src/render/direct3d11/SDL_render_d3d11.cpp
author David Ludwig <dludwig@pobox.com>
Sun, 17 Feb 2013 11:09:07 -0500
changeset 8432 929e53386278
parent 8431 2078dc4f4378
child 8433 3017f87e4479
permissions -rw-r--r--
WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
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);
8429
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
    70
static int D3D11_RenderFillRects(SDL_Renderer * renderer,
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
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;
8429
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
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
8429
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   215
static HRESULT
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   216
D3D11_LoadPixelShader(SDL_Renderer * renderer,
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   217
                      const wstring & shaderName,
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   218
                      ID3D11PixelShader ** shaderOutput)
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   219
{
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   220
    D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   221
    HRESULT result = S_OK;
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   222
    vector<char> fileData;
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   223
    
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   224
    if (!D3D11_ReadShaderContents(shaderName, fileData)) {
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   225
        SDL_SetError("Unable to open SDL's pixel shader file.");
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   226
        return E_FAIL;
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   227
    }
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   228
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   229
    result = data->d3dDevice->CreatePixelShader(
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   230
        &fileData[0],
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   231
        fileData.size(),
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   232
        nullptr,
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   233
        shaderOutput
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   234
        );
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   235
    if (FAILED(result)) {
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   236
        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   237
        return result;
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   238
    }
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   239
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   240
    return S_OK;
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   241
}
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   242
8431
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   243
static HRESULT
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   244
D3D11_CreateBlendMode(SDL_Renderer * renderer,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   245
                      BOOL enableBlending,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   246
                      D3D11_BLEND srcBlend,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   247
                      D3D11_BLEND destBlend,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   248
                      ID3D11BlendState ** blendStateOutput)
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   249
{
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   250
    D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   251
    HRESULT result = S_OK;
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   252
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   253
    D3D11_BLEND_DESC blendDesc;
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   254
    memset(&blendDesc, 0, sizeof(blendDesc));
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   255
    blendDesc.AlphaToCoverageEnable = FALSE;
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   256
    blendDesc.IndependentBlendEnable = FALSE;
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   257
    blendDesc.RenderTarget[0].BlendEnable = enableBlending;
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   258
    blendDesc.RenderTarget[0].SrcBlend = srcBlend;
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   259
    blendDesc.RenderTarget[0].DestBlend = destBlend;
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   260
    blendDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   261
    blendDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   262
    blendDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   263
    blendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   264
    blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   265
    result = data->d3dDevice->CreateBlendState(&blendDesc, blendStateOutput);
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   266
    if (FAILED(result)) {
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   267
        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   268
        return result;
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   269
    }
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   270
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   271
    return S_OK;
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   272
}
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   273
8414
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   274
// 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
   275
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
   276
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
   277
{
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   278
    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
   279
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   280
    // 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
   281
    // 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
   282
    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
   283
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   284
#if defined(_DEBUG)
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   285
    // 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
   286
    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
   287
#endif
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
    // 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
   290
    // 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
   291
    // 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
   292
    // 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
   293
    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
   294
    {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   295
        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
   296
        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
   297
        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
   298
        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
   299
        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
   300
        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
   301
        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
   302
    };
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
    // 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
   305
    ComPtr<ID3D11Device> device;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   306
    ComPtr<ID3D11DeviceContext> context;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   307
    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
   308
    result = D3D11CreateDevice(
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   309
        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
   310
        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
   311
        nullptr,
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   312
        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
   313
        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
   314
        ARRAYSIZE(featureLevels),
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   315
        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
   316
        &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
   317
        &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
   318
        &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
   319
        );
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   320
    if (FAILED(result)) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   321
        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
   322
        return result;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   323
    }
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
    // 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
   326
    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
   327
    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
   328
    if (FAILED(result)) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   329
        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
   330
        return result;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   331
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   332
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   333
    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
   334
    if (FAILED(result)) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   335
        return result;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   336
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   337
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   338
    //
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   339
    // 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
   340
    //
8429
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   341
    vector<char> fileData;
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   342
    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
   343
        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
   344
        return E_FAIL;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   345
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   346
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   347
    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
   348
        &fileData[0],
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   349
        fileData.size(),
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   350
        nullptr,
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   351
        &data->vertexShader
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   352
        );
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   353
    if (FAILED(result)) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   354
        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
   355
        return result;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   356
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   357
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   358
    //
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   359
    // 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
   360
    //
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   361
    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
   362
    {
8429
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   363
        { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   364
        { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
8429
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   365
        { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0 },
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   366
    };
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   367
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   368
    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
   369
        vertexDesc,
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   370
        ARRAYSIZE(vertexDesc),
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   371
        &fileData[0],
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   372
        fileData.size(),
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   373
        &data->inputLayout
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   374
        );
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   375
    if (FAILED(result)) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   376
        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
   377
        return result;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   378
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   379
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   380
    //
8429
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   381
    // Load in SDL's pixel shaders
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   382
    //
8429
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   383
    result = D3D11_LoadPixelShader(renderer, L"SDL_D3D11_PixelShader_TextureCopy.cso", &data->texturePixelShader);
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   384
    if (FAILED(result)) {
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   385
        // D3D11_LoadPixelShader will have aleady set the SDL error
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   386
        return result;
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   387
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   388
8429
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   389
    result = D3D11_LoadPixelShader(renderer, L"SDL_D3D11_PixelShader_FixedColor.cso", &data->colorPixelShader);
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   390
    if (FAILED(result)) {
8429
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   391
        // D3D11_LoadPixelShader will have aleady set the SDL error
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   392
        return result;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   393
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   394
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   395
    //
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
   396
    // 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
   397
    //
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
   398
    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
   399
    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
   400
		&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
   401
		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
   402
        &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
   403
		);
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
   404
    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
   405
        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
   406
        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
   407
    }
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
   408
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
   409
    //
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
   410
    // 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
   411
    // 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
   412
    //
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
   413
    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
   414
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   415
    //
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   416
    // 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
   417
    //
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   418
    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
   419
    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
   420
    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
   421
    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
   422
    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
   423
    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
   424
    samplerDesc.MaxAnisotropy = 1;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   425
    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
   426
    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
   427
    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
   428
    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
   429
    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
   430
    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
   431
    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
   432
    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
   433
        &samplerDesc,
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   434
        &data->mainSampler
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   435
        );
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   436
    if (FAILED(result)) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   437
        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
   438
        return result;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   439
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   440
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   441
    //
8426
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   442
    // 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
   443
    //
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   444
    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
   445
    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
   446
	rasterDesc.AntialiasedLineEnable = false;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   447
	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
   448
	rasterDesc.DepthBias = 0;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   449
	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
   450
	rasterDesc.DepthClipEnable = true;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   451
	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
   452
	rasterDesc.FrontCounterClockwise = false;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   453
	rasterDesc.MultisampleEnable = false;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   454
	rasterDesc.ScissorEnable = false;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   455
	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
   456
	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
   457
	if (FAILED(result)) {
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   458
        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
   459
        return result;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   460
    }
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   461
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   462
    //
8431
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   463
    // Create blending states:
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   464
    //
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   465
    result = D3D11_CreateBlendMode(
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   466
        renderer,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   467
        TRUE,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   468
        D3D11_BLEND_SRC_ALPHA,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   469
        D3D11_BLEND_INV_SRC_ALPHA,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   470
        &data->blendModeBlend);
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   471
    if (FAILED(result)) {
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   472
        // D3D11_CreateBlendMode will set the SDL error, if it fails
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   473
        return result;
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   474
    }
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   475
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   476
    result = D3D11_CreateBlendMode(
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   477
        renderer,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   478
        TRUE,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   479
        D3D11_BLEND_SRC_ALPHA,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   480
        D3D11_BLEND_ONE,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   481
        &data->blendModeAdd);
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   482
    if (FAILED(result)) {
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   483
        // D3D11_CreateBlendMode will set the SDL error, if it fails
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   484
        return result;
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   485
    }
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   486
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   487
    result = D3D11_CreateBlendMode(
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   488
        renderer,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   489
        TRUE,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   490
        D3D11_BLEND_ZERO,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   491
        D3D11_BLEND_SRC_COLOR,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   492
        &data->blendModeMod);
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   493
    if (FAILED(result)) {
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   494
        // D3D11_CreateBlendMode will set the SDL error, if it fails
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   495
        return result;
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   496
    }
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   497
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   498
    //
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   499
    // All done!
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   500
    //
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   501
    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
   502
    return S_OK;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   503
}
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   504
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
   505
#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
   506
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
   507
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
   508
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
   509
{
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
    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
   511
    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
   512
        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
   513
    }
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
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
    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
   516
    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
   517
    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
   518
        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
   519
    }
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
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
    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
   522
        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
   523
    }
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
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
    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
   526
    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
   527
        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
   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
    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
   531
}
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
8414
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   533
// 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
   534
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
   535
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
   536
{
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
    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
   538
    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
   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
#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
   541
8414
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   542
// 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
   543
// 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
   544
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
   545
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
   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
    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
   548
    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
   549
    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
   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
    // 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
   552
    // 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
   553
    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
   554
    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
   555
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
    // 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
   557
    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
   558
    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
   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
    // 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
   561
    // 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
   562
    // 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
   563
    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
   564
    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
   565
        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
   566
        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
   567
    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
   568
    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
   569
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
    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
   571
    {
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
        // 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
   573
        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
   574
            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
   575
            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
   576
            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
   577
            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
   578
            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
   579
            );
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   580
        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
   581
            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
   582
            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
   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
    }
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
    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
   586
    {
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
        // 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
   588
        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
   589
        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
   590
        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
   591
        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
   592
        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
   593
        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
   594
        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
   595
        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
   596
        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
   597
#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
   598
        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
   599
        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
   600
#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
   601
        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
   602
        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
   603
#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
   604
        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
   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
        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
   607
        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
   608
        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
   609
            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
   610
            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
   611
        }
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
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
        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
   614
        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
   615
        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
   616
            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
   617
            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
   618
        }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   619
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   620
        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
   621
        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
   622
            __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
   623
            &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
   624
            );
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   625
        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
   626
            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
   627
            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
   628
        }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   629
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
        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
   631
            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
   632
            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
   633
            &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
   634
            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
   635
            &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
   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
        // 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
   643
        // 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
   644
        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
   645
        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
   646
            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
   647
            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
   648
        }
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
    }
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
    // 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
   652
    // 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
   653
    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
   654
    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
   655
    {
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
        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
   657
            rotation = DXGI_MODE_ROTATION_IDENTITY;
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
            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
   659
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
        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
   661
            rotation = DXGI_MODE_ROTATION_ROTATE270;
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
            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
   663
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
        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
   665
            rotation = DXGI_MODE_ROTATION_ROTATE180;
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
            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
   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
        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
   669
            rotation = DXGI_MODE_ROTATION_ROTATE90;
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
            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
   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
        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
   673
            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
   674
    }
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
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
#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
   677
    // 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
   678
    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
   679
    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
   680
        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
   681
        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
   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
#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
   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
    // 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
   686
    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
   687
    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
   688
        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
   689
        __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
   690
        &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
   691
        );
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   692
    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
   693
        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
   694
        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
   695
    }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   696
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   697
    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
   698
        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
   699
        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
   700
        &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
   701
        );
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   702
    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
   703
        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
   704
        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
   705
    }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   706
8432
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   707
    if (D3D11_UpdateViewport(renderer) != 0) {
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   708
        // D3D11_UpdateViewport will set the SDL error if it fails.
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   709
        return E_FAIL;
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   710
    }
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
   711
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   712
    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
   713
}
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   714
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
   715
// 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
   716
HRESULT
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   717
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
   718
{
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   719
    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
   720
    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
   721
    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
   722
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   723
    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
   724
        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
   725
        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
   726
    {
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   727
        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
   728
        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
   729
        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
   730
        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
   731
        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
   732
        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
   733
            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
   734
            return result;
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   735
        }
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
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   738
    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
   739
}
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   740
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   741
HRESULT
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   742
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
   743
{
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   744
    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
   745
    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
   746
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
   747
    // 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
   748
    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
   749
    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
   750
    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
   751
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   752
    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
   753
    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
   754
        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
   755
        return result;
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   756
    }
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   757
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   758
    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
   759
    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
   760
        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
   761
        return result;
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   762
    }
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   763
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   764
    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
   765
}
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   766
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
   767
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
   768
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
   769
{
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
   770
    //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
   771
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
   772
    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
   773
        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
   774
    }
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
   775
}
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
   776
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
   777
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
   778
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
   779
{
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
    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
   781
    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
   782
    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
   783
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
    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
   785
    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
   786
        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
   787
        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
   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
    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
   790
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
    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
   792
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
    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
   794
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
    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
   796
    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
   797
    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
   798
    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
   799
    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
   800
    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
   801
    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
   802
    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
   803
    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
   804
    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
   805
    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
   806
    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
   807
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
    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
   809
    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
   810
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
    // 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
   812
    //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
   813
    //    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
   814
    //    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
   815
    //    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
   816
    //    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
   817
    //}
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
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
    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
   820
    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
   821
    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
   822
    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
   823
    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
   824
        &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
   825
        &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
   826
        &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
   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
    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
   829
        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
   830
        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
   831
        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
   832
    }
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
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
    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
   835
    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
   836
    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
   837
    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
   838
    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
   839
    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
   840
        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
   841
        &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
   842
        &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
   843
        );
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
    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
   845
        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
   846
        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
   847
        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
   848
    }
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
    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
   851
}
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
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
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
   854
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
   855
                     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
   856
{
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
    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
   858
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
    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
   860
        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
   861
            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
   862
            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
   863
        }
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
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
        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
   866
        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
   867
    }
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
}
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
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
   871
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
   872
                    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
   873
                    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
   874
{
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
    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
   876
    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
   877
    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
   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
    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
   880
    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
   881
        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
   882
        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
   883
        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
   884
        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
   885
        &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
   886
        );
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
    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
   888
        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
   889
        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
   890
    }
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
   891
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
   892
    // 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
   893
    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
   894
        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
   895
            ((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
   896
            ((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
   897
            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
   898
            );
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
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
    // 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
   902
    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
   903
        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
   904
        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
   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
    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
   907
}
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
   908
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   909
static int
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   910
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
   911
{
8432
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   912
    D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   913
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   914
    if (renderer->viewport.w == 0 || renderer->viewport.h == 0) {
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   915
        // If the viewport is empty, assume that it is because
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   916
        // SDL_CreateRenderer is calling it, and will call it again later
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   917
        // with a non-empty viewport.
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   918
        return 0;
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   919
    }
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   920
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   921
    switch (data->orientation)
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   922
    {
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   923
        case DisplayOrientations::Landscape:
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   924
            data->vertexShaderConstantsData.projection = XMFLOAT4X4( // 0-degree Z-rotation
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   925
                1.0f, 0.0f, 0.0f, 0.0f,
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   926
                0.0f, 1.0f, 0.0f, 0.0f,
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   927
                0.0f, 0.0f, 1.0f, 0.0f,
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   928
                0.0f, 0.0f, 0.0f, 1.0f
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   929
                );
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   930
            break;
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   931
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   932
        case DisplayOrientations::Portrait:
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   933
            data->vertexShaderConstantsData.projection = XMFLOAT4X4( // 270-degree Z-rotation
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   934
                0.0f, -1.0f, 0.0f, 0.0f,
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   935
                1.0f, 0.0f, 0.0f, 0.0f,
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   936
                0.0f, 0.0f, 1.0f, 0.0f,
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   937
                0.0f, 0.0f, 0.0f, 1.0f
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   938
                );
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   939
            break;
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   940
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   941
        case DisplayOrientations::LandscapeFlipped:
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   942
            data->vertexShaderConstantsData.projection = XMFLOAT4X4( // 180-degree Z-rotation
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   943
                -1.0f, 0.0f, 0.0f, 0.0f,
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   944
                0.0f, -1.0f, 0.0f, 0.0f,
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   945
                0.0f, 0.0f, 1.0f, 0.0f,
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   946
                0.0f, 0.0f, 0.0f, 1.0f
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   947
                );
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   948
            break;
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   949
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   950
        case DisplayOrientations::PortraitFlipped:
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   951
            data->vertexShaderConstantsData.projection = XMFLOAT4X4( // 90-degree Z-rotation
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   952
                0.0f, 1.0f, 0.0f, 0.0f,
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   953
                -1.0f, 0.0f, 0.0f, 0.0f,
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   954
                0.0f, 0.0f, 1.0f, 0.0f,
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   955
                0.0f, 0.0f, 0.0f, 1.0f
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   956
                );
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   957
            break;
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   958
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   959
        default:
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   960
            SDL_SetError("An unknown DisplayOrientation is being used");
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   961
            return -1;
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   962
    }
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   963
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   964
    //
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   965
    // Update the view matrix
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   966
    //
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   967
    float windowWidth = (float) renderer->viewport.w;
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   968
    float windowHeight = (float) renderer->viewport.h;
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   969
    XMStoreFloat4x4(&data->vertexShaderConstantsData.view,  // (4)
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   970
        XMMatrixMultiply(
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   971
            XMMatrixScaling(2.0f / windowWidth, 2.0f / windowHeight, 1.0f),
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   972
            XMMatrixMultiply(
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   973
                XMMatrixTranslation(-1, -1, 0),
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   974
                XMMatrixRotationX(XM_PI)
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   975
                )));
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   976
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   977
    D3D11_VIEWPORT viewport;
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   978
    memset(&viewport, 0, sizeof(viewport));
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   979
    viewport.TopLeftX = (float) renderer->viewport.x;
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   980
    viewport.TopLeftY = (float) renderer->viewport.y;
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   981
    viewport.Width = (float) renderer->viewport.w;
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   982
    viewport.Height = (float) renderer->viewport.h;
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   983
    viewport.MinDepth = 0.0f;
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   984
    viewport.MaxDepth = 1.0f;
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   985
    data->d3dContext->RSSetViewports(1, &viewport);
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   986
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   987
    return 0;
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   988
}
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   989
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
   990
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
   991
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
   992
{