mesa: replace gl_texture_format with gl_format
[mesa.git] / src / mesa / main / texrender.c
index 49de6f5b8abd4ea6a468991f4f16b7fff72543cf..81bb1d40ffdfed49647a1f6fdbb6b2b6fe72ee5d 100644 (file)
@@ -397,6 +397,14 @@ texture_put_mono_values(GLcontext *ctx, struct gl_renderbuffer *rb,
 }
 
 
+static void
+store_nop(struct gl_texture_image *texImage,
+          GLint col, GLint row, GLint img,
+          const void *texel)
+{
+}
+
+
 static void
 delete_texture_wrapper(struct gl_renderbuffer *rb)
 {
@@ -454,6 +462,7 @@ update_wrapper(GLcontext *ctx, const struct gl_renderbuffer_attachment *att)
 {
    struct texture_renderbuffer *trb
       = (struct texture_renderbuffer *) att->Renderbuffer;
+   gl_format texFormat;
 
    (void) ctx;
    ASSERT(trb);
@@ -461,8 +470,11 @@ update_wrapper(GLcontext *ctx, const struct gl_renderbuffer_attachment *att)
    trb->TexImage = att->Texture->Image[att->CubeMapFace][att->TextureLevel];
    ASSERT(trb->TexImage);
 
-   trb->Store = trb->TexImage->TexFormat->StoreTexel;
-   ASSERT(trb->Store);
+   trb->Store = _mesa_get_texel_store_func(trb->TexImage->TexFormat);
+   if (!trb->Store) {
+      /* we'll never draw into some textures (compressed formats) */
+      trb->Store = store_nop;
+   }
 
    if (att->Texture->Target == GL_TEXTURE_1D_ARRAY_EXT) {
       trb->Yoffset = att->Zoffset;
@@ -473,19 +485,21 @@ update_wrapper(GLcontext *ctx, const struct gl_renderbuffer_attachment *att)
       trb->Zoffset = att->Zoffset;
    }
 
+   texFormat = trb->TexImage->TexFormat;
+
    trb->Base.Width = trb->TexImage->Width;
    trb->Base.Height = trb->TexImage->Height;
    trb->Base.InternalFormat = trb->TexImage->InternalFormat;
    /* XXX may need more special cases here */
-   if (trb->TexImage->TexFormat->MesaFormat == MESA_FORMAT_Z24_S8) {
+   if (trb->TexImage->TexFormat == MESA_FORMAT_Z24_S8) {
       trb->Base._ActualFormat = GL_DEPTH24_STENCIL8_EXT;
       trb->Base.DataType = GL_UNSIGNED_INT_24_8_EXT;
    }
-   else if (trb->TexImage->TexFormat->MesaFormat == MESA_FORMAT_Z16) {
+   else if (trb->TexImage->TexFormat == MESA_FORMAT_Z16) {
       trb->Base._ActualFormat = GL_DEPTH_COMPONENT;
       trb->Base.DataType = GL_UNSIGNED_SHORT;
    }
-   else if (trb->TexImage->TexFormat->MesaFormat == MESA_FORMAT_Z32) {
+   else if (trb->TexImage->TexFormat == MESA_FORMAT_Z32) {
       trb->Base._ActualFormat = GL_DEPTH_COMPONENT;
       trb->Base.DataType = GL_UNSIGNED_INT;
    }
@@ -493,20 +507,15 @@ update_wrapper(GLcontext *ctx, const struct gl_renderbuffer_attachment *att)
       trb->Base._ActualFormat = trb->TexImage->InternalFormat;
       trb->Base.DataType = CHAN_TYPE;
    }
-   trb->Base._BaseFormat = trb->TexImage->TexFormat->BaseFormat;
-#if 0
-   /* fix/avoid this assertion someday */
-   ASSERT(trb->Base._BaseFormat == GL_RGB ||
-          trb->Base._BaseFormat == GL_RGBA ||
-          trb->Base._BaseFormat == GL_DEPTH_COMPONENT);
-#endif
+   trb->Base._BaseFormat = trb->TexImage->_BaseFormat;
    trb->Base.Data = trb->TexImage->Data;
 
-   trb->Base.RedBits = trb->TexImage->TexFormat->RedBits;
-   trb->Base.GreenBits = trb->TexImage->TexFormat->GreenBits;
-   trb->Base.BlueBits = trb->TexImage->TexFormat->BlueBits;
-   trb->Base.AlphaBits = trb->TexImage->TexFormat->AlphaBits;
-   trb->Base.DepthBits = trb->TexImage->TexFormat->DepthBits;
+   trb->Base.RedBits = _mesa_get_format_bits(texFormat, GL_TEXTURE_RED_SIZE);
+   trb->Base.GreenBits = _mesa_get_format_bits(texFormat, GL_TEXTURE_GREEN_SIZE);
+   trb->Base.BlueBits = _mesa_get_format_bits(texFormat, GL_TEXTURE_BLUE_SIZE);
+   trb->Base.AlphaBits = _mesa_get_format_bits(texFormat, GL_TEXTURE_ALPHA_SIZE);
+   trb->Base.DepthBits = _mesa_get_format_bits(texFormat, GL_TEXTURE_DEPTH_SIZE_ARB);
+   trb->Base.StencilBits = _mesa_get_format_bits(texFormat, GL_TEXTURE_STENCIL_SIZE_EXT);
 }