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

Go to the source code of this file.

Macros

#define SDL_WINDOWRENDERDATA   "_SDL_WindowRenderData"
 
#define CHECK_RENDERER_MAGIC(renderer, retval)
 
#define CHECK_TEXTURE_MAGIC(texture, retval)
 
#define SDL_COMPOSE_BLENDMODE(srcColorFactor, dstColorFactor, colorOperation, srcAlphaFactor, dstAlphaFactor, alphaOperation)
 
#define SDL_BLENDMODE_NONE_FULL
 
#define SDL_BLENDMODE_BLEND_FULL
 
#define SDL_BLENDMODE_ADD_FULL
 
#define SDL_BLENDMODE_MOD_FULL
 

Functions

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

Variables

static const SDL_RenderDriverrender_drivers []
 
static char renderer_magic
 
static char texture_magic
 

Macro Definition Documentation

§ CHECK_RENDERER_MAGIC

§ CHECK_TEXTURE_MAGIC

§ SDL_BLENDMODE_ADD_FULL

#define SDL_BLENDMODE_ADD_FULL

§ SDL_BLENDMODE_BLEND_FULL

§ SDL_BLENDMODE_MOD_FULL

#define SDL_BLENDMODE_MOD_FULL

§ SDL_BLENDMODE_NONE_FULL

#define SDL_BLENDMODE_NONE_FULL
Value:

Definition at line 59 of file SDL_render.c.

Referenced by SDL_GetLongBlendMode(), and SDL_GetShortBlendMode().

§ SDL_COMPOSE_BLENDMODE

#define SDL_COMPOSE_BLENDMODE (   srcColorFactor,
  dstColorFactor,
  colorOperation,
  srcAlphaFactor,
  dstAlphaFactor,
  alphaOperation 
)
Value:
(SDL_BlendMode)(((Uint32)colorOperation << 0) | \
((Uint32)srcColorFactor << 4) | \
((Uint32)dstColorFactor << 8) | \
((Uint32)alphaOperation << 16) | \
((Uint32)srcAlphaFactor << 20) | \
((Uint32)dstAlphaFactor << 24))
SDL_BlendMode
The blend mode used in SDL_RenderCopy() and drawing operations.
Definition: SDL_blendmode.h:40
uint32_t Uint32
Definition: SDL_stdinc.h:203

Definition at line 50 of file SDL_render.c.

Referenced by SDL_ComposeCustomBlendMode().

§ SDL_WINDOWRENDERDATA

#define SDL_WINDOWRENDERDATA   "_SDL_WindowRenderData"

Definition at line 33 of file SDL_render.c.

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

Function Documentation

§ GetClosestSupportedFormat()

static Uint32 GetClosestSupportedFormat ( SDL_Renderer renderer,
Uint32  format 
)
static

Definition at line 499 of file SDL_render.c.

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

Referenced by SDL_CreateTexture().

500 {
501  Uint32 i;
502 
504  /* Look for an exact match */
505  for (i = 0; i < renderer->info.num_texture_formats; ++i) {
506  if (renderer->info.texture_formats[i] == format) {
507  return renderer->info.texture_formats[i];
508  }
509  }
510  } else {
512 
513  /* We just want to match the first format that has the same channels */
514  for (i = 0; i < renderer->info.num_texture_formats; ++i) {
515  if (!SDL_ISPIXELFORMAT_FOURCC(renderer->info.texture_formats[i]) &&
516  SDL_ISPIXELFORMAT_ALPHA(renderer->info.texture_formats[i]) == hasAlpha) {
517  return renderer->info.texture_formats[i];
518  }
519  }
520  }
521  return renderer->info.texture_formats[0];
522 }
SDL_RendererInfo info
Uint32 texture_formats[16]
Definition: SDL_render.h:83
#define SDL_ISPIXELFORMAT_ALPHA(format)
Definition: SDL_pixels.h:154
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
SDL_bool
Definition: SDL_stdinc.h:161
uint32_t Uint32
Definition: SDL_stdinc.h:203
Uint32 num_texture_formats
Definition: SDL_render.h:82
#define SDL_ISPIXELFORMAT_FOURCC(format)
Definition: SDL_pixels.h:167

§ GetWindowViewportValues()

static void GetWindowViewportValues ( SDL_Renderer renderer,
int *  logical_w,
int *  logical_h,
SDL_Rect viewport,
SDL_FPoint scale 
)
static

Definition at line 135 of file SDL_render.c.

References SDL_Renderer::logical_h, SDL_Renderer::logical_h_backup, SDL_Renderer::logical_w, SDL_Renderer::logical_w_backup, SDL_Renderer::scale, SDL_Renderer::scale_backup, SDL_LockMutex, SDL_UnlockMutex, SDLCALL, SDL_Renderer::target, SDL_Renderer::target_mutex, SDL_Renderer::viewport, and SDL_Renderer::viewport_backup.

Referenced by SDL_RendererEventWatch().

136 {
137  SDL_LockMutex(renderer->target_mutex);
138  *logical_w = renderer->target ? renderer->logical_w_backup : renderer->logical_w;
139  *logical_h = renderer->target ? renderer->logical_h_backup : renderer->logical_h;
140  *viewport = renderer->target ? renderer->viewport_backup : renderer->viewport;
141  *scale = renderer->target ? renderer->scale_backup : renderer->scale;
142  SDL_UnlockMutex(renderer->target_mutex);
143 }
#define SDL_LockMutex
SDL_FPoint scale
SDL_mutex * target_mutex
SDL_FPoint scale_backup
SDL_Texture * target
SDL_Rect viewport
#define SDL_UnlockMutex
SDL_Rect viewport_backup

§ IsSupportedBlendMode()

static SDL_bool IsSupportedBlendMode ( SDL_Renderer renderer,
SDL_BlendMode  blendMode 
)
static

Definition at line 469 of file SDL_render.c.

References SDL_BLENDMODE_ADD, SDL_BLENDMODE_BLEND, SDL_BLENDMODE_MOD, SDL_BLENDMODE_NONE, SDL_TRUE, and SDL_Renderer::SupportsBlendMode.

Referenced by SDL_SetRenderDrawBlendMode(), and SDL_SetTextureBlendMode().

470 {
471  switch (blendMode)
472  {
473  /* These are required to be supported by all renderers */
474  case SDL_BLENDMODE_NONE:
475  case SDL_BLENDMODE_BLEND:
476  case SDL_BLENDMODE_ADD:
477  case SDL_BLENDMODE_MOD:
478  return SDL_TRUE;
479 
480  default:
481  return renderer->SupportsBlendMode && renderer->SupportsBlendMode(renderer, blendMode);
482  }
483 }
SDL_bool(* SupportsBlendMode)(SDL_Renderer *renderer, SDL_BlendMode blendMode)
Definition: SDL_sysrender.h:91
static SDL_BlendMode blendMode
Definition: testdraw2.c:34

§ IsSupportedFormat()

static SDL_bool IsSupportedFormat ( SDL_Renderer renderer,
Uint32  format 
)
static

Definition at line 486 of file SDL_render.c.

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

Referenced by SDL_CreateTexture().

487 {
488  Uint32 i;
489 
490  for (i = 0; i < renderer->info.num_texture_formats; ++i) {
491  if (renderer->info.texture_formats[i] == format) {
492  return SDL_TRUE;
493  }
494  }
495  return SDL_FALSE;
496 }
SDL_RendererInfo info
Uint32 texture_formats[16]
Definition: SDL_render.h:83
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
uint32_t Uint32
Definition: SDL_stdinc.h:203
Uint32 num_texture_formats
Definition: SDL_render.h:82

§ RenderDrawLinesWithRects()

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

Definition at line 1704 of file SDL_render.c.

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

Referenced by SDL_RenderDrawLines().

1706 {
1707  SDL_FRect *frect;
1708  SDL_FRect *frects;
1709  SDL_FPoint fpoints[2];
1710  int i, nrects;
1711  int status;
1712 
1713  frects = SDL_stack_alloc(SDL_FRect, count-1);
1714  if (!frects) {
1715  return SDL_OutOfMemory();
1716  }
1717 
1718  status = 0;
1719  nrects = 0;
1720  for (i = 0; i < count-1; ++i) {
1721  if (points[i].x == points[i+1].x) {
1722  int minY = SDL_min(points[i].y, points[i+1].y);
1723  int maxY = SDL_max(points[i].y, points[i+1].y);
1724 
1725  frect = &frects[nrects++];
1726  frect->x = points[i].x * renderer->scale.x;
1727  frect->y = minY * renderer->scale.y;
1728  frect->w = renderer->scale.x;
1729  frect->h = (maxY - minY + 1) * renderer->scale.y;
1730  } else if (points[i].y == points[i+1].y) {
1731  int minX = SDL_min(points[i].x, points[i+1].x);
1732  int maxX = SDL_max(points[i].x, points[i+1].x);
1733 
1734  frect = &frects[nrects++];
1735  frect->x = minX * renderer->scale.x;
1736  frect->y = points[i].y * renderer->scale.y;
1737  frect->w = (maxX - minX + 1) * renderer->scale.x;
1738  frect->h = renderer->scale.y;
1739  } else {
1740  /* FIXME: We can't use a rect for this line... */
1741  fpoints[0].x = points[i].x * renderer->scale.x;
1742  fpoints[0].y = points[i].y * renderer->scale.y;
1743  fpoints[1].x = points[i+1].x * renderer->scale.x;
1744  fpoints[1].y = points[i+1].y * renderer->scale.y;
1745  status += renderer->RenderDrawLines(renderer, fpoints, 2);
1746  }
1747  }
1748 
1749  status += renderer->RenderFillRects(renderer, frects, nrects);
1750 
1751  SDL_stack_free(frects);
1752 
1753  if (status < 0) {
1754  status = -1;
1755  }
1756  return status;
1757 }
int(* RenderDrawLines)(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
#define SDL_min(x, y)
Definition: SDL_stdinc.h:406
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
SDL_FPoint scale
int(* RenderFillRects)(SDL_Renderer *renderer, const SDL_FRect *rects, int count)
#define SDL_max(x, y)
Definition: SDL_stdinc.h:407
int x
Definition: SDL_rect.h:50
GLfloat minY
Definition: gl2ext.h:446
int y
Definition: SDL_rect.h:51
#define SDL_stack_alloc(type, count)
Definition: SDL_stdinc.h:354
GLfloat GLfloat GLfloat GLfloat maxX
Definition: gl2ext.h:446
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
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
GLfloat GLfloat GLfloat GLfloat GLfloat maxY
Definition: gl2ext.h:446
#define SDL_stack_free(data)
Definition: SDL_stdinc.h:355

§ RenderDrawPointsWithRects()

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

Definition at line 1624 of file SDL_render.c.

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

Referenced by SDL_RenderDrawPoints().

1626 {
1627  SDL_FRect *frects;
1628  int i;
1629  int status;
1630 
1631  frects = SDL_stack_alloc(SDL_FRect, count);
1632  if (!frects) {
1633  return SDL_OutOfMemory();
1634  }
1635  for (i = 0; i < count; ++i) {
1636  frects[i].x = points[i].x * renderer->scale.x;
1637  frects[i].y = points[i].y * renderer->scale.y;
1638  frects[i].w = renderer->scale.x;
1639  frects[i].h = renderer->scale.y;
1640  }
1641 
1642  status = renderer->RenderFillRects(renderer, frects, count);
1643 
1644  SDL_stack_free(frects);
1645 
1646  return status;
1647 }
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
SDL_FPoint scale
int(* RenderFillRects)(SDL_Renderer *renderer, const SDL_FRect *rects, int count)
int x
Definition: SDL_rect.h:50
int y
Definition: SDL_rect.h:51
#define SDL_stack_alloc(type, count)
Definition: SDL_stdinc.h: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_stack_free(data)
Definition: SDL_stdinc.h:355

§ SDL_ComposeCustomBlendMode()

SDL_BlendMode SDL_ComposeCustomBlendMode ( SDL_BlendFactor  srcColorFactor,
SDL_BlendFactor  dstColorFactor,
SDL_BlendOperation  colorOperation,
SDL_BlendFactor  srcAlphaFactor,
SDL_BlendFactor  dstAlphaFactor,
SDL_BlendOperation  alphaOperation 
)

Create a custom blend mode, which may or may not be supported by a given renderer.

Parameters
srcColorFactor
dstColorFactor
colorOperation
srcAlphaFactor
dstAlphaFactor
alphaOperationThe result of the blend mode operation will be: dstRGB = dstRGB * dstColorFactor colorOperation srcRGB * srcColorFactor and dstA = dstA * dstAlphaFactor alphaOperation srcA * srcAlphaFactor

Definition at line 2241 of file SDL_render.c.

References blendMode, SDL_COMPOSE_BLENDMODE, and SDL_GetShortBlendMode().

2245 {
2246  SDL_BlendMode blendMode = SDL_COMPOSE_BLENDMODE(srcColorFactor, dstColorFactor, colorOperation,
2247  srcAlphaFactor, dstAlphaFactor, alphaOperation);
2248  return SDL_GetShortBlendMode(blendMode);
2249 }
SDL_BlendMode
The blend mode used in SDL_RenderCopy() and drawing operations.
Definition: SDL_blendmode.h:40
static SDL_BlendMode blendMode
Definition: testdraw2.c:34
static SDL_BlendMode SDL_GetShortBlendMode(SDL_BlendMode blendMode)
Definition: SDL_render.c:2205
#define SDL_COMPOSE_BLENDMODE(srcColorFactor, dstColorFactor, colorOperation, srcAlphaFactor, dstAlphaFactor, alphaOperation)
Definition: SDL_render.c:50

§ 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 304 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_CreateMutex, 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::target_mutex, SDL_Renderer::window, window_h, window_w, SDL_FPoint::x, and SDL_FPoint::y.

Referenced by SDL_CreateWindowAndRenderer().

305 {
306 #if !SDL_RENDER_DISABLED
308  int n = SDL_GetNumRenderDrivers();
309  const char *hint;
310 
311  if (!window) {
312  SDL_SetError("Invalid window");
313  return NULL;
314  }
315 
316  if (SDL_GetRenderer(window)) {
317  SDL_SetError("Renderer already associated with window");
318  return NULL;
319  }
320 
324  } else {
326  }
327  }
328 
329  if (index < 0) {
331  if (hint) {
332  for (index = 0; index < n; ++index) {
333  const SDL_RenderDriver *driver = render_drivers[index];
334 
335  if (SDL_strcasecmp(hint, driver->info.name) == 0) {
336  /* Create a new renderer instance */
337  renderer = driver->CreateRenderer(window, flags);
338  break;
339  }
340  }
341  }
342 
343  if (!renderer) {
344  for (index = 0; index < n; ++index) {
345  const SDL_RenderDriver *driver = render_drivers[index];
346 
347  if ((driver->info.flags & flags) == flags) {
348  /* Create a new renderer instance */
349  renderer = driver->CreateRenderer(window, flags);
350  if (renderer) {
351  /* Yay, we got one! */
352  break;
353  }
354  }
355  }
356  }
357  if (index == n) {
358  SDL_SetError("Couldn't find matching render driver");
359  return NULL;
360  }
361  } else {
362  if (index >= SDL_GetNumRenderDrivers()) {
363  SDL_SetError("index must be -1 or in the range of 0 - %d",
365  return NULL;
366  }
367  /* Create a new renderer instance */
368  renderer = render_drivers[index]->CreateRenderer(window, flags);
369  }
370 
371  if (renderer) {
372  renderer->magic = &renderer_magic;
373  renderer->window = window;
374  renderer->target_mutex = SDL_CreateMutex();
375  renderer->scale.x = 1.0f;
376  renderer->scale.y = 1.0f;
377  renderer->dpi_scale.x = 1.0f;
378  renderer->dpi_scale.y = 1.0f;
379 
380  if (window && renderer->GetOutputSize) {
381  int window_w, window_h;
382  int output_w, output_h;
383  if (renderer->GetOutputSize(renderer, &output_w, &output_h) == 0) {
384  SDL_GetWindowSize(renderer->window, &window_w, &window_h);
385  renderer->dpi_scale.x = (float)window_w / output_w;
386  renderer->dpi_scale.y = (float)window_h / output_h;
387  }
388  }
389 
391  renderer->hidden = SDL_TRUE;
392  } else {
393  renderer->hidden = SDL_FALSE;
394  }
395 
396  SDL_SetWindowData(window, SDL_WINDOWRENDERDATA, renderer);
397 
398  SDL_RenderSetViewport(renderer, NULL);
399 
401 
403  "Created renderer: %s", renderer->info.name);
404  }
405  return renderer;
406 #else
407  SDL_SetError("SDL not built with rendering support");
408  return NULL;
409 #endif
410 }
#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
#define SDL_CreateMutex
SDL_FPoint scale
#define SDL_GetHint
#define SDL_GetWindowFlags
SDL_mutex * target_mutex
int SDL_RenderSetViewport(SDL_Renderer *renderer, const SDL_Rect *rect)
Set the drawing area for rendering on the current target.
Definition: SDL_render.c:1453
#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:90
#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:436
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:87
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:146

§ 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 413 of file SDL_render.c.

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

414 {
415 #if !SDL_RENDER_DISABLED
417 
418  renderer = SW_CreateRendererForSurface(surface);
419 
420  if (renderer) {
421  renderer->magic = &renderer_magic;
422  renderer->target_mutex = SDL_CreateMutex();
423  renderer->scale.x = 1.0f;
424  renderer->scale.y = 1.0f;
425 
426  SDL_RenderSetViewport(renderer, NULL);
427  }
428  return renderer;
429 #else
430  SDL_SetError("SDL not built with rendering support");
431  return NULL;
432 #endif /* !SDL_RENDER_DISABLED */
433 }
#define SDL_CreateMutex
SDL_FPoint scale
SDL_mutex * target_mutex
int SDL_RenderSetViewport(SDL_Renderer *renderer, const SDL_Rect *rect)
Set the drawing area for rendering on the current target.
Definition: SDL_render.c:1453
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:87
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 541 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_Texture::scaleMode, SDL_BYTESPERPIXEL, SDL_calloc, SDL_DestroyTexture(), SDL_GetScaleMode(), 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().

542 {
544 
545  CHECK_RENDERER_MAGIC(renderer, NULL);
546 
547  if (!format) {
548  format = renderer->info.texture_formats[0];
549  }
550  if (SDL_BYTESPERPIXEL(format) == 0) {
551  SDL_SetError("Invalid texture format");
552  return NULL;
553  }
555  SDL_SetError("Palettized textures are not supported");
556  return NULL;
557  }
558  if (w <= 0 || h <= 0) {
559  SDL_SetError("Texture dimensions can't be 0");
560  return NULL;
561  }
562  if ((renderer->info.max_texture_width && w > renderer->info.max_texture_width) ||
563  (renderer->info.max_texture_height && h > renderer->info.max_texture_height)) {
564  SDL_SetError("Texture dimensions are limited to %dx%d", renderer->info.max_texture_width, renderer->info.max_texture_height);
565  return NULL;
566  }
567  texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture));
568  if (!texture) {
569  SDL_OutOfMemory();
570  return NULL;
571  }
572  texture->magic = &texture_magic;
573  texture->format = format;
574  texture->access = access;
575  texture->w = w;
576  texture->h = h;
577  texture->r = 255;
578  texture->g = 255;
579  texture->b = 255;
580  texture->a = 255;
581  texture->scaleMode = SDL_GetScaleMode();
582  texture->renderer = renderer;
583  texture->next = renderer->textures;
584  if (renderer->textures) {
585  renderer->textures->prev = texture;
586  }
587  renderer->textures = texture;
588 
589  if (IsSupportedFormat(renderer, format)) {
590  if (renderer->CreateTexture(renderer, texture) < 0) {
591  SDL_DestroyTexture(texture);
592  return NULL;
593  }
594  } else {
595  texture->native = SDL_CreateTexture(renderer,
597  access, w, h);
598  if (!texture->native) {
599  SDL_DestroyTexture(texture);
600  return NULL;
601  }
602 
603  /* Swap textures to have texture before texture->native in the list */
604  texture->native->next = texture->next;
605  if (texture->native->next) {
606  texture->native->next->prev = texture->native;
607  }
608  texture->prev = texture->native->prev;
609  if (texture->prev) {
610  texture->prev->next = texture;
611  }
612  texture->native->prev = texture;
613  texture->next = texture->native;
614  renderer->textures = texture;
615 
616  if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
617  texture->yuv = SDL_SW_CreateYUVTexture(format, w, h);
618  if (!texture->yuv) {
619  SDL_DestroyTexture(texture);
620  return NULL;
621  }
622  } else if (access == SDL_TEXTUREACCESS_STREAMING) {
623  /* The pitch is 4 byte aligned */
624  texture->pitch = (((w * SDL_BYTESPERPIXEL(format)) + 3) & ~3);
625  texture->pixels = SDL_calloc(1, texture->pitch * h);
626  if (!texture->pixels) {
627  SDL_DestroyTexture(texture);
628  return NULL;
629  }
630  }
631  }
632  return texture;
633 }
void * pixels
Definition: SDL_sysrender.h:74
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:499
SDL_RendererInfo info
#define SDL_ISPIXELFORMAT_INDEXED(format)
Definition: SDL_pixels.h:134
GLfloat GLfloat GLfloat GLfloat h
static SDL_ScaleMode SDL_GetScaleMode(void)
Definition: SDL_render.c:525
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:81
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:2089
SDL_Texture * prev
Definition: SDL_sysrender.h:80
static SDL_Renderer * renderer
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:73
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:486
SDL_Renderer * renderer
Definition: SDL_sysrender.h:69
#define SDL_calloc
Uint32 format
Definition: SDL_sysrender.h:60
int(* CreateTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
Definition: SDL_sysrender.h:92
SDL_Texture * native
Definition: SDL_sysrender.h:72
#define SDL_ISPIXELFORMAT_FOURCC(format)
Definition: SDL_pixels.h:167
SDL_ScaleMode scaleMode
Definition: SDL_sysrender.h:66
const void * magic
Definition: SDL_sysrender.h:59
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:541

§ 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 636 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_GetSurfaceAlphaMod, SDL_GetSurfaceBlendMode, SDL_GetSurfaceColorMod, SDL_HasColorKey, 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.

637 {
638  const SDL_PixelFormat *fmt;
639  SDL_bool needAlpha;
640  Uint32 i;
641  Uint32 format;
643 
644  CHECK_RENDERER_MAGIC(renderer, NULL);
645 
646  if (!surface) {
647  SDL_SetError("SDL_CreateTextureFromSurface() passed NULL surface");
648  return NULL;
649  }
650 
651  /* See what the best texture format is */
652  fmt = surface->format;
653  if (fmt->Amask || SDL_HasColorKey(surface)) {
654  needAlpha = SDL_TRUE;
655  } else {
656  needAlpha = SDL_FALSE;
657  }
658  format = renderer->info.texture_formats[0];
659  for (i = 0; i < renderer->info.num_texture_formats; ++i) {
660  if (!SDL_ISPIXELFORMAT_FOURCC(renderer->info.texture_formats[i]) &&
661  SDL_ISPIXELFORMAT_ALPHA(renderer->info.texture_formats[i]) == needAlpha) {
662  format = renderer->info.texture_formats[i];
663  break;
664  }
665  }
666 
667  texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STATIC,
668  surface->w, surface->h);
669  if (!texture) {
670  return NULL;
671  }
672 
673  if (format == surface->format->format) {
674  if (SDL_MUSTLOCK(surface)) {
675  SDL_LockSurface(surface);
676  SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch);
677  SDL_UnlockSurface(surface);
678  } else {
679  SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch);
680  }
681  } else {
682  SDL_PixelFormat *dst_fmt;
683  SDL_Surface *temp = NULL;
684 
685  /* Set up a destination surface for the texture update */
686  dst_fmt = SDL_AllocFormat(format);
687  if (!dst_fmt) {
688  SDL_DestroyTexture(texture);
689  return NULL;
690  }
691  temp = SDL_ConvertSurface(surface, dst_fmt, 0);
692  SDL_FreeFormat(dst_fmt);
693  if (temp) {
694  SDL_UpdateTexture(texture, NULL, temp->pixels, temp->pitch);
695  SDL_FreeSurface(temp);
696  } else {
697  SDL_DestroyTexture(texture);
698  return NULL;
699  }
700  }
701 
702  {
703  Uint8 r, g, b, a;
705 
706  SDL_GetSurfaceColorMod(surface, &r, &g, &b);
707  SDL_SetTextureColorMod(texture, r, g, b);
708 
709  SDL_GetSurfaceAlphaMod(surface, &a);
710  SDL_SetTextureAlphaMod(texture, a);
711 
712  if (SDL_HasColorKey(surface)) {
713  /* We converted to a texture with alpha format */
715  } else {
716  SDL_GetSurfaceBlendMode(surface, &blendMode);
717  SDL_SetTextureBlendMode(texture, blendMode);
718  }
719  }
720  return texture;
721 }
#define SDL_HasColorKey
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
#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:822
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:2089
void * pixels
Definition: SDL_surface.h:75
#define SDL_FreeSurface
uint8_t Uint8
Definition: SDL_stdinc.h:179
#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:788
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:941
#define NULL
Definition: begin_code.h:164
SDL_bool
Definition: SDL_stdinc.h:161
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
uint32_t Uint32
Definition: SDL_stdinc.h:203
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:745
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:541

§ 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 284 of file SDL_render.c.

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

286 {
289  width, height, window_flags);
290  if (!*window) {
291  *renderer = NULL;
292  return -1;
293  }
294 
295  *renderer = SDL_CreateRenderer(*window, -1, 0);
296  if (!*renderer) {
297  return -1;
298  }
299 
300  return 0;
301 }
#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:304

§ 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 2124 of file SDL_render.c.

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

2125 {
2126  CHECK_RENDERER_MAGIC(renderer, );
2127 
2129 
2130  /* Free existing textures for this renderer */
2131  while (renderer->textures) {
2132  SDL_Texture *tex = renderer->textures; (void) tex;
2133  SDL_DestroyTexture(renderer->textures);
2134  SDL_assert(tex != renderer->textures); /* satisfy static analysis. */
2135  }
2136 
2137  if (renderer->window) {
2139  }
2140 
2141  /* It's no longer magical... */
2142  renderer->magic = NULL;
2143 
2144  /* Free the target mutex */
2145  SDL_DestroyMutex(renderer->target_mutex);
2146  renderer->target_mutex = NULL;
2147 
2148  /* Free the renderer instance */
2149  renderer->DestroyRenderer(renderer);
2150 }
#define SDL_DelEventWatch
SDL_mutex * target_mutex
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:2089
#define SDL_assert(condition)
Definition: SDL_assert.h:169
#define NULL
Definition: begin_code.h:164
#define SDL_WINDOWRENDERDATA
Definition: SDL_render.c:33
#define SDL_DestroyMutex
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:87
static int SDL_RendererEventWatch(void *userdata, SDL_Event *event)
Definition: SDL_render.c:146

§ SDL_DestroyTexture()

void SDL_DestroyTexture ( SDL_Texture texture)

Destroy the specified texture.

See also
SDL_CreateTexture()
SDL_CreateTextureFromSurface()

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

2090 {
2092 
2093  CHECK_TEXTURE_MAGIC(texture, );
2094 
2095  renderer = texture->renderer;
2096  if (texture == renderer->target) {
2097  SDL_SetRenderTarget(renderer, NULL);
2098  }
2099 
2100  texture->magic = NULL;
2101 
2102  if (texture->next) {
2103  texture->next->prev = texture->prev;
2104  }
2105  if (texture->prev) {
2106  texture->prev->next = texture->next;
2107  } else {
2108  renderer->textures = texture->next;
2109  }
2110 
2111  if (texture->native) {
2112  SDL_DestroyTexture(texture->native);
2113  }
2114  if (texture->yuv) {
2115  SDL_SW_DestroyYUVTexture(texture->yuv);
2116  }
2117  SDL_free(texture->pixels);
2118 
2119  renderer->DestroyTexture(renderer, texture);
2120  SDL_free(texture);
2121 }
void * pixels
Definition: SDL_sysrender.h:74
SDL_Texture * textures
SDL_Texture * next
Definition: SDL_sysrender.h:81
void SDL_DestroyTexture(SDL_Texture *texture)
Destroy the specified texture.
Definition: SDL_render.c:2089
SDL_Texture * prev
Definition: SDL_sysrender.h:80
SDL_Texture * target
static SDL_Renderer * renderer
#define SDL_free
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:73
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:69
#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:72
int SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
Set a texture as the current rendering target.
Definition: SDL_render.c:1210
const void * magic
Definition: SDL_sysrender.h:59

§ SDL_GetBlendModeAlphaOperation()

SDL_BlendOperation SDL_GetBlendModeAlphaOperation ( SDL_BlendMode  blendMode)

Definition at line 2287 of file SDL_render.c.

References SDL_GetLongBlendMode().

2288 {
2290  return (SDL_BlendOperation)(((Uint32)blendMode >> 16) & 0xF);
2291 }
SDL_BlendOperation
The blend operation used when combining source and destination pixel components.
Definition: SDL_blendmode.h:62
static SDL_BlendMode blendMode
Definition: testdraw2.c:34
uint32_t Uint32
Definition: SDL_stdinc.h:203
static SDL_BlendMode SDL_GetLongBlendMode(SDL_BlendMode blendMode)
Definition: SDL_render.c:2223

§ SDL_GetBlendModeColorOperation()

SDL_BlendOperation SDL_GetBlendModeColorOperation ( SDL_BlendMode  blendMode)

Definition at line 2266 of file SDL_render.c.

References SDL_GetLongBlendMode().

2267 {
2269  return (SDL_BlendOperation)(((Uint32)blendMode >> 0) & 0xF);
2270 }
SDL_BlendOperation
The blend operation used when combining source and destination pixel components.
Definition: SDL_blendmode.h:62
static SDL_BlendMode blendMode
Definition: testdraw2.c:34
uint32_t Uint32
Definition: SDL_stdinc.h:203
static SDL_BlendMode SDL_GetLongBlendMode(SDL_BlendMode blendMode)
Definition: SDL_render.c:2223

§ SDL_GetBlendModeDstAlphaFactor()

SDL_BlendFactor SDL_GetBlendModeDstAlphaFactor ( SDL_BlendMode  blendMode)

Definition at line 2280 of file SDL_render.c.

References SDL_GetLongBlendMode().

2281 {
2283  return (SDL_BlendFactor)(((Uint32)blendMode >> 24) & 0xF);
2284 }
SDL_BlendFactor
The normalized factor used to multiply pixel components.
Definition: SDL_blendmode.h:75
static SDL_BlendMode blendMode
Definition: testdraw2.c:34
uint32_t Uint32
Definition: SDL_stdinc.h:203
static SDL_BlendMode SDL_GetLongBlendMode(SDL_BlendMode blendMode)
Definition: SDL_render.c:2223

§ SDL_GetBlendModeDstColorFactor()

SDL_BlendFactor SDL_GetBlendModeDstColorFactor ( SDL_BlendMode  blendMode)

Definition at line 2259 of file SDL_render.c.

References SDL_GetLongBlendMode().

2260 {
2262  return (SDL_BlendFactor)(((Uint32)blendMode >> 8) & 0xF);
2263 }
SDL_BlendFactor
The normalized factor used to multiply pixel components.
Definition: SDL_blendmode.h:75
static SDL_BlendMode blendMode
Definition: testdraw2.c:34
uint32_t Uint32
Definition: SDL_stdinc.h:203
static SDL_BlendMode SDL_GetLongBlendMode(SDL_BlendMode blendMode)
Definition: SDL_render.c:2223

§ SDL_GetBlendModeSrcAlphaFactor()

SDL_BlendFactor SDL_GetBlendModeSrcAlphaFactor ( SDL_BlendMode  blendMode)

Definition at line 2273 of file SDL_render.c.

References SDL_GetLongBlendMode().

2274 {
2276  return (SDL_BlendFactor)(((Uint32)blendMode >> 20) & 0xF);
2277 }
SDL_BlendFactor
The normalized factor used to multiply pixel components.
Definition: SDL_blendmode.h:75
static SDL_BlendMode blendMode
Definition: testdraw2.c:34
uint32_t Uint32
Definition: SDL_stdinc.h:203
static SDL_BlendMode SDL_GetLongBlendMode(SDL_BlendMode blendMode)
Definition: SDL_render.c:2223

§ SDL_GetBlendModeSrcColorFactor()

SDL_BlendFactor SDL_GetBlendModeSrcColorFactor ( SDL_BlendMode  blendMode)

Definition at line 2252 of file SDL_render.c.

References SDL_GetLongBlendMode().

2253 {
2255  return (SDL_BlendFactor)(((Uint32)blendMode >> 4) & 0xF);
2256 }
SDL_BlendFactor
The normalized factor used to multiply pixel components.
Definition: SDL_blendmode.h:75
static SDL_BlendMode blendMode
Definition: testdraw2.c:34
uint32_t Uint32
Definition: SDL_stdinc.h:203
static SDL_BlendMode SDL_GetLongBlendMode(SDL_BlendMode blendMode)
Definition: SDL_render.c:2223

§ SDL_GetLongBlendMode()

static SDL_BlendMode SDL_GetLongBlendMode ( SDL_BlendMode  blendMode)
static

§ 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:115

§ 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 1593 of file SDL_render.c.

References SDL_Renderer::blendMode, and CHECK_RENDERER_MAGIC.

1594 {
1595  CHECK_RENDERER_MAGIC(renderer, -1);
1596 
1597  *blendMode = renderer->blendMode;
1598  return 0;
1599 }
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 1560 of file SDL_render.c.

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

1562 {
1563  CHECK_RENDERER_MAGIC(renderer, -1);
1564 
1565  if (r) {
1566  *r = renderer->r;
1567  }
1568  if (g) {
1569  *g = renderer->g;
1570  }
1571  if (b) {
1572  *b = renderer->b;
1573  }
1574  if (a) {
1575  *a = renderer->a;
1576  }
1577  return 0;
1578 }
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(), and SDL_SetError.

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

References SDL_GetWindowData, and SDL_WINDOWRENDERDATA.

Referenced by SDL_CreateRenderer().

437 {
439 }
#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 442 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, and SDL_Renderer::info.

443 {
444  CHECK_RENDERER_MAGIC(renderer, -1);
445 
446  *info = renderer->info;
447  return 0;
448 }
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 451 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().

452 {
453  CHECK_RENDERER_MAGIC(renderer, -1);
454 
455  if (renderer->target) {
456  return SDL_QueryTexture(renderer->target, NULL, NULL, w, h);
457  } else if (renderer->GetOutputSize) {
458  return renderer->GetOutputSize(renderer, w, h);
459  } else if (renderer->window) {
460  SDL_GetWindowSize(renderer->window, w, h);
461  return 0;
462  } else {
463  SDL_assert(0 && "This should never happen");
464  return SDL_SetError("Renderer doesn't support querying output size");
465  }
466 }
GLfloat GLfloat GLfloat GLfloat h
SDL_Window * window
int(* GetOutputSize)(SDL_Renderer *renderer, int *w, int *h)
Definition: SDL_sysrender.h:90
int SDL_QueryTexture(SDL_Texture *texture, Uint32 *format, int *access, int *w, int *h)
Query the attributes of a texture.
Definition: SDL_render.c:724
#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 1287 of file SDL_render.c.

References SDL_Renderer::target.

Referenced by SDL_RendererEventWatch().

1288 {
1289  return renderer->target;
1290 }
SDL_Texture * target

§ SDL_GetScaleMode()

static SDL_ScaleMode SDL_GetScaleMode ( void  )
static

Definition at line 525 of file SDL_render.c.

References SDL_atoi, SDL_GetHint, SDL_HINT_RENDER_SCALE_QUALITY, SDL_ScaleModeBest, SDL_ScaleModeLinear, SDL_ScaleModeNearest, and SDL_strcasecmp.

Referenced by SDL_CreateTexture().

526 {
527  const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
528 
529  if (!hint || SDL_strcasecmp(hint, "nearest") == 0) {
530  return SDL_ScaleModeNearest;
531  } else if (SDL_strcasecmp(hint, "linear") == 0) {
532  return SDL_ScaleModeLinear;
533  } else if (SDL_strcasecmp(hint, "best") == 0) {
534  return SDL_ScaleModeBest;
535  } else {
536  return (SDL_ScaleMode)SDL_atoi(hint);
537  }
538 }
#define SDL_HINT_RENDER_SCALE_QUALITY
A variable controlling the scaling quality.
Definition: SDL_hints.h:143
#define SDL_GetHint
#define SDL_strcasecmp
#define SDL_atoi
SDL_ScaleMode
Definition: SDL_sysrender.h:35

§ SDL_GetShortBlendMode()

static SDL_BlendMode SDL_GetShortBlendMode ( SDL_BlendMode  blendMode)
static

Definition at line 2205 of file SDL_render.c.

References blendMode, SDL_BLENDMODE_ADD, SDL_BLENDMODE_ADD_FULL, SDL_BLENDMODE_BLEND, SDL_BLENDMODE_BLEND_FULL, SDL_BLENDMODE_MOD, SDL_BLENDMODE_MOD_FULL, SDL_BLENDMODE_NONE, and SDL_BLENDMODE_NONE_FULL.

Referenced by SDL_ComposeCustomBlendMode().

2206 {
2208  return SDL_BLENDMODE_NONE;
2209  }
2211  return SDL_BLENDMODE_BLEND;
2212  }
2214  return SDL_BLENDMODE_ADD;
2215  }
2217  return SDL_BLENDMODE_MOD;
2218  }
2219  return blendMode;
2220 }
static SDL_BlendMode blendMode
Definition: testdraw2.c:34
#define SDL_BLENDMODE_BLEND_FULL
Definition: SDL_render.c:63
#define SDL_BLENDMODE_MOD_FULL
Definition: SDL_render.c:71
#define SDL_BLENDMODE_NONE_FULL
Definition: SDL_render.c:59
#define SDL_BLENDMODE_ADD_FULL
Definition: SDL_render.c:67

§ 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 811 of file SDL_render.c.

References SDL_Texture::a, and CHECK_TEXTURE_MAGIC.

812 {
813  CHECK_TEXTURE_MAGIC(texture, -1);
814 
815  if (alpha) {
816  *alpha = texture->a;
817  }
818  return 0;
819 }
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 843 of file SDL_render.c.

References SDL_Texture::blendMode, and CHECK_TEXTURE_MAGIC.

844 {
845  CHECK_TEXTURE_MAGIC(texture, -1);
846 
847  if (blendMode) {
848  *blendMode = texture->blendMode;
849  }
850  return 0;
851 }
SDL_BlendMode blendMode
Definition: SDL_sysrender.h:65
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 770 of file SDL_render.c.

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

772 {
773  CHECK_TEXTURE_MAGIC(texture, -1);
774 
775  if (r) {
776  *r = texture->r;
777  }
778  if (g) {
779  *g = texture->g;
780  }
781  if (b) {
782  *b = texture->b;
783  }
784  return 0;
785 }
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 2152 of file SDL_render.c.

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

2153 {
2155 
2156  CHECK_TEXTURE_MAGIC(texture, -1);
2157  renderer = texture->renderer;
2158  if (texture->native) {
2159  return SDL_GL_BindTexture(texture->native, texw, texh);
2160  } else if (renderer && renderer->GL_BindTexture) {
2161  return renderer->GL_BindTexture(renderer, texture, texw, texh);
2162  } else {
2163  return SDL_Unsupported();
2164  }
2165 }
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:2152
SDL_Renderer * renderer
Definition: SDL_sysrender.h:69
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:42
SDL_Texture * native
Definition: SDL_sysrender.h:72
#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 2167 of file SDL_render.c.

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

2168 {
2170 
2171  CHECK_TEXTURE_MAGIC(texture, -1);
2172  renderer = texture->renderer;
2173  if (texture->native) {
2174  return SDL_GL_UnbindTexture(texture->native);
2175  } else if (renderer && renderer->GL_UnbindTexture) {
2176  return renderer->GL_UnbindTexture(renderer, texture);
2177  }
2178 
2179  return SDL_Unsupported();
2180 }
static SDL_Renderer * renderer
int(* GL_UnbindTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
SDL_Renderer * renderer
Definition: SDL_sysrender.h:69
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:42
SDL_Texture * native
Definition: SDL_sysrender.h:72
#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:2167

§ 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 1108 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().

1110 {
1112  SDL_Rect full_rect;
1113 
1114  CHECK_TEXTURE_MAGIC(texture, -1);
1115 
1116  if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
1117  return SDL_SetError("SDL_LockTexture(): texture must be streaming");
1118  }
1119 
1120  if (!rect) {
1121  full_rect.x = 0;
1122  full_rect.y = 0;
1123  full_rect.w = texture->w;
1124  full_rect.h = texture->h;
1125  rect = &full_rect;
1126  }
1127 
1128  if (texture->yuv) {
1129  return SDL_LockTextureYUV(texture, rect, pixels, pitch);
1130  } else if (texture->native) {
1131  return SDL_LockTextureNative(texture, rect, pixels, pitch);
1132  } else {
1133  renderer = texture->renderer;
1134  return renderer->LockTexture(renderer, texture, rect, pixels, pitch);
1135  }
1136 }
int(* LockTexture)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
static int SDL_LockTextureYUV(SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
Definition: SDL_render.c:1089
static SDL_Renderer * renderer
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:73
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:69
#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:72
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:1096

§ SDL_LockTextureNative()

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

Definition at line 1096 of file SDL_render.c.

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

Referenced by SDL_LockTexture().

1098 {
1099  texture->locked_rect = *rect;
1100  *pixels = (void *) ((Uint8 *) texture->pixels +
1101  rect->y * texture->pitch +
1102  rect->x * SDL_BYTESPERPIXEL(texture->format));
1103  *pitch = texture->pitch;
1104  return 0;
1105 }
void * pixels
Definition: SDL_sysrender.h:74
SDL_Rect rect
Definition: testrelative.c:27
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:128
SDL_Rect locked_rect
Definition: SDL_sysrender.h:76
uint8_t Uint8
Definition: SDL_stdinc.h:179
int x
Definition: SDL_rect.h:66
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
Uint32 format
Definition: SDL_sysrender.h:60
int y
Definition: SDL_rect.h:66

§ SDL_LockTextureYUV()

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

Definition at line 1089 of file SDL_render.c.

References SDL_SW_LockYUVTexture(), and SDL_Texture::yuv.

Referenced by SDL_LockTexture().

1091 {
1092  return SDL_SW_LockYUVTexture(texture->yuv, rect, pixels, pitch);
1093 }
int SDL_SW_LockYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect, void **pixels, int *pitch)
Definition: SDL_yuv_sw.c:302
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:73
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572

§ 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 724 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().

726 {
727  CHECK_TEXTURE_MAGIC(texture, -1);
728 
729  if (format) {
730  *format = texture->format;
731  }
732  if (access) {
733  *access = texture->access;
734  }
735  if (w) {
736  *w = texture->w;
737  }
738  if (h) {
739  *h = texture->h;
740  }
741  return 0;
742 }
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:60

§ 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 1602 of file SDL_render.c.

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

1603 {
1604  CHECK_RENDERER_MAGIC(renderer, -1);
1605 
1606  /* Don't draw while we're hidden */
1607  if (renderer->hidden) {
1608  return 0;
1609  }
1610  return renderer->RenderClear(renderer);
1611 }
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 1916 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().

1918 {
1919  SDL_Rect real_srcrect = { 0, 0, 0, 0 };
1920  SDL_Rect real_dstrect = { 0, 0, 0, 0 };
1921  SDL_FRect frect;
1922 
1923  CHECK_RENDERER_MAGIC(renderer, -1);
1924  CHECK_TEXTURE_MAGIC(texture, -1);
1925 
1926  if (renderer != texture->renderer) {
1927  return SDL_SetError("Texture was not created with this renderer");
1928  }
1929 
1930  /* Don't draw while we're hidden */
1931  if (renderer->hidden) {
1932  return 0;
1933  }
1934 
1935  real_srcrect.x = 0;
1936  real_srcrect.y = 0;
1937  real_srcrect.w = texture->w;
1938  real_srcrect.h = texture->h;
1939  if (srcrect) {
1940  if (!SDL_IntersectRect(srcrect, &real_srcrect, &real_srcrect)) {
1941  return 0;
1942  }
1943  }
1944 
1945  SDL_RenderGetViewport(renderer, &real_dstrect);
1946  real_dstrect.x = 0;
1947  real_dstrect.y = 0;
1948  if (dstrect) {
1949  if (!SDL_HasIntersection(dstrect, &real_dstrect)) {
1950  return 0;
1951  }
1952  real_dstrect = *dstrect;
1953  }
1954 
1955  if (texture->native) {
1956  texture = texture->native;
1957  }
1958 
1959  frect.x = real_dstrect.x * renderer->scale.x;
1960  frect.y = real_dstrect.y * renderer->scale.y;
1961  frect.w = real_dstrect.w * renderer->scale.x;
1962  frect.h = real_dstrect.h * renderer->scale.y;
1963 
1964  return renderer->RenderCopy(renderer, texture, &real_srcrect, &frect);
1965 }
#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:69
#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:1473
SDL_Texture * native
Definition: SDL_sysrender.h:72
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 1969 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_Point::x, SDL_FRect::x, SDL_Rect::x, SDL_FPoint::y, SDL_Point::y, SDL_FRect::y, and SDL_Rect::y.

1972 {
1973  SDL_Rect real_srcrect = { 0, 0, 0, 0 };
1974  SDL_Rect real_dstrect = { 0, 0, 0, 0 };
1975  SDL_Point real_center;
1976  SDL_FRect frect;
1977  SDL_FPoint fcenter;
1978 
1979  if (flip == SDL_FLIP_NONE && (int)(angle/360) == angle/360) { /* fast path when we don't need rotation or flipping */
1980  return SDL_RenderCopy(renderer, texture, srcrect, dstrect);
1981  }
1982 
1983  CHECK_RENDERER_MAGIC(renderer, -1);
1984  CHECK_TEXTURE_MAGIC(texture, -1);
1985 
1986  if (renderer != texture->renderer) {
1987  return SDL_SetError("Texture was not created with this renderer");
1988  }
1989  if (!renderer->RenderCopyEx) {
1990  return SDL_SetError("Renderer does not support RenderCopyEx");
1991  }
1992 
1993  /* Don't draw while we're hidden */
1994  if (renderer->hidden) {
1995  return 0;
1996  }
1997 
1998  real_srcrect.x = 0;
1999  real_srcrect.y = 0;
2000  real_srcrect.w = texture->w;
2001  real_srcrect.h = texture->h;
2002  if (srcrect) {
2003  if (!SDL_IntersectRect(srcrect, &real_srcrect, &real_srcrect)) {
2004  return 0;
2005  }
2006  }
2007 
2008  /* We don't intersect the dstrect with the viewport as RenderCopy does because of potential rotation clipping issues... TODO: should we? */
2009  if (dstrect) {
2010  real_dstrect = *dstrect;
2011  } else {
2012  SDL_RenderGetViewport(renderer, &real_dstrect);
2013  real_dstrect.x = 0;
2014  real_dstrect.y = 0;
2015  }
2016 
2017  if (texture->native) {
2018  texture = texture->native;
2019  }
2020 
2021  if (center) {
2022  real_center = *center;
2023  } else {
2024  real_center.x = real_dstrect.w/2;
2025  real_center.y = real_dstrect.h/2;
2026  }
2027 
2028  frect.x = real_dstrect.x * renderer->scale.x;
2029  frect.y = real_dstrect.y * renderer->scale.y;
2030  frect.w = real_dstrect.w * renderer->scale.x;
2031  frect.h = real_dstrect.h * renderer->scale.y;
2032 
2033  fcenter.x = real_center.x * renderer->scale.x;
2034  fcenter.y = real_center.y * renderer->scale.y;
2035 
2036  return renderer->RenderCopyEx(renderer, texture, &real_srcrect, &frect, angle, &fcenter, flip);
2037 }
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:1916
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:69
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:1473
GLfloat angle
SDL_Texture * native
Definition: SDL_sysrender.h:72
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 1692 of file SDL_render.c.

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

1693 {
1694  SDL_Point points[2];
1695 
1696  points[0].x = x1;
1697  points[0].y = y1;
1698  points[1].x = x2;
1699  points[1].y = y2;
1700  return SDL_RenderDrawLines(renderer, points, 2);
1701 }
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:1760

§ 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 1760 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().

1762 {
1763  SDL_FPoint *fpoints;
1764  int i;
1765  int status;
1766 
1767  CHECK_RENDERER_MAGIC(renderer, -1);
1768 
1769  if (!points) {
1770  return SDL_SetError("SDL_RenderDrawLines(): Passed NULL points");
1771  }
1772  if (count < 2) {
1773  return 0;
1774  }
1775 
1776  /* Don't draw while we're hidden */
1777  if (renderer->hidden) {
1778  return 0;
1779  }
1780 
1781  if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) {
1782  return RenderDrawLinesWithRects(renderer, points, count);
1783  }
1784 
1785  fpoints = SDL_stack_alloc(SDL_FPoint, count);
1786  if (!fpoints) {
1787  return SDL_OutOfMemory();
1788  }
1789  for (i = 0; i < count; ++i) {
1790  fpoints[i].x = points[i].x * renderer->scale.x;
1791  fpoints[i].y = points[i].y * renderer->scale.y;
1792  }
1793 
1794  status = renderer->RenderDrawLines(renderer, fpoints, count);
1795 
1796  SDL_stack_free(fpoints);
1797 
1798  return status;
1799 }
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:1704
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 1614 of file SDL_render.c.

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

1615 {
1616  SDL_Point point;
1617 
1618  point.x = x;
1619  point.y = y;
1620  return SDL_RenderDrawPoints(renderer, &point, 1);
1621 }
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:1650
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 1650 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().

1652 {
1653  SDL_FPoint *fpoints;
1654  int i;
1655  int status;
1656 
1657  CHECK_RENDERER_MAGIC(renderer, -1);
1658 
1659  if (!points) {
1660  return SDL_SetError("SDL_RenderDrawPoints(): Passed NULL points");
1661  }
1662  if (count < 1) {
1663  return 0;
1664  }
1665 
1666  /* Don't draw while we're hidden */
1667  if (renderer->hidden) {
1668  return 0;
1669  }
1670 
1671  if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) {
1672  return RenderDrawPointsWithRects(renderer, points, count);
1673  }
1674 
1675  fpoints = SDL_stack_alloc(SDL_FPoint, count);
1676  if (!fpoints) {
1677  return SDL_OutOfMemory();
1678  }
1679  for (i = 0; i < count; ++i) {
1680  fpoints[i].x = points[i].x * renderer->scale.x;
1681  fpoints[i].y = points[i].y * renderer->scale.y;
1682  }
1683 
1684  status = renderer->RenderDrawPoints(renderer, fpoints, count);
1685 
1686  SDL_stack_free(fpoints);
1687 
1688  return status;
1689 }
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:1624
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 1802 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().

1803 {
1804  SDL_Rect full_rect;
1805  SDL_Point points[5];
1806 
1807  CHECK_RENDERER_MAGIC(renderer, -1);
1808 
1809  /* If 'rect' == NULL, then outline the whole surface */
1810  if (!rect) {
1811  SDL_RenderGetViewport(renderer, &full_rect);
1812  full_rect.x = 0;
1813  full_rect.y = 0;
1814  rect = &full_rect;
1815  }
1816 
1817  points[0].x = rect->x;
1818  points[0].y = rect->y;
1819  points[1].x = rect->x+rect->w-1;
1820  points[1].y = rect->y;
1821  points[2].x = rect->x+rect->w-1;
1822  points[2].y = rect->y+rect->h-1;
1823  points[3].x = rect->x;
1824  points[3].y = rect->y+rect->h-1;
1825  points[4].x = rect->x;
1826  points[4].y = rect->y;
1827  return SDL_RenderDrawLines(renderer, points, 5);
1828 }
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:1760
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:1473
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 1831 of file SDL_render.c.

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

1833 {
1834  int i;
1835 
1836  CHECK_RENDERER_MAGIC(renderer, -1);
1837 
1838  if (!rects) {
1839  return SDL_SetError("SDL_RenderDrawRects(): Passed NULL rects");
1840  }
1841  if (count < 1) {
1842  return 0;
1843  }
1844 
1845  /* Don't draw while we're hidden */
1846  if (renderer->hidden) {
1847  return 0;
1848  }
1849 
1850  for (i = 0; i < count; ++i) {
1851  if (SDL_RenderDrawRect(renderer, &rects[i]) < 0) {
1852  return -1;
1853  }
1854  }
1855  return 0;
1856 }
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:1802
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define SDL_SetError

§ SDL_RendererEventWatch()

static int SDL_RendererEventWatch ( void userdata,
SDL_Event event 
)
static

Definition at line 146 of file SDL_render.c.

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

Referenced by SDL_CreateRenderer(), and SDL_DestroyRenderer().

147 {
148  SDL_Renderer *renderer = (SDL_Renderer *)userdata;
149 
150  if (event->type == SDL_WINDOWEVENT) {
152  if (window == renderer->window) {
153  if (renderer->WindowEvent) {
154  renderer->WindowEvent(renderer, &event->window);
155  }
156 
157  if (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
158  /* Make sure we're operating on the default render target */
159  SDL_Texture *saved_target = SDL_GetRenderTarget(renderer);
160  if (saved_target) {
161  SDL_SetRenderTarget(renderer, NULL);
162  }
163 
164  if (renderer->logical_w) {
165  UpdateLogicalSize(renderer);
166  } else {
167  /* Window was resized, reset viewport */
168  int w, h;
169 
170  if (renderer->GetOutputSize) {
171  renderer->GetOutputSize(renderer, &w, &h);
172  } else {
173  SDL_GetWindowSize(renderer->window, &w, &h);
174  }
175 
176  if (renderer->target) {
177  renderer->viewport_backup.x = 0;
178  renderer->viewport_backup.y = 0;
179  renderer->viewport_backup.w = w;
180  renderer->viewport_backup.h = h;
181  } else {
182  renderer->viewport.x = 0;
183  renderer->viewport.y = 0;
184  renderer->viewport.w = w;
185  renderer->viewport.h = h;
186  renderer->UpdateViewport(renderer);
187  }
188  }
189 
190  if (saved_target) {
191  SDL_SetRenderTarget(renderer, saved_target);
192  }
193  } else if (event->window.event == SDL_WINDOWEVENT_HIDDEN) {
194  renderer->hidden = SDL_TRUE;
195  } else if (event->window.event == SDL_WINDOWEVENT_SHOWN) {
196  if (!(SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED)) {
197  renderer->hidden = SDL_FALSE;
198  }
199  } else if (event->window.event == SDL_WINDOWEVENT_MINIMIZED) {
200  renderer->hidden = SDL_TRUE;
201  } else if (event->window.event == SDL_WINDOWEVENT_RESTORED ||
203  if (!(SDL_GetWindowFlags(window) & SDL_WINDOW_HIDDEN)) {
204  renderer->hidden = SDL_FALSE;
205  }
206  }
207  }
208  } else if (event->type == SDL_MOUSEMOTION) {
209  SDL_Window *window = SDL_GetWindowFromID(event->motion.windowID);
210  if (window == renderer->window) {
211  int logical_w, logical_h;
214  GetWindowViewportValues(renderer, &logical_w, &logical_h, &viewport, &scale);
215  if (logical_w) {
216  event->motion.x -= (int)(viewport.x * renderer->dpi_scale.x);
217  event->motion.y -= (int)(viewport.y * renderer->dpi_scale.y);
218  event->motion.x = (int)(event->motion.x / (scale.x * renderer->dpi_scale.x));
219  event->motion.y = (int)(event->motion.y / (scale.y * renderer->dpi_scale.y));
220  if (event->motion.xrel > 0) {
221  event->motion.xrel = SDL_max(1, (int)(event->motion.xrel / (scale.x * renderer->dpi_scale.x)));
222  } else if (event->motion.xrel < 0) {
223  event->motion.xrel = SDL_min(-1, (int)(event->motion.xrel / (scale.x * renderer->dpi_scale.x)));
224  }
225  if (event->motion.yrel > 0) {
226  event->motion.yrel = SDL_max(1, (int)(event->motion.yrel / (scale.y * renderer->dpi_scale.y)));
227  } else if (event->motion.yrel < 0) {
228  event->motion.yrel = SDL_min(-1, (int)(event->motion.yrel / (scale.y * renderer->dpi_scale.y)));
229  }
230  }
231  }
232  } else if (event->type == SDL_MOUSEBUTTONDOWN ||
233  event->type == SDL_MOUSEBUTTONUP) {
234  SDL_Window *window = SDL_GetWindowFromID(event->button.windowID);
235  if (window == renderer->window) {
236  int logical_w, logical_h;
239  GetWindowViewportValues(renderer, &logical_w, &logical_h, &viewport, &scale);
240  if (logical_w) {
241  event->button.x -= (int)(viewport.x * renderer->dpi_scale.x);
242  event->button.y -= (int)(viewport.y * renderer->dpi_scale.y);
243  event->button.x = (int)(event->button.x / (scale.x * renderer->dpi_scale.x));
244  event->button.y = (int)(event->button.y / (scale.y * renderer->dpi_scale.y));
245  }
246  }
247  } else if (event->type == SDL_FINGERDOWN ||
248  event->type == SDL_FINGERUP ||
249  event->type == SDL_FINGERMOTION) {
250  int logical_w, logical_h;
253  GetWindowViewportValues(renderer, &logical_w, &logical_h, &viewport, &scale);
254  if (logical_w) {
255  int w = 1;
256  int h = 1;
257  SDL_GetRendererOutputSize(renderer, &w, &h);
258 
259  event->tfinger.x *= (w - 1);
260  event->tfinger.y *= (h - 1);
261 
262  event->tfinger.x -= (viewport.x * renderer->dpi_scale.x);
263  event->tfinger.y -= (viewport.y * renderer->dpi_scale.y);
264  event->tfinger.x = (event->tfinger.x / (scale.x * renderer->dpi_scale.x));
265  event->tfinger.y = (event->tfinger.y / (scale.y * renderer->dpi_scale.y));
266 
267  if (logical_w > 1) {
268  event->tfinger.x = event->tfinger.x / (logical_w - 1);
269  } else {
270  event->tfinger.x = 0.5f;
271  }
272  if (logical_h > 1) {
273  event->tfinger.y = event->tfinger.y / (logical_h - 1);
274  } else {
275  event->tfinger.y = 0.5f;
276  }
277  }
278  }
279 
280  return 0;
281 }
GLenum GLenum GLenum GLenum GLenum scale
SDL_MouseMotionEvent motion
Definition: SDL_events.h:566
#define SDL_min(x, y)
Definition: SDL_stdinc.h:406
static void GetWindowViewportValues(SDL_Renderer *renderer, int *logical_w, int *logical_h, SDL_Rect *viewport, SDL_FPoint *scale)
Definition: SDL_render.c:135
SDL_bool hidden
GLfloat GLfloat GLfloat GLfloat h
SDL_Texture * SDL_GetRenderTarget(SDL_Renderer *renderer)
Get the current render target or NULL for the default render target.
Definition: SDL_render.c:1287
#define SDL_GetWindowFlags
SDL_Window * window
int SDL_GetRendererOutputSize(SDL_Renderer *renderer, int *w, int *h)
Get the output size in pixels of a rendering context.
Definition: SDL_render.c:451
#define SDL_max(x, y)
Definition: SDL_stdinc.h:407
int(* GetOutputSize)(SDL_Renderer *renderer, int *w, int *h)
Definition: SDL_sysrender.h:90
SDL_WindowEvent window
Definition: SDL_events.h:562
#define SDL_GetWindowSize
SDL_Texture * target
static SDL_Renderer * renderer
GLubyte GLubyte GLubyte GLubyte w
int x
Definition: SDL_rect.h:66
int(* UpdateViewport)(SDL_Renderer *renderer)
#define SDL_GetWindowFromID
int w
Definition: SDL_rect.h:67
static int UpdateLogicalSize(SDL_Renderer *renderer)
Definition: SDL_render.c:1293
#define NULL
Definition: begin_code.h:164
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
SDL_Rect viewport
int h
Definition: SDL_rect.h:67
The type used to identify a window.
Definition: SDL_sysvideo.h:73
SDL_Rect viewport
Definition: testviewport.c:28
void(* WindowEvent)(SDL_Renderer *renderer, const SDL_WindowEvent *event)
Definition: SDL_sysrender.h:89
SDL_MouseButtonEvent button
Definition: SDL_events.h:567
SDL_Rect viewport_backup
int SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
Set a texture as the current rendering target.
Definition: SDL_render.c:1210
int y
Definition: SDL_rect.h:66
SDL_FPoint dpi_scale
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64
Uint32 type
Definition: SDL_events.h:559

§ 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 1859 of file SDL_render.c.

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

1860 {
1861  SDL_Rect full_rect = { 0, 0, 0, 0 };
1862 
1863  CHECK_RENDERER_MAGIC(renderer, -1);
1864 
1865  /* If 'rect' == NULL, then outline the whole surface */
1866  if (!rect) {
1867  SDL_RenderGetViewport(renderer, &full_rect);
1868  full_rect.x = 0;
1869  full_rect.y = 0;
1870  rect = &full_rect;
1871  }
1872  return SDL_RenderFillRects(renderer, rect, 1);
1873 }
#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:1876
void SDL_RenderGetViewport(SDL_Renderer *renderer, SDL_Rect *rect)
Get the drawing area for the current target.
Definition: SDL_render.c:1473
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 1876 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().

1878 {
1879  SDL_FRect *frects;
1880  int i;
1881  int status;
1882 
1883  CHECK_RENDERER_MAGIC(renderer, -1);
1884 
1885  if (!rects) {
1886  return SDL_SetError("SDL_RenderFillRects(): Passed NULL rects");
1887  }
1888  if (count < 1) {
1889  return 0;
1890  }
1891 
1892  /* Don't draw while we're hidden */
1893  if (renderer->hidden) {
1894  return 0;
1895  }
1896 
1897  frects = SDL_stack_alloc(SDL_FRect, count);
1898  if (!frects) {
1899  return SDL_OutOfMemory();
1900  }
1901  for (i = 0; i < count; ++i) {
1902  frects[i].x = rects[i].x * renderer->scale.x;
1903  frects[i].y = rects[i].y * renderer->scale.y;
1904  frects[i].w = rects[i].w * renderer->scale.x;
1905  frects[i].h = rects[i].h * renderer->scale.y;
1906  }
1907 
1908  status = renderer->RenderFillRects(renderer, frects, count);
1909 
1910  SDL_stack_free(frects);
1911 
1912  return status;
1913 }
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 1504 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.

1505 {
1506  CHECK_RENDERER_MAGIC(renderer, )
1507 
1508  if (rect) {
1509  rect->x = (int)(renderer->clip_rect.x / renderer->scale.x);
1510  rect->y = (int)(renderer->clip_rect.y / renderer->scale.y);
1511  rect->w = (int)(renderer->clip_rect.w / renderer->scale.x);
1512  rect->h = (int)(renderer->clip_rect.h / renderer->scale.y);
1513  }
1514 }
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 1445 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::integer_scale, and SDL_FALSE.

1446 {
1447  CHECK_RENDERER_MAGIC(renderer, SDL_FALSE);
1448 
1449  return renderer->integer_scale;
1450 }
#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 1422 of file SDL_render.c.

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

1423 {
1424  CHECK_RENDERER_MAGIC(renderer, );
1425 
1426  if (w) {
1427  *w = renderer->logical_w;
1428  }
1429  if (h) {
1430  *h = renderer->logical_h;
1431  }
1432 }
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 2194 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::GetMetalCommandEncoder, and NULL.

2195 {
2196  CHECK_RENDERER_MAGIC(renderer, NULL);
2197 
2198  if (renderer->GetMetalCommandEncoder) {
2199  return renderer->GetMetalCommandEncoder(renderer);
2200  }
2201  return NULL;
2202 }
#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 2183 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::GetMetalLayer, and NULL.

2184 {
2185  CHECK_RENDERER_MAGIC(renderer, NULL);
2186 
2187  if (renderer->GetMetalLayer) {
2188  return renderer->GetMetalLayer(renderer);
2189  }
2190  return NULL;
2191 }
#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 1534 of file SDL_render.c.

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

1535 {
1536  CHECK_RENDERER_MAGIC(renderer, );
1537 
1538  if (scaleX) {
1539  *scaleX = renderer->scale.x;
1540  }
1541  if (scaleY) {
1542  *scaleY = renderer->scale.y;
1543  }
1544 }
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 1473 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().

1474 {
1475  CHECK_RENDERER_MAGIC(renderer, );
1476 
1477  if (rect) {
1478  rect->x = (int)(renderer->viewport.x / renderer->scale.x);
1479  rect->y = (int)(renderer->viewport.y / renderer->scale.y);
1480  rect->w = (int)(renderer->viewport.w / renderer->scale.x);
1481  rect->h = (int)(renderer->viewport.h / renderer->scale.y);
1482  }
1483 }
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 1517 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::clipping_enabled, and SDL_FALSE.

1518 {
1519  CHECK_RENDERER_MAGIC(renderer, SDL_FALSE)
1520  return renderer->clipping_enabled;
1521 }
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35

§ SDL_RenderPresent()

void SDL_RenderPresent ( SDL_Renderer renderer)

Update the screen with rendering performed.

Definition at line 2077 of file SDL_render.c.

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

2078 {
2079  CHECK_RENDERER_MAGIC(renderer, );
2080 
2081  /* Don't draw while we're hidden */
2082  if (renderer->hidden) {
2083  return;
2084  }
2085  renderer->RenderPresent(renderer);
2086 }
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 2040 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.

2042 {
2043  SDL_Rect real_rect;
2044 
2045  CHECK_RENDERER_MAGIC(renderer, -1);
2046 
2047  if (!renderer->RenderReadPixels) {
2048  return SDL_Unsupported();
2049  }
2050 
2051  if (!format) {
2052  format = SDL_GetWindowPixelFormat(renderer->window);
2053  }
2054 
2055  real_rect.x = renderer->viewport.x;
2056  real_rect.y = renderer->viewport.y;
2057  real_rect.w = renderer->viewport.w;
2058  real_rect.h = renderer->viewport.h;
2059  if (rect) {
2060  if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
2061  return 0;
2062  }
2063  if (real_rect.y > rect->y) {
2064  pixels = (Uint8 *)pixels + pitch * (real_rect.y - rect->y);
2065  }
2066  if (real_rect.x > rect->x) {
2067  int bpp = SDL_BYTESPERPIXEL(format);
2068  pixels = (Uint8 *)pixels + bpp * (real_rect.x - rect->x);
2069  }
2070  }
2071 
2072  return renderer->RenderReadPixels(renderer, &real_rect,
2073  format, pixels, pitch);
2074 }
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:179
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 1486 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.

1487 {
1488  CHECK_RENDERER_MAGIC(renderer, -1)
1489 
1490  if (rect) {
1491  renderer->clipping_enabled = SDL_TRUE;
1492  renderer->clip_rect.x = (int)SDL_floor(rect->x * renderer->scale.x);
1493  renderer->clip_rect.y = (int)SDL_floor(rect->y * renderer->scale.y);
1494  renderer->clip_rect.w = (int)SDL_ceil(rect->w * renderer->scale.x);
1495  renderer->clip_rect.h = (int)SDL_ceil(rect->h * renderer->scale.y);
1496  } else {
1497  renderer->clipping_enabled = SDL_FALSE;
1498  SDL_zero(renderer->clip_rect);
1499  }
1500  return renderer->UpdateClipRect(renderer);
1501 }
#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 1435 of file SDL_render.c.

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

1436 {
1437  CHECK_RENDERER_MAGIC(renderer, -1);
1438 
1439  renderer->integer_scale = enable;
1440 
1441  return UpdateLogicalSize(renderer);
1442 }
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:35
static int UpdateLogicalSize(SDL_Renderer *renderer)
Definition: SDL_render.c:1293
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 1402 of file SDL_render.c.

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

1403 {
1404  CHECK_RENDERER_MAGIC(renderer, -1);
1405 
1406  if (!w || !h) {
1407  /* Clear any previous logical resolution */
1408  renderer->logical_w = 0;
1409  renderer->logical_h = 0;
1410  SDL_RenderSetViewport(renderer, NULL);
1411  SDL_RenderSetScale(renderer, 1.0f, 1.0f);
1412  return 0;
1413  }
1414 
1415  renderer->logical_w = w;
1416  renderer->logical_h = h;
1417 
1418  return UpdateLogicalSize(renderer);
1419 }
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:1453
#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:1293
int SDL_RenderSetScale(SDL_Renderer *renderer, float scaleX, float scaleY)
Set the drawing scale for rendering on the current target.
Definition: SDL_render.c:1524
#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 1524 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().

1525 {
1526  CHECK_RENDERER_MAGIC(renderer, -1);
1527 
1528  renderer->scale.x = scaleX;
1529  renderer->scale.y = scaleY;
1530  return 0;
1531 }
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 1453 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().

1454 {
1455  CHECK_RENDERER_MAGIC(renderer, -1);
1456 
1457  if (rect) {
1458  renderer->viewport.x = (int)SDL_floor(rect->x * renderer->scale.x);
1459  renderer->viewport.y = (int)SDL_floor(rect->y * renderer->scale.y);
1460  renderer->viewport.w = (int)SDL_ceil(rect->w * renderer->scale.x);
1461  renderer->viewport.h = (int)SDL_ceil(rect->h * renderer->scale.y);
1462  } else {
1463  renderer->viewport.x = 0;
1464  renderer->viewport.y = 0;
1465  if (SDL_GetRendererOutputSize(renderer, &renderer->viewport.w, &renderer->viewport.h) < 0) {
1466  return -1;
1467  }
1468  }
1469  return renderer->UpdateViewport(renderer);
1470 }
#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:451
#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 1201 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().

1202 {
1203  if (!renderer || !renderer->SetRenderTarget) {
1204  return SDL_FALSE;
1205  }
1206  return (renderer->info.flags & SDL_RENDERER_TARGETTEXTURE) != 0;
1207 }
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 1581 of file SDL_render.c.

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

1582 {
1583  CHECK_RENDERER_MAGIC(renderer, -1);
1584 
1585  if (!IsSupportedBlendMode(renderer, blendMode)) {
1586  return SDL_Unsupported();
1587  }
1588  renderer->blendMode = blendMode;
1589  return 0;
1590 }
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:469

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

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

1549 {
1550  CHECK_RENDERER_MAGIC(renderer, -1);
1551 
1552  renderer->r = r;
1553  renderer->g = g;
1554  renderer->b = b;
1555  renderer->a = a;
1556  return 0;
1557 }
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 1210 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_LockMutex, SDL_RenderTargetSupported(), SDL_SetError, SDL_TEXTUREACCESS_TARGET, SDL_UnlockMutex, SDL_Unsupported, SDL_zero, SDL_Renderer::SetRenderTarget, SDL_Renderer::target, SDL_Renderer::target_mutex, 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().

1211 {
1212  if (!SDL_RenderTargetSupported(renderer)) {
1213  return SDL_Unsupported();
1214  }
1215  if (texture == renderer->target) {
1216  /* Nothing to do! */
1217  return 0;
1218  }
1219 
1220  /* texture == NULL is valid and means reset the target to the window */
1221  if (texture) {
1222  CHECK_TEXTURE_MAGIC(texture, -1);
1223  if (renderer != texture->renderer) {
1224  return SDL_SetError("Texture was not created with this renderer");
1225  }
1226  if (texture->access != SDL_TEXTUREACCESS_TARGET) {
1227  return SDL_SetError("Texture not created with SDL_TEXTUREACCESS_TARGET");
1228  }
1229  if (texture->native) {
1230  /* Always render to the native texture */
1231  texture = texture->native;
1232  }
1233  }
1234 
1235  SDL_LockMutex(renderer->target_mutex);
1236 
1237  if (texture && !renderer->target) {
1238  /* Make a backup of the viewport */
1239  renderer->viewport_backup = renderer->viewport;
1240  renderer->clip_rect_backup = renderer->clip_rect;
1241  renderer->clipping_enabled_backup = renderer->clipping_enabled;
1242  renderer->scale_backup = renderer->scale;
1243  renderer->logical_w_backup = renderer->logical_w;
1244  renderer->logical_h_backup = renderer->logical_h;
1245  }
1246  renderer->target = texture;
1247 
1248  if (renderer->SetRenderTarget(renderer, texture) < 0) {
1249  SDL_UnlockMutex(renderer->target_mutex);
1250  return -1;
1251  }
1252 
1253  if (texture) {
1254  renderer->viewport.x = 0;
1255  renderer->viewport.y = 0;
1256  renderer->viewport.w = texture->w;
1257  renderer->viewport.h = texture->h;
1258  SDL_zero(renderer->clip_rect);
1259  renderer->clipping_enabled = SDL_FALSE;
1260  renderer->scale.x = 1.0f;
1261  renderer->scale.y = 1.0f;
1262  renderer->logical_w = texture->w;
1263  renderer->logical_h = texture->h;
1264  } else {
1265  renderer->viewport = renderer->viewport_backup;
1266  renderer->clip_rect = renderer->clip_rect_backup;
1267  renderer->clipping_enabled = renderer->clipping_enabled_backup;
1268  renderer->scale = renderer->scale_backup;
1269  renderer->logical_w = renderer->logical_w_backup;
1270  renderer->logical_h = renderer->logical_h_backup;
1271  }
1272 
1273  SDL_UnlockMutex(renderer->target_mutex);
1274 
1275  if (renderer->UpdateViewport(renderer) < 0) {
1276  return -1;
1277  }
1278  if (renderer->UpdateClipRect(renderer) < 0) {
1279  return -1;
1280  }
1281 
1282  /* All set! */
1283  return 0;
1284 }
#define SDL_LockMutex
SDL_Rect clip_rect_backup
SDL_FPoint scale
SDL_mutex * target_mutex
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:1201
#define SDL_SetError
SDL_Renderer * renderer
Definition: SDL_sysrender.h:69
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:42
SDL_Rect viewport
int h
Definition: SDL_rect.h:67
#define SDL_UnlockMutex
SDL_Texture * native
Definition: SDL_sysrender.h:72
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 788 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().

789 {
791 
792  CHECK_TEXTURE_MAGIC(texture, -1);
793 
794  renderer = texture->renderer;
795  if (alpha < 255) {
797  } else {
798  texture->modMode &= ~SDL_TEXTUREMODULATE_ALPHA;
799  }
800  texture->a = alpha;
801  if (texture->native) {
802  return SDL_SetTextureAlphaMod(texture->native, alpha);
803  } else if (renderer->SetTextureAlphaMod) {
804  return renderer->SetTextureAlphaMod(renderer, texture);
805  } else {
806  return 0;
807  }
808 }
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:788
SDL_Renderer * renderer
Definition: SDL_sysrender.h:69
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:42
int(* SetTextureAlphaMod)(SDL_Renderer *renderer, SDL_Texture *texture)
Definition: SDL_sysrender.h:95
SDL_Texture * native
Definition: SDL_sysrender.h:72

§ 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 822 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().

823 {
825 
826  CHECK_TEXTURE_MAGIC(texture, -1);
827 
828  renderer = texture->renderer;
829  if (!IsSupportedBlendMode(renderer, blendMode)) {
830  return SDL_Unsupported();
831  }
832  texture->blendMode = blendMode;
833  if (texture->native) {
834  return SDL_SetTextureBlendMode(texture->native, blendMode);
835  } else if (renderer->SetTextureBlendMode) {
836  return renderer->SetTextureBlendMode(renderer, texture);
837  } else {
838  return 0;
839  }
840 }
SDL_BlendMode blendMode
Definition: SDL_sysrender.h:65
int(* SetTextureBlendMode)(SDL_Renderer *renderer, SDL_Texture *texture)
Definition: SDL_sysrender.h:97
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:822
static SDL_Renderer * renderer
SDL_Renderer * renderer
Definition: SDL_sysrender.h:69
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:42
SDL_Texture * native
Definition: SDL_sysrender.h:72
#define SDL_Unsupported()
Definition: SDL_error.h:53
static SDL_bool IsSupportedBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendMode)
Definition: SDL_render.c:469

§ 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 745 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().

746 {
748 
749  CHECK_TEXTURE_MAGIC(texture, -1);
750 
751  renderer = texture->renderer;
752  if (r < 255 || g < 255 || b < 255) {
754  } else {
755  texture->modMode &= ~SDL_TEXTUREMODULATE_COLOR;
756  }
757  texture->r = r;
758  texture->g = g;
759  texture->b = b;
760  if (texture->native) {
761  return SDL_SetTextureColorMod(texture->native, r, g, b);
762  } else if (renderer->SetTextureColorMod) {
763  return renderer->SetTextureColorMod(renderer, texture);
764  } else {
765  return 0;
766  }
767 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
int(* SetTextureColorMod)(SDL_Renderer *renderer, SDL_Texture *texture)
Definition: SDL_sysrender.h:93
static SDL_Renderer * renderer
SDL_Renderer * renderer
Definition: SDL_sysrender.h:69
#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:745
SDL_Texture * native
Definition: SDL_sysrender.h:72
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 1181 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().

1182 {
1184 
1185  CHECK_TEXTURE_MAGIC(texture, );
1186 
1187  if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
1188  return;
1189  }
1190  if (texture->yuv) {
1191  SDL_UnlockTextureYUV(texture);
1192  } else if (texture->native) {
1193  SDL_UnlockTextureNative(texture);
1194  } else {
1195  renderer = texture->renderer;
1196  renderer->UnlockTexture(renderer, texture);
1197  }
1198 }
static void SDL_UnlockTextureNative(SDL_Texture *texture)
Definition: SDL_render.c:1160
static SDL_Renderer * renderer
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:73
void(* UnlockTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
SDL_Renderer * renderer
Definition: SDL_sysrender.h:69
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:42
SDL_Texture * native
Definition: SDL_sysrender.h:72
static void SDL_UnlockTextureYUV(SDL_Texture *texture)
Definition: SDL_render.c:1139

§ SDL_UnlockTextureNative()

static void SDL_UnlockTextureNative ( SDL_Texture texture)
static

Definition at line 1160 of file SDL_render.c.

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

Referenced by SDL_UnlockTexture().

1161 {
1162  SDL_Texture *native = texture->native;
1163  void *native_pixels = NULL;
1164  int native_pitch = 0;
1165  const SDL_Rect *rect = &texture->locked_rect;
1166  const void* pixels = (void *) ((Uint8 *) texture->pixels +
1167  rect->y * texture->pitch +
1168  rect->x * SDL_BYTESPERPIXEL(texture->format));
1169  int pitch = texture->pitch;
1170 
1171  if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) {
1172  return;
1173  }
1174  SDL_ConvertPixels(rect->w, rect->h,
1175  texture->format, pixels, pitch,
1176  native->format, native_pixels, native_pitch);
1177  SDL_UnlockTexture(native);
1178 }
void * pixels
Definition: SDL_sysrender.h:74
SDL_Rect rect
Definition: testrelative.c:27
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:128
SDL_Rect locked_rect
Definition: SDL_sysrender.h:76
uint8_t Uint8
Definition: SDL_stdinc.h:179
void SDL_UnlockTexture(SDL_Texture *texture)
Unlock a texture, uploading the changes to video memory, if needed.
Definition: SDL_render.c:1181
int SDL_LockTexture(SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
Lock a portion of the texture for write-only pixel access.
Definition: SDL_render.c:1108
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 NULL
Definition: begin_code.h:164
int h
Definition: SDL_rect.h:67
Uint32 format
Definition: SDL_sysrender.h:60
#define SDL_ConvertPixels
SDL_Texture * native
Definition: SDL_sysrender.h:72
int y
Definition: SDL_rect.h:66
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

§ SDL_UnlockTextureYUV()

static void SDL_UnlockTextureYUV ( SDL_Texture texture)
static

Definition at line 1139 of file SDL_render.c.

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

Referenced by SDL_UnlockTexture().

1140 {
1141  SDL_Texture *native = texture->native;
1142  void *native_pixels = NULL;
1143  int native_pitch = 0;
1144  SDL_Rect rect;
1145 
1146  rect.x = 0;
1147  rect.y = 0;
1148  rect.w = texture->w;
1149  rect.h = texture->h;
1150 
1151  if (SDL_LockTexture(native, &rect, &native_pixels, &native_pitch) < 0) {
1152  return;
1153  }
1154  SDL_SW_CopyYUVToRGB(texture->yuv, &rect, native->format,
1155  rect.w, rect.h, native_pixels, native_pitch);
1156  SDL_UnlockTexture(native);
1157 }
SDL_Rect rect
Definition: testrelative.c:27
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:73
void SDL_UnlockTexture(SDL_Texture *texture)
Unlock a texture, uploading the changes to video memory, if needed.
Definition: SDL_render.c:1181
int SDL_LockTexture(SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
Lock a portion of the texture for write-only pixel access.
Definition: SDL_render.c:1108
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
#define NULL
Definition: begin_code.h:164
int h
Definition: SDL_rect.h:67
int SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture *swdata, const SDL_Rect *srcrect, Uint32 target_format, int w, int h, void *pixels, int pitch)
Definition: SDL_yuv_sw.c:334
Uint32 format
Definition: SDL_sysrender.h:60
SDL_Texture * native
Definition: SDL_sysrender.h:72
int y
Definition: SDL_rect.h:66
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

§ SDL_UpdateTexture()

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

Update the given texture rectangle with new pixel data.

Parameters
textureThe texture to update
rectA pointer to the rectangle of pixels to update, or NULL to update the entire texture.
pixelsThe raw pixel data 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 941 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().

943 {
945  SDL_Rect full_rect;
946 
947  CHECK_TEXTURE_MAGIC(texture, -1);
948 
949  if (!pixels) {
950  return SDL_InvalidParamError("pixels");
951  }
952  if (!pitch) {
953  return SDL_InvalidParamError("pitch");
954  }
955 
956  if (!rect) {
957  full_rect.x = 0;
958  full_rect.y = 0;
959  full_rect.w = texture->w;
960  full_rect.h = texture->h;
961  rect = &full_rect;
962  }
963 
964  if ((rect->w == 0) || (rect->h == 0)) {
965  return 0; /* nothing to do. */
966  } else if (texture->yuv) {
967  return SDL_UpdateTextureYUV(texture, rect, pixels, pitch);
968  } else if (texture->native) {
969  return SDL_UpdateTextureNative(texture, rect, pixels, pitch);
970  } else {
971  renderer = texture->renderer;
972  return renderer->UpdateTexture(renderer, texture, rect, pixels, pitch);
973  }
974 }
static int SDL_UpdateTextureNative(SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
Definition: SDL_render.c:900
#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:99
static SDL_Renderer * renderer
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:73
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:854
SDL_Renderer * renderer
Definition: SDL_sysrender.h:69
#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:72
int y
Definition: SDL_rect.h:66
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

§ SDL_UpdateTextureNative()

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

Definition at line 900 of file SDL_render.c.

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

Referenced by SDL_UpdateTexture().

902 {
903  SDL_Texture *native = texture->native;
904 
905  if (!rect->w || !rect->h) {
906  return 0; /* nothing to do. */
907  }
908 
909  if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
910  /* We can lock the texture and copy to it */
911  void *native_pixels = NULL;
912  int native_pitch = 0;
913 
914  if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) {
915  return -1;
916  }
917  SDL_ConvertPixels(rect->w, rect->h,
918  texture->format, pixels, pitch,
919  native->format, native_pixels, native_pitch);
920  SDL_UnlockTexture(native);
921  } else {
922  /* Use a temporary buffer for updating */
923  const int temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3);
924  const size_t alloclen = rect->h * temp_pitch;
925  if (alloclen > 0) {
926  void *temp_pixels = SDL_malloc(alloclen);
927  if (!temp_pixels) {
928  return SDL_OutOfMemory();
929  }
930  SDL_ConvertPixels(rect->w, rect->h,
931  texture->format, pixels, pitch,
932  native->format, temp_pixels, temp_pitch);
933  SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch);
934  SDL_free(temp_pixels);
935  }
936  }
937  return 0;
938 }
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:128
#define SDL_free
void SDL_UnlockTexture(SDL_Texture *texture)
Unlock a texture, uploading the changes to video memory, if needed.
Definition: SDL_render.c:1181
int SDL_LockTexture(SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
Lock a portion of the texture for write-only pixel access.
Definition: SDL_render.c:1108
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
int w
Definition: SDL_rect.h:67
int SDL_UpdateTexture(SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
Update the given texture rectangle with new pixel data.
Definition: SDL_render.c:941
#define NULL
Definition: begin_code.h:164
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
int h
Definition: SDL_rect.h:67
Uint32 format
Definition: SDL_sysrender.h:60
#define SDL_malloc
#define SDL_ConvertPixels
SDL_Texture * native
Definition: SDL_sysrender.h:72

§ SDL_UpdateTextureYUV()

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

Definition at line 854 of file SDL_render.c.

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

Referenced by SDL_UpdateTexture().

856 {
857  SDL_Texture *native = texture->native;
858  SDL_Rect full_rect;
859 
860  if (SDL_SW_UpdateYUVTexture(texture->yuv, rect, pixels, pitch) < 0) {
861  return -1;
862  }
863 
864  full_rect.x = 0;
865  full_rect.y = 0;
866  full_rect.w = texture->w;
867  full_rect.h = texture->h;
868  rect = &full_rect;
869 
870  if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
871  /* We can lock the texture and copy to it */
872  void *native_pixels = NULL;
873  int native_pitch = 0;
874 
875  if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) {
876  return -1;
877  }
878  SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format,
879  rect->w, rect->h, native_pixels, native_pitch);
880  SDL_UnlockTexture(native);
881  } else {
882  /* Use a temporary buffer for updating */
883  const int temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3);
884  const size_t alloclen = rect->h * temp_pitch;
885  if (alloclen > 0) {
886  void *temp_pixels = SDL_malloc(alloclen);
887  if (!temp_pixels) {
888  return SDL_OutOfMemory();
889  }
890  SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format,
891  rect->w, rect->h, temp_pixels, temp_pitch);
892  SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch);
893  SDL_free(temp_pixels);
894  }
895  }
896  return 0;
897 }
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:128
int SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect, const void *pixels, int pitch)
Definition: SDL_yuv_sw.c:139
#define SDL_free
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:73
void SDL_UnlockTexture(SDL_Texture *texture)
Unlock a texture, uploading the changes to video memory, if needed.
Definition: SDL_render.c:1181
int SDL_LockTexture(SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
Lock a portion of the texture for write-only pixel access.
Definition: SDL_render.c:1108
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
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:941
#define NULL
Definition: begin_code.h:164
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
int h
Definition: SDL_rect.h:67
int SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture *swdata, const SDL_Rect *srcrect, Uint32 target_format, int w, int h, void *pixels, int pitch)
Definition: SDL_yuv_sw.c:334
Uint32 format
Definition: SDL_sysrender.h:60
#define SDL_malloc
SDL_Texture * native
Definition: SDL_sysrender.h:72
int y
Definition: SDL_rect.h:66
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

§ SDL_UpdateTextureYUVPlanar()

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

Definition at line 977 of file SDL_render.c.

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

Referenced by SDL_UpdateYUVTexture().

981 {
982  SDL_Texture *native = texture->native;
983  SDL_Rect full_rect;
984 
985  if (SDL_SW_UpdateYUVTexturePlanar(texture->yuv, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch) < 0) {
986  return -1;
987  }
988 
989  full_rect.x = 0;
990  full_rect.y = 0;
991  full_rect.w = texture->w;
992  full_rect.h = texture->h;
993  rect = &full_rect;
994 
995  if (!rect->w || !rect->h) {
996  return 0; /* nothing to do. */
997  }
998 
999  if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
1000  /* We can lock the texture and copy to it */
1001  void *native_pixels = NULL;
1002  int native_pitch = 0;
1003 
1004  if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) {
1005  return -1;
1006  }
1007  SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format,
1008  rect->w, rect->h, native_pixels, native_pitch);
1009  SDL_UnlockTexture(native);
1010  } else {
1011  /* Use a temporary buffer for updating */
1012  const int temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3);
1013  const size_t alloclen = rect->h * temp_pitch;
1014  if (alloclen > 0) {
1015  void *temp_pixels = SDL_malloc(alloclen);
1016  if (!temp_pixels) {
1017  return SDL_OutOfMemory();
1018  }
1019  SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format,
1020  rect->w, rect->h, temp_pixels, temp_pitch);
1021  SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch);
1022  SDL_free(temp_pixels);
1023  }
1024  }
1025  return 0;
1026 }
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:128
#define SDL_free
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:73
void SDL_UnlockTexture(SDL_Texture *texture)
Unlock a texture, uploading the changes to video memory, if needed.
Definition: SDL_render.c:1181
int SDL_LockTexture(SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
Lock a portion of the texture for write-only pixel access.
Definition: SDL_render.c:1108
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
int SDL_UpdateTexture(SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
Update the given texture rectangle with new pixel data.
Definition: SDL_render.c:941
#define NULL
Definition: begin_code.h:164
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
int SDL_SW_UpdateYUVTexturePlanar(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *Uplane, int Upitch, const Uint8 *Vplane, int Vpitch)
Definition: SDL_yuv_sw.c:247
int h
Definition: SDL_rect.h:67
int SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture *swdata, const SDL_Rect *srcrect, Uint32 target_format, int w, int h, void *pixels, int pitch)
Definition: SDL_yuv_sw.c:334
Uint32 format
Definition: SDL_sysrender.h:60
#define SDL_malloc
SDL_Texture * native
Definition: SDL_sysrender.h:72
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 1028 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.

1032 {
1034  SDL_Rect full_rect;
1035 
1036  CHECK_TEXTURE_MAGIC(texture, -1);
1037 
1038  if (!Yplane) {
1039  return SDL_InvalidParamError("Yplane");
1040  }
1041  if (!Ypitch) {
1042  return SDL_InvalidParamError("Ypitch");
1043  }
1044  if (!Uplane) {
1045  return SDL_InvalidParamError("Uplane");
1046  }
1047  if (!Upitch) {
1048  return SDL_InvalidParamError("Upitch");
1049  }
1050  if (!Vplane) {
1051  return SDL_InvalidParamError("Vplane");
1052  }
1053  if (!Vpitch) {
1054  return SDL_InvalidParamError("Vpitch");
1055  }
1056 
1057  if (texture->format != SDL_PIXELFORMAT_YV12 &&
1058  texture->format != SDL_PIXELFORMAT_IYUV) {
1059  return SDL_SetError("Texture format must by YV12 or IYUV");
1060  }
1061 
1062  if (!rect) {
1063  full_rect.x = 0;
1064  full_rect.y = 0;
1065  full_rect.w = texture->w;
1066  full_rect.h = texture->h;
1067  rect = &full_rect;
1068  }
1069 
1070  if (!rect->w || !rect->h) {
1071  return 0; /* nothing to do. */
1072  }
1073 
1074  if (texture->yuv) {
1075  return SDL_UpdateTextureYUVPlanar(texture, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch);
1076  } else {
1077  SDL_assert(!texture->native);
1078  renderer = texture->renderer;
1079  SDL_assert(renderer->UpdateTextureYUV);
1080  if (renderer->UpdateTextureYUV) {
1081  return renderer->UpdateTextureYUV(renderer, texture, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch);
1082  } else {
1083  return SDL_Unsupported();
1084  }
1085  }
1086 }
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:977
#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)
static SDL_Renderer * renderer
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:73
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:69
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:42
int h
Definition: SDL_rect.h:67
Uint32 format
Definition: SDL_sysrender.h:60
SDL_Texture * native
Definition: SDL_sysrender.h:72
int y
Definition: SDL_rect.h:66
#define SDL_Unsupported()
Definition: SDL_error.h:53
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

§ UpdateLogicalSize()

static int UpdateLogicalSize ( SDL_Renderer renderer)
static

Definition at line 1293 of file SDL_render.c.

References SDL_Rect::h, SDL_Renderer::integer_scale, SDL_Renderer::logical_h, SDL_Renderer::logical_w, NULL, SDL_ceil, SDL_fabs, SDL_FALSE, SDL_GetCurrentVideoDriver, SDL_GetHint, SDL_GetRendererOutputSize(), SDL_HINT_RENDER_LOGICAL_SIZE_MODE, SDL_RenderSetScale(), SDL_RenderSetViewport(), SDL_strcasecmp, SDL_TRUE, viewport, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

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

1294 {
1295  int w = 1, h = 1;
1296  float want_aspect;
1297  float real_aspect;
1298  float scale;
1300  /* 0 is for letterbox, 1 is for overscan */
1301  int scale_policy = 0;
1302  const char *hint;
1303 
1304  if (!renderer->logical_w || !renderer->logical_h) {
1305  return 0;
1306  }
1307  if (SDL_GetRendererOutputSize(renderer, &w, &h) < 0) {
1308  return -1;
1309  }
1310 
1312  if (hint && (*hint == '1' || SDL_strcasecmp(hint, "overscan") == 0)) {
1313 #if SDL_VIDEO_RENDER_D3D
1314  SDL_bool overscan_supported = SDL_TRUE;
1315  /* Unfortunately, Direct3D 9 doesn't support negative viewport numbers
1316  which the overscan implementation relies on.
1317  */
1318  if (SDL_strcasecmp(SDL_GetCurrentVideoDriver(), "direct3d") == 0) {
1319  overscan_supported = SDL_FALSE;
1320  }
1321  if (overscan_supported) {
1322  scale_policy = 1;
1323  }
1324 #else
1325  scale_policy = 1;
1326 #endif
1327  }
1328 
1329  want_aspect = (float)renderer->logical_w / renderer->logical_h;
1330  real_aspect = (float)w / h;
1331 
1332  /* Clear the scale because we're setting viewport in output coordinates */
1333  SDL_RenderSetScale(renderer, 1.0f, 1.0f);
1334 
1335  if (renderer->integer_scale) {
1336  if (want_aspect > real_aspect) {
1337  scale = (float)(w / renderer->logical_w);
1338  } else {
1339  scale = (float)(h / renderer->logical_h);
1340  }
1341  viewport.w = (int)SDL_ceil(renderer->logical_w * scale);
1342  viewport.x = (w - viewport.w) / 2;
1343  viewport.h = (int)SDL_ceil(renderer->logical_h * scale);
1344  viewport.y = (h - viewport.h) / 2;
1345 
1346  SDL_RenderSetViewport(renderer, &viewport);
1347  } else if (SDL_fabs(want_aspect-real_aspect) < 0.0001) {
1348  /* The aspect ratios are the same, just scale appropriately */
1349  scale = (float)w / renderer->logical_w;
1350  SDL_RenderSetViewport(renderer, NULL);
1351  } else if (want_aspect > real_aspect) {
1352  if (scale_policy == 1) {
1353  /* We want a wider aspect ratio than is available -
1354  zoom so logical height matches the real height
1355  and the width will grow off the screen
1356  */
1357  scale = (float)h / renderer->logical_h;
1358  viewport.y = 0;
1359  viewport.h = h;
1360  viewport.w = (int)SDL_ceil(renderer->logical_w * scale);
1361  viewport.x = (w - viewport.w) / 2;
1362  SDL_RenderSetViewport(renderer, &viewport);
1363  } else {
1364  /* We want a wider aspect ratio than is available - letterbox it */
1365  scale = (float)w / renderer->logical_w;
1366  viewport.x = 0;
1367  viewport.w = w;
1368  viewport.h = (int)SDL_ceil(renderer->logical_h * scale);
1369  viewport.y = (h - viewport.h) / 2;
1370  SDL_RenderSetViewport(renderer, &viewport);
1371  }
1372  } else {
1373  if (scale_policy == 1) {
1374  /* We want a narrower aspect ratio than is available -
1375  zoom so logical width matches the real width
1376  and the height will grow off the screen
1377  */
1378  scale = (float)w / renderer->logical_w;
1379  viewport.x = 0;
1380  viewport.w = w;
1381  viewport.h = (int)SDL_ceil(renderer->logical_h * scale);
1382  viewport.y = (h - viewport.h) / 2;
1383  SDL_RenderSetViewport(renderer, &viewport);
1384  } else {
1385  /* We want a narrower aspect ratio than is available - use side-bars */
1386  scale = (float)h / renderer->logical_h;
1387  viewport.y = 0;
1388  viewport.h = h;
1389  viewport.w = (int)SDL_ceil(renderer->logical_w * scale);
1390  viewport.x = (w - viewport.w) / 2;
1391  SDL_RenderSetViewport(renderer, &viewport);
1392  }
1393  }
1394 
1395  /* Set the new scale */
1396  SDL_RenderSetScale(renderer, scale, scale);
1397 
1398  return 0;
1399 }
GLenum GLenum GLenum GLenum GLenum scale
#define SDL_ceil
#define SDL_fabs
GLfloat GLfloat GLfloat GLfloat h
#define SDL_GetHint
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:1453
#define SDL_strcasecmp
int SDL_GetRendererOutputSize(SDL_Renderer *renderer, int *w, int *h)
Get the output size in pixels of a rendering context.
Definition: SDL_render.c:451
GLubyte GLubyte GLubyte GLubyte w
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
int SDL_RenderSetScale(SDL_Renderer *renderer, float scaleX, float scaleY)
Set the drawing scale for rendering on the current target.
Definition: SDL_render.c:1524
#define SDL_HINT_RENDER_LOGICAL_SIZE_MODE
A variable controlling the scaling policy for SDL_RenderSetLogicalSize.
Definition: SDL_hints.h:131
#define NULL
Definition: begin_code.h:164
SDL_bool
Definition: SDL_stdinc.h:161
#define SDL_GetCurrentVideoDriver
int h
Definition: SDL_rect.h:67
SDL_Rect viewport
Definition: testviewport.c:28
int y
Definition: SDL_rect.h:66
SDL_bool integer_scale
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

Variable Documentation

§ render_drivers

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

Definition at line 76 of file SDL_render.c.

§ renderer_magic

char renderer_magic
static

Definition at line 105 of file SDL_render.c.

Referenced by SDL_CreateRenderer(), and SDL_CreateSoftwareRenderer().

§ texture_magic

char texture_magic
static

Definition at line 106 of file SDL_render.c.

Referenced by SDL_CreateTexture().