diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-06-10 20:51:32 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-06-10 20:51:32 +0300 |
commit | d7b65dd309ce9b91be9ef4f22d55f7f4009007a2 (patch) | |
tree | 54b890ee5e06cb3f229650a66e04e05e6276b4fa | |
parent | 03b8fa8772ef8aadb73fb096c7ba4e257902a331 (diff) | |
download | manaverse-d7b65dd309ce9b91be9ef4f22d55f7f4009007a2.tar.gz manaverse-d7b65dd309ce9b91be9ef4f22d55f7f4009007a2.tar.bz2 manaverse-d7b65dd309ce9b91be9ef4f22d55f7f4009007a2.tar.xz manaverse-d7b65dd309ce9b91be9ef4f22d55f7f4009007a2.zip |
In modernopengl add basic VAO usage.
-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 |