mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-06 13:15:59 +00:00
fix formatting
This commit is contained in:
parent
084346bd5f
commit
376f1c6a8e
@ -39,25 +39,25 @@ nxt::RenderPass renderpass;
|
||||
nxt::Framebuffer framebuffer;
|
||||
|
||||
void initBuffers() {
|
||||
static const uint32_t indexData[6*6] = {
|
||||
0, 1, 2,
|
||||
0, 2, 3,
|
||||
static const uint32_t indexData[6*6] = {
|
||||
0, 1, 2,
|
||||
0, 2, 3,
|
||||
|
||||
4, 5, 6,
|
||||
4, 6, 7,
|
||||
4, 5, 6,
|
||||
4, 6, 7,
|
||||
|
||||
8, 9, 10,
|
||||
8, 10, 11,
|
||||
8, 9, 10,
|
||||
8, 10, 11,
|
||||
|
||||
12, 13, 14,
|
||||
12, 14, 15,
|
||||
12, 13, 14,
|
||||
12, 14, 15,
|
||||
|
||||
16, 17, 18,
|
||||
16, 18, 19,
|
||||
16, 17, 18,
|
||||
16, 18, 19,
|
||||
|
||||
20, 21, 22,
|
||||
20, 22, 23
|
||||
};
|
||||
20, 21, 22,
|
||||
20, 22, 23
|
||||
};
|
||||
indexBuffer = device.CreateBufferBuilder()
|
||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Index)
|
||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
||||
@ -66,37 +66,37 @@ void initBuffers() {
|
||||
indexBuffer.SetSubData(0, sizeof(indexData) / sizeof(uint32_t), indexData);
|
||||
indexBuffer.FreezeUsage(nxt::BufferUsageBit::Index);
|
||||
|
||||
static const float vertexData[6 * 4 * 6] = {
|
||||
-1.0, -1.0, 1.0, 1.0, 0.0, 0.0,
|
||||
1.0, -1.0, 1.0, 1.0, 0.0, 0.0,
|
||||
1.0, 1.0, 1.0, 1.0, 0.0, 0.0,
|
||||
-1.0, 1.0, 1.0, 1.0, 0.0, 0.0,
|
||||
static const float vertexData[6 * 4 * 6] = {
|
||||
-1.0, -1.0, 1.0, 1.0, 0.0, 0.0,
|
||||
1.0, -1.0, 1.0, 1.0, 0.0, 0.0,
|
||||
1.0, 1.0, 1.0, 1.0, 0.0, 0.0,
|
||||
-1.0, 1.0, 1.0, 1.0, 0.0, 0.0,
|
||||
|
||||
-1.0, -1.0, -1.0, 1.0, 1.0, 0.0,
|
||||
-1.0, 1.0, -1.0, 1.0, 1.0, 0.0,
|
||||
1.0, 1.0, -1.0, 1.0, 1.0, 0.0,
|
||||
1.0, -1.0, -1.0, 1.0, 1.0, 0.0,
|
||||
-1.0, -1.0, -1.0, 1.0, 1.0, 0.0,
|
||||
-1.0, 1.0, -1.0, 1.0, 1.0, 0.0,
|
||||
1.0, 1.0, -1.0, 1.0, 1.0, 0.0,
|
||||
1.0, -1.0, -1.0, 1.0, 1.0, 0.0,
|
||||
|
||||
-1.0, 1.0, -1.0, 1.0, 0.0, 1.0,
|
||||
-1.0, 1.0, 1.0, 1.0, 0.0, 1.0,
|
||||
1.0, 1.0, 1.0, 1.0, 0.0, 1.0,
|
||||
1.0, 1.0, -1.0, 1.0, 0.0, 1.0,
|
||||
-1.0, 1.0, -1.0, 1.0, 0.0, 1.0,
|
||||
-1.0, 1.0, 1.0, 1.0, 0.0, 1.0,
|
||||
1.0, 1.0, 1.0, 1.0, 0.0, 1.0,
|
||||
1.0, 1.0, -1.0, 1.0, 0.0, 1.0,
|
||||
|
||||
-1.0, -1.0, -1.0, 0.0, 1.0, 0.0,
|
||||
1.0, -1.0, -1.0, 0.0, 1.0, 0.0,
|
||||
1.0, -1.0, 1.0, 0.0, 1.0, 0.0,
|
||||
-1.0, -1.0, 1.0, 0.0, 1.0, 0.0,
|
||||
-1.0, -1.0, -1.0, 0.0, 1.0, 0.0,
|
||||
1.0, -1.0, -1.0, 0.0, 1.0, 0.0,
|
||||
1.0, -1.0, 1.0, 0.0, 1.0, 0.0,
|
||||
-1.0, -1.0, 1.0, 0.0, 1.0, 0.0,
|
||||
|
||||
1.0, -1.0, -1.0, 0.0, 1.0, 1.0,
|
||||
1.0, 1.0, -1.0, 0.0, 1.0, 1.0,
|
||||
1.0, 1.0, 1.0, 0.0, 1.0, 1.0,
|
||||
1.0, -1.0, 1.0, 0.0, 1.0, 1.0,
|
||||
1.0, -1.0, -1.0, 0.0, 1.0, 1.0,
|
||||
1.0, 1.0, -1.0, 0.0, 1.0, 1.0,
|
||||
1.0, 1.0, 1.0, 0.0, 1.0, 1.0,
|
||||
1.0, -1.0, 1.0, 0.0, 1.0, 1.0,
|
||||
|
||||
-1.0, -1.0, -1.0, 1.0, 1.0, 1.0,
|
||||
-1.0, -1.0, 1.0, 1.0, 1.0, 1.0,
|
||||
-1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
||||
-1.0, 1.0, -1.0, 1.0, 1.0, 1.0
|
||||
};
|
||||
-1.0, -1.0, -1.0, 1.0, 1.0, 1.0,
|
||||
-1.0, -1.0, 1.0, 1.0, 1.0, 1.0,
|
||||
-1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
||||
-1.0, 1.0, -1.0, 1.0, 1.0, 1.0
|
||||
};
|
||||
|
||||
vertexBuffer = device.CreateBufferBuilder()
|
||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Vertex)
|
||||
@ -107,26 +107,26 @@ void initBuffers() {
|
||||
reinterpret_cast<const uint32_t*>(vertexData));
|
||||
vertexBuffer.FreezeUsage(nxt::BufferUsageBit::Vertex);
|
||||
|
||||
static const float planeData[6 * 4] = {
|
||||
-2.0, -1.0, -2.0, 0.5, 0.5, 0.5,
|
||||
2.0, -1.0, -2.0, 0.5, 0.5, 0.5,
|
||||
2.0, -1.0, 2.0, 0.5, 0.5, 0.5,
|
||||
-2.0, -1.0, 2.0, 0.5, 0.5, 0.5,
|
||||
};
|
||||
static const float planeData[6 * 4] = {
|
||||
-2.0, -1.0, -2.0, 0.5, 0.5, 0.5,
|
||||
2.0, -1.0, -2.0, 0.5, 0.5, 0.5,
|
||||
2.0, -1.0, 2.0, 0.5, 0.5, 0.5,
|
||||
-2.0, -1.0, 2.0, 0.5, 0.5, 0.5,
|
||||
};
|
||||
|
||||
planeBuffer = device.CreateBufferBuilder()
|
||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Vertex)
|
||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
||||
.SetSize(sizeof(planeData))
|
||||
.GetResult();
|
||||
planeBuffer.SetSubData(0, sizeof(planeData) / sizeof(uint32_t),
|
||||
reinterpret_cast<const uint32_t*>(planeData));
|
||||
planeBuffer.FreezeUsage(nxt::BufferUsageBit::Vertex);
|
||||
planeBuffer = device.CreateBufferBuilder()
|
||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Vertex)
|
||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
||||
.SetSize(sizeof(planeData))
|
||||
.GetResult();
|
||||
planeBuffer.SetSubData(0, sizeof(planeData) / sizeof(uint32_t),
|
||||
reinterpret_cast<const uint32_t*>(planeData));
|
||||
planeBuffer.FreezeUsage(nxt::BufferUsageBit::Vertex);
|
||||
}
|
||||
|
||||
struct {
|
||||
glm::mat4 view;
|
||||
glm::mat4 proj;
|
||||
glm::mat4 view;
|
||||
glm::mat4 proj;
|
||||
} cameraData;
|
||||
|
||||
void init() {
|
||||
@ -136,163 +136,163 @@ void init() {
|
||||
|
||||
initBuffers();
|
||||
|
||||
nxt::ShaderModule vsModule = CreateShaderModule(device, nxt::ShaderStage::Vertex, R"(
|
||||
nxt::ShaderModule vsModule = CreateShaderModule(device, nxt::ShaderStage::Vertex, R"(
|
||||
#version 450
|
||||
layout(set = 0, binding = 0) uniform cameraData {
|
||||
mat4 view;
|
||||
mat4 proj;
|
||||
} camera;
|
||||
layout(set = 0, binding = 1) uniform modelData {
|
||||
mat4 modelMatrix;
|
||||
};
|
||||
layout(set = 0, binding = 0) uniform cameraData {
|
||||
mat4 view;
|
||||
mat4 proj;
|
||||
} camera;
|
||||
layout(set = 0, binding = 1) uniform modelData {
|
||||
mat4 modelMatrix;
|
||||
};
|
||||
layout(location = 0) in vec3 pos;
|
||||
layout(location = 1) in vec3 col;
|
||||
layout(location = 2) out vec3 f_col;
|
||||
layout(location = 2) out vec3 f_col;
|
||||
void main() {
|
||||
f_col = col;
|
||||
gl_Position = camera.proj * camera.view * modelMatrix * vec4(pos, 1.0);
|
||||
f_col = col;
|
||||
gl_Position = camera.proj * camera.view * modelMatrix * vec4(pos, 1.0);
|
||||
})"
|
||||
);
|
||||
|
||||
nxt::ShaderModule fsModule = CreateShaderModule(device, nxt::ShaderStage::Fragment, R"(
|
||||
nxt::ShaderModule fsModule = CreateShaderModule(device, nxt::ShaderStage::Fragment, R"(
|
||||
#version 450
|
||||
layout(location = 2) in vec3 f_col;
|
||||
layout(location = 2) in vec3 f_col;
|
||||
out vec4 fragColor;
|
||||
void main() {
|
||||
fragColor = vec4(f_col, 1.0);
|
||||
})"
|
||||
);
|
||||
|
||||
nxt::ShaderModule fsReflectionModule = CreateShaderModule(device, nxt::ShaderStage::Fragment, R"(
|
||||
nxt::ShaderModule fsReflectionModule = CreateShaderModule(device, nxt::ShaderStage::Fragment, R"(
|
||||
#version 450
|
||||
layout(location = 2) in vec3 f_col;
|
||||
layout(location = 2) in vec3 f_col;
|
||||
out vec4 fragColor;
|
||||
void main() {
|
||||
fragColor = vec4(mix(f_col, vec3(0.5, 0.5, 0.5), 0.5), 1.0);
|
||||
})"
|
||||
);
|
||||
);
|
||||
|
||||
auto inputState = device.CreateInputStateBuilder()
|
||||
.SetAttribute(0, 0, nxt::VertexFormat::FloatR32G32B32, 0)
|
||||
.SetAttribute(1, 0, nxt::VertexFormat::FloatR32G32B32, 3 * sizeof(float))
|
||||
.SetInput(0, 6 * sizeof(float), nxt::InputStepMode::Vertex)
|
||||
.SetInput(1, 6 * sizeof(float), nxt::InputStepMode::Vertex)
|
||||
.GetResult();
|
||||
auto inputState = device.CreateInputStateBuilder()
|
||||
.SetAttribute(0, 0, nxt::VertexFormat::FloatR32G32B32, 0)
|
||||
.SetAttribute(1, 0, nxt::VertexFormat::FloatR32G32B32, 3 * sizeof(float))
|
||||
.SetInput(0, 6 * sizeof(float), nxt::InputStepMode::Vertex)
|
||||
.SetInput(1, 6 * sizeof(float), nxt::InputStepMode::Vertex)
|
||||
.GetResult();
|
||||
|
||||
nxt::BindGroupLayout bgl = device.CreateBindGroupLayoutBuilder()
|
||||
.SetBindingsType(nxt::ShaderStageBit::Vertex, nxt::BindingType::UniformBuffer, 0, 2)
|
||||
.GetResult();
|
||||
nxt::BindGroupLayout bgl = device.CreateBindGroupLayoutBuilder()
|
||||
.SetBindingsType(nxt::ShaderStageBit::Vertex, nxt::BindingType::UniformBuffer, 0, 2)
|
||||
.GetResult();
|
||||
|
||||
nxt::PipelineLayout pl = device.CreatePipelineLayoutBuilder()
|
||||
.SetBindGroupLayout(0, bgl)
|
||||
.GetResult();
|
||||
nxt::PipelineLayout pl = device.CreatePipelineLayoutBuilder()
|
||||
.SetBindGroupLayout(0, bgl)
|
||||
.GetResult();
|
||||
|
||||
cameraBuffer = device.CreateBufferBuilder()
|
||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Uniform)
|
||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
||||
.SetSize(sizeof(cameraData))
|
||||
.GetResult();
|
||||
cameraBuffer = device.CreateBufferBuilder()
|
||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Uniform)
|
||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
||||
.SetSize(sizeof(cameraData))
|
||||
.GetResult();
|
||||
|
||||
glm::mat4 transform(1.0);
|
||||
glm::mat4 transform(1.0);
|
||||
|
||||
transformBuffer[0] = device.CreateBufferBuilder()
|
||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Uniform)
|
||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
||||
.SetSize(sizeof(glm::mat4))
|
||||
.GetResult();
|
||||
transformBuffer[0].SetSubData(0, sizeof(glm::mat4) / sizeof(uint32_t), reinterpret_cast<uint32_t*>(&transform));
|
||||
transformBuffer[0].FreezeUsage(nxt::BufferUsageBit::Uniform);
|
||||
transformBuffer[0] = device.CreateBufferBuilder()
|
||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Uniform)
|
||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
||||
.SetSize(sizeof(glm::mat4))
|
||||
.GetResult();
|
||||
transformBuffer[0].SetSubData(0, sizeof(glm::mat4) / sizeof(uint32_t), reinterpret_cast<uint32_t*>(&transform));
|
||||
transformBuffer[0].FreezeUsage(nxt::BufferUsageBit::Uniform);
|
||||
|
||||
transform = glm::translate(transform, glm::vec3(0.f, -2.f, 0.f));
|
||||
transform = glm::translate(transform, glm::vec3(0.f, -2.f, 0.f));
|
||||
|
||||
transformBuffer[1] = device.CreateBufferBuilder()
|
||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Uniform)
|
||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
||||
.SetSize(sizeof(glm::mat4))
|
||||
.GetResult();
|
||||
transformBuffer[1].SetSubData(0, sizeof(glm::mat4) / sizeof(uint32_t), reinterpret_cast<uint32_t*>(&transform));
|
||||
transformBuffer[1].FreezeUsage(nxt::BufferUsageBit::Uniform);
|
||||
transformBuffer[1] = device.CreateBufferBuilder()
|
||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Uniform)
|
||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
||||
.SetSize(sizeof(glm::mat4))
|
||||
.GetResult();
|
||||
transformBuffer[1].SetSubData(0, sizeof(glm::mat4) / sizeof(uint32_t), reinterpret_cast<uint32_t*>(&transform));
|
||||
transformBuffer[1].FreezeUsage(nxt::BufferUsageBit::Uniform);
|
||||
|
||||
nxt::BufferView cameraBufferView = cameraBuffer.CreateBufferViewBuilder()
|
||||
.SetExtent(0, sizeof(cameraData))
|
||||
.GetResult();
|
||||
nxt::BufferView cameraBufferView = cameraBuffer.CreateBufferViewBuilder()
|
||||
.SetExtent(0, sizeof(cameraData))
|
||||
.GetResult();
|
||||
|
||||
nxt::BufferView transformBufferView[2] = {
|
||||
transformBuffer[0].CreateBufferViewBuilder()
|
||||
.SetExtent(0, sizeof(glm::mat4))
|
||||
.GetResult(),
|
||||
transformBuffer[1].CreateBufferViewBuilder()
|
||||
.SetExtent(0, sizeof(glm::mat4))
|
||||
.GetResult(),
|
||||
};
|
||||
nxt::BufferView transformBufferView[2] = {
|
||||
transformBuffer[0].CreateBufferViewBuilder()
|
||||
.SetExtent(0, sizeof(glm::mat4))
|
||||
.GetResult(),
|
||||
transformBuffer[1].CreateBufferViewBuilder()
|
||||
.SetExtent(0, sizeof(glm::mat4))
|
||||
.GetResult(),
|
||||
};
|
||||
|
||||
bindGroup[0] = device.CreateBindGroupBuilder()
|
||||
.SetLayout(bgl)
|
||||
.SetUsage(nxt::BindGroupUsage::Frozen)
|
||||
.SetBufferViews(0, 1, &cameraBufferView)
|
||||
.SetBufferViews(1, 1, &transformBufferView[0])
|
||||
.GetResult();
|
||||
bindGroup[0] = device.CreateBindGroupBuilder()
|
||||
.SetLayout(bgl)
|
||||
.SetUsage(nxt::BindGroupUsage::Frozen)
|
||||
.SetBufferViews(0, 1, &cameraBufferView)
|
||||
.SetBufferViews(1, 1, &transformBufferView[0])
|
||||
.GetResult();
|
||||
|
||||
bindGroup[1] = device.CreateBindGroupBuilder()
|
||||
.SetLayout(bgl)
|
||||
.SetUsage(nxt::BindGroupUsage::Frozen)
|
||||
.SetBufferViews(0, 1, &cameraBufferView)
|
||||
.SetBufferViews(1, 1, &transformBufferView[1])
|
||||
.GetResult();
|
||||
bindGroup[1] = device.CreateBindGroupBuilder()
|
||||
.SetLayout(bgl)
|
||||
.SetUsage(nxt::BindGroupUsage::Frozen)
|
||||
.SetBufferViews(0, 1, &cameraBufferView)
|
||||
.SetBufferViews(1, 1, &transformBufferView[1])
|
||||
.GetResult();
|
||||
|
||||
CreateDefaultRenderPass(device, &renderpass, &framebuffer);
|
||||
|
||||
auto depthStencilState = device.CreateDepthStencilStateBuilder()
|
||||
.SetDepthEnabled(true)
|
||||
.SetStencilEnabled(false)
|
||||
.GetResult();
|
||||
auto depthStencilState = device.CreateDepthStencilStateBuilder()
|
||||
.SetDepthEnabled(true)
|
||||
.SetStencilEnabled(false)
|
||||
.GetResult();
|
||||
|
||||
pipeline = device.CreatePipelineBuilder()
|
||||
.SetSubpass(renderpass, 0)
|
||||
.SetLayout(pl)
|
||||
.SetLayout(pl)
|
||||
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
|
||||
.SetStage(nxt::ShaderStage::Fragment, fsModule, "main")
|
||||
.SetInputState(inputState)
|
||||
.SetDepthStencilState(depthStencilState)
|
||||
.SetDepthStencilState(depthStencilState)
|
||||
.GetResult();
|
||||
|
||||
auto planeStencilState = device.CreateDepthStencilStateBuilder()
|
||||
.SetDepthEnabled(true)
|
||||
.SetDepthWrite(nxt::DepthWriteMode::Disabled)
|
||||
.SetStencilEnabled(true)
|
||||
.SetStencilCompareFunction(nxt::Face::Both, nxt::CompareFunction::Always)
|
||||
.SetStencilOperation(nxt::Face::Both, nxt::StencilOperation::Keep, nxt::StencilOperation::Keep, nxt::StencilOperation::Replace)
|
||||
.SetStencilMask(nxt::Face::Both, 0xff, 0xff)
|
||||
.GetResult();
|
||||
auto planeStencilState = device.CreateDepthStencilStateBuilder()
|
||||
.SetDepthEnabled(true)
|
||||
.SetDepthWrite(nxt::DepthWriteMode::Disabled)
|
||||
.SetStencilEnabled(true)
|
||||
.SetStencilCompareFunction(nxt::Face::Both, nxt::CompareFunction::Always)
|
||||
.SetStencilOperation(nxt::Face::Both, nxt::StencilOperation::Keep, nxt::StencilOperation::Keep, nxt::StencilOperation::Replace)
|
||||
.SetStencilMask(nxt::Face::Both, 0xff, 0xff)
|
||||
.GetResult();
|
||||
|
||||
planePipeline = device.CreatePipelineBuilder()
|
||||
.SetSubpass(renderpass, 0)
|
||||
.SetLayout(pl)
|
||||
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
|
||||
.SetStage(nxt::ShaderStage::Fragment, fsModule, "main")
|
||||
.SetInputState(inputState)
|
||||
.SetDepthStencilState(planeStencilState)
|
||||
.GetResult();
|
||||
planePipeline = device.CreatePipelineBuilder()
|
||||
.SetSubpass(renderpass, 0)
|
||||
.SetLayout(pl)
|
||||
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
|
||||
.SetStage(nxt::ShaderStage::Fragment, fsModule, "main")
|
||||
.SetInputState(inputState)
|
||||
.SetDepthStencilState(planeStencilState)
|
||||
.GetResult();
|
||||
|
||||
auto reflectionStencilState = device.CreateDepthStencilStateBuilder()
|
||||
.SetDepthEnabled(true)
|
||||
.SetDepthWrite(nxt::DepthWriteMode::Enabled)
|
||||
.SetStencilEnabled(true)
|
||||
.SetStencilCompareFunction(nxt::Face::Both, nxt::CompareFunction::Equal)
|
||||
.SetStencilOperation(nxt::Face::Both, nxt::StencilOperation::Keep, nxt::StencilOperation::Keep, nxt::StencilOperation::Replace)
|
||||
.SetStencilMask(nxt::Face::Both, 0xff, 0x00)
|
||||
.GetResult();
|
||||
auto reflectionStencilState = device.CreateDepthStencilStateBuilder()
|
||||
.SetDepthEnabled(true)
|
||||
.SetDepthWrite(nxt::DepthWriteMode::Enabled)
|
||||
.SetStencilEnabled(true)
|
||||
.SetStencilCompareFunction(nxt::Face::Both, nxt::CompareFunction::Equal)
|
||||
.SetStencilOperation(nxt::Face::Both, nxt::StencilOperation::Keep, nxt::StencilOperation::Keep, nxt::StencilOperation::Replace)
|
||||
.SetStencilMask(nxt::Face::Both, 0xff, 0x00)
|
||||
.GetResult();
|
||||
|
||||
reflectionPipeline = device.CreatePipelineBuilder()
|
||||
.SetSubpass(renderpass, 0)
|
||||
.SetLayout(pl)
|
||||
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
|
||||
.SetStage(nxt::ShaderStage::Fragment, fsReflectionModule, "main")
|
||||
.SetInputState(inputState)
|
||||
.SetDepthStencilState(reflectionStencilState)
|
||||
.GetResult();
|
||||
reflectionPipeline = device.CreatePipelineBuilder()
|
||||
.SetSubpass(renderpass, 0)
|
||||
.SetLayout(pl)
|
||||
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
|
||||
.SetStage(nxt::ShaderStage::Fragment, fsReflectionModule, "main")
|
||||
.SetInputState(inputState)
|
||||
.SetDepthStencilState(reflectionStencilState)
|
||||
.GetResult();
|
||||
|
||||
cameraData.proj = glm::perspective(glm::radians(45.0f), 1.f, 1.0f, 100.0f);
|
||||
cameraData.proj = glm::perspective(glm::radians(45.0f), 1.f, 1.0f, 100.0f);
|
||||
}
|
||||
|
||||
struct {uint32_t a; float b;} s;
|
||||
@ -302,34 +302,34 @@ void frame() {
|
||||
if (s.b >= 1.0f) {s.b = 0.0f;}
|
||||
static const uint32_t vertexBufferOffsets[1] = {0};
|
||||
|
||||
cameraData.view = glm::lookAt(
|
||||
glm::vec3(8.f * std::sin(glm::radians(s.b * 360.f)), 2.f, 8.f * std::cos(glm::radians(s.b * 360.f))),
|
||||
glm::vec3(0.0f, 0.0f, 0.0f),
|
||||
glm::vec3(0.0f, 1.0f, 0.0f)
|
||||
);
|
||||
cameraData.view = glm::lookAt(
|
||||
glm::vec3(8.f * std::sin(glm::radians(s.b * 360.f)), 2.f, 8.f * std::cos(glm::radians(s.b * 360.f))),
|
||||
glm::vec3(0.0f, 0.0f, 0.0f),
|
||||
glm::vec3(0.0f, 1.0f, 0.0f)
|
||||
);
|
||||
|
||||
cameraBuffer.TransitionUsage(nxt::BufferUsageBit::Mapped);
|
||||
cameraBuffer.SetSubData(0, sizeof(cameraData) / sizeof(uint32_t), reinterpret_cast<uint32_t*>(&cameraData));
|
||||
cameraBuffer.TransitionUsage(nxt::BufferUsageBit::Mapped);
|
||||
cameraBuffer.SetSubData(0, sizeof(cameraData) / sizeof(uint32_t), reinterpret_cast<uint32_t*>(&cameraData));
|
||||
|
||||
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
||||
.BeginRenderPass(renderpass, framebuffer)
|
||||
.SetPipeline(pipeline)
|
||||
.TransitionBufferUsage(cameraBuffer, nxt::BufferUsageBit::Uniform)
|
||||
.SetBindGroup(0, bindGroup[0])
|
||||
.TransitionBufferUsage(cameraBuffer, nxt::BufferUsageBit::Uniform)
|
||||
.SetBindGroup(0, bindGroup[0])
|
||||
.SetVertexBuffers(0, 1, &vertexBuffer, vertexBufferOffsets)
|
||||
.SetIndexBuffer(indexBuffer, 0, nxt::IndexFormat::Uint32)
|
||||
.DrawElements(36, 1, 0, 0)
|
||||
|
||||
.SetPipeline(planePipeline)
|
||||
.SetStencilReference(0x1, 0x1)
|
||||
.SetVertexBuffers(0, 1, &planeBuffer, vertexBufferOffsets)
|
||||
.DrawElements(6, 1, 0, 0)
|
||||
.SetPipeline(planePipeline)
|
||||
.SetStencilReference(0x1, 0x1)
|
||||
.SetVertexBuffers(0, 1, &planeBuffer, vertexBufferOffsets)
|
||||
.DrawElements(6, 1, 0, 0)
|
||||
|
||||
.SetPipeline(reflectionPipeline)
|
||||
.SetStencilReference(0x1, 0x1)
|
||||
.SetVertexBuffers(0, 1, &vertexBuffer, vertexBufferOffsets)
|
||||
.SetBindGroup(0, bindGroup[1])
|
||||
.DrawElements(36, 1, 0, 0)
|
||||
.SetPipeline(reflectionPipeline)
|
||||
.SetStencilReference(0x1, 0x1)
|
||||
.SetVertexBuffers(0, 1, &vertexBuffer, vertexBufferOffsets)
|
||||
.SetBindGroup(0, bindGroup[1])
|
||||
.DrawElements(36, 1, 0, 0)
|
||||
.EndRenderPass()
|
||||
.GetResult();
|
||||
|
||||
@ -344,7 +344,7 @@ int main(int argc, const char* argv[]) {
|
||||
init();
|
||||
|
||||
while (!ShouldQuit()) {
|
||||
frame();
|
||||
frame();
|
||||
USleep(16000);
|
||||
}
|
||||
|
||||
|
@ -110,12 +110,12 @@ namespace backend {
|
||||
cmd->~SetPushConstantsCmd();
|
||||
}
|
||||
break;
|
||||
case Command::SetStencilReference:
|
||||
{
|
||||
SetStencilReferenceCmd* cmd = commands->NextCommand<SetStencilReferenceCmd>();
|
||||
cmd->~SetStencilReferenceCmd();
|
||||
}
|
||||
break;
|
||||
case Command::SetStencilReference:
|
||||
{
|
||||
SetStencilReferenceCmd* cmd = commands->NextCommand<SetStencilReferenceCmd>();
|
||||
cmd->~SetStencilReferenceCmd();
|
||||
}
|
||||
break;
|
||||
case Command::SetBindGroup:
|
||||
{
|
||||
SetBindGroupCmd* cmd = commands->NextCommand<SetBindGroupCmd>();
|
||||
@ -571,9 +571,9 @@ namespace backend {
|
||||
break;
|
||||
|
||||
case Command::SetStencilReference:
|
||||
{
|
||||
SetStencilReferenceCmd* cmd = iterator.NextCommand<SetStencilReferenceCmd>();
|
||||
}
|
||||
{
|
||||
SetStencilReferenceCmd* cmd = iterator.NextCommand<SetStencilReferenceCmd>();
|
||||
}
|
||||
break;
|
||||
|
||||
case Command::SetBindGroup:
|
||||
|
@ -21,33 +21,33 @@ namespace backend {
|
||||
// DepthStencilStateBase
|
||||
|
||||
DepthStencilStateBase::DepthStencilStateBase(DepthStencilStateBuilder* builder)
|
||||
: depthEnabled(builder->depthEnabled), stencilEnabled(builder->stencilEnabled),
|
||||
depthInfo(builder->depthInfo),
|
||||
stencilInfos { builder->stencilInfos[0], builder->stencilInfos[1] } {
|
||||
: depthEnabled(builder->depthEnabled), stencilEnabled(builder->stencilEnabled),
|
||||
depthInfo(builder->depthInfo),
|
||||
stencilInfos { builder->stencilInfos[0], builder->stencilInfos[1] } {
|
||||
}
|
||||
|
||||
bool DepthStencilStateBase::DepthIsEnabled() const {
|
||||
return depthEnabled;
|
||||
}
|
||||
bool DepthStencilStateBase::DepthIsEnabled() const {
|
||||
return depthEnabled;
|
||||
}
|
||||
|
||||
bool DepthStencilStateBase::StencilIsEnabled() const {
|
||||
return stencilEnabled;
|
||||
}
|
||||
bool DepthStencilStateBase::StencilIsEnabled() const {
|
||||
return stencilEnabled;
|
||||
}
|
||||
|
||||
const DepthStencilStateBase::DepthInfo& DepthStencilStateBase::GetDepth() const {
|
||||
return depthInfo;
|
||||
}
|
||||
const DepthStencilStateBase::DepthInfo& DepthStencilStateBase::GetDepth() const {
|
||||
return depthInfo;
|
||||
}
|
||||
|
||||
const DepthStencilStateBase::StencilInfo& DepthStencilStateBase::GetStencil(nxt::Face face) const {
|
||||
switch (face) {
|
||||
case nxt::Face::Back:
|
||||
return stencilInfos[0];
|
||||
case nxt::Face::Front:
|
||||
return stencilInfos[1];
|
||||
default:
|
||||
ASSERT(false);
|
||||
}
|
||||
}
|
||||
const DepthStencilStateBase::StencilInfo& DepthStencilStateBase::GetStencil(nxt::Face face) const {
|
||||
switch (face) {
|
||||
case nxt::Face::Back:
|
||||
return stencilInfos[0];
|
||||
case nxt::Face::Front:
|
||||
return stencilInfos[1];
|
||||
default:
|
||||
ASSERT(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// DepthStencilStateBuilder
|
||||
@ -59,9 +59,9 @@ namespace backend {
|
||||
return device->CreateDepthStencilState(this);
|
||||
}
|
||||
|
||||
void DepthStencilStateBuilder::SetDepthEnabled(bool depthEnabled) {
|
||||
this->depthEnabled = depthEnabled;
|
||||
}
|
||||
void DepthStencilStateBuilder::SetDepthEnabled(bool depthEnabled) {
|
||||
this->depthEnabled = depthEnabled;
|
||||
}
|
||||
|
||||
void DepthStencilStateBuilder::SetDepthCompareFunction(nxt::CompareFunction depthCompareFunction) {
|
||||
depthInfo.compareFunction = depthCompareFunction;
|
||||
@ -71,48 +71,48 @@ namespace backend {
|
||||
depthInfo.depthWriteMode = depthWriteMode;
|
||||
}
|
||||
|
||||
void DepthStencilStateBuilder::SetStencilEnabled(bool stencilEnabled) {
|
||||
this->stencilEnabled = stencilEnabled;
|
||||
}
|
||||
void DepthStencilStateBuilder::SetStencilEnabled(bool stencilEnabled) {
|
||||
this->stencilEnabled = stencilEnabled;
|
||||
}
|
||||
|
||||
void DepthStencilStateBuilder::SetStencilOperation(nxt::Face face, nxt::StencilOperation stencilFail,
|
||||
nxt::StencilOperation depthFail, nxt::StencilOperation stencilPass) {
|
||||
if (face & nxt::Face::Back) {
|
||||
auto& stencilInfo = stencilInfos[0];
|
||||
stencilInfo.stencilFail = stencilFail;
|
||||
stencilInfo.depthFail = stencilFail;
|
||||
stencilInfo.stencilPass = stencilPass;
|
||||
stencilInfo.stencilFail = stencilFail;
|
||||
stencilInfo.depthFail = stencilFail;
|
||||
stencilInfo.stencilPass = stencilPass;
|
||||
}
|
||||
if (face & nxt::Face::Front) {
|
||||
auto& stencilInfo = stencilInfos[1];
|
||||
stencilInfo.stencilFail = stencilFail;
|
||||
stencilInfo.depthFail = stencilFail;
|
||||
stencilInfo.stencilPass = stencilPass;
|
||||
auto& stencilInfo = stencilInfos[1];
|
||||
stencilInfo.stencilFail = stencilFail;
|
||||
stencilInfo.depthFail = stencilFail;
|
||||
stencilInfo.stencilPass = stencilPass;
|
||||
}
|
||||
}
|
||||
|
||||
void DepthStencilStateBuilder::SetStencilCompareFunction(nxt::Face face, nxt::CompareFunction stencilCompareFunction) {
|
||||
if (face & nxt::Face::Back) {
|
||||
auto& stencilInfo = stencilInfos[0];
|
||||
stencilInfo.compareFunction = stencilCompareFunction;
|
||||
}
|
||||
if (face & nxt::Face::Front) {
|
||||
auto& stencilInfo = stencilInfos[1];
|
||||
stencilInfo.compareFunction = stencilCompareFunction;
|
||||
}
|
||||
if (face & nxt::Face::Back) {
|
||||
auto& stencilInfo = stencilInfos[0];
|
||||
stencilInfo.compareFunction = stencilCompareFunction;
|
||||
}
|
||||
if (face & nxt::Face::Front) {
|
||||
auto& stencilInfo = stencilInfos[1];
|
||||
stencilInfo.compareFunction = stencilCompareFunction;
|
||||
}
|
||||
}
|
||||
|
||||
void DepthStencilStateBuilder::SetStencilMask(nxt::Face face, uint32_t readMask, uint32_t writeMask) {
|
||||
if (face & nxt::Face::Back) {
|
||||
auto& stencilInfo = stencilInfos[0];
|
||||
stencilInfo.readMask = readMask;
|
||||
stencilInfo.writeMask = writeMask;
|
||||
}
|
||||
if (face & nxt::Face::Front) {
|
||||
auto& stencilInfo = stencilInfos[1];
|
||||
stencilInfo.readMask = readMask;
|
||||
stencilInfo.writeMask = writeMask;
|
||||
}
|
||||
if (face & nxt::Face::Back) {
|
||||
auto& stencilInfo = stencilInfos[0];
|
||||
stencilInfo.readMask = readMask;
|
||||
stencilInfo.writeMask = writeMask;
|
||||
}
|
||||
if (face & nxt::Face::Front) {
|
||||
auto& stencilInfo = stencilInfos[1];
|
||||
stencilInfo.readMask = readMask;
|
||||
stencilInfo.writeMask = writeMask;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -35,21 +35,21 @@ namespace backend {
|
||||
|
||||
struct StencilInfo {
|
||||
nxt::CompareFunction compareFunction = nxt::CompareFunction::Always;
|
||||
nxt::StencilOperation stencilFail = nxt::StencilOperation::Keep;
|
||||
nxt::StencilOperation depthFail = nxt::StencilOperation::Keep;
|
||||
nxt::StencilOperation stencilPass = nxt::StencilOperation::Keep;
|
||||
nxt::StencilOperation stencilFail = nxt::StencilOperation::Keep;
|
||||
nxt::StencilOperation depthFail = nxt::StencilOperation::Keep;
|
||||
nxt::StencilOperation stencilPass = nxt::StencilOperation::Keep;
|
||||
uint32_t readMask = 0xff;
|
||||
uint32_t writeMask = 0xff;
|
||||
};
|
||||
|
||||
bool DepthIsEnabled() const;
|
||||
bool StencilIsEnabled() const;
|
||||
bool DepthIsEnabled() const;
|
||||
bool StencilIsEnabled() const;
|
||||
const DepthInfo& GetDepth() const;
|
||||
const StencilInfo& GetStencil(nxt::Face face) const;
|
||||
|
||||
private:
|
||||
bool depthEnabled = false;
|
||||
bool stencilEnabled = false;
|
||||
bool depthEnabled = false;
|
||||
bool stencilEnabled = false;
|
||||
DepthInfo depthInfo;
|
||||
StencilInfo stencilInfos[2];
|
||||
};
|
||||
@ -59,10 +59,10 @@ namespace backend {
|
||||
DepthStencilStateBuilder(DeviceBase* device);
|
||||
|
||||
// NXT API
|
||||
void SetDepthEnabled(bool depthEnabled);
|
||||
void SetDepthCompareFunction(nxt::CompareFunction depthCompareFunction);
|
||||
void SetDepthEnabled(bool depthEnabled);
|
||||
void SetDepthCompareFunction(nxt::CompareFunction depthCompareFunction);
|
||||
void SetDepthWrite(nxt::DepthWriteMode depthWriteMode);
|
||||
void SetStencilEnabled(bool stencilEnabled);
|
||||
void SetStencilEnabled(bool stencilEnabled);
|
||||
void SetStencilOperation(nxt::Face face, nxt::StencilOperation stencilFail,
|
||||
nxt::StencilOperation depthFail, nxt::StencilOperation stencilPass);
|
||||
void SetStencilCompareFunction(nxt::Face face, nxt::CompareFunction stencilCompareFunction);
|
||||
@ -73,8 +73,8 @@ namespace backend {
|
||||
|
||||
DepthStencilStateBase* GetResultImpl() override;
|
||||
|
||||
bool depthEnabled;
|
||||
bool stencilEnabled;
|
||||
bool depthEnabled;
|
||||
bool stencilEnabled;
|
||||
DepthStencilStateBase::DepthInfo depthInfo;
|
||||
DepthStencilStateBase::StencilInfo stencilInfos[2];
|
||||
};
|
||||
|
@ -96,9 +96,9 @@ namespace backend {
|
||||
return inputState.Get();
|
||||
}
|
||||
|
||||
DepthStencilStateBase* PipelineBase::GetDepthStencilState() {
|
||||
return depthStencilState.Get();
|
||||
}
|
||||
DepthStencilStateBase* PipelineBase::GetDepthStencilState() {
|
||||
return depthStencilState.Get();
|
||||
}
|
||||
|
||||
bool PipelineBase::IsCompute() const {
|
||||
return stageMask == nxt::ShaderStageBit::Compute;
|
||||
@ -123,9 +123,9 @@ namespace backend {
|
||||
if (!inputState) {
|
||||
inputState = device->CreateInputStateBuilder()->GetResult();
|
||||
}
|
||||
if (!depthStencilState) {
|
||||
depthStencilState = device->CreateDepthStencilStateBuilder()->GetResult();
|
||||
}
|
||||
if (!depthStencilState) {
|
||||
depthStencilState = device->CreateDepthStencilStateBuilder()->GetResult();
|
||||
}
|
||||
|
||||
return device->CreatePipeline(this);
|
||||
}
|
||||
@ -165,9 +165,9 @@ namespace backend {
|
||||
this->inputState = inputState;
|
||||
}
|
||||
|
||||
void PipelineBuilder::SetDepthStencilState(DepthStencilStateBase* depthStencilState) {
|
||||
this->depthStencilState = depthStencilState;
|
||||
}
|
||||
void PipelineBuilder::SetDepthStencilState(DepthStencilStateBase* depthStencilState) {
|
||||
this->depthStencilState = depthStencilState;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ namespace backend {
|
||||
PipelineLayoutBase* GetLayout();
|
||||
RenderPassBase* GetRenderPass();
|
||||
InputStateBase* GetInputState();
|
||||
DepthStencilStateBase* GetDepthStencilState();
|
||||
DepthStencilStateBase* GetDepthStencilState();
|
||||
|
||||
// TODO(cwallez@chromium.org): split compute and render pipelines
|
||||
bool IsCompute() const;
|
||||
@ -61,7 +61,7 @@ namespace backend {
|
||||
uint32_t subpass;
|
||||
PerStage<PushConstantInfo> pushConstants;
|
||||
Ref<InputStateBase> inputState;
|
||||
Ref<DepthStencilStateBase> depthStencilState;
|
||||
Ref<DepthStencilStateBase> depthStencilState;
|
||||
};
|
||||
|
||||
class PipelineBuilder : public Builder<PipelineBase> {
|
||||
@ -79,7 +79,7 @@ namespace backend {
|
||||
void SetSubpass(RenderPassBase* renderPass, uint32_t subpass);
|
||||
void SetStage(nxt::ShaderStage stage, ShaderModuleBase* module, const char* entryPoint);
|
||||
void SetInputState(InputStateBase* inputState);
|
||||
void SetDepthStencilState(DepthStencilStateBase* depthStencilState);
|
||||
void SetDepthStencilState(DepthStencilStateBase* depthStencilState);
|
||||
|
||||
private:
|
||||
friend class PipelineBase;
|
||||
@ -92,7 +92,7 @@ namespace backend {
|
||||
nxt::ShaderStageBit stageMask;
|
||||
PerStage<StageInfo> stages;
|
||||
Ref<InputStateBase> inputState;
|
||||
Ref<DepthStencilStateBase> depthStencilState;
|
||||
Ref<DepthStencilStateBase> depthStencilState;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -667,48 +667,48 @@ namespace metal {
|
||||
|
||||
static MTLCompareFunction DepthStencilCompareFunction(nxt::CompareFunction compareFunction) {
|
||||
switch (compareFunction) {
|
||||
case nxt::CompareFunction::Never:
|
||||
return MTLCompareFunctionNever;
|
||||
case nxt::CompareFunction::Less:
|
||||
return MTLCompareFunctionLess;
|
||||
case nxt::CompareFunction::LessEqual:
|
||||
return MTLCompareFunctionLessEqual;
|
||||
case nxt::CompareFunction::Greater:
|
||||
return MTLCompareFunctionGreater;
|
||||
case nxt::CompareFunction::GreaterEqual:
|
||||
return MTLCompareFunctionGreaterEqual;
|
||||
case nxt::CompareFunction::NotEqual:
|
||||
return MTLCompareFunctionNotEqual;
|
||||
case nxt::CompareFunction::Equal:
|
||||
return MTLCompareFunctionEqual;
|
||||
case nxt::CompareFunction::Always:
|
||||
return MTLCompareFunctionAlways;
|
||||
default:
|
||||
ASSERT(false);
|
||||
}
|
||||
case nxt::CompareFunction::Never:
|
||||
return MTLCompareFunctionNever;
|
||||
case nxt::CompareFunction::Less:
|
||||
return MTLCompareFunctionLess;
|
||||
case nxt::CompareFunction::LessEqual:
|
||||
return MTLCompareFunctionLessEqual;
|
||||
case nxt::CompareFunction::Greater:
|
||||
return MTLCompareFunctionGreater;
|
||||
case nxt::CompareFunction::GreaterEqual:
|
||||
return MTLCompareFunctionGreaterEqual;
|
||||
case nxt::CompareFunction::NotEqual:
|
||||
return MTLCompareFunctionNotEqual;
|
||||
case nxt::CompareFunction::Equal:
|
||||
return MTLCompareFunctionEqual;
|
||||
case nxt::CompareFunction::Always:
|
||||
return MTLCompareFunctionAlways;
|
||||
default:
|
||||
ASSERT(false);
|
||||
}
|
||||
}
|
||||
|
||||
static MTLStencilOperation StencilOperation(nxt::StencilOperation stencilOperation) {
|
||||
switch (stencilOperation) {
|
||||
case nxt::StencilOperation::Keep:
|
||||
return MTLStencilOperationKeep;
|
||||
case nxt::StencilOperation::Zero:
|
||||
return MTLStencilOperationZero;
|
||||
case nxt::StencilOperation::Replace:
|
||||
return MTLStencilOperationReplace;
|
||||
case nxt::StencilOperation::Invert:
|
||||
return MTLStencilOperationInvert;
|
||||
case nxt::StencilOperation::IncrementClamp:
|
||||
return MTLStencilOperationIncrementClamp;
|
||||
case nxt::StencilOperation::DecrementClamp:
|
||||
return MTLStencilOperationDecrementClamp;
|
||||
case nxt::StencilOperation::IncrementWrap:
|
||||
return MTLStencilOperationIncrementWrap;
|
||||
case nxt::StencilOperation::DecrementWrap:
|
||||
return MTLStencilOperationDecrementWrap;
|
||||
default:
|
||||
ASSERT(false);
|
||||
}
|
||||
case nxt::StencilOperation::Keep:
|
||||
return MTLStencilOperationKeep;
|
||||
case nxt::StencilOperation::Zero:
|
||||
return MTLStencilOperationZero;
|
||||
case nxt::StencilOperation::Replace:
|
||||
return MTLStencilOperationReplace;
|
||||
case nxt::StencilOperation::Invert:
|
||||
return MTLStencilOperationInvert;
|
||||
case nxt::StencilOperation::IncrementClamp:
|
||||
return MTLStencilOperationIncrementClamp;
|
||||
case nxt::StencilOperation::DecrementClamp:
|
||||
return MTLStencilOperationDecrementClamp;
|
||||
case nxt::StencilOperation::IncrementWrap:
|
||||
return MTLStencilOperationIncrementWrap;
|
||||
case nxt::StencilOperation::DecrementWrap:
|
||||
return MTLStencilOperationDecrementWrap;
|
||||
default:
|
||||
ASSERT(false);
|
||||
}
|
||||
}
|
||||
|
||||
DepthStencilState::DepthStencilState(Device* device, DepthStencilStateBuilder* builder)
|
||||
@ -728,7 +728,7 @@ namespace metal {
|
||||
default:
|
||||
ASSERT(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (StencilIsEnabled()) {
|
||||
|
@ -50,9 +50,9 @@ namespace null {
|
||||
CommandBufferBase* Device::CreateCommandBuffer(CommandBufferBuilder* builder) {
|
||||
return new CommandBufferBase(builder);
|
||||
}
|
||||
DepthStencilStateBase* Device::CreateDepthStencilState(DepthStencilStateBuilder* builder) {
|
||||
return new DepthStencilStateBase(builder);
|
||||
}
|
||||
DepthStencilStateBase* Device::CreateDepthStencilState(DepthStencilStateBuilder* builder) {
|
||||
return new DepthStencilStateBase(builder);
|
||||
}
|
||||
InputStateBase* Device::CreateInputState(InputStateBuilder* builder) {
|
||||
return new InputStateBase(builder);
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ namespace null {
|
||||
class Buffer;
|
||||
using BufferView = BufferViewBase;
|
||||
using CommandBuffer = CommandBufferBase;
|
||||
using DepthStencilState = DepthStencilStateBase;
|
||||
using DepthStencilState = DepthStencilStateBase;
|
||||
using InputState = InputStateBase;
|
||||
using Framebuffer = FramebufferBase;
|
||||
using Pipeline = PipelineBase;
|
||||
@ -60,7 +60,7 @@ namespace null {
|
||||
using BufferType = Buffer;
|
||||
using BufferViewType = BufferView;
|
||||
using CommandBufferType = CommandBuffer;
|
||||
using DepthStencilStateType = DepthStencilState;
|
||||
using DepthStencilStateType = DepthStencilState;
|
||||
using InputStateType = InputState;
|
||||
using FramebufferType = Framebuffer;
|
||||
using PipelineType = Pipeline;
|
||||
@ -88,7 +88,7 @@ namespace null {
|
||||
BufferBase* CreateBuffer(BufferBuilder* builder) override;
|
||||
BufferViewBase* CreateBufferView(BufferViewBuilder* builder) override;
|
||||
CommandBufferBase* CreateCommandBuffer(CommandBufferBuilder* builder) override;
|
||||
DepthStencilStateBase* CreateDepthStencilState(DepthStencilStateBuilder* builder) override;
|
||||
DepthStencilStateBase* CreateDepthStencilState(DepthStencilStateBuilder* builder) override;
|
||||
InputStateBase* CreateInputState(InputStateBuilder* builder) override;
|
||||
FramebufferBase* CreateFramebuffer(FramebufferBuilder* builder) override;
|
||||
PipelineBase* CreatePipeline(PipelineBuilder* builder) override;
|
||||
|
@ -184,7 +184,7 @@ namespace opengl {
|
||||
DepthStencilState* depthStencilState = ToBackend(lastPipeline->GetDepthStencilState());
|
||||
depthStencilState->ApplyStencilReferenceNow(cmd->backReference, cmd->frontReference);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
case Command::SetBindGroup:
|
||||
{
|
||||
|
@ -28,8 +28,8 @@ namespace opengl {
|
||||
|
||||
void HACKCLEAR() {
|
||||
glClearColor(0, 0, 0, 1);
|
||||
glStencilMask(0xff);
|
||||
glClearStencil(0);
|
||||
glStencilMask(0xff);
|
||||
glClearStencil(0);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
}
|
||||
|
||||
@ -45,51 +45,51 @@ namespace opengl {
|
||||
*device = reinterpret_cast<nxtDevice>(new Device);
|
||||
}
|
||||
|
||||
static GLuint OpenGLCompareFunction(nxt::CompareFunction compareFunction) {
|
||||
switch (compareFunction) {
|
||||
case nxt::CompareFunction::Never:
|
||||
return GL_NEVER;
|
||||
case nxt::CompareFunction::Less:
|
||||
return GL_LESS;
|
||||
case nxt::CompareFunction::LessEqual:
|
||||
return GL_LEQUAL;
|
||||
case nxt::CompareFunction::Greater:
|
||||
return GL_GREATER;
|
||||
case nxt::CompareFunction::GreaterEqual:
|
||||
return GL_GEQUAL;
|
||||
case nxt::CompareFunction::NotEqual:
|
||||
return GL_NOTEQUAL;
|
||||
case nxt::CompareFunction::Equal:
|
||||
return GL_EQUAL;
|
||||
case nxt::CompareFunction::Always:
|
||||
return GL_ALWAYS;
|
||||
default:
|
||||
ASSERT(false);
|
||||
}
|
||||
}
|
||||
static GLuint OpenGLCompareFunction(nxt::CompareFunction compareFunction) {
|
||||
switch (compareFunction) {
|
||||
case nxt::CompareFunction::Never:
|
||||
return GL_NEVER;
|
||||
case nxt::CompareFunction::Less:
|
||||
return GL_LESS;
|
||||
case nxt::CompareFunction::LessEqual:
|
||||
return GL_LEQUAL;
|
||||
case nxt::CompareFunction::Greater:
|
||||
return GL_GREATER;
|
||||
case nxt::CompareFunction::GreaterEqual:
|
||||
return GL_GEQUAL;
|
||||
case nxt::CompareFunction::NotEqual:
|
||||
return GL_NOTEQUAL;
|
||||
case nxt::CompareFunction::Equal:
|
||||
return GL_EQUAL;
|
||||
case nxt::CompareFunction::Always:
|
||||
return GL_ALWAYS;
|
||||
default:
|
||||
ASSERT(false);
|
||||
}
|
||||
}
|
||||
|
||||
static GLuint OpenGLStencilOperation(nxt::StencilOperation stencilOperation) {
|
||||
switch (stencilOperation) {
|
||||
case nxt::StencilOperation::Keep:
|
||||
return GL_KEEP;
|
||||
case nxt::StencilOperation::Zero:
|
||||
return GL_ZERO;
|
||||
case nxt::StencilOperation::Replace:
|
||||
return GL_REPLACE;
|
||||
case nxt::StencilOperation::Invert:
|
||||
return GL_INVERT;
|
||||
case nxt::StencilOperation::IncrementClamp:
|
||||
return GL_INCR;
|
||||
case nxt::StencilOperation::DecrementClamp:
|
||||
return GL_DECR;
|
||||
case nxt::StencilOperation::IncrementWrap:
|
||||
return GL_INCR_WRAP;
|
||||
case nxt::StencilOperation::DecrementWrap:
|
||||
return GL_DECR_WRAP;
|
||||
default:
|
||||
ASSERT(false);
|
||||
}
|
||||
}
|
||||
static GLuint OpenGLStencilOperation(nxt::StencilOperation stencilOperation) {
|
||||
switch (stencilOperation) {
|
||||
case nxt::StencilOperation::Keep:
|
||||
return GL_KEEP;
|
||||
case nxt::StencilOperation::Zero:
|
||||
return GL_ZERO;
|
||||
case nxt::StencilOperation::Replace:
|
||||
return GL_REPLACE;
|
||||
case nxt::StencilOperation::Invert:
|
||||
return GL_INVERT;
|
||||
case nxt::StencilOperation::IncrementClamp:
|
||||
return GL_INCR;
|
||||
case nxt::StencilOperation::DecrementClamp:
|
||||
return GL_DECR;
|
||||
case nxt::StencilOperation::IncrementWrap:
|
||||
return GL_INCR_WRAP;
|
||||
case nxt::StencilOperation::DecrementWrap:
|
||||
return GL_DECR_WRAP;
|
||||
default:
|
||||
ASSERT(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Device
|
||||
|
||||
@ -108,9 +108,9 @@ namespace opengl {
|
||||
CommandBufferBase* Device::CreateCommandBuffer(CommandBufferBuilder* builder) {
|
||||
return new CommandBuffer(this, builder);
|
||||
}
|
||||
DepthStencilStateBase* Device::CreateDepthStencilState(DepthStencilStateBuilder* builder) {
|
||||
return new DepthStencilState(this, builder);
|
||||
}
|
||||
DepthStencilStateBase* Device::CreateDepthStencilState(DepthStencilStateBuilder* builder) {
|
||||
return new DepthStencilState(this, builder);
|
||||
}
|
||||
InputStateBase* Device::CreateInputState(InputStateBuilder* builder) {
|
||||
return new InputState(this, builder);
|
||||
}
|
||||
@ -186,17 +186,17 @@ namespace opengl {
|
||||
|
||||
// DepthStencilState
|
||||
|
||||
DepthStencilState::DepthStencilState(Device* device, DepthStencilStateBuilder* builder)
|
||||
: DepthStencilStateBase(builder), device(device) {
|
||||
DepthStencilState::DepthStencilState(Device* device, DepthStencilStateBuilder* builder)
|
||||
: DepthStencilStateBase(builder), device(device) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void DepthStencilState::ApplyNow() {
|
||||
if (DepthIsEnabled()) {
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
auto& depth = GetDepth();
|
||||
glDepthFunc(OpenGLCompareFunction(depth.compareFunction));
|
||||
switch (depth.depthWriteMode) {
|
||||
void DepthStencilState::ApplyNow() {
|
||||
if (DepthIsEnabled()) {
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
auto& depth = GetDepth();
|
||||
glDepthFunc(OpenGLCompareFunction(depth.compareFunction));
|
||||
switch (depth.depthWriteMode) {
|
||||
case nxt::DepthWriteMode::Disabled:
|
||||
glDepthMask(GL_FALSE);
|
||||
break;
|
||||
@ -206,14 +206,14 @@ namespace opengl {
|
||||
default:
|
||||
ASSERT(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
if (StencilIsEnabled()) {
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
if (StencilIsEnabled()) {
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
auto& back = GetStencil(nxt::Face::Back);
|
||||
auto& front = GetStencil(nxt::Face::Front);
|
||||
|
||||
@ -228,13 +228,13 @@ namespace opengl {
|
||||
OpenGLStencilOperation(front.stencilPass)
|
||||
);
|
||||
|
||||
glStencilMaskSeparate(GL_BACK, back.writeMask);
|
||||
glStencilMaskSeparate(GL_BACK, back.writeMask);
|
||||
glStencilMaskSeparate(GL_FRONT, front.writeMask);
|
||||
}
|
||||
else {
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
}
|
||||
}
|
||||
|
||||
void DepthStencilState::ApplyStencilReferenceNow(uint32_t backReference, uint32_t frontReference) {
|
||||
if (StencilIsEnabled()) {
|
||||
|
@ -38,7 +38,7 @@ namespace opengl {
|
||||
class Buffer;
|
||||
class BufferView;
|
||||
class CommandBuffer;
|
||||
class DepthStencilState;
|
||||
class DepthStencilState;
|
||||
class InputState;
|
||||
class Pipeline;
|
||||
class PipelineLayout;
|
||||
@ -56,7 +56,7 @@ namespace opengl {
|
||||
using BufferType = Buffer;
|
||||
using BufferViewType = BufferView;
|
||||
using CommandBufferType = CommandBuffer;
|
||||
using DepthStencilStateType = DepthStencilState;
|
||||
using DepthStencilStateType = DepthStencilState;
|
||||
using InputStateType = InputState;
|
||||
using PipelineType = Pipeline;
|
||||
using PipelineLayoutType = PipelineLayout;
|
||||
@ -82,7 +82,7 @@ namespace opengl {
|
||||
BufferBase* CreateBuffer(BufferBuilder* builder) override;
|
||||
BufferViewBase* CreateBufferView(BufferViewBuilder* builder) override;
|
||||
CommandBufferBase* CreateCommandBuffer(CommandBufferBuilder* builder) override;
|
||||
DepthStencilStateBase* CreateDepthStencilState(DepthStencilStateBuilder* builder) override;
|
||||
DepthStencilStateBase* CreateDepthStencilState(DepthStencilStateBuilder* builder) override;
|
||||
InputStateBase* CreateInputState(InputStateBuilder* builder) override;
|
||||
FramebufferBase* CreateFramebuffer(FramebufferBuilder* builder) override;
|
||||
PipelineBase* CreatePipeline(PipelineBuilder* builder) override;
|
||||
@ -136,15 +136,15 @@ namespace opengl {
|
||||
Device* device;
|
||||
};
|
||||
|
||||
class DepthStencilState : public DepthStencilStateBase {
|
||||
public:
|
||||
DepthStencilState(Device* device, DepthStencilStateBuilder* builder);
|
||||
void ApplyNow();
|
||||
class DepthStencilState : public DepthStencilStateBase {
|
||||
public:
|
||||
DepthStencilState(Device* device, DepthStencilStateBuilder* builder);
|
||||
void ApplyNow();
|
||||
void ApplyStencilReferenceNow(uint32_t backReference, uint32_t frontReference);
|
||||
|
||||
private:
|
||||
Device* device;
|
||||
};
|
||||
private:
|
||||
Device* device;
|
||||
};
|
||||
|
||||
class Framebuffer : public FramebufferBase {
|
||||
public:
|
||||
|
Loading…
x
Reference in New Issue
Block a user