From 87143e60ed5708b976754da872f7643ce0982172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20D=C3=B6singer?= Date: Wed, 2 Mar 2016 19:24:20 +0100 Subject: [PATCH] wined3d: Merge surface_prepare_buffer() and wined3d_volume_prepare_pbo(). Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/wined3d/surface.c | 44 +++++++--------------------------- dlls/wined3d/texture.c | 21 ++++++++++++++++ dlls/wined3d/volume.c | 20 +--------------- dlls/wined3d/wined3d_private.h | 2 ++ 4 files changed, 32 insertions(+), 55 deletions(-) diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c index 208c254681a..3cd37827a8f 100644 --- a/dlls/wined3d/surface.c +++ b/dlls/wined3d/surface.c @@ -489,40 +489,6 @@ static void surface_get_memory(const struct wined3d_surface *surface, struct win data->buffer_object = 0; } -static void surface_prepare_buffer(struct wined3d_surface *surface) -{ - struct wined3d_context *context; - GLuint *buffer_object; - GLenum error; - const struct wined3d_gl_info *gl_info; - - buffer_object = &surface->container->sub_resources[surface_get_sub_resource_idx(surface)].buffer_object; - if (*buffer_object) - return; - - context = context_acquire(surface->resource.device, NULL); - gl_info = context->gl_info; - - GL_EXTCALL(glGenBuffers(1, buffer_object)); - error = gl_info->gl_ops.gl.p_glGetError(); - if (!*buffer_object || error != GL_NO_ERROR) - ERR("Failed to create a PBO with error %s (%#x).\n", debug_glerror(error), error); - - TRACE("Binding PBO %u.\n", *buffer_object); - - GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, *buffer_object)); - checkGLcall("glBindBuffer"); - - GL_EXTCALL(glBufferData(GL_PIXEL_UNPACK_BUFFER, surface->resource.size + 4, - NULL, GL_STREAM_DRAW)); - checkGLcall("glBufferData"); - - GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0)); - checkGLcall("glBindBuffer"); - - context_release(context); -} - static void surface_prepare_system_memory(struct wined3d_surface *surface) { TRACE("surface %p.\n", surface); @@ -541,6 +507,9 @@ static void surface_prepare_system_memory(struct wined3d_surface *surface) void surface_prepare_map_memory(struct wined3d_surface *surface) { + struct wined3d_texture *texture = surface->container; + struct wined3d_context *context; + switch (surface->resource.map_binding) { case WINED3D_LOCATION_SYSMEM: @@ -548,7 +517,7 @@ void surface_prepare_map_memory(struct wined3d_surface *surface) break; case WINED3D_LOCATION_USER_MEMORY: - if (!surface->container->user_memory) + if (!texture->user_memory) ERR("Map binding is set to WINED3D_LOCATION_USER_MEMORY but surface->user_memory is NULL.\n"); break; @@ -558,7 +527,10 @@ void surface_prepare_map_memory(struct wined3d_surface *surface) break; case WINED3D_LOCATION_BUFFER: - surface_prepare_buffer(surface); + context = context_acquire(texture->resource.device, NULL); + wined3d_texture_prepare_buffer_object(texture, + surface_get_sub_resource_idx(surface), context->gl_info); + context_release(context); break; default: diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c index a8e9194037d..9846f073724 100644 --- a/dlls/wined3d/texture.c +++ b/dlls/wined3d/texture.c @@ -690,6 +690,27 @@ HRESULT CDECL wined3d_texture_update_desc(struct wined3d_texture *texture, UINT return wined3d_surface_update_desc(surface, gl_info); } +/* Context activation is done by the caller. */ +void wined3d_texture_prepare_buffer_object(struct wined3d_texture *texture, + unsigned int sub_resource_idx, const struct wined3d_gl_info *gl_info) +{ + GLuint *buffer_object; + + buffer_object = &texture->sub_resources[sub_resource_idx].buffer_object; + if (*buffer_object) + return; + + GL_EXTCALL(glGenBuffers(1, buffer_object)); + GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, *buffer_object)); + GL_EXTCALL(glBufferData(GL_PIXEL_UNPACK_BUFFER, + texture->sub_resources[sub_resource_idx].resource->size, NULL, GL_STREAM_DRAW)); + GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0)); + checkGLcall("Create buffer object"); + + TRACE("Created buffer object %u for texture %p, sub-resource %u.\n", + *buffer_object, texture, sub_resource_idx); +} + void wined3d_texture_prepare_texture(struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb) { DWORD alloc_flag = srgb ? WINED3D_TEXTURE_SRGB_ALLOCATED : WINED3D_TEXTURE_RGB_ALLOCATED; diff --git a/dlls/wined3d/volume.c b/dlls/wined3d/volume.c index ef0d69bef82..fcadd395c28 100644 --- a/dlls/wined3d/volume.c +++ b/dlls/wined3d/volume.c @@ -362,24 +362,6 @@ void wined3d_volume_load(struct wined3d_volume *volume, struct wined3d_context * srgb_mode ? WINED3D_LOCATION_TEXTURE_SRGB : WINED3D_LOCATION_TEXTURE_RGB); } -/* Context activation is done by the caller. */ -static void wined3d_volume_prepare_pbo(struct wined3d_volume *volume, struct wined3d_context *context) -{ - GLuint *buffer_object = &volume->container->sub_resources[volume->texture_level].buffer_object; - const struct wined3d_gl_info *gl_info = context->gl_info; - - if (*buffer_object) - return; - - GL_EXTCALL(glGenBuffers(1, buffer_object)); - GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, *buffer_object)); - GL_EXTCALL(glBufferData(GL_PIXEL_UNPACK_BUFFER, volume->resource.size, NULL, GL_STREAM_DRAW)); - GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0)); - checkGLcall("Create PBO"); - - TRACE("Created PBO %u for volume %p.\n", *buffer_object, volume); -} - static void wined3d_volume_free_pbo(struct wined3d_volume *volume) { GLuint *buffer_object = &volume->container->sub_resources[volume->texture_level].buffer_object; @@ -506,7 +488,7 @@ HRESULT wined3d_volume_map(struct wined3d_volume *volume, context = context_acquire(device, NULL); gl_info = context->gl_info; - wined3d_volume_prepare_pbo(volume, context); + wined3d_texture_prepare_buffer_object(texture, volume->texture_level, gl_info); if (flags & WINED3D_MAP_DISCARD) wined3d_volume_validate_location(volume, WINED3D_LOCATION_BUFFER); else diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 468ff11d505..28121b75b7a 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -2420,6 +2420,8 @@ struct wined3d_resource *wined3d_texture_get_sub_resource(const struct wined3d_t UINT sub_resource_idx) DECLSPEC_HIDDEN; void wined3d_texture_load(struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN; +void wined3d_texture_prepare_buffer_object(struct wined3d_texture *texture, + unsigned int sub_resource_idx, const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN; void wined3d_texture_prepare_texture(struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN; void wined3d_texture_set_dirty(struct wined3d_texture *texture) DECLSPEC_HIDDEN;