[Mesa-dev] [PATCH 2/4] mesa: new _mesa_num_tex_faces() helper

Brian Paul brianp at vmware.com
Tue Aug 21 19:29:35 PDT 2012


Not a real big help now, but will be useful for the
GL_ARB_texture_cube_map_array extension in the future.
---
 src/mesa/drivers/dri/intel/intel_tex.c           |    2 +-
 src/mesa/drivers/dri/intel/intel_tex_validate.c  |    7 ++++---
 src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c |    4 ++--
 src/mesa/drivers/dri/radeon/radeon_texture.c     |    4 ++--
 src/mesa/main/mipmap.c                           |    3 ++-
 src/mesa/main/texobj.c                           |    4 ++--
 src/mesa/main/texobj.h                           |   11 +++++++++++
 src/mesa/main/texstorage.c                       |    5 +++--
 src/mesa/state_tracker/st_cb_texture.c           |    2 +-
 src/mesa/swrast/s_texture.c                      |    5 +++--
 10 files changed, 31 insertions(+), 16 deletions(-)

diff --git a/src/mesa/drivers/dri/intel/intel_tex.c b/src/mesa/drivers/dri/intel/intel_tex.c
index 4abe988..5d93879 100644
--- a/src/mesa/drivers/dri/intel/intel_tex.c
+++ b/src/mesa/drivers/dri/intel/intel_tex.c
@@ -120,7 +120,7 @@ intel_alloc_texture_storage(struct gl_context *ctx,
                             GLsizei levels, GLsizei width,
                             GLsizei height, GLsizei depth)
 {
-   const int numFaces = (texObj->Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
+   const int numFaces = _mesa_num_tex_faces(texObj->Target);
    int face;
    int level;
 
diff --git a/src/mesa/drivers/dri/intel/intel_tex_validate.c b/src/mesa/drivers/dri/intel/intel_tex_validate.c
index 34bbbb8..77c9329 100644
--- a/src/mesa/drivers/dri/intel/intel_tex_validate.c
+++ b/src/mesa/drivers/dri/intel/intel_tex_validate.c
@@ -1,6 +1,7 @@
 #include "main/mtypes.h"
 #include "main/macros.h"
 #include "main/samplerobj.h"
+#include "main/texobj.h"
 
 #include "intel_context.h"
 #include "intel_mipmap_tree.h"
@@ -95,7 +96,7 @@ intel_finalize_mipmap_tree(struct intel_context *intel, GLuint unit)
 
    /* Pull in any images not in the object's tree:
     */
-   nr_faces = (intelObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
+   nr_faces = _mesa_num_tex_faces(intelObj->base.Target);
    for (face = 0; face < nr_faces; face++) {
       for (i = tObj->BaseLevel; i <= intelObj->_MaxLevel; i++) {
          struct intel_texture_image *intelImage =
@@ -181,7 +182,7 @@ intel_tex_map_images(struct intel_context *intel,
 		     struct intel_texture_object *intelObj,
 		     GLbitfield mode)
 {
-   GLuint nr_faces = (intelObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
+   GLuint nr_faces = _mesa_num_tex_faces(intelObj->base.Target);
    int i, face;
 
    DBG("%s\n", __FUNCTION__);
@@ -200,7 +201,7 @@ void
 intel_tex_unmap_images(struct intel_context *intel,
 		       struct intel_texture_object *intelObj)
 {
-   GLuint nr_faces = (intelObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
+   GLuint nr_faces = _mesa_num_tex_faces(intelObj->base.Target);
    int i, face;
 
    for (i = intelObj->base.BaseLevel; i <= intelObj->_MaxLevel; i++) {
diff --git a/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c b/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c
index 0ef6457..8901090 100644
--- a/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c
+++ b/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c
@@ -198,7 +198,7 @@ radeon_mipmap_tree* radeon_miptree_create(radeonContextPtr rmesa,
 	mt->mesaFormat = mesaFormat;
 	mt->refcount = 1;
 	mt->target = target;
-	mt->faces = (target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
+	mt->faces = _mesa_num_tex_faces(target);
 	mt->baseLevel = baseLevel;
 	mt->numLevels = numLevels;
 	mt->width0 = width0;
@@ -569,7 +569,7 @@ int radeon_validate_texture_miptree(struct gl_context * ctx,
 			"%s: Using miptree %p\n", __FUNCTION__, t->mt);
 	}
 
-	const unsigned faces = texObj->Target == GL_TEXTURE_CUBE_MAP ? 6 : 1;
+	const unsigned faces = _mesa_num_tex_faces(texObj->Target);
 	unsigned face, level;
 	radeon_texture_image *img;
 	/* Validate only the levels that will actually be used during rendering */
diff --git a/src/mesa/drivers/dri/radeon/radeon_texture.c b/src/mesa/drivers/dri/radeon/radeon_texture.c
index 157cc09..11b825d 100644
--- a/src/mesa/drivers/dri/radeon/radeon_texture.c
+++ b/src/mesa/drivers/dri/radeon/radeon_texture.c
@@ -750,7 +750,7 @@ radeon_swrast_map_texture_images(struct gl_context *ctx,
 				 struct gl_texture_object *texObj)
 {
 	radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
-	GLuint nr_faces = (texObj->Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
+	GLuint nr_faces = _mesa_num_tex_faces(texObj->Target);
 	int i, face;
 
 	for (i = texObj->BaseLevel; i <= texObj->_MaxLevel; i++) {
@@ -766,7 +766,7 @@ radeon_swrast_unmap_texture_images(struct gl_context *ctx,
 				   struct gl_texture_object *texObj)
 {
 	radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
-	GLuint nr_faces = (texObj->Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
+	GLuint nr_faces = _mesa_num_tex_faces(texObj->Target);
 	int i, face;
 
 	for (i = texObj->BaseLevel; i <= texObj->_MaxLevel; i++) {
diff --git a/src/mesa/main/mipmap.c b/src/mesa/main/mipmap.c
index 00d3e8f..15373ba 100644
--- a/src/mesa/main/mipmap.c
+++ b/src/mesa/main/mipmap.c
@@ -33,6 +33,7 @@
 #include "mipmap.h"
 #include "mtypes.h"
 #include "teximage.h"
+#include "texobj.h"
 #include "texstore.h"
 #include "image.h"
 #include "macros.h"
@@ -1817,7 +1818,7 @@ _mesa_prepare_mipmap_level(struct gl_context *ctx,
                            GLsizei width, GLsizei height, GLsizei depth,
                            GLsizei border, GLenum intFormat, gl_format format)
 {
-   const GLuint numFaces = texObj->Target == GL_TEXTURE_CUBE_MAP ? 6 : 1;
+   const GLuint numFaces = _mesa_num_tex_faces(texObj->Target);
    GLuint face;
 
    if (texObj->Immutable) {
diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index 1d905b6..795e47c 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -577,7 +577,7 @@ _mesa_test_texobj_completeness( const struct gl_context *ctx,
       GLint i;
       const GLint minLevel = baseLevel;
       const GLint maxLevel = t->_MaxLevel;
-      const GLuint numFaces = t->Target == GL_TEXTURE_CUBE_MAP ? 6 : 1;
+      const GLuint numFaces = _mesa_num_tex_faces(t->Target);
       GLuint width, height, depth, face;
 
       if (minLevel > maxLevel) {
@@ -826,7 +826,7 @@ _mesa_get_fallback_texture(struct gl_context *ctx, gl_texture_index tex)
 static GLuint
 texture_size(const struct gl_texture_object *texObj)
 {
-   const GLuint numFaces = texObj->Target == GL_TEXTURE_CUBE_MAP ? 6 : 1;
+   const GLuint numFaces = _mesa_num_tex_faces(texObj->Target);
    GLuint face, level, size = 0;
 
    for (face = 0; face < numFaces; face++) {
diff --git a/src/mesa/main/texobj.h b/src/mesa/main/texobj.h
index 93e0d77..a6f1d3a 100644
--- a/src/mesa/main/texobj.h
+++ b/src/mesa/main/texobj.h
@@ -78,6 +78,17 @@ _mesa_reference_texobj(struct gl_texture_object **ptr,
 }
 
 
+/**
+ * Return number of faces for a texture target.  This will be 6 for
+ * cube maps (and cube map arrays) and 1 otherwise.
+ */
+static inline GLuint
+_mesa_num_tex_faces(GLenum target)
+{
+   return target == GL_TEXTURE_CUBE_MAP ? 6 : 1;
+}
+
+
 /** Is the texture "complete" with respect to the given sampler state? */
 static inline GLboolean
 _mesa_is_texture_complete(const struct gl_texture_object *texObj,
diff --git a/src/mesa/main/texstorage.c b/src/mesa/main/texstorage.c
index 5e1f31a..f8af8bf 100644
--- a/src/mesa/main/texstorage.c
+++ b/src/mesa/main/texstorage.c
@@ -36,6 +36,7 @@
 #include "macros.h"
 #include "mfeatures.h"
 #include "teximage.h"
+#include "texobj.h"
 #include "texstorage.h"
 #include "mtypes.h"
 
@@ -128,7 +129,7 @@ setup_texstorage(struct gl_context *ctx,
                  GLsizei width, GLsizei height, GLsizei depth)
 {
    const GLenum target = texObj->Target;
-   const GLuint numFaces = (target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
+   const GLuint numFaces = _mesa_num_tex_faces(target);
    gl_format texFormat;
    GLint level, levelWidth = width, levelHeight = height, levelDepth = depth;
    GLuint face;
@@ -206,7 +207,7 @@ clear_image_fields(struct gl_context *ctx,
                    struct gl_texture_object *texObj)
 {
    const GLenum target = texObj->Target;
-   const GLuint numFaces = (target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
+   const GLuint numFaces = _mesa_num_tex_faces(target);
    GLint level;
    GLuint face;
 
diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
index a7c732b..3de96ad 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -1299,7 +1299,7 @@ st_AllocTextureStorage(struct gl_context *ctx,
                        GLsizei levels, GLsizei width,
                        GLsizei height, GLsizei depth)
 {
-   const GLuint numFaces = (texObj->Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
+   const GLuint numFaces = _mesa_num_tex_faces(texObj->Target);
    struct st_context *st = st_context(ctx);
    struct st_texture_object *stObj = st_texture_object(texObj);
    GLuint ptWidth, ptHeight, ptDepth, ptLayers, bindings;
diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c
index 8df4b84..1b73d46 100644
--- a/src/mesa/swrast/s_texture.c
+++ b/src/mesa/swrast/s_texture.c
@@ -29,6 +29,7 @@
 #include "main/context.h"
 #include "main/fbobject.h"
 #include "main/teximage.h"
+#include "main/texobj.h"
 #include "swrast/swrast.h"
 #include "swrast/s_context.h"
 
@@ -246,7 +247,7 @@ _swrast_unmap_teximage(struct gl_context *ctx,
 void
 _swrast_map_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
 {
-   const GLuint faces = texObj->Target == GL_TEXTURE_CUBE_MAP ? 6 : 1;
+   const GLuint faces = _mesa_num_tex_faces(texObj->Target);
    GLuint face, level;
 
    for (face = 0; face < faces; face++) {
@@ -267,7 +268,7 @@ _swrast_map_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
 void
 _swrast_unmap_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
 {
-   const GLuint faces = texObj->Target == GL_TEXTURE_CUBE_MAP ? 6 : 1;
+   const GLuint faces = _mesa_num_tex_faces(texObj->Target);
    GLuint face, level;
 
    for (face = 0; face < faces; face++) {
-- 
1.7.3.4



More information about the mesa-dev mailing list