render: D3D11 renderer patched to compile. SDL-ryan-batching-renderer
authorRyan C. Gordon <icculus@icculus.org>
Wed, 03 Oct 2018 18:23:53 -0400
branchSDL-ryan-batching-renderer
changeset 1228675abb8e13a91
parent 12283 6c108f3716d5
child 12287 dff7e6ba9137
render: D3D11 renderer patched to compile.
src/render/direct3d11/SDL_render_d3d11.c
     1.1 --- a/src/render/direct3d11/SDL_render_d3d11.c	Wed Oct 03 00:52:37 2018 -0400
     1.2 +++ b/src/render/direct3d11/SDL_render_d3d11.c	Wed Oct 03 18:23:53 2018 -0400
     1.3 @@ -154,6 +154,7 @@
     1.4      SDL_Rect currentViewport;
     1.5      int currentViewportRotation;
     1.6      SDL_bool viewportDirty;
     1.7 +    Float4X4 identity;
     1.8  } D3D11_RenderData;
     1.9  
    1.10  
    1.11 @@ -216,6 +217,8 @@
    1.12      }
    1.13  }
    1.14  
    1.15 +static void D3D11_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
    1.16 +
    1.17  static void
    1.18  D3D11_ReleaseAll(SDL_Renderer * renderer)
    1.19  {
    1.20 @@ -338,7 +341,7 @@
    1.21      }
    1.22  }
    1.23  
    1.24 -static SDL_bool
    1.25 +static ID3D11BlendState *
    1.26  D3D11_CreateBlendState(SDL_Renderer * renderer, SDL_BlendMode blendMode)
    1.27  {
    1.28      D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
    1.29 @@ -367,21 +370,21 @@
    1.30      result = ID3D11Device_CreateBlendState(data->d3dDevice, &blendDesc, &blendState);
    1.31      if (FAILED(result)) {
    1.32          WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateBlendState"), result);
    1.33 -        return SDL_FALSE;
    1.34 +        return NULL;
    1.35      }
    1.36  
    1.37      blendModes = (D3D11_BlendMode *)SDL_realloc(data->blendModes, (data->blendModesCount + 1) * sizeof(*blendModes));
    1.38      if (!blendModes) {
    1.39          SAFE_RELEASE(blendState);
    1.40          SDL_OutOfMemory();
    1.41 -        return SDL_FALSE;
    1.42 +        return NULL;
    1.43      }
    1.44      blendModes[data->blendModesCount].blendMode = blendMode;
    1.45      blendModes[data->blendModesCount].blendState = blendState;
    1.46      data->blendModes = blendModes;
    1.47      ++data->blendModesCount;
    1.48  
    1.49 -    return SDL_TRUE;
    1.50 +    return blendState;
    1.51  }
    1.52  
    1.53  /* Create resources that depend on the device. */
    1.54 @@ -825,6 +828,45 @@
    1.55      return result;
    1.56  }
    1.57  
    1.58 +static void
    1.59 +D3D11_ReleaseMainRenderTargetView(SDL_Renderer * renderer)
    1.60 +{
    1.61 +    D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata;
    1.62 +    ID3D11DeviceContext_OMSetRenderTargets(data->d3dContext, 0, NULL, NULL);
    1.63 +    SAFE_RELEASE(data->mainRenderTargetView);
    1.64 +}
    1.65 +
    1.66 +static HRESULT D3D11_UpdateForWindowSizeChange(SDL_Renderer * renderer);
    1.67 +
    1.68 +
    1.69 +HRESULT
    1.70 +D3D11_HandleDeviceLost(SDL_Renderer * renderer)
    1.71 +{
    1.72 +    HRESULT result = S_OK;
    1.73 +
    1.74 +    D3D11_ReleaseAll(renderer);
    1.75 +
    1.76 +    result = D3D11_CreateDeviceResources(renderer);
    1.77 +    if (FAILED(result)) {
    1.78 +        /* D3D11_CreateDeviceResources will set the SDL error */
    1.79 +        return result;
    1.80 +    }
    1.81 +
    1.82 +    result = D3D11_UpdateForWindowSizeChange(renderer);
    1.83 +    if (FAILED(result)) {
    1.84 +        /* D3D11_UpdateForWindowSizeChange will set the SDL error */
    1.85 +        return result;
    1.86 +    }
    1.87 +
    1.88 +    /* Let the application know that the device has been reset */
    1.89 +    {
    1.90 +        SDL_Event event;
    1.91 +        event.type = SDL_RENDER_DEVICE_RESET;
    1.92 +        SDL_PushEvent(&event);
    1.93 +    }
    1.94 +
    1.95 +    return S_OK;
    1.96 +}
    1.97  
    1.98  /* Initialize all resources that change when the window's size changes. */
    1.99  static HRESULT
   1.100 @@ -941,35 +983,6 @@
   1.101      return D3D11_CreateWindowSizeDependentResources(renderer);
   1.102  }
   1.103  
   1.104 -HRESULT
   1.105 -D3D11_HandleDeviceLost(SDL_Renderer * renderer)
   1.106 -{
   1.107 -    HRESULT result = S_OK;
   1.108 -
   1.109 -    D3D11_ReleaseAll(renderer);
   1.110 -
   1.111 -    result = D3D11_CreateDeviceResources(renderer);
   1.112 -    if (FAILED(result)) {
   1.113 -        /* D3D11_CreateDeviceResources will set the SDL error */
   1.114 -        return result;
   1.115 -    }
   1.116 -
   1.117 -    result = D3D11_UpdateForWindowSizeChange(renderer);
   1.118 -    if (FAILED(result)) {
   1.119 -        /* D3D11_UpdateForWindowSizeChange will set the SDL error */
   1.120 -        return result;
   1.121 -    }
   1.122 -
   1.123 -    /* Let the application know that the device has been reset */
   1.124 -    {
   1.125 -        SDL_Event event;
   1.126 -        event.type = SDL_RENDER_DEVICE_RESET;
   1.127 -        SDL_PushEvent(&event);
   1.128 -    }
   1.129 -
   1.130 -    return S_OK;
   1.131 -}
   1.132 -
   1.133  void
   1.134  D3D11_Trim(SDL_Renderer * renderer)
   1.135  {
   1.136 @@ -1551,13 +1564,13 @@
   1.137      for (i = 0; i < count; i++) {
   1.138          verts->pos.x = points[i].x + 0.5f;
   1.139          verts->pos.y = points[i].y + 0.5f;
   1.140 -        verts->pos.z = 0.0f
   1.141 -        verts->tex.u = 0.0f
   1.142 -        verts->tex.v = 0.0f
   1.143 -        verts->color.r = r;
   1.144 -        verts->color.g = g;
   1.145 -        verts->color.b = b;
   1.146 -        verts->color.a = a;
   1.147 +        verts->pos.z = 0.0f;
   1.148 +        verts->tex.x = 0.0f;
   1.149 +        verts->tex.y = 0.0f;
   1.150 +        verts->color.x = r;
   1.151 +        verts->color.y = g;
   1.152 +        verts->color.z = b;
   1.153 +        verts->color.w = a;
   1.154          verts++;
   1.155      }
   1.156  
   1.157 @@ -1581,46 +1594,46 @@
   1.158      for (i = 0; i < count; i++) {
   1.159          verts->pos.x = rects[i].x;
   1.160          verts->pos.y = rects[i].y;
   1.161 -        verts->pos.z = 0.0f
   1.162 -        verts->tex.u = 0.0f
   1.163 -        verts->tex.v = 0.0f
   1.164 -        verts->color.r = r;
   1.165 -        verts->color.g = g;
   1.166 -        verts->color.b = b;
   1.167 -        verts->color.a = a;
   1.168 +        verts->pos.z = 0.0f;
   1.169 +        verts->tex.x = 0.0f;
   1.170 +        verts->tex.y = 0.0f;
   1.171 +        verts->color.x = r;
   1.172 +        verts->color.y = g;
   1.173 +        verts->color.z = b;
   1.174 +        verts->color.w = a;
   1.175          verts++;
   1.176  
   1.177          verts->pos.x = rects[i].x;
   1.178          verts->pos.y = rects[i].y + rects[i].h;
   1.179 -        verts->pos.z = 0.0f
   1.180 -        verts->tex.u = 0.0f
   1.181 -        verts->tex.v = 0.0f
   1.182 -        verts->color.r = r;
   1.183 -        verts->color.g = g;
   1.184 -        verts->color.b = b;
   1.185 -        verts->color.a = a;
   1.186 +        verts->pos.z = 0.0f;
   1.187 +        verts->tex.x = 0.0f;
   1.188 +        verts->tex.y = 0.0f;
   1.189 +        verts->color.x = r;
   1.190 +        verts->color.y = g;
   1.191 +        verts->color.z = b;
   1.192 +        verts->color.w = a;
   1.193          verts++;
   1.194  
   1.195          verts->pos.x = rects[i].x + rects[i].w;
   1.196          verts->pos.y = rects[i].y;
   1.197 -        verts->pos.z = 0.0f
   1.198 -        verts->tex.u = 0.0f
   1.199 -        verts->tex.v = 0.0f
   1.200 -        verts->color.r = r;
   1.201 -        verts->color.g = g;
   1.202 -        verts->color.b = b;
   1.203 -        verts->color.a = a;
   1.204 +        verts->pos.z = 0.0f;
   1.205 +        verts->tex.x = 0.0f;
   1.206 +        verts->tex.y = 0.0f;
   1.207 +        verts->color.x = r;
   1.208 +        verts->color.y = g;
   1.209 +        verts->color.z = b;
   1.210 +        verts->color.w = a;
   1.211          verts++;
   1.212  
   1.213          verts->pos.x = rects[i].x + rects[i].w;
   1.214          verts->pos.y = rects[i].y + rects[i].h;
   1.215 -        verts->pos.z = 0.0f
   1.216 -        verts->tex.u = 0.0f
   1.217 -        verts->tex.v = 0.0f
   1.218 -        verts->color.r = r;
   1.219 -        verts->color.g = g;
   1.220 -        verts->color.b = b;
   1.221 -        verts->color.a = a;
   1.222 +        verts->pos.z = 0.0f;
   1.223 +        verts->tex.x = 0.0f;
   1.224 +        verts->tex.y = 0.0f;
   1.225 +        verts->color.x = r;
   1.226 +        verts->color.y = g;
   1.227 +        verts->color.z = b;
   1.228 +        verts->color.w = a;
   1.229          verts++;
   1.230      }
   1.231  
   1.232 @@ -1631,7 +1644,7 @@
   1.233  D3D11_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
   1.234               const SDL_Rect * srcrect, const SDL_FRect * dstrect)
   1.235  {
   1.236 -    VertexPositionColor *verts = (VertexPositionColor *) SDL_AllocateRenderVertices(renderer, count * 4 * sizeof (VertexPositionColor), 0, &cmd->data.draw.first);
   1.237 +    VertexPositionColor *verts = (VertexPositionColor *) SDL_AllocateRenderVertices(renderer, 4 * sizeof (VertexPositionColor), 0, &cmd->data.draw.first);
   1.238      const float r = (float)(cmd->data.draw.r / 255.0f);
   1.239      const float g = (float)(cmd->data.draw.g / 255.0f);
   1.240      const float b = (float)(cmd->data.draw.b / 255.0f);
   1.241 @@ -1650,10 +1663,10 @@
   1.242      verts->pos.z = 0.0f;
   1.243      verts->tex.x = minu;
   1.244      verts->tex.y = minv;
   1.245 -    verts->color.r = r;
   1.246 -    verts->color.g = g;
   1.247 -    verts->color.b = b;
   1.248 -    verts->color.a = a;
   1.249 +    verts->color.x = r;
   1.250 +    verts->color.y = g;
   1.251 +    verts->color.z = b;
   1.252 +    verts->color.w = a;
   1.253      verts++;
   1.254  
   1.255      verts->pos.x = dstrect->x;
   1.256 @@ -1661,10 +1674,10 @@
   1.257      verts->pos.z = 0.0f;
   1.258      verts->tex.x = minu;
   1.259      verts->tex.y = maxv;
   1.260 -    verts->color.r = r;
   1.261 -    verts->color.g = g;
   1.262 -    verts->color.b = b;
   1.263 -    verts->color.a = a;
   1.264 +    verts->color.x = r;
   1.265 +    verts->color.y = g;
   1.266 +    verts->color.z = b;
   1.267 +    verts->color.w = a;
   1.268      verts++;
   1.269  
   1.270      verts->pos.x = dstrect->x + dstrect->w;
   1.271 @@ -1672,10 +1685,10 @@
   1.272      verts->pos.z = 0.0f;
   1.273      verts->tex.x = maxu;
   1.274      verts->tex.y = minv;
   1.275 -    verts->color.r = r;
   1.276 -    verts->color.g = g;
   1.277 -    verts->color.b = b;
   1.278 -    verts->color.a = a;
   1.279 +    verts->color.x = r;
   1.280 +    verts->color.y = g;
   1.281 +    verts->color.z = b;
   1.282 +    verts->color.w = a;
   1.283      verts++;
   1.284  
   1.285      verts->pos.x = dstrect->x + dstrect->w;
   1.286 @@ -1683,10 +1696,10 @@
   1.287      verts->pos.z = 0.0f;
   1.288      verts->tex.x = maxu;
   1.289      verts->tex.y = maxv;
   1.290 -    verts->color.r = r;
   1.291 -    verts->color.g = g;
   1.292 -    verts->color.b = b;
   1.293 -    verts->color.a = a;
   1.294 +    verts->color.x = r;
   1.295 +    verts->color.y = g;
   1.296 +    verts->color.z = b;
   1.297 +    verts->color.w = a;
   1.298      verts++;
   1.299  
   1.300      return 0;
   1.301 @@ -1697,7 +1710,7 @@
   1.302                 const SDL_Rect * srcrect, const SDL_FRect * dstrect,
   1.303                 const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
   1.304  {
   1.305 -    VertexPositionColor *verts = (VertexPositionColor *) SDL_AllocateRenderVertices(renderer, count * 5 * sizeof (VertexPositionColor), 0, &cmd->data.draw.first);
   1.306 +    VertexPositionColor *verts = (VertexPositionColor *) SDL_AllocateRenderVertices(renderer, 5 * sizeof (VertexPositionColor), 0, &cmd->data.draw.first);
   1.307      const float r = (float)(cmd->data.draw.r / 255.0f);
   1.308      const float g = (float)(cmd->data.draw.g / 255.0f);
   1.309      const float b = (float)(cmd->data.draw.b / 255.0f);
   1.310 @@ -1713,7 +1726,6 @@
   1.311          maxu = (float) srcrect->x / texture->w;
   1.312      }
   1.313  
   1.314 -    }
   1.315      if (flip & SDL_FLIP_VERTICAL) {
   1.316          minv = (float) srcrect->y / texture->h;
   1.317          maxv = (float) (srcrect->y + srcrect->h) / texture->h;
   1.318 @@ -1732,10 +1744,10 @@
   1.319      verts->pos.z = 0.0f;
   1.320      verts->tex.x = minu;
   1.321      verts->tex.y = minv;
   1.322 -    verts->color.r = r;
   1.323 -    verts->color.g = g;
   1.324 -    verts->color.b = b;
   1.325 -    verts->color.a = a;
   1.326 +    verts->color.x = r;
   1.327 +    verts->color.y = g;
   1.328 +    verts->color.z = b;
   1.329 +    verts->color.w = a;
   1.330      verts++;
   1.331  
   1.332      verts->pos.x = minx;
   1.333 @@ -1743,10 +1755,10 @@
   1.334      verts->pos.z = 0.0f;
   1.335      verts->tex.x = minu;
   1.336      verts->tex.y = maxv;
   1.337 -    verts->color.r = r;
   1.338 -    verts->color.g = g;
   1.339 -    verts->color.b = b;
   1.340 -    verts->color.a = a;
   1.341 +    verts->color.x = r;
   1.342 +    verts->color.y = g;
   1.343 +    verts->color.z = b;
   1.344 +    verts->color.w = a;
   1.345      verts++;
   1.346  
   1.347      verts->pos.x = maxx;
   1.348 @@ -1754,10 +1766,10 @@
   1.349      verts->pos.z = 0.0f;
   1.350      verts->tex.x = maxu;
   1.351      verts->tex.y = minv;
   1.352 -    verts->color.r = r;
   1.353 -    verts->color.g = g;
   1.354 -    verts->color.b = b;
   1.355 -    verts->color.a = a;
   1.356 +    verts->color.x = r;
   1.357 +    verts->color.y = g;
   1.358 +    verts->color.z = b;
   1.359 +    verts->color.w = a;
   1.360      verts++;
   1.361  
   1.362      verts->pos.x = maxx;
   1.363 @@ -1765,21 +1777,21 @@
   1.364      verts->pos.z = 0.0f;
   1.365      verts->tex.x = maxu;
   1.366      verts->tex.y = maxv;
   1.367 -    verts->color.r = r;
   1.368 -    verts->color.g = g;
   1.369 -    verts->color.b = b;
   1.370 -    verts->color.a = a;
   1.371 +    verts->color.x = r;
   1.372 +    verts->color.y = g;
   1.373 +    verts->color.z = b;
   1.374 +    verts->color.w = a;
   1.375      verts++;
   1.376  
   1.377      verts->pos.x = dstrect->x + center->x;  /* X translation */
   1.378      verts->pos.y = dstrect->y + center->y;  /* Y translation */
   1.379      verts->pos.z = (float)(M_PI * (float) angle / 180.0f);  /* rotation */
   1.380 -    verts->tex.u = 0.0f;
   1.381 -    verts->tex.v = 0.0f;
   1.382 -    verts->color.r = 0;
   1.383 -    verts->color.g = 0;
   1.384 -    verts->color.b = 0;
   1.385 -    verts->color.a = 0;
   1.386 +    verts->tex.x = 0.0f;
   1.387 +    verts->tex.y = 0.0f;
   1.388 +    verts->color.x = 0;
   1.389 +    verts->color.y = 0;
   1.390 +    verts->color.z = 0;
   1.391 +    verts->color.w = 0;
   1.392      verts++;
   1.393  
   1.394      return 0;
   1.395 @@ -1947,6 +1959,18 @@
   1.396      return 0;
   1.397  }
   1.398  
   1.399 +static ID3D11RenderTargetView *
   1.400 +D3D11_GetCurrentRenderTargetView(SDL_Renderer * renderer)
   1.401 +{
   1.402 +    D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata;
   1.403 +    if (data->currentOffscreenRenderTargetView) {
   1.404 +        return data->currentOffscreenRenderTargetView;
   1.405 +    }
   1.406 +    else {
   1.407 +        return data->mainRenderTargetView;
   1.408 +    }
   1.409 +}
   1.410 +
   1.411  static int
   1.412  D3D11_SetDrawState(SDL_Renderer * renderer, const SDL_RenderCommand *cmd, ID3D11PixelShader * shader,
   1.413                       const int numShaderResources, ID3D11ShaderResourceView ** shaderResources,
   1.414 @@ -1954,8 +1978,7 @@
   1.415  
   1.416  {
   1.417      D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->driverdata;
   1.418 -    static const Float4X4 identity = MatrixIdentity();
   1.419 -    const Float4X4 *newmatrix = matrix ? matrix : &identity;
   1.420 +    const Float4X4 *newmatrix = matrix ? matrix : &rendererData->identity;
   1.421      ID3D11RasterizerState *rasterizerState;
   1.422      ID3D11RenderTargetView *renderTargetView = D3D11_GetCurrentRenderTargetView(renderer);
   1.423      ID3D11ShaderResourceView *shaderResource;
   1.424 @@ -1984,7 +2007,7 @@
   1.425                  /* D3D11_GetViewportAlignedD3DRect will have set the SDL error */
   1.426                  return -1;
   1.427              }
   1.428 -            ID3D11DeviceContext_RSSetScissorRects(data->d3dContext, 1, &scissorRect);
   1.429 +            ID3D11DeviceContext_RSSetScissorRects(rendererData->d3dContext, 1, &scissorRect);
   1.430          }
   1.431          rendererData->cliprectDirty = SDL_FALSE;
   1.432      }
   1.433 @@ -2008,11 +2031,10 @@
   1.434              }
   1.435          }
   1.436          if (!blendState) {
   1.437 -            if (D3D11_CreateBlendState(renderer, blendMode)) {
   1.438 -                /* Successfully created the blend state, try again */
   1.439 -                D3D11_RenderSetBlendMode(renderer, blendMode);
   1.440 +            blendState = D3D11_CreateBlendState(renderer, blendMode);
   1.441 +            if (!blendState) {
   1.442 +                return -1;
   1.443              }
   1.444 -            return;
   1.445          }
   1.446      }
   1.447      if (blendState != rendererData->currentBlendState) {
   1.448 @@ -2038,13 +2060,13 @@
   1.449          rendererData->currentSampler = sampler;
   1.450      }
   1.451  
   1.452 -    if (SDL_memcmp(&data->vertexShaderConstantsData.model, newmatrix, sizeof (*newmatrix)) != 0) {
   1.453 -        SDL_memcpy(&data->vertexShaderConstantsData.model, newmatrix, sizeof (*newmatrix));
   1.454 -        ID3D11DeviceContext_UpdateSubresource(data->d3dContext,
   1.455 -            (ID3D11Resource *)data->vertexShaderConstants,
   1.456 +    if (SDL_memcmp(&rendererData->vertexShaderConstantsData.model, newmatrix, sizeof (*newmatrix)) != 0) {
   1.457 +        SDL_memcpy(&rendererData->vertexShaderConstantsData.model, newmatrix, sizeof (*newmatrix));
   1.458 +        ID3D11DeviceContext_UpdateSubresource(rendererData->d3dContext,
   1.459 +            (ID3D11Resource *)rendererData->vertexShaderConstants,
   1.460              0,
   1.461              NULL,
   1.462 -            &data->vertexShaderConstantsData,
   1.463 +            &rendererData->vertexShaderConstantsData,
   1.464              0,
   1.465              0
   1.466              );
   1.467 @@ -2123,16 +2145,16 @@
   1.468  
   1.469      }
   1.470  
   1.471 -    return D3D11_SetDrawState(renderer, cmd,  renderer, rendererData->pixelShaders[SHADER_RGB],
   1.472 +    return D3D11_SetDrawState(renderer, cmd, rendererData->pixelShaders[SHADER_RGB],
   1.473                                1, &textureData->mainTextureResourceView, textureSampler, matrix);
   1.474  }
   1.475  
   1.476  static void
   1.477 -D3D11_DrawPrimitives(SDL_Renderer * renderer, D3D11_PRIMITIVE_TOPOLOGY primitiveTopology, const UINT vertexStart, const UINT vertexCount)
   1.478 +D3D11_DrawPrimitives(SDL_Renderer * renderer, D3D11_PRIMITIVE_TOPOLOGY primitiveTopology, const size_t vertexStart, const size_t vertexCount)
   1.479  {
   1.480      D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
   1.481      ID3D11DeviceContext_IASetPrimitiveTopology(rendererData->d3dContext, primitiveTopology);
   1.482 -    ID3D11DeviceContext_Draw(rendererData->d3dContext, vertexCount, vertexStart);
   1.483 +    ID3D11DeviceContext_Draw(rendererData->d3dContext, (UINT) vertexCount, (UINT) vertexStart);
   1.484  }
   1.485  
   1.486  static int
   1.487 @@ -2161,7 +2183,7 @@
   1.488                  SDL_Rect *viewport = &rendererData->currentViewport;
   1.489                  if (SDL_memcmp(viewport, &cmd->data.viewport.rect, sizeof (SDL_Rect)) != 0) {
   1.490                      SDL_memcpy(viewport, &cmd->data.viewport.rect, sizeof (SDL_Rect));
   1.491 -                    data->drawstate.viewportDirty = SDL_TRUE;
   1.492 +                    rendererData->viewportDirty = SDL_TRUE;
   1.493                  }
   1.494                  break;
   1.495              }
   1.496 @@ -2186,7 +2208,7 @@
   1.497                      (cmd->data.color.b / 255.0f),
   1.498                      (cmd->data.color.a / 255.0f)
   1.499                  };
   1.500 -                ID3D11DeviceContext_ClearRenderTargetView(data->d3dContext, D3D11_GetCurrentRenderTargetView(renderer), colorRGBA);
   1.501 +                ID3D11DeviceContext_ClearRenderTargetView(rendererData->d3dContext, D3D11_GetCurrentRenderTargetView(renderer), colorRGBA);
   1.502                  break;
   1.503              }
   1.504  
   1.505 @@ -2206,7 +2228,7 @@
   1.506                  const VertexPositionColor *verts = (VertexPositionColor *) (((Uint8 *) vertices) + first);
   1.507                  D3D11_SetDrawState(renderer, cmd, rendererData->pixelShaders[SHADER_SOLID], 0, NULL, NULL, NULL);
   1.508                  D3D11_DrawPrimitives(renderer, D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP, start, count);
   1.509 -                if (verts[0].x != verts[count - 1].x || verts[0].y != verts[count - 1].y) {
   1.510 +                if (verts[0].pos.x != verts[count - 1].pos.x || verts[0].pos.y != verts[count - 1].pos.y) {
   1.511                      D3D11_DrawPrimitives(renderer, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST, start + (count-1), 1);
   1.512                  }
   1.513                  break;
   1.514 @@ -2227,7 +2249,7 @@
   1.515              case SDL_RENDERCMD_COPY: {
   1.516                  const size_t first = cmd->data.draw.first;
   1.517                  const size_t start = first / sizeof (VertexPositionColor);
   1.518 -                D3D11_SetCopyState(data, cmd, NULL);
   1.519 +                D3D11_SetCopyState(renderer, cmd, NULL);
   1.520                  D3D11_DrawPrimitives(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, start, 4);
   1.521                  break;
   1.522              }
   1.523 @@ -2236,12 +2258,12 @@
   1.524                  const size_t first = cmd->data.draw.first;
   1.525                  const size_t start = first / sizeof (VertexPositionColor);
   1.526                  const VertexPositionColor *verts = (VertexPositionColor *) (((Uint8 *) vertices) + first);
   1.527 -                const Vertex *transvert = verts + 4;
   1.528 +                const VertexPositionColor *transvert = verts + 4;
   1.529                  const float translatex = transvert->pos.x;
   1.530                  const float translatey = transvert->pos.y;
   1.531                  const float rotation = transvert->pos.z;
   1.532                  const Float4X4 matrix = MatrixMultiply(MatrixRotationZ(rotation), MatrixTranslation(translatex, translatey, 0));
   1.533 -                D3D11_SetCopyState(data, cmd, &matrix);
   1.534 +                D3D11_SetCopyState(renderer, cmd, &matrix);
   1.535                  D3D11_DrawPrimitives(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, start, 4);
   1.536                  break;
   1.537              }
   1.538 @@ -2256,26 +2278,6 @@
   1.539      return 0;
   1.540  }
   1.541  
   1.542 -
   1.543 -static void
   1.544 -D3D11_ReleaseMainRenderTargetView(SDL_Renderer * renderer)
   1.545 -{
   1.546 -    D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata;
   1.547 -    ID3D11DeviceContext_OMSetRenderTargets(data->d3dContext, 0, NULL, NULL);
   1.548 -    SAFE_RELEASE(data->mainRenderTargetView);
   1.549 -}
   1.550 -
   1.551 -static ID3D11RenderTargetView *
   1.552 -D3D11_GetCurrentRenderTargetView(SDL_Renderer * renderer)
   1.553 -{
   1.554 -    D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
   1.555 -    if (data->currentOffscreenRenderTargetView) {
   1.556 -        return data->currentOffscreenRenderTargetView;
   1.557 -    } else {
   1.558 -        return data->mainRenderTargetView;
   1.559 -    }
   1.560 -}
   1.561 -
   1.562  static int
   1.563  D3D11_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   1.564                         Uint32 format, void * pixels, int pitch)
   1.565 @@ -2458,6 +2460,8 @@
   1.566          return NULL;
   1.567      }
   1.568  
   1.569 +    data->identity = MatrixIdentity();
   1.570 +
   1.571      renderer->WindowEvent = D3D11_WindowEvent;
   1.572      renderer->SupportsBlendMode = D3D11_SupportsBlendMode;
   1.573      renderer->CreateTexture = D3D11_CreateTexture;