Commit a9094a21a82bfa407f374c67b4da316b1cc1b64a

Ryan C. Gordon 2018-10-03T18:23:53

render: D3D11 renderer patched to compile.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
diff --git a/src/render/direct3d11/SDL_render_d3d11.c b/src/render/direct3d11/SDL_render_d3d11.c
index f381ff5..e9baadc 100644
--- a/src/render/direct3d11/SDL_render_d3d11.c
+++ b/src/render/direct3d11/SDL_render_d3d11.c
@@ -154,6 +154,7 @@ typedef struct
     SDL_Rect currentViewport;
     int currentViewportRotation;
     SDL_bool viewportDirty;
+    Float4X4 identity;
 } D3D11_RenderData;
 
 
@@ -216,6 +217,8 @@ SDLPixelFormatToDXGIFormat(Uint32 sdlFormat)
     }
 }
 
+static void D3D11_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
+
 static void
 D3D11_ReleaseAll(SDL_Renderer * renderer)
 {
@@ -338,7 +341,7 @@ static D3D11_BLEND_OP GetBlendEquation(SDL_BlendOperation operation)
     }
 }
 
-static SDL_bool
+static ID3D11BlendState *
 D3D11_CreateBlendState(SDL_Renderer * renderer, SDL_BlendMode blendMode)
 {
     D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
@@ -367,21 +370,21 @@ D3D11_CreateBlendState(SDL_Renderer * renderer, SDL_BlendMode blendMode)
     result = ID3D11Device_CreateBlendState(data->d3dDevice, &blendDesc, &blendState);
     if (FAILED(result)) {
         WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateBlendState"), result);
-        return SDL_FALSE;
+        return NULL;
     }
 
     blendModes = (D3D11_BlendMode *)SDL_realloc(data->blendModes, (data->blendModesCount + 1) * sizeof(*blendModes));
     if (!blendModes) {
         SAFE_RELEASE(blendState);
         SDL_OutOfMemory();
-        return SDL_FALSE;
+        return NULL;
     }
     blendModes[data->blendModesCount].blendMode = blendMode;
     blendModes[data->blendModesCount].blendState = blendState;
     data->blendModes = blendModes;
     ++data->blendModesCount;
 
-    return SDL_TRUE;
+    return blendState;
 }
 
 /* Create resources that depend on the device. */
@@ -825,6 +828,45 @@ done:
     return result;
 }
 
+static void
+D3D11_ReleaseMainRenderTargetView(SDL_Renderer * renderer)
+{
+    D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata;
+    ID3D11DeviceContext_OMSetRenderTargets(data->d3dContext, 0, NULL, NULL);
+    SAFE_RELEASE(data->mainRenderTargetView);
+}
+
+static HRESULT D3D11_UpdateForWindowSizeChange(SDL_Renderer * renderer);
+
+
+HRESULT
+D3D11_HandleDeviceLost(SDL_Renderer * renderer)
+{
+    HRESULT result = S_OK;
+
+    D3D11_ReleaseAll(renderer);
+
+    result = D3D11_CreateDeviceResources(renderer);
+    if (FAILED(result)) {
+        /* D3D11_CreateDeviceResources will set the SDL error */
+        return result;
+    }
+
+    result = D3D11_UpdateForWindowSizeChange(renderer);
+    if (FAILED(result)) {
+        /* D3D11_UpdateForWindowSizeChange will set the SDL error */
+        return result;
+    }
+
+    /* Let the application know that the device has been reset */
+    {
+        SDL_Event event;
+        event.type = SDL_RENDER_DEVICE_RESET;
+        SDL_PushEvent(&event);
+    }
+
+    return S_OK;
+}
 
 /* Initialize all resources that change when the window's size changes. */
 static HRESULT
@@ -941,35 +983,6 @@ D3D11_UpdateForWindowSizeChange(SDL_Renderer * renderer)
     return D3D11_CreateWindowSizeDependentResources(renderer);
 }
 
-HRESULT
-D3D11_HandleDeviceLost(SDL_Renderer * renderer)
-{
-    HRESULT result = S_OK;
-
-    D3D11_ReleaseAll(renderer);
-
-    result = D3D11_CreateDeviceResources(renderer);
-    if (FAILED(result)) {
-        /* D3D11_CreateDeviceResources will set the SDL error */
-        return result;
-    }
-
-    result = D3D11_UpdateForWindowSizeChange(renderer);
-    if (FAILED(result)) {
-        /* D3D11_UpdateForWindowSizeChange will set the SDL error */
-        return result;
-    }
-
-    /* Let the application know that the device has been reset */
-    {
-        SDL_Event event;
-        event.type = SDL_RENDER_DEVICE_RESET;
-        SDL_PushEvent(&event);
-    }
-
-    return S_OK;
-}
-
 void
 D3D11_Trim(SDL_Renderer * renderer)
 {
@@ -1551,13 +1564,13 @@ D3D11_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL
     for (i = 0; i < count; i++) {
         verts->pos.x = points[i].x + 0.5f;
         verts->pos.y = points[i].y + 0.5f;
-        verts->pos.z = 0.0f
-        verts->tex.u = 0.0f
-        verts->tex.v = 0.0f
-        verts->color.r = r;
-        verts->color.g = g;
-        verts->color.b = b;
-        verts->color.a = a;
+        verts->pos.z = 0.0f;
+        verts->tex.x = 0.0f;
+        verts->tex.y = 0.0f;
+        verts->color.x = r;
+        verts->color.y = g;
+        verts->color.z = b;
+        verts->color.w = a;
         verts++;
     }
 
@@ -1581,46 +1594,46 @@ D3D11_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_
     for (i = 0; i < count; i++) {
         verts->pos.x = rects[i].x;
         verts->pos.y = rects[i].y;
-        verts->pos.z = 0.0f
-        verts->tex.u = 0.0f
-        verts->tex.v = 0.0f
-        verts->color.r = r;
-        verts->color.g = g;
-        verts->color.b = b;
-        verts->color.a = a;
+        verts->pos.z = 0.0f;
+        verts->tex.x = 0.0f;
+        verts->tex.y = 0.0f;
+        verts->color.x = r;
+        verts->color.y = g;
+        verts->color.z = b;
+        verts->color.w = a;
         verts++;
 
         verts->pos.x = rects[i].x;
         verts->pos.y = rects[i].y + rects[i].h;
-        verts->pos.z = 0.0f
-        verts->tex.u = 0.0f
-        verts->tex.v = 0.0f
-        verts->color.r = r;
-        verts->color.g = g;
-        verts->color.b = b;
-        verts->color.a = a;
+        verts->pos.z = 0.0f;
+        verts->tex.x = 0.0f;
+        verts->tex.y = 0.0f;
+        verts->color.x = r;
+        verts->color.y = g;
+        verts->color.z = b;
+        verts->color.w = a;
         verts++;
 
         verts->pos.x = rects[i].x + rects[i].w;
         verts->pos.y = rects[i].y;
-        verts->pos.z = 0.0f
-        verts->tex.u = 0.0f
-        verts->tex.v = 0.0f
-        verts->color.r = r;
-        verts->color.g = g;
-        verts->color.b = b;
-        verts->color.a = a;
+        verts->pos.z = 0.0f;
+        verts->tex.x = 0.0f;
+        verts->tex.y = 0.0f;
+        verts->color.x = r;
+        verts->color.y = g;
+        verts->color.z = b;
+        verts->color.w = a;
         verts++;
 
         verts->pos.x = rects[i].x + rects[i].w;
         verts->pos.y = rects[i].y + rects[i].h;
-        verts->pos.z = 0.0f
-        verts->tex.u = 0.0f
-        verts->tex.v = 0.0f
-        verts->color.r = r;
-        verts->color.g = g;
-        verts->color.b = b;
-        verts->color.a = a;
+        verts->pos.z = 0.0f;
+        verts->tex.x = 0.0f;
+        verts->tex.y = 0.0f;
+        verts->color.x = r;
+        verts->color.y = g;
+        verts->color.z = b;
+        verts->color.w = a;
         verts++;
     }
 
@@ -1631,7 +1644,7 @@ static int
 D3D11_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
              const SDL_Rect * srcrect, const SDL_FRect * dstrect)
 {
-    VertexPositionColor *verts = (VertexPositionColor *) SDL_AllocateRenderVertices(renderer, count * 4 * sizeof (VertexPositionColor), 0, &cmd->data.draw.first);
+    VertexPositionColor *verts = (VertexPositionColor *) SDL_AllocateRenderVertices(renderer, 4 * sizeof (VertexPositionColor), 0, &cmd->data.draw.first);
     const float r = (float)(cmd->data.draw.r / 255.0f);
     const float g = (float)(cmd->data.draw.g / 255.0f);
     const float b = (float)(cmd->data.draw.b / 255.0f);
@@ -1650,10 +1663,10 @@ D3D11_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * t
     verts->pos.z = 0.0f;
     verts->tex.x = minu;
     verts->tex.y = minv;
-    verts->color.r = r;
-    verts->color.g = g;
-    verts->color.b = b;
-    verts->color.a = a;
+    verts->color.x = r;
+    verts->color.y = g;
+    verts->color.z = b;
+    verts->color.w = a;
     verts++;
 
     verts->pos.x = dstrect->x;
@@ -1661,10 +1674,10 @@ D3D11_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * t
     verts->pos.z = 0.0f;
     verts->tex.x = minu;
     verts->tex.y = maxv;
-    verts->color.r = r;
-    verts->color.g = g;
-    verts->color.b = b;
-    verts->color.a = a;
+    verts->color.x = r;
+    verts->color.y = g;
+    verts->color.z = b;
+    verts->color.w = a;
     verts++;
 
     verts->pos.x = dstrect->x + dstrect->w;
@@ -1672,10 +1685,10 @@ D3D11_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * t
     verts->pos.z = 0.0f;
     verts->tex.x = maxu;
     verts->tex.y = minv;
-    verts->color.r = r;
-    verts->color.g = g;
-    verts->color.b = b;
-    verts->color.a = a;
+    verts->color.x = r;
+    verts->color.y = g;
+    verts->color.z = b;
+    verts->color.w = a;
     verts++;
 
     verts->pos.x = dstrect->x + dstrect->w;
@@ -1683,10 +1696,10 @@ D3D11_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * t
     verts->pos.z = 0.0f;
     verts->tex.x = maxu;
     verts->tex.y = maxv;
-    verts->color.r = r;
-    verts->color.g = g;
-    verts->color.b = b;
-    verts->color.a = a;
+    verts->color.x = r;
+    verts->color.y = g;
+    verts->color.z = b;
+    verts->color.w = a;
     verts++;
 
     return 0;
@@ -1697,7 +1710,7 @@ D3D11_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture *
                const SDL_Rect * srcrect, const SDL_FRect * dstrect,
                const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
 {
-    VertexPositionColor *verts = (VertexPositionColor *) SDL_AllocateRenderVertices(renderer, count * 5 * sizeof (VertexPositionColor), 0, &cmd->data.draw.first);
+    VertexPositionColor *verts = (VertexPositionColor *) SDL_AllocateRenderVertices(renderer, 5 * sizeof (VertexPositionColor), 0, &cmd->data.draw.first);
     const float r = (float)(cmd->data.draw.r / 255.0f);
     const float g = (float)(cmd->data.draw.g / 255.0f);
     const float b = (float)(cmd->data.draw.b / 255.0f);
@@ -1713,7 +1726,6 @@ D3D11_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture *
         maxu = (float) srcrect->x / texture->w;
     }
 
-    }
     if (flip & SDL_FLIP_VERTICAL) {
         minv = (float) srcrect->y / texture->h;
         maxv = (float) (srcrect->y + srcrect->h) / texture->h;
@@ -1732,10 +1744,10 @@ D3D11_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture *
     verts->pos.z = 0.0f;
     verts->tex.x = minu;
     verts->tex.y = minv;
-    verts->color.r = r;
-    verts->color.g = g;
-    verts->color.b = b;
-    verts->color.a = a;
+    verts->color.x = r;
+    verts->color.y = g;
+    verts->color.z = b;
+    verts->color.w = a;
     verts++;
 
     verts->pos.x = minx;
@@ -1743,10 +1755,10 @@ D3D11_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture *
     verts->pos.z = 0.0f;
     verts->tex.x = minu;
     verts->tex.y = maxv;
-    verts->color.r = r;
-    verts->color.g = g;
-    verts->color.b = b;
-    verts->color.a = a;
+    verts->color.x = r;
+    verts->color.y = g;
+    verts->color.z = b;
+    verts->color.w = a;
     verts++;
 
     verts->pos.x = maxx;
@@ -1754,10 +1766,10 @@ D3D11_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture *
     verts->pos.z = 0.0f;
     verts->tex.x = maxu;
     verts->tex.y = minv;
-    verts->color.r = r;
-    verts->color.g = g;
-    verts->color.b = b;
-    verts->color.a = a;
+    verts->color.x = r;
+    verts->color.y = g;
+    verts->color.z = b;
+    verts->color.w = a;
     verts++;
 
     verts->pos.x = maxx;
@@ -1765,21 +1777,21 @@ D3D11_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture *
     verts->pos.z = 0.0f;
     verts->tex.x = maxu;
     verts->tex.y = maxv;
-    verts->color.r = r;
-    verts->color.g = g;
-    verts->color.b = b;
-    verts->color.a = a;
+    verts->color.x = r;
+    verts->color.y = g;
+    verts->color.z = b;
+    verts->color.w = a;
     verts++;
 
     verts->pos.x = dstrect->x + center->x;  /* X translation */
     verts->pos.y = dstrect->y + center->y;  /* Y translation */
     verts->pos.z = (float)(M_PI * (float) angle / 180.0f);  /* rotation */
-    verts->tex.u = 0.0f;
-    verts->tex.v = 0.0f;
-    verts->color.r = 0;
-    verts->color.g = 0;
-    verts->color.b = 0;
-    verts->color.a = 0;
+    verts->tex.x = 0.0f;
+    verts->tex.y = 0.0f;
+    verts->color.x = 0;
+    verts->color.y = 0;
+    verts->color.z = 0;
+    verts->color.w = 0;
     verts++;
 
     return 0;
@@ -1947,6 +1959,18 @@ D3D11_UpdateViewport(SDL_Renderer * renderer)
     return 0;
 }
 
+static ID3D11RenderTargetView *
+D3D11_GetCurrentRenderTargetView(SDL_Renderer * renderer)
+{
+    D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata;
+    if (data->currentOffscreenRenderTargetView) {
+        return data->currentOffscreenRenderTargetView;
+    }
+    else {
+        return data->mainRenderTargetView;
+    }
+}
+
 static int
 D3D11_SetDrawState(SDL_Renderer * renderer, const SDL_RenderCommand *cmd, ID3D11PixelShader * shader,
                      const int numShaderResources, ID3D11ShaderResourceView ** shaderResources,
@@ -1954,8 +1978,7 @@ D3D11_SetDrawState(SDL_Renderer * renderer, const SDL_RenderCommand *cmd, ID3D11
 
 {
     D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->driverdata;
-    static const Float4X4 identity = MatrixIdentity();
-    const Float4X4 *newmatrix = matrix ? matrix : &identity;
+    const Float4X4 *newmatrix = matrix ? matrix : &rendererData->identity;
     ID3D11RasterizerState *rasterizerState;
     ID3D11RenderTargetView *renderTargetView = D3D11_GetCurrentRenderTargetView(renderer);
     ID3D11ShaderResourceView *shaderResource;
@@ -1984,7 +2007,7 @@ D3D11_SetDrawState(SDL_Renderer * renderer, const SDL_RenderCommand *cmd, ID3D11
                 /* D3D11_GetViewportAlignedD3DRect will have set the SDL error */
                 return -1;
             }
-            ID3D11DeviceContext_RSSetScissorRects(data->d3dContext, 1, &scissorRect);
+            ID3D11DeviceContext_RSSetScissorRects(rendererData->d3dContext, 1, &scissorRect);
         }
         rendererData->cliprectDirty = SDL_FALSE;
     }
@@ -2008,11 +2031,10 @@ D3D11_SetDrawState(SDL_Renderer * renderer, const SDL_RenderCommand *cmd, ID3D11
             }
         }
         if (!blendState) {
-            if (D3D11_CreateBlendState(renderer, blendMode)) {
-                /* Successfully created the blend state, try again */
-                D3D11_RenderSetBlendMode(renderer, blendMode);
+            blendState = D3D11_CreateBlendState(renderer, blendMode);
+            if (!blendState) {
+                return -1;
             }
-            return;
         }
     }
     if (blendState != rendererData->currentBlendState) {
@@ -2038,13 +2060,13 @@ D3D11_SetDrawState(SDL_Renderer * renderer, const SDL_RenderCommand *cmd, ID3D11
         rendererData->currentSampler = sampler;
     }
 
-    if (SDL_memcmp(&data->vertexShaderConstantsData.model, newmatrix, sizeof (*newmatrix)) != 0) {
-        SDL_memcpy(&data->vertexShaderConstantsData.model, newmatrix, sizeof (*newmatrix));
-        ID3D11DeviceContext_UpdateSubresource(data->d3dContext,
-            (ID3D11Resource *)data->vertexShaderConstants,
+    if (SDL_memcmp(&rendererData->vertexShaderConstantsData.model, newmatrix, sizeof (*newmatrix)) != 0) {
+        SDL_memcpy(&rendererData->vertexShaderConstantsData.model, newmatrix, sizeof (*newmatrix));
+        ID3D11DeviceContext_UpdateSubresource(rendererData->d3dContext,
+            (ID3D11Resource *)rendererData->vertexShaderConstants,
             0,
             NULL,
-            &data->vertexShaderConstantsData,
+            &rendererData->vertexShaderConstantsData,
             0,
             0
             );
@@ -2123,16 +2145,16 @@ D3D11_SetCopyState(SDL_Renderer * renderer, const SDL_RenderCommand *cmd, const 
 
     }
 
-    return D3D11_SetDrawState(renderer, cmd,  renderer, rendererData->pixelShaders[SHADER_RGB],
+    return D3D11_SetDrawState(renderer, cmd, rendererData->pixelShaders[SHADER_RGB],
                               1, &textureData->mainTextureResourceView, textureSampler, matrix);
 }
 
 static void
-D3D11_DrawPrimitives(SDL_Renderer * renderer, D3D11_PRIMITIVE_TOPOLOGY primitiveTopology, const UINT vertexStart, const UINT vertexCount)
+D3D11_DrawPrimitives(SDL_Renderer * renderer, D3D11_PRIMITIVE_TOPOLOGY primitiveTopology, const size_t vertexStart, const size_t vertexCount)
 {
     D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
     ID3D11DeviceContext_IASetPrimitiveTopology(rendererData->d3dContext, primitiveTopology);
-    ID3D11DeviceContext_Draw(rendererData->d3dContext, vertexCount, vertexStart);
+    ID3D11DeviceContext_Draw(rendererData->d3dContext, (UINT) vertexCount, (UINT) vertexStart);
 }
 
 static int
@@ -2161,7 +2183,7 @@ D3D11_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
                 SDL_Rect *viewport = &rendererData->currentViewport;
                 if (SDL_memcmp(viewport, &cmd->data.viewport.rect, sizeof (SDL_Rect)) != 0) {
                     SDL_memcpy(viewport, &cmd->data.viewport.rect, sizeof (SDL_Rect));
-                    data->drawstate.viewportDirty = SDL_TRUE;
+                    rendererData->viewportDirty = SDL_TRUE;
                 }
                 break;
             }
@@ -2186,7 +2208,7 @@ D3D11_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
                     (cmd->data.color.b / 255.0f),
                     (cmd->data.color.a / 255.0f)
                 };
-                ID3D11DeviceContext_ClearRenderTargetView(data->d3dContext, D3D11_GetCurrentRenderTargetView(renderer), colorRGBA);
+                ID3D11DeviceContext_ClearRenderTargetView(rendererData->d3dContext, D3D11_GetCurrentRenderTargetView(renderer), colorRGBA);
                 break;
             }
 
@@ -2206,7 +2228,7 @@ D3D11_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
                 const VertexPositionColor *verts = (VertexPositionColor *) (((Uint8 *) vertices) + first);
                 D3D11_SetDrawState(renderer, cmd, rendererData->pixelShaders[SHADER_SOLID], 0, NULL, NULL, NULL);
                 D3D11_DrawPrimitives(renderer, D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP, start, count);
-                if (verts[0].x != verts[count - 1].x || verts[0].y != verts[count - 1].y) {
+                if (verts[0].pos.x != verts[count - 1].pos.x || verts[0].pos.y != verts[count - 1].pos.y) {
                     D3D11_DrawPrimitives(renderer, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST, start + (count-1), 1);
                 }
                 break;
@@ -2227,7 +2249,7 @@ D3D11_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
             case SDL_RENDERCMD_COPY: {
                 const size_t first = cmd->data.draw.first;
                 const size_t start = first / sizeof (VertexPositionColor);
-                D3D11_SetCopyState(data, cmd, NULL);
+                D3D11_SetCopyState(renderer, cmd, NULL);
                 D3D11_DrawPrimitives(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, start, 4);
                 break;
             }
@@ -2236,12 +2258,12 @@ D3D11_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
                 const size_t first = cmd->data.draw.first;
                 const size_t start = first / sizeof (VertexPositionColor);
                 const VertexPositionColor *verts = (VertexPositionColor *) (((Uint8 *) vertices) + first);
-                const Vertex *transvert = verts + 4;
+                const VertexPositionColor *transvert = verts + 4;
                 const float translatex = transvert->pos.x;
                 const float translatey = transvert->pos.y;
                 const float rotation = transvert->pos.z;
                 const Float4X4 matrix = MatrixMultiply(MatrixRotationZ(rotation), MatrixTranslation(translatex, translatey, 0));
-                D3D11_SetCopyState(data, cmd, &matrix);
+                D3D11_SetCopyState(renderer, cmd, &matrix);
                 D3D11_DrawPrimitives(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, start, 4);
                 break;
             }
@@ -2256,26 +2278,6 @@ D3D11_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
     return 0;
 }
 
-
-static void
-D3D11_ReleaseMainRenderTargetView(SDL_Renderer * renderer)
-{
-    D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata;
-    ID3D11DeviceContext_OMSetRenderTargets(data->d3dContext, 0, NULL, NULL);
-    SAFE_RELEASE(data->mainRenderTargetView);
-}
-
-static ID3D11RenderTargetView *
-D3D11_GetCurrentRenderTargetView(SDL_Renderer * renderer)
-{
-    D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
-    if (data->currentOffscreenRenderTargetView) {
-        return data->currentOffscreenRenderTargetView;
-    } else {
-        return data->mainRenderTargetView;
-    }
-}
-
 static int
 D3D11_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
                        Uint32 format, void * pixels, int pitch)
@@ -2458,6 +2460,8 @@ D3D11_CreateRenderer(SDL_Window * window, Uint32 flags)
         return NULL;
     }
 
+    data->identity = MatrixIdentity();
+
     renderer->WindowEvent = D3D11_WindowEvent;
     renderer->SupportsBlendMode = D3D11_SupportsBlendMode;
     renderer->CreateTexture = D3D11_CreateTexture;