softpipe: add texture border color code
authorBrian Paul <brian.paul@tungstengraphics.com>
Wed, 6 Aug 2008 23:14:22 +0000 (17:14 -0600)
committerBrian Paul <brian.paul@tungstengraphics.com>
Wed, 6 Aug 2008 23:14:22 +0000 (17:14 -0600)
src/gallium/drivers/softpipe/sp_tex_sample.c

index 63b3b91110eac2e5b2d8385abbb7f60090b5da10..ed150527e2d4d7081e3600b919be539e41e88816 100644 (file)
@@ -601,15 +601,25 @@ get_texel(struct tgsi_sampler *sampler,
           unsigned face, unsigned level, int x, int y, int z,
           float rgba[NUM_CHANNELS][QUAD_SIZE], unsigned j)
 {
-   const int tx = x % TILE_SIZE;
-   const int ty = y % TILE_SIZE;
-   const struct softpipe_cached_tile *tile
-      = sp_get_cached_tile_tex(sampler->pipe, sampler->cache,
-                               x, y, z, face, level);
-   rgba[0][j] = tile->data.color[ty][tx][0];
-   rgba[1][j] = tile->data.color[ty][tx][1];
-   rgba[2][j] = tile->data.color[ty][tx][2];
-   rgba[3][j] = tile->data.color[ty][tx][3];
+   if (x < 0 || x >= sampler->texture->width[level] ||
+       y < 0 || y >= sampler->texture->height[level] ||
+       z < 0 || z >= sampler->texture->depth[level]) {
+      rgba[0][j] = sampler->state->border_color[0];
+      rgba[1][j] = sampler->state->border_color[1];
+      rgba[2][j] = sampler->state->border_color[2];
+      rgba[3][j] = sampler->state->border_color[3];
+   }
+   else {
+      const int tx = x % TILE_SIZE;
+      const int ty = y % TILE_SIZE;
+      const struct softpipe_cached_tile *tile
+         = sp_get_cached_tile_tex(sampler->pipe, sampler->cache,
+                                  x, y, z, face, level);
+      rgba[0][j] = tile->data.color[ty][tx][0];
+      rgba[1][j] = tile->data.color[ty][tx][1];
+      rgba[2][j] = tile->data.color[ty][tx][2];
+      rgba[3][j] = tile->data.color[ty][tx][3];
+   }
 }