#include "st_context.h"
#include "st_atom.h"
#include "st_texture.h"
+#include "st_format.h"
#include "st_cb_texture.h"
#include "pipe/p_context.h"
#include "util/u_inlines.h"
static INLINE struct pipe_sampler_view *
st_create_texture_sampler_view_from_stobj(struct pipe_context *pipe,
- struct st_texture_object *stObj)
+ struct st_texture_object *stObj,
+ enum pipe_format format)
{
struct pipe_sampler_view templ;
u_sampler_view_default_template(&templ,
stObj->pt,
- stObj->pt->format);
+ format);
if (stObj->base._Swizzle != SWIZZLE_NOOP) {
templ.swizzle_r = GET_SWZ(stObj->base._Swizzle, 0);
static INLINE struct pipe_sampler_view *
st_get_texture_sampler_view_from_stobj(struct st_texture_object *stObj,
- struct pipe_context *pipe)
+ struct pipe_context *pipe,
+ enum pipe_format format)
{
if (!stObj || !stObj->pt) {
}
if (!stObj->sampler_view) {
- stObj->sampler_view = st_create_texture_sampler_view_from_stobj(pipe, stObj);
+ stObj->sampler_view = st_create_texture_sampler_view_from_stobj(pipe, stObj, format);
}
return stObj->sampler_view;
/* loop over sampler units (aka tex image units) */
for (su = 0; su < st->ctx->Const.MaxTextureImageUnits; su++) {
struct pipe_sampler_view *sampler_view = NULL;
-
+ enum pipe_format st_view_format;
if (samplersUsed & (1 << su)) {
struct gl_texture_object *texObj;
struct st_texture_object *stObj;
continue;
}
+ st_view_format = stObj->pt->format;
+ {
+ struct st_texture_image *firstImage;
+ enum pipe_format firstImageFormat;
+ firstImage = st_texture_image(stObj->base.Image[0][stObj->base.BaseLevel]);
+
+ firstImageFormat = st_mesa_format_to_pipe_format(firstImage->base.TexFormat);
+ if (firstImageFormat != stObj->pt->format)
+ st_view_format = firstImageFormat;
+
+ }
st->state.num_textures = su + 1;
/* if sampler view has changed dereference it */
if (stObj->sampler_view)
- if (check_sampler_swizzle(stObj->sampler_view, stObj->base._Swizzle))
+ if (check_sampler_swizzle(stObj->sampler_view, stObj->base._Swizzle) || (st_view_format != stObj->sampler_view->format))
pipe_sampler_view_reference(&stObj->sampler_view, NULL);
- sampler_view = st_get_texture_sampler_view_from_stobj(stObj, pipe);
+ sampler_view = st_get_texture_sampler_view_from_stobj(stObj, pipe, st_view_format);
}
pipe_sampler_view_reference(&st->state.sampler_views[su], sampler_view);
}
return GL_FALSE;
}
}
+
+GLboolean
+st_sampler_compat_formats(enum pipe_format format1, enum pipe_format format2)
+{
+ if (format1 == format2)
+ return GL_TRUE;
+
+ if (format1 == PIPE_FORMAT_B8G8R8A8_UNORM &&
+ format2 == PIPE_FORMAT_B8G8R8X8_UNORM)
+ return GL_TRUE;
+
+ if (format1 == PIPE_FORMAT_B8G8R8X8_UNORM &&
+ format2 == PIPE_FORMAT_B8G8R8A8_UNORM)
+ return GL_TRUE;
+
+ if (format1 == PIPE_FORMAT_A8B8G8R8_UNORM &&
+ format2 == PIPE_FORMAT_X8B8G8R8_UNORM)
+ return GL_TRUE;
+
+ if (format1 == PIPE_FORMAT_X8B8G8R8_UNORM &&
+ format2 == PIPE_FORMAT_A8B8G8R8_UNORM)
+ return GL_TRUE;
+
+ if (format1 == PIPE_FORMAT_A8R8G8B8_UNORM &&
+ format2 == PIPE_FORMAT_X8R8G8B8_UNORM)
+ return GL_TRUE;
+
+ if (format1 == PIPE_FORMAT_X8R8G8B8_UNORM &&
+ format2 == PIPE_FORMAT_A8R8G8B8_UNORM)
+ return GL_TRUE;
+
+ return GL_FALSE;
+}
* To avoid that, internal_format is (wrongly) ignored here. A sane fix
* is to use a sampler view.
*/
- if (util_format_get_component_bits(tex->format,
+ if (!st_sampler_compat_formats(tex->format, internal_format))
+ internal_format = tex->format;
+
+ if (util_format_get_component_bits(internal_format,
UTIL_FORMAT_COLORSPACE_RGB, 3) > 0)
internalFormat = GL_RGBA;
else
internalFormat = GL_RGB;
-
_mesa_init_teximage_fields(ctx, target, texImage,
tex->width0, tex->height0, 1, 0, internalFormat);
texImage->TexFormat = st_ChooseTextureFormat(ctx, internalFormat,