SDL  2.0
SDL_render.c File Reference
#include "../SDL_internal.h"
#include "SDL_assert.h"
#include "SDL_hints.h"
#include "SDL_log.h"
#include "SDL_render.h"
#include "SDL_sysrender.h"
#include "software/SDL_render_sw_c.h"
+ Include dependency graph for SDL_render.c:

Go to the source code of this file.

Macros

#define SDL_WINDOWRENDERDATA   "_SDL_WindowRenderData"
 
#define CHECK_RENDERER_MAGIC(renderer, retval)
 
#define CHECK_TEXTURE_MAGIC(texture, retval)
 

Functions

static int UpdateLogicalSize (SDL_Renderer *renderer)
 
int SDL_GetNumRenderDrivers (void)
 Get the number of 2D rendering drivers available for the current display. More...
 
int SDL_GetRenderDriverInfo (int index, SDL_RendererInfo *info)
 Get information about a specific 2D rendering driver for the current display. More...
 
static int SDL_RendererEventWatch (void *userdata, SDL_Event *event)
 
int SDL_CreateWindowAndRenderer (int width, int height, Uint32 window_flags, SDL_Window **window, SDL_Renderer **renderer)
 Create a window and default renderer. More...
 
SDL_RendererSDL_CreateRenderer (SDL_Window *window, int index, Uint32 flags)
 Create a 2D rendering context for a window. More...
 
SDL_RendererSDL_CreateSoftwareRenderer (SDL_Surface *surface)
 Create a 2D software rendering context for a surface. More...
 
SDL_RendererSDL_GetRenderer (SDL_Window *window)
 Get the renderer associated with a window. More...
 
int SDL_GetRendererInfo (SDL_Renderer *renderer, SDL_RendererInfo *info)
 Get information about a rendering context. More...
 
int SDL_GetRendererOutputSize (SDL_Renderer *renderer, int *w, int *h)
 Get the output size in pixels of a rendering context. More...
 
static SDL_bool IsSupportedFormat (SDL_Renderer *renderer, Uint32 format)
 
static Uint32 GetClosestSupportedFormat (SDL_Renderer *renderer, Uint32 format)
 
SDL_TextureSDL_CreateTexture (SDL_Renderer *renderer, Uint32 format, int access, int w, int h)
 Create a texture for a rendering context. More...
 
SDL_TextureSDL_CreateTextureFromSurface (SDL_Renderer *renderer, SDL_Surface *surface)
 Create a texture from an existing surface. More...
 
int SDL_QueryTexture (SDL_Texture *texture, Uint32 *format, int *access, int *w, int *h)
 Query the attributes of a texture. More...
 
int SDL_SetTextureColorMod (SDL_Texture *texture, Uint8 r, Uint8 g, Uint8 b)
 Set an additional color value used in render copy operations. More...
 
int SDL_GetTextureColorMod (SDL_Texture *texture, Uint8 *r, Uint8 *g, Uint8 *b)
 Get the additional color value used in render copy operations. More...
 
int SDL_SetTextureAlphaMod (SDL_Texture *texture, Uint8 alpha)
 Set an additional alpha value used in render copy operations. More...
 
int SDL_GetTextureAlphaMod (SDL_Texture *texture, Uint8 *alpha)
 Get the additional alpha value used in render copy operations. More...
 
int SDL_SetTextureBlendMode (SDL_Texture *texture, SDL_BlendMode blendMode)
 Set the blend mode used for texture copy operations. More...
 
int SDL_GetTextureBlendMode (SDL_Texture *texture, SDL_BlendMode *blendMode)
 Get the blend mode used for texture copy operations. More...
 
static int SDL_UpdateTextureYUV (SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
 
static int SDL_UpdateTextureNative (SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
 
int SDL_UpdateTexture (SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
 Update the given texture rectangle with new pixel data. More...
 
static int SDL_UpdateTextureYUVPlanar (SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *Uplane, int Upitch, const Uint8 *Vplane, int Vpitch)
 
int SDL_UpdateYUVTexture (SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *Uplane, int Upitch, const Uint8 *Vplane, int Vpitch)
 Update a rectangle within a planar YV12 or IYUV texture with new pixel data. More...
 
static int SDL_LockTextureYUV (SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
 
static int SDL_LockTextureNative (SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
 
int SDL_LockTexture (SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
 Lock a portion of the texture for write-only pixel access. More...
 
static void SDL_UnlockTextureYUV (SDL_Texture *texture)
 
static void SDL_UnlockTextureNative (SDL_Texture *texture)
 
void SDL_UnlockTexture (SDL_Texture *texture)
 Unlock a texture, uploading the changes to video memory, if needed. More...
 
SDL_bool SDL_RenderTargetSupported (SDL_Renderer *renderer)
 Determines whether a window supports the use of render targets. More...
 
int SDL_SetRenderTarget (SDL_Renderer *renderer, SDL_Texture *texture)
 Set a texture as the current rendering target. More...
 
SDL_TextureSDL_GetRenderTarget (SDL_Renderer *renderer)
 Get the current render target or NULL for the default render target. More...
 
int SDL_RenderSetLogicalSize (SDL_Renderer *renderer, int w, int h)
 Set device independent resolution for rendering. More...
 
void SDL_RenderGetLogicalSize (SDL_Renderer *renderer, int *w, int *h)
 Get device independent resolution for rendering. More...
 
int SDL_RenderSetIntegerScale (SDL_Renderer *renderer, SDL_bool enable)
 Set whether to force integer scales for resolution-independent rendering. More...
 
SDL_bool SDL_RenderGetIntegerScale (SDL_Renderer *renderer)
 Get whether integer scales are forced for resolution-independent rendering. More...
 
int SDL_RenderSetViewport (SDL_Renderer *renderer, const SDL_Rect *rect)
 Set the drawing area for rendering on the current target. More...
 
void SDL_RenderGetViewport (SDL_Renderer *renderer, SDL_Rect *rect)
 Get the drawing area for the current target. More...
 
int SDL_RenderSetClipRect (SDL_Renderer *renderer, const SDL_Rect *rect)
 Set the clip rectangle for the current target. More...
 
void SDL_RenderGetClipRect (SDL_Renderer *renderer, SDL_Rect *rect)
 Get the clip rectangle for the current target. More...
 
SDL_bool SDL_RenderIsClipEnabled (SDL_Renderer *renderer)
 Get whether clipping is enabled on the given renderer. More...
 
int SDL_RenderSetScale (SDL_Renderer *renderer, float scaleX, float scaleY)
 Set the drawing scale for rendering on the current target. More...
 
void SDL_RenderGetScale (SDL_Renderer *renderer, float *scaleX, float *scaleY)
 Get the drawing scale for the current target. More...
 
int SDL_SetRenderDrawColor (SDL_Renderer *renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
 Set the color used for drawing operations (Rect, Line and Clear). More...
 
int SDL_GetRenderDrawColor (SDL_Renderer *renderer, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
 Get the color used for drawing operations (Rect, Line and Clear). More...
 
int SDL_SetRenderDrawBlendMode (SDL_Renderer *renderer, SDL_BlendMode blendMode)
 Set the blend mode used for drawing operations (Fill and Line). More...
 
int SDL_GetRenderDrawBlendMode (SDL_Renderer *renderer, SDL_BlendMode *blendMode)
 Get the blend mode used for drawing operations. More...
 
int SDL_RenderClear (SDL_Renderer *renderer)
 Clear the current rendering target with the drawing color. More...
 
int SDL_RenderDrawPoint (SDL_Renderer *renderer, int x, int y)
 Draw a point on the current rendering target. More...
 
static int RenderDrawPointsWithRects (SDL_Renderer *renderer, const SDL_Point *points, int count)
 
int SDL_RenderDrawPoints (SDL_Renderer *renderer, const SDL_Point *points, int count)
 Draw multiple points on the current rendering target. More...
 
int SDL_RenderDrawLine (SDL_Renderer *renderer, int x1, int y1, int x2, int y2)
 Draw a line on the current rendering target. More...
 
static int RenderDrawLinesWithRects (SDL_Renderer *renderer, const SDL_Point *points, int count)
 
int SDL_RenderDrawLines (SDL_Renderer *renderer, const SDL_Point *points, int count)
 Draw a series of connected lines on the current rendering target. More...
 
int SDL_RenderDrawRect (SDL_Renderer *renderer, const SDL_Rect *rect)
 Draw a rectangle on the current rendering target. More...
 
int SDL_RenderDrawRects (SDL_Renderer *renderer, const SDL_Rect *rects, int count)
 Draw some number of rectangles on the current rendering target. More...
 
int SDL_RenderFillRect (SDL_Renderer *renderer, const SDL_Rect *rect)
 Fill a rectangle on the current rendering target with the drawing color. More...
 
int SDL_RenderFillRects (SDL_Renderer *renderer, const SDL_Rect *rects, int count)
 Fill some number of rectangles on the current rendering target with the drawing color. More...
 
int SDL_RenderCopy (SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect)
 Copy a portion of the texture to the current rendering target. More...
 
int SDL_RenderCopyEx (SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect, const double angle, const SDL_Point *center, const SDL_RendererFlip flip)
 Copy a portion of the source texture to the current rendering target, rotating it by angle around the given center. More...
 
int SDL_RenderReadPixels (SDL_Renderer *renderer, const SDL_Rect *rect, Uint32 format, void *pixels, int pitch)
 Read pixels from the current rendering target. More...
 
void SDL_RenderPresent (SDL_Renderer *renderer)
 Update the screen with rendering performed. More...
 
void SDL_DestroyTexture (SDL_Texture *texture)
 Destroy the specified texture. More...
 
void SDL_DestroyRenderer (SDL_Renderer *renderer)
 Destroy the rendering context for a window and free associated textures. More...
 
int SDL_GL_BindTexture (SDL_Texture *texture, float *texw, float *texh)
 Bind the texture to the current OpenGL/ES/ES2 context for use with OpenGL instructions. More...
 
int SDL_GL_UnbindTexture (SDL_Texture *texture)
 Unbind a texture from the current OpenGL/ES/ES2 context. More...
 

Variables

static const SDL_RenderDriverrender_drivers []
 
static char renderer_magic
 
static char texture_magic
 

Macro Definition Documentation

◆ CHECK_RENDERER_MAGIC

◆ CHECK_TEXTURE_MAGIC

◆ SDL_WINDOWRENDERDATA

#define SDL_WINDOWRENDERDATA   "_SDL_WindowRenderData"

Definition at line 33 of file SDL_render.c.

Referenced by SDL_CreateRenderer(), SDL_DestroyRenderer(), and SDL_GetRenderer().

Function Documentation

◆ GetClosestSupportedFormat()

static Uint32 GetClosestSupportedFormat ( SDL_Renderer renderer,
Uint32  format 
)
static

Definition at line 384 of file SDL_render.c.

References i, SDL_Renderer::info, SDL_RendererInfo::num_texture_formats, SDL_ISPIXELFORMAT_ALPHA, SDL_ISPIXELFORMAT_FOURCC, and SDL_RendererInfo::texture_formats.

Referenced by SDL_CreateTexture().

385 {
386  Uint32 i;
387 
389  /* Look for an exact match */
390  for (i = 0; i < renderer->info.num_texture_formats; ++i) {
391  if (renderer->info.texture_formats[i] == format) {
392  return renderer->info.texture_formats[i];
393  }
394  }
395  } else {
397 
398  /* We just want to match the first format that has the same channels */
399  for (i = 0; i < renderer->info.num_texture_formats; ++i) {
400  if (!SDL_ISPIXELFORMAT_FOURCC(renderer->info.texture_formats[i]) &&
401  SDL_ISPIXELFORMAT_ALPHA(renderer->info.texture_formats[i]) == hasAlpha) {
402  return renderer->info.texture_formats[i];
403  }
404  }
405  }
406  return renderer->info.texture_formats[0];
407 }
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1565
SDL_RendererInfo info
Uint32 texture_formats[16]
Definition: SDL_render.h:83
#define SDL_ISPIXELFORMAT_ALPHA(format)
Definition: SDL_pixels.h:154
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:161
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
SDL_bool
Definition: SDL_stdinc.h:130
Uint32 num_texture_formats
Definition: SDL_render.h:82
#define SDL_ISPIXELFORMAT_FOURCC(format)
Definition: SDL_pixels.h:167

◆ IsSupportedFormat()

static SDL_bool IsSupportedFormat ( SDL_Renderer renderer,
Uint32  format 
)
static

Definition at line 371 of file SDL_render.c.

References i, SDL_Renderer::info, SDL_RendererInfo::num_texture_formats, SDL_FALSE, SDL_TRUE, and SDL_RendererInfo::texture_formats.

Referenced by SDL_CreateTexture().

372 {
373  Uint32 i;
374 
375  for (i = 0; i < renderer->info.num_texture_formats; ++i) {
376  if (renderer->info.texture_formats[i] == format) {
377  return SDL_TRUE;
378  }
379  }
380  return SDL_FALSE;
381 }
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1565
SDL_RendererInfo info
Uint32 texture_formats[16]
Definition: SDL_render.h:83
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:161
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
Uint32 num_texture_formats
Definition: SDL_render.h:82

◆ RenderDrawLinesWithRects()

static int RenderDrawLinesWithRects ( SDL_Renderer renderer,
const SDL_Point points,
int  count 
)
static

Definition at line 1501 of file SDL_render.c.

References SDL_FRect::h, i, SDL_Renderer::RenderDrawLines, SDL_Renderer::RenderFillRects, SDL_Renderer::scale, SDL_max, SDL_min, SDL_OutOfMemory, SDL_stack_alloc, SDL_stack_free, SDL_FRect::w, SDL_FPoint::x, SDL_FRect::x, SDL_Point::x, SDL_FPoint::y, SDL_FRect::y, and SDL_Point::y.

Referenced by SDL_RenderDrawLines().

1503 {
1504  SDL_FRect *frect;
1505  SDL_FRect *frects;
1506  SDL_FPoint fpoints[2];
1507  int i, nrects;
1508  int status;
1509 
1510  frects = SDL_stack_alloc(SDL_FRect, count-1);
1511  if (!frects) {
1512  return SDL_OutOfMemory();
1513  }
1514 
1515  status = 0;
1516  nrects = 0;
1517  for (i = 0; i < count-1; ++i) {
1518  if (points[i].x == points[i+1].x) {
1519  int minY = SDL_min(points[i].y, points[i+1].y);
1520  int maxY = SDL_max(points[i].y, points[i+1].y);
1521 
1522  frect = &frects[nrects++];
1523  frect->x = points[i].x * renderer->scale.x;
1524  frect->y = minY * renderer->scale.y;
1525  frect->w = renderer->scale.x;
1526  frect->h = (maxY - minY + 1) * renderer->scale.y;
1527  } else if (points[i].y == points[i+1].y) {
1528  int minX = SDL_min(points[i].x, points[i+1].x);
1529  int maxX = SDL_max(points[i].x, points[i+1].x);
1530 
1531  frect = &frects[nrects++];
1532  frect->x = minX * renderer->scale.x;
1533  frect->y = points[i].y * renderer->scale.y;
1534  frect->w = (maxX - minX + 1) * renderer->scale.x;
1535  frect->h = renderer->scale.y;
1536  } else {
1537  /* FIXME: We can't use a rect for this line... */
1538  fpoints[0].x = points[i].x * renderer->scale.x;
1539  fpoints[0].y = points[i].y * renderer->scale.y;
1540  fpoints[1].x = points[i+1].x * renderer->scale.x;
1541  fpoints[1].y = points[i+1].y * renderer->scale.y;
1542  status += renderer->RenderDrawLines(renderer, fpoints, 2);
1543  }
1544  }
1545 
1546  status += renderer->RenderFillRects(renderer, frects, nrects);
1547 
1548  SDL_stack_free(frects);
1549 
1550  if (status < 0) {
1551  status = -1;
1552  }
1553  return status;
1554 }
int(* RenderDrawLines)(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
#define SDL_min(x, y)
Definition: SDL_stdinc.h:351
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1567
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1564
SDL_FPoint scale
int(* RenderFillRects)(SDL_Renderer *renderer, const SDL_FRect *rects, int count)
#define SDL_max(x, y)
Definition: SDL_stdinc.h:352
int x
Definition: SDL_rect.h:50
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1567
int y
Definition: SDL_rect.h:51
#define SDL_stack_alloc(type, count)
Definition: SDL_stdinc.h:330
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
#define SDL_stack_free(data)
Definition: SDL_stdinc.h:331

◆ RenderDrawPointsWithRects()

static int RenderDrawPointsWithRects ( SDL_Renderer renderer,
const SDL_Point points,
int  count 
)
static

Definition at line 1421 of file SDL_render.c.

References SDL_FRect::h, i, SDL_Renderer::RenderFillRects, SDL_Renderer::scale, SDL_OutOfMemory, SDL_stack_alloc, SDL_stack_free, SDL_FRect::w, SDL_FPoint::x, SDL_FRect::x, SDL_Point::x, SDL_FPoint::y, SDL_FRect::y, and SDL_Point::y.

Referenced by SDL_RenderDrawPoints().

1423 {
1424  SDL_FRect *frects;
1425  int i;
1426  int status;
1427 
1428  frects = SDL_stack_alloc(SDL_FRect, count);
1429  if (!frects) {
1430  return SDL_OutOfMemory();
1431  }
1432  for (i = 0; i < count; ++i) {
1433  frects[i].x = points[i].x * renderer->scale.x;
1434  frects[i].y = points[i].y * renderer->scale.y;
1435  frects[i].w = renderer->scale.x;
1436  frects[i].h = renderer->scale.y;
1437  }
1438 
1439  status = renderer->RenderFillRects(renderer, frects, count);
1440 
1441  SDL_stack_free(frects);
1442 
1443  return status;
1444 }
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1564
SDL_FPoint scale
int(* RenderFillRects)(SDL_Renderer *renderer, const SDL_FRect *rects, int count)
int x
Definition: SDL_rect.h:50
int y
Definition: SDL_rect.h:51
#define SDL_stack_alloc(type, count)
Definition: SDL_stdinc.h:330
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
#define SDL_stack_free(data)
Definition: SDL_stdinc.h:331

◆ SDL_CreateRenderer()

SDL_Renderer* SDL_CreateRenderer ( SDL_Window window,
int  index,
Uint32  flags 
)

Create a 2D rendering context for a window.

Parameters
windowThe window where rendering is displayed.
indexThe index of the rendering driver to initialize, or -1 to initialize the first one supporting the requested flags.
flagsSDL_RendererFlags.
Returns
A valid rendering context or NULL if there was an error.
See also
SDL_CreateSoftwareRenderer()
SDL_GetRendererInfo()
SDL_DestroyRenderer()

Definition at line 220 of file SDL_render.c.

References SDL_RenderDriver::CreateRenderer, SDL_RendererInfo::flags, SDL_Renderer::hidden, SDL_Renderer::info, SDL_RenderDriver::info, SDL_Renderer::magic, SDL_RendererInfo::name, NULL, renderer, renderer_magic, SDL_Renderer::scale, SDL_AddEventWatch, SDL_FALSE, SDL_GetHint, SDL_GetHintBoolean, SDL_GetNumRenderDrivers(), SDL_GetRenderer(), SDL_GetWindowFlags, SDL_HINT_RENDER_DRIVER, SDL_HINT_RENDER_VSYNC, SDL_LOG_CATEGORY_RENDER, SDL_LogInfo, SDL_RENDERER_PRESENTVSYNC, SDL_RendererEventWatch(), SDL_RenderSetViewport(), SDL_SetError, SDL_SetWindowData, SDL_strcasecmp, SDL_TRUE, SDL_WINDOW_HIDDEN, SDL_WINDOW_MINIMIZED, SDL_WINDOWRENDERDATA, window, SDL_Renderer::window, SDL_FPoint::x, and SDL_FPoint::y.

Referenced by SDL_CreateWindowAndRenderer().

221 {
222 #if !SDL_RENDER_DISABLED
224  int n = SDL_GetNumRenderDrivers();
225  const char *hint;
226 
227  if (!window) {
228  SDL_SetError("Invalid window");
229  return NULL;
230  }
231 
232  if (SDL_GetRenderer(window)) {
233  SDL_SetError("Renderer already associated with window");
234  return NULL;
235  }
236 
240  } else {
242  }
243  }
244 
245  if (index < 0) {
247  if (hint) {
248  for (index = 0; index < n; ++index) {
249  const SDL_RenderDriver *driver = render_drivers[index];
250 
251  if (SDL_strcasecmp(hint, driver->info.name) == 0) {
252  /* Create a new renderer instance */
253  renderer = driver->CreateRenderer(window, flags);
254  break;
255  }
256  }
257  }
258 
259  if (!renderer) {
260  for (index = 0; index < n; ++index) {
261  const SDL_RenderDriver *driver = render_drivers[index];
262 
263  if ((driver->info.flags & flags) == flags) {
264  /* Create a new renderer instance */
265  renderer = driver->CreateRenderer(window, flags);
266  if (renderer) {
267  /* Yay, we got one! */
268  break;
269  }
270  }
271  }
272  }
273  if (index == n) {
274  SDL_SetError("Couldn't find matching render driver");
275  return NULL;
276  }
277  } else {
278  if (index >= SDL_GetNumRenderDrivers()) {
279  SDL_SetError("index must be -1 or in the range of 0 - %d",
281  return NULL;
282  }
283  /* Create a new renderer instance */
284  renderer = render_drivers[index]->CreateRenderer(window, flags);
285  }
286 
287  if (renderer) {
288  renderer->magic = &renderer_magic;
289  renderer->window = window;
290  renderer->scale.x = 1.0f;
291  renderer->scale.y = 1.0f;
292 
294  renderer->hidden = SDL_TRUE;
295  } else {
296  renderer->hidden = SDL_FALSE;
297  }
298 
299  SDL_SetWindowData(window, SDL_WINDOWRENDERDATA, renderer);
300 
301  SDL_RenderSetViewport(renderer, NULL);
302 
304 
306  "Created renderer: %s", renderer->info.name);
307  }
308  return renderer;
309 #else
310  SDL_SetError("SDL not built with rendering support");
311  return NULL;
312 #endif
313 }
GLdouble n
#define SDL_HINT_RENDER_VSYNC
A variable controlling whether updates to the SDL screen surface should be synchronized with the vert...
Definition: SDL_hints.h:142
SDL_RendererInfo info
static SDL_Window * window
SDL_bool hidden
SDL_FPoint scale
#define SDL_GetHint
#define SDL_GetWindowFlags
int SDL_RenderSetViewport(SDL_Renderer *renderer, const SDL_Rect *rect)
Set the drawing area for rendering on the current target.
Definition: SDL_render.c:1253
#define SDL_strcasecmp
const char * name
Definition: SDL_render.h:80
SDL_Window * window
SDL_RendererInfo info
#define SDL_GetHintBoolean
#define SDL_SetWindowData
static SDL_Renderer * renderer
SDL_Renderer *(* CreateRenderer)(SDL_Window *window, Uint32 flags)
int SDL_GetNumRenderDrivers(void)
Get the number of 2D rendering drivers available for the current display.
Definition: SDL_render.c:81
GLuint index
#define NULL
Definition: begin_code.h:143
#define SDL_SetError
static const SDL_RenderDriver * render_drivers[]
Definition: SDL_render.c:49
#define SDL_WINDOWRENDERDATA
Definition: SDL_render.c:33
#define SDL_AddEventWatch
#define SDL_LogInfo
SDL_Renderer * SDL_GetRenderer(SDL_Window *window)
Get the renderer associated with a window.
Definition: SDL_render.c:338
#define SDL_HINT_RENDER_DRIVER
A variable specifying which render driver to use.
Definition: SDL_hints.h:84
const void * magic
Definition: SDL_sysrender.h:78
GLbitfield flags
static char renderer_magic
Definition: SDL_render.c:75
static int SDL_RendererEventWatch(void *userdata, SDL_Event *event)
Definition: SDL_render.c:106

◆ SDL_CreateSoftwareRenderer()

SDL_Renderer* SDL_CreateSoftwareRenderer ( SDL_Surface surface)

Create a 2D software rendering context for a surface.

Parameters
surfaceThe surface where rendering is done.
Returns
A valid rendering context or NULL if there was an error.
See also
SDL_CreateRenderer()
SDL_DestroyRenderer()

Definition at line 316 of file SDL_render.c.

References SDL_Renderer::magic, NULL, renderer, renderer_magic, SDL_Renderer::scale, SDL_RenderSetViewport(), SDL_SetError, SW_CreateRendererForSurface(), SDL_FPoint::x, and SDL_FPoint::y.

317 {
318 #if !SDL_RENDER_DISABLED
320 
321  renderer = SW_CreateRendererForSurface(surface);
322 
323  if (renderer) {
324  renderer->magic = &renderer_magic;
325  renderer->scale.x = 1.0f;
326  renderer->scale.y = 1.0f;
327 
328  SDL_RenderSetViewport(renderer, NULL);
329  }
330  return renderer;
331 #else
332  SDL_SetError("SDL not built with rendering support");
333  return NULL;
334 #endif /* !SDL_RENDER_DISABLED */
335 }
SDL_FPoint scale
int SDL_RenderSetViewport(SDL_Renderer *renderer, const SDL_Rect *rect)
Set the drawing area for rendering on the current target.
Definition: SDL_render.c:1253
SDL_Renderer * SW_CreateRendererForSurface(SDL_Surface *surface)
static SDL_Renderer * renderer
#define NULL
Definition: begin_code.h:143
#define SDL_SetError
const void * magic
Definition: SDL_sysrender.h:78
static char renderer_magic
Definition: SDL_render.c:75

◆ SDL_CreateTexture()

SDL_Texture* SDL_CreateTexture ( SDL_Renderer renderer,
Uint32  format,
int  access,
int  w,
int  h 
)

Create a texture for a rendering context.

Parameters
rendererThe renderer.
formatThe format of the texture.
accessOne of the enumerated values in SDL_TextureAccess.
wThe width of the texture in pixels.
hThe height of the texture in pixels.
Returns
The created texture is returned, or NULL if no rendering context was active, the format was unsupported, or the width or height were out of range.
See also
SDL_QueryTexture()
SDL_UpdateTexture()
SDL_DestroyTexture()

Definition at line 410 of file SDL_render.c.

References SDL_Texture::a, SDL_Texture::access, SDL_Texture::b, CHECK_RENDERER_MAGIC, SDL_Renderer::CreateTexture, SDL_Texture::format, SDL_Texture::g, GetClosestSupportedFormat(), SDL_Texture::h, SDL_Renderer::info, IsSupportedFormat(), SDL_Texture::magic, SDL_RendererInfo::max_texture_height, SDL_RendererInfo::max_texture_width, SDL_Texture::native, SDL_Texture::next, NULL, SDL_Texture::pitch, SDL_Texture::pixels, SDL_Texture::prev, SDL_Texture::r, renderer, SDL_Texture::renderer, SDL_BYTESPERPIXEL, SDL_calloc(), SDL_DestroyTexture(), SDL_ISPIXELFORMAT_FOURCC, SDL_ISPIXELFORMAT_INDEXED, SDL_OutOfMemory, SDL_SetError, SDL_SW_CreateYUVTexture(), SDL_TEXTUREACCESS_STREAMING, SDL_RendererInfo::texture_formats, texture_magic, SDL_Renderer::textures, SDL_Texture::w, and SDL_Texture::yuv.

Referenced by SDL_CreateTextureFromSurface().

411 {
413 
414  CHECK_RENDERER_MAGIC(renderer, NULL);
415 
416  if (!format) {
417  format = renderer->info.texture_formats[0];
418  }
419  if (SDL_BYTESPERPIXEL(format) == 0) {
420  SDL_SetError("Invalid texture format");
421  return NULL;
422  }
424  SDL_SetError("Palettized textures are not supported");
425  return NULL;
426  }
427  if (w <= 0 || h <= 0) {
428  SDL_SetError("Texture dimensions can't be 0");
429  return NULL;
430  }
431  if ((renderer->info.max_texture_width && w > renderer->info.max_texture_width) ||
432  (renderer->info.max_texture_height && h > renderer->info.max_texture_height)) {
433  SDL_SetError("Texture dimensions are limited to %dx%d", renderer->info.max_texture_width, renderer->info.max_texture_height);
434  return NULL;
435  }
436  texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture));
437  if (!texture) {
438  SDL_OutOfMemory();
439  return NULL;
440  }
441  texture->magic = &texture_magic;
442  texture->format = format;
443  texture->access = access;
444  texture->w = w;
445  texture->h = h;
446  texture->r = 255;
447  texture->g = 255;
448  texture->b = 255;
449  texture->a = 255;
450  texture->renderer = renderer;
451  texture->next = renderer->textures;
452  if (renderer->textures) {
453  renderer->textures->prev = texture;
454  }
455  renderer->textures = texture;
456 
457  if (IsSupportedFormat(renderer, format)) {
458  if (renderer->CreateTexture(renderer, texture) < 0) {
459  SDL_DestroyTexture(texture);
460  return NULL;
461  }
462  } else {
463  texture->native = SDL_CreateTexture(renderer,
465  access, w, h);
466  if (!texture->native) {
467  SDL_DestroyTexture(texture);
468  return NULL;
469  }
470 
471  /* Swap textures to have texture before texture->native in the list */
472  texture->native->next = texture->next;
473  if (texture->native->next) {
474  texture->native->next->prev = texture->native;
475  }
476  texture->prev = texture->native->prev;
477  if (texture->prev) {
478  texture->prev->next = texture;
479  }
480  texture->native->prev = texture;
481  texture->next = texture->native;
482  renderer->textures = texture;
483 
484  if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
485  texture->yuv = SDL_SW_CreateYUVTexture(format, w, h);
486  if (!texture->yuv) {
487  SDL_DestroyTexture(texture);
488  return NULL;
489  }
490  } else if (access == SDL_TEXTUREACCESS_STREAMING) {
491  /* The pitch is 4 byte aligned */
492  texture->pitch = (((w * SDL_BYTESPERPIXEL(format)) + 3) & ~3);
493  texture->pixels = SDL_calloc(1, texture->pitch * h);
494  if (!texture->pixels) {
495  SDL_DestroyTexture(texture);
496  return NULL;
497  }
498  }
499  }
500  return texture;
501 }
void * pixels
Definition: SDL_sysrender.h:65
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1565
SDL_SW_YUVTexture * SDL_SW_CreateYUVTexture(Uint32 format, int w, int h)
Definition: SDL_yuv_sw.c:1021
static Uint32 GetClosestSupportedFormat(SDL_Renderer *renderer, Uint32 format)
Definition: SDL_render.c:384
SDL_RendererInfo info
#define SDL_ISPIXELFORMAT_INDEXED(format)
Definition: SDL_pixels.h:134
GLenum GLenum GLuint texture
Uint32 texture_formats[16]
Definition: SDL_render.h:83
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:128
SDL_Texture * textures
int max_texture_height
Definition: SDL_render.h:85
static char texture_magic
Definition: SDL_render.c:76
GLuint GLint GLboolean GLint GLenum access
SDL_Texture * next
Definition: SDL_sysrender.h:72
void * SDL_calloc(size_t nmemb, size_t size)
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
void SDL_DestroyTexture(SDL_Texture *texture)
Destroy the specified texture.
Definition: SDL_render.c:1886
SDL_Texture * prev
Definition: SDL_sysrender.h:71
static SDL_Renderer * renderer
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:64
#define NULL
Definition: begin_code.h:143
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
#define SDL_SetError
static SDL_bool IsSupportedFormat(SDL_Renderer *renderer, Uint32 format)
Definition: SDL_render.c:371
SDL_Renderer * renderer
Definition: SDL_sysrender.h:60
Uint32 format
Definition: SDL_sysrender.h:52
GLubyte GLubyte GLubyte GLubyte w
int(* CreateTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
Definition: SDL_sysrender.h:82
SDL_Texture * native
Definition: SDL_sysrender.h:63
#define SDL_ISPIXELFORMAT_FOURCC(format)
Definition: SDL_pixels.h:167
const void * magic
Definition: SDL_sysrender.h:51
SDL_Texture * SDL_CreateTexture(SDL_Renderer *renderer, Uint32 format, int access, int w, int h)
Create a texture for a rendering context.
Definition: SDL_render.c:410
GLfloat GLfloat GLfloat GLfloat h

◆ SDL_CreateTextureFromSurface()

SDL_Texture* SDL_CreateTextureFromSurface ( SDL_Renderer renderer,
SDL_Surface surface 
)

Create a texture from an existing surface.

Parameters
rendererThe renderer.
surfaceThe surface containing pixel data used to fill the texture.
Returns
The created texture is returned, or NULL on error.
Note
The surface is not modified or freed by this function.
See also
SDL_QueryTexture()
SDL_DestroyTexture()

Definition at line 504 of file SDL_render.c.

References SDL_PixelFormat::Amask, blendMode, CHECK_RENDERER_MAGIC, SDL_Surface::format, SDL_PixelFormat::format, SDL_Surface::h, i, SDL_Renderer::info, NULL, SDL_RendererInfo::num_texture_formats, SDL_Surface::pitch, SDL_Surface::pixels, SDL_AllocFormat, SDL_BLENDMODE_BLEND, SDL_ConvertSurface, SDL_CreateTexture(), SDL_DestroyTexture(), SDL_FALSE, SDL_FreeFormat, SDL_FreeSurface, SDL_GetColorKey, SDL_GetSurfaceAlphaMod, SDL_GetSurfaceBlendMode, SDL_GetSurfaceColorMod, SDL_ISPIXELFORMAT_ALPHA, SDL_ISPIXELFORMAT_FOURCC, SDL_LockSurface, SDL_MUSTLOCK, SDL_SetError, SDL_SetTextureAlphaMod(), SDL_SetTextureBlendMode(), SDL_SetTextureColorMod(), SDL_TEXTUREACCESS_STATIC, SDL_TRUE, SDL_UnlockSurface, SDL_UpdateTexture(), SDL_RendererInfo::texture_formats, and SDL_Surface::w.

505 {
506  const SDL_PixelFormat *fmt;
507  SDL_bool needAlpha;
508  Uint32 i;
509  Uint32 format;
511 
512  CHECK_RENDERER_MAGIC(renderer, NULL);
513 
514  if (!surface) {
515  SDL_SetError("SDL_CreateTextureFromSurface() passed NULL surface");
516  return NULL;
517  }
518 
519  /* See what the best texture format is */
520  fmt = surface->format;
521  if (fmt->Amask || SDL_GetColorKey(surface, NULL) == 0) {
522  needAlpha = SDL_TRUE;
523  } else {
524  needAlpha = SDL_FALSE;
525  }
526  format = renderer->info.texture_formats[0];
527  for (i = 0; i < renderer->info.num_texture_formats; ++i) {
528  if (!SDL_ISPIXELFORMAT_FOURCC(renderer->info.texture_formats[i]) &&
529  SDL_ISPIXELFORMAT_ALPHA(renderer->info.texture_formats[i]) == needAlpha) {
530  format = renderer->info.texture_formats[i];
531  break;
532  }
533  }
534 
535  texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STATIC,
536  surface->w, surface->h);
537  if (!texture) {
538  return NULL;
539  }
540 
541  if (format == surface->format->format) {
542  if (SDL_MUSTLOCK(surface)) {
543  SDL_LockSurface(surface);
544  SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch);
545  SDL_UnlockSurface(surface);
546  } else {
547  SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch);
548  }
549  } else {
550  SDL_PixelFormat *dst_fmt;
551  SDL_Surface *temp = NULL;
552 
553  /* Set up a destination surface for the texture update */
554  dst_fmt = SDL_AllocFormat(format);
555  if (!dst_fmt) {
556  SDL_DestroyTexture(texture);
557  return NULL;
558  }
559  temp = SDL_ConvertSurface(surface, dst_fmt, 0);
560  SDL_FreeFormat(dst_fmt);
561  if (temp) {
562  SDL_UpdateTexture(texture, NULL, temp->pixels, temp->pitch);
563  SDL_FreeSurface(temp);
564  } else {
565  SDL_DestroyTexture(texture);
566  return NULL;
567  }
568  }
569 
570  {
571  Uint8 r, g, b, a;
573 
574  SDL_GetSurfaceColorMod(surface, &r, &g, &b);
575  SDL_SetTextureColorMod(texture, r, g, b);
576 
577  SDL_GetSurfaceAlphaMod(surface, &a);
578  SDL_SetTextureAlphaMod(texture, a);
579 
580  if (SDL_GetColorKey(surface, NULL) == 0) {
581  /* We converted to a texture with alpha format */
583  } else {
584  SDL_GetSurfaceBlendMode(surface, &blendMode);
585  SDL_SetTextureBlendMode(texture, blendMode);
586  }
587  }
588  return texture;
589 }
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1565
#define SDL_UnlockSurface
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2072
SDL_RendererInfo info
SDL_BlendMode
The blend mode used in SDL_RenderCopy() and drawing operations.
Definition: SDL_blendmode.h:40
#define SDL_ConvertSurface
GLenum GLenum GLuint texture
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
Uint32 texture_formats[16]
Definition: SDL_render.h:83
#define SDL_AllocFormat
#define SDL_ISPIXELFORMAT_ALPHA(format)
Definition: SDL_pixels.h:154
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:161
#define SDL_GetSurfaceBlendMode
static SDL_BlendMode blendMode
Definition: testdraw2.c:34
GLboolean GLboolean g
int SDL_SetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode blendMode)
Set the blend mode used for texture copy operations.
Definition: SDL_render.c:690
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
void SDL_DestroyTexture(SDL_Texture *texture)
Destroy the specified texture.
Definition: SDL_render.c:1886
void * pixels
Definition: SDL_surface.h:75
#define SDL_GetColorKey
#define SDL_FreeSurface
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:143
#define SDL_FreeFormat
#define SDL_GetSurfaceAlphaMod
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
int SDL_SetTextureAlphaMod(SDL_Texture *texture, Uint8 alpha)
Set an additional alpha value used in render copy operations.
Definition: SDL_render.c:656
int SDL_UpdateTexture(SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
Update the given texture rectangle with new pixel data.
Definition: SDL_render.c:802
#define NULL
Definition: begin_code.h:143
SDL_bool
Definition: SDL_stdinc.h:130
SDL_PixelFormat * format
Definition: SDL_surface.h:72
#define SDL_SetError
#define SDL_LockSurface
#define SDL_GetSurfaceColorMod
#define SDL_MUSTLOCK(S)
Definition: SDL_surface.h:61
int SDL_SetTextureColorMod(SDL_Texture *texture, Uint8 r, Uint8 g, Uint8 b)
Set an additional color value used in render copy operations.
Definition: SDL_render.c:613
Uint32 num_texture_formats
Definition: SDL_render.h:82
#define SDL_ISPIXELFORMAT_FOURCC(format)
Definition: SDL_pixels.h:167
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean GLboolean b
SDL_Texture * SDL_CreateTexture(SDL_Renderer *renderer, Uint32 format, int access, int w, int h)
Create a texture for a rendering context.
Definition: SDL_render.c:410

◆ SDL_CreateWindowAndRenderer()

int SDL_CreateWindowAndRenderer ( int  width,
int  height,
Uint32  window_flags,
SDL_Window **  window,
SDL_Renderer **  renderer 
)

Create a window and default renderer.

Parameters
widthThe width of the window
heightThe height of the window
window_flagsThe flags used to create the window
windowA pointer filled with the window, or NULL on error
rendererA pointer filled with the renderer, or NULL on error
Returns
0 on success, or -1 on error

Definition at line 200 of file SDL_render.c.

References NULL, SDL_CreateRenderer(), SDL_CreateWindow, and SDL_WINDOWPOS_UNDEFINED.

202 {
205  width, height, window_flags);
206  if (!*window) {
207  *renderer = NULL;
208  return -1;
209  }
210 
211  *renderer = SDL_CreateRenderer(*window, -1, 0);
212  if (!*renderer) {
213  return -1;
214  }
215 
216  return 0;
217 }
GLint GLint GLsizei width
Definition: SDL_opengl.h:1565
#define SDL_CreateWindow
#define SDL_WINDOWPOS_UNDEFINED
Definition: SDL_video.h:127
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1565
#define NULL
Definition: begin_code.h:143
SDL_Renderer * SDL_CreateRenderer(SDL_Window *window, int index, Uint32 flags)
Create a 2D rendering context for a window.
Definition: SDL_render.c:220

◆ SDL_DestroyRenderer()

void SDL_DestroyRenderer ( SDL_Renderer renderer)

Destroy the rendering context for a window and free associated textures.

See also
SDL_CreateRenderer()

Definition at line 1921 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::DestroyRenderer, SDL_Renderer::magic, NULL, SDL_DelEventWatch, SDL_DestroyTexture(), SDL_RendererEventWatch(), SDL_SetWindowData, SDL_WINDOWRENDERDATA, SDL_Renderer::textures, and SDL_Renderer::window.

1922 {
1923  CHECK_RENDERER_MAGIC(renderer, );
1924 
1926 
1927  /* Free existing textures for this renderer */
1928  while (renderer->textures) {
1929  SDL_DestroyTexture(renderer->textures);
1930  }
1931 
1932  if (renderer->window) {
1934  }
1935 
1936  /* It's no longer magical... */
1937  renderer->magic = NULL;
1938 
1939  /* Free the renderer instance */
1940  renderer->DestroyRenderer(renderer);
1941 }
#define SDL_DelEventWatch
SDL_Texture * textures
SDL_Window * window
void(* DestroyRenderer)(SDL_Renderer *renderer)
#define SDL_SetWindowData
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
void SDL_DestroyTexture(SDL_Texture *texture)
Destroy the specified texture.
Definition: SDL_render.c:1886
#define NULL
Definition: begin_code.h:143
#define SDL_WINDOWRENDERDATA
Definition: SDL_render.c:33
const void * magic
Definition: SDL_sysrender.h:78
static int SDL_RendererEventWatch(void *userdata, SDL_Event *event)
Definition: SDL_render.c:106

◆ SDL_DestroyTexture()

void SDL_DestroyTexture ( SDL_Texture texture)

Destroy the specified texture.

See also
SDL_CreateTexture()
SDL_CreateTextureFromSurface()

Definition at line 1886 of file SDL_render.c.

References CHECK_TEXTURE_MAGIC, SDL_Renderer::DestroyTexture, SDL_Texture::magic, SDL_Texture::native, SDL_Texture::next, NULL, SDL_Texture::pixels, SDL_Texture::prev, renderer, SDL_Texture::renderer, SDL_free(), SDL_SetRenderTarget(), SDL_SW_DestroyYUVTexture(), SDL_Renderer::target, SDL_Renderer::textures, and SDL_Texture::yuv.

Referenced by SDL_CreateTexture(), SDL_CreateTextureFromSurface(), and SDL_DestroyRenderer().

1887 {
1889 
1890  CHECK_TEXTURE_MAGIC(texture, );
1891 
1892  renderer = texture->renderer;
1893  if (texture == renderer->target) {
1894  SDL_SetRenderTarget(renderer, NULL);
1895  }
1896 
1897  texture->magic = NULL;
1898 
1899  if (texture->next) {
1900  texture->next->prev = texture->prev;
1901  }
1902  if (texture->prev) {
1903  texture->prev->next = texture->next;
1904  } else {
1905  renderer->textures = texture->next;
1906  }
1907 
1908  if (texture->native) {
1909  SDL_DestroyTexture(texture->native);
1910  }
1911  if (texture->yuv) {
1912  SDL_SW_DestroyYUVTexture(texture->yuv);
1913  }
1914  SDL_free(texture->pixels);
1915 
1916  renderer->DestroyTexture(renderer, texture);
1917  SDL_free(texture);
1918 }
void * pixels
Definition: SDL_sysrender.h:65
SDL_Texture * textures
SDL_Texture * next
Definition: SDL_sysrender.h:72
void SDL_DestroyTexture(SDL_Texture *texture)
Destroy the specified texture.
Definition: SDL_render.c:1886
SDL_Texture * prev
Definition: SDL_sysrender.h:71
SDL_Texture * target
static SDL_Renderer * renderer
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:64
void SDL_free(void *mem)
void SDL_SW_DestroyYUVTexture(SDL_SW_YUVTexture *swdata)
Definition: SDL_yuv_sw.c:1393
#define NULL
Definition: begin_code.h:143
SDL_Renderer * renderer
Definition: SDL_sysrender.h:60
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:41
void(* DestroyTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
SDL_Texture * native
Definition: SDL_sysrender.h:63
int SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
Set a texture as the current rendering target.
Definition: SDL_render.c:1063
const void * magic
Definition: SDL_sysrender.h:51

◆ SDL_GetNumRenderDrivers()

int SDL_GetNumRenderDrivers ( void  )

Get the number of 2D rendering drivers available for the current display.

A render driver is a set of code that handles rendering and texture management on a particular display. Normally there is only one, but some drivers may have several available with different capabilities.

See also
SDL_GetRenderDriverInfo()
SDL_CreateRenderer()

Definition at line 81 of file SDL_render.c.

References SDL_arraysize.

Referenced by SDL_CreateRenderer(), and SDL_GetRenderDriverInfo().

82 {
83 #if !SDL_RENDER_DISABLED
85 #else
86  return 0;
87 #endif
88 }
static const SDL_RenderDriver * render_drivers[]
Definition: SDL_render.c:49
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:90

◆ SDL_GetRenderDrawBlendMode()

int SDL_GetRenderDrawBlendMode ( SDL_Renderer renderer,
SDL_BlendMode blendMode 
)

Get the blend mode used for drawing operations.

Parameters
rendererThe renderer from which blend mode should be queried.
blendModeA pointer filled in with the current blend mode.
Returns
0 on success, or -1 on error
See also
SDL_SetRenderDrawBlendMode()

Definition at line 1390 of file SDL_render.c.

References SDL_Renderer::blendMode, and CHECK_RENDERER_MAGIC.

1391 {
1392  CHECK_RENDERER_MAGIC(renderer, -1);
1393 
1394  *blendMode = renderer->blendMode;
1395  return 0;
1396 }
static SDL_BlendMode blendMode
Definition: testdraw2.c:34
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
SDL_BlendMode blendMode

◆ SDL_GetRenderDrawColor()

int SDL_GetRenderDrawColor ( SDL_Renderer renderer,
Uint8 r,
Uint8 g,
Uint8 b,
Uint8 a 
)

Get the color used for drawing operations (Rect, Line and Clear).

Parameters
rendererThe renderer from which drawing color should be queried.
rA pointer to the red value used to draw on the rendering target.
gA pointer to the green value used to draw on the rendering target.
bA pointer to the blue value used to draw on the rendering target.
aA pointer to the alpha value used to draw on the rendering target, usually SDL_ALPHA_OPAQUE (255).
Returns
0 on success, or -1 on error

Definition at line 1360 of file SDL_render.c.

References SDL_Renderer::a, SDL_Renderer::b, CHECK_RENDERER_MAGIC, SDL_Renderer::g, and SDL_Renderer::r.

1362 {
1363  CHECK_RENDERER_MAGIC(renderer, -1);
1364 
1365  if (r) {
1366  *r = renderer->r;
1367  }
1368  if (g) {
1369  *g = renderer->g;
1370  }
1371  if (b) {
1372  *b = renderer->b;
1373  }
1374  if (a) {
1375  *a = renderer->a;
1376  }
1377  return 0;
1378 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2072
GLboolean GLboolean g
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean GLboolean b

◆ SDL_GetRenderDriverInfo()

int SDL_GetRenderDriverInfo ( int  index,
SDL_RendererInfo info 
)

Get information about a specific 2D rendering driver for the current display.

Parameters
indexThe index of the driver to query information about.
infoA pointer to an SDL_RendererInfo struct to be filled with information on the rendering driver.
Returns
0 on success, -1 if the index was out of range.
See also
SDL_CreateRenderer()

Definition at line 91 of file SDL_render.c.

References SDL_RenderDriver::info, SDL_GetNumRenderDrivers(), and SDL_SetError.

92 {
93 #if !SDL_RENDER_DISABLED
95  return SDL_SetError("index must be in the range of 0 - %d",
97  }
98  *info = render_drivers[index]->info;
99  return 0;
100 #else
101  return SDL_SetError("SDL not built with rendering support");
102 #endif
103 }
SDL_RendererInfo info
int SDL_GetNumRenderDrivers(void)
Get the number of 2D rendering drivers available for the current display.
Definition: SDL_render.c:81
GLuint index
#define SDL_SetError
static const SDL_RenderDriver * render_drivers[]
Definition: SDL_render.c:49

◆ SDL_GetRenderer()

SDL_Renderer* SDL_GetRenderer ( SDL_Window window)

Get the renderer associated with a window.

Definition at line 338 of file SDL_render.c.

References SDL_GetWindowData, and SDL_WINDOWRENDERDATA.

Referenced by SDL_CreateRenderer().

339 {
341 }
#define SDL_GetWindowData
#define SDL_WINDOWRENDERDATA
Definition: SDL_render.c:33

◆ SDL_GetRendererInfo()

int SDL_GetRendererInfo ( SDL_Renderer renderer,
SDL_RendererInfo info 
)

Get information about a rendering context.

Definition at line 344 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, and SDL_Renderer::info.

345 {
346  CHECK_RENDERER_MAGIC(renderer, -1);
347 
348  *info = renderer->info;
349  return 0;
350 }
SDL_RendererInfo info
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35

◆ SDL_GetRendererOutputSize()

int SDL_GetRendererOutputSize ( SDL_Renderer renderer,
int *  w,
int *  h 
)

Get the output size in pixels of a rendering context.

Definition at line 353 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::GetOutputSize, NULL, SDL_assert, SDL_GetWindowSize, SDL_QueryTexture(), SDL_SetError, SDL_Renderer::target, and SDL_Renderer::window.

Referenced by SDL_RenderSetViewport(), and UpdateLogicalSize().

354 {
355  CHECK_RENDERER_MAGIC(renderer, -1);
356 
357  if (renderer->target) {
358  return SDL_QueryTexture(renderer->target, NULL, NULL, w, h);
359  } else if (renderer->GetOutputSize) {
360  return renderer->GetOutputSize(renderer, w, h);
361  } else if (renderer->window) {
362  SDL_GetWindowSize(renderer->window, w, h);
363  return 0;
364  } else {
365  SDL_assert(0 && "This should never happen");
366  return SDL_SetError("Renderer doesn't support querying output size");
367  }
368 }
SDL_Window * window
int(* GetOutputSize)(SDL_Renderer *renderer, int *w, int *h)
Definition: SDL_sysrender.h:81
int SDL_QueryTexture(SDL_Texture *texture, Uint32 *format, int *access, int *w, int *h)
Query the attributes of a texture.
Definition: SDL_render.c:592
#define SDL_GetWindowSize
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
SDL_Texture * target
#define SDL_assert(condition)
Definition: SDL_assert.h:167
#define NULL
Definition: begin_code.h:143
#define SDL_SetError
GLubyte GLubyte GLubyte GLubyte w
GLfloat GLfloat GLfloat GLfloat h

◆ SDL_GetRenderTarget()

SDL_Texture* SDL_GetRenderTarget ( SDL_Renderer renderer)

Get the current render target or NULL for the default render target.

Returns
The current render target
See also
SDL_SetRenderTarget()

Definition at line 1134 of file SDL_render.c.

References SDL_Renderer::target.

Referenced by SDL_RendererEventWatch().

1135 {
1136  return renderer->target;
1137 }
SDL_Texture * target

◆ SDL_GetTextureAlphaMod()

int SDL_GetTextureAlphaMod ( SDL_Texture texture,
Uint8 alpha 
)

Get the additional alpha value used in render copy operations.

Parameters
textureThe texture to query.
alphaA pointer filled in with the current alpha value.
Returns
0 on success, or -1 if the texture is not valid.
See also
SDL_SetTextureAlphaMod()

Definition at line 679 of file SDL_render.c.

References SDL_Texture::a, and CHECK_TEXTURE_MAGIC.

680 {
681  CHECK_TEXTURE_MAGIC(texture, -1);
682 
683  if (alpha) {
684  *alpha = texture->a;
685  }
686  return 0;
687 }
GLfloat GLfloat GLfloat alpha
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:41

◆ SDL_GetTextureBlendMode()

int SDL_GetTextureBlendMode ( SDL_Texture texture,
SDL_BlendMode blendMode 
)

Get the blend mode used for texture copy operations.

Parameters
textureThe texture to query.
blendModeA pointer filled in with the current blend mode.
Returns
0 on success, or -1 if the texture is not valid.
See also
SDL_SetTextureBlendMode()

Definition at line 708 of file SDL_render.c.

References SDL_Texture::blendMode, and CHECK_TEXTURE_MAGIC.

709 {
710  CHECK_TEXTURE_MAGIC(texture, -1);
711 
712  if (blendMode) {
713  *blendMode = texture->blendMode;
714  }
715  return 0;
716 }
SDL_BlendMode blendMode
Definition: SDL_sysrender.h:57
static SDL_BlendMode blendMode
Definition: testdraw2.c:34
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:41

◆ SDL_GetTextureColorMod()

int SDL_GetTextureColorMod ( SDL_Texture texture,
Uint8 r,
Uint8 g,
Uint8 b 
)

Get the additional color value used in render copy operations.

Parameters
textureThe texture to query.
rA pointer filled in with the current red color value.
gA pointer filled in with the current green color value.
bA pointer filled in with the current blue color value.
Returns
0 on success, or -1 if the texture is not valid.
See also
SDL_SetTextureColorMod()

Definition at line 638 of file SDL_render.c.

References SDL_Texture::b, CHECK_TEXTURE_MAGIC, SDL_Texture::g, and SDL_Texture::r.

640 {
641  CHECK_TEXTURE_MAGIC(texture, -1);
642 
643  if (r) {
644  *r = texture->r;
645  }
646  if (g) {
647  *g = texture->g;
648  }
649  if (b) {
650  *b = texture->b;
651  }
652  return 0;
653 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2072
GLboolean GLboolean g
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:41
GLboolean GLboolean GLboolean b

◆ SDL_GL_BindTexture()

int SDL_GL_BindTexture ( SDL_Texture texture,
float *  texw,
float *  texh 
)

Bind the texture to the current OpenGL/ES/ES2 context for use with OpenGL instructions.

Parameters
textureThe SDL texture to bind
texwA pointer to a float that will be filled with the texture width
texhA pointer to a float that will be filled with the texture height
Returns
0 on success, or -1 if the operation is not supported

Definition at line 1943 of file SDL_render.c.

References CHECK_TEXTURE_MAGIC, SDL_Renderer::GL_BindTexture, SDL_Texture::native, renderer, SDL_Texture::renderer, and SDL_Unsupported.

1944 {
1946 
1947  CHECK_TEXTURE_MAGIC(texture, -1);
1948  renderer = texture->renderer;
1949  if (texture->native) {
1950  return SDL_GL_BindTexture(texture->native, texw, texh);
1951  } else if (renderer && renderer->GL_BindTexture) {
1952  return renderer->GL_BindTexture(renderer, texture, texw, texh);
1953  } else {
1954  return SDL_Unsupported();
1955  }
1956 }
static SDL_Renderer * renderer
int(* GL_BindTexture)(SDL_Renderer *renderer, SDL_Texture *texture, float *texw, float *texh)
int SDL_GL_BindTexture(SDL_Texture *texture, float *texw, float *texh)
Bind the texture to the current OpenGL/ES/ES2 context for use with OpenGL instructions.
Definition: SDL_render.c:1943
SDL_Renderer * renderer
Definition: SDL_sysrender.h:60
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:41
SDL_Texture * native
Definition: SDL_sysrender.h:63
#define SDL_Unsupported()
Definition: SDL_error.h:53

◆ SDL_GL_UnbindTexture()

int SDL_GL_UnbindTexture ( SDL_Texture texture)

Unbind a texture from the current OpenGL/ES/ES2 context.

Parameters
textureThe SDL texture to unbind
Returns
0 on success, or -1 if the operation is not supported

Definition at line 1958 of file SDL_render.c.

References CHECK_TEXTURE_MAGIC, SDL_Renderer::GL_UnbindTexture, SDL_Texture::native, renderer, SDL_Texture::renderer, and SDL_Unsupported.

1959 {
1961 
1962  CHECK_TEXTURE_MAGIC(texture, -1);
1963  renderer = texture->renderer;
1964  if (texture->native) {
1965  return SDL_GL_UnbindTexture(texture->native);
1966  } else if (renderer && renderer->GL_UnbindTexture) {
1967  return renderer->GL_UnbindTexture(renderer, texture);
1968  }
1969 
1970  return SDL_Unsupported();
1971 }
static SDL_Renderer * renderer
int(* GL_UnbindTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
SDL_Renderer * renderer
Definition: SDL_sysrender.h:60
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:41
SDL_Texture * native
Definition: SDL_sysrender.h:63
#define SDL_Unsupported()
Definition: SDL_error.h:53
int SDL_GL_UnbindTexture(SDL_Texture *texture)
Unbind a texture from the current OpenGL/ES/ES2 context.
Definition: SDL_render.c:1958

◆ SDL_LockTexture()

int SDL_LockTexture ( SDL_Texture texture,
const SDL_Rect rect,
void **  pixels,
int *  pitch 
)

Lock a portion of the texture for write-only pixel access.

Parameters
textureThe texture to lock for access, which was created with SDL_TEXTUREACCESS_STREAMING.
rectA pointer to the rectangle to lock for access. If the rect is NULL, the entire texture will be locked.
pixelsThis is filled in with a pointer to the locked pixels, appropriately offset by the locked area.
pitchThis is filled in with the pitch of the locked pixels.
Returns
0 on success, or -1 if the texture is not valid or was not created with SDL_TEXTUREACCESS_STREAMING.
See also
SDL_UnlockTexture()

Definition at line 961 of file SDL_render.c.

References SDL_Texture::access, CHECK_TEXTURE_MAGIC, SDL_Texture::h, SDL_Rect::h, SDL_Renderer::LockTexture, SDL_Texture::native, renderer, SDL_Texture::renderer, SDL_LockTextureNative(), SDL_LockTextureYUV(), SDL_SetError, SDL_TEXTUREACCESS_STREAMING, SDL_Texture::w, SDL_Rect::w, SDL_Rect::x, SDL_Rect::y, and SDL_Texture::yuv.

Referenced by SDL_UnlockTextureNative(), SDL_UnlockTextureYUV(), SDL_UpdateTextureNative(), SDL_UpdateTextureYUV(), and SDL_UpdateTextureYUVPlanar().

963 {
965  SDL_Rect full_rect;
966 
967  CHECK_TEXTURE_MAGIC(texture, -1);
968 
969  if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
970  return SDL_SetError("SDL_LockTexture(): texture must be streaming");
971  }
972 
973  if (!rect) {
974  full_rect.x = 0;
975  full_rect.y = 0;
976  full_rect.w = texture->w;
977  full_rect.h = texture->h;
978  rect = &full_rect;
979  }
980 
981  if (texture->yuv) {
982  return SDL_LockTextureYUV(texture, rect, pixels, pitch);
983  } else if (texture->native) {
984  return SDL_LockTextureNative(texture, rect, pixels, pitch);
985  } else {
986  renderer = texture->renderer;
987  return renderer->LockTexture(renderer, texture, rect, pixels, pitch);
988  }
989 }
int(* LockTexture)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
Definition: SDL_sysrender.h:97
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1565
static int SDL_LockTextureYUV(SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
Definition: SDL_render.c:942
static SDL_Renderer * renderer
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:64
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
#define SDL_SetError
SDL_Renderer * renderer
Definition: SDL_sysrender.h:60
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:41
int h
Definition: SDL_rect.h:67
SDL_Texture * native
Definition: SDL_sysrender.h:63
int y
Definition: SDL_rect.h:66
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64
static int SDL_LockTextureNative(SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
Definition: SDL_render.c:949

◆ SDL_LockTextureNative()

static int SDL_LockTextureNative ( SDL_Texture texture,
const SDL_Rect rect,
void **  pixels,
int *  pitch 
)
static

Definition at line 949 of file SDL_render.c.

References SDL_Texture::format, SDL_Texture::locked_rect, SDL_Texture::pitch, SDL_Texture::pixels, rect, SDL_BYTESPERPIXEL, SDL_Rect::x, and SDL_Rect::y.

Referenced by SDL_LockTexture().

951 {
952  texture->locked_rect = *rect;
953  *pixels = (void *) ((Uint8 *) texture->pixels +
954  rect->y * texture->pitch +
955  rect->x * SDL_BYTESPERPIXEL(texture->format));
956  *pitch = texture->pitch;
957  return 0;
958 }
void * pixels
Definition: SDL_sysrender.h:65
SDL_Rect rect
Definition: testrelative.c:27
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:128
SDL_Rect locked_rect
Definition: SDL_sysrender.h:67
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1565
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:143
int x
Definition: SDL_rect.h:66
Uint32 format
Definition: SDL_sysrender.h:52
int y
Definition: SDL_rect.h:66

◆ SDL_LockTextureYUV()

static int SDL_LockTextureYUV ( SDL_Texture texture,
const SDL_Rect rect,
void **  pixels,
int *  pitch 
)
static

Definition at line 942 of file SDL_render.c.

References SDL_SW_LockYUVTexture(), and SDL_Texture::yuv.

Referenced by SDL_LockTexture().

944 {
945  return SDL_SW_LockYUVTexture(texture->yuv, rect, pixels, pitch);
946 }
int SDL_SW_LockYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect, void **pixels, int *pitch)
Definition: SDL_yuv_sw.c:1243
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1565
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:64

◆ SDL_QueryTexture()

int SDL_QueryTexture ( SDL_Texture texture,
Uint32 format,
int *  access,
int *  w,
int *  h 
)

Query the attributes of a texture.

Parameters
textureA texture to be queried.
formatA pointer filled in with the raw format of the texture. The actual format may differ, but pixel transfers will use this format.
accessA pointer filled in with the actual access to the texture.
wA pointer filled in with the width of the texture in pixels.
hA pointer filled in with the height of the texture in pixels.
Returns
0 on success, or -1 if the texture is not valid.

Definition at line 592 of file SDL_render.c.

References SDL_Texture::access, CHECK_TEXTURE_MAGIC, SDL_Texture::format, SDL_Texture::h, and SDL_Texture::w.

Referenced by SDL_GetRendererOutputSize().

594 {
595  CHECK_TEXTURE_MAGIC(texture, -1);
596 
597  if (format) {
598  *format = texture->format;
599  }
600  if (access) {
601  *access = texture->access;
602  }
603  if (w) {
604  *w = texture->w;
605  }
606  if (h) {
607  *h = texture->h;
608  }
609  return 0;
610 }
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1565
GLuint GLint GLboolean GLint GLenum access
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:41
Uint32 format
Definition: SDL_sysrender.h:52
GLubyte GLubyte GLubyte GLubyte w
GLfloat GLfloat GLfloat GLfloat h

◆ SDL_RenderClear()

int SDL_RenderClear ( SDL_Renderer renderer)

Clear the current rendering target with the drawing color.

This function clears the entire rendering target, ignoring the viewport and the clip rectangle.

Returns
0 on success, or -1 on error

Definition at line 1399 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::hidden, and SDL_Renderer::RenderClear.

1400 {
1401  CHECK_RENDERER_MAGIC(renderer, -1);
1402 
1403  /* Don't draw while we're hidden */
1404  if (renderer->hidden) {
1405  return 0;
1406  }
1407  return renderer->RenderClear(renderer);
1408 }
SDL_bool hidden
int(* RenderClear)(SDL_Renderer *renderer)
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35

◆ SDL_RenderCopy()

int SDL_RenderCopy ( SDL_Renderer renderer,
SDL_Texture texture,
const SDL_Rect srcrect,
const SDL_Rect dstrect 
)

Copy a portion of the texture to the current rendering target.

Parameters
rendererThe renderer which should copy parts of a texture.
textureThe source texture.
srcrectA pointer to the source rectangle, or NULL for the entire texture.
dstrectA pointer to the destination rectangle, or NULL for the entire rendering target.
Returns
0 on success, or -1 on error

Definition at line 1713 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, CHECK_TEXTURE_MAGIC, SDL_FRect::h, SDL_Texture::h, SDL_Rect::h, SDL_Renderer::hidden, SDL_Texture::native, SDL_Renderer::RenderCopy, SDL_Texture::renderer, SDL_Renderer::scale, SDL_HasIntersection, SDL_IntersectRect, SDL_RenderGetViewport(), SDL_SetError, SDL_FRect::w, SDL_Texture::w, SDL_Rect::w, SDL_FPoint::x, SDL_FRect::x, SDL_Rect::x, SDL_FPoint::y, SDL_FRect::y, and SDL_Rect::y.

Referenced by SDL_RenderCopyEx().

1715 {
1716  SDL_Rect real_srcrect = { 0, 0, 0, 0 };
1717  SDL_Rect real_dstrect = { 0, 0, 0, 0 };
1718  SDL_FRect frect;
1719 
1720  CHECK_RENDERER_MAGIC(renderer, -1);
1721  CHECK_TEXTURE_MAGIC(texture, -1);
1722 
1723  if (renderer != texture->renderer) {
1724  return SDL_SetError("Texture was not created with this renderer");
1725  }
1726 
1727  /* Don't draw while we're hidden */
1728  if (renderer->hidden) {
1729  return 0;
1730  }
1731 
1732  real_srcrect.x = 0;
1733  real_srcrect.y = 0;
1734  real_srcrect.w = texture->w;
1735  real_srcrect.h = texture->h;
1736  if (srcrect) {
1737  if (!SDL_IntersectRect(srcrect, &real_srcrect, &real_srcrect)) {
1738  return 0;
1739  }
1740  }
1741 
1742  SDL_RenderGetViewport(renderer, &real_dstrect);
1743  real_dstrect.x = 0;
1744  real_dstrect.y = 0;
1745  if (dstrect) {
1746  if (!SDL_HasIntersection(dstrect, &real_dstrect)) {
1747  return 0;
1748  }
1749  real_dstrect = *dstrect;
1750  }
1751 
1752  if (texture->native) {
1753  texture = texture->native;
1754  }
1755 
1756  frect.x = real_dstrect.x * renderer->scale.x;
1757  frect.y = real_dstrect.y * renderer->scale.y;
1758  frect.w = real_dstrect.w * renderer->scale.x;
1759  frect.h = real_dstrect.h * renderer->scale.y;
1760 
1761  return renderer->RenderCopy(renderer, texture, &real_srcrect, &frect);
1762 }
#define SDL_HasIntersection
SDL_bool hidden
SDL_FPoint scale
#define SDL_IntersectRect
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
int(* RenderCopy)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_FRect *dstrect)
#define SDL_SetError
SDL_Renderer * renderer
Definition: SDL_sysrender.h:60
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:41
int h
Definition: SDL_rect.h:67
void SDL_RenderGetViewport(SDL_Renderer *renderer, SDL_Rect *rect)
Get the drawing area for the current target.
Definition: SDL_render.c:1273
SDL_Texture * native
Definition: SDL_sysrender.h:63
int y
Definition: SDL_rect.h:66
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

◆ SDL_RenderCopyEx()

int SDL_RenderCopyEx ( SDL_Renderer renderer,
SDL_Texture texture,
const SDL_Rect srcrect,
const SDL_Rect dstrect,
const double  angle,
const SDL_Point center,
const SDL_RendererFlip  flip 
)

Copy a portion of the source texture to the current rendering target, rotating it by angle around the given center.

Parameters
rendererThe renderer which should copy parts of a texture.
textureThe source texture.
srcrectA pointer to the source rectangle, or NULL for the entire texture.
dstrectA pointer to the destination rectangle, or NULL for the entire rendering target.
angleAn angle in degrees that indicates the rotation that will be applied to dstrect
centerA pointer to a point indicating the point around which dstrect will be rotated (if NULL, rotation will be done around dstrect.w/2, dstrect.h/2).
flipAn SDL_RendererFlip value stating which flipping actions should be performed on the texture
Returns
0 on success, or -1 on error

Definition at line 1766 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, CHECK_TEXTURE_MAGIC, SDL_FRect::h, SDL_Texture::h, SDL_Rect::h, SDL_Renderer::hidden, SDL_Texture::native, SDL_Renderer::RenderCopyEx, SDL_Texture::renderer, SDL_Renderer::scale, SDL_FLIP_NONE, SDL_IntersectRect, SDL_RenderCopy(), SDL_RenderGetViewport(), SDL_SetError, SDL_FRect::w, SDL_Texture::w, SDL_Rect::w, SDL_FPoint::x, SDL_FRect::x, SDL_Point::x, SDL_Rect::x, SDL_FPoint::y, SDL_FRect::y, SDL_Point::y, and SDL_Rect::y.

1769 {
1770  SDL_Rect real_srcrect = { 0, 0, 0, 0 };
1771  SDL_Rect real_dstrect = { 0, 0, 0, 0 };
1772  SDL_Point real_center;
1773  SDL_FRect frect;
1774  SDL_FPoint fcenter;
1775 
1776  if (flip == SDL_FLIP_NONE && (int)(angle/360) == angle/360) { /* fast path when we don't need rotation or flipping */
1777  return SDL_RenderCopy(renderer, texture, srcrect, dstrect);
1778  }
1779 
1780  CHECK_RENDERER_MAGIC(renderer, -1);
1781  CHECK_TEXTURE_MAGIC(texture, -1);
1782 
1783  if (renderer != texture->renderer) {
1784  return SDL_SetError("Texture was not created with this renderer");
1785  }
1786  if (!renderer->RenderCopyEx) {
1787  return SDL_SetError("Renderer does not support RenderCopyEx");
1788  }
1789 
1790  /* Don't draw while we're hidden */
1791  if (renderer->hidden) {
1792  return 0;
1793  }
1794 
1795  real_srcrect.x = 0;
1796  real_srcrect.y = 0;
1797  real_srcrect.w = texture->w;
1798  real_srcrect.h = texture->h;
1799  if (srcrect) {
1800  if (!SDL_IntersectRect(srcrect, &real_srcrect, &real_srcrect)) {
1801  return 0;
1802  }
1803  }
1804 
1805  /* We don't intersect the dstrect with the viewport as RenderCopy does because of potential rotation clipping issues... TODO: should we? */
1806  if (dstrect) {
1807  real_dstrect = *dstrect;
1808  } else {
1809  SDL_RenderGetViewport(renderer, &real_dstrect);
1810  real_dstrect.x = 0;
1811  real_dstrect.y = 0;
1812  }
1813 
1814  if (texture->native) {
1815  texture = texture->native;
1816  }
1817 
1818  if (center) {
1819  real_center = *center;
1820  } else {
1821  real_center.x = real_dstrect.w/2;
1822  real_center.y = real_dstrect.h/2;
1823  }
1824 
1825  frect.x = real_dstrect.x * renderer->scale.x;
1826  frect.y = real_dstrect.y * renderer->scale.y;
1827  frect.w = real_dstrect.w * renderer->scale.x;
1828  frect.h = real_dstrect.h * renderer->scale.y;
1829 
1830  fcenter.x = real_center.x * renderer->scale.x;
1831  fcenter.y = real_center.y * renderer->scale.y;
1832 
1833  return renderer->RenderCopyEx(renderer, texture, &real_srcrect, &frect, angle, &fcenter, flip);
1834 }
int SDL_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect)
Copy a portion of the texture to the current rendering target.
Definition: SDL_render.c:1713
SDL_bool hidden
The structure that defines a point.
Definition: SDL_rect.h:48
SDL_FPoint scale
#define SDL_IntersectRect
int x
Definition: SDL_rect.h:50
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
int y
Definition: SDL_rect.h:51
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
#define SDL_SetError
SDL_Renderer * renderer
Definition: SDL_sysrender.h:60
int(* RenderCopyEx)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcquad, const SDL_FRect *dstrect, const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:41
int h
Definition: SDL_rect.h:67
void SDL_RenderGetViewport(SDL_Renderer *renderer, SDL_Rect *rect)
Get the drawing area for the current target.
Definition: SDL_render.c:1273
GLfloat angle
SDL_Texture * native
Definition: SDL_sysrender.h:63
int y
Definition: SDL_rect.h:66
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

◆ SDL_RenderDrawLine()

int SDL_RenderDrawLine ( SDL_Renderer renderer,
int  x1,
int  y1,
int  x2,
int  y2 
)

Draw a line on the current rendering target.

Parameters
rendererThe renderer which should draw a line.
x1The x coordinate of the start point.
y1The y coordinate of the start point.
x2The x coordinate of the end point.
y2The y coordinate of the end point.
Returns
0 on success, or -1 on error

Definition at line 1489 of file SDL_render.c.

References SDL_RenderDrawLines(), SDL_Point::x, and SDL_Point::y.

1490 {
1491  SDL_Point points[2];
1492 
1493  points[0].x = x1;
1494  points[0].y = y1;
1495  points[1].x = x2;
1496  points[1].y = y2;
1497  return SDL_RenderDrawLines(renderer, points, 2);
1498 }
GLuint GLfloat GLfloat GLfloat x1
GLfixed GLfixed GLfixed y2
The structure that defines a point.
Definition: SDL_rect.h:48
GLfixed GLfixed x2
GLfixed GLfixed GLint GLint GLfixed points
GLfixed y1
int x
Definition: SDL_rect.h:50
int y
Definition: SDL_rect.h:51
int SDL_RenderDrawLines(SDL_Renderer *renderer, const SDL_Point *points, int count)
Draw a series of connected lines on the current rendering target.
Definition: SDL_render.c:1557

◆ SDL_RenderDrawLines()

int SDL_RenderDrawLines ( SDL_Renderer renderer,
const SDL_Point points,
int  count 
)

Draw a series of connected lines on the current rendering target.

Parameters
rendererThe renderer which should draw multiple lines.
pointsThe points along the lines
countThe number of points, drawing count-1 lines
Returns
0 on success, or -1 on error

Definition at line 1557 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::hidden, i, SDL_Renderer::RenderDrawLines, RenderDrawLinesWithRects(), SDL_Renderer::scale, SDL_OutOfMemory, SDL_SetError, SDL_stack_alloc, SDL_stack_free, SDL_FPoint::x, SDL_Point::x, SDL_FPoint::y, and SDL_Point::y.

Referenced by SDL_RenderDrawLine(), and SDL_RenderDrawRect().

1559 {
1560  SDL_FPoint *fpoints;
1561  int i;
1562  int status;
1563 
1564  CHECK_RENDERER_MAGIC(renderer, -1);
1565 
1566  if (!points) {
1567  return SDL_SetError("SDL_RenderDrawLines(): Passed NULL points");
1568  }
1569  if (count < 2) {
1570  return 0;
1571  }
1572 
1573  /* Don't draw while we're hidden */
1574  if (renderer->hidden) {
1575  return 0;
1576  }
1577 
1578  if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) {
1579  return RenderDrawLinesWithRects(renderer, points, count);
1580  }
1581 
1582  fpoints = SDL_stack_alloc(SDL_FPoint, count);
1583  if (!fpoints) {
1584  return SDL_OutOfMemory();
1585  }
1586  for (i = 0; i < count; ++i) {
1587  fpoints[i].x = points[i].x * renderer->scale.x;
1588  fpoints[i].y = points[i].y * renderer->scale.y;
1589  }
1590 
1591  status = renderer->RenderDrawLines(renderer, fpoints, count);
1592 
1593  SDL_stack_free(fpoints);
1594 
1595  return status;
1596 }
int(* RenderDrawLines)(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1564
SDL_bool hidden
SDL_FPoint scale
static int RenderDrawLinesWithRects(SDL_Renderer *renderer, const SDL_Point *points, int count)
Definition: SDL_render.c:1501
int x
Definition: SDL_rect.h:50
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
int y
Definition: SDL_rect.h:51
#define SDL_stack_alloc(type, count)
Definition: SDL_stdinc.h:330
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
#define SDL_SetError
#define SDL_stack_free(data)
Definition: SDL_stdinc.h:331

◆ SDL_RenderDrawPoint()

int SDL_RenderDrawPoint ( SDL_Renderer renderer,
int  x,
int  y 
)

Draw a point on the current rendering target.

Parameters
rendererThe renderer which should draw a point.
xThe x coordinate of the point.
yThe y coordinate of the point.
Returns
0 on success, or -1 on error

Definition at line 1411 of file SDL_render.c.

References SDL_RenderDrawPoints(), SDL_Point::x, and SDL_Point::y.

1412 {
1413  SDL_Point point;
1414 
1415  point.x = x;
1416  point.y = y;
1417  return SDL_RenderDrawPoints(renderer, &point, 1);
1418 }
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1567
The structure that defines a point.
Definition: SDL_rect.h:48
int x
Definition: SDL_rect.h:50
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1567
int y
Definition: SDL_rect.h:51
int SDL_RenderDrawPoints(SDL_Renderer *renderer, const SDL_Point *points, int count)
Draw multiple points on the current rendering target.
Definition: SDL_render.c:1447

◆ SDL_RenderDrawPoints()

int SDL_RenderDrawPoints ( SDL_Renderer renderer,
const SDL_Point points,
int  count 
)

Draw multiple points on the current rendering target.

Parameters
rendererThe renderer which should draw multiple points.
pointsThe points to draw
countThe number of points to draw
Returns
0 on success, or -1 on error

Definition at line 1447 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::hidden, i, SDL_Renderer::RenderDrawPoints, RenderDrawPointsWithRects(), SDL_Renderer::scale, SDL_OutOfMemory, SDL_SetError, SDL_stack_alloc, SDL_stack_free, SDL_FPoint::x, SDL_Point::x, SDL_FPoint::y, and SDL_Point::y.

Referenced by SDL_RenderDrawPoint().

1449 {
1450  SDL_FPoint *fpoints;
1451  int i;
1452  int status;
1453 
1454  CHECK_RENDERER_MAGIC(renderer, -1);
1455 
1456  if (!points) {
1457  return SDL_SetError("SDL_RenderDrawPoints(): Passed NULL points");
1458  }
1459  if (count < 1) {
1460  return 0;
1461  }
1462 
1463  /* Don't draw while we're hidden */
1464  if (renderer->hidden) {
1465  return 0;
1466  }
1467 
1468  if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) {
1469  return RenderDrawPointsWithRects(renderer, points, count);
1470  }
1471 
1472  fpoints = SDL_stack_alloc(SDL_FPoint, count);
1473  if (!fpoints) {
1474  return SDL_OutOfMemory();
1475  }
1476  for (i = 0; i < count; ++i) {
1477  fpoints[i].x = points[i].x * renderer->scale.x;
1478  fpoints[i].y = points[i].y * renderer->scale.y;
1479  }
1480 
1481  status = renderer->RenderDrawPoints(renderer, fpoints, count);
1482 
1483  SDL_stack_free(fpoints);
1484 
1485  return status;
1486 }
int(* RenderDrawPoints)(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1564
SDL_bool hidden
SDL_FPoint scale
static int RenderDrawPointsWithRects(SDL_Renderer *renderer, const SDL_Point *points, int count)
Definition: SDL_render.c:1421
int x
Definition: SDL_rect.h:50
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
int y
Definition: SDL_rect.h:51
#define SDL_stack_alloc(type, count)
Definition: SDL_stdinc.h:330
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
#define SDL_SetError
#define SDL_stack_free(data)
Definition: SDL_stdinc.h:331

◆ SDL_RenderDrawRect()

int SDL_RenderDrawRect ( SDL_Renderer renderer,
const SDL_Rect rect 
)

Draw a rectangle on the current rendering target.

Parameters
rendererThe renderer which should draw a rectangle.
rectA pointer to the destination rectangle, or NULL to outline the entire rendering target.
Returns
0 on success, or -1 on error

Definition at line 1599 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Rect::h, SDL_RenderDrawLines(), SDL_RenderGetViewport(), SDL_Rect::w, SDL_Point::x, SDL_Rect::x, SDL_Point::y, and SDL_Rect::y.

Referenced by SDL_RenderDrawRects().

1600 {
1601  SDL_Rect full_rect;
1602  SDL_Point points[5];
1603 
1604  CHECK_RENDERER_MAGIC(renderer, -1);
1605 
1606  /* If 'rect' == NULL, then outline the whole surface */
1607  if (!rect) {
1608  SDL_RenderGetViewport(renderer, &full_rect);
1609  full_rect.x = 0;
1610  full_rect.y = 0;
1611  rect = &full_rect;
1612  }
1613 
1614  points[0].x = rect->x;
1615  points[0].y = rect->y;
1616  points[1].x = rect->x+rect->w-1;
1617  points[1].y = rect->y;
1618  points[2].x = rect->x+rect->w-1;
1619  points[2].y = rect->y+rect->h-1;
1620  points[3].x = rect->x;
1621  points[3].y = rect->y+rect->h-1;
1622  points[4].x = rect->x;
1623  points[4].y = rect->y;
1624  return SDL_RenderDrawLines(renderer, points, 5);
1625 }
The structure that defines a point.
Definition: SDL_rect.h:48
GLfixed GLfixed GLint GLint GLfixed points
int x
Definition: SDL_rect.h:50
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
int y
Definition: SDL_rect.h:51
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
int SDL_RenderDrawLines(SDL_Renderer *renderer, const SDL_Point *points, int count)
Draw a series of connected lines on the current rendering target.
Definition: SDL_render.c:1557
int h
Definition: SDL_rect.h:67
void SDL_RenderGetViewport(SDL_Renderer *renderer, SDL_Rect *rect)
Get the drawing area for the current target.
Definition: SDL_render.c:1273
int y
Definition: SDL_rect.h:66
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

◆ SDL_RenderDrawRects()

int SDL_RenderDrawRects ( SDL_Renderer renderer,
const SDL_Rect rects,
int  count 
)

Draw some number of rectangles on the current rendering target.

Parameters
rendererThe renderer which should draw multiple rectangles.
rectsA pointer to an array of destination rectangles.
countThe number of rectangles.
Returns
0 on success, or -1 on error

Definition at line 1628 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::hidden, i, SDL_RenderDrawRect(), and SDL_SetError.

1630 {
1631  int i;
1632 
1633  CHECK_RENDERER_MAGIC(renderer, -1);
1634 
1635  if (!rects) {
1636  return SDL_SetError("SDL_RenderDrawRects(): Passed NULL rects");
1637  }
1638  if (count < 1) {
1639  return 0;
1640  }
1641 
1642  /* Don't draw while we're hidden */
1643  if (renderer->hidden) {
1644  return 0;
1645  }
1646 
1647  for (i = 0; i < count; ++i) {
1648  if (SDL_RenderDrawRect(renderer, &rects[i]) < 0) {
1649  return -1;
1650  }
1651  }
1652  return 0;
1653 }
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1564
SDL_bool hidden
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
int SDL_RenderDrawRect(SDL_Renderer *renderer, const SDL_Rect *rect)
Draw a rectangle on the current rendering target.
Definition: SDL_render.c:1599
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define SDL_SetError

◆ SDL_RendererEventWatch()

static int SDL_RendererEventWatch ( void userdata,
SDL_Event event 
)
static

Definition at line 106 of file SDL_render.c.

References SDL_Event::button, SDL_WindowEvent::event, SDL_Renderer::GetOutputSize, SDL_Rect::h, SDL_Renderer::hidden, SDL_Renderer::logical_w, SDL_Event::motion, NULL, renderer, SDL_Renderer::scale, SDL_FALSE, SDL_GetRenderTarget(), SDL_GetWindowFlags, SDL_GetWindowFromID, SDL_GetWindowSize, SDL_max, SDL_min, SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONUP, SDL_MOUSEMOTION, SDL_SetRenderTarget(), SDL_TRUE, SDL_WINDOW_HIDDEN, SDL_WINDOW_MINIMIZED, SDL_WINDOWEVENT, SDL_WINDOWEVENT_HIDDEN, SDL_WINDOWEVENT_MAXIMIZED, SDL_WINDOWEVENT_MINIMIZED, SDL_WINDOWEVENT_RESTORED, SDL_WINDOWEVENT_SHOWN, SDL_WINDOWEVENT_SIZE_CHANGED, SDL_Renderer::target, SDL_Event::type, UpdateLogicalSize(), SDL_Renderer::UpdateViewport, SDL_Renderer::viewport, SDL_Renderer::viewport_backup, SDL_Rect::w, window, SDL_Renderer::window, SDL_Event::window, SDL_Renderer::WindowEvent, SDL_WindowEvent::windowID, SDL_MouseMotionEvent::windowID, SDL_MouseButtonEvent::windowID, SDL_FPoint::x, SDL_Rect::x, SDL_MouseMotionEvent::x, SDL_MouseButtonEvent::x, SDL_MouseMotionEvent::xrel, SDL_FPoint::y, SDL_Rect::y, SDL_MouseMotionEvent::y, SDL_MouseButtonEvent::y, and SDL_MouseMotionEvent::yrel.

Referenced by SDL_CreateRenderer(), and SDL_DestroyRenderer().

107 {
108  SDL_Renderer *renderer = (SDL_Renderer *)userdata;
109 
110  if (event->type == SDL_WINDOWEVENT) {
112  if (window == renderer->window) {
113  if (renderer->WindowEvent) {
114  renderer->WindowEvent(renderer, &event->window);
115  }
116 
117  if (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
118  /* Make sure we're operating on the default render target */
119  SDL_Texture *saved_target = SDL_GetRenderTarget(renderer);
120  if (saved_target) {
121  SDL_SetRenderTarget(renderer, NULL);
122  }
123 
124  if (renderer->logical_w) {
125  UpdateLogicalSize(renderer);
126  } else {
127  /* Window was resized, reset viewport */
128  int w, h;
129 
130  if (renderer->GetOutputSize) {
131  renderer->GetOutputSize(renderer, &w, &h);
132  } else {
133  SDL_GetWindowSize(renderer->window, &w, &h);
134  }
135 
136  if (renderer->target) {
137  renderer->viewport_backup.x = 0;
138  renderer->viewport_backup.y = 0;
139  renderer->viewport_backup.w = w;
140  renderer->viewport_backup.h = h;
141  } else {
142  renderer->viewport.x = 0;
143  renderer->viewport.y = 0;
144  renderer->viewport.w = w;
145  renderer->viewport.h = h;
146  renderer->UpdateViewport(renderer);
147  }
148  }
149 
150  if (saved_target) {
151  SDL_SetRenderTarget(renderer, saved_target);
152  }
153  } else if (event->window.event == SDL_WINDOWEVENT_HIDDEN) {
154  renderer->hidden = SDL_TRUE;
155  } else if (event->window.event == SDL_WINDOWEVENT_SHOWN) {
156  if (!(SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED)) {
157  renderer->hidden = SDL_FALSE;
158  }
159  } else if (event->window.event == SDL_WINDOWEVENT_MINIMIZED) {
160  renderer->hidden = SDL_TRUE;
161  } else if (event->window.event == SDL_WINDOWEVENT_RESTORED ||
163  if (!(SDL_GetWindowFlags(window) & SDL_WINDOW_HIDDEN)) {
164  renderer->hidden = SDL_FALSE;
165  }
166  }
167  }
168  } else if (event->type == SDL_MOUSEMOTION) {
169  SDL_Window *window = SDL_GetWindowFromID(event->motion.windowID);
170  if (renderer->logical_w && window == renderer->window) {
171  event->motion.x -= renderer->viewport.x;
172  event->motion.y -= renderer->viewport.y;
173  event->motion.x = (int)(event->motion.x / renderer->scale.x);
174  event->motion.y = (int)(event->motion.y / renderer->scale.y);
175  if (event->motion.xrel > 0) {
176  event->motion.xrel = SDL_max(1, (int)(event->motion.xrel / renderer->scale.x));
177  } else if (event->motion.xrel < 0) {
178  event->motion.xrel = SDL_min(-1, (int)(event->motion.xrel / renderer->scale.x));
179  }
180  if (event->motion.yrel > 0) {
181  event->motion.yrel = SDL_max(1, (int)(event->motion.yrel / renderer->scale.y));
182  } else if (event->motion.yrel < 0) {
183  event->motion.yrel = SDL_min(-1, (int)(event->motion.yrel / renderer->scale.y));
184  }
185  }
186  } else if (event->type == SDL_MOUSEBUTTONDOWN ||
187  event->type == SDL_MOUSEBUTTONUP) {
188  SDL_Window *window = SDL_GetWindowFromID(event->button.windowID);
189  if (renderer->logical_w && window == renderer->window) {
190  event->button.x -= renderer->viewport.x;
191  event->button.y -= renderer->viewport.y;
192  event->button.x = (int)(event->button.x / renderer->scale.x);
193  event->button.y = (int)(event->button.y / renderer->scale.y);
194  }
195  }
196  return 0;
197 }
SDL_MouseMotionEvent motion
Definition: SDL_events.h:533
#define SDL_min(x, y)
Definition: SDL_stdinc.h:351
static SDL_Window * window
SDL_bool hidden
SDL_Texture * SDL_GetRenderTarget(SDL_Renderer *renderer)
Get the current render target or NULL for the default render target.
Definition: SDL_render.c:1134
SDL_FPoint scale
#define SDL_GetWindowFlags
SDL_Window * window
#define SDL_max(x, y)
Definition: SDL_stdinc.h:352
int(* GetOutputSize)(SDL_Renderer *renderer, int *w, int *h)
Definition: SDL_sysrender.h:81
SDL_WindowEvent window
Definition: SDL_events.h:529
#define SDL_GetWindowSize
SDL_Texture * target
static SDL_Renderer * renderer
int x
Definition: SDL_rect.h:66
int(* UpdateViewport)(SDL_Renderer *renderer)
#define SDL_GetWindowFromID
int w
Definition: SDL_rect.h:67
static int UpdateLogicalSize(SDL_Renderer *renderer)
Definition: SDL_render.c:1140
#define NULL
Definition: begin_code.h:143
SDL_Rect viewport
int h
Definition: SDL_rect.h:67
The type used to identify a window.
Definition: SDL_sysvideo.h:71
void(* WindowEvent)(SDL_Renderer *renderer, const SDL_WindowEvent *event)
Definition: SDL_sysrender.h:80
SDL_MouseButtonEvent button
Definition: SDL_events.h:534
GLubyte GLubyte GLubyte GLubyte w
SDL_Rect viewport_backup
int SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
Set a texture as the current rendering target.
Definition: SDL_render.c:1063
int y
Definition: SDL_rect.h:66
GLfloat GLfloat GLfloat GLfloat h
Uint32 type
Definition: SDL_events.h:527

◆ SDL_RenderFillRect()

int SDL_RenderFillRect ( SDL_Renderer renderer,
const SDL_Rect rect 
)

Fill a rectangle on the current rendering target with the drawing color.

Parameters
rendererThe renderer which should fill a rectangle.
rectA pointer to the destination rectangle, or NULL for the entire rendering target.
Returns
0 on success, or -1 on error

Definition at line 1656 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_RenderFillRects(), SDL_RenderGetViewport(), SDL_Rect::x, and SDL_Rect::y.

1657 {
1658  SDL_Rect full_rect = { 0, 0, 0, 0 };
1659 
1660  CHECK_RENDERER_MAGIC(renderer, -1);
1661 
1662  /* If 'rect' == NULL, then outline the whole surface */
1663  if (!rect) {
1664  SDL_RenderGetViewport(renderer, &full_rect);
1665  full_rect.x = 0;
1666  full_rect.y = 0;
1667  rect = &full_rect;
1668  }
1669  return SDL_RenderFillRects(renderer, rect, 1);
1670 }
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
int x
Definition: SDL_rect.h:66
int SDL_RenderFillRects(SDL_Renderer *renderer, const SDL_Rect *rects, int count)
Fill some number of rectangles on the current rendering target with the drawing color.
Definition: SDL_render.c:1673
void SDL_RenderGetViewport(SDL_Renderer *renderer, SDL_Rect *rect)
Get the drawing area for the current target.
Definition: SDL_render.c:1273
int y
Definition: SDL_rect.h:66
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

◆ SDL_RenderFillRects()

int SDL_RenderFillRects ( SDL_Renderer renderer,
const SDL_Rect rects,
int  count 
)

Fill some number of rectangles on the current rendering target with the drawing color.

Parameters
rendererThe renderer which should fill multiple rectangles.
rectsA pointer to an array of destination rectangles.
countThe number of rectangles.
Returns
0 on success, or -1 on error

Definition at line 1673 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_FRect::h, SDL_Rect::h, SDL_Renderer::hidden, i, SDL_Renderer::RenderFillRects, SDL_Renderer::scale, SDL_OutOfMemory, SDL_SetError, SDL_stack_alloc, SDL_stack_free, SDL_FRect::w, SDL_Rect::w, SDL_FPoint::x, SDL_FRect::x, SDL_Rect::x, SDL_FPoint::y, SDL_FRect::y, and SDL_Rect::y.

Referenced by SDL_RenderFillRect().

1675 {
1676  SDL_FRect *frects;
1677  int i;
1678  int status;
1679 
1680  CHECK_RENDERER_MAGIC(renderer, -1);
1681 
1682  if (!rects) {
1683  return SDL_SetError("SDL_RenderFillRects(): Passed NULL rects");
1684  }
1685  if (count < 1) {
1686  return 0;
1687  }
1688 
1689  /* Don't draw while we're hidden */
1690  if (renderer->hidden) {
1691  return 0;
1692  }
1693 
1694  frects = SDL_stack_alloc(SDL_FRect, count);
1695  if (!frects) {
1696  return SDL_OutOfMemory();
1697  }
1698  for (i = 0; i < count; ++i) {
1699  frects[i].x = rects[i].x * renderer->scale.x;
1700  frects[i].y = rects[i].y * renderer->scale.y;
1701  frects[i].w = rects[i].w * renderer->scale.x;
1702  frects[i].h = rects[i].h * renderer->scale.y;
1703  }
1704 
1705  status = renderer->RenderFillRects(renderer, frects, count);
1706 
1707  SDL_stack_free(frects);
1708 
1709  return status;
1710 }
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1564
SDL_bool hidden
SDL_FPoint scale
int(* RenderFillRects)(SDL_Renderer *renderer, const SDL_FRect *rects, int count)
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
#define SDL_stack_alloc(type, count)
Definition: SDL_stdinc.h:330
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
#define SDL_SetError
int h
Definition: SDL_rect.h:67
#define SDL_stack_free(data)
Definition: SDL_stdinc.h:331
int y
Definition: SDL_rect.h:66

◆ SDL_RenderGetClipRect()

void SDL_RenderGetClipRect ( SDL_Renderer renderer,
SDL_Rect rect 
)

Get the clip rectangle for the current target.

Parameters
rendererThe renderer from which clip rectangle should be queried.
rectA pointer filled in with the current clip rectangle, or an empty rectangle if clipping is disabled.
See also
SDL_RenderSetClipRect()

Definition at line 1304 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::clip_rect, SDL_Rect::h, SDL_Renderer::scale, SDL_Rect::w, SDL_FPoint::x, SDL_Rect::x, SDL_FPoint::y, and SDL_Rect::y.

1305 {
1306  CHECK_RENDERER_MAGIC(renderer, )
1307 
1308  if (rect) {
1309  rect->x = (int)(renderer->clip_rect.x / renderer->scale.x);
1310  rect->y = (int)(renderer->clip_rect.y / renderer->scale.y);
1311  rect->w = (int)(renderer->clip_rect.w / renderer->scale.x);
1312  rect->h = (int)(renderer->clip_rect.h / renderer->scale.y);
1313  }
1314 }
SDL_FPoint scale
SDL_Rect clip_rect
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
int h
Definition: SDL_rect.h:67
int y
Definition: SDL_rect.h:66

◆ SDL_RenderGetIntegerScale()

SDL_bool SDL_RenderGetIntegerScale ( SDL_Renderer renderer)

Get whether integer scales are forced for resolution-independent rendering.

Parameters
rendererThe renderer from which integer scaling should be queried.
See also
SDL_RenderSetIntegerScale()

Definition at line 1245 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::integer_scale, and SDL_FALSE.

1246 {
1247  CHECK_RENDERER_MAGIC(renderer, SDL_FALSE);
1248 
1249  return renderer->integer_scale;
1250 }
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
SDL_bool integer_scale

◆ SDL_RenderGetLogicalSize()

void SDL_RenderGetLogicalSize ( SDL_Renderer renderer,
int *  w,
int *  h 
)

Get device independent resolution for rendering.

Parameters
rendererThe renderer from which resolution should be queried.
wA pointer filled with the width of the logical resolution
hA pointer filled with the height of the logical resolution
See also
SDL_RenderSetLogicalSize()

Definition at line 1222 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::logical_h, and SDL_Renderer::logical_w.

1223 {
1224  CHECK_RENDERER_MAGIC(renderer, );
1225 
1226  if (w) {
1227  *w = renderer->logical_w;
1228  }
1229  if (h) {
1230  *h = renderer->logical_h;
1231  }
1232 }
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
GLubyte GLubyte GLubyte GLubyte w
GLfloat GLfloat GLfloat GLfloat h

◆ SDL_RenderGetScale()

void SDL_RenderGetScale ( SDL_Renderer renderer,
float *  scaleX,
float *  scaleY 
)

Get the drawing scale for the current target.

Parameters
rendererThe renderer from which drawing scale should be queried.
scaleXA pointer filled in with the horizontal scaling factor
scaleYA pointer filled in with the vertical scaling factor
See also
SDL_RenderSetScale()

Definition at line 1334 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::scale, SDL_FPoint::x, and SDL_FPoint::y.

1335 {
1336  CHECK_RENDERER_MAGIC(renderer, );
1337 
1338  if (scaleX) {
1339  *scaleX = renderer->scale.x;
1340  }
1341  if (scaleY) {
1342  *scaleY = renderer->scale.y;
1343  }
1344 }
SDL_FPoint scale
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35

◆ SDL_RenderGetViewport()

void SDL_RenderGetViewport ( SDL_Renderer renderer,
SDL_Rect rect 
)

Get the drawing area for the current target.

See also
SDL_RenderSetViewport()

Definition at line 1273 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Rect::h, SDL_Renderer::scale, SDL_Renderer::viewport, SDL_Rect::w, SDL_FPoint::x, SDL_Rect::x, SDL_FPoint::y, and SDL_Rect::y.

Referenced by SDL_RenderCopy(), SDL_RenderCopyEx(), SDL_RenderDrawRect(), and SDL_RenderFillRect().

1274 {
1275  CHECK_RENDERER_MAGIC(renderer, );
1276 
1277  if (rect) {
1278  rect->x = (int)(renderer->viewport.x / renderer->scale.x);
1279  rect->y = (int)(renderer->viewport.y / renderer->scale.y);
1280  rect->w = (int)(renderer->viewport.w / renderer->scale.x);
1281  rect->h = (int)(renderer->viewport.h / renderer->scale.y);
1282  }
1283 }
SDL_FPoint scale
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
SDL_Rect viewport
int h
Definition: SDL_rect.h:67
int y
Definition: SDL_rect.h:66

◆ SDL_RenderIsClipEnabled()

SDL_bool SDL_RenderIsClipEnabled ( SDL_Renderer renderer)

Get whether clipping is enabled on the given renderer.

Parameters
rendererThe renderer from which clip state should be queried.
See also
SDL_RenderGetClipRect()

Definition at line 1317 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::clipping_enabled, and SDL_FALSE.

1318 {
1319  CHECK_RENDERER_MAGIC(renderer, SDL_FALSE)
1320  return renderer->clipping_enabled;
1321 }
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
SDL_bool clipping_enabled

◆ SDL_RenderPresent()

void SDL_RenderPresent ( SDL_Renderer renderer)

Update the screen with rendering performed.

Definition at line 1874 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::hidden, and SDL_Renderer::RenderPresent.

1875 {
1876  CHECK_RENDERER_MAGIC(renderer, );
1877 
1878  /* Don't draw while we're hidden */
1879  if (renderer->hidden) {
1880  return;
1881  }
1882  renderer->RenderPresent(renderer);
1883 }
SDL_bool hidden
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
void(* RenderPresent)(SDL_Renderer *renderer)

◆ SDL_RenderReadPixels()

int SDL_RenderReadPixels ( SDL_Renderer renderer,
const SDL_Rect rect,
Uint32  format,
void pixels,
int  pitch 
)

Read pixels from the current rendering target.

Parameters
rendererThe renderer from which pixels should be read.
rectA pointer to the rectangle to read, or NULL for the entire render target.
formatThe desired format of the pixel data, or 0 to use the format of the rendering target
pixelsA pointer to be filled in with the pixel data
pitchThe pitch of the pixels parameter.
Returns
0 on success, or -1 if pixel reading is not supported.
Warning
This is a very slow operation, and should not be used frequently.

Definition at line 1837 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Rect::h, SDL_Renderer::RenderReadPixels, SDL_BYTESPERPIXEL, SDL_GetWindowPixelFormat, SDL_IntersectRect, SDL_Unsupported, SDL_Renderer::viewport, SDL_Rect::w, SDL_Renderer::window, SDL_Rect::x, and SDL_Rect::y.

1839 {
1840  SDL_Rect real_rect;
1841 
1842  CHECK_RENDERER_MAGIC(renderer, -1);
1843 
1844  if (!renderer->RenderReadPixels) {
1845  return SDL_Unsupported();
1846  }
1847 
1848  if (!format) {
1849  format = SDL_GetWindowPixelFormat(renderer->window);
1850  }
1851 
1852  real_rect.x = renderer->viewport.x;
1853  real_rect.y = renderer->viewport.y;
1854  real_rect.w = renderer->viewport.w;
1855  real_rect.h = renderer->viewport.h;
1856  if (rect) {
1857  if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
1858  return 0;
1859  }
1860  if (real_rect.y > rect->y) {
1861  pixels = (Uint8 *)pixels + pitch * (real_rect.y - rect->y);
1862  }
1863  if (real_rect.x > rect->x) {
1864  int bpp = SDL_BYTESPERPIXEL(format);
1865  pixels = (Uint8 *)pixels + bpp * (real_rect.x - rect->x);
1866  }
1867  }
1868 
1869  return renderer->RenderReadPixels(renderer, &real_rect,
1870  format, pixels, pitch);
1871 }
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1565
int(* RenderReadPixels)(SDL_Renderer *renderer, const SDL_Rect *rect, Uint32 format, void *pixels, int pitch)
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:128
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1565
#define SDL_IntersectRect
SDL_Window * window
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:143
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
SDL_Rect viewport
int h
Definition: SDL_rect.h:67
#define SDL_GetWindowPixelFormat
int y
Definition: SDL_rect.h:66
#define SDL_Unsupported()
Definition: SDL_error.h:53
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

◆ SDL_RenderSetClipRect()

int SDL_RenderSetClipRect ( SDL_Renderer renderer,
const SDL_Rect rect 
)

Set the clip rectangle for the current target.

Parameters
rendererThe renderer for which clip rectangle should be set.
rectA pointer to the rectangle to set as the clip rectangle, or NULL to disable clipping.
Returns
0 on success, or -1 on error
See also
SDL_RenderGetClipRect()

Definition at line 1286 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::clip_rect, SDL_Renderer::clipping_enabled, SDL_Rect::h, SDL_Renderer::scale, SDL_ceil, SDL_FALSE, SDL_floor, SDL_TRUE, SDL_zero, SDL_Renderer::UpdateClipRect, SDL_Rect::w, SDL_FPoint::x, SDL_Rect::x, SDL_FPoint::y, and SDL_Rect::y.

1287 {
1288  CHECK_RENDERER_MAGIC(renderer, -1)
1289 
1290  if (rect) {
1291  renderer->clipping_enabled = SDL_TRUE;
1292  renderer->clip_rect.x = (int)SDL_floor(rect->x * renderer->scale.x);
1293  renderer->clip_rect.y = (int)SDL_floor(rect->y * renderer->scale.y);
1294  renderer->clip_rect.w = (int)SDL_ceil(rect->w * renderer->scale.x);
1295  renderer->clip_rect.h = (int)SDL_ceil(rect->h * renderer->scale.y);
1296  } else {
1297  renderer->clipping_enabled = SDL_FALSE;
1298  SDL_zero(renderer->clip_rect);
1299  }
1300  return renderer->UpdateClipRect(renderer);
1301 }
#define SDL_ceil
SDL_FPoint scale
SDL_Rect clip_rect
#define SDL_floor
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
#define SDL_zero(x)
Definition: SDL_stdinc.h:361
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
int h
Definition: SDL_rect.h:67
int(* UpdateClipRect)(SDL_Renderer *renderer)
int y
Definition: SDL_rect.h:66
SDL_bool clipping_enabled

◆ SDL_RenderSetIntegerScale()

int SDL_RenderSetIntegerScale ( SDL_Renderer renderer,
SDL_bool  enable 
)

Set whether to force integer scales for resolution-independent rendering.

Parameters
rendererThe renderer for which integer scaling should be set.
enableEnable or disable integer scaling

This function restricts the logical viewport to integer values - that is, when a resolution is between two multiples of a logical size, the viewport size is rounded down to the lower multiple.

See also
SDL_RenderSetLogicalSize()

Definition at line 1235 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::integer_scale, and UpdateLogicalSize().

1236 {
1237  CHECK_RENDERER_MAGIC(renderer, -1);
1238 
1239  renderer->integer_scale = enable;
1240 
1241  return UpdateLogicalSize(renderer);
1242 }
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
static int UpdateLogicalSize(SDL_Renderer *renderer)
Definition: SDL_render.c:1140
GLboolean enable
SDL_bool integer_scale

◆ SDL_RenderSetLogicalSize()

int SDL_RenderSetLogicalSize ( SDL_Renderer renderer,
int  w,
int  h 
)

Set device independent resolution for rendering.

Parameters
rendererThe renderer for which resolution should be set.
wThe width of the logical resolution
hThe height of the logical resolution

This function uses the viewport and scaling functionality to allow a fixed logical resolution for rendering, regardless of the actual output resolution. If the actual output resolution doesn't have the same aspect ratio the output rendering will be centered within the output display.

If the output display is a window, mouse events in the window will be filtered and scaled so they seem to arrive within the logical resolution.

Note
If this function results in scaling or subpixel drawing by the rendering backend, it will be handled using the appropriate quality hints.
See also
SDL_RenderGetLogicalSize()
SDL_RenderSetScale()
SDL_RenderSetViewport()

Definition at line 1202 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::logical_h, SDL_Renderer::logical_w, NULL, SDL_RenderSetScale(), SDL_RenderSetViewport(), and UpdateLogicalSize().

1203 {
1204  CHECK_RENDERER_MAGIC(renderer, -1);
1205 
1206  if (!w || !h) {
1207  /* Clear any previous logical resolution */
1208  renderer->logical_w = 0;
1209  renderer->logical_h = 0;
1210  SDL_RenderSetViewport(renderer, NULL);
1211  SDL_RenderSetScale(renderer, 1.0f, 1.0f);
1212  return 0;
1213  }
1214 
1215  renderer->logical_w = w;
1216  renderer->logical_h = h;
1217 
1218  return UpdateLogicalSize(renderer);
1219 }
GLfloat f
int SDL_RenderSetViewport(SDL_Renderer *renderer, const SDL_Rect *rect)
Set the drawing area for rendering on the current target.
Definition: SDL_render.c:1253
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
static int UpdateLogicalSize(SDL_Renderer *renderer)
Definition: SDL_render.c:1140
int SDL_RenderSetScale(SDL_Renderer *renderer, float scaleX, float scaleY)
Set the drawing scale for rendering on the current target.
Definition: SDL_render.c:1324
#define NULL
Definition: begin_code.h:143
GLubyte GLubyte GLubyte GLubyte w
GLfloat GLfloat GLfloat GLfloat h

◆ SDL_RenderSetScale()

int SDL_RenderSetScale ( SDL_Renderer renderer,
float  scaleX,
float  scaleY 
)

Set the drawing scale for rendering on the current target.

Parameters
rendererThe renderer for which the drawing scale should be set.
scaleXThe horizontal scaling factor
scaleYThe vertical scaling factor

The drawing coordinates are scaled by the x/y scaling factors before they are used by the renderer. This allows resolution independent drawing with a single coordinate system.

Note
If this results in scaling or subpixel drawing by the rendering backend, it will be handled using the appropriate quality hints. For best results use integer scaling factors.
See also
SDL_RenderGetScale()
SDL_RenderSetLogicalSize()

Definition at line 1324 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::scale, SDL_FPoint::x, and SDL_FPoint::y.

Referenced by SDL_RenderSetLogicalSize(), and UpdateLogicalSize().

1325 {
1326  CHECK_RENDERER_MAGIC(renderer, -1);
1327 
1328  renderer->scale.x = scaleX;
1329  renderer->scale.y = scaleY;
1330  return 0;
1331 }
SDL_FPoint scale
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35

◆ SDL_RenderSetViewport()

int SDL_RenderSetViewport ( SDL_Renderer renderer,
const SDL_Rect rect 
)

Set the drawing area for rendering on the current target.

Parameters
rendererThe renderer for which the drawing area should be set.
rectThe rectangle representing the drawing area, or NULL to set the viewport to the entire target.

The x,y of the viewport rect represents the origin for rendering.

Returns
0 on success, or -1 on error
Note
If the window associated with the renderer is resized, the viewport is automatically reset.
See also
SDL_RenderGetViewport()
SDL_RenderSetLogicalSize()

Definition at line 1253 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Rect::h, SDL_Renderer::scale, SDL_ceil, SDL_floor, SDL_GetRendererOutputSize(), SDL_Renderer::UpdateViewport, SDL_Renderer::viewport, SDL_Rect::w, SDL_FPoint::x, SDL_Rect::x, SDL_FPoint::y, and SDL_Rect::y.

Referenced by SDL_CreateRenderer(), SDL_CreateSoftwareRenderer(), SDL_RenderSetLogicalSize(), and UpdateLogicalSize().

1254 {
1255  CHECK_RENDERER_MAGIC(renderer, -1);
1256 
1257  if (rect) {
1258  renderer->viewport.x = (int)SDL_floor(rect->x * renderer->scale.x);
1259  renderer->viewport.y = (int)SDL_floor(rect->y * renderer->scale.y);
1260  renderer->viewport.w = (int)SDL_ceil(rect->w * renderer->scale.x);
1261  renderer->viewport.h = (int)SDL_ceil(rect->h * renderer->scale.y);
1262  } else {
1263  renderer->viewport.x = 0;
1264  renderer->viewport.y = 0;
1265  if (SDL_GetRendererOutputSize(renderer, &renderer->viewport.w, &renderer->viewport.h) < 0) {
1266  return -1;
1267  }
1268  }
1269  return renderer->UpdateViewport(renderer);
1270 }
#define SDL_ceil
SDL_FPoint scale
#define SDL_floor
int SDL_GetRendererOutputSize(SDL_Renderer *renderer, int *w, int *h)
Get the output size in pixels of a rendering context.
Definition: SDL_render.c:353
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
int x
Definition: SDL_rect.h:66
int(* UpdateViewport)(SDL_Renderer *renderer)
int w
Definition: SDL_rect.h:67
SDL_Rect viewport
int h
Definition: SDL_rect.h:67
int y
Definition: SDL_rect.h:66

◆ SDL_RenderTargetSupported()

SDL_bool SDL_RenderTargetSupported ( SDL_Renderer renderer)

Determines whether a window supports the use of render targets.

Parameters
rendererThe renderer that will be checked
Returns
SDL_TRUE if supported, SDL_FALSE if not.

Definition at line 1054 of file SDL_render.c.

References SDL_RendererInfo::flags, SDL_Renderer::info, SDL_FALSE, SDL_RENDERER_TARGETTEXTURE, and SDL_Renderer::SetRenderTarget.

Referenced by SDL_SetRenderTarget().

1055 {
1056  if (!renderer || !renderer->SetRenderTarget) {
1057  return SDL_FALSE;
1058  }
1059  return (renderer->info.flags & SDL_RENDERER_TARGETTEXTURE) != 0;
1060 }
SDL_RendererInfo info
int(* SetRenderTarget)(SDL_Renderer *renderer, SDL_Texture *texture)

◆ SDL_SetRenderDrawBlendMode()

int SDL_SetRenderDrawBlendMode ( SDL_Renderer renderer,
SDL_BlendMode  blendMode 
)

Set the blend mode used for drawing operations (Fill and Line).

Parameters
rendererThe renderer for which blend mode should be set.
blendModeSDL_BlendMode to use for blending.
Returns
0 on success, or -1 on error
Note
If the blend mode is not supported, the closest supported mode is chosen.
See also
SDL_GetRenderDrawBlendMode()

Definition at line 1381 of file SDL_render.c.

References blendMode, SDL_Renderer::blendMode, and CHECK_RENDERER_MAGIC.

1382 {
1383  CHECK_RENDERER_MAGIC(renderer, -1);
1384 
1385  renderer->blendMode = blendMode;
1386  return 0;
1387 }
static SDL_BlendMode blendMode
Definition: testdraw2.c:34
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
SDL_BlendMode blendMode

◆ SDL_SetRenderDrawColor()

int SDL_SetRenderDrawColor ( SDL_Renderer renderer,
Uint8  r,
Uint8  g,
Uint8  b,
Uint8  a 
)

Set the color used for drawing operations (Rect, Line and Clear).

Parameters
rendererThe renderer for which drawing color should be set.
rThe red value used to draw on the rendering target.
gThe green value used to draw on the rendering target.
bThe blue value used to draw on the rendering target.
aThe alpha value used to draw on the rendering target, usually SDL_ALPHA_OPAQUE (255).
Returns
0 on success, or -1 on error

Definition at line 1347 of file SDL_render.c.

References SDL_Renderer::a, SDL_Renderer::b, CHECK_RENDERER_MAGIC, SDL_Renderer::g, and SDL_Renderer::r.

1349 {
1350  CHECK_RENDERER_MAGIC(renderer, -1);
1351 
1352  renderer->r = r;
1353  renderer->g = g;
1354  renderer->b = b;
1355  renderer->a = a;
1356  return 0;
1357 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2072
GLboolean GLboolean g
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean GLboolean b

◆ SDL_SetRenderTarget()

int SDL_SetRenderTarget ( SDL_Renderer renderer,
SDL_Texture texture 
)

Set a texture as the current rendering target.

Parameters
rendererThe renderer.
textureThe targeted texture, which must be created with the SDL_TEXTUREACCESS_TARGET flag, or NULL for the default render target
Returns
0 on success, or -1 on error
See also
SDL_GetRenderTarget()

Definition at line 1063 of file SDL_render.c.

References SDL_Texture::access, CHECK_TEXTURE_MAGIC, SDL_Renderer::clip_rect, SDL_Renderer::clip_rect_backup, SDL_Renderer::clipping_enabled, SDL_Renderer::clipping_enabled_backup, SDL_Texture::h, SDL_Rect::h, SDL_Renderer::logical_h, SDL_Renderer::logical_h_backup, SDL_Renderer::logical_w, SDL_Renderer::logical_w_backup, SDL_Texture::native, SDL_Texture::renderer, SDL_Renderer::scale, SDL_Renderer::scale_backup, SDL_FALSE, SDL_RenderTargetSupported(), SDL_SetError, SDL_TEXTUREACCESS_TARGET, SDL_Unsupported, SDL_zero, SDL_Renderer::SetRenderTarget, SDL_Renderer::target, SDL_Renderer::UpdateClipRect, SDL_Renderer::UpdateViewport, SDL_Renderer::viewport, SDL_Renderer::viewport_backup, SDL_Texture::w, SDL_Rect::w, SDL_FPoint::x, SDL_Rect::x, SDL_FPoint::y, and SDL_Rect::y.

Referenced by SDL_DestroyTexture(), and SDL_RendererEventWatch().

1064 {
1065  if (!SDL_RenderTargetSupported(renderer)) {
1066  return SDL_Unsupported();
1067  }
1068  if (texture == renderer->target) {
1069  /* Nothing to do! */
1070  return 0;
1071  }
1072 
1073  /* texture == NULL is valid and means reset the target to the window */
1074  if (texture) {
1075  CHECK_TEXTURE_MAGIC(texture, -1);
1076  if (renderer != texture->renderer) {
1077  return SDL_SetError("Texture was not created with this renderer");
1078  }
1079  if (texture->access != SDL_TEXTUREACCESS_TARGET) {
1080  return SDL_SetError("Texture not created with SDL_TEXTUREACCESS_TARGET");
1081  }
1082  if (texture->native) {
1083  /* Always render to the native texture */
1084  texture = texture->native;
1085  }
1086  }
1087 
1088  if (texture && !renderer->target) {
1089  /* Make a backup of the viewport */
1090  renderer->viewport_backup = renderer->viewport;
1091  renderer->clip_rect_backup = renderer->clip_rect;
1092  renderer->clipping_enabled_backup = renderer->clipping_enabled;
1093  renderer->scale_backup = renderer->scale;
1094  renderer->logical_w_backup = renderer->logical_w;
1095  renderer->logical_h_backup = renderer->logical_h;
1096  }
1097  renderer->target = texture;
1098 
1099  if (renderer->SetRenderTarget(renderer, texture) < 0) {
1100  return -1;
1101  }
1102 
1103  if (texture) {
1104  renderer->viewport.x = 0;
1105  renderer->viewport.y = 0;
1106  renderer->viewport.w = texture->w;
1107  renderer->viewport.h = texture->h;
1108  SDL_zero(renderer->clip_rect);
1109  renderer->clipping_enabled = SDL_FALSE;
1110  renderer->scale.x = 1.0f;
1111  renderer->scale.y = 1.0f;
1112  renderer->logical_w = texture->w;
1113  renderer->logical_h = texture->h;
1114  } else {
1115  renderer->viewport = renderer->viewport_backup;
1116  renderer->clip_rect = renderer->clip_rect_backup;
1117  renderer->clipping_enabled = renderer->clipping_enabled_backup;
1118  renderer->scale = renderer->scale_backup;
1119  renderer->logical_w = renderer->logical_w_backup;
1120  renderer->logical_h = renderer->logical_h_backup;
1121  }
1122  if (renderer->UpdateViewport(renderer) < 0) {
1123  return -1;
1124  }
1125  if (renderer->UpdateClipRect(renderer) < 0) {
1126  return -1;
1127  }
1128 
1129  /* All set! */
1130  return 0;
1131 }
SDL_Rect clip_rect_backup
GLenum GLenum GLuint texture
SDL_FPoint scale
SDL_Rect clip_rect
SDL_FPoint scale_backup
SDL_Texture * target
#define SDL_zero(x)
Definition: SDL_stdinc.h:361
int x
Definition: SDL_rect.h:66
int(* SetRenderTarget)(SDL_Renderer *renderer, SDL_Texture *texture)
int(* UpdateViewport)(SDL_Renderer *renderer)
int w
Definition: SDL_rect.h:67
SDL_bool SDL_RenderTargetSupported(SDL_Renderer *renderer)
Determines whether a window supports the use of render targets.
Definition: SDL_render.c:1054
#define SDL_SetError
SDL_Renderer * renderer
Definition: SDL_sysrender.h:60
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:41
SDL_Rect viewport
int h
Definition: SDL_rect.h:67
SDL_Texture * native
Definition: SDL_sysrender.h:63
SDL_Rect viewport_backup
int(* UpdateClipRect)(SDL_Renderer *renderer)
SDL_bool clipping_enabled_backup
int y
Definition: SDL_rect.h:66
#define SDL_Unsupported()
Definition: SDL_error.h:53
SDL_bool clipping_enabled

◆ SDL_SetTextureAlphaMod()

int SDL_SetTextureAlphaMod ( SDL_Texture texture,
Uint8  alpha 
)

Set an additional alpha value used in render copy operations.

Parameters
textureThe texture to update.
alphaThe alpha value multiplied into copy operations.
Returns
0 on success, or -1 if the texture is not valid or alpha modulation is not supported.
See also
SDL_GetTextureAlphaMod()

Definition at line 656 of file SDL_render.c.

References SDL_Texture::a, CHECK_TEXTURE_MAGIC, SDL_Texture::modMode, SDL_Texture::native, renderer, SDL_Texture::renderer, SDL_TEXTUREMODULATE_ALPHA, and SDL_Renderer::SetTextureAlphaMod.

Referenced by SDL_CreateTextureFromSurface().

657 {
659 
660  CHECK_TEXTURE_MAGIC(texture, -1);
661 
662  renderer = texture->renderer;
663  if (alpha < 255) {
665  } else {
666  texture->modMode &= ~SDL_TEXTUREMODULATE_ALPHA;
667  }
668  texture->a = alpha;
669  if (texture->native) {
670  return SDL_SetTextureAlphaMod(texture->native, alpha);
671  } else if (renderer->SetTextureAlphaMod) {
672  return renderer->SetTextureAlphaMod(renderer, texture);
673  } else {
674  return 0;
675  }
676 }
GLfloat GLfloat GLfloat alpha
static SDL_Renderer * renderer
int SDL_SetTextureAlphaMod(SDL_Texture *texture, Uint8 alpha)
Set an additional alpha value used in render copy operations.
Definition: SDL_render.c:656
SDL_Renderer * renderer
Definition: SDL_sysrender.h:60
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:41
int(* SetTextureAlphaMod)(SDL_Renderer *renderer, SDL_Texture *texture)
Definition: SDL_sysrender.h:85
SDL_Texture * native
Definition: SDL_sysrender.h:63

◆ SDL_SetTextureBlendMode()

int SDL_SetTextureBlendMode ( SDL_Texture texture,
SDL_BlendMode  blendMode 
)

Set the blend mode used for texture copy operations.

Parameters
textureThe texture to update.
blendModeSDL_BlendMode to use for texture blending.
Returns
0 on success, or -1 if the texture is not valid or the blend mode is not supported.
Note
If the blend mode is not supported, the closest supported mode is chosen.
See also
SDL_GetTextureBlendMode()

Definition at line 690 of file SDL_render.c.

References blendMode, SDL_Texture::blendMode, CHECK_TEXTURE_MAGIC, SDL_Texture::native, renderer, SDL_Texture::renderer, and SDL_Renderer::SetTextureBlendMode.

Referenced by SDL_CreateTextureFromSurface().

691 {
693 
694  CHECK_TEXTURE_MAGIC(texture, -1);
695 
696  renderer = texture->renderer;
697  texture->blendMode = blendMode;
698  if (texture->native) {
699  return SDL_SetTextureBlendMode(texture->native, blendMode);
700  } else if (renderer->SetTextureBlendMode) {
701  return renderer->SetTextureBlendMode(renderer, texture);
702  } else {
703  return 0;
704  }
705 }
SDL_BlendMode blendMode
Definition: SDL_sysrender.h:57
int(* SetTextureBlendMode)(SDL_Renderer *renderer, SDL_Texture *texture)
Definition: SDL_sysrender.h:87
static SDL_BlendMode blendMode
Definition: testdraw2.c:34
int SDL_SetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode blendMode)
Set the blend mode used for texture copy operations.
Definition: SDL_render.c:690
static SDL_Renderer * renderer
SDL_Renderer * renderer
Definition: SDL_sysrender.h:60
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:41
SDL_Texture * native
Definition: SDL_sysrender.h:63

◆ SDL_SetTextureColorMod()

int SDL_SetTextureColorMod ( SDL_Texture texture,
Uint8  r,
Uint8  g,
Uint8  b 
)

Set an additional color value used in render copy operations.

Parameters
textureThe texture to update.
rThe red color value multiplied into copy operations.
gThe green color value multiplied into copy operations.
bThe blue color value multiplied into copy operations.
Returns
0 on success, or -1 if the texture is not valid or color modulation is not supported.
See also
SDL_GetTextureColorMod()

Definition at line 613 of file SDL_render.c.

References SDL_Texture::b, CHECK_TEXTURE_MAGIC, SDL_Texture::g, SDL_Texture::modMode, SDL_Texture::native, SDL_Texture::r, renderer, SDL_Texture::renderer, SDL_TEXTUREMODULATE_COLOR, and SDL_Renderer::SetTextureColorMod.

Referenced by SDL_CreateTextureFromSurface().

614 {
616 
617  CHECK_TEXTURE_MAGIC(texture, -1);
618 
619  renderer = texture->renderer;
620  if (r < 255 || g < 255 || b < 255) {
622  } else {
623  texture->modMode &= ~SDL_TEXTUREMODULATE_COLOR;
624  }
625  texture->r = r;
626  texture->g = g;
627  texture->b = b;
628  if (texture->native) {
629  return SDL_SetTextureColorMod(texture->native, r, g, b);
630  } else if (renderer->SetTextureColorMod) {
631  return renderer->SetTextureColorMod(renderer, texture);
632  } else {
633  return 0;
634  }
635 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2072
GLboolean GLboolean g
int(* SetTextureColorMod)(SDL_Renderer *renderer, SDL_Texture *texture)
Definition: SDL_sysrender.h:83
static SDL_Renderer * renderer
SDL_Renderer * renderer
Definition: SDL_sysrender.h:60
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:41
int SDL_SetTextureColorMod(SDL_Texture *texture, Uint8 r, Uint8 g, Uint8 b)
Set an additional color value used in render copy operations.
Definition: SDL_render.c:613
SDL_Texture * native
Definition: SDL_sysrender.h:63
GLboolean GLboolean GLboolean b

◆ SDL_UnlockTexture()

void SDL_UnlockTexture ( SDL_Texture texture)

Unlock a texture, uploading the changes to video memory, if needed.

See also
SDL_LockTexture()

Definition at line 1034 of file SDL_render.c.

References SDL_Texture::access, CHECK_TEXTURE_MAGIC, SDL_Texture::native, renderer, SDL_Texture::renderer, SDL_TEXTUREACCESS_STREAMING, SDL_UnlockTextureNative(), SDL_UnlockTextureYUV(), SDL_Renderer::UnlockTexture, and SDL_Texture::yuv.

Referenced by SDL_UnlockTextureNative(), SDL_UnlockTextureYUV(), SDL_UpdateTextureNative(), SDL_UpdateTextureYUV(), and SDL_UpdateTextureYUVPlanar().

1035 {
1037 
1038  CHECK_TEXTURE_MAGIC(texture, );
1039 
1040  if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
1041  return;
1042  }
1043  if (texture->yuv) {
1044  SDL_UnlockTextureYUV(texture);
1045  } else if (texture->native) {
1046  SDL_UnlockTextureNative(texture);
1047  } else {
1048  renderer = texture->renderer;
1049  renderer->UnlockTexture(renderer, texture);
1050  }
1051 }
static void SDL_UnlockTextureNative(SDL_Texture *texture)
Definition: SDL_render.c:1013
static SDL_Renderer * renderer
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:64
void(* UnlockTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
Definition: SDL_sysrender.h:99
SDL_Renderer * renderer
Definition: SDL_sysrender.h:60
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:41
SDL_Texture * native
Definition: SDL_sysrender.h:63
static void SDL_UnlockTextureYUV(SDL_Texture *texture)
Definition: SDL_render.c:992

◆ SDL_UnlockTextureNative()

static void SDL_UnlockTextureNative ( SDL_Texture texture)
static

Definition at line 1013 of file SDL_render.c.

References SDL_Texture::format, SDL_Rect::h, SDL_Texture::locked_rect, SDL_Texture::native, NULL, SDL_Texture::pitch, SDL_Texture::pixels, rect, SDL_BYTESPERPIXEL, SDL_ConvertPixels, SDL_LockTexture(), SDL_UnlockTexture(), SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

Referenced by SDL_UnlockTexture().

1014 {
1015  SDL_Texture *native = texture->native;
1016  void *native_pixels = NULL;
1017  int native_pitch = 0;
1018  const SDL_Rect *rect = &texture->locked_rect;
1019  const void* pixels = (void *) ((Uint8 *) texture->pixels +
1020  rect->y * texture->pitch +
1021  rect->x * SDL_BYTESPERPIXEL(texture->format));
1022  int pitch = texture->pitch;
1023 
1024  if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) {
1025  return;
1026  }
1027  SDL_ConvertPixels(rect->w, rect->h,
1028  texture->format, pixels, pitch,
1029  native->format, native_pixels, native_pitch);
1030  SDL_UnlockTexture(native);
1031 }
void * pixels
Definition: SDL_sysrender.h:65
SDL_Rect rect
Definition: testrelative.c:27
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:128
SDL_Rect locked_rect
Definition: SDL_sysrender.h:67
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1565
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:143
void SDL_UnlockTexture(SDL_Texture *texture)
Unlock a texture, uploading the changes to video memory, if needed.
Definition: SDL_render.c:1034
int SDL_LockTexture(SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
Lock a portion of the texture for write-only pixel access.
Definition: SDL_render.c:961
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
#define NULL
Definition: begin_code.h:143
int h
Definition: SDL_rect.h:67
Uint32 format
Definition: SDL_sysrender.h:52
#define SDL_ConvertPixels
SDL_Texture * native
Definition: SDL_sysrender.h:63
int y
Definition: SDL_rect.h:66
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

◆ SDL_UnlockTextureYUV()

static void SDL_UnlockTextureYUV ( SDL_Texture texture)
static

Definition at line 992 of file SDL_render.c.

References SDL_Texture::format, SDL_Texture::h, SDL_Rect::h, SDL_Texture::native, NULL, rect, SDL_LockTexture(), SDL_SW_CopyYUVToRGB(), SDL_UnlockTexture(), SDL_Texture::w, SDL_Rect::w, SDL_Rect::x, SDL_Rect::y, and SDL_Texture::yuv.

Referenced by SDL_UnlockTexture().

993 {
994  SDL_Texture *native = texture->native;
995  void *native_pixels = NULL;
996  int native_pitch = 0;
997  SDL_Rect rect;
998 
999  rect.x = 0;
1000  rect.y = 0;
1001  rect.w = texture->w;
1002  rect.h = texture->h;
1003 
1004  if (SDL_LockTexture(native, &rect, &native_pixels, &native_pitch) < 0) {
1005  return;
1006  }
1007  SDL_SW_CopyYUVToRGB(texture->yuv, &rect, native->format,
1008  rect.w, rect.h, native_pixels, native_pitch);
1009  SDL_UnlockTexture(native);
1010 }
SDL_Rect rect
Definition: testrelative.c:27
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:64
void SDL_UnlockTexture(SDL_Texture *texture)
Unlock a texture, uploading the changes to video memory, if needed.
Definition: SDL_render.c:1034
int SDL_LockTexture(SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
Lock a portion of the texture for write-only pixel access.
Definition: SDL_render.c:961
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
#define NULL
Definition: begin_code.h:143
int h
Definition: SDL_rect.h:67
int SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture *swdata, const SDL_Rect *srcrect, Uint32 target_format, int w, int h, void *pixels, int pitch)
Definition: SDL_yuv_sw.c:1273
Uint32 format
Definition: SDL_sysrender.h:52
SDL_Texture * native
Definition: SDL_sysrender.h:63
int y
Definition: SDL_rect.h:66
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

◆ SDL_UpdateTexture()

int SDL_UpdateTexture ( SDL_Texture texture,
const SDL_Rect rect,
const void pixels,
int  pitch 
)

Update the given texture rectangle with new pixel data.

Parameters
textureThe texture to update
rectA pointer to the rectangle of pixels to update, or NULL to update the entire texture.
pixelsThe raw pixel data.
pitchThe number of bytes in a row of pixel data, including padding between lines.
Returns
0 on success, or -1 if the texture is not valid.
Note
This is a fairly slow function.

Definition at line 802 of file SDL_render.c.

References CHECK_TEXTURE_MAGIC, SDL_Texture::h, SDL_Rect::h, SDL_Texture::native, renderer, SDL_Texture::renderer, SDL_InvalidParamError, SDL_UpdateTextureNative(), SDL_UpdateTextureYUV(), SDL_Renderer::UpdateTexture, SDL_Texture::w, SDL_Rect::w, SDL_Rect::x, SDL_Rect::y, and SDL_Texture::yuv.

Referenced by SDL_CreateTextureFromSurface(), SDL_UpdateTextureNative(), SDL_UpdateTextureYUV(), and SDL_UpdateTextureYUVPlanar().

804 {
806  SDL_Rect full_rect;
807 
808  CHECK_TEXTURE_MAGIC(texture, -1);
809 
810  if (!pixels) {
811  return SDL_InvalidParamError("pixels");
812  }
813  if (!pitch) {
814  return SDL_InvalidParamError("pitch");
815  }
816 
817  if (!rect) {
818  full_rect.x = 0;
819  full_rect.y = 0;
820  full_rect.w = texture->w;
821  full_rect.h = texture->h;
822  rect = &full_rect;
823  }
824 
825  if ((rect->w == 0) || (rect->h == 0)) {
826  return 0; /* nothing to do. */
827  } else if (texture->yuv) {
828  return SDL_UpdateTextureYUV(texture, rect, pixels, pitch);
829  } else if (texture->native) {
830  return SDL_UpdateTextureNative(texture, rect, pixels, pitch);
831  } else {
832  renderer = texture->renderer;
833  return renderer->UpdateTexture(renderer, texture, rect, pixels, pitch);
834  }
835 }
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1565
static int SDL_UpdateTextureNative(SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
Definition: SDL_render.c:765
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
int(* UpdateTexture)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
Definition: SDL_sysrender.h:89
static SDL_Renderer * renderer
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:64
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
static int SDL_UpdateTextureYUV(SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
Definition: SDL_render.c:719
SDL_Renderer * renderer
Definition: SDL_sysrender.h:60
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:41
int h
Definition: SDL_rect.h:67
SDL_Texture * native
Definition: SDL_sysrender.h:63
int y
Definition: SDL_rect.h:66
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

◆ SDL_UpdateTextureNative()

static int SDL_UpdateTextureNative ( SDL_Texture texture,
const SDL_Rect rect,
const void pixels,
int  pitch 
)
static

Definition at line 765 of file SDL_render.c.

References SDL_Texture::access, SDL_Texture::format, SDL_Rect::h, SDL_Texture::native, SDL_BYTESPERPIXEL, SDL_ConvertPixels, SDL_free(), SDL_LockTexture(), SDL_malloc, SDL_OutOfMemory, SDL_TEXTUREACCESS_STREAMING, SDL_UnlockTexture(), SDL_UpdateTexture(), and SDL_Rect::w.

Referenced by SDL_UpdateTexture().

767 {
768  SDL_Texture *native = texture->native;
769 
770  if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
771  /* We can lock the texture and copy to it */
772  void *native_pixels;
773  int native_pitch;
774 
775  if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) {
776  return -1;
777  }
778  SDL_ConvertPixels(rect->w, rect->h,
779  texture->format, pixels, pitch,
780  native->format, native_pixels, native_pitch);
781  SDL_UnlockTexture(native);
782  } else {
783  /* Use a temporary buffer for updating */
784  void *temp_pixels;
785  int temp_pitch;
786 
787  temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3);
788  temp_pixels = SDL_malloc(rect->h * temp_pitch);
789  if (!temp_pixels) {
790  return SDL_OutOfMemory();
791  }
792  SDL_ConvertPixels(rect->w, rect->h,
793  texture->format, pixels, pitch,
794  native->format, temp_pixels, temp_pitch);
795  SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch);
796  SDL_free(temp_pixels);
797  }
798  return 0;
799 }
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:128
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1565
void SDL_UnlockTexture(SDL_Texture *texture)
Unlock a texture, uploading the changes to video memory, if needed.
Definition: SDL_render.c:1034
void SDL_free(void *mem)
int SDL_LockTexture(SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
Lock a portion of the texture for write-only pixel access.
Definition: SDL_render.c:961
int w
Definition: SDL_rect.h:67
int SDL_UpdateTexture(SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
Update the given texture rectangle with new pixel data.
Definition: SDL_render.c:802
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
int h
Definition: SDL_rect.h:67
Uint32 format
Definition: SDL_sysrender.h:52
#define SDL_malloc
#define SDL_ConvertPixels
SDL_Texture * native
Definition: SDL_sysrender.h:63

◆ SDL_UpdateTextureYUV()

static int SDL_UpdateTextureYUV ( SDL_Texture texture,
const SDL_Rect rect,
const void pixels,
int  pitch 
)
static

Definition at line 719 of file SDL_render.c.

References SDL_Texture::access, SDL_Texture::format, SDL_Texture::h, SDL_Rect::h, SDL_Texture::native, SDL_BYTESPERPIXEL, SDL_free(), SDL_LockTexture(), SDL_malloc, SDL_OutOfMemory, SDL_SW_CopyYUVToRGB(), SDL_SW_UpdateYUVTexture(), SDL_TEXTUREACCESS_STREAMING, SDL_UnlockTexture(), SDL_UpdateTexture(), SDL_Texture::w, SDL_Rect::w, SDL_Rect::x, SDL_Rect::y, and SDL_Texture::yuv.

Referenced by SDL_UpdateTexture().

721 {
722  SDL_Texture *native = texture->native;
723  SDL_Rect full_rect;
724 
725  if (SDL_SW_UpdateYUVTexture(texture->yuv, rect, pixels, pitch) < 0) {
726  return -1;
727  }
728 
729  full_rect.x = 0;
730  full_rect.y = 0;
731  full_rect.w = texture->w;
732  full_rect.h = texture->h;
733  rect = &full_rect;
734 
735  if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
736  /* We can lock the texture and copy to it */
737  void *native_pixels;
738  int native_pitch;
739 
740  if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) {
741  return -1;
742  }
743  SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format,
744  rect->w, rect->h, native_pixels, native_pitch);
745  SDL_UnlockTexture(native);
746  } else {
747  /* Use a temporary buffer for updating */
748  void *temp_pixels;
749  int temp_pitch;
750 
751  temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3);
752  temp_pixels = SDL_malloc(rect->h * temp_pitch);
753  if (!temp_pixels) {
754  return SDL_OutOfMemory();
755  }
756  SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format,
757  rect->w, rect->h, temp_pixels, temp_pitch);
758  SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch);
759  SDL_free(temp_pixels);
760  }
761  return 0;
762 }
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:128
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1565
int SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect, const void *pixels, int pitch)
Definition: SDL_yuv_sw.c:1114
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:64
void SDL_UnlockTexture(SDL_Texture *texture)
Unlock a texture, uploading the changes to video memory, if needed.
Definition: SDL_render.c:1034
void SDL_free(void *mem)
int SDL_LockTexture(SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
Lock a portion of the texture for write-only pixel access.
Definition: SDL_render.c:961
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
int SDL_UpdateTexture(SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
Update the given texture rectangle with new pixel data.
Definition: SDL_render.c:802
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
int h
Definition: SDL_rect.h:67
int SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture *swdata, const SDL_Rect *srcrect, Uint32 target_format, int w, int h, void *pixels, int pitch)
Definition: SDL_yuv_sw.c:1273
Uint32 format
Definition: SDL_sysrender.h:52
#define SDL_malloc
SDL_Texture * native
Definition: SDL_sysrender.h:63
int y
Definition: SDL_rect.h:66
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

◆ SDL_UpdateTextureYUVPlanar()

static int SDL_UpdateTextureYUVPlanar ( SDL_Texture texture,
const SDL_Rect rect,
const Uint8 Yplane,
int  Ypitch,
const Uint8 Uplane,
int  Upitch,
const Uint8 Vplane,
int  Vpitch 
)
static

Definition at line 838 of file SDL_render.c.

References SDL_Texture::access, SDL_Texture::format, SDL_Texture::h, SDL_Rect::h, SDL_Texture::native, SDL_BYTESPERPIXEL, SDL_free(), SDL_LockTexture(), SDL_malloc, SDL_OutOfMemory, SDL_SW_CopyYUVToRGB(), SDL_SW_UpdateYUVTexturePlanar(), SDL_TEXTUREACCESS_STREAMING, SDL_UnlockTexture(), SDL_UpdateTexture(), SDL_Texture::w, SDL_Rect::w, SDL_Rect::x, SDL_Rect::y, and SDL_Texture::yuv.

Referenced by SDL_UpdateYUVTexture().

842 {
843  SDL_Texture *native = texture->native;
844  SDL_Rect full_rect;
845 
846  if (SDL_SW_UpdateYUVTexturePlanar(texture->yuv, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch) < 0) {
847  return -1;
848  }
849 
850  full_rect.x = 0;
851  full_rect.y = 0;
852  full_rect.w = texture->w;
853  full_rect.h = texture->h;
854  rect = &full_rect;
855 
856  if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
857  /* We can lock the texture and copy to it */
858  void *native_pixels;
859  int native_pitch;
860 
861  if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) {
862  return -1;
863  }
864  SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format,
865  rect->w, rect->h, native_pixels, native_pitch);
866  SDL_UnlockTexture(native);
867  } else {
868  /* Use a temporary buffer for updating */
869  void *temp_pixels;
870  int temp_pitch;
871 
872  temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3);
873  temp_pixels = SDL_malloc(rect->h * temp_pitch);
874  if (!temp_pixels) {
875  return SDL_OutOfMemory();
876  }
877  SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format,
878  rect->w, rect->h, temp_pixels, temp_pitch);
879  SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch);
880  SDL_free(temp_pixels);
881  }
882  return 0;
883 }
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:128
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:64
void SDL_UnlockTexture(SDL_Texture *texture)
Unlock a texture, uploading the changes to video memory, if needed.
Definition: SDL_render.c:1034
void SDL_free(void *mem)
int SDL_LockTexture(SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
Lock a portion of the texture for write-only pixel access.
Definition: SDL_render.c:961
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
int SDL_UpdateTexture(SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
Update the given texture rectangle with new pixel data.
Definition: SDL_render.c:802
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
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)
Definition: SDL_yuv_sw.c:1188
int h
Definition: SDL_rect.h:67
int SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture *swdata, const SDL_Rect *srcrect, Uint32 target_format, int w, int h, void *pixels, int pitch)
Definition: SDL_yuv_sw.c:1273
Uint32 format
Definition: SDL_sysrender.h:52
#define SDL_malloc
SDL_Texture * native
Definition: SDL_sysrender.h:63
int y
Definition: SDL_rect.h:66
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

◆ SDL_UpdateYUVTexture()

int SDL_UpdateYUVTexture ( SDL_Texture texture,
const SDL_Rect rect,
const Uint8 Yplane,
int  Ypitch,
const Uint8 Uplane,
int  Upitch,
const Uint8 Vplane,
int  Vpitch 
)

Update a rectangle within a planar YV12 or IYUV texture with new pixel data.

Parameters
textureThe texture to update
rectA pointer to the rectangle of pixels to update, or NULL to update the entire texture.
YplaneThe raw pixel data for the Y plane.
YpitchThe number of bytes between rows of pixel data for the Y plane.
UplaneThe raw pixel data for the U plane.
UpitchThe number of bytes between rows of pixel data for the U plane.
VplaneThe raw pixel data for the V plane.
VpitchThe number of bytes between rows of pixel data for the V plane.
Returns
0 on success, or -1 if the texture is not valid.
Note
You can use SDL_UpdateTexture() as long as your pixel data is a contiguous block of Y and U/V planes in the proper order, but this function is available if your pixel data is not contiguous.

Definition at line 885 of file SDL_render.c.

References CHECK_TEXTURE_MAGIC, SDL_Texture::format, SDL_Texture::h, SDL_Rect::h, SDL_Texture::native, renderer, SDL_Texture::renderer, SDL_assert, SDL_InvalidParamError, SDL_PIXELFORMAT_IYUV, SDL_PIXELFORMAT_YV12, SDL_SetError, SDL_Unsupported, SDL_UpdateTextureYUVPlanar(), SDL_Renderer::UpdateTextureYUV, SDL_Texture::w, SDL_Rect::w, SDL_Rect::x, SDL_Rect::y, and SDL_Texture::yuv.

889 {
891  SDL_Rect full_rect;
892 
893  CHECK_TEXTURE_MAGIC(texture, -1);
894 
895  if (!Yplane) {
896  return SDL_InvalidParamError("Yplane");
897  }
898  if (!Ypitch) {
899  return SDL_InvalidParamError("Ypitch");
900  }
901  if (!Uplane) {
902  return SDL_InvalidParamError("Uplane");
903  }
904  if (!Upitch) {
905  return SDL_InvalidParamError("Upitch");
906  }
907  if (!Vplane) {
908  return SDL_InvalidParamError("Vplane");
909  }
910  if (!Vpitch) {
911  return SDL_InvalidParamError("Vpitch");
912  }
913 
914  if (texture->format != SDL_PIXELFORMAT_YV12 &&
915  texture->format != SDL_PIXELFORMAT_IYUV) {
916  return SDL_SetError("Texture format must by YV12 or IYUV");
917  }
918 
919  if (!rect) {
920  full_rect.x = 0;
921  full_rect.y = 0;
922  full_rect.w = texture->w;
923  full_rect.h = texture->h;
924  rect = &full_rect;
925  }
926 
927  if (texture->yuv) {
928  return SDL_UpdateTextureYUVPlanar(texture, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch);
929  } else {
930  SDL_assert(!texture->native);
931  renderer = texture->renderer;
932  SDL_assert(renderer->UpdateTextureYUV);
933  if (renderer->UpdateTextureYUV) {
934  return renderer->UpdateTextureYUV(renderer, texture, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch);
935  } else {
936  return SDL_Unsupported();
937  }
938  }
939 }
static int SDL_UpdateTextureYUVPlanar(SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *Uplane, int Upitch, const Uint8 *Vplane, int Vpitch)
Definition: SDL_render.c:838
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
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)
Definition: SDL_sysrender.h:92
static SDL_Renderer * renderer
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:64
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
#define SDL_assert(condition)
Definition: SDL_assert.h:167
#define SDL_SetError
SDL_Renderer * renderer
Definition: SDL_sysrender.h:60
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:41
int h
Definition: SDL_rect.h:67
Uint32 format
Definition: SDL_sysrender.h:52
SDL_Texture * native
Definition: SDL_sysrender.h:63
int y
Definition: SDL_rect.h:66
#define SDL_Unsupported()
Definition: SDL_error.h:53
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

◆ UpdateLogicalSize()

static int UpdateLogicalSize ( SDL_Renderer renderer)
static

Definition at line 1140 of file SDL_render.c.

References SDL_Rect::h, SDL_Renderer::integer_scale, SDL_Renderer::logical_h, SDL_Renderer::logical_w, NULL, SDL_ceil, SDL_fabs, SDL_GetRendererOutputSize(), SDL_RenderSetScale(), SDL_RenderSetViewport(), viewport, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

Referenced by SDL_RendererEventWatch(), SDL_RenderSetIntegerScale(), and SDL_RenderSetLogicalSize().

1141 {
1142  int w = 1, h = 1;
1143  float want_aspect;
1144  float real_aspect;
1145  float scale;
1147 
1148  if (!renderer->logical_w || !renderer->logical_h) {
1149  return 0;
1150  }
1151  if (SDL_GetRendererOutputSize(renderer, &w, &h) < 0) {
1152  return -1;
1153  }
1154 
1155  want_aspect = (float)renderer->logical_w / renderer->logical_h;
1156  real_aspect = (float)w / h;
1157 
1158  /* Clear the scale because we're setting viewport in output coordinates */
1159  SDL_RenderSetScale(renderer, 1.0f, 1.0f);
1160 
1161  if (renderer->integer_scale) {
1162  if (want_aspect > real_aspect) {
1163  scale = (float)(w / renderer->logical_w);
1164  } else {
1165  scale = (float)(h / renderer->logical_h);
1166  }
1167  viewport.w = (int)SDL_ceil(renderer->logical_w * scale);
1168  viewport.x = (w - viewport.w) / 2;
1169  viewport.h = (int)SDL_ceil(renderer->logical_h * scale);
1170  viewport.y = (h - viewport.h) / 2;
1171 
1172  SDL_RenderSetViewport(renderer, &viewport);
1173  } else if (SDL_fabs(want_aspect-real_aspect) < 0.0001) {
1174  /* The aspect ratios are the same, just scale appropriately */
1175  scale = (float)w / renderer->logical_w;
1176  SDL_RenderSetViewport(renderer, NULL);
1177  } else if (want_aspect > real_aspect) {
1178  /* We want a wider aspect ratio than is available - letterbox it */
1179  scale = (float)w / renderer->logical_w;
1180  viewport.x = 0;
1181  viewport.w = w;
1182  viewport.h = (int)SDL_ceil(renderer->logical_h * scale);
1183  viewport.y = (h - viewport.h) / 2;
1184  SDL_RenderSetViewport(renderer, &viewport);
1185  } else {
1186  /* We want a narrower aspect ratio than is available - use side-bars */
1187  scale = (float)h / renderer->logical_h;
1188  viewport.y = 0;
1189  viewport.h = h;
1190  viewport.w = (int)SDL_ceil(renderer->logical_w * scale);
1191  viewport.x = (w - viewport.w) / 2;
1192  SDL_RenderSetViewport(renderer, &viewport);
1193  }
1194 
1195  /* Set the new scale */
1196  SDL_RenderSetScale(renderer, scale, scale);
1197 
1198  return 0;
1199 }
GLenum GLenum GLenum GLenum GLenum scale
#define SDL_ceil
#define SDL_fabs
GLfloat f
int SDL_RenderSetViewport(SDL_Renderer *renderer, const SDL_Rect *rect)
Set the drawing area for rendering on the current target.
Definition: SDL_render.c:1253
int SDL_GetRendererOutputSize(SDL_Renderer *renderer, int *w, int *h)
Get the output size in pixels of a rendering context.
Definition: SDL_render.c:353
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
int SDL_RenderSetScale(SDL_Renderer *renderer, float scaleX, float scaleY)
Set the drawing scale for rendering on the current target.
Definition: SDL_render.c:1324
#define NULL
Definition: begin_code.h:143
int h
Definition: SDL_rect.h:67
SDL_Rect viewport
Definition: testviewport.c:28
GLubyte GLubyte GLubyte GLubyte w
int y
Definition: SDL_rect.h:66
GLfloat GLfloat GLfloat GLfloat h
SDL_bool integer_scale
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

Variable Documentation

◆ render_drivers

const SDL_RenderDriver* render_drivers[]
static
Initial value:
= {
}
SDL_RenderDriver SW_RenderDriver
Definition: SDL_render_sw.c:78

Definition at line 49 of file SDL_render.c.

◆ renderer_magic

char renderer_magic
static

Definition at line 75 of file SDL_render.c.

Referenced by SDL_CreateRenderer(), and SDL_CreateSoftwareRenderer().

◆ texture_magic

char texture_magic
static

Definition at line 76 of file SDL_render.c.

Referenced by SDL_CreateTexture().