GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
Instances3D.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Ivar Härnqvist
2// SPDX-License-Identifier: MIT
3
4#ifndef GREM_GRAPHICS_3D_INSTANCES_3D_HPP
5#define GREM_GRAPHICS_3D_INSTANCES_3D_HPP
6
8
22#include <GREM/core/math.hpp>
36
37#include <utility> // std::forward
38
39namespace grem::graphics {
40
41class Device; // Forward declaration, to avoid including Device.hpp.
42class Renderer3D; // Forward declaration, to avoid a circular include of Renderer3D.hpp.
43
93
159
172 const Texture* texture = nullptr;
173
174 vec3 pointA{0.0f, 0.0f, 0.0f};
175 vec3 pointB{1.0f, 0.0f, 0.0f};
176 vec3 pointC{0.0f, 1.0f, 0.0f};
177
185 vec2 textureOffset{0.0f, 0.0f};
186
195
208
218
224};
225
237 const Texture* texture = nullptr;
238
242 vec3 position{0.0f, 0.0f, 0.0f};
243
247 quat orientation{0.0f, 0.0f, 0.0f, 1.0f};
248
252 vec2 size{1.0f, 1.0f};
253
259 vec2 origin{0.0f, 0.0f};
260
268 vec2 textureOffset{0.0f, 0.0f};
269
278
291
301
307};
308
316 vec3 position{0.0f, 0.0f, 0.0f};
317
321 quat orientation{0.0f, 0.0f, 0.0f, 1.0f};
322
326 vec2 size{1.0f, 1.0f};
327
333 vec2 origin{0.0f, 0.0f};
334
344
354
360};
361
370 vec3 position{0.0f, 0.0f, 0.0f};
371
375 quat orientation{0.0f, 0.0f, 0.0f, 1.0f};
376
388 vec2 scale{1.0f, 1.0f};
389
394
400
405
411};
412
420 uint32_t characterSize = 16;
421
426 vec3 position{0.0f, 0.0f, 0.0f};
427
431 quat orientation{0.0f, 0.0f, 0.0f, 1.0f};
432
444 vec2 shapeScale{1.0f, 1.0f};
445
453 vec2 shapeOrigin{0.0f, 0.0f};
454
466 vec2 scale{1.0f, 1.0f};
467
472
478
483
489};
490
495public:
508 Instances3D(Device& device, Renderer3D& renderer3D)
509 : device(&device)
510 , renderer3D(&renderer3D) {}
511
520 void clear() {
521 jointsDirty = !joints.empty();
522 morphTargetWeightsDirty = !morphTargetWeights.empty();
523 model3DInstanceBuffer.clear();
524 model2DInstanceBuffer.clear();
525 opaqueModel3DDrawCommandBuffer.clear();
526 transparent3DDrawCommands.clear();
527 transparent2DDrawCommands.clear();
528 joints.clear();
529 morphTargetWeights.clear();
530 }
531
545 GREM_API(graphics_3d) void putPBRModelInstance(const Model3D& model, resource::Model::TransformationView transformation, const ModelInstance3D& instance = {});
546
560 GREM_API(graphics_3d) void putPBRModelInstance(const Model3D& model, const mat4& transformation, const ModelInstance3D& instance = {});
561
577 GREM_API(graphics_3d) void putPBRModelInstance(const Model3D& model, const mat4& transformation, resource::Model::PoseView pose, const ModelInstance3D& instance);
578
594 GREM_API(graphics_3d)
595 void putPBRModelInstances(const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations, StridedSpan<const ModelInstance3D> instances);
596
612 GREM_API(graphics_3d) void putPBRModelInstances(const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations, const ModelInstance3D& instance);
613
627 GREM_API(graphics_3d) void putPBRModelInstances(const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations);
628
646 GREM_API(graphics_3d)
647 void putVisiblePBRModelInstances(const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations, StridedSpan<const ModelInstance3D> instances,
648 StridedSpan<const bool> instancesVisible);
649
667 GREM_API(graphics_3d)
668 void putVisiblePBRModelInstances(const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations, const ModelInstance3D& instance,
669 StridedSpan<const bool> instancesVisible);
670
686 GREM_API(graphics_3d)
687 void putVisiblePBRModelInstances(const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations, StridedSpan<const bool> instancesVisible);
688
702 GREM_API(graphics_3d) void putHDRPBRModelInstance(const Model3D& model, resource::Model::TransformationView transformation, const ModelInstance3D& instance = {});
703
717 GREM_API(graphics_3d) void putHDRPBRModelInstance(const Model3D& model, const mat4& transformation, const ModelInstance3D& instance = {});
718
734 GREM_API(graphics_3d) void putHDRPBRModelInstance(const Model3D& model, const mat4& transformation, resource::Model::PoseView pose, const ModelInstance3D& instance);
735
751 GREM_API(graphics_3d)
752 void putHDRPBRModelInstances(const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations, StridedSpan<const ModelInstance3D> instances);
753
769 GREM_API(graphics_3d)
770 void putHDRPBRModelInstances(const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations, const ModelInstance3D& instance);
771
785 GREM_API(graphics_3d) void putHDRPBRModelInstances(const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations);
786
804 GREM_API(graphics_3d)
805 void putVisibleHDRPBRModelInstances(const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations, StridedSpan<const ModelInstance3D> instances,
806 StridedSpan<const bool> instancesVisible);
807
825 GREM_API(graphics_3d)
826 void putVisibleHDRPBRModelInstances(const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations, const ModelInstance3D& instance,
827 StridedSpan<const bool> instancesVisible);
828
844 GREM_API(graphics_3d)
845 void putVisibleHDRPBRModelInstances(const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations, StridedSpan<const bool> instancesVisible);
846
860 GREM_API(graphics_3d) void putUnlitModelInstance(const Model3D& model, resource::Model::TransformationView transformation, const ModelInstance3D& instance = {});
861
875 GREM_API(graphics_3d) void putUnlitModelInstance(const Model3D& model, const mat4& transformation, const ModelInstance3D& instance = {});
876
892 GREM_API(graphics_3d) void putUnlitModelInstance(const Model3D& model, const mat4& transformation, resource::Model::PoseView pose, const ModelInstance3D& instance = {});
893
909 GREM_API(graphics_3d)
910 void putUnlitModelInstances(const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations, StridedSpan<const ModelInstance3D> instances);
911
927 GREM_API(graphics_3d)
928 void putUnlitModelInstances(const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations, const ModelInstance3D& instance);
929
943 GREM_API(graphics_3d) void putUnlitModelInstances(const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations);
944
962 GREM_API(graphics_3d)
963 void putVisibleUnlitModelInstances(const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations, StridedSpan<const ModelInstance3D> instances,
964 StridedSpan<const bool> instancesVisible);
965
983 GREM_API(graphics_3d)
984 void putVisibleUnlitModelInstances(const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations, const ModelInstance3D& instance,
985 StridedSpan<const bool> instancesVisible);
986
1002 GREM_API(graphics_3d)
1003 void putVisibleUnlitModelInstances(const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations, StridedSpan<const bool> instancesVisible);
1004
1019 GREM_API(graphics_3d) void putHDRUnlitModelInstance(const Model3D& model, resource::Model::TransformationView transformation, const ModelInstance3D& instance = {});
1020
1034 GREM_API(graphics_3d) void putHDRUnlitModelInstance(const Model3D& model, const mat4& transformation, const ModelInstance3D& instance = {});
1035
1051 GREM_API(graphics_3d) void putHDRUnlitModelInstance(const Model3D& model, const mat4& transformation, resource::Model::PoseView pose, const ModelInstance3D& instance = {});
1052
1068 GREM_API(graphics_3d)
1069 void putHDRUnlitModelInstances(const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations, StridedSpan<const ModelInstance3D> instances);
1070
1086 GREM_API(graphics_3d)
1087 void putHDRUnlitModelInstances(const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations, const ModelInstance3D& instance);
1088
1102 GREM_API(graphics_3d) void putHDRUnlitModelInstances(const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations);
1103
1121 GREM_API(graphics_3d)
1122 void putVisibleHDRUnlitModelInstances(const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations,
1123 StridedSpan<const ModelInstance3D> instances, StridedSpan<const bool> instancesVisible);
1124
1142 GREM_API(graphics_3d)
1143 void putVisibleHDRUnlitModelInstances(const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations, const ModelInstance3D& instance,
1144 StridedSpan<const bool> instancesVisible);
1145
1161 GREM_API(graphics_3d)
1162 void putVisibleHDRUnlitModelInstances(const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations, StridedSpan<const bool> instancesVisible);
1163
1180 void putShadedModelInstance(auto&& shaderPipelineSelector, const Model3D& model, resource::Model::TransformationView transformation, const ModelInstance3D& instance = {}) {
1181 const auto shaderPipelineSelectorAdapter = [&](const Model3D::ShaderConfiguration& shaderConfiguration) -> SharedPointer<ShaderPipelineImplementation> {
1182 return shaderPipelineSelector(shaderConfiguration).lock();
1183 };
1184 putShadedModelInstanceImplementation(shaderPipelineSelectorAdapter, model, transformation, instance);
1185 }
1186
1203 void putShadedModelInstance(auto&& shaderPipelineSelector, const Model3D& model, const mat4& transformation, const ModelInstance3D& instance = {}) {
1204 const resource::Model::Pose& pose = model.getBindPose();
1205 resource::Model::Transformation& temporaryModelTransformation = getTemporaryModelTransformation();
1206 temporaryModelTransformation.assign(transformation, pose.localJoints, pose.localMorphTargetWeights, model.getJointParentIndices());
1207 putShadedModelInstance(std::forward<decltype(shaderPipelineSelector)>(shaderPipelineSelector), model, temporaryModelTransformation, instance);
1208 }
1209
1228 void putShadedModelInstance(auto&& shaderPipelineSelector, const Model3D& model, const mat4& transformation, resource::Model::PoseView pose,
1229 const ModelInstance3D& instance = {}) {
1230 resource::Model::Transformation& temporaryModelTransformation = getTemporaryModelTransformation();
1231 temporaryModelTransformation.assign(transformation, Span{pose.localJoints, model.getJointCount()}, Span{pose.localMorphTargetWeights, model.getMorphTargetWeightCount()},
1232 model.getJointParentIndices());
1233 putShadedModelInstance(std::forward<decltype(shaderPipelineSelector)>(shaderPipelineSelector), model, temporaryModelTransformation, instance);
1234 }
1235
1254 void putShadedModelInstances(auto&& shaderPipelineSelector, const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations,
1256 GREM_ASSERT(transformations.size() == instances.size());
1257 const auto shaderPipelineSelectorAdapter = [&](const Model3D::ShaderConfiguration& shaderConfiguration) -> SharedPointer<ShaderPipelineImplementation> {
1258 return shaderPipelineSelector(shaderConfiguration).lock();
1259 };
1260 putShadedModelInstancesImplementation(shaderPipelineSelectorAdapter, model, transformations, instances);
1261 }
1262
1281 void putShadedModelInstances(auto&& shaderPipelineSelector, const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations,
1282 const ModelInstance3D& instance) {
1283 const auto shaderPipelineSelectorAdapter = [&](const Model3D::ShaderConfiguration& shaderConfiguration) -> SharedPointer<ShaderPipelineImplementation> {
1284 return shaderPipelineSelector(shaderConfiguration).lock();
1285 };
1286 putShadedModelInstancesImplementation(shaderPipelineSelectorAdapter, model, transformations, StridedSpan{&instance, 1});
1287 }
1288
1305 void putShadedModelInstances(auto&& shaderPipelineSelector, const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations) {
1306 const auto shaderPipelineSelectorAdapter = [&](const Model3D::ShaderConfiguration& shaderConfiguration) -> SharedPointer<ShaderPipelineImplementation> {
1307 return shaderPipelineSelector(shaderConfiguration).lock();
1308 };
1309 const ModelInstance3D defaultInstance{};
1310 putShadedModelInstancesImplementation(shaderPipelineSelectorAdapter, model, transformations, StridedSpan{&defaultInstance, 1});
1311 }
1312
1333 void putVisibleShadedModelInstances(auto&& shaderPipelineSelector, const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations,
1334 StridedSpan<const ModelInstance3D> instances, StridedSpan<const bool> instancesVisible) {
1335 GREM_ASSERT(transformations.size() == instances.size());
1336 const auto shaderPipelineSelectorAdapter = [&](const Model3D::ShaderConfiguration& shaderConfiguration) -> SharedPointer<ShaderPipelineImplementation> {
1337 return shaderPipelineSelector(shaderConfiguration).lock();
1338 };
1339 putVisibleShadedModelInstancesImplementation(shaderPipelineSelectorAdapter, model, transformations, instances, instancesVisible);
1340 }
1341
1362 void putVisibleShadedModelInstances(auto&& shaderPipelineSelector, const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations,
1363 const ModelInstance3D& instance, StridedSpan<const bool> instancesVisible) {
1364 const auto shaderPipelineSelectorAdapter = [&](const Model3D::ShaderConfiguration& shaderConfiguration) -> SharedPointer<ShaderPipelineImplementation> {
1365 return shaderPipelineSelector(shaderConfiguration).lock();
1366 };
1367 putVisibleShadedModelInstancesImplementation(shaderPipelineSelectorAdapter, model, transformations, StridedSpan{&instance, 1}, instancesVisible);
1368 }
1369
1388 void putVisibleShadedModelInstances(auto&& shaderPipelineSelector, const Model3D& model, StridedSpan<const resource::Model::TransformationView> transformations,
1389 StridedSpan<const bool> instancesVisible) {
1390 const auto shaderPipelineSelectorAdapter = [&](const Model3D::ShaderConfiguration& shaderConfiguration) -> SharedPointer<ShaderPipelineImplementation> {
1391 return shaderPipelineSelector(shaderConfiguration).lock();
1392 };
1393 const ModelInstance3D defaultInstance{};
1394 putVisibleShadedModelInstancesImplementation(shaderPipelineSelectorAdapter, model, transformations, StridedSpan{&defaultInstance, 1}, instancesVisible);
1395 }
1396
1412 GREM_API(graphics_3d) void putFlatModelInstance(const Model2D& model, const FlatModelInstance3D& instance);
1413
1430 GREM_API(graphics_3d) void putShadedFlatModelInstance(const Model2D::ShaderPipeline& shaderPipeline, const Model2D& model, const FlatModelInstance3D& instance);
1431
1444 GREM_API(graphics_3d) void putTriangleInstance(const TriangleInstance3D& instance);
1445
1459 GREM_API(graphics_3d) void putShadedTriangleInstance(const Model2D::ShaderPipeline& shaderPipeline, const TriangleInstance3D& instance);
1460
1474 GREM_API(graphics_3d) void putQuadInstance(const QuadInstance3D& instance);
1475
1490 GREM_API(graphics_3d) void putShadedQuadInstance(const Model2D::ShaderPipeline& shaderPipeline, const QuadInstance3D& instance);
1491
1508 GREM_API(graphics_3d) void putSpriteInstance(const SpriteAtlas& spriteAtlas, SpriteID spriteID, const SpriteInstance3D& instance);
1509
1527 GREM_API(graphics_3d)
1528 void putShadedSpriteInstance(const Model2D::ShaderPipeline& shaderPipeline, const SpriteAtlas& spriteAtlas, SpriteID spriteID, const SpriteInstance3D& instance);
1529
1543 GREM_API(graphics_3d) void putTextInstance(const Text2D& text, const TextInstance3D& instance);
1544
1559 GREM_API(graphics_3d) void putShadedTextInstance(const Model2D::ShaderPipeline& shaderPipeline, const Text2D& text, const TextInstance3D& instance);
1560
1583 GREM_API(graphics_3d) void putTextStringInstance(Font2D& font, UTF8StringView string, const TextStringInstance3D& instance);
1584
1608 GREM_API(graphics_3d)
1609 void putShadedTextStringInstance(const Model2D::ShaderPipeline& shaderPipeline, Font2D& font, UTF8StringView string, const TextStringInstance3D& instance);
1610
1634 GREM_API(graphics_3d) void putTextStringInstance(Font2D& font, StringView string, const TextStringInstance3D& instance);
1635
1660 GREM_API(graphics_3d) void putShadedTextStringInstance(const Model2D::ShaderPipeline& shaderPipeline, Font2D& font, StringView string, const TextStringInstance3D& instance);
1661
1662private:
1663 friend Renderer3D;
1664
1665 struct Transparent3DDrawCommand {
1666 vec3 position;
1667 uint32_t instanceIndex;
1670 float boundingRadius;
1671 float distanceOrderingBias;
1672 };
1673
1674 struct Transparent2DDrawCommand {
1675 mat4 transformation;
1679 uint32_t instanceOffset;
1680 float boundingRadius;
1681 float distanceOrderingBias;
1682 };
1683
1684 [[nodiscard]] GREM_API(graphics_3d) resource::Model::Transformation& getTemporaryModelTransformation();
1685
1686 GREM_API(graphics_3d)
1687 void putShadedModelInstanceImplementation(
1688 FunctionView<SharedPointer<ShaderPipelineImplementation>(const Model3D::ShaderConfiguration& shaderConfiguration)> shaderPipelineSelectorAdapter, const Model3D& model,
1689 resource::Model::TransformationView transformation, const ModelInstance3D& instance);
1690
1691 GREM_API(graphics_3d)
1692 void putShadedModelInstancesImplementation(
1693 FunctionView<SharedPointer<ShaderPipelineImplementation>(const Model3D::ShaderConfiguration& shaderConfiguration)> shaderPipelineSelectorAdapter, const Model3D& model,
1695
1696 GREM_API(graphics_3d)
1697 void putVisibleShadedModelInstancesImplementation(
1698 FunctionView<SharedPointer<ShaderPipelineImplementation>(const Model3D::ShaderConfiguration& shaderConfiguration)> shaderPipelineSelectorAdapter, const Model3D& model,
1700
1701 GREM_API(graphics_3d)
1702 void putShadedFlatModelInstanceImplementation(SharedPointer<ShaderPipelineImplementation> shaderPipelineHandle, const Model2D& model, const FlatModelInstance3D& instance);
1703
1704 GREM_API(graphics_3d)
1705 void putShadedTextInstanceImplementation(SharedPointer<ShaderPipelineImplementation> shaderPipelineHandle, const Text2D& text, const TextInstance3D& instance);
1706
1707 Device* device;
1708 Renderer3D* renderer3D;
1709 mutable Model3D::InstanceBuffers buffers{*device};
1710 mutable bool jointsDirty = false;
1711 mutable bool morphTargetWeightsDirty = false;
1712 InstanceBuffer<Model3D::Instance> model3DInstanceBuffer{*device};
1713 InstanceBuffer<Model2D::Instance> model2DInstanceBuffer{*device};
1714 UnorderedDrawCommandBuffer<Model3D::Mesh> opaqueModel3DDrawCommandBuffer{*device};
1715 ArrayList<Transparent3DDrawCommand> transparent3DDrawCommands{};
1716 ArrayList<Transparent2DDrawCommand> transparent2DDrawCommands{};
1717 Buffer<Model3D::JointFields> joints{};
1718 Buffer<Model3D::MorphTargetWeightFields> morphTargetWeights{};
1719};
1720
1726 FunctionView<bool(vec3 position, float boundingRadius, float distanceOrderingBias)> transparentInstanceFilter = [](vec3, float, float) -> bool {
1727 return true;
1728 };
1729
1732
1735
1738
1741};
1742
1749
1752
1755
1758
1768
1777 Instances3DView(const Instances3D& instances, const Model2D::ShaderPipeline& shaderPipelineOverride2D, const Instances3DFilter& filter = {})
1779 , shaderPipelineOverride2DHandle(shaderPipelineOverride2D.lock())
1780 , filter(filter) {}
1781
1790 Instances3DView(const Instances3D& instances, const Model3D::ShaderPipeline& shaderPipelineOverride3D, const Instances3DFilter& filter = {})
1792 , shaderPipelineOverride3DHandle(shaderPipelineOverride3D.lock())
1793 , filter(filter) {}
1794
1805 Instances3DView(const Instances3D& instances, const Model2D::ShaderPipeline& shaderPipelineOverride2D, const Model3D::ShaderPipeline& shaderPipelineOverride3D,
1806 const Instances3DFilter& filter = {})
1808 , shaderPipelineOverride2DHandle(shaderPipelineOverride2D.lock())
1809 , shaderPipelineOverride3DHandle(shaderPipelineOverride3D.lock())
1810 , filter(filter) {}
1811};
1812
1813} // namespace grem::graphics
1814
1815#endif
#define GREM_ASSERT(expression)
Definition assertions.hpp:77
Floating-point linear RGBA color in the Rec.
Definition Color.hpp:60
static const Color INVISIBLE
Definition Color.hpp:70
static const Color WHITE
Definition Color.hpp:215
Definition FunctionView.hpp:29
Definition SharedPointer.hpp:65
Definition Span.hpp:146
Definition StridedSpan.hpp:427
Persistent system managing the rendering context of a Window.
Definition Device.hpp:68
Typeface describing an assortment of character glyphs that may be rendered on-demand into an expandin...
Definition Font2D.hpp:66
Batch of instances to be drawn in a Renderer3D frame.
Definition Instances3D.hpp:494
void putVisibleShadedModelInstances(auto &&shaderPipelineSelector, const Model3D &model, StridedSpan< const resource::Model::TransformationView > transformations, StridedSpan< const bool > instancesVisible)
Add a list of instances of a 3D model to be rendered using a specific shader pipeline if they are in ...
Definition Instances3D.hpp:1388
void putHDRPBRModelInstance(const Model3D &model, const mat4 &transformation, resource::Model::PoseView pose, const ModelInstance3D &instance)
Add a 3D model instance to be rendered in a specific local pose using the default HDR PBR shader.
void putHDRPBRModelInstance(const Model3D &model, resource::Model::TransformationView transformation, const ModelInstance3D &instance={})
Add a 3D model instance to be rendered using the default HDR PBR shader.
void putShadedModelInstances(auto &&shaderPipelineSelector, const Model3D &model, StridedSpan< const resource::Model::TransformationView > transformations, const ModelInstance3D &instance)
Add a list of instances of a 3D model to be rendered using a specific shader pipeline.
Definition Instances3D.hpp:1281
void putHDRUnlitModelInstance(const Model3D &model, const mat4 &transformation, const ModelInstance3D &instance={})
Add a 3D model instance to be rendered in its default bind pose using the default HDR unlit shader.
void putShadedModelInstance(auto &&shaderPipelineSelector, const Model3D &model, const mat4 &transformation, const ModelInstance3D &instance={})
Add a 3D model instance to be rendered in its default bind pose using a specific shader pipeline.
Definition Instances3D.hpp:1203
void putVisibleHDRUnlitModelInstances(const Model3D &model, StridedSpan< const resource::Model::TransformationView > transformations, StridedSpan< const ModelInstance3D > instances, StridedSpan< const bool > instancesVisible)
Add a list of instances of a 3D model to be rendered using the default HDR unlit shader if they are i...
void putHDRPBRModelInstances(const Model3D &model, StridedSpan< const resource::Model::TransformationView > transformations, StridedSpan< const ModelInstance3D > instances)
Add a list of instances of a 3D model to be rendered using the default HDR PBR shader.
void putShadedSpriteInstance(const Model2D::ShaderPipeline &shaderPipeline, const SpriteAtlas &spriteAtlas, SpriteID spriteID, const SpriteInstance3D &instance)
Add a sprite instance to be rendered using a specific shader pipeline.
void clear()
Clear the batch of all instances.
Definition Instances3D.hpp:520
void putHDRPBRModelInstance(const Model3D &model, const mat4 &transformation, const ModelInstance3D &instance={})
Add a 3D model instance to be rendered in its default bind pose using the default HDR PBR shader.
void putVisibleHDRPBRModelInstances(const Model3D &model, StridedSpan< const resource::Model::TransformationView > transformations, StridedSpan< const ModelInstance3D > instances, StridedSpan< const bool > instancesVisible)
Add a list of instances of a 3D model to be rendered using the default HDR PBR shader if they are in ...
void putHDRUnlitModelInstance(const Model3D &model, resource::Model::TransformationView transformation, const ModelInstance3D &instance={})
Add a 3D model instance to be rendered using the default HDR unlit shader.
void putVisiblePBRModelInstances(const Model3D &model, StridedSpan< const resource::Model::TransformationView > transformations, StridedSpan< const ModelInstance3D > instances, StridedSpan< const bool > instancesVisible)
Add a list of instances of a 3D model to be rendered using the default PBR shader if they are in a vi...
void putShadedModelInstance(auto &&shaderPipelineSelector, const Model3D &model, const mat4 &transformation, resource::Model::PoseView pose, const ModelInstance3D &instance={})
Add a 3D model instance to be rendered in a specific local pose using a specific shader pipeline.
Definition Instances3D.hpp:1228
void putShadedQuadInstance(const Model2D::ShaderPipeline &shaderPipeline, const QuadInstance3D &instance)
Add a quad instance to be rendered using a specific shader pipeline.
void putVisibleUnlitModelInstances(const Model3D &model, StridedSpan< const resource::Model::TransformationView > transformations, StridedSpan< const ModelInstance3D > instances, StridedSpan< const bool > instancesVisible)
Add a list of instances of a 3D model to be rendered using the default unlit shader if they are in a ...
void putPBRModelInstance(const Model3D &model, const mat4 &transformation, const ModelInstance3D &instance={})
Add a 3D model instance to be rendered in its default bind pose using the default PBR shader.
void putShadedFlatModelInstance(const Model2D::ShaderPipeline &shaderPipeline, const Model2D &model, const FlatModelInstance3D &instance)
Add a flat 2D model instance to be rendered using a specific shader pipeline.
void putShadedModelInstances(auto &&shaderPipelineSelector, const Model3D &model, StridedSpan< const resource::Model::TransformationView > transformations)
Add a list of instances of a 3D model to be rendered using a specific shader pipeline.
Definition Instances3D.hpp:1305
void putPBRModelInstance(const Model3D &model, const mat4 &transformation, resource::Model::PoseView pose, const ModelInstance3D &instance)
Add a 3D model instance to be rendered in a specific local pose using the default PBR shader.
void putPBRModelInstances(const Model3D &model, StridedSpan< const resource::Model::TransformationView > transformations, StridedSpan< const ModelInstance3D > instances)
Add a list of instances of a 3D model to be rendered using the default PBR shader.
void putFlatModelInstance(const Model2D &model, const FlatModelInstance3D &instance)
Add a flat 2D model instance to be rendered using a plain 2D model shader.
void putQuadInstance(const QuadInstance3D &instance)
Add a quad instance to be rendered using a plain 2D model shader.
void putUnlitModelInstance(const Model3D &model, const mat4 &transformation, resource::Model::PoseView pose, const ModelInstance3D &instance={})
Add a 3D model instance to be rendered in a specific local pose using the default unlit shader.
void putVisibleShadedModelInstances(auto &&shaderPipelineSelector, const Model3D &model, StridedSpan< const resource::Model::TransformationView > transformations, StridedSpan< const ModelInstance3D > instances, StridedSpan< const bool > instancesVisible)
Add a list of instances of a 3D model to be rendered using a specific shader pipeline if they are in ...
Definition Instances3D.hpp:1333
void putUnlitModelInstance(const Model3D &model, resource::Model::TransformationView transformation, const ModelInstance3D &instance={})
Add a 3D model instance to be rendered using the default unlit shader.
void putShadedModelInstances(auto &&shaderPipelineSelector, const Model3D &model, StridedSpan< const resource::Model::TransformationView > transformations, StridedSpan< const ModelInstance3D > instances)
Add a list of instances of a 3D model to be rendered using a specific shader pipeline.
Definition Instances3D.hpp:1254
void putShadedModelInstance(auto &&shaderPipelineSelector, const Model3D &model, resource::Model::TransformationView transformation, const ModelInstance3D &instance={})
Add a 3D model instance to be rendered using a specific shader pipeline.
Definition Instances3D.hpp:1180
void putSpriteInstance(const SpriteAtlas &spriteAtlas, SpriteID spriteID, const SpriteInstance3D &instance)
Add a sprite instance to be rendered using a plain 2D model shader.
void putUnlitModelInstances(const Model3D &model, StridedSpan< const resource::Model::TransformationView > transformations, StridedSpan< const ModelInstance3D > instances)
Add a list of instances of a 3D model to be rendered using the default unlit shader.
void putUnlitModelInstance(const Model3D &model, const mat4 &transformation, const ModelInstance3D &instance={})
Add a 3D model instance to be rendered in its default bind pose using the default unlit shader.
void putShadedTextStringInstance(const Model2D::ShaderPipeline &shaderPipeline, Font2D &font, UTF8StringView string, const TextStringInstance3D &instance)
Add a 3D text string instance to be rendered using a specific shader pipeline.
Instances3D(Device &device, Renderer3D &renderer3D)
Construct a batch of instances.
Definition Instances3D.hpp:508
void putTextInstance(const Text2D &text, const TextInstance3D &instance)
Add a 3D text instance to be rendered using a plain 3D text shader.
void putShadedTriangleInstance(const Model2D::ShaderPipeline &shaderPipeline, const TriangleInstance3D &instance)
Add a triangle instance to be rendered using a specific shader pipeline.
void putTriangleInstance(const TriangleInstance3D &instance)
Add a triangle instance to be rendered using a plain 2D model shader.
void putHDRUnlitModelInstance(const Model3D &model, const mat4 &transformation, resource::Model::PoseView pose, const ModelInstance3D &instance={})
Add a 3D model instance to be rendered in a specific local pose using the default HDR unlit shader.
void putVisibleShadedModelInstances(auto &&shaderPipelineSelector, const Model3D &model, StridedSpan< const resource::Model::TransformationView > transformations, const ModelInstance3D &instance, StridedSpan< const bool > instancesVisible)
Add a list of instances of a 3D model to be rendered using a specific shader pipeline if they are in ...
Definition Instances3D.hpp:1362
void putHDRUnlitModelInstances(const Model3D &model, StridedSpan< const resource::Model::TransformationView > transformations, StridedSpan< const ModelInstance3D > instances)
Add a list of instances of a 3D model to be rendered using the default HDR unlit shader.
void putPBRModelInstance(const Model3D &model, resource::Model::TransformationView transformation, const ModelInstance3D &instance={})
Add a 3D model instance to be rendered using the default PBR shader.
void putShadedTextInstance(const Model2D::ShaderPipeline &shaderPipeline, const Text2D &text, const TextInstance3D &instance)
Add a 3D text instance to be rendered using a specific shader pipeline.
void putTextStringInstance(Font2D &font, UTF8StringView string, const TextStringInstance3D &instance)
Add a 3D text string instance to be rendered using a plain 3D text shader.
Container for a set of 2D triangle strip meshes stored on the GPU.
Definition Model2D.hpp:30
graphics::ShaderPipeline< Mesh > ShaderPipeline
Shader pipeline for drawing 2D models.
Definition Model2D.hpp:152
Container for a set of 3D triangle mesh nodes stored on the GPU.
Definition Model3D.hpp:67
const resource::Model::Pose & getBindPose() const noexcept
Get the local bind pose of the model.
Definition Model3D.hpp:935
resource::Model::JointCount getJointCount() const noexcept
Get the number of joints in the model.
Definition Model3D.hpp:944
resource::Model::MorphTargetWeightCount getMorphTargetWeightCount() const noexcept
Get the number of morph target weights of the model.
Definition Model3D.hpp:963
BufferSet< JointBuffer, MorphTargetWeightBuffer > InstanceBuffers
Set of shader buffers related to the dynamic data of 3D model instances.
Definition Model3D.hpp:355
Span< const resource::Model::JointIndex > getJointParentIndices() const noexcept
Get the indices of the parent joints of each joint of the model.
Definition Model3D.hpp:972
graphics::ShaderPipeline< Mesh > ShaderPipeline
Shader pipeline for drawing 3D models.
Definition Model3D.hpp:398
Persistent system that provides 3D rendering capabilities.
Definition Renderer3D.hpp:120
Linked GPU shader pipeline.
Definition shaders.hpp:1508
Expandable texture atlas for packing 2D images into a spritesheet to enable batch rendering.
Definition SpriteAtlas.hpp:173
Facility for shaping text, according to a Font2D, into renderable glyphs.
Definition Text2D.hpp:206
Storage for multidimensional data, such as 2D images, on the GPU, combined with a sampler configurati...
Definition Texture.hpp:700
Definition buffer_layouts.hpp:20
Definition Window.hpp:15
qua< float > quat
Definition math.hpp:892
vec< 2, float > vec2
Definition math.hpp:438
GREM_ALWAYS_INLINE void lock(Lockable1 &lock1, Lockable2 &lock2, LockableN &... lockN)
Definition synchronization.hpp:1268
vec< 3, float > vec3
Definition math.hpp:439
mat< 2, 2, float > mat2
Definition math.hpp:804
mat< 4, 4, float > mat4
Definition math.hpp:806
StringViewBase< char, std::char_traits< char > > StringView
Definition StringView.hpp:16
StringViewBase< char8_t, std::char_traits< char8_t > > UTF8StringView
Definition StringView.hpp:17
Configuration of a flat Model2D instance to draw in 3D.
Definition Instances3D.hpp:97
const Texture * texture
Non-owning pointer to a texture to apply to the model, or nullptr to use a fully white texture.
Definition Instances3D.hpp:105
Color color
Tint color to use in the shader.
Definition Instances3D.hpp:141
float distanceOrderingBias
Bias to subtract from the model's distance from the camera, which is used for distance ordering when ...
Definition Instances3D.hpp:157
vec2 textureOffset
Offset, in texture coordinates, to apply to the texture coordinates before sampling the texture.
Definition Instances3D.hpp:119
mat4 transformation
Transformation of the model instance.
Definition Instances3D.hpp:110
mat2 textureBasis
Texture coordinate basis to scale/rotate/shear the texture coordinates by before sampling the texture...
Definition Instances3D.hpp:128
Color emissiveColor
Emissive color to use in the shader.
Definition Instances3D.hpp:151
Filter parameters that determine which instances in a 3D batch to draw.
Definition Instances3D.hpp:1724
bool skipAlphaBlendedModelMeshInstances
If set, alpha-blended model mesh instances will not be drawn.
Definition Instances3D.hpp:1731
FunctionView< bool(vec3 position, float boundingRadius, float distanceOrderingBias)> transparentInstanceFilter
Function that determines whether a specific transparent instance should be drawn or not.
Definition Instances3D.hpp:1726
bool skipOpaqueModelMeshInstances
If set, non-alpha-blended model mesh instances will not be drawn.
Definition Instances3D.hpp:1734
bool skipAll2DInstances
If set, 2D instances will not be drawn.
Definition Instances3D.hpp:1740
bool skipAll3DInstances
If set, 3D instances will not be drawn.
Definition Instances3D.hpp:1737
Instances3DFilter filter
Filter parameters that determine which instances to draw.
Definition Instances3D.hpp:1757
Instances3DView(const Instances3D &instances, const Model2D::ShaderPipeline &shaderPipelineOverride2D, const Model3D::ShaderPipeline &shaderPipelineOverride3D, const Instances3DFilter &filter={})
Construct an instance batch view with both 2D and 3D shader overrides.
Definition Instances3D.hpp:1805
const Instances3D * instances
Non-owning read-only pointer to the batch of instances.
Definition Instances3D.hpp:1748
SharedPointer< ShaderPipelineImplementation > shaderPipelineOverride2DHandle
Shader pipeline override to use for 2D mesh instances, or nullptr to not use a shader override.
Definition Instances3D.hpp:1751
Instances3DView(const Instances3D &instances, const Model3D::ShaderPipeline &shaderPipelineOverride3D, const Instances3DFilter &filter={})
Construct an instance batch view with a 3D shader override.
Definition Instances3D.hpp:1790
Instances3DView(const Instances3D &instances, const Instances3DFilter &filter={})
Construct an instance batch view.
Definition Instances3D.hpp:1765
Instances3DView(const Instances3D &instances, const Model2D::ShaderPipeline &shaderPipelineOverride2D, const Instances3DFilter &filter={})
Construct an instance batch view with a 2D shader override.
Definition Instances3D.hpp:1777
SharedPointer< ShaderPipelineImplementation > shaderPipelineOverride3DHandle
Shader pipeline override to use for 3D mesh instances, or nullptr to not use a shader override.
Definition Instances3D.hpp:1754
Configuration options for shading a mesh instance of a 3D model.
Definition Model3D.hpp:81
Configuration of a Model3D instance to draw.
Definition Instances3D.hpp:47
vec3 emissiveFactor
Emissive factor to use in the shader.
Definition Instances3D.hpp:75
Color emissiveColor
Emissive color to use in the shader.
Definition Instances3D.hpp:66
float distanceOrderingBias
Bias to subtract from the model's distance from the camera, which is used for distance ordering when ...
Definition Instances3D.hpp:91
uint32_t instanceIdentifier
Instance identifier that can be used to identify this instance in shaders.
Definition Instances3D.hpp:82
Color color
Tint color to use in the shader.
Definition Instances3D.hpp:56
Configuration of a 3D quadrilateral instance, optionally textured, to draw.
Definition Instances3D.hpp:229
vec2 origin
Offset, in local vertex coordinates, specifying the origin relative to the bottom left of the quad.
Definition Instances3D.hpp:259
quat orientation
Rotation of the quad around its QuadInstance3D::origin.
Definition Instances3D.hpp:247
mat2 textureBasis
Texture coordinate basis to scale/rotate/shear the texture coordinates by before sampling the texture...
Definition Instances3D.hpp:277
vec2 size
Size of the quad, in world coordinates.
Definition Instances3D.hpp:252
float distanceOrderingBias
Bias to subtract from the quad's distance from the camera, which is used for distance ordering when d...
Definition Instances3D.hpp:306
Color color
Tint color to use in the shader.
Definition Instances3D.hpp:290
Color emissiveColor
Emissive color to use in the shader.
Definition Instances3D.hpp:300
vec3 position
Position, in world coordinates, to draw the quad at.
Definition Instances3D.hpp:242
const Texture * texture
Non-owning pointer to a texture to apply to the quad, or nullptr to use a fully white texture.
Definition Instances3D.hpp:237
vec2 textureOffset
Offset, in texture coordinates, to apply to the texture coordinates before sampling the texture.
Definition Instances3D.hpp:268
Identifier for a specific image in a SpriteAtlas.
Definition SpriteAtlas.hpp:124
Configuration of a 3D sprite instance from a SpriteAtlas to draw.
Definition Instances3D.hpp:312
float distanceOrderingBias
Bias to subtract from the sprite's distance from the camera, which is used for distance ordering when...
Definition Instances3D.hpp:359
Color color
Tint color to use in the shader.
Definition Instances3D.hpp:343
Color emissiveColor
Emissive color to use in the shader.
Definition Instances3D.hpp:353
quat orientation
Rotation of the sprite around its SpriteInstance3D::origin.
Definition Instances3D.hpp:321
vec2 origin
Offset, in local vertex coordinates, specifying the origin relative to the bottom left of the sprite.
Definition Instances3D.hpp:333
vec3 position
Position, in world coordinates, to draw the sprite at.
Definition Instances3D.hpp:316
vec2 size
Size of the sprite, in world coordinates.
Definition Instances3D.hpp:326
Text alignment mode.
Definition Text2D.hpp:53
static const TextAlign NONE
No alignment.
Definition Text2D.hpp:54
Configuration of a 3D instance of Text2D shaped from a Font2D to draw.
Definition Instances3D.hpp:365
float distanceOrderingBias
Bias to subtract from the text's distance from the camera, which is used for distance ordering when d...
Definition Instances3D.hpp:410
vec2 alignmentOffset
Additional offset to apply to the text after applying the specified alignment.
Definition Instances3D.hpp:399
TextAlign alignment
Alignment mode of the text.
Definition Instances3D.hpp:393
quat orientation
Rotation of the text around its TextInstance3D::origin.
Definition Instances3D.hpp:375
vec2 scale
Coefficients to scale the size of the text by.
Definition Instances3D.hpp:388
vec3 position
Starting position, in world coordinates, to draw the text at.
Definition Instances3D.hpp:370
Color color
Base text color.
Definition Instances3D.hpp:404
Configuration of a 3D instance of a string of text to draw using a Font2D.
Definition Instances3D.hpp:416
uint32_t characterSize
Character size to shape the glyphs at.
Definition Instances3D.hpp:420
float distanceOrderingBias
Bias to subtract from the text's distance from the camera, which is used for distance ordering when d...
Definition Instances3D.hpp:488
vec2 scale
Coefficients to scale the size of the text by.
Definition Instances3D.hpp:466
Color color
Base text color.
Definition Instances3D.hpp:482
quat orientation
Rotation of the text around its TextStringInstance3D::origin.
Definition Instances3D.hpp:431
vec2 shapeOrigin
Offset, in normalized coordinates, specifying the origin relative to the baseline of the first line o...
Definition Instances3D.hpp:453
TextAlign alignment
Alignment mode of the text.
Definition Instances3D.hpp:471
vec2 alignmentOffset
Additional offset to apply to the text after applying the specified alignment.
Definition Instances3D.hpp:477
vec3 position
Starting position, in world coordinates, to draw the text at.
Definition Instances3D.hpp:426
vec2 shapeScale
Scaling to apply to the size of the shaped glyphs.
Definition Instances3D.hpp:444
Configuration of an arbitrarily transformed 3D triangle instance, optionally textured,...
Definition Instances3D.hpp:164
float distanceOrderingBias
Bias to subtract from the triangle's distance from the camera, which is used for distance ordering wh...
Definition Instances3D.hpp:223
mat2 textureBasis
Texture coordinate basis to scale/rotate/shear the texture coordinates by before sampling the texture...
Definition Instances3D.hpp:194
vec3 pointC
Position, in world coordinates, of the third vertex of the triangle to draw.
Definition Instances3D.hpp:176
const Texture * texture
Non-owning pointer to a texture to apply to the triangle, or nullptr to use a fully white texture.
Definition Instances3D.hpp:172
vec3 pointB
Position, in world coordinates, of the second vertex of the triangle to draw.
Definition Instances3D.hpp:175
vec3 pointA
Position, in world coordinates, of the first vertex of the triangle to draw.
Definition Instances3D.hpp:174
vec2 textureOffset
Offset, in texture coordinates, to apply to the texture coordinates before sampling the texture.
Definition Instances3D.hpp:185
Color color
Tint color to use in the shader.
Definition Instances3D.hpp:207
Color emissiveColor
Emissive color to use in the shader.
Definition Instances3D.hpp:217
Read-only view over a local pose of a model.
Definition Model.hpp:682
const Joint * localJoints
Non-owning read-only pointer to the current local joints of the pose.
Definition Model.hpp:686
const float * localMorphTargetWeights
Non-owning read-only pointer to the current local morph target weights of the pose.
Definition Model.hpp:692
Local pose of a model.
Definition Model.hpp:733
ArrayList< Joint > localJoints
Current local joints of the pose.
Definition Model.hpp:734
ArrayList< float > localMorphTargetWeights
Current local morph target weights of the pose.
Definition Model.hpp:735
Read-only view over a world-space transformation of a model.
Definition Model.hpp:772
World-space transformation of a model.
Definition Model.hpp:818
void assign(const mat4 &rootTransformation, Span< const Joint > localJoints, Span< const float > localMorphTargetWeights, Span< const JointIndex > modelJointParentIndices)
Assign new joints and morph target weights to the transformation according to a local pose,...
Definition Model.hpp:858