Updated SDL2 to the latest Mercurial revision.

This commit is contained in:
Alex Szpakowski
2015-08-22 14:16:20 -03:00
parent 0753e6b560
commit c47a4b56bb
916 changed files with 16588 additions and 22006 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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
+13 -5
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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
@@ -165,7 +165,8 @@ SDL_RendererEventWatch(void *userdata, SDL_Event *event)
}
}
} else if (event->type == SDL_MOUSEMOTION) {
if (renderer->logical_w) {
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);
@@ -183,7 +184,8 @@ SDL_RendererEventWatch(void *userdata, SDL_Event *event)
}
} else if (event->type == SDL_MOUSEBUTTONDOWN ||
event->type == SDL_MOUSEBUTTONUP) {
if (renderer->logical_w) {
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);
@@ -455,7 +457,7 @@ SDL_CreateTexture(SDL_Renderer * renderer, Uint32 format, int access, int w, int
if (IsSupportedFormat(renderer, format)) {
if (renderer->CreateTexture(renderer, texture) < 0) {
SDL_DestroyTexture(texture);
return 0;
return NULL;
}
} else {
texture->native = SDL_CreateTexture(renderer,
@@ -820,7 +822,9 @@ SDL_UpdateTexture(SDL_Texture * texture, const SDL_Rect * rect,
rect = &full_rect;
}
if (texture->yuv) {
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);
@@ -1730,6 +1734,10 @@ SDL_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
SDL_FRect frect;
SDL_FPoint fcenter;
if (flip == SDL_FLIP_NONE && angle == 0) { /* 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);
+1 -1
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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
@@ -843,7 +843,7 @@ D3D_CreateStagingTexture(IDirect3DDevice9 *device, D3D_TextureRep *texture)
HRESULT result;
if (texture->staging == NULL) {
result = IDirect3DDevice9_CreateTexture(device, texture->w, texture->h, 1, texture->usage,
result = IDirect3DDevice9_CreateTexture(device, texture->w, texture->h, 1, 0,
PixelFormatToD3DFMT(texture->format),
D3DPOOL_SYSTEMMEM, &texture->staging, NULL);
if (FAILED(result)) {
@@ -1269,10 +1269,10 @@ D3D_UpdateClipRect(SDL_Renderer * renderer)
HRESULT result;
IDirect3DDevice9_SetRenderState(data->device, D3DRS_SCISSORTESTENABLE, TRUE);
r.left = rect->x;
r.top = rect->y;
r.right = rect->x + rect->w;
r.bottom = rect->y + rect->h;
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) {
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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
@@ -1356,7 +1356,7 @@ D3D11_GetRotationForCurrentRenderTarget(SDL_Renderer * renderer)
}
static int
D3D11_GetViewportAlignedD3DRect(SDL_Renderer * renderer, const SDL_Rect * sdlRect, D3D11_RECT * outRect)
D3D11_GetViewportAlignedD3DRect(SDL_Renderer * renderer, const SDL_Rect * sdlRect, D3D11_RECT * outRect, BOOL includeViewportOffset)
{
D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
const int rotation = D3D11_GetRotationForCurrentRenderTarget(renderer);
@@ -1366,6 +1366,12 @@ D3D11_GetViewportAlignedD3DRect(SDL_Renderer * renderer, const SDL_Rect * sdlRec
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;
@@ -2280,7 +2286,7 @@ D3D11_UpdateClipRect(SDL_Renderer * renderer)
ID3D11DeviceContext_RSSetScissorRects(data->d3dContext, 0, NULL);
} else {
D3D11_RECT scissorRect;
if (D3D11_GetViewportAlignedD3DRect(renderer, &renderer->clip_rect, &scissorRect) != 0) {
if (D3D11_GetViewportAlignedD3DRect(renderer, &renderer->clip_rect, &scissorRect, TRUE) != 0) {
/* D3D11_GetViewportAlignedD3DRect will have set the SDL error */
return -1;
}
@@ -2869,7 +2875,7 @@ D3D11_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
}
/* Copy the desired portion of the back buffer to the staging texture: */
if (D3D11_GetViewportAlignedD3DRect(renderer, rect, &srcRect) != 0) {
if (D3D11_GetViewportAlignedD3DRect(renderer, rect, &srcRect, FALSE) != 0) {
/* D3D11_GetViewportAlignedD3DRect will have set the SDL error */
goto done;
}
@@ -2916,7 +2922,7 @@ D3D11_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
*/
char errorMessage[1024];
SDL_snprintf(errorMessage, sizeof(errorMessage), __FUNCTION__ ", Convert Pixels failed: %s", SDL_GetError());
SDL_SetError(errorMessage);
SDL_SetError("%s", errorMessage);
goto done;
}
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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
+9 -2
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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
@@ -1046,7 +1046,14 @@ GL_UpdateClipRect(SDL_Renderer * renderer)
if (renderer->clipping_enabled) {
const SDL_Rect *rect = &renderer->clip_rect;
data->glEnable(GL_SCISSOR_TEST);
data->glScissor(rect->x, renderer->viewport.h - rect->y - rect->h, rect->w, rect->h);
if (renderer->target) {
data->glScissor(renderer->viewport.x + rect->x, renderer->viewport.y + rect->y, rect->w, rect->h);
} else {
int w, h;
SDL_GetRendererOutputSize(renderer, &w, &h);
data->glScissor(renderer->viewport.x + rect->x, (h - renderer->viewport.y - renderer->viewport.h) + rect->y, rect->w, rect->h);
}
} else {
data->glDisable(GL_SCISSOR_TEST);
}
+1 -1
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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
+42 -16
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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,7 +43,7 @@ glDrawTexiOES(GLint x, GLint y, GLint z, GLint width, GLint height)
return;
}
#endif /* PANDORA */
#endif /* SDL_VIDEO_DRIVER_PANDORA */
/* OpenGL ES 1.1 renderer implementation, based on the OpenGL renderer */
@@ -55,6 +55,7 @@ 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,
@@ -205,7 +206,7 @@ static int GLES_LoadFunctions(GLES_RenderData * data)
do { \
data->func = SDL_GL_GetProcAddress(#func); \
} while ( 0 );
#endif /* _SDL_NOGETPROCADDR_ */
#endif /* __SDL_NOGETPROCADDR__ */
#include "SDL_glesfuncs.h"
#undef SDL_PROC
@@ -219,12 +220,10 @@ GLES_FBOList *
GLES_GetFBO(GLES_RenderData *data, Uint32 w, Uint32 h)
{
GLES_FBOList *result = data->framebuffers;
while ((result) && ((result->w != w) || (result->h != h)) )
{
while ((result) && ((result->w != w) || (result->h != h)) ) {
result = result->next;
}
if (result == NULL)
{
if (result == NULL) {
result = SDL_malloc(sizeof(GLES_FBOList));
result->w = w;
result->h = h;
@@ -321,6 +320,7 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
}
renderer->WindowEvent = GLES_WindowEvent;
renderer->GetOutputSize = GLES_GetOutputSize;
renderer->CreateTexture = GLES_CreateTexture;
renderer->UpdateTexture = GLES_UpdateTexture;
renderer->LockTexture = GLES_LockTexture;
@@ -438,6 +438,13 @@ GLES_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
}
}
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)
{
@@ -563,8 +570,9 @@ GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
GLES_ActivateRenderer(renderer);
/* Bail out if we're supposed to update an empty rectangle */
if (rect->w <= 0 || rect->h <= 0)
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);
@@ -599,8 +607,7 @@ GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
src);
SDL_free(blob);
if (renderdata->glGetError() != GL_NO_ERROR)
{
if (renderdata->glGetError() != GL_NO_ERROR) {
return SDL_SetError("Failed to update texture");
}
return 0;
@@ -641,7 +648,7 @@ GLES_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
GLenum status;
GLES_ActivateRenderer(renderer);
if (!data->GL_OES_framebuffer_object_supported) {
return SDL_SetError("Can't enable render target support in this renderer");
}
@@ -673,8 +680,16 @@ GLES_UpdateViewport(SDL_Renderer * renderer)
return 0;
}
data->glViewport(renderer->viewport.x, renderer->viewport.y,
renderer->viewport.w, renderer->viewport.h);
if (renderer->target) {
data->glViewport(renderer->viewport.x, renderer->viewport.y,
renderer->viewport.w, renderer->viewport.h);
} else {
int w, h;
SDL_GetRendererOutputSize(renderer, &w, &h);
data->glViewport(renderer->viewport.x, (h - renderer->viewport.y - renderer->viewport.h),
renderer->viewport.w, renderer->viewport.h);
}
if (renderer->viewport.w && renderer->viewport.h) {
data->glMatrixMode(GL_PROJECTION);
@@ -700,7 +715,14 @@ GLES_UpdateClipRect(SDL_Renderer * renderer)
if (renderer->clipping_enabled) {
const SDL_Rect *rect = &renderer->clip_rect;
data->glEnable(GL_SCISSOR_TEST);
data->glScissor(rect->x, renderer->viewport.h - rect->y - rect->h, rect->w, rect->h);
if (renderer->target) {
data->glScissor(renderer->viewport.x + rect->x, renderer->viewport.y + rect->y, rect->w, rect->h);
} else {
int w, h;
SDL_GetRendererOutputSize(renderer, &w, &h);
data->glScissor(renderer->viewport.x + rect->x, (h - renderer->viewport.y - renderer->viewport.h) + rect->y, rect->w, rect->h);
}
} else {
data->glDisable(GL_SCISSOR_TEST);
}
@@ -1197,8 +1219,12 @@ static int GLES_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, floa
data->glEnable(GL_TEXTURE_2D);
data->glBindTexture(texturedata->type, texturedata->texture);
if(texw) *texw = (float)texturedata->texw;
if(texh) *texh = (float)texturedata->texh;
if (texw) {
*texw = (float)texturedata->texw;
}
if (texh) {
*texh = (float)texturedata->texh;
}
return 0;
}
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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
+148 -132
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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
@@ -224,8 +224,7 @@ GL_ClearErrors(SDL_Renderer *renderer)
{
GLES2_DriverContext *data = (GLES2_DriverContext *) renderer->driverdata;
if (!data->debug_enabled)
{
if (!data->debug_enabled) {
return;
}
while (data->glGetError() != GL_NO_ERROR) {
@@ -239,8 +238,7 @@ GL_CheckAllErrors (const char *prefix, SDL_Renderer *renderer, const char *file,
GLES2_DriverContext *data = (GLES2_DriverContext *) renderer->driverdata;
int ret = 0;
if (!data->debug_enabled)
{
if (!data->debug_enabled) {
return 0;
}
/* check gl errors (can return multiple errors) */
@@ -302,7 +300,7 @@ static int GLES2_LoadFunctions(GLES2_DriverContext * data)
return SDL_SetError("Couldn't load GLES2 function %s: %s\n", #func, SDL_GetError()); \
} \
} while ( 0 );
#endif /* _SDL_NOGETPROCADDR_ */
#endif /* __SDL_NOGETPROCADDR__ */
#include "SDL_gles2funcs.h"
#undef SDL_PROC
@@ -313,12 +311,10 @@ GLES2_FBOList *
GLES2_GetFBO(GLES2_DriverContext *data, Uint32 w, Uint32 h)
{
GLES2_FBOList *result = data->framebuffers;
while ((result) && ((result->w != w) || (result->h != h)) )
{
while ((result) && ((result->w != w) || (result->h != h)) ) {
result = result->next;
}
if (result == NULL)
{
if (result == NULL) {
result = SDL_malloc(sizeof(GLES2_FBOList));
result->w = w;
result->h = h;
@@ -369,6 +365,13 @@ GLES2_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
}
}
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)
{
@@ -379,8 +382,16 @@ GLES2_UpdateViewport(SDL_Renderer * renderer)
return 0;
}
data->glViewport(renderer->viewport.x, renderer->viewport.y,
renderer->viewport.w, renderer->viewport.h);
if (renderer->target) {
data->glViewport(renderer->viewport.x, renderer->viewport.y,
renderer->viewport.w, renderer->viewport.h);
} else {
int w, h;
SDL_GetRendererOutputSize(renderer, &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);
@@ -401,7 +412,14 @@ GLES2_UpdateClipRect(SDL_Renderer * renderer)
if (renderer->clipping_enabled) {
const SDL_Rect *rect = &renderer->clip_rect;
data->glEnable(GL_SCISSOR_TEST);
data->glScissor(rect->x, renderer->viewport.h - rect->y - rect->h, rect->w, rect->h);
if (renderer->target) {
data->glScissor(renderer->viewport.x + rect->x, renderer->viewport.y + rect->y, rect->w, rect->h);
} else {
int w, h;
SDL_GetRendererOutputSize(renderer, &w, &h);
data->glScissor(renderer->viewport.x + rect->x, (h - renderer->viewport.y - renderer->viewport.h) + rect->y, rect->w, rect->h);
}
} else {
data->glDisable(GL_SCISSOR_TEST);
}
@@ -421,8 +439,7 @@ GLES2_DestroyRenderer(SDL_Renderer *renderer)
GLES2_ShaderCacheEntry *entry;
GLES2_ShaderCacheEntry *next;
entry = data->shader_cache.head;
while (entry)
{
while (entry) {
data->glDeleteShader(entry->id);
next = entry->next;
SDL_free(entry);
@@ -670,8 +687,9 @@ GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect
GLES2_ActivateRenderer(renderer);
/* Bail out if we're supposed to update an empty rectangle */
if (rect->w <= 0 || rect->h <= 0)
if (rect->w <= 0 || rect->h <= 0) {
return 0;
}
/* Create a texture subimage with the supplied data */
data->glBindTexture(tdata->texture_type, tdata->texture);
@@ -748,8 +766,9 @@ GLES2_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
GLES2_ActivateRenderer(renderer);
/* Bail out if we're supposed to update an empty rectangle */
if (rect->w <= 0 || rect->h <= 0)
if (rect->w <= 0 || rect->h <= 0) {
return 0;
}
data->glBindTexture(tdata->texture_type, tdata->texture_v);
GLES2_TexSubImage2D(data, tdata->texture_type,
@@ -845,8 +864,7 @@ GLES2_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
GLES2_ActivateRenderer(renderer);
/* Destroy the texture */
if (tdata)
{
if (tdata) {
data->glDeleteTextures(1, &tdata->texture);
if (tdata->texture_v) {
data->glDeleteTextures(1, &tdata->texture_v);
@@ -885,20 +903,20 @@ GLES2_CacheProgram(SDL_Renderer *renderer, GLES2_ShaderCacheEntry *vertex,
/* Check if we've already cached this program */
entry = data->program_cache.head;
while (entry)
{
if (entry->vertex_shader == vertex && entry->fragment_shader == fragment)
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)
if (entry) {
if (data->program_cache.head != entry) {
if (entry->next) {
entry->next->prev = entry->prev;
if (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;
@@ -909,8 +927,7 @@ GLES2_CacheProgram(SDL_Renderer *renderer, GLES2_ShaderCacheEntry *vertex,
/* Create a program cache entry */
entry = (GLES2_ProgramCacheEntry *)SDL_calloc(1, sizeof(GLES2_ProgramCacheEntry));
if (!entry)
{
if (!entry) {
SDL_OutOfMemory();
return NULL;
}
@@ -928,8 +945,7 @@ GLES2_CacheProgram(SDL_Renderer *renderer, GLES2_ShaderCacheEntry *vertex,
data->glBindAttribLocation(entry->id, GLES2_ATTRIBUTE_CENTER, "a_center");
data->glLinkProgram(entry->id);
data->glGetProgramiv(entry->id, GL_LINK_STATUS, &linkSuccessful);
if (!linkSuccessful)
{
if (!linkSuccessful) {
data->glDeleteProgram(entry->id);
SDL_free(entry);
SDL_SetError("Failed to link shader program");
@@ -962,13 +978,10 @@ GLES2_CacheProgram(SDL_Renderer *renderer, GLES2_ShaderCacheEntry *vertex,
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)
{
if (data->program_cache.head) {
entry->next = data->program_cache.head;
data->program_cache.head->prev = entry;
}
else
{
} else {
data->program_cache.tail = entry;
}
data->program_cache.head = entry;
@@ -979,14 +992,15 @@ GLES2_CacheProgram(SDL_Renderer *renderer, GLES2_ShaderCacheEntry *vertex,
++fragment->references;
/* Evict the last entry from the cache if we exceed the limit */
if (data->program_cache.count > GLES2_MAX_CACHED_PROGRAMS)
{
if (data->program_cache.count > GLES2_MAX_CACHED_PROGRAMS) {
shaderEntry = data->program_cache.tail->vertex_shader;
if (--shaderEntry->references <= 0)
if (--shaderEntry->references <= 0) {
GLES2_EvictShader(renderer, shaderEntry);
}
shaderEntry = data->program_cache.tail->fragment_shader;
if (--shaderEntry->references <= 0)
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);
@@ -1008,47 +1022,43 @@ GLES2_CacheShader(SDL_Renderer *renderer, GLES2_ShaderType type, SDL_BlendMode b
/* Find the corresponding shader */
shader = GLES2_GetShader(type, blendMode);
if (!shader)
{
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)
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])
continue;
if (shader->instances[i]->format != data->shader_formats[j])
}
if (shader->instances[i]->format != data->shader_formats[j]) {
continue;
}
instance = shader->instances[i];
}
}
if (!instance)
{
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)
while (entry) {
if (entry->instance == instance) {
break;
}
entry = entry->next;
}
if (entry)
if (entry) {
return entry;
}
/* Create a shader cache entry */
entry = (GLES2_ShaderCacheEntry *)SDL_calloc(1, sizeof(GLES2_ShaderCacheEntry));
if (!entry)
{
if (!entry) {
SDL_OutOfMemory();
return NULL;
}
@@ -1057,19 +1067,15 @@ GLES2_CacheShader(SDL_Renderer *renderer, GLES2_ShaderType type, SDL_BlendMode b
/* Compile or load the selected shader instance */
entry->id = data->glCreateShader(instance->type);
if (instance->format == (GLenum)-1)
{
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
{
} else {
data->glShaderBinary(1, &entry->id, instance->format, instance->data, instance->length);
compileSuccessful = GL_TRUE;
}
if (!compileSuccessful)
{
if (!compileSuccessful) {
char *info = NULL;
int length = 0;
@@ -1092,8 +1098,7 @@ GLES2_CacheShader(SDL_Renderer *renderer, GLES2_ShaderType type, SDL_BlendMode b
}
/* Link the shader entry in at the front of the cache */
if (data->shader_cache.head)
{
if (data->shader_cache.head) {
entry->next = data->shader_cache.head;
data->shader_cache.head->prev = entry;
}
@@ -1108,12 +1113,15 @@ GLES2_EvictShader(SDL_Renderer *renderer, GLES2_ShaderCacheEntry *entry)
GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
/* Unlink the shader from the cache */
if (entry->next)
if (entry->next) {
entry->next->prev = entry->prev;
if (entry->prev)
}
if (entry->prev) {
entry->prev->next = entry->next;
if (data->shader_cache.head == entry)
}
if (data->shader_cache.head == entry) {
data->shader_cache.head = entry->next;
}
--data->shader_cache.count;
/* Deallocate the shader */
@@ -1132,8 +1140,7 @@ GLES2_SelectProgram(SDL_Renderer *renderer, GLES2_ImageSource source, SDL_BlendM
/* Select an appropriate shader pair for the specified modes */
vtype = GLES2_SHADER_VERTEX_DEFAULT;
switch (source)
{
switch (source) {
case GLES2_IMAGESOURCE_SOLID:
ftype = GLES2_SHADER_FRAGMENT_SOLID_SRC;
break;
@@ -1164,22 +1171,26 @@ GLES2_SelectProgram(SDL_Renderer *renderer, GLES2_ImageSource source, SDL_BlendM
/* Load the requested shaders */
vertex = GLES2_CacheShader(renderer, vtype, blendMode);
if (!vertex)
if (!vertex) {
goto fault;
}
fragment = GLES2_CacheShader(renderer, ftype, blendMode);
if (!fragment)
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)
data->current_program->fragment_shader == fragment) {
return 0;
}
/* Generate a matching program */
program = GLES2_CacheProgram(renderer, vertex, fragment, blendMode);
if (!program)
if (!program) {
goto fault;
}
/* Select that program in OpenGL */
data->glUseProgram(program->id);
@@ -1188,16 +1199,19 @@ GLES2_SelectProgram(SDL_Renderer *renderer, GLES2_ImageSource source, SDL_BlendM
data->current_program = program;
/* Activate an orthographic projection */
if (GLES2_SetOrthographicProjection(renderer) < 0)
if (GLES2_SetOrthographicProjection(renderer) < 0) {
goto fault;
}
/* Clean up and return */
return 0;
fault:
if (vertex && vertex->references <= 0)
if (vertex && vertex->references <= 0) {
GLES2_EvictShader(renderer, vertex);
if (fragment && fragment->references <= 0)
}
if (fragment && fragment->references <= 0) {
GLES2_EvictShader(renderer, fragment);
}
data->current_program = NULL;
return -1;
}
@@ -1412,8 +1426,9 @@ GLES2_UpdateVertexBuffer(SDL_Renderer *renderer, GLES2_Attribute attr,
#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])
if (!data->vertex_buffers[attr]) {
data->glGenBuffers(1, &data->vertex_buffers[attr]);
}
data->glBindBuffer(GL_ARRAY_BUFFER, data->vertex_buffers[attr]);
@@ -1541,58 +1556,53 @@ GLES2_SetupCopy(SDL_Renderer *renderer, SDL_Texture *texture)
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)
{
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;
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;
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;
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;
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:
@@ -1608,11 +1618,11 @@ GLES2_SetupCopy(SDL_Renderer *renderer, SDL_Texture *texture)
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 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)
{
switch (texture->format) {
case SDL_PIXELFORMAT_ARGB8888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
break;
@@ -1877,8 +1887,12 @@ static int GLES2_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, flo
data->glBindTexture(texturedata->texture_type, texturedata->texture);
if(texw) *texw = 1.0;
if(texh) *texh = 1.0;
if (texw) {
*texw = 1.0;
}
if (texh) {
*texh = 1.0;
}
return 0;
}
@@ -2034,12 +2048,12 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
#else /* !ZUNE_HD */
data->glGetIntegerv(GL_NUM_SHADER_BINARY_FORMATS, &nFormats);
data->glGetBooleanv(GL_SHADER_COMPILER, &hasCompiler);
if (hasCompiler)
if (hasCompiler) {
++nFormats;
}
#endif /* ZUNE_HD */
data->shader_formats = (GLenum *)SDL_calloc(nFormats, sizeof(GLenum));
if (!data->shader_formats)
{
if (!data->shader_formats) {
GLES2_DestroyRenderer(renderer);
SDL_OutOfMemory();
goto error;
@@ -2049,8 +2063,9 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
data->shader_formats[0] = GL_NVIDIA_PLATFORM_BINARY_NV;
#else /* !ZUNE_HD */
data->glGetIntegerv(GL_SHADER_BINARY_FORMATS, (GLint *)data->shader_formats);
if (hasCompiler)
if (hasCompiler) {
data->shader_formats[nFormats - 1] = (GLenum)-1;
}
#endif /* ZUNE_HD */
data->framebuffers = NULL;
@@ -2059,6 +2074,7 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
/* 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;
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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
@@ -810,13 +810,11 @@ static GLES2_Shader GLES2_FragmentShader_TextureNV21Src = {
const GLES2_Shader *GLES2_GetShader(GLES2_ShaderType type, SDL_BlendMode blendMode)
{
switch (type)
{
switch (type) {
case GLES2_SHADER_VERTEX_DEFAULT:
return &GLES2_VertexShader_Default;
case GLES2_SHADER_FRAGMENT_SOLID_SRC:
switch (blendMode)
{
switch (blendMode) {
case SDL_BLENDMODE_NONE:
return &GLES2_FragmentShader_None_SolidSrc;
case SDL_BLENDMODE_BLEND:
@@ -829,8 +827,7 @@ const GLES2_Shader *GLES2_GetShader(GLES2_ShaderType type, SDL_BlendMode blendMo
return NULL;
}
case GLES2_SHADER_FRAGMENT_TEXTURE_ABGR_SRC:
switch (blendMode)
{
switch (blendMode) {
case SDL_BLENDMODE_NONE:
return &GLES2_FragmentShader_None_TextureABGRSrc;
case SDL_BLENDMODE_BLEND:
@@ -843,8 +840,7 @@ const GLES2_Shader *GLES2_GetShader(GLES2_ShaderType type, SDL_BlendMode blendMo
return NULL;
}
case GLES2_SHADER_FRAGMENT_TEXTURE_ARGB_SRC:
switch (blendMode)
{
switch (blendMode) {
case SDL_BLENDMODE_NONE:
return &GLES2_FragmentShader_None_TextureARGBSrc;
case SDL_BLENDMODE_BLEND:
@@ -858,8 +854,7 @@ const GLES2_Shader *GLES2_GetShader(GLES2_ShaderType type, SDL_BlendMode blendMo
}
case GLES2_SHADER_FRAGMENT_TEXTURE_RGB_SRC:
switch (blendMode)
{
switch (blendMode) {
case SDL_BLENDMODE_NONE:
return &GLES2_FragmentShader_None_TextureRGBSrc;
case SDL_BLENDMODE_BLEND:
@@ -873,8 +868,7 @@ const GLES2_Shader *GLES2_GetShader(GLES2_ShaderType type, SDL_BlendMode blendMo
}
case GLES2_SHADER_FRAGMENT_TEXTURE_BGR_SRC:
switch (blendMode)
{
switch (blendMode) {
case SDL_BLENDMODE_NONE:
return &GLES2_FragmentShader_None_TextureBGRSrc;
case SDL_BLENDMODE_BLEND:
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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
+2 -2
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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
@@ -459,7 +459,7 @@ 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));;
PSP_TextureData* psp_texture = (PSP_TextureData*) SDL_calloc(1, sizeof(*psp_texture));
if(!psp_texture)
return -1;
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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 -58
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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
@@ -253,6 +253,12 @@ 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);
}
@@ -261,6 +267,12 @@ 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);
}
@@ -268,6 +280,12 @@ 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);
}
@@ -553,6 +571,10 @@ SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
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);
}
}
@@ -578,7 +600,6 @@ SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
SDL_Surface *src = (SDL_Surface *) texture->driverdata;
SDL_Rect final_rect, tmp_rect;
SDL_Surface *surface_rotated, *surface_scaled;
Uint32 colorkey;
int retval, dstwidth, dstheight, abscenterx, abscentery;
double cangle, sangle, px, py, p1x, p1y, p2x, p2y, p3x, p3y, p4x, p4y;
@@ -596,66 +617,113 @@ SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
final_rect.w = (int)dstrect->w;
final_rect.h = (int)dstrect->h;
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) {
SDL_GetColorKey(src, &colorkey);
SDL_SetColorKey(surface_scaled, SDL_TRUE, colorkey);
tmp_rect = final_rect;
tmp_rect.x = 0;
tmp_rect.y = 0;
/* 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;
retval = SDL_BlitScaled(src, srcrect, surface_scaled, &tmp_rect);
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_scaled);
SDL_FreeSurface(surface_rotated);
return retval;
}
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);
}
return retval;
}
return -1;
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
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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
+33 -38
View File
@@ -188,10 +188,8 @@ _transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int
dy = (sdy >> 16);
if (flipx) dx = sw - dx;
if (flipy) dy = sh - dy;
if ((dx > -1) && (dy > -1) && (dx < (src->w-1)) && (dy < (src->h-1))) {
sp = (tColorRGBA *)src->pixels;
sp += ((src->pitch/4) * dy);
sp += dx;
if ((unsigned)dx < (unsigned)sw && (unsigned)dy < (unsigned)sh) {
sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy) + dx;
c00 = *sp;
sp += 1;
c01 = *sp;
@@ -237,14 +235,12 @@ _transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int
sdx = (ax + (isin * dy)) + xd;
sdy = (ay - (icos * dy)) + yd;
for (x = 0; x < dst->w; x++) {
dx = (short) (sdx >> 16);
dy = (short) (sdy >> 16);
if (flipx) dx = (src->w-1)-dx;
if (flipy) dy = (src->h-1)-dy;
if ((dx >= 0) && (dy >= 0) && (dx < src->w) && (dy < src->h)) {
sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy);
sp += dx;
*pc = *sp;
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;
@@ -277,7 +273,7 @@ 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, *sp;
tColorY *pc;
int gap;
/*
@@ -301,14 +297,12 @@ transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin
sdx = (ax + (isin * dy)) + xd;
sdy = (ay - (icos * dy)) + yd;
for (x = 0; x < dst->w; x++) {
dx = (short) (sdx >> 16);
dy = (short) (sdy >> 16);
if (flipx) dx = (src->w-1)-dx;
if (flipy) dy = (src->h-1)-dy;
if ((dx >= 0) && (dy >= 0) && (dx < src->w) && (dy < src->h)) {
sp = (tColorY *) (src->pixels);
sp += (src->pitch * dy + dx);
*pc = *sp;
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;
@@ -348,7 +342,7 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery,
SDL_Surface *rz_src;
SDL_Surface *rz_dst;
int is32bit;
int i, src_converted;
int i;
Uint8 r,g,b;
Uint32 colorkey = 0;
int colorKeyAvailable = 0;
@@ -375,27 +369,15 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery,
* Use source surface 'as is'
*/
rz_src = src;
src_converted = 0;
} else {
/*
* New source surface is 32bit with a defined RGBA ordering
*/
rz_src =
SDL_CreateRGBSurface(SDL_SWSURFACE, src->w, src->h, 32,
Uint32 format = SDL_MasksToPixelFormatEnum(32,
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000
#else
0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff
#endif
);
if(colorKeyAvailable)
SDL_SetColorKey(src, 0, 0);
SDL_BlitSurface(src, NULL, rz_src, NULL);
if(colorKeyAvailable)
SDL_SetColorKey(src, SDL_TRUE /* SDL_SRCCOLORKEY */, colorkey);
src_converted = 1;
);
rz_src = SDL_ConvertSurfaceFormat(src, format, src->flags);
is32bit = 1;
}
@@ -480,6 +462,19 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery,
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
*/
@@ -490,7 +485,7 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery,
/*
* Cleanup temp surface
*/
if (src_converted) {
if (rz_src != src) {
SDL_FreeSurface(rz_src);
}
+1 -1
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2015 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