mesa/st: enable carry/borrow lowering pass
[mesa.git] / src / mesa / main / textureview.c
index 1094993a17a503158484dac7e10e47aaf9630d80..77a3b782b5af036a6220e351437747311a388cd7 100644 (file)
@@ -169,7 +169,7 @@ static const struct internal_format_class_info s3tc_compatible_internal_formats[
 static GLenum
 lookup_view_class(struct gl_context *ctx, GLenum internalformat)
 {
-   uint i;
+   GLuint i;
 
    for (i = 0; i < ARRAY_SIZE(compatible_internal_formats); i++) {
       if (compatible_internal_formats[i].internal_format == internalformat)
@@ -196,7 +196,7 @@ initialize_texture_fields(struct gl_context *ctx,
                           struct gl_texture_object *texObj,
                           GLint levels,
                           GLsizei width, GLsizei height, GLsizei depth,
-                          GLenum internalFormat, gl_format texFormat)
+                          GLenum internalFormat, mesa_format texFormat)
 {
    const GLuint numFaces = _mesa_num_tex_faces(target);
    GLint level, levelWidth = width, levelHeight = height, levelDepth = depth;
@@ -208,8 +208,13 @@ initialize_texture_fields(struct gl_context *ctx,
    /* Set up all the texture object's gl_texture_images */
    for (level = 0; level < levels; level++) {
       for (face = 0; face < numFaces; face++) {
-         struct gl_texture_image *texImage =
-                 _mesa_get_tex_image(ctx, texObj, face, level);
+         struct gl_texture_image *texImage;
+         GLenum faceTarget = target;
+
+         if (target == GL_TEXTURE_CUBE_MAP)
+            faceTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + face;
+
+         texImage = _mesa_get_tex_image(ctx, texObj, faceTarget, level);
 
          if (!texImage) {
             _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexStorage");
@@ -346,6 +351,67 @@ compatible_format(struct gl_context *ctx, const struct gl_texture_object *origTe
                _mesa_lookup_enum_by_nr(origInternalFormat));
    return false;
 }
+/**
+ * Helper function for TexStorage and teximagemultisample to set immutable
+ * texture state needed by ARB_texture_view.
+ */
+void
+_mesa_set_texture_view_state(struct gl_context *ctx,
+                             struct gl_texture_object *texObj,
+                             GLenum target, GLuint levels)
+{
+   struct gl_texture_image *texImage;
+
+   /* Get a reference to what will become this View's base level */
+   texImage = _mesa_select_tex_image(ctx, texObj, target, 0);
+
+   /* When an immutable texture is created via glTexStorage or glTexImageMultisample,
+    * TEXTURE_IMMUTABLE_FORMAT becomes TRUE.
+    * TEXTURE_IMMUTABLE_LEVELS and TEXTURE_VIEW_NUM_LEVELS become levels.
+    * If the texture target is TEXTURE_1D_ARRAY then
+    * TEXTURE_VIEW_NUM_LAYERS becomes height.
+    * If the texture target is TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP_ARRAY,
+    * or TEXTURE_2D_MULTISAMPLE_ARRAY then TEXTURE_VIEW_NUM_LAYERS becomes depth.
+    * If the texture target is TEXTURE_CUBE_MAP, then
+    * TEXTURE_VIEW_NUM_LAYERS becomes 6.
+    * For any other texture target, TEXTURE_VIEW_NUM_LAYERS becomes 1.
+    * 
+    * ARB_texture_multisample: Multisample textures do
+    * not have multiple image levels.
+    */
+
+   texObj->Immutable = GL_TRUE;
+   texObj->ImmutableLevels = levels;
+   texObj->MinLevel = 0;
+   texObj->NumLevels = levels;
+   texObj->MinLayer = 0;
+   texObj->NumLayers = 1;
+   switch (target) {
+   case GL_TEXTURE_1D_ARRAY:
+      texObj->NumLayers = texImage->Height;
+      break;
+
+   case GL_TEXTURE_2D_MULTISAMPLE:
+      texObj->NumLevels = 1;
+      texObj->ImmutableLevels = 1;
+      break;
+
+   case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
+      texObj->NumLevels = 1;
+      texObj->ImmutableLevels = 1;
+      /* fall through to set NumLayers */
+
+   case GL_TEXTURE_2D_ARRAY:
+   case GL_TEXTURE_CUBE_MAP_ARRAY:
+      texObj->NumLayers = texImage->Depth;
+      break;
+
+   case GL_TEXTURE_CUBE_MAP:
+      texObj->NumLayers = 6;
+      break;
+
+   }
+}
 
 /**
  * glTextureView (ARB_texture_view)
@@ -364,7 +430,7 @@ _mesa_TextureView(GLuint texture, GLenum target, GLuint origtexture,
    GLuint newViewMinLevel, newViewMinLayer;
    GLuint newViewNumLevels, newViewNumLayers;
    GLsizei width, height, depth;
-   gl_format texFormat;
+   mesa_format texFormat;
    GLboolean sizeOK, dimensionsOK;
    GLenum faceTarget;