src/render/SDL_d3dmath.c
author Ryan C. Gordon <icculus@icculus.org>
Thu, 09 Apr 2015 22:28:37 -0400
changeset 9541 cf8fab52e33b
parent 8764 3d5ef7548688
child 9619 b94b6d0bff0f
permissions -rw-r--r--
Merged Alex Szpakowski's iOS-improvement branch to default.

Fixes Bugzilla #2798.
Fixes Bugzilla #2212.
Fixes Bugzilla #2826.
Fixes Bugzilla #2661.
Fixes Bugzilla #1885.
Fixes Bugzilla #1578.
Fixes Bugzilla #2751.

(whew!)

Notable changes, from Alex's notes:

- The SDL_WINDOW_ALLOW_HIGHDPI flag is now needed (along with SDL_GL_GetDrawableSize or SDL_GetRendererOutputSize) to use Retina / high DPI resolutions, bringing SDL’s Retina-related behavior on iOS in line with Mac OS X. Window dimensions and display modes are now in the “points” (non-high DPI) coordinate system rather than pixels, whereas SDL_GL_GetDrawableSize is in pixels.

- Reworked the custom extended launch screen code:
- It now hides after the first SDL_PumpEvents call rather than SDL_CreateWindow, and it fades out in a similar manner to the system launch screen behavior.
- It now mirrors the system launch screen behavior when deciding which image to display: it falls back to using the Launch Images dictionary in Info.plist if the iOS 8+ launch screen nib isn’t available, and if the Launch Images dictionary doesn’t exist it uses the old standard launch image names.
- The extended launch screen can now be disabled via the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h.

- Added support for SDL_HINT_ACCELEROMETER_AS_JOYSTICK.

- Added access to a window view's renderbuffer and framebuffer to syswm.

- Added OpenGL ES debug labels for the Renderbuffer and Framebuffer Objects created with SDL_GL_CreateContext.

- Added support for sRGB OpenGL ES contexts on iOS 7+.

- Updated OpenGL ES contexts to support native-resolution rendering (when SDL_WINDOW_ALLOW_HIGHDPI is enabled) on the iPhone 6 Plus, i.e. 1080x1920 rather than 1242x2208.

- Updated SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext to be more robust.

- Updated SDL windows to display a UIView at all times, even when an OpenGL context is not active. This allows rotation, touch events, and other windowing-related events to work properly without an active OpenGL context. It also makes it easier to use SDL_GetWindowWMInfo after creating a SDL window.

- Updated the iOS-specific Objective-C code to use cleaner and more modern language features and APIs, including ARC instead of manual reference counting.

- Updated SDL_HINT_ORIENTATIONS to allow disabling custom orientations if the hint is set with no valid orientation names.

- Fixed several rotation and orientation bugs with windows and display modes, especially in iOS 8+.

- Fixed SDL_SetWindowFullscreen failing to update the status bar visibility on iOS 7+.

- Fixed the orientation of the offset applied to the window’s view when the onscreen keyboard is shown in iOS 8+.

- Fixed SDL_IsScreenKeyboardShown (patch by Phil Hassey.)

- Fixed several major memory leaks caused by missing autorelease pool blocks in the iOS-specific Objective-C code.

- Removed several dead code paths.

- The iOS 7 SDK (Xcode 5) or newer is now required to build SDL for iOS.
slouken@8599
     1
/*
slouken@8599
     2
  Simple DirectMedia Layer
slouken@8599
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
slouken@8599
     4
slouken@8599
     5
  This software is provided 'as-is', without any express or implied
slouken@8599
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@8599
     7
  arising from the use of this software.
slouken@8599
     8
slouken@8599
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@8599
    10
  including commercial applications, and to alter it and redistribute it
slouken@8599
    11
  freely, subject to the following restrictions:
slouken@8599
    12
slouken@8599
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@8599
    14
     claim that you wrote the original software. If you use this software
slouken@8599
    15
     in a product, an acknowledgment in the product documentation would be
slouken@8599
    16
     appreciated but is not required.
slouken@8599
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@8599
    18
     misrepresented as being the original software.
slouken@8599
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@8599
    20
*/
slouken@8599
    21
#include "../SDL_internal.h"
gabomdq@8764
    22
gabomdq@8764
    23
#if (SDL_VIDEO_RENDER_D3D || SDL_VIDEO_RENDER_D3D11) && !SDL_RENDER_DISABLED
slouken@8599
    24
#include "SDL_stdinc.h"
slouken@8599
    25
slouken@8599
    26
#include "SDL_d3dmath.h"
slouken@8599
    27
slouken@8599
    28
/* Direct3D matrix math functions */
slouken@8599
    29
slouken@8599
    30
Float4X4 MatrixIdentity()
slouken@8599
    31
{
slouken@8599
    32
    Float4X4 m;
slouken@8599
    33
    SDL_zero(m);
slouken@8599
    34
    m._11 = 1.0f;
slouken@8599
    35
    m._22 = 1.0f;
slouken@8599
    36
    m._33 = 1.0f;
slouken@8599
    37
    m._44 = 1.0f;
slouken@8599
    38
    return m;
slouken@8599
    39
}
slouken@8599
    40
slouken@8599
    41
Float4X4 MatrixMultiply(Float4X4 M1, Float4X4 M2)
slouken@8599
    42
{
slouken@8599
    43
    Float4X4 m;
slouken@8599
    44
    m._11 = M1._11 * M2._11 + M1._12 * M2._21 + M1._13 * M2._31 + M1._14 * M2._41;
slouken@8599
    45
    m._12 = M1._11 * M2._12 + M1._12 * M2._22 + M1._13 * M2._32 + M1._14 * M2._42;
slouken@8599
    46
    m._13 = M1._11 * M2._13 + M1._12 * M2._23 + M1._13 * M2._33 + M1._14 * M2._43;
slouken@8599
    47
    m._14 = M1._11 * M2._14 + M1._12 * M2._24 + M1._13 * M2._34 + M1._14 * M2._44;
slouken@8599
    48
    m._21 = M1._21 * M2._11 + M1._22 * M2._21 + M1._23 * M2._31 + M1._24 * M2._41;
slouken@8599
    49
    m._22 = M1._21 * M2._12 + M1._22 * M2._22 + M1._23 * M2._32 + M1._24 * M2._42;
slouken@8599
    50
    m._23 = M1._21 * M2._13 + M1._22 * M2._23 + M1._23 * M2._33 + M1._24 * M2._43;
slouken@8599
    51
    m._24 = M1._21 * M2._14 + M1._22 * M2._24 + M1._23 * M2._34 + M1._24 * M2._44;
slouken@8599
    52
    m._31 = M1._31 * M2._11 + M1._32 * M2._21 + M1._33 * M2._31 + M1._34 * M2._41;
slouken@8599
    53
    m._32 = M1._31 * M2._12 + M1._32 * M2._22 + M1._33 * M2._32 + M1._34 * M2._42;
slouken@8599
    54
    m._33 = M1._31 * M2._13 + M1._32 * M2._23 + M1._33 * M2._33 + M1._34 * M2._43;
slouken@8599
    55
    m._34 = M1._31 * M2._14 + M1._32 * M2._24 + M1._33 * M2._34 + M1._34 * M2._44;
slouken@8599
    56
    m._41 = M1._41 * M2._11 + M1._42 * M2._21 + M1._43 * M2._31 + M1._44 * M2._41;
slouken@8599
    57
    m._42 = M1._41 * M2._12 + M1._42 * M2._22 + M1._43 * M2._32 + M1._44 * M2._42;
slouken@8599
    58
    m._43 = M1._41 * M2._13 + M1._42 * M2._23 + M1._43 * M2._33 + M1._44 * M2._43;
slouken@8599
    59
    m._44 = M1._41 * M2._14 + M1._42 * M2._24 + M1._43 * M2._34 + M1._44 * M2._44;
slouken@8599
    60
    return m;
slouken@8599
    61
}
slouken@8599
    62
slouken@8599
    63
Float4X4 MatrixScaling(float x, float y, float z)
slouken@8599
    64
{
slouken@8599
    65
    Float4X4 m;
slouken@8599
    66
    SDL_zero(m);
slouken@8599
    67
    m._11 = x;
slouken@8599
    68
    m._22 = y;
slouken@8599
    69
    m._33 = z;
slouken@8599
    70
    m._44 = 1.0f;
slouken@8599
    71
    return m;
slouken@8599
    72
}
slouken@8599
    73
slouken@8599
    74
Float4X4 MatrixTranslation(float x, float y, float z)
slouken@8599
    75
{
slouken@8599
    76
    Float4X4 m;
slouken@8599
    77
    SDL_zero(m);
slouken@8599
    78
    m._11 = 1.0f;
slouken@8599
    79
    m._22 = 1.0f;
slouken@8599
    80
    m._33 = 1.0f;
slouken@8599
    81
    m._44 = 1.0f;
slouken@8599
    82
    m._41 = x;
slouken@8599
    83
    m._42 = y;
slouken@8599
    84
    m._43 = z;
slouken@8599
    85
    return m;
slouken@8599
    86
}
slouken@8599
    87
slouken@8599
    88
Float4X4 MatrixRotationX(float r)
slouken@8599
    89
{
slouken@8599
    90
    float sinR = SDL_sinf(r);
slouken@8599
    91
    float cosR = SDL_cosf(r);
slouken@8599
    92
    Float4X4 m;
slouken@8599
    93
    SDL_zero(m);
slouken@8599
    94
    m._11 = 1.0f;
slouken@8599
    95
    m._22 = cosR;
slouken@8599
    96
    m._23 = sinR;
slouken@8599
    97
    m._32 = -sinR;
slouken@8599
    98
    m._33 = cosR;
slouken@8599
    99
    m._44 = 1.0f;
slouken@8599
   100
    return m;
slouken@8599
   101
}
slouken@8599
   102
slouken@8599
   103
Float4X4 MatrixRotationY(float r)
slouken@8599
   104
{
slouken@8599
   105
    float sinR = SDL_sinf(r);
slouken@8599
   106
    float cosR = SDL_cosf(r);
slouken@8599
   107
    Float4X4 m;
slouken@8599
   108
    SDL_zero(m);
slouken@8599
   109
    m._11 = cosR;
slouken@8599
   110
    m._13 = -sinR;
slouken@8599
   111
    m._22 = 1.0f;
slouken@8599
   112
    m._31 = sinR;
slouken@8599
   113
    m._33 = cosR;
slouken@8599
   114
    m._44 = 1.0f;
slouken@8599
   115
    return m;
slouken@8599
   116
}
slouken@8599
   117
slouken@8599
   118
Float4X4 MatrixRotationZ(float r)
slouken@8599
   119
{
slouken@8599
   120
    float sinR = SDL_sinf(r);
slouken@8599
   121
    float cosR = SDL_cosf(r);
slouken@8599
   122
    Float4X4 m;
slouken@8599
   123
    SDL_zero(m);
slouken@8599
   124
    m._11 = cosR;
slouken@8599
   125
    m._12 = sinR;
slouken@8599
   126
    m._21 = -sinR;
slouken@8599
   127
    m._22 = cosR;
slouken@8599
   128
    m._33 = 1.0f;
slouken@8599
   129
    m._44 = 1.0f;
slouken@8599
   130
    return m;
gabomdq@8764
   131
slouken@8599
   132
}
slouken@8599
   133
gabomdq@8764
   134
#endif /* (SDL_VIDEO_RENDER_D3D || SDL_VIDEO_RENDER_D3D11) && !SDL_RENDER_DISABLED */
gabomdq@8764
   135
slouken@8599
   136
/* vi: set ts=4 sw=4 expandtab: */