diff options
Diffstat (limited to 'src/mesa/swrast/s_triangle.c')
-rw-r--r-- | src/mesa/swrast/s_triangle.c | 193 |
1 files changed, 100 insertions, 93 deletions
diff --git a/src/mesa/swrast/s_triangle.c b/src/mesa/swrast/s_triangle.c index 1ab0e19f92..d80a6761f4 100644 --- a/src/mesa/swrast/s_triangle.c +++ b/src/mesa/swrast/s_triangle.c @@ -134,22 +134,24 @@ _swrast_culltriangle( GLcontext *ctx, #define SETUP_CODE \ struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0]; \ - struct gl_texture_object *obj = \ + const struct gl_texture_object *obj = \ ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX]; \ - const GLint b = obj->BaseLevel; \ - const GLfloat twidth = (GLfloat) obj->Image[0][b]->Width; \ - const GLfloat theight = (GLfloat) obj->Image[0][b]->Height; \ - const GLint twidth_log2 = obj->Image[0][b]->WidthLog2; \ - const GLchan *texture = (const GLchan *) obj->Image[0][b]->Data; \ - const GLint smask = obj->Image[0][b]->Width - 1; \ - const GLint tmask = obj->Image[0][b]->Height - 1; \ + const struct gl_texture_image *texImg = \ + obj->Image[0][obj->BaseLevel]; \ + const GLfloat twidth = (GLfloat) texImg->Width; \ + const GLfloat theight = (GLfloat) texImg->Height; \ + const GLint twidth_log2 = texImg->WidthLog2; \ + const GLubyte *texture = (const GLubyte *) texImg->Data; \ + const GLint smask = texImg->Width - 1; \ + const GLint tmask = texImg->Height - 1; \ + ASSERT(texImg->TexFormat == MESA_FORMAT_RGB888); \ if (!rb || !texture) { \ return; \ } #define RENDER_SPAN( span ) \ GLuint i; \ - GLchan rgb[MAX_WIDTH][3]; \ + GLubyte rgb[MAX_WIDTH][3]; \ span.intTex[0] -= FIXED_HALF; /* off-by-one error? */ \ span.intTex[1] -= FIXED_HALF; \ for (i = 0; i < span.end; i++) { \ @@ -157,9 +159,9 @@ _swrast_culltriangle( GLcontext *ctx, GLint t = FixedToInt(span.intTex[1]) & tmask; \ GLint pos = (t << twidth_log2) + s; \ pos = pos + pos + pos; /* multiply by 3 */ \ - rgb[i][RCOMP] = texture[pos]; \ + rgb[i][RCOMP] = texture[pos+2]; \ rgb[i][GCOMP] = texture[pos+1]; \ - rgb[i][BCOMP] = texture[pos+2]; \ + rgb[i][BCOMP] = texture[pos+0]; \ span.intTex[0] += span.intTexStep[0]; \ span.intTex[1] += span.intTexStep[1]; \ } \ @@ -186,22 +188,24 @@ _swrast_culltriangle( GLcontext *ctx, #define SETUP_CODE \ struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0]; \ - struct gl_texture_object *obj = \ + const struct gl_texture_object *obj = \ ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX]; \ - const GLint b = obj->BaseLevel; \ - const GLfloat twidth = (GLfloat) obj->Image[0][b]->Width; \ - const GLfloat theight = (GLfloat) obj->Image[0][b]->Height; \ - const GLint twidth_log2 = obj->Image[0][b]->WidthLog2; \ - const GLchan *texture = (const GLchan *) obj->Image[0][b]->Data; \ - const GLint smask = obj->Image[0][b]->Width - 1; \ - const GLint tmask = obj->Image[0][b]->Height - 1; \ + const struct gl_texture_image *texImg = \ + obj->Image[0][obj->BaseLevel]; \ + const GLfloat twidth = (GLfloat) texImg->Width; \ + const GLfloat theight = (GLfloat) texImg->Height; \ + const GLint twidth_log2 = texImg->WidthLog2; \ + const GLubyte *texture = (const GLubyte *) texImg->Data; \ + const GLint smask = texImg->Width - 1; \ + const GLint tmask = texImg->Height - 1; \ + ASSERT(texImg->TexFormat == MESA_FORMAT_RGB888); \ if (!rb || !texture) { \ return; \ } #define RENDER_SPAN( span ) \ GLuint i; \ - GLchan rgb[MAX_WIDTH][3]; \ + GLubyte rgb[MAX_WIDTH][3]; \ span.intTex[0] -= FIXED_HALF; /* off-by-one error? */ \ span.intTex[1] -= FIXED_HALF; \ for (i = 0; i < span.end; i++) { \ @@ -211,9 +215,9 @@ _swrast_culltriangle( GLcontext *ctx, GLint t = FixedToInt(span.intTex[1]) & tmask; \ GLint pos = (t << twidth_log2) + s; \ pos = pos + pos + pos; /* multiply by 3 */ \ - rgb[i][RCOMP] = texture[pos]; \ + rgb[i][RCOMP] = texture[pos+2]; \ rgb[i][GCOMP] = texture[pos+1]; \ - rgb[i][BCOMP] = texture[pos+2]; \ + rgb[i][BCOMP] = texture[pos+0]; \ zRow[i] = z; \ span.array->mask[i] = 1; \ } \ @@ -276,25 +280,29 @@ affine_span(GLcontext *ctx, SWspan *span, * unused variables (for instance tf,sf,ti,si in case of GL_NEAREST). */ -#define NEAREST_RGB \ - sample[RCOMP] = tex00[RCOMP]; \ - sample[GCOMP] = tex00[GCOMP]; \ - sample[BCOMP] = tex00[BCOMP]; \ - sample[ACOMP] = CHAN_MAX +#define NEAREST_RGB \ + sample[RCOMP] = tex00[2]; \ + sample[GCOMP] = tex00[1]; \ + sample[BCOMP] = tex00[0]; \ + sample[ACOMP] = CHAN_MAX; #define LINEAR_RGB \ - sample[RCOMP] = ilerp_2d(sf, tf, tex00[0], tex01[0], tex10[0], tex11[0]);\ + sample[RCOMP] = ilerp_2d(sf, tf, tex00[2], tex01[2], tex10[2], tex11[2]);\ sample[GCOMP] = ilerp_2d(sf, tf, tex00[1], tex01[1], tex10[1], tex11[1]);\ - sample[BCOMP] = ilerp_2d(sf, tf, tex00[2], tex01[2], tex10[2], tex11[2]);\ + sample[BCOMP] = ilerp_2d(sf, tf, tex00[0], tex01[0], tex10[0], tex11[0]);\ sample[ACOMP] = CHAN_MAX; -#define NEAREST_RGBA COPY_CHAN4(sample, tex00) +#define NEAREST_RGBA \ + sample[RCOMP] = tex00[3]; \ + sample[GCOMP] = tex00[2]; \ + sample[BCOMP] = tex00[1]; \ + sample[ACOMP] = tex00[0]; #define LINEAR_RGBA \ - sample[RCOMP] = ilerp_2d(sf, tf, tex00[0], tex01[0], tex10[0], tex11[0]);\ - sample[GCOMP] = ilerp_2d(sf, tf, tex00[1], tex01[1], tex10[1], tex11[1]);\ - sample[BCOMP] = ilerp_2d(sf, tf, tex00[2], tex01[2], tex10[2], tex11[2]);\ - sample[ACOMP] = ilerp_2d(sf, tf, tex00[3], tex01[3], tex10[3], tex11[3]) + sample[RCOMP] = ilerp_2d(sf, tf, tex00[3], tex01[3], tex10[3], tex11[3]);\ + sample[GCOMP] = ilerp_2d(sf, tf, tex00[2], tex01[2], tex10[2], tex11[2]);\ + sample[BCOMP] = ilerp_2d(sf, tf, tex00[1], tex01[1], tex10[1], tex11[1]);\ + sample[ACOMP] = ilerp_2d(sf, tf, tex00[0], tex01[0], tex10[0], tex11[0]) #define MODULATE \ dest[RCOMP] = span->red * (sample[RCOMP] + 1u) >> (FIXED_SHIFT + 8); \ @@ -345,7 +353,11 @@ affine_span(GLcontext *ctx, SWspan *span, dest[2] = sample[2]; \ dest[3] = FixedToInt(span->alpha); -#define NEAREST_RGBA_REPLACE COPY_CHAN4(dest, tex00) +#define NEAREST_RGBA_REPLACE \ + dest[RCOMP] = tex00[3]; \ + dest[GCOMP] = tex00[2]; \ + dest[BCOMP] = tex00[1]; \ + dest[ACOMP] = tex00[0] #define SPAN_NEAREST(DO_TEX, COMPS) \ for (i = 0; i < span->end; i++) { \ @@ -406,7 +418,7 @@ affine_span(GLcontext *ctx, SWspan *span, switch (info->filter) { case GL_NEAREST: switch (info->format) { - case GL_RGB: + case MESA_FORMAT_RGB888: switch (info->envmode) { case GL_MODULATE: SPAN_NEAREST(NEAREST_RGB;MODULATE,3); @@ -426,7 +438,7 @@ affine_span(GLcontext *ctx, SWspan *span, return; } break; - case GL_RGBA: + case MESA_FORMAT_RGBA8888: switch(info->envmode) { case GL_MODULATE: SPAN_NEAREST(NEAREST_RGBA;MODULATE,4); @@ -455,7 +467,7 @@ affine_span(GLcontext *ctx, SWspan *span, span->intTex[0] -= FIXED_HALF; span->intTex[1] -= FIXED_HALF; switch (info->format) { - case GL_RGB: + case MESA_FORMAT_RGB888: switch (info->envmode) { case GL_MODULATE: SPAN_LINEAR(LINEAR_RGB;MODULATE,3); @@ -475,7 +487,7 @@ affine_span(GLcontext *ctx, SWspan *span, return; } break; - case GL_RGBA: + case MESA_FORMAT_RGBA8888: switch (info->envmode) { case GL_MODULATE: SPAN_LINEAR(LINEAR_RGBA;MODULATE,4); @@ -528,16 +540,17 @@ affine_span(GLcontext *ctx, SWspan *span, #define SETUP_CODE \ struct affine_info info; \ struct gl_texture_unit *unit = ctx->Texture.Unit+0; \ - struct gl_texture_object *obj = \ + const struct gl_texture_object *obj = \ ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX]; \ - const GLint b = obj->BaseLevel; \ - const GLfloat twidth = (GLfloat) obj->Image[0][b]->Width; \ - const GLfloat theight = (GLfloat) obj->Image[0][b]->Height; \ - info.texture = (const GLchan *) obj->Image[0][b]->Data; \ - info.twidth_log2 = obj->Image[0][b]->WidthLog2; \ - info.smask = obj->Image[0][b]->Width - 1; \ - info.tmask = obj->Image[0][b]->Height - 1; \ - info.format = obj->Image[0][b]->_BaseFormat; \ + const struct gl_texture_image *texImg = \ + obj->Image[0][obj->BaseLevel]; \ + const GLfloat twidth = (GLfloat) texImg->Width; \ + const GLfloat theight = (GLfloat) texImg->Height; \ + info.texture = (const GLchan *) texImg->Data; \ + info.twidth_log2 = texImg->WidthLog2; \ + info.smask = texImg->Width - 1; \ + info.tmask = texImg->Height - 1; \ + info.format = texImg->TexFormat; \ info.filter = obj->MinFilter; \ info.envmode = unit->EnvMode; \ span.arrayMask |= SPAN_RGBA; \ @@ -555,25 +568,17 @@ affine_span(GLcontext *ctx, SWspan *span, } \ \ switch (info.format) { \ - case GL_ALPHA: \ - case GL_LUMINANCE: \ - case GL_INTENSITY: \ - info.tbytesline = obj->Image[0][b]->Width; \ - break; \ - case GL_LUMINANCE_ALPHA: \ - info.tbytesline = obj->Image[0][b]->Width * 2; \ + case MESA_FORMAT_RGB888: \ + info.tbytesline = texImg->Width * 3; \ break; \ - case GL_RGB: \ - info.tbytesline = obj->Image[0][b]->Width * 3; \ - break; \ - case GL_RGBA: \ - info.tbytesline = obj->Image[0][b]->Width * 4; \ + case MESA_FORMAT_RGBA8888: \ + info.tbytesline = texImg->Width * 4; \ break; \ default: \ _mesa_problem(NULL, "Bad texture format in affine_texture_triangle");\ return; \ } \ - info.tsize = obj->Image[0][b]->Height * info.tbytesline; + info.tsize = texImg->Height * info.tbytesline; #define RENDER_SPAN( span ) affine_span(ctx, &span, &info); @@ -680,7 +685,7 @@ fast_persp_span(GLcontext *ctx, SWspan *span, switch (info->filter) { case GL_NEAREST: switch (info->format) { - case GL_RGB: + case MESA_FORMAT_RGB888: switch (info->envmode) { case GL_MODULATE: SPAN_NEAREST(NEAREST_RGB;MODULATE,3); @@ -700,7 +705,7 @@ fast_persp_span(GLcontext *ctx, SWspan *span, return; } break; - case GL_RGBA: + case MESA_FORMAT_RGBA8888: switch(info->envmode) { case GL_MODULATE: SPAN_NEAREST(NEAREST_RGBA;MODULATE,4); @@ -727,7 +732,7 @@ fast_persp_span(GLcontext *ctx, SWspan *span, case GL_LINEAR: switch (info->format) { - case GL_RGB: + case MESA_FORMAT_RGB888: switch (info->envmode) { case GL_MODULATE: SPAN_LINEAR(LINEAR_RGB;MODULATE,3); @@ -747,7 +752,7 @@ fast_persp_span(GLcontext *ctx, SWspan *span, return; } break; - case GL_RGBA: + case MESA_FORMAT_RGBA8888: switch (info->envmode) { case GL_MODULATE: SPAN_LINEAR(LINEAR_RGBA;MODULATE,4); @@ -799,14 +804,15 @@ fast_persp_span(GLcontext *ctx, SWspan *span, #define SETUP_CODE \ struct persp_info info; \ const struct gl_texture_unit *unit = ctx->Texture.Unit+0; \ - struct gl_texture_object *obj = \ + const struct gl_texture_object *obj = \ ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX]; \ - const GLint b = obj->BaseLevel; \ - info.texture = (const GLchan *) obj->Image[0][b]->Data; \ - info.twidth_log2 = obj->Image[0][b]->WidthLog2; \ - info.smask = obj->Image[0][b]->Width - 1; \ - info.tmask = obj->Image[0][b]->Height - 1; \ - info.format = obj->Image[0][b]->_BaseFormat; \ + const struct gl_texture_image *texImg = \ + obj->Image[0][obj->BaseLevel]; \ + info.texture = (const GLchan *) texImg->Data; \ + info.twidth_log2 = texImg->WidthLog2; \ + info.smask = texImg->Width - 1; \ + info.tmask = texImg->Height - 1; \ + info.format = texImg->TexFormat; \ info.filter = obj->MinFilter; \ info.envmode = unit->EnvMode; \ \ @@ -823,25 +829,17 @@ fast_persp_span(GLcontext *ctx, SWspan *span, } \ \ switch (info.format) { \ - case GL_ALPHA: \ - case GL_LUMINANCE: \ - case GL_INTENSITY: \ - info.tbytesline = obj->Image[0][b]->Width; \ - break; \ - case GL_LUMINANCE_ALPHA: \ - info.tbytesline = obj->Image[0][b]->Width * 2; \ - break; \ - case GL_RGB: \ - info.tbytesline = obj->Image[0][b]->Width * 3; \ + case MESA_FORMAT_RGB888: \ + info.tbytesline = texImg->Width * 3; \ break; \ - case GL_RGBA: \ - info.tbytesline = obj->Image[0][b]->Width * 4; \ + case MESA_FORMAT_RGBA8888: \ + info.tbytesline = texImg->Width * 4; \ break; \ default: \ _mesa_problem(NULL, "Bad texture format in persp_textured_triangle");\ return; \ } \ - info.tsize = obj->Image[0][b]->Height * info.tbytesline; + info.tsize = texImg->Height * info.tbytesline; #define RENDER_SPAN( span ) \ span.interpMask &= ~SPAN_RGBA; \ @@ -883,7 +881,7 @@ fast_persp_span(GLcontext *ctx, SWspan *span, return; \ } #define RENDER_SPAN( span ) \ - if (rb->DepthBits <= 16) { \ + if (rb->Format == MESA_FORMAT_Z16) { \ GLuint i; \ const GLushort *zRow = (const GLushort *) \ rb->GetPointer(ctx, rb, span.x, span.y); \ @@ -1055,19 +1053,20 @@ _swrast_choose_triangle( GLcontext *ctx ) const struct gl_texture_object *texObj2D; const struct gl_texture_image *texImg; GLenum minFilter, magFilter, envMode; - GLint format; + gl_format format; texObj2D = ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX]; texImg = texObj2D ? texObj2D->Image[0][texObj2D->BaseLevel] : NULL; - format = texImg ? texImg->TexFormat->MesaFormat : -1; - minFilter = texObj2D ? texObj2D->MinFilter : (GLenum) 0; - magFilter = texObj2D ? texObj2D->MagFilter : (GLenum) 0; + format = texImg ? texImg->TexFormat : MESA_FORMAT_NONE; + minFilter = texObj2D ? texObj2D->MinFilter : GL_NONE; + magFilter = texObj2D ? texObj2D->MagFilter : GL_NONE; envMode = ctx->Texture.Unit[0].EnvMode; /* First see if we can use an optimized 2-D texture function */ if (ctx->Texture._EnabledCoordUnits == 0x1 && !ctx->FragmentProgram._Current && !ctx->ATIFragmentShader._Enabled + && ctx->Texture._EnabledUnits == 0x1 && ctx->Texture.Unit[0]._ReallyEnabled == TEXTURE_2D_BIT && texObj2D->WrapS == GL_REPEAT && texObj2D->WrapT == GL_REPEAT @@ -1075,7 +1074,7 @@ _swrast_choose_triangle( GLcontext *ctx ) && texImg->_IsPowerOfTwo && texImg->Border == 0 && texImg->Width == texImg->RowStride - && (format == MESA_FORMAT_RGB || format == MESA_FORMAT_RGBA) + && (format == MESA_FORMAT_RGB888 || format == MESA_FORMAT_RGBA8888) && minFilter == magFilter && ctx->Light.Model.ColorControl == GL_SINGLE_COLOR && !swrast->_FogEnabled @@ -1083,7 +1082,7 @@ _swrast_choose_triangle( GLcontext *ctx ) && ctx->Texture.Unit[0].EnvMode != GL_COMBINE4_NV) { if (ctx->Hint.PerspectiveCorrection==GL_FASTEST) { if (minFilter == GL_NEAREST - && format == MESA_FORMAT_RGB + && format == MESA_FORMAT_RGB888 && (envMode == GL_REPLACE || envMode == GL_DECAL) && ((swrast->_RasterMask == (DEPTH_BIT | TEXTURE_BIT) && ctx->Depth.Func == GL_LESS @@ -1102,7 +1101,15 @@ _swrast_choose_triangle( GLcontext *ctx ) #if CHAN_BITS != 8 USE(general_triangle); #else - USE(affine_textured_triangle); + if (format == MESA_FORMAT_RGBA8888 && !_mesa_little_endian()) { + /* We only handle RGBA8888 correctly on little endian + * in the optimized code above. + */ + USE(general_triangle); + } + else { + USE(affine_textured_triangle); + } #endif } } |