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, 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] = {
|
||||
-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
|
||||
};
|
||||
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] = {
|
||||
-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,
|
||||
};
|
||||
planeBuffer = CreateFrozenBufferFromData(device, (void*)planeData, sizeof(planeData), nxt::BufferUsageBit::Vertex);
|
||||
planeBuffer = CreateFrozenBufferFromData(device, planeData, sizeof(planeData), nxt::BufferUsageBit::Vertex);
|
||||
}
|
||||
|
||||
struct CameraData {
|
||||
|
@ -171,10 +171,10 @@ void init() {
|
|||
.GetResult();
|
||||
|
||||
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));
|
||||
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()
|
||||
.SetExtent(0, sizeof(CameraData))
|
||||
|
|
|
@ -245,7 +245,7 @@ void CreateDefaultRenderPass(const nxt::Device& device, nxt::RenderPass* renderP
|
|||
.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()
|
||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | usage)
|
||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
||||
|
@ -307,10 +307,6 @@ extern "C" {
|
|||
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() {
|
||||
if (cmdBufType == CmdBufType::Terrible) {
|
||||
c2sBuf->Flush();
|
||||
|
|
|
@ -34,9 +34,8 @@ extern "C" {
|
|||
nxt::Device CreateCppNXTDevice();
|
||||
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);
|
||||
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
|
||||
nxtDevice CreateNXTDevice();
|
||||
nxtShaderModule CreateShaderModule(nxtDevice device, nxtShaderStage stage, const char* source);
|
||||
nxtBuffer CreateFrozenBufferFromData(nxtDevice device, void* data, uint32_t size, nxtBufferUsageBit usage);
|
||||
#endif
|
||||
|
|
|
@ -29,16 +29,14 @@ namespace backend {
|
|||
}
|
||||
|
||||
bool DepthStencilStateBase::StencilTestEnabled() const {
|
||||
return (
|
||||
stencilInfo.back.compareFunction != nxt::CompareFunction::Always ||
|
||||
return stencilInfo.back.compareFunction != nxt::CompareFunction::Always ||
|
||||
stencilInfo.back.stencilFail != nxt::StencilOperation::Keep ||
|
||||
stencilInfo.back.depthFail != nxt::StencilOperation::Keep ||
|
||||
stencilInfo.back.depthStencilPass != nxt::StencilOperation::Keep ||
|
||||
stencilInfo.front.compareFunction != nxt::CompareFunction::Always ||
|
||||
stencilInfo.front.stencilFail != 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 {
|
||||
|
|
|
@ -185,7 +185,6 @@ namespace opengl {
|
|||
case Command::SetStencilReference:
|
||||
{
|
||||
SetStencilReferenceCmd* cmd = commands.NextCommand<SetStencilReferenceCmd>();
|
||||
// DepthStencilState* depthStencilState = ToBackend(lastPipeline->GetDepthStencilState());
|
||||
persistentPipelineState.SetStencilReference(cmd->reference);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -95,32 +95,20 @@ namespace opengl {
|
|||
|
||||
GLenum backCompareFunction = OpenGLCompareFunction(stencilInfo.back.compareFunction);
|
||||
GLenum frontCompareFunction = OpenGLCompareFunction(stencilInfo.front.compareFunction);
|
||||
|
||||
persistentPipelineState.CacheStencilFuncsAndMask(backCompareFunction, frontCompareFunction, stencilInfo.readMask);
|
||||
persistentPipelineState.SetStencilFuncsAndMask(backCompareFunction, frontCompareFunction, stencilInfo.readMask);
|
||||
|
||||
glStencilOpSeparate(GL_BACK,
|
||||
OpenGLStencilOperation(stencilInfo.back.stencilFail),
|
||||
OpenGLStencilOperation(stencilInfo.back.depthFail),
|
||||
OpenGLStencilOperation(stencilInfo.back.depthStencilPass)
|
||||
);
|
||||
glStencilFuncSeparate(GL_BACK,
|
||||
backCompareFunction,
|
||||
persistentPipelineState.GetCachedStencilReference(),
|
||||
stencilInfo.readMask
|
||||
);
|
||||
glStencilMaskSeparate(GL_BACK, stencilInfo.writeMask);
|
||||
|
||||
glStencilOpSeparate(GL_FRONT,
|
||||
OpenGLStencilOperation(stencilInfo.front.stencilFail),
|
||||
OpenGLStencilOperation(stencilInfo.front.depthFail),
|
||||
OpenGLStencilOperation(stencilInfo.front.depthStencilPass)
|
||||
);
|
||||
glStencilFuncSeparate(GL_FRONT,
|
||||
frontCompareFunction,
|
||||
persistentPipelineState.GetCachedStencilReference(),
|
||||
stencilInfo.readMask
|
||||
);
|
||||
glStencilMaskSeparate(GL_FRONT, stencilInfo.writeMask);
|
||||
|
||||
glStencilMask(stencilInfo.writeMask);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -20,36 +20,40 @@ namespace backend {
|
|||
namespace opengl {
|
||||
|
||||
void PersistentPipelineState::SetDefaultState() {
|
||||
stencilBackCompareFunction = GL_ALWAYS;
|
||||
stencilFrontCompareFunction = GL_ALWAYS;
|
||||
stencilReadMask = 0xff;
|
||||
SetStencilReference(0);
|
||||
CallGLStencilFunc();
|
||||
}
|
||||
|
||||
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->stencilFrontCompareFunction = stencilFrontCompareFunction;
|
||||
this->stencilReadMask = stencilReadMask;
|
||||
CallGLStencilFunc();
|
||||
}
|
||||
|
||||
void PersistentPipelineState::SetStencilReference(uint32_t stencilReference) {
|
||||
if (this->stencilReference != stencilReference) {
|
||||
this->stencilReference = stencilReference;
|
||||
glStencilFuncSeparate(GL_BACK,
|
||||
if (this->stencilReference == stencilReference) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->stencilReference = stencilReference;
|
||||
CallGLStencilFunc();
|
||||
}
|
||||
|
||||
void PersistentPipelineState::CallGLStencilFunc() {
|
||||
glStencilFuncSeparate(GL_BACK,
|
||||
stencilBackCompareFunction,
|
||||
stencilReference,
|
||||
stencilReadMask
|
||||
);
|
||||
glStencilFuncSeparate(GL_FRONT,
|
||||
stencilReadMask);
|
||||
glStencilFuncSeparate(GL_FRONT,
|
||||
stencilFrontCompareFunction,
|
||||
stencilReference,
|
||||
stencilReadMask
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
GLuint PersistentPipelineState::GetCachedStencilReference() const {
|
||||
return stencilReference;
|
||||
stencilReadMask);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,15 +25,16 @@ namespace opengl {
|
|||
class PersistentPipelineState {
|
||||
public:
|
||||
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);
|
||||
GLuint GetCachedStencilReference() const;
|
||||
|
||||
private:
|
||||
GLenum stencilBackCompareFunction;
|
||||
GLenum stencilFrontCompareFunction;
|
||||
GLuint stencilReadMask;
|
||||
GLuint stencilReference;
|
||||
void CallGLStencilFunc();
|
||||
|
||||
GLenum stencilBackCompareFunction = GL_ALWAYS;
|
||||
GLenum stencilFrontCompareFunction = GL_ALWAYS;
|
||||
GLuint stencilReadMask = 0xffffffff;
|
||||
GLuint stencilReference = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue