Fix OpenGL stencil clear hack. Improve example stencil reflection
diff --git a/examples/HelloDepthStencil.cpp b/examples/HelloDepthStencil.cpp
index df5ba0f..437cc9e 100644
--- a/examples/HelloDepthStencil.cpp
+++ b/examples/HelloDepthStencil.cpp
@@ -163,6 +163,15 @@
})"
);
+ nxt::ShaderModule fsReflectionModule = CreateShaderModule(device, nxt::ShaderStage::Fragment, R"(
+ #version 450
+ 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))
@@ -278,7 +287,7 @@
.SetSubpass(renderpass, 0)
.SetLayout(pl)
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
- .SetStage(nxt::ShaderStage::Fragment, fsModule, "main")
+ .SetStage(nxt::ShaderStage::Fragment, fsReflectionModule, "main")
.SetInputState(inputState)
.SetDepthStencilState(reflectionStencilState)
.GetResult();
@@ -294,8 +303,8 @@
static const uint32_t vertexBufferOffsets[1] = {0};
cameraData.view = glm::lookAt(
- glm::vec3(10.f * std::sin(glm::radians(s.b * 360.f)), 2.f, 10.f * std::cos(glm::radians(s.b * 360.f))),
- glm::vec3(0.0f, -1.0f, 0.0f),
+ 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)
);
diff --git a/src/backend/opengl/OpenGLBackend.cpp b/src/backend/opengl/OpenGLBackend.cpp
index 9322a27..7118e3a 100644
--- a/src/backend/opengl/OpenGLBackend.cpp
+++ b/src/backend/opengl/OpenGLBackend.cpp
@@ -28,9 +28,9 @@
void HACKCLEAR() {
glClearColor(0, 0, 0, 1);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glStencilMask(0xff);
glClearStencil(0);
- glClear(GL_STENCIL_BUFFER_BIT);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
}
void Init(void* (*getProc)(const char*), nxtProcTable* procs, nxtDevice* device) {