[Mesa-dev] [PATCH 12/12] mesa: create, use new _mesa_texture_base_format() function
Brian Paul
brianp at vmware.com
Fri Jan 2 16:55:02 PST 2015
---
src/mesa/main/ff_fragment_shader.cpp | 2 +-
src/mesa/main/texobj.c | 14 ++++++++++++++
src/mesa/main/texobj.h | 3 +++
src/mesa/state_tracker/st_atom_sampler.c | 4 +---
src/mesa/state_tracker/st_atom_texture.c | 7 +++----
src/mesa/swrast/s_texfilter.c | 2 +-
6 files changed, 23 insertions(+), 9 deletions(-)
diff --git a/src/mesa/main/ff_fragment_shader.cpp b/src/mesa/main/ff_fragment_shader.cpp
index bc6fdbd..c682892 100644
--- a/src/mesa/main/ff_fragment_shader.cpp
+++ b/src/mesa/main/ff_fragment_shader.cpp
@@ -418,7 +418,7 @@ static GLuint make_state_key( struct gl_context *ctx, struct state_key *key )
continue;
samp = _mesa_get_samplerobj(ctx, i);
- format = texObj->Image[0][texObj->BaseLevel]->_BaseFormat;
+ format = _mesa_texture_base_format(texObj);
key->unit[i].enabled = 1;
key->enabled_units |= (1<<i);
diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index f0ff605..d199bd7 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -954,6 +954,20 @@ _mesa_total_texture_memory(struct gl_context *ctx)
}
+/**
+ * Return the base format for the given texture object by looking
+ * at the base texture image.
+ * \return base format (such as GL_RGBA) or GL_NONE if it can't be determined
+ */
+GLenum
+_mesa_texture_base_format(const struct gl_texture_object *texObj)
+{
+ const struct gl_texture_image *texImage = _mesa_base_tex_image(texObj);
+
+ return texImage ? texImage->_BaseFormat : GL_NONE;
+}
+
+
static struct gl_texture_object *
invalidate_tex_image_error_check(struct gl_context *ctx, GLuint texture,
GLint level, const char *name)
diff --git a/src/mesa/main/texobj.h b/src/mesa/main/texobj.h
index efcd766..f33991d 100644
--- a/src/mesa/main/texobj.h
+++ b/src/mesa/main/texobj.h
@@ -165,6 +165,9 @@ _mesa_get_fallback_texture(struct gl_context *ctx, gl_texture_index tex);
extern GLuint
_mesa_total_texture_memory(struct gl_context *ctx);
+extern GLenum
+_mesa_texture_base_format(const struct gl_texture_object *texObj);
+
extern void
_mesa_unlock_context_textures( struct gl_context *ctx );
diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c
index f8d7cd7..b68eb16 100644
--- a/src/mesa/state_tracker/st_atom_sampler.c
+++ b/src/mesa/state_tracker/st_atom_sampler.c
@@ -134,7 +134,6 @@ convert_sampler(struct st_context *st,
const struct gl_texture_object *texobj;
struct gl_context *ctx = st->ctx;
struct gl_sampler_object *msamp;
- const struct gl_texture_image *teximg;
GLenum texBaseFormat;
texobj = ctx->Texture.Unit[texUnit]._Current;
@@ -142,8 +141,7 @@ convert_sampler(struct st_context *st,
texobj = _mesa_get_fallback_texture(ctx, TEXTURE_2D_INDEX);
}
- teximg = _mesa_base_tex_image_const(texobj);
- texBaseFormat = teximg ? teximg->_BaseFormat : GL_RGBA;
+ texBaseFormat = _mesa_texture_base_format(texobj);
msamp = _mesa_get_samplerobj(ctx, texUnit);
diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c
index c95e36a..eff28fc 100644
--- a/src/mesa/state_tracker/st_atom_texture.c
+++ b/src/mesa/state_tracker/st_atom_texture.c
@@ -176,12 +176,11 @@ compute_texture_format_swizzle(GLenum baseFormat, GLenum depthMode,
static unsigned
get_texture_format_swizzle(const struct st_texture_object *stObj)
{
- const struct gl_texture_image *texImage =
- _mesa_base_tex_image_const(&stObj->base);
+ 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);
}
diff --git a/src/mesa/swrast/s_texfilter.c b/src/mesa/swrast/s_texfilter.c
index 8a1b045..fa79fdc 100644
--- a/src/mesa/swrast/s_texfilter.c
+++ b/src/mesa/swrast/s_texfilter.c
@@ -833,7 +833,7 @@ apply_depth_mode(GLenum depthMode, GLfloat z, GLfloat texel[4])
static GLboolean
is_depth_texture(const struct gl_texture_object *tObj)
{
- GLenum format = tObj->Image[0][tObj->BaseLevel]->_BaseFormat;
+ GLenum format = _mesa_texture_base_format(tObj);
return format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL_EXT;
}
--
1.9.1
More information about the mesa-dev
mailing list