From 3f7474e5b8fb4ce9bacbbfe5520b3b264dcfab3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 30 May 2018 18:14:13 +0200 Subject: [PATCH] More (disabled by default) gl error logging.. --- ext/native/thin3d/GLQueueRunner.cpp | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/ext/native/thin3d/GLQueueRunner.cpp b/ext/native/thin3d/GLQueueRunner.cpp index 653125d3fe..0c9cf6bd65 100644 --- a/ext/native/thin3d/GLQueueRunner.cpp +++ b/ext/native/thin3d/GLQueueRunner.cpp @@ -24,6 +24,7 @@ extern void bindDefaultFBO(); GLuint g_defaultFBO = 0; void GLQueueRunner::CreateDeviceObjects() { + CHECK_GL_ERROR_IF_DEBUG(); if (gl_extensions.EXT_texture_filter_anisotropic) { glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropyLevel_); } else { @@ -52,9 +53,11 @@ void GLQueueRunner::CreateDeviceObjects() { if (!gl_extensions.IsCoreContext) { // Not OK to query this in core profile! populate(GL_EXTENSIONS); } + CHECK_GL_ERROR_IF_DEBUG(); } void GLQueueRunner::DestroyDeviceObjects() { + CHECK_GL_ERROR_IF_DEBUG(); if (!nameCache_.empty()) { glDeleteTextures((GLsizei)nameCache_.size(), &nameCache_[0]); nameCache_.clear(); @@ -66,6 +69,7 @@ void GLQueueRunner::DestroyDeviceObjects() { readbackBufferSize_ = 0; delete[] tempBuffer_; tempBufferSize_ = 0; + CHECK_GL_ERROR_IF_DEBUG(); } void GLQueueRunner::RunInitSteps(const std::vector &steps) { @@ -83,6 +87,7 @@ void GLQueueRunner::RunInitSteps(const std::vector &steps) { glGenTextures(1, &tex->texture); glBindTexture(tex->target, tex->texture); boundTexture = tex->texture; + CHECK_GL_ERROR_IF_DEBUG(); break; } case GLRInitStepType::CREATE_BUFFER: @@ -91,6 +96,7 @@ void GLQueueRunner::RunInitSteps(const std::vector &steps) { glGenBuffers(1, &buffer->buffer); glBindBuffer(buffer->target_, buffer->buffer); glBufferData(buffer->target_, step.create_buffer.size, nullptr, step.create_buffer.usage); + CHECK_GL_ERROR_IF_DEBUG(); break; } case GLRInitStepType::BUFFER_SUBDATA: @@ -100,6 +106,7 @@ void GLQueueRunner::RunInitSteps(const std::vector &steps) { glBufferSubData(GL_ARRAY_BUFFER, step.buffer_subdata.offset, step.buffer_subdata.size, step.buffer_subdata.data); if (step.buffer_subdata.deleteData) delete[] step.buffer_subdata.data; + CHECK_GL_ERROR_IF_DEBUG(); break; } case GLRInitStepType::CREATE_PROGRAM: @@ -432,6 +439,7 @@ void GLQueueRunner::InitCreateFramebuffer(const GLRInitStep &step) { } void GLQueueRunner::RunSteps(const std::vector &steps) { + CHECK_GL_ERROR_IF_DEBUG(); for (size_t i = 0; i < steps.size(); i++) { const GLRStep &step = *steps[i]; switch (step.stepType) { @@ -456,6 +464,7 @@ void GLQueueRunner::RunSteps(const std::vector &steps) { } delete steps[i]; } + CHECK_GL_ERROR_IF_DEBUG(); } void GLQueueRunner::LogSteps(const std::vector &steps) { @@ -464,6 +473,7 @@ void GLQueueRunner::LogSteps(const std::vector &steps) { void GLQueueRunner::PerformBlit(const GLRStep &step) { + CHECK_GL_ERROR_IF_DEBUG(); // Without FBO_ARB / GLES3, this will collide with bind_for_read, but there's nothing // in ES 2.0 that actually separate them anyway of course, so doesn't matter. fbo_bind_fb_target(false, step.blit.dst->handle); @@ -492,6 +502,7 @@ void GLQueueRunner::PerformBlit(const GLRStep &step) { } void GLQueueRunner::PerformRenderPass(const GLRStep &step) { + CHECK_GL_ERROR_IF_DEBUG(); // Don't execute empty renderpasses. if (step.commands.empty()) { // Nothing to do. @@ -583,6 +594,7 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) { glDisable(GL_STENCIL_TEST); stencilEnabled = false; } + CHECK_GL_ERROR_IF_DEBUG(); break; case GLRRenderCommand::STENCILOP: glStencilOp(c.stencilOp.sFail, c.stencilOp.zFail, c.stencilOp.pass); @@ -608,6 +620,7 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) { glColorMask(c.blend.mask & 1, (c.blend.mask >> 1) & 1, (c.blend.mask >> 2) & 1, (c.blend.mask >> 3) & 1); colorMask = c.blend.mask; } + CHECK_GL_ERROR_IF_DEBUG(); break; case GLRRenderCommand::LOGICOP: #ifndef USING_GLES2 @@ -624,6 +637,7 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) { logicEnabled = false; } #endif + CHECK_GL_ERROR_IF_DEBUG(); break; case GLRRenderCommand::CLEAR: // Scissor test is on, and should be on after leaving this case. If we disable it, @@ -656,6 +670,7 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) { if (c.clear.scissorW == 0) { glEnable(GL_SCISSOR_TEST); } + CHECK_GL_ERROR_IF_DEBUG(); break; case GLRRenderCommand::INVALIDATE: { @@ -668,6 +683,7 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) { if (c.clear.clearMask & GL_STENCIL_BUFFER_BIT) attachments[count++] = GL_STENCIL_BUFFER_BIT; glInvalidateFramebuffer(GL_FRAMEBUFFER, count, attachments); + CHECK_GL_ERROR_IF_DEBUG(); break; } case GLRRenderCommand::BLENDCOLOR: @@ -686,6 +702,7 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) { #else glDepthRangef(c.viewport.vp.minZ, c.viewport.vp.maxZ); #endif + CHECK_GL_ERROR_IF_DEBUG(); break; } case GLRRenderCommand::SCISSOR: @@ -694,6 +711,7 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) { if (!curFB_) y = curFBHeight_ - y - c.scissor.rc.h; glScissor(c.scissor.rc.x, y, c.scissor.rc.w, c.scissor.rc.h); + CHECK_GL_ERROR_IF_DEBUG(); break; } case GLRRenderCommand::UNIFORM4F: @@ -718,6 +736,7 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) { break; } } + CHECK_GL_ERROR_IF_DEBUG(); break; } case GLRRenderCommand::UNIFORM4I: @@ -742,6 +761,7 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) { break; } } + CHECK_GL_ERROR_IF_DEBUG(); break; } case GLRRenderCommand::UNIFORMMATRIX: @@ -753,6 +773,7 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) { if (loc >= 0) { glUniformMatrix4fv(loc, 1, false, c.uniformMatrix4.m); } + CHECK_GL_ERROR_IF_DEBUG(); break; } case GLRRenderCommand::BINDTEXTURE: @@ -798,6 +819,7 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) { glUseProgram(c.program.program->program); curProgram = c.program.program; } + CHECK_GL_ERROR_IF_DEBUG(); break; } case GLRRenderCommand::BIND_VERTEX_BUFFER: @@ -861,6 +883,7 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) { } else { glDrawElementsInstanced(c.drawIndexed.mode, c.drawIndexed.count, c.drawIndexed.indexType, c.drawIndexed.indices, c.drawIndexed.instances); } + CHECK_GL_ERROR_IF_DEBUG(); break; case GLRRenderCommand::TEXTURESAMPLER: { @@ -949,6 +972,7 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) { glDisable(GL_DITHER); ditherEnabled = false; } + CHECK_GL_ERROR_IF_DEBUG(); break; default: Crash(); @@ -966,6 +990,7 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) { glActiveTexture(GL_TEXTURE0); activeSlot = 0; // doesn't matter, just nice. } + CHECK_GL_ERROR_IF_DEBUG(); // Wipe out the current state. glBindBuffer(GL_ARRAY_BUFFER, 0); @@ -986,6 +1011,7 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) { } void GLQueueRunner::PerformCopy(const GLRStep &step) { + CHECK_GL_ERROR_IF_DEBUG(); GLuint srcTex = 0; GLuint dstTex = 0; GLuint target = GL_TEXTURE_2D; @@ -1047,6 +1073,7 @@ void GLQueueRunner::PerformCopy(const GLRStep &step) { void GLQueueRunner::PerformReadback(const GLRStep &pass) { using namespace Draw; + CHECK_GL_ERROR_IF_DEBUG(); GLRFramebuffer *fb = pass.readback.src; @@ -1149,6 +1176,7 @@ void GLQueueRunner::PerformBindFramebufferAsRenderTarget(const GLRStep &pass) { fbo_unbind(); // Backbuffer is now bound. } + CHECK_GL_ERROR_IF_DEBUG(); } void GLQueueRunner::CopyReadbackBuffer(int width, int height, Draw::DataFormat srcFormat, Draw::DataFormat destFormat, int pixelStride, uint8_t *pixels) { @@ -1168,6 +1196,7 @@ GLuint GLQueueRunner::AllocTextureName() { } u32 name = nameCache_.back(); nameCache_.pop_back(); + CHECK_GL_ERROR_IF_DEBUG(); return name; } @@ -1178,6 +1207,8 @@ GLuint GLQueueRunner::AllocTextureName() { void GLQueueRunner::fbo_ext_create(const GLRInitStep &step) { GLRFramebuffer *fbo = step.create_framebuffer.framebuffer; + CHECK_GL_ERROR_IF_DEBUG(); + // Color texture is same everywhere glGenFramebuffersEXT(1, &fbo->handle); glGenTextures(1, &fbo->color_texture.texture); @@ -1230,6 +1261,8 @@ void GLQueueRunner::fbo_ext_create(const GLRInitStep &step) { glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); glBindTexture(GL_TEXTURE_2D, 0); + CHECK_GL_ERROR_IF_DEBUG(); + currentDrawHandle_ = fbo->handle; currentReadHandle_ = fbo->handle; } @@ -1295,6 +1328,7 @@ void GLQueueRunner::fbo_unbind() { } GLRFramebuffer::~GLRFramebuffer() { + CHECK_GL_ERROR_IF_DEBUG(); if (gl_extensions.ARB_framebuffer_object || gl_extensions.IsGLES) { if (handle) { glBindFramebuffer(GL_FRAMEBUFFER, handle); @@ -1326,4 +1360,5 @@ GLRFramebuffer::~GLRFramebuffer() { glDeleteRenderbuffers(1, &stencil_buffer); #endif } + CHECK_GL_ERROR_IF_DEBUG(); }