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

Fixes issue with flickering framebuffers on iOS (and any platform where the
default framebuffer is not 0).

Adam Blake 13 лет назад
Родитель
Сommit
6d69b65f7d
3 измененных файлов с 15 добавлено и 2 удалено
  1. 9 1
      gameplay/src/FrameBuffer.cpp
  2. 4 0
      gameplay/src/FrameBuffer.h
  3. 2 1
      gameplay/src/Game.cpp

+ 9 - 1
gameplay/src/FrameBuffer.cpp

@@ -10,6 +10,7 @@ namespace gameplay
 
 static unsigned int __maxRenderTargets = 0;
 static std::vector<FrameBuffer*> __frameBuffers;
+static FrameBufferHandle __defaultHandle = 0;
 
 FrameBuffer::FrameBuffer(const char* id) :
     _id(id ? id : ""), _handle(0), _renderTargets(NULL), _depthStencilTarget(NULL)
@@ -41,6 +42,13 @@ FrameBuffer::~FrameBuffer()
     }
 }
 
+void FrameBuffer::initialize()
+{
+    GLint fbo;
+    glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fbo);
+    __defaultHandle = (FrameBufferHandle)fbo;
+}
+
 FrameBuffer* FrameBuffer::create(const char* id)
 {
     // Create GL FBO resource.
@@ -230,7 +238,7 @@ void FrameBuffer::bind()
 
 void FrameBuffer::bindDefault()
 {
-    GL_ASSERT( glBindFramebuffer(GL_FRAMEBUFFER, 0) );
+    GL_ASSERT( glBindFramebuffer(GL_FRAMEBUFFER, __defaultHandle) );
 }
 
 }

+ 4 - 0
gameplay/src/FrameBuffer.h

@@ -19,6 +19,8 @@ namespace gameplay
  */
 class FrameBuffer : public Ref
 {
+    friend class Game;
+
 public:
 
     /**
@@ -118,6 +120,8 @@ private:
      */
     ~FrameBuffer();
 
+    static void initialize();
+
     std::string _id;
     FrameBufferHandle _handle;
     RenderTarget** _renderTargets;

+ 2 - 1
gameplay/src/Game.cpp

@@ -3,6 +3,7 @@
 #include "Platform.h"
 #include "RenderState.h"
 #include "FileSystem.h"
+#include "FrameBuffer.h"
 
 // Extern global variables
 GLenum __gl_error_code = GL_NO_ERROR;
@@ -92,8 +93,8 @@ bool Game::startup()
         return false;
 
     setViewport(Rectangle(0.0f, 0.0f, (float)_width, (float)_height));
-
     RenderState::initialize();
+    FrameBuffer::initialize();
 
     _animationController = new AnimationController();
     _animationController->initialize();