diff options
Diffstat (limited to '3rdparty/SDL2/src/render')
38 files changed, 0 insertions, 22077 deletions
diff --git a/3rdparty/SDL2/src/render/SDL_d3dmath.c b/3rdparty/SDL2/src/render/SDL_d3dmath.c deleted file mode 100644 index 83d67bfa703..00000000000 --- a/3rdparty/SDL2/src/render/SDL_d3dmath.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../SDL_internal.h" - -#if (SDL_VIDEO_RENDER_D3D || SDL_VIDEO_RENDER_D3D11) && !SDL_RENDER_DISABLED -#include "SDL_stdinc.h" - -#include "SDL_d3dmath.h" - -/* Direct3D matrix math functions */ - -Float4X4 MatrixIdentity() -{ - Float4X4 m; - SDL_zero(m); - m._11 = 1.0f; - m._22 = 1.0f; - m._33 = 1.0f; - m._44 = 1.0f; - return m; -} - -Float4X4 MatrixMultiply(Float4X4 M1, Float4X4 M2) -{ - Float4X4 m; - m._11 = M1._11 * M2._11 + M1._12 * M2._21 + M1._13 * M2._31 + M1._14 * M2._41; - m._12 = M1._11 * M2._12 + M1._12 * M2._22 + M1._13 * M2._32 + M1._14 * M2._42; - m._13 = M1._11 * M2._13 + M1._12 * M2._23 + M1._13 * M2._33 + M1._14 * M2._43; - m._14 = M1._11 * M2._14 + M1._12 * M2._24 + M1._13 * M2._34 + M1._14 * M2._44; - m._21 = M1._21 * M2._11 + M1._22 * M2._21 + M1._23 * M2._31 + M1._24 * M2._41; - m._22 = M1._21 * M2._12 + M1._22 * M2._22 + M1._23 * M2._32 + M1._24 * M2._42; - m._23 = M1._21 * M2._13 + M1._22 * M2._23 + M1._23 * M2._33 + M1._24 * M2._43; - m._24 = M1._21 * M2._14 + M1._22 * M2._24 + M1._23 * M2._34 + M1._24 * M2._44; - m._31 = M1._31 * M2._11 + M1._32 * M2._21 + M1._33 * M2._31 + M1._34 * M2._41; - m._32 = M1._31 * M2._12 + M1._32 * M2._22 + M1._33 * M2._32 + M1._34 * M2._42; - m._33 = M1._31 * M2._13 + M1._32 * M2._23 + M1._33 * M2._33 + M1._34 * M2._43; - m._34 = M1._31 * M2._14 + M1._32 * M2._24 + M1._33 * M2._34 + M1._34 * M2._44; - m._41 = M1._41 * M2._11 + M1._42 * M2._21 + M1._43 * M2._31 + M1._44 * M2._41; - m._42 = M1._41 * M2._12 + M1._42 * M2._22 + M1._43 * M2._32 + M1._44 * M2._42; - m._43 = M1._41 * M2._13 + M1._42 * M2._23 + M1._43 * M2._33 + M1._44 * M2._43; - m._44 = M1._41 * M2._14 + M1._42 * M2._24 + M1._43 * M2._34 + M1._44 * M2._44; - return m; -} - -Float4X4 MatrixScaling(float x, float y, float z) -{ - Float4X4 m; - SDL_zero(m); - m._11 = x; - m._22 = y; - m._33 = z; - m._44 = 1.0f; - return m; -} - -Float4X4 MatrixTranslation(float x, float y, float z) -{ - Float4X4 m; - SDL_zero(m); - m._11 = 1.0f; - m._22 = 1.0f; - m._33 = 1.0f; - m._44 = 1.0f; - m._41 = x; - m._42 = y; - m._43 = z; - return m; -} - -Float4X4 MatrixRotationX(float r) -{ - float sinR = SDL_sinf(r); - float cosR = SDL_cosf(r); - Float4X4 m; - SDL_zero(m); - m._11 = 1.0f; - m._22 = cosR; - m._23 = sinR; - m._32 = -sinR; - m._33 = cosR; - m._44 = 1.0f; - return m; -} - -Float4X4 MatrixRotationY(float r) -{ - float sinR = SDL_sinf(r); - float cosR = SDL_cosf(r); - Float4X4 m; - SDL_zero(m); - m._11 = cosR; - m._13 = -sinR; - m._22 = 1.0f; - m._31 = sinR; - m._33 = cosR; - m._44 = 1.0f; - return m; -} - -Float4X4 MatrixRotationZ(float r) -{ - float sinR = SDL_sinf(r); - float cosR = SDL_cosf(r); - Float4X4 m; - SDL_zero(m); - m._11 = cosR; - m._12 = sinR; - m._21 = -sinR; - m._22 = cosR; - m._33 = 1.0f; - m._44 = 1.0f; - return m; - -} - -#endif /* (SDL_VIDEO_RENDER_D3D || SDL_VIDEO_RENDER_D3D11) && !SDL_RENDER_DISABLED */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/SDL_d3dmath.h b/3rdparty/SDL2/src/render/SDL_d3dmath.h deleted file mode 100644 index 87c44c7a331..00000000000 --- a/3rdparty/SDL2/src/render/SDL_d3dmath.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../SDL_internal.h" - -#if (SDL_VIDEO_RENDER_D3D || SDL_VIDEO_RENDER_D3D11) && !SDL_RENDER_DISABLED - -/* Direct3D matrix math functions */ - -typedef struct -{ - float x; - float y; -} Float2; - -typedef struct -{ - float x; - float y; - float z; -} Float3; - -typedef struct -{ - float x; - float y; - float z; - float w; -} Float4; - -typedef struct -{ - union { - struct { - float _11, _12, _13, _14; - float _21, _22, _23, _24; - float _31, _32, _33, _34; - float _41, _42, _43, _44; - }; - float m[4][4]; - }; -} Float4X4; - - -Float4X4 MatrixIdentity(); -Float4X4 MatrixMultiply(Float4X4 M1, Float4X4 M2); -Float4X4 MatrixScaling(float x, float y, float z); -Float4X4 MatrixTranslation(float x, float y, float z); -Float4X4 MatrixRotationX(float r); -Float4X4 MatrixRotationY(float r); -Float4X4 MatrixRotationZ(float r); - -#endif /* (SDL_VIDEO_RENDER_D3D || SDL_VIDEO_RENDER_D3D11) && !SDL_RENDER_DISABLED */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/SDL_render.c b/3rdparty/SDL2/src/render/SDL_render.c deleted file mode 100644 index 94750810d8b..00000000000 --- a/3rdparty/SDL2/src/render/SDL_render.c +++ /dev/null @@ -1,1973 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../SDL_internal.h" - -/* The SDL 2D rendering system */ - -#include "SDL_assert.h" -#include "SDL_hints.h" -#include "SDL_log.h" -#include "SDL_render.h" -#include "SDL_sysrender.h" -#include "software/SDL_render_sw_c.h" - - -#define SDL_WINDOWRENDERDATA "_SDL_WindowRenderData" - -#define CHECK_RENDERER_MAGIC(renderer, retval) \ - if (!renderer || renderer->magic != &renderer_magic) { \ - SDL_SetError("Invalid renderer"); \ - return retval; \ - } - -#define CHECK_TEXTURE_MAGIC(texture, retval) \ - if (!texture || texture->magic != &texture_magic) { \ - SDL_SetError("Invalid texture"); \ - return retval; \ - } - - -#if !SDL_RENDER_DISABLED -static const SDL_RenderDriver *render_drivers[] = { -#if SDL_VIDEO_RENDER_D3D - &D3D_RenderDriver, -#endif -#if SDL_VIDEO_RENDER_D3D11 - &D3D11_RenderDriver, -#endif -#if SDL_VIDEO_RENDER_OGL - &GL_RenderDriver, -#endif -#if SDL_VIDEO_RENDER_OGL_ES2 - &GLES2_RenderDriver, -#endif -#if SDL_VIDEO_RENDER_OGL_ES - &GLES_RenderDriver, -#endif -#if SDL_VIDEO_RENDER_DIRECTFB - &DirectFB_RenderDriver, -#endif -#if SDL_VIDEO_RENDER_PSP - &PSP_RenderDriver, -#endif - &SW_RenderDriver -}; -#endif /* !SDL_RENDER_DISABLED */ - -static char renderer_magic; -static char texture_magic; - -static int UpdateLogicalSize(SDL_Renderer *renderer); - -int -SDL_GetNumRenderDrivers(void) -{ -#if !SDL_RENDER_DISABLED - return SDL_arraysize(render_drivers); -#else - return 0; -#endif -} - -int -SDL_GetRenderDriverInfo(int index, SDL_RendererInfo * info) -{ -#if !SDL_RENDER_DISABLED - if (index < 0 || index >= SDL_GetNumRenderDrivers()) { - return SDL_SetError("index must be in the range of 0 - %d", - SDL_GetNumRenderDrivers() - 1); - } - *info = render_drivers[index]->info; - return 0; -#else - return SDL_SetError("SDL not built with rendering support"); -#endif -} - -static int -SDL_RendererEventWatch(void *userdata, SDL_Event *event) -{ - SDL_Renderer *renderer = (SDL_Renderer *)userdata; - - if (event->type == SDL_WINDOWEVENT) { - SDL_Window *window = SDL_GetWindowFromID(event->window.windowID); - if (window == renderer->window) { - if (renderer->WindowEvent) { - renderer->WindowEvent(renderer, &event->window); - } - - if (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { - /* Make sure we're operating on the default render target */ - SDL_Texture *saved_target = SDL_GetRenderTarget(renderer); - if (saved_target) { - SDL_SetRenderTarget(renderer, NULL); - } - - if (renderer->logical_w) { - UpdateLogicalSize(renderer); - } else { - /* Window was resized, reset viewport */ - int w, h; - - if (renderer->GetOutputSize) { - renderer->GetOutputSize(renderer, &w, &h); - } else { - SDL_GetWindowSize(renderer->window, &w, &h); - } - - if (renderer->target) { - renderer->viewport_backup.x = 0; - renderer->viewport_backup.y = 0; - renderer->viewport_backup.w = w; - renderer->viewport_backup.h = h; - } else { - renderer->viewport.x = 0; - renderer->viewport.y = 0; - renderer->viewport.w = w; - renderer->viewport.h = h; - renderer->UpdateViewport(renderer); - } - } - - if (saved_target) { - SDL_SetRenderTarget(renderer, saved_target); - } - } else if (event->window.event == SDL_WINDOWEVENT_HIDDEN) { - renderer->hidden = SDL_TRUE; - } else if (event->window.event == SDL_WINDOWEVENT_SHOWN) { - if (!(SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED)) { - renderer->hidden = SDL_FALSE; - } - } else if (event->window.event == SDL_WINDOWEVENT_MINIMIZED) { - renderer->hidden = SDL_TRUE; - } else if (event->window.event == SDL_WINDOWEVENT_RESTORED || - event->window.event == SDL_WINDOWEVENT_MAXIMIZED) { - if (!(SDL_GetWindowFlags(window) & SDL_WINDOW_HIDDEN)) { - renderer->hidden = SDL_FALSE; - } - } - } - } else if (event->type == SDL_MOUSEMOTION) { - SDL_Window *window = SDL_GetWindowFromID(event->motion.windowID); - if (renderer->logical_w && window == renderer->window) { - event->motion.x -= renderer->viewport.x; - event->motion.y -= renderer->viewport.y; - event->motion.x = (int)(event->motion.x / renderer->scale.x); - event->motion.y = (int)(event->motion.y / renderer->scale.y); - if (event->motion.xrel > 0) { - event->motion.xrel = SDL_max(1, (int)(event->motion.xrel / renderer->scale.x)); - } else if (event->motion.xrel < 0) { - event->motion.xrel = SDL_min(-1, (int)(event->motion.xrel / renderer->scale.x)); - } - if (event->motion.yrel > 0) { - event->motion.yrel = SDL_max(1, (int)(event->motion.yrel / renderer->scale.y)); - } else if (event->motion.yrel < 0) { - event->motion.yrel = SDL_min(-1, (int)(event->motion.yrel / renderer->scale.y)); - } - } - } else if (event->type == SDL_MOUSEBUTTONDOWN || - event->type == SDL_MOUSEBUTTONUP) { - SDL_Window *window = SDL_GetWindowFromID(event->button.windowID); - if (renderer->logical_w && window == renderer->window) { - event->button.x -= renderer->viewport.x; - event->button.y -= renderer->viewport.y; - event->button.x = (int)(event->button.x / renderer->scale.x); - event->button.y = (int)(event->button.y / renderer->scale.y); - } - } - return 0; -} - -int -SDL_CreateWindowAndRenderer(int width, int height, Uint32 window_flags, - SDL_Window **window, SDL_Renderer **renderer) -{ - *window = SDL_CreateWindow(NULL, SDL_WINDOWPOS_UNDEFINED, - SDL_WINDOWPOS_UNDEFINED, - width, height, window_flags); - if (!*window) { - *renderer = NULL; - return -1; - } - - *renderer = SDL_CreateRenderer(*window, -1, 0); - if (!*renderer) { - return -1; - } - - return 0; -} - -SDL_Renderer * -SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags) -{ -#if !SDL_RENDER_DISABLED - SDL_Renderer *renderer = NULL; - int n = SDL_GetNumRenderDrivers(); - const char *hint; - - if (!window) { - SDL_SetError("Invalid window"); - return NULL; - } - - if (SDL_GetRenderer(window)) { - SDL_SetError("Renderer already associated with window"); - return NULL; - } - - if (SDL_GetHint(SDL_HINT_RENDER_VSYNC)) { - if (SDL_GetHintBoolean(SDL_HINT_RENDER_VSYNC, SDL_TRUE)) { - flags |= SDL_RENDERER_PRESENTVSYNC; - } else { - flags &= ~SDL_RENDERER_PRESENTVSYNC; - } - } - - if (index < 0) { - hint = SDL_GetHint(SDL_HINT_RENDER_DRIVER); - if (hint) { - for (index = 0; index < n; ++index) { - const SDL_RenderDriver *driver = render_drivers[index]; - - if (SDL_strcasecmp(hint, driver->info.name) == 0) { - /* Create a new renderer instance */ - renderer = driver->CreateRenderer(window, flags); - break; - } - } - } - - if (!renderer) { - for (index = 0; index < n; ++index) { - const SDL_RenderDriver *driver = render_drivers[index]; - - if ((driver->info.flags & flags) == flags) { - /* Create a new renderer instance */ - renderer = driver->CreateRenderer(window, flags); - if (renderer) { - /* Yay, we got one! */ - break; - } - } - } - } - if (index == n) { - SDL_SetError("Couldn't find matching render driver"); - return NULL; - } - } else { - if (index >= SDL_GetNumRenderDrivers()) { - SDL_SetError("index must be -1 or in the range of 0 - %d", - SDL_GetNumRenderDrivers() - 1); - return NULL; - } - /* Create a new renderer instance */ - renderer = render_drivers[index]->CreateRenderer(window, flags); - } - - if (renderer) { - renderer->magic = &renderer_magic; - renderer->window = window; - renderer->scale.x = 1.0f; - renderer->scale.y = 1.0f; - - if (SDL_GetWindowFlags(window) & (SDL_WINDOW_HIDDEN|SDL_WINDOW_MINIMIZED)) { - renderer->hidden = SDL_TRUE; - } else { - renderer->hidden = SDL_FALSE; - } - - SDL_SetWindowData(window, SDL_WINDOWRENDERDATA, renderer); - - SDL_RenderSetViewport(renderer, NULL); - - SDL_AddEventWatch(SDL_RendererEventWatch, renderer); - - SDL_LogInfo(SDL_LOG_CATEGORY_RENDER, - "Created renderer: %s", renderer->info.name); - } - return renderer; -#else - SDL_SetError("SDL not built with rendering support"); - return NULL; -#endif -} - -SDL_Renderer * -SDL_CreateSoftwareRenderer(SDL_Surface * surface) -{ -#if !SDL_RENDER_DISABLED - SDL_Renderer *renderer; - - renderer = SW_CreateRendererForSurface(surface); - - if (renderer) { - renderer->magic = &renderer_magic; - renderer->scale.x = 1.0f; - renderer->scale.y = 1.0f; - - SDL_RenderSetViewport(renderer, NULL); - } - return renderer; -#else - SDL_SetError("SDL not built with rendering support"); - return NULL; -#endif /* !SDL_RENDER_DISABLED */ -} - -SDL_Renderer * -SDL_GetRenderer(SDL_Window * window) -{ - return (SDL_Renderer *)SDL_GetWindowData(window, SDL_WINDOWRENDERDATA); -} - -int -SDL_GetRendererInfo(SDL_Renderer * renderer, SDL_RendererInfo * info) -{ - CHECK_RENDERER_MAGIC(renderer, -1); - - *info = renderer->info; - return 0; -} - -int -SDL_GetRendererOutputSize(SDL_Renderer * renderer, int *w, int *h) -{ - CHECK_RENDERER_MAGIC(renderer, -1); - - if (renderer->target) { - return SDL_QueryTexture(renderer->target, NULL, NULL, w, h); - } else if (renderer->GetOutputSize) { - return renderer->GetOutputSize(renderer, w, h); - } else if (renderer->window) { - SDL_GetWindowSize(renderer->window, w, h); - return 0; - } else { - SDL_assert(0 && "This should never happen"); - return SDL_SetError("Renderer doesn't support querying output size"); - } -} - -static SDL_bool -IsSupportedFormat(SDL_Renderer * renderer, Uint32 format) -{ - Uint32 i; - - for (i = 0; i < renderer->info.num_texture_formats; ++i) { - if (renderer->info.texture_formats[i] == format) { - return SDL_TRUE; - } - } - return SDL_FALSE; -} - -static Uint32 -GetClosestSupportedFormat(SDL_Renderer * renderer, Uint32 format) -{ - Uint32 i; - - if (SDL_ISPIXELFORMAT_FOURCC(format)) { - /* Look for an exact match */ - for (i = 0; i < renderer->info.num_texture_formats; ++i) { - if (renderer->info.texture_formats[i] == format) { - return renderer->info.texture_formats[i]; - } - } - } else { - SDL_bool hasAlpha = SDL_ISPIXELFORMAT_ALPHA(format); - - /* We just want to match the first format that has the same channels */ - for (i = 0; i < renderer->info.num_texture_formats; ++i) { - if (!SDL_ISPIXELFORMAT_FOURCC(renderer->info.texture_formats[i]) && - SDL_ISPIXELFORMAT_ALPHA(renderer->info.texture_formats[i]) == hasAlpha) { - return renderer->info.texture_formats[i]; - } - } - } - return renderer->info.texture_formats[0]; -} - -SDL_Texture * -SDL_CreateTexture(SDL_Renderer * renderer, Uint32 format, int access, int w, int h) -{ - SDL_Texture *texture; - - CHECK_RENDERER_MAGIC(renderer, NULL); - - if (!format) { - format = renderer->info.texture_formats[0]; - } - if (SDL_BYTESPERPIXEL(format) == 0) { - SDL_SetError("Invalid texture format"); - return NULL; - } - if (SDL_ISPIXELFORMAT_INDEXED(format)) { - SDL_SetError("Palettized textures are not supported"); - return NULL; - } - if (w <= 0 || h <= 0) { - SDL_SetError("Texture dimensions can't be 0"); - return NULL; - } - if ((renderer->info.max_texture_width && w > renderer->info.max_texture_width) || - (renderer->info.max_texture_height && h > renderer->info.max_texture_height)) { - SDL_SetError("Texture dimensions are limited to %dx%d", renderer->info.max_texture_width, renderer->info.max_texture_height); - return NULL; - } - texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture)); - if (!texture) { - SDL_OutOfMemory(); - return NULL; - } - texture->magic = &texture_magic; - texture->format = format; - texture->access = access; - texture->w = w; - texture->h = h; - texture->r = 255; - texture->g = 255; - texture->b = 255; - texture->a = 255; - texture->renderer = renderer; - texture->next = renderer->textures; - if (renderer->textures) { - renderer->textures->prev = texture; - } - renderer->textures = texture; - - if (IsSupportedFormat(renderer, format)) { - if (renderer->CreateTexture(renderer, texture) < 0) { - SDL_DestroyTexture(texture); - return NULL; - } - } else { - texture->native = SDL_CreateTexture(renderer, - GetClosestSupportedFormat(renderer, format), - access, w, h); - if (!texture->native) { - SDL_DestroyTexture(texture); - return NULL; - } - - /* Swap textures to have texture before texture->native in the list */ - texture->native->next = texture->next; - if (texture->native->next) { - texture->native->next->prev = texture->native; - } - texture->prev = texture->native->prev; - if (texture->prev) { - texture->prev->next = texture; - } - texture->native->prev = texture; - texture->next = texture->native; - renderer->textures = texture; - - if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { - texture->yuv = SDL_SW_CreateYUVTexture(format, w, h); - if (!texture->yuv) { - SDL_DestroyTexture(texture); - return NULL; - } - } else if (access == SDL_TEXTUREACCESS_STREAMING) { - /* The pitch is 4 byte aligned */ - texture->pitch = (((w * SDL_BYTESPERPIXEL(format)) + 3) & ~3); - texture->pixels = SDL_calloc(1, texture->pitch * h); - if (!texture->pixels) { - SDL_DestroyTexture(texture); - return NULL; - } - } - } - return texture; -} - -SDL_Texture * -SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface) -{ - const SDL_PixelFormat *fmt; - SDL_bool needAlpha; - Uint32 i; - Uint32 format; - SDL_Texture *texture; - - CHECK_RENDERER_MAGIC(renderer, NULL); - - if (!surface) { - SDL_SetError("SDL_CreateTextureFromSurface() passed NULL surface"); - return NULL; - } - - /* See what the best texture format is */ - fmt = surface->format; - if (fmt->Amask || SDL_GetColorKey(surface, NULL) == 0) { - needAlpha = SDL_TRUE; - } else { - needAlpha = SDL_FALSE; - } - format = renderer->info.texture_formats[0]; - for (i = 0; i < renderer->info.num_texture_formats; ++i) { - if (!SDL_ISPIXELFORMAT_FOURCC(renderer->info.texture_formats[i]) && - SDL_ISPIXELFORMAT_ALPHA(renderer->info.texture_formats[i]) == needAlpha) { - format = renderer->info.texture_formats[i]; - break; - } - } - - texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STATIC, - surface->w, surface->h); - if (!texture) { - return NULL; - } - - if (format == surface->format->format) { - if (SDL_MUSTLOCK(surface)) { - SDL_LockSurface(surface); - SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch); - SDL_UnlockSurface(surface); - } else { - SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch); - } - } else { - SDL_PixelFormat *dst_fmt; - SDL_Surface *temp = NULL; - - /* Set up a destination surface for the texture update */ - dst_fmt = SDL_AllocFormat(format); - if (!dst_fmt) { - SDL_DestroyTexture(texture); - return NULL; - } - temp = SDL_ConvertSurface(surface, dst_fmt, 0); - SDL_FreeFormat(dst_fmt); - if (temp) { - SDL_UpdateTexture(texture, NULL, temp->pixels, temp->pitch); - SDL_FreeSurface(temp); - } else { - SDL_DestroyTexture(texture); - return NULL; - } - } - - { - Uint8 r, g, b, a; - SDL_BlendMode blendMode; - - SDL_GetSurfaceColorMod(surface, &r, &g, &b); - SDL_SetTextureColorMod(texture, r, g, b); - - SDL_GetSurfaceAlphaMod(surface, &a); - SDL_SetTextureAlphaMod(texture, a); - - if (SDL_GetColorKey(surface, NULL) == 0) { - /* We converted to a texture with alpha format */ - SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); - } else { - SDL_GetSurfaceBlendMode(surface, &blendMode); - SDL_SetTextureBlendMode(texture, blendMode); - } - } - return texture; -} - -int -SDL_QueryTexture(SDL_Texture * texture, Uint32 * format, int *access, - int *w, int *h) -{ - CHECK_TEXTURE_MAGIC(texture, -1); - - if (format) { - *format = texture->format; - } - if (access) { - *access = texture->access; - } - if (w) { - *w = texture->w; - } - if (h) { - *h = texture->h; - } - return 0; -} - -int -SDL_SetTextureColorMod(SDL_Texture * texture, Uint8 r, Uint8 g, Uint8 b) -{ - SDL_Renderer *renderer; - - CHECK_TEXTURE_MAGIC(texture, -1); - - renderer = texture->renderer; - if (r < 255 || g < 255 || b < 255) { - texture->modMode |= SDL_TEXTUREMODULATE_COLOR; - } else { - texture->modMode &= ~SDL_TEXTUREMODULATE_COLOR; - } - texture->r = r; - texture->g = g; - texture->b = b; - if (texture->native) { - return SDL_SetTextureColorMod(texture->native, r, g, b); - } else if (renderer->SetTextureColorMod) { - return renderer->SetTextureColorMod(renderer, texture); - } else { - return 0; - } -} - -int -SDL_GetTextureColorMod(SDL_Texture * texture, Uint8 * r, Uint8 * g, - Uint8 * b) -{ - CHECK_TEXTURE_MAGIC(texture, -1); - - if (r) { - *r = texture->r; - } - if (g) { - *g = texture->g; - } - if (b) { - *b = texture->b; - } - return 0; -} - -int -SDL_SetTextureAlphaMod(SDL_Texture * texture, Uint8 alpha) -{ - SDL_Renderer *renderer; - - CHECK_TEXTURE_MAGIC(texture, -1); - - renderer = texture->renderer; - if (alpha < 255) { - texture->modMode |= SDL_TEXTUREMODULATE_ALPHA; - } else { - texture->modMode &= ~SDL_TEXTUREMODULATE_ALPHA; - } - texture->a = alpha; - if (texture->native) { - return SDL_SetTextureAlphaMod(texture->native, alpha); - } else if (renderer->SetTextureAlphaMod) { - return renderer->SetTextureAlphaMod(renderer, texture); - } else { - return 0; - } -} - -int -SDL_GetTextureAlphaMod(SDL_Texture * texture, Uint8 * alpha) -{ - CHECK_TEXTURE_MAGIC(texture, -1); - - if (alpha) { - *alpha = texture->a; - } - return 0; -} - -int -SDL_SetTextureBlendMode(SDL_Texture * texture, SDL_BlendMode blendMode) -{ - SDL_Renderer *renderer; - - CHECK_TEXTURE_MAGIC(texture, -1); - - renderer = texture->renderer; - texture->blendMode = blendMode; - if (texture->native) { - return SDL_SetTextureBlendMode(texture->native, blendMode); - } else if (renderer->SetTextureBlendMode) { - return renderer->SetTextureBlendMode(renderer, texture); - } else { - return 0; - } -} - -int -SDL_GetTextureBlendMode(SDL_Texture * texture, SDL_BlendMode *blendMode) -{ - CHECK_TEXTURE_MAGIC(texture, -1); - - if (blendMode) { - *blendMode = texture->blendMode; - } - return 0; -} - -static int -SDL_UpdateTextureYUV(SDL_Texture * texture, const SDL_Rect * rect, - const void *pixels, int pitch) -{ - SDL_Texture *native = texture->native; - SDL_Rect full_rect; - - if (SDL_SW_UpdateYUVTexture(texture->yuv, rect, pixels, pitch) < 0) { - return -1; - } - - full_rect.x = 0; - full_rect.y = 0; - full_rect.w = texture->w; - full_rect.h = texture->h; - rect = &full_rect; - - if (texture->access == SDL_TEXTUREACCESS_STREAMING) { - /* We can lock the texture and copy to it */ - void *native_pixels; - int native_pitch; - - if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) { - return -1; - } - SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, - rect->w, rect->h, native_pixels, native_pitch); - SDL_UnlockTexture(native); - } else { - /* Use a temporary buffer for updating */ - void *temp_pixels; - int temp_pitch; - - temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3); - temp_pixels = SDL_malloc(rect->h * temp_pitch); - if (!temp_pixels) { - return SDL_OutOfMemory(); - } - SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, - rect->w, rect->h, temp_pixels, temp_pitch); - SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch); - SDL_free(temp_pixels); - } - return 0; -} - -static int -SDL_UpdateTextureNative(SDL_Texture * texture, const SDL_Rect * rect, - const void *pixels, int pitch) -{ - SDL_Texture *native = texture->native; - - if (texture->access == SDL_TEXTUREACCESS_STREAMING) { - /* We can lock the texture and copy to it */ - void *native_pixels; - int native_pitch; - - if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) { - return -1; - } - SDL_ConvertPixels(rect->w, rect->h, - texture->format, pixels, pitch, - native->format, native_pixels, native_pitch); - SDL_UnlockTexture(native); - } else { - /* Use a temporary buffer for updating */ - void *temp_pixels; - int temp_pitch; - - temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3); - temp_pixels = SDL_malloc(rect->h * temp_pitch); - if (!temp_pixels) { - return SDL_OutOfMemory(); - } - SDL_ConvertPixels(rect->w, rect->h, - texture->format, pixels, pitch, - native->format, temp_pixels, temp_pitch); - SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch); - SDL_free(temp_pixels); - } - return 0; -} - -int -SDL_UpdateTexture(SDL_Texture * texture, const SDL_Rect * rect, - const void *pixels, int pitch) -{ - SDL_Renderer *renderer; - SDL_Rect full_rect; - - CHECK_TEXTURE_MAGIC(texture, -1); - - if (!pixels) { - return SDL_InvalidParamError("pixels"); - } - if (!pitch) { - return SDL_InvalidParamError("pitch"); - } - - if (!rect) { - full_rect.x = 0; - full_rect.y = 0; - full_rect.w = texture->w; - full_rect.h = texture->h; - rect = &full_rect; - } - - if ((rect->w == 0) || (rect->h == 0)) { - return 0; /* nothing to do. */ - } else if (texture->yuv) { - return SDL_UpdateTextureYUV(texture, rect, pixels, pitch); - } else if (texture->native) { - return SDL_UpdateTextureNative(texture, rect, pixels, pitch); - } else { - renderer = texture->renderer; - return renderer->UpdateTexture(renderer, texture, rect, pixels, pitch); - } -} - -static int -SDL_UpdateTextureYUVPlanar(SDL_Texture * texture, const SDL_Rect * rect, - const Uint8 *Yplane, int Ypitch, - const Uint8 *Uplane, int Upitch, - const Uint8 *Vplane, int Vpitch) -{ - SDL_Texture *native = texture->native; - SDL_Rect full_rect; - - if (SDL_SW_UpdateYUVTexturePlanar(texture->yuv, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch) < 0) { - return -1; - } - - full_rect.x = 0; - full_rect.y = 0; - full_rect.w = texture->w; - full_rect.h = texture->h; - rect = &full_rect; - - if (texture->access == SDL_TEXTUREACCESS_STREAMING) { - /* We can lock the texture and copy to it */ - void *native_pixels; - int native_pitch; - - if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) { - return -1; - } - SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, - rect->w, rect->h, native_pixels, native_pitch); - SDL_UnlockTexture(native); - } else { - /* Use a temporary buffer for updating */ - void *temp_pixels; - int temp_pitch; - - temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3); - temp_pixels = SDL_malloc(rect->h * temp_pitch); - if (!temp_pixels) { - return SDL_OutOfMemory(); - } - SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, - rect->w, rect->h, temp_pixels, temp_pitch); - SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch); - SDL_free(temp_pixels); - } - return 0; -} - -int SDL_UpdateYUVTexture(SDL_Texture * texture, const SDL_Rect * rect, - const Uint8 *Yplane, int Ypitch, - const Uint8 *Uplane, int Upitch, - const Uint8 *Vplane, int Vpitch) -{ - SDL_Renderer *renderer; - SDL_Rect full_rect; - - CHECK_TEXTURE_MAGIC(texture, -1); - - if (!Yplane) { - return SDL_InvalidParamError("Yplane"); - } - if (!Ypitch) { - return SDL_InvalidParamError("Ypitch"); - } - if (!Uplane) { - return SDL_InvalidParamError("Uplane"); - } - if (!Upitch) { - return SDL_InvalidParamError("Upitch"); - } - if (!Vplane) { - return SDL_InvalidParamError("Vplane"); - } - if (!Vpitch) { - return SDL_InvalidParamError("Vpitch"); - } - - if (texture->format != SDL_PIXELFORMAT_YV12 && - texture->format != SDL_PIXELFORMAT_IYUV) { - return SDL_SetError("Texture format must by YV12 or IYUV"); - } - - if (!rect) { - full_rect.x = 0; - full_rect.y = 0; - full_rect.w = texture->w; - full_rect.h = texture->h; - rect = &full_rect; - } - - if (texture->yuv) { - return SDL_UpdateTextureYUVPlanar(texture, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch); - } else { - SDL_assert(!texture->native); - renderer = texture->renderer; - SDL_assert(renderer->UpdateTextureYUV); - if (renderer->UpdateTextureYUV) { - return renderer->UpdateTextureYUV(renderer, texture, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch); - } else { - return SDL_Unsupported(); - } - } -} - -static int -SDL_LockTextureYUV(SDL_Texture * texture, const SDL_Rect * rect, - void **pixels, int *pitch) -{ - return SDL_SW_LockYUVTexture(texture->yuv, rect, pixels, pitch); -} - -static int -SDL_LockTextureNative(SDL_Texture * texture, const SDL_Rect * rect, - void **pixels, int *pitch) -{ - texture->locked_rect = *rect; - *pixels = (void *) ((Uint8 *) texture->pixels + - rect->y * texture->pitch + - rect->x * SDL_BYTESPERPIXEL(texture->format)); - *pitch = texture->pitch; - return 0; -} - -int -SDL_LockTexture(SDL_Texture * texture, const SDL_Rect * rect, - void **pixels, int *pitch) -{ - SDL_Renderer *renderer; - SDL_Rect full_rect; - - CHECK_TEXTURE_MAGIC(texture, -1); - - if (texture->access != SDL_TEXTUREACCESS_STREAMING) { - return SDL_SetError("SDL_LockTexture(): texture must be streaming"); - } - - if (!rect) { - full_rect.x = 0; - full_rect.y = 0; - full_rect.w = texture->w; - full_rect.h = texture->h; - rect = &full_rect; - } - - if (texture->yuv) { - return SDL_LockTextureYUV(texture, rect, pixels, pitch); - } else if (texture->native) { - return SDL_LockTextureNative(texture, rect, pixels, pitch); - } else { - renderer = texture->renderer; - return renderer->LockTexture(renderer, texture, rect, pixels, pitch); - } -} - -static void -SDL_UnlockTextureYUV(SDL_Texture * texture) -{ - SDL_Texture *native = texture->native; - void *native_pixels = NULL; - int native_pitch = 0; - SDL_Rect rect; - - rect.x = 0; - rect.y = 0; - rect.w = texture->w; - rect.h = texture->h; - - if (SDL_LockTexture(native, &rect, &native_pixels, &native_pitch) < 0) { - return; - } - SDL_SW_CopyYUVToRGB(texture->yuv, &rect, native->format, - rect.w, rect.h, native_pixels, native_pitch); - SDL_UnlockTexture(native); -} - -static void -SDL_UnlockTextureNative(SDL_Texture * texture) -{ - SDL_Texture *native = texture->native; - void *native_pixels = NULL; - int native_pitch = 0; - const SDL_Rect *rect = &texture->locked_rect; - const void* pixels = (void *) ((Uint8 *) texture->pixels + - rect->y * texture->pitch + - rect->x * SDL_BYTESPERPIXEL(texture->format)); - int pitch = texture->pitch; - - if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) { - return; - } - SDL_ConvertPixels(rect->w, rect->h, - texture->format, pixels, pitch, - native->format, native_pixels, native_pitch); - SDL_UnlockTexture(native); -} - -void -SDL_UnlockTexture(SDL_Texture * texture) -{ - SDL_Renderer *renderer; - - CHECK_TEXTURE_MAGIC(texture, ); - - if (texture->access != SDL_TEXTUREACCESS_STREAMING) { - return; - } - if (texture->yuv) { - SDL_UnlockTextureYUV(texture); - } else if (texture->native) { - SDL_UnlockTextureNative(texture); - } else { - renderer = texture->renderer; - renderer->UnlockTexture(renderer, texture); - } -} - -SDL_bool -SDL_RenderTargetSupported(SDL_Renderer *renderer) -{ - if (!renderer || !renderer->SetRenderTarget) { - return SDL_FALSE; - } - return (renderer->info.flags & SDL_RENDERER_TARGETTEXTURE) != 0; -} - -int -SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) -{ - if (!SDL_RenderTargetSupported(renderer)) { - return SDL_Unsupported(); - } - if (texture == renderer->target) { - /* Nothing to do! */ - return 0; - } - - /* texture == NULL is valid and means reset the target to the window */ - if (texture) { - CHECK_TEXTURE_MAGIC(texture, -1); - if (renderer != texture->renderer) { - return SDL_SetError("Texture was not created with this renderer"); - } - if (texture->access != SDL_TEXTUREACCESS_TARGET) { - return SDL_SetError("Texture not created with SDL_TEXTUREACCESS_TARGET"); - } - if (texture->native) { - /* Always render to the native texture */ - texture = texture->native; - } - } - - if (texture && !renderer->target) { - /* Make a backup of the viewport */ - renderer->viewport_backup = renderer->viewport; - renderer->clip_rect_backup = renderer->clip_rect; - renderer->clipping_enabled_backup = renderer->clipping_enabled; - renderer->scale_backup = renderer->scale; - renderer->logical_w_backup = renderer->logical_w; - renderer->logical_h_backup = renderer->logical_h; - } - renderer->target = texture; - - if (renderer->SetRenderTarget(renderer, texture) < 0) { - return -1; - } - - if (texture) { - renderer->viewport.x = 0; - renderer->viewport.y = 0; - renderer->viewport.w = texture->w; - renderer->viewport.h = texture->h; - SDL_zero(renderer->clip_rect); - renderer->clipping_enabled = SDL_FALSE; - renderer->scale.x = 1.0f; - renderer->scale.y = 1.0f; - renderer->logical_w = texture->w; - renderer->logical_h = texture->h; - } else { - renderer->viewport = renderer->viewport_backup; - renderer->clip_rect = renderer->clip_rect_backup; - renderer->clipping_enabled = renderer->clipping_enabled_backup; - renderer->scale = renderer->scale_backup; - renderer->logical_w = renderer->logical_w_backup; - renderer->logical_h = renderer->logical_h_backup; - } - if (renderer->UpdateViewport(renderer) < 0) { - return -1; - } - if (renderer->UpdateClipRect(renderer) < 0) { - return -1; - } - - /* All set! */ - return 0; -} - -SDL_Texture * -SDL_GetRenderTarget(SDL_Renderer *renderer) -{ - return renderer->target; -} - -static int -UpdateLogicalSize(SDL_Renderer *renderer) -{ - int w = 1, h = 1; - float want_aspect; - float real_aspect; - float scale; - SDL_Rect viewport; - - if (!renderer->logical_w || !renderer->logical_h) { - return 0; - } - if (SDL_GetRendererOutputSize(renderer, &w, &h) < 0) { - return -1; - } - - want_aspect = (float)renderer->logical_w / renderer->logical_h; - real_aspect = (float)w / h; - - /* Clear the scale because we're setting viewport in output coordinates */ - SDL_RenderSetScale(renderer, 1.0f, 1.0f); - - if (renderer->integer_scale) { - if (want_aspect > real_aspect) { - scale = (float)(w / renderer->logical_w); - } else { - scale = (float)(h / renderer->logical_h); - } - viewport.w = (int)SDL_ceil(renderer->logical_w * scale); - viewport.x = (w - viewport.w) / 2; - viewport.h = (int)SDL_ceil(renderer->logical_h * scale); - viewport.y = (h - viewport.h) / 2; - - SDL_RenderSetViewport(renderer, &viewport); - } else if (SDL_fabs(want_aspect-real_aspect) < 0.0001) { - /* The aspect ratios are the same, just scale appropriately */ - scale = (float)w / renderer->logical_w; - SDL_RenderSetViewport(renderer, NULL); - } else if (want_aspect > real_aspect) { - /* We want a wider aspect ratio than is available - letterbox it */ - scale = (float)w / renderer->logical_w; - viewport.x = 0; - viewport.w = w; - viewport.h = (int)SDL_ceil(renderer->logical_h * scale); - viewport.y = (h - viewport.h) / 2; - SDL_RenderSetViewport(renderer, &viewport); - } else { - /* We want a narrower aspect ratio than is available - use side-bars */ - scale = (float)h / renderer->logical_h; - viewport.y = 0; - viewport.h = h; - viewport.w = (int)SDL_ceil(renderer->logical_w * scale); - viewport.x = (w - viewport.w) / 2; - SDL_RenderSetViewport(renderer, &viewport); - } - - /* Set the new scale */ - SDL_RenderSetScale(renderer, scale, scale); - - return 0; -} - -int -SDL_RenderSetLogicalSize(SDL_Renderer * renderer, int w, int h) -{ - CHECK_RENDERER_MAGIC(renderer, -1); - - if (!w || !h) { - /* Clear any previous logical resolution */ - renderer->logical_w = 0; - renderer->logical_h = 0; - SDL_RenderSetViewport(renderer, NULL); - SDL_RenderSetScale(renderer, 1.0f, 1.0f); - return 0; - } - - renderer->logical_w = w; - renderer->logical_h = h; - - return UpdateLogicalSize(renderer); -} - -void -SDL_RenderGetLogicalSize(SDL_Renderer * renderer, int *w, int *h) -{ - CHECK_RENDERER_MAGIC(renderer, ); - - if (w) { - *w = renderer->logical_w; - } - if (h) { - *h = renderer->logical_h; - } -} - -int -SDL_RenderSetIntegerScale(SDL_Renderer * renderer, SDL_bool enable) -{ - CHECK_RENDERER_MAGIC(renderer, -1); - - renderer->integer_scale = enable; - - return UpdateLogicalSize(renderer); -} - -SDL_bool -SDLCALL SDL_RenderGetIntegerScale(SDL_Renderer * renderer) -{ - CHECK_RENDERER_MAGIC(renderer, SDL_FALSE); - - return renderer->integer_scale; -} - -int -SDL_RenderSetViewport(SDL_Renderer * renderer, const SDL_Rect * rect) -{ - CHECK_RENDERER_MAGIC(renderer, -1); - - if (rect) { - renderer->viewport.x = (int)SDL_floor(rect->x * renderer->scale.x); - renderer->viewport.y = (int)SDL_floor(rect->y * renderer->scale.y); - renderer->viewport.w = (int)SDL_ceil(rect->w * renderer->scale.x); - renderer->viewport.h = (int)SDL_ceil(rect->h * renderer->scale.y); - } else { - renderer->viewport.x = 0; - renderer->viewport.y = 0; - if (SDL_GetRendererOutputSize(renderer, &renderer->viewport.w, &renderer->viewport.h) < 0) { - return -1; - } - } - return renderer->UpdateViewport(renderer); -} - -void -SDL_RenderGetViewport(SDL_Renderer * renderer, SDL_Rect * rect) -{ - CHECK_RENDERER_MAGIC(renderer, ); - - if (rect) { - rect->x = (int)(renderer->viewport.x / renderer->scale.x); - rect->y = (int)(renderer->viewport.y / renderer->scale.y); - rect->w = (int)(renderer->viewport.w / renderer->scale.x); - rect->h = (int)(renderer->viewport.h / renderer->scale.y); - } -} - -int -SDL_RenderSetClipRect(SDL_Renderer * renderer, const SDL_Rect * rect) -{ - CHECK_RENDERER_MAGIC(renderer, -1) - - if (rect) { - renderer->clipping_enabled = SDL_TRUE; - renderer->clip_rect.x = (int)SDL_floor(rect->x * renderer->scale.x); - renderer->clip_rect.y = (int)SDL_floor(rect->y * renderer->scale.y); - renderer->clip_rect.w = (int)SDL_ceil(rect->w * renderer->scale.x); - renderer->clip_rect.h = (int)SDL_ceil(rect->h * renderer->scale.y); - } else { - renderer->clipping_enabled = SDL_FALSE; - SDL_zero(renderer->clip_rect); - } - return renderer->UpdateClipRect(renderer); -} - -void -SDL_RenderGetClipRect(SDL_Renderer * renderer, SDL_Rect * rect) -{ - CHECK_RENDERER_MAGIC(renderer, ) - - if (rect) { - rect->x = (int)(renderer->clip_rect.x / renderer->scale.x); - rect->y = (int)(renderer->clip_rect.y / renderer->scale.y); - rect->w = (int)(renderer->clip_rect.w / renderer->scale.x); - rect->h = (int)(renderer->clip_rect.h / renderer->scale.y); - } -} - -SDL_bool -SDL_RenderIsClipEnabled(SDL_Renderer * renderer) -{ - CHECK_RENDERER_MAGIC(renderer, SDL_FALSE) - return renderer->clipping_enabled; -} - -int -SDL_RenderSetScale(SDL_Renderer * renderer, float scaleX, float scaleY) -{ - CHECK_RENDERER_MAGIC(renderer, -1); - - renderer->scale.x = scaleX; - renderer->scale.y = scaleY; - return 0; -} - -void -SDL_RenderGetScale(SDL_Renderer * renderer, float *scaleX, float *scaleY) -{ - CHECK_RENDERER_MAGIC(renderer, ); - - if (scaleX) { - *scaleX = renderer->scale.x; - } - if (scaleY) { - *scaleY = renderer->scale.y; - } -} - -int -SDL_SetRenderDrawColor(SDL_Renderer * renderer, - Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - CHECK_RENDERER_MAGIC(renderer, -1); - - renderer->r = r; - renderer->g = g; - renderer->b = b; - renderer->a = a; - return 0; -} - -int -SDL_GetRenderDrawColor(SDL_Renderer * renderer, - Uint8 * r, Uint8 * g, Uint8 * b, Uint8 * a) -{ - CHECK_RENDERER_MAGIC(renderer, -1); - - if (r) { - *r = renderer->r; - } - if (g) { - *g = renderer->g; - } - if (b) { - *b = renderer->b; - } - if (a) { - *a = renderer->a; - } - return 0; -} - -int -SDL_SetRenderDrawBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode) -{ - CHECK_RENDERER_MAGIC(renderer, -1); - - renderer->blendMode = blendMode; - return 0; -} - -int -SDL_GetRenderDrawBlendMode(SDL_Renderer * renderer, SDL_BlendMode *blendMode) -{ - CHECK_RENDERER_MAGIC(renderer, -1); - - *blendMode = renderer->blendMode; - return 0; -} - -int -SDL_RenderClear(SDL_Renderer * renderer) -{ - CHECK_RENDERER_MAGIC(renderer, -1); - - /* Don't draw while we're hidden */ - if (renderer->hidden) { - return 0; - } - return renderer->RenderClear(renderer); -} - -int -SDL_RenderDrawPoint(SDL_Renderer * renderer, int x, int y) -{ - SDL_Point point; - - point.x = x; - point.y = y; - return SDL_RenderDrawPoints(renderer, &point, 1); -} - -static int -RenderDrawPointsWithRects(SDL_Renderer * renderer, - const SDL_Point * points, int count) -{ - SDL_FRect *frects; - int i; - int status; - - frects = SDL_stack_alloc(SDL_FRect, count); - if (!frects) { - return SDL_OutOfMemory(); - } - for (i = 0; i < count; ++i) { - frects[i].x = points[i].x * renderer->scale.x; - frects[i].y = points[i].y * renderer->scale.y; - frects[i].w = renderer->scale.x; - frects[i].h = renderer->scale.y; - } - - status = renderer->RenderFillRects(renderer, frects, count); - - SDL_stack_free(frects); - - return status; -} - -int -SDL_RenderDrawPoints(SDL_Renderer * renderer, - const SDL_Point * points, int count) -{ - SDL_FPoint *fpoints; - int i; - int status; - - CHECK_RENDERER_MAGIC(renderer, -1); - - if (!points) { - return SDL_SetError("SDL_RenderDrawPoints(): Passed NULL points"); - } - if (count < 1) { - return 0; - } - - /* Don't draw while we're hidden */ - if (renderer->hidden) { - return 0; - } - - if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) { - return RenderDrawPointsWithRects(renderer, points, count); - } - - fpoints = SDL_stack_alloc(SDL_FPoint, count); - if (!fpoints) { - return SDL_OutOfMemory(); - } - for (i = 0; i < count; ++i) { - fpoints[i].x = points[i].x * renderer->scale.x; - fpoints[i].y = points[i].y * renderer->scale.y; - } - - status = renderer->RenderDrawPoints(renderer, fpoints, count); - - SDL_stack_free(fpoints); - - return status; -} - -int -SDL_RenderDrawLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) -{ - SDL_Point points[2]; - - points[0].x = x1; - points[0].y = y1; - points[1].x = x2; - points[1].y = y2; - return SDL_RenderDrawLines(renderer, points, 2); -} - -static int -RenderDrawLinesWithRects(SDL_Renderer * renderer, - const SDL_Point * points, int count) -{ - SDL_FRect *frect; - SDL_FRect *frects; - SDL_FPoint fpoints[2]; - int i, nrects; - int status; - - frects = SDL_stack_alloc(SDL_FRect, count-1); - if (!frects) { - return SDL_OutOfMemory(); - } - - status = 0; - nrects = 0; - for (i = 0; i < count-1; ++i) { - if (points[i].x == points[i+1].x) { - int minY = SDL_min(points[i].y, points[i+1].y); - int maxY = SDL_max(points[i].y, points[i+1].y); - - frect = &frects[nrects++]; - frect->x = points[i].x * renderer->scale.x; - frect->y = minY * renderer->scale.y; - frect->w = renderer->scale.x; - frect->h = (maxY - minY + 1) * renderer->scale.y; - } else if (points[i].y == points[i+1].y) { - int minX = SDL_min(points[i].x, points[i+1].x); - int maxX = SDL_max(points[i].x, points[i+1].x); - - frect = &frects[nrects++]; - frect->x = minX * renderer->scale.x; - frect->y = points[i].y * renderer->scale.y; - frect->w = (maxX - minX + 1) * renderer->scale.x; - frect->h = renderer->scale.y; - } else { - /* FIXME: We can't use a rect for this line... */ - fpoints[0].x = points[i].x * renderer->scale.x; - fpoints[0].y = points[i].y * renderer->scale.y; - fpoints[1].x = points[i+1].x * renderer->scale.x; - fpoints[1].y = points[i+1].y * renderer->scale.y; - status += renderer->RenderDrawLines(renderer, fpoints, 2); - } - } - - status += renderer->RenderFillRects(renderer, frects, nrects); - - SDL_stack_free(frects); - - if (status < 0) { - status = -1; - } - return status; -} - -int -SDL_RenderDrawLines(SDL_Renderer * renderer, - const SDL_Point * points, int count) -{ - SDL_FPoint *fpoints; - int i; - int status; - - CHECK_RENDERER_MAGIC(renderer, -1); - - if (!points) { - return SDL_SetError("SDL_RenderDrawLines(): Passed NULL points"); - } - if (count < 2) { - return 0; - } - - /* Don't draw while we're hidden */ - if (renderer->hidden) { - return 0; - } - - if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) { - return RenderDrawLinesWithRects(renderer, points, count); - } - - fpoints = SDL_stack_alloc(SDL_FPoint, count); - if (!fpoints) { - return SDL_OutOfMemory(); - } - for (i = 0; i < count; ++i) { - fpoints[i].x = points[i].x * renderer->scale.x; - fpoints[i].y = points[i].y * renderer->scale.y; - } - - status = renderer->RenderDrawLines(renderer, fpoints, count); - - SDL_stack_free(fpoints); - - return status; -} - -int -SDL_RenderDrawRect(SDL_Renderer * renderer, const SDL_Rect * rect) -{ - SDL_Rect full_rect; - SDL_Point points[5]; - - CHECK_RENDERER_MAGIC(renderer, -1); - - /* If 'rect' == NULL, then outline the whole surface */ - if (!rect) { - SDL_RenderGetViewport(renderer, &full_rect); - full_rect.x = 0; - full_rect.y = 0; - rect = &full_rect; - } - - points[0].x = rect->x; - points[0].y = rect->y; - points[1].x = rect->x+rect->w-1; - points[1].y = rect->y; - points[2].x = rect->x+rect->w-1; - points[2].y = rect->y+rect->h-1; - points[3].x = rect->x; - points[3].y = rect->y+rect->h-1; - points[4].x = rect->x; - points[4].y = rect->y; - return SDL_RenderDrawLines(renderer, points, 5); -} - -int -SDL_RenderDrawRects(SDL_Renderer * renderer, - const SDL_Rect * rects, int count) -{ - int i; - - CHECK_RENDERER_MAGIC(renderer, -1); - - if (!rects) { - return SDL_SetError("SDL_RenderDrawRects(): Passed NULL rects"); - } - if (count < 1) { - return 0; - } - - /* Don't draw while we're hidden */ - if (renderer->hidden) { - return 0; - } - - for (i = 0; i < count; ++i) { - if (SDL_RenderDrawRect(renderer, &rects[i]) < 0) { - return -1; - } - } - return 0; -} - -int -SDL_RenderFillRect(SDL_Renderer * renderer, const SDL_Rect * rect) -{ - SDL_Rect full_rect = { 0, 0, 0, 0 }; - - CHECK_RENDERER_MAGIC(renderer, -1); - - /* If 'rect' == NULL, then outline the whole surface */ - if (!rect) { - SDL_RenderGetViewport(renderer, &full_rect); - full_rect.x = 0; - full_rect.y = 0; - rect = &full_rect; - } - return SDL_RenderFillRects(renderer, rect, 1); -} - -int -SDL_RenderFillRects(SDL_Renderer * renderer, - const SDL_Rect * rects, int count) -{ - SDL_FRect *frects; - int i; - int status; - - CHECK_RENDERER_MAGIC(renderer, -1); - - if (!rects) { - return SDL_SetError("SDL_RenderFillRects(): Passed NULL rects"); - } - if (count < 1) { - return 0; - } - - /* Don't draw while we're hidden */ - if (renderer->hidden) { - return 0; - } - - frects = SDL_stack_alloc(SDL_FRect, count); - if (!frects) { - return SDL_OutOfMemory(); - } - for (i = 0; i < count; ++i) { - frects[i].x = rects[i].x * renderer->scale.x; - frects[i].y = rects[i].y * renderer->scale.y; - frects[i].w = rects[i].w * renderer->scale.x; - frects[i].h = rects[i].h * renderer->scale.y; - } - - status = renderer->RenderFillRects(renderer, frects, count); - - SDL_stack_free(frects); - - return status; -} - -int -SDL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_Rect * dstrect) -{ - SDL_Rect real_srcrect = { 0, 0, 0, 0 }; - SDL_Rect real_dstrect = { 0, 0, 0, 0 }; - SDL_FRect frect; - - CHECK_RENDERER_MAGIC(renderer, -1); - CHECK_TEXTURE_MAGIC(texture, -1); - - if (renderer != texture->renderer) { - return SDL_SetError("Texture was not created with this renderer"); - } - - /* Don't draw while we're hidden */ - if (renderer->hidden) { - return 0; - } - - real_srcrect.x = 0; - real_srcrect.y = 0; - real_srcrect.w = texture->w; - real_srcrect.h = texture->h; - if (srcrect) { - if (!SDL_IntersectRect(srcrect, &real_srcrect, &real_srcrect)) { - return 0; - } - } - - SDL_RenderGetViewport(renderer, &real_dstrect); - real_dstrect.x = 0; - real_dstrect.y = 0; - if (dstrect) { - if (!SDL_HasIntersection(dstrect, &real_dstrect)) { - return 0; - } - real_dstrect = *dstrect; - } - - if (texture->native) { - texture = texture->native; - } - - frect.x = real_dstrect.x * renderer->scale.x; - frect.y = real_dstrect.y * renderer->scale.y; - frect.w = real_dstrect.w * renderer->scale.x; - frect.h = real_dstrect.h * renderer->scale.y; - - return renderer->RenderCopy(renderer, texture, &real_srcrect, &frect); -} - - -int -SDL_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_Rect * dstrect, - const double angle, const SDL_Point *center, const SDL_RendererFlip flip) -{ - SDL_Rect real_srcrect = { 0, 0, 0, 0 }; - SDL_Rect real_dstrect = { 0, 0, 0, 0 }; - SDL_Point real_center; - SDL_FRect frect; - SDL_FPoint fcenter; - - if (flip == SDL_FLIP_NONE && (int)(angle/360) == angle/360) { /* fast path when we don't need rotation or flipping */ - return SDL_RenderCopy(renderer, texture, srcrect, dstrect); - } - - CHECK_RENDERER_MAGIC(renderer, -1); - CHECK_TEXTURE_MAGIC(texture, -1); - - if (renderer != texture->renderer) { - return SDL_SetError("Texture was not created with this renderer"); - } - if (!renderer->RenderCopyEx) { - return SDL_SetError("Renderer does not support RenderCopyEx"); - } - - /* Don't draw while we're hidden */ - if (renderer->hidden) { - return 0; - } - - real_srcrect.x = 0; - real_srcrect.y = 0; - real_srcrect.w = texture->w; - real_srcrect.h = texture->h; - if (srcrect) { - if (!SDL_IntersectRect(srcrect, &real_srcrect, &real_srcrect)) { - return 0; - } - } - - /* We don't intersect the dstrect with the viewport as RenderCopy does because of potential rotation clipping issues... TODO: should we? */ - if (dstrect) { - real_dstrect = *dstrect; - } else { - SDL_RenderGetViewport(renderer, &real_dstrect); - real_dstrect.x = 0; - real_dstrect.y = 0; - } - - if (texture->native) { - texture = texture->native; - } - - if (center) { - real_center = *center; - } else { - real_center.x = real_dstrect.w/2; - real_center.y = real_dstrect.h/2; - } - - frect.x = real_dstrect.x * renderer->scale.x; - frect.y = real_dstrect.y * renderer->scale.y; - frect.w = real_dstrect.w * renderer->scale.x; - frect.h = real_dstrect.h * renderer->scale.y; - - fcenter.x = real_center.x * renderer->scale.x; - fcenter.y = real_center.y * renderer->scale.y; - - return renderer->RenderCopyEx(renderer, texture, &real_srcrect, &frect, angle, &fcenter, flip); -} - -int -SDL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, - Uint32 format, void * pixels, int pitch) -{ - SDL_Rect real_rect; - - CHECK_RENDERER_MAGIC(renderer, -1); - - if (!renderer->RenderReadPixels) { - return SDL_Unsupported(); - } - - if (!format) { - format = SDL_GetWindowPixelFormat(renderer->window); - } - - real_rect.x = renderer->viewport.x; - real_rect.y = renderer->viewport.y; - real_rect.w = renderer->viewport.w; - real_rect.h = renderer->viewport.h; - if (rect) { - if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) { - return 0; - } - if (real_rect.y > rect->y) { - pixels = (Uint8 *)pixels + pitch * (real_rect.y - rect->y); - } - if (real_rect.x > rect->x) { - int bpp = SDL_BYTESPERPIXEL(format); - pixels = (Uint8 *)pixels + bpp * (real_rect.x - rect->x); - } - } - - return renderer->RenderReadPixels(renderer, &real_rect, - format, pixels, pitch); -} - -void -SDL_RenderPresent(SDL_Renderer * renderer) -{ - CHECK_RENDERER_MAGIC(renderer, ); - - /* Don't draw while we're hidden */ - if (renderer->hidden) { - return; - } - renderer->RenderPresent(renderer); -} - -void -SDL_DestroyTexture(SDL_Texture * texture) -{ - SDL_Renderer *renderer; - - CHECK_TEXTURE_MAGIC(texture, ); - - renderer = texture->renderer; - if (texture == renderer->target) { - SDL_SetRenderTarget(renderer, NULL); - } - - texture->magic = NULL; - - if (texture->next) { - texture->next->prev = texture->prev; - } - if (texture->prev) { - texture->prev->next = texture->next; - } else { - renderer->textures = texture->next; - } - - if (texture->native) { - SDL_DestroyTexture(texture->native); - } - if (texture->yuv) { - SDL_SW_DestroyYUVTexture(texture->yuv); - } - SDL_free(texture->pixels); - - renderer->DestroyTexture(renderer, texture); - SDL_free(texture); -} - -void -SDL_DestroyRenderer(SDL_Renderer * renderer) -{ - CHECK_RENDERER_MAGIC(renderer, ); - - SDL_DelEventWatch(SDL_RendererEventWatch, renderer); - - /* Free existing textures for this renderer */ - while (renderer->textures) { - SDL_DestroyTexture(renderer->textures); - } - - if (renderer->window) { - SDL_SetWindowData(renderer->window, SDL_WINDOWRENDERDATA, NULL); - } - - /* It's no longer magical... */ - renderer->magic = NULL; - - /* Free the renderer instance */ - renderer->DestroyRenderer(renderer); -} - -int SDL_GL_BindTexture(SDL_Texture *texture, float *texw, float *texh) -{ - SDL_Renderer *renderer; - - CHECK_TEXTURE_MAGIC(texture, -1); - renderer = texture->renderer; - if (texture->native) { - return SDL_GL_BindTexture(texture->native, texw, texh); - } else if (renderer && renderer->GL_BindTexture) { - return renderer->GL_BindTexture(renderer, texture, texw, texh); - } else { - return SDL_Unsupported(); - } -} - -int SDL_GL_UnbindTexture(SDL_Texture *texture) -{ - SDL_Renderer *renderer; - - CHECK_TEXTURE_MAGIC(texture, -1); - renderer = texture->renderer; - if (texture->native) { - return SDL_GL_UnbindTexture(texture->native); - } else if (renderer && renderer->GL_UnbindTexture) { - return renderer->GL_UnbindTexture(renderer, texture); - } - - return SDL_Unsupported(); -} - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/SDL_sysrender.h b/3rdparty/SDL2/src/render/SDL_sysrender.h deleted file mode 100644 index 378fc4d9726..00000000000 --- a/3rdparty/SDL2/src/render/SDL_sysrender.h +++ /dev/null @@ -1,205 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../SDL_internal.h" - -#ifndef _SDL_sysrender_h -#define _SDL_sysrender_h - -#include "SDL_render.h" -#include "SDL_events.h" -#include "SDL_yuv_sw_c.h" - -/* The SDL 2D rendering system */ - -typedef struct SDL_RenderDriver SDL_RenderDriver; - -typedef struct -{ - float x; - float y; -} SDL_FPoint; - -typedef struct -{ - float x; - float y; - float w; - float h; -} SDL_FRect; - -/* Define the SDL texture structure */ -struct SDL_Texture -{ - const void *magic; - Uint32 format; /**< The pixel format of the texture */ - int access; /**< SDL_TextureAccess */ - int w; /**< The width of the texture */ - int h; /**< The height of the texture */ - int modMode; /**< The texture modulation mode */ - SDL_BlendMode blendMode; /**< The texture blend mode */ - Uint8 r, g, b, a; /**< Texture modulation values */ - - SDL_Renderer *renderer; - - /* Support for formats not supported directly by the renderer */ - SDL_Texture *native; - SDL_SW_YUVTexture *yuv; - void *pixels; - int pitch; - SDL_Rect locked_rect; - - void *driverdata; /**< Driver specific texture representation */ - - SDL_Texture *prev; - SDL_Texture *next; -}; - -/* Define the SDL renderer structure */ -struct SDL_Renderer -{ - const void *magic; - - void (*WindowEvent) (SDL_Renderer * renderer, const SDL_WindowEvent *event); - int (*GetOutputSize) (SDL_Renderer * renderer, int *w, int *h); - int (*CreateTexture) (SDL_Renderer * renderer, SDL_Texture * texture); - int (*SetTextureColorMod) (SDL_Renderer * renderer, - SDL_Texture * texture); - int (*SetTextureAlphaMod) (SDL_Renderer * renderer, - SDL_Texture * texture); - int (*SetTextureBlendMode) (SDL_Renderer * renderer, - SDL_Texture * texture); - int (*UpdateTexture) (SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, const void *pixels, - int pitch); - int (*UpdateTextureYUV) (SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, - const Uint8 *Yplane, int Ypitch, - const Uint8 *Uplane, int Upitch, - const Uint8 *Vplane, int Vpitch); - int (*LockTexture) (SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, void **pixels, int *pitch); - void (*UnlockTexture) (SDL_Renderer * renderer, SDL_Texture * texture); - int (*SetRenderTarget) (SDL_Renderer * renderer, SDL_Texture * texture); - int (*UpdateViewport) (SDL_Renderer * renderer); - int (*UpdateClipRect) (SDL_Renderer * renderer); - int (*RenderClear) (SDL_Renderer * renderer); - int (*RenderDrawPoints) (SDL_Renderer * renderer, const SDL_FPoint * points, - int count); - int (*RenderDrawLines) (SDL_Renderer * renderer, const SDL_FPoint * points, - int count); - int (*RenderFillRects) (SDL_Renderer * renderer, const SDL_FRect * rects, - int count); - int (*RenderCopy) (SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_FRect * dstrect); - int (*RenderCopyEx) (SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcquad, const SDL_FRect * dstrect, - const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip); - int (*RenderReadPixels) (SDL_Renderer * renderer, const SDL_Rect * rect, - Uint32 format, void * pixels, int pitch); - void (*RenderPresent) (SDL_Renderer * renderer); - void (*DestroyTexture) (SDL_Renderer * renderer, SDL_Texture * texture); - - void (*DestroyRenderer) (SDL_Renderer * renderer); - - int (*GL_BindTexture) (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh); - int (*GL_UnbindTexture) (SDL_Renderer * renderer, SDL_Texture *texture); - - /* The current renderer info */ - SDL_RendererInfo info; - - /* The window associated with the renderer */ - SDL_Window *window; - SDL_bool hidden; - - /* The logical resolution for rendering */ - int logical_w; - int logical_h; - int logical_w_backup; - int logical_h_backup; - - /* Whether or not to force the viewport to even integer intervals */ - SDL_bool integer_scale; - - /* The drawable area within the window */ - SDL_Rect viewport; - SDL_Rect viewport_backup; - - /* The clip rectangle within the window */ - SDL_Rect clip_rect; - SDL_Rect clip_rect_backup; - - /* Wether or not the clipping rectangle is used. */ - SDL_bool clipping_enabled; - SDL_bool clipping_enabled_backup; - - /* The render output coordinate scale */ - SDL_FPoint scale; - SDL_FPoint scale_backup; - - /* The list of textures */ - SDL_Texture *textures; - SDL_Texture *target; - - Uint8 r, g, b, a; /**< Color for drawing operations values */ - SDL_BlendMode blendMode; /**< The drawing blend mode */ - - void *driverdata; -}; - -/* Define the SDL render driver structure */ -struct SDL_RenderDriver -{ - SDL_Renderer *(*CreateRenderer) (SDL_Window * window, Uint32 flags); - - /* Info about the renderer capabilities */ - SDL_RendererInfo info; -}; - -#if !SDL_RENDER_DISABLED - -#if SDL_VIDEO_RENDER_D3D -extern SDL_RenderDriver D3D_RenderDriver; -#endif -#if SDL_VIDEO_RENDER_D3D11 -extern SDL_RenderDriver D3D11_RenderDriver; -#endif -#if SDL_VIDEO_RENDER_OGL -extern SDL_RenderDriver GL_RenderDriver; -#endif -#if SDL_VIDEO_RENDER_OGL_ES2 -extern SDL_RenderDriver GLES2_RenderDriver; -#endif -#if SDL_VIDEO_RENDER_OGL_ES -extern SDL_RenderDriver GLES_RenderDriver; -#endif -#if SDL_VIDEO_RENDER_DIRECTFB -extern SDL_RenderDriver DirectFB_RenderDriver; -#endif -#if SDL_VIDEO_RENDER_PSP -extern SDL_RenderDriver PSP_RenderDriver; -#endif -extern SDL_RenderDriver SW_RenderDriver; - -#endif /* !SDL_RENDER_DISABLED */ - -#endif /* _SDL_sysrender_h */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/SDL_yuv_mmx.c b/3rdparty/SDL2/src/render/SDL_yuv_mmx.c deleted file mode 100644 index 0de776a36ec..00000000000 --- a/3rdparty/SDL2/src/render/SDL_yuv_mmx.c +++ /dev/null @@ -1,431 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../SDL_internal.h" - -#if (__GNUC__ > 2) && defined(__i386__) && __OPTIMIZE__ && SDL_ASSEMBLY_ROUTINES - -#include "SDL_stdinc.h" - -#include "mmx.h" - -/* *INDENT-OFF* */ - -static mmx_t MMX_0080w = { .ud = {0x00800080, 0x00800080} }; -static mmx_t MMX_00FFw = { .ud = {0x00ff00ff, 0x00ff00ff} }; -static mmx_t MMX_FF00w = { .ud = {0xff00ff00, 0xff00ff00} }; - -static mmx_t MMX_Ycoeff = { .uw = {0x004a, 0x004a, 0x004a, 0x004a} }; - -static mmx_t MMX_UbluRGB = { .uw = {0x0072, 0x0072, 0x0072, 0x0072} }; -static mmx_t MMX_VredRGB = { .uw = {0x0059, 0x0059, 0x0059, 0x0059} }; -static mmx_t MMX_UgrnRGB = { .uw = {0xffea, 0xffea, 0xffea, 0xffea} }; -static mmx_t MMX_VgrnRGB = { .uw = {0xffd2, 0xffd2, 0xffd2, 0xffd2} }; - -static mmx_t MMX_Ublu5x5 = { .uw = {0x0081, 0x0081, 0x0081, 0x0081} }; -static mmx_t MMX_Vred5x5 = { .uw = {0x0066, 0x0066, 0x0066, 0x0066} }; -static mmx_t MMX_Ugrn565 = { .uw = {0xffe8, 0xffe8, 0xffe8, 0xffe8} }; -static mmx_t MMX_Vgrn565 = { .uw = {0xffcd, 0xffcd, 0xffcd, 0xffcd} }; - -static mmx_t MMX_red565 = { .uw = {0xf800, 0xf800, 0xf800, 0xf800} }; -static mmx_t MMX_grn565 = { .uw = {0x07e0, 0x07e0, 0x07e0, 0x07e0} }; - -/** - This MMX assembler is my first assembler/MMX program ever. - Thus it maybe buggy. - Send patches to: - mvogt@rhrk.uni-kl.de - - After it worked fine I have "obfuscated" the code a bit to have - more parallism in the MMX units. This means I moved - initilisation around and delayed other instruction. - Performance measurement did not show that this brought any advantage - but in theory it _should_ be faster this way. - - The overall performanve gain to the C based dither was 30%-40%. - The MMX routine calculates 256bit=8RGB values in each cycle - (4 for row1 & 4 for row2) - - The red/green/blue.. coefficents are taken from the mpeg_play - player. They look nice, but I dont know if you can have - better values, to avoid integer rounding errors. - - - IMPORTANT: - ========== - - It is a requirement that the cr/cb/lum are 8 byte aligned and - the out are 16byte aligned or you will/may get segfaults - -*/ - -void ColorRGBDitherYV12MMX1X( int *colortab, Uint32 *rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod ) -{ - Uint32 *row1; - Uint32 *row2; - - unsigned char* y = lum +cols*rows; /* Pointer to the end */ - int x = 0; - row1 = (Uint32 *)out; /* 32 bit target */ - row2 = (Uint32 *)out+cols+mod; /* start of second row */ - mod = (mod+cols+mod)*4; /* increment for row1 in byte */ - - __asm__ __volatile__ ( - /* tap dance to workaround the inability to use %%ebx at will... */ - /* move one thing to the stack... */ - "pushl $0\n" /* save a slot on the stack. */ - "pushl %%ebx\n" /* save %%ebx. */ - "movl %0, %%ebx\n" /* put the thing in ebx. */ - "movl %%ebx,4(%%esp)\n" /* put the thing in the stack slot. */ - "popl %%ebx\n" /* get back %%ebx (the PIC register). */ - - ".align 8\n" - "1:\n" - - /* create Cr (result in mm1) */ - "pushl %%ebx\n" - "movl 4(%%esp),%%ebx\n" - "movd (%%ebx),%%mm1\n" /* 0 0 0 0 v3 v2 v1 v0 */ - "popl %%ebx\n" - "pxor %%mm7,%%mm7\n" /* 00 00 00 00 00 00 00 00 */ - "movd (%2), %%mm2\n" /* 0 0 0 0 l3 l2 l1 l0 */ - "punpcklbw %%mm7,%%mm1\n" /* 0 v3 0 v2 00 v1 00 v0 */ - "punpckldq %%mm1,%%mm1\n" /* 00 v1 00 v0 00 v1 00 v0 */ - "psubw %9,%%mm1\n" /* mm1-128:r1 r1 r0 r0 r1 r1 r0 r0 */ - - /* create Cr_g (result in mm0) */ - "movq %%mm1,%%mm0\n" /* r1 r1 r0 r0 r1 r1 r0 r0 */ - "pmullw %10,%%mm0\n" /* red*-46dec=0.7136*64 */ - "pmullw %11,%%mm1\n" /* red*89dec=1.4013*64 */ - "psraw $6, %%mm0\n" /* red=red/64 */ - "psraw $6, %%mm1\n" /* red=red/64 */ - - /* create L1 L2 (result in mm2,mm4) */ - /* L2=lum+cols */ - "movq (%2,%4),%%mm3\n" /* 0 0 0 0 L3 L2 L1 L0 */ - "punpckldq %%mm3,%%mm2\n" /* L3 L2 L1 L0 l3 l2 l1 l0 */ - "movq %%mm2,%%mm4\n" /* L3 L2 L1 L0 l3 l2 l1 l0 */ - "pand %12,%%mm2\n" /* L3 0 L1 0 l3 0 l1 0 */ - "pand %13,%%mm4\n" /* 0 L2 0 L0 0 l2 0 l0 */ - "psrlw $8,%%mm2\n" /* 0 L3 0 L1 0 l3 0 l1 */ - - /* create R (result in mm6) */ - "movq %%mm2,%%mm5\n" /* 0 L3 0 L1 0 l3 0 l1 */ - "movq %%mm4,%%mm6\n" /* 0 L2 0 L0 0 l2 0 l0 */ - "paddsw %%mm1, %%mm5\n" /* lum1+red:x R3 x R1 x r3 x r1 */ - "paddsw %%mm1, %%mm6\n" /* lum1+red:x R2 x R0 x r2 x r0 */ - "packuswb %%mm5,%%mm5\n" /* R3 R1 r3 r1 R3 R1 r3 r1 */ - "packuswb %%mm6,%%mm6\n" /* R2 R0 r2 r0 R2 R0 r2 r0 */ - "pxor %%mm7,%%mm7\n" /* 00 00 00 00 00 00 00 00 */ - "punpcklbw %%mm5,%%mm6\n" /* R3 R2 R1 R0 r3 r2 r1 r0 */ - - /* create Cb (result in mm1) */ - "movd (%1), %%mm1\n" /* 0 0 0 0 u3 u2 u1 u0 */ - "punpcklbw %%mm7,%%mm1\n" /* 0 u3 0 u2 00 u1 00 u0 */ - "punpckldq %%mm1,%%mm1\n" /* 00 u1 00 u0 00 u1 00 u0 */ - "psubw %9,%%mm1\n" /* mm1-128:u1 u1 u0 u0 u1 u1 u0 u0 */ - - /* create Cb_g (result in mm5) */ - "movq %%mm1,%%mm5\n" /* u1 u1 u0 u0 u1 u1 u0 u0 */ - "pmullw %14,%%mm5\n" /* blue*-109dec=1.7129*64 */ - "pmullw %15,%%mm1\n" /* blue*114dec=1.78125*64 */ - "psraw $6, %%mm5\n" /* blue=red/64 */ - "psraw $6, %%mm1\n" /* blue=blue/64 */ - - /* create G (result in mm7) */ - "movq %%mm2,%%mm3\n" /* 0 L3 0 L1 0 l3 0 l1 */ - "movq %%mm4,%%mm7\n" /* 0 L2 0 L0 0 l2 0 l1 */ - "paddsw %%mm5, %%mm3\n" /* lum1+Cb_g:x G3t x G1t x g3t x g1t */ - "paddsw %%mm5, %%mm7\n" /* lum1+Cb_g:x G2t x G0t x g2t x g0t */ - "paddsw %%mm0, %%mm3\n" /* lum1+Cr_g:x G3 x G1 x g3 x g1 */ - "paddsw %%mm0, %%mm7\n" /* lum1+blue:x G2 x G0 x g2 x g0 */ - "packuswb %%mm3,%%mm3\n" /* G3 G1 g3 g1 G3 G1 g3 g1 */ - "packuswb %%mm7,%%mm7\n" /* G2 G0 g2 g0 G2 G0 g2 g0 */ - "punpcklbw %%mm3,%%mm7\n" /* G3 G2 G1 G0 g3 g2 g1 g0 */ - - /* create B (result in mm5) */ - "movq %%mm2,%%mm3\n" /* 0 L3 0 L1 0 l3 0 l1 */ - "movq %%mm4,%%mm5\n" /* 0 L2 0 L0 0 l2 0 l1 */ - "paddsw %%mm1, %%mm3\n" /* lum1+blue:x B3 x B1 x b3 x b1 */ - "paddsw %%mm1, %%mm5\n" /* lum1+blue:x B2 x B0 x b2 x b0 */ - "packuswb %%mm3,%%mm3\n" /* B3 B1 b3 b1 B3 B1 b3 b1 */ - "packuswb %%mm5,%%mm5\n" /* B2 B0 b2 b0 B2 B0 b2 b0 */ - "punpcklbw %%mm3,%%mm5\n" /* B3 B2 B1 B0 b3 b2 b1 b0 */ - - /* fill destination row1 (needed are mm6=Rr,mm7=Gg,mm5=Bb) */ - - "pxor %%mm2,%%mm2\n" /* 0 0 0 0 0 0 0 0 */ - "pxor %%mm4,%%mm4\n" /* 0 0 0 0 0 0 0 0 */ - "movq %%mm6,%%mm1\n" /* R3 R2 R1 R0 r3 r2 r1 r0 */ - "movq %%mm5,%%mm3\n" /* B3 B2 B1 B0 b3 b2 b1 b0 */ - - /* process lower lum */ - "punpcklbw %%mm4,%%mm1\n" /* 0 r3 0 r2 0 r1 0 r0 */ - "punpcklbw %%mm4,%%mm3\n" /* 0 b3 0 b2 0 b1 0 b0 */ - "movq %%mm1,%%mm2\n" /* 0 r3 0 r2 0 r1 0 r0 */ - "movq %%mm3,%%mm0\n" /* 0 b3 0 b2 0 b1 0 b0 */ - "punpcklwd %%mm1,%%mm3\n" /* 0 r1 0 b1 0 r0 0 b0 */ - "punpckhwd %%mm2,%%mm0\n" /* 0 r3 0 b3 0 r2 0 b2 */ - - "pxor %%mm2,%%mm2\n" /* 0 0 0 0 0 0 0 0 */ - "movq %%mm7,%%mm1\n" /* G3 G2 G1 G0 g3 g2 g1 g0 */ - "punpcklbw %%mm1,%%mm2\n" /* g3 0 g2 0 g1 0 g0 0 */ - "punpcklwd %%mm4,%%mm2\n" /* 0 0 g1 0 0 0 g0 0 */ - "por %%mm3, %%mm2\n" /* 0 r1 g1 b1 0 r0 g0 b0 */ - "movq %%mm2,(%3)\n" /* wrote out ! row1 */ - - "pxor %%mm2,%%mm2\n" /* 0 0 0 0 0 0 0 0 */ - "punpcklbw %%mm1,%%mm4\n" /* g3 0 g2 0 g1 0 g0 0 */ - "punpckhwd %%mm2,%%mm4\n" /* 0 0 g3 0 0 0 g2 0 */ - "por %%mm0, %%mm4\n" /* 0 r3 g3 b3 0 r2 g2 b2 */ - "movq %%mm4,8(%3)\n" /* wrote out ! row1 */ - - /* fill destination row2 (needed are mm6=Rr,mm7=Gg,mm5=Bb) */ - /* this can be done "destructive" */ - "pxor %%mm2,%%mm2\n" /* 0 0 0 0 0 0 0 0 */ - "punpckhbw %%mm2,%%mm6\n" /* 0 R3 0 R2 0 R1 0 R0 */ - "punpckhbw %%mm1,%%mm5\n" /* G3 B3 G2 B2 G1 B1 G0 B0 */ - "movq %%mm5,%%mm1\n" /* G3 B3 G2 B2 G1 B1 G0 B0 */ - "punpcklwd %%mm6,%%mm1\n" /* 0 R1 G1 B1 0 R0 G0 B0 */ - "movq %%mm1,(%5)\n" /* wrote out ! row2 */ - "punpckhwd %%mm6,%%mm5\n" /* 0 R3 G3 B3 0 R2 G2 B2 */ - "movq %%mm5,8(%5)\n" /* wrote out ! row2 */ - - "addl $4,%2\n" /* lum+4 */ - "leal 16(%3),%3\n" /* row1+16 */ - "leal 16(%5),%5\n" /* row2+16 */ - "addl $2,(%%esp)\n" /* cr+2 */ - "addl $2,%1\n" /* cb+2 */ - - "addl $4,%6\n" /* x+4 */ - "cmpl %4,%6\n" - - "jl 1b\n" - "addl %4,%2\n" /* lum += cols */ - "addl %8,%3\n" /* row1+= mod */ - "addl %8,%5\n" /* row2+= mod */ - "movl $0,%6\n" /* x=0 */ - "cmpl %7,%2\n" - "jl 1b\n" - - "addl $4,%%esp\n" /* get rid of the stack slot we reserved. */ - "emms\n" /* reset MMX registers. */ - : - : "m" (cr), "r"(cb),"r"(lum), - "r"(row1),"r"(cols),"r"(row2),"m"(x),"m"(y),"m"(mod), - "m"(MMX_0080w),"m"(MMX_VgrnRGB),"m"(MMX_VredRGB), - "m"(MMX_FF00w),"m"(MMX_00FFw),"m"(MMX_UgrnRGB), - "m"(MMX_UbluRGB) - ); -} - -void Color565DitherYV12MMX1X( int *colortab, Uint32 *rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod ) -{ - Uint16 *row1; - Uint16 *row2; - - unsigned char* y = lum +cols*rows; /* Pointer to the end */ - int x = 0; - row1 = (Uint16 *)out; /* 16 bit target */ - row2 = (Uint16 *)out+cols+mod; /* start of second row */ - mod = (mod+cols+mod)*2; /* increment for row1 in byte */ - - __asm__ __volatile__( - /* tap dance to workaround the inability to use %%ebx at will... */ - /* move one thing to the stack... */ - "pushl $0\n" /* save a slot on the stack. */ - "pushl %%ebx\n" /* save %%ebx. */ - "movl %0, %%ebx\n" /* put the thing in ebx. */ - "movl %%ebx, 4(%%esp)\n" /* put the thing in the stack slot. */ - "popl %%ebx\n" /* get back %%ebx (the PIC register). */ - - ".align 8\n" - "1:\n" - - "movd (%1), %%mm0\n" /* 4 Cb 0 0 0 0 u3 u2 u1 u0 */ - "pxor %%mm7, %%mm7\n" - "pushl %%ebx\n" - "movl 4(%%esp), %%ebx\n" - "movd (%%ebx), %%mm1\n" /* 4 Cr 0 0 0 0 v3 v2 v1 v0 */ - "popl %%ebx\n" - - "punpcklbw %%mm7, %%mm0\n" /* 4 W cb 0 u3 0 u2 0 u1 0 u0 */ - "punpcklbw %%mm7, %%mm1\n" /* 4 W cr 0 v3 0 v2 0 v1 0 v0 */ - "psubw %9, %%mm0\n" - "psubw %9, %%mm1\n" - "movq %%mm0, %%mm2\n" /* Cb 0 u3 0 u2 0 u1 0 u0 */ - "movq %%mm1, %%mm3\n" /* Cr */ - "pmullw %10, %%mm2\n" /* Cb2green 0 R3 0 R2 0 R1 0 R0 */ - "movq (%2), %%mm6\n" /* L1 l7 L6 L5 L4 L3 L2 L1 L0 */ - "pmullw %11, %%mm0\n" /* Cb2blue */ - "pand %12, %%mm6\n" /* L1 00 L6 00 L4 00 L2 00 L0 */ - "pmullw %13, %%mm3\n" /* Cr2green */ - "movq (%2), %%mm7\n" /* L2 */ - "pmullw %14, %%mm1\n" /* Cr2red */ - "psrlw $8, %%mm7\n" /* L2 00 L7 00 L5 00 L3 00 L1 */ - "pmullw %15, %%mm6\n" /* lum1 */ - "paddw %%mm3, %%mm2\n" /* Cb2green + Cr2green == green */ - "pmullw %15, %%mm7\n" /* lum2 */ - - "movq %%mm6, %%mm4\n" /* lum1 */ - "paddw %%mm0, %%mm6\n" /* lum1 +blue 00 B6 00 B4 00 B2 00 B0 */ - "movq %%mm4, %%mm5\n" /* lum1 */ - "paddw %%mm1, %%mm4\n" /* lum1 +red 00 R6 00 R4 00 R2 00 R0 */ - "paddw %%mm2, %%mm5\n" /* lum1 +green 00 G6 00 G4 00 G2 00 G0 */ - "psraw $6, %%mm4\n" /* R1 0 .. 64 */ - "movq %%mm7, %%mm3\n" /* lum2 00 L7 00 L5 00 L3 00 L1 */ - "psraw $6, %%mm5\n" /* G1 - .. + */ - "paddw %%mm0, %%mm7\n" /* Lum2 +blue 00 B7 00 B5 00 B3 00 B1 */ - "psraw $6, %%mm6\n" /* B1 0 .. 64 */ - "packuswb %%mm4, %%mm4\n" /* R1 R1 */ - "packuswb %%mm5, %%mm5\n" /* G1 G1 */ - "packuswb %%mm6, %%mm6\n" /* B1 B1 */ - "punpcklbw %%mm4, %%mm4\n" - "punpcklbw %%mm5, %%mm5\n" - - "pand %16, %%mm4\n" - "psllw $3, %%mm5\n" /* GREEN 1 */ - "punpcklbw %%mm6, %%mm6\n" - "pand %17, %%mm5\n" - "pand %16, %%mm6\n" - "por %%mm5, %%mm4\n" /* */ - "psrlw $11, %%mm6\n" /* BLUE 1 */ - "movq %%mm3, %%mm5\n" /* lum2 */ - "paddw %%mm1, %%mm3\n" /* lum2 +red 00 R7 00 R5 00 R3 00 R1 */ - "paddw %%mm2, %%mm5\n" /* lum2 +green 00 G7 00 G5 00 G3 00 G1 */ - "psraw $6, %%mm3\n" /* R2 */ - "por %%mm6, %%mm4\n" /* MM4 */ - "psraw $6, %%mm5\n" /* G2 */ - "movq (%2, %4), %%mm6\n" /* L3 load lum2 */ - "psraw $6, %%mm7\n" - "packuswb %%mm3, %%mm3\n" - "packuswb %%mm5, %%mm5\n" - "packuswb %%mm7, %%mm7\n" - "pand %12, %%mm6\n" /* L3 */ - "punpcklbw %%mm3, %%mm3\n" - "punpcklbw %%mm5, %%mm5\n" - "pmullw %15, %%mm6\n" /* lum3 */ - "punpcklbw %%mm7, %%mm7\n" - "psllw $3, %%mm5\n" /* GREEN 2 */ - "pand %16, %%mm7\n" - "pand %16, %%mm3\n" - "psrlw $11, %%mm7\n" /* BLUE 2 */ - "pand %17, %%mm5\n" - "por %%mm7, %%mm3\n" - "movq (%2,%4), %%mm7\n" /* L4 load lum2 */ - "por %%mm5, %%mm3\n" - "psrlw $8, %%mm7\n" /* L4 */ - "movq %%mm4, %%mm5\n" - "punpcklwd %%mm3, %%mm4\n" - "pmullw %15, %%mm7\n" /* lum4 */ - "punpckhwd %%mm3, %%mm5\n" - - "movq %%mm4, (%3)\n" /* write row1 */ - "movq %%mm5, 8(%3)\n" /* write row1 */ - - "movq %%mm6, %%mm4\n" /* Lum3 */ - "paddw %%mm0, %%mm6\n" /* Lum3 +blue */ - - "movq %%mm4, %%mm5\n" /* Lum3 */ - "paddw %%mm1, %%mm4\n" /* Lum3 +red */ - "paddw %%mm2, %%mm5\n" /* Lum3 +green */ - "psraw $6, %%mm4\n" - "movq %%mm7, %%mm3\n" /* Lum4 */ - "psraw $6, %%mm5\n" - "paddw %%mm0, %%mm7\n" /* Lum4 +blue */ - "psraw $6, %%mm6\n" /* Lum3 +blue */ - "movq %%mm3, %%mm0\n" /* Lum4 */ - "packuswb %%mm4, %%mm4\n" - "paddw %%mm1, %%mm3\n" /* Lum4 +red */ - "packuswb %%mm5, %%mm5\n" - "paddw %%mm2, %%mm0\n" /* Lum4 +green */ - "packuswb %%mm6, %%mm6\n" - "punpcklbw %%mm4, %%mm4\n" - "punpcklbw %%mm5, %%mm5\n" - "punpcklbw %%mm6, %%mm6\n" - "psllw $3, %%mm5\n" /* GREEN 3 */ - "pand %16, %%mm4\n" - "psraw $6, %%mm3\n" /* psr 6 */ - "psraw $6, %%mm0\n" - "pand %16, %%mm6\n" /* BLUE */ - "pand %17, %%mm5\n" - "psrlw $11, %%mm6\n" /* BLUE 3 */ - "por %%mm5, %%mm4\n" - "psraw $6, %%mm7\n" - "por %%mm6, %%mm4\n" - "packuswb %%mm3, %%mm3\n" - "packuswb %%mm0, %%mm0\n" - "packuswb %%mm7, %%mm7\n" - "punpcklbw %%mm3, %%mm3\n" - "punpcklbw %%mm0, %%mm0\n" - "punpcklbw %%mm7, %%mm7\n" - "pand %16, %%mm3\n" - "pand %16, %%mm7\n" /* BLUE */ - "psllw $3, %%mm0\n" /* GREEN 4 */ - "psrlw $11, %%mm7\n" - "pand %17, %%mm0\n" - "por %%mm7, %%mm3\n" - "por %%mm0, %%mm3\n" - - "movq %%mm4, %%mm5\n" - - "punpcklwd %%mm3, %%mm4\n" - "punpckhwd %%mm3, %%mm5\n" - - "movq %%mm4, (%5)\n" - "movq %%mm5, 8(%5)\n" - - "addl $8, %6\n" - "addl $8, %2\n" - "addl $4, (%%esp)\n" - "addl $4, %1\n" - "cmpl %4, %6\n" - "leal 16(%3), %3\n" - "leal 16(%5),%5\n" /* row2+16 */ - - "jl 1b\n" - "addl %4, %2\n" /* lum += cols */ - "addl %8, %3\n" /* row1+= mod */ - "addl %8, %5\n" /* row2+= mod */ - "movl $0, %6\n" /* x=0 */ - "cmpl %7, %2\n" - "jl 1b\n" - "addl $4, %%esp\n" /* get rid of the stack slot we reserved. */ - "emms\n" - : - : "m" (cr), "r"(cb),"r"(lum), - "r"(row1),"r"(cols),"r"(row2),"m"(x),"m"(y),"m"(mod), - "m"(MMX_0080w),"m"(MMX_Ugrn565),"m"(MMX_Ublu5x5), - "m"(MMX_00FFw),"m"(MMX_Vgrn565),"m"(MMX_Vred5x5), - "m"(MMX_Ycoeff),"m"(MMX_red565),"m"(MMX_grn565) - ); -} - -/* *INDENT-ON* */ - -#endif /* GCC3 i386 inline assembly */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/SDL_yuv_sw.c b/3rdparty/SDL2/src/render/SDL_yuv_sw.c deleted file mode 100644 index 7fc6b88654c..00000000000 --- a/3rdparty/SDL2/src/render/SDL_yuv_sw.c +++ /dev/null @@ -1,1405 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../SDL_internal.h" - -/* This is the software implementation of the YUV texture support */ - -/* This code was derived from code carrying the following copyright notices: - - * Copyright (c) 1995 The Regents of the University of California. - * All rights reserved. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose, without fee, and without written agreement is - * hereby granted, provided that the above copyright notice and the following - * two paragraphs appear in all copies of this software. - * - * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR - * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT - * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF - * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - - * Copyright (c) 1995 Erik Corry - * All rights reserved. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose, without fee, and without written agreement is - * hereby granted, provided that the above copyright notice and the following - * two paragraphs appear in all copies of this software. - * - * IN NO EVENT SHALL ERIK CORRY BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, - * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF - * THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF ERIK CORRY HAS BEEN ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * - * ERIK CORRY SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" - * BASIS, AND ERIK CORRY HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, - * UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - - * Portions of this software Copyright (c) 1995 Brown University. - * All rights reserved. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose, without fee, and without written agreement - * is hereby granted, provided that the above copyright notice and the - * following two paragraphs appear in all copies of this software. - * - * IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE TO ANY PARTY FOR - * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT - * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF BROWN - * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * BROWN UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" - * BASIS, AND BROWN UNIVERSITY HAS NO OBLIGATION TO PROVIDE MAINTENANCE, - * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - */ - -#include "SDL_assert.h" -#include "SDL_video.h" -#include "SDL_cpuinfo.h" -#include "SDL_yuv_sw_c.h" - - -/* The colorspace conversion functions */ - -#if (__GNUC__ > 2) && defined(__i386__) && __OPTIMIZE__ && SDL_ASSEMBLY_ROUTINES -extern void Color565DitherYV12MMX1X(int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod); -extern void ColorRGBDitherYV12MMX1X(int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod); -#endif - -static void -Color16DitherYV12Mod1X(int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod) -{ - unsigned short *row1; - unsigned short *row2; - unsigned char *lum2; - int x, y; - int cr_r; - int crb_g; - int cb_b; - int cols_2 = cols / 2; - - row1 = (unsigned short *) out; - row2 = row1 + cols + mod; - lum2 = lum + cols; - - mod += cols + mod; - - y = rows / 2; - while (y--) { - x = cols_2; - while (x--) { - register int L; - - cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; - crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] - + colortab[*cb + 2 * 256]; - cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; - ++cr; - ++cb; - - L = *lum++; - *row1++ = (unsigned short) (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | - rgb_2_pix[L + cb_b]); - - L = *lum++; - *row1++ = (unsigned short) (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | - rgb_2_pix[L + cb_b]); - - - /* Now, do second row. */ - - L = *lum2++; - *row2++ = (unsigned short) (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | - rgb_2_pix[L + cb_b]); - - L = *lum2++; - *row2++ = (unsigned short) (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | - rgb_2_pix[L + cb_b]); - } - - /* - * These values are at the start of the next line, (due - * to the ++'s above),but they need to be at the start - * of the line after that. - */ - lum += cols; - lum2 += cols; - row1 += mod; - row2 += mod; - } -} - -static void -Color24DitherYV12Mod1X(int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod) -{ - unsigned int value; - unsigned char *row1; - unsigned char *row2; - unsigned char *lum2; - int x, y; - int cr_r; - int crb_g; - int cb_b; - int cols_2 = cols / 2; - - row1 = out; - row2 = row1 + cols * 3 + mod * 3; - lum2 = lum + cols; - - mod += cols + mod; - mod *= 3; - - y = rows / 2; - while (y--) { - x = cols_2; - while (x--) { - register int L; - - cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; - crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] - + colortab[*cb + 2 * 256]; - cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; - ++cr; - ++cb; - - L = *lum++; - value = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - *row1++ = (value) & 0xFF; - *row1++ = (value >> 8) & 0xFF; - *row1++ = (value >> 16) & 0xFF; - - L = *lum++; - value = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - *row1++ = (value) & 0xFF; - *row1++ = (value >> 8) & 0xFF; - *row1++ = (value >> 16) & 0xFF; - - - /* Now, do second row. */ - - L = *lum2++; - value = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - *row2++ = (value) & 0xFF; - *row2++ = (value >> 8) & 0xFF; - *row2++ = (value >> 16) & 0xFF; - - L = *lum2++; - value = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - *row2++ = (value) & 0xFF; - *row2++ = (value >> 8) & 0xFF; - *row2++ = (value >> 16) & 0xFF; - } - - /* - * These values are at the start of the next line, (due - * to the ++'s above),but they need to be at the start - * of the line after that. - */ - lum += cols; - lum2 += cols; - row1 += mod; - row2 += mod; - } -} - -static void -Color32DitherYV12Mod1X(int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod) -{ - unsigned int *row1; - unsigned int *row2; - unsigned char *lum2; - int x, y; - int cr_r; - int crb_g; - int cb_b; - int cols_2 = cols / 2; - - row1 = (unsigned int *) out; - row2 = row1 + cols + mod; - lum2 = lum + cols; - - mod += cols + mod; - - y = rows / 2; - while (y--) { - x = cols_2; - while (x--) { - register int L; - - cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; - crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] - + colortab[*cb + 2 * 256]; - cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; - ++cr; - ++cb; - - L = *lum++; - *row1++ = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - - L = *lum++; - *row1++ = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - - - /* Now, do second row. */ - - L = *lum2++; - *row2++ = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - - L = *lum2++; - *row2++ = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - } - - /* - * These values are at the start of the next line, (due - * to the ++'s above),but they need to be at the start - * of the line after that. - */ - lum += cols; - lum2 += cols; - row1 += mod; - row2 += mod; - } -} - -/* - * In this function I make use of a nasty trick. The tables have the lower - * 16 bits replicated in the upper 16. This means I can write ints and get - * the horisontal doubling for free (almost). - */ -static void -Color16DitherYV12Mod2X(int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod) -{ - unsigned int *row1 = (unsigned int *) out; - const int next_row = cols + (mod / 2); - unsigned int *row2 = row1 + 2 * next_row; - unsigned char *lum2; - int x, y; - int cr_r; - int crb_g; - int cb_b; - int cols_2 = cols / 2; - - lum2 = lum + cols; - - mod = (next_row * 3) + (mod / 2); - - y = rows / 2; - while (y--) { - x = cols_2; - while (x--) { - register int L; - - cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; - crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] - + colortab[*cb + 2 * 256]; - cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; - ++cr; - ++cb; - - L = *lum++; - row1[0] = row1[next_row] = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | - rgb_2_pix[L + cb_b]); - row1++; - - L = *lum++; - row1[0] = row1[next_row] = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | - rgb_2_pix[L + cb_b]); - row1++; - - - /* Now, do second row. */ - - L = *lum2++; - row2[0] = row2[next_row] = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | - rgb_2_pix[L + cb_b]); - row2++; - - L = *lum2++; - row2[0] = row2[next_row] = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | - rgb_2_pix[L + cb_b]); - row2++; - } - - /* - * These values are at the start of the next line, (due - * to the ++'s above),but they need to be at the start - * of the line after that. - */ - lum += cols; - lum2 += cols; - row1 += mod; - row2 += mod; - } -} - -static void -Color24DitherYV12Mod2X(int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod) -{ - unsigned int value; - unsigned char *row1 = out; - const int next_row = (cols * 2 + mod) * 3; - unsigned char *row2 = row1 + 2 * next_row; - unsigned char *lum2; - int x, y; - int cr_r; - int crb_g; - int cb_b; - int cols_2 = cols / 2; - - lum2 = lum + cols; - - mod = next_row * 3 + mod * 3; - - y = rows / 2; - while (y--) { - x = cols_2; - while (x--) { - register int L; - - cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; - crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] - + colortab[*cb + 2 * 256]; - cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; - ++cr; - ++cb; - - L = *lum++; - value = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - row1[0 + 0] = row1[3 + 0] = row1[next_row + 0] = - row1[next_row + 3 + 0] = (value) & 0xFF; - row1[0 + 1] = row1[3 + 1] = row1[next_row + 1] = - row1[next_row + 3 + 1] = (value >> 8) & 0xFF; - row1[0 + 2] = row1[3 + 2] = row1[next_row + 2] = - row1[next_row + 3 + 2] = (value >> 16) & 0xFF; - row1 += 2 * 3; - - L = *lum++; - value = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - row1[0 + 0] = row1[3 + 0] = row1[next_row + 0] = - row1[next_row + 3 + 0] = (value) & 0xFF; - row1[0 + 1] = row1[3 + 1] = row1[next_row + 1] = - row1[next_row + 3 + 1] = (value >> 8) & 0xFF; - row1[0 + 2] = row1[3 + 2] = row1[next_row + 2] = - row1[next_row + 3 + 2] = (value >> 16) & 0xFF; - row1 += 2 * 3; - - - /* Now, do second row. */ - - L = *lum2++; - value = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - row2[0 + 0] = row2[3 + 0] = row2[next_row + 0] = - row2[next_row + 3 + 0] = (value) & 0xFF; - row2[0 + 1] = row2[3 + 1] = row2[next_row + 1] = - row2[next_row + 3 + 1] = (value >> 8) & 0xFF; - row2[0 + 2] = row2[3 + 2] = row2[next_row + 2] = - row2[next_row + 3 + 2] = (value >> 16) & 0xFF; - row2 += 2 * 3; - - L = *lum2++; - value = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - row2[0 + 0] = row2[3 + 0] = row2[next_row + 0] = - row2[next_row + 3 + 0] = (value) & 0xFF; - row2[0 + 1] = row2[3 + 1] = row2[next_row + 1] = - row2[next_row + 3 + 1] = (value >> 8) & 0xFF; - row2[0 + 2] = row2[3 + 2] = row2[next_row + 2] = - row2[next_row + 3 + 2] = (value >> 16) & 0xFF; - row2 += 2 * 3; - } - - /* - * These values are at the start of the next line, (due - * to the ++'s above),but they need to be at the start - * of the line after that. - */ - lum += cols; - lum2 += cols; - row1 += mod; - row2 += mod; - } -} - -static void -Color32DitherYV12Mod2X(int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod) -{ - unsigned int *row1 = (unsigned int *) out; - const int next_row = cols * 2 + mod; - unsigned int *row2 = row1 + 2 * next_row; - unsigned char *lum2; - int x, y; - int cr_r; - int crb_g; - int cb_b; - int cols_2 = cols / 2; - - lum2 = lum + cols; - - mod = (next_row * 3) + mod; - - y = rows / 2; - while (y--) { - x = cols_2; - while (x--) { - register int L; - - cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; - crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] - + colortab[*cb + 2 * 256]; - cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; - ++cr; - ++cb; - - L = *lum++; - row1[0] = row1[1] = row1[next_row] = row1[next_row + 1] = - (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - row1 += 2; - - L = *lum++; - row1[0] = row1[1] = row1[next_row] = row1[next_row + 1] = - (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - row1 += 2; - - - /* Now, do second row. */ - - L = *lum2++; - row2[0] = row2[1] = row2[next_row] = row2[next_row + 1] = - (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - row2 += 2; - - L = *lum2++; - row2[0] = row2[1] = row2[next_row] = row2[next_row + 1] = - (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - row2 += 2; - } - - /* - * These values are at the start of the next line, (due - * to the ++'s above),but they need to be at the start - * of the line after that. - */ - lum += cols; - lum2 += cols; - row1 += mod; - row2 += mod; - } -} - -static void -Color16DitherYUY2Mod1X(int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod) -{ - unsigned short *row; - int x, y; - int cr_r; - int crb_g; - int cb_b; - int cols_2 = cols / 2; - - row = (unsigned short *) out; - - y = rows; - while (y--) { - x = cols_2; - while (x--) { - register int L; - - cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; - crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] - + colortab[*cb + 2 * 256]; - cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; - cr += 4; - cb += 4; - - L = *lum; - lum += 2; - *row++ = (unsigned short) (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | - rgb_2_pix[L + cb_b]); - - L = *lum; - lum += 2; - *row++ = (unsigned short) (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | - rgb_2_pix[L + cb_b]); - - } - - row += mod; - } -} - -static void -Color24DitherYUY2Mod1X(int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod) -{ - unsigned int value; - unsigned char *row; - int x, y; - int cr_r; - int crb_g; - int cb_b; - int cols_2 = cols / 2; - - row = (unsigned char *) out; - mod *= 3; - y = rows; - while (y--) { - x = cols_2; - while (x--) { - register int L; - - cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; - crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] - + colortab[*cb + 2 * 256]; - cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; - cr += 4; - cb += 4; - - L = *lum; - lum += 2; - value = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - *row++ = (value) & 0xFF; - *row++ = (value >> 8) & 0xFF; - *row++ = (value >> 16) & 0xFF; - - L = *lum; - lum += 2; - value = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - *row++ = (value) & 0xFF; - *row++ = (value >> 8) & 0xFF; - *row++ = (value >> 16) & 0xFF; - - } - row += mod; - } -} - -static void -Color32DitherYUY2Mod1X(int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod) -{ - unsigned int *row; - int x, y; - int cr_r; - int crb_g; - int cb_b; - int cols_2 = cols / 2; - - row = (unsigned int *) out; - y = rows; - while (y--) { - x = cols_2; - while (x--) { - register int L; - - cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; - crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] - + colortab[*cb + 2 * 256]; - cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; - cr += 4; - cb += 4; - - L = *lum; - lum += 2; - *row++ = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - - L = *lum; - lum += 2; - *row++ = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - - - } - row += mod; - } -} - -/* - * In this function I make use of a nasty trick. The tables have the lower - * 16 bits replicated in the upper 16. This means I can write ints and get - * the horisontal doubling for free (almost). - */ -static void -Color16DitherYUY2Mod2X(int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod) -{ - unsigned int *row = (unsigned int *) out; - const int next_row = cols + (mod / 2); - int x, y; - int cr_r; - int crb_g; - int cb_b; - int cols_2 = cols / 2; - - y = rows; - while (y--) { - x = cols_2; - while (x--) { - register int L; - - cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; - crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] - + colortab[*cb + 2 * 256]; - cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; - cr += 4; - cb += 4; - - L = *lum; - lum += 2; - row[0] = row[next_row] = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | - rgb_2_pix[L + cb_b]); - row++; - - L = *lum; - lum += 2; - row[0] = row[next_row] = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | - rgb_2_pix[L + cb_b]); - row++; - - } - row += next_row; - } -} - -static void -Color24DitherYUY2Mod2X(int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod) -{ - unsigned int value; - unsigned char *row = out; - const int next_row = (cols * 2 + mod) * 3; - int x, y; - int cr_r; - int crb_g; - int cb_b; - int cols_2 = cols / 2; - y = rows; - while (y--) { - x = cols_2; - while (x--) { - register int L; - - cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; - crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] - + colortab[*cb + 2 * 256]; - cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; - cr += 4; - cb += 4; - - L = *lum; - lum += 2; - value = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - row[0 + 0] = row[3 + 0] = row[next_row + 0] = - row[next_row + 3 + 0] = (value) & 0xFF; - row[0 + 1] = row[3 + 1] = row[next_row + 1] = - row[next_row + 3 + 1] = (value >> 8) & 0xFF; - row[0 + 2] = row[3 + 2] = row[next_row + 2] = - row[next_row + 3 + 2] = (value >> 16) & 0xFF; - row += 2 * 3; - - L = *lum; - lum += 2; - value = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - row[0 + 0] = row[3 + 0] = row[next_row + 0] = - row[next_row + 3 + 0] = (value) & 0xFF; - row[0 + 1] = row[3 + 1] = row[next_row + 1] = - row[next_row + 3 + 1] = (value >> 8) & 0xFF; - row[0 + 2] = row[3 + 2] = row[next_row + 2] = - row[next_row + 3 + 2] = (value >> 16) & 0xFF; - row += 2 * 3; - - } - row += next_row; - } -} - -static void -Color32DitherYUY2Mod2X(int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod) -{ - unsigned int *row = (unsigned int *) out; - const int next_row = cols * 2 + mod; - int x, y; - int cr_r; - int crb_g; - int cb_b; - int cols_2 = cols / 2; - mod += mod; - y = rows; - while (y--) { - x = cols_2; - while (x--) { - register int L; - - cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; - crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] - + colortab[*cb + 2 * 256]; - cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; - cr += 4; - cb += 4; - - L = *lum; - lum += 2; - row[0] = row[1] = row[next_row] = row[next_row + 1] = - (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - row += 2; - - L = *lum; - lum += 2; - row[0] = row[1] = row[next_row] = row[next_row + 1] = - (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - row += 2; - - - } - - row += next_row; - } -} - -/* - * How many 1 bits are there in the Uint32. - * Low performance, do not call often. - */ -static int -number_of_bits_set(Uint32 a) -{ - if (!a) - return 0; - if (a & 1) - return 1 + number_of_bits_set(a >> 1); - return (number_of_bits_set(a >> 1)); -} - -/* - * How many 0 bits are there at least significant end of Uint32. - * Low performance, do not call often. - */ -static int -free_bits_at_bottom(Uint32 a) -{ - /* assume char is 8 bits */ - if (!a) - return sizeof(Uint32) * 8; - if (((Sint32) a) & 1l) - return 0; - return 1 + free_bits_at_bottom(a >> 1); -} - -static int -SDL_SW_SetupYUVDisplay(SDL_SW_YUVTexture * swdata, Uint32 target_format) -{ - Uint32 *r_2_pix_alloc; - Uint32 *g_2_pix_alloc; - Uint32 *b_2_pix_alloc; - int i; - int bpp; - Uint32 Rmask, Gmask, Bmask, Amask; - - if (!SDL_PixelFormatEnumToMasks - (target_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask) || bpp < 15) { - return SDL_SetError("Unsupported YUV destination format"); - } - - swdata->target_format = target_format; - r_2_pix_alloc = &swdata->rgb_2_pix[0 * 768]; - g_2_pix_alloc = &swdata->rgb_2_pix[1 * 768]; - b_2_pix_alloc = &swdata->rgb_2_pix[2 * 768]; - - /* - * Set up entries 0-255 in rgb-to-pixel value tables. - */ - for (i = 0; i < 256; ++i) { - r_2_pix_alloc[i + 256] = i >> (8 - number_of_bits_set(Rmask)); - r_2_pix_alloc[i + 256] <<= free_bits_at_bottom(Rmask); - r_2_pix_alloc[i + 256] |= Amask; - g_2_pix_alloc[i + 256] = i >> (8 - number_of_bits_set(Gmask)); - g_2_pix_alloc[i + 256] <<= free_bits_at_bottom(Gmask); - g_2_pix_alloc[i + 256] |= Amask; - b_2_pix_alloc[i + 256] = i >> (8 - number_of_bits_set(Bmask)); - b_2_pix_alloc[i + 256] <<= free_bits_at_bottom(Bmask); - b_2_pix_alloc[i + 256] |= Amask; - } - - /* - * If we have 16-bit output depth, then we double the value - * in the top word. This means that we can write out both - * pixels in the pixel doubling mode with one op. It is - * harmless in the normal case as storing a 32-bit value - * through a short pointer will lose the top bits anyway. - */ - if (SDL_BYTESPERPIXEL(target_format) == 2) { - for (i = 0; i < 256; ++i) { - r_2_pix_alloc[i + 256] |= (r_2_pix_alloc[i + 256]) << 16; - g_2_pix_alloc[i + 256] |= (g_2_pix_alloc[i + 256]) << 16; - b_2_pix_alloc[i + 256] |= (b_2_pix_alloc[i + 256]) << 16; - } - } - - /* - * Spread out the values we have to the rest of the array so that - * we do not need to check for overflow. - */ - for (i = 0; i < 256; ++i) { - r_2_pix_alloc[i] = r_2_pix_alloc[256]; - r_2_pix_alloc[i + 512] = r_2_pix_alloc[511]; - g_2_pix_alloc[i] = g_2_pix_alloc[256]; - g_2_pix_alloc[i + 512] = g_2_pix_alloc[511]; - b_2_pix_alloc[i] = b_2_pix_alloc[256]; - b_2_pix_alloc[i + 512] = b_2_pix_alloc[511]; - } - - /* You have chosen wisely... */ - switch (swdata->format) { - case SDL_PIXELFORMAT_YV12: - case SDL_PIXELFORMAT_IYUV: - if (SDL_BYTESPERPIXEL(target_format) == 2) { -#if (__GNUC__ > 2) && defined(__i386__) && __OPTIMIZE__ && SDL_ASSEMBLY_ROUTINES - /* inline assembly functions */ - if (SDL_HasMMX() && (Rmask == 0xF800) && - (Gmask == 0x07E0) && (Bmask == 0x001F) - && (swdata->w & 15) == 0) { -/* printf("Using MMX 16-bit 565 dither\n"); */ - swdata->Display1X = Color565DitherYV12MMX1X; - } else { -/* printf("Using C 16-bit dither\n"); */ - swdata->Display1X = Color16DitherYV12Mod1X; - } -#else - swdata->Display1X = Color16DitherYV12Mod1X; -#endif - swdata->Display2X = Color16DitherYV12Mod2X; - } - if (SDL_BYTESPERPIXEL(target_format) == 3) { - swdata->Display1X = Color24DitherYV12Mod1X; - swdata->Display2X = Color24DitherYV12Mod2X; - } - if (SDL_BYTESPERPIXEL(target_format) == 4) { -#if (__GNUC__ > 2) && defined(__i386__) && __OPTIMIZE__ && SDL_ASSEMBLY_ROUTINES - /* inline assembly functions */ - if (SDL_HasMMX() && (Rmask == 0x00FF0000) && - (Gmask == 0x0000FF00) && - (Bmask == 0x000000FF) && (swdata->w & 15) == 0) { -/* printf("Using MMX 32-bit dither\n"); */ - swdata->Display1X = ColorRGBDitherYV12MMX1X; - } else { -/* printf("Using C 32-bit dither\n"); */ - swdata->Display1X = Color32DitherYV12Mod1X; - } -#else - swdata->Display1X = Color32DitherYV12Mod1X; -#endif - swdata->Display2X = Color32DitherYV12Mod2X; - } - break; - case SDL_PIXELFORMAT_YUY2: - case SDL_PIXELFORMAT_UYVY: - case SDL_PIXELFORMAT_YVYU: - if (SDL_BYTESPERPIXEL(target_format) == 2) { - swdata->Display1X = Color16DitherYUY2Mod1X; - swdata->Display2X = Color16DitherYUY2Mod2X; - } - if (SDL_BYTESPERPIXEL(target_format) == 3) { - swdata->Display1X = Color24DitherYUY2Mod1X; - swdata->Display2X = Color24DitherYUY2Mod2X; - } - if (SDL_BYTESPERPIXEL(target_format) == 4) { - swdata->Display1X = Color32DitherYUY2Mod1X; - swdata->Display2X = Color32DitherYUY2Mod2X; - } - break; - default: - /* We should never get here (caught above) */ - break; - } - - SDL_FreeSurface(swdata->display); - swdata->display = NULL; - return 0; -} - -SDL_SW_YUVTexture * -SDL_SW_CreateYUVTexture(Uint32 format, int w, int h) -{ - SDL_SW_YUVTexture *swdata; - int *Cr_r_tab; - int *Cr_g_tab; - int *Cb_g_tab; - int *Cb_b_tab; - int i; - int CR, CB; - - switch (format) { - case SDL_PIXELFORMAT_YV12: - case SDL_PIXELFORMAT_IYUV: - case SDL_PIXELFORMAT_YUY2: - case SDL_PIXELFORMAT_UYVY: - case SDL_PIXELFORMAT_YVYU: - break; - default: - SDL_SetError("Unsupported YUV format"); - return NULL; - } - - swdata = (SDL_SW_YUVTexture *) SDL_calloc(1, sizeof(*swdata)); - if (!swdata) { - SDL_OutOfMemory(); - return NULL; - } - - swdata->format = format; - swdata->target_format = SDL_PIXELFORMAT_UNKNOWN; - swdata->w = w; - swdata->h = h; - swdata->pixels = (Uint8 *) SDL_malloc(w * h * 2); - swdata->colortab = (int *) SDL_malloc(4 * 256 * sizeof(int)); - swdata->rgb_2_pix = (Uint32 *) SDL_malloc(3 * 768 * sizeof(Uint32)); - if (!swdata->pixels || !swdata->colortab || !swdata->rgb_2_pix) { - SDL_SW_DestroyYUVTexture(swdata); - SDL_OutOfMemory(); - return NULL; - } - - /* Generate the tables for the display surface */ - Cr_r_tab = &swdata->colortab[0 * 256]; - Cr_g_tab = &swdata->colortab[1 * 256]; - Cb_g_tab = &swdata->colortab[2 * 256]; - Cb_b_tab = &swdata->colortab[3 * 256]; - for (i = 0; i < 256; i++) { - /* Gamma correction (luminescence table) and chroma correction - would be done here. See the Berkeley mpeg_play sources. - */ - CB = CR = (i - 128); - Cr_r_tab[i] = (int) ((0.419 / 0.299) * CR); - Cr_g_tab[i] = (int) (-(0.299 / 0.419) * CR); - Cb_g_tab[i] = (int) (-(0.114 / 0.331) * CB); - Cb_b_tab[i] = (int) ((0.587 / 0.331) * CB); - } - - /* Find the pitch and offset values for the overlay */ - switch (format) { - case SDL_PIXELFORMAT_YV12: - case SDL_PIXELFORMAT_IYUV: - swdata->pitches[0] = w; - swdata->pitches[1] = swdata->pitches[0] / 2; - swdata->pitches[2] = swdata->pitches[0] / 2; - swdata->planes[0] = swdata->pixels; - swdata->planes[1] = swdata->planes[0] + swdata->pitches[0] * h; - swdata->planes[2] = swdata->planes[1] + swdata->pitches[1] * h / 2; - break; - case SDL_PIXELFORMAT_YUY2: - case SDL_PIXELFORMAT_UYVY: - case SDL_PIXELFORMAT_YVYU: - swdata->pitches[0] = w * 2; - swdata->planes[0] = swdata->pixels; - break; - default: - SDL_assert(0 && "We should never get here (caught above)"); - break; - } - - /* We're all done.. */ - return (swdata); -} - -int -SDL_SW_QueryYUVTexturePixels(SDL_SW_YUVTexture * swdata, void **pixels, - int *pitch) -{ - *pixels = swdata->planes[0]; - *pitch = swdata->pitches[0]; - return 0; -} - -int -SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect, - const void *pixels, int pitch) -{ - switch (swdata->format) { - case SDL_PIXELFORMAT_YV12: - case SDL_PIXELFORMAT_IYUV: - if (rect->x == 0 && rect->y == 0 && - rect->w == swdata->w && rect->h == swdata->h) { - SDL_memcpy(swdata->pixels, pixels, - (swdata->h * swdata->w) + (swdata->h * swdata->w) / 2); - } else { - Uint8 *src, *dst; - int row; - size_t length; - - /* Copy the Y plane */ - src = (Uint8 *) pixels; - dst = swdata->pixels + rect->y * swdata->w + rect->x; - length = rect->w; - for (row = 0; row < rect->h; ++row) { - SDL_memcpy(dst, src, length); - src += pitch; - dst += swdata->w; - } - - /* Copy the next plane */ - src = (Uint8 *) pixels + rect->h * pitch; - dst = swdata->pixels + swdata->h * swdata->w; - dst += rect->y/2 * swdata->w/2 + rect->x/2; - length = rect->w / 2; - for (row = 0; row < rect->h/2; ++row) { - SDL_memcpy(dst, src, length); - src += pitch/2; - dst += swdata->w/2; - } - - /* Copy the next plane */ - src = (Uint8 *) pixels + rect->h * pitch + (rect->h * pitch) / 4; - dst = swdata->pixels + swdata->h * swdata->w + - (swdata->h * swdata->w) / 4; - dst += rect->y/2 * swdata->w/2 + rect->x/2; - length = rect->w / 2; - for (row = 0; row < rect->h/2; ++row) { - SDL_memcpy(dst, src, length); - src += pitch/2; - dst += swdata->w/2; - } - } - break; - case SDL_PIXELFORMAT_YUY2: - case SDL_PIXELFORMAT_UYVY: - case SDL_PIXELFORMAT_YVYU: - { - Uint8 *src, *dst; - int row; - size_t length; - - src = (Uint8 *) pixels; - dst = - swdata->planes[0] + rect->y * swdata->pitches[0] + - rect->x * 2; - length = rect->w * 2; - for (row = 0; row < rect->h; ++row) { - SDL_memcpy(dst, src, length); - src += pitch; - dst += swdata->pitches[0]; - } - } - break; - } - return 0; -} - -int -SDL_SW_UpdateYUVTexturePlanar(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect, - const Uint8 *Yplane, int Ypitch, - const Uint8 *Uplane, int Upitch, - const Uint8 *Vplane, int Vpitch) -{ - const Uint8 *src; - Uint8 *dst; - int row; - size_t length; - - /* Copy the Y plane */ - src = Yplane; - dst = swdata->pixels + rect->y * swdata->w + rect->x; - length = rect->w; - for (row = 0; row < rect->h; ++row) { - SDL_memcpy(dst, src, length); - src += Ypitch; - dst += swdata->w; - } - - /* Copy the U plane */ - src = Uplane; - if (swdata->format == SDL_PIXELFORMAT_IYUV) { - dst = swdata->pixels + swdata->h * swdata->w; - } else { - dst = swdata->pixels + swdata->h * swdata->w + - (swdata->h * swdata->w) / 4; - } - dst += rect->y/2 * swdata->w/2 + rect->x/2; - length = rect->w / 2; - for (row = 0; row < rect->h/2; ++row) { - SDL_memcpy(dst, src, length); - src += Upitch; - dst += swdata->w/2; - } - - /* Copy the V plane */ - src = Vplane; - if (swdata->format == SDL_PIXELFORMAT_YV12) { - dst = swdata->pixels + swdata->h * swdata->w; - } else { - dst = swdata->pixels + swdata->h * swdata->w + - (swdata->h * swdata->w) / 4; - } - dst += rect->y/2 * swdata->w/2 + rect->x/2; - length = rect->w / 2; - for (row = 0; row < rect->h/2; ++row) { - SDL_memcpy(dst, src, length); - src += Vpitch; - dst += swdata->w/2; - } - return 0; -} - -int -SDL_SW_LockYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect, - void **pixels, int *pitch) -{ - switch (swdata->format) { - case SDL_PIXELFORMAT_YV12: - case SDL_PIXELFORMAT_IYUV: - if (rect - && (rect->x != 0 || rect->y != 0 || rect->w != swdata->w - || rect->h != swdata->h)) { - return SDL_SetError - ("YV12 and IYUV textures only support full surface locks"); - } - break; - } - - if (rect) { - *pixels = swdata->planes[0] + rect->y * swdata->pitches[0] + rect->x * 2; - } else { - *pixels = swdata->planes[0]; - } - *pitch = swdata->pitches[0]; - return 0; -} - -void -SDL_SW_UnlockYUVTexture(SDL_SW_YUVTexture * swdata) -{ -} - -int -SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture * swdata, const SDL_Rect * srcrect, - Uint32 target_format, int w, int h, void *pixels, - int pitch) -{ - const int targetbpp = SDL_BYTESPERPIXEL(target_format); - int stretch; - int scale_2x; - Uint8 *lum, *Cr, *Cb; - int mod; - - if (targetbpp == 0) { - return SDL_SetError("Invalid target pixel format"); - } - - /* Make sure we're set up to display in the desired format */ - if (target_format != swdata->target_format) { - if (SDL_SW_SetupYUVDisplay(swdata, target_format) < 0) { - return -1; - } - } - - stretch = 0; - scale_2x = 0; - if (srcrect->x || srcrect->y || srcrect->w < swdata->w - || srcrect->h < swdata->h) { - /* The source rectangle has been clipped. - Using a scratch surface is easier than adding clipped - source support to all the blitters, plus that would - slow them down in the general unclipped case. - */ - stretch = 1; - } else if ((srcrect->w != w) || (srcrect->h != h)) { - if ((w == 2 * srcrect->w) && (h == 2 * srcrect->h)) { - scale_2x = 1; - } else { - stretch = 1; - } - } - if (stretch) { - int bpp; - Uint32 Rmask, Gmask, Bmask, Amask; - - if (swdata->display) { - swdata->display->w = w; - swdata->display->h = h; - swdata->display->pixels = pixels; - swdata->display->pitch = pitch; - } else { - /* This must have succeeded in SDL_SW_SetupYUVDisplay() earlier */ - SDL_PixelFormatEnumToMasks(target_format, &bpp, &Rmask, &Gmask, - &Bmask, &Amask); - swdata->display = - SDL_CreateRGBSurfaceFrom(pixels, w, h, bpp, pitch, Rmask, - Gmask, Bmask, Amask); - if (!swdata->display) { - return (-1); - } - } - if (!swdata->stretch) { - /* This must have succeeded in SDL_SW_SetupYUVDisplay() earlier */ - SDL_PixelFormatEnumToMasks(target_format, &bpp, &Rmask, &Gmask, - &Bmask, &Amask); - swdata->stretch = - SDL_CreateRGBSurface(0, swdata->w, swdata->h, bpp, Rmask, - Gmask, Bmask, Amask); - if (!swdata->stretch) { - return (-1); - } - } - pixels = swdata->stretch->pixels; - pitch = swdata->stretch->pitch; - } - switch (swdata->format) { - case SDL_PIXELFORMAT_YV12: - lum = swdata->planes[0]; - Cr = swdata->planes[1]; - Cb = swdata->planes[2]; - break; - case SDL_PIXELFORMAT_IYUV: - lum = swdata->planes[0]; - Cr = swdata->planes[2]; - Cb = swdata->planes[1]; - break; - case SDL_PIXELFORMAT_YUY2: - lum = swdata->planes[0]; - Cr = lum + 3; - Cb = lum + 1; - break; - case SDL_PIXELFORMAT_UYVY: - lum = swdata->planes[0] + 1; - Cr = lum + 1; - Cb = lum - 1; - break; - case SDL_PIXELFORMAT_YVYU: - lum = swdata->planes[0]; - Cr = lum + 1; - Cb = lum + 3; - break; - default: - return SDL_SetError("Unsupported YUV format in copy"); - } - mod = (pitch / targetbpp); - - if (scale_2x) { - mod -= (swdata->w * 2); - swdata->Display2X(swdata->colortab, swdata->rgb_2_pix, - lum, Cr, Cb, pixels, swdata->h, swdata->w, mod); - } else { - mod -= swdata->w; - swdata->Display1X(swdata->colortab, swdata->rgb_2_pix, - lum, Cr, Cb, pixels, swdata->h, swdata->w, mod); - } - if (stretch) { - SDL_Rect rect = *srcrect; - SDL_SoftStretch(swdata->stretch, &rect, swdata->display, NULL); - } - return 0; -} - -void -SDL_SW_DestroyYUVTexture(SDL_SW_YUVTexture * swdata) -{ - if (swdata) { - SDL_free(swdata->pixels); - SDL_free(swdata->colortab); - SDL_free(swdata->rgb_2_pix); - SDL_FreeSurface(swdata->stretch); - SDL_FreeSurface(swdata->display); - SDL_free(swdata); - } -} - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/SDL_yuv_sw_c.h b/3rdparty/SDL2/src/render/SDL_yuv_sw_c.h deleted file mode 100644 index 2752096f455..00000000000 --- a/3rdparty/SDL2/src/render/SDL_yuv_sw_c.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../SDL_internal.h" - -#include "SDL_video.h" - -/* This is the software implementation of the YUV texture support */ - -struct SDL_SW_YUVTexture -{ - Uint32 format; - Uint32 target_format; - int w, h; - Uint8 *pixels; - int *colortab; - Uint32 *rgb_2_pix; - void (*Display1X) (int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod); - void (*Display2X) (int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod); - - /* These are just so we don't have to allocate them separately */ - Uint16 pitches[3]; - Uint8 *planes[3]; - - /* This is a temporary surface in case we have to stretch copy */ - SDL_Surface *stretch; - SDL_Surface *display; -}; - -typedef struct SDL_SW_YUVTexture SDL_SW_YUVTexture; - -SDL_SW_YUVTexture *SDL_SW_CreateYUVTexture(Uint32 format, int w, int h); -int SDL_SW_QueryYUVTexturePixels(SDL_SW_YUVTexture * swdata, void **pixels, - int *pitch); -int SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect, - const void *pixels, int pitch); -int SDL_SW_UpdateYUVTexturePlanar(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect, - const Uint8 *Yplane, int Ypitch, - const Uint8 *Uplane, int Upitch, - const Uint8 *Vplane, int Vpitch); -int SDL_SW_LockYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect, - void **pixels, int *pitch); -void SDL_SW_UnlockYUVTexture(SDL_SW_YUVTexture * swdata); -int SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture * swdata, const SDL_Rect * srcrect, - Uint32 target_format, int w, int h, void *pixels, - int pitch); -void SDL_SW_DestroyYUVTexture(SDL_SW_YUVTexture * swdata); - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/direct3d/SDL_render_d3d.c b/3rdparty/SDL2/src/render/direct3d/SDL_render_d3d.c deleted file mode 100644 index 151dbbf04d5..00000000000 --- a/3rdparty/SDL2/src/render/direct3d/SDL_render_d3d.c +++ /dev/null @@ -1,1990 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../../SDL_internal.h" - -#include "SDL_render.h" -#include "SDL_system.h" - -#if SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED - -#include "../../core/windows/SDL_windows.h" - -#include "SDL_hints.h" -#include "SDL_loadso.h" -#include "SDL_syswm.h" -#include "../SDL_sysrender.h" -#include "../SDL_d3dmath.h" -#include "../../video/windows/SDL_windowsvideo.h" - -#if SDL_VIDEO_RENDER_D3D -#define D3D_DEBUG_INFO -#include <d3d9.h> -#endif - - -#ifdef ASSEMBLE_SHADER -#pragma comment(lib, "d3dx9.lib") - -/************************************************************************** - * ID3DXBuffer: - * ------------ - * The buffer object is used by D3DX to return arbitrary size data. - * - * GetBufferPointer - - * Returns a pointer to the beginning of the buffer. - * - * GetBufferSize - - * Returns the size of the buffer, in bytes. - **************************************************************************/ - -typedef interface ID3DXBuffer ID3DXBuffer; -typedef interface ID3DXBuffer *LPD3DXBUFFER; - -/* {8BA5FB08-5195-40e2-AC58-0D989C3A0102} */ -DEFINE_GUID(IID_ID3DXBuffer, -0x8ba5fb08, 0x5195, 0x40e2, 0xac, 0x58, 0xd, 0x98, 0x9c, 0x3a, 0x1, 0x2); - -#undef INTERFACE -#define INTERFACE ID3DXBuffer - -typedef interface ID3DXBuffer { - const struct ID3DXBufferVtbl FAR* lpVtbl; -} ID3DXBuffer; -typedef const struct ID3DXBufferVtbl ID3DXBufferVtbl; -const struct ID3DXBufferVtbl -{ - /* IUnknown */ - STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE; - STDMETHOD_(ULONG, AddRef)(THIS) PURE; - STDMETHOD_(ULONG, Release)(THIS) PURE; - - /* ID3DXBuffer */ - STDMETHOD_(LPVOID, GetBufferPointer)(THIS) PURE; - STDMETHOD_(DWORD, GetBufferSize)(THIS) PURE; -}; - -HRESULT WINAPI - D3DXAssembleShader( - LPCSTR pSrcData, - UINT SrcDataLen, - CONST LPVOID* pDefines, - LPVOID pInclude, - DWORD Flags, - LPD3DXBUFFER* ppShader, - LPD3DXBUFFER* ppErrorMsgs); - -static void PrintShaderData(LPDWORD shader_data, DWORD shader_size) -{ - OutputDebugStringA("const DWORD shader_data[] = {\n\t"); - { - SDL_bool newline = SDL_FALSE; - unsigned i; - for (i = 0; i < shader_size / sizeof(DWORD); ++i) { - char dword[11]; - if (i > 0) { - if ((i%6) == 0) { - newline = SDL_TRUE; - } - if (newline) { - OutputDebugStringA(",\n "); - newline = SDL_FALSE; - } else { - OutputDebugStringA(", "); - } - } - SDL_snprintf(dword, sizeof(dword), "0x%8.8x", shader_data[i]); - OutputDebugStringA(dword); - } - OutputDebugStringA("\n};\n"); - } -} - -#endif /* ASSEMBLE_SHADER */ - - -/* Direct3D renderer implementation */ - -static SDL_Renderer *D3D_CreateRenderer(SDL_Window * window, Uint32 flags); -static void D3D_WindowEvent(SDL_Renderer * renderer, - const SDL_WindowEvent *event); -static int D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); -static int D3D_RecreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); -static int D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, const void *pixels, - int pitch); -static int D3D_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, - const Uint8 *Yplane, int Ypitch, - const Uint8 *Uplane, int Upitch, - const Uint8 *Vplane, int Vpitch); -static int D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, void **pixels, int *pitch); -static void D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); -static int D3D_SetRenderTargetInternal(SDL_Renderer * renderer, SDL_Texture * texture); -static int D3D_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture); -static int D3D_UpdateViewport(SDL_Renderer * renderer); -static int D3D_UpdateClipRect(SDL_Renderer * renderer); -static int D3D_RenderClear(SDL_Renderer * renderer); -static int D3D_RenderDrawPoints(SDL_Renderer * renderer, - const SDL_FPoint * points, int count); -static int D3D_RenderDrawLines(SDL_Renderer * renderer, - const SDL_FPoint * points, int count); -static int D3D_RenderFillRects(SDL_Renderer * renderer, - const SDL_FRect * rects, int count); -static int D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_FRect * dstrect); -static int D3D_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_FRect * dstrect, - const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip); -static int D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, - Uint32 format, void * pixels, int pitch); -static void D3D_RenderPresent(SDL_Renderer * renderer); -static void D3D_DestroyTexture(SDL_Renderer * renderer, - SDL_Texture * texture); -static void D3D_DestroyRenderer(SDL_Renderer * renderer); - - -SDL_RenderDriver D3D_RenderDriver = { - D3D_CreateRenderer, - { - "direct3d", - (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE), - 1, - {SDL_PIXELFORMAT_ARGB8888}, - 0, - 0} -}; - -typedef struct -{ - void* d3dDLL; - IDirect3D9 *d3d; - IDirect3DDevice9 *device; - UINT adapter; - D3DPRESENT_PARAMETERS pparams; - SDL_bool updateSize; - SDL_bool beginScene; - SDL_bool enableSeparateAlphaBlend; - D3DTEXTUREFILTERTYPE scaleMode[8]; - IDirect3DSurface9 *defaultRenderTarget; - IDirect3DSurface9 *currentRenderTarget; - void* d3dxDLL; - LPDIRECT3DPIXELSHADER9 ps_yuv; -} D3D_RenderData; - -typedef struct -{ - SDL_bool dirty; - int w, h; - DWORD usage; - Uint32 format; - IDirect3DTexture9 *texture; - IDirect3DTexture9 *staging; -} D3D_TextureRep; - -typedef struct -{ - D3D_TextureRep texture; - D3DTEXTUREFILTERTYPE scaleMode; - - /* YV12 texture support */ - SDL_bool yuv; - D3D_TextureRep utexture; - D3D_TextureRep vtexture; - Uint8 *pixels; - int pitch; - SDL_Rect locked_rect; -} D3D_TextureData; - -typedef struct -{ - float x, y, z; - DWORD color; - float u, v; -} Vertex; - -static int -D3D_SetError(const char *prefix, HRESULT result) -{ - const char *error; - - switch (result) { - case D3DERR_WRONGTEXTUREFORMAT: - error = "WRONGTEXTUREFORMAT"; - break; - case D3DERR_UNSUPPORTEDCOLOROPERATION: - error = "UNSUPPORTEDCOLOROPERATION"; - break; - case D3DERR_UNSUPPORTEDCOLORARG: - error = "UNSUPPORTEDCOLORARG"; - break; - case D3DERR_UNSUPPORTEDALPHAOPERATION: - error = "UNSUPPORTEDALPHAOPERATION"; - break; - case D3DERR_UNSUPPORTEDALPHAARG: - error = "UNSUPPORTEDALPHAARG"; - break; - case D3DERR_TOOMANYOPERATIONS: - error = "TOOMANYOPERATIONS"; - break; - case D3DERR_CONFLICTINGTEXTUREFILTER: - error = "CONFLICTINGTEXTUREFILTER"; - break; - case D3DERR_UNSUPPORTEDFACTORVALUE: - error = "UNSUPPORTEDFACTORVALUE"; - break; - case D3DERR_CONFLICTINGRENDERSTATE: - error = "CONFLICTINGRENDERSTATE"; - break; - case D3DERR_UNSUPPORTEDTEXTUREFILTER: - error = "UNSUPPORTEDTEXTUREFILTER"; - break; - case D3DERR_CONFLICTINGTEXTUREPALETTE: - error = "CONFLICTINGTEXTUREPALETTE"; - break; - case D3DERR_DRIVERINTERNALERROR: - error = "DRIVERINTERNALERROR"; - break; - case D3DERR_NOTFOUND: - error = "NOTFOUND"; - break; - case D3DERR_MOREDATA: - error = "MOREDATA"; - break; - case D3DERR_DEVICELOST: - error = "DEVICELOST"; - break; - case D3DERR_DEVICENOTRESET: - error = "DEVICENOTRESET"; - break; - case D3DERR_NOTAVAILABLE: - error = "NOTAVAILABLE"; - break; - case D3DERR_OUTOFVIDEOMEMORY: - error = "OUTOFVIDEOMEMORY"; - break; - case D3DERR_INVALIDDEVICE: - error = "INVALIDDEVICE"; - break; - case D3DERR_INVALIDCALL: - error = "INVALIDCALL"; - break; - case D3DERR_DRIVERINVALIDCALL: - error = "DRIVERINVALIDCALL"; - break; - case D3DERR_WASSTILLDRAWING: - error = "WASSTILLDRAWING"; - break; - default: - error = "UNKNOWN"; - break; - } - return SDL_SetError("%s: %s", prefix, error); -} - -static D3DFORMAT -PixelFormatToD3DFMT(Uint32 format) -{ - switch (format) { - case SDL_PIXELFORMAT_RGB565: - return D3DFMT_R5G6B5; - case SDL_PIXELFORMAT_RGB888: - return D3DFMT_X8R8G8B8; - case SDL_PIXELFORMAT_ARGB8888: - return D3DFMT_A8R8G8B8; - case SDL_PIXELFORMAT_YV12: - case SDL_PIXELFORMAT_IYUV: - return D3DFMT_L8; - default: - return D3DFMT_UNKNOWN; - } -} - -static Uint32 -D3DFMTToPixelFormat(D3DFORMAT format) -{ - switch (format) { - case D3DFMT_R5G6B5: - return SDL_PIXELFORMAT_RGB565; - case D3DFMT_X8R8G8B8: - return SDL_PIXELFORMAT_RGB888; - case D3DFMT_A8R8G8B8: - return SDL_PIXELFORMAT_ARGB8888; - default: - return SDL_PIXELFORMAT_UNKNOWN; - } -} - -static void -D3D_InitRenderState(D3D_RenderData *data) -{ - D3DMATRIX matrix; - - IDirect3DDevice9 *device = data->device; - - IDirect3DDevice9_SetVertexShader(device, NULL); - IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1); - IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_FALSE); - IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_NONE); - IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE); - - /* Enable color modulation by diffuse color */ - IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, - D3DTOP_MODULATE); - IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, - D3DTA_TEXTURE); - IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG2, - D3DTA_DIFFUSE); - - /* Enable alpha modulation by diffuse alpha */ - IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAOP, - D3DTOP_MODULATE); - IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAARG1, - D3DTA_TEXTURE); - IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAARG2, - D3DTA_DIFFUSE); - - /* Enable separate alpha blend function, if possible */ - if (data->enableSeparateAlphaBlend) { - IDirect3DDevice9_SetRenderState(device, D3DRS_SEPARATEALPHABLENDENABLE, TRUE); - } - - /* Disable second texture stage, since we're done */ - IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP, - D3DTOP_DISABLE); - IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_ALPHAOP, - D3DTOP_DISABLE); - - /* Set an identity world and view matrix */ - matrix.m[0][0] = 1.0f; - matrix.m[0][1] = 0.0f; - matrix.m[0][2] = 0.0f; - matrix.m[0][3] = 0.0f; - matrix.m[1][0] = 0.0f; - matrix.m[1][1] = 1.0f; - matrix.m[1][2] = 0.0f; - matrix.m[1][3] = 0.0f; - matrix.m[2][0] = 0.0f; - matrix.m[2][1] = 0.0f; - matrix.m[2][2] = 1.0f; - matrix.m[2][3] = 0.0f; - matrix.m[3][0] = 0.0f; - matrix.m[3][1] = 0.0f; - matrix.m[3][2] = 0.0f; - matrix.m[3][3] = 1.0f; - IDirect3DDevice9_SetTransform(device, D3DTS_WORLD, &matrix); - IDirect3DDevice9_SetTransform(device, D3DTS_VIEW, &matrix); - - /* Reset our current scale mode */ - SDL_memset(data->scaleMode, 0xFF, sizeof(data->scaleMode)); - - /* Start the render with beginScene */ - data->beginScene = SDL_TRUE; -} - -static int -D3D_Reset(SDL_Renderer * renderer) -{ - D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; - HRESULT result; - SDL_Texture *texture; - - /* Release the default render target before reset */ - if (data->defaultRenderTarget) { - IDirect3DSurface9_Release(data->defaultRenderTarget); - data->defaultRenderTarget = NULL; - } - if (data->currentRenderTarget != NULL) { - IDirect3DSurface9_Release(data->currentRenderTarget); - data->currentRenderTarget = NULL; - } - - /* Release application render targets */ - for (texture = renderer->textures; texture; texture = texture->next) { - if (texture->access == SDL_TEXTUREACCESS_TARGET) { - D3D_DestroyTexture(renderer, texture); - } else { - D3D_RecreateTexture(renderer, texture); - } - } - - result = IDirect3DDevice9_Reset(data->device, &data->pparams); - if (FAILED(result)) { - if (result == D3DERR_DEVICELOST) { - /* Don't worry about it, we'll reset later... */ - return 0; - } else { - return D3D_SetError("Reset()", result); - } - } - - /* Allocate application render targets */ - for (texture = renderer->textures; texture; texture = texture->next) { - if (texture->access == SDL_TEXTUREACCESS_TARGET) { - D3D_CreateTexture(renderer, texture); - } - } - - IDirect3DDevice9_GetRenderTarget(data->device, 0, &data->defaultRenderTarget); - D3D_InitRenderState(data); - D3D_SetRenderTargetInternal(renderer, renderer->target); - D3D_UpdateViewport(renderer); - - /* Let the application know that render targets were reset */ - { - SDL_Event event; - event.type = SDL_RENDER_TARGETS_RESET; - SDL_PushEvent(&event); - } - - return 0; -} - -static int -D3D_ActivateRenderer(SDL_Renderer * renderer) -{ - D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; - HRESULT result; - - if (data->updateSize) { - SDL_Window *window = renderer->window; - int w, h; - Uint32 window_flags = SDL_GetWindowFlags(window); - - SDL_GetWindowSize(window, &w, &h); - data->pparams.BackBufferWidth = w; - data->pparams.BackBufferHeight = h; - if (window_flags & SDL_WINDOW_FULLSCREEN && (window_flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP) { - SDL_DisplayMode fullscreen_mode; - SDL_GetWindowDisplayMode(window, &fullscreen_mode); - data->pparams.Windowed = FALSE; - data->pparams.BackBufferFormat = PixelFormatToD3DFMT(fullscreen_mode.format); - data->pparams.FullScreen_RefreshRateInHz = fullscreen_mode.refresh_rate; - } else { - data->pparams.Windowed = TRUE; - data->pparams.BackBufferFormat = D3DFMT_UNKNOWN; - data->pparams.FullScreen_RefreshRateInHz = 0; - } - if (D3D_Reset(renderer) < 0) { - return -1; - } - - data->updateSize = SDL_FALSE; - } - if (data->beginScene) { - result = IDirect3DDevice9_BeginScene(data->device); - if (result == D3DERR_DEVICELOST) { - if (D3D_Reset(renderer) < 0) { - return -1; - } - result = IDirect3DDevice9_BeginScene(data->device); - } - if (FAILED(result)) { - return D3D_SetError("BeginScene()", result); - } - data->beginScene = SDL_FALSE; - } - return 0; -} - -SDL_Renderer * -D3D_CreateRenderer(SDL_Window * window, Uint32 flags) -{ - SDL_Renderer *renderer; - D3D_RenderData *data; - SDL_SysWMinfo windowinfo; - HRESULT result; - D3DPRESENT_PARAMETERS pparams; - IDirect3DSwapChain9 *chain; - D3DCAPS9 caps; - DWORD device_flags; - Uint32 window_flags; - int w, h; - SDL_DisplayMode fullscreen_mode; - int displayIndex; - - renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); - if (!renderer) { - SDL_OutOfMemory(); - return NULL; - } - - data = (D3D_RenderData *) SDL_calloc(1, sizeof(*data)); - if (!data) { - SDL_free(renderer); - SDL_OutOfMemory(); - return NULL; - } - - if (!D3D_LoadDLL(&data->d3dDLL, &data->d3d)) { - SDL_free(renderer); - SDL_free(data); - SDL_SetError("Unable to create Direct3D interface"); - return NULL; - } - - renderer->WindowEvent = D3D_WindowEvent; - renderer->CreateTexture = D3D_CreateTexture; - renderer->UpdateTexture = D3D_UpdateTexture; - renderer->UpdateTextureYUV = D3D_UpdateTextureYUV; - renderer->LockTexture = D3D_LockTexture; - renderer->UnlockTexture = D3D_UnlockTexture; - renderer->SetRenderTarget = D3D_SetRenderTarget; - renderer->UpdateViewport = D3D_UpdateViewport; - renderer->UpdateClipRect = D3D_UpdateClipRect; - renderer->RenderClear = D3D_RenderClear; - renderer->RenderDrawPoints = D3D_RenderDrawPoints; - renderer->RenderDrawLines = D3D_RenderDrawLines; - renderer->RenderFillRects = D3D_RenderFillRects; - renderer->RenderCopy = D3D_RenderCopy; - renderer->RenderCopyEx = D3D_RenderCopyEx; - renderer->RenderReadPixels = D3D_RenderReadPixels; - renderer->RenderPresent = D3D_RenderPresent; - renderer->DestroyTexture = D3D_DestroyTexture; - renderer->DestroyRenderer = D3D_DestroyRenderer; - renderer->info = D3D_RenderDriver.info; - renderer->info.flags = (SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE); - renderer->driverdata = data; - - SDL_VERSION(&windowinfo.version); - SDL_GetWindowWMInfo(window, &windowinfo); - - window_flags = SDL_GetWindowFlags(window); - SDL_GetWindowSize(window, &w, &h); - SDL_GetWindowDisplayMode(window, &fullscreen_mode); - - SDL_zero(pparams); - pparams.hDeviceWindow = windowinfo.info.win.window; - pparams.BackBufferWidth = w; - pparams.BackBufferHeight = h; - pparams.BackBufferCount = 1; - pparams.SwapEffect = D3DSWAPEFFECT_DISCARD; - - if (window_flags & SDL_WINDOW_FULLSCREEN && (window_flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP) { - pparams.Windowed = FALSE; - pparams.BackBufferFormat = PixelFormatToD3DFMT(fullscreen_mode.format); - pparams.FullScreen_RefreshRateInHz = fullscreen_mode.refresh_rate; - } else { - pparams.Windowed = TRUE; - pparams.BackBufferFormat = D3DFMT_UNKNOWN; - pparams.FullScreen_RefreshRateInHz = 0; - } - if (flags & SDL_RENDERER_PRESENTVSYNC) { - pparams.PresentationInterval = D3DPRESENT_INTERVAL_ONE; - } else { - pparams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; - } - - /* Get the adapter for the display that the window is on */ - displayIndex = SDL_GetWindowDisplayIndex(window); - data->adapter = SDL_Direct3D9GetAdapterIndex(displayIndex); - - IDirect3D9_GetDeviceCaps(data->d3d, data->adapter, D3DDEVTYPE_HAL, &caps); - - device_flags = D3DCREATE_FPU_PRESERVE; - if (caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) { - device_flags |= D3DCREATE_HARDWARE_VERTEXPROCESSING; - } else { - device_flags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING; - } - - if (SDL_GetHintBoolean(SDL_HINT_RENDER_DIRECT3D_THREADSAFE, SDL_FALSE)) { - device_flags |= D3DCREATE_MULTITHREADED; - } - - result = IDirect3D9_CreateDevice(data->d3d, data->adapter, - D3DDEVTYPE_HAL, - pparams.hDeviceWindow, - device_flags, - &pparams, &data->device); - if (FAILED(result)) { - D3D_DestroyRenderer(renderer); - D3D_SetError("CreateDevice()", result); - return NULL; - } - - /* Get presentation parameters to fill info */ - result = IDirect3DDevice9_GetSwapChain(data->device, 0, &chain); - if (FAILED(result)) { - D3D_DestroyRenderer(renderer); - D3D_SetError("GetSwapChain()", result); - return NULL; - } - result = IDirect3DSwapChain9_GetPresentParameters(chain, &pparams); - if (FAILED(result)) { - IDirect3DSwapChain9_Release(chain); - D3D_DestroyRenderer(renderer); - D3D_SetError("GetPresentParameters()", result); - return NULL; - } - IDirect3DSwapChain9_Release(chain); - if (pparams.PresentationInterval == D3DPRESENT_INTERVAL_ONE) { - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; - } - data->pparams = pparams; - - IDirect3DDevice9_GetDeviceCaps(data->device, &caps); - renderer->info.max_texture_width = caps.MaxTextureWidth; - renderer->info.max_texture_height = caps.MaxTextureHeight; - if (caps.NumSimultaneousRTs >= 2) { - renderer->info.flags |= SDL_RENDERER_TARGETTEXTURE; - } - - if (caps.PrimitiveMiscCaps & D3DPMISCCAPS_SEPARATEALPHABLEND) { - data->enableSeparateAlphaBlend = SDL_TRUE; - } - - /* Store the default render target */ - IDirect3DDevice9_GetRenderTarget(data->device, 0, &data->defaultRenderTarget); - data->currentRenderTarget = NULL; - - /* Set up parameters for rendering */ - D3D_InitRenderState(data); - - if (caps.MaxSimultaneousTextures >= 3) - { -#ifdef ASSEMBLE_SHADER - /* This shader was created by running the following HLSL through the fxc compiler - and then tuning the generated assembly. - - fxc /T fx_4_0 /O3 /Gfa /Fc yuv.fxc yuv.fx - - --- yuv.fx --- - Texture2D g_txY; - Texture2D g_txU; - Texture2D g_txV; - - SamplerState samLinear - { - Filter = ANISOTROPIC; - AddressU = Clamp; - AddressV = Clamp; - MaxAnisotropy = 1; - }; - - struct VS_OUTPUT - { - float2 TextureUV : TEXCOORD0; - }; - - struct PS_OUTPUT - { - float4 RGBAColor : SV_Target; - }; - - PS_OUTPUT YUV420( VS_OUTPUT In ) - { - const float3 offset = {-0.0627451017, -0.501960814, -0.501960814}; - const float3 Rcoeff = {1.164, 0.000, 1.596}; - const float3 Gcoeff = {1.164, -0.391, -0.813}; - const float3 Bcoeff = {1.164, 2.018, 0.000}; - - PS_OUTPUT Output; - float2 TextureUV = In.TextureUV; - - float3 yuv; - yuv.x = g_txY.Sample( samLinear, TextureUV ).r; - yuv.y = g_txU.Sample( samLinear, TextureUV ).r; - yuv.z = g_txV.Sample( samLinear, TextureUV ).r; - - yuv += offset; - Output.RGBAColor.r = dot(yuv, Rcoeff); - Output.RGBAColor.g = dot(yuv, Gcoeff); - Output.RGBAColor.b = dot(yuv, Bcoeff); - Output.RGBAColor.a = 1.0f; - - return Output; - } - - technique10 RenderYUV420 - { - pass P0 - { - SetPixelShader( CompileShader( ps_4_0_level_9_0, YUV420() ) ); - } - } - */ - const char *shader_text = - "ps_2_0\n" - "def c0, -0.0627451017, -0.501960814, -0.501960814, 1\n" - "def c1, 1.16400003, 0, 1.59599996, 0\n" - "def c2, 1.16400003, -0.391000003, -0.813000023, 0\n" - "def c3, 1.16400003, 2.01799989, 0, 0\n" - "dcl t0.xy\n" - "dcl v0.xyzw\n" - "dcl_2d s0\n" - "dcl_2d s1\n" - "dcl_2d s2\n" - "texld r0, t0, s0\n" - "texld r1, t0, s1\n" - "texld r2, t0, s2\n" - "mov r0.y, r1.x\n" - "mov r0.z, r2.x\n" - "add r0.xyz, r0, c0\n" - "dp3 r1.x, r0, c1\n" - "dp3 r1.y, r0, c2\n" - "dp2add r1.z, r0, c3, c3.z\n" /* Logically this is "dp3 r1.z, r0, c3" but the optimizer did its magic */ - "mov r1.w, c0.w\n" - "mul r0, r1, v0\n" /* Not in the HLSL, multiply by vertex color */ - "mov oC0, r0\n" - ; - LPD3DXBUFFER pCode; - LPD3DXBUFFER pErrorMsgs; - LPDWORD shader_data = NULL; - DWORD shader_size = 0; - result = D3DXAssembleShader(shader_text, SDL_strlen(shader_text), NULL, NULL, 0, &pCode, &pErrorMsgs); - if (!FAILED(result)) { - shader_data = (DWORD*)pCode->lpVtbl->GetBufferPointer(pCode); - shader_size = pCode->lpVtbl->GetBufferSize(pCode); - PrintShaderData(shader_data, shader_size); - } else { - const char *error = (const char *)pErrorMsgs->lpVtbl->GetBufferPointer(pErrorMsgs); - SDL_SetError("Couldn't assemble shader: %s", error); - } -#else - const DWORD shader_data[] = { - 0xffff0200, 0x05000051, 0xa00f0000, 0xbd808081, 0xbf008081, 0xbf008081, - 0x3f800000, 0x05000051, 0xa00f0001, 0x3f94fdf4, 0x00000000, 0x3fcc49ba, - 0x00000000, 0x05000051, 0xa00f0002, 0x3f94fdf4, 0xbec83127, 0xbf5020c5, - 0x00000000, 0x05000051, 0xa00f0003, 0x3f94fdf4, 0x400126e9, 0x00000000, - 0x00000000, 0x0200001f, 0x80000000, 0xb0030000, 0x0200001f, 0x80000000, - 0x900f0000, 0x0200001f, 0x90000000, 0xa00f0800, 0x0200001f, 0x90000000, - 0xa00f0801, 0x0200001f, 0x90000000, 0xa00f0802, 0x03000042, 0x800f0000, - 0xb0e40000, 0xa0e40800, 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40801, - 0x03000042, 0x800f0002, 0xb0e40000, 0xa0e40802, 0x02000001, 0x80020000, - 0x80000001, 0x02000001, 0x80040000, 0x80000002, 0x03000002, 0x80070000, - 0x80e40000, 0xa0e40000, 0x03000008, 0x80010001, 0x80e40000, 0xa0e40001, - 0x03000008, 0x80020001, 0x80e40000, 0xa0e40002, 0x0400005a, 0x80040001, - 0x80e40000, 0xa0e40003, 0xa0aa0003, 0x02000001, 0x80080001, 0xa0ff0000, - 0x03000005, 0x800f0000, 0x80e40001, 0x90e40000, 0x02000001, 0x800f0800, - 0x80e40000, 0x0000ffff - }; -#endif - if (shader_data != NULL) { - result = IDirect3DDevice9_CreatePixelShader(data->device, shader_data, &data->ps_yuv); - if (!FAILED(result)) { - renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_YV12; - renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_IYUV; - } else { - D3D_SetError("CreatePixelShader()", result); - } - } - } - - return renderer; -} - -static void -D3D_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event) -{ - D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; - - if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) { - data->updateSize = SDL_TRUE; - } -} - -static D3DTEXTUREFILTERTYPE -GetScaleQuality(void) -{ - const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY); - - if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) { - return D3DTEXF_POINT; - } else /* if (*hint == '1' || SDL_strcasecmp(hint, "linear") == 0) */ { - return D3DTEXF_LINEAR; - } -} - -static int -D3D_CreateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, DWORD usage, Uint32 format, int w, int h) -{ - HRESULT result; - - texture->dirty = SDL_FALSE; - texture->w = w; - texture->h = h; - texture->usage = usage; - texture->format = format; - - result = IDirect3DDevice9_CreateTexture(device, w, h, 1, usage, - PixelFormatToD3DFMT(format), - D3DPOOL_DEFAULT, &texture->texture, NULL); - if (FAILED(result)) { - return D3D_SetError("CreateTexture(D3DPOOL_DEFAULT)", result); - } - return 0; -} - - -static int -D3D_CreateStagingTexture(IDirect3DDevice9 *device, D3D_TextureRep *texture) -{ - HRESULT result; - - if (texture->staging == NULL) { - result = IDirect3DDevice9_CreateTexture(device, texture->w, texture->h, 1, 0, - PixelFormatToD3DFMT(texture->format), - D3DPOOL_SYSTEMMEM, &texture->staging, NULL); - if (FAILED(result)) { - return D3D_SetError("CreateTexture(D3DPOOL_SYSTEMMEM)", result); - } - } - return 0; -} - -static int -D3D_BindTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, DWORD sampler) -{ - HRESULT result; - - if (texture->dirty && texture->staging) { - if (!texture->texture) { - result = IDirect3DDevice9_CreateTexture(device, texture->w, texture->h, 1, texture->usage, - PixelFormatToD3DFMT(texture->format), D3DPOOL_DEFAULT, &texture->texture, NULL); - if (FAILED(result)) { - return D3D_SetError("CreateTexture(D3DPOOL_DEFAULT)", result); - } - } - - result = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)texture->staging, (IDirect3DBaseTexture9 *)texture->texture); - if (FAILED(result)) { - return D3D_SetError("UpdateTexture()", result); - } - texture->dirty = SDL_FALSE; - } - result = IDirect3DDevice9_SetTexture(device, sampler, (IDirect3DBaseTexture9 *)texture->texture); - if (FAILED(result)) { - return D3D_SetError("SetTexture()", result); - } - return 0; -} - -static int -D3D_RecreateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, Uint32 format, int w, int h) -{ - if (texture->texture) { - IDirect3DTexture9_Release(texture->texture); - texture->texture = NULL; - } - if (texture->staging) { - IDirect3DTexture9_AddDirtyRect(texture->staging, NULL); - texture->dirty = SDL_TRUE; - } - return 0; -} - -static int -D3D_UpdateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, Uint32 format, int x, int y, int w, int h, const void *pixels, int pitch) -{ - RECT d3drect; - D3DLOCKED_RECT locked; - const Uint8 *src; - Uint8 *dst; - int row, length; - HRESULT result; - - if (D3D_CreateStagingTexture(device, texture) < 0) { - return -1; - } - - d3drect.left = x; - d3drect.right = x + w; - d3drect.top = y; - d3drect.bottom = y + h; - - result = IDirect3DTexture9_LockRect(texture->staging, 0, &locked, &d3drect, 0); - if (FAILED(result)) { - return D3D_SetError("LockRect()", result); - } - - src = (const Uint8 *)pixels; - dst = locked.pBits; - length = w * SDL_BYTESPERPIXEL(format); - if (length == pitch && length == locked.Pitch) { - SDL_memcpy(dst, src, length*h); - } else { - if (length > pitch) { - length = pitch; - } - if (length > locked.Pitch) { - length = locked.Pitch; - } - for (row = 0; row < h; ++row) { - SDL_memcpy(dst, src, length); - src += pitch; - dst += locked.Pitch; - } - } - result = IDirect3DTexture9_UnlockRect(texture->staging, 0); - if (FAILED(result)) { - return D3D_SetError("UnlockRect()", result); - } - texture->dirty = SDL_TRUE; - - return 0; -} - -static void -D3D_DestroyTextureRep(D3D_TextureRep *texture) -{ - if (texture->texture) { - IDirect3DTexture9_Release(texture->texture); - texture->texture = NULL; - } - if (texture->staging) { - IDirect3DTexture9_Release(texture->staging); - texture->staging = NULL; - } -} - -static int -D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; - D3D_TextureData *texturedata; - DWORD usage; - - texturedata = (D3D_TextureData *) SDL_calloc(1, sizeof(*texturedata)); - if (!texturedata) { - return SDL_OutOfMemory(); - } - texturedata->scaleMode = GetScaleQuality(); - - texture->driverdata = texturedata; - - if (texture->access == SDL_TEXTUREACCESS_TARGET) { - usage = D3DUSAGE_RENDERTARGET; - } else { - usage = 0; - } - - if (D3D_CreateTextureRep(data->device, &texturedata->texture, usage, texture->format, texture->w, texture->h) < 0) { - return -1; - } - - if (texture->format == SDL_PIXELFORMAT_YV12 || - texture->format == SDL_PIXELFORMAT_IYUV) { - texturedata->yuv = SDL_TRUE; - - if (D3D_CreateTextureRep(data->device, &texturedata->utexture, usage, texture->format, texture->w / 2, texture->h / 2) < 0) { - return -1; - } - - if (D3D_CreateTextureRep(data->device, &texturedata->vtexture, usage, texture->format, texture->w / 2, texture->h / 2) < 0) { - return -1; - } - } - return 0; -} - -static int -D3D_RecreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata; - D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata; - - if (!texturedata) { - return 0; - } - - if (D3D_RecreateTextureRep(data->device, &texturedata->texture, texture->format, texture->w, texture->h) < 0) { - return -1; - } - - if (texturedata->yuv) { - if (D3D_RecreateTextureRep(data->device, &texturedata->utexture, texture->format, texture->w / 2, texture->h / 2) < 0) { - return -1; - } - - if (D3D_RecreateTextureRep(data->device, &texturedata->vtexture, texture->format, texture->w / 2, texture->h / 2) < 0) { - return -1; - } - } - return 0; -} - -static int -D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, const void *pixels, int pitch) -{ - D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata; - D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata; - - if (!texturedata) { - SDL_SetError("Texture is not currently available"); - return -1; - } - - if (D3D_UpdateTextureRep(data->device, &texturedata->texture, texture->format, rect->x, rect->y, rect->w, rect->h, pixels, pitch) < 0) { - return -1; - } - - if (texturedata->yuv) { - /* Skip to the correct offset into the next texture */ - pixels = (const void*)((const Uint8*)pixels + rect->h * pitch); - - if (D3D_UpdateTextureRep(data->device, texture->format == SDL_PIXELFORMAT_YV12 ? &texturedata->vtexture : &texturedata->utexture, texture->format, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, pixels, pitch / 2) < 0) { - return -1; - } - - /* Skip to the correct offset into the next texture */ - pixels = (const void*)((const Uint8*)pixels + (rect->h * pitch)/4); - if (D3D_UpdateTextureRep(data->device, texture->format == SDL_PIXELFORMAT_YV12 ? &texturedata->utexture : &texturedata->vtexture, texture->format, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, pixels, pitch / 2) < 0) { - return -1; - } - } - return 0; -} - -static int -D3D_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, - const Uint8 *Yplane, int Ypitch, - const Uint8 *Uplane, int Upitch, - const Uint8 *Vplane, int Vpitch) -{ - D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata; - D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata; - - if (!texturedata) { - SDL_SetError("Texture is not currently available"); - return -1; - } - - if (D3D_UpdateTextureRep(data->device, &texturedata->texture, texture->format, rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch) < 0) { - return -1; - } - if (D3D_UpdateTextureRep(data->device, &texturedata->utexture, texture->format, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Uplane, Upitch) < 0) { - return -1; - } - if (D3D_UpdateTextureRep(data->device, &texturedata->vtexture, texture->format, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Vplane, Vpitch) < 0) { - return -1; - } - return 0; -} - -static int -D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, void **pixels, int *pitch) -{ - D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata; - D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata; - IDirect3DDevice9 *device = data->device; - - if (!texturedata) { - SDL_SetError("Texture is not currently available"); - return -1; - } - - texturedata->locked_rect = *rect; - - if (texturedata->yuv) { - /* It's more efficient to upload directly... */ - if (!texturedata->pixels) { - texturedata->pitch = texture->w; - texturedata->pixels = (Uint8 *)SDL_malloc((texture->h * texturedata->pitch * 3) / 2); - if (!texturedata->pixels) { - return SDL_OutOfMemory(); - } - } - *pixels = - (void *) ((Uint8 *) texturedata->pixels + rect->y * texturedata->pitch + - rect->x * SDL_BYTESPERPIXEL(texture->format)); - *pitch = texturedata->pitch; - } else { - RECT d3drect; - D3DLOCKED_RECT locked; - HRESULT result; - - if (D3D_CreateStagingTexture(device, &texturedata->texture) < 0) { - return -1; - } - - d3drect.left = rect->x; - d3drect.right = rect->x + rect->w; - d3drect.top = rect->y; - d3drect.bottom = rect->y + rect->h; - - result = IDirect3DTexture9_LockRect(texturedata->texture.staging, 0, &locked, &d3drect, 0); - if (FAILED(result)) { - return D3D_SetError("LockRect()", result); - } - *pixels = locked.pBits; - *pitch = locked.Pitch; - } - return 0; -} - -static void -D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - /*D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;*/ - D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata; - - if (!texturedata) { - return; - } - - if (texturedata->yuv) { - const SDL_Rect *rect = &texturedata->locked_rect; - void *pixels = - (void *) ((Uint8 *) texturedata->pixels + rect->y * texturedata->pitch + - rect->x * SDL_BYTESPERPIXEL(texture->format)); - D3D_UpdateTexture(renderer, texture, rect, pixels, texturedata->pitch); - } else { - IDirect3DTexture9_UnlockRect(texturedata->texture.staging, 0); - texturedata->texture.dirty = SDL_TRUE; - } -} - -static int -D3D_SetRenderTargetInternal(SDL_Renderer * renderer, SDL_Texture * texture) -{ - D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; - D3D_TextureData *texturedata; - D3D_TextureRep *texturerep; - HRESULT result; - IDirect3DDevice9 *device = data->device; - - /* Release the previous render target if it wasn't the default one */ - if (data->currentRenderTarget != NULL) { - IDirect3DSurface9_Release(data->currentRenderTarget); - data->currentRenderTarget = NULL; - } - - if (texture == NULL) { - IDirect3DDevice9_SetRenderTarget(data->device, 0, data->defaultRenderTarget); - return 0; - } - - texturedata = (D3D_TextureData *)texture->driverdata; - if (!texturedata) { - SDL_SetError("Texture is not currently available"); - return -1; - } - - /* Make sure the render target is updated if it was locked and written to */ - texturerep = &texturedata->texture; - if (texturerep->dirty && texturerep->staging) { - if (!texturerep->texture) { - result = IDirect3DDevice9_CreateTexture(device, texturerep->w, texturerep->h, 1, texturerep->usage, - PixelFormatToD3DFMT(texturerep->format), D3DPOOL_DEFAULT, &texturerep->texture, NULL); - if (FAILED(result)) { - return D3D_SetError("CreateTexture(D3DPOOL_DEFAULT)", result); - } - } - - result = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)texturerep->staging, (IDirect3DBaseTexture9 *)texturerep->texture); - if (FAILED(result)) { - return D3D_SetError("UpdateTexture()", result); - } - texturerep->dirty = SDL_FALSE; - } - - result = IDirect3DTexture9_GetSurfaceLevel(texturedata->texture.texture, 0, &data->currentRenderTarget); - if(FAILED(result)) { - return D3D_SetError("GetSurfaceLevel()", result); - } - result = IDirect3DDevice9_SetRenderTarget(data->device, 0, data->currentRenderTarget); - if(FAILED(result)) { - return D3D_SetError("SetRenderTarget()", result); - } - - return 0; -} - -static int -D3D_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture) -{ - D3D_ActivateRenderer(renderer); - - return D3D_SetRenderTargetInternal(renderer, texture); -} - -static int -D3D_UpdateViewport(SDL_Renderer * renderer) -{ - D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; - D3DVIEWPORT9 viewport; - D3DMATRIX matrix; - - /* Set the viewport */ - viewport.X = renderer->viewport.x; - viewport.Y = renderer->viewport.y; - viewport.Width = renderer->viewport.w; - viewport.Height = renderer->viewport.h; - viewport.MinZ = 0.0f; - viewport.MaxZ = 1.0f; - IDirect3DDevice9_SetViewport(data->device, &viewport); - - /* Set an orthographic projection matrix */ - if (renderer->viewport.w && renderer->viewport.h) { - matrix.m[0][0] = 2.0f / renderer->viewport.w; - matrix.m[0][1] = 0.0f; - matrix.m[0][2] = 0.0f; - matrix.m[0][3] = 0.0f; - matrix.m[1][0] = 0.0f; - matrix.m[1][1] = -2.0f / renderer->viewport.h; - matrix.m[1][2] = 0.0f; - matrix.m[1][3] = 0.0f; - matrix.m[2][0] = 0.0f; - matrix.m[2][1] = 0.0f; - matrix.m[2][2] = 1.0f; - matrix.m[2][3] = 0.0f; - matrix.m[3][0] = -1.0f; - matrix.m[3][1] = 1.0f; - matrix.m[3][2] = 0.0f; - matrix.m[3][3] = 1.0f; - IDirect3DDevice9_SetTransform(data->device, D3DTS_PROJECTION, &matrix); - } - - return 0; -} - -static int -D3D_UpdateClipRect(SDL_Renderer * renderer) -{ - D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; - - if (renderer->clipping_enabled) { - const SDL_Rect *rect = &renderer->clip_rect; - RECT r; - HRESULT result; - - IDirect3DDevice9_SetRenderState(data->device, D3DRS_SCISSORTESTENABLE, TRUE); - r.left = renderer->viewport.x + rect->x; - r.top = renderer->viewport.y + rect->y; - r.right = renderer->viewport.x + rect->x + rect->w; - r.bottom = renderer->viewport.y + rect->y + rect->h; - - result = IDirect3DDevice9_SetScissorRect(data->device, &r); - if (result != D3D_OK) { - D3D_SetError("SetScissor()", result); - return -1; - } - } else { - IDirect3DDevice9_SetRenderState(data->device, D3DRS_SCISSORTESTENABLE, FALSE); - } - return 0; -} - -static int -D3D_RenderClear(SDL_Renderer * renderer) -{ - D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; - DWORD color; - HRESULT result; - int BackBufferWidth, BackBufferHeight; - - if (D3D_ActivateRenderer(renderer) < 0) { - return -1; - } - - color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b); - - if (renderer->target) { - BackBufferWidth = renderer->target->w; - BackBufferHeight = renderer->target->h; - } else { - BackBufferWidth = data->pparams.BackBufferWidth; - BackBufferHeight = data->pparams.BackBufferHeight; - } - - if (renderer->clipping_enabled) { - IDirect3DDevice9_SetRenderState(data->device, D3DRS_SCISSORTESTENABLE, FALSE); - } - - /* Don't reset the viewport if we don't have to! */ - if (!renderer->viewport.x && !renderer->viewport.y && - renderer->viewport.w == BackBufferWidth && - renderer->viewport.h == BackBufferHeight) { - result = IDirect3DDevice9_Clear(data->device, 0, NULL, D3DCLEAR_TARGET, color, 0.0f, 0); - } else { - D3DVIEWPORT9 viewport; - - /* Clear is defined to clear the entire render target */ - viewport.X = 0; - viewport.Y = 0; - viewport.Width = BackBufferWidth; - viewport.Height = BackBufferHeight; - viewport.MinZ = 0.0f; - viewport.MaxZ = 1.0f; - IDirect3DDevice9_SetViewport(data->device, &viewport); - - result = IDirect3DDevice9_Clear(data->device, 0, NULL, D3DCLEAR_TARGET, color, 0.0f, 0); - - /* Reset the viewport */ - viewport.X = renderer->viewport.x; - viewport.Y = renderer->viewport.y; - viewport.Width = renderer->viewport.w; - viewport.Height = renderer->viewport.h; - viewport.MinZ = 0.0f; - viewport.MaxZ = 1.0f; - IDirect3DDevice9_SetViewport(data->device, &viewport); - } - - if (renderer->clipping_enabled) { - IDirect3DDevice9_SetRenderState(data->device, D3DRS_SCISSORTESTENABLE, TRUE); - } - - if (FAILED(result)) { - return D3D_SetError("Clear()", result); - } - return 0; -} - -static void -D3D_SetBlendMode(D3D_RenderData * data, int blendMode) -{ - switch (blendMode) { - case SDL_BLENDMODE_NONE: - IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE, - FALSE); - break; - case SDL_BLENDMODE_BLEND: - IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE, - TRUE); - IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND, - D3DBLEND_SRCALPHA); - IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND, - D3DBLEND_INVSRCALPHA); - if (data->enableSeparateAlphaBlend) { - IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLENDALPHA, - D3DBLEND_ONE); - IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLENDALPHA, - D3DBLEND_INVSRCALPHA); - } - break; - case SDL_BLENDMODE_ADD: - IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE, - TRUE); - IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND, - D3DBLEND_SRCALPHA); - IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND, - D3DBLEND_ONE); - if (data->enableSeparateAlphaBlend) { - IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLENDALPHA, - D3DBLEND_ZERO); - IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLENDALPHA, - D3DBLEND_ONE); - } - break; - case SDL_BLENDMODE_MOD: - IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE, - TRUE); - IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND, - D3DBLEND_ZERO); - IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND, - D3DBLEND_SRCCOLOR); - if (data->enableSeparateAlphaBlend) { - IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLENDALPHA, - D3DBLEND_ZERO); - IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLENDALPHA, - D3DBLEND_ONE); - } - break; - } -} - -static int -D3D_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points, - int count) -{ - D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; - DWORD color; - Vertex *vertices; - int i; - HRESULT result; - - if (D3D_ActivateRenderer(renderer) < 0) { - return -1; - } - - D3D_SetBlendMode(data, renderer->blendMode); - - result = - IDirect3DDevice9_SetTexture(data->device, 0, - (IDirect3DBaseTexture9 *) 0); - if (FAILED(result)) { - return D3D_SetError("SetTexture()", result); - } - - color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b); - - vertices = SDL_stack_alloc(Vertex, count); - for (i = 0; i < count; ++i) { - vertices[i].x = points[i].x; - vertices[i].y = points[i].y; - vertices[i].z = 0.0f; - vertices[i].color = color; - vertices[i].u = 0.0f; - vertices[i].v = 0.0f; - } - result = - IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_POINTLIST, count, - vertices, sizeof(*vertices)); - SDL_stack_free(vertices); - if (FAILED(result)) { - return D3D_SetError("DrawPrimitiveUP()", result); - } - return 0; -} - -static int -D3D_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points, - int count) -{ - D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; - DWORD color; - Vertex *vertices; - int i; - HRESULT result; - - if (D3D_ActivateRenderer(renderer) < 0) { - return -1; - } - - D3D_SetBlendMode(data, renderer->blendMode); - - result = - IDirect3DDevice9_SetTexture(data->device, 0, - (IDirect3DBaseTexture9 *) 0); - if (FAILED(result)) { - return D3D_SetError("SetTexture()", result); - } - - color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b); - - vertices = SDL_stack_alloc(Vertex, count); - for (i = 0; i < count; ++i) { - vertices[i].x = points[i].x; - vertices[i].y = points[i].y; - vertices[i].z = 0.0f; - vertices[i].color = color; - vertices[i].u = 0.0f; - vertices[i].v = 0.0f; - } - result = - IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_LINESTRIP, count-1, - vertices, sizeof(*vertices)); - - /* DirectX 9 has the same line rasterization semantics as GDI, - so we need to close the endpoint of the line */ - if (count == 2 || - points[0].x != points[count-1].x || points[0].y != points[count-1].y) { - vertices[0].x = points[count-1].x; - vertices[0].y = points[count-1].y; - result = IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_POINTLIST, 1, vertices, sizeof(*vertices)); - } - - SDL_stack_free(vertices); - if (FAILED(result)) { - return D3D_SetError("DrawPrimitiveUP()", result); - } - return 0; -} - -static int -D3D_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects, - int count) -{ - D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; - DWORD color; - int i; - float minx, miny, maxx, maxy; - Vertex vertices[4]; - HRESULT result; - - if (D3D_ActivateRenderer(renderer) < 0) { - return -1; - } - - D3D_SetBlendMode(data, renderer->blendMode); - - result = - IDirect3DDevice9_SetTexture(data->device, 0, - (IDirect3DBaseTexture9 *) 0); - if (FAILED(result)) { - return D3D_SetError("SetTexture()", result); - } - - color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b); - - for (i = 0; i < count; ++i) { - const SDL_FRect *rect = &rects[i]; - - minx = rect->x; - miny = rect->y; - maxx = rect->x + rect->w; - maxy = rect->y + rect->h; - - vertices[0].x = minx; - vertices[0].y = miny; - vertices[0].z = 0.0f; - vertices[0].color = color; - vertices[0].u = 0.0f; - vertices[0].v = 0.0f; - - vertices[1].x = maxx; - vertices[1].y = miny; - vertices[1].z = 0.0f; - vertices[1].color = color; - vertices[1].u = 0.0f; - vertices[1].v = 0.0f; - - vertices[2].x = maxx; - vertices[2].y = maxy; - vertices[2].z = 0.0f; - vertices[2].color = color; - vertices[2].u = 0.0f; - vertices[2].v = 0.0f; - - vertices[3].x = minx; - vertices[3].y = maxy; - vertices[3].z = 0.0f; - vertices[3].color = color; - vertices[3].u = 0.0f; - vertices[3].v = 0.0f; - - result = - IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN, - 2, vertices, sizeof(*vertices)); - if (FAILED(result)) { - return D3D_SetError("DrawPrimitiveUP()", result); - } - } - return 0; -} - -static void -D3D_UpdateTextureScaleMode(D3D_RenderData *data, D3D_TextureData *texturedata, unsigned index) -{ - if (texturedata->scaleMode != data->scaleMode[index]) { - IDirect3DDevice9_SetSamplerState(data->device, index, D3DSAMP_MINFILTER, - texturedata->scaleMode); - IDirect3DDevice9_SetSamplerState(data->device, index, D3DSAMP_MAGFILTER, - texturedata->scaleMode); - data->scaleMode[index] = texturedata->scaleMode; - } -} - -static int -D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_FRect * dstrect) -{ - D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; - D3D_TextureData *texturedata; - LPDIRECT3DPIXELSHADER9 shader = NULL; - float minx, miny, maxx, maxy; - float minu, maxu, minv, maxv; - DWORD color; - Vertex vertices[4]; - HRESULT result; - - if (D3D_ActivateRenderer(renderer) < 0) { - return -1; - } - - texturedata = (D3D_TextureData *)texture->driverdata; - if (!texturedata) { - SDL_SetError("Texture is not currently available"); - return -1; - } - - minx = dstrect->x - 0.5f; - miny = dstrect->y - 0.5f; - maxx = dstrect->x + dstrect->w - 0.5f; - maxy = dstrect->y + dstrect->h - 0.5f; - - minu = (float) srcrect->x / texture->w; - maxu = (float) (srcrect->x + srcrect->w) / texture->w; - minv = (float) srcrect->y / texture->h; - maxv = (float) (srcrect->y + srcrect->h) / texture->h; - - color = D3DCOLOR_ARGB(texture->a, texture->r, texture->g, texture->b); - - vertices[0].x = minx; - vertices[0].y = miny; - vertices[0].z = 0.0f; - vertices[0].color = color; - vertices[0].u = minu; - vertices[0].v = minv; - - vertices[1].x = maxx; - vertices[1].y = miny; - vertices[1].z = 0.0f; - vertices[1].color = color; - vertices[1].u = maxu; - vertices[1].v = minv; - - vertices[2].x = maxx; - vertices[2].y = maxy; - vertices[2].z = 0.0f; - vertices[2].color = color; - vertices[2].u = maxu; - vertices[2].v = maxv; - - vertices[3].x = minx; - vertices[3].y = maxy; - vertices[3].z = 0.0f; - vertices[3].color = color; - vertices[3].u = minu; - vertices[3].v = maxv; - - D3D_SetBlendMode(data, texture->blendMode); - - D3D_UpdateTextureScaleMode(data, texturedata, 0); - - if (D3D_BindTextureRep(data->device, &texturedata->texture, 0) < 0) { - return -1; - } - - if (texturedata->yuv) { - shader = data->ps_yuv; - - D3D_UpdateTextureScaleMode(data, texturedata, 1); - D3D_UpdateTextureScaleMode(data, texturedata, 2); - - if (D3D_BindTextureRep(data->device, &texturedata->utexture, 1) < 0) { - return -1; - } - if (D3D_BindTextureRep(data->device, &texturedata->vtexture, 2) < 0) { - return -1; - } - } - - if (shader) { - result = IDirect3DDevice9_SetPixelShader(data->device, shader); - if (FAILED(result)) { - return D3D_SetError("SetShader()", result); - } - } - result = - IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN, 2, - vertices, sizeof(*vertices)); - if (FAILED(result)) { - return D3D_SetError("DrawPrimitiveUP()", result); - } - if (shader) { - result = IDirect3DDevice9_SetPixelShader(data->device, NULL); - if (FAILED(result)) { - return D3D_SetError("SetShader()", result); - } - } - return 0; -} - - -static int -D3D_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_FRect * dstrect, - const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip) -{ - D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; - D3D_TextureData *texturedata; - LPDIRECT3DPIXELSHADER9 shader = NULL; - float minx, miny, maxx, maxy; - float minu, maxu, minv, maxv; - float centerx, centery; - DWORD color; - Vertex vertices[4]; - Float4X4 modelMatrix; - HRESULT result; - - if (D3D_ActivateRenderer(renderer) < 0) { - return -1; - } - - texturedata = (D3D_TextureData *)texture->driverdata; - if (!texturedata) { - SDL_SetError("Texture is not currently available"); - return -1; - } - - centerx = center->x; - centery = center->y; - - if (flip & SDL_FLIP_HORIZONTAL) { - minx = dstrect->w - centerx - 0.5f; - maxx = -centerx - 0.5f; - } - else { - minx = -centerx - 0.5f; - maxx = dstrect->w - centerx - 0.5f; - } - - if (flip & SDL_FLIP_VERTICAL) { - miny = dstrect->h - centery - 0.5f; - maxy = -centery - 0.5f; - } - else { - miny = -centery - 0.5f; - maxy = dstrect->h - centery - 0.5f; - } - - minu = (float) srcrect->x / texture->w; - maxu = (float) (srcrect->x + srcrect->w) / texture->w; - minv = (float) srcrect->y / texture->h; - maxv = (float) (srcrect->y + srcrect->h) / texture->h; - - color = D3DCOLOR_ARGB(texture->a, texture->r, texture->g, texture->b); - - vertices[0].x = minx; - vertices[0].y = miny; - vertices[0].z = 0.0f; - vertices[0].color = color; - vertices[0].u = minu; - vertices[0].v = minv; - - vertices[1].x = maxx; - vertices[1].y = miny; - vertices[1].z = 0.0f; - vertices[1].color = color; - vertices[1].u = maxu; - vertices[1].v = minv; - - vertices[2].x = maxx; - vertices[2].y = maxy; - vertices[2].z = 0.0f; - vertices[2].color = color; - vertices[2].u = maxu; - vertices[2].v = maxv; - - vertices[3].x = minx; - vertices[3].y = maxy; - vertices[3].z = 0.0f; - vertices[3].color = color; - vertices[3].u = minu; - vertices[3].v = maxv; - - D3D_SetBlendMode(data, texture->blendMode); - - /* Rotate and translate */ - modelMatrix = MatrixMultiply( - MatrixRotationZ((float)(M_PI * (float) angle / 180.0f)), - MatrixTranslation(dstrect->x + center->x, dstrect->y + center->y, 0) -); - IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, (D3DMATRIX*)&modelMatrix); - - D3D_UpdateTextureScaleMode(data, texturedata, 0); - - if (D3D_BindTextureRep(data->device, &texturedata->texture, 0) < 0) { - return -1; - } - - if (texturedata->yuv) { - shader = data->ps_yuv; - - D3D_UpdateTextureScaleMode(data, texturedata, 1); - D3D_UpdateTextureScaleMode(data, texturedata, 2); - - if (D3D_BindTextureRep(data->device, &texturedata->utexture, 1) < 0) { - return -1; - } - if (D3D_BindTextureRep(data->device, &texturedata->vtexture, 2) < 0) { - return -1; - } - } - - if (shader) { - result = IDirect3DDevice9_SetPixelShader(data->device, shader); - if (FAILED(result)) { - return D3D_SetError("SetShader()", result); - } - } - result = - IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN, 2, - vertices, sizeof(*vertices)); - if (FAILED(result)) { - return D3D_SetError("DrawPrimitiveUP()", result); - } - if (shader) { - result = IDirect3DDevice9_SetPixelShader(data->device, NULL); - if (FAILED(result)) { - return D3D_SetError("SetShader()", result); - } - } - - modelMatrix = MatrixIdentity(); - IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, (D3DMATRIX*)&modelMatrix); - return 0; -} - -static int -D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, - Uint32 format, void * pixels, int pitch) -{ - D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; - D3DSURFACE_DESC desc; - LPDIRECT3DSURFACE9 backBuffer; - LPDIRECT3DSURFACE9 surface; - RECT d3drect; - D3DLOCKED_RECT locked; - HRESULT result; - - if (data->currentRenderTarget) { - backBuffer = data->currentRenderTarget; - } else { - backBuffer = data->defaultRenderTarget; - } - - result = IDirect3DSurface9_GetDesc(backBuffer, &desc); - if (FAILED(result)) { - IDirect3DSurface9_Release(backBuffer); - return D3D_SetError("GetDesc()", result); - } - - result = IDirect3DDevice9_CreateOffscreenPlainSurface(data->device, desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &surface, NULL); - if (FAILED(result)) { - IDirect3DSurface9_Release(backBuffer); - return D3D_SetError("CreateOffscreenPlainSurface()", result); - } - - result = IDirect3DDevice9_GetRenderTargetData(data->device, backBuffer, surface); - if (FAILED(result)) { - IDirect3DSurface9_Release(surface); - IDirect3DSurface9_Release(backBuffer); - return D3D_SetError("GetRenderTargetData()", result); - } - - d3drect.left = rect->x; - d3drect.right = rect->x + rect->w; - d3drect.top = rect->y; - d3drect.bottom = rect->y + rect->h; - - result = IDirect3DSurface9_LockRect(surface, &locked, &d3drect, D3DLOCK_READONLY); - if (FAILED(result)) { - IDirect3DSurface9_Release(surface); - IDirect3DSurface9_Release(backBuffer); - return D3D_SetError("LockRect()", result); - } - - SDL_ConvertPixels(rect->w, rect->h, - D3DFMTToPixelFormat(desc.Format), locked.pBits, locked.Pitch, - format, pixels, pitch); - - IDirect3DSurface9_UnlockRect(surface); - - IDirect3DSurface9_Release(surface); - - return 0; -} - -static void -D3D_RenderPresent(SDL_Renderer * renderer) -{ - D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; - HRESULT result; - - if (!data->beginScene) { - IDirect3DDevice9_EndScene(data->device); - data->beginScene = SDL_TRUE; - } - - result = IDirect3DDevice9_TestCooperativeLevel(data->device); - if (result == D3DERR_DEVICELOST) { - /* We'll reset later */ - return; - } - if (result == D3DERR_DEVICENOTRESET) { - D3D_Reset(renderer); - } - result = IDirect3DDevice9_Present(data->device, NULL, NULL, NULL, NULL); - if (FAILED(result)) { - D3D_SetError("Present()", result); - } -} - -static void -D3D_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - D3D_TextureData *data = (D3D_TextureData *) texture->driverdata; - - if (!data) { - return; - } - D3D_DestroyTextureRep(&data->texture); - D3D_DestroyTextureRep(&data->utexture); - D3D_DestroyTextureRep(&data->vtexture); - SDL_free(data->pixels); - SDL_free(data); - texture->driverdata = NULL; -} - -static void -D3D_DestroyRenderer(SDL_Renderer * renderer) -{ - D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; - - if (data) { - /* Release the render target */ - if (data->defaultRenderTarget) { - IDirect3DSurface9_Release(data->defaultRenderTarget); - data->defaultRenderTarget = NULL; - } - if (data->currentRenderTarget != NULL) { - IDirect3DSurface9_Release(data->currentRenderTarget); - data->currentRenderTarget = NULL; - } - if (data->ps_yuv) { - IDirect3DPixelShader9_Release(data->ps_yuv); - } - if (data->device) { - IDirect3DDevice9_Release(data->device); - } - if (data->d3d) { - IDirect3D9_Release(data->d3d); - SDL_UnloadObject(data->d3dDLL); - } - SDL_free(data); - } - SDL_free(renderer); -} -#endif /* SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED */ - -#ifdef __WIN32__ -/* This function needs to always exist on Windows, for the Dynamic API. */ -IDirect3DDevice9 * -SDL_RenderGetD3D9Device(SDL_Renderer * renderer) -{ - IDirect3DDevice9 *device = NULL; - -#if SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED - D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; - - /* Make sure that this is a D3D renderer */ - if (renderer->DestroyRenderer != D3D_DestroyRenderer) { - SDL_SetError("Renderer is not a D3D renderer"); - return NULL; - } - - device = data->device; - if (device) { - IDirect3DDevice9_AddRef(device); - } -#endif /* SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED */ - - return device; -} -#endif /* __WIN32__ */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/direct3d11/SDL_render_d3d11.c b/3rdparty/SDL2/src/render/direct3d11/SDL_render_d3d11.c deleted file mode 100644 index df0f1558aa5..00000000000 --- a/3rdparty/SDL2/src/render/direct3d11/SDL_render_d3d11.c +++ /dev/null @@ -1,3014 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../../SDL_internal.h" - -#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED - -#define COBJMACROS -#include "../../core/windows/SDL_windows.h" -#include "SDL_hints.h" -#include "SDL_loadso.h" -#include "SDL_syswm.h" -#include "../SDL_sysrender.h" -#include "../SDL_d3dmath.h" -/* #include "SDL_log.h" */ - -#include <d3d11_1.h> - - -#ifdef __WINRT__ - -#if NTDDI_VERSION > NTDDI_WIN8 -#include <DXGI1_3.h> -#endif - -#include "SDL_render_winrt.h" - -#if WINAPI_FAMILY == WINAPI_FAMILY_APP -#include <windows.ui.xaml.media.dxinterop.h> -/* TODO, WinRT, XAML: get the ISwapChainBackgroundPanelNative from something other than a global var */ -extern ISwapChainBackgroundPanelNative * WINRT_GlobalSwapChainBackgroundPanelNative; -#endif /* WINAPI_FAMILY == WINAPI_FAMILY_APP */ - -#endif /* __WINRT__ */ - - -#define SDL_COMPOSE_ERROR(str) SDL_STRINGIFY_ARG(__FUNCTION__) ", " str - -#define SAFE_RELEASE(X) if ((X)) { IUnknown_Release(SDL_static_cast(IUnknown*, X)); X = NULL; } - - -/* Vertex shader, common values */ -typedef struct -{ - Float4X4 model; - Float4X4 projectionAndView; -} VertexShaderConstants; - -/* Per-vertex data */ -typedef struct -{ - Float3 pos; - Float2 tex; - Float4 color; -} VertexPositionColor; - -/* Per-texture data */ -typedef struct -{ - ID3D11Texture2D *mainTexture; - ID3D11ShaderResourceView *mainTextureResourceView; - ID3D11RenderTargetView *mainTextureRenderTargetView; - ID3D11Texture2D *stagingTexture; - int lockedTexturePositionX; - int lockedTexturePositionY; - D3D11_FILTER scaleMode; - - /* YV12 texture support */ - SDL_bool yuv; - ID3D11Texture2D *mainTextureU; - ID3D11ShaderResourceView *mainTextureResourceViewU; - ID3D11Texture2D *mainTextureV; - ID3D11ShaderResourceView *mainTextureResourceViewV; - Uint8 *pixels; - int pitch; - SDL_Rect locked_rect; -} D3D11_TextureData; - -/* Private renderer data */ -typedef struct -{ - void *hDXGIMod; - void *hD3D11Mod; - IDXGIFactory2 *dxgiFactory; - IDXGIAdapter *dxgiAdapter; - ID3D11Device1 *d3dDevice; - ID3D11DeviceContext1 *d3dContext; - IDXGISwapChain1 *swapChain; - DXGI_SWAP_EFFECT swapEffect; - ID3D11RenderTargetView *mainRenderTargetView; - ID3D11RenderTargetView *currentOffscreenRenderTargetView; - ID3D11InputLayout *inputLayout; - ID3D11Buffer *vertexBuffer; - ID3D11VertexShader *vertexShader; - ID3D11PixelShader *colorPixelShader; - ID3D11PixelShader *texturePixelShader; - ID3D11PixelShader *yuvPixelShader; - ID3D11BlendState *blendModeBlend; - ID3D11BlendState *blendModeAdd; - ID3D11BlendState *blendModeMod; - ID3D11SamplerState *nearestPixelSampler; - ID3D11SamplerState *linearSampler; - D3D_FEATURE_LEVEL featureLevel; - - /* Rasterizers */ - ID3D11RasterizerState *mainRasterizer; - ID3D11RasterizerState *clippedRasterizer; - - /* Vertex buffer constants */ - VertexShaderConstants vertexShaderConstantsData; - ID3D11Buffer *vertexShaderConstants; - - /* Cached renderer properties */ - DXGI_MODE_ROTATION rotation; - ID3D11RenderTargetView *currentRenderTargetView; - ID3D11RasterizerState *currentRasterizerState; - ID3D11BlendState *currentBlendState; - ID3D11PixelShader *currentShader; - ID3D11ShaderResourceView *currentShaderResource; - ID3D11SamplerState *currentSampler; -} D3D11_RenderData; - - -/* Define D3D GUIDs here so we don't have to include uuid.lib. -* -* Fix for SDL bug https://bugzilla.libsdl.org/show_bug.cgi?id=3437: -* The extra 'SDL_' was added to the start of each IID's name, in order -* to prevent build errors on both MinGW-w64 and WinRT/UWP. -* (SDL bug https://bugzilla.libsdl.org/show_bug.cgi?id=3336 led to -* linker errors in WinRT/UWP builds.) -*/ - -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-const-variable" -#endif - -static const GUID SDL_IID_IDXGIFactory2 = { 0x50c83a1c, 0xe072, 0x4c48, { 0x87, 0xb0, 0x36, 0x30, 0xfa, 0x36, 0xa6, 0xd0 } }; -static const GUID SDL_IID_IDXGIDevice1 = { 0x77db970f, 0x6276, 0x48ba, { 0xba, 0x28, 0x07, 0x01, 0x43, 0xb4, 0x39, 0x2c } }; -static const GUID SDL_IID_IDXGIDevice3 = { 0x6007896c, 0x3244, 0x4afd, { 0xbf, 0x18, 0xa6, 0xd3, 0xbe, 0xda, 0x50, 0x23 } }; -static const GUID SDL_IID_ID3D11Texture2D = { 0x6f15aaf2, 0xd208, 0x4e89, { 0x9a, 0xb4, 0x48, 0x95, 0x35, 0xd3, 0x4f, 0x9c } }; -static const GUID SDL_IID_ID3D11Device1 = { 0xa04bfb29, 0x08ef, 0x43d6, { 0xa4, 0x9c, 0xa9, 0xbd, 0xbd, 0xcb, 0xe6, 0x86 } }; -static const GUID SDL_IID_ID3D11DeviceContext1 = { 0xbb2c6faa, 0xb5fb, 0x4082, { 0x8e, 0x6b, 0x38, 0x8b, 0x8c, 0xfa, 0x90, 0xe1 } }; -static const GUID SDL_IID_ID3D11Debug = { 0x79cf2233, 0x7536, 0x4948, { 0x9d, 0x36, 0x1e, 0x46, 0x92, 0xdc, 0x57, 0x60 } }; - -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif - -/* Direct3D 11.x shaders - - SDL's shaders are compiled into SDL itself, to simplify distribution. - - All Direct3D 11.x shaders were compiled with the following: - - fxc /E"main" /T "<TYPE>" /Fo"<OUTPUT FILE>" "<INPUT FILE>" - - Variables: - - <TYPE>: the type of shader. A table of utilized shader types is - listed below. - - <OUTPUT FILE>: where to store compiled output - - <INPUT FILE>: where to read shader source code from - - Shader types: - - ps_4_0_level_9_1: Pixel shader for Windows 8+, including Windows RT - - vs_4_0_level_9_1: Vertex shader for Windows 8+, including Windows RT - - ps_4_0_level_9_3: Pixel shader for Windows Phone 8 - - vs_4_0_level_9_3: Vertex shader for Windows Phone 8 - - - Shader object code was converted to a list of DWORDs via the following - *nix style command (available separately from Windows + MSVC): - - hexdump -v -e '6/4 "0x%08.8x, " "\n"' <FILE> - */ -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP -#define D3D11_USE_SHADER_MODEL_4_0_level_9_3 -#else -#define D3D11_USE_SHADER_MODEL_4_0_level_9_1 -#endif - -/* The color-only-rendering pixel shader: - - --- D3D11_PixelShader_Colors.hlsl --- - struct PixelShaderInput - { - float4 pos : SV_POSITION; - float2 tex : TEXCOORD0; - float4 color : COLOR0; - }; - - float4 main(PixelShaderInput input) : SV_TARGET - { - return input.color; - } -*/ -#if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1) -static const DWORD D3D11_PixelShader_Colors[] = { - 0x43425844, 0xd74c28fe, 0xa1eb8804, 0x269d512a, 0x7699723d, 0x00000001, - 0x00000240, 0x00000006, 0x00000038, 0x00000084, 0x000000c4, 0x00000140, - 0x00000198, 0x0000020c, 0x396e6f41, 0x00000044, 0x00000044, 0xffff0200, - 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, - 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0001, 0x02000001, - 0x800f0800, 0xb0e40001, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, - 0x0000000e, 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, - 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, - 0x0100003e, 0x54415453, 0x00000074, 0x00000002, 0x00000000, 0x00000000, - 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x46454452, 0x00000050, 0x00000000, 0x00000000, - 0x00000000, 0x0000001c, 0xffff0400, 0x00000100, 0x0000001c, 0x7263694d, - 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, - 0x6c69706d, 0x39207265, 0x2e30332e, 0x30303239, 0x3336312e, 0xab003438, - 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, - 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, - 0x00000000, 0x00000003, 0x00000001, 0x00000003, 0x00000065, 0x00000000, - 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f, - 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f, - 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, - 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054 -}; -#elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3) -static const DWORD D3D11_PixelShader_Colors[] = { - 0x43425844, 0x93f6ccfc, 0x5f919270, 0x7a11aa4f, 0x9148e931, 0x00000001, - 0x00000240, 0x00000006, 0x00000038, 0x00000084, 0x000000c4, 0x00000140, - 0x00000198, 0x0000020c, 0x396e6f41, 0x00000044, 0x00000044, 0xffff0200, - 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, - 0x00240000, 0xffff0201, 0x0200001f, 0x80000000, 0xb00f0001, 0x02000001, - 0x800f0800, 0xb0e40001, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, - 0x0000000e, 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, - 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, - 0x0100003e, 0x54415453, 0x00000074, 0x00000002, 0x00000000, 0x00000000, - 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x46454452, 0x00000050, 0x00000000, 0x00000000, - 0x00000000, 0x0000001c, 0xffff0400, 0x00000100, 0x0000001c, 0x7263694d, - 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, - 0x6c69706d, 0x39207265, 0x2e30332e, 0x30303239, 0x3336312e, 0xab003438, - 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, - 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, - 0x00000000, 0x00000003, 0x00000001, 0x00000003, 0x00000065, 0x00000000, - 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f, - 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f, - 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, - 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054 -}; -#else -#error "An appropriate 'colors' pixel shader is not defined." -#endif - -/* The texture-rendering pixel shader: - - --- D3D11_PixelShader_Textures.hlsl --- - Texture2D theTexture : register(t0); - SamplerState theSampler : register(s0); - - struct PixelShaderInput - { - float4 pos : SV_POSITION; - float2 tex : TEXCOORD0; - float4 color : COLOR0; - }; - - float4 main(PixelShaderInput input) : SV_TARGET - { - return theTexture.Sample(theSampler, input.tex) * input.color; - } -*/ -#if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1) -static const DWORD D3D11_PixelShader_Textures[] = { - 0x43425844, 0x6299b59f, 0x155258f2, 0x873ab86a, 0xfcbb6dcd, 0x00000001, - 0x00000330, 0x00000006, 0x00000038, 0x000000c0, 0x0000015c, 0x000001d8, - 0x00000288, 0x000002fc, 0x396e6f41, 0x00000080, 0x00000080, 0xffff0200, - 0x00000058, 0x00000028, 0x00280000, 0x00280000, 0x00280000, 0x00240001, - 0x00280000, 0x00000000, 0xffff0200, 0x0200001f, 0x80000000, 0xb0030000, - 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f, 0x90000000, 0xa00f0800, - 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, 0x03000005, 0x800f0000, - 0x80e40000, 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, - 0x52444853, 0x00000094, 0x00000040, 0x00000025, 0x0300005a, 0x00106000, - 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x03001062, - 0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002, 0x03000065, - 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x09000045, 0x001000f2, - 0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000, 0x00106000, - 0x00000000, 0x07000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, - 0x00101e46, 0x00000002, 0x0100003e, 0x54415453, 0x00000074, 0x00000003, - 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x00000000, 0x00000000, - 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x46454452, 0x000000a8, - 0x00000000, 0x00000000, 0x00000002, 0x0000001c, 0xffff0400, 0x00000100, - 0x00000072, 0x0000005c, 0x00000003, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000001, 0x00000001, 0x00000067, 0x00000002, 0x00000005, - 0x00000004, 0xffffffff, 0x00000000, 0x00000001, 0x0000000d, 0x53656874, - 0x6c706d61, 0x74007265, 0x65546568, 0x72757478, 0x694d0065, 0x736f7263, - 0x2074666f, 0x20295228, 0x4c534c48, 0x61685320, 0x20726564, 0x706d6f43, - 0x72656c69, 0x332e3920, 0x32392e30, 0x312e3030, 0x34383336, 0xababab00, - 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, - 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, - 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000065, 0x00000000, - 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f, - 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f, - 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, - 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054 -}; -#elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3) -static const DWORD D3D11_PixelShader_Textures[] = { - 0x43425844, 0x5876569a, 0x01b6c87e, 0x8447454f, 0xc7f3ef10, 0x00000001, - 0x00000330, 0x00000006, 0x00000038, 0x000000c0, 0x0000015c, 0x000001d8, - 0x00000288, 0x000002fc, 0x396e6f41, 0x00000080, 0x00000080, 0xffff0200, - 0x00000058, 0x00000028, 0x00280000, 0x00280000, 0x00280000, 0x00240001, - 0x00280000, 0x00000000, 0xffff0201, 0x0200001f, 0x80000000, 0xb0030000, - 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f, 0x90000000, 0xa00f0800, - 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, 0x03000005, 0x800f0000, - 0x80e40000, 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, - 0x52444853, 0x00000094, 0x00000040, 0x00000025, 0x0300005a, 0x00106000, - 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x03001062, - 0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002, 0x03000065, - 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x09000045, 0x001000f2, - 0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000, 0x00106000, - 0x00000000, 0x07000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, - 0x00101e46, 0x00000002, 0x0100003e, 0x54415453, 0x00000074, 0x00000003, - 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x00000000, 0x00000000, - 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x46454452, 0x000000a8, - 0x00000000, 0x00000000, 0x00000002, 0x0000001c, 0xffff0400, 0x00000100, - 0x00000072, 0x0000005c, 0x00000003, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000001, 0x00000001, 0x00000067, 0x00000002, 0x00000005, - 0x00000004, 0xffffffff, 0x00000000, 0x00000001, 0x0000000d, 0x53656874, - 0x6c706d61, 0x74007265, 0x65546568, 0x72757478, 0x694d0065, 0x736f7263, - 0x2074666f, 0x20295228, 0x4c534c48, 0x61685320, 0x20726564, 0x706d6f43, - 0x72656c69, 0x332e3920, 0x32392e30, 0x312e3030, 0x34383336, 0xababab00, - 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, - 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, - 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000065, 0x00000000, - 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f, - 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f, - 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, - 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054 -}; -#else -#error "An appropriate 'textures' pixel shader is not defined" -#endif - -/* The yuv-rendering pixel shader: - - --- D3D11_PixelShader_YUV.hlsl --- - Texture2D theTextureY : register(t0); - Texture2D theTextureU : register(t1); - Texture2D theTextureV : register(t2); - SamplerState theSampler : register(s0); - - struct PixelShaderInput - { - float4 pos : SV_POSITION; - float2 tex : TEXCOORD0; - float4 color : COLOR0; - }; - - float4 main(PixelShaderInput input) : SV_TARGET - { - const float3 offset = {-0.0627451017, -0.501960814, -0.501960814}; - const float3 Rcoeff = {1.164, 0.000, 1.596}; - const float3 Gcoeff = {1.164, -0.391, -0.813}; - const float3 Bcoeff = {1.164, 2.018, 0.000}; - - float4 Output; - - float3 yuv; - yuv.x = theTextureY.Sample(theSampler, input.tex).r; - yuv.y = theTextureU.Sample(theSampler, input.tex).r; - yuv.z = theTextureV.Sample(theSampler, input.tex).r; - - yuv += offset; - Output.r = dot(yuv, Rcoeff); - Output.g = dot(yuv, Gcoeff); - Output.b = dot(yuv, Bcoeff); - Output.a = 1.0f; - - return Output * input.color; - } - -*/ -#if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1) -static const DWORD D3D11_PixelShader_YUV[] = { - 0x43425844, 0x2321c6c6, 0xf14df2d1, 0xc79d068d, 0x8e672abf, 0x00000001, - 0x000005e8, 0x00000006, 0x00000038, 0x000001dc, 0x000003bc, 0x00000438, - 0x00000540, 0x000005b4, 0x396e6f41, 0x0000019c, 0x0000019c, 0xffff0200, - 0x0000016c, 0x00000030, 0x00300000, 0x00300000, 0x00300000, 0x00240003, - 0x00300000, 0x00000000, 0x00010001, 0x00020002, 0xffff0200, 0x05000051, - 0xa00f0000, 0xbd808081, 0xbf008081, 0xbf008081, 0x3f800000, 0x05000051, - 0xa00f0001, 0x3f94fdf4, 0x3fcc49ba, 0x00000000, 0x00000000, 0x05000051, - 0xa00f0002, 0x3f94fdf4, 0xbec83127, 0xbf5020c5, 0x00000000, 0x05000051, - 0xa00f0003, 0x3f94fdf4, 0x400126e9, 0x00000000, 0x00000000, 0x0200001f, - 0x80000000, 0xb0030000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f, - 0x90000000, 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x0200001f, - 0x90000000, 0xa00f0802, 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, - 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40801, 0x03000042, 0x800f0002, - 0xb0e40000, 0xa0e40802, 0x02000001, 0x80020000, 0x80000001, 0x02000001, - 0x80040000, 0x80000002, 0x03000002, 0x80070000, 0x80e40000, 0xa0e40000, - 0x03000005, 0x80080000, 0x80000000, 0xa0000001, 0x04000004, 0x80010001, - 0x80aa0000, 0xa0550001, 0x80ff0000, 0x03000008, 0x80020001, 0x80e40000, - 0xa0e40002, 0x0400005a, 0x80040001, 0x80e40000, 0xa0e40003, 0xa0aa0003, - 0x02000001, 0x80080001, 0xa0ff0000, 0x03000005, 0x800f0000, 0x80e40001, - 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, 0x52444853, - 0x000001d8, 0x00000040, 0x00000076, 0x0300005a, 0x00106000, 0x00000000, - 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858, 0x00107000, - 0x00000001, 0x00005555, 0x04001858, 0x00107000, 0x00000002, 0x00005555, - 0x03001062, 0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002, - 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x09000045, - 0x001000f2, 0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000, - 0x00106000, 0x00000000, 0x09000045, 0x001000f2, 0x00000001, 0x00101046, - 0x00000001, 0x00107e46, 0x00000001, 0x00106000, 0x00000000, 0x05000036, - 0x00100022, 0x00000000, 0x0010000a, 0x00000001, 0x09000045, 0x001000f2, - 0x00000001, 0x00101046, 0x00000001, 0x00107e46, 0x00000002, 0x00106000, - 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x0010000a, 0x00000001, - 0x0a000000, 0x00100072, 0x00000000, 0x00100246, 0x00000000, 0x00004002, - 0xbd808081, 0xbf008081, 0xbf008081, 0x00000000, 0x0a00000f, 0x00100012, - 0x00000001, 0x00100086, 0x00000000, 0x00004002, 0x3f94fdf4, 0x3fcc49ba, - 0x00000000, 0x00000000, 0x0a000010, 0x00100022, 0x00000001, 0x00100246, - 0x00000000, 0x00004002, 0x3f94fdf4, 0xbec83127, 0xbf5020c5, 0x00000000, - 0x0a00000f, 0x00100042, 0x00000001, 0x00100046, 0x00000000, 0x00004002, - 0x3f94fdf4, 0x400126e9, 0x00000000, 0x00000000, 0x05000036, 0x00100082, - 0x00000001, 0x00004001, 0x3f800000, 0x07000038, 0x001020f2, 0x00000000, - 0x00100e46, 0x00000001, 0x00101e46, 0x00000002, 0x0100003e, 0x54415453, - 0x00000074, 0x0000000c, 0x00000002, 0x00000000, 0x00000003, 0x00000005, - 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x46454452, 0x00000100, 0x00000000, 0x00000000, 0x00000004, 0x0000001c, - 0xffff0400, 0x00000100, 0x000000cb, 0x0000009c, 0x00000003, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x000000a7, - 0x00000002, 0x00000005, 0x00000004, 0xffffffff, 0x00000000, 0x00000001, - 0x0000000d, 0x000000b3, 0x00000002, 0x00000005, 0x00000004, 0xffffffff, - 0x00000001, 0x00000001, 0x0000000d, 0x000000bf, 0x00000002, 0x00000005, - 0x00000004, 0xffffffff, 0x00000002, 0x00000001, 0x0000000d, 0x53656874, - 0x6c706d61, 0x74007265, 0x65546568, 0x72757478, 0x74005965, 0x65546568, - 0x72757478, 0x74005565, 0x65546568, 0x72757478, 0x4d005665, 0x6f726369, - 0x74666f73, 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, - 0x656c6970, 0x2e362072, 0x36392e33, 0x312e3030, 0x34383336, 0xababab00, - 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, - 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, - 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000065, 0x00000000, - 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f, - 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f, - 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, - 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054 -}; -#elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3) -static const DWORD D3D11_PixelShader_YUV[] = { - 0x43425844, 0x6ede7360, 0x45ff5f8a, 0x34ac92ba, 0xb865f5e0, 0x00000001, - 0x000005c0, 0x00000006, 0x00000038, 0x000001b4, 0x00000394, 0x00000410, - 0x00000518, 0x0000058c, 0x396e6f41, 0x00000174, 0x00000174, 0xffff0200, - 0x00000144, 0x00000030, 0x00300000, 0x00300000, 0x00300000, 0x00240003, - 0x00300000, 0x00000000, 0x00010001, 0x00020002, 0xffff0201, 0x05000051, - 0xa00f0000, 0xbd808081, 0xbf008081, 0x3f800000, 0x00000000, 0x05000051, - 0xa00f0001, 0x3f94fdf4, 0x3fcc49ba, 0x00000000, 0x400126e9, 0x05000051, - 0xa00f0002, 0x3f94fdf4, 0xbec83127, 0xbf5020c5, 0x00000000, 0x0200001f, - 0x80000000, 0xb0030000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f, - 0x90000000, 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x0200001f, - 0x90000000, 0xa00f0802, 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40801, - 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40800, 0x02000001, 0x80020001, - 0x80000000, 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40802, 0x02000001, - 0x80040001, 0x80000000, 0x03000002, 0x80070000, 0x80e40001, 0xa0d40000, - 0x0400005a, 0x80010001, 0x80e80000, 0xa0e40001, 0xa0aa0001, 0x03000008, - 0x80020001, 0x80e40000, 0xa0e40002, 0x0400005a, 0x80040001, 0x80e40000, - 0xa0ec0001, 0xa0aa0001, 0x02000001, 0x80080001, 0xa0aa0000, 0x03000005, - 0x800f0000, 0x80e40001, 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000, - 0x0000ffff, 0x52444853, 0x000001d8, 0x00000040, 0x00000076, 0x0300005a, - 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, - 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04001858, 0x00107000, - 0x00000002, 0x00005555, 0x03001062, 0x00101032, 0x00000001, 0x03001062, - 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, - 0x00000002, 0x09000045, 0x001000f2, 0x00000000, 0x00101046, 0x00000001, - 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x09000045, 0x001000f2, - 0x00000001, 0x00101046, 0x00000001, 0x00107e46, 0x00000001, 0x00106000, - 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x0010000a, 0x00000001, - 0x09000045, 0x001000f2, 0x00000001, 0x00101046, 0x00000001, 0x00107e46, - 0x00000002, 0x00106000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, - 0x0010000a, 0x00000001, 0x0a000000, 0x00100072, 0x00000000, 0x00100246, - 0x00000000, 0x00004002, 0xbd808081, 0xbf008081, 0xbf008081, 0x00000000, - 0x0a00000f, 0x00100012, 0x00000001, 0x00100086, 0x00000000, 0x00004002, - 0x3f94fdf4, 0x3fcc49ba, 0x00000000, 0x00000000, 0x0a000010, 0x00100022, - 0x00000001, 0x00100246, 0x00000000, 0x00004002, 0x3f94fdf4, 0xbec83127, - 0xbf5020c5, 0x00000000, 0x0a00000f, 0x00100042, 0x00000001, 0x00100046, - 0x00000000, 0x00004002, 0x3f94fdf4, 0x400126e9, 0x00000000, 0x00000000, - 0x05000036, 0x00100082, 0x00000001, 0x00004001, 0x3f800000, 0x07000038, - 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00101e46, 0x00000002, - 0x0100003e, 0x54415453, 0x00000074, 0x0000000c, 0x00000002, 0x00000000, - 0x00000003, 0x00000005, 0x00000000, 0x00000000, 0x00000001, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x46454452, 0x00000100, 0x00000000, 0x00000000, - 0x00000004, 0x0000001c, 0xffff0400, 0x00000100, 0x000000cb, 0x0000009c, - 0x00000003, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, - 0x00000001, 0x000000a7, 0x00000002, 0x00000005, 0x00000004, 0xffffffff, - 0x00000000, 0x00000001, 0x0000000d, 0x000000b3, 0x00000002, 0x00000005, - 0x00000004, 0xffffffff, 0x00000001, 0x00000001, 0x0000000d, 0x000000bf, - 0x00000002, 0x00000005, 0x00000004, 0xffffffff, 0x00000002, 0x00000001, - 0x0000000d, 0x53656874, 0x6c706d61, 0x74007265, 0x65546568, 0x72757478, - 0x74005965, 0x65546568, 0x72757478, 0x74005565, 0x65546568, 0x72757478, - 0x4d005665, 0x6f726369, 0x74666f73, 0x29522820, 0x534c4820, 0x6853204c, - 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e362072, 0x36392e33, 0x312e3030, - 0x34383336, 0xababab00, 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, - 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, - 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000303, - 0x00000065, 0x00000000, 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, - 0x505f5653, 0x5449534f, 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, - 0xab00524f, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, - 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, - 0x45475241, 0xabab0054 -}; -#else -#error "An appropriate 'yuv' pixel shader is not defined." -#endif - -/* The sole vertex shader: - - --- D3D11_VertexShader.hlsl --- - #pragma pack_matrix( row_major ) - - cbuffer VertexShaderConstants : register(b0) - { - matrix model; - matrix projectionAndView; - }; - - struct VertexShaderInput - { - float3 pos : POSITION; - float2 tex : TEXCOORD0; - float4 color : COLOR0; - }; - - struct VertexShaderOutput - { - float4 pos : SV_POSITION; - float2 tex : TEXCOORD0; - float4 color : COLOR0; - }; - - VertexShaderOutput main(VertexShaderInput input) - { - VertexShaderOutput output; - float4 pos = float4(input.pos, 1.0f); - - // Transform the vertex position into projected space. - pos = mul(pos, model); - pos = mul(pos, projectionAndView); - output.pos = pos; - - // Pass through texture coordinates and color values without transformation - output.tex = input.tex; - output.color = input.color; - - return output; - } -*/ -#if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1) -static const DWORD D3D11_VertexShader[] = { - 0x43425844, 0x62dfae5f, 0x3e8bd8df, 0x9ec97127, 0x5044eefb, 0x00000001, - 0x00000598, 0x00000006, 0x00000038, 0x0000016c, 0x00000334, 0x000003b0, - 0x000004b4, 0x00000524, 0x396e6f41, 0x0000012c, 0x0000012c, 0xfffe0200, - 0x000000f8, 0x00000034, 0x00240001, 0x00300000, 0x00300000, 0x00240000, - 0x00300001, 0x00000000, 0x00010008, 0x00000000, 0x00000000, 0xfffe0200, - 0x0200001f, 0x80000005, 0x900f0000, 0x0200001f, 0x80010005, 0x900f0001, - 0x0200001f, 0x80020005, 0x900f0002, 0x03000005, 0x800f0000, 0x90550000, - 0xa0e40002, 0x04000004, 0x800f0000, 0x90000000, 0xa0e40001, 0x80e40000, - 0x04000004, 0x800f0000, 0x90aa0000, 0xa0e40003, 0x80e40000, 0x03000002, - 0x800f0000, 0x80e40000, 0xa0e40004, 0x03000005, 0x800f0001, 0x80550000, - 0xa0e40006, 0x04000004, 0x800f0001, 0x80000000, 0xa0e40005, 0x80e40001, - 0x04000004, 0x800f0001, 0x80aa0000, 0xa0e40007, 0x80e40001, 0x04000004, - 0x800f0000, 0x80ff0000, 0xa0e40008, 0x80e40001, 0x04000004, 0xc0030000, - 0x80ff0000, 0xa0e40000, 0x80e40000, 0x02000001, 0xc00c0000, 0x80e40000, - 0x02000001, 0xe0030000, 0x90e40001, 0x02000001, 0xe00f0001, 0x90e40002, - 0x0000ffff, 0x52444853, 0x000001c0, 0x00010040, 0x00000070, 0x04000059, - 0x00208e46, 0x00000000, 0x00000008, 0x0300005f, 0x00101072, 0x00000000, - 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, - 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102032, - 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000002, - 0x08000038, 0x001000f2, 0x00000000, 0x00101556, 0x00000000, 0x00208e46, - 0x00000000, 0x00000001, 0x0a000032, 0x001000f2, 0x00000000, 0x00101006, - 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000, - 0x0a000032, 0x001000f2, 0x00000000, 0x00101aa6, 0x00000000, 0x00208e46, - 0x00000000, 0x00000002, 0x00100e46, 0x00000000, 0x08000000, 0x001000f2, - 0x00000000, 0x00100e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003, - 0x08000038, 0x001000f2, 0x00000001, 0x00100556, 0x00000000, 0x00208e46, - 0x00000000, 0x00000005, 0x0a000032, 0x001000f2, 0x00000001, 0x00100006, - 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x00100e46, 0x00000001, - 0x0a000032, 0x001000f2, 0x00000001, 0x00100aa6, 0x00000000, 0x00208e46, - 0x00000000, 0x00000006, 0x00100e46, 0x00000001, 0x0a000032, 0x001020f2, - 0x00000000, 0x00100ff6, 0x00000000, 0x00208e46, 0x00000000, 0x00000007, - 0x00100e46, 0x00000001, 0x05000036, 0x00102032, 0x00000001, 0x00101046, - 0x00000001, 0x05000036, 0x001020f2, 0x00000002, 0x00101e46, 0x00000002, - 0x0100003e, 0x54415453, 0x00000074, 0x0000000b, 0x00000002, 0x00000000, - 0x00000006, 0x00000003, 0x00000000, 0x00000000, 0x00000001, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x46454452, 0x000000fc, 0x00000001, 0x00000054, - 0x00000001, 0x0000001c, 0xfffe0400, 0x00000100, 0x000000c6, 0x0000003c, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, - 0x00000001, 0x74726556, 0x68537865, 0x72656461, 0x736e6f43, 0x746e6174, - 0xabab0073, 0x0000003c, 0x00000002, 0x0000006c, 0x00000080, 0x00000000, - 0x00000000, 0x0000009c, 0x00000000, 0x00000040, 0x00000002, 0x000000a4, - 0x00000000, 0x000000b4, 0x00000040, 0x00000040, 0x00000002, 0x000000a4, - 0x00000000, 0x65646f6d, 0xabab006c, 0x00030002, 0x00040004, 0x00000000, - 0x00000000, 0x6a6f7270, 0x69746365, 0x6e416e6f, 0x65695664, 0x694d0077, - 0x736f7263, 0x2074666f, 0x20295228, 0x4c534c48, 0x61685320, 0x20726564, - 0x706d6f43, 0x72656c69, 0x332e3920, 0x32392e30, 0x312e3030, 0x34383336, - 0xababab00, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050, - 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000707, 0x00000059, - 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000062, - 0x00000000, 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x49534f50, - 0x4e4f4954, 0x58455400, 0x524f4f43, 0x4f430044, 0x00524f4c, 0x4e47534f, - 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, - 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, - 0x00000003, 0x00000001, 0x00000c03, 0x00000065, 0x00000000, 0x00000000, - 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, - 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f -}; -#elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3) -static const DWORD D3D11_VertexShader[] = { - 0x43425844, 0x01a24e41, 0x696af551, 0x4b2a87d1, 0x82ea03f6, 0x00000001, - 0x00000598, 0x00000006, 0x00000038, 0x0000016c, 0x00000334, 0x000003b0, - 0x000004b4, 0x00000524, 0x396e6f41, 0x0000012c, 0x0000012c, 0xfffe0200, - 0x000000f8, 0x00000034, 0x00240001, 0x00300000, 0x00300000, 0x00240000, - 0x00300001, 0x00000000, 0x00010008, 0x00000000, 0x00000000, 0xfffe0201, - 0x0200001f, 0x80000005, 0x900f0000, 0x0200001f, 0x80010005, 0x900f0001, - 0x0200001f, 0x80020005, 0x900f0002, 0x03000005, 0x800f0000, 0x90550000, - 0xa0e40002, 0x04000004, 0x800f0000, 0x90000000, 0xa0e40001, 0x80e40000, - 0x04000004, 0x800f0000, 0x90aa0000, 0xa0e40003, 0x80e40000, 0x03000002, - 0x800f0000, 0x80e40000, 0xa0e40004, 0x03000005, 0x800f0001, 0x80550000, - 0xa0e40006, 0x04000004, 0x800f0001, 0x80000000, 0xa0e40005, 0x80e40001, - 0x04000004, 0x800f0001, 0x80aa0000, 0xa0e40007, 0x80e40001, 0x04000004, - 0x800f0000, 0x80ff0000, 0xa0e40008, 0x80e40001, 0x04000004, 0xc0030000, - 0x80ff0000, 0xa0e40000, 0x80e40000, 0x02000001, 0xc00c0000, 0x80e40000, - 0x02000001, 0xe0030000, 0x90e40001, 0x02000001, 0xe00f0001, 0x90e40002, - 0x0000ffff, 0x52444853, 0x000001c0, 0x00010040, 0x00000070, 0x04000059, - 0x00208e46, 0x00000000, 0x00000008, 0x0300005f, 0x00101072, 0x00000000, - 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, - 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102032, - 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000002, - 0x08000038, 0x001000f2, 0x00000000, 0x00101556, 0x00000000, 0x00208e46, - 0x00000000, 0x00000001, 0x0a000032, 0x001000f2, 0x00000000, 0x00101006, - 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000, - 0x0a000032, 0x001000f2, 0x00000000, 0x00101aa6, 0x00000000, 0x00208e46, - 0x00000000, 0x00000002, 0x00100e46, 0x00000000, 0x08000000, 0x001000f2, - 0x00000000, 0x00100e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003, - 0x08000038, 0x001000f2, 0x00000001, 0x00100556, 0x00000000, 0x00208e46, - 0x00000000, 0x00000005, 0x0a000032, 0x001000f2, 0x00000001, 0x00100006, - 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x00100e46, 0x00000001, - 0x0a000032, 0x001000f2, 0x00000001, 0x00100aa6, 0x00000000, 0x00208e46, - 0x00000000, 0x00000006, 0x00100e46, 0x00000001, 0x0a000032, 0x001020f2, - 0x00000000, 0x00100ff6, 0x00000000, 0x00208e46, 0x00000000, 0x00000007, - 0x00100e46, 0x00000001, 0x05000036, 0x00102032, 0x00000001, 0x00101046, - 0x00000001, 0x05000036, 0x001020f2, 0x00000002, 0x00101e46, 0x00000002, - 0x0100003e, 0x54415453, 0x00000074, 0x0000000b, 0x00000002, 0x00000000, - 0x00000006, 0x00000003, 0x00000000, 0x00000000, 0x00000001, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x46454452, 0x000000fc, 0x00000001, 0x00000054, - 0x00000001, 0x0000001c, 0xfffe0400, 0x00000100, 0x000000c6, 0x0000003c, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, - 0x00000001, 0x74726556, 0x68537865, 0x72656461, 0x736e6f43, 0x746e6174, - 0xabab0073, 0x0000003c, 0x00000002, 0x0000006c, 0x00000080, 0x00000000, - 0x00000000, 0x0000009c, 0x00000000, 0x00000040, 0x00000002, 0x000000a4, - 0x00000000, 0x000000b4, 0x00000040, 0x00000040, 0x00000002, 0x000000a4, - 0x00000000, 0x65646f6d, 0xabab006c, 0x00030002, 0x00040004, 0x00000000, - 0x00000000, 0x6a6f7270, 0x69746365, 0x6e416e6f, 0x65695664, 0x694d0077, - 0x736f7263, 0x2074666f, 0x20295228, 0x4c534c48, 0x61685320, 0x20726564, - 0x706d6f43, 0x72656c69, 0x332e3920, 0x32392e30, 0x312e3030, 0x34383336, - 0xababab00, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050, - 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000707, 0x00000059, - 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000062, - 0x00000000, 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x49534f50, - 0x4e4f4954, 0x58455400, 0x524f4f43, 0x4f430044, 0x00524f4c, 0x4e47534f, - 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, - 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, - 0x00000003, 0x00000001, 0x00000c03, 0x00000065, 0x00000000, 0x00000000, - 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, - 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f -}; -#else -#error "An appropriate vertex shader is not defined." -#endif - - -/* Direct3D 11.1 renderer implementation */ -static SDL_Renderer *D3D11_CreateRenderer(SDL_Window * window, Uint32 flags); -static void D3D11_WindowEvent(SDL_Renderer * renderer, - const SDL_WindowEvent *event); -static int D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); -static int D3D11_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, const void *srcPixels, - int srcPitch); -static int D3D11_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, - const Uint8 *Yplane, int Ypitch, - const Uint8 *Uplane, int Upitch, - const Uint8 *Vplane, int Vpitch); -static int D3D11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, void **pixels, int *pitch); -static void D3D11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); -static int D3D11_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture); -static int D3D11_UpdateViewport(SDL_Renderer * renderer); -static int D3D11_UpdateClipRect(SDL_Renderer * renderer); -static int D3D11_RenderClear(SDL_Renderer * renderer); -static int D3D11_RenderDrawPoints(SDL_Renderer * renderer, - const SDL_FPoint * points, int count); -static int D3D11_RenderDrawLines(SDL_Renderer * renderer, - const SDL_FPoint * points, int count); -static int D3D11_RenderFillRects(SDL_Renderer * renderer, - const SDL_FRect * rects, int count); -static int D3D11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_FRect * dstrect); -static int D3D11_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_FRect * dstrect, - const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip); -static int D3D11_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, - Uint32 format, void * pixels, int pitch); -static void D3D11_RenderPresent(SDL_Renderer * renderer); -static void D3D11_DestroyTexture(SDL_Renderer * renderer, - SDL_Texture * texture); -static void D3D11_DestroyRenderer(SDL_Renderer * renderer); - -/* Direct3D 11.1 Internal Functions */ -static HRESULT D3D11_CreateDeviceResources(SDL_Renderer * renderer); -static HRESULT D3D11_CreateWindowSizeDependentResources(SDL_Renderer * renderer); -static HRESULT D3D11_UpdateForWindowSizeChange(SDL_Renderer * renderer); -static HRESULT D3D11_HandleDeviceLost(SDL_Renderer * renderer); -static void D3D11_ReleaseMainRenderTargetView(SDL_Renderer * renderer); - -SDL_RenderDriver D3D11_RenderDriver = { - D3D11_CreateRenderer, - { - "direct3d11", - ( - SDL_RENDERER_ACCELERATED | - SDL_RENDERER_PRESENTVSYNC | - SDL_RENDERER_TARGETTEXTURE - ), /* flags. see SDL_RendererFlags */ - 4, /* num_texture_formats */ - { /* texture_formats */ - SDL_PIXELFORMAT_ARGB8888, - SDL_PIXELFORMAT_RGB888, - SDL_PIXELFORMAT_YV12, - SDL_PIXELFORMAT_IYUV - }, - 0, /* max_texture_width: will be filled in later */ - 0 /* max_texture_height: will be filled in later */ - } -}; - - -Uint32 -D3D11_DXGIFormatToSDLPixelFormat(DXGI_FORMAT dxgiFormat) { - switch (dxgiFormat) { - case DXGI_FORMAT_B8G8R8A8_UNORM: - return SDL_PIXELFORMAT_ARGB8888; - case DXGI_FORMAT_B8G8R8X8_UNORM: - return SDL_PIXELFORMAT_RGB888; - default: - return SDL_PIXELFORMAT_UNKNOWN; - } -} - -static DXGI_FORMAT -SDLPixelFormatToDXGIFormat(Uint32 sdlFormat) -{ - switch (sdlFormat) { - case SDL_PIXELFORMAT_ARGB8888: - return DXGI_FORMAT_B8G8R8A8_UNORM; - case SDL_PIXELFORMAT_RGB888: - return DXGI_FORMAT_B8G8R8X8_UNORM; - case SDL_PIXELFORMAT_YV12: - case SDL_PIXELFORMAT_IYUV: - return DXGI_FORMAT_R8_UNORM; - default: - return DXGI_FORMAT_UNKNOWN; - } -} - -SDL_Renderer * -D3D11_CreateRenderer(SDL_Window * window, Uint32 flags) -{ - SDL_Renderer *renderer; - D3D11_RenderData *data; - - renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); - if (!renderer) { - SDL_OutOfMemory(); - return NULL; - } - - data = (D3D11_RenderData *) SDL_calloc(1, sizeof(*data)); - if (!data) { - SDL_OutOfMemory(); - return NULL; - } - - renderer->WindowEvent = D3D11_WindowEvent; - renderer->CreateTexture = D3D11_CreateTexture; - renderer->UpdateTexture = D3D11_UpdateTexture; - renderer->UpdateTextureYUV = D3D11_UpdateTextureYUV; - renderer->LockTexture = D3D11_LockTexture; - renderer->UnlockTexture = D3D11_UnlockTexture; - renderer->SetRenderTarget = D3D11_SetRenderTarget; - renderer->UpdateViewport = D3D11_UpdateViewport; - renderer->UpdateClipRect = D3D11_UpdateClipRect; - renderer->RenderClear = D3D11_RenderClear; - renderer->RenderDrawPoints = D3D11_RenderDrawPoints; - renderer->RenderDrawLines = D3D11_RenderDrawLines; - renderer->RenderFillRects = D3D11_RenderFillRects; - renderer->RenderCopy = D3D11_RenderCopy; - renderer->RenderCopyEx = D3D11_RenderCopyEx; - renderer->RenderReadPixels = D3D11_RenderReadPixels; - renderer->RenderPresent = D3D11_RenderPresent; - renderer->DestroyTexture = D3D11_DestroyTexture; - renderer->DestroyRenderer = D3D11_DestroyRenderer; - renderer->info = D3D11_RenderDriver.info; - renderer->info.flags = (SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE); - renderer->driverdata = data; - -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP - /* VSync is required in Windows Phone, at least for Win Phone 8.0 and 8.1. - * Failure to use it seems to either result in: - * - * - with the D3D11 debug runtime turned OFF, vsync seemingly gets turned - * off (framerate doesn't get capped), but nothing appears on-screen - * - * - with the D3D11 debug runtime turned ON, vsync gets automatically - * turned back on, and the following gets output to the debug console: - * - * DXGI ERROR: IDXGISwapChain::Present: Interval 0 is not supported, changed to Interval 1. [ UNKNOWN ERROR #1024: ] - */ - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; -#else - if ((flags & SDL_RENDERER_PRESENTVSYNC)) { - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; - } -#endif - - /* HACK: make sure the SDL_Renderer references the SDL_Window data now, in - * order to give init functions access to the underlying window handle: - */ - renderer->window = window; - - /* Initialize Direct3D resources */ - if (FAILED(D3D11_CreateDeviceResources(renderer))) { - D3D11_DestroyRenderer(renderer); - return NULL; - } - if (FAILED(D3D11_CreateWindowSizeDependentResources(renderer))) { - D3D11_DestroyRenderer(renderer); - return NULL; - } - - return renderer; -} - -static void -D3D11_ReleaseAll(SDL_Renderer * renderer) -{ - D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata; - SDL_Texture *texture = NULL; - - /* Release all textures */ - for (texture = renderer->textures; texture; texture = texture->next) { - D3D11_DestroyTexture(renderer, texture); - } - - /* Release/reset everything else */ - if (data) { - SAFE_RELEASE(data->dxgiFactory); - SAFE_RELEASE(data->dxgiAdapter); - SAFE_RELEASE(data->d3dDevice); - SAFE_RELEASE(data->d3dContext); - SAFE_RELEASE(data->swapChain); - SAFE_RELEASE(data->mainRenderTargetView); - SAFE_RELEASE(data->currentOffscreenRenderTargetView); - SAFE_RELEASE(data->inputLayout); - SAFE_RELEASE(data->vertexBuffer); - SAFE_RELEASE(data->vertexShader); - SAFE_RELEASE(data->colorPixelShader); - SAFE_RELEASE(data->texturePixelShader); - SAFE_RELEASE(data->yuvPixelShader); - SAFE_RELEASE(data->blendModeBlend); - SAFE_RELEASE(data->blendModeAdd); - SAFE_RELEASE(data->blendModeMod); - SAFE_RELEASE(data->nearestPixelSampler); - SAFE_RELEASE(data->linearSampler); - SAFE_RELEASE(data->mainRasterizer); - SAFE_RELEASE(data->clippedRasterizer); - SAFE_RELEASE(data->vertexShaderConstants); - - data->swapEffect = (DXGI_SWAP_EFFECT) 0; - data->rotation = DXGI_MODE_ROTATION_UNSPECIFIED; - data->currentRenderTargetView = NULL; - data->currentRasterizerState = NULL; - data->currentBlendState = NULL; - data->currentShader = NULL; - data->currentShaderResource = NULL; - data->currentSampler = NULL; - - /* Unload the D3D libraries. This should be done last, in order - * to prevent IUnknown::Release() calls from crashing. - */ - if (data->hD3D11Mod) { - SDL_UnloadObject(data->hD3D11Mod); - data->hD3D11Mod = NULL; - } - if (data->hDXGIMod) { - SDL_UnloadObject(data->hDXGIMod); - data->hDXGIMod = NULL; - } - } -} - -static void -D3D11_DestroyRenderer(SDL_Renderer * renderer) -{ - D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata; - D3D11_ReleaseAll(renderer); - if (data) { - SDL_free(data); - } - SDL_free(renderer); -} - -static HRESULT -D3D11_CreateBlendMode(SDL_Renderer * renderer, - BOOL enableBlending, - D3D11_BLEND srcBlend, - D3D11_BLEND destBlend, - D3D11_BLEND srcBlendAlpha, - D3D11_BLEND destBlendAlpha, - ID3D11BlendState ** blendStateOutput) -{ - D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata; - HRESULT result = S_OK; - - D3D11_BLEND_DESC blendDesc; - SDL_zero(blendDesc); - blendDesc.AlphaToCoverageEnable = FALSE; - blendDesc.IndependentBlendEnable = FALSE; - blendDesc.RenderTarget[0].BlendEnable = enableBlending; - blendDesc.RenderTarget[0].SrcBlend = srcBlend; - blendDesc.RenderTarget[0].DestBlend = destBlend; - blendDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; - blendDesc.RenderTarget[0].SrcBlendAlpha = srcBlendAlpha; - blendDesc.RenderTarget[0].DestBlendAlpha = destBlendAlpha; - blendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; - blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; - result = ID3D11Device_CreateBlendState(data->d3dDevice, &blendDesc, blendStateOutput); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateBlendState"), result); - return result; - } - - return S_OK; -} - -/* Create resources that depend on the device. */ -static HRESULT -D3D11_CreateDeviceResources(SDL_Renderer * renderer) -{ - typedef HRESULT(WINAPI *PFN_CREATE_DXGI_FACTORY)(REFIID riid, void **ppFactory); - PFN_CREATE_DXGI_FACTORY CreateDXGIFactoryFunc; - D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata; - PFN_D3D11_CREATE_DEVICE D3D11CreateDeviceFunc; - ID3D11Device *d3dDevice = NULL; - ID3D11DeviceContext *d3dContext = NULL; - IDXGIDevice1 *dxgiDevice = NULL; - HRESULT result = S_OK; - UINT creationFlags; - - /* This array defines the set of DirectX hardware feature levels this app will support. - * Note the ordering should be preserved. - * Don't forget to declare your application's minimum required feature level in its - * description. All applications are assumed to support 9.1 unless otherwise stated. - */ - D3D_FEATURE_LEVEL featureLevels[] = - { - D3D_FEATURE_LEVEL_11_1, - D3D_FEATURE_LEVEL_11_0, - D3D_FEATURE_LEVEL_10_1, - D3D_FEATURE_LEVEL_10_0, - D3D_FEATURE_LEVEL_9_3, - D3D_FEATURE_LEVEL_9_2, - D3D_FEATURE_LEVEL_9_1 - }; - - /* Declare how the input layout for SDL's vertex shader will be setup: */ - const D3D11_INPUT_ELEMENT_DESC vertexDesc[] = - { - { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - }; - - D3D11_BUFFER_DESC constantBufferDesc; - D3D11_SAMPLER_DESC samplerDesc; - D3D11_RASTERIZER_DESC rasterDesc; - -#ifdef __WINRT__ - CreateDXGIFactoryFunc = CreateDXGIFactory1; - D3D11CreateDeviceFunc = D3D11CreateDevice; -#else - data->hDXGIMod = SDL_LoadObject("dxgi.dll"); - if (!data->hDXGIMod) { - result = E_FAIL; - goto done; - } - - CreateDXGIFactoryFunc = (PFN_CREATE_DXGI_FACTORY)SDL_LoadFunction(data->hDXGIMod, "CreateDXGIFactory"); - if (!CreateDXGIFactoryFunc) { - result = E_FAIL; - goto done; - } - - data->hD3D11Mod = SDL_LoadObject("d3d11.dll"); - if (!data->hD3D11Mod) { - result = E_FAIL; - goto done; - } - - D3D11CreateDeviceFunc = (PFN_D3D11_CREATE_DEVICE)SDL_LoadFunction(data->hD3D11Mod, "D3D11CreateDevice"); - if (!D3D11CreateDeviceFunc) { - result = E_FAIL; - goto done; - } -#endif /* __WINRT__ */ - - result = CreateDXGIFactoryFunc(&SDL_IID_IDXGIFactory2, (void **)&data->dxgiFactory); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("CreateDXGIFactory"), result); - goto done; - } - - /* FIXME: Should we use the default adapter? */ - result = IDXGIFactory2_EnumAdapters(data->dxgiFactory, 0, &data->dxgiAdapter); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("D3D11CreateDevice"), result); - goto done; - } - - /* This flag adds support for surfaces with a different color channel ordering - * than the API default. It is required for compatibility with Direct2D. - */ - creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT; - - /* Make sure Direct3D's debugging feature gets used, if the app requests it. */ - if (SDL_GetHintBoolean(SDL_HINT_RENDER_DIRECT3D11_DEBUG, SDL_FALSE)) { - creationFlags |= D3D11_CREATE_DEVICE_DEBUG; - } - - /* Create the Direct3D 11 API device object and a corresponding context. */ - result = D3D11CreateDeviceFunc( - data->dxgiAdapter, - D3D_DRIVER_TYPE_UNKNOWN, - NULL, - creationFlags, /* Set set debug and Direct2D compatibility flags. */ - featureLevels, /* List of feature levels this app can support. */ - SDL_arraysize(featureLevels), - D3D11_SDK_VERSION, /* Always set this to D3D11_SDK_VERSION for Windows Store apps. */ - &d3dDevice, /* Returns the Direct3D device created. */ - &data->featureLevel, /* Returns feature level of device created. */ - &d3dContext /* Returns the device immediate context. */ - ); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("D3D11CreateDevice"), result); - goto done; - } - - result = ID3D11Device_QueryInterface(d3dDevice, &SDL_IID_ID3D11Device1, (void **)&data->d3dDevice); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device to ID3D11Device1"), result); - goto done; - } - - result = ID3D11DeviceContext_QueryInterface(d3dContext, &SDL_IID_ID3D11DeviceContext1, (void **)&data->d3dContext); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11DeviceContext to ID3D11DeviceContext1"), result); - goto done; - } - - result = ID3D11Device_QueryInterface(d3dDevice, &SDL_IID_IDXGIDevice1, (void **)&dxgiDevice); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device to IDXGIDevice1"), result); - goto done; - } - - /* Ensure that DXGI does not queue more than one frame at a time. This both reduces latency and - * ensures that the application will only render after each VSync, minimizing power consumption. - */ - result = IDXGIDevice1_SetMaximumFrameLatency(dxgiDevice, 1); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGIDevice1::SetMaximumFrameLatency"), result); - goto done; - } - - /* Make note of the maximum texture size - * Max texture sizes are documented on MSDN, at: - * http://msdn.microsoft.com/en-us/library/windows/apps/ff476876.aspx - */ - switch (data->featureLevel) { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - renderer->info.max_texture_width = renderer->info.max_texture_height = 16384; - break; - - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - renderer->info.max_texture_width = renderer->info.max_texture_height = 8192; - break; - - case D3D_FEATURE_LEVEL_9_3: - renderer->info.max_texture_width = renderer->info.max_texture_height = 4096; - break; - - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - renderer->info.max_texture_width = renderer->info.max_texture_height = 2048; - break; - - default: - SDL_SetError("%s, Unexpected feature level: %d", __FUNCTION__, data->featureLevel); - result = E_FAIL; - goto done; - } - - /* Load in SDL's one and only vertex shader: */ - result = ID3D11Device_CreateVertexShader(data->d3dDevice, - D3D11_VertexShader, - sizeof(D3D11_VertexShader), - NULL, - &data->vertexShader - ); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateVertexShader"), result); - goto done; - } - - /* Create an input layout for SDL's vertex shader: */ - result = ID3D11Device_CreateInputLayout(data->d3dDevice, - vertexDesc, - ARRAYSIZE(vertexDesc), - D3D11_VertexShader, - sizeof(D3D11_VertexShader), - &data->inputLayout - ); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateInputLayout"), result); - goto done; - } - - /* Load in SDL's pixel shaders */ - result = ID3D11Device_CreatePixelShader(data->d3dDevice, - D3D11_PixelShader_Colors, - sizeof(D3D11_PixelShader_Colors), - NULL, - &data->colorPixelShader - ); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreatePixelShader ['color' shader]"), result); - goto done; - } - - result = ID3D11Device_CreatePixelShader(data->d3dDevice, - D3D11_PixelShader_Textures, - sizeof(D3D11_PixelShader_Textures), - NULL, - &data->texturePixelShader - ); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreatePixelShader ['textures' shader]"), result); - goto done; - } - - result = ID3D11Device_CreatePixelShader(data->d3dDevice, - D3D11_PixelShader_YUV, - sizeof(D3D11_PixelShader_YUV), - NULL, - &data->yuvPixelShader - ); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreatePixelShader ['yuv' shader]"), result); - goto done; - } - - /* Setup space to hold vertex shader constants: */ - SDL_zero(constantBufferDesc); - constantBufferDesc.ByteWidth = sizeof(VertexShaderConstants); - constantBufferDesc.Usage = D3D11_USAGE_DEFAULT; - constantBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; - result = ID3D11Device_CreateBuffer(data->d3dDevice, - &constantBufferDesc, - NULL, - &data->vertexShaderConstants - ); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateBuffer [vertex shader constants]"), result); - goto done; - } - - /* Create samplers to use when drawing textures: */ - SDL_zero(samplerDesc); - samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; - samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; - samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; - samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; - samplerDesc.MipLODBias = 0.0f; - samplerDesc.MaxAnisotropy = 1; - samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS; - samplerDesc.MinLOD = 0.0f; - samplerDesc.MaxLOD = D3D11_FLOAT32_MAX; - result = ID3D11Device_CreateSamplerState(data->d3dDevice, - &samplerDesc, - &data->nearestPixelSampler - ); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateSamplerState [nearest-pixel filter]"), result); - goto done; - } - - samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; - result = ID3D11Device_CreateSamplerState(data->d3dDevice, - &samplerDesc, - &data->linearSampler - ); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateSamplerState [linear filter]"), result); - goto done; - } - - /* Setup Direct3D rasterizer states */ - SDL_zero(rasterDesc); - rasterDesc.AntialiasedLineEnable = FALSE; - rasterDesc.CullMode = D3D11_CULL_NONE; - rasterDesc.DepthBias = 0; - rasterDesc.DepthBiasClamp = 0.0f; - rasterDesc.DepthClipEnable = TRUE; - rasterDesc.FillMode = D3D11_FILL_SOLID; - rasterDesc.FrontCounterClockwise = FALSE; - rasterDesc.MultisampleEnable = FALSE; - rasterDesc.ScissorEnable = FALSE; - rasterDesc.SlopeScaledDepthBias = 0.0f; - result = ID3D11Device_CreateRasterizerState(data->d3dDevice, &rasterDesc, &data->mainRasterizer); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateRasterizerState [main rasterizer]"), result); - goto done; - } - - rasterDesc.ScissorEnable = TRUE; - result = ID3D11Device_CreateRasterizerState(data->d3dDevice, &rasterDesc, &data->clippedRasterizer); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateRasterizerState [clipped rasterizer]"), result); - goto done; - } - - /* Create blending states: */ - result = D3D11_CreateBlendMode( - renderer, - TRUE, - D3D11_BLEND_SRC_ALPHA, /* srcBlend */ - D3D11_BLEND_INV_SRC_ALPHA, /* destBlend */ - D3D11_BLEND_ONE, /* srcBlendAlpha */ - D3D11_BLEND_INV_SRC_ALPHA, /* destBlendAlpha */ - &data->blendModeBlend); - if (FAILED(result)) { - /* D3D11_CreateBlendMode will set the SDL error, if it fails */ - goto done; - } - - result = D3D11_CreateBlendMode( - renderer, - TRUE, - D3D11_BLEND_SRC_ALPHA, /* srcBlend */ - D3D11_BLEND_ONE, /* destBlend */ - D3D11_BLEND_ZERO, /* srcBlendAlpha */ - D3D11_BLEND_ONE, /* destBlendAlpha */ - &data->blendModeAdd); - if (FAILED(result)) { - /* D3D11_CreateBlendMode will set the SDL error, if it fails */ - goto done; - } - - result = D3D11_CreateBlendMode( - renderer, - TRUE, - D3D11_BLEND_ZERO, /* srcBlend */ - D3D11_BLEND_SRC_COLOR, /* destBlend */ - D3D11_BLEND_ZERO, /* srcBlendAlpha */ - D3D11_BLEND_ONE, /* destBlendAlpha */ - &data->blendModeMod); - if (FAILED(result)) { - /* D3D11_CreateBlendMode will set the SDL error, if it fails */ - goto done; - } - - /* Setup render state that doesn't change */ - ID3D11DeviceContext_IASetInputLayout(data->d3dContext, data->inputLayout); - ID3D11DeviceContext_VSSetShader(data->d3dContext, data->vertexShader, NULL, 0); - ID3D11DeviceContext_VSSetConstantBuffers(data->d3dContext, 0, 1, &data->vertexShaderConstants); - -done: - SAFE_RELEASE(d3dDevice); - SAFE_RELEASE(d3dContext); - SAFE_RELEASE(dxgiDevice); - return result; -} - -#ifdef __WIN32__ - -static DXGI_MODE_ROTATION -D3D11_GetCurrentRotation() -{ - /* FIXME */ - return DXGI_MODE_ROTATION_IDENTITY; -} - -#endif /* __WIN32__ */ - -static BOOL -D3D11_IsDisplayRotated90Degrees(DXGI_MODE_ROTATION rotation) -{ - switch (rotation) { - case DXGI_MODE_ROTATION_ROTATE90: - case DXGI_MODE_ROTATION_ROTATE270: - return TRUE; - default: - return FALSE; - } -} - -static int -D3D11_GetRotationForCurrentRenderTarget(SDL_Renderer * renderer) -{ - D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata; - if (data->currentOffscreenRenderTargetView) { - return DXGI_MODE_ROTATION_IDENTITY; - } else { - return data->rotation; - } -} - -static int -D3D11_GetViewportAlignedD3DRect(SDL_Renderer * renderer, const SDL_Rect * sdlRect, D3D11_RECT * outRect, BOOL includeViewportOffset) -{ - const int rotation = D3D11_GetRotationForCurrentRenderTarget(renderer); - switch (rotation) { - case DXGI_MODE_ROTATION_IDENTITY: - outRect->left = sdlRect->x; - outRect->right = sdlRect->x + sdlRect->w; - outRect->top = sdlRect->y; - outRect->bottom = sdlRect->y + sdlRect->h; - if (includeViewportOffset) { - outRect->left += renderer->viewport.x; - outRect->right += renderer->viewport.x; - outRect->top += renderer->viewport.y; - outRect->bottom += renderer->viewport.y; - } - break; - case DXGI_MODE_ROTATION_ROTATE270: - outRect->left = sdlRect->y; - outRect->right = sdlRect->y + sdlRect->h; - outRect->top = renderer->viewport.w - sdlRect->x - sdlRect->w; - outRect->bottom = renderer->viewport.w - sdlRect->x; - break; - case DXGI_MODE_ROTATION_ROTATE180: - outRect->left = renderer->viewport.w - sdlRect->x - sdlRect->w; - outRect->right = renderer->viewport.w - sdlRect->x; - outRect->top = renderer->viewport.h - sdlRect->y - sdlRect->h; - outRect->bottom = renderer->viewport.h - sdlRect->y; - break; - case DXGI_MODE_ROTATION_ROTATE90: - outRect->left = renderer->viewport.h - sdlRect->y - sdlRect->h; - outRect->right = renderer->viewport.h - sdlRect->y; - outRect->top = sdlRect->x; - outRect->bottom = sdlRect->x + sdlRect->h; - break; - default: - return SDL_SetError("The physical display is in an unknown or unsupported rotation"); - } - return 0; -} - -static HRESULT -D3D11_CreateSwapChain(SDL_Renderer * renderer, int w, int h) -{ - D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata; -#ifdef __WINRT__ - IUnknown *coreWindow = D3D11_GetCoreWindowFromSDLRenderer(renderer); - const BOOL usingXAML = (coreWindow == NULL); -#else - IUnknown *coreWindow = NULL; - const BOOL usingXAML = FALSE; -#endif - HRESULT result = S_OK; - - /* Create a swap chain using the same adapter as the existing Direct3D device. */ - DXGI_SWAP_CHAIN_DESC1 swapChainDesc; - SDL_zero(swapChainDesc); - swapChainDesc.Width = w; - swapChainDesc.Height = h; - swapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; /* This is the most common swap chain format. */ - swapChainDesc.Stereo = FALSE; - swapChainDesc.SampleDesc.Count = 1; /* Don't use multi-sampling. */ - swapChainDesc.SampleDesc.Quality = 0; - swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; - swapChainDesc.BufferCount = 2; /* Use double-buffering to minimize latency. */ -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP - swapChainDesc.Scaling = DXGI_SCALING_STRETCH; /* On phone, only stretch and aspect-ratio stretch scaling are allowed. */ - swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; /* On phone, no swap effects are supported. */ - /* TODO, WinRT: see if Win 8.x DXGI_SWAP_CHAIN_DESC1 settings are available on Windows Phone 8.1, and if there's any advantage to having them on */ -#else - if (usingXAML) { - swapChainDesc.Scaling = DXGI_SCALING_STRETCH; - } else { - swapChainDesc.Scaling = DXGI_SCALING_NONE; - } - swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; /* All Windows Store apps must use this SwapEffect. */ -#endif - swapChainDesc.Flags = 0; - - if (coreWindow) { - result = IDXGIFactory2_CreateSwapChainForCoreWindow(data->dxgiFactory, - (IUnknown *)data->d3dDevice, - coreWindow, - &swapChainDesc, - NULL, /* Allow on all displays. */ - &data->swapChain - ); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGIFactory2::CreateSwapChainForCoreWindow"), result); - goto done; - } - } else if (usingXAML) { - result = IDXGIFactory2_CreateSwapChainForComposition(data->dxgiFactory, - (IUnknown *)data->d3dDevice, - &swapChainDesc, - NULL, - &data->swapChain); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGIFactory2::CreateSwapChainForComposition"), result); - goto done; - } - -#if WINAPI_FAMILY == WINAPI_FAMILY_APP - result = ISwapChainBackgroundPanelNative_SetSwapChain(WINRT_GlobalSwapChainBackgroundPanelNative, (IDXGISwapChain *) data->swapChain); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ISwapChainBackgroundPanelNative::SetSwapChain"), result); - goto done; - } -#else - SDL_SetError(SDL_COMPOSE_ERROR("XAML support is not yet available for Windows Phone")); - result = E_FAIL; - goto done; -#endif - } else { -#ifdef __WIN32__ - SDL_SysWMinfo windowinfo; - SDL_VERSION(&windowinfo.version); - SDL_GetWindowWMInfo(renderer->window, &windowinfo); - - result = IDXGIFactory2_CreateSwapChainForHwnd(data->dxgiFactory, - (IUnknown *)data->d3dDevice, - windowinfo.info.win.window, - &swapChainDesc, - NULL, - NULL, /* Allow on all displays. */ - &data->swapChain - ); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGIFactory2::CreateSwapChainForHwnd"), result); - goto done; - } - - IDXGIFactory_MakeWindowAssociation(data->dxgiFactory, windowinfo.info.win.window, DXGI_MWA_NO_WINDOW_CHANGES); -#else - SDL_SetError(__FUNCTION__", Unable to find something to attach a swap chain to"); - goto done; -#endif /* ifdef __WIN32__ / else */ - } - data->swapEffect = swapChainDesc.SwapEffect; - -done: - SAFE_RELEASE(coreWindow); - return result; -} - - -/* Initialize all resources that change when the window's size changes. */ -static HRESULT -D3D11_CreateWindowSizeDependentResources(SDL_Renderer * renderer) -{ - D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata; - ID3D11Texture2D *backBuffer = NULL; - HRESULT result = S_OK; - int w, h; - - /* Release the previous render target view */ - D3D11_ReleaseMainRenderTargetView(renderer); - - /* The width and height of the swap chain must be based on the display's - * non-rotated size. - */ - SDL_GetWindowSize(renderer->window, &w, &h); - data->rotation = D3D11_GetCurrentRotation(); - /* SDL_Log("%s: windowSize={%d,%d}, orientation=%d\n", __FUNCTION__, w, h, (int)data->rotation); */ - if (D3D11_IsDisplayRotated90Degrees(data->rotation)) { - int tmp = w; - w = h; - h = tmp; - } - - if (data->swapChain) { - /* IDXGISwapChain::ResizeBuffers is not available on Windows Phone 8. */ -#if !defined(__WINRT__) || (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP) - /* If the swap chain already exists, resize it. */ - result = IDXGISwapChain_ResizeBuffers(data->swapChain, - 0, - w, h, - DXGI_FORMAT_UNKNOWN, - 0 - ); - if (result == DXGI_ERROR_DEVICE_REMOVED) { - /* If the device was removed for any reason, a new device and swap chain will need to be created. */ - D3D11_HandleDeviceLost(renderer); - - /* Everything is set up now. Do not continue execution of this method. HandleDeviceLost will reenter this method - * and correctly set up the new device. - */ - goto done; - } else if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGISwapChain::ResizeBuffers"), result); - goto done; - } -#endif - } else { - result = D3D11_CreateSwapChain(renderer, w, h); - if (FAILED(result)) { - goto done; - } - } - -#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP - /* Set the proper rotation for the swap chain. - * - * To note, the call for this, IDXGISwapChain1::SetRotation, is not necessary - * on Windows Phone 8.0, nor is it supported there. - * - * IDXGISwapChain1::SetRotation does seem to be available on Windows Phone 8.1, - * however I've yet to find a way to make it work. It might have something to - * do with IDXGISwapChain::ResizeBuffers appearing to not being available on - * Windows Phone 8.1 (it wasn't on Windows Phone 8.0), but I'm not 100% sure of this. - * The call doesn't appear to be entirely necessary though, and is a performance-related - * call, at least according to the following page on MSDN: - * http://code.msdn.microsoft.com/windowsapps/DXGI-swap-chain-rotation-21d13d71 - * -- David L. - * - * TODO, WinRT: reexamine the docs for IDXGISwapChain1::SetRotation, see if might be available, usable, and prudent-to-call on WinPhone 8.1 - */ - if (data->swapEffect == DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL) { - result = IDXGISwapChain1_SetRotation(data->swapChain, data->rotation); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGISwapChain1::SetRotation"), result); - goto done; - } - } -#endif - - result = IDXGISwapChain_GetBuffer(data->swapChain, - 0, - &SDL_IID_ID3D11Texture2D, - (void **)&backBuffer - ); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGISwapChain::GetBuffer [back-buffer]"), result); - goto done; - } - - /* Create a render target view of the swap chain back buffer. */ - result = ID3D11Device_CreateRenderTargetView(data->d3dDevice, - (ID3D11Resource *)backBuffer, - NULL, - &data->mainRenderTargetView - ); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device::CreateRenderTargetView"), result); - goto done; - } - - if (D3D11_UpdateViewport(renderer) != 0) { - /* D3D11_UpdateViewport will set the SDL error if it fails. */ - result = E_FAIL; - goto done; - } - -done: - SAFE_RELEASE(backBuffer); - return result; -} - -/* This method is called when the window's size changes. */ -static HRESULT -D3D11_UpdateForWindowSizeChange(SDL_Renderer * renderer) -{ - return D3D11_CreateWindowSizeDependentResources(renderer); -} - -HRESULT -D3D11_HandleDeviceLost(SDL_Renderer * renderer) -{ - HRESULT result = S_OK; - - D3D11_ReleaseAll(renderer); - - result = D3D11_CreateDeviceResources(renderer); - if (FAILED(result)) { - /* D3D11_CreateDeviceResources will set the SDL error */ - return result; - } - - result = D3D11_UpdateForWindowSizeChange(renderer); - if (FAILED(result)) { - /* D3D11_UpdateForWindowSizeChange will set the SDL error */ - return result; - } - - /* Let the application know that the device has been reset */ - { - SDL_Event event; - event.type = SDL_RENDER_DEVICE_RESET; - SDL_PushEvent(&event); - } - - return S_OK; -} - -void -D3D11_Trim(SDL_Renderer * renderer) -{ -#ifdef __WINRT__ -#if NTDDI_VERSION > NTDDI_WIN8 - D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata; - HRESULT result = S_OK; - IDXGIDevice3 *dxgiDevice = NULL; - - result = ID3D11Device_QueryInterface(data->d3dDevice, &SDL_IID_IDXGIDevice3, &dxgiDevice); - if (FAILED(result)) { - //WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11Device to IDXGIDevice3", result); - return; - } - - IDXGIDevice3_Trim(dxgiDevice); - SAFE_RELEASE(dxgiDevice); -#endif -#endif -} - -static void -D3D11_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event) -{ - if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) { - D3D11_UpdateForWindowSizeChange(renderer); - } -} - -static D3D11_FILTER -GetScaleQuality(void) -{ - const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY); - if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) { - return D3D11_FILTER_MIN_MAG_MIP_POINT; - } else /* if (*hint == '1' || SDL_strcasecmp(hint, "linear") == 0) */ { - return D3D11_FILTER_MIN_MAG_MIP_LINEAR; - } -} - -static int -D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata; - D3D11_TextureData *textureData; - HRESULT result; - DXGI_FORMAT textureFormat = SDLPixelFormatToDXGIFormat(texture->format); - D3D11_TEXTURE2D_DESC textureDesc; - D3D11_SHADER_RESOURCE_VIEW_DESC resourceViewDesc; - - if (textureFormat == DXGI_FORMAT_UNKNOWN) { - return SDL_SetError("%s, An unsupported SDL pixel format (0x%x) was specified", - __FUNCTION__, texture->format); - } - - textureData = (D3D11_TextureData*) SDL_calloc(1, sizeof(*textureData)); - if (!textureData) { - SDL_OutOfMemory(); - return -1; - } - textureData->scaleMode = GetScaleQuality(); - - texture->driverdata = textureData; - - SDL_zero(textureDesc); - textureDesc.Width = texture->w; - textureDesc.Height = texture->h; - textureDesc.MipLevels = 1; - textureDesc.ArraySize = 1; - textureDesc.Format = textureFormat; - textureDesc.SampleDesc.Count = 1; - textureDesc.SampleDesc.Quality = 0; - textureDesc.MiscFlags = 0; - - if (texture->access == SDL_TEXTUREACCESS_STREAMING) { - textureDesc.Usage = D3D11_USAGE_DYNAMIC; - textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - } else { - textureDesc.Usage = D3D11_USAGE_DEFAULT; - textureDesc.CPUAccessFlags = 0; - } - - if (texture->access == SDL_TEXTUREACCESS_TARGET) { - textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET; - } else { - textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE; - } - - result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice, - &textureDesc, - NULL, - &textureData->mainTexture - ); - if (FAILED(result)) { - D3D11_DestroyTexture(renderer, texture); - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D"), result); - return -1; - } - - if (texture->format == SDL_PIXELFORMAT_YV12 || - texture->format == SDL_PIXELFORMAT_IYUV) { - textureData->yuv = SDL_TRUE; - - textureDesc.Width /= 2; - textureDesc.Height /= 2; - - result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice, - &textureDesc, - NULL, - &textureData->mainTextureU - ); - if (FAILED(result)) { - D3D11_DestroyTexture(renderer, texture); - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D"), result); - return -1; - } - - result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice, - &textureDesc, - NULL, - &textureData->mainTextureV - ); - if (FAILED(result)) { - D3D11_DestroyTexture(renderer, texture); - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D"), result); - return -1; - } - } - - resourceViewDesc.Format = textureDesc.Format; - resourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; - resourceViewDesc.Texture2D.MostDetailedMip = 0; - resourceViewDesc.Texture2D.MipLevels = textureDesc.MipLevels; - result = ID3D11Device_CreateShaderResourceView(rendererData->d3dDevice, - (ID3D11Resource *)textureData->mainTexture, - &resourceViewDesc, - &textureData->mainTextureResourceView - ); - if (FAILED(result)) { - D3D11_DestroyTexture(renderer, texture); - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateShaderResourceView"), result); - return -1; - } - - if (textureData->yuv) { - result = ID3D11Device_CreateShaderResourceView(rendererData->d3dDevice, - (ID3D11Resource *)textureData->mainTextureU, - &resourceViewDesc, - &textureData->mainTextureResourceViewU - ); - if (FAILED(result)) { - D3D11_DestroyTexture(renderer, texture); - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateShaderResourceView"), result); - return -1; - } - result = ID3D11Device_CreateShaderResourceView(rendererData->d3dDevice, - (ID3D11Resource *)textureData->mainTextureV, - &resourceViewDesc, - &textureData->mainTextureResourceViewV - ); - if (FAILED(result)) { - D3D11_DestroyTexture(renderer, texture); - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateShaderResourceView"), result); - return -1; - } - } - - if (texture->access & SDL_TEXTUREACCESS_TARGET) { - D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc; - renderTargetViewDesc.Format = textureDesc.Format; - renderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; - renderTargetViewDesc.Texture2D.MipSlice = 0; - - result = ID3D11Device_CreateRenderTargetView(rendererData->d3dDevice, - (ID3D11Resource *)textureData->mainTexture, - &renderTargetViewDesc, - &textureData->mainTextureRenderTargetView); - if (FAILED(result)) { - D3D11_DestroyTexture(renderer, texture); - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateRenderTargetView"), result); - return -1; - } - } - - return 0; -} - -static void -D3D11_DestroyTexture(SDL_Renderer * renderer, - SDL_Texture * texture) -{ - D3D11_TextureData *data = (D3D11_TextureData *)texture->driverdata; - - if (!data) { - return; - } - - SAFE_RELEASE(data->mainTexture); - SAFE_RELEASE(data->mainTextureResourceView); - SAFE_RELEASE(data->mainTextureRenderTargetView); - SAFE_RELEASE(data->stagingTexture); - SAFE_RELEASE(data->mainTextureU); - SAFE_RELEASE(data->mainTextureResourceViewU); - SAFE_RELEASE(data->mainTextureV); - SAFE_RELEASE(data->mainTextureResourceViewV); - SDL_free(data->pixels); - SDL_free(data); - texture->driverdata = NULL; -} - -static int -D3D11_UpdateTextureInternal(D3D11_RenderData *rendererData, ID3D11Texture2D *texture, Uint32 format, int x, int y, int w, int h, const void *pixels, int pitch) -{ - ID3D11Texture2D *stagingTexture; - const Uint8 *src; - Uint8 *dst; - int row; - UINT length; - HRESULT result; - D3D11_TEXTURE2D_DESC stagingTextureDesc; - D3D11_MAPPED_SUBRESOURCE textureMemory; - - /* Create a 'staging' texture, which will be used to write to a portion of the main texture. */ - ID3D11Texture2D_GetDesc(texture, &stagingTextureDesc); - stagingTextureDesc.Width = w; - stagingTextureDesc.Height = h; - stagingTextureDesc.BindFlags = 0; - stagingTextureDesc.MiscFlags = 0; - stagingTextureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - stagingTextureDesc.Usage = D3D11_USAGE_STAGING; - result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice, - &stagingTextureDesc, - NULL, - &stagingTexture); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D [create staging texture]"), result); - return -1; - } - - /* Get a write-only pointer to data in the staging texture: */ - result = ID3D11DeviceContext_Map(rendererData->d3dContext, - (ID3D11Resource *)stagingTexture, - 0, - D3D11_MAP_WRITE, - 0, - &textureMemory - ); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11DeviceContext1::Map [map staging texture]"), result); - SAFE_RELEASE(stagingTexture); - return -1; - } - - src = (const Uint8 *)pixels; - dst = textureMemory.pData; - length = w * SDL_BYTESPERPIXEL(format); - if (length == pitch && length == textureMemory.RowPitch) { - SDL_memcpy(dst, src, length*h); - } else { - if (length > (UINT)pitch) { - length = pitch; - } - if (length > textureMemory.RowPitch) { - length = textureMemory.RowPitch; - } - for (row = 0; row < h; ++row) { - SDL_memcpy(dst, src, length); - src += pitch; - dst += textureMemory.RowPitch; - } - } - - /* Commit the pixel buffer's changes back to the staging texture: */ - ID3D11DeviceContext_Unmap(rendererData->d3dContext, - (ID3D11Resource *)stagingTexture, - 0); - - /* Copy the staging texture's contents back to the texture: */ - ID3D11DeviceContext_CopySubresourceRegion(rendererData->d3dContext, - (ID3D11Resource *)texture, - 0, - x, - y, - 0, - (ID3D11Resource *)stagingTexture, - 0, - NULL); - - SAFE_RELEASE(stagingTexture); - - return 0; -} - -static int -D3D11_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, const void * srcPixels, - int srcPitch) -{ - D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->driverdata; - D3D11_TextureData *textureData = (D3D11_TextureData *)texture->driverdata; - - if (!textureData) { - SDL_SetError("Texture is not currently available"); - return -1; - } - - if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTexture, texture->format, rect->x, rect->y, rect->w, rect->h, srcPixels, srcPitch) < 0) { - return -1; - } - - if (textureData->yuv) { - /* Skip to the correct offset into the next texture */ - srcPixels = (const void*)((const Uint8*)srcPixels + rect->h * srcPitch); - - if (D3D11_UpdateTextureInternal(rendererData, texture->format == SDL_PIXELFORMAT_YV12 ? textureData->mainTextureV : textureData->mainTextureU, texture->format, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, srcPixels, srcPitch / 2) < 0) { - return -1; - } - - /* Skip to the correct offset into the next texture */ - srcPixels = (const void*)((const Uint8*)srcPixels + (rect->h * srcPitch) / 4); - if (D3D11_UpdateTextureInternal(rendererData, texture->format == SDL_PIXELFORMAT_YV12 ? textureData->mainTextureU : textureData->mainTextureV, texture->format, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, srcPixels, srcPitch / 2) < 0) { - return -1; - } - } - return 0; -} - -static int -D3D11_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, - const Uint8 *Yplane, int Ypitch, - const Uint8 *Uplane, int Upitch, - const Uint8 *Vplane, int Vpitch) -{ - D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->driverdata; - D3D11_TextureData *textureData = (D3D11_TextureData *)texture->driverdata; - - if (!textureData) { - SDL_SetError("Texture is not currently available"); - return -1; - } - - if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTexture, texture->format, rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch) < 0) { - return -1; - } - if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTextureU, texture->format, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Uplane, Upitch) < 0) { - return -1; - } - if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTextureV, texture->format, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Vplane, Vpitch) < 0) { - return -1; - } - return 0; -} - -static int -D3D11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, void **pixels, int *pitch) -{ - D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata; - D3D11_TextureData *textureData = (D3D11_TextureData *) texture->driverdata; - HRESULT result = S_OK; - D3D11_TEXTURE2D_DESC stagingTextureDesc; - D3D11_MAPPED_SUBRESOURCE textureMemory; - - if (!textureData) { - SDL_SetError("Texture is not currently available"); - return -1; - } - - if (textureData->yuv) { - /* It's more efficient to upload directly... */ - if (!textureData->pixels) { - textureData->pitch = texture->w; - textureData->pixels = (Uint8 *)SDL_malloc((texture->h * textureData->pitch * 3) / 2); - if (!textureData->pixels) { - return SDL_OutOfMemory(); - } - } - textureData->locked_rect = *rect; - *pixels = - (void *)((Uint8 *)textureData->pixels + rect->y * textureData->pitch + - rect->x * SDL_BYTESPERPIXEL(texture->format)); - *pitch = textureData->pitch; - return 0; - } - - if (textureData->stagingTexture) { - return SDL_SetError("texture is already locked"); - } - - /* Create a 'staging' texture, which will be used to write to a portion - * of the main texture. This is necessary, as Direct3D 11.1 does not - * have the ability to write a CPU-bound pixel buffer to a rectangular - * subrect of a texture. Direct3D 11.1 can, however, write a pixel - * buffer to an entire texture, hence the use of a staging texture. - * - * TODO, WinRT: consider avoiding the use of a staging texture in D3D11_LockTexture if/when the entire texture is being updated - */ - ID3D11Texture2D_GetDesc(textureData->mainTexture, &stagingTextureDesc); - stagingTextureDesc.Width = rect->w; - stagingTextureDesc.Height = rect->h; - stagingTextureDesc.BindFlags = 0; - stagingTextureDesc.MiscFlags = 0; - stagingTextureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - stagingTextureDesc.Usage = D3D11_USAGE_STAGING; - result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice, - &stagingTextureDesc, - NULL, - &textureData->stagingTexture); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D [create staging texture]"), result); - return -1; - } - - /* Get a write-only pointer to data in the staging texture: */ - result = ID3D11DeviceContext_Map(rendererData->d3dContext, - (ID3D11Resource *)textureData->stagingTexture, - 0, - D3D11_MAP_WRITE, - 0, - &textureMemory - ); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11DeviceContext1::Map [map staging texture]"), result); - SAFE_RELEASE(textureData->stagingTexture); - return -1; - } - - /* Make note of where the staging texture will be written to - * (on a call to SDL_UnlockTexture): - */ - textureData->lockedTexturePositionX = rect->x; - textureData->lockedTexturePositionY = rect->y; - - /* Make sure the caller has information on the texture's pixel buffer, - * then return: - */ - *pixels = textureMemory.pData; - *pitch = textureMemory.RowPitch; - return 0; -} - -static void -D3D11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata; - D3D11_TextureData *textureData = (D3D11_TextureData *) texture->driverdata; - - if (!textureData) { - return; - } - - if (textureData->yuv) { - const SDL_Rect *rect = &textureData->locked_rect; - void *pixels = - (void *) ((Uint8 *) textureData->pixels + rect->y * textureData->pitch + - rect->x * SDL_BYTESPERPIXEL(texture->format)); - D3D11_UpdateTexture(renderer, texture, rect, pixels, textureData->pitch); - return; - } - - /* Commit the pixel buffer's changes back to the staging texture: */ - ID3D11DeviceContext_Unmap(rendererData->d3dContext, - (ID3D11Resource *)textureData->stagingTexture, - 0); - - /* Copy the staging texture's contents back to the main texture: */ - ID3D11DeviceContext_CopySubresourceRegion(rendererData->d3dContext, - (ID3D11Resource *)textureData->mainTexture, - 0, - textureData->lockedTexturePositionX, - textureData->lockedTexturePositionY, - 0, - (ID3D11Resource *)textureData->stagingTexture, - 0, - NULL); - - SAFE_RELEASE(textureData->stagingTexture); -} - -static int -D3D11_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture) -{ - D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata; - D3D11_TextureData *textureData = NULL; - - if (texture == NULL) { - rendererData->currentOffscreenRenderTargetView = NULL; - return 0; - } - - textureData = (D3D11_TextureData *) texture->driverdata; - - if (!textureData->mainTextureRenderTargetView) { - return SDL_SetError("specified texture is not a render target"); - } - - rendererData->currentOffscreenRenderTargetView = textureData->mainTextureRenderTargetView; - - return 0; -} - -static void -D3D11_SetModelMatrix(SDL_Renderer *renderer, const Float4X4 *matrix) -{ - D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata; - - if (matrix) { - data->vertexShaderConstantsData.model = *matrix; - } else { - data->vertexShaderConstantsData.model = MatrixIdentity(); - } - - ID3D11DeviceContext_UpdateSubresource(data->d3dContext, - (ID3D11Resource *)data->vertexShaderConstants, - 0, - NULL, - &data->vertexShaderConstantsData, - 0, - 0 - ); -} - -static int -D3D11_UpdateViewport(SDL_Renderer * renderer) -{ - D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata; - Float4X4 projection; - Float4X4 view; - SDL_FRect orientationAlignedViewport; - BOOL swapDimensions; - D3D11_VIEWPORT viewport; - const int rotation = D3D11_GetRotationForCurrentRenderTarget(renderer); - - if (renderer->viewport.w == 0 || renderer->viewport.h == 0) { - /* If the viewport is empty, assume that it is because - * SDL_CreateRenderer is calling it, and will call it again later - * with a non-empty viewport. - */ - /* SDL_Log("%s, no viewport was set!\n", __FUNCTION__); */ - return 0; - } - - /* Make sure the SDL viewport gets rotated to that of the physical display's rotation. - * Keep in mind here that the Y-axis will be been inverted (from Direct3D's - * default coordinate system) so rotations will be done in the opposite - * direction of the DXGI_MODE_ROTATION enumeration. - */ - switch (rotation) { - case DXGI_MODE_ROTATION_IDENTITY: - projection = MatrixIdentity(); - break; - case DXGI_MODE_ROTATION_ROTATE270: - projection = MatrixRotationZ(SDL_static_cast(float, M_PI * 0.5f)); - break; - case DXGI_MODE_ROTATION_ROTATE180: - projection = MatrixRotationZ(SDL_static_cast(float, M_PI)); - break; - case DXGI_MODE_ROTATION_ROTATE90: - projection = MatrixRotationZ(SDL_static_cast(float, -M_PI * 0.5f)); - break; - default: - return SDL_SetError("An unknown DisplayOrientation is being used"); - } - - /* Update the view matrix */ - view.m[0][0] = 2.0f / renderer->viewport.w; - view.m[0][1] = 0.0f; - view.m[0][2] = 0.0f; - view.m[0][3] = 0.0f; - view.m[1][0] = 0.0f; - view.m[1][1] = -2.0f / renderer->viewport.h; - view.m[1][2] = 0.0f; - view.m[1][3] = 0.0f; - view.m[2][0] = 0.0f; - view.m[2][1] = 0.0f; - view.m[2][2] = 1.0f; - view.m[2][3] = 0.0f; - view.m[3][0] = -1.0f; - view.m[3][1] = 1.0f; - view.m[3][2] = 0.0f; - view.m[3][3] = 1.0f; - - /* Combine the projection + view matrix together now, as both only get - * set here (as of this writing, on Dec 26, 2013). When done, store it - * for eventual transfer to the GPU. - */ - data->vertexShaderConstantsData.projectionAndView = MatrixMultiply( - view, - projection); - - /* Reset the model matrix */ - D3D11_SetModelMatrix(renderer, NULL); - - /* Update the Direct3D viewport, which seems to be aligned to the - * swap buffer's coordinate space, which is always in either - * a landscape mode, for all Windows 8/RT devices, or a portrait mode, - * for Windows Phone devices. - */ - swapDimensions = D3D11_IsDisplayRotated90Degrees(rotation); - if (swapDimensions) { - orientationAlignedViewport.x = (float) renderer->viewport.y; - orientationAlignedViewport.y = (float) renderer->viewport.x; - orientationAlignedViewport.w = (float) renderer->viewport.h; - orientationAlignedViewport.h = (float) renderer->viewport.w; - } else { - orientationAlignedViewport.x = (float) renderer->viewport.x; - orientationAlignedViewport.y = (float) renderer->viewport.y; - orientationAlignedViewport.w = (float) renderer->viewport.w; - orientationAlignedViewport.h = (float) renderer->viewport.h; - } - /* TODO, WinRT: get custom viewports working with non-Landscape modes (Portrait, PortraitFlipped, and LandscapeFlipped) */ - - viewport.TopLeftX = orientationAlignedViewport.x; - viewport.TopLeftY = orientationAlignedViewport.y; - viewport.Width = orientationAlignedViewport.w; - viewport.Height = orientationAlignedViewport.h; - viewport.MinDepth = 0.0f; - viewport.MaxDepth = 1.0f; - /* SDL_Log("%s: D3D viewport = {%f,%f,%f,%f}\n", __FUNCTION__, viewport.TopLeftX, viewport.TopLeftY, viewport.Width, viewport.Height); */ - ID3D11DeviceContext_RSSetViewports(data->d3dContext, 1, &viewport); - - return 0; -} - -static int -D3D11_UpdateClipRect(SDL_Renderer * renderer) -{ - D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata; - - if (!renderer->clipping_enabled) { - ID3D11DeviceContext_RSSetScissorRects(data->d3dContext, 0, NULL); - } else { - D3D11_RECT scissorRect; - if (D3D11_GetViewportAlignedD3DRect(renderer, &renderer->clip_rect, &scissorRect, TRUE) != 0) { - /* D3D11_GetViewportAlignedD3DRect will have set the SDL error */ - return -1; - } - ID3D11DeviceContext_RSSetScissorRects(data->d3dContext, 1, &scissorRect); - } - - return 0; -} - -static void -D3D11_ReleaseMainRenderTargetView(SDL_Renderer * renderer) -{ - D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata; - ID3D11DeviceContext_OMSetRenderTargets(data->d3dContext, 0, NULL, NULL); - SAFE_RELEASE(data->mainRenderTargetView); -} - -static ID3D11RenderTargetView * -D3D11_GetCurrentRenderTargetView(SDL_Renderer * renderer) -{ - D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata; - if (data->currentOffscreenRenderTargetView) { - return data->currentOffscreenRenderTargetView; - } else { - return data->mainRenderTargetView; - } -} - -static int -D3D11_RenderClear(SDL_Renderer * renderer) -{ - D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata; - const float colorRGBA[] = { - (renderer->r / 255.0f), - (renderer->g / 255.0f), - (renderer->b / 255.0f), - (renderer->a / 255.0f) - }; - ID3D11DeviceContext_ClearRenderTargetView(data->d3dContext, - D3D11_GetCurrentRenderTargetView(renderer), - colorRGBA - ); - return 0; -} - -static int -D3D11_UpdateVertexBuffer(SDL_Renderer *renderer, - const void * vertexData, size_t dataSizeInBytes) -{ - D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata; - D3D11_BUFFER_DESC vertexBufferDesc; - HRESULT result = S_OK; - D3D11_SUBRESOURCE_DATA vertexBufferData; - const UINT stride = sizeof(VertexPositionColor); - const UINT offset = 0; - - if (rendererData->vertexBuffer) { - ID3D11Buffer_GetDesc(rendererData->vertexBuffer, &vertexBufferDesc); - } else { - SDL_zero(vertexBufferDesc); - } - - if (rendererData->vertexBuffer && vertexBufferDesc.ByteWidth >= dataSizeInBytes) { - D3D11_MAPPED_SUBRESOURCE mappedResource; - result = ID3D11DeviceContext_Map(rendererData->d3dContext, - (ID3D11Resource *)rendererData->vertexBuffer, - 0, - D3D11_MAP_WRITE_DISCARD, - 0, - &mappedResource - ); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11DeviceContext1::Map [vertex buffer]"), result); - return -1; - } - SDL_memcpy(mappedResource.pData, vertexData, dataSizeInBytes); - ID3D11DeviceContext_Unmap(rendererData->d3dContext, (ID3D11Resource *)rendererData->vertexBuffer, 0); - } else { - SAFE_RELEASE(rendererData->vertexBuffer); - - vertexBufferDesc.ByteWidth = (UINT) dataSizeInBytes; - vertexBufferDesc.Usage = D3D11_USAGE_DYNAMIC; - vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; - vertexBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - - SDL_zero(vertexBufferData); - vertexBufferData.pSysMem = vertexData; - vertexBufferData.SysMemPitch = 0; - vertexBufferData.SysMemSlicePitch = 0; - - result = ID3D11Device_CreateBuffer(rendererData->d3dDevice, - &vertexBufferDesc, - &vertexBufferData, - &rendererData->vertexBuffer - ); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateBuffer [vertex buffer]"), result); - return -1; - } - - ID3D11DeviceContext_IASetVertexBuffers(rendererData->d3dContext, - 0, - 1, - &rendererData->vertexBuffer, - &stride, - &offset - ); - } - - return 0; -} - -static void -D3D11_RenderStartDrawOp(SDL_Renderer * renderer) -{ - D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->driverdata; - ID3D11RasterizerState *rasterizerState; - ID3D11RenderTargetView *renderTargetView = D3D11_GetCurrentRenderTargetView(renderer); - if (renderTargetView != rendererData->currentRenderTargetView) { - ID3D11DeviceContext_OMSetRenderTargets(rendererData->d3dContext, - 1, - &renderTargetView, - NULL - ); - rendererData->currentRenderTargetView = renderTargetView; - } - - if (!renderer->clipping_enabled) { - rasterizerState = rendererData->mainRasterizer; - } else { - rasterizerState = rendererData->clippedRasterizer; - } - if (rasterizerState != rendererData->currentRasterizerState) { - ID3D11DeviceContext_RSSetState(rendererData->d3dContext, rasterizerState); - rendererData->currentRasterizerState = rasterizerState; - } -} - -static void -D3D11_RenderSetBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode) -{ - D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->driverdata; - ID3D11BlendState *blendState = NULL; - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - blendState = rendererData->blendModeBlend; - break; - case SDL_BLENDMODE_ADD: - blendState = rendererData->blendModeAdd; - break; - case SDL_BLENDMODE_MOD: - blendState = rendererData->blendModeMod; - break; - case SDL_BLENDMODE_NONE: - blendState = NULL; - break; - } - if (blendState != rendererData->currentBlendState) { - ID3D11DeviceContext_OMSetBlendState(rendererData->d3dContext, blendState, 0, 0xFFFFFFFF); - rendererData->currentBlendState = blendState; - } -} - -static void -D3D11_SetPixelShader(SDL_Renderer * renderer, - ID3D11PixelShader * shader, - int numShaderResources, - ID3D11ShaderResourceView ** shaderResources, - ID3D11SamplerState * sampler) -{ - D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata; - ID3D11ShaderResourceView *shaderResource; - if (shader != rendererData->currentShader) { - ID3D11DeviceContext_PSSetShader(rendererData->d3dContext, shader, NULL, 0); - rendererData->currentShader = shader; - } - if (numShaderResources > 0) { - shaderResource = shaderResources[0]; - } else { - shaderResource = NULL; - } - if (shaderResource != rendererData->currentShaderResource) { - ID3D11DeviceContext_PSSetShaderResources(rendererData->d3dContext, 0, numShaderResources, shaderResources); - rendererData->currentShaderResource = shaderResource; - } - if (sampler != rendererData->currentSampler) { - ID3D11DeviceContext_PSSetSamplers(rendererData->d3dContext, 0, 1, &sampler); - rendererData->currentSampler = sampler; - } -} - -static void -D3D11_RenderFinishDrawOp(SDL_Renderer * renderer, - D3D11_PRIMITIVE_TOPOLOGY primitiveTopology, - UINT vertexCount) -{ - D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata; - - ID3D11DeviceContext_IASetPrimitiveTopology(rendererData->d3dContext, primitiveTopology); - ID3D11DeviceContext_Draw(rendererData->d3dContext, vertexCount, 0); -} - -static int -D3D11_RenderDrawPoints(SDL_Renderer * renderer, - const SDL_FPoint * points, int count) -{ - D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata; - float r, g, b, a; - VertexPositionColor *vertices; - int i; - - r = (float)(renderer->r / 255.0f); - g = (float)(renderer->g / 255.0f); - b = (float)(renderer->b / 255.0f); - a = (float)(renderer->a / 255.0f); - - vertices = SDL_stack_alloc(VertexPositionColor, count); - for (i = 0; i < count; ++i) { - const VertexPositionColor v = { { points[i].x, points[i].y, 0.0f }, { 0.0f, 0.0f }, { r, g, b, a } }; - vertices[i] = v; - } - - D3D11_RenderStartDrawOp(renderer); - D3D11_RenderSetBlendMode(renderer, renderer->blendMode); - if (D3D11_UpdateVertexBuffer(renderer, vertices, (unsigned int)count * sizeof(VertexPositionColor)) != 0) { - SDL_stack_free(vertices); - return -1; - } - - D3D11_SetPixelShader( - renderer, - rendererData->colorPixelShader, - 0, - NULL, - NULL); - - D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST, count); - SDL_stack_free(vertices); - return 0; -} - -static int -D3D11_RenderDrawLines(SDL_Renderer * renderer, - const SDL_FPoint * points, int count) -{ - D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata; - float r, g, b, a; - VertexPositionColor *vertices; - int i; - - r = (float)(renderer->r / 255.0f); - g = (float)(renderer->g / 255.0f); - b = (float)(renderer->b / 255.0f); - a = (float)(renderer->a / 255.0f); - - vertices = SDL_stack_alloc(VertexPositionColor, count); - for (i = 0; i < count; ++i) { - const VertexPositionColor v = { { points[i].x, points[i].y, 0.0f }, { 0.0f, 0.0f }, { r, g, b, a } }; - vertices[i] = v; - } - - D3D11_RenderStartDrawOp(renderer); - D3D11_RenderSetBlendMode(renderer, renderer->blendMode); - if (D3D11_UpdateVertexBuffer(renderer, vertices, (unsigned int)count * sizeof(VertexPositionColor)) != 0) { - SDL_stack_free(vertices); - return -1; - } - - D3D11_SetPixelShader( - renderer, - rendererData->colorPixelShader, - 0, - NULL, - NULL); - - D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP, count); - SDL_stack_free(vertices); - return 0; -} - -static int -D3D11_RenderFillRects(SDL_Renderer * renderer, - const SDL_FRect * rects, int count) -{ - D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata; - float r, g, b, a; - int i; - - r = (float)(renderer->r / 255.0f); - g = (float)(renderer->g / 255.0f); - b = (float)(renderer->b / 255.0f); - a = (float)(renderer->a / 255.0f); - - for (i = 0; i < count; ++i) { - VertexPositionColor vertices[] = { - { { rects[i].x, rects[i].y, 0.0f }, { 0.0f, 0.0f}, {r, g, b, a} }, - { { rects[i].x, rects[i].y + rects[i].h, 0.0f }, { 0.0f, 0.0f }, { r, g, b, a } }, - { { rects[i].x + rects[i].w, rects[i].y, 0.0f }, { 0.0f, 0.0f }, { r, g, b, a } }, - { { rects[i].x + rects[i].w, rects[i].y + rects[i].h, 0.0f }, { 0.0f, 0.0f }, { r, g, b, a } }, - }; - - D3D11_RenderStartDrawOp(renderer); - D3D11_RenderSetBlendMode(renderer, renderer->blendMode); - if (D3D11_UpdateVertexBuffer(renderer, vertices, sizeof(vertices)) != 0) { - return -1; - } - - D3D11_SetPixelShader( - renderer, - rendererData->colorPixelShader, - 0, - NULL, - NULL); - - D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, SDL_arraysize(vertices)); - } - - return 0; -} - -static ID3D11SamplerState * -D3D11_RenderGetSampler(SDL_Renderer * renderer, SDL_Texture * texture) -{ - D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata; - D3D11_TextureData *textureData = (D3D11_TextureData *) texture->driverdata; - - switch (textureData->scaleMode) { - case D3D11_FILTER_MIN_MAG_MIP_POINT: - return rendererData->nearestPixelSampler; - case D3D11_FILTER_MIN_MAG_MIP_LINEAR: - return rendererData->linearSampler; - default: - return NULL; - } -} - -static int -D3D11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_FRect * dstrect) -{ - D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata; - D3D11_TextureData *textureData = (D3D11_TextureData *) texture->driverdata; - float minu, maxu, minv, maxv; - Float4 color; - VertexPositionColor vertices[4]; - ID3D11SamplerState *textureSampler; - - D3D11_RenderStartDrawOp(renderer); - D3D11_RenderSetBlendMode(renderer, texture->blendMode); - - minu = (float) srcrect->x / texture->w; - maxu = (float) (srcrect->x + srcrect->w) / texture->w; - minv = (float) srcrect->y / texture->h; - maxv = (float) (srcrect->y + srcrect->h) / texture->h; - - color.x = 1.0f; /* red */ - color.y = 1.0f; /* green */ - color.z = 1.0f; /* blue */ - color.w = 1.0f; /* alpha */ - if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) { - color.x = (float)(texture->r / 255.0f); /* red */ - color.y = (float)(texture->g / 255.0f); /* green */ - color.z = (float)(texture->b / 255.0f); /* blue */ - } - if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA) { - color.w = (float)(texture->a / 255.0f); /* alpha */ - } - - vertices[0].pos.x = dstrect->x; - vertices[0].pos.y = dstrect->y; - vertices[0].pos.z = 0.0f; - vertices[0].tex.x = minu; - vertices[0].tex.y = minv; - vertices[0].color = color; - - vertices[1].pos.x = dstrect->x; - vertices[1].pos.y = dstrect->y + dstrect->h; - vertices[1].pos.z = 0.0f; - vertices[1].tex.x = minu; - vertices[1].tex.y = maxv; - vertices[1].color = color; - - vertices[2].pos.x = dstrect->x + dstrect->w; - vertices[2].pos.y = dstrect->y; - vertices[2].pos.z = 0.0f; - vertices[2].tex.x = maxu; - vertices[2].tex.y = minv; - vertices[2].color = color; - - vertices[3].pos.x = dstrect->x + dstrect->w; - vertices[3].pos.y = dstrect->y + dstrect->h; - vertices[3].pos.z = 0.0f; - vertices[3].tex.x = maxu; - vertices[3].tex.y = maxv; - vertices[3].color = color; - - if (D3D11_UpdateVertexBuffer(renderer, vertices, sizeof(vertices)) != 0) { - return -1; - } - - textureSampler = D3D11_RenderGetSampler(renderer, texture); - if (textureData->yuv) { - ID3D11ShaderResourceView *shaderResources[] = { - textureData->mainTextureResourceView, - textureData->mainTextureResourceViewU, - textureData->mainTextureResourceViewV - }; - D3D11_SetPixelShader( - renderer, - rendererData->yuvPixelShader, - SDL_arraysize(shaderResources), - shaderResources, - textureSampler); - } else { - D3D11_SetPixelShader( - renderer, - rendererData->texturePixelShader, - 1, - &textureData->mainTextureResourceView, - textureSampler); - } - - D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, sizeof(vertices) / sizeof(VertexPositionColor)); - - return 0; -} - -static int -D3D11_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_FRect * dstrect, - const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip) -{ - D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata; - D3D11_TextureData *textureData = (D3D11_TextureData *) texture->driverdata; - float minu, maxu, minv, maxv; - Float4 color; - Float4X4 modelMatrix; - float minx, maxx, miny, maxy; - VertexPositionColor vertices[4]; - ID3D11SamplerState *textureSampler; - - D3D11_RenderStartDrawOp(renderer); - D3D11_RenderSetBlendMode(renderer, texture->blendMode); - - minu = (float) srcrect->x / texture->w; - maxu = (float) (srcrect->x + srcrect->w) / texture->w; - minv = (float) srcrect->y / texture->h; - maxv = (float) (srcrect->y + srcrect->h) / texture->h; - - color.x = 1.0f; /* red */ - color.y = 1.0f; /* green */ - color.z = 1.0f; /* blue */ - color.w = 1.0f; /* alpha */ - if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) { - color.x = (float)(texture->r / 255.0f); /* red */ - color.y = (float)(texture->g / 255.0f); /* green */ - color.z = (float)(texture->b / 255.0f); /* blue */ - } - if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA) { - color.w = (float)(texture->a / 255.0f); /* alpha */ - } - - if (flip & SDL_FLIP_HORIZONTAL) { - float tmp = maxu; - maxu = minu; - minu = tmp; - } - if (flip & SDL_FLIP_VERTICAL) { - float tmp = maxv; - maxv = minv; - minv = tmp; - } - - modelMatrix = MatrixMultiply( - MatrixRotationZ((float)(M_PI * (float) angle / 180.0f)), - MatrixTranslation(dstrect->x + center->x, dstrect->y + center->y, 0) - ); - D3D11_SetModelMatrix(renderer, &modelMatrix); - - minx = -center->x; - maxx = dstrect->w - center->x; - miny = -center->y; - maxy = dstrect->h - center->y; - - vertices[0].pos.x = minx; - vertices[0].pos.y = miny; - vertices[0].pos.z = 0.0f; - vertices[0].tex.x = minu; - vertices[0].tex.y = minv; - vertices[0].color = color; - - vertices[1].pos.x = minx; - vertices[1].pos.y = maxy; - vertices[1].pos.z = 0.0f; - vertices[1].tex.x = minu; - vertices[1].tex.y = maxv; - vertices[1].color = color; - - vertices[2].pos.x = maxx; - vertices[2].pos.y = miny; - vertices[2].pos.z = 0.0f; - vertices[2].tex.x = maxu; - vertices[2].tex.y = minv; - vertices[2].color = color; - - vertices[3].pos.x = maxx; - vertices[3].pos.y = maxy; - vertices[3].pos.z = 0.0f; - vertices[3].tex.x = maxu; - vertices[3].tex.y = maxv; - vertices[3].color = color; - - if (D3D11_UpdateVertexBuffer(renderer, vertices, sizeof(vertices)) != 0) { - return -1; - } - - textureSampler = D3D11_RenderGetSampler(renderer, texture); - if (textureData->yuv) { - ID3D11ShaderResourceView *shaderResources[] = { - textureData->mainTextureResourceView, - textureData->mainTextureResourceViewU, - textureData->mainTextureResourceViewV - }; - D3D11_SetPixelShader( - renderer, - rendererData->yuvPixelShader, - SDL_arraysize(shaderResources), - shaderResources, - textureSampler); - } else { - D3D11_SetPixelShader( - renderer, - rendererData->texturePixelShader, - 1, - &textureData->mainTextureResourceView, - textureSampler); - } - - D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, sizeof(vertices) / sizeof(VertexPositionColor)); - - D3D11_SetModelMatrix(renderer, NULL); - - return 0; -} - -static int -D3D11_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, - Uint32 format, void * pixels, int pitch) -{ - D3D11_RenderData * data = (D3D11_RenderData *) renderer->driverdata; - ID3D11Texture2D *backBuffer = NULL; - ID3D11Texture2D *stagingTexture = NULL; - HRESULT result; - int status = -1; - D3D11_TEXTURE2D_DESC stagingTextureDesc; - D3D11_RECT srcRect = {0, 0, 0, 0}; - D3D11_BOX srcBox; - D3D11_MAPPED_SUBRESOURCE textureMemory; - - /* Retrieve a pointer to the back buffer: */ - result = IDXGISwapChain_GetBuffer(data->swapChain, - 0, - &SDL_IID_ID3D11Texture2D, - (void **)&backBuffer - ); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGISwapChain1::GetBuffer [get back buffer]"), result); - goto done; - } - - /* Create a staging texture to copy the screen's data to: */ - ID3D11Texture2D_GetDesc(backBuffer, &stagingTextureDesc); - stagingTextureDesc.Width = rect->w; - stagingTextureDesc.Height = rect->h; - stagingTextureDesc.BindFlags = 0; - stagingTextureDesc.MiscFlags = 0; - stagingTextureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; - stagingTextureDesc.Usage = D3D11_USAGE_STAGING; - result = ID3D11Device_CreateTexture2D(data->d3dDevice, - &stagingTextureDesc, - NULL, - &stagingTexture); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D [create staging texture]"), result); - goto done; - } - - /* Copy the desired portion of the back buffer to the staging texture: */ - if (D3D11_GetViewportAlignedD3DRect(renderer, rect, &srcRect, FALSE) != 0) { - /* D3D11_GetViewportAlignedD3DRect will have set the SDL error */ - goto done; - } - - srcBox.left = srcRect.left; - srcBox.right = srcRect.right; - srcBox.top = srcRect.top; - srcBox.bottom = srcRect.bottom; - srcBox.front = 0; - srcBox.back = 1; - ID3D11DeviceContext_CopySubresourceRegion(data->d3dContext, - (ID3D11Resource *)stagingTexture, - 0, - 0, 0, 0, - (ID3D11Resource *)backBuffer, - 0, - &srcBox); - - /* Map the staging texture's data to CPU-accessible memory: */ - result = ID3D11DeviceContext_Map(data->d3dContext, - (ID3D11Resource *)stagingTexture, - 0, - D3D11_MAP_READ, - 0, - &textureMemory); - if (FAILED(result)) { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11DeviceContext1::Map [map staging texture]"), result); - goto done; - } - - /* Copy the data into the desired buffer, converting pixels to the - * desired format at the same time: - */ - if (SDL_ConvertPixels( - rect->w, rect->h, - D3D11_DXGIFormatToSDLPixelFormat(stagingTextureDesc.Format), - textureMemory.pData, - textureMemory.RowPitch, - format, - pixels, - pitch) != 0) { - /* When SDL_ConvertPixels fails, it'll have already set the format. - * Get the error message, and attach some extra data to it. - */ - char errorMessage[1024]; - SDL_snprintf(errorMessage, sizeof(errorMessage), "%s, Convert Pixels failed: %s", __FUNCTION__, SDL_GetError()); - SDL_SetError("%s", errorMessage); - goto done; - } - - /* Unmap the texture: */ - ID3D11DeviceContext_Unmap(data->d3dContext, - (ID3D11Resource *)stagingTexture, - 0); - - status = 0; - -done: - SAFE_RELEASE(backBuffer); - SAFE_RELEASE(stagingTexture); - return status; -} - -static void -D3D11_RenderPresent(SDL_Renderer * renderer) -{ - D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata; - UINT syncInterval; - UINT presentFlags; - HRESULT result; - DXGI_PRESENT_PARAMETERS parameters; - - SDL_zero(parameters); - -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP - syncInterval = 1; - presentFlags = 0; - result = IDXGISwapChain_Present(data->swapChain, syncInterval, presentFlags); -#else - if (renderer->info.flags & SDL_RENDERER_PRESENTVSYNC) { - syncInterval = 1; - presentFlags = 0; - } else { - syncInterval = 0; - presentFlags = DXGI_PRESENT_DO_NOT_WAIT; - } - - /* The application may optionally specify "dirty" or "scroll" - * rects to improve efficiency in certain scenarios. - * This option is not available on Windows Phone 8, to note. - */ - result = IDXGISwapChain1_Present1(data->swapChain, syncInterval, presentFlags, ¶meters); -#endif - - /* Discard the contents of the render target. - * This is a valid operation only when the existing contents will be entirely - * overwritten. If dirty or scroll rects are used, this call should be removed. - */ - ID3D11DeviceContext1_DiscardView(data->d3dContext, (ID3D11View*)data->mainRenderTargetView); - - /* When the present flips, it unbinds the current view, so bind it again on the next draw call */ - data->currentRenderTargetView = NULL; - - if (FAILED(result) && result != DXGI_ERROR_WAS_STILL_DRAWING) { - /* If the device was removed either by a disconnect or a driver upgrade, we - * must recreate all device resources. - * - * TODO, WinRT: consider throwing an exception if D3D11_RenderPresent fails, especially if there is a way to salvage debug info from users' machines - */ - if ( result == DXGI_ERROR_DEVICE_REMOVED ) { - D3D11_HandleDeviceLost(renderer); - } else if (result == DXGI_ERROR_INVALID_CALL) { - /* We probably went through a fullscreen <-> windowed transition */ - D3D11_CreateWindowSizeDependentResources(renderer); - } else { - WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGISwapChain::Present"), result); - } - } -} - -#endif /* SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/direct3d11/SDL_render_winrt.cpp b/3rdparty/SDL2/src/render/direct3d11/SDL_render_winrt.cpp deleted file mode 100644 index 99f2b4ea429..00000000000 --- a/3rdparty/SDL2/src/render/direct3d11/SDL_render_winrt.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../../SDL_internal.h" - -#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED - -#include "SDL_syswm.h" -#include "../../video/winrt/SDL_winrtvideo_cpp.h" -extern "C" { -#include "../SDL_sysrender.h" -} - -#include <windows.ui.core.h> -#include <windows.graphics.display.h> - -#if WINAPI_FAMILY == WINAPI_FAMILY_APP -#include <windows.ui.xaml.media.dxinterop.h> -#endif - -using namespace Windows::UI::Core; -using namespace Windows::Graphics::Display; - -#include <DXGI.h> - -#include "SDL_render_winrt.h" - - -extern "C" void * -D3D11_GetCoreWindowFromSDLRenderer(SDL_Renderer * renderer) -{ - SDL_Window * sdlWindow = renderer->window; - if ( ! renderer->window ) { - return NULL; - } - - SDL_SysWMinfo sdlWindowInfo; - SDL_VERSION(&sdlWindowInfo.version); - if ( ! SDL_GetWindowWMInfo(sdlWindow, &sdlWindowInfo) ) { - return NULL; - } - - if (sdlWindowInfo.subsystem != SDL_SYSWM_WINRT) { - return NULL; - } - - if (!sdlWindowInfo.info.winrt.window) { - return NULL; - } - - ABI::Windows::UI::Core::ICoreWindow *coreWindow = NULL; - if (FAILED(sdlWindowInfo.info.winrt.window->QueryInterface(&coreWindow))) { - return NULL; - } - - IUnknown *coreWindowAsIUnknown = NULL; - coreWindow->QueryInterface(&coreWindowAsIUnknown); - coreWindow->Release(); - - return coreWindowAsIUnknown; -} - -extern "C" DXGI_MODE_ROTATION -D3D11_GetCurrentRotation() -{ - const DisplayOrientations currentOrientation = WINRT_DISPLAY_PROPERTY(CurrentOrientation); - - switch (currentOrientation) { - -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP - /* Windows Phone rotations */ - case DisplayOrientations::Landscape: - return DXGI_MODE_ROTATION_ROTATE90; - case DisplayOrientations::Portrait: - return DXGI_MODE_ROTATION_IDENTITY; - case DisplayOrientations::LandscapeFlipped: - return DXGI_MODE_ROTATION_ROTATE270; - case DisplayOrientations::PortraitFlipped: - return DXGI_MODE_ROTATION_ROTATE180; -#else - /* Non-Windows-Phone rotations (ex: Windows 8, Windows RT) */ - case DisplayOrientations::Landscape: - return DXGI_MODE_ROTATION_IDENTITY; - case DisplayOrientations::Portrait: - return DXGI_MODE_ROTATION_ROTATE270; - case DisplayOrientations::LandscapeFlipped: - return DXGI_MODE_ROTATION_ROTATE180; - case DisplayOrientations::PortraitFlipped: - return DXGI_MODE_ROTATION_ROTATE90; -#endif /* WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP */ - } - - return DXGI_MODE_ROTATION_IDENTITY; -} - - -#endif /* SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/direct3d11/SDL_render_winrt.h b/3rdparty/SDL2/src/render/direct3d11/SDL_render_winrt.h deleted file mode 100644 index 734ebf41aa2..00000000000 --- a/3rdparty/SDL2/src/render/direct3d11/SDL_render_winrt.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../../SDL_internal.h" - -#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED - -#include "SDL_render.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void * D3D11_GetCoreWindowFromSDLRenderer(SDL_Renderer * renderer); -DXGI_MODE_ROTATION D3D11_GetCurrentRotation(); - -#ifdef __cplusplus -} -#endif - -#endif /* SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/mmx.h b/3rdparty/SDL2/src/render/mmx.h deleted file mode 100644 index 3bd00ac2398..00000000000 --- a/3rdparty/SDL2/src/render/mmx.h +++ /dev/null @@ -1,642 +0,0 @@ -/* mmx.h - - MultiMedia eXtensions GCC interface library for IA32. - - To use this library, simply include this header file - and compile with GCC. You MUST have inlining enabled - in order for mmx_ok() to work; this can be done by - simply using -O on the GCC command line. - - Compiling with -DMMX_TRACE will cause detailed trace - output to be sent to stderr for each mmx operation. - This adds lots of code, and obviously slows execution to - a crawl, but can be very useful for debugging. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT - LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR ANY PARTICULAR PURPOSE. - - 1997-99 by H. Dietz and R. Fisher - - Notes: - It appears that the latest gas has the pand problem fixed, therefore - I'll undefine BROKEN_PAND by default. -*/ - -#ifndef _MMX_H -#define _MMX_H - - -/* Warning: at this writing, the version of GAS packaged - with most Linux distributions does not handle the - parallel AND operation mnemonic correctly. If the - symbol BROKEN_PAND is defined, a slower alternative - coding will be used. If execution of mmxtest results - in an illegal instruction fault, define this symbol. -*/ -#undef BROKEN_PAND - - -/* The type of an value that fits in an MMX register - (note that long long constant values MUST be suffixed - by LL and unsigned long long values by ULL, lest - they be truncated by the compiler) -*/ -typedef union -{ - long long q; /* Quadword (64-bit) value */ - unsigned long long uq; /* Unsigned Quadword */ - int d[2]; /* 2 Doubleword (32-bit) values */ - unsigned int ud[2]; /* 2 Unsigned Doubleword */ - short w[4]; /* 4 Word (16-bit) values */ - unsigned short uw[4]; /* 4 Unsigned Word */ - char b[8]; /* 8 Byte (8-bit) values */ - unsigned char ub[8]; /* 8 Unsigned Byte */ - float s[2]; /* Single-precision (32-bit) value */ -} __attribute__ ((aligned(8))) mmx_t; /* On an 8-byte (64-bit) boundary */ - - -#if 0 -/* Function to test if multimedia instructions are supported... -*/ -inline extern int -mm_support(void) -{ - /* Returns 1 if MMX instructions are supported, - 3 if Cyrix MMX and Extended MMX instructions are supported - 5 if AMD MMX and 3DNow! instructions are supported - 0 if hardware does not support any of these - */ - register int rval = 0; - - __asm__ __volatile__( - /* See if CPUID instruction is supported ... */ - /* ... Get copies of EFLAGS into eax and ecx */ - "pushf\n\t" - "popl %%eax\n\t" "movl %%eax, %%ecx\n\t" - /* ... Toggle the ID bit in one copy and store */ - /* to the EFLAGS reg */ - "xorl $0x200000, %%eax\n\t" - "push %%eax\n\t" "popf\n\t" - /* ... Get the (hopefully modified) EFLAGS */ - "pushf\n\t" "popl %%eax\n\t" - /* ... Compare and test result */ - "xorl %%eax, %%ecx\n\t" "testl $0x200000, %%ecx\n\t" "jz NotSupported1\n\t" /* CPUID not supported */ - /* Get standard CPUID information, and - go to a specific vendor section */ - "movl $0, %%eax\n\t" "cpuid\n\t" - /* Check for Intel */ - "cmpl $0x756e6547, %%ebx\n\t" - "jne TryAMD\n\t" - "cmpl $0x49656e69, %%edx\n\t" - "jne TryAMD\n\t" - "cmpl $0x6c65746e, %%ecx\n" - "jne TryAMD\n\t" "jmp Intel\n\t" - /* Check for AMD */ - "\nTryAMD:\n\t" - "cmpl $0x68747541, %%ebx\n\t" - "jne TryCyrix\n\t" - "cmpl $0x69746e65, %%edx\n\t" - "jne TryCyrix\n\t" - "cmpl $0x444d4163, %%ecx\n" - "jne TryCyrix\n\t" "jmp AMD\n\t" - /* Check for Cyrix */ - "\nTryCyrix:\n\t" - "cmpl $0x69727943, %%ebx\n\t" - "jne NotSupported2\n\t" - "cmpl $0x736e4978, %%edx\n\t" - "jne NotSupported3\n\t" - "cmpl $0x64616574, %%ecx\n\t" - "jne NotSupported4\n\t" - /* Drop through to Cyrix... */ - /* Cyrix Section */ - /* See if extended CPUID level 80000001 is supported */ - /* The value of CPUID/80000001 for the 6x86MX is undefined - according to the Cyrix CPU Detection Guide (Preliminary - Rev. 1.01 table 1), so we'll check the value of eax for - CPUID/0 to see if standard CPUID level 2 is supported. - According to the table, the only CPU which supports level - 2 is also the only one which supports extended CPUID levels. - */ - "cmpl $0x2, %%eax\n\t" "jne MMXtest\n\t" /* Use standard CPUID instead */ - /* Extended CPUID supported (in theory), so get extended - features */ - "movl $0x80000001, %%eax\n\t" "cpuid\n\t" "testl $0x00800000, %%eax\n\t" /* Test for MMX */ - "jz NotSupported5\n\t" /* MMX not supported */ - "testl $0x01000000, %%eax\n\t" /* Test for Ext'd MMX */ - "jnz EMMXSupported\n\t" "movl $1, %0:\n\n\t" /* MMX Supported */ - "jmp Return\n\n" "EMMXSupported:\n\t" "movl $3, %0:\n\n\t" /* EMMX and MMX Supported */ - "jmp Return\n\t" - /* AMD Section */ - "AMD:\n\t" - /* See if extended CPUID is supported */ - "movl $0x80000000, %%eax\n\t" "cpuid\n\t" "cmpl $0x80000000, %%eax\n\t" "jl MMXtest\n\t" /* Use standard CPUID instead */ - /* Extended CPUID supported, so get extended features */ - "movl $0x80000001, %%eax\n\t" "cpuid\n\t" "testl $0x00800000, %%edx\n\t" /* Test for MMX */ - "jz NotSupported6\n\t" /* MMX not supported */ - "testl $0x80000000, %%edx\n\t" /* Test for 3DNow! */ - "jnz ThreeDNowSupported\n\t" "movl $1, %0:\n\n\t" /* MMX Supported */ - "jmp Return\n\n" "ThreeDNowSupported:\n\t" "movl $5, %0:\n\n\t" /* 3DNow! and MMX Supported */ - "jmp Return\n\t" - /* Intel Section */ - "Intel:\n\t" - /* Check for MMX */ - "MMXtest:\n\t" "movl $1, %%eax\n\t" "cpuid\n\t" "testl $0x00800000, %%edx\n\t" /* Test for MMX */ - "jz NotSupported7\n\t" /* MMX Not supported */ - "movl $1, %0:\n\n\t" /* MMX Supported */ - "jmp Return\n\t" - /* Nothing supported */ - "\nNotSupported1:\n\t" "#movl $101, %0:\n\n\t" "\nNotSupported2:\n\t" "#movl $102, %0:\n\n\t" "\nNotSupported3:\n\t" "#movl $103, %0:\n\n\t" "\nNotSupported4:\n\t" "#movl $104, %0:\n\n\t" "\nNotSupported5:\n\t" "#movl $105, %0:\n\n\t" "\nNotSupported6:\n\t" "#movl $106, %0:\n\n\t" "\nNotSupported7:\n\t" "#movl $107, %0:\n\n\t" "movl $0, %0:\n\n\t" "Return:\n\t":"=a"(rval): /* no input */ - :"eax", "ebx", "ecx", "edx"); - - /* Return */ - return (rval); -} - -/* Function to test if mmx instructions are supported... -*/ -inline extern int -mmx_ok(void) -{ - /* Returns 1 if MMX instructions are supported, 0 otherwise */ - return (mm_support() & 0x1); -} -#endif - -/* Helper functions for the instruction macros that follow... - (note that memory-to-register, m2r, instructions are nearly - as efficient as register-to-register, r2r, instructions; - however, memory-to-memory instructions are really simulated - as a convenience, and are only 1/3 as efficient) -*/ -#ifdef MMX_TRACE - -/* Include the stuff for printing a trace to stderr... -*/ - -#define mmx_i2r(op, imm, reg) \ - { \ - mmx_t mmx_trace; \ - mmx_trace.uq = (imm); \ - printf(#op "_i2r(" #imm "=0x%08x%08x, ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - __asm__ __volatile__ ("movq %%" #reg ", %0" \ - : "=X" (mmx_trace) \ - : /* nothing */ ); \ - printf(#reg "=0x%08x%08x) => ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - __asm__ __volatile__ (#op " %0, %%" #reg \ - : /* nothing */ \ - : "X" (imm)); \ - __asm__ __volatile__ ("movq %%" #reg ", %0" \ - : "=X" (mmx_trace) \ - : /* nothing */ ); \ - printf(#reg "=0x%08x%08x\n", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - } - -#define mmx_m2r(op, mem, reg) \ - { \ - mmx_t mmx_trace; \ - mmx_trace = (mem); \ - printf(#op "_m2r(" #mem "=0x%08x%08x, ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - __asm__ __volatile__ ("movq %%" #reg ", %0" \ - : "=X" (mmx_trace) \ - : /* nothing */ ); \ - printf(#reg "=0x%08x%08x) => ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - __asm__ __volatile__ (#op " %0, %%" #reg \ - : /* nothing */ \ - : "X" (mem)); \ - __asm__ __volatile__ ("movq %%" #reg ", %0" \ - : "=X" (mmx_trace) \ - : /* nothing */ ); \ - printf(#reg "=0x%08x%08x\n", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - } - -#define mmx_r2m(op, reg, mem) \ - { \ - mmx_t mmx_trace; \ - __asm__ __volatile__ ("movq %%" #reg ", %0" \ - : "=X" (mmx_trace) \ - : /* nothing */ ); \ - printf(#op "_r2m(" #reg "=0x%08x%08x, ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - mmx_trace = (mem); \ - printf(#mem "=0x%08x%08x) => ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - __asm__ __volatile__ (#op " %%" #reg ", %0" \ - : "=X" (mem) \ - : /* nothing */ ); \ - mmx_trace = (mem); \ - printf(#mem "=0x%08x%08x\n", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - } - -#define mmx_r2r(op, regs, regd) \ - { \ - mmx_t mmx_trace; \ - __asm__ __volatile__ ("movq %%" #regs ", %0" \ - : "=X" (mmx_trace) \ - : /* nothing */ ); \ - printf(#op "_r2r(" #regs "=0x%08x%08x, ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - __asm__ __volatile__ ("movq %%" #regd ", %0" \ - : "=X" (mmx_trace) \ - : /* nothing */ ); \ - printf(#regd "=0x%08x%08x) => ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - __asm__ __volatile__ (#op " %" #regs ", %" #regd); \ - __asm__ __volatile__ ("movq %%" #regd ", %0" \ - : "=X" (mmx_trace) \ - : /* nothing */ ); \ - printf(#regd "=0x%08x%08x\n", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - } - -#define mmx_m2m(op, mems, memd) \ - { \ - mmx_t mmx_trace; \ - mmx_trace = (mems); \ - printf(#op "_m2m(" #mems "=0x%08x%08x, ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - mmx_trace = (memd); \ - printf(#memd "=0x%08x%08x) => ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - __asm__ __volatile__ ("movq %0, %%mm0\n\t" \ - #op " %1, %%mm0\n\t" \ - "movq %%mm0, %0" \ - : "=X" (memd) \ - : "X" (mems)); \ - mmx_trace = (memd); \ - printf(#memd "=0x%08x%08x\n", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - } - -#else - -/* These macros are a lot simpler without the tracing... -*/ - -#define mmx_i2r(op, imm, reg) \ - __asm__ __volatile__ (#op " %0, %%" #reg \ - : /* nothing */ \ - : "X" (imm) ) - -#define mmx_m2r(op, mem, reg) \ - __asm__ __volatile__ (#op " %0, %%" #reg \ - : /* nothing */ \ - : "m" (mem)) - -#define mmx_r2m(op, reg, mem) \ - __asm__ __volatile__ (#op " %%" #reg ", %0" \ - : "=m" (mem) \ - : /* nothing */ ) - -#define mmx_r2r(op, regs, regd) \ - __asm__ __volatile__ (#op " %" #regs ", %" #regd) - -#define mmx_m2m(op, mems, memd) \ - __asm__ __volatile__ ("movq %0, %%mm0\n\t" \ - #op " %1, %%mm0\n\t" \ - "movq %%mm0, %0" \ - : "=X" (memd) \ - : "X" (mems)) - -#endif - - -/* 1x64 MOVe Quadword - (this is both a load and a store... - in fact, it is the only way to store) -*/ -#define movq_m2r(var, reg) mmx_m2r(movq, var, reg) -#define movq_r2m(reg, var) mmx_r2m(movq, reg, var) -#define movq_r2r(regs, regd) mmx_r2r(movq, regs, regd) -#define movq(vars, vard) \ - __asm__ __volatile__ ("movq %1, %%mm0\n\t" \ - "movq %%mm0, %0" \ - : "=X" (vard) \ - : "X" (vars)) - - -/* 1x32 MOVe Doubleword - (like movq, this is both load and store... - but is most useful for moving things between - mmx registers and ordinary registers) -*/ -#define movd_m2r(var, reg) mmx_m2r(movd, var, reg) -#define movd_r2m(reg, var) mmx_r2m(movd, reg, var) -#define movd_r2r(regs, regd) mmx_r2r(movd, regs, regd) -#define movd(vars, vard) \ - __asm__ __volatile__ ("movd %1, %%mm0\n\t" \ - "movd %%mm0, %0" \ - : "=X" (vard) \ - : "X" (vars)) - - -/* 2x32, 4x16, and 8x8 Parallel ADDs -*/ -#define paddd_m2r(var, reg) mmx_m2r(paddd, var, reg) -#define paddd_r2r(regs, regd) mmx_r2r(paddd, regs, regd) -#define paddd(vars, vard) mmx_m2m(paddd, vars, vard) - -#define paddw_m2r(var, reg) mmx_m2r(paddw, var, reg) -#define paddw_r2r(regs, regd) mmx_r2r(paddw, regs, regd) -#define paddw(vars, vard) mmx_m2m(paddw, vars, vard) - -#define paddb_m2r(var, reg) mmx_m2r(paddb, var, reg) -#define paddb_r2r(regs, regd) mmx_r2r(paddb, regs, regd) -#define paddb(vars, vard) mmx_m2m(paddb, vars, vard) - - -/* 4x16 and 8x8 Parallel ADDs using Saturation arithmetic -*/ -#define paddsw_m2r(var, reg) mmx_m2r(paddsw, var, reg) -#define paddsw_r2r(regs, regd) mmx_r2r(paddsw, regs, regd) -#define paddsw(vars, vard) mmx_m2m(paddsw, vars, vard) - -#define paddsb_m2r(var, reg) mmx_m2r(paddsb, var, reg) -#define paddsb_r2r(regs, regd) mmx_r2r(paddsb, regs, regd) -#define paddsb(vars, vard) mmx_m2m(paddsb, vars, vard) - - -/* 4x16 and 8x8 Parallel ADDs using Unsigned Saturation arithmetic -*/ -#define paddusw_m2r(var, reg) mmx_m2r(paddusw, var, reg) -#define paddusw_r2r(regs, regd) mmx_r2r(paddusw, regs, regd) -#define paddusw(vars, vard) mmx_m2m(paddusw, vars, vard) - -#define paddusb_m2r(var, reg) mmx_m2r(paddusb, var, reg) -#define paddusb_r2r(regs, regd) mmx_r2r(paddusb, regs, regd) -#define paddusb(vars, vard) mmx_m2m(paddusb, vars, vard) - - -/* 2x32, 4x16, and 8x8 Parallel SUBs -*/ -#define psubd_m2r(var, reg) mmx_m2r(psubd, var, reg) -#define psubd_r2r(regs, regd) mmx_r2r(psubd, regs, regd) -#define psubd(vars, vard) mmx_m2m(psubd, vars, vard) - -#define psubw_m2r(var, reg) mmx_m2r(psubw, var, reg) -#define psubw_r2r(regs, regd) mmx_r2r(psubw, regs, regd) -#define psubw(vars, vard) mmx_m2m(psubw, vars, vard) - -#define psubb_m2r(var, reg) mmx_m2r(psubb, var, reg) -#define psubb_r2r(regs, regd) mmx_r2r(psubb, regs, regd) -#define psubb(vars, vard) mmx_m2m(psubb, vars, vard) - - -/* 4x16 and 8x8 Parallel SUBs using Saturation arithmetic -*/ -#define psubsw_m2r(var, reg) mmx_m2r(psubsw, var, reg) -#define psubsw_r2r(regs, regd) mmx_r2r(psubsw, regs, regd) -#define psubsw(vars, vard) mmx_m2m(psubsw, vars, vard) - -#define psubsb_m2r(var, reg) mmx_m2r(psubsb, var, reg) -#define psubsb_r2r(regs, regd) mmx_r2r(psubsb, regs, regd) -#define psubsb(vars, vard) mmx_m2m(psubsb, vars, vard) - - -/* 4x16 and 8x8 Parallel SUBs using Unsigned Saturation arithmetic -*/ -#define psubusw_m2r(var, reg) mmx_m2r(psubusw, var, reg) -#define psubusw_r2r(regs, regd) mmx_r2r(psubusw, regs, regd) -#define psubusw(vars, vard) mmx_m2m(psubusw, vars, vard) - -#define psubusb_m2r(var, reg) mmx_m2r(psubusb, var, reg) -#define psubusb_r2r(regs, regd) mmx_r2r(psubusb, regs, regd) -#define psubusb(vars, vard) mmx_m2m(psubusb, vars, vard) - - -/* 4x16 Parallel MULs giving Low 4x16 portions of results -*/ -#define pmullw_m2r(var, reg) mmx_m2r(pmullw, var, reg) -#define pmullw_r2r(regs, regd) mmx_r2r(pmullw, regs, regd) -#define pmullw(vars, vard) mmx_m2m(pmullw, vars, vard) - - -/* 4x16 Parallel MULs giving High 4x16 portions of results -*/ -#define pmulhw_m2r(var, reg) mmx_m2r(pmulhw, var, reg) -#define pmulhw_r2r(regs, regd) mmx_r2r(pmulhw, regs, regd) -#define pmulhw(vars, vard) mmx_m2m(pmulhw, vars, vard) - - -/* 4x16->2x32 Parallel Mul-ADD - (muls like pmullw, then adds adjacent 16-bit fields - in the multiply result to make the final 2x32 result) -*/ -#define pmaddwd_m2r(var, reg) mmx_m2r(pmaddwd, var, reg) -#define pmaddwd_r2r(regs, regd) mmx_r2r(pmaddwd, regs, regd) -#define pmaddwd(vars, vard) mmx_m2m(pmaddwd, vars, vard) - - -/* 1x64 bitwise AND -*/ -#ifdef BROKEN_PAND -#define pand_m2r(var, reg) \ - { \ - mmx_m2r(pandn, (mmx_t) -1LL, reg); \ - mmx_m2r(pandn, var, reg); \ - } -#define pand_r2r(regs, regd) \ - { \ - mmx_m2r(pandn, (mmx_t) -1LL, regd); \ - mmx_r2r(pandn, regs, regd) \ - } -#define pand(vars, vard) \ - { \ - movq_m2r(vard, mm0); \ - mmx_m2r(pandn, (mmx_t) -1LL, mm0); \ - mmx_m2r(pandn, vars, mm0); \ - movq_r2m(mm0, vard); \ - } -#else -#define pand_m2r(var, reg) mmx_m2r(pand, var, reg) -#define pand_r2r(regs, regd) mmx_r2r(pand, regs, regd) -#define pand(vars, vard) mmx_m2m(pand, vars, vard) -#endif - - -/* 1x64 bitwise AND with Not the destination -*/ -#define pandn_m2r(var, reg) mmx_m2r(pandn, var, reg) -#define pandn_r2r(regs, regd) mmx_r2r(pandn, regs, regd) -#define pandn(vars, vard) mmx_m2m(pandn, vars, vard) - - -/* 1x64 bitwise OR -*/ -#define por_m2r(var, reg) mmx_m2r(por, var, reg) -#define por_r2r(regs, regd) mmx_r2r(por, regs, regd) -#define por(vars, vard) mmx_m2m(por, vars, vard) - - -/* 1x64 bitwise eXclusive OR -*/ -#define pxor_m2r(var, reg) mmx_m2r(pxor, var, reg) -#define pxor_r2r(regs, regd) mmx_r2r(pxor, regs, regd) -#define pxor(vars, vard) mmx_m2m(pxor, vars, vard) - - -/* 2x32, 4x16, and 8x8 Parallel CoMPare for EQuality - (resulting fields are either 0 or -1) -*/ -#define pcmpeqd_m2r(var, reg) mmx_m2r(pcmpeqd, var, reg) -#define pcmpeqd_r2r(regs, regd) mmx_r2r(pcmpeqd, regs, regd) -#define pcmpeqd(vars, vard) mmx_m2m(pcmpeqd, vars, vard) - -#define pcmpeqw_m2r(var, reg) mmx_m2r(pcmpeqw, var, reg) -#define pcmpeqw_r2r(regs, regd) mmx_r2r(pcmpeqw, regs, regd) -#define pcmpeqw(vars, vard) mmx_m2m(pcmpeqw, vars, vard) - -#define pcmpeqb_m2r(var, reg) mmx_m2r(pcmpeqb, var, reg) -#define pcmpeqb_r2r(regs, regd) mmx_r2r(pcmpeqb, regs, regd) -#define pcmpeqb(vars, vard) mmx_m2m(pcmpeqb, vars, vard) - - -/* 2x32, 4x16, and 8x8 Parallel CoMPare for Greater Than - (resulting fields are either 0 or -1) -*/ -#define pcmpgtd_m2r(var, reg) mmx_m2r(pcmpgtd, var, reg) -#define pcmpgtd_r2r(regs, regd) mmx_r2r(pcmpgtd, regs, regd) -#define pcmpgtd(vars, vard) mmx_m2m(pcmpgtd, vars, vard) - -#define pcmpgtw_m2r(var, reg) mmx_m2r(pcmpgtw, var, reg) -#define pcmpgtw_r2r(regs, regd) mmx_r2r(pcmpgtw, regs, regd) -#define pcmpgtw(vars, vard) mmx_m2m(pcmpgtw, vars, vard) - -#define pcmpgtb_m2r(var, reg) mmx_m2r(pcmpgtb, var, reg) -#define pcmpgtb_r2r(regs, regd) mmx_r2r(pcmpgtb, regs, regd) -#define pcmpgtb(vars, vard) mmx_m2m(pcmpgtb, vars, vard) - - -/* 1x64, 2x32, and 4x16 Parallel Shift Left Logical -*/ -#define psllq_i2r(imm, reg) mmx_i2r(psllq, imm, reg) -#define psllq_m2r(var, reg) mmx_m2r(psllq, var, reg) -#define psllq_r2r(regs, regd) mmx_r2r(psllq, regs, regd) -#define psllq(vars, vard) mmx_m2m(psllq, vars, vard) - -#define pslld_i2r(imm, reg) mmx_i2r(pslld, imm, reg) -#define pslld_m2r(var, reg) mmx_m2r(pslld, var, reg) -#define pslld_r2r(regs, regd) mmx_r2r(pslld, regs, regd) -#define pslld(vars, vard) mmx_m2m(pslld, vars, vard) - -#define psllw_i2r(imm, reg) mmx_i2r(psllw, imm, reg) -#define psllw_m2r(var, reg) mmx_m2r(psllw, var, reg) -#define psllw_r2r(regs, regd) mmx_r2r(psllw, regs, regd) -#define psllw(vars, vard) mmx_m2m(psllw, vars, vard) - - -/* 1x64, 2x32, and 4x16 Parallel Shift Right Logical -*/ -#define psrlq_i2r(imm, reg) mmx_i2r(psrlq, imm, reg) -#define psrlq_m2r(var, reg) mmx_m2r(psrlq, var, reg) -#define psrlq_r2r(regs, regd) mmx_r2r(psrlq, regs, regd) -#define psrlq(vars, vard) mmx_m2m(psrlq, vars, vard) - -#define psrld_i2r(imm, reg) mmx_i2r(psrld, imm, reg) -#define psrld_m2r(var, reg) mmx_m2r(psrld, var, reg) -#define psrld_r2r(regs, regd) mmx_r2r(psrld, regs, regd) -#define psrld(vars, vard) mmx_m2m(psrld, vars, vard) - -#define psrlw_i2r(imm, reg) mmx_i2r(psrlw, imm, reg) -#define psrlw_m2r(var, reg) mmx_m2r(psrlw, var, reg) -#define psrlw_r2r(regs, regd) mmx_r2r(psrlw, regs, regd) -#define psrlw(vars, vard) mmx_m2m(psrlw, vars, vard) - - -/* 2x32 and 4x16 Parallel Shift Right Arithmetic -*/ -#define psrad_i2r(imm, reg) mmx_i2r(psrad, imm, reg) -#define psrad_m2r(var, reg) mmx_m2r(psrad, var, reg) -#define psrad_r2r(regs, regd) mmx_r2r(psrad, regs, regd) -#define psrad(vars, vard) mmx_m2m(psrad, vars, vard) - -#define psraw_i2r(imm, reg) mmx_i2r(psraw, imm, reg) -#define psraw_m2r(var, reg) mmx_m2r(psraw, var, reg) -#define psraw_r2r(regs, regd) mmx_r2r(psraw, regs, regd) -#define psraw(vars, vard) mmx_m2m(psraw, vars, vard) - - -/* 2x32->4x16 and 4x16->8x8 PACK and Signed Saturate - (packs source and dest fields into dest in that order) -*/ -#define packssdw_m2r(var, reg) mmx_m2r(packssdw, var, reg) -#define packssdw_r2r(regs, regd) mmx_r2r(packssdw, regs, regd) -#define packssdw(vars, vard) mmx_m2m(packssdw, vars, vard) - -#define packsswb_m2r(var, reg) mmx_m2r(packsswb, var, reg) -#define packsswb_r2r(regs, regd) mmx_r2r(packsswb, regs, regd) -#define packsswb(vars, vard) mmx_m2m(packsswb, vars, vard) - - -/* 4x16->8x8 PACK and Unsigned Saturate - (packs source and dest fields into dest in that order) -*/ -#define packuswb_m2r(var, reg) mmx_m2r(packuswb, var, reg) -#define packuswb_r2r(regs, regd) mmx_r2r(packuswb, regs, regd) -#define packuswb(vars, vard) mmx_m2m(packuswb, vars, vard) - - -/* 2x32->1x64, 4x16->2x32, and 8x8->4x16 UNPaCK Low - (interleaves low half of dest with low half of source - as padding in each result field) -*/ -#define punpckldq_m2r(var, reg) mmx_m2r(punpckldq, var, reg) -#define punpckldq_r2r(regs, regd) mmx_r2r(punpckldq, regs, regd) -#define punpckldq(vars, vard) mmx_m2m(punpckldq, vars, vard) - -#define punpcklwd_m2r(var, reg) mmx_m2r(punpcklwd, var, reg) -#define punpcklwd_r2r(regs, regd) mmx_r2r(punpcklwd, regs, regd) -#define punpcklwd(vars, vard) mmx_m2m(punpcklwd, vars, vard) - -#define punpcklbw_m2r(var, reg) mmx_m2r(punpcklbw, var, reg) -#define punpcklbw_r2r(regs, regd) mmx_r2r(punpcklbw, regs, regd) -#define punpcklbw(vars, vard) mmx_m2m(punpcklbw, vars, vard) - - -/* 2x32->1x64, 4x16->2x32, and 8x8->4x16 UNPaCK High - (interleaves high half of dest with high half of source - as padding in each result field) -*/ -#define punpckhdq_m2r(var, reg) mmx_m2r(punpckhdq, var, reg) -#define punpckhdq_r2r(regs, regd) mmx_r2r(punpckhdq, regs, regd) -#define punpckhdq(vars, vard) mmx_m2m(punpckhdq, vars, vard) - -#define punpckhwd_m2r(var, reg) mmx_m2r(punpckhwd, var, reg) -#define punpckhwd_r2r(regs, regd) mmx_r2r(punpckhwd, regs, regd) -#define punpckhwd(vars, vard) mmx_m2m(punpckhwd, vars, vard) - -#define punpckhbw_m2r(var, reg) mmx_m2r(punpckhbw, var, reg) -#define punpckhbw_r2r(regs, regd) mmx_r2r(punpckhbw, regs, regd) -#define punpckhbw(vars, vard) mmx_m2m(punpckhbw, vars, vard) - - -/* Empty MMx State - (used to clean-up when going from mmx to float use - of the registers that are shared by both; note that - there is no float-to-mmx operation needed, because - only the float tag word info is corruptible) -*/ -#ifdef MMX_TRACE - -#define emms() \ - { \ - printf("emms()\n"); \ - __asm__ __volatile__ ("emms"); \ - } - -#else - -#define emms() __asm__ __volatile__ ("emms") - -#endif - -#endif -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/opengl/SDL_glfuncs.h b/3rdparty/SDL2/src/render/opengl/SDL_glfuncs.h deleted file mode 100644 index c8eba583cb3..00000000000 --- a/3rdparty/SDL2/src/render/opengl/SDL_glfuncs.h +++ /dev/null @@ -1,477 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -/* list of OpenGL functions sorted alphabetically - If you need to use a GL function from the SDL video subsystem, - change its entry from SDL_PROC_UNUSED to SDL_PROC and rebuild. -*/ -#define SDL_PROC_UNUSED(ret,func,params) - -SDL_PROC_UNUSED(void, glAccum, (GLenum, GLfloat)) -SDL_PROC_UNUSED(void, glAlphaFunc, (GLenum, GLclampf)) -SDL_PROC_UNUSED(GLboolean, glAreTexturesResident, - (GLsizei, const GLuint *, GLboolean *)) -SDL_PROC_UNUSED(void, glArrayElement, (GLint)) -SDL_PROC(void, glBegin, (GLenum)) -SDL_PROC(void, glBindTexture, (GLenum, GLuint)) -SDL_PROC_UNUSED(void, glBitmap, - (GLsizei, GLsizei, GLfloat, GLfloat, GLfloat, GLfloat, - const GLubyte *)) -SDL_PROC(void, glBlendFunc, (GLenum, GLenum)) -SDL_PROC(void, glBlendFuncSeparate, (GLenum, GLenum, GLenum, GLenum)) -SDL_PROC_UNUSED(void, glCallList, (GLuint)) -SDL_PROC_UNUSED(void, glCallLists, (GLsizei, GLenum, const GLvoid *)) -SDL_PROC(void, glClear, (GLbitfield)) -SDL_PROC_UNUSED(void, glClearAccum, (GLfloat, GLfloat, GLfloat, GLfloat)) -SDL_PROC(void, glClearColor, (GLclampf, GLclampf, GLclampf, GLclampf)) -SDL_PROC_UNUSED(void, glClearDepth, (GLclampd)) -SDL_PROC_UNUSED(void, glClearIndex, (GLfloat)) -SDL_PROC_UNUSED(void, glClearStencil, (GLint)) -SDL_PROC_UNUSED(void, glClipPlane, (GLenum, const GLdouble *)) -SDL_PROC_UNUSED(void, glColor3b, (GLbyte, GLbyte, GLbyte)) -SDL_PROC_UNUSED(void, glColor3bv, (const GLbyte *)) -SDL_PROC_UNUSED(void, glColor3d, (GLdouble, GLdouble, GLdouble)) -SDL_PROC_UNUSED(void, glColor3dv, (const GLdouble *)) -SDL_PROC_UNUSED(void, glColor3f, (GLfloat, GLfloat, GLfloat)) -SDL_PROC(void, glColor3fv, (const GLfloat *)) -SDL_PROC_UNUSED(void, glColor3i, (GLint, GLint, GLint)) -SDL_PROC_UNUSED(void, glColor3iv, (const GLint *)) -SDL_PROC_UNUSED(void, glColor3s, (GLshort, GLshort, GLshort)) -SDL_PROC_UNUSED(void, glColor3sv, (const GLshort *)) -SDL_PROC_UNUSED(void, glColor3ub, (GLubyte, GLubyte, GLubyte)) -SDL_PROC_UNUSED(void, glColor3ubv, (const GLubyte *)) -SDL_PROC_UNUSED(void, glColor3ui, (GLuint, GLuint, GLuint)) -SDL_PROC_UNUSED(void, glColor3uiv, (const GLuint *)) -SDL_PROC_UNUSED(void, glColor3us, (GLushort, GLushort, GLushort)) -SDL_PROC_UNUSED(void, glColor3usv, (const GLushort *)) -SDL_PROC_UNUSED(void, glColor4b, (GLbyte, GLbyte, GLbyte, GLbyte)) -SDL_PROC_UNUSED(void, glColor4bv, (const GLbyte *)) -SDL_PROC_UNUSED(void, glColor4d, (GLdouble, GLdouble, GLdouble, GLdouble)) -SDL_PROC_UNUSED(void, glColor4dv, (const GLdouble *)) -SDL_PROC(void, glColor4f, (GLfloat, GLfloat, GLfloat, GLfloat)) -SDL_PROC_UNUSED(void, glColor4fv, (const GLfloat *)) -SDL_PROC_UNUSED(void, glColor4i, (GLint, GLint, GLint, GLint)) -SDL_PROC_UNUSED(void, glColor4iv, (const GLint *)) -SDL_PROC_UNUSED(void, glColor4s, (GLshort, GLshort, GLshort, GLshort)) -SDL_PROC_UNUSED(void, glColor4sv, (const GLshort *)) -SDL_PROC_UNUSED(void, glColor4ub, - (GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)) -SDL_PROC_UNUSED(void, glColor4ubv, (const GLubyte * v)) -SDL_PROC_UNUSED(void, glColor4ui, - (GLuint red, GLuint green, GLuint blue, GLuint alpha)) -SDL_PROC_UNUSED(void, glColor4uiv, (const GLuint * v)) -SDL_PROC_UNUSED(void, glColor4us, - (GLushort red, GLushort green, GLushort blue, GLushort alpha)) -SDL_PROC_UNUSED(void, glColor4usv, (const GLushort * v)) -SDL_PROC_UNUSED(void, glColorMask, - (GLboolean red, GLboolean green, GLboolean blue, - GLboolean alpha)) -SDL_PROC_UNUSED(void, glColorMaterial, (GLenum face, GLenum mode)) -SDL_PROC_UNUSED(void, glColorPointer, - (GLint size, GLenum type, GLsizei stride, - const GLvoid * pointer)) -SDL_PROC_UNUSED(void, glCopyPixels, - (GLint x, GLint y, GLsizei width, GLsizei height, - GLenum type)) -SDL_PROC_UNUSED(void, glCopyTexImage1D, - (GLenum target, GLint level, GLenum internalFormat, GLint x, - GLint y, GLsizei width, GLint border)) -SDL_PROC_UNUSED(void, glCopyTexImage2D, - (GLenum target, GLint level, GLenum internalFormat, GLint x, - GLint y, GLsizei width, GLsizei height, GLint border)) -SDL_PROC_UNUSED(void, glCopyTexSubImage1D, - (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, - GLsizei width)) -SDL_PROC_UNUSED(void, glCopyTexSubImage2D, - (GLenum target, GLint level, GLint xoffset, GLint yoffset, - GLint x, GLint y, GLsizei width, GLsizei height)) -SDL_PROC_UNUSED(void, glCullFace, (GLenum mode)) -SDL_PROC_UNUSED(void, glDeleteLists, (GLuint list, GLsizei range)) -SDL_PROC(void, glDeleteTextures, (GLsizei n, const GLuint * textures)) -SDL_PROC(void, glDepthFunc, (GLenum func)) -SDL_PROC_UNUSED(void, glDepthMask, (GLboolean flag)) -SDL_PROC_UNUSED(void, glDepthRange, (GLclampd zNear, GLclampd zFar)) -SDL_PROC(void, glDisable, (GLenum cap)) -SDL_PROC_UNUSED(void, glDisableClientState, (GLenum array)) -SDL_PROC_UNUSED(void, glDrawArrays, (GLenum mode, GLint first, GLsizei count)) -SDL_PROC_UNUSED(void, glDrawBuffer, (GLenum mode)) -SDL_PROC_UNUSED(void, glDrawElements, - (GLenum mode, GLsizei count, GLenum type, - const GLvoid * indices)) -SDL_PROC(void, glDrawPixels, - (GLsizei width, GLsizei height, GLenum format, GLenum type, - const GLvoid * pixels)) -SDL_PROC_UNUSED(void, glEdgeFlag, (GLboolean flag)) -SDL_PROC_UNUSED(void, glEdgeFlagPointer, - (GLsizei stride, const GLvoid * pointer)) -SDL_PROC_UNUSED(void, glEdgeFlagv, (const GLboolean * flag)) -SDL_PROC(void, glEnable, (GLenum cap)) -SDL_PROC_UNUSED(void, glEnableClientState, (GLenum array)) -SDL_PROC(void, glEnd, (void)) -SDL_PROC_UNUSED(void, glEndList, (void)) -SDL_PROC_UNUSED(void, glEvalCoord1d, (GLdouble u)) -SDL_PROC_UNUSED(void, glEvalCoord1dv, (const GLdouble * u)) -SDL_PROC_UNUSED(void, glEvalCoord1f, (GLfloat u)) -SDL_PROC_UNUSED(void, glEvalCoord1fv, (const GLfloat * u)) -SDL_PROC_UNUSED(void, glEvalCoord2d, (GLdouble u, GLdouble v)) -SDL_PROC_UNUSED(void, glEvalCoord2dv, (const GLdouble * u)) -SDL_PROC_UNUSED(void, glEvalCoord2f, (GLfloat u, GLfloat v)) -SDL_PROC_UNUSED(void, glEvalCoord2fv, (const GLfloat * u)) -SDL_PROC_UNUSED(void, glEvalMesh1, (GLenum mode, GLint i1, GLint i2)) -SDL_PROC_UNUSED(void, glEvalMesh2, - (GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2)) -SDL_PROC_UNUSED(void, glEvalPoint1, (GLint i)) -SDL_PROC_UNUSED(void, glEvalPoint2, (GLint i, GLint j)) -SDL_PROC_UNUSED(void, glFeedbackBuffer, - (GLsizei size, GLenum type, GLfloat * buffer)) -SDL_PROC_UNUSED(void, glFinish, (void)) -SDL_PROC_UNUSED(void, glFlush, (void)) -SDL_PROC_UNUSED(void, glFogf, (GLenum pname, GLfloat param)) -SDL_PROC_UNUSED(void, glFogfv, (GLenum pname, const GLfloat * params)) -SDL_PROC_UNUSED(void, glFogi, (GLenum pname, GLint param)) -SDL_PROC_UNUSED(void, glFogiv, (GLenum pname, const GLint * params)) -SDL_PROC_UNUSED(void, glFrontFace, (GLenum mode)) -SDL_PROC_UNUSED(void, glFrustum, - (GLdouble left, GLdouble right, GLdouble bottom, - GLdouble top, GLdouble zNear, GLdouble zFar)) -SDL_PROC_UNUSED(GLuint, glGenLists, (GLsizei range)) -SDL_PROC(void, glGenTextures, (GLsizei n, GLuint * textures)) -SDL_PROC_UNUSED(void, glGetBooleanv, (GLenum pname, GLboolean * params)) -SDL_PROC_UNUSED(void, glGetClipPlane, (GLenum plane, GLdouble * equation)) -SDL_PROC_UNUSED(void, glGetDoublev, (GLenum pname, GLdouble * params)) -SDL_PROC(GLenum, glGetError, (void)) -SDL_PROC_UNUSED(void, glGetFloatv, (GLenum pname, GLfloat * params)) -SDL_PROC(void, glGetIntegerv, (GLenum pname, GLint * params)) -SDL_PROC_UNUSED(void, glGetLightfv, - (GLenum light, GLenum pname, GLfloat * params)) -SDL_PROC_UNUSED(void, glGetLightiv, - (GLenum light, GLenum pname, GLint * params)) -SDL_PROC_UNUSED(void, glGetMapdv, (GLenum target, GLenum query, GLdouble * v)) -SDL_PROC_UNUSED(void, glGetMapfv, (GLenum target, GLenum query, GLfloat * v)) -SDL_PROC_UNUSED(void, glGetMapiv, (GLenum target, GLenum query, GLint * v)) -SDL_PROC_UNUSED(void, glGetMaterialfv, - (GLenum face, GLenum pname, GLfloat * params)) -SDL_PROC_UNUSED(void, glGetMaterialiv, - (GLenum face, GLenum pname, GLint * params)) -SDL_PROC_UNUSED(void, glGetPixelMapfv, (GLenum map, GLfloat * values)) -SDL_PROC_UNUSED(void, glGetPixelMapuiv, (GLenum map, GLuint * values)) -SDL_PROC_UNUSED(void, glGetPixelMapusv, (GLenum map, GLushort * values)) -SDL_PROC(void, glGetPointerv, (GLenum pname, GLvoid * *params)) -SDL_PROC_UNUSED(void, glGetPolygonStipple, (GLubyte * mask)) -SDL_PROC(const GLubyte *, glGetString, (GLenum name)) -SDL_PROC_UNUSED(void, glGetTexEnvfv, - (GLenum target, GLenum pname, GLfloat * params)) -SDL_PROC_UNUSED(void, glGetTexEnviv, - (GLenum target, GLenum pname, GLint * params)) -SDL_PROC_UNUSED(void, glGetTexGendv, - (GLenum coord, GLenum pname, GLdouble * params)) -SDL_PROC_UNUSED(void, glGetTexGenfv, - (GLenum coord, GLenum pname, GLfloat * params)) -SDL_PROC_UNUSED(void, glGetTexGeniv, - (GLenum coord, GLenum pname, GLint * params)) -SDL_PROC_UNUSED(void, glGetTexImage, - (GLenum target, GLint level, GLenum format, GLenum type, - GLvoid * pixels)) -SDL_PROC_UNUSED(void, glGetTexLevelParameterfv, - (GLenum target, GLint level, GLenum pname, GLfloat * params)) -SDL_PROC_UNUSED(void, glGetTexLevelParameteriv, - (GLenum target, GLint level, GLenum pname, GLint * params)) -SDL_PROC_UNUSED(void, glGetTexParameterfv, - (GLenum target, GLenum pname, GLfloat * params)) -SDL_PROC_UNUSED(void, glGetTexParameteriv, - (GLenum target, GLenum pname, GLint * params)) -SDL_PROC_UNUSED(void, glHint, (GLenum target, GLenum mode)) -SDL_PROC_UNUSED(void, glIndexMask, (GLuint mask)) -SDL_PROC_UNUSED(void, glIndexPointer, - (GLenum type, GLsizei stride, const GLvoid * pointer)) -SDL_PROC_UNUSED(void, glIndexd, (GLdouble c)) -SDL_PROC_UNUSED(void, glIndexdv, (const GLdouble * c)) -SDL_PROC_UNUSED(void, glIndexf, (GLfloat c)) -SDL_PROC_UNUSED(void, glIndexfv, (const GLfloat * c)) -SDL_PROC_UNUSED(void, glIndexi, (GLint c)) -SDL_PROC_UNUSED(void, glIndexiv, (const GLint * c)) -SDL_PROC_UNUSED(void, glIndexs, (GLshort c)) -SDL_PROC_UNUSED(void, glIndexsv, (const GLshort * c)) -SDL_PROC_UNUSED(void, glIndexub, (GLubyte c)) -SDL_PROC_UNUSED(void, glIndexubv, (const GLubyte * c)) -SDL_PROC_UNUSED(void, glInitNames, (void)) -SDL_PROC_UNUSED(void, glInterleavedArrays, - (GLenum format, GLsizei stride, const GLvoid * pointer)) -SDL_PROC_UNUSED(GLboolean, glIsEnabled, (GLenum cap)) -SDL_PROC_UNUSED(GLboolean, glIsList, (GLuint list)) -SDL_PROC_UNUSED(GLboolean, glIsTexture, (GLuint texture)) -SDL_PROC_UNUSED(void, glLightModelf, (GLenum pname, GLfloat param)) -SDL_PROC_UNUSED(void, glLightModelfv, (GLenum pname, const GLfloat * params)) -SDL_PROC_UNUSED(void, glLightModeli, (GLenum pname, GLint param)) -SDL_PROC_UNUSED(void, glLightModeliv, (GLenum pname, const GLint * params)) -SDL_PROC_UNUSED(void, glLightf, (GLenum light, GLenum pname, GLfloat param)) -SDL_PROC_UNUSED(void, glLightfv, - (GLenum light, GLenum pname, const GLfloat * params)) -SDL_PROC_UNUSED(void, glLighti, (GLenum light, GLenum pname, GLint param)) -SDL_PROC_UNUSED(void, glLightiv, - (GLenum light, GLenum pname, const GLint * params)) -SDL_PROC_UNUSED(void, glLineStipple, (GLint factor, GLushort pattern)) -SDL_PROC(void, glLineWidth, (GLfloat width)) -SDL_PROC_UNUSED(void, glListBase, (GLuint base)) -SDL_PROC(void, glLoadIdentity, (void)) -SDL_PROC_UNUSED(void, glLoadMatrixd, (const GLdouble * m)) -SDL_PROC_UNUSED(void, glLoadMatrixf, (const GLfloat * m)) -SDL_PROC_UNUSED(void, glLoadName, (GLuint name)) -SDL_PROC_UNUSED(void, glLogicOp, (GLenum opcode)) -SDL_PROC_UNUSED(void, glMap1d, - (GLenum target, GLdouble u1, GLdouble u2, GLint stride, - GLint order, const GLdouble * points)) -SDL_PROC_UNUSED(void, glMap1f, - (GLenum target, GLfloat u1, GLfloat u2, GLint stride, - GLint order, const GLfloat * points)) -SDL_PROC_UNUSED(void, glMap2d, - (GLenum target, GLdouble u1, GLdouble u2, GLint ustride, - GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, - GLint vorder, const GLdouble * points)) -SDL_PROC_UNUSED(void, glMap2f, - (GLenum target, GLfloat u1, GLfloat u2, GLint ustride, - GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, - GLint vorder, const GLfloat * points)) -SDL_PROC_UNUSED(void, glMapGrid1d, (GLint un, GLdouble u1, GLdouble u2)) -SDL_PROC_UNUSED(void, glMapGrid1f, (GLint un, GLfloat u1, GLfloat u2)) -SDL_PROC_UNUSED(void, glMapGrid2d, - (GLint un, GLdouble u1, GLdouble u2, GLint vn, GLdouble v1, - GLdouble v2)) -SDL_PROC_UNUSED(void, glMapGrid2f, - (GLint un, GLfloat u1, GLfloat u2, GLint vn, GLfloat v1, - GLfloat v2)) -SDL_PROC_UNUSED(void, glMaterialf, (GLenum face, GLenum pname, GLfloat param)) -SDL_PROC_UNUSED(void, glMaterialfv, - (GLenum face, GLenum pname, const GLfloat * params)) -SDL_PROC_UNUSED(void, glMateriali, (GLenum face, GLenum pname, GLint param)) -SDL_PROC_UNUSED(void, glMaterialiv, - (GLenum face, GLenum pname, const GLint * params)) -SDL_PROC(void, glMatrixMode, (GLenum mode)) -SDL_PROC_UNUSED(void, glMultMatrixd, (const GLdouble * m)) -SDL_PROC_UNUSED(void, glMultMatrixf, (const GLfloat * m)) -SDL_PROC_UNUSED(void, glNewList, (GLuint list, GLenum mode)) -SDL_PROC_UNUSED(void, glNormal3b, (GLbyte nx, GLbyte ny, GLbyte nz)) -SDL_PROC_UNUSED(void, glNormal3bv, (const GLbyte * v)) -SDL_PROC_UNUSED(void, glNormal3d, (GLdouble nx, GLdouble ny, GLdouble nz)) -SDL_PROC_UNUSED(void, glNormal3dv, (const GLdouble * v)) -SDL_PROC_UNUSED(void, glNormal3f, (GLfloat nx, GLfloat ny, GLfloat nz)) -SDL_PROC_UNUSED(void, glNormal3fv, (const GLfloat * v)) -SDL_PROC_UNUSED(void, glNormal3i, (GLint nx, GLint ny, GLint nz)) -SDL_PROC_UNUSED(void, glNormal3iv, (const GLint * v)) -SDL_PROC_UNUSED(void, glNormal3s, (GLshort nx, GLshort ny, GLshort nz)) -SDL_PROC_UNUSED(void, glNormal3sv, (const GLshort * v)) -SDL_PROC_UNUSED(void, glNormalPointer, - (GLenum type, GLsizei stride, const GLvoid * pointer)) -SDL_PROC(void, glOrtho, - (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, - GLdouble zNear, GLdouble zFar)) -SDL_PROC_UNUSED(void, glPassThrough, (GLfloat token)) -SDL_PROC_UNUSED(void, glPixelMapfv, - (GLenum map, GLsizei mapsize, const GLfloat * values)) -SDL_PROC_UNUSED(void, glPixelMapuiv, - (GLenum map, GLsizei mapsize, const GLuint * values)) -SDL_PROC_UNUSED(void, glPixelMapusv, - (GLenum map, GLsizei mapsize, const GLushort * values)) -SDL_PROC_UNUSED(void, glPixelStoref, (GLenum pname, GLfloat param)) -SDL_PROC(void, glPixelStorei, (GLenum pname, GLint param)) -SDL_PROC_UNUSED(void, glPixelTransferf, (GLenum pname, GLfloat param)) -SDL_PROC_UNUSED(void, glPixelTransferi, (GLenum pname, GLint param)) -SDL_PROC_UNUSED(void, glPixelZoom, (GLfloat xfactor, GLfloat yfactor)) -SDL_PROC(void, glPointSize, (GLfloat size)) -SDL_PROC_UNUSED(void, glPolygonMode, (GLenum face, GLenum mode)) -SDL_PROC_UNUSED(void, glPolygonOffset, (GLfloat factor, GLfloat units)) -SDL_PROC_UNUSED(void, glPolygonStipple, (const GLubyte * mask)) -SDL_PROC_UNUSED(void, glPopAttrib, (void)) -SDL_PROC_UNUSED(void, glPopClientAttrib, (void)) -SDL_PROC(void, glPopMatrix, (void)) -SDL_PROC_UNUSED(void, glPopName, (void)) -SDL_PROC_UNUSED(void, glPrioritizeTextures, - (GLsizei n, const GLuint * textures, - const GLclampf * priorities)) -SDL_PROC_UNUSED(void, glPushAttrib, (GLbitfield mask)) -SDL_PROC_UNUSED(void, glPushClientAttrib, (GLbitfield mask)) -SDL_PROC(void, glPushMatrix, (void)) -SDL_PROC_UNUSED(void, glPushName, (GLuint name)) -SDL_PROC_UNUSED(void, glRasterPos2d, (GLdouble x, GLdouble y)) -SDL_PROC_UNUSED(void, glRasterPos2dv, (const GLdouble * v)) -SDL_PROC_UNUSED(void, glRasterPos2f, (GLfloat x, GLfloat y)) -SDL_PROC_UNUSED(void, glRasterPos2fv, (const GLfloat * v)) -SDL_PROC(void, glRasterPos2i, (GLint x, GLint y)) -SDL_PROC_UNUSED(void, glRasterPos2iv, (const GLint * v)) -SDL_PROC_UNUSED(void, glRasterPos2s, (GLshort x, GLshort y)) -SDL_PROC_UNUSED(void, glRasterPos2sv, (const GLshort * v)) -SDL_PROC_UNUSED(void, glRasterPos3d, (GLdouble x, GLdouble y, GLdouble z)) -SDL_PROC_UNUSED(void, glRasterPos3dv, (const GLdouble * v)) -SDL_PROC_UNUSED(void, glRasterPos3f, (GLfloat x, GLfloat y, GLfloat z)) -SDL_PROC_UNUSED(void, glRasterPos3fv, (const GLfloat * v)) -SDL_PROC_UNUSED(void, glRasterPos3i, (GLint x, GLint y, GLint z)) -SDL_PROC_UNUSED(void, glRasterPos3iv, (const GLint * v)) -SDL_PROC_UNUSED(void, glRasterPos3s, (GLshort x, GLshort y, GLshort z)) -SDL_PROC_UNUSED(void, glRasterPos3sv, (const GLshort * v)) -SDL_PROC_UNUSED(void, glRasterPos4d, - (GLdouble x, GLdouble y, GLdouble z, GLdouble w)) -SDL_PROC_UNUSED(void, glRasterPos4dv, (const GLdouble * v)) -SDL_PROC_UNUSED(void, glRasterPos4f, - (GLfloat x, GLfloat y, GLfloat z, GLfloat w)) -SDL_PROC_UNUSED(void, glRasterPos4fv, (const GLfloat * v)) -SDL_PROC_UNUSED(void, glRasterPos4i, (GLint x, GLint y, GLint z, GLint w)) -SDL_PROC_UNUSED(void, glRasterPos4iv, (const GLint * v)) -SDL_PROC_UNUSED(void, glRasterPos4s, - (GLshort x, GLshort y, GLshort z, GLshort w)) -SDL_PROC_UNUSED(void, glRasterPos4sv, (const GLshort * v)) -SDL_PROC(void, glReadBuffer, (GLenum mode)) -SDL_PROC(void, glReadPixels, - (GLint x, GLint y, GLsizei width, GLsizei height, - GLenum format, GLenum type, GLvoid * pixels)) -SDL_PROC_UNUSED(void, glRectd, - (GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2)) -SDL_PROC_UNUSED(void, glRectdv, (const GLdouble * v1, const GLdouble * v2)) -SDL_PROC(void, glRectf, - (GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)) -SDL_PROC_UNUSED(void, glRectfv, (const GLfloat * v1, const GLfloat * v2)) -SDL_PROC_UNUSED(void, glRecti, (GLint x1, GLint y1, GLint x2, GLint y2)) -SDL_PROC_UNUSED(void, glRectiv, (const GLint * v1, const GLint * v2)) -SDL_PROC_UNUSED(void, glRects, - (GLshort x1, GLshort y1, GLshort x2, GLshort y2)) -SDL_PROC_UNUSED(void, glRectsv, (const GLshort * v1, const GLshort * v2)) -SDL_PROC_UNUSED(GLint, glRenderMode, (GLenum mode)) -SDL_PROC(void, glRotated, - (GLdouble angle, GLdouble x, GLdouble y, GLdouble z)) -SDL_PROC(void, glRotatef, - (GLfloat angle, GLfloat x, GLfloat y, GLfloat z)) -SDL_PROC_UNUSED(void, glScaled, (GLdouble x, GLdouble y, GLdouble z)) -SDL_PROC_UNUSED(void, glScalef, (GLfloat x, GLfloat y, GLfloat z)) -SDL_PROC(void, glScissor, (GLint x, GLint y, GLsizei width, GLsizei height)) -SDL_PROC_UNUSED(void, glSelectBuffer, (GLsizei size, GLuint * buffer)) -SDL_PROC(void, glShadeModel, (GLenum mode)) -SDL_PROC_UNUSED(void, glStencilFunc, (GLenum func, GLint ref, GLuint mask)) -SDL_PROC_UNUSED(void, glStencilMask, (GLuint mask)) -SDL_PROC_UNUSED(void, glStencilOp, (GLenum fail, GLenum zfail, GLenum zpass)) -SDL_PROC_UNUSED(void, glTexCoord1d, (GLdouble s)) -SDL_PROC_UNUSED(void, glTexCoord1dv, (const GLdouble * v)) -SDL_PROC_UNUSED(void, glTexCoord1f, (GLfloat s)) -SDL_PROC_UNUSED(void, glTexCoord1fv, (const GLfloat * v)) -SDL_PROC_UNUSED(void, glTexCoord1i, (GLint s)) -SDL_PROC_UNUSED(void, glTexCoord1iv, (const GLint * v)) -SDL_PROC_UNUSED(void, glTexCoord1s, (GLshort s)) -SDL_PROC_UNUSED(void, glTexCoord1sv, (const GLshort * v)) -SDL_PROC_UNUSED(void, glTexCoord2d, (GLdouble s, GLdouble t)) -SDL_PROC_UNUSED(void, glTexCoord2dv, (const GLdouble * v)) -SDL_PROC(void, glTexCoord2f, (GLfloat s, GLfloat t)) -SDL_PROC_UNUSED(void, glTexCoord2fv, (const GLfloat * v)) -SDL_PROC_UNUSED(void, glTexCoord2i, (GLint s, GLint t)) -SDL_PROC_UNUSED(void, glTexCoord2iv, (const GLint * v)) -SDL_PROC_UNUSED(void, glTexCoord2s, (GLshort s, GLshort t)) -SDL_PROC_UNUSED(void, glTexCoord2sv, (const GLshort * v)) -SDL_PROC_UNUSED(void, glTexCoord3d, (GLdouble s, GLdouble t, GLdouble r)) -SDL_PROC_UNUSED(void, glTexCoord3dv, (const GLdouble * v)) -SDL_PROC_UNUSED(void, glTexCoord3f, (GLfloat s, GLfloat t, GLfloat r)) -SDL_PROC_UNUSED(void, glTexCoord3fv, (const GLfloat * v)) -SDL_PROC_UNUSED(void, glTexCoord3i, (GLint s, GLint t, GLint r)) -SDL_PROC_UNUSED(void, glTexCoord3iv, (const GLint * v)) -SDL_PROC_UNUSED(void, glTexCoord3s, (GLshort s, GLshort t, GLshort r)) -SDL_PROC_UNUSED(void, glTexCoord3sv, (const GLshort * v)) -SDL_PROC_UNUSED(void, glTexCoord4d, - (GLdouble s, GLdouble t, GLdouble r, GLdouble q)) -SDL_PROC_UNUSED(void, glTexCoord4dv, (const GLdouble * v)) -SDL_PROC_UNUSED(void, glTexCoord4f, - (GLfloat s, GLfloat t, GLfloat r, GLfloat q)) -SDL_PROC_UNUSED(void, glTexCoord4fv, (const GLfloat * v)) -SDL_PROC_UNUSED(void, glTexCoord4i, (GLint s, GLint t, GLint r, GLint q)) -SDL_PROC_UNUSED(void, glTexCoord4iv, (const GLint * v)) -SDL_PROC_UNUSED(void, glTexCoord4s, - (GLshort s, GLshort t, GLshort r, GLshort q)) -SDL_PROC_UNUSED(void, glTexCoord4sv, (const GLshort * v)) -SDL_PROC_UNUSED(void, glTexCoordPointer, - (GLint size, GLenum type, GLsizei stride, - const GLvoid * pointer)) -SDL_PROC(void, glTexEnvf, (GLenum target, GLenum pname, GLfloat param)) -SDL_PROC_UNUSED(void, glTexEnvfv, - (GLenum target, GLenum pname, const GLfloat * params)) -SDL_PROC_UNUSED(void, glTexEnvi, (GLenum target, GLenum pname, GLint param)) -SDL_PROC_UNUSED(void, glTexEnviv, - (GLenum target, GLenum pname, const GLint * params)) -SDL_PROC_UNUSED(void, glTexGend, (GLenum coord, GLenum pname, GLdouble param)) -SDL_PROC_UNUSED(void, glTexGendv, - (GLenum coord, GLenum pname, const GLdouble * params)) -SDL_PROC_UNUSED(void, glTexGenf, (GLenum coord, GLenum pname, GLfloat param)) -SDL_PROC_UNUSED(void, glTexGenfv, - (GLenum coord, GLenum pname, const GLfloat * params)) -SDL_PROC_UNUSED(void, glTexGeni, (GLenum coord, GLenum pname, GLint param)) -SDL_PROC_UNUSED(void, glTexGeniv, - (GLenum coord, GLenum pname, const GLint * params)) -SDL_PROC_UNUSED(void, glTexImage1D, - (GLenum target, GLint level, GLint internalformat, - GLsizei width, GLint border, GLenum format, GLenum type, - const GLvoid * pixels)) -SDL_PROC(void, glTexImage2D, - (GLenum target, GLint level, GLint internalformat, GLsizei width, - GLsizei height, GLint border, GLenum format, GLenum type, - const GLvoid * pixels)) -SDL_PROC_UNUSED(void, glTexParameterf, - (GLenum target, GLenum pname, GLfloat param)) -SDL_PROC_UNUSED(void, glTexParameterfv, - (GLenum target, GLenum pname, const GLfloat * params)) -SDL_PROC(void, glTexParameteri, (GLenum target, GLenum pname, GLint param)) -SDL_PROC_UNUSED(void, glTexParameteriv, - (GLenum target, GLenum pname, const GLint * params)) -SDL_PROC_UNUSED(void, glTexSubImage1D, - (GLenum target, GLint level, GLint xoffset, GLsizei width, - GLenum format, GLenum type, const GLvoid * pixels)) -SDL_PROC(void, glTexSubImage2D, - (GLenum target, GLint level, GLint xoffset, GLint yoffset, - GLsizei width, GLsizei height, GLenum format, GLenum type, - const GLvoid * pixels)) -SDL_PROC_UNUSED(void, glTranslated, (GLdouble x, GLdouble y, GLdouble z)) -SDL_PROC(void, glTranslatef, (GLfloat x, GLfloat y, GLfloat z)) -SDL_PROC_UNUSED(void, glVertex2d, (GLdouble x, GLdouble y)) -SDL_PROC_UNUSED(void, glVertex2dv, (const GLdouble * v)) -SDL_PROC(void, glVertex2f, (GLfloat x, GLfloat y)) -SDL_PROC_UNUSED(void, glVertex2fv, (const GLfloat * v)) -SDL_PROC_UNUSED(void, glVertex2i, (GLint x, GLint y)) -SDL_PROC_UNUSED(void, glVertex2iv, (const GLint * v)) -SDL_PROC_UNUSED(void, glVertex2s, (GLshort x, GLshort y)) -SDL_PROC_UNUSED(void, glVertex2sv, (const GLshort * v)) -SDL_PROC_UNUSED(void, glVertex3d, (GLdouble x, GLdouble y, GLdouble z)) -SDL_PROC_UNUSED(void, glVertex3dv, (const GLdouble * v)) -SDL_PROC_UNUSED(void, glVertex3f, (GLfloat x, GLfloat y, GLfloat z)) -SDL_PROC(void, glVertex3fv, (const GLfloat * v)) -SDL_PROC_UNUSED(void, glVertex3i, (GLint x, GLint y, GLint z)) -SDL_PROC_UNUSED(void, glVertex3iv, (const GLint * v)) -SDL_PROC_UNUSED(void, glVertex3s, (GLshort x, GLshort y, GLshort z)) -SDL_PROC_UNUSED(void, glVertex3sv, (const GLshort * v)) -SDL_PROC_UNUSED(void, glVertex4d, - (GLdouble x, GLdouble y, GLdouble z, GLdouble w)) -SDL_PROC_UNUSED(void, glVertex4dv, (const GLdouble * v)) -SDL_PROC_UNUSED(void, glVertex4f, - (GLfloat x, GLfloat y, GLfloat z, GLfloat w)) -SDL_PROC_UNUSED(void, glVertex4fv, (const GLfloat * v)) -SDL_PROC_UNUSED(void, glVertex4i, (GLint x, GLint y, GLint z, GLint w)) -SDL_PROC_UNUSED(void, glVertex4iv, (const GLint * v)) -SDL_PROC_UNUSED(void, glVertex4s, - (GLshort x, GLshort y, GLshort z, GLshort w)) -SDL_PROC_UNUSED(void, glVertex4sv, (const GLshort * v)) -SDL_PROC_UNUSED(void, glVertexPointer, - (GLint size, GLenum type, GLsizei stride, - const GLvoid * pointer)) -SDL_PROC(void, glViewport, (GLint x, GLint y, GLsizei width, GLsizei height)) - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/opengl/SDL_render_gl.c b/3rdparty/SDL2/src/render/opengl/SDL_render_gl.c deleted file mode 100644 index 1ca2cb5c4c0..00000000000 --- a/3rdparty/SDL2/src/render/opengl/SDL_render_gl.c +++ /dev/null @@ -1,1597 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../../SDL_internal.h" - -#if SDL_VIDEO_RENDER_OGL && !SDL_RENDER_DISABLED - -#include "SDL_hints.h" -#include "SDL_log.h" -#include "SDL_assert.h" -#include "SDL_opengl.h" -#include "../SDL_sysrender.h" -#include "SDL_shaders_gl.h" - -#ifdef __MACOSX__ -#include <OpenGL/OpenGL.h> -#endif - -/* To prevent unnecessary window recreation, - * these should match the defaults selected in SDL_GL_ResetAttributes - */ - -#define RENDERER_CONTEXT_MAJOR 2 -#define RENDERER_CONTEXT_MINOR 1 - -/* OpenGL renderer implementation */ - -/* Details on optimizing the texture path on Mac OS X: - http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_texturedata/opengl_texturedata.html -*/ - -/* Used to re-create the window with OpenGL capability */ -extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags); - -static const float inv255f = 1.0f / 255.0f; - -static SDL_Renderer *GL_CreateRenderer(SDL_Window * window, Uint32 flags); -static void GL_WindowEvent(SDL_Renderer * renderer, - const SDL_WindowEvent *event); -static int GL_GetOutputSize(SDL_Renderer * renderer, int *w, int *h); -static int GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); -static int GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, const void *pixels, - int pitch); -static int GL_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, - const Uint8 *Yplane, int Ypitch, - const Uint8 *Uplane, int Upitch, - const Uint8 *Vplane, int Vpitch); -static int GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, void **pixels, int *pitch); -static void GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); -static int GL_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture); -static int GL_UpdateViewport(SDL_Renderer * renderer); -static int GL_UpdateClipRect(SDL_Renderer * renderer); -static int GL_RenderClear(SDL_Renderer * renderer); -static int GL_RenderDrawPoints(SDL_Renderer * renderer, - const SDL_FPoint * points, int count); -static int GL_RenderDrawLines(SDL_Renderer * renderer, - const SDL_FPoint * points, int count); -static int GL_RenderFillRects(SDL_Renderer * renderer, - const SDL_FRect * rects, int count); -static int GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_FRect * dstrect); -static int GL_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_FRect * dstrect, - const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip); -static int GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, - Uint32 pixel_format, void * pixels, int pitch); -static void GL_RenderPresent(SDL_Renderer * renderer); -static void GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture); -static void GL_DestroyRenderer(SDL_Renderer * renderer); -static int GL_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh); -static int GL_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture); - -SDL_RenderDriver GL_RenderDriver = { - GL_CreateRenderer, - { - "opengl", - (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE), - 1, - {SDL_PIXELFORMAT_ARGB8888}, - 0, - 0} -}; - -typedef struct GL_FBOList GL_FBOList; - -struct GL_FBOList -{ - Uint32 w, h; - GLuint FBO; - GL_FBOList *next; -}; - -typedef struct -{ - SDL_GLContext context; - - SDL_bool debug_enabled; - SDL_bool GL_ARB_debug_output_supported; - int errors; - char **error_messages; - GLDEBUGPROCARB next_error_callback; - GLvoid *next_error_userparam; - - SDL_bool GL_ARB_texture_non_power_of_two_supported; - SDL_bool GL_ARB_texture_rectangle_supported; - struct { - GL_Shader shader; - Uint32 color; - int blendMode; - } current; - - SDL_bool GL_EXT_framebuffer_object_supported; - GL_FBOList *framebuffers; - - /* OpenGL functions */ -#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params; -#include "SDL_glfuncs.h" -#undef SDL_PROC - - /* Multitexture support */ - SDL_bool GL_ARB_multitexture_supported; - PFNGLACTIVETEXTUREARBPROC glActiveTextureARB; - GLint num_texture_units; - - PFNGLGENFRAMEBUFFERSEXTPROC glGenFramebuffersEXT; - PFNGLDELETEFRAMEBUFFERSEXTPROC glDeleteFramebuffersEXT; - PFNGLFRAMEBUFFERTEXTURE2DEXTPROC glFramebufferTexture2DEXT; - PFNGLBINDFRAMEBUFFEREXTPROC glBindFramebufferEXT; - PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC glCheckFramebufferStatusEXT; - - /* Shader support */ - GL_ShaderContext *shaders; - -} GL_RenderData; - -typedef struct -{ - GLuint texture; - GLenum type; - GLfloat texw; - GLfloat texh; - GLenum format; - GLenum formattype; - void *pixels; - int pitch; - SDL_Rect locked_rect; - - /* YUV texture support */ - SDL_bool yuv; - SDL_bool nv12; - GLuint utexture; - GLuint vtexture; - - GL_FBOList *fbo; -} GL_TextureData; - -SDL_FORCE_INLINE const char* -GL_TranslateError (GLenum error) -{ -#define GL_ERROR_TRANSLATE(e) case e: return #e; - switch (error) { - GL_ERROR_TRANSLATE(GL_INVALID_ENUM) - GL_ERROR_TRANSLATE(GL_INVALID_VALUE) - GL_ERROR_TRANSLATE(GL_INVALID_OPERATION) - GL_ERROR_TRANSLATE(GL_OUT_OF_MEMORY) - GL_ERROR_TRANSLATE(GL_NO_ERROR) - GL_ERROR_TRANSLATE(GL_STACK_OVERFLOW) - GL_ERROR_TRANSLATE(GL_STACK_UNDERFLOW) - GL_ERROR_TRANSLATE(GL_TABLE_TOO_LARGE) - default: - return "UNKNOWN"; -} -#undef GL_ERROR_TRANSLATE -} - -SDL_FORCE_INLINE void -GL_ClearErrors(SDL_Renderer *renderer) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - - if (!data->debug_enabled) - { - return; - } - if (data->GL_ARB_debug_output_supported) { - if (data->errors) { - int i; - for (i = 0; i < data->errors; ++i) { - SDL_free(data->error_messages[i]); - } - SDL_free(data->error_messages); - - data->errors = 0; - data->error_messages = NULL; - } - } else { - while (data->glGetError() != GL_NO_ERROR) { - continue; - } - } -} - -SDL_FORCE_INLINE int -GL_CheckAllErrors (const char *prefix, SDL_Renderer *renderer, const char *file, int line, const char *function) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - int ret = 0; - - if (!data->debug_enabled) - { - return 0; - } - if (data->GL_ARB_debug_output_supported) { - if (data->errors) { - int i; - for (i = 0; i < data->errors; ++i) { - SDL_SetError("%s: %s (%d): %s %s", prefix, file, line, function, data->error_messages[i]); - ret = -1; - } - GL_ClearErrors(renderer); - } - } else { - /* check gl errors (can return multiple errors) */ - for (;;) { - GLenum error = data->glGetError(); - if (error != GL_NO_ERROR) { - if (prefix == NULL || prefix[0] == '\0') { - prefix = "generic"; - } - SDL_SetError("%s: %s (%d): %s %s (0x%X)", prefix, file, line, function, GL_TranslateError(error), error); - ret = -1; - } else { - break; - } - } - } - return ret; -} - -#if 0 -#define GL_CheckError(prefix, renderer) -#elif defined(_MSC_VER) -#define GL_CheckError(prefix, renderer) GL_CheckAllErrors(prefix, renderer, __FILE__, __LINE__, __FUNCTION__) -#else -#define GL_CheckError(prefix, renderer) GL_CheckAllErrors(prefix, renderer, __FILE__, __LINE__, __PRETTY_FUNCTION__) -#endif - -static int -GL_LoadFunctions(GL_RenderData * data) -{ -#ifdef __SDL_NOGETPROCADDR__ -#define SDL_PROC(ret,func,params) data->func=func; -#else -#define SDL_PROC(ret,func,params) \ - do { \ - data->func = SDL_GL_GetProcAddress(#func); \ - if ( ! data->func ) { \ - return SDL_SetError("Couldn't load GL function %s: %s\n", #func, SDL_GetError()); \ - } \ - } while ( 0 ); -#endif /* __SDL_NOGETPROCADDR__ */ - -#include "SDL_glfuncs.h" -#undef SDL_PROC - return 0; -} - -static SDL_GLContext SDL_CurrentContext = NULL; - -static int -GL_ActivateRenderer(SDL_Renderer * renderer) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - - if (SDL_CurrentContext != data->context || - SDL_GL_GetCurrentContext() != data->context) { - if (SDL_GL_MakeCurrent(renderer->window, data->context) < 0) { - return -1; - } - SDL_CurrentContext = data->context; - - GL_UpdateViewport(renderer); - } - - GL_ClearErrors(renderer); - - return 0; -} - -/* This is called if we need to invalidate all of the SDL OpenGL state */ -static void -GL_ResetState(SDL_Renderer *renderer) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - - if (SDL_GL_GetCurrentContext() == data->context) { - GL_UpdateViewport(renderer); - } else { - GL_ActivateRenderer(renderer); - } - - data->current.shader = SHADER_NONE; - data->current.color = 0; - data->current.blendMode = -1; - - data->glDisable(GL_DEPTH_TEST); - data->glDisable(GL_CULL_FACE); - /* This ended up causing video discrepancies between OpenGL and Direct3D */ - /* data->glEnable(GL_LINE_SMOOTH); */ - - data->glMatrixMode(GL_MODELVIEW); - data->glLoadIdentity(); - - GL_CheckError("", renderer); -} - -static void APIENTRY -GL_HandleDebugMessage(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const char *message, const void *userParam) -{ - SDL_Renderer *renderer = (SDL_Renderer *) userParam; - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - - if (type == GL_DEBUG_TYPE_ERROR_ARB) { - /* Record this error */ - int errors = data->errors + 1; - char **error_messages = SDL_realloc(data->error_messages, errors * sizeof(*data->error_messages)); - if (error_messages) { - data->errors = errors; - data->error_messages = error_messages; - data->error_messages[data->errors-1] = SDL_strdup(message); - } - } - - /* If there's another error callback, pass it along, otherwise log it */ - if (data->next_error_callback) { - data->next_error_callback(source, type, id, severity, length, message, data->next_error_userparam); - } else { - if (type == GL_DEBUG_TYPE_ERROR_ARB) { - SDL_LogError(SDL_LOG_CATEGORY_RENDER, "%s", message); - } else { - SDL_LogDebug(SDL_LOG_CATEGORY_RENDER, "%s", message); - } - } -} - -static GL_FBOList * -GL_GetFBO(GL_RenderData *data, Uint32 w, Uint32 h) -{ - GL_FBOList *result = data->framebuffers; - - while (result && ((result->w != w) || (result->h != h))) { - result = result->next; - } - - if (!result) { - result = SDL_malloc(sizeof(GL_FBOList)); - if (result) { - result->w = w; - result->h = h; - data->glGenFramebuffersEXT(1, &result->FBO); - result->next = data->framebuffers; - data->framebuffers = result; - } - } - return result; -} - -SDL_Renderer * -GL_CreateRenderer(SDL_Window * window, Uint32 flags) -{ - SDL_Renderer *renderer; - GL_RenderData *data; - GLint value; - Uint32 window_flags; - int profile_mask = 0, major = 0, minor = 0; - SDL_bool changed_window = SDL_FALSE; - - SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profile_mask); - SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major); - SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor); - - window_flags = SDL_GetWindowFlags(window); - if (!(window_flags & SDL_WINDOW_OPENGL) || - profile_mask == SDL_GL_CONTEXT_PROFILE_ES || major != RENDERER_CONTEXT_MAJOR || minor != RENDERER_CONTEXT_MINOR) { - - changed_window = SDL_TRUE; - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR); - - if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 0) { - goto error; - } - } - - renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); - if (!renderer) { - SDL_OutOfMemory(); - goto error; - } - - data = (GL_RenderData *) SDL_calloc(1, sizeof(*data)); - if (!data) { - GL_DestroyRenderer(renderer); - SDL_OutOfMemory(); - goto error; - } - - renderer->WindowEvent = GL_WindowEvent; - renderer->GetOutputSize = GL_GetOutputSize; - renderer->CreateTexture = GL_CreateTexture; - renderer->UpdateTexture = GL_UpdateTexture; - renderer->UpdateTextureYUV = GL_UpdateTextureYUV; - renderer->LockTexture = GL_LockTexture; - renderer->UnlockTexture = GL_UnlockTexture; - renderer->SetRenderTarget = GL_SetRenderTarget; - renderer->UpdateViewport = GL_UpdateViewport; - renderer->UpdateClipRect = GL_UpdateClipRect; - renderer->RenderClear = GL_RenderClear; - renderer->RenderDrawPoints = GL_RenderDrawPoints; - renderer->RenderDrawLines = GL_RenderDrawLines; - renderer->RenderFillRects = GL_RenderFillRects; - renderer->RenderCopy = GL_RenderCopy; - renderer->RenderCopyEx = GL_RenderCopyEx; - renderer->RenderReadPixels = GL_RenderReadPixels; - renderer->RenderPresent = GL_RenderPresent; - renderer->DestroyTexture = GL_DestroyTexture; - renderer->DestroyRenderer = GL_DestroyRenderer; - renderer->GL_BindTexture = GL_BindTexture; - renderer->GL_UnbindTexture = GL_UnbindTexture; - renderer->info = GL_RenderDriver.info; - renderer->info.flags = SDL_RENDERER_ACCELERATED; - renderer->driverdata = data; - renderer->window = window; - - data->context = SDL_GL_CreateContext(window); - if (!data->context) { - GL_DestroyRenderer(renderer); - goto error; - } - if (SDL_GL_MakeCurrent(window, data->context) < 0) { - GL_DestroyRenderer(renderer); - goto error; - } - - if (GL_LoadFunctions(data) < 0) { - GL_DestroyRenderer(renderer); - goto error; - } - -#ifdef __MACOSX__ - /* Enable multi-threaded rendering */ - /* Disabled until Ryan finishes his VBO/PBO code... - CGLEnable(CGLGetCurrentContext(), kCGLCEMPEngine); - */ -#endif - - if (flags & SDL_RENDERER_PRESENTVSYNC) { - SDL_GL_SetSwapInterval(1); - } else { - SDL_GL_SetSwapInterval(0); - } - if (SDL_GL_GetSwapInterval() > 0) { - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; - } - - /* Check for debug output support */ - if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_FLAGS, &value) == 0 && - (value & SDL_GL_CONTEXT_DEBUG_FLAG)) { - data->debug_enabled = SDL_TRUE; - } - if (data->debug_enabled && SDL_GL_ExtensionSupported("GL_ARB_debug_output")) { - PFNGLDEBUGMESSAGECALLBACKARBPROC glDebugMessageCallbackARBFunc = (PFNGLDEBUGMESSAGECALLBACKARBPROC) SDL_GL_GetProcAddress("glDebugMessageCallbackARB"); - - data->GL_ARB_debug_output_supported = SDL_TRUE; - data->glGetPointerv(GL_DEBUG_CALLBACK_FUNCTION_ARB, (GLvoid **)&data->next_error_callback); - data->glGetPointerv(GL_DEBUG_CALLBACK_USER_PARAM_ARB, &data->next_error_userparam); - glDebugMessageCallbackARBFunc(GL_HandleDebugMessage, renderer); - - /* Make sure our callback is called when errors actually happen */ - data->glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB); - } - - if (SDL_GL_ExtensionSupported("GL_ARB_texture_non_power_of_two")) { - data->GL_ARB_texture_non_power_of_two_supported = SDL_TRUE; - } else if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle") || - SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) { - data->GL_ARB_texture_rectangle_supported = SDL_TRUE; - } - if (data->GL_ARB_texture_rectangle_supported) { - data->glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, &value); - renderer->info.max_texture_width = value; - renderer->info.max_texture_height = value; - } else { - data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value); - renderer->info.max_texture_width = value; - renderer->info.max_texture_height = value; - } - - /* Check for multitexture support */ - if (SDL_GL_ExtensionSupported("GL_ARB_multitexture")) { - data->glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC) SDL_GL_GetProcAddress("glActiveTextureARB"); - if (data->glActiveTextureARB) { - data->GL_ARB_multitexture_supported = SDL_TRUE; - data->glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &data->num_texture_units); - } - } - - /* Check for shader support */ - if (SDL_GetHintBoolean(SDL_HINT_RENDER_OPENGL_SHADERS, SDL_TRUE)) { - data->shaders = GL_CreateShaderContext(); - } - SDL_LogInfo(SDL_LOG_CATEGORY_RENDER, "OpenGL shaders: %s", - data->shaders ? "ENABLED" : "DISABLED"); - - /* We support YV12 textures using 3 textures and a shader */ - if (data->shaders && data->num_texture_units >= 3) { - renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_YV12; - renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_IYUV; - renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_NV12; - renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_NV21; - } - -#ifdef __MACOSX__ - renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_UYVY; -#endif - - if (SDL_GL_ExtensionSupported("GL_EXT_framebuffer_object")) { - data->GL_EXT_framebuffer_object_supported = SDL_TRUE; - data->glGenFramebuffersEXT = (PFNGLGENFRAMEBUFFERSEXTPROC) - SDL_GL_GetProcAddress("glGenFramebuffersEXT"); - data->glDeleteFramebuffersEXT = (PFNGLDELETEFRAMEBUFFERSEXTPROC) - SDL_GL_GetProcAddress("glDeleteFramebuffersEXT"); - data->glFramebufferTexture2DEXT = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) - SDL_GL_GetProcAddress("glFramebufferTexture2DEXT"); - data->glBindFramebufferEXT = (PFNGLBINDFRAMEBUFFEREXTPROC) - SDL_GL_GetProcAddress("glBindFramebufferEXT"); - data->glCheckFramebufferStatusEXT = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) - SDL_GL_GetProcAddress("glCheckFramebufferStatusEXT"); - renderer->info.flags |= SDL_RENDERER_TARGETTEXTURE; - } - data->framebuffers = NULL; - - /* Set up parameters for rendering */ - GL_ResetState(renderer); - - return renderer; - -error: - if (changed_window) { - /* Uh oh, better try to put it back... */ - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile_mask); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, major); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minor); - SDL_RecreateWindow(window, window_flags); - } - return NULL; -} - -static void -GL_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event) -{ - if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED || - event->event == SDL_WINDOWEVENT_SHOWN || - event->event == SDL_WINDOWEVENT_HIDDEN) { - /* Rebind the context to the window area and update matrices */ - SDL_CurrentContext = NULL; - } -} - -static int -GL_GetOutputSize(SDL_Renderer * renderer, int *w, int *h) -{ - SDL_GL_GetDrawableSize(renderer->window, w, h); - return 0; -} - -SDL_FORCE_INLINE int -power_of_2(int input) -{ - int value = 1; - - while (value < input) { - value <<= 1; - } - return value; -} - -SDL_FORCE_INLINE SDL_bool -convert_format(GL_RenderData *renderdata, Uint32 pixel_format, - GLint* internalFormat, GLenum* format, GLenum* type) -{ - switch (pixel_format) { - case SDL_PIXELFORMAT_ARGB8888: - *internalFormat = GL_RGBA8; - *format = GL_BGRA; - *type = GL_UNSIGNED_INT_8_8_8_8_REV; - break; - case SDL_PIXELFORMAT_YV12: - case SDL_PIXELFORMAT_IYUV: - case SDL_PIXELFORMAT_NV12: - case SDL_PIXELFORMAT_NV21: - *internalFormat = GL_LUMINANCE; - *format = GL_LUMINANCE; - *type = GL_UNSIGNED_BYTE; - break; -#ifdef __MACOSX__ - case SDL_PIXELFORMAT_UYVY: - *internalFormat = GL_RGB8; - *format = GL_YCBCR_422_APPLE; - *type = GL_UNSIGNED_SHORT_8_8_APPLE; - break; -#endif - default: - return SDL_FALSE; - } - return SDL_TRUE; -} - -static GLenum -GetScaleQuality(void) -{ - const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY); - - if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) { - return GL_NEAREST; - } else { - return GL_LINEAR; - } -} - -static int -GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata; - GL_TextureData *data; - GLint internalFormat; - GLenum format, type; - int texture_w, texture_h; - GLenum scaleMode; - - GL_ActivateRenderer(renderer); - - if (texture->access == SDL_TEXTUREACCESS_TARGET && - !renderdata->GL_EXT_framebuffer_object_supported) { - return SDL_SetError("Render targets not supported by OpenGL"); - } - - if (!convert_format(renderdata, texture->format, &internalFormat, - &format, &type)) { - return SDL_SetError("Texture format %s not supported by OpenGL", - SDL_GetPixelFormatName(texture->format)); - } - - data = (GL_TextureData *) SDL_calloc(1, sizeof(*data)); - if (!data) { - return SDL_OutOfMemory(); - } - - if (texture->access == SDL_TEXTUREACCESS_STREAMING) { - size_t size; - data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format); - size = texture->h * data->pitch; - if (texture->format == SDL_PIXELFORMAT_YV12 || - texture->format == SDL_PIXELFORMAT_IYUV) { - /* Need to add size for the U and V planes */ - size += (2 * (texture->h * data->pitch) / 4); - } - if (texture->format == SDL_PIXELFORMAT_NV12 || - texture->format == SDL_PIXELFORMAT_NV21) { - /* Need to add size for the U/V plane */ - size += ((texture->h * data->pitch) / 2); - } - data->pixels = SDL_calloc(1, size); - if (!data->pixels) { - SDL_free(data); - return SDL_OutOfMemory(); - } - } - - if (texture->access == SDL_TEXTUREACCESS_TARGET) { - data->fbo = GL_GetFBO(renderdata, texture->w, texture->h); - } else { - data->fbo = NULL; - } - - GL_CheckError("", renderer); - renderdata->glGenTextures(1, &data->texture); - if (GL_CheckError("glGenTextures()", renderer) < 0) { - if (data->pixels) { - SDL_free(data->pixels); - } - SDL_free(data); - return -1; - } - texture->driverdata = data; - - if (renderdata->GL_ARB_texture_non_power_of_two_supported) { - data->type = GL_TEXTURE_2D; - texture_w = texture->w; - texture_h = texture->h; - data->texw = 1.0f; - data->texh = 1.0f; - } else if (renderdata->GL_ARB_texture_rectangle_supported) { - data->type = GL_TEXTURE_RECTANGLE_ARB; - texture_w = texture->w; - texture_h = texture->h; - data->texw = (GLfloat) texture_w; - data->texh = (GLfloat) texture_h; - } else { - data->type = GL_TEXTURE_2D; - texture_w = power_of_2(texture->w); - texture_h = power_of_2(texture->h); - data->texw = (GLfloat) (texture->w) / texture_w; - data->texh = (GLfloat) texture->h / texture_h; - } - - data->format = format; - data->formattype = type; - scaleMode = GetScaleQuality(); - renderdata->glEnable(data->type); - renderdata->glBindTexture(data->type, data->texture); - renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER, scaleMode); - renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER, scaleMode); - /* According to the spec, CLAMP_TO_EDGE is the default for TEXTURE_RECTANGLE - and setting it causes an INVALID_ENUM error in the latest NVidia drivers. - */ - if (data->type != GL_TEXTURE_RECTANGLE_ARB) { - renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S, - GL_CLAMP_TO_EDGE); - renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T, - GL_CLAMP_TO_EDGE); - } -#ifdef __MACOSX__ -#ifndef GL_TEXTURE_STORAGE_HINT_APPLE -#define GL_TEXTURE_STORAGE_HINT_APPLE 0x85BC -#endif -#ifndef STORAGE_CACHED_APPLE -#define STORAGE_CACHED_APPLE 0x85BE -#endif -#ifndef STORAGE_SHARED_APPLE -#define STORAGE_SHARED_APPLE 0x85BF -#endif - if (texture->access == SDL_TEXTUREACCESS_STREAMING) { - renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE, - GL_STORAGE_SHARED_APPLE); - } else { - renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE, - GL_STORAGE_CACHED_APPLE); - } - if (texture->access == SDL_TEXTUREACCESS_STREAMING - && texture->format == SDL_PIXELFORMAT_ARGB8888 - && (texture->w % 8) == 0) { - renderdata->glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE); - renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, - (data->pitch / SDL_BYTESPERPIXEL(texture->format))); - renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w, - texture_h, 0, format, type, data->pixels); - renderdata->glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE); - } - else -#endif - { - renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w, - texture_h, 0, format, type, NULL); - } - renderdata->glDisable(data->type); - if (GL_CheckError("glTexImage2D()", renderer) < 0) { - return -1; - } - - if (texture->format == SDL_PIXELFORMAT_YV12 || - texture->format == SDL_PIXELFORMAT_IYUV) { - data->yuv = SDL_TRUE; - - renderdata->glGenTextures(1, &data->utexture); - renderdata->glGenTextures(1, &data->vtexture); - renderdata->glEnable(data->type); - - renderdata->glBindTexture(data->type, data->utexture); - renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER, - scaleMode); - renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER, - scaleMode); - renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S, - GL_CLAMP_TO_EDGE); - renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T, - GL_CLAMP_TO_EDGE); - renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w/2, - texture_h/2, 0, format, type, NULL); - - renderdata->glBindTexture(data->type, data->vtexture); - renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER, - scaleMode); - renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER, - scaleMode); - renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S, - GL_CLAMP_TO_EDGE); - renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T, - GL_CLAMP_TO_EDGE); - renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w/2, - texture_h/2, 0, format, type, NULL); - - renderdata->glDisable(data->type); - } - - if (texture->format == SDL_PIXELFORMAT_NV12 || - texture->format == SDL_PIXELFORMAT_NV21) { - data->nv12 = SDL_TRUE; - - renderdata->glGenTextures(1, &data->utexture); - renderdata->glEnable(data->type); - - renderdata->glBindTexture(data->type, data->utexture); - renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER, - scaleMode); - renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER, - scaleMode); - renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S, - GL_CLAMP_TO_EDGE); - renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T, - GL_CLAMP_TO_EDGE); - renderdata->glTexImage2D(data->type, 0, GL_LUMINANCE_ALPHA, texture_w/2, - texture_h/2, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, NULL); - renderdata->glDisable(data->type); - } - - return GL_CheckError("", renderer); -} - -static int -GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, const void *pixels, int pitch) -{ - GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata; - GL_TextureData *data = (GL_TextureData *) texture->driverdata; - const int texturebpp = SDL_BYTESPERPIXEL(texture->format); - - SDL_assert(texturebpp != 0); /* otherwise, division by zero later. */ - - GL_ActivateRenderer(renderer); - - renderdata->glEnable(data->type); - renderdata->glBindTexture(data->type, data->texture); - renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, (pitch / texturebpp)); - renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w, - rect->h, data->format, data->formattype, - pixels); - if (data->yuv) { - renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, (pitch / 2)); - - /* Skip to the correct offset into the next texture */ - pixels = (const void*)((const Uint8*)pixels + rect->h * pitch); - if (texture->format == SDL_PIXELFORMAT_YV12) { - renderdata->glBindTexture(data->type, data->vtexture); - } else { - renderdata->glBindTexture(data->type, data->utexture); - } - renderdata->glTexSubImage2D(data->type, 0, rect->x/2, rect->y/2, - rect->w/2, rect->h/2, - data->format, data->formattype, pixels); - - /* Skip to the correct offset into the next texture */ - pixels = (const void*)((const Uint8*)pixels + (rect->h * pitch)/4); - if (texture->format == SDL_PIXELFORMAT_YV12) { - renderdata->glBindTexture(data->type, data->utexture); - } else { - renderdata->glBindTexture(data->type, data->vtexture); - } - renderdata->glTexSubImage2D(data->type, 0, rect->x/2, rect->y/2, - rect->w/2, rect->h/2, - data->format, data->formattype, pixels); - } - - if (data->nv12) { - renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, (pitch / 2)); - - /* Skip to the correct offset into the next texture */ - pixels = (const void*)((const Uint8*)pixels + rect->h * pitch); - renderdata->glBindTexture(data->type, data->utexture); - renderdata->glTexSubImage2D(data->type, 0, rect->x/2, rect->y/2, - rect->w/2, rect->h/2, - GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, pixels); - } - renderdata->glDisable(data->type); - - return GL_CheckError("glTexSubImage2D()", renderer); -} - -static int -GL_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, - const Uint8 *Yplane, int Ypitch, - const Uint8 *Uplane, int Upitch, - const Uint8 *Vplane, int Vpitch) -{ - GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata; - GL_TextureData *data = (GL_TextureData *) texture->driverdata; - - GL_ActivateRenderer(renderer); - - renderdata->glEnable(data->type); - renderdata->glBindTexture(data->type, data->texture); - renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, Ypitch); - renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w, - rect->h, data->format, data->formattype, - Yplane); - - renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, Upitch); - renderdata->glBindTexture(data->type, data->utexture); - renderdata->glTexSubImage2D(data->type, 0, rect->x/2, rect->y/2, - rect->w/2, rect->h/2, - data->format, data->formattype, Uplane); - - renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, Vpitch); - renderdata->glBindTexture(data->type, data->vtexture); - renderdata->glTexSubImage2D(data->type, 0, rect->x/2, rect->y/2, - rect->w/2, rect->h/2, - data->format, data->formattype, Vplane); - renderdata->glDisable(data->type); - - return GL_CheckError("glTexSubImage2D()", renderer); -} - -static int -GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, void **pixels, int *pitch) -{ - GL_TextureData *data = (GL_TextureData *) texture->driverdata; - - data->locked_rect = *rect; - *pixels = - (void *) ((Uint8 *) data->pixels + rect->y * data->pitch + - rect->x * SDL_BYTESPERPIXEL(texture->format)); - *pitch = data->pitch; - return 0; -} - -static void -GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - GL_TextureData *data = (GL_TextureData *) texture->driverdata; - const SDL_Rect *rect; - void *pixels; - - rect = &data->locked_rect; - pixels = - (void *) ((Uint8 *) data->pixels + rect->y * data->pitch + - rect->x * SDL_BYTESPERPIXEL(texture->format)); - GL_UpdateTexture(renderer, texture, rect, pixels, data->pitch); -} - -static int -GL_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - GL_TextureData *texturedata; - GLenum status; - - GL_ActivateRenderer(renderer); - - if (!data->GL_EXT_framebuffer_object_supported) { - return SDL_SetError("Render targets not supported by OpenGL"); - } - - if (texture == NULL) { - data->glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); - return 0; - } - - texturedata = (GL_TextureData *) texture->driverdata; - data->glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, texturedata->fbo->FBO); - /* TODO: check if texture pixel format allows this operation */ - data->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, texturedata->type, texturedata->texture, 0); - /* Check FBO status */ - status = data->glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); - if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { - return SDL_SetError("glFramebufferTexture2DEXT() failed"); - } - return 0; -} - -static int -GL_UpdateViewport(SDL_Renderer * renderer) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - - if (SDL_CurrentContext != data->context) { - /* We'll update the viewport after we rebind the context */ - return 0; - } - - if (renderer->target) { - data->glViewport(renderer->viewport.x, renderer->viewport.y, - renderer->viewport.w, renderer->viewport.h); - } else { - int w, h; - - SDL_GL_GetDrawableSize(renderer->window, &w, &h); - data->glViewport(renderer->viewport.x, (h - renderer->viewport.y - renderer->viewport.h), - renderer->viewport.w, renderer->viewport.h); - } - - data->glMatrixMode(GL_PROJECTION); - data->glLoadIdentity(); - if (renderer->viewport.w && renderer->viewport.h) { - if (renderer->target) { - data->glOrtho((GLdouble) 0, - (GLdouble) renderer->viewport.w, - (GLdouble) 0, - (GLdouble) renderer->viewport.h, - 0.0, 1.0); - } else { - data->glOrtho((GLdouble) 0, - (GLdouble) renderer->viewport.w, - (GLdouble) renderer->viewport.h, - (GLdouble) 0, - 0.0, 1.0); - } - } - return GL_CheckError("", renderer); -} - -static int -GL_UpdateClipRect(SDL_Renderer * renderer) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - - if (renderer->clipping_enabled) { - const SDL_Rect *rect = &renderer->clip_rect; - data->glEnable(GL_SCISSOR_TEST); - if (renderer->target) { - data->glScissor(renderer->viewport.x + rect->x, renderer->viewport.y + rect->y, rect->w, rect->h); - } else { - int w, h; - - SDL_GL_GetDrawableSize(renderer->window, &w, &h); - data->glScissor(renderer->viewport.x + rect->x, h - renderer->viewport.y - rect->y - rect->h, rect->w, rect->h); - } - } else { - data->glDisable(GL_SCISSOR_TEST); - } - return 0; -} - -static void -GL_SetShader(GL_RenderData * data, GL_Shader shader) -{ - if (data->shaders && shader != data->current.shader) { - GL_SelectShader(data->shaders, shader); - data->current.shader = shader; - } -} - -static void -GL_SetColor(GL_RenderData * data, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - Uint32 color = ((a << 24) | (r << 16) | (g << 8) | b); - - if (color != data->current.color) { - data->glColor4f((GLfloat) r * inv255f, - (GLfloat) g * inv255f, - (GLfloat) b * inv255f, - (GLfloat) a * inv255f); - data->current.color = color; - } -} - -static void -GL_SetBlendMode(GL_RenderData * data, int blendMode) -{ - if (blendMode != data->current.blendMode) { - switch (blendMode) { - case SDL_BLENDMODE_NONE: - data->glDisable(GL_BLEND); - break; - case SDL_BLENDMODE_BLEND: - data->glEnable(GL_BLEND); - data->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - break; - case SDL_BLENDMODE_ADD: - data->glEnable(GL_BLEND); - data->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ZERO, GL_ONE); - break; - case SDL_BLENDMODE_MOD: - data->glEnable(GL_BLEND); - data->glBlendFuncSeparate(GL_ZERO, GL_SRC_COLOR, GL_ZERO, GL_ONE); - break; - } - data->current.blendMode = blendMode; - } -} - -static void -GL_SetDrawingState(SDL_Renderer * renderer) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - - GL_ActivateRenderer(renderer); - - GL_SetColor(data, renderer->r, - renderer->g, - renderer->b, - renderer->a); - - GL_SetBlendMode(data, renderer->blendMode); - - GL_SetShader(data, SHADER_SOLID); -} - -static int -GL_RenderClear(SDL_Renderer * renderer) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - - GL_ActivateRenderer(renderer); - - data->glClearColor((GLfloat) renderer->r * inv255f, - (GLfloat) renderer->g * inv255f, - (GLfloat) renderer->b * inv255f, - (GLfloat) renderer->a * inv255f); - - if (renderer->clipping_enabled) { - data->glDisable(GL_SCISSOR_TEST); - } - - data->glClear(GL_COLOR_BUFFER_BIT); - - if (renderer->clipping_enabled) { - data->glEnable(GL_SCISSOR_TEST); - } - - return 0; -} - -static int -GL_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points, - int count) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - int i; - - GL_SetDrawingState(renderer); - - data->glBegin(GL_POINTS); - for (i = 0; i < count; ++i) { - data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y); - } - data->glEnd(); - - return 0; -} - -static int -GL_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points, - int count) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - int i; - - GL_SetDrawingState(renderer); - - if (count > 2 && - points[0].x == points[count-1].x && points[0].y == points[count-1].y) { - data->glBegin(GL_LINE_LOOP); - /* GL_LINE_LOOP takes care of the final segment */ - --count; - for (i = 0; i < count; ++i) { - data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y); - } - data->glEnd(); - } else { -#if defined(__MACOSX__) || defined(__WIN32__) -#else - int x1, y1, x2, y2; -#endif - - data->glBegin(GL_LINE_STRIP); - for (i = 0; i < count; ++i) { - data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y); - } - data->glEnd(); - - /* The line is half open, so we need one more point to complete it. - * http://www.opengl.org/documentation/specs/version1.1/glspec1.1/node47.html - * If we have to, we can use vertical line and horizontal line textures - * for vertical and horizontal lines, and then create custom textures - * for diagonal lines and software render those. It's terrible, but at - * least it would be pixel perfect. - */ - data->glBegin(GL_POINTS); -#if defined(__MACOSX__) || defined(__WIN32__) - /* Mac OS X and Windows seem to always leave the last point open */ - data->glVertex2f(0.5f + points[count-1].x, 0.5f + points[count-1].y); -#else - /* Linux seems to leave the right-most or bottom-most point open */ - x1 = points[0].x; - y1 = points[0].y; - x2 = points[count-1].x; - y2 = points[count-1].y; - - if (x1 > x2) { - data->glVertex2f(0.5f + x1, 0.5f + y1); - } else if (x2 > x1) { - data->glVertex2f(0.5f + x2, 0.5f + y2); - } - if (y1 > y2) { - data->glVertex2f(0.5f + x1, 0.5f + y1); - } else if (y2 > y1) { - data->glVertex2f(0.5f + x2, 0.5f + y2); - } -#endif - data->glEnd(); - } - return GL_CheckError("", renderer); -} - -static int -GL_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects, int count) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - int i; - - GL_SetDrawingState(renderer); - - for (i = 0; i < count; ++i) { - const SDL_FRect *rect = &rects[i]; - - data->glRectf(rect->x, rect->y, rect->x + rect->w, rect->y + rect->h); - } - return GL_CheckError("", renderer); -} - -static int -GL_SetupCopy(SDL_Renderer * renderer, SDL_Texture * texture) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata; - - data->glEnable(texturedata->type); - if (texturedata->yuv) { - data->glActiveTextureARB(GL_TEXTURE2_ARB); - data->glBindTexture(texturedata->type, texturedata->vtexture); - - data->glActiveTextureARB(GL_TEXTURE1_ARB); - data->glBindTexture(texturedata->type, texturedata->utexture); - - data->glActiveTextureARB(GL_TEXTURE0_ARB); - } - if (texturedata->nv12) { - data->glActiveTextureARB(GL_TEXTURE1_ARB); - data->glBindTexture(texturedata->type, texturedata->utexture); - - data->glActiveTextureARB(GL_TEXTURE0_ARB); - } - data->glBindTexture(texturedata->type, texturedata->texture); - - if (texture->modMode) { - GL_SetColor(data, texture->r, texture->g, texture->b, texture->a); - } else { - GL_SetColor(data, 255, 255, 255, 255); - } - - GL_SetBlendMode(data, texture->blendMode); - - if (texturedata->yuv) { - GL_SetShader(data, SHADER_YUV); - } else if (texturedata->nv12) { - if (texture->format == SDL_PIXELFORMAT_NV12) { - GL_SetShader(data, SHADER_NV12); - } else { - GL_SetShader(data, SHADER_NV21); - } - } else { - GL_SetShader(data, SHADER_RGB); - } - return 0; -} - -static int -GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_FRect * dstrect) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata; - GLfloat minx, miny, maxx, maxy; - GLfloat minu, maxu, minv, maxv; - - GL_ActivateRenderer(renderer); - - if (GL_SetupCopy(renderer, texture) < 0) { - return -1; - } - - minx = dstrect->x; - miny = dstrect->y; - maxx = dstrect->x + dstrect->w; - maxy = dstrect->y + dstrect->h; - - minu = (GLfloat) srcrect->x / texture->w; - minu *= texturedata->texw; - maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w; - maxu *= texturedata->texw; - minv = (GLfloat) srcrect->y / texture->h; - minv *= texturedata->texh; - maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h; - maxv *= texturedata->texh; - - data->glBegin(GL_TRIANGLE_STRIP); - data->glTexCoord2f(minu, minv); - data->glVertex2f(minx, miny); - data->glTexCoord2f(maxu, minv); - data->glVertex2f(maxx, miny); - data->glTexCoord2f(minu, maxv); - data->glVertex2f(minx, maxy); - data->glTexCoord2f(maxu, maxv); - data->glVertex2f(maxx, maxy); - data->glEnd(); - - data->glDisable(texturedata->type); - - return GL_CheckError("", renderer); -} - -static int -GL_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_FRect * dstrect, - const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata; - GLfloat minx, miny, maxx, maxy; - GLfloat centerx, centery; - GLfloat minu, maxu, minv, maxv; - - GL_ActivateRenderer(renderer); - - if (GL_SetupCopy(renderer, texture) < 0) { - return -1; - } - - centerx = center->x; - centery = center->y; - - if (flip & SDL_FLIP_HORIZONTAL) { - minx = dstrect->w - centerx; - maxx = -centerx; - } - else { - minx = -centerx; - maxx = dstrect->w - centerx; - } - - if (flip & SDL_FLIP_VERTICAL) { - miny = dstrect->h - centery; - maxy = -centery; - } - else { - miny = -centery; - maxy = dstrect->h - centery; - } - - minu = (GLfloat) srcrect->x / texture->w; - minu *= texturedata->texw; - maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w; - maxu *= texturedata->texw; - minv = (GLfloat) srcrect->y / texture->h; - minv *= texturedata->texh; - maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h; - maxv *= texturedata->texh; - - /* Translate to flip, rotate, translate to position */ - data->glPushMatrix(); - data->glTranslatef((GLfloat)dstrect->x + centerx, (GLfloat)dstrect->y + centery, (GLfloat)0.0); - data->glRotated(angle, (GLdouble)0.0, (GLdouble)0.0, (GLdouble)1.0); - - data->glBegin(GL_TRIANGLE_STRIP); - data->glTexCoord2f(minu, minv); - data->glVertex2f(minx, miny); - data->glTexCoord2f(maxu, minv); - data->glVertex2f(maxx, miny); - data->glTexCoord2f(minu, maxv); - data->glVertex2f(minx, maxy); - data->glTexCoord2f(maxu, maxv); - data->glVertex2f(maxx, maxy); - data->glEnd(); - data->glPopMatrix(); - - data->glDisable(texturedata->type); - - return GL_CheckError("", renderer); -} - -static int -GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, - Uint32 pixel_format, void * pixels, int pitch) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - Uint32 temp_format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_ARGB8888; - void *temp_pixels; - int temp_pitch; - GLint internalFormat; - GLenum format, type; - Uint8 *src, *dst, *tmp; - int w, h, length, rows; - int status; - - GL_ActivateRenderer(renderer); - - temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format); - temp_pixels = SDL_malloc(rect->h * temp_pitch); - if (!temp_pixels) { - return SDL_OutOfMemory(); - } - - if (!convert_format(data, temp_format, &internalFormat, &format, &type)) { - SDL_free(temp_pixels); - return SDL_SetError("Texture format %s not supported by OpenGL", - SDL_GetPixelFormatName(temp_format)); - } - - SDL_GetRendererOutputSize(renderer, &w, &h); - - data->glPixelStorei(GL_PACK_ALIGNMENT, 1); - data->glPixelStorei(GL_PACK_ROW_LENGTH, - (temp_pitch / SDL_BYTESPERPIXEL(temp_format))); - - data->glReadPixels(rect->x, renderer->target ? rect->y : (h-rect->y)-rect->h, - rect->w, rect->h, format, type, temp_pixels); - - if (GL_CheckError("glReadPixels()", renderer) < 0) { - SDL_free(temp_pixels); - return -1; - } - - /* Flip the rows to be top-down if necessary */ - if (!renderer->target) { - length = rect->w * SDL_BYTESPERPIXEL(temp_format); - src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch; - dst = (Uint8*)temp_pixels; - tmp = SDL_stack_alloc(Uint8, length); - rows = rect->h / 2; - while (rows--) { - SDL_memcpy(tmp, dst, length); - SDL_memcpy(dst, src, length); - SDL_memcpy(src, tmp, length); - dst += temp_pitch; - src -= temp_pitch; - } - SDL_stack_free(tmp); - } - - status = SDL_ConvertPixels(rect->w, rect->h, - temp_format, temp_pixels, temp_pitch, - pixel_format, pixels, pitch); - SDL_free(temp_pixels); - - return status; -} - -static void -GL_RenderPresent(SDL_Renderer * renderer) -{ - GL_ActivateRenderer(renderer); - - SDL_GL_SwapWindow(renderer->window); -} - -static void -GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata; - GL_TextureData *data = (GL_TextureData *) texture->driverdata; - - GL_ActivateRenderer(renderer); - - if (!data) { - return; - } - if (data->texture) { - renderdata->glDeleteTextures(1, &data->texture); - } - if (data->yuv) { - renderdata->glDeleteTextures(1, &data->utexture); - renderdata->glDeleteTextures(1, &data->vtexture); - } - SDL_free(data->pixels); - SDL_free(data); - texture->driverdata = NULL; -} - -static void -GL_DestroyRenderer(SDL_Renderer * renderer) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - - if (data) { - GL_ClearErrors(renderer); - if (data->GL_ARB_debug_output_supported) { - PFNGLDEBUGMESSAGECALLBACKARBPROC glDebugMessageCallbackARBFunc = (PFNGLDEBUGMESSAGECALLBACKARBPROC) SDL_GL_GetProcAddress("glDebugMessageCallbackARB"); - - /* Uh oh, we don't have a safe way of removing ourselves from the callback chain, if it changed after we set our callback. */ - /* For now, just always replace the callback with the original one */ - glDebugMessageCallbackARBFunc(data->next_error_callback, data->next_error_userparam); - } - if (data->shaders) { - GL_DestroyShaderContext(data->shaders); - } - if (data->context) { - while (data->framebuffers) { - GL_FBOList *nextnode = data->framebuffers->next; - /* delete the framebuffer object */ - data->glDeleteFramebuffersEXT(1, &data->framebuffers->FBO); - GL_CheckError("", renderer); - SDL_free(data->framebuffers); - data->framebuffers = nextnode; - } - SDL_GL_DeleteContext(data->context); - } - SDL_free(data); - } - SDL_free(renderer); -} - -static int -GL_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata; - GL_ActivateRenderer(renderer); - - data->glEnable(texturedata->type); - if (texturedata->yuv) { - data->glActiveTextureARB(GL_TEXTURE2_ARB); - data->glBindTexture(texturedata->type, texturedata->vtexture); - - data->glActiveTextureARB(GL_TEXTURE1_ARB); - data->glBindTexture(texturedata->type, texturedata->utexture); - - data->glActiveTextureARB(GL_TEXTURE0_ARB); - } - data->glBindTexture(texturedata->type, texturedata->texture); - - if(texw) *texw = (float)texturedata->texw; - if(texh) *texh = (float)texturedata->texh; - - return 0; -} - -static int -GL_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata; - GL_ActivateRenderer(renderer); - - if (texturedata->yuv) { - data->glActiveTextureARB(GL_TEXTURE2_ARB); - data->glDisable(texturedata->type); - - data->glActiveTextureARB(GL_TEXTURE1_ARB); - data->glDisable(texturedata->type); - - data->glActiveTextureARB(GL_TEXTURE0_ARB); - } - - data->glDisable(texturedata->type); - - return 0; -} - -#endif /* SDL_VIDEO_RENDER_OGL && !SDL_RENDER_DISABLED */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/opengl/SDL_shaders_gl.c b/3rdparty/SDL2/src/render/opengl/SDL_shaders_gl.c deleted file mode 100644 index bcf7b431503..00000000000 --- a/3rdparty/SDL2/src/render/opengl/SDL_shaders_gl.c +++ /dev/null @@ -1,463 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../../SDL_internal.h" - -#if SDL_VIDEO_RENDER_OGL && !SDL_RENDER_DISABLED - -#include "SDL_stdinc.h" -#include "SDL_log.h" -#include "SDL_opengl.h" -#include "SDL_video.h" -#include "SDL_shaders_gl.h" - -/* OpenGL shader implementation */ - -/* #define DEBUG_SHADERS */ - -typedef struct -{ - GLhandleARB program; - GLhandleARB vert_shader; - GLhandleARB frag_shader; -} GL_ShaderData; - -struct GL_ShaderContext -{ - GLenum (*glGetError)(void); - - PFNGLATTACHOBJECTARBPROC glAttachObjectARB; - PFNGLCOMPILESHADERARBPROC glCompileShaderARB; - PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB; - PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB; - PFNGLDELETEOBJECTARBPROC glDeleteObjectARB; - PFNGLGETINFOLOGARBPROC glGetInfoLogARB; - PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB; - PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB; - PFNGLLINKPROGRAMARBPROC glLinkProgramARB; - PFNGLSHADERSOURCEARBPROC glShaderSourceARB; - PFNGLUNIFORM1IARBPROC glUniform1iARB; - PFNGLUNIFORM1FARBPROC glUniform1fARB; - PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB; - - SDL_bool GL_ARB_texture_rectangle_supported; - - GL_ShaderData shaders[NUM_SHADERS]; -}; - -/* - * NOTE: Always use sampler2D, etc here. We'll #define them to the - * texture_rectangle versions if we choose to use that extension. - */ -static const char *shader_source[NUM_SHADERS][2] = -{ - /* SHADER_NONE */ - { NULL, NULL }, - - /* SHADER_SOLID */ - { - /* vertex shader */ -"varying vec4 v_color;\n" -"\n" -"void main()\n" -"{\n" -" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" -" v_color = gl_Color;\n" -"}", - /* fragment shader */ -"varying vec4 v_color;\n" -"\n" -"void main()\n" -"{\n" -" gl_FragColor = v_color;\n" -"}" - }, - - /* SHADER_RGB */ - { - /* vertex shader */ -"varying vec4 v_color;\n" -"varying vec2 v_texCoord;\n" -"\n" -"void main()\n" -"{\n" -" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" -" v_color = gl_Color;\n" -" v_texCoord = vec2(gl_MultiTexCoord0);\n" -"}", - /* fragment shader */ -"varying vec4 v_color;\n" -"varying vec2 v_texCoord;\n" -"uniform sampler2D tex0;\n" -"\n" -"void main()\n" -"{\n" -" gl_FragColor = texture2D(tex0, v_texCoord) * v_color;\n" -"}" - }, - - /* SHADER_YUV */ - { - /* vertex shader */ -"varying vec4 v_color;\n" -"varying vec2 v_texCoord;\n" -"\n" -"void main()\n" -"{\n" -" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" -" v_color = gl_Color;\n" -" v_texCoord = vec2(gl_MultiTexCoord0);\n" -"}", - /* fragment shader */ -"varying vec4 v_color;\n" -"varying vec2 v_texCoord;\n" -"uniform sampler2D tex0; // Y \n" -"uniform sampler2D tex1; // U \n" -"uniform sampler2D tex2; // V \n" -"\n" -"// YUV offset \n" -"const vec3 offset = vec3(-0.0627451017, -0.501960814, -0.501960814);\n" -"\n" -"// RGB coefficients \n" -"const vec3 Rcoeff = vec3(1.164, 0.000, 1.596);\n" -"const vec3 Gcoeff = vec3(1.164, -0.391, -0.813);\n" -"const vec3 Bcoeff = vec3(1.164, 2.018, 0.000);\n" -"\n" -"void main()\n" -"{\n" -" vec2 tcoord;\n" -" vec3 yuv, rgb;\n" -"\n" -" // Get the Y value \n" -" tcoord = v_texCoord;\n" -" yuv.x = texture2D(tex0, tcoord).r;\n" -"\n" -" // Get the U and V values \n" -" tcoord *= UVCoordScale;\n" -" yuv.y = texture2D(tex1, tcoord).r;\n" -" yuv.z = texture2D(tex2, tcoord).r;\n" -"\n" -" // Do the color transform \n" -" yuv += offset;\n" -" rgb.r = dot(yuv, Rcoeff);\n" -" rgb.g = dot(yuv, Gcoeff);\n" -" rgb.b = dot(yuv, Bcoeff);\n" -"\n" -" // That was easy. :) \n" -" gl_FragColor = vec4(rgb, 1.0) * v_color;\n" -"}" - }, - - /* SHADER_NV12 */ - { - /* vertex shader */ -"varying vec4 v_color;\n" -"varying vec2 v_texCoord;\n" -"\n" -"void main()\n" -"{\n" -" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" -" v_color = gl_Color;\n" -" v_texCoord = vec2(gl_MultiTexCoord0);\n" -"}", - /* fragment shader */ -"varying vec4 v_color;\n" -"varying vec2 v_texCoord;\n" -"uniform sampler2D tex0; // Y \n" -"uniform sampler2D tex1; // U/V \n" -"\n" -"// YUV offset \n" -"const vec3 offset = vec3(-0.0627451017, -0.501960814, -0.501960814);\n" -"\n" -"// RGB coefficients \n" -"const vec3 Rcoeff = vec3(1.164, 0.000, 1.596);\n" -"const vec3 Gcoeff = vec3(1.164, -0.391, -0.813);\n" -"const vec3 Bcoeff = vec3(1.164, 2.018, 0.000);\n" -"\n" -"void main()\n" -"{\n" -" vec2 tcoord;\n" -" vec3 yuv, rgb;\n" -"\n" -" // Get the Y value \n" -" tcoord = v_texCoord;\n" -" yuv.x = texture2D(tex0, tcoord).r;\n" -"\n" -" // Get the U and V values \n" -" tcoord *= UVCoordScale;\n" -" yuv.yz = texture2D(tex1, tcoord).ra;\n" -"\n" -" // Do the color transform \n" -" yuv += offset;\n" -" rgb.r = dot(yuv, Rcoeff);\n" -" rgb.g = dot(yuv, Gcoeff);\n" -" rgb.b = dot(yuv, Bcoeff);\n" -"\n" -" // That was easy. :) \n" -" gl_FragColor = vec4(rgb, 1.0) * v_color;\n" -"}" - }, - - /* SHADER_NV21 */ - { - /* vertex shader */ -"varying vec4 v_color;\n" -"varying vec2 v_texCoord;\n" -"\n" -"void main()\n" -"{\n" -" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" -" v_color = gl_Color;\n" -" v_texCoord = vec2(gl_MultiTexCoord0);\n" -"}", - /* fragment shader */ -"varying vec4 v_color;\n" -"varying vec2 v_texCoord;\n" -"uniform sampler2D tex0; // Y \n" -"uniform sampler2D tex1; // U/V \n" -"\n" -"// YUV offset \n" -"const vec3 offset = vec3(-0.0627451017, -0.501960814, -0.501960814);\n" -"\n" -"// RGB coefficients \n" -"const vec3 Rcoeff = vec3(1.164, 0.000, 1.596);\n" -"const vec3 Gcoeff = vec3(1.164, -0.391, -0.813);\n" -"const vec3 Bcoeff = vec3(1.164, 2.018, 0.000);\n" -"\n" -"void main()\n" -"{\n" -" vec2 tcoord;\n" -" vec3 yuv, rgb;\n" -"\n" -" // Get the Y value \n" -" tcoord = v_texCoord;\n" -" yuv.x = texture2D(tex0, tcoord).r;\n" -"\n" -" // Get the U and V values \n" -" tcoord *= UVCoordScale;\n" -" yuv.yz = texture2D(tex1, tcoord).ar;\n" -"\n" -" // Do the color transform \n" -" yuv += offset;\n" -" rgb.r = dot(yuv, Rcoeff);\n" -" rgb.g = dot(yuv, Gcoeff);\n" -" rgb.b = dot(yuv, Bcoeff);\n" -"\n" -" // That was easy. :) \n" -" gl_FragColor = vec4(rgb, 1.0) * v_color;\n" -"}" - }, -}; - -static SDL_bool -CompileShader(GL_ShaderContext *ctx, GLhandleARB shader, const char *defines, const char *source) -{ - GLint status; - const char *sources[2]; - - sources[0] = defines; - sources[1] = source; - - ctx->glShaderSourceARB(shader, SDL_arraysize(sources), sources, NULL); - ctx->glCompileShaderARB(shader); - ctx->glGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &status); - if (status == 0) { - GLint length; - char *info; - - ctx->glGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length); - info = SDL_stack_alloc(char, length+1); - ctx->glGetInfoLogARB(shader, length, NULL, info); - SDL_LogError(SDL_LOG_CATEGORY_RENDER, - "Failed to compile shader:\n%s%s\n%s", defines, source, info); -#ifdef DEBUG_SHADERS - fprintf(stderr, - "Failed to compile shader:\n%s%s\n%s", defines, source, info); -#endif - SDL_stack_free(info); - - return SDL_FALSE; - } else { - return SDL_TRUE; - } -} - -static SDL_bool -CompileShaderProgram(GL_ShaderContext *ctx, int index, GL_ShaderData *data) -{ - const int num_tmus_bound = 4; - const char *vert_defines = ""; - const char *frag_defines = ""; - int i; - GLint location; - - if (index == SHADER_NONE) { - return SDL_TRUE; - } - - ctx->glGetError(); - - /* Make sure we use the correct sampler type for our texture type */ - if (ctx->GL_ARB_texture_rectangle_supported) { - frag_defines = -"#define sampler2D sampler2DRect\n" -"#define texture2D texture2DRect\n" -"#define UVCoordScale 0.5\n"; - } else { - frag_defines = -"#define UVCoordScale 1.0\n"; - } - - /* Create one program object to rule them all */ - data->program = ctx->glCreateProgramObjectARB(); - - /* Create the vertex shader */ - data->vert_shader = ctx->glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB); - if (!CompileShader(ctx, data->vert_shader, vert_defines, shader_source[index][0])) { - return SDL_FALSE; - } - - /* Create the fragment shader */ - data->frag_shader = ctx->glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB); - if (!CompileShader(ctx, data->frag_shader, frag_defines, shader_source[index][1])) { - return SDL_FALSE; - } - - /* ... and in the darkness bind them */ - ctx->glAttachObjectARB(data->program, data->vert_shader); - ctx->glAttachObjectARB(data->program, data->frag_shader); - ctx->glLinkProgramARB(data->program); - - /* Set up some uniform variables */ - ctx->glUseProgramObjectARB(data->program); - for (i = 0; i < num_tmus_bound; ++i) { - char tex_name[10]; - SDL_snprintf(tex_name, SDL_arraysize(tex_name), "tex%d", i); - location = ctx->glGetUniformLocationARB(data->program, tex_name); - if (location >= 0) { - ctx->glUniform1iARB(location, i); - } - } - ctx->glUseProgramObjectARB(0); - - return (ctx->glGetError() == GL_NO_ERROR); -} - -static void -DestroyShaderProgram(GL_ShaderContext *ctx, GL_ShaderData *data) -{ - ctx->glDeleteObjectARB(data->vert_shader); - ctx->glDeleteObjectARB(data->frag_shader); - ctx->glDeleteObjectARB(data->program); -} - -GL_ShaderContext * -GL_CreateShaderContext() -{ - GL_ShaderContext *ctx; - SDL_bool shaders_supported; - int i; - - ctx = (GL_ShaderContext *)SDL_calloc(1, sizeof(*ctx)); - if (!ctx) { - return NULL; - } - - if (!SDL_GL_ExtensionSupported("GL_ARB_texture_non_power_of_two") && - (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle") || - SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle"))) { - ctx->GL_ARB_texture_rectangle_supported = SDL_TRUE; - } - - /* Check for shader support */ - shaders_supported = SDL_FALSE; - if (SDL_GL_ExtensionSupported("GL_ARB_shader_objects") && - SDL_GL_ExtensionSupported("GL_ARB_shading_language_100") && - SDL_GL_ExtensionSupported("GL_ARB_vertex_shader") && - SDL_GL_ExtensionSupported("GL_ARB_fragment_shader")) { - ctx->glGetError = (GLenum (*)(void)) SDL_GL_GetProcAddress("glGetError"); - ctx->glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) SDL_GL_GetProcAddress("glAttachObjectARB"); - ctx->glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) SDL_GL_GetProcAddress("glCompileShaderARB"); - ctx->glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) SDL_GL_GetProcAddress("glCreateProgramObjectARB"); - ctx->glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) SDL_GL_GetProcAddress("glCreateShaderObjectARB"); - ctx->glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC) SDL_GL_GetProcAddress("glDeleteObjectARB"); - ctx->glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC) SDL_GL_GetProcAddress("glGetInfoLogARB"); - ctx->glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC) SDL_GL_GetProcAddress("glGetObjectParameterivARB"); - ctx->glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) SDL_GL_GetProcAddress("glGetUniformLocationARB"); - ctx->glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) SDL_GL_GetProcAddress("glLinkProgramARB"); - ctx->glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) SDL_GL_GetProcAddress("glShaderSourceARB"); - ctx->glUniform1iARB = (PFNGLUNIFORM1IARBPROC) SDL_GL_GetProcAddress("glUniform1iARB"); - ctx->glUniform1fARB = (PFNGLUNIFORM1FARBPROC) SDL_GL_GetProcAddress("glUniform1fARB"); - ctx->glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) SDL_GL_GetProcAddress("glUseProgramObjectARB"); - if (ctx->glGetError && - ctx->glAttachObjectARB && - ctx->glCompileShaderARB && - ctx->glCreateProgramObjectARB && - ctx->glCreateShaderObjectARB && - ctx->glDeleteObjectARB && - ctx->glGetInfoLogARB && - ctx->glGetObjectParameterivARB && - ctx->glGetUniformLocationARB && - ctx->glLinkProgramARB && - ctx->glShaderSourceARB && - ctx->glUniform1iARB && - ctx->glUniform1fARB && - ctx->glUseProgramObjectARB) { - shaders_supported = SDL_TRUE; - } - } - - if (!shaders_supported) { - SDL_free(ctx); - return NULL; - } - - /* Compile all the shaders */ - for (i = 0; i < NUM_SHADERS; ++i) { - if (!CompileShaderProgram(ctx, i, &ctx->shaders[i])) { - GL_DestroyShaderContext(ctx); - return NULL; - } - } - - /* We're done! */ - return ctx; -} - -void -GL_SelectShader(GL_ShaderContext *ctx, GL_Shader shader) -{ - ctx->glUseProgramObjectARB(ctx->shaders[shader].program); -} - -void -GL_DestroyShaderContext(GL_ShaderContext *ctx) -{ - int i; - - for (i = 0; i < NUM_SHADERS; ++i) { - DestroyShaderProgram(ctx, &ctx->shaders[i]); - } - SDL_free(ctx); -} - -#endif /* SDL_VIDEO_RENDER_OGL && !SDL_RENDER_DISABLED */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/opengl/SDL_shaders_gl.h b/3rdparty/SDL2/src/render/opengl/SDL_shaders_gl.h deleted file mode 100644 index 261627cc79a..00000000000 --- a/3rdparty/SDL2/src/render/opengl/SDL_shaders_gl.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../../SDL_internal.h" - -/* OpenGL shader implementation */ - -typedef enum { - SHADER_NONE, - SHADER_SOLID, - SHADER_RGB, - SHADER_YUV, - SHADER_NV12, - SHADER_NV21, - NUM_SHADERS -} GL_Shader; - -typedef struct GL_ShaderContext GL_ShaderContext; - -extern GL_ShaderContext * GL_CreateShaderContext(); -extern void GL_SelectShader(GL_ShaderContext *ctx, GL_Shader shader); -extern void GL_DestroyShaderContext(GL_ShaderContext *ctx); - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/opengles/SDL_glesfuncs.h b/3rdparty/SDL2/src/render/opengles/SDL_glesfuncs.h deleted file mode 100644 index a15d76d4967..00000000000 --- a/3rdparty/SDL2/src/render/opengles/SDL_glesfuncs.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -SDL_PROC(void, glBindTexture, (GLenum, GLuint)) -SDL_PROC(void, glBlendFunc, (GLenum, GLenum)) -SDL_PROC_OES(void, glBlendFuncSeparateOES, (GLenum, GLenum, GLenum, GLenum)) -SDL_PROC(void, glClear, (GLbitfield)) -SDL_PROC(void, glClearColor, (GLclampf, GLclampf, GLclampf, GLclampf)) -SDL_PROC(void, glColor4f, (GLfloat, GLfloat, GLfloat, GLfloat)) -SDL_PROC(void, glDeleteTextures, (GLsizei, const GLuint *)) -SDL_PROC(void, glDisable, (GLenum)) -SDL_PROC(void, glDisableClientState, (GLenum array)) -SDL_PROC(void, glDrawArrays, (GLenum, GLint, GLsizei)) -SDL_PROC_OES(void, glDrawTexfOES, (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat)) -SDL_PROC(void, glEnable, (GLenum)) -SDL_PROC(void, glEnableClientState, (GLenum)) -SDL_PROC(void, glFinish, (void)) -SDL_PROC_OES(void, glGenFramebuffersOES, (GLsizei, GLuint *)) -SDL_PROC(void, glGenTextures, (GLsizei, GLuint *)) -SDL_PROC(GLenum, glGetError, (void)) -SDL_PROC(void, glGetIntegerv, (GLenum, GLint *)) -SDL_PROC(void, glLoadIdentity, (void)) -SDL_PROC(void, glMatrixMode, (GLenum)) -SDL_PROC(void, glOrthof, (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat)) -SDL_PROC(void, glPixelStorei, (GLenum, GLint)) -SDL_PROC(void, glReadPixels, (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid*)) -SDL_PROC(void, glScissor, (GLint, GLint, GLsizei, GLsizei)) -SDL_PROC(void, glTexCoordPointer, (GLint, GLenum, GLsizei, const GLvoid *)) -SDL_PROC(void, glTexEnvf, (GLenum, GLenum, GLfloat)) -SDL_PROC(void, glTexImage2D, (GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *)) -SDL_PROC(void, glTexParameteri, (GLenum, GLenum, GLint)) -SDL_PROC(void, glTexParameteriv, (GLenum, GLenum, const GLint *)) -SDL_PROC(void, glTexSubImage2D, (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *)) -SDL_PROC(void, glVertexPointer, (GLint, GLenum, GLsizei, const GLvoid *)) -SDL_PROC(void, glViewport, (GLint, GLint, GLsizei, GLsizei)) -SDL_PROC_OES(void, glBindFramebufferOES, (GLenum, GLuint)) -SDL_PROC_OES(void, glFramebufferTexture2DOES, (GLenum, GLenum, GLenum, GLuint, GLint)) -SDL_PROC_OES(GLenum, glCheckFramebufferStatusOES, (GLenum)) -SDL_PROC(void, glPushMatrix, (void)) -SDL_PROC(void, glTranslatef, (GLfloat, GLfloat, GLfloat)) -SDL_PROC(void, glRotatef, (GLfloat, GLfloat, GLfloat, GLfloat)) -SDL_PROC(void, glPopMatrix, (void)) -SDL_PROC_OES(void, glDeleteFramebuffersOES, (GLsizei, const GLuint*)) - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/opengles/SDL_render_gles.c b/3rdparty/SDL2/src/render/opengles/SDL_render_gles.c deleted file mode 100644 index 71f5b3a7a0d..00000000000 --- a/3rdparty/SDL2/src/render/opengles/SDL_render_gles.c +++ /dev/null @@ -1,1216 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../../SDL_internal.h" - -#if SDL_VIDEO_RENDER_OGL_ES && !SDL_RENDER_DISABLED - -#include "SDL_hints.h" -#include "SDL_opengles.h" -#include "../SDL_sysrender.h" - -/* To prevent unnecessary window recreation, - * these should match the defaults selected in SDL_GL_ResetAttributes - */ - -#define RENDERER_CONTEXT_MAJOR 1 -#define RENDERER_CONTEXT_MINOR 1 - -#if defined(SDL_VIDEO_DRIVER_PANDORA) - -/* Empty function stub to get OpenGL ES 1.x support without */ -/* OpenGL ES extension GL_OES_draw_texture supported */ -GL_API void GL_APIENTRY -glDrawTexiOES(GLint x, GLint y, GLint z, GLint width, GLint height) -{ - return; -} - -#endif /* SDL_VIDEO_DRIVER_PANDORA */ - -/* OpenGL ES 1.1 renderer implementation, based on the OpenGL renderer */ - -/* Used to re-create the window with OpenGL ES capability */ -extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags); - -static const float inv255f = 1.0f / 255.0f; - -static SDL_Renderer *GLES_CreateRenderer(SDL_Window * window, Uint32 flags); -static void GLES_WindowEvent(SDL_Renderer * renderer, - const SDL_WindowEvent *event); -static int GLES_GetOutputSize(SDL_Renderer * renderer, int *w, int *h); -static int GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); -static int GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, const void *pixels, - int pitch); -static int GLES_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, void **pixels, int *pitch); -static void GLES_UnlockTexture(SDL_Renderer * renderer, - SDL_Texture * texture); -static int GLES_SetRenderTarget(SDL_Renderer * renderer, - SDL_Texture * texture); -static int GLES_UpdateViewport(SDL_Renderer * renderer); -static int GLES_UpdateClipRect(SDL_Renderer * renderer); -static int GLES_RenderClear(SDL_Renderer * renderer); -static int GLES_RenderDrawPoints(SDL_Renderer * renderer, - const SDL_FPoint * points, int count); -static int GLES_RenderDrawLines(SDL_Renderer * renderer, - const SDL_FPoint * points, int count); -static int GLES_RenderFillRects(SDL_Renderer * renderer, - const SDL_FRect * rects, int count); -static int GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, - const SDL_FRect * dstrect); -static int GLES_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_FRect * dstrect, - const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip); -static int GLES_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, - Uint32 pixel_format, void * pixels, int pitch); -static void GLES_RenderPresent(SDL_Renderer * renderer); -static void GLES_DestroyTexture(SDL_Renderer * renderer, - SDL_Texture * texture); -static void GLES_DestroyRenderer(SDL_Renderer * renderer); -static int GLES_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh); -static int GLES_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture); - -typedef struct GLES_FBOList GLES_FBOList; - -struct GLES_FBOList -{ - Uint32 w, h; - GLuint FBO; - GLES_FBOList *next; -}; - - -SDL_RenderDriver GLES_RenderDriver = { - GLES_CreateRenderer, - { - "opengles", - (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC), - 1, - {SDL_PIXELFORMAT_ABGR8888}, - 0, - 0} -}; - -typedef struct -{ - SDL_GLContext context; - struct { - Uint32 color; - int blendMode; - SDL_bool tex_coords; - } current; - -#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params; -#define SDL_PROC_OES SDL_PROC -#include "SDL_glesfuncs.h" -#undef SDL_PROC -#undef SDL_PROC_OES - SDL_bool GL_OES_framebuffer_object_supported; - GLES_FBOList *framebuffers; - GLuint window_framebuffer; - - SDL_bool GL_OES_blend_func_separate_supported; -} GLES_RenderData; - -typedef struct -{ - GLuint texture; - GLenum type; - GLfloat texw; - GLfloat texh; - GLenum format; - GLenum formattype; - void *pixels; - int pitch; - GLES_FBOList *fbo; -} GLES_TextureData; - -static int -GLES_SetError(const char *prefix, GLenum result) -{ - const char *error; - - switch (result) { - case GL_NO_ERROR: - error = "GL_NO_ERROR"; - break; - case GL_INVALID_ENUM: - error = "GL_INVALID_ENUM"; - break; - case GL_INVALID_VALUE: - error = "GL_INVALID_VALUE"; - break; - case GL_INVALID_OPERATION: - error = "GL_INVALID_OPERATION"; - break; - case GL_STACK_OVERFLOW: - error = "GL_STACK_OVERFLOW"; - break; - case GL_STACK_UNDERFLOW: - error = "GL_STACK_UNDERFLOW"; - break; - case GL_OUT_OF_MEMORY: - error = "GL_OUT_OF_MEMORY"; - break; - default: - error = "UNKNOWN"; - break; - } - return SDL_SetError("%s: %s", prefix, error); -} - -static int GLES_LoadFunctions(GLES_RenderData * data) -{ -#if SDL_VIDEO_DRIVER_UIKIT -#define __SDL_NOGETPROCADDR__ -#elif SDL_VIDEO_DRIVER_ANDROID -#define __SDL_NOGETPROCADDR__ -#elif SDL_VIDEO_DRIVER_PANDORA -#define __SDL_NOGETPROCADDR__ -#endif - -#ifdef __SDL_NOGETPROCADDR__ -#define SDL_PROC(ret,func,params) data->func=func; -#define SDL_PROC_OES(ret,func,params) data->func=func; -#else -#define SDL_PROC(ret,func,params) \ - do { \ - data->func = SDL_GL_GetProcAddress(#func); \ - if ( ! data->func ) { \ - return SDL_SetError("Couldn't load GLES function %s: %s\n", #func, SDL_GetError()); \ - } \ - } while ( 0 ); -#define SDL_PROC_OES(ret,func,params) \ - do { \ - data->func = SDL_GL_GetProcAddress(#func); \ - } while ( 0 ); -#endif /* __SDL_NOGETPROCADDR__ */ - -#include "SDL_glesfuncs.h" -#undef SDL_PROC -#undef SDL_PROC_OES - return 0; -} - -static SDL_GLContext SDL_CurrentContext = NULL; - -GLES_FBOList * -GLES_GetFBO(GLES_RenderData *data, Uint32 w, Uint32 h) -{ - GLES_FBOList *result = data->framebuffers; - while ((result) && ((result->w != w) || (result->h != h)) ) { - result = result->next; - } - if (result == NULL) { - result = SDL_malloc(sizeof(GLES_FBOList)); - result->w = w; - result->h = h; - data->glGenFramebuffersOES(1, &result->FBO); - result->next = data->framebuffers; - data->framebuffers = result; - } - return result; -} - - -static int -GLES_ActivateRenderer(SDL_Renderer * renderer) -{ - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - - if (SDL_CurrentContext != data->context) { - if (SDL_GL_MakeCurrent(renderer->window, data->context) < 0) { - return -1; - } - SDL_CurrentContext = data->context; - - GLES_UpdateViewport(renderer); - } - return 0; -} - -/* This is called if we need to invalidate all of the SDL OpenGL state */ -static void -GLES_ResetState(SDL_Renderer *renderer) -{ - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - - if (SDL_CurrentContext == data->context) { - GLES_UpdateViewport(renderer); - } else { - GLES_ActivateRenderer(renderer); - } - - data->current.color = 0; - data->current.blendMode = -1; - data->current.tex_coords = SDL_FALSE; - - data->glDisable(GL_DEPTH_TEST); - data->glDisable(GL_CULL_FACE); - - data->glMatrixMode(GL_MODELVIEW); - data->glLoadIdentity(); - - data->glEnableClientState(GL_VERTEX_ARRAY); - data->glDisableClientState(GL_TEXTURE_COORD_ARRAY); -} - -SDL_Renderer * -GLES_CreateRenderer(SDL_Window * window, Uint32 flags) -{ - - SDL_Renderer *renderer; - GLES_RenderData *data; - GLint value; - Uint32 window_flags; - int profile_mask = 0, major = 0, minor = 0; - SDL_bool changed_window = SDL_FALSE; - - SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profile_mask); - SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major); - SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor); - - window_flags = SDL_GetWindowFlags(window); - if (!(window_flags & SDL_WINDOW_OPENGL) || - profile_mask != SDL_GL_CONTEXT_PROFILE_ES || major != RENDERER_CONTEXT_MAJOR || minor != RENDERER_CONTEXT_MINOR) { - - changed_window = SDL_TRUE; - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR); - - if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 0) { - goto error; - } - } - - renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); - if (!renderer) { - SDL_OutOfMemory(); - goto error; - } - - data = (GLES_RenderData *) SDL_calloc(1, sizeof(*data)); - if (!data) { - GLES_DestroyRenderer(renderer); - SDL_OutOfMemory(); - goto error; - } - - renderer->WindowEvent = GLES_WindowEvent; - renderer->GetOutputSize = GLES_GetOutputSize; - renderer->CreateTexture = GLES_CreateTexture; - renderer->UpdateTexture = GLES_UpdateTexture; - renderer->LockTexture = GLES_LockTexture; - renderer->UnlockTexture = GLES_UnlockTexture; - renderer->SetRenderTarget = GLES_SetRenderTarget; - renderer->UpdateViewport = GLES_UpdateViewport; - renderer->UpdateClipRect = GLES_UpdateClipRect; - renderer->RenderClear = GLES_RenderClear; - renderer->RenderDrawPoints = GLES_RenderDrawPoints; - renderer->RenderDrawLines = GLES_RenderDrawLines; - renderer->RenderFillRects = GLES_RenderFillRects; - renderer->RenderCopy = GLES_RenderCopy; - renderer->RenderCopyEx = GLES_RenderCopyEx; - renderer->RenderReadPixels = GLES_RenderReadPixels; - renderer->RenderPresent = GLES_RenderPresent; - renderer->DestroyTexture = GLES_DestroyTexture; - renderer->DestroyRenderer = GLES_DestroyRenderer; - renderer->GL_BindTexture = GLES_BindTexture; - renderer->GL_UnbindTexture = GLES_UnbindTexture; - renderer->info = GLES_RenderDriver.info; - renderer->info.flags = SDL_RENDERER_ACCELERATED; - renderer->driverdata = data; - renderer->window = window; - - data->context = SDL_GL_CreateContext(window); - if (!data->context) { - GLES_DestroyRenderer(renderer); - goto error; - } - if (SDL_GL_MakeCurrent(window, data->context) < 0) { - GLES_DestroyRenderer(renderer); - goto error; - } - - if (GLES_LoadFunctions(data) < 0) { - GLES_DestroyRenderer(renderer); - goto error; - } - - if (flags & SDL_RENDERER_PRESENTVSYNC) { - SDL_GL_SetSwapInterval(1); - } else { - SDL_GL_SetSwapInterval(0); - } - if (SDL_GL_GetSwapInterval() > 0) { - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; - } - - value = 0; - data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value); - renderer->info.max_texture_width = value; - value = 0; - data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value); - renderer->info.max_texture_height = value; - - /* Android does not report GL_OES_framebuffer_object but the functionality seems to be there anyway */ - if (SDL_GL_ExtensionSupported("GL_OES_framebuffer_object") || data->glGenFramebuffersOES) { - data->GL_OES_framebuffer_object_supported = SDL_TRUE; - renderer->info.flags |= SDL_RENDERER_TARGETTEXTURE; - - value = 0; - data->glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, &value); - data->window_framebuffer = (GLuint)value; - } - data->framebuffers = NULL; - - if (SDL_GL_ExtensionSupported("GL_OES_blend_func_separate")) { - data->GL_OES_blend_func_separate_supported = SDL_TRUE; - } - - /* Set up parameters for rendering */ - GLES_ResetState(renderer); - - return renderer; - -error: - if (changed_window) { - /* Uh oh, better try to put it back... */ - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile_mask); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, major); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minor); - SDL_RecreateWindow(window, window_flags); - } - return NULL; -} - -static void -GLES_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event) -{ - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - - if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED || - event->event == SDL_WINDOWEVENT_SHOWN || - event->event == SDL_WINDOWEVENT_HIDDEN) { - /* Rebind the context to the window area and update matrices */ - SDL_CurrentContext = NULL; - } - - if (event->event == SDL_WINDOWEVENT_MINIMIZED) { - /* According to Apple documentation, we need to finish drawing NOW! */ - data->glFinish(); - } -} - -static int -GLES_GetOutputSize(SDL_Renderer * renderer, int *w, int *h) -{ - SDL_GL_GetDrawableSize(renderer->window, w, h); - return 0; -} - -static SDL_INLINE int -power_of_2(int input) -{ - int value = 1; - - while (value < input) { - value <<= 1; - } - return value; -} - -static GLenum -GetScaleQuality(void) -{ - const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY); - - if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) { - return GL_NEAREST; - } else { - return GL_LINEAR; - } -} - -static int -GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata; - GLES_TextureData *data; - GLint internalFormat; - GLenum format, type; - int texture_w, texture_h; - GLenum scaleMode; - GLenum result; - - GLES_ActivateRenderer(renderer); - - switch (texture->format) { - case SDL_PIXELFORMAT_ABGR8888: - internalFormat = GL_RGBA; - format = GL_RGBA; - type = GL_UNSIGNED_BYTE; - break; - default: - return SDL_SetError("Texture format not supported"); - } - - data = (GLES_TextureData *) SDL_calloc(1, sizeof(*data)); - if (!data) { - return SDL_OutOfMemory(); - } - - if (texture->access == SDL_TEXTUREACCESS_STREAMING) { - data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format); - data->pixels = SDL_calloc(1, texture->h * data->pitch); - if (!data->pixels) { - SDL_free(data); - return SDL_OutOfMemory(); - } - } - - - if (texture->access == SDL_TEXTUREACCESS_TARGET) { - if (!renderdata->GL_OES_framebuffer_object_supported) { - SDL_free(data); - return SDL_SetError("GL_OES_framebuffer_object not supported"); - } - data->fbo = GLES_GetFBO(renderer->driverdata, texture->w, texture->h); - } else { - data->fbo = NULL; - } - - - renderdata->glGetError(); - renderdata->glEnable(GL_TEXTURE_2D); - renderdata->glGenTextures(1, &data->texture); - result = renderdata->glGetError(); - if (result != GL_NO_ERROR) { - SDL_free(data); - return GLES_SetError("glGenTextures()", result); - } - - data->type = GL_TEXTURE_2D; - /* no NPOV textures allowed in OpenGL ES (yet) */ - texture_w = power_of_2(texture->w); - texture_h = power_of_2(texture->h); - data->texw = (GLfloat) texture->w / texture_w; - data->texh = (GLfloat) texture->h / texture_h; - - data->format = format; - data->formattype = type; - scaleMode = GetScaleQuality(); - renderdata->glBindTexture(data->type, data->texture); - renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER, scaleMode); - renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER, scaleMode); - renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - - renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w, - texture_h, 0, format, type, NULL); - renderdata->glDisable(GL_TEXTURE_2D); - - result = renderdata->glGetError(); - if (result != GL_NO_ERROR) { - SDL_free(data); - return GLES_SetError("glTexImage2D()", result); - } - - texture->driverdata = data; - return 0; -} - -static int -GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, const void *pixels, int pitch) -{ - GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata; - GLES_TextureData *data = (GLES_TextureData *) texture->driverdata; - Uint8 *blob = NULL; - Uint8 *src; - int srcPitch; - int y; - - GLES_ActivateRenderer(renderer); - - /* Bail out if we're supposed to update an empty rectangle */ - if (rect->w <= 0 || rect->h <= 0) { - return 0; - } - - /* Reformat the texture data into a tightly packed array */ - srcPitch = rect->w * SDL_BYTESPERPIXEL(texture->format); - src = (Uint8 *)pixels; - if (pitch != srcPitch) { - blob = (Uint8 *)SDL_malloc(srcPitch * rect->h); - if (!blob) { - return SDL_OutOfMemory(); - } - src = blob; - for (y = 0; y < rect->h; ++y) { - SDL_memcpy(src, pixels, srcPitch); - src += srcPitch; - pixels = (Uint8 *)pixels + pitch; - } - src = blob; - } - - /* Create a texture subimage with the supplied data */ - renderdata->glGetError(); - renderdata->glEnable(data->type); - renderdata->glBindTexture(data->type, data->texture); - renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - renderdata->glTexSubImage2D(data->type, - 0, - rect->x, - rect->y, - rect->w, - rect->h, - data->format, - data->formattype, - src); - renderdata->glDisable(data->type); - SDL_free(blob); - - if (renderdata->glGetError() != GL_NO_ERROR) { - return SDL_SetError("Failed to update texture"); - } - return 0; -} - -static int -GLES_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, void **pixels, int *pitch) -{ - GLES_TextureData *data = (GLES_TextureData *) texture->driverdata; - - *pixels = - (void *) ((Uint8 *) data->pixels + rect->y * data->pitch + - rect->x * SDL_BYTESPERPIXEL(texture->format)); - *pitch = data->pitch; - return 0; -} - -static void -GLES_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - GLES_TextureData *data = (GLES_TextureData *) texture->driverdata; - SDL_Rect rect; - - /* We do whole texture updates, at least for now */ - rect.x = 0; - rect.y = 0; - rect.w = texture->w; - rect.h = texture->h; - GLES_UpdateTexture(renderer, texture, &rect, data->pixels, data->pitch); -} - -static int -GLES_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture) -{ - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - GLES_TextureData *texturedata = NULL; - GLenum status; - - GLES_ActivateRenderer(renderer); - - if (!data->GL_OES_framebuffer_object_supported) { - return SDL_SetError("Can't enable render target support in this renderer"); - } - - if (texture == NULL) { - data->glBindFramebufferOES(GL_FRAMEBUFFER_OES, data->window_framebuffer); - return 0; - } - - texturedata = (GLES_TextureData *) texture->driverdata; - data->glBindFramebufferOES(GL_FRAMEBUFFER_OES, texturedata->fbo->FBO); - /* TODO: check if texture pixel format allows this operation */ - data->glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, texturedata->type, texturedata->texture, 0); - /* Check FBO status */ - status = data->glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES); - if (status != GL_FRAMEBUFFER_COMPLETE_OES) { - return SDL_SetError("glFramebufferTexture2DOES() failed"); - } - return 0; -} - -static int -GLES_UpdateViewport(SDL_Renderer * renderer) -{ - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - - if (SDL_CurrentContext != data->context) { - /* We'll update the viewport after we rebind the context */ - return 0; - } - - if (renderer->target) { - data->glViewport(renderer->viewport.x, renderer->viewport.y, - renderer->viewport.w, renderer->viewport.h); - } else { - int w, h; - - SDL_GL_GetDrawableSize(renderer->window, &w, &h); - data->glViewport(renderer->viewport.x, (h - renderer->viewport.y - renderer->viewport.h), - renderer->viewport.w, renderer->viewport.h); - } - - data->glMatrixMode(GL_PROJECTION); - data->glLoadIdentity(); - if (renderer->viewport.w && renderer->viewport.h) { - if (renderer->target) { - data->glOrthof((GLfloat) 0, - (GLfloat) renderer->viewport.w, - (GLfloat) 0, - (GLfloat) renderer->viewport.h, - 0.0, 1.0); - } else { - data->glOrthof((GLfloat) 0, - (GLfloat) renderer->viewport.w, - (GLfloat) renderer->viewport.h, - (GLfloat) 0, - 0.0, 1.0); - } - } - return 0; -} - -static int -GLES_UpdateClipRect(SDL_Renderer * renderer) -{ - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - - if (SDL_CurrentContext != data->context) { - /* We'll update the clip rect after we rebind the context */ - return 0; - } - - if (renderer->clipping_enabled) { - const SDL_Rect *rect = &renderer->clip_rect; - data->glEnable(GL_SCISSOR_TEST); - if (renderer->target) { - data->glScissor(renderer->viewport.x + rect->x, renderer->viewport.y + rect->y, rect->w, rect->h); - } else { - int w, h; - - SDL_GL_GetDrawableSize(renderer->window, &w, &h); - data->glScissor(renderer->viewport.x + rect->x, h - renderer->viewport.y - rect->y - rect->h, rect->w, rect->h); - } - } else { - data->glDisable(GL_SCISSOR_TEST); - } - return 0; -} - -static void -GLES_SetColor(GLES_RenderData * data, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - Uint32 color = ((a << 24) | (r << 16) | (g << 8) | b); - - if (color != data->current.color) { - data->glColor4f((GLfloat) r * inv255f, - (GLfloat) g * inv255f, - (GLfloat) b * inv255f, - (GLfloat) a * inv255f); - data->current.color = color; - } -} - -static void -GLES_SetBlendMode(GLES_RenderData * data, int blendMode) -{ - if (blendMode != data->current.blendMode) { - switch (blendMode) { - case SDL_BLENDMODE_NONE: - data->glDisable(GL_BLEND); - break; - case SDL_BLENDMODE_BLEND: - data->glEnable(GL_BLEND); - if (data->GL_OES_blend_func_separate_supported) { - data->glBlendFuncSeparateOES(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - } else { - data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } - break; - case SDL_BLENDMODE_ADD: - data->glEnable(GL_BLEND); - if (data->GL_OES_blend_func_separate_supported) { - data->glBlendFuncSeparateOES(GL_SRC_ALPHA, GL_ONE, GL_ZERO, GL_ONE); - } else { - data->glBlendFunc(GL_SRC_ALPHA, GL_ONE); - } - break; - case SDL_BLENDMODE_MOD: - data->glEnable(GL_BLEND); - if (data->GL_OES_blend_func_separate_supported) { - data->glBlendFuncSeparateOES(GL_ZERO, GL_SRC_COLOR, GL_ZERO, GL_ONE); - } else { - data->glBlendFunc(GL_ZERO, GL_SRC_COLOR); - } - break; - } - data->current.blendMode = blendMode; - } -} - -static void -GLES_SetTexCoords(GLES_RenderData * data, SDL_bool enabled) -{ - if (enabled != data->current.tex_coords) { - if (enabled) { - data->glEnableClientState(GL_TEXTURE_COORD_ARRAY); - } else { - data->glDisableClientState(GL_TEXTURE_COORD_ARRAY); - } - data->current.tex_coords = enabled; - } -} - -static void -GLES_SetDrawingState(SDL_Renderer * renderer) -{ - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - - GLES_ActivateRenderer(renderer); - - GLES_SetColor(data, (GLfloat) renderer->r, - (GLfloat) renderer->g, - (GLfloat) renderer->b, - (GLfloat) renderer->a); - - GLES_SetBlendMode(data, renderer->blendMode); - - GLES_SetTexCoords(data, SDL_FALSE); -} - -static int -GLES_RenderClear(SDL_Renderer * renderer) -{ - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - - GLES_ActivateRenderer(renderer); - - data->glClearColor((GLfloat) renderer->r * inv255f, - (GLfloat) renderer->g * inv255f, - (GLfloat) renderer->b * inv255f, - (GLfloat) renderer->a * inv255f); - - if (renderer->clipping_enabled) { - data->glDisable(GL_SCISSOR_TEST); - } - - data->glClear(GL_COLOR_BUFFER_BIT); - - if (renderer->clipping_enabled) { - data->glEnable(GL_SCISSOR_TEST); - } - - return 0; -} - -static int -GLES_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points, - int count) -{ - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - GLfloat *vertices; - int idx; - - GLES_SetDrawingState(renderer); - - /* Emit the specified vertices as points */ - vertices = SDL_stack_alloc(GLfloat, count * 2); - for (idx = 0; idx < count; ++idx) { - GLfloat x = points[idx].x + 0.5f; - GLfloat y = points[idx].y + 0.5f; - - vertices[idx * 2] = x; - vertices[(idx * 2) + 1] = y; - } - - data->glVertexPointer(2, GL_FLOAT, 0, vertices); - data->glDrawArrays(GL_POINTS, 0, count); - SDL_stack_free(vertices); - return 0; -} - -static int -GLES_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points, - int count) -{ - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - GLfloat *vertices; - int idx; - - GLES_SetDrawingState(renderer); - - /* Emit a line strip including the specified vertices */ - vertices = SDL_stack_alloc(GLfloat, count * 2); - for (idx = 0; idx < count; ++idx) { - GLfloat x = points[idx].x + 0.5f; - GLfloat y = points[idx].y + 0.5f; - - vertices[idx * 2] = x; - vertices[(idx * 2) + 1] = y; - } - - data->glVertexPointer(2, GL_FLOAT, 0, vertices); - if (count > 2 && - points[0].x == points[count-1].x && points[0].y == points[count-1].y) { - /* GL_LINE_LOOP takes care of the final segment */ - --count; - data->glDrawArrays(GL_LINE_LOOP, 0, count); - } else { - data->glDrawArrays(GL_LINE_STRIP, 0, count); - /* We need to close the endpoint of the line */ - data->glDrawArrays(GL_POINTS, count-1, 1); - } - SDL_stack_free(vertices); - - return 0; -} - -static int -GLES_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects, - int count) -{ - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - int i; - - GLES_SetDrawingState(renderer); - - for (i = 0; i < count; ++i) { - const SDL_FRect *rect = &rects[i]; - GLfloat minx = rect->x; - GLfloat maxx = rect->x + rect->w; - GLfloat miny = rect->y; - GLfloat maxy = rect->y + rect->h; - GLfloat vertices[8]; - vertices[0] = minx; - vertices[1] = miny; - vertices[2] = maxx; - vertices[3] = miny; - vertices[4] = minx; - vertices[5] = maxy; - vertices[6] = maxx; - vertices[7] = maxy; - - data->glVertexPointer(2, GL_FLOAT, 0, vertices); - data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - } - - return 0; -} - -static int -GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_FRect * dstrect) -{ - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata; - GLfloat minx, miny, maxx, maxy; - GLfloat minu, maxu, minv, maxv; - GLfloat vertices[8]; - GLfloat texCoords[8]; - - GLES_ActivateRenderer(renderer); - - data->glEnable(GL_TEXTURE_2D); - - data->glBindTexture(texturedata->type, texturedata->texture); - - if (texture->modMode) { - GLES_SetColor(data, texture->r, texture->g, texture->b, texture->a); - } else { - GLES_SetColor(data, 255, 255, 255, 255); - } - - GLES_SetBlendMode(data, texture->blendMode); - - GLES_SetTexCoords(data, SDL_TRUE); - - minx = dstrect->x; - miny = dstrect->y; - maxx = dstrect->x + dstrect->w; - maxy = dstrect->y + dstrect->h; - - minu = (GLfloat) srcrect->x / texture->w; - minu *= texturedata->texw; - maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w; - maxu *= texturedata->texw; - minv = (GLfloat) srcrect->y / texture->h; - minv *= texturedata->texh; - maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h; - maxv *= texturedata->texh; - - vertices[0] = minx; - vertices[1] = miny; - vertices[2] = maxx; - vertices[3] = miny; - vertices[4] = minx; - vertices[5] = maxy; - vertices[6] = maxx; - vertices[7] = maxy; - - texCoords[0] = minu; - texCoords[1] = minv; - texCoords[2] = maxu; - texCoords[3] = minv; - texCoords[4] = minu; - texCoords[5] = maxv; - texCoords[6] = maxu; - texCoords[7] = maxv; - - data->glVertexPointer(2, GL_FLOAT, 0, vertices); - data->glTexCoordPointer(2, GL_FLOAT, 0, texCoords); - data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - - data->glDisable(GL_TEXTURE_2D); - - return 0; -} - -static int -GLES_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_FRect * dstrect, - const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip) -{ - - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata; - GLfloat minx, miny, maxx, maxy; - GLfloat minu, maxu, minv, maxv; - GLfloat centerx, centery; - GLfloat vertices[8]; - GLfloat texCoords[8]; - - - GLES_ActivateRenderer(renderer); - - data->glEnable(GL_TEXTURE_2D); - - data->glBindTexture(texturedata->type, texturedata->texture); - - if (texture->modMode) { - GLES_SetColor(data, texture->r, texture->g, texture->b, texture->a); - } else { - GLES_SetColor(data, 255, 255, 255, 255); - } - - GLES_SetBlendMode(data, texture->blendMode); - - GLES_SetTexCoords(data, SDL_TRUE); - - centerx = center->x; - centery = center->y; - - /* Rotate and translate */ - data->glPushMatrix(); - data->glTranslatef(dstrect->x + centerx, dstrect->y + centery, 0.0f); - data->glRotatef((GLfloat)angle, 0.0f, 0.0f, 1.0f); - - if (flip & SDL_FLIP_HORIZONTAL) { - minx = dstrect->w - centerx; - maxx = -centerx; - } else { - minx = -centerx; - maxx = dstrect->w - centerx; - } - - if (flip & SDL_FLIP_VERTICAL) { - miny = dstrect->h - centery; - maxy = -centery; - } else { - miny = -centery; - maxy = dstrect->h - centery; - } - - minu = (GLfloat) srcrect->x / texture->w; - minu *= texturedata->texw; - maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w; - maxu *= texturedata->texw; - minv = (GLfloat) srcrect->y / texture->h; - minv *= texturedata->texh; - maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h; - maxv *= texturedata->texh; - - vertices[0] = minx; - vertices[1] = miny; - vertices[2] = maxx; - vertices[3] = miny; - vertices[4] = minx; - vertices[5] = maxy; - vertices[6] = maxx; - vertices[7] = maxy; - - texCoords[0] = minu; - texCoords[1] = minv; - texCoords[2] = maxu; - texCoords[3] = minv; - texCoords[4] = minu; - texCoords[5] = maxv; - texCoords[6] = maxu; - texCoords[7] = maxv; - data->glVertexPointer(2, GL_FLOAT, 0, vertices); - data->glTexCoordPointer(2, GL_FLOAT, 0, texCoords); - data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - data->glPopMatrix(); - data->glDisable(GL_TEXTURE_2D); - - return 0; -} - -static int -GLES_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, - Uint32 pixel_format, void * pixels, int pitch) -{ - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - Uint32 temp_format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_ABGR8888; - void *temp_pixels; - int temp_pitch; - Uint8 *src, *dst, *tmp; - int w, h, length, rows; - int status; - - GLES_ActivateRenderer(renderer); - - temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format); - temp_pixels = SDL_malloc(rect->h * temp_pitch); - if (!temp_pixels) { - return SDL_OutOfMemory(); - } - - SDL_GetRendererOutputSize(renderer, &w, &h); - - data->glPixelStorei(GL_PACK_ALIGNMENT, 1); - - data->glReadPixels(rect->x, renderer->target ? rect->y : (h-rect->y)-rect->h, - rect->w, rect->h, GL_RGBA, GL_UNSIGNED_BYTE, temp_pixels); - - /* Flip the rows to be top-down if necessary */ - if (!renderer->target) { - length = rect->w * SDL_BYTESPERPIXEL(temp_format); - src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch; - dst = (Uint8*)temp_pixels; - tmp = SDL_stack_alloc(Uint8, length); - rows = rect->h / 2; - while (rows--) { - SDL_memcpy(tmp, dst, length); - SDL_memcpy(dst, src, length); - SDL_memcpy(src, tmp, length); - dst += temp_pitch; - src -= temp_pitch; - } - SDL_stack_free(tmp); - } - - status = SDL_ConvertPixels(rect->w, rect->h, - temp_format, temp_pixels, temp_pitch, - pixel_format, pixels, pitch); - SDL_free(temp_pixels); - - return status; -} - -static void -GLES_RenderPresent(SDL_Renderer * renderer) -{ - GLES_ActivateRenderer(renderer); - - SDL_GL_SwapWindow(renderer->window); -} - -static void -GLES_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata; - - GLES_TextureData *data = (GLES_TextureData *) texture->driverdata; - - GLES_ActivateRenderer(renderer); - - if (!data) { - return; - } - if (data->texture) { - renderdata->glDeleteTextures(1, &data->texture); - } - SDL_free(data->pixels); - SDL_free(data); - texture->driverdata = NULL; -} - -static void -GLES_DestroyRenderer(SDL_Renderer * renderer) -{ - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - - if (data) { - if (data->context) { - while (data->framebuffers) { - GLES_FBOList *nextnode = data->framebuffers->next; - data->glDeleteFramebuffersOES(1, &data->framebuffers->FBO); - SDL_free(data->framebuffers); - data->framebuffers = nextnode; - } - SDL_GL_DeleteContext(data->context); - } - SDL_free(data); - } - SDL_free(renderer); -} - -static int GLES_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh) -{ - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata; - GLES_ActivateRenderer(renderer); - - data->glEnable(GL_TEXTURE_2D); - data->glBindTexture(texturedata->type, texturedata->texture); - - if (texw) { - *texw = (float)texturedata->texw; - } - if (texh) { - *texh = (float)texturedata->texh; - } - - return 0; -} - -static int GLES_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture) -{ - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata; - GLES_ActivateRenderer(renderer); - data->glDisable(texturedata->type); - - return 0; -} - -#endif /* SDL_VIDEO_RENDER_OGL_ES && !SDL_RENDER_DISABLED */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/opengles2/SDL_gles2funcs.h b/3rdparty/SDL2/src/render/opengles2/SDL_gles2funcs.h deleted file mode 100644 index 0ecfa7f94ea..00000000000 --- a/3rdparty/SDL2/src/render/opengles2/SDL_gles2funcs.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -SDL_PROC(void, glActiveTexture, (GLenum)) -SDL_PROC(void, glAttachShader, (GLuint, GLuint)) -SDL_PROC(void, glBindAttribLocation, (GLuint, GLuint, const char *)) -SDL_PROC(void, glBindTexture, (GLenum, GLuint)) -SDL_PROC(void, glBlendFuncSeparate, (GLenum, GLenum, GLenum, GLenum)) -SDL_PROC(void, glClear, (GLbitfield)) -SDL_PROC(void, glClearColor, (GLclampf, GLclampf, GLclampf, GLclampf)) -SDL_PROC(void, glCompileShader, (GLuint)) -SDL_PROC(GLuint, glCreateProgram, (void)) -SDL_PROC(GLuint, glCreateShader, (GLenum)) -SDL_PROC(void, glDeleteProgram, (GLuint)) -SDL_PROC(void, glDeleteShader, (GLuint)) -SDL_PROC(void, glDeleteTextures, (GLsizei, const GLuint *)) -SDL_PROC(void, glDisable, (GLenum)) -SDL_PROC(void, glDisableVertexAttribArray, (GLuint)) -SDL_PROC(void, glDrawArrays, (GLenum, GLint, GLsizei)) -SDL_PROC(void, glEnable, (GLenum)) -SDL_PROC(void, glEnableVertexAttribArray, (GLuint)) -SDL_PROC(void, glFinish, (void)) -SDL_PROC(void, glGenFramebuffers, (GLsizei, GLuint *)) -SDL_PROC(void, glGenTextures, (GLsizei, GLuint *)) -SDL_PROC(void, glGetBooleanv, (GLenum, GLboolean *)) -SDL_PROC(const GLubyte *, glGetString, (GLenum)) -SDL_PROC(GLenum, glGetError, (void)) -SDL_PROC(void, glGetIntegerv, (GLenum, GLint *)) -SDL_PROC(void, glGetProgramiv, (GLuint, GLenum, GLint *)) -SDL_PROC(void, glGetShaderInfoLog, (GLuint, GLsizei, GLsizei *, char *)) -SDL_PROC(void, glGetShaderiv, (GLuint, GLenum, GLint *)) -SDL_PROC(GLint, glGetUniformLocation, (GLuint, const char *)) -SDL_PROC(void, glLinkProgram, (GLuint)) -SDL_PROC(void, glPixelStorei, (GLenum, GLint)) -SDL_PROC(void, glReadPixels, (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid*)) -SDL_PROC(void, glScissor, (GLint, GLint, GLsizei, GLsizei)) -SDL_PROC(void, glShaderBinary, (GLsizei, const GLuint *, GLenum, const void *, GLsizei)) -SDL_PROC(void, glShaderSource, (GLuint, GLsizei, const GLchar* const*, const GLint *)) -SDL_PROC(void, glTexImage2D, (GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, const void *)) -SDL_PROC(void, glTexParameteri, (GLenum, GLenum, GLint)) -SDL_PROC(void, glTexSubImage2D, (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *)) -SDL_PROC(void, glUniform1i, (GLint, GLint)) -SDL_PROC(void, glUniform4f, (GLint, GLfloat, GLfloat, GLfloat, GLfloat)) -SDL_PROC(void, glUniformMatrix4fv, (GLint, GLsizei, GLboolean, const GLfloat *)) -SDL_PROC(void, glUseProgram, (GLuint)) -SDL_PROC(void, glVertexAttribPointer, (GLuint, GLint, GLenum, GLboolean, GLsizei, const void *)) -SDL_PROC(void, glViewport, (GLint, GLint, GLsizei, GLsizei)) -SDL_PROC(void, glBindFramebuffer, (GLenum, GLuint)) -SDL_PROC(void, glFramebufferTexture2D, (GLenum, GLenum, GLenum, GLuint, GLint)) -SDL_PROC(GLenum, glCheckFramebufferStatus, (GLenum)) -SDL_PROC(void, glDeleteFramebuffers, (GLsizei, const GLuint *)) -SDL_PROC(GLint, glGetAttribLocation, (GLuint, const GLchar *)) -SDL_PROC(void, glGetProgramInfoLog, (GLuint, GLsizei, GLsizei*, GLchar*)) -SDL_PROC(void, glGenBuffers, (GLsizei, GLuint *)) -SDL_PROC(void, glBindBuffer, (GLenum, GLuint)) -SDL_PROC(void, glBufferData, (GLenum, GLsizeiptr, const GLvoid *, GLenum)) -SDL_PROC(void, glBufferSubData, (GLenum, GLintptr, GLsizeiptr, const GLvoid *)) diff --git a/3rdparty/SDL2/src/render/opengles2/SDL_render_gles2.c b/3rdparty/SDL2/src/render/opengles2/SDL_render_gles2.c deleted file mode 100644 index c846a7b395f..00000000000 --- a/3rdparty/SDL2/src/render/opengles2/SDL_render_gles2.c +++ /dev/null @@ -1,2137 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../../SDL_internal.h" - -#if SDL_VIDEO_RENDER_OGL_ES2 && !SDL_RENDER_DISABLED - -#include "SDL_hints.h" -#include "SDL_opengles2.h" -#include "../SDL_sysrender.h" -#include "../../video/SDL_blit.h" -#include "SDL_shaders_gles2.h" - -/* !!! FIXME: Emscripten makes these into WebGL calls, and WebGL doesn't offer - !!! FIXME: client-side arrays (without an Emscripten compatibility hack, - !!! FIXME: at least), but the current VBO code here is dramatically - !!! FIXME: slower on actual iOS devices, even though the iOS Simulator - !!! FIXME: is okay. Some time after 2.0.4 ships, we should revisit this, - !!! FIXME: fix the performance bottleneck, and make everything use VBOs. -*/ -#ifdef __EMSCRIPTEN__ -#define SDL_GLES2_USE_VBOS 1 -#else -#define SDL_GLES2_USE_VBOS 0 -#endif - -/* To prevent unnecessary window recreation, - * these should match the defaults selected in SDL_GL_ResetAttributes - */ -#define RENDERER_CONTEXT_MAJOR 2 -#define RENDERER_CONTEXT_MINOR 0 - -/* Used to re-create the window with OpenGL ES capability */ -extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags); - -/************************************************************************************************* - * Bootstrap data * - *************************************************************************************************/ - -static SDL_Renderer *GLES2_CreateRenderer(SDL_Window *window, Uint32 flags); - -SDL_RenderDriver GLES2_RenderDriver = { - GLES2_CreateRenderer, - { - "opengles2", - (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE), - 4, - { - SDL_PIXELFORMAT_ARGB8888, - SDL_PIXELFORMAT_ABGR8888, - SDL_PIXELFORMAT_RGB888, - SDL_PIXELFORMAT_BGR888 - }, - 0, - 0 - } -}; - -/************************************************************************************************* - * Context structures * - *************************************************************************************************/ - -typedef struct GLES2_FBOList GLES2_FBOList; - -struct GLES2_FBOList -{ - Uint32 w, h; - GLuint FBO; - GLES2_FBOList *next; -}; - -typedef struct GLES2_TextureData -{ - GLenum texture; - GLenum texture_type; - GLenum pixel_format; - GLenum pixel_type; - void *pixel_data; - int pitch; - /* YUV texture support */ - SDL_bool yuv; - SDL_bool nv12; - GLenum texture_v; - GLenum texture_u; - GLES2_FBOList *fbo; -} GLES2_TextureData; - -typedef struct GLES2_ShaderCacheEntry -{ - GLuint id; - GLES2_ShaderType type; - const GLES2_ShaderInstance *instance; - int references; - Uint8 modulation_r, modulation_g, modulation_b, modulation_a; - struct GLES2_ShaderCacheEntry *prev; - struct GLES2_ShaderCacheEntry *next; -} GLES2_ShaderCacheEntry; - -typedef struct GLES2_ShaderCache -{ - int count; - GLES2_ShaderCacheEntry *head; -} GLES2_ShaderCache; - -typedef struct GLES2_ProgramCacheEntry -{ - GLuint id; - SDL_BlendMode blend_mode; - GLES2_ShaderCacheEntry *vertex_shader; - GLES2_ShaderCacheEntry *fragment_shader; - GLuint uniform_locations[16]; - Uint8 color_r, color_g, color_b, color_a; - Uint8 modulation_r, modulation_g, modulation_b, modulation_a; - GLfloat projection[4][4]; - struct GLES2_ProgramCacheEntry *prev; - struct GLES2_ProgramCacheEntry *next; -} GLES2_ProgramCacheEntry; - -typedef struct GLES2_ProgramCache -{ - int count; - GLES2_ProgramCacheEntry *head; - GLES2_ProgramCacheEntry *tail; -} GLES2_ProgramCache; - -typedef enum -{ - GLES2_ATTRIBUTE_POSITION = 0, - GLES2_ATTRIBUTE_TEXCOORD = 1, - GLES2_ATTRIBUTE_ANGLE = 2, - GLES2_ATTRIBUTE_CENTER = 3, -} GLES2_Attribute; - -typedef enum -{ - GLES2_UNIFORM_PROJECTION, - GLES2_UNIFORM_TEXTURE, - GLES2_UNIFORM_MODULATION, - GLES2_UNIFORM_COLOR, - GLES2_UNIFORM_TEXTURE_U, - GLES2_UNIFORM_TEXTURE_V -} GLES2_Uniform; - -typedef enum -{ - GLES2_IMAGESOURCE_SOLID, - GLES2_IMAGESOURCE_TEXTURE_ABGR, - GLES2_IMAGESOURCE_TEXTURE_ARGB, - GLES2_IMAGESOURCE_TEXTURE_RGB, - GLES2_IMAGESOURCE_TEXTURE_BGR, - GLES2_IMAGESOURCE_TEXTURE_YUV, - GLES2_IMAGESOURCE_TEXTURE_NV12, - GLES2_IMAGESOURCE_TEXTURE_NV21 -} GLES2_ImageSource; - -typedef struct GLES2_DriverContext -{ - SDL_GLContext *context; - - SDL_bool debug_enabled; - - struct { - int blendMode; - SDL_bool tex_coords; - } current; - -#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params; -#include "SDL_gles2funcs.h" -#undef SDL_PROC - GLES2_FBOList *framebuffers; - GLuint window_framebuffer; - - int shader_format_count; - GLenum *shader_formats; - GLES2_ShaderCache shader_cache; - GLES2_ProgramCache program_cache; - GLES2_ProgramCacheEntry *current_program; - Uint8 clear_r, clear_g, clear_b, clear_a; - -#if SDL_GLES2_USE_VBOS - GLuint vertex_buffers[4]; - GLsizeiptr vertex_buffer_size[4]; -#endif -} GLES2_DriverContext; - -#define GLES2_MAX_CACHED_PROGRAMS 8 - - -SDL_FORCE_INLINE const char* -GL_TranslateError (GLenum error) -{ -#define GL_ERROR_TRANSLATE(e) case e: return #e; - switch (error) { - GL_ERROR_TRANSLATE(GL_INVALID_ENUM) - GL_ERROR_TRANSLATE(GL_INVALID_VALUE) - GL_ERROR_TRANSLATE(GL_INVALID_OPERATION) - GL_ERROR_TRANSLATE(GL_OUT_OF_MEMORY) - GL_ERROR_TRANSLATE(GL_NO_ERROR) - default: - return "UNKNOWN"; -} -#undef GL_ERROR_TRANSLATE -} - -SDL_FORCE_INLINE void -GL_ClearErrors(SDL_Renderer *renderer) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *) renderer->driverdata; - - if (!data->debug_enabled) { - return; - } - while (data->glGetError() != GL_NO_ERROR) { - continue; - } -} - -SDL_FORCE_INLINE int -GL_CheckAllErrors (const char *prefix, SDL_Renderer *renderer, const char *file, int line, const char *function) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *) renderer->driverdata; - int ret = 0; - - if (!data->debug_enabled) { - return 0; - } - /* check gl errors (can return multiple errors) */ - for (;;) { - GLenum error = data->glGetError(); - if (error != GL_NO_ERROR) { - if (prefix == NULL || prefix[0] == '\0') { - prefix = "generic"; - } - SDL_SetError("%s: %s (%d): %s %s (0x%X)", prefix, file, line, function, GL_TranslateError(error), error); - ret = -1; - } else { - break; - } - } - return ret; -} - -#if 0 -#define GL_CheckError(prefix, renderer) -#elif defined(_MSC_VER) -#define GL_CheckError(prefix, renderer) GL_CheckAllErrors(prefix, renderer, __FILE__, __LINE__, __FUNCTION__) -#else -#define GL_CheckError(prefix, renderer) GL_CheckAllErrors(prefix, renderer, __FILE__, __LINE__, __PRETTY_FUNCTION__) -#endif - - -/************************************************************************************************* - * Renderer state APIs * - *************************************************************************************************/ - -static int GLES2_ActivateRenderer(SDL_Renderer *renderer); -static void GLES2_WindowEvent(SDL_Renderer * renderer, - const SDL_WindowEvent *event); -static int GLES2_UpdateViewport(SDL_Renderer * renderer); -static void GLES2_DestroyRenderer(SDL_Renderer *renderer); -static int GLES2_SetOrthographicProjection(SDL_Renderer *renderer); - - -static SDL_GLContext SDL_CurrentContext = NULL; - -static int GLES2_LoadFunctions(GLES2_DriverContext * data) -{ -#if SDL_VIDEO_DRIVER_UIKIT -#define __SDL_NOGETPROCADDR__ -#elif SDL_VIDEO_DRIVER_ANDROID -#define __SDL_NOGETPROCADDR__ -#elif SDL_VIDEO_DRIVER_PANDORA -#define __SDL_NOGETPROCADDR__ -#endif - -#if defined __SDL_NOGETPROCADDR__ -#define SDL_PROC(ret,func,params) data->func=func; -#else -#define SDL_PROC(ret,func,params) \ - do { \ - data->func = SDL_GL_GetProcAddress(#func); \ - if ( ! data->func ) { \ - return SDL_SetError("Couldn't load GLES2 function %s: %s\n", #func, SDL_GetError()); \ - } \ - } while ( 0 ); -#endif /* __SDL_NOGETPROCADDR__ */ - -#include "SDL_gles2funcs.h" -#undef SDL_PROC - return 0; -} - -GLES2_FBOList * -GLES2_GetFBO(GLES2_DriverContext *data, Uint32 w, Uint32 h) -{ - GLES2_FBOList *result = data->framebuffers; - while ((result) && ((result->w != w) || (result->h != h)) ) { - result = result->next; - } - if (result == NULL) { - result = SDL_malloc(sizeof(GLES2_FBOList)); - result->w = w; - result->h = h; - data->glGenFramebuffers(1, &result->FBO); - result->next = data->framebuffers; - data->framebuffers = result; - } - return result; -} - -static int -GLES2_ActivateRenderer(SDL_Renderer * renderer) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; - - if (SDL_CurrentContext != data->context) { - /* Null out the current program to ensure we set it again */ - data->current_program = NULL; - - if (SDL_GL_MakeCurrent(renderer->window, data->context) < 0) { - return -1; - } - SDL_CurrentContext = data->context; - - GLES2_UpdateViewport(renderer); - } - - GL_ClearErrors(renderer); - - return 0; -} - -static void -GLES2_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; - - if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED || - event->event == SDL_WINDOWEVENT_SHOWN || - event->event == SDL_WINDOWEVENT_HIDDEN) { - /* Rebind the context to the window area */ - SDL_CurrentContext = NULL; - } - - if (event->event == SDL_WINDOWEVENT_MINIMIZED) { - /* According to Apple documentation, we need to finish drawing NOW! */ - data->glFinish(); - } -} - -static int -GLES2_GetOutputSize(SDL_Renderer * renderer, int *w, int *h) -{ - SDL_GL_GetDrawableSize(renderer->window, w, h); - return 0; -} - -static int -GLES2_UpdateViewport(SDL_Renderer * renderer) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; - - if (SDL_CurrentContext != data->context) { - /* We'll update the viewport after we rebind the context */ - return 0; - } - - if (renderer->target) { - data->glViewport(renderer->viewport.x, renderer->viewport.y, - renderer->viewport.w, renderer->viewport.h); - } else { - int w, h; - - SDL_GL_GetDrawableSize(renderer->window, &w, &h); - data->glViewport(renderer->viewport.x, (h - renderer->viewport.y - renderer->viewport.h), - renderer->viewport.w, renderer->viewport.h); - } - - if (data->current_program) { - GLES2_SetOrthographicProjection(renderer); - } - return GL_CheckError("", renderer); -} - -static int -GLES2_UpdateClipRect(SDL_Renderer * renderer) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; - - if (SDL_CurrentContext != data->context) { - /* We'll update the clip rect after we rebind the context */ - return 0; - } - - if (renderer->clipping_enabled) { - const SDL_Rect *rect = &renderer->clip_rect; - data->glEnable(GL_SCISSOR_TEST); - if (renderer->target) { - data->glScissor(renderer->viewport.x + rect->x, renderer->viewport.y + rect->y, rect->w, rect->h); - } else { - int w, h; - - SDL_GL_GetDrawableSize(renderer->window, &w, &h); - data->glScissor(renderer->viewport.x + rect->x, h - renderer->viewport.y - rect->y - rect->h, rect->w, rect->h); - } - } else { - data->glDisable(GL_SCISSOR_TEST); - } - return 0; -} - -static void -GLES2_DestroyRenderer(SDL_Renderer *renderer) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; - - /* Deallocate everything */ - if (data) { - GLES2_ActivateRenderer(renderer); - - { - GLES2_ShaderCacheEntry *entry; - GLES2_ShaderCacheEntry *next; - entry = data->shader_cache.head; - while (entry) { - data->glDeleteShader(entry->id); - next = entry->next; - SDL_free(entry); - entry = next; - } - } - { - GLES2_ProgramCacheEntry *entry; - GLES2_ProgramCacheEntry *next; - entry = data->program_cache.head; - while (entry) { - data->glDeleteProgram(entry->id); - next = entry->next; - SDL_free(entry); - entry = next; - } - } - if (data->context) { - while (data->framebuffers) { - GLES2_FBOList *nextnode = data->framebuffers->next; - data->glDeleteFramebuffers(1, &data->framebuffers->FBO); - GL_CheckError("", renderer); - SDL_free(data->framebuffers); - data->framebuffers = nextnode; - } - SDL_GL_DeleteContext(data->context); - } - SDL_free(data->shader_formats); - SDL_free(data); - } - SDL_free(renderer); -} - -/************************************************************************************************* - * Texture APIs * - *************************************************************************************************/ - -static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture); -static int GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, - const void *pixels, int pitch); -static int GLES2_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, - const Uint8 *Yplane, int Ypitch, - const Uint8 *Uplane, int Upitch, - const Uint8 *Vplane, int Vpitch); -static int GLES2_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, - void **pixels, int *pitch); -static void GLES2_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture); -static int GLES2_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture); -static void GLES2_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture); - -static GLenum -GetScaleQuality(void) -{ - const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY); - - if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) { - return GL_NEAREST; - } else { - return GL_LINEAR; - } -} - -static int -GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture) -{ - GLES2_DriverContext *renderdata = (GLES2_DriverContext *)renderer->driverdata; - GLES2_TextureData *data; - GLenum format; - GLenum type; - GLenum scaleMode; - - GLES2_ActivateRenderer(renderer); - - /* Determine the corresponding GLES texture format params */ - switch (texture->format) - { - case SDL_PIXELFORMAT_ARGB8888: - case SDL_PIXELFORMAT_ABGR8888: - case SDL_PIXELFORMAT_RGB888: - case SDL_PIXELFORMAT_BGR888: - format = GL_RGBA; - type = GL_UNSIGNED_BYTE; - break; - case SDL_PIXELFORMAT_IYUV: - case SDL_PIXELFORMAT_YV12: - case SDL_PIXELFORMAT_NV12: - case SDL_PIXELFORMAT_NV21: - format = GL_LUMINANCE; - type = GL_UNSIGNED_BYTE; - break; - default: - return SDL_SetError("Texture format not supported"); - } - - /* Allocate a texture struct */ - data = (GLES2_TextureData *)SDL_calloc(1, sizeof(GLES2_TextureData)); - if (!data) { - return SDL_OutOfMemory(); - } - data->texture = 0; - data->texture_type = GL_TEXTURE_2D; - data->pixel_format = format; - data->pixel_type = type; - data->yuv = ((texture->format == SDL_PIXELFORMAT_IYUV) || (texture->format == SDL_PIXELFORMAT_YV12)); - data->nv12 = ((texture->format == SDL_PIXELFORMAT_NV12) || (texture->format == SDL_PIXELFORMAT_NV21)); - data->texture_u = 0; - data->texture_v = 0; - scaleMode = GetScaleQuality(); - - /* Allocate a blob for image renderdata */ - if (texture->access == SDL_TEXTUREACCESS_STREAMING) { - size_t size; - data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format); - size = texture->h * data->pitch; - if (data->yuv) { - /* Need to add size for the U and V planes */ - size += (2 * (texture->h * data->pitch) / 4); - } - if (data->nv12) { - /* Need to add size for the U/V plane */ - size += ((texture->h * data->pitch) / 2); - } - data->pixel_data = SDL_calloc(1, size); - if (!data->pixel_data) { - SDL_free(data); - return SDL_OutOfMemory(); - } - } - - /* Allocate the texture */ - GL_CheckError("", renderer); - - if (data->yuv) { - renderdata->glGenTextures(1, &data->texture_v); - if (GL_CheckError("glGenTexures()", renderer) < 0) { - return -1; - } - renderdata->glActiveTexture(GL_TEXTURE2); - renderdata->glBindTexture(data->texture_type, data->texture_v); - renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MIN_FILTER, scaleMode); - renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MAG_FILTER, scaleMode); - renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - renderdata->glTexImage2D(data->texture_type, 0, format, texture->w / 2, texture->h / 2, 0, format, type, NULL); - - renderdata->glGenTextures(1, &data->texture_u); - if (GL_CheckError("glGenTexures()", renderer) < 0) { - return -1; - } - renderdata->glActiveTexture(GL_TEXTURE1); - renderdata->glBindTexture(data->texture_type, data->texture_u); - renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MIN_FILTER, scaleMode); - renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MAG_FILTER, scaleMode); - renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - renderdata->glTexImage2D(data->texture_type, 0, format, texture->w / 2, texture->h / 2, 0, format, type, NULL); - if (GL_CheckError("glTexImage2D()", renderer) < 0) { - return -1; - } - } - - if (data->nv12) { - renderdata->glGenTextures(1, &data->texture_u); - if (GL_CheckError("glGenTexures()", renderer) < 0) { - return -1; - } - renderdata->glActiveTexture(GL_TEXTURE1); - renderdata->glBindTexture(data->texture_type, data->texture_u); - renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MIN_FILTER, scaleMode); - renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MAG_FILTER, scaleMode); - renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - renderdata->glTexImage2D(data->texture_type, 0, GL_LUMINANCE_ALPHA, texture->w / 2, texture->h / 2, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, NULL); - if (GL_CheckError("glTexImage2D()", renderer) < 0) { - return -1; - } - } - - renderdata->glGenTextures(1, &data->texture); - if (GL_CheckError("glGenTexures()", renderer) < 0) { - return -1; - } - texture->driverdata = data; - renderdata->glActiveTexture(GL_TEXTURE0); - renderdata->glBindTexture(data->texture_type, data->texture); - renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MIN_FILTER, scaleMode); - renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MAG_FILTER, scaleMode); - renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - renderdata->glTexImage2D(data->texture_type, 0, format, texture->w, texture->h, 0, format, type, NULL); - if (GL_CheckError("glTexImage2D()", renderer) < 0) { - return -1; - } - - if (texture->access == SDL_TEXTUREACCESS_TARGET) { - data->fbo = GLES2_GetFBO(renderer->driverdata, texture->w, texture->h); - } else { - data->fbo = NULL; - } - - return GL_CheckError("", renderer); -} - -static int -GLES2_TexSubImage2D(GLES2_DriverContext *data, GLenum target, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels, GLint pitch, GLint bpp) -{ - Uint8 *blob = NULL; - Uint8 *src; - int src_pitch; - int y; - - /* Reformat the texture data into a tightly packed array */ - src_pitch = width * bpp; - src = (Uint8 *)pixels; - if (pitch != src_pitch) { - blob = (Uint8 *)SDL_malloc(src_pitch * height); - if (!blob) { - return SDL_OutOfMemory(); - } - src = blob; - for (y = 0; y < height; ++y) - { - SDL_memcpy(src, pixels, src_pitch); - src += src_pitch; - pixels = (Uint8 *)pixels + pitch; - } - src = blob; - } - - data->glTexSubImage2D(target, 0, xoffset, yoffset, width, height, format, type, src); - if (blob) { - SDL_free(blob); - } - return 0; -} - -static int -GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, - const void *pixels, int pitch) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; - GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata; - - GLES2_ActivateRenderer(renderer); - - /* Bail out if we're supposed to update an empty rectangle */ - if (rect->w <= 0 || rect->h <= 0) { - return 0; - } - - /* Create a texture subimage with the supplied data */ - data->glBindTexture(tdata->texture_type, tdata->texture); - GLES2_TexSubImage2D(data, tdata->texture_type, - rect->x, - rect->y, - rect->w, - rect->h, - tdata->pixel_format, - tdata->pixel_type, - pixels, pitch, SDL_BYTESPERPIXEL(texture->format)); - - if (tdata->yuv) { - /* Skip to the correct offset into the next texture */ - pixels = (const void*)((const Uint8*)pixels + rect->h * pitch); - if (texture->format == SDL_PIXELFORMAT_YV12) { - data->glBindTexture(tdata->texture_type, tdata->texture_v); - } else { - data->glBindTexture(tdata->texture_type, tdata->texture_u); - } - GLES2_TexSubImage2D(data, tdata->texture_type, - rect->x / 2, - rect->y / 2, - rect->w / 2, - rect->h / 2, - tdata->pixel_format, - tdata->pixel_type, - pixels, pitch / 2, 1); - - /* Skip to the correct offset into the next texture */ - pixels = (const void*)((const Uint8*)pixels + (rect->h * pitch)/4); - if (texture->format == SDL_PIXELFORMAT_YV12) { - data->glBindTexture(tdata->texture_type, tdata->texture_u); - } else { - data->glBindTexture(tdata->texture_type, tdata->texture_v); - } - GLES2_TexSubImage2D(data, tdata->texture_type, - rect->x / 2, - rect->y / 2, - rect->w / 2, - rect->h / 2, - tdata->pixel_format, - tdata->pixel_type, - pixels, pitch / 2, 1); - } - - if (tdata->nv12) { - /* Skip to the correct offset into the next texture */ - pixels = (const void*)((const Uint8*)pixels + rect->h * pitch); - data->glBindTexture(tdata->texture_type, tdata->texture_u); - GLES2_TexSubImage2D(data, tdata->texture_type, - rect->x / 2, - rect->y / 2, - rect->w / 2, - rect->h / 2, - GL_LUMINANCE_ALPHA, - GL_UNSIGNED_BYTE, - pixels, pitch, 2); - } - - return GL_CheckError("glTexSubImage2D()", renderer); -} - -static int -GLES2_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, - const Uint8 *Yplane, int Ypitch, - const Uint8 *Uplane, int Upitch, - const Uint8 *Vplane, int Vpitch) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; - GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata; - - GLES2_ActivateRenderer(renderer); - - /* Bail out if we're supposed to update an empty rectangle */ - if (rect->w <= 0 || rect->h <= 0) { - return 0; - } - - data->glBindTexture(tdata->texture_type, tdata->texture_v); - GLES2_TexSubImage2D(data, tdata->texture_type, - rect->x / 2, - rect->y / 2, - rect->w / 2, - rect->h / 2, - tdata->pixel_format, - tdata->pixel_type, - Vplane, Vpitch, 1); - - data->glBindTexture(tdata->texture_type, tdata->texture_u); - GLES2_TexSubImage2D(data, tdata->texture_type, - rect->x / 2, - rect->y / 2, - rect->w / 2, - rect->h / 2, - tdata->pixel_format, - tdata->pixel_type, - Uplane, Upitch, 1); - - data->glBindTexture(tdata->texture_type, tdata->texture); - GLES2_TexSubImage2D(data, tdata->texture_type, - rect->x, - rect->y, - rect->w, - rect->h, - tdata->pixel_format, - tdata->pixel_type, - Yplane, Ypitch, 1); - - return GL_CheckError("glTexSubImage2D()", renderer); -} - -static int -GLES2_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, - void **pixels, int *pitch) -{ - GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata; - - /* Retrieve the buffer/pitch for the specified region */ - *pixels = (Uint8 *)tdata->pixel_data + - (tdata->pitch * rect->y) + - (rect->x * SDL_BYTESPERPIXEL(texture->format)); - *pitch = tdata->pitch; - - return 0; -} - -static void -GLES2_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture) -{ - GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata; - SDL_Rect rect; - - /* We do whole texture updates, at least for now */ - rect.x = 0; - rect.y = 0; - rect.w = texture->w; - rect.h = texture->h; - GLES2_UpdateTexture(renderer, texture, &rect, tdata->pixel_data, tdata->pitch); -} - -static int -GLES2_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *) renderer->driverdata; - GLES2_TextureData *texturedata = NULL; - GLenum status; - - if (texture == NULL) { - data->glBindFramebuffer(GL_FRAMEBUFFER, data->window_framebuffer); - } else { - texturedata = (GLES2_TextureData *) texture->driverdata; - data->glBindFramebuffer(GL_FRAMEBUFFER, texturedata->fbo->FBO); - /* TODO: check if texture pixel format allows this operation */ - data->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texturedata->texture_type, texturedata->texture, 0); - /* Check FBO status */ - status = data->glCheckFramebufferStatus(GL_FRAMEBUFFER); - if (status != GL_FRAMEBUFFER_COMPLETE) { - return SDL_SetError("glFramebufferTexture2D() failed"); - } - } - return 0; -} - -static void -GLES2_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; - GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata; - - GLES2_ActivateRenderer(renderer); - - /* Destroy the texture */ - if (tdata) { - data->glDeleteTextures(1, &tdata->texture); - if (tdata->texture_v) { - data->glDeleteTextures(1, &tdata->texture_v); - } - if (tdata->texture_u) { - data->glDeleteTextures(1, &tdata->texture_u); - } - SDL_free(tdata->pixel_data); - SDL_free(tdata); - texture->driverdata = NULL; - } -} - -/************************************************************************************************* - * Shader management functions * - *************************************************************************************************/ - -static GLES2_ShaderCacheEntry *GLES2_CacheShader(SDL_Renderer *renderer, GLES2_ShaderType type, - SDL_BlendMode blendMode); -static void GLES2_EvictShader(SDL_Renderer *renderer, GLES2_ShaderCacheEntry *entry); -static GLES2_ProgramCacheEntry *GLES2_CacheProgram(SDL_Renderer *renderer, - GLES2_ShaderCacheEntry *vertex, - GLES2_ShaderCacheEntry *fragment, - SDL_BlendMode blendMode); -static int GLES2_SelectProgram(SDL_Renderer *renderer, GLES2_ImageSource source, - SDL_BlendMode blendMode); - -static GLES2_ProgramCacheEntry * -GLES2_CacheProgram(SDL_Renderer *renderer, GLES2_ShaderCacheEntry *vertex, - GLES2_ShaderCacheEntry *fragment, SDL_BlendMode blendMode) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; - GLES2_ProgramCacheEntry *entry; - GLES2_ShaderCacheEntry *shaderEntry; - GLint linkSuccessful; - - /* Check if we've already cached this program */ - entry = data->program_cache.head; - while (entry) { - if (entry->vertex_shader == vertex && entry->fragment_shader == fragment) { - break; - } - entry = entry->next; - } - if (entry) { - if (data->program_cache.head != entry) { - if (entry->next) { - entry->next->prev = entry->prev; - } - if (entry->prev) { - entry->prev->next = entry->next; - } - entry->prev = NULL; - entry->next = data->program_cache.head; - data->program_cache.head->prev = entry; - data->program_cache.head = entry; - } - return entry; - } - - /* Create a program cache entry */ - entry = (GLES2_ProgramCacheEntry *)SDL_calloc(1, sizeof(GLES2_ProgramCacheEntry)); - if (!entry) { - SDL_OutOfMemory(); - return NULL; - } - entry->vertex_shader = vertex; - entry->fragment_shader = fragment; - entry->blend_mode = blendMode; - - /* Create the program and link it */ - entry->id = data->glCreateProgram(); - data->glAttachShader(entry->id, vertex->id); - data->glAttachShader(entry->id, fragment->id); - data->glBindAttribLocation(entry->id, GLES2_ATTRIBUTE_POSITION, "a_position"); - data->glBindAttribLocation(entry->id, GLES2_ATTRIBUTE_TEXCOORD, "a_texCoord"); - data->glBindAttribLocation(entry->id, GLES2_ATTRIBUTE_ANGLE, "a_angle"); - data->glBindAttribLocation(entry->id, GLES2_ATTRIBUTE_CENTER, "a_center"); - data->glLinkProgram(entry->id); - data->glGetProgramiv(entry->id, GL_LINK_STATUS, &linkSuccessful); - if (!linkSuccessful) { - data->glDeleteProgram(entry->id); - SDL_free(entry); - SDL_SetError("Failed to link shader program"); - return NULL; - } - - /* Predetermine locations of uniform variables */ - entry->uniform_locations[GLES2_UNIFORM_PROJECTION] = - data->glGetUniformLocation(entry->id, "u_projection"); - entry->uniform_locations[GLES2_UNIFORM_TEXTURE_V] = - data->glGetUniformLocation(entry->id, "u_texture_v"); - entry->uniform_locations[GLES2_UNIFORM_TEXTURE_U] = - data->glGetUniformLocation(entry->id, "u_texture_u"); - entry->uniform_locations[GLES2_UNIFORM_TEXTURE] = - data->glGetUniformLocation(entry->id, "u_texture"); - entry->uniform_locations[GLES2_UNIFORM_MODULATION] = - data->glGetUniformLocation(entry->id, "u_modulation"); - entry->uniform_locations[GLES2_UNIFORM_COLOR] = - data->glGetUniformLocation(entry->id, "u_color"); - - entry->modulation_r = entry->modulation_g = entry->modulation_b = entry->modulation_a = 255; - entry->color_r = entry->color_g = entry->color_b = entry->color_a = 255; - - data->glUseProgram(entry->id); - data->glUniform1i(entry->uniform_locations[GLES2_UNIFORM_TEXTURE_V], 2); /* always texture unit 2. */ - data->glUniform1i(entry->uniform_locations[GLES2_UNIFORM_TEXTURE_U], 1); /* always texture unit 1. */ - data->glUniform1i(entry->uniform_locations[GLES2_UNIFORM_TEXTURE], 0); /* always texture unit 0. */ - data->glUniformMatrix4fv(entry->uniform_locations[GLES2_UNIFORM_PROJECTION], 1, GL_FALSE, (GLfloat *)entry->projection); - data->glUniform4f(entry->uniform_locations[GLES2_UNIFORM_MODULATION], 1.0f, 1.0f, 1.0f, 1.0f); - data->glUniform4f(entry->uniform_locations[GLES2_UNIFORM_COLOR], 1.0f, 1.0f, 1.0f, 1.0f); - - /* Cache the linked program */ - if (data->program_cache.head) { - entry->next = data->program_cache.head; - data->program_cache.head->prev = entry; - } else { - data->program_cache.tail = entry; - } - data->program_cache.head = entry; - ++data->program_cache.count; - - /* Increment the refcount of the shaders we're using */ - ++vertex->references; - ++fragment->references; - - /* Evict the last entry from the cache if we exceed the limit */ - if (data->program_cache.count > GLES2_MAX_CACHED_PROGRAMS) { - shaderEntry = data->program_cache.tail->vertex_shader; - if (--shaderEntry->references <= 0) { - GLES2_EvictShader(renderer, shaderEntry); - } - shaderEntry = data->program_cache.tail->fragment_shader; - if (--shaderEntry->references <= 0) { - GLES2_EvictShader(renderer, shaderEntry); - } - data->glDeleteProgram(data->program_cache.tail->id); - data->program_cache.tail = data->program_cache.tail->prev; - SDL_free(data->program_cache.tail->next); - data->program_cache.tail->next = NULL; - --data->program_cache.count; - } - return entry; -} - -static GLES2_ShaderCacheEntry * -GLES2_CacheShader(SDL_Renderer *renderer, GLES2_ShaderType type, SDL_BlendMode blendMode) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; - const GLES2_Shader *shader; - const GLES2_ShaderInstance *instance = NULL; - GLES2_ShaderCacheEntry *entry = NULL; - GLint compileSuccessful = GL_FALSE; - int i, j; - - /* Find the corresponding shader */ - shader = GLES2_GetShader(type, blendMode); - if (!shader) { - SDL_SetError("No shader matching the requested characteristics was found"); - return NULL; - } - - /* Find a matching shader instance that's supported on this hardware */ - for (i = 0; i < shader->instance_count && !instance; ++i) { - for (j = 0; j < data->shader_format_count && !instance; ++j) { - if (!shader->instances[i]) { - continue; - } - if (shader->instances[i]->format != data->shader_formats[j]) { - continue; - } - instance = shader->instances[i]; - } - } - if (!instance) { - SDL_SetError("The specified shader cannot be loaded on the current platform"); - return NULL; - } - - /* Check if we've already cached this shader */ - entry = data->shader_cache.head; - while (entry) { - if (entry->instance == instance) { - break; - } - entry = entry->next; - } - if (entry) { - return entry; - } - - /* Create a shader cache entry */ - entry = (GLES2_ShaderCacheEntry *)SDL_calloc(1, sizeof(GLES2_ShaderCacheEntry)); - if (!entry) { - SDL_OutOfMemory(); - return NULL; - } - entry->type = type; - entry->instance = instance; - - /* Compile or load the selected shader instance */ - entry->id = data->glCreateShader(instance->type); - if (instance->format == (GLenum)-1) { - data->glShaderSource(entry->id, 1, (const char **)&instance->data, NULL); - data->glCompileShader(entry->id); - data->glGetShaderiv(entry->id, GL_COMPILE_STATUS, &compileSuccessful); - } else { - data->glShaderBinary(1, &entry->id, instance->format, instance->data, instance->length); - compileSuccessful = GL_TRUE; - } - if (!compileSuccessful) { - char *info = NULL; - int length = 0; - - data->glGetShaderiv(entry->id, GL_INFO_LOG_LENGTH, &length); - if (length > 0) { - info = SDL_stack_alloc(char, length); - if (info) { - data->glGetShaderInfoLog(entry->id, length, &length, info); - } - } - if (info) { - SDL_SetError("Failed to load the shader: %s", info); - SDL_stack_free(info); - } else { - SDL_SetError("Failed to load the shader"); - } - data->glDeleteShader(entry->id); - SDL_free(entry); - return NULL; - } - - /* Link the shader entry in at the front of the cache */ - if (data->shader_cache.head) { - entry->next = data->shader_cache.head; - data->shader_cache.head->prev = entry; - } - data->shader_cache.head = entry; - ++data->shader_cache.count; - return entry; -} - -static void -GLES2_EvictShader(SDL_Renderer *renderer, GLES2_ShaderCacheEntry *entry) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; - - /* Unlink the shader from the cache */ - if (entry->next) { - entry->next->prev = entry->prev; - } - if (entry->prev) { - entry->prev->next = entry->next; - } - if (data->shader_cache.head == entry) { - data->shader_cache.head = entry->next; - } - --data->shader_cache.count; - - /* Deallocate the shader */ - data->glDeleteShader(entry->id); - SDL_free(entry); -} - -static int -GLES2_SelectProgram(SDL_Renderer *renderer, GLES2_ImageSource source, SDL_BlendMode blendMode) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; - GLES2_ShaderCacheEntry *vertex = NULL; - GLES2_ShaderCacheEntry *fragment = NULL; - GLES2_ShaderType vtype, ftype; - GLES2_ProgramCacheEntry *program; - - /* Select an appropriate shader pair for the specified modes */ - vtype = GLES2_SHADER_VERTEX_DEFAULT; - switch (source) { - case GLES2_IMAGESOURCE_SOLID: - ftype = GLES2_SHADER_FRAGMENT_SOLID_SRC; - break; - case GLES2_IMAGESOURCE_TEXTURE_ABGR: - ftype = GLES2_SHADER_FRAGMENT_TEXTURE_ABGR_SRC; - break; - case GLES2_IMAGESOURCE_TEXTURE_ARGB: - ftype = GLES2_SHADER_FRAGMENT_TEXTURE_ARGB_SRC; - break; - case GLES2_IMAGESOURCE_TEXTURE_RGB: - ftype = GLES2_SHADER_FRAGMENT_TEXTURE_RGB_SRC; - break; - case GLES2_IMAGESOURCE_TEXTURE_BGR: - ftype = GLES2_SHADER_FRAGMENT_TEXTURE_BGR_SRC; - break; - case GLES2_IMAGESOURCE_TEXTURE_YUV: - ftype = GLES2_SHADER_FRAGMENT_TEXTURE_YUV_SRC; - break; - case GLES2_IMAGESOURCE_TEXTURE_NV12: - ftype = GLES2_SHADER_FRAGMENT_TEXTURE_NV12_SRC; - break; - case GLES2_IMAGESOURCE_TEXTURE_NV21: - ftype = GLES2_SHADER_FRAGMENT_TEXTURE_NV21_SRC; - break; - default: - goto fault; - } - - /* Load the requested shaders */ - vertex = GLES2_CacheShader(renderer, vtype, blendMode); - if (!vertex) { - goto fault; - } - fragment = GLES2_CacheShader(renderer, ftype, blendMode); - if (!fragment) { - goto fault; - } - - /* Check if we need to change programs at all */ - if (data->current_program && - data->current_program->vertex_shader == vertex && - data->current_program->fragment_shader == fragment) { - return 0; - } - - /* Generate a matching program */ - program = GLES2_CacheProgram(renderer, vertex, fragment, blendMode); - if (!program) { - goto fault; - } - - /* Select that program in OpenGL */ - data->glUseProgram(program->id); - - /* Set the current program */ - data->current_program = program; - - /* Activate an orthographic projection */ - if (GLES2_SetOrthographicProjection(renderer) < 0) { - goto fault; - } - - /* Clean up and return */ - return 0; -fault: - if (vertex && vertex->references <= 0) { - GLES2_EvictShader(renderer, vertex); - } - if (fragment && fragment->references <= 0) { - GLES2_EvictShader(renderer, fragment); - } - data->current_program = NULL; - return -1; -} - -static int -GLES2_SetOrthographicProjection(SDL_Renderer *renderer) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; - GLfloat projection[4][4]; - - if (!renderer->viewport.w || !renderer->viewport.h) { - return 0; - } - - /* Prepare an orthographic projection */ - projection[0][0] = 2.0f / renderer->viewport.w; - projection[0][1] = 0.0f; - projection[0][2] = 0.0f; - projection[0][3] = 0.0f; - projection[1][0] = 0.0f; - if (renderer->target) { - projection[1][1] = 2.0f / renderer->viewport.h; - } else { - projection[1][1] = -2.0f / renderer->viewport.h; - } - projection[1][2] = 0.0f; - projection[1][3] = 0.0f; - projection[2][0] = 0.0f; - projection[2][1] = 0.0f; - projection[2][2] = 0.0f; - projection[2][3] = 0.0f; - projection[3][0] = -1.0f; - if (renderer->target) { - projection[3][1] = -1.0f; - } else { - projection[3][1] = 1.0f; - } - projection[3][2] = 0.0f; - projection[3][3] = 1.0f; - - /* Set the projection matrix */ - if (SDL_memcmp(data->current_program->projection, projection, sizeof (projection)) != 0) { - const GLuint locProjection = data->current_program->uniform_locations[GLES2_UNIFORM_PROJECTION]; - data->glUniformMatrix4fv(locProjection, 1, GL_FALSE, (GLfloat *)projection); - SDL_memcpy(data->current_program->projection, projection, sizeof (projection)); - } - - return 0; -} - -/************************************************************************************************* - * Rendering functions * - *************************************************************************************************/ - -static const float inv255f = 1.0f / 255.0f; - -static int GLES2_RenderClear(SDL_Renderer *renderer); -static int GLES2_RenderDrawPoints(SDL_Renderer *renderer, const SDL_FPoint *points, int count); -static int GLES2_RenderDrawLines(SDL_Renderer *renderer, const SDL_FPoint *points, int count); -static int GLES2_RenderFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count); -static int GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, - const SDL_FRect *dstrect); -static int GLES2_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_FRect * dstrect, - const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip); -static int GLES2_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, - Uint32 pixel_format, void * pixels, int pitch); -static void GLES2_RenderPresent(SDL_Renderer *renderer); - -static SDL_bool -CompareColors(Uint8 r1, Uint8 g1, Uint8 b1, Uint8 a1, - Uint8 r2, Uint8 g2, Uint8 b2, Uint8 a2) -{ - Uint32 Pixel1, Pixel2; - RGBA8888_FROM_RGBA(Pixel1, r1, g1, b1, a1); - RGBA8888_FROM_RGBA(Pixel2, r2, g2, b2, a2); - return (Pixel1 == Pixel2); -} - -static int -GLES2_RenderClear(SDL_Renderer * renderer) -{ - Uint8 r, g, b, a; - - GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; - - GLES2_ActivateRenderer(renderer); - - if (!CompareColors(data->clear_r, data->clear_g, data->clear_b, data->clear_a, - renderer->r, renderer->g, renderer->b, renderer->a)) { - - /* Select the color to clear with */ - g = renderer->g; - a = renderer->a; - - if (renderer->target && - (renderer->target->format == SDL_PIXELFORMAT_ARGB8888 || - renderer->target->format == SDL_PIXELFORMAT_RGB888)) { - r = renderer->b; - b = renderer->r; - } else { - r = renderer->r; - b = renderer->b; - } - - data->glClearColor((GLfloat) r * inv255f, - (GLfloat) g * inv255f, - (GLfloat) b * inv255f, - (GLfloat) a * inv255f); - data->clear_r = renderer->r; - data->clear_g = renderer->g; - data->clear_b = renderer->b; - data->clear_a = renderer->a; - } - - if (renderer->clipping_enabled) { - data->glDisable(GL_SCISSOR_TEST); - } - - data->glClear(GL_COLOR_BUFFER_BIT); - - if (renderer->clipping_enabled) { - data->glEnable(GL_SCISSOR_TEST); - } - - return 0; -} - -static void -GLES2_SetBlendMode(GLES2_DriverContext *data, int blendMode) -{ - if (blendMode != data->current.blendMode) { - switch (blendMode) { - default: - case SDL_BLENDMODE_NONE: - data->glDisable(GL_BLEND); - break; - case SDL_BLENDMODE_BLEND: - data->glEnable(GL_BLEND); - data->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - break; - case SDL_BLENDMODE_ADD: - data->glEnable(GL_BLEND); - data->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ZERO, GL_ONE); - break; - case SDL_BLENDMODE_MOD: - data->glEnable(GL_BLEND); - data->glBlendFuncSeparate(GL_ZERO, GL_SRC_COLOR, GL_ZERO, GL_ONE); - break; - } - data->current.blendMode = blendMode; - } -} - -static void -GLES2_SetTexCoords(GLES2_DriverContext * data, SDL_bool enabled) -{ - if (enabled != data->current.tex_coords) { - if (enabled) { - data->glEnableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD); - } else { - data->glDisableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD); - } - data->current.tex_coords = enabled; - } -} - -static int -GLES2_SetDrawingState(SDL_Renderer * renderer) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; - const int blendMode = renderer->blendMode; - GLES2_ProgramCacheEntry *program; - Uint8 r, g, b, a; - - GLES2_ActivateRenderer(renderer); - - GLES2_SetBlendMode(data, blendMode); - - GLES2_SetTexCoords(data, SDL_FALSE); - - /* Activate an appropriate shader and set the projection matrix */ - if (GLES2_SelectProgram(renderer, GLES2_IMAGESOURCE_SOLID, blendMode) < 0) { - return -1; - } - - /* Select the color to draw with */ - g = renderer->g; - a = renderer->a; - - if (renderer->target && - (renderer->target->format == SDL_PIXELFORMAT_ARGB8888 || - renderer->target->format == SDL_PIXELFORMAT_RGB888)) { - r = renderer->b; - b = renderer->r; - } else { - r = renderer->r; - b = renderer->b; - } - - program = data->current_program; - if (!CompareColors(program->color_r, program->color_g, program->color_b, program->color_a, r, g, b, a)) { - /* Select the color to draw with */ - data->glUniform4f(program->uniform_locations[GLES2_UNIFORM_COLOR], r * inv255f, g * inv255f, b * inv255f, a * inv255f); - program->color_r = r; - program->color_g = g; - program->color_b = b; - program->color_a = a; - } - - return 0; -} - -static int -GLES2_UpdateVertexBuffer(SDL_Renderer *renderer, GLES2_Attribute attr, - const void *vertexData, size_t dataSizeInBytes) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; - -#if !SDL_GLES2_USE_VBOS - data->glVertexAttribPointer(attr, attr == GLES2_ATTRIBUTE_ANGLE ? 1 : 2, GL_FLOAT, GL_FALSE, 0, vertexData); -#else - if (!data->vertex_buffers[attr]) { - data->glGenBuffers(1, &data->vertex_buffers[attr]); - } - - data->glBindBuffer(GL_ARRAY_BUFFER, data->vertex_buffers[attr]); - - if (data->vertex_buffer_size[attr] < dataSizeInBytes) { - data->glBufferData(GL_ARRAY_BUFFER, dataSizeInBytes, vertexData, GL_STREAM_DRAW); - data->vertex_buffer_size[attr] = dataSizeInBytes; - } else { - data->glBufferSubData(GL_ARRAY_BUFFER, 0, dataSizeInBytes, vertexData); - } - - data->glVertexAttribPointer(attr, attr == GLES2_ATTRIBUTE_ANGLE ? 1 : 2, GL_FLOAT, GL_FALSE, 0, 0); -#endif - - return 0; -} - -static int -GLES2_RenderDrawPoints(SDL_Renderer *renderer, const SDL_FPoint *points, int count) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; - GLfloat *vertices; - int idx; - - if (GLES2_SetDrawingState(renderer) < 0) { - return -1; - } - - /* Emit the specified vertices as points */ - vertices = SDL_stack_alloc(GLfloat, count * 2); - for (idx = 0; idx < count; ++idx) { - GLfloat x = points[idx].x + 0.5f; - GLfloat y = points[idx].y + 0.5f; - - vertices[idx * 2] = x; - vertices[(idx * 2) + 1] = y; - } - /*data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);*/ - GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_POSITION, vertices, count * 2 * sizeof(GLfloat)); - data->glDrawArrays(GL_POINTS, 0, count); - SDL_stack_free(vertices); - return 0; -} - -static int -GLES2_RenderDrawLines(SDL_Renderer *renderer, const SDL_FPoint *points, int count) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; - GLfloat *vertices; - int idx; - - if (GLES2_SetDrawingState(renderer) < 0) { - return -1; - } - - /* Emit a line strip including the specified vertices */ - vertices = SDL_stack_alloc(GLfloat, count * 2); - for (idx = 0; idx < count; ++idx) { - GLfloat x = points[idx].x + 0.5f; - GLfloat y = points[idx].y + 0.5f; - - vertices[idx * 2] = x; - vertices[(idx * 2) + 1] = y; - } - /*data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);*/ - GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_POSITION, vertices, count * 2 * sizeof(GLfloat)); - data->glDrawArrays(GL_LINE_STRIP, 0, count); - - /* We need to close the endpoint of the line */ - if (count == 2 || - points[0].x != points[count-1].x || points[0].y != points[count-1].y) { - data->glDrawArrays(GL_POINTS, count-1, 1); - } - SDL_stack_free(vertices); - - return GL_CheckError("", renderer); -} - -static int -GLES2_RenderFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; - GLfloat vertices[8]; - int idx; - - if (GLES2_SetDrawingState(renderer) < 0) { - return -1; - } - - /* Emit a line loop for each rectangle */ - for (idx = 0; idx < count; ++idx) { - const SDL_FRect *rect = &rects[idx]; - - GLfloat xMin = rect->x; - GLfloat xMax = (rect->x + rect->w); - GLfloat yMin = rect->y; - GLfloat yMax = (rect->y + rect->h); - - vertices[0] = xMin; - vertices[1] = yMin; - vertices[2] = xMax; - vertices[3] = yMin; - vertices[4] = xMin; - vertices[5] = yMax; - vertices[6] = xMax; - vertices[7] = yMax; - /*data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);*/ - GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_POSITION, vertices, 8 * sizeof(GLfloat)); - data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - } - return GL_CheckError("", renderer); -} - -static int -GLES2_SetupCopy(SDL_Renderer *renderer, SDL_Texture *texture) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; - GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata; - GLES2_ImageSource sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR; - SDL_BlendMode blendMode; - GLES2_ProgramCacheEntry *program; - Uint8 r, g, b, a; - - /* Activate an appropriate shader and set the projection matrix */ - blendMode = texture->blendMode; - if (renderer->target) { - /* Check if we need to do color mapping between the source and render target textures */ - if (renderer->target->format != texture->format) { - switch (texture->format) { - case SDL_PIXELFORMAT_ARGB8888: - switch (renderer->target->format) { - case SDL_PIXELFORMAT_ABGR8888: - case SDL_PIXELFORMAT_BGR888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB; - break; - case SDL_PIXELFORMAT_RGB888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR; - break; - } - break; - case SDL_PIXELFORMAT_ABGR8888: - switch (renderer->target->format) { - case SDL_PIXELFORMAT_ARGB8888: - case SDL_PIXELFORMAT_RGB888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB; - break; - case SDL_PIXELFORMAT_BGR888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR; - break; - } - break; - case SDL_PIXELFORMAT_RGB888: - switch (renderer->target->format) { - case SDL_PIXELFORMAT_ABGR8888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB; - break; - case SDL_PIXELFORMAT_ARGB8888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_BGR; - break; - case SDL_PIXELFORMAT_BGR888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB; - break; - } - break; - case SDL_PIXELFORMAT_BGR888: - switch (renderer->target->format) { - case SDL_PIXELFORMAT_ABGR8888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_BGR; - break; - case SDL_PIXELFORMAT_ARGB8888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_RGB; - break; - case SDL_PIXELFORMAT_RGB888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB; - break; - } - break; - case SDL_PIXELFORMAT_IYUV: - case SDL_PIXELFORMAT_YV12: - sourceType = GLES2_IMAGESOURCE_TEXTURE_YUV; - break; - case SDL_PIXELFORMAT_NV12: - sourceType = GLES2_IMAGESOURCE_TEXTURE_NV12; - break; - case SDL_PIXELFORMAT_NV21: - sourceType = GLES2_IMAGESOURCE_TEXTURE_NV21; - break; - default: - return SDL_SetError("Unsupported texture format"); - } - } else { - sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR; /* Texture formats match, use the non color mapping shader (even if the formats are not ABGR) */ - } - } else { - switch (texture->format) { - case SDL_PIXELFORMAT_ARGB8888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB; - break; - case SDL_PIXELFORMAT_ABGR8888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR; - break; - case SDL_PIXELFORMAT_RGB888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_RGB; - break; - case SDL_PIXELFORMAT_BGR888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_BGR; - break; - case SDL_PIXELFORMAT_IYUV: - case SDL_PIXELFORMAT_YV12: - sourceType = GLES2_IMAGESOURCE_TEXTURE_YUV; - break; - case SDL_PIXELFORMAT_NV12: - sourceType = GLES2_IMAGESOURCE_TEXTURE_NV12; - break; - case SDL_PIXELFORMAT_NV21: - sourceType = GLES2_IMAGESOURCE_TEXTURE_NV21; - break; - default: - return SDL_SetError("Unsupported texture format"); - } - } - - if (GLES2_SelectProgram(renderer, sourceType, blendMode) < 0) { - return -1; - } - - /* Select the target texture */ - if (tdata->yuv) { - data->glActiveTexture(GL_TEXTURE2); - data->glBindTexture(tdata->texture_type, tdata->texture_v); - - data->glActiveTexture(GL_TEXTURE1); - data->glBindTexture(tdata->texture_type, tdata->texture_u); - - data->glActiveTexture(GL_TEXTURE0); - } - if (tdata->nv12) { - data->glActiveTexture(GL_TEXTURE1); - data->glBindTexture(tdata->texture_type, tdata->texture_u); - - data->glActiveTexture(GL_TEXTURE0); - } - data->glBindTexture(tdata->texture_type, tdata->texture); - - /* Configure color modulation */ - g = texture->g; - a = texture->a; - - if (renderer->target && - (renderer->target->format == SDL_PIXELFORMAT_ARGB8888 || - renderer->target->format == SDL_PIXELFORMAT_RGB888)) { - r = texture->b; - b = texture->r; - } else { - r = texture->r; - b = texture->b; - } - - program = data->current_program; - - if (!CompareColors(program->modulation_r, program->modulation_g, program->modulation_b, program->modulation_a, r, g, b, a)) { - data->glUniform4f(program->uniform_locations[GLES2_UNIFORM_MODULATION], r * inv255f, g * inv255f, b * inv255f, a * inv255f); - program->modulation_r = r; - program->modulation_g = g; - program->modulation_b = b; - program->modulation_a = a; - } - - /* Configure texture blending */ - GLES2_SetBlendMode(data, blendMode); - - GLES2_SetTexCoords(data, SDL_TRUE); - return 0; -} - -static int -GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, - const SDL_FRect *dstrect) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; - GLfloat vertices[8]; - GLfloat texCoords[8]; - - GLES2_ActivateRenderer(renderer); - - if (GLES2_SetupCopy(renderer, texture) < 0) { - return -1; - } - - /* Emit the textured quad */ - vertices[0] = dstrect->x; - vertices[1] = dstrect->y; - vertices[2] = (dstrect->x + dstrect->w); - vertices[3] = dstrect->y; - vertices[4] = dstrect->x; - vertices[5] = (dstrect->y + dstrect->h); - vertices[6] = (dstrect->x + dstrect->w); - vertices[7] = (dstrect->y + dstrect->h); - /*data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);*/ - GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_POSITION, vertices, 8 * sizeof(GLfloat)); - texCoords[0] = srcrect->x / (GLfloat)texture->w; - texCoords[1] = srcrect->y / (GLfloat)texture->h; - texCoords[2] = (srcrect->x + srcrect->w) / (GLfloat)texture->w; - texCoords[3] = srcrect->y / (GLfloat)texture->h; - texCoords[4] = srcrect->x / (GLfloat)texture->w; - texCoords[5] = (srcrect->y + srcrect->h) / (GLfloat)texture->h; - texCoords[6] = (srcrect->x + srcrect->w) / (GLfloat)texture->w; - texCoords[7] = (srcrect->y + srcrect->h) / (GLfloat)texture->h; - /*data->glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, texCoords);*/ - GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_TEXCOORD, texCoords, 8 * sizeof(GLfloat)); - data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - - return GL_CheckError("", renderer); -} - -static int -GLES2_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, - const SDL_FRect *dstrect, const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; - GLfloat vertices[8]; - GLfloat texCoords[8]; - GLfloat translate[8]; - GLfloat fAngle[4]; - GLfloat tmp; - - GLES2_ActivateRenderer(renderer); - - if (GLES2_SetupCopy(renderer, texture) < 0) { - return -1; - } - - data->glEnableVertexAttribArray(GLES2_ATTRIBUTE_CENTER); - data->glEnableVertexAttribArray(GLES2_ATTRIBUTE_ANGLE); - fAngle[0] = fAngle[1] = fAngle[2] = fAngle[3] = (GLfloat)(360.0f - angle); - /* Calculate the center of rotation */ - translate[0] = translate[2] = translate[4] = translate[6] = (center->x + dstrect->x); - translate[1] = translate[3] = translate[5] = translate[7] = (center->y + dstrect->y); - - /* Emit the textured quad */ - vertices[0] = dstrect->x; - vertices[1] = dstrect->y; - vertices[2] = (dstrect->x + dstrect->w); - vertices[3] = dstrect->y; - vertices[4] = dstrect->x; - vertices[5] = (dstrect->y + dstrect->h); - vertices[6] = (dstrect->x + dstrect->w); - vertices[7] = (dstrect->y + dstrect->h); - if (flip & SDL_FLIP_HORIZONTAL) { - tmp = vertices[0]; - vertices[0] = vertices[4] = vertices[2]; - vertices[2] = vertices[6] = tmp; - } - if (flip & SDL_FLIP_VERTICAL) { - tmp = vertices[1]; - vertices[1] = vertices[3] = vertices[5]; - vertices[5] = vertices[7] = tmp; - } - - /*data->glVertexAttribPointer(GLES2_ATTRIBUTE_ANGLE, 1, GL_FLOAT, GL_FALSE, 0, &fAngle); - data->glVertexAttribPointer(GLES2_ATTRIBUTE_CENTER, 2, GL_FLOAT, GL_FALSE, 0, translate); - data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);*/ - - GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_ANGLE, fAngle, 4 * sizeof(GLfloat)); - GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_CENTER, translate, 8 * sizeof(GLfloat)); - GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_POSITION, vertices, 8 * sizeof(GLfloat)); - - texCoords[0] = srcrect->x / (GLfloat)texture->w; - texCoords[1] = srcrect->y / (GLfloat)texture->h; - texCoords[2] = (srcrect->x + srcrect->w) / (GLfloat)texture->w; - texCoords[3] = srcrect->y / (GLfloat)texture->h; - texCoords[4] = srcrect->x / (GLfloat)texture->w; - texCoords[5] = (srcrect->y + srcrect->h) / (GLfloat)texture->h; - texCoords[6] = (srcrect->x + srcrect->w) / (GLfloat)texture->w; - texCoords[7] = (srcrect->y + srcrect->h) / (GLfloat)texture->h; - /*data->glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, texCoords);*/ - GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_TEXCOORD, texCoords, 8 * sizeof(GLfloat)); - data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - data->glDisableVertexAttribArray(GLES2_ATTRIBUTE_CENTER); - data->glDisableVertexAttribArray(GLES2_ATTRIBUTE_ANGLE); - - return GL_CheckError("", renderer); -} - -static int -GLES2_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, - Uint32 pixel_format, void * pixels, int pitch) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; - Uint32 temp_format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_ABGR8888; - void *temp_pixels; - int temp_pitch; - Uint8 *src, *dst, *tmp; - int w, h, length, rows; - int status; - - GLES2_ActivateRenderer(renderer); - - temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format); - temp_pixels = SDL_malloc(rect->h * temp_pitch); - if (!temp_pixels) { - return SDL_OutOfMemory(); - } - - SDL_GetRendererOutputSize(renderer, &w, &h); - - data->glReadPixels(rect->x, renderer->target ? rect->y : (h-rect->y)-rect->h, - rect->w, rect->h, GL_RGBA, GL_UNSIGNED_BYTE, temp_pixels); - if (GL_CheckError("glReadPixels()", renderer) < 0) { - return -1; - } - - /* Flip the rows to be top-down if necessary */ - if (!renderer->target) { - length = rect->w * SDL_BYTESPERPIXEL(temp_format); - src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch; - dst = (Uint8*)temp_pixels; - tmp = SDL_stack_alloc(Uint8, length); - rows = rect->h / 2; - while (rows--) { - SDL_memcpy(tmp, dst, length); - SDL_memcpy(dst, src, length); - SDL_memcpy(src, tmp, length); - dst += temp_pitch; - src -= temp_pitch; - } - SDL_stack_free(tmp); - } - - status = SDL_ConvertPixels(rect->w, rect->h, - temp_format, temp_pixels, temp_pitch, - pixel_format, pixels, pitch); - SDL_free(temp_pixels); - - return status; -} - -static void -GLES2_RenderPresent(SDL_Renderer *renderer) -{ - GLES2_ActivateRenderer(renderer); - - /* Tell the video driver to swap buffers */ - SDL_GL_SwapWindow(renderer->window); -} - - -/************************************************************************************************* - * Bind/unbinding of textures - *************************************************************************************************/ -static int GLES2_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh); -static int GLES2_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture); - -static int GLES2_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; - GLES2_TextureData *texturedata = (GLES2_TextureData *)texture->driverdata; - GLES2_ActivateRenderer(renderer); - - data->glBindTexture(texturedata->texture_type, texturedata->texture); - - if (texw) { - *texw = 1.0; - } - if (texh) { - *texh = 1.0; - } - - return 0; -} - -static int GLES2_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; - GLES2_TextureData *texturedata = (GLES2_TextureData *)texture->driverdata; - GLES2_ActivateRenderer(renderer); - - data->glBindTexture(texturedata->texture_type, 0); - - return 0; -} - - -/************************************************************************************************* - * Renderer instantiation * - *************************************************************************************************/ - -#define GL_NVIDIA_PLATFORM_BINARY_NV 0x890B - -static void -GLES2_ResetState(SDL_Renderer *renderer) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *) renderer->driverdata; - - if (SDL_CurrentContext == data->context) { - GLES2_UpdateViewport(renderer); - } else { - GLES2_ActivateRenderer(renderer); - } - - data->current.blendMode = -1; - data->current.tex_coords = SDL_FALSE; - - data->glActiveTexture(GL_TEXTURE0); - data->glPixelStorei(GL_PACK_ALIGNMENT, 1); - data->glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - - data->glClearColor((GLfloat) data->clear_r * inv255f, - (GLfloat) data->clear_g * inv255f, - (GLfloat) data->clear_b * inv255f, - (GLfloat) data->clear_a * inv255f); - - data->glEnableVertexAttribArray(GLES2_ATTRIBUTE_POSITION); - data->glDisableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD); - - GL_CheckError("", renderer); -} - -static SDL_Renderer * -GLES2_CreateRenderer(SDL_Window *window, Uint32 flags) -{ - SDL_Renderer *renderer; - GLES2_DriverContext *data; - GLint nFormats; -#ifndef ZUNE_HD - GLboolean hasCompiler; -#endif - Uint32 window_flags; - GLint window_framebuffer; - GLint value; - int profile_mask = 0, major = 0, minor = 0; - SDL_bool changed_window = SDL_FALSE; - - if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profile_mask) < 0) { - goto error; - } - if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major) < 0) { - goto error; - } - if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor) < 0) { - goto error; - } - - window_flags = SDL_GetWindowFlags(window); - if (!(window_flags & SDL_WINDOW_OPENGL) || - profile_mask != SDL_GL_CONTEXT_PROFILE_ES || major != RENDERER_CONTEXT_MAJOR || minor != RENDERER_CONTEXT_MINOR) { - - changed_window = SDL_TRUE; - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR); - - if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 0) { - goto error; - } - } - - /* Create the renderer struct */ - renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(SDL_Renderer)); - if (!renderer) { - SDL_OutOfMemory(); - goto error; - } - - data = (GLES2_DriverContext *)SDL_calloc(1, sizeof(GLES2_DriverContext)); - if (!data) { - GLES2_DestroyRenderer(renderer); - SDL_OutOfMemory(); - goto error; - } - renderer->info = GLES2_RenderDriver.info; - renderer->info.flags = (SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE); - renderer->driverdata = data; - renderer->window = window; - - /* Create an OpenGL ES 2.0 context */ - data->context = SDL_GL_CreateContext(window); - if (!data->context) { - GLES2_DestroyRenderer(renderer); - goto error; - } - if (SDL_GL_MakeCurrent(window, data->context) < 0) { - GLES2_DestroyRenderer(renderer); - goto error; - } - - if (GLES2_LoadFunctions(data) < 0) { - GLES2_DestroyRenderer(renderer); - goto error; - } - -#if __WINRT__ - /* DLudwig, 2013-11-29: ANGLE for WinRT doesn't seem to work unless VSync - * is turned on. Not doing so will freeze the screen's contents to that - * of the first drawn frame. - */ - flags |= SDL_RENDERER_PRESENTVSYNC; -#endif - - if (flags & SDL_RENDERER_PRESENTVSYNC) { - SDL_GL_SetSwapInterval(1); - } else { - SDL_GL_SetSwapInterval(0); - } - if (SDL_GL_GetSwapInterval() > 0) { - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; - } - - /* Check for debug output support */ - if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_FLAGS, &value) == 0 && - (value & SDL_GL_CONTEXT_DEBUG_FLAG)) { - data->debug_enabled = SDL_TRUE; - } - - value = 0; - data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value); - renderer->info.max_texture_width = value; - value = 0; - data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value); - renderer->info.max_texture_height = value; - - /* Determine supported shader formats */ - /* HACK: glGetInteger is broken on the Zune HD's compositor, so we just hardcode this */ -#ifdef ZUNE_HD - nFormats = 1; -#else /* !ZUNE_HD */ - data->glGetIntegerv(GL_NUM_SHADER_BINARY_FORMATS, &nFormats); - data->glGetBooleanv(GL_SHADER_COMPILER, &hasCompiler); - if (hasCompiler) { - ++nFormats; - } -#endif /* ZUNE_HD */ - data->shader_formats = (GLenum *)SDL_calloc(nFormats, sizeof(GLenum)); - if (!data->shader_formats) { - GLES2_DestroyRenderer(renderer); - SDL_OutOfMemory(); - goto error; - } - data->shader_format_count = nFormats; -#ifdef ZUNE_HD - data->shader_formats[0] = GL_NVIDIA_PLATFORM_BINARY_NV; -#else /* !ZUNE_HD */ - data->glGetIntegerv(GL_SHADER_BINARY_FORMATS, (GLint *)data->shader_formats); - if (hasCompiler) { - data->shader_formats[nFormats - 1] = (GLenum)-1; - } -#endif /* ZUNE_HD */ - - data->framebuffers = NULL; - data->glGetIntegerv(GL_FRAMEBUFFER_BINDING, &window_framebuffer); - data->window_framebuffer = (GLuint)window_framebuffer; - - /* Populate the function pointers for the module */ - renderer->WindowEvent = &GLES2_WindowEvent; - renderer->GetOutputSize = &GLES2_GetOutputSize; - renderer->CreateTexture = &GLES2_CreateTexture; - renderer->UpdateTexture = &GLES2_UpdateTexture; - renderer->UpdateTextureYUV = &GLES2_UpdateTextureYUV; - renderer->LockTexture = &GLES2_LockTexture; - renderer->UnlockTexture = &GLES2_UnlockTexture; - renderer->SetRenderTarget = &GLES2_SetRenderTarget; - renderer->UpdateViewport = &GLES2_UpdateViewport; - renderer->UpdateClipRect = &GLES2_UpdateClipRect; - renderer->RenderClear = &GLES2_RenderClear; - renderer->RenderDrawPoints = &GLES2_RenderDrawPoints; - renderer->RenderDrawLines = &GLES2_RenderDrawLines; - renderer->RenderFillRects = &GLES2_RenderFillRects; - renderer->RenderCopy = &GLES2_RenderCopy; - renderer->RenderCopyEx = &GLES2_RenderCopyEx; - renderer->RenderReadPixels = &GLES2_RenderReadPixels; - renderer->RenderPresent = &GLES2_RenderPresent; - renderer->DestroyTexture = &GLES2_DestroyTexture; - renderer->DestroyRenderer = &GLES2_DestroyRenderer; - renderer->GL_BindTexture = &GLES2_BindTexture; - renderer->GL_UnbindTexture = &GLES2_UnbindTexture; - - renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_YV12; - renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_IYUV; - renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_NV12; - renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_NV21; - - GLES2_ResetState(renderer); - - return renderer; - -error: - if (changed_window) { - /* Uh oh, better try to put it back... */ - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile_mask); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, major); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minor); - SDL_RecreateWindow(window, window_flags); - } - return NULL; -} - -#endif /* SDL_VIDEO_RENDER_OGL_ES2 && !SDL_RENDER_DISABLED */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/opengles2/SDL_shaders_gles2.c b/3rdparty/SDL2/src/render/opengles2/SDL_shaders_gles2.c deleted file mode 100644 index 0c01a8c64ed..00000000000 --- a/3rdparty/SDL2/src/render/opengles2/SDL_shaders_gles2.c +++ /dev/null @@ -1,906 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../../SDL_internal.h" - -#if SDL_VIDEO_RENDER_OGL_ES2 && !SDL_RENDER_DISABLED - -#include "SDL_video.h" -#include "SDL_opengles2.h" -#include "SDL_shaders_gles2.h" -#include "SDL_stdinc.h" - -/************************************************************************************************* - * Vertex/fragment shader source * - *************************************************************************************************/ - -static const Uint8 GLES2_VertexSrc_Default_[] = " \ - uniform mat4 u_projection; \ - attribute vec2 a_position; \ - attribute vec2 a_texCoord; \ - attribute float a_angle; \ - attribute vec2 a_center; \ - varying vec2 v_texCoord; \ - \ - void main() \ - { \ - float angle = radians(a_angle); \ - float c = cos(angle); \ - float s = sin(angle); \ - mat2 rotationMatrix = mat2(c, -s, s, c); \ - vec2 position = rotationMatrix * (a_position - a_center) + a_center; \ - v_texCoord = a_texCoord; \ - gl_Position = u_projection * vec4(position, 0.0, 1.0);\ - gl_PointSize = 1.0; \ - } \ -"; - -static const Uint8 GLES2_FragmentSrc_SolidSrc_[] = " \ - precision mediump float; \ - uniform vec4 u_color; \ - \ - void main() \ - { \ - gl_FragColor = u_color; \ - } \ -"; - -static const Uint8 GLES2_FragmentSrc_TextureABGRSrc_[] = " \ - precision mediump float; \ - uniform sampler2D u_texture; \ - uniform vec4 u_modulation; \ - varying vec2 v_texCoord; \ - \ - void main() \ - { \ - gl_FragColor = texture2D(u_texture, v_texCoord); \ - gl_FragColor *= u_modulation; \ - } \ -"; - -/* ARGB to ABGR conversion */ -static const Uint8 GLES2_FragmentSrc_TextureARGBSrc_[] = " \ - precision mediump float; \ - uniform sampler2D u_texture; \ - uniform vec4 u_modulation; \ - varying vec2 v_texCoord; \ - \ - void main() \ - { \ - vec4 abgr = texture2D(u_texture, v_texCoord); \ - gl_FragColor = abgr; \ - gl_FragColor.r = abgr.b; \ - gl_FragColor.b = abgr.r; \ - gl_FragColor *= u_modulation; \ - } \ -"; - -/* RGB to ABGR conversion */ -static const Uint8 GLES2_FragmentSrc_TextureRGBSrc_[] = " \ - precision mediump float; \ - uniform sampler2D u_texture; \ - uniform vec4 u_modulation; \ - varying vec2 v_texCoord; \ - \ - void main() \ - { \ - vec4 abgr = texture2D(u_texture, v_texCoord); \ - gl_FragColor = abgr; \ - gl_FragColor.r = abgr.b; \ - gl_FragColor.b = abgr.r; \ - gl_FragColor.a = 1.0; \ - gl_FragColor *= u_modulation; \ - } \ -"; - -/* BGR to ABGR conversion */ -static const Uint8 GLES2_FragmentSrc_TextureBGRSrc_[] = " \ - precision mediump float; \ - uniform sampler2D u_texture; \ - uniform vec4 u_modulation; \ - varying vec2 v_texCoord; \ - \ - void main() \ - { \ - vec4 abgr = texture2D(u_texture, v_texCoord); \ - gl_FragColor = abgr; \ - gl_FragColor.a = 1.0; \ - gl_FragColor *= u_modulation; \ - } \ -"; - -/* YUV to ABGR conversion */ -static const Uint8 GLES2_FragmentSrc_TextureYUVSrc_[] = " \ - precision mediump float; \ - uniform sampler2D u_texture; \ - uniform sampler2D u_texture_u; \ - uniform sampler2D u_texture_v; \ - uniform vec4 u_modulation; \ - varying vec2 v_texCoord; \ - \ - void main() \ - { \ - mediump vec3 yuv; \ - lowp vec3 rgb; \ - yuv.x = texture2D(u_texture, v_texCoord).r; \ - yuv.y = texture2D(u_texture_u, v_texCoord).r - 0.5; \ - yuv.z = texture2D(u_texture_v, v_texCoord).r - 0.5; \ - rgb = mat3( 1, 1, 1, \ - 0, -0.39465, 2.03211, \ - 1.13983, -0.58060, 0) * yuv; \ - gl_FragColor = vec4(rgb, 1); \ - gl_FragColor *= u_modulation; \ - } \ -"; - -/* NV12 to ABGR conversion */ -static const Uint8 GLES2_FragmentSrc_TextureNV12Src_[] = " \ - precision mediump float; \ - uniform sampler2D u_texture; \ - uniform sampler2D u_texture_u; \ - uniform vec4 u_modulation; \ - varying vec2 v_texCoord; \ - \ - void main() \ - { \ - mediump vec3 yuv; \ - lowp vec3 rgb; \ - yuv.x = texture2D(u_texture, v_texCoord).r; \ - yuv.yz = texture2D(u_texture_u, v_texCoord).ra - 0.5; \ - rgb = mat3( 1, 1, 1, \ - 0, -0.39465, 2.03211, \ - 1.13983, -0.58060, 0) * yuv; \ - gl_FragColor = vec4(rgb, 1); \ - gl_FragColor *= u_modulation; \ - } \ -"; - -/* NV21 to ABGR conversion */ -static const Uint8 GLES2_FragmentSrc_TextureNV21Src_[] = " \ - precision mediump float; \ - uniform sampler2D u_texture; \ - uniform sampler2D u_texture_u; \ - uniform vec4 u_modulation; \ - varying vec2 v_texCoord; \ - \ - void main() \ - { \ - mediump vec3 yuv; \ - lowp vec3 rgb; \ - yuv.x = texture2D(u_texture, v_texCoord).r; \ - yuv.yz = texture2D(u_texture_u, v_texCoord).ar - 0.5; \ - rgb = mat3( 1, 1, 1, \ - 0, -0.39465, 2.03211, \ - 1.13983, -0.58060, 0) * yuv; \ - gl_FragColor = vec4(rgb, 1); \ - gl_FragColor *= u_modulation; \ - } \ -"; - -static const GLES2_ShaderInstance GLES2_VertexSrc_Default = { - GL_VERTEX_SHADER, - GLES2_SOURCE_SHADER, - sizeof(GLES2_VertexSrc_Default_), - GLES2_VertexSrc_Default_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentSrc_SolidSrc = { - GL_FRAGMENT_SHADER, - GLES2_SOURCE_SHADER, - sizeof(GLES2_FragmentSrc_SolidSrc_), - GLES2_FragmentSrc_SolidSrc_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureABGRSrc = { - GL_FRAGMENT_SHADER, - GLES2_SOURCE_SHADER, - sizeof(GLES2_FragmentSrc_TextureABGRSrc_), - GLES2_FragmentSrc_TextureABGRSrc_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureARGBSrc = { - GL_FRAGMENT_SHADER, - GLES2_SOURCE_SHADER, - sizeof(GLES2_FragmentSrc_TextureARGBSrc_), - GLES2_FragmentSrc_TextureARGBSrc_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureRGBSrc = { - GL_FRAGMENT_SHADER, - GLES2_SOURCE_SHADER, - sizeof(GLES2_FragmentSrc_TextureRGBSrc_), - GLES2_FragmentSrc_TextureRGBSrc_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureBGRSrc = { - GL_FRAGMENT_SHADER, - GLES2_SOURCE_SHADER, - sizeof(GLES2_FragmentSrc_TextureBGRSrc_), - GLES2_FragmentSrc_TextureBGRSrc_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureYUVSrc = { - GL_FRAGMENT_SHADER, - GLES2_SOURCE_SHADER, - sizeof(GLES2_FragmentSrc_TextureYUVSrc_), - GLES2_FragmentSrc_TextureYUVSrc_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureNV12Src = { - GL_FRAGMENT_SHADER, - GLES2_SOURCE_SHADER, - sizeof(GLES2_FragmentSrc_TextureNV12Src_), - GLES2_FragmentSrc_TextureNV12Src_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureNV21Src = { - GL_FRAGMENT_SHADER, - GLES2_SOURCE_SHADER, - sizeof(GLES2_FragmentSrc_TextureNV21Src_), - GLES2_FragmentSrc_TextureNV21Src_ -}; - - -/************************************************************************************************* - * Vertex/fragment shader binaries (NVIDIA Tegra 1/2) * - *************************************************************************************************/ - -#if GLES2_INCLUDE_NVIDIA_SHADERS - -#define GL_NVIDIA_PLATFORM_BINARY_NV 0x890B - -static const Uint8 GLES2_VertexTegra_Default_[] = { - 243, 193, 1, 142, 31, 109, 131, 38, 6, 0, 1, 0, 5, 0, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 73, 0, - 0, 0, 46, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 85, 0, 0, 0, 2, 0, 0, 0, 24, 0, 0, 0, 3, 0, 0, 0, - 91, 0, 0, 0, 1, 0, 0, 0, 16, 0, 0, 0, 5, 0, 0, 0, 95, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 95, 0, 0, 0, 1, 0, 0, 0, 28, 0, 0, 0, - 13, 0, 0, 0, 102, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 16, 0, 0, 0, 104, 0, 0, 0, 1, 0, 0, 0, 32, 0, 0, 0, 17, 0, 0, 0, 112, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 112, 0, 0, 0, 80, 0, 0, 0, 80, 0, 0, 0, 19, 0, 0, 0, 132, 0, - 0, 0, 104, 0, 0, 0, 104, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 97, 110, 70, 73, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 97, - 95, 112, 111, 115, 105, 116, 105, 111, 110, 0, 97, 95, 116, 101, 120, 67, 111, 111, 114, 100, - 0, 118, 95, 116, 101, 120, 67, 111, 111, 114, 100, 0, 117, 95, 112, 114, 111, 106, 101, 99, - 116, 105, 111, 110, 0, 0, 0, 0, 0, 0, 0, 82, 139, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 80, 139, 0, - 0, 1, 0, 0, 0, 22, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 33, 0, 0, 0, 92, 139, 0, 0, - 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 240, 0, 0, 0, 0, 0, 0, 1, 0, - 0, 0, 64, 0, 0, 0, 80, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 193, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 128, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 66, 24, 0, 6, 34, 108, 28, - 0, 0, 42, 16, 128, 0, 195, 192, 6, 129, 252, 255, 65, 96, 108, 28, 0, 0, 0, 0, 0, 1, 195, 192, - 6, 1, 252, 255, 33, 96, 108, 156, 31, 64, 8, 1, 64, 0, 131, 192, 6, 1, 156, 159, 65, 96, 108, - 28, 0, 0, 85, 32, 0, 1, 195, 192, 6, 1, 252, 255, 33, 96, 108, 156, 31, 64, 0, 64, 64, 0, 131, - 192, 134, 1, 152, 31, 65, 96, 108, 156, 31, 64, 127, 48, 0, 1, 195, 192, 6, 129, 129, 255, 33, - 96 -}; - -static const Uint8 GLES2_FragmentTegra_None_SolidSrc_[] = { - 155, 191, 159, 1, 47, 109, 131, 38, 6, 0, 1, 0, 5, 0, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 73, 0, - 0, 0, 8, 0, 0, 0, 8, 0, 0, 0, 2, 0, 0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 75, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, - 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 75, 0, 0, 0, 1, 0, 0, 0, 28, 0, 0, 0, 13, 0, - 0, 0, 82, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 14, 0, 0, 0, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 22, 0, 0, 0, 84, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 23, 0, 0, 0, 92, 0, 0, 0, 1, 0, 0, 0, 4, - 0, 0, 0, 15, 0, 0, 0, 93, 0, 0, 0, 1, 0, 0, 0, 80, 0, 0, 0, 17, 0, 0, 0, 113, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 113, 0, 0, - 0, 108, 0, 0, 0, 108, 0, 0, 0, 20, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, 0, 0, - 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 97, 110, 70, 73, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 117, 95, 99, 111, 108, 111, 114, 0, 0, 0, 0, 0, 82, 139, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 241, 0, 0, 0, 240, 0, 0, - 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 21, 32, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 20, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 82, 50, 48, 45, 66, 73, 78, 1, - 0, 0, 0, 1, 0, 0, 0, 1, 0, 65, 37, 0, 0, 0, 0, 1, 0, 0, 21, 0, 0, 0, 0, 1, 0, 1, 38, 0, 0, 0, - 0, 1, 0, 1, 39, 0, 0, 0, 0, 1, 0, 1, 40, 1, 0, 0, 0, 8, 0, 4, 40, 0, 40, 0, 0, 0, 242, 65, 63, - 192, 200, 0, 0, 0, 242, 65, 63, 128, 168, 0, 0, 0, 242, 65, 63, 64, 72, 0, 0, 0, 242, 65, 63, - 1, 0, 6, 40, 0, 0, 0, 0, 1, 0, 1, 41, 5, 0, 2, 0 -}; - -static const Uint8 GLES2_FragmentTegra_Alpha_SolidSrc_[] = { - 169, 153, 195, 28, 47, 109, 131, 38, 6, 0, 1, 0, 5, 0, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 73, 0, - 0, 0, 8, 0, 0, 0, 8, 0, 0, 0, 2, 0, 0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 75, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, - 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 75, 0, 0, 0, 1, 0, 0, 0, 28, 0, 0, 0, 13, 0, - 0, 0, 82, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 14, 0, 0, 0, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 22, 0, 0, 0, 84, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 23, 0, 0, 0, 92, 0, 0, 0, 1, 0, 0, 0, 4, - 0, 0, 0, 15, 0, 0, 0, 93, 0, 0, 0, 1, 0, 0, 0, 80, 0, 0, 0, 17, 0, 0, 0, 113, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 113, 0, 0, - 0, 220, 0, 0, 0, 220, 0, 0, 0, 20, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, 0, 0, - 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 97, 110, 70, 73, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 117, 95, 99, 111, 108, 111, 114, 0, 0, 0, 0, 0, 82, 139, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 48, 0, 0, 0, 0, 0, 0, 118, 118, 17, 241, 0, 0, 0, 240, 0, - 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 0, 0, 0, 7, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 21, 32, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 82, 50, 48, 45, 66, 73, 78, - 1, 0, 0, 0, 3, 0, 0, 0, 3, 0, 65, 37, 8, 0, 129, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 21, 0, - 0, 0, 0, 3, 0, 1, 38, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 1, 39, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 3, 0, 1, 40, 1, 0, 0, 0, 5, 0, 0, 0, 9, 0, 0, 0, 24, 0, 4, 40, 232, 231, 15, - 0, 0, 242, 65, 62, 194, 72, 1, 0, 0, 250, 65, 63, 194, 40, 1, 0, 0, 250, 65, 63, 192, 168, 1, - 0, 0, 242, 1, 64, 192, 168, 1, 0, 0, 242, 1, 68, 168, 32, 0, 0, 0, 50, 64, 0, 192, 168, 15, - 0, 0, 242, 1, 66, 168, 64, 0, 16, 0, 242, 65, 1, 232, 231, 15, 0, 0, 242, 65, 62, 168, 160, - 0, 0, 0, 50, 64, 2, 104, 192, 0, 0, 36, 48, 66, 4, 232, 231, 15, 0, 0, 242, 65, 62, 3, 0, 6, - 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 1, 41, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 2, 0 -}; - -static const Uint8 GLES2_FragmentTegra_Additive_SolidSrc_[] = { - 59, 71, 42, 17, 47, 109, 131, 38, 6, 0, 1, 0, 5, 0, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 73, 0, 0, - 0, 8, 0, 0, 0, 8, 0, 0, 0, 2, 0, 0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 75, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, - 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 75, 0, 0, 0, 1, 0, 0, 0, 28, 0, 0, 0, 13, 0, - 0, 0, 82, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 14, 0, 0, 0, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 22, 0, 0, 0, 84, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 23, 0, 0, 0, 92, 0, 0, 0, 1, 0, 0, 0, 4, - 0, 0, 0, 15, 0, 0, 0, 93, 0, 0, 0, 1, 0, 0, 0, 80, 0, 0, 0, 17, 0, 0, 0, 113, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 113, 0, 0, - 0, 108, 0, 0, 0, 108, 0, 0, 0, 20, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, 0, 0, - 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 97, 110, 70, 73, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 117, 95, 99, 111, 108, 111, 114, 0, 0, 0, 0, 0, 82, 139, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 48, 0, 0, 0, 0, 0, 0, 22, 22, 17, 241, 0, 0, 0, 240, 0, - 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 0, 0, 0, 7, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 21, 32, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 82, 50, 48, 45, 66, 73, 78, - 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 65, 37, 8, 0, 129, 0, 1, 0, 0, 21, 0, 0, 0, 0, 1, 0, 1, 38, 0, - 0, 0, 0, 1, 0, 1, 39, 0, 0, 0, 0, 1, 0, 1, 40, 1, 0, 0, 0, 8, 0, 4, 40, 192, 200, 0, 0, 0, 26, - 0, 70, 192, 40, 0, 0, 0, 2, 0, 64, 192, 72, 0, 0, 0, 10, 0, 66, 192, 168, 0, 0, 0, 18, 0, 68, - 1, 0, 6, 40, 0, 0, 0, 0, 1, 0, 1, 41, 5, 0, 2, 0 -}; - -static const Uint8 GLES2_FragmentTegra_Modulated_SolidSrc_[] = { - 37, 191, 49, 17, 47, 109, 131, 38, 6, 0, 1, 0, 5, 0, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 73, 0, 0, - 0, 8, 0, 0, 0, 8, 0, 0, 0, 2, 0, 0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 75, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, - 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 75, 0, 0, 0, 1, 0, 0, 0, 28, 0, 0, 0, 13, 0, - 0, 0, 82, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 14, 0, 0, 0, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 22, 0, 0, 0, 84, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 23, 0, 0, 0, 92, 0, 0, 0, 1, 0, 0, 0, 4, - 0, 0, 0, 15, 0, 0, 0, 93, 0, 0, 0, 1, 0, 0, 0, 80, 0, 0, 0, 17, 0, 0, 0, 113, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 113, 0, 0, - 0, 108, 0, 0, 0, 108, 0, 0, 0, 20, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, 0, 0, - 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 97, 110, 70, 73, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 117, 95, 99, 111, 108, 111, 114, 0, 0, 0, 0, 0, 82, 139, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 48, 0, 0, 0, 0, 0, 0, 32, 32, 17, 241, 0, 0, 0, 240, 0, - 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 0, 0, 0, 7, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 21, 32, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 82, 50, 48, 45, 66, 73, 78, - 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 65, 37, 8, 0, 129, 0, 1, 0, 0, 21, 0, 0, 0, 0, 1, 0, 1, 38, 0, - 0, 0, 0, 1, 0, 1, 39, 0, 0, 0, 0, 1, 0, 1, 40, 1, 0, 0, 0, 8, 0, 4, 40, 104, 192, 0, 0, 0, 242, - 1, 70, 8, 32, 0, 0, 0, 242, 1, 64, 40, 64, 0, 0, 0, 242, 1, 66, 72, 160, 0, 0, 0, 242, 1, 68, - 1, 0, 6, 40, 0, 0, 0, 0, 1, 0, 1, 41, 5, 0, 2, 0 -}; - -static const Uint8 GLES2_FragmentTegra_None_TextureSrc_[] = { - 220, 217, 41, 211, 47, 109, 131, 38, 6, 0, 1, 0, 5, 0, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 73, 0, - 0, 0, 34, 0, 0, 0, 36, 0, 0, 0, 2, 0, 0, 0, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, - 82, 0, 0, 0, 1, 0, 0, 0, 20, 0, 0, 0, 6, 0, 0, 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, - 0, 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 87, 0, 0, 0, 2, 0, 0, 0, 56, 0, 0, 0, - 13, 0, 0, 0, 101, 0, 0, 0, 4, 0, 0, 0, 16, 0, 0, 0, 14, 0, 0, 0, 105, 0, 0, 0, 1, 0, 0, 0, 4, - 0, 0, 0, 22, 0, 0, 0, 106, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 23, 0, 0, 0, 114, 0, 0, 0, 1, 0, - 0, 0, 4, 0, 0, 0, 15, 0, 0, 0, 115, 0, 0, 0, 1, 0, 0, 0, 80, 0, 0, 0, 17, 0, 0, 0, 135, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 135, - 0, 0, 0, 120, 0, 0, 0, 120, 0, 0, 0, 20, 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, - 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 97, 110, 70, 73, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 118, 95, 116, 101, 120, 67, 111, 111, 114, 100, 0, 117, 95, 109, 111, 100, 117, 108, - 97, 116, 105, 111, 110, 0, 117, 95, 116, 101, 120, 116, 117, 114, 101, 0, 0, 0, 0, 0, 0, 0, - 2, 0, 0, 0, 0, 0, 0, 0, 220, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 82, 139, 0, 0, 1, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 94, 139, 0, 0, 1, 0, 0, 0, 1, 0, 0, - 0, 2, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 5, 48, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1, 0, 0, 0, 241, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, - 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 1, 0, - 0, 0, 1, 0, 0, 0, 21, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0, - 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 65, 82, 50, 48, 45, 66, 73, 78, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 65, 37, 0, 0, 0, 0, 1, 0, - 0, 21, 0, 0, 0, 0, 1, 0, 1, 38, 1, 0, 0, 0, 2, 0, 4, 38, 186, 81, 78, 16, 2, 1, 0, 0, 1, 0, - 1, 39, 0, 4, 0, 0, 1, 0, 1, 40, 1, 0, 0, 0, 8, 0, 4, 40, 104, 192, 0, 0, 0, 242, 1, 70, 8, 32, - 0, 0, 0, 242, 1, 64, 40, 64, 0, 0, 0, 242, 1, 66, 72, 160, 0, 0, 0, 242, 1, 68, 1, 0, 6, 40, - 0, 0, 0, 0, 1, 0, 1, 41, 5, 0, 2, 0 -}; - -static const Uint8 GLES2_FragmentTegra_Alpha_TextureSrc_[] = { - 71, 202, 114, 229, 47, 109, 131, 38, 6, 0, 1, 0, 5, 0, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 73, 0, - 0, 0, 34, 0, 0, 0, 36, 0, 0, 0, 2, 0, 0, 0, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, - 82, 0, 0, 0, 1, 0, 0, 0, 20, 0, 0, 0, 6, 0, 0, 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, - 0, 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 87, 0, 0, 0, 2, 0, 0, 0, 56, 0, 0, 0, - 13, 0, 0, 0, 101, 0, 0, 0, 4, 0, 0, 0, 16, 0, 0, 0, 14, 0, 0, 0, 105, 0, 0, 0, 1, 0, 0, 0, 4, - 0, 0, 0, 22, 0, 0, 0, 106, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 23, 0, 0, 0, 114, 0, 0, 0, 1, 0, - 0, 0, 4, 0, 0, 0, 15, 0, 0, 0, 115, 0, 0, 0, 1, 0, 0, 0, 80, 0, 0, 0, 17, 0, 0, 0, 135, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 135, - 0, 0, 0, 176, 0, 0, 0, 176, 0, 0, 0, 20, 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, - 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 97, 110, 70, 73, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 118, 95, 116, 101, 120, 67, 111, 111, 114, 100, 0, 117, 95, 109, 111, 100, 117, 108, - 97, 116, 105, 111, 110, 0, 117, 95, 116, 101, 120, 116, 117, 114, 101, 0, 0, 0, 0, 0, 0, 0, - 2, 0, 0, 0, 0, 0, 0, 0, 220, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 82, 139, 0, 0, 1, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 94, 139, 0, 0, 1, 0, 0, 0, 1, 0, 0, - 0, 2, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 5, 48, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1, 118, 118, 17, 241, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, - 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 7, 0, 0, 0, 2, 0, 0, 0, - 1, 0, 0, 0, 2, 0, 0, 0, 21, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 16, 0, 0, 0, 16, - 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 65, 82, 50, 48, 45, 66, 73, 78, 1, 0, 0, 0, 2, 0, 0, 0, 2, 0, 65, 37, 0, 0, 0, 0, - 8, 0, 129, 0, 1, 0, 0, 21, 0, 0, 0, 0, 2, 0, 1, 38, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 4, 38, 186, - 81, 78, 16, 2, 1, 0, 0, 2, 0, 1, 39, 0, 4, 0, 0, 0, 0, 0, 0, 2, 0, 1, 40, 1, 0, 0, 0, 5, 0, - 0, 0, 16, 0, 4, 40, 40, 160, 1, 0, 0, 242, 1, 66, 8, 192, 1, 0, 0, 242, 1, 64, 104, 32, 1, 0, - 0, 242, 1, 70, 72, 64, 1, 0, 0, 242, 1, 68, 154, 192, 0, 0, 37, 34, 64, 3, 8, 32, 0, 0, 5, 58, - 208, 4, 40, 64, 0, 0, 5, 50, 208, 4, 72, 160, 0, 0, 37, 42, 208, 4, 2, 0, 6, 40, 0, 0, 0, 0, - 0, 0, 0, 0, 2, 0, 1, 41, 0, 0, 0, 0, 5, 0, 2, 0 -}; - -static const Uint8 GLES2_FragmentTegra_Additive_TextureSrc_[] = { - 161, 234, 193, 234, 47, 109, 131, 38, 6, 0, 1, 0, 5, 0, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 73, 0, - 0, 0, 34, 0, 0, 0, 36, 0, 0, 0, 2, 0, 0, 0, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, - 82, 0, 0, 0, 1, 0, 0, 0, 20, 0, 0, 0, 6, 0, 0, 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, - 0, 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 87, 0, 0, 0, 2, 0, 0, 0, 56, 0, 0, 0, - 13, 0, 0, 0, 101, 0, 0, 0, 4, 0, 0, 0, 16, 0, 0, 0, 14, 0, 0, 0, 105, 0, 0, 0, 1, 0, 0, 0, 4, - 0, 0, 0, 22, 0, 0, 0, 106, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 23, 0, 0, 0, 114, 0, 0, 0, 1, 0, - 0, 0, 4, 0, 0, 0, 15, 0, 0, 0, 115, 0, 0, 0, 1, 0, 0, 0, 80, 0, 0, 0, 17, 0, 0, 0, 135, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 135, - 0, 0, 0, 176, 0, 0, 0, 176, 0, 0, 0, 20, 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, - 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 97, 110, 70, 73, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 118, 95, 116, 101, 120, 67, 111, 111, 114, 100, 0, 117, 95, 109, 111, 100, 117, 108, - 97, 116, 105, 111, 110, 0, 117, 95, 116, 101, 120, 116, 117, 114, 101, 0, 0, 0, 0, 0, 0, 0, - 2, 0, 0, 0, 0, 0, 0, 0, 220, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 82, 139, 0, 0, 1, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 94, 139, 0, 0, 1, 0, 0, 0, 1, 0, 0, - 0, 2, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 5, 48, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1, 22, 22, 17, 241, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, - 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 7, 0, 0, 0, 2, 0, 0, 0, 1, 0, - 0, 0, 2, 0, 0, 0, 21, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0, - 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 65, 82, 50, 48, 45, 66, 73, 78, 1, 0, 0, 0, 2, 0, 0, 0, 2, 0, 65, 37, 0, 0, 0, 0, 8, 0, - 129, 0, 1, 0, 0, 21, 0, 0, 0, 0, 2, 0, 1, 38, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 4, 38, 186, 81, - 78, 16, 2, 1, 0, 0, 2, 0, 1, 39, 0, 4, 0, 0, 0, 0, 0, 0, 2, 0, 1, 40, 1, 0, 0, 0, 5, 0, 0, 0, - 16, 0, 4, 40, 40, 160, 1, 0, 0, 242, 1, 66, 104, 32, 1, 0, 0, 242, 1, 70, 8, 192, 1, 0, 0, 242, - 1, 64, 72, 64, 1, 0, 0, 242, 1, 68, 136, 192, 0, 0, 0, 26, 64, 4, 136, 32, 0, 0, 0, 2, 64, 7, - 136, 64, 0, 0, 0, 10, 64, 6, 136, 160, 0, 0, 0, 18, 64, 5, 2, 0, 6, 40, 0, 0, 0, 0, 0, 0, 0, - 0, 2, 0, 1, 41, 0, 0, 0, 0, 5, 0, 2, 0 -}; - -static const Uint8 GLES2_FragmentTegra_Modulated_TextureSrc_[] = { - 75, 132, 201, 227, 47, 109, 131, 38, 6, 0, 1, 0, 5, 0, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 73, 0, - 0, 0, 34, 0, 0, 0, 36, 0, 0, 0, 2, 0, 0, 0, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, - 82, 0, 0, 0, 1, 0, 0, 0, 20, 0, 0, 0, 6, 0, 0, 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, - 0, 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 87, 0, 0, 0, 2, 0, 0, 0, 56, 0, 0, 0, - 13, 0, 0, 0, 101, 0, 0, 0, 4, 0, 0, 0, 16, 0, 0, 0, 14, 0, 0, 0, 105, 0, 0, 0, 1, 0, 0, 0, 4, - 0, 0, 0, 22, 0, 0, 0, 106, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 23, 0, 0, 0, 114, 0, 0, 0, 1, 0, - 0, 0, 4, 0, 0, 0, 15, 0, 0, 0, 115, 0, 0, 0, 1, 0, 0, 0, 80, 0, 0, 0, 17, 0, 0, 0, 135, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 135, - 0, 0, 0, 176, 0, 0, 0, 176, 0, 0, 0, 20, 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, - 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 97, 110, 70, 73, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 118, 95, 116, 101, 120, 67, 111, 111, 114, 100, 0, 117, 95, 109, 111, 100, 117, 108, - 97, 116, 105, 111, 110, 0, 117, 95, 116, 101, 120, 116, 117, 114, 101, 0, 0, 0, 0, 0, 0, 0, - 2, 0, 0, 0, 0, 0, 0, 0, 220, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 82, 139, 0, 0, 1, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 94, 139, 0, 0, 1, 0, 0, 0, 1, 0, 0, - 0, 2, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 5, 48, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1, 32, 32, 17, 241, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, - 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 7, 0, 0, 0, 2, 0, 0, 0, 1, 0, - 0, 0, 2, 0, 0, 0, 21, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0, - 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 65, 82, 50, 48, 45, 66, 73, 78, 1, 0, 0, 0, 2, 0, 0, 0, 2, 0, 65, 37, 0, 0, 0, 0, 8, 0, - 129, 0, 1, 0, 0, 21, 0, 0, 0, 0, 2, 0, 1, 38, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 4, 38, 186, 81, - 78, 16, 2, 1, 0, 0, 2, 0, 1, 39, 0, 4, 0, 0, 0, 0, 0, 0, 2, 0, 1, 40, 1, 0, 0, 0, 5, 0, 0, 0, - 16, 0, 4, 40, 40, 160, 1, 0, 0, 242, 1, 66, 8, 192, 1, 0, 0, 242, 1, 64, 104, 32, 1, 0, 0, 242, - 1, 70, 72, 64, 1, 0, 0, 242, 1, 68, 104, 192, 0, 0, 0, 242, 65, 4, 232, 32, 0, 0, 0, 242, 65, - 0, 40, 64, 0, 0, 0, 242, 65, 6, 72, 160, 0, 0, 0, 242, 65, 5, 2, 0, 6, 40, 0, 0, 0, 0, 0, 0, - 0, 0, 2, 0, 1, 41, 0, 0, 0, 0, 5, 0, 2, 0 -}; - -static const GLES2_ShaderInstance GLES2_VertexTegra_Default = { - GL_VERTEX_SHADER, - GL_NVIDIA_PLATFORM_BINARY_NV, - sizeof(GLES2_VertexTegra_Default_), - GLES2_VertexTegra_Default_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentTegra_None_SolidSrc = { - GL_FRAGMENT_SHADER, - GL_NVIDIA_PLATFORM_BINARY_NV, - sizeof(GLES2_FragmentTegra_None_SolidSrc_), - GLES2_FragmentTegra_None_SolidSrc_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentTegra_Alpha_SolidSrc = { - GL_FRAGMENT_SHADER, - GL_NVIDIA_PLATFORM_BINARY_NV, - sizeof(GLES2_FragmentTegra_Alpha_SolidSrc_), - GLES2_FragmentTegra_Alpha_SolidSrc_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentTegra_Additive_SolidSrc = { - GL_FRAGMENT_SHADER, - GL_NVIDIA_PLATFORM_BINARY_NV, - sizeof(GLES2_FragmentTegra_Additive_SolidSrc_), - GLES2_FragmentTegra_Additive_SolidSrc_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentTegra_Modulated_SolidSrc = { - GL_FRAGMENT_SHADER, - GL_NVIDIA_PLATFORM_BINARY_NV, - sizeof(GLES2_FragmentTegra_Modulated_SolidSrc_), - GLES2_FragmentTegra_Modulated_SolidSrc_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentTegra_None_TextureSrc = { - GL_FRAGMENT_SHADER, - GL_NVIDIA_PLATFORM_BINARY_NV, - sizeof(GLES2_FragmentTegra_None_TextureSrc_), - GLES2_FragmentTegra_None_TextureSrc_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentTegra_Alpha_TextureSrc = { - GL_FRAGMENT_SHADER, - GL_NVIDIA_PLATFORM_BINARY_NV, - sizeof(GLES2_FragmentTegra_Alpha_TextureSrc_), - GLES2_FragmentTegra_Alpha_TextureSrc_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentTegra_Additive_TextureSrc = { - GL_FRAGMENT_SHADER, - GL_NVIDIA_PLATFORM_BINARY_NV, - sizeof(GLES2_FragmentTegra_Additive_TextureSrc_), - GLES2_FragmentTegra_Additive_TextureSrc_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentTegra_Modulated_TextureSrc = { - GL_FRAGMENT_SHADER, - GL_NVIDIA_PLATFORM_BINARY_NV, - sizeof(GLES2_FragmentTegra_Modulated_TextureSrc_), - GLES2_FragmentTegra_Modulated_TextureSrc_ -}; - -#endif /* GLES2_INCLUDE_NVIDIA_SHADERS */ - -/************************************************************************************************* - * Vertex/fragment shader definitions * - *************************************************************************************************/ - -static GLES2_Shader GLES2_VertexShader_Default = { -#if GLES2_INCLUDE_NVIDIA_SHADERS - 2, -#else - 1, -#endif - { -#if GLES2_INCLUDE_NVIDIA_SHADERS - &GLES2_VertexTegra_Default, -#endif - &GLES2_VertexSrc_Default - } -}; - -static GLES2_Shader GLES2_FragmentShader_None_SolidSrc = { -#if GLES2_INCLUDE_NVIDIA_SHADERS - 2, -#else - 1, -#endif - { -#if GLES2_INCLUDE_NVIDIA_SHADERS - &GLES2_FragmentTegra_None_SolidSrc, -#endif - &GLES2_FragmentSrc_SolidSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Alpha_SolidSrc = { -#if GLES2_INCLUDE_NVIDIA_SHADERS - 2, -#else - 1, -#endif - { -#if GLES2_INCLUDE_NVIDIA_SHADERS - &GLES2_FragmentTegra_Alpha_SolidSrc, -#endif - &GLES2_FragmentSrc_SolidSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Additive_SolidSrc = { -#if GLES2_INCLUDE_NVIDIA_SHADERS - 2, -#else - 1, -#endif - { -#if GLES2_INCLUDE_NVIDIA_SHADERS - &GLES2_FragmentTegra_Additive_SolidSrc, -#endif - &GLES2_FragmentSrc_SolidSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Modulated_SolidSrc = { -#if GLES2_INCLUDE_NVIDIA_SHADERS - 2, -#else - 1, -#endif - { -#if GLES2_INCLUDE_NVIDIA_SHADERS - &GLES2_FragmentTegra_Modulated_SolidSrc, -#endif - &GLES2_FragmentSrc_SolidSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_None_TextureABGRSrc = { -#if GLES2_INCLUDE_NVIDIA_SHADERS - 2, -#else - 1, -#endif - { -#if GLES2_INCLUDE_NVIDIA_SHADERS - &GLES2_FragmentTegra_None_TextureSrc, -#endif - &GLES2_FragmentSrc_TextureABGRSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Alpha_TextureABGRSrc = { -#if GLES2_INCLUDE_NVIDIA_SHADERS - 2, -#else - 1, -#endif - { -#if GLES2_INCLUDE_NVIDIA_SHADERS - &GLES2_FragmentTegra_Alpha_TextureSrc, -#endif - &GLES2_FragmentSrc_TextureABGRSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Additive_TextureABGRSrc = { -#if GLES2_INCLUDE_NVIDIA_SHADERS - 2, -#else - 1, -#endif - { -#if GLES2_INCLUDE_NVIDIA_SHADERS - &GLES2_FragmentTegra_Additive_TextureSrc, -#endif - &GLES2_FragmentSrc_TextureABGRSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Modulated_TextureABGRSrc = { -#if GLES2_INCLUDE_NVIDIA_SHADERS - 2, -#else - 1, -#endif - { -#if GLES2_INCLUDE_NVIDIA_SHADERS - &GLES2_FragmentTegra_Modulated_TextureSrc, -#endif - &GLES2_FragmentSrc_TextureABGRSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_None_TextureARGBSrc = { - 1, - { - &GLES2_FragmentSrc_TextureARGBSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Alpha_TextureARGBSrc = { - 1, - { - &GLES2_FragmentSrc_TextureARGBSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Additive_TextureARGBSrc = { - 1, - { - &GLES2_FragmentSrc_TextureARGBSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Modulated_TextureARGBSrc = { - 1, - { - &GLES2_FragmentSrc_TextureARGBSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_None_TextureRGBSrc = { - 1, - { - &GLES2_FragmentSrc_TextureRGBSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Alpha_TextureRGBSrc = { - 1, - { - &GLES2_FragmentSrc_TextureRGBSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Additive_TextureRGBSrc = { - 1, - { - &GLES2_FragmentSrc_TextureRGBSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Modulated_TextureRGBSrc = { - 1, - { - &GLES2_FragmentSrc_TextureRGBSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_None_TextureBGRSrc = { - 1, - { - &GLES2_FragmentSrc_TextureBGRSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Alpha_TextureBGRSrc = { - 1, - { - &GLES2_FragmentSrc_TextureBGRSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Additive_TextureBGRSrc = { - 1, - { - &GLES2_FragmentSrc_TextureBGRSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Modulated_TextureBGRSrc = { - 1, - { - &GLES2_FragmentSrc_TextureBGRSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_TextureYUVSrc = { - 1, - { - &GLES2_FragmentSrc_TextureYUVSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_TextureNV12Src = { - 1, - { - &GLES2_FragmentSrc_TextureNV12Src - } -}; - -static GLES2_Shader GLES2_FragmentShader_TextureNV21Src = { - 1, - { - &GLES2_FragmentSrc_TextureNV21Src - } -}; - - -/************************************************************************************************* - * Shader selector * - *************************************************************************************************/ - -const GLES2_Shader *GLES2_GetShader(GLES2_ShaderType type, SDL_BlendMode blendMode) -{ - switch (type) { - case GLES2_SHADER_VERTEX_DEFAULT: - return &GLES2_VertexShader_Default; - case GLES2_SHADER_FRAGMENT_SOLID_SRC: - switch (blendMode) { - case SDL_BLENDMODE_NONE: - return &GLES2_FragmentShader_None_SolidSrc; - case SDL_BLENDMODE_BLEND: - return &GLES2_FragmentShader_Alpha_SolidSrc; - case SDL_BLENDMODE_ADD: - return &GLES2_FragmentShader_Additive_SolidSrc; - case SDL_BLENDMODE_MOD: - return &GLES2_FragmentShader_Modulated_SolidSrc; - default: - return NULL; - } - case GLES2_SHADER_FRAGMENT_TEXTURE_ABGR_SRC: - switch (blendMode) { - case SDL_BLENDMODE_NONE: - return &GLES2_FragmentShader_None_TextureABGRSrc; - case SDL_BLENDMODE_BLEND: - return &GLES2_FragmentShader_Alpha_TextureABGRSrc; - case SDL_BLENDMODE_ADD: - return &GLES2_FragmentShader_Additive_TextureABGRSrc; - case SDL_BLENDMODE_MOD: - return &GLES2_FragmentShader_Modulated_TextureABGRSrc; - default: - return NULL; - } - case GLES2_SHADER_FRAGMENT_TEXTURE_ARGB_SRC: - switch (blendMode) { - case SDL_BLENDMODE_NONE: - return &GLES2_FragmentShader_None_TextureARGBSrc; - case SDL_BLENDMODE_BLEND: - return &GLES2_FragmentShader_Alpha_TextureARGBSrc; - case SDL_BLENDMODE_ADD: - return &GLES2_FragmentShader_Additive_TextureARGBSrc; - case SDL_BLENDMODE_MOD: - return &GLES2_FragmentShader_Modulated_TextureARGBSrc; - default: - return NULL; - } - - case GLES2_SHADER_FRAGMENT_TEXTURE_RGB_SRC: - switch (blendMode) { - case SDL_BLENDMODE_NONE: - return &GLES2_FragmentShader_None_TextureRGBSrc; - case SDL_BLENDMODE_BLEND: - return &GLES2_FragmentShader_Alpha_TextureRGBSrc; - case SDL_BLENDMODE_ADD: - return &GLES2_FragmentShader_Additive_TextureRGBSrc; - case SDL_BLENDMODE_MOD: - return &GLES2_FragmentShader_Modulated_TextureRGBSrc; - default: - return NULL; - } - - case GLES2_SHADER_FRAGMENT_TEXTURE_BGR_SRC: - switch (blendMode) { - case SDL_BLENDMODE_NONE: - return &GLES2_FragmentShader_None_TextureBGRSrc; - case SDL_BLENDMODE_BLEND: - return &GLES2_FragmentShader_Alpha_TextureBGRSrc; - case SDL_BLENDMODE_ADD: - return &GLES2_FragmentShader_Additive_TextureBGRSrc; - case SDL_BLENDMODE_MOD: - return &GLES2_FragmentShader_Modulated_TextureBGRSrc; - default: - return NULL; - } - - case GLES2_SHADER_FRAGMENT_TEXTURE_YUV_SRC: - { - return &GLES2_FragmentShader_TextureYUVSrc; - } - - case GLES2_SHADER_FRAGMENT_TEXTURE_NV12_SRC: - { - return &GLES2_FragmentShader_TextureNV12Src; - } - - case GLES2_SHADER_FRAGMENT_TEXTURE_NV21_SRC: - { - return &GLES2_FragmentShader_TextureNV21Src; - } - - default: - return NULL; - } -} - -#endif /* SDL_VIDEO_RENDER_OGL_ES2 && !SDL_RENDER_DISABLED */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/opengles2/SDL_shaders_gles2.h b/3rdparty/SDL2/src/render/opengles2/SDL_shaders_gles2.h deleted file mode 100644 index 3958ae00d10..00000000000 --- a/3rdparty/SDL2/src/render/opengles2/SDL_shaders_gles2.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../../SDL_internal.h" - -#if SDL_VIDEO_RENDER_OGL_ES2 - -#ifndef SDL_shaderdata_h_ -#define SDL_shaderdata_h_ - -typedef struct GLES2_ShaderInstance -{ - GLenum type; - GLenum format; - int length; - const void *data; -} GLES2_ShaderInstance; - -typedef struct GLES2_Shader -{ - int instance_count; - const GLES2_ShaderInstance *instances[4]; -} GLES2_Shader; - -typedef enum -{ - GLES2_SHADER_VERTEX_DEFAULT, - GLES2_SHADER_FRAGMENT_SOLID_SRC, - GLES2_SHADER_FRAGMENT_TEXTURE_ABGR_SRC, - GLES2_SHADER_FRAGMENT_TEXTURE_ARGB_SRC, - GLES2_SHADER_FRAGMENT_TEXTURE_BGR_SRC, - GLES2_SHADER_FRAGMENT_TEXTURE_RGB_SRC, - GLES2_SHADER_FRAGMENT_TEXTURE_YUV_SRC, - GLES2_SHADER_FRAGMENT_TEXTURE_NV12_SRC, - GLES2_SHADER_FRAGMENT_TEXTURE_NV21_SRC -} GLES2_ShaderType; - -#define GLES2_SOURCE_SHADER (GLenum)-1 - -const GLES2_Shader *GLES2_GetShader(GLES2_ShaderType type, SDL_BlendMode blendMode); - -#endif /* SDL_shaderdata_h_ */ - -#endif /* SDL_VIDEO_RENDER_OGL_ES2 */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/psp/SDL_render_psp.c b/3rdparty/SDL2/src/render/psp/SDL_render_psp.c deleted file mode 100644 index f2851319ee2..00000000000 --- a/3rdparty/SDL2/src/render/psp/SDL_render_psp.c +++ /dev/null @@ -1,1028 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../../SDL_internal.h" - -#if SDL_VIDEO_RENDER_PSP - -#include "SDL_hints.h" -#include "../SDL_sysrender.h" - -#include <pspkernel.h> -#include <pspdisplay.h> -#include <pspgu.h> -#include <pspgum.h> -#include <stdio.h> -#include <string.h> -#include <math.h> -#include <pspge.h> -#include <stdarg.h> -#include <stdlib.h> -#include <vram.h> - - - - -/* PSP renderer implementation, based on the PGE */ - - -extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags); - - -static SDL_Renderer *PSP_CreateRenderer(SDL_Window * window, Uint32 flags); -static void PSP_WindowEvent(SDL_Renderer * renderer, - const SDL_WindowEvent *event); -static int PSP_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); -static int PSP_SetTextureColorMod(SDL_Renderer * renderer, - SDL_Texture * texture); -static int PSP_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, const void *pixels, - int pitch); -static int PSP_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, void **pixels, int *pitch); -static void PSP_UnlockTexture(SDL_Renderer * renderer, - SDL_Texture * texture); -static int PSP_SetRenderTarget(SDL_Renderer * renderer, - SDL_Texture * texture); -static int PSP_UpdateViewport(SDL_Renderer * renderer); -static int PSP_RenderClear(SDL_Renderer * renderer); -static int PSP_RenderDrawPoints(SDL_Renderer * renderer, - const SDL_FPoint * points, int count); -static int PSP_RenderDrawLines(SDL_Renderer * renderer, - const SDL_FPoint * points, int count); -static int PSP_RenderFillRects(SDL_Renderer * renderer, - const SDL_FRect * rects, int count); -static int PSP_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, - const SDL_FRect * dstrect); -static int PSP_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, - Uint32 pixel_format, void * pixels, int pitch); -static int PSP_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_FRect * dstrect, - const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip); -static void PSP_RenderPresent(SDL_Renderer * renderer); -static void PSP_DestroyTexture(SDL_Renderer * renderer, - SDL_Texture * texture); -static void PSP_DestroyRenderer(SDL_Renderer * renderer); - -/* -SDL_RenderDriver PSP_RenderDriver = { - PSP_CreateRenderer, - { - "PSP", - (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE), - 1, - {SDL_PIXELFORMAT_ABGR8888}, - 0, - 0} -}; -*/ -SDL_RenderDriver PSP_RenderDriver = { - .CreateRenderer = PSP_CreateRenderer, - .info = { - .name = "PSP", - .flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE, - .num_texture_formats = 4, - .texture_formats = { [0] = SDL_PIXELFORMAT_BGR565, - [1] = SDL_PIXELFORMAT_ABGR1555, - [2] = SDL_PIXELFORMAT_ABGR4444, - [3] = SDL_PIXELFORMAT_ABGR8888, - }, - .max_texture_width = 512, - .max_texture_height = 512, - } -}; - -#define PSP_SCREEN_WIDTH 480 -#define PSP_SCREEN_HEIGHT 272 - -#define PSP_FRAME_BUFFER_WIDTH 512 -#define PSP_FRAME_BUFFER_SIZE (PSP_FRAME_BUFFER_WIDTH*PSP_SCREEN_HEIGHT) - -static unsigned int __attribute__((aligned(16))) DisplayList[262144]; - - -#define COL5650(r,g,b,a) ((r>>3) | ((g>>2)<<5) | ((b>>3)<<11)) -#define COL5551(r,g,b,a) ((r>>3) | ((g>>3)<<5) | ((b>>3)<<10) | (a>0?0x7000:0)) -#define COL4444(r,g,b,a) ((r>>4) | ((g>>4)<<4) | ((b>>4)<<8) | ((a>>4)<<12)) -#define COL8888(r,g,b,a) ((r) | ((g)<<8) | ((b)<<16) | ((a)<<24)) - - -typedef struct -{ - void* frontbuffer ; - void* backbuffer ; - SDL_bool initialized ; - SDL_bool displayListAvail ; - unsigned int psm ; - unsigned int bpp ; - - SDL_bool vsync; - unsigned int currentColor; - int currentBlendMode; - -} PSP_RenderData; - - -typedef struct -{ - void *data; /**< Image data. */ - unsigned int size; /**< Size of data in bytes. */ - unsigned int width; /**< Image width. */ - unsigned int height; /**< Image height. */ - unsigned int textureWidth; /**< Texture width (power of two). */ - unsigned int textureHeight; /**< Texture height (power of two). */ - unsigned int bits; /**< Image bits per pixel. */ - unsigned int format; /**< Image format - one of ::pgePixelFormat. */ - unsigned int pitch; - SDL_bool swizzled; /**< Is image swizzled. */ - -} PSP_TextureData; - -typedef struct -{ - float x, y, z; -} VertV; - - -typedef struct -{ - float u, v; - float x, y, z; - -} VertTV; - - -/* Return next power of 2 */ -static int -TextureNextPow2(unsigned int w) -{ - if(w == 0) - return 0; - - unsigned int n = 2; - - while(w > n) - n <<= 1; - - return n; -} - - -static int -GetScaleQuality(void) -{ - const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY); - - if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) { - return GU_NEAREST; /* GU_NEAREST good for tile-map */ - } else { - return GU_LINEAR; /* GU_LINEAR good for scaling */ - } -} - -static int -PixelFormatToPSPFMT(Uint32 format) -{ - switch (format) { - case SDL_PIXELFORMAT_BGR565: - return GU_PSM_5650; - case SDL_PIXELFORMAT_ABGR1555: - return GU_PSM_5551; - case SDL_PIXELFORMAT_ABGR4444: - return GU_PSM_4444; - case SDL_PIXELFORMAT_ABGR8888: - return GU_PSM_8888; - default: - return GU_PSM_8888; - } -} - -void -StartDrawing(SDL_Renderer * renderer) -{ - PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata; - if(data->displayListAvail) - return; - - sceGuStart(GU_DIRECT, DisplayList); - data->displayListAvail = SDL_TRUE; -} - - -int -TextureSwizzle(PSP_TextureData *psp_texture) -{ - if(psp_texture->swizzled) - return 1; - - int bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3); - int height = psp_texture->size / bytewidth; - - int rowblocks = (bytewidth>>4); - int rowblocksadd = (rowblocks-1)<<7; - unsigned int blockaddress = 0; - unsigned int *src = (unsigned int*) psp_texture->data; - - unsigned char *data = NULL; - data = malloc(psp_texture->size); - - int j; - - for(j = 0; j < height; j++, blockaddress += 16) - { - unsigned int *block; - - block = (unsigned int*)&data[blockaddress]; - - int i; - - for(i = 0; i < rowblocks; i++) - { - *block++ = *src++; - *block++ = *src++; - *block++ = *src++; - *block++ = *src++; - block += 28; - } - - if((j & 0x7) == 0x7) - blockaddress += rowblocksadd; - } - - free(psp_texture->data); - psp_texture->data = data; - psp_texture->swizzled = SDL_TRUE; - - return 1; -} -int TextureUnswizzle(PSP_TextureData *psp_texture) -{ - if(!psp_texture->swizzled) - return 1; - - int blockx, blocky; - - int bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3); - int height = psp_texture->size / bytewidth; - - int widthblocks = bytewidth/16; - int heightblocks = height/8; - - int dstpitch = (bytewidth - 16)/4; - int dstrow = bytewidth * 8; - - unsigned int *src = (unsigned int*) psp_texture->data; - - unsigned char *data = NULL; - - data = malloc(psp_texture->size); - - if(!data) - return 0; - - sceKernelDcacheWritebackAll(); - - int j; - - unsigned char *ydst = (unsigned char *)data; - - for(blocky = 0; blocky < heightblocks; ++blocky) - { - unsigned char *xdst = ydst; - - for(blockx = 0; blockx < widthblocks; ++blockx) - { - unsigned int *block; - - block = (unsigned int*)xdst; - - for(j = 0; j < 8; ++j) - { - *(block++) = *(src++); - *(block++) = *(src++); - *(block++) = *(src++); - *(block++) = *(src++); - block += dstpitch; - } - - xdst += 16; - } - - ydst += dstrow; - } - - free(psp_texture->data); - - psp_texture->data = data; - - psp_texture->swizzled = SDL_FALSE; - - return 1; -} - -SDL_Renderer * -PSP_CreateRenderer(SDL_Window * window, Uint32 flags) -{ - - SDL_Renderer *renderer; - PSP_RenderData *data; - int pixelformat; - renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); - if (!renderer) { - SDL_OutOfMemory(); - return NULL; - } - - data = (PSP_RenderData *) SDL_calloc(1, sizeof(*data)); - if (!data) { - PSP_DestroyRenderer(renderer); - SDL_OutOfMemory(); - return NULL; - } - - - renderer->WindowEvent = PSP_WindowEvent; - renderer->CreateTexture = PSP_CreateTexture; - renderer->SetTextureColorMod = PSP_SetTextureColorMod; - renderer->UpdateTexture = PSP_UpdateTexture; - renderer->LockTexture = PSP_LockTexture; - renderer->UnlockTexture = PSP_UnlockTexture; - renderer->SetRenderTarget = PSP_SetRenderTarget; - renderer->UpdateViewport = PSP_UpdateViewport; - renderer->RenderClear = PSP_RenderClear; - renderer->RenderDrawPoints = PSP_RenderDrawPoints; - renderer->RenderDrawLines = PSP_RenderDrawLines; - renderer->RenderFillRects = PSP_RenderFillRects; - renderer->RenderCopy = PSP_RenderCopy; - renderer->RenderReadPixels = PSP_RenderReadPixels; - renderer->RenderCopyEx = PSP_RenderCopyEx; - renderer->RenderPresent = PSP_RenderPresent; - renderer->DestroyTexture = PSP_DestroyTexture; - renderer->DestroyRenderer = PSP_DestroyRenderer; - renderer->info = PSP_RenderDriver.info; - renderer->info.flags = (SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE); - renderer->driverdata = data; - renderer->window = window; - - if (data->initialized != SDL_FALSE) - return 0; - data->initialized = SDL_TRUE; - - if (flags & SDL_RENDERER_PRESENTVSYNC) { - data->vsync = SDL_TRUE; - } else { - data->vsync = SDL_FALSE; - } - - pixelformat=PixelFormatToPSPFMT(SDL_GetWindowPixelFormat(window)); - switch(pixelformat) - { - case GU_PSM_4444: - case GU_PSM_5650: - case GU_PSM_5551: - data->frontbuffer = (unsigned int *)(PSP_FRAME_BUFFER_SIZE<<1); - data->backbuffer = (unsigned int *)(0); - data->bpp = 2; - data->psm = pixelformat; - break; - default: - data->frontbuffer = (unsigned int *)(PSP_FRAME_BUFFER_SIZE<<2); - data->backbuffer = (unsigned int *)(0); - data->bpp = 4; - data->psm = GU_PSM_8888; - break; - } - - sceGuInit(); - /* setup GU */ - sceGuStart(GU_DIRECT, DisplayList); - sceGuDrawBuffer(data->psm, data->frontbuffer, PSP_FRAME_BUFFER_WIDTH); - sceGuDispBuffer(PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT, data->backbuffer, PSP_FRAME_BUFFER_WIDTH); - - - sceGuOffset(2048 - (PSP_SCREEN_WIDTH>>1), 2048 - (PSP_SCREEN_HEIGHT>>1)); - sceGuViewport(2048, 2048, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT); - - data->frontbuffer = vabsptr(data->frontbuffer); - data->backbuffer = vabsptr(data->backbuffer); - - /* Scissoring */ - sceGuScissor(0, 0, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT); - sceGuEnable(GU_SCISSOR_TEST); - - /* Backface culling */ - sceGuFrontFace(GU_CCW); - sceGuEnable(GU_CULL_FACE); - - /* Texturing */ - sceGuEnable(GU_TEXTURE_2D); - sceGuShadeModel(GU_SMOOTH); - sceGuTexWrap(GU_REPEAT, GU_REPEAT); - - /* Blending */ - sceGuEnable(GU_BLEND); - sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); - - sceGuTexFilter(GU_LINEAR,GU_LINEAR); - - sceGuFinish(); - sceGuSync(0,0); - sceDisplayWaitVblankStartCB(); - sceGuDisplay(GU_TRUE); - - return renderer; -} - -static void -PSP_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event) -{ - -} - - -static int -PSP_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ -/* PSP_RenderData *renderdata = (PSP_RenderData *) renderer->driverdata; */ - PSP_TextureData* psp_texture = (PSP_TextureData*) SDL_calloc(1, sizeof(*psp_texture)); - - if(!psp_texture) - return -1; - - psp_texture->swizzled = SDL_FALSE; - psp_texture->width = texture->w; - psp_texture->height = texture->h; - psp_texture->textureHeight = TextureNextPow2(texture->h); - psp_texture->textureWidth = TextureNextPow2(texture->w); - psp_texture->format = PixelFormatToPSPFMT(texture->format); - - switch(psp_texture->format) - { - case GU_PSM_5650: - case GU_PSM_5551: - case GU_PSM_4444: - psp_texture->bits = 16; - break; - - case GU_PSM_8888: - psp_texture->bits = 32; - break; - - default: - return -1; - } - - psp_texture->pitch = psp_texture->textureWidth * SDL_BYTESPERPIXEL(texture->format); - psp_texture->size = psp_texture->textureHeight*psp_texture->pitch; - psp_texture->data = SDL_calloc(1, psp_texture->size); - - if(!psp_texture->data) - { - SDL_free(psp_texture); - return SDL_OutOfMemory(); - } - texture->driverdata = psp_texture; - - return 0; -} - -static int -PSP_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture) -{ - return SDL_Unsupported(); -} - -void -TextureActivate(SDL_Texture * texture) -{ - PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata; - int scaleMode = GetScaleQuality(); - - /* Swizzling is useless with small textures. */ - if (texture->w >= 16 || texture->h >= 16) - { - TextureSwizzle(psp_texture); - } - - sceGuEnable(GU_TEXTURE_2D); - sceGuTexWrap(GU_REPEAT, GU_REPEAT); - sceGuTexMode(psp_texture->format, 0, 0, psp_texture->swizzled); - sceGuTexFilter(scaleMode, scaleMode); /* GU_NEAREST good for tile-map */ - /* GU_LINEAR good for scaling */ - sceGuTexImage(0, psp_texture->textureWidth, psp_texture->textureHeight, psp_texture->textureWidth, psp_texture->data); - sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); -} - - -static int -PSP_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, const void *pixels, int pitch) -{ -/* PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata; */ - const Uint8 *src; - Uint8 *dst; - int row, length,dpitch; - src = pixels; - - PSP_LockTexture(renderer, texture,rect,(void **)&dst, &dpitch); - length = rect->w * SDL_BYTESPERPIXEL(texture->format); - if (length == pitch && length == dpitch) { - SDL_memcpy(dst, src, length*rect->h); - } else { - for (row = 0; row < rect->h; ++row) { - SDL_memcpy(dst, src, length); - src += pitch; - dst += dpitch; - } - } - - sceKernelDcacheWritebackAll(); - return 0; -} - -static int -PSP_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, void **pixels, int *pitch) -{ - PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata; - - *pixels = - (void *) ((Uint8 *) psp_texture->data + rect->y * psp_texture->pitch + - rect->x * SDL_BYTESPERPIXEL(texture->format)); - *pitch = psp_texture->pitch; - return 0; -} - -static void -PSP_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata; - SDL_Rect rect; - - /* We do whole texture updates, at least for now */ - rect.x = 0; - rect.y = 0; - rect.w = texture->w; - rect.h = texture->h; - PSP_UpdateTexture(renderer, texture, &rect, psp_texture->data, psp_texture->pitch); -} - -static int -PSP_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture) -{ - - return 0; -} - -static int -PSP_UpdateViewport(SDL_Renderer * renderer) -{ - - return 0; -} - - -static void -PSP_SetBlendMode(SDL_Renderer * renderer, int blendMode) -{ - PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata; - if (blendMode != data-> currentBlendMode) { - switch (blendMode) { - case SDL_BLENDMODE_NONE: - sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); - sceGuDisable(GU_BLEND); - break; - case SDL_BLENDMODE_BLEND: - sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA); - sceGuEnable(GU_BLEND); - sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0 ); - break; - case SDL_BLENDMODE_ADD: - sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA); - sceGuEnable(GU_BLEND); - sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_FIX, 0, 0x00FFFFFF ); - break; - case SDL_BLENDMODE_MOD: - sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA); - sceGuEnable(GU_BLEND); - sceGuBlendFunc( GU_ADD, GU_FIX, GU_SRC_COLOR, 0, 0); - break; - } - data->currentBlendMode = blendMode; - } -} - - - -static int -PSP_RenderClear(SDL_Renderer * renderer) -{ - /* start list */ - StartDrawing(renderer); - int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r; - sceGuClearColor(color); - sceGuClearDepth(0); - sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT|GU_FAST_CLEAR_BIT); - - return 0; -} - -static int -PSP_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points, - int count) -{ - int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r; - int i; - StartDrawing(renderer); - VertV* vertices = (VertV*)sceGuGetMemory(count*sizeof(VertV)); - - for (i = 0; i < count; ++i) { - vertices[i].x = points[i].x; - vertices[i].y = points[i].y; - vertices[i].z = 0.0f; - } - sceGuDisable(GU_TEXTURE_2D); - sceGuColor(color); - sceGuShadeModel(GU_FLAT); - sceGuDrawArray(GU_POINTS, GU_VERTEX_32BITF|GU_TRANSFORM_2D, count, 0, vertices); - sceGuShadeModel(GU_SMOOTH); - sceGuEnable(GU_TEXTURE_2D); - - return 0; -} - -static int -PSP_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points, - int count) -{ - int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r; - int i; - StartDrawing(renderer); - VertV* vertices = (VertV*)sceGuGetMemory(count*sizeof(VertV)); - - for (i = 0; i < count; ++i) { - vertices[i].x = points[i].x; - vertices[i].y = points[i].y; - vertices[i].z = 0.0f; - } - - sceGuDisable(GU_TEXTURE_2D); - sceGuColor(color); - sceGuShadeModel(GU_FLAT); - sceGuDrawArray(GU_LINE_STRIP, GU_VERTEX_32BITF|GU_TRANSFORM_2D, count, 0, vertices); - sceGuShadeModel(GU_SMOOTH); - sceGuEnable(GU_TEXTURE_2D); - - return 0; -} - -static int -PSP_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects, - int count) -{ - int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r; - int i; - StartDrawing(renderer); - - for (i = 0; i < count; ++i) { - const SDL_FRect *rect = &rects[i]; - VertV* vertices = (VertV*)sceGuGetMemory((sizeof(VertV)<<1)); - vertices[0].x = rect->x; - vertices[0].y = rect->y; - vertices[0].z = 0.0f; - - vertices[1].x = rect->x + rect->w; - vertices[1].y = rect->y + rect->h; - vertices[1].z = 0.0f; - - sceGuDisable(GU_TEXTURE_2D); - sceGuColor(color); - sceGuShadeModel(GU_FLAT); - sceGuDrawArray(GU_SPRITES, GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices); - sceGuShadeModel(GU_SMOOTH); - sceGuEnable(GU_TEXTURE_2D); - } - - return 0; -} - - -#define PI 3.14159265358979f - -#define radToDeg(x) ((x)*180.f/PI) -#define degToRad(x) ((x)*PI/180.f) - -float MathAbs(float x) -{ - float result; - - __asm__ volatile ( - "mtv %1, S000\n" - "vabs.s S000, S000\n" - "mfv %0, S000\n" - : "=r"(result) : "r"(x)); - - return result; -} - -void MathSincos(float r, float *s, float *c) -{ - __asm__ volatile ( - "mtv %2, S002\n" - "vcst.s S003, VFPU_2_PI\n" - "vmul.s S002, S002, S003\n" - "vrot.p C000, S002, [s, c]\n" - "mfv %0, S000\n" - "mfv %1, S001\n" - : "=r"(*s), "=r"(*c): "r"(r)); -} - -void Swap(float *a, float *b) -{ - float n=*a; - *a = *b; - *b = n; -} - -static int -PSP_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_FRect * dstrect) -{ - float x, y, width, height; - float u0, v0, u1, v1; - unsigned char alpha; - - x = dstrect->x; - y = dstrect->y; - width = dstrect->w; - height = dstrect->h; - - u0 = srcrect->x; - v0 = srcrect->y; - u1 = srcrect->x + srcrect->w; - v1 = srcrect->y + srcrect->h; - - alpha = texture->a; - - StartDrawing(renderer); - TextureActivate(texture); - PSP_SetBlendMode(renderer, renderer->blendMode); - - if(alpha != 255) - { - sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA); - sceGuColor(GU_RGBA(255, 255, 255, alpha)); - }else{ - sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); - sceGuColor(0xFFFFFFFF); - } - - if((MathAbs(u1) - MathAbs(u0)) < 64.0f) - { - VertTV* vertices = (VertTV*)sceGuGetMemory((sizeof(VertTV))<<1); - - vertices[0].u = u0; - vertices[0].v = v0; - vertices[0].x = x; - vertices[0].y = y; - vertices[0].z = 0; - - vertices[1].u = u1; - vertices[1].v = v1; - vertices[1].x = x + width; - vertices[1].y = y + height; - vertices[1].z = 0; - - sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices); - } - else - { - float start, end; - float curU = u0; - float curX = x; - float endX = x + width; - float slice = 64.0f; - float ustep = (u1 - u0)/width * slice; - - if(ustep < 0.0f) - ustep = -ustep; - - for(start = 0, end = width; start < end; start += slice) - { - VertTV* vertices = (VertTV*)sceGuGetMemory((sizeof(VertTV))<<1); - - float polyWidth = ((curX + slice) > endX) ? (endX - curX) : slice; - float sourceWidth = ((curU + ustep) > u1) ? (u1 - curU) : ustep; - - vertices[0].u = curU; - vertices[0].v = v0; - vertices[0].x = curX; - vertices[0].y = y; - vertices[0].z = 0; - - curU += sourceWidth; - curX += polyWidth; - - vertices[1].u = curU; - vertices[1].v = v1; - vertices[1].x = curX; - vertices[1].y = (y + height); - vertices[1].z = 0; - - sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices); - } - } - - if(alpha != 255) - sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); - return 0; -} - -static int -PSP_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, - Uint32 pixel_format, void * pixels, int pitch) - -{ - return SDL_Unsupported(); -} - - -static int -PSP_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_FRect * dstrect, - const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip) -{ - float x, y, width, height; - float u0, v0, u1, v1; - unsigned char alpha; - float centerx, centery; - - x = dstrect->x; - y = dstrect->y; - width = dstrect->w; - height = dstrect->h; - - u0 = srcrect->x; - v0 = srcrect->y; - u1 = srcrect->x + srcrect->w; - v1 = srcrect->y + srcrect->h; - - centerx = center->x; - centery = center->y; - - alpha = texture->a; - - StartDrawing(renderer); - TextureActivate(texture); - PSP_SetBlendMode(renderer, renderer->blendMode); - - if(alpha != 255) - { - sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA); - sceGuColor(GU_RGBA(255, 255, 255, alpha)); - }else{ - sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); - sceGuColor(0xFFFFFFFF); - } - -/* x += width * 0.5f; */ -/* y += height * 0.5f; */ - x += centerx; - y += centery; - - float c, s; - - MathSincos(degToRad(angle), &s, &c); - -/* width *= 0.5f; */ -/* height *= 0.5f; */ - width -= centerx; - height -= centery; - - - float cw = c*width; - float sw = s*width; - float ch = c*height; - float sh = s*height; - - VertTV* vertices = (VertTV*)sceGuGetMemory(sizeof(VertTV)<<2); - - vertices[0].u = u0; - vertices[0].v = v0; - vertices[0].x = x - cw + sh; - vertices[0].y = y - sw - ch; - vertices[0].z = 0; - - vertices[1].u = u0; - vertices[1].v = v1; - vertices[1].x = x - cw - sh; - vertices[1].y = y - sw + ch; - vertices[1].z = 0; - - vertices[2].u = u1; - vertices[2].v = v1; - vertices[2].x = x + cw - sh; - vertices[2].y = y + sw + ch; - vertices[2].z = 0; - - vertices[3].u = u1; - vertices[3].v = v0; - vertices[3].x = x + cw + sh; - vertices[3].y = y + sw - ch; - vertices[3].z = 0; - - if (flip & SDL_FLIP_HORIZONTAL) { - Swap(&vertices[0].v, &vertices[2].v); - Swap(&vertices[1].v, &vertices[3].v); - } - if (flip & SDL_FLIP_VERTICAL) { - Swap(&vertices[0].u, &vertices[2].u); - Swap(&vertices[1].u, &vertices[3].u); - } - - sceGuDrawArray(GU_TRIANGLE_FAN, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 4, 0, vertices); - - if(alpha != 255) - sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); - return 0; -} - -static void -PSP_RenderPresent(SDL_Renderer * renderer) -{ - PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata; - if(!data->displayListAvail) - return; - - data->displayListAvail = SDL_FALSE; - sceGuFinish(); - sceGuSync(0,0); - -/* if(data->vsync) */ - sceDisplayWaitVblankStart(); - - data->backbuffer = data->frontbuffer; - data->frontbuffer = vabsptr(sceGuSwapBuffers()); - -} - -static void -PSP_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - PSP_RenderData *renderdata = (PSP_RenderData *) renderer->driverdata; - PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata; - - if (renderdata == 0) - return; - - if(psp_texture == 0) - return; - - SDL_free(psp_texture->data); - SDL_free(psp_texture); - texture->driverdata = NULL; -} - -static void -PSP_DestroyRenderer(SDL_Renderer * renderer) -{ - PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata; - if (data) { - if (!data->initialized) - return; - - StartDrawing(renderer); - - sceGuTerm(); -/* vfree(data->backbuffer); */ -/* vfree(data->frontbuffer); */ - - data->initialized = SDL_FALSE; - data->displayListAvail = SDL_FALSE; - SDL_free(data); - } - SDL_free(renderer); -} - -#endif /* SDL_VIDEO_RENDER_PSP */ - -/* vi: set ts=4 sw=4 expandtab: */ - diff --git a/3rdparty/SDL2/src/render/software/SDL_blendfillrect.c b/3rdparty/SDL2/src/render/software/SDL_blendfillrect.c deleted file mode 100644 index 7cfb274aefd..00000000000 --- a/3rdparty/SDL2/src/render/software/SDL_blendfillrect.c +++ /dev/null @@ -1,336 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../../SDL_internal.h" - -#if !SDL_RENDER_DISABLED - -#include "SDL_draw.h" -#include "SDL_blendfillrect.h" - - -static int -SDL_BlendFillRect_RGB555(SDL_Surface * dst, const SDL_Rect * rect, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - unsigned inva = 0xff - a; - - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB555); - break; - case SDL_BLENDMODE_ADD: - FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB555); - break; - case SDL_BLENDMODE_MOD: - FILLRECT(Uint16, DRAW_SETPIXEL_MOD_RGB555); - break; - default: - FILLRECT(Uint16, DRAW_SETPIXEL_RGB555); - break; - } - return 0; -} - -static int -SDL_BlendFillRect_RGB565(SDL_Surface * dst, const SDL_Rect * rect, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - unsigned inva = 0xff - a; - - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB565); - break; - case SDL_BLENDMODE_ADD: - FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB565); - break; - case SDL_BLENDMODE_MOD: - FILLRECT(Uint16, DRAW_SETPIXEL_MOD_RGB565); - break; - default: - FILLRECT(Uint16, DRAW_SETPIXEL_RGB565); - break; - } - return 0; -} - -static int -SDL_BlendFillRect_RGB888(SDL_Surface * dst, const SDL_Rect * rect, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - unsigned inva = 0xff - a; - - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGB888); - break; - case SDL_BLENDMODE_ADD: - FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGB888); - break; - case SDL_BLENDMODE_MOD: - FILLRECT(Uint32, DRAW_SETPIXEL_MOD_RGB888); - break; - default: - FILLRECT(Uint32, DRAW_SETPIXEL_RGB888); - break; - } - return 0; -} - -static int -SDL_BlendFillRect_ARGB8888(SDL_Surface * dst, const SDL_Rect * rect, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - unsigned inva = 0xff - a; - - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888); - break; - case SDL_BLENDMODE_ADD: - FILLRECT(Uint32, DRAW_SETPIXEL_ADD_ARGB8888); - break; - case SDL_BLENDMODE_MOD: - FILLRECT(Uint32, DRAW_SETPIXEL_MOD_ARGB8888); - break; - default: - FILLRECT(Uint32, DRAW_SETPIXEL_ARGB8888); - break; - } - return 0; -} - -static int -SDL_BlendFillRect_RGB(SDL_Surface * dst, const SDL_Rect * rect, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - SDL_PixelFormat *fmt = dst->format; - unsigned inva = 0xff - a; - - switch (fmt->BytesPerPixel) { - case 2: - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB); - break; - case SDL_BLENDMODE_ADD: - FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB); - break; - case SDL_BLENDMODE_MOD: - FILLRECT(Uint16, DRAW_SETPIXEL_MOD_RGB); - break; - default: - FILLRECT(Uint16, DRAW_SETPIXEL_RGB); - break; - } - return 0; - case 4: - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGB); - break; - case SDL_BLENDMODE_ADD: - FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGB); - break; - case SDL_BLENDMODE_MOD: - FILLRECT(Uint32, DRAW_SETPIXEL_MOD_RGB); - break; - default: - FILLRECT(Uint32, DRAW_SETPIXEL_RGB); - break; - } - return 0; - default: - return SDL_Unsupported(); - } -} - -static int -SDL_BlendFillRect_RGBA(SDL_Surface * dst, const SDL_Rect * rect, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - SDL_PixelFormat *fmt = dst->format; - unsigned inva = 0xff - a; - - switch (fmt->BytesPerPixel) { - case 4: - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGBA); - break; - case SDL_BLENDMODE_ADD: - FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGBA); - break; - case SDL_BLENDMODE_MOD: - FILLRECT(Uint32, DRAW_SETPIXEL_MOD_RGBA); - break; - default: - FILLRECT(Uint32, DRAW_SETPIXEL_RGBA); - break; - } - return 0; - default: - return SDL_Unsupported(); - } -} - -int -SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - SDL_Rect clipped; - - if (!dst) { - return SDL_SetError("Passed NULL destination surface"); - } - - /* This function doesn't work on surfaces < 8 bpp */ - if (dst->format->BitsPerPixel < 8) { - return SDL_SetError("SDL_BlendFillRect(): Unsupported surface format"); - } - - /* If 'rect' == NULL, then fill the whole surface */ - if (rect) { - /* Perform clipping */ - if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) { - return 0; - } - rect = &clipped; - } else { - rect = &dst->clip_rect; - } - - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { - r = DRAW_MUL(r, a); - g = DRAW_MUL(g, a); - b = DRAW_MUL(b, a); - } - - switch (dst->format->BitsPerPixel) { - case 15: - switch (dst->format->Rmask) { - case 0x7C00: - return SDL_BlendFillRect_RGB555(dst, rect, blendMode, r, g, b, a); - } - break; - case 16: - switch (dst->format->Rmask) { - case 0xF800: - return SDL_BlendFillRect_RGB565(dst, rect, blendMode, r, g, b, a); - } - break; - case 32: - switch (dst->format->Rmask) { - case 0x00FF0000: - if (!dst->format->Amask) { - return SDL_BlendFillRect_RGB888(dst, rect, blendMode, r, g, b, a); - } else { - return SDL_BlendFillRect_ARGB8888(dst, rect, blendMode, r, g, b, a); - } - break; - } - break; - default: - break; - } - - if (!dst->format->Amask) { - return SDL_BlendFillRect_RGB(dst, rect, blendMode, r, g, b, a); - } else { - return SDL_BlendFillRect_RGBA(dst, rect, blendMode, r, g, b, a); - } -} - -int -SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect * rects, int count, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - SDL_Rect rect; - int i; - int (*func)(SDL_Surface * dst, const SDL_Rect * rect, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL; - int status = 0; - - if (!dst) { - return SDL_SetError("Passed NULL destination surface"); - } - - /* This function doesn't work on surfaces < 8 bpp */ - if (dst->format->BitsPerPixel < 8) { - return SDL_SetError("SDL_BlendFillRects(): Unsupported surface format"); - } - - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { - r = DRAW_MUL(r, a); - g = DRAW_MUL(g, a); - b = DRAW_MUL(b, a); - } - - /* FIXME: Does this function pointer slow things down significantly? */ - switch (dst->format->BitsPerPixel) { - case 15: - switch (dst->format->Rmask) { - case 0x7C00: - func = SDL_BlendFillRect_RGB555; - } - break; - case 16: - switch (dst->format->Rmask) { - case 0xF800: - func = SDL_BlendFillRect_RGB565; - } - break; - case 32: - switch (dst->format->Rmask) { - case 0x00FF0000: - if (!dst->format->Amask) { - func = SDL_BlendFillRect_RGB888; - } else { - func = SDL_BlendFillRect_ARGB8888; - } - break; - } - break; - default: - break; - } - - if (!func) { - if (!dst->format->Amask) { - func = SDL_BlendFillRect_RGB; - } else { - func = SDL_BlendFillRect_RGBA; - } - } - - for (i = 0; i < count; ++i) { - /* Perform clipping */ - if (!SDL_IntersectRect(&rects[i], &dst->clip_rect, &rect)) { - continue; - } - status = func(dst, &rect, blendMode, r, g, b, a); - } - return status; -} - -#endif /* !SDL_RENDER_DISABLED */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/software/SDL_blendfillrect.h b/3rdparty/SDL2/src/render/software/SDL_blendfillrect.h deleted file mode 100644 index 88bb2e2c467..00000000000 --- a/3rdparty/SDL2/src/render/software/SDL_blendfillrect.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../../SDL_internal.h" - - -extern int SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); -extern int SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect * rects, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/software/SDL_blendline.c b/3rdparty/SDL2/src/render/software/SDL_blendline.c deleted file mode 100644 index ef0d585316c..00000000000 --- a/3rdparty/SDL2/src/render/software/SDL_blendline.c +++ /dev/null @@ -1,777 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../../SDL_internal.h" - -#if !SDL_RENDER_DISABLED - -#include "SDL_draw.h" -#include "SDL_blendline.h" -#include "SDL_blendpoint.h" - - -static void -SDL_BlendLine_RGB2(SDL_Surface * dst, int x1, int y1, int x2, int y2, - SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, - SDL_bool draw_end) -{ - const SDL_PixelFormat *fmt = dst->format; - unsigned r, g, b, a, inva; - - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { - r = DRAW_MUL(_r, _a); - g = DRAW_MUL(_g, _a); - b = DRAW_MUL(_b, _a); - a = _a; - } else { - r = _r; - g = _g; - b = _b; - a = _a; - } - inva = (a ^ 0xff); - - if (y1 == y2) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end); - break; - case SDL_BLENDMODE_ADD: - HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end); - break; - case SDL_BLENDMODE_MOD: - HLINE(Uint16, DRAW_SETPIXEL_MOD_RGB, draw_end); - break; - default: - HLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end); - break; - } - } else if (x1 == x2) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end); - break; - case SDL_BLENDMODE_ADD: - VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end); - break; - case SDL_BLENDMODE_MOD: - VLINE(Uint16, DRAW_SETPIXEL_MOD_RGB, draw_end); - break; - default: - VLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end); - break; - } - } else if (ABS(x1 - x2) == ABS(y1 - y2)) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end); - break; - case SDL_BLENDMODE_ADD: - DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end); - break; - case SDL_BLENDMODE_MOD: - DLINE(Uint16, DRAW_SETPIXEL_MOD_RGB, draw_end); - break; - default: - DLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end); - break; - } - } else { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY2_BLEND_RGB, DRAW_SETPIXELXY2_BLEND_RGB, - draw_end); - break; - case SDL_BLENDMODE_ADD: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY2_ADD_RGB, DRAW_SETPIXELXY2_ADD_RGB, - draw_end); - break; - case SDL_BLENDMODE_MOD: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY2_MOD_RGB, DRAW_SETPIXELXY2_MOD_RGB, - draw_end); - break; - default: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY2_RGB, DRAW_SETPIXELXY2_BLEND_RGB, - draw_end); - break; - } - } -} - -static void -SDL_BlendLine_RGB555(SDL_Surface * dst, int x1, int y1, int x2, int y2, - SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, - SDL_bool draw_end) -{ - unsigned r, g, b, a, inva; - - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { - r = DRAW_MUL(_r, _a); - g = DRAW_MUL(_g, _a); - b = DRAW_MUL(_b, _a); - a = _a; - } else { - r = _r; - g = _g; - b = _b; - a = _a; - } - inva = (a ^ 0xff); - - if (y1 == y2) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end); - break; - case SDL_BLENDMODE_ADD: - HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end); - break; - case SDL_BLENDMODE_MOD: - HLINE(Uint16, DRAW_SETPIXEL_MOD_RGB555, draw_end); - break; - default: - HLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end); - break; - } - } else if (x1 == x2) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end); - break; - case SDL_BLENDMODE_ADD: - VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end); - break; - case SDL_BLENDMODE_MOD: - VLINE(Uint16, DRAW_SETPIXEL_MOD_RGB555, draw_end); - break; - default: - VLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end); - break; - } - } else if (ABS(x1 - x2) == ABS(y1 - y2)) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end); - break; - case SDL_BLENDMODE_ADD: - DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end); - break; - case SDL_BLENDMODE_MOD: - DLINE(Uint16, DRAW_SETPIXEL_MOD_RGB555, draw_end); - break; - default: - DLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end); - break; - } - } else { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_BLEND_RGB555, DRAW_SETPIXELXY_BLEND_RGB555, - draw_end); - break; - case SDL_BLENDMODE_ADD: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_ADD_RGB555, DRAW_SETPIXELXY_ADD_RGB555, - draw_end); - break; - case SDL_BLENDMODE_MOD: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_MOD_RGB555, DRAW_SETPIXELXY_MOD_RGB555, - draw_end); - break; - default: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_RGB555, DRAW_SETPIXELXY_BLEND_RGB555, - draw_end); - break; - } - } -} - -static void -SDL_BlendLine_RGB565(SDL_Surface * dst, int x1, int y1, int x2, int y2, - SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, - SDL_bool draw_end) -{ - unsigned r, g, b, a, inva; - - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { - r = DRAW_MUL(_r, _a); - g = DRAW_MUL(_g, _a); - b = DRAW_MUL(_b, _a); - a = _a; - } else { - r = _r; - g = _g; - b = _b; - a = _a; - } - inva = (a ^ 0xff); - - if (y1 == y2) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end); - break; - case SDL_BLENDMODE_ADD: - HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end); - break; - case SDL_BLENDMODE_MOD: - HLINE(Uint16, DRAW_SETPIXEL_MOD_RGB565, draw_end); - break; - default: - HLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end); - break; - } - } else if (x1 == x2) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end); - break; - case SDL_BLENDMODE_ADD: - VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end); - break; - case SDL_BLENDMODE_MOD: - VLINE(Uint16, DRAW_SETPIXEL_MOD_RGB565, draw_end); - break; - default: - VLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end); - break; - } - } else if (ABS(x1 - x2) == ABS(y1 - y2)) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end); - break; - case SDL_BLENDMODE_ADD: - DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end); - break; - case SDL_BLENDMODE_MOD: - DLINE(Uint16, DRAW_SETPIXEL_MOD_RGB565, draw_end); - break; - default: - DLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end); - break; - } - } else { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_BLEND_RGB565, DRAW_SETPIXELXY_BLEND_RGB565, - draw_end); - break; - case SDL_BLENDMODE_ADD: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_ADD_RGB565, DRAW_SETPIXELXY_ADD_RGB565, - draw_end); - break; - case SDL_BLENDMODE_MOD: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_MOD_RGB565, DRAW_SETPIXELXY_MOD_RGB565, - draw_end); - break; - default: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_RGB565, DRAW_SETPIXELXY_BLEND_RGB565, - draw_end); - break; - } - } -} - -static void -SDL_BlendLine_RGB4(SDL_Surface * dst, int x1, int y1, int x2, int y2, - SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, - SDL_bool draw_end) -{ - const SDL_PixelFormat *fmt = dst->format; - unsigned r, g, b, a, inva; - - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { - r = DRAW_MUL(_r, _a); - g = DRAW_MUL(_g, _a); - b = DRAW_MUL(_b, _a); - a = _a; - } else { - r = _r; - g = _g; - b = _b; - a = _a; - } - inva = (a ^ 0xff); - - if (y1 == y2) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end); - break; - case SDL_BLENDMODE_ADD: - HLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end); - break; - case SDL_BLENDMODE_MOD: - HLINE(Uint32, DRAW_SETPIXEL_MOD_RGB, draw_end); - break; - default: - HLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end); - break; - } - } else if (x1 == x2) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end); - break; - case SDL_BLENDMODE_ADD: - VLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end); - break; - case SDL_BLENDMODE_MOD: - VLINE(Uint32, DRAW_SETPIXEL_MOD_RGB, draw_end); - break; - default: - VLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end); - break; - } - } else if (ABS(x1 - x2) == ABS(y1 - y2)) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end); - break; - case SDL_BLENDMODE_ADD: - DLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end); - break; - case SDL_BLENDMODE_MOD: - DLINE(Uint32, DRAW_SETPIXEL_MOD_RGB, draw_end); - break; - default: - DLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end); - break; - } - } else { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY4_BLEND_RGB, DRAW_SETPIXELXY4_BLEND_RGB, - draw_end); - break; - case SDL_BLENDMODE_ADD: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY4_ADD_RGB, DRAW_SETPIXELXY4_ADD_RGB, - draw_end); - break; - case SDL_BLENDMODE_MOD: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY4_MOD_RGB, DRAW_SETPIXELXY4_MOD_RGB, - draw_end); - break; - default: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY4_RGB, DRAW_SETPIXELXY4_BLEND_RGB, - draw_end); - break; - } - } -} - -static void -SDL_BlendLine_RGBA4(SDL_Surface * dst, int x1, int y1, int x2, int y2, - SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, - SDL_bool draw_end) -{ - const SDL_PixelFormat *fmt = dst->format; - unsigned r, g, b, a, inva; - - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { - r = DRAW_MUL(_r, _a); - g = DRAW_MUL(_g, _a); - b = DRAW_MUL(_b, _a); - a = _a; - } else { - r = _r; - g = _g; - b = _b; - a = _a; - } - inva = (a ^ 0xff); - - if (y1 == y2) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end); - break; - case SDL_BLENDMODE_ADD: - HLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end); - break; - case SDL_BLENDMODE_MOD: - HLINE(Uint32, DRAW_SETPIXEL_MOD_RGBA, draw_end); - break; - default: - HLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end); - break; - } - } else if (x1 == x2) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end); - break; - case SDL_BLENDMODE_ADD: - VLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end); - break; - case SDL_BLENDMODE_MOD: - VLINE(Uint32, DRAW_SETPIXEL_MOD_RGBA, draw_end); - break; - default: - VLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end); - break; - } - } else if (ABS(x1 - x2) == ABS(y1 - y2)) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end); - break; - case SDL_BLENDMODE_ADD: - DLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end); - break; - case SDL_BLENDMODE_MOD: - DLINE(Uint32, DRAW_SETPIXEL_MOD_RGBA, draw_end); - break; - default: - DLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end); - break; - } - } else { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY4_BLEND_RGBA, DRAW_SETPIXELXY4_BLEND_RGBA, - draw_end); - break; - case SDL_BLENDMODE_ADD: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY4_ADD_RGBA, DRAW_SETPIXELXY4_ADD_RGBA, - draw_end); - break; - case SDL_BLENDMODE_MOD: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY4_MOD_RGBA, DRAW_SETPIXELXY4_MOD_RGBA, - draw_end); - break; - default: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY4_RGBA, DRAW_SETPIXELXY4_BLEND_RGBA, - draw_end); - break; - } - } -} - -static void -SDL_BlendLine_RGB888(SDL_Surface * dst, int x1, int y1, int x2, int y2, - SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, - SDL_bool draw_end) -{ - unsigned r, g, b, a, inva; - - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { - r = DRAW_MUL(_r, _a); - g = DRAW_MUL(_g, _a); - b = DRAW_MUL(_b, _a); - a = _a; - } else { - r = _r; - g = _g; - b = _b; - a = _a; - } - inva = (a ^ 0xff); - - if (y1 == y2) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end); - break; - case SDL_BLENDMODE_ADD: - HLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end); - break; - case SDL_BLENDMODE_MOD: - HLINE(Uint32, DRAW_SETPIXEL_MOD_RGB888, draw_end); - break; - default: - HLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end); - break; - } - } else if (x1 == x2) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end); - break; - case SDL_BLENDMODE_ADD: - VLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end); - break; - case SDL_BLENDMODE_MOD: - VLINE(Uint32, DRAW_SETPIXEL_MOD_RGB888, draw_end); - break; - default: - VLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end); - break; - } - } else if (ABS(x1 - x2) == ABS(y1 - y2)) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end); - break; - case SDL_BLENDMODE_ADD: - DLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end); - break; - case SDL_BLENDMODE_MOD: - DLINE(Uint32, DRAW_SETPIXEL_MOD_RGB888, draw_end); - break; - default: - DLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end); - break; - } - } else { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_BLEND_RGB888, DRAW_SETPIXELXY_BLEND_RGB888, - draw_end); - break; - case SDL_BLENDMODE_ADD: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_ADD_RGB888, DRAW_SETPIXELXY_ADD_RGB888, - draw_end); - break; - case SDL_BLENDMODE_MOD: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_MOD_RGB888, DRAW_SETPIXELXY_MOD_RGB888, - draw_end); - break; - default: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_RGB888, DRAW_SETPIXELXY_BLEND_RGB888, - draw_end); - break; - } - } -} - -static void -SDL_BlendLine_ARGB8888(SDL_Surface * dst, int x1, int y1, int x2, int y2, - SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, - SDL_bool draw_end) -{ - unsigned r, g, b, a, inva; - - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { - r = DRAW_MUL(_r, _a); - g = DRAW_MUL(_g, _a); - b = DRAW_MUL(_b, _a); - a = _a; - } else { - r = _r; - g = _g; - b = _b; - a = _a; - } - inva = (a ^ 0xff); - - if (y1 == y2) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - HLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end); - break; - case SDL_BLENDMODE_ADD: - HLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end); - break; - case SDL_BLENDMODE_MOD: - HLINE(Uint32, DRAW_SETPIXEL_MOD_ARGB8888, draw_end); - break; - default: - HLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end); - break; - } - } else if (x1 == x2) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - VLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end); - break; - case SDL_BLENDMODE_ADD: - VLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end); - break; - case SDL_BLENDMODE_MOD: - VLINE(Uint32, DRAW_SETPIXEL_MOD_ARGB8888, draw_end); - break; - default: - VLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end); - break; - } - } else if (ABS(x1 - x2) == ABS(y1 - y2)) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - DLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end); - break; - case SDL_BLENDMODE_ADD: - DLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end); - break; - case SDL_BLENDMODE_MOD: - DLINE(Uint32, DRAW_SETPIXEL_MOD_ARGB8888, draw_end); - break; - default: - DLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end); - break; - } - } else { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_BLEND_ARGB8888, DRAW_SETPIXELXY_BLEND_ARGB8888, - draw_end); - break; - case SDL_BLENDMODE_ADD: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_ADD_ARGB8888, DRAW_SETPIXELXY_ADD_ARGB8888, - draw_end); - break; - case SDL_BLENDMODE_MOD: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_MOD_ARGB8888, DRAW_SETPIXELXY_MOD_ARGB8888, - draw_end); - break; - default: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_ARGB8888, DRAW_SETPIXELXY_BLEND_ARGB8888, - draw_end); - break; - } - } -} - -typedef void (*BlendLineFunc) (SDL_Surface * dst, - int x1, int y1, int x2, int y2, - SDL_BlendMode blendMode, - Uint8 r, Uint8 g, Uint8 b, Uint8 a, - SDL_bool draw_end); - -static BlendLineFunc -SDL_CalculateBlendLineFunc(const SDL_PixelFormat * fmt) -{ - switch (fmt->BytesPerPixel) { - case 2: - if (fmt->Rmask == 0x7C00) { - return SDL_BlendLine_RGB555; - } else if (fmt->Rmask == 0xF800) { - return SDL_BlendLine_RGB565; - } else { - return SDL_BlendLine_RGB2; - } - break; - case 4: - if (fmt->Rmask == 0x00FF0000) { - if (fmt->Amask) { - return SDL_BlendLine_ARGB8888; - } else { - return SDL_BlendLine_RGB888; - } - } else { - if (fmt->Amask) { - return SDL_BlendLine_RGBA4; - } else { - return SDL_BlendLine_RGB4; - } - } - } - return NULL; -} - -int -SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - BlendLineFunc func; - - if (!dst) { - return SDL_SetError("SDL_BlendLine(): Passed NULL destination surface"); - } - - func = SDL_CalculateBlendLineFunc(dst->format); - if (!func) { - return SDL_SetError("SDL_BlendLine(): Unsupported surface format"); - } - - /* Perform clipping */ - /* FIXME: We don't actually want to clip, as it may change line slope */ - if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) { - return 0; - } - - func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, SDL_TRUE); - return 0; -} - -int -SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - int i; - int x1, y1; - int x2, y2; - SDL_bool draw_end; - BlendLineFunc func; - - if (!dst) { - return SDL_SetError("SDL_BlendLines(): Passed NULL destination surface"); - } - - func = SDL_CalculateBlendLineFunc(dst->format); - if (!func) { - return SDL_SetError("SDL_BlendLines(): Unsupported surface format"); - } - - for (i = 1; i < count; ++i) { - x1 = points[i-1].x; - y1 = points[i-1].y; - x2 = points[i].x; - y2 = points[i].y; - - /* Perform clipping */ - /* FIXME: We don't actually want to clip, as it may change line slope */ - if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) { - continue; - } - - /* Draw the end if it was clipped */ - draw_end = (x2 != points[i].x || y2 != points[i].y); - - func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, draw_end); - } - if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) { - SDL_BlendPoint(dst, points[count-1].x, points[count-1].y, - blendMode, r, g, b, a); - } - return 0; -} - -#endif /* !SDL_RENDER_DISABLED */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/software/SDL_blendline.h b/3rdparty/SDL2/src/render/software/SDL_blendline.h deleted file mode 100644 index c0b545f3459..00000000000 --- a/3rdparty/SDL2/src/render/software/SDL_blendline.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../../SDL_internal.h" - - -extern int SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); -extern int SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/software/SDL_blendpoint.c b/3rdparty/SDL2/src/render/software/SDL_blendpoint.c deleted file mode 100644 index fc42dfe767a..00000000000 --- a/3rdparty/SDL2/src/render/software/SDL_blendpoint.c +++ /dev/null @@ -1,343 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../../SDL_internal.h" - -#if !SDL_RENDER_DISABLED - -#include "SDL_draw.h" -#include "SDL_blendpoint.h" - - -static int -SDL_BlendPoint_RGB555(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, - Uint8 g, Uint8 b, Uint8 a) -{ - unsigned inva = 0xff - a; - - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - DRAW_SETPIXELXY_BLEND_RGB555(x, y); - break; - case SDL_BLENDMODE_ADD: - DRAW_SETPIXELXY_ADD_RGB555(x, y); - break; - case SDL_BLENDMODE_MOD: - DRAW_SETPIXELXY_MOD_RGB555(x, y); - break; - default: - DRAW_SETPIXELXY_RGB555(x, y); - break; - } - return 0; -} - -static int -SDL_BlendPoint_RGB565(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, - Uint8 g, Uint8 b, Uint8 a) -{ - unsigned inva = 0xff - a; - - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - DRAW_SETPIXELXY_BLEND_RGB565(x, y); - break; - case SDL_BLENDMODE_ADD: - DRAW_SETPIXELXY_ADD_RGB565(x, y); - break; - case SDL_BLENDMODE_MOD: - DRAW_SETPIXELXY_MOD_RGB565(x, y); - break; - default: - DRAW_SETPIXELXY_RGB565(x, y); - break; - } - return 0; -} - -static int -SDL_BlendPoint_RGB888(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, - Uint8 g, Uint8 b, Uint8 a) -{ - unsigned inva = 0xff - a; - - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - DRAW_SETPIXELXY_BLEND_RGB888(x, y); - break; - case SDL_BLENDMODE_ADD: - DRAW_SETPIXELXY_ADD_RGB888(x, y); - break; - case SDL_BLENDMODE_MOD: - DRAW_SETPIXELXY_MOD_RGB888(x, y); - break; - default: - DRAW_SETPIXELXY_RGB888(x, y); - break; - } - return 0; -} - -static int -SDL_BlendPoint_ARGB8888(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, - Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - unsigned inva = 0xff - a; - - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - DRAW_SETPIXELXY_BLEND_ARGB8888(x, y); - break; - case SDL_BLENDMODE_ADD: - DRAW_SETPIXELXY_ADD_ARGB8888(x, y); - break; - case SDL_BLENDMODE_MOD: - DRAW_SETPIXELXY_MOD_ARGB8888(x, y); - break; - default: - DRAW_SETPIXELXY_ARGB8888(x, y); - break; - } - return 0; -} - -static int -SDL_BlendPoint_RGB(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, - Uint8 g, Uint8 b, Uint8 a) -{ - SDL_PixelFormat *fmt = dst->format; - unsigned inva = 0xff - a; - - switch (fmt->BytesPerPixel) { - case 2: - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - DRAW_SETPIXELXY2_BLEND_RGB(x, y); - break; - case SDL_BLENDMODE_ADD: - DRAW_SETPIXELXY2_ADD_RGB(x, y); - break; - case SDL_BLENDMODE_MOD: - DRAW_SETPIXELXY2_MOD_RGB(x, y); - break; - default: - DRAW_SETPIXELXY2_RGB(x, y); - break; - } - return 0; - case 4: - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - DRAW_SETPIXELXY4_BLEND_RGB(x, y); - break; - case SDL_BLENDMODE_ADD: - DRAW_SETPIXELXY4_ADD_RGB(x, y); - break; - case SDL_BLENDMODE_MOD: - DRAW_SETPIXELXY4_MOD_RGB(x, y); - break; - default: - DRAW_SETPIXELXY4_RGB(x, y); - break; - } - return 0; - default: - return SDL_Unsupported(); - } -} - -static int -SDL_BlendPoint_RGBA(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, - Uint8 g, Uint8 b, Uint8 a) -{ - SDL_PixelFormat *fmt = dst->format; - unsigned inva = 0xff - a; - - switch (fmt->BytesPerPixel) { - case 4: - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - DRAW_SETPIXELXY4_BLEND_RGBA(x, y); - break; - case SDL_BLENDMODE_ADD: - DRAW_SETPIXELXY4_ADD_RGBA(x, y); - break; - case SDL_BLENDMODE_MOD: - DRAW_SETPIXELXY4_MOD_RGBA(x, y); - break; - default: - DRAW_SETPIXELXY4_RGBA(x, y); - break; - } - return 0; - default: - return SDL_Unsupported(); - } -} - -int -SDL_BlendPoint(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, - Uint8 g, Uint8 b, Uint8 a) -{ - if (!dst) { - return SDL_SetError("Passed NULL destination surface"); - } - - /* This function doesn't work on surfaces < 8 bpp */ - if (dst->format->BitsPerPixel < 8) { - return SDL_SetError("SDL_BlendPoint(): Unsupported surface format"); - } - - /* Perform clipping */ - if (x < dst->clip_rect.x || y < dst->clip_rect.y || - x >= (dst->clip_rect.x + dst->clip_rect.w) || - y >= (dst->clip_rect.y + dst->clip_rect.h)) { - return 0; - } - - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { - r = DRAW_MUL(r, a); - g = DRAW_MUL(g, a); - b = DRAW_MUL(b, a); - } - - switch (dst->format->BitsPerPixel) { - case 15: - switch (dst->format->Rmask) { - case 0x7C00: - return SDL_BlendPoint_RGB555(dst, x, y, blendMode, r, g, b, a); - } - break; - case 16: - switch (dst->format->Rmask) { - case 0xF800: - return SDL_BlendPoint_RGB565(dst, x, y, blendMode, r, g, b, a); - } - break; - case 32: - switch (dst->format->Rmask) { - case 0x00FF0000: - if (!dst->format->Amask) { - return SDL_BlendPoint_RGB888(dst, x, y, blendMode, r, g, b, - a); - } else { - return SDL_BlendPoint_ARGB8888(dst, x, y, blendMode, r, g, b, - a); - } - break; - } - break; - default: - break; - } - - if (!dst->format->Amask) { - return SDL_BlendPoint_RGB(dst, x, y, blendMode, r, g, b, a); - } else { - return SDL_BlendPoint_RGBA(dst, x, y, blendMode, r, g, b, a); - } -} - -int -SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - int minx, miny; - int maxx, maxy; - int i; - int x, y; - int (*func)(SDL_Surface * dst, int x, int y, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL; - int status = 0; - - if (!dst) { - return SDL_SetError("Passed NULL destination surface"); - } - - /* This function doesn't work on surfaces < 8 bpp */ - if (dst->format->BitsPerPixel < 8) { - return SDL_SetError("SDL_BlendPoints(): Unsupported surface format"); - } - - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { - r = DRAW_MUL(r, a); - g = DRAW_MUL(g, a); - b = DRAW_MUL(b, a); - } - - /* FIXME: Does this function pointer slow things down significantly? */ - switch (dst->format->BitsPerPixel) { - case 15: - switch (dst->format->Rmask) { - case 0x7C00: - func = SDL_BlendPoint_RGB555; - break; - } - break; - case 16: - switch (dst->format->Rmask) { - case 0xF800: - func = SDL_BlendPoint_RGB565; - break; - } - break; - case 32: - switch (dst->format->Rmask) { - case 0x00FF0000: - if (!dst->format->Amask) { - func = SDL_BlendPoint_RGB888; - } else { - func = SDL_BlendPoint_ARGB8888; - } - break; - } - break; - default: - break; - } - - if (!func) { - if (!dst->format->Amask) { - func = SDL_BlendPoint_RGB; - } else { - func = SDL_BlendPoint_RGBA; - } - } - - minx = dst->clip_rect.x; - maxx = dst->clip_rect.x + dst->clip_rect.w - 1; - miny = dst->clip_rect.y; - maxy = dst->clip_rect.y + dst->clip_rect.h - 1; - - for (i = 0; i < count; ++i) { - x = points[i].x; - y = points[i].y; - - if (x < minx || x > maxx || y < miny || y > maxy) { - continue; - } - status = func(dst, x, y, blendMode, r, g, b, a); - } - return status; -} - -#endif /* !SDL_RENDER_DISABLED */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/software/SDL_blendpoint.h b/3rdparty/SDL2/src/render/software/SDL_blendpoint.h deleted file mode 100644 index 58ddec7ee42..00000000000 --- a/3rdparty/SDL2/src/render/software/SDL_blendpoint.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../../SDL_internal.h" - - -extern int SDL_BlendPoint(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); -extern int SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/software/SDL_draw.h b/3rdparty/SDL2/src/render/software/SDL_draw.h deleted file mode 100644 index 3a5e7cf1133..00000000000 --- a/3rdparty/SDL2/src/render/software/SDL_draw.h +++ /dev/null @@ -1,576 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../../SDL_internal.h" - -#include "../../video/SDL_blit.h" - -/* This code assumes that r, g, b, a are the source color, - * and in the blend and add case, the RGB values are premultiplied by a. - */ - -#define DRAW_MUL(_a, _b) (((unsigned)(_a)*(_b))/255) - -#define DRAW_FASTSETPIXEL(type) \ - *pixel = (type) color - -#define DRAW_FASTSETPIXEL1 DRAW_FASTSETPIXEL(Uint8) -#define DRAW_FASTSETPIXEL2 DRAW_FASTSETPIXEL(Uint16) -#define DRAW_FASTSETPIXEL4 DRAW_FASTSETPIXEL(Uint32) - -#define DRAW_FASTSETPIXELXY(x, y, type, bpp, color) \ - *(type *)((Uint8 *)dst->pixels + (y) * dst->pitch \ - + (x) * bpp) = (type) color - -#define DRAW_FASTSETPIXELXY1(x, y) DRAW_FASTSETPIXELXY(x, y, Uint8, 1, color) -#define DRAW_FASTSETPIXELXY2(x, y) DRAW_FASTSETPIXELXY(x, y, Uint16, 2, color) -#define DRAW_FASTSETPIXELXY4(x, y) DRAW_FASTSETPIXELXY(x, y, Uint32, 4, color) - -#define DRAW_SETPIXEL(setpixel) \ -do { \ - unsigned sr = r, sg = g, sb = b, sa = a; (void) sa; \ - setpixel; \ -} while (0) - -#define DRAW_SETPIXEL_BLEND(getpixel, setpixel) \ -do { \ - unsigned sr, sg, sb, sa = 0xFF; \ - getpixel; \ - sr = DRAW_MUL(inva, sr) + r; \ - sg = DRAW_MUL(inva, sg) + g; \ - sb = DRAW_MUL(inva, sb) + b; \ - sa = DRAW_MUL(inva, sa) + a; \ - setpixel; \ -} while (0) - -#define DRAW_SETPIXEL_ADD(getpixel, setpixel) \ -do { \ - unsigned sr, sg, sb, sa; (void) sa; \ - getpixel; \ - sr += r; if (sr > 0xff) sr = 0xff; \ - sg += g; if (sg > 0xff) sg = 0xff; \ - sb += b; if (sb > 0xff) sb = 0xff; \ - setpixel; \ -} while (0) - -#define DRAW_SETPIXEL_MOD(getpixel, setpixel) \ -do { \ - unsigned sr, sg, sb, sa; (void) sa; \ - getpixel; \ - sr = DRAW_MUL(sr, r); \ - sg = DRAW_MUL(sg, g); \ - sb = DRAW_MUL(sb, b); \ - setpixel; \ -} while (0) - -#define DRAW_SETPIXELXY(x, y, type, bpp, op) \ -do { \ - type *pixel = (type *)((Uint8 *)dst->pixels + (y) * dst->pitch \ - + (x) * bpp); \ - op; \ -} while (0) - -/* - * Define draw operators for RGB555 - */ - -#define DRAW_SETPIXEL_RGB555 \ - DRAW_SETPIXEL(RGB555_FROM_RGB(*pixel, sr, sg, sb)) - -#define DRAW_SETPIXEL_BLEND_RGB555 \ - DRAW_SETPIXEL_BLEND(RGB_FROM_RGB555(*pixel, sr, sg, sb), \ - RGB555_FROM_RGB(*pixel, sr, sg, sb)) - -#define DRAW_SETPIXEL_ADD_RGB555 \ - DRAW_SETPIXEL_ADD(RGB_FROM_RGB555(*pixel, sr, sg, sb), \ - RGB555_FROM_RGB(*pixel, sr, sg, sb)) - -#define DRAW_SETPIXEL_MOD_RGB555 \ - DRAW_SETPIXEL_MOD(RGB_FROM_RGB555(*pixel, sr, sg, sb), \ - RGB555_FROM_RGB(*pixel, sr, sg, sb)) - -#define DRAW_SETPIXELXY_RGB555(x, y) \ - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB555) - -#define DRAW_SETPIXELXY_BLEND_RGB555(x, y) \ - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB555) - -#define DRAW_SETPIXELXY_ADD_RGB555(x, y) \ - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB555) - -#define DRAW_SETPIXELXY_MOD_RGB555(x, y) \ - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MOD_RGB555) - -/* - * Define draw operators for RGB565 - */ - -#define DRAW_SETPIXEL_RGB565 \ - DRAW_SETPIXEL(RGB565_FROM_RGB(*pixel, sr, sg, sb)) - -#define DRAW_SETPIXEL_BLEND_RGB565 \ - DRAW_SETPIXEL_BLEND(RGB_FROM_RGB565(*pixel, sr, sg, sb), \ - RGB565_FROM_RGB(*pixel, sr, sg, sb)) - -#define DRAW_SETPIXEL_ADD_RGB565 \ - DRAW_SETPIXEL_ADD(RGB_FROM_RGB565(*pixel, sr, sg, sb), \ - RGB565_FROM_RGB(*pixel, sr, sg, sb)) - -#define DRAW_SETPIXEL_MOD_RGB565 \ - DRAW_SETPIXEL_MOD(RGB_FROM_RGB565(*pixel, sr, sg, sb), \ - RGB565_FROM_RGB(*pixel, sr, sg, sb)) - -#define DRAW_SETPIXELXY_RGB565(x, y) \ - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB565) - -#define DRAW_SETPIXELXY_BLEND_RGB565(x, y) \ - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB565) - -#define DRAW_SETPIXELXY_ADD_RGB565(x, y) \ - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB565) - -#define DRAW_SETPIXELXY_MOD_RGB565(x, y) \ - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MOD_RGB565) - -/* - * Define draw operators for RGB888 - */ - -#define DRAW_SETPIXEL_RGB888 \ - DRAW_SETPIXEL(RGB888_FROM_RGB(*pixel, sr, sg, sb)) - -#define DRAW_SETPIXEL_BLEND_RGB888 \ - DRAW_SETPIXEL_BLEND(RGB_FROM_RGB888(*pixel, sr, sg, sb), \ - RGB888_FROM_RGB(*pixel, sr, sg, sb)) - -#define DRAW_SETPIXEL_ADD_RGB888 \ - DRAW_SETPIXEL_ADD(RGB_FROM_RGB888(*pixel, sr, sg, sb), \ - RGB888_FROM_RGB(*pixel, sr, sg, sb)) - -#define DRAW_SETPIXEL_MOD_RGB888 \ - DRAW_SETPIXEL_MOD(RGB_FROM_RGB888(*pixel, sr, sg, sb), \ - RGB888_FROM_RGB(*pixel, sr, sg, sb)) - -#define DRAW_SETPIXELXY_RGB888(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGB888) - -#define DRAW_SETPIXELXY_BLEND_RGB888(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGB888) - -#define DRAW_SETPIXELXY_ADD_RGB888(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGB888) - -#define DRAW_SETPIXELXY_MOD_RGB888(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_RGB888) - -/* - * Define draw operators for ARGB8888 - */ - -#define DRAW_SETPIXEL_ARGB8888 \ - DRAW_SETPIXEL(ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa)) - -#define DRAW_SETPIXEL_BLEND_ARGB8888 \ - DRAW_SETPIXEL_BLEND(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \ - ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa)) - -#define DRAW_SETPIXEL_ADD_ARGB8888 \ - DRAW_SETPIXEL_ADD(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \ - ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa)) - -#define DRAW_SETPIXEL_MOD_ARGB8888 \ - DRAW_SETPIXEL_MOD(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \ - ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa)) - -#define DRAW_SETPIXELXY_ARGB8888(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ARGB8888) - -#define DRAW_SETPIXELXY_BLEND_ARGB8888(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_ARGB8888) - -#define DRAW_SETPIXELXY_ADD_ARGB8888(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_ARGB8888) - -#define DRAW_SETPIXELXY_MOD_ARGB8888(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_ARGB8888) - -/* - * Define draw operators for general RGB - */ - -#define DRAW_SETPIXEL_RGB \ - DRAW_SETPIXEL(PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb)) - -#define DRAW_SETPIXEL_BLEND_RGB \ - DRAW_SETPIXEL_BLEND(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \ - PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb)) - -#define DRAW_SETPIXEL_ADD_RGB \ - DRAW_SETPIXEL_ADD(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \ - PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb)) - -#define DRAW_SETPIXEL_MOD_RGB \ - DRAW_SETPIXEL_MOD(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \ - PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb)) - -#define DRAW_SETPIXELXY2_RGB(x, y) \ - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB) - -#define DRAW_SETPIXELXY4_RGB(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGB) - -#define DRAW_SETPIXELXY2_BLEND_RGB(x, y) \ - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB) - -#define DRAW_SETPIXELXY4_BLEND_RGB(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGB) - -#define DRAW_SETPIXELXY2_ADD_RGB(x, y) \ - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB) - -#define DRAW_SETPIXELXY4_ADD_RGB(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGB) - -#define DRAW_SETPIXELXY2_MOD_RGB(x, y) \ - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MOD_RGB) - -#define DRAW_SETPIXELXY4_MOD_RGB(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_RGB) - - -/* - * Define draw operators for general RGBA - */ - -#define DRAW_SETPIXEL_RGBA \ - DRAW_SETPIXEL(PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa)) - -#define DRAW_SETPIXEL_BLEND_RGBA \ - DRAW_SETPIXEL_BLEND(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \ - PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa)) - -#define DRAW_SETPIXEL_ADD_RGBA \ - DRAW_SETPIXEL_ADD(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \ - PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa)) - -#define DRAW_SETPIXEL_MOD_RGBA \ - DRAW_SETPIXEL_MOD(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \ - PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa)) - -#define DRAW_SETPIXELXY4_RGBA(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGBA) - -#define DRAW_SETPIXELXY4_BLEND_RGBA(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGBA) - -#define DRAW_SETPIXELXY4_ADD_RGBA(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGBA) - -#define DRAW_SETPIXELXY4_MOD_RGBA(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_RGBA) - -/* - * Define line drawing macro - */ - -#define ABS(_x) ((_x) < 0 ? -(_x) : (_x)) - -/* Horizontal line */ -#define HLINE(type, op, draw_end) \ -{ \ - int length; \ - int pitch = (dst->pitch / dst->format->BytesPerPixel); \ - type *pixel; \ - if (x1 <= x2) { \ - pixel = (type *)dst->pixels + y1 * pitch + x1; \ - length = draw_end ? (x2-x1+1) : (x2-x1); \ - } else { \ - pixel = (type *)dst->pixels + y1 * pitch + x2; \ - if (!draw_end) { \ - ++pixel; \ - } \ - length = draw_end ? (x1-x2+1) : (x1-x2); \ - } \ - while (length--) { \ - op; \ - ++pixel; \ - } \ -} - -/* Vertical line */ -#define VLINE(type, op, draw_end) \ -{ \ - int length; \ - int pitch = (dst->pitch / dst->format->BytesPerPixel); \ - type *pixel; \ - if (y1 <= y2) { \ - pixel = (type *)dst->pixels + y1 * pitch + x1; \ - length = draw_end ? (y2-y1+1) : (y2-y1); \ - } else { \ - pixel = (type *)dst->pixels + y2 * pitch + x1; \ - if (!draw_end) { \ - pixel += pitch; \ - } \ - length = draw_end ? (y1-y2+1) : (y1-y2); \ - } \ - while (length--) { \ - op; \ - pixel += pitch; \ - } \ -} - -/* Diagonal line */ -#define DLINE(type, op, draw_end) \ -{ \ - int length; \ - int pitch = (dst->pitch / dst->format->BytesPerPixel); \ - type *pixel; \ - if (y1 <= y2) { \ - pixel = (type *)dst->pixels + y1 * pitch + x1; \ - if (x1 <= x2) { \ - ++pitch; \ - } else { \ - --pitch; \ - } \ - length = (y2-y1); \ - } else { \ - pixel = (type *)dst->pixels + y2 * pitch + x2; \ - if (x2 <= x1) { \ - ++pitch; \ - } else { \ - --pitch; \ - } \ - if (!draw_end) { \ - pixel += pitch; \ - } \ - length = (y1-y2); \ - } \ - if (draw_end) { \ - ++length; \ - } \ - while (length--) { \ - op; \ - pixel += pitch; \ - } \ -} - -/* Bresenham's line algorithm */ -#define BLINE(x1, y1, x2, y2, op, draw_end) \ -{ \ - int i, deltax, deltay, numpixels; \ - int d, dinc1, dinc2; \ - int x, xinc1, xinc2; \ - int y, yinc1, yinc2; \ - \ - deltax = ABS(x2 - x1); \ - deltay = ABS(y2 - y1); \ - \ - if (deltax >= deltay) { \ - numpixels = deltax + 1; \ - d = (2 * deltay) - deltax; \ - dinc1 = deltay * 2; \ - dinc2 = (deltay - deltax) * 2; \ - xinc1 = 1; \ - xinc2 = 1; \ - yinc1 = 0; \ - yinc2 = 1; \ - } else { \ - numpixels = deltay + 1; \ - d = (2 * deltax) - deltay; \ - dinc1 = deltax * 2; \ - dinc2 = (deltax - deltay) * 2; \ - xinc1 = 0; \ - xinc2 = 1; \ - yinc1 = 1; \ - yinc2 = 1; \ - } \ - \ - if (x1 > x2) { \ - xinc1 = -xinc1; \ - xinc2 = -xinc2; \ - } \ - if (y1 > y2) { \ - yinc1 = -yinc1; \ - yinc2 = -yinc2; \ - } \ - \ - x = x1; \ - y = y1; \ - \ - if (!draw_end) { \ - --numpixels; \ - } \ - for (i = 0; i < numpixels; ++i) { \ - op(x, y); \ - if (d < 0) { \ - d += dinc1; \ - x += xinc1; \ - y += yinc1; \ - } else { \ - d += dinc2; \ - x += xinc2; \ - y += yinc2; \ - } \ - } \ -} - -/* Xiaolin Wu's line algorithm, based on Michael Abrash's implementation */ -#define WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \ -{ \ - Uint16 ErrorAdj, ErrorAcc; \ - Uint16 ErrorAccTemp, Weighting; \ - int DeltaX, DeltaY, Temp, XDir; \ - unsigned r, g, b, a, inva; \ - \ - /* Draw the initial pixel, which is always exactly intersected by \ - the line and so needs no weighting */ \ - opaque_op(x1, y1); \ - \ - /* Draw the final pixel, which is always exactly intersected by the line \ - and so needs no weighting */ \ - if (draw_end) { \ - opaque_op(x2, y2); \ - } \ - \ - /* Make sure the line runs top to bottom */ \ - if (y1 > y2) { \ - Temp = y1; y1 = y2; y2 = Temp; \ - Temp = x1; x1 = x2; x2 = Temp; \ - } \ - DeltaY = y2 - y1; \ - \ - if ((DeltaX = x2 - x1) >= 0) { \ - XDir = 1; \ - } else { \ - XDir = -1; \ - DeltaX = -DeltaX; /* make DeltaX positive */ \ - } \ - \ - /* line is not horizontal, diagonal, or vertical */ \ - ErrorAcc = 0; /* initialize the line error accumulator to 0 */ \ - \ - /* Is this an X-major or Y-major line? */ \ - if (DeltaY > DeltaX) { \ - /* Y-major line; calculate 16-bit fixed-point fractional part of a \ - pixel that X advances each time Y advances 1 pixel, truncating the \ - result so that we won't overrun the endpoint along the X axis */ \ - ErrorAdj = ((unsigned long) DeltaX << 16) / (unsigned long) DeltaY; \ - /* Draw all pixels other than the first and last */ \ - while (--DeltaY) { \ - ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */ \ - ErrorAcc += ErrorAdj; /* calculate error for next pixel */ \ - if (ErrorAcc <= ErrorAccTemp) { \ - /* The error accumulator turned over, so advance the X coord */ \ - x1 += XDir; \ - } \ - y1++; /* Y-major, so always advance Y */ \ - /* The IntensityBits most significant bits of ErrorAcc give us the \ - intensity weighting for this pixel, and the complement of the \ - weighting for the paired pixel */ \ - Weighting = ErrorAcc >> 8; \ - { \ - a = DRAW_MUL(_a, (Weighting ^ 255)); \ - r = DRAW_MUL(_r, a); \ - g = DRAW_MUL(_g, a); \ - b = DRAW_MUL(_b, a); \ - inva = (a ^ 0xFF); \ - blend_op(x1, y1); \ - } \ - { \ - a = DRAW_MUL(_a, Weighting); \ - r = DRAW_MUL(_r, a); \ - g = DRAW_MUL(_g, a); \ - b = DRAW_MUL(_b, a); \ - inva = (a ^ 0xFF); \ - blend_op(x1 + XDir, y1); \ - } \ - } \ - } else { \ - /* X-major line; calculate 16-bit fixed-point fractional part of a \ - pixel that Y advances each time X advances 1 pixel, truncating the \ - result to avoid overrunning the endpoint along the X axis */ \ - ErrorAdj = ((unsigned long) DeltaY << 16) / (unsigned long) DeltaX; \ - /* Draw all pixels other than the first and last */ \ - while (--DeltaX) { \ - ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */ \ - ErrorAcc += ErrorAdj; /* calculate error for next pixel */ \ - if (ErrorAcc <= ErrorAccTemp) { \ - /* The error accumulator turned over, so advance the Y coord */ \ - y1++; \ - } \ - x1 += XDir; /* X-major, so always advance X */ \ - /* The IntensityBits most significant bits of ErrorAcc give us the \ - intensity weighting for this pixel, and the complement of the \ - weighting for the paired pixel */ \ - Weighting = ErrorAcc >> 8; \ - { \ - a = DRAW_MUL(_a, (Weighting ^ 255)); \ - r = DRAW_MUL(_r, a); \ - g = DRAW_MUL(_g, a); \ - b = DRAW_MUL(_b, a); \ - inva = (a ^ 0xFF); \ - blend_op(x1, y1); \ - } \ - { \ - a = DRAW_MUL(_a, Weighting); \ - r = DRAW_MUL(_r, a); \ - g = DRAW_MUL(_g, a); \ - b = DRAW_MUL(_b, a); \ - inva = (a ^ 0xFF); \ - blend_op(x1, y1 + 1); \ - } \ - } \ - } \ -} - -#ifdef AA_LINES -#define AALINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \ - WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) -#else -#define AALINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \ - BLINE(x1, y1, x2, y2, opaque_op, draw_end) -#endif - -/* - * Define fill rect macro - */ - -#define FILLRECT(type, op) \ -do { \ - int width = rect->w; \ - int height = rect->h; \ - int pitch = (dst->pitch / dst->format->BytesPerPixel); \ - int skip = pitch - width; \ - type *pixel = (type *)dst->pixels + rect->y * pitch + rect->x; \ - while (height--) { \ - { int n = (width+3)/4; \ - switch (width & 3) { \ - case 0: do { op; pixel++; \ - case 3: op; pixel++; \ - case 2: op; pixel++; \ - case 1: op; pixel++; \ - } while ( --n > 0 ); \ - } \ - } \ - pixel += skip; \ - } \ -} while (0) - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/software/SDL_drawline.c b/3rdparty/SDL2/src/render/software/SDL_drawline.c deleted file mode 100644 index fd50ea748b0..00000000000 --- a/3rdparty/SDL2/src/render/software/SDL_drawline.c +++ /dev/null @@ -1,209 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../../SDL_internal.h" - -#if !SDL_RENDER_DISABLED - -#include "SDL_draw.h" -#include "SDL_drawline.h" -#include "SDL_drawpoint.h" - - -static void -SDL_DrawLine1(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color, - SDL_bool draw_end) -{ - if (y1 == y2) { - int length; - int pitch = (dst->pitch / dst->format->BytesPerPixel); - Uint8 *pixel; - if (x1 <= x2) { - pixel = (Uint8 *)dst->pixels + y1 * pitch + x1; - length = draw_end ? (x2-x1+1) : (x2-x1); - } else { - pixel = (Uint8 *)dst->pixels + y1 * pitch + x2; - if (!draw_end) { - ++pixel; - } - length = draw_end ? (x1-x2+1) : (x1-x2); - } - SDL_memset(pixel, color, length); - } else if (x1 == x2) { - VLINE(Uint8, DRAW_FASTSETPIXEL1, draw_end); - } else if (ABS(x1 - x2) == ABS(y1 - y2)) { - DLINE(Uint8, DRAW_FASTSETPIXEL1, draw_end); - } else { - BLINE(x1, y1, x2, y2, DRAW_FASTSETPIXELXY1, draw_end); - } -} - -static void -SDL_DrawLine2(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color, - SDL_bool draw_end) -{ - if (y1 == y2) { - HLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end); - } else if (x1 == x2) { - VLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end); - } else if (ABS(x1 - x2) == ABS(y1 - y2)) { - DLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end); - } else { - Uint8 _r, _g, _b, _a; - const SDL_PixelFormat * fmt = dst->format; - SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a); - if (fmt->Rmask == 0x7C00) { - AALINE(x1, y1, x2, y2, - DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY_BLEND_RGB555, - draw_end); - } else if (fmt->Rmask == 0xF800) { - AALINE(x1, y1, x2, y2, - DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY_BLEND_RGB565, - draw_end); - } else { - AALINE(x1, y1, x2, y2, - DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY2_BLEND_RGB, - draw_end); - } - } -} - -static void -SDL_DrawLine4(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color, - SDL_bool draw_end) -{ - if (y1 == y2) { - HLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end); - } else if (x1 == x2) { - VLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end); - } else if (ABS(x1 - x2) == ABS(y1 - y2)) { - DLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end); - } else { - Uint8 _r, _g, _b, _a; - const SDL_PixelFormat * fmt = dst->format; - SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a); - if (fmt->Rmask == 0x00FF0000) { - if (!fmt->Amask) { - AALINE(x1, y1, x2, y2, - DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY_BLEND_RGB888, - draw_end); - } else { - AALINE(x1, y1, x2, y2, - DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY_BLEND_ARGB8888, - draw_end); - } - } else { - AALINE(x1, y1, x2, y2, - DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY4_BLEND_RGB, - draw_end); - } - } -} - -typedef void (*DrawLineFunc) (SDL_Surface * dst, - int x1, int y1, int x2, int y2, - Uint32 color, SDL_bool draw_end); - -static DrawLineFunc -SDL_CalculateDrawLineFunc(const SDL_PixelFormat * fmt) -{ - switch (fmt->BytesPerPixel) { - case 1: - if (fmt->BitsPerPixel < 8) { - break; - } - return SDL_DrawLine1; - case 2: - return SDL_DrawLine2; - case 4: - return SDL_DrawLine4; - } - return NULL; -} - -int -SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color) -{ - DrawLineFunc func; - - if (!dst) { - return SDL_SetError("SDL_DrawLine(): Passed NULL destination surface"); - } - - func = SDL_CalculateDrawLineFunc(dst->format); - if (!func) { - return SDL_SetError("SDL_DrawLine(): Unsupported surface format"); - } - - /* Perform clipping */ - /* FIXME: We don't actually want to clip, as it may change line slope */ - if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) { - return 0; - } - - func(dst, x1, y1, x2, y2, color, SDL_TRUE); - return 0; -} - -int -SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count, - Uint32 color) -{ - int i; - int x1, y1; - int x2, y2; - SDL_bool draw_end; - DrawLineFunc func; - - if (!dst) { - return SDL_SetError("SDL_DrawLines(): Passed NULL destination surface"); - } - - func = SDL_CalculateDrawLineFunc(dst->format); - if (!func) { - return SDL_SetError("SDL_DrawLines(): Unsupported surface format"); - } - - for (i = 1; i < count; ++i) { - x1 = points[i-1].x; - y1 = points[i-1].y; - x2 = points[i].x; - y2 = points[i].y; - - /* Perform clipping */ - /* FIXME: We don't actually want to clip, as it may change line slope */ - if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) { - continue; - } - - /* Draw the end if it was clipped */ - draw_end = (x2 != points[i].x || y2 != points[i].y); - - func(dst, x1, y1, x2, y2, color, draw_end); - } - if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) { - SDL_DrawPoint(dst, points[count-1].x, points[count-1].y, color); - } - return 0; -} - -#endif /* !SDL_RENDER_DISABLED */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/software/SDL_drawline.h b/3rdparty/SDL2/src/render/software/SDL_drawline.h deleted file mode 100644 index 40721c3fcec..00000000000 --- a/3rdparty/SDL2/src/render/software/SDL_drawline.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../../SDL_internal.h" - - -extern int SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color); -extern int SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color); - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/software/SDL_drawpoint.c b/3rdparty/SDL2/src/render/software/SDL_drawpoint.c deleted file mode 100644 index 98f0d83c00c..00000000000 --- a/3rdparty/SDL2/src/render/software/SDL_drawpoint.c +++ /dev/null @@ -1,114 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../../SDL_internal.h" - -#if !SDL_RENDER_DISABLED - -#include "SDL_draw.h" -#include "SDL_drawpoint.h" - - -int -SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color) -{ - if (!dst) { - return SDL_SetError("Passed NULL destination surface"); - } - - /* This function doesn't work on surfaces < 8 bpp */ - if (dst->format->BitsPerPixel < 8) { - return SDL_SetError("SDL_DrawPoint(): Unsupported surface format"); - } - - /* Perform clipping */ - if (x < dst->clip_rect.x || y < dst->clip_rect.y || - x >= (dst->clip_rect.x + dst->clip_rect.w) || - y >= (dst->clip_rect.y + dst->clip_rect.h)) { - return 0; - } - - switch (dst->format->BytesPerPixel) { - case 1: - DRAW_FASTSETPIXELXY1(x, y); - break; - case 2: - DRAW_FASTSETPIXELXY2(x, y); - break; - case 3: - return SDL_Unsupported(); - case 4: - DRAW_FASTSETPIXELXY4(x, y); - break; - } - return 0; -} - -int -SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count, - Uint32 color) -{ - int minx, miny; - int maxx, maxy; - int i; - int x, y; - - if (!dst) { - return SDL_SetError("Passed NULL destination surface"); - } - - /* This function doesn't work on surfaces < 8 bpp */ - if (dst->format->BitsPerPixel < 8) { - return SDL_SetError("SDL_DrawPoints(): Unsupported surface format"); - } - - minx = dst->clip_rect.x; - maxx = dst->clip_rect.x + dst->clip_rect.w - 1; - miny = dst->clip_rect.y; - maxy = dst->clip_rect.y + dst->clip_rect.h - 1; - - for (i = 0; i < count; ++i) { - x = points[i].x; - y = points[i].y; - - if (x < minx || x > maxx || y < miny || y > maxy) { - continue; - } - - switch (dst->format->BytesPerPixel) { - case 1: - DRAW_FASTSETPIXELXY1(x, y); - break; - case 2: - DRAW_FASTSETPIXELXY2(x, y); - break; - case 3: - return SDL_Unsupported(); - case 4: - DRAW_FASTSETPIXELXY4(x, y); - break; - } - } - return 0; -} - -#endif /* !SDL_RENDER_DISABLED */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/software/SDL_drawpoint.h b/3rdparty/SDL2/src/render/software/SDL_drawpoint.h deleted file mode 100644 index e77857ac91a..00000000000 --- a/3rdparty/SDL2/src/render/software/SDL_drawpoint.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../../SDL_internal.h" - - -extern int SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color); -extern int SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color); - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/software/SDL_render_sw.c b/3rdparty/SDL2/src/render/software/SDL_render_sw.c deleted file mode 100644 index e7a6cd88d53..00000000000 --- a/3rdparty/SDL2/src/render/software/SDL_render_sw.c +++ /dev/null @@ -1,794 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../../SDL_internal.h" - -#if !SDL_RENDER_DISABLED - -#include "../SDL_sysrender.h" -#include "SDL_render_sw_c.h" -#include "SDL_hints.h" - -#include "SDL_draw.h" -#include "SDL_blendfillrect.h" -#include "SDL_blendline.h" -#include "SDL_blendpoint.h" -#include "SDL_drawline.h" -#include "SDL_drawpoint.h" -#include "SDL_rotate.h" - -/* SDL surface based renderer implementation */ - -static SDL_Renderer *SW_CreateRenderer(SDL_Window * window, Uint32 flags); -static void SW_WindowEvent(SDL_Renderer * renderer, - const SDL_WindowEvent *event); -static int SW_GetOutputSize(SDL_Renderer * renderer, int *w, int *h); -static int SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); -static int SW_SetTextureColorMod(SDL_Renderer * renderer, - SDL_Texture * texture); -static int SW_SetTextureAlphaMod(SDL_Renderer * renderer, - SDL_Texture * texture); -static int SW_SetTextureBlendMode(SDL_Renderer * renderer, - SDL_Texture * texture); -static int SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, const void *pixels, - int pitch); -static int SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, void **pixels, int *pitch); -static void SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); -static int SW_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture); -static int SW_UpdateViewport(SDL_Renderer * renderer); -static int SW_UpdateClipRect(SDL_Renderer * renderer); -static int SW_RenderClear(SDL_Renderer * renderer); -static int SW_RenderDrawPoints(SDL_Renderer * renderer, - const SDL_FPoint * points, int count); -static int SW_RenderDrawLines(SDL_Renderer * renderer, - const SDL_FPoint * points, int count); -static int SW_RenderFillRects(SDL_Renderer * renderer, - const SDL_FRect * rects, int count); -static int SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_FRect * dstrect); -static int SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_FRect * dstrect, - const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip); -static int SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, - Uint32 format, void * pixels, int pitch); -static void SW_RenderPresent(SDL_Renderer * renderer); -static void SW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture); -static void SW_DestroyRenderer(SDL_Renderer * renderer); - - -SDL_RenderDriver SW_RenderDriver = { - SW_CreateRenderer, - { - "software", - SDL_RENDERER_SOFTWARE | SDL_RENDERER_TARGETTEXTURE, - 8, - { - SDL_PIXELFORMAT_ARGB8888, - SDL_PIXELFORMAT_ABGR8888, - SDL_PIXELFORMAT_RGBA8888, - SDL_PIXELFORMAT_BGRA8888, - SDL_PIXELFORMAT_RGB888, - SDL_PIXELFORMAT_BGR888, - SDL_PIXELFORMAT_RGB565, - SDL_PIXELFORMAT_RGB555 - }, - 0, - 0} -}; - -typedef struct -{ - SDL_Surface *surface; - SDL_Surface *window; -} SW_RenderData; - - -static SDL_Surface * -SW_ActivateRenderer(SDL_Renderer * renderer) -{ - SW_RenderData *data = (SW_RenderData *) renderer->driverdata; - - if (!data->surface) { - data->surface = data->window; - } - if (!data->surface) { - SDL_Surface *surface = SDL_GetWindowSurface(renderer->window); - if (surface) { - data->surface = data->window = surface; - - SW_UpdateViewport(renderer); - SW_UpdateClipRect(renderer); - } - } - return data->surface; -} - -SDL_Renderer * -SW_CreateRendererForSurface(SDL_Surface * surface) -{ - SDL_Renderer *renderer; - SW_RenderData *data; - - if (!surface) { - SDL_SetError("Can't create renderer for NULL surface"); - return NULL; - } - - renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); - if (!renderer) { - SDL_OutOfMemory(); - return NULL; - } - - data = (SW_RenderData *) SDL_calloc(1, sizeof(*data)); - if (!data) { - SW_DestroyRenderer(renderer); - SDL_OutOfMemory(); - return NULL; - } - data->surface = surface; - data->window = surface; - - renderer->WindowEvent = SW_WindowEvent; - renderer->GetOutputSize = SW_GetOutputSize; - renderer->CreateTexture = SW_CreateTexture; - renderer->SetTextureColorMod = SW_SetTextureColorMod; - renderer->SetTextureAlphaMod = SW_SetTextureAlphaMod; - renderer->SetTextureBlendMode = SW_SetTextureBlendMode; - renderer->UpdateTexture = SW_UpdateTexture; - renderer->LockTexture = SW_LockTexture; - renderer->UnlockTexture = SW_UnlockTexture; - renderer->SetRenderTarget = SW_SetRenderTarget; - renderer->UpdateViewport = SW_UpdateViewport; - renderer->UpdateClipRect = SW_UpdateClipRect; - renderer->RenderClear = SW_RenderClear; - renderer->RenderDrawPoints = SW_RenderDrawPoints; - renderer->RenderDrawLines = SW_RenderDrawLines; - renderer->RenderFillRects = SW_RenderFillRects; - renderer->RenderCopy = SW_RenderCopy; - renderer->RenderCopyEx = SW_RenderCopyEx; - renderer->RenderReadPixels = SW_RenderReadPixels; - renderer->RenderPresent = SW_RenderPresent; - renderer->DestroyTexture = SW_DestroyTexture; - renderer->DestroyRenderer = SW_DestroyRenderer; - renderer->info = SW_RenderDriver.info; - renderer->driverdata = data; - - SW_ActivateRenderer(renderer); - - return renderer; -} - -SDL_Renderer * -SW_CreateRenderer(SDL_Window * window, Uint32 flags) -{ - SDL_Surface *surface; - - surface = SDL_GetWindowSurface(window); - if (!surface) { - return NULL; - } - return SW_CreateRendererForSurface(surface); -} - -static void -SW_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event) -{ - SW_RenderData *data = (SW_RenderData *) renderer->driverdata; - - if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) { - data->surface = NULL; - data->window = NULL; - } -} - -static int -SW_GetOutputSize(SDL_Renderer * renderer, int *w, int *h) -{ - SDL_Surface *surface = SW_ActivateRenderer(renderer); - - if (surface) { - if (w) { - *w = surface->w; - } - if (h) { - *h = surface->h; - } - return 0; - } else { - SDL_SetError("Software renderer doesn't have an output surface"); - return -1; - } -} - -static int -SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - int bpp; - Uint32 Rmask, Gmask, Bmask, Amask; - - if (!SDL_PixelFormatEnumToMasks - (texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { - return SDL_SetError("Unknown texture format"); - } - - texture->driverdata = - SDL_CreateRGBSurface(0, texture->w, texture->h, bpp, Rmask, Gmask, - Bmask, Amask); - SDL_SetSurfaceColorMod(texture->driverdata, texture->r, texture->g, - texture->b); - SDL_SetSurfaceAlphaMod(texture->driverdata, texture->a); - SDL_SetSurfaceBlendMode(texture->driverdata, texture->blendMode); - - if (texture->access == SDL_TEXTUREACCESS_STATIC) { - SDL_SetSurfaceRLE(texture->driverdata, 1); - } - - if (!texture->driverdata) { - return -1; - } - return 0; -} - -static int -SW_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture) -{ - SDL_Surface *surface = (SDL_Surface *) texture->driverdata; - /* If the color mod is ever enabled (non-white), permanently disable RLE (which doesn't support - * color mod) to avoid potentially frequent RLE encoding/decoding. - */ - if ((texture->r & texture->g & texture->b) != 255) { - SDL_SetSurfaceRLE(surface, 0); - } - return SDL_SetSurfaceColorMod(surface, texture->r, texture->g, - texture->b); -} - -static int -SW_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture) -{ - SDL_Surface *surface = (SDL_Surface *) texture->driverdata; - /* If the texture ever has multiple alpha values (surface alpha plus alpha channel), permanently - * disable RLE (which doesn't support this) to avoid potentially frequent RLE encoding/decoding. - */ - if (texture->a != 255 && surface->format->Amask) { - SDL_SetSurfaceRLE(surface, 0); - } - return SDL_SetSurfaceAlphaMod(surface, texture->a); -} - -static int -SW_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture) -{ - SDL_Surface *surface = (SDL_Surface *) texture->driverdata; - /* If add or mod blending are ever enabled, permanently disable RLE (which doesn't support - * them) to avoid potentially frequent RLE encoding/decoding. - */ - if ((texture->blendMode == SDL_BLENDMODE_ADD || texture->blendMode == SDL_BLENDMODE_MOD)) { - SDL_SetSurfaceRLE(surface, 0); - } - return SDL_SetSurfaceBlendMode(surface, texture->blendMode); -} - -static int -SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, const void *pixels, int pitch) -{ - SDL_Surface *surface = (SDL_Surface *) texture->driverdata; - Uint8 *src, *dst; - int row; - size_t length; - - if(SDL_MUSTLOCK(surface)) - SDL_LockSurface(surface); - src = (Uint8 *) pixels; - dst = (Uint8 *) surface->pixels + - rect->y * surface->pitch + - rect->x * surface->format->BytesPerPixel; - length = rect->w * surface->format->BytesPerPixel; - for (row = 0; row < rect->h; ++row) { - SDL_memcpy(dst, src, length); - src += pitch; - dst += surface->pitch; - } - if(SDL_MUSTLOCK(surface)) - SDL_UnlockSurface(surface); - return 0; -} - -static int -SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, void **pixels, int *pitch) -{ - SDL_Surface *surface = (SDL_Surface *) texture->driverdata; - - *pixels = - (void *) ((Uint8 *) surface->pixels + rect->y * surface->pitch + - rect->x * surface->format->BytesPerPixel); - *pitch = surface->pitch; - return 0; -} - -static void -SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ -} - -static int -SW_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture) -{ - SW_RenderData *data = (SW_RenderData *) renderer->driverdata; - - if (texture ) { - data->surface = (SDL_Surface *) texture->driverdata; - } else { - data->surface = data->window; - } - return 0; -} - -static int -SW_UpdateViewport(SDL_Renderer * renderer) -{ - SW_RenderData *data = (SW_RenderData *) renderer->driverdata; - SDL_Surface *surface = data->surface; - - if (!surface) { - /* We'll update the viewport after we recreate the surface */ - return 0; - } - - SDL_SetClipRect(data->surface, &renderer->viewport); - return 0; -} - -static int -SW_UpdateClipRect(SDL_Renderer * renderer) -{ - SW_RenderData *data = (SW_RenderData *) renderer->driverdata; - SDL_Surface *surface = data->surface; - if (surface) { - if (renderer->clipping_enabled) { - SDL_SetClipRect(surface, &renderer->clip_rect); - } else { - SDL_SetClipRect(surface, NULL); - } - } - return 0; -} - -static int -SW_RenderClear(SDL_Renderer * renderer) -{ - SDL_Surface *surface = SW_ActivateRenderer(renderer); - Uint32 color; - SDL_Rect clip_rect; - - if (!surface) { - return -1; - } - - color = SDL_MapRGBA(surface->format, - renderer->r, renderer->g, renderer->b, renderer->a); - - /* By definition the clear ignores the clip rect */ - clip_rect = surface->clip_rect; - SDL_SetClipRect(surface, NULL); - SDL_FillRect(surface, NULL, color); - SDL_SetClipRect(surface, &clip_rect); - return 0; -} - -static int -SW_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points, - int count) -{ - SDL_Surface *surface = SW_ActivateRenderer(renderer); - SDL_Point *final_points; - int i, status; - - if (!surface) { - return -1; - } - - final_points = SDL_stack_alloc(SDL_Point, count); - if (!final_points) { - return SDL_OutOfMemory(); - } - if (renderer->viewport.x || renderer->viewport.y) { - int x = renderer->viewport.x; - int y = renderer->viewport.y; - - for (i = 0; i < count; ++i) { - final_points[i].x = (int)(x + points[i].x); - final_points[i].y = (int)(y + points[i].y); - } - } else { - for (i = 0; i < count; ++i) { - final_points[i].x = (int)points[i].x; - final_points[i].y = (int)points[i].y; - } - } - - /* Draw the points! */ - if (renderer->blendMode == SDL_BLENDMODE_NONE) { - Uint32 color = SDL_MapRGBA(surface->format, - renderer->r, renderer->g, renderer->b, - renderer->a); - - status = SDL_DrawPoints(surface, final_points, count, color); - } else { - status = SDL_BlendPoints(surface, final_points, count, - renderer->blendMode, - renderer->r, renderer->g, renderer->b, - renderer->a); - } - SDL_stack_free(final_points); - - return status; -} - -static int -SW_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points, - int count) -{ - SDL_Surface *surface = SW_ActivateRenderer(renderer); - SDL_Point *final_points; - int i, status; - - if (!surface) { - return -1; - } - - final_points = SDL_stack_alloc(SDL_Point, count); - if (!final_points) { - return SDL_OutOfMemory(); - } - if (renderer->viewport.x || renderer->viewport.y) { - int x = renderer->viewport.x; - int y = renderer->viewport.y; - - for (i = 0; i < count; ++i) { - final_points[i].x = (int)(x + points[i].x); - final_points[i].y = (int)(y + points[i].y); - } - } else { - for (i = 0; i < count; ++i) { - final_points[i].x = (int)points[i].x; - final_points[i].y = (int)points[i].y; - } - } - - /* Draw the lines! */ - if (renderer->blendMode == SDL_BLENDMODE_NONE) { - Uint32 color = SDL_MapRGBA(surface->format, - renderer->r, renderer->g, renderer->b, - renderer->a); - - status = SDL_DrawLines(surface, final_points, count, color); - } else { - status = SDL_BlendLines(surface, final_points, count, - renderer->blendMode, - renderer->r, renderer->g, renderer->b, - renderer->a); - } - SDL_stack_free(final_points); - - return status; -} - -static int -SW_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects, int count) -{ - SDL_Surface *surface = SW_ActivateRenderer(renderer); - SDL_Rect *final_rects; - int i, status; - - if (!surface) { - return -1; - } - - final_rects = SDL_stack_alloc(SDL_Rect, count); - if (!final_rects) { - return SDL_OutOfMemory(); - } - if (renderer->viewport.x || renderer->viewport.y) { - int x = renderer->viewport.x; - int y = renderer->viewport.y; - - for (i = 0; i < count; ++i) { - final_rects[i].x = (int)(x + rects[i].x); - final_rects[i].y = (int)(y + rects[i].y); - final_rects[i].w = SDL_max((int)rects[i].w, 1); - final_rects[i].h = SDL_max((int)rects[i].h, 1); - } - } else { - for (i = 0; i < count; ++i) { - final_rects[i].x = (int)rects[i].x; - final_rects[i].y = (int)rects[i].y; - final_rects[i].w = SDL_max((int)rects[i].w, 1); - final_rects[i].h = SDL_max((int)rects[i].h, 1); - } - } - - if (renderer->blendMode == SDL_BLENDMODE_NONE) { - Uint32 color = SDL_MapRGBA(surface->format, - renderer->r, renderer->g, renderer->b, - renderer->a); - status = SDL_FillRects(surface, final_rects, count, color); - } else { - status = SDL_BlendFillRects(surface, final_rects, count, - renderer->blendMode, - renderer->r, renderer->g, renderer->b, - renderer->a); - } - SDL_stack_free(final_rects); - - return status; -} - -static int -SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_FRect * dstrect) -{ - SDL_Surface *surface = SW_ActivateRenderer(renderer); - SDL_Surface *src = (SDL_Surface *) texture->driverdata; - SDL_Rect final_rect; - - if (!surface) { - return -1; - } - - if (renderer->viewport.x || renderer->viewport.y) { - final_rect.x = (int)(renderer->viewport.x + dstrect->x); - final_rect.y = (int)(renderer->viewport.y + dstrect->y); - } else { - final_rect.x = (int)dstrect->x; - final_rect.y = (int)dstrect->y; - } - final_rect.w = (int)dstrect->w; - final_rect.h = (int)dstrect->h; - - if ( srcrect->w == final_rect.w && srcrect->h == final_rect.h ) { - return SDL_BlitSurface(src, srcrect, surface, &final_rect); - } else { - /* If scaling is ever done, permanently disable RLE (which doesn't support scaling) - * to avoid potentially frequent RLE encoding/decoding. - */ - SDL_SetSurfaceRLE(surface, 0); - return SDL_BlitScaled(src, srcrect, surface, &final_rect); - } -} - -static int -GetScaleQuality(void) -{ - const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY); - - if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) { - return 0; - } else { - return 1; - } -} - -static int -SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_FRect * dstrect, - const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip) -{ - SDL_Surface *surface = SW_ActivateRenderer(renderer); - SDL_Surface *src = (SDL_Surface *) texture->driverdata; - SDL_Rect final_rect, tmp_rect; - SDL_Surface *surface_rotated, *surface_scaled; - int retval, dstwidth, dstheight, abscenterx, abscentery; - double cangle, sangle, px, py, p1x, p1y, p2x, p2y, p3x, p3y, p4x, p4y; - - if (!surface) { - return -1; - } - - if (renderer->viewport.x || renderer->viewport.y) { - final_rect.x = (int)(renderer->viewport.x + dstrect->x); - final_rect.y = (int)(renderer->viewport.y + dstrect->y); - } else { - final_rect.x = (int)dstrect->x; - final_rect.y = (int)dstrect->y; - } - final_rect.w = (int)dstrect->w; - final_rect.h = (int)dstrect->h; - - /* SDLgfx_rotateSurface doesn't accept a source rectangle, so crop and scale if we need to */ - tmp_rect = final_rect; - tmp_rect.x = 0; - tmp_rect.y = 0; - if (srcrect->w == final_rect.w && srcrect->h == final_rect.h && srcrect->x == 0 && srcrect->y == 0) { - surface_scaled = src; /* but if we don't need to, just use the original */ - retval = 0; - } else { - SDL_Surface *blit_src = src; - Uint32 colorkey; - SDL_BlendMode blendMode; - Uint8 alphaMod, r, g, b; - SDL_bool cloneSource = SDL_FALSE; - - surface_scaled = SDL_CreateRGBSurface(SDL_SWSURFACE, final_rect.w, final_rect.h, src->format->BitsPerPixel, - src->format->Rmask, src->format->Gmask, - src->format->Bmask, src->format->Amask ); - if (!surface_scaled) { - return -1; - } - - /* copy the color key, alpha mod, blend mode, and color mod so the scaled surface behaves like the source */ - if (SDL_GetColorKey(src, &colorkey) == 0) { - SDL_SetColorKey(surface_scaled, SDL_TRUE, colorkey); - cloneSource = SDL_TRUE; - } - SDL_GetSurfaceAlphaMod(src, &alphaMod); /* these will be copied to surface_scaled below if necessary */ - SDL_GetSurfaceBlendMode(src, &blendMode); - SDL_GetSurfaceColorMod(src, &r, &g, &b); - - /* now we need to blit the src into surface_scaled. since we want to copy the colors from the source to - * surface_scaled rather than blend them, etc. we'll need to disable the blend mode, alpha mod, etc. - * but we don't want to modify src (in case it's being used on other threads), so we'll need to clone it - * before changing the blend options - */ - cloneSource |= blendMode != SDL_BLENDMODE_NONE || (alphaMod & r & g & b) != 255; - if (cloneSource) { - blit_src = SDL_ConvertSurface(src, src->format, src->flags); /* clone src */ - if (!blit_src) { - SDL_FreeSurface(surface_scaled); - return -1; - } - SDL_SetSurfaceAlphaMod(blit_src, 255); /* disable all blending options in blit_src */ - SDL_SetSurfaceBlendMode(blit_src, SDL_BLENDMODE_NONE); - SDL_SetColorKey(blit_src, 0, 0); - SDL_SetSurfaceColorMod(blit_src, 255, 255, 255); - SDL_SetSurfaceRLE(blit_src, 0); /* don't RLE encode a surface we'll only use once */ - - SDL_SetSurfaceAlphaMod(surface_scaled, alphaMod); /* copy blending options to surface_scaled */ - SDL_SetSurfaceBlendMode(surface_scaled, blendMode); - SDL_SetSurfaceColorMod(surface_scaled, r, g, b); - } - - retval = SDL_BlitScaled(blit_src, srcrect, surface_scaled, &tmp_rect); - if (blit_src != src) { - SDL_FreeSurface(blit_src); - } - } - - if (!retval) { - SDLgfx_rotozoomSurfaceSizeTrig(tmp_rect.w, tmp_rect.h, angle, &dstwidth, &dstheight, &cangle, &sangle); - surface_rotated = SDLgfx_rotateSurface(surface_scaled, angle, dstwidth/2, dstheight/2, GetScaleQuality(), flip & SDL_FLIP_HORIZONTAL, flip & SDL_FLIP_VERTICAL, dstwidth, dstheight, cangle, sangle); - if(surface_rotated) { - /* Find out where the new origin is by rotating the four final_rect points around the center and then taking the extremes */ - abscenterx = final_rect.x + (int)center->x; - abscentery = final_rect.y + (int)center->y; - /* Compensate the angle inversion to match the behaviour of the other backends */ - sangle = -sangle; - - /* Top Left */ - px = final_rect.x - abscenterx; - py = final_rect.y - abscentery; - p1x = px * cangle - py * sangle + abscenterx; - p1y = px * sangle + py * cangle + abscentery; - - /* Top Right */ - px = final_rect.x + final_rect.w - abscenterx; - py = final_rect.y - abscentery; - p2x = px * cangle - py * sangle + abscenterx; - p2y = px * sangle + py * cangle + abscentery; - - /* Bottom Left */ - px = final_rect.x - abscenterx; - py = final_rect.y + final_rect.h - abscentery; - p3x = px * cangle - py * sangle + abscenterx; - p3y = px * sangle + py * cangle + abscentery; - - /* Bottom Right */ - px = final_rect.x + final_rect.w - abscenterx; - py = final_rect.y + final_rect.h - abscentery; - p4x = px * cangle - py * sangle + abscenterx; - p4y = px * sangle + py * cangle + abscentery; - - tmp_rect.x = (int)MIN(MIN(p1x, p2x), MIN(p3x, p4x)); - tmp_rect.y = (int)MIN(MIN(p1y, p2y), MIN(p3y, p4y)); - tmp_rect.w = dstwidth; - tmp_rect.h = dstheight; - - retval = SDL_BlitSurface(surface_rotated, NULL, surface, &tmp_rect); - SDL_FreeSurface(surface_rotated); - } - } - - if (surface_scaled != src) { - SDL_FreeSurface(surface_scaled); - } - return retval; -} - -static int -SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, - Uint32 format, void * pixels, int pitch) -{ - SDL_Surface *surface = SW_ActivateRenderer(renderer); - Uint32 src_format; - void *src_pixels; - SDL_Rect final_rect; - - if (!surface) { - return -1; - } - - if (renderer->viewport.x || renderer->viewport.y) { - final_rect.x = renderer->viewport.x + rect->x; - final_rect.y = renderer->viewport.y + rect->y; - final_rect.w = rect->w; - final_rect.h = rect->h; - rect = &final_rect; - } - - if (rect->x < 0 || rect->x+rect->w > surface->w || - rect->y < 0 || rect->y+rect->h > surface->h) { - return SDL_SetError("Tried to read outside of surface bounds"); - } - - src_format = surface->format->format; - src_pixels = (void*)((Uint8 *) surface->pixels + - rect->y * surface->pitch + - rect->x * surface->format->BytesPerPixel); - - return SDL_ConvertPixels(rect->w, rect->h, - src_format, src_pixels, surface->pitch, - format, pixels, pitch); -} - -static void -SW_RenderPresent(SDL_Renderer * renderer) -{ - SDL_Window *window = renderer->window; - - if (window) { - SDL_UpdateWindowSurface(window); - } -} - -static void -SW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - SDL_Surface *surface = (SDL_Surface *) texture->driverdata; - - SDL_FreeSurface(surface); -} - -static void -SW_DestroyRenderer(SDL_Renderer * renderer) -{ - SW_RenderData *data = (SW_RenderData *) renderer->driverdata; - - SDL_free(data); - SDL_free(renderer); -} - -#endif /* !SDL_RENDER_DISABLED */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/software/SDL_render_sw_c.h b/3rdparty/SDL2/src/render/software/SDL_render_sw_c.h deleted file mode 100644 index 89b4e8acc4e..00000000000 --- a/3rdparty/SDL2/src/render/software/SDL_render_sw_c.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -extern SDL_Renderer * SW_CreateRendererForSurface(SDL_Surface * surface); - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/3rdparty/SDL2/src/render/software/SDL_rotate.c b/3rdparty/SDL2/src/render/software/SDL_rotate.c deleted file mode 100644 index 0141d174d9f..00000000000 --- a/3rdparty/SDL2/src/render/software/SDL_rotate.c +++ /dev/null @@ -1,579 +0,0 @@ -/* - -SDL_rotate.c: rotates 32bit or 8bit surfaces - -Shamelessly stolen from SDL_gfx by Andreas Schiffler. Original copyright follows: - -Copyright (C) 2001-2011 Andreas Schiffler - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source - distribution. - -Andreas Schiffler -- aschiffler at ferzkopp dot net - -*/ -#include "../../SDL_internal.h" - -#if defined(__WIN32__) -#include "../../core/windows/SDL_windows.h" -#endif - -#include <stdlib.h> -#include <string.h> - -#include "SDL.h" -#include "SDL_rotate.h" - -/* ---- Internally used structures */ - -/* ! -\brief A 32 bit RGBA pixel. -*/ -typedef struct tColorRGBA { - Uint8 r; - Uint8 g; - Uint8 b; - Uint8 a; -} tColorRGBA; - -/* ! -\brief A 8bit Y/palette pixel. -*/ -typedef struct tColorY { - Uint8 y; -} tColorY; - -/* ! -\brief Returns maximum of two numbers a and b. -*/ -#define MAX(a,b) (((a) > (b)) ? (a) : (b)) - -/* ! -\brief Number of guard rows added to destination surfaces. - -This is a simple but effective workaround for observed issues. -These rows allocate extra memory and are then hidden from the surface. -Rows are added to the end of destination surfaces when they are allocated. -This catches any potential overflows which seem to happen with -just the right src image dimensions and scale/rotation and can lead -to a situation where the program can segfault. -*/ -#define GUARD_ROWS (2) - -/* ! -\brief Lower limit of absolute zoom factor or rotation degrees. -*/ -#define VALUE_LIMIT 0.001 - -/* ! -\brief Returns colorkey info for a surface -*/ -static Uint32 -_colorkey(SDL_Surface *src) -{ - Uint32 key = 0; - SDL_GetColorKey(src, &key); - return key; -} - - -/* ! -\brief Internal target surface sizing function for rotations with trig result return. - -\param width The source surface width. -\param height The source surface height. -\param angle The angle to rotate in degrees. -\param dstwidth The calculated width of the destination surface. -\param dstheight The calculated height of the destination surface. -\param cangle The sine of the angle -\param sangle The cosine of the angle - -*/ -void -SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, - int *dstwidth, int *dstheight, - double *cangle, double *sangle) -{ - /* The trig code below gets the wrong size (due to FP inaccuracy?) when angle is a multiple of 90 degrees */ - int angle90 = (int)(angle/90); - if(angle90 == angle/90) { /* if the angle is a multiple of 90 degrees */ - angle90 %= 4; - if(angle90 < 0) angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */ - if(angle90 & 1) { - *dstwidth = height; - *dstheight = width; - *cangle = 0; - *sangle = angle90 == 1 ? -1 : 1; /* reversed because our rotations are clockwise */ - } else { - *dstwidth = width; - *dstheight = height; - *cangle = angle90 == 0 ? 1 : -1; - *sangle = 0; - } - } else { - double x, y, cx, cy, sx, sy; - double radangle; - int dstwidthhalf, dstheighthalf; - /* - * Determine destination width and height by rotating a centered source box - */ - radangle = angle * (M_PI / -180.0); /* reverse the angle because our rotations are clockwise */ - *sangle = SDL_sin(radangle); - *cangle = SDL_cos(radangle); - x = (double)(width / 2); - y = (double)(height / 2); - cx = *cangle * x; - cy = *cangle * y; - sx = *sangle * x; - sy = *sangle * y; - - dstwidthhalf = MAX((int) - SDL_ceil(MAX(MAX(MAX(SDL_fabs(cx + sy), SDL_fabs(cx - sy)), SDL_fabs(-cx + sy)), SDL_fabs(-cx - sy))), 1); - dstheighthalf = MAX((int) - SDL_ceil(MAX(MAX(MAX(SDL_fabs(sx + cy), SDL_fabs(sx - cy)), SDL_fabs(-sx + cy)), SDL_fabs(-sx - cy))), 1); - *dstwidth = 2 * dstwidthhalf; - *dstheight = 2 * dstheighthalf; - } -} - -/* Computes source pointer X/Y increments for a rotation that's a multiple of 90 degrees. */ -static void -computeSourceIncrements90(SDL_Surface * src, int bpp, int angle, int flipx, int flipy, - int *sincx, int *sincy, int *signx, int *signy) -{ - int pitch = flipy ? -src->pitch : src->pitch; - if (flipx) { - bpp = -bpp; - } - switch (angle) { /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */ - case 0: *sincx = bpp; *sincy = pitch - src->w * *sincx; *signx = *signy = 1; break; - case 1: *sincx = -pitch; *sincy = bpp - *sincx * src->h; *signx = 1; *signy = -1; break; - case 2: *sincx = -bpp; *sincy = -src->w * *sincx - pitch; *signx = *signy = -1; break; - case 3: default: *sincx = pitch; *sincy = -*sincx * src->h - bpp; *signx = -1; *signy = 1; break; - } - if (flipx) { - *signx = -*signx; - } - if (flipy) { - *signy = -*signy; - } -} - -/* Performs a relatively fast rotation/flip when the angle is a multiple of 90 degrees. */ -#define TRANSFORM_SURFACE_90(pixelType) \ - int dy, dincy = dst->pitch - dst->w*sizeof(pixelType), sincx, sincy, signx, signy; \ - Uint8 *sp = (Uint8*)src->pixels, *dp = (Uint8*)dst->pixels, *de; \ - \ - computeSourceIncrements90(src, sizeof(pixelType), angle, flipx, flipy, &sincx, &sincy, &signx, &signy); \ - if (signx < 0) sp += (src->w-1)*sizeof(pixelType); \ - if (signy < 0) sp += (src->h-1)*src->pitch; \ - \ - for (dy = 0; dy < dst->h; sp += sincy, dp += dincy, dy++) { \ - if (sincx == sizeof(pixelType)) { /* if advancing src and dest equally, use memcpy */ \ - SDL_memcpy(dp, sp, dst->w*sizeof(pixelType)); \ - sp += dst->w*sizeof(pixelType); \ - dp += dst->w*sizeof(pixelType); \ - } else { \ - for (de = dp + dst->w*sizeof(pixelType); dp != de; sp += sincx, dp += sizeof(pixelType)) { \ - *(pixelType*)dp = *(pixelType*)sp; \ - } \ - } \ - } - -static void -transformSurfaceRGBA90(SDL_Surface * src, SDL_Surface * dst, int angle, int flipx, int flipy) -{ - TRANSFORM_SURFACE_90(tColorRGBA); -} - -static void -transformSurfaceY90(SDL_Surface * src, SDL_Surface * dst, int angle, int flipx, int flipy) -{ - TRANSFORM_SURFACE_90(tColorY); -} - -#undef TRANSFORM_SURFACE_90 - -/* ! -\brief Internal 32 bit rotozoomer with optional anti-aliasing. - -Rotates and zooms 32 bit RGBA/ABGR 'src' surface to 'dst' surface based on the control -parameters by scanning the destination surface and applying optionally anti-aliasing -by bilinear interpolation. -Assumes src and dst surfaces are of 32 bit depth. -Assumes dst surface was allocated with the correct dimensions. - -\param src Source surface. -\param dst Destination surface. -\param cx Horizontal center coordinate. -\param cy Vertical center coordinate. -\param isin Integer version of sine of angle. -\param icos Integer version of cosine of angle. -\param flipx Flag indicating horizontal mirroring should be applied. -\param flipy Flag indicating vertical mirroring should be applied. -\param smooth Flag indicating anti-aliasing should be used. -*/ -static void -_transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos, int flipx, int flipy, int smooth) -{ - int x, y, t1, t2, dx, dy, xd, yd, sdx, sdy, ax, ay, ex, ey, sw, sh; - tColorRGBA c00, c01, c10, c11, cswap; - tColorRGBA *pc, *sp; - int gap; - - /* - * Variable setup - */ - xd = ((src->w - dst->w) << 15); - yd = ((src->h - dst->h) << 15); - ax = (cx << 16) - (icos * cx); - ay = (cy << 16) - (isin * cx); - sw = src->w - 1; - sh = src->h - 1; - pc = (tColorRGBA*) dst->pixels; - gap = dst->pitch - dst->w * 4; - - /* - * Switch between interpolating and non-interpolating code - */ - if (smooth) { - for (y = 0; y < dst->h; y++) { - dy = cy - y; - sdx = (ax + (isin * dy)) + xd; - sdy = (ay - (icos * dy)) + yd; - for (x = 0; x < dst->w; x++) { - dx = (sdx >> 16); - dy = (sdy >> 16); - if (flipx) dx = sw - dx; - if (flipy) dy = sh - dy; - if ((unsigned)dx < (unsigned)sw && (unsigned)dy < (unsigned)sh) { - sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy) + dx; - c00 = *sp; - sp += 1; - c01 = *sp; - sp += (src->pitch/4); - c11 = *sp; - sp -= 1; - c10 = *sp; - if (flipx) { - cswap = c00; c00=c01; c01=cswap; - cswap = c10; c10=c11; c11=cswap; - } - if (flipy) { - cswap = c00; c00=c10; c10=cswap; - cswap = c01; c01=c11; c11=cswap; - } - /* - * Interpolate colors - */ - ex = (sdx & 0xffff); - ey = (sdy & 0xffff); - t1 = ((((c01.r - c00.r) * ex) >> 16) + c00.r) & 0xff; - t2 = ((((c11.r - c10.r) * ex) >> 16) + c10.r) & 0xff; - pc->r = (((t2 - t1) * ey) >> 16) + t1; - t1 = ((((c01.g - c00.g) * ex) >> 16) + c00.g) & 0xff; - t2 = ((((c11.g - c10.g) * ex) >> 16) + c10.g) & 0xff; - pc->g = (((t2 - t1) * ey) >> 16) + t1; - t1 = ((((c01.b - c00.b) * ex) >> 16) + c00.b) & 0xff; - t2 = ((((c11.b - c10.b) * ex) >> 16) + c10.b) & 0xff; - pc->b = (((t2 - t1) * ey) >> 16) + t1; - t1 = ((((c01.a - c00.a) * ex) >> 16) + c00.a) & 0xff; - t2 = ((((c11.a - c10.a) * ex) >> 16) + c10.a) & 0xff; - pc->a = (((t2 - t1) * ey) >> 16) + t1; - } - sdx += icos; - sdy += isin; - pc++; - } - pc = (tColorRGBA *) ((Uint8 *) pc + gap); - } - } else { - for (y = 0; y < dst->h; y++) { - dy = cy - y; - sdx = (ax + (isin * dy)) + xd; - sdy = (ay - (icos * dy)) + yd; - for (x = 0; x < dst->w; x++) { - dx = (sdx >> 16); - dy = (sdy >> 16); - if ((unsigned)dx < (unsigned)src->w && (unsigned)dy < (unsigned)src->h) { - if(flipx) dx = sw - dx; - if(flipy) dy = sh - dy; - *pc = *((tColorRGBA *)((Uint8 *)src->pixels + src->pitch * dy) + dx); - } - sdx += icos; - sdy += isin; - pc++; - } - pc = (tColorRGBA *) ((Uint8 *) pc + gap); - } - } -} - -/* ! - -\brief Rotates and zooms 8 bit palette/Y 'src' surface to 'dst' surface without smoothing. - -Rotates and zooms 8 bit RGBA/ABGR 'src' surface to 'dst' surface based on the control -parameters by scanning the destination surface. -Assumes src and dst surfaces are of 8 bit depth. -Assumes dst surface was allocated with the correct dimensions. - -\param src Source surface. -\param dst Destination surface. -\param cx Horizontal center coordinate. -\param cy Vertical center coordinate. -\param isin Integer version of sine of angle. -\param icos Integer version of cosine of angle. -\param flipx Flag indicating horizontal mirroring should be applied. -\param flipy Flag indicating vertical mirroring should be applied. -*/ -static void -transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos, int flipx, int flipy) -{ - int x, y, dx, dy, xd, yd, sdx, sdy, ax, ay; - tColorY *pc; - int gap; - - /* - * Variable setup - */ - xd = ((src->w - dst->w) << 15); - yd = ((src->h - dst->h) << 15); - ax = (cx << 16) - (icos * cx); - ay = (cy << 16) - (isin * cx); - pc = (tColorY*) dst->pixels; - gap = dst->pitch - dst->w; - /* - * Clear surface to colorkey - */ - SDL_memset(pc, (int)(_colorkey(src) & 0xff), dst->pitch * dst->h); - /* - * Iterate through destination surface - */ - for (y = 0; y < dst->h; y++) { - dy = cy - y; - sdx = (ax + (isin * dy)) + xd; - sdy = (ay - (icos * dy)) + yd; - for (x = 0; x < dst->w; x++) { - dx = (sdx >> 16); - dy = (sdy >> 16); - if ((unsigned)dx < (unsigned)src->w && (unsigned)dy < (unsigned)src->h) { - if (flipx) dx = (src->w-1)-dx; - if (flipy) dy = (src->h-1)-dy; - *pc = *((tColorY *)src->pixels + src->pitch * dy + dx); - } - sdx += icos; - sdy += isin; - pc++; - } - pc += gap; - } -} - - -/* ! -\brief Rotates and zooms a surface with different horizontal and vertival scaling factors and optional anti-aliasing. - -Rotates a 32bit or 8bit 'src' surface to newly created 'dst' surface. -'angle' is the rotation in degrees, 'centerx' and 'centery' the rotation center. If 'smooth' is set -then the destination 32bit surface is anti-aliased. If the surface is not 8bit -or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly. - -\param src The surface to rotozoom. -\param angle The angle to rotate in degrees. -\param centerx The horizontal coordinate of the center of rotation -\param zoomy The vertical coordinate of the center of rotation -\param smooth Antialiasing flag; set to SMOOTHING_ON to enable. -\param flipx Set to 1 to flip the image horizontally -\param flipy Set to 1 to flip the image vertically -\param dstwidth The destination surface width -\param dstheight The destination surface height -\param cangle The angle cosine -\param sangle The angle sine -\return The new rotated surface. - -*/ - -SDL_Surface * -SDLgfx_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery, int smooth, int flipx, int flipy, int dstwidth, int dstheight, double cangle, double sangle) -{ - SDL_Surface *rz_src; - SDL_Surface *rz_dst; - int is32bit, angle90; - int i; - Uint8 r = 0, g = 0, b = 0; - Uint32 colorkey = 0; - int colorKeyAvailable = 0; - double sangleinv, cangleinv; - - /* - * Sanity check - */ - if (src == NULL) - return (NULL); - - if (src->flags & SDL_TRUE/* SDL_SRCCOLORKEY */) - { - colorkey = _colorkey(src); - SDL_GetRGB(colorkey, src->format, &r, &g, &b); - colorKeyAvailable = 1; - } - /* - * Determine if source surface is 32bit or 8bit - */ - is32bit = (src->format->BitsPerPixel == 32); - if ((is32bit) || (src->format->BitsPerPixel == 8)) { - /* - * Use source surface 'as is' - */ - rz_src = src; - } else { - rz_src = SDL_ConvertSurfaceFormat(src, SDL_PIXELFORMAT_ARGB32, src->flags); - if (rz_src == NULL) { - return NULL; - } - is32bit = 1; - } - - /* Determine target size */ - /* _rotozoomSurfaceSizeTrig(rz_src->w, rz_src->h, angle, &dstwidth, &dstheight, &cangle, &sangle); */ - - /* - * Calculate target factors from sin/cos and zoom - */ - sangleinv = sangle*65536.0; - cangleinv = cangle*65536.0; - - /* - * Alloc space to completely contain the rotated surface - */ - if (is32bit) { - /* - * Target surface is 32bit with source RGBA/ABGR ordering - */ - rz_dst = - SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight + GUARD_ROWS, 32, - rz_src->format->Rmask, rz_src->format->Gmask, - rz_src->format->Bmask, rz_src->format->Amask); - } else { - /* - * Target surface is 8bit - */ - rz_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight + GUARD_ROWS, 8, 0, 0, 0, 0); - } - - /* Check target */ - if (rz_dst == NULL) - return NULL; - - /* Adjust for guard rows */ - rz_dst->h = dstheight; - - if (colorKeyAvailable == 1){ - colorkey = SDL_MapRGB(rz_dst->format, r, g, b); - - SDL_FillRect(rz_dst, NULL, colorkey ); - } - - /* - * Lock source surface - */ - if (SDL_MUSTLOCK(rz_src)) { - SDL_LockSurface(rz_src); - } - - /* check if the rotation is a multiple of 90 degrees so we can take a fast path and also somewhat reduce - * the off-by-one problem in _transformSurfaceRGBA that expresses itself when the rotation is near - * multiples of 90 degrees. - */ - angle90 = (int)(angle/90); - if (angle90 == angle/90) { - angle90 %= 4; - if (angle90 < 0) angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */ - } else { - angle90 = -1; - } - - /* - * Check which kind of surface we have - */ - if (is32bit) { - /* - * Call the 32bit transformation routine to do the rotation (using alpha) - */ - if (angle90 >= 0) { - transformSurfaceRGBA90(rz_src, rz_dst, angle90, flipx, flipy); - } else { - _transformSurfaceRGBA(rz_src, rz_dst, centerx, centery, (int) (sangleinv), (int) (cangleinv), flipx, flipy, smooth); - } - /* - * Turn on source-alpha support - */ - /* SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255); */ - SDL_SetColorKey(rz_dst, /* SDL_SRCCOLORKEY */ SDL_TRUE | SDL_RLEACCEL, _colorkey(rz_src)); - } else { - /* - * Copy palette and colorkey info - */ - for (i = 0; i < rz_src->format->palette->ncolors; i++) { - rz_dst->format->palette->colors[i] = rz_src->format->palette->colors[i]; - } - rz_dst->format->palette->ncolors = rz_src->format->palette->ncolors; - /* - * Call the 8bit transformation routine to do the rotation - */ - if(angle90 >= 0) { - transformSurfaceY90(rz_src, rz_dst, angle90, flipx, flipy); - } else { - transformSurfaceY(rz_src, rz_dst, centerx, centery, (int)(sangleinv), (int)(cangleinv), flipx, flipy); - } - SDL_SetColorKey(rz_dst, /* SDL_SRCCOLORKEY */ SDL_TRUE | SDL_RLEACCEL, _colorkey(rz_src)); - } - - /* copy alpha mod, color mod, and blend mode */ - { - SDL_BlendMode blendMode; - Uint8 alphaMod, cr, cg, cb; - SDL_GetSurfaceAlphaMod(src, &alphaMod); - SDL_GetSurfaceBlendMode(src, &blendMode); - SDL_GetSurfaceColorMod(src, &cr, &cg, &cb); - SDL_SetSurfaceAlphaMod(rz_dst, alphaMod); - SDL_SetSurfaceBlendMode(rz_dst, blendMode); - SDL_SetSurfaceColorMod(rz_dst, cr, cg, cb); - } - - /* - * Unlock source surface - */ - if (SDL_MUSTLOCK(rz_src)) { - SDL_UnlockSurface(rz_src); - } - - /* - * Cleanup temp surface - */ - if (rz_src != src) { - SDL_FreeSurface(rz_src); - } - - /* - * Return destination surface - */ - return (rz_dst); -} diff --git a/3rdparty/SDL2/src/render/software/SDL_rotate.h b/3rdparty/SDL2/src/render/software/SDL_rotate.h deleted file mode 100644 index 338109fc053..00000000000 --- a/3rdparty/SDL2/src/render/software/SDL_rotate.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -#ifndef MIN -#define MIN(a,b) (((a) < (b)) ? (a) : (b)) -#endif - -extern SDL_Surface *SDLgfx_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery, int smooth, int flipx, int flipy, int dstwidth, int dstheight, double cangle, double sangle); -extern void SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, int *dstwidth, int *dstheight, double *cangle, double *sangle); - |