3#include "Resources/MaterialInstance.h"
7#include "RenderStates.h"
8#include "RenderResource.h"
9#include "../Components/Core/RenderComponent.h"
11#include "Foundation/Geometry/BoundingBox.hpp"
15 struct RenderTaskContext;
17 enum struct RenderItemFlags : uint16_t
22 CalculateDepth = 1 << 2,
28 CustomBucket = 1 << 8,
29 CustomBounds = 1 << 9,
33 ObjectBufferSlot = 1 << 13
35 ENABLE_ENUM_FLAGS(RenderItemFlags);
37 enum struct StateChangeFlags : uint16_t {
39 ChangeTransform = 1 << 0,
41 ChangeMaterialInstance = 1 << 2,
42 ChangeMaterialVariant = 1 << 3,
43 ChangeRasterizerState = 1 << 4,
44 ChangeBlendState = 1 << 5,
45 ChangeDepthStencilState = 1 << 6,
47 ChangeViewport = 1 << 8,
48 ChangeViewportData = 1 << 9,
51 ENABLE_ENUM_FLAGS(StateChangeFlags);
72 Annotation = 1 <<
size_t(BucketType::Annotation),
73 Overlay = 1 << size_t(BucketType::Overlay),
74 Custom = 1 << size_t(BucketType::Custom),
78 ENABLE_ENUM_FLAGS(BucketMask);
80 inline bool hasBucket(BucketMask bucketMask,
BucketType bucket)
82 return (
size_t(bucketMask) & (
size_t(1) <<
size_t(bucket))) != 0;
91 bool isCustom()
const {
return (flags & (RenderItemFlags::Custom | RenderItemFlags::Custom2)) != 0; }
92 bool isCustom1()
const {
return (flags & RenderItemFlags::Custom) != 0; }
93 bool isCustom2()
const {
return (flags & RenderItemFlags::Custom2) != 0; }
94 bool isSprite()
const {
return (flags & RenderItemFlags::Sprite) != 0; }
95 bool isClockwise()
const {
return (flags & RenderItemFlags::Clockwise) != 0; }
96 bool isTransparent()
const {
return (flags & RenderItemFlags::Transparent) != 0; }
97 bool isCustomBucket()
const {
return (flags & RenderItemFlags::CustomBucket) != 0; }
98 bool isBackdrop()
const {
return (flags & RenderItemFlags::Backdrop) != 0; }
99 bool needsDepthCalculation()
const {
return (flags & RenderItemFlags::CalculateDepth) != 0; }
100 bool hasBoundingBox()
const {
return (flags & RenderItemFlags::CustomBounds) != 0; }
101 bool isCulled()
const {
return !hasBoundingBox() && !isCustom(); }
102 bool isInstanced()
const {
return (flags & RenderItemFlags::Instanced) != 0; }
103 bool hasObjectBufferSlot()
const {
return (flags & RenderItemFlags::ObjectBufferSlot) != 0; }
105 void setBounds(
const Geometry::BoundingBox* bounds)
107 boundingBox = bounds;
108 flags |= RenderItemFlags::CustomBounds;
112 void setCallbackData(T* t)
const { callbackData = t; }
115 void setCallbackData2(T* t)
const { callbackData2 = t; }
118 T* getCallbackData()
const {
return static_cast<T*
>(callbackData); }
121 T* getCallbackData2()
const {
return static_cast<T*
>(callbackData2); }
129 const struct CameraData * viewportData =
nullptr;
130 const struct PoseData * poseData =
nullptr;
133 uint32_t cullingIndex;
134 const Geometry::BoundingBox* boundingBox =
nullptr;
144 const glm::mat4* worldMatrix;
151 uint32_t startInstance;
152 uint32_t numInstances;
163 CustomCallback* callback;
164 CustomCallback2* callback2;
166 mutable void* callbackData;
167 mutable void* callbackData2;
176 uint32_t objectId = 0;
179 RenderItemFlags flags = RenderItemFlags::None;
186 uint16_t blendState = 0;
187 uint16_t depthState = 0;
188 uint16_t rasterizerState = 0;
189 uint8_t clipShapeIx = 0;
192 hashValue =
Cogs::hash(
reinterpret_cast<intptr_t
>(renderMaterialInstance), hashValue);
193 hashValue =
Cogs::hash(
reinterpret_cast<intptr_t
>(materialInstance), hashValue);
194 hashValue =
Cogs::hash(
reinterpret_cast<intptr_t
>(binding), hashValue);
195 hashValue =
Cogs::hash(
reinterpret_cast<intptr_t
>(viewportData), hashValue);
196 hashValue =
Cogs::hash(
reinterpret_cast<intptr_t
>(poseData), hashValue);
198 if (hasBoundingBox()) {
199 hashValue =
Cogs::hash(
reinterpret_cast<intptr_t
>(boundingBox), hashValue);
202 hashValue =
Cogs::hash(cullingIndex, hashValue);
207 hashValue =
Cogs::hash(
reinterpret_cast<intptr_t
>(worldMatrix), hashValue);
208 hashValue =
Cogs::hash(
reinterpret_cast<intptr_t
>(meshData), hashValue);
209 hashValue =
Cogs::hash(startIndex, hashValue);
210 hashValue =
Cogs::hash(numIndexes, hashValue);
211 hashValue =
Cogs::hash(
reinterpret_cast<intptr_t
>(instanceData), hashValue);
212 hashValue =
Cogs::hash(startInstance, hashValue);
213 hashValue =
Cogs::hash(numInstances, hashValue);
214 hashValue =
Cogs::hash(primitiveType, hashValue);
217 hashValue =
Cogs::hash(
reinterpret_cast<intptr_t
>(streamsLayout), hashValue);
218 hashValue =
Cogs::hash(
reinterpret_cast<intptr_t
>(callback), hashValue);
219 hashValue =
Cogs::hash(
reinterpret_cast<intptr_t
>(callbackData), hashValue);
220 hashValue =
Cogs::hash(
reinterpret_cast<intptr_t
>(callbackData2), hashValue);
226 hashValue =
Cogs::hash(lod.lodFraction, hashValue);
233 hashValue =
Cogs::hash(blendState, hashValue);
234 hashValue =
Cogs::hash(depthState, hashValue);
235 hashValue =
Cogs::hash(rasterizerState, hashValue);
236 hashValue =
Cogs::hash(clipShapeIx, hashValue);
242 typedef std::vector<RenderItem> RenderItems;
250 current = allItems.data();
255 RenderItem * begin() {
return allItems.data(); }
257 const RenderItem * begin()
const {
return allItems.data(); }
258 const RenderItem * end()
const {
return current; }
259 size_t size()
const {
return size_t(current - begin()); }
260 bool empty()
const {
return begin() == end(); }
263 assert(idx < size());
266 const RenderItem& operator[](
size_t idx)
const
268 assert(idx < size());
272 void clear() { current = allItems.data(); }
276 const size_t sz = size();
277 if (sz == allItems.size()) {
278 allItems.resize(allItems.size() * 2);
279 current = allItems.data() + sz;
288 item.cullingIndex = (uint32_t)-1;
289 item.flags = RenderItemFlags::Custom;
294 RenderItems allItems;
297 size_t generation = 0;
298 size_t missing = (size_t)-1;
305 RenderItem * begin() {
return batch.begin(); }
307 const RenderItem * begin()
const {
return batch.begin(); }
308 const RenderItem * end()
const {
return batch.end(); }
309 size_t size()
const {
return batch.size(); }
313 batches = { &batch };
319 rv.streamsLayout = streamsLayout;
325 std::vector<RenderBatch *> batches;
327 RenderItems buckets[size_t(BucketType::Count)];
330 const struct CameraData * viewportData =
nullptr;
336template<>
inline Cogs::StringView getName<Cogs::Core::StateChangeFlags>() {
return "StateChangeFlags"; }
337template<>
inline Cogs::StringView getName<Cogs::Core::BucketMask>() {
return "BucketMask"; }
Provides a weakly referenced view over the contents of a string.
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
@ CastShadows
Casts shadows.
@ DisableCulling
Disable culling and always force this component to be rendered.
@ SolidOrderedBack
Opaque ordered geometry behind un-ordered geometry.
@ Transparent
Transparent geometry rendered after the opaque geometry.
@ SolidOrderedFront
Opaque ordered geometry in front of un-ordered geometry.
@ Solid
Opaque geometry in arbitrary order.
@ Backdrop
Background geometry behind everything else.
RenderLayers
Contains common render layers.
constexpr size_t hash() noexcept
Simple getter function that returns the initial value for fnv1a hashing.
PrimitiveType
Primitive types for interpreting vertex data sent to the graphics pipeline.
Contains data describing a Camera instance and its derived data structured such as matrix data and vi...
Material instances represent a specialized Material combined with state for all its buffers and prope...
Lod data holding the LoD state of the entity this render component belongs to.
uint8_t numLods
Total number of LoDs available.
uint8_t currentLod
The assigned LoD of the current component.
uint8_t selectedLod
The selected LoD of the composite entity.
uint32_t objectBufferSlot
Set if ObjectBufferSlot is set (then transform and objectId is in the object buffer).
int32_t drawOrder
Ordering of draw items within a bucket.
uint32_t objectId
Lower 6 of upper 8 bits are instance id bits, lower 24 bits are object id.
RenderLayers layer
Visibility mask.
StateChangeFlags stateChanges
Encodes what state changed from previous item, updated by FilterListTask.
float depth
Used for depth-sorting of transparent objects.
static const Handle_t NoHandle
Represents a handle to nothing.
handle_type handle
Internal resource handle.