ReactOS 0.4.16-dev-319-g6cf4263
texture.c File Reference
#include "config.h"
#include "wine/port.h"
#include "wined3d_private.h"
Include dependency graph for texture.c:

Go to the source code of this file.

Macros

#define WINED3D_TEXTURE_DYNAMIC_MAP_THRESHOLD   50
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (d3d)
 
 WINE_DECLARE_DEBUG_CHANNEL (d3d_perf)
 
 WINE_DECLARE_DEBUG_CHANNEL (winediag)
 
static BOOL wined3d_texture_use_pbo (const struct wined3d_texture *texture, const struct wined3d_gl_info *gl_info)
 
static BOOL wined3d_texture_use_immutable_storage (const struct wined3d_texture *texture, const struct wined3d_gl_info *gl_info)
 
GLenum wined3d_texture_get_gl_buffer (const struct wined3d_texture *texture)
 
static DWORD wined3d_resource_access_from_location (DWORD location)
 
static BOOL is_power_of_two (UINT x)
 
static void wined3d_texture_evict_sysmem (struct wined3d_texture *texture)
 
void wined3d_texture_validate_location (struct wined3d_texture *texture, unsigned int sub_resource_idx, DWORD location)
 
static void wined3d_texture_set_dirty (struct wined3d_texture *texture)
 
void wined3d_texture_invalidate_location (struct wined3d_texture *texture, unsigned int sub_resource_idx, DWORD location)
 
static BOOL wined3d_texture_copy_sysmem_location (struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, DWORD location)
 
BOOL wined3d_texture_load_location (struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, DWORD location)
 
void wined3d_texture_get_memory (struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_bo_address *data, DWORD locations)
 
static HRESULT wined3d_texture_init (struct wined3d_texture *texture, const struct wined3d_texture_ops *texture_ops, UINT layer_count, UINT level_count, const struct wined3d_resource_desc *desc, DWORD flags, struct wined3d_device *device, void *parent, const struct wined3d_parent_ops *parent_ops, const struct wined3d_resource_ops *resource_ops)
 
static void wined3d_texture_remove_buffer_object (struct wined3d_texture *texture, unsigned int sub_resource_idx, const struct wined3d_gl_info *gl_info)
 
static void wined3d_texture_update_map_binding (struct wined3d_texture *texture)
 
void wined3d_texture_set_map_binding (struct wined3d_texture *texture, DWORD map_binding)
 
static void gltexture_delete (struct wined3d_device *device, const struct wined3d_gl_info *gl_info, struct gl_texture *tex)
 
static unsigned int wined3d_texture_get_gl_sample_count (const struct wined3d_texture *texture)
 
static void wined3d_texture_allocate_gl_mutable_storage (struct wined3d_texture *texture, GLenum gl_internal_format, const struct wined3d_format *format, const struct wined3d_gl_info *gl_info)
 
static void wined3d_texture_allocate_gl_immutable_storage (struct wined3d_texture *texture, GLenum gl_internal_format, const struct wined3d_gl_info *gl_info)
 
static void wined3d_texture_unload_gl_texture (struct wined3d_texture *texture)
 
static void wined3d_texture_sub_resources_destroyed (struct wined3d_texture *texture)
 
static void wined3d_texture_cleanup (struct wined3d_texture *texture)
 
void wined3d_texture_set_swapchain (struct wined3d_texture *texture, struct wined3d_swapchain *swapchain)
 
void wined3d_texture_bind (struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb)
 
void wined3d_texture_bind_and_dirtify (struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb)
 
void wined3d_texture_apply_sampler_desc (struct wined3d_texture *texture, const struct wined3d_sampler_desc *sampler_desc, const struct wined3d_context *context)
 
ULONG CDECL wined3d_texture_incref (struct wined3d_texture *texture)
 
static void wined3d_texture_cleanup_sync (struct wined3d_texture *texture)
 
static void wined3d_texture_destroy_object (void *object)
 
ULONG CDECL wined3d_texture_decref (struct wined3d_texture *texture)
 
struct wined3d_resource *CDECL wined3d_texture_get_resource (struct wined3d_texture *texture)
 
static BOOL color_key_equal (const struct wined3d_color_key *c1, struct wined3d_color_key *c2)
 
void wined3d_texture_load (struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb)
 
void *CDECL wined3d_texture_get_parent (const struct wined3d_texture *texture)
 
HRESULT wined3d_texture_check_box_dimensions (const struct wined3d_texture *texture, unsigned int level, const struct wined3d_box *box)
 
void CDECL wined3d_texture_get_pitch (const struct wined3d_texture *texture, unsigned int level, unsigned int *row_pitch, unsigned int *slice_pitch)
 
DWORD CDECL wined3d_texture_set_lod (struct wined3d_texture *texture, DWORD lod)
 
DWORD CDECL wined3d_texture_get_lod (const struct wined3d_texture *texture)
 
DWORD CDECL wined3d_texture_get_level_count (const struct wined3d_texture *texture)
 
HRESULT CDECL wined3d_texture_set_color_key (struct wined3d_texture *texture, DWORD flags, const struct wined3d_color_key *color_key)
 
static void texture2d_create_dc (void *object)
 
static void texture2d_destroy_dc (void *object)
 
HRESULT CDECL wined3d_texture_update_desc (struct wined3d_texture *texture, UINT width, UINT height, enum wined3d_format_id format_id, enum wined3d_multisample_type multisample_type, UINT multisample_quality, void *mem, UINT pitch)
 
static void wined3d_texture_prepare_buffer_object (struct wined3d_texture *texture, unsigned int sub_resource_idx, const struct wined3d_gl_info *gl_info)
 
static void wined3d_texture_force_reload (struct wined3d_texture *texture)
 
void wined3d_texture_prepare_texture (struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb)
 
static void wined3d_texture_prepare_rb (struct wined3d_texture *texture, const struct wined3d_gl_info *gl_info, BOOL multisample)
 
BOOL wined3d_texture_prepare_location (struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, DWORD location)
 
static struct wined3d_texture_sub_resource * wined3d_texture_get_sub_resource (struct wined3d_texture *texture, unsigned int sub_resource_idx)
 
HRESULT CDECL wined3d_texture_add_dirty_region (struct wined3d_texture *texture, UINT layer, const struct wined3d_box *dirty_region)
 
void wined3d_texture_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)
 
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, unsigned int row_pitch, unsigned int slice_pitch)
 
static void texture1d_download_data (struct wined3d_texture *texture, unsigned int sub_resource_idx, const struct wined3d_context *context, const struct wined3d_bo_address *data)
 
static void texture1d_srgb_transfer (struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, BOOL dest_is_srgb)
 
static BOOL texture1d_load_location (struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, DWORD location)
 
static void texture1d_prepare_texture (struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb)
 
static void texture1d_cleanup_sub_resources (struct wined3d_texture *texture)
 
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)
 
static BOOL texture2d_load_location (struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, DWORD location)
 
static void texture2d_prepare_texture (struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb)
 
static void texture2d_cleanup_sub_resources (struct wined3d_texture *texture)
 
struct wined3d_texture *__cdecl wined3d_texture_from_resource (struct wined3d_resource *resource)
 
static ULONG texture_resource_incref (struct wined3d_resource *resource)
 
static ULONG texture_resource_decref (struct wined3d_resource *resource)
 
static void texture_resource_preload (struct wined3d_resource *resource)
 
static void wined3d_texture_unload (struct wined3d_resource *resource)
 
static HRESULT texture_resource_sub_resource_map (struct wined3d_resource *resource, unsigned int sub_resource_idx, struct wined3d_map_desc *map_desc, const struct wined3d_box *box, DWORD flags)
 
static HRESULT texture_resource_sub_resource_map_info (struct wined3d_resource *resource, unsigned int sub_resource_idx, struct wined3d_map_info *info, DWORD flags)
 
static HRESULT texture_resource_sub_resource_unmap (struct wined3d_resource *resource, unsigned int sub_resource_idx)
 
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)
 
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)
 
static void texture3d_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)
 
static void texture3d_download_data (struct wined3d_texture *texture, unsigned int sub_resource_idx, const struct wined3d_context *context, const struct wined3d_bo_address *data)
 
static void texture3d_srgb_transfer (struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, BOOL dest_is_srgb)
 
static BOOL texture3d_load_location (struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, DWORD location)
 
static void texture3d_prepare_texture (struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb)
 
static void texture3d_cleanup_sub_resources (struct wined3d_texture *texture)
 
static HRESULT volumetexture_init (struct wined3d_texture *texture, const struct wined3d_resource_desc *desc, UINT layer_count, UINT level_count, DWORD flags, struct wined3d_device *device, void *parent, const struct wined3d_parent_ops *parent_ops)
 
HRESULT CDECL wined3d_texture_blt (struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, const RECT *dst_rect, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx, const RECT *src_rect, DWORD flags, const struct wined3d_blt_fx *fx, enum wined3d_texture_filter_type filter)
 
HRESULT CDECL wined3d_texture_get_overlay_position (const struct wined3d_texture *texture, unsigned int sub_resource_idx, LONG *x, LONG *y)
 
HRESULT CDECL wined3d_texture_set_overlay_position (struct wined3d_texture *texture, unsigned int sub_resource_idx, LONG x, LONG y)
 
HRESULT CDECL wined3d_texture_update_overlay (struct wined3d_texture *texture, unsigned int sub_resource_idx, const RECT *src_rect, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, const RECT *dst_rect, DWORD flags)
 
void *CDECL wined3d_texture_get_sub_resource_parent (struct wined3d_texture *texture, unsigned int sub_resource_idx)
 
void CDECL wined3d_texture_set_sub_resource_parent (struct wined3d_texture *texture, unsigned int sub_resource_idx, void *parent)
 
HRESULT CDECL wined3d_texture_get_sub_resource_desc (const struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_sub_resource_desc *desc)
 
HRESULT CDECL wined3d_texture_create (struct wined3d_device *device, const struct wined3d_resource_desc *desc, UINT layer_count, UINT level_count, DWORD flags, const struct wined3d_sub_resource_data *data, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_texture **texture)
 
HRESULT CDECL wined3d_texture_get_dc (struct wined3d_texture *texture, unsigned int sub_resource_idx, HDC *dc)
 
HRESULT CDECL wined3d_texture_release_dc (struct wined3d_texture *texture, unsigned int sub_resource_idx, HDC dc)
 

Variables

static const struct wined3d_texture_ops texture1d_ops
 
static const struct wined3d_texture_ops texture2d_ops
 
static const struct wined3d_resource_ops texture_resource_ops
 
static const struct wined3d_texture_ops texture3d_ops
 

Macro Definition Documentation

◆ WINED3D_TEXTURE_DYNAMIC_MAP_THRESHOLD

#define WINED3D_TEXTURE_DYNAMIC_MAP_THRESHOLD   50

Definition at line 31 of file texture.c.

Function Documentation

◆ color_key_equal()

static BOOL color_key_equal ( const struct wined3d_color_key c1,
struct wined3d_color_key c2 
)
static

Definition at line 1059 of file texture.c.

1060{
1063}
DWORD color_space_high_value
Definition: wined3d.h:1982
DWORD color_space_low_value
Definition: wined3d.h:1980

Referenced by wined3d_texture_load().

◆ gltexture_delete()

static void gltexture_delete ( struct wined3d_device device,
const struct wined3d_gl_info gl_info,
struct gl_texture tex 
)
static

Definition at line 476 of file texture.c.

478{
480 gl_info->gl_ops.gl.p_glDeleteTextures(1, &tex->name);
481 tex->name = 0;
482}
#define FALSE
Definition: types.h:117
void context_gl_resource_released(struct wined3d_device *device, GLuint name, BOOL rb_namespace)
Definition: context.c:1104
Definition: devices.h:37
struct opengl_funcs gl_ops

Referenced by wined3d_texture_unload_gl_texture().

◆ is_power_of_two()

static BOOL is_power_of_two ( UINT  x)
static

Definition at line 104 of file texture.c.

105{
106 return (x != 0) && !(x & (x - 1));
107}
GLint GLint GLint GLint GLint x
Definition: gl.h:1548

Referenced by texture1d_init(), volumetexture_init(), and wined3d_texture_update_desc().

◆ texture1d_cleanup_sub_resources()

static void texture1d_cleanup_sub_resources ( struct wined3d_texture texture)
static

Definition at line 2072 of file texture.c.

2073{
2074}

◆ texture1d_download_data()

static void texture1d_download_data ( struct wined3d_texture texture,
unsigned int  sub_resource_idx,
const struct wined3d_context context,
const struct wined3d_bo_address data 
)
static

Definition at line 1785 of file texture.c.

1787{
1788 struct wined3d_surface *surface = texture->sub_resources[sub_resource_idx].u.surface;
1789 const struct wined3d_format *format = texture->resource.format;
1790 const struct wined3d_gl_info *gl_info = context->gl_info;
1791 struct wined3d_texture_sub_resource *sub_resource;
1792 BYTE *temporary_mem = NULL;
1793 void *mem;
1794 GLenum target;
1795
1796 sub_resource = &texture->sub_resources[sub_resource_idx];
1797
1798 if (format->conv_byte_count)
1799 {
1800 FIXME("Attempting to download a converted 1d texture, format %s.\n",
1801 debug_d3dformat(format->id));
1802 return;
1803 }
1804
1807 {
1808 WARN_(d3d_perf)("Downloading all miplevel layers to get the surface data for a single sub-resource.\n");
1809
1810 if (!(temporary_mem = heap_calloc(texture->layer_count, sub_resource->size)))
1811 {
1812 ERR("Out of memory.\n");
1813 return;
1814 }
1815
1816 mem = temporary_mem;
1817 }
1818 else if (data->buffer_object)
1819 {
1820 GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, data->buffer_object));
1821 checkGLcall("glBindBuffer");
1822 mem = data->addr;
1823 }
1824 else
1825 mem = data->addr;
1826
1827 gl_info->gl_ops.gl.p_glGetTexImage(target, sub_resource_idx,
1828 format->glFormat, format->glType, mem);
1829 checkGLcall("glGetTexImage");
1830
1831 if (temporary_mem)
1832 {
1833 void *src_data = temporary_mem + surface->texture_layer * sub_resource->size;
1834 if (data->buffer_object)
1835 {
1836 GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, data->buffer_object));
1837 checkGLcall("glBindBuffer");
1838 GL_EXTCALL(glBufferSubData(GL_PIXEL_PACK_BUFFER, 0, sub_resource->size, src_data));
1839 checkGLcall("glBufferSubData");
1840 }
1841 else
1842 {
1843 memcpy(data->addr, src_data, sub_resource->size);
1844 }
1845 }
1846
1847 if (data->buffer_object)
1848 {
1849 GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, 0));
1850 checkGLcall("glBindBuffer");
1851 }
1852
1853 HeapFree(GetProcessHeap(), 0, temporary_mem);
1854}
#define FIXME(fmt,...)
Definition: precomp.h:53
#define ERR(fmt,...)
Definition: precomp.h:57
#define NULL
Definition: types.h:112
const char * debug_d3dformat(enum wined3d_format_id format_id)
Definition: utils.c:3980
#define GetProcessHeap()
Definition: compat.h:736
#define HeapFree(x, y, z)
Definition: compat.h:735
unsigned int GLenum
Definition: gl.h:150
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLenum GLuint texture
Definition: glext.h:6295
#define GL_PIXEL_PACK_BUFFER
Definition: glext.h:476
#define GL_TEXTURE_1D_ARRAY
Definition: glext.h:533
GLenum target
Definition: glext.h:7315
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define WARN_(ch,...)
Definition: debug.h:157
static void * heap_calloc(SIZE_T count, SIZE_T size)
Definition: heap.h:49
Definition: http.c:7252
Definition: format.c:58
Definition: mem.c:349
unsigned int texture_layer
#define GL_EXTCALL(f)
static GLenum wined3d_texture_get_sub_resource_target(const struct wined3d_texture *texture, unsigned int sub_resource_idx)
#define checkGLcall(A)
unsigned char BYTE
Definition: xxhash.c:193

Referenced by texture1d_load_location(), and texture1d_srgb_transfer().

◆ texture1d_init()

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 
)
static

Definition at line 2518 of file texture.c.

2521{
2522 struct wined3d_device_parent *device_parent = device->device_parent;
2523 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
2524 struct wined3d_surface *surfaces;
2525 unsigned int i, j;
2526 HRESULT hr;
2527
2528 if (layer_count > 1 && !gl_info->supported[EXT_TEXTURE_ARRAY])
2529 {
2530 WARN("OpenGL implementation does not support array textures.\n");
2532 }
2533
2534 /* TODO: It should only be possible to create textures for formats
2535 * that are reported as supported. */
2536 if (WINED3DFMT_UNKNOWN >= desc->format)
2537 {
2538 WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
2540 }
2541
2542 if (desc->usage & WINED3DUSAGE_LEGACY_CUBEMAP)
2543 {
2544 WARN("1d textures can not be used for cube mapping, returning D3DERR_INVALIDCALL.\n");
2546 }
2547
2549 || (desc->usage & WINED3DUSAGE_SCRATCH))
2550 {
2551 WARN("Attempted to create a DYNAMIC texture in pool %s.\n", wined3d_debug_resource_access(desc->access));
2553 }
2554
2556 {
2557 if (desc->usage & WINED3DUSAGE_SCRATCH)
2558 {
2559 WARN("Creating a scratch NPOT 1d texture despite lack of HW support.\n");
2560 }
2561 else
2562 {
2563 WARN("Attempted to create a NPOT 1d texture (%u, %u, %u) without GL support.\n",
2564 desc->width, desc->height, desc->depth);
2566 }
2567 }
2568
2570 {
2571 if (level_count != 1)
2572 {
2573 WARN("WINED3DUSAGE_QUERY_GENMIPMAP is set, and level count != 1, returning WINED3DERR_INVALIDCALL.\n");
2575 }
2576 }
2577
2578 if (FAILED(hr = wined3d_texture_init(texture, &texture1d_ops, layer_count, level_count, desc,
2579 0, device, parent, parent_ops, &texture_resource_ops)))
2580 {
2581 WARN("Failed to initialize texture, returning %#x.\n", hr);
2582 return hr;
2583 }
2584
2585 texture->pow2_matrix[0] = 1.0f;
2586 texture->pow2_matrix[5] = 1.0f;
2587 texture->pow2_matrix[10] = 1.0f;
2588 texture->pow2_matrix[15] = 1.0f;
2589 texture->target = (layer_count > 1) ? GL_TEXTURE_1D_ARRAY : GL_TEXTURE_1D;
2590
2591 if (wined3d_texture_use_pbo(texture, gl_info))
2592 {
2594 texture->resource.map_binding = WINED3D_LOCATION_BUFFER;
2595 }
2596
2597 if (level_count > ~(SIZE_T)0 / layer_count
2598 || !(surfaces = heap_calloc(level_count * layer_count, sizeof(*surfaces))))
2599 {
2601 return E_OUTOFMEMORY;
2602 }
2603
2604 /* Generate all the surfaces. */
2605 for (i = 0; i < texture->level_count; ++i)
2606 {
2607 for (j = 0; j < texture->layer_count; ++j)
2608 {
2609 struct wined3d_texture_sub_resource *sub_resource;
2610 unsigned int idx = j * texture->level_count + i;
2611 struct wined3d_surface *surface;
2612
2613 surface = &surfaces[idx];
2614 surface->container = texture;
2615 surface->texture_level = i;
2616 surface->texture_layer = j;
2617 list_init(&surface->renderbuffers);
2618
2619 sub_resource = &texture->sub_resources[idx];
2620 sub_resource->locations = WINED3D_LOCATION_DISCARDED;
2621 sub_resource->u.surface = surface;
2622
2623 if (FAILED(hr = device_parent->ops->surface_created(device_parent,
2624 texture, idx, &sub_resource->parent, &sub_resource->parent_ops)))
2625 {
2626 WARN("Failed to create texture1d parent, hr %#x.\n", hr);
2627 sub_resource->parent = NULL;
2629 return hr;
2630 }
2631
2632 TRACE("parent %p, parent_ops %p.\n", parent, parent_ops);
2633
2634 TRACE("Created 1d texture surface level %u, layer %u @ %p.\n", i, j, surface);
2635 }
2636 }
2637
2638 return WINED3D_OK;
2639}
static void list_init(struct list_entry *head)
Definition: list.h:51
#define WARN(fmt,...)
Definition: precomp.h:61
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
void wined3d_resource_free_sysmem(struct wined3d_resource *resource)
Definition: resource.c:504
static const struct wined3d_resource_ops texture_resource_ops
Definition: texture.c:2507
static BOOL is_power_of_two(UINT x)
Definition: texture.c:104
static HRESULT wined3d_texture_init(struct wined3d_texture *texture, const struct wined3d_texture_ops *texture_ops, UINT layer_count, UINT level_count, const struct wined3d_resource_desc *desc, DWORD flags, struct wined3d_device *device, void *parent, const struct wined3d_parent_ops *parent_ops, const struct wined3d_resource_ops *resource_ops)
Definition: texture.c:323
static BOOL wined3d_texture_use_pbo(const struct wined3d_texture *texture, const struct wined3d_gl_info *gl_info)
Definition: texture.c:33
static const struct wined3d_texture_ops texture1d_ops
Definition: texture.c:2076
static void wined3d_texture_cleanup_sync(struct wined3d_texture *texture)
Definition: texture.c:1009
unsigned int idx
Definition: utils.c:41
const char * wined3d_debug_resource_access(DWORD access)
Definition: utils.c:4200
r parent
Definition: btrfs.c:3010
#define GL_TEXTURE_1D
Definition: gl.h:644
const GLvdpauSurfaceNV * surfaces
Definition: glext.h:11586
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define FAILED(hr)
Definition: intsafe.h:51
static const WCHAR desc[]
Definition: protectdata.c:36
HRESULT hr
Definition: shlfolder.c:183
#define TRACE(s)
Definition: solgame.cpp:4
const struct wined3d_device_parent_ops * ops
Definition: wined3d.h:2133
BOOL supported[WINED3D_GL_EXT_COUNT]
struct list renderbuffers
struct wined3d_texture * container
unsigned int texture_level
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define WINED3D_OK
Definition: wined3d.h:37
#define WINED3DUSAGE_LEGACY_CUBEMAP
Definition: wined3d.h:917
@ WINED3DFMT_UNKNOWN
Definition: wined3d.h:107
#define WINED3DUSAGE_SCRATCH
Definition: wined3d.h:915
#define WINED3DUSAGE_QUERY_GENMIPMAP
Definition: wined3d.h:923
#define WINED3DUSAGE_DYNAMIC
Definition: wined3d.h:907
#define WINED3DERR_INVALIDCALL
Definition: wined3d.h:48
@ ARB_TEXTURE_NON_POWER_OF_TWO
Definition: wined3d_gl.h:123
@ EXT_TEXTURE_ARRAY
Definition: wined3d_gl.h:172
#define WINED3D_LOCATION_BUFFER
static BOOL wined3d_resource_access_is_managed(unsigned int access)
#define WINED3D_LOCATION_DISCARDED

Referenced by wined3d_texture_create().

◆ texture1d_load_location()

static BOOL texture1d_load_location ( struct wined3d_texture texture,
unsigned int  sub_resource_idx,
struct wined3d_context context,
DWORD  location 
)
static

Definition at line 1880 of file texture.c.

1882{
1883 struct wined3d_texture_sub_resource *sub_resource = &texture->sub_resources[sub_resource_idx];
1885 unsigned int row_pitch, slice_pitch;
1886
1887 TRACE("texture %p, sub_resource_idx %u, context %p, location %s.\n",
1888 texture, sub_resource_idx, context, wined3d_debug_location(location));
1889
1890 TRACE("Current resource location %s.\n", wined3d_debug_location(sub_resource->locations));
1891
1892 if ((sub_resource->locations & location) == location)
1893 {
1894 TRACE("Location(s) already up to date.\n");
1895 return TRUE;
1896 }
1897
1898 if ((texture->resource.access & required_access) != required_access)
1899 {
1900 ERR("Operation requires %#x access, but 1d texture only has %#x.\n",
1901 required_access, texture->resource.access);
1902 return FALSE;
1903 }
1904
1905 if (!wined3d_texture_prepare_location(texture, sub_resource_idx, context, location))
1906 return FALSE;
1907
1908 if (sub_resource->locations & WINED3D_LOCATION_DISCARDED)
1909 {
1910 TRACE("1d texture previously discarded, nothing to do.\n");
1913 goto done;
1914 }
1915
1916 switch (location)
1917 {
1920 if (sub_resource->locations & WINED3D_LOCATION_SYSMEM)
1921 {
1922 struct wined3d_const_bo_address data = {0, texture->resource.heap_memory};
1923 data.addr += sub_resource->offset;
1925 wined3d_texture_get_pitch(texture, sub_resource_idx, &row_pitch, &slice_pitch);
1926 texture1d_upload_data(texture, sub_resource_idx, context, NULL, &data, row_pitch, slice_pitch);
1927 }
1928 else if (sub_resource->locations & WINED3D_LOCATION_BUFFER)
1929 {
1930#if !defined(STAGING_CSMT)
1931 struct wined3d_const_bo_address data = {sub_resource->buffer_object, NULL};
1932#else /* STAGING_CSMT */
1933 struct wined3d_const_bo_address data = {sub_resource->buffer->name, NULL};
1934#endif /* STAGING_CSMT */
1936 wined3d_texture_get_pitch(texture, sub_resource_idx, &row_pitch, &slice_pitch);
1937 texture1d_upload_data(texture, sub_resource_idx, context, NULL, &data, row_pitch, slice_pitch);
1938 }
1939 else if (sub_resource->locations & WINED3D_LOCATION_TEXTURE_RGB)
1940 {
1941 texture1d_srgb_transfer(texture, sub_resource_idx, context, TRUE);
1942 }
1943 else if (sub_resource->locations & WINED3D_LOCATION_TEXTURE_SRGB)
1944 {
1945 texture1d_srgb_transfer(texture, sub_resource_idx, context, FALSE);
1946 }
1947 else
1948 {
1949 FIXME("Implement 1d texture loading from %s.\n", wined3d_debug_location(sub_resource->locations));
1950 return FALSE;
1951 }
1952 break;
1953
1955 if (sub_resource->locations & (WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_TEXTURE_SRGB))
1956 {
1957 struct wined3d_bo_address data = {0, texture->resource.heap_memory};
1958
1959 data.addr += sub_resource->offset;
1960 if (sub_resource->locations & WINED3D_LOCATION_TEXTURE_RGB)
1962 else
1964
1965 texture1d_download_data(texture, sub_resource_idx, context, &data);
1966 ++texture->download_count;
1967 }
1968 else
1969 {
1970 FIXME("Implement WINED3D_LOCATION_SYSMEM loading from %s.\n",
1971 wined3d_debug_location(sub_resource->locations));
1972 return FALSE;
1973 }
1974 break;
1975
1977 if (sub_resource->locations & (WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_TEXTURE_SRGB))
1978 {
1979#if !defined(STAGING_CSMT)
1980 struct wined3d_bo_address data = {sub_resource->buffer_object, NULL};
1981#else /* STAGING_CSMT */
1982 struct wined3d_bo_address data = {sub_resource->buffer->name, NULL};
1983#endif /* STAGING_CSMT */
1984
1985 if (sub_resource->locations & WINED3D_LOCATION_TEXTURE_RGB)
1987 else
1989
1990 texture1d_download_data(texture, sub_resource_idx, context, &data);
1991 }
1992 else
1993 {
1994 FIXME("Implement WINED3D_LOCATION_BUFFER loading from %s.\n",
1995 wined3d_debug_location(sub_resource->locations));
1996 return FALSE;
1997 }
1998 break;
1999
2000 default:
2001 FIXME("Implement %s loading from %s.\n", wined3d_debug_location(location),
2002 wined3d_debug_location(sub_resource->locations));
2003 return FALSE;
2004 }
2005
2006done:
2008
2009 return TRUE;
2010}
#define TRUE
Definition: types.h:120
void wined3d_texture_invalidate_location(struct wined3d_texture *texture, unsigned int sub_resource_idx, DWORD location)
Definition: texture.c:159
BOOL wined3d_texture_prepare_location(struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, DWORD location)
Definition: texture.c:1605
void wined3d_texture_bind_and_dirtify(struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb)
Definition: texture.c:868
static DWORD wined3d_resource_access_from_location(DWORD location)
Definition: texture.c:79
static void texture1d_download_data(struct wined3d_texture *texture, unsigned int sub_resource_idx, const struct wined3d_context *context, const struct wined3d_bo_address *data)
Definition: texture.c:1785
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, unsigned int row_pitch, unsigned int slice_pitch)
Definition: texture.c:1708
void wined3d_texture_validate_location(struct wined3d_texture *texture, unsigned int sub_resource_idx, DWORD location)
Definition: texture.c:135
static void texture1d_srgb_transfer(struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, BOOL dest_is_srgb)
Definition: texture.c:1857
void CDECL wined3d_texture_get_pitch(const struct wined3d_texture *texture, unsigned int level, unsigned int *row_pitch, unsigned int *slice_pitch)
Definition: texture.c:1168
const char * wined3d_debug_location(DWORD location)
Definition: utils.c:6396
unsigned long DWORD
Definition: ntddk_ex.h:95
#define WINED3D_LOCATION_TEXTURE_SRGB
#define WINED3D_LOCATION_SYSMEM
#define WINED3D_LOCATION_TEXTURE_RGB

◆ texture1d_prepare_texture()

static void texture1d_prepare_texture ( struct wined3d_texture texture,
struct wined3d_context context,
BOOL  srgb 
)
static

Definition at line 2012 of file texture.c.

2013{
2014 const struct wined3d_format *format = texture->resource.format;
2015 unsigned int sub_count = texture->level_count * texture->layer_count;
2016 const struct wined3d_gl_info *gl_info = context->gl_info;
2017 unsigned int width;
2019
2021
2022 if (srgb)
2023 internal = format->glGammaInternal;
2024 else if (texture->resource.usage & WINED3DUSAGE_RENDERTARGET
2026 internal = format->rtInternal;
2027 else
2028 internal = format->glInternal;
2029
2031 {
2033
2034 if (texture->target == GL_TEXTURE_1D_ARRAY)
2035 {
2036 GL_EXTCALL(glTexStorage2D(texture->target, texture->level_count, internal, width, texture->layer_count));
2037 checkGLcall("glTexStorage2D");
2038 }
2039 else
2040 {
2041 GL_EXTCALL(glTexStorage1D(texture->target, texture->level_count, internal, width));
2042 checkGLcall("glTexStorage1D");
2043 }
2044 }
2045 else
2046 {
2047 unsigned int i;
2048
2049 for (i = 0; i < sub_count; ++i)
2050 {
2051 GLenum target;
2052 struct wined3d_surface *surface = texture->sub_resources[i].u.surface;
2055
2056 if (texture->target == GL_TEXTURE_1D_ARRAY)
2057 {
2058 gl_info->gl_ops.gl.p_glTexImage2D(target, surface->texture_level,
2059 internal, width, texture->layer_count, 0, format->glFormat, format->glType, NULL);
2060 checkGLcall("glTexImage2D");
2061 }
2062 else
2063 {
2064 gl_info->gl_ops.gl.p_glTexImage1D(target, surface->texture_level,
2065 internal, width, 0, format->glFormat, format->glType, NULL);
2066 checkGLcall("glTexImage1D");
2067 }
2068 }
2069 }
2070}
ios_base &_STLP_CALL internal(ios_base &__s)
Definition: _ios_base.h:311
BOOL wined3d_resource_is_offscreen(struct wined3d_resource *resource)
Definition: resource.c:547
static BOOL wined3d_texture_use_immutable_storage(const struct wined3d_texture *texture, const struct wined3d_gl_info *gl_info)
Definition: texture.c:42
GLint GLint GLsizei width
Definition: gl.h:1546
#define WINED3DUSAGE_RENDERTARGET
Definition: wined3d.h:899
static unsigned int wined3d_texture_get_level_width(const struct wined3d_texture *texture, unsigned int level)

◆ texture1d_srgb_transfer()

static void texture1d_srgb_transfer ( struct wined3d_texture texture,
unsigned int  sub_resource_idx,
struct wined3d_context context,
BOOL  dest_is_srgb 
)
static

Definition at line 1857 of file texture.c.

1859{
1860 struct wined3d_texture_sub_resource *sub_resource = &texture->sub_resources[sub_resource_idx];
1861 unsigned int row_pitch, slice_pitch;
1862 struct wined3d_bo_address data;
1863
1864 WARN_(d3d_perf)("Performing slow rgb/srgb 1d texture transfer.\n");
1865 data.buffer_object = 0;
1866 if (!(data.addr = HeapAlloc(GetProcessHeap(), 0, sub_resource->size)))
1867 return;
1868
1869 wined3d_texture_get_pitch(texture, sub_resource_idx, &row_pitch, &slice_pitch);
1871 texture1d_download_data(texture, sub_resource_idx, context, &data);
1873 texture1d_upload_data(texture, sub_resource_idx, context, NULL,
1874 wined3d_const_bo_address(&data), row_pitch, slice_pitch);
1875
1876 HeapFree(GetProcessHeap(), 0, data.addr);
1877}
#define HeapAlloc
Definition: compat.h:733

Referenced by texture1d_load_location().

◆ texture1d_upload_data()

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,
unsigned int  row_pitch,
unsigned int  slice_pitch 
)
static

Definition at line 1708 of file texture.c.

1711{
1712 struct wined3d_surface *surface = texture->sub_resources[sub_resource_idx].u.surface;
1713 const struct wined3d_format *format = texture->resource.format;
1714 unsigned int level = sub_resource_idx % texture->level_count;
1715 const struct wined3d_gl_info *gl_info = context->gl_info;
1716 const void *mem = data->addr;
1717 void *converted_mem = NULL;
1718 unsigned int width, x, update_w;
1719 GLenum target;
1720
1721 TRACE("texture %p, sub_resource_idx %u, context %p, box %p, data {%#x:%p}, row_pitch %#x, slice_pitch %#x.\n",
1722 texture, sub_resource_idx, context, box, data->buffer_object, data->addr, row_pitch, slice_pitch);
1723
1725
1726 if (!box)
1727 {
1728 x = 0;
1729 update_w = width;
1730 }
1731 else
1732 {
1733 x = box->left;
1734 update_w = box->right - box->left;
1735 }
1736
1737 if (format->upload)
1738 {
1739 unsigned int dst_row_pitch;
1740
1741 if (data->buffer_object)
1742 ERR("Loading a converted texture from a PBO.\n");
1743 if (texture->resource.format_flags & WINED3DFMT_FLAG_BLOCKS)
1744 ERR("Converting a block-based format.\n");
1745
1746 dst_row_pitch = update_w * format->conv_byte_count;
1747
1748 converted_mem = HeapAlloc(GetProcessHeap(), 0, dst_row_pitch);
1749 format->upload(data->addr, converted_mem, row_pitch, slice_pitch, dst_row_pitch, dst_row_pitch, update_w, 1, 1);
1750 mem = converted_mem;
1751 }
1752
1753 if (data->buffer_object)
1754 {
1755 GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, data->buffer_object));
1756 checkGLcall("glBindBuffer");
1757 }
1758
1761 {
1762 gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_ROW_LENGTH, row_pitch / format->byte_count);
1763
1764 gl_info->gl_ops.gl.p_glTexSubImage2D(target, level, x, surface->texture_layer, update_w, 1, format->glFormat, format->glType, mem);
1765 checkGLcall("glTexSubImage2D");
1766
1767 gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
1768 }
1769 else
1770 {
1771 gl_info->gl_ops.gl.p_glTexSubImage1D(target, level, x, update_w, format->glFormat, format->glType, mem);
1772 checkGLcall("glTexSubImage1D");
1773 }
1774
1775 if (data->buffer_object)
1776 {
1777 GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));
1778 checkGLcall("glBindBuffer");
1779 }
1780
1781 HeapFree(GetProcessHeap(), 0, converted_mem);
1782}
GLint level
Definition: gl.h:1546
#define GL_UNPACK_ROW_LENGTH
Definition: gl.h:634
#define GL_PIXEL_UNPACK_BUFFER
Definition: glext.h:477
Definition: palette.c:468
#define WINED3DFMT_FLAG_BLOCKS

Referenced by texture1d_load_location(), and texture1d_srgb_transfer().

◆ texture2d_cleanup_sub_resources()

static void texture2d_cleanup_sub_resources ( struct wined3d_texture texture)
static

Definition at line 2161 of file texture.c.

2162{
2163 unsigned int sub_count = texture->level_count * texture->layer_count;
2164 struct wined3d_device *device = texture->resource.device;
2165 struct wined3d_texture_sub_resource *sub_resource;
2166 struct wined3d_renderbuffer_entry *entry, *entry2;
2167 const struct wined3d_gl_info *gl_info = NULL;
2168 struct wined3d_context *context = NULL;
2169 struct wined3d_surface *surface;
2170 unsigned int i;
2171
2172 for (i = 0; i < sub_count; ++i)
2173 {
2174 sub_resource = &texture->sub_resources[i];
2175 if (!(surface = sub_resource->u.surface))
2176 continue;
2177
2178 TRACE("surface %p.\n", surface);
2179
2180 if (!context && !list_empty(&surface->renderbuffers))
2181 {
2183 gl_info = context->gl_info;
2184 }
2185
2187 {
2188 TRACE("Deleting renderbuffer %u.\n", entry->id);
2190 gl_info->fbo_ops.glDeleteRenderbuffers(1, &entry->id);
2192 }
2193
2194 if (surface->dc)
2195 texture2d_destroy_dc(surface);
2196 }
2197 if (context)
2199 heap_free(texture->sub_resources[0].u.surface);
2200}
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
static int list_empty(struct list_entry *head)
Definition: list.h:58
struct wined3d_context * context_acquire(const struct wined3d_device *device, struct wined3d_texture *texture, unsigned int sub_resource_idx)
Definition: context.c:4242
void context_release(struct wined3d_context *context)
Definition: context.c:1571
static void texture2d_destroy_dc(void *object)
Definition: texture.c:1316
uint32_t entry
Definition: isohybrid.c:63
#define LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, list, type, field)
Definition: list.h:204
struct wined3d_fbo_ops fbo_ops

◆ texture2d_create_dc()

static void texture2d_create_dc ( void object)
static

Definition at line 1255 of file texture.c.

1256{
1257 struct wined3d_surface *surface = object;
1258 struct wined3d_context *context = NULL;
1259 const struct wined3d_format *format;
1260 unsigned int row_pitch, slice_pitch;
1261 struct wined3d_texture *texture;
1262 struct wined3d_bo_address data;
1263 D3DKMT_CREATEDCFROMMEMORY desc;
1264 unsigned int sub_resource_idx;
1265 struct wined3d_device *device;
1267
1268 TRACE("surface %p.\n", surface);
1269
1270 texture = surface->container;
1271 sub_resource_idx = surface_get_sub_resource_idx(surface);
1272 device = texture->resource.device;
1273
1274 format = texture->resource.format;
1275 if (!format->ddi_format)
1276 {
1277 WARN("Cannot create a DC for format %s.\n", debug_d3dformat(format->id));
1278 return;
1279 }
1280
1281 if (device->d3d_initialized)
1283
1284 wined3d_texture_load_location(texture, sub_resource_idx, context, texture->resource.map_binding);
1285 wined3d_texture_invalidate_location(texture, sub_resource_idx, ~texture->resource.map_binding);
1286 wined3d_texture_get_pitch(texture, surface->texture_level, &row_pitch, &slice_pitch);
1287 wined3d_texture_get_memory(texture, sub_resource_idx, &data, texture->resource.map_binding);
1289 texture->sub_resources[sub_resource_idx].size,
1291
1292 if (context)
1294
1295 desc.Format = format->ddi_format;
1298 desc.Pitch = row_pitch;
1299 desc.hDeviceDc = CreateCompatibleDC(NULL);
1300 desc.pColorTable = NULL;
1301
1303 DeleteDC(desc.hDeviceDc);
1304 if (status)
1305 {
1306 WARN("Failed to create DC, status %#x.\n", status);
1307 return;
1308 }
1309
1310 surface->dc = desc.hDc;
1311 surface->bitmap = desc.hBitmap;
1312
1313 TRACE("Created DC %p, bitmap %p for surface %p.\n", surface->dc, surface->bitmap, surface);
1314}
LONG NTSTATUS
Definition: precomp.h:26
void * context_map_bo_address(struct wined3d_context *context, const struct wined3d_bo_address *data, size_t size, GLenum binding, DWORD flags)
Definition: context.c:2802
BOOL wined3d_texture_load_location(struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, DWORD location)
Definition: texture.c:229
void wined3d_texture_get_memory(struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_bo_address *data, DWORD locations)
Definition: texture.c:285
Definition: ps.c:97
NTSTATUS APIENTRY D3DKMTCreateDCFromMemory(_Inout_ D3DKMT_CREATEDCFROMMEMORY *desc)
Definition: dc.c:18
#define WINED3D_MAP_READ
Definition: wined3d.h:939
#define WINED3D_MAP_WRITE
Definition: wined3d.h:938
static unsigned int wined3d_texture_get_level_height(const struct wined3d_texture *texture, unsigned int level)
static unsigned int surface_get_sub_resource_idx(const struct wined3d_surface *surface)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
BOOL WINAPI DeleteDC(_In_ HDC)

Referenced by texture_init(), wined3d_texture_get_dc(), and wined3d_texture_update_desc().

◆ texture2d_destroy_dc()

static void texture2d_destroy_dc ( void object)
static

Definition at line 1316 of file texture.c.

1317{
1318 struct wined3d_surface *surface = object;
1319 D3DKMT_DESTROYDCFROMMEMORY destroy_desc;
1320 struct wined3d_context *context = NULL;
1321 struct wined3d_texture *texture;
1322 struct wined3d_bo_address data;
1323 unsigned int sub_resource_idx;
1324 struct wined3d_device *device;
1326
1327 texture = surface->container;
1328 sub_resource_idx = surface_get_sub_resource_idx(surface);
1329 device = texture->resource.device;
1330
1331 if (!surface->dc)
1332 {
1333 ERR("Surface %p has no DC.\n", surface);
1334 return;
1335 }
1336
1337 TRACE("dc %p, bitmap %p.\n", surface->dc, surface->bitmap);
1338
1339 destroy_desc.hDc = surface->dc;
1340 destroy_desc.hBitmap = surface->bitmap;
1341 if ((status = D3DKMTDestroyDCFromMemory(&destroy_desc)))
1342 ERR("Failed to destroy dc, status %#x.\n", status);
1343 surface->dc = NULL;
1344 surface->bitmap = NULL;
1345
1346 if (device->d3d_initialized)
1348
1349 wined3d_texture_get_memory(texture, sub_resource_idx, &data, texture->resource.map_binding);
1351
1352 if (context)
1354}
void context_unmap_bo_address(struct wined3d_context *context, const struct wined3d_bo_address *data, GLenum binding)
Definition: context.c:2831
NTSTATUS APIENTRY D3DKMTDestroyDCFromMemory(_In_ CONST D3DKMT_DESTROYDCFROMMEMORY *desc)
Definition: dc.c:23

Referenced by texture2d_cleanup_sub_resources(), wined3d_texture_release_dc(), and wined3d_texture_update_desc().

◆ texture2d_load_location()

static BOOL texture2d_load_location ( struct wined3d_texture texture,
unsigned int  sub_resource_idx,
struct wined3d_context context,
DWORD  location 
)
static

Definition at line 2113 of file texture.c.

2115{
2116 return surface_load_location(texture->sub_resources[sub_resource_idx].u.surface, context, location);
2117}
BOOL surface_load_location(struct wined3d_surface *surface, struct wined3d_context *context, DWORD location)
Definition: surface.c:2630

◆ texture2d_prepare_texture()

static void texture2d_prepare_texture ( struct wined3d_texture texture,
struct wined3d_context context,
BOOL  srgb 
)
static

Definition at line 2120 of file texture.c.

2121{
2122 const struct wined3d_format *format = texture->resource.format;
2123 const struct wined3d_gl_info *gl_info = context->gl_info;
2124 const struct wined3d_color_key_conversion *conversion;
2126
2127 TRACE("texture %p, context %p, format %s.\n", texture, context, debug_d3dformat(format->id));
2128
2129 if (format->conv_byte_count)
2130 {
2132 }
2133 else if ((conversion = wined3d_format_get_color_key_conversion(texture, TRUE)))
2134 {
2136 format = wined3d_get_format(gl_info, conversion->dst_format, texture->resource.usage);
2137 TRACE("Using format %s for color key conversion.\n", debug_d3dformat(format->id));
2138 }
2139
2141
2142 if (srgb)
2143 internal = format->glGammaInternal;
2144 else if (texture->resource.usage & WINED3DUSAGE_RENDERTARGET
2146 internal = format->rtInternal;
2147 else
2148 internal = format->glInternal;
2149
2150 if (!internal)
2151 FIXME("No GL internal format for format %s.\n", debug_d3dformat(format->id));
2152
2153 TRACE("internal %#x, format %#x, type %#x.\n", internal, format->glFormat, format->glType);
2154
2157 else
2159}
static void wined3d_texture_allocate_gl_immutable_storage(struct wined3d_texture *texture, GLenum gl_internal_format, const struct wined3d_gl_info *gl_info)
Definition: texture.c:564
static void wined3d_texture_allocate_gl_mutable_storage(struct wined3d_texture *texture, GLenum gl_internal_format, const struct wined3d_format *format, const struct wined3d_gl_info *gl_info)
Definition: texture.c:518
const struct wined3d_format * wined3d_get_format(const struct wined3d_gl_info *gl_info, enum wined3d_format_id format_id, unsigned int resource_usage)
Definition: utils.c:3831
const struct wined3d_color_key_conversion * wined3d_format_get_color_key_conversion(const struct wined3d_texture *texture, BOOL need_alpha_ck)
Definition: utils.c:1046
enum wined3d_format_id dst_format
#define WINED3D_TEXTURE_CONVERTED

◆ texture2d_upload_data()

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 
)
static

Definition at line 2084 of file texture.c.

2087{
2088 unsigned int texture_level;
2089 POINT dst_point;
2090 RECT src_rect;
2091
2092 src_rect.left = 0;
2093 src_rect.top = 0;
2094 if (box)
2095 {
2096 dst_point.x = box->left;
2097 dst_point.y = box->top;
2098 src_rect.right = box->right - box->left;
2099 src_rect.bottom = box->bottom - box->top;
2100 }
2101 else
2102 {
2103 dst_point.x = dst_point.y = 0;
2104 texture_level = sub_resource_idx % texture->level_count;
2105 src_rect.right = wined3d_texture_get_level_width(texture, texture_level);
2106 src_rect.bottom = wined3d_texture_get_level_height(texture, texture_level);
2107 }
2108
2109 wined3d_surface_upload_data(texture->sub_resources[sub_resource_idx].u.surface, context->gl_info,
2110 texture->resource.format, &src_rect, row_pitch, &dst_point, FALSE, data);
2111}
void wined3d_surface_upload_data(struct wined3d_surface *surface, const struct wined3d_gl_info *gl_info, const struct wined3d_format *format, const RECT *src_rect, UINT src_pitch, const POINT *dst_point, BOOL srgb, const struct wined3d_const_bo_address *data)
Definition: surface.c:779
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306

◆ texture3d_cleanup_sub_resources()

static void texture3d_cleanup_sub_resources ( struct wined3d_texture texture)
static

Definition at line 3152 of file texture.c.

3153{
3154}

◆ texture3d_download_data()

static void texture3d_download_data ( struct wined3d_texture texture,
unsigned int  sub_resource_idx,
const struct wined3d_context context,
const struct wined3d_bo_address data 
)
static

Definition at line 2955 of file texture.c.

2957{
2958 const struct wined3d_format *format = texture->resource.format;
2959 const struct wined3d_gl_info *gl_info = context->gl_info;
2960
2961 if (format->conv_byte_count)
2962 {
2963 FIXME("Attempting to download a converted volume, format %s.\n",
2964 debug_d3dformat(format->id));
2965 return;
2966 }
2967
2968 if (data->buffer_object)
2969 {
2970 GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, data->buffer_object));
2971 checkGLcall("glBindBuffer");
2972 }
2973
2974 gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_3D, sub_resource_idx,
2975 format->glFormat, format->glType, data->addr);
2976 checkGLcall("glGetTexImage");
2977
2978 if (data->buffer_object)
2979 {
2980 GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, 0));
2981 checkGLcall("glBindBuffer");
2982 }
2983
2984}
#define GL_TEXTURE_3D
Definition: gl.h:1515

Referenced by texture3d_load_location(), and texture3d_srgb_transfer().

◆ texture3d_load_location()

static BOOL texture3d_load_location ( struct wined3d_texture texture,
unsigned int  sub_resource_idx,
struct wined3d_context context,
DWORD  location 
)
static

Definition at line 3016 of file texture.c.

3018{
3019 struct wined3d_texture_sub_resource *sub_resource = &texture->sub_resources[sub_resource_idx];
3020 unsigned int row_pitch, slice_pitch;
3021
3022 if (!wined3d_texture_prepare_location(texture, sub_resource_idx, context, location))
3023 return FALSE;
3024
3025 switch (location)
3026 {
3029 if (sub_resource->locations & WINED3D_LOCATION_SYSMEM)
3030 {
3031 struct wined3d_const_bo_address data = {0, texture->resource.heap_memory};
3032 data.addr += sub_resource->offset;
3035 wined3d_texture_get_pitch(texture, sub_resource_idx, &row_pitch, &slice_pitch);
3036 texture3d_upload_data(texture, sub_resource_idx, context, NULL, &data, row_pitch, slice_pitch);
3037 }
3038 else if (sub_resource->locations & WINED3D_LOCATION_BUFFER)
3039 {
3040#if !defined(STAGING_CSMT)
3041 struct wined3d_const_bo_address data = {sub_resource->buffer_object, NULL};
3042#else /* STAGING_CSMT */
3043 struct wined3d_const_bo_address data = {sub_resource->buffer->name, NULL};
3044#endif /* STAGING_CSMT */
3047 wined3d_texture_get_pitch(texture, sub_resource_idx, &row_pitch, &slice_pitch);
3048 texture3d_upload_data(texture, sub_resource_idx, context, NULL, &data, row_pitch, slice_pitch);
3049 }
3050 else if (sub_resource->locations & WINED3D_LOCATION_TEXTURE_RGB)
3051 {
3052 texture3d_srgb_transfer(texture, sub_resource_idx, context, TRUE);
3053 }
3054 else if (sub_resource->locations & WINED3D_LOCATION_TEXTURE_SRGB)
3055 {
3056 texture3d_srgb_transfer(texture, sub_resource_idx, context, FALSE);
3057 }
3058 else
3059 {
3060 FIXME("Implement texture loading from %s.\n", wined3d_debug_location(sub_resource->locations));
3061 return FALSE;
3062 }
3063 break;
3064
3066 if (sub_resource->locations & (WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_TEXTURE_SRGB))
3067 {
3068 struct wined3d_bo_address data = {0, texture->resource.heap_memory};
3069
3070 data.addr += sub_resource->offset;
3071 if (sub_resource->locations & WINED3D_LOCATION_TEXTURE_RGB)
3073 else
3075
3076 texture3d_download_data(texture, sub_resource_idx, context, &data);
3077 ++texture->download_count;
3078 }
3079 else
3080 {
3081 FIXME("Implement WINED3D_LOCATION_SYSMEM loading from %s.\n",
3082 wined3d_debug_location(sub_resource->locations));
3083 return FALSE;
3084 }
3085 break;
3086
3088 if (sub_resource->locations & (WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_TEXTURE_SRGB))
3089 {
3090#if !defined(STAGING_CSMT)
3091 struct wined3d_bo_address data = {sub_resource->buffer_object, NULL};
3092#else /* STAGING_CSMT */
3093 struct wined3d_bo_address data = {sub_resource->buffer->name, NULL};
3094#endif /* STAGING_CSMT */
3095
3096 if (sub_resource->locations & WINED3D_LOCATION_TEXTURE_RGB)
3098 else
3100
3101 texture3d_download_data(texture, sub_resource_idx, context, &data);
3102 }
3103 else
3104 {
3105 FIXME("Implement WINED3D_LOCATION_BUFFER loading from %s.\n",
3106 wined3d_debug_location(sub_resource->locations));
3107 return FALSE;
3108 }
3109 break;
3110
3111 default:
3112 FIXME("Implement %s loading from %s.\n", wined3d_debug_location(location),
3113 wined3d_debug_location(sub_resource->locations));
3114 return FALSE;
3115 }
3116
3117 return TRUE;
3118}
static void texture3d_srgb_transfer(struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, BOOL dest_is_srgb)
Definition: texture.c:2987
static void texture3d_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)
Definition: texture.c:2875
static void texture3d_download_data(struct wined3d_texture *texture, unsigned int sub_resource_idx, const struct wined3d_context *context, const struct wined3d_bo_address *data)
Definition: texture.c:2955

◆ texture3d_prepare_texture()

static void texture3d_prepare_texture ( struct wined3d_texture texture,
struct wined3d_context context,
BOOL  srgb 
)
static

Definition at line 3120 of file texture.c.

3121{
3122 const struct wined3d_format *format = texture->resource.format;
3123 GLenum internal = srgb ? format->glGammaInternal : format->glInternal;
3124 unsigned int sub_count = texture->level_count * texture->layer_count;
3125 const struct wined3d_gl_info *gl_info = context->gl_info;
3126 unsigned int i;
3127
3129
3131 {
3132 GL_EXTCALL(glTexStorage3D(GL_TEXTURE_3D, texture->level_count, internal,
3136 checkGLcall("glTexStorage3D");
3137 }
3138 else
3139 {
3140 for (i = 0; i < sub_count; ++i)
3141 {
3146 0, format->glFormat, format->glType, NULL));
3147 checkGLcall("glTexImage3D");
3148 }
3149 }
3150}
GLAPI void GLAPIENTRY glTexImage3D(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels)
static unsigned int wined3d_texture_get_level_depth(const struct wined3d_texture *texture, unsigned int level)

◆ texture3d_srgb_transfer()

static void texture3d_srgb_transfer ( struct wined3d_texture texture,
unsigned int  sub_resource_idx,
struct wined3d_context context,
BOOL  dest_is_srgb 
)
static

Definition at line 2987 of file texture.c.

2989{
2990 struct wined3d_texture_sub_resource *sub_resource = &texture->sub_resources[sub_resource_idx];
2991 unsigned int row_pitch, slice_pitch;
2992 struct wined3d_bo_address data;
2993
2994 /* Optimisations are possible, but the effort should be put into either
2995 * implementing EXT_SRGB_DECODE in the driver or finding out why we
2996 * picked the wrong copy for the original upload and fixing that.
2997 *
2998 * Also keep in mind that we want to avoid using resource.heap_memory
2999 * for DEFAULT pool surfaces. */
3000 WARN_(d3d_perf)("Performing slow rgb/srgb volume transfer.\n");
3001 data.buffer_object = 0;
3002 if (!(data.addr = heap_alloc(sub_resource->size)))
3003 return;
3004
3005 wined3d_texture_get_pitch(texture, sub_resource_idx, &row_pitch, &slice_pitch);
3007 texture3d_download_data(texture, sub_resource_idx, context, &data);
3009 texture3d_upload_data(texture, sub_resource_idx, context,
3010 NULL, wined3d_const_bo_address(&data), row_pitch, slice_pitch);
3011
3012 heap_free(data.addr);
3013}
static void * heap_alloc(size_t len)
Definition: appwiz.h:66

Referenced by texture3d_load_location().

◆ texture3d_upload_data()

static void texture3d_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 
)
static

Definition at line 2875 of file texture.c.

2878{
2879 const struct wined3d_format *format = texture->resource.format;
2880 unsigned int level = sub_resource_idx % texture->level_count;
2881 const struct wined3d_gl_info *gl_info = context->gl_info;
2882 unsigned int x, y, z, update_w, update_h, update_d;
2883 unsigned int dst_row_pitch, dst_slice_pitch;
2884 unsigned int width, height, depth;
2885 const void *mem = data->addr;
2886 void *converted_mem = NULL;
2887
2888 TRACE("texture %p, sub_resource_idx %u, context %p, box %s, data {%#x:%p}, row_pitch %#x, slice_pitch %#x.\n",
2889 texture, sub_resource_idx, context, debug_box(box),
2890 data->buffer_object, data->addr, row_pitch, slice_pitch);
2891
2895
2896 if (!box)
2897 {
2898 x = y = z = 0;
2899 update_w = width;
2900 update_h = height;
2901 update_d = depth;
2902 }
2903 else
2904 {
2905 x = box->left;
2906 y = box->top;
2907 z = box->front;
2908 update_w = box->right - box->left;
2909 update_h = box->bottom - box->top;
2910 update_d = box->back - box->front;
2911 }
2912
2913 if (format->conv_byte_count)
2914 {
2915 if (data->buffer_object)
2916 ERR("Loading a converted texture from a PBO.\n");
2917 if (texture->resource.format_flags & WINED3DFMT_FLAG_BLOCKS)
2918 ERR("Converting a block-based format.\n");
2919
2920 dst_row_pitch = update_w * format->conv_byte_count;
2921 dst_slice_pitch = dst_row_pitch * update_h;
2922
2923 converted_mem = heap_calloc(update_d, dst_slice_pitch);
2924 format->upload(data->addr, converted_mem, row_pitch, slice_pitch,
2925 dst_row_pitch, dst_slice_pitch, update_w, update_h, update_d);
2926 mem = converted_mem;
2927 }
2928 else
2929 {
2930 wined3d_texture_get_pitch(texture, sub_resource_idx, &dst_row_pitch, &dst_slice_pitch);
2931 if (row_pitch != dst_row_pitch || slice_pitch != dst_slice_pitch)
2932 FIXME("Ignoring row/slice pitch (%u/%u).\n", row_pitch, slice_pitch);
2933 }
2934
2935 if (data->buffer_object)
2936 {
2937 GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, data->buffer_object));
2938 checkGLcall("glBindBuffer");
2939 }
2940
2942 update_w, update_h, update_d, format->glFormat, format->glType, mem));
2943 checkGLcall("glTexSubImage3D");
2944
2945 if (data->buffer_object)
2946 {
2947 GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));
2948 checkGLcall("glBindBuffer");
2949 }
2950
2951 heap_free(converted_mem);
2952}
const char * debug_box(const struct wined3d_box *box)
Definition: utils.c:3939
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLAPI void GLAPIENTRY glTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels)
GLdouble GLdouble z
Definition: glext.h:5874

Referenced by texture3d_load_location(), and texture3d_srgb_transfer().

◆ texture_init()

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 
)
static

Definition at line 2641 of file texture.c.

2644{
2645 struct wined3d_device_parent *device_parent = device->device_parent;
2646 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
2647 struct wined3d_surface *surfaces;
2648 UINT pow2_width, pow2_height;
2649 unsigned int i, j, sub_count;
2650 HRESULT hr;
2651
2652 if (!(desc->usage & WINED3DUSAGE_LEGACY_CUBEMAP) && layer_count > 1
2653 && !gl_info->supported[EXT_TEXTURE_ARRAY])
2654 {
2655 WARN("OpenGL implementation does not support array textures.\n");
2657 }
2658
2659 /* TODO: It should only be possible to create textures for formats
2660 * that are reported as supported. */
2661 if (WINED3DFMT_UNKNOWN >= desc->format)
2662 {
2663 WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
2665 }
2666
2668 FIXME("Trying to create a managed texture with dynamic usage.\n");
2671 WARN("Creating a mappable texture that doesn't specify dynamic usage.\n");
2673 FIXME("Trying to create a CPU accessible render target.\n");
2674
2675 pow2_width = desc->width;
2676 pow2_height = desc->height;
2677 if (((desc->width & (desc->width - 1)) || (desc->height & (desc->height - 1)))
2679 {
2680 /* level_count == 0 returns an error as well. */
2681 if (level_count != 1 || layer_count != 1)
2682 {
2683 if (!(desc->usage & WINED3DUSAGE_SCRATCH))
2684 {
2685 WARN("Attempted to create a mipmapped/cube/array NPOT texture without unconditional NPOT support.\n");
2687 }
2688
2689 WARN("Creating a scratch mipmapped/cube/array NPOT texture despite lack of HW support.\n");
2690 }
2692
2694 {
2695 const struct wined3d_format *format = wined3d_get_format(gl_info, desc->format, desc->usage);
2696
2697 /* TODO: Add support for non-power-of-two compressed textures. */
2700 {
2701 FIXME("Compressed or height scaled non-power-of-two (%ux%u) textures are not supported.\n",
2702 desc->width, desc->height);
2704 }
2705
2706 /* Find the nearest pow2 match. */
2707 pow2_width = pow2_height = 1;
2708 while (pow2_width < desc->width)
2709 pow2_width <<= 1;
2710 while (pow2_height < desc->height)
2711 pow2_height <<= 1;
2713 }
2714 }
2715 texture->pow2_width = pow2_width;
2716 texture->pow2_height = pow2_height;
2717
2718 if ((pow2_width > gl_info->limits.texture_size || pow2_height > gl_info->limits.texture_size)
2719 && (desc->usage & WINED3DUSAGE_TEXTURE))
2720 {
2721 /* One of four options:
2722 * 1: Do the same as we do with NPOT and scale the texture. (Any
2723 * texture ops would require the texture to be scaled which is
2724 * potentially slow.)
2725 * 2: Set the texture to the maximum size (bad idea).
2726 * 3: WARN and return WINED3DERR_NOTAVAILABLE.
2727 * 4: Create the surface, but allow it to be used only for DirectDraw
2728 * Blts. Some apps (e.g. Swat 3) create textures with a height of
2729 * 16 and a width > 3000 and blt 16x16 letter areas from them to
2730 * the render target. */
2731 if (desc->access & WINED3D_RESOURCE_ACCESS_GPU)
2732 {
2733 WARN("Dimensions (%ux%u) exceed the maximum texture size.\n", pow2_width, pow2_height);
2735 }
2736
2737 /* We should never use this surface in combination with OpenGL. */
2738 TRACE("Creating an oversized (%ux%u) surface.\n", pow2_width, pow2_height);
2739 }
2740
2741 if (FAILED(hr = wined3d_texture_init(texture, &texture2d_ops, layer_count, level_count, desc,
2742 flags, device, parent, parent_ops, &texture_resource_ops)))
2743 {
2744 WARN("Failed to initialize texture, returning %#x.\n", hr);
2745 return hr;
2746 }
2747
2748 /* Precalculated scaling for 'faked' non power of two texture coords. */
2749 if (texture->resource.gl_type == WINED3D_GL_RES_TYPE_TEX_RECT)
2750 {
2751 texture->pow2_matrix[0] = (float)desc->width;
2752 texture->pow2_matrix[5] = (float)desc->height;
2755 }
2756 else
2757 {
2759 {
2760 texture->pow2_matrix[0] = (((float)desc->width) / ((float)pow2_width));
2761 texture->pow2_matrix[5] = (((float)desc->height) / ((float)pow2_height));
2762 texture->flags &= ~WINED3D_TEXTURE_POW2_MAT_IDENT;
2763 }
2764 else
2765 {
2766 texture->pow2_matrix[0] = 1.0f;
2767 texture->pow2_matrix[5] = 1.0f;
2768 }
2769 if (desc->usage & WINED3DUSAGE_LEGACY_CUBEMAP)
2770 {
2772 }
2773 else if (desc->multisample_type && gl_info->supported[ARB_TEXTURE_MULTISAMPLE])
2774 {
2775 if (layer_count > 1)
2777 else
2779 }
2780 else
2781 {
2782 if (layer_count > 1)
2783 texture->target = GL_TEXTURE_2D_ARRAY;
2784 else
2785 texture->target = GL_TEXTURE_2D;
2786 }
2787 }
2788 texture->pow2_matrix[10] = 1.0f;
2789 texture->pow2_matrix[15] = 1.0f;
2790 TRACE("x scale %.8e, y scale %.8e.\n", texture->pow2_matrix[0], texture->pow2_matrix[5]);
2791
2792 if (wined3d_texture_use_pbo(texture, gl_info))
2793 texture->resource.map_binding = WINED3D_LOCATION_BUFFER;
2794
2795 sub_count = level_count * layer_count;
2796 if (sub_count / layer_count != level_count
2797 || !(surfaces = heap_calloc(sub_count, sizeof(*surfaces))))
2798 {
2800 return E_OUTOFMEMORY;
2801 }
2802
2803 if (desc->usage & WINED3DUSAGE_OVERLAY)
2804 {
2805 if (!(texture->overlay_info = heap_calloc(sub_count, sizeof(*texture->overlay_info))))
2806 {
2809 return E_OUTOFMEMORY;
2810 }
2811
2812 for (i = 0; i < sub_count; ++i)
2813 {
2814 list_init(&texture->overlay_info[i].entry);
2815 list_init(&texture->overlay_info[i].overlays);
2816 }
2817 }
2818
2819 /* Generate all the surfaces. */
2820 for (i = 0; i < texture->level_count; ++i)
2821 {
2822 for (j = 0; j < texture->layer_count; ++j)
2823 {
2824 struct wined3d_texture_sub_resource *sub_resource;
2825 unsigned int idx = j * texture->level_count + i;
2826 struct wined3d_surface *surface;
2827
2828 surface = &surfaces[idx];
2829 surface->container = texture;
2830 surface->texture_level = i;
2831 surface->texture_layer = j;
2832 list_init(&surface->renderbuffers);
2833
2834 sub_resource = &texture->sub_resources[idx];
2835 sub_resource->locations = WINED3D_LOCATION_DISCARDED;
2836 sub_resource->u.surface = surface;
2837 if (!(texture->resource.usage & WINED3DUSAGE_DEPTHSTENCIL))
2838 {
2841 }
2842
2843 if (FAILED(hr = device_parent->ops->surface_created(device_parent,
2844 texture, idx, &sub_resource->parent, &sub_resource->parent_ops)))
2845 {
2846 WARN("Failed to create surface parent, hr %#x.\n", hr);
2847 sub_resource->parent = NULL;
2849 return hr;
2850 }
2851
2852 TRACE("parent %p, parent_ops %p.\n", sub_resource->parent, sub_resource->parent_ops);
2853
2854 TRACE("Created surface level %u, layer %u @ %p.\n", i, j, surface);
2855
2856 if ((desc->usage & WINED3DUSAGE_OWNDC) || (device->wined3d->flags & WINED3D_NO3D))
2857 {
2859 device->cs->ops->finish(device->cs, WINED3D_CS_QUEUE_DEFAULT);
2860 if (!surface->dc)
2861 {
2864 }
2865 }
2866 }
2867 }
2868
2869 return WINED3D_OK;
2870}
void wined3d_cs_init_object(struct wined3d_cs *cs, void(*callback)(void *object), void *object)
Definition: cs.c:1890
static void texture2d_create_dc(void *object)
Definition: texture.c:1255
static const struct wined3d_texture_ops texture2d_ops
Definition: texture.c:2202
#define GL_TEXTURE_2D
Definition: gl.h:645
#define GL_TEXTURE_CUBE_MAP_ARB
Definition: glext.h:1230
GLbitfield flags
Definition: glext.h:7161
#define GL_TEXTURE_2D_MULTISAMPLE_ARRAY
Definition: glext.h:1941
#define GL_TEXTURE_2D_MULTISAMPLE
Definition: glext.h:1939
#define GL_TEXTURE_RECTANGLE_ARB
Definition: glext.h:1614
#define GL_TEXTURE_2D_ARRAY
Definition: glext.h:535
static float(__cdecl *square_half_float)(float x
unsigned int UINT
Definition: ndis.h:50
struct wined3d_gl_limits limits
#define WINED3D_NO3D
Definition: wined3d.h:1316
#define WINED3DUSAGE_OWNDC
Definition: wined3d.h:919
#define WINED3D_RESOURCE_ACCESS_GPU
Definition: wined3d.h:55
#define WINED3D_RESOURCE_ACCESS_CPU
Definition: wined3d.h:56
#define WINED3DERR_NOTAVAILABLE
Definition: wined3d.h:46
#define WINED3DUSAGE_OVERLAY
Definition: wined3d.h:921
#define WINED3D_TEXTURE_CREATE_MAPPABLE
Definition: wined3d.h:1558
#define WINED3DUSAGE_TEXTURE
Definition: wined3d.h:918
#define WINED3DUSAGE_DEPTHSTENCIL
Definition: wined3d.h:900
@ ARB_TEXTURE_MULTISAMPLE
Definition: wined3d_gl.h:122
@ WINED3D_GL_NORMALIZED_TEXRECT
Definition: wined3d_gl.h:214
@ ARB_TEXTURE_RECTANGLE
Definition: wined3d_gl.h:125
#define WINED3DFMT_FLAG_HEIGHT_SCALE
#define WINED3D_TEXTURE_POW2_MAT_IDENT
#define WINED3D_TEXTURE_COND_NP2
#define WINED3D_TEXTURE_COND_NP2_EMULATED
@ WINED3D_GL_RES_TYPE_TEX_2D
@ WINED3D_GL_RES_TYPE_TEX_RECT
#define WINED3DFMT_FLAG_COMPRESSED
#define WINED3D_TEXTURE_NORMALIZED_COORDS
@ WINED3D_CS_QUEUE_DEFAULT

◆ texture_resource_decref()

static ULONG texture_resource_decref ( struct wined3d_resource resource)
static

Definition at line 2220 of file texture.c.

2221{
2223}
ULONG CDECL wined3d_texture_decref(struct wined3d_texture *texture)
Definition: texture.c:1023
static struct wined3d_texture * texture_from_resource(struct wined3d_resource *resource)

◆ texture_resource_incref()

static ULONG texture_resource_incref ( struct wined3d_resource resource)
static

Definition at line 2215 of file texture.c.

2216{
2218}
ULONG CDECL wined3d_texture_incref(struct wined3d_texture *texture)
Definition: texture.c:994

◆ texture_resource_preload()

static void texture_resource_preload ( struct wined3d_resource resource)
static

Definition at line 2225 of file texture.c.

2226{
2228 struct wined3d_context *context;
2229
2230 context = context_acquire(resource->device, NULL, 0);
2233}
void wined3d_texture_load(struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb)
Definition: texture.c:1066
#define WINED3D_TEXTURE_IS_SRGB

◆ texture_resource_sub_resource_map()

static HRESULT texture_resource_sub_resource_map ( struct wined3d_resource resource,
unsigned int  sub_resource_idx,
struct wined3d_map_desc map_desc,
const struct wined3d_box box,
DWORD  flags 
)
static

Definition at line 2302 of file texture.c.

2304{
2305 const struct wined3d_format *format = resource->format;
2306 struct wined3d_texture_sub_resource *sub_resource;
2307 struct wined3d_device *device = resource->device;
2308 unsigned int fmt_flags = resource->format_flags;
2309 struct wined3d_context *context = NULL;
2310 struct wined3d_texture *texture;
2311 struct wined3d_bo_address data;
2312 unsigned int texture_level;
2313 BYTE *base_memory;
2314 BOOL ret;
2315
2316 TRACE("resource %p, sub_resource_idx %u, map_desc %p, box %s, flags %#x.\n",
2317 resource, sub_resource_idx, map_desc, debug_box(box), flags);
2318
2320 if (!(sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx)))
2321 return E_INVALIDARG;
2322
2323 texture_level = sub_resource_idx % texture->level_count;
2325 {
2326 WARN("Map box is invalid.\n");
2327 if (((fmt_flags & WINED3DFMT_FLAG_BLOCKS) && !(resource->access & WINED3D_RESOURCE_ACCESS_CPU))
2330 }
2331
2333 {
2334 WARN("DC is in use.\n");
2336 }
2337
2338 if (sub_resource->map_count)
2339 {
2340 WARN("Sub-resource is already mapped.\n");
2342 }
2343
2344 if (device->d3d_initialized)
2346
2348 {
2349 TRACE("WINED3D_MAP_DISCARD flag passed, marking %s as up to date.\n",
2350 wined3d_debug_location(resource->map_binding));
2351 if ((ret = wined3d_texture_prepare_location(texture, sub_resource_idx, context, resource->map_binding)))
2352 wined3d_texture_validate_location(texture, sub_resource_idx, resource->map_binding);
2353 }
2354 else
2355 {
2356 if (resource->usage & WINED3DUSAGE_DYNAMIC)
2357 WARN_(d3d_perf)("Mapping a dynamic texture without WINED3D_MAP_DISCARD.\n");
2358 ret = wined3d_texture_load_location(texture, sub_resource_idx, context, resource->map_binding);
2359 }
2360
2361 if (!ret)
2362 {
2363 ERR("Failed to prepare location.\n");
2365 return E_OUTOFMEMORY;
2366 }
2367
2370 wined3d_texture_invalidate_location(texture, sub_resource_idx, ~resource->map_binding);
2371
2372 wined3d_texture_get_memory(texture, sub_resource_idx, &data, resource->map_binding);
2373 base_memory = context_map_bo_address(context, &data, sub_resource->size, GL_PIXEL_UNPACK_BUFFER, flags);
2374 TRACE("Base memory pointer %p.\n", base_memory);
2375
2376 if (context)
2378
2379 if (fmt_flags & WINED3DFMT_FLAG_BROKEN_PITCH)
2380 {
2381 map_desc->row_pitch = wined3d_texture_get_level_width(texture, texture_level) * format->byte_count;
2382 map_desc->slice_pitch = wined3d_texture_get_level_height(texture, texture_level) * map_desc->row_pitch;
2383 }
2384 else
2385 {
2386 wined3d_texture_get_pitch(texture, texture_level, &map_desc->row_pitch, &map_desc->slice_pitch);
2387 }
2388
2389 if (!box)
2390 {
2391 map_desc->data = base_memory;
2392 }
2393 else
2394 {
2396 {
2397 /* Compressed textures are block based, so calculate the offset of
2398 * the block that contains the top-left pixel of the mapped box. */
2399 map_desc->data = base_memory
2400 + (box->front * map_desc->slice_pitch)
2401 + ((box->top / format->block_height) * map_desc->row_pitch)
2402 + ((box->left / format->block_width) * format->block_byte_count);
2403 }
2404 else
2405 {
2406 map_desc->data = base_memory
2407 + (box->front * map_desc->slice_pitch)
2408 + (box->top * map_desc->row_pitch)
2409 + (box->left * format->byte_count);
2410 }
2411 }
2412
2413 if (texture->swapchain && texture->swapchain->front_buffer == texture)
2414 {
2415 RECT *r = &texture->swapchain->front_buffer_update;
2416
2417 if (!box)
2418 SetRect(r, 0, 0, resource->width, resource->height);
2419 else
2420 SetRect(r, box->left, box->top, box->right, box->bottom);
2421 TRACE("Mapped front buffer %s.\n", wine_dbgstr_rect(r));
2422 }
2423
2424 ++resource->map_count;
2425 ++sub_resource->map_count;
2426
2427 TRACE("Returning memory %p, row pitch %u, slice pitch %u.\n",
2428 map_desc->data, map_desc->row_pitch, map_desc->slice_pitch);
2429
2430 return WINED3D_OK;
2431}
static const char * wine_dbgstr_rect(const RECT *prc)
Definition: atltest.h:160
#define E_INVALIDARG
Definition: ddrawi.h:101
HRESULT wined3d_texture_check_box_dimensions(const struct wined3d_texture *texture, unsigned int level, const struct wined3d_box *box)
Definition: texture.c:1128
static struct wined3d_texture_sub_resource * wined3d_texture_get_sub_resource(struct wined3d_texture *texture, unsigned int sub_resource_idx)
Definition: texture.c:1661
unsigned int BOOL
Definition: ntddk_ex.h:94
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
int ret
#define WINED3D_MAP_NO_DIRTY_UPDATE
Definition: wined3d.h:937
@ WINED3D_RTYPE_TEXTURE_2D
Definition: wined3d.h:700
#define WINED3D_MAP_DISCARD
Definition: wined3d.h:935
#define WINED3DFMT_FLAG_BROKEN_PITCH
#define WINED3D_TEXTURE_DC_IN_USE
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)

◆ texture_resource_sub_resource_map_info()

static HRESULT texture_resource_sub_resource_map_info ( struct wined3d_resource resource,
unsigned int  sub_resource_idx,
struct wined3d_map_info info,
DWORD  flags 
)
static

Definition at line 2433 of file texture.c.

2435{
2436 const struct wined3d_format *format = resource->format;
2437 struct wined3d_texture_sub_resource *sub_resource;
2438 unsigned int fmt_flags = resource->format_flags;
2439 struct wined3d_texture *texture;
2440 unsigned int texture_level;
2441
2443 if (!(sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx)))
2444 return E_INVALIDARG;
2445
2446 texture_level = sub_resource_idx % texture->level_count;
2447
2448 if (fmt_flags & WINED3DFMT_FLAG_BROKEN_PITCH)
2449 {
2450 info->row_pitch = wined3d_texture_get_level_width(texture, texture_level) * format->byte_count;
2451 info->slice_pitch = wined3d_texture_get_level_height(texture, texture_level) * info->row_pitch;
2452 }
2453 else
2454 {
2455 wined3d_texture_get_pitch(texture, texture_level, &info->row_pitch, &info->slice_pitch);
2456 }
2457
2458 info->size = info->slice_pitch * wined3d_texture_get_level_depth(texture, texture_level);
2459
2460 return WINED3D_OK;
2461}

◆ texture_resource_sub_resource_unmap()

static HRESULT texture_resource_sub_resource_unmap ( struct wined3d_resource resource,
unsigned int  sub_resource_idx 
)
static

Definition at line 2463 of file texture.c.

2464{
2465 struct wined3d_texture_sub_resource *sub_resource;
2466 struct wined3d_device *device = resource->device;
2467 struct wined3d_context *context = NULL;
2468 struct wined3d_texture *texture;
2469 struct wined3d_bo_address data;
2470
2471 TRACE("resource %p, sub_resource_idx %u.\n", resource, sub_resource_idx);
2472
2474 if (!(sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx)))
2475 return E_INVALIDARG;
2476
2477 if (!sub_resource->map_count)
2478 {
2479 WARN("Trying to unmap unmapped sub-resource.\n");
2481 return WINED3D_OK;
2482 return WINEDDERR_NOTLOCKED;
2483 }
2484
2485 if (device->d3d_initialized)
2487
2488 wined3d_texture_get_memory(texture, sub_resource_idx, &data, texture->resource.map_binding);
2490
2491 if (context)
2493
2494 if (texture->swapchain && texture->swapchain->front_buffer == texture)
2495 {
2496 if (!(sub_resource->locations & (WINED3D_LOCATION_DRAWABLE | WINED3D_LOCATION_TEXTURE_RGB)))
2497 texture->swapchain->swapchain_ops->swapchain_frontbuffer_updated(texture->swapchain);
2498 }
2499
2500 --sub_resource->map_count;
2501 if (!--resource->map_count && texture->update_map_binding)
2503
2504 return WINED3D_OK;
2505}
static void wined3d_texture_update_map_binding(struct wined3d_texture *texture)
Definition: texture.c:437
#define WINEDDERR_NOTLOCKED
Definition: wined3d.h:50
#define WINED3D_LOCATION_DRAWABLE

◆ volumetexture_init()

static HRESULT volumetexture_init ( struct wined3d_texture texture,
const struct wined3d_resource_desc desc,
UINT  layer_count,
UINT  level_count,
DWORD  flags,
struct wined3d_device device,
void parent,
const struct wined3d_parent_ops parent_ops 
)
static

Definition at line 3164 of file texture.c.

3167{
3168 struct wined3d_device_parent *device_parent = device->device_parent;
3169 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
3170 unsigned int i;
3171 HRESULT hr;
3172
3173 if (layer_count != 1)
3174 {
3175 ERR("Invalid layer count for volume texture.\n");
3176 return E_INVALIDARG;
3177 }
3178
3179 /* TODO: It should only be possible to create textures for formats
3180 * that are reported as supported. */
3181 if (WINED3DFMT_UNKNOWN >= desc->format)
3182 {
3183 WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
3185 }
3186
3187 if (!gl_info->supported[EXT_TEXTURE3D])
3188 {
3189 WARN("(%p) : Texture cannot be created - no volume texture support.\n", texture);
3191 }
3192
3194 || desc->usage & WINED3DUSAGE_SCRATCH))
3195 {
3196 WARN("Attempted to create a DYNAMIC texture with access %s.\n",
3199 }
3200
3202 {
3203 if (!is_power_of_two(desc->width) || !is_power_of_two(desc->height) || !is_power_of_two(desc->depth))
3204 {
3205 if (desc->usage & WINED3DUSAGE_SCRATCH)
3206 {
3207 WARN("Creating a scratch NPOT volume texture despite lack of HW support.\n");
3208 }
3209 else
3210 {
3211 WARN("Attempted to create a NPOT volume texture (%u, %u, %u) without GL support.\n",
3212 desc->width, desc->height, desc->depth);
3214 }
3215 }
3216 }
3217
3218 if (FAILED(hr = wined3d_texture_init(texture, &texture3d_ops, 1, level_count, desc,
3219 flags, device, parent, parent_ops, &texture_resource_ops)))
3220 {
3221 WARN("Failed to initialize texture, returning %#x.\n", hr);
3222 return hr;
3223 }
3224
3225 texture->pow2_matrix[0] = 1.0f;
3226 texture->pow2_matrix[5] = 1.0f;
3227 texture->pow2_matrix[10] = 1.0f;
3228 texture->pow2_matrix[15] = 1.0f;
3229 texture->target = GL_TEXTURE_3D;
3230
3231 if (wined3d_texture_use_pbo(texture, gl_info))
3232 {
3234 texture->resource.map_binding = WINED3D_LOCATION_BUFFER;
3235 }
3236
3237 /* Generate all the sub resources. */
3238 for (i = 0; i < texture->level_count; ++i)
3239 {
3240 struct wined3d_texture_sub_resource *sub_resource;
3241
3242 sub_resource = &texture->sub_resources[i];
3243 sub_resource->locations = WINED3D_LOCATION_DISCARDED;
3244
3245 if (FAILED(hr = device_parent->ops->volume_created(device_parent,
3246 texture, i, &sub_resource->parent, &sub_resource->parent_ops)))
3247 {
3248 WARN("Failed to create volume parent, hr %#x.\n", hr);
3249 sub_resource->parent = NULL;
3251 return hr;
3252 }
3253
3254 TRACE("parent %p, parent_ops %p.\n", parent, parent_ops);
3255
3256 TRACE("Created volume level %u.\n", i);
3257 }
3258
3259 return WINED3D_OK;
3260}
static const struct wined3d_texture_ops texture3d_ops
Definition: texture.c:3156
@ EXT_TEXTURE3D
Definition: wined3d_gl.h:171

◆ WINE_DECLARE_DEBUG_CHANNEL() [1/2]

WINE_DECLARE_DEBUG_CHANNEL ( d3d_perf  )

◆ WINE_DECLARE_DEBUG_CHANNEL() [2/2]

WINE_DECLARE_DEBUG_CHANNEL ( winediag  )

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( d3d  )

◆ wined3d_resource_access_from_location()

static DWORD wined3d_resource_access_from_location ( DWORD  location)
static

Definition at line 79 of file texture.c.

80{
81 switch (location)
82 {
84 return 0;
85
89
97
98 default:
99 FIXME("Unhandled location %#x.\n", location);
100 return 0;
101 }
102}
#define WINED3D_LOCATION_RB_RESOLVED
#define WINED3D_LOCATION_USER_MEMORY
#define WINED3D_LOCATION_RB_MULTISAMPLE

Referenced by texture1d_load_location(), and wined3d_texture_load_location().

◆ wined3d_texture_add_dirty_region()

HRESULT CDECL wined3d_texture_add_dirty_region ( struct wined3d_texture texture,
UINT  layer,
const struct wined3d_box dirty_region 
)

Definition at line 1677 of file texture.c.

1679{
1680 TRACE("texture %p, layer %u, dirty_region %s.\n", texture, layer, debug_box(dirty_region));
1681
1682 if (layer >= texture->layer_count)
1683 {
1684 WARN("Invalid layer %u specified.\n", layer);
1686 }
1687
1688 if (dirty_region)
1689 WARN("Ignoring dirty_region %s.\n", debug_box(dirty_region));
1690
1692
1693 return WINED3D_OK;
1694}
void wined3d_cs_emit_add_dirty_texture_region(struct wined3d_cs *cs, struct wined3d_texture *texture, unsigned int layer)
Definition: cs.c:2353
GLenum GLuint GLint GLint layer
Definition: glext.h:7007

Referenced by d3d8_texture_2d_AddDirtyRect(), d3d8_texture_3d_AddDirtyBox(), d3d8_texture_cube_AddDirtyRect(), d3d9_texture_2d_AddDirtyRect(), d3d9_texture_3d_AddDirtyBox(), and d3d9_texture_cube_AddDirtyRect().

◆ wined3d_texture_allocate_gl_immutable_storage()

static void wined3d_texture_allocate_gl_immutable_storage ( struct wined3d_texture texture,
GLenum  gl_internal_format,
const struct wined3d_gl_info gl_info 
)
static

Definition at line 564 of file texture.c.

566{
570
571 switch (texture->target)
572 {
574 GL_EXTCALL(glTexStorage3D(texture->target, texture->level_count,
575 gl_internal_format, width, height, texture->layer_count));
576 break;
578 GL_EXTCALL(glTexStorage2DMultisample(texture->target, samples,
579 gl_internal_format, width, height, GL_FALSE));
580 break;
582 GL_EXTCALL(glTexStorage3DMultisample(texture->target, samples,
583 gl_internal_format, width, height, texture->layer_count, GL_FALSE));
584 break;
585 default:
586 GL_EXTCALL(glTexStorage2D(texture->target, texture->level_count,
587 gl_internal_format, width, height));
588 break;
589 }
590
591 checkGLcall("allocate immutable storage");
592}
static unsigned int wined3d_texture_get_gl_sample_count(const struct wined3d_texture *texture)
Definition: texture.c:484
#define GL_FALSE
Definition: gl.h:173
int GLsizei
Definition: gl.h:160
GLsizei samples
Definition: glext.h:7006
static unsigned int wined3d_texture_get_level_pow2_height(const struct wined3d_texture *texture, unsigned int level)
static unsigned int wined3d_texture_get_level_pow2_width(const struct wined3d_texture *texture, unsigned int level)

Referenced by texture2d_prepare_texture().

◆ wined3d_texture_allocate_gl_mutable_storage()

static void wined3d_texture_allocate_gl_mutable_storage ( struct wined3d_texture texture,
GLenum  gl_internal_format,
const struct wined3d_format format,
const struct wined3d_gl_info gl_info 
)
static

Definition at line 518 of file texture.c.

521{
522 unsigned int level, level_count, layer, layer_count;
525
526 level_count = texture->level_count;
527 layer_count = texture->target == GL_TEXTURE_2D_ARRAY ? 1 : texture->layer_count;
528
529 for (layer = 0; layer < layer_count; ++layer)
530 {
532
533 for (level = 0; level < level_count; ++level)
534 {
537 if (texture->resource.format_flags & WINED3DFMT_FLAG_HEIGHT_SCALE)
538 {
539 height *= format->height_scale.numerator;
540 height /= format->height_scale.denominator;
541 }
542
543 TRACE("texture %p, layer %u, level %u, target %#x, width %u, height %u.\n",
545
546 if (texture->target == GL_TEXTURE_2D_ARRAY)
547 {
548 GL_EXTCALL(glTexImage3D(target, level, gl_internal_format, width, height,
549 texture->layer_count, 0, format->glFormat, format->glType, NULL));
550 checkGLcall("glTexImage3D");
551 }
552 else
553 {
554 gl_info->gl_ops.gl.p_glTexImage2D(target, level, gl_internal_format,
555 width, height, 0, format->glFormat, format->glType, NULL);
556 checkGLcall("glTexImage2D");
557 }
558 }
559 }
560}

Referenced by texture2d_prepare_texture().

◆ wined3d_texture_apply_sampler_desc()

void wined3d_texture_apply_sampler_desc ( struct wined3d_texture texture,
const struct wined3d_sampler_desc sampler_desc,
const struct wined3d_context context 
)

Definition at line 896 of file texture.c.

898{
899 const struct wined3d_gl_info *gl_info = context->gl_info;
900 GLenum target = texture->target;
901 struct gl_texture *gl_tex;
902 DWORD state;
903
904 TRACE("texture %p, sampler_desc %p, context %p.\n", texture, sampler_desc, context);
905
907
908 state = sampler_desc->address_u;
909 if (state != gl_tex->sampler_desc.address_u)
910 {
911 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_S,
913 gl_tex->sampler_desc.address_u = state;
914 }
915
916 state = sampler_desc->address_v;
917 if (state != gl_tex->sampler_desc.address_v)
918 {
919 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_T,
921 gl_tex->sampler_desc.address_v = state;
922 }
923
924 state = sampler_desc->address_w;
925 if (state != gl_tex->sampler_desc.address_w)
926 {
927 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_R,
929 gl_tex->sampler_desc.address_w = state;
930 }
931
932 if (memcmp(gl_tex->sampler_desc.border_color, sampler_desc->border_color,
933 sizeof(gl_tex->sampler_desc.border_color)))
934 {
935 gl_info->gl_ops.gl.p_glTexParameterfv(target, GL_TEXTURE_BORDER_COLOR, &sampler_desc->border_color[0]);
936 memcpy(gl_tex->sampler_desc.border_color, sampler_desc->border_color,
937 sizeof(gl_tex->sampler_desc.border_color));
938 }
939
940 state = sampler_desc->mag_filter;
941 if (state != gl_tex->sampler_desc.mag_filter)
942 {
943 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MAG_FILTER, wined3d_gl_mag_filter(state));
944 gl_tex->sampler_desc.mag_filter = state;
945 }
946
947 if (sampler_desc->min_filter != gl_tex->sampler_desc.min_filter
948 || sampler_desc->mip_filter != gl_tex->sampler_desc.mip_filter)
949 {
950 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MIN_FILTER,
951 wined3d_gl_min_mip_filter(sampler_desc->min_filter, sampler_desc->mip_filter));
952 gl_tex->sampler_desc.min_filter = sampler_desc->min_filter;
953 gl_tex->sampler_desc.mip_filter = sampler_desc->mip_filter;
954 }
955
956 state = sampler_desc->max_anisotropy;
957 if (state != gl_tex->sampler_desc.max_anisotropy)
958 {
960 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MAX_ANISOTROPY, state);
961 else
962 WARN("Anisotropic filtering not supported.\n");
963 gl_tex->sampler_desc.max_anisotropy = state;
964 }
965
966 if (!sampler_desc->srgb_decode != !gl_tex->sampler_desc.srgb_decode
967 && (context->d3d_info->wined3d_creation_flags & WINED3D_SRGB_READ_WRITE_CONTROL)
969 {
970 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_SRGB_DECODE_EXT,
972 gl_tex->sampler_desc.srgb_decode = sampler_desc->srgb_decode;
973 }
974
975 if (!sampler_desc->compare != !gl_tex->sampler_desc.compare)
976 {
977 if (sampler_desc->compare)
979 else
980 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE);
981 gl_tex->sampler_desc.compare = sampler_desc->compare;
982 }
983
984 checkGLcall("Texture parameter application");
985
986 if (gl_info->supported[EXT_TEXTURE_LOD_BIAS])
987 {
988 gl_info->gl_ops.gl.p_glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT,
990 checkGLcall("glTexEnvf(GL_TEXTURE_LOD_BIAS_EXT, ...)");
991 }
992}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
static int state
Definition: maze.c:121
#define GL_NONE
Definition: gl.h:465
#define GL_TEXTURE_MIN_FILTER
Definition: gl.h:649
#define GL_TEXTURE_BORDER_COLOR
Definition: gl.h:656
#define GL_TEXTURE_WRAP_R
Definition: gl.h:1518
#define GL_TEXTURE_WRAP_S
Definition: gl.h:646
#define GL_TEXTURE_WRAP_T
Definition: gl.h:647
#define GL_TEXTURE_MAG_FILTER
Definition: gl.h:648
#define GL_SKIP_DECODE_EXT
Definition: glext.h:5291
#define GL_DECODE_EXT
Definition: glext.h:5290
#define GL_TEXTURE_SRGB_DECODE_EXT
Definition: glext.h:5289
#define GL_TEXTURE_COMPARE_MODE_ARB
Definition: glext.h:1371
#define GL_TEXTURE_LOD_BIAS_EXT
Definition: glext.h:3362
#define GL_COMPARE_R_TO_TEXTURE_ARB
Definition: glext.h:1373
#define GL_TEXTURE_FILTER_CONTROL_EXT
Definition: glext.h:3361
struct wined3d_sampler_desc sampler_desc
GLint wrap_lookup[WINED3D_TADDRESS_MIRROR_ONCE - WINED3D_TADDRESS_WRAP+1]
#define GL_TEXTURE_MAX_ANISOTROPY
Definition: wgl.h:4357
@ WINED3D_TADDRESS_WRAP
Definition: wined3d.h:639
#define WINED3D_SRGB_READ_WRITE_CONTROL
Definition: wined3d.h:1324
@ ARB_TEXTURE_FILTER_ANISOTROPIC
Definition: wined3d_gl.h:117
@ EXT_TEXTURE_SRGB_DECODE
Definition: wined3d_gl.h:183
@ EXT_TEXTURE_LOD_BIAS
Definition: wined3d_gl.h:178
static GLenum wined3d_gl_mag_filter(enum wined3d_texture_filter_type mag_filter)
static GLenum wined3d_gl_min_mip_filter(enum wined3d_texture_filter_type min_filter, enum wined3d_texture_filter_type mip_filter)
static struct gl_texture * wined3d_texture_get_gl_texture(struct wined3d_texture *texture, BOOL srgb)

Referenced by wined3d_sampler_bind().

◆ wined3d_texture_bind()

void wined3d_texture_bind ( struct wined3d_texture texture,
struct wined3d_context context,
BOOL  srgb 
)

Definition at line 729 of file texture.c.

731{
732 const struct wined3d_gl_info *gl_info = context->gl_info;
733 const struct wined3d_format *format = texture->resource.format;
734 const struct color_fixup_desc fixup = format->color_fixup;
735 struct gl_texture *gl_tex;
737
738 TRACE("texture %p, context %p, srgb %#x.\n", texture, context, srgb);
739
741 srgb = FALSE;
742
743 /* sRGB mode cache for preload() calls outside drawprim. */
744 if (srgb)
746 else
747 texture->flags &= ~WINED3D_TEXTURE_IS_SRGB;
748
750 target = texture->target;
751
752 if (gl_tex->name)
753 {
755 return;
756 }
757
758 gl_info->gl_ops.gl.p_glGenTextures(1, &gl_tex->name);
759 checkGLcall("glGenTextures");
760 TRACE("Generated texture %d.\n", gl_tex->name);
761
762 if (!gl_tex->name)
763 {
764 ERR("Failed to generate a texture name.\n");
765 return;
766 }
767
768 /* Initialise the state of the texture object to the OpenGL defaults, not
769 * the wined3d defaults. */
770 gl_tex->sampler_desc.address_u = WINED3D_TADDRESS_WRAP;
771 gl_tex->sampler_desc.address_v = WINED3D_TADDRESS_WRAP;
772 gl_tex->sampler_desc.address_w = WINED3D_TADDRESS_WRAP;
773 memset(gl_tex->sampler_desc.border_color, 0, sizeof(gl_tex->sampler_desc.border_color));
774 gl_tex->sampler_desc.mag_filter = WINED3D_TEXF_LINEAR;
775 gl_tex->sampler_desc.min_filter = WINED3D_TEXF_POINT; /* GL_NEAREST_MIPMAP_LINEAR */
776 gl_tex->sampler_desc.mip_filter = WINED3D_TEXF_LINEAR; /* GL_NEAREST_MIPMAP_LINEAR */
777 gl_tex->sampler_desc.lod_bias = 0.0f;
778 gl_tex->sampler_desc.min_lod = -1000.0f;
779 gl_tex->sampler_desc.max_lod = 1000.0f;
780 gl_tex->sampler_desc.max_anisotropy = 1;
781 gl_tex->sampler_desc.compare = FALSE;
782 gl_tex->sampler_desc.comparison_func = WINED3D_CMP_LESSEQUAL;
783 if (context->gl_info->supported[EXT_TEXTURE_SRGB_DECODE])
784 gl_tex->sampler_desc.srgb_decode = TRUE;
785 else
786 gl_tex->sampler_desc.srgb_decode = srgb;
787 gl_tex->base_level = 0;
789
791
792 /* For a new texture we have to set the texture levels after binding the
793 * texture. Beware that texture rectangles do not support mipmapping, but
794 * set the maxmiplevel if we're relying on the partial
795 * GL_ARB_texture_non_power_of_two emulation with texture rectangles.
796 * (I.e., do not care about cond_np2 here, just look for
797 * GL_TEXTURE_RECTANGLE_ARB.) */
799 {
800 TRACE("Setting GL_TEXTURE_MAX_LEVEL to %u.\n", texture->level_count - 1);
801 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, texture->level_count - 1);
802 checkGLcall("glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, texture->level_count)");
803 }
804
806 {
807 /* Cubemaps are always set to clamp, regardless of the sampler state. */
808 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
809 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
810 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
811 }
812
814 {
815 /* Conditinal non power of two textures use a different clamping
816 * default. If we're using the GL_WINE_normalized_texrect partial
817 * driver emulation, we're dealing with a GL_TEXTURE_2D texture which
818 * has the address mode set to repeat - something that prevents us
819 * from hitting the accelerated codepath. Thus manually set the GL
820 * state. The same applies to filtering. Even if the texture has only
821 * one mip level, the default LINEAR_MIPMAP_LINEAR filter causes a SW
822 * fallback on macos. */
823 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
824 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
825 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
826 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
827 checkGLcall("glTexParameteri");
828 gl_tex->sampler_desc.address_u = WINED3D_TADDRESS_CLAMP;
829 gl_tex->sampler_desc.address_v = WINED3D_TADDRESS_CLAMP;
830 gl_tex->sampler_desc.mag_filter = WINED3D_TEXF_POINT;
831 gl_tex->sampler_desc.min_filter = WINED3D_TEXF_POINT;
832 gl_tex->sampler_desc.mip_filter = WINED3D_TEXF_NONE;
833 }
834
836 {
837 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY);
838 checkGLcall("glTexParameteri(GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY)");
839 }
840
841 if (!is_identity_fixup(fixup) && can_use_texture_swizzle(gl_info, format))
842 {
843 static const GLenum swizzle_source[] =
844 {
845 GL_ZERO, /* CHANNEL_SOURCE_ZERO */
846 GL_ONE, /* CHANNEL_SOURCE_ONE */
847 GL_RED, /* CHANNEL_SOURCE_X */
848 GL_GREEN, /* CHANNEL_SOURCE_Y */
849 GL_BLUE, /* CHANNEL_SOURCE_Z */
850 GL_ALPHA, /* CHANNEL_SOURCE_W */
851 };
852 struct
853 {
854 GLint x, y, z, w;
855 }
856 swizzle;
857
858 swizzle.x = swizzle_source[fixup.x_source];
859 swizzle.y = swizzle_source[fixup.y_source];
860 swizzle.z = swizzle_source[fixup.z_source];
861 swizzle.w = swizzle_source[fixup.w_source];
862 gl_info->gl_ops.gl.p_glTexParameteriv(target, GL_TEXTURE_SWIZZLE_RGBA, &swizzle.x);
863 checkGLcall("glTexParameteriv(GL_TEXTURE_SWIZZLE_RGBA)");
864 }
865}
void context_bind_texture(struct wined3d_context *context, GLenum target, GLuint name)
Definition: context.c:2734
static void wined3d_texture_set_dirty(struct wined3d_texture *texture)
Definition: texture.c:154
#define GL_TEXTURE_MAX_LEVEL
Definition: gl.h:1504
#define GL_INTENSITY
Definition: gl.h:747
#define GL_BLUE
Definition: gl.h:482
#define GL_ZERO
Definition: gl.h:374
#define GL_RED
Definition: gl.h:480
#define GL_NEAREST
Definition: gl.h:678
#define GL_ONE
Definition: gl.h:375
int GLint
Definition: gl.h:156
#define GL_ALPHA
Definition: gl.h:483
#define GL_CLAMP_TO_EDGE
Definition: gl.h:1481
#define GL_GREEN
Definition: gl.h:481
#define GL_DEPTH_TEXTURE_MODE_ARB
Definition: glext.h:1367
GLuint GLenum swizzle
Definition: glext.h:9511
#define GL_TEXTURE_SWIZZLE_RGBA
Definition: glext.h:2032
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
#define memset(x, y, z)
Definition: compat.h:39
unsigned short x_source
unsigned short w_source
unsigned short y_source
unsigned short z_source
unsigned int base_level
@ WINED3D_TEXF_NONE
Definition: wined3d.h:685
@ WINED3D_TEXF_POINT
Definition: wined3d.h:686
@ WINED3D_TEXF_LINEAR
Definition: wined3d.h:687
@ WINED3D_TADDRESS_CLAMP
Definition: wined3d.h:641
@ WINED3D_CMP_LESSEQUAL
Definition: wined3d.h:455
@ ARB_DEPTH_TEXTURE
Definition: wined3d_gl.h:59
@ WINED3D_GL_LEGACY_CONTEXT
Definition: wined3d_gl.h:213
static BOOL is_identity_fixup(struct color_fixup_desc fixup)
static BOOL needs_separate_srgb_gl_texture(const struct wined3d_context *context, const struct wined3d_texture *texture)
static BOOL can_use_texture_swizzle(const struct wined3d_gl_info *gl_info, const struct wined3d_format *format)

Referenced by sampler(), wined3d_shader_resource_view_bind(), and wined3d_texture_bind_and_dirtify().

◆ wined3d_texture_bind_and_dirtify()

void wined3d_texture_bind_and_dirtify ( struct wined3d_texture texture,
struct wined3d_context context,
BOOL  srgb 
)

Definition at line 868 of file texture.c.

870{
871 /* We don't need a specific texture unit, but after binding the texture
872 * the current unit is dirty. Read the unit back instead of switching to
873 * 0, this avoids messing around with the state manager's GL states. The
874 * current texture unit should always be a valid one.
875 *
876 * To be more specific, this is tricky because we can implicitly be
877 * called from sampler() in state.c. This means we can't touch anything
878 * other than whatever happens to be the currently active texture, or we
879 * would risk marking already applied sampler states dirty again. */
880 if (context->active_texture < ARRAY_SIZE(context->rev_tex_unit_map))
881 {
882 DWORD active_sampler = context->rev_tex_unit_map[context->active_texture];
883 if (active_sampler != WINED3D_UNMAPPED_STAGE)
885 }
886 /* FIXME: Ideally we'd only do this when touching a binding that's used by
887 * a shader. */
890
892}
#define ARRAY_SIZE(A)
Definition: main.h:20
void context_invalidate_compute_state(struct wined3d_context *context, DWORD state_id)
Definition: context.c:1642
void context_invalidate_state(struct wined3d_context *context, DWORD state)
Definition: context.c:1652
void wined3d_texture_bind(struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb)
Definition: texture.c:729
#define STATE_GRAPHICS_SHADER_RESOURCE_BINDING
#define STATE_SAMPLER(num)
#define STATE_COMPUTE_SHADER_RESOURCE_BINDING
#define WINED3D_UNMAPPED_STAGE

Referenced by shader_resource_view_generate_mipmaps(), surface_convert_format(), surface_load_fb_texture(), surface_load_sysmem(), surface_load_texture(), surface_upload_from_surface(), texture1d_load_location(), texture1d_prepare_texture(), texture1d_srgb_transfer(), texture2d_prepare_texture(), texture3d_load_location(), texture3d_prepare_texture(), texture3d_srgb_transfer(), wined3d_cs_exec_blt_sub_resource(), and wined3d_cs_exec_update_sub_resource().

◆ wined3d_texture_blt()

HRESULT CDECL wined3d_texture_blt ( struct wined3d_texture dst_texture,
unsigned int  dst_sub_resource_idx,
const RECT dst_rect,
struct wined3d_texture src_texture,
unsigned int  src_sub_resource_idx,
const RECT src_rect,
DWORD  flags,
const struct wined3d_blt_fx fx,
enum wined3d_texture_filter_type  filter 
)

Definition at line 3262 of file texture.c.

3265{
3266 struct wined3d_box src_box = {src_rect->left, src_rect->top, src_rect->right, src_rect->bottom, 0, 1};
3267 struct wined3d_box dst_box = {dst_rect->left, dst_rect->top, dst_rect->right, dst_rect->bottom, 0, 1};
3268 unsigned int dst_format_flags, src_format_flags = 0;
3269 HRESULT hr;
3270
3271 TRACE("dst_texture %p, dst_sub_resource_idx %u, dst_rect %s, src_texture %p, "
3272 "src_sub_resource_idx %u, src_rect %s, flags %#x, fx %p, filter %s.\n",
3273 dst_texture, dst_sub_resource_idx, wine_dbgstr_rect(dst_rect), src_texture,
3274 src_sub_resource_idx, wine_dbgstr_rect(src_rect), flags, fx, debug_d3dtexturefiltertype(filter));
3275
3276 if (dst_sub_resource_idx >= dst_texture->level_count * dst_texture->layer_count
3277 || dst_texture->resource.type != WINED3D_RTYPE_TEXTURE_2D)
3279
3280 if (src_sub_resource_idx >= src_texture->level_count * src_texture->layer_count
3281 || src_texture->resource.type != WINED3D_RTYPE_TEXTURE_2D)
3283
3284 dst_format_flags = dst_texture->resource.format_flags;
3286 dst_sub_resource_idx % dst_texture->level_count, &dst_box)))
3287 return hr;
3288
3289 src_format_flags = src_texture->resource.format_flags;
3291 src_sub_resource_idx % src_texture->level_count, &src_box)))
3292 return hr;
3293
3294 if (dst_texture->sub_resources[dst_sub_resource_idx].map_count
3295 || src_texture->sub_resources[src_sub_resource_idx].map_count)
3296 {
3297#if !defined(STAGING_CSMT)
3298 WARN("Sub-resource is busy, returning WINEDDERR_SURFACEBUSY.\n");
3299 return WINEDDERR_SURFACEBUSY;
3300#else /* STAGING_CSMT */
3301 struct wined3d_device *device = dst_texture->resource.device;
3302 device->cs->ops->finish(device->cs, WINED3D_CS_QUEUE_DEFAULT);
3303 if (dst_texture->sub_resources[dst_sub_resource_idx].map_count
3304 || (src_texture && src_texture->sub_resources[src_sub_resource_idx].map_count))
3305 {
3306 WARN("Sub-resource is busy, returning WINEDDERR_SURFACEBUSY.\n");
3307 return WINEDDERR_SURFACEBUSY;
3308 }
3309#endif /* STAGING_CSMT */
3310 }
3311
3312 if ((src_format_flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL))
3313 != (dst_format_flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL)))
3314 {
3315 WARN("Rejecting depth/stencil blit between incompatible formats.\n");
3317 }
3318
3319 wined3d_cs_emit_blt_sub_resource(dst_texture->resource.device->cs, &dst_texture->resource, dst_sub_resource_idx,
3320 &dst_box, &src_texture->resource, src_sub_resource_idx, &src_box, flags, fx, filter);
3321
3322 return WINED3D_OK;
3323}
void wined3d_cs_emit_blt_sub_resource(struct wined3d_cs *cs, struct wined3d_resource *dst_resource, unsigned int dst_sub_resource_idx, const struct wined3d_box *dst_box, struct wined3d_resource *src_resource, unsigned int src_sub_resource_idx, const struct wined3d_box *src_box, DWORD flags, const struct wined3d_blt_fx *fx, enum wined3d_texture_filter_type filter)
Definition: cs.c:2172
const char * debug_d3dtexturefiltertype(enum wined3d_texture_filter_type filter_type)
Definition: utils.c:4539
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glext.h:7005
struct wined3d_resource resource
struct wined3d_texture::wined3d_texture_sub_resource sub_resources[1]
GLfixed fx
Definition: tritemp.h:484
#define WINEDDERR_SURFACEBUSY
Definition: wined3d.h:51
#define WINED3DFMT_FLAG_STENCIL
#define WINED3DFMT_FLAG_DEPTH

Referenced by copy_mipmap_chain(), d3d8_device_CopyRects(), d3d9_device_GetRenderTargetData(), d3d9_device_StretchRect(), d3d_texture2_Load(), ddraw_surface7_BltFast(), ddraw_surface_blt(), ddraw_surface_update_frontbuffer(), swapchain_gl_present(), wined3d_device_resolve_sub_resource(), and wined3d_swapchain_get_front_buffer_data().

◆ wined3d_texture_check_box_dimensions()

HRESULT wined3d_texture_check_box_dimensions ( const struct wined3d_texture texture,
unsigned int  level,
const struct wined3d_box box 
)

Definition at line 1128 of file texture.c.

1130{
1131 const struct wined3d_format *format = texture->resource.format;
1132 unsigned int width_mask, height_mask, width, height, depth;
1133
1137
1138 if (box->left >= box->right || box->right > width
1139 || box->top >= box->bottom || box->bottom > height
1140 || box->front >= box->back || box->back > depth)
1141 {
1142 WARN("Box %s is invalid.\n", debug_box(box));
1143 return WINEDDERR_INVALIDRECT;
1144 }
1145
1146 if (texture->resource.format_flags & WINED3DFMT_FLAG_BLOCKS)
1147 {
1148 /* This assumes power of two block sizes, but NPOT block sizes would
1149 * be silly anyway.
1150 *
1151 * This also assumes that the format's block depth is 1. */
1152 width_mask = format->block_width - 1;
1153 height_mask = format->block_height - 1;
1154
1155 if ((box->left & width_mask) || (box->top & height_mask)
1156 || (box->right & width_mask && box->right != width)
1157 || (box->bottom & height_mask && box->bottom != height))
1158 {
1159 WARN("Box %s is misaligned for %ux%u blocks.\n",
1160 debug_box(box), format->block_width, format->block_height);
1162 }
1163 }
1164
1165 return WINED3D_OK;
1166}
#define WINEDDERR_INVALIDRECT
Definition: wined3d.h:52

Referenced by texture_resource_sub_resource_map(), wined3d_device_clear_rendertarget_view(), wined3d_device_copy_sub_resource_region(), and wined3d_texture_blt().

◆ wined3d_texture_cleanup()

static void wined3d_texture_cleanup ( struct wined3d_texture texture)
static

Definition at line 654 of file texture.c.

655{
656 unsigned int sub_count = texture->level_count * texture->layer_count;
657 struct wined3d_device *device = texture->resource.device;
658 struct wined3d_context *context = NULL;
659#if !defined(STAGING_CSMT)
660 const struct wined3d_gl_info *gl_info;
661 GLuint buffer_object;
662#else /* STAGING_CSMT */
663 struct wined3d_gl_bo *buffer;
664#endif /* STAGING_CSMT */
665 unsigned int i;
666
667 TRACE("texture %p.\n", texture);
668
669 for (i = 0; i < sub_count; ++i)
670 {
671#if !defined(STAGING_CSMT)
672 if (!(buffer_object = texture->sub_resources[i].buffer_object))
673 continue;
674
675 TRACE("Deleting buffer object %u.\n", buffer_object);
676#else /* STAGING_CSMT */
677 if (!(buffer = texture->sub_resources[i].buffer))
678 continue;
679
680 TRACE("Deleting buffer object %u.\n", buffer->name);
681#endif /* STAGING_CSMT */
682
683 /* We may not be able to get a context in wined3d_texture_cleanup() in
684 * general, but if a buffer object was previously created we can. */
685 if (!context)
686#if !defined(STAGING_CSMT)
687 {
689 gl_info = context->gl_info;
690 }
691
692 GL_EXTCALL(glDeleteBuffers(1, &buffer_object));
693#else /* STAGING_CSMT */
695
696 wined3d_device_release_bo(device, buffer, context);
697 texture->sub_resources[i].buffer = NULL;
698#endif /* STAGING_CSMT */
699 }
700 if (context)
702
703 texture->texture_ops->texture_cleanup_sub_resources(texture);
704 if (texture->overlay_info)
705 {
706 for (i = 0; i < sub_count; ++i)
707 {
708 struct wined3d_overlay_info *info = &texture->overlay_info[i];
709 struct wined3d_overlay_info *overlay, *cur;
710
711 list_remove(&info->entry);
712 LIST_FOR_EACH_ENTRY_SAFE(overlay, cur, &info->overlays, struct wined3d_overlay_info, entry)
713 {
714 list_remove(&overlay->entry);
715 }
716 }
717 heap_free(texture->overlay_info);
718 }
720}
static void list_remove(struct list_entry *entry)
Definition: list.h:90
static void wined3d_texture_unload_gl_texture(struct wined3d_texture *texture)
Definition: texture.c:594
FxCollectionEntry * cur
unsigned int GLuint
Definition: gl.h:159
GLuint buffer
Definition: glext.h:5915

Referenced by wined3d_texture_cleanup_sync(), and wined3d_texture_destroy_object().

◆ wined3d_texture_cleanup_sync()

static void wined3d_texture_cleanup_sync ( struct wined3d_texture texture)
static

Definition at line 1009 of file texture.c.

1010{
1012 resource_cleanup(&texture->resource);
1015}
void resource_cleanup(struct wined3d_resource *resource)
Definition: resource.c:237
static void wined3d_texture_cleanup(struct wined3d_texture *texture)
Definition: texture.c:654
static void wined3d_texture_sub_resources_destroyed(struct wined3d_texture *texture)
Definition: texture.c:636
static void wined3d_resource_wait_idle(struct wined3d_resource *resource)

Referenced by texture1d_init(), texture_init(), volumetexture_init(), and wined3d_texture_create().

◆ wined3d_texture_copy_sysmem_location()

static BOOL wined3d_texture_copy_sysmem_location ( struct wined3d_texture texture,
unsigned int  sub_resource_idx,
struct wined3d_context context,
DWORD  location 
)
static

Definition at line 184 of file texture.c.

186{
187 unsigned int size = texture->sub_resources[sub_resource_idx].size;
188 struct wined3d_device *device = texture->resource.device;
189 const struct wined3d_gl_info *gl_info;
190 struct wined3d_bo_address dst, src;
191
193 return FALSE;
194
195 wined3d_texture_get_memory(texture, sub_resource_idx, &dst, location);
196 wined3d_texture_get_memory(texture, sub_resource_idx, &src,
197 texture->sub_resources[sub_resource_idx].locations);
198
199 if (dst.buffer_object)
200 {
202 gl_info = context->gl_info;
203 GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, dst.buffer_object));
204 GL_EXTCALL(glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, size, src.addr));
205 GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));
206 checkGLcall("PBO upload");
208 return TRUE;
209 }
210
211 if (src.buffer_object)
212 {
214 gl_info = context->gl_info;
215 GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, src.buffer_object));
216 GL_EXTCALL(glGetBufferSubData(GL_PIXEL_PACK_BUFFER, 0, size, dst.addr));
217 GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, 0));
218 checkGLcall("PBO download");
220 return TRUE;
221 }
222
223 memcpy(dst.addr, src.addr, size);
224 return TRUE;
225}
GLsizeiptr size
Definition: glext.h:5919
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340

Referenced by wined3d_texture_load_location().

◆ wined3d_texture_create()

HRESULT CDECL wined3d_texture_create ( struct wined3d_device device,
const struct wined3d_resource_desc desc,
UINT  layer_count,
UINT  level_count,
DWORD  flags,
const struct wined3d_sub_resource_data data,
void parent,
const struct wined3d_parent_ops parent_ops,
struct wined3d_texture **  texture 
)

Definition at line 3511 of file texture.c.

3514{
3515 struct wined3d_texture *object;
3516 HRESULT hr;
3517
3518 TRACE("device %p, desc %p, layer_count %u, level_count %u, flags %#x, data %p, "
3519 "parent %p, parent_ops %p, texture %p.\n",
3521
3522 if (!layer_count)
3523 {
3524 WARN("Invalid layer count.\n");
3525 return E_INVALIDARG;
3526 }
3527 if ((desc->usage & WINED3DUSAGE_LEGACY_CUBEMAP) && layer_count != 6)
3528 {
3529 ERR("Invalid layer count %u for legacy cubemap.\n", layer_count);
3530 layer_count = 6;
3531 }
3532
3533 if (!level_count)
3534 {
3535 WARN("Invalid level count.\n");
3537 }
3538
3539 if (desc->multisample_type != WINED3D_MULTISAMPLE_NONE)
3540 {
3541 const struct wined3d_format *format = wined3d_get_format(&device->adapter->gl_info,
3542 desc->format, desc->usage);
3543
3544 if (desc->multisample_type == WINED3D_MULTISAMPLE_NON_MASKABLE
3545 && desc->multisample_quality >= wined3d_popcount(format->multisample_types))
3546 {
3547 WARN("Unsupported quality level %u requested for WINED3D_MULTISAMPLE_NON_MASKABLE.\n",
3548 desc->multisample_quality);
3550 }
3551 if (desc->multisample_type != WINED3D_MULTISAMPLE_NON_MASKABLE
3552 && (!(format->multisample_types & 1u << (desc->multisample_type - 1))
3553 || desc->multisample_quality))
3554 {
3555 WARN("Unsupported multisample type %u quality %u requested.\n", desc->multisample_type,
3556 desc->multisample_quality);
3558 }
3559 }
3560
3561 if (!(object = heap_alloc_zero(FIELD_OFFSET(struct wined3d_texture,
3562 sub_resources[level_count * layer_count]))))
3563 return E_OUTOFMEMORY;
3564
3565 switch (desc->resource_type)
3566 {
3568 hr = texture1d_init(object, desc, layer_count, level_count, device, parent, parent_ops);
3569 break;
3570
3572 hr = texture_init(object, desc, layer_count, level_count, flags, device, parent, parent_ops);
3573 break;
3574
3576 hr = volumetexture_init(object, desc, layer_count, level_count, flags, device, parent, parent_ops);
3577 break;
3578
3579 default:
3580 ERR("Invalid resource type %s.\n", debug_d3dresourcetype(desc->resource_type));
3582 break;
3583 }
3584
3585 if (FAILED(hr))
3586 {
3587 WARN("Failed to initialize texture, returning %#x.\n", hr);
3588 heap_free(object);
3589 return hr;
3590 }
3591
3592 /* FIXME: We'd like to avoid ever allocating system memory for the texture
3593 * in this case. */
3594 if (data)
3595 {
3596 unsigned int sub_count = level_count * layer_count;
3597 unsigned int i;
3598
3599 for (i = 0; i < sub_count; ++i)
3600 {
3601 if (!data[i].data)
3602 {
3603 WARN("Invalid sub-resource data specified for sub-resource %u.\n", i);
3605 heap_free(object);
3606 return E_INVALIDARG;
3607 }
3608 }
3609
3610 for (i = 0; i < sub_count; ++i)
3611 {
3613 i, NULL, data[i].data, data[i].row_pitch, data[i].slice_pitch);
3614 }
3615 }
3616
3617 TRACE("Created texture %p.\n", object);
3618 *texture = object;
3619
3620 return WINED3D_OK;
3621}
void CDECL wined3d_device_update_sub_resource(struct wined3d_device *device, struct wined3d_resource *resource, unsigned int sub_resource_idx, const struct wined3d_box *box, const void *data, unsigned int row_pitch, unsigned int depth_pitch)
Definition: device.c:4281
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)
Definition: texture.c:2641
static HRESULT volumetexture_init(struct wined3d_texture *texture, const struct wined3d_resource_desc *desc, UINT layer_count, UINT level_count, DWORD flags, struct wined3d_device *device, void *parent, const struct wined3d_parent_ops *parent_ops)
Definition: texture.c:3164
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)
Definition: texture.c:2518
const char * debug_d3dresourcetype(enum wined3d_resource_type resource_type)
Definition: utils.c:4329
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
@ WINED3D_MULTISAMPLE_NON_MASKABLE
Definition: wined3d.h:555
@ WINED3D_MULTISAMPLE_NONE
Definition: wined3d.h:554
@ WINED3D_RTYPE_TEXTURE_1D
Definition: wined3d.h:699
@ WINED3D_RTYPE_TEXTURE_3D
Definition: wined3d.h:701
static unsigned int wined3d_popcount(unsigned int x)

Referenced by cubetexture_init(), d3d8_device_create_surface(), d3d9_device_create_surface(), ddraw_surface_create(), device_load_logo(), device_parent_create_swapchain_texture(), surface_convert_format(), texture_init(), volumetexture_init(), and wined3d_device_create_cursor_texture().

◆ wined3d_texture_decref()

ULONG CDECL wined3d_texture_decref ( struct wined3d_texture texture)

Definition at line 1023 of file texture.c.

1024{
1025 ULONG refcount;
1026
1027 TRACE("texture %p, swapchain %p.\n", texture, texture->swapchain);
1028
1029 if (texture->swapchain)
1030 return wined3d_swapchain_decref(texture->swapchain);
1031
1032 refcount = InterlockedDecrement(&texture->resource.ref);
1033 TRACE("%p decreasing refcount to %u.\n", texture, refcount);
1034
1035 if (!refcount)
1036 {
1037 /* Wait for the texture to become idle if it's using user memory,
1038 * since the application is allowed to free that memory once the
1039 * texture is destroyed. Note that this implies that
1040 * wined3d_texture_destroy_object() can't access that memory either. */
1041 if (texture->user_memory)
1044 texture->resource.parent_ops->wined3d_object_destroyed(texture->resource.parent);
1045 resource_cleanup(&texture->resource);
1047 }
1048
1049 return refcount;
1050}
#define InterlockedDecrement
Definition: armddk.h:52
void wined3d_cs_destroy_object(struct wined3d_cs *cs, void(*callback)(void *object), void *object)
Definition: cs.c:1885
static void wined3d_texture_destroy_object(void *object)
Definition: texture.c:1017
uint32_t ULONG
Definition: typedefs.h:59
ULONG CDECL wined3d_swapchain_decref(struct wined3d_swapchain *swapchain)
Definition: swapchain.c:113

Referenced by d3d8_device_create_surface(), d3d8_surface_Release(), d3d8_texture_2d_Release(), d3d8_texture_3d_Release(), d3d8_texture_cube_Release(), d3d9_device_create_surface(), d3d9_surface_Release(), d3d9_texture_cleanup(), ddraw_surface_cleanup(), ddraw_surface_create(), device_load_logo(), state_unbind_resources(), surface_cpu_blt(), swapchain_cleanup(), swapchain_init(), texture_resource_decref(), wined3d_device_reset(), wined3d_device_set_cursor_properties(), wined3d_device_set_texture(), wined3d_device_uninit_3d(), and wined3d_stateblock_capture().

◆ wined3d_texture_destroy_object()

static void wined3d_texture_destroy_object ( void object)
static

Definition at line 1017 of file texture.c.

1018{
1020 heap_free(object);
1021}

Referenced by wined3d_texture_decref().

◆ wined3d_texture_evict_sysmem()

static void wined3d_texture_evict_sysmem ( struct wined3d_texture texture)
static

Definition at line 109 of file texture.c.

110{
111 struct wined3d_texture_sub_resource *sub_resource;
112 unsigned int i, sub_count;
113
116 {
117 TRACE("Not evicting system memory for texture %p.\n", texture);
118 return;
119 }
120
121 TRACE("Evicting system memory for texture %p.\n", texture);
122
123 sub_count = texture->level_count * texture->layer_count;
124 for (i = 0; i < sub_count; ++i)
125 {
126 sub_resource = &texture->sub_resources[i];
127 if (sub_resource->locations == WINED3D_LOCATION_SYSMEM)
128 ERR("WINED3D_LOCATION_SYSMEM is the only location for sub-resource %u of texture %p.\n",
129 i, texture);
130 sub_resource->locations &= ~WINED3D_LOCATION_SYSMEM;
131 }
133}
#define WINED3D_TEXTURE_DYNAMIC_MAP_THRESHOLD
Definition: texture.c:31
#define WINED3D_TEXTURE_PIN_SYSMEM

Referenced by wined3d_texture_validate_location().

◆ wined3d_texture_force_reload()

static void wined3d_texture_force_reload ( struct wined3d_texture texture)
static

Definition at line 1531 of file texture.c.

1532{
1533 unsigned int sub_count = texture->level_count * texture->layer_count;
1534 unsigned int i;
1535
1538 texture->async.flags &= ~WINED3D_TEXTURE_ASYNC_COLOR_KEY;
1539 for (i = 0; i < sub_count; ++i)
1540 {
1543 }
1544}
#define WINED3D_TEXTURE_RGB_ALLOCATED
#define WINED3D_TEXTURE_SRGB_ALLOCATED

Referenced by wined3d_texture_prepare_texture(), and wined3d_texture_unload().

◆ wined3d_texture_from_resource()

◆ wined3d_texture_get_dc()

HRESULT CDECL wined3d_texture_get_dc ( struct wined3d_texture texture,
unsigned int  sub_resource_idx,
HDC dc 
)

Definition at line 3623 of file texture.c.

3624{
3625 struct wined3d_device *device = texture->resource.device;
3626 struct wined3d_texture_sub_resource *sub_resource;
3627 struct wined3d_surface *surface;
3628
3629 TRACE("texture %p, sub_resource_idx %u, dc %p.\n", texture, sub_resource_idx, dc);
3630
3631 if (!(texture->flags & WINED3D_TEXTURE_GET_DC))
3632 {
3633 WARN("Texture does not support GetDC\n");
3634 /* Don't touch the DC */
3636 }
3637
3638 if (!(sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx)))
3640
3641 if (texture->resource.type != WINED3D_RTYPE_TEXTURE_2D)
3642 {
3643 WARN("Not supported on %s resources.\n", debug_d3dresourcetype(texture->resource.type));
3645 }
3646
3647 surface = sub_resource->u.surface;
3648
3649 if (texture->resource.map_count && !(texture->flags & WINED3D_TEXTURE_GET_DC_LENIENT))
3651
3652 if (!surface->dc)
3653 {
3655 device->cs->ops->finish(device->cs, WINED3D_CS_QUEUE_DEFAULT);
3656 }
3657 if (!surface->dc)
3659
3662 ++texture->resource.map_count;
3663 ++sub_resource->map_count;
3664
3665 *dc = surface->dc;
3666 TRACE("Returning dc %p.\n", *dc);
3667
3668 return WINED3D_OK;
3669}
static const WCHAR dc[]
#define WINED3D_TEXTURE_GET_DC_LENIENT
#define WINED3D_TEXTURE_GET_DC

Referenced by d3d9_surface_GetDC(), ddraw_surface7_GetDC(), ddraw_surface_update_frontbuffer(), and device_load_logo().

◆ wined3d_texture_get_gl_buffer()

GLenum wined3d_texture_get_gl_buffer ( const struct wined3d_texture texture)

Definition at line 51 of file texture.c.

52{
53 const struct wined3d_swapchain *swapchain = texture->swapchain;
54
55 TRACE("texture %p.\n", texture);
56
57 if (!swapchain)
58 {
59 ERR("Texture %p is not part of a swapchain.\n", texture);
60 return GL_NONE;
61 }
62
63 if (texture == swapchain->front_buffer)
64 {
65 TRACE("Returning GL_FRONT.\n");
66 return GL_FRONT;
67 }
68
69 if (texture == swapchain->back_buffers[0])
70 {
71 TRACE("Returning GL_BACK.\n");
72 return GL_BACK;
73 }
74
75 FIXME("Higher back buffer, returning GL_BACK.\n");
76 return GL_BACK;
77}
#define GL_BACK
Definition: gl.h:271
#define GL_FRONT
Definition: gl.h:270
struct wined3d_texture ** back_buffers
struct wined3d_texture * front_buffer

Referenced by arbfp_blitter_blit(), context_generate_rt_mask_from_resource(), fb_copy_to_texture_direct(), fb_copy_to_texture_hwstretch(), ffp_blitter_blit(), read_from_framebuffer(), surface_blt_fbo(), and surface_load_fb_texture().

◆ wined3d_texture_get_gl_sample_count()

static unsigned int wined3d_texture_get_gl_sample_count ( const struct wined3d_texture texture)
static

Definition at line 484 of file texture.c.

485{
486 const struct wined3d_format *format = texture->resource.format;
487
488 /* TODO: NVIDIA expose their Coverage Sample Anti-Aliasing (CSAA)
489 * feature through type == MULTISAMPLE_XX and quality != 0. This could
490 * be mapped to GL_NV_framebuffer_multisample_coverage.
491 *
492 * AMD have a similar feature called Enhanced Quality Anti-Aliasing
493 * (EQAA), but it does not have an equivalent OpenGL extension. */
494
495 /* We advertise as many WINED3D_MULTISAMPLE_NON_MASKABLE quality
496 * levels as the count of advertised multisample types for the texture
497 * format. */
498 if (texture->resource.multisample_type == WINED3D_MULTISAMPLE_NON_MASKABLE)
499 {
500 unsigned int i, count = 0;
501
502 for (i = 0; i < sizeof(format->multisample_types) * CHAR_BIT; ++i)
503 {
504 if (format->multisample_types & 1u << i)
505 {
506 if (texture->resource.multisample_quality == count++)
507 break;
508 }
509 }
510 return i + 1;
511 }
512
513 return texture->resource.multisample_type;
514}
#define CHAR_BIT
Definition: urlcache.c:62
GLuint GLuint GLsizei count
Definition: gl.h:1545

Referenced by wined3d_texture_allocate_gl_immutable_storage(), and wined3d_texture_prepare_rb().

◆ wined3d_texture_get_level_count()

◆ wined3d_texture_get_lod()

DWORD CDECL wined3d_texture_get_lod ( const struct wined3d_texture texture)

Definition at line 1221 of file texture.c.

1222{
1223 TRACE("texture %p, returning %u.\n", texture, texture->lod);
1224
1225 return texture->lod;
1226}

Referenced by d3d8_texture_2d_GetLOD(), d3d8_texture_3d_GetLOD(), d3d8_texture_cube_GetLOD(), d3d9_texture_2d_GetLOD(), d3d9_texture_3d_GetLOD(), d3d9_texture_cube_GetLOD(), and ddraw_surface7_GetLOD().

◆ wined3d_texture_get_memory()

void wined3d_texture_get_memory ( struct wined3d_texture texture,
unsigned int  sub_resource_idx,
struct wined3d_bo_address data,
DWORD  locations 
)

Definition at line 285 of file texture.c.

287{
288 struct wined3d_texture_sub_resource *sub_resource;
289
290 TRACE("texture %p, sub_resource_idx %u, data %p, locations %s.\n",
291 texture, sub_resource_idx, data, wined3d_debug_location(locations));
292
293 sub_resource = &texture->sub_resources[sub_resource_idx];
295 {
296 data->addr = NULL;
297#if !defined(STAGING_CSMT)
298 data->buffer_object = sub_resource->buffer_object;
299#else /* STAGING_CSMT */
300 data->buffer_object = sub_resource->buffer->name;
301#endif /* STAGING_CSMT */
302 return;
303 }
305 {
306 data->addr = texture->user_memory;
307 data->buffer_object = 0;
308 return;
309 }
311 {
312 data->addr = texture->resource.heap_memory;
313 data->addr += sub_resource->offset;
314 data->buffer_object = 0;
315 return;
316 }
317
318 ERR("Unexpected locations %s.\n", wined3d_debug_location(locations));
319 data->addr = NULL;
320 data->buffer_object = 0;
321}
GLsizei const GLint * locations
Definition: glext.h:10542
char * name
Definition: compiler.c:66

Referenced by read_from_framebuffer(), surface_convert_format(), surface_cpu_blt(), surface_cpu_blt_colour_fill(), surface_download_data(), surface_load_texture(), surface_upload_from_surface(), texture2d_create_dc(), texture2d_destroy_dc(), texture_resource_sub_resource_map(), texture_resource_sub_resource_unmap(), wined3d_cs_exec_blt_sub_resource(), and wined3d_texture_copy_sysmem_location().

◆ wined3d_texture_get_overlay_position()

HRESULT CDECL wined3d_texture_get_overlay_position ( const struct wined3d_texture texture,
unsigned int  sub_resource_idx,
LONG x,
LONG y 
)

Definition at line 3325 of file texture.c.

3327{
3328 struct wined3d_overlay_info *overlay;
3329
3330 TRACE("texture %p, sub_resource_idx %u, x %p, y %p.\n", texture, sub_resource_idx, x, y);
3331
3332 if (!(texture->resource.usage & WINED3DUSAGE_OVERLAY)
3333 || sub_resource_idx >= texture->level_count * texture->layer_count)
3334 {
3335 WARN("Invalid sub-resource specified.\n");
3337 }
3338
3339 overlay = &texture->overlay_info[sub_resource_idx];
3340 if (!overlay->dst)
3341 {
3342 TRACE("Overlay not visible.\n");
3343 *x = 0;
3344 *y = 0;
3346 }
3347
3348 *x = overlay->dst_rect.left;
3349 *y = overlay->dst_rect.top;
3350
3351 TRACE("Returning position %d, %d.\n", *x, *y);
3352
3353 return WINED3D_OK;
3354}
#define WINEDDERR_OVERLAYNOTVISIBLE
Definition: wined3d.h:53
#define WINEDDERR_NOTAOVERLAYSURFACE
Definition: wined3d.h:49

Referenced by ddraw_surface7_GetOverlayPosition().

◆ wined3d_texture_get_parent()

◆ wined3d_texture_get_pitch()

void CDECL wined3d_texture_get_pitch ( const struct wined3d_texture texture,
unsigned int  level,
unsigned int row_pitch,
unsigned int slice_pitch 
)

Definition at line 1168 of file texture.c.

1170{
1171 const struct wined3d_resource *resource = &texture->resource;
1174
1175 if (texture->row_pitch)
1176 {
1177 *row_pitch = texture->row_pitch;
1178 *slice_pitch = texture->slice_pitch;
1179 return;
1180 }
1181
1182 wined3d_format_calculate_pitch(resource->format, resource->device->surface_alignment,
1183 width, height, row_pitch, slice_pitch);
1184}
void wined3d_format_calculate_pitch(const struct wined3d_format *format, unsigned int alignment, unsigned int width, unsigned int height, unsigned int *row_pitch, unsigned int *slice_pitch)
Definition: utils.c:3876

Referenced by ddraw_surface_init(), read_from_framebuffer(), surface_convert_format(), surface_cpu_blt(), surface_cpu_blt_colour_fill(), surface_download_data(), surface_load_texture(), surface_upload_from_surface(), texture1d_load_location(), texture1d_srgb_transfer(), texture2d_create_dc(), texture3d_load_location(), texture3d_srgb_transfer(), texture3d_upload_data(), texture_resource_sub_resource_map(), texture_resource_sub_resource_map_info(), and wined3d_cs_exec_blt_sub_resource().

◆ wined3d_texture_get_resource()

◆ wined3d_texture_get_sub_resource()

static struct wined3d_texture_sub_resource * wined3d_texture_get_sub_resource ( struct wined3d_texture texture,
unsigned int  sub_resource_idx 
)
static

Definition at line 1661 of file texture.c.

1663{
1664 UINT sub_count = texture->level_count * texture->layer_count;
1665
1666 TRACE("texture %p, sub_resource_idx %u.\n", texture, sub_resource_idx);
1667
1668 if (sub_resource_idx >= sub_count)
1669 {
1670 WARN("sub_resource_idx %u >= sub_count %u.\n", sub_resource_idx, sub_count);
1671 return NULL;
1672 }
1673
1674 return &texture->sub_resources[sub_resource_idx];
1675}

Referenced by texture_resource_sub_resource_map(), texture_resource_sub_resource_map_info(), texture_resource_sub_resource_unmap(), wined3d_texture_get_dc(), wined3d_texture_release_dc(), and wined3d_texture_update_overlay().

◆ wined3d_texture_get_sub_resource_desc()

HRESULT CDECL wined3d_texture_get_sub_resource_desc ( const struct wined3d_texture texture,
unsigned int  sub_resource_idx,
struct wined3d_sub_resource_desc desc 
)

Definition at line 3480 of file texture.c.

3482{
3483 unsigned int sub_count = texture->level_count * texture->layer_count;
3484 const struct wined3d_resource *resource;
3485 unsigned int level_idx;
3486
3487 TRACE("texture %p, sub_resource_idx %u, desc %p.\n", texture, sub_resource_idx, desc);
3488
3489 if (sub_resource_idx >= sub_count)
3490 {
3491 WARN("sub_resource_idx %u >= sub_count %u.\n", sub_resource_idx, sub_count);
3493 }
3494
3495 resource = &texture->resource;
3496 desc->format = resource->format->id;
3497 desc->multisample_type = resource->multisample_type;
3498 desc->multisample_quality = resource->multisample_quality;
3499 desc->usage = resource->usage;
3500 desc->access = resource->access;
3501
3502 level_idx = sub_resource_idx % texture->level_count;
3503 desc->width = wined3d_texture_get_level_width(texture, level_idx);
3504 desc->height = wined3d_texture_get_level_height(texture, level_idx);
3505 desc->depth = wined3d_texture_get_level_depth(texture, level_idx);
3506 desc->size = texture->sub_resources[sub_resource_idx].size;
3507
3508 return WINED3D_OK;
3509}
#define resource
Definition: kernel32.h:9

Referenced by d3d8_device_CopyRects(), d3d8_device_SetRenderTarget(), d3d8_surface_GetDesc(), d3d8_texture_2d_GetLevelDesc(), d3d8_texture_3d_GetLevelDesc(), d3d8_texture_cube_GetLevelDesc(), d3d8_volume_GetDesc(), d3d9_device_ColorFill(), d3d9_device_GetRenderTargetData(), d3d9_device_StretchRect(), d3d9_device_UpdateSurface(), d3d9_surface_GetDesc(), d3d9_texture_2d_GetLevelDesc(), d3d9_texture_3d_GetLevelDesc(), d3d9_texture_acquire_shader_resource_view(), d3d9_texture_cube_GetLevelDesc(), d3d9_volume_GetDesc(), ddraw_surface7_Restore(), and ddraw_surface_create().

◆ wined3d_texture_get_sub_resource_parent()

◆ wined3d_texture_incref()

ULONG CDECL wined3d_texture_incref ( struct wined3d_texture texture)

Definition at line 994 of file texture.c.

995{
996 ULONG refcount;
997
998 TRACE("texture %p, swapchain %p.\n", texture, texture->swapchain);
999
1000 if (texture->swapchain)
1001 return wined3d_swapchain_incref(texture->swapchain);
1002
1003 refcount = InterlockedIncrement(&texture->resource.ref);
1004 TRACE("%p increasing refcount to %u.\n", texture, refcount);
1005
1006 return refcount;
1007}
#define InterlockedIncrement
Definition: armddk.h:53
ULONG CDECL wined3d_swapchain_incref(struct wined3d_swapchain *swapchain)
Definition: swapchain.c:104

Referenced by d3d8_surface_AddRef(), d3d8_texture_2d_AddRef(), d3d8_texture_3d_AddRef(), d3d8_texture_cube_AddRef(), d3d9_surface_AddRef(), d3d9_texture_2d_AddRef(), d3d9_texture_3d_AddRef(), d3d9_texture_cube_AddRef(), ddraw_surface_add_iface(), ddraw_surface_init(), texture_resource_incref(), wined3d_device_set_texture(), and wined3d_stateblock_capture().

◆ wined3d_texture_init()

static HRESULT wined3d_texture_init ( struct wined3d_texture texture,
const struct wined3d_texture_ops texture_ops,
UINT  layer_count,
UINT  level_count,
const struct wined3d_resource_desc desc,
DWORD  flags,
struct wined3d_device device,
void parent,
const struct wined3d_parent_ops parent_ops,
const struct wined3d_resource_ops resource_ops 
)
static

Definition at line 323 of file texture.c.

327{
328 unsigned int i, j, size, offset = 0;
329 const struct wined3d_format *format;
330 HRESULT hr;
331
332 TRACE("texture %p, texture_ops %p, layer_count %u, level_count %u, resource_type %s, format %s, "
333 "multisample_type %#x, multisample_quality %#x, usage %s, access %s, width %u, height %u, depth %u, "
334 "flags %#x, device %p, parent %p, parent_ops %p, resource_ops %p.\n",
335 texture, texture_ops, layer_count, level_count, debug_d3dresourcetype(desc->resource_type),
336 debug_d3dformat(desc->format), desc->multisample_type, desc->multisample_quality,
338 desc->width, desc->height, desc->depth, flags, device, parent, parent_ops, resource_ops);
339
340 if (!desc->width || !desc->height || !desc->depth)
342
343 format = wined3d_get_format(&device->adapter->gl_info, desc->format, desc->usage);
344
345 for (i = 0; i < layer_count; ++i)
346 {
347 for (j = 0; j < level_count; ++j)
348 {
349 unsigned int idx = i * level_count + j;
350
351 size = wined3d_format_calculate_size(format, device->surface_alignment,
352 max(1, desc->width >> j), max(1, desc->height >> j), max(1, desc->depth >> j));
353 texture->sub_resources[idx].offset = offset;
354 texture->sub_resources[idx].size = size;
355 offset += size;
356 }
358 }
359
360 if (!offset)
362
363 if (FAILED(hr = resource_init(&texture->resource, device, desc->resource_type, format,
364 desc->multisample_type, desc->multisample_quality, desc->usage, desc->access,
365 desc->width, desc->height, desc->depth, offset, parent, parent_ops, resource_ops)))
366 {
367 static unsigned int once;
368
369 /* DXTn 3D textures are not supported. Do not write the ERR for them. */
370 if ((desc->format == WINED3DFMT_DXT1 || desc->format == WINED3DFMT_DXT2 || desc->format == WINED3DFMT_DXT3
371 || desc->format == WINED3DFMT_DXT4 || desc->format == WINED3DFMT_DXT5)
373 && desc->resource_type != WINED3D_RTYPE_TEXTURE_3D && !once++)
374 ERR_(winediag)("The application tried to create a DXTn texture, but the driver does not support them.\n");
375
376 WARN("Failed to initialize resource, returning %#x\n",