Просмотр исходного кода

fallback to OpenGL 2.0 on Windows if 3.0 is not supported

Andrew Karpushin 12 лет назад
Родитель
Сommit
a8af7c0c8c
2 измененных файлов с 48 добавлено и 3 удалено
  1. 40 2
      gameplay/src/PlatformWindows.cpp
  2. 8 1
      gameplay/src/Texture.cpp

+ 40 - 2
gameplay/src/PlatformWindows.cpp

@@ -558,8 +558,11 @@ bool createWindow(WindowCreationParams* params, HWND* hwnd, HDC* hdc)
     }
     style |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
 
-    // Adjust the window rectangle so the client size is the requested size.
-    AdjustWindowRectEx(&rect, style, FALSE, styleEx);
+	if( params )
+	{
+		// Adjust the window rectangle so the client size is the requested size.
+		AdjustWindowRectEx(&rect, style, FALSE, styleEx);
+	}
 
     // Create the native Windows window.
     *hwnd = CreateWindowEx(styleEx, L"gameplay", windowName.c_str(), style, 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, __hinstance, NULL);
@@ -649,6 +652,8 @@ bool initializeGL(WindowCreationParams* params)
         return false;
     }
 
+    if( wglChoosePixelFormatARB && wglCreateContextAttribsARB )
+    {
     // Choose pixel format using wglChoosePixelFormatARB, which allows us to specify
     // additional attributes such as multisampling.
     //
@@ -745,10 +750,43 @@ bool initializeGL(WindowCreationParams* params)
         GP_ERROR("Failed to make the window current.");
         return false;
     }
+    } else    // fallback to OpenGL 2.0 if wglChoosePixelFormatARB or wglCreateContextAttribsARB is NULL.
+	{
+        // Context is already here, just use it.
+        __hrc = tempContext;
+		__hwnd = hwnd;
+		__hdc = hdc;
+	}
 
     // Vertical sync.
     wglSwapIntervalEXT(__vsync ? 1 : 0);
 
+    // Some old graphics cards support EXT_framebuffer_object instead of ARB_framebuffer_object.
+    // Patch ARB_framebuffer_object functions to EXT_framebuffer_object ones since semantic is same.
+	if( !GLEW_ARB_framebuffer_object && GLEW_EXT_framebuffer_object )
+	{
+		glBindFramebuffer = glBindFramebufferEXT;
+		glBindRenderbuffer = glBindRenderbufferEXT;
+		glBlitFramebuffer = glBlitFramebufferEXT;
+		glCheckFramebufferStatus = glCheckFramebufferStatusEXT;
+		glDeleteFramebuffers = glDeleteFramebuffersEXT;
+		glDeleteRenderbuffers = glDeleteRenderbuffersEXT;
+		glFramebufferRenderbuffer = glFramebufferRenderbufferEXT;
+		glFramebufferTexture1D = glFramebufferTexture1DEXT;
+		glFramebufferTexture2D = glFramebufferTexture2DEXT;
+		glFramebufferTexture3D = glFramebufferTexture3DEXT;
+		glFramebufferTextureLayer = glFramebufferTextureLayerEXT;
+		glGenFramebuffers = glGenFramebuffersEXT;
+		glGenRenderbuffers = glGenRenderbuffersEXT;
+		glGenerateMipmap = glGenerateMipmapEXT;
+		glGetFramebufferAttachmentParameteriv = glGetFramebufferAttachmentParameterivEXT;
+		glGetRenderbufferParameteriv = glGetRenderbufferParameterivEXT;
+		glIsFramebuffer = glIsFramebufferEXT;
+		glIsRenderbuffer = glIsRenderbufferEXT;
+		glRenderbufferStorage = glRenderbufferStorageEXT;
+		glRenderbufferStorageMultisample = glRenderbufferStorageMultisampleEXT;
+	}
+
     return true;
 }
 

+ 8 - 1
gameplay/src/Texture.cpp

@@ -162,6 +162,12 @@ Texture* Texture::create(Format format, unsigned int width, unsigned int height,
     GL_ASSERT( glGenTextures(1, &textureId) );
     GL_ASSERT( glBindTexture(GL_TEXTURE_2D, textureId) );
     GL_ASSERT( glPixelStorei(GL_UNPACK_ALIGNMENT, 1) );
+#ifndef GL_ES_VERSION_2_0
+    // glGenerateMipmap is new in OpenGL 3.0. For OpenGL 2.0 we must fallback to use glTexParameteri 
+    // with GL_GENERATE_MIPMAP prior to actual texture creation (glTexImage2D)
+    if( generateMipmaps && glGenerateMipmap == NULL )
+        GL_ASSERT( glTexParameteri( GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE ) );
+#endif
     GL_ASSERT( glTexImage2D(GL_TEXTURE_2D, 0, (GLenum)format, width, height, 0, (GLenum)format, GL_UNSIGNED_BYTE, data) );
 
     // Set initial minification filter based on whether or not mipmaping was enabled.
@@ -839,7 +845,8 @@ void Texture::generateMipmaps()
     {
         GL_ASSERT( glBindTexture(GL_TEXTURE_2D, _handle) );
         GL_ASSERT( glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST) );
-        GL_ASSERT( glGenerateMipmap(GL_TEXTURE_2D) );
+        if( glGenerateMipmap != NULL )
+            GL_ASSERT( glGenerateMipmap(GL_TEXTURE_2D) );
 
         _mipmapped = true;
     }