From 9d8d5fb99efea2a4d8628429c811457b1b347647 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Sun, 6 Mar 2016 22:08:37 +0100
Subject: Revert "wined3d: Cleanup sub-resource buffer objects in
 wined3d_texture_cleanup()."

This reverts commit 45fa5b6471093db4f97f90b661d1f89d56aa48e7.
---
 dlls/wined3d/surface.c | 11 ++++++++++-
 dlls/wined3d/texture.c | 27 ---------------------------
 dlls/wined3d/volume.c  |  3 +++
 3 files changed, 13 insertions(+), 28 deletions(-)

diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 208c254..994756d 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -48,10 +48,13 @@ static unsigned int surface_get_sub_resource_idx(const struct wined3d_surface *s
 void wined3d_surface_cleanup(struct wined3d_surface *surface)
 {
     struct wined3d_surface *overlay, *cur;
+    GLuint buffer_object;
 
     TRACE("surface %p.\n", surface);
 
-    if (surface->rb_multisample || surface->rb_resolved || !list_empty(&surface->renderbuffers))
+    buffer_object = surface->container->sub_resources[surface_get_sub_resource_idx(surface)].buffer_object;
+    if (buffer_object || surface->rb_multisample
+            || surface->rb_resolved || !list_empty(&surface->renderbuffers))
     {
         struct wined3d_renderbuffer_entry *entry, *entry2;
         const struct wined3d_gl_info *gl_info;
@@ -61,6 +64,12 @@ void wined3d_surface_cleanup(struct wined3d_surface *surface)
         context = context_acquire(device, NULL);
         gl_info = context->gl_info;
 
+        if (buffer_object)
+        {
+            TRACE("Deleting buffer object %u.\n", buffer_object);
+            GL_EXTCALL(glDeleteBuffers(1, &buffer_object));
+        }
+
         if (surface->rb_multisample)
         {
             TRACE("Deleting multisample renderbuffer %u.\n", surface->rb_multisample);
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c
index a8e9194..cb2b310f 100644
--- a/dlls/wined3d/texture.c
+++ b/dlls/wined3d/texture.c
@@ -108,35 +108,8 @@ static void wined3d_texture_unload_gl_texture(struct wined3d_texture *texture)
 
 static void wined3d_texture_cleanup(struct wined3d_texture *texture)
 {
-    unsigned int sub_count = texture->level_count * texture->layer_count;
-    struct wined3d_device *device = texture->resource.device;
-    struct wined3d_context *context = NULL;
-    const struct wined3d_gl_info *gl_info;
-    GLuint buffer_object;
-    unsigned int i;
-
     TRACE("texture %p.\n", texture);
 
-    for (i = 0; i < sub_count; ++i)
-    {
-        if (!(buffer_object = texture->sub_resources[i].buffer_object))
-            continue;
-
-        TRACE("Deleting buffer object %u.\n", buffer_object);
-
-        /* We may not be able to get a context in wined3d_texture_cleanup() in
-         * general, but if a buffer object was previously created we can. */
-        if (!context)
-        {
-            context = context_acquire(device, NULL);
-            gl_info = context->gl_info;
-        }
-
-        GL_EXTCALL(glDeleteBuffers(1, &buffer_object));
-    }
-    if (context)
-        context_release(context);
-
     texture->texture_ops->texture_cleanup_sub_resources(texture);
     wined3d_texture_unload_gl_texture(texture);
     resource_cleanup(&texture->resource);
diff --git a/dlls/wined3d/volume.c b/dlls/wined3d/volume.c
index ef0d69b..3782642 100644
--- a/dlls/wined3d/volume.c
+++ b/dlls/wined3d/volume.c
@@ -397,6 +397,9 @@ void wined3d_volume_cleanup(struct wined3d_volume *volume)
 {
     TRACE("volume %p.\n", volume);
 
+    if (volume->container->sub_resources[volume->texture_level].buffer_object)
+        wined3d_volume_free_pbo(volume);
+
     resource_cleanup(&volume->resource);
 }
 
-- 
2.7.1

