src/render/direct3d11/SDL_render_d3d11.cpp
changeset 8550 321f0992541c
parent 8548 db8a89a4e633
child 8553 199f6c870823
--- a/src/render/direct3d11/SDL_render_d3d11.cpp	Sat Dec 21 10:08:11 2013 -0500
+++ b/src/render/direct3d11/SDL_render_d3d11.cpp	Sun Dec 22 21:13:35 2013 -0500
@@ -1384,7 +1384,7 @@
 
 static int
 D3D11_UpdateVertexBuffer(SDL_Renderer *renderer,
-                         const void * vertexData, unsigned int dataSizeInBytes)
+                         const void * vertexData, size_t dataSizeInBytes)
 {
     D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
     HRESULT result = S_OK;
@@ -1397,10 +1397,20 @@
     }
 
     if (vertexBufferDesc.ByteWidth >= dataSizeInBytes) {
-        rendererData->d3dContext->UpdateSubresource(rendererData->vertexBuffer.Get(), 0, NULL, vertexData, dataSizeInBytes, 0);
+        D3D11_MAPPED_SUBRESOURCE mappedResource;
+        ZeroMemory(&mappedResource, sizeof(D3D11_MAPPED_SUBRESOURCE));
+        result = rendererData->d3dContext->Map(rendererData->vertexBuffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
+        if (FAILED(result)) {
+            WIN_SetErrorFromHRESULT(__FUNCTION__, result);
+            return -1;
+        }
+        memcpy(mappedResource.pData, vertexData, dataSizeInBytes);
+        rendererData->d3dContext->Unmap(rendererData->vertexBuffer.Get(), 0);
     } else {
         vertexBufferDesc.ByteWidth = dataSizeInBytes;
+        vertexBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
         vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
+        vertexBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
 
         D3D11_SUBRESOURCE_DATA vertexBufferData = {0};
         vertexBufferData.pSysMem = vertexData;