2 Simple DirectMedia Layer
3 Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
21 #include "../SDL_internal.h"
23 #ifndef SDL_sysrender_h_
24 #define SDL_sysrender_h_
26 #include "SDL_render.h"
27 #include "SDL_events.h"
28 #include "SDL_mutex.h"
29 #include "SDL_yuv_sw_c.h"
31 /* The SDL 2D rendering system */
33 typedef struct SDL_RenderDriver SDL_RenderDriver;
35 /* Define the SDL texture structure */
39 Uint32 format; /**< The pixel format of the texture */
40 int access; /**< SDL_TextureAccess */
41 int w; /**< The width of the texture */
42 int h; /**< The height of the texture */
43 int modMode; /**< The texture modulation mode */
44 SDL_BlendMode blendMode; /**< The texture blend mode */
45 SDL_ScaleMode scaleMode; /**< The texture scale mode */
46 Uint8 r, g, b, a; /**< Texture modulation values */
48 SDL_Renderer *renderer;
50 /* Support for formats not supported directly by the renderer */
52 SDL_SW_YUVTexture *yuv;
56 SDL_Surface *locked_surface; /**< Locked region exposed as a SDL surface */
58 Uint32 last_command_generation; /* last command queue generation this texture was in. */
60 void *driverdata; /**< Driver specific texture representation */
69 SDL_RENDERCMD_SETVIEWPORT,
70 SDL_RENDERCMD_SETCLIPRECT,
71 SDL_RENDERCMD_SETDRAWCOLOR,
73 SDL_RENDERCMD_DRAW_POINTS,
74 SDL_RENDERCMD_DRAW_LINES,
75 SDL_RENDERCMD_FILL_RECTS,
78 } SDL_RenderCommandType;
80 typedef struct SDL_RenderCommand
82 SDL_RenderCommandType command;
104 struct SDL_RenderCommand *next;
108 /* Define the SDL renderer structure */
113 void (*WindowEvent) (SDL_Renderer * renderer, const SDL_WindowEvent *event);
114 int (*GetOutputSize) (SDL_Renderer * renderer, int *w, int *h);
115 SDL_bool (*SupportsBlendMode)(SDL_Renderer * renderer, SDL_BlendMode blendMode);
116 int (*CreateTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
117 int (*QueueSetViewport) (SDL_Renderer * renderer, SDL_RenderCommand *cmd);
118 int (*QueueSetDrawColor) (SDL_Renderer * renderer, SDL_RenderCommand *cmd);
119 int (*QueueDrawPoints) (SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points,
121 int (*QueueDrawLines) (SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points,
123 int (*QueueFillRects) (SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects,
125 int (*QueueCopy) (SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
126 const SDL_Rect * srcrect, const SDL_FRect * dstrect);
127 int (*QueueCopyEx) (SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
128 const SDL_Rect * srcquad, const SDL_FRect * dstrect,
129 const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip);
130 int (*RunCommandQueue) (SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize);
131 int (*UpdateTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
132 const SDL_Rect * rect, const void *pixels,
134 int (*UpdateTextureYUV) (SDL_Renderer * renderer, SDL_Texture * texture,
135 const SDL_Rect * rect,
136 const Uint8 *Yplane, int Ypitch,
137 const Uint8 *Uplane, int Upitch,
138 const Uint8 *Vplane, int Vpitch);
139 int (*LockTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
140 const SDL_Rect * rect, void **pixels, int *pitch);
141 void (*UnlockTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
142 void (*SetTextureScaleMode) (SDL_Renderer * renderer, SDL_Texture * texture, SDL_ScaleMode scaleMode);
143 int (*SetRenderTarget) (SDL_Renderer * renderer, SDL_Texture * texture);
144 int (*RenderReadPixels) (SDL_Renderer * renderer, const SDL_Rect * rect,
145 Uint32 format, void * pixels, int pitch);
146 void (*RenderPresent) (SDL_Renderer * renderer);
147 void (*DestroyTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
149 void (*DestroyRenderer) (SDL_Renderer * renderer);
151 int (*GL_BindTexture) (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh);
152 int (*GL_UnbindTexture) (SDL_Renderer * renderer, SDL_Texture *texture);
154 void *(*GetMetalLayer) (SDL_Renderer * renderer);
155 void *(*GetMetalCommandEncoder) (SDL_Renderer * renderer);
157 /* The current renderer info */
158 SDL_RendererInfo info;
160 /* The window associated with the renderer */
164 /* The logical resolution for rendering */
167 int logical_w_backup;
168 int logical_h_backup;
170 /* Whether or not to force the viewport to even integer intervals */
171 SDL_bool integer_scale;
173 /* The drawable area within the window */
175 SDL_Rect viewport_backup;
177 /* The clip rectangle within the window */
179 SDL_Rect clip_rect_backup;
181 /* Wether or not the clipping rectangle is used. */
182 SDL_bool clipping_enabled;
183 SDL_bool clipping_enabled_backup;
185 /* The render output coordinate scale */
187 SDL_FPoint scale_backup;
189 /* The pixel to point coordinate scale */
190 SDL_FPoint dpi_scale;
192 /* Whether or not to scale relative mouse motion */
193 SDL_bool relative_scaling;
195 /* Remainder from scaled relative motion */
199 /* The list of textures */
200 SDL_Texture *textures;
202 SDL_mutex *target_mutex;
204 Uint8 r, g, b, a; /**< Color for drawing operations values */
205 SDL_BlendMode blendMode; /**< The drawing blend mode */
207 SDL_bool always_batch;
209 SDL_RenderCommand *render_commands;
210 SDL_RenderCommand *render_commands_tail;
211 SDL_RenderCommand *render_commands_pool;
212 Uint32 render_command_generation;
213 Uint32 last_queued_color;
214 SDL_Rect last_queued_viewport;
215 SDL_Rect last_queued_cliprect;
216 SDL_bool last_queued_cliprect_enabled;
217 SDL_bool color_queued;
218 SDL_bool viewport_queued;
219 SDL_bool cliprect_queued;
222 size_t vertex_data_used;
223 size_t vertex_data_allocation;
228 /* Define the SDL render driver structure */
229 struct SDL_RenderDriver
231 SDL_Renderer *(*CreateRenderer) (SDL_Window * window, Uint32 flags);
233 /* Info about the renderer capabilities */
234 SDL_RendererInfo info;
237 /* Not all of these are available in a given build. Use #ifdefs, etc. */
238 extern SDL_RenderDriver D3D_RenderDriver;
239 extern SDL_RenderDriver D3D11_RenderDriver;
240 extern SDL_RenderDriver GL_RenderDriver;
241 extern SDL_RenderDriver GLES2_RenderDriver;
242 extern SDL_RenderDriver GLES_RenderDriver;
243 extern SDL_RenderDriver DirectFB_RenderDriver;
244 extern SDL_RenderDriver METAL_RenderDriver;
245 extern SDL_RenderDriver PSP_RenderDriver;
246 extern SDL_RenderDriver SW_RenderDriver;
248 /* Blend mode functions */
249 extern SDL_BlendFactor SDL_GetBlendModeSrcColorFactor(SDL_BlendMode blendMode);
250 extern SDL_BlendFactor SDL_GetBlendModeDstColorFactor(SDL_BlendMode blendMode);
251 extern SDL_BlendOperation SDL_GetBlendModeColorOperation(SDL_BlendMode blendMode);
252 extern SDL_BlendFactor SDL_GetBlendModeSrcAlphaFactor(SDL_BlendMode blendMode);
253 extern SDL_BlendFactor SDL_GetBlendModeDstAlphaFactor(SDL_BlendMode blendMode);
254 extern SDL_BlendOperation SDL_GetBlendModeAlphaOperation(SDL_BlendMode blendMode);
256 /* drivers call this during their Queue*() methods to make space in a array that are used
257 for a vertex buffer during RunCommandQueue(). Pointers returned here are only valid until
258 the next call, because it might be in an array that gets realloc()'d. */
259 extern void *SDL_AllocateRenderVertices(SDL_Renderer *renderer, const size_t numbytes, const size_t alignment, size_t *offset);
261 #endif /* SDL_sysrender_h_ */
263 /* vi: set ts=4 sw=4 expandtab: */