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();
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);
if(g_graphics.canUseDrawArrays())
glEnableClientState(GL_VERTEX_ARRAY);
}
void PainterOGL1::unbind()
{
if(g_graphics.canUseDrawArrays())
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_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);
}
}

View File

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