fix reverseCW issue (#3433)

This commit is contained in:
Yun Hsiao Wu
2021-04-20 12:38:19 +08:00
committed by GitHub
parent 6a3ef36ae2
commit 3940e643af
7 changed files with 29 additions and 37 deletions
@@ -419,7 +419,7 @@ enum class MemoryUsageBit : FlagBits {
HOST = 0x2,
};
using MemoryUsage = MemoryUsageBit;
CC_ENUM_OPERATORS(MemoryUsageBit)
CC_ENUM_OPERATORS(MemoryUsageBit);
enum class TextureType {
TEX1D,
@@ -441,7 +441,7 @@ enum class TextureUsageBit : FlagBits {
INPUT_ATTACHMENT = 0x40,
};
using TextureUsage = TextureUsageBit;
CC_ENUM_OPERATORS(TextureUsageBit)
CC_ENUM_OPERATORS(TextureUsageBit);
enum class TextureFlagBit : FlagBits {
NONE = 0,
@@ -449,7 +449,7 @@ enum class TextureFlagBit : FlagBits {
IMMUTABLE = 0x2,
};
using TextureFlags = TextureFlagBit;
CC_ENUM_OPERATORS(TextureFlagBit)
CC_ENUM_OPERATORS(TextureFlagBit);
enum class SampleCount {
X1,
@@ -531,7 +531,7 @@ enum class ColorMask : FlagBits {
A = 0x8,
ALL = R | G | B | A,
};
CC_ENUM_OPERATORS(ColorMask)
CC_ENUM_OPERATORS(ColorMask);
enum class ShaderStageFlagBit : FlagBits {
NONE = 0x0,
@@ -544,7 +544,7 @@ enum class ShaderStageFlagBit : FlagBits {
ALL = 0x3f,
};
using ShaderStageFlags = ShaderStageFlagBit;
CC_ENUM_OPERATORS(ShaderStageFlagBit)
CC_ENUM_OPERATORS(ShaderStageFlagBit);
enum class LoadOp {
LOAD, // Load the contents from the fbo from previous
@@ -647,7 +647,7 @@ enum class DynamicStateFlagBit : FlagBits {
STENCIL_COMPARE_MASK = 0x80,
};
using DynamicStateFlags = DynamicStateFlagBit;
CC_ENUM_OPERATORS(DynamicStateFlagBit)
CC_ENUM_OPERATORS(DynamicStateFlagBit);
using DynamicStateList = vector<DynamicStateFlagBit>;
@@ -669,7 +669,7 @@ enum class DescriptorType : FlagBits {
STORAGE_IMAGE = 0x80,
INPUT_ATTACHMENT = 0x100,
};
CC_ENUM_OPERATORS(DescriptorType)
CC_ENUM_OPERATORS(DescriptorType);
enum class QueueType {
GRAPHICS,
@@ -691,7 +691,7 @@ enum class ClearFlagBit : FlagBits {
ALL = COLOR | DEPTH | STENCIL,
};
using ClearFlags = ClearFlagBit;
CC_ENUM_OPERATORS(ClearFlagBit)
CC_ENUM_OPERATORS(ClearFlagBit);
struct Size {
uint x = 0U;
@@ -1354,8 +1354,6 @@ void cmdFuncGLES2BeginRenderPass(GLES2Device *device, GLES2GPURenderPass *gpuRen
if (cache->glFramebuffer != gpuFramebuffer->glFramebuffer) {
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, gpuFramebuffer->glFramebuffer));
cache->glFramebuffer = gpuFramebuffer->glFramebuffer;
// render targets are drawn with flipped-Y
gfxStateCache.reverseCW = !!gpuFramebuffer->glFramebuffer;
}
if (cache->viewport.left != renderArea.x ||
@@ -1609,10 +1607,9 @@ void cmdFuncGLES2BindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli
}
cache->rs.cullMode = gpuPipelineState->rs.cullMode;
}
bool isFrontFaceCCW = static_cast<bool>(gpuPipelineState->rs.isFrontFaceCCW) != gfxStateCache.reverseCW;
if (static_cast<bool>(cache->rs.isFrontFaceCCW) != isFrontFaceCCW) {
GL_CHECK(glFrontFace(isFrontFaceCCW ? GL_CCW : GL_CW));
cache->rs.isFrontFaceCCW = isFrontFaceCCW;
if (cache->rs.isFrontFaceCCW != gpuPipelineState->rs.isFrontFaceCCW) {
GL_CHECK(glFrontFace(gpuPipelineState->rs.isFrontFaceCCW ? GL_CCW : GL_CW));
cache->rs.isFrontFaceCCW = gpuPipelineState->rs.isFrontFaceCCW;
}
if ((cache->rs.depthBias != gpuPipelineState->rs.depthBias) ||
(cache->rs.depthBiasSlop != gpuPipelineState->rs.depthBiasSlop)) {
@@ -125,6 +125,7 @@ bool GLES2Device::doInit(const DeviceInfo & info) {
if (checkExtension("draw_buffers")) {
_features[static_cast<uint>(Feature::MULTIPLE_RENDER_TARGETS)] = true;
glGetIntegerv(GL_MAX_DRAW_BUFFERS_EXT, reinterpret_cast<GLint *>(&_caps.maxColorRenderTargets));
}
if (checkExtension("blend_minmax")) {
@@ -198,13 +199,13 @@ bool GLES2Device::doInit(const DeviceInfo & info) {
}
void GLES2Device::doDestroy() {
CC_SAFE_DELETE(_gpuStagingBufferPool);
CC_SAFE_DELETE(_gpuStateCache);
CC_SAFE_DELETE(_gpuStagingBufferPool)
CC_SAFE_DELETE(_gpuStateCache)
CC_SAFE_DESTROY(_cmdBuff);
CC_SAFE_DESTROY(_queue);
CC_SAFE_DESTROY(_deviceContext);
CC_SAFE_DESTROY(_renderContext);
CC_SAFE_DESTROY(_cmdBuff)
CC_SAFE_DESTROY(_queue)
CC_SAFE_DESTROY(_deviceContext)
CC_SAFE_DESTROY(_renderContext)
}
void GLES2Device::releaseSurface(uintptr_t windowHandle) {
@@ -300,7 +300,6 @@ struct GLES2ObjectCache final {
GLES2GPUFramebuffer * gpuFramebuffer = nullptr;
GLES2GPUPipelineState * gpuPipelineState = nullptr;
GLES2GPUInputAssembler *gpuInputAssembler = nullptr;
bool reverseCW = false;
GLenum glPrimitive = 0;
GLenum invalidAttachments[MAX_ATTACHMENTS];
};
@@ -361,7 +360,6 @@ public:
gfxStateCache.gpuFramebuffer = nullptr;
gfxStateCache.gpuInputAssembler = nullptr;
gfxStateCache.glPrimitive = 0U;
gfxStateCache.reverseCW = false;
}
};
@@ -1524,8 +1524,6 @@ void cmdFuncGLES3BeginRenderPass(GLES3Device *device, GLES3GPURenderPass *gpuRen
if (cache->glDrawFramebuffer != gpuFramebuffer->glFramebuffer) {
GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, gpuFramebuffer->glFramebuffer));
cache->glDrawFramebuffer = gpuFramebuffer->glFramebuffer;
// render targets are drawn with flipped-Y
gfxStateCache.reverseCW = gpuFramebuffer->isOffscreen;
}
if (cache->viewport.left != renderArea.x ||
@@ -1779,10 +1777,9 @@ void cmdFuncGLES3BindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli
}
cache->rs.cullMode = gpuPipelineState->rs.cullMode;
}
bool isFrontFaceCCW = gpuPipelineState->rs.isFrontFaceCCW != gfxStateCache.reverseCW;
if (static_cast<bool>(cache->rs.isFrontFaceCCW) != isFrontFaceCCW) {
GL_CHECK(glFrontFace(isFrontFaceCCW ? GL_CCW : GL_CW));
cache->rs.isFrontFaceCCW = isFrontFaceCCW;
if (cache->rs.isFrontFaceCCW != gpuPipelineState->rs.isFrontFaceCCW) {
GL_CHECK(glFrontFace(gpuPipelineState->rs.isFrontFaceCCW ? GL_CCW : GL_CW));
cache->rs.isFrontFaceCCW = gpuPipelineState->rs.isFrontFaceCCW;
}
if ((cache->rs.depthBias != gpuPipelineState->rs.depthBias) ||
(cache->rs.depthBiasSlop != gpuPipelineState->rs.depthBiasSlop)) {
@@ -171,6 +171,7 @@ bool GLES3Device::doInit(const DeviceInfo & info) {
glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, reinterpret_cast<GLint *>(&_caps.maxFragmentUniformVectors));
glGetIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, reinterpret_cast<GLint *>(&_caps.maxUniformBufferBindings));
glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, reinterpret_cast<GLint *>(&_caps.maxUniformBlockSize));
glGetIntegerv(GL_MAX_DRAW_BUFFERS, reinterpret_cast<GLint *>(&_caps.maxColorRenderTargets));
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, reinterpret_cast<GLint *>(&_caps.maxTextureUnits));
glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, reinterpret_cast<GLint *>(&_caps.maxVertexTextureUnits));
glGetIntegerv(GL_MAX_TEXTURE_SIZE, reinterpret_cast<GLint *>(&_caps.maxTextureSize));
@@ -199,14 +200,14 @@ bool GLES3Device::doInit(const DeviceInfo & info) {
}
void GLES3Device::doDestroy() {
CC_SAFE_DELETE(_gpuFramebufferCacheMap);
CC_SAFE_DELETE(_gpuStagingBufferPool);
CC_SAFE_DELETE(_gpuStateCache);
CC_SAFE_DELETE(_gpuFramebufferCacheMap)
CC_SAFE_DELETE(_gpuStagingBufferPool)
CC_SAFE_DELETE(_gpuStateCache)
CC_SAFE_DESTROY(_cmdBuff);
CC_SAFE_DESTROY(_queue);
CC_SAFE_DESTROY(_deviceContext);
CC_SAFE_DESTROY(_renderContext);
CC_SAFE_DESTROY(_cmdBuff)
CC_SAFE_DESTROY(_queue)
CC_SAFE_DESTROY(_deviceContext)
CC_SAFE_DESTROY(_renderContext)
}
void GLES3Device::releaseSurface(const uintptr_t windowHandle) {
@@ -297,7 +297,6 @@ struct GLES3ObjectCache final {
GLES3GPUFramebuffer * gpuFramebuffer = nullptr;
GLES3GPUPipelineState * gpuPipelineState = nullptr;
GLES3GPUInputAssembler *gpuInputAssembler = nullptr;
uint reverseCW = 0U;
GLenum glPrimitive = 0;
GLenum invalidAttachments[MAX_ATTACHMENTS];
};
@@ -380,7 +379,6 @@ public:
gfxStateCache.gpuPipelineState = nullptr;
gfxStateCache.gpuInputAssembler = nullptr;
gfxStateCache.glPrimitive = 0U;
gfxStateCache.reverseCW = false;
}
};