src/render/direct3d11/SDL_render_d3d11.cpp
author David Ludwig <dludwig@pobox.com>
Sun, 22 Dec 2013 21:13:35 -0500
changeset 8550 321f0992541c
parent 8548 db8a89a4e633
child 8553 199f6c870823
permissions -rw-r--r--
WinRT: better rendering performance via D3D11_USAGE_DYNAMIC
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
8463
98dbf81ed5e9 WinRT: made SDL's inner WinRT CoreWindow be accessible to non-C++/CX code, in theory
David Ludwig <dludwig@pobox.com>
parents: 8459
diff changeset
    26
#ifdef __WINRT__
98dbf81ed5e9 WinRT: made SDL's inner WinRT CoreWindow be accessible to non-C++/CX code, in theory
David Ludwig <dludwig@pobox.com>
parents: 8459
diff changeset
    27
#include <windows.ui.core.h>
98dbf81ed5e9 WinRT: made SDL's inner WinRT CoreWindow be accessible to non-C++/CX code, in theory
David Ludwig <dludwig@pobox.com>
parents: 8459
diff changeset
    28
#include <windows.foundation.h>
8505
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
    29
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
    30
#if WINAPI_FAMILY == WINAPI_FAMILY_APP
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
    31
#include <windows.ui.xaml.media.dxinterop.h>
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
    32
#endif
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
    33
8463
98dbf81ed5e9 WinRT: made SDL's inner WinRT CoreWindow be accessible to non-C++/CX code, in theory
David Ludwig <dludwig@pobox.com>
parents: 8459
diff changeset
    34
#endif
98dbf81ed5e9 WinRT: made SDL's inner WinRT CoreWindow be accessible to non-C++/CX code, in theory
David Ludwig <dludwig@pobox.com>
parents: 8459
diff changeset
    35
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    36
extern "C" {
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    37
#include "../../core/windows/SDL_windows.h"
8533
89cf2a2635d1 WinRT: made the Direct3D 11.x 'Debug Layer' be enable-able in any app via a hint
David Ludwig <dludwig@pobox.com>
parents: 8526
diff changeset
    38
#include "SDL_hints.h"
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    39
//#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
    40
#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
    41
#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
    42
#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
    43
#include "SDL_log.h"
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8432
diff changeset
    44
#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
    45
//#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
    46
}
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    47
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    48
#include <fstream>
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    49
#include <string>
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    50
#include <vector>
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    51
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    52
#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
    53
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    54
using namespace DirectX;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    55
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
    56
using namespace std;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    57
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
    58
#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
    59
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
    60
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
    61
#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
    62
8540
724af2cd53b8 WinRT: added support for SDL_HINT_RENDER_SCALE_QUALITY
David Ludwig <dludwig@pobox.com>
parents: 8533
diff changeset
    63
/* Texture sampling types */
724af2cd53b8 WinRT: added support for SDL_HINT_RENDER_SCALE_QUALITY
David Ludwig <dludwig@pobox.com>
parents: 8533
diff changeset
    64
static const D3D11_FILTER SDL_D3D11_NEAREST_PIXEL_FILTER = D3D11_FILTER_MIN_MAG_MIP_POINT;
724af2cd53b8 WinRT: added support for SDL_HINT_RENDER_SCALE_QUALITY
David Ludwig <dludwig@pobox.com>
parents: 8533
diff changeset
    65
static const D3D11_FILTER SDL_D3D11_LINEAR_FILTER = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
724af2cd53b8 WinRT: added support for SDL_HINT_RENDER_SCALE_QUALITY
David Ludwig <dludwig@pobox.com>
parents: 8533
diff changeset
    66
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    67
/* 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
    68
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    69
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
    70
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
    71
                            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
    72
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
    73
static int D3D11_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
8459
1178e27580c7 WinRT: added render-to-texture support for D3D 11.1, via SDL_SetRenderTarget
David Ludwig <dludwig@pobox.com>
parents: 8458
diff changeset
    74
                             const SDL_Rect * rect, const void *srcPixels,
1178e27580c7 WinRT: added render-to-texture support for D3D 11.1, via SDL_SetRenderTarget
David Ludwig <dludwig@pobox.com>
parents: 8458
diff changeset
    75
                             int srcPitch);
8451
092ea651523a WinRT: added SDL_LockTexture and SDL_UnlockTexture support to the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8450
diff changeset
    76
static int D3D11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
092ea651523a WinRT: added SDL_LockTexture and SDL_UnlockTexture support to the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8450
diff changeset
    77
                             const SDL_Rect * rect, void **pixels, int *pitch);
092ea651523a WinRT: added SDL_LockTexture and SDL_UnlockTexture support to the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8450
diff changeset
    78
static void D3D11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
8459
1178e27580c7 WinRT: added render-to-texture support for D3D 11.1, via SDL_SetRenderTarget
David Ludwig <dludwig@pobox.com>
parents: 8458
diff changeset
    79
static int D3D11_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture);
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    80
static int D3D11_UpdateViewport(SDL_Renderer * renderer);
8482
eb0b00e7519e WinRT: added a stub implementation of UpdateClipRect to the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8463
diff changeset
    81
static int D3D11_UpdateClipRect(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 int D3D11_RenderClear(SDL_Renderer * renderer);
8450
6f34a798cb54 WinRT: added point drawing support to the Direct3D 11.1 rendering backend
David Ludwig <dludwig@pobox.com>
parents: 8449
diff changeset
    83
static int D3D11_RenderDrawPoints(SDL_Renderer * renderer,
6f34a798cb54 WinRT: added point drawing support to the Direct3D 11.1 rendering backend
David Ludwig <dludwig@pobox.com>
parents: 8449
diff changeset
    84
                                  const SDL_FPoint * points, int count);
8449
2e4e5085e5b1 WinRT: added line drawing support to the Direct3D 11.1 rendering backend
David Ludwig <dludwig@pobox.com>
parents: 8448
diff changeset
    85
static int D3D11_RenderDrawLines(SDL_Renderer * renderer,
2e4e5085e5b1 WinRT: added line drawing support to the Direct3D 11.1 rendering backend
David Ludwig <dludwig@pobox.com>
parents: 8448
diff changeset
    86
                                 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
    87
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
    88
                                 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
    89
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
    90
                            const SDL_Rect * srcrect, const SDL_FRect * dstrect);
8455
14d4b48cc07f WinRT: implemented SDL_RenderCopyEx, w/ SDL_RendererFlip support, in D3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8454
diff changeset
    91
static int D3D11_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
14d4b48cc07f WinRT: implemented SDL_RenderCopyEx, w/ SDL_RendererFlip support, in D3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8454
diff changeset
    92
                              const SDL_Rect * srcrect, const SDL_FRect * dstrect,
14d4b48cc07f WinRT: implemented SDL_RenderCopyEx, w/ SDL_RendererFlip support, in D3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8454
diff changeset
    93
                              const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip);
8454
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
    94
static int D3D11_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
    95
                                  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
    96
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
    97
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
    98
                                 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
    99
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
   100
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   101
/* 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
   102
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
   103
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
   104
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
   105
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
   106
8442
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   107
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
   108
    D3D11_CreateRenderer,
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   109
    {
8442
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   110
        "direct3d 11.1",
8459
1178e27580c7 WinRT: added render-to-texture support for D3D 11.1, via SDL_SetRenderTarget
David Ludwig <dludwig@pobox.com>
parents: 8458
diff changeset
   111
        (
1178e27580c7 WinRT: added render-to-texture support for D3D 11.1, via SDL_SetRenderTarget
David Ludwig <dludwig@pobox.com>
parents: 8458
diff changeset
   112
            SDL_RENDERER_ACCELERATED |
1178e27580c7 WinRT: added render-to-texture support for D3D 11.1, via SDL_SetRenderTarget
David Ludwig <dludwig@pobox.com>
parents: 8458
diff changeset
   113
            SDL_RENDERER_PRESENTVSYNC |
1178e27580c7 WinRT: added render-to-texture support for D3D 11.1, via SDL_SetRenderTarget
David Ludwig <dludwig@pobox.com>
parents: 8458
diff changeset
   114
            SDL_RENDERER_TARGETTEXTURE
1178e27580c7 WinRT: added render-to-texture support for D3D 11.1, via SDL_SetRenderTarget
David Ludwig <dludwig@pobox.com>
parents: 8458
diff changeset
   115
        ),                          // flags.  see SDL_RendererFlags
8442
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   116
        2,                          // num_texture_formats
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   117
        {                           // texture_formats
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   118
            SDL_PIXELFORMAT_RGB888,
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   119
            SDL_PIXELFORMAT_ARGB8888
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   120
        },
8446
290de0966136 WinRT: allowed for querying of max texture size (via Direct3D 11.1)
David Ludwig <dludwig@pobox.com>
parents: 8445
diff changeset
   121
        0,                          // max_texture_width: will be filled in later
290de0966136 WinRT: allowed for querying of max texture size (via Direct3D 11.1)
David Ludwig <dludwig@pobox.com>
parents: 8445
diff changeset
   122
        0                           // max_texture_height: will be filled in later
8442
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   123
    }
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   124
};
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   125
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   126
8454
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   127
static Uint32
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   128
DXGIFormatToSDLPixelFormat(DXGI_FORMAT dxgiFormat) {
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   129
    switch (dxgiFormat) {
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   130
        case DXGI_FORMAT_B8G8R8A8_UNORM:
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   131
            return SDL_PIXELFORMAT_ARGB8888;
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   132
        case DXGI_FORMAT_B8G8R8X8_UNORM:
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   133
            return SDL_PIXELFORMAT_RGB888;
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   134
        default:
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   135
            return SDL_PIXELFORMAT_UNKNOWN;
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   136
    }
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   137
}
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   138
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   139
static DXGI_FORMAT
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   140
SDLPixelFormatToDXGIFormat(Uint32 sdlFormat)
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   141
{
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   142
    switch (sdlFormat) {
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   143
        case SDL_PIXELFORMAT_ARGB8888:
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   144
            return DXGI_FORMAT_B8G8R8A8_UNORM;
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   145
        case SDL_PIXELFORMAT_RGB888:
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   146
            return DXGI_FORMAT_B8G8R8X8_UNORM;
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   147
        default:
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   148
            return DXGI_FORMAT_UNKNOWN;
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   149
    }
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   150
}
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   151
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   152
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   153
//typedef struct
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   154
//{
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   155
//    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
   156
//    DWORD color;
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   157
//    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
   158
//} Vertex;
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   159
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   160
SDL_Renderer *
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   161
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
   162
{
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   163
    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
   164
    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
   165
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   166
    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
   167
    if (!renderer) {
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   168
        SDL_OutOfMemory();
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   169
        return NULL;
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   170
    }
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   171
    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
   172
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   173
    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
   174
    if (!data) {
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   175
        SDL_OutOfMemory();
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   176
        return NULL;
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   177
    }
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   178
    data->featureLevel = (D3D_FEATURE_LEVEL) 0;
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
   179
    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
   180
    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
   181
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
   182
    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
   183
    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
   184
    renderer->UpdateTexture = D3D11_UpdateTexture;
8451
092ea651523a WinRT: added SDL_LockTexture and SDL_UnlockTexture support to the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8450
diff changeset
   185
    renderer->LockTexture = D3D11_LockTexture;
092ea651523a WinRT: added SDL_LockTexture and SDL_UnlockTexture support to the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8450
diff changeset
   186
    renderer->UnlockTexture = D3D11_UnlockTexture;
8459
1178e27580c7 WinRT: added render-to-texture support for D3D 11.1, via SDL_SetRenderTarget
David Ludwig <dludwig@pobox.com>
parents: 8458
diff changeset
   187
    renderer->SetRenderTarget = D3D11_SetRenderTarget;
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   188
    renderer->UpdateViewport = D3D11_UpdateViewport;
8482
eb0b00e7519e WinRT: added a stub implementation of UpdateClipRect to the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8463
diff changeset
   189
    renderer->UpdateClipRect = D3D11_UpdateClipRect;
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
   190
    renderer->RenderClear = D3D11_RenderClear;
8450
6f34a798cb54 WinRT: added point drawing support to the Direct3D 11.1 rendering backend
David Ludwig <dludwig@pobox.com>
parents: 8449
diff changeset
   191
    renderer->RenderDrawPoints = D3D11_RenderDrawPoints;
8449
2e4e5085e5b1 WinRT: added line drawing support to the Direct3D 11.1 rendering backend
David Ludwig <dludwig@pobox.com>
parents: 8448
diff changeset
   192
    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
   193
    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
   194
    renderer->RenderCopy = D3D11_RenderCopy;
8455
14d4b48cc07f WinRT: implemented SDL_RenderCopyEx, w/ SDL_RendererFlip support, in D3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8454
diff changeset
   195
    renderer->RenderCopyEx = D3D11_RenderCopyEx;
8454
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   196
    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
   197
    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
   198
    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
   199
    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
   200
    renderer->info = D3D11_RenderDriver.info;
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   201
    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
   202
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
   203
    // 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
   204
    // 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
   205
    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
   206
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
   207
    /* 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
   208
    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
   209
        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
   210
        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
   211
    }
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
   212
    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
   213
        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
   214
        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
   215
    }
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   216
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
   217
    // 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
   218
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   219
    return renderer;
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   220
}
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   221
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
   222
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
   223
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
   224
{
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
   225
    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
   226
    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
   227
        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
   228
        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
   229
    }
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
   230
}
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
   231
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   232
static bool
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   233
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
   234
{
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   235
    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
   236
    if (!in) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   237
        return false;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   238
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   239
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   240
    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
   241
    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
   242
    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
   243
    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
   244
    return in.good();
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   245
}
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   246
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   247
static bool
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   248
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
   249
{
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   250
    wstring fileName;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   251
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   252
#if WINAPI_FAMILY == WINAPI_FAMILY_APP
8454
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   253
    fileName = SDL_WinRTGetFSPathUNICODE(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
   254
    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
   255
#elif WINAPI_FAMILY == WINAPI_PHONE_APP
8454
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   256
    fileName = SDL_WinRTGetFSPathUNICODE(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
   257
    fileName += L"\\";
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   258
#endif
8504
3205689d1fff WinRT: made all WinRT-related TODO comments use the same prefix, "TODO, WinRT"
David Ludwig <dludwig@pobox.com>
parents: 8496
diff changeset
   259
    // TODO, WinRT: test Direct3D 11.1 shader loading on Win32
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   260
    fileName += shaderName;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   261
    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
   262
}
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   263
8429
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   264
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
   265
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
   266
                      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
   267
                      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
   268
{
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   269
    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
   270
    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
   271
    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
   272
    
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   273
    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
   274
        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
   275
        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
   276
    }
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   277
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   278
    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
   279
        &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
   280
        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
   281
        nullptr,
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   282
        shaderOutput
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   283
        );
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   284
    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
   285
        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
   286
        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
   287
    }
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   288
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   289
    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
   290
}
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   291
8431
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   292
static HRESULT
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   293
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
   294
                      BOOL enableBlending,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   295
                      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
   296
                      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
   297
                      ID3D11BlendState ** blendStateOutput)
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   298
{
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   299
    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
   300
    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
   301
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   302
    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
   303
    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
   304
    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
   305
    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
   306
    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
   307
    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
   308
    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
   309
    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
   310
    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
   311
    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
   312
    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
   313
    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
   314
    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
   315
    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
   316
        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
   317
        return result;
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   318
    }
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   319
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   320
    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
   321
}
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   322
8414
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   323
// 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
   324
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
   325
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
   326
{
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   327
    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
   328
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   329
    // 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
   330
    // 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
   331
    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
   332
8533
89cf2a2635d1 WinRT: made the Direct3D 11.x 'Debug Layer' be enable-able in any app via a hint
David Ludwig <dludwig@pobox.com>
parents: 8526
diff changeset
   333
    // Make sure Direct3D's debugging feature gets used, if the app requests it.
89cf2a2635d1 WinRT: made the Direct3D 11.x 'Debug Layer' be enable-able in any app via a hint
David Ludwig <dludwig@pobox.com>
parents: 8526
diff changeset
   334
    const char *hint = SDL_GetHint(SDL_HINT_RENDER_DIRECT3D11_DEBUG);
89cf2a2635d1 WinRT: made the Direct3D 11.x 'Debug Layer' be enable-able in any app via a hint
David Ludwig <dludwig@pobox.com>
parents: 8526
diff changeset
   335
    if (hint) {
89cf2a2635d1 WinRT: made the Direct3D 11.x 'Debug Layer' be enable-able in any app via a hint
David Ludwig <dludwig@pobox.com>
parents: 8526
diff changeset
   336
        if (*hint == '1') {
89cf2a2635d1 WinRT: made the Direct3D 11.x 'Debug Layer' be enable-able in any app via a hint
David Ludwig <dludwig@pobox.com>
parents: 8526
diff changeset
   337
            creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
89cf2a2635d1 WinRT: made the Direct3D 11.x 'Debug Layer' be enable-able in any app via a hint
David Ludwig <dludwig@pobox.com>
parents: 8526
diff changeset
   338
        }
89cf2a2635d1 WinRT: made the Direct3D 11.x 'Debug Layer' be enable-able in any app via a hint
David Ludwig <dludwig@pobox.com>
parents: 8526
diff changeset
   339
    }
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   340
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   341
    // 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
   342
    // 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
   343
    // 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
   344
    // 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
   345
    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
   346
    {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   347
        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
   348
        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
   349
        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
   350
        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
   351
        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
   352
        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
   353
        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
   354
    };
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   355
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   356
    // 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
   357
    ComPtr<ID3D11Device> device;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   358
    ComPtr<ID3D11DeviceContext> context;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   359
    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
   360
    result = D3D11CreateDevice(
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   361
        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
   362
        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
   363
        nullptr,
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   364
        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
   365
        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
   366
        ARRAYSIZE(featureLevels),
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   367
        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
   368
        &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
   369
        &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
   370
        &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
   371
        );
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   372
    if (FAILED(result)) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   373
        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
   374
        return result;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   375
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   376
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   377
    // 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
   378
    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
   379
    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
   380
    if (FAILED(result)) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   381
        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
   382
        return result;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   383
    }
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
    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
   386
    if (FAILED(result)) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   387
        return result;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   388
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   389
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   390
    //
8446
290de0966136 WinRT: allowed for querying of max texture size (via Direct3D 11.1)
David Ludwig <dludwig@pobox.com>
parents: 8445
diff changeset
   391
    // Make note of the maximum texture size
290de0966136 WinRT: allowed for querying of max texture size (via Direct3D 11.1)
David Ludwig <dludwig@pobox.com>
parents: 8445
diff changeset
   392
    // Max texture sizes are documented on MSDN, at:
290de0966136 WinRT: allowed for querying of max texture size (via Direct3D 11.1)
David Ludwig <dludwig@pobox.com>
parents: 8445
diff changeset
   393
    // http://msdn.microsoft.com/en-us/library/windows/apps/ff476876.aspx
290de0966136 WinRT: allowed for querying of max texture size (via Direct3D 11.1)
David Ludwig <dludwig@pobox.com>
parents: 8445
diff changeset
   394
    //
290de0966136 WinRT: allowed for querying of max texture size (via Direct3D 11.1)
David Ludwig <dludwig@pobox.com>
parents: 8445
diff changeset
   395
    switch (data->d3dDevice->GetFeatureLevel()) {
290de0966136 WinRT: allowed for querying of max texture size (via Direct3D 11.1)
David Ludwig <dludwig@pobox.com>
parents: 8445
diff changeset
   396
        case D3D_FEATURE_LEVEL_11_1:
290de0966136 WinRT: allowed for querying of max texture size (via Direct3D 11.1)
David Ludwig <dludwig@pobox.com>
parents: 8445
diff changeset
   397
        case D3D_FEATURE_LEVEL_11_0:
290de0966136 WinRT: allowed for querying of max texture size (via Direct3D 11.1)
David Ludwig <dludwig@pobox.com>
parents: 8445
diff changeset
   398
            renderer->info.max_texture_width = renderer->info.max_texture_height = 16384;
290de0966136 WinRT: allowed for querying of max texture size (via Direct3D 11.1)
David Ludwig <dludwig@pobox.com>
parents: 8445
diff changeset
   399
            break;
290de0966136 WinRT: allowed for querying of max texture size (via Direct3D 11.1)
David Ludwig <dludwig@pobox.com>
parents: 8445
diff changeset
   400
290de0966136 WinRT: allowed for querying of max texture size (via Direct3D 11.1)
David Ludwig <dludwig@pobox.com>
parents: 8445
diff changeset
   401
        case D3D_FEATURE_LEVEL_10_1:
290de0966136 WinRT: allowed for querying of max texture size (via Direct3D 11.1)
David Ludwig <dludwig@pobox.com>
parents: 8445
diff changeset
   402
        case D3D_FEATURE_LEVEL_10_0:
290de0966136 WinRT: allowed for querying of max texture size (via Direct3D 11.1)
David Ludwig <dludwig@pobox.com>
parents: 8445
diff changeset
   403
            renderer->info.max_texture_width = renderer->info.max_texture_height = 8192;
290de0966136 WinRT: allowed for querying of max texture size (via Direct3D 11.1)
David Ludwig <dludwig@pobox.com>
parents: 8445
diff changeset
   404
            break;
290de0966136 WinRT: allowed for querying of max texture size (via Direct3D 11.1)
David Ludwig <dludwig@pobox.com>
parents: 8445
diff changeset
   405
290de0966136 WinRT: allowed for querying of max texture size (via Direct3D 11.1)
David Ludwig <dludwig@pobox.com>
parents: 8445
diff changeset
   406
        case D3D_FEATURE_LEVEL_9_3:
290de0966136 WinRT: allowed for querying of max texture size (via Direct3D 11.1)
David Ludwig <dludwig@pobox.com>
parents: 8445
diff changeset
   407
            renderer->info.max_texture_width = renderer->info.max_texture_height = 4096;
290de0966136 WinRT: allowed for querying of max texture size (via Direct3D 11.1)
David Ludwig <dludwig@pobox.com>
parents: 8445
diff changeset
   408
            break;
290de0966136 WinRT: allowed for querying of max texture size (via Direct3D 11.1)
David Ludwig <dludwig@pobox.com>
parents: 8445
diff changeset
   409
290de0966136 WinRT: allowed for querying of max texture size (via Direct3D 11.1)
David Ludwig <dludwig@pobox.com>
parents: 8445
diff changeset
   410
        case D3D_FEATURE_LEVEL_9_2:
290de0966136 WinRT: allowed for querying of max texture size (via Direct3D 11.1)
David Ludwig <dludwig@pobox.com>
parents: 8445
diff changeset
   411
        case D3D_FEATURE_LEVEL_9_1:
290de0966136 WinRT: allowed for querying of max texture size (via Direct3D 11.1)
David Ludwig <dludwig@pobox.com>
parents: 8445
diff changeset
   412
            renderer->info.max_texture_width = renderer->info.max_texture_height = 2048;
290de0966136 WinRT: allowed for querying of max texture size (via Direct3D 11.1)
David Ludwig <dludwig@pobox.com>
parents: 8445
diff changeset
   413
            break;
290de0966136 WinRT: allowed for querying of max texture size (via Direct3D 11.1)
David Ludwig <dludwig@pobox.com>
parents: 8445
diff changeset
   414
    }
290de0966136 WinRT: allowed for querying of max texture size (via Direct3D 11.1)
David Ludwig <dludwig@pobox.com>
parents: 8445
diff changeset
   415
290de0966136 WinRT: allowed for querying of max texture size (via Direct3D 11.1)
David Ludwig <dludwig@pobox.com>
parents: 8445
diff changeset
   416
    //
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   417
    // 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
   418
    //
8429
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   419
    vector<char> fileData;
8444
dc12c4eda7e3 WinRT: moved the default vertex shader into the Direct3D 11.1 renderer's folder
David Ludwig <dludwig@pobox.com>
parents: 8442
diff changeset
   420
    if (!D3D11_ReadShaderContents(L"SDL_D3D11_VertexShader_Default.cso", fileData)) {
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   421
        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
   422
        return E_FAIL;
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
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   425
    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
   426
        &fileData[0],
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   427
        fileData.size(),
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   428
        nullptr,
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   429
        &data->vertexShader
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   430
        );
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   431
    if (FAILED(result)) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   432
        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
   433
        return result;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   434
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   435
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   436
    //
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   437
    // 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
   438
    //
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   439
    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
   440
    {
8429
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   441
        { "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
   442
        { "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
   443
        { "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
   444
    };
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
    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
   447
        vertexDesc,
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   448
        ARRAYSIZE(vertexDesc),
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   449
        &fileData[0],
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   450
        fileData.size(),
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   451
        &data->inputLayout
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   452
        );
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   453
    if (FAILED(result)) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   454
        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
   455
        return result;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   456
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   457
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   458
    //
8429
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   459
    // 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
   460
    //
8458
9b25393568f3 WinRT: added texture channel color-modulation support for D3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8457
diff changeset
   461
    result = D3D11_LoadPixelShader(renderer, L"SDL_D3D11_PixelShader_TextureColored.cso", &data->texturePixelShader);
8429
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   462
    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
   463
        // 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
   464
        return result;
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   465
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   466
8429
a8b45a923fbd WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8427
diff changeset
   467
    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
   468
    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
   469
        // 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
   470
        return result;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   471
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   472
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   473
    //
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
   474
    // 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
   475
    //
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
   476
    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
   477
    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
   478
		&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
   479
		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
   480
        &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
   481
		);
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
   482
    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
   483
        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
   484
        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
   485
    }
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
   486
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
   487
    //
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
   488
    // 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
   489
    // 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
   490
    //
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
   491
    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
   492
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   493
    //
8540
724af2cd53b8 WinRT: added support for SDL_HINT_RENDER_SCALE_QUALITY
David Ludwig <dludwig@pobox.com>
parents: 8533
diff changeset
   494
    // Create samplers to use when drawing textures:
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   495
    //
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   496
    D3D11_SAMPLER_DESC samplerDesc;
8540
724af2cd53b8 WinRT: added support for SDL_HINT_RENDER_SCALE_QUALITY
David Ludwig <dludwig@pobox.com>
parents: 8533
diff changeset
   497
    samplerDesc.Filter = SDL_D3D11_NEAREST_PIXEL_FILTER;
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   498
    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
   499
    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
   500
    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
   501
    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
   502
    samplerDesc.MaxAnisotropy = 1;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   503
    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
   504
    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
   505
    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
   506
    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
   507
    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
   508
    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
   509
    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
   510
    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
   511
        &samplerDesc,
8540
724af2cd53b8 WinRT: added support for SDL_HINT_RENDER_SCALE_QUALITY
David Ludwig <dludwig@pobox.com>
parents: 8533
diff changeset
   512
        &data->nearestPixelSampler
724af2cd53b8 WinRT: added support for SDL_HINT_RENDER_SCALE_QUALITY
David Ludwig <dludwig@pobox.com>
parents: 8533
diff changeset
   513
        );
724af2cd53b8 WinRT: added support for SDL_HINT_RENDER_SCALE_QUALITY
David Ludwig <dludwig@pobox.com>
parents: 8533
diff changeset
   514
    if (FAILED(result)) {
724af2cd53b8 WinRT: added support for SDL_HINT_RENDER_SCALE_QUALITY
David Ludwig <dludwig@pobox.com>
parents: 8533
diff changeset
   515
        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
724af2cd53b8 WinRT: added support for SDL_HINT_RENDER_SCALE_QUALITY
David Ludwig <dludwig@pobox.com>
parents: 8533
diff changeset
   516
        return result;
724af2cd53b8 WinRT: added support for SDL_HINT_RENDER_SCALE_QUALITY
David Ludwig <dludwig@pobox.com>
parents: 8533
diff changeset
   517
    }
724af2cd53b8 WinRT: added support for SDL_HINT_RENDER_SCALE_QUALITY
David Ludwig <dludwig@pobox.com>
parents: 8533
diff changeset
   518
724af2cd53b8 WinRT: added support for SDL_HINT_RENDER_SCALE_QUALITY
David Ludwig <dludwig@pobox.com>
parents: 8533
diff changeset
   519
    samplerDesc.Filter = SDL_D3D11_LINEAR_FILTER;
724af2cd53b8 WinRT: added support for SDL_HINT_RENDER_SCALE_QUALITY
David Ludwig <dludwig@pobox.com>
parents: 8533
diff changeset
   520
    result = data->d3dDevice->CreateSamplerState(
724af2cd53b8 WinRT: added support for SDL_HINT_RENDER_SCALE_QUALITY
David Ludwig <dludwig@pobox.com>
parents: 8533
diff changeset
   521
        &samplerDesc,
724af2cd53b8 WinRT: added support for SDL_HINT_RENDER_SCALE_QUALITY
David Ludwig <dludwig@pobox.com>
parents: 8533
diff changeset
   522
        &data->linearSampler
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   523
        );
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   524
    if (FAILED(result)) {
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   525
        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
   526
        return result;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   527
    }
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   528
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   529
    //
8426
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   530
    // 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
   531
    //
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   532
    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
   533
    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
   534
	rasterDesc.AntialiasedLineEnable = false;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   535
	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
   536
	rasterDesc.DepthBias = 0;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   537
	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
   538
	rasterDesc.DepthClipEnable = true;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   539
	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
   540
	rasterDesc.FrontCounterClockwise = false;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   541
	rasterDesc.MultisampleEnable = false;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   542
	rasterDesc.ScissorEnable = false;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   543
	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
   544
	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
   545
	if (FAILED(result)) {
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   546
        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
   547
        return result;
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   548
    }
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   549
9775bb101357 WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
David Ludwig <dludwig@pobox.com>
parents: 8425
diff changeset
   550
    //
8431
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   551
    // 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
   552
    //
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   553
    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
   554
        renderer,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   555
        TRUE,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   556
        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
   557
        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
   558
        &data->blendModeBlend);
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   559
    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
   560
        // 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
   561
        return result;
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   562
    }
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   563
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   564
    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
   565
        renderer,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   566
        TRUE,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   567
        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
   568
        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
   569
        &data->blendModeAdd);
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   570
    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
   571
        // 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
   572
        return result;
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   573
    }
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   574
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   575
    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
   576
        renderer,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   577
        TRUE,
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   578
        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
   579
        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
   580
        &data->blendModeMod);
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   581
    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
   582
        // 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
   583
        return result;
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   584
    }
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   585
2078dc4f4378 WinRT: D3D 11.1 blending mode support added; FillRects coloring bug-fix
David Ludwig <dludwig@pobox.com>
parents: 8430
diff changeset
   586
    //
8410
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   587
    // All done!
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   588
    //
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   589
    return S_OK;
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   590
}
ba725b3a0c87 WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   591
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
   592
#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
   593
8463
98dbf81ed5e9 WinRT: made SDL's inner WinRT CoreWindow be accessible to non-C++/CX code, in theory
David Ludwig <dludwig@pobox.com>
parents: 8459
diff changeset
   594
static ABI::Windows::UI::Core::ICoreWindow *
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
   595
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
   596
{
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
    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
   598
    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
   599
        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
   600
    }
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
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
    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
   603
    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
   604
    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
   605
        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
   606
    }
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
8496
9f0a4fbc6452 WinRT: renamed SDL_SYSWM_WINDOWSRT to SDL_SYSWM_WINRT
David Ludwig <dludwig@pobox.com>
parents: 8482
diff changeset
   608
    if (sdlWindowInfo.subsystem != SDL_SYSWM_WINRT) {
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
   609
        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
   610
    }
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
8463
98dbf81ed5e9 WinRT: made SDL's inner WinRT CoreWindow be accessible to non-C++/CX code, in theory
David Ludwig <dludwig@pobox.com>
parents: 8459
diff changeset
   612
    if ( ! sdlWindowInfo.info.winrt.window ) {
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
   613
        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
   614
    }
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
8463
98dbf81ed5e9 WinRT: made SDL's inner WinRT CoreWindow be accessible to non-C++/CX code, in theory
David Ludwig <dludwig@pobox.com>
parents: 8459
diff changeset
   616
    ABI::Windows::UI::Core::ICoreWindow * coreWindow = nullptr;
98dbf81ed5e9 WinRT: made SDL's inner WinRT CoreWindow be accessible to non-C++/CX code, in theory
David Ludwig <dludwig@pobox.com>
parents: 8459
diff changeset
   617
    if (FAILED(sdlWindowInfo.info.winrt.window->QueryInterface(&coreWindow))) {
98dbf81ed5e9 WinRT: made SDL's inner WinRT CoreWindow be accessible to non-C++/CX code, in theory
David Ludwig <dludwig@pobox.com>
parents: 8459
diff changeset
   618
        return nullptr;
98dbf81ed5e9 WinRT: made SDL's inner WinRT CoreWindow be accessible to non-C++/CX code, in theory
David Ludwig <dludwig@pobox.com>
parents: 8459
diff changeset
   619
    }
98dbf81ed5e9 WinRT: made SDL's inner WinRT CoreWindow be accessible to non-C++/CX code, in theory
David Ludwig <dludwig@pobox.com>
parents: 8459
diff changeset
   620
98dbf81ed5e9 WinRT: made SDL's inner WinRT CoreWindow be accessible to non-C++/CX code, in theory
David Ludwig <dludwig@pobox.com>
parents: 8459
diff changeset
   621
    return 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
   622
}
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
8414
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   624
// 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
   625
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
   626
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
   627
{
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
    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
   629
    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
   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
#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
   632
8505
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   633
#if WINAPI_FAMILY == WINAPI_FAMILY_APP
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   634
// TODO, WinRT, XAML: get the ISwapChainBackgroundPanelNative from something other than a global var
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   635
extern ISwapChainBackgroundPanelNative * WINRT_GlobalSwapChainBackgroundPanelNative;
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   636
#endif
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   637
8548
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   638
static DXGI_MODE_ROTATION
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   639
D3D11_GetRotationForOrientation(Windows::Graphics::Display::DisplayOrientations orientation)
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   640
{
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   641
    switch (orientation)
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   642
    {
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   643
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   644
        //
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   645
        // Windows Phone rotations
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   646
        //
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   647
        case DisplayOrientations::Landscape:
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   648
            return DXGI_MODE_ROTATION_ROTATE90;
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   649
        case DisplayOrientations::Portrait:
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   650
            return DXGI_MODE_ROTATION_IDENTITY;
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   651
        case DisplayOrientations::LandscapeFlipped:
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   652
            return DXGI_MODE_ROTATION_ROTATE270;
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   653
        case DisplayOrientations::PortraitFlipped:
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   654
            return DXGI_MODE_ROTATION_ROTATE180;
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   655
#else
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   656
        //
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   657
        // Non-Windows-Phone rotations (ex: Windows 8, Windows RT)
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   658
        //
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   659
        case DisplayOrientations::Landscape:
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   660
            return DXGI_MODE_ROTATION_IDENTITY;
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   661
        case DisplayOrientations::Portrait:
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   662
            return DXGI_MODE_ROTATION_ROTATE270;
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   663
        case DisplayOrientations::LandscapeFlipped:
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   664
            return DXGI_MODE_ROTATION_ROTATE180;
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   665
        case DisplayOrientations::PortraitFlipped:
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   666
            return DXGI_MODE_ROTATION_ROTATE90;
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   667
#endif // WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   668
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   669
        default:
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   670
            return DXGI_MODE_ROTATION_UNSPECIFIED;
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   671
    }
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   672
}
8505
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   673
8414
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   674
// Initialize all resources that change when the window's size changes.
8504
3205689d1fff WinRT: made all WinRT-related TODO comments use the same prefix, "TODO, WinRT"
David Ludwig <dludwig@pobox.com>
parents: 8496
diff changeset
   675
// TODO, WinRT: get D3D11_CreateWindowSizeDependentResources working on Win32
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
   676
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
   677
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
   678
{
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
    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
   680
    HRESULT result = S_OK;
8463
98dbf81ed5e9 WinRT: made SDL's inner WinRT CoreWindow be accessible to non-C++/CX code, in theory
David Ludwig <dludwig@pobox.com>
parents: 8459
diff changeset
   681
    ABI::Windows::UI::Core::ICoreWindow * coreWindow = D3D11_GetCoreWindowFromSDLRenderer(renderer);
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
   682
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   683
    // 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
   684
    // avoid rebuilding everything if the size is identical.
8505
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   685
    ABI::Windows::Foundation::Rect nativeWindowBounds;
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   686
    if (coreWindow) {
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   687
        result = coreWindow->get_Bounds(&nativeWindowBounds);
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   688
        if (FAILED(result)) {
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   689
            WIN_SetErrorFromHRESULT(__FUNCTION__", Get Window Bounds", result);
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   690
            return result;
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   691
        }
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   692
    } else {
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   693
        // TODO, WinRT, XAML: clean up window-bounds code in D3D11_CreateWindowSizeDependentResources
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   694
        SDL_DisplayMode displayMode;
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   695
        if (SDL_GetDesktopDisplayMode(0, &displayMode) < 0) {
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   696
            SDL_SetError(__FUNCTION__", Get Window Bounds (XAML): Unable to retrieve the native window's size");
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   697
            return E_FAIL;
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   698
        }
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   699
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   700
        nativeWindowBounds.Width = (FLOAT) displayMode.w;
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   701
        nativeWindowBounds.Height = (FLOAT) displayMode.h;
8463
98dbf81ed5e9 WinRT: made SDL's inner WinRT CoreWindow be accessible to non-C++/CX code, in theory
David Ludwig <dludwig@pobox.com>
parents: 8459
diff changeset
   702
    }
98dbf81ed5e9 WinRT: made SDL's inner WinRT CoreWindow be accessible to non-C++/CX code, in theory
David Ludwig <dludwig@pobox.com>
parents: 8459
diff changeset
   703
8505
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   704
    // TODO, WinRT, XAML: see if window/control sizes are in DIPs, or something else.  If something else, then adjust renderer size tracking accordingly.
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   705
    data->windowSizeInDIPs.x = nativeWindowBounds.Width;
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   706
    data->windowSizeInDIPs.y = nativeWindowBounds.Height;
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
   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
    // 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
   709
    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
   710
    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
   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
    // 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
   713
    // 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
   714
    // 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
   715
    data->orientation = DisplayProperties::CurrentOrientation;
8508
3d6da410a49f WinRT: rendering orientation fixes for Windows Phone, part 1
David Ludwig <dludwig@pobox.com>
parents: 8507
diff changeset
   716
3d6da410a49f WinRT: rendering orientation fixes for Windows Phone, part 1
David Ludwig <dludwig@pobox.com>
parents: 8507
diff changeset
   717
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
3d6da410a49f WinRT: rendering orientation fixes for Windows Phone, part 1
David Ludwig <dludwig@pobox.com>
parents: 8507
diff changeset
   718
    const bool swapDimensions = false;
3d6da410a49f WinRT: rendering orientation fixes for Windows Phone, part 1
David Ludwig <dludwig@pobox.com>
parents: 8507
diff changeset
   719
#else
8433
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8432
diff changeset
   720
    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
   721
        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
   722
        data->orientation == DisplayOrientations::PortraitFlipped;
8508
3d6da410a49f WinRT: rendering orientation fixes for Windows Phone, part 1
David Ludwig <dludwig@pobox.com>
parents: 8507
diff changeset
   723
#endif
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
   724
    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
   725
    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
   726
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   727
    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
   728
    {
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   729
        // 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
   730
        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
   731
            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
   732
            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
   733
            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
   734
            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
   735
            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
   736
            );
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   737
        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
   738
            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
   739
            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
   740
        }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   741
    }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   742
    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
   743
    {
8505
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   744
        const bool usingXAML = (coreWindow == nullptr);
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   745
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
   746
        // 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
   747
        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
   748
        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
   749
        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
   750
        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
   751
        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
   752
        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
   753
        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
   754
        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
   755
        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
   756
#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
   757
        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
   758
        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
   759
#else
8505
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   760
        if (usingXAML) {
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   761
            swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   762
        } else {
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   763
            swapChainDesc.Scaling = DXGI_SCALING_NONE;
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   764
        }
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
   765
        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
   766
#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
   767
        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
   768
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   769
        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
   770
        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
   771
        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
   772
            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
   773
            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
   774
        }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   775
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   776
        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
   777
        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
   778
        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
   779
            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
   780
            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
   781
        }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   782
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   783
        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
   784
        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
   785
            __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
   786
            &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
   787
            );
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   788
        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
   789
            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
   790
            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
   791
        }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   792
8505
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   793
        if (usingXAML) {
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   794
            result = dxgiFactory->CreateSwapChainForComposition(
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   795
                data->d3dDevice.Get(),
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   796
                &swapChainDesc,
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   797
                nullptr,
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   798
                &data->swapChain);
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   799
            if (FAILED(result)) {
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   800
                WIN_SetErrorFromHRESULT(__FUNCTION__ ", CreateSwapChainForComposition", result);
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   801
                return result;
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   802
            }
8463
98dbf81ed5e9 WinRT: made SDL's inner WinRT CoreWindow be accessible to non-C++/CX code, in theory
David Ludwig <dludwig@pobox.com>
parents: 8459
diff changeset
   803
8505
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   804
#if WINAPI_FAMILY == WINAPI_FAMILY_APP
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   805
            result = WINRT_GlobalSwapChainBackgroundPanelNative->SetSwapChain(data->swapChain.Get());
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   806
            if (FAILED(result)) {
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   807
                WIN_SetErrorFromHRESULT(__FUNCTION__ ", ISwapChainBackgroundPanelNative::SetSwapChain", result);
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   808
                return result;
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   809
            }
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   810
#else
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   811
            SDL_SetError(__FUNCTION__ ", XAML support is not yet available for Windows Phone");
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   812
            return E_FAIL;
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   813
#endif
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   814
        } else {
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   815
            IUnknown * coreWindowAsIUnknown = nullptr;
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   816
            result = coreWindow->QueryInterface(&coreWindowAsIUnknown);
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   817
            if (FAILED(result)) {
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   818
                WIN_SetErrorFromHRESULT(__FUNCTION__ ", CoreWindow to IUnknown", result);
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   819
                return result;
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   820
            }
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   821
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   822
            result = dxgiFactory->CreateSwapChainForCoreWindow(
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   823
                data->d3dDevice.Get(),
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   824
                coreWindowAsIUnknown,
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   825
                &swapChainDesc,
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   826
                nullptr, // Allow on all displays.
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   827
                &data->swapChain
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   828
                );
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   829
            if (FAILED(result)) {
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   830
                WIN_SetErrorFromHRESULT(__FUNCTION__, result);
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   831
                return result;
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   832
            }
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
   833
        }
8505
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8504
diff changeset
   834
        
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
   835
        // 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
   836
        // 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
   837
        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
   838
        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
   839
            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
   840
            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
   841
        }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   842
    }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   843
    
8508
3d6da410a49f WinRT: rendering orientation fixes for Windows Phone, part 1
David Ludwig <dludwig@pobox.com>
parents: 8507
diff changeset
   844
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
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
   845
    // 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
   846
    // 3D matrix transformation for rendering to the rotated swap chain.
8509
977e2aabdcaa WinRT: removed a comment regarding a dealt-with TODO
David Ludwig <dludwig@pobox.com>
parents: 8508
diff changeset
   847
    //
8548
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   848
    // To note, the call for this, IDXGISwapChain1::SetRotation, is not necessary
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   849
    // on Windows Phone, nor is it supported there.  It's only needed in Windows 8/RT.
db8a89a4e633 WinRT: fixed bug: SDL_RenderReadPixels didn't work with certain orientations of the physical display
David Ludwig <dludwig@pobox.com>
parents: 8540
diff changeset
   850
    DXGI_MODE_ROTATION rotation = D3D11_GetRotationForOrientation(data->orientation);
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
   851
    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
   852
    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
   853
        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
   854
        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
   855
    }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   856
#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
   857
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   858
    // 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
   859
    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
   860
    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
   861
        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
   862
        __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
   863
        &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
   864
        );
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   865
    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
   866
        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
   867
        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
   868
    }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   869
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   870
    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
   871
        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
   872
        nullptr,
8459
1178e27580c7 WinRT: added render-to-texture support for D3D 11.1, via SDL_SetRenderTarget
David Ludwig <dludwig@pobox.com>
parents: 8458
diff changeset
   873
        &data->mainRenderTargetView
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
   874
        );
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   875
    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
   876
        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
   877
        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
   878
    }
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   879
8432
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   880
    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
   881
        // 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
   882
        return E_FAIL;
929e53386278 WinRT: made SDL_RenderSetViewport work with the D3D 11.1 renderer
David Ludwig <dludwig@pobox.com>
parents: 8431
diff changeset
   883
    }
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
   884
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   885
    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
   886
}
59f1191a5cca WinRT: more work on moving rendering code from SDL_winrtrenderer.* to SDL_render_d3d11*
David Ludwig <dludwig@pobox.com>
parents: 8410
diff changeset
   887
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
   888
// 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
   889
HRESULT
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   890
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
   891
{
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   892
    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
   893
    HRESULT result = S_OK;
8463
98dbf81ed5e9 WinRT: made SDL's inner WinRT CoreWindow be accessible to non-C++/CX code, in theory
David Ludwig <dludwig@pobox.com>
parents: 8459
diff changeset
   894
    ABI::Windows::UI::Core::ICoreWindow * coreWindow = D3D11_GetCoreWindowFromSDLRenderer(renderer);
98dbf81ed5e9 WinRT: made SDL's inner WinRT CoreWindow be accessible to non-C++/CX code, in theory
David Ludwig <dludwig@pobox.com>
parents: 8459
diff changeset
   895
    ABI::Windows::Foundation::Rect coreWindowBounds;
8414
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   896
8463
98dbf81ed5e9 WinRT: made SDL's inner WinRT CoreWindow be accessible to non-C++/CX code, in theory
David Ludwig <dludwig@pobox.com>
parents: 8459
diff changeset
   897
    result = coreWindow->get_Bounds(&coreWindowBounds);
98dbf81ed5e9 WinRT: made SDL's inner WinRT CoreWindow be accessible to non-C++/CX code, in theory
David Ludwig <dludwig@pobox.com>
parents: 8459
diff changeset
   898
    if (FAILED(result)) {
98dbf81ed5e9 WinRT: made SDL's inner WinRT CoreWindow be accessible to non-C++/CX code, in theory
David Ludwig <dludwig@pobox.com>
parents: 8459
diff changeset
   899
        WIN_SetErrorFromHRESULT(__FUNCTION__ ", Get Window Bounds", result);
98dbf81ed5e9 WinRT: made SDL's inner WinRT CoreWindow be accessible to non-C++/CX code, in theory
David Ludwig <dludwig@pobox.com>
parents: 8459
diff changeset
   900
        return result;
98dbf81ed5e9 WinRT: made SDL's inner WinRT CoreWindow be accessible to non-C++/CX code, in theory
David Ludwig <dludwig@pobox.com>
parents: 8459
diff changeset
   901
    }
98dbf81ed5e9 WinRT: made SDL's inner WinRT CoreWindow be accessible to non-C++/CX code, in theory
David Ludwig <dludwig@pobox.com>
parents: 8459
diff changeset
   902
98dbf81ed5e9 WinRT: made SDL's inner WinRT CoreWindow be accessible to non-C++/CX code, in theory
David Ludwig <dludwig@pobox.com>
parents: 8459
diff changeset
   903
    if (coreWindowBounds.Width  != data->windowSizeInDIPs.x ||
98dbf81ed5e9 WinRT: made SDL's inner WinRT CoreWindow be accessible to non-C++/CX code, in theory
David Ludwig <dludwig@pobox.com>
parents: 8459
diff changeset
   904
        coreWindowBounds.Height != data->windowSizeInDIPs.y ||
8414
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   905
        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
   906
    {
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   907
        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
   908
        data->d3dContext->OMSetRenderTargets(ARRAYSIZE(nullViews), nullViews, nullptr);
8459
1178e27580c7 WinRT: added render-to-texture support for D3D 11.1, via SDL_SetRenderTarget
David Ludwig <dludwig@pobox.com>
parents: 8458
diff changeset
   909
        data->mainRenderTargetView = nullptr;
8414
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   910
        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
   911
        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
   912
        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
   913
            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
   914
            return result;
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   915
        }
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   916
    }
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   917
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   918
    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
   919
}
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   920
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   921
HRESULT
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   922
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
   923
{
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   924
    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
   925
    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
   926
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
   927
    // 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
   928
    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
   929
    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
   930
    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
   931
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   932
    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
   933
    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
   934
        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
   935
        return result;
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   936
    }
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   937
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   938
    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
   939
    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
   940
        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
   941
        return result;
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   942
    }
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   943
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   944
    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
   945
}
25a7605097a2 WinRT: more code-moving from WinRT code to Direct3D 11.1 code
David Ludwig <dludwig@pobox.com>
parents: 8413
diff changeset
   946
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
   947
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
   948
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
   949
{
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
   950
    //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
   951
8510
b828c4cc5cd8 WinRT: made rendering work with orientation changes on Windows Phone
David Ludwig <dludwig@pobox.com>
parents: 8509
diff changeset
   952
    if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
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
   953
        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
   954
    }
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
   955
}
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
   956
8540
724af2cd53b8 WinRT: added support for SDL_HINT_RENDER_SCALE_QUALITY
David Ludwig <dludwig@pobox.com>
parents: 8533
diff changeset
   957
static D3D11_FILTER
724af2cd53b8 WinRT: added support for SDL_HINT_RENDER_SCALE_QUALITY
David Ludwig <dludwig@pobox.com>
parents: 8533
diff changeset
   958
GetScaleQuality(void)
724af2cd53b8 WinRT: added support for SDL_HINT_RENDER_SCALE_QUALITY
David Ludwig <dludwig@pobox.com>
parents: 8533
diff changeset
   959
{
724af2cd53b8 WinRT: added support for SDL_HINT_RENDER_SCALE_QUALITY
David Ludwig <dludwig@pobox.com>
parents: 8533
diff changeset
   960
    const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
724af2cd53b8 WinRT: added support for SDL_HINT_RENDER_SCALE_QUALITY
David Ludwig <dludwig@pobox.com>
parents: 8533
diff changeset
   961
    if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
724af2cd53b8 WinRT: added support for SDL_HINT_RENDER_SCALE_QUALITY
David Ludwig <dludwig@pobox.com>
parents: 8533
diff changeset
   962
        return SDL_D3D11_NEAREST_PIXEL_FILTER;
724af2cd53b8 WinRT: added support for SDL_HINT_RENDER_SCALE_QUALITY
David Ludwig <dludwig@pobox.com>
parents: 8533
diff changeset
   963
    } else /* if (*hint == '1' || SDL_strcasecmp(hint, "linear") == 0) */ {
724af2cd53b8 WinRT: added support for SDL_HINT_RENDER_SCALE_QUALITY
David Ludwig <dludwig@pobox.com>
parents: 8533
diff changeset
   964
        return SDL_D3D11_LINEAR_FILTER;
724af2cd53b8 WinRT: added support for SDL_HINT_RENDER_SCALE_QUALITY
David Ludwig <dludwig@pobox.com>
parents: 8533
diff changeset
   965
    }
724af2cd53b8 WinRT: added support for SDL_HINT_RENDER_SCALE_QUALITY
David Ludwig <dludwig@pobox.com>
parents: 8533
diff changeset
   966
}
724af2cd53b8 WinRT: added support for SDL_HINT_RENDER_SCALE_QUALITY
David Ludwig <dludwig@pobox.com>
parents: 8533
diff changeset
   967
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
   968
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
   969
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
   970
{
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   971
    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
   972
    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
   973
    HRESULT result;
8454
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   974
    DXGI_FORMAT textureFormat = SDLPixelFormatToDXGIFormat(texture->format);
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   975
    if (textureFormat == SDL_PIXELFORMAT_UNKNOWN) {
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   976
        SDL_SetError("%s, An unsupported SDL pixel format (0x%x) was specified",
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   977
            __FUNCTION__, texture->format);
ac6a37f54dc2 WinRT: implemented SDL_RenderReadPixels in Direct3D 11.1
David Ludwig <dludwig@pobox.com>
parents: 8452
diff changeset
   978
        return -1;
8442
7046465c646c WinRT: added support for alpha-blended texture rendering
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   979
    }
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
   980
17040ce2693d WinRT: moved texture management code from SDL_winrtrenderer to the D3D 11.1 SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
   981
    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: