Update SDL to version 2.0.10.

This commit is contained in:
Alex Szpakowski
2019-07-25 19:13:03 -03:00
parent 7b84b428d5
commit e173593f7c
842 changed files with 14306 additions and 5672 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
+1 -1
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
+126 -59
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@@ -29,6 +29,9 @@
#include "SDL_sysrender.h"
#include "software/SDL_render_sw_c.h"
#if defined(__ANDROID__)
# include "../core/android/SDL_android.h"
#endif
#define SDL_WINDOWRENDERDATA "_SDL_WindowRenderData"
@@ -837,14 +840,18 @@ SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags)
SDL_bool batching = SDL_TRUE;
const char *hint;
#if defined(__ANDROID__)
Android_ActivityMutex_Lock_Running();
#endif
if (!window) {
SDL_SetError("Invalid window");
return NULL;
goto error;
}
if (SDL_GetRenderer(window)) {
SDL_SetError("Renderer already associated with window");
return NULL;
goto error;
}
if (SDL_GetHint(SDL_HINT_RENDER_VSYNC)) {
@@ -888,67 +895,81 @@ SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags)
}
if (index == n) {
SDL_SetError("Couldn't find matching render driver");
return NULL;
goto error;
}
} else {
if (index >= SDL_GetNumRenderDrivers()) {
SDL_SetError("index must be -1 or in the range of 0 - %d",
SDL_GetNumRenderDrivers() - 1);
return NULL;
goto error;
}
/* Create a new renderer instance */
renderer = render_drivers[index]->CreateRenderer(window, flags);
batching = SDL_FALSE;
}
if (renderer) {
VerifyDrawQueueFunctions(renderer);
/* let app/user override batching decisions. */
if (renderer->always_batch) {
batching = SDL_TRUE;
} else if (SDL_GetHint(SDL_HINT_RENDER_BATCHING)) {
batching = SDL_GetHintBoolean(SDL_HINT_RENDER_BATCHING, SDL_TRUE);
}
renderer->batching = batching;
renderer->magic = &renderer_magic;
renderer->window = window;
renderer->target_mutex = SDL_CreateMutex();
renderer->scale.x = 1.0f;
renderer->scale.y = 1.0f;
renderer->dpi_scale.x = 1.0f;
renderer->dpi_scale.y = 1.0f;
/* new textures start at zero, so we start at 1 so first render doesn't flush by accident. */
renderer->render_command_generation = 1;
if (window && renderer->GetOutputSize) {
int window_w, window_h;
int output_w, output_h;
if (renderer->GetOutputSize(renderer, &output_w, &output_h) == 0) {
SDL_GetWindowSize(renderer->window, &window_w, &window_h);
renderer->dpi_scale.x = (float)window_w / output_w;
renderer->dpi_scale.y = (float)window_h / output_h;
}
}
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);
if (!renderer) {
goto error;
}
VerifyDrawQueueFunctions(renderer);
/* let app/user override batching decisions. */
if (renderer->always_batch) {
batching = SDL_TRUE;
} else if (SDL_GetHint(SDL_HINT_RENDER_BATCHING)) {
batching = SDL_GetHintBoolean(SDL_HINT_RENDER_BATCHING, SDL_TRUE);
}
renderer->batching = batching;
renderer->magic = &renderer_magic;
renderer->window = window;
renderer->target_mutex = SDL_CreateMutex();
renderer->scale.x = 1.0f;
renderer->scale.y = 1.0f;
renderer->dpi_scale.x = 1.0f;
renderer->dpi_scale.y = 1.0f;
/* new textures start at zero, so we start at 1 so first render doesn't flush by accident. */
renderer->render_command_generation = 1;
if (window && renderer->GetOutputSize) {
int window_w, window_h;
int output_w, output_h;
if (renderer->GetOutputSize(renderer, &output_w, &output_h) == 0) {
SDL_GetWindowSize(renderer->window, &window_w, &window_h);
renderer->dpi_scale.x = (float)window_w / output_w;
renderer->dpi_scale.y = (float)window_h / output_h;
}
}
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);
#if defined(__ANDROID__)
Android_ActivityMutex_Unlock();
#endif
return renderer;
error:
#if defined(__ANDROID__)
Android_ActivityMutex_Unlock();
#endif
return NULL;
#else
SDL_SetError("SDL not built with rendering support");
return NULL;
@@ -1187,8 +1208,9 @@ SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface)
{
const SDL_PixelFormat *fmt;
SDL_bool needAlpha;
Uint32 i;
Uint32 format;
SDL_bool direct_update;
int i;
Uint32 format = SDL_PIXELFORMAT_UNKNOWN;
SDL_Texture *texture;
CHECK_RENDERER_MAGIC(renderer, NULL);
@@ -1217,12 +1239,43 @@ SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface)
}
}
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;
/* Try to have the best pixel format for the texture */
/* No alpha, but a colorkey => promote to alpha */
if (!fmt->Amask && SDL_HasColorKey(surface)) {
if (fmt->format == SDL_PIXELFORMAT_RGB888) {
for (i = 0; i < (int)renderer->info.num_texture_formats; ++i) {
if (renderer->info.texture_formats[i] == SDL_PIXELFORMAT_ARGB8888) {
format = SDL_PIXELFORMAT_ARGB8888;
break;
}
}
} else if (fmt->format == SDL_PIXELFORMAT_BGR888) {
for (i = 0; i < (int)renderer->info.num_texture_formats; ++i) {
if (renderer->info.texture_formats[i] == SDL_PIXELFORMAT_ABGR8888) {
format = SDL_PIXELFORMAT_ABGR8888;
break;
}
}
}
} else {
/* Exact match would be fine */
for (i = 0; i < (int)renderer->info.num_texture_formats; ++i) {
if (renderer->info.texture_formats[i] == fmt->format) {
format = fmt->format;
break;
}
}
}
/* Fallback, choose a valid pixel format */
if (format == SDL_PIXELFORMAT_UNKNOWN) {
format = renderer->info.texture_formats[0];
for (i = 0; i < (int)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;
}
}
}
@@ -1233,6 +1286,20 @@ SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface)
}
if (format == surface->format->format) {
if (surface->format->Amask && SDL_HasColorKey(surface)) {
/* Surface and Renderer formats are identicals.
* Intermediate conversion is needed to convert color key to alpha (SDL_ConvertColorkeyToAlpha()). */
direct_update = SDL_FALSE;
} else {
/* Update Texture directly */
direct_update = SDL_TRUE;
}
} else {
/* Surface and Renderer formats are differents, it needs an intermediate conversion. */
direct_update = SDL_FALSE;
}
if (direct_update) {
if (SDL_MUSTLOCK(surface)) {
SDL_LockSurface(surface);
SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch);
+1 -1
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
+1 -1
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
+1 -1
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
+35 -15
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@@ -791,7 +791,7 @@ D3D_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_F
const DWORD color = D3DCOLOR_ARGB(cmd->data.draw.a, cmd->data.draw.r, cmd->data.draw.g, cmd->data.draw.b);
const size_t vertslen = count * sizeof (Vertex);
Vertex *verts = (Vertex *) SDL_AllocateRenderVertices(renderer, vertslen, 0, &cmd->data.draw.first);
size_t i;
int i;
if (!verts) {
return -1;
@@ -815,7 +815,7 @@ D3D_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FR
const DWORD color = D3DCOLOR_ARGB(cmd->data.draw.a, cmd->data.draw.r, cmd->data.draw.g, cmd->data.draw.b);
const size_t vertslen = count * sizeof (Vertex) * 4;
Vertex *verts = (Vertex *) SDL_AllocateRenderVertices(renderer, vertslen, 0, &cmd->data.draw.first);
size_t i;
int i;
if (!verts) {
return -1;
@@ -1127,6 +1127,13 @@ SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd)
}
data->drawstate.texture = texture;
} else if (texture) {
D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata;
UpdateDirtyTexture(data->device, &texturedata->texture);
if (texturedata->yuv) {
UpdateDirtyTexture(data->device, &texturedata->utexture);
UpdateDirtyTexture(data->device, &texturedata->vtexture);
}
}
if (blend != data->drawstate.blend) {
@@ -1185,7 +1192,7 @@ SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd)
if (data->drawstate.cliprect_dirty) {
const SDL_Rect *viewport = &data->drawstate.viewport;
const SDL_Rect *rect = &cmd->data.cliprect.rect;
const SDL_Rect *rect = &data->drawstate.cliprect;
const RECT d3drect = { viewport->x + rect->x, viewport->y + rect->y, viewport->x + rect->x + rect->w, viewport->y + rect->y + rect->h };
IDirect3DDevice9_SetScissorRect(data->device, &d3drect);
data->drawstate.cliprect_dirty = SDL_FALSE;
@@ -1216,7 +1223,7 @@ D3D_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *verti
IDirect3DVertexBuffer9_Release(vbo);
}
if (FAILED(IDirect3DDevice9_CreateVertexBuffer(data->device, vertsize, usage, fvf, D3DPOOL_DEFAULT, &vbo, NULL))) {
if (FAILED(IDirect3DDevice9_CreateVertexBuffer(data->device, (UINT) vertsize, usage, fvf, D3DPOOL_DEFAULT, &vbo, NULL))) {
vbo = NULL;
}
data->vertexBuffers[vboidx] = vbo;
@@ -1225,7 +1232,7 @@ D3D_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *verti
if (vbo) {
void *ptr;
if (FAILED(IDirect3DVertexBuffer9_Lock(vbo, 0, vertsize, &ptr, D3DLOCK_DISCARD))) {
if (FAILED(IDirect3DVertexBuffer9_Lock(vbo, 0, (UINT) vertsize, &ptr, D3DLOCK_DISCARD))) {
vbo = NULL; /* oh well, we'll do immediate mode drawing. :( */
} else {
SDL_memcpy(ptr, vertices, vertsize);
@@ -1313,10 +1320,10 @@ D3D_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *verti
const size_t first = cmd->data.draw.first;
SetDrawState(data, cmd);
if (vbo) {
IDirect3DDevice9_DrawPrimitive(data->device, D3DPT_POINTLIST, first / sizeof (Vertex), count);
IDirect3DDevice9_DrawPrimitive(data->device, D3DPT_POINTLIST, (UINT) (first / sizeof (Vertex)), (UINT) count);
} else {
const Vertex *verts = (Vertex *) (((Uint8 *) vertices) + first);
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_POINTLIST, count, verts, sizeof (Vertex));
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_POINTLIST, (UINT) count, verts, sizeof (Vertex));
}
break;
}
@@ -1333,12 +1340,12 @@ D3D_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *verti
SetDrawState(data, cmd);
if (vbo) {
IDirect3DDevice9_DrawPrimitive(data->device, D3DPT_LINESTRIP, first / sizeof (Vertex), count - 1);
IDirect3DDevice9_DrawPrimitive(data->device, D3DPT_LINESTRIP, (UINT) (first / sizeof (Vertex)), (UINT) (count - 1));
if (close_endpoint) {
IDirect3DDevice9_DrawPrimitive(data->device, D3DPT_POINTLIST, (first / sizeof (Vertex)) + (count - 1), 1);
IDirect3DDevice9_DrawPrimitive(data->device, D3DPT_POINTLIST, (UINT) ((first / sizeof (Vertex)) + (count - 1)), 1);
}
} else {
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_LINESTRIP, count - 1, verts, sizeof (Vertex));
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_LINESTRIP, (UINT) (count - 1), verts, sizeof (Vertex));
if (close_endpoint) {
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_POINTLIST, 1, &verts[count-1], sizeof (Vertex));
}
@@ -1353,7 +1360,7 @@ D3D_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *verti
if (vbo) {
size_t offset = 0;
for (i = 0; i < count; ++i, offset += 4) {
IDirect3DDevice9_DrawPrimitive(data->device, D3DPT_TRIANGLEFAN, (first / sizeof (Vertex)) + offset, 2);
IDirect3DDevice9_DrawPrimitive(data->device, D3DPT_TRIANGLEFAN, (UINT) ((first / sizeof (Vertex)) + offset), 2);
}
} else {
const Vertex *verts = (Vertex *) (((Uint8 *) vertices) + first);
@@ -1371,7 +1378,7 @@ D3D_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *verti
if (vbo) {
size_t offset = 0;
for (i = 0; i < count; ++i, offset += 4) {
IDirect3DDevice9_DrawPrimitive(data->device, D3DPT_TRIANGLEFAN, (first / sizeof (Vertex)) + offset, 2);
IDirect3DDevice9_DrawPrimitive(data->device, D3DPT_TRIANGLEFAN, (UINT) ((first / sizeof (Vertex)) + offset), 2);
}
} else {
const Vertex *verts = (Vertex *) (((Uint8 *) vertices) + first);
@@ -1395,7 +1402,7 @@ D3D_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *verti
IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, (D3DMATRIX*)&d3dmatrix);
if (vbo) {
IDirect3DDevice9_DrawPrimitive(data->device, D3DPT_TRIANGLEFAN, first / sizeof (Vertex), 2);
IDirect3DDevice9_DrawPrimitive(data->device, D3DPT_TRIANGLEFAN, (UINT) (first / sizeof (Vertex)), 2);
} else {
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN, 2, verts, sizeof (Vertex));
}
@@ -1501,11 +1508,17 @@ D3D_RenderPresent(SDL_Renderer * renderer)
static void
D3D_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
D3D_RenderData *renderdata = (D3D_RenderData *) renderer->driverdata;
D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
if (renderdata->drawstate.texture == texture) {
renderdata->drawstate.texture = NULL;
}
if (!data) {
return;
}
D3D_DestroyTextureRep(&data->texture);
D3D_DestroyTextureRep(&data->utexture);
D3D_DestroyTextureRep(&data->vtexture);
@@ -1537,6 +1550,13 @@ D3D_DestroyRenderer(SDL_Renderer * renderer)
data->shaders[i] = NULL;
}
}
/* Release all vertex buffers */
for (i = 0; i < SDL_arraysize(data->vertexBuffers); ++i) {
if (data->vertexBuffers[i]) {
IDirect3DVertexBuffer9_Release(data->vertexBuffers[i]);
}
data->vertexBuffers[i] = NULL;
}
if (data->device) {
IDirect3DDevice9_Release(data->device);
data->device = NULL;
@@ -1578,7 +1598,7 @@ D3D_Reset(SDL_Renderer * renderer)
}
}
/* Release all vertex buffers */
/* Release all vertex buffers */
for (i = 0; i < SDL_arraysize(data->vertexBuffers); ++i) {
if (data->vertexBuffers[i]) {
IDirect3DVertexBuffer9_Release(data->vertexBuffers[i]);
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@@ -1559,7 +1559,7 @@ D3D11_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL
const float g = (float)(cmd->data.draw.g / 255.0f);
const float b = (float)(cmd->data.draw.b / 255.0f);
const float a = (float)(cmd->data.draw.a / 255.0f);
size_t i;
int i;
if (!verts) {
return -1;
@@ -1591,7 +1591,7 @@ D3D11_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_
const float g = (float)(cmd->data.draw.g / 255.0f);
const float b = (float)(cmd->data.draw.b / 255.0f);
const float a = (float)(cmd->data.draw.a / 255.0f);
size_t i;
int i;
if (!verts) {
return -1;
@@ -1897,7 +1897,7 @@ D3D11_UpdateViewport(SDL_Renderer * renderer)
* with a non-empty viewport.
*/
/* SDL_Log("%s, no viewport was set!\n", __FUNCTION__); */
return 0;
return -1;
}
/* Make sure the SDL viewport gets rotated to that of the physical display's rotation.
@@ -1997,6 +1997,7 @@ D3D11_SetDrawState(SDL_Renderer * renderer, const SDL_RenderCommand *cmd, ID3D11
ID3D11ShaderResourceView *shaderResource;
const SDL_BlendMode blendMode = cmd->data.draw.blend;
ID3D11BlendState *blendState = NULL;
SDL_bool updateSubresource = SDL_FALSE;
if (renderTargetView != rendererData->currentRenderTargetView) {
ID3D11DeviceContext_OMSetRenderTargets(rendererData->d3dContext,
@@ -2008,7 +2009,10 @@ D3D11_SetDrawState(SDL_Renderer * renderer, const SDL_RenderCommand *cmd, ID3D11
}
if (rendererData->viewportDirty) {
D3D11_UpdateViewport(renderer);
if (D3D11_UpdateViewport(renderer) == 0) {
/* vertexShaderConstantsData.projectionAndView has changed */
updateSubresource = SDL_TRUE;
}
}
if (rendererData->cliprectDirty) {
@@ -2073,7 +2077,7 @@ D3D11_SetDrawState(SDL_Renderer * renderer, const SDL_RenderCommand *cmd, ID3D11
rendererData->currentSampler = sampler;
}
if (SDL_memcmp(&rendererData->vertexShaderConstantsData.model, newmatrix, sizeof (*newmatrix)) != 0) {
if (updateSubresource == SDL_TRUE || SDL_memcmp(&rendererData->vertexShaderConstantsData.model, newmatrix, sizeof (*newmatrix)) != 0) {
SDL_memcpy(&rendererData->vertexShaderConstantsData.model, newmatrix, sizeof (*newmatrix));
ID3D11DeviceContext_UpdateSubresource(rendererData->d3dContext,
(ID3D11Resource *)rendererData->vertexShaderConstants,
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@@ -1733,11 +1733,12 @@ METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
#endif
#else
#ifdef __IPHONE_11_0
if (@available(iOS 11.0, *)) {
if ([mtldevice supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily4_v1]) {
maxtexsize = 16384;
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
if ([mtldevice supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily4_v1]) {
maxtexsize = 16384;
} else
#pragma clang diagnostic pop
#endif
#ifdef __IPHONE_10_0
if ([mtldevice supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily3_v1]) {
+1 -1
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
+43 -10
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@@ -178,7 +178,7 @@ GL_ClearErrors(SDL_Renderer *renderer)
data->errors = 0;
data->error_messages = NULL;
}
} else {
} else if (data->glGetError != NULL) {
while (data->glGetError() != GL_NO_ERROR) {
continue;
}
@@ -234,18 +234,19 @@ GL_LoadFunctions(GL_RenderData * data)
#ifdef __SDL_NOGETPROCADDR__
#define SDL_PROC(ret,func,params) data->func=func;
#else
int retval = 0;
#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", #func, SDL_GetError()); \
retval = SDL_SetError("Couldn't load GL function %s: %s", #func, SDL_GetError()); \
} \
} while ( 0 );
#endif /* __SDL_NOGETPROCADDR__ */
#include "SDL_glfuncs.h"
#undef SDL_PROC
return 0;
return retval;
}
static int
@@ -405,10 +406,17 @@ convert_format(GL_RenderData *renderdata, Uint32 pixel_format,
{
switch (pixel_format) {
case SDL_PIXELFORMAT_ARGB8888:
case SDL_PIXELFORMAT_RGB888:
*internalFormat = GL_RGBA8;
*format = GL_BGRA;
*type = GL_UNSIGNED_INT_8_8_8_8_REV;
break;
case SDL_PIXELFORMAT_ABGR8888:
case SDL_PIXELFORMAT_BGR888:
*internalFormat = GL_RGBA8;
*format = GL_RGBA;
*type = GL_UNSIGNED_INT_8_8_8_8_REV;
break;
case SDL_PIXELFORMAT_YV12:
case SDL_PIXELFORMAT_IYUV:
case SDL_PIXELFORMAT_NV12:
@@ -443,6 +451,8 @@ GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
GL_ActivateRenderer(renderer);
renderdata->drawstate.texture = NULL; /* we trash this state. */
if (texture->access == SDL_TEXTUREACCESS_TARGET &&
!renderdata->GL_EXT_framebuffer_object_supported) {
return SDL_SetError("Render targets not supported by OpenGL");
@@ -641,6 +651,8 @@ GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
GL_ActivateRenderer(renderer);
renderdata->drawstate.texture = NULL; /* we trash this state. */
renderdata->glEnable(textype);
renderdata->glBindTexture(textype, data->texture);
renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
@@ -702,6 +714,8 @@ GL_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
GL_ActivateRenderer(renderer);
renderdata->drawstate.texture = NULL; /* we trash this state. */
renderdata->glEnable(textype);
renderdata->glBindTexture(textype, data->texture);
renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
@@ -767,6 +781,8 @@ GL_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
return SDL_SetError("Render targets not supported by OpenGL");
}
data->drawstate.viewport_dirty = SDL_TRUE;
if (texture == NULL) {
data->glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
return 0;
@@ -797,7 +813,7 @@ static int
GL_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points, int count)
{
GLfloat *verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, count * 2 * sizeof (GLfloat), 0, &cmd->data.draw.first);
size_t i;
int i;
if (!verts) {
return -1;
@@ -816,7 +832,7 @@ static int
GL_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects, int count)
{
GLfloat *verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, count * 4 * sizeof (GLfloat), 0, &cmd->data.draw.first);
size_t i;
int i;
if (!verts) {
return -1;
@@ -1011,7 +1027,13 @@ SetCopyState(GL_RenderData *data, const SDL_RenderCommand *cmd)
{
SDL_Texture *texture = cmd->data.draw.texture;
const GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata;
GL_Shader shader = SHADER_RGB;
GL_Shader shader;
if (texture->format == SDL_PIXELFORMAT_ABGR8888 || texture->format == SDL_PIXELFORMAT_ARGB8888) {
shader = SHADER_RGBA;
} else {
shader = SHADER_RGB;
}
if (data->shaders) {
if (texturedata->yuv || texturedata->nv12) {
@@ -1469,6 +1491,9 @@ GL_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, floa
}
data->glBindTexture(textype, texturedata->texture);
data->drawstate.texturing = SDL_TRUE;
data->drawstate.texture = texture;
if(texw) *texw = (float)texturedata->texw;
if(texh) *texh = (float)texturedata->texh;
@@ -1496,6 +1521,9 @@ GL_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture)
data->glDisable(textype);
data->drawstate.texturing = SDL_FALSE;
data->drawstate.texture = NULL;
return 0;
}
@@ -1513,7 +1541,7 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
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) {
@@ -1719,8 +1747,13 @@ SDL_RenderDriver GL_RenderDriver = {
{
"opengl",
(SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE),
1,
{SDL_PIXELFORMAT_ARGB8888},
4,
{
SDL_PIXELFORMAT_ARGB8888,
SDL_PIXELFORMAT_ABGR8888,
SDL_PIXELFORMAT_RGB888,
SDL_PIXELFORMAT_BGR888
},
0,
0}
};
+18 -1
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@@ -240,6 +240,23 @@ static const char *shader_source[NUM_SHADERS][2] =
"\n"
"void main()\n"
"{\n"
" gl_FragColor = texture2D(tex0, v_texCoord);\n"
" gl_FragColor.a = 1.0;\n"
" gl_FragColor *= v_color;\n"
"}"
},
/* SHADER_RGBA */
{
/* vertex shader */
TEXTURE_VERTEX_SHADER,
/* 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"
"}"
},
+2 -1
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@@ -31,6 +31,7 @@ typedef enum {
SHADER_NONE,
SHADER_SOLID,
SHADER_RGB,
SHADER_RGBA,
SHADER_YUV_JPEG,
SHADER_YUV_BT601,
SHADER_YUV_BT709,
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@@ -26,8 +26,8 @@
#include "SDL_opengles.h"
#include "../SDL_sysrender.h"
/* To prevent unnecessary window recreation,
* these should match the defaults selected in SDL_GL_ResetAttributes
/* To prevent unnecessary window recreation,
* these should match the defaults selected in SDL_GL_ResetAttributes
*/
#define RENDERER_CONTEXT_MAJOR 1
@@ -170,7 +170,7 @@ static int GLES_LoadFunctions(GLES_RenderData * data)
#define SDL_PROC_OES(ret,func,params) \
do { \
data->func = SDL_GL_GetProcAddress(#func); \
} while ( 0 );
} while ( 0 );
#endif /* __SDL_NOGETPROCADDR__ */
#include "SDL_glesfuncs.h"
@@ -351,7 +351,7 @@ GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
}
}
if (texture->access == SDL_TEXTUREACCESS_TARGET) {
if (!renderdata->GL_OES_framebuffer_object_supported) {
SDL_free(data);
@@ -361,7 +361,7 @@ GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
} else {
data->fbo = NULL;
}
renderdata->glGetError();
renderdata->glEnable(GL_TEXTURE_2D);
@@ -391,13 +391,15 @@ GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
texture_h, 0, format, type, NULL);
renderdata->glDisable(GL_TEXTURE_2D);
renderdata->drawstate.texture = texture;
renderdata->drawstate.texturing = SDL_FALSE;
result = renderdata->glGetError();
if (result != GL_NO_ERROR) {
SDL_free(data);
return GLES_SetError("glTexImage2D()", result);
}
texture->driverdata = data;
return 0;
}
@@ -454,6 +456,9 @@ GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
renderdata->glDisable(data->type);
SDL_free(blob);
renderdata->drawstate.texture = texture;
renderdata->drawstate.texturing = SDL_FALSE;
if (renderdata->glGetError() != GL_NO_ERROR) {
return SDL_SetError("Failed to update texture");
}
@@ -498,6 +503,8 @@ GLES_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
return SDL_SetError("Can't enable render target support in this renderer");
}
data->drawstate.viewport_dirty = SDL_TRUE;
if (texture == NULL) {
data->glBindFramebufferOES(GL_FRAMEBUFFER_OES, data->window_framebuffer);
return 0;
@@ -526,7 +533,7 @@ static int
GLES_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points, int count)
{
GLfloat *verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, count * 2 * sizeof (GLfloat), 0, &cmd->data.draw.first);
size_t i;
int i;
if (!verts) {
return -1;
@@ -545,7 +552,7 @@ static int
GLES_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects, int count)
{
GLfloat *verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, count * 8 * sizeof (GLfloat), 0, &cmd->data.draw.first);
size_t i;
int i;
if (!verts) {
return -1;
@@ -1060,6 +1067,9 @@ static int GLES_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, floa
data->glEnable(GL_TEXTURE_2D);
data->glBindTexture(texturedata->type, texturedata->texture);
data->drawstate.texture = texture;
data->drawstate.texturing = SDL_TRUE;
if (texw) {
*texw = (float)texturedata->texw;
}
@@ -1077,6 +1087,9 @@ static int GLES_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture)
GLES_ActivateRenderer(renderer);
data->glDisable(texturedata->type);
data->drawstate.texture = NULL;
data->drawstate.texturing = SDL_FALSE;
return 0;
}
@@ -1210,6 +1223,8 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
data->glEnableClientState(GL_VERTEX_ARRAY);
data->glDisableClientState(GL_TEXTURE_COORD_ARRAY);
data->glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
data->drawstate.blend = SDL_BLENDMODE_INVALID;
data->drawstate.color = 0xFFFFFFFF;
data->drawstate.clear_color = 0xFFFFFFFF;
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@@ -30,7 +30,7 @@
#include "SDL_shaders_gles2.h"
/* To prevent unnecessary window recreation,
* these should match the defaults selected in SDL_GL_ResetAttributes
* these should match the defaults selected in SDL_GL_ResetAttributes
*/
#define RENDERER_CONTEXT_MAJOR 2
#define RENDERER_CONTEXT_MINOR 0
@@ -529,8 +529,10 @@ GLES2_CacheProgram(GLES2_RenderData *data, GLES2_ShaderCacheEntry *vertex,
}
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;
if (data->program_cache.tail != NULL) {
SDL_free(data->program_cache.tail->next);
data->program_cache.tail->next = NULL;
}
--data->program_cache.count;
}
return entry;
@@ -766,7 +768,7 @@ static int
GLES2_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points, int count)
{
GLfloat *verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, count * 2 * sizeof (GLfloat), 0, &cmd->data.draw.first);
size_t i;
int i;
if (!verts) {
return -1;
@@ -785,7 +787,7 @@ static int
GLES2_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects, int count)
{
GLfloat *verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, count * 8 * sizeof (GLfloat), 0, &cmd->data.draw.first);
size_t i;
int i;
if (!verts) {
return -1;
@@ -1400,6 +1402,8 @@ GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
GLES2_ActivateRenderer(renderer);
renderdata->drawstate.texture = NULL; /* we trash this state. */
/* Determine the corresponding GLES texture format params */
switch (texture->format)
{
@@ -1595,6 +1599,8 @@ GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect
return 0;
}
data->drawstate.texture = NULL; /* we trash this state. */
/* Create a texture subimage with the supplied data */
data->glBindTexture(tdata->texture_type, tdata->texture);
GLES2_TexSubImage2D(data, tdata->texture_type,
@@ -1673,6 +1679,8 @@ GLES2_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
return 0;
}
data->drawstate.texture = NULL; /* we trash this state. */
data->glBindTexture(tdata->texture_type, tdata->texture_v);
GLES2_TexSubImage2D(data, tdata->texture_type,
rect->x / 2,
@@ -1742,6 +1750,8 @@ GLES2_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
GLES2_TextureData *texturedata = NULL;
GLenum status;
data->drawstate.viewport_dirty = SDL_TRUE;
if (texture == NULL) {
data->glBindFramebuffer(GL_FRAMEBUFFER, data->window_framebuffer);
} else {
@@ -1867,6 +1877,7 @@ static int GLES2_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, flo
GLES2_ActivateRenderer(renderer);
data->glBindTexture(texturedata->texture_type, texturedata->texture);
data->drawstate.texture = texture;
if (texw) {
*texw = 1.0;
@@ -1885,6 +1896,7 @@ static int GLES2_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture)
GLES2_ActivateRenderer(renderer);
data->glBindTexture(texturedata->texture_type, 0);
data->drawstate.texture = NULL;
return 0;
}
@@ -2076,6 +2088,7 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_EXTERNAL_OES;
#endif
/* Set up parameters for rendering */
data->glActiveTexture(GL_TEXTURE0);
data->glPixelStorei(GL_PACK_ALIGNMENT, 1);
data->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
@@ -2083,6 +2096,8 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
data->glEnableVertexAttribArray(GLES2_ATTRIBUTE_POSITION);
data->glDisableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD);
data->glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
data->drawstate.blend = SDL_BLENDMODE_INVALID;
data->drawstate.color = 0xFFFFFFFF;
data->drawstate.clear_color = 0xFFFFFFFF;
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
+3 -3
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@@ -444,7 +444,7 @@ static int
PSP_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points, int count)
{
VertV *verts = (VertV *) SDL_AllocateRenderVertices(renderer, count * sizeof (VertV), 4, &cmd->data.draw.first);
size_t i;
int i;
if (!verts) {
return -1;
@@ -465,7 +465,7 @@ static int
PSP_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects, int count)
{
VertV *verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, count * 2 * sizeof (VertV), 4, &cmd->data.draw.first);
size_t i;
int i;
if (!verts) {
return -1;
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
+1 -1
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
+1 -1
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
+1 -1
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
+62 -31
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@@ -37,6 +37,13 @@
/* SDL surface based renderer implementation */
typedef struct
{
const SDL_Rect *viewport;
const SDL_Rect *cliprect;
SDL_bool surface_cliprect_dirty;
} SW_DrawStateCache;
typedef struct
{
SDL_Surface *surface;
@@ -75,20 +82,25 @@ SW_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
static int
SW_GetOutputSize(SDL_Renderer * renderer, int *w, int *h)
{
SDL_Surface *surface = SW_ActivateRenderer(renderer);
SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
if (surface) {
if (data->surface) {
if (w) {
*w = surface->w;
*w = data->surface->w;
}
if (h) {
*h = surface->h;
*h = data->surface->h;
}
return 0;
} else {
SDL_SetError("Software renderer doesn't have an output surface");
return -1;
}
if (renderer->window) {
SDL_GetWindowSize(renderer->window, w, h);
return 0;
}
SDL_SetError("Software renderer doesn't have an output surface");
return -1;
}
static int
@@ -172,7 +184,7 @@ SW_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
{
SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
if (texture ) {
if (texture) {
data->surface = (SDL_Surface *) texture->driverdata;
} else {
data->surface = data->window;
@@ -190,7 +202,7 @@ static int
SW_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points, int count)
{
SDL_Point *verts = (SDL_Point *) SDL_AllocateRenderVertices(renderer, count * sizeof (SDL_Point), 0, &cmd->data.draw.first);
size_t i;
int i;
if (!verts) {
return -1;
@@ -219,7 +231,7 @@ static int
SW_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects, int count)
{
SDL_Rect *verts = (SDL_Rect *) SDL_AllocateRenderVertices(renderer, count * sizeof (SDL_Rect), 0, &cmd->data.draw.first);
size_t i;
int i;
if (!verts) {
return -1;
@@ -568,18 +580,43 @@ PrepTextureForCopy(const SDL_RenderCommand *cmd)
SDL_SetSurfaceBlendMode(surface, blend);
}
static void
SetDrawState(SDL_Surface *surface, SW_DrawStateCache *drawstate)
{
if (drawstate->surface_cliprect_dirty) {
const SDL_Rect *viewport = drawstate->viewport;
const SDL_Rect *cliprect = drawstate->cliprect;
SDL_assert(viewport != NULL); /* the higher level should have forced a SDL_RENDERCMD_SETVIEWPORT */
if (cliprect != NULL) {
SDL_Rect clip_rect;
clip_rect.x = cliprect->x + viewport->x;
clip_rect.y = cliprect->y + viewport->y;
clip_rect.w = cliprect->w;
clip_rect.h = cliprect->h;
SDL_IntersectRect(viewport, &clip_rect, &clip_rect);
SDL_SetClipRect(surface, &clip_rect);
} else {
SDL_SetClipRect(surface, drawstate->viewport);
}
drawstate->surface_cliprect_dirty = SDL_FALSE;
}
}
static int
SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
{
SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
SDL_Surface *surface = SW_ActivateRenderer(renderer);
const SDL_Rect *viewport = NULL;
const SDL_Rect *cliprect = NULL;
SW_DrawStateCache drawstate;
if (!surface) {
return -1;
}
drawstate.viewport = NULL;
drawstate.cliprect = NULL;
drawstate.surface_cliprect_dirty = SDL_TRUE;
while (cmd) {
switch (cmd->command) {
case SDL_RENDERCMD_SETDRAWCOLOR: {
@@ -587,25 +624,14 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
}
case SDL_RENDERCMD_SETVIEWPORT: {
viewport = &cmd->data.viewport.rect;
SDL_SetClipRect(data->surface, viewport);
drawstate.viewport = &cmd->data.viewport.rect;
drawstate.surface_cliprect_dirty = SDL_TRUE;
break;
}
case SDL_RENDERCMD_SETCLIPRECT: {
SDL_assert(viewport != NULL);
cliprect = cmd->data.cliprect.enabled ? &cmd->data.cliprect.rect : NULL;
if (cliprect) {
SDL_Rect clip_rect;
clip_rect.x = cliprect->x + viewport->x;
clip_rect.y = cliprect->y + viewport->y;
clip_rect.w = cliprect->w;
clip_rect.h = cliprect->h;
SDL_IntersectRect(viewport, &clip_rect, &clip_rect);
SDL_SetClipRect(surface, &clip_rect);
} else {
SDL_SetClipRect(surface, viewport);
}
drawstate.cliprect = cmd->data.cliprect.enabled ? &cmd->data.cliprect.rect : NULL;
drawstate.surface_cliprect_dirty = SDL_TRUE;
break;
}
@@ -614,11 +640,10 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
const Uint8 g = cmd->data.color.g;
const Uint8 b = cmd->data.color.b;
const Uint8 a = cmd->data.color.a;
const SDL_Rect clip_rect = surface->clip_rect;
/* By definition the clear ignores the clip rect */
SDL_SetClipRect(surface, NULL);
SDL_FillRect(surface, NULL, SDL_MapRGBA(surface->format, r, g, b, a));
SDL_SetClipRect(surface, &clip_rect);
drawstate.surface_cliprect_dirty = SDL_TRUE;
break;
}
@@ -630,6 +655,7 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
const int count = (int) cmd->data.draw.count;
const SDL_Point *verts = (SDL_Point *) (((Uint8 *) vertices) + cmd->data.draw.first);
const SDL_BlendMode blend = cmd->data.draw.blend;
SetDrawState(surface, &drawstate);
if (blend == SDL_BLENDMODE_NONE) {
SDL_DrawPoints(surface, verts, count, SDL_MapRGBA(surface->format, r, g, b, a));
} else {
@@ -646,6 +672,7 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
const int count = (int) cmd->data.draw.count;
const SDL_Point *verts = (SDL_Point *) (((Uint8 *) vertices) + cmd->data.draw.first);
const SDL_BlendMode blend = cmd->data.draw.blend;
SetDrawState(surface, &drawstate);
if (blend == SDL_BLENDMODE_NONE) {
SDL_DrawLines(surface, verts, count, SDL_MapRGBA(surface->format, r, g, b, a));
} else {
@@ -662,6 +689,7 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
const int count = (int) cmd->data.draw.count;
const SDL_Rect *verts = (SDL_Rect *) (((Uint8 *) vertices) + cmd->data.draw.first);
const SDL_BlendMode blend = cmd->data.draw.blend;
SetDrawState(surface, &drawstate);
if (blend == SDL_BLENDMODE_NONE) {
SDL_FillRects(surface, verts, count, SDL_MapRGBA(surface->format, r, g, b, a));
} else {
@@ -677,6 +705,8 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
SDL_Texture *texture = cmd->data.draw.texture;
SDL_Surface *src = (SDL_Surface *) texture->driverdata;
SetDrawState(surface, &drawstate);
PrepTextureForCopy(cmd);
if ( srcrect->w == dstrect->w && srcrect->h == dstrect->h ) {
@@ -693,6 +723,7 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
case SDL_RENDERCMD_COPY_EX: {
const CopyExData *copydata = (CopyExData *) (((Uint8 *) vertices) + cmd->data.draw.first);
SetDrawState(surface, &drawstate);
PrepTextureForCopy(cmd);
SW_RenderCopyEx(renderer, surface, cmd->data.draw.texture, &copydata->srcrect,
&copydata->dstrect, copydata->angle, &copydata->center, copydata->flip);
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
+1 -1
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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