diff --git a/layer0/GenericBuffer.cpp b/layer0/GenericBuffer.cpp index a879ecd2b..6e6b93ee0 100644 --- a/layer0/GenericBuffer.cpp +++ b/layer0/GenericBuffer.cpp @@ -1,6 +1,9 @@ -#include #include "GenericBuffer.h" +#include "GraphicsUtil.h" + +#include + VertexFormatBaseType GetVertexFormatBaseType(VertexFormat format) { switch (format) { @@ -369,13 +372,13 @@ bool GenericBuffer::interleaveBufferData() bool GenericBuffer::genBuffer(GLuint& id, size_t size, const void* ptr) { glGenBuffers(1, &id); - if (!glCheckOkay()) + if (!CheckGLErrorOK(nullptr, "GenericBuffer::genBuffer failed\n")) return false; glBindBuffer(bufferType(), id); - if (!glCheckOkay()) + if (!CheckGLErrorOK(nullptr, "GenericBuffer::bindBuffer failed\n")) return false; glBufferData(bufferType(), size, ptr, GL_STATIC_DRAW); - if (!glCheckOkay()) + if (!CheckGLErrorOK(nullptr, "GenericBuffer::bufferData failed\n")) return false; return true; } @@ -487,7 +490,7 @@ void renderBuffer_t::genBuffer() { glRenderbufferStorage(GL_RENDERBUFFER, rbo_lut[(int)_storage], _width, _height); - glCheckOkay(); + CheckGLErrorOK(nullptr, "GLRenderBuffer::genBuffer failed"); } void renderBuffer_t::freeBuffer() { glDeleteRenderbuffers(1, &_id); } @@ -653,7 +656,7 @@ void textureBuffer_t::genBuffer() { glTexParameteri(dim, GL_TEXTURE_WRAP_R, tex_tab(_sampling[4])); #endif - glCheckOkay(); + CheckGLErrorOK(nullptr, "GLTextureBuffer::genBuffer failed"); } void textureBuffer_t::freeBuffer() { glDeleteTextures(1, &_id); } @@ -682,7 +685,7 @@ void textureBuffer_t::texture_data_1D(int width, const void *data) { default: break; }; - glCheckOkay(); + CheckGLErrorOK(nullptr, "GLTextureBuffer::texture_data_1D failed"); #endif } @@ -707,7 +710,7 @@ void textureBuffer_t::texture_data_2D(int width, int height, const void *data) { default: break; } - glCheckOkay(); + CheckGLErrorOK(nullptr, "GLTextureBuffer::texture_data_2D failed"); } void textureBuffer_t::texture_subdata_2D( @@ -726,7 +729,7 @@ void textureBuffer_t::texture_subdata_2D( tex_tab(_format), tex_tab(_type), data); break; } - glCheckOkay(); + CheckGLErrorOK(nullptr, "GLTextureBuffer::texture_subdata_2D failed"); } void textureBuffer_t::texture_data_3D(int width, int height, int depth, @@ -757,7 +760,7 @@ void textureBuffer_t::texture_data_3D(int width, int height, int depth, } #endif - glCheckOkay(); + CheckGLErrorOK(nullptr, "GLTextureBuffer::texture_data_3D failed"); } void textureBuffer_t::bind() const { glBindTexture(tex_tab(_dim), _id); } @@ -929,7 +932,7 @@ void renderTarget_t::layout(std::vector &&desc, } _fbo->attach_renderbuffer(_rbo, fbo::attachment::DEPTH); _desc = std::move(desc); - glCheckOkay(); + CheckGLErrorOK(nullptr, "GLRenderBuffer::layout failed\n"); } void renderTarget_t::resize(shape_type size) { diff --git a/layer0/GenericBuffer.h b/layer0/GenericBuffer.h index f9e9b36f5..a17c3e109 100644 --- a/layer0/GenericBuffer.h +++ b/layer0/GenericBuffer.h @@ -1,6 +1,5 @@ #pragma once // ----------------------------------------------------------------------------- -#include "GraphicsUtil.h" #include "Vector.h" #include #include diff --git a/layer0/GraphicsUtil.cpp b/layer0/GraphicsUtil.cpp index 64e22d0de..e2f2f9766 100755 --- a/layer0/GraphicsUtil.cpp +++ b/layer0/GraphicsUtil.cpp @@ -1,8 +1,14 @@ +#include "GraphicsUtil.h" + +#include "PyMOLGlobals.h" +#include "Feedback.h" + #include #ifdef _WEBGL +#include #endif + #include -#include "GraphicsUtil.h" // ----------------------------------------------------------------------------- // UTIL // Prints a backtrace during runtime of the last ^ stack frames @@ -26,6 +32,25 @@ bool glCheckOkay() { return true; } +bool CheckGLErrorOK(PyMOLGlobals* G, std::string_view errString) +{ + GLenum err; + if ((err = glGetError()) != 0) { +#ifdef _WEBGL + print_trace(); +#else + if (G) { + PRINTFB(G, FB_CGO, FB_Errors) + "GL_Error: 0x%04x @ %s\n", err, errString.data() ENDFB(G); + } else { + printf("GL_ERROR : 0x%04x %s\n", err, errString.data()); + } + std::terminate(); +#endif + } + return err == 0; +} + /** * GL debugging callback - enable with "pymol --gldebug" * diff --git a/layer0/GraphicsUtil.h b/layer0/GraphicsUtil.h index 00e79a507..c7ff81418 100755 --- a/layer0/GraphicsUtil.h +++ b/layer0/GraphicsUtil.h @@ -2,8 +2,11 @@ #include "os_gl.h" -// Generic Error Handing -bool glCheckOkay(); +#include + +struct PyMOLGlobals; + +bool CheckGLErrorOK(PyMOLGlobals* G, std::string_view errString); void GLAPIENTRY gl_debug_proc(GLenum, GLenum, GLuint, GLenum, GLsizei, const GLchar *, const void *); // userParam is qualified as const in OpenGL 4.4 spec but non-const in OpenGL 4.3 spec diff --git a/layer1/CGO.cpp b/layer1/CGO.cpp index 5b37ef008..6aa3b2278 100644 --- a/layer1/CGO.cpp +++ b/layer1/CGO.cpp @@ -46,6 +46,7 @@ Z* ------------------------------------------------------------------- #include "Util.h" #include "VFont.h" #include "Vector.h" +#include "GraphicsUtil.h" #include "pymol/algorithm.h" diff --git a/layer1/CGOGL.cpp b/layer1/CGOGL.cpp index f8cbbb1bf..ae26eac6e 100644 --- a/layer1/CGOGL.cpp +++ b/layer1/CGOGL.cpp @@ -5,6 +5,7 @@ #include "CGORenderer.h" #include "CoordSet.h" #include "Feedback.h" +#include "GraphicsUtil.h" #include "Scene.h" #include "SceneDef.h" #include "ShaderMgr.h" @@ -56,17 +57,6 @@ static int CGOConvertDebugMode(int debug, int modeArg) return mode; } -#define CHECK_GL_ERROR_OK(printstr) \ - if ((err = glGetError()) != 0) { \ - PRINTFB(G, FB_CGO, FB_Errors) printstr, err ENDFB(G); \ - } - -void CheckGLErrorOK(PyMOLGlobals* G, pymol::zstring_view errString) -{ - GLenum err; - CHECK_GL_ERROR_OK(errString.c_str()); -} - static void CGO_gl_begin(CCGORenderer* I, CGO_op_data pc) { #ifndef PURE_OPENGL_ES_2 diff --git a/layer1/CGOGL.h b/layer1/CGOGL.h index 05ecebbde..6771ea87a 100644 --- a/layer1/CGOGL.h +++ b/layer1/CGOGL.h @@ -9,8 +9,6 @@ struct CSetting; struct Rep; struct PickContext; -void CheckGLErrorOK(PyMOLGlobals* G, pymol::zstring_view errString); - void CGORenderGLPicking(CGO * I, RenderInfo *info, PickContext * context, CSetting * set1, CSetting * set2, Rep *rep); void CGORenderGL(CGO * I, const float *color, CSetting * set1, CSetting * set2, diff --git a/layer1/Ortho.cpp b/layer1/Ortho.cpp index abd8f488c..d740666cf 100644 --- a/layer1/Ortho.cpp +++ b/layer1/Ortho.cpp @@ -3122,7 +3122,6 @@ static pymol::Result OrthoMakeSizedImage( OrthoSetExtent(G, extent); G->ShaderMgr->bindOffscreenOrtho(extent, true); - auto drawBuffer = SceneDrawBothGetConfig(G); pymol::Image final_image(extent.width, extent.height); // Save before we change scene extents in OrthoDrawSizedTile diff --git a/layer1/Scene.cpp b/layer1/Scene.cpp index b825d307d..0b40d6779 100644 --- a/layer1/Scene.cpp +++ b/layer1/Scene.cpp @@ -1512,10 +1512,12 @@ float *SceneGetPmvMatrix(PyMOLGlobals * G) GLFramebufferConfig SceneDrawBothGetConfig(PyMOLGlobals* G) { - if (SceneMustDrawBoth(G)) { - return { CShaderMgr::OpenGLDefaultFramebufferID, GL_BACK_LEFT }; - } - return { CShaderMgr::OpenGLDefaultFramebufferID, GL_BACK }; + GLFramebufferConfig config; + config.framebuffer = G->ShaderMgr->defaultBackbuffer.framebuffer; + config.drawBuffer = SceneMustDrawBoth(G) + ? GL_BACK_LEFT + : G->ShaderMgr->defaultBackbuffer.drawBuffer; + return config; } int SceneCaptureWindow(PyMOLGlobals * G) @@ -1792,7 +1794,6 @@ pymol::Result<> SceneMakeSizedImage(PyMOLGlobals* G, Extent2D extent, int nXStep = (extent.width / (I->Width + 1)) + 1; int nYStep = (extent.height / (I->Height + 1)) + 1; - auto drawBuffer = SceneDrawBothGetConfig(G); pymol::Image final_image(extent.width, extent.height); @@ -4557,10 +4558,6 @@ void SceneCopy(PyMOLGlobals * G, GLFramebufferConfig config, int force, int enti { CScene *I = G->Scene; - if (config.drawBuffer == GL_BACK) { - config.drawBuffer = G->ShaderMgr->defaultBackbuffer.drawBuffer; - } - if(force || (!(I->StereoMode || SettingGetGlobal_b(G, cSetting_stereo_double_pump_mono) || I->ButtonsShown))) { /* no copies while in stereo mode */