Browse Source

Small graphics code cleanup

--HG--
branch : minor
Alex Szpakowski 7 years ago
parent
commit
050be14547

+ 1 - 1
src/modules/graphics/Image.cpp

@@ -94,7 +94,7 @@ void Image::init(PixelFormat fmt, int w, int h, const Settings &settings)
 
 
 	if (getMipmapCount() > 1)
 	if (getMipmapCount() > 1)
 		filter.mipmap = defaultMipmapFilter;
 		filter.mipmap = defaultMipmapFilter;
-	
+
 	initQuad();
 	initQuad();
 }
 }
 
 

+ 1 - 2
src/modules/graphics/opengl/Canvas.cpp

@@ -186,8 +186,7 @@ bool Canvas::loadVolatile()
 
 
 	// getMaxRenderbufferSamples will be 0 on systems that don't support
 	// getMaxRenderbufferSamples will be 0 on systems that don't support
 	// multisampled renderbuffers / don't export FBO multisample extensions.
 	// multisampled renderbuffers / don't export FBO multisample extensions.
-	actualSamples = getRequestedMSAA();
-	actualSamples = std::min(actualSamples, gl.getMaxRenderbufferSamples());
+	actualSamples = std::min(getRequestedMSAA(), gl.getMaxRenderbufferSamples());
 	actualSamples = std::max(actualSamples, 0);
 	actualSamples = std::max(actualSamples, 0);
 	actualSamples = actualSamples == 1 ? 0 : actualSamples;
 	actualSamples = actualSamples == 1 ? 0 : actualSamples;
 
 

+ 32 - 32
src/modules/graphics/opengl/Mesh.cpp

@@ -81,9 +81,22 @@ int Mesh::bindAttributeToShaderInput(int attributeindex, const std::string &inpu
 	vbo->unmap();
 	vbo->unmap();
 
 
 	gl.bindBuffer(BUFFER_VERTEX, (GLuint) vbo->getHandle());
 	gl.bindBuffer(BUFFER_VERTEX, (GLuint) vbo->getHandle());
+	
+	GLenum datatype = 0;
+	switch (format.type)
+	{
+	case DATA_BYTE:
+		datatype = GL_UNSIGNED_BYTE;
+		break;
+	case DATA_FLOAT:
+		datatype = GL_FLOAT;
+		break;
+	default:
+		datatype = 0;
+		break;
+	}
 
 
 	const void *gloffset = BUFFER_OFFSET(getAttributeOffset(attributeindex));
 	const void *gloffset = BUFFER_OFFSET(getAttributeOffset(attributeindex));
-	GLenum datatype = getGLDataType(format.type);
 	GLboolean normalized = (datatype == GL_UNSIGNED_BYTE);
 	GLboolean normalized = (datatype == GL_UNSIGNED_BYTE);
 
 
 	glVertexAttribPointer(attriblocation, format.components, datatype, normalized, (GLsizei) vertexStride, gloffset);
 	glVertexAttribPointer(attriblocation, format.components, datatype, normalized, (GLsizei) vertexStride, gloffset);
@@ -98,8 +111,24 @@ void Mesh::drawInternal(int start, int count, int instancecount, bool useindexbu
 	gl.useVertexAttribArrays(attribflags, instancedattribflags);
 	gl.useVertexAttribArrays(attribflags, instancedattribflags);
 	gl.bindTextureToUnit(texture, 0, false);
 	gl.bindTextureToUnit(texture, 0, false);
 	gl.prepareDraw();
 	gl.prepareDraw();
-
-	GLenum gldrawmode = getGLDrawMode(drawMode);
+	
+	GLenum gldrawmode = GL_TRIANGLES;
+	switch (drawMode)
+	{
+	case DRAWMODE_FAN:
+		gldrawmode = GL_TRIANGLE_FAN;
+		break;
+	case DRAWMODE_STRIP:
+		gldrawmode = GL_TRIANGLE_STRIP;
+		break;
+	case DRAWMODE_TRIANGLES:
+	default:
+		gldrawmode = GL_TRIANGLES;
+		break;
+	case DRAWMODE_POINTS:
+		gldrawmode = GL_POINTS;
+		break;
+	}
 
 
 	if (useindexbuffer)
 	if (useindexbuffer)
 	{
 	{
@@ -116,35 +145,6 @@ void Mesh::drawInternal(int start, int count, int instancecount, bool useindexbu
 	}
 	}
 }
 }
 
 
-GLenum Mesh::getGLDrawMode(DrawMode mode)
-{
-	switch (mode)
-	{
-	case DRAWMODE_FAN:
-		return GL_TRIANGLE_FAN;
-	case DRAWMODE_STRIP:
-		return GL_TRIANGLE_STRIP;
-	case DRAWMODE_TRIANGLES:
-	default:
-		return GL_TRIANGLES;
-	case DRAWMODE_POINTS:
-		return GL_POINTS;
-	}
-}
-
-GLenum Mesh::getGLDataType(DataType type)
-{
-	switch (type)
-	{
-	case DATA_BYTE:
-		return GL_UNSIGNED_BYTE;
-	case DATA_FLOAT:
-		return GL_FLOAT;
-	default:
-		return 0;
-	}
-}
-
 } // opengl
 } // opengl
 } // graphics
 } // graphics
 } // love
 } // love

+ 0 - 5
src/modules/graphics/opengl/Mesh.h

@@ -49,11 +49,6 @@ protected:
 
 
 	void drawInternal(int start, int count, int instancecount, bool useindexbuffer, uint32 attribflags, uint32 instancedattribflags) const override;
 	void drawInternal(int start, int count, int instancecount, bool useindexbuffer, uint32 attribflags, uint32 instancedattribflags) const override;
 
 
-private:
-
-	static GLenum getGLDrawMode(DrawMode mode);
-	static GLenum getGLDataType(DataType type);
-
 }; // Mesh
 }; // Mesh
 
 
 } // opengl
 } // opengl