Alex Szpakowski avatar Alex Szpakowski committed 13c480c

Only apply an AMD-specific hack when generating mipmaps on AMD GPUs

Comments (0)

Files changed (3)

src/modules/graphics/opengl/Image.cpp

 
 	if (hasNpot() && (GLEE_VERSION_3_0 || GLEE_ARB_framebuffer_object))
 	{
-		// AMD/ATI drivers have several bugs when generating mipmaps,
-		// re-uploading the entire base image seems to be required.
-		uploadTexture();
+		if (gl.getVendor() == OpenGL::VENDOR_ATI_AMD)
+		{
+			// AMD/ATI drivers have several bugs when generating mipmaps,
+			// re-uploading the entire base image seems to be required.
+			uploadTexture();
 
-		// More bugs: http://www.opengl.org/wiki/Common_Mistakes#Automatic_mipmap_generation
-		glEnable(GL_TEXTURE_2D);
+			// More bugs: http://www.opengl.org/wiki/Common_Mistakes#Automatic_mipmap_generation
+			glEnable(GL_TEXTURE_2D);
+		}
+
 		glGenerateMipmap(GL_TEXTURE_2D);
 	}
 	else

src/modules/graphics/opengl/OpenGL.cpp

 #include "Shader.h"
 #include "common/Exception.h"
 
-// STL
+// C++
 #include <algorithm>
 
+// C
+#include <cstring>
+
 namespace love
 {
 namespace graphics
 	: contextInitialized(false)
 	, maxAnisotropy(1.0f)
 	, maxTextureSize(0)
+	, vendor(VENDOR_UNKNOWN)
 	, state()
 {
 }
 	contextInitialized = false;
 }
 
+void OpenGL::initVendor()
+{
+	const char *vstr = (const char *) glGetString(GL_VENDOR);
+	if (!vstr)
+		return;
+
+	// http://feedback.wildfiregames.com/report/opengl/feature/GL_VENDOR
+	if (strstr(vstr, "ATI Technologies"))
+		vendor = VENDOR_ATI_AMD;
+	else if (strstr(vstr, "NVIDIA"))
+		vendor = VENDOR_NVIDIA;
+	else if (strstr(vstr, "Intel"))
+		vendor = VENDOR_INTEL;
+	else if (strstr(vstr, "Mesa"))
+		vendor = VENDOR_MESA_SOFT;
+	else if (strstr(vstr, "Apple Computer"))
+		vendor = VENDOR_APPLE;
+	else if (strstr(vstr, "Microsoft"))
+		vendor = VENDOR_MICROSOFT;
+	else
+		vendor = VENDOR_UNKNOWN;
+}
+
 void OpenGL::initOpenGLFunctions()
 {
 	// The functionality of the core and ARB VBOs are identical, so we can
 	return maxTextureSize;
 }
 
+OpenGL::Vendor OpenGL::getVendor() const
+{
+	return vendor;
+}
+
 // OpenGL class instance singleton.
 OpenGL gl;
 

src/modules/graphics/opengl/OpenGL.h

 {
 public:
 
+	// OpenGL GPU vendors.
+	enum Vendor
+	{
+		VENDOR_ATI_AMD,
+		VENDOR_NVIDIA,
+		VENDOR_INTEL,
+		VENDOR_MESA_SOFT, // Software renderer.
+		VENDOR_APPLE,     // Software renderer.
+		VENDOR_MICROSOFT, // Software renderer.
+		VENDOR_UNKNOWN
+	};
+
 	// A rectangle representing an OpenGL viewport or a scissor box.
 	struct Viewport
 	{
 	 **/
 	int getMaxTextureSize() const;
 
+	/**
+	 * Get the GPU vendor of this OpenGL context.
+	 **/
+	Vendor getVendor() const;
+
 private:
 
+	void initVendor();
 	void initOpenGLFunctions();
 	void initMaxValues();
 	void createDefaultTexture();
 	float maxAnisotropy;
 	int maxTextureSize;
 
+	Vendor vendor;
+
 	// Tracked OpenGL state.
 	struct
 	{
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.