Cogs.Core
IContext.h
1#pragma once
2
3#include "Common.h"
4#include "DataFormat.h"
5
6namespace Cogs
7{
8 class StringView;
9 struct FrameStatistics;
10 struct UploadStatistics;
11
12 enum class LoadOp : uint32_t{
13 Undefined,
14 Clear,
15 Load,
16 };
17
18 enum class StoreOp : uint32_t{
19 Undefined,
20 Store,
21 Discard
22 };
23
25 RenderTargetHandle renderTargetHandle = {};
26 DepthStencilHandle depthStencilHandle = {};
27 TextureViewHandle resolveHandle[8] = {};
28
29 LoadOp loadOp[8] = {LoadOp::Clear, LoadOp::Clear, LoadOp::Clear, LoadOp::Clear, LoadOp::Clear, LoadOp::Clear, LoadOp::Clear, LoadOp::Clear};
30 StoreOp storeOp[8] = {StoreOp::Store, StoreOp::Store, StoreOp::Store, StoreOp::Store, StoreOp::Store, StoreOp::Store, StoreOp::Store, StoreOp::Store};
31 float clearValue[8][4] = {};
32
33 LoadOp depthLoadOp = LoadOp::Clear;
34 StoreOp depthStoreOp = StoreOp::Store;
35 float depthClearValue = 1.0f;
36 bool depthReadOnly = false;
37 };
38
42 struct IContext
43 {
44 virtual const Cogs::FrameStatistics& getLastFrameStatistics() = 0;
45 virtual const Cogs::UploadStatistics& getLastUploadStatistics() = 0;
46
47 virtual void frameStatisticsConfigure(bool enable) = 0;
48
55 virtual void clearCachedState() {}
56
62 virtual void pushCommandGroupAnnotation(const StringView & name) { (void)name; }
63
67 virtual void popCommandGroupAnnotation() {}
68
72 virtual void setAnnotationMarker(const StringView & name) { (void)name; }
73
74 //
75 // Render Pass
76 //
85 virtual void beginRenderPass(const RenderPassInfo &info) = 0;
86
90 virtual void endRenderPass() = 0;
91
92 //
93 // Render target management
94 //
98 virtual void setRenderTarget(const RenderTargetHandle handle, const DepthStencilHandle depthStencilHandle) = 0;
99
103 virtual void setViewport(const float x, const float y, const float width, const float height) = 0;
104
110 virtual void setScissor(const int x, const int y, const int width, const int height) = 0;
111
117 virtual void clearRenderTarget(const float * value) = 0;
118
123 virtual void clearRenderTarget(const float ** values, const int numvalues) = 0;
124
128 virtual void clearDepth(const float depth = 1.0f) = 0;
129
130 //
131 // Pipeline state setup
132 //
133
137 virtual void setDepthStencilState(const DepthStencilStateHandle handle) = 0;
138
142 virtual void setBlendState(const BlendStateHandle handle, const float* constant = nullptr) = 0;
143
147 virtual void setRasterizerState(const RasterizerStateHandle handle) = 0;
148
149 //
150 // Effect state setup
151 //
152
157 virtual void setEffect(EffectHandle handle) = 0;
158
163 virtual void setMatrixVariable(const StringView& name, const float * value) = 0;
164
168 virtual void setScalarVariable(const StringView& name, const float value) = 0;
169
173 virtual void setScalarVariable(const StringView& name, int value) = 0;
174
178 virtual void setVector2Variable(const StringView& name, const float * value) = 0;
179
183 virtual void setVector3Variable(const StringView& name, const float * value) = 0;
184
188 virtual void setVector4Variable(const StringView& name, const float * value) = 0;
189
193 virtual void setVariable(const EffectVariableHandle index, const uint8_t * data, size_t size) = 0;
194
199 virtual void setMatrixVariable(const EffectVariableHandle variableHandle, const float * value) = 0;
200
205 virtual void setMatrixVariable(const EffectVariableHandle variableHandle, const float * value, size_t count) = 0;
206
210 virtual void setScalarVariable(const EffectVariableHandle variableHandle, const float value) = 0;
211
215 virtual void setScalarVariable(const EffectVariableHandle variableHandle, const float* value, size_t count) = 0;
216
220 virtual void setScalarVariable(const EffectVariableHandle variableHandle, int value) = 0;
221
225 virtual void setScalarVariable(const EffectVariableHandle variableHandle, const int* value, size_t count) = 0;
226
230 virtual void setVector2Variable(const EffectVariableHandle variableHandle, const float * value, size_t count = 1) = 0;
231
235 virtual void setVector3Variable(const EffectVariableHandle variableHandle, const float * value, size_t count = 1) = 0;
236
240 virtual void setVector4Variable(const EffectVariableHandle variableHandle, const float * value, size_t count = 1) = 0;
241
245 virtual void setVector4Variable(const EffectVariableHandle variableHandle, const int * value, size_t count = 1) = 0;
246
247 //
248 // Texture state setup
249 //
250
259 virtual void setTexture(const StringView& name, unsigned int unit, TextureHandle textureHandle) = 0;
260
267 virtual void setTexture(const TextureBindingHandle textureBindingHandle, const TextureHandle textureHandle) = 0;
268
269 virtual void setTexture(const StringView& name, TextureViewHandle textureViewHandle) = 0;
270 virtual void setTexture(const TextureBindingHandle textureBindingHandle, TextureViewHandle textureViewHandle) = 0;
271
281 virtual void setSamplerState(const StringView& name, unsigned int unit, SamplerStateHandle samplerStateHandle) = 0;
282
290 virtual void setSamplerState(const SamplerStateBindingHandle samplerStateBindingHandle, const SamplerStateHandle samplerStateHandle) = 0;
291
292 //
293 // Draw state setup
294 //
295
301 virtual void setInputLayout(const InputLayoutHandle inputLayoutHandle) = 0;
302
311 virtual void setVertexBuffers(const VertexBufferHandle * vertexBufferHandles, const size_t count, const uint32_t * strides, const uint32_t * offsets) = 0;
312
318 virtual void setVertexBuffers(const VertexBufferHandle * vertexBufferHandles, const size_t count) = 0;
319
328 virtual void setIndexBuffer(IndexBufferHandle bufferHandle, uint32_t stride = 4, uint32_t offset = 0) = 0;
329
330
336 virtual void setVertexArrayObject(VertexArrayObjectHandle vertexArrayObject) = 0;
337
338
345 virtual void setConstantBuffer(const StringView& name, const BufferHandle bufferHandle, const uint32_t offset = 0, const uint32_t size = ~0u) = 0;
346
354 virtual void setConstantBuffer(const ConstantBufferBindingHandle bufferBindingHandle, const BufferHandle bufferHandle, const uint32_t offset = 0, const uint32_t size = ~0u) = 0;
355
362 virtual void setBuffer(const StringView& name, BufferHandle bufferHandle) = 0;
363
370 virtual void setBuffer(const BufferBindingHandle bufferBindingHandle, BufferHandle bufferHandle) = 0;
371
379 virtual void setBufferCounter(BufferHandle bufferHandle, uint32_t value) = 0;
380
388 virtual void setBufferCounter(BufferHandle bufferHandle, BufferHandle sourceBufferHandle) = 0;
389
397 virtual void getBufferCounter(BufferHandle bufferHandle, BufferHandle destinationBufferHandle) = 0;
398
404 virtual uint32_t getBufferCounter(BufferHandle bufferHandle) = 0;
405
406 //
407 // Draw calls
408 //
409
417 virtual void draw(PrimitiveType::EPrimitiveType primitiveType, const size_t startVertex, const size_t numVertexes) = 0;
418
427 virtual void drawIndexed(PrimitiveType::EPrimitiveType primitiveType, const size_t startIndex, const size_t numIndexes, const size_t startVertex = 0) = 0;
428
438 virtual void drawInstanced(PrimitiveType::EPrimitiveType primitiveType, const size_t startVertex, const size_t numVertexes, const size_t startInstance, const size_t numInstances) = 0;
439
449 virtual void drawInstancedIndexed(PrimitiveType::EPrimitiveType primitiveType, const size_t startInstance, const size_t numInstances, const size_t startIndex, const size_t numIndexes) = 0;
450
458 virtual void dispatchCompute(const unsigned int threadGroupsX, const unsigned int threadGroupsY, const unsigned int threadGroupsZ) = 0;
459
460 //
461 // Render target, texture and buffer manipulation.
462 //
463
473 virtual void resolveResource(TextureHandle source, TextureHandle destination) = 0;
474
485 virtual void readDepthBuffer(BufferHandle bufferHandle, int x, int y, int width, int height, Framebuffer::EFrameBuffer framebuffer) = 0;
486
497 virtual void readColorBuffer(BufferHandle bufferHandle, int x, int y, int width, int height, Framebuffer::EFrameBuffer framebuffer) = 0;
498
499
509 virtual void * map(BufferHandle bufferHandle, MapMode::EMapMode mapMode, uint32_t * stride = nullptr) = 0;
510
517 virtual void unmap(BufferHandle bufferHandle) = 0;
518
528 virtual void updateBuffer(BufferHandle bufferHandle, const void* data, size_t size) = 0;
529
541 virtual void * map(TextureHandle textureHandle, MapMode::EMapMode accessMode, uint32_t * rowPitch, uint32_t * depthPitch) = 0;
542
548 virtual void unmap(TextureHandle textureHandle) = 0;
549
555 virtual void signal(FenceHandle fenceHandle) = 0;
556
565 virtual void updateSubTexture(TextureHandle textureHandle, const size_t level, const void * data) = 0;
566
576 virtual void updateSubBuffer(BufferHandle bufferHandle, const size_t offset, const size_t size, const void* data) = 0;
577
578 virtual void copyResource(BufferHandle destinationHandle, BufferHandle sourceHandle) = 0;
579 virtual void copyResource(TextureHandle destinationHandle, TextureHandle sourceHandle) = 0;
580
581 virtual void copyTexture(TextureHandle dstHandle, unsigned dstSub, unsigned dstX, unsigned dstY, unsigned dstZ, TextureHandle sourceHandle, unsigned srcSub) = 0;
582
583 virtual void clearResource(BufferHandle destinationHandle, uint32_t *Values) = 0;
584 virtual void clearResource(BufferHandle destinationHandle, float *Values) = 0;
585
586 //
587 // Context management.
588 //
589
593 virtual void reset() {};
594 };
595}
Provides a weakly referenced view over the contents of a string.
Definition: StringView.h:24
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
Represents a graphics device context which can receive rendering commands.
Definition: IContext.h:43
virtual void * map(TextureHandle textureHandle, MapMode::EMapMode accessMode, uint32_t *rowPitch, uint32_t *depthPitch)=0
Create host mapping of a staging texture.
virtual void clearRenderTarget(const float **values, const int numvalues)=0
Clear the currently set render target, setting the individual render target views to the given values...
virtual void updateSubBuffer(BufferHandle bufferHandle, const size_t offset, const size_t size, const void *data)=0
Update a region of data in a buffer.
virtual void drawIndexed(PrimitiveType::EPrimitiveType primitiveType, const size_t startIndex, const size_t numIndexes, const size_t startVertex=0)=0
Draws indexed, non-instanced primitives.
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 uint32_t getBufferCounter(BufferHandle bufferHandle)=0
Get the associated counter of a buffer.
virtual void setRasterizerState(const RasterizerStateHandle handle)=0
Set the current rasterizer state.
virtual void setBufferCounter(BufferHandle bufferHandle, BufferHandle sourceBufferHandle)=0
Set the associated counter of a buffer.
virtual void setBlendState(const BlendStateHandle handle, const float *constant=nullptr)=0
Set the current blend state.
virtual void signal(FenceHandle fenceHandle)=0
Insert a fence in the command stream that will signal when all commands before the fence are complete...
virtual void updateSubTexture(TextureHandle textureHandle, const size_t level, const void *data)=0
Update the data of a level in the given texture.
virtual void setVector4Variable(const EffectVariableHandle variableHandle, const int *value, size_t count=1)=0
Sets the given vector variable to the given four-component value.
virtual void unmap(TextureHandle textureHandle)=0
Release a host mapping of a staging texture.
virtual void setBuffer(const BufferBindingHandle bufferBindingHandle, BufferHandle bufferHandle)=0
Sets a buffer to bind to the given binding.
virtual void setInputLayout(const InputLayoutHandle inputLayoutHandle)=0
Sets the current input layout.
virtual void readColorBuffer(BufferHandle bufferHandle, int x, int y, int width, int height, Framebuffer::EFrameBuffer framebuffer)=0
Reads data from the current render target into the given bufferHandle.
virtual void setAnnotationMarker(const StringView &name)
Add a tag in the sequence of commands in graphics debugger.
Definition: IContext.h:72
virtual void setVector4Variable(const StringView &name, const float *value)=0
Sets the vector variable with the given name to the given four-component value.
virtual void setScalarVariable(const EffectVariableHandle variableHandle, int value)=0
Sets the given scalar integer point variable to the given value.
virtual void * map(BufferHandle bufferHandle, MapMode::EMapMode mapMode, uint32_t *stride=nullptr)=0
Maps the given buffer so it can be accessed.
virtual void unmap(BufferHandle bufferHandle)=0
Unmaps the given buffer, applying any synchronization necessary to reflect changes in the mapped memo...
virtual void setMatrixVariable(const EffectVariableHandle variableHandle, const float *value, size_t count)=0
Sets the given matrix variable to value.
virtual void drawInstancedIndexed(PrimitiveType::EPrimitiveType primitiveType, const size_t startInstance, const size_t numInstances, const size_t startIndex, const size_t numIndexes)=0
Draws indexed, instanced primitives.
virtual void dispatchCompute(const unsigned int threadGroupsX, const unsigned int threadGroupsY, const unsigned int threadGroupsZ)=0
Dispatch computing work on the graphics device using the desired thread group count.
virtual void setVertexArrayObject(VertexArrayObjectHandle vertexArrayObject)=0
Sets vertexBuffers and index buffers using a prevalidated vertex array object.
virtual void setScissor(const int x, const int y, const int width, const int height)=0
Sets the current scissor rectangle.
virtual void clearRenderTarget(const float *value)=0
Clear the currently set render target to the given value (4 component floating point RGBA).
virtual void setSamplerState(const SamplerStateBindingHandle samplerStateBindingHandle, const SamplerStateHandle samplerStateHandle)=0
Sets the sampler state binding given to the given sampler state.
virtual void setScalarVariable(const StringView &name, int value)=0
Sets the scalar integer variable with the given name to the given value.
virtual void setMatrixVariable(const EffectVariableHandle variableHandle, const float *value)=0
Sets the given matrix variable to value.
virtual void setMatrixVariable(const StringView &name, const float *value)=0
Sets the matrix variable with the given name in the current effect to value.
virtual void setScalarVariable(const EffectVariableHandle variableHandle, const float *value, size_t count)=0
Sets the given scalar integer point variable to the given value.
virtual void endRenderPass()=0
End a render pass.
virtual void setVector3Variable(const StringView &name, const float *value)=0
Sets the vector variable with the given name to the given three-component value.
virtual void setScalarVariable(const EffectVariableHandle variableHandle, const int *value, size_t count)=0
Sets the given scalar integer point variable to the given value.
virtual void setIndexBuffer(IndexBufferHandle bufferHandle, uint32_t stride=4, uint32_t offset=0)=0
Sets the current index buffer.
virtual void setTexture(const TextureBindingHandle textureBindingHandle, const TextureHandle textureHandle)=0
Sets the texture given to the binding given by textureBindingHandle.
virtual void reset()
Resets all state changes made to the GPU since the last call to beginFrame.
Definition: IContext.h:593
virtual void setVector3Variable(const EffectVariableHandle variableHandle, const float *value, size_t count=1)=0
Sets the given vector variable to the given three-component value.
virtual void setConstantBuffer(const ConstantBufferBindingHandle bufferBindingHandle, const BufferHandle bufferHandle, const uint32_t offset=0, const uint32_t size=~0u)=0
Sets a constant buffer to the given constant buffer binding.
virtual void setDepthStencilState(const DepthStencilStateHandle handle)=0
Set the current depth stencil state.
virtual void getBufferCounter(BufferHandle bufferHandle, BufferHandle destinationBufferHandle)=0
Get the associated counter of a buffer.
virtual void setScalarVariable(const EffectVariableHandle variableHandle, const float value)=0
Sets the given scalar floating point variable to the given value.
virtual void resolveResource(TextureHandle source, TextureHandle destination)=0
Resolves the given source resource target into the given destination texture.
virtual void clearCachedState()
Prepare context for external manipulation of graphics device.
Definition: IContext.h:55
virtual void clearDepth(const float depth=1.0f)=0
Clear the currently set depth/stencil target to the given depth.
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 setScalarVariable(const StringView &name, const float value)=0
Sets the scalar floating point variable with the given name to the given value.
virtual void setVector2Variable(const EffectVariableHandle variableHandle, const float *value, size_t count=1)=0
Sets the given vector variable to the given two-component value.
virtual void updateBuffer(BufferHandle bufferHandle, const void *data, size_t size)=0
Replace contents of buffer with new data.
virtual void setVector4Variable(const EffectVariableHandle variableHandle, const float *value, size_t count=1)=0
Sets the given vector variable to the given four-component value.
virtual void setVertexBuffers(const VertexBufferHandle *vertexBufferHandles, const size_t count)=0
Overload provided to support transitioning.
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 readDepthBuffer(BufferHandle bufferHandle, int x, int y, int width, int height, Framebuffer::EFrameBuffer framebuffer)=0
Reads data from the current depth target into the given bufferHandle.
virtual void setBuffer(const StringView &name, BufferHandle bufferHandle)=0
Sets the given buffer to the buffer binding slot with the given name.
virtual void draw(PrimitiveType::EPrimitiveType primitiveType, const size_t startVertex, const size_t numVertexes)=0
Draws non-indexed, non-instanced primitives.
virtual void popCommandGroupAnnotation()
End to tag a sequence of commands as a group in graphics debugger.
Definition: IContext.h:67
virtual void beginRenderPass(const RenderPassInfo &info)=0
Begin a render pass.
virtual void setBufferCounter(BufferHandle bufferHandle, uint32_t value)=0
Set the associated counter of a buffer.
virtual void pushCommandGroupAnnotation(const StringView &name)
Begin to tag a sequence of commands as a group in graphics debugger.
Definition: IContext.h:62
virtual void setVector2Variable(const StringView &name, const float *value)=0
Sets the vector variable with the given name to the given two-component value.
virtual void drawInstanced(PrimitiveType::EPrimitiveType primitiveType, const size_t startVertex, const size_t numVertexes, const size_t startInstance, const size_t numInstances)=0
Draws non-indexed, instanced primitives.
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 setVariable(const EffectVariableHandle index, const uint8_t *data, size_t size)=0
Sets the variable with the given name and size.
virtual void setEffect(EffectHandle handle)=0
Set the current effect.
virtual void setRenderTarget(const RenderTargetHandle handle, const DepthStencilHandle depthStencilHandle)=0
Sets the current render target and an associated depth stencil target.
EMapMode
Mapping mode enumeration.
Definition: Flags.h:93
EPrimitiveType
Primitive type enumeration.
Definition: Common.h:114