[Mesa-dev] [PATCH 2/3] mesa: move gl_texture_image::Width/Height/DepthScale fields to swrast

Brian Paul brian.e.paul at gmail.com
Wed Sep 21 17:56:53 PDT 2011


From: Brian Paul <brianp at vmware.com>

These fields were only used for swrast so move them into
swrast_texture_image.
---
 src/mesa/main/mtypes.h        |    3 ---
 src/mesa/main/teximage.c      |   13 -------------
 src/mesa/swrast/s_context.h   |    2 +-
 src/mesa/swrast/s_fragprog.c  |    6 ++++--
 src/mesa/swrast/s_span.c      |    7 +++++--
 src/mesa/swrast/s_texfilter.c |   11 +++++++----
 src/mesa/swrast/s_texture.c   |   13 +++++++++++++
 7 files changed, 30 insertions(+), 25 deletions(-)

diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index a3f0deb..dc4dd07 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1254,9 +1254,6 @@ struct gl_texture_image
    GLuint HeightLog2;		/**< = log2(Height2) */
    GLuint DepthLog2;		/**< = log2(Depth2) */
    GLuint MaxLog2;		/**< = MAX(WidthLog2, HeightLog2) */
-   GLfloat WidthScale;		/**< used for mipmap LOD computation */
-   GLfloat HeightScale;		/**< used for mipmap LOD computation */
-   GLfloat DepthScale;		/**< used for mipmap LOD computation */
    GLboolean IsClientData;	/**< Data owned by client? */
 
    struct gl_texture_object *TexObject;  /**< Pointer back to parent object */
diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index 50e7b4c..4f7f2ed 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -1172,19 +1172,6 @@ _mesa_init_teximage_fields(struct gl_context *ctx, GLenum target,
       img->ImageOffsets[i] = i * width * height;
    }
 
-   /* Compute Width/Height/DepthScale for mipmap lod computation */
-   if (target == GL_TEXTURE_RECTANGLE_NV) {
-      /* scale = 1.0 since texture coords directly map to texels */
-      img->WidthScale = 1.0;
-      img->HeightScale = 1.0;
-      img->DepthScale = 1.0;
-   }
-   else {
-      img->WidthScale = (GLfloat) img->Width;
-      img->HeightScale = (GLfloat) img->Height;
-      img->DepthScale = (GLfloat) img->Depth;
-   }
-
    img->TexFormat = format;
 }
 
diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h
index 363115a..1e0bfc0 100644
--- a/src/mesa/swrast/s_context.h
+++ b/src/mesa/swrast/s_context.h
@@ -141,10 +141,10 @@ struct swrast_texture_image
 
    GLboolean _IsPowerOfTwo;  /**< Are all dimensions powers of two? */
 
-#if 0
    /** used for mipmap LOD computation */
    GLfloat WidthScale, HeightScale, DepthScale;
 
+#if 0
    GLubyte *Data;    /**< The actual texture data in malloc'd memory */
 
    GLint TexelSize;  /**< bytes per texel block */
diff --git a/src/mesa/swrast/s_fragprog.c b/src/mesa/swrast/s_fragprog.c
index b6bfeae..9513b1c 100644
--- a/src/mesa/swrast/s_fragprog.c
+++ b/src/mesa/swrast/s_fragprog.c
@@ -103,8 +103,10 @@ fetch_texel_deriv( struct gl_context *ctx, const GLfloat texcoord[4],
    if (texObj) {
       const struct gl_texture_image *texImg =
          texObj->Image[0][texObj->BaseLevel];
-      const GLfloat texW = (GLfloat) texImg->WidthScale;
-      const GLfloat texH = (GLfloat) texImg->HeightScale;
+      const struct swrast_texture_image *swImg =
+         swrast_texture_image_const(texImg);
+      const GLfloat texW = (GLfloat) swImg->WidthScale;
+      const GLfloat texH = (GLfloat) swImg->HeightScale;
       GLfloat lambda;
       GLfloat rgba[4];
 
diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c
index 16ff7ff..4631ff3 100644
--- a/src/mesa/swrast/s_span.c
+++ b/src/mesa/swrast/s_span.c
@@ -490,6 +490,9 @@ interpolate_texcoords(struct gl_context *ctx, SWspan *span)
 
          if (obj) {
             const struct gl_texture_image *img = obj->Image[0][obj->BaseLevel];
+            const struct swrast_texture_image *swImg =
+               swrast_texture_image_const(img);
+
             needLambda = (obj->Sampler.MinFilter != obj->Sampler.MagFilter)
                || ctx->FragmentProgram._Current;
             /* LOD is calculated directly in the ansiotropic filter, we can
@@ -499,8 +502,8 @@ interpolate_texcoords(struct gl_context *ctx, SWspan *span)
                 obj->Sampler.MinFilter == GL_LINEAR_MIPMAP_LINEAR) {
                needLambda = GL_FALSE;
             }
-            texW = img->WidthScale;
-            texH = img->HeightScale;
+            texW = swImg->WidthScale;
+            texH = swImg->HeightScale;
          }
          else {
             /* using a fragment program */
diff --git a/src/mesa/swrast/s_texfilter.c b/src/mesa/swrast/s_texfilter.c
index 262ad74..dd37619 100644
--- a/src/mesa/swrast/s_texfilter.c
+++ b/src/mesa/swrast/s_texfilter.c
@@ -1585,8 +1585,10 @@ sample_2d_ewa(struct gl_context *ctx,
    const struct gl_texture_image *img =	tObj->Image[0][level];
    const struct gl_texture_image *mostDetailedImage =
       tObj->Image[0][tObj->BaseLevel];
-   GLfloat tex_u=-0.5 + texcoord[0] * mostDetailedImage->WidthScale * scaling;
-   GLfloat tex_v=-0.5 + texcoord[1] * mostDetailedImage->HeightScale * scaling;
+   const struct swrast_texture_image *swImg =
+      swrast_texture_image_const(mostDetailedImage);
+   GLfloat tex_u=-0.5 + texcoord[0] * swImg->WidthScale * scaling;
+   GLfloat tex_v=-0.5 + texcoord[1] * swImg->HeightScale * scaling;
 
    GLfloat ux = dudx * scaling;
    GLfloat vx = dvdx * scaling;
@@ -1793,6 +1795,7 @@ sample_lambda_2d_aniso(struct gl_context *ctx,
                        const GLfloat lambda_iso[], GLfloat rgba[][4])
 {
    const struct gl_texture_image *tImg = tObj->Image[0][tObj->BaseLevel];
+   const struct swrast_texture_image *swImg = swrast_texture_image_const(tImg);
    const GLfloat maxEccentricity =
       tObj->Sampler.MaxAnisotropy * tObj->Sampler.MaxAnisotropy;
    
@@ -1835,8 +1838,8 @@ sample_lambda_2d_aniso(struct gl_context *ctx,
       create_filter_table();
    }
 
-   texW = tImg->WidthScale;
-   texH = tImg->HeightScale;
+   texW = swImg->WidthScale;
+   texH = swImg->HeightScale;
 
    for (i = 0; i < n; i++) {
       const GLfloat invQ = (q == 0.0F) ? 1.0F : (1.0F / q);
diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c
index 14ee0eb..1dcb08c 100644
--- a/src/mesa/swrast/s_texture.c
+++ b/src/mesa/swrast/s_texture.c
@@ -85,6 +85,19 @@ _swrast_alloc_texture_image_buffer(struct gl_context *ctx,
    else
       swImg->_IsPowerOfTwo = GL_FALSE;
 
+   /* Compute Width/Height/DepthScale for mipmap lod computation */
+   if (texImage->TexObject->Target == GL_TEXTURE_RECTANGLE_NV) {
+      /* scale = 1.0 since texture coords directly map to texels */
+      swImg->WidthScale = 1.0;
+      swImg->HeightScale = 1.0;
+      swImg->DepthScale = 1.0;
+   }
+   else {
+      swImg->WidthScale = (GLfloat) texImage->Width;
+      swImg->HeightScale = (GLfloat) texImage->Height;
+      swImg->DepthScale = (GLfloat) texImage->Depth;
+   }
+
    return texImage->Data != NULL;
 }
 
-- 
1.7.3.4



More information about the mesa-dev mailing list