Cogs.Core
HighlightRegionRenderer.cpp
1#include "Foundation/Logging/Logger.h"
2
3#include "Rendering/IBuffers.h"
4#include "Rendering/ICapabilities.h"
5#include "Rendering/IContext.h"
6#include "Rendering/IEffects.h"
7#include "Rendering/IGraphicsDevice.h"
8#include "Rendering/IRenderTargets.h"
9
10#include "Components/Core/ClipShapeComponent.h"
11
12#include "Resources/MaterialInstance.h"
13
14#include "Systems/Core/CameraSystem.h"
15
16#include "Renderer/Renderer.h"
17#include "Renderer/Tasks/RenderTask.h"
18#include "Renderer/Tasks/FilterListTask.h"
19#include "Renderer/RenderTarget.h"
20#include "Renderer/RenderStateUpdater.h"
21
22#include "HighlightRegionSystem.h"
23#include "HighlightRegionRenderer.h"
24
25namespace {
26 using namespace Cogs::Core;
27 Cogs::Logging::Log logger = Cogs::Logging::getLogger("HighlightRegion");
28
29 struct Matrices {
30 glm::mat4 clipFromLocal;
31 glm::mat4 localFromClip;
32 glm::vec4 eye;
33 glm::vec4 nearPlaneLocal;
34 glm::vec4 viewPlaneLocal;
35 };
36
37 void setTexture(Cogs::IContext* deviceContext, RenderMaterialInstance* renderMaterialInstance, const EffectBinding* binding, RenderTexture* texture, VariableKey key)
38 {
39 if (key == NoProperty) return;
40
41 const Cogs::TextureBindingHandle& texBinding = binding->textureBindings[key];
42 if (texture && HandleIsValid(texture->textureHandle)) {
43 deviceContext->setTexture(texBinding, texture->textureHandle);
44 }
45 else {
46 deviceContext->setTexture(texBinding, Cogs::TextureHandle::NoHandle);
47 }
48
49 const Cogs::SamplerStateBindingHandle& samplerBinding = binding->samplerBindings[key];
50 if (HandleIsValid(renderMaterialInstance->samplerStates[key])) {
51 deviceContext->setSamplerState(samplerBinding, renderMaterialInstance->samplerStates[key]);
52 }
53 else {
54 deviceContext->setSamplerState(samplerBinding, Cogs::SamplerStateHandle::NoHandle);
55 }
56 }
57
58}
59
60namespace {
61
62 uint32_t packSplitVertex4(size_t a, size_t b, size_t c, size_t d)
63 {
64 return static_cast<uint32_t>(((d) << 9) | ((c ) << 6) | ((b ) << 3) | ((a ) << 0));
65 }
66
67 uint32_t packSplitVertex2(size_t a, size_t b)
68 {
69 return packSplitVertex4(a, a, b, b);
70 }
71
72 uint32_t packSplitVertex1(size_t a)
73 {
74 return packSplitVertex4(a, a, a, a);
75 }
76
77}
78
80{
83 LOG_WARNING_ONCE(logger, "HighlightRegionRenderer only supports OpenGLES30 or WebGPU currently");
84 return;
85 }
86
87 Cogs::VertexElement vertexElements[1] = {
88 Cogs::VertexElement{0, Cogs::DataFormat::R32G32B32_FLOAT, Cogs::ElementSemantic::Position, 0, Cogs::InputType::VertexData, 0}
89 };
90 VertexFormatHandle vertexFormatHandle = VertexFormats::createVertexFormat(vertexElements, std::size(vertexElements));
91
92 Cogs::VertexElement splitCubeVertexElements[1] = {
94 };
95 VertexFormatHandle splitCubeVertexFormatHandle = VertexFormats::createVertexFormat(splitCubeVertexElements, std::size(splitCubeVertexElements));
96
97 Cogs::VertexElement instanceElements[2] = {
98 Cogs::VertexElement { 0 * sizeof(glm::mat4), Cogs::DataFormat::MAT4X4_FLOAT, Cogs::ElementSemantic::InstanceMatrix, 0, Cogs::InputType::InstanceData, 1 },
99 Cogs::VertexElement { 1 * sizeof(glm::mat4), Cogs::DataFormat::MAT4X4_FLOAT, Cogs::ElementSemantic::InstanceMatrix, 1, Cogs::InputType::InstanceData, 1 }
100 };
101
102 VertexFormatHandle instanceFormatHandle = VertexFormats::createVertexFormat(instanceElements, std::size(instanceElements));
103 assert(Cogs::getSize(instanceFormatHandle) == sizeof(HighlightRegionInstanceData));
104
105 solidStreamsLayout.vertexFormats[0] = vertexFormatHandle;
106 solidStreamsLayout.vertexFormats[1] = instanceFormatHandle;
107 solidStreamsLayout.numStreams = 2;
108 solidStreamsLayout.updateHash();
109
110 splitCubeStreamsLayout.vertexFormats[0] = splitCubeVertexFormatHandle;
111 splitCubeStreamsLayout.vertexFormats[1] = instanceFormatHandle;
112 splitCubeStreamsLayout.numStreams = 2;
113 splitCubeStreamsLayout.updateHash();
114
115 Cogs::IBuffers* buffers = device->getBuffers();
116
117 {
118 static const float cubeVertexData[8][3] = {
119 { -1, -1, -1 },
120 { 1, -1, -1 },
121 { -1, 1, -1 },
122 { 1, 1, -1 },
123 { -1, -1, 1 },
124 { 1, -1, 1 },
125 { -1, 1, 1 },
126 { 1, 1, 1 },
127 };
128 static_assert(std::size(cubeVertexData) == 8);
129 cubeVertices = buffers->loadVertexBuffer(cubeVertexData, std::size(cubeVertexData), solidStreamsLayout.vertexFormats[0]);
130
131 static const uint16_t cubeTriIndicesData[] = {
132 0, 3, 1, 0, 2, 3,
133 0, 1, 5, 0, 5, 4,
134 1, 3, 7, 7, 5, 1,
135 4, 6, 2, 4, 2, 0,
136 2, 7, 3, 7, 2, 6,
137 4, 7, 6, 4, 5, 7
138 };
139 cubeTriIndicesCount = static_cast<uint32_t>(std::size(cubeTriIndicesData));
140 cubeTriIndices = buffers->loadIndexBuffer(cubeTriIndicesData, cubeTriIndicesCount, sizeof(cubeTriIndicesData[0]));
141 }
142
143 {
144 static const uint32_t splitCubeVertexData[26] = {
145 packSplitVertex1(0), // glm::vec3( -1, -1, -1 ),
146 packSplitVertex2(0, 1), // glm::vec3( 0, -1, -1 ),
147 packSplitVertex1(1), // glm::vec3( 1, -1, -1 ),
148 packSplitVertex2(0, 2), // glm::vec3( -1, 0, -1 ),
149 packSplitVertex4(0, 2, 3, 1), // glm::vec3( 0, 0, -1 ),
150 packSplitVertex2(1, 3), // glm::vec3( 1, 0, -1 ),
151 packSplitVertex1(2), // glm::vec3( -1, 1, -1 ),
152 packSplitVertex2(2, 3), // glm::vec3( 0, 1, -1 ),
153 packSplitVertex1(3), // glm::vec3( 1, 1, -1 ),
154
155 packSplitVertex2(0, 4), // glm::vec3( -1, -1, 0 ),
156 packSplitVertex4(0, 1, 5, 4), // glm::vec3( 0, -1, 0 ),
157 packSplitVertex2(1, 5), // glm::vec3( 1, -1, 0 ),
158 packSplitVertex4(0, 4, 6, 2), // glm::vec3( -1, 0, 0 ),
159 packSplitVertex4(1, 3, 7, 5), // glm::vec3( 1, 0, 0 ),
160 packSplitVertex2(2, 6), // glm::vec3( -1, 1, 0 ),
161 packSplitVertex4(2, 6, 7, 3), // glm::vec3( 0, 1, 0 ),
162 packSplitVertex2(3, 7), // glm::vec3( 1, 1, 0 ),
163
164 packSplitVertex1(4), // glm::vec3( -1, -1, 1 ),
165 packSplitVertex2(4, 5), // glm::vec3( 0, -1, 1 ),
166 packSplitVertex1(5), // glm::vec3( 1, -1, 1 ),
167 packSplitVertex2(4, 6), // glm::vec3( -1, 0, 1 ),
168 packSplitVertex4(4, 5, 7, 6), // glm::vec3( 0, 0, 1 ),
169 packSplitVertex2(5, 7), // glm::vec3( 1, 0, 1 ),
170 packSplitVertex1(6), // glm::vec3( -1, 1, 1 ),
171 packSplitVertex2(6, 7), // glm::vec3( 0, 1, 1 ),
172 packSplitVertex1(7) // glm::vec3( 1, 1, 1 ),
173 };
174 splitCubeVertices = buffers->loadVertexBuffer(splitCubeVertexData, std::size(splitCubeVertexData), splitCubeStreamsLayout.vertexFormats[0]);
175
176 static const uint16_t splitCubeTriIndicesData[] = {
177 3, 1, 0, 4, 1, 3,
178 7, 3, 6, 4, 3, 7,
179 5, 7, 8, 4, 7, 5,
180 1, 5, 2, 4, 5, 1,
181
182 18, 20, 17, 21, 20, 18,
183 20, 24, 23, 21, 24, 20,
184 24, 22, 25, 21, 22, 24,
185 22, 18, 19, 21, 18, 22,
186
187 9, 3, 0, 12, 3, 9,
188 3, 14, 6, 12, 14, 3,
189 14, 20, 23, 12, 20, 14,
190 20, 9, 17, 12, 9, 20,
191
192 5, 11, 2, 13, 11, 5,
193 16, 5, 8, 13, 5, 16,
194 22, 16, 25, 13, 16, 22,
195 11, 22, 19, 13, 22, 11,
196
197 14, 7, 6, 15, 7, 14,
198 7, 16, 8, 15, 16, 7,
199 16, 24, 25, 15, 24, 16,
200 24, 14, 23, 15, 14, 24,
201
202 1, 9, 0, 10, 9, 1,
203 11, 1, 2, 10, 1, 11,
204 18, 11, 19, 10, 11, 18,
205 9, 18, 17, 10, 18, 9
206 };
207 splitCubeTriIndicesCount = static_cast<uint32_t>(std::size(splitCubeTriIndicesData));
208 splitCubeTriIndices = buffers->loadIndexBuffer(splitCubeTriIndicesData, splitCubeTriIndicesCount, sizeof(splitCubeTriIndicesData[0]));
209 }
210
211 // We have our own version of this depthStencilHandle since we need the
212 // OrEqual-test in additon to Less/Greater: When depth is clamped behind the
213 // near-plane, both the "normal" geometry and the highlight-region-pass gets
214 // the same value and without OrEqual, highlight-region would loose the tie.
215 // We would like it to win.
216 Cogs::IRenderTargets* renderTargets = device->getRenderTargets();
217 DepthStencilState depthState = { true, false, DepthStencilState::LessOrEqual };
218 noWriteDepthStencilState = renderTargets->loadDepthStencilState(depthState);
219
220 // Whether or not reverse depth should be used is not known this early, so we
221 // cover both cases and choose at render time,
223 noWriteDepthStencilStateReverse = renderTargets->loadDepthStencilState(depthState);
224}
225
226void Cogs::Core::HighlightRegionRenderer::handleEvent(uint32_t eventId, const DrawContext* renderingContext)
227{
228 Cogs::IGraphicsDevice* device = renderingContext->device;
230 device->getType() != Cogs::GraphicsDeviceType::WebGPU) return;
231
232 if (matrices.index == NoProperty && hrSystem->material && hrSystem->material->isActive()) {
233 for (const MaterialPropertyBuffer& buffer: hrSystem->material->constantBuffers.buffers) {
234 if (buffer.name == "Matrices" && sizeof(Matrices) <= buffer.size) {
235 LOG_DEBUG(logger, "Found Matrices buffer: %u (size=%zu)", buffer.index, buffer.size);
236 matrices.index = buffer.index;
238 }
239 }
240 }
241
242
243 Cogs::IBuffers* buffers = device->getBuffers();
244 RenderResources& renderResources = renderingContext->renderer->getRenderResources();
245 switch (eventId) {
247 // Do non-view/pass specific init at pre-render time
248 for (const HighlightRegionComponent& regionComp : hrSystem->pool) {
249 HighlightRegionData& data = hrSystem->getData(&regionComp);
250 if (data.materialInstance && data.materialInstance->isActive()) {
251 data.renderMaterialInstance = renderResources.getRenderMaterialInstance(data.materialInstance);
252 }
253
254 if (!regionComp.isVisible()) {
255 if (HandleIsValid(data.instanceDataHandle)) {
256 buffers->releaseVertexBuffer(data.instanceDataHandle);
257 data.instanceDataHandle = Cogs::BufferHandle::NoHandle;
258 data.instanceDataUpdated = true;
259 }
260 }
261 else {
262 if (data.instanceDataUpdated) {
263 data.instanceDataUpdated = false;
264 if (HandleIsValid(data.instanceDataHandle)) {
265 buffers->releaseVertexBuffer(data.instanceDataHandle);
266 data.instanceDataHandle = Cogs::BufferHandle::NoHandle;
267 }
268 if (!data.instanceData.empty()) {
269 data.instanceDataHandle = buffers->loadVertexBuffer(data.instanceData.data(), data.instanceData.size(), solidStreamsLayout.vertexFormats[1]);
270 }
271 }
272 }
273 }
274 break;
275 default:
276 break;
277 }
278}
279
280void Cogs::Core::HighlightRegionRenderer::generateCommands(const RenderTaskContext* /*renderingContext*/, RenderList* /*renderList*/)
281{
282}
283
284
285void Cogs::Core::HighlightRegionRenderer::render(RenderTaskContext* renderTaskContext, RenderTarget* renderTarget, RenderList* renderList, RenderTexture* color, RenderTexture* depth)
286{
287 if (renderTaskContext->device->getType() != Cogs::GraphicsDeviceType::OpenGLES30 &&
288 renderTaskContext->device->getType() != Cogs::GraphicsDeviceType::WebGPU) return;
289
290 const CameraData* camData = renderList->viewportData;
291 if (!camData) return;
292
293 size_t permutationIndex = 0;
294 EnginePermutation* permutation = renderTaskContext->renderer->getEnginePermutations().get(permutationIndex);
295 if (!permutation) return;
296
297 DrawContext drawContext;
298 drawContext.context = renderTaskContext->context;
299 drawContext.renderer = renderTaskContext->renderer;
300 drawContext.device = drawContext.renderer->getDevice();
301 drawContext.deviceContext = drawContext.device->getImmediateContext();
302 drawContext.cameraData = renderList->viewportData;
303 drawContext.permutation = permutation;
304 drawContext.engineBuffers = &drawContext.renderer->getEngineBuffers();
305 drawContext.taskContext = renderTaskContext;
306 drawContext.renderTarget = renderTarget;
307
308 if (drawContext.permutation == nullptr) return;
309
310 IContext* deviceContext = drawContext.deviceContext;
311 bool reverseDepth = drawContext.taskContext->states->reverseDepth;
312
313 drawContext.renderer->updatePermutation(drawContext.permutation);
314
315 if(renderTaskContext->device->getCapabilities()->getDeviceCapabilities().RenderPass){
316 RenderPassInfo info;
317 info.renderTargetHandle = renderTarget->renderTargetHandle;
318 info.depthStencilHandle = renderTarget->depthTargetHandle;
319 {
320 uint32_t i = 0;
321 info.loadOp[i] = LoadOp::Load;
322 info.storeOp[i] = StoreOp::Store;
323 }
324 info.depthLoadOp = LoadOp::Load;
325 info.depthStoreOp = StoreOp::Store;
326 // info.depthReadOnly = true;
327 deviceContext->beginRenderPass(info);
328 }
329 else{
330 deviceContext->setRenderTarget(renderTarget->renderTargetHandle, renderTarget->depthTargetHandle);
331 }
332
333// if (drawContext.task->viewportFromTarget && drawContext.renderTarget) {
334 if (true) {
335 deviceContext->setViewport(0.f, 0.f, float(drawContext.renderTarget->width), float(drawContext.renderTarget->height));
336 }
337 else {
338 deviceContext->setViewport(camData->viewportOrigin.x, camData->viewportOrigin.y, camData->viewportSize.x, camData->viewportSize.y);
339 }
340
341// deviceContext->setViewport(camData->viewportOrigin.x, camData->viewportOrigin.y, camData->viewportSize.x, camData->viewportSize.y);
342 updateViewportBuffer(renderTaskContext, renderTaskContext->engineBuffers->sceneBufferHandle, renderTaskContext->engineBuffers->viewBufferHandle, renderTarget, camData, nullptr);
343
344 deviceContext->setDepthStencilState(reverseDepth
345 ? noWriteDepthStencilStateReverse
346 : noWriteDepthStencilState);
347 deviceContext->setBlendState(renderTaskContext->states->blendStates[size_t(BlendMode::None)].handle);
348 for (const HighlightRegionComponent& regionComp : hrSystem->pool) {
349 HighlightRegionData& data = hrSystem->getData(&regionComp);
350 if (!HandleIsValid(data.instanceDataHandle) || !data.renderMaterialInstance) continue;
351
352 MaterialInstance* materialInstance = data.renderMaterialInstance->getResource();
353 assert(materialInstance);
354
355 VariableKey colorKey = NoProperty;
356 VariableKey depthKey = NoProperty;
357 for (const TextureValue& texProp : materialInstance->textureVariables) {
358 switch (Cogs::hash(texProp.property->name)) {
359 case Cogs::hash("offscreenColor"):
360 colorKey = texProp.key;
361 break;
362 case Cogs::hash("offscreenDepth"):
363 depthKey = texProp.key;
364 break;
365 default:
366 break;
367 }
368 }
369
370 RenderPassOptions passOptions = initRenderPassOptions(*camData, materialInstance);
371 passOptions.depthBias = reverseDepth ? regionComp.depthConstantBias : -regionComp.depthConstantBias;
372 passOptions.depthSlopedBias = reverseDepth ? regionComp.depthSlopedFactor : -regionComp.depthSlopedFactor;
373 passOptions.setFlag(RenderPassOptions::Flags::NoDepthClip);
374 passOptions.updateHash();
375
376 uint16_t rasterizerState = drawContext.renderer->getRenderStates().getRasterizerState(passOptions, Cogs::RasterizerState::Back, false, true);
377 deviceContext->setRasterizerState(drawContext.taskContext->states->rasterizerStateHandles[rasterizerState]);
378
379 const ClipShapeType clipShape = ClipShapeType::None;
380
381 const EffectBinding* effectBinding = nullptr;
382 if (data.debugForceNoSplit) {
383 effectBinding = data.renderMaterialInstance->checkReady(solidStreamsLayout, drawContext.permutation, passOptions, clipShape);
384 }
385 else {
386 effectBinding = data.renderMaterialInstance->checkReady(splitCubeStreamsLayout, drawContext.permutation, passOptions, clipShape);
387 }
388 if (!effectBinding) continue;
389
390 drawContext.renderer->updatePermutation(permutation);
391 for (const MaterialPropertyBuffer& buffer : permutation->constantBuffers.buffers) {
392 permutation->bufferHandles.resize(permutation->constantBuffers.buffers.size());
393 if (!HandleIsValid(permutation->bufferHandles[buffer.index])) {
394 Cogs::IBuffers* buffers = drawContext.device->getBuffers();
395 permutation->bufferHandles[buffer.index] = buffers->loadBuffer(nullptr, buffer.size, Cogs::Usage::Dynamic, Cogs::AccessMode::Write, Cogs::BindFlags::ConstantBuffer);
396 }
397 deviceContext->updateBuffer(permutation->bufferHandles[buffer.index], buffer.content.data(), buffer.size);
398 deviceContext->setConstantBuffer(buffer.name, permutation->bufferHandles[buffer.index]);
399
400 }
401 applyMaterialPermutation(drawContext.taskContext, &drawContext, effectBinding, data.renderMaterialInstance);
402 applyMaterialInstance(&drawContext, effectBinding, data.renderMaterialInstance);
403 updateEnvironmentBindings(&drawContext, effectBinding);
404 updateSceneBindings(drawContext.taskContext, effectBinding);
405 updateMaterialBindings(&drawContext, data.renderMaterialInstance, effectBinding, true);
406
407 setTexture(deviceContext, data.renderMaterialInstance, effectBinding, color, colorKey);
408 setTexture(deviceContext, data.renderMaterialInstance, effectBinding, depth, depthKey);
409
410 if (HandleIsValid(matrices.buffer) && matrices.index < effectBinding->buffers.size()) {
411 if (const Cogs::ConstantBufferBindingHandle& bufferBinding = effectBinding->bufferBindings[matrices.index]; HandleIsValid(bufferBinding)) {
412
413 glm::dmat4 viewMatrix = camData->viewMatrix;
414 glm::dmat4 viewFromLocal = viewMatrix * glm::dmat4(data.worldMatrix);
415 glm::dmat4 clipFromLocal = glm::dmat4(camData->projectionMatrix) * viewFromLocal;
416 glm::dmat4 localFromClip = glm::inverse(clipFromLocal);
417
418 if (Cogs::MappedBuffer<Matrices> matricesBuffer(deviceContext, matrices.buffer, Cogs::MapMode::WriteDiscard); matricesBuffer) {
419 matricesBuffer->clipFromLocal = clipFromLocal;
420 matricesBuffer->localFromClip = localFromClip;
421 matricesBuffer->eye = glm::inverse(viewFromLocal) * glm::vec4(0,0,0,1); // World eye
422 matricesBuffer->nearPlaneLocal = glm::vec4(0, 0, -1, -camData->nearDistance) * viewFromLocal;
423 matricesBuffer->viewPlaneLocal = glm::vec4(0, 0, -1, 0) * viewFromLocal;
424 }
425 deviceContext->setConstantBuffer(bufferBinding, matrices.buffer);
426 }
427 }
428
429 if (data.debugForceNoSplit) {
430 Cogs::VertexBufferHandle vertexBuffers[2] = {
431 cubeVertices,
432 data.instanceDataHandle
433 };
434 deviceContext->setVertexBuffers(vertexBuffers, std::size(vertexBuffers));
435 deviceContext->setIndexBuffer(cubeTriIndices, 2, 0);
436 deviceContext->drawInstancedIndexed(Cogs::PrimitiveType::TriangleList, 0, data.instanceData.size(), 0, cubeTriIndicesCount);
437 }
438 else {
439 Cogs::VertexBufferHandle vertexBuffers[2] = {
440 splitCubeVertices,
441 data.instanceDataHandle
442 };
443 deviceContext->setVertexBuffers(vertexBuffers, std::size(vertexBuffers));
444 deviceContext->setIndexBuffer(splitCubeTriIndices, 2, 0);
445 deviceContext->drawInstancedIndexed(Cogs::PrimitiveType::TriangleList, 0, data.instanceData.size(), 0, splitCubeTriIndicesCount);
446 }
447 }
448
449 if(renderTaskContext->device->getCapabilities()->getDeviceCapabilities().RenderPass){
450 deviceContext->endRenderPass();
451 }
452}
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Definition: Context.h:83
float depthConstantBias
Pull highlight frontface slightly towards the camera with a constant.
float depthSlopedFactor
Pull highlight frontface slightly towards the camera based on surface slope.
constexpr bool isVisible() const
Check if the entity is visible or not.
Contains render resources used by the renderer.
void updatePermutation(EnginePermutation *permutation) override
Updates the EnginePermutation.
Definition: Renderer.cpp:758
EngineBuffers & getEngineBuffers() override
Get the reference to the EngineBuffers structure.
Definition: Renderer.h:67
RenderStates & getRenderStates() override
Get the reference to the RenderStates structure.
Definition: Renderer.h:68
IGraphicsDevice * getDevice() override
Get the graphics device used by the renderer.
Definition: Renderer.h:45
EnginePermutations & getEnginePermutations() override
Get the reference to the EnginePermutations structure.
Definition: Renderer.h:76
Represents a graphics device used to manage graphics resources and issue drawing commands.
virtual ICapabilities * getCapabilities()=0
Get a pointer to the capability management interface used to query the graphics device capability fla...
virtual IContext * getImmediateContext()=0
Get a pointer to the immediate context used to issue commands to the graphics device.
virtual IBuffers * getBuffers()=0
Get a pointer to the buffer management interface.
virtual GraphicsDeviceType getType() const
Get the type of the graphics device.
virtual IRenderTargets * getRenderTargets()=0
Get a pointer to the render target management interface.
Log implementation class.
Definition: LogManager.h:140
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
ClipShapeType
Specifices what kind of shape a clip shape has.
@ None
No clipping at all.
bool HandleIsValid(const ResourceHandle_t< T > &handle)
Check if the given resource is valid, that is not equal to NoHandle or InvalidHandle.
@ None
No blending enabled for opaque shapes, defaults to Blend for transparent shapes.
uint16_t VariableKey
Used to lookup material properties.
Definition: Resources.h:46
constexpr Log getLogger(const char(&name)[LEN]) noexcept
Definition: LogManager.h:181
@ OpenGLES30
Graphics device using the OpenGLES 3.0 API.
@ WebGPU
Graphics device using the WebGPU API Backend.
constexpr size_t hash() noexcept
Simple getter function that returns the initial value for fnv1a hashing.
Definition: HashFunctions.h:62
@ InstanceData
Per instance data.
@ VertexData
Per vertex data.
@ TriangleList
List of triangles.
@ Position
Position semantic.
@ InstanceMatrix
Instance matrix semantic.
@ Write
The buffer can be mapped and written to by the CPU after creation.
Definition: Flags.h:50
@ ConstantBuffer
The buffer can be bound as input to effects as a constant buffer.
Definition: Flags.h:72
Contains data describing a Camera instance and its derived data structured such as matrix data and vi...
Definition: CameraSystem.h:67
std::vector< MaterialPropertyBuffer > buffers
Constant buffer instances.
void initialize(Context *context, IGraphicsDevice *device) override
Initialize the extension using the given context and device.
void handleEvent(uint32_t eventId, const DrawContext *renderingContext) override
Called when rendering events occur.
Material instances represent a specialized Material combined with state for all its buffers and prope...
std::vector< TextureValue > textureVariables
Texture property values for this instance.
Material property buffers contain properties for a material, such as color, reflectiveness or other v...
ConstantBufferKey index
Index of the buffer in the set of buffers owned by the same Material.
size_t size
Total size of the buffer in bytes.
PropertyName name
Name used to refer to the buffer in shaders.
std::vector< uint8_t > content
Default content for property buffer instances created from this buffer.
PropertyName name
Name of the property, used to reference named uniforms of constant buffer members in shaders.
VertexFormatHandle vertexFormats[maxStreams]
COGSCORE_DLL_API void updateHash()
COGSCORE_DLL_API void updateHash()
@ PreRender
Pre rendering happening for a given rendering context.
Definition: IRenderer.h:93
const TextureProperty * property
Pointer to the property this value is for.
Encapsulates state for depth buffer usage and stencil buffer usage in a state object.
@ GreaterOrEqual
Greater or equal depth.
@ LessOrEqual
Less or equal depth.
DepthFunction depthFunction
The depth function to use for depth testing.
static const Handle_t NoHandle
Represents a handle to nothing.
Definition: Common.h:78
Provides buffer management functionality.
Definition: IBuffers.h:13
virtual void releaseVertexBuffer(VertexBufferHandle vertexBufferHandle)=0
Release the vertex buffer with the given handle.
virtual IndexBufferHandle loadIndexBuffer(const void *indexData, const size_t count, const size_t indexSize)=0
Loads a new index buffer and populates it with the given indexData.
virtual BufferHandle loadBuffer(const void *data, const size_t size, Usage::EUsage usage, uint32_t accessMode, uint32_t bindFlags, uint32_t stride=0)=0
Loads a new buffer using the given data to populate the buffer.
virtual VertexBufferHandle loadVertexBuffer(const void *vertexData, const size_t count, const VertexFormat &vertexFormat)=0
Loads a new vertex buffer and populates it with the given data.
virtual const GraphicsDeviceCapabilities & getDeviceCapabilities() const
Gets the device capabilities in a structure.
Represents a graphics device context which can receive rendering commands.
Definition: IContext.h:43
virtual void setTexture(const StringView &name, unsigned int unit, TextureHandle textureHandle)=0
Sets the texture slot given by unit with the given name to contain the given texture.
virtual void setRasterizerState(const RasterizerStateHandle handle)=0
Set the current rasterizer state.
virtual void setBlendState(const BlendStateHandle handle, const float *constant=nullptr)=0
Set the current blend state.
virtual void drawInstancedIndexed(PrimitiveType primitiveType, const size_t startInstance, const size_t numInstances, const size_t startIndex, const size_t numIndexes)=0
Draws indexed, instanced primitives.
virtual void endRenderPass()=0
End a render pass.
virtual void setIndexBuffer(IndexBufferHandle bufferHandle, uint32_t stride=4, uint32_t offset=0)=0
Sets the current index buffer.
virtual void setDepthStencilState(const DepthStencilStateHandle handle)=0
Set the current depth stencil state.
virtual void setConstantBuffer(const StringView &name, const BufferHandle bufferHandle, const uint32_t offset=0, const uint32_t size=~0u)=0
Sets a constant buffer to be bound to the given name and slot.
virtual void updateBuffer(BufferHandle bufferHandle, const void *data, size_t size)=0
Replace contents of buffer with new data.
virtual void setViewport(const float x, const float y, const float width, const float height)=0
Sets the current viewport to the given location and dimensions.
virtual void beginRenderPass(const RenderPassInfo &info)=0
Begin a render pass.
virtual void setSamplerState(const StringView &name, unsigned int unit, SamplerStateHandle samplerStateHandle)=0
Sets the sampler slot given by unit with the given name to contain the given sampler state.
virtual void setVertexBuffers(const VertexBufferHandle *vertexBufferHandles, const size_t count, const uint32_t *strides, const uint32_t *offsets)=0
Sets the current vertex buffers.
virtual void setRenderTarget(const RenderTargetHandle handle, const DepthStencilHandle depthStencilHandle)=0
Sets the current render target and an associated depth stencil target.
Provides render target management functionality.
virtual DepthStencilStateHandle loadDepthStencilState(const DepthStencilState &depthStencilState)=0
Load a depth stencil state object.
@ WriteDiscard
Write access. When unmapping the graphics system will discard the old contents of the resource.
Definition: Flags.h:103
Provides RAII style mapping of a buffer resource.
Definition: IBuffers.h:160
@ Back
Cull back facing primitives.
@ Dynamic
Buffer will be loaded and modified with some frequency.
Definition: Flags.h:30
Vertex element structure used to describe a single data element in a vertex for the input assembler.
Definition: VertexFormat.h:38