#include "main/macros.h"
#include "main/mtypes.h"
#include "main/samplerobj.h"
+#include "main/teximage.h"
#include "main/texobj.h"
#include "program/prog_instruction.h"
static unsigned
get_texture_format_swizzle(const struct st_texture_object *stObj)
{
- const struct gl_texture_image *texImage =
- stObj->base.Image[0][stObj->base.BaseLevel];
+ GLenum baseFormat = _mesa_texture_base_format(&stObj->base);
unsigned tex_swizzle;
- if (texImage) {
- tex_swizzle = compute_texture_format_swizzle(texImage->_BaseFormat,
+ if (baseFormat != GL_NONE) {
+ tex_swizzle = compute_texture_format_swizzle(baseFormat,
stObj->base.DepthMode,
stObj->pt->format);
}
static unsigned last_layer(struct st_texture_object *stObj)
{
- if (stObj->base.Immutable)
+ if (stObj->base.Immutable && stObj->pt->array_size > 1)
return MIN2(stObj->base.MinLayer + stObj->base.NumLayers - 1,
stObj->pt->array_size - 1);
return stObj->pt->array_size - 1;
enum pipe_format format)
{
struct pipe_sampler_view **sv;
-
+ const struct st_texture_image *firstImage;
if (!stObj || !stObj->pt) {
return NULL;
}
sv = st_texture_get_sampler_view(st, stObj);
- if (stObj->base.StencilSampling &&
- util_format_is_depth_and_stencil(format))
- format = util_format_stencil_only(format);
+ if (util_format_is_depth_and_stencil(format)) {
+ if (stObj->base.StencilSampling)
+ format = util_format_stencil_only(format);
+ else {
+ firstImage = st_texture_image_const(_mesa_base_tex_image(&stObj->base));
+ if (firstImage->base._BaseFormat == GL_STENCIL_INDEX)
+ format = util_format_stencil_only(format);
+ }
+ }
/* if sampler view has changed dereference it */
if (*sv) {