diff options
author | Brian Paul <brianp@vmware.com> | 2009-04-06 13:51:14 -0600 |
---|---|---|
committer | Brian Paul <brianp@vmware.com> | 2009-04-06 13:53:46 -0600 |
commit | b48eb05f1f547e2b03a22056f3e82ee7b9065337 (patch) | |
tree | 0dbcb5a3909d55db192bcf78fc52c4cc21f6c970 /src | |
parent | 8332925c3caadd293d0c091ef84f7268c673013c (diff) |
swrast: fix texture border color interpretation
The texture border color must be interpreted according to the texture's
base format. For example, for a GL_ALPHA texture, sampling the border
color should return (0,0,0,borderAlpha). This wasn't an issue here until
I removed the legacy texenv code (we always use the combiner path now).
Diffstat (limited to 'src')
-rw-r--r-- | src/mesa/swrast/s_texfilter.c | 98 |
1 files changed, 68 insertions, 30 deletions
diff --git a/src/mesa/swrast/s_texfilter.c b/src/mesa/swrast/s_texfilter.c index d84f37e576..a483023a50 100644 --- a/src/mesa/swrast/s_texfilter.c +++ b/src/mesa/swrast/s_texfilter.c @@ -734,6 +734,44 @@ compute_min_mag_ranges(const struct gl_texture_object *tObj, } +/** + * When we sample the border color, it must be interpreted according to + * the base texture format. Ex: if the texture base format it GL_ALPHA, + * we return (0,0,0,BorderAlpha). + */ +static INLINE void +get_border_color(const struct gl_texture_object *tObj, + const struct gl_texture_image *img, + GLfloat rgba[4]) +{ + switch (img->TexFormat->BaseFormat) { + case GL_RGB: + rgba[0] = tObj->BorderColor[0]; + rgba[1] = tObj->BorderColor[1]; + rgba[2] = tObj->BorderColor[2]; + rgba[3] = 1.0F; + break; + case GL_ALPHA: + rgba[0] = rgba[1] = rgba[2] = 0.0; + rgba[3] = tObj->BorderColor[3]; + break; + case GL_LUMINANCE: + rgba[0] = rgba[1] = rgba[2] = tObj->BorderColor[0]; + rgba[3] = 1.0; + break; + case GL_LUMINANCE_ALPHA: + rgba[0] = rgba[1] = rgba[2] = tObj->BorderColor[0]; + rgba[3] = tObj->BorderColor[3]; + break; + case GL_INTENSITY: + rgba[0] = rgba[1] = rgba[2] = rgba[3] = tObj->BorderColor[0]; + break; + default: + COPY_4V(rgba, tObj->BorderColor); + } +} + + /**********************************************************************/ /* 1-D Texture Sampling Functions */ /**********************************************************************/ @@ -754,7 +792,7 @@ sample_1d_nearest(GLcontext *ctx, i += img->Border; if (i < 0 || i >= (GLint) img->Width) { /* Need this test for GL_CLAMP_TO_BORDER mode */ - COPY_4V(rgba, tObj->BorderColor); + get_border_color(tObj, img, rgba); } else { img->FetchTexelf(img, i, 0, 0, rgba); @@ -790,13 +828,13 @@ sample_1d_linear(GLcontext *ctx, /* fetch texel colors */ if (useBorderColor & I0BIT) { - COPY_4V(t0, tObj->BorderColor); + get_border_color(tObj, img, t0); } else { img->FetchTexelf(img, i0, 0, 0, t0); } if (useBorderColor & I1BIT) { - COPY_4V(t1, tObj->BorderColor); + get_border_color(tObj, img, t1); } else { img->FetchTexelf(img, i1, 0, 0, t1); @@ -1019,7 +1057,7 @@ sample_2d_nearest(GLcontext *ctx, if (i < 0 || i >= (GLint) img->Width || j < 0 || j >= (GLint) img->Height) { /* Need this test for GL_CLAMP_TO_BORDER mode */ - COPY_4V(rgba, tObj->BorderColor); + get_border_color(tObj, img, rgba); } else { img->FetchTexelf(img, i, j, 0, rgba); @@ -1063,25 +1101,25 @@ sample_2d_linear(GLcontext *ctx, /* fetch four texel colors */ if (useBorderColor & (I0BIT | J0BIT)) { - COPY_4V(t00, tObj->BorderColor); + get_border_color(tObj, img, t00); } else { img->FetchTexelf(img, i0, j0, 0, t00); } if (useBorderColor & (I1BIT | J0BIT)) { - COPY_4V(t10, tObj->BorderColor); + get_border_color(tObj, img, t10); } else { img->FetchTexelf(img, i1, j0, 0, t10); } if (useBorderColor & (I0BIT | J1BIT)) { - COPY_4V(t01, tObj->BorderColor); + get_border_color(tObj, img, t01); } else { img->FetchTexelf(img, i0, j1, 0, t01); } if (useBorderColor & (I1BIT | J1BIT)) { - COPY_4V(t11, tObj->BorderColor); + get_border_color(tObj, img, t11); } else { img->FetchTexelf(img, i1, j1, 0, t11); @@ -1505,7 +1543,7 @@ sample_3d_nearest(GLcontext *ctx, j < 0 || j >= (GLint) img->Height || k < 0 || k >= (GLint) img->Depth) { /* Need this test for GL_CLAMP_TO_BORDER mode */ - COPY_4V(rgba, tObj->BorderColor); + get_border_color(tObj, img, rgba); } else { img->FetchTexelf(img, i, j, k, rgba); @@ -1556,50 +1594,50 @@ sample_3d_linear(GLcontext *ctx, /* Fetch texels */ if (useBorderColor & (I0BIT | J0BIT | K0BIT)) { - COPY_4V(t000, tObj->BorderColor); + get_border_color(tObj, img, t000); } else { img->FetchTexelf(img, i0, j0, k0, t000); } if (useBorderColor & (I1BIT | J0BIT | K0BIT)) { - COPY_4V(t100, tObj->BorderColor); + get_border_color(tObj, img, t100); } else { img->FetchTexelf(img, i1, j0, k0, t100); } if (useBorderColor & (I0BIT | J1BIT | K0BIT)) { - COPY_4V(t010, tObj->BorderColor); + get_border_color(tObj, img, t010); } else { img->FetchTexelf(img, i0, j1, k0, t010); } if (useBorderColor & (I1BIT | J1BIT | K0BIT)) { - COPY_4V(t110, tObj->BorderColor); + get_border_color(tObj, img, t110); } else { img->FetchTexelf(img, i1, j1, k0, t110); } if (useBorderColor & (I0BIT | J0BIT | K1BIT)) { - COPY_4V(t001, tObj->BorderColor); + get_border_color(tObj, img, t001); } else { img->FetchTexelf(img, i0, j0, k1, t001); } if (useBorderColor & (I1BIT | J0BIT | K1BIT)) { - COPY_4V(t101, tObj->BorderColor); + get_border_color(tObj, img, t101); } else { img->FetchTexelf(img, i1, j0, k1, t101); } if (useBorderColor & (I0BIT | J1BIT | K1BIT)) { - COPY_4V(t011, tObj->BorderColor); + get_border_color(tObj, img, t011); } else { img->FetchTexelf(img, i0, j1, k1, t011); } if (useBorderColor & (I1BIT | J1BIT | K1BIT)) { - COPY_4V(t111, tObj->BorderColor); + get_border_color(tObj, img, t111); } else { img->FetchTexelf(img, i1, j1, k1, t111); @@ -2117,7 +2155,7 @@ sample_nearest_rect(GLcontext *ctx, col = clamp_rect_coord_nearest(tObj->WrapS, texcoords[i][0], width); row = clamp_rect_coord_nearest(tObj->WrapT, texcoords[i][1], height); if (col < 0 || col >= width || row < 0 || row >= height) - COPY_4V(rgba[i], tObj->BorderColor); + get_border_color(tObj, img, rgba[i]); else img->FetchTexelf(img, col, row, 0, rgba[i]); } @@ -2165,22 +2203,22 @@ sample_linear_rect(GLcontext *ctx, /* get four texel samples */ if (useBorderColor & (I0BIT | J0BIT)) - COPY_4V(t00, tObj->BorderColor); + get_border_color(tObj, img, t00); else img->FetchTexelf(img, i0, j0, 0, t00); if (useBorderColor & (I1BIT | J0BIT)) - COPY_4V(t10, tObj->BorderColor); + get_border_color(tObj, img, t10); else img->FetchTexelf(img, i1, j0, 0, t10); if (useBorderColor & (I0BIT | J1BIT)) - COPY_4V(t01, tObj->BorderColor); + get_border_color(tObj, img, t01); else img->FetchTexelf(img, i0, j1, 0, t01); if (useBorderColor & (I1BIT | J1BIT)) - COPY_4V(t11, tObj->BorderColor); + get_border_color(tObj, img, t11); else img->FetchTexelf(img, i1, j1, 0, t11); @@ -2257,7 +2295,7 @@ sample_2d_array_nearest(GLcontext *ctx, j < 0 || j >= (GLint) img->Height || array < 0 || array >= (GLint) img->Depth) { /* Need this test for GL_CLAMP_TO_BORDER mode */ - COPY_4V(rgba, tObj->BorderColor); + get_border_color(tObj, img, rgba); } else { img->FetchTexelf(img, i, j, array, rgba); @@ -2308,25 +2346,25 @@ sample_2d_array_linear(GLcontext *ctx, /* Fetch texels */ if (useBorderColor & (I0BIT | J0BIT)) { - COPY_4V(t00, tObj->BorderColor); + get_border_color(tObj, img, t00); } else { img->FetchTexelf(img, i0, j0, array, t00); } if (useBorderColor & (I1BIT | J0BIT)) { - COPY_4V(t10, tObj->BorderColor); + get_border_color(tObj, img, t10); } else { img->FetchTexelf(img, i1, j0, array, t10); } if (useBorderColor & (I0BIT | J1BIT)) { - COPY_4V(t01, tObj->BorderColor); + get_border_color(tObj, img, t01); } else { img->FetchTexelf(img, i0, j1, array, t01); } if (useBorderColor & (I1BIT | J1BIT)) { - COPY_4V(t11, tObj->BorderColor); + get_border_color(tObj, img, t11); } else { img->FetchTexelf(img, i1, j1, array, t11); @@ -2564,7 +2602,7 @@ sample_1d_array_nearest(GLcontext *ctx, if (i < 0 || i >= (GLint) img->Width || array < 0 || array >= (GLint) img->Height) { /* Need this test for GL_CLAMP_TO_BORDER mode */ - COPY_4V(rgba, tObj->BorderColor); + get_border_color(tObj, img, rgba); } else { img->FetchTexelf(img, i, array, 0, rgba); @@ -2607,13 +2645,13 @@ sample_1d_array_linear(GLcontext *ctx, /* Fetch texels */ if (useBorderColor & (I0BIT | K0BIT)) { - COPY_4V(t0, tObj->BorderColor); + get_border_color(tObj, img, t0); } else { img->FetchTexelf(img, i0, array, 0, t0); } if (useBorderColor & (I1BIT | K0BIT)) { - COPY_4V(t1, tObj->BorderColor); + get_border_color(tObj, img, t1); } else { img->FetchTexelf(img, i1, array, 0, t1); |