wine-staging/patches/wined3d-1DTextures/0004-wined3d-Create-dummy-1d-textures-and-surfaces.patch

225 lines
8.8 KiB
Diff
Raw Normal View History

From 80118da171e87348ce58c22599202053fe95d3b6 Mon Sep 17 00:00:00 2001
2016-08-31 08:42:50 -07:00
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
Date: Thu, 25 Aug 2016 19:24:47 +0200
Subject: wined3d: Create dummy 1d textures and surfaces.
---
dlls/wined3d/resource.c | 1 +
dlls/wined3d/texture.c | 174 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 175 insertions(+)
diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c
index 611c61f..64dce8f 100644
2016-08-31 08:42:50 -07:00
--- a/dlls/wined3d/resource.c
+++ b/dlls/wined3d/resource.c
@@ -94,6 +94,7 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *
resource_types[] =
{
{WINED3D_RTYPE_BUFFER, 0, WINED3D_GL_RES_TYPE_BUFFER},
+ {WINED3D_RTYPE_TEXTURE_1D, 0, WINED3D_GL_RES_TYPE_TEX_1D},
{WINED3D_RTYPE_TEXTURE_2D, 0, WINED3D_GL_RES_TYPE_TEX_2D},
{WINED3D_RTYPE_TEXTURE_2D, 0, WINED3D_GL_RES_TYPE_TEX_RECT},
{WINED3D_RTYPE_TEXTURE_2D, 0, WINED3D_GL_RES_TYPE_RB},
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c
index 90bd4a0..4ecd4ce 100644
2016-08-31 08:42:50 -07:00
--- a/dlls/wined3d/texture.c
+++ b/dlls/wined3d/texture.c
@@ -1448,6 +1448,45 @@ void wined3d_texture_upload_data(struct wined3d_texture *texture, unsigned int s
context, box, data, row_pitch, slice_pitch);
2016-08-31 08:42:50 -07:00
}
+
+/* This call just uploads data, the caller is responsible for binding the
+ * correct texture. */
+/* Context activation is done by the caller. */
+static void texture1d_upload_data(struct wined3d_texture *texture, unsigned int sub_resource_idx,
+ const struct wined3d_context *context, const struct wined3d_box *box, const struct wined3d_const_bo_address *data,
2016-08-31 08:42:50 -07:00
+ unsigned int row_pitch, unsigned int slice_pitch)
+{
+ FIXME("texture %p, sub_resource_idx %u, context %p, box %p, data {%#x:%p}, row_pitch %#x, slice_pitch %#x: stub.\n",
+ texture, sub_resource_idx, context, box, data->buffer_object, data->addr, row_pitch, slice_pitch);
2016-08-31 08:42:50 -07:00
+}
+
+/* Context activation is done by the caller. */
+static BOOL texture1d_load_location(struct wined3d_texture *texture, unsigned int sub_resource_idx,
+ struct wined3d_context *context, DWORD location)
+{
+ FIXME("texture %p, sub_resource_idx %u, context %p, location %s: stub.\n",
+ texture, sub_resource_idx, context, wined3d_debug_location(location));
+
+ return FALSE;
+}
+
+static void texture1d_prepare_texture(struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb)
+{
+ FIXME("stub.\n");
+}
+
+static void texture1d_cleanup_sub_resources(struct wined3d_texture *texture)
+{
+}
+
+static const struct wined3d_texture_ops texture1d_ops =
+{
+ texture1d_upload_data,
+ texture1d_load_location,
+ texture1d_prepare_texture,
+ texture1d_cleanup_sub_resources,
+};
+
static void texture2d_upload_data(struct wined3d_texture *texture, unsigned int sub_resource_idx,
const struct wined3d_context *context, const struct wined3d_box *box,
const struct wined3d_const_bo_address *data, unsigned int row_pitch, unsigned int slice_pitch)
@@ -1882,6 +1921,137 @@ static const struct wined3d_resource_ops texture_resource_ops =
2016-08-31 08:42:50 -07:00
texture_resource_sub_resource_unmap,
};
+static HRESULT texture1d_init(struct wined3d_texture *texture, const struct wined3d_resource_desc *desc,
+ UINT layer_count, UINT level_count, struct wined3d_device *device, void *parent,
+ const struct wined3d_parent_ops *parent_ops)
+{
+ struct wined3d_device_parent *device_parent = device->device_parent;
+ const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
+ struct wined3d_surface *surfaces;
+ unsigned int i, j;
+ HRESULT hr;
+
+ if (layer_count > 1 && !gl_info->supported[EXT_TEXTURE_ARRAY])
+ {
+ WARN("OpenGL implementation does not support array textures.\n");
+ return WINED3DERR_INVALIDCALL;
+ }
+
+ /* TODO: It should only be possible to create textures for formats
+ * that are reported as supported. */
+ if (WINED3DFMT_UNKNOWN >= desc->format)
+ {
+ WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
+ return WINED3DERR_INVALIDCALL;
+ }
+
+ if (desc->usage & WINED3DUSAGE_LEGACY_CUBEMAP)
+ {
+ WARN("1d textures can not be used for cube mapping, returning D3DERR_INVALIDCALL.\n");
+ return WINED3DERR_INVALIDCALL;
+ }
+
+ if (desc->usage & WINED3DUSAGE_DYNAMIC && (desc->pool == WINED3D_POOL_MANAGED
+ || desc->pool == WINED3D_POOL_SCRATCH))
+ {
+ WARN("Attempted to create a DYNAMIC texture in pool %s.\n", debug_d3dpool(desc->pool));
+ return WINED3DERR_INVALIDCALL;
+ }
+
+ if (!gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] && !is_power_of_two(desc->width))
+ {
+ if (desc->pool == WINED3D_POOL_SCRATCH)
+ {
+ WARN("Creating a scratch NPOT 1d texture despite lack of HW support.\n");
+ }
+ else
+ {
+ WARN("Attempted to create a NPOT 1d texture (%u, %u, %u) without GL support.\n",
+ desc->width, desc->height, desc->depth);
+ return WINED3DERR_INVALIDCALL;
+ }
+ }
+
+ if (desc->usage & WINED3DUSAGE_AUTOGENMIPMAP)
+ {
+ if (!gl_info->supported[SGIS_GENERATE_MIPMAP])
+ {
+ WARN("No mipmap generation support, returning WINED3DERR_INVALIDCALL.\n");
+ return WINED3DERR_INVALIDCALL;
+ }
+
+ if (level_count != 1)
+ {
+ WARN("WINED3DUSAGE_AUTOGENMIPMAP is set, and level count != 1, returning WINED3DERR_INVALIDCALL.\n");
+ return WINED3DERR_INVALIDCALL;
+ }
+ }
+
+ if (FAILED(hr = wined3d_texture_init(texture, &texture1d_ops, layer_count, level_count, desc,
+ 0, device, parent, parent_ops, &texture_resource_ops)))
+ {
+ WARN("Failed to initialize texture, returning %#x.\n", hr);
+ return hr;
+ }
+
+ texture->pow2_matrix[0] = 1.0f;
+ texture->pow2_matrix[5] = 1.0f;
+ texture->pow2_matrix[10] = 1.0f;
+ texture->pow2_matrix[15] = 1.0f;
+ texture->target = (layer_count > 1) ? GL_TEXTURE_1D_ARRAY : GL_TEXTURE_1D;
+
+ if (wined3d_texture_use_pbo(texture, gl_info))
+ {
+ wined3d_resource_free_sysmem(&texture->resource);
+ texture->resource.map_binding = WINED3D_LOCATION_BUFFER;
+ }
+
+ if (level_count > ~(SIZE_T)0 / layer_count
+ || !(surfaces = wined3d_calloc(level_count * layer_count, sizeof(*surfaces))))
+ {
+ wined3d_texture_cleanup_sync(texture);
+ return E_OUTOFMEMORY;
+ }
+
+ /* Generate all the surfaces. */
+ for (i = 0; i < texture->level_count; ++i)
+ {
+ for (j = 0; j < texture->layer_count; ++j)
+ {
+ struct wined3d_texture_sub_resource *sub_resource;
+ unsigned int idx = j * texture->level_count + i;
+ struct wined3d_surface *surface;
+
+ surface = &surfaces[idx];
+ surface->container = texture;
+ surface->texture_target = texture->target;
+ surface->texture_level = i;
+ surface->texture_layer = j;
+ list_init(&surface->renderbuffers);
+ list_init(&surface->overlays);
+
+ sub_resource = &texture->sub_resources[idx];
+ sub_resource->locations = WINED3D_LOCATION_DISCARDED;
+ sub_resource->u.surface = surface;
+
+ if (FAILED(hr = device_parent->ops->surface_created(device_parent,
+ texture, idx, &sub_resource->parent, &sub_resource->parent_ops)))
+ {
+ WARN("Failed to create texture1d parent, hr %#x.\n", hr);
+ sub_resource->parent = NULL;
+ wined3d_texture_cleanup_sync(texture);
+ return hr;
+ }
+
+ TRACE("parent %p, parent_ops %p.\n", parent, parent_ops);
+
+ TRACE("Created 1d texture surface level %u, layer %u @ %p.\n", i, j, surface);
+ }
+ }
+
+ return WINED3D_OK;
+}
+
static HRESULT texture_init(struct wined3d_texture *texture, const struct wined3d_resource_desc *desc,
unsigned int layer_count, unsigned int level_count, DWORD flags, struct wined3d_device *device,
void *parent, const struct wined3d_parent_ops *parent_ops)
@@ -2828,6 +2998,10 @@ HRESULT CDECL wined3d_texture_create(struct wined3d_device *device, const struct
2016-08-31 08:42:50 -07:00
switch (desc->resource_type)
{
+ case WINED3D_RTYPE_TEXTURE_1D:
+ hr = texture1d_init(object, desc, layer_count, level_count, device, parent, parent_ops);
+ break;
+
case WINED3D_RTYPE_TEXTURE_2D:
hr = texture_init(object, desc, layer_count, level_count, flags, device, parent, parent_ops);
break;
--
2.9.0
2016-08-31 08:42:50 -07:00