initial lod/mipmap texture supported
authorBrian <brian@i915.localnet.net>
Wed, 8 Aug 2007 22:09:13 +0000 (16:09 -0600)
committerBrian <brian@i915.localnet.net>
Wed, 8 Aug 2007 22:10:40 +0000 (16:10 -0600)
src/mesa/pipe/softpipe/sp_quad_fs.c
src/mesa/pipe/softpipe/sp_tex_sample.c
src/mesa/pipe/tgsi/core/tgsi_exec.h

index e5ab0ebc1667ec2769859f623dfc5041f333d546..b68d0f95ac91c032b6647ab6a14b79bab66e5c09 100644 (file)
@@ -325,6 +325,7 @@ static void shade_begin(struct quad_stage *qs)
       /* init cache info here */
       qss->samplers[i].cache_x =
       qss->samplers[i].cache_y = -1;
+      qss->samplers[i].cache_level = -1;
    }
 
    if (qs->next)
index 7f8bf0d99c64ff86b5bb2ff35c2aa430d1f92aec..062d61dea455a4b947f24204b88fd97d4c2fe9fc 100644 (file)
@@ -447,6 +447,22 @@ sp_get_sample_1d(struct tgsi_sampler *sampler,
    }
 }
 
+static GLuint
+choose_mipmap_level(struct tgsi_sampler *sampler, GLfloat lambda)
+{
+   if (sampler->state->min_filter == sampler->state->mag_filter) {
+      assert(sampler->state->min_filter == PIPE_TEX_FILTER_LINEAR ||
+            sampler->state->min_filter == PIPE_TEX_FILTER_NEAREST);
+      return 0;
+   }
+   else {
+      GLint level = (int) lambda;
+      level = CLAMP(level, sampler->texture->first_level,
+                   sampler->texture->last_level);
+      return level;
+   }
+}
+
 
 /**
  * Called via tgsi_sampler::get_sample()
@@ -465,14 +481,22 @@ sp_get_sample_2d(struct tgsi_sampler *sampler,
                  const GLfloat strq[4], GLfloat lambda, GLfloat rgba[4])
 {
    struct pipe_context *pipe = (struct pipe_context *) sampler->pipe;
-   struct pipe_surface *ps
-      = pipe->get_tex_surface(pipe, sampler->texture, 0, 0, 0);
+   GLuint filter;
+   GLint level0;
 
-   switch (sampler->state->min_filter) {
+   if (lambda < 0.0)
+      filter = sampler->state->mag_filter;
+   else
+      filter = sampler->state->min_filter;
+
+   level0 = choose_mipmap_level(sampler, lambda);
+
+   switch (filter) {
    case PIPE_TEX_FILTER_NEAREST:
+   case PIPE_TEX_FILTER_NEAREST_MIPMAP_NEAREST:
       {
-         GLint x, y, cx, cy;         
-         const GLfloat *src;
+         GLint x, y, cx, cy;
+
          x = nearest_texcoord(sampler->state->wrap_s, strq[0],
                               sampler->texture->width0);
          y = nearest_texcoord(sampler->state->wrap_t, strq[1],
@@ -480,8 +504,12 @@ sp_get_sample_2d(struct tgsi_sampler *sampler,
 
          cx = x / SAMPLER_CACHE_SIZE;
          cy = y / SAMPLER_CACHE_SIZE;
-         if (cx != sampler->cache_x || cy != sampler->cache_y) {
+         if (cx != sampler->cache_x || cy != sampler->cache_y ||
+             level0 != sampler->cache_level) {
             /* cache miss, replace cache with new tile */
+            struct pipe_surface *ps
+               = pipe->get_tex_surface(pipe, sampler->texture, 0, level0, 0);
+            sampler->cache_level = level0;
             sampler->cache_x = cx;
             sampler->cache_y = cy;
             ps->get_tile(ps,
@@ -497,8 +525,7 @@ sp_get_sample_2d(struct tgsi_sampler *sampler,
 
          cx = x % SAMPLER_CACHE_SIZE;
          cy = y % SAMPLER_CACHE_SIZE;
-         src = sampler->cache[cy][cx];
-         COPY_4V(rgba, src);
+         COPY_4V(rgba, sampler->cache[cy][cx]);
       }
       break;
    case PIPE_TEX_FILTER_LINEAR:
@@ -506,6 +533,9 @@ sp_get_sample_2d(struct tgsi_sampler *sampler,
          GLfloat t00[4], t01[4], t10[4], t11[4];
          GLint x0, y0, x1, y1;
          GLfloat a, b;
+         struct pipe_surface *ps
+            = pipe->get_tex_surface(pipe, sampler->texture, 0, level0, 0);
+
          linear_texcoord(sampler->state->wrap_s, strq[0],
                          sampler->texture->width0, &x0, &x1, &a);
          linear_texcoord(sampler->state->wrap_t, strq[1],
@@ -521,6 +551,13 @@ sp_get_sample_2d(struct tgsi_sampler *sampler,
          rgba[3] = lerp_2d(a, b, t00[3], t10[3], t01[3], t11[3]);
       }
       break;
+      /*
+      {
+        GLuint level0, level1;
+        level0 = choose_mipmap_level(sampler, lambda);
+      }
+      break;
+      */
    default:
       assert(0);
    }
index fb11eec777686f23f1237eb0d38e4800598f45ca..01dd7f11b8c492131fa797e4ea52b262bed42a9a 100644 (file)
@@ -31,7 +31,7 @@ struct tgsi_sampler
                       const GLfloat strq[4], GLfloat lambda, GLfloat rgba[4]);
    void *pipe; /*XXX temporary*/
 
-   GLint cache_x, cache_y;
+   GLint cache_x, cache_y, cache_level;
    GLfloat cache[SAMPLER_CACHE_SIZE][SAMPLER_CACHE_SIZE][4];
 };