Commit 87143e60 authored by Stefan Dösinger's avatar Stefan Dösinger Committed by Alexandre Julliard

wined3d: Merge surface_prepare_buffer() and wined3d_volume_prepare_pbo().

parent 45fa5b64
......@@ -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:
......
......@@ -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;
......
......@@ -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
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment