From b7cf2e2b12b808a6f7fc16b4b8b3b0d3f00bdb48 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Sun, 6 Mar 2016 22:08:36 +0100
Subject: Revert "wined3d: Merge surface_prepare_buffer() and
 wined3d_volume_prepare_pbo()."

This reverts commit 87143e60ed5708b976754da872f7643ce0982172.
---
 dlls/wined3d/surface.c         | 44 ++++++++++++++++++++++++++++++++++--------
 dlls/wined3d/texture.c         | 21 --------------------
 dlls/wined3d/volume.c          | 20 ++++++++++++++++++-
 dlls/wined3d/wined3d_private.h |  2 --
 4 files changed, 55 insertions(+), 32 deletions(-)

diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 3cd3782..208c254 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -489,6 +489,40 @@ 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);
@@ -507,9 +541,6 @@ 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:
@@ -517,7 +548,7 @@ void surface_prepare_map_memory(struct wined3d_surface *surface)
             break;
 
         case WINED3D_LOCATION_USER_MEMORY:
-            if (!texture->user_memory)
+            if (!surface->container->user_memory)
                 ERR("Map binding is set to WINED3D_LOCATION_USER_MEMORY but surface->user_memory is NULL.\n");
             break;
 
@@ -527,10 +558,7 @@ void surface_prepare_map_memory(struct wined3d_surface *surface)
             break;
 
         case WINED3D_LOCATION_BUFFER:
-            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);
+            surface_prepare_buffer(surface);
             break;
 
         default:
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c
index 9846f07..a8e9194 100644
--- a/dlls/wined3d/texture.c
+++ b/dlls/wined3d/texture.c
@@ -690,27 +690,6 @@ 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 fcadd39..ef0d69b 100644
--- a/dlls/wined3d/volume.c
+++ b/dlls/wined3d/volume.c
@@ -362,6 +362,24 @@ 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;
@@ -488,7 +506,7 @@ HRESULT wined3d_volume_map(struct wined3d_volume *volume,
         context = context_acquire(device, NULL);
         gl_info = context->gl_info;
 
-        wined3d_texture_prepare_buffer_object(texture, volume->texture_level, gl_info);
+        wined3d_volume_prepare_pbo(volume, context);
         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 28121b7..468ff11 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2420,8 +2420,6 @@ 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;
-- 
2.7.1

