[Mesa-dev] [PATCH] st/mesa: fix integer texture border color for some formats
Brian Paul
brianp at vmware.com
Mon Oct 15 06:37:22 PDT 2012
On 10/15/2012 07:24 AM, Marek Olšák wrote:
> And the clear color too, though that maybe an issue only with GL_RGB if it's
> actually RGBA in the driver.
>
> NOTE: This is a candidate for the stable branches.
> ---
> src/mesa/state_tracker/st_atom_sampler.c | 8 +-
> src/mesa/state_tracker/st_cb_clear.c | 13 +++-
> src/mesa/state_tracker/st_format.c | 118 ++++++++++++++++++++----------
> src/mesa/state_tracker/st_format.h | 2 +-
> 4 files changed, 99 insertions(+), 42 deletions(-)
>
> diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c
> index adcc7b5..1a58a65 100644
> --- a/src/mesa/state_tracker/st_atom_sampler.c
> +++ b/src/mesa/state_tracker/st_atom_sampler.c
> @@ -34,6 +34,7 @@
>
> #include "main/macros.h"
> #include "main/mtypes.h"
> +#include "main/glformats.h"
> #include "main/samplerobj.h"
> #include "main/texobj.h"
>
> @@ -172,12 +173,17 @@ convert_sampler(struct st_context *st,
> msamp->BorderColor.ui[2] ||
> msamp->BorderColor.ui[3]) {
> struct gl_texture_image *teximg;
> + GLboolean is_integer = GL_FALSE;
>
> teximg = texobj->Image[0][texobj->BaseLevel];
>
> + if (teximg) {
> + is_integer = _mesa_is_enum_format_integer(teximg->InternalFormat);
> + }
> +
> st_translate_color(msamp->BorderColor.f,
> teximg ? teximg->_BaseFormat : GL_RGBA,
> - sampler->border_color.f);
> + sampler->border_color.f, is_integer);
> }
>
> sampler->max_anisotropy = (msamp->MaxAnisotropy == 1.0 ?
> diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c
> index e731b6b..4795baf 100644
> --- a/src/mesa/state_tracker/st_cb_clear.c
> +++ b/src/mesa/state_tracker/st_cb_clear.c
> @@ -37,6 +37,7 @@
> #include "main/accum.h"
> #include "main/formats.h"
> #include "main/macros.h"
> +#include "main/glformats.h"
> #include "program/prog_instruction.h"
> #include "st_context.h"
> #include "st_atom.h"
> @@ -301,9 +302,12 @@ clear_with_quad(struct gl_context *ctx,
> cso_set_geometry_shader_handle(st->cso_context, NULL);
>
> if (ctx->DrawBuffer->_ColorDrawBuffers[0]) {
> + struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0];
> + GLboolean is_integer = _mesa_is_enum_format_integer(rb->InternalFormat);
> +
> st_translate_color(ctx->Color.ClearColor.f,
> - ctx->DrawBuffer->_ColorDrawBuffers[0]->_BaseFormat,
> - clearColor.f);
> + ctx->DrawBuffer->_ColorDrawBuffers[0]->_BaseFormat,
> + clearColor.f, is_integer);
> }
>
> /* draw quad matching scissor rect */
> @@ -540,9 +544,12 @@ st_Clear(struct gl_context *ctx, GLbitfield mask)
> clear_buffers |= PIPE_CLEAR_DEPTHSTENCIL;
>
> if (ctx->DrawBuffer->_ColorDrawBuffers[0]) {
> + struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0];
> + GLboolean is_integer = _mesa_is_enum_format_integer(rb->InternalFormat);
> +
> st_translate_color(ctx->Color.ClearColor.f,
> ctx->DrawBuffer->_ColorDrawBuffers[0]->_BaseFormat,
> - clearColor.f);
> + clearColor.f, is_integer);
> }
>
> st->pipe->clear(st->pipe, clear_buffers,&clearColor,
> diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c
> index a9ff2cd..7f49540 100644
> --- a/src/mesa/state_tracker/st_format.c
> +++ b/src/mesa/state_tracker/st_format.c
> @@ -1687,43 +1687,87 @@ st_sampler_compat_formats(enum pipe_format format1, enum pipe_format format2)
> */
> void
> st_translate_color(const GLfloat colorIn[4], GLenum baseFormat,
> - GLfloat colorOut[4])
> + GLfloat colorOut[4], GLboolean is_integer)
We should probably change colorIn to be gl_color_union instead of
float and colorOut to be pipe_color_union.
Otherwise this looks good.
> {
> - switch (baseFormat) {
> - case GL_RED:
> - colorOut[0] = colorIn[0];
> - colorOut[1] = 0.0F;
> - colorOut[2] = 0.0F;
> - colorOut[3] = 1.0F;
> - break;
> - case GL_RG:
> - colorOut[0] = colorIn[0];
> - colorOut[1] = colorIn[1];
> - colorOut[2] = 0.0F;
> - colorOut[3] = 1.0F;
> - break;
> - case GL_RGB:
> - colorOut[0] = colorIn[0];
> - colorOut[1] = colorIn[1];
> - colorOut[2] = colorIn[2];
> - colorOut[3] = 1.0F;
> - break;
> - case GL_ALPHA:
> - colorOut[0] = colorOut[1] = colorOut[2] = 0.0;
> - colorOut[3] = colorIn[3];
> - break;
> - case GL_LUMINANCE:
> - colorOut[0] = colorOut[1] = colorOut[2] = colorIn[0];
> - colorOut[3] = 1.0;
> - break;
> - case GL_LUMINANCE_ALPHA:
> - colorOut[0] = colorOut[1] = colorOut[2] = colorIn[0];
> - colorOut[3] = colorIn[3];
> - break;
> - case GL_INTENSITY:
> - colorOut[0] = colorOut[1] = colorOut[2] = colorOut[3] = colorIn[0];
> - break;
> - default:
> - COPY_4V(colorOut, colorIn);
> + if (is_integer) {
> + int *icolorIn = (int*)colorIn;
> + int *icolorOut = (int*)colorOut;
> +
> + switch (baseFormat) {
> + case GL_RED:
> + icolorOut[0] = icolorIn[0];
> + icolorOut[1] = 0;
> + icolorOut[2] = 0;
> + icolorOut[3] = 1;
> + break;
> + case GL_RG:
> + icolorOut[0] = icolorIn[0];
> + icolorOut[1] = icolorIn[1];
> + icolorOut[2] = 0;
> + icolorOut[3] = 1;
> + break;
> + case GL_RGB:
> + icolorOut[0] = icolorIn[0];
> + icolorOut[1] = icolorIn[1];
> + icolorOut[2] = icolorIn[2];
> + icolorOut[3] = 1;
> + break;
> + case GL_ALPHA:
> + icolorOut[0] = icolorOut[1] = icolorOut[2] = 0;
> + icolorOut[3] = icolorIn[3];
> + break;
> + case GL_LUMINANCE:
> + icolorOut[0] = icolorOut[1] = icolorOut[2] = icolorIn[0];
> + icolorOut[3] = 1;
> + break;
> + case GL_LUMINANCE_ALPHA:
> + icolorOut[0] = icolorOut[1] = icolorOut[2] = icolorIn[0];
> + icolorOut[3] = icolorIn[3];
> + break;
> + case GL_INTENSITY:
> + icolorOut[0] = icolorOut[1] = icolorOut[2] = icolorOut[3] = icolorIn[0];
> + break;
> + default:
> + COPY_4V(icolorOut, icolorIn);
> + }
> + }
> + else {
> + switch (baseFormat) {
> + case GL_RED:
> + colorOut[0] = colorIn[0];
> + colorOut[1] = 0.0F;
> + colorOut[2] = 0.0F;
> + colorOut[3] = 1.0F;
> + break;
> + case GL_RG:
> + colorOut[0] = colorIn[0];
> + colorOut[1] = colorIn[1];
> + colorOut[2] = 0.0F;
> + colorOut[3] = 1.0F;
> + break;
> + case GL_RGB:
> + colorOut[0] = colorIn[0];
> + colorOut[1] = colorIn[1];
> + colorOut[2] = colorIn[2];
> + colorOut[3] = 1.0F;
> + break;
> + case GL_ALPHA:
> + colorOut[0] = colorOut[1] = colorOut[2] = 0.0;
> + colorOut[3] = colorIn[3];
> + break;
> + case GL_LUMINANCE:
> + colorOut[0] = colorOut[1] = colorOut[2] = colorIn[0];
> + colorOut[3] = 1.0;
> + break;
> + case GL_LUMINANCE_ALPHA:
> + colorOut[0] = colorOut[1] = colorOut[2] = colorIn[0];
> + colorOut[3] = colorIn[3];
> + break;
> + case GL_INTENSITY:
> + colorOut[0] = colorOut[1] = colorOut[2] = colorOut[3] = colorIn[0];
> + break;
> + default:
> + COPY_4V(colorOut, colorIn);
> + }
> }
> }
> diff --git a/src/mesa/state_tracker/st_format.h b/src/mesa/state_tracker/st_format.h
> index 2eef2c0..d87ef3d 100644
> --- a/src/mesa/state_tracker/st_format.h
> +++ b/src/mesa/state_tracker/st_format.h
> @@ -76,6 +76,6 @@ st_sampler_compat_formats(enum pipe_format format1, enum pipe_format format2);
>
> extern void
> st_translate_color(const GLfloat colorIn[4], GLenum baseFormat,
> - GLfloat colorOut[4]);
> + GLfloat colorOut[4], GLboolean is_integer);
>
> #endif /* ST_FORMAT_H */
More information about the mesa-dev
mailing list