On 02/13/2012 09:47 AM, Jose Fonseca wrote:


----- Original Message -----
Previously, this function only handled 2D textures.

The fallback texture is used when we try to sample from an incomplete
texture object.  GLSL says sampling an incomplete texture should
return
(0,0,0,1).
---
  src/mesa/main/mtypes.h   |    2 +-
  src/mesa/main/shared.c   |    8 ++-
  src/mesa/main/texobj.c   |  118
  ++++++++++++++++++++++++++++++++++++---------
  src/mesa/main/texobj.h   |    4 +-
  src/mesa/main/texstate.c |   10 +++-
  5 files changed, 110 insertions(+), 32 deletions(-)

diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 5ef97c8..9200f3f 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2483,7 +2483,7 @@ struct gl_shared_state
     struct gl_texture_object *DefaultTex[NUM_TEXTURE_TARGETS];

     /** Fallback texture used when a bound texture is incomplete */
-   struct gl_texture_object *FallbackTex;
+   struct gl_texture_object *FallbackTex[NUM_TEXTURE_TARGETS];

     /**
      * \name Thread safety and statechange notification for texture
diff --git a/src/mesa/main/shared.c b/src/mesa/main/shared.c
index c07ce82..2269476 100644
--- a/src/mesa/main/shared.c
+++ b/src/mesa/main/shared.c
@@ -307,9 +307,11 @@ free_shared_state(struct gl_context *ctx, struct
gl_shared_state *shared)
  {
     GLuint i;

-   /* Free the dummy/fallback texture object */
-   if (shared->FallbackTex)
-      ctx->Driver.DeleteTexture(ctx, shared->FallbackTex);
+   /* Free the dummy/fallback texture objects */
+   for (i = 0; i<  NUM_TEXTURE_TARGETS; i++) {
+      if (shared->FallbackTex[i])
+         ctx->Driver.DeleteTexture(ctx, shared->FallbackTex[i]);
+   }

     /*
      * Free display lists
diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index 1b61d3a..93a4cf6 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -759,59 +759,129 @@ _mesa_dirty_texobj(struct gl_context *ctx,
struct gl_texture_object *texObj,


  /**
- * Return pointer to a default/fallback texture.
- * The texture is a 2D 8x8 RGBA texture with all texels = (0,0,0,1).
- * That's the value a sampler should get when sampling from an
+ * Return pointer to a default/fallback texture of the given
type/target.
+ * The texture is an RGBA texture with all texels = (0,0,0,1).
+ * That's the value a GLSL sampler should get when sampling from an
   * incomplete texture.
   */
  struct gl_texture_object *
-_mesa_get_fallback_texture(struct gl_context *ctx)
+_mesa_get_fallback_texture(struct gl_context *ctx, gl_texture_index
tex)
  {
-   if (!ctx->Shared->FallbackTex) {
+   if (!ctx->Shared->FallbackTex[tex]) {
        /* create fallback texture now */
-      static GLubyte texels[8 * 8][4];
+      const GLsizei width = 4, height = 4, depth = 4;
+      GLubyte texels[width * height * depth][4];

I'm not sure this builds correctly on MSVC. You might need a #define.

I thought MSVC handled the case like this where the dimensions are const. I can change it though.


Why 8x8 or 4x4, and not 1x1?

Probably no good reason. In the past I've occasionally ran into glitches with 1x1 textures (esp w/ compressed textures) so in test programs (and here) I generally try to avoid them to be extra safe. It would simplify the code to just use 1x1 though...


Otherwise looks good.

Thanks.  I wrote this patch 6 weeks ago and had forgot about it.

-Brian
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to