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

Go to the source code of this file.

Data Structures

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

Enumerations

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

Functions

int SDL_GetNumRenderDrivers (void)
 Get the number of 2D rendering drivers available for the current display. More...
 
int SDL_GetRenderDriverInfo (int index, SDL_RendererInfo *info)
 Get information about a specific 2D rendering driver for the current display. More...
 
int SDL_CreateWindowAndRenderer (int width, int height, Uint32 window_flags, SDL_Window **window, SDL_Renderer **renderer)
 Create a window and default renderer. More...
 
SDL_RendererSDL_CreateRenderer (SDL_Window *window, int index, Uint32 flags)
 Create a 2D rendering context for a window. More...
 
SDL_RendererSDL_CreateSoftwareRenderer (SDL_Surface *surface)
 Create a 2D software rendering context for a surface. More...
 
SDL_RendererSDL_GetRenderer (SDL_Window *window)
 Get the renderer associated with a window. More...
 
int SDL_GetRendererInfo (SDL_Renderer *renderer, SDL_RendererInfo *info)
 Get information about a rendering context. More...
 
int SDL_GetRendererOutputSize (SDL_Renderer *renderer, int *w, int *h)
 Get the output size in pixels of a rendering context. More...
 
SDL_TextureSDL_CreateTexture (SDL_Renderer *renderer, Uint32 format, int access, int w, int h)
 Create a texture for a rendering context. More...
 
SDL_TextureSDL_CreateTextureFromSurface (SDL_Renderer *renderer, SDL_Surface *surface)
 Create a texture from an existing surface. More...
 
int SDL_QueryTexture (SDL_Texture *texture, Uint32 *format, int *access, int *w, int *h)
 Query the attributes of a texture. More...
 
int SDL_SetTextureColorMod (SDL_Texture *texture, Uint8 r, Uint8 g, Uint8 b)
 Set an additional color value used in render copy operations. More...
 
int SDL_GetTextureColorMod (SDL_Texture *texture, Uint8 *r, Uint8 *g, Uint8 *b)
 Get the additional color value used in render copy operations. More...
 
int SDL_SetTextureAlphaMod (SDL_Texture *texture, Uint8 alpha)
 Set an additional alpha value used in render copy operations. More...
 
int SDL_GetTextureAlphaMod (SDL_Texture *texture, Uint8 *alpha)
 Get the additional alpha value used in render copy operations. More...
 
int SDL_SetTextureBlendMode (SDL_Texture *texture, SDL_BlendMode blendMode)
 Set the blend mode used for texture copy operations. More...
 
int SDL_GetTextureBlendMode (SDL_Texture *texture, SDL_BlendMode *blendMode)
 Get the blend mode used for texture copy operations. More...
 
int SDL_UpdateTexture (SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
 Update the given texture rectangle with new pixel data. More...
 
int SDL_UpdateYUVTexture (SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *Uplane, int Upitch, const Uint8 *Vplane, int Vpitch)
 Update a rectangle within a planar YV12 or IYUV texture with new pixel data. More...
 
int SDL_LockTexture (SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
 Lock a portion of the texture for write-only pixel access. More...
 
void SDL_UnlockTexture (SDL_Texture *texture)
 Unlock a texture, uploading the changes to video memory, if needed. More...
 
SDL_bool SDL_RenderTargetSupported (SDL_Renderer *renderer)
 Determines whether a window supports the use of render targets. More...
 
int SDL_SetRenderTarget (SDL_Renderer *renderer, SDL_Texture *texture)
 Set a texture as the current rendering target. More...
 
SDL_TextureSDL_GetRenderTarget (SDL_Renderer *renderer)
 Get the current render target or NULL for the default render target. More...
 
int SDL_RenderSetLogicalSize (SDL_Renderer *renderer, int w, int h)
 Set device independent resolution for rendering. More...
 
void SDL_RenderGetLogicalSize (SDL_Renderer *renderer, int *w, int *h)
 Get device independent resolution for rendering. More...
 
int SDL_RenderSetIntegerScale (SDL_Renderer *renderer, SDL_bool enable)
 Set whether to force integer scales for resolution-independent rendering. More...
 
SDL_bool SDL_RenderGetIntegerScale (SDL_Renderer *renderer)
 Get whether integer scales are forced for resolution-independent rendering. More...
 
int SDL_RenderSetViewport (SDL_Renderer *renderer, const SDL_Rect *rect)
 Set the drawing area for rendering on the current target. More...
 
void SDL_RenderGetViewport (SDL_Renderer *renderer, SDL_Rect *rect)
 Get the drawing area for the current target. More...
 
int SDL_RenderSetClipRect (SDL_Renderer *renderer, const SDL_Rect *rect)
 Set the clip rectangle for the current target. More...
 
void SDL_RenderGetClipRect (SDL_Renderer *renderer, SDL_Rect *rect)
 Get the clip rectangle for the current target. More...
 
SDL_bool SDL_RenderIsClipEnabled (SDL_Renderer *renderer)
 Get whether clipping is enabled on the given renderer. More...
 
int SDL_RenderSetScale (SDL_Renderer *renderer, float scaleX, float scaleY)
 Set the drawing scale for rendering on the current target. More...
 
void SDL_RenderGetScale (SDL_Renderer *renderer, float *scaleX, float *scaleY)
 Get the drawing scale for the current target. More...
 
int SDL_SetRenderDrawColor (SDL_Renderer *renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
 Set the color used for drawing operations (Rect, Line and Clear). More...
 
int SDL_GetRenderDrawColor (SDL_Renderer *renderer, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
 Get the color used for drawing operations (Rect, Line and Clear). More...
 
int SDL_SetRenderDrawBlendMode (SDL_Renderer *renderer, SDL_BlendMode blendMode)
 Set the blend mode used for drawing operations (Fill and Line). More...
 
int SDL_GetRenderDrawBlendMode (SDL_Renderer *renderer, SDL_BlendMode *blendMode)
 Get the blend mode used for drawing operations. More...
 
int SDL_RenderClear (SDL_Renderer *renderer)
 Clear the current rendering target with the drawing color. More...
 
int SDL_RenderDrawPoint (SDL_Renderer *renderer, int x, int y)
 Draw a point on the current rendering target. More...
 
int SDL_RenderDrawPoints (SDL_Renderer *renderer, const SDL_Point *points, int count)
 Draw multiple points on the current rendering target. More...
 
int SDL_RenderDrawLine (SDL_Renderer *renderer, int x1, int y1, int x2, int y2)
 Draw a line on the current rendering target. More...
 
int SDL_RenderDrawLines (SDL_Renderer *renderer, const SDL_Point *points, int count)
 Draw a series of connected lines on the current rendering target. More...
 
int SDL_RenderDrawRect (SDL_Renderer *renderer, const SDL_Rect *rect)
 Draw a rectangle on the current rendering target. More...
 
int SDL_RenderDrawRects (SDL_Renderer *renderer, const SDL_Rect *rects, int count)
 Draw some number of rectangles on the current rendering target. More...
 
int SDL_RenderFillRect (SDL_Renderer *renderer, const SDL_Rect *rect)
 Fill a rectangle on the current rendering target with the drawing color. More...
 
int SDL_RenderFillRects (SDL_Renderer *renderer, const SDL_Rect *rects, int count)
 Fill some number of rectangles on the current rendering target with the drawing color. More...
 
int SDL_RenderCopy (SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect)
 Copy a portion of the texture to the current rendering target. More...
 
int SDL_RenderCopyEx (SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect, const double angle, const SDL_Point *center, const SDL_RendererFlip flip)
 Copy a portion of the source texture to the current rendering target, rotating it by angle around the given center. More...
 
int SDL_RenderDrawPointF (SDL_Renderer *renderer, float x, float y)
 Draw a point on the current rendering target. More...
 
int SDL_RenderDrawPointsF (SDL_Renderer *renderer, const SDL_FPoint *points, int count)
 Draw multiple points on the current rendering target. More...
 
int SDL_RenderDrawLineF (SDL_Renderer *renderer, float x1, float y1, float x2, float y2)
 Draw a line on the current rendering target. More...
 
int SDL_RenderDrawLinesF (SDL_Renderer *renderer, const SDL_FPoint *points, int count)
 Draw a series of connected lines on the current rendering target. More...
 
int SDL_RenderDrawRectF (SDL_Renderer *renderer, const SDL_FRect *rect)
 Draw a rectangle on the current rendering target. More...
 
int SDL_RenderDrawRectsF (SDL_Renderer *renderer, const SDL_FRect *rects, int count)
 Draw some number of rectangles on the current rendering target. More...
 
int SDL_RenderFillRectF (SDL_Renderer *renderer, const SDL_FRect *rect)
 Fill a rectangle on the current rendering target with the drawing color. More...
 
int SDL_RenderFillRectsF (SDL_Renderer *renderer, const SDL_FRect *rects, int count)
 Fill some number of rectangles on the current rendering target with the drawing color. More...
 
int SDL_RenderCopyF (SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_FRect *dstrect)
 Copy a portion of the texture to the current rendering target. More...
 
int SDL_RenderCopyExF (SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_FRect *dstrect, const double angle, const SDL_FPoint *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_RenderFlush (SDL_Renderer *renderer)
 Force the rendering context to flush any pending commands to the underlying rendering API. More...
 
int SDL_GL_BindTexture (SDL_Texture *texture, float *texw, float *texh)
 Bind the texture to the current OpenGL/ES/ES2 context for use with OpenGL instructions. More...
 
int SDL_GL_UnbindTexture (SDL_Texture *texture)
 Unbind a texture from the current OpenGL/ES/ES2 context. More...
 
voidSDL_RenderGetMetalLayer (SDL_Renderer *renderer)
 Get the CAMetalLayer associated with the given Metal renderer. More...
 
voidSDL_RenderGetMetalCommandEncoder (SDL_Renderer *renderer)
 Get the Metal command encoder for the current frame. More...
 

Detailed Description

Header file for SDL 2D rendering functions.

This API supports the following features:

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

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

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

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

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

Definition in file SDL_render.h.

Enumeration Type Documentation

◆ SDL_RendererFlags

Flags used when creating a rendering context.

Enumerator
SDL_RENDERER_SOFTWARE 

The renderer is a software fallback

SDL_RENDERER_ACCELERATED 

The renderer uses hardware acceleration

SDL_RENDERER_PRESENTVSYNC 

Present is synchronized with the refresh rate

SDL_RENDERER_TARGETTEXTURE 

The renderer supports rendering to texture

Definition at line 64 of file SDL_render.h.

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

◆ SDL_RendererFlip

enum 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 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 Uint32 return SDL_AudioCVT SDL_AudioFormat Uint8 int SDL_AudioFormat Uint8 int return Uint8 const Uint8 Uint32 int const char return return return return return return return return Uint32 return Uint32 SDL_Event return SDL_Event int return SDL_EventFilter void SDL_EventFilter void SDL_EventFilter void int return const char const char return SDL_JoystickGUID return int return int return SDL_GameController return int return const char return SDL_GameController SDL_GameControllerAxis return const char return SDL_GameController SDL_GameControllerButton return SDL_GameController SDL_RWops return SDL_TouchID SDL_RWops return int return int return return SDL_Joystick return SDL_Haptic SDL_Haptic return SDL_Haptic return SDL_Haptic SDL_HapticEffect return SDL_Haptic int Uint32 return SDL_Haptic int SDL_Haptic int return SDL_Haptic return SDL_Haptic return SDL_Haptic return SDL_Haptic return const char const char return const char SDL_HintCallback void int return SDL_Joystick return SDL_Joystick return const char return SDL_Joystick return SDL_Joystick return SDL_Joystick return int return SDL_Joystick int return SDL_Joystick int return return return SDL_Scancode return SDL_Scancode return SDL_Keycode return return const char return void int SDL_LogPriority SDL_LogOutputFunction void Uint32 const char const char SDL_Window return int int return SDL_Window int int return SDL_Surface int int return SDL_Cursor return int return SDL_mutex return SDL_mutex return Uint32 return SDL_sem return SDL_sem Uint32 return SDL_sem return SDL_cond SDL_cond return SDL_cond SDL_mutex Uint32 return Uint32 int Uint32 Uint32 Uint32 Uint32 return Uint32 return int return SDL_Palette const SDL_Color int int return const SDL_PixelFormat Uint8 Uint8 Uint8 return Uint32 const SDL_PixelFormat Uint8 Uint8 Uint8 float Uint16 int int return const SDL_Rect const SDL_Rect SDL_Rect return const SDL_Point int const SDL_Rect SDL_Rect return return int int Uint32 SDL_Window SDL_Renderer return SDL_Surface return SDL_Renderer SDL_RendererInfo return SDL_Renderer Uint32 int int int return SDL_Texture Uint32 int int int return SDL_Texture Uint8 Uint8 Uint8 return SDL_Texture Uint8 return SDL_Texture SDL_BlendMode return SDL_Texture const SDL_Rect const Uint8 int const Uint8 int const Uint8 int return SDL_Texture SDL_Renderer SDL_Texture return SDL_Renderer int int return SDL_Renderer const SDL_Rect return SDL_Renderer const SDL_Rect return SDL_Renderer float float return SDL_Renderer Uint8 Uint8 Uint8 Uint8 return SDL_Renderer SDL_BlendMode return SDL_Renderer return SDL_Renderer const SDL_Point int return SDL_Renderer const SDL_Point int return SDL_Renderer const SDL_Rect int return SDL_Renderer const SDL_Rect int return SDL_Renderer SDL_Texture const SDL_Rect const SDL_Rect const double const SDL_Point const SDL_RendererFlip return SDL_Renderer SDL_Renderer SDL_Texture return void int return return SDL_RWops return SDL_RWops return SDL_RWops return SDL_RWops return SDL_RWops Uint16 return SDL_RWops Uint32 return SDL_RWops Uint64 return const char unsigned int unsigned int unsigned int unsigned int Uint32 return SDL_Window SDL_Surface SDL_WindowShapeMode return size_t return void size_t return const char return void size_t size_t int(*) g int return int return int size_t return size_t return const wchar_t return const wchar_t size_t return const char size_t return const char size_t return char return char return const char int return int char int return long char int return Sint64 char int return const char return const char char int return const char char int return const char char return const char const char size_t return const char const char size_t return double return double return double return double return double return double return double int return float return const char const char return SDL_iconv_t const char size_t char size_t return Uint32 int int int Uint32 Uint32 Uint32 Uint32 return SDL_Surface SDL_Surface return SDL_RWops int return SDL_Surface int return SDL_Surface Uint32 return SDL_Surface Uint8 Uint8 Uint8 return SDL_Surface Uint8 return SDL_Surface SDL_BlendMode return SDL_Surface SDL_Rect SDL_Surface Uint32 Uint32 return SDL_Surface const SDL_Rect Uint32 return SDL_Surface const SDL_Rect SDL_Surface SDL_Rect return SDL_Surface const SDL_Rect SDL_Surface const SDL_Rect return SDL_Surface SDL_Rect SDL_Surface SDL_Rect return SDL_Thread return SDL_Thread return SDL_Thread int return SDL_TLSID const void void(*) return return Uint32 SDL_TimerID return int return SDL_TouchID int return return return const char return return int return int return int SDL_DisplayMode return int const SDL_DisplayMode SDL_DisplayMode return SDL_Window const SDL_DisplayMode return SDL_Window return const void return Uint32 return SDL_Window const char SDL_Window SDL_Surface SDL_Window const char return SDL_Window int int SDL_Window int int SDL_Window int int SDL_Window int int SDL_Window SDL_Window SDL_Window SDL_Window Uint32 return SDL_Window return SDL_Window SDL_bool SDL_Window float return SDL_Window const Uint16 const Uint16 const Uint16 return SDL_Window const char return SDL_GLattr int return SDL_Window return return SDL_Window int int return SDL_GLContext SDL_RWops int return return void return int int return double return SDL_bool return int int return SDL_AudioDeviceID const void Uint32 return SDL_AudioDeviceID int float float float return SDL_JoystickID return int SDL_Rect return SDL_Window float return SDL_Window return SDL_Renderer SDL_bool return SDL_AudioDeviceID void Uint32 return Uint32 int int int Uint32 return const char SDL_bool return int return SDL_Joystick return SDL_Joystick return SDL_GameController return return int return int return int return SDL_RWops size_t int return SDL_BlendFactor SDL_BlendFactor SDL_BlendOperation SDL_BlendFactor SDL_BlendFactor SDL_BlendOperation return const char return SDL_Window VkInstance VkSurfaceKHR return SDL_malloc_func SDL_calloc_func SDL_realloc_func SDL_free_func return SDL_AudioStream const void int return SDL_AudioStream SDL_AudioStream float return float return float return float return float return float int return float float return return SDL_Renderer return double return int return double return const wchar_t return SDL_Joystick Uint16 Uint16 Uint32 return int return int return int return SDL_Sensor return SDL_Sensor return SDL_Sensor float int return int return SDL_ThreadFunction const char const size_t void return SDL_Joystick return SDL_Renderer return SDL_Renderer const SDL_FPoint int return SDL_Renderer const SDL_FPoint int return SDL_Renderer const SDL_FRect int return SDL_Renderer const SDL_FRect int return SDL_Renderer SDL_Texture const SDL_Rect const SDL_FRect const double const SDL_FPoint const SDL_RendererFlip

Flip constants for SDL_RenderCopyEx.

Enumerator
SDL_FLIP_NONE 

Do not flip

SDL_FLIP_HORIZONTAL 

flip horizontally

SDL_FLIP_VERTICAL 

flip vertically

Definition at line 111 of file SDL_render.h.

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

◆ SDL_TextureAccess

The access pattern allowed for a texture.

Enumerator
SDL_TEXTUREACCESS_STATIC 

Changes rarely, not lockable

SDL_TEXTUREACCESS_STREAMING 

Changes frequently, lockable

SDL_TEXTUREACCESS_TARGET 

Texture can be used as a render target

Definition at line 91 of file SDL_render.h.

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

◆ SDL_TextureModulate

The texture channel modulation used in SDL_RenderCopy().

Enumerator
SDL_TEXTUREMODULATE_NONE 

No modulation

SDL_TEXTUREMODULATE_COLOR 

srcC = srcC * color

SDL_TEXTUREMODULATE_ALPHA 

srcA = srcA * alpha

Definition at line 101 of file SDL_render.h.

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

Function Documentation

◆ SDL_CreateRenderer()

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

Create a 2D rendering context for a window.

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

Definition at line 835 of file SDL_render.c.

References SDL_Renderer::always_batch, Android_ActivityMutex_Lock_Running(), Android_ActivityMutex_Unlock(), SDL_Renderer::batching, 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, SDL_Renderer::render_command_generation, 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_BATCHING, 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, VerifyDrawQueueFunctions(), SDL_Renderer::window, window_h, window_w, SDL_FPoint::x, and SDL_FPoint::y.

Referenced by SDL_CreateWindowAndRenderer().

836 {
837 #if !SDL_RENDER_DISABLED
839  int n = SDL_GetNumRenderDrivers();
840  SDL_bool batching = SDL_TRUE;
841  const char *hint;
842 
843 #if defined(__ANDROID__)
845 #endif
846 
847  if (!window) {
848  SDL_SetError("Invalid window");
849  goto error;
850  }
851 
852  if (SDL_GetRenderer(window)) {
853  SDL_SetError("Renderer already associated with window");
854  goto error;
855  }
856 
860  } else {
862  }
863  }
864 
865  if (index < 0) {
867  if (hint) {
868  for (index = 0; index < n; ++index) {
869  const SDL_RenderDriver *driver = render_drivers[index];
870 
871  if (SDL_strcasecmp(hint, driver->info.name) == 0) {
872  /* Create a new renderer instance */
873  renderer = driver->CreateRenderer(window, flags);
874  if (renderer) {
875  batching = SDL_FALSE;
876  }
877  break;
878  }
879  }
880  }
881 
882  if (!renderer) {
883  for (index = 0; index < n; ++index) {
884  const SDL_RenderDriver *driver = render_drivers[index];
885 
886  if ((driver->info.flags & flags) == flags) {
887  /* Create a new renderer instance */
888  renderer = driver->CreateRenderer(window, flags);
889  if (renderer) {
890  /* Yay, we got one! */
891  break;
892  }
893  }
894  }
895  }
896  if (index == n) {
897  SDL_SetError("Couldn't find matching render driver");
898  goto error;
899  }
900  } else {
901  if (index >= SDL_GetNumRenderDrivers()) {
902  SDL_SetError("index must be -1 or in the range of 0 - %d",
904  goto error;
905  }
906  /* Create a new renderer instance */
907  renderer = render_drivers[index]->CreateRenderer(window, flags);
908  batching = SDL_FALSE;
909  }
910 
911  if (!renderer) {
912  goto error;
913  }
914 
915  VerifyDrawQueueFunctions(renderer);
916 
917  /* let app/user override batching decisions. */
918  if (renderer->always_batch) {
919  batching = SDL_TRUE;
922  }
923 
924  renderer->batching = batching;
925  renderer->magic = &renderer_magic;
926  renderer->window = window;
927  renderer->target_mutex = SDL_CreateMutex();
928  renderer->scale.x = 1.0f;
929  renderer->scale.y = 1.0f;
930  renderer->dpi_scale.x = 1.0f;
931  renderer->dpi_scale.y = 1.0f;
932 
933  /* new textures start at zero, so we start at 1 so first render doesn't flush by accident. */
934  renderer->render_command_generation = 1;
935 
936  if (window && renderer->GetOutputSize) {
937  int window_w, window_h;
938  int output_w, output_h;
939  if (renderer->GetOutputSize(renderer, &output_w, &output_h) == 0) {
940  SDL_GetWindowSize(renderer->window, &window_w, &window_h);
941  renderer->dpi_scale.x = (float)window_w / output_w;
942  renderer->dpi_scale.y = (float)window_h / output_h;
943  }
944  }
945 
947  renderer->hidden = SDL_TRUE;
948  } else {
949  renderer->hidden = SDL_FALSE;
950  }
951 
952  SDL_SetWindowData(window, SDL_WINDOWRENDERDATA, renderer);
953 
954  SDL_RenderSetViewport(renderer, NULL);
955 
957 
959  "Created renderer: %s", renderer->info.name);
960 
961 #if defined(__ANDROID__)
963 #endif
964  return renderer;
965 
966 error:
967 
968 #if defined(__ANDROID__)
970 #endif
971  return NULL;
972 
973 #else
974  SDL_SetError("SDL not built with rendering support");
975  return NULL;
976 #endif
977 }
SDL_bool always_batch
#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
void Android_ActivityMutex_Lock_Running(void)
SDL_RendererInfo info
#define SDL_HINT_RENDER_BATCHING
A variable controlling whether the 2D render API is compatible or efficient.
Definition: SDL_hints.h:1087
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:2078
#define SDL_strcasecmp
const char * name
Definition: SDL_render.h:80
SDL_bool batching
SDL_Window * window
SDL_RendererInfo info
int(* GetOutputSize)(SDL_Renderer *renderer, int *w, int *h)
#define SDL_GetHintBoolean
#define SDL_SetWindowData
#define SDL_GetWindowSize
static SDL_INLINE void VerifyDrawQueueFunctions(const SDL_Renderer *renderer)
Definition: SDL_render.c:821
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:627
Uint32 render_command_generation
GLuint index
#define NULL
Definition: begin_code.h:167
SDL_bool
Definition: SDL_stdinc.h:161
#define SDL_SetError
static const SDL_RenderDriver * render_drivers[]
Definition: SDL_render.c:79
#define SDL_WINDOWRENDERDATA
Definition: SDL_render.c:36
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:1007
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
static char renderer_magic
Definition: SDL_render.c:108
void Android_ActivityMutex_Unlock(void)
int window_w
Definition: testoverlay2.c:143
SDL_FPoint dpi_scale
float x
Definition: SDL_rect.h:62
static int SDL_RendererEventWatch(void *userdata, SDL_Event *event)
Definition: SDL_render.c:662
float y
Definition: SDL_rect.h:63

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

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

981 {
982 #if !SDL_RENDER_DISABLED
984 
985  renderer = SW_CreateRendererForSurface(surface);
986 
987  if (renderer) {
988  VerifyDrawQueueFunctions(renderer);
989  renderer->magic = &renderer_magic;
990  renderer->target_mutex = SDL_CreateMutex();
991  renderer->scale.x = 1.0f;
992  renderer->scale.y = 1.0f;
993 
994  /* new textures start at zero, so we start at 1 so first render doesn't flush by accident. */
995  renderer->render_command_generation = 1;
996 
997  SDL_RenderSetViewport(renderer, NULL);
998  }
999  return renderer;
1000 #else
1001  SDL_SetError("SDL not built with rendering support");
1002  return NULL;
1003 #endif /* !SDL_RENDER_DISABLED */
1004 }
#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:2078
SDL_Renderer * SW_CreateRendererForSurface(SDL_Surface *surface)
static SDL_INLINE void VerifyDrawQueueFunctions(const SDL_Renderer *renderer)
Definition: SDL_render.c:821
static SDL_Renderer * renderer
Uint32 render_command_generation
#define NULL
Definition: begin_code.h:167
#define SDL_SetError
const void * magic
static char renderer_magic
Definition: SDL_render.c:108
float x
Definition: SDL_rect.h:62
float y
Definition: SDL_rect.h:63

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

1113 {
1115 
1116  CHECK_RENDERER_MAGIC(renderer, NULL);
1117 
1118  if (!format) {
1119  format = renderer->info.texture_formats[0];
1120  }
1121  if (SDL_BYTESPERPIXEL(format) == 0) {
1122  SDL_SetError("Invalid texture format");
1123  return NULL;
1124  }
1126  SDL_SetError("Palettized textures are not supported");
1127  return NULL;
1128  }
1129  if (w <= 0 || h <= 0) {
1130  SDL_SetError("Texture dimensions can't be 0");
1131  return NULL;
1132  }
1133  if ((renderer->info.max_texture_width && w > renderer->info.max_texture_width) ||
1134  (renderer->info.max_texture_height && h > renderer->info.max_texture_height)) {
1135  SDL_SetError("Texture dimensions are limited to %dx%d", renderer->info.max_texture_width, renderer->info.max_texture_height);
1136  return NULL;
1137  }
1138  texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture));
1139  if (!texture) {
1140  SDL_OutOfMemory();
1141  return NULL;
1142  }
1143  texture->magic = &texture_magic;
1144  texture->format = format;
1145  texture->access = access;
1146  texture->w = w;
1147  texture->h = h;
1148  texture->r = 255;
1149  texture->g = 255;
1150  texture->b = 255;
1151  texture->a = 255;
1152  texture->scaleMode = SDL_GetScaleMode();
1153  texture->renderer = renderer;
1154  texture->next = renderer->textures;
1155  if (renderer->textures) {
1156  renderer->textures->prev = texture;
1157  }
1158  renderer->textures = texture;
1159 
1160  if (IsSupportedFormat(renderer, format)) {
1161  if (renderer->CreateTexture(renderer, texture) < 0) {
1162  SDL_DestroyTexture(texture);
1163  return NULL;
1164  }
1165  } else {
1166  texture->native = SDL_CreateTexture(renderer,
1167  GetClosestSupportedFormat(renderer, format),
1168  access, w, h);
1169  if (!texture->native) {
1170  SDL_DestroyTexture(texture);
1171  return NULL;
1172  }
1173 
1174  /* Swap textures to have texture before texture->native in the list */
1175  texture->native->next = texture->next;
1176  if (texture->native->next) {
1177  texture->native->next->prev = texture->native;
1178  }
1179  texture->prev = texture->native->prev;
1180  if (texture->prev) {
1181  texture->prev->next = texture;
1182  }
1183  texture->native->prev = texture;
1184  texture->next = texture->native;
1185  renderer->textures = texture;
1186 
1187  if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
1188  texture->yuv = SDL_SW_CreateYUVTexture(format, w, h);
1189  if (!texture->yuv) {
1190  SDL_DestroyTexture(texture);
1191  return NULL;
1192  }
1193  } else if (access == SDL_TEXTUREACCESS_STREAMING) {
1194  /* The pitch is 4 byte aligned */
1195  texture->pitch = (((w * SDL_BYTESPERPIXEL(format)) + 3) & ~3);
1196  texture->pixels = SDL_calloc(1, texture->pitch * h);
1197  if (!texture->pixels) {
1198  SDL_DestroyTexture(texture);
1199  return NULL;
1200  }
1201  }
1202  }
1203  return texture;
1204 }
void * pixels
Definition: SDL_sysrender.h:60
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:1070
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:1096
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:109
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:69
GLenum GLenum GLuint texture
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
void SDL_DestroyTexture(SDL_Texture *texture)
Destroy the specified texture.
Definition: SDL_render.c:3140
SDL_Texture * prev
Definition: SDL_sysrender.h:68
static SDL_Renderer * renderer
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:59
GLubyte GLubyte GLubyte GLubyte w
#define NULL
Definition: begin_code.h:167
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
#define SDL_SetError
static SDL_bool IsSupportedFormat(SDL_Renderer *renderer, Uint32 format)
Definition: SDL_render.c:1057
SDL_Renderer * renderer
Definition: SDL_sysrender.h:55
#define SDL_calloc
Uint32 format
Definition: SDL_sysrender.h:46
int(* CreateTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
SDL_Texture * native
Definition: SDL_sysrender.h:58
#define SDL_ISPIXELFORMAT_FOURCC(format)
Definition: SDL_pixels.h:167
SDL_ScaleMode scaleMode
Definition: SDL_sysrender.h:52
const void * magic
Definition: SDL_sysrender.h:45
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:1112

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

References SDL_Color::a, SDL_PixelFormat::Amask, blendMode, CHECK_RENDERER_MAGIC, SDL_Palette::colors, SDL_Surface::format, SDL_PixelFormat::format, SDL_Surface::h, i, SDL_Renderer::info, SDL_Palette::ncolors, NULL, SDL_RendererInfo::num_texture_formats, SDL_PixelFormat::palette, SDL_Surface::pitch, SDL_Surface::pixels, SDL_AllocFormat, SDL_ALPHA_OPAQUE, 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_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_UNKNOWN, 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.

1208 {
1209  const SDL_PixelFormat *fmt;
1210  SDL_bool needAlpha;
1211  SDL_bool direct_update;
1212  int i;
1215 
1216  CHECK_RENDERER_MAGIC(renderer, NULL);
1217 
1218  if (!surface) {
1219  SDL_SetError("SDL_CreateTextureFromSurface() passed NULL surface");
1220  return NULL;
1221  }
1222 
1223  /* See what the best texture format is */
1224  fmt = surface->format;
1225  if (fmt->Amask || SDL_HasColorKey(surface)) {
1226  needAlpha = SDL_TRUE;
1227  } else {
1228  needAlpha = SDL_FALSE;
1229  }
1230 
1231  /* If Palette contains alpha values, promotes to alpha format */
1232  if (fmt->palette) {
1233  for (i = 0; i < fmt->palette->ncolors; i++) {
1234  Uint8 alpha_value = fmt->palette->colors[i].a;
1235  if (alpha_value != 0 || alpha_value != SDL_ALPHA_OPAQUE) {
1236  needAlpha = SDL_TRUE;
1237  break;
1238  }
1239  }
1240  }
1241 
1242  /* Try to have the best pixel format for the texture */
1243  /* No alpha, but a colorkey => promote to alpha */
1244  if (!fmt->Amask && SDL_HasColorKey(surface)) {
1245  if (fmt->format == SDL_PIXELFORMAT_RGB888) {
1246  for (i = 0; i < (int)renderer->info.num_texture_formats; ++i) {
1247  if (renderer->info.texture_formats[i] == SDL_PIXELFORMAT_ARGB8888) {
1248  format = SDL_PIXELFORMAT_ARGB8888;
1249  break;
1250  }
1251  }
1252  } else if (fmt->format == SDL_PIXELFORMAT_BGR888) {
1253  for (i = 0; i < (int)renderer->info.num_texture_formats; ++i) {
1254  if (renderer->info.texture_formats[i] == SDL_PIXELFORMAT_ABGR8888) {
1255  format = SDL_PIXELFORMAT_ABGR8888;
1256  break;
1257  }
1258  }
1259  }
1260  } else {
1261  /* Exact match would be fine */
1262  for (i = 0; i < (int)renderer->info.num_texture_formats; ++i) {
1263  if (renderer->info.texture_formats[i] == fmt->format) {
1264  format = fmt->format;
1265  break;
1266  }
1267  }
1268  }
1269 
1270  /* Fallback, choose a valid pixel format */
1271  if (format == SDL_PIXELFORMAT_UNKNOWN) {
1272  format = renderer->info.texture_formats[0];
1273  for (i = 0; i < (int)renderer->info.num_texture_formats; ++i) {
1274  if (!SDL_ISPIXELFORMAT_FOURCC(renderer->info.texture_formats[i]) &&
1275  SDL_ISPIXELFORMAT_ALPHA(renderer->info.texture_formats[i]) == needAlpha) {
1276  format = renderer->info.texture_formats[i];
1277  break;
1278  }
1279  }
1280  }
1281 
1282  texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STATIC,
1283  surface->w, surface->h);
1284  if (!texture) {
1285  return NULL;
1286  }
1287 
1288  if (format == surface->format->format) {
1289  if (surface->format->Amask && SDL_HasColorKey(surface)) {
1290  /* Surface and Renderer formats are identicals.
1291  * Intermediate conversion is needed to convert color key to alpha (SDL_ConvertColorkeyToAlpha()). */
1292  direct_update = SDL_FALSE;
1293  } else {
1294  /* Update Texture directly */
1295  direct_update = SDL_TRUE;
1296  }
1297  } else {
1298  /* Surface and Renderer formats are differents, it needs an intermediate conversion. */
1299  direct_update = SDL_FALSE;
1300  }
1301 
1302  if (direct_update) {
1303  if (SDL_MUSTLOCK(surface)) {
1304  SDL_LockSurface(surface);
1305  SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch);
1306  SDL_UnlockSurface(surface);
1307  } else {
1308  SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch);
1309  }
1310  } else {
1311  SDL_PixelFormat *dst_fmt;
1312  SDL_Surface *temp = NULL;
1313 
1314  /* Set up a destination surface for the texture update */
1315  dst_fmt = SDL_AllocFormat(format);
1316  if (!dst_fmt) {
1317  SDL_DestroyTexture(texture);
1318  return NULL;
1319  }
1320  temp = SDL_ConvertSurface(surface, dst_fmt, 0);
1321  SDL_FreeFormat(dst_fmt);
1322  if (temp) {
1323  SDL_UpdateTexture(texture, NULL, temp->pixels, temp->pitch);
1324  SDL_FreeSurface(temp);
1325  } else {
1326  SDL_DestroyTexture(texture);
1327  return NULL;
1328  }
1329  }
1330 
1331  {
1332  Uint8 r, g, b, a;
1334 
1335  SDL_GetSurfaceColorMod(surface, &r, &g, &b);
1336  SDL_SetTextureColorMod(texture, r, g, b);
1337 
1338  SDL_GetSurfaceAlphaMod(surface, &a);
1339  SDL_SetTextureAlphaMod(texture, a);
1340 
1341  if (SDL_HasColorKey(surface)) {
1342  /* We converted to a texture with alpha format */
1344  } else {
1345  SDL_GetSurfaceBlendMode(surface, &blendMode);
1346  SDL_SetTextureBlendMode(texture, blendMode);
1347  }
1348  }
1349  return texture;
1350 }
#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:70
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:1439
GLenum GLenum GLuint texture
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
void SDL_DestroyTexture(SDL_Texture *texture)
Destroy the specified texture.
Definition: SDL_render.c:3140
void * pixels
Definition: SDL_surface.h:76
#define SDL_FreeSurface
Uint8 a
Definition: SDL_pixels.h:300
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:1411
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:1555
#define NULL
Definition: begin_code.h:167
SDL_bool
Definition: SDL_stdinc.h:161
SDL_Color * colors
Definition: SDL_pixels.h:307
SDL_PixelFormat * format
Definition: SDL_surface.h:73
#define SDL_SetError
#define SDL_LockSurface
#define SDL_GetSurfaceColorMod
#define SDL_MUSTLOCK(S)
Definition: SDL_surface.h:62
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:1374
Uint32 num_texture_formats
Definition: SDL_render.h:82
SDL_Palette * palette
Definition: SDL_pixels.h:318
#define SDL_ISPIXELFORMAT_FOURCC(format)
Definition: SDL_pixels.h:167
GLboolean GLboolean GLboolean GLboolean a
#define SDL_ALPHA_OPAQUE
Definition: SDL_pixels.h:46
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:1112

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

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

803 {
806  width, height, window_flags);
807  if (!*window) {
808  *renderer = NULL;
809  return -1;
810  }
811 
812  *renderer = SDL_CreateRenderer(*window, -1, 0);
813  if (!*renderer) {
814  return -1;
815  }
816 
817  return 0;
818 }
#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:167
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:835

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

References CHECK_RENDERER_MAGIC, SDL_Renderer::DestroyRenderer, SDL_Renderer::magic, SDL_RenderCommand::next, SDL_AllocVertGap::next, NULL, SDL_Renderer::render_commands, SDL_Renderer::render_commands_pool, SDL_Renderer::render_commands_tail, SDL_assert, SDL_DelEventWatch, SDL_DestroyMutex, SDL_DestroyTexture(), SDL_free, SDL_RendererEventWatch(), SDL_SetWindowData, SDL_WINDOWRENDERDATA, SDL_Renderer::target_mutex, SDL_Renderer::textures, SDL_Renderer::vertex_data, SDL_Renderer::vertex_data_gaps, SDL_Renderer::vertex_data_gaps_pool, void, and SDL_Renderer::window.

3178 {
3179  SDL_RenderCommand *cmd;
3180  SDL_AllocVertGap *gap;
3181  SDL_AllocVertGap *nextgap;
3182 
3183  CHECK_RENDERER_MAGIC(renderer, );
3184 
3186 
3187  if (renderer->render_commands_tail != NULL) {
3188  renderer->render_commands_tail->next = renderer->render_commands_pool;
3189  cmd = renderer->render_commands;
3190  } else {
3191  cmd = renderer->render_commands_pool;
3192  }
3193 
3194  renderer->render_commands_pool = NULL;
3195  renderer->render_commands_tail = NULL;
3196  renderer->render_commands = NULL;
3197 
3198  while (cmd != NULL) {
3199  SDL_RenderCommand *next = cmd->next;
3200  SDL_free(cmd);
3201  cmd = next;
3202  }
3203 
3204  SDL_free(renderer->vertex_data);
3205 
3206  for (gap = renderer->vertex_data_gaps.next; gap; gap = nextgap) {
3207  nextgap = gap->next;
3208  SDL_free(gap);
3209  }
3210 
3211  for (gap = renderer->vertex_data_gaps_pool; gap; gap = nextgap) {
3212  nextgap = gap->next;
3213  SDL_free(gap);
3214  }
3215 
3216  /* Free existing textures for this renderer */
3217  while (renderer->textures) {
3218  SDL_Texture *tex = renderer->textures; (void) tex;
3219  SDL_DestroyTexture(renderer->textures);
3220  SDL_assert(tex != renderer->textures); /* satisfy static analysis. */
3221  }
3222 
3223  if (renderer->window) {
3225  }
3226 
3227  /* It's no longer magical... */
3228  renderer->magic = NULL;
3229 
3230  /* Free the target mutex */
3231  SDL_DestroyMutex(renderer->target_mutex);
3232  renderer->target_mutex = NULL;
3233 
3234  /* Free the renderer instance */
3235  renderer->DestroyRenderer(renderer);
3236 }
#define SDL_DelEventWatch
SDL_AllocVertGap * vertex_data_gaps_pool
struct SDL_AllocVertGap * next
SDL_mutex * target_mutex
SDL_Texture * textures
SDL_Window * window
void(* DestroyRenderer)(SDL_Renderer *renderer)
#define SDL_SetWindowData
SDL_RenderCommand * render_commands_tail
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
void SDL_DestroyTexture(SDL_Texture *texture)
Destroy the specified texture.
Definition: SDL_render.c:3140
SDL_RenderCommand * render_commands_pool
#define SDL_free
SDL_RenderCommand * render_commands
#define SDL_assert(condition)
Definition: SDL_assert.h:169
#define NULL
Definition: begin_code.h:167
#define SDL_WINDOWRENDERDATA
Definition: SDL_render.c:36
#define SDL_DestroyMutex
SDL_AllocVertGap vertex_data_gaps
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
void * vertex_data
const void * magic
struct SDL_RenderCommand * next
static int SDL_RendererEventWatch(void *userdata, SDL_Event *event)
Definition: SDL_render.c:662

◆ SDL_DestroyTexture()

void SDL_DestroyTexture ( SDL_Texture texture)

Destroy the specified texture.

See also
SDL_CreateTexture()
SDL_CreateTextureFromSurface()

Definition at line 3140 of file SDL_render.c.

References CHECK_TEXTURE_MAGIC, SDL_Renderer::DestroyTexture, FlushRenderCommandsIfTextureNeeded(), 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().

3141 {
3143 
3144  CHECK_TEXTURE_MAGIC(texture, );
3145 
3146  renderer = texture->renderer;
3147  if (texture == renderer->target) {
3148  SDL_SetRenderTarget(renderer, NULL); /* implies command queue flush */
3149  } else {
3151  }
3152 
3153  texture->magic = NULL;
3154 
3155  if (texture->next) {
3156  texture->next->prev = texture->prev;
3157  }
3158  if (texture->prev) {
3159  texture->prev->next = texture->next;
3160  } else {
3161  renderer->textures = texture->next;
3162  }
3163 
3164  if (texture->native) {
3165  SDL_DestroyTexture(texture->native);
3166  }
3167  if (texture->yuv) {
3168  SDL_SW_DestroyYUVTexture(texture->yuv);
3169  }
3170  SDL_free(texture->pixels);
3171 
3172  renderer->DestroyTexture(renderer, texture);
3173  SDL_free(texture);
3174 }
void * pixels
Definition: SDL_sysrender.h:60
static int FlushRenderCommandsIfTextureNeeded(SDL_Texture *texture)
Definition: SDL_render.c:244
SDL_Texture * textures
SDL_Texture * next
Definition: SDL_sysrender.h:69
void SDL_DestroyTexture(SDL_Texture *texture)
Destroy the specified texture.
Definition: SDL_render.c:3140
SDL_Texture * prev
Definition: SDL_sysrender.h:68
SDL_Texture * target
static SDL_Renderer * renderer
#define SDL_free
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:59
void SDL_SW_DestroyYUVTexture(SDL_SW_YUVTexture *swdata)
Definition: SDL_yuv_sw.c:404
#define NULL
Definition: begin_code.h:167
SDL_Renderer * renderer
Definition: SDL_sysrender.h:55
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:45
void(* DestroyTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
SDL_Texture * native
Definition: SDL_sysrender.h:58
int SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
Set a texture as the current rendering target.
Definition: SDL_render.c:1833
const void * magic
Definition: SDL_sysrender.h:45

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

References SDL_arraysize.

Referenced by SDL_CreateRenderer(), and SDL_GetRenderDriverInfo().

628 {
629 #if !SDL_RENDER_DISABLED
631 #else
632  return 0;
633 #endif
634 }
static const SDL_RenderDriver * render_drivers[]
Definition: SDL_render.c:79
#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 2223 of file SDL_render.c.

References SDL_Renderer::blendMode, and CHECK_RENDERER_MAGIC.

2224 {
2225  CHECK_RENDERER_MAGIC(renderer, -1);
2226 
2227  *blendMode = renderer->blendMode;
2228  return 0;
2229 }
static SDL_BlendMode blendMode
Definition: testdraw2.c:34
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
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 2190 of file SDL_render.c.

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

2192 {
2193  CHECK_RENDERER_MAGIC(renderer, -1);
2194 
2195  if (r) {
2196  *r = renderer->r;
2197  }
2198  if (g) {
2199  *g = renderer->g;
2200  }
2201  if (b) {
2202  *b = renderer->b;
2203  }
2204  if (a) {
2205  *a = renderer->a;
2206  }
2207  return 0;
2208 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
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 637 of file SDL_render.c.

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

638 {
639 #if !SDL_RENDER_DISABLED
641  return SDL_SetError("index must be in the range of 0 - %d",
643  }
644  *info = render_drivers[index]->info;
645  return 0;
646 #else
647  return SDL_SetError("SDL not built with rendering support");
648 #endif
649 }
SDL_RendererInfo info
int SDL_GetNumRenderDrivers(void)
Get the number of 2D rendering drivers available for the current display.
Definition: SDL_render.c:627
GLuint index
#define SDL_SetError
static const SDL_RenderDriver * render_drivers[]
Definition: SDL_render.c:79

◆ SDL_GetRenderer()

SDL_Renderer* SDL_GetRenderer ( SDL_Window window)

Get the renderer associated with a window.

Definition at line 1007 of file SDL_render.c.

References SDL_GetWindowData, and SDL_WINDOWRENDERDATA.

Referenced by SDL_CreateRenderer().

1008 {
1010 }
#define SDL_GetWindowData
#define SDL_WINDOWRENDERDATA
Definition: SDL_render.c:36

◆ SDL_GetRendererInfo()

int SDL_GetRendererInfo ( SDL_Renderer renderer,
SDL_RendererInfo info 
)

Get information about a rendering context.

Definition at line 1013 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, and SDL_Renderer::info.

1014 {
1015  CHECK_RENDERER_MAGIC(renderer, -1);
1016 
1017  *info = renderer->info;
1018  return 0;
1019 }
SDL_RendererInfo info
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38

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

1023 {
1024  CHECK_RENDERER_MAGIC(renderer, -1);
1025 
1026  if (renderer->target) {
1027  return SDL_QueryTexture(renderer->target, NULL, NULL, w, h);
1028  } else if (renderer->GetOutputSize) {
1029  return renderer->GetOutputSize(renderer, w, h);
1030  } else if (renderer->window) {
1031  SDL_GetWindowSize(renderer->window, w, h);
1032  return 0;
1033  } else {
1034  SDL_assert(0 && "This should never happen");
1035  return SDL_SetError("Renderer doesn't support querying output size");
1036  }
1037 }
GLfloat GLfloat GLfloat GLfloat h
SDL_Window * window
int(* GetOutputSize)(SDL_Renderer *renderer, int *w, int *h)
int SDL_QueryTexture(SDL_Texture *texture, Uint32 *format, int *access, int *w, int *h)
Query the attributes of a texture.
Definition: SDL_render.c:1353
#define SDL_GetWindowSize
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
SDL_Texture * target
GLubyte GLubyte GLubyte GLubyte w
#define SDL_assert(condition)
Definition: SDL_assert.h:169
#define NULL
Definition: begin_code.h:167
#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 1912 of file SDL_render.c.

References SDL_Renderer::target.

Referenced by SDL_RendererEventWatch().

1913 {
1914  return renderer->target;
1915 }
SDL_Texture * target

◆ SDL_GetTextureAlphaMod()

int SDL_GetTextureAlphaMod ( SDL_Texture texture,
Uint8 alpha 
)

Get the additional alpha value used in render copy operations.

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

Definition at line 1428 of file SDL_render.c.

References SDL_Texture::a, and CHECK_TEXTURE_MAGIC.

1429 {
1430  CHECK_TEXTURE_MAGIC(texture, -1);
1431 
1432  if (alpha) {
1433  *alpha = texture->a;
1434  }
1435  return 0;
1436 }
GLfloat GLfloat GLfloat alpha
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:45

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

References SDL_Texture::blendMode, and CHECK_TEXTURE_MAGIC.

1458 {
1459  CHECK_TEXTURE_MAGIC(texture, -1);
1460 
1461  if (blendMode) {
1462  *blendMode = texture->blendMode;
1463  }
1464  return 0;
1465 }
SDL_BlendMode blendMode
Definition: SDL_sysrender.h:51
static SDL_BlendMode blendMode
Definition: testdraw2.c:34
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:45

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

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

1395 {
1396  CHECK_TEXTURE_MAGIC(texture, -1);
1397 
1398  if (r) {
1399  *r = texture->r;
1400  }
1401  if (g) {
1402  *g = texture->g;
1403  }
1404  if (b) {
1405  *b = texture->b;
1406  }
1407  return 0;
1408 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:45
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 3238 of file SDL_render.c.

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

3239 {
3241 
3242  CHECK_TEXTURE_MAGIC(texture, -1);
3243  renderer = texture->renderer;
3244  if (texture->native) {
3245  return SDL_GL_BindTexture(texture->native, texw, texh);
3246  } else if (renderer && renderer->GL_BindTexture) {
3247  FlushRenderCommandsIfTextureNeeded(texture); /* in case the app is going to mess with it. */
3248  return renderer->GL_BindTexture(renderer, texture, texw, texh);
3249  } else {
3250  return SDL_Unsupported();
3251  }
3252 }
static int FlushRenderCommandsIfTextureNeeded(SDL_Texture *texture)
Definition: SDL_render.c:244
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:3238
SDL_Renderer * renderer
Definition: SDL_sysrender.h:55
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:45
SDL_Texture * native
Definition: SDL_sysrender.h:58
#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 3254 of file SDL_render.c.

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

3255 {
3257 
3258  CHECK_TEXTURE_MAGIC(texture, -1);
3259  renderer = texture->renderer;
3260  if (texture->native) {
3261  return SDL_GL_UnbindTexture(texture->native);
3262  } else if (renderer && renderer->GL_UnbindTexture) {
3263  FlushRenderCommandsIfTextureNeeded(texture); /* in case the app messed with it. */
3264  return renderer->GL_UnbindTexture(renderer, texture);
3265  }
3266 
3267  return SDL_Unsupported();
3268 }
static int FlushRenderCommandsIfTextureNeeded(SDL_Texture *texture)
Definition: SDL_render.c:244
static SDL_Renderer * renderer
int(* GL_UnbindTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
SDL_Renderer * renderer
Definition: SDL_sysrender.h:55
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:45
SDL_Texture * native
Definition: SDL_sysrender.h:58
#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:3254

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

References SDL_Texture::access, CHECK_TEXTURE_MAGIC, FlushRenderCommandsIfTextureNeeded(), SDL_Texture::h, SDL_Rect::h, SDL_Renderer::LockTexture, SDL_Texture::native, 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().

1729 {
1730  SDL_Rect full_rect;
1731 
1732  CHECK_TEXTURE_MAGIC(texture, -1);
1733 
1734  if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
1735  return SDL_SetError("SDL_LockTexture(): texture must be streaming");
1736  }
1737 
1738  if (!rect) {
1739  full_rect.x = 0;
1740  full_rect.y = 0;
1741  full_rect.w = texture->w;
1742  full_rect.h = texture->h;
1743  rect = &full_rect;
1744  }
1745 
1746  if (texture->yuv) {
1747  if (FlushRenderCommandsIfTextureNeeded(texture) < 0) {
1748  return -1;
1749  }
1750  return SDL_LockTextureYUV(texture, rect, pixels, pitch);
1751  } else if (texture->native) {
1752  /* Calls a real SDL_LockTexture/SDL_UnlockTexture on unlock, flushing then. */
1753  return SDL_LockTextureNative(texture, rect, pixels, pitch);
1754  } else {
1755  SDL_Renderer *renderer = texture->renderer;
1756  if (FlushRenderCommandsIfTextureNeeded(texture) < 0) {
1757  return -1;
1758  }
1759  return renderer->LockTexture(renderer, texture, rect, pixels, pitch);
1760  }
1761 }
int(* LockTexture)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
static int FlushRenderCommandsIfTextureNeeded(SDL_Texture *texture)
Definition: SDL_render.c:244
static int SDL_LockTextureYUV(SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
Definition: SDL_render.c:1708
static SDL_Renderer * renderer
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:59
int x
Definition: SDL_rect.h:79
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
int w
Definition: SDL_rect.h:80
#define SDL_SetError
SDL_Renderer * renderer
Definition: SDL_sysrender.h:55
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:45
int h
Definition: SDL_rect.h:80
SDL_Texture * native
Definition: SDL_sysrender.h:58
int y
Definition: SDL_rect.h:79
A rectangle, with the origin at the upper left (integer).
Definition: SDL_rect.h:77
static int SDL_LockTextureNative(SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
Definition: SDL_render.c:1715

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

1355 {
1356  CHECK_TEXTURE_MAGIC(texture, -1);
1357 
1358  if (format) {
1359  *format = texture->format;
1360  }
1361  if (access) {
1362  *access = texture->access;
1363  }
1364  if (w) {
1365  *w = texture->w;
1366  }
1367  if (h) {
1368  *h = texture->h;
1369  }
1370  return 0;
1371 }
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:45
Uint32 format
Definition: SDL_sysrender.h:46

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

References CHECK_RENDERER_MAGIC, FlushRenderCommandsIfNotBatching(), QueueCmdClear(), and retval.

2233 {
2234  int retval;
2235  CHECK_RENDERER_MAGIC(renderer, -1);
2236  retval = QueueCmdClear(renderer);
2237  return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
2238 }
SDL_bool retval
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
static SDL_INLINE int FlushRenderCommandsIfNotBatching(SDL_Renderer *renderer)
Definition: SDL_render.c:255
static int QueueCmdClear(SDL_Renderer *renderer)
Definition: SDL_render.c:474

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

References SDL_Rect::h, SDL_FRect::h, NULL, SDL_RenderCopyF(), SDL_Rect::w, SDL_FRect::w, SDL_Rect::x, SDL_FRect::x, SDL_Rect::y, and SDL_FRect::y.

2910 {
2911  SDL_FRect dstfrect;
2912  SDL_FRect *pdstfrect = NULL;
2913  if (dstrect) {
2914  dstfrect.x = (float) dstrect->x;
2915  dstfrect.y = (float) dstrect->y;
2916  dstfrect.w = (float) dstrect->w;
2917  dstfrect.h = (float) dstrect->h;
2918  pdstfrect = &dstfrect;
2919  }
2920  return SDL_RenderCopyF(renderer, texture, srcrect, pdstfrect);
2921 }
float w
Definition: SDL_rect.h:91
int SDL_RenderCopyF(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_FRect *dstrect)
Copy a portion of the texture to the current rendering target.
Definition: SDL_render.c:2924
float y
Definition: SDL_rect.h:90
int x
Definition: SDL_rect.h:79
int w
Definition: SDL_rect.h:80
float h
Definition: SDL_rect.h:92
#define NULL
Definition: begin_code.h:167
int h
Definition: SDL_rect.h:80
float x
Definition: SDL_rect.h:89
int y
Definition: SDL_rect.h:79
A rectangle, with the origin at the upper left (floating point).
Definition: SDL_rect.h:87

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

References SDL_Rect::h, SDL_FRect::h, NULL, SDL_RenderCopyExF(), SDL_Rect::w, SDL_FRect::w, SDL_Point::x, SDL_FPoint::x, SDL_Rect::x, SDL_FRect::x, SDL_Point::y, SDL_FPoint::y, SDL_Rect::y, and SDL_FRect::y.

2986 {
2987  SDL_FRect dstfrect;
2988  SDL_FRect *pdstfrect = NULL;
2989  SDL_FPoint fcenter;
2990  SDL_FPoint *pfcenter = NULL;
2991 
2992  if (dstrect) {
2993  dstfrect.x = (float) dstrect->x;
2994  dstfrect.y = (float) dstrect->y;
2995  dstfrect.w = (float) dstrect->w;
2996  dstfrect.h = (float) dstrect->h;
2997  pdstfrect = &dstfrect;
2998  }
2999 
3000  if (center) {
3001  fcenter.x = (float) center->x;
3002  fcenter.y = (float) center->y;
3003  pfcenter = &fcenter;
3004  }
3005 
3006  return SDL_RenderCopyExF(renderer, texture, srcrect, pdstfrect, angle, pfcenter, flip);
3007 }
float w
Definition: SDL_rect.h:91
int SDL_RenderCopyExF(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_FRect *dstrect, const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
Copy a portion of the source texture to the current rendering target, rotating it by angle around the...
Definition: SDL_render.c:3010
float y
Definition: SDL_rect.h:90
int x
Definition: SDL_rect.h:50
int y
Definition: SDL_rect.h:51
int x
Definition: SDL_rect.h:79
int w
Definition: SDL_rect.h:80
float h
Definition: SDL_rect.h:92
#define NULL
Definition: begin_code.h:167
int h
Definition: SDL_rect.h:80
GLfloat angle
float x
Definition: SDL_rect.h:89
int y
Definition: SDL_rect.h:79
float x
Definition: SDL_rect.h:62
A rectangle, with the origin at the upper left (floating point).
Definition: SDL_rect.h:87
The structure that defines a point (floating point)
Definition: SDL_rect.h:60
float y
Definition: SDL_rect.h:63

◆ SDL_RenderCopyExF()

int SDL_RenderCopyExF ( SDL_Renderer renderer,
SDL_Texture texture,
const SDL_Rect srcrect,
const SDL_FRect dstrect,
const double  angle,
const SDL_FPoint 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 3010 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, CHECK_TEXTURE_MAGIC, FlushRenderCommandsIfNotBatching(), SDL_Texture::h, SDL_Rect::h, SDL_FRect::h, SDL_Renderer::hidden, SDL_Texture::last_command_generation, SDL_Texture::native, QueueCmdCopyEx(), SDL_Renderer::QueueCopyEx, SDL_Renderer::render_command_generation, SDL_Texture::renderer, retval, SDL_Renderer::scale, SDL_FLIP_NONE, SDL_IntersectRect, SDL_RenderCopyF(), SDL_RenderGetViewport(), SDL_SetError, SDL_zero, SDL_Texture::w, SDL_Rect::w, SDL_FRect::w, SDL_FPoint::x, SDL_Rect::x, SDL_FRect::x, SDL_FPoint::y, SDL_Rect::y, and SDL_FRect::y.

Referenced by SDL_RenderCopyEx().

3013 {
3014  SDL_Rect real_srcrect;
3015  SDL_FRect real_dstrect;
3016  SDL_FPoint real_center;
3017  int retval;
3018 
3019  if (flip == SDL_FLIP_NONE && (int)(angle/360) == angle/360) { /* fast path when we don't need rotation or flipping */
3020  return SDL_RenderCopyF(renderer, texture, srcrect, dstrect);
3021  }
3022 
3023  CHECK_RENDERER_MAGIC(renderer, -1);
3024  CHECK_TEXTURE_MAGIC(texture, -1);
3025 
3026  if (renderer != texture->renderer) {
3027  return SDL_SetError("Texture was not created with this renderer");
3028  }
3029  if (!renderer->QueueCopyEx) {
3030  return SDL_SetError("Renderer does not support RenderCopyEx");
3031  }
3032 
3033  /* Don't draw while we're hidden */
3034  if (renderer->hidden) {
3035  return 0;
3036  }
3037 
3038  real_srcrect.x = 0;
3039  real_srcrect.y = 0;
3040  real_srcrect.w = texture->w;
3041  real_srcrect.h = texture->h;
3042  if (srcrect) {
3043  if (!SDL_IntersectRect(srcrect, &real_srcrect, &real_srcrect)) {
3044  return 0;
3045  }
3046  }
3047 
3048  /* We don't intersect the dstrect with the viewport as RenderCopy does because of potential rotation clipping issues... TODO: should we? */
3049  if (dstrect) {
3050  real_dstrect = *dstrect;
3051  } else {
3052  SDL_Rect r;
3053  SDL_zero(r);
3054  SDL_RenderGetViewport(renderer, &r);
3055  real_dstrect.x = 0.0f;
3056  real_dstrect.y = 0.0f;
3057  real_dstrect.w = (float) r.w;
3058  real_dstrect.h = (float) r.h;
3059  }
3060 
3061  if (texture->native) {
3062  texture = texture->native;
3063  }
3064 
3065  if (center) {
3066  real_center = *center;
3067  } else {
3068  real_center.x = real_dstrect.w / 2.0f;
3069  real_center.y = real_dstrect.h / 2.0f;
3070  }
3071 
3072  real_dstrect.x *= renderer->scale.x;
3073  real_dstrect.y *= renderer->scale.y;
3074  real_dstrect.w *= renderer->scale.x;
3075  real_dstrect.h *= renderer->scale.y;
3076 
3077  real_center.x *= renderer->scale.x;
3078  real_center.y *= renderer->scale.y;
3079 
3081 
3082  retval = QueueCmdCopyEx(renderer, texture, &real_srcrect, &real_dstrect, angle, &real_center, flip);
3083  return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
3084 }
float w
Definition: SDL_rect.h:91
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
int SDL_RenderCopyF(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_FRect *dstrect)
Copy a portion of the texture to the current rendering target.
Definition: SDL_render.c:2924
SDL_bool hidden
SDL_FPoint scale
int(* QueueCopyEx)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, const SDL_Rect *srcquad, const SDL_FRect *dstrect, const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
#define SDL_IntersectRect
float y
Definition: SDL_rect.h:90
SDL_bool retval
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
static SDL_INLINE int FlushRenderCommandsIfNotBatching(SDL_Renderer *renderer)
Definition: SDL_render.c:255
#define SDL_zero(x)
Definition: SDL_stdinc.h:416
Uint32 last_command_generation
Definition: SDL_sysrender.h:64
int x
Definition: SDL_rect.h:79
Uint32 render_command_generation
int w
Definition: SDL_rect.h:80
float h
Definition: SDL_rect.h:92
#define SDL_SetError
SDL_Renderer * renderer
Definition: SDL_sysrender.h:55
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:45
int h
Definition: SDL_rect.h:80
void SDL_RenderGetViewport(SDL_Renderer *renderer, SDL_Rect *rect)
Get the drawing area for the current target.
Definition: SDL_render.c:2100
GLfloat angle
SDL_Texture * native
Definition: SDL_sysrender.h:58
float x
Definition: SDL_rect.h:89
static int QueueCmdCopyEx(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)
Definition: SDL_render.c:607
int y
Definition: SDL_rect.h:79
float x
Definition: SDL_rect.h:62
A rectangle, with the origin at the upper left (floating point).
Definition: SDL_rect.h:87
The structure that defines a point (floating point)
Definition: SDL_rect.h:60
A rectangle, with the origin at the upper left (integer).
Definition: SDL_rect.h:77
float y
Definition: SDL_rect.h:63

◆ SDL_RenderCopyF()

int SDL_RenderCopyF ( SDL_Renderer renderer,
SDL_Texture texture,
const SDL_Rect srcrect,
const SDL_FRect 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 2924 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, CHECK_TEXTURE_MAGIC, FlushRenderCommandsIfNotBatching(), SDL_Texture::h, SDL_Rect::h, SDL_FRect::h, SDL_Renderer::hidden, SDL_Texture::last_command_generation, SDL_Texture::native, QueueCmdCopy(), SDL_Renderer::render_command_generation, SDL_Texture::renderer, retval, SDL_Renderer::scale, SDL_HasIntersectionF(), SDL_IntersectRect, SDL_RenderGetViewport(), SDL_SetError, SDL_zero, SDL_Texture::w, SDL_Rect::w, SDL_FRect::w, SDL_FPoint::x, SDL_Rect::x, SDL_FRect::x, SDL_FPoint::y, SDL_Rect::y, and SDL_FRect::y.

Referenced by SDL_RenderCopy(), and SDL_RenderCopyExF().

2926 {
2927  SDL_Rect real_srcrect;
2928  SDL_FRect real_dstrect;
2929  SDL_Rect r;
2930  int retval;
2931 
2932  CHECK_RENDERER_MAGIC(renderer, -1);
2933  CHECK_TEXTURE_MAGIC(texture, -1);
2934 
2935  if (renderer != texture->renderer) {
2936  return SDL_SetError("Texture was not created with this renderer");
2937  }
2938 
2939  /* Don't draw while we're hidden */
2940  if (renderer->hidden) {
2941  return 0;
2942  }
2943 
2944  real_srcrect.x = 0;
2945  real_srcrect.y = 0;
2946  real_srcrect.w = texture->w;
2947  real_srcrect.h = texture->h;
2948  if (srcrect) {
2949  if (!SDL_IntersectRect(srcrect, &real_srcrect, &real_srcrect)) {
2950  return 0;
2951  }
2952  }
2953 
2954  SDL_zero(r);
2955  SDL_RenderGetViewport(renderer, &r);
2956  real_dstrect.x = 0.0f;
2957  real_dstrect.y = 0.0f;
2958  real_dstrect.w = (float) r.w;
2959  real_dstrect.h = (float) r.h;
2960  if (dstrect) {
2961  if (!SDL_HasIntersectionF(dstrect, &real_dstrect)) {
2962  return 0;
2963  }
2964  real_dstrect = *dstrect;
2965  }
2966 
2967  if (texture->native) {
2968  texture = texture->native;
2969  }
2970 
2971  real_dstrect.x *= renderer->scale.x;
2972  real_dstrect.y *= renderer->scale.y;
2973  real_dstrect.w *= renderer->scale.x;
2974  real_dstrect.h *= renderer->scale.y;
2975 
2977 
2978  retval = QueueCmdCopy(renderer, texture, &real_srcrect, &real_dstrect);
2979  return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
2980 }
float w
Definition: SDL_rect.h:91
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
SDL_bool hidden
SDL_FPoint scale
static int QueueCmdCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_FRect *dstrect)
Definition: SDL_render.c:593
#define SDL_IntersectRect
float y
Definition: SDL_rect.h:90
SDL_bool retval
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
static SDL_INLINE int FlushRenderCommandsIfNotBatching(SDL_Renderer *renderer)
Definition: SDL_render.c:255
#define SDL_zero(x)
Definition: SDL_stdinc.h:416
Uint32 last_command_generation
Definition: SDL_sysrender.h:64
int x
Definition: SDL_rect.h:79
static SDL_bool SDL_HasIntersectionF(const SDL_FRect *A, const SDL_FRect *B)
Definition: SDL_render.c:2861
Uint32 render_command_generation
int w
Definition: SDL_rect.h:80
float h
Definition: SDL_rect.h:92
#define SDL_SetError
SDL_Renderer * renderer
Definition: SDL_sysrender.h:55
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:45
int h
Definition: SDL_rect.h:80
void SDL_RenderGetViewport(SDL_Renderer *renderer, SDL_Rect *rect)
Get the drawing area for the current target.
Definition: SDL_render.c:2100
SDL_Texture * native
Definition: SDL_sysrender.h:58
float x
Definition: SDL_rect.h:89
int y
Definition: SDL_rect.h:79
float x
Definition: SDL_rect.h:62
A rectangle, with the origin at the upper left (floating point).
Definition: SDL_rect.h:87
A rectangle, with the origin at the upper left (integer).
Definition: SDL_rect.h:77
float y
Definition: SDL_rect.h:63

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

References SDL_RenderDrawLinesF(), SDL_FPoint::x, and SDL_FPoint::y.

2404 {
2405  SDL_FPoint points[2];
2406  points[0].x = (float) x1;
2407  points[0].y = (float) y1;
2408  points[1].x = (float) x2;
2409  points[1].y = (float) y2;
2410  return SDL_RenderDrawLinesF(renderer, points, 2);
2411 }
GLuint GLfloat GLfloat GLfloat x1
GLfixed GLfixed GLfixed y2
GLfixed GLfixed x2
GLfixed GLfixed GLint GLint GLfixed points
GLfixed y1
int SDL_RenderDrawLinesF(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
Draw a series of connected lines on the current rendering target.
Definition: SDL_render.c:2578
float x
Definition: SDL_rect.h:62
The structure that defines a point (floating point)
Definition: SDL_rect.h:60
float y
Definition: SDL_rect.h:63

◆ SDL_RenderDrawLineF()

int SDL_RenderDrawLineF ( SDL_Renderer renderer,
float  x1,
float  y1,
float  x2,
float  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 2414 of file SDL_render.c.

References SDL_RenderDrawLinesF(), SDL_FPoint::x, and SDL_FPoint::y.

2415 {
2416  SDL_FPoint points[2];
2417  points[0].x = x1;
2418  points[0].y = y1;
2419  points[1].x = x2;
2420  points[1].y = y2;
2421  return SDL_RenderDrawLinesF(renderer, points, 2);
2422 }
GLuint GLfloat GLfloat GLfloat x1
GLfixed GLfixed GLfixed y2
GLfixed GLfixed x2
GLfixed GLfixed GLint GLint GLfixed points
GLfixed y1
int SDL_RenderDrawLinesF(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
Draw a series of connected lines on the current rendering target.
Definition: SDL_render.c:2578
float x
Definition: SDL_rect.h:62
The structure that defines a point (floating point)
Definition: SDL_rect.h:60
float y
Definition: SDL_rect.h:63

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

References CHECK_RENDERER_MAGIC, FlushRenderCommandsIfNotBatching(), SDL_Renderer::hidden, i, QueueCmdDrawLines(), RenderDrawLinesWithRects(), retval, SDL_Renderer::scale, SDL_OutOfMemory, SDL_SetError, SDL_small_alloc, SDL_small_free, SDL_Point::x, SDL_FPoint::x, SDL_Point::y, and SDL_FPoint::y.

2537 {
2538  SDL_FPoint *fpoints;
2539  int i;
2540  int retval;
2541  SDL_bool isstack;
2542 
2543  CHECK_RENDERER_MAGIC(renderer, -1);
2544 
2545  if (!points) {
2546  return SDL_SetError("SDL_RenderDrawLines(): Passed NULL points");
2547  }
2548  if (count < 2) {
2549  return 0;
2550  }
2551 
2552  /* Don't draw while we're hidden */
2553  if (renderer->hidden) {
2554  return 0;
2555  }
2556 
2557  if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) {
2558  return RenderDrawLinesWithRects(renderer, points, count);
2559  }
2560 
2561  fpoints = SDL_small_alloc(SDL_FPoint, count, &isstack);
2562  if (!fpoints) {
2563  return SDL_OutOfMemory();
2564  }
2565  for (i = 0; i < count; ++i) {
2566  fpoints[i].x = points[i].x * renderer->scale.x;
2567  fpoints[i].y = points[i].y * renderer->scale.y;
2568  }
2569 
2570  retval = QueueCmdDrawLines(renderer, fpoints, count);
2571 
2572  SDL_small_free(fpoints, isstack);
2573 
2574  return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
2575 }
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
SDL_bool hidden
SDL_FPoint scale
int x
Definition: SDL_rect.h:50
#define SDL_small_alloc(type, count, pisstack)
Definition: SDL_internal.h:39
SDL_bool retval
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
int y
Definition: SDL_rect.h:51
static int RenderDrawLinesWithRects(SDL_Renderer *renderer, const SDL_Point *points, const int count)
Definition: SDL_render.c:2425
static SDL_INLINE int FlushRenderCommandsIfNotBatching(SDL_Renderer *renderer)
Definition: SDL_render.c:255
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
SDL_bool
Definition: SDL_stdinc.h:161
#define SDL_SetError
#define SDL_small_free(ptr, isstack)
Definition: SDL_internal.h:40
static int QueueCmdDrawLines(SDL_Renderer *renderer, const SDL_FPoint *points, const int count)
Definition: SDL_render.c:543
float x
Definition: SDL_rect.h:62
The structure that defines a point (floating point)
Definition: SDL_rect.h:60
float y
Definition: SDL_rect.h:63

◆ SDL_RenderDrawLinesF()

int SDL_RenderDrawLinesF ( SDL_Renderer renderer,
const SDL_FPoint 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 2578 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, FlushRenderCommandsIfNotBatching(), SDL_Renderer::hidden, i, QueueCmdDrawLines(), RenderDrawLinesWithRectsF(), retval, SDL_Renderer::scale, SDL_OutOfMemory, SDL_SetError, SDL_small_alloc, SDL_small_free, SDL_FPoint::x, and SDL_FPoint::y.

Referenced by SDL_RenderDrawLine(), SDL_RenderDrawLineF(), and SDL_RenderDrawRectF().

2580 {
2581  SDL_FPoint *fpoints;
2582  int i;
2583  int retval;
2584  SDL_bool isstack;
2585 
2586  CHECK_RENDERER_MAGIC(renderer, -1);
2587 
2588  if (!points) {
2589  return SDL_SetError("SDL_RenderDrawLines(): Passed NULL points");
2590  }
2591  if (count < 2) {
2592  return 0;
2593  }
2594 
2595  /* Don't draw while we're hidden */
2596  if (renderer->hidden) {
2597  return 0;
2598  }
2599 
2600  if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) {
2601  return RenderDrawLinesWithRectsF(renderer, points, count);
2602  }
2603 
2604  fpoints = SDL_small_alloc(SDL_FPoint, count, &isstack);
2605  if (!fpoints) {
2606  return SDL_OutOfMemory();
2607  }
2608  for (i = 0; i < count; ++i) {
2609  fpoints[i].x = points[i].x * renderer->scale.x;
2610  fpoints[i].y = points[i].y * renderer->scale.y;
2611  }
2612 
2613  retval = QueueCmdDrawLines(renderer, fpoints, count);
2614 
2615  SDL_small_free(fpoints, isstack);
2616 
2617  return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
2618 }
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
static int RenderDrawLinesWithRectsF(SDL_Renderer *renderer, const SDL_FPoint *points, const int count)
Definition: SDL_render.c:2480
SDL_bool hidden
SDL_FPoint scale
#define SDL_small_alloc(type, count, pisstack)
Definition: SDL_internal.h:39
SDL_bool retval
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
static SDL_INLINE int FlushRenderCommandsIfNotBatching(SDL_Renderer *renderer)
Definition: SDL_render.c:255
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
SDL_bool
Definition: SDL_stdinc.h:161
#define SDL_SetError
#define SDL_small_free(ptr, isstack)
Definition: SDL_internal.h:40
static int QueueCmdDrawLines(SDL_Renderer *renderer, const SDL_FPoint *points, const int count)
Definition: SDL_render.c:543
float x
Definition: SDL_rect.h:62
The structure that defines a point (floating point)
Definition: SDL_rect.h:60
float y
Definition: SDL_rect.h:63

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

References SDL_RenderDrawPointsF(), SDL_FPoint::x, and SDL_FPoint::y.

2246 {
2247  SDL_FPoint fpoint;
2248  fpoint.x = (float) x;
2249  fpoint.y = (float) y;
2250  return SDL_RenderDrawPointsF(renderer, &fpoint, 1);
2251 }
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
int SDL_RenderDrawPointsF(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
Draw multiple points on the current rendering target.
Definition: SDL_render.c:2360
float x
Definition: SDL_rect.h:62
The structure that defines a point (floating point)
Definition: SDL_rect.h:60
float y
Definition: SDL_rect.h:63

◆ SDL_RenderDrawPointF()

int SDL_RenderDrawPointF ( SDL_Renderer renderer,
float  x,
float  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 2254 of file SDL_render.c.

References SDL_RenderDrawPointsF(), SDL_FPoint::x, and SDL_FPoint::y.

2255 {
2256  SDL_FPoint fpoint;
2257  fpoint.x = x;
2258  fpoint.y = y;
2259  return SDL_RenderDrawPointsF(renderer, &fpoint, 1);
2260 }
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
int SDL_RenderDrawPointsF(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
Draw multiple points on the current rendering target.
Definition: SDL_render.c:2360
float x
Definition: SDL_rect.h:62
The structure that defines a point (floating point)
Definition: SDL_rect.h:60
float y
Definition: SDL_rect.h:63

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

References CHECK_RENDERER_MAGIC, FlushRenderCommandsIfNotBatching(), SDL_Renderer::hidden, i, QueueCmdDrawPoints(), RenderDrawPointsWithRects(), retval, SDL_Renderer::scale, SDL_OutOfMemory, SDL_SetError, SDL_small_alloc, SDL_small_free, SDL_Point::x, SDL_FPoint::x, SDL_Point::y, and SDL_FPoint::y.

2292 {
2293  SDL_FPoint *fpoints;
2294  int i;
2295  int retval;
2296  SDL_bool isstack;
2297 
2298  CHECK_RENDERER_MAGIC(renderer, -1);
2299 
2300  if (!points) {
2301  return SDL_SetError("SDL_RenderDrawPoints(): Passed NULL points");
2302  }
2303  if (count < 1) {
2304  return 0;
2305  }
2306 
2307  /* Don't draw while we're hidden */
2308  if (renderer->hidden) {
2309  return 0;
2310  }
2311 
2312  if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) {
2313  return RenderDrawPointsWithRects(renderer, points, count);
2314  }
2315 
2316  fpoints = SDL_small_alloc(SDL_FPoint, count, &isstack);
2317  if (!fpoints) {
2318  return SDL_OutOfMemory();
2319  }
2320  for (i = 0; i < count; ++i) {
2321  fpoints[i].x = points[i].x * renderer->scale.x;
2322  fpoints[i].y = points[i].y * renderer->scale.y;
2323  }
2324 
2325  retval = QueueCmdDrawPoints(renderer, fpoints, count);
2326 
2327  SDL_small_free(fpoints, isstack);
2328 
2329  return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
2330 }
static int RenderDrawPointsWithRects(SDL_Renderer *renderer, const SDL_Point *points, const int count)
Definition: SDL_render.c:2263
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
SDL_bool hidden
SDL_FPoint scale
int x
Definition: SDL_rect.h:50
#define SDL_small_alloc(type, count, pisstack)
Definition: SDL_internal.h:39
SDL_bool retval
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
int y
Definition: SDL_rect.h:51
static SDL_INLINE int FlushRenderCommandsIfNotBatching(SDL_Renderer *renderer)
Definition: SDL_render.c:255
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
SDL_bool
Definition: SDL_stdinc.h:161
#define SDL_SetError
#define SDL_small_free(ptr, isstack)
Definition: SDL_internal.h:40
float x
Definition: SDL_rect.h:62
The structure that defines a point (floating point)
Definition: SDL_rect.h:60
static int QueueCmdDrawPoints(SDL_Renderer *renderer, const SDL_FPoint *points, const int count)
Definition: SDL_render.c:529
float y
Definition: SDL_rect.h:63

◆ SDL_RenderDrawPointsF()

int SDL_RenderDrawPointsF ( SDL_Renderer renderer,
const SDL_FPoint 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 2360 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, FlushRenderCommandsIfNotBatching(), SDL_Renderer::hidden, i, QueueCmdDrawPoints(), RenderDrawPointsWithRectsF(), retval, SDL_Renderer::scale, SDL_OutOfMemory, SDL_SetError, SDL_small_alloc, SDL_small_free, SDL_FPoint::x, and SDL_FPoint::y.

Referenced by SDL_RenderDrawPoint(), and SDL_RenderDrawPointF().

2362 {
2363  SDL_FPoint *fpoints;
2364  int i;
2365  int retval;
2366  SDL_bool isstack;
2367 
2368  CHECK_RENDERER_MAGIC(renderer, -1);
2369 
2370  if (!points) {
2371  return SDL_SetError("SDL_RenderDrawFPoints(): Passed NULL points");
2372  }
2373  if (count < 1) {
2374  return 0;
2375  }
2376 
2377  /* Don't draw while we're hidden */
2378  if (renderer->hidden) {
2379  return 0;
2380  }
2381 
2382  if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) {
2383  return RenderDrawPointsWithRectsF(renderer, points, count);
2384  }
2385 
2386  fpoints = SDL_small_alloc(SDL_FPoint, count, &isstack);
2387  if (!fpoints) {
2388  return SDL_OutOfMemory();
2389  }
2390  for (i = 0; i < count; ++i) {
2391  fpoints[i].x = points[i].x * renderer->scale.x;
2392  fpoints[i].y = points[i].y * renderer->scale.y;
2393  }
2394 
2395  retval = QueueCmdDrawPoints(renderer, fpoints, count);
2396 
2397  SDL_small_free(fpoints, isstack);
2398 
2399  return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
2400 }
static int RenderDrawPointsWithRectsF(SDL_Renderer *renderer, const SDL_FPoint *fpoints, const int count)
Definition: SDL_render.c:2333
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
SDL_bool hidden
SDL_FPoint scale
#define SDL_small_alloc(type, count, pisstack)
Definition: SDL_internal.h:39
SDL_bool retval
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
static SDL_INLINE int FlushRenderCommandsIfNotBatching(SDL_Renderer *renderer)
Definition: SDL_render.c:255
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
SDL_bool
Definition: SDL_stdinc.h:161
#define SDL_SetError
#define SDL_small_free(ptr, isstack)
Definition: SDL_internal.h:40
float x
Definition: SDL_rect.h:62
The structure that defines a point (floating point)
Definition: SDL_rect.h:60
static int QueueCmdDrawPoints(SDL_Renderer *renderer, const SDL_FPoint *points, const int count)
Definition: SDL_render.c:529
float y
Definition: SDL_rect.h:63

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

References SDL_Rect::h, SDL_FRect::h, NULL, SDL_RenderDrawRectF(), SDL_Rect::w, SDL_FRect::w, SDL_Rect::x, SDL_FRect::x, SDL_Rect::y, and SDL_FRect::y.

Referenced by SDL_RenderDrawRects().

2622 {
2623  SDL_FRect frect;
2624  SDL_FRect *prect = NULL;
2625 
2626  if (rect) {
2627  frect.x = (float) rect->x;
2628  frect.y = (float) rect->y;
2629  frect.w = (float) rect->w;
2630  frect.h = (float) rect->h;
2631  prect = &frect;
2632  }
2633 
2634  return SDL_RenderDrawRectF(renderer, prect);
2635 }
float w
Definition: SDL_rect.h:91
float y
Definition: SDL_rect.h:90
int x
Definition: SDL_rect.h:79
int w
Definition: SDL_rect.h:80
float h
Definition: SDL_rect.h:92
#define NULL
Definition: begin_code.h:167
int SDL_RenderDrawRectF(SDL_Renderer *renderer, const SDL_FRect *rect)
Draw a rectangle on the current rendering target.
Definition: SDL_render.c:2638
int h
Definition: SDL_rect.h:80
float x
Definition: SDL_rect.h:89
int y
Definition: SDL_rect.h:79
A rectangle, with the origin at the upper left (floating point).
Definition: SDL_rect.h:87

◆ SDL_RenderDrawRectF()

int SDL_RenderDrawRectF ( SDL_Renderer renderer,
const SDL_FRect 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 2638 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Rect::h, SDL_FRect::h, SDL_RenderDrawLinesF(), SDL_RenderGetViewport(), SDL_Rect::w, SDL_FRect::w, SDL_FPoint::x, SDL_FRect::x, SDL_FPoint::y, and SDL_FRect::y.

Referenced by SDL_RenderDrawRect(), and SDL_RenderDrawRectsF().

2639 {
2640  SDL_FRect frect;
2641  SDL_FPoint points[5];
2642 
2643  CHECK_RENDERER_MAGIC(renderer, -1);
2644 
2645  /* If 'rect' == NULL, then outline the whole surface */
2646  if (!rect) {
2647  SDL_Rect r;
2648  SDL_RenderGetViewport(renderer, &r);
2649  frect.x = 0.0f;
2650  frect.y = 0.0f;
2651  frect.w = (float) r.w;
2652  frect.h = (float) r.h;
2653  rect = &frect;
2654  }
2655 
2656  points[0].x = rect->x;
2657  points[0].y = rect->y;
2658  points[1].x = rect->x+rect->w-1;
2659  points[1].y = rect->y;
2660  points[2].x = rect->x+rect->w-1;
2661  points[2].y = rect->y+rect->h-1;
2662  points[3].x = rect->x;
2663  points[3].y = rect->y+rect->h-1;
2664  points[4].x = rect->x;
2665  points[4].y = rect->y;
2666  return SDL_RenderDrawLinesF(renderer, points, 5);
2667 }
float w
Definition: SDL_rect.h:91
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
float y
Definition: SDL_rect.h:90
GLfixed GLfixed GLint GLint GLfixed points
int SDL_RenderDrawLinesF(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
Draw a series of connected lines on the current rendering target.
Definition: SDL_render.c:2578
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
int w
Definition: SDL_rect.h:80
float h
Definition: SDL_rect.h:92
int h
Definition: SDL_rect.h:80
void SDL_RenderGetViewport(SDL_Renderer *renderer, SDL_Rect *rect)
Get the drawing area for the current target.
Definition: SDL_render.c:2100
float x
Definition: SDL_rect.h:89
float x
Definition: SDL_rect.h:62
A rectangle, with the origin at the upper left (floating point).
Definition: SDL_rect.h:87
The structure that defines a point (floating point)
Definition: SDL_rect.h:60
A rectangle, with the origin at the upper left (integer).
Definition: SDL_rect.h:77
float y
Definition: SDL_rect.h:63

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

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

2672 {
2673  int i;
2674 
2675  CHECK_RENDERER_MAGIC(renderer, -1);
2676 
2677  if (!rects) {
2678  return SDL_SetError("SDL_RenderDrawRects(): Passed NULL rects");
2679  }
2680  if (count < 1) {
2681  return 0;
2682  }
2683 
2684  /* Don't draw while we're hidden */
2685  if (renderer->hidden) {
2686  return 0;
2687  }
2688 
2689  for (i = 0; i < count; ++i) {
2690  if (SDL_RenderDrawRect(renderer, &rects[i]) < 0) {
2691  return -1;
2692  }
2693  }
2694  return 0;
2695 }
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
SDL_bool hidden
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
int SDL_RenderDrawRect(SDL_Renderer *renderer, const SDL_Rect *rect)
Draw a rectangle on the current rendering target.
Definition: SDL_render.c:2621
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_RenderDrawRectsF()

int SDL_RenderDrawRectsF ( SDL_Renderer renderer,
const SDL_FRect 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 2698 of file SDL_render.c.

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

2700 {
2701  int i;
2702 
2703  CHECK_RENDERER_MAGIC(renderer, -1);
2704 
2705  if (!rects) {
2706  return SDL_SetError("SDL_RenderDrawRects(): Passed NULL rects");
2707  }
2708  if (count < 1) {
2709  return 0;
2710  }
2711 
2712  /* Don't draw while we're hidden */
2713  if (renderer->hidden) {
2714  return 0;
2715  }
2716 
2717  for (i = 0; i < count; ++i) {
2718  if (SDL_RenderDrawRectF(renderer, &rects[i]) < 0) {
2719  return -1;
2720  }
2721  }
2722  return 0;
2723 }
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
SDL_bool hidden
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
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_RenderDrawRectF(SDL_Renderer *renderer, const SDL_FRect *rect)
Draw a rectangle on the current rendering target.
Definition: SDL_render.c:2638
#define SDL_SetError

◆ SDL_RenderFillRect()

int SDL_RenderFillRect ( SDL_Renderer renderer,
const SDL_Rect rect 
)

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

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

Definition at line 2726 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Rect::h, SDL_FRect::h, SDL_RenderFillRectsF(), SDL_RenderGetViewport(), SDL_zero, SDL_Rect::w, SDL_FRect::w, SDL_Rect::x, SDL_FRect::x, SDL_Rect::y, and SDL_FRect::y.

2727 {
2728  SDL_FRect frect;
2729 
2730  CHECK_RENDERER_MAGIC(renderer, -1);
2731 
2732  /* If 'rect' == NULL, then outline the whole surface */
2733  if (rect) {
2734  frect.x = (float) rect->x;
2735  frect.y = (float) rect->y;
2736  frect.w = (float) rect->w;
2737  frect.h = (float) rect->h;
2738  } else {
2739  SDL_Rect r;
2740  SDL_zero(r);
2741  SDL_RenderGetViewport(renderer, &r);
2742  frect.x = 0.0f;
2743  frect.y = 0.0f;
2744  frect.w = (float) r.w;
2745  frect.h = (float) r.h;
2746  }
2747  return SDL_RenderFillRectsF(renderer, &frect, 1);
2748 }
float w
Definition: SDL_rect.h:91
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
int SDL_RenderFillRectsF(SDL_Renderer *renderer, const SDL_FRect *rects, int count)
Fill some number of rectangles on the current rendering target with the drawing color.
Definition: SDL_render.c:2813
float y
Definition: SDL_rect.h:90
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
#define SDL_zero(x)
Definition: SDL_stdinc.h:416
int x
Definition: SDL_rect.h:79
int w
Definition: SDL_rect.h:80
float h
Definition: SDL_rect.h:92
int h
Definition: SDL_rect.h:80
void SDL_RenderGetViewport(SDL_Renderer *renderer, SDL_Rect *rect)
Get the drawing area for the current target.
Definition: SDL_render.c:2100
float x
Definition: SDL_rect.h:89
int y
Definition: SDL_rect.h:79
A rectangle, with the origin at the upper left (floating point).
Definition: SDL_rect.h:87
A rectangle, with the origin at the upper left (integer).
Definition: SDL_rect.h:77

◆ SDL_RenderFillRectF()

int SDL_RenderFillRectF ( SDL_Renderer renderer,
const SDL_FRect 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 2751 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Rect::h, SDL_FRect::h, SDL_RenderFillRectsF(), SDL_RenderGetViewport(), SDL_zero, SDL_Rect::w, SDL_FRect::w, SDL_FRect::x, and SDL_FRect::y.

2752 {
2753  SDL_FRect frect;
2754 
2755  CHECK_RENDERER_MAGIC(renderer, -1);
2756 
2757  /* If 'rect' == NULL, then outline the whole surface */
2758  if (!rect) {
2759  SDL_Rect r;
2760  SDL_zero(r);
2761  SDL_RenderGetViewport(renderer, &r);
2762  frect.x = 0.0f;
2763  frect.y = 0.0f;
2764  frect.w = (float) r.w;
2765  frect.h = (float) r.h;
2766  rect = &frect;
2767  }
2768  return SDL_RenderFillRectsF(renderer, rect, 1);
2769 }
float w
Definition: SDL_rect.h:91
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
int SDL_RenderFillRectsF(SDL_Renderer *renderer, const SDL_FRect *rects, int count)
Fill some number of rectangles on the current rendering target with the drawing color.
Definition: SDL_render.c:2813
float y
Definition: SDL_rect.h:90
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
#define SDL_zero(x)
Definition: SDL_stdinc.h:416
int w
Definition: SDL_rect.h:80
float h
Definition: SDL_rect.h:92
int h
Definition: SDL_rect.h:80
void SDL_RenderGetViewport(SDL_Renderer *renderer, SDL_Rect *rect)
Get the drawing area for the current target.
Definition: SDL_render.c:2100
float x
Definition: SDL_rect.h:89
A rectangle, with the origin at the upper left (floating point).
Definition: SDL_rect.h:87
A rectangle, with the origin at the upper left (integer).
Definition: SDL_rect.h:77

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

References CHECK_RENDERER_MAGIC, FlushRenderCommandsIfNotBatching(), SDL_Rect::h, SDL_FRect::h, SDL_Renderer::hidden, i, QueueCmdFillRects(), retval, SDL_Renderer::scale, SDL_OutOfMemory, SDL_SetError, SDL_small_alloc, SDL_small_free, SDL_Rect::w, SDL_FRect::w, SDL_FPoint::x, SDL_Rect::x, SDL_FRect::x, SDL_FPoint::y, SDL_Rect::y, and SDL_FRect::y.

2774 {
2775  SDL_FRect *frects;
2776  int i;
2777  int retval;
2778  SDL_bool isstack;
2779 
2780  CHECK_RENDERER_MAGIC(renderer, -1);
2781 
2782  if (!rects) {
2783  return SDL_SetError("SDL_RenderFillRects(): Passed NULL rects");
2784  }
2785  if (count < 1) {
2786  return 0;
2787  }
2788 
2789  /* Don't draw while we're hidden */
2790  if (renderer->hidden) {
2791  return 0;
2792  }
2793 
2794  frects = SDL_small_alloc(SDL_FRect, count, &isstack);
2795  if (!frects) {
2796  return SDL_OutOfMemory();
2797  }
2798  for (i = 0; i < count; ++i) {
2799  frects[i].x = rects[i].x * renderer->scale.x;
2800  frects[i].y = rects[i].y * renderer->scale.y;
2801  frects[i].w = rects[i].w * renderer->scale.x;
2802  frects[i].h = rects[i].h * renderer->scale.y;
2803  }
2804 
2805  retval = QueueCmdFillRects(renderer, frects, count);
2806 
2807  SDL_small_free(frects, isstack);
2808 
2809  return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
2810 }
float w
Definition: SDL_rect.h:91
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
SDL_bool hidden
SDL_FPoint scale
float y
Definition: SDL_rect.h:90
#define SDL_small_alloc(type, count, pisstack)
Definition: SDL_internal.h:39
SDL_bool retval
static int QueueCmdFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, const int count)
Definition: SDL_render.c:557
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
static SDL_INLINE int FlushRenderCommandsIfNotBatching(SDL_Renderer *renderer)
Definition: SDL_render.c:255
int x
Definition: SDL_rect.h:79
int w
Definition: SDL_rect.h:80
float h
Definition: SDL_rect.h:92
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
SDL_bool
Definition: SDL_stdinc.h:161
#define SDL_SetError
int h
Definition: SDL_rect.h:80
#define SDL_small_free(ptr, isstack)
Definition: SDL_internal.h:40
float x
Definition: SDL_rect.h:89
int y
Definition: SDL_rect.h:79
float x
Definition: SDL_rect.h:62
A rectangle, with the origin at the upper left (floating point).
Definition: SDL_rect.h:87
float y
Definition: SDL_rect.h:63

◆ SDL_RenderFillRectsF()

int SDL_RenderFillRectsF ( SDL_Renderer renderer,
const SDL_FRect 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 2813 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, FlushRenderCommandsIfNotBatching(), SDL_FRect::h, SDL_Renderer::hidden, i, QueueCmdFillRects(), retval, SDL_Renderer::scale, SDL_OutOfMemory, SDL_SetError, SDL_small_alloc, SDL_small_free, SDL_FRect::w, SDL_FPoint::x, SDL_FRect::x, SDL_FPoint::y, and SDL_FRect::y.

Referenced by SDL_RenderFillRect(), and SDL_RenderFillRectF().

2815 {
2816  SDL_FRect *frects;
2817  int i;
2818  int retval;
2819  SDL_bool isstack;
2820 
2821  CHECK_RENDERER_MAGIC(renderer, -1);
2822 
2823  if (!rects) {
2824  return SDL_SetError("SDL_RenderFillFRects(): Passed NULL rects");
2825  }
2826  if (count < 1) {
2827  return 0;
2828  }
2829 
2830  /* Don't draw while we're hidden */
2831  if (renderer->hidden) {
2832  return 0;
2833  }
2834 
2835  frects = SDL_small_alloc(SDL_FRect, count, &isstack);
2836  if (!frects) {
2837  return SDL_OutOfMemory();
2838  }
2839  for (i = 0; i < count; ++i) {
2840  frects[i].x = rects[i].x * renderer->scale.x;
2841  frects[i].y = rects[i].y * renderer->scale.y;
2842  frects[i].w = rects[i].w * renderer->scale.x;
2843  frects[i].h = rects[i].h * renderer->scale.y;
2844  }
2845 
2846  retval = QueueCmdFillRects(renderer, frects, count);
2847 
2848  SDL_small_free(frects, isstack);
2849 
2850  return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
2851 }
float w
Definition: SDL_rect.h:91
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
SDL_bool hidden
SDL_FPoint scale
float y
Definition: SDL_rect.h:90
#define SDL_small_alloc(type, count, pisstack)
Definition: SDL_internal.h:39
SDL_bool retval
static int QueueCmdFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, const int count)
Definition: SDL_render.c:557
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
static SDL_INLINE int FlushRenderCommandsIfNotBatching(SDL_Renderer *renderer)
Definition: SDL_render.c:255
float h
Definition: SDL_rect.h:92
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
SDL_bool
Definition: SDL_stdinc.h:161
#define SDL_SetError
#define SDL_small_free(ptr, isstack)
Definition: SDL_internal.h:40
float x
Definition: SDL_rect.h:89
float x
Definition: SDL_rect.h:62
A rectangle, with the origin at the upper left (floating point).
Definition: SDL_rect.h:87
float y
Definition: SDL_rect.h:63

◆ SDL_RenderFlush()

int SDL_RenderFlush ( SDL_Renderer renderer)

Force the rendering context to flush any pending commands to the underlying rendering API.

You do not need to (and in fact, shouldn't) call this function unless you are planning to call into OpenGL/Direct3D/Metal/whatever directly in addition to using an SDL_Renderer.

This is for a very-specific case: if you are using SDL's render API, you asked for a specific renderer backend (OpenGL, Direct3D, etc), you set SDL_HINT_RENDER_BATCHING to "1", and you plan to make OpenGL/D3D/whatever calls in addition to SDL render API calls. If all of this applies, you should call SDL_RenderFlush() between calls to SDL's render API and the low-level API you're using in cooperation.

In all other cases, you can ignore this function. This is only here to get maximum performance out of a specific situation. In all other cases, SDL will do the right thing, perhaps at a performance loss.

This function is first available in SDL 2.0.10, and is not needed in 2.0.9 and earlier, as earlier versions did not queue rendering commands at all, instead flushing them to the OS immediately.

Definition at line 261 of file SDL_render.c.

References FlushRenderCommands().

262 {
263  return FlushRenderCommands(renderer);
264 }
static int FlushRenderCommands(SDL_Renderer *renderer)
Definition: SDL_render.c:203

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

2135 {
2136  CHECK_RENDERER_MAGIC(renderer, )
2137 
2138  if (rect) {
2139  rect->x = (int)(renderer->clip_rect.x / renderer->scale.x);
2140  rect->y = (int)(renderer->clip_rect.y / renderer->scale.y);
2141  rect->w = (int)(renderer->clip_rect.w / renderer->scale.x);
2142  rect->h = (int)(renderer->clip_rect.h / renderer->scale.y);
2143  }
2144 }
SDL_FPoint scale
SDL_Rect clip_rect
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
int x
Definition: SDL_rect.h:79
int w
Definition: SDL_rect.h:80
int h
Definition: SDL_rect.h:80
int y
Definition: SDL_rect.h:79
float x
Definition: SDL_rect.h:62
float y
Definition: SDL_rect.h:63

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

References CHECK_RENDERER_MAGIC, SDL_Renderer::integer_scale, and SDL_FALSE.

2071 {
2072  CHECK_RENDERER_MAGIC(renderer, SDL_FALSE);
2073 
2074  return renderer->integer_scale;
2075 }
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
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 2047 of file SDL_render.c.

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

2048 {
2049  CHECK_RENDERER_MAGIC(renderer, );
2050 
2051  if (w) {
2052  *w = renderer->logical_w;
2053  }
2054  if (h) {
2055  *h = renderer->logical_h;
2056  }
2057 }
GLfloat GLfloat GLfloat GLfloat h
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
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 3283 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, FlushRenderCommands(), SDL_Renderer::GetMetalCommandEncoder, and NULL.

3284 {
3285  CHECK_RENDERER_MAGIC(renderer, NULL);
3286 
3287  if (renderer->GetMetalCommandEncoder) {
3288  FlushRenderCommands(renderer); /* in case the app is going to mess with it. */
3289  return renderer->GetMetalCommandEncoder(renderer);
3290  }
3291  return NULL;
3292 }
static int FlushRenderCommands(SDL_Renderer *renderer)
Definition: SDL_render.c:203
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
#define NULL
Definition: begin_code.h:167
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 3271 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, FlushRenderCommands(), SDL_Renderer::GetMetalLayer, and NULL.

3272 {
3273  CHECK_RENDERER_MAGIC(renderer, NULL);
3274 
3275  if (renderer->GetMetalLayer) {
3276  FlushRenderCommands(renderer); /* in case the app is going to mess with it. */
3277  return renderer->GetMetalLayer(renderer);
3278  }
3279  return NULL;
3280 }
static int FlushRenderCommands(SDL_Renderer *renderer)
Definition: SDL_render.c:203
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
void *(* GetMetalLayer)(SDL_Renderer *renderer)
#define NULL
Definition: begin_code.h:167

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

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

2165 {
2166  CHECK_RENDERER_MAGIC(renderer, );
2167 
2168  if (scaleX) {
2169  *scaleX = renderer->scale.x;
2170  }
2171  if (scaleY) {
2172  *scaleY = renderer->scale.y;
2173  }
2174 }
SDL_FPoint scale
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
float x
Definition: SDL_rect.h:62
float y
Definition: SDL_rect.h:63

◆ 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 2100 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_RenderCopyExF(), SDL_RenderCopyF(), SDL_RenderDrawRectF(), SDL_RenderFillRect(), and SDL_RenderFillRectF().

2101 {
2102  CHECK_RENDERER_MAGIC(renderer, );
2103 
2104  if (rect) {
2105  rect->x = (int)(renderer->viewport.x / renderer->scale.x);
2106  rect->y = (int)(renderer->viewport.y / renderer->scale.y);
2107  rect->w = (int)(renderer->viewport.w / renderer->scale.x);
2108  rect->h = (int)(renderer->viewport.h / renderer->scale.y);
2109  }
2110 }
SDL_FPoint scale
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
int x
Definition: SDL_rect.h:79
int w
Definition: SDL_rect.h:80
SDL_Rect viewport
int h
Definition: SDL_rect.h:80
int y
Definition: SDL_rect.h:79
float x
Definition: SDL_rect.h:62
float y
Definition: SDL_rect.h:63

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

References CHECK_RENDERER_MAGIC, SDL_Renderer::clipping_enabled, and SDL_FALSE.

2148 {
2149  CHECK_RENDERER_MAGIC(renderer, SDL_FALSE)
2150  return renderer->clipping_enabled;
2151 }
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
SDL_bool clipping_enabled

◆ SDL_RenderPresent()

void SDL_RenderPresent ( SDL_Renderer renderer)

Update the screen with rendering performed.

Definition at line 3126 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, FlushRenderCommands(), SDL_Renderer::hidden, and SDL_Renderer::RenderPresent.

3127 {
3128  CHECK_RENDERER_MAGIC(renderer, );
3129 
3130  FlushRenderCommands(renderer); /* time to send everything to the GPU! */
3131 
3132  /* Don't present while we're hidden */
3133  if (renderer->hidden) {
3134  return;
3135  }
3136  renderer->RenderPresent(renderer);
3137 }
static int FlushRenderCommands(SDL_Renderer *renderer)
Definition: SDL_render.c:203
SDL_bool hidden
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
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 3087 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, FlushRenderCommands(), 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.

3089 {
3090  SDL_Rect real_rect;
3091 
3092  CHECK_RENDERER_MAGIC(renderer, -1);
3093 
3094  if (!renderer->RenderReadPixels) {
3095  return SDL_Unsupported();
3096  }
3097 
3098  FlushRenderCommands(renderer); /* we need to render before we read the results. */
3099 
3100  if (!format) {
3101  format = SDL_GetWindowPixelFormat(renderer->window);
3102  }
3103 
3104  real_rect.x = renderer->viewport.x;
3105  real_rect.y = renderer->viewport.y;
3106  real_rect.w = renderer->viewport.w;
3107  real_rect.h = renderer->viewport.h;
3108  if (rect) {
3109  if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
3110  return 0;
3111  }
3112  if (real_rect.y > rect->y) {
3113  pixels = (Uint8 *)pixels + pitch * (real_rect.y - rect->y);
3114  }
3115  if (real_rect.x > rect->x) {
3116  int bpp = SDL_BYTESPERPIXEL(format);
3117  pixels = (Uint8 *)pixels + bpp * (real_rect.x - rect->x);
3118  }
3119  }
3120 
3121  return renderer->RenderReadPixels(renderer, &real_rect,
3122  format, pixels, pitch);
3123 }
int(* RenderReadPixels)(SDL_Renderer *renderer, const SDL_Rect *rect, Uint32 format, void *pixels, int pitch)
static int FlushRenderCommands(SDL_Renderer *renderer)
Definition: SDL_render.c:203
#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:38
uint8_t Uint8
Definition: SDL_stdinc.h:179
int x
Definition: SDL_rect.h:79
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
int w
Definition: SDL_rect.h:80
SDL_Rect viewport
int h
Definition: SDL_rect.h:80
#define SDL_GetWindowPixelFormat
int y
Definition: SDL_rect.h:79
#define SDL_Unsupported()
Definition: SDL_error.h:53
A rectangle, with the origin at the upper left (integer).
Definition: SDL_rect.h:77

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

References CHECK_RENDERER_MAGIC, SDL_Renderer::clip_rect, SDL_Renderer::clipping_enabled, FlushRenderCommandsIfNotBatching(), SDL_Rect::h, QueueCmdSetClipRect(), retval, SDL_Renderer::scale, SDL_ceil, SDL_FALSE, SDL_floor, SDL_TRUE, SDL_zero, SDL_Rect::w, SDL_FPoint::x, SDL_Rect::x, SDL_FPoint::y, and SDL_Rect::y.

2114 {
2115  int retval;
2116  CHECK_RENDERER_MAGIC(renderer, -1)
2117 
2118  if (rect) {
2119  renderer->clipping_enabled = SDL_TRUE;
2120  renderer->clip_rect.x = (int)SDL_floor(rect->x * renderer->scale.x);
2121  renderer->clip_rect.y = (int)SDL_floor(rect->y * renderer->scale.y);
2122  renderer->clip_rect.w = (int)SDL_ceil(rect->w * renderer->scale.x);
2123  renderer->clip_rect.h = (int)SDL_ceil(rect->h * renderer->scale.y);
2124  } else {
2125  renderer->clipping_enabled = SDL_FALSE;
2126  SDL_zero(renderer->clip_rect);
2127  }
2128 
2129  retval = QueueCmdSetClipRect(renderer);
2130  return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
2131 }
#define SDL_ceil
SDL_FPoint scale
SDL_Rect clip_rect
#define SDL_floor
SDL_bool retval
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
static SDL_INLINE int FlushRenderCommandsIfNotBatching(SDL_Renderer *renderer)
Definition: SDL_render.c:255
#define SDL_zero(x)
Definition: SDL_stdinc.h:416
int x
Definition: SDL_rect.h:79
int w
Definition: SDL_rect.h:80
int h
Definition: SDL_rect.h:80
static int QueueCmdSetClipRect(SDL_Renderer *renderer)
Definition: SDL_render.c:423
int y
Definition: SDL_rect.h:79
float x
Definition: SDL_rect.h:62
SDL_bool clipping_enabled
float y
Definition: SDL_rect.h:63

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

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

2061 {
2062  CHECK_RENDERER_MAGIC(renderer, -1);
2063 
2064  renderer->integer_scale = enable;
2065 
2066  return UpdateLogicalSize(renderer);
2067 }
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
static int UpdateLogicalSize(SDL_Renderer *renderer)
Definition: SDL_render.c:1918
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 2027 of file SDL_render.c.

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

2028 {
2029  CHECK_RENDERER_MAGIC(renderer, -1);
2030 
2031  if (!w || !h) {
2032  /* Clear any previous logical resolution */
2033  renderer->logical_w = 0;
2034  renderer->logical_h = 0;
2035  SDL_RenderSetViewport(renderer, NULL);
2036  SDL_RenderSetScale(renderer, 1.0f, 1.0f);
2037  return 0;
2038  }
2039 
2040  renderer->logical_w = w;
2041  renderer->logical_h = h;
2042 
2043  return UpdateLogicalSize(renderer);
2044 }
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:2078
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
GLubyte GLubyte GLubyte GLubyte w
static int UpdateLogicalSize(SDL_Renderer *renderer)
Definition: SDL_render.c:1918
int SDL_RenderSetScale(SDL_Renderer *renderer, float scaleX, float scaleY)
Set the drawing scale for rendering on the current target.
Definition: SDL_render.c:2154
#define NULL
Definition: begin_code.h:167

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

2155 {
2156  CHECK_RENDERER_MAGIC(renderer, -1);
2157 
2158  renderer->scale.x = scaleX;
2159  renderer->scale.y = scaleY;
2160  return 0;
2161 }
SDL_FPoint scale
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
float x
Definition: SDL_rect.h:62
float y
Definition: SDL_rect.h:63

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

References CHECK_RENDERER_MAGIC, FlushRenderCommandsIfNotBatching(), SDL_Rect::h, QueueCmdSetViewport(), retval, SDL_Renderer::scale, SDL_ceil, SDL_floor, SDL_GetRendererOutputSize(), 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().

2079 {
2080  int retval;
2081  CHECK_RENDERER_MAGIC(renderer, -1);
2082 
2083  if (rect) {
2084  renderer->viewport.x = (int)SDL_floor(rect->x * renderer->scale.x);
2085  renderer->viewport.y = (int)SDL_floor(rect->y * renderer->scale.y);
2086  renderer->viewport.w = (int)SDL_ceil(rect->w * renderer->scale.x);
2087  renderer->viewport.h = (int)SDL_ceil(rect->h * renderer->scale.y);
2088  } else {
2089  renderer->viewport.x = 0;
2090  renderer->viewport.y = 0;
2091  if (SDL_GetRendererOutputSize(renderer, &renderer->viewport.w, &renderer->viewport.h) < 0) {
2092  return -1;
2093  }
2094  }
2095  retval = QueueCmdSetViewport(renderer);
2096  return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
2097 }
#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:1022
SDL_bool retval
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
static SDL_INLINE int FlushRenderCommandsIfNotBatching(SDL_Renderer *renderer)
Definition: SDL_render.c:255
int x
Definition: SDL_rect.h:79
int w
Definition: SDL_rect.h:80
SDL_Rect viewport
int h
Definition: SDL_rect.h:80
static int QueueCmdSetViewport(SDL_Renderer *renderer)
Definition: SDL_render.c:400
int y
Definition: SDL_rect.h:79
float x
Definition: SDL_rect.h:62
float y
Definition: SDL_rect.h:63

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

1825 {
1826  if (!renderer || !renderer->SetRenderTarget) {
1827  return SDL_FALSE;
1828  }
1829  return (renderer->info.flags & SDL_RENDERER_TARGETTEXTURE) != 0;
1830 }
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 2211 of file SDL_render.c.

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

2212 {
2213  CHECK_RENDERER_MAGIC(renderer, -1);
2214 
2215  if (!IsSupportedBlendMode(renderer, blendMode)) {
2216  return SDL_Unsupported();
2217  }
2218  renderer->blendMode = blendMode;
2219  return 0;
2220 }
static SDL_BlendMode blendMode
Definition: testdraw2.c:34
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
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:1040

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

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

2179 {
2180  CHECK_RENDERER_MAGIC(renderer, -1);
2181 
2182  renderer->r = r;
2183  renderer->g = g;
2184  renderer->b = b;
2185  renderer->a = a;
2186  return 0;
2187 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
#define CHECK_RENDERER_MAGIC(renderer, retval)
Definition: SDL_render.c:38
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 1833 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, FlushRenderCommands(), FlushRenderCommandsIfNotBatching(), 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, QueueCmdSetClipRect(), QueueCmdSetViewport(), 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::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().

1834 {
1835  if (!SDL_RenderTargetSupported(renderer)) {
1836  return SDL_Unsupported();
1837  }
1838  if (texture == renderer->target) {
1839  /* Nothing to do! */
1840  return 0;
1841  }
1842 
1843  FlushRenderCommands(renderer); /* time to send everything to the GPU! */
1844 
1845  /* texture == NULL is valid and means reset the target to the window */
1846  if (texture) {
1847  CHECK_TEXTURE_MAGIC(texture, -1);
1848  if (renderer != texture->renderer) {
1849  return SDL_SetError("Texture was not created with this renderer");
1850  }
1851  if (texture->access != SDL_TEXTUREACCESS_TARGET) {
1852  return SDL_SetError("Texture not created with SDL_TEXTUREACCESS_TARGET");
1853  }
1854  if (texture->native) {
1855  /* Always render to the native texture */
1856  texture = texture->native;
1857  }
1858  }
1859 
1860  SDL_LockMutex(renderer->target_mutex);
1861 
1862  if (texture && !renderer->target) {
1863  /* Make a backup of the viewport */
1864  renderer->viewport_backup = renderer->viewport;
1865  renderer->clip_rect_backup = renderer->clip_rect;
1866  renderer->clipping_enabled_backup = renderer->clipping_enabled;
1867  renderer->scale_backup = renderer->scale;
1868  renderer->logical_w_backup = renderer->logical_w;
1869  renderer->logical_h_backup = renderer->logical_h;
1870  }
1871  renderer->target = texture;
1872 
1873  if (renderer->SetRenderTarget(renderer, texture) < 0) {
1874  SDL_UnlockMutex(renderer->target_mutex);
1875  return -1;
1876  }
1877 
1878  if (texture) {
1879  renderer->viewport.x = 0;
1880  renderer->viewport.y = 0;
1881  renderer->viewport.w = texture->w;
1882  renderer->viewport.h = texture->h;
1883  SDL_zero(renderer->clip_rect);
1884  renderer->clipping_enabled = SDL_FALSE;
1885  renderer->scale.x = 1.0f;
1886  renderer->scale.y = 1.0f;
1887  renderer->logical_w = texture->w;
1888  renderer->logical_h = texture->h;
1889  } else {
1890  renderer->viewport = renderer->viewport_backup;
1891  renderer->clip_rect = renderer->clip_rect_backup;
1892  renderer->clipping_enabled = renderer->clipping_enabled_backup;
1893  renderer->scale = renderer->scale_backup;
1894  renderer->logical_w = renderer->logical_w_backup;
1895  renderer->logical_h = renderer->logical_h_backup;
1896  }
1897 
1898  SDL_UnlockMutex(renderer->target_mutex);
1899 
1900  if (QueueCmdSetViewport(renderer) < 0) {
1901  return -1;
1902  }
1903  if (QueueCmdSetClipRect(renderer) < 0) {
1904  return -1;
1905  }
1906 
1907  /* All set! */
1908  return FlushRenderCommandsIfNotBatching(renderer);
1909 }
#define SDL_LockMutex
static int FlushRenderCommands(SDL_Renderer *renderer)
Definition: SDL_render.c:203
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
static SDL_INLINE int FlushRenderCommandsIfNotBatching(SDL_Renderer *renderer)
Definition: SDL_render.c:255
#define SDL_zero(x)
Definition: SDL_stdinc.h:416
int x
Definition: SDL_rect.h:79
int(* SetRenderTarget)(SDL_Renderer *renderer, SDL_Texture *texture)
int w
Definition: SDL_rect.h:80
SDL_bool SDL_RenderTargetSupported(SDL_Renderer *renderer)
Determines whether a window supports the use of render targets.
Definition: SDL_render.c:1824
#define SDL_SetError
SDL_Renderer * renderer
Definition: SDL_sysrender.h:55
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:45
SDL_Rect viewport
int h
Definition: SDL_rect.h:80
static int QueueCmdSetViewport(SDL_Renderer *renderer)
Definition: SDL_render.c:400
#define SDL_UnlockMutex
static int QueueCmdSetClipRect(SDL_Renderer *renderer)
Definition: SDL_render.c:423
SDL_Texture * native
Definition: SDL_sysrender.h:58
SDL_Rect viewport_backup
SDL_bool clipping_enabled_backup
int y
Definition: SDL_rect.h:79
#define SDL_Unsupported()
Definition: SDL_error.h:53
float x
Definition: SDL_rect.h:62
SDL_bool clipping_enabled
float y
Definition: SDL_rect.h:63

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

References SDL_Texture::a, CHECK_TEXTURE_MAGIC, SDL_Texture::modMode, SDL_Texture::native, and SDL_TEXTUREMODULATE_ALPHA.

Referenced by SDL_CreateTextureFromSurface().

1412 {
1413  CHECK_TEXTURE_MAGIC(texture, -1);
1414 
1415  if (alpha < 255) {
1416  texture->modMode |= SDL_TEXTUREMODULATE_ALPHA;
1417  } else {
1418  texture->modMode &= ~SDL_TEXTUREMODULATE_ALPHA;
1419  }
1420  texture->a = alpha;
1421  if (texture->native) {
1422  return SDL_SetTextureAlphaMod(texture->native, alpha);
1423  }
1424  return 0;
1425 }
GLfloat GLfloat GLfloat alpha
int SDL_SetTextureAlphaMod(SDL_Texture *texture, Uint8 alpha)
Set an additional alpha value used in render copy operations.
Definition: SDL_render.c:1411
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:45
SDL_Texture * native
Definition: SDL_sysrender.h:58

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

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

Referenced by SDL_CreateTextureFromSurface().

1440 {
1442 
1443  CHECK_TEXTURE_MAGIC(texture, -1);
1444 
1445  renderer = texture->renderer;
1446  if (!IsSupportedBlendMode(renderer, blendMode)) {
1447  return SDL_Unsupported();
1448  }
1449  texture->blendMode = blendMode;
1450  if (texture->native) {
1451  return SDL_SetTextureBlendMode(texture->native, blendMode);
1452  }
1453  return 0;
1454 }
SDL_BlendMode blendMode
Definition: SDL_sysrender.h:51
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:1439
static SDL_Renderer * renderer
SDL_Renderer * renderer
Definition: SDL_sysrender.h:55
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:45
SDL_Texture * native
Definition: SDL_sysrender.h:58
#define SDL_Unsupported()
Definition: SDL_error.h:53
static SDL_bool IsSupportedBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendMode)
Definition: SDL_render.c:1040

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

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

Referenced by SDL_CreateTextureFromSurface().

1375 {
1376  CHECK_TEXTURE_MAGIC(texture, -1);
1377 
1378  if (r < 255 || g < 255 || b < 255) {
1379  texture->modMode |= SDL_TEXTUREMODULATE_COLOR;
1380  } else {
1381  texture->modMode &= ~SDL_TEXTUREMODULATE_COLOR;
1382  }
1383  texture->r = r;
1384  texture->g = g;
1385  texture->b = b;
1386  if (texture->native) {
1387  return SDL_SetTextureColorMod(texture->native, r, g, b);
1388  }
1389  return 0;
1390 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:45
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:1374
SDL_Texture * native
Definition: SDL_sysrender.h:58
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 1806 of file SDL_render.c.

References SDL_Texture::access, CHECK_TEXTURE_MAGIC, SDL_Texture::native, 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().

1807 {
1808  CHECK_TEXTURE_MAGIC(texture, );
1809 
1810  if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
1811  return;
1812  }
1813  if (texture->yuv) {
1814  SDL_UnlockTextureYUV(texture);
1815  } else if (texture->native) {
1816  SDL_UnlockTextureNative(texture);
1817  } else {
1818  SDL_Renderer *renderer = texture->renderer;
1819  renderer->UnlockTexture(renderer, texture);
1820  }
1821 }
static void SDL_UnlockTextureNative(SDL_Texture *texture)
Definition: SDL_render.c:1785
static SDL_Renderer * renderer
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:59
void(* UnlockTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
SDL_Renderer * renderer
Definition: SDL_sysrender.h:55
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:45
SDL_Texture * native
Definition: SDL_sysrender.h:58
static void SDL_UnlockTextureYUV(SDL_Texture *texture)
Definition: SDL_render.c:1764

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

References CHECK_TEXTURE_MAGIC, FlushRenderCommandsIfTextureNeeded(), SDL_Texture::h, SDL_Rect::h, SDL_Texture::native, 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().

1557 {
1558  SDL_Rect full_rect;
1559 
1560  CHECK_TEXTURE_MAGIC(texture, -1);
1561 
1562  if (!pixels) {
1563  return SDL_InvalidParamError("pixels");
1564  }
1565  if (!pitch) {
1566  return SDL_InvalidParamError("pitch");
1567  }
1568 
1569  if (!rect) {
1570  full_rect.x = 0;
1571  full_rect.y = 0;
1572  full_rect.w = texture->w;
1573  full_rect.h = texture->h;
1574  rect = &full_rect;
1575  }
1576 
1577  if ((rect->w == 0) || (rect->h == 0)) {
1578  return 0; /* nothing to do. */
1579  } else if (texture->yuv) {
1580  return SDL_UpdateTextureYUV(texture, rect, pixels, pitch);
1581  } else if (texture->native) {
1582  return SDL_UpdateTextureNative(texture, rect, pixels, pitch);
1583  } else {
1584  SDL_Renderer *renderer = texture->renderer;
1585  if (FlushRenderCommandsIfTextureNeeded(texture) < 0) {
1586  return -1;
1587  }
1588  return renderer->UpdateTexture(renderer, texture, rect, pixels, pitch);
1589  }
1590 }
static int FlushRenderCommandsIfTextureNeeded(SDL_Texture *texture)
Definition: SDL_render.c:244
static int SDL_UpdateTextureNative(SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
Definition: SDL_render.c:1514
#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)
static SDL_Renderer * renderer
SDL_SW_YUVTexture * yuv
Definition: SDL_sysrender.h:59
int x
Definition: SDL_rect.h:79
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
int w
Definition: SDL_rect.h:80
static int SDL_UpdateTextureYUV(SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
Definition: SDL_render.c:1468
SDL_Renderer * renderer
Definition: SDL_sysrender.h:55
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:45
int h
Definition: SDL_rect.h:80
SDL_Texture * native
Definition: SDL_sysrender.h:58
int y
Definition: SDL_rect.h:79
A rectangle, with the origin at the upper left (integer).
Definition: SDL_rect.h:77

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

References CHECK_TEXTURE_MAGIC, FlushRenderCommandsIfTextureNeeded(), 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.

1648 {
1650  SDL_Rect full_rect;
1651 
1652  CHECK_TEXTURE_MAGIC(texture, -1);
1653 
1654  if (!Yplane) {
1655  return SDL_InvalidParamError("Yplane");
1656  }
1657  if (!Ypitch) {
1658  return SDL_InvalidParamError("Ypitch");
1659  }
1660  if (!Uplane) {
1661  return SDL_InvalidParamError("Uplane");
1662  }
1663  if (!Upitch) {
1664  return SDL_InvalidParamError("Upitch");
1665  }
1666  if (!Vplane) {
1667  return SDL_InvalidParamError("Vplane");
1668  }
1669  if (!Vpitch) {
1670  return SDL_InvalidParamError("Vpitch");
1671  }
1672 
1673  if (texture->format != SDL_PIXELFORMAT_YV12 &&
1674  texture->format != SDL_PIXELFORMAT_IYUV) {
1675  return SDL_SetError("Texture format must by YV12 or IYUV");
1676  }
1677 
1678  if (!rect) {
1679  full_rect.x = 0;
1680  full_rect.y = 0;
1681  full_rect.w = texture->w;
1682  full_rect.h = texture->h;
1683  rect = &full_rect;
1684  }
1685 
1686  if (!rect->w || !rect->h) {
1687  return 0; /* nothing to do. */
1688  }
1689 
1690  if (texture->yuv) {
1691  return SDL_UpdateTextureYUVPlanar(texture, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch);
1692  } else {
1693  SDL_assert(!texture->native);
1694  renderer = texture->renderer;
1695  SDL_assert(renderer->UpdateTextureYUV);
1696  if (renderer->UpdateTextureYUV) {
1697  if (FlushRenderCommandsIfTextureNeeded(texture) < 0) {
1698  return -1;
1699  }
1700  return renderer->UpdateTextureYUV(renderer, texture, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch);
1701  } else {
1702  return SDL_Unsupported();
1703  }
1704  }
1705 }
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:1593
static int FlushRenderCommandsIfTextureNeeded(SDL_Texture *texture)
Definition: SDL_render.c:244
#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:59
int x
Definition: SDL_rect.h:79
int w
Definition: SDL_rect.h:80
#define SDL_assert(condition)
Definition: SDL_assert.h:169
#define SDL_SetError
SDL_Renderer * renderer
Definition: SDL_sysrender.h:55
#define CHECK_TEXTURE_MAGIC(texture, retval)
Definition: SDL_render.c:45
int h
Definition: SDL_rect.h:80
Uint32 format
Definition: SDL_sysrender.h:46
SDL_Texture * native
Definition: SDL_sysrender.h:58
int y
Definition: SDL_rect.h:79
#define SDL_Unsupported()
Definition: SDL_error.h:53
A rectangle, with the origin at the upper left (integer).
Definition: SDL_rect.h:77