1 2 // Copyright Michael D. Parker 2018. 3 // Distributed under the Boost Software License, Version 1.0. 4 // (See accompanying file LICENSE_1_0.txt or copy at 5 // http://www.boost.org/LICENSE_1_0.txt) 6 7 module bindbc.sdl.bind.sdlrender; 8 9 import bindbc.sdl.config; 10 import bindbc.sdl.bind.sdlblendmode : SDL_BlendMode; 11 import bindbc.sdl.bind.sdlrect; 12 import bindbc.sdl.bind.sdlstdinc : SDL_bool; 13 import bindbc.sdl.bind.sdlsurface : SDL_Surface; 14 import bindbc.sdl.bind.sdlvideo : SDL_Window; 15 16 enum SDL_RendererFlags : uint { 17 SDL_RENDERER_SOFTWARE = 0x00000001, 18 SDL_RENDERER_ACCELERATED = 0x00000002, 19 SDL_RENDERER_PRESENTVSYNC = 0x00000004, 20 SDL_RENDERER_TARGETTEXTURE = 0x00000008, 21 } 22 23 mixin(expandEnum!SDL_RendererFlags); 24 25 struct SDL_RendererInfo { 26 const(char)* name; 27 SDL_RendererFlags flags; 28 uint num_texture_formats; 29 uint[16] texture_formats; 30 int max_texture_width; 31 int max_texture_height; 32 } 33 34 enum SDL_TextureAccess { 35 SDL_TEXTUREACCESS_STATIC, 36 SDL_TEXTUREACCESS_STREAMING, 37 SDL_TEXTUREACCESS_TARGET, 38 } 39 mixin(expandEnum!SDL_TextureAccess); 40 41 enum SDL_TextureModulate { 42 SDL_TEXTUREMODULATE_NONE = 0x00000000, 43 SDL_TEXTUREMODULATE_COLOR = 0x00000001, 44 SDL_TEXTUREMODULATE_ALPHA = 0x00000002 45 } 46 mixin(expandEnum!SDL_TextureModulate); 47 48 enum SDL_RendererFlip { 49 SDL_FLIP_NONE = 0x00000000, 50 SDL_FLIP_HORIZONTAL = 0x00000001, 51 SDL_FLIP_VERTICAL = 0x00000002, 52 } 53 mixin(expandEnum!SDL_RendererFlip); 54 55 struct SDL_Renderer; 56 struct SDL_Texture; 57 58 version(BindSDL_Static) { 59 extern(C) @nogc nothrow { 60 int SDL_GetNumRenderDrivers(); 61 int SDL_GetRenderDriverInfo(int,SDL_RendererInfo*); 62 int SDL_CreateWindowAndRenderer(int,int,uint,SDL_Window**,SDL_Renderer**); 63 SDL_Renderer* SDL_CreateRenderer(SDL_Window*,int,SDL_RendererFlags); 64 SDL_Renderer* SDL_CreateSoftwareRenderer(SDL_Surface*); 65 SDL_Renderer* SDL_GetRenderer(SDL_Window*); 66 int SDL_GetRendererInfo(SDL_Renderer*,SDL_RendererInfo*); 67 int SDL_GetRendererOutputSize(SDL_Renderer*,int*,int*); 68 SDL_Texture* SDL_CreateTexture(SDL_Renderer*,uint,SDL_TextureAccess,int,int); 69 SDL_Texture* SDL_CreateTextureFromSurface(SDL_Renderer*,SDL_Surface*); 70 int SDL_QueryTexture(SDL_Texture*,uint*,int*,int*,int*); 71 int SDL_SetTextureColorMod(SDL_Texture*,ubyte,ubyte,ubyte); 72 int SDL_GetTextureColorMod(SDL_Texture*,ubyte*,ubyte*,ubyte*); 73 int SDL_SetTextureAlphaMod(SDL_Texture*,ubyte); 74 int SDL_GetTextureAlphaMod(SDL_Texture*,ubyte*); 75 int SDL_SetTextureBlendMode(SDL_Texture*,SDL_BlendMode); 76 int SDL_GetTextureBlendMode(SDL_Texture*,SDL_BlendMode*); 77 int SDL_UpdateTexture(SDL_Texture*,const(SDL_Rect)*,const(void)*,int); 78 int SDL_LockTexture(SDL_Texture*,const(SDL_Rect)*,void**,int*); 79 void SDL_UnlockTexture(SDL_Texture*); 80 SDL_bool SDL_RenderTargetSupported(SDL_Renderer*); 81 int SDL_SetRenderTarget(SDL_Renderer*,SDL_Texture*); 82 SDL_Texture* SDL_GetRenderTarget(SDL_Renderer*); 83 int SDL_RenderSetClipRect(SDL_Renderer*,const(SDL_Rect)*); 84 void SDL_RenderGetClipRect(SDL_Renderer* renderer,SDL_Rect*); 85 int SDL_RenderSetLogicalSize(SDL_Renderer*,int,int); 86 void SDL_RenderGetLogicalSize(SDL_Renderer*,int*,int*); 87 int SDL_RenderSetViewport(SDL_Renderer*,const(SDL_Rect)*); 88 void SDL_RenderGetViewport(SDL_Renderer*,SDL_Rect*); 89 int SDL_RenderSetScale(SDL_Renderer*,float,float); 90 int SDL_RenderGetScale(SDL_Renderer*,float*,float*); 91 int SDL_SetRenderDrawColor(SDL_Renderer*,ubyte,ubyte,ubyte,ubyte); 92 int SDL_GetRenderDrawColor(SDL_Renderer*,ubyte*,ubyte*,ubyte*,ubyte*); 93 int SDL_SetRenderDrawBlendMode(SDL_Renderer*,SDL_BlendMode); 94 int SDL_GetRenderDrawBlendMode(SDL_Renderer*,SDL_BlendMode*); 95 int SDL_RenderClear(SDL_Renderer*); 96 int SDL_RenderDrawPoint(SDL_Renderer*,int,int); 97 int SDL_RenderDrawPoints(SDL_Renderer*,const(SDL_Point)*,int); 98 int SDL_RenderDrawLine(SDL_Renderer*,int,int,int,int); 99 int SDL_RenderDrawLines(SDL_Renderer*,const(SDL_Point)*,int); 100 int SDL_RenderDrawRect(SDL_Renderer*,const(SDL_Rect)*); 101 int SDL_RenderDrawRects(SDL_Renderer*,const(SDL_Rect)*,int); 102 int SDL_RenderFillRect(SDL_Renderer*,const(SDL_Rect)*); 103 int SDL_RenderFillRects(SDL_Renderer*,const(SDL_Rect)*,int); 104 int SDL_RenderCopy(SDL_Renderer*,SDL_Texture*,const(SDL_Rect)*,const(SDL_Rect*)); 105 int SDL_RenderCopyEx(SDL_Renderer*,SDL_Texture*,const(SDL_Rect)*,const(SDL_Rect)*,const(double),const(SDL_Point)*,const(SDL_RendererFlip)); 106 int SDL_RenderReadPixels(SDL_Renderer*,const(SDL_Rect)*,uint,void*,int); 107 void SDL_RenderPresent(SDL_Renderer*); 108 void SDL_DestroyTexture(SDL_Texture*); 109 void SDL_DestroyRenderer(SDL_Renderer*); 110 int SDL_GL_BindTexture(SDL_Texture*,float*,float*); 111 int SDL_GL_UnbindTexture(SDL_Texture*); 112 113 static if(sdlSupport >= SDLSupport.sdl201) { 114 int SDL_UpdateYUVTexture(SDL_Texture*,const(SDL_Rect)*,const(ubyte)*,int,const(ubyte)*,int,const(ubyte)*,int); 115 } 116 static if(sdlSupport >= SDLSupport.sdl204) { 117 SDL_bool SDL_RenderIsClipEnabled(SDL_Renderer*); 118 } 119 static if(sdlSupport >= SDLSupport.sdl205) { 120 SDL_bool SDL_RenderGetIntegerScale(SDL_Renderer*); 121 int SDL_RenderSetIntegerScale(SDL_Renderer*,SDL_bool); 122 } 123 static if(sdlSupport >= SDLSupport.sdl208) { 124 void* SDL_RenderGetMetalLayer(SDL_Renderer*); 125 void* SDL_RenderGetMetalCommandEncoder(SDL_Renderer*); 126 } 127 static if(sdlSupport >= SDLSupport.sdl2010) { 128 int SDL_RenderDrawPointF(SDL_Renderer*,float,float); 129 int SDL_RenderDrawPointsF(SDL_Renderer*,const(SDL_FPoint)*,int); 130 int SDL_RenderDrawLineF(SDL_Renderer*,float,float,float,float); 131 int SDL_RenderDrawLinesF(SDL_Renderer*,const(SDL_FPoint)*,int); 132 int SDL_RenderDrawRectF(SDL_Renderer*,const(SDL_FRect)*); 133 int SDL_RenderDrawRectsF(SDL_Renderer*,const(SDL_FRect)*,int); 134 int SDL_RenderFillRectF(SDL_Renderer*,const(SDL_FRect)*); 135 int SDL_RenderFillRectsF(SDL_Renderer*,const(SDL_FRect)*,int); 136 int SDL_RenderCopyF(SDL_Renderer*,SDL_Texture*,const(SDL_FRect)*,const(SDL_FRect)*); 137 int SDL_RenderCopyExF(SDL_Renderer*,SDL_Texture*,const(SDL_FRect)*,const(SDL_FRect)*,const(double),const(SDL_FPoint)*,const(SDL_RendererFlip)); 138 int SDL_RenderFlush(SDL_Renderer*); 139 } 140 } 141 } 142 else { 143 extern(C) @nogc nothrow { 144 alias pSDL_GetNumRenderDrivers = int function(); 145 alias pSDL_GetRenderDriverInfo = int function(int,SDL_RendererInfo*); 146 alias pSDL_CreateWindowAndRenderer = int function(int,int,uint,SDL_Window**,SDL_Renderer**); 147 alias pSDL_CreateRenderer = SDL_Renderer* function(SDL_Window*,int,SDL_RendererFlags); 148 alias pSDL_CreateSoftwareRenderer = SDL_Renderer* function(SDL_Surface*); 149 alias pSDL_GetRenderer = SDL_Renderer* function(SDL_Window*); 150 alias pSDL_GetRendererInfo = int function(SDL_Renderer*,SDL_RendererInfo*); 151 alias pSDL_GetRendererOutputSize = int function(SDL_Renderer*,int*,int*); 152 alias pSDL_CreateTexture = SDL_Texture* function(SDL_Renderer*,uint,SDL_TextureAccess,int,int); 153 alias pSDL_CreateTextureFromSurface = SDL_Texture* function(SDL_Renderer*,SDL_Surface*); 154 alias pSDL_QueryTexture = int function(SDL_Texture*,uint*,int*,int*,int*); 155 alias pSDL_SetTextureColorMod = int function(SDL_Texture*,ubyte,ubyte,ubyte); 156 alias pSDL_GetTextureColorMod = int function(SDL_Texture*,ubyte*,ubyte*,ubyte*); 157 alias pSDL_SetTextureAlphaMod = int function(SDL_Texture*,ubyte); 158 alias pSDL_GetTextureAlphaMod = int function(SDL_Texture*,ubyte*); 159 alias pSDL_SetTextureBlendMode = int function(SDL_Texture*,SDL_BlendMode); 160 alias pSDL_GetTextureBlendMode = int function(SDL_Texture*,SDL_BlendMode*); 161 alias pSDL_UpdateTexture = int function(SDL_Texture*,const(SDL_Rect)*,const(void)*,int); 162 alias pSDL_LockTexture = int function(SDL_Texture*,const(SDL_Rect)*,void**,int*); 163 alias pSDL_UnlockTexture = void function(SDL_Texture*); 164 alias pSDL_RenderTargetSupported = SDL_bool function(SDL_Renderer*); 165 alias pSDL_SetRenderTarget = int function(SDL_Renderer*,SDL_Texture*); 166 alias pSDL_GetRenderTarget = SDL_Texture* function(SDL_Renderer*); 167 alias pSDL_RenderSetClipRect = int function(SDL_Renderer*,const(SDL_Rect)*); 168 alias pSDL_RenderGetClipRect = void function(SDL_Renderer* renderer,SDL_Rect*); 169 alias pSDL_RenderSetLogicalSize = int function(SDL_Renderer*,int,int); 170 alias pSDL_RenderGetLogicalSize = void function(SDL_Renderer*,int*,int*); 171 alias pSDL_RenderSetViewport = int function(SDL_Renderer*,const(SDL_Rect)*); 172 alias pSDL_RenderGetViewport = void function(SDL_Renderer*,SDL_Rect*); 173 alias pSDL_RenderSetScale = int function(SDL_Renderer*,float,float); 174 alias pSDL_RenderGetScale = int function(SDL_Renderer*,float*,float*); 175 alias pSDL_SetRenderDrawColor = int function(SDL_Renderer*,ubyte,ubyte,ubyte,ubyte); 176 alias pSDL_GetRenderDrawColor = int function(SDL_Renderer*,ubyte*,ubyte*,ubyte*,ubyte*); 177 alias pSDL_SetRenderDrawBlendMode = int function(SDL_Renderer*,SDL_BlendMode); 178 alias pSDL_GetRenderDrawBlendMode = int function(SDL_Renderer*,SDL_BlendMode*); 179 alias pSDL_RenderClear = int function(SDL_Renderer*); 180 alias pSDL_RenderDrawPoint = int function(SDL_Renderer*,int,int); 181 alias pSDL_RenderDrawPoints = int function(SDL_Renderer*,const(SDL_Point)*,int); 182 alias pSDL_RenderDrawLine = int function(SDL_Renderer*,int,int,int,int); 183 alias pSDL_RenderDrawLines = int function(SDL_Renderer*,const(SDL_Point)*,int); 184 alias pSDL_RenderDrawRect = int function(SDL_Renderer*,const(SDL_Rect)*); 185 alias pSDL_RenderDrawRects = int function(SDL_Renderer*,const(SDL_Rect)*,int); 186 alias pSDL_RenderFillRect = int function(SDL_Renderer*,const(SDL_Rect)*); 187 alias pSDL_RenderFillRects = int function(SDL_Renderer*,const(SDL_Rect)*,int); 188 alias pSDL_RenderCopy = int function(SDL_Renderer*,SDL_Texture*,const(SDL_Rect)*,const(SDL_Rect*)); 189 alias pSDL_RenderCopyEx = int function(SDL_Renderer*,SDL_Texture*,const(SDL_Rect)*,const(SDL_Rect)*,const(double),const(SDL_Point)*,const(SDL_RendererFlip)); 190 alias pSDL_RenderReadPixels = int function(SDL_Renderer*,const(SDL_Rect)*,uint,void*,int); 191 alias pSDL_RenderPresent = void function(SDL_Renderer*); 192 alias pSDL_DestroyTexture = void function(SDL_Texture*); 193 alias pSDL_DestroyRenderer = void function(SDL_Renderer*); 194 alias pSDL_GL_BindTexture = int function(SDL_Texture*,float*,float*); 195 alias pSDL_GL_UnbindTexture = int function(SDL_Texture*); 196 } 197 198 __gshared { 199 pSDL_GetNumRenderDrivers SDL_GetNumRenderDrivers; 200 pSDL_GetRenderDriverInfo SDL_GetRenderDriverInfo; 201 pSDL_CreateWindowAndRenderer SDL_CreateWindowAndRenderer; 202 pSDL_CreateRenderer SDL_CreateRenderer; 203 pSDL_CreateSoftwareRenderer SDL_CreateSoftwareRenderer; 204 pSDL_GetRenderer SDL_GetRenderer; 205 pSDL_GetRendererInfo SDL_GetRendererInfo; 206 pSDL_GetRendererOutputSize SDL_GetRendererOutputSize; 207 pSDL_CreateTexture SDL_CreateTexture; 208 pSDL_CreateTextureFromSurface SDL_CreateTextureFromSurface; 209 pSDL_QueryTexture SDL_QueryTexture; 210 pSDL_SetTextureColorMod SDL_SetTextureColorMod; 211 pSDL_GetTextureColorMod SDL_GetTextureColorMod; 212 pSDL_SetTextureAlphaMod SDL_SetTextureAlphaMod; 213 pSDL_GetTextureAlphaMod SDL_GetTextureAlphaMod; 214 pSDL_SetTextureBlendMode SDL_SetTextureBlendMode; 215 pSDL_GetTextureBlendMode SDL_GetTextureBlendMode; 216 pSDL_UpdateTexture SDL_UpdateTexture; 217 pSDL_LockTexture SDL_LockTexture; 218 pSDL_UnlockTexture SDL_UnlockTexture; 219 pSDL_RenderTargetSupported SDL_RenderTargetSupported; 220 pSDL_SetRenderTarget SDL_SetRenderTarget; 221 pSDL_GetRenderTarget SDL_GetRenderTarget; 222 pSDL_RenderSetClipRect SDL_RenderSetClipRect; 223 pSDL_RenderGetClipRect SDL_RenderGetClipRect; 224 pSDL_RenderSetLogicalSize SDL_RenderSetLogicalSize; 225 pSDL_RenderGetLogicalSize SDL_RenderGetLogicalSize; 226 pSDL_RenderSetViewport SDL_RenderSetViewport; 227 pSDL_RenderGetViewport SDL_RenderGetViewport; 228 pSDL_RenderSetScale SDL_RenderSetScale; 229 pSDL_RenderGetScale SDL_RenderGetScale; 230 pSDL_SetRenderDrawColor SDL_SetRenderDrawColor; 231 pSDL_GetRenderDrawColor SDL_GetRenderDrawColor; 232 pSDL_SetRenderDrawBlendMode SDL_SetRenderDrawBlendMode; 233 pSDL_GetRenderDrawBlendMode SDL_GetRenderDrawBlendMode; 234 pSDL_RenderClear SDL_RenderClear; 235 pSDL_RenderDrawPoint SDL_RenderDrawPoint; 236 pSDL_RenderDrawPoints SDL_RenderDrawPoints; 237 pSDL_RenderDrawLine SDL_RenderDrawLine; 238 pSDL_RenderDrawLines SDL_RenderDrawLines; 239 pSDL_RenderDrawRect SDL_RenderDrawRect; 240 pSDL_RenderDrawRects SDL_RenderDrawRects; 241 pSDL_RenderFillRect SDL_RenderFillRect; 242 pSDL_RenderFillRects SDL_RenderFillRects; 243 pSDL_RenderCopy SDL_RenderCopy; 244 pSDL_RenderCopyEx SDL_RenderCopyEx; 245 pSDL_RenderReadPixels SDL_RenderReadPixels; 246 pSDL_RenderPresent SDL_RenderPresent; 247 pSDL_DestroyTexture SDL_DestroyTexture; 248 pSDL_DestroyRenderer SDL_DestroyRenderer; 249 pSDL_GL_BindTexture SDL_GL_BindTexture; 250 pSDL_GL_UnbindTexture SDL_GL_UnbindTexture; 251 } 252 static if(sdlSupport >= SDLSupport.sdl201) { 253 extern(C) @nogc nothrow { 254 alias pSDL_UpdateYUVTexture = int function(SDL_Texture*,const(SDL_Rect)*,const(ubyte)*,int,const(ubyte)*,int,const(ubyte)*,int); 255 } 256 __gshared { 257 pSDL_UpdateYUVTexture SDL_UpdateYUVTexture; 258 } 259 } 260 static if(sdlSupport >= SDLSupport.sdl204) { 261 extern(C) @nogc nothrow { 262 alias pSDL_RenderIsClipEnabled = SDL_bool function(SDL_Renderer*); 263 } 264 __gshared { 265 pSDL_RenderIsClipEnabled SDL_RenderIsClipEnabled; 266 } 267 } 268 static if(sdlSupport >= SDLSupport.sdl205) { 269 extern(C) @nogc nothrow { 270 alias pSDL_RenderGetIntegerScale = SDL_bool function(SDL_Renderer*); 271 alias pSDL_RenderSetIntegerScale = int function(SDL_Renderer*,SDL_bool); 272 } 273 __gshared { 274 pSDL_RenderGetIntegerScale SDL_RenderGetIntegerScale; 275 pSDL_RenderSetIntegerScale SDL_RenderSetIntegerScale; 276 } 277 } 278 static if(sdlSupport >= SDLSupport.sdl208) { 279 extern(C) @nogc nothrow { 280 alias pSDL_RenderGetMetalLayer = void* function(SDL_Renderer*); 281 alias pSDL_RenderGetMetalCommandEncoder = void* function(SDL_Renderer*); 282 } 283 __gshared { 284 pSDL_RenderGetMetalLayer SDL_RenderGetMetalLayer; 285 pSDL_RenderGetMetalCommandEncoder SDL_RenderGetMetalCommandEncoder; 286 } 287 } 288 static if(sdlSupport >= SDLSupport.sdl2010) { 289 extern(C) @nogc nothrow { 290 alias pSDL_RenderDrawPointF = int function(SDL_Renderer*,float,float); 291 alias pSDL_RenderDrawPointsF = int function(SDL_Renderer*,const(SDL_FPoint)*,int); 292 alias pSDL_RenderDrawLineF = int function(SDL_Renderer*,float,float,float,float); 293 alias pSDL_RenderDrawLinesF = int function(SDL_Renderer*,const(SDL_FPoint)*,int); 294 alias pSDL_RenderDrawRectF = int function(SDL_Renderer*,const(SDL_FRect)*); 295 alias pSDL_RenderDrawRectsF = int function(SDL_Renderer*,const(SDL_FRect)*,int); 296 alias pSDL_RenderFillRectF = int function(SDL_Renderer*,const(SDL_FRect)*); 297 alias pSDL_RenderFillRectsF = int function(SDL_Renderer*,const(SDL_FRect)*,int); 298 alias pSDL_RenderCopyF = int function(SDL_Renderer*,SDL_Texture*,const(SDL_FRect)*,const(SDL_FRect)*); 299 alias pSDL_RenderCopyExF = int function(SDL_Renderer*,SDL_Texture*,const(SDL_FRect)*,const(SDL_FRect)*,const(double),const(SDL_FPoint)*,const(SDL_RendererFlip)); 300 alias pSDL_RenderFlush = int function(SDL_Renderer*); 301 } 302 __gshared { 303 pSDL_RenderDrawPointF SDL_RenderDrawPointF; 304 pSDL_RenderDrawPointsF SDL_RenderDrawPointsF; 305 pSDL_RenderDrawLineF SDL_RenderDrawLineF; 306 pSDL_RenderDrawLinesF SDL_RenderDrawLinesF; 307 pSDL_RenderDrawRectF SDL_RenderDrawRectF; 308 pSDL_RenderDrawRectsF SDL_RenderDrawRectsF; 309 pSDL_RenderFillRectF SDL_RenderFillRectF; 310 pSDL_RenderFillRectsF SDL_RenderFillRectsF; 311 pSDL_RenderCopyF SDL_RenderCopyF; 312 pSDL_RenderCopyExF SDL_RenderCopyExF; 313 pSDL_RenderFlush SDL_RenderFlush; 314 } 315 } 316 }