Fix some nits from depth-stencil PR
This commit is contained in:
parent
58c76b3fe4
commit
001c2ea98f
|
@ -58,7 +58,7 @@ void initBuffers() {
|
||||||
20, 21, 22,
|
20, 21, 22,
|
||||||
20, 22, 23
|
20, 22, 23
|
||||||
};
|
};
|
||||||
indexBuffer = CreateFrozenBufferFromData(device, (void*)indexData, sizeof(indexData), nxt::BufferUsageBit::Index);
|
indexBuffer = CreateFrozenBufferFromData(device, indexData, sizeof(indexData), nxt::BufferUsageBit::Index);
|
||||||
|
|
||||||
static const float vertexData[6 * 4 * 6] = {
|
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,
|
||||||
|
@ -91,7 +91,7 @@ void initBuffers() {
|
||||||
-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 = CreateFrozenBufferFromData(device, (void*)vertexData, sizeof(vertexData), nxt::BufferUsageBit::Vertex);
|
vertexBuffer = CreateFrozenBufferFromData(device, vertexData, sizeof(vertexData), nxt::BufferUsageBit::Vertex);
|
||||||
|
|
||||||
static const float planeData[6 * 4] = {
|
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,
|
||||||
|
@ -99,7 +99,7 @@ void initBuffers() {
|
||||||
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 = CreateFrozenBufferFromData(device, (void*)planeData, sizeof(planeData), nxt::BufferUsageBit::Vertex);
|
planeBuffer = CreateFrozenBufferFromData(device, planeData, sizeof(planeData), nxt::BufferUsageBit::Vertex);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CameraData {
|
struct CameraData {
|
||||||
|
@ -171,10 +171,10 @@ void init() {
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
glm::mat4 transform(1.0);
|
glm::mat4 transform(1.0);
|
||||||
transformBuffer[0] = CreateFrozenBufferFromData(device, (void*)&transform, sizeof(glm::mat4), nxt::BufferUsageBit::Uniform);
|
transformBuffer[0] = CreateFrozenBufferFromData(device, &transform, sizeof(glm::mat4), 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] = CreateFrozenBufferFromData(device, (void*)&transform, sizeof(glm::mat4), nxt::BufferUsageBit::Uniform);
|
transformBuffer[1] = CreateFrozenBufferFromData(device, &transform, sizeof(glm::mat4), nxt::BufferUsageBit::Uniform);
|
||||||
|
|
||||||
nxt::BufferView cameraBufferView = cameraBuffer.CreateBufferViewBuilder()
|
nxt::BufferView cameraBufferView = cameraBuffer.CreateBufferViewBuilder()
|
||||||
.SetExtent(0, sizeof(CameraData))
|
.SetExtent(0, sizeof(CameraData))
|
||||||
|
|
|
@ -245,7 +245,7 @@ void CreateDefaultRenderPass(const nxt::Device& device, nxt::RenderPass* renderP
|
||||||
.GetResult();
|
.GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
nxt::Buffer CreateFrozenBufferFromData(const nxt::Device& device, void* data, uint32_t size, nxt::BufferUsageBit usage) {
|
nxt::Buffer CreateFrozenBufferFromData(const nxt::Device& device, const void* data, uint32_t size, nxt::BufferUsageBit usage) {
|
||||||
nxt::Buffer buffer = device.CreateBufferBuilder()
|
nxt::Buffer buffer = device.CreateBufferBuilder()
|
||||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | usage)
|
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | usage)
|
||||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
||||||
|
@ -307,10 +307,6 @@ extern "C" {
|
||||||
return CreateShaderModule(device, static_cast<nxt::ShaderStage>(stage), source).Release();
|
return CreateShaderModule(device, static_cast<nxt::ShaderStage>(stage), source).Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
nxtBuffer CreateFrozenBufferFromData(nxtDevice device, void* data, uint32_t size, nxtBufferUsageBit usage) {
|
|
||||||
return CreateFrozenBufferFromData(device, data, size, usage);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DoSwapBuffers() {
|
void DoSwapBuffers() {
|
||||||
if (cmdBufType == CmdBufType::Terrible) {
|
if (cmdBufType == CmdBufType::Terrible) {
|
||||||
c2sBuf->Flush();
|
c2sBuf->Flush();
|
||||||
|
|
|
@ -34,9 +34,8 @@ extern "C" {
|
||||||
nxt::Device CreateCppNXTDevice();
|
nxt::Device CreateCppNXTDevice();
|
||||||
nxt::ShaderModule CreateShaderModule(const nxt::Device& device, nxt::ShaderStage stage, const char* source);
|
nxt::ShaderModule CreateShaderModule(const nxt::Device& device, nxt::ShaderStage stage, const char* source);
|
||||||
void CreateDefaultRenderPass(const nxt::Device& device, nxt::RenderPass* renderPass, nxt::Framebuffer* framebuffer);
|
void CreateDefaultRenderPass(const nxt::Device& device, nxt::RenderPass* renderPass, nxt::Framebuffer* framebuffer);
|
||||||
nxt::Buffer CreateFrozenBufferFromData(const nxt::Device& device, void* data, uint32_t size, nxt::BufferUsageBit usage);
|
nxt::Buffer CreateFrozenBufferFromData(const nxt::Device& device, const void* data, uint32_t size, nxt::BufferUsageBit usage);
|
||||||
#else
|
#else
|
||||||
nxtDevice CreateNXTDevice();
|
nxtDevice CreateNXTDevice();
|
||||||
nxtShaderModule CreateShaderModule(nxtDevice device, nxtShaderStage stage, const char* source);
|
nxtShaderModule CreateShaderModule(nxtDevice device, nxtShaderStage stage, const char* source);
|
||||||
nxtBuffer CreateFrozenBufferFromData(nxtDevice device, void* data, uint32_t size, nxtBufferUsageBit usage);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -29,16 +29,14 @@ namespace backend {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DepthStencilStateBase::StencilTestEnabled() const {
|
bool DepthStencilStateBase::StencilTestEnabled() const {
|
||||||
return (
|
return stencilInfo.back.compareFunction != nxt::CompareFunction::Always ||
|
||||||
stencilInfo.back.compareFunction != nxt::CompareFunction::Always ||
|
|
||||||
stencilInfo.back.stencilFail != nxt::StencilOperation::Keep ||
|
stencilInfo.back.stencilFail != nxt::StencilOperation::Keep ||
|
||||||
stencilInfo.back.depthFail != nxt::StencilOperation::Keep ||
|
stencilInfo.back.depthFail != nxt::StencilOperation::Keep ||
|
||||||
stencilInfo.back.depthStencilPass != nxt::StencilOperation::Keep ||
|
stencilInfo.back.depthStencilPass != nxt::StencilOperation::Keep ||
|
||||||
stencilInfo.front.compareFunction != nxt::CompareFunction::Always ||
|
stencilInfo.front.compareFunction != nxt::CompareFunction::Always ||
|
||||||
stencilInfo.front.stencilFail != nxt::StencilOperation::Keep ||
|
stencilInfo.front.stencilFail != nxt::StencilOperation::Keep ||
|
||||||
stencilInfo.front.depthFail != nxt::StencilOperation::Keep ||
|
stencilInfo.front.depthFail != nxt::StencilOperation::Keep ||
|
||||||
stencilInfo.front.depthStencilPass != nxt::StencilOperation::Keep
|
stencilInfo.front.depthStencilPass != nxt::StencilOperation::Keep;
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const DepthStencilStateBase::DepthInfo& DepthStencilStateBase::GetDepth() const {
|
const DepthStencilStateBase::DepthInfo& DepthStencilStateBase::GetDepth() const {
|
||||||
|
|
|
@ -185,7 +185,6 @@ namespace opengl {
|
||||||
case Command::SetStencilReference:
|
case Command::SetStencilReference:
|
||||||
{
|
{
|
||||||
SetStencilReferenceCmd* cmd = commands.NextCommand<SetStencilReferenceCmd>();
|
SetStencilReferenceCmd* cmd = commands.NextCommand<SetStencilReferenceCmd>();
|
||||||
// DepthStencilState* depthStencilState = ToBackend(lastPipeline->GetDepthStencilState());
|
|
||||||
persistentPipelineState.SetStencilReference(cmd->reference);
|
persistentPipelineState.SetStencilReference(cmd->reference);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -95,32 +95,20 @@ namespace opengl {
|
||||||
|
|
||||||
GLenum backCompareFunction = OpenGLCompareFunction(stencilInfo.back.compareFunction);
|
GLenum backCompareFunction = OpenGLCompareFunction(stencilInfo.back.compareFunction);
|
||||||
GLenum frontCompareFunction = OpenGLCompareFunction(stencilInfo.front.compareFunction);
|
GLenum frontCompareFunction = OpenGLCompareFunction(stencilInfo.front.compareFunction);
|
||||||
|
persistentPipelineState.SetStencilFuncsAndMask(backCompareFunction, frontCompareFunction, stencilInfo.readMask);
|
||||||
persistentPipelineState.CacheStencilFuncsAndMask(backCompareFunction, frontCompareFunction, stencilInfo.readMask);
|
|
||||||
|
|
||||||
glStencilOpSeparate(GL_BACK,
|
glStencilOpSeparate(GL_BACK,
|
||||||
OpenGLStencilOperation(stencilInfo.back.stencilFail),
|
OpenGLStencilOperation(stencilInfo.back.stencilFail),
|
||||||
OpenGLStencilOperation(stencilInfo.back.depthFail),
|
OpenGLStencilOperation(stencilInfo.back.depthFail),
|
||||||
OpenGLStencilOperation(stencilInfo.back.depthStencilPass)
|
OpenGLStencilOperation(stencilInfo.back.depthStencilPass)
|
||||||
);
|
);
|
||||||
glStencilFuncSeparate(GL_BACK,
|
|
||||||
backCompareFunction,
|
|
||||||
persistentPipelineState.GetCachedStencilReference(),
|
|
||||||
stencilInfo.readMask
|
|
||||||
);
|
|
||||||
glStencilMaskSeparate(GL_BACK, stencilInfo.writeMask);
|
|
||||||
|
|
||||||
glStencilOpSeparate(GL_FRONT,
|
glStencilOpSeparate(GL_FRONT,
|
||||||
OpenGLStencilOperation(stencilInfo.front.stencilFail),
|
OpenGLStencilOperation(stencilInfo.front.stencilFail),
|
||||||
OpenGLStencilOperation(stencilInfo.front.depthFail),
|
OpenGLStencilOperation(stencilInfo.front.depthFail),
|
||||||
OpenGLStencilOperation(stencilInfo.front.depthStencilPass)
|
OpenGLStencilOperation(stencilInfo.front.depthStencilPass)
|
||||||
);
|
);
|
||||||
glStencilFuncSeparate(GL_FRONT,
|
|
||||||
frontCompareFunction,
|
glStencilMask(stencilInfo.writeMask);
|
||||||
persistentPipelineState.GetCachedStencilReference(),
|
|
||||||
stencilInfo.readMask
|
|
||||||
);
|
|
||||||
glStencilMaskSeparate(GL_FRONT, stencilInfo.writeMask);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,36 +20,40 @@ namespace backend {
|
||||||
namespace opengl {
|
namespace opengl {
|
||||||
|
|
||||||
void PersistentPipelineState::SetDefaultState() {
|
void PersistentPipelineState::SetDefaultState() {
|
||||||
stencilBackCompareFunction = GL_ALWAYS;
|
CallGLStencilFunc();
|
||||||
stencilFrontCompareFunction = GL_ALWAYS;
|
|
||||||
stencilReadMask = 0xff;
|
|
||||||
SetStencilReference(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PersistentPipelineState::CacheStencilFuncsAndMask(GLenum stencilBackCompareFunction, GLenum stencilFrontCompareFunction, uint32_t stencilReadMask) {
|
void PersistentPipelineState::SetStencilFuncsAndMask(GLenum stencilBackCompareFunction, GLenum stencilFrontCompareFunction, uint32_t stencilReadMask) {
|
||||||
|
if (this->stencilBackCompareFunction == stencilBackCompareFunction &&
|
||||||
|
this->stencilFrontCompareFunction == stencilFrontCompareFunction &&
|
||||||
|
this->stencilReadMask == stencilReadMask) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this->stencilBackCompareFunction = stencilBackCompareFunction;
|
this->stencilBackCompareFunction = stencilBackCompareFunction;
|
||||||
this->stencilFrontCompareFunction = stencilFrontCompareFunction;
|
this->stencilFrontCompareFunction = stencilFrontCompareFunction;
|
||||||
this->stencilReadMask = stencilReadMask;
|
this->stencilReadMask = stencilReadMask;
|
||||||
|
CallGLStencilFunc();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PersistentPipelineState::SetStencilReference(uint32_t stencilReference) {
|
void PersistentPipelineState::SetStencilReference(uint32_t stencilReference) {
|
||||||
if (this->stencilReference != stencilReference) {
|
if (this->stencilReference == stencilReference) {
|
||||||
this->stencilReference = stencilReference;
|
return;
|
||||||
glStencilFuncSeparate(GL_BACK,
|
}
|
||||||
|
|
||||||
|
this->stencilReference = stencilReference;
|
||||||
|
CallGLStencilFunc();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PersistentPipelineState::CallGLStencilFunc() {
|
||||||
|
glStencilFuncSeparate(GL_BACK,
|
||||||
stencilBackCompareFunction,
|
stencilBackCompareFunction,
|
||||||
stencilReference,
|
stencilReference,
|
||||||
stencilReadMask
|
stencilReadMask);
|
||||||
);
|
glStencilFuncSeparate(GL_FRONT,
|
||||||
glStencilFuncSeparate(GL_FRONT,
|
|
||||||
stencilFrontCompareFunction,
|
stencilFrontCompareFunction,
|
||||||
stencilReference,
|
stencilReference,
|
||||||
stencilReadMask
|
stencilReadMask);
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
GLuint PersistentPipelineState::GetCachedStencilReference() const {
|
|
||||||
return stencilReference;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,16 @@ namespace opengl {
|
||||||
class PersistentPipelineState {
|
class PersistentPipelineState {
|
||||||
public:
|
public:
|
||||||
void SetDefaultState();
|
void SetDefaultState();
|
||||||
void CacheStencilFuncsAndMask(GLenum stencilBackCompareFunction, GLenum stencilFrontCompareFunction, uint32_t stencilReadMask);
|
void SetStencilFuncsAndMask(GLenum stencilBackCompareFunction, GLenum stencilFrontCompareFunction, uint32_t stencilReadMask);
|
||||||
void SetStencilReference(uint32_t stencilReference);
|
void SetStencilReference(uint32_t stencilReference);
|
||||||
GLuint GetCachedStencilReference() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GLenum stencilBackCompareFunction;
|
void CallGLStencilFunc();
|
||||||
GLenum stencilFrontCompareFunction;
|
|
||||||
GLuint stencilReadMask;
|
GLenum stencilBackCompareFunction = GL_ALWAYS;
|
||||||
GLuint stencilReference;
|
GLenum stencilFrontCompareFunction = GL_ALWAYS;
|
||||||
|
GLuint stencilReadMask = 0xffffffff;
|
||||||
|
GLuint stencilReference = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue