From cfa7db77da04fa7b2e4027b460ce7f96d2ad6d08 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Sun, 3 Jun 2012 18:41:44 -0300 Subject: [PATCH] fix possible crash in older opengl driver implementations --- src/framework/graphics/painterogl1.cpp | 27 ++++++++++++++++++-------- src/framework/graphics/painterogl1.h | 1 + 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/framework/graphics/painterogl1.cpp b/src/framework/graphics/painterogl1.cpp index 0c994e52..d20e0e11 100644 --- a/src/framework/graphics/painterogl1.cpp +++ b/src/framework/graphics/painterogl1.cpp @@ -38,6 +38,7 @@ void PainterOGL1::refreshState() updateGlMatrixMode(); updateGlProjectionMatrix(); updateGlTextureMatrix(); + updateGlTextureState(); } void PainterOGL1::bind() @@ -46,14 +47,14 @@ void PainterOGL1::bind() // vertex and texture coord arrays are always enabled // to avoid massive enable/disables, thus improving frame rate - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glEnableClientState(GL_VERTEX_ARRAY); + if(g_graphics.canUseDrawArrays()) + glEnableClientState(GL_VERTEX_ARRAY); } void PainterOGL1::unbind() { - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); + if(g_graphics.canUseDrawArrays()) + glDisableClientState(GL_VERTEX_ARRAY); } void PainterOGL1::drawCoords(CoordsBuffer& coordsBuffer, DrawMode drawMode) @@ -69,11 +70,8 @@ void PainterOGL1::drawCoords(CoordsBuffer& coordsBuffer, DrawMode drawMode) return; if(textured != m_textureEnabled) { - if(textured) - glEnable(GL_TEXTURE_2D); - else - glDisable(GL_TEXTURE_2D); m_textureEnabled = textured; + updateGlTextureState(); } // use vertex arrays if possible, much faster @@ -256,3 +254,16 @@ void PainterOGL1::updateGlTextureMatrix() setMatrixMode(MatrixTexture); glLoadMatrixf(glTextureMatrix); } + +void PainterOGL1::updateGlTextureState() +{ + if(m_textureEnabled) { + glEnable(GL_TEXTURE_2D); + if(g_graphics.canUseDrawArrays()) + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + } else { + glDisable(GL_TEXTURE_2D); + if(g_graphics.canUseDrawArrays()) + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + } +} diff --git a/src/framework/graphics/painterogl1.h b/src/framework/graphics/painterogl1.h index f062943a..e083670c 100644 --- a/src/framework/graphics/painterogl1.h +++ b/src/framework/graphics/painterogl1.h @@ -66,6 +66,7 @@ private: void updateGlMatrixMode(); void updateGlProjectionMatrix(); void updateGlTextureMatrix(); + void updateGlTextureState(); GLenum m_matrixMode; Boolean m_textureEnabled;