mesa: rewrite/consolidate code in _mesa_test_texobj_completeness()

Merge the mipmap level checking code that was separate cases for 1D,
2D, 3D and CUBE before.

Reviewed-by: José Fonseca <jfonseca@vmware.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
This commit is contained in:
Brian Paul 2012-03-17 16:30:03 -06:00
parent e86d0dea8e
commit d335e69b9a

View file

@ -531,179 +531,86 @@ _mesa_test_texobj_completeness( const struct gl_context *ctx,
} }
} }
/* extra checking for mipmaps */ /*
* Do mipmap consistency checking
*/
if (t->Sampler.MinFilter != GL_NEAREST && t->Sampler.MinFilter != GL_LINEAR) { if (t->Sampler.MinFilter != GL_NEAREST && t->Sampler.MinFilter != GL_LINEAR) {
/* /*
* Mipmapping: determine if we have a complete set of mipmaps * Mipmapping: determine if we have a complete set of mipmaps
*/ */
GLint i; GLint i;
GLint minLevel = baseLevel; const GLint minLevel = baseLevel;
GLint maxLevel = t->_MaxLevel; const GLint maxLevel = t->_MaxLevel;
GLuint width, height, depth, face, numFaces = 1;
if (minLevel > maxLevel) { if (minLevel > maxLevel) {
incomplete(t, "minLevel > maxLevel"); incomplete(t, "minLevel > maxLevel");
return; return;
} }
/* Test dimension-independent attributes */ /* Get the base image's dimensions */
for (i = minLevel; i <= maxLevel; i++) { width = baseImage->Width2;
if (t->Image[0][i]) { height = baseImage->Height2;
if (t->Image[0][i]->TexFormat != baseImage->TexFormat) { depth = baseImage->Depth2;
incomplete(t, "Format[i] != Format[baseLevel]");
return;
}
if (t->Image[0][i]->Border != baseImage->Border) {
incomplete(t, "Border[i] != Border[baseLevel]");
return;
}
}
}
/* Test things which depend on number of texture image dimensions */ /* Note: this loop will be a no-op for RECT, BUFFER, EXTERNAL textures */
if ((t->Target == GL_TEXTURE_1D) || for (i = baseLevel + 1; i < maxLevels; i++) {
(t->Target == GL_TEXTURE_1D_ARRAY_EXT)) { /* Compute the expected size of image at level[i] */
/* Test 1-D mipmaps */ if (width > 1) {
GLuint width = baseImage->Width2; width /= 2;
for (i = baseLevel + 1; i < maxLevels; i++) {
if (width > 1) {
width /= 2;
}
if (i >= minLevel && i <= maxLevel) {
const struct gl_texture_image *img = t->Image[0][i];
if (!img) {
incomplete(t, "1D Image[%d] is missing", i);
return;
}
if (img->Width2 != width ) {
incomplete(t, "1D Image[%d] bad width %u", i, img->Width2);
return;
}
}
if (width == 1) {
return; /* found smallest needed mipmap, all done! */
}
} }
} if (height > 1 && t->Target != GL_TEXTURE_1D_ARRAY) {
else if ((t->Target == GL_TEXTURE_2D) || height /= 2;
(t->Target == GL_TEXTURE_2D_ARRAY_EXT)) { }
/* Test 2-D mipmaps */ if (depth > 1 && t->Target != GL_TEXTURE_2D_ARRAY) {
GLuint width = baseImage->Width2; depth /= 2;
GLuint height = baseImage->Height2; }
for (i = baseLevel + 1; i < maxLevels; i++) {
if (width > 1) { /* loop over cube faces (or single face otherwise) */
width /= 2; for (face = 0; face < numFaces; face++) {
}
if (height > 1) {
height /= 2;
}
if (i >= minLevel && i <= maxLevel) { if (i >= minLevel && i <= maxLevel) {
const struct gl_texture_image *img = t->Image[0][i]; const struct gl_texture_image *img = t->Image[face][i];
if (!img) { if (!img) {
incomplete(t, "2D Image[%d of %d] is missing", i, maxLevel); incomplete(t, "TexImage[%d] is missing", i);
return;
}
if (img->TexFormat != baseImage->TexFormat) {
incomplete(t, "Format[i] != Format[baseLevel]");
return;
}
if (img->Border != baseImage->Border) {
incomplete(t, "Border[i] != Border[baseLevel]");
return; return;
} }
if (img->Width2 != width) { if (img->Width2 != width) {
incomplete(t, "2D Image[%d] bad width %u", i, img->Width2); incomplete(t, "TexImage[%d] bad width %u", i, img->Width2);
return; return;
} }
if (img->Height2 != height) { if (img->Height2 != height) {
incomplete(t, "2D Image[i] bad height %u", i, img->Height2); incomplete(t, "TexImage[%d] bad height %u", i, img->Height2);
return;
}
if (width==1 && height==1) {
return; /* found smallest needed mipmap, all done! */
}
}
}
}
else if (t->Target == GL_TEXTURE_3D) {
/* Test 3-D mipmaps */
GLuint width = baseImage->Width2;
GLuint height = baseImage->Height2;
GLuint depth = baseImage->Depth2;
for (i = baseLevel + 1; i < maxLevels; i++) {
if (width > 1) {
width /= 2;
}
if (height > 1) {
height /= 2;
}
if (depth > 1) {
depth /= 2;
}
if (i >= minLevel && i <= maxLevel) {
const struct gl_texture_image *img = t->Image[0][i];
if (!img) {
incomplete(t, "3D Image[%d] is missing", i);
return;
}
if (img->_BaseFormat == GL_DEPTH_COMPONENT) {
incomplete(t, "GL_DEPTH_COMPONENT only works with 1/2D tex");
return;
}
if (img->Width2 != width) {
incomplete(t, "3D Image[%d] bad width %u", i, img->Width2);
return;
}
if (img->Height2 != height) {
incomplete(t, "3D Image[%d] bad height %u", i, img->Height2);
return; return;
} }
if (img->Depth2 != depth) { if (img->Depth2 != depth) {
incomplete(t, "3D Image[%d] bad depth %u", i, img->Depth2); incomplete(t, "TexImage[%d] bad depth %u", i, img->Depth2);
return; return;
} }
}
if (width == 1 && height == 1 && depth == 1) { /* Extra checks for cube textures */
return; /* found smallest needed mipmap, all done! */ if (face > 0) {
} /* check that cube faces are the same size */
} if (img->Width2 != t->Image[0][i]->Width2 ||
} img->Height2 != t->Image[0][i]->Height2) {
else if (t->Target == GL_TEXTURE_CUBE_MAP_ARB) {
/* make sure 6 cube faces are consistant */
GLuint width = baseImage->Width2;
GLuint height = baseImage->Height2;
for (i = baseLevel + 1; i < maxLevels; i++) {
if (width > 1) {
width /= 2;
}
if (height > 1) {
height /= 2;
}
if (i >= minLevel && i <= maxLevel) {
GLuint face;
for (face = 0; face < 6; face++) {
/* check that we have images defined */
if (!t->Image[face][i]) {
incomplete(t, "CubeMap Image[n][i] == NULL");
return;
}
/* Don't support GL_DEPTH_COMPONENT for cube maps */
if (ctx->VersionMajor < 3 && !ctx->Extensions.EXT_gpu_shader4) {
if (t->Image[face][i]->_BaseFormat == GL_DEPTH_COMPONENT) {
incomplete(t, "GL_DEPTH_COMPONENT only works with 1/2D tex");
return;
}
}
/* check that all six images have same size */
if (t->Image[face][i]->Width2 != width ||
t->Image[face][i]->Height2 != height) {
incomplete(t, "CubeMap Image[n][i] bad size"); incomplete(t, "CubeMap Image[n][i] bad size");
return; return;
} }
} }
}
if (width == 1 && height == 1) {
return; /* found smallest needed mipmap, all done! */
} }
} }
}
else if (t->Target == GL_TEXTURE_RECTANGLE_NV) { if (width == 1 && height == 1 && depth == 1) {
/* XXX special checking? */ return; /* found smallest needed mipmap, all done! */
} }
else {
/* Target = ??? */
_mesa_problem(ctx, "Bug in gl_test_texture_object_completeness\n");
} }
} }
} }