4#ifndef GREM_GRAPHICS_2D_RENDERER_2D_HPP
5#define GREM_GRAPHICS_2D_RENDERER_2D_HPP
109 template <
typename... ExtraBuffers>
114 drawFrameImplementation(renderPass, instanceBatches, camera, extraBufferHandles);
123 return invisibleTexture2D;
132 return invisibleTexture2DArray;
141 return invisibleTextureCube;
150 return invisibleTextureCubeArray;
159 return whiteTexture2D;
168 return whiteTextureCube;
177 return flatNormalTexture2D;
186 return defaultDepthTexture2D;
195 return defaultDepthTexture2DArray;
204 return defaultDepthTextureCube;
213 return defaultDepthTextureCubeArray;
236 if (!plainModel2DShaderPipeline) {
241 return *plainModel2DShaderPipeline;
257 if (!textModel2DShaderPipeline) {
262 return *textModel2DShaderPipeline;
278 if (!tonemappingModel2DShaderPipeline) {
285 return *tonemappingModel2DShaderPipeline;
301 return unitSquareModel2D;
315 return unitRightAngledTriangleModel2D;
327 .maxAnisotropy = 1.0f,
333 template <
typename... Buffers>
334 void setTemporaryCombinedBufferHandles(
Span<
const Pair<BufferLayoutReference,
SharedPointer<void>>> extraBufferHandles,
const Buffers&... buffers) {
335 temporaryCombinedBufferHandles.clear();
336 (temporaryCombinedBufferHandles.push_back(
Pair<BufferLayoutReference,
SharedPointer<void>>{Buffers::LAYOUT_REFERENCE, buffers.lock()}), ...);
337 for (
const Pair<BufferLayoutReference, SharedPointer<void>>& extraBufferHandle : extraBufferHandles) {
338 temporaryCombinedBufferHandles.push_back(extraBufferHandle);
343 GREM_API(graphics_2d)
345 Span<
const Pair<BufferLayoutReference, SharedPointer<void>>> extraBufferHandles);
348 Texture invisibleTexture2D =
356 Texture whiteTexture2D =
362 Texture defaultDepthTexture2D =
364 Texture defaultDepthTexture2DArray =
366 Texture defaultDepthTextureCube =
368 Texture defaultDepthTextureCubeArray =
370 Optional<Model2D::VertexShader> defaultModel2DVertexShader{};
371 Optional<PlainModel2DFragmentShader> plainModel2DFragmentShader{};
372 Optional<Model2D::ShaderPipeline> plainModel2DShaderPipeline{};
373 Optional<TextModel2DFragmentShader> textModel2DFragmentShader{};
374 Optional<Model2D::ShaderPipeline> textModel2DShaderPipeline{};
375 Optional<TonemappingModel2DFragmentShader> tonemappingModel2DFragmentShader{};
376 Optional<Model2D::ShaderPipeline> tonemappingModel2DShaderPipeline{};
377 Model2D unitSquareModel2D{device, *
this, UNIT_SQUARE_MESH_2D_VERTICES};
378 Model2D unitRightAngledTriangleModel2D{device, *
this,
Span{UNIT_SQUARE_MESH_2D_VERTICES}.first<3>()};
379 Text2D temporaryText{};
380 ArrayList<Pair<BufferLayoutReference, SharedPointer<void>>> temporaryCombinedBufferHandles{};
381 DrawCommandBuffer<Model2D::Mesh> drawCommandBuffer2D{device};
static const Color INVISIBLE
Definition Color.hpp:70
static constexpr Color fromLinear(float x, float a=1.0f) noexcept
Create a grayscale color from a linear scalar.
Definition Color.hpp:336
static const Color WHITE
Definition Color.hpp:215
Definition SharedPointer.hpp:65
Definition StridedSpan.hpp:427
Combined view-projection matrix, defining a 2D perspective to render from.
Definition Camera2D.hpp:109
Persistent system managing the rendering context of a Window.
Definition Device.hpp:68
Batch of instances to be drawn in a Renderer2D frame.
Definition Instances2D.hpp:586
Container for a set of 2D triangle strip meshes stored on the GPU.
Definition Model2D.hpp:30
UniformBuffer< TextureParameters, "Model2DTexture"> TextureBuffer
Shader buffer for 2D model texture parameters.
Definition Model2D.hpp:97
static constexpr FragmentShaderConstants DEFAULT_FRAGMENT_SHADER_CONSTANTS
Default 2D model fragment shader constants.
Definition Model2D.hpp:176
static constexpr VertexShaderConstants DEFAULT_VERTEX_SHADER_CONSTANTS
Default 2D model vertex shader constants.
Definition Model2D.hpp:171
graphics::ShaderPipeline< Mesh > ShaderPipeline
Shader pipeline for drawing 2D models.
Definition Model2D.hpp:152
static constexpr ShaderPipelineOptions DEFAULT_SHADER_PIPELINE_OPTIONS
Default 2D model graphics pipeline configuration.
Definition Model2D.hpp:181
VertexShaderBase< VertexShaderConstants, VertexShaderOutputs > VertexShader
Default vertex shader for drawing 2D models.
Definition Model2D.hpp:127
FragmentShaderBase< VertexShaderOutputs, FragmentShaderConstants, FragmentShaderOutputs > FragmentShader
Default fragment shader type for drawing 2D models.
Definition Model2D.hpp:147
Backend-specific implementation of RenderPass.
Definition RenderPass.hpp:38
const Model2D::ShaderPipeline & getTonemappingModel2DShaderPipeline()
Get the default tonemapping shader pipeline.
Definition Renderer2D.hpp:277
const Model2D::ShaderPipeline & getTextModel2DShaderPipeline()
Get the default text shader pipeline.
Definition Renderer2D.hpp:256
const Texture & getInvisibleTexture2DArray()
Get the default invisible 2D array texture.
Definition Renderer2D.hpp:131
const Texture & getDefaultDepthTexture2D()
Get the default 2D depth texture.
Definition Renderer2D.hpp:185
const Texture & getDefaultDepthTextureCube()
Get the default cube depth texture.
Definition Renderer2D.hpp:203
const Texture & getInvisibleTexture2D()
Get the default invisible 2D texture.
Definition Renderer2D.hpp:122
Renderer2D & operator=(const Renderer2D &)=delete
Copying a renderer is not allowed.
Model2D::FragmentShader TonemappingModel2DFragmentShader
Default fragment shader type for tonemapping.
Definition Renderer2D.hpp:58
Renderer2D(Renderer2D &&)=delete
Moving a renderer is not allowed.
const Model2D::ShaderPipeline & getPlainModel2DShaderPipeline()
Get the default plain 2D model shader pipeline.
Definition Renderer2D.hpp:235
const Model2D::VertexShader & getDefaultModel2DVertexShader()
Get the default 2D model vertex shader.
Renderer2D & operator=(Renderer2D &&)=delete
Moving a renderer is not allowed.
const Texture & getInvisibleTextureCubeArray()
Get the default invisible cube array texture.
Definition Renderer2D.hpp:149
const Texture & getFlatNormalTexture2D()
Get the default flat normal map 2D texture.
Definition Renderer2D.hpp:176
const Texture & getWhiteTextureCube()
Get the default white cubemap texture.
Definition Renderer2D.hpp:167
Renderer2D(const Renderer2D &)=delete
Copying a renderer is not allowed.
Model2D::FragmentShader PlainModel2DFragmentShader
Default fragment shader type for drawing plain 2D models.
Definition Renderer2D.hpp:52
const Model2D & getUnitSquareModel2D() const noexcept
Get the default 2D unit square model, which holds a single mesh that forms a square using a triangle ...
Definition Renderer2D.hpp:300
Model2D::VertexShader DefaultModel2DVertexShader
Default vertex shader type for drawing 2D models.
Definition Renderer2D.hpp:49
Renderer2D(Device &device, const Renderer2DOptions &options={})
Construct a 2D renderer.
const TonemappingModel2DFragmentShader & getTonemappingModel2DFragmentShader()
Get the default tonemapping fragment shader.
const TextModel2DFragmentShader & getTextModel2DFragmentShader()
Get the default text fragment shader.
const Texture & getInvisibleTextureCube()
Get the default invisible cube texture.
Definition Renderer2D.hpp:140
const Texture & getWhiteTexture2D()
Get the default white 2D texture.
Definition Renderer2D.hpp:158
Model2D::FragmentShader TextModel2DFragmentShader
Default fragment shader type for drawing text.
Definition Renderer2D.hpp:55
const Texture & getDefaultDepthTextureCubeArray()
Get the default cube array depth texture.
Definition Renderer2D.hpp:212
const Model2D & getUnitRightAngledTriangleModel2D() const noexcept
Get the default 2D unit right-angled triangle model, which holds a single mesh that forms a single tr...
Definition Renderer2D.hpp:314
const PlainModel2DFragmentShader & getPlainModel2DFragmentShader()
Get the default plain 2D model fragment shader.
const Texture & getDefaultDepthTexture2DArray()
Get the default 2D array depth texture.
Definition Renderer2D.hpp:194
void drawFrame(RenderPass &renderPass, StridedSpan< const Instances2DView > instanceBatches, const Camera2D &camera, const ExtraBuffers &... extraBuffers)
Push the draw commands of a frame of 2D instance batches to a render pass.
Definition Renderer2D.hpp:110
Storage for multidimensional data, such as 2D images, on the GPU, combined with a sampler configurati...
Definition Texture.hpp:700
static Texture create(Device &device, TextureType type, TextureFormat internalFormat, Extent3D size, uint32_t mipLevelCount, const void *pixels, Optional< TextureSamplerOptions > samplerOptions=TextureSamplerOptions{})
Create a new texture object and allocate GPU memory for storing image data.
Definition buffer_layouts.hpp:20
@ LESS_OR_EQUAL
The depth test passes if and only if the new depth value is less than or equal to the reference depth...
Definition Texture.hpp:515
@ CLAMP_TO_EDGE
Clamp to the edge of the texture when sampling outside the 0-1 range.
Definition Texture.hpp:492
@ D16_UNORM
Raw bitmap where each texel comprises 1 normalized 16-bit unsigned integer component: depth.
Definition Texture.hpp:282
@ R8G8B8A8_UNORM
Raw bitmap where each texel comprises 4 normalized 8-bit unsigned integer components: red,...
Definition Texture.hpp:276
@ NONE
Always use the most detailed mip level (level 0).
Definition Texture.hpp:482
@ NEAREST
Use the nearest neighbor to the sampled texel, which results in a blocky appearance.
Definition Texture.hpp:474
@ TEXTURE_2D_ARRAY
Texture set up to store an array of 2D images.
Definition Texture.hpp:40
@ TEXTURE_CUBE
Texture set up to store a cube of 6 sides of square 2D images.
Definition Texture.hpp:41
@ TEXTURE_CUBE_ARRAY
Texture set up to store an array of cubes of 6 sides of square 2D images.
Definition Texture.hpp:42
@ TEXTURE_2D
Texture set up to store a single 2D image.
Definition Texture.hpp:39
StridedSpan(R &&range) -> StridedSpan< std::remove_reference_t< decltype(*std::data(range))>, DYNAMIC_EXTENT, sizeof(std::remove_reference_t< decltype(*std::data(range))>)>
constexpr void sortByAscending(random_access_range auto &&range)
Definition algorithms.hpp:514
Extent< 2 > Extent2D
Size of a 2D data region.
Definition extents.hpp:31
Span(R &&range) -> Span< std::remove_reference_t< decltype(*std::data(range))> >
Pair(T1, T2) -> Pair< T1, T2 >
Extent< 3 > Extent3D
Size of a 3D data region.
Definition extents.hpp:32
Configuration options for a Renderer2D.
Definition Renderer2D.hpp:30
constexpr bool operator==(const Renderer2DOptions &other) const noexcept=default
Compare these options to another set of options for equality.
Configuration of a graphics pipeline.
Definition shaders.hpp:428
Optional< BlendState > blendState
How to blend the pixel color with the output while rendering.
Definition shaders.hpp:652
Configuration options for the sampler of a Texture.
Definition Texture.hpp:617
static const TextureSamplerOptions UNFILTERED
A texture sampler configuration that ensures that the texture is sampled as directly as possible,...
Definition Texture.hpp:622