diff mbox

[Branch,~glmark2-dev/glmark2/trunk] Rev 272: SceneDesktop: RenderObject::init() was creating a zero-sized texture image and

Message ID 20130521221814.12276.49982.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Jesse Barker May 21, 2013, 10:18 p.m. UTC
------------------------------------------------------------
revno: 272
committer: Jesse Barker <jesse.barker@linaro.org>
branch nick: trunk
timestamp: Tue 2013-05-21 15:15:05 -0700
message:
  SceneDesktop: RenderObject::init() was creating a zero-sized texture image and
  attaching it to a framebuffer object.  This is not illegal, but it does violate
  the spec rules for framebuffer completeness.  Some implementations are doing
  the check immediately at attach time rather than deferring to draw time, which
  is not really "correct", but we can live with it.  Defer the image
  (re)creation to resize time and (re)attach it to the framebuffer object then.
modified:
  src/scene-desktop.cpp


--
lp:glmark2
https://code.launchpad.net/~glmark2-dev/glmark2/trunk

You are subscribed to branch lp:glmark2.
To unsubscribe from this branch go to https://code.launchpad.net/~glmark2-dev/glmark2/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'src/scene-desktop.cpp'
--- src/scene-desktop.cpp	2012-08-15 09:45:06 +0000
+++ src/scene-desktop.cpp	2013-05-21 22:15:05 +0000
@@ -121,14 +121,28 @@ 
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size_.x(), size_.y(), 0,
-                     GL_RGBA, GL_UNSIGNED_BYTE, 0);
 
         /* Create a FBO */
         glGenFramebuffers(1, &fbo_);
         glBindFramebuffer(GL_FRAMEBUFFER, fbo_);
-        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
-                               GL_TEXTURE_2D, texture_, 0);
+
+        /*
+         * Only create the texture image and attach it to the framebuffer
+         * if the size has been set.  Framebuffer completeness depends
+         * upon non-zero width and height images, and some implementations
+         * are overly aggressive in checking at attachment time rather than
+         * at draw time.
+         */ 
+        if (size_.x() != 0 && size_.y() != 0) {
+            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size_.x(), size_.y(), 0,
+                         GL_RGBA, GL_UNSIGNED_BYTE, 0);
+            glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+                                   GL_TEXTURE_2D, texture_, 0);
+            unsigned int status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+            if (status != GL_FRAMEBUFFER_COMPLETE) {
+                Log::error("RenderObject::init: glCheckFramebufferStatus failed (0x%x)\n", status);
+            }
+        }
 
         glBindFramebuffer(GL_FRAMEBUFFER, 0);
 
@@ -182,9 +196,17 @@ 
         /* Recreate the backing texture with correct size */
         if (size_.x() != size.x() || size_.y() != size.y()) {
             size_ = size;
+            /* If we're resizing the texture, we need to tell the framebuffer*/
             glBindTexture(GL_TEXTURE_2D, texture_);
             glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size_.x(), size_.y(), 0,
                          GL_RGBA, GL_UNSIGNED_BYTE, 0);
+            glBindFramebuffer(GL_FRAMEBUFFER, fbo_);
+            glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+                                   GL_TEXTURE_2D, texture_, 0);
+            unsigned int status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+            if (status != GL_FRAMEBUFFER_COMPLETE) {
+                Log::error("RenderObject::size: glCheckFramebufferStatus failed (0x%x)\n", status);
+            }
             texture_contents_invalid_ = true;
         }