[Mesa-dev] [PATCH] i965/hiz: Don't bind GL_DRAW_FRAMEBUFFER on GLES

Chad Versace chad.versace at linux.intel.com
Wed Jan 11 14:37:46 PST 2012


From: Neil Roberts <neil at linux.intel.com>

When using Mesa with a GLES API, calling _mesa_FramebufferRenderbuffer
with GL_DRAW_FRAMEBUFFER will report a 'user error' because
get_framebuffer_target validates that this enum from the framebuffer
blit extension is only used on GL. To work around it this patch makes
it use the GL_FRAMEBUFFER enum instead in that case.

[chad]: Make comments more concise. Change the if-condition to be
compatible with a core context, which may not advertise old extensions.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=43418
CC: Neil Roberts <neil at linux.intel.com>
Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
---
 src/mesa/drivers/dri/i965/gen6_hiz.c |   37 +++++++++++++++++++++++++++++----
 1 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/gen6_hiz.c b/src/mesa/drivers/dri/i965/gen6_hiz.c
index e282511..4428777 100644
--- a/src/mesa/drivers/dri/i965/gen6_hiz.c
+++ b/src/mesa/drivers/dri/i965/gen6_hiz.c
@@ -109,6 +109,27 @@ static const uint32_t gen6_hiz_meta_save =
 
       MESA_META_SELECT_FEEDBACK;
 
+static void
+gen6_hiz_get_framebuffer_enum(struct gl_context *ctx,
+                              GLenum *bind_enum,
+                              GLenum *get_enum)
+{
+   if (ctx->VersionMajor >= 3
+       || ctx->Extensions.EXT_framebuffer_blit) {
+      /* Different buffers may be bound to the read and draw framebuffers. Take
+       * care not to disrupt the readbuffer.
+       */
+      *bind_enum = GL_DRAW_FRAMEBUFFER;
+      *get_enum = GL_DRAW_FRAMEBUFFER_BINDING;
+   } else {
+      /* The enums GL_DRAW_FRAMEBUFFER and GL_READ_FRAMEBUFFER do not exist.
+       * The bound framebuffer is both the read and draw buffer.
+       */
+      *bind_enum = GL_FRAMEBUFFER;
+      *get_enum = GL_FRAMEBUFFER_BINDING;
+   }
+}
+
 /**
  * Initialize static data needed for HiZ operations.
  */
@@ -117,10 +138,13 @@ gen6_hiz_init(struct brw_context *brw)
 {
    struct gl_context *ctx = &brw->intel.ctx;
    struct brw_hiz_state *hiz = &brw->hiz;
+   GLenum fb_bind_enum, fb_get_enum;
 
    if (hiz->fbo != 0)
       return;
 
+   gen6_hiz_get_framebuffer_enum(ctx, &fb_bind_enum, &fb_get_enum);
+
    /* Create depthbuffer.
     *
     * Until glRenderbufferStorage is called, the renderbuffer hash table
@@ -139,8 +163,8 @@ gen6_hiz_init(struct brw_context *brw)
 
    /* Setup FBO. */
    _mesa_GenFramebuffersEXT(1, &hiz->fbo);
-   _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, hiz->fbo);
-   _mesa_FramebufferRenderbufferEXT(GL_DRAW_FRAMEBUFFER,
+   _mesa_BindFramebufferEXT(fb_bind_enum, hiz->fbo);
+   _mesa_FramebufferRenderbufferEXT(fb_bind_enum,
                                     GL_DEPTH_ATTACHMENT,
                                     GL_RENDERBUFFER,
                                     hiz->depth_rb->Name);
@@ -241,6 +265,7 @@ gen6_resolve_slice(struct intel_context *intel,
    struct gl_context *ctx = &intel->ctx;
    struct brw_context *brw = brw_context(ctx);
    struct brw_hiz_state *hiz = &brw->hiz;
+   GLenum fb_bind_enum, fb_get_enum;
 
    /* Do not recurse. */
    assert(!brw->hiz.op);
@@ -250,11 +275,13 @@ gen6_resolve_slice(struct intel_context *intel,
    assert(level <= mt->last_level);
    assert(layer < mt->level[level].depth);
 
+   gen6_hiz_get_framebuffer_enum(ctx, &fb_bind_enum, &fb_get_enum);
+
    /* Save state. */
    GLint save_drawbuffer;
    GLint save_renderbuffer;
    _mesa_meta_begin(ctx, gen6_hiz_meta_save);
-   _mesa_GetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &save_drawbuffer);
+   _mesa_GetIntegerv(fb_get_enum, &save_drawbuffer);
    _mesa_GetIntegerv(GL_RENDERBUFFER_BINDING, &save_renderbuffer);
 
    /* Initialize context data for HiZ operations. */
@@ -272,7 +299,7 @@ gen6_resolve_slice(struct intel_context *intel,
 
    /* Setup FBO. */
    gen6_hiz_setup_depth_buffer(brw, mt, level, layer);
-   _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, hiz->fbo);
+   _mesa_BindFramebufferEXT(fb_bind_enum, hiz->fbo);
 
 
    /* A rectangle primitive (3DPRIM_RECTLIST) consists of only three vertices.
@@ -316,7 +343,7 @@ gen6_resolve_slice(struct intel_context *intel,
     */
    gen6_hiz_teardown_depth_buffer(hiz->depth_rb);
    _mesa_BindRenderbufferEXT(GL_RENDERBUFFER, save_renderbuffer);
-   _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, save_drawbuffer);
+   _mesa_BindFramebufferEXT(fb_bind_enum, save_drawbuffer);
    _mesa_meta_end(ctx);
 }
 
-- 
1.7.7.4



More information about the mesa-dev mailing list