Cogs.Core
GPGPUQuadRenderer.cpp
1#include "GPGPUQuadRenderer.h"
2
3#include "Rendering/IBuffers.h"
4#include "Rendering/IGraphicsDevice.h"
5#include "Rendering/IRenderTargets.h"
6#include "Rendering/ITextures.h"
7
8void Cogs::GPGPUQuadRenderer::initialize(IGraphicsDevice* device)
9{
10 // Geometry
11 float vertexData[] = {
12 -1, -1, 0, 0,
13 1, -1, 1, 0,
14 1, 1, 1, 1,
15
16 -1, -1, 0, 0,
17 1, 1, 1, 1,
18 -1, 1, 0, 1,
19 };
20
21 VertexElement elements[] = {
22 { 0, DataFormat::X32Y32_FLOAT, ElementSemantic::Position, 0, InputType::VertexData, 0 },
23 { 2 * sizeof(float), DataFormat::X32Y32_FLOAT, ElementSemantic::TextureCoordinate, 0, InputType::VertexData, 0 }
24 };
25 format = device->getBuffers()->createVertexFormat(elements, 2);
26 quadVertexBuffer = device->getBuffers()->loadVertexBuffer(vertexData, 6, format);
27
28 DepthStencilState depthStencilState = {false, false, DepthStencilState::Less };
29 solidDepthStencilState = device->getRenderTargets()->loadDepthStencilState(depthStencilState);
30
31 solidBlendState = device->getRenderTargets()->loadBlendState(BlendState::DefaultState());
32
33 RasterizerState solid = { false, RasterizerState::CullMode::Back, true, true, 0.0f, 0.0f, 0.0f, false, false };
34 solidRasterizerState = device->getRenderTargets()->loadRasterizerState(solid);
35
36 pointSampleState = device->getTextures()->loadSamplerState({ SamplerState::Wrap,
40 SamplerState::Never,
41 0,
42 { 0, 0, 0, 1 } });
43
44}
45
46void Cogs::GPGPUQuadRenderer::bind(IContext* context)
47{
48 const uint32_t strides[] = { 4 * sizeof(float) };
49 context->setVertexBuffers(&quadVertexBuffer, 1, strides, nullptr);
50 context->setBlendState(solidBlendState);
51 context->setDepthStencilState(solidDepthStencilState);
52 context->setRasterizerState(solidRasterizerState);
53}
@ VertexData
Per vertex data.
@ Position
Position semantic.
@ TextureCoordinate
Texture coordinate semantic.
static BlendState DefaultState()
Creates a blend state object initialized with the default settings.
Definition: BlendState.h:55
@ Back
Cull back facing primitives.
@ Wrap
Texture coordinates automatically wrap around to [0, 1] range.
Definition: SamplerState.h:19
@ MinMagMipPoint
Point sampling for both minification and magnification.
Definition: SamplerState.h:33