From 93fe426cbd0d2b61997d59fbbd1e49b2615f8c0c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20D=C3=B6singer?= <stefan@codeweavers.com>
Date: Fri, 30 Aug 2013 17:06:29 +0200
Subject: wined3d: Separate resource map and draw buffers

---
 dlls/wined3d/resource.c        | 9 +++++++--
 dlls/wined3d/wined3d_private.h | 2 +-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c
index 8fb95a1..39555ef 100644
--- a/dlls/wined3d/resource.c
+++ b/dlls/wined3d/resource.c
@@ -146,8 +146,12 @@ void wined3d_resource_free_bo(struct wined3d_resource *resource)
 {
     struct wined3d_context *context = context_acquire(resource->device, NULL);
 
+    if (resource->buffer != resource->map_buffer)
+        ERR("Releasing resource buffer with buffer != map_buffer.\n");
+
     wined3d_device_release_bo(resource->device, resource->buffer, context);
     resource->buffer = NULL;
+    resource->map_buffer = NULL;
 
     context_release(context);
 }
@@ -535,7 +539,7 @@ BYTE *wined3d_resource_get_map_ptr(const struct wined3d_resource *resource,
     {
         case WINED3D_LOCATION_BUFFER:
             gl_info = context->gl_info;
-            GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, resource->buffer->name));
+            GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, resource->map_buffer->name));
 
             if (gl_info->supported[ARB_MAP_BUFFER_RANGE])
             {
@@ -578,7 +582,7 @@ void wined3d_resource_release_map_ptr(const struct wined3d_resource *resource,
     {
         case WINED3D_LOCATION_BUFFER:
             gl_info = context->gl_info;
-            GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, resource->buffer->name));
+            GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, resource->map_buffer->name));
             GL_EXTCALL(glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER));
             GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));
             checkGLcall("Unmap GL buffer");
@@ -603,6 +607,7 @@ static void wined3d_resource_prepare_bo(struct wined3d_resource *resource, struc
 
     resource->buffer = wined3d_device_get_bo(resource->device, resource->size,
             GL_STREAM_DRAW, GL_PIXEL_UNPACK_BUFFER, context);
+    resource->map_buffer = resource->buffer;
     TRACE("Created GL buffer %u for resource %p.\n", resource->buffer->name, resource);
 }
 
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index ff64215..374dbc2 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2139,7 +2139,7 @@ struct wined3d_resource
     DWORD priority;
     void *heap_memory, *user_memory, *bitmap_data;
     UINT custom_row_pitch, custom_slice_pitch;
-    struct wined3d_gl_bo *buffer;
+    struct wined3d_gl_bo *buffer, *map_buffer;
     struct list resource_list_entry;
     DWORD locations;
     LONG access_fence;
-- 
2.2.1

