4#ifndef GREM_GRAPHICS_2D_MODEL_2D_HPP
5#define GREM_GRAPHICS_2D_MODEL_2D_HPP
121 template <
typename Constants,
typename Outputs,
typename... ExtraBuffers>
141 template <
typename Inputs,
typename Constants,
typename Outputs,
typename... ExtraBuffers>
202 : nodes(std::
move(nodes)) {
208 boundingBox = this->nodes.front().boundingBox;
209 boundingRadius = this->nodes.front().boundingRadius;
211 boundingBox.min =
min(boundingBox.min, node.boundingBox.min);
212 boundingBox.max =
max(boundingBox.max, node.boundingBox.max);
213 boundingRadius =
max(boundingRadius, node.boundingRadius);
234 float meshBoundingRadius = 0.0f;
235 if (!vertices.
empty()) {
236 meshBoundingBox = {.min = vertices.
front().vertexPosition, .max = vertices.
front().vertexPosition};
237 float meshBoundingRadiusSquared =
length2(vertices.
front().vertexPosition);
239 meshBoundingBox.
min =
min(meshBoundingBox.
min, vertex.vertexPosition);
240 meshBoundingBox.
max =
max(meshBoundingBox.
max, vertex.vertexPosition);
241 meshBoundingRadiusSquared =
max(meshBoundingRadiusSquared,
length2(vertex.vertexPosition));
243 meshBoundingRadius =
sqrt(meshBoundingRadiusSquared);
246 nodes.push_back(
Node{.mesh =
Mesh{device, vertices}, .boundingBox = meshBoundingBox, .boundingRadius = meshBoundingRadius});
247 boundingBox = meshBoundingBox;
248 boundingRadius = meshBoundingRadius;
276 return boundingRadius;
282 float boundingRadius = 0.0f;
#define GREM_ASSERT(expression)
Definition assertions.hpp:77
Definition ArrayList.hpp:27
constexpr reference front() const noexcept
Definition Span.hpp:261
constexpr bool empty() const noexcept
Definition Span.hpp:257
constexpr detail::subspan_type_t< T, EXTENT, Offset, N > subspan() const
Definition Span.hpp:284
UniformBuffer< Parameters, "Camera2DParameters"> ParameterBuffer
Shader buffer for 2D camera parameters.
Definition Camera2D.hpp:125
Persistent system managing the rendering context of a Window.
Definition Device.hpp:68
Compiled GPU fragment shader stage.
Definition shaders.hpp:1274
Generic abstraction of a GPU vertex array object and its associated buffers.
Definition Mesh.hpp:209
UniformBuffer< TextureParameters, "Model2DTexture"> TextureBuffer
Shader buffer for 2D model texture parameters.
Definition Model2D.hpp:97
graphics::Mesh< Vertex, NoIndex, NoParameters, Instance > Mesh
Type of a single mesh of a 2D model.
Definition Model2D.hpp:59
graphics::VertexShader< Mesh, Constants, Outputs, Camera2D::ParameterBuffer, ExtraBuffers... > VertexShaderBase
Vertex shader for drawing 2D models.
Definition Model2D.hpp:122
static constexpr FragmentShaderConstants DEFAULT_FRAGMENT_SHADER_CONSTANTS
Default 2D model fragment shader constants.
Definition Model2D.hpp:176
Box< 2, float > getBoundingBox() const noexcept
Get the local bounding box of the model.
Definition Model2D.hpp:266
static constexpr VertexShaderConstants DEFAULT_VERTEX_SHADER_CONSTANTS
Default 2D model vertex shader constants.
Definition Model2D.hpp:171
graphics::FragmentShader< Mesh, Inputs, Constants, Outputs, Camera2D::ParameterBuffer, ExtraBuffers..., TextureBuffer > FragmentShaderBase
Fragment shader for drawing 2D models.
Definition Model2D.hpp:142
UniformBuffer< Transformation3DParameters, "Model2DTransformation3D"> Transformation3DBuffer
Shader buffer for 2D model 3D transformation parameters.
Definition Model2D.hpp:109
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
Span< const Node > getNodes() const noexcept
Get the nodes of the model.
Definition Model2D.hpp:256
float getBoundingRadius() const noexcept
Get the local bounding radius of the model.
Definition Model2D.hpp:275
Model2D(Device &device, Renderer2D &renderer2D, Span< const Vertex > vertices)
Construct a model with a single mesh from a list of vertices.
Definition Model2D.hpp:230
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
Model2D() noexcept=default
Construct an invalid model that must be reassigned before use.
Persistent system that provides 2D rendering capabilities.
Definition Renderer2D.hpp:46
Linked GPU shader pipeline.
Definition shaders.hpp:1508
Compiled GPU vertex shader stage.
Definition shaders.hpp:1060
Definition buffer_layouts.hpp:20
@ TRIANGLE_STRIP
Each point, except the first two, forms a filled triangle with the previous two points.
Definition shaders.hpp:296
@ NONE
Ignore the depth buffer.
Definition shaders.hpp:59
@ NONE
Ignore facing, don't cull primitives based on their winding order.
Definition shaders.hpp:319
GREM_ALWAYS_INLINE constexpr T GREM_VECTORCALL length2(T a)
Definition math.hpp:1969
vec< 4, float > vec4
Definition math.hpp:440
GREM_ALWAYS_INLINE constexpr T GREM_VECTORCALL sqrt(T a)
Get the square root of a value.
Definition math.hpp:1114
vec< 2, float > vec2
Definition math.hpp:438
vec< 3, float > vec3
Definition math.hpp:439
constexpr auto move(input_range auto &&range, auto outputIterator)
Definition algorithms.hpp:669
mat< 2, 2, float > mat2
Definition math.hpp:804
GREM_ALWAYS_INLINE constexpr decltype(auto) max(A &&a, B &&b)
Get the greater of two values, or the first value if they are equivalent.
Definition fundamentals.hpp:598
mat< 4, 4, float > mat4
Definition math.hpp:806
GREM_ALWAYS_INLINE constexpr decltype(auto) min(A &&a, B &&b)
Get the smaller of two values, or the first value if they are equivalent.
Definition fundamentals.hpp:585
Generic axis-aligned box shape with minimum and maximum extents in N-dimensional space.
Definition geometry.hpp:149
Point< N, T > max
Position with the maximum coordinates of the box extents on each coordinate axis.
Definition geometry.hpp:154
Point< N, T > min
Position with the minimum coordinates of the box extents on each coordinate axis.
Definition geometry.hpp:153
static const BlendState ALPHA_BLENDING_PREMULTIPLIED
Blend state to use for pre-multiplied alpha blending using the standard "over" operator.
Definition shaders.hpp:391
Struct of default fragment shader constants.
Definition Model2D.hpp:78
Struct of fields output by the default fragment shader.
Definition Model2D.hpp:83
vec4 outputColor
Final fragment color.
Definition Model2D.hpp:84
Data layout for the attributes of a single instance of a 2D model mesh.
Definition Model2D.hpp:47
vec3 instanceEmissiveColor
Additive emissive color to use when rendering.
Definition Model2D.hpp:53
mat2 instanceTextureBasis
Basis transformation to apply to the texture coordinates before sampling the texture.
Definition Model2D.hpp:51
vec4 instanceTintColor
Multiplicative tint color to use when rendering.
Definition Model2D.hpp:52
vec2 instanceTextureOffset
Offset to apply to the texture coordinates before sampling the texture.
Definition Model2D.hpp:50
vec2 instancePosition
Offset to apply to the vertex positions.
Definition Model2D.hpp:48
mat2 instanceBasis
Basis transformation to apply to the vertex positions.
Definition Model2D.hpp:49
Node of a 2D model.
Definition Model2D.hpp:157
Mesh mesh
Mesh primitive of the node.
Definition Model2D.hpp:159
Box< 2, float > boundingBox
Local bounding box of the node.
Definition Model2D.hpp:162
float boundingRadius
Local bounding radius of the node.
Definition Model2D.hpp:165
Struct of shader parameters representing the texture of a 2D model.
Definition Model2D.hpp:90
sampler2D mainTexture
Texture to use when rendering the model.
Definition Model2D.hpp:91
Struct of default vertex shader constants.
Definition Model2D.hpp:64
Struct of fields output by the default vertex shader.
Definition Model2D.hpp:69
vec3 fragmentEmissiveColor
Emissive color of the vertex.
Definition Model2D.hpp:72
vec2 fragmentTextureCoordinates
Texture coordinates of the vertex.
Definition Model2D.hpp:70
vec4 fragmentTintColor
Tint color of the vertex.
Definition Model2D.hpp:71
Data layout for the attributes of a single vertex of a 2D model mesh.
Definition Model2D.hpp:37
vec2 vertexTextureCoordinates
Texture UV coordinates that map to this vertex.
Definition Model2D.hpp:39
vec2 vertexPosition
Position relative to the model origin.
Definition Model2D.hpp:38
Configuration of a graphics pipeline.
Definition shaders.hpp:428
Reference to a sampler2D Texture that may be used as a parameter value type in a shader-read buffer.
Definition ParameterDescription.hpp:131