mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-14 16:14:38 +00:00
update sdl to 2.32.6
This commit is contained in:
parent
e557f5962b
commit
ddc1f8c1e2
1339 changed files with 53966 additions and 19207 deletions
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
#include "../SDL_internal.h"
|
||||
|
||||
#if (SDL_VIDEO_RENDER_D3D || SDL_VIDEO_RENDER_D3D11 || SDL_VIDEO_RENDER_D3D12) && !SDL_RENDER_DISABLED
|
||||
#if (SDL_VIDEO_RENDER_D3D || SDL_VIDEO_RENDER_D3D11 || SDL_VIDEO_RENDER_D3D12)
|
||||
#include "SDL_stdinc.h"
|
||||
|
||||
#include "SDL_d3dmath.h"
|
||||
|
|
@ -130,6 +130,6 @@ Float4X4 MatrixRotationZ(float r)
|
|||
return m;
|
||||
}
|
||||
|
||||
#endif /* (SDL_VIDEO_RENDER_D3D || SDL_VIDEO_RENDER_D3D11 || SDL_VIDEO_RENDER_D3D12) && !SDL_RENDER_DISABLED */
|
||||
#endif /* (SDL_VIDEO_RENDER_D3D || SDL_VIDEO_RENDER_D3D11 || SDL_VIDEO_RENDER_D3D12) */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
#include "../SDL_internal.h"
|
||||
|
||||
#if (SDL_VIDEO_RENDER_D3D || SDL_VIDEO_RENDER_D3D11 || SDL_VIDEO_RENDER_D3D12) && !SDL_RENDER_DISABLED
|
||||
#if (SDL_VIDEO_RENDER_D3D || SDL_VIDEO_RENDER_D3D11 || SDL_VIDEO_RENDER_D3D12)
|
||||
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
|
|
@ -78,6 +78,6 @@ Float4X4 MatrixRotationZ(float r);
|
|||
}
|
||||
#endif
|
||||
|
||||
#endif /* (SDL_VIDEO_RENDER_D3D || SDL_VIDEO_RENDER_D3D11 || SDL_VIDEO_RENDER_D3D12) && !SDL_RENDER_DISABLED */
|
||||
#endif /* (SDL_VIDEO_RENDER_D3D || SDL_VIDEO_RENDER_D3D11 || SDL_VIDEO_RENDER_D3D12) */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -47,12 +47,19 @@ this should probably be removed at some point in the future. --ryan. */
|
|||
|
||||
#define SDL_WINDOWRENDERDATA "_SDL_WindowRenderData"
|
||||
|
||||
#define CHECK_RENDERER_MAGIC(renderer, retval) \
|
||||
#define CHECK_RENDERER_MAGIC_BUT_NOT_DESTROYED_FLAG(renderer, retval) \
|
||||
if (!renderer || renderer->magic != &renderer_magic) { \
|
||||
SDL_InvalidParamError("renderer"); \
|
||||
return retval; \
|
||||
}
|
||||
|
||||
#define CHECK_RENDERER_MAGIC(renderer, retval) \
|
||||
CHECK_RENDERER_MAGIC_BUT_NOT_DESTROYED_FLAG(renderer, retval); \
|
||||
if (renderer->destroyed) { \
|
||||
SDL_SetError("Renderer's window has been destroyed, can't use further"); \
|
||||
return retval; \
|
||||
}
|
||||
|
||||
#define CHECK_TEXTURE_MAGIC(texture, retval) \
|
||||
if (!texture || texture->magic != &texture_magic) { \
|
||||
SDL_InvalidParamError("texture"); \
|
||||
|
|
@ -89,7 +96,7 @@ this should probably be removed at some point in the future. --ryan. */
|
|||
SDL_COMPOSE_BLENDMODE(SDL_BLENDFACTOR_DST_COLOR, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD, \
|
||||
SDL_BLENDFACTOR_ZERO, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_ADD)
|
||||
|
||||
#if !SDL_RENDER_DISABLED
|
||||
#ifndef SDL_RENDER_DISABLED
|
||||
static const SDL_RenderDriver *render_drivers[] = {
|
||||
#if SDL_VIDEO_RENDER_D3D
|
||||
&D3D_RenderDriver,
|
||||
|
|
@ -239,7 +246,7 @@ static int FlushRenderCommands(SDL_Renderer *renderer)
|
|||
|
||||
SDL_assert((renderer->render_commands == NULL) == (renderer->render_commands_tail == NULL));
|
||||
|
||||
if (renderer->render_commands == NULL) { /* nothing to do! */
|
||||
if (!renderer->render_commands) { /* nothing to do! */
|
||||
SDL_assert(renderer->vertex_data_used == 0);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -249,7 +256,7 @@ static int FlushRenderCommands(SDL_Renderer *renderer)
|
|||
retval = renderer->RunCommandQueue(renderer, renderer->render_commands, renderer->vertex_data, renderer->vertex_data_used);
|
||||
|
||||
/* Move the whole render command queue to the unused pool so we can reuse them next time. */
|
||||
if (renderer->render_commands_tail != NULL) {
|
||||
if (renderer->render_commands_tail) {
|
||||
renderer->render_commands_tail->next = renderer->render_commands_pool;
|
||||
renderer->render_commands_pool = renderer->render_commands;
|
||||
renderer->render_commands_tail = NULL;
|
||||
|
|
@ -301,7 +308,7 @@ void *SDL_AllocateRenderVertices(SDL_Renderer *renderer, const size_t numbytes,
|
|||
|
||||
ptr = SDL_realloc(renderer->vertex_data, newsize);
|
||||
|
||||
if (ptr == NULL) {
|
||||
if (!ptr) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -324,19 +331,19 @@ static SDL_RenderCommand *AllocateRenderCommand(SDL_Renderer *renderer)
|
|||
|
||||
/* !!! FIXME: are there threading limitations in SDL's render API? If not, we need to mutex this. */
|
||||
retval = renderer->render_commands_pool;
|
||||
if (retval != NULL) {
|
||||
if (retval) {
|
||||
renderer->render_commands_pool = retval->next;
|
||||
retval->next = NULL;
|
||||
} else {
|
||||
retval = SDL_calloc(1, sizeof(*retval));
|
||||
if (retval == NULL) {
|
||||
if (!retval) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_assert((renderer->render_commands == NULL) == (renderer->render_commands_tail == NULL));
|
||||
if (renderer->render_commands_tail != NULL) {
|
||||
if (renderer->render_commands_tail) {
|
||||
renderer->render_commands_tail->next = retval;
|
||||
} else {
|
||||
renderer->render_commands = retval;
|
||||
|
|
@ -352,7 +359,7 @@ static int QueueCmdSetViewport(SDL_Renderer *renderer)
|
|||
if (!renderer->viewport_queued || (SDL_memcmp(&renderer->viewport, &renderer->last_queued_viewport, sizeof(SDL_DRect)) != 0)) {
|
||||
SDL_RenderCommand *cmd = AllocateRenderCommand(renderer);
|
||||
retval = -1;
|
||||
if (cmd != NULL) {
|
||||
if (cmd) {
|
||||
cmd->command = SDL_RENDERCMD_SETVIEWPORT;
|
||||
cmd->data.viewport.first = 0; /* render backend will fill this in. */
|
||||
/* Convert SDL_DRect to SDL_Rect */
|
||||
|
|
@ -379,7 +386,7 @@ static int QueueCmdSetClipRect(SDL_Renderer *renderer)
|
|||
(renderer->clipping_enabled != renderer->last_queued_cliprect_enabled) ||
|
||||
(SDL_memcmp(&renderer->clip_rect, &renderer->last_queued_cliprect, sizeof(SDL_DRect)) != 0)) {
|
||||
SDL_RenderCommand *cmd = AllocateRenderCommand(renderer);
|
||||
if (cmd == NULL) {
|
||||
if (!cmd) {
|
||||
retval = -1;
|
||||
} else {
|
||||
cmd->command = SDL_RENDERCMD_SETCLIPRECT;
|
||||
|
|
@ -406,7 +413,7 @@ static int QueueCmdSetDrawColor(SDL_Renderer *renderer, SDL_Color *col)
|
|||
SDL_RenderCommand *cmd = AllocateRenderCommand(renderer);
|
||||
retval = -1;
|
||||
|
||||
if (cmd != NULL) {
|
||||
if (cmd) {
|
||||
cmd->command = SDL_RENDERCMD_SETDRAWCOLOR;
|
||||
cmd->data.color.first = 0; /* render backend will fill this in. */
|
||||
cmd->data.color.r = col->r;
|
||||
|
|
@ -428,7 +435,7 @@ static int QueueCmdSetDrawColor(SDL_Renderer *renderer, SDL_Color *col)
|
|||
static int QueueCmdClear(SDL_Renderer *renderer)
|
||||
{
|
||||
SDL_RenderCommand *cmd = AllocateRenderCommand(renderer);
|
||||
if (cmd == NULL) {
|
||||
if (!cmd) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -472,7 +479,7 @@ static SDL_RenderCommand *PrepQueueCmdDraw(SDL_Renderer *renderer, const SDL_Ren
|
|||
|
||||
if (retval == 0) {
|
||||
cmd = AllocateRenderCommand(renderer);
|
||||
if (cmd != NULL) {
|
||||
if (cmd) {
|
||||
cmd->command = cmdtype;
|
||||
cmd->data.draw.first = 0; /* render backend will fill this in. */
|
||||
cmd->data.draw.count = 0; /* render backend will fill this in. */
|
||||
|
|
@ -491,7 +498,7 @@ static int QueueCmdDrawPoints(SDL_Renderer *renderer, const SDL_FPoint *points,
|
|||
{
|
||||
SDL_RenderCommand *cmd = PrepQueueCmdDraw(renderer, SDL_RENDERCMD_DRAW_POINTS, NULL);
|
||||
int retval = -1;
|
||||
if (cmd != NULL) {
|
||||
if (cmd) {
|
||||
retval = renderer->QueueDrawPoints(renderer, cmd, points, count);
|
||||
if (retval < 0) {
|
||||
cmd->command = SDL_RENDERCMD_NO_OP;
|
||||
|
|
@ -504,7 +511,7 @@ static int QueueCmdDrawLines(SDL_Renderer *renderer, const SDL_FPoint *points, c
|
|||
{
|
||||
SDL_RenderCommand *cmd = PrepQueueCmdDraw(renderer, SDL_RENDERCMD_DRAW_LINES, NULL);
|
||||
int retval = -1;
|
||||
if (cmd != NULL) {
|
||||
if (cmd) {
|
||||
retval = renderer->QueueDrawLines(renderer, cmd, points, count);
|
||||
if (retval < 0) {
|
||||
cmd->command = SDL_RENDERCMD_NO_OP;
|
||||
|
|
@ -517,11 +524,11 @@ static int QueueCmdFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, con
|
|||
{
|
||||
SDL_RenderCommand *cmd;
|
||||
int retval = -1;
|
||||
const int use_rendergeometry = (renderer->QueueFillRects == NULL);
|
||||
const int use_rendergeometry = (!renderer->QueueFillRects);
|
||||
|
||||
cmd = PrepQueueCmdDraw(renderer, (use_rendergeometry ? SDL_RENDERCMD_GEOMETRY : SDL_RENDERCMD_FILL_RECTS), NULL);
|
||||
|
||||
if (cmd != NULL) {
|
||||
if (cmd) {
|
||||
if (use_rendergeometry) {
|
||||
SDL_bool isstack1;
|
||||
SDL_bool isstack2;
|
||||
|
|
@ -591,7 +598,7 @@ static int QueueCmdCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_
|
|||
{
|
||||
SDL_RenderCommand *cmd = PrepQueueCmdDraw(renderer, SDL_RENDERCMD_COPY, texture);
|
||||
int retval = -1;
|
||||
if (cmd != NULL) {
|
||||
if (cmd) {
|
||||
retval = renderer->QueueCopy(renderer, cmd, texture, srcrect, dstrect);
|
||||
if (retval < 0) {
|
||||
cmd->command = SDL_RENDERCMD_NO_OP;
|
||||
|
|
@ -606,7 +613,7 @@ static int QueueCmdCopyEx(SDL_Renderer *renderer, SDL_Texture *texture,
|
|||
{
|
||||
SDL_RenderCommand *cmd = PrepQueueCmdDraw(renderer, SDL_RENDERCMD_COPY_EX, texture);
|
||||
int retval = -1;
|
||||
if (cmd != NULL) {
|
||||
if (cmd) {
|
||||
retval = renderer->QueueCopyEx(renderer, cmd, texture, srcquad, dstrect, angle, center, flip, scale_x, scale_y);
|
||||
if (retval < 0) {
|
||||
cmd->command = SDL_RENDERCMD_NO_OP;
|
||||
|
|
@ -626,7 +633,7 @@ static int QueueCmdGeometry(SDL_Renderer *renderer, SDL_Texture *texture,
|
|||
SDL_RenderCommand *cmd;
|
||||
int retval = -1;
|
||||
cmd = PrepQueueCmdDraw(renderer, SDL_RENDERCMD_GEOMETRY, texture);
|
||||
if (cmd != NULL) {
|
||||
if (cmd) {
|
||||
retval = renderer->QueueGeometry(renderer, cmd, texture,
|
||||
xy, xy_stride,
|
||||
color, color_stride, uv, uv_stride,
|
||||
|
|
@ -643,7 +650,7 @@ static int UpdateLogicalSize(SDL_Renderer *renderer, SDL_bool flush_viewport_cmd
|
|||
|
||||
int SDL_GetNumRenderDrivers(void)
|
||||
{
|
||||
#if !SDL_RENDER_DISABLED
|
||||
#ifndef SDL_RENDER_DISABLED
|
||||
return SDL_arraysize(render_drivers);
|
||||
#else
|
||||
return 0;
|
||||
|
|
@ -652,7 +659,7 @@ int SDL_GetNumRenderDrivers(void)
|
|||
|
||||
int SDL_GetRenderDriverInfo(int index, SDL_RendererInfo *info)
|
||||
{
|
||||
#if !SDL_RENDER_DISABLED
|
||||
#ifndef SDL_RENDER_DISABLED
|
||||
if (index < 0 || index >= SDL_GetNumRenderDrivers()) {
|
||||
return SDL_SetError("index must be in the range of 0 - %d",
|
||||
SDL_GetNumRenderDrivers() - 1);
|
||||
|
|
@ -799,6 +806,20 @@ static int SDLCALL SDL_RendererEventWatch(void *userdata, SDL_Event *event)
|
|||
event->button.y = (int)(event->button.y / (scale.y * renderer->dpi_scale.y));
|
||||
}
|
||||
}
|
||||
} else if (event->type == SDL_MOUSEWHEEL) {
|
||||
SDL_Window *window = SDL_GetWindowFromID(event->wheel.windowID);
|
||||
if (window == renderer->window) {
|
||||
int logical_w, logical_h;
|
||||
SDL_DRect viewport;
|
||||
SDL_FPoint scale;
|
||||
GetWindowViewportValues(renderer, &logical_w, &logical_h, &viewport, &scale);
|
||||
if (logical_w) {
|
||||
event->wheel.mouseX -= (int)(viewport.x * renderer->dpi_scale.x);
|
||||
event->wheel.mouseY -= (int)(viewport.y * renderer->dpi_scale.y);
|
||||
event->wheel.mouseX = (int)(event->wheel.mouseX / (scale.x * renderer->dpi_scale.x));
|
||||
event->wheel.mouseY = (int)(event->wheel.mouseY / (scale.y * renderer->dpi_scale.y));
|
||||
}
|
||||
}
|
||||
} else if (event->type == SDL_FINGERDOWN ||
|
||||
event->type == SDL_FINGERUP ||
|
||||
event->type == SDL_FINGERMOTION) {
|
||||
|
|
@ -878,7 +899,7 @@ int SDL_CreateWindowAndRenderer(int width, int height, Uint32 window_flags,
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if !SDL_RENDER_DISABLED
|
||||
#ifndef SDL_RENDER_DISABLED
|
||||
static SDL_INLINE void VerifyDrawQueueFunctions(const SDL_Renderer *renderer)
|
||||
{
|
||||
/* all of these functions are required to be implemented, even as no-ops, so we don't
|
||||
|
|
@ -892,7 +913,7 @@ static SDL_INLINE void VerifyDrawQueueFunctions(const SDL_Renderer *renderer)
|
|||
SDL_assert(renderer->RunCommandQueue != NULL);
|
||||
}
|
||||
|
||||
static SDL_RenderLineMethod SDL_GetRenderLineMethod()
|
||||
static SDL_RenderLineMethod SDL_GetRenderLineMethod(void)
|
||||
{
|
||||
const char *hint = SDL_GetHint(SDL_HINT_RENDER_LINE_METHOD);
|
||||
|
||||
|
|
@ -935,17 +956,18 @@ static void SDL_CalculateSimulatedVSyncInterval(SDL_Renderer *renderer, SDL_Wind
|
|||
|
||||
SDL_Renderer *SDL_CreateRenderer(SDL_Window *window, int index, Uint32 flags)
|
||||
{
|
||||
#if !SDL_RENDER_DISABLED
|
||||
#ifndef SDL_RENDER_DISABLED
|
||||
SDL_Renderer *renderer = NULL;
|
||||
int n = SDL_GetNumRenderDrivers();
|
||||
SDL_bool batching = SDL_TRUE;
|
||||
const char *hint;
|
||||
int rc = -1;
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
Android_ActivityMutex_Lock_Running();
|
||||
#endif
|
||||
|
||||
if (window == NULL) {
|
||||
if (!window) {
|
||||
SDL_InvalidParamError("window");
|
||||
goto error;
|
||||
}
|
||||
|
|
@ -960,6 +982,14 @@ SDL_Renderer *SDL_CreateRenderer(SDL_Window *window, int index, Uint32 flags)
|
|||
goto error;
|
||||
}
|
||||
|
||||
renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(*renderer));
|
||||
if (!renderer) {
|
||||
SDL_OutOfMemory();
|
||||
goto error;
|
||||
}
|
||||
|
||||
renderer->magic = &renderer_magic;
|
||||
|
||||
hint = SDL_GetHint(SDL_HINT_RENDER_VSYNC);
|
||||
if (hint && *hint) {
|
||||
if (SDL_GetHintBoolean(SDL_HINT_RENDER_VSYNC, SDL_TRUE)) {
|
||||
|
|
@ -977,30 +1007,36 @@ SDL_Renderer *SDL_CreateRenderer(SDL_Window *window, int index, Uint32 flags)
|
|||
|
||||
if (SDL_strcasecmp(hint, driver->info.name) == 0) {
|
||||
/* Create a new renderer instance */
|
||||
renderer = driver->CreateRenderer(window, flags);
|
||||
if (renderer) {
|
||||
rc = driver->CreateRenderer(renderer, window, flags);
|
||||
if (rc == 0) {
|
||||
batching = SDL_FALSE;
|
||||
} else {
|
||||
SDL_zerop(renderer); /* make sure we don't leave function pointers from a previous CreateRenderer() in this struct. */
|
||||
renderer->magic = &renderer_magic;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (renderer == NULL) {
|
||||
if (rc == -1) {
|
||||
for (index = 0; index < n; ++index) {
|
||||
const SDL_RenderDriver *driver = render_drivers[index];
|
||||
|
||||
if ((driver->info.flags & flags) == flags) {
|
||||
/* Create a new renderer instance */
|
||||
renderer = driver->CreateRenderer(window, flags);
|
||||
if (renderer) {
|
||||
rc = driver->CreateRenderer(renderer, window, flags);
|
||||
if (rc == 0) {
|
||||
/* Yay, we got one! */
|
||||
break;
|
||||
} else {
|
||||
SDL_zerop(renderer); /* make sure we don't leave function pointers from a previous CreateRenderer() in this struct. */
|
||||
renderer->magic = &renderer_magic;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (renderer == NULL) {
|
||||
if (rc == -1) {
|
||||
SDL_SetError("Couldn't find matching render driver");
|
||||
goto error;
|
||||
}
|
||||
|
|
@ -1011,9 +1047,9 @@ SDL_Renderer *SDL_CreateRenderer(SDL_Window *window, int index, Uint32 flags)
|
|||
goto error;
|
||||
}
|
||||
/* Create a new renderer instance */
|
||||
renderer = render_drivers[index]->CreateRenderer(window, flags);
|
||||
rc = render_drivers[index]->CreateRenderer(renderer, window, flags);
|
||||
batching = SDL_FALSE;
|
||||
if (renderer == NULL) {
|
||||
if (rc == -1) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
|
@ -1094,6 +1130,7 @@ SDL_Renderer *SDL_CreateRenderer(SDL_Window *window, int index, Uint32 flags)
|
|||
return renderer;
|
||||
|
||||
error:
|
||||
SDL_free(renderer);
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
Android_ActivityMutex_Unlock();
|
||||
|
|
@ -1108,14 +1145,25 @@ error:
|
|||
|
||||
SDL_Renderer *SDL_CreateSoftwareRenderer(SDL_Surface *surface)
|
||||
{
|
||||
#if !SDL_RENDER_DISABLED && SDL_VIDEO_RENDER_SW
|
||||
#if SDL_VIDEO_RENDER_SW
|
||||
SDL_Renderer *renderer;
|
||||
int rc;
|
||||
|
||||
renderer = SW_CreateRendererForSurface(surface);
|
||||
renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(*renderer));
|
||||
if (!renderer) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (renderer) {
|
||||
renderer->magic = &renderer_magic;
|
||||
|
||||
rc = SW_CreateRendererForSurface(renderer, surface);
|
||||
|
||||
if (rc == -1) {
|
||||
SDL_free(renderer);
|
||||
renderer = NULL;
|
||||
} else {
|
||||
VerifyDrawQueueFunctions(renderer);
|
||||
renderer->magic = &renderer_magic;
|
||||
renderer->target_mutex = SDL_CreateMutex();
|
||||
renderer->scale.x = 1.0f;
|
||||
renderer->scale.y = 1.0f;
|
||||
|
|
@ -1228,7 +1276,7 @@ static SDL_ScaleMode SDL_GetScaleMode(void)
|
|||
{
|
||||
const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
|
||||
|
||||
if (hint == NULL || SDL_strcasecmp(hint, "nearest") == 0) {
|
||||
if (!hint || SDL_strcasecmp(hint, "nearest") == 0) {
|
||||
return SDL_ScaleModeNearest;
|
||||
} else if (SDL_strcasecmp(hint, "linear") == 0) {
|
||||
return SDL_ScaleModeLinear;
|
||||
|
|
@ -1269,7 +1317,7 @@ SDL_Texture *SDL_CreateTexture(SDL_Renderer *renderer, Uint32 format, int access
|
|||
return NULL;
|
||||
}
|
||||
texture = (SDL_Texture *)SDL_calloc(1, sizeof(*texture));
|
||||
if (texture == NULL) {
|
||||
if (!texture) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -1360,7 +1408,7 @@ SDL_Texture *SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *s
|
|||
|
||||
CHECK_RENDERER_MAGIC(renderer, NULL);
|
||||
|
||||
if (surface == NULL) {
|
||||
if (!surface) {
|
||||
SDL_InvalidParamError("SDL_CreateTextureFromSurface(): surface");
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -1424,7 +1472,7 @@ SDL_Texture *SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *s
|
|||
|
||||
texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STATIC,
|
||||
surface->w, surface->h);
|
||||
if (texture == NULL) {
|
||||
if (!texture) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -1468,7 +1516,7 @@ SDL_Texture *SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *s
|
|||
|
||||
/* Set up a destination surface for the texture update */
|
||||
dst_fmt = SDL_AllocFormat(format);
|
||||
if (dst_fmt == NULL) {
|
||||
if (!dst_fmt) {
|
||||
SDL_DestroyTexture(texture);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -1687,7 +1735,7 @@ static int SDL_UpdateTextureYUV(SDL_Texture *texture, const SDL_Rect *rect,
|
|||
const size_t alloclen = (size_t)rect->h * temp_pitch;
|
||||
if (alloclen > 0) {
|
||||
void *temp_pixels = SDL_malloc(alloclen);
|
||||
if (temp_pixels == NULL) {
|
||||
if (!temp_pixels) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format,
|
||||
|
|
@ -1727,7 +1775,7 @@ static int SDL_UpdateTextureNative(SDL_Texture *texture, const SDL_Rect *rect,
|
|||
const size_t alloclen = (size_t)rect->h * temp_pitch;
|
||||
if (alloclen > 0) {
|
||||
void *temp_pixels = SDL_malloc(alloclen);
|
||||
if (temp_pixels == NULL) {
|
||||
if (!temp_pixels) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_ConvertPixels(rect->w, rect->h,
|
||||
|
|
@ -1747,7 +1795,7 @@ int SDL_UpdateTexture(SDL_Texture *texture, const SDL_Rect *rect,
|
|||
|
||||
CHECK_TEXTURE_MAGIC(texture, -1);
|
||||
|
||||
if (pixels == NULL) {
|
||||
if (!pixels) {
|
||||
return SDL_InvalidParamError("pixels");
|
||||
}
|
||||
if (!pitch) {
|
||||
|
|
@ -1821,7 +1869,7 @@ static int SDL_UpdateTextureYUVPlanar(SDL_Texture *texture, const SDL_Rect *rect
|
|||
const size_t alloclen = (size_t)rect->h * temp_pitch;
|
||||
if (alloclen > 0) {
|
||||
void *temp_pixels = SDL_malloc(alloclen);
|
||||
if (temp_pixels == NULL) {
|
||||
if (!temp_pixels) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format,
|
||||
|
|
@ -1871,7 +1919,7 @@ static int SDL_UpdateTextureNVPlanar(SDL_Texture *texture, const SDL_Rect *rect,
|
|||
const size_t alloclen = (size_t)rect->h * temp_pitch;
|
||||
if (alloclen > 0) {
|
||||
void *temp_pixels = SDL_malloc(alloclen);
|
||||
if (temp_pixels == NULL) {
|
||||
if (!temp_pixels) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format,
|
||||
|
|
@ -1896,19 +1944,19 @@ int SDL_UpdateYUVTexture(SDL_Texture *texture, const SDL_Rect *rect,
|
|||
|
||||
CHECK_TEXTURE_MAGIC(texture, -1);
|
||||
|
||||
if (Yplane == NULL) {
|
||||
if (!Yplane) {
|
||||
return SDL_InvalidParamError("Yplane");
|
||||
}
|
||||
if (!Ypitch) {
|
||||
return SDL_InvalidParamError("Ypitch");
|
||||
}
|
||||
if (Uplane == NULL) {
|
||||
if (!Uplane) {
|
||||
return SDL_InvalidParamError("Uplane");
|
||||
}
|
||||
if (!Upitch) {
|
||||
return SDL_InvalidParamError("Upitch");
|
||||
}
|
||||
if (Vplane == NULL) {
|
||||
if (!Vplane) {
|
||||
return SDL_InvalidParamError("Vplane");
|
||||
}
|
||||
if (!Vpitch) {
|
||||
|
|
@ -1962,13 +2010,13 @@ int SDL_UpdateNVTexture(SDL_Texture *texture, const SDL_Rect *rect,
|
|||
|
||||
CHECK_TEXTURE_MAGIC(texture, -1);
|
||||
|
||||
if (Yplane == NULL) {
|
||||
if (!Yplane) {
|
||||
return SDL_InvalidParamError("Yplane");
|
||||
}
|
||||
if (!Ypitch) {
|
||||
return SDL_InvalidParamError("Ypitch");
|
||||
}
|
||||
if (UVplane == NULL) {
|
||||
if (!UVplane) {
|
||||
return SDL_InvalidParamError("UVplane");
|
||||
}
|
||||
if (!UVpitch) {
|
||||
|
|
@ -2042,7 +2090,7 @@ int SDL_LockTexture(SDL_Texture *texture, const SDL_Rect *rect,
|
|||
return SDL_SetError("SDL_LockTexture(): texture must be streaming");
|
||||
}
|
||||
|
||||
if (rect == NULL) {
|
||||
if (!rect) {
|
||||
full_rect.x = 0;
|
||||
full_rect.y = 0;
|
||||
full_rect.w = texture->w;
|
||||
|
|
@ -2078,7 +2126,7 @@ int SDL_LockTextureToSurface(SDL_Texture *texture, const SDL_Rect *rect,
|
|||
int pitch = 0; /* fix static analysis */
|
||||
int ret;
|
||||
|
||||
if (texture == NULL || surface == NULL) {
|
||||
if (!texture || !surface) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -2096,7 +2144,7 @@ int SDL_LockTextureToSurface(SDL_Texture *texture, const SDL_Rect *rect,
|
|||
}
|
||||
|
||||
texture->locked_surface = SDL_CreateRGBSurfaceWithFormatFrom(pixels, real_rect.w, real_rect.h, 0, pitch, texture->format);
|
||||
if (texture->locked_surface == NULL) {
|
||||
if (!texture->locked_surface) {
|
||||
SDL_UnlockTexture(texture);
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -2172,7 +2220,7 @@ void SDL_UnlockTexture(SDL_Texture *texture)
|
|||
|
||||
SDL_bool SDL_RenderTargetSupported(SDL_Renderer *renderer)
|
||||
{
|
||||
if (renderer == NULL || !renderer->SetRenderTarget) {
|
||||
if (!renderer || !renderer->SetRenderTarget) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
return (renderer->info.flags & SDL_RENDERER_TARGETTEXTURE) != 0;
|
||||
|
|
@ -2660,7 +2708,7 @@ static int RenderDrawPointsWithRects(SDL_Renderer *renderer,
|
|||
}
|
||||
|
||||
frects = SDL_small_alloc(SDL_FRect, count, &isstack);
|
||||
if (frects == NULL) {
|
||||
if (!frects) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
|
|
@ -2688,7 +2736,7 @@ int SDL_RenderDrawPoints(SDL_Renderer *renderer,
|
|||
|
||||
CHECK_RENDERER_MAGIC(renderer, -1);
|
||||
|
||||
if (points == NULL) {
|
||||
if (!points) {
|
||||
return SDL_InvalidParamError("SDL_RenderDrawPoints(): points");
|
||||
}
|
||||
if (count < 1) {
|
||||
|
|
@ -2706,7 +2754,7 @@ int SDL_RenderDrawPoints(SDL_Renderer *renderer,
|
|||
retval = RenderDrawPointsWithRects(renderer, points, count);
|
||||
} else {
|
||||
fpoints = SDL_small_alloc(SDL_FPoint, count, &isstack);
|
||||
if (fpoints == NULL) {
|
||||
if (!fpoints) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
for (i = 0; i < count; ++i) {
|
||||
|
|
@ -2734,7 +2782,7 @@ static int RenderDrawPointsWithRectsF(SDL_Renderer *renderer,
|
|||
}
|
||||
|
||||
frects = SDL_small_alloc(SDL_FRect, count, &isstack);
|
||||
if (frects == NULL) {
|
||||
if (!frects) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
|
|
@ -2759,7 +2807,7 @@ int SDL_RenderDrawPointsF(SDL_Renderer *renderer,
|
|||
|
||||
CHECK_RENDERER_MAGIC(renderer, -1);
|
||||
|
||||
if (points == NULL) {
|
||||
if (!points) {
|
||||
return SDL_InvalidParamError("SDL_RenderDrawPointsF(): points");
|
||||
}
|
||||
if (count < 1) {
|
||||
|
|
@ -2810,6 +2858,18 @@ static int RenderDrawLineBresenham(SDL_Renderer *renderer, int x1, int y1, int x
|
|||
int retval;
|
||||
SDL_bool isstack;
|
||||
SDL_FPoint *points;
|
||||
SDL_Rect clip_rect;
|
||||
|
||||
/* the backend might clip this further to the clipping rect, but we
|
||||
just want a basic safety against generating millions of points for
|
||||
massive lines. */
|
||||
clip_rect.x = 0;
|
||||
clip_rect.y = 0;
|
||||
clip_rect.w = (int) renderer->viewport.w;
|
||||
clip_rect.h = (int) renderer->viewport.h;
|
||||
if (!SDL_IntersectRectAndLine(&clip_rect, &x1, &y1, &x2, &y2)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
deltax = SDL_abs(x2 - x1);
|
||||
deltay = SDL_abs(y2 - y1);
|
||||
|
|
@ -2851,7 +2911,7 @@ static int RenderDrawLineBresenham(SDL_Renderer *renderer, int x1, int y1, int x
|
|||
}
|
||||
|
||||
points = SDL_small_alloc(SDL_FPoint, numpixels, &isstack);
|
||||
if (points == NULL) {
|
||||
if (!points) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
for (i = 0; i < numpixels; ++i) {
|
||||
|
|
@ -2894,7 +2954,7 @@ static int RenderDrawLinesWithRectsF(SDL_Renderer *renderer,
|
|||
SDL_bool draw_last = SDL_FALSE;
|
||||
|
||||
frects = SDL_small_alloc(SDL_FRect, count - 1, &isstack);
|
||||
if (frects == NULL) {
|
||||
if (!frects) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
|
|
@ -2964,7 +3024,7 @@ int SDL_RenderDrawLines(SDL_Renderer *renderer,
|
|||
|
||||
CHECK_RENDERER_MAGIC(renderer, -1);
|
||||
|
||||
if (points == NULL) {
|
||||
if (!points) {
|
||||
return SDL_InvalidParamError("SDL_RenderDrawLines(): points");
|
||||
}
|
||||
if (count < 2) {
|
||||
|
|
@ -2979,7 +3039,7 @@ int SDL_RenderDrawLines(SDL_Renderer *renderer,
|
|||
#endif
|
||||
|
||||
fpoints = SDL_small_alloc(SDL_FPoint, count, &isstack);
|
||||
if (fpoints == NULL) {
|
||||
if (!fpoints) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
|
|
@ -3002,7 +3062,7 @@ int SDL_RenderDrawLinesF(SDL_Renderer *renderer,
|
|||
|
||||
CHECK_RENDERER_MAGIC(renderer, -1);
|
||||
|
||||
if (points == NULL) {
|
||||
if (!points) {
|
||||
return SDL_InvalidParamError("SDL_RenderDrawLinesF(): points");
|
||||
}
|
||||
if (count < 2) {
|
||||
|
|
@ -3171,7 +3231,7 @@ int SDL_RenderDrawRectF(SDL_Renderer *renderer, const SDL_FRect *rect)
|
|||
CHECK_RENDERER_MAGIC(renderer, -1);
|
||||
|
||||
/* If 'rect' == NULL, then outline the whole surface */
|
||||
if (rect == NULL) {
|
||||
if (!rect) {
|
||||
RenderGetViewportSize(renderer, &frect);
|
||||
rect = &frect;
|
||||
}
|
||||
|
|
@ -3196,7 +3256,7 @@ int SDL_RenderDrawRects(SDL_Renderer *renderer,
|
|||
|
||||
CHECK_RENDERER_MAGIC(renderer, -1);
|
||||
|
||||
if (rects == NULL) {
|
||||
if (!rects) {
|
||||
return SDL_InvalidParamError("SDL_RenderDrawRects(): rects");
|
||||
}
|
||||
if (count < 1) {
|
||||
|
|
@ -3225,7 +3285,7 @@ int SDL_RenderDrawRectsF(SDL_Renderer *renderer,
|
|||
|
||||
CHECK_RENDERER_MAGIC(renderer, -1);
|
||||
|
||||
if (rects == NULL) {
|
||||
if (!rects) {
|
||||
return SDL_InvalidParamError("SDL_RenderDrawRectsF(): rects");
|
||||
}
|
||||
if (count < 1) {
|
||||
|
|
@ -3272,7 +3332,7 @@ int SDL_RenderFillRectF(SDL_Renderer *renderer, const SDL_FRect *rect)
|
|||
CHECK_RENDERER_MAGIC(renderer, -1);
|
||||
|
||||
/* If 'rect' == NULL, then outline the whole surface */
|
||||
if (rect == NULL) {
|
||||
if (!rect) {
|
||||
RenderGetViewportSize(renderer, &frect);
|
||||
rect = &frect;
|
||||
}
|
||||
|
|
@ -3289,7 +3349,7 @@ int SDL_RenderFillRects(SDL_Renderer *renderer,
|
|||
|
||||
CHECK_RENDERER_MAGIC(renderer, -1);
|
||||
|
||||
if (rects == NULL) {
|
||||
if (!rects) {
|
||||
return SDL_InvalidParamError("SDL_RenderFillRects(): rects");
|
||||
}
|
||||
if (count < 1) {
|
||||
|
|
@ -3304,7 +3364,7 @@ int SDL_RenderFillRects(SDL_Renderer *renderer,
|
|||
#endif
|
||||
|
||||
frects = SDL_small_alloc(SDL_FRect, count, &isstack);
|
||||
if (frects == NULL) {
|
||||
if (!frects) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
for (i = 0; i < count; ++i) {
|
||||
|
|
@ -3331,7 +3391,7 @@ int SDL_RenderFillRectsF(SDL_Renderer *renderer,
|
|||
|
||||
CHECK_RENDERER_MAGIC(renderer, -1);
|
||||
|
||||
if (rects == NULL) {
|
||||
if (!rects) {
|
||||
return SDL_InvalidParamError("SDL_RenderFillRectsF(): rects");
|
||||
}
|
||||
if (count < 1) {
|
||||
|
|
@ -3346,7 +3406,7 @@ int SDL_RenderFillRectsF(SDL_Renderer *renderer,
|
|||
#endif
|
||||
|
||||
frects = SDL_small_alloc(SDL_FRect, count, &isstack);
|
||||
if (frects == NULL) {
|
||||
if (!frects) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
for (i = 0; i < count; ++i) {
|
||||
|
|
@ -3400,7 +3460,7 @@ int SDL_RenderCopyF(SDL_Renderer *renderer, SDL_Texture *texture,
|
|||
}
|
||||
#endif
|
||||
|
||||
use_rendergeometry = (renderer->QueueCopy == NULL);
|
||||
use_rendergeometry = (!renderer->QueueCopy);
|
||||
|
||||
real_srcrect.x = 0;
|
||||
real_srcrect.y = 0;
|
||||
|
|
@ -3540,7 +3600,7 @@ int SDL_RenderCopyExF(SDL_Renderer *renderer, SDL_Texture *texture,
|
|||
}
|
||||
#endif
|
||||
|
||||
use_rendergeometry = (renderer->QueueCopyEx == NULL);
|
||||
use_rendergeometry = (!renderer->QueueCopyEx);
|
||||
|
||||
real_srcrect.x = 0;
|
||||
real_srcrect.y = 0;
|
||||
|
|
@ -4071,15 +4131,15 @@ int SDL_RenderGeometryRaw(SDL_Renderer *renderer,
|
|||
}
|
||||
}
|
||||
|
||||
if (xy == NULL) {
|
||||
if (!xy) {
|
||||
return SDL_InvalidParamError("xy");
|
||||
}
|
||||
|
||||
if (color == NULL) {
|
||||
if (!color) {
|
||||
return SDL_InvalidParamError("color");
|
||||
}
|
||||
|
||||
if (texture && uv == NULL) {
|
||||
if (texture && !uv) {
|
||||
return SDL_InvalidParamError("uv");
|
||||
}
|
||||
|
||||
|
|
@ -4171,7 +4231,7 @@ int SDL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
|
|||
FlushRenderCommands(renderer); /* we need to render before we read the results. */
|
||||
|
||||
if (!format) {
|
||||
if (renderer->target == NULL) {
|
||||
if (!renderer->target) {
|
||||
format = SDL_GetWindowPixelFormat(renderer->window);
|
||||
} else {
|
||||
format = renderer->target->format;
|
||||
|
|
@ -4292,15 +4352,18 @@ void SDL_DestroyTexture(SDL_Texture *texture)
|
|||
SDL_free(texture);
|
||||
}
|
||||
|
||||
void SDL_DestroyRenderer(SDL_Renderer *renderer)
|
||||
void SDL_DestroyRendererWithoutFreeing(SDL_Renderer *renderer)
|
||||
{
|
||||
SDL_RenderCommand *cmd;
|
||||
|
||||
CHECK_RENDERER_MAGIC(renderer, );
|
||||
SDL_assert(renderer != NULL);
|
||||
SDL_assert(!renderer->destroyed);
|
||||
|
||||
renderer->destroyed = SDL_TRUE;
|
||||
|
||||
SDL_DelEventWatch(SDL_RendererEventWatch, renderer);
|
||||
|
||||
if (renderer->render_commands_tail != NULL) {
|
||||
if (renderer->render_commands_tail) {
|
||||
renderer->render_commands_tail->next = renderer->render_commands_pool;
|
||||
cmd = renderer->render_commands;
|
||||
} else {
|
||||
|
|
@ -4311,7 +4374,7 @@ void SDL_DestroyRenderer(SDL_Renderer *renderer)
|
|||
renderer->render_commands_tail = NULL;
|
||||
renderer->render_commands = NULL;
|
||||
|
||||
while (cmd != NULL) {
|
||||
while (cmd) {
|
||||
SDL_RenderCommand *next = cmd->next;
|
||||
SDL_free(cmd);
|
||||
cmd = next;
|
||||
|
|
@ -4331,9 +4394,6 @@ void SDL_DestroyRenderer(SDL_Renderer *renderer)
|
|||
SDL_SetWindowData(renderer->window, SDL_WINDOWRENDERDATA, NULL);
|
||||
}
|
||||
|
||||
/* It's no longer magical... */
|
||||
renderer->magic = NULL;
|
||||
|
||||
/* Free the target mutex */
|
||||
SDL_DestroyMutex(renderer->target_mutex);
|
||||
renderer->target_mutex = NULL;
|
||||
|
|
@ -4342,6 +4402,22 @@ void SDL_DestroyRenderer(SDL_Renderer *renderer)
|
|||
renderer->DestroyRenderer(renderer);
|
||||
}
|
||||
|
||||
void SDL_DestroyRenderer(SDL_Renderer *renderer)
|
||||
{
|
||||
CHECK_RENDERER_MAGIC_BUT_NOT_DESTROYED_FLAG(renderer,);
|
||||
|
||||
/* if we've already destroyed the renderer through SDL_DestroyWindow, we just need
|
||||
to free the renderer pointer. This lets apps destroy the window and renderer
|
||||
in either order. */
|
||||
if (!renderer->destroyed) {
|
||||
SDL_DestroyRendererWithoutFreeing(renderer);
|
||||
renderer->magic = NULL; // It's no longer magical...
|
||||
}
|
||||
|
||||
SDL_free(renderer);
|
||||
}
|
||||
|
||||
|
||||
int SDL_GL_BindTexture(SDL_Texture *texture, float *texw, float *texh)
|
||||
{
|
||||
SDL_Renderer *renderer;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -282,13 +282,15 @@ struct SDL_Renderer
|
|||
size_t vertex_data_used;
|
||||
size_t vertex_data_allocation;
|
||||
|
||||
SDL_bool destroyed; /* already destroyed by SDL_DestroyWindow; just free this struct in SDL_DestroyRenderer. */
|
||||
|
||||
void *driverdata;
|
||||
};
|
||||
|
||||
/* Define the SDL render driver structure */
|
||||
struct SDL_RenderDriver
|
||||
{
|
||||
SDL_Renderer *(*CreateRenderer)(SDL_Window *window, Uint32 flags);
|
||||
int (*CreateRenderer)(SDL_Renderer *renderer, SDL_Window *window, Uint32 flags);
|
||||
|
||||
/* Info about the renderer capabilities */
|
||||
SDL_RendererInfo info;
|
||||
|
|
@ -324,6 +326,9 @@ extern void *SDL_AllocateRenderVertices(SDL_Renderer *renderer, const size_t num
|
|||
extern int SDL_PrivateLowerBlitScaled(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
|
||||
extern int SDL_PrivateUpperBlitScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
|
||||
|
||||
/* Let the video subsystem destroy a renderer without making its pointer invalid. */
|
||||
extern void SDL_DestroyRendererWithoutFreeing(SDL_Renderer *renderer);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -47,7 +47,7 @@ SDL_SW_YUVTexture *SDL_SW_CreateYUVTexture(Uint32 format, int w, int h)
|
|||
}
|
||||
|
||||
swdata = (SDL_SW_YUVTexture *)SDL_calloc(1, sizeof(*swdata));
|
||||
if (swdata == NULL) {
|
||||
if (!swdata) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
#include "SDL_render.h"
|
||||
#include "SDL_system.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_D3D
|
||||
|
||||
#include "../../core/windows/SDL_windows.h"
|
||||
|
||||
|
|
@ -443,7 +443,7 @@ static int D3D_CreateStagingTexture(IDirect3DDevice9 *device, D3D_TextureRep *te
|
|||
{
|
||||
HRESULT result;
|
||||
|
||||
if (texture->staging == NULL) {
|
||||
if (!texture->staging) {
|
||||
result = IDirect3DDevice9_CreateTexture(device, texture->w, texture->h, 1, 0,
|
||||
texture->d3dfmt, D3DPOOL_SYSTEMMEM, &texture->staging, NULL);
|
||||
if (FAILED(result)) {
|
||||
|
|
@ -535,7 +535,7 @@ static int D3D_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
DWORD usage;
|
||||
|
||||
texturedata = (D3D_TextureData *)SDL_calloc(1, sizeof(*texturedata));
|
||||
if (texturedata == NULL) {
|
||||
if (!texturedata) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
texturedata->scaleMode = (texture->scaleMode == SDL_ScaleModeNearest) ? D3DTEXF_POINT : D3DTEXF_LINEAR;
|
||||
|
|
@ -573,7 +573,7 @@ static int D3D_RecreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
|
||||
D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata;
|
||||
|
||||
if (texturedata == NULL) {
|
||||
if (!texturedata) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -600,7 +600,7 @@ static int D3D_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
|
|||
D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
|
||||
D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata;
|
||||
|
||||
if (texturedata == NULL) {
|
||||
if (!texturedata) {
|
||||
return SDL_SetError("Texture is not currently available");
|
||||
}
|
||||
|
||||
|
|
@ -636,7 +636,7 @@ static int D3D_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture,
|
|||
D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
|
||||
D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata;
|
||||
|
||||
if (texturedata == NULL) {
|
||||
if (!texturedata) {
|
||||
return SDL_SetError("Texture is not currently available");
|
||||
}
|
||||
|
||||
|
|
@ -660,7 +660,7 @@ static int D3D_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
|
|||
D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata;
|
||||
IDirect3DDevice9 *device = data->device;
|
||||
|
||||
if (texturedata == NULL) {
|
||||
if (!texturedata) {
|
||||
return SDL_SetError("Texture is not currently available");
|
||||
}
|
||||
#if SDL_HAVE_YUV
|
||||
|
|
@ -710,7 +710,7 @@ static void D3D_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
|
||||
D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata;
|
||||
|
||||
if (texturedata == NULL) {
|
||||
if (!texturedata) {
|
||||
return;
|
||||
}
|
||||
#if SDL_HAVE_YUV
|
||||
|
|
@ -738,7 +738,7 @@ static void D3D_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *texture
|
|||
{
|
||||
D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata;
|
||||
|
||||
if (texturedata == NULL) {
|
||||
if (!texturedata) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -754,18 +754,18 @@ static int D3D_SetRenderTargetInternal(SDL_Renderer *renderer, SDL_Texture *text
|
|||
IDirect3DDevice9 *device = data->device;
|
||||
|
||||
/* Release the previous render target if it wasn't the default one */
|
||||
if (data->currentRenderTarget != NULL) {
|
||||
if (data->currentRenderTarget) {
|
||||
IDirect3DSurface9_Release(data->currentRenderTarget);
|
||||
data->currentRenderTarget = NULL;
|
||||
}
|
||||
|
||||
if (texture == NULL) {
|
||||
if (!texture) {
|
||||
IDirect3DDevice9_SetRenderTarget(data->device, 0, data->defaultRenderTarget);
|
||||
return 0;
|
||||
}
|
||||
|
||||
texturedata = (D3D_TextureData *)texture->driverdata;
|
||||
if (texturedata == NULL) {
|
||||
if (!texturedata) {
|
||||
return SDL_SetError("Texture is not currently available");
|
||||
}
|
||||
|
||||
|
|
@ -820,7 +820,7 @@ static int D3D_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, c
|
|||
Vertex *verts = (Vertex *)SDL_AllocateRenderVertices(renderer, vertslen, 0, &cmd->data.draw.first);
|
||||
int i;
|
||||
|
||||
if (verts == NULL) {
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -845,7 +845,7 @@ static int D3D_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL
|
|||
int count = indices ? num_indices : num_vertices;
|
||||
Vertex *verts = (Vertex *)SDL_AllocateRenderVertices(renderer, count * sizeof(Vertex), 0, &cmd->data.draw.first);
|
||||
|
||||
if (verts == NULL) {
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -941,7 +941,7 @@ static int SetupTextureState(D3D_RenderData *data, SDL_Texture *texture, LPDIREC
|
|||
|
||||
SDL_assert(*shader == NULL);
|
||||
|
||||
if (texturedata == NULL) {
|
||||
if (!texturedata) {
|
||||
return SDL_SetError("Texture is not currently available");
|
||||
}
|
||||
|
||||
|
|
@ -993,11 +993,11 @@ static int SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd)
|
|||
LPDIRECT3DPIXELSHADER9 shader = NULL;
|
||||
|
||||
/* disable any enabled textures we aren't going to use, let SetupTextureState() do the rest. */
|
||||
if (texture == NULL) {
|
||||
if (!texture) {
|
||||
IDirect3DDevice9_SetTexture(data->device, 0, NULL);
|
||||
}
|
||||
#if SDL_HAVE_YUV
|
||||
if ((newtexturedata == NULL || !newtexturedata->yuv) && (oldtexturedata && oldtexturedata->yuv)) {
|
||||
if ((!newtexturedata || !newtexturedata->yuv) && (oldtexturedata && oldtexturedata->yuv)) {
|
||||
IDirect3DDevice9_SetTexture(data->device, 1, NULL);
|
||||
IDirect3DDevice9_SetTexture(data->device, 2, NULL);
|
||||
}
|
||||
|
|
@ -1170,6 +1170,7 @@ static int D3D_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, v
|
|||
if (SDL_memcmp(viewport, &cmd->data.viewport.rect, sizeof(cmd->data.viewport.rect)) != 0) {
|
||||
SDL_copyp(viewport, &cmd->data.viewport.rect);
|
||||
data->drawstate.viewport_dirty = SDL_TRUE;
|
||||
data->drawstate.cliprect_dirty = SDL_TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -1391,7 +1392,7 @@ static void D3D_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
#endif
|
||||
}
|
||||
|
||||
if (data == NULL) {
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1417,7 +1418,7 @@ static void D3D_DestroyRenderer(SDL_Renderer *renderer)
|
|||
IDirect3DSurface9_Release(data->defaultRenderTarget);
|
||||
data->defaultRenderTarget = NULL;
|
||||
}
|
||||
if (data->currentRenderTarget != NULL) {
|
||||
if (data->currentRenderTarget) {
|
||||
IDirect3DSurface9_Release(data->currentRenderTarget);
|
||||
data->currentRenderTarget = NULL;
|
||||
}
|
||||
|
|
@ -1446,7 +1447,6 @@ static void D3D_DestroyRenderer(SDL_Renderer *renderer)
|
|||
}
|
||||
SDL_free(data);
|
||||
}
|
||||
SDL_free(renderer);
|
||||
}
|
||||
|
||||
static int D3D_Reset(SDL_Renderer *renderer)
|
||||
|
|
@ -1468,7 +1468,7 @@ static int D3D_Reset(SDL_Renderer *renderer)
|
|||
IDirect3DSurface9_Release(data->defaultRenderTarget);
|
||||
data->defaultRenderTarget = NULL;
|
||||
}
|
||||
if (data->currentRenderTarget != NULL) {
|
||||
if (data->currentRenderTarget) {
|
||||
IDirect3DSurface9_Release(data->currentRenderTarget);
|
||||
data->currentRenderTarget = NULL;
|
||||
}
|
||||
|
|
@ -1546,9 +1546,8 @@ static int D3D_SetVSync(SDL_Renderer *renderer, const int vsync)
|
|||
return 0;
|
||||
}
|
||||
|
||||
SDL_Renderer *D3D_CreateRenderer(SDL_Window *window, Uint32 flags)
|
||||
int D3D_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, Uint32 flags)
|
||||
{
|
||||
SDL_Renderer *renderer;
|
||||
D3D_RenderData *data;
|
||||
SDL_SysWMinfo windowinfo;
|
||||
HRESULT result;
|
||||
|
|
@ -1561,24 +1560,14 @@ SDL_Renderer *D3D_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
SDL_DisplayMode fullscreen_mode;
|
||||
int displayIndex;
|
||||
|
||||
renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
|
||||
if (renderer == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
data = (D3D_RenderData *)SDL_calloc(1, sizeof(*data));
|
||||
if (data == NULL) {
|
||||
SDL_free(renderer);
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
if (!data) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
if (!D3D_LoadDLL(&data->d3dDLL, &data->d3d)) {
|
||||
SDL_free(renderer);
|
||||
SDL_free(data);
|
||||
SDL_SetError("Unable to create Direct3D interface");
|
||||
return NULL;
|
||||
return SDL_SetError("Unable to create Direct3D interface");
|
||||
}
|
||||
|
||||
renderer->WindowEvent = D3D_WindowEvent;
|
||||
|
|
@ -1609,7 +1598,11 @@ SDL_Renderer *D3D_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
renderer->driverdata = data;
|
||||
|
||||
SDL_VERSION(&windowinfo.version);
|
||||
SDL_GetWindowWMInfo(window, &windowinfo);
|
||||
if (!SDL_GetWindowWMInfo(window, &windowinfo) ||
|
||||
windowinfo.subsystem != SDL_SYSWM_WINDOWS) {
|
||||
SDL_free(data);
|
||||
return SDL_SetError("Couldn't get window handle");
|
||||
}
|
||||
|
||||
window_flags = SDL_GetWindowFlags(window);
|
||||
SDL_GetWindowSizeInPixels(window, &w, &h);
|
||||
|
|
@ -1661,23 +1654,20 @@ SDL_Renderer *D3D_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
&pparams, &data->device);
|
||||
if (FAILED(result)) {
|
||||
D3D_DestroyRenderer(renderer);
|
||||
D3D_SetError("CreateDevice()", result);
|
||||
return NULL;
|
||||
return D3D_SetError("CreateDevice()", result);
|
||||
}
|
||||
|
||||
/* Get presentation parameters to fill info */
|
||||
result = IDirect3DDevice9_GetSwapChain(data->device, 0, &chain);
|
||||
if (FAILED(result)) {
|
||||
D3D_DestroyRenderer(renderer);
|
||||
D3D_SetError("GetSwapChain()", result);
|
||||
return NULL;
|
||||
return D3D_SetError("GetSwapChain()", result);
|
||||
}
|
||||
result = IDirect3DSwapChain9_GetPresentParameters(chain, &pparams);
|
||||
if (FAILED(result)) {
|
||||
IDirect3DSwapChain9_Release(chain);
|
||||
D3D_DestroyRenderer(renderer);
|
||||
D3D_SetError("GetPresentParameters()", result);
|
||||
return NULL;
|
||||
return D3D_SetError("GetPresentParameters()", result);
|
||||
}
|
||||
IDirect3DSwapChain9_Release(chain);
|
||||
if (pparams.PresentationInterval == D3DPRESENT_INTERVAL_ONE) {
|
||||
|
|
@ -1719,7 +1709,7 @@ SDL_Renderer *D3D_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
data->drawstate.cliprect_enabled_dirty = SDL_TRUE;
|
||||
data->drawstate.blend = SDL_BLENDMODE_INVALID;
|
||||
|
||||
return renderer;
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_RenderDriver D3D_RenderDriver = {
|
||||
|
|
@ -1731,7 +1721,7 @@ SDL_RenderDriver D3D_RenderDriver = {
|
|||
0,
|
||||
0 }
|
||||
};
|
||||
#endif /* SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_D3D */
|
||||
|
||||
#if defined(__WIN32__) || defined(__WINGDK__)
|
||||
/* This function needs to always exist on Windows, for the Dynamic API. */
|
||||
|
|
@ -1739,7 +1729,7 @@ IDirect3DDevice9 *SDL_RenderGetD3D9Device(SDL_Renderer *renderer)
|
|||
{
|
||||
IDirect3DDevice9 *device = NULL;
|
||||
|
||||
#if SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_D3D
|
||||
D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
|
||||
|
||||
/* Make sure that this is a D3D renderer */
|
||||
|
|
@ -1752,7 +1742,7 @@ IDirect3DDevice9 *SDL_RenderGetD3D9Device(SDL_Renderer *renderer)
|
|||
if (device) {
|
||||
IDirect3DDevice9_AddRef(device);
|
||||
}
|
||||
#endif /* SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_D3D */
|
||||
|
||||
return device;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
#include "SDL_render.h"
|
||||
#include "SDL_system.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_D3D
|
||||
|
||||
#include "../../core/windows/SDL_windows.h"
|
||||
|
||||
|
|
@ -268,6 +268,6 @@ HRESULT D3D9_CreatePixelShader(IDirect3DDevice9 *d3dDevice, D3D9_Shader shader,
|
|||
return IDirect3DDevice9_CreatePixelShader(d3dDevice, D3D9_shaders[shader], pixelShader);
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_D3D */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
#include "SDL_render.h"
|
||||
#include "SDL_system.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_D3D11
|
||||
|
||||
#define COBJMACROS
|
||||
#include "../../core/windows/SDL_windows.h"
|
||||
|
|
@ -304,7 +304,6 @@ static void D3D11_DestroyRenderer(SDL_Renderer *renderer)
|
|||
if (data) {
|
||||
SDL_free(data);
|
||||
}
|
||||
SDL_free(renderer);
|
||||
}
|
||||
|
||||
static D3D11_BLEND GetBlendFunc(SDL_BlendFactor factor)
|
||||
|
|
@ -385,7 +384,7 @@ static ID3D11BlendState *D3D11_CreateBlendState(SDL_Renderer *renderer, SDL_Blen
|
|||
}
|
||||
|
||||
blendModes = (D3D11_BlendMode *)SDL_realloc(data->blendModes, (data->blendModesCount + 1) * sizeof(*blendModes));
|
||||
if (blendModes == NULL) {
|
||||
if (!blendModes) {
|
||||
SAFE_RELEASE(blendState);
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
|
|
@ -442,7 +441,7 @@ static HRESULT D3D11_CreateDeviceResources(SDL_Renderer *renderer)
|
|||
}
|
||||
|
||||
CreateDXGIFactoryFunc = (PFN_CREATE_DXGI_FACTORY)SDL_LoadFunction(data->hDXGIMod, "CreateDXGIFactory");
|
||||
if (CreateDXGIFactoryFunc == NULL) {
|
||||
if (!CreateDXGIFactoryFunc) {
|
||||
result = E_FAIL;
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -740,7 +739,7 @@ static HRESULT D3D11_CreateSwapChain(SDL_Renderer *renderer, int w, int h)
|
|||
D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata;
|
||||
#ifdef __WINRT__
|
||||
IUnknown *coreWindow = D3D11_GetCoreWindowFromSDLRenderer(renderer);
|
||||
const BOOL usingXAML = (coreWindow == NULL);
|
||||
const BOOL usingXAML = (!coreWindow);
|
||||
#else
|
||||
IUnknown *coreWindow = NULL;
|
||||
const BOOL usingXAML = FALSE;
|
||||
|
|
@ -758,7 +757,7 @@ static HRESULT D3D11_CreateSwapChain(SDL_Renderer *renderer, int w, int h)
|
|||
swapChainDesc.SampleDesc.Quality = 0;
|
||||
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
swapChainDesc.BufferCount = 2; /* Use double-buffering to minimize latency. */
|
||||
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
|
||||
#if SDL_WINAPI_FAMILY_PHONE
|
||||
swapChainDesc.Scaling = DXGI_SCALING_STRETCH; /* On phone, only stretch and aspect-ratio stretch scaling are allowed. */
|
||||
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; /* On phone, no swap effects are supported. */
|
||||
/* TODO, WinRT: see if Win 8.x DXGI_SWAP_CHAIN_DESC1 settings are available on Windows Phone 8.1, and if there's any advantage to having them on */
|
||||
|
|
@ -813,7 +812,12 @@ static HRESULT D3D11_CreateSwapChain(SDL_Renderer *renderer, int w, int h)
|
|||
#if defined(__WIN32__) || defined(__WINGDK__)
|
||||
SDL_SysWMinfo windowinfo;
|
||||
SDL_VERSION(&windowinfo.version);
|
||||
SDL_GetWindowWMInfo(renderer->window, &windowinfo);
|
||||
if (!SDL_GetWindowWMInfo(renderer->window, &windowinfo) ||
|
||||
windowinfo.subsystem != SDL_SYSWM_WINDOWS) {
|
||||
SDL_SetError("Couldn't get window handle");
|
||||
result = E_FAIL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
result = IDXGIFactory2_CreateSwapChainForHwnd(data->dxgiFactory,
|
||||
(IUnknown *)data->d3dDevice,
|
||||
|
|
@ -907,7 +911,7 @@ static HRESULT D3D11_CreateWindowSizeDependentResources(SDL_Renderer *renderer)
|
|||
|
||||
if (data->swapChain) {
|
||||
/* IDXGISwapChain::ResizeBuffers is not available on Windows Phone 8. */
|
||||
#if !defined(__WINRT__) || (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP)
|
||||
#if !defined(__WINRT__) || !SDL_WINAPI_FAMILY_PHONE
|
||||
/* If the swap chain already exists, resize it. */
|
||||
result = IDXGISwapChain_ResizeBuffers(data->swapChain,
|
||||
0,
|
||||
|
|
@ -929,12 +933,12 @@ static HRESULT D3D11_CreateWindowSizeDependentResources(SDL_Renderer *renderer)
|
|||
#endif
|
||||
} else {
|
||||
result = D3D11_CreateSwapChain(renderer, w, h);
|
||||
if (FAILED(result) || data->swapChain == NULL) {
|
||||
if (FAILED(result) || !data->swapChain) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
|
||||
#if !SDL_WINAPI_FAMILY_PHONE
|
||||
/* Set the proper rotation for the swap chain.
|
||||
*
|
||||
* To note, the call for this, IDXGISwapChain1::SetRotation, is not necessary
|
||||
|
|
@ -1071,7 +1075,7 @@ static int D3D11_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
}
|
||||
|
||||
textureData = (D3D11_TextureData *)SDL_calloc(1, sizeof(*textureData));
|
||||
if (textureData == NULL) {
|
||||
if (!textureData) {
|
||||
SDL_OutOfMemory();
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -1232,7 +1236,7 @@ static void D3D11_DestroyTexture(SDL_Renderer *renderer,
|
|||
{
|
||||
D3D11_TextureData *data = (D3D11_TextureData *)texture->driverdata;
|
||||
|
||||
if (data == NULL) {
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1339,7 +1343,7 @@ static int D3D11_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
|
|||
D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->driverdata;
|
||||
D3D11_TextureData *textureData = (D3D11_TextureData *)texture->driverdata;
|
||||
|
||||
if (textureData == NULL) {
|
||||
if (!textureData) {
|
||||
return SDL_SetError("Texture is not currently available");
|
||||
}
|
||||
|
||||
|
|
@ -1384,7 +1388,7 @@ static int D3D11_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture,
|
|||
D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->driverdata;
|
||||
D3D11_TextureData *textureData = (D3D11_TextureData *)texture->driverdata;
|
||||
|
||||
if (textureData == NULL) {
|
||||
if (!textureData) {
|
||||
return SDL_SetError("Texture is not currently available");
|
||||
}
|
||||
|
||||
|
|
@ -1408,7 +1412,7 @@ static int D3D11_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture,
|
|||
D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->driverdata;
|
||||
D3D11_TextureData *textureData = (D3D11_TextureData *)texture->driverdata;
|
||||
|
||||
if (textureData == NULL) {
|
||||
if (!textureData) {
|
||||
return SDL_SetError("Texture is not currently available");
|
||||
}
|
||||
|
||||
|
|
@ -1432,7 +1436,7 @@ static int D3D11_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
|
|||
D3D11_TEXTURE2D_DESC stagingTextureDesc;
|
||||
D3D11_MAPPED_SUBRESOURCE textureMemory;
|
||||
|
||||
if (textureData == NULL) {
|
||||
if (!textureData) {
|
||||
return SDL_SetError("Texture is not currently available");
|
||||
}
|
||||
#if SDL_HAVE_YUV
|
||||
|
|
@ -1511,7 +1515,7 @@ static void D3D11_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->driverdata;
|
||||
D3D11_TextureData *textureData = (D3D11_TextureData *)texture->driverdata;
|
||||
|
||||
if (textureData == NULL) {
|
||||
if (!textureData) {
|
||||
return;
|
||||
}
|
||||
#if SDL_HAVE_YUV
|
||||
|
|
@ -1547,7 +1551,7 @@ static void D3D11_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *textu
|
|||
{
|
||||
D3D11_TextureData *textureData = (D3D11_TextureData *)texture->driverdata;
|
||||
|
||||
if (textureData == NULL) {
|
||||
if (!textureData) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1559,7 +1563,7 @@ static int D3D11_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->driverdata;
|
||||
D3D11_TextureData *textureData = NULL;
|
||||
|
||||
if (texture == NULL) {
|
||||
if (!texture) {
|
||||
rendererData->currentOffscreenRenderTargetView = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1590,7 +1594,7 @@ static int D3D11_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
|
|||
color.b = cmd->data.draw.b;
|
||||
color.a = cmd->data.draw.a;
|
||||
|
||||
if (verts == NULL) {
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -1617,7 +1621,7 @@ static int D3D11_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, S
|
|||
int count = indices ? num_indices : num_vertices;
|
||||
VertexPositionColor *verts = (VertexPositionColor *)SDL_AllocateRenderVertices(renderer, count * sizeof(VertexPositionColor), 0, &cmd->data.draw.first);
|
||||
|
||||
if (verts == NULL) {
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -1842,6 +1846,19 @@ static int D3D11_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *c
|
|||
ID3D11BlendState *blendState = NULL;
|
||||
SDL_bool updateSubresource = SDL_FALSE;
|
||||
|
||||
if (numShaderResources > 0) {
|
||||
shaderResource = shaderResources[0];
|
||||
} else {
|
||||
shaderResource = NULL;
|
||||
}
|
||||
|
||||
/* Make sure the render target isn't bound to a shader */
|
||||
if (shaderResource != rendererData->currentShaderResource) {
|
||||
ID3D11ShaderResourceView *pNullResource = NULL;
|
||||
ID3D11DeviceContext_PSSetShaderResources(rendererData->d3dContext, 0, 1, &pNullResource);
|
||||
rendererData->currentShaderResource = NULL;
|
||||
}
|
||||
|
||||
if (renderTargetView != rendererData->currentRenderTargetView) {
|
||||
ID3D11DeviceContext_OMSetRenderTargets(rendererData->d3dContext,
|
||||
1,
|
||||
|
|
@ -1889,9 +1906,9 @@ static int D3D11_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *c
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (blendState == NULL) {
|
||||
if (!blendState) {
|
||||
blendState = D3D11_CreateBlendState(renderer, blendMode);
|
||||
if (blendState == NULL) {
|
||||
if (!blendState) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -1905,11 +1922,6 @@ static int D3D11_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *c
|
|||
ID3D11DeviceContext_PSSetShader(rendererData->d3dContext, shader, NULL, 0);
|
||||
rendererData->currentShader = shader;
|
||||
}
|
||||
if (numShaderResources > 0) {
|
||||
shaderResource = shaderResources[0];
|
||||
} else {
|
||||
shaderResource = NULL;
|
||||
}
|
||||
if (shaderResource != rendererData->currentShaderResource) {
|
||||
ID3D11DeviceContext_PSSetShaderResources(rendererData->d3dContext, 0, numShaderResources, shaderResources);
|
||||
rendererData->currentShaderResource = shaderResource;
|
||||
|
|
@ -2039,6 +2051,7 @@ static int D3D11_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
|
|||
if (SDL_memcmp(viewport, &cmd->data.viewport.rect, sizeof(cmd->data.viewport.rect)) != 0) {
|
||||
SDL_copyp(viewport, &cmd->data.viewport.rect);
|
||||
rendererData->viewportDirty = SDL_TRUE;
|
||||
rendererData->cliprectDirty = SDL_TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -2144,13 +2157,13 @@ static int D3D11_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
|
|||
D3D11_MAPPED_SUBRESOURCE textureMemory;
|
||||
|
||||
renderTargetView = D3D11_GetCurrentRenderTargetView(renderer);
|
||||
if (renderTargetView == NULL) {
|
||||
if (!renderTargetView) {
|
||||
SDL_SetError("%s, ID3D11DeviceContext::OMGetRenderTargets failed", __FUNCTION__);
|
||||
goto done;
|
||||
}
|
||||
|
||||
ID3D11View_GetResource(renderTargetView, (ID3D11Resource **)&backBuffer);
|
||||
if (backBuffer == NULL) {
|
||||
if (!backBuffer) {
|
||||
SDL_SetError("%s, ID3D11View::GetResource failed", __FUNCTION__);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -2237,7 +2250,7 @@ static int D3D11_RenderPresent(SDL_Renderer *renderer)
|
|||
|
||||
SDL_zero(parameters);
|
||||
|
||||
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
|
||||
#if SDL_WINAPI_FAMILY_PHONE
|
||||
syncInterval = 1;
|
||||
presentFlags = 0;
|
||||
result = IDXGISwapChain_Present(data->swapChain, syncInterval, presentFlags);
|
||||
|
|
@ -2285,7 +2298,7 @@ static int D3D11_RenderPresent(SDL_Renderer *renderer)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
|
||||
#if SDL_WINAPI_FAMILY_PHONE
|
||||
/* no-op. */
|
||||
#else
|
||||
static int D3D11_SetVSync(SDL_Renderer *renderer, const int vsync)
|
||||
|
|
@ -2299,22 +2312,13 @@ static int D3D11_SetVSync(SDL_Renderer *renderer, const int vsync)
|
|||
}
|
||||
#endif
|
||||
|
||||
SDL_Renderer *D3D11_CreateRenderer(SDL_Window *window, Uint32 flags)
|
||||
int D3D11_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, Uint32 flags)
|
||||
{
|
||||
SDL_Renderer *renderer;
|
||||
D3D11_RenderData *data;
|
||||
|
||||
renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(*renderer));
|
||||
if (renderer == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
data = (D3D11_RenderData *)SDL_calloc(1, sizeof(*data));
|
||||
if (data == NULL) {
|
||||
SDL_free(renderer);
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
if (!data) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
data->identity = MatrixIdentity();
|
||||
|
|
@ -2348,7 +2352,7 @@ SDL_Renderer *D3D11_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
renderer->info.flags = (SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
|
||||
renderer->driverdata = data;
|
||||
|
||||
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
|
||||
#if SDL_WINAPI_FAMILY_PHONE
|
||||
/* VSync is required in Windows Phone, at least for Win Phone 8.0 and 8.1.
|
||||
* Failure to use it seems to either result in:
|
||||
*
|
||||
|
|
@ -2376,14 +2380,14 @@ SDL_Renderer *D3D11_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
/* Initialize Direct3D resources */
|
||||
if (FAILED(D3D11_CreateDeviceResources(renderer))) {
|
||||
D3D11_DestroyRenderer(renderer);
|
||||
return NULL;
|
||||
return -1;
|
||||
}
|
||||
if (FAILED(D3D11_CreateWindowSizeDependentResources(renderer))) {
|
||||
D3D11_DestroyRenderer(renderer);
|
||||
return NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return renderer;
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_RenderDriver D3D11_RenderDriver = {
|
||||
|
|
@ -2407,7 +2411,7 @@ SDL_RenderDriver D3D11_RenderDriver = {
|
|||
}
|
||||
};
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_D3D11 */
|
||||
|
||||
#if defined(__WIN32__) || defined(__WINGDK__)
|
||||
/* This function needs to always exist on Windows, for the Dynamic API. */
|
||||
|
|
@ -2415,7 +2419,7 @@ ID3D11Device *SDL_RenderGetD3D11Device(SDL_Renderer *renderer)
|
|||
{
|
||||
ID3D11Device *device = NULL;
|
||||
|
||||
#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_D3D11
|
||||
D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata;
|
||||
|
||||
/* Make sure that this is a D3D renderer */
|
||||
|
|
@ -2428,7 +2432,7 @@ ID3D11Device *SDL_RenderGetD3D11Device(SDL_Renderer *renderer)
|
|||
if (device) {
|
||||
ID3D11Device_AddRef(device);
|
||||
}
|
||||
#endif /* SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_D3D11 */
|
||||
|
||||
return device;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_D3D11
|
||||
|
||||
#include "SDL_syswm.h"
|
||||
#include "../../video/winrt/SDL_winrtvideo_cpp.h"
|
||||
|
|
@ -46,7 +46,7 @@ extern "C" void *
|
|||
D3D11_GetCoreWindowFromSDLRenderer(SDL_Renderer *renderer)
|
||||
{
|
||||
SDL_Window *sdlWindow = renderer->window;
|
||||
if (renderer->window == NULL) {
|
||||
if (!renderer->window) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -83,7 +83,7 @@ D3D11_GetCurrentRotation()
|
|||
|
||||
switch (currentOrientation) {
|
||||
|
||||
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
|
||||
#if SDL_WINAPI_FAMILY_PHONE
|
||||
/* Windows Phone rotations */
|
||||
case DisplayOrientations::Landscape:
|
||||
return DXGI_MODE_ROTATION_ROTATE90;
|
||||
|
|
@ -103,12 +103,12 @@ D3D11_GetCurrentRotation()
|
|||
return DXGI_MODE_ROTATION_ROTATE180;
|
||||
case DisplayOrientations::PortraitFlipped:
|
||||
return DXGI_MODE_ROTATION_ROTATE90;
|
||||
#endif /* WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP */
|
||||
#endif /* SDL_WINAPI_FAMILY_PHONE */
|
||||
}
|
||||
|
||||
return DXGI_MODE_ROTATION_IDENTITY;
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_D3D11 */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_D3D11
|
||||
|
||||
#include "SDL_render.h"
|
||||
|
||||
|
|
@ -35,6 +35,6 @@ DXGI_MODE_ROTATION D3D11_GetCurrentRotation();
|
|||
}
|
||||
#endif
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_D3D11 */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_D3D11
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
|
||||
|
|
@ -58,7 +58,7 @@
|
|||
|
||||
hexdump -v -e '6/4 "0x%08.8x, " "\n"' <FILE>
|
||||
*/
|
||||
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
|
||||
#if SDL_WINAPI_FAMILY_PHONE
|
||||
#define D3D11_USE_SHADER_MODEL_4_0_level_9_3
|
||||
#else
|
||||
#define D3D11_USE_SHADER_MODEL_4_0_level_9_1
|
||||
|
|
@ -1949,6 +1949,6 @@ int D3D11_CreatePixelShader(ID3D11Device1 *d3dDevice, D3D11_Shader shader, ID3D1
|
|||
return 0;
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_D3D11 */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
#include "SDL_render.h"
|
||||
#include "SDL_system.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_D3D12
|
||||
|
||||
#define SDL_D3D12_NUM_BUFFERS 2
|
||||
#define SDL_D3D12_NUM_VERTEX_BUFFERS 256
|
||||
|
|
@ -48,6 +48,7 @@
|
|||
#include <dxgi1_6.h>
|
||||
#include <dxgidebug.h>
|
||||
#include <d3d12sdklayers.h>
|
||||
#include <sdkddkver.h>
|
||||
#endif
|
||||
|
||||
#include "SDL_shaders_d3d12.h"
|
||||
|
|
@ -58,6 +59,11 @@
|
|||
#define SDL_COMPOSE_ERROR(str) SDL_STRINGIFY_ARG(__FUNCTION__) ", " str
|
||||
#endif
|
||||
|
||||
/* DXGI_PRESENT flags are removed on Xbox */
|
||||
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
|
||||
#define DXGI_PRESENT_ALLOW_TEARING 0
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define SAFE_RELEASE(X) \
|
||||
if (X) { \
|
||||
|
|
@ -78,6 +84,54 @@
|
|||
#define D3D_GUID(X) &(X)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Older MS Windows SDK headers declare some d3d12 functions with the wrong function prototype.
|
||||
* - ID3D12Heap::GetDesc
|
||||
* - ID3D12Resource::GetDesc
|
||||
* - ID3D12DescriptorHeap::GetDesc
|
||||
* (and 9 more)+
|
||||
* This is fixed in SDKs since WDK_NTDDI_VERSION >= NTDDI_WIN10_FE (0x0A00000A)
|
||||
*/
|
||||
|
||||
#if !(defined(__MINGW32__) || defined(__XBOXONE__) || defined(__XBOXSERIES__)) \
|
||||
&& (WDK_NTDDI_VERSION < 0x0A00000A)
|
||||
|
||||
#define D3D_CALL_RET_ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(THIS, ...) do { \
|
||||
void (STDMETHODCALLTYPE * func)(ID3D12DescriptorHeap * This, D3D12_CPU_DESCRIPTOR_HANDLE * Handle) = \
|
||||
(void*)(THIS)->lpVtbl->GetCPUDescriptorHandleForHeapStart; \
|
||||
func((THIS), ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#define D3D_CALL_RET_ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(THIS, ...) do { \
|
||||
void (STDMETHODCALLTYPE * func)(ID3D12DescriptorHeap * This, D3D12_GPU_DESCRIPTOR_HANDLE * Handle) = \
|
||||
(void*)(THIS)->lpVtbl->GetGPUDescriptorHandleForHeapStart; \
|
||||
func((THIS), ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#define D3D_CALL_RET_ID3D12Resource_GetDesc(THIS, ...) do { \
|
||||
void (STDMETHODCALLTYPE * func)(ID3D12Resource * This, D3D12_RESOURCE_DESC * Desc) = \
|
||||
(void*)(THIS)->lpVtbl->GetDesc; \
|
||||
func((THIS), ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
* MinGW has correct function prototypes in the vtables, but defines wrong functions
|
||||
* Xbox just needs these macros defined as used below (because CINTERFACE doesn't exist)
|
||||
*/
|
||||
|
||||
#define D3D_CALL_RET_ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(THIS, ...) \
|
||||
D3D_CALL_RET(THIS, GetCPUDescriptorHandleForHeapStart, ##__VA_ARGS__);
|
||||
|
||||
#define D3D_CALL_RET_ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(THIS, ...) \
|
||||
D3D_CALL_RET(THIS, GetGPUDescriptorHandleForHeapStart, ##__VA_ARGS__);
|
||||
|
||||
#define D3D_CALL_RET_ID3D12Resource_GetDesc(THIS, ...) \
|
||||
D3D_CALL_RET(THIS, GetDesc, ##__VA_ARGS__);
|
||||
|
||||
#endif
|
||||
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
@ -393,10 +447,10 @@ static D3D12_GPU_DESCRIPTOR_HANDLE D3D12_CPUtoGPUHandle(ID3D12DescriptorHeap *he
|
|||
SIZE_T offset;
|
||||
|
||||
/* Calculate the correct offset into the heap */
|
||||
D3D_CALL_RET(heap, GetCPUDescriptorHandleForHeapStart, &CPUHeapStart);
|
||||
D3D_CALL_RET_ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(heap, &CPUHeapStart);
|
||||
offset = CPUHandle.ptr - CPUHeapStart.ptr;
|
||||
|
||||
D3D_CALL_RET(heap, GetGPUDescriptorHandleForHeapStart, &GPUHandle);
|
||||
D3D_CALL_RET_ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(heap, &GPUHandle);
|
||||
GPUHandle.ptr += offset;
|
||||
|
||||
return GPUHandle;
|
||||
|
|
@ -427,7 +481,7 @@ static D3D12_CPU_DESCRIPTOR_HANDLE D3D12_GetCurrentRenderTargetView(SDL_Renderer
|
|||
}
|
||||
|
||||
SDL_zero(rtvDescriptor);
|
||||
D3D_CALL_RET(data->rtvDescriptorHeap, GetCPUDescriptorHandleForHeapStart, &rtvDescriptor);
|
||||
D3D_CALL_RET_ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(data->rtvDescriptorHeap, &rtvDescriptor);
|
||||
rtvDescriptor.ptr += data->currentBackBufferIndex * data->rtvDescriptorSize;
|
||||
return rtvDescriptor;
|
||||
}
|
||||
|
|
@ -502,7 +556,6 @@ static void D3D12_DestroyRenderer(SDL_Renderer *renderer)
|
|||
if (data) {
|
||||
SDL_free(data);
|
||||
}
|
||||
SDL_free(renderer);
|
||||
}
|
||||
|
||||
static int D3D12_GetOutputSize(SDL_Renderer *renderer, int *w, int *h)
|
||||
|
|
@ -633,7 +686,7 @@ static D3D12_PipelineState *D3D12_CreatePipelineState(SDL_Renderer *renderer,
|
|||
}
|
||||
|
||||
pipelineStates = (D3D12_PipelineState *)SDL_realloc(data->pipelineStates, (data->pipelineStateCount + 1) * sizeof(*pipelineStates));
|
||||
if (pipelineStates == NULL) {
|
||||
if (!pipelineStates) {
|
||||
SAFE_RELEASE(pipelineState);
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
|
|
@ -748,7 +801,7 @@ static HRESULT D3D12_CreateDeviceResources(SDL_Renderer *renderer)
|
|||
}
|
||||
}
|
||||
#endif
|
||||
if (CreateEventExFunc == NULL) {
|
||||
if (!CreateEventExFunc) {
|
||||
result = E_FAIL;
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -761,7 +814,7 @@ static HRESULT D3D12_CreateDeviceResources(SDL_Renderer *renderer)
|
|||
}
|
||||
|
||||
CreateDXGIFactoryFunc = (PFN_CREATE_DXGI_FACTORY)SDL_LoadFunction(data->hDXGIMod, "CreateDXGIFactory2");
|
||||
if (CreateDXGIFactoryFunc == NULL) {
|
||||
if (!CreateDXGIFactoryFunc) {
|
||||
result = E_FAIL;
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -805,7 +858,7 @@ static HRESULT D3D12_CreateDeviceResources(SDL_Renderer *renderer)
|
|||
|
||||
/* If the debug hint is set, also create the DXGI factory in debug mode */
|
||||
DXGIGetDebugInterfaceFunc = (PFN_CREATE_DXGI_FACTORY)SDL_LoadFunction(data->hDXGIMod, "DXGIGetDebugInterface1");
|
||||
if (DXGIGetDebugInterfaceFunc == NULL) {
|
||||
if (!DXGIGetDebugInterfaceFunc) {
|
||||
result = E_FAIL;
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1047,7 +1100,7 @@ static HRESULT D3D12_CreateDeviceResources(SDL_Renderer *renderer)
|
|||
samplerDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_ALWAYS;
|
||||
samplerDesc.MinLOD = 0.0f;
|
||||
samplerDesc.MaxLOD = D3D12_FLOAT32_MAX;
|
||||
D3D_CALL_RET(data->samplerDescriptorHeap, GetCPUDescriptorHandleForHeapStart, &data->nearestPixelSampler);
|
||||
D3D_CALL_RET_ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(data->samplerDescriptorHeap, &data->nearestPixelSampler);
|
||||
D3D_CALL(data->d3dDevice, CreateSampler, &samplerDesc, data->nearestPixelSampler);
|
||||
|
||||
samplerDesc.Filter = D3D12_FILTER_MIN_MAG_MIP_LINEAR;
|
||||
|
|
@ -1141,7 +1194,7 @@ static int D3D12_GetViewportAlignedD3DRect(SDL_Renderer *renderer, const SDL_Rec
|
|||
static HRESULT D3D12_CreateSwapChain(SDL_Renderer *renderer, int w, int h)
|
||||
{
|
||||
D3D12_RenderData *data = (D3D12_RenderData *)renderer->driverdata;
|
||||
IDXGISwapChain1* swapChain;
|
||||
IDXGISwapChain1* swapChain = NULL;
|
||||
HRESULT result = S_OK;
|
||||
SDL_SysWMinfo windowinfo;
|
||||
|
||||
|
|
@ -1166,7 +1219,13 @@ static HRESULT D3D12_CreateSwapChain(SDL_Renderer *renderer, int w, int h)
|
|||
DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING; /* To support presenting with allow tearing on */
|
||||
|
||||
SDL_VERSION(&windowinfo.version);
|
||||
SDL_GetWindowWMInfo(renderer->window, &windowinfo);
|
||||
if (!SDL_GetWindowWMInfo(renderer->window, &windowinfo) ||
|
||||
windowinfo.subsystem != SDL_SYSWM_WINDOWS)
|
||||
{
|
||||
SDL_SetError("Couldn't get window handle");
|
||||
result = E_FAIL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
result = D3D_CALL(data->dxgiFactory, CreateSwapChainForHwnd,
|
||||
(IUnknown *)data->commandQueue,
|
||||
|
|
@ -1330,7 +1389,7 @@ static HRESULT D3D12_CreateWindowSizeDependentResources(SDL_Renderer *renderer)
|
|||
rtvDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D;
|
||||
|
||||
SDL_zero(rtvDescriptor);
|
||||
D3D_CALL_RET(data->rtvDescriptorHeap, GetCPUDescriptorHandleForHeapStart, &rtvDescriptor);
|
||||
D3D_CALL_RET_ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(data->rtvDescriptorHeap, &rtvDescriptor);
|
||||
rtvDescriptor.ptr += i * data->rtvDescriptorSize;
|
||||
D3D_CALL(data->d3dDevice, CreateRenderTargetView, data->renderTargets[i], &rtvDesc, rtvDescriptor);
|
||||
}
|
||||
|
|
@ -1432,7 +1491,7 @@ static int D3D12_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
}
|
||||
|
||||
textureData = (D3D12_TextureData *)SDL_calloc(1, sizeof(*textureData));
|
||||
if (textureData == NULL) {
|
||||
if (!textureData) {
|
||||
SDL_OutOfMemory();
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -1544,7 +1603,7 @@ static int D3D12_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
resourceViewDesc.Texture2D.MipLevels = textureDesc.MipLevels;
|
||||
|
||||
textureData->mainSRVIndex = D3D12_GetAvailableSRVIndex(renderer);
|
||||
D3D_CALL_RET(rendererData->srvDescriptorHeap, GetCPUDescriptorHandleForHeapStart, &textureData->mainTextureResourceView);
|
||||
D3D_CALL_RET_ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(rendererData->srvDescriptorHeap, &textureData->mainTextureResourceView);
|
||||
textureData->mainTextureResourceView.ptr += textureData->mainSRVIndex * rendererData->srvDescriptorSize;
|
||||
|
||||
D3D_CALL(rendererData->d3dDevice, CreateShaderResourceView,
|
||||
|
|
@ -1553,7 +1612,7 @@ static int D3D12_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
textureData->mainTextureResourceView);
|
||||
#if SDL_HAVE_YUV
|
||||
if (textureData->yuv) {
|
||||
D3D_CALL_RET(rendererData->srvDescriptorHeap, GetCPUDescriptorHandleForHeapStart, &textureData->mainTextureResourceViewU);
|
||||
D3D_CALL_RET_ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(rendererData->srvDescriptorHeap, &textureData->mainTextureResourceViewU);
|
||||
textureData->mainSRVIndexU = D3D12_GetAvailableSRVIndex(renderer);
|
||||
textureData->mainTextureResourceViewU.ptr += textureData->mainSRVIndexU * rendererData->srvDescriptorSize;
|
||||
D3D_CALL(rendererData->d3dDevice, CreateShaderResourceView,
|
||||
|
|
@ -1561,7 +1620,7 @@ static int D3D12_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
&resourceViewDesc,
|
||||
textureData->mainTextureResourceViewU);
|
||||
|
||||
D3D_CALL_RET(rendererData->srvDescriptorHeap, GetCPUDescriptorHandleForHeapStart, &textureData->mainTextureResourceViewV);
|
||||
D3D_CALL_RET_ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(rendererData->srvDescriptorHeap, &textureData->mainTextureResourceViewV);
|
||||
textureData->mainSRVIndexV = D3D12_GetAvailableSRVIndex(renderer);
|
||||
textureData->mainTextureResourceViewV.ptr += textureData->mainSRVIndexV * rendererData->srvDescriptorSize;
|
||||
D3D_CALL(rendererData->d3dDevice, CreateShaderResourceView,
|
||||
|
|
@ -1575,7 +1634,7 @@ static int D3D12_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
|
||||
nvResourceViewDesc.Format = DXGI_FORMAT_R8G8_UNORM;
|
||||
|
||||
D3D_CALL_RET(rendererData->srvDescriptorHeap, GetCPUDescriptorHandleForHeapStart, &textureData->mainTextureResourceViewNV);
|
||||
D3D_CALL_RET_ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(rendererData->srvDescriptorHeap, &textureData->mainTextureResourceViewNV);
|
||||
textureData->mainSRVIndexNV = D3D12_GetAvailableSRVIndex(renderer);
|
||||
textureData->mainTextureResourceViewNV.ptr += textureData->mainSRVIndexNV * rendererData->srvDescriptorSize;
|
||||
D3D_CALL(rendererData->d3dDevice, CreateShaderResourceView,
|
||||
|
|
@ -1592,7 +1651,7 @@ static int D3D12_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
renderTargetViewDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D;
|
||||
renderTargetViewDesc.Texture2D.MipSlice = 0;
|
||||
|
||||
D3D_CALL_RET(rendererData->textureRTVDescriptorHeap, GetCPUDescriptorHandleForHeapStart, &textureData->mainTextureRenderTargetView);
|
||||
D3D_CALL_RET_ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(rendererData->textureRTVDescriptorHeap, &textureData->mainTextureRenderTargetView);
|
||||
textureData->mainTextureRenderTargetView.ptr += textureData->mainSRVIndex * rendererData->rtvDescriptorSize;
|
||||
|
||||
D3D_CALL(rendererData->d3dDevice, CreateRenderTargetView,
|
||||
|
|
@ -1610,7 +1669,7 @@ static void D3D12_DestroyTexture(SDL_Renderer *renderer,
|
|||
D3D12_RenderData *rendererData = (D3D12_RenderData *)renderer->driverdata;
|
||||
D3D12_TextureData *textureData = (D3D12_TextureData *)texture->driverdata;
|
||||
|
||||
if (textureData == NULL) {
|
||||
if (!textureData) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1657,7 +1716,7 @@ static int D3D12_UpdateTextureInternal(D3D12_RenderData *rendererData, ID3D12Res
|
|||
|
||||
/* Create an upload buffer, which will be used to write to the main texture. */
|
||||
SDL_zero(textureDesc);
|
||||
D3D_CALL_RET(texture, GetDesc, &textureDesc);
|
||||
D3D_CALL_RET_ID3D12Resource_GetDesc(texture, &textureDesc);
|
||||
textureDesc.Width = w;
|
||||
textureDesc.Height = h;
|
||||
|
||||
|
|
@ -1788,7 +1847,7 @@ static int D3D12_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
|
|||
D3D12_RenderData *rendererData = (D3D12_RenderData *)renderer->driverdata;
|
||||
D3D12_TextureData *textureData = (D3D12_TextureData *)texture->driverdata;
|
||||
|
||||
if (textureData == NULL) {
|
||||
if (!textureData) {
|
||||
return SDL_SetError("Texture is not currently available");
|
||||
}
|
||||
|
||||
|
|
@ -1833,7 +1892,7 @@ static int D3D12_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture,
|
|||
D3D12_RenderData *rendererData = (D3D12_RenderData *)renderer->driverdata;
|
||||
D3D12_TextureData *textureData = (D3D12_TextureData *)texture->driverdata;
|
||||
|
||||
if (textureData == NULL) {
|
||||
if (!textureData) {
|
||||
return SDL_SetError("Texture is not currently available");
|
||||
}
|
||||
|
||||
|
|
@ -1857,7 +1916,7 @@ static int D3D12_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture,
|
|||
D3D12_RenderData *rendererData = (D3D12_RenderData *)renderer->driverdata;
|
||||
D3D12_TextureData *textureData = (D3D12_TextureData *)texture->driverdata;
|
||||
|
||||
if (textureData == NULL) {
|
||||
if (!textureData) {
|
||||
return SDL_SetError("Texture is not currently available");
|
||||
}
|
||||
|
||||
|
|
@ -1886,7 +1945,7 @@ static int D3D12_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
|
|||
BYTE *textureMemory;
|
||||
int bpp;
|
||||
|
||||
if (textureData == NULL) {
|
||||
if (!textureData) {
|
||||
return SDL_SetError("Texture is not currently available");
|
||||
}
|
||||
#if SDL_HAVE_YUV
|
||||
|
|
@ -1913,7 +1972,7 @@ static int D3D12_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
|
|||
|
||||
/* Create an upload buffer, which will be used to write to the main texture. */
|
||||
SDL_zero(textureDesc);
|
||||
D3D_CALL_RET(textureData->mainTexture, GetDesc, &textureDesc);
|
||||
D3D_CALL_RET_ID3D12Resource_GetDesc(textureData->mainTexture, &textureDesc);
|
||||
textureDesc.Width = rect->w;
|
||||
textureDesc.Height = rect->h;
|
||||
|
||||
|
|
@ -2005,7 +2064,7 @@ static void D3D12_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
D3D12_TEXTURE_COPY_LOCATION dstLocation;
|
||||
int bpp;
|
||||
|
||||
if (textureData == NULL) {
|
||||
if (!textureData) {
|
||||
return;
|
||||
}
|
||||
#if SDL_HAVE_YUV
|
||||
|
|
@ -2022,7 +2081,7 @@ static void D3D12_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
D3D_CALL(textureData->stagingBuffer, Unmap, 0, NULL);
|
||||
|
||||
SDL_zero(textureDesc);
|
||||
D3D_CALL_RET(textureData->mainTexture, GetDesc, &textureDesc);
|
||||
D3D_CALL_RET_ID3D12Resource_GetDesc(textureData->mainTexture, &textureDesc);
|
||||
textureDesc.Width = textureData->lockedRect.w;
|
||||
textureDesc.Height = textureData->lockedRect.h;
|
||||
|
||||
|
|
@ -2076,7 +2135,7 @@ static void D3D12_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *textu
|
|||
{
|
||||
D3D12_TextureData *textureData = (D3D12_TextureData *)texture->driverdata;
|
||||
|
||||
if (textureData == NULL) {
|
||||
if (!textureData) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -2088,7 +2147,7 @@ static int D3D12_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
D3D12_RenderData *rendererData = (D3D12_RenderData *)renderer->driverdata;
|
||||
D3D12_TextureData *textureData = NULL;
|
||||
|
||||
if (texture == NULL) {
|
||||
if (!texture) {
|
||||
if (rendererData->textureRenderTarget) {
|
||||
D3D12_TransitionResource(rendererData,
|
||||
rendererData->textureRenderTarget->mainTexture,
|
||||
|
|
@ -2131,7 +2190,7 @@ static int D3D12_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
|
|||
color.b = cmd->data.draw.b;
|
||||
color.a = cmd->data.draw.a;
|
||||
|
||||
if (verts == NULL) {
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -2158,7 +2217,7 @@ static int D3D12_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, S
|
|||
int count = indices ? num_indices : num_vertices;
|
||||
VertexPositionColor *verts = (VertexPositionColor *)SDL_AllocateRenderVertices(renderer, count * sizeof(VertexPositionColor), 0, &cmd->data.draw.first);
|
||||
|
||||
if (verts == NULL) {
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -2602,6 +2661,7 @@ static int D3D12_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
|
|||
if (SDL_memcmp(viewport, &cmd->data.viewport.rect, sizeof(cmd->data.viewport.rect)) != 0) {
|
||||
SDL_copyp(viewport, &cmd->data.viewport.rect);
|
||||
rendererData->viewportDirty = SDL_TRUE;
|
||||
rendererData->cliprectDirty = SDL_TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -2732,7 +2792,7 @@ static int D3D12_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
|
|||
|
||||
/* Create a staging texture to copy the screen's data to: */
|
||||
SDL_zero(textureDesc);
|
||||
D3D_CALL_RET(backBuffer, GetDesc, &textureDesc);
|
||||
D3D_CALL_RET_ID3D12Resource_GetDesc(backBuffer, &textureDesc);
|
||||
textureDesc.Width = rect->w;
|
||||
textureDesc.Height = rect->h;
|
||||
|
||||
|
|
@ -2837,8 +2897,8 @@ static int D3D12_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
|
|||
NULL,
|
||||
(void **)&textureMemory);
|
||||
if (FAILED(result)) {
|
||||
SAFE_RELEASE(readbackBuffer);
|
||||
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D12Resource::Map [map staging texture]"), result);
|
||||
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D12Resource::Map [map staging texture]"), result);
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Copy the data into the desired buffer, converting pixels to the
|
||||
|
|
@ -2953,22 +3013,13 @@ static int D3D12_SetVSync(SDL_Renderer *renderer, const int vsync)
|
|||
return 0;
|
||||
}
|
||||
|
||||
SDL_Renderer *D3D12_CreateRenderer(SDL_Window *window, Uint32 flags)
|
||||
int D3D12_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, Uint32 flags)
|
||||
{
|
||||
SDL_Renderer *renderer;
|
||||
D3D12_RenderData *data;
|
||||
|
||||
renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(*renderer));
|
||||
if (renderer == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
data = (D3D12_RenderData *)SDL_calloc(1, sizeof(*data));
|
||||
if (data == NULL) {
|
||||
SDL_free(renderer);
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
if (!data) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
data->identity = MatrixIdentity();
|
||||
|
|
@ -3013,14 +3064,14 @@ SDL_Renderer *D3D12_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
/* Initialize Direct3D resources */
|
||||
if (FAILED(D3D12_CreateDeviceResources(renderer))) {
|
||||
D3D12_DestroyRenderer(renderer);
|
||||
return NULL;
|
||||
return -1;
|
||||
}
|
||||
if (FAILED(D3D12_CreateWindowSizeDependentResources(renderer))) {
|
||||
D3D12_DestroyRenderer(renderer);
|
||||
return NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return renderer;
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_RenderDriver D3D12_RenderDriver = {
|
||||
|
|
@ -3049,7 +3100,7 @@ SDL_RenderDriver D3D12_RenderDriver = {
|
|||
}
|
||||
#endif
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_D3D12 */
|
||||
|
||||
#if defined(__WIN32__) || defined(__GDK__)
|
||||
#ifdef __cplusplus
|
||||
|
|
@ -3061,7 +3112,7 @@ extern "C"
|
|||
{
|
||||
ID3D12Device *device = NULL;
|
||||
|
||||
#if SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_D3D12
|
||||
D3D12_RenderData *data = (D3D12_RenderData *)renderer->driverdata;
|
||||
|
||||
/* Make sure that this is a D3D renderer */
|
||||
|
|
@ -3074,7 +3125,7 @@ extern "C"
|
|||
if (device) {
|
||||
D3D_CALL(device, AddRef);
|
||||
}
|
||||
#endif /* SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_D3D12 */
|
||||
|
||||
return device;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -20,8 +20,155 @@
|
|||
*/
|
||||
|
||||
#include "../../SDL_internal.h"
|
||||
#if SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED && (defined(__XBOXONE__) || defined(__XBOXSERIES__))
|
||||
#if SDL_VIDEO_RENDER_D3D12 && (defined(__XBOXONE__) || defined(__XBOXSERIES__))
|
||||
#include "SDL_render_d3d12_xbox.h"
|
||||
#include "../../core/windows/SDL_windows.h"
|
||||
#include <XGameRuntime.h>
|
||||
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
#define SDL_COMPOSE_ERROR(str) __FUNCTION__ ", " str
|
||||
#else
|
||||
#define SDL_COMPOSE_ERROR(str) SDL_STRINGIFY_ARG(__FUNCTION__) ", " str
|
||||
#endif
|
||||
|
||||
static const GUID SDL_IID_ID3D12Device1 = { 0x77acce80, 0x638e, 0x4e65, { 0x88, 0x95, 0xc1, 0xf2, 0x33, 0x86, 0x86, 0x3e } };
|
||||
static const GUID SDL_IID_ID3D12Resource = { 0x696442be, 0xa72e, 0x4059, { 0xbc, 0x79, 0x5b, 0x5c, 0x98, 0x04, 0x0f, 0xad } };
|
||||
static const GUID SDL_IID_IDXGIDevice1 = { 0x77db970f, 0x6276, 0x48ba, { 0xba, 0x28, 0x07, 0x01, 0x43, 0xb4, 0x39, 0x2c } };
|
||||
|
||||
extern "C" HRESULT
|
||||
D3D12_XBOX_CreateDevice(ID3D12Device **device, SDL_bool createDebug)
|
||||
{
|
||||
HRESULT result;
|
||||
D3D12XBOX_CREATE_DEVICE_PARAMETERS params;
|
||||
IDXGIDevice1 *dxgiDevice;
|
||||
IDXGIAdapter *dxgiAdapter;
|
||||
IDXGIOutput *dxgiOutput;
|
||||
SDL_zero(params);
|
||||
|
||||
params.Version = D3D12_SDK_VERSION;
|
||||
params.ProcessDebugFlags = createDebug ? D3D12_PROCESS_DEBUG_FLAG_DEBUG_LAYER_ENABLED : D3D12XBOX_PROCESS_DEBUG_FLAG_NONE;
|
||||
params.GraphicsCommandQueueRingSizeBytes = D3D12XBOX_DEFAULT_SIZE_BYTES;
|
||||
params.GraphicsScratchMemorySizeBytes = D3D12XBOX_DEFAULT_SIZE_BYTES;
|
||||
params.ComputeScratchMemorySizeBytes = D3D12XBOX_DEFAULT_SIZE_BYTES;
|
||||
|
||||
result = D3D12XboxCreateDevice(NULL, ¶ms, SDL_IID_ID3D12Device1, (void **) device);
|
||||
if (FAILED(result)) {
|
||||
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("[xbox] D3D12XboxCreateDevice"), result);
|
||||
goto done;
|
||||
}
|
||||
|
||||
result = (*device)->QueryInterface(SDL_IID_IDXGIDevice1, (void **) &dxgiDevice);
|
||||
if (FAILED(result)) {
|
||||
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("[xbox] ID3D12Device to IDXGIDevice1"), result);
|
||||
goto done;
|
||||
}
|
||||
|
||||
result = dxgiDevice->GetAdapter(&dxgiAdapter);
|
||||
if (FAILED(result)) {
|
||||
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("[xbox] dxgiDevice->GetAdapter"), result);
|
||||
goto done;
|
||||
}
|
||||
|
||||
result = dxgiAdapter->EnumOutputs(0, &dxgiOutput);
|
||||
if (FAILED(result)) {
|
||||
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("[xbox] dxgiAdapter->EnumOutputs"), result);
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Set frame interval */
|
||||
result = (*device)->SetFrameIntervalX(dxgiOutput, D3D12XBOX_FRAME_INTERVAL_60_HZ, 1, D3D12XBOX_FRAME_INTERVAL_FLAG_NONE);
|
||||
if (FAILED(result)) {
|
||||
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("[xbox] SetFrameIntervalX"), result);
|
||||
goto done;
|
||||
}
|
||||
|
||||
result = (*device)->ScheduleFrameEventX(D3D12XBOX_FRAME_EVENT_ORIGIN, 0, NULL, D3D12XBOX_SCHEDULE_FRAME_EVENT_FLAG_NONE);
|
||||
if (FAILED(result)) {
|
||||
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("[xbox] ScheduleFrameEventX"), result);
|
||||
goto done;
|
||||
}
|
||||
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
extern "C" HRESULT
|
||||
D3D12_XBOX_CreateBackBufferTarget(ID3D12Device1 *device, int width, int height, void **resource)
|
||||
{
|
||||
|
||||
D3D12_HEAP_PROPERTIES heapProps;
|
||||
D3D12_RESOURCE_DESC resourceDesc;
|
||||
|
||||
SDL_zero(heapProps);
|
||||
heapProps.Type = D3D12_HEAP_TYPE_DEFAULT;
|
||||
heapProps.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
|
||||
heapProps.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
|
||||
heapProps.CreationNodeMask = 1;
|
||||
heapProps.VisibleNodeMask = 1;
|
||||
|
||||
SDL_zero(resourceDesc);
|
||||
resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
|
||||
resourceDesc.Alignment = 0;
|
||||
resourceDesc.Width = width;
|
||||
resourceDesc.Height = height;
|
||||
resourceDesc.DepthOrArraySize = 1;
|
||||
resourceDesc.MipLevels = 1;
|
||||
resourceDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
resourceDesc.SampleDesc.Count = 1;
|
||||
resourceDesc.SampleDesc.Quality = 0;
|
||||
resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
|
||||
resourceDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
|
||||
|
||||
return device->CreateCommittedResource(&heapProps,
|
||||
D3D12_HEAP_FLAG_ALLOW_DISPLAY,
|
||||
&resourceDesc,
|
||||
D3D12_RESOURCE_STATE_PRESENT,
|
||||
NULL,
|
||||
SDL_IID_ID3D12Resource,
|
||||
resource
|
||||
);
|
||||
}
|
||||
|
||||
extern "C" HRESULT
|
||||
D3D12_XBOX_StartFrame(ID3D12Device1 *device, UINT64 *outToken)
|
||||
{
|
||||
*outToken = D3D12XBOX_FRAME_PIPELINE_TOKEN_NULL;
|
||||
return device->WaitFrameEventX(D3D12XBOX_FRAME_EVENT_ORIGIN, INFINITE, NULL, D3D12XBOX_WAIT_FRAME_EVENT_FLAG_NONE, outToken);
|
||||
}
|
||||
|
||||
extern "C" HRESULT
|
||||
D3D12_XBOX_PresentFrame(ID3D12CommandQueue *commandQueue, UINT64 token, ID3D12Resource *renderTarget)
|
||||
{
|
||||
D3D12XBOX_PRESENT_PLANE_PARAMETERS planeParameters;
|
||||
SDL_zero(planeParameters);
|
||||
planeParameters.Token = token;
|
||||
planeParameters.ResourceCount = 1;
|
||||
planeParameters.ppResources = &renderTarget;
|
||||
return commandQueue->PresentX(1, &planeParameters, NULL);
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
D3D12_XBOX_GetResolution(Uint32 *width, Uint32 *height)
|
||||
{
|
||||
switch (XSystemGetDeviceType()) {
|
||||
case XSystemDeviceType::XboxScarlettLockhart:
|
||||
*width = 2560;
|
||||
*height = 1440;
|
||||
break;
|
||||
|
||||
case XSystemDeviceType::XboxOneX:
|
||||
case XSystemDeviceType::XboxScarlettAnaconda:
|
||||
case XSystemDeviceType::XboxOneXDevkit:
|
||||
case XSystemDeviceType::XboxScarlettDevkit:
|
||||
*width = 3840;
|
||||
*height = 2160;
|
||||
break;
|
||||
|
||||
default:
|
||||
*width = 1920;
|
||||
*height = 1080;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#error "This is a placeholder Xbox file, as the real one is under NDA. See README-gdk.md for more info."
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -19,4 +19,31 @@
|
|||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#error "This is a placeholder Xbox file, as the real one is under NDA. See README-gdk.md for more info."
|
||||
#ifndef SDL_render_d3d12_xbox_h_
|
||||
#define SDL_render_d3d12_xbox_h_
|
||||
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if defined(__XBOXONE__)
|
||||
#include <d3d12_x.h>
|
||||
#else /* __XBOXSERIES__ */
|
||||
#include <d3d12_xs.h>
|
||||
#endif
|
||||
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern HRESULT D3D12_XBOX_CreateDevice(ID3D12Device **device, SDL_bool createDebug);
|
||||
extern HRESULT D3D12_XBOX_CreateBackBufferTarget(ID3D12Device1 *device, int width, int height, void **resource);
|
||||
extern HRESULT D3D12_XBOX_StartFrame(ID3D12Device1 *device, UINT64 *outToken);
|
||||
extern HRESULT D3D12_XBOX_PresentFrame(ID3D12CommandQueue *commandQueue, UINT64 token, ID3D12Resource *renderTarget);
|
||||
extern void D3D12_XBOX_GetResolution(Uint32 *width, Uint32 *height);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
|
||||
#if SDL_VIDEO_RENDER_D3D12 && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
|
||||
|
|
@ -6934,6 +6934,6 @@ void D3D12_GetRootSignatureData(D3D12_RootSignature rootSig, D3D12_SHADER_BYTECO
|
|||
outBytecode->BytecodeLength = D3D12_rootsigs[rootSig].rs_shader_size;
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED && !defined(__XBOXONE__) && !defined(__XBOXSERIES__) */
|
||||
#endif /* SDL_VIDEO_RENDER_D3D12 && !defined(__XBOXONE__) && !defined(__XBOXSERIES__) */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -20,10 +20,125 @@
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED && defined(__XBOXONE__)
|
||||
#if SDL_VIDEO_RENDER_D3D12 && defined(__XBOXONE__)
|
||||
|
||||
#error "This is a placeholder Xbox file, as the real one is under NDA. See README-gdk.md for more info."
|
||||
#include <SDL_stdinc.h>
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED && defined(__XBOXONE__) */
|
||||
#include "../../core/windows/SDL_windows.h"
|
||||
#include <d3d12_x.h>
|
||||
|
||||
#include "SDL_shaders_d3d12.h"
|
||||
|
||||
#define SDL_COMPOSE_ERROR(str) SDL_STRINGIFY_ARG(__FUNCTION__) ", " str
|
||||
|
||||
/* Shader blob headers are generated with a pre-build step using buildshaders.bat */
|
||||
#include "../VisualC-GDK/shaders/D3D12_PixelShader_Colors_One.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_PixelShader_NV12_BT601_One.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_PixelShader_NV12_BT709_One.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_PixelShader_NV12_JPEG_One.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_PixelShader_NV21_BT601_One.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_PixelShader_NV21_BT709_One.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_PixelShader_NV21_JPEG_One.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_PixelShader_Textures_One.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_PixelShader_YUV_BT601_One.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_PixelShader_YUV_BT709_One.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_PixelShader_YUV_JPEG_One.h"
|
||||
|
||||
#include "../VisualC-GDK/shaders/D3D12_VertexShader_Color_One.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_VertexShader_NV_One.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_VertexShader_Texture_One.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_VertexShader_YUV_One.h"
|
||||
|
||||
#include "../VisualC-GDK/shaders/D3D12_RootSig_Color_One.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_RootSig_NV_One.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_RootSig_Texture_One.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_RootSig_YUV_One.h"
|
||||
|
||||
static struct
|
||||
{
|
||||
const void *ps_shader_data;
|
||||
SIZE_T ps_shader_size;
|
||||
const void *vs_shader_data;
|
||||
SIZE_T vs_shader_size;
|
||||
D3D12_RootSignature root_sig;
|
||||
} D3D12_shaders[NUM_SHADERS] = {
|
||||
{ D3D12_PixelShader_Colors, sizeof(D3D12_PixelShader_Colors),
|
||||
D3D12_VertexShader_Color, sizeof(D3D12_VertexShader_Color),
|
||||
ROOTSIG_COLOR },
|
||||
{ D3D12_PixelShader_Textures, sizeof(D3D12_PixelShader_Textures),
|
||||
D3D12_VertexShader_Texture, sizeof(D3D12_VertexShader_Texture),
|
||||
ROOTSIG_TEXTURE },
|
||||
#if SDL_HAVE_YUV
|
||||
{ D3D12_PixelShader_YUV_JPEG, sizeof(D3D12_PixelShader_YUV_JPEG),
|
||||
D3D12_VertexShader_YUV, sizeof(D3D12_VertexShader_YUV),
|
||||
ROOTSIG_YUV },
|
||||
{ D3D12_PixelShader_YUV_BT601, sizeof(D3D12_PixelShader_YUV_BT601),
|
||||
D3D12_VertexShader_YUV, sizeof(D3D12_VertexShader_YUV),
|
||||
ROOTSIG_YUV },
|
||||
{ D3D12_PixelShader_YUV_BT709, sizeof(D3D12_PixelShader_YUV_BT709),
|
||||
D3D12_VertexShader_YUV, sizeof(D3D12_VertexShader_YUV),
|
||||
ROOTSIG_YUV },
|
||||
{ D3D12_PixelShader_NV12_JPEG, sizeof(D3D12_PixelShader_NV12_JPEG),
|
||||
D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV),
|
||||
ROOTSIG_NV },
|
||||
{ D3D12_PixelShader_NV12_BT601, sizeof(D3D12_PixelShader_NV12_BT601),
|
||||
D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV),
|
||||
ROOTSIG_NV },
|
||||
{ D3D12_PixelShader_NV12_BT709, sizeof(D3D12_PixelShader_NV12_BT709),
|
||||
D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV),
|
||||
ROOTSIG_NV },
|
||||
{ D3D12_PixelShader_NV21_JPEG, sizeof(D3D12_PixelShader_NV21_JPEG),
|
||||
D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV),
|
||||
ROOTSIG_NV },
|
||||
{ D3D12_PixelShader_NV21_BT601, sizeof(D3D12_PixelShader_NV21_BT601),
|
||||
D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV),
|
||||
ROOTSIG_NV },
|
||||
{ D3D12_PixelShader_NV21_BT709, sizeof(D3D12_PixelShader_NV21_BT709),
|
||||
D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV),
|
||||
ROOTSIG_NV },
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct
|
||||
{
|
||||
const void *rs_shader_data;
|
||||
SIZE_T rs_shader_size;
|
||||
} D3D12_rootsigs[NUM_ROOTSIGS] = {
|
||||
{ D3D12_RootSig_Color, sizeof(D3D12_RootSig_Color) },
|
||||
{ D3D12_RootSig_Texture, sizeof(D3D12_RootSig_Texture) },
|
||||
#if SDL_HAVE_YUV
|
||||
{ D3D12_RootSig_YUV, sizeof(D3D12_RootSig_YUV) },
|
||||
{ D3D12_RootSig_NV, sizeof(D3D12_RootSig_NV) },
|
||||
#endif
|
||||
};
|
||||
|
||||
extern "C" void
|
||||
D3D12_GetVertexShader(D3D12_Shader shader, D3D12_SHADER_BYTECODE *outBytecode)
|
||||
{
|
||||
outBytecode->pShaderBytecode = D3D12_shaders[shader].vs_shader_data;
|
||||
outBytecode->BytecodeLength = D3D12_shaders[shader].vs_shader_size;
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
D3D12_GetPixelShader(D3D12_Shader shader, D3D12_SHADER_BYTECODE *outBytecode)
|
||||
{
|
||||
outBytecode->pShaderBytecode = D3D12_shaders[shader].ps_shader_data;
|
||||
outBytecode->BytecodeLength = D3D12_shaders[shader].ps_shader_size;
|
||||
}
|
||||
|
||||
extern "C" D3D12_RootSignature
|
||||
D3D12_GetRootSignatureType(D3D12_Shader shader)
|
||||
{
|
||||
return D3D12_shaders[shader].root_sig;
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
D3D12_GetRootSignatureData(D3D12_RootSignature rootSig, D3D12_SHADER_BYTECODE *outBytecode)
|
||||
{
|
||||
outBytecode->pShaderBytecode = D3D12_rootsigs[rootSig].rs_shader_data;
|
||||
outBytecode->BytecodeLength = D3D12_rootsigs[rootSig].rs_shader_size;
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_D3D12 && defined(__XBOXONE__) */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -20,10 +20,125 @@
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED && defined(__XBOXSERIES__)
|
||||
#if SDL_VIDEO_RENDER_D3D12 && defined(__XBOXSERIES__)
|
||||
|
||||
#error "This is a placeholder Xbox file, as the real one is under NDA. See README-gdk.md for more info."
|
||||
#include <SDL_stdinc.h>
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED && defined(__XBOXSERIES__) */
|
||||
#include "../../core/windows/SDL_windows.h"
|
||||
#include <d3d12_xs.h>
|
||||
|
||||
#include "SDL_shaders_d3d12.h"
|
||||
|
||||
#define SDL_COMPOSE_ERROR(str) SDL_STRINGIFY_ARG(__FUNCTION__) ", " str
|
||||
|
||||
/* Shader blob headers are generated with a pre-build step using buildshaders.bat */
|
||||
#include "../VisualC-GDK/shaders/D3D12_PixelShader_Colors_Series.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_PixelShader_Textures_Series.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_PixelShader_NV12_BT601_Series.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_PixelShader_NV12_BT709_Series.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_PixelShader_NV12_JPEG_Series.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_PixelShader_NV21_BT601_Series.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_PixelShader_NV21_BT709_Series.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_PixelShader_NV21_JPEG_Series.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_PixelShader_YUV_BT601_Series.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_PixelShader_YUV_BT709_Series.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_PixelShader_YUV_JPEG_Series.h"
|
||||
|
||||
#include "../VisualC-GDK/shaders/D3D12_VertexShader_Color_Series.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_VertexShader_Texture_Series.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_VertexShader_NV_Series.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_VertexShader_YUV_Series.h"
|
||||
|
||||
#include "../VisualC-GDK/shaders/D3D12_RootSig_Color_Series.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_RootSig_Texture_Series.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_RootSig_YUV_Series.h"
|
||||
#include "../VisualC-GDK/shaders/D3D12_RootSig_NV_Series.h"
|
||||
|
||||
static struct
|
||||
{
|
||||
const void *ps_shader_data;
|
||||
SIZE_T ps_shader_size;
|
||||
const void *vs_shader_data;
|
||||
SIZE_T vs_shader_size;
|
||||
D3D12_RootSignature root_sig;
|
||||
} D3D12_shaders[NUM_SHADERS] = {
|
||||
{ D3D12_PixelShader_Colors, sizeof(D3D12_PixelShader_Colors),
|
||||
D3D12_VertexShader_Color, sizeof(D3D12_VertexShader_Color),
|
||||
ROOTSIG_COLOR },
|
||||
{ D3D12_PixelShader_Textures, sizeof(D3D12_PixelShader_Textures),
|
||||
D3D12_VertexShader_Texture, sizeof(D3D12_VertexShader_Texture),
|
||||
ROOTSIG_TEXTURE },
|
||||
#if SDL_HAVE_YUV
|
||||
{ D3D12_PixelShader_YUV_JPEG, sizeof(D3D12_PixelShader_YUV_JPEG),
|
||||
D3D12_VertexShader_YUV, sizeof(D3D12_VertexShader_YUV),
|
||||
ROOTSIG_YUV },
|
||||
{ D3D12_PixelShader_YUV_BT601, sizeof(D3D12_PixelShader_YUV_BT601),
|
||||
D3D12_VertexShader_YUV, sizeof(D3D12_VertexShader_YUV),
|
||||
ROOTSIG_YUV },
|
||||
{ D3D12_PixelShader_YUV_BT709, sizeof(D3D12_PixelShader_YUV_BT709),
|
||||
D3D12_VertexShader_YUV, sizeof(D3D12_VertexShader_YUV),
|
||||
ROOTSIG_YUV },
|
||||
{ D3D12_PixelShader_NV12_JPEG, sizeof(D3D12_PixelShader_NV12_JPEG),
|
||||
D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV),
|
||||
ROOTSIG_NV },
|
||||
{ D3D12_PixelShader_NV12_BT601, sizeof(D3D12_PixelShader_NV12_BT601),
|
||||
D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV),
|
||||
ROOTSIG_NV },
|
||||
{ D3D12_PixelShader_NV12_BT709, sizeof(D3D12_PixelShader_NV12_BT709),
|
||||
D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV),
|
||||
ROOTSIG_NV },
|
||||
{ D3D12_PixelShader_NV21_JPEG, sizeof(D3D12_PixelShader_NV21_JPEG),
|
||||
D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV),
|
||||
ROOTSIG_NV },
|
||||
{ D3D12_PixelShader_NV21_BT601, sizeof(D3D12_PixelShader_NV21_BT601),
|
||||
D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV),
|
||||
ROOTSIG_NV },
|
||||
{ D3D12_PixelShader_NV21_BT709, sizeof(D3D12_PixelShader_NV21_BT709),
|
||||
D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV),
|
||||
ROOTSIG_NV },
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct
|
||||
{
|
||||
const void *rs_shader_data;
|
||||
SIZE_T rs_shader_size;
|
||||
} D3D12_rootsigs[NUM_ROOTSIGS] = {
|
||||
{ D3D12_RootSig_Color, sizeof(D3D12_RootSig_Color) },
|
||||
{ D3D12_RootSig_Texture, sizeof(D3D12_RootSig_Texture) },
|
||||
#if SDL_HAVE_YUV
|
||||
{ D3D12_RootSig_YUV, sizeof(D3D12_RootSig_YUV) },
|
||||
{ D3D12_RootSig_NV, sizeof(D3D12_RootSig_NV) },
|
||||
#endif
|
||||
};
|
||||
|
||||
extern "C" void
|
||||
D3D12_GetVertexShader(D3D12_Shader shader, D3D12_SHADER_BYTECODE *outBytecode)
|
||||
{
|
||||
outBytecode->pShaderBytecode = D3D12_shaders[shader].vs_shader_data;
|
||||
outBytecode->BytecodeLength = D3D12_shaders[shader].vs_shader_size;
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
D3D12_GetPixelShader(D3D12_Shader shader, D3D12_SHADER_BYTECODE *outBytecode)
|
||||
{
|
||||
outBytecode->pShaderBytecode = D3D12_shaders[shader].ps_shader_data;
|
||||
outBytecode->BytecodeLength = D3D12_shaders[shader].ps_shader_size;
|
||||
}
|
||||
|
||||
extern "C" D3D12_RootSignature
|
||||
D3D12_GetRootSignatureType(D3D12_Shader shader)
|
||||
{
|
||||
return D3D12_shaders[shader].root_sig;
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
D3D12_GetRootSignatureData(D3D12_RootSignature rootSig, D3D12_SHADER_BYTECODE *outBytecode)
|
||||
{
|
||||
outBytecode->pShaderBytecode = D3D12_rootsigs[rootSig].rs_shader_data;
|
||||
outBytecode->BytecodeLength = D3D12_rootsigs[rootSig].rs_shader_size;
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_D3D12 && defined(__XBOXSERIES__) */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_METAL && !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_METAL
|
||||
|
||||
#include "SDL_hints.h"
|
||||
#include "SDL_syswm.h"
|
||||
|
|
@ -1513,8 +1513,6 @@ static void METAL_DestroyRenderer(SDL_Renderer * renderer)
|
|||
/* SDL_Metal_DestroyView(data.mtlview); */
|
||||
CFBridgingRelease(data.mtlview);
|
||||
}
|
||||
|
||||
SDL_free(renderer);
|
||||
}}
|
||||
|
||||
static void *METAL_GetMetalLayer(SDL_Renderer * renderer)
|
||||
|
|
@ -1580,9 +1578,8 @@ static SDL_MetalView GetWindowView(SDL_Window *window)
|
|||
return nil;
|
||||
}
|
||||
|
||||
static SDL_Renderer *METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
|
||||
static int METAL_CreateRenderer(SDL_Renderer *renderer, SDL_Window * window, Uint32 flags)
|
||||
{ @autoreleasepool {
|
||||
SDL_Renderer *renderer = NULL;
|
||||
METAL_RenderData *data = NULL;
|
||||
id<MTLDevice> mtldevice = nil;
|
||||
SDL_MetalView view = NULL;
|
||||
|
|
@ -1641,17 +1638,11 @@ static SDL_Renderer *METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
|
||||
SDL_VERSION(&syswm.version);
|
||||
if (!SDL_GetWindowWMInfo(window, &syswm)) {
|
||||
return NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (IsMetalAvailable(&syswm) == -1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
|
||||
if (!renderer) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef __MACOSX__
|
||||
|
|
@ -1672,9 +1663,7 @@ static SDL_Renderer *METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
}
|
||||
|
||||
if (mtldevice == nil) {
|
||||
SDL_free(renderer);
|
||||
SDL_SetError("Failed to obtain Metal device");
|
||||
return NULL;
|
||||
return SDL_SetError("Failed to obtain Metal device");
|
||||
}
|
||||
|
||||
view = GetWindowView(window);
|
||||
|
|
@ -1683,8 +1672,7 @@ static SDL_Renderer *METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
}
|
||||
|
||||
if (view == NULL) {
|
||||
SDL_free(renderer);
|
||||
return NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// !!! FIXME: error checking on all of this.
|
||||
|
|
@ -1696,8 +1684,7 @@ static SDL_Renderer *METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
*/
|
||||
/* SDL_Metal_DestroyView(view); */
|
||||
CFBridgingRelease(view);
|
||||
SDL_free(renderer);
|
||||
return NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
renderer->driverdata = (void*)CFBridgingRetain(data);
|
||||
|
|
@ -1875,7 +1862,7 @@ static SDL_Renderer *METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
renderer->info.max_texture_width = maxtexsize;
|
||||
renderer->info.max_texture_height = maxtexsize;
|
||||
|
||||
return renderer;
|
||||
return 0;
|
||||
}}
|
||||
|
||||
SDL_RenderDriver METAL_RenderDriver = {
|
||||
|
|
@ -1896,6 +1883,6 @@ SDL_RenderDriver METAL_RenderDriver = {
|
|||
}
|
||||
};
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_METAL && !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_METAL */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_OGL && !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_OGL
|
||||
#include "SDL_hints.h"
|
||||
#include "../../video/SDL_sysvideo.h" /* For SDL_GL_SwapWindowWithResult */
|
||||
#include "SDL_opengl.h"
|
||||
|
|
@ -186,7 +186,7 @@ GL_ClearErrors(SDL_Renderer *renderer)
|
|||
data->errors = 0;
|
||||
data->error_messages = NULL;
|
||||
}
|
||||
} else if (data->glGetError != NULL) {
|
||||
} else if (data->glGetError) {
|
||||
while (data->glGetError() != GL_NO_ERROR) {
|
||||
/* continue; */
|
||||
}
|
||||
|
|
@ -306,7 +306,7 @@ static GL_FBOList *GL_GetFBO(GL_RenderData *data, Uint32 w, Uint32 h)
|
|||
result = result->next;
|
||||
}
|
||||
|
||||
if (result == NULL) {
|
||||
if (!result) {
|
||||
result = SDL_malloc(sizeof(GL_FBOList));
|
||||
if (result) {
|
||||
result->w = w;
|
||||
|
|
@ -458,6 +458,7 @@ static int GL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
GL_ActivateRenderer(renderer);
|
||||
|
||||
renderdata->drawstate.texture = NULL; /* we trash this state. */
|
||||
renderdata->drawstate.texturing = SDL_FALSE; /* we trash this state. */
|
||||
|
||||
if (texture->access == SDL_TEXTUREACCESS_TARGET &&
|
||||
!renderdata->GL_EXT_framebuffer_object_supported) {
|
||||
|
|
@ -471,7 +472,7 @@ static int GL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
}
|
||||
|
||||
data = (GL_TextureData *)SDL_calloc(1, sizeof(*data));
|
||||
if (data == NULL) {
|
||||
if (!data) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
|
|
@ -888,7 +889,7 @@ static int GL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
|
||||
data->drawstate.viewport_dirty = SDL_TRUE;
|
||||
|
||||
if (texture == NULL) {
|
||||
if (!texture) {
|
||||
data->glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -918,7 +919,7 @@ static int GL_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, co
|
|||
GLfloat *verts = (GLfloat *)SDL_AllocateRenderVertices(renderer, count * 2 * sizeof(GLfloat), 0, &cmd->data.draw.first);
|
||||
int i;
|
||||
|
||||
if (verts == NULL) {
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -938,7 +939,7 @@ static int GL_QueueDrawLines(SDL_Renderer *renderer, SDL_RenderCommand *cmd, con
|
|||
const size_t vertlen = (sizeof(GLfloat) * 2) * count;
|
||||
GLfloat *verts = (GLfloat *)SDL_AllocateRenderVertices(renderer, vertlen, 0, &cmd->data.draw.first);
|
||||
|
||||
if (verts == NULL) {
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
cmd->data.draw.count = count;
|
||||
|
|
@ -983,7 +984,7 @@ static int GL_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_
|
|||
size_t sz = 2 * sizeof(GLfloat) + 4 * sizeof(Uint8) + (texture ? 2 : 0) * sizeof(GLfloat);
|
||||
|
||||
verts = (GLfloat *)SDL_AllocateRenderVertices(renderer, count * sz, 0, &cmd->data.draw.first);
|
||||
if (verts == NULL) {
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -1089,7 +1090,7 @@ static int SetDrawState(GL_RenderData *data, const SDL_RenderCommand *cmd, const
|
|||
}
|
||||
|
||||
if ((cmd->data.draw.texture != NULL) != data->drawstate.texturing) {
|
||||
if (cmd->data.draw.texture == NULL) {
|
||||
if (!cmd->data.draw.texture) {
|
||||
data->glDisable(data->textype);
|
||||
data->drawstate.texturing = SDL_FALSE;
|
||||
} else {
|
||||
|
|
@ -1223,6 +1224,7 @@ static int GL_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo
|
|||
if (SDL_memcmp(viewport, &cmd->data.viewport.rect, sizeof(cmd->data.viewport.rect)) != 0) {
|
||||
SDL_copyp(viewport, &cmd->data.viewport.rect);
|
||||
data->drawstate.viewport_dirty = SDL_TRUE;
|
||||
data->drawstate.cliprect_dirty = SDL_TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -1294,7 +1296,7 @@ static int GL_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo
|
|||
SDL_RenderCommand *nextcmd = cmd->next;
|
||||
SDL_BlendMode thisblend = cmd->data.draw.blend;
|
||||
|
||||
while (nextcmd != NULL) {
|
||||
while (nextcmd) {
|
||||
const SDL_RenderCommandType nextcmdtype = nextcmd->command;
|
||||
if (nextcmdtype != SDL_RENDERCMD_DRAW_LINES) {
|
||||
break; /* can't go any further on this draw call, different render command up next. */
|
||||
|
|
@ -1328,7 +1330,7 @@ static int GL_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo
|
|||
SDL_RenderCommand *nextcmd = cmd->next;
|
||||
size_t count = cmd->data.draw.count;
|
||||
int ret;
|
||||
while (nextcmd != NULL) {
|
||||
while (nextcmd) {
|
||||
const SDL_RenderCommandType nextcmdtype = nextcmd->command;
|
||||
if (nextcmdtype != thiscmdtype) {
|
||||
break; /* can't go any further on this draw call, different render command up next. */
|
||||
|
|
@ -1437,7 +1439,7 @@ static int GL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
|
|||
|
||||
temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format);
|
||||
temp_pixels = SDL_malloc((size_t)rect->h * temp_pitch);
|
||||
if (temp_pixels == NULL) {
|
||||
if (!temp_pixels) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
|
|
@ -1502,7 +1504,7 @@ static void GL_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
renderdata->drawstate.target = NULL;
|
||||
}
|
||||
|
||||
if (data == NULL) {
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
if (data->texture) {
|
||||
|
|
@ -1524,7 +1526,7 @@ static void GL_DestroyRenderer(SDL_Renderer *renderer)
|
|||
GL_RenderData *data = (GL_RenderData *)renderer->driverdata;
|
||||
|
||||
if (data) {
|
||||
if (data->context != NULL) {
|
||||
if (data->context) {
|
||||
/* make sure we delete the right resources! */
|
||||
GL_ActivateRenderer(renderer);
|
||||
}
|
||||
|
|
@ -1553,7 +1555,6 @@ static void GL_DestroyRenderer(SDL_Renderer *renderer)
|
|||
}
|
||||
SDL_free(data);
|
||||
}
|
||||
SDL_free(renderer);
|
||||
}
|
||||
|
||||
static int GL_BindTexture(SDL_Renderer *renderer, SDL_Texture *texture, float *texw, float *texh)
|
||||
|
|
@ -1664,7 +1665,7 @@ static int GL_SetVSync(SDL_Renderer *renderer, const int vsync)
|
|||
if (retval != 0) {
|
||||
return retval;
|
||||
}
|
||||
if (SDL_GL_GetSwapInterval() > 0) {
|
||||
if (SDL_GL_GetSwapInterval() != 0) {
|
||||
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
|
||||
} else {
|
||||
renderer->info.flags &= ~SDL_RENDERER_PRESENTVSYNC;
|
||||
|
|
@ -1698,9 +1699,8 @@ static SDL_bool GL_IsProbablyAccelerated(const GL_RenderData *data)
|
|||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
static SDL_Renderer *GL_CreateRenderer(SDL_Window *window, Uint32 flags)
|
||||
static int GL_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, Uint32 flags)
|
||||
{
|
||||
SDL_Renderer *renderer;
|
||||
GL_RenderData *data;
|
||||
GLint value;
|
||||
Uint32 window_flags;
|
||||
|
|
@ -1729,15 +1729,8 @@ static SDL_Renderer *GL_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
}
|
||||
#endif
|
||||
|
||||
renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(*renderer));
|
||||
if (renderer == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
goto error;
|
||||
}
|
||||
|
||||
data = (GL_RenderData *)SDL_calloc(1, sizeof(*data));
|
||||
if (data == NULL) {
|
||||
SDL_free(renderer);
|
||||
if (!data) {
|
||||
SDL_OutOfMemory();
|
||||
goto error;
|
||||
}
|
||||
|
|
@ -1775,20 +1768,17 @@ static SDL_Renderer *GL_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
|
||||
data->context = SDL_GL_CreateContext(window);
|
||||
if (!data->context) {
|
||||
SDL_free(renderer);
|
||||
SDL_free(data);
|
||||
goto error;
|
||||
}
|
||||
if (SDL_GL_MakeCurrent(window, data->context) < 0) {
|
||||
SDL_GL_DeleteContext(data->context);
|
||||
SDL_free(renderer);
|
||||
SDL_free(data);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (GL_LoadFunctions(data) < 0) {
|
||||
SDL_GL_DeleteContext(data->context);
|
||||
SDL_free(renderer);
|
||||
SDL_free(data);
|
||||
goto error;
|
||||
}
|
||||
|
|
@ -1809,7 +1799,7 @@ static SDL_Renderer *GL_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
} else {
|
||||
SDL_GL_SetSwapInterval(0);
|
||||
}
|
||||
if (SDL_GL_GetSwapInterval() > 0) {
|
||||
if (SDL_GL_GetSwapInterval() != 0) {
|
||||
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
|
||||
}
|
||||
|
||||
|
|
@ -1831,7 +1821,7 @@ static SDL_Renderer *GL_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
}
|
||||
|
||||
hint = SDL_getenv("GL_ARB_texture_non_power_of_two");
|
||||
if (hint == NULL || *hint != '0') {
|
||||
if (!hint || *hint != '0') {
|
||||
SDL_bool isGL2 = SDL_FALSE;
|
||||
const char *verstr = (const char *)data->glGetString(GL_VERSION);
|
||||
if (verstr) {
|
||||
|
|
@ -1942,7 +1932,7 @@ static SDL_Renderer *GL_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
data->drawstate.color = 0xFFFFFFFF;
|
||||
data->drawstate.clear_color = 0xFFFFFFFF;
|
||||
|
||||
return renderer;
|
||||
return 0;
|
||||
|
||||
error:
|
||||
if (changed_window) {
|
||||
|
|
@ -1952,7 +1942,7 @@ error:
|
|||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minor);
|
||||
SDL_RecreateWindow(window, window_flags);
|
||||
}
|
||||
return NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDL_RenderDriver GL_RenderDriver = {
|
||||
|
|
@ -1968,6 +1958,6 @@ SDL_RenderDriver GL_RenderDriver = {
|
|||
0 }
|
||||
};
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_OGL && !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_OGL */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_OGL && !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_OGL
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_opengl.h"
|
||||
|
|
@ -497,7 +497,7 @@ GL_ShaderContext *GL_CreateShaderContext(void)
|
|||
int i;
|
||||
|
||||
ctx = (GL_ShaderContext *)SDL_calloc(1, sizeof(*ctx));
|
||||
if (ctx == NULL) {
|
||||
if (!ctx) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -577,6 +577,6 @@ void GL_DestroyShaderContext(GL_ShaderContext *ctx)
|
|||
SDL_free(ctx);
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_OGL && !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_OGL */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_OGL_ES && !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_OGL_ES
|
||||
|
||||
#include "SDL_hints.h"
|
||||
#include "../../video/SDL_sysvideo.h" /* For SDL_GL_SwapWindowWithResult */
|
||||
|
|
@ -150,11 +150,11 @@ static int GLES_SetError(const char *prefix, GLenum result)
|
|||
|
||||
static int GLES_LoadFunctions(GLES_RenderData *data)
|
||||
{
|
||||
#if SDL_VIDEO_DRIVER_UIKIT
|
||||
#ifdef SDL_VIDEO_DRIVER_UIKIT
|
||||
#define __SDL_NOGETPROCADDR__
|
||||
#elif SDL_VIDEO_DRIVER_ANDROID
|
||||
#elif defined(SDL_VIDEO_DRIVER_ANDROID)
|
||||
#define __SDL_NOGETPROCADDR__
|
||||
#elif SDL_VIDEO_DRIVER_PANDORA
|
||||
#elif defined(SDL_VIDEO_DRIVER_PANDORA)
|
||||
#define __SDL_NOGETPROCADDR__
|
||||
#endif
|
||||
|
||||
|
|
@ -187,7 +187,7 @@ static GLES_FBOList *GLES_GetFBO(GLES_RenderData *data, Uint32 w, Uint32 h)
|
|||
while ((result) && ((result->w != w) || (result->h != h))) {
|
||||
result = result->next;
|
||||
}
|
||||
if (result == NULL) {
|
||||
if (!result) {
|
||||
result = SDL_malloc(sizeof(GLES_FBOList));
|
||||
result->w = w;
|
||||
result->h = h;
|
||||
|
|
@ -322,7 +322,7 @@ static int GLES_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
GLES_ActivateRenderer(renderer);
|
||||
|
||||
switch (texture->format) {
|
||||
case SDL_PIXELFORMAT_ABGR8888:
|
||||
case SDL_PIXELFORMAT_RGBA32:
|
||||
internalFormat = GL_RGBA;
|
||||
format = GL_RGBA;
|
||||
type = GL_UNSIGNED_BYTE;
|
||||
|
|
@ -332,7 +332,7 @@ static int GLES_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
}
|
||||
|
||||
data = (GLES_TextureData *)SDL_calloc(1, sizeof(*data));
|
||||
if (data == NULL) {
|
||||
if (!data) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
|
|
@ -424,7 +424,7 @@ static int GLES_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
|
|||
src = (Uint8 *)pixels;
|
||||
if (pitch != srcPitch) {
|
||||
blob = (Uint8 *)SDL_malloc(srcPitch * rect->h);
|
||||
if (blob == NULL) {
|
||||
if (!blob) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
src = blob;
|
||||
|
|
@ -510,7 +510,7 @@ static int GLES_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
|
||||
data->drawstate.viewport_dirty = SDL_TRUE;
|
||||
|
||||
if (texture == NULL) {
|
||||
if (!texture) {
|
||||
data->glBindFramebufferOES(GL_FRAMEBUFFER_OES, data->window_framebuffer);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -537,7 +537,7 @@ static int GLES_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
|
|||
GLfloat *verts = (GLfloat *)SDL_AllocateRenderVertices(renderer, count * 2 * sizeof(GLfloat), 0, &cmd->data.draw.first);
|
||||
int i;
|
||||
|
||||
if (verts == NULL) {
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -557,7 +557,7 @@ static int GLES_QueueDrawLines(SDL_Renderer *renderer, SDL_RenderCommand *cmd, c
|
|||
const size_t vertlen = (sizeof(GLfloat) * 2) * count;
|
||||
GLfloat *verts = (GLfloat *)SDL_AllocateRenderVertices(renderer, vertlen, 0, &cmd->data.draw.first);
|
||||
|
||||
if (verts == NULL) {
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
cmd->data.draw.count = count;
|
||||
|
|
@ -602,7 +602,7 @@ static int GLES_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SD
|
|||
int sz = 2 + 4 + (texture ? 2 : 0);
|
||||
|
||||
verts = (GLfloat *)SDL_AllocateRenderVertices(renderer, count * sz * sizeof(GLfloat), 0, &cmd->data.draw.first);
|
||||
if (verts == NULL) {
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -900,7 +900,7 @@ static int GLES_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
|
|||
Uint32 pixel_format, void *pixels, int pitch)
|
||||
{
|
||||
GLES_RenderData *data = (GLES_RenderData *)renderer->driverdata;
|
||||
Uint32 temp_format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_ABGR8888;
|
||||
Uint32 temp_format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_RGBA32;
|
||||
void *temp_pixels;
|
||||
int temp_pitch;
|
||||
Uint8 *src, *dst, *tmp;
|
||||
|
|
@ -911,7 +911,7 @@ static int GLES_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
|
|||
|
||||
temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format);
|
||||
temp_pixels = SDL_malloc(rect->h * temp_pitch);
|
||||
if (temp_pixels == NULL) {
|
||||
if (!temp_pixels) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
|
|
@ -970,7 +970,7 @@ static void GLES_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
renderdata->drawstate.target = NULL;
|
||||
}
|
||||
|
||||
if (data == NULL) {
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
if (data->texture) {
|
||||
|
|
@ -997,7 +997,6 @@ static void GLES_DestroyRenderer(SDL_Renderer *renderer)
|
|||
}
|
||||
SDL_free(data);
|
||||
}
|
||||
SDL_free(renderer);
|
||||
}
|
||||
|
||||
static int GLES_BindTexture(SDL_Renderer *renderer, SDL_Texture *texture, float *texw, float *texh)
|
||||
|
|
@ -1046,7 +1045,7 @@ static int GLES_SetVSync(SDL_Renderer *renderer, const int vsync)
|
|||
if (retval != 0) {
|
||||
return retval;
|
||||
}
|
||||
if (SDL_GL_GetSwapInterval() > 0) {
|
||||
if (SDL_GL_GetSwapInterval() != 0) {
|
||||
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
|
||||
} else {
|
||||
renderer->info.flags &= ~SDL_RENDERER_PRESENTVSYNC;
|
||||
|
|
@ -1054,10 +1053,9 @@ static int GLES_SetVSync(SDL_Renderer *renderer, const int vsync)
|
|||
return retval;
|
||||
}
|
||||
|
||||
static SDL_Renderer *GLES_CreateRenderer(SDL_Window *window, Uint32 flags)
|
||||
static int GLES_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, Uint32 flags)
|
||||
{
|
||||
SDL_Renderer *renderer;
|
||||
GLES_RenderData *data;
|
||||
GLES_RenderData *data = NULL;
|
||||
GLint value;
|
||||
Uint32 window_flags;
|
||||
int profile_mask = 0, major = 0, minor = 0;
|
||||
|
|
@ -1081,14 +1079,8 @@ static SDL_Renderer *GLES_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
}
|
||||
}
|
||||
|
||||
renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(*renderer));
|
||||
if (renderer == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
goto error;
|
||||
}
|
||||
|
||||
data = (GLES_RenderData *)SDL_calloc(1, sizeof(*data));
|
||||
if (data == NULL) {
|
||||
if (!data) {
|
||||
GLES_DestroyRenderer(renderer);
|
||||
SDL_OutOfMemory();
|
||||
goto error;
|
||||
|
|
@ -1141,7 +1133,7 @@ static SDL_Renderer *GLES_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
} else {
|
||||
SDL_GL_SetSwapInterval(0);
|
||||
}
|
||||
if (SDL_GL_GetSwapInterval() > 0) {
|
||||
if (SDL_GL_GetSwapInterval() != 0) {
|
||||
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
|
||||
}
|
||||
|
||||
|
|
@ -1192,7 +1184,7 @@ static SDL_Renderer *GLES_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
data->drawstate.color = 0xFFFFFFFF;
|
||||
data->drawstate.clear_color = 0xFFFFFFFF;
|
||||
|
||||
return renderer;
|
||||
return 0;
|
||||
|
||||
error:
|
||||
if (changed_window) {
|
||||
|
|
@ -1202,7 +1194,7 @@ error:
|
|||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minor);
|
||||
SDL_RecreateWindow(window, window_flags);
|
||||
}
|
||||
return NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDL_RenderDriver GLES_RenderDriver = {
|
||||
|
|
@ -1210,11 +1202,11 @@ SDL_RenderDriver GLES_RenderDriver = {
|
|||
{ "opengles",
|
||||
(SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC),
|
||||
1,
|
||||
{ SDL_PIXELFORMAT_ABGR8888 },
|
||||
{ SDL_PIXELFORMAT_RGBA32 },
|
||||
0,
|
||||
0 }
|
||||
};
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_OGL_ES && !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_OGL_ES */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -53,7 +53,7 @@ SDL_PROC(void, glPixelStorei, (GLenum, GLint))
|
|||
SDL_PROC(void, glReadPixels, (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid *))
|
||||
SDL_PROC(void, glScissor, (GLint, GLint, GLsizei, GLsizei))
|
||||
SDL_PROC(void, glShaderBinary, (GLsizei, const GLuint *, GLenum, const void *, GLsizei))
|
||||
#if __NACL__
|
||||
#ifdef __NACL__
|
||||
SDL_PROC(void, glShaderSource, (GLuint, GLsizei, const GLchar **, const GLint *))
|
||||
#else
|
||||
SDL_PROC(void, glShaderSource, (GLuint, GLsizei, const GLchar* const*, const GLint *))
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_OGL_ES2 && !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_OGL_ES2
|
||||
|
||||
#include "SDL_hints.h"
|
||||
#include "../../video/SDL_sysvideo.h" /* For SDL_GL_SwapWindowWithResult */
|
||||
|
|
@ -220,7 +220,7 @@ GL_CheckAllErrors(const char *prefix, SDL_Renderer *renderer, const char *file,
|
|||
for (;;) {
|
||||
GLenum error = data->glGetError();
|
||||
if (error != GL_NO_ERROR) {
|
||||
if (prefix == NULL || prefix[0] == '\0') {
|
||||
if (!prefix || prefix[0] == '\0') {
|
||||
prefix = "generic";
|
||||
}
|
||||
SDL_SetError("%s: %s (%d): %s %s (0x%X)", prefix, file, line, function, GL_TranslateError(error), error);
|
||||
|
|
@ -244,11 +244,11 @@ GL_CheckAllErrors(const char *prefix, SDL_Renderer *renderer, const char *file,
|
|||
|
||||
static int GLES2_LoadFunctions(GLES2_RenderData *data)
|
||||
{
|
||||
#if SDL_VIDEO_DRIVER_UIKIT
|
||||
#ifdef SDL_VIDEO_DRIVER_UIKIT
|
||||
#define __SDL_NOGETPROCADDR__
|
||||
#elif SDL_VIDEO_DRIVER_ANDROID
|
||||
#elif defined(SDL_VIDEO_DRIVER_ANDROID)
|
||||
#define __SDL_NOGETPROCADDR__
|
||||
#elif SDL_VIDEO_DRIVER_PANDORA
|
||||
#elif defined(SDL_VIDEO_DRIVER_PANDORA)
|
||||
#define __SDL_NOGETPROCADDR__
|
||||
#endif
|
||||
|
||||
|
|
@ -275,7 +275,7 @@ static GLES2_FBOList *GLES2_GetFBO(GLES2_RenderData *data, Uint32 w, Uint32 h)
|
|||
while ((result) && ((result->w != w) || (result->h != h))) {
|
||||
result = result->next;
|
||||
}
|
||||
if (result == NULL) {
|
||||
if (!result) {
|
||||
result = SDL_malloc(sizeof(GLES2_FBOList));
|
||||
result->w = w;
|
||||
result->h = h;
|
||||
|
|
@ -427,7 +427,7 @@ static GLES2_ProgramCacheEntry *GLES2_CacheProgram(GLES2_RenderData *data, GLuin
|
|||
|
||||
/* Create a program cache entry */
|
||||
entry = (GLES2_ProgramCacheEntry *)SDL_calloc(1, sizeof(GLES2_ProgramCacheEntry));
|
||||
if (entry == NULL) {
|
||||
if (!entry) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -488,7 +488,7 @@ static GLES2_ProgramCacheEntry *GLES2_CacheProgram(GLES2_RenderData *data, GLuin
|
|||
if (data->program_cache.count > GLES2_MAX_CACHED_PROGRAMS) {
|
||||
data->glDeleteProgram(data->program_cache.tail->id);
|
||||
data->program_cache.tail = data->program_cache.tail->prev;
|
||||
if (data->program_cache.tail != NULL) {
|
||||
if (data->program_cache.tail) {
|
||||
SDL_free(data->program_cache.tail->next);
|
||||
data->program_cache.tail->next = NULL;
|
||||
}
|
||||
|
|
@ -505,7 +505,7 @@ static GLuint GLES2_CacheShader(GLES2_RenderData *data, GLES2_ShaderType type, G
|
|||
const GLchar *shader_src_list[3];
|
||||
const GLchar *shader_body = GLES2_GetShader(type);
|
||||
|
||||
if (shader_body == NULL) {
|
||||
if (!shader_body) {
|
||||
SDL_SetError("No shader body src");
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -715,7 +715,7 @@ static int GLES2_SelectProgram(GLES2_RenderData *data, GLES2_ImageSource source,
|
|||
|
||||
/* Generate a matching program */
|
||||
program = GLES2_CacheProgram(data, vertex, fragment);
|
||||
if (program == NULL) {
|
||||
if (!program) {
|
||||
goto fault;
|
||||
}
|
||||
|
||||
|
|
@ -739,7 +739,7 @@ static int GLES2_QueueSetViewport(SDL_Renderer *renderer, SDL_RenderCommand *cmd
|
|||
|
||||
static int GLES2_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count)
|
||||
{
|
||||
const SDL_bool colorswap = (renderer->target && (renderer->target->format == SDL_PIXELFORMAT_ARGB8888 || renderer->target->format == SDL_PIXELFORMAT_RGB888));
|
||||
const SDL_bool colorswap = (renderer->target && (renderer->target->format == SDL_PIXELFORMAT_BGRA32 || renderer->target->format == SDL_PIXELFORMAT_BGRX32));
|
||||
SDL_VertexSolid *verts = (SDL_VertexSolid *)SDL_AllocateRenderVertices(renderer, count * sizeof(*verts), 0, &cmd->data.draw.first);
|
||||
int i;
|
||||
SDL_Color color;
|
||||
|
|
@ -748,7 +748,7 @@ static int GLES2_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
|
|||
color.b = cmd->data.draw.b;
|
||||
color.a = cmd->data.draw.a;
|
||||
|
||||
if (verts == NULL) {
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -771,7 +771,7 @@ static int GLES2_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
|
|||
|
||||
static int GLES2_QueueDrawLines(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count)
|
||||
{
|
||||
const SDL_bool colorswap = (renderer->target && (renderer->target->format == SDL_PIXELFORMAT_ARGB8888 || renderer->target->format == SDL_PIXELFORMAT_RGB888));
|
||||
const SDL_bool colorswap = (renderer->target && (renderer->target->format == SDL_PIXELFORMAT_BGRA32 || renderer->target->format == SDL_PIXELFORMAT_BGRX32));
|
||||
int i;
|
||||
GLfloat prevx, prevy;
|
||||
SDL_VertexSolid *verts = (SDL_VertexSolid *)SDL_AllocateRenderVertices(renderer, count * sizeof(*verts), 0, &cmd->data.draw.first);
|
||||
|
|
@ -781,7 +781,7 @@ static int GLES2_QueueDrawLines(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
|
|||
color.b = cmd->data.draw.b;
|
||||
color.a = cmd->data.draw.a;
|
||||
|
||||
if (verts == NULL) {
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -831,7 +831,7 @@ static int GLES2_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, S
|
|||
float scale_x, float scale_y)
|
||||
{
|
||||
int i;
|
||||
const SDL_bool colorswap = (renderer->target && (renderer->target->format == SDL_PIXELFORMAT_ARGB8888 || renderer->target->format == SDL_PIXELFORMAT_RGB888));
|
||||
const SDL_bool colorswap = (renderer->target && (renderer->target->format == SDL_PIXELFORMAT_BGRA32 || renderer->target->format == SDL_PIXELFORMAT_BGRX32));
|
||||
int count = indices ? num_indices : num_vertices;
|
||||
|
||||
cmd->data.draw.count = count;
|
||||
|
|
@ -839,7 +839,7 @@ static int GLES2_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, S
|
|||
|
||||
if (texture) {
|
||||
SDL_Vertex *verts = (SDL_Vertex *)SDL_AllocateRenderVertices(renderer, count * sizeof(*verts), 0, &cmd->data.draw.first);
|
||||
if (verts == NULL) {
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -879,7 +879,7 @@ static int GLES2_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, S
|
|||
|
||||
} else {
|
||||
SDL_VertexSolid *verts = (SDL_VertexSolid *)SDL_AllocateRenderVertices(renderer, count * sizeof(*verts), 0, &cmd->data.draw.first);
|
||||
if (verts == NULL) {
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -959,7 +959,7 @@ static int SetDrawState(GLES2_RenderData *data, const SDL_RenderCommand *cmd, co
|
|||
}
|
||||
|
||||
if ((texture != NULL) != data->drawstate.texturing) {
|
||||
if (texture == NULL) {
|
||||
if (!texture) {
|
||||
data->glDisableVertexAttribArray((GLenum)GLES2_ATTRIBUTE_TEXCOORD);
|
||||
data->drawstate.texturing = SDL_FALSE;
|
||||
} else {
|
||||
|
|
@ -975,8 +975,8 @@ static int SetDrawState(GLES2_RenderData *data, const SDL_RenderCommand *cmd, co
|
|||
}
|
||||
|
||||
if (texture) {
|
||||
SDL_Vertex *verts = (SDL_Vertex *)(((Uint8 *)vertices) + cmd->data.draw.first);
|
||||
data->glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, stride, (const GLvoid *)&verts->tex_coord);
|
||||
uintptr_t base = (uintptr_t)vertices + cmd->data.draw.first; // address of first vertex, or base offset when using VBOs.
|
||||
data->glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, stride, (const GLvoid *)(base + offsetof(SDL_Vertex, tex_coord)));
|
||||
}
|
||||
|
||||
if (GLES2_SelectProgram(data, imgsrc, texture ? texture->w : 0, texture ? texture->h : 0) < 0) {
|
||||
|
|
@ -1009,9 +1009,9 @@ static int SetDrawState(GLES2_RenderData *data, const SDL_RenderCommand *cmd, co
|
|||
|
||||
/* all drawing commands use this */
|
||||
{
|
||||
SDL_VertexSolid *verts = (SDL_VertexSolid *)(((Uint8 *)vertices) + cmd->data.draw.first);
|
||||
data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, stride, (const GLvoid *)&verts->position);
|
||||
data->glVertexAttribPointer(GLES2_ATTRIBUTE_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE /* Normalized */, stride, (const GLvoid *)&verts->color);
|
||||
uintptr_t base = (uintptr_t)vertices + cmd->data.draw.first; // address of first vertex, or base offset when using VBOs.
|
||||
data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, stride, (const GLvoid *)(base + offsetof(SDL_VertexSolid, position)));
|
||||
data->glVertexAttribPointer(GLES2_ATTRIBUTE_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE /* Normalized */, stride, (const GLvoid *)(base + offsetof(SDL_VertexSolid, color)));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -1029,50 +1029,50 @@ static int SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, vo
|
|||
/* Check if we need to do color mapping between the source and render target textures */
|
||||
if (renderer->target->format != texture->format) {
|
||||
switch (texture->format) {
|
||||
case SDL_PIXELFORMAT_ARGB8888:
|
||||
case SDL_PIXELFORMAT_BGRA32:
|
||||
switch (renderer->target->format) {
|
||||
case SDL_PIXELFORMAT_ABGR8888:
|
||||
case SDL_PIXELFORMAT_BGR888:
|
||||
case SDL_PIXELFORMAT_RGBA32:
|
||||
case SDL_PIXELFORMAT_RGBX32:
|
||||
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
|
||||
break;
|
||||
case SDL_PIXELFORMAT_RGB888:
|
||||
case SDL_PIXELFORMAT_BGRX32:
|
||||
sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SDL_PIXELFORMAT_ABGR8888:
|
||||
case SDL_PIXELFORMAT_RGBA32:
|
||||
switch (renderer->target->format) {
|
||||
case SDL_PIXELFORMAT_ARGB8888:
|
||||
case SDL_PIXELFORMAT_RGB888:
|
||||
case SDL_PIXELFORMAT_BGRA32:
|
||||
case SDL_PIXELFORMAT_BGRX32:
|
||||
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
|
||||
break;
|
||||
case SDL_PIXELFORMAT_BGR888:
|
||||
case SDL_PIXELFORMAT_RGBX32:
|
||||
sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SDL_PIXELFORMAT_RGB888:
|
||||
case SDL_PIXELFORMAT_BGRX32:
|
||||
switch (renderer->target->format) {
|
||||
case SDL_PIXELFORMAT_ABGR8888:
|
||||
case SDL_PIXELFORMAT_RGBA32:
|
||||
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
|
||||
break;
|
||||
case SDL_PIXELFORMAT_ARGB8888:
|
||||
case SDL_PIXELFORMAT_BGRA32:
|
||||
sourceType = GLES2_IMAGESOURCE_TEXTURE_BGR;
|
||||
break;
|
||||
case SDL_PIXELFORMAT_BGR888:
|
||||
case SDL_PIXELFORMAT_RGBX32:
|
||||
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SDL_PIXELFORMAT_BGR888:
|
||||
case SDL_PIXELFORMAT_RGBX32:
|
||||
switch (renderer->target->format) {
|
||||
case SDL_PIXELFORMAT_ABGR8888:
|
||||
case SDL_PIXELFORMAT_RGBA32:
|
||||
sourceType = GLES2_IMAGESOURCE_TEXTURE_BGR;
|
||||
break;
|
||||
case SDL_PIXELFORMAT_ARGB8888:
|
||||
case SDL_PIXELFORMAT_BGRA32:
|
||||
sourceType = GLES2_IMAGESOURCE_TEXTURE_RGB;
|
||||
break;
|
||||
case SDL_PIXELFORMAT_RGB888:
|
||||
case SDL_PIXELFORMAT_BGRX32:
|
||||
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
|
||||
break;
|
||||
}
|
||||
|
|
@ -1100,16 +1100,16 @@ static int SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, vo
|
|||
}
|
||||
} else {
|
||||
switch (texture->format) {
|
||||
case SDL_PIXELFORMAT_ARGB8888:
|
||||
case SDL_PIXELFORMAT_BGRA32:
|
||||
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
|
||||
break;
|
||||
case SDL_PIXELFORMAT_ABGR8888:
|
||||
case SDL_PIXELFORMAT_RGBA32:
|
||||
sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR;
|
||||
break;
|
||||
case SDL_PIXELFORMAT_RGB888:
|
||||
case SDL_PIXELFORMAT_BGRX32:
|
||||
sourceType = GLES2_IMAGESOURCE_TEXTURE_RGB;
|
||||
break;
|
||||
case SDL_PIXELFORMAT_BGR888:
|
||||
case SDL_PIXELFORMAT_RGBX32:
|
||||
sourceType = GLES2_IMAGESOURCE_TEXTURE_BGR;
|
||||
break;
|
||||
#if SDL_HAVE_YUV
|
||||
|
|
@ -1162,7 +1162,7 @@ static int SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, vo
|
|||
static int GLES2_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
|
||||
{
|
||||
GLES2_RenderData *data = (GLES2_RenderData *)renderer->driverdata;
|
||||
const SDL_bool colorswap = (renderer->target && (renderer->target->format == SDL_PIXELFORMAT_ARGB8888 || renderer->target->format == SDL_PIXELFORMAT_RGB888));
|
||||
const SDL_bool colorswap = (renderer->target && (renderer->target->format == SDL_PIXELFORMAT_BGRA32 || renderer->target->format == SDL_PIXELFORMAT_BGRX32));
|
||||
|
||||
#if USE_VERTEX_BUFFER_OBJECTS
|
||||
const int vboidx = data->current_vertex_buffer;
|
||||
|
|
@ -1200,7 +1200,8 @@ static int GLES2_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
|
|||
if (data->current_vertex_buffer >= SDL_arraysize(data->vertex_buffers)) {
|
||||
data->current_vertex_buffer = 0;
|
||||
}
|
||||
vertices = NULL; /* attrib pointers will be offsets into the VBO. */
|
||||
// attrib pointers will be offsets into the VBO.
|
||||
vertices = (void *)(uintptr_t)0; // must be the exact value 0, not NULL (the representation of NULL is not guaranteed to be 0).
|
||||
#endif
|
||||
|
||||
while (cmd) {
|
||||
|
|
@ -1216,6 +1217,7 @@ static int GLES2_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
|
|||
if (SDL_memcmp(viewport, &cmd->data.viewport.rect, sizeof(cmd->data.viewport.rect)) != 0) {
|
||||
SDL_copyp(viewport, &cmd->data.viewport.rect);
|
||||
data->drawstate.viewport_dirty = SDL_TRUE;
|
||||
data->drawstate.cliprect_dirty = SDL_TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -1282,7 +1284,7 @@ static int GLES2_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
|
|||
SDL_RenderCommand *nextcmd = cmd->next;
|
||||
SDL_BlendMode thisblend = cmd->data.draw.blend;
|
||||
|
||||
while (nextcmd != NULL) {
|
||||
while (nextcmd) {
|
||||
const SDL_RenderCommandType nextcmdtype = nextcmd->command;
|
||||
if (nextcmdtype != SDL_RENDERCMD_DRAW_LINES) {
|
||||
break; /* can't go any further on this draw call, different render command up next. */
|
||||
|
|
@ -1316,7 +1318,7 @@ static int GLES2_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
|
|||
SDL_RenderCommand *nextcmd = cmd->next;
|
||||
size_t count = cmd->data.draw.count;
|
||||
int ret;
|
||||
while (nextcmd != NULL) {
|
||||
while (nextcmd) {
|
||||
const SDL_RenderCommandType nextcmdtype = nextcmd->command;
|
||||
if (nextcmdtype != thiscmdtype) {
|
||||
break; /* can't go any further on this draw call, different render command up next. */
|
||||
|
|
@ -1405,7 +1407,6 @@ static void GLES2_DestroyRenderer(SDL_Renderer *renderer)
|
|||
|
||||
SDL_free(data);
|
||||
}
|
||||
SDL_free(renderer);
|
||||
}
|
||||
|
||||
static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
||||
|
|
@ -1422,10 +1423,10 @@ static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
|
||||
/* Determine the corresponding GLES texture format params */
|
||||
switch (texture->format) {
|
||||
case SDL_PIXELFORMAT_ARGB8888:
|
||||
case SDL_PIXELFORMAT_ABGR8888:
|
||||
case SDL_PIXELFORMAT_RGB888:
|
||||
case SDL_PIXELFORMAT_BGR888:
|
||||
case SDL_PIXELFORMAT_BGRA32:
|
||||
case SDL_PIXELFORMAT_RGBA32:
|
||||
case SDL_PIXELFORMAT_BGRX32:
|
||||
case SDL_PIXELFORMAT_RGBX32:
|
||||
format = GL_RGBA;
|
||||
type = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
|
|
@ -1455,7 +1456,7 @@ static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
|
||||
/* Allocate a texture struct */
|
||||
data = (GLES2_TextureData *)SDL_calloc(1, sizeof(GLES2_TextureData));
|
||||
if (data == NULL) {
|
||||
if (!data) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
data->texture = 0;
|
||||
|
|
@ -1574,9 +1575,6 @@ static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
static int GLES2_TexSubImage2D(GLES2_RenderData *data, GLenum target, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels, GLint pitch, GLint bpp)
|
||||
{
|
||||
Uint8 *blob = NULL;
|
||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||
Uint32 *blob2 = NULL;
|
||||
#endif
|
||||
Uint8 *src;
|
||||
size_t src_pitch;
|
||||
int y;
|
||||
|
|
@ -1590,7 +1588,7 @@ static int GLES2_TexSubImage2D(GLES2_RenderData *data, GLenum target, GLint xoff
|
|||
src = (Uint8 *)pixels;
|
||||
if (pitch != src_pitch) {
|
||||
blob = (Uint8 *)SDL_malloc(src_pitch * height);
|
||||
if (blob == NULL) {
|
||||
if (!blob) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
src = blob;
|
||||
|
|
@ -1602,33 +1600,10 @@ static int GLES2_TexSubImage2D(GLES2_RenderData *data, GLenum target, GLint xoff
|
|||
src = blob;
|
||||
}
|
||||
|
||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||
if (format == GL_RGBA) {
|
||||
int i;
|
||||
Uint32 *src32 = (Uint32 *)src;
|
||||
blob2 = (Uint32 *)SDL_malloc(src_pitch * height);
|
||||
if (blob2 == NULL) {
|
||||
if (blob) {
|
||||
SDL_free(blob);
|
||||
}
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
for (i = 0; i < (src_pitch * height) / 4; i++) {
|
||||
blob2[i] = SDL_Swap32(src32[i]);
|
||||
}
|
||||
src = (Uint8 *)blob2;
|
||||
}
|
||||
#endif
|
||||
|
||||
data->glTexSubImage2D(target, 0, xoffset, yoffset, width, height, format, type, src);
|
||||
if (blob) {
|
||||
SDL_free(blob);
|
||||
}
|
||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||
if (blob2) {
|
||||
SDL_free(blob2);
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -1868,7 +1843,7 @@ static int GLES2_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
|
||||
data->drawstate.viewport_dirty = SDL_TRUE;
|
||||
|
||||
if (texture == NULL) {
|
||||
if (!texture) {
|
||||
data->glBindFramebuffer(GL_FRAMEBUFFER, data->window_framebuffer);
|
||||
} else {
|
||||
texturedata = (GLES2_TextureData *)texture->driverdata;
|
||||
|
|
@ -1919,7 +1894,7 @@ static int GLES2_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
|
|||
Uint32 pixel_format, void *pixels, int pitch)
|
||||
{
|
||||
GLES2_RenderData *data = (GLES2_RenderData *)renderer->driverdata;
|
||||
Uint32 temp_format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_ABGR8888;
|
||||
Uint32 temp_format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_RGBA32;
|
||||
size_t buflen;
|
||||
void *temp_pixels;
|
||||
int temp_pitch;
|
||||
|
|
@ -1934,7 +1909,7 @@ static int GLES2_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
|
|||
}
|
||||
|
||||
temp_pixels = SDL_malloc(buflen);
|
||||
if (temp_pixels == NULL) {
|
||||
if (!temp_pixels) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
|
|
@ -1989,7 +1964,7 @@ static int GLES2_SetVSync(SDL_Renderer *renderer, const int vsync)
|
|||
if (retval != 0) {
|
||||
return retval;
|
||||
}
|
||||
if (SDL_GL_GetSwapInterval() > 0) {
|
||||
if (SDL_GL_GetSwapInterval() != 0) {
|
||||
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
|
||||
} else {
|
||||
renderer->info.flags &= ~SDL_RENDERER_PRESENTVSYNC;
|
||||
|
|
@ -2055,10 +2030,9 @@ static int GLES2_UnbindTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
* Renderer instantiation *
|
||||
*************************************************************************************************/
|
||||
|
||||
static SDL_Renderer *GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
|
||||
static int GLES2_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, Uint32 flags)
|
||||
{
|
||||
SDL_Renderer *renderer;
|
||||
GLES2_RenderData *data;
|
||||
GLES2_RenderData *data = NULL;
|
||||
Uint32 window_flags = 0; /* -Wconditional-uninitialized */
|
||||
GLint window_framebuffer;
|
||||
GLint value;
|
||||
|
|
@ -2091,16 +2065,8 @@ static SDL_Renderer *GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
}
|
||||
}
|
||||
|
||||
/* Create the renderer struct */
|
||||
renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(SDL_Renderer));
|
||||
if (renderer == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
goto error;
|
||||
}
|
||||
|
||||
data = (GLES2_RenderData *)SDL_calloc(1, sizeof(GLES2_RenderData));
|
||||
if (data == NULL) {
|
||||
SDL_free(renderer);
|
||||
if (!data) {
|
||||
SDL_OutOfMemory();
|
||||
goto error;
|
||||
}
|
||||
|
|
@ -2112,32 +2078,24 @@ static SDL_Renderer *GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
/* Create an OpenGL ES 2.0 context */
|
||||
data->context = SDL_GL_CreateContext(window);
|
||||
if (!data->context) {
|
||||
SDL_free(renderer);
|
||||
SDL_free(data);
|
||||
goto error;
|
||||
}
|
||||
if (SDL_GL_MakeCurrent(window, data->context) < 0) {
|
||||
SDL_GL_DeleteContext(data->context);
|
||||
SDL_free(renderer);
|
||||
SDL_free(data);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (GLES2_LoadFunctions(data) < 0) {
|
||||
SDL_GL_DeleteContext(data->context);
|
||||
SDL_free(renderer);
|
||||
SDL_free(data);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (GLES2_CacheShaders(data) < 0) {
|
||||
SDL_GL_DeleteContext(data->context);
|
||||
SDL_free(renderer);
|
||||
SDL_free(data);
|
||||
goto error;
|
||||
}
|
||||
|
||||
#if __WINRT__
|
||||
#ifdef __WINRT__
|
||||
/* DLudwig, 2013-11-29: ANGLE for WinRT doesn't seem to work unless VSync
|
||||
* is turned on. Not doing so will freeze the screen's contents to that
|
||||
* of the first drawn frame.
|
||||
|
|
@ -2150,7 +2108,7 @@ static SDL_Renderer *GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
} else {
|
||||
SDL_GL_SetSwapInterval(0);
|
||||
}
|
||||
if (SDL_GL_GetSwapInterval() > 0) {
|
||||
if (SDL_GL_GetSwapInterval() != 0) {
|
||||
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
|
||||
}
|
||||
|
||||
|
|
@ -2244,9 +2202,10 @@ static SDL_Renderer *GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
|
||||
GL_CheckError("", renderer);
|
||||
|
||||
return renderer;
|
||||
return 0;
|
||||
|
||||
error:
|
||||
SDL_free(data);
|
||||
if (changed_window) {
|
||||
/* Uh oh, better try to put it back... */
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile_mask);
|
||||
|
|
@ -2254,7 +2213,7 @@ error:
|
|||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minor);
|
||||
SDL_RecreateWindow(window, window_flags);
|
||||
}
|
||||
return NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDL_RenderDriver GLES2_RenderDriver = {
|
||||
|
|
@ -2262,14 +2221,14 @@ SDL_RenderDriver GLES2_RenderDriver = {
|
|||
{ "opengles2",
|
||||
(SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE),
|
||||
4,
|
||||
{ SDL_PIXELFORMAT_ARGB8888,
|
||||
SDL_PIXELFORMAT_ABGR8888,
|
||||
SDL_PIXELFORMAT_RGB888,
|
||||
SDL_PIXELFORMAT_BGR888 },
|
||||
{ SDL_PIXELFORMAT_BGRA32,
|
||||
SDL_PIXELFORMAT_ABGR32,
|
||||
SDL_PIXELFORMAT_BGRX32,
|
||||
SDL_PIXELFORMAT_RGBX32 },
|
||||
0,
|
||||
0 }
|
||||
};
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_OGL_ES2 && !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_OGL_ES2 */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_OGL_ES2 && !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_OGL_ES2
|
||||
|
||||
#include "SDL_hints.h"
|
||||
#include "SDL_video.h"
|
||||
|
|
@ -380,7 +380,7 @@ const char *GLES2_GetShaderInclude(GLES2_ShaderIncludeType type)
|
|||
}
|
||||
}
|
||||
|
||||
GLES2_ShaderIncludeType GLES2_GetTexCoordPrecisionEnumFromHint()
|
||||
GLES2_ShaderIncludeType GLES2_GetTexCoordPrecisionEnumFromHint(void)
|
||||
{
|
||||
const char *texcoord_hint = SDL_GetHint("SDL_RENDER_OPENGLES2_TEXCOORD_PRECISION");
|
||||
GLES2_ShaderIncludeType value = GLES2_SHADER_FRAGMENT_INCLUDE_BEST_TEXCOORD_PRECISION;
|
||||
|
|
@ -444,6 +444,6 @@ const char *GLES2_GetShader(GLES2_ShaderType type)
|
|||
}
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_OGL_ES2 && !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_OGL_ES2 */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -47,6 +47,7 @@ typedef struct
|
|||
{
|
||||
GSGLOBAL *gsGlobal;
|
||||
uint64_t drawColor;
|
||||
SDL_Rect *viewport;
|
||||
int32_t vsync_callback_id;
|
||||
uint8_t vsync; /* 0 (Disabled), 1 (Enabled), 2 (Dynamic) */
|
||||
} PS2_RenderData;
|
||||
|
|
@ -54,7 +55,7 @@ typedef struct
|
|||
static int vsync_sema_id = 0;
|
||||
|
||||
/* PRIVATE METHODS */
|
||||
static int vsync_handler()
|
||||
static int vsync_handler(void)
|
||||
{
|
||||
iSignalSema(vsync_sema_id);
|
||||
|
||||
|
|
@ -105,7 +106,7 @@ static int PS2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
{
|
||||
GSTEXTURE *ps2_tex = (GSTEXTURE *)SDL_calloc(1, sizeof(GSTEXTURE));
|
||||
|
||||
if (ps2_tex == NULL) {
|
||||
if (!ps2_tex) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
|
|
@ -190,6 +191,19 @@ static int PS2_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
}
|
||||
|
||||
static int PS2_QueueSetViewport(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
|
||||
{
|
||||
PS2_RenderData *data = (PS2_RenderData *)renderer->driverdata;
|
||||
const SDL_Rect *viewport = &cmd->data.viewport.rect;
|
||||
data->viewport = (SDL_Rect *)viewport;
|
||||
|
||||
data->gsGlobal->OffsetX = (int)((2048.0f + (float)viewport->x) * 16.0f);
|
||||
data->gsGlobal->OffsetY = (int)((2048.0f + (float)viewport->y) * 16.0f);
|
||||
gsKit_set_scissor(data->gsGlobal, GS_SETREG_SCISSOR(viewport->x, viewport->x + viewport->w, viewport->y, viewport->y + viewport->h));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int PS2_QueueSetDrawColor(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
|
||||
{
|
||||
return 0; /* nothing to do in this backend. */
|
||||
}
|
||||
|
|
@ -202,16 +216,16 @@ static int PS2_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, c
|
|||
gs_rgbaq rgbaq;
|
||||
int i;
|
||||
|
||||
if (vertices == NULL) {
|
||||
if (!vertices) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
cmd->data.draw.count = count;
|
||||
|
||||
colorR = cmd->data.draw.r >> 1;
|
||||
colorG = cmd->data.draw.g >> 1;
|
||||
colorB = cmd->data.draw.b >> 1;
|
||||
colorA = cmd->data.draw.a >> 1;
|
||||
colorR = cmd->data.draw.r;
|
||||
colorG = cmd->data.draw.g;
|
||||
colorB = cmd->data.draw.b;
|
||||
colorA = cmd->data.draw.a;
|
||||
rgbaq = color_to_RGBAQ(colorR, colorG, colorB, colorA, 0.0f);
|
||||
|
||||
for (i = 0; i < count; i++, vertices++, points++) {
|
||||
|
|
@ -237,7 +251,7 @@ static int PS2_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL
|
|||
GSPRIMUVPOINT *vertices = (GSPRIMUVPOINT *) SDL_AllocateRenderVertices(renderer, count * sizeof(GSPRIMUVPOINT), 4, &cmd->data.draw.first);
|
||||
GSTEXTURE *ps2_tex = (GSTEXTURE *) texture->driverdata;
|
||||
|
||||
if (vertices == NULL) {
|
||||
if (!vertices) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -261,7 +275,7 @@ static int PS2_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL
|
|||
uv_ = (float *)((char *)uv + j * uv_stride);
|
||||
|
||||
vertices->xyz2 = vertex_to_XYZ2(data->gsGlobal, xy_[0] * scale_x, xy_[1] * scale_y, 0);
|
||||
vertices->rgbaq = color_to_RGBAQ(col_.r >> 1, col_.g >> 1, col_.b >> 1, col_.a >> 1, 0);
|
||||
vertices->rgbaq = color_to_RGBAQ(col_.r, col_.g, col_.b, col_.a, 0);
|
||||
vertices->uv = vertex_to_UV(ps2_tex, uv_[0] * ps2_tex->Width, uv_[1] * ps2_tex->Height);
|
||||
|
||||
vertices++;
|
||||
|
|
@ -270,7 +284,7 @@ static int PS2_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL
|
|||
} else {
|
||||
GSPRIMPOINT *vertices = (GSPRIMPOINT *)SDL_AllocateRenderVertices(renderer, count * sizeof(GSPRIMPOINT), 4, &cmd->data.draw.first);
|
||||
|
||||
if (vertices == NULL) {
|
||||
if (!vertices) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -292,7 +306,7 @@ static int PS2_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL
|
|||
col_ = *(SDL_Color *)((char *)color + j * color_stride);
|
||||
|
||||
vertices->xyz2 = vertex_to_XYZ2(data->gsGlobal, xy_[0] * scale_x, xy_[1] * scale_y, 0);
|
||||
vertices->rgbaq = color_to_RGBAQ(col_.r >> 1, col_.g >> 1, col_.b >> 1, col_.a >> 1, 0.0f);
|
||||
vertices->rgbaq = color_to_RGBAQ(col_.r, col_.g, col_.b, col_.a, 0.0f);
|
||||
|
||||
vertices++;
|
||||
}
|
||||
|
|
@ -303,26 +317,24 @@ static int PS2_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL
|
|||
|
||||
static int PS2_RenderSetViewPort(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
|
||||
{
|
||||
PS2_RenderData *data = (PS2_RenderData *)renderer->driverdata;
|
||||
const SDL_Rect *viewport = &cmd->data.viewport.rect;
|
||||
|
||||
gsKit_set_display_offset(data->gsGlobal, viewport->x, viewport->y);
|
||||
gsKit_set_scissor(data->gsGlobal, GS_SETREG_SCISSOR(viewport->x, viewport->y, viewport->w, viewport->h));
|
||||
|
||||
return 0;
|
||||
return 0; /* nothing to do in this backend. */
|
||||
}
|
||||
|
||||
static int PS2_RenderSetClipRect(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
|
||||
{
|
||||
PS2_RenderData *data = (PS2_RenderData *)renderer->driverdata;
|
||||
SDL_Rect *viewport = data->viewport;
|
||||
|
||||
const SDL_Rect *rect = &cmd->data.cliprect.rect;
|
||||
|
||||
if (cmd->data.cliprect.enabled) {
|
||||
gsKit_set_scissor(data->gsGlobal, GS_SETREG_SCISSOR(rect->x, rect->y, rect->w, rect->h));
|
||||
} else {
|
||||
gsKit_set_scissor(data->gsGlobal, GS_SCISSOR_RESET);
|
||||
/* We need to do it relative to saved viewport */
|
||||
viewport->x += rect->x;
|
||||
viewport->y += rect->y;
|
||||
viewport->w = SDL_min(viewport->w, rect->w);
|
||||
viewport->h = SDL_min(viewport->h, rect->h);
|
||||
}
|
||||
gsKit_set_scissor(data->gsGlobal, GS_SETREG_SCISSOR(viewport->x, viewport->x + viewport->w, viewport->y, viewport->y + viewport->h));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -333,26 +345,43 @@ static int PS2_RenderSetDrawColor(SDL_Renderer *renderer, SDL_RenderCommand *cmd
|
|||
|
||||
PS2_RenderData *data = (PS2_RenderData *)renderer->driverdata;
|
||||
|
||||
colorR = (cmd->data.color.r) >> 1;
|
||||
colorG = (cmd->data.color.g) >> 1;
|
||||
colorB = (cmd->data.color.b) >> 1;
|
||||
colorA = (cmd->data.color.a) >> 1;
|
||||
colorR = (cmd->data.color.r);
|
||||
colorG = (cmd->data.color.g);
|
||||
colorB = (cmd->data.color.b);
|
||||
colorA = (cmd->data.color.a);
|
||||
data->drawColor = GS_SETREG_RGBAQ(colorR, colorG, colorB, colorA, 0x00);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int PS2_RenderClear(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
|
||||
{
|
||||
int colorR, colorG, colorB, colorA;
|
||||
int colorR, colorG, colorB, colorA, offsetX, offsetY;
|
||||
SDL_Rect *viewport;
|
||||
|
||||
PS2_RenderData *data = (PS2_RenderData *)renderer->driverdata;
|
||||
|
||||
colorR = (cmd->data.color.r) >> 1;
|
||||
colorG = (cmd->data.color.g) >> 1;
|
||||
colorB = (cmd->data.color.b) >> 1;
|
||||
colorA = (cmd->data.color.a) >> 1;
|
||||
colorR = (cmd->data.color.r);
|
||||
colorG = (cmd->data.color.g);
|
||||
colorB = (cmd->data.color.b);
|
||||
colorA = (cmd->data.color.a);
|
||||
|
||||
/* Clear the screen, so let's put default viewport */
|
||||
gsKit_set_scissor(data->gsGlobal, GS_SCISSOR_RESET);
|
||||
/* Put back original offset */
|
||||
offsetX = data->gsGlobal->OffsetX;
|
||||
offsetY = data->gsGlobal->OffsetY;
|
||||
data->gsGlobal->OffsetX = (int)(2048.0f * 16.0f);
|
||||
data->gsGlobal->OffsetY = (int)(2048.0f * 16.0f);
|
||||
gsKit_clear(data->gsGlobal, GS_SETREG_RGBAQ(colorR, colorG, colorB, colorA, 0x00));
|
||||
|
||||
/* Put back original offset */
|
||||
data->gsGlobal->OffsetX = offsetX;
|
||||
data->gsGlobal->OffsetY = offsetY;
|
||||
|
||||
// /* Put back view port */
|
||||
viewport = data->viewport;
|
||||
gsKit_set_scissor(data->gsGlobal, GS_SETREG_SCISSOR(viewport->x, viewport->x + viewport->w, viewport->y, viewport->y + viewport->h));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -448,6 +477,7 @@ static int PS2_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, v
|
|||
case SDL_RENDERCMD_SETVIEWPORT:
|
||||
{
|
||||
PS2_RenderSetViewPort(renderer, cmd);
|
||||
/* FIXME: We need to update the clip rect too, see https://github.com/libsdl-org/SDL/issues/9094 */
|
||||
break;
|
||||
}
|
||||
case SDL_RENDERCMD_SETCLIPRECT:
|
||||
|
|
@ -531,11 +561,11 @@ static void PS2_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
GSTEXTURE *ps2_texture = (GSTEXTURE *)texture->driverdata;
|
||||
PS2_RenderData *data = (PS2_RenderData *)renderer->driverdata;
|
||||
|
||||
if (data == NULL) {
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ps2_texture == NULL) {
|
||||
if (!ps2_texture) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -563,8 +593,6 @@ static void PS2_DestroyRenderer(SDL_Renderer *renderer)
|
|||
if (vsync_sema_id >= 0) {
|
||||
DeleteSema(vsync_sema_id);
|
||||
}
|
||||
|
||||
SDL_free(renderer);
|
||||
}
|
||||
|
||||
static int PS2_SetVSync(SDL_Renderer *renderer, const int vsync)
|
||||
|
|
@ -575,25 +603,17 @@ static int PS2_SetVSync(SDL_Renderer *renderer, const int vsync)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static SDL_Renderer *PS2_CreateRenderer(SDL_Window *window, Uint32 flags)
|
||||
static int PS2_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, Uint32 flags)
|
||||
{
|
||||
SDL_Renderer *renderer;
|
||||
PS2_RenderData *data;
|
||||
GSGLOBAL *gsGlobal;
|
||||
ee_sema_t sema;
|
||||
SDL_bool dynamicVsync;
|
||||
|
||||
renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(*renderer));
|
||||
if (renderer == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
data = (PS2_RenderData *)SDL_calloc(1, sizeof(*data));
|
||||
if (data == NULL) {
|
||||
if (!data) {
|
||||
PS2_DestroyRenderer(renderer);
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
/* Specific gsKit init */
|
||||
|
|
@ -645,7 +665,7 @@ static SDL_Renderer *PS2_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
renderer->SetTextureScaleMode = PS2_SetTextureScaleMode;
|
||||
renderer->SetRenderTarget = PS2_SetRenderTarget;
|
||||
renderer->QueueSetViewport = PS2_QueueSetViewport;
|
||||
renderer->QueueSetDrawColor = PS2_QueueSetViewport;
|
||||
renderer->QueueSetDrawColor = PS2_QueueSetDrawColor;
|
||||
renderer->QueueDrawPoints = PS2_QueueDrawPoints;
|
||||
renderer->QueueDrawLines = PS2_QueueDrawPoints;
|
||||
renderer->QueueGeometry = PS2_QueueGeometry;
|
||||
|
|
@ -659,7 +679,7 @@ static SDL_Renderer *PS2_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
renderer->driverdata = data;
|
||||
renderer->window = window;
|
||||
|
||||
return renderer;
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_RenderDriver PS2_RenderDriver = {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -36,15 +36,9 @@
|
|||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <vram.h>
|
||||
#include "SDL_render_psp.h"
|
||||
|
||||
/* PSP renderer implementation, based on the PGE */
|
||||
|
||||
#define PSP_SCREEN_WIDTH 480
|
||||
#define PSP_SCREEN_HEIGHT 272
|
||||
|
||||
#define PSP_FRAME_BUFFER_WIDTH 512
|
||||
#define PSP_FRAME_BUFFER_SIZE (PSP_FRAME_BUFFER_WIDTH * PSP_SCREEN_HEIGHT)
|
||||
|
||||
static unsigned int __attribute__((aligned(16))) DisplayList[262144];
|
||||
|
||||
#define COL5650(r, g, b, a) ((r >> 3) | ((g >> 2) << 5) | ((b >> 3) << 11))
|
||||
|
|
@ -124,6 +118,24 @@ typedef struct
|
|||
float x, y, z;
|
||||
} VertTCV;
|
||||
|
||||
int SDL_PSP_RenderGetProp(SDL_Renderer *r, enum SDL_PSP_RenderProps which, void** out)
|
||||
{
|
||||
PSP_RenderData *rd;
|
||||
if (r == NULL) {
|
||||
return -1;
|
||||
}
|
||||
rd = r->driverdata;
|
||||
switch (which) {
|
||||
case SDL_PSP_RENDERPROPS_FRONTBUFFER:
|
||||
*out = rd->frontbuffer;
|
||||
return 0;
|
||||
case SDL_PSP_RENDERPROPS_BACKBUFFER:
|
||||
*out = rd->backbuffer;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
#define PI 3.14159265358979f
|
||||
|
||||
#define radToDeg(x) ((x)*180.f / PI)
|
||||
|
|
@ -282,11 +294,11 @@ static int TextureSwizzle(PSP_TextureData *psp_texture, void *dst)
|
|||
src = (unsigned int *)psp_texture->data;
|
||||
|
||||
data = dst;
|
||||
if (data == NULL) {
|
||||
if (!data) {
|
||||
data = SDL_malloc(psp_texture->size);
|
||||
}
|
||||
|
||||
if (data == NULL) {
|
||||
if (!data) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
|
|
@ -344,11 +356,11 @@ static int TextureUnswizzle(PSP_TextureData *psp_texture, void *dst)
|
|||
|
||||
data = dst;
|
||||
|
||||
if (data == NULL) {
|
||||
if (!data) {
|
||||
data = SDL_malloc(psp_texture->size);
|
||||
}
|
||||
|
||||
if (data == NULL) {
|
||||
if (!data) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
|
|
@ -392,7 +404,7 @@ static int TextureSpillToSram(PSP_RenderData *data, PSP_TextureData *psp_texture
|
|||
if (psp_texture->swizzled) {
|
||||
// Texture was swizzled in vram, just copy to system memory
|
||||
void *sdata = SDL_malloc(psp_texture->size);
|
||||
if (sdata == NULL) {
|
||||
if (!sdata) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
|
|
@ -484,7 +496,7 @@ static int PSP_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
PSP_RenderData *data = renderer->driverdata;
|
||||
PSP_TextureData *psp_texture = (PSP_TextureData *)SDL_calloc(1, sizeof(*psp_texture));
|
||||
|
||||
if (psp_texture == NULL) {
|
||||
if (!psp_texture) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
|
|
@ -630,7 +642,7 @@ static int PSP_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, c
|
|||
VertV *verts = (VertV *)SDL_AllocateRenderVertices(renderer, count * sizeof(VertV), 4, &cmd->data.draw.first);
|
||||
int i;
|
||||
|
||||
if (verts == NULL) {
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -656,10 +668,10 @@ static int PSP_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL
|
|||
cmd->data.draw.count = count;
|
||||
size_indices = indices ? size_indices : 0;
|
||||
|
||||
if (texture == NULL) {
|
||||
if (!texture) {
|
||||
VertCV *verts;
|
||||
verts = (VertCV *)SDL_AllocateRenderVertices(renderer, count * sizeof(VertCV), 4, &cmd->data.draw.first);
|
||||
if (verts == NULL) {
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -692,7 +704,7 @@ static int PSP_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL
|
|||
PSP_TextureData *psp_texture = (PSP_TextureData *)texture->driverdata;
|
||||
VertTCV *verts;
|
||||
verts = (VertTCV *)SDL_AllocateRenderVertices(renderer, count * sizeof(VertTCV), 4, &cmd->data.draw.first);
|
||||
if (verts == NULL) {
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -737,7 +749,7 @@ static int PSP_QueueFillRects(SDL_Renderer *renderer, SDL_RenderCommand *cmd, co
|
|||
VertV *verts = (VertV *)SDL_AllocateRenderVertices(renderer, count * 2 * sizeof(VertV), 4, &cmd->data.draw.first);
|
||||
int i;
|
||||
|
||||
if (verts == NULL) {
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -773,7 +785,7 @@ static int PSP_QueueCopy(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Tex
|
|||
|
||||
if ((MathAbs(u1) - MathAbs(u0)) < 64.0f) {
|
||||
verts = (VertTV *)SDL_AllocateRenderVertices(renderer, 2 * sizeof(VertTV), 4, &cmd->data.draw.first);
|
||||
if (verts == NULL) {
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -809,7 +821,7 @@ static int PSP_QueueCopy(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Tex
|
|||
cmd->data.draw.count = count;
|
||||
|
||||
verts = (VertTV *)SDL_AllocateRenderVertices(renderer, count * 2 * sizeof(VertTV), 4, &cmd->data.draw.first);
|
||||
if (verts == NULL) {
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -860,7 +872,7 @@ static int PSP_QueueCopyEx(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_T
|
|||
float u1 = srcrect->x + srcrect->w;
|
||||
float v1 = srcrect->y + srcrect->h;
|
||||
|
||||
if (verts == NULL) {
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -1011,7 +1023,7 @@ static void PSP_SetBlendState(PSP_RenderData *data, PSP_BlendState *state)
|
|||
}
|
||||
|
||||
if (state->texture != current->texture) {
|
||||
if (state->texture != NULL) {
|
||||
if (state->texture) {
|
||||
TextureActivate(state->texture);
|
||||
sceGuEnable(GU_TEXTURE_2D);
|
||||
} else {
|
||||
|
|
@ -1035,7 +1047,7 @@ static int PSP_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, v
|
|||
rendering backends report a reasonable maximum, so the higher level can flush
|
||||
if we appear to be exceeding that. */
|
||||
gpumem = (Uint8 *)sceGuGetMemory(vertsize);
|
||||
if (gpumem == NULL) {
|
||||
if (!gpumem) {
|
||||
return SDL_SetError("Couldn't obtain a %d-byte vertex buffer!", (int)vertsize);
|
||||
}
|
||||
SDL_memcpy(gpumem, vertices, vertsize);
|
||||
|
|
@ -1053,6 +1065,7 @@ static int PSP_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, v
|
|||
sceGuOffset(2048 - (viewport->w >> 1), 2048 - (viewport->h >> 1));
|
||||
sceGuViewport(2048, 2048, viewport->w, viewport->h);
|
||||
sceGuScissor(viewport->x, viewport->y, viewport->w, viewport->h);
|
||||
/* FIXME: We need to update the clip rect too, see https://github.com/libsdl-org/SDL/issues/9094 */
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -1177,7 +1190,7 @@ static int PSP_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, v
|
|||
case SDL_RENDERCMD_GEOMETRY:
|
||||
{
|
||||
const size_t count = cmd->data.draw.count;
|
||||
if (cmd->data.draw.texture == NULL) {
|
||||
if (!cmd->data.draw.texture) {
|
||||
const VertCV *verts = (VertCV *)(gpumem + cmd->data.draw.first);
|
||||
sceGuDisable(GU_TEXTURE_2D);
|
||||
/* In GU_SMOOTH mode */
|
||||
|
|
@ -1245,11 +1258,11 @@ static void PSP_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
PSP_RenderData *renderdata = (PSP_RenderData *)renderer->driverdata;
|
||||
PSP_TextureData *psp_texture = (PSP_TextureData *)texture->driverdata;
|
||||
|
||||
if (renderdata == NULL) {
|
||||
if (!renderdata) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (psp_texture == NULL) {
|
||||
if (!psp_texture) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1267,8 +1280,6 @@ static void PSP_DestroyRenderer(SDL_Renderer *renderer)
|
|||
return;
|
||||
}
|
||||
|
||||
StartDrawing(renderer);
|
||||
|
||||
sceKernelDisableSubIntr(PSP_VBLANK_INT, 0);
|
||||
sceKernelReleaseSubIntrHandler(PSP_VBLANK_INT, 0);
|
||||
sceDisplayWaitVblankStart();
|
||||
|
|
@ -1281,7 +1292,6 @@ static void PSP_DestroyRenderer(SDL_Renderer *renderer)
|
|||
data->displayListAvail = SDL_FALSE;
|
||||
SDL_free(data);
|
||||
}
|
||||
SDL_free(renderer);
|
||||
}
|
||||
|
||||
static int PSP_SetVSync(SDL_Renderer *renderer, const int vsync)
|
||||
|
|
@ -1291,25 +1301,16 @@ static int PSP_SetVSync(SDL_Renderer *renderer, const int vsync)
|
|||
return 0;
|
||||
}
|
||||
|
||||
SDL_Renderer *PSP_CreateRenderer(SDL_Window *window, Uint32 flags)
|
||||
int PSP_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, Uint32 flags)
|
||||
{
|
||||
|
||||
SDL_Renderer *renderer;
|
||||
PSP_RenderData *data;
|
||||
int pixelformat;
|
||||
void *doublebuffer = NULL;
|
||||
|
||||
renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(*renderer));
|
||||
if (renderer == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
data = (PSP_RenderData *)SDL_calloc(1, sizeof(*data));
|
||||
if (data == NULL) {
|
||||
if (!data) {
|
||||
PSP_DestroyRenderer(renderer);
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
renderer->WindowEvent = PSP_WindowEvent;
|
||||
|
|
@ -1401,7 +1402,7 @@ SDL_Renderer *PSP_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
sceKernelRegisterSubIntrHandler(PSP_VBLANK_INT, 0, psp_on_vblank, data);
|
||||
sceKernelEnableSubIntr(PSP_VBLANK_INT, 0);
|
||||
|
||||
return renderer;
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_RenderDriver PSP_RenderDriver = {
|
||||
|
|
|
|||
38
Engine/lib/sdl/src/render/psp/SDL_render_psp.h
Normal file
38
Engine/lib/sdl/src/render/psp/SDL_render_psp.h
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
/* this header is meant to be included after the other related internal SDL
|
||||
headers. it's the interface between psp renderer and video driver code. */
|
||||
|
||||
#define PSP_SCREEN_WIDTH 480
|
||||
#define PSP_SCREEN_HEIGHT 272
|
||||
|
||||
#define PSP_FRAME_BUFFER_WIDTH 512
|
||||
#define PSP_FRAME_BUFFER_SIZE (PSP_FRAME_BUFFER_WIDTH * PSP_SCREEN_HEIGHT)
|
||||
|
||||
enum SDL_PSP_RenderProps
|
||||
{
|
||||
SDL_PSP_RENDERPROPS_FRONTBUFFER,
|
||||
SDL_PSP_RENDERPROPS_BACKBUFFER,
|
||||
};
|
||||
|
||||
int SDL_PSP_RenderGetProp(SDL_Renderer *r, enum SDL_PSP_RenderProps which, void** out);
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_SW
|
||||
|
||||
#include "SDL_draw.h"
|
||||
#include "SDL_blendfillrect.h"
|
||||
|
|
@ -211,7 +211,7 @@ int SDL_BlendFillRect(SDL_Surface *dst, const SDL_Rect *rect,
|
|||
{
|
||||
SDL_Rect clipped;
|
||||
|
||||
if (dst == NULL) {
|
||||
if (!dst) {
|
||||
return SDL_InvalidParamError("SDL_BlendFillRect(): dst");
|
||||
}
|
||||
|
||||
|
|
@ -281,7 +281,7 @@ int SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count,
|
|||
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
|
||||
int status = 0;
|
||||
|
||||
if (dst == NULL) {
|
||||
if (!dst) {
|
||||
return SDL_InvalidParamError("SDL_BlendFillRects(): dst");
|
||||
}
|
||||
|
||||
|
|
@ -325,7 +325,7 @@ int SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count,
|
|||
break;
|
||||
}
|
||||
|
||||
if (func == NULL) {
|
||||
if (!func) {
|
||||
if (!dst->format->Amask) {
|
||||
func = SDL_BlendFillRect_RGB;
|
||||
} else {
|
||||
|
|
@ -343,6 +343,6 @@ int SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count,
|
|||
return status;
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_SW */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_SW
|
||||
|
||||
#include "SDL_draw.h"
|
||||
#include "SDL_blendline.h"
|
||||
|
|
@ -798,12 +798,12 @@ int SDL_BlendLine(SDL_Surface *dst, int x1, int y1, int x2, int y2,
|
|||
{
|
||||
BlendLineFunc func;
|
||||
|
||||
if (dst == NULL) {
|
||||
if (!dst) {
|
||||
return SDL_InvalidParamError("SDL_BlendLine(): dst");
|
||||
}
|
||||
|
||||
func = SDL_CalculateBlendLineFunc(dst->format);
|
||||
if (func == NULL) {
|
||||
if (!func) {
|
||||
return SDL_SetError("SDL_BlendLine(): Unsupported surface format");
|
||||
}
|
||||
|
||||
|
|
@ -826,12 +826,12 @@ int SDL_BlendLines(SDL_Surface *dst, const SDL_Point *points, int count,
|
|||
SDL_bool draw_end;
|
||||
BlendLineFunc func;
|
||||
|
||||
if (dst == NULL) {
|
||||
if (!dst) {
|
||||
return SDL_SetError("SDL_BlendLines(): Passed NULL destination surface");
|
||||
}
|
||||
|
||||
func = SDL_CalculateBlendLineFunc(dst->format);
|
||||
if (func == NULL) {
|
||||
if (!func) {
|
||||
return SDL_SetError("SDL_BlendLines(): Unsupported surface format");
|
||||
}
|
||||
|
||||
|
|
@ -859,6 +859,6 @@ int SDL_BlendLines(SDL_Surface *dst, const SDL_Point *points, int count,
|
|||
return 0;
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_SW */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_SW
|
||||
|
||||
#include "SDL_draw.h"
|
||||
#include "SDL_blendpoint.h"
|
||||
|
|
@ -209,7 +209,7 @@ static int SDL_BlendPoint_RGBA(SDL_Surface *dst, int x, int y, SDL_BlendMode ble
|
|||
int SDL_BlendPoint(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
|
||||
Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
if (dst == NULL) {
|
||||
if (!dst) {
|
||||
return SDL_InvalidParamError("SDL_BlendPoint(): dst");
|
||||
}
|
||||
|
||||
|
|
@ -277,7 +277,7 @@ int SDL_BlendPoints(SDL_Surface *dst, const SDL_Point *points, int count,
|
|||
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
|
||||
int status = 0;
|
||||
|
||||
if (dst == NULL) {
|
||||
if (!dst) {
|
||||
return SDL_InvalidParamError("SDL_BlendPoints(): dst");
|
||||
}
|
||||
|
||||
|
|
@ -323,7 +323,7 @@ int SDL_BlendPoints(SDL_Surface *dst, const SDL_Point *points, int count,
|
|||
break;
|
||||
}
|
||||
|
||||
if (func == NULL) {
|
||||
if (!func) {
|
||||
if (!dst->format->Amask) {
|
||||
func = SDL_BlendPoint_RGB;
|
||||
} else {
|
||||
|
|
@ -348,6 +348,6 @@ int SDL_BlendPoints(SDL_Surface *dst, const SDL_Point *points, int count,
|
|||
return status;
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_SW */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_SW
|
||||
|
||||
#include "SDL_draw.h"
|
||||
#include "SDL_drawline.h"
|
||||
|
|
@ -137,12 +137,12 @@ int SDL_DrawLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color)
|
|||
{
|
||||
DrawLineFunc func;
|
||||
|
||||
if (dst == NULL) {
|
||||
if (!dst) {
|
||||
return SDL_InvalidParamError("SDL_DrawLine(): dst");
|
||||
}
|
||||
|
||||
func = SDL_CalculateDrawLineFunc(dst->format);
|
||||
if (func == NULL) {
|
||||
if (!func) {
|
||||
return SDL_SetError("SDL_DrawLine(): Unsupported surface format");
|
||||
}
|
||||
|
||||
|
|
@ -165,12 +165,12 @@ int SDL_DrawLines(SDL_Surface *dst, const SDL_Point *points, int count,
|
|||
SDL_bool draw_end;
|
||||
DrawLineFunc func;
|
||||
|
||||
if (dst == NULL) {
|
||||
if (!dst) {
|
||||
return SDL_InvalidParamError("SDL_DrawLines(): dst");
|
||||
}
|
||||
|
||||
func = SDL_CalculateDrawLineFunc(dst->format);
|
||||
if (func == NULL) {
|
||||
if (!func) {
|
||||
return SDL_SetError("SDL_DrawLines(): Unsupported surface format");
|
||||
}
|
||||
|
||||
|
|
@ -197,6 +197,6 @@ int SDL_DrawLines(SDL_Surface *dst, const SDL_Point *points, int count,
|
|||
return 0;
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_SW */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -20,14 +20,14 @@
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_SW
|
||||
|
||||
#include "SDL_draw.h"
|
||||
#include "SDL_drawpoint.h"
|
||||
|
||||
int SDL_DrawPoint(SDL_Surface *dst, int x, int y, Uint32 color)
|
||||
{
|
||||
if (dst == NULL) {
|
||||
if (!dst) {
|
||||
return SDL_InvalidParamError("SDL_DrawPoint(): dst");
|
||||
}
|
||||
|
||||
|
|
@ -67,7 +67,7 @@ int SDL_DrawPoints(SDL_Surface *dst, const SDL_Point *points, int count,
|
|||
int i;
|
||||
int x, y;
|
||||
|
||||
if (dst == NULL) {
|
||||
if (!dst) {
|
||||
return SDL_InvalidParamError("SDL_DrawPoints(): dst");
|
||||
}
|
||||
|
||||
|
|
@ -106,6 +106,6 @@ int SDL_DrawPoints(SDL_Surface *dst, const SDL_Point *points, int count,
|
|||
return 0;
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_SW */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_SW
|
||||
|
||||
#include "../SDL_sysrender.h"
|
||||
#include "SDL_render_sw_c.h"
|
||||
|
|
@ -196,7 +196,7 @@ static int SW_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, co
|
|||
SDL_Point *verts = (SDL_Point *)SDL_AllocateRenderVertices(renderer, count * sizeof(SDL_Point), 0, &cmd->data.draw.first);
|
||||
int i;
|
||||
|
||||
if (verts == NULL) {
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -215,7 +215,7 @@ static int SW_QueueFillRects(SDL_Renderer *renderer, SDL_RenderCommand *cmd, con
|
|||
SDL_Rect *verts = (SDL_Rect *)SDL_AllocateRenderVertices(renderer, count * sizeof(SDL_Rect), 0, &cmd->data.draw.first);
|
||||
int i;
|
||||
|
||||
if (verts == NULL) {
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -236,7 +236,7 @@ static int SW_QueueCopy(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Text
|
|||
{
|
||||
SDL_Rect *verts = (SDL_Rect *)SDL_AllocateRenderVertices(renderer, 2 * sizeof(SDL_Rect), 0, &cmd->data.draw.first);
|
||||
|
||||
if (verts == NULL) {
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -270,7 +270,7 @@ static int SW_QueueCopyEx(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Te
|
|||
{
|
||||
CopyExData *verts = (CopyExData *)SDL_AllocateRenderVertices(renderer, sizeof(CopyExData), 0, &cmd->data.draw.first);
|
||||
|
||||
if (verts == NULL) {
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -324,7 +324,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
|
|||
int blitRequired = SDL_FALSE;
|
||||
int isOpaque = SDL_FALSE;
|
||||
|
||||
if (surface == NULL) {
|
||||
if (!surface) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -346,7 +346,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
|
|||
src_clone = SDL_CreateRGBSurfaceFrom(src->pixels, src->w, src->h, src->format->BitsPerPixel, src->pitch,
|
||||
src->format->Rmask, src->format->Gmask,
|
||||
src->format->Bmask, src->format->Amask);
|
||||
if (src_clone == NULL) {
|
||||
if (!src_clone) {
|
||||
if (SDL_MUSTLOCK(src)) {
|
||||
SDL_UnlockSurface(src);
|
||||
}
|
||||
|
|
@ -390,7 +390,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
|
|||
if (blendmode == SDL_BLENDMODE_NONE && !isOpaque) {
|
||||
mask = SDL_CreateRGBSurface(0, final_rect->w, final_rect->h, 32,
|
||||
0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
|
||||
if (mask == NULL) {
|
||||
if (!mask) {
|
||||
retval = -1;
|
||||
} else {
|
||||
SDL_SetSurfaceBlendMode(mask, SDL_BLENDMODE_MOD);
|
||||
|
|
@ -404,7 +404,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
|
|||
SDL_Rect scale_rect = tmp_rect;
|
||||
src_scaled = SDL_CreateRGBSurface(0, final_rect->w, final_rect->h, 32,
|
||||
0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
|
||||
if (src_scaled == NULL) {
|
||||
if (!src_scaled) {
|
||||
retval = -1;
|
||||
} else {
|
||||
SDL_SetSurfaceBlendMode(src_clone, SDL_BLENDMODE_NONE);
|
||||
|
|
@ -427,15 +427,15 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
|
|||
src_rotated = SDLgfx_rotateSurface(src_clone, angle,
|
||||
(texture->scaleMode == SDL_ScaleModeNearest) ? 0 : 1, flip & SDL_FLIP_HORIZONTAL, flip & SDL_FLIP_VERTICAL,
|
||||
&rect_dest, cangle, sangle, center);
|
||||
if (src_rotated == NULL) {
|
||||
if (!src_rotated) {
|
||||
retval = -1;
|
||||
}
|
||||
if (!retval && mask != NULL) {
|
||||
if (!retval && mask) {
|
||||
/* The mask needed for the NONE blend mode gets rotated with the same parameters. */
|
||||
mask_rotated = SDLgfx_rotateSurface(mask, angle,
|
||||
SDL_FALSE, 0, 0,
|
||||
&rect_dest, cangle, sangle, center);
|
||||
if (mask_rotated == NULL) {
|
||||
if (!mask_rotated) {
|
||||
retval = -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -487,7 +487,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
|
|||
src_rotated->format->BitsPerPixel, src_rotated->pitch,
|
||||
src_rotated->format->Rmask, src_rotated->format->Gmask,
|
||||
src_rotated->format->Bmask, 0);
|
||||
if (src_rotated_rgb == NULL) {
|
||||
if (!src_rotated_rgb) {
|
||||
retval = -1;
|
||||
} else {
|
||||
SDL_SetSurfaceBlendMode(src_rotated_rgb, SDL_BLENDMODE_ADD);
|
||||
|
|
@ -499,7 +499,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
|
|||
}
|
||||
SDL_FreeSurface(mask_rotated);
|
||||
}
|
||||
if (src_rotated != NULL) {
|
||||
if (src_rotated) {
|
||||
SDL_FreeSurface(src_rotated);
|
||||
}
|
||||
}
|
||||
|
|
@ -508,10 +508,10 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
|
|||
if (SDL_MUSTLOCK(src)) {
|
||||
SDL_UnlockSurface(src);
|
||||
}
|
||||
if (mask != NULL) {
|
||||
if (mask) {
|
||||
SDL_FreeSurface(mask);
|
||||
}
|
||||
if (src_clone != NULL) {
|
||||
if (src_clone) {
|
||||
SDL_FreeSurface(src_clone);
|
||||
}
|
||||
return retval;
|
||||
|
|
@ -538,10 +538,10 @@ static int SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_
|
|||
int i;
|
||||
int count = indices ? num_indices : num_vertices;
|
||||
void *verts;
|
||||
size_t sz = texture != NULL ? sizeof(GeometryCopyData) : sizeof(GeometryFillData);
|
||||
size_t sz = texture ? sizeof(GeometryCopyData) : sizeof(GeometryFillData);
|
||||
|
||||
verts = SDL_AllocateRenderVertices(renderer, count * sz, 0, &cmd->data.draw.first);
|
||||
if (verts == NULL) {
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -643,7 +643,7 @@ static void SetDrawState(SDL_Surface *surface, SW_DrawStateCache *drawstate)
|
|||
const SDL_Rect *cliprect = drawstate->cliprect;
|
||||
SDL_assert_release(viewport != NULL); /* the higher level should have forced a SDL_RENDERCMD_SETVIEWPORT */
|
||||
|
||||
if (cliprect != NULL) {
|
||||
if (cliprect) {
|
||||
SDL_Rect clip_rect;
|
||||
clip_rect.x = cliprect->x + viewport->x;
|
||||
clip_rect.y = cliprect->y + viewport->y;
|
||||
|
|
@ -663,7 +663,7 @@ static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo
|
|||
SDL_Surface *surface = SW_ActivateRenderer(renderer);
|
||||
SW_DrawStateCache drawstate;
|
||||
|
||||
if (surface == NULL) {
|
||||
if (!surface) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -712,7 +712,7 @@ static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo
|
|||
SetDrawState(surface, &drawstate);
|
||||
|
||||
/* Apply viewport */
|
||||
if (drawstate.viewport != NULL && (drawstate.viewport->x || drawstate.viewport->y)) {
|
||||
if (drawstate.viewport && (drawstate.viewport->x || drawstate.viewport->y)) {
|
||||
int i;
|
||||
for (i = 0; i < count; i++) {
|
||||
verts[i].x += drawstate.viewport->x;
|
||||
|
|
@ -739,7 +739,7 @@ static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo
|
|||
SetDrawState(surface, &drawstate);
|
||||
|
||||
/* Apply viewport */
|
||||
if (drawstate.viewport != NULL && (drawstate.viewport->x || drawstate.viewport->y)) {
|
||||
if (drawstate.viewport && (drawstate.viewport->x || drawstate.viewport->y)) {
|
||||
int i;
|
||||
for (i = 0; i < count; i++) {
|
||||
verts[i].x += drawstate.viewport->x;
|
||||
|
|
@ -766,7 +766,7 @@ static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo
|
|||
SetDrawState(surface, &drawstate);
|
||||
|
||||
/* Apply viewport */
|
||||
if (drawstate.viewport != NULL && (drawstate.viewport->x || drawstate.viewport->y)) {
|
||||
if (drawstate.viewport && (drawstate.viewport->x || drawstate.viewport->y)) {
|
||||
int i;
|
||||
for (i = 0; i < count; i++) {
|
||||
verts[i].x += drawstate.viewport->x;
|
||||
|
|
@ -794,7 +794,7 @@ static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo
|
|||
PrepTextureForCopy(cmd);
|
||||
|
||||
/* Apply viewport */
|
||||
if (drawstate.viewport != NULL && (drawstate.viewport->x || drawstate.viewport->y)) {
|
||||
if (drawstate.viewport && (drawstate.viewport->x || drawstate.viewport->y)) {
|
||||
dstrect->x += drawstate.viewport->x;
|
||||
dstrect->y += drawstate.viewport->y;
|
||||
}
|
||||
|
|
@ -852,7 +852,7 @@ static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo
|
|||
PrepTextureForCopy(cmd);
|
||||
|
||||
/* Apply viewport */
|
||||
if (drawstate.viewport != NULL && (drawstate.viewport->x || drawstate.viewport->y)) {
|
||||
if (drawstate.viewport && (drawstate.viewport->x || drawstate.viewport->y)) {
|
||||
copydata->dstrect.x += drawstate.viewport->x;
|
||||
copydata->dstrect.y += drawstate.viewport->y;
|
||||
}
|
||||
|
|
@ -880,7 +880,7 @@ static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo
|
|||
PrepTextureForCopy(cmd);
|
||||
|
||||
/* Apply viewport */
|
||||
if (drawstate.viewport != NULL && (drawstate.viewport->x || drawstate.viewport->y)) {
|
||||
if (drawstate.viewport && (drawstate.viewport->x || drawstate.viewport->y)) {
|
||||
SDL_Point vp;
|
||||
vp.x = drawstate.viewport->x;
|
||||
vp.y = drawstate.viewport->y;
|
||||
|
|
@ -903,7 +903,7 @@ static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo
|
|||
GeometryFillData *ptr = (GeometryFillData *) verts;
|
||||
|
||||
/* Apply viewport */
|
||||
if (drawstate.viewport != NULL && (drawstate.viewport->x || drawstate.viewport->y)) {
|
||||
if (drawstate.viewport && (drawstate.viewport->x || drawstate.viewport->y)) {
|
||||
SDL_Point vp;
|
||||
vp.x = drawstate.viewport->x;
|
||||
vp.y = drawstate.viewport->y;
|
||||
|
|
@ -938,7 +938,7 @@ static int SW_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
|
|||
Uint32 src_format;
|
||||
void *src_pixels;
|
||||
|
||||
if (surface == NULL) {
|
||||
if (!surface) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -965,7 +965,7 @@ static int SW_RenderPresent(SDL_Renderer *renderer)
|
|||
{
|
||||
SDL_Window *window = renderer->window;
|
||||
|
||||
if (window == NULL) {
|
||||
if (!window) {
|
||||
return -1;
|
||||
}
|
||||
return SDL_UpdateWindowSurface(window);
|
||||
|
|
@ -980,33 +980,27 @@ static void SW_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
|
||||
static void SW_DestroyRenderer(SDL_Renderer *renderer)
|
||||
{
|
||||
SDL_Window *window = renderer->window;
|
||||
SW_RenderData *data = (SW_RenderData *)renderer->driverdata;
|
||||
|
||||
if (window) {
|
||||
SDL_DestroyWindowSurface(window);
|
||||
}
|
||||
SDL_free(data);
|
||||
SDL_free(renderer);
|
||||
}
|
||||
|
||||
SDL_Renderer *SW_CreateRendererForSurface(SDL_Surface *surface)
|
||||
int SW_CreateRendererForSurface(SDL_Renderer *renderer, SDL_Surface *surface)
|
||||
{
|
||||
SDL_Renderer *renderer;
|
||||
SW_RenderData *data;
|
||||
|
||||
if (surface == NULL) {
|
||||
SDL_InvalidParamError("surface");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(*renderer));
|
||||
if (renderer == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
if (!surface) {
|
||||
return SDL_InvalidParamError("surface");
|
||||
}
|
||||
|
||||
data = (SW_RenderData *)SDL_calloc(1, sizeof(*data));
|
||||
if (data == NULL) {
|
||||
if (!data) {
|
||||
SW_DestroyRenderer(renderer);
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
data->surface = surface;
|
||||
data->window = surface;
|
||||
|
|
@ -1035,12 +1029,10 @@ SDL_Renderer *SW_CreateRendererForSurface(SDL_Surface *surface)
|
|||
renderer->info = SW_RenderDriver.info;
|
||||
renderer->driverdata = data;
|
||||
|
||||
SW_ActivateRenderer(renderer);
|
||||
|
||||
return renderer;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SDL_Renderer *SW_CreateRenderer(SDL_Window *window, Uint32 flags)
|
||||
static int SW_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, Uint32 flags)
|
||||
{
|
||||
const char *hint;
|
||||
SDL_Surface *surface;
|
||||
|
|
@ -1048,7 +1040,7 @@ static SDL_Renderer *SW_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
|
||||
/* Set the vsync hint based on our flags, if it's not already set */
|
||||
hint = SDL_GetHint(SDL_HINT_RENDER_VSYNC);
|
||||
if (hint == NULL || !*hint) {
|
||||
if (!hint || !*hint) {
|
||||
no_hint_set = SDL_TRUE;
|
||||
} else {
|
||||
no_hint_set = SDL_FALSE;
|
||||
|
|
@ -1065,10 +1057,10 @@ static SDL_Renderer *SW_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
SDL_SetHint(SDL_HINT_RENDER_VSYNC, "");
|
||||
}
|
||||
|
||||
if (surface == NULL) {
|
||||
return NULL;
|
||||
if (!surface) {
|
||||
return -1;
|
||||
}
|
||||
return SW_CreateRendererForSurface(surface);
|
||||
return SW_CreateRendererForSurface(renderer, surface);
|
||||
}
|
||||
|
||||
SDL_RenderDriver SW_RenderDriver = {
|
||||
|
|
@ -1091,6 +1083,6 @@ SDL_RenderDriver SW_RenderDriver = {
|
|||
0}
|
||||
};
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_SW */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
#ifndef SDL_render_sw_c_h_
|
||||
#define SDL_render_sw_c_h_
|
||||
|
||||
extern SDL_Renderer *SW_CreateRendererForSurface(SDL_Surface *surface);
|
||||
extern int SW_CreateRendererForSurface(SDL_Renderer *renderer, SDL_Surface *surface);
|
||||
|
||||
#endif /* SDL_render_sw_c_h_ */
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ Andreas Schiffler -- aschiffler at ferzkopp dot net
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_SW
|
||||
|
||||
#if defined(__WIN32__) || defined(__GDK__)
|
||||
#include "../../core/windows/SDL_windows.h"
|
||||
|
|
@ -500,7 +500,7 @@ SDL_Surface *SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, in
|
|||
double sangleinv, cangleinv;
|
||||
|
||||
/* Sanity check */
|
||||
if (src == NULL) {
|
||||
if (!src) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -524,7 +524,7 @@ SDL_Surface *SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, in
|
|||
if (is8bit) {
|
||||
/* Target surface is 8 bit */
|
||||
rz_dst = SDL_CreateRGBSurfaceWithFormat(0, rect_dest->w, rect_dest->h + GUARD_ROWS, 8, src->format->format);
|
||||
if (rz_dst != NULL) {
|
||||
if (rz_dst) {
|
||||
if (src->format->palette) {
|
||||
for (i = 0; i < src->format->palette->ncolors; i++) {
|
||||
rz_dst->format->palette->colors[i] = src->format->palette->colors[i];
|
||||
|
|
@ -540,7 +540,7 @@ SDL_Surface *SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, in
|
|||
}
|
||||
|
||||
/* Check target */
|
||||
if (rz_dst == NULL) {
|
||||
if (!rz_dst) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -617,4 +617,4 @@ SDL_Surface *SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, in
|
|||
return rz_dst;
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_SW */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -20,7 +20,9 @@
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_SW
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include "SDL_surface.h"
|
||||
#include "SDL_triangle.h"
|
||||
|
|
@ -87,9 +89,9 @@ int SDL_FillTriangle(SDL_Surface *dst, const SDL_Point points[3], Uint32 color)
|
|||
#endif
|
||||
|
||||
/* cross product AB x AC */
|
||||
static int cross_product(const SDL_Point *a, const SDL_Point *b, int c_x, int c_y)
|
||||
static Sint64 cross_product(const SDL_Point *a, const SDL_Point *b, int c_x, int c_y)
|
||||
{
|
||||
return (b->x - a->x) * (c_y - a->y) - (b->y - a->y) * (c_x - a->x);
|
||||
return ((Sint64)(b->x - a->x)) * ((Sint64)(c_y - a->y)) - ((Sint64)(b->y - a->y)) * ((Sint64)(c_x - a->x));
|
||||
}
|
||||
|
||||
/* check for top left rules */
|
||||
|
|
@ -113,10 +115,23 @@ static int is_top_left(const SDL_Point *a, const SDL_Point *b, int is_clockwise)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* x = (y << FP_BITS) */
|
||||
/* prevent runtime error: left shift of negative value */
|
||||
#define PRECOMP(x, y) \
|
||||
val = y; \
|
||||
if (val >= 0) { \
|
||||
x = val << FP_BITS; \
|
||||
} else { \
|
||||
val *= -1; \
|
||||
x = val << FP_BITS; \
|
||||
x *= -1; \
|
||||
}
|
||||
|
||||
void trianglepoint_2_fixedpoint(SDL_Point *a)
|
||||
{
|
||||
a->x <<= FP_BITS;
|
||||
a->y <<= FP_BITS;
|
||||
int val;
|
||||
PRECOMP(a->x, a->x);
|
||||
PRECOMP(a->y, a->y);
|
||||
}
|
||||
|
||||
/* bounding rect of three points (in fixed point) */
|
||||
|
|
@ -158,9 +173,9 @@ static void bounding_rect(const SDL_Point *a, const SDL_Point *b, const SDL_Poin
|
|||
int x, y; \
|
||||
for (y = 0; y < dstrect.h; y++) { \
|
||||
/* y start */ \
|
||||
int w0 = w0_row; \
|
||||
int w1 = w1_row; \
|
||||
int w2 = w2_row; \
|
||||
Sint64 w0 = w0_row; \
|
||||
Sint64 w1 = w1_row; \
|
||||
Sint64 w2 = w2_row; \
|
||||
for (x = 0; x < dstrect.w; x++) { \
|
||||
/* In triangle */ \
|
||||
if (w0 + bias_w0 >= 0 && w1 + bias_w1 >= 0 && w2 + bias_w2 >= 0) { \
|
||||
|
|
@ -210,17 +225,18 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
|
|||
Uint8 *dst_ptr;
|
||||
int dst_pitch;
|
||||
|
||||
int area, is_clockwise;
|
||||
Sint64 area;
|
||||
int is_clockwise;
|
||||
|
||||
int d2d1_y, d1d2_x, d0d2_y, d2d0_x, d1d0_y, d0d1_x;
|
||||
int w0_row, w1_row, w2_row;
|
||||
Sint64 w0_row, w1_row, w2_row;
|
||||
int bias_w0, bias_w1, bias_w2;
|
||||
|
||||
int is_uniform;
|
||||
|
||||
SDL_Surface *tmp = NULL;
|
||||
|
||||
if (dst == NULL) {
|
||||
if (!dst) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -272,7 +288,7 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
|
|||
|
||||
/* Use an intermediate surface */
|
||||
tmp = SDL_CreateRGBSurfaceWithFormat(0, dstrect.w, dstrect.h, 0, format);
|
||||
if (tmp == NULL) {
|
||||
if (!tmp) {
|
||||
ret = -1;
|
||||
goto end;
|
||||
}
|
||||
|
|
@ -296,14 +312,19 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
|
|||
}
|
||||
|
||||
is_clockwise = area > 0;
|
||||
area = SDL_abs(area);
|
||||
if (area < 0) {
|
||||
area = -area;
|
||||
}
|
||||
|
||||
d2d1_y = (d1->y - d2->y) << FP_BITS;
|
||||
d0d2_y = (d2->y - d0->y) << FP_BITS;
|
||||
d1d0_y = (d0->y - d1->y) << FP_BITS;
|
||||
d1d2_x = (d2->x - d1->x) << FP_BITS;
|
||||
d2d0_x = (d0->x - d2->x) << FP_BITS;
|
||||
d0d1_x = (d1->x - d0->x) << FP_BITS;
|
||||
{
|
||||
int val;
|
||||
PRECOMP(d2d1_y, d1->y - d2->y)
|
||||
PRECOMP(d0d2_y, d2->y - d0->y)
|
||||
PRECOMP(d1d0_y, d0->y - d1->y)
|
||||
PRECOMP(d1d2_x, d2->x - d1->x)
|
||||
PRECOMP(d2d0_x, d0->x - d2->x)
|
||||
PRECOMP(d0d1_x, d1->x - d0->x)
|
||||
}
|
||||
|
||||
/* Starting point for rendering, at the middle of a pixel */
|
||||
{
|
||||
|
|
@ -339,12 +360,7 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
|
|||
if (is_uniform) {
|
||||
Uint32 color;
|
||||
if (tmp) {
|
||||
if (dst->format->Amask) {
|
||||
color = SDL_MapRGBA(tmp->format, c0.r, c0.g, c0.b, c0.a);
|
||||
} else {
|
||||
// color = SDL_MapRGB(tmp->format, c0.r, c0.g, c0.b);
|
||||
color = SDL_MapRGBA(tmp->format, c0.r, c0.g, c0.b, c0.a);
|
||||
}
|
||||
color = SDL_MapRGBA(tmp->format, c0.r, c0.g, c0.b, c0.a);
|
||||
} else {
|
||||
color = SDL_MapRGBA(dst->format, c0.r, c0.g, c0.b, c0.a);
|
||||
}
|
||||
|
|
@ -453,20 +469,24 @@ int SDL_SW_BlitTriangle(
|
|||
int *src_ptr;
|
||||
int src_pitch;
|
||||
|
||||
int area, is_clockwise;
|
||||
Sint64 area, tmp64;
|
||||
int is_clockwise;
|
||||
|
||||
int d2d1_y, d1d2_x, d0d2_y, d2d0_x, d1d0_y, d0d1_x;
|
||||
int s2s0_x, s2s1_x, s2s0_y, s2s1_y;
|
||||
|
||||
int w0_row, w1_row, w2_row;
|
||||
Sint64 w0_row, w1_row, w2_row;
|
||||
int bias_w0, bias_w1, bias_w2;
|
||||
|
||||
int is_uniform;
|
||||
|
||||
int has_modulation;
|
||||
|
||||
if (src == NULL || dst == NULL) {
|
||||
return -1;
|
||||
if (!src) {
|
||||
return SDL_InvalidParamError("src");
|
||||
}
|
||||
if (!src) {
|
||||
return SDL_InvalidParamError("dst");
|
||||
}
|
||||
|
||||
area = cross_product(d0, d1, d2->x, d2->y);
|
||||
|
|
@ -568,15 +588,19 @@ int SDL_SW_BlitTriangle(
|
|||
src_pitch = src->pitch;
|
||||
|
||||
is_clockwise = area > 0;
|
||||
area = SDL_abs(area);
|
||||
if (area < 0) {
|
||||
area = -area;
|
||||
}
|
||||
|
||||
d2d1_y = (d1->y - d2->y) << FP_BITS;
|
||||
d0d2_y = (d2->y - d0->y) << FP_BITS;
|
||||
d1d0_y = (d0->y - d1->y) << FP_BITS;
|
||||
|
||||
d1d2_x = (d2->x - d1->x) << FP_BITS;
|
||||
d2d0_x = (d0->x - d2->x) << FP_BITS;
|
||||
d0d1_x = (d1->x - d0->x) << FP_BITS;
|
||||
{
|
||||
int val;
|
||||
PRECOMP(d2d1_y, d1->y - d2->y)
|
||||
PRECOMP(d0d2_y, d2->y - d0->y)
|
||||
PRECOMP(d1d0_y, d0->y - d1->y)
|
||||
PRECOMP(d1d2_x, d2->x - d1->x)
|
||||
PRECOMP(d2d0_x, d0->x - d2->x)
|
||||
PRECOMP(d0d1_x, d1->x - d0->x)
|
||||
}
|
||||
|
||||
s2s0_x = s0->x - s2->x;
|
||||
s2s1_x = s1->x - s2->x;
|
||||
|
|
@ -615,8 +639,20 @@ int SDL_SW_BlitTriangle(
|
|||
bias_w2 = (is_top_left(d0, d1, is_clockwise) ? 0 : -1);
|
||||
|
||||
/* precompute constant 's2->x * area' used in TRIANGLE_GET_TEXTCOORD */
|
||||
s2_x_area.x = s2->x * area;
|
||||
s2_x_area.y = s2->y * area;
|
||||
tmp64 = s2->x * area;
|
||||
if (tmp64 >= INT_MIN && tmp64 <= INT_MAX) {
|
||||
s2_x_area.x = (int)tmp64;
|
||||
} else {
|
||||
ret = SDL_SetError("triangle area overflow");
|
||||
goto end;
|
||||
}
|
||||
tmp64 = s2->y * area;
|
||||
if (tmp64 >= INT_MIN && tmp64 <= INT_MAX) {
|
||||
s2_x_area.y = (int)tmp64;
|
||||
} else {
|
||||
ret = SDL_SetError("triangle area overflow");
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (blend != SDL_BLENDMODE_NONE || src->format->format != dst->format->format || has_modulation || !is_uniform) {
|
||||
/* Use SDL_BlitTriangle_Slow */
|
||||
|
|
@ -662,9 +698,18 @@ int SDL_SW_BlitTriangle(
|
|||
tmp_info.dst = dst_ptr;
|
||||
tmp_info.dst_pitch = dst_pitch;
|
||||
|
||||
SDL_BlitTriangle_Slow(&tmp_info, s2_x_area, dstrect, area, bias_w0, bias_w1, bias_w2,
|
||||
#define CHECK_INT_RANGE(X) \
|
||||
if ((X) < INT_MIN || (X) > INT_MAX) { \
|
||||
ret = SDL_SetError("integer overflow (%s = %" SDL_PRIs64 ")", #X, X); \
|
||||
goto end; \
|
||||
}
|
||||
CHECK_INT_RANGE(area);
|
||||
CHECK_INT_RANGE(w0_row);
|
||||
CHECK_INT_RANGE(w1_row);
|
||||
CHECK_INT_RANGE(w2_row);
|
||||
SDL_BlitTriangle_Slow(&tmp_info, s2_x_area, dstrect, (int)area, bias_w0, bias_w1, bias_w2,
|
||||
d2d1_y, d1d2_x, d0d2_y, d2d0_x, d1d0_y, d0d1_x,
|
||||
s2s0_x, s2s1_x, s2s0_y, s2s1_y, w0_row, w1_row, w2_row,
|
||||
s2s0_x, s2s1_x, s2s0_y, s2s1_y, (int)w0_row, (int)w1_row, (int)w2_row,
|
||||
c0, c1, c2, is_uniform);
|
||||
|
||||
goto end;
|
||||
|
|
@ -789,15 +834,20 @@ static void SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
|
|||
continue;
|
||||
}
|
||||
}
|
||||
if (FORMAT_HAS_ALPHA(dstfmt_val)) {
|
||||
DISEMBLE_RGBA(dst, dstbpp, dst_fmt, dstpixel, dstR, dstG, dstB, dstA);
|
||||
} else if (FORMAT_HAS_NO_ALPHA(dstfmt_val)) {
|
||||
DISEMBLE_RGB(dst, dstbpp, dst_fmt, dstpixel, dstR, dstG, dstB);
|
||||
dstA = 0xFF;
|
||||
if ((flags & (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_MUL))) {
|
||||
if (FORMAT_HAS_ALPHA(dstfmt_val)) {
|
||||
DISEMBLE_RGBA(dst, dstbpp, dst_fmt, dstpixel, dstR, dstG, dstB, dstA);
|
||||
} else if (FORMAT_HAS_NO_ALPHA(dstfmt_val)) {
|
||||
DISEMBLE_RGB(dst, dstbpp, dst_fmt, dstpixel, dstR, dstG, dstB);
|
||||
dstA = 0xFF;
|
||||
} else {
|
||||
/* SDL_PIXELFORMAT_ARGB2101010 */
|
||||
dstpixel = *((Uint32 *) (dst));
|
||||
RGBA_FROM_ARGB2101010(dstpixel, dstR, dstG, dstB, dstA);
|
||||
}
|
||||
} else {
|
||||
/* SDL_PIXELFORMAT_ARGB2101010 */
|
||||
dstpixel = *((Uint32 *)(dst));
|
||||
RGBA_FROM_ARGB2101010(dstpixel, dstR, dstG, dstB, dstA);
|
||||
/* don't care */
|
||||
dstR = dstG = dstB = dstA = 0;
|
||||
}
|
||||
|
||||
if (!is_uniform) {
|
||||
|
|
@ -885,6 +935,6 @@ static void SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
|
|||
TRIANGLE_END_LOOP
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_SW */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -40,11 +40,11 @@
|
|||
|
||||
/* #define DEBUG_RAZOR */
|
||||
|
||||
#if DEBUG_RAZOR
|
||||
#ifdef DEBUG_RAZOR
|
||||
#include <psp2/sysmodule.h>
|
||||
#endif
|
||||
|
||||
static SDL_Renderer *VITA_GXM_CreateRenderer(SDL_Window *window, Uint32 flags);
|
||||
static int VITA_GXM_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, Uint32 flags);
|
||||
|
||||
static void VITA_GXM_WindowEvent(SDL_Renderer *renderer, const SDL_WindowEvent *event);
|
||||
|
||||
|
|
@ -169,7 +169,7 @@ void StartDrawing(SDL_Renderer *renderer)
|
|||
// data->colorFragmentProgram = in->color;
|
||||
// data->textureFragmentProgram = in->texture;
|
||||
|
||||
if (renderer->target == NULL) {
|
||||
if (!renderer->target) {
|
||||
sceGxmBeginScene(
|
||||
data->gxm_context,
|
||||
0,
|
||||
|
|
@ -211,22 +211,13 @@ static int VITA_GXM_SetVSync(SDL_Renderer *renderer, const int vsync)
|
|||
return 0;
|
||||
}
|
||||
|
||||
SDL_Renderer *VITA_GXM_CreateRenderer(SDL_Window *window, Uint32 flags)
|
||||
int VITA_GXM_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, Uint32 flags)
|
||||
{
|
||||
SDL_Renderer *renderer;
|
||||
VITA_GXM_RenderData *data;
|
||||
|
||||
renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(*renderer));
|
||||
if (renderer == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
data = (VITA_GXM_RenderData *)SDL_calloc(1, sizeof(VITA_GXM_RenderData));
|
||||
if (data == NULL) {
|
||||
SDL_free(renderer);
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
if (!data) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
renderer->WindowEvent = VITA_GXM_WindowEvent;
|
||||
|
|
@ -266,18 +257,17 @@ SDL_Renderer *VITA_GXM_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
data->displayData.wait_vblank = SDL_FALSE;
|
||||
}
|
||||
|
||||
#if DEBUG_RAZOR
|
||||
#ifdef DEBUG_RAZOR
|
||||
sceSysmoduleLoadModule(SCE_SYSMODULE_RAZOR_HUD);
|
||||
sceSysmoduleLoadModule(SCE_SYSMODULE_RAZOR_CAPTURE);
|
||||
#endif
|
||||
|
||||
if (gxm_init(renderer) != 0) {
|
||||
SDL_free(data);
|
||||
SDL_free(renderer);
|
||||
return NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return renderer;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void VITA_GXM_WindowEvent(SDL_Renderer *renderer, const SDL_WindowEvent *event)
|
||||
|
|
@ -295,7 +285,7 @@ static int VITA_GXM_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
VITA_GXM_RenderData *data = (VITA_GXM_RenderData *)renderer->driverdata;
|
||||
VITA_GXM_TextureData *vita_texture = (VITA_GXM_TextureData *)SDL_calloc(1, sizeof(VITA_GXM_TextureData));
|
||||
|
||||
if (vita_texture == NULL) {
|
||||
if (!vita_texture) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
|
|
@ -366,6 +356,7 @@ static int VITA_GXM_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
|
|||
length = rect->w * SDL_BYTESPERPIXEL(texture->format);
|
||||
if (length == pitch && length == dpitch) {
|
||||
SDL_memcpy(dst, pixels, length * rect->h);
|
||||
pixels += pitch * rect->h;
|
||||
} else {
|
||||
for (row = 0; row < rect->h; ++row) {
|
||||
SDL_memcpy(dst, pixels, length);
|
||||
|
|
@ -393,6 +384,7 @@ static int VITA_GXM_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
|
|||
// U plane
|
||||
if (length == uv_src_pitch && length == uv_pitch) {
|
||||
SDL_memcpy(Udst, pixels, length * UVrect.h);
|
||||
pixels += uv_src_pitch * UVrect.h;
|
||||
} else {
|
||||
for (row = 0; row < UVrect.h; ++row) {
|
||||
SDL_memcpy(Udst, pixels, length);
|
||||
|
|
@ -583,7 +575,7 @@ static int VITA_GXM_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
|
|||
*pitch = vita_texture->pitch;
|
||||
|
||||
// make sure that rendering is finished on render target textures
|
||||
if (vita_texture->tex->gxm_rendertarget != NULL) {
|
||||
if (vita_texture->tex->gxm_rendertarget) {
|
||||
sceGxmFinish(data->gxm_context);
|
||||
}
|
||||
|
||||
|
|
@ -733,7 +725,7 @@ static int VITA_GXM_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd
|
|||
data,
|
||||
count * sizeof(texture_vertex));
|
||||
|
||||
if (vertices == NULL) {
|
||||
if (!vertices) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -772,7 +764,7 @@ static int VITA_GXM_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd
|
|||
data,
|
||||
count * sizeof(color_vertex));
|
||||
|
||||
if (vertices == NULL) {
|
||||
if (!vertices) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -956,6 +948,7 @@ static int VITA_GXM_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *c
|
|||
if (SDL_memcmp(viewport, &cmd->data.viewport.rect, sizeof(cmd->data.viewport.rect)) != 0) {
|
||||
SDL_copyp(viewport, &cmd->data.viewport.rect);
|
||||
data->drawstate.viewport_dirty = SDL_TRUE;
|
||||
data->drawstate.cliprect_dirty = SDL_TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -1006,7 +999,7 @@ static int VITA_GXM_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *c
|
|||
SDL_RenderCommand *nextcmd = cmd->next;
|
||||
size_t count = cmd->data.draw.count;
|
||||
int ret;
|
||||
while (nextcmd != NULL) {
|
||||
while (nextcmd) {
|
||||
const SDL_RenderCommandType nextcmdtype = nextcmd->command;
|
||||
if (nextcmdtype != thiscmdtype) {
|
||||
break; /* can't go any further on this draw call, different render command up next. */
|
||||
|
|
@ -1103,7 +1096,7 @@ static int VITA_GXM_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rec
|
|||
}
|
||||
|
||||
temp_pixels = SDL_malloc(buflen);
|
||||
if (temp_pixels == NULL) {
|
||||
if (!temp_pixels) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
|
|
@ -1161,7 +1154,7 @@ static int VITA_GXM_RenderPresent(SDL_Renderer *renderer)
|
|||
|
||||
sceCommonDialogUpdate(&updateParam);
|
||||
|
||||
#if DEBUG_RAZOR
|
||||
#ifdef DEBUG_RAZOR
|
||||
sceGxmPadHeartbeat(
|
||||
(const SceGxmColorSurface *)&data->displaySurface[data->backBufferIndex],
|
||||
(SceGxmSyncObject *)data->displayBufferSync[data->backBufferIndex]);
|
||||
|
|
@ -1186,15 +1179,15 @@ static void VITA_GXM_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture
|
|||
VITA_GXM_RenderData *data = (VITA_GXM_RenderData *)renderer->driverdata;
|
||||
VITA_GXM_TextureData *vita_texture = (VITA_GXM_TextureData *)texture->driverdata;
|
||||
|
||||
if (data == NULL) {
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (vita_texture == NULL) {
|
||||
if (!vita_texture) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (vita_texture->tex == NULL) {
|
||||
if (!vita_texture->tex) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1221,7 +1214,6 @@ static void VITA_GXM_DestroyRenderer(SDL_Renderer *renderer)
|
|||
data->drawing = SDL_FALSE;
|
||||
SDL_free(data);
|
||||
}
|
||||
SDL_free(renderer);
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_VITA_GXM */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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,8 @@ void *vita_mem_alloc(unsigned int type, unsigned int size, unsigned int alignmen
|
|||
|
||||
if (type == SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW) {
|
||||
size = ALIGN(size, 256 * 1024);
|
||||
} else if (type == SCE_KERNEL_MEMBLOCK_TYPE_USER_MAIN_PHYCONT_NC_RW) {
|
||||
size = ALIGN(size, 1024 * 1024);
|
||||
} else {
|
||||
size = ALIGN(size, 4 * 1024);
|
||||
}
|
||||
|
|
@ -66,7 +68,7 @@ void *vita_gpu_mem_alloc(VITA_GXM_RenderData *data, unsigned int size)
|
|||
{
|
||||
void *mem;
|
||||
|
||||
if (data->texturePool == NULL) {
|
||||
if (!data->texturePool) {
|
||||
int poolsize;
|
||||
int ret;
|
||||
SceKernelFreeMemorySizeInfo info;
|
||||
|
|
@ -88,7 +90,7 @@ void *vita_gpu_mem_alloc(VITA_GXM_RenderData *data, unsigned int size)
|
|||
}
|
||||
data->texturePool = sceClibMspaceCreate(mem, poolsize);
|
||||
|
||||
if (data->texturePool == NULL) {
|
||||
if (!data->texturePool) {
|
||||
return NULL;
|
||||
}
|
||||
ret = sceGxmMapMemory(mem, poolsize, SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE);
|
||||
|
|
@ -101,7 +103,7 @@ void *vita_gpu_mem_alloc(VITA_GXM_RenderData *data, unsigned int size)
|
|||
|
||||
void vita_gpu_mem_free(VITA_GXM_RenderData *data, void *ptr)
|
||||
{
|
||||
if (data->texturePool != NULL) {
|
||||
if (data->texturePool) {
|
||||
sceClibMspaceFree(data->texturePool, ptr);
|
||||
}
|
||||
}
|
||||
|
|
@ -109,7 +111,7 @@ void vita_gpu_mem_free(VITA_GXM_RenderData *data, void *ptr)
|
|||
void vita_gpu_mem_destroy(VITA_GXM_RenderData *data)
|
||||
{
|
||||
void *mem = NULL;
|
||||
if (data->texturePool != NULL) {
|
||||
if (data->texturePool) {
|
||||
sceClibMspaceDestroy(data->texturePool);
|
||||
data->texturePool = NULL;
|
||||
if (sceKernelGetMemBlockBase(data->texturePoolUID, &mem) < 0) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -1003,7 +1003,7 @@ gxm_texture *create_gxm_texture(VITA_GXM_RenderData *data, unsigned int w, unsig
|
|||
tex_size += (((aligned_w + 1) / 2) * ((h + 1) / 2)) * 2;
|
||||
}
|
||||
|
||||
if (texture == NULL) {
|
||||
if (!texture) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -1017,7 +1017,7 @@ gxm_texture *create_gxm_texture(VITA_GXM_RenderData *data, unsigned int w, unsig
|
|||
tex_size);
|
||||
|
||||
/* Try SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE in case we're out of VRAM */
|
||||
if (texture_data == NULL) {
|
||||
if (!texture_data) {
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_RENDER, "CDRAM texture allocation failed\n");
|
||||
texture_data = vita_mem_alloc(
|
||||
SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE,
|
||||
|
|
@ -1030,7 +1030,7 @@ gxm_texture *create_gxm_texture(VITA_GXM_RenderData *data, unsigned int w, unsig
|
|||
texture->cdram = 1;
|
||||
}
|
||||
|
||||
if (texture_data == NULL) {
|
||||
if (!texture_data) {
|
||||
SDL_free(texture);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -1162,7 +1162,7 @@ void gxm_init_for_common_dialog(void)
|
|||
for (int i = 0; i < VITA_GXM_BUFFERS; i += 1) {
|
||||
buffer_for_common_dialog[i].displayData.wait_vblank = SDL_TRUE;
|
||||
buffer_for_common_dialog[i].displayData.address = vita_mem_alloc(
|
||||
SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW,
|
||||
SCE_KERNEL_MEMBLOCK_TYPE_USER_MAIN_PHYCONT_NC_RW,
|
||||
4 * VITA_GXM_SCREEN_STRIDE * VITA_GXM_SCREEN_HEIGHT,
|
||||
SCE_GXM_COLOR_SURFACE_ALIGNMENT,
|
||||
SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue