summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian <brian.paul@tungstengraphics.com>2008-02-11 09:43:30 -0700
committerBrian <brian.paul@tungstengraphics.com>2008-02-11 09:46:50 -0700
commitc22d9152e33792ea58426c53bc9b96bf552b0b44 (patch)
tree4f93496da5d2dc3ab727c394cb91ec9f305e7c13
parente4026167d70f0aa0bc0cd2546ef9b41f7b167735 (diff)
code refactoring, new next_mipmap_level_size() function
-rw-r--r--src/mesa/main/mipmap.c75
1 files changed, 50 insertions, 25 deletions
diff --git a/src/mesa/main/mipmap.c b/src/mesa/main/mipmap.c
index ed7795aef9..721a227bb5 100644
--- a/src/mesa/main/mipmap.c
+++ b/src/mesa/main/mipmap.c
@@ -895,6 +895,51 @@ _mesa_generate_mipmap_level(GLenum target,
/**
+ * compute next (level+1) image size
+ * \return GL_FALSE if no smaller size can be generated (eg. src is 1x1x1 size)
+ */
+static GLboolean
+next_mipmap_level_size(GLenum target, GLint border,
+ GLint srcWidth, GLint srcHeight, GLint srcDepth,
+ GLint *dstWidth, GLint *dstHeight, GLint *dstDepth)
+{
+ if (srcWidth - 2 * border > 1) {
+ *dstWidth = (srcWidth - 2 * border) / 2 + 2 * border;
+ }
+ else {
+ *dstWidth = srcWidth; /* can't go smaller */
+ }
+
+ if ((srcHeight - 2 * border > 1) &&
+ (target != GL_TEXTURE_1D_ARRAY_EXT)) {
+ *dstHeight = (srcHeight - 2 * border) / 2 + 2 * border;
+ }
+ else {
+ *dstHeight = srcHeight; /* can't go smaller */
+ }
+
+ if ((srcDepth - 2 * border > 1) &&
+ (target != GL_TEXTURE_2D_ARRAY_EXT)) {
+ *dstDepth = (srcDepth - 2 * border) / 2 + 2 * border;
+ }
+ else {
+ *dstDepth = srcDepth; /* can't go smaller */
+ }
+
+ if (*dstWidth == srcWidth &&
+ *dstHeight == srcHeight &&
+ *dstDepth == srcDepth) {
+ return GL_FALSE;
+ }
+ else {
+ return GL_TRUE;
+ }
+}
+
+
+
+
+/**
* For GL_SGIX_generate_mipmap:
* Generate a complete set of mipmaps from texObj's base-level image.
* Stop at texObj's MaxLevel or when we get to the 1x1 texture.
@@ -982,6 +1027,7 @@ _mesa_generate_mipmap(GLcontext *ctx, GLenum target,
GLint srcWidth, srcHeight, srcDepth;
GLint dstWidth, dstHeight, dstDepth;
GLint border, bytesPerTexel;
+ GLboolean nextLevel;
/* get src image parameters */
srcImage = _mesa_select_tex_image(ctx, texObj, target, level);
@@ -991,31 +1037,10 @@ _mesa_generate_mipmap(GLcontext *ctx, GLenum target,
srcDepth = srcImage->Depth;
border = srcImage->Border;
- /* compute next (level+1) image size */
- if (srcWidth - 2 * border > 1) {
- dstWidth = (srcWidth - 2 * border) / 2 + 2 * border;
- }
- else {
- dstWidth = srcWidth; /* can't go smaller */
- }
- if ((srcHeight - 2 * border > 1) &&
- (texObj->Target != GL_TEXTURE_1D_ARRAY_EXT)) {
- dstHeight = (srcHeight - 2 * border) / 2 + 2 * border;
- }
- else {
- dstHeight = srcHeight; /* can't go smaller */
- }
- if ((srcDepth - 2 * border > 1) &&
- (texObj->Target != GL_TEXTURE_2D_ARRAY_EXT)) {
- dstDepth = (srcDepth - 2 * border) / 2 + 2 * border;
- }
- else {
- dstDepth = srcDepth; /* can't go smaller */
- }
-
- if (dstWidth == srcWidth &&
- dstHeight == srcHeight &&
- dstDepth == srcDepth) {
+ nextLevel = next_mipmap_level_size(target, border,
+ srcWidth, srcHeight, srcDepth,
+ &dstWidth, &dstHeight, &dstDepth);
+ if (!nextLevel) {
/* all done */
if (srcImage->IsCompressed) {
_mesa_free((void *) srcData);