<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Nov 1, 2013 at 1:42 PM, Ian Romanick <span dir="ltr"><<a href="mailto:idr@freedesktop.org" target="_blank">idr@freedesktop.org</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div>On 11/01/2013 09:54 AM, Courtney Goeltzenleuchter wrote:<br>


> Add necessary driver interface and state to support glTextureView as<br>
> specified by ARB_texture_view.  Includes updates to configuration<br>
> files (i.e. Makefile.am, SConscript, etc.), xml definition for<br>
> glTextureView, header files and the new texture parameters.<br>
<br>
</div>This needs to be split into multiple patches.  Please look at Fredrik<br>
Hoglund's recent ARB_vertex_attrib_binding series for a good example.<br>
<br>
- Some early patch should just update src/mapi/glapi,<br>
src/mesa/main/tests/dispatch_sanity.cpp (missing from this patch), and<br>
stub versions of the new functions.<br>
<br>
- A patch after that should add tracking to src/mesa/main/extensions.c<br>
and the necessary updates to struct gl_extensions.  Sometimes this is<br>
squashed in with the glapi changes, sometimes not.<br>
<br>
- A patch after that should add new data types, tracking, etc. to mtypes.h.<br>
<br>
- Successive patches should implement the new functions added by the<br>
extension.  These patches will also generally update dd_function_table.<br>
<br>
- After the core implementation, patches should add back-end work for<br>
specific drivers (none in this case).<br>
<br>
One other general comment... for types that are not visible to the API<br>
layer, we generally prefer to *not* use GL types.  It looks like there<br>
are a few places that use GLboolean, for example, that should just use<br>
bool (from stdbool.h).<br>
<br>
I've made just a couple other comments below...<br>
<div><div><br>
> ---<br>
>  src/mapi/glapi/gen/ARB_texture_view.xml |  23 ++<br>
>  src/mapi/glapi/gen/Makefile.am          |   1 +<br>
>  src/mapi/glapi/gen/gl_API.xml           |   6 +-<br>
>  src/mapi/glapi/gen/gl_genexec.py        |   1 +<br>
>  src/mesa/Makefile.sources               |   1 +<br>
>  src/mesa/SConscript                     |   1 +<br>
>  src/mesa/drivers/common/driverfuncs.c   |   3 +<br>
>  src/mesa/main/dd.h                      |   5 +<br>
>  src/mesa/main/extensions.c              |   1 +<br>
>  src/mesa/main/mtypes.h                  |   6 +<br>
>  src/mesa/main/texparam.c                |  52 ++-<br>
>  src/mesa/main/texstorage.c              |  33 ++<br>
>  src/mesa/main/textureview.c             | 622 ++++++++++++++++++++++++++++++++<br>
>  src/mesa/main/textureview.h             |  39 ++<br>
>  14 files changed, 792 insertions(+), 2 deletions(-)<br>
>  create mode 100644 src/mapi/glapi/gen/ARB_texture_view.xml<br>
>  create mode 100644 src/mesa/main/textureview.c<br>
>  create mode 100644 src/mesa/main/textureview.h<br>
><br>
> diff --git a/src/mapi/glapi/gen/ARB_texture_view.xml b/src/mapi/glapi/gen/ARB_texture_view.xml<br>
> new file mode 100644<br>
> index 0000000..3e6b8c9<br>
> --- /dev/null<br>
> +++ b/src/mapi/glapi/gen/ARB_texture_view.xml<br>
> @@ -0,0 +1,23 @@<br>
> +<?xml version="1.0"?><br>
> +<!DOCTYPE OpenGLAPI SYSTEM "gl_API.dtd"><br>
> +<br>
> +<!-- Note: no GLX protocol info yet. --><br>
> +<br>
> +<OpenGLAPI><br>
> +<br>
> +<category name="GL_ARB_texture_view" number="124"><br>
> +<br>
> +   <function name="TextureView" offset="assign"><br>
> +      <param name="texture" type="GLuint"/><br>
> +      <param name="target" type="GLenum"/><br>
> +      <param name="origtexture" type="GLuint"/><br>
> +      <param name="internalformat" type="GLenum"/><br>
> +      <param name="minlevel" type="GLuint"/><br>
> +      <param name="numlevels" type="GLuint"/><br>
> +      <param name="minlayer" type="GLuint"/><br>
> +      <param name="numlayers" type="GLuint"/><br>
> +   </function><br>
> +<br>
> +</category><br>
> +<br>
> +</OpenGLAPI><br>
> diff --git a/src/mapi/glapi/gen/Makefile.am b/src/mapi/glapi/gen/Makefile.am<br>
> index 3902452..c35e3c1 100644<br>
> --- a/src/mapi/glapi/gen/Makefile.am<br>
> +++ b/src/mapi/glapi/gen/Makefile.am<br>
> @@ -123,6 +123,7 @@ API_XML = \<br>
>       ARB_texture_rg.xml \<br>
>       ARB_texture_storage_multisample.xml \<br>
>       ARB_texture_storage.xml \<br>
> +     ARB_texture_view.xml \<br>
>       ARB_vertex_array_object.xml \<br>
>       AMD_draw_buffers_blend.xml \<br>
>       AMD_performance_monitor.xml \<br>
> diff --git a/src/mapi/glapi/gen/gl_API.xml b/src/mapi/glapi/gen/gl_API.xml<br>
> index 45d69b4..0b0d3b5 100644<br>
> --- a/src/mapi/glapi/gen/gl_API.xml<br>
> +++ b/src/mapi/glapi/gen/gl_API.xml<br>
> @@ -8458,7 +8458,11 @@<br>
><br>
>  </category><br>
><br>
> -<!-- ARB extensions #120...#126 --><br>
> +<!-- ARB extensions #120...#123 --><br>
> +<br>
> +<xi:include href="ARB_texture_view.xml" xmlns:xi="<a href="http://www.w3.org/2001/XInclude" target="_blank">http://www.w3.org/2001/XInclude</a>"/><br>
> +<br>
> +<!-- ARB extensions #125...#126 --><br>
><br>
>  <xi:include href="ARB_ES3_compatibility.xml" xmlns:xi="<a href="http://www.w3.org/2001/XInclude" target="_blank">http://www.w3.org/2001/XInclude</a>"/><br>
><br>
> diff --git a/src/mapi/glapi/gen/gl_genexec.py b/src/mapi/glapi/gen/gl_genexec.py<br>
> index 3ce190f..b557b3b 100644<br>
> --- a/src/mapi/glapi/gen/gl_genexec.py<br>
> +++ b/src/mapi/glapi/gen/gl_genexec.py<br>
> @@ -102,6 +102,7 @@ header = """/**<br>
>  #include "main/texstate.h"<br>
>  #include "main/texstorage.h"<br>
>  #include "main/texturebarrier.h"<br>
> +#include "main/textureview.h"<br>
>  #include "main/transformfeedback.h"<br>
>  #include "main/mtypes.h"<br>
>  #include "main/varray.h"<br>
> diff --git a/src/mesa/Makefile.sources b/src/mesa/Makefile.sources<br>
> index a84f8a7..39525bc 100644<br>
> --- a/src/mesa/Makefile.sources<br>
> +++ b/src/mesa/Makefile.sources<br>
> @@ -103,6 +103,7 @@ MAIN_FILES = \<br>
>       $(SRCDIR)main/texstate.c \<br>
>       $(SRCDIR)main/texstorage.c \<br>
>       $(SRCDIR)main/texstore.c \<br>
> +        $(SRCDIR)main/textureview.c \<br>
>       $(SRCDIR)main/texturebarrier.c \<br>
>       $(SRCDIR)main/transformfeedback.c \<br>
>       $(SRCDIR)main/uniforms.c \<br>
> diff --git a/src/mesa/SConscript b/src/mesa/SConscript<br>
> index 4213498..581bd69 100644<br>
> --- a/src/mesa/SConscript<br>
> +++ b/src/mesa/SConscript<br>
> @@ -136,6 +136,7 @@ main_sources = [<br>
>      'main/texstorage.c',<br>
>      'main/texstore.c',<br>
>      'main/texturebarrier.c',<br>
> +    'main/textureview.c',<br>
>      'main/transformfeedback.c',<br>
>      'main/uniform_query.cpp',<br>
>      'main/uniforms.c',<br>
> diff --git a/src/mesa/drivers/common/driverfuncs.c b/src/mesa/drivers/common/driverfuncs.c<br>
> index 5faa98a..f185688 100644<br>
> --- a/src/mesa/drivers/common/driverfuncs.c<br>
> +++ b/src/mesa/drivers/common/driverfuncs.c<br>
> @@ -211,6 +211,9 @@ _mesa_init_driver_functions(struct dd_function_table *driver)<br>
>     /* GL_ARB_texture_storage */<br>
>     driver->AllocTextureStorage = _mesa_alloc_texture_storage;<br>
><br>
> +   /* GL_ARB_texture_view */<br>
> +   driver->TextureView = NULL;<br>
> +<br>
>     /* GL_ARB_texture_multisample */<br>
>     driver->GetSamplePosition = NULL;<br>
>  }<br>
> diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h<br>
> index d7c4327..6690e5a 100644<br>
> --- a/src/mesa/main/dd.h<br>
> +++ b/src/mesa/main/dd.h<br>
> @@ -375,6 +375,11 @@ struct dd_function_table {<br>
>                                      GLsizei levels, GLsizei width,<br>
>                                      GLsizei height, GLsizei depth);<br>
><br>
> +   /** Called as part of glTextureView to add views to origTexObj */<br>
> +   GLboolean (*TextureView)(struct gl_context *ctx,<br>
> +                            struct gl_texture_object *texObj,<br>
> +                            struct gl_texture_object *origTexObj);<br>
> +<br>
>     /**<br>
>      * Map a renderbuffer into user space.<br>
>      * \param mode  bitmask of GL_MAP_READ_BIT, GL_MAP_WRITE_BIT and<br>
> diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c<br>
> index 285ec37..1a532b5 100644<br>
> --- a/src/mesa/main/extensions.c<br>
> +++ b/src/mesa/main/extensions.c<br>
> @@ -155,6 +155,7 @@ static const struct extension extension_table[] = {<br>
>     { "GL_ARB_texture_rg",                          o(ARB_texture_rg),                          GL,             2008 },<br>
>     { "GL_ARB_texture_storage",                     o(dummy_true),                              GL,             2011 },<br>
>     { "GL_ARB_texture_storage_multisample",         o(ARB_texture_multisample),                 GL,             2012 },<br>
> +   { "GL_ARB_texture_view",                        o(ARB_texture_view),                        GL,             2012 },<br>
>     { "GL_ARB_texture_swizzle",                     o(EXT_texture_swizzle),                     GL,             2008 },<br>
>     { "GL_ARB_timer_query",                         o(ARB_timer_query),                         GL,             2010 },<br>
>     { "GL_ARB_transform_feedback2",                 o(ARB_transform_feedback2),                 GL,             2010 },<br>
> diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h<br>
> index 087bc37..74c5d30 100644<br>
> --- a/src/mesa/main/mtypes.h<br>
> +++ b/src/mesa/main/mtypes.h<br>
> @@ -1184,6 +1184,11 @@ struct gl_texture_object<br>
>                                      pressure? */<br>
>     GLboolean Immutable;        /**< GL_ARB_texture_storage */<br>
><br>
> +   GLuint MinLevel;            /**< GL_ARB_texture_view */<br>
> +   GLuint MinLayer;            /**< GL_ARB_texture_view */<br>
> +   GLuint NumLevels;           /**< GL_ARB_texture_view */<br>
> +   GLuint NumLayers;           /**< GL_ARB_texture_view */<br>
> +<br>
>     /** Actual texture images, indexed by [cube face] and [mipmap level] */<br>
>     struct gl_texture_image *Image[MAX_FACES][MAX_TEXTURE_LEVELS];<br>
><br>
> @@ -3273,6 +3278,7 @@ struct gl_extensions<br>
>     GLboolean ARB_texture_query_lod;<br>
>     GLboolean ARB_texture_rg;<br>
>     GLboolean ARB_texture_rgb10_a2ui;<br>
> +   GLboolean ARB_texture_view;<br>
>     GLboolean ARB_timer_query;<br>
>     GLboolean ARB_transform_feedback2;<br>
>     GLboolean ARB_transform_feedback3;<br>
> diff --git a/src/mesa/main/texparam.c b/src/mesa/main/texparam.c<br>
> index d56b7d9..9a5bb61 100644<br>
> --- a/src/mesa/main/texparam.c<br>
> +++ b/src/mesa/main/texparam.c<br>
> @@ -1570,6 +1570,30 @@ _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )<br>
>           *params = (GLfloat) obj->ImmutableLevels;<br>
>           break;<br>
><br>
> +      case GL_TEXTURE_VIEW_MIN_LEVEL:<br>
> +         if (!ctx->Extensions.ARB_texture_view)<br>
> +            goto invalid_pname;<br>
> +         *params = (GLfloat) obj->MinLevel;<br>
> +         break;<br>
> +<br>
> +      case GL_TEXTURE_VIEW_NUM_LEVELS:<br>
> +         if (!ctx->Extensions.ARB_texture_view)<br>
> +            goto invalid_pname;<br>
> +         *params = (GLfloat) obj->NumLevels;<br>
> +         break;<br>
> +<br>
> +      case GL_TEXTURE_VIEW_MIN_LAYER:<br>
> +         if (!ctx->Extensions.ARB_texture_view)<br>
> +            goto invalid_pname;<br>
> +         *params = (GLfloat) obj->MinLayer;<br>
> +         break;<br>
> +<br>
> +      case GL_TEXTURE_VIEW_NUM_LAYERS:<br>
> +         if (!ctx->Extensions.ARB_texture_view)<br>
> +            goto invalid_pname;<br>
> +         *params = (GLfloat) obj->NumLayers;<br>
> +         break;<br>
> +<br>
>        case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:<br>
>           if (!_mesa_is_gles(ctx) || !ctx->Extensions.OES_EGL_image_external)<br>
>              goto invalid_pname;<br>
> @@ -1746,11 +1770,37 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )<br>
>           break;<br>
><br>
>        case GL_TEXTURE_IMMUTABLE_LEVELS:<br>
> -         if (!_mesa_is_gles3(ctx))<br>
> +         if (!_mesa_is_gles3(ctx)<br>
> +             && !_mesa_is_desktop_gl(ctx)<br>
> +             && !ctx->Extensions.ARB_texture_view)<br>
<br>
</div></div>This if-statement will never evaluate to true because at least one of<br>
_mesa_is_gles3 or _mesa_is_desktop_gl will be false.<br></blockquote><div><br></div><div>The intent - as I understand it - is to only return GL_TEXTURE_IMMUTABLE_LEVELS if we are being called using a context that can support it. How about:</div>

<div>if (_mesa_is_gles3(ctx) || ctx->Extensions.ARB_texture_view)</div><div>   *params = obj->ImmutableLevels;</div><div>else</div><div>   goto invalid_pname;</div><div><br></div><div>Does that protect GL_TEXTURE_IMMUTABLE_LEVELS properly?</div>

</div><div class="gmail_quote"><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div><div><br>
>              goto invalid_pname;<br>
>           *params = obj->ImmutableLevels;<br>
>           break;<br>
><br>
> +      case GL_TEXTURE_VIEW_MIN_LEVEL:<br>
> +         if (!ctx->Extensions.ARB_texture_view)<br>
> +            goto invalid_pname;<br>
> +         *params = (GLint) obj->MinLevel;<br>
> +         break;<br>
> +<br>
> +      case GL_TEXTURE_VIEW_NUM_LEVELS:<br>
> +         if (!ctx->Extensions.ARB_texture_view)<br>
> +            goto invalid_pname;<br>
> +         *params = (GLint) obj->NumLevels;<br>
> +         break;<br>
> +<br>
> +      case GL_TEXTURE_VIEW_MIN_LAYER:<br>
> +         if (!ctx->Extensions.ARB_texture_view)<br>
> +            goto invalid_pname;<br>
> +         *params = (GLint) obj->MinLayer;<br>
> +         break;<br>
> +<br>
> +      case GL_TEXTURE_VIEW_NUM_LAYERS:<br>
> +         if (!ctx->Extensions.ARB_texture_view)<br>
> +            goto invalid_pname;<br>
> +         *params = (GLint) obj->NumLayers;<br>
> +         break;<br>
> +<br>
>        case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:<br>
>           if (!_mesa_is_gles(ctx) || !ctx->Extensions.OES_EGL_image_external)<br>
>              goto invalid_pname;<br>
> diff --git a/src/mesa/main/texstorage.c b/src/mesa/main/texstorage.c<br>
> index 7bd8652..e8db4af 100644<br>
> --- a/src/mesa/main/texstorage.c<br>
> +++ b/src/mesa/main/texstorage.c<br>
> @@ -429,8 +429,41 @@ texstorage(GLuint dims, GLenum target, GLsizei levels, GLenum internalformat,<br>
>           return;<br>
>        }<br>
><br>
> +      /* If the command is successful,<br>
> +       * TEXTURE_IMMUTABLE_FORMAT becomes TRUE.<br>
> +       * TEXTURE_IMMUTABLE_LEVELS and TEXTURE_VIEW_NUM_LEVELS become levels.<br>
> +       * If the texture target is TEXTURE_1D_ARRAY then<br>
> +       * TEXTURE_VIEW_NUM_LAYERS becomes height.<br>
> +       * If the texture target is TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP_ARRAY,<br>
> +       * or TEXTURE_2D_MULTISAMPLE_ARRAY then TEXTURE_VIEW_NUM_LAYERS becomes depth.<br>
> +       * If the texture target is TEXTURE_CUBE_MAP, then<br>
> +       * TEXTURE_VIEW_NUM_LAYERS becomes 6.<br>
> +       * For any other texture target, TEXTURE_VIEW_NUM_LAYERS becomes 1.<br>
> +       */<br>
> +<br>
>        texObj->Immutable = GL_TRUE;<br>
>        texObj->ImmutableLevels = levels;<br>
> +      texObj->MinLevel = 0;<br>
> +      texObj->NumLevels = levels;<br>
> +      texObj->MinLayer = 0;<br>
> +      texObj->NumLayers = 1;<br>
> +      switch (target)<br>
> +      {<br>
<br>
</div></div>{ on the same line as the switch.<br></blockquote><div>got it. </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


<div><div><br>
> +      case GL_TEXTURE_1D_ARRAY:<br>
> +         texObj->NumLayers = height;<br>
> +         break;<br>
> +<br>
> +      case GL_TEXTURE_2D_ARRAY:<br>
> +      case GL_TEXTURE_CUBE_MAP_ARRAY:<br>
> +      case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:<br>
> +         texObj->NumLayers = depth;<br>
> +         break;<br>
> +<br>
> +      case GL_TEXTURE_CUBE_MAP:<br>
> +         texObj->NumLayers = 6;<br>
> +         break;<br>
> +      }<br>
> +<br>
>     }<br>
>  }<br>
><br>
> diff --git a/src/mesa/main/textureview.c b/src/mesa/main/textureview.c<br>
> new file mode 100644<br>
> index 0000000..62b295b<br>
> --- /dev/null<br>
> +++ b/src/mesa/main/textureview.c<br>
> @@ -0,0 +1,622 @@<br>
> +/*<br>
> + * Mesa 3-D graphics library<br>
> + *<br>
> + * Copyright (C) 2013 LunarG, Inc.<br>
> + *<br>
> + * Permission is hereby granted, free of charge, to any person obtaining a<br>
> + * copy of this software and associated documentation files (the "Software"),<br>
> + * to deal in the Software without restriction, including without limitation<br>
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
> + * and/or sell copies of the Software, and to permit persons to whom the<br>
> + * Software is furnished to do so, subject to the following conditions:<br>
> + *<br>
> + * The above copyright notice and this permission notice shall be included<br>
> + * in all copies or substantial portions of the Software.<br>
> + *<br>
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL<br>
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br>
> + * DEALINGS IN THE SOFTWARE.<br>
> + *<br>
> + * Authors:<br>
> + *    Courtney Goeltzenleuchter <<a href="mailto:courtney@lunarg.com" target="_blank">courtney@lunarg.com</a>><br>
> + */<br>
> +<br>
> +<br>
> +/**<br>
> + * \file textureview.c<br>
> + * GL_ARB_texture_view functions<br>
> + */<br>
> +<br>
> +#include "glheader.h"<br>
> +#include "context.h"<br>
> +#include "enums.h"<br>
> +#include "imports.h"<br>
> +#include "macros.h"<br>
> +#include "teximage.h"<br>
> +#include "texobj.h"<br>
> +#include "texstorage.h"<br>
> +#include "textureview.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>
> +   INFO(FALSE, FALSE)<br>
<br>
</div></div>I don't think the sentinel is necessary.<br>
<div><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 GLenum<br>
> +lookup_view_class(GLenum internalformat)<br>
> +{<br>
> +   GLuint i;<br>
> +<br>
> +   for (i = 0; _compatible_internal_formats[i].view_class != GL_FALSE; i++) {<br>
<br>
</div>With the sentinel removed, use<br>
<br>
   for (i = 0; i < ARRAY_SIZE(_compatible_internal_formats); i++) {<br></blockquote><div>okay </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


<div><div><br>
> +      if (_compatible_internal_formats[i].internal_format == internalformat)<br>
> +         return _compatible_internal_formats[i].view_class;<br>
> +   }<br>
> +   return GL_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>
> +   GLenum origInternalFormat = texImage->InternalFormat;<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>
> +   if (lookup_view_class(origInternalFormat) ==<br>
> +       lookup_view_class(internalformat))<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>
> + * \return none.<br>
> + */<br>
> +void GLAPIENTRY<br>
> +_mesa_TextureView(GLuint texture, GLenum target, GLuint origtexture,<br>
> +                  GLenum internalformat,<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 %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) newViewNumLevels;<br>
> +      break;<br>
> +<br>
> +   case GL_TEXTURE_2D:<br>
> +   case GL_TEXTURE_2D_MULTISAMPLE:<br>
> +   case GL_TEXTURE_RECTANGLE:<br>
> +      depth = 1;<br>
> +      break;<br>
> +<br>
> +   case GL_TEXTURE_CUBE_MAP:<br>
> +   case GL_TEXTURE_2D_ARRAY:<br>
> +   case GL_TEXTURE_CUBE_MAP_ARRAY:<br>
> +   case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:<br>
> +      depth = newViewNumLevels;<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>
> diff --git a/src/mesa/main/textureview.h b/src/mesa/main/textureview.h<br>
> new file mode 100644<br>
> index 0000000..c2f0f32<br>
> --- /dev/null<br>
> +++ b/src/mesa/main/textureview.h<br>
> @@ -0,0 +1,39 @@<br>
> +/*<br>
> + * Mesa 3-D graphics library<br>
> + *<br>
> + * Copyright (C) 2012-2013 LunarG, Inc.<br>
> + *<br>
> + * Permission is hereby granted, free of charge, to any person obtaining a<br>
> + * copy of this software and associated documentation files (the "Software"),<br>
> + * to deal in the Software without restriction, including without limitation<br>
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
> + * and/or sell copies of the Software, and to permit persons to whom the<br>
> + * Software is furnished to do so, subject to the following conditions:<br>
> + *<br>
> + * The above copyright notice and this permission notice shall be included<br>
> + * in all copies or substantial portions of the Software.<br>
> + *<br>
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL<br>
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br>
> + * DEALINGS IN THE SOFTWARE.<br>
> + *<br>
> + * Authors:<br>
> + *    Courtney Goeltzenleuchter <<a href="mailto:courtney@lunarg.com" target="_blank">courtney@lunarg.com</a>><br>
> + */<br>
> +<br>
> +<br>
> +#ifndef TEXTUREVIEW_H<br>
> +#define TEXTUREVIEW_H<br>
> +<br>
> +<br>
> +extern void GLAPIENTRY<br>
> +_mesa_TextureView(GLuint texture, GLenum target, GLuint origtexture,<br>
> +                  GLenum internalformat,<br>
> +                  GLuint minlevel, GLuint numlevels,<br>
> +                  GLuint minlayer, GLuint numlayers);<br>
> +<br>
> +#endif /* TEXTUREVIEW_H */<br>
><br>
<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>