SDL  2.0
SDL_render.h File Reference
#include "SDL_stdinc.h"
#include "SDL_rect.h"
#include "SDL_video.h"
#include "begin_code.h"
#include "close_code.h"
+ Include dependency graph for SDL_render.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SDL_RendererInfo
 Information on the capabilities of a render driver or context. More...
 

Enumerations

enum  SDL_RendererFlags {
  SDL_RENDERER_SOFTWARE = 0x00000001,
  SDL_RENDERER_ACCELERATED = 0x00000002,
  SDL_RENDERER_PRESENTVSYNC = 0x00000004,
  SDL_RENDERER_TARGETTEXTURE = 0x00000008
}
 Flags used when creating a rendering context. More...
 
enum  SDL_TextureAccess {
  SDL_TEXTUREACCESS_STATIC,
  SDL_TEXTUREACCESS_STREAMING,
  SDL_TEXTUREACCESS_TARGET
}
 The access pattern allowed for a texture. More...
 
enum  SDL_TextureModulate {
  SDL_TEXTUREMODULATE_NONE = 0x00000000,
  SDL_TEXTUREMODULATE_COLOR = 0x00000001,
  SDL_TEXTUREMODULATE_ALPHA = 0x00000002
}
 The texture channel modulation used in SDL_RenderCopy(). More...
 
enum  SDL_RendererFlip {
  SDL_FLIP_NONE = 0x00000000,
  SDL_FLIP_HORIZONTAL = 0x00000001,
  SDL_FLIP_VERTICAL = 0x00000002
}
 Flip constants for SDL_RenderCopyEx. More...
 

Functions

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...
 
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...
 
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...
 
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...
 
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...
 
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...
 
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...
 
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...
 
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...
 
voidSDL_RenderGetMetalLayer (SDL_Renderer *renderer)
 Get the CAMetalLayer associated with the given Metal renderer. More...
 
voidSDL_RenderGetMetalCommandEncoder (SDL_Renderer *renderer)
 Get the Metal command encoder for the current frame. More...
 

Detailed Description

Header file for SDL 2D rendering functions.

This API supports the following features:

  • single pixel points
  • single pixel lines
  • filled rectangles
  • texture images

The primitives may be drawn in opaque, blended, or additive modes.

The texture images may be drawn in opaque, blended, or additive modes. They can have an additional color tint or alpha modulation applied to them, and may also be stretched with linear interpolation.

This API is designed to accelerate simple 2D operations. You may want more functionality such as polygons and particle effects and in that case you should use SDL's OpenGL/Direct3D support or one of the many good 3D engines.

These functions must be called from the main thread. See this bug for details: http://bugzilla.libsdl.org/show_bug.cgi?id=1995

Definition in file SDL_render.h.

Enumeration Type Documentation

◆ SDL_RendererFlags

Flags used when creating a rendering context.

Enumerator
SDL_RENDERER_SOFTWARE 

The renderer is a software fallback

SDL_RENDERER_ACCELERATED 

The renderer uses hardware acceleration

SDL_RENDERER_PRESENTVSYNC 

Present is synchronized with the refresh rate

SDL_RENDERER_TARGETTEXTURE 

The renderer supports rendering to texture

Definition at line 64 of file SDL_render.h.

65 {
66  SDL_RENDERER_SOFTWARE = 0x00000001, /**< The renderer is a software fallback */
67  SDL_RENDERER_ACCELERATED = 0x00000002, /**< The renderer uses hardware
68  acceleration */
69  SDL_RENDERER_PRESENTVSYNC = 0x00000004, /**< Present is synchronized
70  with the refresh rate */
71  SDL_RENDERER_TARGETTEXTURE = 0x00000008 /**< The renderer supports
72  rendering to texture */
SDL_RendererFlags
Flags used when creating a rendering context.
Definition: SDL_render.h:64

◆ SDL_RendererFlip

Flip constants for SDL_RenderCopyEx.

Enumerator
SDL_FLIP_NONE 

Do not flip

SDL_FLIP_HORIZONTAL 

flip horizontally

SDL_FLIP_VERTICAL 

flip vertically

Definition at line 111 of file SDL_render.h.

112 {
113  SDL_FLIP_NONE = 0x00000000, /**< Do not flip */
114  SDL_FLIP_HORIZONTAL = 0x00000001, /**< flip horizontally */
115  SDL_FLIP_VERTICAL = 0x00000002 /**< flip vertically */
SDL_RendererFlip
Flip constants for SDL_RenderCopyEx.
Definition: SDL_render.h:111

◆ SDL_TextureAccess

The access pattern allowed for a texture.

Enumerator
SDL_TEXTUREACCESS_STATIC 

Changes rarely, not lockable

SDL_TEXTUREACCESS_STREAMING 

Changes frequently, lockable

SDL_TEXTUREACCESS_TARGET 

Texture can be used as a render target

Definition at line 91 of file SDL_render.h.

92 {
93  SDL_TEXTUREACCESS_STATIC, /**< Changes rarely, not lockable */
94  SDL_TEXTUREACCESS_STREAMING, /**< Changes frequently, lockable */
95  SDL_TEXTUREACCESS_TARGET /**< Texture can be used as a render target */
SDL_TextureAccess
The access pattern allowed for a texture.
Definition: SDL_render.h:91

◆ SDL_TextureModulate

The texture channel modulation used in SDL_RenderCopy().

Enumerator
SDL_TEXTUREMODULATE_NONE 

No modulation

SDL_TEXTUREMODULATE_COLOR 

srcC = srcC * color

SDL_TEXTUREMODULATE_ALPHA 

srcA = srcA * alpha

Definition at line 101 of file SDL_render.h.

102 {
103  SDL_TEXTUREMODULATE_NONE = 0x00000000, /**< No modulation */
104  SDL_TEXTUREMODULATE_COLOR = 0x00000001, /**< srcC = srcC * color */
105  SDL_TEXTUREMODULATE_ALPHA = 0x00000002 /**< srcA = srcA * alpha */
SDL_TextureModulate
The texture channel modulation used in SDL_RenderCopy().
Definition: SDL_render.h:101

Function Documentation

◆ 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 278 of file SDL_render.c.

References SDL_RenderDriver::CreateRenderer, SDL_Renderer::dpi_scale, SDL_RendererInfo::flags, SDL_Renderer::GetOutputSize, 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_GetWindowSize, 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, SDL_Renderer::window, window_h, window_w, SDL_FPoint::x, and SDL_FPoint::y.

Referenced by SDL_CreateWindowAndRenderer().

279 {
280 #if !SDL_RENDER_DISABLED
282  int n = SDL_GetNumRenderDrivers();
283  const char *hint;
284 
285  if (!window) {
286  SDL_SetError("Invalid window");
287  return NULL;
288  }
289 
290  if (SDL_GetRenderer(window)) {
291  SDL_SetError("Renderer already associated with window");
292  return NULL;
293  }
294 
298  } else {
300  }
301  }
302 
303  if (index < 0) {
305  if (hint) {
306  for (index = 0; index < n; ++index) {
307  const SDL_RenderDriver *driver = render_drivers[index];
308 
309  if (SDL_strcasecmp(hint, driver->info.name) == 0) {
310  /* Create a new renderer instance */
311  renderer = driver->CreateRenderer(window, flags);
312  break;
313  }
314  }
315  }
316 
317  if (!renderer) {
318  for (index = 0; index < n; ++index) {
319  const SDL_RenderDriver *driver = render_drivers[index];
320 
321  if ((driver->info.flags & flags) == flags) {
322  /* Create a new renderer instance */
323  renderer = driver->CreateRenderer(window, flags);
324  if (renderer) {
325  /* Yay, we got one! */
326  break;
327  }
328  }
329  }
330  }
331  if (index == n) {
332  SDL_SetError("Couldn't find matching render driver");
333  return NULL;
334  }
335  } else {
336  if (index >= SDL_GetNumRenderDrivers()) {
337  SDL_SetError("index must be -1 or in the range of 0 - %d",
339  return NULL;
340  }
341  /* Create a new renderer instance */
342  renderer = render_drivers[index]->CreateRenderer(window, flags);
343  }
344 
345  if (renderer) {
346  renderer->magic = &renderer_magic;
347  renderer->window = window;
348  renderer->scale.x = 1.0f;
349  renderer->scale.y = 1.0f;
350  renderer->dpi_scale.x = 1.0f;
351  renderer->dpi_scale.y = 1.0f;
352 
353  if (window && renderer->GetOutputSize) {
354  int window_w, window_h;
355  int output_w, output_h;
356  if (renderer->GetOutputSize(renderer, &output_w, &output_h) == 0) {
357  SDL_GetWindowSize(renderer->window, &window_w, &window_h);
358  renderer->dpi_scale.x = (float)window_w / output_w;
359  renderer->dpi_scale.y = (float)window_h / output_h;
360  }
361  }
362 
364  renderer->hidden = SDL_TRUE;
365  } else {
366  renderer->hidden = SDL_FALSE;
367  }
368 
369  SDL_SetWindowData(window, SDL_WINDOWRENDERDATA, renderer);
370 
371  SDL_RenderSetViewport(renderer, NULL);
372 
374 
376  "Created renderer: %s", renderer->info.name);
377  }
378  return renderer;
379 #else
380  SDL_SetError("SDL not built with rendering support");
381  return NULL;
382 #endif
383 }
#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:154
SDL_RendererInfo info
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:1398
#define SDL_strcasecmp
const char * name
Definition: SDL_render.h:80
SDL_Window * window
SDL_RendererInfo info
int(* GetOutputSize)(SDL_Renderer *renderer, int *w, int *h)
Definition: SDL_sysrender.h:81
#define SDL_GetHintBoolean
#define SDL_SetWindowData
#define SDL_GetWindowSize
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:111
GLuint index
#define NULL
Definition: begin_code.h:164
#define SDL_SetError
static const SDL_RenderDriver * render_drivers[]
Definition: SDL_render.c:76
#define SDL_WINDOWRENDERDATA
Definition: SDL_render.c:33
GLbitfield flags
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
#define SDL_AddEventWatch
#define SDL_LogInfo
SDL_Renderer * SDL_GetRenderer(SDL_Window *window)
Get the renderer associated with a window.
Definition: SDL_render.c:408
GLdouble n
#define SDL_HINT_RENDER_DRIVER
A variable specifying which render driver to use.
Definition: SDL_hints.h:85
int window_h
Definition: testoverlay2.c:144
const void * magic
Definition: SDL_sysrender.h:78
static char renderer_magic
Definition: SDL_render.c:105
int window_w
Definition: testoverlay2.c:143
SDL_FPoint dpi_scale
static int SDL_RendererEventWatch(void *userdata, SDL_Event *event)
Definition: SDL_render.c:136

◆ 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 386 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.

387 {
388 #if !SDL_RENDER_DISABLED
390 
391  renderer = SW_CreateRendererForSurface(surface);
392 
393  if (renderer) {
394  renderer->magic = &renderer_magic;
395  renderer->scale.x = 1.0f;
396  renderer->scale.y = 1.0f;
397 
398  SDL_RenderSetViewport(renderer, NULL);
399  }
400  return renderer;
401 #else
402  SDL_SetError("SDL not built with rendering support");
403  return NULL;
404 #endif /* !SDL_RENDER_DISABLED */
405 }
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:1398
SDL_Renderer * SW_CreateRendererForSurface(SDL_Surface *surface)
static SDL_Renderer * renderer
#define NULL
Definition: begin_code.h:164
#define SDL_SetError
const void * magic
Definition: SDL_sysrender.h:78
static char renderer_magic
Definition: SDL_render.c:105

◆ 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.
Note
The contents of the texture are not defined at creation.
See also
SDL_QueryTexture()
SDL_UpdateTexture()
SDL_DestroyTexture()

Definition at line 497 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().

498 {
500 
501  CHECK_RENDERER_MAGIC(renderer, NULL);
502 
503  if (!format) {
504  format = renderer->info.texture_formats[0];
505  }
506  if (SDL_BYTESPERPIXEL(format) == 0) {
507  SDL_SetError("Invalid texture format");
508  return NULL;
509  }
511  SDL_SetError("Palettized textures are not supported");
512  return NULL;
513  }
514  if (w <= 0 || h <= 0) {
515  SDL_SetError("Texture dimensions can't be 0");
516  return NULL;
517  }
518  if ((renderer->info.max_texture_width && w > renderer->info.max_texture_width) ||
519  (renderer->info.max_texture_height && h > renderer->info.max_texture_height)) {
520  SDL_SetError("Texture dimensions are limited to %dx%d", renderer->info.max_texture_width, renderer->info.max_texture_height);
521  return NULL;
522  }
523  texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture));
524  if (!texture) {
525  SDL_OutOfMemory();
526  return NULL;
527  }
528  texture->magic = &texture_magic;
529  texture->format = format;
530  texture->access = access;
531  texture->w = w;
532  texture->h = h;
533  texture->r = 255;
534  texture->g = 255;
535  texture->b = 255;
536  texture->a = 255;
537  texture->renderer = renderer;
538  texture->next = renderer->textures;
539  if (renderer->textures) {
540  renderer->textures->prev = texture;
541  }
542  renderer->textures = texture;
543 
544  if (IsSupportedFormat(renderer, format)) {
545  if (renderer->CreateTexture(renderer, texture) < 0) {
546  SDL_DestroyTexture(texture);
547  return NULL;
548  }
549  } else {
550  texture->native = SDL_CreateTexture(renderer,
552  access, w, h);
553  if (!texture->native) {
554  SDL_DestroyTexture(texture);
555  return NULL;
556  }
557 
558  /* Swap textures to have texture before texture->native in the list */
559  texture->native->next = texture->next;
560  if (texture->native->next) {
561  texture->native->next->prev = texture->native;
562  }
563  texture->prev = texture->native->prev;
564  if (texture->prev) {
565  texture->prev->next = texture;
566  }
567  texture->native->prev = texture;
568  texture->next = texture->native;
569  renderer->textures = texture;
570 
571  if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
572  texture->yuv = SDL_SW_CreateYUVTexture(format, w, h);
573  if (!texture->yuv) {
574  SDL_DestroyTexture(texture);
575  return NULL;
576  }
577  } else if (access == SDL_TEXTUREACCESS_STREAMING) {
578  /* The pitch is 4 byte aligned */
579  texture->pitch = (((w * SDL_BYTESPERPIXEL(format)) + 3) & ~3);
580  texture->pixels = SDL_calloc(1, texture->pitch * h);
581  if (!texture->pixels) {
582  SDL_DestroyTexture(texture);
583  return NULL;
584  }
585  }
586  }
587  return texture;
588 }
void * pixels
Definition: SDL_sysrender.h:65
SDL_SW_YUVTexture * SDL_SW_CreateYUVTexture(Uint32 format, int w, int h)
Definition: SDL_yuv_sw.c:31
static Uint32 GetClosestSupportedFormat(SDL_Renderer *renderer, Uint32 format)
Definition: SDL_render.c:471
SDL_RendererInfo info
#define SDL_ISPIXELFORMAT_INDEXED(format)
Definition: SDL_pixels.h:134
GLfloat GLfloat GLfloat GLfloat h
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:106
GLuint GLint GLboolean GLint GLenum access
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
SDL_Texture * next
Definition: SDL_sysrender.h:72
GLenum GLenum GLuint texture
#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:2034
SDL_Texture * prev
Definition: SDL_sysrender.h:71
static SDL_Renderer * renderer
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:64
GLubyte GLubyte GLubyte GLubyte w
#define NULL
Definition: begin_code.h:164
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
#define SDL_SetError
static SDL_bool IsSupportedFormat(SDL_Renderer *renderer, Uint32 format)
Definition: SDL_render.c:458
SDL_Renderer * renderer
Definition: SDL_sysrender.h:60
#define SDL_calloc
Uint32 format
Definition: SDL_sysrender.h:52
int(* CreateTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
Definition: SDL_sysrender.h:83
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:497

◆ 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 591 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.

592 {
593  const SDL_PixelFormat *fmt;
594  SDL_bool needAlpha;
595  Uint32 i;
596  Uint32 format;
598 
599  CHECK_RENDERER_MAGIC(renderer, NULL);
600 
601  if (!surface) {
602  SDL_SetError("SDL_CreateTextureFromSurface() passed NULL surface");
603  return NULL;
604  }
605 
606  /* See what the best texture format is */
607  fmt = surface->format;
608  if (fmt->Amask || SDL_GetColorKey(surface, NULL) == 0) {
609  needAlpha = SDL_TRUE;
610  } else {
611  needAlpha = SDL_FALSE;
612  }
613  format = renderer->info.texture_formats[0];
614  for (i = 0; i < renderer->info.num_texture_formats; ++i) {
615  if (!SDL_ISPIXELFORMAT_FOURCC(renderer->info.texture_formats[i]) &&
616  SDL_ISPIXELFORMAT_ALPHA(renderer->info.texture_formats[i]) == needAlpha) {
617  format = renderer->info.texture_formats[i];
618  break;
619  }
620  }
621 
622  texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STATIC,
623  surface->w, surface->h);
624  if (!texture) {
625  return NULL;
626  }
627 
628  if (format == surface->format->format) {
629  if (SDL_MUSTLOCK(surface)) {
630  SDL_LockSurface(surface);
631  SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch);
632  SDL_UnlockSurface(surface);
633  } else {
634  SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch);
635  }
636  } else {
637  SDL_PixelFormat *dst_fmt;
638  SDL_Surface *temp = NULL;
639 
640  /* Set up a destination surface for the texture update */
641  dst_fmt = SDL_AllocFormat(format);
642  if (!dst_fmt) {
643  SDL_DestroyTexture(texture);
644  return NULL;
645  }
646  temp = SDL_ConvertSurface(surface, dst_fmt, 0);
647  SDL_FreeFormat(dst_fmt);
648  if (temp) {
649  SDL_UpdateTexture(texture, NULL, temp->pixels, temp->pitch);
650  SDL_FreeSurface(temp);
651  } else {
652  SDL_DestroyTexture(texture);
653  return NULL;
654  }
655  }
656 
657  {
658  Uint8 r, g, b, a;
660 
661  SDL_GetSurfaceColorMod(surface, &r, &g, &b);
662  SDL_SetTextureColorMod(texture, r, g, b);
663 
664  SDL_GetSurfaceAlphaMod(surface, &a);
665  SDL_SetTextureAlphaMod(texture, a);
666 
667  if (SDL_GetColorKey(surface, NULL) == 0) {
668  /* We converted to a texture with alpha format */
670  } else {
671  SDL_GetSurfaceBlendMode(surface, &blendMode);
672  SDL_SetTextureBlendMode(texture, blendMode);
673  }
674  }
675  return texture;
676 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
#define SDL_UnlockSurface
SDL_RendererInfo info
SDL_BlendMode
The blend mode used in SDL_RenderCopy() and drawing operations.
Definition: SDL_blendmode.h:40
#define SDL_ConvertSurface
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
Definition: SDL_stdinc.h:181
#define SDL_GetSurfaceBlendMode
static SDL_BlendMode blendMode
Definition: testdraw2.c:34
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
int SDL_SetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode blendMode)
Set the blend mode used for texture copy operations.
Definition: SDL_render.c:777
GLenum GLenum GLuint texture
#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:2034
void * pixels
Definition: SDL_surface.h:75
#define SDL_GetColorKey
#define SDL_FreeSurface
uint8_t Uint8
Definition: SDL_stdinc.h:157
#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:743
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:896
#define NULL
Definition: begin_code.h:164
SDL_bool
Definition: SDL_stdinc.h:139
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:700
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 g
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:497

◆ 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 258 of file SDL_render.c.

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

260 {
263  width, height, window_flags);
264  if (!*window) {
265  *renderer = NULL;
266  return -1;
267  }
268 
269  *renderer = SDL_CreateRenderer(*window, -1, 0);
270  if (!*renderer) {
271  return -1;
272  }
273 
274  return 0;
275 }
#define SDL_CreateWindow
#define SDL_WINDOWPOS_UNDEFINED
Definition: SDL_video.h:130
GLint GLint GLsizei width
Definition: SDL_opengl.h:1572
#define NULL
Definition: begin_code.h:164
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1572
SDL_Renderer * SDL_CreateRenderer(SDL_Window *window, int index, Uint32 flags)
Create a 2D rendering context for a window.
Definition: SDL_render.c:278

◆ 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 2069 of file SDL_render.c.

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

2070 {
2071  CHECK_RENDERER_MAGIC(renderer, );
2072 
2074 
2075  /* Free existing textures for this renderer */
2076  while (renderer->textures) {
2077  SDL_Texture *tex = renderer->textures; (void) tex;
2078  SDL_DestroyTexture(renderer->textures);
2079  SDL_assert(tex != renderer->textures); /* satisfy static analysis. */
2080  }
2081 
2082  if (renderer->window) {
2084  }
2085 
2086  /* It's no longer magical... */
2087  renderer->magic = NULL;
2088 
2089  /* Free the renderer instance */
2090  renderer->DestroyRenderer(renderer);
2091 }
#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:2034
#define SDL_assert(condition)
Definition: SDL_assert.h:169
#define NULL
Definition: begin_code.h:164
#define SDL_WINDOWRENDERDATA
Definition: SDL_render.c:33
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
const void * magic
Definition: SDL_sysrender.h:78
static int SDL_RendererEventWatch(void *userdata, SDL_Event *event)
Definition: SDL_render.c:136

◆ SDL_DestroyTexture()

void SDL_DestroyTexture ( SDL_Texture texture)

Destroy the specified texture.

See also
SDL_CreateTexture()
SDL_CreateTextureFromSurface()

Definition at line 2034 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().

2035 {
2037 
2038  CHECK_TEXTURE_MAGIC(texture, );
2039 
2040  renderer = texture->renderer;
2041  if (texture == renderer->target) {
2042  SDL_SetRenderTarget(renderer, NULL);
2043  }
2044 
2045  texture->magic = NULL;
2046 
2047  if (texture->next) {
2048  texture->next->prev = texture->prev;
2049  }
2050  if (texture->prev) {
2051  texture->prev->next = texture->next;
2052  } else {
2053  renderer->textures = texture->next;
2054  }
2055 
2056  if (texture->native) {
2057  SDL_DestroyTexture(texture->native);
2058  }
2059  if (texture->yuv) {
2060  SDL_SW_DestroyYUVTexture(texture->yuv);
2061  }
2062  SDL_free(texture->pixels);
2063 
2064  renderer->DestroyTexture(renderer, texture);
2065  SDL_free(texture);
2066 }
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:2034
SDL_Texture * prev
Definition: SDL_sysrender.h:71
SDL_Texture * target
static SDL_Renderer * renderer
#define SDL_free
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:64
void SDL_SW_DestroyYUVTexture(SDL_SW_YUVTexture *swdata)
Definition: SDL_yuv_sw.c:404
#define NULL
Definition: begin_code.h:164
SDL_Renderer * renderer
Definition: SDL_sysrender.h:60
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:42
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:1165
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 111 of file SDL_render.c.

References SDL_arraysize.

Referenced by SDL_CreateRenderer(), and SDL_GetRenderDriverInfo().

112 {
113 #if !SDL_RENDER_DISABLED
115 #else
116  return 0;
117 #endif
118 }
static const SDL_RenderDriver * render_drivers[]
Definition: SDL_render.c:76
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:93

◆ 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 1538 of file SDL_render.c.

References SDL_Renderer::blendMode, and CHECK_RENDERER_MAGIC.

1539 {
1540  CHECK_RENDERER_MAGIC(renderer, -1);
1541 
1542  *blendMode = renderer->blendMode;
1543  return 0;
1544 }
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 1505 of file SDL_render.c.

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

1507 {
1508  CHECK_RENDERER_MAGIC(renderer, -1);
1509 
1510  if (r) {
1511  *r = renderer->r;
1512  }
1513  if (g) {
1514  *g = renderer->g;
1515  }
1516  if (b) {
1517  *b = renderer->b;
1518  }
1519  if (a) {
1520  *a = renderer->a;
1521  }
1522  return 0;
1523 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean g
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 121 of file SDL_render.c.

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

122 {
123 #if !SDL_RENDER_DISABLED
125  return SDL_SetError("index must be in the range of 0 - %d",
127  }
128  *info = render_drivers[index]->info;
129  return 0;
130 #else
131  return SDL_SetError("SDL not built with rendering support");
132 #endif
133 }
SDL_RendererInfo info
int SDL_GetNumRenderDrivers(void)
Get the number of 2D rendering drivers available for the current display.
Definition: SDL_render.c:111
GLuint index
#define SDL_SetError
static const SDL_RenderDriver * render_drivers[]
Definition: SDL_render.c:76

◆ SDL_GetRenderer()

SDL_Renderer* SDL_GetRenderer ( SDL_Window window)

Get the renderer associated with a window.

Definition at line 408 of file SDL_render.c.

References SDL_GetWindowData, and SDL_WINDOWRENDERDATA.

Referenced by SDL_CreateRenderer().

409 {
411 }
#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 414 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, and SDL_Renderer::info.

415 {
416  CHECK_RENDERER_MAGIC(renderer, -1);
417 
418  *info = renderer->info;
419  return 0;
420 }
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 423 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_RendererEventWatch(), SDL_RenderSetViewport(), and UpdateLogicalSize().

424 {
425  CHECK_RENDERER_MAGIC(renderer, -1);
426 
427  if (renderer->target) {
428  return SDL_QueryTexture(renderer->target, NULL, NULL, w, h);
429  } else if (renderer->GetOutputSize) {
430  return renderer->GetOutputSize(renderer, w, h);
431  } else if (renderer->window) {
432  SDL_GetWindowSize(renderer->window, w, h);
433  return 0;
434  } else {
435  SDL_assert(0 && "This should never happen");
436  return SDL_SetError("Renderer doesn't support querying output size");
437  }
438 }
GLfloat GLfloat GLfloat GLfloat h
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:679
#define SDL_GetWindowSize
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
SDL_Texture * target
GLubyte GLubyte GLubyte GLubyte w
#define SDL_assert(condition)
Definition: SDL_assert.h:169
#define NULL
Definition: begin_code.h:164
#define SDL_SetError

◆ 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 1236 of file SDL_render.c.

References SDL_Renderer::target.

Referenced by SDL_RendererEventWatch().

1237 {
1238  return renderer->target;
1239 }
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 766 of file SDL_render.c.

References SDL_Texture::a, and CHECK_TEXTURE_MAGIC.

767 {
768  CHECK_TEXTURE_MAGIC(texture, -1);
769 
770  if (alpha) {
771  *alpha = texture->a;
772  }
773  return 0;
774 }
GLfloat GLfloat GLfloat alpha
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:42

◆ 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 798 of file SDL_render.c.

References SDL_Texture::blendMode, and CHECK_TEXTURE_MAGIC.

799 {
800  CHECK_TEXTURE_MAGIC(texture, -1);
801 
802  if (blendMode) {
803  *blendMode = texture->blendMode;
804  }
805  return 0;
806 }
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:42

◆ 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 725 of file SDL_render.c.

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

727 {
728  CHECK_TEXTURE_MAGIC(texture, -1);
729 
730  if (r) {
731  *r = texture->r;
732  }
733  if (g) {
734  *g = texture->g;
735  }
736  if (b) {
737  *b = texture->b;
738  }
739  return 0;
740 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:42
GLboolean GLboolean g
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 2093 of file SDL_render.c.

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

2094 {
2096 
2097  CHECK_TEXTURE_MAGIC(texture, -1);
2098  renderer = texture->renderer;
2099  if (texture->native) {
2100  return SDL_GL_BindTexture(texture->native, texw, texh);
2101  } else if (renderer && renderer->GL_BindTexture) {
2102  return renderer->GL_BindTexture(renderer, texture, texw, texh);
2103  } else {
2104  return SDL_Unsupported();
2105  }
2106 }
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:2093
SDL_Renderer * renderer
Definition: SDL_sysrender.h:60
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:42
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 2108 of file SDL_render.c.

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

2109 {
2111 
2112  CHECK_TEXTURE_MAGIC(texture, -1);
2113  renderer = texture->renderer;
2114  if (texture->native) {
2115  return SDL_GL_UnbindTexture(texture->native);
2116  } else if (renderer && renderer->GL_UnbindTexture) {
2117  return renderer->GL_UnbindTexture(renderer, texture);
2118  }
2119 
2120  return SDL_Unsupported();
2121 }
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:42
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:2108

◆ 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 1063 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().

1065 {
1067  SDL_Rect full_rect;
1068 
1069  CHECK_TEXTURE_MAGIC(texture, -1);
1070 
1071  if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
1072  return SDL_SetError("SDL_LockTexture(): texture must be streaming");
1073  }
1074 
1075  if (!rect) {
1076  full_rect.x = 0;
1077  full_rect.y = 0;
1078  full_rect.w = texture->w;
1079  full_rect.h = texture->h;
1080  rect = &full_rect;
1081  }
1082 
1083  if (texture->yuv) {
1084  return SDL_LockTextureYUV(texture, rect, pixels, pitch);
1085  } else if (texture->native) {
1086  return SDL_LockTextureNative(texture, rect, pixels, pitch);
1087  } else {
1088  renderer = texture->renderer;
1089  return renderer->LockTexture(renderer, texture, rect, pixels, pitch);
1090  }
1091 }
int(* LockTexture)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
Definition: SDL_sysrender.h:98
static int SDL_LockTextureYUV(SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
Definition: SDL_render.c:1044
static SDL_Renderer * renderer
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:64
int x
Definition: SDL_rect.h:66
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
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:42
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:1051

◆ 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 679 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().

681 {
682  CHECK_TEXTURE_MAGIC(texture, -1);
683 
684  if (format) {
685  *format = texture->format;
686  }
687  if (access) {
688  *access = texture->access;
689  }
690  if (w) {
691  *w = texture->w;
692  }
693  if (h) {
694  *h = texture->h;
695  }
696  return 0;
697 }
GLfloat GLfloat GLfloat GLfloat h
GLuint GLint GLboolean GLint GLenum access
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
GLubyte GLubyte GLubyte GLubyte w
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:42
Uint32 format
Definition: SDL_sysrender.h:52

◆ 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 1547 of file SDL_render.c.

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

1548 {
1549  CHECK_RENDERER_MAGIC(renderer, -1);
1550 
1551  /* Don't draw while we're hidden */
1552  if (renderer->hidden) {
1553  return 0;
1554  }
1555  return renderer->RenderClear(renderer);
1556 }
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 1861 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().

1863 {
1864  SDL_Rect real_srcrect = { 0, 0, 0, 0 };
1865  SDL_Rect real_dstrect = { 0, 0, 0, 0 };
1866  SDL_FRect frect;
1867 
1868  CHECK_RENDERER_MAGIC(renderer, -1);
1869  CHECK_TEXTURE_MAGIC(texture, -1);
1870 
1871  if (renderer != texture->renderer) {
1872  return SDL_SetError("Texture was not created with this renderer");
1873  }
1874 
1875  /* Don't draw while we're hidden */
1876  if (renderer->hidden) {
1877  return 0;
1878  }
1879 
1880  real_srcrect.x = 0;
1881  real_srcrect.y = 0;
1882  real_srcrect.w = texture->w;
1883  real_srcrect.h = texture->h;
1884  if (srcrect) {
1885  if (!SDL_IntersectRect(srcrect, &real_srcrect, &real_srcrect)) {
1886  return 0;
1887  }
1888  }
1889 
1890  SDL_RenderGetViewport(renderer, &real_dstrect);
1891  real_dstrect.x = 0;
1892  real_dstrect.y = 0;
1893  if (dstrect) {
1894  if (!SDL_HasIntersection(dstrect, &real_dstrect)) {
1895  return 0;
1896  }
1897  real_dstrect = *dstrect;
1898  }
1899 
1900  if (texture->native) {
1901  texture = texture->native;
1902  }
1903 
1904  frect.x = real_dstrect.x * renderer->scale.x;
1905  frect.y = real_dstrect.y * renderer->scale.y;
1906  frect.w = real_dstrect.w * renderer->scale.x;
1907  frect.h = real_dstrect.h * renderer->scale.y;
1908 
1909  return renderer->RenderCopy(renderer, texture, &real_srcrect, &frect);
1910 }
#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:42
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:1418
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, rotating it in a clockwise direction
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 1914 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.

1917 {
1918  SDL_Rect real_srcrect = { 0, 0, 0, 0 };
1919  SDL_Rect real_dstrect = { 0, 0, 0, 0 };
1920  SDL_Point real_center;
1921  SDL_FRect frect;
1922  SDL_FPoint fcenter;
1923 
1924  if (flip == SDL_FLIP_NONE && (int)(angle/360) == angle/360) { /* fast path when we don't need rotation or flipping */
1925  return SDL_RenderCopy(renderer, texture, srcrect, dstrect);
1926  }
1927 
1928  CHECK_RENDERER_MAGIC(renderer, -1);
1929  CHECK_TEXTURE_MAGIC(texture, -1);
1930 
1931  if (renderer != texture->renderer) {
1932  return SDL_SetError("Texture was not created with this renderer");
1933  }
1934  if (!renderer->RenderCopyEx) {
1935  return SDL_SetError("Renderer does not support RenderCopyEx");
1936  }
1937 
1938  /* Don't draw while we're hidden */
1939  if (renderer->hidden) {
1940  return 0;
1941  }
1942 
1943  real_srcrect.x = 0;
1944  real_srcrect.y = 0;
1945  real_srcrect.w = texture->w;
1946  real_srcrect.h = texture->h;
1947  if (srcrect) {
1948  if (!SDL_IntersectRect(srcrect, &real_srcrect, &real_srcrect)) {
1949  return 0;
1950  }
1951  }
1952 
1953  /* We don't intersect the dstrect with the viewport as RenderCopy does because of potential rotation clipping issues... TODO: should we? */
1954  if (dstrect) {
1955  real_dstrect = *dstrect;
1956  } else {
1957  SDL_RenderGetViewport(renderer, &real_dstrect);
1958  real_dstrect.x = 0;
1959  real_dstrect.y = 0;
1960  }
1961 
1962  if (texture->native) {
1963  texture = texture->native;
1964  }
1965 
1966  if (center) {
1967  real_center = *center;
1968  } else {
1969  real_center.x = real_dstrect.w/2;
1970  real_center.y = real_dstrect.h/2;
1971  }
1972 
1973  frect.x = real_dstrect.x * renderer->scale.x;
1974  frect.y = real_dstrect.y * renderer->scale.y;
1975  frect.w = real_dstrect.w * renderer->scale.x;
1976  frect.h = real_dstrect.h * renderer->scale.y;
1977 
1978  fcenter.x = real_center.x * renderer->scale.x;
1979  fcenter.y = real_center.y * renderer->scale.y;
1980 
1981  return renderer->RenderCopyEx(renderer, texture, &real_srcrect, &frect, angle, &fcenter, flip);
1982 }
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:1861
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:42
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:1418
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 1637 of file SDL_render.c.

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

1638 {
1639  SDL_Point points[2];
1640 
1641  points[0].x = x1;
1642  points[0].y = y1;
1643  points[1].x = x2;
1644  points[1].y = y2;
1645  return SDL_RenderDrawLines(renderer, points, 2);
1646 }
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:1705

◆ 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 1705 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().

1707 {
1708  SDL_FPoint *fpoints;
1709  int i;
1710  int status;
1711 
1712  CHECK_RENDERER_MAGIC(renderer, -1);
1713 
1714  if (!points) {
1715  return SDL_SetError("SDL_RenderDrawLines(): Passed NULL points");
1716  }
1717  if (count < 2) {
1718  return 0;
1719  }
1720 
1721  /* Don't draw while we're hidden */
1722  if (renderer->hidden) {
1723  return 0;
1724  }
1725 
1726  if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) {
1727  return RenderDrawLinesWithRects(renderer, points, count);
1728  }
1729 
1730  fpoints = SDL_stack_alloc(SDL_FPoint, count);
1731  if (!fpoints) {
1732  return SDL_OutOfMemory();
1733  }
1734  for (i = 0; i < count; ++i) {
1735  fpoints[i].x = points[i].x * renderer->scale.x;
1736  fpoints[i].y = points[i].y * renderer->scale.y;
1737  }
1738 
1739  status = renderer->RenderDrawLines(renderer, fpoints, count);
1740 
1741  SDL_stack_free(fpoints);
1742 
1743  return status;
1744 }
int(* RenderDrawLines)(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
SDL_bool hidden
SDL_FPoint scale
static int RenderDrawLinesWithRects(SDL_Renderer *renderer, const SDL_Point *points, int count)
Definition: SDL_render.c:1649
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:354
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:355

◆ 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 1559 of file SDL_render.c.

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

1560 {
1561  SDL_Point point;
1562 
1563  point.x = x;
1564  point.y = y;
1565  return SDL_RenderDrawPoints(renderer, &point, 1);
1566 }
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
The structure that defines a point.
Definition: SDL_rect.h:48
int x
Definition: SDL_rect.h:50
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:1595
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574

◆ 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 1595 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().

1597 {
1598  SDL_FPoint *fpoints;
1599  int i;
1600  int status;
1601 
1602  CHECK_RENDERER_MAGIC(renderer, -1);
1603 
1604  if (!points) {
1605  return SDL_SetError("SDL_RenderDrawPoints(): Passed NULL points");
1606  }
1607  if (count < 1) {
1608  return 0;
1609  }
1610 
1611  /* Don't draw while we're hidden */
1612  if (renderer->hidden) {
1613  return 0;
1614  }
1615 
1616  if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) {
1617  return RenderDrawPointsWithRects(renderer, points, count);
1618  }
1619 
1620  fpoints = SDL_stack_alloc(SDL_FPoint, count);
1621  if (!fpoints) {
1622  return SDL_OutOfMemory();
1623  }
1624  for (i = 0; i < count; ++i) {
1625  fpoints[i].x = points[i].x * renderer->scale.x;
1626  fpoints[i].y = points[i].y * renderer->scale.y;
1627  }
1628 
1629  status = renderer->RenderDrawPoints(renderer, fpoints, count);
1630 
1631  SDL_stack_free(fpoints);
1632 
1633  return status;
1634 }
int(* RenderDrawPoints)(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
SDL_bool hidden
SDL_FPoint scale
static int RenderDrawPointsWithRects(SDL_Renderer *renderer, const SDL_Point *points, int count)
Definition: SDL_render.c:1569
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:354
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:355

◆ 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 1747 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().

1748 {
1749  SDL_Rect full_rect;
1750  SDL_Point points[5];
1751 
1752  CHECK_RENDERER_MAGIC(renderer, -1);
1753 
1754  /* If 'rect' == NULL, then outline the whole surface */
1755  if (!rect) {
1756  SDL_RenderGetViewport(renderer, &full_rect);
1757  full_rect.x = 0;
1758  full_rect.y = 0;
1759  rect = &full_rect;
1760  }
1761 
1762  points[0].x = rect->x;
1763  points[0].y = rect->y;
1764  points[1].x = rect->x+rect->w-1;
1765  points[1].y = rect->y;
1766  points[2].x = rect->x+rect->w-1;
1767  points[2].y = rect->y+rect->h-1;
1768  points[3].x = rect->x;
1769  points[3].y = rect->y+rect->h-1;
1770  points[4].x = rect->x;
1771  points[4].y = rect->y;
1772  return SDL_RenderDrawLines(renderer, points, 5);
1773 }
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:1705
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:1418
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 1776 of file SDL_render.c.

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

1778 {
1779  int i;
1780 
1781  CHECK_RENDERER_MAGIC(renderer, -1);
1782 
1783  if (!rects) {
1784  return SDL_SetError("SDL_RenderDrawRects(): Passed NULL rects");
1785  }
1786  if (count < 1) {
1787  return 0;
1788  }
1789 
1790  /* Don't draw while we're hidden */
1791  if (renderer->hidden) {
1792  return 0;
1793  }
1794 
1795  for (i = 0; i < count; ++i) {
1796  if (SDL_RenderDrawRect(renderer, &rects[i]) < 0) {
1797  return -1;
1798  }
1799  }
1800  return 0;
1801 }
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
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:1747
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_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 1804 of file SDL_render.c.

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

1805 {
1806  SDL_Rect full_rect = { 0, 0, 0, 0 };
1807 
1808  CHECK_RENDERER_MAGIC(renderer, -1);
1809 
1810  /* If 'rect' == NULL, then outline the whole surface */
1811  if (!rect) {
1812  SDL_RenderGetViewport(renderer, &full_rect);
1813  full_rect.x = 0;
1814  full_rect.y = 0;
1815  rect = &full_rect;
1816  }
1817  return SDL_RenderFillRects(renderer, rect, 1);
1818 }
#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:1821
void SDL_RenderGetViewport(SDL_Renderer *renderer, SDL_Rect *rect)
Get the drawing area for the current target.
Definition: SDL_render.c:1418
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 1821 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().

1823 {
1824  SDL_FRect *frects;
1825  int i;
1826  int status;
1827 
1828  CHECK_RENDERER_MAGIC(renderer, -1);
1829 
1830  if (!rects) {
1831  return SDL_SetError("SDL_RenderFillRects(): Passed NULL rects");
1832  }
1833  if (count < 1) {
1834  return 0;
1835  }
1836 
1837  /* Don't draw while we're hidden */
1838  if (renderer->hidden) {
1839  return 0;
1840  }
1841 
1842  frects = SDL_stack_alloc(SDL_FRect, count);
1843  if (!frects) {
1844  return SDL_OutOfMemory();
1845  }
1846  for (i = 0; i < count; ++i) {
1847  frects[i].x = rects[i].x * renderer->scale.x;
1848  frects[i].y = rects[i].y * renderer->scale.y;
1849  frects[i].w = rects[i].w * renderer->scale.x;
1850  frects[i].h = rects[i].h * renderer->scale.y;
1851  }
1852 
1853  status = renderer->RenderFillRects(renderer, frects, count);
1854 
1855  SDL_stack_free(frects);
1856 
1857  return status;
1858 }
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
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:354
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:355
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 1449 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.

1450 {
1451  CHECK_RENDERER_MAGIC(renderer, )
1452 
1453  if (rect) {
1454  rect->x = (int)(renderer->clip_rect.x / renderer->scale.x);
1455  rect->y = (int)(renderer->clip_rect.y / renderer->scale.y);
1456  rect->w = (int)(renderer->clip_rect.w / renderer->scale.x);
1457  rect->h = (int)(renderer->clip_rect.h / renderer->scale.y);
1458  }
1459 }
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 1390 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::integer_scale, and SDL_FALSE.

1391 {
1392  CHECK_RENDERER_MAGIC(renderer, SDL_FALSE);
1393 
1394  return renderer->integer_scale;
1395 }
#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 1367 of file SDL_render.c.

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

1368 {
1369  CHECK_RENDERER_MAGIC(renderer, );
1370 
1371  if (w) {
1372  *w = renderer->logical_w;
1373  }
1374  if (h) {
1375  *h = renderer->logical_h;
1376  }
1377 }
GLfloat GLfloat GLfloat GLfloat h
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
GLubyte GLubyte GLubyte GLubyte w

◆ SDL_RenderGetMetalCommandEncoder()

void* SDL_RenderGetMetalCommandEncoder ( SDL_Renderer renderer)

Get the Metal command encoder for the current frame.

Parameters
rendererThe renderer to query
Returns
id<MTLRenderCommandEncoder> on success, or NULL if the renderer isn't a Metal renderer
See also
SDL_RenderGetMetalLayer()

Definition at line 2135 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::GetMetalCommandEncoder, and NULL.

2136 {
2137  CHECK_RENDERER_MAGIC(renderer, NULL);
2138 
2139  if (renderer->GetMetalCommandEncoder) {
2140  return renderer->GetMetalCommandEncoder(renderer);
2141  }
2142  return NULL;
2143 }
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
#define NULL
Definition: begin_code.h:164
void *(* GetMetalCommandEncoder)(SDL_Renderer *renderer)

◆ SDL_RenderGetMetalLayer()

void* SDL_RenderGetMetalLayer ( SDL_Renderer renderer)

Get the CAMetalLayer associated with the given Metal renderer.

Parameters
rendererThe renderer to query
Returns
CAMetalLayer* on success, or NULL if the renderer isn't a Metal renderer
See also
SDL_RenderGetMetalCommandEncoder()

Definition at line 2124 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::GetMetalLayer, and NULL.

2125 {
2126  CHECK_RENDERER_MAGIC(renderer, NULL);
2127 
2128  if (renderer->GetMetalLayer) {
2129  return renderer->GetMetalLayer(renderer);
2130  }
2131  return NULL;
2132 }
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
void *(* GetMetalLayer)(SDL_Renderer *renderer)
#define NULL
Definition: begin_code.h:164

◆ 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 1479 of file SDL_render.c.

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

1480 {
1481  CHECK_RENDERER_MAGIC(renderer, );
1482 
1483  if (scaleX) {
1484  *scaleX = renderer->scale.x;
1485  }
1486  if (scaleY) {
1487  *scaleY = renderer->scale.y;
1488  }
1489 }
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 1418 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().

1419 {
1420  CHECK_RENDERER_MAGIC(renderer, );
1421 
1422  if (rect) {
1423  rect->x = (int)(renderer->viewport.x / renderer->scale.x);
1424  rect->y = (int)(renderer->viewport.y / renderer->scale.y);
1425  rect->w = (int)(renderer->viewport.w / renderer->scale.x);
1426  rect->h = (int)(renderer->viewport.h / renderer->scale.y);
1427  }
1428 }
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 1462 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::clipping_enabled, and SDL_FALSE.

1463 {
1464  CHECK_RENDERER_MAGIC(renderer, SDL_FALSE)
1465  return renderer->clipping_enabled;
1466 }
#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 2022 of file SDL_render.c.

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

2023 {
2024  CHECK_RENDERER_MAGIC(renderer, );
2025 
2026  /* Don't draw while we're hidden */
2027  if (renderer->hidden) {
2028  return;
2029  }
2030  renderer->RenderPresent(renderer);
2031 }
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 1985 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.

1987 {
1988  SDL_Rect real_rect;
1989 
1990  CHECK_RENDERER_MAGIC(renderer, -1);
1991 
1992  if (!renderer->RenderReadPixels) {
1993  return SDL_Unsupported();
1994  }
1995 
1996  if (!format) {
1997  format = SDL_GetWindowPixelFormat(renderer->window);
1998  }
1999 
2000  real_rect.x = renderer->viewport.x;
2001  real_rect.y = renderer->viewport.y;
2002  real_rect.w = renderer->viewport.w;
2003  real_rect.h = renderer->viewport.h;
2004  if (rect) {
2005  if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
2006  return 0;
2007  }
2008  if (real_rect.y > rect->y) {
2009  pixels = (Uint8 *)pixels + pitch * (real_rect.y - rect->y);
2010  }
2011  if (real_rect.x > rect->x) {
2012  int bpp = SDL_BYTESPERPIXEL(format);
2013  pixels = (Uint8 *)pixels + bpp * (real_rect.x - rect->x);
2014  }
2015  }
2016 
2017  return renderer->RenderReadPixels(renderer, &real_rect,
2018  format, pixels, pitch);
2019 }
int(* RenderReadPixels)(SDL_Renderer *renderer, const SDL_Rect *rect, Uint32 format, void *pixels, int pitch)
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:128
#define SDL_IntersectRect
SDL_Window * window
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
uint8_t Uint8
Definition: SDL_stdinc.h:157
int x
Definition: SDL_rect.h:66
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
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 1431 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.

1432 {
1433  CHECK_RENDERER_MAGIC(renderer, -1)
1434 
1435  if (rect) {
1436  renderer->clipping_enabled = SDL_TRUE;
1437  renderer->clip_rect.x = (int)SDL_floor(rect->x * renderer->scale.x);
1438  renderer->clip_rect.y = (int)SDL_floor(rect->y * renderer->scale.y);
1439  renderer->clip_rect.w = (int)SDL_ceil(rect->w * renderer->scale.x);
1440  renderer->clip_rect.h = (int)SDL_ceil(rect->h * renderer->scale.y);
1441  } else {
1442  renderer->clipping_enabled = SDL_FALSE;
1443  SDL_zero(renderer->clip_rect);
1444  }
1445  return renderer->UpdateClipRect(renderer);
1446 }
#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:416
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 1380 of file SDL_render.c.

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

1381 {
1382  CHECK_RENDERER_MAGIC(renderer, -1);
1383 
1384  renderer->integer_scale = enable;
1385 
1386  return UpdateLogicalSize(renderer);
1387 }
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
static int UpdateLogicalSize(SDL_Renderer *renderer)
Definition: SDL_render.c:1242
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 1347 of file SDL_render.c.

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

1348 {
1349  CHECK_RENDERER_MAGIC(renderer, -1);
1350 
1351  if (!w || !h) {
1352  /* Clear any previous logical resolution */
1353  renderer->logical_w = 0;
1354  renderer->logical_h = 0;
1355  SDL_RenderSetViewport(renderer, NULL);
1356  SDL_RenderSetScale(renderer, 1.0f, 1.0f);
1357  return 0;
1358  }
1359 
1360  renderer->logical_w = w;
1361  renderer->logical_h = h;
1362 
1363  return UpdateLogicalSize(renderer);
1364 }
GLfloat GLfloat GLfloat GLfloat h
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:1398
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
GLubyte GLubyte GLubyte GLubyte w
static int UpdateLogicalSize(SDL_Renderer *renderer)
Definition: SDL_render.c:1242
int SDL_RenderSetScale(SDL_Renderer *renderer, float scaleX, float scaleY)
Set the drawing scale for rendering on the current target.
Definition: SDL_render.c:1469
#define NULL
Definition: begin_code.h:164

◆ 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 1469 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().

1470 {
1471  CHECK_RENDERER_MAGIC(renderer, -1);
1472 
1473  renderer->scale.x = scaleX;
1474  renderer->scale.y = scaleY;
1475  return 0;
1476 }
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 1398 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().

1399 {
1400  CHECK_RENDERER_MAGIC(renderer, -1);
1401 
1402  if (rect) {
1403  renderer->viewport.x = (int)SDL_floor(rect->x * renderer->scale.x);
1404  renderer->viewport.y = (int)SDL_floor(rect->y * renderer->scale.y);
1405  renderer->viewport.w = (int)SDL_ceil(rect->w * renderer->scale.x);
1406  renderer->viewport.h = (int)SDL_ceil(rect->h * renderer->scale.y);
1407  } else {
1408  renderer->viewport.x = 0;
1409  renderer->viewport.y = 0;
1410  if (SDL_GetRendererOutputSize(renderer, &renderer->viewport.w, &renderer->viewport.h) < 0) {
1411  return -1;
1412  }
1413  }
1414  return renderer->UpdateViewport(renderer);
1415 }
#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:423
#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 1156 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().

1157 {
1158  if (!renderer || !renderer->SetRenderTarget) {
1159  return SDL_FALSE;
1160  }
1161  return (renderer->info.flags & SDL_RENDERER_TARGETTEXTURE) != 0;
1162 }
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 1526 of file SDL_render.c.

References blendMode, SDL_Renderer::blendMode, CHECK_RENDERER_MAGIC, IsSupportedBlendMode(), and SDL_Unsupported.

1527 {
1528  CHECK_RENDERER_MAGIC(renderer, -1);
1529 
1530  if (!IsSupportedBlendMode(renderer, blendMode)) {
1531  return SDL_Unsupported();
1532  }
1533  renderer->blendMode = blendMode;
1534  return 0;
1535 }
static SDL_BlendMode blendMode
Definition: testdraw2.c:34
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
SDL_BlendMode blendMode
#define SDL_Unsupported()
Definition: SDL_error.h:53
static SDL_bool IsSupportedBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendMode)
Definition: SDL_render.c:441

◆ 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 1492 of file SDL_render.c.

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

1494 {
1495  CHECK_RENDERER_MAGIC(renderer, -1);
1496 
1497  renderer->r = r;
1498  renderer->g = g;
1499  renderer->b = b;
1500  renderer->a = a;
1501  return 0;
1502 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean g
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 1165 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().

1166 {
1167  if (!SDL_RenderTargetSupported(renderer)) {
1168  return SDL_Unsupported();
1169  }
1170  if (texture == renderer->target) {
1171  /* Nothing to do! */
1172  return 0;
1173  }
1174 
1175  /* texture == NULL is valid and means reset the target to the window */
1176  if (texture) {
1177  CHECK_TEXTURE_MAGIC(texture, -1);
1178  if (renderer != texture->renderer) {
1179  return SDL_SetError("Texture was not created with this renderer");
1180  }
1181  if (texture->access != SDL_TEXTUREACCESS_TARGET) {
1182  return SDL_SetError("Texture not created with SDL_TEXTUREACCESS_TARGET");
1183  }
1184  if (texture->native) {
1185  /* Always render to the native texture */
1186  texture = texture->native;
1187  }
1188  }
1189 
1190  if (texture && !renderer->target) {
1191  /* Make a backup of the viewport */
1192  renderer->viewport_backup = renderer->viewport;
1193  renderer->clip_rect_backup = renderer->clip_rect;
1194  renderer->clipping_enabled_backup = renderer->clipping_enabled;
1195  renderer->scale_backup = renderer->scale;
1196  renderer->logical_w_backup = renderer->logical_w;
1197  renderer->logical_h_backup = renderer->logical_h;
1198  }
1199  renderer->target = texture;
1200 
1201  if (renderer->SetRenderTarget(renderer, texture) < 0) {
1202  return -1;
1203  }
1204 
1205  if (texture) {
1206  renderer->viewport.x = 0;
1207  renderer->viewport.y = 0;
1208  renderer->viewport.w = texture->w;
1209  renderer->viewport.h = texture->h;
1210  SDL_zero(renderer->clip_rect);
1211  renderer->clipping_enabled = SDL_FALSE;
1212  renderer->scale.x = 1.0f;
1213  renderer->scale.y = 1.0f;
1214  renderer->logical_w = texture->w;
1215  renderer->logical_h = texture->h;
1216  } else {
1217  renderer->viewport = renderer->viewport_backup;
1218  renderer->clip_rect = renderer->clip_rect_backup;
1219  renderer->clipping_enabled = renderer->clipping_enabled_backup;
1220  renderer->scale = renderer->scale_backup;
1221  renderer->logical_w = renderer->logical_w_backup;
1222  renderer->logical_h = renderer->logical_h_backup;
1223  }
1224  if (renderer->UpdateViewport(renderer) < 0) {
1225  return -1;
1226  }
1227  if (renderer->UpdateClipRect(renderer) < 0) {
1228  return -1;
1229  }
1230 
1231  /* All set! */
1232  return 0;
1233 }
SDL_Rect clip_rect_backup
SDL_FPoint scale
SDL_Rect clip_rect
SDL_FPoint scale_backup
GLenum GLenum GLuint texture
SDL_Texture * target
#define SDL_zero(x)
Definition: SDL_stdinc.h:416
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:1156
#define SDL_SetError
SDL_Renderer * renderer
Definition: SDL_sysrender.h:60
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:42
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 743 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().

744 {
746 
747  CHECK_TEXTURE_MAGIC(texture, -1);
748 
749  renderer = texture->renderer;
750  if (alpha < 255) {
752  } else {
753  texture->modMode &= ~SDL_TEXTUREMODULATE_ALPHA;
754  }
755  texture->a = alpha;
756  if (texture->native) {
757  return SDL_SetTextureAlphaMod(texture->native, alpha);
758  } else if (renderer->SetTextureAlphaMod) {
759  return renderer->SetTextureAlphaMod(renderer, texture);
760  } else {
761  return 0;
762  }
763 }
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:743
SDL_Renderer * renderer
Definition: SDL_sysrender.h:60
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:42
int(* SetTextureAlphaMod)(SDL_Renderer *renderer, SDL_Texture *texture)
Definition: SDL_sysrender.h:86
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 777 of file SDL_render.c.

References blendMode, SDL_Texture::blendMode, CHECK_TEXTURE_MAGIC, IsSupportedBlendMode(), SDL_Texture::native, renderer, SDL_Texture::renderer, SDL_Unsupported, and SDL_Renderer::SetTextureBlendMode.

Referenced by SDL_CreateTextureFromSurface().

778 {
780 
781  CHECK_TEXTURE_MAGIC(texture, -1);
782 
783  renderer = texture->renderer;
784  if (!IsSupportedBlendMode(renderer, blendMode)) {
785  return SDL_Unsupported();
786  }
787  texture->blendMode = blendMode;
788  if (texture->native) {
789  return SDL_SetTextureBlendMode(texture->native, blendMode);
790  } else if (renderer->SetTextureBlendMode) {
791  return renderer->SetTextureBlendMode(renderer, texture);
792  } else {
793  return 0;
794  }
795 }
SDL_BlendMode blendMode
Definition: SDL_sysrender.h:57
int(* SetTextureBlendMode)(SDL_Renderer *renderer, SDL_Texture *texture)
Definition: SDL_sysrender.h:88
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:777
static SDL_Renderer * renderer
SDL_Renderer * renderer
Definition: SDL_sysrender.h:60
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:42
SDL_Texture * native
Definition: SDL_sysrender.h:63
#define SDL_Unsupported()
Definition: SDL_error.h:53
static SDL_bool IsSupportedBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendMode)
Definition: SDL_render.c:441

◆ 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 700 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().

701 {
703 
704  CHECK_TEXTURE_MAGIC(texture, -1);
705 
706  renderer = texture->renderer;
707  if (r < 255 || g < 255 || b < 255) {
709  } else {
710  texture->modMode &= ~SDL_TEXTUREMODULATE_COLOR;
711  }
712  texture->r = r;
713  texture->g = g;
714  texture->b = b;
715  if (texture->native) {
716  return SDL_SetTextureColorMod(texture->native, r, g, b);
717  } else if (renderer->SetTextureColorMod) {
718  return renderer->SetTextureColorMod(renderer, texture);
719  } else {
720  return 0;
721  }
722 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
int(* SetTextureColorMod)(SDL_Renderer *renderer, SDL_Texture *texture)
Definition: SDL_sysrender.h:84
static SDL_Renderer * renderer
SDL_Renderer * renderer
Definition: SDL_sysrender.h:60
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:42
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:700
SDL_Texture * native
Definition: SDL_sysrender.h:63
GLboolean GLboolean g
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 1136 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().

1137 {
1139 
1140  CHECK_TEXTURE_MAGIC(texture, );
1141 
1142  if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
1143  return;
1144  }
1145  if (texture->yuv) {
1146  SDL_UnlockTextureYUV(texture);
1147  } else if (texture->native) {
1148  SDL_UnlockTextureNative(texture);
1149  } else {
1150  renderer = texture->renderer;
1151  renderer->UnlockTexture(renderer, texture);
1152  }
1153 }
static void SDL_UnlockTextureNative(SDL_Texture *texture)
Definition: SDL_render.c:1115
static SDL_Renderer * renderer
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:64
void(* UnlockTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
SDL_Renderer * renderer
Definition: SDL_sysrender.h:60
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:42
SDL_Texture * native
Definition: SDL_sysrender.h:63
static void SDL_UnlockTextureYUV(SDL_Texture *texture)
Definition: SDL_render.c:1094

◆ 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 in the format of the texture.
pitchThe number of bytes in a row of pixel data, including padding between lines.

The pixel data must be in the format of the texture. The pixel format can be queried with SDL_QueryTexture.

Returns
0 on success, or -1 if the texture is not valid.
Note
This is a fairly slow function.

Definition at line 896 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().

898 {
900  SDL_Rect full_rect;
901 
902  CHECK_TEXTURE_MAGIC(texture, -1);
903 
904  if (!pixels) {
905  return SDL_InvalidParamError("pixels");
906  }
907  if (!pitch) {
908  return SDL_InvalidParamError("pitch");
909  }
910 
911  if (!rect) {
912  full_rect.x = 0;
913  full_rect.y = 0;
914  full_rect.w = texture->w;
915  full_rect.h = texture->h;
916  rect = &full_rect;
917  }
918 
919  if ((rect->w == 0) || (rect->h == 0)) {
920  return 0; /* nothing to do. */
921  } else if (texture->yuv) {
922  return SDL_UpdateTextureYUV(texture, rect, pixels, pitch);
923  } else if (texture->native) {
924  return SDL_UpdateTextureNative(texture, rect, pixels, pitch);
925  } else {
926  renderer = texture->renderer;
927  return renderer->UpdateTexture(renderer, texture, rect, pixels, pitch);
928  }
929 }
static int SDL_UpdateTextureNative(SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
Definition: SDL_render.c:855
#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:90
static SDL_Renderer * renderer
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:64
int x
Definition: SDL_rect.h:66
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
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:809
SDL_Renderer * renderer
Definition: SDL_sysrender.h:60
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:42
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_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 983 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.

987 {
989  SDL_Rect full_rect;
990 
991  CHECK_TEXTURE_MAGIC(texture, -1);
992 
993  if (!Yplane) {
994  return SDL_InvalidParamError("Yplane");
995  }
996  if (!Ypitch) {
997  return SDL_InvalidParamError("Ypitch");
998  }
999  if (!Uplane) {
1000  return SDL_InvalidParamError("Uplane");
1001  }
1002  if (!Upitch) {
1003  return SDL_InvalidParamError("Upitch");
1004  }
1005  if (!Vplane) {
1006  return SDL_InvalidParamError("Vplane");
1007  }
1008  if (!Vpitch) {
1009  return SDL_InvalidParamError("Vpitch");
1010  }
1011 
1012  if (texture->format != SDL_PIXELFORMAT_YV12 &&
1013  texture->format != SDL_PIXELFORMAT_IYUV) {
1014  return SDL_SetError("Texture format must by YV12 or IYUV");
1015  }
1016 
1017  if (!rect) {
1018  full_rect.x = 0;
1019  full_rect.y = 0;
1020  full_rect.w = texture->w;
1021  full_rect.h = texture->h;
1022  rect = &full_rect;
1023  }
1024 
1025  if (!rect->w || !rect->h) {
1026  return 0; /* nothing to do. */
1027  }
1028 
1029  if (texture->yuv) {
1030  return SDL_UpdateTextureYUVPlanar(texture, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch);
1031  } else {
1032  SDL_assert(!texture->native);
1033  renderer = texture->renderer;
1034  SDL_assert(renderer->UpdateTextureYUV);
1035  if (renderer->UpdateTextureYUV) {
1036  return renderer->UpdateTextureYUV(renderer, texture, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch);
1037  } else {
1038  return SDL_Unsupported();
1039  }
1040  }
1041 }
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:932
#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:93
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:169
#define SDL_SetError
SDL_Renderer * renderer
Definition: SDL_sysrender.h:60
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:42
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