<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote">On Fri, Nov 22, 2013 at 10:09 AM, Marek Olšák <span dir="ltr"><<a href="mailto:maraeo@gmail.com" target="_blank">maraeo@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Courtney,<br>
<br>
The VIEW_CLASS_S3TC_* classes should be added too. See the section<br>
"Dependencies on EXT_texture_compression_s3tc".<br></blockquote><div><br></div><div>Got it.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<span class="HOEnZb"><font color="#888888"><br>
Marek<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Wed, Nov 20, 2013 at 12:16 AM, Courtney Goeltzenleuchter<br>
<<a href="mailto:courtney@lunarg.com">courtney@lunarg.com</a>> wrote:<br>
> Add Mesa TextureView logic.<br>
> Incorporate feedback on ARB_texture_view<br>
><br>
> Signed-off-by: Courtney Goeltzenleuchter <courtney@LunarG.com><br>
> ---<br>
>  src/mesa/main/textureview.c | 562 +++++++++++++++++++++++++++++++++++++++++++-<br>
>  1 file changed, 561 insertions(+), 1 deletion(-)<br>
><br>
> diff --git a/src/mesa/main/textureview.c b/src/mesa/main/textureview.c<br>
> index 4a6bd62..1858465 100644<br>
> --- a/src/mesa/main/textureview.c<br>
> +++ b/src/mesa/main/textureview.c<br>
> @@ -40,8 +40,346 @@<br>
>  #include "texobj.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>
> +    ---------------------------------------------------------------------------<br>
> +    | Class                 | Internal formats                                |<br>
> +    ---------------------------------------------------------------------------<br>
> +    | VIEW_CLASS_128_BITS   | RGBA32F, RGBA32UI, RGBA32I                      |<br>
> +    ---------------------------------------------------------------------------<br>
> +    | VIEW_CLASS_96_BITS    | RGB32F, RGB32UI, RGB32I                         |<br>
> +    ---------------------------------------------------------------------------<br>
> +    | VIEW_CLASS_64_BITS    | RGBA16F, RG32F, RGBA16UI, RG32UI, RGBA16I,      |<br>
> +    |                       | RG32I, RGBA16, RGBA16_SNORM                     |<br>
> +    ---------------------------------------------------------------------------<br>
> +    | VIEW_CLASS_48_BITS    | RGB16, RGB16_SNORM, RGB16F, RGB16UI, RGB16I     |<br>
> +    ---------------------------------------------------------------------------<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>
> +    ---------------------------------------------------------------------------<br>
> +    | VIEW_CLASS_24_BITS    | RGB8, RGB8_SNORM, SRGB8, RGB8UI, RGB8I          |<br>
> +    ---------------------------------------------------------------------------<br>
> +    | VIEW_CLASS_16_BITS    | R16F, RG8UI, R16UI, RG8I, R16I, RG8, R16,       |<br>
> +    |                       | RG8_SNORM, R16_SNORM                            |<br>
> +    ---------------------------------------------------------------------------<br>
> +    | VIEW_CLASS_8_BITS     | R8UI, R8I, R8, R8_SNORM                         |<br>
> +    ---------------------------------------------------------------------------<br>
> +    | VIEW_CLASS_RGTC1_RED  | COMPRESSED_RED_RGTC1,                           |<br>
> +    |                       | COMPRESSED_SIGNED_RED_RGTC1                     |<br>
> +    ---------------------------------------------------------------------------<br>
> +    | VIEW_CLASS_RGTC2_RG   | COMPRESSED_RG_RGTC2,                            |<br>
> +    |                       | COMPRESSED_SIGNED_RG_RGTC2                      |<br>
> +    ---------------------------------------------------------------------------<br>
> +    | VIEW_CLASS_BPTC_UNORM | COMPRESSED_RGBA_BPTC_UNORM,                     |<br>
> +    |                       | COMPRESSED_SRGB_ALPHA_BPTC_UNORM                |<br>
> +    ---------------------------------------------------------------------------<br>
> +    | VIEW_CLASS_BPTC_FLOAT | COMPRESSED_RGB_BPTC_SIGNED_FLOAT,               |<br>
> +    |                       | COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT              |<br>
> +    ---------------------------------------------------------------------------<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>
> +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_ARB),<br>
> +   INFO(VIEW_CLASS_BPTC_UNORM, COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB),<br>
> +   INFO(VIEW_CLASS_BPTC_FLOAT, COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB),<br>
> +   INFO(VIEW_CLASS_BPTC_FLOAT, COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB),<br>
> +};<br>
> +#undef INFO<br>
> +<br>
> +/**<br>
> + * Lookup format view class based on internalformat<br>
> + * \return VIEW_CLASS if internalformat found in table, GL_FALSE otherwise.<br>
> + */<br>
> +static unsigned int<br>
> +lookup_view_class(GLenum internalformat)<br>
> +{<br>
> +   uint i;<br>
> +<br>
> +   for (i = 0; i < ARRAY_SIZE(_compatible_internal_formats); i++) {<br>
> +      if (_compatible_internal_formats[i].internal_format == internalformat)<br>
> +         return _compatible_internal_formats[i].view_class;<br>
> +   }<br>
> +   return false;<br>
> +}<br>
> +<br>
> +/**<br>
> + * Compute the size of the next mipmap level.<br>
> + */<br>
> +static void<br>
> +next_mipmap_level_size(GLenum target,<br>
> +                       GLint *width, GLint *height, GLint *depth)<br>
> +{<br>
> +   if (*width > 1) {<br>
> +      *width /= 2;<br>
> +   }<br>
> +<br>
> +   if ((*height > 1) && (target != GL_TEXTURE_1D_ARRAY)) {<br>
> +      *height /= 2;<br>
> +   }<br>
> +<br>
> +   if ((*depth > 1) && (target != GL_TEXTURE_2D_ARRAY)) {<br>
> +      *depth /= 2;<br>
> +   }<br>
> +}<br>
> +<br>
> +/** Helper to get a particular texture image in a texture object */<br>
> +static struct gl_texture_image *<br>
> +get_tex_image(struct gl_context *ctx,<br>
> +              struct gl_texture_object *texObj,<br>
> +              GLuint face, GLuint level)<br>
> +{<br>
> +   struct gl_texture_image *texImage;<br>
> +<br>
> +   if (!texObj)<br>
> +      return NULL;<br>
> +<br>
> +   texImage = texObj->Image[face][level];<br>
> +   if (!texImage) {<br>
> +      texImage = ctx->Driver.NewTextureImage(ctx);<br>
> +      if (!texImage) {<br>
> +         _mesa_error(ctx, GL_OUT_OF_MEMORY, "texture image allocation");<br>
> +         return NULL;<br>
> +      }<br>
> +<br>
> +      texObj->Image[face][level] = texImage;<br>
> +<br>
> +      /* Set the 'back' pointer */<br>
> +      texImage->TexObject = texObj;<br>
> +      texImage->Level = level;<br>
> +      texImage->Face = face;<br>
> +   }<br>
> +<br>
> +   return texImage;<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(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>
> +                 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(ctx, texImage,<br>
> +                                    levelWidth, levelHeight, levelDepth,<br>
> +                                    0, internalFormat, texFormat);<br>
> +      }<br>
> +<br>
> +      next_mipmap_level_size(target, &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 GL_TRUE;                          \<br>
> +} while (0)<br>
> +<br>
> +/**<br>
> + * Check for compatible target<br>
> + * If an error is found, record it with _mesa_error()<br>
> + * \return GL_FALSE if any error, GL_TRUE otherwise.<br>
> + */<br>
> +static GLboolean<br>
> +target_valid(struct gl_context *ctx, GLenum origTarget, GLenum newTarget)<br>
> +{<br>
> +   /*<br>
> +    * From ARB_texture_view spec:<br>
> +   ---------------------------------------------------------------------------------------------------------<br>
> +   | Original target              | Valid new targets |<br>
> +   ---------------------------------------------------------------------------------------------------------<br>
> +   | TEXTURE_1D                   | TEXTURE_1D, TEXTURE_1D_ARRAY |<br>
> +   | ------------------------------------------------------------------------------------------------------- |<br>
> +   | TEXTURE_2D                   | TEXTURE_2D, TEXTURE_2D_ARRAY |<br>
> +   | ------------------------------------------------------------------------------------------------------- |<br>
> +   | TEXTURE_3D                   | TEXTURE_3D |<br>
> +   | ------------------------------------------------------------------------------------------------------- |<br>
> +   | TEXTURE_CUBE_MAP             | TEXTURE_CUBE_MAP, TEXTURE_2D, TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP_ARRAY |<br>
> +   | ------------------------------------------------------------------------------------------------------- |<br>
> +   | TEXTURE_RECTANGLE            | TEXTURE_RECTANGLE |<br>
> +   | ------------------------------------------------------------------------------------------------------- |<br>
> +   | TEXTURE_BUFFER               | <none> |<br>
> +   | ------------------------------------------------------------------------------------------------------- |<br>
> +   | TEXTURE_1D_ARRAY             | TEXTURE_1D_ARRAY, TEXTURE_1D |<br>
> +   | ------------------------------------------------------------------------------------------------------- |<br>
> +   | TEXTURE_2D_ARRAY             | TEXTURE_2D_ARRAY, TEXTURE_2D, TEXTURE_CUBE_MAP, TEXTURE_CUBE_MAP_ARRAY |<br>
> +   | ------------------------------------------------------------------------------------------------------- |<br>
> +   | TEXTURE_CUBE_MAP_ARRAY       | TEXTURE_CUBE_MAP_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_2D, TEXTURE_CUBE_MAP |<br>
> +   | ------------------------------------------------------------------------------------------------------- |<br>
> +   | TEXTURE_2D_MULTISAMPLE       | TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY |<br>
> +   | ------------------------------------------------------------------------------------------------------- |<br>
> +   | TEXTURE_2D_MULTISAMPLE_ARRAY | TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY |<br>
> +   ---------------------------------------------------------------------------------------------------------<br>
> +    */<br>
> +<br>
> +   switch (origTarget) {<br>
> +   case GL_TEXTURE_1D:<br>
> +   case GL_TEXTURE_1D_ARRAY:<br>
> +      RETURN_IF_SUPPORTED(TEXTURE_1D);<br>
> +      RETURN_IF_SUPPORTED(TEXTURE_1D_ARRAY);<br>
> +      break;<br>
> +   case GL_TEXTURE_2D:<br>
> +      RETURN_IF_SUPPORTED(TEXTURE_2D);<br>
> +      RETURN_IF_SUPPORTED(TEXTURE_2D_ARRAY);<br>
> +      break;<br>
> +   case GL_TEXTURE_3D:<br>
> +      RETURN_IF_SUPPORTED(TEXTURE_3D);<br>
> +      break;<br>
> +   case GL_TEXTURE_RECTANGLE:<br>
> +      RETURN_IF_SUPPORTED(TEXTURE_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_2D);<br>
> +      RETURN_IF_SUPPORTED(TEXTURE_2D_ARRAY);<br>
> +      RETURN_IF_SUPPORTED(TEXTURE_CUBE_MAP);<br>
> +      RETURN_IF_SUPPORTED(TEXTURE_CUBE_MAP_ARRAY);<br>
> +      break;<br>
> +   case GL_TEXTURE_2D_MULTISAMPLE:<br>
> +   case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:<br>
> +      RETURN_IF_SUPPORTED(TEXTURE_2D_MULTISAMPLE);<br>
> +      RETURN_IF_SUPPORTED(TEXTURE_2D_MULTISAMPLE_ARRAY);<br>
> +      break;<br>
> +   }<br>
> +   _mesa_error(ctx, GL_INVALID_OPERATION,<br>
> +               "glTextureView(illegal target=%s)",<br>
> +               _mesa_lookup_enum_by_nr(newTarget));<br>
> +   return GL_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 GL_FALSE if any error, GL_TRUE otherwise.<br>
> + */<br>
> +static GLboolean<br>
> +compatible_format(struct gl_context *ctx, 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>
> +   /* 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 GL_TRUE;<br>
> +<br>
> +   origViewClass = lookup_view_class(origInternalFormat);<br>
> +   newViewClass = lookup_view_class(internalformat);<br>
> +   if ((origViewClass == newViewClass) && origViewClass != false)<br>
> +      return GL_TRUE;<br>
> +<br>
> +   _mesa_error(ctx, GL_INVALID_OPERATION,<br>
> +               "glTextureView(internalformat  %s not compatible with origtexture %s)",<br>
> +               _mesa_lookup_enum_by_nr(internalformat),<br>
> +               _mesa_lookup_enum_by_nr(origInternalFormat));<br>
> +   return GL_FALSE;<br>
> +}<br>
> +<br>
>  /**<br>
>   * glTextureView (ARB_texture_view)<br>
>   * If an error is found, record it with _mesa_error()<br>
> @@ -53,13 +391,235 @@ _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(target), origtexture,<br>
>                    _mesa_lookup_enum_by_nr(internalformat),<br>
>                    minlevel, numlevels, minlayer, numlayers);<br>
><br>
> +   if (origtexture == 0) {<br>
> +      _mesa_error(ctx, GL_INVALID_VALUE, "glTextureView(origtexture = 0x%x)", origtexture);<br>
> +      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 = 0x%x)", origtexture);<br>
> +      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 0x%x non-gen name)", texture);<br>
> +      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 0x%x already bound)", texture);<br>
> +      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>
> +   newViewMinLevel = origTexObj->MinLevel + minlevel;<br>
> +   newViewMinLayer = origTexObj->MinLayer + minlayer;<br>
> +   if (newViewMinLevel >= (origTexObj->MinLevel + origTexObj->NumLevels) ||<br>
> +       newViewMinLayer >= (origTexObj->MinLayer + origTexObj->NumLayers)) {<br>
> +      _mesa_error(ctx, GL_INVALID_VALUE, "glTextureView(origtexture = 0x%x)", origtexture);<br>
> +      return;<br>
> +   }<br>
> +<br>
> +   if (!compatible_format(ctx, origTexObj, internalformat)) {<br>
> +      return; // Error logged<br>
> +   }<br>
> +<br>
> +   texFormat = _mesa_choose_texture_format(ctx, texObj, target, 0,<br>
> +                                           internalformat, GL_NONE, GL_NONE);<br>
> +   assert(texFormat != MESA_FORMAT_NONE);<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_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_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(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, "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(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>
> 1.8.1.2<br>
><br>
</div></div><div class="HOEnZb"><div class="h5">> _______________________________________________<br>
> mesa-dev mailing list<br>
> <a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/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></div>