Commits

Marc Lepage committed 49e300f Draft

Implement SpriteBatch::draw (without per-sprite color).

Comments (0)

Files changed (6)

src/modules/graphics/opengl/GLES.cpp

 float color[4] = { 1, 1, 1, 1 };
 float colorWhite[4] = { 1, 1, 1, 1 };
 
+GLushort quadIndices[] = { 0, 1, 2, 0, 2, 3 };
+
 // Modes: 0=modelview, 1=projection, 2=color, 3=texture
 std::vector<Matrix> stack[4];
 
 	// TODO
 }
 
-void glesDrawQuad(int vstride, const float* vdata, int tstride, const float* tdata)
+const unsigned short* glesQuadIndices()
 {
-	static GLubyte indices[] = { 0, 1, 3, 2 };
+	return quadIndices;
+}
+
+void glesDrawTriangles(int count, const unsigned short* indices, int vstride, const float* vdata, int tstride, const float* tdata)
+{
+	static GLushort defaultIndices[] = { 0, 1, 2, 0, 2, 3 };
+	static GLint locP, locM, locC, locS, locV, locT;
 	static GLuint program = 0;
-	static GLint locP, locM, locC, locS, locV, locT;
-
-	// TODO add support for color modulation
 
 	if (!program)
 	{
 	glVertexAttribPointer(locV, 2, GL_FLOAT, GL_FALSE, vstride, vdata);
 	glVertexAttribPointer(locT, 2, GL_FLOAT, GL_FALSE, tstride, tdata);
 
-	glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, indices);
+	glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, indices);
 
 	glDisableVertexAttribArray(0);
 	glDisableVertexAttribArray(1);

src/modules/graphics/opengl/GLES.h

 void glPushAttrib(unsigned int mask);
 void glPopAttrib(void);
 
+// For drawing a quad as two triangles
+const unsigned short* glesQuadIndices();
+
 // Takes 2D vertex and texture coordinates in order TL BL BR TR
 // Assumes texture is already bound
-void glesDrawQuad(int vstride, const float* vdata, int tstride, const float* tdata);
+void glesDrawTriangles(int count, const unsigned short* indices, int vstride, const float* vdata, int tstride, const float* tdata);
 
 }
 

src/modules/graphics/opengl/Graphics.cpp

 	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 	glDisableClientState(GL_VERTEX_ARRAY);
 #else
-	glesDrawQuad(sizeof(vertex), &buf[0].x, sizeof(vertex), &vertices[0].s);
+	glesDrawTriangles(6, glesQuadIndices(), sizeof(vertex), &buf[0].x, sizeof(vertex), &vertices[0].s);
 #endif
 }
 

src/modules/graphics/opengl/Image.cpp

 	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 	glDisableClientState(GL_VERTEX_ARRAY);
 #else
-	glesDrawQuad(sizeof(vertex), &v[0].x, sizeof(vertex), &v[0].s);
+	glesDrawTriangles(6, glesQuadIndices(), sizeof(vertex), &v[0].x, sizeof(vertex), &v[0].s);
 #endif
 
 	glPopMatrix();

src/modules/graphics/opengl/SpriteBatch.cpp

 	glDisableClientState(GL_VERTEX_ARRAY);
 	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 	glDisableClientState(GL_COLOR_ARRAY);
+#else
+	glesDrawTriangles(next*6, (unsigned short*) element_buf->getPointer(0),
+		sizeof(vertex), (const float*) array_buf->getPointer(vertex_offset),
+		sizeof(vertex), (const float*) array_buf->getPointer(texel_offset));
 #endif
 
 	glPopMatrix();

src/modules/graphics/opengl/VertexBuffer.cpp

 {
 #if !defined(HAVE_GLES)
 	if (!(GLEE_ARB_vertex_buffer_object || GLEE_VERSION_1_5))
+#endif
 		throw love::Exception("Not supported");
-#endif
 
 	bool ok = load(false);