Commits

Marc Lepage  committed fa0eb39 Draft

Port GL code that is simple to emulate.

  • Participants
  • Parent commits cc451ce
  • Branches gles

Comments (0)

Files changed (8)

File src/modules/graphics/opengl/Canvas.cpp

 #include "Graphics.h"
 #include "common/Matrix.h"
 
+#ifdef HAVE_GLES
+	#include "GLES.h"
+#endif
+
 #include <cstring> // For memcpy
 
 namespace love
 	if (current != NULL)
 		current->stopGrab();
 
-#if !defined(HAVE_GLES)
 	// bind buffer and clear screen
 	glPushAttrib(GL_VIEWPORT_BIT | GL_TRANSFORM_BIT);
 	strategy->bindFBO(fbo);
 
 	// Switch back to modelview matrix
 	glMatrixMode(GL_MODELVIEW);
-#endif
 
 	// indicate we are using this fbo
 	current = this;
 
 	// bind default
 	strategy->bindFBO(0);
-#if !defined(HAVE_GLES)
 	glMatrixMode(GL_PROJECTION);
 	glPopMatrix();
 	glPopAttrib();
-#endif
 	current = NULL;
 }
 
 
 void Canvas::drawv(const Matrix &t, const vertex *v) const
 {
-#if !defined(HAVE_GLES)
 	glPushMatrix();
 
 	glMultMatrixf((const GLfloat *)t.getElements());
 
 	bindTexture(img);
 
+#if !defined(HAVE_GLES)
 	glEnableClientState(GL_VERTEX_ARRAY);
 	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
 	glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&v[0].x);
 	glDrawArrays(GL_QUADS, 0, 4);
 	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 	glDisableClientState(GL_VERTEX_ARRAY);
+#endif
 
 	glPopMatrix();
-#endif
 }
 
 } // opengl

File src/modules/graphics/opengl/Font.cpp

 #include "font/GlyphData.h"
 #include "Quad.h"
 
+#ifdef HAVE_GLES
+	#include "GLES.h"
+#endif
+
 #include "libraries/utf8/utf8.h"
 
 #include "common/math.h"
 
 void Font::print(std::string text, float x, float y, float letter_spacing, float angle, float sx, float sy, float ox, float oy, float kx, float ky)
 {
-#if !defined(HAVE_GLES)
 	float dx = 0.0f; // spacing counter for newline handling
 	glPushMatrix();
 
 			// 1.25 is magic line height for true type fonts
 			if (type == FONT_TRUETYPE) glTranslatef(0, floor(getHeight() / 1.25f + 0.5f), 0);
 			bindTexture(glyph->texture);
+#if !defined(HAVE_GLES)
 			glCallList(glyph->list);
+#endif
 			glPopMatrix();
 			glTranslatef(static_cast<GLfloat>(glyph->spacing + letter_spacing), 0, 0);
 			dx += glyph->spacing + letter_spacing;
 		throw love::Exception("%s", e.what());
 	}
 	glPopMatrix();
-#endif
 }
 
 void Font::print(char character, float x, float y)
 
 	if (0 != glyph->texture)
 	{
-#if !defined(HAVE_GLES)
 		glPushMatrix();
 		glTranslatef(x, floor(y+getHeight() + 0.5f), 0.0f);
 		bindTexture(glyph->texture);
+#if !defined(HAVE_GLES)
 		glCallList(glyph->list);
+#endif
 		glPopMatrix();
-#endif
 	}
 }
 

File src/modules/graphics/opengl/GLES.cpp

 	memcpy(params, color, sizeof(float)*4);
 }
 
+void glColor4fv(const float* v)
+{
+	memcpy(color, v, sizeof(float)*4);
+}
+
 void glColor4f(float red, float green, float blue, float alpha)
 {
 	color[0] = red;

File src/modules/graphics/opengl/GLES.h

 
 void glesGetColorfv(float* params);
 
+void glColor4fv(const float* v);
 void glColor4f(float red, float green, float blue, float alpha);
 void glColor4ubv(const unsigned char* v);
 

File src/modules/graphics/opengl/Graphics.cpp

 #include "Graphics.h"
 #include "window/sdl/Window.h"
 
+#ifdef HAVE_GLES
+	#include "GLES.h"
+#endif
+
 #include <vector>
 #include <sstream>
 #include <algorithm>
 	glGetFloatv(GL_POINT_SIZE, &s.pointSize);
 	//get point style
 	s.pointStyle = (glIsEnabled(GL_POINT_SMOOTH) == GL_TRUE) ? Graphics::POINT_SMOOTH : Graphics::POINT_ROUGH;
+#else
+	s.pointSize = 1;
+	s.pointStyle = Graphics::POINT_ROUGH;
 #endif
 	//get scissor status
 	s.scissor = (glIsEnabled(GL_SCISSOR_TEST) == GL_TRUE);
 	// Set the viewport to top-left corner
 	glViewport(0, 0, width, height);
 
-#if !defined(HAVE_GLES)
 	// Reset the projection matrix
 	glMatrixMode(GL_PROJECTION);
 	glLoadIdentity();
 	// Reset modelview matrix
 	glMatrixMode(GL_MODELVIEW);
 	glLoadIdentity();
-#endif
 
 	// Set pixel row alignment
 	glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
 	// subtract a few to give the engine some room.
 	glGetIntegerv(GL_MAX_MODELVIEW_STACK_DEPTH, &matrixLimit);
 	matrixLimit -= 5;
+#else
+	matrixLimit = 32; // no real limit
 #endif
 
 	return success;
 void Graphics::clear()
 {
 	glClear(GL_COLOR_BUFFER_BIT);
-#if !defined(HAVE_GLES)
 	glLoadIdentity();
-#endif
 }
 
 void Graphics::present()
 
 void Graphics::setColor(const Color &c)
 {
-#if !defined(HAVE_GLES)
 	glColor4ubv(&c.r);
-#endif
 }
 
 Color Graphics::getColor()
 	float c[4];
 #if !defined(HAVE_GLES)
 	glGetFloatv(GL_CURRENT_COLOR, c);
+#else
+	glesGetColorfv(c);
 #endif
 
 	Color t;
 	else if (mode == GL_COMBINE)
 		return COLOR_COMBINE;
 	else // mode == GL_REPLACE
+#endif
 		return COLOR_REPLACE;
-#endif
 }
 
 const Image::Filter &Graphics::getDefaultImageFilter() const
 	GLfloat c[4];
 #if !defined(HAVE_GLES)
 	glGetFloatv(GL_CURRENT_COLOR, c);
+#else
+	glesGetColorfv(c);
 #endif
 
 	Color *colors = new Color[2*count+2];
 	glVertexPointer(2, GL_FLOAT, 0, (const GLvoid *)overdraw);
 	glDrawArrays(GL_TRIANGLE_STRIP, 0, 2*count + 2 * int(!looping));
 	glDisableClientState(GL_COLOR_ARRAY);
+#endif
 	// "if GL_COLOR_ARRAY is enabled, the value of the current color is
 	// undefined after glDrawArrays executes"
 	glColor4fv(c);
-#endif
 
 	delete[] colors;
 }
 		GLfloat m[16];
 #if !defined(HAVE_GLES)
 		glGetFloatv(GL_MODELVIEW_MATRIX, m);
+#else
+		glesGetMatrixfv(m);
 #endif
 		float det  = m[0]*m[5]*m[10] + m[4]*m[9]*m[2] + m[8]*m[1]*m[6];
 		det       -= m[2]*m[5]*m[8]  + m[6]*m[9]*m[0] + m[10]*m[1]*m[4];
 {
 	if (userMatrices == matrixLimit)
 		throw Exception("Maximum stack depth reached.");
-#if !defined(HAVE_GLES)
 	glPushMatrix();
-#endif
 	++userMatrices;
 }
 
 {
 	if (userMatrices < 1)
 		throw Exception("Minimum stack depth reached. (More pops than pushes?)");
-#if !defined(HAVE_GLES)
 	glPopMatrix();
-#endif
 	--userMatrices;
 }
 
 void Graphics::rotate(float r)
 {
-#if !defined(HAVE_GLES)
 	glRotatef(LOVE_TODEG(r), 0, 0, 1);
-#endif
 }
 
 void Graphics::scale(float x, float y)
 {
-#if !defined(HAVE_GLES)
 	glScalef(x, y, 1);
-#endif
 }
 
 void Graphics::translate(float x, float y)
 {
-#if !defined(HAVE_GLES)
 	glTranslatef(x, y, 0);
-#endif
 }
 
 void Graphics::shear(float kx, float ky)
 {
 	Matrix t;
 	t.setShear(kx, ky);
-#if !defined(HAVE_GLES)
 	glMultMatrixf((const GLfloat *)t.getElements());
-#endif
 }
 
 void Graphics::drawTest(Image *image, float x, float y, float a, float sx, float sy, float ox, float oy)

File src/modules/graphics/opengl/Image.cpp

 
 #include "Image.h"
 
+#ifdef HAVE_GLES
+	#include "GLES.h"
+#endif
+
 // STD
 #include <cstring> // For memcpy
 
 {
 	bind();
 
-#if !defined(HAVE_GLES)
 	glPushMatrix();
 
 	glMultMatrixf((const GLfloat *)t.getElements());
 
+#if !defined(HAVE_GLES)
 	glEnableClientState(GL_VERTEX_ARRAY);
 	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
 	glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&v[0].x);
 	glDrawArrays(GL_QUADS, 0, 4);
 	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 	glDisableClientState(GL_VERTEX_ARRAY);
+#endif
 
 	glPopMatrix();
-#endif
 }
 
 bool Image::hasNpot()
 #if !defined(HAVE_GLES)
 	return GLEE_ARB_texture_non_power_of_two != 0;
 #else
-	return true;
+	return true; // for GLES2
 #endif
 }
 

File src/modules/graphics/opengl/ParticleSystem.cpp

 
 #ifdef HAVE_GLES
 	#include <GLES2/gl2.h>
+	#include "GLES.h"
 #else
 	#include "GLee.h"
 #endif
 {
 	if (sprite == 0) return;  // just in case of failure
 
+	glPushMatrix();
 #if !defined(HAVE_GLES)
-	glPushMatrix();
 	glPushAttrib(GL_CURRENT_BIT);
+#else
+	GLfloat c[4];
+	glesGetColorfv(c);
+#endif
 
 	Matrix t;
 	t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
 		p++;
 	}
 
+#if !defined(HAVE_GLES)
 	glPopAttrib();
+#else
+	glColor4fv(c);
+#endif
 	glPopMatrix();
-#endif
 }
 
 void ParticleSystem::update(float dt)

File src/modules/graphics/opengl/SpriteBatch.cpp

 #include "Quad.h"
 #include "VertexBuffer.h"
 
+#ifdef HAVE_GLES
+	#include "GLES.h"
+#endif
+
 namespace love
 {
 namespace graphics
 
 	static Matrix t;
 
-#if !defined(HAVE_GLES)
 	glPushMatrix();
 
 	t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
 	glMultMatrixf((const GLfloat *)t.getElements());
-#endif
 
 	image->bind();
 
 	glDisableClientState(GL_VERTEX_ARRAY);
 	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 	glDisableClientState(GL_COLOR_ARRAY);
+#endif
 
 	glPopMatrix();
-#endif
 }
 
 void SpriteBatch::addv(const vertex *v, int index)