<div dir="ltr">Hi Brian,<div><br></div><div>I've made all the recommended changes.</div><div><br></div><div>I also added one, a test that the Driver.TextureView != NULL before calling. This lets me test the non DD functionality with the MESA_EXTENSION_OVERRIDE=+GL_ARB_texture_view</div>
<div><br></div><div>I've also rebased to latest master (no changes required). Whole stream can be found at: <a href="https://github.com/courtney-lunarg/mesa/tree/texture_view-rc6">https://github.com/courtney-lunarg/mesa/tree/texture_view-rc6</a></div>
<div><br></div><div>Let me know if you need me to post the patches to the mail list or not.</div><div><br></div><div>Thanks,</div><div>Courtney</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Dec 3, 2013 at 10:56 AM, Brian Paul <span dir="ltr"><<a href="mailto:brianp@vmware.com" target="_blank">brianp@vmware.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This looks pretty good. Just a bunch of nitpicks below.<div><div class="h5"><br>
<br>
<br>
On 11/25/2013 05:49 PM, Courtney Goeltzenleuchter wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Add Mesa TextureView logic.<br>
Incorporate feedback on ARB_texture_view:<br>
- Add S3TC VIEW_CLASSes to compatibility table<br>
- Use existing _mesa_get_tex_image<br>
- Clean up error strings<br>
- Use bool instead of GLboolean for internal functions<br>
- Split compound level & layer test into individual tests<br>
<br>
Signed-off-by: Courtney Goeltzenleuchter <courtney@LunarG.com><br>
---<br>
src/mesa/main/textureview.c | 540 ++++++++++++++++++++++++++++++<u></u>+++++++++++++-<br>
1 file changed, 539 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/src/mesa/main/textureview.c b/src/mesa/main/textureview.c<br>
index 4a6bd62..1bfc86b 100644<br>
--- a/src/mesa/main/textureview.c<br>
+++ b/src/mesa/main/textureview.c<br>
@@ -38,10 +38,318 @@<br>
#include "macros.h"<br>
#include "teximage.h"<br>
#include "texobj.h"<br>
+#include "mipmap.h"<br>
#include "texstorage.h"<br>
#include "textureview.h"<br>
+#include "stdbool.h"<br>
#include "mtypes.h"<br>
<br>
+/* Table 3.X.2 (Compatible internal formats for TextureView)<br>
+ ------------------------------<u></u>------------------------------<u></u>---------------<br>
+ | Class | Internal formats |<br>
+ ------------------------------<u></u>------------------------------<u></u>---------------<br>
+ | VIEW_CLASS_128_BITS | RGBA32F, RGBA32UI, RGBA32I |<br>
+ ------------------------------<u></u>------------------------------<u></u>---------------<br>
+ | VIEW_CLASS_96_BITS | RGB32F, RGB32UI, RGB32I |<br>
+ ------------------------------<u></u>------------------------------<u></u>---------------<br>
+ | VIEW_CLASS_64_BITS | RGBA16F, RG32F, RGBA16UI, RG32UI, RGBA16I, |<br>
+ | | RG32I, RGBA16, RGBA16_SNORM |<br>
+ ------------------------------<u></u>------------------------------<u></u>---------------<br>
+ | VIEW_CLASS_48_BITS | RGB16, RGB16_SNORM, RGB16F, RGB16UI, RGB16I |<br>
+ ------------------------------<u></u>------------------------------<u></u>---------------<br>
+ | VIEW_CLASS_32_BITS | RG16F, R11F_G11F_B10F, R32F, |<br>
+ | | RGB10_A2UI, RGBA8UI, RG16UI, R32UI, |<br>
+ | | RGBA8I, RG16I, R32I, RGB10_A2, RGBA8, RG16, |<br>
+ | | RGBA8_SNORM, RG16_SNORM, SRGB8_ALPHA8, RGB9_E5 |<br>
+ ------------------------------<u></u>------------------------------<u></u>---------------<br>
+ | VIEW_CLASS_24_BITS | RGB8, RGB8_SNORM, SRGB8, RGB8UI, RGB8I |<br>
+ ------------------------------<u></u>------------------------------<u></u>---------------<br>
+ | VIEW_CLASS_16_BITS | R16F, RG8UI, R16UI, RG8I, R16I, RG8, R16, |<br>
+ | | RG8_SNORM, R16_SNORM |<br>
+ ------------------------------<u></u>------------------------------<u></u>---------------<br>
+ | VIEW_CLASS_8_BITS | R8UI, R8I, R8, R8_SNORM |<br>
+ ------------------------------<u></u>------------------------------<u></u>---------------<br>
+ | VIEW_CLASS_RGTC1_RED | COMPRESSED_RED_RGTC1, |<br>
+ | | COMPRESSED_SIGNED_RED_RGTC1 |<br>
+ ------------------------------<u></u>------------------------------<u></u>---------------<br>
+ | VIEW_CLASS_RGTC2_RG | COMPRESSED_RG_RGTC2, |<br>
+ | | COMPRESSED_SIGNED_RG_RGTC2 |<br>
+ ------------------------------<u></u>------------------------------<u></u>---------------<br>
+ | VIEW_CLASS_BPTC_UNORM | COMPRESSED_RGBA_BPTC_UNORM, |<br>
+ | | COMPRESSED_SRGB_ALPHA_BPTC_<u></u>UNORM |<br>
+ ------------------------------<u></u>------------------------------<u></u>---------------<br>
+ | VIEW_CLASS_BPTC_FLOAT | COMPRESSED_RGB_BPTC_SIGNED_<u></u>FLOAT, |<br>
+ | | COMPRESSED_RGB_BPTC_UNSIGNED_<u></u>FLOAT |<br>
+ ------------------------------<u></u>------------------------------<u></u>---------------<br>
+ */<br>
+struct internal_format_class_info {<br>
+ GLenum view_class;<br>
+ GLenum internal_format;<br>
+};<br>
+#define INFO(c,f) {GL_##c, GL_##f}<br>
</blockquote>
<br></div></div>
I'd like to see this INFO() macro stuff go away. It just obfuscates the code.<div><div class="h5"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+static const struct internal_format_class_info compatible_internal_formats[] = {<br>
+ INFO(VIEW_CLASS_128_BITS, RGBA32F),<br>
+ INFO(VIEW_CLASS_128_BITS, RGBA32UI),<br>
+ INFO(VIEW_CLASS_128_BITS, RGBA32I),<br>
+ INFO(VIEW_CLASS_96_BITS, RGB32F),<br>
+ INFO(VIEW_CLASS_96_BITS, RGB32UI),<br>
+ INFO(VIEW_CLASS_96_BITS, RGB32I),<br>
+ INFO(VIEW_CLASS_64_BITS, RGBA16F),<br>
+ INFO(VIEW_CLASS_64_BITS, RG32F),<br>
+ INFO(VIEW_CLASS_64_BITS, RGBA16UI),<br>
+ INFO(VIEW_CLASS_64_BITS, RG32UI),<br>
+ INFO(VIEW_CLASS_64_BITS, RGBA16I),<br>
+ INFO(VIEW_CLASS_64_BITS, RG32I),<br>
+ INFO(VIEW_CLASS_64_BITS, RGBA16),<br>
+ INFO(VIEW_CLASS_64_BITS, RGBA16_SNORM),<br>
+ INFO(VIEW_CLASS_48_BITS, RGB16),<br>
+ INFO(VIEW_CLASS_48_BITS, RGB16_SNORM),<br>
+ INFO(VIEW_CLASS_48_BITS, RGB16F),<br>
+ INFO(VIEW_CLASS_48_BITS, RGB16UI),<br>
+ INFO(VIEW_CLASS_48_BITS, RGB16I),<br>
+ INFO(VIEW_CLASS_32_BITS, RG16F),<br>
+ INFO(VIEW_CLASS_32_BITS, R11F_G11F_B10F),<br>
+ INFO(VIEW_CLASS_32_BITS, R32F),<br>
+ INFO(VIEW_CLASS_32_BITS, RGB10_A2UI),<br>
+ INFO(VIEW_CLASS_32_BITS, RGBA8UI),<br>
+ INFO(VIEW_CLASS_32_BITS, RG16UI),<br>
+ INFO(VIEW_CLASS_32_BITS, R32UI),<br>
+ INFO(VIEW_CLASS_32_BITS, RGBA8I),<br>
+ INFO(VIEW_CLASS_32_BITS, RG16I),<br>
+ INFO(VIEW_CLASS_32_BITS, R32I),<br>
+ INFO(VIEW_CLASS_32_BITS, RGB10_A2),<br>
+ INFO(VIEW_CLASS_32_BITS, RGBA8),<br>
+ INFO(VIEW_CLASS_32_BITS, RG16),<br>
+ INFO(VIEW_CLASS_32_BITS, RGBA8_SNORM),<br>
+ INFO(VIEW_CLASS_32_BITS, RG16_SNORM),<br>
+ INFO(VIEW_CLASS_32_BITS, SRGB8_ALPHA8),<br>
+ INFO(VIEW_CLASS_32_BITS, RGB9_E5),<br>
+ INFO(VIEW_CLASS_24_BITS, RGB8),<br>
+ INFO(VIEW_CLASS_24_BITS, RGB8_SNORM),<br>
+ INFO(VIEW_CLASS_24_BITS, SRGB8),<br>
+ INFO(VIEW_CLASS_24_BITS, RGB8UI),<br>
+ INFO(VIEW_CLASS_24_BITS, RGB8I),<br>
+ INFO(VIEW_CLASS_16_BITS, R16F),<br>
+ INFO(VIEW_CLASS_16_BITS, RG8UI),<br>
+ INFO(VIEW_CLASS_16_BITS, R16UI),<br>
+ INFO(VIEW_CLASS_16_BITS, RG8I),<br>
+ INFO(VIEW_CLASS_16_BITS, R16I),<br>
+ INFO(VIEW_CLASS_16_BITS, RG8),<br>
+ INFO(VIEW_CLASS_16_BITS, R16),<br>
+ INFO(VIEW_CLASS_16_BITS, RG8_SNORM),<br>
+ INFO(VIEW_CLASS_16_BITS, R16_SNORM),<br>
+ INFO(VIEW_CLASS_8_BITS, R8UI),<br>
+ INFO(VIEW_CLASS_8_BITS, R8I),<br>
+ INFO(VIEW_CLASS_8_BITS, R8),<br>
+ INFO(VIEW_CLASS_8_BITS, R8_SNORM),<br>
+ INFO(VIEW_CLASS_RGTC1_RED, COMPRESSED_RED_RGTC1),<br>
+ INFO(VIEW_CLASS_RGTC1_RED, COMPRESSED_SIGNED_RED_RGTC1),<br>
+ INFO(VIEW_CLASS_RGTC2_RG, COMPRESSED_RG_RGTC2),<br>
+ INFO(VIEW_CLASS_RGTC2_RG, COMPRESSED_SIGNED_RG_RGTC2),<br>
+ INFO(VIEW_CLASS_BPTC_UNORM, COMPRESSED_RGBA_BPTC_UNORM_<u></u>ARB),<br>
+ INFO(VIEW_CLASS_BPTC_UNORM, COMPRESSED_SRGB_ALPHA_BPTC_<u></u>UNORM_ARB),<br>
+ INFO(VIEW_CLASS_BPTC_FLOAT, COMPRESSED_RGB_BPTC_SIGNED_<u></u>FLOAT_ARB),<br>
+ INFO(VIEW_CLASS_BPTC_FLOAT, COMPRESSED_RGB_BPTC_UNSIGNED_<u></u>FLOAT_ARB),<br>
+};<br>
+<br>
+static const struct internal_format_class_info s3tc_compatible_internal_<u></u>formats[] = {<br>
+ INFO(VIEW_CLASS_S3TC_DXT1_RGB, COMPRESSED_RGB_S3TC_DXT1_EXT),<br>
+ INFO(VIEW_CLASS_S3TC_DXT1_RGB, COMPRESSED_SRGB_S3TC_DXT1_EXT)<u></u>,<br>
+ INFO(VIEW_CLASS_S3TC_DXT1_<u></u>RGBA, COMPRESSED_RGBA_S3TC_DXT1_EXT)<u></u>,<br>
+ INFO(VIEW_CLASS_S3TC_DXT1_<u></u>RGBA, COMPRESSED_SRGB_ALPHA_S3TC_<u></u>DXT1_EXT),<br>
+ INFO(VIEW_CLASS_S3TC_DXT3_<u></u>RGBA, COMPRESSED_RGBA_S3TC_DXT3_EXT)<u></u>,<br>
+ INFO(VIEW_CLASS_S3TC_DXT3_<u></u>RGBA, COMPRESSED_SRGB_ALPHA_S3TC_<u></u>DXT3_EXT),<br>
+ INFO(VIEW_CLASS_S3TC_DXT5_<u></u>RGBA, COMPRESSED_RGBA_S3TC_DXT5_EXT)<u></u>,<br>
+ INFO(VIEW_CLASS_S3TC_DXT5_<u></u>RGBA, COMPRESSED_SRGB_ALPHA_S3TC_<u></u>DXT5_EXT),<br>
+};<br>
+#undef INFO<br>
+<br>
+/**<br>
+ * Lookup format view class based on internalformat<br>
+ * \return VIEW_CLASS if internalformat found in table, false otherwise.<br>
+ */<br>
+static GLenum<br>
+lookup_view_class(struct gl_context *ctx, GLenum internalformat)<br>
+{<br>
+ uint i;<br>
+<br>
+ for (i = 0; i < ARRAY_SIZE(compatible_<u></u>internal_formats); i++) {<br>
+ if (compatible_internal_formats[<u></u>i].internal_format == internalformat)<br>
+ return compatible_internal_formats[i]<u></u>.view_class;<br>
+ }<br>
+<br>
+ if (ctx->Extensions.EXT_texture_<u></u>compression_s3tc && ctx->Extensions.EXT_texture_<u></u>sRGB) {<br>
+ for (i = 0; i < ARRAY_SIZE(s3tc_compatible_<u></u>internal_formats); i++) {<br>
+ if (s3tc_compatible_internal_<u></u>formats[i].internal_format == internalformat)<br>
+ return s3tc_compatible_internal_<u></u>formats[i].view_class;<br>
+ }<br>
+ }<br>
+ return GL_FALSE;<br>
+}<br>
+<br>
+/**<br>
+ * Initialize new texture's gl_texture_image structures. Will not call driver<br>
+ * to allocate new space, simply record relevant layer, face, format, etc.<br>
+ * \return GL_FALSE if any error, GL_TRUE otherwise.<br>
+ */<br>
+static GLboolean<br>
+initialize_texture_fields(<u></u>struct gl_context *ctx,<br>
+ GLenum target,<br>
+ struct gl_texture_object *texObj,<br>
+ GLint levels,<br>
+ GLsizei width, GLsizei height, GLsizei depth,<br>
+ GLenum internalFormat, gl_format texFormat)<br>
+{<br>
+ const GLuint numFaces = _mesa_num_tex_faces(target);<br>
+ GLint level, levelWidth = width, levelHeight = height, levelDepth = depth;<br>
+ GLuint face;<br>
+<br>
+ /* Pretend we are bound to initialize the gl_texture_image structs */<br>
+ texObj->Target = target;<br>
+<br>
+ /* Set up all the texture object's gl_texture_images */<br>
+ for (level = 0; level < levels; level++) {<br>
+ for (face = 0; face < numFaces; face++) {<br>
+ struct gl_texture_image *texImage =<br>
+ _mesa_get_tex_image(ctx, texObj, face, level);<br>
+<br>
+ if (!texImage) {<br>
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexStorage");<br>
+ return GL_FALSE;<br>
+ }<br>
+<br>
+ _mesa_init_teximage_fields(<u></u>ctx, texImage,<br>
+ levelWidth, levelHeight, levelDepth,<br>
+ 0, internalFormat, texFormat);<br>
+ }<br>
+<br>
+ _mesa_next_mipmap_level_size(<u></u>target, 0, levelWidth, levelHeight, levelDepth,<br>
+ &levelWidth, &levelHeight, &levelDepth);<br>
+ }<br>
+<br>
+ /* "unbind" */<br>
+ texObj->Target = 0;<br>
+<br>
+ return GL_TRUE;<br>
+}<br>
+<br>
+#define RETURN_IF_SUPPORTED(t) do { \<br>
+ if (newTarget == GL_ ## t) \<br>
+ return true; \<br>
+} while (0)<br>
+<br>
+/**<br>
+ * Check for compatible target<br>
+ * If an error is found, record it with _mesa_error()<br>
+ * \return false if any error, true otherwise.<br>
+ */<br>
+static bool<br>
+target_valid(struct gl_context *ctx, GLenum origTarget, GLenum newTarget)<br>
+{<br>
+ /*<br>
+ * From ARB_texture_view spec:<br>
+ ------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>---------------<br>
+ | Original target | Valid new targets |<br>
+ ------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>---------------<br>
+ | TEXTURE_1D | TEXTURE_1D, TEXTURE_1D_ARRAY |<br>
+ | ------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>------------- |<br>
+ | TEXTURE_2D | TEXTURE_2D, TEXTURE_2D_ARRAY |<br>
+ | ------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>------------- |<br>
+ | TEXTURE_3D | TEXTURE_3D |<br>
+ | ------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>------------- |<br>
+ | TEXTURE_CUBE_MAP | TEXTURE_CUBE_MAP, TEXTURE_2D, TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP_ARRAY |<br>
+ | ------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>------------- |<br>
+ | TEXTURE_RECTANGLE | TEXTURE_RECTANGLE |<br>
+ | ------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>------------- |<br>
+ | TEXTURE_BUFFER | <none> |<br>
+ | ------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>------------- |<br>
+ | TEXTURE_1D_ARRAY | TEXTURE_1D_ARRAY, TEXTURE_1D |<br>
+ | ------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>------------- |<br>
+ | TEXTURE_2D_ARRAY | TEXTURE_2D_ARRAY, TEXTURE_2D, TEXTURE_CUBE_MAP, TEXTURE_CUBE_MAP_ARRAY |<br>
+ | ------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>------------- |<br>
+ | TEXTURE_CUBE_MAP_ARRAY | TEXTURE_CUBE_MAP_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_2D, TEXTURE_CUBE_MAP |<br>
+ | ------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>------------- |<br>
+ | TEXTURE_2D_MULTISAMPLE | TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY |<br>
+ | ------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>------------- |<br>
+ | TEXTURE_2D_MULTISAMPLE_ARRAY | TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY |<br>
+ ------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>---------------<br>
+ */<br>
+<br>
+ switch (origTarget) {<br>
+ case GL_TEXTURE_1D:<br>
+ case GL_TEXTURE_1D_ARRAY:<br>
+ RETURN_IF_SUPPORTED(TEXTURE_<u></u>1D);<br>
+ RETURN_IF_SUPPORTED(TEXTURE_<u></u>1D_ARRAY);<br>
+ break;<br>
+ case GL_TEXTURE_2D:<br>
+ RETURN_IF_SUPPORTED(TEXTURE_<u></u>2D);<br>
+ RETURN_IF_SUPPORTED(TEXTURE_<u></u>2D_ARRAY);<br>
+ break;<br>
+ case GL_TEXTURE_3D:<br>
+ RETURN_IF_SUPPORTED(TEXTURE_<u></u>3D);<br>
+ break;<br>
+ case GL_TEXTURE_RECTANGLE:<br>
+ RETURN_IF_SUPPORTED(TEXTURE_<u></u>RECTANGLE);<br>
+ break;<br>
+ case GL_TEXTURE_CUBE_MAP:<br>
+ case GL_TEXTURE_2D_ARRAY:<br>
+ case GL_TEXTURE_CUBE_MAP_ARRAY:<br>
+ RETURN_IF_SUPPORTED(TEXTURE_<u></u>2D);<br>
+ RETURN_IF_SUPPORTED(TEXTURE_<u></u>2D_ARRAY);<br>
+ RETURN_IF_SUPPORTED(TEXTURE_<u></u>CUBE_MAP);<br>
+ RETURN_IF_SUPPORTED(TEXTURE_<u></u>CUBE_MAP_ARRAY);<br>
+ break;<br>
+ case GL_TEXTURE_2D_MULTISAMPLE:<br>
+ case GL_TEXTURE_2D_MULTISAMPLE_<u></u>ARRAY:<br>
+ RETURN_IF_SUPPORTED(TEXTURE_<u></u>2D_MULTISAMPLE);<br>
+ RETURN_IF_SUPPORTED(TEXTURE_<u></u>2D_MULTISAMPLE_ARRAY);<br>
+ break;<br>
+ }<br>
+ _mesa_error(ctx, GL_INVALID_OPERATION,<br>
+ "glTextureView(illegal target=%s)",<br>
+ _mesa_lookup_enum_by_nr(<u></u>newTarget));<br>
+ return false;<br>
+}<br>
+#undef RETURN_IF_SUPPORTED<br>
+<br>
+/**<br>
+ * Check for compatible format<br>
+ * If an error is found, record it with _mesa_error()<br>
+ * \return false if any error, true otherwise.<br>
+ */<br>
+static bool<br>
+compatible_format(struct gl_context *ctx, const struct gl_texture_object *origTexObj,<br>
+ GLenum internalformat)<br>
+{<br>
+ /* Level 0 of a texture created by glTextureStorage or glTextureView<br>
+ * is always defined.<br>
+ */<br>
+ struct gl_texture_image *texImage = origTexObj->Image[0][0];<br>
+ GLint origInternalFormat = texImage->InternalFormat;<br>
+ unsigned int origViewClass, newViewClass;<br>
+<br>
+<br>
</blockquote>
<br></div></div>
One blank line there would be enough.<div><div class="h5"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ /* The two textures' internal formats must be compatible according to<br>
+ * Table 3.X.2 (Compatible internal formats for TextureView)<br>
+ * if the internal format exists in that table the view class must match.<br>
+ * The internal formats must be identical if not in that table,<br>
+ * or an INVALID_OPERATION error is generated.<br>
+ */<br>
+ if (origInternalFormat == internalformat)<br>
+ return true;<br>
+<br>
+ origViewClass = lookup_view_class(ctx, origInternalFormat);<br>
+ newViewClass = lookup_view_class(ctx, internalformat);<br>
+ if ((origViewClass == newViewClass) && origViewClass != false)<br>
+ return true;<br>
+<br>
+ _mesa_error(ctx, GL_INVALID_OPERATION,<br>
+ "glTextureView(internalformat %s not compatible with origtexture %s)",<br>
+ _mesa_lookup_enum_by_nr(<u></u>internalformat),<br>
+ _mesa_lookup_enum_by_nr(<u></u>origInternalFormat));<br>
+ return false;<br>
+}<br>
+<br>
/**<br>
* glTextureView (ARB_texture_view)<br>
* If an error is found, record it with _mesa_error()<br>
@@ -53,13 +361,243 @@ _mesa_TextureView(GLuint texture, GLenum target, GLuint origtexture,<br>
GLuint minlevel, GLuint numlevels,<br>
GLuint minlayer, GLuint numlayers)<br>
{<br>
+ struct gl_texture_object *texObj;<br>
+ struct gl_texture_object *origTexObj;<br>
+ struct gl_texture_image *origTexImage;<br>
+ GLuint newViewMinLevel, newViewMinLayer;<br>
+ GLuint newViewNumLevels, newViewNumLayers;<br>
+ GLsizei width, height, depth;<br>
+ gl_format texFormat;<br>
+ GLboolean sizeOK, dimensionsOK;<br>
+ GLenum faceTarget;<br>
+<br>
GET_CURRENT_CONTEXT(ctx);<br>
<br>
if (MESA_VERBOSE & (VERBOSE_API | VERBOSE_TEXTURE))<br>
- _mesa_debug(ctx, "glTextureView (unfinished) %d %s %d %s %d %d %d %d\n",<br>
+ _mesa_debug(ctx, "glTextureView %d %s %d %s %d %d %d %d\n",<br>
texture, _mesa_lookup_enum_by_nr(<u></u>target), origtexture,<br>
_mesa_lookup_enum_by_nr(<u></u>internalformat),<br>
minlevel, numlevels, minlayer, numlayers);<br>
<br>
+ if (origtexture == 0) {<br>
+ _mesa_error(ctx, GL_INVALID_VALUE, "glTextureView(origtexture = %d)", origtexture);<br>
</blockquote>
<br></div></div>
%u format for unsigned values.<div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ return;<br>
+ }<br>
+<br>
+ /* Need original texture information to validate arguments */<br>
+ origTexObj = _mesa_lookup_texture(ctx, origtexture);<br>
+<br>
+ /* If <origtexture> is not the name of a texture, INVALID_VALUE is generated. */<br>
+ if (!origTexObj) {<br>
+ _mesa_error(ctx, GL_INVALID_VALUE, "glTextureView(origtexture = %d)", origtexture);<br>
</blockquote>
<br></div>
%u<div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ return;<br>
+ }<br>
+<br>
+ /* If <origtexture>'s TEXTURE_IMMUTABLE_FORMAT value is not TRUE,<br>
+ * INVALID_OPERATION is generated.<br>
+ */<br>
+ if (!origTexObj->Immutable) {<br>
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureView(origtexture not immutable)");<br>
+ return;<br>
+ }<br>
+<br>
+ /* If <texture> is 0, INVALID_VALUE is generated. */<br>
+ if (texture == 0) {<br>
+ _mesa_error(ctx, GL_INVALID_VALUE, "glTextureView(texture = 0)");<br>
+ return;<br>
+ }<br>
+<br>
+ /* If <texture> is not a valid name returned by GenTextures,<br>
+ * the error INVALID_OPERATION is generated.<br>
+ */<br>
+ texObj = _mesa_lookup_texture(ctx, texture);<br>
+ if (texObj == NULL) {<br>
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureView(texture = %d non-gen name)", texture);<br>
</blockquote>
<br></div>
%u<div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ return;<br>
+ }<br>
+<br>
+ /* If <texture> has already been bound and given a target, then<br>
+ * the error INVALID_OPERATION is generated.<br>
+ */<br>
+ if (texObj->Target) {<br>
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureView(texture = %d already bound)", texture);<br>
</blockquote>
<br></div>
%u<div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ return;<br>
+ }<br>
+<br>
+ /* Check for compatible target */<br>
+ if (!target_valid(ctx, origTexObj->Target, target)) {<br>
+ return; /* error was recorded */<br>
+ }<br>
+<br>
+ /* minlevel and minlayer are relative to the view of origtexture */<br>
+ /* If minlevel or minlayer is greater than level or layer, respectively,<br>
+ * of origtexture return INVALID_VALUE.<br>
+ */<br>
</blockquote>
<br></div>
I'd merge those two comments into one block.<div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ newViewMinLevel = origTexObj->MinLevel + minlevel;<br>
+ newViewMinLayer = origTexObj->MinLayer + minlayer;<br>
+ if (newViewMinLevel >= (origTexObj->MinLevel + origTexObj->NumLevels)) {<br>
+ _mesa_error(ctx, GL_INVALID_VALUE, "glTextureView(new minlevel (%d) > orig minlevel (%d) + orig numlevels (%d))",<br>
</blockquote>
<br></div>
Wrap to 78 columns.<div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ newViewMinLevel, origTexObj->MinLevel, origTexObj->NumLevels);<br>
+ return;<br>
+ }<br>
+<br>
+ if (newViewMinLayer >= (origTexObj->MinLayer + origTexObj->NumLayers)) {<br>
+ _mesa_error(ctx, GL_INVALID_VALUE, "glTextureView(new minlayer (%d) > orig minlayer (%d) + orig numlayers (%d))",<br>
</blockquote>
<br></div>
wrap.<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ newViewMinLayer, origTexObj->MinLayer, origTexObj->NumLayers);<br>
+ return;<br>
+ }<br>
+<br>
+ if (!compatible_format(ctx, origTexObj, internalformat)) {<br>
+ return; /* Error logged */<br>
+ }<br>
+<br>
+ texFormat = _mesa_choose_texture_format(<u></u>ctx, texObj, target, 0,<br>
+ internalformat, GL_NONE, GL_NONE);<br>
+ assert(texFormat != MESA_FORMAT_NONE);<br>
+ if (texFormat == MESA_FORMAT_NONE) return;<br>
+<br>
+ newViewNumLevels = MIN2(numlevels, origTexObj->NumLevels - minlevel);<br>
+ newViewNumLayers = MIN2(numlayers, origTexObj->NumLayers - minlayer);<br>
+<br>
+ faceTarget = origTexObj->Target;<br>
+ if (faceTarget == GL_TEXTURE_CUBE_MAP)<br>
+ faceTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + minlayer;<br>
+<br>
+ /* Get a reference to what will become this View's base level */<br>
+ origTexImage = _mesa_select_tex_image(ctx, origTexObj,<br>
+ faceTarget, minlevel);<br>
+ width = origTexImage->Width;<br>
+ height = origTexImage->Height;<br>
+ depth = origTexImage->Depth;<br>
+<br>
+ /* Adjust width, height, depth to be appropriate for new target */<br>
+ switch (target) {<br>
+ case GL_TEXTURE_1D:<br>
+ case GL_TEXTURE_3D:<br>
+ break;<br>
+<br>
+ case GL_TEXTURE_1D_ARRAY:<br>
+ height = (GLsizei) newViewNumLayers;<br>
+ break;<br>
+<br>
+ case GL_TEXTURE_2D:<br>
+ case GL_TEXTURE_2D_MULTISAMPLE:<br>
+ case GL_TEXTURE_RECTANGLE:<br>
+ case GL_TEXTURE_CUBE_MAP:<br>
+ depth = 1;<br>
+ break;<br>
+<br>
+ case GL_TEXTURE_2D_ARRAY:<br>
+ case GL_TEXTURE_CUBE_MAP_ARRAY:<br>
+ case GL_TEXTURE_2D_MULTISAMPLE_<u></u>ARRAY:<br>
+ depth = newViewNumLayers;<br>
+ break;<br>
+ }<br>
+<br>
+ /* If the dimensions of the original texture are larger than the maximum<br>
+ * supported dimensions of the new target, the error INVALID_OPERATION is<br>
+ * generated. For example, if the original texture has a TEXTURE_2D_ARRAY<br>
+ * target and its width is greater than MAX_CUBE_MAP_TEXTURE_SIZE, an error<br>
+ * will be generated if TextureView is called to create a TEXTURE_CUBE_MAP<br>
+ * view.<br>
+ */<br>
+ dimensionsOK = _mesa_legal_texture_<u></u>dimensions(ctx, target, 0,<br>
+ width, height, depth, 0);<br>
+ if (!dimensionsOK) {<br>
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureView(invalid width or height or depth)");<br>
+ return;<br>
+ }<br>
+<br>
+ sizeOK = ctx->Driver.TestProxyTexImage(<u></u>ctx, target, 0, texFormat,<br>
+ width, height, depth, 0);<br>
+ if (!sizeOK) {<br>
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureView(invalid texture size)");<br>
+ return;<br>
+ }<br>
+<br>
+ /* If <target> is TEXTURE_1D, TEXTURE_2D, TEXTURE_3D, TEXTURE_RECTANGLE,<br>
+ * or TEXTURE_2D_MULTISAMPLE and <numlayers> does not equal 1, the error<br>
+ * INVALID_VALUE is generated.<br>
+ */<br>
+ switch (target) {<br>
+ case GL_TEXTURE_1D:<br>
+ case GL_TEXTURE_2D:<br>
+ case GL_TEXTURE_3D:<br>
+ case GL_TEXTURE_RECTANGLE:<br>
+ case GL_TEXTURE_2D_MULTISAMPLE:<br>
+ if (numlayers != 1) {<br>
+ _mesa_error(ctx, GL_INVALID_VALUE, "glTextureView(numlayers %d != 1)", numlayers);<br>
+ return;<br>
+ }<br>
+ break;<br>
+<br>
+ case GL_TEXTURE_CUBE_MAP:<br>
+ /* If the new texture's target is TEXTURE_CUBE_MAP, the clamped <numlayers><br>
+ * must be equal to 6.<br>
+ */<br>
+ if (newViewNumLayers != 6) {<br>
+ _mesa_error(ctx, GL_INVALID_VALUE, "glTextureView(clamped numlayers %d != 6)",<br>
+ newViewNumLayers);<br>
+ return;<br>
+ }<br>
+ break;<br>
+<br>
+ case GL_TEXTURE_CUBE_MAP_ARRAY:<br>
+ /* If the new texture's target is TEXTURE_CUBE_MAP_ARRAY,<br>
+ * then <numlayers> counts layer-faces rather than layers,<br>
+ * and the clamped <numlayers> must be a multiple of 6.<br>
+ * Otherwise, the error INVALID_VALUE is generated.<br>
+ */<br>
+ if ((newViewNumLayers % 6) != 0) {<br>
+ _mesa_error(ctx, GL_INVALID_VALUE,<br>
+ "glTextureView(clamped numlayers %d is not a multiple of 6)",<br>
+ newViewNumLayers);<br>
+ return;<br>
+ }<br>
+ break;<br>
+ }<br>
+<br>
+ /* If the new texture's target is TEXTURE_CUBE_MAP or<br>
+ * TEXTURE_CUBE_MAP_ARRAY, the width and height of the original texture's<br>
+ * levels must be equal otherwise the error INVALID_OPERATION is generated.<br>
+ */<br>
+ if ((target == GL_TEXTURE_CUBE_MAP || target == GL_TEXTURE_CUBE_MAP_ARRAY) &&<br>
+ (origTexImage->Width != origTexImage->Height)) {<br>
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureView(origtexture width (%d) != height (%d))",<br>
+ origTexImage->Width, origTexImage->Height);<br>
+ return;<br>
+ }<br>
+<br>
+ /* When the original texture's target is TEXTURE_CUBE_MAP, the layer<br>
+ * parameters are interpreted in the same order as if it were a<br>
+ * TEXTURE_CUBE_MAP_ARRAY with 6 layer-faces.<br>
+ */<br>
+<br>
+ /* If the internal format does not exactly match the internal format of the<br>
+ * original texture, the contents of the memory are reinterpreted in the<br>
+ * same manner as for image bindings described in<br>
+ * section 3.9.20 (Texture Image Loads and Stores).<br>
+ */<br>
+<br>
+ /* TEXTURE_BASE_LEVEL and TEXTURE_MAX_LEVEL are interpreted<br>
+ * relative to the view and not relative to the original data store.<br>
+ */<br>
+<br>
+ if (!initialize_texture_fields(<u></u>ctx, target, texObj, newViewNumLevels,<br>
+ width, height, depth,<br>
+ internalformat, texFormat)) {<br>
+ return; /* Already recorded error */<br>
+ }<br>
+<br>
+ texObj->MinLevel = newViewMinLevel;<br>
+ texObj->MinLayer = newViewMinLayer;<br>
+ texObj->NumLevels = newViewNumLevels;<br>
+ texObj->NumLayers = newViewNumLayers;<br>
+ texObj->Immutable = GL_TRUE;<br>
+ texObj->ImmutableLevels = origTexObj->ImmutableLevels;<br>
+ texObj->Target = target;<br>
<br>
+ if (!ctx->Driver.TextureView(ctx, texObj, origTexObj)) {<br>
+ return; /* driver recorded error */<br>
+ }<br>
}<br>
<br>
</blockquote>
<br></div></div><div class="HOEnZb"><div class="h5">
______________________________<u></u>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/<u></u>mailman/listinfo/mesa-dev</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">Courtney Goeltzenleuchter<br><div>LunarG</div><div><img src="http://media.lunarg.com/wp-content/themes/LunarG/images/logo.png" width="96" height="65"><br>
</div></div>
</div>