Commits

Alex Szpakowski committed fec8fb5

Added limited OpenGL ES 2.0 detection

Comments (0)

Files changed (9)

src/modules/graphics/opengl/Canvas.cpp

 	{
 		Context *ctx = getContext();
 
+		// TODO: conditionals for ES2
+
 		// get currently bound fbo to reset to it later
 		GLint current_fbo;
 		glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &current_fbo);
 {
 	if (!strategy)
 	{
-		if (GLEW_VERSION_3_0 || GLEW_ARB_framebuffer_object)
+		if (GLEW_ES_VERSION_2_0 || GLEW_VERSION_3_0 || GLEW_ARB_framebuffer_object)
 			strategy = &strategyCore;
 		else if (GLEW_EXT_framebuffer_object && GLEW_EXT_packed_depth_stencil)
 			strategy = &strategyPackedEXT;

src/modules/graphics/opengl/Context.cpp

 	// The functionality of the core and ARB VBOs are identical, so we can
 	// assign the pointers of the ARB functions to the names of the core
 	// functions, if the latter isn't supported but the former is.
-	if (!GLEW_VERSION_1_5 && GLEW_ARB_vertex_buffer_object)
+	if (!(GLEW_ES_VERSION_2_0 || GLEW_VERSION_1_5) && GLEW_ARB_vertex_buffer_object)
 	{
 		glBindBuffer = glBindBufferARB;
 		glBufferData = glBufferDataARB;
 		glUnmapBuffer = glUnmapBufferARB;
 	}
 
+	// Similar deal with glActiveTexture
+	if (!(GLEW_ES_VERSION_2_0 || GLEW_VERSION_1_3) && GLEW_ARB_multitexture)
+		glActiveTexture = glActiveTextureARB;
+
 	extensionsInitialized = true;
 }
 
 	state.textureUnits.clear();
 
 	// initialize multiple texture unit support, if available
-	if (GLEW_VERSION_1_3 || GLEW_ARB_multitexture)
+	if (GLEW_ES_VERSION_2_0 || GLEW_VERSION_1_3 || GLEW_ARB_multitexture)
 	{
 		GLint maxtextureunits;
 		glGetIntegerv(GL_MAX_TEXTURE_UNITS, &maxtextureunits);
 
 		// shaders/GL2.0 added "Texture Image Units." Total max texture units is the greater of the two
-		if (GLEW_VERSION_2_0 || GLEW_ARB_vertex_shader)
+		if (GLEW_ES_VERSION_2_0 || GLEW_VERSION_2_0 || GLEW_ARB_vertex_shader)
 		{
 			GLint maxtextureimageunits;
 			glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxtextureimageunits);
 		// retrieve currently bound textures for each texture unit
 		for (size_t i = 0; i < state.textureUnits.size(); ++i)
 		{
-			if (GLEW_VERSION_1_3)
-				glActiveTexture(GL_TEXTURE0 + i);
-			else
-				glActiveTextureARB(GL_TEXTURE0 + i);
-
+			glActiveTexture(GL_TEXTURE0 + i);
 			glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint *) &state.textureUnits[i]);
 		}
 
-		if (GLEW_VERSION_1_3)
-			glActiveTexture(curgltextureunit);
-		else
-			glActiveTextureARB(curgltextureunit);
+		glActiveTexture(curgltextureunit);
 	}
 	else
 	{
 
 	// get the maximum point size
 	GLfloat pointsizerange[2];
-	glGetFloatv(GLEW_VERSION_1_2 ? GL_ALIASED_POINT_SIZE_RANGE : GL_POINT_SIZE_RANGE, pointsizerange);
+	if (GLEW_ES_VERSION_2_0 || GLEW_VERSION_1_2)
+		glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, pointsizerange);
+	else
+		glGetFloatv(GL_POINT_SIZE_RANGE, pointsizerange);
 	state.maxPointSize = pointsizerange[1];
 }
 
 
 bool Context::isGenericVertexAttrib(unsigned int attrib)
 {
-	return attrib > ATTRIB_COLOR; // TODO: check for ES2
+	return GLEW_ES_VERSION_2_0 || attrib > ATTRIB_COLOR;
 }
 
 void Context::useVertexAttribArray(unsigned int attrib, bool use)
 void Context::setPointSize(float size)
 {
 	state.pointSize = size;
-	glPointSize((GLfloat) size);
+
+	// GLES2 can only set the point size with gl_PointSize in shaders
+	if (!GLEW_ES_VERSION_2_0)
+		glPointSize((GLfloat) size);
 }
 
 float Context::getPointSize()
 
 	if (textureunit != state.curTextureUnit)
 	{
-		if (GLEW_VERSION_1_3)
+		if (GLEW_ES_VERSION_2_0 || GLEW_VERSION_1_3 || GLEW_ARB_multitexture)
 			glActiveTexture(GL_TEXTURE0 + textureunit);
-		else if (GLEW_ARB_multitexture)
-			glActiveTextureARB(GL_TEXTURE0 + textureunit);
 		else
 			throw love::Exception("Multitexturing not supported.");
 	}

src/modules/graphics/opengl/Font.cpp

 	{
 		glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
 
-		if (GLEW_VERSION_3_0 || GLEW_ARB_framebuffer_object)
+		if (GLEW_ES_VERSION_2_0 || GLEW_VERSION_3_0 || GLEW_ARB_framebuffer_object)
 			glGenerateMipmap(GL_TEXTURE_2D);
 		else if (GLEW_EXT_framebuffer_object)
 			glGenerateMipmapEXT(GL_TEXTURE_2D);

src/modules/graphics/opengl/Graphics.cpp

 	glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
 
 	// Auto-generated mipmaps should be the best quality possible
-	if (GLEW_VERSION_1_4 || GLEW_SGIS_generate_mipmap)
+	if (GLEW_ES_VERSION_2_0 || GLEW_VERSION_1_4 || GLEW_SGIS_generate_mipmap)
 		glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST);
 
 	// Enable textures
 
 void Graphics::setBlendMode(Graphics::BlendMode mode)
 {
-	if (GLEW_VERSION_1_4 || GLEW_ARB_imaging)
+	if (GLEW_ES_VERSION_2_0 || GLEW_VERSION_1_4 || GLEW_ARB_imaging)
 	{
 		if (mode == BLEND_SUBTRACTIVE)
 			glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);

src/modules/graphics/opengl/Image.cpp

 	{
 		glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
 
-		if (GLEW_VERSION_3_0 || GLEW_ARB_framebuffer_object)
+		if (GLEW_ES_VERSION_2_0 || GLEW_VERSION_3_0 || GLEW_ARB_framebuffer_object)
 			glGenerateMipmap(GL_TEXTURE_2D);
 		else if (GLEW_EXT_framebuffer_object)
 			glGenerateMipmapEXT(GL_TEXTURE_2D);
 
 bool Image::hasNpot()
 {
-	return GLEW_VERSION_2_0 || GLEW_ARB_texture_non_power_of_two;
+	return GLEW_ES_VERSION_2_0 || GLEW_VERSION_2_0 || GLEW_ARB_texture_non_power_of_two;
 }
 
 bool Image::hasMipmapSupport()
 {
-	return (GLEW_VERSION_1_4 || GLEW_SGIS_generate_mipmap) != 0;
+	return GLEW_ES_VERSION_2_0 || GLEW_VERSION_1_4 || GLEW_SGIS_generate_mipmap;
 }
 
 bool Image::hasMipmapSharpnessSupport()

src/modules/graphics/opengl/Quad.cpp

 
 void Quad::refresh(const Viewport &v, float sw, float sh)
 {
-	if (!GLEW_ARB_texture_non_power_of_two)
+	if (!(GLEW_ES_VERSION_2_0 || GLEW_VERSION_2_0 || GLEW_ARB_texture_non_power_of_two))
 	{
 		sw = next_p2(sw);
 		sh = next_p2(sh);

src/modules/graphics/opengl/Shader.cpp

 
 bool Shader::isSupported()
 {
-	return GLEW_VERSION_2_0 && getGLSLVersion() >= "1.2";
+	return GLEW_ES_VERSION_2_0 || (GLEW_VERSION_2_0 && getGLSLVersion() >= "1.2");
 }
 
 } // opengl

src/modules/graphics/opengl/VertexBuffer.cpp

 	, is_mapped(false)
 	, is_dirty(true)
 {
-	if (!(GLEW_VERSION_1_5 || GLEW_ARB_vertex_buffer_object))
+	if (!(GLEW_ES_VERSION_2_0 || GLEW_VERSION_1_5 || GLEW_ARB_vertex_buffer_object))
 		throw love::Exception("Not supported");
 
 	bool ok = load(false);

src/modules/graphics/opengl/wrap_Graphics.cpp

 				supported = false;
 			break;
 		case Graphics::SUPPORT_SUBTRACTIVE:
-			if (!((GLEW_VERSION_1_4 || GLEW_ARB_imaging) || (GLEW_EXT_blend_minmax && GLEW_EXT_blend_subtract)))
+			if (!((GLEW_ES_VERSION_2_0 || GLEW_VERSION_1_4 || GLEW_ARB_imaging) || (GLEW_EXT_blend_minmax && GLEW_EXT_blend_subtract)))
 				supported = false;
 			break;
 		case Graphics::SUPPORT_MIPMAP: