Fix color rendering

This commit is contained in:
Martin Gräßlin 2010-12-07 21:50:00 +01:00
parent 7d37977558
commit a182744648
2 changed files with 20 additions and 14 deletions

View file

@ -1252,6 +1252,7 @@ class GLVertexBufferPrivate
, dimension( 2 ) , dimension( 2 )
, useShader( false ) , useShader( false )
, useColor( false ) , useColor( false )
, useTexCoords( true )
, color( 0, 0, 0, 255 ) , color( 0, 0, 0, 255 )
{ {
if( GLVertexBufferPrivate::supported ) if( GLVertexBufferPrivate::supported )
@ -1275,6 +1276,7 @@ class GLVertexBufferPrivate
QVector<float> legacyVertices; QVector<float> legacyVertices;
QVector<float> legacyTexCoords; QVector<float> legacyTexCoords;
bool useColor; bool useColor;
bool useTexCoords;
QColor color; QColor color;
void legacyPainting( QRegion region, GLenum primitiveMode ); void legacyPainting( QRegion region, GLenum primitiveMode );
@ -1316,7 +1318,9 @@ void GLVertexBufferPrivate::legacyPainting( QRegion region, GLenum primitiveMode
void GLVertexBufferPrivate::corePainting( const QRegion& region, GLenum primitiveMode ) void GLVertexBufferPrivate::corePainting( const QRegion& region, GLenum primitiveMode )
{ {
glEnableVertexAttribArray( 0 ); glEnableVertexAttribArray( 0 );
glEnableVertexAttribArray( 1 ); if (useTexCoords) {
glEnableVertexAttribArray( 1 );
}
// TODO: have this information available somewhere useable // TODO: have this information available somewhere useable
GLint currentProgram; GLint currentProgram;
@ -1324,19 +1328,21 @@ void GLVertexBufferPrivate::corePainting( const QRegion& region, GLenum primitiv
GLint vertexAttrib = glGetAttribLocation( currentProgram, "vertex" ); GLint vertexAttrib = glGetAttribLocation( currentProgram, "vertex" );
GLint texAttrib = glGetAttribLocation( currentProgram, "texCoord" ); GLint texAttrib = glGetAttribLocation( currentProgram, "texCoord" );
glBindBuffer( GL_ARRAY_BUFFER, buffers[ 0 ] );
glVertexAttribPointer( vertexAttrib, dimension, GL_FLOAT, GL_FALSE, 0, 0 );
glBindBuffer( GL_ARRAY_BUFFER, buffers[ 1 ] );
glVertexAttribPointer( texAttrib, 2, GL_FLOAT, GL_FALSE, 0, 0 );
if (useColor) { if (useColor) {
GLint colorLocation = glGetUniformLocation(currentProgram, "geometryColor"); GLint colorLocation = glGetUniformLocation(currentProgram, "geometryColor");
if (colorLocation != 0) { if (colorLocation != 0) {
glUniform4f(currentProgram, color.redF(), color.greenF(), color.blueF(), color.alphaF()); glUniform4f(colorLocation, color.redF(), color.greenF(), color.blueF(), color.alphaF());
} }
} }
glBindBuffer( GL_ARRAY_BUFFER, buffers[ 0 ] );
glVertexAttribPointer( vertexAttrib, dimension, GL_FLOAT, GL_FALSE, 0, 0 );
if (texAttrib != -1 && useTexCoords) {
glBindBuffer( GL_ARRAY_BUFFER, buffers[ 1 ] );
glVertexAttribPointer( texAttrib, 2, GL_FLOAT, GL_FALSE, 0, 0 );
}
// TODO: reenable paint clipper // TODO: reenable paint clipper
// Clip using scissoring // Clip using scissoring
PaintClipper pc( region ); PaintClipper pc( region );
@ -1349,7 +1355,9 @@ void GLVertexBufferPrivate::corePainting( const QRegion& region, GLenum primitiv
glBindBuffer( GL_ARRAY_BUFFER, 0 ); glBindBuffer( GL_ARRAY_BUFFER, 0 );
glDisableVertexAttribArray( 1 ); if (useTexCoords) {
glDisableVertexAttribArray( 1 );
}
glDisableVertexAttribArray( 0 ); glDisableVertexAttribArray( 0 );
} }
@ -1370,6 +1378,7 @@ void GLVertexBuffer::setData( int numberVertices, int dim, const float* vertices
{ {
d->numberVertices = numberVertices; d->numberVertices = numberVertices;
d->dimension = dim; d->dimension = dim;
d->useTexCoords = (texcoords != NULL);
if( !GLVertexBufferPrivate::supported ) if( !GLVertexBufferPrivate::supported )
{ {
// legacy data // legacy data
@ -1380,7 +1389,7 @@ void GLVertexBuffer::setData( int numberVertices, int dim, const float* vertices
d->legacyVertices << vertices[i]; d->legacyVertices << vertices[i];
} }
d->legacyTexCoords.clear(); d->legacyTexCoords.clear();
if (texcoords != NULL) { if (d->useTexCoords) {
d->legacyTexCoords.reserve( numberVertices * 2 ); d->legacyTexCoords.reserve( numberVertices * 2 );
for (int i=0; i<numberVertices*2; ++i) { for (int i=0; i<numberVertices*2; ++i) {
d->legacyTexCoords << texcoords[i]; d->legacyTexCoords << texcoords[i];
@ -1408,7 +1417,7 @@ void GLVertexBuffer::setData( int numberVertices, int dim, const float* vertices
glBindBuffer( GL_ARRAY_BUFFER, d->buffers[ 0 ] ); glBindBuffer( GL_ARRAY_BUFFER, d->buffers[ 0 ] );
glBufferData( GL_ARRAY_BUFFER, sizeof(GLfloat)*numberVertices*d->dimension, vertices, hint ); glBufferData( GL_ARRAY_BUFFER, sizeof(GLfloat)*numberVertices*d->dimension, vertices, hint );
if (texcoords != NULL) { if (d->useTexCoords) {
glBindBuffer( GL_ARRAY_BUFFER, d->buffers[ 1 ] ); glBindBuffer( GL_ARRAY_BUFFER, d->buffers[ 1 ] );
glBufferData( GL_ARRAY_BUFFER, sizeof(GLfloat)*numberVertices*2, texcoords, hint ); glBufferData( GL_ARRAY_BUFFER, sizeof(GLfloat)*numberVertices*2, texcoords, hint );
} }

View file

@ -3,9 +3,6 @@ precision highp float;
#endif #endif
uniform vec4 geometryColor; uniform vec4 geometryColor;
// not used
varying vec2 varyingTexCoords;
void main() { void main() {
gl_FragColor = geometryColor; gl_FragColor = geometryColor;
} }