DEADSOFTWARE

rebuild the FBO from scratch when RBO is not supported
authorfgsfds <pvt.fgsfds@gmail.com>
Tue, 25 Feb 2020 16:09:28 +0000 (19:09 +0300)
committerfgsfds <pvt.fgsfds@gmail.com>
Tue, 25 Feb 2020 16:09:28 +0000 (19:09 +0300)
src/engine/e_graphics.pas

index d9761c13e02a1108c460c82896f7c7beca4e6687..af999b19d4d3efb3373fd9ee9042b8395cd287fc 100644 (file)
@@ -201,6 +201,7 @@ var
   //e_SavedTextures: array of TSavedTexture;
   e_FBO: GLuint = 0;
   e_RBO: GLuint = 0;
+  e_RBOSupported: Boolean = True;
   e_Frame: GLuint = 0;
   e_FrameW: Integer = -1;
   e_FrameH: Integer = -1;
@@ -440,27 +441,29 @@ begin
 
   glBindFramebuffer(GL_FRAMEBUFFER, e_FBO);
   glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, e_Frame, 0);
-
-{$IFNDEF USE_GLES1}
-  glGenRenderbuffers(1, @e_RBO);
-  glBindRenderbuffer(GL_RENDERBUFFER, e_RBO);
-  glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, Width, Height);
-  glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, e_RBO);
   if glCheckFramebufferStatus(GL_FRAMEBUFFER) <> GL_FRAMEBUFFER_COMPLETE then
   begin
-    e_LogWriteln('GL: can''t construct framebuffer with depth+stencil attachment');
-    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0);
-    glDeleteRenderbuffers(1, @e_RBO); e_RBO := 0;
+    e_LogWriteln('GL: can''t construct framebuffer with color attachment');
+    DestroyFramebuffer;
     Exit;
   end;
-{$ENDIF}
 
-  if glCheckFramebufferStatus(GL_FRAMEBUFFER) <> GL_FRAMEBUFFER_COMPLETE then
+{$IFNDEF USE_GLES1}
+  if e_RBOSupported then
   begin
-    e_LogWriteln('GL: can''t construct framebuffer with color attachment');
-    DestroyFramebuffer;
-    Exit;
+    glGenRenderbuffers(1, @e_RBO);
+    glBindRenderbuffer(GL_RENDERBUFFER, e_RBO);
+    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, Width, Height);
+    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, e_RBO);
+    if glCheckFramebufferStatus(GL_FRAMEBUFFER) <> GL_FRAMEBUFFER_COMPLETE then
+    begin
+      e_LogWriteln('GL: can''t construct framebuffer with depth+stencil attachment, trying without');
+      e_RBOSupported := False;
+      Result := e_ResizeFramebuffer(Width, Height);
+      Exit;
+    end;
   end;
+{$ENDIF}
 
   Result := True;
 end;