-/* $Id: s_texture.c,v 1.23 2001/04/12 15:18:07 brianp Exp $ */
+/* $Id: s_texture.c,v 1.32 2001/06/01 13:23:27 brianp Exp $ */
/*
* Mesa 3-D graphics library
#include "s_texture.h"
-/* XXX this is temporary, until GL/glext.h is updated. */
-#ifndef GL_DOT3_RGB_ARB
-#define GL_DOT3_RGB_ARB 0x86AE
-#endif
-#ifndef GL_DOT3_RGBA_ARB
-#define GL_DOT3_RGBA_ARB 0x86AF
-#endif
-
-/* XXX this is temporary, until GL/glext.h is updated. */
-#ifndef GL_CLAMP_TO_BORDER_ARB
-#define GL_CLAMP_TO_BORDER_ARB 0x812D
-#endif
-
-
/*
* These values are used in the fixed-point arithmetic used
* for linear filtering.
/*
* Note, the FRAC macro has to work perfectly. Otherwise you'll sometimes
- * see 1-pixel bands of improperly weighted linear-sampled texels.
- * In particular, #define FRAC(f) ((f) - IFLOOR(f)) doesn't work.
+ * see 1-pixel bands of improperly weighted linear-sampled texels. The
+ * tests/texwrap.c demo is a good test.
* Also note, FRAC(x) doesn't truly return the fractional part of x for x < 0.
* Instead, if x < 0 then FRAC(x) = 1 - true_frac(x).
*/
-#define FRAC(f) ((f) - floor(f))
+#define FRAC(f) ((f) - IFLOOR(f))
+
/*
/* skip over the border, if any */
i += img->Border;
- if (i < 0 || i >= img->Width) {
+ if (i < 0 || i >= (GLint) img->Width) {
/* Need this test for GL_CLAMP_TO_BORDER_ARB mode */
COPY_CHAN4(rgba, tObj->BorderColor);
}
}
{
- const GLfloat a = FRAC(u + 1.0F);
+ const GLfloat a = FRAC(u);
+
+#if CHAN_BITS == 32
+ const GLfloat w0 = (1.0F-a);
+ const GLfloat w1 = a ;
+#else /* CHAN_BITS == 8 || CHAN_BITS == 16 */
/* compute sample weights in fixed point in [0,WEIGHT_SCALE] */
- const GLint w0 = IROUND_POS((1.0F-a) * WEIGHT_SCALE);
- const GLint w1 = IROUND_POS( a * WEIGHT_SCALE);
+ const GLint w0 = IROUND_POS((1.0F - a) * WEIGHT_SCALE);
+ const GLint w1 = IROUND_POS( a * WEIGHT_SCALE);
+#endif
GLchan t0[4], t1[4]; /* texels */
}
}
+#if CHAN_BITS == 32
+ rgba[0] = w0 * t0[0] + w1 * t1[0];
+ rgba[1] = w0 * t0[1] + w1 * t1[1];
+ rgba[2] = w0 * t0[2] + w1 * t1[2];
+ rgba[3] = w0 * t0[3] + w1 * t1[3];
+#else /* CHAN_BITS == 8 || CHAN_BITS == 16 */
rgba[0] = (GLchan) ((w0 * t0[0] + w1 * t1[0]) >> WEIGHT_SHIFT);
rgba[1] = (GLchan) ((w0 * t0[1] + w1 * t1[1]) >> WEIGHT_SHIFT);
rgba[2] = (GLchan) ((w0 * t0[2] + w1 * t1[2]) >> WEIGHT_SHIFT);
rgba[3] = (GLchan) ((w0 * t0[3] + w1 * t1[3]) >> WEIGHT_SHIFT);
+#endif
+
}
}
i += img->Border;
j += img->Border;
- if (i < 0 || i >= img->Width || j < 0 || j >= img->Height) {
+ if (i < 0 || i >= (GLint) img->Width || j < 0 || j >= (GLint) img->Height) {
/* Need this test for GL_CLAMP_TO_BORDER_ARB mode */
COPY_CHAN4(rgba, tObj->BorderColor);
}
}
{
- const GLfloat a = FRAC(u - 1.0);
- const GLfloat b = FRAC(v - 1.0);
+ const GLfloat a = FRAC(u);
+ const GLfloat b = FRAC(v);
+
+#if CHAN_BITS == 32
+ const GLfloat w00 = (1.0F-a) * (1.0F-b);
+ const GLfloat w10 = a * (1.0F-b);
+ const GLfloat w01 = (1.0F-a) * b ;
+ const GLfloat w11 = a * b ;
+#else /* CHAN_BITS == 8 || CHAN_BITS == 16 */
/* compute sample weights in fixed point in [0,WEIGHT_SCALE] */
const GLint w00 = IROUND_POS((1.0F-a) * (1.0F-b) * WEIGHT_SCALE);
const GLint w10 = IROUND_POS( a * (1.0F-b) * WEIGHT_SCALE);
const GLint w01 = IROUND_POS((1.0F-a) * b * WEIGHT_SCALE);
const GLint w11 = IROUND_POS( a * b * WEIGHT_SCALE);
+#endif
+
GLchan t00[4];
GLchan t10[4];
GLchan t01[4];
palette_sample(ctx, tObj, t11[0], t11);
}
}
-
+#if CHAN_BITS == 32
+ rgba[0] = w00 * t00[0] + w10 * t10[0] + w01 * t01[0] + w11 * t11[0];
+ rgba[1] = w00 * t00[1] + w10 * t10[1] + w01 * t01[1] + w11 * t11[1];
+ rgba[2] = w00 * t00[2] + w10 * t10[2] + w01 * t01[2] + w11 * t11[2];
+ rgba[3] = w00 * t00[3] + w10 * t10[3] + w01 * t01[3] + w11 * t11[3];
+#else /* CHAN_BITS == 8 || CHAN_BITS == 16 */
rgba[0] = (GLchan) ((w00 * t00[0] + w10 * t10[0] + w01 * t01[0] + w11 * t11[0]) >> WEIGHT_SHIFT);
rgba[1] = (GLchan) ((w00 * t00[1] + w10 * t10[1] + w01 * t01[1] + w11 * t11[1]) >> WEIGHT_SHIFT);
rgba[2] = (GLchan) ((w00 * t00[2] + w10 * t10[2] + w01 * t01[2] + w11 * t11[2]) >> WEIGHT_SHIFT);
rgba[3] = (GLchan) ((w00 * t00[3] + w10 * t10[3] + w01 * t01[3] + w11 * t11[3]) >> WEIGHT_SHIFT);
+#endif
+
}
}
COMPUTE_NEAREST_TEXEL_LOCATION(tObj->WrapT, t, height, j);
COMPUTE_NEAREST_TEXEL_LOCATION(tObj->WrapR, r, depth, k);
- if (i < 0 || i >= img->Width ||
- j < 0 || j >= img->Height ||
- k < 0 || k >= img->Depth) {
+ if (i < 0 || i >= (GLint) img->Width ||
+ j < 0 || j >= (GLint) img->Height ||
+ k < 0 || k >= (GLint) img->Depth) {
/* Need this test for GL_CLAMP_TO_BORDER_ARB mode */
COPY_CHAN4(rgba, tObj->BorderColor);
}
}
{
- const GLfloat a = FRAC(u + 1.0F);
- const GLfloat b = FRAC(v + 1.0F);
- const GLfloat c = FRAC(w + 1.0F);
+ const GLfloat a = FRAC(u);
+ const GLfloat b = FRAC(v);
+ const GLfloat c = FRAC(w);
+
+#if CHAN_BITS == 32
+ /* compute sample weights in fixed point in [0,WEIGHT_SCALE] */
+ GLfloat w000 = (1.0F-a) * (1.0F-b) * (1.0F-c);
+ GLfloat w100 = a * (1.0F-b) * (1.0F-c);
+ GLfloat w010 = (1.0F-a) * b * (1.0F-c);
+ GLfloat w110 = a * b * (1.0F-c);
+ GLfloat w001 = (1.0F-a) * (1.0F-b) * c ;
+ GLfloat w101 = a * (1.0F-b) * c ;
+ GLfloat w011 = (1.0F-a) * b * c ;
+ GLfloat w111 = a * b * c ;
+#else /* CHAN_BITS == 8 || CHAN_BITS == 16 */
/* compute sample weights in fixed point in [0,WEIGHT_SCALE] */
GLint w000 = IROUND_POS((1.0F-a) * (1.0F-b) * (1.0F-c) * WEIGHT_SCALE);
GLint w100 = IROUND_POS( a * (1.0F-b) * (1.0F-c) * WEIGHT_SCALE);
GLint w101 = IROUND_POS( a * (1.0F-b) * c * WEIGHT_SCALE);
GLint w011 = IROUND_POS((1.0F-a) * b * c * WEIGHT_SCALE);
GLint w111 = IROUND_POS( a * b * c * WEIGHT_SCALE);
+#endif
GLchan t000[4], t010[4], t001[4], t011[4];
GLchan t100[4], t110[4], t101[4], t111[4];
}
}
+#if CHAN_BITS == 32
+ rgba[0] = w000*t000[0] + w010*t010[0] + w001*t001[0] + w011*t011[0] +
+ w100*t100[0] + w110*t110[0] + w101*t101[0] + w111*t111[0];
+ rgba[1] = w000*t000[1] + w010*t010[1] + w001*t001[1] + w011*t011[1] +
+ w100*t100[1] + w110*t110[1] + w101*t101[1] + w111*t111[1];
+ rgba[2] = w000*t000[2] + w010*t010[2] + w001*t001[2] + w011*t011[2] +
+ w100*t100[2] + w110*t110[2] + w101*t101[2] + w111*t111[2];
+ rgba[3] = w000*t000[3] + w010*t010[3] + w001*t001[3] + w011*t011[3] +
+ w100*t100[3] + w110*t110[3] + w101*t101[3] + w111*t111[3];
+#else /* CHAN_BITS == 8 || CHAN_BITS == 16 */
rgba[0] = (GLchan) (
(w000*t000[0] + w010*t010[0] + w001*t001[0] + w011*t011[0] +
- w100*t100[0] + w110*t110[0] + w101*t101[0] + w111*t111[0] )
+ w100*t100[0] + w110*t110[0] + w101*t101[0] + w111*t111[0] )
>> WEIGHT_SHIFT);
rgba[1] = (GLchan) (
(w000*t000[1] + w010*t010[1] + w001*t001[1] + w011*t011[1] +
(w000*t000[3] + w010*t010[3] + w001*t001[3] + w011*t011[3] +
w100*t100[3] + w110*t110[3] + w101*t101[3] + w111*t111[3] )
>> WEIGHT_SHIFT);
+#endif
+
}
}
CONST GLchan (*texel)[4],
GLchan (*rgba)[4])
{
- GLchan ccolor [3][3*MAX_WIDTH][4];
const GLchan (*argRGB [3])[4];
const GLchan (*argA [3])[4];
GLuint i, j;
const GLuint RGBshift = textureUnit->CombineScaleShiftRGB;
const GLuint Ashift = textureUnit->CombineScaleShiftA;
+ DEFMNARRAY(GLchan, ccolor, 3, 3 * MAX_WIDTH, 4); /* mac 32k limitation */
+ CHECKARRAY(ccolor, return); /* mac 32k limitation */
- ASSERT(ctx->Extensions.EXT_texture_env_combine);
+ ASSERT(ctx->Extensions.EXT_texture_env_combine ||
+ ctx->Extensions.ARB_texture_env_combine);
/*
* Do operand setup for up to 3 operands. Loop over the terms.
case GL_CONSTANT_EXT:
{
GLchan (*c)[4] = ccolor[j];
- GLchan red, green, blue;
+ GLchan red, green, blue, alpha;
UNCLAMPED_FLOAT_TO_CHAN(red, textureUnit->EnvColor[0]);
UNCLAMPED_FLOAT_TO_CHAN(green, textureUnit->EnvColor[1]);
UNCLAMPED_FLOAT_TO_CHAN(blue, textureUnit->EnvColor[2]);
+ UNCLAMPED_FLOAT_TO_CHAN(alpha, textureUnit->EnvColor[3]);
for (i = 0; i < n; i++) {
c[i][RCOMP] = red;
c[i][GCOMP] = green;
c[i][BCOMP] = blue;
+ c[i][ACOMP] = alpha;
}
argRGB[j] = (const GLchan (*)[4]) ccolor[j];
}
const GLchan (*src)[4] = argRGB[j];
GLchan (*dst)[4] = ccolor[j];
+ /* point to new arg[j] storage */
argRGB[j] = (const GLchan (*)[4]) ccolor[j];
if (textureUnit->CombineOperandRGB[j] == GL_ONE_MINUS_SRC_COLOR) {
}
}
else if (textureUnit->CombineOperandRGB[j] == GL_SRC_ALPHA) {
- src = (const GLchan (*)[4]) argA[j];
for (i = 0; i < n; i++) {
dst[i][RCOMP] = src[i][ACOMP];
dst[i][GCOMP] = src[i][ACOMP];
}
else {
ASSERT(textureUnit->CombineOperandRGB[j] ==GL_ONE_MINUS_SRC_ALPHA);
- src = (const GLchan (*)[4]) argA[j];
for (i = 0; i < n; i++) {
dst[i][RCOMP] = CHAN_MAX - src[i][ACOMP];
dst[i][GCOMP] = CHAN_MAX - src[i][ACOMP];
}
}
break;
+ case GL_SUBTRACT_ARB:
+ {
+ const GLchan (*arg0)[4] = (const GLchan (*)[4]) argRGB[0];
+ const GLchan (*arg1)[4] = (const GLchan (*)[4]) argRGB[1];
+ for (i = 0; i < n; i++) {
+ GLint r = ((GLint) arg0[i][RCOMP] - (GLint) arg1[i][RCOMP]) << RGBshift;
+ GLint g = ((GLint) arg0[i][GCOMP] - (GLint) arg1[i][GCOMP]) << RGBshift;
+ GLint b = ((GLint) arg0[i][BCOMP] - (GLint) arg1[i][BCOMP]) << RGBshift;
+ rgba[i][RCOMP] = (GLchan) CLAMP(r, 0, CHAN_MAX);
+ rgba[i][GCOMP] = (GLchan) CLAMP(g, 0, CHAN_MAX);
+ rgba[i][BCOMP] = (GLchan) CLAMP(b, 0, CHAN_MAX);
+ }
+ }
+ break;
case GL_DOT3_RGB_EXT:
case GL_DOT3_RGBA_EXT:
case GL_DOT3_RGB_ARB:
case GL_DOT3_RGBA_ARB:
{
- const GLubyte (*arg0)[4] = (const GLubyte (*)[4]) argRGB[0];
- const GLubyte (*arg1)[4] = (const GLubyte (*)[4]) argRGB[1];
+ const GLchan (*arg0)[4] = (const GLchan (*)[4]) argRGB[0];
+ const GLchan (*arg1)[4] = (const GLchan (*)[4]) argRGB[1];
/* ATI's EXT extension has a constant scale by 4. The ARB
* one will likely remove this restriction, and we should
* drop the EXT extension in favour of the ARB one.
(GLint)arg1[i][GCOMP] - 128) +
S_PROD((GLint)arg0[i][BCOMP] - 128,
(GLint)arg1[i][BCOMP] - 128)) >> 6;
- rgba[i][RCOMP] = (GLubyte) CLAMP(dot, 0, 255);
- rgba[i][GCOMP] = (GLubyte) CLAMP(dot, 0, 255);
- rgba[i][BCOMP] = (GLubyte) CLAMP(dot, 0, 255);
+ dot = CLAMP(dot, 0, 255);
+ rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = (GLchan) dot;
}
}
break;
}
}
break;
+ case GL_SUBTRACT_ARB:
+ {
+ const GLchan (*arg0)[4] = (const GLchan (*)[4]) argRGB[0];
+ const GLchan (*arg1)[4] = (const GLchan (*)[4]) argRGB[1];
+ for (i = 0; i < n; i++) {
+ GLint a = ((GLint) arg0[i][ACOMP] - (GLint) arg1[i][ACOMP]) << RGBshift;
+ rgba[i][ACOMP] = (GLchan) CLAMP(a, 0, CHAN_MAX);
+ }
+ }
+ break;
+
default:
_mesa_problem(NULL, "invalid combine mode");
}
rgba[i][ACOMP] = rgba[i][RCOMP];
}
}
+ UNDEFARRAY(ccolor); /* mac 32k limitation */
}
#undef PROD