src/render/direct3d11/SDL_render_d3d11.c
changeset 9158 8fa5ff95c410
parent 8969 7fb90df60b99
child 9335 3eb0896ecb91
equal deleted inserted replaced
9157:c4f435c99e16 9158:8fa5ff95c410
  1328             return FALSE;
  1328             return FALSE;
  1329     }
  1329     }
  1330 }
  1330 }
  1331 
  1331 
  1332 static int
  1332 static int
       
  1333 D3D11_GetRotationForCurrentRenderTarget(SDL_Renderer * renderer)
       
  1334 {
       
  1335     D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata;
       
  1336     if (data->currentOffscreenRenderTargetView) {
       
  1337         return DXGI_MODE_ROTATION_IDENTITY;
       
  1338     } else {
       
  1339         return data->rotation;
       
  1340     }
       
  1341 }
       
  1342 
       
  1343 static int
  1333 D3D11_GetViewportAlignedD3DRect(SDL_Renderer * renderer, const SDL_Rect * sdlRect, D3D11_RECT * outRect)
  1344 D3D11_GetViewportAlignedD3DRect(SDL_Renderer * renderer, const SDL_Rect * sdlRect, D3D11_RECT * outRect)
  1334 {
  1345 {
  1335     D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
  1346     D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
  1336     switch (data->rotation) {
  1347     const int rotation = D3D11_GetRotationForCurrentRenderTarget(renderer);
       
  1348     switch (rotation) {
  1337         case DXGI_MODE_ROTATION_IDENTITY:
  1349         case DXGI_MODE_ROTATION_IDENTITY:
  1338             outRect->left = sdlRect->x;
  1350             outRect->left = sdlRect->x;
  1339             outRect->right = sdlRect->x + sdlRect->w;
  1351             outRect->right = sdlRect->x + sdlRect->w;
  1340             outRect->top = sdlRect->y;
  1352             outRect->top = sdlRect->y;
  1341             outRect->bottom = sdlRect->y + sdlRect->h;
  1353             outRect->bottom = sdlRect->y + sdlRect->h;
  2149     Float4X4 projection;
  2161     Float4X4 projection;
  2150     Float4X4 view;
  2162     Float4X4 view;
  2151     SDL_FRect orientationAlignedViewport;
  2163     SDL_FRect orientationAlignedViewport;
  2152     BOOL swapDimensions;
  2164     BOOL swapDimensions;
  2153     D3D11_VIEWPORT viewport;
  2165     D3D11_VIEWPORT viewport;
       
  2166     const int rotation = D3D11_GetRotationForCurrentRenderTarget(renderer);
  2154 
  2167 
  2155     if (renderer->viewport.w == 0 || renderer->viewport.h == 0) {
  2168     if (renderer->viewport.w == 0 || renderer->viewport.h == 0) {
  2156         /* If the viewport is empty, assume that it is because
  2169         /* If the viewport is empty, assume that it is because
  2157          * SDL_CreateRenderer is calling it, and will call it again later
  2170          * SDL_CreateRenderer is calling it, and will call it again later
  2158          * with a non-empty viewport.
  2171          * with a non-empty viewport.
  2164     /* Make sure the SDL viewport gets rotated to that of the physical display's rotation.
  2177     /* Make sure the SDL viewport gets rotated to that of the physical display's rotation.
  2165      * Keep in mind here that the Y-axis will be been inverted (from Direct3D's
  2178      * Keep in mind here that the Y-axis will be been inverted (from Direct3D's
  2166      * default coordinate system) so rotations will be done in the opposite
  2179      * default coordinate system) so rotations will be done in the opposite
  2167      * direction of the DXGI_MODE_ROTATION enumeration.
  2180      * direction of the DXGI_MODE_ROTATION enumeration.
  2168      */
  2181      */
  2169     switch (data->rotation) {
  2182     switch (rotation) {
  2170         case DXGI_MODE_ROTATION_IDENTITY:
  2183         case DXGI_MODE_ROTATION_IDENTITY:
  2171             projection = MatrixIdentity();
  2184             projection = MatrixIdentity();
  2172             break;
  2185             break;
  2173         case DXGI_MODE_ROTATION_ROTATE270:
  2186         case DXGI_MODE_ROTATION_ROTATE270:
  2174             projection = MatrixRotationZ(SDL_static_cast(float, M_PI * 0.5f));
  2187             projection = MatrixRotationZ(SDL_static_cast(float, M_PI * 0.5f));
  2215     /* Update the Direct3D viewport, which seems to be aligned to the
  2228     /* Update the Direct3D viewport, which seems to be aligned to the
  2216      * swap buffer's coordinate space, which is always in either
  2229      * swap buffer's coordinate space, which is always in either
  2217      * a landscape mode, for all Windows 8/RT devices, or a portrait mode,
  2230      * a landscape mode, for all Windows 8/RT devices, or a portrait mode,
  2218      * for Windows Phone devices.
  2231      * for Windows Phone devices.
  2219      */
  2232      */
  2220     swapDimensions = D3D11_IsDisplayRotated90Degrees(data->rotation);
  2233     swapDimensions = D3D11_IsDisplayRotated90Degrees(rotation);
  2221     if (swapDimensions) {
  2234     if (swapDimensions) {
  2222         orientationAlignedViewport.x = (float) renderer->viewport.y;
  2235         orientationAlignedViewport.x = (float) renderer->viewport.y;
  2223         orientationAlignedViewport.y = (float) renderer->viewport.x;
  2236         orientationAlignedViewport.y = (float) renderer->viewport.x;
  2224         orientationAlignedViewport.w = (float) renderer->viewport.h;
  2237         orientationAlignedViewport.w = (float) renderer->viewport.h;
  2225         orientationAlignedViewport.h = (float) renderer->viewport.w;
  2238         orientationAlignedViewport.h = (float) renderer->viewport.w;