src/render/direct3d11/SDL_render_d3d11.cpp
author David Ludwig <dludwig@pobox.com>
Tue, 12 Feb 2013 20:49:26 -0500
changeset 8426 9775bb101357
parent 8425 99448fee696f
child 8427 61794d3b1d89
permissions -rw-r--r--
WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     1
/*
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     2
  Simple DirectMedia Layer
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     3
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     4
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     5
  This software is provided 'as-is', without any express or implied
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     7
  arising from the use of this software.
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     8
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    11
  freely, subject to the following restrictions:
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    12
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    14
     claim that you wrote the original software. If you use this software
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    16
     appreciated but is not required.
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    18
     misrepresented as being the original software.
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    20
*/
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    21
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    22
#include "SDL_config.h"
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    23
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    24
#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    25
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    26
extern "C" {
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    27
#include "../../core/windows/SDL_windows.h"
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    28
//#include "SDL_hints.h"
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    29
//#include "SDL_loadso.h"
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    30
#include "SDL_system.h"
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    31
#include "SDL_syswm.h"
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    32
#include "../SDL_sysrender.h"
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    33
//#include "stdio.h"
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    34
}
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    35
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    36
#include <fstream>
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    37
#include <string>
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    38
#include <vector>
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    39
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    40
#include "SDL_render_d3d11_cpp.h"
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    41
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    42
using namespace DirectX;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    43
using namespace Microsoft::WRL;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    44
using namespace std;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    45
8412
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
    46
#ifdef __WINRT__
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
    47
using namespace Windows::Graphics::Display;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
    48
using namespace Windows::UI::Core;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
    49
#endif
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
    50
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    51
/* Direct3D 11.1 renderer implementation */
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    52
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    53
static SDL_Renderer *D3D11_CreateRenderer(SDL_Window * window, Uint32 flags);
8415
91977f5b2135 WinRT: added SDL_WINDOWEVENT_RESIZED support, and moved window-resize-handling code from WinRT rendering code to D3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8414
diff changeset
    54
static void D3D11_WindowEvent(SDL_Renderer * renderer,
91977f5b2135 WinRT: added SDL_WINDOWEVENT_RESIZED support, and moved window-resize-handling code from WinRT rendering code to D3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8414
diff changeset
    55
                            const SDL_WindowEvent *event);
8416
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
    56
static int D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
    57
static int D3D11_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
    58
                             const SDL_Rect * rect, const void *pixels,
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
    59
                             int pitch);
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    60
//static int D3D11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    61
//                           const SDL_Rect * rect, void **pixels, int *pitch);
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    62
//static void D3D11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    63
//static int D3D11_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture);
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    64
static int D3D11_UpdateViewport(SDL_Renderer * renderer);
8416
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
    65
static int D3D11_RenderClear(SDL_Renderer * renderer);
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    66
//static int D3D11_RenderDrawPoints(SDL_Renderer * renderer,
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    67
//                                const SDL_FPoint * points, int count);
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    68
//static int D3D11_RenderDrawLines(SDL_Renderer * renderer,
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    69
//                               const SDL_FPoint * points, int count);
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    70
//static int D3D11_RenderFillRects(SDL_Renderer * renderer,
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    71
//                               const SDL_FRect * rects, int count);
8416
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
    72
static int D3D11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
    73
                            const SDL_Rect * srcrect, const SDL_FRect * dstrect);
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    74
//static int D3D11_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    75
//                          const SDL_Rect * srcrect, const SDL_FRect * dstrect,
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    76
//                          const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip);
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    77
//static int D3D11_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    78
//                                Uint32 format, void * pixels, int pitch);
8401
29ecd2eca4af WinRT: moved a bit more Direct3D 11.1 code into the SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8400
diff changeset
    79
static void D3D11_RenderPresent(SDL_Renderer * renderer);
8416
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
    80
static void D3D11_DestroyTexture(SDL_Renderer * renderer,
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
    81
                                 SDL_Texture * texture);
8413
4ae81c5dc55e WinRT: made the Direct3D 11.1 renderer directly initialize more of itself, rather than deferring to code in the WinRT video driver
David Ludwig <dludwig@pobox.com>
parents: 8412
diff changeset
    82
static void D3D11_DestroyRenderer(SDL_Renderer * renderer);
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    83
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    84
/* Direct3D 11.1 Internal Functions */
8412
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
    85
HRESULT D3D11_CreateDeviceResources(SDL_Renderer * renderer);
8413
4ae81c5dc55e WinRT: made the Direct3D 11.1 renderer directly initialize more of itself, rather than deferring to code in the WinRT video driver
David Ludwig <dludwig@pobox.com>
parents: 8412
diff changeset
    86
HRESULT D3D11_CreateWindowSizeDependentResources(SDL_Renderer * renderer);
8414
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
    87
HRESULT D3D11_UpdateForWindowSizeChange(SDL_Renderer * renderer);
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
    88
HRESULT D3D11_HandleDeviceLost(SDL_Renderer * renderer);
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    89
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    90
extern "C" {
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    91
    SDL_RenderDriver D3D11_RenderDriver = {
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    92
    D3D11_CreateRenderer,
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    93
    {
8416
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
    94
     "direct3d 11.1",
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    95
     (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE),
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    96
     1,
8416
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
    97
     {SDL_PIXELFORMAT_RGB888},
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    98
     0,
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    99
     0}
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   100
    };
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   101
}
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   102
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   103
//typedef struct
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   104
//{
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   105
//    float x, y, z;
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   106
//    DWORD color;
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   107
//    float u, v;
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   108
//} Vertex;
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   109
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   110
SDL_Renderer *
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   111
D3D11_CreateRenderer(SDL_Window * window, Uint32 flags)
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   112
{
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   113
    SDL_Renderer *renderer;
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   114
    D3D11_RenderData *data;
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   115
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   116
    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   117
    if (!renderer) {
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   118
        SDL_OutOfMemory();
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   119
        return NULL;
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   120
    }
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   121
    SDL_zerop(renderer);
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   122
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   123
    data = new D3D11_RenderData;    // Use the C++ 'new' operator to make sure the struct's members initialize using C++ rules
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   124
    if (!data) {
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   125
        SDL_OutOfMemory();
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   126
        return NULL;
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   127
    }
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   128
    data->featureLevel = (D3D_FEATURE_LEVEL) 0;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   129
    data->loadingComplete = false;
8412
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   130
    data->windowSizeInDIPs = XMFLOAT2(0, 0);
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   131
    data->renderTargetSize = XMFLOAT2(0, 0);
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   132
8415
91977f5b2135 WinRT: added SDL_WINDOWEVENT_RESIZED support, and moved window-resize-handling code from WinRT rendering code to D3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8414
diff changeset
   133
    renderer->WindowEvent = D3D11_WindowEvent;
8416
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   134
    renderer->CreateTexture = D3D11_CreateTexture;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   135
    renderer->UpdateTexture = D3D11_UpdateTexture;
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   136
    //renderer->LockTexture = D3D11_LockTexture;
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   137
    //renderer->UnlockTexture = D3D11_UnlockTexture;
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   138
    //renderer->SetRenderTarget = D3D11_SetRenderTarget;
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   139
    renderer->UpdateViewport = D3D11_UpdateViewport;
8416
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   140
    renderer->RenderClear = D3D11_RenderClear;
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   141
    //renderer->RenderDrawPoints = D3D11_RenderDrawPoints;
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   142
    //renderer->RenderDrawLines = D3D11_RenderDrawLines;
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   143
    //renderer->RenderFillRects = D3D11_RenderFillRects;
8416
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   144
    renderer->RenderCopy = D3D11_RenderCopy;
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   145
    //renderer->RenderCopyEx = D3D11_RenderCopyEx;
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   146
    //renderer->RenderReadPixels = D3D11_RenderReadPixels;
8401
29ecd2eca4af WinRT: moved a bit more Direct3D 11.1 code into the SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8400
diff changeset
   147
    renderer->RenderPresent = D3D11_RenderPresent;
8416
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   148
    renderer->DestroyTexture = D3D11_DestroyTexture;
8413
4ae81c5dc55e WinRT: made the Direct3D 11.1 renderer directly initialize more of itself, rather than deferring to code in the WinRT video driver
David Ludwig <dludwig@pobox.com>
parents: 8412
diff changeset
   149
    renderer->DestroyRenderer = D3D11_DestroyRenderer;
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   150
    renderer->info = D3D11_RenderDriver.info;
8413
4ae81c5dc55e WinRT: made the Direct3D 11.1 renderer directly initialize more of itself, rather than deferring to code in the WinRT video driver
David Ludwig <dludwig@pobox.com>
parents: 8412
diff changeset
   151
    renderer->info.flags = SDL_RENDERER_ACCELERATED;
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   152
    renderer->driverdata = data;
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   153
8413
4ae81c5dc55e WinRT: made the Direct3D 11.1 renderer directly initialize more of itself, rather than deferring to code in the WinRT video driver
David Ludwig <dludwig@pobox.com>
parents: 8412
diff changeset
   154
    // HACK: make sure the SDL_Renderer references the SDL_Window data now, in
4ae81c5dc55e WinRT: made the Direct3D 11.1 renderer directly initialize more of itself, rather than deferring to code in the WinRT video driver
David Ludwig <dludwig@pobox.com>
parents: 8412
diff changeset
   155
    // order to give init functions access to the underlying window handle:
4ae81c5dc55e WinRT: made the Direct3D 11.1 renderer directly initialize more of itself, rather than deferring to code in the WinRT video driver
David Ludwig <dludwig@pobox.com>
parents: 8412
diff changeset
   156
    renderer->window = window;
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   157
8413
4ae81c5dc55e WinRT: made the Direct3D 11.1 renderer directly initialize more of itself, rather than deferring to code in the WinRT video driver
David Ludwig <dludwig@pobox.com>
parents: 8412
diff changeset
   158
    /* Initialize Direct3D resources */
4ae81c5dc55e WinRT: made the Direct3D 11.1 renderer directly initialize more of itself, rather than deferring to code in the WinRT video driver
David Ludwig <dludwig@pobox.com>
parents: 8412
diff changeset
   159
    if (FAILED(D3D11_CreateDeviceResources(renderer))) {
4ae81c5dc55e WinRT: made the Direct3D 11.1 renderer directly initialize more of itself, rather than deferring to code in the WinRT video driver
David Ludwig <dludwig@pobox.com>
parents: 8412
diff changeset
   160
        D3D11_DestroyRenderer(renderer);
4ae81c5dc55e WinRT: made the Direct3D 11.1 renderer directly initialize more of itself, rather than deferring to code in the WinRT video driver
David Ludwig <dludwig@pobox.com>
parents: 8412
diff changeset
   161
        return NULL;
4ae81c5dc55e WinRT: made the Direct3D 11.1 renderer directly initialize more of itself, rather than deferring to code in the WinRT video driver
David Ludwig <dludwig@pobox.com>
parents: 8412
diff changeset
   162
    }
4ae81c5dc55e WinRT: made the Direct3D 11.1 renderer directly initialize more of itself, rather than deferring to code in the WinRT video driver
David Ludwig <dludwig@pobox.com>
parents: 8412
diff changeset
   163
    if (FAILED(D3D11_CreateWindowSizeDependentResources(renderer))) {
4ae81c5dc55e WinRT: made the Direct3D 11.1 renderer directly initialize more of itself, rather than deferring to code in the WinRT video driver
David Ludwig <dludwig@pobox.com>
parents: 8412
diff changeset
   164
        D3D11_DestroyRenderer(renderer);
4ae81c5dc55e WinRT: made the Direct3D 11.1 renderer directly initialize more of itself, rather than deferring to code in the WinRT video driver
David Ludwig <dludwig@pobox.com>
parents: 8412
diff changeset
   165
        return NULL;
4ae81c5dc55e WinRT: made the Direct3D 11.1 renderer directly initialize more of itself, rather than deferring to code in the WinRT video driver
David Ludwig <dludwig@pobox.com>
parents: 8412
diff changeset
   166
    }
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   167
8416
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   168
    // TODO, WinRT: fill in renderer->info.texture_formats where appropriate
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   169
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   170
    return renderer;
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   171
}
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   172
8413
4ae81c5dc55e WinRT: made the Direct3D 11.1 renderer directly initialize more of itself, rather than deferring to code in the WinRT video driver
David Ludwig <dludwig@pobox.com>
parents: 8412
diff changeset
   173
static void
4ae81c5dc55e WinRT: made the Direct3D 11.1 renderer directly initialize more of itself, rather than deferring to code in the WinRT video driver
David Ludwig <dludwig@pobox.com>
parents: 8412
diff changeset
   174
D3D11_DestroyRenderer(SDL_Renderer * renderer)
4ae81c5dc55e WinRT: made the Direct3D 11.1 renderer directly initialize more of itself, rather than deferring to code in the WinRT video driver
David Ludwig <dludwig@pobox.com>
parents: 8412
diff changeset
   175
{
4ae81c5dc55e WinRT: made the Direct3D 11.1 renderer directly initialize more of itself, rather than deferring to code in the WinRT video driver
David Ludwig <dludwig@pobox.com>
parents: 8412
diff changeset
   176
    D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
4ae81c5dc55e WinRT: made the Direct3D 11.1 renderer directly initialize more of itself, rather than deferring to code in the WinRT video driver
David Ludwig <dludwig@pobox.com>
parents: 8412
diff changeset
   177
    if (data) {
4ae81c5dc55e WinRT: made the Direct3D 11.1 renderer directly initialize more of itself, rather than deferring to code in the WinRT video driver
David Ludwig <dludwig@pobox.com>
parents: 8412
diff changeset
   178
        delete data;
4ae81c5dc55e WinRT: made the Direct3D 11.1 renderer directly initialize more of itself, rather than deferring to code in the WinRT video driver
David Ludwig <dludwig@pobox.com>
parents: 8412
diff changeset
   179
        data = NULL;
4ae81c5dc55e WinRT: made the Direct3D 11.1 renderer directly initialize more of itself, rather than deferring to code in the WinRT video driver
David Ludwig <dludwig@pobox.com>
parents: 8412
diff changeset
   180
    }
4ae81c5dc55e WinRT: made the Direct3D 11.1 renderer directly initialize more of itself, rather than deferring to code in the WinRT video driver
David Ludwig <dludwig@pobox.com>
parents: 8412
diff changeset
   181
}
4ae81c5dc55e WinRT: made the Direct3D 11.1 renderer directly initialize more of itself, rather than deferring to code in the WinRT video driver
David Ludwig <dludwig@pobox.com>
parents: 8412
diff changeset
   182
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   183
static bool
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   184
D3D11_ReadFileContents(const wstring & fileName, vector<char> & out)
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   185
{
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   186
    ifstream in(fileName, ios::in | ios::binary);
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   187
    if (!in) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   188
        return false;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   189
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   190
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   191
    in.seekg(0, ios::end);
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   192
    out.resize((size_t) in.tellg());
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   193
    in.seekg(0, ios::beg);
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   194
    in.read(&out[0], out.size());
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   195
    return in.good();
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   196
}
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   197
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   198
static bool
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   199
D3D11_ReadShaderContents(const wstring & shaderName, vector<char> & out)
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   200
{
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   201
    wstring fileName;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   202
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   203
#if WINAPI_FAMILY == WINAPI_FAMILY_APP
8420
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8419
diff changeset
   204
    fileName = SDL_WinRTGetFileSystemPath(SDL_WINRT_PATH_INSTALLED_LOCATION);
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   205
    fileName += L"\\SDL_VS2012_WinRT\\";
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   206
#elif WINAPI_FAMILY == WINAPI_PHONE_APP
8420
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8419
diff changeset
   207
    fileName = SDL_WinRTGetFileSystemPath(SDL_WINRT_PATH_INSTALLED_LOCATION);
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   208
    fileName += L"\\";
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   209
#endif
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   210
    // WinRT, TODO: test Direct3D 11.1 shader loading on Win32
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   211
    fileName += shaderName;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   212
    return D3D11_ReadFileContents(fileName, out);
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   213
}
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   214
8414
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   215
// Create resources that depend on the device.
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   216
HRESULT
8412
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   217
D3D11_CreateDeviceResources(SDL_Renderer * renderer)
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   218
{
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   219
    D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   220
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   221
    // This flag adds support for surfaces with a different color channel ordering
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   222
    // than the API default. It is required for compatibility with Direct2D.
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   223
    UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   224
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   225
#if defined(_DEBUG)
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   226
    // If the project is in a debug build, enable debugging via SDK Layers with this flag.
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   227
    creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   228
#endif
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   229
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   230
    // This array defines the set of DirectX hardware feature levels this app will support.
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   231
    // Note the ordering should be preserved.
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   232
    // Don't forget to declare your application's minimum required feature level in its
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   233
    // description.  All applications are assumed to support 9.1 unless otherwise stated.
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   234
    D3D_FEATURE_LEVEL featureLevels[] = 
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   235
    {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   236
        D3D_FEATURE_LEVEL_11_1,
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   237
        D3D_FEATURE_LEVEL_11_0,
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   238
        D3D_FEATURE_LEVEL_10_1,
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   239
        D3D_FEATURE_LEVEL_10_0,
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   240
        D3D_FEATURE_LEVEL_9_3,
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   241
        D3D_FEATURE_LEVEL_9_2,
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   242
        D3D_FEATURE_LEVEL_9_1
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   243
    };
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   244
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   245
    // Create the Direct3D 11 API device object and a corresponding context.
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   246
    ComPtr<ID3D11Device> device;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   247
    ComPtr<ID3D11DeviceContext> context;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   248
    HRESULT result = S_OK;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   249
    result = D3D11CreateDevice(
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   250
        nullptr, // Specify nullptr to use the default adapter.
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   251
        D3D_DRIVER_TYPE_HARDWARE,
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   252
        nullptr,
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   253
        creationFlags, // Set set debug and Direct2D compatibility flags.
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   254
        featureLevels, // List of feature levels this app can support.
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   255
        ARRAYSIZE(featureLevels),
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   256
        D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION for Windows Store apps.
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   257
        &device, // Returns the Direct3D device created.
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   258
        &data->featureLevel, // Returns feature level of device created.
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   259
        &context // Returns the device immediate context.
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   260
        );
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   261
    if (FAILED(result)) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   262
        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   263
        return result;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   264
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   265
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   266
    // Get the Direct3D 11.1 API device and context interfaces.
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   267
    Microsoft::WRL::ComPtr<ID3D11Device1> d3dDevice1;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   268
    result = device.As(&(data->d3dDevice));
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   269
    if (FAILED(result)) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   270
        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   271
        return result;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   272
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   273
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   274
    result = context.As(&data->d3dContext);
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   275
    if (FAILED(result)) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   276
        return result;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   277
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   278
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   279
    // Start loading GPU shaders:
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   280
    vector<char> fileData;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   281
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   282
    //
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   283
    // Load in SDL's one and only vertex shader:
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   284
    //
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   285
    if (!D3D11_ReadShaderContents(L"SimpleVertexShader.cso", fileData)) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   286
        SDL_SetError("Unable to open SDL's vertex shader file.");
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   287
        return E_FAIL;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   288
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   289
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   290
    result = data->d3dDevice->CreateVertexShader(
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   291
        &fileData[0],
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   292
        fileData.size(),
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   293
        nullptr,
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   294
        &data->vertexShader
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   295
        );
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   296
    if (FAILED(result)) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   297
        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   298
        return result;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   299
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   300
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   301
    //
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   302
    // Create an input layout for SDL's vertex shader:
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   303
    //
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   304
    const D3D11_INPUT_ELEMENT_DESC vertexDesc[] = 
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   305
    {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   306
        { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D11_INPUT_PER_VERTEX_DATA, 0 },
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   307
        { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   308
    };
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   309
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   310
    result = data->d3dDevice->CreateInputLayout(
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   311
        vertexDesc,
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   312
        ARRAYSIZE(vertexDesc),
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   313
        &fileData[0],
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   314
        fileData.size(),
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   315
        &data->inputLayout
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   316
        );
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   317
    if (FAILED(result)) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   318
        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   319
        return result;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   320
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   321
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   322
    //
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   323
    // Load in SDL's one and only pixel shader (for now, more are likely to follow):
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   324
    //
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   325
    if (!D3D11_ReadShaderContents(L"SimplePixelShader.cso", fileData)) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   326
        SDL_SetError("Unable to open SDL's pixel shader file.");
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   327
        return E_FAIL;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   328
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   329
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   330
    result = data->d3dDevice->CreatePixelShader(
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   331
        &fileData[0],
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   332
        fileData.size(),
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   333
        nullptr,
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   334
        &data->pixelShader
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   335
        );
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   336
    if (FAILED(result)) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   337
        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   338
        return result;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   339
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   340
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   341
    //
8418
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   342
    // Setup space to hold vertex shader constants:
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   343
    //
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   344
    CD3D11_BUFFER_DESC constantBufferDesc(sizeof(SDL_VertexShaderConstants), D3D11_BIND_CONSTANT_BUFFER);
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   345
    result = data->d3dDevice->CreateBuffer(
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   346
		&constantBufferDesc,
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   347
		nullptr,
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   348
        &data->vertexShaderConstants
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   349
		);
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   350
    if (FAILED(result)) {
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   351
        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   352
        return result;
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   353
    }
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   354
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   355
    //
8425
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   356
    // Make sure that the vertex buffer, if already created, gets freed.
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   357
    // It will be recreated later.
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   358
    //
8425
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   359
    data->vertexBuffer = nullptr;
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   360
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   361
    //
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   362
    // Create a sampler to use when drawing textures:
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   363
    //
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   364
    D3D11_SAMPLER_DESC samplerDesc;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   365
    samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   366
    samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   367
    samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   368
    samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   369
    samplerDesc.MipLODBias = 0.0f;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   370
    samplerDesc.MaxAnisotropy = 1;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   371
    samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   372
    samplerDesc.BorderColor[0] = 0.0f;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   373
    samplerDesc.BorderColor[1] = 0.0f;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   374
    samplerDesc.BorderColor[2] = 0.0f;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   375
    samplerDesc.BorderColor[3] = 0.0f;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   376
    samplerDesc.MinLOD = 0.0f;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   377
    samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   378
    result = data->d3dDevice->CreateSamplerState(
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   379
        &samplerDesc,
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   380
        &data->mainSampler
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   381
        );
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   382
    if (FAILED(result)) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   383
        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   384
        return result;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   385
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   386
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   387
    //
8426
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   388
    // Setup the Direct3D rasterizer
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   389
    //
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   390
    D3D11_RASTERIZER_DESC rasterDesc;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   391
    memset(&rasterDesc, 0, sizeof(rasterDesc));
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   392
	rasterDesc.AntialiasedLineEnable = false;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   393
	rasterDesc.CullMode = D3D11_CULL_NONE;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   394
	rasterDesc.DepthBias = 0;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   395
	rasterDesc.DepthBiasClamp = 0.0f;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   396
	rasterDesc.DepthClipEnable = true;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   397
	rasterDesc.FillMode = D3D11_FILL_SOLID;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   398
	rasterDesc.FrontCounterClockwise = false;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   399
	rasterDesc.MultisampleEnable = false;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   400
	rasterDesc.ScissorEnable = false;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   401
	rasterDesc.SlopeScaledDepthBias = 0.0f;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   402
	result = data->d3dDevice->CreateRasterizerState(&rasterDesc, &data->mainRasterizer);
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   403
	if (FAILED(result)) {
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   404
        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   405
        return result;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   406
    }
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   407
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   408
    //
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   409
    // All done!
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   410
    //
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   411
    data->loadingComplete = true;       // This variable can probably be factored-out
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   412
    return S_OK;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   413
}
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   414
8412
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   415
#ifdef __WINRT__
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   416
8415
91977f5b2135 WinRT: added SDL_WINDOWEVENT_RESIZED support, and moved window-resize-handling code from WinRT rendering code to D3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8414
diff changeset
   417
static CoreWindow ^
8412
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   418
D3D11_GetCoreWindowFromSDLRenderer(SDL_Renderer * renderer)
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   419
{
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   420
    SDL_Window * sdlWindow = renderer->window;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   421
    if ( ! renderer->window ) {
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   422
        return nullptr;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   423
    }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   424
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   425
    SDL_SysWMinfo sdlWindowInfo;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   426
    SDL_VERSION(&sdlWindowInfo.version);
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   427
    if ( ! SDL_GetWindowWMInfo(sdlWindow, &sdlWindowInfo) ) {
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   428
        return nullptr;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   429
    }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   430
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   431
    if (sdlWindowInfo.subsystem != SDL_SYSWM_WINDOWSRT) {
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   432
        return nullptr;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   433
    }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   434
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   435
    CoreWindow ^* coreWindowPointer = (CoreWindow ^*) sdlWindowInfo.info.winrt.window;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   436
    if ( ! coreWindowPointer ) {
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   437
        return nullptr;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   438
    }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   439
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   440
    return *coreWindowPointer;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   441
}
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   442
8414
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   443
// Method to convert a length in device-independent pixels (DIPs) to a length in physical pixels.
8412
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   444
static float
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   445
D3D11_ConvertDipsToPixels(float dips)
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   446
{
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   447
    static const float dipsPerInch = 96.0f;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   448
    return floor(dips * DisplayProperties::LogicalDpi / dipsPerInch + 0.5f); // Round to nearest integer.
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   449
}
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   450
#endif
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   451
8414
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   452
// Initialize all resources that change when the window's size changes.
8412
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   453
// WinRT, TODO: get D3D11_CreateWindowSizeDependentResources working on Win32
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   454
HRESULT
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   455
D3D11_CreateWindowSizeDependentResources(SDL_Renderer * renderer)
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   456
{
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   457
    D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   458
    HRESULT result = S_OK;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   459
    Windows::UI::Core::CoreWindow ^ coreWindow = D3D11_GetCoreWindowFromSDLRenderer(renderer);
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   460
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   461
    // Store the window bounds so the next time we get a SizeChanged event we can
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   462
    // avoid rebuilding everything if the size is identical.
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   463
    data->windowSizeInDIPs.x = coreWindow->Bounds.Width;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   464
    data->windowSizeInDIPs.y = coreWindow->Bounds.Height;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   465
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   466
    // Calculate the necessary swap chain and render target size in pixels.
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   467
    float windowWidth = D3D11_ConvertDipsToPixels(data->windowSizeInDIPs.x);
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   468
    float windowHeight = D3D11_ConvertDipsToPixels(data->windowSizeInDIPs.y);
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   469
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   470
    // The width and height of the swap chain must be based on the window's
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   471
    // landscape-oriented width and height. If the window is in a portrait
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   472
    // orientation, the dimensions must be reversed.
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   473
    data->orientation = DisplayProperties::CurrentOrientation;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   474
    bool swapDimensions =
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   475
        data->orientation == DisplayOrientations::Portrait ||
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   476
        data->orientation == DisplayOrientations::PortraitFlipped;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   477
    data->renderTargetSize.x = swapDimensions ? windowHeight : windowWidth;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   478
    data->renderTargetSize.y = swapDimensions ? windowWidth : windowHeight;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   479
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   480
    if(data->swapChain != nullptr)
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   481
    {
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   482
        // If the swap chain already exists, resize it.
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   483
        result = data->swapChain->ResizeBuffers(
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   484
            2, // Double-buffered swap chain.
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   485
            static_cast<UINT>(data->renderTargetSize.x),
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   486
            static_cast<UINT>(data->renderTargetSize.y),
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   487
            DXGI_FORMAT_B8G8R8A8_UNORM,
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   488
            0
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   489
            );
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   490
        if (FAILED(result)) {
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   491
            WIN_SetErrorFromHRESULT(__FUNCTION__, result);
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   492
            return result;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   493
        }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   494
    }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   495
    else
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   496
    {
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   497
        // Otherwise, create a new one using the same adapter as the existing Direct3D device.
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   498
        DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {0};
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   499
        swapChainDesc.Width = static_cast<UINT>(data->renderTargetSize.x); // Match the size of the window.
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   500
        swapChainDesc.Height = static_cast<UINT>(data->renderTargetSize.y);
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   501
        swapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; // This is the most common swap chain format.
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   502
        swapChainDesc.Stereo = false;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   503
        swapChainDesc.SampleDesc.Count = 1; // Don't use multi-sampling.
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   504
        swapChainDesc.SampleDesc.Quality = 0;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   505
        swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   506
        swapChainDesc.BufferCount = 2; // Use double-buffering to minimize latency.
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   507
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   508
        swapChainDesc.Scaling = DXGI_SCALING_STRETCH; // On phone, only stretch and aspect-ratio stretch scaling are allowed.
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   509
        swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; // On phone, no swap effects are supported.
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   510
#else
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   511
        swapChainDesc.Scaling = DXGI_SCALING_NONE;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   512
        swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; // All Windows Store apps must use this SwapEffect.
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   513
#endif
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   514
        swapChainDesc.Flags = 0;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   515
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   516
        ComPtr<IDXGIDevice1>  dxgiDevice;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   517
        result = data->d3dDevice.As(&dxgiDevice);
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   518
        if (FAILED(result)) {
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   519
            WIN_SetErrorFromHRESULT(__FUNCTION__, result);
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   520
            return result;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   521
        }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   522
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   523
        ComPtr<IDXGIAdapter> dxgiAdapter;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   524
        result = dxgiDevice->GetAdapter(&dxgiAdapter);
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   525
        if (FAILED(result)) {
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   526
            WIN_SetErrorFromHRESULT(__FUNCTION__, result);
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   527
            return result;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   528
        }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   529
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   530
        ComPtr<IDXGIFactory2> dxgiFactory;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   531
        result = dxgiAdapter->GetParent(
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   532
            __uuidof(IDXGIFactory2), 
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   533
            &dxgiFactory
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   534
            );
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   535
        if (FAILED(result)) {
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   536
            WIN_SetErrorFromHRESULT(__FUNCTION__, result);
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   537
            return result;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   538
        }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   539
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   540
        result = dxgiFactory->CreateSwapChainForCoreWindow(
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   541
            data->d3dDevice.Get(),
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   542
            reinterpret_cast<IUnknown*>(coreWindow),
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   543
            &swapChainDesc,
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   544
            nullptr, // Allow on all displays.
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   545
            &data->swapChain
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   546
            );
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   547
        if (FAILED(result)) {
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   548
            WIN_SetErrorFromHRESULT(__FUNCTION__, result);
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   549
            return result;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   550
        }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   551
            
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   552
        // Ensure that DXGI does not queue more than one frame at a time. This both reduces latency and
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   553
        // ensures that the application will only render after each VSync, minimizing power consumption.
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   554
        result = dxgiDevice->SetMaximumFrameLatency(1);
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   555
        if (FAILED(result)) {
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   556
            WIN_SetErrorFromHRESULT(__FUNCTION__, result);
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   557
            return result;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   558
        }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   559
    }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   560
    
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   561
    // Set the proper orientation for the swap chain, and generate the
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   562
    // 3D matrix transformation for rendering to the rotated swap chain.
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   563
    DXGI_MODE_ROTATION rotation = DXGI_MODE_ROTATION_UNSPECIFIED;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   564
    switch (data->orientation)
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   565
    {
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   566
        case DisplayOrientations::Landscape:
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   567
            rotation = DXGI_MODE_ROTATION_IDENTITY;
8418
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   568
            data->vertexShaderConstantsData.projection = XMFLOAT4X4( // 0-degree Z-rotation
8412
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   569
                1.0f, 0.0f, 0.0f, 0.0f,
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   570
                0.0f, 1.0f, 0.0f, 0.0f,
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   571
                0.0f, 0.0f, 1.0f, 0.0f,
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   572
                0.0f, 0.0f, 0.0f, 1.0f
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   573
                );
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   574
            break;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   575
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   576
        case DisplayOrientations::Portrait:
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   577
            rotation = DXGI_MODE_ROTATION_ROTATE270;
8418
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   578
            data->vertexShaderConstantsData.projection = XMFLOAT4X4( // 270-degree Z-rotation
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   579
                0.0f, -1.0f, 0.0f, 0.0f,
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   580
                1.0f, 0.0f, 0.0f, 0.0f,
8412
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   581
                0.0f, 0.0f, 1.0f, 0.0f,
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   582
                0.0f, 0.0f, 0.0f, 1.0f
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   583
                );
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   584
            break;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   585
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   586
        case DisplayOrientations::LandscapeFlipped:
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   587
            rotation = DXGI_MODE_ROTATION_ROTATE180;
8418
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   588
            data->vertexShaderConstantsData.projection = XMFLOAT4X4( // 180-degree Z-rotation
8412
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   589
                -1.0f, 0.0f, 0.0f, 0.0f,
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   590
                0.0f, -1.0f, 0.0f, 0.0f,
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   591
                0.0f, 0.0f, 1.0f, 0.0f,
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   592
                0.0f, 0.0f, 0.0f, 1.0f
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   593
                );
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   594
            break;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   595
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   596
        case DisplayOrientations::PortraitFlipped:
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   597
            rotation = DXGI_MODE_ROTATION_ROTATE90;
8418
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   598
            data->vertexShaderConstantsData.projection = XMFLOAT4X4( // 90-degree Z-rotation
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   599
                0.0f, 1.0f, 0.0f, 0.0f,
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   600
                -1.0f, 0.0f, 0.0f, 0.0f,
8412
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   601
                0.0f, 0.0f, 1.0f, 0.0f,
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   602
                0.0f, 0.0f, 0.0f, 1.0f
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   603
                );
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   604
            break;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   605
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   606
        default:
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   607
            throw ref new Platform::FailureException();
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   608
    }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   609
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   610
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   611
    // TODO, WinRT: Windows Phone does not have the IDXGISwapChain1::SetRotation method.  Check if an alternative is available, or needed.
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   612
    result = data->swapChain->SetRotation(rotation);
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   613
    if (FAILED(result)) {
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   614
        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   615
        return result;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   616
    }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   617
#endif
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   618
8426
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   619
    //
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   620
    // Update the view matrix
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   621
    //
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   622
    XMStoreFloat4x4(&data->vertexShaderConstantsData.view,  // (4)
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   623
        XMMatrixMultiply(
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   624
            XMMatrixScaling(2.0f / windowWidth, 2.0f / windowHeight, 1.0f),
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   625
            XMMatrixMultiply(
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   626
                XMMatrixTranslation(-1, -1, 0),
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   627
                XMMatrixRotationX(XM_PI)
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   628
                )));
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   629
8412
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   630
    // Create a render target view of the swap chain back buffer.
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   631
    ComPtr<ID3D11Texture2D> backBuffer;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   632
    result = data->swapChain->GetBuffer(
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   633
        0,
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   634
        __uuidof(ID3D11Texture2D),
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   635
        &backBuffer
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   636
        );
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   637
    if (FAILED(result)) {
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   638
        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   639
        return result;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   640
    }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   641
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   642
    result = data->d3dDevice->CreateRenderTargetView(
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   643
        backBuffer.Get(),
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   644
        nullptr,
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   645
        &data->renderTargetView
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   646
        );
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   647
    if (FAILED(result)) {
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   648
        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   649
        return result;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   650
    }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   651
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   652
    // Create a depth stencil view.
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   653
    CD3D11_TEXTURE2D_DESC depthStencilDesc(
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   654
        DXGI_FORMAT_D24_UNORM_S8_UINT, 
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   655
        static_cast<UINT>(data->renderTargetSize.x),
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   656
        static_cast<UINT>(data->renderTargetSize.y),
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   657
        1,
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   658
        1,
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   659
        D3D11_BIND_DEPTH_STENCIL
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   660
        );
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   661
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   662
    ComPtr<ID3D11Texture2D> depthStencil;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   663
    result = data->d3dDevice->CreateTexture2D(
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   664
        &depthStencilDesc,
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   665
        nullptr,
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   666
        &depthStencil
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   667
        );
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   668
    if (FAILED(result)) {
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   669
        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   670
        return result;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   671
    }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   672
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   673
    // Set the rendering viewport to target the entire window.
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   674
    CD3D11_VIEWPORT viewport(
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   675
        0.0f,
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   676
        0.0f,
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   677
        data->renderTargetSize.x,
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   678
        data->renderTargetSize.y
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   679
        );
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   680
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   681
    data->d3dContext->RSSetViewports(1, &viewport);
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   682
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   683
    return S_OK;
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   684
}
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   685
8415
91977f5b2135 WinRT: added SDL_WINDOWEVENT_RESIZED support, and moved window-resize-handling code from WinRT rendering code to D3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8414
diff changeset
   686
// This method is called when the window's size changes.
8414
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   687
HRESULT
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   688
D3D11_UpdateForWindowSizeChange(SDL_Renderer * renderer)
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   689
{
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   690
    D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   691
    HRESULT result = S_OK;
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   692
    Windows::UI::Core::CoreWindow ^ coreWindow = D3D11_GetCoreWindowFromSDLRenderer(renderer);
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   693
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   694
    if (coreWindow->Bounds.Width  != data->windowSizeInDIPs.x ||
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   695
        coreWindow->Bounds.Height != data->windowSizeInDIPs.y ||
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   696
        data->orientation != DisplayProperties::CurrentOrientation)
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   697
    {
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   698
        ID3D11RenderTargetView* nullViews[] = {nullptr};
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   699
        data->d3dContext->OMSetRenderTargets(ARRAYSIZE(nullViews), nullViews, nullptr);
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   700
        data->renderTargetView = nullptr;
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   701
        data->d3dContext->Flush();
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   702
        result = D3D11_CreateWindowSizeDependentResources(renderer);
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   703
        if (FAILED(result)) {
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   704
            WIN_SetErrorFromHRESULT(__FUNCTION__, result);
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   705
            return result;
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   706
        }
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   707
    }
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   708
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   709
    return S_OK;
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   710
}
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   711
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   712
HRESULT
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   713
D3D11_HandleDeviceLost(SDL_Renderer * renderer)
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   714
{
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   715
    D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   716
    HRESULT result = S_OK;
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   717
8415
91977f5b2135 WinRT: added SDL_WINDOWEVENT_RESIZED support, and moved window-resize-handling code from WinRT rendering code to D3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8414
diff changeset
   718
    // Reset these member variables to ensure that D3D11_UpdateForWindowSizeChange recreates all resources.
8414
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   719
    data->windowSizeInDIPs.x = 0;
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   720
    data->windowSizeInDIPs.y = 0;
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   721
    data->swapChain = nullptr;
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   722
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   723
    result = D3D11_CreateDeviceResources(renderer);
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   724
    if (FAILED(result)) {
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   725
        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   726
        return result;
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   727
    }
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   728
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   729
    result = D3D11_UpdateForWindowSizeChange(renderer);
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   730
    if (FAILED(result)) {
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   731
        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   732
        return result;
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   733
    }
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   734
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   735
    return S_OK;
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   736
}
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   737
8415
91977f5b2135 WinRT: added SDL_WINDOWEVENT_RESIZED support, and moved window-resize-handling code from WinRT rendering code to D3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8414
diff changeset
   738
static void
91977f5b2135 WinRT: added SDL_WINDOWEVENT_RESIZED support, and moved window-resize-handling code from WinRT rendering code to D3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8414
diff changeset
   739
D3D11_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
91977f5b2135 WinRT: added SDL_WINDOWEVENT_RESIZED support, and moved window-resize-handling code from WinRT rendering code to D3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8414
diff changeset
   740
{
91977f5b2135 WinRT: added SDL_WINDOWEVENT_RESIZED support, and moved window-resize-handling code from WinRT rendering code to D3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8414
diff changeset
   741
    //D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
91977f5b2135 WinRT: added SDL_WINDOWEVENT_RESIZED support, and moved window-resize-handling code from WinRT rendering code to D3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8414
diff changeset
   742
91977f5b2135 WinRT: added SDL_WINDOWEVENT_RESIZED support, and moved window-resize-handling code from WinRT rendering code to D3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8414
diff changeset
   743
    if (event->event == SDL_WINDOWEVENT_RESIZED) {
91977f5b2135 WinRT: added SDL_WINDOWEVENT_RESIZED support, and moved window-resize-handling code from WinRT rendering code to D3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8414
diff changeset
   744
        D3D11_UpdateForWindowSizeChange(renderer);
91977f5b2135 WinRT: added SDL_WINDOWEVENT_RESIZED support, and moved window-resize-handling code from WinRT rendering code to D3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8414
diff changeset
   745
    }
91977f5b2135 WinRT: added SDL_WINDOWEVENT_RESIZED support, and moved window-resize-handling code from WinRT rendering code to D3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8414
diff changeset
   746
}
91977f5b2135 WinRT: added SDL_WINDOWEVENT_RESIZED support, and moved window-resize-handling code from WinRT rendering code to D3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8414
diff changeset
   747
8416
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   748
static int
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   749
D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   750
{
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   751
    D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   752
    D3D11_TextureData *textureData;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   753
    HRESULT result;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   754
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   755
    textureData = new D3D11_TextureData;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   756
    if (!textureData) {
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   757
        SDL_OutOfMemory();
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   758
        return -1;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   759
    }
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   760
    textureData->pixelFormat = SDL_AllocFormat(texture->format);
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   761
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   762
    texture->driverdata = textureData;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   763
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   764
    const int pixelSizeInBytes = textureData->pixelFormat->BytesPerPixel;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   765
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   766
    D3D11_TEXTURE2D_DESC textureDesc = {0};
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   767
    textureDesc.Width = texture->w;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   768
    textureDesc.Height = texture->h;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   769
    textureDesc.MipLevels = 1;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   770
    textureDesc.ArraySize = 1;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   771
    textureDesc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   772
    textureDesc.SampleDesc.Count = 1;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   773
    textureDesc.SampleDesc.Quality = 0;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   774
    textureDesc.Usage = D3D11_USAGE_DYNAMIC;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   775
    textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   776
    textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   777
    textureDesc.MiscFlags = 0;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   778
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   779
    const int numPixels = textureDesc.Width * textureDesc.Height;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   780
    std::vector<uint8> initialTexturePixels(numPixels * pixelSizeInBytes, 0x00);
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   781
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   782
    // Fill the texture with a non-black color, for debugging purposes:
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   783
    //for (int i = 0; i < (numPixels * pixelSizeInBytes); i += pixelSizeInBytes) {
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   784
    //    initialTexturePixels[i+0] = 0xff;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   785
    //    initialTexturePixels[i+1] = 0xff;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   786
    //    initialTexturePixels[i+2] = 0x00;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   787
    //    initialTexturePixels[i+3] = 0xff;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   788
    //}
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   789
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   790
    D3D11_SUBRESOURCE_DATA initialTextureData = {0};
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   791
    initialTextureData.pSysMem = (void *)&(initialTexturePixels[0]);
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   792
    initialTextureData.SysMemPitch = textureDesc.Width * pixelSizeInBytes;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   793
    initialTextureData.SysMemSlicePitch = numPixels * pixelSizeInBytes;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   794
    result = rendererData->d3dDevice->CreateTexture2D(
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   795
        &textureDesc,
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   796
        &initialTextureData,
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   797
        &textureData->mainTexture
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   798
        );
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   799
    if (FAILED(result)) {
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   800
        D3D11_DestroyTexture(renderer, texture);
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   801
        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   802
        return -1;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   803
    }
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   804
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   805
    D3D11_SHADER_RESOURCE_VIEW_DESC resourceViewDesc;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   806
    resourceViewDesc.Format = textureDesc.Format;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   807
    resourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   808
    resourceViewDesc.Texture2D.MostDetailedMip = 0;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   809
    resourceViewDesc.Texture2D.MipLevels = textureDesc.MipLevels;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   810
    result = rendererData->d3dDevice->CreateShaderResourceView(
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   811
        textureData->mainTexture.Get(),
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   812
        &resourceViewDesc,
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   813
        &textureData->mainTextureResourceView
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   814
        );
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   815
    if (FAILED(result)) {
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   816
        D3D11_DestroyTexture(renderer, texture);
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   817
        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   818
        return -1;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   819
    }
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   820
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   821
    return 0;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   822
}
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   823
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   824
static void
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   825
D3D11_DestroyTexture(SDL_Renderer * renderer,
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   826
                     SDL_Texture * texture)
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   827
{
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   828
    D3D11_TextureData *textureData = (D3D11_TextureData *) texture->driverdata;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   829
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   830
    if (textureData) {
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   831
        if (textureData->pixelFormat) {
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   832
            SDL_FreeFormat(textureData->pixelFormat);
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   833
            textureData->pixelFormat = NULL;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   834
        }
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   835
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   836
        delete textureData;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   837
        texture->driverdata = NULL;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   838
    }
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   839
}
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   840
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   841
static int
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   842
D3D11_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   843
                    const SDL_Rect * rect, const void *pixels,
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   844
                    int pitch)
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   845
{
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   846
    D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   847
    D3D11_TextureData *textureData = (D3D11_TextureData *) texture->driverdata;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   848
    HRESULT result = S_OK;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   849
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   850
    D3D11_MAPPED_SUBRESOURCE textureMemory = {0};
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   851
    result = rendererData->d3dContext->Map(
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   852
        textureData->mainTexture.Get(),
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   853
        0,
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   854
        D3D11_MAP_WRITE_DISCARD,
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   855
        0,
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   856
        &textureMemory
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   857
        );
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   858
    if (FAILED(result)) {
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   859
        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   860
        return -1;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   861
    }
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   862
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   863
    // Copy pixel data to the locked texture's memory:
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   864
    for (int y = 0; y < rect->h; ++y) {
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   865
        memcpy(
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   866
            ((Uint8 *)textureMemory.pData) + (textureMemory.RowPitch * y),
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   867
            ((Uint8 *)pixels) + (pitch * y),
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   868
            pitch
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   869
            );
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   870
    }
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   871
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   872
    // Clean up a bit, then commit the texture's memory back to Direct3D:
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   873
    rendererData->d3dContext->Unmap(
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   874
        textureData->mainTexture.Get(),
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   875
        0);
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   876
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   877
    return 0;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   878
}
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   879
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   880
static int
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   881
D3D11_UpdateViewport(SDL_Renderer * renderer)
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   882
{
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   883
    return 0;
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   884
}
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   885
8416
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   886
static int
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   887
D3D11_RenderClear(SDL_Renderer * renderer)
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   888
{
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   889
    D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   890
    const float colorRGBA[] = {
8423
61f9a3eb6bc8 WinRT: made SDL_RenderClear display the correct color via Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8420
diff changeset
   891
        (renderer->r / 255.0f),
61f9a3eb6bc8 WinRT: made SDL_RenderClear display the correct color via Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8420
diff changeset
   892
        (renderer->g / 255.0f),
61f9a3eb6bc8 WinRT: made SDL_RenderClear display the correct color via Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8420
diff changeset
   893
        (renderer->b / 255.0f),
61f9a3eb6bc8 WinRT: made SDL_RenderClear display the correct color via Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8420
diff changeset
   894
        (renderer->a / 255.0f)
8416
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   895
    };
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   896
    data->d3dContext->ClearRenderTargetView(
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   897
        data->renderTargetView.Get(),
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   898
        colorRGBA
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   899
        );
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   900
    return 0;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   901
}
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   902
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   903
static int D3D11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   904
                            const SDL_Rect * srcrect, const SDL_FRect * dstrect)
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   905
{
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   906
    D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   907
    D3D11_TextureData *textureData = (D3D11_TextureData *) texture->driverdata;
8425
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   908
    HRESULT result = S_OK;
8416
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   909
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   910
    rendererData->d3dContext->OMSetRenderTargets(
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   911
        1,
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   912
        rendererData->renderTargetView.GetAddressOf(),
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   913
        nullptr
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   914
        );
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   915
8418
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   916
    rendererData->d3dContext->UpdateSubresource(
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   917
        rendererData->vertexShaderConstants.Get(),
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   918
		0,
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   919
		NULL,
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   920
		&rendererData->vertexShaderConstantsData,
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   921
		0,
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   922
		0
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   923
		);
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   924
8425
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   925
    //
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   926
    // Create or update the vertex buffer:
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   927
    //
8426
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   928
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   929
    // WinRT, TODO: get srcrect working in tandem with SDL_RenderCopy, etc.
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   930
    //SDL_FRect fSrcRect;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   931
    //fSrcRect.x = (float)srcrect->x;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   932
    //fSrcRect.y = (float)srcrect->y;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   933
    //fSrcRect.w = (float)srcrect->w;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   934
    //fSrcRect.h = (float)srcrect->h;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   935
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   936
    VertexPositionColor vertices[] =
8425
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   937
    {
8426
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   938
        {XMFLOAT3(dstrect->x, dstrect->y, 0.0f),                           XMFLOAT2(0.0f, 0.0f)},
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   939
        {XMFLOAT3(dstrect->x, dstrect->y + dstrect->h, 0.0f),              XMFLOAT2(0.0f, 1.0f)},
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   940
        {XMFLOAT3(dstrect->x + dstrect->h, dstrect->y, 0.0f),              XMFLOAT2(1.0f, 0.0f)},
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   941
        {XMFLOAT3(dstrect->x + dstrect->h, dstrect->y + dstrect->h, 0.0f), XMFLOAT2(1.0f, 1.0f)},
8425
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   942
    };
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   943
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   944
    if (rendererData->vertexBuffer) {
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   945
        rendererData->d3dContext->UpdateSubresource(rendererData->vertexBuffer.Get(), 0, NULL, vertices, sizeof(vertices), 0);
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   946
    } else {
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   947
        D3D11_SUBRESOURCE_DATA vertexBufferData = {0};
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   948
        vertexBufferData.pSysMem = vertices;
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   949
        vertexBufferData.SysMemPitch = 0;
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   950
        vertexBufferData.SysMemSlicePitch = 0;
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   951
        CD3D11_BUFFER_DESC vertexBufferDesc(sizeof(vertices), D3D11_BIND_VERTEX_BUFFER);
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   952
        result = rendererData->d3dDevice->CreateBuffer(
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   953
            &vertexBufferDesc,
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   954
            &vertexBufferData,
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   955
            &rendererData->vertexBuffer
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   956
            );
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   957
        if (FAILED(result)) {
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   958
            WIN_SetErrorFromHRESULT(__FUNCTION__, result);
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   959
            return -1;
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   960
        }
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   961
    }
99448fee696f WinRT: made d3d 11.1 vertex buffers get created, and updated, when a render op is invoked
David Ludwig <dludwig@pobox.com>
parents: 8423
diff changeset
   962
8416
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   963
    UINT stride = sizeof(VertexPositionColor);
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   964
    UINT offset = 0;
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   965
    rendererData->d3dContext->IASetVertexBuffers(
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   966
        0,
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   967
        1,
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   968
        rendererData->vertexBuffer.GetAddressOf(),
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   969
        &stride,
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   970
        &offset
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   971
        );
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   972
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   973
    rendererData->d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   974
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   975
    rendererData->d3dContext->IASetInputLayout(rendererData->inputLayout.Get());
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   976
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   977
    rendererData->d3dContext->VSSetShader(
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   978
        rendererData->vertexShader.Get(),
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   979
        nullptr,
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   980
        0
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   981
        );
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   982
8418
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   983
    rendererData->d3dContext->VSSetConstantBuffers(
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   984
		0,
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   985
		1,
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   986
        rendererData->vertexShaderConstants.GetAddressOf()
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   987
		);
5230bba62cf2 WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
David Ludwig <dludwig@pobox.com>
parents: 8416
diff changeset
   988
8416
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   989
    rendererData->d3dContext->PSSetShader(
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   990
        rendererData->pixelShader.Get(),