From d7b65dd309ce9b91be9ef4f22d55f7f4009007a2 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 10 Jun 2014 20:51:32 +0300 Subject: In modernopengl add basic VAO usage. --- src/render/modernopenglgraphics.cpp | 38 +++++++++++++++++++------------------ 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 -- cgit v1.2.3-70-g09d2