Updates the SDL library to the latest standard bugfix release

This commit is contained in:
JeffR 2023-07-13 15:20:29 -05:00
parent cb766f2878
commit 083d2175ea
1280 changed files with 343926 additions and 179615 deletions

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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_RENDER_DISABLED
#if (SDL_VIDEO_RENDER_D3D || SDL_VIDEO_RENDER_D3D11 || SDL_VIDEO_RENDER_D3D12) && !SDL_RENDER_DISABLED
#include "SDL_stdinc.h"
#include "SDL_d3dmath.h"
@ -128,9 +128,8 @@ Float4X4 MatrixRotationZ(float r)
m.v._33 = 1.0f;
m.v._44 = 1.0f;
return m;
}
#endif /* (SDL_VIDEO_RENDER_D3D || SDL_VIDEO_RENDER_D3D11) && !SDL_RENDER_DISABLED */
#endif /* (SDL_VIDEO_RENDER_D3D || SDL_VIDEO_RENDER_D3D11 || SDL_VIDEO_RENDER_D3D12) && !SDL_RENDER_DISABLED */
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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,12 @@
*/
#include "../SDL_internal.h"
#if (SDL_VIDEO_RENDER_D3D || SDL_VIDEO_RENDER_D3D11) && !SDL_RENDER_DISABLED
#if (SDL_VIDEO_RENDER_D3D || SDL_VIDEO_RENDER_D3D11 || SDL_VIDEO_RENDER_D3D12) && !SDL_RENDER_DISABLED
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/* Direct3D matrix math functions */
@ -47,8 +52,10 @@ typedef struct
typedef struct
{
union {
struct {
union
{
struct
{
float _11, _12, _13, _14;
float _21, _22, _23, _24;
float _31, _32, _33, _34;
@ -58,7 +65,6 @@ typedef struct
};
} Float4X4;
Float4X4 MatrixIdentity();
Float4X4 MatrixMultiply(Float4X4 M1, Float4X4 M2);
Float4X4 MatrixScaling(float x, float y, float z);
@ -67,6 +73,11 @@ Float4X4 MatrixRotationX(float r);
Float4X4 MatrixRotationY(float r);
Float4X4 MatrixRotationZ(float r);
#endif /* (SDL_VIDEO_RENDER_D3D || SDL_VIDEO_RENDER_D3D11) && !SDL_RENDER_DISABLED */
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#endif /* (SDL_VIDEO_RENDER_D3D || SDL_VIDEO_RENDER_D3D11 || SDL_VIDEO_RENDER_D3D12) && !SDL_RENDER_DISABLED */
/* vi: set ts=4 sw=4 expandtab: */

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -28,6 +28,10 @@
#include "SDL_mutex.h"
#include "SDL_yuv_sw_c.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/**
* A rectangle, with the origin at the upper left (double precision).
@ -40,7 +44,6 @@ typedef struct SDL_DRect
double h;
} SDL_DRect;
/* The SDL 2D rendering system */
typedef struct SDL_RenderDriver SDL_RenderDriver;
@ -49,14 +52,14 @@ typedef struct SDL_RenderDriver SDL_RenderDriver;
struct SDL_Texture
{
const void *magic;
Uint32 format; /**< The pixel format of the texture */
int access; /**< SDL_TextureAccess */
int w; /**< The width of the texture */
int h; /**< The height of the texture */
int modMode; /**< The texture modulation mode */
SDL_BlendMode blendMode; /**< The texture blend mode */
SDL_ScaleMode scaleMode; /**< The texture scale mode */
SDL_Color color; /**< Texture modulation values */
Uint32 format; /**< The pixel format of the texture */
int access; /**< SDL_TextureAccess */
int w; /**< The width of the texture */
int h; /**< The height of the texture */
int modMode; /**< The texture modulation mode */
SDL_BlendMode blendMode; /**< The texture blend mode */
SDL_ScaleMode scaleMode; /**< The texture scale mode */
SDL_Color color; /**< Texture modulation values */
SDL_Renderer *renderer;
@ -66,11 +69,11 @@ struct SDL_Texture
void *pixels;
int pitch;
SDL_Rect locked_rect;
SDL_Surface *locked_surface; /**< Locked region exposed as a SDL surface */
SDL_Surface *locked_surface; /**< Locked region exposed as a SDL surface */
Uint32 last_command_generation; /* last command queue generation this texture was in. */
void *driverdata; /**< Driver specific texture representation */
void *driverdata; /**< Driver specific texture representation */
void *userdata;
SDL_Texture *prev;
@ -95,23 +98,28 @@ typedef enum
typedef struct SDL_RenderCommand
{
SDL_RenderCommandType command;
union {
struct {
union
{
struct
{
size_t first;
SDL_Rect rect;
} viewport;
struct {
struct
{
SDL_bool enabled;
SDL_Rect rect;
} cliprect;
struct {
struct
{
size_t first;
size_t count;
Uint8 r, g, b, a;
SDL_BlendMode blend;
SDL_Texture *texture;
} draw;
struct {
struct
{
size_t first;
Uint8 r, g, b, a;
} color;
@ -119,14 +127,12 @@ typedef struct SDL_RenderCommand
struct SDL_RenderCommand *next;
} SDL_RenderCommand;
typedef struct SDL_VertexSolid
{
SDL_FPoint position;
SDL_Color color;
SDL_Color color;
} SDL_VertexSolid;
typedef enum
{
SDL_RENDERLINEMETHOD_POINTS,
@ -134,68 +140,67 @@ typedef enum
SDL_RENDERLINEMETHOD_GEOMETRY,
} SDL_RenderLineMethod;
/* Define the SDL renderer structure */
struct SDL_Renderer
{
const void *magic;
void (*WindowEvent) (SDL_Renderer * renderer, const SDL_WindowEvent *event);
int (*GetOutputSize) (SDL_Renderer * renderer, int *w, int *h);
SDL_bool (*SupportsBlendMode)(SDL_Renderer * renderer, SDL_BlendMode blendMode);
int (*CreateTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
int (*QueueSetViewport) (SDL_Renderer * renderer, SDL_RenderCommand *cmd);
int (*QueueSetDrawColor) (SDL_Renderer * renderer, SDL_RenderCommand *cmd);
int (*QueueDrawPoints) (SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points,
int count);
int (*QueueDrawLines) (SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points,
int count);
int (*QueueFillRects) (SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects,
int count);
int (*QueueCopy) (SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_FRect * dstrect);
int (*QueueCopyEx) (SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
const SDL_Rect * srcquad, const SDL_FRect * dstrect,
const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip, float scale_x, float scale_y);
int (*QueueGeometry) (SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
const float *xy, int xy_stride, const SDL_Color *color, int color_stride, const float *uv, int uv_stride,
int num_vertices, const void *indices, int num_indices, int size_indices,
float scale_x, float scale_y);
void (*WindowEvent)(SDL_Renderer *renderer, const SDL_WindowEvent *event);
int (*GetOutputSize)(SDL_Renderer *renderer, int *w, int *h);
SDL_bool (*SupportsBlendMode)(SDL_Renderer *renderer, SDL_BlendMode blendMode);
int (*CreateTexture)(SDL_Renderer *renderer, SDL_Texture *texture);
int (*QueueSetViewport)(SDL_Renderer *renderer, SDL_RenderCommand *cmd);
int (*QueueSetDrawColor)(SDL_Renderer *renderer, SDL_RenderCommand *cmd);
int (*QueueDrawPoints)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points,
int count);
int (*QueueDrawLines)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points,
int count);
int (*QueueFillRects)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FRect *rects,
int count);
int (*QueueCopy)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
const SDL_Rect *srcrect, const SDL_FRect *dstrect);
int (*QueueCopyEx)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
const SDL_Rect *srcquad, const SDL_FRect *dstrect,
const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip, float scale_x, float scale_y);
int (*QueueGeometry)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
const float *xy, int xy_stride, const SDL_Color *color, int color_stride, const float *uv, int uv_stride,
int num_vertices, const void *indices, int num_indices, int size_indices,
float scale_x, float scale_y);
int (*RunCommandQueue) (SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize);
int (*UpdateTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels,
int pitch);
int (*RunCommandQueue)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize);
int (*UpdateTexture)(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect, const void *pixels,
int pitch);
#if SDL_HAVE_YUV
int (*UpdateTextureYUV) (SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect,
int (*UpdateTextureYUV)(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect,
const Uint8 *Yplane, int Ypitch,
const Uint8 *Uplane, int Upitch,
const Uint8 *Vplane, int Vpitch);
int (*UpdateTextureNV) (SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect,
const Uint8 *Yplane, int Ypitch,
const Uint8 *UVplane, int UVpitch);
int (*UpdateTextureNV)(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect,
const Uint8 *Yplane, int Ypitch,
const Uint8 *UVplane, int UVpitch);
#endif
int (*LockTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, void **pixels, int *pitch);
void (*UnlockTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
void (*SetTextureScaleMode) (SDL_Renderer * renderer, SDL_Texture * texture, SDL_ScaleMode scaleMode);
int (*SetRenderTarget) (SDL_Renderer * renderer, SDL_Texture * texture);
int (*RenderReadPixels) (SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 format, void * pixels, int pitch);
void (*RenderPresent) (SDL_Renderer * renderer);
void (*DestroyTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
int (*LockTexture)(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect, void **pixels, int *pitch);
void (*UnlockTexture)(SDL_Renderer *renderer, SDL_Texture *texture);
void (*SetTextureScaleMode)(SDL_Renderer *renderer, SDL_Texture *texture, SDL_ScaleMode scaleMode);
int (*SetRenderTarget)(SDL_Renderer *renderer, SDL_Texture *texture);
int (*RenderReadPixels)(SDL_Renderer *renderer, const SDL_Rect *rect,
Uint32 format, void *pixels, int pitch);
int (*RenderPresent)(SDL_Renderer *renderer);
void (*DestroyTexture)(SDL_Renderer *renderer, SDL_Texture *texture);
void (*DestroyRenderer) (SDL_Renderer * renderer);
void (*DestroyRenderer)(SDL_Renderer *renderer);
int (*SetVSync) (SDL_Renderer * renderer, int vsync);
int (*SetVSync)(SDL_Renderer *renderer, int vsync);
int (*GL_BindTexture) (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh);
int (*GL_UnbindTexture) (SDL_Renderer * renderer, SDL_Texture *texture);
int (*GL_BindTexture)(SDL_Renderer *renderer, SDL_Texture *texture, float *texw, float *texh);
int (*GL_UnbindTexture)(SDL_Renderer *renderer, SDL_Texture *texture);
void *(*GetMetalLayer) (SDL_Renderer * renderer);
void *(*GetMetalCommandEncoder) (SDL_Renderer * renderer);
void *(*GetMetalLayer)(SDL_Renderer *renderer);
void *(*GetMetalCommandEncoder)(SDL_Renderer *renderer);
/* The current renderer info */
SDL_RendererInfo info;
@ -204,6 +209,12 @@ struct SDL_Renderer
SDL_Window *window;
SDL_bool hidden;
/* Whether we should simulate vsync */
SDL_bool wanted_vsync;
SDL_bool simulate_vsync;
Uint32 simulate_vsync_interval;
Uint32 last_present;
/* The logical resolution for rendering */
int logical_w;
int logical_h;
@ -221,7 +232,7 @@ struct SDL_Renderer
SDL_DRect clip_rect;
SDL_DRect clip_rect_backup;
/* Wether or not the clipping rectangle is used. */
/* Whether or not the clipping rectangle is used. */
SDL_bool clipping_enabled;
SDL_bool clipping_enabled_backup;
@ -238,6 +249,9 @@ struct SDL_Renderer
/* The method of drawing lines */
SDL_RenderLineMethod line_method;
/* List of triangle indices to draw rects */
int rect_index_order[6];
/* Remainder from scaled relative motion */
float xrel;
float yrel;
@ -247,8 +261,8 @@ struct SDL_Renderer
SDL_Texture *target;
SDL_mutex *target_mutex;
SDL_Color color; /**< Color for drawing operations values */
SDL_BlendMode blendMode; /**< The drawing blend mode */
SDL_Color color; /**< Color for drawing operations values */
SDL_BlendMode blendMode; /**< The drawing blend mode */
SDL_bool always_batch;
SDL_bool batching;
@ -274,7 +288,7 @@ struct SDL_Renderer
/* Define the SDL render driver structure */
struct SDL_RenderDriver
{
SDL_Renderer *(*CreateRenderer) (SDL_Window * window, Uint32 flags);
SDL_Renderer *(*CreateRenderer)(SDL_Window *window, Uint32 flags);
/* Info about the renderer capabilities */
SDL_RendererInfo info;
@ -283,11 +297,13 @@ struct SDL_RenderDriver
/* Not all of these are available in a given build. Use #ifdefs, etc. */
extern SDL_RenderDriver D3D_RenderDriver;
extern SDL_RenderDriver D3D11_RenderDriver;
extern SDL_RenderDriver D3D12_RenderDriver;
extern SDL_RenderDriver GL_RenderDriver;
extern SDL_RenderDriver GLES2_RenderDriver;
extern SDL_RenderDriver GLES_RenderDriver;
extern SDL_RenderDriver DirectFB_RenderDriver;
extern SDL_RenderDriver METAL_RenderDriver;
extern SDL_RenderDriver PS2_RenderDriver;
extern SDL_RenderDriver PSP_RenderDriver;
extern SDL_RenderDriver SW_RenderDriver;
extern SDL_RenderDriver VITA_GXM_RenderDriver;
@ -305,8 +321,13 @@ extern SDL_BlendOperation SDL_GetBlendModeAlphaOperation(SDL_BlendMode blendMode
the next call, because it might be in an array that gets realloc()'d. */
extern void *SDL_AllocateRenderVertices(SDL_Renderer *renderer, const size_t numbytes, const size_t alignment, size_t *offset);
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);
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);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#endif /* SDL_sysrender_h_ */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -24,13 +24,11 @@
#if SDL_HAVE_YUV
#include "SDL_yuv_sw_c.h"
#include "../video/SDL_yuv_c.h"
#include "SDL_cpuinfo.h"
SDL_SW_YUVTexture *
SDL_SW_CreateYUVTexture(Uint32 format, int w, int h)
SDL_SW_YUVTexture *SDL_SW_CreateYUVTexture(Uint32 format, int w, int h)
{
SDL_SW_YUVTexture *swdata;
@ -48,8 +46,8 @@ SDL_SW_CreateYUVTexture(Uint32 format, int w, int h)
return NULL;
}
swdata = (SDL_SW_YUVTexture *) SDL_calloc(1, sizeof(*swdata));
if (!swdata) {
swdata = (SDL_SW_YUVTexture *)SDL_calloc(1, sizeof(*swdata));
if (swdata == NULL) {
SDL_OutOfMemory();
return NULL;
}
@ -59,33 +57,13 @@ SDL_SW_CreateYUVTexture(Uint32 format, int w, int h)
swdata->w = w;
swdata->h = h;
{
const int sz_plane = w * h;
const int sz_plane_chroma = ((w + 1) / 2) * ((h + 1) / 2);
const int sz_plane_packed = ((w + 1) / 2) * h;
int dst_size = 0;
switch(format)
{
case SDL_PIXELFORMAT_YV12: /**< Planar mode: Y + V + U (3 planes) */
case SDL_PIXELFORMAT_IYUV: /**< Planar mode: Y + U + V (3 planes) */
dst_size = sz_plane + sz_plane_chroma + sz_plane_chroma;
break;
case SDL_PIXELFORMAT_YUY2: /**< Packed mode: Y0+U0+Y1+V0 (1 plane) */
case SDL_PIXELFORMAT_UYVY: /**< Packed mode: U0+Y0+V0+Y1 (1 plane) */
case SDL_PIXELFORMAT_YVYU: /**< Packed mode: Y0+V0+Y1+U0 (1 plane) */
dst_size = 4 * sz_plane_packed;
break;
case SDL_PIXELFORMAT_NV12: /**< Planar mode: Y + U/V interleaved (2 planes) */
case SDL_PIXELFORMAT_NV21: /**< Planar mode: Y + V/U interleaved (2 planes) */
dst_size = sz_plane + sz_plane_chroma + sz_plane_chroma;
break;
default:
SDL_assert(0 && "We should never get here (caught above)");
break;
size_t dst_size;
if (SDL_CalculateYUVSize(format, w, h, &dst_size, NULL) < 0) {
SDL_SW_DestroyYUVTexture(swdata);
SDL_OutOfMemory();
return NULL;
}
swdata->pixels = (Uint8 *) SDL_SIMDAlloc(dst_size);
swdata->pixels = (Uint8 *)SDL_SIMDAlloc(dst_size);
if (!swdata->pixels) {
SDL_SW_DestroyYUVTexture(swdata);
SDL_OutOfMemory();
@ -125,36 +103,34 @@ SDL_SW_CreateYUVTexture(Uint32 format, int w, int h)
}
/* We're all done.. */
return (swdata);
return swdata;
}
int
SDL_SW_QueryYUVTexturePixels(SDL_SW_YUVTexture * swdata, void **pixels,
int *pitch)
int SDL_SW_QueryYUVTexturePixels(SDL_SW_YUVTexture *swdata, void **pixels,
int *pitch)
{
*pixels = swdata->planes[0];
*pitch = swdata->pitches[0];
return 0;
}
int
SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
const void *pixels, int pitch)
int SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect,
const void *pixels, int pitch)
{
switch (swdata->format) {
case SDL_PIXELFORMAT_YV12:
case SDL_PIXELFORMAT_IYUV:
if (rect->x == 0 && rect->y == 0 &&
rect->w == swdata->w && rect->h == swdata->h) {
SDL_memcpy(swdata->pixels, pixels,
(swdata->h * swdata->w) + 2* ((swdata->h + 1) /2) * ((swdata->w + 1) / 2));
SDL_memcpy(swdata->pixels, pixels,
(size_t)(swdata->h * swdata->w) + 2 * ((swdata->h + 1) / 2) * ((swdata->w + 1) / 2));
} else {
Uint8 *src, *dst;
int row;
size_t length;
/* Copy the Y plane */
src = (Uint8 *) pixels;
src = (Uint8 *)pixels;
dst = swdata->pixels + rect->y * swdata->w + rect->x;
length = rect->w;
for (row = 0; row < rect->h; ++row) {
@ -162,94 +138,92 @@ SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
src += pitch;
dst += swdata->w;
}
/* Copy the next plane */
src = (Uint8 *) pixels + rect->h * pitch;
src = (Uint8 *)pixels + rect->h * pitch;
dst = swdata->pixels + swdata->h * swdata->w;
dst += rect->y/2 * ((swdata->w + 1) / 2) + rect->x/2;
dst += rect->y / 2 * ((swdata->w + 1) / 2) + rect->x / 2;
length = (rect->w + 1) / 2;
for (row = 0; row < (rect->h + 1)/2; ++row) {
for (row = 0; row < (rect->h + 1) / 2; ++row) {
SDL_memcpy(dst, src, length);
src += (pitch + 1)/2;
dst += (swdata->w + 1)/2;
src += (pitch + 1) / 2;
dst += (swdata->w + 1) / 2;
}
/* Copy the next plane */
src = (Uint8 *) pixels + rect->h * pitch + ((rect->h + 1) / 2) * ((pitch + 1) / 2);
src = (Uint8 *)pixels + rect->h * pitch + ((rect->h + 1) / 2) * ((pitch + 1) / 2);
dst = swdata->pixels + swdata->h * swdata->w +
((swdata->h + 1)/2) * ((swdata->w+1) / 2);
dst += rect->y/2 * ((swdata->w + 1)/2) + rect->x/2;
((swdata->h + 1) / 2) * ((swdata->w + 1) / 2);
dst += rect->y / 2 * ((swdata->w + 1) / 2) + rect->x / 2;
length = (rect->w + 1) / 2;
for (row = 0; row < (rect->h + 1)/2; ++row) {
for (row = 0; row < (rect->h + 1) / 2; ++row) {
SDL_memcpy(dst, src, length);
src += (pitch + 1)/2;
dst += (swdata->w + 1)/2;
src += (pitch + 1) / 2;
dst += (swdata->w + 1) / 2;
}
}
break;
case SDL_PIXELFORMAT_YUY2:
case SDL_PIXELFORMAT_UYVY:
case SDL_PIXELFORMAT_YVYU:
{
{
Uint8 *src, *dst;
int row;
size_t length;
src = (Uint8 *)pixels;
dst =
swdata->planes[0] + rect->y * swdata->pitches[0] +
rect->x * 2;
length = 4 * (((size_t)rect->w + 1) / 2);
for (row = 0; row < rect->h; ++row) {
SDL_memcpy(dst, src, length);
src += pitch;
dst += swdata->pitches[0];
}
} break;
case SDL_PIXELFORMAT_NV12:
case SDL_PIXELFORMAT_NV21:
{
if (rect->x == 0 && rect->y == 0 && rect->w == swdata->w && rect->h == swdata->h) {
SDL_memcpy(swdata->pixels, pixels,
(size_t)(swdata->h * swdata->w) + 2 * ((swdata->h + 1) / 2) * ((swdata->w + 1) / 2));
} else {
Uint8 *src, *dst;
int row;
size_t length;
src = (Uint8 *) pixels;
dst =
swdata->planes[0] + rect->y * swdata->pitches[0] +
rect->x * 2;
length = 4 * ((rect->w + 1) / 2);
/* Copy the Y plane */
src = (Uint8 *)pixels;
dst = swdata->pixels + rect->y * swdata->w + rect->x;
length = rect->w;
for (row = 0; row < rect->h; ++row) {
SDL_memcpy(dst, src, length);
src += pitch;
dst += swdata->pitches[0];
}
}
break;
case SDL_PIXELFORMAT_NV12:
case SDL_PIXELFORMAT_NV21:
{
if (rect->x == 0 && rect->y == 0 && rect->w == swdata->w && rect->h == swdata->h) {
SDL_memcpy(swdata->pixels, pixels,
(swdata->h * swdata->w) + 2* ((swdata->h + 1) /2) * ((swdata->w + 1) / 2));
} else {
Uint8 *src, *dst;
int row;
size_t length;
/* Copy the Y plane */
src = (Uint8 *) pixels;
dst = swdata->pixels + rect->y * swdata->w + rect->x;
length = rect->w;
for (row = 0; row < rect->h; ++row) {
SDL_memcpy(dst, src, length);
src += pitch;
dst += swdata->w;
}
/* Copy the next plane */
src = (Uint8 *) pixels + rect->h * pitch;
dst = swdata->pixels + swdata->h * swdata->w;
dst += 2 * ((rect->y + 1)/2) * ((swdata->w + 1) / 2) + 2 * (rect->x/2);
length = 2 * ((rect->w + 1) / 2);
for (row = 0; row < (rect->h + 1)/2; ++row) {
SDL_memcpy(dst, src, length);
src += 2 * ((pitch + 1)/2);
dst += 2 * ((swdata->w + 1)/2);
}
dst += swdata->w;
}
/* Copy the next plane */
src = (Uint8 *)pixels + rect->h * pitch;
dst = swdata->pixels + swdata->h * swdata->w;
dst += 2 * ((rect->y + 1) / 2) * ((swdata->w + 1) / 2) + 2 * (rect->x / 2);
length = 2 * (((size_t)rect->w + 1) / 2);
for (row = 0; row < (rect->h + 1) / 2; ++row) {
SDL_memcpy(dst, src, length);
src += 2 * ((pitch + 1) / 2);
dst += 2 * ((swdata->w + 1) / 2);
}
}
}
}
return 0;
}
int
SDL_SW_UpdateYUVTexturePlanar(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
const Uint8 *Yplane, int Ypitch,
const Uint8 *Uplane, int Upitch,
const Uint8 *Vplane, int Vpitch)
int SDL_SW_UpdateYUVTexturePlanar(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect,
const Uint8 *Yplane, int Ypitch,
const Uint8 *Uplane, int Upitch,
const Uint8 *Vplane, int Vpitch)
{
const Uint8 *src;
Uint8 *dst;
@ -274,12 +248,12 @@ SDL_SW_UpdateYUVTexturePlanar(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
dst = swdata->pixels + swdata->h * swdata->w +
((swdata->h + 1) / 2) * ((swdata->w + 1) / 2);
}
dst += rect->y/2 * ((swdata->w + 1)/2) + rect->x/2;
dst += rect->y / 2 * ((swdata->w + 1) / 2) + rect->x / 2;
length = (rect->w + 1) / 2;
for (row = 0; row < (rect->h + 1)/2; ++row) {
for (row = 0; row < (rect->h + 1) / 2; ++row) {
SDL_memcpy(dst, src, length);
src += Upitch;
dst += (swdata->w + 1)/2;
dst += (swdata->w + 1) / 2;
}
/* Copy the V plane */
@ -290,19 +264,19 @@ SDL_SW_UpdateYUVTexturePlanar(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
dst = swdata->pixels + swdata->h * swdata->w +
((swdata->h + 1) / 2) * ((swdata->w + 1) / 2);
}
dst += rect->y/2 * ((swdata->w + 1)/2) + rect->x/2;
dst += rect->y / 2 * ((swdata->w + 1) / 2) + rect->x / 2;
length = (rect->w + 1) / 2;
for (row = 0; row < (rect->h + 1)/2; ++row) {
for (row = 0; row < (rect->h + 1) / 2; ++row) {
SDL_memcpy(dst, src, length);
src += Vpitch;
dst += (swdata->w + 1)/2;
dst += (swdata->w + 1) / 2;
}
return 0;
}
int SDL_SW_UpdateNVTexturePlanar(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
const Uint8 *Yplane, int Ypitch,
const Uint8 *UVplane, int UVpitch)
int SDL_SW_UpdateNVTexturePlanar(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect,
const Uint8 *Yplane, int Ypitch,
const Uint8 *UVplane, int UVpitch)
{
const Uint8 *src;
Uint8 *dst;
@ -322,32 +296,28 @@ int SDL_SW_UpdateNVTexturePlanar(SDL_SW_YUVTexture * swdata, const SDL_Rect * re
/* Copy the UV or VU plane */
src = UVplane;
dst = swdata->pixels + swdata->h * swdata->w;
dst += rect->y * ((swdata->w + 1)/2) + rect->x;
dst += rect->y * ((swdata->w + 1) / 2) + rect->x;
length = (rect->w + 1) / 2;
length *= 2;
for (row = 0; row < (rect->h + 1)/2; ++row) {
for (row = 0; row < (rect->h + 1) / 2; ++row) {
SDL_memcpy(dst, src, length);
src += UVpitch;
dst += 2 * ((swdata->w + 1)/2);
dst += 2 * ((swdata->w + 1) / 2);
}
return 0;
}
int
SDL_SW_LockYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
void **pixels, int *pitch)
int SDL_SW_LockYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect,
void **pixels, int *pitch)
{
switch (swdata->format) {
case SDL_PIXELFORMAT_YV12:
case SDL_PIXELFORMAT_IYUV:
case SDL_PIXELFORMAT_NV12:
case SDL_PIXELFORMAT_NV21:
if (rect
&& (rect->x != 0 || rect->y != 0 || rect->w != swdata->w
|| rect->h != swdata->h)) {
return SDL_SetError
("YV12, IYUV, NV12, NV21 textures only support full surface locks");
if (rect && (rect->x != 0 || rect->y != 0 || rect->w != swdata->w || rect->h != swdata->h)) {
return SDL_SetError("YV12, IYUV, NV12, NV21 textures only support full surface locks");
}
break;
}
@ -361,15 +331,13 @@ SDL_SW_LockYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
return 0;
}
void
SDL_SW_UnlockYUVTexture(SDL_SW_YUVTexture * swdata)
void SDL_SW_UnlockYUVTexture(SDL_SW_YUVTexture *swdata)
{
}
int
SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture * swdata, const SDL_Rect * srcrect,
Uint32 target_format, int w, int h, void *pixels,
int pitch)
int SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture *swdata, const SDL_Rect *srcrect,
Uint32 target_format, int w, int h, void *pixels,
int pitch)
{
int stretch;
@ -407,7 +375,7 @@ SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture * swdata, const SDL_Rect * srcrect,
SDL_CreateRGBSurfaceFrom(pixels, w, h, bpp, pitch, Rmask,
Gmask, Bmask, Amask);
if (!swdata->display) {
return (-1);
return -1;
}
}
if (!swdata->stretch) {
@ -418,14 +386,14 @@ SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture * swdata, const SDL_Rect * srcrect,
SDL_CreateRGBSurface(0, swdata->w, swdata->h, bpp, Rmask,
Gmask, Bmask, Amask);
if (!swdata->stretch) {
return (-1);
return -1;
}
}
pixels = swdata->stretch->pixels;
pitch = swdata->stretch->pitch;
}
if (SDL_ConvertPixels(swdata->w, swdata->h, swdata->format,
swdata->planes[0], swdata->pitches[0],
swdata->planes[0], swdata->pitches[0],
target_format, pixels, pitch) < 0) {
return -1;
}
@ -436,8 +404,7 @@ SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture * swdata, const SDL_Rect * srcrect,
return 0;
}
void
SDL_SW_DestroyYUVTexture(SDL_SW_YUVTexture * swdata)
void SDL_SW_DestroyYUVTexture(SDL_SW_YUVTexture *swdata)
{
if (swdata) {
SDL_SIMDFree(swdata->pixels);

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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,24 +47,24 @@ struct SDL_SW_YUVTexture
typedef struct SDL_SW_YUVTexture SDL_SW_YUVTexture;
SDL_SW_YUVTexture *SDL_SW_CreateYUVTexture(Uint32 format, int w, int h);
int SDL_SW_QueryYUVTexturePixels(SDL_SW_YUVTexture * swdata, void **pixels,
int SDL_SW_QueryYUVTexturePixels(SDL_SW_YUVTexture *swdata, void **pixels,
int *pitch);
int SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
int SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect,
const void *pixels, int pitch);
int SDL_SW_UpdateYUVTexturePlanar(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
int SDL_SW_UpdateYUVTexturePlanar(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect,
const Uint8 *Yplane, int Ypitch,
const Uint8 *Uplane, int Upitch,
const Uint8 *Vplane, int Vpitch);
int SDL_SW_UpdateNVTexturePlanar(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
const Uint8 *Yplane, int Ypitch,
const Uint8 *UVplane, int UVpitch);
int SDL_SW_LockYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
int SDL_SW_UpdateNVTexturePlanar(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect,
const Uint8 *Yplane, int Ypitch,
const Uint8 *UVplane, int UVpitch);
int SDL_SW_LockYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect,
void **pixels, int *pitch);
void SDL_SW_UnlockYUVTexture(SDL_SW_YUVTexture * swdata);
int SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture * swdata, const SDL_Rect * srcrect,
void SDL_SW_UnlockYUVTexture(SDL_SW_YUVTexture *swdata);
int SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture *swdata, const SDL_Rect *srcrect,
Uint32 target_format, int w, int h, void *pixels,
int pitch);
void SDL_SW_DestroyYUVTexture(SDL_SW_YUVTexture * swdata);
void SDL_SW_DestroyYUVTexture(SDL_SW_YUVTexture *swdata);
#endif /* SDL_yuv_sw_c_h_ */

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -257,7 +257,6 @@ static const DWORD D3D9_PixelShader_YUV_BT709[] = {
0x90e40000, 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff
};
static const DWORD *D3D9_shaders[] = {
D3D9_PixelShader_YUV_JPEG,
D3D9_PixelShader_YUV_BT601,

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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,8 @@
/* D3D9 shader implementation */
typedef enum {
typedef enum
{
SHADER_YUV_JPEG,
SHADER_YUV_BT601,
SHADER_YUV_BT709,

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -42,12 +42,11 @@ using namespace Windows::Graphics::Display;
#include "SDL_render_winrt.h"
extern "C" void *
D3D11_GetCoreWindowFromSDLRenderer(SDL_Renderer * renderer)
D3D11_GetCoreWindowFromSDLRenderer(SDL_Renderer *renderer)
{
SDL_Window * sdlWindow = renderer->window;
if ( ! renderer->window ) {
SDL_Window *sdlWindow = renderer->window;
if (renderer->window == NULL) {
return NULL;
}
@ -110,7 +109,6 @@ D3D11_GetCurrentRotation()
return DXGI_MODE_ROTATION_IDENTITY;
}
#endif /* SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED */
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -28,7 +28,7 @@
extern "C" {
#endif
void * D3D11_GetCoreWindowFromSDLRenderer(SDL_Renderer * renderer);
void *D3D11_GetCoreWindowFromSDLRenderer(SDL_Renderer *renderer);
DXGI_MODE_ROTATION D3D11_GetCurrentRotation();
#ifdef __cplusplus

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -32,7 +32,6 @@
#define SDL_COMPOSE_ERROR(str) SDL_STRINGIFY_ARG(__FUNCTION__) ", " str
/* Direct3D 11.x shaders
SDL's shaders are compiled into SDL itself, to simplify distribution.
@ -52,7 +51,7 @@
- vs_4_0_level_9_1: Vertex shader for Windows 8+, including Windows RT
- ps_4_0_level_9_3: Pixel shader for Windows Phone 8
- vs_4_0_level_9_3: Vertex shader for Windows Phone 8
Shader object code was converted to a list of DWORDs via the following
*nix style command (available separately from Windows + MSVC):
@ -1905,8 +1904,7 @@ static struct
int D3D11_CreateVertexShader(ID3D11Device1 *d3dDevice, ID3D11VertexShader **vertexShader, ID3D11InputLayout **inputLayout)
{
/* Declare how the input layout for SDL's vertex shader will be setup: */
const D3D11_INPUT_ELEMENT_DESC vertexDesc[] =
{
const D3D11_INPUT_ELEMENT_DESC vertexDesc[] = {
{ "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0 },
@ -1915,23 +1913,21 @@ int D3D11_CreateVertexShader(ID3D11Device1 *d3dDevice, ID3D11VertexShader **vert
/* Load in SDL's one and only vertex shader: */
result = ID3D11Device_CreateVertexShader(d3dDevice,
D3D11_VertexShader,
sizeof(D3D11_VertexShader),
NULL,
vertexShader
);
D3D11_VertexShader,
sizeof(D3D11_VertexShader),
NULL,
vertexShader);
if (FAILED(result)) {
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateVertexShader"), result);
}
/* Create an input layout for SDL's vertex shader: */
result = ID3D11Device_CreateInputLayout(d3dDevice,
vertexDesc,
ARRAYSIZE(vertexDesc),
D3D11_VertexShader,
sizeof(D3D11_VertexShader),
inputLayout
);
vertexDesc,
ARRAYSIZE(vertexDesc),
D3D11_VertexShader,
sizeof(D3D11_VertexShader),
inputLayout);
if (FAILED(result)) {
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateInputLayout"), result);
}
@ -1943,11 +1939,10 @@ int D3D11_CreatePixelShader(ID3D11Device1 *d3dDevice, D3D11_Shader shader, ID3D1
HRESULT result;
result = ID3D11Device_CreatePixelShader(d3dDevice,
D3D11_shaders[shader].shader_data,
D3D11_shaders[shader].shader_size,
NULL,
pixelShader
);
D3D11_shaders[shader].shader_data,
D3D11_shaders[shader].shader_size,
NULL,
pixelShader);
if (FAILED(result)) {
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreatePixelShader"), result);
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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,8 @@
/* D3D11 shader implementation */
typedef enum {
typedef enum
{
SHADER_SOLID,
SHADER_RGB,
#if SDL_HAVE_YUV

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,27 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED && (defined(__XBOXONE__) || defined(__XBOXSERIES__))
#include "SDL_render_d3d12_xbox.h"
#error "This is a placeholder Xbox file, as the real one is under NDA. See README-gdk.md for more info."
#endif

View file

@ -0,0 +1,22 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 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.
*/
#error "This is a placeholder Xbox file, as the real one is under NDA. See README-gdk.md for more info."

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,69 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
/* D3D12 shader implementation */
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
typedef enum
{
SHADER_SOLID,
SHADER_RGB,
#if SDL_HAVE_YUV
SHADER_YUV_JPEG,
SHADER_YUV_BT601,
SHADER_YUV_BT709,
SHADER_NV12_JPEG,
SHADER_NV12_BT601,
SHADER_NV12_BT709,
SHADER_NV21_JPEG,
SHADER_NV21_BT601,
SHADER_NV21_BT709,
#endif
NUM_SHADERS
} D3D12_Shader;
typedef enum
{
ROOTSIG_COLOR,
ROOTSIG_TEXTURE,
#if SDL_HAVE_YUV
ROOTSIG_YUV,
ROOTSIG_NV,
#endif
NUM_ROOTSIGS
} D3D12_RootSignature;
extern void D3D12_GetVertexShader(D3D12_Shader shader, D3D12_SHADER_BYTECODE *outBytecode);
extern void D3D12_GetPixelShader(D3D12_Shader shader, D3D12_SHADER_BYTECODE *outBytecode);
extern D3D12_RootSignature D3D12_GetRootSignatureType(D3D12_Shader shader);
extern void D3D12_GetRootSignatureData(D3D12_RootSignature rootSig, D3D12_SHADER_BYTECODE *outBytecode);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -0,0 +1,29 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED && defined(__XBOXONE__)
#error "This is a placeholder Xbox file, as the real one is under NDA. See README-gdk.md for more info."
#endif /* SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED && defined(__XBOXONE__) */
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -0,0 +1,29 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED && defined(__XBOXSERIES__)
#error "This is a placeholder Xbox file, as the real one is under NDA. See README-gdk.md for more info."
#endif /* SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED && defined(__XBOXSERIES__) */
/* vi: set ts=4 sw=4 expandtab: */

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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 @@
If you need to use a GL function from the SDL video subsystem,
change its entry from SDL_PROC_UNUSED to SDL_PROC and rebuild.
*/
#define SDL_PROC_UNUSED(ret,func,params)
#define SDL_PROC_UNUSED(ret, func, params)
SDL_PROC_UNUSED(void, glAccum, (GLenum, GLfloat))
SDL_PROC_UNUSED(void, glAlphaFunc, (GLenum, GLclampf))
@ -74,21 +74,21 @@ SDL_PROC_UNUSED(void, glColor4iv, (const GLint *))
SDL_PROC_UNUSED(void, glColor4s, (GLshort, GLshort, GLshort, GLshort))
SDL_PROC_UNUSED(void, glColor4sv, (const GLshort *))
SDL_PROC(void, glColor4ub,
(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha))
SDL_PROC_UNUSED(void, glColor4ubv, (const GLubyte * v))
(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha))
SDL_PROC_UNUSED(void, glColor4ubv, (const GLubyte *v))
SDL_PROC_UNUSED(void, glColor4ui,
(GLuint red, GLuint green, GLuint blue, GLuint alpha))
SDL_PROC_UNUSED(void, glColor4uiv, (const GLuint * v))
SDL_PROC_UNUSED(void, glColor4uiv, (const GLuint *v))
SDL_PROC_UNUSED(void, glColor4us,
(GLushort red, GLushort green, GLushort blue, GLushort alpha))
SDL_PROC_UNUSED(void, glColor4usv, (const GLushort * v))
SDL_PROC_UNUSED(void, glColor4usv, (const GLushort *v))
SDL_PROC_UNUSED(void, glColorMask,
(GLboolean red, GLboolean green, GLboolean blue,
GLboolean alpha))
SDL_PROC_UNUSED(void, glColorMaterial, (GLenum face, GLenum mode))
SDL_PROC(void, glColorPointer,
(GLint size, GLenum type, GLsizei stride,
const GLvoid * pointer))
(GLint size, GLenum type, GLsizei stride,
const GLvoid *pointer))
SDL_PROC_UNUSED(void, glCopyPixels,
(GLint x, GLint y, GLsizei width, GLsizei height,
GLenum type))
@ -106,7 +106,7 @@ SDL_PROC_UNUSED(void, glCopyTexSubImage2D,
GLint x, GLint y, GLsizei width, GLsizei height))
SDL_PROC_UNUSED(void, glCullFace, (GLenum mode))
SDL_PROC_UNUSED(void, glDeleteLists, (GLuint list, GLsizei range))
SDL_PROC(void, glDeleteTextures, (GLsizei n, const GLuint * textures))
SDL_PROC(void, glDeleteTextures, (GLsizei n, const GLuint *textures))
SDL_PROC(void, glDepthFunc, (GLenum func))
SDL_PROC_UNUSED(void, glDepthMask, (GLboolean flag))
SDL_PROC_UNUSED(void, glDepthRange, (GLclampd zNear, GLclampd zFar))
@ -116,141 +116,141 @@ SDL_PROC(void, glDrawArrays, (GLenum mode, GLint first, GLsizei count))
SDL_PROC_UNUSED(void, glDrawBuffer, (GLenum mode))
SDL_PROC_UNUSED(void, glDrawElements,
(GLenum mode, GLsizei count, GLenum type,
const GLvoid * indices))
const GLvoid *indices))
SDL_PROC(void, glDrawPixels,
(GLsizei width, GLsizei height, GLenum format, GLenum type,
const GLvoid * pixels))
const GLvoid *pixels))
SDL_PROC_UNUSED(void, glEdgeFlag, (GLboolean flag))
SDL_PROC_UNUSED(void, glEdgeFlagPointer,
(GLsizei stride, const GLvoid * pointer))
SDL_PROC_UNUSED(void, glEdgeFlagv, (const GLboolean * flag))
(GLsizei stride, const GLvoid *pointer))
SDL_PROC_UNUSED(void, glEdgeFlagv, (const GLboolean *flag))
SDL_PROC(void, glEnable, (GLenum cap))
SDL_PROC(void, glEnableClientState, (GLenum array))
SDL_PROC(void, glEnd, (void))
SDL_PROC_UNUSED(void, glEndList, (void))
SDL_PROC_UNUSED(void, glEvalCoord1d, (GLdouble u))
SDL_PROC_UNUSED(void, glEvalCoord1dv, (const GLdouble * u))
SDL_PROC_UNUSED(void, glEvalCoord1dv, (const GLdouble *u))
SDL_PROC_UNUSED(void, glEvalCoord1f, (GLfloat u))
SDL_PROC_UNUSED(void, glEvalCoord1fv, (const GLfloat * u))
SDL_PROC_UNUSED(void, glEvalCoord1fv, (const GLfloat *u))
SDL_PROC_UNUSED(void, glEvalCoord2d, (GLdouble u, GLdouble v))
SDL_PROC_UNUSED(void, glEvalCoord2dv, (const GLdouble * u))
SDL_PROC_UNUSED(void, glEvalCoord2dv, (const GLdouble *u))
SDL_PROC_UNUSED(void, glEvalCoord2f, (GLfloat u, GLfloat v))
SDL_PROC_UNUSED(void, glEvalCoord2fv, (const GLfloat * u))
SDL_PROC_UNUSED(void, glEvalCoord2fv, (const GLfloat *u))
SDL_PROC_UNUSED(void, glEvalMesh1, (GLenum mode, GLint i1, GLint i2))
SDL_PROC_UNUSED(void, glEvalMesh2,
(GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2))
SDL_PROC_UNUSED(void, glEvalPoint1, (GLint i))
SDL_PROC_UNUSED(void, glEvalPoint2, (GLint i, GLint j))
SDL_PROC_UNUSED(void, glFeedbackBuffer,
(GLsizei size, GLenum type, GLfloat * buffer))
(GLsizei size, GLenum type, GLfloat *buffer))
SDL_PROC_UNUSED(void, glFinish, (void))
SDL_PROC_UNUSED(void, glFlush, (void))
SDL_PROC_UNUSED(void, glFogf, (GLenum pname, GLfloat param))
SDL_PROC_UNUSED(void, glFogfv, (GLenum pname, const GLfloat * params))
SDL_PROC_UNUSED(void, glFogfv, (GLenum pname, const GLfloat *params))
SDL_PROC_UNUSED(void, glFogi, (GLenum pname, GLint param))
SDL_PROC_UNUSED(void, glFogiv, (GLenum pname, const GLint * params))
SDL_PROC_UNUSED(void, glFogiv, (GLenum pname, const GLint *params))
SDL_PROC_UNUSED(void, glFrontFace, (GLenum mode))
SDL_PROC_UNUSED(void, glFrustum,
(GLdouble left, GLdouble right, GLdouble bottom,
GLdouble top, GLdouble zNear, GLdouble zFar))
SDL_PROC_UNUSED(GLuint, glGenLists, (GLsizei range))
SDL_PROC(void, glGenTextures, (GLsizei n, GLuint * textures))
SDL_PROC_UNUSED(void, glGetBooleanv, (GLenum pname, GLboolean * params))
SDL_PROC_UNUSED(void, glGetClipPlane, (GLenum plane, GLdouble * equation))
SDL_PROC_UNUSED(void, glGetDoublev, (GLenum pname, GLdouble * params))
SDL_PROC(void, glGenTextures, (GLsizei n, GLuint *textures))
SDL_PROC_UNUSED(void, glGetBooleanv, (GLenum pname, GLboolean *params))
SDL_PROC_UNUSED(void, glGetClipPlane, (GLenum plane, GLdouble *equation))
SDL_PROC_UNUSED(void, glGetDoublev, (GLenum pname, GLdouble *params))
SDL_PROC(GLenum, glGetError, (void))
SDL_PROC(void, glGetFloatv, (GLenum pname, GLfloat * params))
SDL_PROC(void, glGetIntegerv, (GLenum pname, GLint * params))
SDL_PROC(void, glGetFloatv, (GLenum pname, GLfloat *params))
SDL_PROC(void, glGetIntegerv, (GLenum pname, GLint *params))
SDL_PROC_UNUSED(void, glGetLightfv,
(GLenum light, GLenum pname, GLfloat * params))
(GLenum light, GLenum pname, GLfloat *params))
SDL_PROC_UNUSED(void, glGetLightiv,
(GLenum light, GLenum pname, GLint * params))
SDL_PROC_UNUSED(void, glGetMapdv, (GLenum target, GLenum query, GLdouble * v))
SDL_PROC_UNUSED(void, glGetMapfv, (GLenum target, GLenum query, GLfloat * v))
SDL_PROC_UNUSED(void, glGetMapiv, (GLenum target, GLenum query, GLint * v))
(GLenum light, GLenum pname, GLint *params))
SDL_PROC_UNUSED(void, glGetMapdv, (GLenum target, GLenum query, GLdouble *v))
SDL_PROC_UNUSED(void, glGetMapfv, (GLenum target, GLenum query, GLfloat *v))
SDL_PROC_UNUSED(void, glGetMapiv, (GLenum target, GLenum query, GLint *v))
SDL_PROC_UNUSED(void, glGetMaterialfv,
(GLenum face, GLenum pname, GLfloat * params))
(GLenum face, GLenum pname, GLfloat *params))
SDL_PROC_UNUSED(void, glGetMaterialiv,
(GLenum face, GLenum pname, GLint * params))
SDL_PROC_UNUSED(void, glGetPixelMapfv, (GLenum map, GLfloat * values))
SDL_PROC_UNUSED(void, glGetPixelMapuiv, (GLenum map, GLuint * values))
SDL_PROC_UNUSED(void, glGetPixelMapusv, (GLenum map, GLushort * values))
SDL_PROC(void, glGetPointerv, (GLenum pname, GLvoid * *params))
(GLenum face, GLenum pname, GLint *params))
SDL_PROC_UNUSED(void, glGetPixelMapfv, (GLenum map, GLfloat *values))
SDL_PROC_UNUSED(void, glGetPixelMapuiv, (GLenum map, GLuint *values))
SDL_PROC_UNUSED(void, glGetPixelMapusv, (GLenum map, GLushort *values))
SDL_PROC(void, glGetPointerv, (GLenum pname, GLvoid **params))
SDL_PROC_UNUSED(void, glGetPolygonStipple, (GLubyte * mask))
SDL_PROC(const GLubyte *, glGetString, (GLenum name))
SDL_PROC_UNUSED(void, glGetTexEnvfv,
(GLenum target, GLenum pname, GLfloat * params))
(GLenum target, GLenum pname, GLfloat *params))
SDL_PROC_UNUSED(void, glGetTexEnviv,
(GLenum target, GLenum pname, GLint * params))
(GLenum target, GLenum pname, GLint *params))
SDL_PROC_UNUSED(void, glGetTexGendv,
(GLenum coord, GLenum pname, GLdouble * params))
(GLenum coord, GLenum pname, GLdouble *params))
SDL_PROC_UNUSED(void, glGetTexGenfv,
(GLenum coord, GLenum pname, GLfloat * params))
(GLenum coord, GLenum pname, GLfloat *params))
SDL_PROC_UNUSED(void, glGetTexGeniv,
(GLenum coord, GLenum pname, GLint * params))
(GLenum coord, GLenum pname, GLint *params))
SDL_PROC_UNUSED(void, glGetTexImage,
(GLenum target, GLint level, GLenum format, GLenum type,
GLvoid * pixels))
GLvoid *pixels))
SDL_PROC_UNUSED(void, glGetTexLevelParameterfv,
(GLenum target, GLint level, GLenum pname, GLfloat * params))
(GLenum target, GLint level, GLenum pname, GLfloat *params))
SDL_PROC_UNUSED(void, glGetTexLevelParameteriv,
(GLenum target, GLint level, GLenum pname, GLint * params))
(GLenum target, GLint level, GLenum pname, GLint *params))
SDL_PROC_UNUSED(void, glGetTexParameterfv,
(GLenum target, GLenum pname, GLfloat * params))
(GLenum target, GLenum pname, GLfloat *params))
SDL_PROC_UNUSED(void, glGetTexParameteriv,
(GLenum target, GLenum pname, GLint * params))
(GLenum target, GLenum pname, GLint *params))
SDL_PROC_UNUSED(void, glHint, (GLenum target, GLenum mode))
SDL_PROC_UNUSED(void, glIndexMask, (GLuint mask))
SDL_PROC_UNUSED(void, glIndexPointer,
(GLenum type, GLsizei stride, const GLvoid * pointer))
(GLenum type, GLsizei stride, const GLvoid *pointer))
SDL_PROC_UNUSED(void, glIndexd, (GLdouble c))
SDL_PROC_UNUSED(void, glIndexdv, (const GLdouble * c))
SDL_PROC_UNUSED(void, glIndexdv, (const GLdouble *c))
SDL_PROC_UNUSED(void, glIndexf, (GLfloat c))
SDL_PROC_UNUSED(void, glIndexfv, (const GLfloat * c))
SDL_PROC_UNUSED(void, glIndexfv, (const GLfloat *c))
SDL_PROC_UNUSED(void, glIndexi, (GLint c))
SDL_PROC_UNUSED(void, glIndexiv, (const GLint * c))
SDL_PROC_UNUSED(void, glIndexiv, (const GLint *c))
SDL_PROC_UNUSED(void, glIndexs, (GLshort c))
SDL_PROC_UNUSED(void, glIndexsv, (const GLshort * c))
SDL_PROC_UNUSED(void, glIndexsv, (const GLshort *c))
SDL_PROC_UNUSED(void, glIndexub, (GLubyte c))
SDL_PROC_UNUSED(void, glIndexubv, (const GLubyte * c))
SDL_PROC_UNUSED(void, glIndexubv, (const GLubyte *c))
SDL_PROC_UNUSED(void, glInitNames, (void))
SDL_PROC_UNUSED(void, glInterleavedArrays,
(GLenum format, GLsizei stride, const GLvoid * pointer))
(GLenum format, GLsizei stride, const GLvoid *pointer))
SDL_PROC_UNUSED(GLboolean, glIsEnabled, (GLenum cap))
SDL_PROC_UNUSED(GLboolean, glIsList, (GLuint list))
SDL_PROC_UNUSED(GLboolean, glIsTexture, (GLuint texture))
SDL_PROC_UNUSED(void, glLightModelf, (GLenum pname, GLfloat param))
SDL_PROC_UNUSED(void, glLightModelfv, (GLenum pname, const GLfloat * params))
SDL_PROC_UNUSED(void, glLightModelfv, (GLenum pname, const GLfloat *params))
SDL_PROC_UNUSED(void, glLightModeli, (GLenum pname, GLint param))
SDL_PROC_UNUSED(void, glLightModeliv, (GLenum pname, const GLint * params))
SDL_PROC_UNUSED(void, glLightModeliv, (GLenum pname, const GLint *params))
SDL_PROC_UNUSED(void, glLightf, (GLenum light, GLenum pname, GLfloat param))
SDL_PROC_UNUSED(void, glLightfv,
(GLenum light, GLenum pname, const GLfloat * params))
(GLenum light, GLenum pname, const GLfloat *params))
SDL_PROC_UNUSED(void, glLighti, (GLenum light, GLenum pname, GLint param))
SDL_PROC_UNUSED(void, glLightiv,
(GLenum light, GLenum pname, const GLint * params))
(GLenum light, GLenum pname, const GLint *params))
SDL_PROC_UNUSED(void, glLineStipple, (GLint factor, GLushort pattern))
SDL_PROC(void, glLineWidth, (GLfloat width))
SDL_PROC_UNUSED(void, glListBase, (GLuint base))
SDL_PROC(void, glLoadIdentity, (void))
SDL_PROC_UNUSED(void, glLoadMatrixd, (const GLdouble * m))
SDL_PROC_UNUSED(void, glLoadMatrixf, (const GLfloat * m))
SDL_PROC_UNUSED(void, glLoadMatrixd, (const GLdouble *m))
SDL_PROC_UNUSED(void, glLoadMatrixf, (const GLfloat *m))
SDL_PROC_UNUSED(void, glLoadName, (GLuint name))
SDL_PROC_UNUSED(void, glLogicOp, (GLenum opcode))
SDL_PROC_UNUSED(void, glMap1d,
(GLenum target, GLdouble u1, GLdouble u2, GLint stride,
GLint order, const GLdouble * points))
GLint order, const GLdouble *points))
SDL_PROC_UNUSED(void, glMap1f,
(GLenum target, GLfloat u1, GLfloat u2, GLint stride,
GLint order, const GLfloat * points))
GLint order, const GLfloat *points))
SDL_PROC_UNUSED(void, glMap2d,
(GLenum target, GLdouble u1, GLdouble u2, GLint ustride,
GLint uorder, GLdouble v1, GLdouble v2, GLint vstride,
GLint vorder, const GLdouble * points))
GLint vorder, const GLdouble *points))
SDL_PROC_UNUSED(void, glMap2f,
(GLenum target, GLfloat u1, GLfloat u2, GLint ustride,
GLint uorder, GLfloat v1, GLfloat v2, GLint vstride,
GLint vorder, const GLfloat * points))
GLint vorder, const GLfloat *points))
SDL_PROC_UNUSED(void, glMapGrid1d, (GLint un, GLdouble u1, GLdouble u2))
SDL_PROC_UNUSED(void, glMapGrid1f, (GLint un, GLfloat u1, GLfloat u2))
SDL_PROC_UNUSED(void, glMapGrid2d,
@ -261,36 +261,36 @@ SDL_PROC_UNUSED(void, glMapGrid2f,
GLfloat v2))
SDL_PROC_UNUSED(void, glMaterialf, (GLenum face, GLenum pname, GLfloat param))
SDL_PROC_UNUSED(void, glMaterialfv,
(GLenum face, GLenum pname, const GLfloat * params))
(GLenum face, GLenum pname, const GLfloat *params))
SDL_PROC_UNUSED(void, glMateriali, (GLenum face, GLenum pname, GLint param))
SDL_PROC_UNUSED(void, glMaterialiv,
(GLenum face, GLenum pname, const GLint * params))
(GLenum face, GLenum pname, const GLint *params))
SDL_PROC(void, glMatrixMode, (GLenum mode))
SDL_PROC_UNUSED(void, glMultMatrixd, (const GLdouble * m))
SDL_PROC_UNUSED(void, glMultMatrixf, (const GLfloat * m))
SDL_PROC_UNUSED(void, glMultMatrixd, (const GLdouble *m))
SDL_PROC_UNUSED(void, glMultMatrixf, (const GLfloat *m))
SDL_PROC_UNUSED(void, glNewList, (GLuint list, GLenum mode))
SDL_PROC_UNUSED(void, glNormal3b, (GLbyte nx, GLbyte ny, GLbyte nz))
SDL_PROC_UNUSED(void, glNormal3bv, (const GLbyte * v))
SDL_PROC_UNUSED(void, glNormal3bv, (const GLbyte *v))
SDL_PROC_UNUSED(void, glNormal3d, (GLdouble nx, GLdouble ny, GLdouble nz))
SDL_PROC_UNUSED(void, glNormal3dv, (const GLdouble * v))
SDL_PROC_UNUSED(void, glNormal3dv, (const GLdouble *v))
SDL_PROC_UNUSED(void, glNormal3f, (GLfloat nx, GLfloat ny, GLfloat nz))
SDL_PROC_UNUSED(void, glNormal3fv, (const GLfloat * v))
SDL_PROC_UNUSED(void, glNormal3fv, (const GLfloat *v))
SDL_PROC_UNUSED(void, glNormal3i, (GLint nx, GLint ny, GLint nz))
SDL_PROC_UNUSED(void, glNormal3iv, (const GLint * v))
SDL_PROC_UNUSED(void, glNormal3iv, (const GLint *v))
SDL_PROC_UNUSED(void, glNormal3s, (GLshort nx, GLshort ny, GLshort nz))
SDL_PROC_UNUSED(void, glNormal3sv, (const GLshort * v))
SDL_PROC_UNUSED(void, glNormal3sv, (const GLshort *v))
SDL_PROC_UNUSED(void, glNormalPointer,
(GLenum type, GLsizei stride, const GLvoid * pointer))
(GLenum type, GLsizei stride, const GLvoid *pointer))
SDL_PROC(void, glOrtho,
(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top,
GLdouble zNear, GLdouble zFar))
SDL_PROC_UNUSED(void, glPassThrough, (GLfloat token))
SDL_PROC_UNUSED(void, glPixelMapfv,
(GLenum map, GLsizei mapsize, const GLfloat * values))
(GLenum map, GLsizei mapsize, const GLfloat *values))
SDL_PROC_UNUSED(void, glPixelMapuiv,
(GLenum map, GLsizei mapsize, const GLuint * values))
(GLenum map, GLsizei mapsize, const GLuint *values))
SDL_PROC_UNUSED(void, glPixelMapusv,
(GLenum map, GLsizei mapsize, const GLushort * values))
(GLenum map, GLsizei mapsize, const GLushort *values))
SDL_PROC_UNUSED(void, glPixelStoref, (GLenum pname, GLfloat param))
SDL_PROC(void, glPixelStorei, (GLenum pname, GLint param))
SDL_PROC_UNUSED(void, glPixelTransferf, (GLenum pname, GLfloat param))
@ -299,180 +299,180 @@ SDL_PROC_UNUSED(void, glPixelZoom, (GLfloat xfactor, GLfloat yfactor))
SDL_PROC(void, glPointSize, (GLfloat size))
SDL_PROC_UNUSED(void, glPolygonMode, (GLenum face, GLenum mode))
SDL_PROC_UNUSED(void, glPolygonOffset, (GLfloat factor, GLfloat units))
SDL_PROC_UNUSED(void, glPolygonStipple, (const GLubyte * mask))
SDL_PROC_UNUSED(void, glPolygonStipple, (const GLubyte *mask))
SDL_PROC_UNUSED(void, glPopAttrib, (void))
SDL_PROC_UNUSED(void, glPopClientAttrib, (void))
SDL_PROC_UNUSED(void, glPopMatrix, (void))
SDL_PROC_UNUSED(void, glPopName, (void))
SDL_PROC_UNUSED(void, glPrioritizeTextures,
(GLsizei n, const GLuint * textures,
const GLclampf * priorities))
(GLsizei n, const GLuint *textures,
const GLclampf *priorities))
SDL_PROC_UNUSED(void, glPushAttrib, (GLbitfield mask))
SDL_PROC_UNUSED(void, glPushClientAttrib, (GLbitfield mask))
SDL_PROC_UNUSED(void, glPushMatrix, (void))
SDL_PROC_UNUSED(void, glPushName, (GLuint name))
SDL_PROC_UNUSED(void, glRasterPos2d, (GLdouble x, GLdouble y))
SDL_PROC_UNUSED(void, glRasterPos2dv, (const GLdouble * v))
SDL_PROC_UNUSED(void, glRasterPos2dv, (const GLdouble *v))
SDL_PROC_UNUSED(void, glRasterPos2f, (GLfloat x, GLfloat y))
SDL_PROC_UNUSED(void, glRasterPos2fv, (const GLfloat * v))
SDL_PROC_UNUSED(void, glRasterPos2fv, (const GLfloat *v))
SDL_PROC(void, glRasterPos2i, (GLint x, GLint y))
SDL_PROC_UNUSED(void, glRasterPos2iv, (const GLint * v))
SDL_PROC_UNUSED(void, glRasterPos2iv, (const GLint *v))
SDL_PROC_UNUSED(void, glRasterPos2s, (GLshort x, GLshort y))
SDL_PROC_UNUSED(void, glRasterPos2sv, (const GLshort * v))
SDL_PROC_UNUSED(void, glRasterPos2sv, (const GLshort *v))
SDL_PROC_UNUSED(void, glRasterPos3d, (GLdouble x, GLdouble y, GLdouble z))
SDL_PROC_UNUSED(void, glRasterPos3dv, (const GLdouble * v))
SDL_PROC_UNUSED(void, glRasterPos3dv, (const GLdouble *v))
SDL_PROC_UNUSED(void, glRasterPos3f, (GLfloat x, GLfloat y, GLfloat z))
SDL_PROC_UNUSED(void, glRasterPos3fv, (const GLfloat * v))
SDL_PROC_UNUSED(void, glRasterPos3fv, (const GLfloat *v))
SDL_PROC_UNUSED(void, glRasterPos3i, (GLint x, GLint y, GLint z))
SDL_PROC_UNUSED(void, glRasterPos3iv, (const GLint * v))
SDL_PROC_UNUSED(void, glRasterPos3iv, (const GLint *v))
SDL_PROC_UNUSED(void, glRasterPos3s, (GLshort x, GLshort y, GLshort z))
SDL_PROC_UNUSED(void, glRasterPos3sv, (const GLshort * v))
SDL_PROC_UNUSED(void, glRasterPos3sv, (const GLshort *v))
SDL_PROC_UNUSED(void, glRasterPos4d,
(GLdouble x, GLdouble y, GLdouble z, GLdouble w))
SDL_PROC_UNUSED(void, glRasterPos4dv, (const GLdouble * v))
SDL_PROC_UNUSED(void, glRasterPos4dv, (const GLdouble *v))
SDL_PROC_UNUSED(void, glRasterPos4f,
(GLfloat x, GLfloat y, GLfloat z, GLfloat w))
SDL_PROC_UNUSED(void, glRasterPos4fv, (const GLfloat * v))
SDL_PROC_UNUSED(void, glRasterPos4fv, (const GLfloat *v))
SDL_PROC_UNUSED(void, glRasterPos4i, (GLint x, GLint y, GLint z, GLint w))
SDL_PROC_UNUSED(void, glRasterPos4iv, (const GLint * v))
SDL_PROC_UNUSED(void, glRasterPos4iv, (const GLint *v))
SDL_PROC_UNUSED(void, glRasterPos4s,
(GLshort x, GLshort y, GLshort z, GLshort w))
SDL_PROC_UNUSED(void, glRasterPos4sv, (const GLshort * v))
SDL_PROC_UNUSED(void, glRasterPos4sv, (const GLshort *v))
SDL_PROC(void, glReadBuffer, (GLenum mode))
SDL_PROC(void, glReadPixels,
(GLint x, GLint y, GLsizei width, GLsizei height,
GLenum format, GLenum type, GLvoid * pixels))
GLenum format, GLenum type, GLvoid *pixels))
SDL_PROC_UNUSED(void, glRectd,
(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2))
SDL_PROC_UNUSED(void, glRectdv, (const GLdouble * v1, const GLdouble * v2))
SDL_PROC_UNUSED(void, glRectdv, (const GLdouble *v1, const GLdouble *v2))
SDL_PROC(void, glRectf,
(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2))
SDL_PROC_UNUSED(void, glRectfv, (const GLfloat * v1, const GLfloat * v2))
(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2))
SDL_PROC_UNUSED(void, glRectfv, (const GLfloat *v1, const GLfloat *v2))
SDL_PROC_UNUSED(void, glRecti, (GLint x1, GLint y1, GLint x2, GLint y2))
SDL_PROC_UNUSED(void, glRectiv, (const GLint * v1, const GLint * v2))
SDL_PROC_UNUSED(void, glRectiv, (const GLint *v1, const GLint *v2))
SDL_PROC_UNUSED(void, glRects,
(GLshort x1, GLshort y1, GLshort x2, GLshort y2))
SDL_PROC_UNUSED(void, glRectsv, (const GLshort * v1, const GLshort * v2))
SDL_PROC_UNUSED(void, glRectsv, (const GLshort *v1, const GLshort *v2))
SDL_PROC_UNUSED(GLint, glRenderMode, (GLenum mode))
SDL_PROC_UNUSED(void, glRotated,
(GLdouble angle, GLdouble x, GLdouble y, GLdouble z))
SDL_PROC(void, glRotatef,
(GLfloat angle, GLfloat x, GLfloat y, GLfloat z))
(GLfloat angle, GLfloat x, GLfloat y, GLfloat z))
SDL_PROC_UNUSED(void, glScaled, (GLdouble x, GLdouble y, GLdouble z))
SDL_PROC_UNUSED(void, glScalef, (GLfloat x, GLfloat y, GLfloat z))
SDL_PROC(void, glScissor, (GLint x, GLint y, GLsizei width, GLsizei height))
SDL_PROC_UNUSED(void, glSelectBuffer, (GLsizei size, GLuint * buffer))
SDL_PROC_UNUSED(void, glSelectBuffer, (GLsizei size, GLuint *buffer))
SDL_PROC(void, glShadeModel, (GLenum mode))
SDL_PROC_UNUSED(void, glStencilFunc, (GLenum func, GLint ref, GLuint mask))
SDL_PROC_UNUSED(void, glStencilMask, (GLuint mask))
SDL_PROC_UNUSED(void, glStencilOp, (GLenum fail, GLenum zfail, GLenum zpass))
SDL_PROC_UNUSED(void, glTexCoord1d, (GLdouble s))
SDL_PROC_UNUSED(void, glTexCoord1dv, (const GLdouble * v))
SDL_PROC_UNUSED(void, glTexCoord1dv, (const GLdouble *v))
SDL_PROC_UNUSED(void, glTexCoord1f, (GLfloat s))
SDL_PROC_UNUSED(void, glTexCoord1fv, (const GLfloat * v))
SDL_PROC_UNUSED(void, glTexCoord1fv, (const GLfloat *v))
SDL_PROC_UNUSED(void, glTexCoord1i, (GLint s))
SDL_PROC_UNUSED(void, glTexCoord1iv, (const GLint * v))
SDL_PROC_UNUSED(void, glTexCoord1iv, (const GLint *v))
SDL_PROC_UNUSED(void, glTexCoord1s, (GLshort s))
SDL_PROC_UNUSED(void, glTexCoord1sv, (const GLshort * v))
SDL_PROC_UNUSED(void, glTexCoord1sv, (const GLshort *v))
SDL_PROC_UNUSED(void, glTexCoord2d, (GLdouble s, GLdouble t))
SDL_PROC_UNUSED(void, glTexCoord2dv, (const GLdouble * v))
SDL_PROC_UNUSED(void, glTexCoord2dv, (const GLdouble *v))
SDL_PROC(void, glTexCoord2f, (GLfloat s, GLfloat t))
SDL_PROC_UNUSED(void, glTexCoord2fv, (const GLfloat * v))
SDL_PROC_UNUSED(void, glTexCoord2fv, (const GLfloat *v))
SDL_PROC_UNUSED(void, glTexCoord2i, (GLint s, GLint t))
SDL_PROC_UNUSED(void, glTexCoord2iv, (const GLint * v))
SDL_PROC_UNUSED(void, glTexCoord2iv, (const GLint *v))
SDL_PROC_UNUSED(void, glTexCoord2s, (GLshort s, GLshort t))
SDL_PROC_UNUSED(void, glTexCoord2sv, (const GLshort * v))
SDL_PROC_UNUSED(void, glTexCoord2sv, (const GLshort *v))
SDL_PROC_UNUSED(void, glTexCoord3d, (GLdouble s, GLdouble t, GLdouble r))
SDL_PROC_UNUSED(void, glTexCoord3dv, (const GLdouble * v))
SDL_PROC_UNUSED(void, glTexCoord3dv, (const GLdouble *v))
SDL_PROC_UNUSED(void, glTexCoord3f, (GLfloat s, GLfloat t, GLfloat r))
SDL_PROC_UNUSED(void, glTexCoord3fv, (const GLfloat * v))
SDL_PROC_UNUSED(void, glTexCoord3fv, (const GLfloat *v))
SDL_PROC_UNUSED(void, glTexCoord3i, (GLint s, GLint t, GLint r))
SDL_PROC_UNUSED(void, glTexCoord3iv, (const GLint * v))
SDL_PROC_UNUSED(void, glTexCoord3iv, (const GLint *v))
SDL_PROC_UNUSED(void, glTexCoord3s, (GLshort s, GLshort t, GLshort r))
SDL_PROC_UNUSED(void, glTexCoord3sv, (const GLshort * v))
SDL_PROC_UNUSED(void, glTexCoord3sv, (const GLshort *v))
SDL_PROC_UNUSED(void, glTexCoord4d,
(GLdouble s, GLdouble t, GLdouble r, GLdouble q))
SDL_PROC_UNUSED(void, glTexCoord4dv, (const GLdouble * v))
SDL_PROC_UNUSED(void, glTexCoord4dv, (const GLdouble *v))
SDL_PROC_UNUSED(void, glTexCoord4f,
(GLfloat s, GLfloat t, GLfloat r, GLfloat q))
SDL_PROC_UNUSED(void, glTexCoord4fv, (const GLfloat * v))
SDL_PROC_UNUSED(void, glTexCoord4fv, (const GLfloat *v))
SDL_PROC_UNUSED(void, glTexCoord4i, (GLint s, GLint t, GLint r, GLint q))
SDL_PROC_UNUSED(void, glTexCoord4iv, (const GLint * v))
SDL_PROC_UNUSED(void, glTexCoord4iv, (const GLint *v))
SDL_PROC_UNUSED(void, glTexCoord4s,
(GLshort s, GLshort t, GLshort r, GLshort q))
SDL_PROC_UNUSED(void, glTexCoord4sv, (const GLshort * v))
SDL_PROC_UNUSED(void, glTexCoord4sv, (const GLshort *v))
SDL_PROC(void, glTexCoordPointer,
(GLint size, GLenum type, GLsizei stride,
const GLvoid * pointer))
(GLint size, GLenum type, GLsizei stride,
const GLvoid *pointer))
SDL_PROC(void, glTexEnvf, (GLenum target, GLenum pname, GLfloat param))
SDL_PROC_UNUSED(void, glTexEnvfv,
(GLenum target, GLenum pname, const GLfloat * params))
(GLenum target, GLenum pname, const GLfloat *params))
SDL_PROC_UNUSED(void, glTexEnvi, (GLenum target, GLenum pname, GLint param))
SDL_PROC_UNUSED(void, glTexEnviv,
(GLenum target, GLenum pname, const GLint * params))
(GLenum target, GLenum pname, const GLint *params))
SDL_PROC_UNUSED(void, glTexGend, (GLenum coord, GLenum pname, GLdouble param))
SDL_PROC_UNUSED(void, glTexGendv,
(GLenum coord, GLenum pname, const GLdouble * params))
(GLenum coord, GLenum pname, const GLdouble *params))
SDL_PROC_UNUSED(void, glTexGenf, (GLenum coord, GLenum pname, GLfloat param))
SDL_PROC_UNUSED(void, glTexGenfv,
(GLenum coord, GLenum pname, const GLfloat * params))
(GLenum coord, GLenum pname, const GLfloat *params))
SDL_PROC_UNUSED(void, glTexGeni, (GLenum coord, GLenum pname, GLint param))
SDL_PROC_UNUSED(void, glTexGeniv,
(GLenum coord, GLenum pname, const GLint * params))
(GLenum coord, GLenum pname, const GLint *params))
SDL_PROC_UNUSED(void, glTexImage1D,
(GLenum target, GLint level, GLint internalformat,
GLsizei width, GLint border, GLenum format, GLenum type,
const GLvoid * pixels))
const GLvoid *pixels))
SDL_PROC(void, glTexImage2D,
(GLenum target, GLint level, GLint internalformat, GLsizei width,
GLsizei height, GLint border, GLenum format, GLenum type,
const GLvoid * pixels))
const GLvoid *pixels))
SDL_PROC_UNUSED(void, glTexParameterf,
(GLenum target, GLenum pname, GLfloat param))
SDL_PROC_UNUSED(void, glTexParameterfv,
(GLenum target, GLenum pname, const GLfloat * params))
(GLenum target, GLenum pname, const GLfloat *params))
SDL_PROC(void, glTexParameteri, (GLenum target, GLenum pname, GLint param))
SDL_PROC_UNUSED(void, glTexParameteriv,
(GLenum target, GLenum pname, const GLint * params))
(GLenum target, GLenum pname, const GLint *params))
SDL_PROC_UNUSED(void, glTexSubImage1D,
(GLenum target, GLint level, GLint xoffset, GLsizei width,
GLenum format, GLenum type, const GLvoid * pixels))
GLenum format, GLenum type, const GLvoid *pixels))
SDL_PROC(void, glTexSubImage2D,
(GLenum target, GLint level, GLint xoffset, GLint yoffset,
GLsizei width, GLsizei height, GLenum format, GLenum type,
const GLvoid * pixels))
const GLvoid *pixels))
SDL_PROC_UNUSED(void, glTranslated, (GLdouble x, GLdouble y, GLdouble z))
SDL_PROC_UNUSED(void, glTranslatef, (GLfloat x, GLfloat y, GLfloat z))
SDL_PROC_UNUSED(void, glVertex2d, (GLdouble x, GLdouble y))
SDL_PROC_UNUSED(void, glVertex2dv, (const GLdouble * v))
SDL_PROC_UNUSED(void, glVertex2dv, (const GLdouble *v))
SDL_PROC(void, glVertex2f, (GLfloat x, GLfloat y))
SDL_PROC_UNUSED(void, glVertex2fv, (const GLfloat * v))
SDL_PROC_UNUSED(void, glVertex2fv, (const GLfloat *v))
SDL_PROC_UNUSED(void, glVertex2i, (GLint x, GLint y))
SDL_PROC_UNUSED(void, glVertex2iv, (const GLint * v))
SDL_PROC_UNUSED(void, glVertex2iv, (const GLint *v))
SDL_PROC_UNUSED(void, glVertex2s, (GLshort x, GLshort y))
SDL_PROC_UNUSED(void, glVertex2sv, (const GLshort * v))
SDL_PROC_UNUSED(void, glVertex2sv, (const GLshort *v))
SDL_PROC_UNUSED(void, glVertex3d, (GLdouble x, GLdouble y, GLdouble z))
SDL_PROC_UNUSED(void, glVertex3dv, (const GLdouble * v))
SDL_PROC_UNUSED(void, glVertex3dv, (const GLdouble *v))
SDL_PROC_UNUSED(void, glVertex3f, (GLfloat x, GLfloat y, GLfloat z))
SDL_PROC(void, glVertex3fv, (const GLfloat * v))
SDL_PROC(void, glVertex3fv, (const GLfloat *v))
SDL_PROC_UNUSED(void, glVertex3i, (GLint x, GLint y, GLint z))
SDL_PROC_UNUSED(void, glVertex3iv, (const GLint * v))
SDL_PROC_UNUSED(void, glVertex3iv, (const GLint *v))
SDL_PROC_UNUSED(void, glVertex3s, (GLshort x, GLshort y, GLshort z))
SDL_PROC_UNUSED(void, glVertex3sv, (const GLshort * v))
SDL_PROC_UNUSED(void, glVertex3sv, (const GLshort *v))
SDL_PROC_UNUSED(void, glVertex4d,
(GLdouble x, GLdouble y, GLdouble z, GLdouble w))
SDL_PROC_UNUSED(void, glVertex4dv, (const GLdouble * v))
SDL_PROC_UNUSED(void, glVertex4dv, (const GLdouble *v))
SDL_PROC_UNUSED(void, glVertex4f,
(GLfloat x, GLfloat y, GLfloat z, GLfloat w))
SDL_PROC_UNUSED(void, glVertex4fv, (const GLfloat * v))
SDL_PROC_UNUSED(void, glVertex4fv, (const GLfloat *v))
SDL_PROC_UNUSED(void, glVertex4i, (GLint x, GLint y, GLint z, GLint w))
SDL_PROC_UNUSED(void, glVertex4iv, (const GLint * v))
SDL_PROC_UNUSED(void, glVertex4iv, (const GLint *v))
SDL_PROC_UNUSED(void, glVertex4s,
(GLshort x, GLshort y, GLshort z, GLshort w))
SDL_PROC_UNUSED(void, glVertex4sv, (const GLshort * v))
SDL_PROC_UNUSED(void, glVertex4sv, (const GLshort *v))
SDL_PROC(void, glVertexPointer,
(GLint size, GLenum type, GLsizei stride,
const GLvoid * pointer))
(GLint size, GLenum type, GLsizei stride,
const GLvoid *pointer))
SDL_PROC(void, glViewport, (GLint x, GLint y, GLsizei width, GLsizei height))
/* vi: set ts=4 sw=4 expandtab: */

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -61,6 +61,8 @@ struct GL_ShaderContext
GL_ShaderData shaders[NUM_SHADERS];
};
/* *INDENT-OFF* */ /* clang-format off */
#define COLOR_VERTEX_SHADER \
"varying vec4 v_color;\n" \
"\n" \
@ -235,8 +237,7 @@ struct GL_ShaderContext
* NOTE: Always use sampler2D, etc here. We'll #define them to the
* texture_rectangle versions if we choose to use that extension.
*/
static const char *shader_source[NUM_SHADERS][2] =
{
static const char *shader_source[NUM_SHADERS][2] = {
/* SHADER_NONE */
{ NULL, NULL },
@ -387,8 +388,9 @@ static const char *shader_source[NUM_SHADERS][2] =
#endif /* SDL_HAVE_YUV */
};
static SDL_bool
CompileShader(GL_ShaderContext *ctx, GLhandleARB shader, const char *defines, const char *source)
/* *INDENT-ON* */ /* clang-format on */
static SDL_bool CompileShader(GL_ShaderContext *ctx, GLhandleARB shader, const char *defines, const char *source)
{
GLint status;
const char *sources[2];
@ -405,13 +407,13 @@ CompileShader(GL_ShaderContext *ctx, GLhandleARB shader, const char *defines, co
char *info;
ctx->glGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
info = SDL_small_alloc(char, length+1, &isstack);
info = SDL_small_alloc(char, length + 1, &isstack);
ctx->glGetInfoLogARB(shader, length, NULL, info);
SDL_LogError(SDL_LOG_CATEGORY_RENDER,
"Failed to compile shader:\n%s%s\n%s", defines, source, info);
"Failed to compile shader:\n%s%s\n%s", defines, source, info);
#ifdef DEBUG_SHADERS
fprintf(stderr,
"Failed to compile shader:\n%s%s\n%s", defines, source, info);
"Failed to compile shader:\n%s%s\n%s", defines, source, info);
#endif
SDL_small_free(info, isstack);
@ -421,8 +423,7 @@ CompileShader(GL_ShaderContext *ctx, GLhandleARB shader, const char *defines, co
}
}
static SDL_bool
CompileShaderProgram(GL_ShaderContext *ctx, int index, GL_ShaderData *data)
static SDL_bool CompileShaderProgram(GL_ShaderContext *ctx, int index, GL_ShaderData *data)
{
const int num_tmus_bound = 4;
const char *vert_defines = "";
@ -439,12 +440,12 @@ CompileShaderProgram(GL_ShaderContext *ctx, int index, GL_ShaderData *data)
/* Make sure we use the correct sampler type for our texture type */
if (ctx->GL_ARB_texture_rectangle_supported) {
frag_defines =
"#define sampler2D sampler2DRect\n"
"#define texture2D texture2DRect\n"
"#define UVCoordScale 0.5\n";
"#define sampler2D sampler2DRect\n"
"#define texture2D texture2DRect\n"
"#define UVCoordScale 0.5\n";
} else {
frag_defines =
"#define UVCoordScale 1.0\n";
frag_defines =
"#define UVCoordScale 1.0\n";
}
/* Create one program object to rule them all */
@ -471,7 +472,7 @@ CompileShaderProgram(GL_ShaderContext *ctx, int index, GL_ShaderData *data)
ctx->glUseProgramObjectARB(data->program);
for (i = 0; i < num_tmus_bound; ++i) {
char tex_name[10];
SDL_snprintf(tex_name, SDL_arraysize(tex_name), "tex%d", i);
(void)SDL_snprintf(tex_name, SDL_arraysize(tex_name), "tex%d", i);
location = ctx->glGetUniformLocationARB(data->program, tex_name);
if (location >= 0) {
ctx->glUniform1iARB(location, i);
@ -479,26 +480,24 @@ CompileShaderProgram(GL_ShaderContext *ctx, int index, GL_ShaderData *data)
}
ctx->glUseProgramObjectARB(0);
return (ctx->glGetError() == GL_NO_ERROR);
return ctx->glGetError() == GL_NO_ERROR;
}
static void
DestroyShaderProgram(GL_ShaderContext *ctx, GL_ShaderData *data)
static void DestroyShaderProgram(GL_ShaderContext *ctx, GL_ShaderData *data)
{
ctx->glDeleteObjectARB(data->vert_shader);
ctx->glDeleteObjectARB(data->frag_shader);
ctx->glDeleteObjectARB(data->program);
}
GL_ShaderContext *
GL_CreateShaderContext(void)
GL_ShaderContext *GL_CreateShaderContext(void)
{
GL_ShaderContext *ctx;
SDL_bool shaders_supported;
int i;
ctx = (GL_ShaderContext *)SDL_calloc(1, sizeof(*ctx));
if (!ctx) {
if (ctx == NULL) {
return NULL;
}
@ -514,20 +513,20 @@ GL_CreateShaderContext(void)
SDL_GL_ExtensionSupported("GL_ARB_shading_language_100") &&
SDL_GL_ExtensionSupported("GL_ARB_vertex_shader") &&
SDL_GL_ExtensionSupported("GL_ARB_fragment_shader")) {
ctx->glGetError = (GLenum (*)(void)) SDL_GL_GetProcAddress("glGetError");
ctx->glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) SDL_GL_GetProcAddress("glAttachObjectARB");
ctx->glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) SDL_GL_GetProcAddress("glCompileShaderARB");
ctx->glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) SDL_GL_GetProcAddress("glCreateProgramObjectARB");
ctx->glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) SDL_GL_GetProcAddress("glCreateShaderObjectARB");
ctx->glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC) SDL_GL_GetProcAddress("glDeleteObjectARB");
ctx->glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC) SDL_GL_GetProcAddress("glGetInfoLogARB");
ctx->glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC) SDL_GL_GetProcAddress("glGetObjectParameterivARB");
ctx->glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) SDL_GL_GetProcAddress("glGetUniformLocationARB");
ctx->glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) SDL_GL_GetProcAddress("glLinkProgramARB");
ctx->glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) SDL_GL_GetProcAddress("glShaderSourceARB");
ctx->glUniform1iARB = (PFNGLUNIFORM1IARBPROC) SDL_GL_GetProcAddress("glUniform1iARB");
ctx->glUniform1fARB = (PFNGLUNIFORM1FARBPROC) SDL_GL_GetProcAddress("glUniform1fARB");
ctx->glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) SDL_GL_GetProcAddress("glUseProgramObjectARB");
ctx->glGetError = (GLenum(*)(void))SDL_GL_GetProcAddress("glGetError");
ctx->glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)SDL_GL_GetProcAddress("glAttachObjectARB");
ctx->glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)SDL_GL_GetProcAddress("glCompileShaderARB");
ctx->glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)SDL_GL_GetProcAddress("glCreateProgramObjectARB");
ctx->glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)SDL_GL_GetProcAddress("glCreateShaderObjectARB");
ctx->glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC)SDL_GL_GetProcAddress("glDeleteObjectARB");
ctx->glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC)SDL_GL_GetProcAddress("glGetInfoLogARB");
ctx->glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC)SDL_GL_GetProcAddress("glGetObjectParameterivARB");
ctx->glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)SDL_GL_GetProcAddress("glGetUniformLocationARB");
ctx->glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)SDL_GL_GetProcAddress("glLinkProgramARB");
ctx->glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)SDL_GL_GetProcAddress("glShaderSourceARB");
ctx->glUniform1iARB = (PFNGLUNIFORM1IARBPROC)SDL_GL_GetProcAddress("glUniform1iARB");
ctx->glUniform1fARB = (PFNGLUNIFORM1FARBPROC)SDL_GL_GetProcAddress("glUniform1fARB");
ctx->glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)SDL_GL_GetProcAddress("glUseProgramObjectARB");
if (ctx->glGetError &&
ctx->glAttachObjectARB &&
ctx->glCompileShaderARB &&
@ -563,14 +562,12 @@ GL_CreateShaderContext(void)
return ctx;
}
void
GL_SelectShader(GL_ShaderContext *ctx, GL_Shader shader)
void GL_SelectShader(GL_ShaderContext *ctx, GL_Shader shader)
{
ctx->glUseProgramObjectARB(ctx->shaders[shader].program);
}
void
GL_DestroyShaderContext(GL_ShaderContext *ctx)
void GL_DestroyShaderContext(GL_ShaderContext *ctx)
{
int i;

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -26,7 +26,8 @@
/* OpenGL shader implementation */
typedef enum {
typedef enum
{
SHADER_INVALID = -1,
SHADER_NONE,
SHADER_SOLID,
@ -50,7 +51,7 @@ typedef enum {
typedef struct GL_ShaderContext GL_ShaderContext;
extern GL_ShaderContext * GL_CreateShaderContext(void);
extern GL_ShaderContext *GL_CreateShaderContext(void);
extern void GL_SelectShader(GL_ShaderContext *ctx, GL_Shader shader);
extern void GL_DestroyShaderContext(GL_ShaderContext *ctx);

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -44,7 +44,7 @@ SDL_PROC(void, glLoadIdentity, (void))
SDL_PROC(void, glMatrixMode, (GLenum))
SDL_PROC(void, glOrthof, (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat))
SDL_PROC(void, glPixelStorei, (GLenum, GLint))
SDL_PROC(void, glReadPixels, (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid*))
SDL_PROC(void, glReadPixels, (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid *))
SDL_PROC(void, glScissor, (GLint, GLint, GLsizei, GLsizei))
SDL_PROC(void, glTexCoordPointer, (GLint, GLenum, GLsizei, const GLvoid *))
SDL_PROC(void, glTexEnvf, (GLenum, GLenum, GLfloat))
@ -57,6 +57,6 @@ SDL_PROC(void, glViewport, (GLint, GLint, GLsizei, GLsizei))
SDL_PROC_OES(void, glBindFramebufferOES, (GLenum, GLuint))
SDL_PROC_OES(void, glFramebufferTexture2DOES, (GLenum, GLenum, GLenum, GLuint, GLint))
SDL_PROC_OES(GLenum, glCheckFramebufferStatusOES, (GLenum))
SDL_PROC_OES(void, glDeleteFramebuffersOES, (GLsizei, const GLuint*))
SDL_PROC_OES(void, glDeleteFramebuffersOES, (GLsizei, const GLuint *))
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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,8 +23,10 @@
#if SDL_VIDEO_RENDER_OGL_ES && !SDL_RENDER_DISABLED
#include "SDL_hints.h"
#include "../../video/SDL_sysvideo.h" /* For SDL_GL_SwapWindowWithResult */
#include "SDL_opengles.h"
#include "../SDL_sysrender.h"
#include "../../SDL_utils_c.h"
/* To prevent unnecessary window recreation,
* these should match the defaults selected in SDL_GL_ResetAttributes
@ -48,7 +50,7 @@ glDrawTexiOES(GLint x, GLint y, GLint z, GLint width, GLint height)
/* OpenGL ES 1.1 renderer implementation, based on the OpenGL renderer */
/* Used to re-create the window with OpenGL ES capability */
extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
extern int SDL_RecreateWindow(SDL_Window *window, Uint32 flags);
static const float inv255f = 1.0f / 255.0f;
@ -56,9 +58,9 @@ typedef struct GLES_FBOList GLES_FBOList;
struct GLES_FBOList
{
Uint32 w, h;
GLuint FBO;
GLES_FBOList *next;
Uint32 w, h;
GLuint FBO;
GLES_FBOList *next;
};
typedef struct
@ -83,8 +85,8 @@ typedef struct
{
SDL_GLContext context;
#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
#define SDL_PROC_OES SDL_PROC
#define SDL_PROC(ret, func, params) ret (APIENTRY *func) params;
#define SDL_PROC_OES SDL_PROC
#include "SDL_glesfuncs.h"
#undef SDL_PROC
#undef SDL_PROC_OES
@ -95,6 +97,7 @@ typedef struct
SDL_bool GL_OES_blend_func_separate_supported;
SDL_bool GL_OES_blend_equation_separate_supported;
SDL_bool GL_OES_blend_subtract_supported;
SDL_bool GL_EXT_blend_minmax_supported;
GLES_DrawStateCache drawstate;
} GLES_RenderData;
@ -112,8 +115,7 @@ typedef struct
GLES_FBOList *fbo;
} GLES_TextureData;
static int
GLES_SetError(const char *prefix, GLenum result)
static int GLES_SetError(const char *prefix, GLenum result)
{
const char *error;
@ -146,7 +148,7 @@ GLES_SetError(const char *prefix, GLenum result)
return SDL_SetError("%s: %s", prefix, error);
}
static int GLES_LoadFunctions(GLES_RenderData * data)
static int GLES_LoadFunctions(GLES_RenderData *data)
{
#if SDL_VIDEO_DRIVER_UIKIT
#define __SDL_NOGETPROCADDR__
@ -157,20 +159,20 @@ static int GLES_LoadFunctions(GLES_RenderData * data)
#endif
#ifdef __SDL_NOGETPROCADDR__
#define SDL_PROC(ret,func,params) data->func=func;
#define SDL_PROC_OES(ret,func,params) data->func=func;
#define SDL_PROC(ret, func, params) data->func = func;
#define SDL_PROC_OES(ret, func, params) data->func = func;
#else
#define SDL_PROC(ret,func,params) \
do { \
data->func = SDL_GL_GetProcAddress(#func); \
if ( ! data->func ) { \
#define SDL_PROC(ret, func, params) \
do { \
data->func = SDL_GL_GetProcAddress(#func); \
if (!data->func) { \
return SDL_SetError("Couldn't load GLES function %s: %s", #func, SDL_GetError()); \
} \
} while ( 0 );
#define SDL_PROC_OES(ret,func,params) \
do { \
} \
} while (0);
#define SDL_PROC_OES(ret, func, params) \
do { \
data->func = SDL_GL_GetProcAddress(#func); \
} while ( 0 );
} while (0);
#endif /* __SDL_NOGETPROCADDR__ */
#include "SDL_glesfuncs.h"
@ -179,29 +181,26 @@ static int GLES_LoadFunctions(GLES_RenderData * data)
return 0;
}
static GLES_FBOList *
GLES_GetFBO(GLES_RenderData *data, Uint32 w, Uint32 h)
static GLES_FBOList *GLES_GetFBO(GLES_RenderData *data, Uint32 w, Uint32 h)
{
GLES_FBOList *result = data->framebuffers;
while ((result) && ((result->w != w) || (result->h != h)) ) {
result = result->next;
}
if (result == NULL) {
result = SDL_malloc(sizeof(GLES_FBOList));
result->w = w;
result->h = h;
data->glGenFramebuffersOES(1, &result->FBO);
result->next = data->framebuffers;
data->framebuffers = result;
}
return result;
GLES_FBOList *result = data->framebuffers;
while ((result) && ((result->w != w) || (result->h != h))) {
result = result->next;
}
if (result == NULL) {
result = SDL_malloc(sizeof(GLES_FBOList));
result->w = w;
result->h = h;
data->glGenFramebuffersOES(1, &result->FBO);
result->next = data->framebuffers;
data->framebuffers = result;
}
return result;
}
static int
GLES_ActivateRenderer(SDL_Renderer * renderer)
static int GLES_ActivateRenderer(SDL_Renderer *renderer)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
GLES_RenderData *data = (GLES_RenderData *)renderer->driverdata;
if (SDL_GL_GetCurrentContext() != data->context) {
if (SDL_GL_MakeCurrent(renderer->window, data->context) < 0) {
@ -212,10 +211,9 @@ GLES_ActivateRenderer(SDL_Renderer * renderer)
return 0;
}
static void
GLES_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
static void GLES_WindowEvent(SDL_Renderer *renderer, const SDL_WindowEvent *event)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
GLES_RenderData *data = (GLES_RenderData *)renderer->driverdata;
if (event->event == SDL_WINDOWEVENT_MINIMIZED) {
/* According to Apple documentation, we need to finish drawing NOW! */
@ -223,8 +221,7 @@ GLES_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
}
}
static int
GLES_GetOutputSize(SDL_Renderer * renderer, int *w, int *h)
static int GLES_GetOutputSize(SDL_Renderer *renderer, int *w, int *h)
{
SDL_GL_GetDrawableSize(renderer->window, w, h);
return 0;
@ -267,15 +264,18 @@ static GLenum GetBlendEquation(SDL_BlendOperation operation)
return GL_FUNC_SUBTRACT_OES;
case SDL_BLENDOPERATION_REV_SUBTRACT:
return GL_FUNC_REVERSE_SUBTRACT_OES;
case SDL_BLENDOPERATION_MINIMUM:
return GL_MIN_EXT;
case SDL_BLENDOPERATION_MAXIMUM:
return GL_MAX_EXT;
default:
return GL_INVALID_ENUM;
}
}
static SDL_bool
GLES_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
static SDL_bool GLES_SupportsBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendMode)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
GLES_RenderData *data = (GLES_RenderData *)renderer->driverdata;
SDL_BlendFactor srcColorFactor = SDL_GetBlendModeSrcColorFactor(blendMode);
SDL_BlendFactor srcAlphaFactor = SDL_GetBlendModeSrcAlphaFactor(blendMode);
SDL_BlendOperation colorOperation = SDL_GetBlendModeColorOperation(blendMode);
@ -300,24 +300,18 @@ GLES_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
if (colorOperation != SDL_BLENDOPERATION_ADD && !data->GL_OES_blend_subtract_supported) {
return SDL_FALSE;
}
if (colorOperation == SDL_BLENDOPERATION_MINIMUM && !data->GL_EXT_blend_minmax_supported) {
return SDL_FALSE;
}
if (colorOperation == SDL_BLENDOPERATION_MAXIMUM && !data->GL_EXT_blend_minmax_supported) {
return SDL_FALSE;
}
return SDL_TRUE;
}
static SDL_INLINE int
power_of_2(int input)
static int GLES_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
{
int value = 1;
while (value < input) {
value <<= 1;
}
return value;
}
static int
GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
GLES_RenderData *renderdata = (GLES_RenderData *)renderer->driverdata;
GLES_TextureData *data;
GLint internalFormat;
GLenum format, type;
@ -337,8 +331,8 @@ GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
return SDL_SetError("Texture format not supported");
}
data = (GLES_TextureData *) SDL_calloc(1, sizeof(*data));
if (!data) {
data = (GLES_TextureData *)SDL_calloc(1, sizeof(*data));
if (data == NULL) {
return SDL_OutOfMemory();
}
@ -351,7 +345,6 @@ GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
}
}
if (texture->access == SDL_TEXTUREACCESS_TARGET) {
if (!renderdata->GL_OES_framebuffer_object_supported) {
SDL_free(data);
@ -362,22 +355,24 @@ GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
data->fbo = NULL;
}
renderdata->glGetError();
renderdata->glEnable(GL_TEXTURE_2D);
renderdata->glGenTextures(1, &data->texture);
result = renderdata->glGetError();
if (result != GL_NO_ERROR) {
if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
SDL_free(data->pixels);
}
SDL_free(data);
return GLES_SetError("glGenTextures()", result);
}
data->type = GL_TEXTURE_2D;
/* no NPOV textures allowed in OpenGL ES (yet) */
texture_w = power_of_2(texture->w);
texture_h = power_of_2(texture->h);
data->texw = (GLfloat) texture->w / texture_w;
data->texh = (GLfloat) texture->h / texture_h;
texture_w = SDL_powerof2(texture->w);
texture_h = SDL_powerof2(texture->h);
data->texw = (GLfloat)texture->w / texture_w;
data->texh = (GLfloat)texture->h / texture_h;
data->format = format;
data->formattype = type;
@ -396,6 +391,9 @@ GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
result = renderdata->glGetError();
if (result != GL_NO_ERROR) {
if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
SDL_free(data->pixels);
}
SDL_free(data);
return GLES_SetError("glTexImage2D()", result);
}
@ -404,12 +402,11 @@ GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
return 0;
}
static int
GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels, int pitch)
static int GLES_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect, const void *pixels, int pitch)
{
GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
GLES_RenderData *renderdata = (GLES_RenderData *)renderer->driverdata;
GLES_TextureData *data = (GLES_TextureData *)texture->driverdata;
Uint8 *blob = NULL;
Uint8 *src;
int srcPitch;
@ -427,7 +424,7 @@ GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
src = (Uint8 *)pixels;
if (pitch != srcPitch) {
blob = (Uint8 *)SDL_malloc(srcPitch * rect->h);
if (!blob) {
if (blob == NULL) {
return SDL_OutOfMemory();
}
src = blob;
@ -445,14 +442,14 @@ GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
renderdata->glBindTexture(data->type, data->texture);
renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
renderdata->glTexSubImage2D(data->type,
0,
rect->x,
rect->y,
rect->w,
rect->h,
data->format,
data->formattype,
src);
0,
rect->x,
rect->y,
rect->w,
rect->h,
data->format,
data->formattype,
src);
renderdata->glDisable(data->type);
SDL_free(blob);
@ -465,23 +462,21 @@ GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
return 0;
}
static int
GLES_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, void **pixels, int *pitch)
static int GLES_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect, void **pixels, int *pitch)
{
GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
GLES_TextureData *data = (GLES_TextureData *)texture->driverdata;
*pixels =
(void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
rect->x * SDL_BYTESPERPIXEL(texture->format));
(void *)((Uint8 *)data->pixels + rect->y * data->pitch +
rect->x * SDL_BYTESPERPIXEL(texture->format));
*pitch = data->pitch;
return 0;
}
static void
GLES_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
static void GLES_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
{
GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
GLES_TextureData *data = (GLES_TextureData *)texture->driverdata;
SDL_Rect rect;
/* We do whole texture updates, at least for now */
@ -492,11 +487,10 @@ GLES_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
GLES_UpdateTexture(renderer, texture, &rect, data->pixels, data->pitch);
}
static void
GLES_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture, SDL_ScaleMode scaleMode)
static void GLES_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *texture, SDL_ScaleMode scaleMode)
{
GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
GLES_RenderData *renderdata = (GLES_RenderData *)renderer->driverdata;
GLES_TextureData *data = (GLES_TextureData *)texture->driverdata;
GLenum glScaleMode = (scaleMode == SDL_ScaleModeNearest) ? GL_NEAREST : GL_LINEAR;
renderdata->glBindTexture(data->type, data->texture);
@ -504,10 +498,9 @@ GLES_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture, SDL_Sca
renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER, glScaleMode);
}
static int
GLES_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
static int GLES_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
GLES_RenderData *data = (GLES_RenderData *)renderer->driverdata;
GLES_TextureData *texturedata = NULL;
GLenum status;
@ -522,7 +515,7 @@ GLES_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
return 0;
}
texturedata = (GLES_TextureData *) texture->driverdata;
texturedata = (GLES_TextureData *)texture->driverdata;
data->glBindFramebufferOES(GL_FRAMEBUFFER_OES, texturedata->fbo->FBO);
/* TODO: check if texture pixel format allows this operation */
data->glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, texturedata->type, texturedata->texture, 0);
@ -534,20 +527,17 @@ GLES_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
return 0;
}
static int
GLES_QueueSetViewport(SDL_Renderer * renderer, SDL_RenderCommand *cmd)
static int GLES_QueueSetViewport(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
{
return 0; /* nothing to do in this backend. */
return 0; /* nothing to do in this backend. */
}
static int
GLES_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points, int count)
static int GLES_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count)
{
GLfloat *verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, count * 2 * sizeof (GLfloat), 0, &cmd->data.draw.first);
GLfloat *verts = (GLfloat *)SDL_AllocateRenderVertices(renderer, count * 2 * sizeof(GLfloat), 0, &cmd->data.draw.first);
int i;
if (!verts) {
if (verts == NULL) {
return -1;
}
@ -560,15 +550,14 @@ GLES_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_
return 0;
}
static int
GLES_QueueDrawLines(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points, int count)
static int GLES_QueueDrawLines(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count)
{
int i;
GLfloat prevx, prevy;
const size_t vertlen = (sizeof (GLfloat) * 2) * count;
GLfloat *verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, vertlen, 0, &cmd->data.draw.first);
const size_t vertlen = (sizeof(GLfloat) * 2) * count;
GLfloat *verts = (GLfloat *)SDL_AllocateRenderVertices(renderer, vertlen, 0, &cmd->data.draw.first);
if (!verts) {
if (verts == NULL) {
return -1;
}
cmd->data.draw.count = count;
@ -586,7 +575,7 @@ GLES_QueueDrawLines(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_F
for (i = 1; i < count; i++) {
const GLfloat xstart = prevx;
const GLfloat ystart = prevy;
const GLfloat xend = points[i].x + 0.5f; /* 0.5f to hit pixel center. */
const GLfloat xend = points[i].x + 0.5f; /* 0.5f to hit pixel center. */
const GLfloat yend = points[i].y + 0.5f;
/* bump a little in the direction we are moving in. */
const GLfloat deltax = xend - xstart;
@ -601,11 +590,10 @@ GLES_QueueDrawLines(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_F
return 0;
}
static int
GLES_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
const float *xy, int xy_stride, const SDL_Color *color, int color_stride, const float *uv, int uv_stride,
int num_vertices, const void *indices, int num_indices, int size_indices,
float scale_x, float scale_y)
static int GLES_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
const float *xy, int xy_stride, const SDL_Color *color, int color_stride, const float *uv, int uv_stride,
int num_vertices, const void *indices, int num_indices, int size_indices,
float scale_x, float scale_y)
{
GLES_TextureData *texturedata = NULL;
int i;
@ -613,13 +601,13 @@ GLES_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *
GLfloat *verts;
int sz = 2 + 4 + (texture ? 2 : 0);
verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, count * sz * sizeof (GLfloat), 0, &cmd->data.draw.first);
if (!verts) {
verts = (GLfloat *)SDL_AllocateRenderVertices(renderer, count * sz * sizeof(GLfloat), 0, &cmd->data.draw.first);
if (verts == NULL) {
return -1;
}
if (texture) {
texturedata = (GLES_TextureData *) texture->driverdata;
texturedata = (GLES_TextureData *)texture->driverdata;
}
cmd->data.draw.count = count;
@ -639,8 +627,8 @@ GLES_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *
j = i;
}
xy_ = (float *)((char*)xy + j * xy_stride);
col_ = *(SDL_Color *)((char*)color + j * color_stride);
xy_ = (float *)((char *)xy + j * xy_stride);
col_ = *(SDL_Color *)((char *)color + j * color_stride);
*(verts++) = xy_[0] * scale_x;
*(verts++) = xy_[1] * scale_y;
@ -651,7 +639,7 @@ GLES_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *
*(verts++) = col_.a * inv255f;
if (texture) {
float *uv_ = (float *)((char*)uv + j * uv_stride);
float *uv_ = (float *)((char *)uv + j * uv_stride);
*(verts++) = uv_[0] * texturedata->texw;
*(verts++) = uv_[1] * texturedata->texh;
}
@ -659,8 +647,7 @@ GLES_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *
return 0;
}
static void
SetDrawState(GLES_RenderData *data, const SDL_RenderCommand *cmd)
static void SetDrawState(GLES_RenderData *data, const SDL_RenderCommand *cmd)
{
const SDL_BlendMode blend = cmd->data.draw.blend;
const Uint8 r = cmd->data.draw.r;
@ -670,10 +657,10 @@ SetDrawState(GLES_RenderData *data, const SDL_RenderCommand *cmd)
const Uint32 color = (((Uint32)a << 24) | (r << 16) | (g << 8) | b);
if (color != data->drawstate.color) {
const GLfloat fr = ((GLfloat) r) * inv255f;
const GLfloat fg = ((GLfloat) g) * inv255f;
const GLfloat fb = ((GLfloat) b) * inv255f;
const GLfloat fa = ((GLfloat) a) * inv255f;
const GLfloat fr = ((GLfloat)r) * inv255f;
const GLfloat fg = ((GLfloat)g) * inv255f;
const GLfloat fb = ((GLfloat)b) * inv255f;
const GLfloat fa = ((GLfloat)a) * inv255f;
data->glColor4f(fr, fg, fb, fa);
data->drawstate.color = color;
}
@ -687,9 +674,9 @@ SetDrawState(GLES_RenderData *data, const SDL_RenderCommand *cmd)
istarget ? viewport->y : (data->drawstate.drawableh - viewport->y - viewport->h),
viewport->w, viewport->h);
if (viewport->w && viewport->h) {
data->glOrthof((GLfloat) 0, (GLfloat) viewport->w,
(GLfloat) (istarget ? 0 : viewport->h),
(GLfloat) (istarget ? viewport->h : 0),
data->glOrthof((GLfloat)0, (GLfloat)viewport->w,
(GLfloat)(istarget ? 0 : viewport->h),
(GLfloat)(istarget ? viewport->h : 0),
0.0, 1.0);
}
data->glMatrixMode(GL_MODELVIEW);
@ -752,23 +739,21 @@ SetDrawState(GLES_RenderData *data, const SDL_RenderCommand *cmd)
}
}
static void
SetCopyState(GLES_RenderData *data, const SDL_RenderCommand *cmd)
static void SetCopyState(GLES_RenderData *data, const SDL_RenderCommand *cmd)
{
SDL_Texture *texture = cmd->data.draw.texture;
SetDrawState(data, cmd);
if (texture != data->drawstate.texture) {
GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata;
GLES_TextureData *texturedata = (GLES_TextureData *)texture->driverdata;
data->glBindTexture(GL_TEXTURE_2D, texturedata->texture);
data->drawstate.texture = texture;
}
}
static int
GLES_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
static int GLES_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
GLES_RenderData *data = (GLES_RenderData *)renderer->driverdata;
if (GLES_ActivateRenderer(renderer) < 0) {
return -1;
@ -780,123 +765,129 @@ GLES_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vert
int w, h;
SDL_GL_GetDrawableSize(renderer->window, &w, &h);
if ((w != data->drawstate.drawablew) || (h != data->drawstate.drawableh)) {
data->drawstate.viewport_dirty = SDL_TRUE; // if the window dimensions changed, invalidate the current viewport, etc.
data->drawstate.viewport_dirty = SDL_TRUE; // if the window dimensions changed, invalidate the current viewport, etc.
data->drawstate.cliprect_dirty = SDL_TRUE;
data->drawstate.drawablew = w;
data->drawstate.drawableh = h;
}
}
while (cmd) {
switch (cmd->command) {
case SDL_RENDERCMD_SETDRAWCOLOR: {
break; /* not used in this render backend. */
case SDL_RENDERCMD_SETDRAWCOLOR:
{
break; /* not used in this render backend. */
}
case SDL_RENDERCMD_SETVIEWPORT:
{
SDL_Rect *viewport = &data->drawstate.viewport;
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;
}
break;
}
case SDL_RENDERCMD_SETCLIPRECT:
{
const SDL_Rect *rect = &cmd->data.cliprect.rect;
if (data->drawstate.cliprect_enabled != cmd->data.cliprect.enabled) {
data->drawstate.cliprect_enabled = cmd->data.cliprect.enabled;
data->drawstate.cliprect_enabled_dirty = SDL_TRUE;
}
if (SDL_memcmp(&data->drawstate.cliprect, rect, sizeof(*rect)) != 0) {
SDL_copyp(&data->drawstate.cliprect, rect);
data->drawstate.cliprect_dirty = SDL_TRUE;
}
break;
}
case SDL_RENDERCMD_CLEAR:
{
const Uint8 r = cmd->data.color.r;
const Uint8 g = cmd->data.color.g;
const Uint8 b = cmd->data.color.b;
const Uint8 a = cmd->data.color.a;
const Uint32 color = (((Uint32)a << 24) | (r << 16) | (g << 8) | b);
if (color != data->drawstate.clear_color) {
const GLfloat fr = ((GLfloat)r) * inv255f;
const GLfloat fg = ((GLfloat)g) * inv255f;
const GLfloat fb = ((GLfloat)b) * inv255f;
const GLfloat fa = ((GLfloat)a) * inv255f;
data->glClearColor(fr, fg, fb, fa);
data->drawstate.clear_color = color;
}
case SDL_RENDERCMD_SETVIEWPORT: {
SDL_Rect *viewport = &data->drawstate.viewport;
if (SDL_memcmp(viewport, &cmd->data.viewport.rect, sizeof (SDL_Rect)) != 0) {
SDL_memcpy(viewport, &cmd->data.viewport.rect, sizeof (SDL_Rect));
data->drawstate.viewport_dirty = SDL_TRUE;
}
break;
if (data->drawstate.cliprect_enabled || data->drawstate.cliprect_enabled_dirty) {
data->glDisable(GL_SCISSOR_TEST);
data->drawstate.cliprect_enabled_dirty = data->drawstate.cliprect_enabled;
}
case SDL_RENDERCMD_SETCLIPRECT: {
const SDL_Rect *rect = &cmd->data.cliprect.rect;
if (data->drawstate.cliprect_enabled != cmd->data.cliprect.enabled) {
data->drawstate.cliprect_enabled = cmd->data.cliprect.enabled;
data->drawstate.cliprect_enabled_dirty = SDL_TRUE;
}
if (SDL_memcmp(&data->drawstate.cliprect, rect, sizeof (SDL_Rect)) != 0) {
SDL_memcpy(&data->drawstate.cliprect, rect, sizeof (SDL_Rect));
data->drawstate.cliprect_dirty = SDL_TRUE;
}
break;
}
data->glClear(GL_COLOR_BUFFER_BIT);
case SDL_RENDERCMD_CLEAR: {
const Uint8 r = cmd->data.color.r;
const Uint8 g = cmd->data.color.g;
const Uint8 b = cmd->data.color.b;
const Uint8 a = cmd->data.color.a;
const Uint32 color = (((Uint32)a << 24) | (r << 16) | (g << 8) | b);
if (color != data->drawstate.clear_color) {
const GLfloat fr = ((GLfloat) r) * inv255f;
const GLfloat fg = ((GLfloat) g) * inv255f;
const GLfloat fb = ((GLfloat) b) * inv255f;
const GLfloat fa = ((GLfloat) a) * inv255f;
data->glClearColor(fr, fg, fb, fa);
data->drawstate.clear_color = color;
}
break;
}
if (data->drawstate.cliprect_enabled || data->drawstate.cliprect_enabled_dirty) {
data->glDisable(GL_SCISSOR_TEST);
data->drawstate.cliprect_enabled_dirty = data->drawstate.cliprect_enabled;
}
case SDL_RENDERCMD_DRAW_POINTS:
{
const size_t count = cmd->data.draw.count;
const GLfloat *verts = (GLfloat *)(((Uint8 *)vertices) + cmd->data.draw.first);
SetDrawState(data, cmd);
data->glVertexPointer(2, GL_FLOAT, 0, verts);
data->glDrawArrays(GL_POINTS, 0, (GLsizei)count);
break;
}
data->glClear(GL_COLOR_BUFFER_BIT);
case SDL_RENDERCMD_DRAW_LINES:
{
const GLfloat *verts = (GLfloat *)(((Uint8 *)vertices) + cmd->data.draw.first);
const size_t count = cmd->data.draw.count;
SDL_assert(count >= 2);
SetDrawState(data, cmd);
data->glVertexPointer(2, GL_FLOAT, 0, verts);
data->glDrawArrays(GL_LINE_STRIP, 0, (GLsizei)count);
break;
}
break;
}
case SDL_RENDERCMD_FILL_RECTS: /* unused */
break;
case SDL_RENDERCMD_DRAW_POINTS: {
const size_t count = cmd->data.draw.count;
const GLfloat *verts = (GLfloat *) (((Uint8 *) vertices) + cmd->data.draw.first);
case SDL_RENDERCMD_COPY: /* unused */
break;
case SDL_RENDERCMD_COPY_EX: /* unused */
break;
case SDL_RENDERCMD_GEOMETRY:
{
const GLfloat *verts = (GLfloat *)(((Uint8 *)vertices) + cmd->data.draw.first);
SDL_Texture *texture = cmd->data.draw.texture;
const size_t count = cmd->data.draw.count;
int stride = (2 + 4 + (texture ? 2 : 0)) * sizeof(float);
if (texture) {
SetCopyState(data, cmd);
} else {
SetDrawState(data, cmd);
data->glVertexPointer(2, GL_FLOAT, 0, verts);
data->glDrawArrays(GL_POINTS, 0, (GLsizei) count);
break;
}
case SDL_RENDERCMD_DRAW_LINES: {
const GLfloat *verts = (GLfloat *) (((Uint8 *) vertices) + cmd->data.draw.first);
const size_t count = cmd->data.draw.count;
SDL_assert(count >= 2);
SetDrawState(data, cmd);
data->glVertexPointer(2, GL_FLOAT, 0, verts);
data->glDrawArrays(GL_LINE_STRIP, 0, (GLsizei) count);
break;
data->glEnableClientState(GL_COLOR_ARRAY);
data->glVertexPointer(2, GL_FLOAT, stride, verts);
data->glColorPointer(4, GL_FLOAT, stride, verts + 2);
if (texture) {
data->glTexCoordPointer(2, GL_FLOAT, stride, verts + 2 + 4);
}
case SDL_RENDERCMD_FILL_RECTS: /* unused */
break;
data->glDrawArrays(GL_TRIANGLES, 0, (GLsizei)count);
case SDL_RENDERCMD_COPY: /* unused */
break;
data->glDisableClientState(GL_COLOR_ARRAY);
break;
}
case SDL_RENDERCMD_COPY_EX: /* unused */
break;
case SDL_RENDERCMD_GEOMETRY: {
const GLfloat *verts = (GLfloat *) (((Uint8 *) vertices) + cmd->data.draw.first);
SDL_Texture *texture = cmd->data.draw.texture;
const size_t count = cmd->data.draw.count;
int stride = (2 + 4 + (texture ? 2 : 0)) * sizeof (float);
if (texture) {
SetCopyState(data, cmd);
} else {
SetDrawState(data, cmd);
}
data->glEnableClientState(GL_COLOR_ARRAY);
data->glVertexPointer(2, GL_FLOAT, stride, verts);
data->glColorPointer(4, GL_FLOAT, stride, verts + 2);
if (texture) {
data->glTexCoordPointer(2, GL_FLOAT, stride, verts + 2 + 4);
}
data->glDrawArrays(GL_TRIANGLES, 0, (GLsizei) count);
data->glDisableClientState(GL_COLOR_ARRAY);
break;
}
case SDL_RENDERCMD_NO_OP:
break;
case SDL_RENDERCMD_NO_OP:
break;
}
cmd = cmd->next;
@ -905,11 +896,10 @@ GLES_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vert
return 0;
}
static int
GLES_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 pixel_format, void * pixels, int pitch)
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;
GLES_RenderData *data = (GLES_RenderData *)renderer->driverdata;
Uint32 temp_format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_ABGR8888;
void *temp_pixels;
int temp_pitch;
@ -921,7 +911,7 @@ 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) {
if (temp_pixels == NULL) {
return SDL_OutOfMemory();
}
@ -929,15 +919,15 @@ GLES_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
data->glPixelStorei(GL_PACK_ALIGNMENT, 1);
data->glReadPixels(rect->x, renderer->target ? rect->y : (h-rect->y)-rect->h,
data->glReadPixels(rect->x, renderer->target ? rect->y : (h - rect->y) - rect->h,
rect->w, rect->h, GL_RGBA, GL_UNSIGNED_BYTE, temp_pixels);
/* Flip the rows to be top-down if necessary */
if (!renderer->target) {
SDL_bool isstack;
length = rect->w * SDL_BYTESPERPIXEL(temp_format);
src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch;
dst = (Uint8*)temp_pixels;
src = (Uint8 *)temp_pixels + (rect->h - 1) * temp_pitch;
dst = (Uint8 *)temp_pixels;
tmp = SDL_small_alloc(Uint8, length, &isstack);
rows = rect->h / 2;
while (rows--) {
@ -958,20 +948,18 @@ GLES_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
return status;
}
static void
GLES_RenderPresent(SDL_Renderer * renderer)
static int GLES_RenderPresent(SDL_Renderer *renderer)
{
GLES_ActivateRenderer(renderer);
SDL_GL_SwapWindow(renderer->window);
return SDL_GL_SwapWindowWithResult(renderer->window);
}
static void
GLES_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
static void GLES_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
{
GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
GLES_RenderData *renderdata = (GLES_RenderData *)renderer->driverdata;
GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
GLES_TextureData *data = (GLES_TextureData *)texture->driverdata;
GLES_ActivateRenderer(renderer);
@ -982,7 +970,7 @@ GLES_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
renderdata->drawstate.target = NULL;
}
if (!data) {
if (data == NULL) {
return;
}
if (data->texture) {
@ -993,18 +981,17 @@ GLES_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
texture->driverdata = NULL;
}
static void
GLES_DestroyRenderer(SDL_Renderer * renderer)
static void GLES_DestroyRenderer(SDL_Renderer *renderer)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
GLES_RenderData *data = (GLES_RenderData *)renderer->driverdata;
if (data) {
if (data->context) {
while (data->framebuffers) {
GLES_FBOList *nextnode = data->framebuffers->next;
data->glDeleteFramebuffersOES(1, &data->framebuffers->FBO);
SDL_free(data->framebuffers);
data->framebuffers = nextnode;
GLES_FBOList *nextnode = data->framebuffers->next;
data->glDeleteFramebuffersOES(1, &data->framebuffers->FBO);
SDL_free(data->framebuffers);
data->framebuffers = nextnode;
}
SDL_GL_DeleteContext(data->context);
}
@ -1013,10 +1000,10 @@ GLES_DestroyRenderer(SDL_Renderer * renderer)
SDL_free(renderer);
}
static int GLES_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh)
static int GLES_BindTexture(SDL_Renderer *renderer, SDL_Texture *texture, float *texw, float *texh)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata;
GLES_RenderData *data = (GLES_RenderData *)renderer->driverdata;
GLES_TextureData *texturedata = (GLES_TextureData *)texture->driverdata;
GLES_ActivateRenderer(renderer);
data->glEnable(GL_TEXTURE_2D);
@ -1035,10 +1022,10 @@ static int GLES_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, floa
return 0;
}
static int GLES_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture)
static int GLES_UnbindTexture(SDL_Renderer *renderer, SDL_Texture *texture)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata;
GLES_RenderData *data = (GLES_RenderData *)renderer->driverdata;
GLES_TextureData *texturedata = (GLES_TextureData *)texture->driverdata;
GLES_ActivateRenderer(renderer);
data->glDisable(texturedata->type);
@ -1048,8 +1035,7 @@ static int GLES_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture)
return 0;
}
static int
GLES_SetVSync(SDL_Renderer * renderer, const int vsync)
static int GLES_SetVSync(SDL_Renderer *renderer, const int vsync)
{
int retval;
if (vsync) {
@ -1068,9 +1054,7 @@ GLES_SetVSync(SDL_Renderer * renderer, const int vsync)
return retval;
}
static SDL_Renderer *
GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
static SDL_Renderer *GLES_CreateRenderer(SDL_Window *window, Uint32 flags)
{
SDL_Renderer *renderer;
GLES_RenderData *data;
@ -1097,14 +1081,14 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
}
}
renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
if (!renderer) {
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) {
data = (GLES_RenderData *)SDL_calloc(1, sizeof(*data));
if (data == NULL) {
GLES_DestroyRenderer(renderer);
SDL_OutOfMemory();
goto error;
@ -1120,7 +1104,7 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->SetTextureScaleMode = GLES_SetTextureScaleMode;
renderer->SetRenderTarget = GLES_SetRenderTarget;
renderer->QueueSetViewport = GLES_QueueSetViewport;
renderer->QueueSetDrawColor = GLES_QueueSetViewport; /* SetViewport and SetDrawColor are (currently) no-ops. */
renderer->QueueSetDrawColor = GLES_QueueSetViewport; /* SetViewport and SetDrawColor are (currently) no-ops. */
renderer->QueueDrawPoints = GLES_QueueDrawPoints;
renderer->QueueDrawLines = GLES_QueueDrawLines;
renderer->QueueGeometry = GLES_QueueGeometry;
@ -1188,6 +1172,9 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
if (SDL_GL_ExtensionSupported("GL_OES_blend_subtract")) {
data->GL_OES_blend_subtract_supported = SDL_TRUE;
}
if (SDL_GL_ExtensionSupported("GL_EXT_blend_minmax")) {
data->GL_EXT_blend_minmax_supported = SDL_TRUE;
}
/* Set up parameters for rendering */
data->glDisable(GL_DEPTH_TEST);
@ -1220,14 +1207,12 @@ error:
SDL_RenderDriver GLES_RenderDriver = {
GLES_CreateRenderer,
{
"opengles",
(SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC),
1,
{SDL_PIXELFORMAT_ABGR8888},
0,
0
}
{ "opengles",
(SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC),
1,
{ SDL_PIXELFORMAT_ABGR8888 },
0,
0 }
};
#endif /* SDL_VIDEO_RENDER_OGL_ES && !SDL_RENDER_DISABLED */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -50,7 +50,7 @@ SDL_PROC(void, glGetShaderiv, (GLuint, GLenum, GLint *))
SDL_PROC(GLint, glGetUniformLocation, (GLuint, const char *))
SDL_PROC(void, glLinkProgram, (GLuint))
SDL_PROC(void, glPixelStorei, (GLenum, GLint))
SDL_PROC(void, glReadPixels, (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid*))
SDL_PROC(void, 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__
@ -72,7 +72,7 @@ SDL_PROC(void, glFramebufferTexture2D, (GLenum, GLenum, GLenum, GLuint, GLint))
SDL_PROC(GLenum, glCheckFramebufferStatus, (GLenum))
SDL_PROC(void, glDeleteFramebuffers, (GLsizei, const GLuint *))
SDL_PROC(GLint, glGetAttribLocation, (GLuint, const GLchar *))
SDL_PROC(void, glGetProgramInfoLog, (GLuint, GLsizei, GLsizei*, GLchar*))
SDL_PROC(void, glGetProgramInfoLog, (GLuint, GLsizei, GLsizei *, GLchar *))
SDL_PROC(void, glGenBuffers, (GLsizei, GLuint *))
SDL_PROC(void, glDeleteBuffers, (GLsizei, const GLuint *))
SDL_PROC(void, glBindBuffer, (GLenum, GLuint))

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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,104 +22,134 @@
#if SDL_VIDEO_RENDER_OGL_ES2 && !SDL_RENDER_DISABLED
#include "SDL_hints.h"
#include "SDL_video.h"
#include "SDL_opengles2.h"
#include "SDL_shaders_gles2.h"
#include "SDL_stdinc.h"
/* *INDENT-OFF* */ /* clang-format off */
/*************************************************************************************************
* Vertex/fragment shader source *
*************************************************************************************************/
static const Uint8 GLES2_Vertex_Default[] = " \
uniform mat4 u_projection; \
attribute vec2 a_position; \
attribute vec4 a_color; \
attribute vec2 a_texCoord; \
varying vec2 v_texCoord; \
varying vec4 v_color; \
\
void main() \
{ \
v_texCoord = a_texCoord; \
gl_Position = u_projection * vec4(a_position, 0.0, 1.0);\
gl_PointSize = 1.0; \
v_color = a_color; \
} \
";
static const Uint8 GLES2_Fragment_Solid[] = " \
precision mediump float; \
varying vec4 v_color; \
\
void main() \
{ \
gl_FragColor = v_color; \
} \
";
static const char GLES2_Fragment_Include_Best_Texture_Precision[] = \
"#ifdef GL_FRAGMENT_PRECISION_HIGH\n" \
"#define SDL_TEXCOORD_PRECISION highp\n" \
"#else\n" \
"#define SDL_TEXCOORD_PRECISION mediump\n" \
"#endif\n" \
"\n" \
"precision mediump float;\n" \
"\n" \
;
static const Uint8 GLES2_Fragment_TextureABGR[] = " \
precision mediump float; \
uniform sampler2D u_texture; \
varying vec4 v_color; \
varying vec2 v_texCoord; \
\
void main() \
{ \
gl_FragColor = texture2D(u_texture, v_texCoord); \
gl_FragColor *= v_color; \
} \
";
static const char GLES2_Fragment_Include_Medium_Texture_Precision[] = \
"#define SDL_TEXCOORD_PRECISION mediump\n" \
"precision mediump float;\n" \
"\n" \
;
static const char GLES2_Fragment_Include_High_Texture_Precision[] = \
"#define SDL_TEXCOORD_PRECISION highp\n" \
"precision mediump float;\n" \
"\n" \
;
static const char GLES2_Fragment_Include_Undef_Precision[] = \
"#define mediump\n" \
"#define highp\n" \
"#define lowp\n" \
"#define SDL_TEXCOORD_PRECISION\n" \
"\n" \
;
static const char GLES2_Vertex_Default[] = \
"uniform mat4 u_projection;\n" \
"attribute vec2 a_position;\n" \
"attribute vec4 a_color;\n" \
"attribute vec2 a_texCoord;\n" \
"varying vec2 v_texCoord;\n" \
"varying vec4 v_color;\n" \
"\n" \
"void main()\n" \
"{\n" \
" v_texCoord = a_texCoord;\n" \
" gl_Position = u_projection * vec4(a_position, 0.0, 1.0);\n" \
" gl_PointSize = 1.0;\n" \
" v_color = a_color;\n" \
"}\n" \
;
static const char GLES2_Fragment_Solid[] = \
"varying mediump vec4 v_color;\n" \
"\n" \
"void main()\n" \
"{\n" \
" gl_FragColor = v_color;\n" \
"}\n" \
;
static const char GLES2_Fragment_TextureABGR[] = \
"uniform sampler2D u_texture;\n" \
"varying mediump vec4 v_color;\n" \
"varying SDL_TEXCOORD_PRECISION vec2 v_texCoord;\n" \
"\n" \
"void main()\n" \
"{\n" \
" gl_FragColor = texture2D(u_texture, v_texCoord);\n" \
" gl_FragColor *= v_color;\n" \
"}\n" \
;
/* ARGB to ABGR conversion */
static const Uint8 GLES2_Fragment_TextureARGB[] = " \
precision mediump float; \
uniform sampler2D u_texture; \
varying vec4 v_color; \
varying vec2 v_texCoord; \
\
void main() \
{ \
vec4 abgr = texture2D(u_texture, v_texCoord); \
gl_FragColor = abgr; \
gl_FragColor.r = abgr.b; \
gl_FragColor.b = abgr.r; \
gl_FragColor *= v_color; \
} \
";
static const char GLES2_Fragment_TextureARGB[] = \
"uniform sampler2D u_texture;\n" \
"varying mediump vec4 v_color;\n" \
"varying SDL_TEXCOORD_PRECISION vec2 v_texCoord;\n" \
"\n" \
"void main()\n" \
"{\n" \
" mediump vec4 abgr = texture2D(u_texture, v_texCoord);\n" \
" gl_FragColor = abgr;\n" \
" gl_FragColor.r = abgr.b;\n" \
" gl_FragColor.b = abgr.r;\n" \
" gl_FragColor *= v_color;\n" \
"}\n" \
;
/* RGB to ABGR conversion */
static const Uint8 GLES2_Fragment_TextureRGB[] = " \
precision mediump float; \
uniform sampler2D u_texture; \
varying vec4 v_color; \
varying vec2 v_texCoord; \
\
void main() \
{ \
vec4 abgr = texture2D(u_texture, v_texCoord); \
gl_FragColor = abgr; \
gl_FragColor.r = abgr.b; \
gl_FragColor.b = abgr.r; \
gl_FragColor.a = 1.0; \
gl_FragColor *= v_color; \
} \
";
static const char GLES2_Fragment_TextureRGB[] = \
"uniform sampler2D u_texture;\n" \
"varying mediump vec4 v_color;\n" \
"varying SDL_TEXCOORD_PRECISION vec2 v_texCoord;\n" \
"\n" \
"void main()\n" \
"{\n" \
" mediump vec4 abgr = texture2D(u_texture, v_texCoord);\n" \
" gl_FragColor = abgr;\n" \
" gl_FragColor.r = abgr.b;\n" \
" gl_FragColor.b = abgr.r;\n" \
" gl_FragColor.a = 1.0;\n" \
" gl_FragColor *= v_color;\n" \
"}\n" \
;
/* BGR to ABGR conversion */
static const Uint8 GLES2_Fragment_TextureBGR[] = " \
precision mediump float; \
uniform sampler2D u_texture; \
varying vec4 v_color; \
varying vec2 v_texCoord; \
\
void main() \
{ \
vec4 abgr = texture2D(u_texture, v_texCoord); \
gl_FragColor = abgr; \
gl_FragColor.a = 1.0; \
gl_FragColor *= v_color; \
} \
";
static const char GLES2_Fragment_TextureBGR[] = \
"uniform sampler2D u_texture;\n" \
"varying mediump vec4 v_color;\n" \
"varying SDL_TEXCOORD_PRECISION vec2 v_texCoord;\n" \
"\n" \
"void main()\n" \
"{\n" \
" mediump vec4 abgr = texture2D(u_texture, v_texCoord);\n" \
" gl_FragColor = abgr;\n" \
" gl_FragColor.a = 1.0;\n" \
" gl_FragColor *= v_color;\n" \
"}\n" \
;
#if SDL_HAVE_YUV
@ -131,6 +161,7 @@ static const Uint8 GLES2_Fragment_TextureBGR[] = " \
"const mat3 matrix = mat3( 1, 1, 1,\n" \
" 0, -0.3441, 1.772,\n" \
" 1.402, -0.7141, 0);\n" \
"\n" \
#define BT601_SHADER_CONSTANTS \
"// YUV offset \n" \
@ -140,6 +171,7 @@ static const Uint8 GLES2_Fragment_TextureBGR[] = " \
"const mat3 matrix = mat3( 1.1644, 1.1644, 1.1644,\n" \
" 0, -0.3918, 2.0172,\n" \
" 1.596, -0.813, 0);\n" \
"\n" \
#define BT709_SHADER_CONSTANTS \
"// YUV offset \n" \
@ -149,19 +181,18 @@ static const Uint8 GLES2_Fragment_TextureBGR[] = " \
"const mat3 matrix = mat3( 1.1644, 1.1644, 1.1644,\n" \
" 0, -0.2132, 2.1124,\n" \
" 1.7927, -0.5329, 0);\n" \
"\n" \
#define YUV_SHADER_PROLOGUE \
"precision mediump float;\n" \
"uniform sampler2D u_texture;\n" \
"uniform sampler2D u_texture_u;\n" \
"uniform sampler2D u_texture_v;\n" \
"varying vec4 v_color;\n" \
"varying vec2 v_texCoord;\n" \
"varying mediump vec4 v_color;\n" \
"varying SDL_TEXCOORD_PRECISION vec2 v_texCoord;\n" \
"\n" \
#define YUV_SHADER_BODY \
"\n" \
"void main()\n" \
"{\n" \
" mediump vec3 yuv;\n" \
@ -182,7 +213,6 @@ static const Uint8 GLES2_Fragment_TextureBGR[] = " \
"}" \
#define NV12_RA_SHADER_BODY \
"\n" \
"void main()\n" \
"{\n" \
" mediump vec3 yuv;\n" \
@ -202,7 +232,6 @@ static const Uint8 GLES2_Fragment_TextureBGR[] = " \
"}" \
#define NV12_RG_SHADER_BODY \
"\n" \
"void main()\n" \
"{\n" \
" mediump vec3 yuv;\n" \
@ -222,7 +251,6 @@ static const Uint8 GLES2_Fragment_TextureBGR[] = " \
"}" \
#define NV21_SHADER_BODY \
"\n" \
"void main()\n" \
"{\n" \
" mediump vec3 yuv;\n" \
@ -242,61 +270,61 @@ static const Uint8 GLES2_Fragment_TextureBGR[] = " \
"}" \
/* YUV to ABGR conversion */
static const Uint8 GLES2_Fragment_TextureYUVJPEG[] = \
static const char GLES2_Fragment_TextureYUVJPEG[] = \
YUV_SHADER_PROLOGUE \
JPEG_SHADER_CONSTANTS \
YUV_SHADER_BODY \
;
static const Uint8 GLES2_Fragment_TextureYUVBT601[] = \
static const char GLES2_Fragment_TextureYUVBT601[] = \
YUV_SHADER_PROLOGUE \
BT601_SHADER_CONSTANTS \
YUV_SHADER_BODY \
;
static const Uint8 GLES2_Fragment_TextureYUVBT709[] = \
static const char GLES2_Fragment_TextureYUVBT709[] = \
YUV_SHADER_PROLOGUE \
BT709_SHADER_CONSTANTS \
YUV_SHADER_BODY \
;
/* NV12 to ABGR conversion */
static const Uint8 GLES2_Fragment_TextureNV12JPEG[] = \
static const char GLES2_Fragment_TextureNV12JPEG[] = \
YUV_SHADER_PROLOGUE \
JPEG_SHADER_CONSTANTS \
NV12_RA_SHADER_BODY \
;
static const Uint8 GLES2_Fragment_TextureNV12BT601_RA[] = \
static const char GLES2_Fragment_TextureNV12BT601_RA[] = \
YUV_SHADER_PROLOGUE \
BT601_SHADER_CONSTANTS \
NV12_RA_SHADER_BODY \
;
static const Uint8 GLES2_Fragment_TextureNV12BT601_RG[] = \
static const char GLES2_Fragment_TextureNV12BT601_RG[] = \
YUV_SHADER_PROLOGUE \
BT601_SHADER_CONSTANTS \
NV12_RG_SHADER_BODY \
;
static const Uint8 GLES2_Fragment_TextureNV12BT709_RA[] = \
static const char GLES2_Fragment_TextureNV12BT709_RA[] = \
YUV_SHADER_PROLOGUE \
BT709_SHADER_CONSTANTS \
NV12_RA_SHADER_BODY \
;
static const Uint8 GLES2_Fragment_TextureNV12BT709_RG[] = \
static const char GLES2_Fragment_TextureNV12BT709_RG[] = \
YUV_SHADER_PROLOGUE \
BT709_SHADER_CONSTANTS \
NV12_RG_SHADER_BODY \
;
/* NV21 to ABGR conversion */
static const Uint8 GLES2_Fragment_TextureNV21JPEG[] = \
static const char GLES2_Fragment_TextureNV21JPEG[] = \
YUV_SHADER_PROLOGUE \
JPEG_SHADER_CONSTANTS \
NV21_SHADER_BODY \
;
static const Uint8 GLES2_Fragment_TextureNV21BT601[] = \
static const char GLES2_Fragment_TextureNV21BT601[] = \
YUV_SHADER_PROLOGUE \
BT601_SHADER_CONSTANTS \
NV21_SHADER_BODY \
;
static const Uint8 GLES2_Fragment_TextureNV21BT709[] = \
static const char GLES2_Fragment_TextureNV21BT709[] = \
YUV_SHADER_PROLOGUE \
BT709_SHADER_CONSTANTS \
NV21_SHADER_BODY \
@ -304,26 +332,73 @@ static const Uint8 GLES2_Fragment_TextureNV21BT709[] = \
#endif
/* Custom Android video format texture */
static const Uint8 GLES2_Fragment_TextureExternalOES[] = " \
#extension GL_OES_EGL_image_external : require\n\
precision mediump float; \
uniform samplerExternalOES u_texture; \
varying vec4 v_color; \
varying vec2 v_texCoord; \
\
void main() \
{ \
gl_FragColor = texture2D(u_texture, v_texCoord); \
gl_FragColor *= v_color; \
} \
";
static const char GLES2_Fragment_TextureExternalOES_Prologue[] = \
"#extension GL_OES_EGL_image_external : require\n" \
"\n" \
;
static const char GLES2_Fragment_TextureExternalOES[] = \
"uniform samplerExternalOES u_texture;\n" \
"varying mediump vec4 v_color;\n" \
"varying SDL_TEXCOORD_PRECISION vec2 v_texCoord;\n" \
"\n" \
"void main()\n" \
"{\n" \
" gl_FragColor = texture2D(u_texture, v_texCoord);\n" \
" gl_FragColor *= v_color;\n" \
"}\n" \
;
/* *INDENT-ON* */ /* clang-format on */
/*************************************************************************************************
* Shader selector *
*************************************************************************************************/
const Uint8 *GLES2_GetShader(GLES2_ShaderType type)
const char *GLES2_GetShaderPrologue(GLES2_ShaderType type)
{
switch (type) {
case GLES2_SHADER_FRAGMENT_TEXTURE_EXTERNAL_OES:
return GLES2_Fragment_TextureExternalOES_Prologue;
default:
return "";
}
}
const char *GLES2_GetShaderInclude(GLES2_ShaderIncludeType type)
{
switch (type) {
case GLES2_SHADER_FRAGMENT_INCLUDE_UNDEF_PRECISION:
return GLES2_Fragment_Include_Undef_Precision;
case GLES2_SHADER_FRAGMENT_INCLUDE_BEST_TEXCOORD_PRECISION:
return GLES2_Fragment_Include_Best_Texture_Precision;
case GLES2_SHADER_FRAGMENT_INCLUDE_MEDIUM_TEXCOORD_PRECISION:
return GLES2_Fragment_Include_Medium_Texture_Precision;
case GLES2_SHADER_FRAGMENT_INCLUDE_HIGH_TEXCOORD_PRECISION:
return GLES2_Fragment_Include_High_Texture_Precision;
default:
return "";
}
}
GLES2_ShaderIncludeType GLES2_GetTexCoordPrecisionEnumFromHint()
{
const char *texcoord_hint = SDL_GetHint("SDL_RENDER_OPENGLES2_TEXCOORD_PRECISION");
GLES2_ShaderIncludeType value = GLES2_SHADER_FRAGMENT_INCLUDE_BEST_TEXCOORD_PRECISION;
if (texcoord_hint) {
if (SDL_strcmp(texcoord_hint, "undefined") == 0) {
return GLES2_SHADER_FRAGMENT_INCLUDE_UNDEF_PRECISION;
}
if (SDL_strcmp(texcoord_hint, "high") == 0) {
return GLES2_SHADER_FRAGMENT_INCLUDE_HIGH_TEXCOORD_PRECISION;
}
if (SDL_strcmp(texcoord_hint, "medium") == 0) {
return GLES2_SHADER_FRAGMENT_INCLUDE_MEDIUM_TEXCOORD_PRECISION;
}
}
return value;
}
const char *GLES2_GetShader(GLES2_ShaderType type)
{
switch (type) {
case GLES2_SHADER_VERTEX_DEFAULT:

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -25,6 +25,15 @@
#if SDL_VIDEO_RENDER_OGL_ES2
typedef enum
{
GLES2_SHADER_FRAGMENT_INCLUDE_NONE = 0,
GLES2_SHADER_FRAGMENT_INCLUDE_BEST_TEXCOORD_PRECISION,
GLES2_SHADER_FRAGMENT_INCLUDE_MEDIUM_TEXCOORD_PRECISION,
GLES2_SHADER_FRAGMENT_INCLUDE_HIGH_TEXCOORD_PRECISION,
GLES2_SHADER_FRAGMENT_INCLUDE_UNDEF_PRECISION,
GLES2_SHADER_FRAGMENT_INCLUDE_COUNT
} GLES2_ShaderIncludeType;
typedef enum
{
@ -47,11 +56,15 @@ typedef enum
GLES2_SHADER_FRAGMENT_TEXTURE_NV21_BT601,
GLES2_SHADER_FRAGMENT_TEXTURE_NV21_BT709,
#endif
/* Shaders beyond this point are optional and not cached at render creation */
GLES2_SHADER_FRAGMENT_TEXTURE_EXTERNAL_OES,
GLES2_SHADER_COUNT
} GLES2_ShaderType;
const Uint8 *GLES2_GetShader(GLES2_ShaderType type);
extern const char *GLES2_GetShaderPrologue(GLES2_ShaderType type);
extern const char *GLES2_GetShaderInclude(GLES2_ShaderIncludeType type);
extern const char *GLES2_GetShader(GLES2_ShaderType type);
extern GLES2_ShaderIncludeType GLES2_GetTexCoordPrecisionEnumFromHint(void);
#endif /* SDL_VIDEO_RENDER_OGL_ES2 */

View file

@ -0,0 +1,682 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_RENDER_PS2
#include "../SDL_sysrender.h"
#include "SDL_hints.h"
#include <kernel.h>
#include <malloc.h>
#include <gsKit.h>
#include <dmaKit.h>
#include <gsToolkit.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeclaration-after-statement"
#include <gsInline.h>
#pragma GCC diagnostic pop
/* turn black GS Screen */
#define GS_BLACK GS_SETREG_RGBA(0x00, 0x00, 0x00, 0x80)
/* Size of Persistent drawbuffer (Single Buffered) */
#define RENDER_QUEUE_PER_POOLSIZE 1024 * 256 // 256K of persistent renderqueue
/* Size of Oneshot drawbuffer (Double Buffered, so it uses this size * 2) */
#define RENDER_QUEUE_OS_POOLSIZE 1024 * 1024 * 2 // 2048K of oneshot renderqueue
typedef struct
{
GSGLOBAL *gsGlobal;
uint64_t drawColor;
int32_t vsync_callback_id;
uint8_t vsync; /* 0 (Disabled), 1 (Enabled), 2 (Dynamic) */
} PS2_RenderData;
static int vsync_sema_id = 0;
/* PRIVATE METHODS */
static int vsync_handler()
{
iSignalSema(vsync_sema_id);
ExitHandler();
return 0;
}
/* Copy of gsKit_sync_flip, but without the 'flip' */
static void gsKit_sync(GSGLOBAL *gsGlobal)
{
if (!gsGlobal->FirstFrame) {
WaitSema(vsync_sema_id);
}
while (PollSema(vsync_sema_id) >= 0)
;
}
/* Copy of gsKit_sync_flip, but without the 'sync' */
static void gsKit_flip(GSGLOBAL *gsGlobal)
{
if (!gsGlobal->FirstFrame) {
if (gsGlobal->DoubleBuffering == GS_SETTING_ON) {
GS_SET_DISPFB2(gsGlobal->ScreenBuffer[gsGlobal->ActiveBuffer & 1] / 8192,
gsGlobal->Width / 64, gsGlobal->PSM, 0, 0);
gsGlobal->ActiveBuffer ^= 1;
}
}
gsKit_setactive(gsGlobal);
}
static int PixelFormatToPS2PSM(Uint32 format)
{
switch (format) {
case SDL_PIXELFORMAT_ABGR1555:
return GS_PSM_CT16;
default:
return GS_PSM_CT32;
}
}
static void PS2_WindowEvent(SDL_Renderer *renderer, const SDL_WindowEvent *event)
{
}
static int PS2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
{
GSTEXTURE *ps2_tex = (GSTEXTURE *)SDL_calloc(1, sizeof(GSTEXTURE));
if (ps2_tex == NULL) {
return SDL_OutOfMemory();
}
ps2_tex->Width = texture->w;
ps2_tex->Height = texture->h;
ps2_tex->PSM = PixelFormatToPS2PSM(texture->format);
ps2_tex->Mem = memalign(128, gsKit_texture_size_ee(ps2_tex->Width, ps2_tex->Height, ps2_tex->PSM));
if (!ps2_tex->Mem) {
SDL_free(ps2_tex);
return SDL_OutOfMemory();
}
texture->driverdata = ps2_tex;
return 0;
}
static int PS2_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect, void **pixels, int *pitch)
{
GSTEXTURE *ps2_texture = (GSTEXTURE *)texture->driverdata;
*pixels =
(void *)((Uint8 *)ps2_texture->Mem + rect->y * ps2_texture->Width * SDL_BYTESPERPIXEL(texture->format) +
rect->x * SDL_BYTESPERPIXEL(texture->format));
*pitch = ps2_texture->Width * SDL_BYTESPERPIXEL(texture->format);
return 0;
}
static void PS2_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
{
GSTEXTURE *ps2_texture = (GSTEXTURE *)texture->driverdata;
PS2_RenderData *data = (PS2_RenderData *)renderer->driverdata;
gsKit_TexManager_invalidate(data->gsGlobal, ps2_texture);
}
static int PS2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect, const void *pixels, int pitch)
{
const Uint8 *src;
Uint8 *dst;
int row, length, dpitch;
src = pixels;
PS2_LockTexture(renderer, texture, rect, (void **)&dst, &dpitch);
length = rect->w * SDL_BYTESPERPIXEL(texture->format);
if (length == pitch && length == dpitch) {
SDL_memcpy(dst, src, length * rect->h);
} else {
for (row = 0; row < rect->h; ++row) {
SDL_memcpy(dst, src, length);
src += pitch;
dst += dpitch;
}
}
PS2_UnlockTexture(renderer, texture);
return 0;
}
static void PS2_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *texture, SDL_ScaleMode scaleMode)
{
GSTEXTURE *ps2_texture = (GSTEXTURE *)texture->driverdata;
/*
set texture filtering according to scaleMode
suported hint values are nearest (0, default) or linear (1)
gskit scale mode is either GS_FILTER_NEAREST (good for tile-map)
or GS_FILTER_LINEAR (good for scaling)
*/
uint32_t gsKitScaleMode = (scaleMode == SDL_ScaleModeNearest
? GS_FILTER_NEAREST
: GS_FILTER_LINEAR);
ps2_texture->Filter = gsKitScaleMode;
}
static int PS2_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
{
return 0;
}
static int PS2_QueueSetViewport(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
{
return 0; /* nothing to do in this backend. */
}
static int PS2_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count)
{
PS2_RenderData *data = (PS2_RenderData *)renderer->driverdata;
GSPRIMPOINT *vertices = (GSPRIMPOINT *)SDL_AllocateRenderVertices(renderer, count * sizeof(GSPRIMPOINT), 4, &cmd->data.draw.first);
uint8_t colorR, colorG, colorB, colorA;
gs_rgbaq rgbaq;
int i;
if (vertices == NULL) {
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;
rgbaq = color_to_RGBAQ(colorR, colorG, colorB, colorA, 0.0f);
for (i = 0; i < count; i++, vertices++, points++) {
vertices->xyz2 = vertex_to_XYZ2(data->gsGlobal, points->x, points->y, 0);
vertices->rgbaq = rgbaq;
}
return 0;
}
static int PS2_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
const float *xy, int xy_stride, const SDL_Color *color, int color_stride, const float *uv, int uv_stride,
int num_vertices, const void *indices, int num_indices, int size_indices,
float scale_x, float scale_y)
{
int i;
int count = indices ? num_indices : num_vertices;
PS2_RenderData *data = (PS2_RenderData *)renderer->driverdata;
cmd->data.draw.count = count;
size_indices = indices ? size_indices : 0;
if (texture) {
GSPRIMUVPOINT *vertices = (GSPRIMUVPOINT *) SDL_AllocateRenderVertices(renderer, count * sizeof(GSPRIMUVPOINT), 4, &cmd->data.draw.first);
GSTEXTURE *ps2_tex = (GSTEXTURE *) texture->driverdata;
if (vertices == NULL) {
return -1;
}
for (i = 0; i < count; i++) {
int j;
float *xy_;
float *uv_;
SDL_Color col_;
if (size_indices == 4) {
j = ((const Uint32 *)indices)[i];
} else if (size_indices == 2) {
j = ((const Uint16 *)indices)[i];
} else if (size_indices == 1) {
j = ((const Uint8 *)indices)[i];
} else {
j = i;
}
xy_ = (float *)((char *)xy + j * xy_stride);
col_ = *(SDL_Color *)((char *)color + j * color_stride);
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->uv = vertex_to_UV(ps2_tex, uv_[0] * ps2_tex->Width, uv_[1] * ps2_tex->Height);
vertices++;
}
} else {
GSPRIMPOINT *vertices = (GSPRIMPOINT *)SDL_AllocateRenderVertices(renderer, count * sizeof(GSPRIMPOINT), 4, &cmd->data.draw.first);
if (vertices == NULL) {
return -1;
}
for (i = 0; i < count; i++) {
int j;
float *xy_;
SDL_Color col_;
if (size_indices == 4) {
j = ((const Uint32 *)indices)[i];
} else if (size_indices == 2) {
j = ((const Uint16 *)indices)[i];
} else if (size_indices == 1) {
j = ((const Uint8 *)indices)[i];
} else {
j = i;
}
xy_ = (float *)((char *)xy + j * xy_stride);
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++;
}
}
return 0;
}
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;
}
static int PS2_RenderSetClipRect(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
{
PS2_RenderData *data = (PS2_RenderData *)renderer->driverdata;
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);
}
return 0;
}
static int PS2_RenderSetDrawColor(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
{
int colorR, colorG, colorB, colorA;
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;
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;
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;
gsKit_clear(data->gsGlobal, GS_SETREG_RGBAQ(colorR, colorG, colorB, colorA, 0x00));
return 0;
}
static void PS2_SetBlendMode(PS2_RenderData *data, int blendMode)
{
#define A_COLOR_SOURCE 0
#define A_COLOR_DEST 1
#define A_COLOR_NULL 2
#define A_ALPHA_SOURCE 0
#define A_ALPHA_DEST 1
#define A_ALPHA_FIX 2
switch (blendMode) {
case SDL_BLENDMODE_NONE:
{
data->gsGlobal->PrimAlphaEnable = GS_SETTING_OFF;
break;
}
case SDL_BLENDMODE_BLEND:
{
gsKit_set_primalpha(data->gsGlobal, GS_SETREG_ALPHA(A_COLOR_SOURCE, A_COLOR_DEST, A_ALPHA_SOURCE, A_COLOR_DEST, 0), 0);
data->gsGlobal->PrimAlphaEnable = GS_SETTING_ON;
break;
}
case SDL_BLENDMODE_ADD:
{
gsKit_set_primalpha(data->gsGlobal, GS_SETREG_ALPHA(A_COLOR_SOURCE, A_COLOR_NULL, A_ALPHA_FIX, A_COLOR_DEST, 0x80), 0);
data->gsGlobal->PrimAlphaEnable = GS_SETTING_ON;
break;
}
case SDL_BLENDMODE_MUL:
case SDL_BLENDMODE_MOD:
{
/* We don't fully support MOD and MUL, however this is the best we can do */
gsKit_set_primalpha(data->gsGlobal, GS_SETREG_ALPHA(A_COLOR_DEST, A_COLOR_NULL, A_ALPHA_SOURCE, A_COLOR_SOURCE, 0x80), 0);
data->gsGlobal->PrimAlphaEnable = GS_SETTING_ON;
break;
}
}
}
static int PS2_RenderGeometry(SDL_Renderer *renderer, void *vertices, SDL_RenderCommand *cmd)
{
PS2_RenderData *data = (PS2_RenderData *)renderer->driverdata;
const size_t count = cmd->data.draw.count;
PS2_SetBlendMode(data, cmd->data.draw.blend);
if (cmd->data.draw.texture) {
const GSPRIMUVPOINT *verts = (GSPRIMUVPOINT *) (vertices + cmd->data.draw.first);
GSTEXTURE *ps2_tex = (GSTEXTURE *)cmd->data.draw.texture->driverdata;
gsKit_TexManager_bind(data->gsGlobal, ps2_tex);
gsKit_prim_list_triangle_goraud_texture_uv_3d(data->gsGlobal, ps2_tex, count, verts);
} else {
const GSPRIMPOINT *verts = (GSPRIMPOINT *)(vertices + cmd->data.draw.first);
gsKit_prim_list_triangle_gouraud_3d(data->gsGlobal, count, verts);
}
return 0;
}
int PS2_RenderLines(SDL_Renderer *renderer, void *vertices, SDL_RenderCommand *cmd)
{
PS2_RenderData *data = (PS2_RenderData *)renderer->driverdata;
const size_t count = cmd->data.draw.count;
const GSPRIMPOINT *verts = (GSPRIMPOINT *)(vertices + cmd->data.draw.first);
PS2_SetBlendMode(data, cmd->data.draw.blend);
gsKit_prim_list_line_goraud_3d(data->gsGlobal, count, verts);
/* We're done! */
return 0;
}
int PS2_RenderPoints(SDL_Renderer *renderer, void *vertices, SDL_RenderCommand *cmd)
{
PS2_RenderData *data = (PS2_RenderData *)renderer->driverdata;
const size_t count = cmd->data.draw.count;
const GSPRIMPOINT *verts = (GSPRIMPOINT *)(vertices + cmd->data.draw.first);
PS2_SetBlendMode(data, cmd->data.draw.blend);
gsKit_prim_list_points(data->gsGlobal, count, verts);
/* We're done! */
return 0;
}
static int PS2_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
{
while (cmd) {
switch (cmd->command) {
case SDL_RENDERCMD_SETVIEWPORT:
{
PS2_RenderSetViewPort(renderer, cmd);
break;
}
case SDL_RENDERCMD_SETCLIPRECT:
{
PS2_RenderSetClipRect(renderer, cmd);
break;
}
case SDL_RENDERCMD_SETDRAWCOLOR:
{
PS2_RenderSetDrawColor(renderer, cmd);
break;
}
case SDL_RENDERCMD_CLEAR:
{
PS2_RenderClear(renderer, cmd);
break;
}
case SDL_RENDERCMD_DRAW_POINTS:
{
PS2_RenderPoints(renderer, vertices, cmd);
break;
}
case SDL_RENDERCMD_DRAW_LINES:
{
PS2_RenderLines(renderer, vertices, cmd);
break;
}
case SDL_RENDERCMD_FILL_RECTS: /* unused */
break;
case SDL_RENDERCMD_COPY: /* unused */
break;
case SDL_RENDERCMD_COPY_EX: /* unused */
break;
case SDL_RENDERCMD_GEOMETRY:
{
PS2_RenderGeometry(renderer, vertices, cmd);
break;
}
case SDL_RENDERCMD_NO_OP:
break;
}
cmd = cmd->next;
}
return 0;
}
static int PS2_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
Uint32 format, void *pixels, int pitch)
{
return SDL_Unsupported();
}
static int PS2_RenderPresent(SDL_Renderer *renderer)
{
PS2_RenderData *data = (PS2_RenderData *)renderer->driverdata;
if (data->gsGlobal->DoubleBuffering == GS_SETTING_OFF) {
if (data->vsync == 2) { // Dynamic
gsKit_sync(data->gsGlobal);
} else if (data->vsync == 1) {
gsKit_vsync_wait();
}
gsKit_queue_exec(data->gsGlobal);
} else {
gsKit_queue_exec(data->gsGlobal);
gsKit_finish();
if (data->vsync == 2) { // Dynamic
gsKit_sync(data->gsGlobal);
} else if (data->vsync == 1) {
gsKit_vsync_wait();
}
gsKit_flip(data->gsGlobal);
}
gsKit_TexManager_nextFrame(data->gsGlobal);
gsKit_clear(data->gsGlobal, GS_BLACK);
return 0;
}
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) {
return;
}
if (ps2_texture == NULL) {
return;
}
// Free from vram
gsKit_TexManager_free(data->gsGlobal, ps2_texture);
SDL_free(ps2_texture->Mem);
SDL_free(ps2_texture);
texture->driverdata = NULL;
}
static void PS2_DestroyRenderer(SDL_Renderer *renderer)
{
PS2_RenderData *data = (PS2_RenderData *)renderer->driverdata;
if (data) {
gsKit_clear(data->gsGlobal, GS_BLACK);
gsKit_vram_clear(data->gsGlobal);
gsKit_deinit_global(data->gsGlobal);
gsKit_remove_vsync_handler(data->vsync_callback_id);
SDL_free(data);
}
if (vsync_sema_id >= 0) {
DeleteSema(vsync_sema_id);
}
SDL_free(renderer);
}
static int PS2_SetVSync(SDL_Renderer *renderer, const int vsync)
{
PS2_RenderData *data = (PS2_RenderData *)renderer->driverdata;
SDL_bool dynamicVsync = SDL_GetHintBoolean(SDL_HINT_PS2_DYNAMIC_VSYNC, SDL_FALSE);
data->vsync = vsync ? (dynamicVsync ? 2 : 1) : 0;
return 0;
}
static SDL_Renderer *PS2_CreateRenderer(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) {
PS2_DestroyRenderer(renderer);
SDL_OutOfMemory();
return NULL;
}
/* Specific gsKit init */
sema.init_count = 0;
sema.max_count = 1;
sema.option = 0;
vsync_sema_id = CreateSema(&sema);
gsGlobal = gsKit_init_global_custom(RENDER_QUEUE_OS_POOLSIZE, RENDER_QUEUE_PER_POOLSIZE);
gsGlobal->Mode = GS_MODE_NTSC;
gsGlobal->Height = 448;
gsGlobal->PSM = GS_PSM_CT24;
gsGlobal->PSMZ = GS_PSMZ_16S;
gsGlobal->ZBuffering = GS_SETTING_OFF;
gsGlobal->DoubleBuffering = GS_SETTING_ON;
gsGlobal->PrimAlphaEnable = GS_SETTING_ON;
gsGlobal->Dithering = GS_SETTING_OFF;
gsKit_set_primalpha(gsGlobal, GS_SETREG_ALPHA(0, 1, 0, 1, 0), 0);
dmaKit_init(D_CTRL_RELE_OFF, D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC, D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);
dmaKit_chan_init(DMA_CHANNEL_GIF);
gsKit_set_clamp(gsGlobal, GS_CMODE_REPEAT);
gsKit_vram_clear(gsGlobal);
gsKit_init_screen(gsGlobal);
gsKit_TexManager_init(gsGlobal);
data->vsync_callback_id = gsKit_add_vsync_handler(vsync_handler);
gsKit_mode_switch(gsGlobal, GS_ONESHOT);
gsKit_clear(gsGlobal, GS_BLACK);
data->gsGlobal = gsGlobal;
dynamicVsync = SDL_GetHintBoolean(SDL_HINT_PS2_DYNAMIC_VSYNC, SDL_FALSE);
data->vsync = flags & SDL_RENDERER_PRESENTVSYNC ? (dynamicVsync ? 2 : 1) : 0;
renderer->WindowEvent = PS2_WindowEvent;
renderer->CreateTexture = PS2_CreateTexture;
renderer->UpdateTexture = PS2_UpdateTexture;
renderer->LockTexture = PS2_LockTexture;
renderer->UnlockTexture = PS2_UnlockTexture;
renderer->SetTextureScaleMode = PS2_SetTextureScaleMode;
renderer->SetRenderTarget = PS2_SetRenderTarget;
renderer->QueueSetViewport = PS2_QueueSetViewport;
renderer->QueueSetDrawColor = PS2_QueueSetViewport;
renderer->QueueDrawPoints = PS2_QueueDrawPoints;
renderer->QueueDrawLines = PS2_QueueDrawPoints;
renderer->QueueGeometry = PS2_QueueGeometry;
renderer->RunCommandQueue = PS2_RunCommandQueue;
renderer->RenderReadPixels = PS2_RenderReadPixels;
renderer->RenderPresent = PS2_RenderPresent;
renderer->DestroyTexture = PS2_DestroyTexture;
renderer->DestroyRenderer = PS2_DestroyRenderer;
renderer->SetVSync = PS2_SetVSync;
renderer->info = PS2_RenderDriver.info;
renderer->driverdata = data;
renderer->window = window;
return renderer;
}
SDL_RenderDriver PS2_RenderDriver = {
.CreateRenderer = PS2_CreateRenderer,
.info = {
.name = "PS2 gsKit",
.flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE,
.num_texture_formats = 2,
.texture_formats = {
[0] = SDL_PIXELFORMAT_ABGR1555,
[1] = SDL_PIXELFORMAT_ABGR8888,
},
.max_texture_width = 1024,
.max_texture_height = 1024,
}
};
#endif /* SDL_VIDEO_RENDER_PS2 */
/* vi: set ts=4 sw=4 expandtab: */

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -25,10 +25,8 @@
#include "SDL_draw.h"
#include "SDL_blendfillrect.h"
static int
SDL_BlendFillRect_RGB555(SDL_Surface * dst, const SDL_Rect * rect,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
static int SDL_BlendFillRect_RGB555(SDL_Surface *dst, const SDL_Rect *rect,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
unsigned inva = 0xff - a;
@ -52,9 +50,8 @@ SDL_BlendFillRect_RGB555(SDL_Surface * dst, const SDL_Rect * rect,
return 0;
}
static int
SDL_BlendFillRect_RGB565(SDL_Surface * dst, const SDL_Rect * rect,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
static int SDL_BlendFillRect_RGB565(SDL_Surface *dst, const SDL_Rect *rect,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
unsigned inva = 0xff - a;
@ -78,9 +75,8 @@ SDL_BlendFillRect_RGB565(SDL_Surface * dst, const SDL_Rect * rect,
return 0;
}
static int
SDL_BlendFillRect_RGB888(SDL_Surface * dst, const SDL_Rect * rect,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
static int SDL_BlendFillRect_RGB888(SDL_Surface *dst, const SDL_Rect *rect,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
unsigned inva = 0xff - a;
@ -104,9 +100,8 @@ SDL_BlendFillRect_RGB888(SDL_Surface * dst, const SDL_Rect * rect,
return 0;
}
static int
SDL_BlendFillRect_ARGB8888(SDL_Surface * dst, const SDL_Rect * rect,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
static int SDL_BlendFillRect_ARGB8888(SDL_Surface *dst, const SDL_Rect *rect,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
unsigned inva = 0xff - a;
@ -130,9 +125,8 @@ SDL_BlendFillRect_ARGB8888(SDL_Surface * dst, const SDL_Rect * rect,
return 0;
}
static int
SDL_BlendFillRect_RGB(SDL_Surface * dst, const SDL_Rect * rect,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
static int SDL_BlendFillRect_RGB(SDL_Surface *dst, const SDL_Rect *rect,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
SDL_PixelFormat *fmt = dst->format;
unsigned inva = 0xff - a;
@ -181,9 +175,8 @@ SDL_BlendFillRect_RGB(SDL_Surface * dst, const SDL_Rect * rect,
}
}
static int
SDL_BlendFillRect_RGBA(SDL_Surface * dst, const SDL_Rect * rect,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
static int SDL_BlendFillRect_RGBA(SDL_Surface *dst, const SDL_Rect *rect,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
SDL_PixelFormat *fmt = dst->format;
unsigned inva = 0xff - a;
@ -213,13 +206,12 @@ SDL_BlendFillRect_RGBA(SDL_Surface * dst, const SDL_Rect * rect,
}
}
int
SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
int SDL_BlendFillRect(SDL_Surface *dst, const SDL_Rect *rect,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
SDL_Rect clipped;
if (!dst) {
if (dst == NULL) {
return SDL_InvalidParamError("SDL_BlendFillRect(): dst");
}
@ -280,17 +272,16 @@ SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect,
}
}
int
SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect * rects, int count,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
int SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
SDL_Rect rect;
int i;
int (*func)(SDL_Surface * dst, const SDL_Rect * rect,
int (*func)(SDL_Surface * dst, const SDL_Rect *rect,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
int status = 0;
if (!dst) {
if (dst == NULL) {
return SDL_InvalidParamError("SDL_BlendFillRects(): dst");
}
@ -334,7 +325,7 @@ SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect * rects, int count,
break;
}
if (!func) {
if (func == NULL) {
if (!dst->format->Amask) {
func = SDL_BlendFillRect_RGB;
} else {

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -24,9 +24,8 @@
#include "../../SDL_internal.h"
extern int SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern int SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect * rects, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern int SDL_BlendFillRect(SDL_Surface *dst, const SDL_Rect *rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern int SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
#endif /* SDL_blendfillrect_h_ */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -26,11 +26,9 @@
#include "SDL_blendline.h"
#include "SDL_blendpoint.h"
static void
SDL_BlendLine_RGB2(SDL_Surface * dst, int x1, int y1, int x2, int y2,
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
SDL_bool draw_end)
static void SDL_BlendLine_RGB2(SDL_Surface *dst, int x1, int y1, int x2, int y2,
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
SDL_bool draw_end)
{
const SDL_PixelFormat *fmt = dst->format;
unsigned r, g, b, a, inva;
@ -133,10 +131,9 @@ SDL_BlendLine_RGB2(SDL_Surface * dst, int x1, int y1, int x2, int y2,
}
}
static void
SDL_BlendLine_RGB555(SDL_Surface * dst, int x1, int y1, int x2, int y2,
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
SDL_bool draw_end)
static void SDL_BlendLine_RGB555(SDL_Surface *dst, int x1, int y1, int x2, int y2,
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
SDL_bool draw_end)
{
unsigned r, g, b, a, inva;
@ -238,10 +235,9 @@ SDL_BlendLine_RGB555(SDL_Surface * dst, int x1, int y1, int x2, int y2,
}
}
static void
SDL_BlendLine_RGB565(SDL_Surface * dst, int x1, int y1, int x2, int y2,
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
SDL_bool draw_end)
static void SDL_BlendLine_RGB565(SDL_Surface *dst, int x1, int y1, int x2, int y2,
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
SDL_bool draw_end)
{
unsigned r, g, b, a, inva;
@ -343,10 +339,9 @@ SDL_BlendLine_RGB565(SDL_Surface * dst, int x1, int y1, int x2, int y2,
}
}
static void
SDL_BlendLine_RGB4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
SDL_bool draw_end)
static void SDL_BlendLine_RGB4(SDL_Surface *dst, int x1, int y1, int x2, int y2,
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
SDL_bool draw_end)
{
const SDL_PixelFormat *fmt = dst->format;
unsigned r, g, b, a, inva;
@ -449,10 +444,9 @@ SDL_BlendLine_RGB4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
}
}
static void
SDL_BlendLine_RGBA4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
SDL_bool draw_end)
static void SDL_BlendLine_RGBA4(SDL_Surface *dst, int x1, int y1, int x2, int y2,
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
SDL_bool draw_end)
{
const SDL_PixelFormat *fmt = dst->format;
unsigned r, g, b, a, inva;
@ -555,10 +549,9 @@ SDL_BlendLine_RGBA4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
}
}
static void
SDL_BlendLine_RGB888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
SDL_bool draw_end)
static void SDL_BlendLine_RGB888(SDL_Surface *dst, int x1, int y1, int x2, int y2,
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
SDL_bool draw_end)
{
unsigned r, g, b, a, inva;
@ -660,10 +653,9 @@ SDL_BlendLine_RGB888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
}
}
static void
SDL_BlendLine_ARGB8888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
SDL_bool draw_end)
static void SDL_BlendLine_ARGB8888(SDL_Surface *dst, int x1, int y1, int x2, int y2,
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
SDL_bool draw_end)
{
unsigned r, g, b, a, inva;
@ -765,14 +757,13 @@ SDL_BlendLine_ARGB8888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
}
}
typedef void (*BlendLineFunc) (SDL_Surface * dst,
int x1, int y1, int x2, int y2,
SDL_BlendMode blendMode,
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
SDL_bool draw_end);
typedef void (*BlendLineFunc)(SDL_Surface *dst,
int x1, int y1, int x2, int y2,
SDL_BlendMode blendMode,
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
SDL_bool draw_end);
static BlendLineFunc
SDL_CalculateBlendLineFunc(const SDL_PixelFormat * fmt)
static BlendLineFunc SDL_CalculateBlendLineFunc(const SDL_PixelFormat *fmt)
{
switch (fmt->BytesPerPixel) {
case 2:
@ -802,18 +793,17 @@ SDL_CalculateBlendLineFunc(const SDL_PixelFormat * fmt)
return NULL;
}
int
SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
int SDL_BlendLine(SDL_Surface *dst, int x1, int y1, int x2, int y2,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
BlendLineFunc func;
if (!dst) {
if (dst == NULL) {
return SDL_InvalidParamError("SDL_BlendLine(): dst");
}
func = SDL_CalculateBlendLineFunc(dst->format);
if (!func) {
if (func == NULL) {
return SDL_SetError("SDL_BlendLine(): Unsupported surface format");
}
@ -827,9 +817,8 @@ SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2,
return 0;
}
int
SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
int SDL_BlendLines(SDL_Surface *dst, const SDL_Point *points, int count,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
int i;
int x1, y1;
@ -837,18 +826,18 @@ SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count,
SDL_bool draw_end;
BlendLineFunc func;
if (!dst) {
if (dst == NULL) {
return SDL_SetError("SDL_BlendLines(): Passed NULL destination surface");
}
func = SDL_CalculateBlendLineFunc(dst->format);
if (!func) {
if (func == NULL) {
return SDL_SetError("SDL_BlendLines(): Unsupported surface format");
}
for (i = 1; i < count; ++i) {
x1 = points[i-1].x;
y1 = points[i-1].y;
x1 = points[i - 1].x;
y1 = points[i - 1].y;
x2 = points[i].x;
y2 = points[i].y;
@ -863,8 +852,8 @@ SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count,
func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, draw_end);
}
if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
SDL_BlendPoint(dst, points[count-1].x, points[count-1].y,
if (points[0].x != points[count - 1].x || points[0].y != points[count - 1].y) {
SDL_BlendPoint(dst, points[count - 1].x, points[count - 1].y,
blendMode, r, g, b, a);
}
return 0;

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -24,9 +24,8 @@
#include "../../SDL_internal.h"
extern int SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern int SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern int SDL_BlendLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern int SDL_BlendLines(SDL_Surface *dst, const SDL_Point *points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
#endif /* SDL_blendline_h_ */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -25,10 +25,8 @@
#include "SDL_draw.h"
#include "SDL_blendpoint.h"
static int
SDL_BlendPoint_RGB555(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
Uint8 g, Uint8 b, Uint8 a)
static int SDL_BlendPoint_RGB555(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
Uint8 g, Uint8 b, Uint8 a)
{
unsigned inva = 0xff - a;
@ -52,9 +50,8 @@ SDL_BlendPoint_RGB555(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode,
return 0;
}
static int
SDL_BlendPoint_RGB565(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
Uint8 g, Uint8 b, Uint8 a)
static int SDL_BlendPoint_RGB565(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
Uint8 g, Uint8 b, Uint8 a)
{
unsigned inva = 0xff - a;
@ -78,9 +75,8 @@ SDL_BlendPoint_RGB565(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode,
return 0;
}
static int
SDL_BlendPoint_RGB888(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
Uint8 g, Uint8 b, Uint8 a)
static int SDL_BlendPoint_RGB888(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
Uint8 g, Uint8 b, Uint8 a)
{
unsigned inva = 0xff - a;
@ -104,9 +100,8 @@ SDL_BlendPoint_RGB888(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode,
return 0;
}
static int
SDL_BlendPoint_ARGB8888(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode,
Uint8 r, Uint8 g, Uint8 b, Uint8 a)
static int SDL_BlendPoint_ARGB8888(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode,
Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
unsigned inva = 0xff - a;
@ -130,9 +125,8 @@ SDL_BlendPoint_ARGB8888(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode
return 0;
}
static int
SDL_BlendPoint_RGB(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
Uint8 g, Uint8 b, Uint8 a)
static int SDL_BlendPoint_RGB(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
Uint8 g, Uint8 b, Uint8 a)
{
SDL_PixelFormat *fmt = dst->format;
unsigned inva = 0xff - a;
@ -181,9 +175,8 @@ SDL_BlendPoint_RGB(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uin
}
}
static int
SDL_BlendPoint_RGBA(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
Uint8 g, Uint8 b, Uint8 a)
static int SDL_BlendPoint_RGBA(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
Uint8 g, Uint8 b, Uint8 a)
{
SDL_PixelFormat *fmt = dst->format;
unsigned inva = 0xff - a;
@ -213,11 +206,10 @@ SDL_BlendPoint_RGBA(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Ui
}
}
int
SDL_BlendPoint(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
Uint8 g, Uint8 b, Uint8 a)
int SDL_BlendPoint(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
Uint8 g, Uint8 b, Uint8 a)
{
if (!dst) {
if (dst == NULL) {
return SDL_InvalidParamError("SDL_BlendPoint(): dst");
}
@ -274,9 +266,8 @@ SDL_BlendPoint(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r
}
}
int
SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
int SDL_BlendPoints(SDL_Surface *dst, const SDL_Point *points, int count,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
int minx, miny;
int maxx, maxy;
@ -286,7 +277,7 @@ 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) {
if (dst == NULL) {
return SDL_InvalidParamError("SDL_BlendPoints(): dst");
}
@ -332,7 +323,7 @@ SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count,
break;
}
if (!func) {
if (func == NULL) {
if (!dst->format->Amask) {
func = SDL_BlendPoint_RGB;
} else {

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -24,9 +24,8 @@
#include "../../SDL_internal.h"
extern int SDL_BlendPoint(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern int SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern int SDL_BlendPoint(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern int SDL_BlendPoints(SDL_Surface *dst, const SDL_Point *points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
#endif /* SDL_blendpoint_h_ */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -26,77 +26,90 @@
* and in the blend and add case, the RGB values are premultiplied by a.
*/
#define DRAW_MUL(_a, _b) (((unsigned)(_a)*(_b))/255)
#define DRAW_MUL(_a, _b) (((unsigned)(_a) * (_b)) / 255)
#define DRAW_FASTSETPIXEL(type) \
*pixel = (type) color
*pixel = (type)color
#define DRAW_FASTSETPIXEL1 DRAW_FASTSETPIXEL(Uint8)
#define DRAW_FASTSETPIXEL2 DRAW_FASTSETPIXEL(Uint16)
#define DRAW_FASTSETPIXEL4 DRAW_FASTSETPIXEL(Uint32)
#define DRAW_FASTSETPIXELXY(x, y, type, bpp, color) \
*(type *)((Uint8 *)dst->pixels + (y) * dst->pitch \
+ (x) * bpp) = (type) color
*(type *)((Uint8 *)dst->pixels + (y)*dst->pitch + (x)*bpp) = (type)color
#define DRAW_FASTSETPIXELXY1(x, y) DRAW_FASTSETPIXELXY(x, y, Uint8, 1, color)
#define DRAW_FASTSETPIXELXY2(x, y) DRAW_FASTSETPIXELXY(x, y, Uint16, 2, color)
#define DRAW_FASTSETPIXELXY4(x, y) DRAW_FASTSETPIXELXY(x, y, Uint32, 4, color)
#define DRAW_SETPIXEL(setpixel) \
do { \
unsigned sr = r, sg = g, sb = b, sa = a; (void) sa; \
setpixel; \
} while (0)
#define DRAW_SETPIXEL(setpixel) \
do { \
unsigned sr = r, sg = g, sb = b, sa = a; \
(void)sa; \
setpixel; \
} while (0)
#define DRAW_SETPIXEL_BLEND(getpixel, setpixel) \
do { \
unsigned sr, sg, sb, sa = 0xFF; \
getpixel; \
sr = DRAW_MUL(inva, sr) + r; \
sg = DRAW_MUL(inva, sg) + g; \
sb = DRAW_MUL(inva, sb) + b; \
sa = DRAW_MUL(inva, sa) + a; \
setpixel; \
} while (0)
do { \
unsigned sr, sg, sb, sa = 0xFF; \
getpixel; \
sr = DRAW_MUL(inva, sr) + r; \
sg = DRAW_MUL(inva, sg) + g; \
sb = DRAW_MUL(inva, sb) + b; \
sa = DRAW_MUL(inva, sa) + a; \
setpixel; \
} while (0)
#define DRAW_SETPIXEL_ADD(getpixel, setpixel) \
do { \
unsigned sr, sg, sb, sa; (void) sa; \
getpixel; \
sr += r; if (sr > 0xff) sr = 0xff; \
sg += g; if (sg > 0xff) sg = 0xff; \
sb += b; if (sb > 0xff) sb = 0xff; \
setpixel; \
} while (0)
do { \
unsigned sr, sg, sb, sa; \
(void)sa; \
getpixel; \
sr += r; \
if (sr > 0xff) \
sr = 0xff; \
sg += g; \
if (sg > 0xff) \
sg = 0xff; \
sb += b; \
if (sb > 0xff) \
sb = 0xff; \
setpixel; \
} while (0)
#define DRAW_SETPIXEL_MOD(getpixel, setpixel) \
do { \
unsigned sr, sg, sb, sa; (void) sa; \
getpixel; \
sr = DRAW_MUL(sr, r); \
sg = DRAW_MUL(sg, g); \
sb = DRAW_MUL(sb, b); \
setpixel; \
} while (0)
do { \
unsigned sr, sg, sb, sa; \
(void)sa; \
getpixel; \
sr = DRAW_MUL(sr, r); \
sg = DRAW_MUL(sg, g); \
sb = DRAW_MUL(sb, b); \
setpixel; \
} while (0)
#define DRAW_SETPIXEL_MUL(getpixel, setpixel) \
do { \
unsigned sr, sg, sb, sa; sa = 0xFF; \
getpixel; \
sr = DRAW_MUL(sr, r) + DRAW_MUL(inva, sr); if (sr > 0xff) sr = 0xff; \
sg = DRAW_MUL(sg, g) + DRAW_MUL(inva, sg); if (sg > 0xff) sg = 0xff; \
sb = DRAW_MUL(sb, b) + DRAW_MUL(inva, sb); if (sb > 0xff) sb = 0xff; \
sa = DRAW_MUL(sa, a) + DRAW_MUL(inva, sa); if (sa > 0xff) sa = 0xff; \
setpixel; \
} while (0)
#define DRAW_SETPIXEL_MUL(getpixel, setpixel) \
do { \
unsigned sr, sg, sb, sa; \
(void)sa; \
getpixel; \
sr = DRAW_MUL(sr, r) + DRAW_MUL(inva, sr); \
if (sr > 0xff) \
sr = 0xff; \
sg = DRAW_MUL(sg, g) + DRAW_MUL(inva, sg); \
if (sg > 0xff) \
sg = 0xff; \
sb = DRAW_MUL(sb, b) + DRAW_MUL(inva, sb); \
if (sb > 0xff) \
sb = 0xff; \
setpixel; \
} while (0)
#define DRAW_SETPIXELXY(x, y, type, bpp, op) \
do { \
type *pixel = (type *)((Uint8 *)dst->pixels + (y) * dst->pitch \
+ (x) * bpp); \
op; \
} while (0)
#define DRAW_SETPIXELXY(x, y, type, bpp, op) \
do { \
type *pixel = (type *)((Uint8 *)dst->pixels + (y)*dst->pitch + (x)*bpp); \
op; \
} while (0)
/*
* Define draw operators for RGB555
@ -105,19 +118,19 @@ do { \
#define DRAW_SETPIXEL_RGB555 \
DRAW_SETPIXEL(RGB555_FROM_RGB(*pixel, sr, sg, sb))
#define DRAW_SETPIXEL_BLEND_RGB555 \
#define DRAW_SETPIXEL_BLEND_RGB555 \
DRAW_SETPIXEL_BLEND(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
RGB555_FROM_RGB(*pixel, sr, sg, sb))
#define DRAW_SETPIXEL_ADD_RGB555 \
#define DRAW_SETPIXEL_ADD_RGB555 \
DRAW_SETPIXEL_ADD(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
RGB555_FROM_RGB(*pixel, sr, sg, sb))
#define DRAW_SETPIXEL_MOD_RGB555 \
#define DRAW_SETPIXEL_MOD_RGB555 \
DRAW_SETPIXEL_MOD(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
RGB555_FROM_RGB(*pixel, sr, sg, sb))
#define DRAW_SETPIXEL_MUL_RGB555 \
#define DRAW_SETPIXEL_MUL_RGB555 \
DRAW_SETPIXEL_MUL(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
RGB555_FROM_RGB(*pixel, sr, sg, sb))
@ -143,19 +156,19 @@ do { \
#define DRAW_SETPIXEL_RGB565 \
DRAW_SETPIXEL(RGB565_FROM_RGB(*pixel, sr, sg, sb))
#define DRAW_SETPIXEL_BLEND_RGB565 \
#define DRAW_SETPIXEL_BLEND_RGB565 \
DRAW_SETPIXEL_BLEND(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
RGB565_FROM_RGB(*pixel, sr, sg, sb))
#define DRAW_SETPIXEL_ADD_RGB565 \
#define DRAW_SETPIXEL_ADD_RGB565 \
DRAW_SETPIXEL_ADD(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
RGB565_FROM_RGB(*pixel, sr, sg, sb))
#define DRAW_SETPIXEL_MOD_RGB565 \
#define DRAW_SETPIXEL_MOD_RGB565 \
DRAW_SETPIXEL_MOD(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
RGB565_FROM_RGB(*pixel, sr, sg, sb))
#define DRAW_SETPIXEL_MUL_RGB565 \
#define DRAW_SETPIXEL_MUL_RGB565 \
DRAW_SETPIXEL_MUL(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
RGB565_FROM_RGB(*pixel, sr, sg, sb))
@ -181,19 +194,19 @@ do { \
#define DRAW_SETPIXEL_RGB888 \
DRAW_SETPIXEL(RGB888_FROM_RGB(*pixel, sr, sg, sb))
#define DRAW_SETPIXEL_BLEND_RGB888 \
#define DRAW_SETPIXEL_BLEND_RGB888 \
DRAW_SETPIXEL_BLEND(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
RGB888_FROM_RGB(*pixel, sr, sg, sb))
#define DRAW_SETPIXEL_ADD_RGB888 \
#define DRAW_SETPIXEL_ADD_RGB888 \
DRAW_SETPIXEL_ADD(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
RGB888_FROM_RGB(*pixel, sr, sg, sb))
#define DRAW_SETPIXEL_MOD_RGB888 \
#define DRAW_SETPIXEL_MOD_RGB888 \
DRAW_SETPIXEL_MOD(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
RGB888_FROM_RGB(*pixel, sr, sg, sb))
#define DRAW_SETPIXEL_MUL_RGB888 \
#define DRAW_SETPIXEL_MUL_RGB888 \
DRAW_SETPIXEL_MUL(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
RGB888_FROM_RGB(*pixel, sr, sg, sb))
@ -219,19 +232,19 @@ do { \
#define DRAW_SETPIXEL_ARGB8888 \
DRAW_SETPIXEL(ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
#define DRAW_SETPIXEL_BLEND_ARGB8888 \
#define DRAW_SETPIXEL_BLEND_ARGB8888 \
DRAW_SETPIXEL_BLEND(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
#define DRAW_SETPIXEL_ADD_ARGB8888 \
#define DRAW_SETPIXEL_ADD_ARGB8888 \
DRAW_SETPIXEL_ADD(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
#define DRAW_SETPIXEL_MOD_ARGB8888 \
#define DRAW_SETPIXEL_MOD_ARGB8888 \
DRAW_SETPIXEL_MOD(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
#define DRAW_SETPIXEL_MUL_ARGB8888 \
#define DRAW_SETPIXEL_MUL_ARGB8888 \
DRAW_SETPIXEL_MUL(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
@ -257,19 +270,19 @@ do { \
#define DRAW_SETPIXEL_RGB \
DRAW_SETPIXEL(PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
#define DRAW_SETPIXEL_BLEND_RGB \
#define DRAW_SETPIXEL_BLEND_RGB \
DRAW_SETPIXEL_BLEND(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \
PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
#define DRAW_SETPIXEL_ADD_RGB \
#define DRAW_SETPIXEL_ADD_RGB \
DRAW_SETPIXEL_ADD(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \
PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
#define DRAW_SETPIXEL_MOD_RGB \
#define DRAW_SETPIXEL_MOD_RGB \
DRAW_SETPIXEL_MOD(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \
PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
#define DRAW_SETPIXEL_MUL_RGB \
#define DRAW_SETPIXEL_MUL_RGB \
DRAW_SETPIXEL_MUL(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \
PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
@ -303,7 +316,6 @@ do { \
#define DRAW_SETPIXELXY4_MUL_RGB(x, y) \
DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MUL_RGB)
/*
* Define draw operators for general RGBA
*/
@ -311,19 +323,19 @@ do { \
#define DRAW_SETPIXEL_RGBA \
DRAW_SETPIXEL(PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
#define DRAW_SETPIXEL_BLEND_RGBA \
#define DRAW_SETPIXEL_BLEND_RGBA \
DRAW_SETPIXEL_BLEND(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \
PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
#define DRAW_SETPIXEL_ADD_RGBA \
#define DRAW_SETPIXEL_ADD_RGBA \
DRAW_SETPIXEL_ADD(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \
PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
#define DRAW_SETPIXEL_MOD_RGBA \
#define DRAW_SETPIXEL_MOD_RGBA \
DRAW_SETPIXEL_MOD(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \
PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
#define DRAW_SETPIXEL_MUL_RGBA \
#define DRAW_SETPIXEL_MUL_RGBA \
DRAW_SETPIXEL_MUL(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \
PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
@ -349,284 +361,301 @@ do { \
#define ABS(_x) ((_x) < 0 ? -(_x) : (_x))
/* Horizontal line */
#define HLINE(type, op, draw_end) \
{ \
int length; \
int pitch = (dst->pitch / dst->format->BytesPerPixel); \
type *pixel; \
if (x1 <= x2) { \
pixel = (type *)dst->pixels + y1 * pitch + x1; \
length = draw_end ? (x2-x1+1) : (x2-x1); \
} else { \
pixel = (type *)dst->pixels + y1 * pitch + x2; \
if (!draw_end) { \
++pixel; \
} \
length = draw_end ? (x1-x2+1) : (x1-x2); \
} \
while (length--) { \
op; \
++pixel; \
} \
}
#define HLINE(type, op, draw_end) \
{ \
int length; \
int pitch = (dst->pitch / dst->format->BytesPerPixel); \
type *pixel; \
if (x1 <= x2) { \
pixel = (type *)dst->pixels + y1 * pitch + x1; \
length = draw_end ? (x2 - x1 + 1) : (x2 - x1); \
} else { \
pixel = (type *)dst->pixels + y1 * pitch + x2; \
if (!draw_end) { \
++pixel; \
} \
length = draw_end ? (x1 - x2 + 1) : (x1 - x2); \
} \
while (length--) { \
op; \
++pixel; \
} \
}
/* Vertical line */
#define VLINE(type, op, draw_end) \
{ \
int length; \
int pitch = (dst->pitch / dst->format->BytesPerPixel); \
type *pixel; \
if (y1 <= y2) { \
pixel = (type *)dst->pixels + y1 * pitch + x1; \
length = draw_end ? (y2-y1+1) : (y2-y1); \
} else { \
pixel = (type *)dst->pixels + y2 * pitch + x1; \
if (!draw_end) { \
pixel += pitch; \
} \
length = draw_end ? (y1-y2+1) : (y1-y2); \
} \
while (length--) { \
op; \
pixel += pitch; \
} \
}
#define VLINE(type, op, draw_end) \
{ \
int length; \
int pitch = (dst->pitch / dst->format->BytesPerPixel); \
type *pixel; \
if (y1 <= y2) { \
pixel = (type *)dst->pixels + y1 * pitch + x1; \
length = draw_end ? (y2 - y1 + 1) : (y2 - y1); \
} else { \
pixel = (type *)dst->pixels + y2 * pitch + x1; \
if (!draw_end) { \
pixel += pitch; \
} \
length = draw_end ? (y1 - y2 + 1) : (y1 - y2); \
} \
while (length--) { \
op; \
pixel += pitch; \
} \
}
/* Diagonal line */
#define DLINE(type, op, draw_end) \
{ \
int length; \
int pitch = (dst->pitch / dst->format->BytesPerPixel); \
type *pixel; \
if (y1 <= y2) { \
pixel = (type *)dst->pixels + y1 * pitch + x1; \
if (x1 <= x2) { \
++pitch; \
} else { \
--pitch; \
} \
length = (y2-y1); \
} else { \
pixel = (type *)dst->pixels + y2 * pitch + x2; \
if (x2 <= x1) { \
++pitch; \
} else { \
--pitch; \
} \
if (!draw_end) { \
pixel += pitch; \
} \
length = (y1-y2); \
} \
if (draw_end) { \
++length; \
} \
while (length--) { \
op; \
pixel += pitch; \
} \
}
#define DLINE(type, op, draw_end) \
{ \
int length; \
int pitch = (dst->pitch / dst->format->BytesPerPixel); \
type *pixel; \
if (y1 <= y2) { \
pixel = (type *)dst->pixels + y1 * pitch + x1; \
if (x1 <= x2) { \
++pitch; \
} else { \
--pitch; \
} \
length = (y2 - y1); \
} else { \
pixel = (type *)dst->pixels + y2 * pitch + x2; \
if (x2 <= x1) { \
++pitch; \
} else { \
--pitch; \
} \
if (!draw_end) { \
pixel += pitch; \
} \
length = (y1 - y2); \
} \
if (draw_end) { \
++length; \
} \
while (length--) { \
op; \
pixel += pitch; \
} \
}
/* Bresenham's line algorithm */
#define BLINE(x1, y1, x2, y2, op, draw_end) \
{ \
int i, deltax, deltay, numpixels; \
int d, dinc1, dinc2; \
int x, xinc1, xinc2; \
int y, yinc1, yinc2; \
\
deltax = ABS(x2 - x1); \
deltay = ABS(y2 - y1); \
\
if (deltax >= deltay) { \
numpixels = deltax + 1; \
d = (2 * deltay) - deltax; \
dinc1 = deltay * 2; \
dinc2 = (deltay - deltax) * 2; \
xinc1 = 1; \
xinc2 = 1; \
yinc1 = 0; \
yinc2 = 1; \
} else { \
numpixels = deltay + 1; \
d = (2 * deltax) - deltay; \
dinc1 = deltax * 2; \
dinc2 = (deltax - deltay) * 2; \
xinc1 = 0; \
xinc2 = 1; \
yinc1 = 1; \
yinc2 = 1; \
} \
\
if (x1 > x2) { \
xinc1 = -xinc1; \
xinc2 = -xinc2; \
} \
if (y1 > y2) { \
yinc1 = -yinc1; \
yinc2 = -yinc2; \
} \
\
x = x1; \
y = y1; \
\
if (!draw_end) { \
--numpixels; \
} \
for (i = 0; i < numpixels; ++i) { \
op(x, y); \
if (d < 0) { \
d += dinc1; \
x += xinc1; \
y += yinc1; \
} else { \
d += dinc2; \
x += xinc2; \
y += yinc2; \
} \
} \
}
{ \
int i, deltax, deltay, numpixels; \
int d, dinc1, dinc2; \
int x, xinc1, xinc2; \
int y, yinc1, yinc2; \
\
deltax = ABS(x2 - x1); \
deltay = ABS(y2 - y1); \
\
if (deltax >= deltay) { \
numpixels = deltax + 1; \
d = (2 * deltay) - deltax; \
dinc1 = deltay * 2; \
dinc2 = (deltay - deltax) * 2; \
xinc1 = 1; \
xinc2 = 1; \
yinc1 = 0; \
yinc2 = 1; \
} else { \
numpixels = deltay + 1; \
d = (2 * deltax) - deltay; \
dinc1 = deltax * 2; \
dinc2 = (deltax - deltay) * 2; \
xinc1 = 0; \
xinc2 = 1; \
yinc1 = 1; \
yinc2 = 1; \
} \
\
if (x1 > x2) { \
xinc1 = -xinc1; \
xinc2 = -xinc2; \
} \
if (y1 > y2) { \
yinc1 = -yinc1; \
yinc2 = -yinc2; \
} \
\
x = x1; \
y = y1; \
\
if (!draw_end) { \
--numpixels; \
} \
for (i = 0; i < numpixels; ++i) { \
op(x, y); \
if (d < 0) { \
d += dinc1; \
x += xinc1; \
y += yinc1; \
} else { \
d += dinc2; \
x += xinc2; \
y += yinc2; \
} \
} \
}
/* Xiaolin Wu's line algorithm, based on Michael Abrash's implementation */
#define WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
{ \
Uint16 ErrorAdj, ErrorAcc; \
Uint16 ErrorAccTemp, Weighting; \
int DeltaX, DeltaY, Temp, XDir; \
unsigned r, g, b, a, inva; \
\
/* Draw the initial pixel, which is always exactly intersected by \
the line and so needs no weighting */ \
opaque_op(x1, y1); \
\
/* Draw the final pixel, which is always exactly intersected by the line \
and so needs no weighting */ \
if (draw_end) { \
opaque_op(x2, y2); \
} \
\
/* Make sure the line runs top to bottom */ \
if (y1 > y2) { \
Temp = y1; y1 = y2; y2 = Temp; \
Temp = x1; x1 = x2; x2 = Temp; \
} \
DeltaY = y2 - y1; \
\
if ((DeltaX = x2 - x1) >= 0) { \
XDir = 1; \
} else { \
XDir = -1; \
DeltaX = -DeltaX; /* make DeltaX positive */ \
} \
\
/* line is not horizontal, diagonal, or vertical */ \
ErrorAcc = 0; /* initialize the line error accumulator to 0 */ \
\
/* Is this an X-major or Y-major line? */ \
if (DeltaY > DeltaX) { \
/* Y-major line; calculate 16-bit fixed-point fractional part of a \
pixel that X advances each time Y advances 1 pixel, truncating the \
result so that we won't overrun the endpoint along the X axis */ \
ErrorAdj = ((unsigned long) DeltaX << 16) / (unsigned long) DeltaY; \
/* Draw all pixels other than the first and last */ \
while (--DeltaY) { \
ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */ \
ErrorAcc += ErrorAdj; /* calculate error for next pixel */ \
if (ErrorAcc <= ErrorAccTemp) { \
/* The error accumulator turned over, so advance the X coord */ \
x1 += XDir; \
} \
y1++; /* Y-major, so always advance Y */ \
/* The IntensityBits most significant bits of ErrorAcc give us the \
intensity weighting for this pixel, and the complement of the \
weighting for the paired pixel */ \
Weighting = ErrorAcc >> 8; \
{ \
a = DRAW_MUL(_a, (Weighting ^ 255)); \
r = DRAW_MUL(_r, a); \
g = DRAW_MUL(_g, a); \
b = DRAW_MUL(_b, a); \
inva = (a ^ 0xFF); \
blend_op(x1, y1); \
} \
{ \
a = DRAW_MUL(_a, Weighting); \
r = DRAW_MUL(_r, a); \
g = DRAW_MUL(_g, a); \
b = DRAW_MUL(_b, a); \
inva = (a ^ 0xFF); \
blend_op(x1 + XDir, y1); \
} \
} \
} else { \
/* X-major line; calculate 16-bit fixed-point fractional part of a \
pixel that Y advances each time X advances 1 pixel, truncating the \
result to avoid overrunning the endpoint along the X axis */ \
ErrorAdj = ((unsigned long) DeltaY << 16) / (unsigned long) DeltaX; \
/* Draw all pixels other than the first and last */ \
while (--DeltaX) { \
ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */ \
ErrorAcc += ErrorAdj; /* calculate error for next pixel */ \
if (ErrorAcc <= ErrorAccTemp) { \
/* The error accumulator turned over, so advance the Y coord */ \
y1++; \
} \
x1 += XDir; /* X-major, so always advance X */ \
/* The IntensityBits most significant bits of ErrorAcc give us the \
intensity weighting for this pixel, and the complement of the \
weighting for the paired pixel */ \
Weighting = ErrorAcc >> 8; \
{ \
a = DRAW_MUL(_a, (Weighting ^ 255)); \
r = DRAW_MUL(_r, a); \
g = DRAW_MUL(_g, a); \
b = DRAW_MUL(_b, a); \
inva = (a ^ 0xFF); \
blend_op(x1, y1); \
} \
{ \
a = DRAW_MUL(_a, Weighting); \
r = DRAW_MUL(_r, a); \
g = DRAW_MUL(_g, a); \
b = DRAW_MUL(_b, a); \
inva = (a ^ 0xFF); \
blend_op(x1, y1 + 1); \
} \
} \
} \
}
#define WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
{ \
Uint16 ErrorAdj, ErrorAcc; \
Uint16 ErrorAccTemp, Weighting; \
int DeltaX, DeltaY, Temp, XDir; \
unsigned r, g, b, a, inva; \
\
/* Draw the initial pixel, which is always exactly intersected by \
the line and so needs no weighting */ \
opaque_op(x1, y1); \
\
/* Draw the final pixel, which is always exactly intersected by the line \
and so needs no weighting */ \
if (draw_end) { \
opaque_op(x2, y2); \
} \
\
/* Make sure the line runs top to bottom */ \
if (y1 > y2) { \
Temp = y1; \
y1 = y2; \
y2 = Temp; \
Temp = x1; \
x1 = x2; \
x2 = Temp; \
} \
DeltaY = y2 - y1; \
\
if ((DeltaX = x2 - x1) >= 0) { \
XDir = 1; \
} else { \
XDir = -1; \
DeltaX = -DeltaX; /* make DeltaX positive */ \
} \
\
/* line is not horizontal, diagonal, or vertical */ \
ErrorAcc = 0; /* initialize the line error accumulator to 0 */ \
\
/* Is this an X-major or Y-major line? */ \
if (DeltaY > DeltaX) { \
/* Y-major line; calculate 16-bit fixed-point fractional part of a \
pixel that X advances each time Y advances 1 pixel, truncating the \
result so that we won't overrun the endpoint along the X axis */ \
ErrorAdj = ((unsigned long)DeltaX << 16) / (unsigned long)DeltaY; \
/* Draw all pixels other than the first and last */ \
while (--DeltaY) { \
ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */ \
ErrorAcc += ErrorAdj; /* calculate error for next pixel */ \
if (ErrorAcc <= ErrorAccTemp) { \
/* The error accumulator turned over, so advance the X coord */ \
x1 += XDir; \
} \
y1++; /* Y-major, so always advance Y */ \
/* The IntensityBits most significant bits of ErrorAcc give us the \
intensity weighting for this pixel, and the complement of the \
weighting for the paired pixel */ \
Weighting = ErrorAcc >> 8; \
{ \
a = DRAW_MUL(_a, (Weighting ^ 255)); \
r = DRAW_MUL(_r, a); \
g = DRAW_MUL(_g, a); \
b = DRAW_MUL(_b, a); \
inva = (a ^ 0xFF); \
blend_op(x1, y1); \
} \
{ \
a = DRAW_MUL(_a, Weighting); \
r = DRAW_MUL(_r, a); \
g = DRAW_MUL(_g, a); \
b = DRAW_MUL(_b, a); \
inva = (a ^ 0xFF); \
blend_op(x1 + XDir, y1); \
} \
} \
} else { \
/* X-major line; calculate 16-bit fixed-point fractional part of a \
pixel that Y advances each time X advances 1 pixel, truncating the \
result to avoid overrunning the endpoint along the X axis */ \
ErrorAdj = ((unsigned long)DeltaY << 16) / (unsigned long)DeltaX; \
/* Draw all pixels other than the first and last */ \
while (--DeltaX) { \
ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */ \
ErrorAcc += ErrorAdj; /* calculate error for next pixel */ \
if (ErrorAcc <= ErrorAccTemp) { \
/* The error accumulator turned over, so advance the Y coord */ \
y1++; \
} \
x1 += XDir; /* X-major, so always advance X */ \
/* The IntensityBits most significant bits of ErrorAcc give us the \
intensity weighting for this pixel, and the complement of the \
weighting for the paired pixel */ \
Weighting = ErrorAcc >> 8; \
{ \
a = DRAW_MUL(_a, (Weighting ^ 255)); \
r = DRAW_MUL(_r, a); \
g = DRAW_MUL(_g, a); \
b = DRAW_MUL(_b, a); \
inva = (a ^ 0xFF); \
blend_op(x1, y1); \
} \
{ \
a = DRAW_MUL(_a, Weighting); \
r = DRAW_MUL(_r, a); \
g = DRAW_MUL(_g, a); \
b = DRAW_MUL(_b, a); \
inva = (a ^ 0xFF); \
blend_op(x1, y1 + 1); \
} \
} \
} \
}
#ifdef AA_LINES
#define AALINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end)
WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end)
#else
#define AALINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
BLINE(x1, y1, x2, y2, opaque_op, draw_end)
BLINE(x1, y1, x2, y2, opaque_op, draw_end)
#endif
/*
* Define fill rect macro
*/
#define FILLRECT(type, op) \
do { \
int width = rect->w; \
int height = rect->h; \
int pitch = (dst->pitch / dst->format->BytesPerPixel); \
int skip = pitch - width; \
type *pixel = (type *)dst->pixels + rect->y * pitch + rect->x; \
while (height--) { \
{ int n = (width+3)/4; \
switch (width & 3) { \
case 0: do { op; pixel++; SDL_FALLTHROUGH; \
case 3: op; pixel++; SDL_FALLTHROUGH; \
case 2: op; pixel++; SDL_FALLTHROUGH; \
case 1: op; pixel++; \
} while ( --n > 0 ); \
} \
} \
pixel += skip; \
} \
} while (0)
#define FILLRECT(type, op) \
do { \
int width = rect->w; \
int height = rect->h; \
int pitch = (dst->pitch / dst->format->BytesPerPixel); \
int skip = pitch - width; \
type *pixel = (type *)dst->pixels + rect->y * pitch + rect->x; \
while (height--) { \
{ \
int n = (width + 3) / 4; \
switch (width & 3) { \
case 0: \
do { \
op; \
pixel++; \
SDL_FALLTHROUGH; \
case 3: \
op; \
pixel++; \
SDL_FALLTHROUGH; \
case 2: \
op; \
pixel++; \
SDL_FALLTHROUGH; \
case 1: \
op; \
pixel++; \
} while (--n > 0); \
} \
} \
pixel += skip; \
} \
} while (0)
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -26,10 +26,8 @@
#include "SDL_drawline.h"
#include "SDL_drawpoint.h"
static void
SDL_DrawLine1(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
SDL_bool draw_end)
static void SDL_DrawLine1(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color,
SDL_bool draw_end)
{
if (y1 == y2) {
int length;
@ -37,13 +35,13 @@ SDL_DrawLine1(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
Uint8 *pixel;
if (x1 <= x2) {
pixel = (Uint8 *)dst->pixels + y1 * pitch + x1;
length = draw_end ? (x2-x1+1) : (x2-x1);
length = draw_end ? (x2 - x1 + 1) : (x2 - x1);
} else {
pixel = (Uint8 *)dst->pixels + y1 * pitch + x2;
if (!draw_end) {
++pixel;
}
length = draw_end ? (x1-x2+1) : (x1-x2);
length = draw_end ? (x1 - x2 + 1) : (x1 - x2);
}
SDL_memset(pixel, color, length);
} else if (x1 == x2) {
@ -55,9 +53,8 @@ SDL_DrawLine1(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
}
}
static void
SDL_DrawLine2(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
SDL_bool draw_end)
static void SDL_DrawLine2(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color,
SDL_bool draw_end)
{
if (y1 == y2) {
HLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end);
@ -67,7 +64,7 @@ SDL_DrawLine2(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
DLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end);
} else {
Uint8 _r, _g, _b, _a;
const SDL_PixelFormat * fmt = dst->format;
const SDL_PixelFormat *fmt = dst->format;
SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a);
if (fmt->Rmask == 0x7C00) {
AALINE(x1, y1, x2, y2,
@ -85,9 +82,8 @@ SDL_DrawLine2(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
}
}
static void
SDL_DrawLine4(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
SDL_bool draw_end)
static void SDL_DrawLine4(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color,
SDL_bool draw_end)
{
if (y1 == y2) {
HLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end);
@ -97,7 +93,7 @@ SDL_DrawLine4(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
DLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end);
} else {
Uint8 _r, _g, _b, _a;
const SDL_PixelFormat * fmt = dst->format;
const SDL_PixelFormat *fmt = dst->format;
SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a);
if (fmt->Rmask == 0x00FF0000) {
if (!fmt->Amask) {
@ -117,12 +113,11 @@ SDL_DrawLine4(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
}
}
typedef void (*DrawLineFunc) (SDL_Surface * dst,
int x1, int y1, int x2, int y2,
Uint32 color, SDL_bool draw_end);
typedef void (*DrawLineFunc)(SDL_Surface *dst,
int x1, int y1, int x2, int y2,
Uint32 color, SDL_bool draw_end);
static DrawLineFunc
SDL_CalculateDrawLineFunc(const SDL_PixelFormat * fmt)
static DrawLineFunc SDL_CalculateDrawLineFunc(const SDL_PixelFormat *fmt)
{
switch (fmt->BytesPerPixel) {
case 1:
@ -138,17 +133,16 @@ SDL_CalculateDrawLineFunc(const SDL_PixelFormat * fmt)
return NULL;
}
int
SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color)
int SDL_DrawLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color)
{
DrawLineFunc func;
if (!dst) {
if (dst == NULL) {
return SDL_InvalidParamError("SDL_DrawLine(): dst");
}
func = SDL_CalculateDrawLineFunc(dst->format);
if (!func) {
if (func == NULL) {
return SDL_SetError("SDL_DrawLine(): Unsupported surface format");
}
@ -162,9 +156,8 @@ SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color)
return 0;
}
int
SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count,
Uint32 color)
int SDL_DrawLines(SDL_Surface *dst, const SDL_Point *points, int count,
Uint32 color)
{
int i;
int x1, y1;
@ -172,18 +165,18 @@ SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count,
SDL_bool draw_end;
DrawLineFunc func;
if (!dst) {
if (dst == NULL) {
return SDL_InvalidParamError("SDL_DrawLines(): dst");
}
func = SDL_CalculateDrawLineFunc(dst->format);
if (!func) {
if (func == NULL) {
return SDL_SetError("SDL_DrawLines(): Unsupported surface format");
}
for (i = 1; i < count; ++i) {
x1 = points[i-1].x;
y1 = points[i-1].y;
x1 = points[i - 1].x;
y1 = points[i - 1].y;
x2 = points[i].x;
y2 = points[i].y;
@ -198,8 +191,8 @@ SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count,
func(dst, x1, y1, x2, y2, color, draw_end);
}
if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
SDL_DrawPoint(dst, points[count-1].x, points[count-1].y, color);
if (points[0].x != points[count - 1].x || points[0].y != points[count - 1].y) {
SDL_DrawPoint(dst, points[count - 1].x, points[count - 1].y, color);
}
return 0;
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -24,9 +24,8 @@
#include "../../SDL_internal.h"
extern int SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color);
extern int SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color);
extern int SDL_DrawLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color);
extern int SDL_DrawLines(SDL_Surface *dst, const SDL_Point *points, int count, Uint32 color);
#endif /* SDL_drawline_h_ */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -25,11 +25,9 @@
#include "SDL_draw.h"
#include "SDL_drawpoint.h"
int
SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color)
int SDL_DrawPoint(SDL_Surface *dst, int x, int y, Uint32 color)
{
if (!dst) {
if (dst == NULL) {
return SDL_InvalidParamError("SDL_DrawPoint(): dst");
}
@ -61,16 +59,15 @@ SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color)
return 0;
}
int
SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count,
Uint32 color)
int SDL_DrawPoints(SDL_Surface *dst, const SDL_Point *points, int count,
Uint32 color)
{
int minx, miny;
int maxx, maxy;
int i;
int x, y;
if (!dst) {
if (dst == NULL) {
return SDL_InvalidParamError("SDL_DrawPoints(): dst");
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -24,9 +24,8 @@
#include "../../SDL_internal.h"
extern int SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color);
extern int SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color);
extern int SDL_DrawPoint(SDL_Surface *dst, int x, int y, Uint32 color);
extern int SDL_DrawPoints(SDL_Surface *dst, const SDL_Point *points, int count, Uint32 color);
#endif /* SDL_drawpoint_h_ */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -50,11 +50,9 @@ typedef struct
SDL_Surface *window;
} SW_RenderData;
static SDL_Surface *
SW_ActivateRenderer(SDL_Renderer * renderer)
static SDL_Surface *SW_ActivateRenderer(SDL_Renderer *renderer)
{
SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
SW_RenderData *data = (SW_RenderData *)renderer->driverdata;
if (!data->surface) {
data->surface = data->window;
@ -68,10 +66,9 @@ SW_ActivateRenderer(SDL_Renderer * renderer)
return data->surface;
}
static void
SW_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
static void SW_WindowEvent(SDL_Renderer *renderer, const SDL_WindowEvent *event)
{
SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
SW_RenderData *data = (SW_RenderData *)renderer->driverdata;
if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
data->surface = NULL;
@ -79,10 +76,9 @@ SW_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
}
}
static int
SW_GetOutputSize(SDL_Renderer * renderer, int *w, int *h)
static int SW_GetOutputSize(SDL_Renderer *renderer, int *w, int *h)
{
SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
SW_RenderData *data = (SW_RenderData *)renderer->driverdata;
if (data->surface) {
if (w) {
@ -95,21 +91,19 @@ SW_GetOutputSize(SDL_Renderer * renderer, int *w, int *h)
}
if (renderer->window) {
SDL_GetWindowSize(renderer->window, w, h);
SDL_GetWindowSizeInPixels(renderer->window, w, h);
return 0;
}
return SDL_SetError("Software renderer doesn't have an output surface");
}
static int
SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
static int SW_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
{
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
if (!SDL_PixelFormatEnumToMasks
(texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
if (!SDL_PixelFormatEnumToMasks(texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
return SDL_SetError("Unknown texture format");
}
@ -133,81 +127,76 @@ SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
return 0;
}
static int
SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels, int pitch)
static int SW_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect, const void *pixels, int pitch)
{
SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
SDL_Surface *surface = (SDL_Surface *)texture->driverdata;
Uint8 *src, *dst;
int row;
size_t length;
if(SDL_MUSTLOCK(surface))
if (SDL_MUSTLOCK(surface)) {
SDL_LockSurface(surface);
src = (Uint8 *) pixels;
dst = (Uint8 *) surface->pixels +
rect->y * surface->pitch +
rect->x * surface->format->BytesPerPixel;
length = rect->w * surface->format->BytesPerPixel;
}
src = (Uint8 *)pixels;
dst = (Uint8 *)surface->pixels +
rect->y * surface->pitch +
rect->x * surface->format->BytesPerPixel;
length = (size_t)rect->w * surface->format->BytesPerPixel;
for (row = 0; row < rect->h; ++row) {
SDL_memcpy(dst, src, length);
src += pitch;
dst += surface->pitch;
}
if(SDL_MUSTLOCK(surface))
if (SDL_MUSTLOCK(surface)) {
SDL_UnlockSurface(surface);
}
return 0;
}
static int
SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, void **pixels, int *pitch)
static int SW_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect, void **pixels, int *pitch)
{
SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
SDL_Surface *surface = (SDL_Surface *)texture->driverdata;
*pixels =
(void *) ((Uint8 *) surface->pixels + rect->y * surface->pitch +
rect->x * surface->format->BytesPerPixel);
(void *)((Uint8 *)surface->pixels + rect->y * surface->pitch +
rect->x * surface->format->BytesPerPixel);
*pitch = surface->pitch;
return 0;
}
static void
SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
static void SW_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
{
}
static void
SW_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture, SDL_ScaleMode scaleMode)
static void SW_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *texture, SDL_ScaleMode scaleMode)
{
}
static int
SW_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
static int SW_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
{
SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
SW_RenderData *data = (SW_RenderData *)renderer->driverdata;
if (texture) {
data->surface = (SDL_Surface *) texture->driverdata;
data->surface = (SDL_Surface *)texture->driverdata;
} else {
data->surface = data->window;
}
return 0;
}
static int
SW_QueueSetViewport(SDL_Renderer * renderer, SDL_RenderCommand *cmd)
static int SW_QueueSetViewport(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
{
return 0; /* nothing to do in this backend. */
return 0; /* nothing to do in this backend. */
}
static int
SW_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points, int count)
static int SW_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count)
{
SDL_Point *verts = (SDL_Point *) SDL_AllocateRenderVertices(renderer, count * sizeof (SDL_Point), 0, &cmd->data.draw.first);
SDL_Point *verts = (SDL_Point *)SDL_AllocateRenderVertices(renderer, count * sizeof(SDL_Point), 0, &cmd->data.draw.first);
int i;
if (!verts) {
if (verts == NULL) {
return -1;
}
@ -221,13 +210,12 @@ SW_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FP
return 0;
}
static int
SW_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects, int count)
static int SW_QueueFillRects(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FRect *rects, int count)
{
SDL_Rect *verts = (SDL_Rect *) SDL_AllocateRenderVertices(renderer, count * sizeof (SDL_Rect), 0, &cmd->data.draw.first);
SDL_Rect *verts = (SDL_Rect *)SDL_AllocateRenderVertices(renderer, count * sizeof(SDL_Rect), 0, &cmd->data.draw.first);
int i;
if (!verts) {
if (verts == NULL) {
return -1;
}
@ -243,19 +231,18 @@ SW_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRe
return 0;
}
static int
SW_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_FRect * dstrect)
static int SW_QueueCopy(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
const SDL_Rect *srcrect, const SDL_FRect *dstrect)
{
SDL_Rect *verts = (SDL_Rect *) SDL_AllocateRenderVertices(renderer, 2 * sizeof (SDL_Rect), 0, &cmd->data.draw.first);
SDL_Rect *verts = (SDL_Rect *)SDL_AllocateRenderVertices(renderer, 2 * sizeof(SDL_Rect), 0, &cmd->data.draw.first);
if (!verts) {
if (verts == NULL) {
return -1;
}
cmd->data.draw.count = 1;
SDL_memcpy(verts, srcrect, sizeof (SDL_Rect));
SDL_copyp(verts, srcrect);
verts++;
verts->x = (int)dstrect->x;
@ -277,27 +264,26 @@ typedef struct CopyExData
float scale_y;
} CopyExData;
static int
SW_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_FRect * dstrect,
const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip, float scale_x, float scale_y)
static int SW_QueueCopyEx(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
const SDL_Rect *srcrect, const SDL_FRect *dstrect,
const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip, float scale_x, float scale_y)
{
CopyExData *verts = (CopyExData *) SDL_AllocateRenderVertices(renderer, sizeof (CopyExData), 0, &cmd->data.draw.first);
CopyExData *verts = (CopyExData *)SDL_AllocateRenderVertices(renderer, sizeof(CopyExData), 0, &cmd->data.draw.first);
if (!verts) {
if (verts == NULL) {
return -1;
}
cmd->data.draw.count = 1;
SDL_memcpy(&verts->srcrect, srcrect, sizeof (SDL_Rect));
SDL_copyp(&verts->srcrect, srcrect);
verts->dstrect.x = (int)dstrect->x;
verts->dstrect.y = (int)dstrect->y;
verts->dstrect.w = (int)dstrect->w;
verts->dstrect.h = (int)dstrect->h;
verts->angle = angle;
SDL_memcpy(&verts->center, center, sizeof (SDL_FPoint));
SDL_copyp(&verts->center, center);
verts->flip = flip;
verts->scale_x = scale_x;
verts->scale_y = scale_y;
@ -305,18 +291,17 @@ SW_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * te
return 0;
}
static int
Blit_to_Screen(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *surface, SDL_Rect *dstrect,
float scale_x, float scale_y, SDL_ScaleMode scaleMode)
static int Blit_to_Screen(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *surface, SDL_Rect *dstrect,
float scale_x, float scale_y, SDL_ScaleMode scaleMode)
{
int retval;
/* Renderer scaling, if needed */
if (scale_x != 1.0f || scale_y != 1.0f) {
SDL_Rect r;
r.x = (int)((float) dstrect->x * scale_x);
r.y = (int)((float) dstrect->y * scale_y);
r.w = (int)((float) dstrect->w * scale_x);
r.h = (int)((float) dstrect->h * scale_y);
r.x = (int)((float)dstrect->x * scale_x);
r.y = (int)((float)dstrect->y * scale_y);
r.w = (int)((float)dstrect->w * scale_x);
r.h = (int)((float)dstrect->h * scale_y);
retval = SDL_PrivateUpperBlitScaled(src, srcrect, surface, &r, scaleMode);
} else {
retval = SDL_BlitSurface(src, srcrect, surface, dstrect);
@ -324,12 +309,11 @@ Blit_to_Screen(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *surface, SDL_Re
return retval;
}
static int
SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Surface *surface, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_Rect * final_rect,
const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip, float scale_x, float scale_y)
static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Texture *texture,
const SDL_Rect *srcrect, const SDL_Rect *final_rect,
const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip, float scale_x, float scale_y)
{
SDL_Surface *src = (SDL_Surface *) texture->driverdata;
SDL_Surface *src = (SDL_Surface *)texture->driverdata;
SDL_Rect tmp_rect;
SDL_Surface *src_clone, *src_rotated, *src_scaled;
SDL_Surface *mask = NULL, *mask_rotated = NULL;
@ -340,7 +324,7 @@ SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Surface *surface, SDL_Texture * tex
int blitRequired = SDL_FALSE;
int isOpaque = SDL_FALSE;
if (!surface) {
if (surface == NULL) {
return -1;
}
@ -439,18 +423,18 @@ SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Surface *surface, SDL_Texture * tex
double cangle, sangle;
SDLgfx_rotozoomSurfaceSizeTrig(tmp_rect.w, tmp_rect.h, angle, center,
&rect_dest, &cangle, &sangle);
&rect_dest, &cangle, &sangle);
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);
(texture->scaleMode == SDL_ScaleModeNearest) ? 0 : 1, flip & SDL_FLIP_HORIZONTAL, flip & SDL_FLIP_VERTICAL,
&rect_dest, cangle, sangle, center);
if (src_rotated == NULL) {
retval = -1;
}
if (!retval && mask != NULL) {
/* 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);
SDL_FALSE, 0, 0,
&rect_dest, cangle, sangle, center);
if (mask_rotated == NULL) {
retval = -1;
}
@ -533,7 +517,6 @@ SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Surface *surface, SDL_Texture * tex
return retval;
}
typedef struct GeometryFillData
{
SDL_Point dst;
@ -547,19 +530,18 @@ typedef struct GeometryCopyData
SDL_Color color;
} GeometryCopyData;
static int
SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
const float *xy, int xy_stride, const SDL_Color *color, int color_stride, const float *uv, int uv_stride,
int num_vertices, const void *indices, int num_indices, int size_indices,
float scale_x, float scale_y)
static int SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
const float *xy, int xy_stride, const SDL_Color *color, int color_stride, const float *uv, int uv_stride,
int num_vertices, const void *indices, int num_indices, int size_indices,
float scale_x, float scale_y)
{
int i;
int count = indices ? num_indices : num_vertices;
void *verts;
int sz = texture ? sizeof (GeometryCopyData) : sizeof (GeometryFillData);
size_t sz = texture != NULL ? sizeof(GeometryCopyData) : sizeof(GeometryFillData);
verts = (void *) SDL_AllocateRenderVertices(renderer, count * sz, 0, &cmd->data.draw.first);
if (!verts) {
verts = SDL_AllocateRenderVertices(renderer, count * sz, 0, &cmd->data.draw.first);
if (verts == NULL) {
return -1;
}
@ -567,7 +549,7 @@ SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *te
size_indices = indices ? size_indices : 0;
if (texture) {
GeometryCopyData *ptr = (GeometryCopyData *) verts;
GeometryCopyData *ptr = (GeometryCopyData *)verts;
for (i = 0; i < count; i++) {
int j;
float *xy_;
@ -583,10 +565,10 @@ SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *te
j = i;
}
xy_ = (float *)((char*)xy + j * xy_stride);
col_ = *(SDL_Color *)((char*)color + j * color_stride);
xy_ = (float *)((char *)xy + j * xy_stride);
col_ = *(SDL_Color *)((char *)color + j * color_stride);
uv_ = (float *)((char*)uv + j * uv_stride);
uv_ = (float *)((char *)uv + j * uv_stride);
ptr->src.x = (int)(uv_[0] * texture->w);
ptr->src.y = (int)(uv_[1] * texture->h);
@ -598,9 +580,9 @@ SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *te
ptr->color = col_;
ptr++;
}
}
} else {
GeometryFillData *ptr = (GeometryFillData *) verts;
GeometryFillData *ptr = (GeometryFillData *)verts;
for (i = 0; i < count; i++) {
int j;
@ -616,8 +598,8 @@ SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *te
j = i;
}
xy_ = (float *)((char*)xy + j * xy_stride);
col_ = *(SDL_Color *)((char*)color + j * color_stride);
xy_ = (float *)((char *)xy + j * xy_stride);
col_ = *(SDL_Color *)((char *)color + j * color_stride);
ptr->dst.x = (int)(xy_[0] * scale_x);
ptr->dst.y = (int)(xy_[1] * scale_y);
@ -626,13 +608,12 @@ SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *te
ptr->color = col_;
ptr++;
}
}
}
return 0;
}
static void
PrepTextureForCopy(const SDL_RenderCommand *cmd)
static void PrepTextureForCopy(const SDL_RenderCommand *cmd)
{
const Uint8 r = cmd->data.draw.r;
const Uint8 g = cmd->data.draw.g;
@ -640,7 +621,7 @@ PrepTextureForCopy(const SDL_RenderCommand *cmd)
const Uint8 a = cmd->data.draw.a;
const SDL_BlendMode blend = cmd->data.draw.blend;
SDL_Texture *texture = cmd->data.draw.texture;
SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
SDL_Surface *surface = (SDL_Surface *)texture->driverdata;
const SDL_bool colormod = ((r & g & b) != 0xFF);
const SDL_bool alphamod = (a != 0xFF);
const SDL_bool blending = ((blend == SDL_BLENDMODE_ADD) || (blend == SDL_BLENDMODE_MOD) || (blend == SDL_BLENDMODE_MUL));
@ -655,13 +636,12 @@ PrepTextureForCopy(const SDL_RenderCommand *cmd)
SDL_SetSurfaceBlendMode(surface, blend);
}
static void
SetDrawState(SDL_Surface *surface, SW_DrawStateCache *drawstate)
static void SetDrawState(SDL_Surface *surface, SW_DrawStateCache *drawstate)
{
if (drawstate->surface_cliprect_dirty) {
const SDL_Rect *viewport = drawstate->viewport;
const SDL_Rect *cliprect = drawstate->cliprect;
SDL_assert(viewport != NULL); /* the higher level should have forced a SDL_RENDERCMD_SETVIEWPORT */
SDL_assert_release(viewport != NULL); /* the higher level should have forced a SDL_RENDERCMD_SETVIEWPORT */
if (cliprect != NULL) {
SDL_Rect clip_rect;
@ -678,13 +658,12 @@ SetDrawState(SDL_Surface *surface, SW_DrawStateCache *drawstate)
}
}
static int
SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
{
SDL_Surface *surface = SW_ActivateRenderer(renderer);
SW_DrawStateCache drawstate;
if (!surface) {
if (surface == NULL) {
return -1;
}
@ -733,7 +712,7 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
SetDrawState(surface, &drawstate);
/* Apply viewport */
if (drawstate.viewport->x || drawstate.viewport->y) {
if (drawstate.viewport != NULL && (drawstate.viewport->x || drawstate.viewport->y)) {
int i;
for (i = 0; i < count; i++) {
verts[i].x += drawstate.viewport->x;
@ -760,7 +739,7 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
SetDrawState(surface, &drawstate);
/* Apply viewport */
if (drawstate.viewport->x || drawstate.viewport->y) {
if (drawstate.viewport != NULL && (drawstate.viewport->x || drawstate.viewport->y)) {
int i;
for (i = 0; i < count; i++) {
verts[i].x += drawstate.viewport->x;
@ -787,7 +766,7 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
SetDrawState(surface, &drawstate);
/* Apply viewport */
if (drawstate.viewport->x || drawstate.viewport->y) {
if (drawstate.viewport != NULL && (drawstate.viewport->x || drawstate.viewport->y)) {
int i;
for (i = 0; i < count; i++) {
verts[i].x += drawstate.viewport->x;
@ -815,7 +794,7 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
PrepTextureForCopy(cmd);
/* Apply viewport */
if (drawstate.viewport->x || drawstate.viewport->y) {
if (drawstate.viewport != NULL && (drawstate.viewport->x || drawstate.viewport->y)) {
dstrect->x += drawstate.viewport->x;
dstrect->y += drawstate.viewport->y;
}
@ -873,7 +852,7 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
PrepTextureForCopy(cmd);
/* Apply viewport */
if (drawstate.viewport->x || drawstate.viewport->y) {
if (drawstate.viewport != NULL && (drawstate.viewport->x || drawstate.viewport->y)) {
copydata->dstrect.x += drawstate.viewport->x;
copydata->dstrect.y += drawstate.viewport->y;
}
@ -901,7 +880,7 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
PrepTextureForCopy(cmd);
/* Apply viewport */
if (drawstate.viewport->x || drawstate.viewport->y) {
if (drawstate.viewport != NULL && (drawstate.viewport->x || drawstate.viewport->y)) {
SDL_Point vp;
vp.x = drawstate.viewport->x;
vp.y = drawstate.viewport->y;
@ -924,7 +903,7 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
GeometryFillData *ptr = (GeometryFillData *) verts;
/* Apply viewport */
if (drawstate.viewport->x || drawstate.viewport->y) {
if (drawstate.viewport != NULL && (drawstate.viewport->x || drawstate.viewport->y)) {
SDL_Point vp;
vp.x = drawstate.viewport->x;
vp.y = drawstate.viewport->y;
@ -952,15 +931,14 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
return 0;
}
static int
SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 format, void * pixels, int pitch)
static int SW_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
Uint32 format, void *pixels, int pitch)
{
SDL_Surface *surface = SW_ActivateRenderer(renderer);
Uint32 src_format;
void *src_pixels;
if (!surface) {
if (surface == NULL) {
return -1;
}
@ -968,67 +946,64 @@ SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
* SDL_RenderReadPixels.
*/
if (rect->x < 0 || rect->x+rect->w > surface->w ||
rect->y < 0 || rect->y+rect->h > surface->h) {
if (rect->x < 0 || rect->x + rect->w > surface->w ||
rect->y < 0 || rect->y + rect->h > surface->h) {
return SDL_SetError("Tried to read outside of surface bounds");
}
src_format = surface->format->format;
src_pixels = (void*)((Uint8 *) surface->pixels +
rect->y * surface->pitch +
rect->x * surface->format->BytesPerPixel);
src_pixels = (void *)((Uint8 *)surface->pixels +
rect->y * surface->pitch +
rect->x * surface->format->BytesPerPixel);
return SDL_ConvertPixels(rect->w, rect->h,
src_format, src_pixels, surface->pitch,
format, pixels, pitch);
}
static void
SW_RenderPresent(SDL_Renderer * renderer)
static int SW_RenderPresent(SDL_Renderer *renderer)
{
SDL_Window *window = renderer->window;
if (window) {
SDL_UpdateWindowSurface(window);
if (window == NULL) {
return -1;
}
return SDL_UpdateWindowSurface(window);
}
static void
SW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
static void SW_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
{
SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
SDL_Surface *surface = (SDL_Surface *)texture->driverdata;
SDL_FreeSurface(surface);
}
static void
SW_DestroyRenderer(SDL_Renderer * renderer)
static void SW_DestroyRenderer(SDL_Renderer *renderer)
{
SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
SW_RenderData *data = (SW_RenderData *)renderer->driverdata;
SDL_free(data);
SDL_free(renderer);
}
SDL_Renderer *
SW_CreateRendererForSurface(SDL_Surface * surface)
SDL_Renderer *SW_CreateRendererForSurface(SDL_Surface *surface)
{
SDL_Renderer *renderer;
SW_RenderData *data;
if (!surface) {
if (surface == NULL) {
SDL_InvalidParamError("surface");
return NULL;
}
renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
if (!renderer) {
renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(*renderer));
if (renderer == NULL) {
SDL_OutOfMemory();
return NULL;
}
data = (SW_RenderData *) SDL_calloc(1, sizeof(*data));
if (!data) {
data = (SW_RenderData *)SDL_calloc(1, sizeof(*data));
if (data == NULL) {
SW_DestroyRenderer(renderer);
SDL_OutOfMemory();
return NULL;
@ -1045,9 +1020,9 @@ SW_CreateRendererForSurface(SDL_Surface * surface)
renderer->SetTextureScaleMode = SW_SetTextureScaleMode;
renderer->SetRenderTarget = SW_SetRenderTarget;
renderer->QueueSetViewport = SW_QueueSetViewport;
renderer->QueueSetDrawColor = SW_QueueSetViewport; /* SetViewport and SetDrawColor are (currently) no-ops. */
renderer->QueueSetDrawColor = SW_QueueSetViewport; /* SetViewport and SetDrawColor are (currently) no-ops. */
renderer->QueueDrawPoints = SW_QueueDrawPoints;
renderer->QueueDrawLines = SW_QueueDrawPoints; /* lines and points queue vertices the same way. */
renderer->QueueDrawLines = SW_QueueDrawPoints; /* lines and points queue vertices the same way. */
renderer->QueueFillRects = SW_QueueFillRects;
renderer->QueueCopy = SW_QueueCopy;
renderer->QueueCopyEx = SW_QueueCopyEx;
@ -1065,8 +1040,7 @@ SW_CreateRendererForSurface(SDL_Surface * surface)
return renderer;
}
static SDL_Renderer *
SW_CreateRenderer(SDL_Window * window, Uint32 flags)
static SDL_Renderer *SW_CreateRenderer(SDL_Window *window, Uint32 flags)
{
const char *hint;
SDL_Surface *surface;
@ -1074,7 +1048,7 @@ 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 || !*hint) {
if (hint == NULL || !*hint) {
no_hint_set = SDL_TRUE;
} else {
no_hint_set = SDL_FALSE;
@ -1091,7 +1065,7 @@ SW_CreateRenderer(SDL_Window * window, Uint32 flags)
SDL_SetHint(SDL_HINT_RENDER_VSYNC, "");
}
if (!surface) {
if (surface == NULL) {
return NULL;
}
return SW_CreateRendererForSurface(surface);

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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 SDL_Renderer *SW_CreateRendererForSurface(SDL_Surface *surface);
#endif /* SDL_render_sw_c_h_ */

View file

@ -32,7 +32,7 @@ Andreas Schiffler -- aschiffler at ferzkopp dot net
#if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED
#if defined(__WIN32__)
#if defined(__WIN32__) || defined(__GDK__)
#include "../../core/windows/SDL_windows.h"
#endif
@ -47,7 +47,8 @@ Andreas Schiffler -- aschiffler at ferzkopp dot net
/* !
\brief A 32 bit RGBA pixel.
*/
typedef struct tColorRGBA {
typedef struct tColorRGBA
{
Uint8 r;
Uint8 g;
Uint8 b;
@ -57,7 +58,8 @@ typedef struct tColorRGBA {
/* !
\brief A 8bit Y/palette pixel.
*/
typedef struct tColorY {
typedef struct tColorY
{
Uint8 y;
} tColorY;
@ -76,8 +78,7 @@ to a situation where the program can segfault.
/* !
\brief Returns colorkey info for a surface
*/
static Uint32
get_colorkey(SDL_Surface *src)
static Uint32 get_colorkey(SDL_Surface *src)
{
Uint32 key = 0;
if (SDL_HasColorKey(src)) {
@ -87,8 +88,8 @@ get_colorkey(SDL_Surface *src)
}
/* rotate (sx, sy) by (angle, center) into (dx, dy) */
static void
rotate(double sx, double sy, double sinangle, double cosangle, const SDL_FPoint *center, double *dx, double *dy) {
static void rotate(double sx, double sy, double sinangle, double cosangle, const SDL_FPoint *center, double *dx, double *dy)
{
sx -= center->x;
sy -= center->y;
@ -111,9 +112,8 @@ rotate(double sx, double sy, double sinangle, double cosangle, const SDL_FPoint
\param sangle The cosine of the angle
*/
void
SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, const SDL_FPoint *center,
SDL_Rect *rect_dest, double *cangle, double *sangle)
void SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, const SDL_FPoint *center,
SDL_Rect *rect_dest, double *cangle, double *sangle)
{
int minx, maxx, miny, maxy;
double radangle;
@ -129,16 +129,16 @@ SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, const SDL_FP
/*
* Determine destination width and height by rotating a source box, at pixel center
*/
rotate(0.5, 0.5, sinangle, cosangle, center, &x0, &y0);
rotate(width - 0.5, 0.5, sinangle, cosangle, center, &x1, &y1);
rotate(0.5, height - 0.5, sinangle, cosangle, center, &x2, &y2);
rotate(0.5, 0.5, sinangle, cosangle, center, &x0, &y0);
rotate(width - 0.5, 0.5, sinangle, cosangle, center, &x1, &y1);
rotate(0.5, height - 0.5, sinangle, cosangle, center, &x2, &y2);
rotate(width - 0.5, height - 0.5, sinangle, cosangle, center, &x3, &y3);
minx = (int)SDL_floor( SDL_min( SDL_min(x0, x1), SDL_min(x2, x3) ) );
maxx = (int)SDL_ceil( SDL_max( SDL_max(x0, x1), SDL_max(x2, x3) ) );
minx = (int)SDL_floor(SDL_min(SDL_min(x0, x1), SDL_min(x2, x3)));
maxx = (int)SDL_ceil(SDL_max(SDL_max(x0, x1), SDL_max(x2, x3)));
miny = (int)SDL_floor( SDL_min( SDL_min(y0, y1), SDL_min(y2, y3) ) );
maxy = (int)SDL_ceil( SDL_max( SDL_max(y0, y1), SDL_max(y2, y3) ) );
miny = (int)SDL_floor(SDL_min(SDL_min(y0, y1), SDL_min(y2, y3)));
maxy = (int)SDL_ceil(SDL_max(SDL_max(y0, y1), SDL_max(y2, y3)));
rect_dest->w = maxx - minx;
rect_dest->h = maxy - miny;
@ -151,17 +151,20 @@ SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, const SDL_FP
{
/* The trig code below gets the wrong size (due to FP inaccuracy?) when angle is a multiple of 90 degrees */
int angle90 = (int)(angle/90);
if(angle90 == angle/90) { /* if the angle is a multiple of 90 degrees */
int angle90 = (int)(angle / 90);
if (angle90 == angle / 90) { /* if the angle is a multiple of 90 degrees */
angle90 %= 4;
if(angle90 < 0) angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
if(angle90 & 1) {
rect_dest->w = height;
if (angle90 < 0) {
angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
}
if (angle90 & 1) {
rect_dest->w = height;
rect_dest->h = width;
*cangle = 0;
*sangle = angle90 == 1 ? -1 : 1; /* reversed because our rotations are clockwise */
} else {
rect_dest->w = width;
rect_dest->w = width;
rect_dest->h = height;
*cangle = angle90 == 0 ? 1 : -1;
*sangle = 0;
@ -171,19 +174,37 @@ SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, const SDL_FP
}
/* Computes source pointer X/Y increments for a rotation that's a multiple of 90 degrees. */
static void
computeSourceIncrements90(SDL_Surface * src, int bpp, int angle, int flipx, int flipy,
int *sincx, int *sincy, int *signx, int *signy)
static void computeSourceIncrements90(SDL_Surface *src, int bpp, int angle, int flipx, int flipy,
int *sincx, int *sincy, int *signx, int *signy)
{
int pitch = flipy ? -src->pitch : src->pitch;
if (flipx) {
bpp = -bpp;
}
switch (angle) { /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
case 0: *sincx = bpp; *sincy = pitch - src->w * *sincx; *signx = *signy = 1; break;
case 1: *sincx = -pitch; *sincy = bpp - *sincx * src->h; *signx = 1; *signy = -1; break;
case 2: *sincx = -bpp; *sincy = -src->w * *sincx - pitch; *signx = *signy = -1; break;
case 3: default: *sincx = pitch; *sincy = -*sincx * src->h - bpp; *signx = -1; *signy = 1; break;
case 0:
*sincx = bpp;
*sincy = pitch - src->w * *sincx;
*signx = *signy = 1;
break;
case 1:
*sincx = -pitch;
*sincy = bpp - *sincx * src->h;
*signx = 1;
*signy = -1;
break;
case 2:
*sincx = -bpp;
*sincy = -src->w * *sincx - pitch;
*signx = *signy = -1;
break;
case 3:
default:
*sincx = pitch;
*sincy = -*sincx * src->h - bpp;
*signx = -1;
*signy = 1;
break;
}
if (flipx) {
*signx = -*signx;
@ -194,34 +215,34 @@ computeSourceIncrements90(SDL_Surface * src, int bpp, int angle, int flipx, int
}
/* Performs a relatively fast rotation/flip when the angle is a multiple of 90 degrees. */
#define TRANSFORM_SURFACE_90(pixelType) \
int dy, dincy = dst->pitch - dst->w*sizeof(pixelType), sincx, sincy, signx, signy; \
Uint8 *sp = (Uint8*)src->pixels, *dp = (Uint8*)dst->pixels, *de; \
#define TRANSFORM_SURFACE_90(pixelType) \
int dy, dincy = dst->pitch - dst->w * sizeof(pixelType), sincx, sincy, signx, signy; \
Uint8 *sp = (Uint8 *)src->pixels, *dp = (Uint8 *)dst->pixels, *de; \
\
computeSourceIncrements90(src, sizeof(pixelType), angle, flipx, flipy, &sincx, &sincy, &signx, &signy); \
if (signx < 0) sp += (src->w-1)*sizeof(pixelType); \
if (signy < 0) sp += (src->h-1)*src->pitch; \
if (signx < 0) \
sp += (src->w - 1) * sizeof(pixelType); \
if (signy < 0) \
sp += (src->h - 1) * src->pitch; \
\
for (dy = 0; dy < dst->h; sp += sincy, dp += dincy, dy++) { \
if (sincx == sizeof(pixelType)) { /* if advancing src and dest equally, use SDL_memcpy */ \
SDL_memcpy(dp, sp, dst->w*sizeof(pixelType)); \
sp += dst->w*sizeof(pixelType); \
dp += dst->w*sizeof(pixelType); \
SDL_memcpy(dp, sp, dst->w * sizeof(pixelType)); \
sp += dst->w * sizeof(pixelType); \
dp += dst->w * sizeof(pixelType); \
} else { \
for (de = dp + dst->w*sizeof(pixelType); dp != de; sp += sincx, dp += sizeof(pixelType)) { \
*(pixelType*)dp = *(pixelType*)sp; \
for (de = dp + dst->w * sizeof(pixelType); dp != de; sp += sincx, dp += sizeof(pixelType)) { \
*(pixelType *)dp = *(pixelType *)sp; \
} \
} \
}
static void
transformSurfaceRGBA90(SDL_Surface * src, SDL_Surface * dst, int angle, int flipx, int flipy)
static void transformSurfaceRGBA90(SDL_Surface *src, SDL_Surface *dst, int angle, int flipx, int flipy)
{
TRANSFORM_SURFACE_90(tColorRGBA);
}
static void
transformSurfaceY90(SDL_Surface * src, SDL_Surface * dst, int angle, int flipx, int flipy)
static void transformSurfaceY90(SDL_Surface *src, SDL_Surface *dst, int angle, int flipx, int flipy)
{
TRANSFORM_SURFACE_90(tColorY);
}
@ -247,32 +268,31 @@ Assumes dst surface was allocated with the correct dimensions.
\param dst_rect destination coordinates
\param center true center.
*/
static void
transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int isin, int icos,
int flipx, int flipy, int smooth,
const SDL_Rect *rect_dest,
const SDL_FPoint *center)
static void transformSurfaceRGBA(SDL_Surface *src, SDL_Surface *dst, int isin, int icos,
int flipx, int flipy, int smooth,
const SDL_Rect *rect_dest,
const SDL_FPoint *center)
{
int sw, sh;
int cx, cy;
tColorRGBA c00, c01, c10, c11, cswap;
tColorRGBA *pc, *sp;
int gap;
const int fp_half = (1<<15);
const int fp_half = (1 << 15);
/*
* Variable setup
*/
* Variable setup
*/
sw = src->w - 1;
sh = src->h - 1;
pc = (tColorRGBA*) dst->pixels;
pc = (tColorRGBA *)dst->pixels;
gap = dst->pitch - dst->w * 4;
cx = (int)(center->x * 65536.0);
cy = (int)(center->y * 65536.0);
/*
* Switch between interpolating and non-interpolating code
*/
* Switch between interpolating and non-interpolating code
*/
if (smooth) {
int y;
for (y = 0; y < dst->h; y++) {
@ -284,30 +304,42 @@ transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int isin, int icos,
for (x = 0; x < dst->w; x++) {
int dx = (sdx >> 16);
int dy = (sdy >> 16);
if (flipx) dx = sw - dx;
if (flipy) dy = sh - dy;
if ((dx > -1) && (dy > -1) && (dx < (src->w-1)) && (dy < (src->h-1))) {
if (flipx) {
dx = sw - dx;
}
if (flipy) {
dy = sh - dy;
}
if ((dx > -1) && (dy > -1) && (dx < (src->w - 1)) && (dy < (src->h - 1))) {
int ex, ey;
int t1, t2;
sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy) + dx;
sp = (tColorRGBA *)((Uint8 *)src->pixels + src->pitch * dy) + dx;
c00 = *sp;
sp += 1;
c01 = *sp;
sp += (src->pitch/4);
sp += (src->pitch / 4);
c11 = *sp;
sp -= 1;
c10 = *sp;
if (flipx) {
cswap = c00; c00=c01; c01=cswap;
cswap = c10; c10=c11; c11=cswap;
cswap = c00;
c00 = c01;
c01 = cswap;
cswap = c10;
c10 = c11;
c11 = cswap;
}
if (flipy) {
cswap = c00; c00=c10; c10=cswap;
cswap = c01; c01=c11; c11=cswap;
cswap = c00;
c00 = c10;
c10 = cswap;
cswap = c01;
c01 = c11;
c11 = cswap;
}
/*
* Interpolate colors
*/
* Interpolate colors
*/
ex = (sdx & 0xffff);
ey = (sdy & 0xffff);
t1 = ((((c01.r - c00.r) * ex) >> 16) + c00.r) & 0xff;
@ -327,7 +359,7 @@ transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int isin, int icos,
sdy += isin;
pc++;
}
pc = (tColorRGBA *) ((Uint8 *) pc + gap);
pc = (tColorRGBA *)((Uint8 *)pc + gap);
}
} else {
int y;
@ -341,15 +373,19 @@ transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int isin, int icos,
int dx = (sdx >> 16);
int dy = (sdy >> 16);
if ((unsigned)dx < (unsigned)src->w && (unsigned)dy < (unsigned)src->h) {
if(flipx) dx = sw - dx;
if(flipy) dy = sh - dy;
if (flipx) {
dx = sw - dx;
}
if (flipy) {
dy = sh - dy;
}
*pc = *((tColorRGBA *)((Uint8 *)src->pixels + src->pitch * dy) + dx);
}
sdx += icos;
sdy += isin;
pc++;
}
pc = (tColorRGBA *) ((Uint8 *) pc + gap);
pc = (tColorRGBA *)((Uint8 *)pc + gap);
}
}
}
@ -372,35 +408,34 @@ Assumes dst surface was allocated with the correct dimensions.
\param dst_rect destination coordinates
\param center true center.
*/
static void
transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int isin, int icos, int flipx, int flipy,
const SDL_Rect *rect_dest,
const SDL_FPoint *center)
static void transformSurfaceY(SDL_Surface *src, SDL_Surface *dst, int isin, int icos, int flipx, int flipy,
const SDL_Rect *rect_dest,
const SDL_FPoint *center)
{
int sw, sh;
int cx, cy;
tColorY *pc;
int gap;
const int fp_half = (1<<15);
const int fp_half = (1 << 15);
int y;
/*
* Variable setup
*/
* Variable setup
*/
sw = src->w - 1;
sh = src->h - 1;
pc = (tColorY*) dst->pixels;
pc = (tColorY *)dst->pixels;
gap = dst->pitch - dst->w;
cx = (int)(center->x * 65536.0);
cy = (int)(center->y * 65536.0);
/*
* Clear surface to colorkey
*/
SDL_memset(pc, (int)(get_colorkey(src) & 0xff), dst->pitch * dst->h);
* Clear surface to colorkey
*/
SDL_memset(pc, (int)(get_colorkey(src) & 0xff), (size_t)dst->pitch * dst->h);
/*
* Iterate through destination surface
*/
* Iterate through destination surface
*/
for (y = 0; y < dst->h; y++) {
int x;
double src_x = (rect_dest->x + 0 + 0.5 - center->x);
@ -411,8 +446,12 @@ transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int isin, int icos, int
int dx = (sdx >> 16);
int dy = (sdy >> 16);
if ((unsigned)dx < (unsigned)src->w && (unsigned)dy < (unsigned)src->h) {
if (flipx) dx = sw - dx;
if (flipy) dy = sh- dy;
if (flipx) {
dx = sw - dx;
}
if (flipy) {
dy = sh - dy;
}
*pc = *((tColorY *)src->pixels + src->pitch * dy + dx);
}
sdx += icos;
@ -423,7 +462,6 @@ transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int isin, int icos, int
}
}
/* !
\brief Rotates and zooms a surface with different horizontal and vertival scaling factors and optional anti-aliasing.
@ -450,9 +488,8 @@ When using the NONE and MOD modes, color and alpha modulation must be applied be
*/
SDL_Surface *
SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int flipy,
const SDL_Rect *rect_dest, double cangle, double sangle, const SDL_FPoint *center)
SDL_Surface *SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, int flipx, int flipy,
const SDL_Rect *rect_dest, double cangle, double sangle, const SDL_FPoint *center)
{
SDL_Surface *rz_dst;
int is8bit, angle90;
@ -463,8 +500,9 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int
double sangleinv, cangleinv;
/* Sanity check */
if (src == NULL)
if (src == NULL) {
return NULL;
}
if (SDL_HasColorKey(src)) {
if (SDL_GetColorKey(src, &colorkey) == 0) {
@ -473,12 +511,13 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int
}
/* This function requires a 32-bit surface or 8-bit surface with a colorkey */
is8bit = src->format->BitsPerPixel == 8 && colorKeyAvailable;
if (!(is8bit || (src->format->BitsPerPixel == 32 && src->format->Amask)))
if (!(is8bit || (src->format->BitsPerPixel == 32 && src->format->Amask))) {
return NULL;
}
/* Calculate target factors from sine/cosine and zoom */
sangleinv = sangle*65536.0;
cangleinv = cangle*65536.0;
sangleinv = sangle * 65536.0;
cangleinv = cangle * 65536.0;
/* Alloc space to completely contain the rotated surface */
rz_dst = NULL;
@ -501,8 +540,9 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int
}
/* Check target */
if (rz_dst == NULL)
if (rz_dst == NULL) {
return NULL;
}
/* Adjust for guard rows */
rz_dst->h = rect_dest->h;
@ -539,17 +579,20 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int
* the off-by-one problem in transformSurfaceRGBA that expresses itself when the rotation is near
* multiples of 90 degrees.
*/
angle90 = (int)(angle/90);
if (angle90 == angle/90) {
angle90 = (int)(angle / 90);
if (angle90 == angle / 90) {
angle90 %= 4;
if (angle90 < 0) angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
if (angle90 < 0) {
angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
}
} else {
angle90 = -1;
}
if (is8bit) {
/* Call the 8-bit transformation routine to do the rotation */
if(angle90 >= 0) {
if (angle90 >= 0) {
transformSurfaceY90(src, rz_dst, angle90, flipx, flipy);
} else {
transformSurfaceY(src, rz_dst, (int)sangleinv, (int)cangleinv,
@ -561,7 +604,7 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int
transformSurfaceRGBA90(src, rz_dst, angle90, flipx, flipy);
} else {
transformSurfaceRGBA(src, rz_dst, (int)sangleinv, (int)cangleinv,
flipx, flipy, smooth, rect_dest, center);
flipx, flipy, smooth, rect_dest, center);
}
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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,9 +22,9 @@
#ifndef SDL_rotate_h_
#define SDL_rotate_h_
extern SDL_Surface *SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int flipy,
const SDL_Rect *rect_dest, double cangle, double sangle, const SDL_FPoint *center);
extern SDL_Surface *SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, int flipx, int flipy,
const SDL_Rect *rect_dest, double cangle, double sangle, const SDL_FPoint *center);
extern void SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, const SDL_FPoint *center,
SDL_Rect *rect_dest, double *cangle, double *sangle);
SDL_Rect *rect_dest, double *cangle, double *sangle);
#endif /* SDL_rotate_h_ */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -33,16 +33,15 @@
* But, if increased too much, it overflows (srcx, srcy) coordinates used for filling with texture.
* (which could be turned to int64).
*/
#define FP_BITS 1
#define FP_BITS 1
#define COLOR_EQ(c1, c2) ((c1).r == (c2).r && (c1).g == (c2).g && (c1).b == (c2).b && (c1).a == (c2).a)
#define COLOR_EQ(c1, c2) ((c1).r == (c2).r && (c1).g == (c2).g && (c1).b == (c2).b && (c1).a == (c2).a)
static void SDL_BlitTriangle_Slow(SDL_BlitInfo * info,
SDL_Point s2_x_area, SDL_Rect dstrect, int area, int bias_w0, int bias_w1, int bias_w2,
int d2d1_y, int d1d2_x, int d0d2_y, int d2d0_x, int d1d0_y, int d0d1_x,
int s2s0_x, int s2s1_x, int s2s0_y, int s2s1_y, int w0_row, int w1_row, int w2_row,
SDL_Color c0, SDL_Color c1, SDL_Color c2, int is_uniform);
static void SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
SDL_Point s2_x_area, SDL_Rect dstrect, int area, int bias_w0, int bias_w1, int bias_w2,
int d2d1_y, int d1d2_x, int d0d2_y, int d2d0_x, int d1d0_y, int d0d1_x,
int s2s0_x, int s2s1_x, int s2s0_y, int s2s1_y, int w0_row, int w1_row, int w2_row,
SDL_Color c0, SDL_Color c1, SDL_Color c2, int is_uniform);
#if 0
int SDL_BlitTriangle(SDL_Surface *src, const SDL_Point srcpoints[3], SDL_Surface *dst, const SDL_Point dstpoints[3])
@ -114,7 +113,8 @@ static int is_top_left(const SDL_Point *a, const SDL_Point *b, int is_clockwise)
return 0;
}
void trianglepoint_2_fixedpoint(SDL_Point *a) {
void trianglepoint_2_fixedpoint(SDL_Point *a)
{
a->x <<= FP_BITS;
a->y <<= FP_BITS;
}
@ -146,7 +146,6 @@ static void bounding_rect(const SDL_Point *a, const SDL_Point *b, const SDL_Poin
r->h = (max_y - min_y);
}
/* Triangle rendering, using Barycentric coordinates (w0, w1, w2)
*
* The cross product isn't computed from scratch at each iteration,
@ -154,53 +153,51 @@ static void bounding_rect(const SDL_Point *a, const SDL_Point *b, const SDL_Poin
*
*/
#define TRIANGLE_BEGIN_LOOP \
{ \
int x, y; \
for (y = 0; y < dstrect.h; y++) { \
/* y start */ \
int w0 = w0_row; \
int w1 = w1_row; \
int 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) { \
Uint8 *dptr = (Uint8 *) dst_ptr + x * dstbpp; \
#define TRIANGLE_BEGIN_LOOP \
{ \
int x, y; \
for (y = 0; y < dstrect.h; y++) { \
/* y start */ \
int w0 = w0_row; \
int w1 = w1_row; \
int 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) { \
Uint8 *dptr = (Uint8 *)dst_ptr + x * dstbpp;
/* Use 64 bits precision to prevent overflow when interpolating color / texture with wide triangles */
#define TRIANGLE_GET_TEXTCOORD \
int srcx = (int)(((Sint64)w0 * s2s0_x + (Sint64)w1 * s2s1_x + s2_x_area.x) / area); \
int srcy = (int)(((Sint64)w0 * s2s0_y + (Sint64)w1 * s2s1_y + s2_x_area.y) / area); \
#define TRIANGLE_GET_TEXTCOORD \
int srcx = (int)(((Sint64)w0 * s2s0_x + (Sint64)w1 * s2s1_x + s2_x_area.x) / area); \
int srcy = (int)(((Sint64)w0 * s2s0_y + (Sint64)w1 * s2s1_y + s2_x_area.y) / area);
#define TRIANGLE_GET_MAPPED_COLOR \
int r = (int)(((Sint64)w0 * c0.r + (Sint64)w1 * c1.r + (Sint64)w2 * c2.r) / area); \
int g = (int)(((Sint64)w0 * c0.g + (Sint64)w1 * c1.g + (Sint64)w2 * c2.g) / area); \
int b = (int)(((Sint64)w0 * c0.b + (Sint64)w1 * c1.b + (Sint64)w2 * c2.b) / area); \
int a = (int)(((Sint64)w0 * c0.a + (Sint64)w1 * c1.a + (Sint64)w2 * c2.a) / area); \
int color = SDL_MapRGBA(format, r, g, b, a); \
#define TRIANGLE_GET_MAPPED_COLOR \
int r = (int)(((Sint64)w0 * c0.r + (Sint64)w1 * c1.r + (Sint64)w2 * c2.r) / area); \
int g = (int)(((Sint64)w0 * c0.g + (Sint64)w1 * c1.g + (Sint64)w2 * c2.g) / area); \
int b = (int)(((Sint64)w0 * c0.b + (Sint64)w1 * c1.b + (Sint64)w2 * c2.b) / area); \
int a = (int)(((Sint64)w0 * c0.a + (Sint64)w1 * c1.a + (Sint64)w2 * c2.a) / area); \
int color = SDL_MapRGBA(format, r, g, b, a);
#define TRIANGLE_GET_COLOR \
int r = (int)(((Sint64)w0 * c0.r + (Sint64)w1 * c1.r + (Sint64)w2 * c2.r) / area); \
int g = (int)(((Sint64)w0 * c0.g + (Sint64)w1 * c1.g + (Sint64)w2 * c2.g) / area); \
int b = (int)(((Sint64)w0 * c0.b + (Sint64)w1 * c1.b + (Sint64)w2 * c2.b) / area); \
int a = (int)(((Sint64)w0 * c0.a + (Sint64)w1 * c1.a + (Sint64)w2 * c2.a) / area); \
#define TRIANGLE_GET_COLOR \
int r = (int)(((Sint64)w0 * c0.r + (Sint64)w1 * c1.r + (Sint64)w2 * c2.r) / area); \
int g = (int)(((Sint64)w0 * c0.g + (Sint64)w1 * c1.g + (Sint64)w2 * c2.g) / area); \
int b = (int)(((Sint64)w0 * c0.b + (Sint64)w1 * c1.b + (Sint64)w2 * c2.b) / area); \
int a = (int)(((Sint64)w0 * c0.a + (Sint64)w1 * c1.a + (Sint64)w2 * c2.a) / area);
#define TRIANGLE_END_LOOP \
} \
/* x += 1 */ \
w0 += d2d1_y; \
w1 += d0d2_y; \
w2 += d1d0_y; \
} \
/* y += 1 */ \
w0_row += d1d2_x; \
w1_row += d2d0_x; \
w2_row += d0d1_x; \
dst_ptr += dst_pitch; \
} \
} \
#define TRIANGLE_END_LOOP \
} \
/* x += 1 */ \
w0 += d2d1_y; \
w1 += d0d2_y; \
w2 += d1d0_y; \
} \
/* y += 1 */ \
w0_row += d1d2_x; \
w1_row += d2d0_x; \
w2_row += d0d1_x; \
dst_ptr += dst_pitch; \
} \
}
int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Point *d2, SDL_BlendMode blend, SDL_Color c0, SDL_Color c1, SDL_Color c2)
{
@ -265,12 +262,11 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
SDL_IntersectRect(&dstrect, &rect, &dstrect);
}
if (blend != SDL_BLENDMODE_NONE) {
int format = dst->format->format;
/* need an alpha format */
if (! dst->format->Amask) {
if (!dst->format->Amask) {
format = SDL_PIXELFORMAT_ARGB8888;
}
@ -323,7 +319,7 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
}
/* Handle anti-clockwise triangles */
if (! is_clockwise) {
if (!is_clockwise) {
d2d1_y *= -1;
d0d2_y *= -1;
d1d0_y *= -1;
@ -346,7 +342,7 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
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_MapRGB(tmp->format, c0.r, c0.g, c0.b);
color = SDL_MapRGBA(tmp->format, c0.r, c0.g, c0.b, c0.a);
}
} else {
@ -362,7 +358,7 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
} else if (dstbpp == 3) {
TRIANGLE_BEGIN_LOOP
{
Uint8 *s = (Uint8*)&color;
Uint8 *s = (Uint8 *)&color;
dptr[0] = s[0];
dptr[1] = s[1];
dptr[2] = s[2];
@ -397,7 +393,7 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
TRIANGLE_BEGIN_LOOP
{
TRIANGLE_GET_MAPPED_COLOR
Uint8 *s = (Uint8*)&color;
Uint8 *s = (Uint8 *)&color;
dptr[0] = s[0];
dptr[1] = s[1];
dptr[2] = s[2];
@ -433,18 +429,12 @@ end:
return ret;
}
int SDL_SW_BlitTriangle(
SDL_Surface *src,
SDL_Point *s0, SDL_Point *s1, SDL_Point *s2,
SDL_Surface *dst,
SDL_Point *d0, SDL_Point *d1, SDL_Point *d2,
SDL_Color c0, SDL_Color c1, SDL_Color c2)
SDL_Surface *src,
SDL_Point *s0, SDL_Point *s1, SDL_Point *s2,
SDL_Surface *dst,
SDL_Point *d0, SDL_Point *d1, SDL_Point *d2,
SDL_Color c0, SDL_Color c1, SDL_Color c2)
{
int ret = 0;
int src_locked = 0;
@ -520,20 +510,32 @@ int SDL_SW_BlitTriangle(
maxx = srcrect.x + srcrect.w;
maxy = srcrect.y + srcrect.h;
if (srcrect.w > 0) {
if (s0->x == maxx) s0->x--;
if (s1->x == maxx) s1->x--;
if (s2->x == maxx) s2->x--;
if (s0->x == maxx) {
s0->x--;
}
if (s1->x == maxx) {
s1->x--;
}
if (s2->x == maxx) {
s2->x--;
}
}
if (srcrect.h > 0) {
if (s0->y == maxy) s0->y--;
if (s1->y == maxy) s1->y--;
if (s2->y == maxy) s2->y--;
if (s0->y == maxy) {
s0->y--;
}
if (s1->y == maxy) {
s1->y--;
}
if (s2->y == maxy) {
s2->y--;
}
}
}
if (is_uniform) {
// SDL_GetSurfaceColorMod(src, &r, &g, &b);
has_modulation = c0.r != 255 || c0.g != 255 || c0.b != 255 || c0.a != 255;;
has_modulation = c0.r != 255 || c0.g != 255 || c0.b != 255 || c0.a != 255;
} else {
has_modulation = SDL_TRUE;
}
@ -572,7 +574,6 @@ int SDL_SW_BlitTriangle(
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;
@ -596,7 +597,7 @@ int SDL_SW_BlitTriangle(
}
/* Handle anti-clockwise triangles */
if (! is_clockwise) {
if (!is_clockwise) {
d2d1_y *= -1;
d0d2_y *= -1;
d1d0_y *= -1;
@ -617,7 +618,7 @@ int SDL_SW_BlitTriangle(
s2_x_area.x = s2->x * area;
s2_x_area.y = s2->y * area;
if (blend != SDL_BLENDMODE_NONE || src->format->format != dst->format->format || has_modulation || ! is_uniform) {
if (blend != SDL_BLENDMODE_NONE || src->format->format != dst->format->format || has_modulation || !is_uniform) {
/* Use SDL_BlitTriangle_Slow */
SDL_BlitInfo *info = &src->map->info;
@ -639,12 +640,11 @@ int SDL_SW_BlitTriangle(
tmp_info.b = c0.b;
tmp_info.a = c0.a;
tmp_info.flags &= ~(SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA);
if (c0.r != 255 || c1.r != 255 || c2.r != 255 ||
c0.g != 255 || c1.g != 255 || c2.g != 255 ||
c0.b != 255 || c1.b != 255 || c2.b != 255) {
if (c0.r != 255 || c1.r != 255 || c2.r != 255 ||
c0.g != 255 || c1.g != 255 || c2.g != 255 ||
c0.b != 255 || c1.b != 255 || c2.b != 255) {
tmp_info.flags |= SDL_COPY_MODULATE_COLOR;
}
@ -655,17 +655,17 @@ int SDL_SW_BlitTriangle(
tmp_info.colorkey = info->colorkey;
/* src */
tmp_info.src = (Uint8 *) src_ptr;
tmp_info.src = (Uint8 *)src_ptr;
tmp_info.src_pitch = src_pitch;
/* dst */
tmp_info.dst = (Uint8 *) dst_ptr;
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,
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,
c0, c1, c2, is_uniform);
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,
c0, c1, c2, is_uniform);
goto end;
}
@ -674,7 +674,7 @@ int SDL_SW_BlitTriangle(
TRIANGLE_BEGIN_LOOP
{
TRIANGLE_GET_TEXTCOORD
Uint32 *sptr = (Uint32 *)((Uint8 *) src_ptr + srcy * src_pitch);
Uint32 *sptr = (Uint32 *)((Uint8 *)src_ptr + srcy * src_pitch);
*(Uint32 *)dptr = sptr[srcx];
}
TRIANGLE_END_LOOP
@ -682,7 +682,7 @@ int SDL_SW_BlitTriangle(
TRIANGLE_BEGIN_LOOP
{
TRIANGLE_GET_TEXTCOORD
Uint8 *sptr = (Uint8 *)((Uint8 *) src_ptr + srcy * src_pitch);
Uint8 *sptr = (Uint8 *)src_ptr + srcy * src_pitch;
dptr[0] = sptr[3 * srcx];
dptr[1] = sptr[3 * srcx + 1];
dptr[2] = sptr[3 * srcx + 2];
@ -692,7 +692,7 @@ int SDL_SW_BlitTriangle(
TRIANGLE_BEGIN_LOOP
{
TRIANGLE_GET_TEXTCOORD
Uint16 *sptr = (Uint16 *)((Uint8 *) src_ptr + srcy * src_pitch);
Uint16 *sptr = (Uint16 *)((Uint8 *)src_ptr + srcy * src_pitch);
*(Uint16 *)dptr = sptr[srcx];
}
TRIANGLE_END_LOOP
@ -700,7 +700,7 @@ int SDL_SW_BlitTriangle(
TRIANGLE_BEGIN_LOOP
{
TRIANGLE_GET_TEXTCOORD
Uint8 *sptr = (Uint8 *)((Uint8 *) src_ptr + srcy * src_pitch);
Uint8 *sptr = (Uint8 *)src_ptr + srcy * src_pitch;
*dptr = sptr[srcx];
}
TRIANGLE_END_LOOP
@ -717,13 +717,13 @@ end:
return ret;
}
#define FORMAT_ALPHA 0
#define FORMAT_NO_ALPHA -1
#define FORMAT_2101010 1
#define FORMAT_HAS_ALPHA(format) format == 0
#define FORMAT_HAS_NO_ALPHA(format) format < 0
static int SDL_INLINE detect_format(SDL_PixelFormat *pf) {
#define FORMAT_ALPHA 0
#define FORMAT_NO_ALPHA -1
#define FORMAT_2101010 1
#define FORMAT_HAS_ALPHA(format) format == 0
#define FORMAT_HAS_NO_ALPHA(format) format < 0
static int SDL_INLINE detect_format(SDL_PixelFormat *pf)
{
if (pf->format == SDL_PIXELFORMAT_ARGB2101010) {
return FORMAT_2101010;
} else if (pf->Amask) {
@ -733,12 +733,11 @@ static int SDL_INLINE detect_format(SDL_PixelFormat *pf) {
}
}
static void
SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
SDL_Point s2_x_area, SDL_Rect dstrect, int area, int bias_w0, int bias_w1, int bias_w2,
int d2d1_y, int d1d2_x, int d0d2_y, int d2d0_x, int d1d0_y, int d0d1_x,
int s2s0_x, int s2s1_x, int s2s0_y, int s2s1_y, int w0_row, int w1_row, int w2_row,
SDL_Color c0, SDL_Color c1, SDL_Color c2, int is_uniform)
static void SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
SDL_Point s2_x_area, SDL_Rect dstrect, int area, int bias_w0, int bias_w1, int bias_w2,
int d2d1_y, int d1d2_x, int d0d2_y, int d2d0_x, int d1d0_y, int d0d1_x,
int s2s0_x, int s2s1_x, int s2s0_y, int s2s1_y, int w0_row, int w1_row, int w2_row,
SDL_Color c0, SDL_Color c1, SDL_Color c2, int is_uniform)
{
const int flags = info->flags;
Uint32 modulateR = info->r;
@ -759,7 +758,7 @@ SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
Uint32 ckey = info->colorkey & rgbmask;
Uint8 *dst_ptr = info->dst;
int dst_pitch = info->dst_pitch;;
int dst_pitch = info->dst_pitch;
srcfmt_val = detect_format(src_fmt);
dstfmt_val = detect_format(dst_fmt);
@ -784,7 +783,7 @@ SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
/* srcpixel isn't set for 24 bpp */
if (srcbpp == 3) {
srcpixel = (srcR << src_fmt->Rshift) |
(srcG << src_fmt->Gshift) | (srcB << src_fmt->Bshift);
(srcG << src_fmt->Gshift) | (srcB << src_fmt->Bshift);
}
if ((srcpixel & rgbmask) == ckey) {
continue;
@ -801,7 +800,7 @@ SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
RGBA_FROM_ARGB2101010(dstpixel, dstR, dstG, dstB, dstA);
}
if (! is_uniform) {
if (!is_uniform) {
TRIANGLE_GET_COLOR
modulateR = r;
modulateG = g;
@ -840,14 +839,17 @@ SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
break;
case SDL_COPY_ADD:
dstR = srcR + dstR;
if (dstR > 255)
if (dstR > 255) {
dstR = 255;
}
dstG = srcG + dstG;
if (dstG > 255)
if (dstG > 255) {
dstG = 255;
}
dstB = srcB + dstB;
if (dstB > 255)
if (dstB > 255) {
dstB = 255;
}
break;
case SDL_COPY_MOD:
dstR = (srcR * dstR) / 255;
@ -856,17 +858,17 @@ SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
break;
case SDL_COPY_MUL:
dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255;
if (dstR > 255)
if (dstR > 255) {
dstR = 255;
}
dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255;
if (dstG > 255)
if (dstG > 255) {
dstG = 255;
}
dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255;
if (dstB > 255)
if (dstB > 255) {
dstB = 255;
dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255;
if (dstA > 255)
dstA = 255;
}
break;
}
if (FORMAT_HAS_ALPHA(dstfmt_val)) {

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -25,15 +25,15 @@
#include "../../SDL_internal.h"
extern int SDL_SW_FillTriangle(SDL_Surface *dst,
SDL_Point *d0, SDL_Point *d1, SDL_Point *d2,
SDL_BlendMode blend, SDL_Color c0, SDL_Color c1, SDL_Color c2);
SDL_Point *d0, SDL_Point *d1, SDL_Point *d2,
SDL_BlendMode blend, SDL_Color c0, SDL_Color c1, SDL_Color c2);
extern int SDL_SW_BlitTriangle(
SDL_Surface *src,
SDL_Point *s0, SDL_Point *s1, SDL_Point *s2,
SDL_Surface *dst,
SDL_Point *d0, SDL_Point *d1, SDL_Point *d2,
SDL_Color c0, SDL_Color c1, SDL_Color c2);
SDL_Surface *src,
SDL_Point *s0, SDL_Point *s1, SDL_Point *s2,
SDL_Surface *dst,
SDL_Point *d0, SDL_Point *d1, SDL_Point *d2,
SDL_Color c0, SDL_Color c1, SDL_Color c2);
extern void trianglepoint_2_fixedpoint(SDL_Point *a);

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -25,43 +25,44 @@
#include "SDL_render_vita_gxm_memory.h"
void *
vita_mem_alloc(unsigned int type, unsigned int size, unsigned int alignment, unsigned int attribs, SceUID *uid)
void *vita_mem_alloc(unsigned int type, unsigned int size, unsigned int alignment, unsigned int attribs, SceUID *uid)
{
void *mem;
if (type == SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW) {
size = ALIGN(size, 256*1024);
size = ALIGN(size, 256 * 1024);
} else {
size = ALIGN(size, 4*1024);
size = ALIGN(size, 4 * 1024);
}
*uid = sceKernelAllocMemBlock("gpu_mem", type, size, NULL);
if (*uid < 0)
if (*uid < 0) {
return NULL;
}
if (sceKernelGetMemBlockBase(*uid, &mem) < 0)
if (sceKernelGetMemBlockBase(*uid, &mem) < 0) {
return NULL;
}
if (sceGxmMapMemory(mem, size, attribs) < 0)
if (sceGxmMapMemory(mem, size, attribs) < 0) {
return NULL;
}
return mem;
}
void
vita_mem_free(SceUID uid)
void vita_mem_free(SceUID uid)
{
void *mem = NULL;
if (sceKernelGetMemBlockBase(uid, &mem) < 0)
if (sceKernelGetMemBlockBase(uid, &mem) < 0) {
return;
}
sceGxmUnmapMemory(mem);
sceKernelFreeMemBlock(uid);
}
void *
vita_gpu_mem_alloc(VITA_GXM_RenderData *data, unsigned int size)
void *vita_gpu_mem_alloc(VITA_GXM_RenderData *data, unsigned int size)
{
void *mem;
@ -72,9 +73,9 @@ vita_gpu_mem_alloc(VITA_GXM_RenderData *data, unsigned int size)
info.size = sizeof(SceKernelFreeMemorySizeInfo);
sceKernelGetFreeMemorySize(&info);
poolsize = ALIGN(info.size_cdram, 256*1024);
poolsize = ALIGN(info.size_cdram, 256 * 1024);
if (poolsize > info.size_cdram) {
poolsize = ALIGN(info.size_cdram - 256*1024, 256*1024);
poolsize = ALIGN(info.size_cdram - 256 * 1024, 256 * 1024);
}
data->texturePoolUID = sceKernelAllocMemBlock("gpu_texture_pool", SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW, poolsize, NULL);
if (data->texturePoolUID < 0) {
@ -82,8 +83,7 @@ vita_gpu_mem_alloc(VITA_GXM_RenderData *data, unsigned int size)
}
ret = sceKernelGetMemBlockBase(data->texturePoolUID, &mem);
if ( ret < 0)
{
if (ret < 0) {
return NULL;
}
data->texturePool = sceClibMspaceCreate(mem, poolsize);
@ -92,86 +92,84 @@ vita_gpu_mem_alloc(VITA_GXM_RenderData *data, unsigned int size)
return NULL;
}
ret = sceGxmMapMemory(mem, poolsize, SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE);
if (ret < 0)
{
if (ret < 0) {
return NULL;
}
}
return sceClibMspaceMemalign(data->texturePool, SCE_GXM_TEXTURE_ALIGNMENT, size);
}
void
vita_gpu_mem_free(VITA_GXM_RenderData *data, void* ptr)
void vita_gpu_mem_free(VITA_GXM_RenderData *data, void *ptr)
{
if (data->texturePool != NULL)
{
if (data->texturePool != NULL) {
sceClibMspaceFree(data->texturePool, ptr);
}
}
void
vita_gpu_mem_destroy(VITA_GXM_RenderData *data)
void vita_gpu_mem_destroy(VITA_GXM_RenderData *data)
{
void *mem = NULL;
if (data->texturePool != NULL)
{
if (data->texturePool != NULL) {
sceClibMspaceDestroy(data->texturePool);
data->texturePool = NULL;
if (sceKernelGetMemBlockBase(data->texturePoolUID, &mem) < 0)
if (sceKernelGetMemBlockBase(data->texturePoolUID, &mem) < 0) {
return;
}
sceGxmUnmapMemory(mem);
sceKernelFreeMemBlock(data->texturePoolUID);
}
}
void *
vita_mem_vertex_usse_alloc(unsigned int size, SceUID *uid, unsigned int *usse_offset)
void *vita_mem_vertex_usse_alloc(unsigned int size, SceUID *uid, unsigned int *usse_offset)
{
void *mem = NULL;
size = ALIGN(size, 4096);
*uid = sceKernelAllocMemBlock("vertex_usse", SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE, size, NULL);
if (sceKernelGetMemBlockBase(*uid, &mem) < 0)
if (sceKernelGetMemBlockBase(*uid, &mem) < 0) {
return NULL;
if (sceGxmMapVertexUsseMemory(mem, size, usse_offset) < 0)
}
if (sceGxmMapVertexUsseMemory(mem, size, usse_offset) < 0) {
return NULL;
}
return mem;
}
void
vita_mem_vertex_usse_free(SceUID uid)
void vita_mem_vertex_usse_free(SceUID uid)
{
void *mem = NULL;
if (sceKernelGetMemBlockBase(uid, &mem) < 0)
if (sceKernelGetMemBlockBase(uid, &mem) < 0) {
return;
}
sceGxmUnmapVertexUsseMemory(mem);
sceKernelFreeMemBlock(uid);
}
void *
vita_mem_fragment_usse_alloc(unsigned int size, SceUID *uid, unsigned int *usse_offset)
void *vita_mem_fragment_usse_alloc(unsigned int size, SceUID *uid, unsigned int *usse_offset)
{
void *mem = NULL;
size = ALIGN(size, 4096);
*uid = sceKernelAllocMemBlock("fragment_usse", SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE, size, NULL);
if (sceKernelGetMemBlockBase(*uid, &mem) < 0)
if (sceKernelGetMemBlockBase(*uid, &mem) < 0) {
return NULL;
if (sceGxmMapFragmentUsseMemory(mem, size, usse_offset) < 0)
}
if (sceGxmMapFragmentUsseMemory(mem, size, usse_offset) < 0) {
return NULL;
}
return mem;
}
void
vita_mem_fragment_usse_free(SceUID uid)
void vita_mem_fragment_usse_free(SceUID uid)
{
void *mem = NULL;
if (sceKernelGetMemBlockBase(uid, &mem) < 0)
if (sceKernelGetMemBlockBase(uid, &mem) < 0) {
return;
}
sceGxmUnmapFragmentUsseMemory(mem);
sceKernelFreeMemBlock(uid);
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -27,12 +27,12 @@
#include <psp2/kernel/sysmem.h>
#include "SDL_render_vita_gxm_types.h"
#define ALIGN(x, a) (((x) + ((a) - 1)) & ~((a) - 1))
#define ALIGN(x, a) (((x) + ((a)-1)) & ~((a)-1))
void *vita_mem_alloc(unsigned int type, unsigned int size, unsigned int alignment, unsigned int attribs, SceUID *uid);
void vita_mem_free(SceUID uid);
void *vita_gpu_mem_alloc(VITA_GXM_RenderData *data, unsigned int size);
void vita_gpu_mem_free(VITA_GXM_RenderData *data, void* ptr);
void vita_gpu_mem_free(VITA_GXM_RenderData *data, void *ptr);
void vita_gpu_mem_destroy(VITA_GXM_RenderData *data);
void *vita_mem_vertex_usse_alloc(unsigned int size, SceUID *uid, unsigned int *usse_offset);
void vita_mem_vertex_usse_free(SceUID uid);

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -24,6 +24,8 @@
#include <psp2/gxm.h>
/* *INDENT-OFF* */ /* clang-format off */
#define gxm_shader_clear_f_size 232
static const unsigned char gxm_shader_clear_f[gxm_shader_clear_f_size] = {
0x47, 0x58, 0x50, 0x00, 0x01, 0x05, 0x50, 0x03,
@ -268,12 +270,14 @@ static const unsigned char gxm_shader_texture_v[gxm_shader_texture_v_size] = {
0x6f, 0x72, 0x00, 0x77, 0x76, 0x70, 0x00, 0x00,
};
static const SceGxmProgram *const clearVertexProgramGxp = (const SceGxmProgram *)gxm_shader_clear_v;
static const SceGxmProgram *const clearFragmentProgramGxp = (const SceGxmProgram *)gxm_shader_clear_f;
static const SceGxmProgram *const colorVertexProgramGxp = (const SceGxmProgram *)gxm_shader_color_v;
static const SceGxmProgram *const colorFragmentProgramGxp = (const SceGxmProgram *)gxm_shader_color_f;
static const SceGxmProgram *const textureVertexProgramGxp = (const SceGxmProgram *)gxm_shader_texture_v;
static const SceGxmProgram *const textureFragmentProgramGxp = (const SceGxmProgram *)gxm_shader_texture_f;
/* *INDENT-ON* */ /* clang-format on */
static const SceGxmProgram *const clearVertexProgramGxp = (const SceGxmProgram *)gxm_shader_clear_v;
static const SceGxmProgram *const clearFragmentProgramGxp = (const SceGxmProgram *)gxm_shader_clear_f;
static const SceGxmProgram *const colorVertexProgramGxp = (const SceGxmProgram *)gxm_shader_color_v;
static const SceGxmProgram *const colorFragmentProgramGxp = (const SceGxmProgram *)gxm_shader_color_f;
static const SceGxmProgram *const textureVertexProgramGxp = (const SceGxmProgram *)gxm_shader_texture_v;
static const SceGxmProgram *const textureFragmentProgramGxp = (const SceGxmProgram *)gxm_shader_texture_f;
#endif // SDL_RENDER_VITA_GXM_SHADERS_H

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -45,23 +45,22 @@
#include "SDL_render_vita_gxm_memory.h"
#include "SDL_render_vita_gxm_shaders.h"
void
init_orthographic_matrix(float *m, float left, float right, float bottom, float top, float near, float far)
void init_orthographic_matrix(float *m, float left, float right, float bottom, float top, float near, float far)
{
m[0x0] = 2.0f/(right-left);
m[0x0] = 2.0f / (right - left);
m[0x4] = 0.0f;
m[0x8] = 0.0f;
m[0xC] = -(right+left)/(right-left);
m[0xC] = -(right + left) / (right - left);
m[0x1] = 0.0f;
m[0x5] = 2.0f/(top-bottom);
m[0x5] = 2.0f / (top - bottom);
m[0x9] = 0.0f;
m[0xD] = -(top+bottom)/(top-bottom);
m[0xD] = -(top + bottom) / (top - bottom);
m[0x2] = 0.0f;
m[0x6] = 0.0f;
m[0xA] = -2.0f/(far-near);
m[0xE] = (far+near)/(far-near);
m[0xA] = -2.0f / (far - near);
m[0xE] = (far + near) / (far - near);
m[0x3] = 0.0f;
m[0x7] = 0.0f;
@ -69,23 +68,20 @@ init_orthographic_matrix(float *m, float left, float right, float bottom, float
m[0xF] = 1.0f;
}
static void *
patcher_host_alloc(void *user_data, unsigned int size)
static void *patcher_host_alloc(void *user_data, unsigned int size)
{
void *mem = SDL_malloc(size);
(void)user_data;
return mem;
}
static void
patcher_host_free(void *user_data, void *mem)
static void patcher_host_free(void *user_data, void *mem)
{
(void)user_data;
SDL_free(mem);
}
void *
pool_malloc(VITA_GXM_RenderData *data, unsigned int size)
void *pool_malloc(VITA_GXM_RenderData *data, unsigned int size)
{
if ((data->pool_index + size) < VITA_GXM_POOL_SIZE) {
@ -97,8 +93,7 @@ pool_malloc(VITA_GXM_RenderData *data, unsigned int size)
return NULL;
}
void *
pool_memalign(VITA_GXM_RenderData *data, unsigned int size, unsigned int alignment)
void *pool_memalign(VITA_GXM_RenderData *data, unsigned int size, unsigned int alignment)
{
unsigned int new_index = (data->pool_index + alignment - 1) & ~(alignment - 1);
if ((new_index + size) < VITA_GXM_POOL_SIZE) {
@ -110,8 +105,7 @@ pool_memalign(VITA_GXM_RenderData *data, unsigned int size, unsigned int alignme
return NULL;
}
static int
tex_format_to_bytespp(SceGxmTextureFormat format)
static int tex_format_to_bytespp(SceGxmTextureFormat format)
{
switch (format & 0x9f000000U) {
case SCE_GXM_TEXTURE_BASE_FORMAT_U8:
@ -141,19 +135,18 @@ tex_format_to_bytespp(SceGxmTextureFormat format)
}
}
static void
display_callback(const void *callback_data)
static void display_callback(const void *callback_data)
{
SceDisplayFrameBuf framebuf;
const VITA_GXM_DisplayData *display_data = (const VITA_GXM_DisplayData *)callback_data;
SDL_memset(&framebuf, 0x00, sizeof(SceDisplayFrameBuf));
framebuf.size = sizeof(SceDisplayFrameBuf);
framebuf.base = display_data->address;
framebuf.pitch = VITA_GXM_SCREEN_STRIDE;
framebuf.size = sizeof(SceDisplayFrameBuf);
framebuf.base = display_data->address;
framebuf.pitch = VITA_GXM_SCREEN_STRIDE;
framebuf.pixelformat = VITA_GXM_PIXEL_FORMAT;
framebuf.width = VITA_GXM_SCREEN_WIDTH;
framebuf.height = VITA_GXM_SCREEN_HEIGHT;
framebuf.width = VITA_GXM_SCREEN_WIDTH;
framebuf.height = VITA_GXM_SCREEN_HEIGHT;
sceDisplaySetFrameBuf(&framebuf, SCE_DISPLAY_SETBUF_NEXTFRAME);
if (display_data->wait_vblank) {
@ -161,16 +154,14 @@ display_callback(const void *callback_data)
}
}
static void
free_fragment_programs(VITA_GXM_RenderData *data, fragment_programs *out)
static void free_fragment_programs(VITA_GXM_RenderData *data, fragment_programs *out)
{
sceGxmShaderPatcherReleaseFragmentProgram(data->shaderPatcher, out->color);
sceGxmShaderPatcherReleaseFragmentProgram(data->shaderPatcher, out->texture);
}
static void
make_fragment_programs(VITA_GXM_RenderData *data, fragment_programs *out,
const SceGxmBlendInfo *blend_info)
static void make_fragment_programs(VITA_GXM_RenderData *data, fragment_programs *out,
const SceGxmBlendInfo *blend_info)
{
int err;
@ -181,8 +172,7 @@ make_fragment_programs(VITA_GXM_RenderData *data, fragment_programs *out,
0,
blend_info,
colorVertexProgramGxp,
&out->color
);
&out->color);
if (err != 0) {
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "Patcher create fragment failed: %d\n", err);
@ -196,8 +186,7 @@ make_fragment_programs(VITA_GXM_RenderData *data, fragment_programs *out,
0,
blend_info,
textureVertexProgramGxp,
&out->texture
);
&out->texture);
if (err != 0) {
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "Patcher create fragment failed: %d\n", err);
@ -205,16 +194,13 @@ make_fragment_programs(VITA_GXM_RenderData *data, fragment_programs *out,
}
}
static void
set_stencil_mask(VITA_GXM_RenderData *data, float x, float y, float w, float h)
static void set_stencil_mask(VITA_GXM_RenderData *data, float x, float y, float w, float h)
{
void *vertexDefaultBuffer;
color_vertex *vertices = (color_vertex *)pool_memalign(
data,
4 * sizeof(color_vertex), // 4 vertices
sizeof(color_vertex)
);
sizeof(color_vertex));
vertices[0].x = x;
vertices[0].y = y;
@ -256,11 +242,9 @@ set_stencil_mask(VITA_GXM_RenderData *data, float x, float y, float w, float h)
sceGxmDraw(data->gxm_context, SCE_GXM_PRIMITIVE_TRIANGLE_STRIP, SCE_GXM_INDEX_FORMAT_U16, data->linearIndices, 4);
}
void
set_clip_rectangle(VITA_GXM_RenderData *data, int x_min, int y_min, int x_max, int y_max)
void set_clip_rectangle(VITA_GXM_RenderData *data, int x_min, int y_min, int x_max, int y_max)
{
if(data->drawing) {
if (data->drawing) {
// clear the stencil buffer to 0
sceGxmSetFrontStencilFunc(
data->gxm_context,
@ -269,8 +253,7 @@ set_clip_rectangle(VITA_GXM_RenderData *data, int x_min, int y_min, int x_max, i
SCE_GXM_STENCIL_OP_ZERO,
SCE_GXM_STENCIL_OP_ZERO,
0xFF,
0xFF
);
0xFF);
set_stencil_mask(data, 0, 0, VITA_GXM_SCREEN_WIDTH, VITA_GXM_SCREEN_HEIGHT);
@ -282,8 +265,7 @@ set_clip_rectangle(VITA_GXM_RenderData *data, int x_min, int y_min, int x_max, i
SCE_GXM_STENCIL_OP_REPLACE,
SCE_GXM_STENCIL_OP_REPLACE,
0xFF,
0xFF
);
0xFF);
set_stencil_mask(data, x_min, y_min, x_max - x_min, y_max - y_min);
@ -295,13 +277,11 @@ set_clip_rectangle(VITA_GXM_RenderData *data, int x_min, int y_min, int x_max, i
SCE_GXM_STENCIL_OP_KEEP,
SCE_GXM_STENCIL_OP_KEEP,
0xFF,
0xFF
);
0xFF);
}
}
void
unset_clip_rectangle(VITA_GXM_RenderData *data)
void unset_clip_rectangle(VITA_GXM_RenderData *data)
{
sceGxmSetFrontStencilFunc(
data->gxm_context,
@ -310,12 +290,10 @@ unset_clip_rectangle(VITA_GXM_RenderData *data)
SCE_GXM_STENCIL_OP_KEEP,
SCE_GXM_STENCIL_OP_KEEP,
0xFF,
0xFF
);
0xFF);
}
int
gxm_init(SDL_Renderer *renderer)
int gxm_init(SDL_Renderer *renderer)
{
unsigned int i, x, y;
int err;
@ -341,38 +319,38 @@ gxm_init(SDL_Renderer *renderer)
unsigned int depthStrideInSamples = alignedWidth;
// set buffer sizes for this sample
const unsigned int patcherBufferSize = 64*1024;
const unsigned int patcherVertexUsseSize = 64*1024;
const unsigned int patcherFragmentUsseSize = 64*1024;
const unsigned int patcherBufferSize = 64 * 1024;
const unsigned int patcherVertexUsseSize = 64 * 1024;
const unsigned int patcherFragmentUsseSize = 64 * 1024;
// Fill SceGxmBlendInfo
static const SceGxmBlendInfo blend_info_none = {
.colorFunc = SCE_GXM_BLEND_FUNC_NONE,
.alphaFunc = SCE_GXM_BLEND_FUNC_NONE,
.colorSrc = SCE_GXM_BLEND_FACTOR_ZERO,
.colorDst = SCE_GXM_BLEND_FACTOR_ZERO,
.alphaSrc = SCE_GXM_BLEND_FACTOR_ZERO,
.alphaDst = SCE_GXM_BLEND_FACTOR_ZERO,
.colorSrc = SCE_GXM_BLEND_FACTOR_ZERO,
.colorDst = SCE_GXM_BLEND_FACTOR_ZERO,
.alphaSrc = SCE_GXM_BLEND_FACTOR_ZERO,
.alphaDst = SCE_GXM_BLEND_FACTOR_ZERO,
.colorMask = SCE_GXM_COLOR_MASK_ALL
};
static const SceGxmBlendInfo blend_info_blend = {
.colorFunc = SCE_GXM_BLEND_FUNC_ADD,
.alphaFunc = SCE_GXM_BLEND_FUNC_ADD,
.colorSrc = SCE_GXM_BLEND_FACTOR_SRC_ALPHA,
.colorDst = SCE_GXM_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
.alphaSrc = SCE_GXM_BLEND_FACTOR_ONE,
.alphaDst = SCE_GXM_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
.colorSrc = SCE_GXM_BLEND_FACTOR_SRC_ALPHA,
.colorDst = SCE_GXM_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
.alphaSrc = SCE_GXM_BLEND_FACTOR_ONE,
.alphaDst = SCE_GXM_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
.colorMask = SCE_GXM_COLOR_MASK_ALL
};
static const SceGxmBlendInfo blend_info_add = {
.colorFunc = SCE_GXM_BLEND_FUNC_ADD,
.alphaFunc = SCE_GXM_BLEND_FUNC_ADD,
.colorSrc = SCE_GXM_BLEND_FACTOR_SRC_ALPHA,
.colorDst = SCE_GXM_BLEND_FACTOR_ONE,
.alphaSrc = SCE_GXM_BLEND_FACTOR_ZERO,
.alphaDst = SCE_GXM_BLEND_FACTOR_ONE,
.colorSrc = SCE_GXM_BLEND_FACTOR_SRC_ALPHA,
.colorDst = SCE_GXM_BLEND_FACTOR_ONE,
.alphaSrc = SCE_GXM_BLEND_FACTOR_ZERO,
.alphaDst = SCE_GXM_BLEND_FACTOR_ONE,
.colorMask = SCE_GXM_COLOR_MASK_ALL
};
@ -380,33 +358,33 @@ gxm_init(SDL_Renderer *renderer)
.colorFunc = SCE_GXM_BLEND_FUNC_ADD,
.alphaFunc = SCE_GXM_BLEND_FUNC_ADD,
.colorSrc = SCE_GXM_BLEND_FACTOR_ZERO,
.colorDst = SCE_GXM_BLEND_FACTOR_SRC_COLOR,
.colorSrc = SCE_GXM_BLEND_FACTOR_ZERO,
.colorDst = SCE_GXM_BLEND_FACTOR_SRC_COLOR,
.alphaSrc = SCE_GXM_BLEND_FACTOR_ZERO,
.alphaDst = SCE_GXM_BLEND_FACTOR_ONE,
.alphaSrc = SCE_GXM_BLEND_FACTOR_ZERO,
.alphaDst = SCE_GXM_BLEND_FACTOR_ONE,
.colorMask = SCE_GXM_COLOR_MASK_ALL
};
static const SceGxmBlendInfo blend_info_mul = {
.colorFunc = SCE_GXM_BLEND_FUNC_ADD,
.alphaFunc = SCE_GXM_BLEND_FUNC_ADD,
.colorSrc = SCE_GXM_BLEND_FACTOR_DST_COLOR,
.colorDst = SCE_GXM_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
.alphaSrc = SCE_GXM_BLEND_FACTOR_DST_ALPHA,
.alphaDst = SCE_GXM_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
.colorSrc = SCE_GXM_BLEND_FACTOR_DST_COLOR,
.colorDst = SCE_GXM_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
.alphaSrc = SCE_GXM_BLEND_FACTOR_DST_ALPHA,
.alphaDst = SCE_GXM_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
.colorMask = SCE_GXM_COLOR_MASK_ALL
};
VITA_GXM_RenderData *data = (VITA_GXM_RenderData *) renderer->driverdata;
VITA_GXM_RenderData *data = (VITA_GXM_RenderData *)renderer->driverdata;
SceGxmInitializeParams initializeParams;
SDL_memset(&initializeParams, 0, sizeof(SceGxmInitializeParams));
initializeParams.flags = 0;
initializeParams.displayQueueMaxPendingCount = VITA_GXM_PENDING_SWAPS;
initializeParams.displayQueueCallback = display_callback;
initializeParams.displayQueueCallbackDataSize = sizeof(VITA_GXM_DisplayData);
initializeParams.parameterBufferSize = SCE_GXM_DEFAULT_PARAMETER_BUFFER_SIZE;
initializeParams.flags = 0;
initializeParams.displayQueueMaxPendingCount = VITA_GXM_PENDING_SWAPS;
initializeParams.displayQueueCallback = display_callback;
initializeParams.displayQueueCallbackDataSize = sizeof(VITA_GXM_DisplayData);
initializeParams.parameterBufferSize = SCE_GXM_DEFAULT_PARAMETER_BUFFER_SIZE;
err = sceGxmInitialize(&initializeParams);
@ -443,17 +421,17 @@ gxm_init(SDL_Renderer *renderer)
&fragmentUsseRingBufferOffset);
SDL_memset(&data->contextParams, 0, sizeof(SceGxmContextParams));
data->contextParams.hostMem = SDL_malloc(SCE_GXM_MINIMUM_CONTEXT_HOST_MEM_SIZE);
data->contextParams.hostMemSize = SCE_GXM_MINIMUM_CONTEXT_HOST_MEM_SIZE;
data->contextParams.vdmRingBufferMem = vdmRingBuffer;
data->contextParams.vdmRingBufferMemSize = SCE_GXM_DEFAULT_VDM_RING_BUFFER_SIZE;
data->contextParams.vertexRingBufferMem = vertexRingBuffer;
data->contextParams.vertexRingBufferMemSize = SCE_GXM_DEFAULT_VERTEX_RING_BUFFER_SIZE;
data->contextParams.fragmentRingBufferMem = fragmentRingBuffer;
data->contextParams.fragmentRingBufferMemSize = SCE_GXM_DEFAULT_FRAGMENT_RING_BUFFER_SIZE;
data->contextParams.fragmentUsseRingBufferMem = fragmentUsseRingBuffer;
data->contextParams.hostMem = SDL_malloc(SCE_GXM_MINIMUM_CONTEXT_HOST_MEM_SIZE);
data->contextParams.hostMemSize = SCE_GXM_MINIMUM_CONTEXT_HOST_MEM_SIZE;
data->contextParams.vdmRingBufferMem = vdmRingBuffer;
data->contextParams.vdmRingBufferMemSize = SCE_GXM_DEFAULT_VDM_RING_BUFFER_SIZE;
data->contextParams.vertexRingBufferMem = vertexRingBuffer;
data->contextParams.vertexRingBufferMemSize = SCE_GXM_DEFAULT_VERTEX_RING_BUFFER_SIZE;
data->contextParams.fragmentRingBufferMem = fragmentRingBuffer;
data->contextParams.fragmentRingBufferMemSize = SCE_GXM_DEFAULT_FRAGMENT_RING_BUFFER_SIZE;
data->contextParams.fragmentUsseRingBufferMem = fragmentUsseRingBuffer;
data->contextParams.fragmentUsseRingBufferMemSize = SCE_GXM_DEFAULT_FRAGMENT_USSE_RING_BUFFER_SIZE;
data->contextParams.fragmentUsseRingBufferOffset = fragmentUsseRingBufferOffset;
data->contextParams.fragmentUsseRingBufferOffset = fragmentUsseRingBufferOffset;
err = sceGxmCreateContext(&data->contextParams, &data->gxm_context);
if (err != 0) {
@ -463,13 +441,13 @@ gxm_init(SDL_Renderer *renderer)
// set up parameters
SDL_memset(&renderTargetParams, 0, sizeof(SceGxmRenderTargetParams));
renderTargetParams.flags = 0;
renderTargetParams.width = VITA_GXM_SCREEN_WIDTH;
renderTargetParams.height = VITA_GXM_SCREEN_HEIGHT;
renderTargetParams.scenesPerFrame = 1;
renderTargetParams.multisampleMode = 0;
renderTargetParams.flags = 0;
renderTargetParams.width = VITA_GXM_SCREEN_WIDTH;
renderTargetParams.height = VITA_GXM_SCREEN_HEIGHT;
renderTargetParams.scenesPerFrame = 1;
renderTargetParams.multisampleMode = 0;
renderTargetParams.multisampleLocations = 0;
renderTargetParams.driverMemBlock = -1; // Invalid UID
renderTargetParams.driverMemBlock = -1; // Invalid UID
// create the render target
err = sceGxmCreateRenderTarget(&renderTargetParams, &data->renderTarget);
@ -507,25 +485,21 @@ gxm_init(SDL_Renderer *renderer)
VITA_GXM_SCREEN_WIDTH,
VITA_GXM_SCREEN_HEIGHT,
VITA_GXM_SCREEN_STRIDE,
data->displayBufferData[i]
);
data->displayBufferData[i]);
if (err != 0) {
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "color surface init failed: %d\n", err);
return err;
}
// create a sync object that we will associate with this buffer
err = sceGxmSyncObjectCreate(&data->displayBufferSync[i]);
if (err != 0) {
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "sync object creation failed: %d\n", err);
return err;
}
}
// allocate the depth buffer
data->depthBufferData = vita_mem_alloc(
SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE,
@ -554,7 +528,6 @@ gxm_init(SDL_Renderer *renderer)
// set the stencil test reference (this is currently assumed to always remain 1 after here for region clipping)
sceGxmSetFrontStencilRef(data->gxm_context, 1);
// set the stencil function (this wouldn't actually be needed, as the set clip rectangle function has to call this at the begginning of every scene)
sceGxmSetFrontStencilFunc(
data->gxm_context,
@ -565,7 +538,6 @@ gxm_init(SDL_Renderer *renderer)
0xFF,
0xFF);
// allocate memory for buffers and USSE code
patcherBuffer = vita_mem_alloc(
SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE,
@ -586,23 +558,23 @@ gxm_init(SDL_Renderer *renderer)
// create a shader patcher
SDL_memset(&patcherParams, 0, sizeof(SceGxmShaderPatcherParams));
patcherParams.userData = NULL;
patcherParams.hostAllocCallback = &patcher_host_alloc;
patcherParams.hostFreeCallback = &patcher_host_free;
patcherParams.bufferAllocCallback = NULL;
patcherParams.bufferFreeCallback = NULL;
patcherParams.bufferMem = patcherBuffer;
patcherParams.bufferMemSize = patcherBufferSize;
patcherParams.vertexUsseAllocCallback = NULL;
patcherParams.vertexUsseFreeCallback = NULL;
patcherParams.vertexUsseMem = patcherVertexUsse;
patcherParams.vertexUsseMemSize = patcherVertexUsseSize;
patcherParams.vertexUsseOffset = patcherVertexUsseOffset;
patcherParams.userData = NULL;
patcherParams.hostAllocCallback = &patcher_host_alloc;
patcherParams.hostFreeCallback = &patcher_host_free;
patcherParams.bufferAllocCallback = NULL;
patcherParams.bufferFreeCallback = NULL;
patcherParams.bufferMem = patcherBuffer;
patcherParams.bufferMemSize = patcherBufferSize;
patcherParams.vertexUsseAllocCallback = NULL;
patcherParams.vertexUsseFreeCallback = NULL;
patcherParams.vertexUsseMem = patcherVertexUsse;
patcherParams.vertexUsseMemSize = patcherVertexUsseSize;
patcherParams.vertexUsseOffset = patcherVertexUsseOffset;
patcherParams.fragmentUsseAllocCallback = NULL;
patcherParams.fragmentUsseFreeCallback = NULL;
patcherParams.fragmentUsseMem = patcherFragmentUsse;
patcherParams.fragmentUsseMemSize = patcherFragmentUsseSize;
patcherParams.fragmentUsseOffset = patcherFragmentUsseOffset;
patcherParams.fragmentUsseFreeCallback = NULL;
patcherParams.fragmentUsseMem = patcherFragmentUsse;
patcherParams.fragmentUsseMemSize = patcherFragmentUsseSize;
patcherParams.fragmentUsseOffset = patcherFragmentUsseOffset;
err = sceGxmShaderPatcherCreate(&patcherParams, &data->shaderPatcher);
if (err != 0) {
@ -610,7 +582,6 @@ gxm_init(SDL_Renderer *renderer)
return err;
}
// check the shaders
err = sceGxmProgramCheck(clearVertexProgramGxp);
if (err != 0) {
@ -692,13 +663,13 @@ gxm_init(SDL_Renderer *renderer)
// create clear vertex format
SceGxmVertexAttribute clearVertexAttributes[1];
SceGxmVertexStream clearVertexStreams[1];
clearVertexAttributes[0].streamIndex = 0;
clearVertexAttributes[0].offset = 0;
clearVertexAttributes[0].format = SCE_GXM_ATTRIBUTE_FORMAT_F32;
clearVertexAttributes[0].streamIndex = 0;
clearVertexAttributes[0].offset = 0;
clearVertexAttributes[0].format = SCE_GXM_ATTRIBUTE_FORMAT_F32;
clearVertexAttributes[0].componentCount = 2;
clearVertexAttributes[0].regIndex = sceGxmProgramParameterGetResourceIndex(paramClearPositionAttribute);
clearVertexStreams[0].stride = sizeof(clear_vertex);
clearVertexStreams[0].indexSource = SCE_GXM_INDEX_SOURCE_INDEX_16BIT;
clearVertexAttributes[0].regIndex = sceGxmProgramParameterGetResourceIndex(paramClearPositionAttribute);
clearVertexStreams[0].stride = sizeof(clear_vertex);
clearVertexStreams[0].indexSource = SCE_GXM_INDEX_SOURCE_INDEX_16BIT;
// create clear programs
err = sceGxmShaderPatcherCreateVertexProgram(
@ -708,8 +679,7 @@ gxm_init(SDL_Renderer *renderer)
1,
clearVertexStreams,
1,
&data->clearVertexProgram
);
&data->clearVertexProgram);
if (err != 0) {
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "create program (clear vertex) failed: %d\n", err);
return err;
@ -722,8 +692,7 @@ gxm_init(SDL_Renderer *renderer)
0,
NULL,
clearVertexProgramGxp,
&data->clearFragmentProgram
);
&data->clearFragmentProgram);
if (err != 0) {
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "create program (clear fragment) failed: %d\n", err);
return err;
@ -732,11 +701,10 @@ gxm_init(SDL_Renderer *renderer)
// create the clear triangle vertex/index data
data->clearVertices = (clear_vertex *)vita_mem_alloc(
SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE,
3*sizeof(clear_vertex),
3 * sizeof(clear_vertex),
4,
SCE_GXM_MEMORY_ATTRIB_READ,
&data->clearVerticesUid
);
&data->clearVerticesUid);
}
// Allocate a 64k * 2 bytes = 128 KiB buffer and store all possible
@ -744,23 +712,21 @@ gxm_init(SDL_Renderer *renderer)
// all drawing operations where we don't want to use indexing.
data->linearIndices = (uint16_t *)vita_mem_alloc(
SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE,
UINT16_MAX*sizeof(uint16_t),
UINT16_MAX * sizeof(uint16_t),
sizeof(uint16_t),
SCE_GXM_MEMORY_ATTRIB_READ,
&data->linearIndicesUid
);
&data->linearIndicesUid);
for (i = 0; i <= UINT16_MAX; ++i)
{
for (i = 0; i <= UINT16_MAX; ++i) {
data->linearIndices[i] = i;
}
data->clearVertices[0].x = -1.0f;
data->clearVertices[0].y = -1.0f;
data->clearVertices[1].x = 3.0f;
data->clearVertices[1].x = 3.0f;
data->clearVertices[1].y = -1.0f;
data->clearVertices[2].x = -1.0f;
data->clearVertices[2].y = 3.0f;
data->clearVertices[2].y = 3.0f;
{
const SceGxmProgramParameter *paramColorPositionAttribute = sceGxmProgramFindParameterByName(colorVertexProgramGxp, "aPosition");
@ -794,16 +760,13 @@ gxm_init(SDL_Renderer *renderer)
2,
colorVertexStreams,
1,
&data->colorVertexProgram
);
&data->colorVertexProgram);
if (err != 0) {
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "create program (color vertex) failed: %d\n", err);
return err;
}
}
{
const SceGxmProgramParameter *paramTexturePositionAttribute = sceGxmProgramFindParameterByName(textureVertexProgramGxp, "aPosition");
const SceGxmProgramParameter *paramTextureTexcoordAttribute = sceGxmProgramFindParameterByName(textureVertexProgramGxp, "aTexcoord");
@ -842,13 +805,11 @@ gxm_init(SDL_Renderer *renderer)
3,
textureVertexStreams,
1,
&data->textureVertexProgram
);
&data->textureVertexProgram);
if (err != 0) {
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "create program (texture vertex) failed: %x\n", err);
return err;
}
}
// Create variations of the fragment program based on blending mode
@ -864,7 +825,6 @@ gxm_init(SDL_Renderer *renderer)
data->colorFragmentProgram = in->color;
data->textureFragmentProgram = in->texture;
}
// find vertex uniforms by name and cache parameter information
@ -878,16 +838,14 @@ gxm_init(SDL_Renderer *renderer)
VITA_GXM_POOL_SIZE,
sizeof(void *),
SCE_GXM_MEMORY_ATTRIB_READ,
&data->poolUid[0]
);
&data->poolUid[0]);
data->pool_addr[1] = vita_mem_alloc(
SCE_KERNEL_MEMBLOCK_TYPE_USER_RW,
VITA_GXM_POOL_SIZE,
sizeof(void *),
SCE_GXM_MEMORY_ATTRIB_READ,
&data->poolUid[1]
);
&data->poolUid[1]);
init_orthographic_matrix(data->ortho_matrix, 0.0f, VITA_GXM_SCREEN_WIDTH, VITA_GXM_SCREEN_HEIGHT, 0.0f, 0.0f, 1.0f);
@ -902,7 +860,7 @@ gxm_init(SDL_Renderer *renderer)
void gxm_finish(SDL_Renderer *renderer)
{
VITA_GXM_RenderData *data = (VITA_GXM_RenderData *) renderer->driverdata;
VITA_GXM_RenderData *data = (VITA_GXM_RenderData *)renderer->driverdata;
// wait until rendering is done
sceGxmFinish(data->gxm_context);
@ -913,7 +871,6 @@ void gxm_finish(SDL_Renderer *renderer)
sceGxmShaderPatcherReleaseVertexProgram(data->shaderPatcher, data->colorVertexProgram);
sceGxmShaderPatcherReleaseVertexProgram(data->shaderPatcher, data->textureVertexProgram);
free_fragment_programs(data, &data->blendFragmentPrograms.blend_mode_none);
free_fragment_programs(data, &data->blendFragmentPrograms.blend_mode_blend);
free_fragment_programs(data, &data->blendFragmentPrograms.blend_mode_add);
@ -929,8 +886,7 @@ void gxm_finish(SDL_Renderer *renderer)
// clean up display queue
vita_mem_free(data->depthBufferUid);
for (size_t i = 0; i < VITA_GXM_BUFFERS; i++)
{
for (size_t i = 0; i < VITA_GXM_BUFFERS; i++) {
// clear the buffer then deallocate
SDL_memset(data->displayBufferData[i], 0, VITA_GXM_SCREEN_HEIGHT * VITA_GXM_SCREEN_STRIDE * 4);
vita_mem_free(data->displayBufferUid[i]);
@ -977,8 +933,7 @@ void gxm_finish(SDL_Renderer *renderer)
// textures
void
free_gxm_texture(VITA_GXM_RenderData *data, gxm_texture *texture)
void free_gxm_texture(VITA_GXM_RenderData *data, gxm_texture *texture)
{
if (texture) {
if (texture->gxm_rendertarget) {
@ -1002,36 +957,55 @@ gxm_texture_get_format(const gxm_texture *texture)
return sceGxmTextureGetFormat(&texture->gxm_tex);
}
void *
gxm_texture_get_datap(const gxm_texture *texture)
void *gxm_texture_get_datap(const gxm_texture *texture)
{
return sceGxmTextureGetData(&texture->gxm_tex);
}
gxm_texture *
create_gxm_texture(VITA_GXM_RenderData *data, unsigned int w, unsigned int h, SceGxmTextureFormat format, unsigned int isRenderTarget, unsigned int *return_w, unsigned int *return_h, unsigned int *return_pitch, float *return_wscale)
static SceGxmColorFormat tex_format_to_color_format(SceGxmTextureFormat format)
{
switch (format) {
case SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_ARGB:
return SCE_GXM_COLOR_FORMAT_U8U8U8U8_ARGB;
case SCE_GXM_TEXTURE_FORMAT_U8U8U8_RGB:
return SCE_GXM_COLOR_FORMAT_U8U8U8_RGB;
case SCE_GXM_TEXTURE_FORMAT_U8U8U8_BGR:
return SCE_GXM_COLOR_FORMAT_U8U8U8_BGR;
case SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_ABGR:
return SCE_GXM_COLOR_FORMAT_U8U8U8U8_ABGR;
case SCE_GXM_TEXTURE_FORMAT_U5U6U5_RGB:
return SCE_GXM_COLOR_FORMAT_U5U6U5_RGB;
case SCE_GXM_TEXTURE_FORMAT_U5U6U5_BGR:
return SCE_GXM_COLOR_FORMAT_U5U6U5_BGR;
default:
return SCE_GXM_COLOR_FORMAT_U8U8U8U8_ABGR;
}
}
gxm_texture *create_gxm_texture(VITA_GXM_RenderData *data, unsigned int w, unsigned int h, SceGxmTextureFormat format, unsigned int isRenderTarget, unsigned int *return_w, unsigned int *return_h, unsigned int *return_pitch, float *return_wscale)
{
gxm_texture *texture = SDL_calloc(1, sizeof(gxm_texture));
int aligned_w = ALIGN(w, 8);
int texture_w = w;
int tex_size = aligned_w * h * tex_format_to_bytespp(format);
int tex_size = aligned_w * h * tex_format_to_bytespp(format);
void *texture_data;
int ret;
*return_wscale = 1.0f;
// SCE_GXM_TEXTURE_BASE_FORMAT_YUV420P3/P2 based formats require width aligned to 16
if ( (format & 0x9f000000U) == SCE_GXM_TEXTURE_BASE_FORMAT_YUV420P3 || (format & 0x9f000000U) == SCE_GXM_TEXTURE_BASE_FORMAT_YUV420P2) {
if ((format & 0x9f000000U) == SCE_GXM_TEXTURE_BASE_FORMAT_YUV420P3 || (format & 0x9f000000U) == SCE_GXM_TEXTURE_BASE_FORMAT_YUV420P2) {
aligned_w = ALIGN(w, 16);
texture_w = aligned_w;
tex_size = aligned_w * h * tex_format_to_bytespp(format);
*return_wscale = (float) (w) / texture_w;
tex_size = aligned_w * h * tex_format_to_bytespp(format);
*return_wscale = (float)(w) / texture_w;
// add storage for UV planes
tex_size += (((aligned_w + 1) / 2) * ((h + 1) / 2)) * 2;
}
if (!texture)
if (texture == NULL) {
return NULL;
}
*return_w = w;
*return_h = h;
@ -1040,25 +1014,23 @@ create_gxm_texture(VITA_GXM_RenderData *data, unsigned int w, unsigned int h, Sc
/* Allocate a GPU buffer for the texture */
texture_data = vita_gpu_mem_alloc(
data,
tex_size
);
tex_size);
/* Try SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE in case we're out of VRAM */
if (!texture_data) {
if (texture_data == NULL) {
SDL_LogWarn(SDL_LOG_CATEGORY_RENDER, "CDRAM texture allocation failed\n");
texture_data = vita_mem_alloc(
SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE,
tex_size,
SCE_GXM_TEXTURE_ALIGNMENT,
SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE,
&texture->data_UID
);
&texture->data_UID);
texture->cdram = 0;
} else {
texture->cdram = 1;
}
if (!texture_data) {
if (texture_data == NULL) {
SDL_free(texture);
return NULL;
}
@ -1067,32 +1039,31 @@ create_gxm_texture(VITA_GXM_RenderData *data, unsigned int w, unsigned int h, Sc
SDL_memset(texture_data, 0, tex_size);
/* Create the gxm texture */
ret = sceGxmTextureInitLinear( &texture->gxm_tex, texture_data, format, texture_w, h, 0);
ret = sceGxmTextureInitLinear(&texture->gxm_tex, texture_data, format, texture_w, h, 0);
if (ret < 0) {
free_gxm_texture(data, texture);
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "texture init failed: %x\n", ret);
return NULL;
free_gxm_texture(data, texture);
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "texture init failed: %x\n", ret);
return NULL;
}
if (isRenderTarget) {
void *depthBufferData;
const uint32_t alignedWidth = ALIGN(w, SCE_GXM_TILE_SIZEX);
const uint32_t alignedHeight = ALIGN(h, SCE_GXM_TILE_SIZEY);
uint32_t sampleCount = alignedWidth*alignedHeight;
uint32_t sampleCount = alignedWidth * alignedHeight;
uint32_t depthStrideInSamples = alignedWidth;
const uint32_t alignedColorSurfaceStride = ALIGN(w, 8);
int err = sceGxmColorSurfaceInit(
&texture->gxm_colorsurface,
SCE_GXM_COLOR_FORMAT_A8B8G8R8,
tex_format_to_color_format(format),
SCE_GXM_COLOR_SURFACE_LINEAR,
SCE_GXM_COLOR_SURFACE_SCALE_NONE,
SCE_GXM_OUTPUT_REGISTER_SIZE_32BIT,
w,
h,
alignedColorSurfaceStride,
texture_data
);
texture_data);
if (err < 0) {
free_gxm_texture(data, texture);
@ -1103,7 +1074,7 @@ create_gxm_texture(VITA_GXM_RenderData *data, unsigned int w, unsigned int h, Sc
// allocate it
depthBufferData = vita_mem_alloc(
SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE,
4*sampleCount,
4 * sampleCount,
SCE_GXM_DEPTHSTENCIL_SURFACE_ALIGNMENT,
SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE,
&texture->depth_UID);
@ -1148,14 +1119,12 @@ create_gxm_texture(VITA_GXM_RenderData *data, unsigned int w, unsigned int h, Sc
return NULL;
}
}
}
return texture;
}
void
gxm_texture_set_filters(gxm_texture *texture, SceGxmTextureFilter min_filter, SceGxmTextureFilter mag_filter)
void gxm_texture_set_filters(gxm_texture *texture, SceGxmTextureFilter min_filter, SceGxmTextureFilter mag_filter)
{
sceGxmTextureSetMinFilter(&texture->gxm_tex, min_filter);
sceGxmTextureSetMagFilter(&texture->gxm_tex, mag_filter);
@ -1166,7 +1135,7 @@ static unsigned int front_buffer_index_for_common_dialog = 0;
struct
{
VITA_GXM_DisplayData displayData;
SceGxmSyncObject* sync;
SceGxmSyncObject *sync;
SceGxmColorSurface surf;
SceUID uid;
} buffer_for_common_dialog[VITA_GXM_BUFFERS];
@ -1175,11 +1144,11 @@ void gxm_minimal_init_for_common_dialog(void)
{
SceGxmInitializeParams initializeParams;
SDL_zero(initializeParams);
initializeParams.flags = 0;
initializeParams.displayQueueMaxPendingCount = VITA_GXM_PENDING_SWAPS;
initializeParams.displayQueueCallback = display_callback;
initializeParams.displayQueueCallbackDataSize = sizeof(VITA_GXM_DisplayData);
initializeParams.parameterBufferSize = SCE_GXM_DEFAULT_PARAMETER_BUFFER_SIZE;
initializeParams.flags = 0;
initializeParams.displayQueueMaxPendingCount = VITA_GXM_PENDING_SWAPS;
initializeParams.displayQueueCallback = display_callback;
initializeParams.displayQueueCallbackDataSize = sizeof(VITA_GXM_DisplayData);
initializeParams.parameterBufferSize = SCE_GXM_DEFAULT_PARAMETER_BUFFER_SIZE;
sceGxmInitialize(&initializeParams);
}
@ -1190,8 +1159,7 @@ void gxm_minimal_term_for_common_dialog(void)
void gxm_init_for_common_dialog(void)
{
for (int i = 0; i < VITA_GXM_BUFFERS; i += 1)
{
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,
@ -1208,8 +1176,7 @@ void gxm_init_for_common_dialog(void)
VITA_GXM_SCREEN_WIDTH,
VITA_GXM_SCREEN_HEIGHT,
VITA_GXM_SCREEN_STRIDE,
buffer_for_common_dialog[i].displayData.address
);
buffer_for_common_dialog[i].displayData.address);
sceGxmSyncObjectCreate(&buffer_for_common_dialog[i].sync);
}
sceGxmDisplayQueueFinish();
@ -1219,10 +1186,10 @@ void gxm_swap_for_common_dialog(void)
{
SceCommonDialogUpdateParam updateParam;
SDL_zero(updateParam);
updateParam.renderTarget.colorFormat = VITA_GXM_PIXEL_FORMAT;
updateParam.renderTarget.surfaceType = SCE_GXM_COLOR_SURFACE_LINEAR;
updateParam.renderTarget.width = VITA_GXM_SCREEN_WIDTH;
updateParam.renderTarget.height = VITA_GXM_SCREEN_HEIGHT;
updateParam.renderTarget.colorFormat = VITA_GXM_PIXEL_FORMAT;
updateParam.renderTarget.surfaceType = SCE_GXM_COLOR_SURFACE_LINEAR;
updateParam.renderTarget.width = VITA_GXM_SCREEN_WIDTH;
updateParam.renderTarget.height = VITA_GXM_SCREEN_HEIGHT;
updateParam.renderTarget.strideInPixels = VITA_GXM_SCREEN_STRIDE;
updateParam.renderTarget.colorSurfaceData = buffer_for_common_dialog[back_buffer_index_for_common_dialog].displayData.address;
@ -1239,8 +1206,7 @@ void gxm_swap_for_common_dialog(void)
void gxm_term_for_common_dialog(void)
{
sceGxmDisplayQueueFinish();
for (int i = 0; i < VITA_GXM_BUFFERS; i += 1)
{
for (int i = 0; i < VITA_GXM_BUFFERS; i += 1) {
vita_mem_free(buffer_for_common_dialog[i].uid);
sceGxmSyncObjectDestroy(buffer_for_common_dialog[i].sync);
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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,8 +36,7 @@
#include "SDL_render_vita_gxm_types.h"
void
init_orthographic_matrix(float *m, float left, float right, float bottom, float top, float near, float far);
void init_orthographic_matrix(float *m, float left, float right, float bottom, float top, float near, float far);
void *pool_malloc(VITA_GXM_RenderData *data, unsigned int size);
void *pool_memalign(VITA_GXM_RenderData *data, unsigned int size, unsigned int alignment);

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -37,35 +37,38 @@
#include <string.h>
#define VITA_GXM_SCREEN_WIDTH 960
#define VITA_GXM_SCREEN_HEIGHT 544
#define VITA_GXM_SCREEN_STRIDE 960
#define VITA_GXM_SCREEN_WIDTH 960
#define VITA_GXM_SCREEN_HEIGHT 544
#define VITA_GXM_SCREEN_STRIDE 960
#define VITA_GXM_COLOR_FORMAT SCE_GXM_COLOR_FORMAT_A8B8G8R8
#define VITA_GXM_PIXEL_FORMAT SCE_DISPLAY_PIXELFORMAT_A8B8G8R8
#define VITA_GXM_COLOR_FORMAT SCE_GXM_COLOR_FORMAT_A8B8G8R8
#define VITA_GXM_PIXEL_FORMAT SCE_DISPLAY_PIXELFORMAT_A8B8G8R8
#define VITA_GXM_BUFFERS 3
#define VITA_GXM_PENDING_SWAPS 2
#define VITA_GXM_POOL_SIZE 2 * 1024 * 1024
#define VITA_GXM_BUFFERS 3
#define VITA_GXM_PENDING_SWAPS 2
#define VITA_GXM_POOL_SIZE 2 * 1024 * 1024
typedef struct
{
void *address;
Uint8 wait_vblank;
void *address;
Uint8 wait_vblank;
} VITA_GXM_DisplayData;
typedef struct clear_vertex {
typedef struct clear_vertex
{
float x;
float y;
} clear_vertex;
typedef struct color_vertex {
typedef struct color_vertex
{
float x;
float y;
SDL_Color color;
} color_vertex;
typedef struct texture_vertex {
typedef struct texture_vertex
{
float x;
float y;
float u;
@ -73,7 +76,8 @@ typedef struct texture_vertex {
SDL_Color color;
} texture_vertex;
typedef struct gxm_texture {
typedef struct gxm_texture
{
SceGxmTexture gxm_tex;
SceUID data_UID;
SceGxmRenderTarget *gxm_rendertarget;
@ -83,12 +87,14 @@ typedef struct gxm_texture {
SDL_bool cdram;
} gxm_texture;
typedef struct fragment_programs {
typedef struct fragment_programs
{
SceGxmFragmentProgram *color;
SceGxmFragmentProgram *texture;
} fragment_programs;
typedef struct blend_fragment_programs {
typedef struct blend_fragment_programs
{
fragment_programs blend_mode_none;
fragment_programs blend_mode_blend;
fragment_programs blend_mode_add;
@ -119,13 +125,13 @@ typedef struct
typedef struct
{
SDL_bool initialized;
SDL_bool drawing;
SDL_bool initialized;
SDL_bool drawing;
unsigned int psm;
unsigned int bpp;
unsigned int psm;
unsigned int bpp;
int currentBlendMode;
int currentBlendMode;
VITA_GXM_DisplayData displayData;
@ -150,12 +156,12 @@ typedef struct
unsigned int backBufferIndex;
unsigned int frontBufferIndex;
void* pool_addr[2];
void *pool_addr[2];
SceUID poolUid[2];
unsigned int pool_index;
unsigned int current_pool;
float ortho_matrix[4*4];
float ortho_matrix[4 * 4];
SceGxmVertexProgram *colorVertexProgram;
SceGxmFragmentProgram *colorFragmentProgram;
@ -194,13 +200,13 @@ typedef struct
typedef struct
{
gxm_texture *tex;
gxm_texture *tex;
unsigned int pitch;
unsigned int w;
unsigned int h;
float wscale;
SDL_bool yuv;
SDL_bool nv12;
SDL_bool yuv;
SDL_bool nv12;
} VITA_GXM_TextureData;
#endif /* SDL_RENDER_VITA_GXM_TYPES_H */