fix scissor update strat (#3995)

This commit is contained in:
Yun Hsiao Wu
2021-10-20 11:13:16 +08:00
committed by GitHub
parent 859974a4ca
commit e55ab9be46
6 changed files with 104 additions and 37 deletions
@@ -1282,20 +1282,20 @@ void cmdFuncGLES2DestroyInputAssembler(GLES2Device *device, GLES2GPUInputAssembl
gpuInputAssembler->glVAOs.clear();
}
static GLuint doCreateFramebuffer(GLES2Device * device,
static GLES2GPUFramebuffer::GLFramebufferInfo doCreateFramebuffer(GLES2Device * device,
const vector<GLES2GPUTexture *> &attachments, const uint32_t *colors, size_t colorCount,
const GLES2GPUTexture *depthStencil,
const uint32_t * resolves = nullptr,
const GLES2GPUTexture *depthStencilResolve = nullptr,
GLbitfield * resolveMask = nullptr) {
static vector<GLenum> drawBuffers;
GLuint glFramebuffer{0U};
GLES2GPUStateCache * cache = device->stateCache();
GLES2GPUFramebuffer::GLFramebufferInfo res;
GL_CHECK(glGenFramebuffers(1, &glFramebuffer));
if (cache->glFramebuffer != glFramebuffer) {
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, glFramebuffer));
cache->glFramebuffer = glFramebuffer;
GL_CHECK(glGenFramebuffers(1, &res.glFramebuffer));
if (cache->glFramebuffer != res.glFramebuffer) {
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, res.glFramebuffer));
cache->glFramebuffer = res.glFramebuffer;
}
drawBuffers.clear();
@@ -1324,6 +1324,8 @@ static GLuint doCreateFramebuffer(GLES2Device * device,
GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + j),
gpuColorTexture->glTarget, gpuColorTexture->glRenderbuffer));
}
res.width = std::min(res.width, gpuColorTexture->width);
res.height = std::min(res.height, gpuColorTexture->height);
}
if (depthStencil) {
bool hasStencil = GFX_FORMAT_INFOS[static_cast<int>(depthStencil->format)].hasStencil;
@@ -1337,11 +1339,13 @@ static GLuint doCreateFramebuffer(GLES2Device * device,
// fallback to blit-based manual resolve
if (depthStencilResolve) *resolveMask |= hasStencil ? GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT : GL_DEPTH_BUFFER_BIT;
res.width = std::min(res.width, depthStencil->width);
res.height = std::min(res.height, depthStencil->height);
}
// register to framebuffer caches
if (colorCount == 1) device->framebufferCacheMap()->registerExternal(glFramebuffer, attachments[colors[0]]);
if (depthStencil) device->framebufferCacheMap()->registerExternal(glFramebuffer, depthStencil);
if (colorCount == 1) device->framebufferCacheMap()->registerExternal(res.glFramebuffer, attachments[colors[0]]);
if (depthStencil) device->framebufferCacheMap()->registerExternal(res.glFramebuffer, depthStencil);
if (device->hasFeature(Feature::MULTIPLE_RENDER_TARGETS)) {
GL_CHECK(glDrawBuffersEXT(utils::toUint(drawBuffers.size()), drawBuffers.data()));
@@ -1369,7 +1373,7 @@ static GLuint doCreateFramebuffer(GLES2Device * device,
}
}
return glFramebuffer;
return res;
}
static GLES2GPUSwapchain *getSwapchainIfExists(const vector<GLES2GPUTexture *> &textures, const uint32_t *indices, size_t count) {
@@ -1534,6 +1538,19 @@ void cmdFuncGLES2BeginRenderPass(GLES2Device *device, uint32_t subpassIdx, GLES2
cache->viewport.width = renderArea->width;
cache->viewport.height = renderArea->height;
}
uint32_t fboWidth = instance.framebuffer.getWidth();
uint32_t fboHeight = instance.framebuffer.getHeight();
if (cache->scissor.x != 0 ||
cache->scissor.y != 0 ||
cache->scissor.width != fboWidth ||
cache->scissor.height != fboHeight) {
GL_CHECK(glScissor(0, 0, fboWidth, fboHeight));
cache->scissor.x = 0;
cache->scissor.y = 0;
cache->scissor.width = fboWidth;
cache->scissor.height = fboHeight;
}
}
GLbitfield glClears = 0;
@@ -92,13 +92,6 @@ private:
StringArray _extensions;
};
class GLES2GPUSwapchain final : public Object {
public:
EGLSurface eglSurface{EGL_NO_SURFACE};
EGLint eglSwapInterval{0};
GLuint glFramebuffer{0};
};
class GLES2GPUBuffer final : public Object {
public:
BufferUsage usage = BufferUsage::NONE;
@@ -152,6 +145,14 @@ public:
using GLES2GPUTextureList = vector<GLES2GPUTexture *>;
class GLES2GPUSwapchain final : public Object {
public:
EGLSurface eglSurface{EGL_NO_SURFACE};
EGLint eglSwapInterval{0};
GLuint glFramebuffer{0};
GLES2GPUTexture *gpuColorTexture{nullptr};
};
class GLES2GPUSampler final : public Object {
public:
Filter minFilter = Filter::NONE;
@@ -285,17 +286,31 @@ public:
GLES2GPUTexture * gpuDepthStencilTexture{nullptr};
bool usesFBF{false};
struct GLFramebufferInfo {
GLuint glFramebuffer{0U};
uint32_t width{UINT_MAX};
uint32_t height{UINT_MAX};
};
struct GLFramebuffer {
inline void initialize(GLES2GPUSwapchain *sc) { swapchain = sc; }
inline void initialize(GLuint framebuffer) { _glFramebuffer = framebuffer; }
inline GLuint getFramebuffer() const { return swapchain ? swapchain->glFramebuffer : _glFramebuffer; }
inline void initialize(GLES2GPUSwapchain *sc) { swapchain = sc; }
inline void initialize(const GLFramebufferInfo &info) {
_glFramebuffer = info.glFramebuffer;
_width = info.width;
_height = info.height;
}
inline GLuint getFramebuffer() const { return swapchain ? swapchain->glFramebuffer : _glFramebuffer; }
inline uint32_t getWidth() const { return swapchain ? swapchain->gpuColorTexture->width : _width; }
inline uint32_t getHeight() const { return swapchain ? swapchain->gpuColorTexture->height : _height; }
void destroy(GLES2GPUStateCache *cache, GLES2GPUFramebufferCacheMap *framebufferCacheMap);
GLES2GPUSwapchain *swapchain{nullptr};
private:
GLuint _glFramebuffer{0U};
GLuint _glFramebuffer{0U};
uint32_t _width{0U};
uint32_t _height{0U};
};
struct Framebuffer {
@@ -98,6 +98,8 @@ void GLES2Swapchain::doInit(const SwapchainInfo& info) {
textureInfo.format = Format::DEPTH_STENCIL;
initTexture(textureInfo, _depthStencilTexture);
_gpuSwapchain->gpuColorTexture = static_cast<GLES2Texture*>(_colorTexture)->gpuTexture();
}
void GLES2Swapchain::doDestroy() {
@@ -1478,20 +1478,20 @@ void cmdFuncGLES3DestroyInputAssembler(GLES3Device *device, GLES3GPUInputAssembl
gpuInputAssembler->glVAOs.clear();
}
static GLuint doCreateFramebuffer(GLES3Device * device,
static GLES3GPUFramebuffer::GLFramebufferInfo doCreateFramebuffer(GLES3Device * device,
const vector<GLES3GPUTexture *> &attachments, const uint32_t *colors, size_t colorCount,
const GLES3GPUTexture *depthStencil,
const uint32_t * resolves = nullptr,
const GLES3GPUTexture *depthStencilResolve = nullptr,
GLbitfield * resolveMask = nullptr) {
static vector<GLenum> drawBuffers;
GLuint glFramebuffer{0U};
GLES3GPUStateCache * cache = device->stateCache();
GLES3GPUFramebuffer::GLFramebufferInfo res;
GL_CHECK(glGenFramebuffers(1, &glFramebuffer));
if (cache->glDrawFramebuffer != glFramebuffer) {
GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, glFramebuffer));
cache->glDrawFramebuffer = glFramebuffer;
GL_CHECK(glGenFramebuffers(1, &res.glFramebuffer));
if (cache->glDrawFramebuffer != res.glFramebuffer) {
GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, res.glFramebuffer));
cache->glDrawFramebuffer = res.glFramebuffer;
}
drawBuffers.clear();
@@ -1520,6 +1520,8 @@ static GLuint doCreateFramebuffer(GLES3Device * device,
GL_CHECK(glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + j),
gpuColorTexture->glTarget, gpuColorTexture->glRenderbuffer));
}
res.width = std::min(res.width, gpuColorTexture->width);
res.height = std::min(res.height, gpuColorTexture->height);
}
if (depthStencil) {
bool hasStencil = GFX_FORMAT_INFOS[static_cast<int>(depthStencil->format)].hasStencil;
@@ -1532,11 +1534,13 @@ static GLuint doCreateFramebuffer(GLES3Device * device,
// fallback to blit-based manual resolve
if (depthStencilResolve) *resolveMask |= hasStencil ? GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT : GL_DEPTH_BUFFER_BIT;
res.width = std::min(res.width, depthStencil->width);
res.height = std::min(res.height, depthStencil->height);
}
// register to framebuffer caches
if (colorCount == 1) device->framebufferCacheMap()->registerExternal(glFramebuffer, attachments[colors[0]], 0);
if (depthStencil) device->framebufferCacheMap()->registerExternal(glFramebuffer, depthStencil, 0);
if (colorCount == 1) device->framebufferCacheMap()->registerExternal(res.glFramebuffer, attachments[colors[0]], 0);
if (depthStencil) device->framebufferCacheMap()->registerExternal(res.glFramebuffer, depthStencil, 0);
GL_CHECK(glDrawBuffers(utils::toUint(drawBuffers.size()), drawBuffers.data()));
@@ -1565,7 +1569,7 @@ static GLuint doCreateFramebuffer(GLES3Device * device,
}
}
return glFramebuffer;
return res;
}
static GLES3GPUSwapchain *getSwapchainIfExists(const vector<GLES3GPUTexture *> &textures, const uint32_t *indices, size_t count) {
@@ -1884,6 +1888,19 @@ void cmdFuncGLES3BeginRenderPass(GLES3Device *device, uint32_t subpassIdx, GLES3
cache->viewport.width = renderArea->width;
cache->viewport.height = renderArea->height;
}
uint32_t fboWidth = instance.framebuffer.getWidth();
uint32_t fboHeight = instance.framebuffer.getHeight();
if (cache->scissor.x != 0 ||
cache->scissor.y != 0 ||
cache->scissor.width != fboWidth ||
cache->scissor.height != fboHeight) {
GL_CHECK(glScissor(0, 0, fboWidth, fboHeight));
cache->scissor.x = 0;
cache->scissor.y = 0;
cache->scissor.width = fboWidth;
cache->scissor.height = fboHeight;
}
}
GLbitfield glClears = 0;
@@ -90,13 +90,6 @@ private:
StringArray _extensions;
};
class GLES3GPUSwapchain final : public Object {
public:
EGLSurface eglSurface{EGL_NO_SURFACE};
EGLint eglSwapInterval{0};
GLuint glFramebuffer{0};
};
class GLES3GPUQueryPool final : public Object {
public:
QueryType type{QueryType::OCCLUSION};
@@ -159,6 +152,14 @@ public:
using GLES3GPUTextureList = vector<GLES3GPUTexture *>;
class GLES3GPUSwapchain final : public Object {
public:
EGLSurface eglSurface{EGL_NO_SURFACE};
EGLint eglSwapInterval{0};
GLuint glFramebuffer{0};
GLES3GPUTexture *gpuColorTexture{nullptr};
};
class GLES3GPUSampler final : public Object {
public:
Filter minFilter = Filter::NONE;
@@ -328,10 +329,21 @@ public:
GLES3GPUTexture * gpuDepthStencilTexture{nullptr};
bool usesFBF{false};
struct GLFramebufferInfo {
GLuint glFramebuffer{0U};
uint32_t width{UINT_MAX};
uint32_t height{UINT_MAX};
};
struct GLFramebuffer {
inline void initialize(GLES3GPUSwapchain *sc) { swapchain = sc; }
inline void initialize(GLuint framebuffer) { _glFramebuffer = framebuffer; }
inline void initialize(const GLFramebufferInfo &info) {
_glFramebuffer = info.glFramebuffer;
_width = info.width;
_height = info.height;
}
inline GLuint getFramebuffer() const { return swapchain ? swapchain->glFramebuffer : _glFramebuffer; }
inline uint32_t getWidth() const { return swapchain ? swapchain->gpuColorTexture->width : _width; }
inline uint32_t getHeight() const { return swapchain ? swapchain->gpuColorTexture->height : _height; }
void destroy(GLES3GPUStateCache *cache, GLES3GPUFramebufferCacheMap *framebufferCacheMap);
@@ -339,6 +351,8 @@ public:
private:
GLuint _glFramebuffer{0U};
uint32_t _width{0U};
uint32_t _height{0U};
};
struct Framebuffer {
@@ -98,6 +98,8 @@ void GLES3Swapchain::doInit(const SwapchainInfo& info) {
textureInfo.format = Format::DEPTH_STENCIL;
initTexture(textureInfo, _depthStencilTexture);
_gpuSwapchain->gpuColorTexture = static_cast<GLES3Texture*>(_colorTexture)->gpuTexture();
}
void GLES3Swapchain::doDestroy() {