Mesa (master): mesa: added _mesa_get_attachment_teximage() helpers

Brian Paul brianp at kemper.freedesktop.org
Tue Apr 5 06:53:39 PDT 2011


Module: Mesa
Branch: master
Commit: db0f9e701d59dcfcd3b50f4d245897692f27fec9
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=db0f9e701d59dcfcd3b50f4d245897692f27fec9

Author: Brian Paul <brianp at vmware.com>
Date:   Tue Apr  5 07:51:01 2011 -0600

mesa: added _mesa_get_attachment_teximage() helpers

---

 src/mesa/main/fbobject.c           |   10 ++++------
 src/mesa/main/fbobject.h           |   19 +++++++++++++++++++
 src/mesa/main/framebuffer.c        |    4 ++--
 src/mesa/main/teximage.c           |    2 +-
 src/mesa/main/texrender.c          |    5 +++--
 src/mesa/state_tracker/st_cb_fbo.c |    5 ++---
 6 files changed, 31 insertions(+), 14 deletions(-)

diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c
index 4eab3e1..f0065ad 100644
--- a/src/mesa/main/fbobject.c
+++ b/src/mesa/main/fbobject.c
@@ -335,7 +335,7 @@ _mesa_set_texture_attachment(struct gl_context *ctx,
    att->Zoffset = zoffset;
    att->Complete = GL_FALSE;
 
-   if (att->Texture->Image[att->CubeMapFace][att->TextureLevel]) {
+   if (_mesa_get_attachment_teximage(att)) {
       ctx->Driver.RenderTexture(ctx, fb, att);
    }
 
@@ -716,8 +716,8 @@ _mesa_test_framebuffer_completeness(struct gl_context *ctx,
       /* get width, height, format of the renderbuffer/texture
        */
       if (att->Type == GL_TEXTURE) {
-         const struct gl_texture_image *texImg
-            = att->Texture->Image[att->CubeMapFace][att->TextureLevel];
+         const struct gl_texture_image *texImg =
+            _mesa_get_attachment_teximage(att);
          minWidth = MIN2(minWidth, texImg->Width);
          maxWidth = MAX2(maxWidth, texImg->Width);
          minHeight = MIN2(minHeight, texImg->Height);
@@ -1496,9 +1496,7 @@ check_begin_texture_render(struct gl_context *ctx, struct gl_framebuffer *fb)
 
    for (i = 0; i < BUFFER_COUNT; i++) {
       struct gl_renderbuffer_attachment *att = fb->Attachment + i;
-      struct gl_texture_object *texObj = att->Texture;
-      if (texObj
-          && texObj->Image[att->CubeMapFace][att->TextureLevel]) {
+      if (att->Texture && _mesa_get_attachment_teximage(att)) {
          ctx->Driver.RenderTexture(ctx, fb, att);
       }
    }
diff --git a/src/mesa/main/fbobject.h b/src/mesa/main/fbobject.h
index 0e1c096..7eb2005 100644
--- a/src/mesa/main/fbobject.h
+++ b/src/mesa/main/fbobject.h
@@ -26,6 +26,7 @@
 #ifndef FBOBJECT_H
 #define FBOBJECT_H
 
+#include "compiler.h"
 #include "glheader.h"
 
 struct gl_context;
@@ -48,6 +49,24 @@ _mesa_get_attachment(struct gl_context *ctx, struct gl_framebuffer *fb,
                      GLenum attachment);
 
 
+/** Return the texture image for a renderbuffer attachment */
+static INLINE struct gl_texture_image *
+_mesa_get_attachment_teximage(struct gl_renderbuffer_attachment *att)
+{
+   assert(att->Type == GL_TEXTURE);
+   return att->Texture->Image[att->CubeMapFace][att->TextureLevel];
+}
+
+
+/** Return the (const) texture image for a renderbuffer attachment */
+static INLINE const struct gl_texture_image *
+_mesa_get_attachment_teximage_const(const struct gl_renderbuffer_attachment *att)
+{
+   assert(att->Type == GL_TEXTURE);
+   return att->Texture->Image[att->CubeMapFace][att->TextureLevel];
+}
+
+
 extern void
 _mesa_remove_attachment(struct gl_context *ctx,
                         struct gl_renderbuffer_attachment *att);
diff --git a/src/mesa/main/framebuffer.c b/src/mesa/main/framebuffer.c
index 430e013..4f0e6f5 100644
--- a/src/mesa/main/framebuffer.c
+++ b/src/mesa/main/framebuffer.c
@@ -1061,12 +1061,12 @@ _mesa_print_framebuffer(const struct gl_framebuffer *fb)
    for (i = 0; i < BUFFER_COUNT; i++) {
       const struct gl_renderbuffer_attachment *att = &fb->Attachment[i];
       if (att->Type == GL_TEXTURE) {
-         const struct gl_texture_image *texImage;
+         const struct gl_texture_image *texImage =
+            _mesa_get_attachment_teximage_const(att);
          fprintf(stderr,
                  "  %2d: Texture %u, level %u, face %u, slice %u, complete %d\n",
                  i, att->Texture->Name, att->TextureLevel, att->CubeMapFace,
                  att->Zoffset, att->Complete);
-         texImage = att->Texture->Image[att->CubeMapFace][att->TextureLevel];
          fprintf(stderr, "       Size: %u x %u x %u  Format %s\n",
                  texImage->Width, texImage->Height, texImage->Depth,
                  _mesa_get_format_name(texImage->TexFormat));
diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index 86927d3..6161eb4 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -2251,7 +2251,7 @@ check_rtt_cb(GLuint key, void *data, void *userData)
              att->Texture == texObj &&
              att->TextureLevel == level &&
              att->CubeMapFace == face) {
-            ASSERT(att->Texture->Image[att->CubeMapFace][att->TextureLevel]);
+            ASSERT(_mesa_get_attachment_teximage(att));
             /* Tell driver about the new renderbuffer texture */
             ctx->Driver.RenderTexture(ctx, ctx->DrawBuffer, att);
             /* Mark fb status as indeterminate to force re-validation */
diff --git a/src/mesa/main/texrender.c b/src/mesa/main/texrender.c
index 8cec24c..a7641a5 100644
--- a/src/mesa/main/texrender.c
+++ b/src/mesa/main/texrender.c
@@ -1,6 +1,7 @@
 
 #include "context.h"
 #include "colormac.h"
+#include "fbobject.h"
 #include "macros.h"
 #include "texfetch.h"
 #include "teximage.h"
@@ -525,7 +526,7 @@ wrap_texture(struct gl_context *ctx, struct gl_renderbuffer_attachment *att)
  * update the internal format info, etc.
  */
 static void
-update_wrapper(struct gl_context *ctx, const struct gl_renderbuffer_attachment *att)
+update_wrapper(struct gl_context *ctx, struct gl_renderbuffer_attachment *att)
 {
    struct texture_renderbuffer *trb
       = (struct texture_renderbuffer *) att->Renderbuffer;
@@ -533,7 +534,7 @@ update_wrapper(struct gl_context *ctx, const struct gl_renderbuffer_attachment *
    (void) ctx;
    ASSERT(trb);
 
-   trb->TexImage = att->Texture->Image[att->CubeMapFace][att->TextureLevel];
+   trb->TexImage = _mesa_get_attachment_teximage(att);
    ASSERT(trb->TexImage);
 
    trb->Store = _mesa_get_texel_store_func(trb->TexImage->TexFormat);
diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c
index 7ffee90..e632d81 100644
--- a/src/mesa/state_tracker/st_cb_fbo.c
+++ b/src/mesa/state_tracker/st_cb_fbo.c
@@ -353,7 +353,7 @@ st_render_texture(struct gl_context *ctx,
       return;
 
    /* get pointer to texture image we're rendeing to */
-   texImage = att->Texture->Image[att->CubeMapFace][att->TextureLevel];
+   texImage = _mesa_get_attachment_teximage(att);
 
    /* create new renderbuffer which wraps the texture image */
    rb = st_new_renderbuffer(ctx, 0);
@@ -471,8 +471,7 @@ st_validate_attachment(struct gl_context *ctx,
       return GL_FALSE;
 
    format = stObj->pt->format;
-   texFormat =
-      stObj->base.Image[att->CubeMapFace][att->TextureLevel]->TexFormat;
+   texFormat = _mesa_get_attachment_teximage_const(att)->TexFormat;
 
    /* If the encoding is sRGB and sRGB rendering cannot be enabled,
     * check for linear format support instead.



More information about the mesa-commit mailing list