Commits

Alex Szpakowski committed 9448187

Added wrapper function for glVertex/TexCoord/ColorPointer calls

Comments (0)

Files changed (8)

src/modules/graphics/opengl/Canvas.cpp

 	ctx->bindTexture(img);
 
 	ctx->setActiveVertexAttribs(Context::ATTRIB_VERTEX | Context::ATTRIB_TEXCOORD);
-	
-	glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&v[0].x);
-	glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&v[0].s);
-	
+
+	ctx->vertexAttribPointer(Context::ATTRIB_VERTEX, 2, GL_FLOAT, sizeof(vertex), (GLvoid *)&v[0].x);
+	ctx->vertexAttribPointer(Context::ATTRIB_TEXCOORD, 2, GL_FLOAT, sizeof(vertex), (GLvoid *)&v[0].s);
+
 	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
 
 	glPopMatrix();

src/modules/graphics/opengl/Context.cpp

 		glDisableClientState(glattrib->second);
 
 	// save the attribute's state
-	attribenabled->second = enable;
+	state.enabledVertexAttribs[attrib] = enable;
 }
 
 void Context::setActiveVertexAttribs(unsigned int attribs)
 	}
 }
 
+void Context::vertexAttribPointer(Context::VertexAttribType attrib, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)
+{
+	// TODO: use glVertexAttribPointer when using GLES2
+	// TODO: custom vertex attributes?
+	switch (attrib)
+	{
+	case Context::ATTRIB_VERTEX:
+		glVertexPointer(size, type, stride, pointer);
+		break;
+	case Context::ATTRIB_TEXCOORD:
+		glTexCoordPointer(size, type, stride, pointer);
+		break;
+	case Context::ATTRIB_COLOR:
+		glColorPointer(size, type, stride, pointer);
+		break;
+	default:
+		break; // TODO?
+	}
+}
+
 void Context::setActiveTextureUnit(int textureunit)
 {
 	if (textureunit < 0 || (size_t) textureunit >= state.textureUnits.size())

src/modules/graphics/opengl/Context.h

 	 **/
 	void setVertexAttribState(unsigned int attrib, bool enable);
 
+	void vertexAttribPointer(VertexAttribType attrib, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
+
 	/**
 	 * Sets the active texture unit.
 	 *

src/modules/graphics/opengl/Font.cpp

 
 		ctx->setActiveVertexAttribs(Context::ATTRIB_VERTEX | Context::ATTRIB_TEXCOORD);
 
-		glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&glyphquads[0].vertices[0].x);
-		glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&glyphquads[0].vertices[0].s);
+		ctx->vertexAttribPointer(Context::ATTRIB_VERTEX, 2, GL_FLOAT, sizeof(vertex), (GLvoid *)&glyphquads[0].vertices[0].x);
+		ctx->vertexAttribPointer(Context::ATTRIB_TEXCOORD, 2, GL_FLOAT, sizeof(vertex), (GLvoid *)&glyphquads[0].vertices[0].s);
 
 		// we need to draw a new vertex array for every section of the string that uses a different texture than the previous section
 		std::vector<GlyphArrayDrawInfo>::const_iterator it;

src/modules/graphics/opengl/Graphics.cpp

 
 	// draw faded out line halos
 	ctx->setVertexAttribState(Context::ATTRIB_COLOR, true);
-	glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors);
-	glVertexPointer(2, GL_FLOAT, 0, (const GLvoid *)overdraw);
+	
+	ctx->vertexAttribPointer(Context::ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, 0, colors);
+	ctx->vertexAttribPointer(Context::ATTRIB_VERTEX, 2, GL_FLOAT, 0, (const GLvoid *)overdraw);
+	
 	glDrawArrays(GL_TRIANGLE_STRIP, 0, 2*count + 2 * int(!looping));
+
 	// "if GL_COLOR_ARRAY is enabled, the value of the current color is
 	// undefined after glDrawArrays executes"
 	glColor4fv(c);
 	// draw the core line
 	ctx->bindTexture(0);
 	ctx->setActiveVertexAttribs(Context::ATTRIB_VERTEX);
-	glVertexPointer(2, GL_FLOAT, 0, (const GLvoid *)vertices);
+	ctx->vertexAttribPointer(Context::ATTRIB_VERTEX, 2, GL_FLOAT, 0, (const GLvoid *)vertices);
 	glDrawArrays(GL_TRIANGLE_STRIP, 0, count);
 
 	// draw the line halo (antialiasing)
 		Context *ctx = getContext();
 		ctx->bindTexture(0);
 		ctx->setActiveVertexAttribs(Context::ATTRIB_VERTEX);
-		glVertexPointer(2, GL_FLOAT, 0, (const GLvoid *) coords);
+		ctx->vertexAttribPointer(Context::ATTRIB_VERTEX, 2, GL_FLOAT, 0, (const GLvoid *) coords);
 		glDrawArrays(GL_TRIANGLE_FAN, 0, points + 2);
 	}
 
 		Context *ctx = getContext();
 		ctx->bindTexture(0);
 		ctx->setActiveVertexAttribs(Context::ATTRIB_VERTEX);
-		glVertexPointer(2, GL_FLOAT, 0, (const GLvoid *)coords);
+		ctx->vertexAttribPointer(Context::ATTRIB_VERTEX, 2, GL_FLOAT, 0, (const GLvoid *)coords);
 		glDrawArrays(GL_POLYGON, 0, count/2-1); // opengl will close the polygon for us
 	}
 }

src/modules/graphics/opengl/Image.cpp

 
 	ctx->setActiveVertexAttribs(Context::ATTRIB_VERTEX | Context::ATTRIB_TEXCOORD);
 	
-	glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&v[0].x);
-	glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&v[0].s);
+	ctx->vertexAttribPointer(Context::ATTRIB_VERTEX, 2, GL_FLOAT, sizeof(vertex), (GLvoid *)&v[0].x);
+	ctx->vertexAttribPointer(Context::ATTRIB_TEXCOORD, 2, GL_FLOAT, sizeof(vertex), (GLvoid *)&v[0].s);
 	
 	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
 

src/modules/graphics/opengl/ParticleSystem.cpp

 
 	ctx->setActiveVertexAttribs(Context::ATTRIB_VERTEX | Context::ATTRIB_TEXCOORD | Context::ATTRIB_COLOR);
 
-	glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(vertex), (GLvoid *)&particleVerts[0].r);
-	glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&particleVerts[0].x);
-	glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&particleVerts[0].s);
+	ctx->vertexAttribPointer(Context::ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, sizeof(vertex), (GLvoid *)&particleVerts[0].r);
+	ctx->vertexAttribPointer(Context::ATTRIB_VERTEX, 2, GL_FLOAT, sizeof(vertex), (GLvoid *)&particleVerts[0].x);
+	ctx->vertexAttribPointer(Context::ATTRIB_TEXCOORD, 2, GL_FLOAT, sizeof(vertex), (GLvoid *)&particleVerts[0].s);
 
 	glDrawArrays(GL_QUADS, 0, numParticles*4);
 

src/modules/graphics/opengl/SpriteBatch.cpp

 
 	ctx->setActiveVertexAttribs(Context::ATTRIB_VERTEX | Context::ATTRIB_TEXCOORD);
 
-	glVertexPointer(2, GL_FLOAT, sizeof(vertex), array_buf->getPointer(vertex_offset));
-	glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), array_buf->getPointer(texel_offset));
+	ctx->vertexAttribPointer(Context::ATTRIB_VERTEX, 2, GL_FLOAT, sizeof(vertex), array_buf->getPointer(vertex_offset));
+	ctx->vertexAttribPointer(Context::ATTRIB_TEXCOORD, 2, GL_FLOAT, sizeof(vertex), array_buf->getPointer(texel_offset));
 
 	// Apply per-sprite color, if a color is set.
 	if (color)
 	{
 		ctx->setVertexAttribState(Context::ATTRIB_COLOR, true);
-		glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(vertex), array_buf->getPointer(color_offset));
+		ctx->vertexAttribPointer(Context::ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, sizeof(vertex), array_buf->getPointer(color_offset));
 	}
 
 	glDrawElements(GL_TRIANGLES, element_buf->getIndexCount(next), element_buf->getType(), element_buf->getPointer(0));