swrast: do texture sampling/combining in floating point

The code's cleaner and a step toward supporting float-valued texture sampling.
Some optimizations for common cases can be added and re-enabled...
This commit is contained in:
Brian Paul
2009-03-08 13:49:57 -06:00
parent f8304bf1ed
commit de2afd8688
8 changed files with 512 additions and 779 deletions

View File

@@ -71,9 +71,6 @@
/** \def COPY_CHAN4
* Copy a GLchan[4] array */
/** \def CHAN_PRODUCT
* Scaled product (usually approximated) between two GLchan arguments */
#if CHAN_BITS == 8
#define BYTE_TO_CHAN(b) ((b) < 0 ? 0 : (GLchan) (b))
@@ -91,8 +88,6 @@
#define COPY_CHAN4(DST, SRC) COPY_4UBV(DST, SRC)
#define CHAN_PRODUCT(a, b) ((GLubyte) (((GLint)(a) * ((GLint)(b) + 1)) >> 8))
#elif CHAN_BITS == 16
#define BYTE_TO_CHAN(b) ((b) < 0 ? 0 : (((GLchan) (b)) * 516))
@@ -110,8 +105,6 @@
#define COPY_CHAN4(DST, SRC) COPY_4V(DST, SRC)
#define CHAN_PRODUCT(a, b) ((GLchan) ((((GLuint) (a)) * ((GLuint) (b))) / 65535))
#elif CHAN_BITS == 32
/* XXX floating-point color channels not fully thought-out */
@@ -130,8 +123,6 @@
#define COPY_CHAN4(DST, SRC) COPY_4V(DST, SRC)
#define CHAN_PRODUCT(a, b) ((a) * (b))
#else
#error unexpected CHAN_BITS size

View File

@@ -47,17 +47,12 @@ static void
fetch_texel(GLcontext * ctx, const GLfloat texcoord[4], GLfloat lambda,
GLuint unit, GLfloat color[4])
{
GLchan rgba[4];
SWcontext *swrast = SWRAST_CONTEXT(ctx);
/* XXX use a float-valued TextureSample routine here!!! */
swrast->TextureSample[unit](ctx, ctx->Texture.Unit[unit]._Current,
1, (const GLfloat(*)[4]) texcoord,
&lambda, &rgba);
color[0] = CHAN_TO_FLOAT(rgba[0]);
color[1] = CHAN_TO_FLOAT(rgba[1]);
color[2] = CHAN_TO_FLOAT(rgba[2]);
color[3] = CHAN_TO_FLOAT(rgba[3]);
&lambda, (GLfloat (*)[4]) color);
}
static void

View File

@@ -820,8 +820,8 @@ _swrast_CreateContext( GLcontext *ctx )
swrast->PointSpan.facing = 0;
swrast->PointSpan.array = swrast->SpanArrays;
swrast->TexelBuffer = (GLchan *) MALLOC(ctx->Const.MaxTextureImageUnits *
MAX_WIDTH * 4 * sizeof(GLchan));
swrast->TexelBuffer = (GLfloat *) MALLOC(ctx->Const.MaxTextureImageUnits *
MAX_WIDTH * 4 * sizeof(GLfloat));
if (!swrast->TexelBuffer) {
FREE(swrast->SpanArrays);
FREE(swrast);

View File

@@ -52,7 +52,7 @@
typedef void (*texture_sample_func)(GLcontext *ctx,
const struct gl_texture_object *tObj,
GLuint n, const GLfloat texcoords[][4],
const GLfloat lambda[], GLchan rgba[][4]);
const GLfloat lambda[], GLfloat rgba[][4]);
typedef void (_ASMAPIP blend_func)( GLcontext *ctx, GLuint n,
const GLubyte mask[],
@@ -221,7 +221,7 @@ typedef struct
/** Buffer for saving the sampled texture colors.
* Needed for GL_ARB_texture_env_crossbar implementation.
*/
GLchan *TexelBuffer;
GLfloat *TexelBuffer;
validate_texture_image_func ValidateTextureImage;

View File

@@ -37,20 +37,17 @@
* and return results in 'colorOut'.
*/
static INLINE void
swizzle_texel(const GLchan texel[4], GLfloat colorOut[4], GLuint swizzle)
swizzle_texel(const GLfloat texel[4], GLfloat colorOut[4], GLuint swizzle)
{
if (swizzle == SWIZZLE_NOOP) {
colorOut[0] = CHAN_TO_FLOAT(texel[0]);
colorOut[1] = CHAN_TO_FLOAT(texel[1]);
colorOut[2] = CHAN_TO_FLOAT(texel[2]);
colorOut[3] = CHAN_TO_FLOAT(texel[3]);
COPY_4V(colorOut, texel);
}
else {
GLfloat vector[6];
vector[SWIZZLE_X] = CHAN_TO_FLOAT(texel[0]);
vector[SWIZZLE_Y] = CHAN_TO_FLOAT(texel[1]);
vector[SWIZZLE_Z] = CHAN_TO_FLOAT(texel[2]);
vector[SWIZZLE_W] = CHAN_TO_FLOAT(texel[3]);
vector[SWIZZLE_X] = texel[0];
vector[SWIZZLE_Y] = texel[1];
vector[SWIZZLE_Z] = texel[2];
vector[SWIZZLE_W] = texel[3];
vector[SWIZZLE_ZERO] = 0.0F;
vector[SWIZZLE_ONE] = 1.0F;
colorOut[0] = vector[GET_SWZ(swizzle, 0)];
@@ -73,7 +70,7 @@ fetch_texel_lod( GLcontext *ctx, const GLfloat texcoord[4], GLfloat lambda,
if (texObj) {
SWcontext *swrast = SWRAST_CONTEXT(ctx);
GLchan rgba[4];
GLfloat rgba[4];
lambda = CLAMP(lambda, texObj->MinLod, texObj->MaxLod);
@@ -108,7 +105,7 @@ fetch_texel_deriv( GLcontext *ctx, const GLfloat texcoord[4],
const GLfloat texW = (GLfloat) texImg->WidthScale;
const GLfloat texH = (GLfloat) texImg->HeightScale;
GLfloat lambda;
GLchan rgba[4];
GLfloat rgba[4];
lambda = _swrast_compute_lambda(texdx[0], texdy[0], /* ds/dx, ds/dy */
texdx[1], texdy[1], /* dt/dx, dt/dy */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -176,17 +176,12 @@ static void
vp_fetch_texel(GLcontext *ctx, const GLfloat texcoord[4], GLfloat lambda,
GLuint unit, GLfloat color[4])
{
GLchan rgba[4];
SWcontext *swrast = SWRAST_CONTEXT(ctx);
/* XXX use a float-valued TextureSample routine here!!! */
swrast->TextureSample[unit](ctx, ctx->Texture.Unit[unit]._Current,
1, (const GLfloat (*)[4]) texcoord,
&lambda, &rgba);
color[0] = CHAN_TO_FLOAT(rgba[0]);
color[1] = CHAN_TO_FLOAT(rgba[1]);
color[2] = CHAN_TO_FLOAT(rgba[2]);
color[3] = CHAN_TO_FLOAT(rgba[3]);
&lambda, (GLfloat (*)[4]) color);
}