1 /+ 2 + Copyright 2022 – 2024 Aya Partridge 3 + Copyright 2018 - 2022 Michael D. Parker 4 + Distributed under the Boost Software License, Version 1.0. 5 + (See accompanying file LICENSE_1_0.txt or copy at 6 + http://www.boost.org/LICENSE_1_0.txt) 7 +/ 8 module sdl.render; 9 10 import bindbc.sdl.config; 11 import bindbc.sdl.codegen; 12 13 import sdl.blendmode: SDL_BlendMode; 14 import sdl.rect; 15 import sdl.stdinc: SDL_bool; 16 import sdl.surface: SDL_Surface; 17 import sdl.video; 18 import sdl.pixels: SDL_Color; 19 20 alias SDL_RendererFlags = uint; 21 enum: SDL_RendererFlags{ 22 SDL_RENDERER_SOFTWARE = 0x00000001, 23 SDL_RENDERER_ACCELERATED = 0x00000002, 24 SDL_RENDERER_PRESENTVSYNC = 0x00000004, 25 SDL_RENDERER_TARGETTEXTURE = 0x00000008, 26 } 27 28 struct SDL_RendererInfo{ 29 const(char)* name; 30 SDL_RendererFlags flags; 31 uint num_texture_formats; 32 uint[16] texture_formats; 33 int max_texture_width; 34 int max_texture_height; 35 } 36 37 static if(sdlSupport >= SDLSupport.v2_0_18){ 38 struct SDL_Vertex{ 39 SDL_FPoint position; 40 SDL_Color color; 41 alias colour = color; 42 SDL_FPoint tex_coord; 43 } 44 } 45 46 static if(sdlSupport >= SDLSupport.v2_0_12){ 47 alias SDL_ScaleMode = int; 48 enum: SDL_ScaleMode{ 49 SDL_ScaleModeNearest, 50 SDL_ScaleModeLinear, 51 SDL_ScaleModeBest, 52 } 53 } 54 55 alias SDL_TextureAccess = int; 56 enum: SDL_TextureAccess{ 57 SDL_TEXTUREACCESS_STATIC, 58 SDL_TEXTUREACCESS_STREAMING, 59 SDL_TEXTUREACCESS_TARGET, 60 } 61 62 alias SDL_TextureModulate = int; 63 enum: SDL_TextureModulate{ 64 SDL_TEXTUREMODULATE_NONE = 0x00000000, 65 SDL_TEXTUREMODULATE_COLOR = 0x00000001, 66 SDL_TEXTUREMODULATE_ALPHA = 0x00000002, 67 68 SDL_TEXTUREMODULATE_COLOUR = SDL_TEXTUREMODULATE_COLOR, 69 } 70 71 alias SDL_RendererFlip = int; 72 enum: SDL_RendererFlip{ 73 SDL_FLIP_NONE = 0x00000000, 74 SDL_FLIP_HORIZONTAL = 0x00000001, 75 SDL_FLIP_VERTICAL = 0x00000002, 76 } 77 78 struct SDL_Renderer; 79 80 struct SDL_Texture; 81 82 mixin(joinFnBinds((){ 83 FnBind[] ret = [ 84 {q{int}, q{SDL_GetNumRenderDrivers}, q{}}, 85 {q{int}, q{SDL_GetRenderDriverInfo}, q{int index, SDL_RendererInfo* info}}, 86 {q{int}, q{SDL_CreateWindowAndRenderer}, q{int width, int height, uint windowFlags, SDL_Window** window, SDL_Renderer** renderer}}, 87 {q{SDL_Renderer*}, q{SDL_CreateRenderer}, q{SDL_Window* window, int index, SDL_RendererFlags flags}}, 88 {q{SDL_Renderer*}, q{SDL_CreateSoftwareRenderer}, q{SDL_Surface* surface}}, 89 {q{SDL_Renderer*}, q{SDL_GetRenderer}, q{SDL_Window* window}}, 90 {q{int}, q{SDL_GetRendererInfo}, q{SDL_Renderer* renderer, SDL_RendererInfo* info}}, 91 {q{int}, q{SDL_GetRendererOutputSize}, q{SDL_Renderer* renderer, int* w, int* h}}, 92 {q{SDL_Texture*}, q{SDL_CreateTexture}, q{SDL_Renderer* renderer, uint format, SDL_TextureAccess access, int w, int h}}, 93 {q{SDL_Texture*}, q{SDL_CreateTextureFromSurface}, q{SDL_Renderer* renderer, SDL_Surface* surface}}, 94 {q{int}, q{SDL_QueryTexture}, q{SDL_Texture* texture, uint* format, SDL_TextureAccess* access, int* w, int* h}}, 95 {q{int}, q{SDL_SetTextureColorMod}, q{SDL_Texture* texture, ubyte r, ubyte g, ubyte b}}, 96 {q{int}, q{SDL_GetTextureColorMod}, q{SDL_Texture* texture, ubyte* r, ubyte* g, ubyte* b}}, 97 {q{int}, q{SDL_SetTextureAlphaMod}, q{SDL_Texture* texture, ubyte alpha}}, 98 {q{int}, q{SDL_GetTextureAlphaMod}, q{SDL_Texture* texture, ubyte* alpha}}, 99 {q{int}, q{SDL_SetTextureBlendMode}, q{SDL_Texture* texture, SDL_BlendMode blendMode}}, 100 {q{int}, q{SDL_GetTextureBlendMode}, q{SDL_Texture* texture, SDL_BlendMode* blendMode}}, 101 {q{int}, q{SDL_UpdateTexture}, q{SDL_Texture* texture, const(SDL_Rect)* rect, const(void)* pixels, int pitch}}, 102 {q{int}, q{SDL_LockTexture}, q{SDL_Texture* texture, const(SDL_Rect)* rect, void** pixels, int* pitch}}, 103 {q{void}, q{SDL_UnlockTexture}, q{SDL_Texture* texture}}, 104 {q{SDL_bool}, q{SDL_RenderTargetSupported}, q{SDL_Renderer* renderer}}, 105 {q{int}, q{SDL_SetRenderTarget}, q{SDL_Renderer* renderer, SDL_Texture* texture}}, 106 {q{SDL_Texture*}, q{SDL_GetRenderTarget}, q{SDL_Renderer* renderer}}, 107 {q{int}, q{SDL_RenderSetClipRect}, q{SDL_Renderer* renderer, const(SDL_Rect)* rect}}, 108 {q{void}, q{SDL_RenderGetClipRect}, q{SDL_Renderer* renderer, SDL_Rect* rect}}, 109 {q{int}, q{SDL_RenderSetLogicalSize}, q{SDL_Renderer* renderer, int w, int h}}, 110 {q{void}, q{SDL_RenderGetLogicalSize}, q{SDL_Renderer* renderer, int* w, int* h}}, 111 {q{int}, q{SDL_RenderSetViewport}, q{SDL_Renderer* renderer, const(SDL_Rect)* rect}}, 112 {q{void}, q{SDL_RenderGetViewport}, q{SDL_Renderer* renderer, SDL_Rect* rect}}, 113 {q{int}, q{SDL_RenderSetScale}, q{SDL_Renderer* renderer, float scaleX, float scaleY}}, 114 {q{int}, q{SDL_RenderGetScale}, q{SDL_Renderer* renderer, float* scaleX, float* scaleY}}, 115 {q{int}, q{SDL_SetRenderDrawColor}, q{SDL_Renderer* renderer, ubyte r, ubyte g, ubyte b, ubyte a}}, 116 {q{int}, q{SDL_GetRenderDrawColor}, q{SDL_Renderer* renderer, ubyte* r, ubyte* g, ubyte* b, ubyte* a}}, 117 {q{int}, q{SDL_SetRenderDrawBlendMode}, q{SDL_Renderer* renderer, SDL_BlendMode blendMode}}, 118 {q{int}, q{SDL_GetRenderDrawBlendMode}, q{SDL_Renderer* renderer, SDL_BlendMode* blendMode}}, 119 {q{int}, q{SDL_RenderClear}, q{SDL_Renderer* renderer}}, 120 {q{int}, q{SDL_RenderDrawPoint}, q{SDL_Renderer* renderer, int x, int y}}, 121 {q{int}, q{SDL_RenderDrawPoints}, q{SDL_Renderer* renderer, const(SDL_Point)* points, int count}}, 122 {q{int}, q{SDL_RenderDrawLine}, q{SDL_Renderer* renderer, int x1, int y1, int x2, int y2}}, 123 {q{int}, q{SDL_RenderDrawLines}, q{SDL_Renderer* renderer, const(SDL_Point)* points, int count}}, 124 {q{int}, q{SDL_RenderDrawRect}, q{SDL_Renderer* renderer, const(SDL_Rect)* rect}}, 125 {q{int}, q{SDL_RenderDrawRects}, q{SDL_Renderer* renderer, const(SDL_Rect)* rects, int count}}, 126 {q{int}, q{SDL_RenderFillRect}, q{SDL_Renderer* renderer, const(SDL_Rect)* rect}}, 127 {q{int}, q{SDL_RenderFillRects}, q{SDL_Renderer* renderer, const(SDL_Rect)* rects, int count}}, 128 {q{int}, q{SDL_RenderCopy}, q{SDL_Renderer* renderer, SDL_Texture* texture, const(SDL_Rect)* srcRect, const(SDL_Rect)* dstRect}}, 129 {q{int}, q{SDL_RenderCopyEx}, q{SDL_Renderer* renderer, SDL_Texture* texture, const(SDL_Rect)* srcRect, const(SDL_Rect)* dstRect, const(double) angle, const(SDL_Point)* centre, const(SDL_RendererFlip) flip}}, 130 {q{int}, q{SDL_RenderReadPixels}, q{SDL_Renderer* renderer, const(SDL_Rect)* rect, uint, void*, int}}, 131 {q{void}, q{SDL_RenderPresent}, q{SDL_Renderer* renderer}}, 132 {q{void}, q{SDL_DestroyTexture}, q{SDL_Texture* texture}}, 133 {q{void}, q{SDL_DestroyRenderer}, q{SDL_Renderer* renderer}}, 134 {q{int}, q{SDL_GL_BindTexture}, q{SDL_Texture* texture, float* texw, float* texh}}, 135 {q{int}, q{SDL_GL_UnbindTexture}, q{SDL_Texture* texture}}, 136 ]; 137 if(sdlSupport >= SDLSupport.v2_0_1){ 138 FnBind[] add = [ 139 {q{int}, q{SDL_UpdateYUVTexture}, q{SDL_Texture* texture ,const(SDL_Rect)* rect, const(ubyte)* yPlane, int yPitch, const(ubyte)* uPlane, int uPitch, const(ubyte)* vPlane, int vPitch}}, 140 ]; 141 ret ~= add; 142 } 143 if(sdlSupport >= SDLSupport.v2_0_4){ 144 FnBind[] add = [ 145 {q{SDL_bool}, q{SDL_RenderIsClipEnabled}, q{SDL_Renderer* renderer}}, 146 ]; 147 ret ~= add; 148 } 149 if(sdlSupport >= SDLSupport.v2_0_5){ 150 FnBind[] add = [ 151 {q{SDL_bool}, q{SDL_RenderGetIntegerScale}, q{SDL_Renderer* renderer}}, 152 {q{int}, q{SDL_RenderSetIntegerScale}, q{SDL_Renderer* renderer, SDL_bool}}, 153 ]; 154 ret ~= add; 155 } 156 if(sdlSupport >= SDLSupport.v2_0_8){ 157 FnBind[] add = [ 158 {q{void*}, q{SDL_RenderGetMetalLayer}, q{SDL_Renderer* renderer}}, 159 {q{void*}, q{SDL_RenderGetMetalCommandEncoder}, q{SDL_Renderer* renderer}}, 160 ]; 161 ret ~= add; 162 } 163 if(sdlSupport >= SDLSupport.v2_0_10){ 164 FnBind[] add = [ 165 {q{int}, q{SDL_RenderDrawPointF}, q{SDL_Renderer* renderer, float x, float y}}, 166 {q{int}, q{SDL_RenderDrawPointsF}, q{SDL_Renderer* renderer, const(SDL_FPoint)* points, int count}}, 167 {q{int}, q{SDL_RenderDrawLineF}, q{SDL_Renderer* renderer, float x1, float y1, float x2, float y2}}, 168 {q{int}, q{SDL_RenderDrawLinesF}, q{SDL_Renderer* renderer, const(SDL_FPoint)* points, int count}}, 169 {q{int}, q{SDL_RenderDrawRectF}, q{SDL_Renderer* renderer, const(SDL_FRect)* rect}}, 170 {q{int}, q{SDL_RenderDrawRectsF}, q{SDL_Renderer* renderer, const(SDL_FRect)* rects, int count}}, 171 {q{int}, q{SDL_RenderFillRectF}, q{SDL_Renderer* renderer, const(SDL_FRect)* rect}}, 172 {q{int}, q{SDL_RenderFillRectsF}, q{SDL_Renderer* renderer, const(SDL_FRect)* rects, int count}}, 173 {q{int}, q{SDL_RenderCopyF}, q{SDL_Renderer* renderer, SDL_Texture* texture, const(SDL_Rect)* srcRect, const(SDL_FRect)* dstRect}}, 174 {q{int}, q{SDL_RenderCopyExF}, q{SDL_Renderer* renderer, SDL_Texture* texture, const(SDL_Rect)* srcRect, const(SDL_FRect)* dstRect, const(double) angle, const(SDL_FPoint)* centre, const(SDL_RendererFlip) flip}}, 175 {q{int}, q{SDL_RenderFlush}, q{SDL_Renderer* renderer}}, 176 ]; 177 ret ~= add; 178 } 179 if(sdlSupport >= SDLSupport.v2_0_12){ 180 FnBind[] add = [ 181 {q{int}, q{SDL_SetTextureScaleMode}, q{SDL_Texture* texture, SDL_ScaleMode scaleMode}}, 182 {q{int}, q{SDL_GetTextureScaleMode}, q{SDL_Texture* texture, SDL_ScaleMode* scaleMode}}, 183 {q{int}, q{SDL_LockTextureToSurface}, q{SDL_Texture* texture, const(SDL_Rect)* rect, SDL_Surface** surface}}, 184 ]; 185 ret ~= add; 186 } 187 if(sdlSupport >= SDLSupport.v2_0_16){ 188 FnBind[] add = [ 189 {q{int}, q{SDL_UpdateNVTexture}, q{SDL_Texture* texture, const(SDL_Rect)* rect, const(ubyte)* yPlane, int yPitch, const(ubyte)* uvPlane, int uvPitch}}, 190 ]; 191 ret ~= add; 192 } 193 if(sdlSupport >= SDLSupport.v2_0_18){ 194 { 195 FnBind[] add = [ 196 {q{int}, q{SDL_SetTextureUserData}, q{SDL_Texture* texture, void* userdata}}, 197 {q{void*}, q{SDL_GetTextureUserData}, q{SDL_Texture* texture}}, 198 {q{void}, q{SDL_RenderWindowToLogical}, q{SDL_Renderer* renderer, int windowX, int windowY, float* logicalX, float* logicalY}}, 199 {q{void}, q{SDL_RenderLogicalToWindow}, q{SDL_Renderer* renderer, float logicalX, float logicalY, int* windowX, int* windowY}}, 200 {q{int}, q{SDL_RenderGeometry}, q{SDL_Renderer* renderer, SDL_Texture* texture, const(SDL_Vertex)* vertices, int numVertices, const(int)* indices, int numIndices}}, 201 {q{int}, q{SDL_RenderSetVSync}, q{SDL_Renderer* renderer, int vsync}}, 202 ]; 203 ret ~= add; 204 } 205 if(sdlSupport >= SDLSupport.v2_0_20){ 206 FnBind[] add = [ 207 {q{int}, q{SDL_RenderGeometryRaw}, q{SDL_Renderer* renderer, SDL_Texture* texture, const(float)* xy, int xyStride, const(SDL_Color)* colour, int colourStride, const(float)* uv, int uvStride, int numVertices, const(void)* indices, int numIndices, int sizeIndices}}, 208 ]; 209 ret ~= add; 210 }else{ 211 FnBind[] add = [ 212 {q{int}, q{SDL_RenderGeometryRaw}, q{SDL_Renderer* renderer, SDL_Texture* texture, const(float)* xy, int xyStride, const(int)* colour, int colourStride, const(float)* uv, int uvStride, int numVertices, const(void)* indices, int numIndices, int sizeIndices}}, 213 ]; 214 ret ~= add; 215 } 216 } 217 if(sdlSupport >= SDLSupport.v2_0_22){ 218 FnBind[] add = [ 219 {q{SDL_Window*}, q{SDL_RenderGetWindow}, q{SDL_Renderer* renderer}}, 220 ]; 221 ret ~= add; 222 } 223 return ret; 224 }())); 225 226 alias SDL_SetTextureColourMod = SDL_SetTextureColorMod; 227 alias SDL_GetTextureColourMod = SDL_GetTextureColorMod; 228 alias SDL_SetRenderDrawColour = SDL_SetRenderDrawColor; 229 alias SDL_GetRenderDrawColour = SDL_GetRenderDrawColor;