diff options
-rw-r--r-- | src/render/modernopenglgraphics.cpp | 38 | ||||
-rw-r--r-- | src/render/modernopenglgraphics.h | 1 |
2 files changed, 21 insertions, 18 deletions
diff --git a/src/render/modernopenglgraphics.cpp b/src/render/modernopenglgraphics.cpp index caa14cb33..c3e4fbba3 100644 --- a/src/render/modernopenglgraphics.cpp +++ b/src/render/modernopenglgraphics.cpp @@ -71,6 +71,7 @@ ModernOpenGLGraphics::ModernOpenGLGraphics() : mTexAttrib(0), mSimpleScreenUniform(0U), mTextureScreenUniform(0U), + mVao(0U), mColorAlpha(false), mTextureDraw(false), #ifdef DEBUG_BIND_TEXTURE @@ -88,6 +89,8 @@ ModernOpenGLGraphics::~ModernOpenGLGraphics() deleteArraysInternal(); if (mSimpleProgram) mSimpleProgram->decRef(); + if (mVao) + mglDeleteVertexArrays(1, &mVao); } void ModernOpenGLGraphics::initArrays(const int vertCount) @@ -109,30 +112,29 @@ void ModernOpenGLGraphics::initArrays(const int vertCount) void ModernOpenGLGraphics::postInit() { + mglGenVertexArrays(1, &mVao); + mglBindVertexArray(mVao); + logger->log("Compiling shaders"); mSimpleProgram = shaders.getSimpleProgram(); mSimpleProgramId = mSimpleProgram->getProgramId(); mTextureProgram = shaders.getTextureProgram(); mTextureProgramId = mTextureProgram->getProgramId(); - if (mSimpleProgram && mTextureProgram) - { - logger->log("Shaders compilation done."); - mglUseProgram(mSimpleProgramId); - mSimplePosAttrib = mglGetAttribLocation(mSimpleProgramId, "position"); - mglEnableVertexAttribArray(mSimplePosAttrib); - mSimpleColorUniform = mglGetUniformLocation(mSimpleProgramId, "color"); - mSimpleScreenUniform = mglGetUniformLocation(mSimpleProgramId, "screen"); - - mTexturePosAttrib = mglGetAttribLocation(mTextureProgramId, "position"); - mTexAttrib = mglGetAttribLocation(mTextureProgramId, "texcoord"); - mTextureScreenUniform = mglGetUniformLocation(mTextureProgramId, "screen"); - - screenResized(); - } - else - { + if (!mSimpleProgram || !mTextureProgram) logger->error("Shaders compilation error."); - } + + logger->log("Shaders compilation done."); + mglUseProgram(mSimpleProgramId); + mSimplePosAttrib = mglGetAttribLocation(mSimpleProgramId, "position"); + mglEnableVertexAttribArray(mSimplePosAttrib); + mSimpleColorUniform = mglGetUniformLocation(mSimpleProgramId, "color"); + mSimpleScreenUniform = mglGetUniformLocation(mSimpleProgramId, "screen"); + + mTexturePosAttrib = mglGetAttribLocation(mTextureProgramId, "position"); + mTexAttrib = mglGetAttribLocation(mTextureProgramId, "texcoord"); + mTextureScreenUniform = mglGetUniformLocation(mTextureProgramId, "screen"); + + screenResized(); } void ModernOpenGLGraphics::screenResized() diff --git a/src/render/modernopenglgraphics.h b/src/render/modernopenglgraphics.h index 3b3be8d85..b3a217ca2 100644 --- a/src/render/modernopenglgraphics.h +++ b/src/render/modernopenglgraphics.h @@ -99,6 +99,7 @@ class ModernOpenGLGraphics final : public Graphics GLint mTexAttrib; GLuint mSimpleScreenUniform; GLuint mTextureScreenUniform; + GLuint mVao; bool mColorAlpha; bool mTextureDraw; #ifdef DEBUG_BIND_TEXTURE |