fix possible crash in older opengl driver implementations

This commit is contained in:
Eduardo Bart 2012-06-03 18:41:44 -03:00
parent 9548ce78c6
commit cfa7db77da
2 changed files with 20 additions and 8 deletions

View File

@ -38,6 +38,7 @@ void PainterOGL1::refreshState()
updateGlMatrixMode(); updateGlMatrixMode();
updateGlProjectionMatrix(); updateGlProjectionMatrix();
updateGlTextureMatrix(); updateGlTextureMatrix();
updateGlTextureState();
} }
void PainterOGL1::bind() void PainterOGL1::bind()
@ -46,14 +47,14 @@ void PainterOGL1::bind()
// vertex and texture coord arrays are always enabled // vertex and texture coord arrays are always enabled
// to avoid massive enable/disables, thus improving frame rate // to avoid massive enable/disables, thus improving frame rate
glEnableClientState(GL_TEXTURE_COORD_ARRAY); if(g_graphics.canUseDrawArrays())
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
} }
void PainterOGL1::unbind() void PainterOGL1::unbind()
{ {
glDisableClientState(GL_VERTEX_ARRAY); if(g_graphics.canUseDrawArrays())
glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY);
} }
void PainterOGL1::drawCoords(CoordsBuffer& coordsBuffer, DrawMode drawMode) void PainterOGL1::drawCoords(CoordsBuffer& coordsBuffer, DrawMode drawMode)
@ -69,11 +70,8 @@ void PainterOGL1::drawCoords(CoordsBuffer& coordsBuffer, DrawMode drawMode)
return; return;
if(textured != m_textureEnabled) { if(textured != m_textureEnabled) {
if(textured)
glEnable(GL_TEXTURE_2D);
else
glDisable(GL_TEXTURE_2D);
m_textureEnabled = textured; m_textureEnabled = textured;
updateGlTextureState();
} }
// use vertex arrays if possible, much faster // use vertex arrays if possible, much faster
@ -256,3 +254,16 @@ void PainterOGL1::updateGlTextureMatrix()
setMatrixMode(MatrixTexture); setMatrixMode(MatrixTexture);
glLoadMatrixf(glTextureMatrix); 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);
}
}

View File

@ -66,6 +66,7 @@ private:
void updateGlMatrixMode(); void updateGlMatrixMode();
void updateGlProjectionMatrix(); void updateGlProjectionMatrix();
void updateGlTextureMatrix(); void updateGlTextureMatrix();
void updateGlTextureState();
GLenum m_matrixMode; GLenum m_matrixMode;
Boolean<false> m_textureEnabled; Boolean<false> m_textureEnabled;