Cogs.Core
HighlightRegionRenderer.cpp
1#include "Foundation/Logging/Logger.h"
2
3#include "Rendering/IGraphicsDevice.h"
4#include "Rendering/IContext.h"
5#include "Rendering/IEffects.h"
6#include "Rendering/IBuffers.h"
7#include "Rendering/IRenderTargets.h"
8
9#include "Components/Core/ClipShapeComponent.h"
10
11#include "Resources/MaterialInstance.h"
12
13#include "Systems/Core/CameraSystem.h"
14
15#include "Renderer/Renderer.h"
16#include "Renderer/Tasks/RenderTask.h"
17#include "Renderer/Tasks/FilterListTask.h"
18#include "Renderer/RenderTarget.h"
19#include "Renderer/RenderStateUpdater.h"
20
21#include "HighlightRegionSystem.h"
22#include "HighlightRegionRenderer.h"
23
24namespace {
25 using namespace Cogs::Core;
26 Cogs::Logging::Log logger = Cogs::Logging::getLogger("HighlightRegion");
27
28 struct Matrices {
29 glm::mat4 clipFromLocal;
30 glm::mat4 localFromClip;
31 glm::vec4 eye;
32 glm::vec4 nearPlaneLocal;
33 glm::vec4 viewPlaneLocal;
34 };
35
36 void setTexture(Cogs::IContext* deviceContext, RenderMaterialInstance* renderMaterialInstance, const EffectBinding* binding, RenderTexture* texture, VariableKey key)
37 {
38 if (key == NoProperty) return;
39
40 const Cogs::TextureBindingHandle& texBinding = binding->textureBindings[key];
41 if (texture && HandleIsValid(texture->textureHandle)) {
42 deviceContext->setTexture(texBinding, texture->textureHandle);
43 }
44 else {
45 deviceContext->setTexture(texBinding, Cogs::TextureHandle::NoHandle);
46 }
47
48 const Cogs::SamplerStateBindingHandle& samplerBinding = binding->samplerBindings[key];
49 if (HandleIsValid(renderMaterialInstance->samplerStates[key])) {
50 deviceContext->setSamplerState(samplerBinding, renderMaterialInstance->samplerStates[key]);
51 }
52 else {
53 deviceContext->setSamplerState(samplerBinding, Cogs::SamplerStateHandle::NoHandle);
54 }
55 }
56
57}
58
59namespace {
60
61 uint32_t packSplitVertex4(size_t a, size_t b, size_t c, size_t d)
62 {
63 return static_cast<uint32_t>(((d) << 9) | ((c ) << 6) | ((b ) << 3) | ((a ) << 0));
64 }
65
66 uint32_t packSplitVertex2(size_t a, size_t b)
67 {
68 return packSplitVertex4(a, a, b, b);
69 }
70
71 uint32_t packSplitVertex1(size_t a)
72 {
73 return packSplitVertex4(a, a, a, a);
74 }
75
76}
77
79{
81 LOG_WARNING_ONCE(logger, "HighlightRegionRenderer only supports OpenGLES30 currently");
82 return;
83 }
84
85 Cogs::VertexElement vertexElements[1] = {
86 Cogs::VertexElement{0, Cogs::DataFormat::R32G32B32_FLOAT, Cogs::ElementSemantic::Position, 0, Cogs::InputType::VertexData, 0}
87 };
88 VertexFormatHandle vertexFormatHandle = VertexFormats::createVertexFormat(vertexElements, std::size(vertexElements));
89
90 Cogs::VertexElement splitCubeVertexElements[1] = {
92 };
93 VertexFormatHandle splitCubeVertexFormatHandle = VertexFormats::createVertexFormat(splitCubeVertexElements, std::size(splitCubeVertexElements));
94
95 Cogs::VertexElement instanceElements[2] = {
96 Cogs::VertexElement { 0 * sizeof(glm::mat4), Cogs::DataFormat::MAT4X4_FLOAT, Cogs::ElementSemantic::InstanceMatrix, 0, Cogs::InputType::InstanceData, 1 },
97 Cogs::VertexElement { 1 * sizeof(glm::mat4), Cogs::DataFormat::MAT4X4_FLOAT, Cogs::ElementSemantic::InstanceMatrix, 1, Cogs::InputType::InstanceData, 1 }
98 };
99
100 VertexFormatHandle instanceFormatHandle = VertexFormats::createVertexFormat(instanceElements, std::size(instanceElements));
101 assert(Cogs::getSize(instanceFormatHandle) == sizeof(HighlightRegionInstanceData));
102
103 solidStreamsLayout.vertexFormats[0] = vertexFormatHandle;
104 solidStreamsLayout.vertexFormats[1] = instanceFormatHandle;
105 solidStreamsLayout.numStreams = 2;
106 solidStreamsLayout.updateHash();
107
108 splitCubeStreamsLayout.vertexFormats[0] = splitCubeVertexFormatHandle;
109 splitCubeStreamsLayout.vertexFormats[1] = instanceFormatHandle;
110 splitCubeStreamsLayout.numStreams = 2;
111 splitCubeStreamsLayout.updateHash();
112
113 Cogs::IBuffers* buffers = device->getBuffers();
114
115 {
116 static const float cubeVertexData[8][3] = {
117 { -1, -1, -1 },
118 { 1, -1, -1 },
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 };
126 static_assert(std::size(cubeVertexData) == 8);
127 cubeVertices = buffers->loadVertexBuffer(cubeVertexData, std::size(cubeVertexData), solidStreamsLayout.vertexFormats[0]);
128
129 static const uint16_t cubeTriIndicesData[] = {
130 0, 3, 1, 0, 2, 3,
131 0, 1, 5, 0, 5, 4,
132 1, 3, 7, 7, 5, 1,
133 4, 6, 2, 4, 2, 0,
134 2, 7, 3, 7, 2, 6,
135 4, 7, 6, 4, 5, 7
136 };
137 cubeTriIndicesCount = static_cast<uint32_t>(std::size(cubeTriIndicesData));
138 cubeTriIndices = buffers->loadIndexBuffer(cubeTriIndicesData, cubeTriIndicesCount, sizeof(cubeTriIndicesData[0]));
139 }
140
141 {
142 static const uint32_t splitCubeVertexData[26] = {
143 packSplitVertex1(0), // glm::vec3( -1, -1, -1 ),
144 packSplitVertex2(0, 1), // glm::vec3( 0, -1, -1 ),
145 packSplitVertex1(1), // glm::vec3( 1, -1, -1 ),
146 packSplitVertex2(0, 2), // glm::vec3( -1, 0, -1 ),
147 packSplitVertex4(0, 2, 3, 1), // glm::vec3( 0, 0, -1 ),
148 packSplitVertex2(1, 3), // glm::vec3( 1, 0, -1 ),
149 packSplitVertex1(2), // glm::vec3( -1, 1, -1 ),
150 packSplitVertex2(2, 3), // glm::vec3( 0, 1, -1 ),
151 packSplitVertex1(3), // glm::vec3( 1, 1, -1 ),
152
153 packSplitVertex2(0, 4), // glm::vec3( -1, -1, 0 ),
154 packSplitVertex4(0, 1, 5, 4), // glm::vec3( 0, -1, 0 ),
155 packSplitVertex2(1, 5), // glm::vec3( 1, -1, 0 ),
156 packSplitVertex4(0, 4, 6, 2), // glm::vec3( -1, 0, 0 ),
157 packSplitVertex4(1, 3, 7, 5), // glm::vec3( 1, 0, 0 ),
158 packSplitVertex2(2, 6), // glm::vec3( -1, 1, 0 ),
159 packSplitVertex4(2, 6, 7, 3), // glm::vec3( 0, 1, 0 ),
160 packSplitVertex2(3, 7), // glm::vec3( 1, 1, 0 ),
161
162 packSplitVertex1(4), // glm::vec3( -1, -1, 1 ),
163 packSplitVertex2(4, 5), // glm::vec3( 0, -1, 1 ),
164 packSplitVertex1(5), // glm::vec3( 1, -1, 1 ),
165 packSplitVertex2(4, 6), // glm::vec3( -1, 0, 1 ),
166 packSplitVertex4(4, 5, 7, 6), // glm::vec3( 0, 0, 1 ),
167 packSplitVertex2(5, 7), // glm::vec3( 1, 0, 1 ),
168 packSplitVertex1(6), // glm::vec3( -1, 1, 1 ),
169 packSplitVertex2(6, 7), // glm::vec3( 0, 1, 1 ),
170 packSplitVertex1(7) // glm::vec3( 1, 1, 1 ),
171 };
172 splitCubeVertices = buffers->loadVertexBuffer(splitCubeVertexData, std::size(splitCubeVertexData), splitCubeStreamsLayout.vertexFormats[0]);
173
174 static const uint16_t splitCubeTriIndicesData[] = {
175 3, 1, 0, 4, 1, 3,
176 7, 3, 6, 4, 3, 7,
177 5, 7, 8, 4, 7, 5,
178 1, 5, 2, 4, 5, 1,
179
180 18, 20, 17, 21, 20, 18,
181 20, 24, 23, 21, 24, 20,
182 24, 22, 25, 21, 22, 24,
183 22, 18, 19, 21, 18, 22,
184
185 9, 3, 0, 12, 3, 9,
186 3, 14, 6, 12, 14, 3,
187 14, 20, 23, 12, 20, 14,
188 20, 9, 17, 12, 9, 20,
189
190 5, 11, 2, 13, 11, 5,
191 16, 5, 8, 13, 5, 16,
192 22, 16, 25, 13, 16, 22,
193 11, 22, 19, 13, 22, 11,
194
195 14, 7, 6, 15, 7, 14,
196 7, 16, 8, 15, 16, 7,
197 16, 24, 25, 15, 24, 16,
198 24, 14, 23, 15, 14, 24,
199
200 1, 9, 0, 10, 9, 1,
201 11, 1, 2, 10, 1, 11,
202 18, 11, 19, 10, 11, 18,
203 9, 18, 17, 10, 18, 9
204 };
205 splitCubeTriIndicesCount = static_cast<uint32_t>(std::size(splitCubeTriIndicesData));
206 splitCubeTriIndices = buffers->loadIndexBuffer(splitCubeTriIndicesData, splitCubeTriIndicesCount, sizeof(splitCubeTriIndicesData[0]));
207 }
208
209 // We have our own version of this depthStencilHandle since we need the
210 // OrEqual-test in additon to Less/Greater: When depth is clamped behind the
211 // near-plane, both the "normal" geometry and the highlight-region-pass gets
212 // the same value and without OrEqual, highlight-region would loose the tie.
213 // We would like it to win.
214 Cogs::IRenderTargets* renderTargets = device->getRenderTargets();
215 DepthStencilState depthState = { true, false, DepthStencilState::LessOrEqual };
216 noWriteDepthStencilState = renderTargets->loadDepthStencilState(depthState);
217
218 // Whether or not reverse depth should be used is not known this early, so we
219 // cover both cases and choose at render time,
221 noWriteDepthStencilStateReverse = renderTargets->loadDepthStencilState(depthState);
222}
223
224void Cogs::Core::HighlightRegionRenderer::handleEvent(uint32_t eventId, const DrawContext* renderingContext)
225{
226 Cogs::IGraphicsDevice* device = renderingContext->device;
227 if (device->getType() != Cogs::GraphicsDeviceType::OpenGLES30) return;
228
229 if (matrices.index == NoProperty && hrSystem->material && hrSystem->material->isActive()) {
230 for (const MaterialPropertyBuffer& buffer: hrSystem->material->constantBuffers.buffers) {
231 if (buffer.name == "Matrices" && sizeof(Matrices) <= buffer.size) {
232 LOG_DEBUG(logger, "Found Matrices buffer: %u (size=%zu)", buffer.index, buffer.size);
233 matrices.index = buffer.index;
235 }
236 }
237 }
238
239
240 Cogs::IBuffers* buffers = device->getBuffers();
241 RenderResources& renderResources = renderingContext->renderer->getRenderResources();
242 switch (eventId) {
244 // Do non-view/pass specific init at pre-render time
245 for (const HighlightRegionComponent& regionComp : hrSystem->pool) {
246 HighlightRegionData& data = hrSystem->getData(&regionComp);
247 if (data.materialInstance && data.materialInstance->isActive()) {
248 data.renderMaterialInstance = renderResources.getRenderMaterialInstance(data.materialInstance);
249 }
250
251 if (!regionComp.isVisible()) {
252 if (HandleIsValid(data.instanceDataHandle)) {
253 buffers->releaseVertexBuffer(data.instanceDataHandle);
254 data.instanceDataHandle = Cogs::BufferHandle::NoHandle;
255 data.instanceDataUpdated = true;
256 }
257 }
258 else {
259 if (data.instanceDataUpdated) {
260 data.instanceDataUpdated = false;
261 if (HandleIsValid(data.instanceDataHandle)) {
262 buffers->releaseVertexBuffer(data.instanceDataHandle);
263 data.instanceDataHandle = Cogs::BufferHandle::NoHandle;
264 }
265 if (!data.instanceData.empty()) {
266 data.instanceDataHandle = buffers->loadVertexBuffer(data.instanceData.data(), data.instanceData.size(), solidStreamsLayout.vertexFormats[1]);
267 }
268 }
269 }
270 }
271 break;
272 default:
273 break;
274 }
275}
276
277void Cogs::Core::HighlightRegionRenderer::generateCommands(const RenderTaskContext* /*renderingContext*/, RenderList* /*renderList*/)
278{
279}
280
281
282void Cogs::Core::HighlightRegionRenderer::render(RenderTaskContext* renderTaskContext, RenderTarget* renderTarget, RenderList* renderList, RenderTexture* color, RenderTexture* depth)
283{
284 if (renderTaskContext->device->getType() != Cogs::GraphicsDeviceType::OpenGLES30) return;
285
286 const CameraData* camData = renderList->viewportData;
287 if (!camData) return;
288
289 size_t permutationIndex = 0;
290 EnginePermutation* permutation = renderTaskContext->renderer->getEnginePermutations().get(permutationIndex);
291 if (!permutation) return;
292
293 DrawContext drawContext;
294 drawContext.context = renderTaskContext->context;
295 drawContext.renderer = renderTaskContext->renderer;
296 drawContext.device = drawContext.renderer->getDevice();
297 drawContext.deviceContext = drawContext.device->getImmediateContext();
298 drawContext.cameraData = renderList->viewportData;
299 drawContext.permutation = permutation;
300 drawContext.engineBuffers = &drawContext.renderer->getEngineBuffers();
301 drawContext.taskContext = renderTaskContext;
302 drawContext.renderTarget = renderTarget;
303
304 if (drawContext.permutation == nullptr) return;
305
306 IContext* deviceContext = drawContext.deviceContext;
307 bool reverseDepth = drawContext.taskContext->states->reverseDepth;
308
309 drawContext.renderer->updatePermutation(drawContext.permutation);
310
311 deviceContext->setBlendState(renderTaskContext->states->blendStates[size_t(BlendMode::None)].handle);
312
313
314 deviceContext->setRenderTarget(renderTarget->renderTargetHandle, renderTarget->depthTargetHandle);
315
316// if (drawContext.task->viewportFromTarget && drawContext.renderTarget) {
317 if (true) {
318 deviceContext->setViewport(0.f, 0.f, float(drawContext.renderTarget->width), float(drawContext.renderTarget->height));
319 }
320 else {
321 deviceContext->setViewport(camData->viewportOrigin.x, camData->viewportOrigin.y, camData->viewportSize.x, camData->viewportSize.y);
322 }
323
324// deviceContext->setViewport(camData->viewportOrigin.x, camData->viewportOrigin.y, camData->viewportSize.x, camData->viewportSize.y);
325 updateViewportBuffer(renderTaskContext, renderTaskContext->engineBuffers->sceneBufferHandle, renderTaskContext->engineBuffers->viewBufferHandle, renderTarget, camData, nullptr);
326
327 deviceContext->setDepthStencilState(renderTaskContext->context->renderer->getRenderStates().reverseDepth
328 ? noWriteDepthStencilStateReverse
329 : noWriteDepthStencilState);
330 for (const HighlightRegionComponent& regionComp : hrSystem->pool) {
331 HighlightRegionData& data = hrSystem->getData(&regionComp);
332 if (!HandleIsValid(data.instanceDataHandle) || !data.renderMaterialInstance) continue;
333
334 MaterialInstance* materialInstance = data.renderMaterialInstance->getResource();
335 assert(materialInstance);
336
337 VariableKey colorKey = NoProperty;
338 VariableKey depthKey = NoProperty;
339 for (const TextureValue& texProp : materialInstance->textureVariables) {
340 switch (Cogs::hash(texProp.property->name)) {
341 case Cogs::hash("offscreenColor"):
342 colorKey = texProp.key;
343 break;
344 case Cogs::hash("offscreenDepth"):
345 depthKey = texProp.key;
346 break;
347 default:
348 break;
349 }
350 }
351
352 RenderPassOptions passOptions = initRenderPassOptions(*camData, materialInstance);
353 passOptions.depthBias = reverseDepth ? regionComp.depthConstantBias : -regionComp.depthConstantBias;
354 passOptions.depthSlopedBias = reverseDepth ? regionComp.depthSlopedFactor : -regionComp.depthSlopedFactor;
355 passOptions.setFlag(RenderPassOptions::Flags::NoDepthClip);
356 passOptions.updateHash();
357
358 uint16_t rasterizerState = drawContext.renderer->getRenderStates().getRasterizerState(passOptions, Cogs::RasterizerState::Back, false, true);
359 deviceContext->setRasterizerState(drawContext.taskContext->states->rasterizerStateHandles[rasterizerState]);
360
361 const ClipShapeType clipShape = ClipShapeType::None;
362
363 const EffectBinding* effectBinding = nullptr;
364 if (data.debugForceNoSplit) {
365 effectBinding = data.renderMaterialInstance->checkReady(solidStreamsLayout, drawContext.permutation, passOptions, clipShape);
366 }
367 else {
368 effectBinding = data.renderMaterialInstance->checkReady(splitCubeStreamsLayout, drawContext.permutation, passOptions, clipShape);
369 }
370 if (!effectBinding) continue;
371
372 drawContext.renderer->updatePermutation(permutation);
373 for (const MaterialPropertyBuffer& buffer : permutation->constantBuffers.buffers) {
374 permutation->bufferHandles.resize(permutation->constantBuffers.buffers.size());
375 if (!HandleIsValid(permutation->bufferHandles[buffer.index])) {
376 Cogs::IBuffers* buffers = drawContext.device->getBuffers();
377 permutation->bufferHandles[buffer.index] = buffers->loadBuffer(nullptr, buffer.size, Cogs::Usage::Dynamic, Cogs::AccessMode::Write, Cogs::BindFlags::ConstantBuffer);
378 }
379 deviceContext->updateBuffer(permutation->bufferHandles[buffer.index], buffer.content.data(), buffer.size);
380 deviceContext->setConstantBuffer(buffer.name, permutation->bufferHandles[buffer.index]);
381
382 }
383 applyMaterialPermutation(drawContext.taskContext, &drawContext, effectBinding, data.renderMaterialInstance);
384 applyMaterialInstance(&drawContext, effectBinding, data.renderMaterialInstance);
385 updateEnvironmentBindings(&drawContext, effectBinding);
386 updateSceneBindings(drawContext.taskContext, effectBinding);
387 updateMaterialBindings(&drawContext, data.renderMaterialInstance, effectBinding, true);
388
389 setTexture(deviceContext, data.renderMaterialInstance, effectBinding, color, colorKey);
390 setTexture(deviceContext, data.renderMaterialInstance, effectBinding, depth, depthKey);
391
392 if (HandleIsValid(matrices.buffer) && matrices.index < effectBinding->buffers.size()) {
393 if (const Cogs::ConstantBufferBindingHandle& bufferBinding = effectBinding->bufferBindings[matrices.index]; HandleIsValid(bufferBinding)) {
394
395 glm::dmat4 inverseView = camData->inverseViewMatrix;
396 glm::dmat4 viewMatrix = glm::inverse(inverseView);
397 glm::dmat4 viewFromLocal = viewMatrix * glm::dmat4(data.worldMatrix);
398 glm::dmat4 clipFromLocal = glm::dmat4(camData->projectionMatrix) * viewFromLocal;
399 glm::dmat4 localFromClip = glm::inverse(clipFromLocal);
400
401 if (Cogs::MappedBuffer<Matrices> matricesBuffer(deviceContext, matrices.buffer, Cogs::MapMode::WriteDiscard); matricesBuffer) {
402 matricesBuffer->clipFromLocal = clipFromLocal;
403 matricesBuffer->localFromClip = localFromClip;
404 matricesBuffer->eye = glm::inverse(viewFromLocal) * glm::vec4(0,0,0,1);
405 matricesBuffer->nearPlaneLocal = glm::vec4(0, 0, -1, -camData->nearDistance) * viewFromLocal;
406 matricesBuffer->viewPlaneLocal = glm::vec4(0, 0, -1, 0) * viewFromLocal;
407 }
408 deviceContext->setConstantBuffer(bufferBinding, matrices.buffer);
409 }
410 }
411
412 if (data.debugForceNoSplit) {
413 Cogs::VertexBufferHandle vertexBuffers[2] = {
414 cubeVertices,
415 data.instanceDataHandle
416 };
417 deviceContext->setVertexBuffers(vertexBuffers, std::size(vertexBuffers));
418 deviceContext->setIndexBuffer(cubeTriIndices, 2, 0);
419 deviceContext->drawInstancedIndexed(Cogs::PrimitiveType::TriangleList, 0, data.instanceData.size(), 0, cubeTriIndicesCount);
420 }
421 else {
422 Cogs::VertexBufferHandle vertexBuffers[2] = {
423 splitCubeVertices,
424 data.instanceDataHandle
425 };
426 deviceContext->setVertexBuffers(vertexBuffers, std::size(vertexBuffers));
427 deviceContext->setIndexBuffer(splitCubeTriIndices, 2, 0);
428 deviceContext->drawInstancedIndexed(Cogs::PrimitiveType::TriangleList, 0, data.instanceData.size(), 0, splitCubeTriIndicesCount);
429 }
430 }
431}
432
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Definition: Context.h:83
class IRenderer * renderer
Renderer.
Definition: Context.h:228
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.
virtual RenderStates & getRenderStates()=0
Get the reference to the RenderStates structure.
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:754
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 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.
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.
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 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 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