2015-06-21 10:33:46 -05:00
|
|
|
/*
|
|
|
|
Simple DirectMedia Layer
|
2023-01-09 11:41:41 -06:00
|
|
|
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
2015-06-21 10:33:46 -05:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2022-11-29 20:34:15 -06:00
|
|
|
#include "SDL_internal.h"
|
2015-06-21 10:33:46 -05:00
|
|
|
|
2016-11-20 23:34:54 -06:00
|
|
|
#ifndef SDL_sysrender_h_
|
|
|
|
#define SDL_sysrender_h_
|
2015-06-21 10:33:46 -05:00
|
|
|
|
|
|
|
#include "SDL_yuv_sw_c.h"
|
|
|
|
|
2022-06-26 13:47:34 -05:00
|
|
|
/* Set up for C function definitions, even when using C++ */
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2022-04-18 14:09:48 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A rectangle, with the origin at the upper left (double precision).
|
|
|
|
*/
|
|
|
|
typedef struct SDL_DRect
|
|
|
|
{
|
|
|
|
double x;
|
|
|
|
double y;
|
|
|
|
double w;
|
|
|
|
double h;
|
|
|
|
} SDL_DRect;
|
|
|
|
|
2015-06-21 10:33:46 -05:00
|
|
|
/* The SDL 2D rendering system */
|
|
|
|
|
|
|
|
typedef struct SDL_RenderDriver SDL_RenderDriver;
|
|
|
|
|
2023-02-03 14:25:46 -06:00
|
|
|
/* Rendering view state */
|
|
|
|
typedef struct SDL_RenderViewState
|
|
|
|
{
|
|
|
|
int pixel_w;
|
|
|
|
int pixel_h;
|
|
|
|
SDL_Rect viewport;
|
|
|
|
SDL_Rect clip_rect;
|
|
|
|
SDL_bool clipping_enabled;
|
|
|
|
SDL_FPoint scale;
|
|
|
|
|
|
|
|
} SDL_RenderViewState;
|
|
|
|
|
2015-06-21 10:33:46 -05:00
|
|
|
/* Define the SDL texture structure */
|
|
|
|
struct SDL_Texture
|
|
|
|
{
|
|
|
|
const void *magic;
|
2023-02-03 14:25:46 -06:00
|
|
|
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_RenderViewState view; /**< Target texture view state */
|
2015-06-21 10:33:46 -05:00
|
|
|
|
|
|
|
SDL_Renderer *renderer;
|
|
|
|
|
|
|
|
/* Support for formats not supported directly by the renderer */
|
|
|
|
SDL_Texture *native;
|
|
|
|
SDL_SW_YUVTexture *yuv;
|
|
|
|
void *pixels;
|
|
|
|
int pitch;
|
|
|
|
SDL_Rect locked_rect;
|
2022-11-30 14:51:59 -06:00
|
|
|
SDL_Surface *locked_surface; /**< Locked region exposed as a SDL surface */
|
2015-06-21 10:33:46 -05:00
|
|
|
|
2018-09-20 14:46:02 -05:00
|
|
|
Uint32 last_command_generation; /* last command queue generation this texture was in. */
|
|
|
|
|
2022-11-30 14:51:59 -06:00
|
|
|
void *driverdata; /**< Driver specific texture representation */
|
2021-08-10 17:17:59 -05:00
|
|
|
void *userdata;
|
2015-06-21 10:33:46 -05:00
|
|
|
|
|
|
|
SDL_Texture *prev;
|
|
|
|
SDL_Texture *next;
|
|
|
|
};
|
|
|
|
|
2018-09-20 14:46:02 -05:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
SDL_RENDERCMD_NO_OP,
|
|
|
|
SDL_RENDERCMD_SETVIEWPORT,
|
|
|
|
SDL_RENDERCMD_SETCLIPRECT,
|
2018-09-23 22:20:40 -05:00
|
|
|
SDL_RENDERCMD_SETDRAWCOLOR,
|
2018-09-20 14:46:02 -05:00
|
|
|
SDL_RENDERCMD_CLEAR,
|
|
|
|
SDL_RENDERCMD_DRAW_POINTS,
|
|
|
|
SDL_RENDERCMD_DRAW_LINES,
|
|
|
|
SDL_RENDERCMD_FILL_RECTS,
|
|
|
|
SDL_RENDERCMD_COPY,
|
2021-03-16 09:09:34 -05:00
|
|
|
SDL_RENDERCMD_COPY_EX,
|
|
|
|
SDL_RENDERCMD_GEOMETRY
|
2018-09-20 14:46:02 -05:00
|
|
|
} SDL_RenderCommandType;
|
|
|
|
|
|
|
|
typedef struct SDL_RenderCommand
|
|
|
|
{
|
|
|
|
SDL_RenderCommandType command;
|
2022-11-30 14:51:59 -06:00
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
2018-09-23 22:20:40 -05:00
|
|
|
size_t first;
|
|
|
|
SDL_Rect rect;
|
|
|
|
} viewport;
|
2022-11-30 14:51:59 -06:00
|
|
|
struct
|
|
|
|
{
|
2018-09-20 14:46:02 -05:00
|
|
|
SDL_bool enabled;
|
|
|
|
SDL_Rect rect;
|
|
|
|
} cliprect;
|
2022-11-30 14:51:59 -06:00
|
|
|
struct
|
|
|
|
{
|
2018-09-20 14:46:02 -05:00
|
|
|
size_t first;
|
|
|
|
size_t count;
|
|
|
|
Uint8 r, g, b, a;
|
|
|
|
SDL_BlendMode blend;
|
|
|
|
SDL_Texture *texture;
|
|
|
|
} draw;
|
2022-11-30 14:51:59 -06:00
|
|
|
struct
|
|
|
|
{
|
2018-09-23 22:20:40 -05:00
|
|
|
size_t first;
|
2018-09-20 14:46:02 -05:00
|
|
|
Uint8 r, g, b, a;
|
|
|
|
} color;
|
|
|
|
} data;
|
|
|
|
struct SDL_RenderCommand *next;
|
|
|
|
} SDL_RenderCommand;
|
|
|
|
|
2021-12-16 03:52:36 -06:00
|
|
|
typedef struct SDL_VertexSolid
|
|
|
|
{
|
|
|
|
SDL_FPoint position;
|
2022-11-30 14:51:59 -06:00
|
|
|
SDL_Color color;
|
2021-12-16 03:52:36 -06:00
|
|
|
} SDL_VertexSolid;
|
|
|
|
|
2022-01-08 13:36:29 -06:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
SDL_RENDERLINEMETHOD_POINTS,
|
|
|
|
SDL_RENDERLINEMETHOD_LINES,
|
|
|
|
SDL_RENDERLINEMETHOD_GEOMETRY,
|
|
|
|
} SDL_RenderLineMethod;
|
|
|
|
|
2015-06-21 10:33:46 -05:00
|
|
|
/* Define the SDL renderer structure */
|
|
|
|
struct SDL_Renderer
|
|
|
|
{
|
|
|
|
const void *magic;
|
|
|
|
|
2022-11-30 14:51:59 -06:00
|
|
|
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);
|
2021-01-05 10:39:48 -06:00
|
|
|
#if SDL_HAVE_YUV
|
2022-11-30 14:51:59 -06:00
|
|
|
int (*UpdateTextureYUV)(SDL_Renderer *renderer, SDL_Texture *texture,
|
|
|
|
const SDL_Rect *rect,
|
2015-06-21 10:33:46 -05:00
|
|
|
const Uint8 *Yplane, int Ypitch,
|
|
|
|
const Uint8 *Uplane, int Upitch,
|
|
|
|
const Uint8 *Vplane, int Vpitch);
|
2022-11-30 14:51:59 -06:00
|
|
|
int (*UpdateTextureNV)(SDL_Renderer *renderer, SDL_Texture *texture,
|
|
|
|
const SDL_Rect *rect,
|
|
|
|
const Uint8 *Yplane, int Ypitch,
|
|
|
|
const Uint8 *UVplane, int UVpitch);
|
2021-01-05 10:39:48 -06:00
|
|
|
#endif
|
2022-11-30 14:51:59 -06:00
|
|
|
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);
|
2015-06-21 10:33:46 -05:00
|
|
|
|
2022-11-30 14:51:59 -06:00
|
|
|
void (*DestroyRenderer)(SDL_Renderer *renderer);
|
2015-06-21 10:33:46 -05:00
|
|
|
|
2022-11-30 14:51:59 -06:00
|
|
|
int (*SetVSync)(SDL_Renderer *renderer, int vsync);
|
2021-03-07 17:20:45 -06:00
|
|
|
|
2022-11-30 14:51:59 -06:00
|
|
|
int (*GL_BindTexture)(SDL_Renderer *renderer, SDL_Texture *texture, float *texw, float *texh);
|
|
|
|
int (*GL_UnbindTexture)(SDL_Renderer *renderer, SDL_Texture *texture);
|
2015-06-21 10:33:46 -05:00
|
|
|
|
2022-11-30 14:51:59 -06:00
|
|
|
void *(*GetMetalLayer)(SDL_Renderer *renderer);
|
|
|
|
void *(*GetMetalCommandEncoder)(SDL_Renderer *renderer);
|
2017-12-08 16:30:10 -06:00
|
|
|
|
2015-06-21 10:33:46 -05:00
|
|
|
/* The current renderer info */
|
|
|
|
SDL_RendererInfo info;
|
|
|
|
|
|
|
|
/* The window associated with the renderer */
|
|
|
|
SDL_Window *window;
|
|
|
|
SDL_bool hidden;
|
|
|
|
|
2022-09-15 03:00:12 -05:00
|
|
|
/* Whether we should simulate vsync */
|
|
|
|
SDL_bool wanted_vsync;
|
|
|
|
SDL_bool simulate_vsync;
|
2022-12-02 03:17:17 -06:00
|
|
|
Uint64 simulate_vsync_interval_ns;
|
|
|
|
Uint64 last_present;
|
2022-09-15 03:00:12 -05:00
|
|
|
|
2023-02-03 14:25:46 -06:00
|
|
|
/* Support for logical output coordinates */
|
|
|
|
SDL_Texture *logical_target;
|
|
|
|
SDL_RendererLogicalPresentation logical_presentation_mode;
|
|
|
|
SDL_ScaleMode logical_scale_mode;
|
|
|
|
SDL_Rect logical_src_rect;
|
|
|
|
SDL_FRect logical_dst_rect;
|
2016-01-05 15:39:18 -06:00
|
|
|
|
2023-02-03 14:25:46 -06:00
|
|
|
SDL_RenderViewState *view;
|
|
|
|
SDL_RenderViewState main_view;
|
2015-06-21 10:33:46 -05:00
|
|
|
|
2023-02-03 14:25:46 -06:00
|
|
|
/* The window pixel to point coordinate scale */
|
2017-08-02 15:38:46 -05:00
|
|
|
SDL_FPoint dpi_scale;
|
|
|
|
|
2022-01-08 13:36:29 -06:00
|
|
|
/* The method of drawing lines */
|
|
|
|
SDL_RenderLineMethod line_method;
|
2022-10-18 03:34:56 -05:00
|
|
|
|
|
|
|
/* List of triangle indices to draw rects */
|
2022-10-18 10:40:03 -05:00
|
|
|
int rect_index_order[6];
|
2022-01-08 13:36:29 -06:00
|
|
|
|
2015-06-21 10:33:46 -05:00
|
|
|
/* The list of textures */
|
|
|
|
SDL_Texture *textures;
|
|
|
|
SDL_Texture *target;
|
2018-06-18 15:13:56 -05:00
|
|
|
SDL_mutex *target_mutex;
|
2015-06-21 10:33:46 -05:00
|
|
|
|
2022-11-30 14:51:59 -06:00
|
|
|
SDL_Color color; /**< Color for drawing operations values */
|
|
|
|
SDL_BlendMode blendMode; /**< The drawing blend mode */
|
2015-06-21 10:33:46 -05:00
|
|
|
|
2018-09-23 22:20:40 -05:00
|
|
|
SDL_bool always_batch;
|
2018-09-20 14:46:02 -05:00
|
|
|
SDL_bool batching;
|
|
|
|
SDL_RenderCommand *render_commands;
|
|
|
|
SDL_RenderCommand *render_commands_tail;
|
|
|
|
SDL_RenderCommand *render_commands_pool;
|
|
|
|
Uint32 render_command_generation;
|
2018-09-23 22:20:40 -05:00
|
|
|
Uint32 last_queued_color;
|
2023-02-03 14:25:46 -06:00
|
|
|
SDL_Rect last_queued_viewport;
|
|
|
|
SDL_Rect last_queued_cliprect;
|
2018-09-23 22:20:40 -05:00
|
|
|
SDL_bool last_queued_cliprect_enabled;
|
|
|
|
SDL_bool color_queued;
|
|
|
|
SDL_bool viewport_queued;
|
|
|
|
SDL_bool cliprect_queued;
|
2018-09-20 14:46:02 -05:00
|
|
|
|
|
|
|
void *vertex_data;
|
|
|
|
size_t vertex_data_used;
|
|
|
|
size_t vertex_data_allocation;
|
|
|
|
|
2015-06-21 10:33:46 -05:00
|
|
|
void *driverdata;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Define the SDL render driver structure */
|
|
|
|
struct SDL_RenderDriver
|
|
|
|
{
|
2022-11-30 14:51:59 -06:00
|
|
|
SDL_Renderer *(*CreateRenderer)(SDL_Window *window, Uint32 flags);
|
2015-06-21 10:33:46 -05:00
|
|
|
|
|
|
|
/* Info about the renderer capabilities */
|
|
|
|
SDL_RendererInfo info;
|
|
|
|
};
|
|
|
|
|
2017-02-25 23:40:04 -06:00
|
|
|
/* Not all of these are available in a given build. Use #ifdefs, etc. */
|
2015-06-21 10:33:46 -05:00
|
|
|
extern SDL_RenderDriver D3D_RenderDriver;
|
|
|
|
extern SDL_RenderDriver D3D11_RenderDriver;
|
2022-06-06 19:42:30 -05:00
|
|
|
extern SDL_RenderDriver D3D12_RenderDriver;
|
2015-06-21 10:33:46 -05:00
|
|
|
extern SDL_RenderDriver GL_RenderDriver;
|
|
|
|
extern SDL_RenderDriver GLES2_RenderDriver;
|
2016-04-21 02:16:44 -05:00
|
|
|
extern SDL_RenderDriver METAL_RenderDriver;
|
2022-06-30 09:44:35 -05:00
|
|
|
extern SDL_RenderDriver PS2_RenderDriver;
|
2015-06-21 10:33:46 -05:00
|
|
|
extern SDL_RenderDriver PSP_RenderDriver;
|
|
|
|
extern SDL_RenderDriver SW_RenderDriver;
|
2020-11-16 11:40:22 -06:00
|
|
|
extern SDL_RenderDriver VITA_GXM_RenderDriver;
|
2015-06-21 10:33:46 -05:00
|
|
|
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 07:51:44 -05:00
|
|
|
/* Blend mode functions */
|
|
|
|
extern SDL_BlendFactor SDL_GetBlendModeSrcColorFactor(SDL_BlendMode blendMode);
|
|
|
|
extern SDL_BlendFactor SDL_GetBlendModeDstColorFactor(SDL_BlendMode blendMode);
|
|
|
|
extern SDL_BlendOperation SDL_GetBlendModeColorOperation(SDL_BlendMode blendMode);
|
|
|
|
extern SDL_BlendFactor SDL_GetBlendModeSrcAlphaFactor(SDL_BlendMode blendMode);
|
|
|
|
extern SDL_BlendFactor SDL_GetBlendModeDstAlphaFactor(SDL_BlendMode blendMode);
|
|
|
|
extern SDL_BlendOperation SDL_GetBlendModeAlphaOperation(SDL_BlendMode blendMode);
|
|
|
|
|
2018-09-20 14:46:02 -05:00
|
|
|
/* drivers call this during their Queue*() methods to make space in a array that are used
|
|
|
|
for a vertex buffer during RunCommandQueue(). Pointers returned here are only valid until
|
|
|
|
the next call, because it might be in an array that gets realloc()'d. */
|
2018-09-23 22:20:40 -05:00
|
|
|
extern void *SDL_AllocateRenderVertices(SDL_Renderer *renderer, const size_t numbytes, const size_t alignment, size_t *offset);
|
2018-09-20 14:46:02 -05:00
|
|
|
|
2022-12-27 17:05:51 -06:00
|
|
|
extern int SDL_PrivateBlitSurfaceUncheckedScaled(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
|
|
|
|
extern int SDL_PrivateBlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
|
2020-12-27 13:28:24 -06:00
|
|
|
|
2022-06-26 13:47:34 -05:00
|
|
|
/* Ends C function definitions when using C++ */
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-11-20 23:34:54 -06:00
|
|
|
#endif /* SDL_sysrender_h_ */
|