src/render/direct3d11/SDL_render_d3d11.cpp
author David Ludwig <dludwig@pobox.com>
Sat, 23 Feb 2013 22:58:09 -0500
changeset 8442 7046465c646c
parent 8434 c49d0a46f516
child 8444 dc12c4eda7e3
permissions -rw-r--r--
WinRT: added support for alpha-blended texture rendering
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"
8433
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8432
diff changeset
    33
#include "SDL_log.h"
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8432
diff changeset
    34
#include "../../video/SDL_sysvideo.h"
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    35
//#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
    36
}
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    37
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    38
#include <fstream>
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    39
#include <string>
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    40
#include <vector>
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    41
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    42
#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
    43
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    44
using namespace DirectX;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    45
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
    46
using namespace std;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    47
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
    48
#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
    49
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
    50
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
    51
#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
    52
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    53
/* 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
    54
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    55
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
    56
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
    57
                            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
    58
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
    59
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
    60
                             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
    61
                             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
    62
//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
    63
//                           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
    64
//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
    65
//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
    66
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
    67
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
    68
//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
    69
//                                const SDL_FPoint * points, int count);
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    70
//static int D3D11_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
    71
//                               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
    72
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
    73
                                 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
    74
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
    75
                            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
    76
//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
    77
//                          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
    78
//                          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
    79
//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
    80
//                                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
    81
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
    82
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
    83
                                 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
    84
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
    85
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    86
/* 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
    87
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
    88
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
    89
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
    90
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
    91
8442
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
    92
// WinRT, TODO: fill in the Direct3D 11.1 renderer's max texture width and height
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
    93
extern "C" SDL_RenderDriver D3D11_RenderDriver = {
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    94
    D3D11_CreateRenderer,
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    95
    {
8442
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
    96
        "direct3d 11.1",
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
    97
        (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE),    // flags.  see SDL_RendererFlags
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
    98
        2,                          // num_texture_formats
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
    99
        {                           // texture_formats
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   100
            SDL_PIXELFORMAT_RGB888,
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   101
            SDL_PIXELFORMAT_ARGB8888
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   102
        },
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   103
        0,                          // max_texture_width
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   104
        0                           // max_texture_height
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   105
    }
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   106
};
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   107
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   108
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   109
//typedef struct
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   110
//{
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   111
//    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
   112
//    DWORD color;
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   113
//    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
   114
//} Vertex;
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
SDL_Renderer *
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   117
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
   118
{
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   119
    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
   120
    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
   121
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   122
    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
   123
    if (!renderer) {
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   124
        SDL_OutOfMemory();
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   125
        return NULL;
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   126
    }
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   127
    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
   128
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   129
    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
   130
    if (!data) {
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   131
        SDL_OutOfMemory();
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   132
        return NULL;
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   133
    }
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   134
    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
   135
    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
   136
    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
   137
    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
   138
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
   139
    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
   140
    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
   141
    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
   142
    //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
   143
    //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
   144
    //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
   145
    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
   146
    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
   147
    //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
   148
    //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
   149
    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
   150
    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
   151
    //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
   152
    //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
   153
    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
   154
    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
   155
    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
   156
    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
   157
    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
   158
    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
   159
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
   160
    // 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
   161
    // 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
   162
    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
   163
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
   164
    /* 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
   165
    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
   166
        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
   167
        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
   168
    }
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
   169
    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
   170
        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
   171
        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
   172
    }
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   173
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
   174
    // 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
   175
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   176
    return renderer;
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   177
}
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   178
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
   179
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
   180
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
   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
    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
   183
    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
   184
        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
   185
        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
   186
    }
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
   187
}
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
   188
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   189
static bool
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   190
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
   191
{
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   192
    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
   193
    if (!in) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   194
        return false;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   195
    }
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
    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
   198
    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
   199
    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
   200
    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
   201
    return in.good();
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
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   204
static bool
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   205
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
   206
{
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   207
    wstring fileName;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   208
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   209
#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
   210
    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
   211
    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
   212
#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
   213
    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
   214
    fileName += L"\\";
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   215
#endif
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   216
    // 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
   217
    fileName += shaderName;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   218
    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
   219
}
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   220
8429
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   221
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
   222
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
   223
                      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
   224
                      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
   225
{
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   226
    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
   227
    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
   228
    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
   229
    
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   230
    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
   231
        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
   232
        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
   233
    }
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
    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
   236
        &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
   237
        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
   238
        nullptr,
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   239
        shaderOutput
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   240
        );
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   241
    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
   242
        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
   243
        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
   244
    }
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   245
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   246
    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
   247
}
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   248
8431
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   249
static HRESULT
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   250
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
   251
                      BOOL enableBlending,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   252
                      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
   253
                      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
   254
                      ID3D11BlendState ** blendStateOutput)
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   255
{
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   256
    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
   257
    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
   258
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   259
    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
   260
    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
   261
    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
   262
    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
   263
    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
   264
    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
   265
    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
   266
    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
   267
    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
   268
    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
   269
    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
   270
    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
   271
    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
   272
    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
   273
        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
   274
        return result;
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   275
    }
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   276
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   277
    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
   278
}
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   279
8414
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   280
// 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
   281
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
   282
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
   283
{
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   284
    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
   285
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   286
    // 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
   287
    // 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
   288
    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
   289
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   290
#if defined(_DEBUG)
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   291
    // 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
   292
    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
   293
#endif
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
    // 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
   296
    // 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
   297
    // 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
   298
    // 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
   299
    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
   300
    {
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_11_1,
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   302
        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
   303
        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
   304
        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
   305
        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
   306
        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
   307
        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
   308
    };
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   309
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   310
    // 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
   311
    ComPtr<ID3D11Device> device;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   312
    ComPtr<ID3D11DeviceContext> context;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   313
    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
   314
    result = D3D11CreateDevice(
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   315
        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
   316
        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
   317
        nullptr,
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   318
        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
   319
        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
   320
        ARRAYSIZE(featureLevels),
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   321
        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
   322
        &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
   323
        &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
   324
        &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
   325
        );
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   326
    if (FAILED(result)) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   327
        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
   328
        return result;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   329
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   330
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   331
    // 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
   332
    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
   333
    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
   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
        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
   336
        return result;
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
    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
   340
    if (FAILED(result)) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   341
        return result;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   342
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   343
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   344
    //
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   345
    // 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
   346
    //
8429
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   347
    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
   348
    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
   349
        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
   350
        return E_FAIL;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   351
    }
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
    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
   354
        &fileData[0],
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   355
        fileData.size(),
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   356
        nullptr,
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   357
        &data->vertexShader
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
    if (FAILED(result)) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   360
        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
   361
        return result;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   362
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   363
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   364
    //
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   365
    // 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
   366
    //
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   367
    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
   368
    {
8429
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   369
        { "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
   370
        { "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
   371
        { "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
   372
    };
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   373
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   374
    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
   375
        vertexDesc,
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   376
        ARRAYSIZE(vertexDesc),
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   377
        &fileData[0],
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   378
        fileData.size(),
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   379
        &data->inputLayout
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   380
        );
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   381
    if (FAILED(result)) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   382
        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
   383
        return result;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   384
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   385
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   386
    //
8429
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   387
    // 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
   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_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
   390
    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
   391
        // 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
   392
        return result;
8410
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
8429
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   395
    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
   396
    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
   397
        // 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
   398
        return result;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   399
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   400
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   401
    //
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
   402
    // 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
   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
    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
   405
    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
   406
		&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
   407
		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
   408
        &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
   409
		);
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
   410
    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
   411
        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
   412
        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
   413
    }
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
   414
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
   415
    //
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
   416
    // 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
   417
    // 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
   418
    //
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
   419
    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
   420
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   421
    //
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   422
    // 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
   423
    //
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   424
    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
   425
    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
   426
    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
   427
    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
   428
    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
   429
    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
   430
    samplerDesc.MaxAnisotropy = 1;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   431
    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
   432
    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
   433
    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
   434
    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
   435
    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
   436
    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
   437
    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
   438
    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
   439
        &samplerDesc,
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   440
        &data->mainSampler
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   441
        );
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   442
    if (FAILED(result)) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   443
        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
   444
        return result;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   445
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   446
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   447
    //
8426
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   448
    // 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
   449
    //
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   450
    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
   451
    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
   452
	rasterDesc.AntialiasedLineEnable = false;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   453
	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
   454
	rasterDesc.DepthBias = 0;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   455
	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
   456
	rasterDesc.DepthClipEnable = true;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   457
	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
   458
	rasterDesc.FrontCounterClockwise = false;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   459
	rasterDesc.MultisampleEnable = false;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   460
	rasterDesc.ScissorEnable = false;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   461
	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
   462
	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
   463
	if (FAILED(result)) {
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   464
        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
   465
        return result;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   466
    }
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   467
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   468
    //
8431
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   469
    // 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
   470
    //
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   471
    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
   472
        renderer,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   473
        TRUE,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   474
        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
   475
        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
   476
        &data->blendModeBlend);
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   477
    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
   478
        // 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
   479
        return result;
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   480
    }
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   481
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   482
    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
   483
        renderer,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   484
        TRUE,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   485
        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
   486
        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
   487
        &data->blendModeAdd);
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   488
    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
   489
        // 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
   490
        return result;
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   491
    }
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   492
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   493
    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
   494
        renderer,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   495
        TRUE,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   496
        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
   497
        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
   498
        &data->blendModeMod);
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   499
    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
   500
        // 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
   501
        return result;
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   502
    }
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   503
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   504
    //
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   505
    // All done!
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   506
    //
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   507
    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
   508
    return S_OK;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   509
}
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   510
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
   511
#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
   512
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
   513
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
   514
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
   515
{
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   516
    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
   517
    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
   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
    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
   522
    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
   523
    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
   524
        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
   525
    }
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
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
    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
   528
        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
   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
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
    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
   532
    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
   533
        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
   534
    }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   535
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
    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
   537
}
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
8414
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   539
// 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
   540
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
   541
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
   542
{
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
    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
   544
    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
   545
}
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
#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
   547
8414
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   548
// 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
   549
// 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
   550
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
   551
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
   552
{
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
    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
   554
    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
   555
    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
   556
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
    // 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
   558
    // 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
   559
    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
   560
    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
   561
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
    // 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
   563
    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
   564
    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
   565
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   566
    // 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
   567
    // 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
   568
    // 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
   569
    data->orientation = DisplayProperties::CurrentOrientation;
8433
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8432
diff changeset
   570
    const bool swapDimensions =
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
   571
        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
   572
        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
   573
    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
   574
    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
   575
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   576
    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
   577
    {
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
        // 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
   579
        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
   580
            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
   581
            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
   582
            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
   583
            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
   584
            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
   585
            );
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   586
        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
   587
            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
   588
            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
   589
        }
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
    }
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
    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
   592
    {
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
        // 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
   594
        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
   595
        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
   596
        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
   597
        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
   598
        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
   599
        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
   600
        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
   601
        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
   602
        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
   603
#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
   604
        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
   605
        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
   606
#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
   607
        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
   608
        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
   609
#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
   610
        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
   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
        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
   613
        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
   614
        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
   615
            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
   616
            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
   617
        }
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
        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
   620
        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
   621
        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
   622
            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
   623
            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
   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
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
        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
   627
        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
   628
            __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
   629
            &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
   630
            );
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
        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
   632
            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
   633
            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
   634
        }
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
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
        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
   637
            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
   638
            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
   639
            &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
   640
            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
   641
            &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
   642
            );
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
        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
   644
            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
   645
            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
   646
        }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   647
            
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
        // 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
   649
        // 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
   650
        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
   651
        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
   652
            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
   653
            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
   654
        }
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
    
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
    // 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
   658
    // 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
   659
    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
   660
    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
   661
    {
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   662
        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
   663
            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
   664
            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
   665
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
        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
   667
            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
   668
            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
   669
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
        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
   671
            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
   672
            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
   673
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
        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
   675
            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
   676
            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
   677
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
        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
   679
            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
   680
    }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   681
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
#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
   683
    // 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
   684
    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
   685
    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
   686
        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
   687
        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
   688
    }
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
#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
   690
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
    // 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
   692
    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
   693
    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
   694
        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
   695
        __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
   696
        &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
   697
        );
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
    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
   699
        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
   700
        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
   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
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
    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
   704
        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
   705
        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
   706
        &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
   707
        );
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   708
    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
   709
        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
   710
        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
   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
8432
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   713
    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
   714
        // 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
   715
        return E_FAIL;
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   716
    }
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
   717
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   718
    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
   719
}
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   720
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
   721
// 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
   722
HRESULT
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   723
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
   724
{
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   725
    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
   726
    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
   727
    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
   728
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   729
    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
   730
        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
   731
        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
   732
    {
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   733
        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
   734
        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
   735
        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
   736
        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
   737
        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
   738
        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
   739
            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
   740
            return result;
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   741
        }
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   742
    }
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
    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
   745
}
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   746
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   747
HRESULT
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   748
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
   749
{
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   750
    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
   751
    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
   752
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
   753
    // 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
   754
    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
   755
    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
   756
    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
   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_CreateDeviceResources(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
    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
   765
    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
   766
        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
   767
        return result;
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   768
    }
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   769
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   770
    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
   771
}
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   772
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
   773
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
   774
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
   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
    //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
   777
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
   778
    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
   779
        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
   780
    }
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
   781
}
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
   782
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
   783
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
   784
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
   785
{
17040ce2693d WinRT: 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
    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
   787
    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
   788
    HRESULT result;
8442
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   789
    DXGI_FORMAT textureFormat = DXGI_FORMAT_UNKNOWN;
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   790
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   791
    switch (texture->format) {
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   792
        case SDL_PIXELFORMAT_ARGB8888:
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   793
            textureFormat = DXGI_FORMAT_B8G8R8A8_UNORM;
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   794
            break;
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   795
        case SDL_PIXELFORMAT_RGB888:
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   796
            textureFormat = DXGI_FORMAT_B8G8R8X8_UNORM;
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   797
            break;
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   798
        default:
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   799
            SDL_SetError("%s, An unsupported SDL pixel format (0x%x) was specified",
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   800
                __FUNCTION__, texture->format);
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   801
            return -1;
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   802
    }
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
   803
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   804
    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
   805
    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
   806
        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
   807
        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
   808
    }
17040ce2693d WinRT: 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
    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
   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
    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
   812
17040ce2693d WinRT: 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
    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
   814
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   815
    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
   816
    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
   817
    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
   818
    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
   819
    textureDesc.ArraySize = 1;
8442
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   820
    textureDesc.Format = textureFormat;
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
   821
    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
   822
    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
   823
    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
   824
    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
   825
    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
   826
    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
   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
    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
   829
    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
   830
17040ce2693d WinRT: 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
    // 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
   832
    //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
   833
    //    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
   834
    //    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
   835
    //    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
   836
    //    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
   837
    //}
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   838
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   839
    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
   840
    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
   841
    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
   842
    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
   843
    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
   844
        &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
   845
        &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
   846
        &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
   847
        );
17040ce2693d WinRT: 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
    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
   849
        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
   850
        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
   851
        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
   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
17040ce2693d WinRT: 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_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
   855
    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
   856
    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
   857
    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
   858
    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
   859
    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
   860
        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
   861
        &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
   862
        &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
   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
    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
   865
        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
   866
        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
   867
        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
   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
    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
   871
}
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   872
17040ce2693d WinRT: 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
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
   874
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
   875
                     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
   876
{
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   877
    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
   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
    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
   880
        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
   881
            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
   882
            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
   883
        }
17040ce2693d WinRT: 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
17040ce2693d WinRT: 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
        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
   886
        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
   887
    }
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   888
}
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   889
17040ce2693d WinRT: 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
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
   891
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
   892
                    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
   893
                    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
   894
{
17040ce2693d WinRT: 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
    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
   896
    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
   897
    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
   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
    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
   900
    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
   901
        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
   902
        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
   903
        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
   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
        &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
   906
        );
17040ce2693d WinRT: 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
    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
   908
        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
   909
        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
   910
    }
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   911
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   912
    // 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
   913
    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
   914
        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
   915
            ((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
   916
            ((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
   917
            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
   918
            );
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   919
    }
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   920
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   921
    // 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
   922
    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
   923
        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
   924
        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
   925
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   926
    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
   927
}
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   928
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   929
static int
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   930
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
   931
{
8432
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   932
    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
   933
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   934
    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
   935
        // 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
   936
        // 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
   937
        // 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
   938
        return 0;
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   939
    }
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
    switch (data->orientation)
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   942
    {
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   943
        case DisplayOrientations::Landscape:
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   944
            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
   945
                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
   946
                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
   947
                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
   948
                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
   949
                );
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   950
            break;
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   951
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   952
        case DisplayOrientations::Portrait:
8433
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8432
diff changeset
   953
            data->vertexShaderConstantsData.projection = XMFLOAT4X4( // 90-degree Z-rotation
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8432
diff changeset
   954
                0.0f, 1.0f, 0.0f, 0.0f,
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8432
diff changeset
   955
                -1.0f, 0.0f, 0.0f, 0.0f,
8432
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   956
                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
   957
                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
   958
                );
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   959
            break;
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   960
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   961
        case DisplayOrientations::LandscapeFlipped:
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   962
            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
   963
                -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
   964
                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
   965
                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
   966
                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
   967
                );
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   968
            break;
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   969
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   970
        case DisplayOrientations::PortraitFlipped:
8433
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8432
diff changeset
   971
            data->vertexShaderConstantsData.projection = XMFLOAT4X4( // 270-degree Z-rotation
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8432
diff changeset
   972
                0.0f, -1.0f, 0.0f, 0.0f,
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8432
diff changeset
   973
                1.0f, 0.0f, 0.0f, 0.0f,
8432
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   974
                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
   975
                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
   976
                );
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   977
            break;
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   978
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   979
        default:
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   980
            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
   981
            return -1;
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   982
    }
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   983
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   984
    //
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   985
    // 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
   986
    //
8433
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8432
diff changeset
   987
    float viewportWidth = (float) renderer->viewport.w;
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8432
diff changeset
   988
    float viewportHeight = (float) renderer->viewport.h;
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8432
diff changeset
   989
    XMStoreFloat4x4(&data->vertexShaderConstantsData.view,
8432
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   990
        XMMatrixMultiply(
8433