[PATCH 08/10] wined3d: Implement creating 2D array textures.

Józef Kucia jkucia at codeweavers.com
Mon Apr 18 17:01:32 CDT 2016


Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
---
 dlls/wined3d/surface.c | 56 ++++++++++++++++++++++++++++++++++++++------------
 dlls/wined3d/texture.c | 30 +++++++++++++++++++++------
 2 files changed, 67 insertions(+), 19 deletions(-)

diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 2fb1655..0e069d1 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -1303,14 +1303,24 @@ void wined3d_surface_upload_data(struct wined3d_surface *surface, const struct w
         else
             internal = format->glInternal;
 
-        TRACE("glCompressedTexSubImage2D, target %#x, level %d, x %d, y %d, w %d, h %d, "
-                "format %#x, image_size %#x, addr %p.\n", surface->texture_target, surface->texture_level,
+        TRACE("glCompressedTexSubImage target %#x, level %u, layer %u, x %d, y %d, w %u, h %u, "
+                "format %#x, image_size %#x, addr %p.\n",
+                surface->texture_target, surface->texture_level, surface->texture_layer,
                 dst_point->x, dst_point->y, update_w, update_h, internal, row_count * row_length, addr);
 
         if (row_length == src_pitch)
         {
-            GL_EXTCALL(glCompressedTexSubImage2D(surface->texture_target, surface->texture_level,
-                    dst_point->x, dst_point->y, update_w, update_h, internal, row_count * row_length, addr));
+            if (surface->texture_target == GL_TEXTURE_2D_ARRAY)
+            {
+                GL_EXTCALL(glCompressedTexSubImage3D(surface->texture_target, surface->texture_level,
+                            dst_point->x, dst_point->y, surface->texture_layer, update_w, update_h, 1,
+                            internal, row_count * row_length, addr));
+            }
+            else
+            {
+                GL_EXTCALL(glCompressedTexSubImage2D(surface->texture_target, surface->texture_level,
+                            dst_point->x, dst_point->y, update_w, update_h, internal, row_count * row_length, addr));
+            }
         }
         else
         {
@@ -1320,13 +1330,23 @@ void wined3d_surface_upload_data(struct wined3d_surface *surface, const struct w
              * can't use the unpack row length like for glTexSubImage2D. */
             for (row = 0, y = dst_point->y; row < row_count; ++row)
             {
-                GL_EXTCALL(glCompressedTexSubImage2D(surface->texture_target, surface->texture_level,
-                        dst_point->x, y, update_w, format->block_height, internal, row_length, addr));
+                if (surface->texture_target == GL_TEXTURE_2D_ARRAY)
+                {
+                    GL_EXTCALL(glCompressedTexSubImage3D(surface->texture_target, surface->texture_level,
+                            dst_point->x, y, surface->texture_layer, update_w, format->block_height, 1,
+                            internal, row_count * row_length, addr));
+                }
+                else
+                {
+                    GL_EXTCALL(glCompressedTexSubImage2D(surface->texture_target, surface->texture_level,
+                            dst_point->x, y, update_w, format->block_height, internal, row_length, addr));
+                }
+
                 y += format->block_height;
                 addr += src_pitch;
             }
         }
-        checkGLcall("glCompressedTexSubImage2D");
+        checkGLcall("glCompressedTexSubImage");
     }
     else
     {
@@ -1335,15 +1355,25 @@ void wined3d_surface_upload_data(struct wined3d_surface *surface, const struct w
         addr += src_rect->top * src_pitch;
         addr += src_rect->left * format->byte_count;
 
-        TRACE("glTexSubImage2D, target %#x, level %d, x %d, y %d, w %d, h %d, format %#x, type %#x, addr %p.\n",
-                surface->texture_target, surface->texture_level, dst_point->x, dst_point->y,
-                update_w, update_h, format->glFormat, format->glType, addr);
+        TRACE("glTexSubImage target %#x, level %u, layer %u, x %d, y %d, w %u, h %u, "
+                "format %#x, type %#x, addr %p.\n",
+                surface->texture_target, surface->texture_level, surface->texture_layer,
+                dst_point->x, dst_point->y, update_w, update_h, format->glFormat, format->glType, addr);
 
         gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_ROW_LENGTH, src_pitch / format->byte_count);
-        gl_info->gl_ops.gl.p_glTexSubImage2D(surface->texture_target, surface->texture_level,
-                dst_point->x, dst_point->y, update_w, update_h, format->glFormat, format->glType, addr);
+        if (surface->texture_target == GL_TEXTURE_2D_ARRAY)
+        {
+            GL_EXTCALL(glTexSubImage3D(surface->texture_target, surface->texture_level,
+                    dst_point->x, dst_point->y, surface->texture_layer, update_w, update_h, 1,
+                    format->glFormat, format->glType, addr));
+        }
+        else
+        {
+            gl_info->gl_ops.gl.p_glTexSubImage2D(surface->texture_target, surface->texture_level,
+                    dst_point->x, dst_point->y, update_w, update_h, format->glFormat, format->glType, addr);
+        }
         gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
-        checkGLcall("glTexSubImage2D");
+        checkGLcall("glTexSubImage");
     }
 
     if (data->buffer_object)
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c
index c46a357..725b431 100644
--- a/dlls/wined3d/texture.c
+++ b/dlls/wined3d/texture.c
@@ -1150,10 +1150,10 @@ static BOOL texture2d_prepare_location(struct wined3d_texture *texture, unsigned
 /* Context activation is done by the caller. */
 static void texture2d_prepare_texture(struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb)
 {
-    UINT sub_count = texture->level_count * texture->layer_count;
     const struct wined3d_format *format = texture->resource.format;
     const struct wined3d_gl_info *gl_info = context->gl_info;
     const struct wined3d_color_key_conversion *conversion;
+    unsigned int sub_count;
     GLenum internal;
     UINT i;
 
@@ -1185,6 +1185,9 @@ static void texture2d_prepare_texture(struct wined3d_texture *texture, struct wi
 
     TRACE("internal %#x, format %#x, type %#x.\n", internal, format->glFormat, format->glType);
 
+    sub_count = texture->level_count;
+    if (texture->target != GL_TEXTURE_2D_ARRAY)
+        sub_count *= texture->layer_count;
     for (i = 0; i < sub_count; ++i)
     {
         struct wined3d_surface *surface = texture->sub_resources[i].u.surface;
@@ -1200,9 +1203,18 @@ static void texture2d_prepare_texture(struct wined3d_texture *texture, struct wi
         TRACE("surface %p, target %#x, level %d, width %d, height %d.\n",
                 surface, surface->texture_target, surface->texture_level, width, height);
 
-        gl_info->gl_ops.gl.p_glTexImage2D(surface->texture_target, surface->texture_level,
-                internal, width, height, 0, format->glFormat, format->glType, NULL);
-        checkGLcall("glTexImage2D");
+        if (texture->target == GL_TEXTURE_2D_ARRAY)
+        {
+            GL_EXTCALL(glTexImage3D(surface->texture_target, surface->texture_level,
+                    internal, width, height, texture->layer_count, 0, format->glFormat, format->glType, NULL));
+            checkGLcall("glTexImage3D");
+        }
+        else
+        {
+            gl_info->gl_ops.gl.p_glTexImage2D(surface->texture_target, surface->texture_level,
+                    internal, width, height, 0, format->glFormat, format->glType, NULL);
+            checkGLcall("glTexImage2D");
+        }
     }
 }
 
@@ -1499,8 +1511,12 @@ static HRESULT texture_init(struct wined3d_texture *texture, const struct wined3
     unsigned int i, j;
     HRESULT hr;
 
-    if (!(desc->usage & WINED3DUSAGE_LEGACY_CUBEMAP) && layer_count != 1)
-        FIXME("Array textures not implemented.\n");
+    if (!(desc->usage & WINED3DUSAGE_LEGACY_CUBEMAP) && layer_count > 1
+            && !gl_info->supported[EXT_TEXTURE_ARRAY])
+    {
+        WARN("Array textures not supported.\n");
+        return WINED3DERR_INVALIDCALL;
+    }
 
     /* TODO: It should only be possible to create textures for formats
      * that are reported as supported. */
@@ -1630,6 +1646,8 @@ static HRESULT texture_init(struct wined3d_texture *texture, const struct wined3
         }
         if (desc->usage & WINED3DUSAGE_LEGACY_CUBEMAP)
             texture->target = GL_TEXTURE_CUBE_MAP_ARB;
+        else if (layer_count > 1)
+            texture->target = GL_TEXTURE_2D_ARRAY;
         else
             texture->target = GL_TEXTURE_2D;
     }
-- 
2.4.10




More information about the wine-patches mailing list