this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at master 2071 lines 88 kB view raw
1#ifndef _SDL_GPU_H__ 2#define _SDL_GPU_H__ 3 4#ifndef _USE_MATH_DEFINES 5#define _USE_MATH_DEFINES // So M_PI and company get defined on MSVC when we include math.h 6#endif 7#include <math.h> // Must be included before SDL.h, otherwise both try to define M_PI and we get a warning 8 9#include "SDL.h" 10#include <stdio.h> 11#include <stdarg.h> 12 13// Use SDL's DLL defines 14#include "begin_code.h" 15 16#ifdef __cplusplus 17extern "C" { 18#endif 19 20// Compile-time version info 21#include "SDL_gpu_version.h" 22 23/* Auto-detect if we're using the SDL2 API by the headers available. */ 24#if SDL_VERSION_ATLEAST(2,0,0) 25 #define SDL_GPU_USE_SDL2 26#else 27 #define SDL_GPU_USE_SDL1 28#endif 29 30 31// Check for bool support 32#ifdef __STDC_VERSION__ 33 #define GPU_HAVE_STDC 1 34#else 35 #define GPU_HAVE_STDC 0 36#endif 37 38#define GPU_HAVE_C99 (GPU_HAVE_STDC && (__STDC_VERSION__ >= 199901L)) 39 40#ifdef __GNUC__ // catches both gcc and clang I believe 41 #define GPU_HAVE_GNUC 1 42#else 43 #define GPU_HAVE_GNUC 0 44#endif 45 46#ifdef _MSC_VER 47 #define GPU_HAVE_MSVC 1 48#else 49 #define GPU_HAVE_MSVC 0 50#endif 51 52#define GPU_HAVE_MSVC18 (GPU_HAVE_MSVC && (_MSC_VER >= 1800)) // VS2013+ 53 54#if defined(GPU_USE_REAL_BOOL) && GPU_USE_REAL_BOOL // allow user to specify 55 #define GPU_bool bool 56#elif defined(GPU_USE_INT_BOOL) && GPU_USE_INT_BOOL 57 #define GPU_bool int 58#elif GPU_HAVE_C99 || GPU_HAVE_GNUC || GPU_HAVE_MSVC18 || (defined(GPU_HAVE_STDBOOL) && GPU_HAVE_STDBOOL) 59 #include <stdbool.h> 60 #define GPU_bool bool 61#else 62 #define GPU_bool int 63#endif 64 65#if defined(_MSC_VER) || (defined(__INTEL_COMPILER) && defined(_WIN32)) 66 #if defined(_M_X64) 67 #define SDL_GPU_BITNESS 64 68 #else 69 #define SDL_GPU_BITNESS 32 70 #endif 71 #define SDL_GPU_LONG_SIZE 4 72#elif defined(__clang__) || defined(__INTEL_COMPILER) || defined(__GNUC__) 73 #if defined(__x86_64) 74 #define SDL_GPU_BITNESS 64 75 #else 76 #define SDL_GPU_BITNESS 32 77 #endif 78 #if __LONG_MAX__ == 2147483647L 79 #define SDL_GPU_LONG_SIZE 4 80 #else 81 #define SDL_GPU_LONG_SIZE 8 82 #endif 83#endif 84 85// Struct padding for 32 or 64 bit alignment 86#if SDL_GPU_BITNESS == 32 87#define GPU_PAD_1_TO_32 char _padding[1]; 88#define GPU_PAD_2_TO_32 char _padding[2]; 89#define GPU_PAD_3_TO_32 char _padding[3]; 90#define GPU_PAD_1_TO_64 char _padding[1]; 91#define GPU_PAD_2_TO_64 char _padding[2]; 92#define GPU_PAD_3_TO_64 char _padding[3]; 93#define GPU_PAD_4_TO_64 94#define GPU_PAD_5_TO_64 char _padding[1]; 95#define GPU_PAD_6_TO_64 char _padding[2]; 96#define GPU_PAD_7_TO_64 char _padding[3]; 97#elif SDL_GPU_BITNESS == 64 98#define GPU_PAD_1_TO_32 char _padding[1]; 99#define GPU_PAD_2_TO_32 char _padding[2]; 100#define GPU_PAD_3_TO_32 char _padding[3]; 101#define GPU_PAD_1_TO_64 char _padding[1]; 102#define GPU_PAD_2_TO_64 char _padding[2]; 103#define GPU_PAD_3_TO_64 char _padding[3]; 104#define GPU_PAD_4_TO_64 char _padding[4]; 105#define GPU_PAD_5_TO_64 char _padding[5]; 106#define GPU_PAD_6_TO_64 char _padding[6]; 107#define GPU_PAD_7_TO_64 char _padding[7]; 108#endif 109 110#define GPU_FALSE 0 111#define GPU_TRUE 1 112 113 114typedef struct GPU_Renderer GPU_Renderer; 115typedef struct GPU_Target GPU_Target; 116 117/*! 118 * \defgroup Initialization Initialization 119 * \defgroup Logging Debugging, Logging, and Error Handling 120 * \defgroup RendererSetup Renderer Setup 121 * \defgroup RendererControls Renderer Controls 122 * \defgroup ContextControls Context Controls 123 * \defgroup TargetControls Target Controls 124 * \defgroup SurfaceControls Surface Controls 125 * \defgroup ImageControls Image Controls 126 * \defgroup Conversions Surface, Image, and Target Conversions 127 * \defgroup Matrix Matrix Controls 128 * \defgroup Rendering Rendering 129 * \defgroup Shapes Shapes 130 * \defgroup ShaderInterface Shader Interface 131 */ 132 133/*! \ingroup Rendering 134 * A struct representing a rectangular area with floating point precision. 135 * \see GPU_MakeRect() 136 */ 137typedef struct GPU_Rect 138{ 139 float x, y; 140 float w, h; 141} GPU_Rect; 142 143#define GPU_RENDERER_ORDER_MAX 10 144 145typedef Uint32 GPU_RendererEnum; 146static const GPU_RendererEnum GPU_RENDERER_UNKNOWN = 0; // invalid value 147static const GPU_RendererEnum GPU_RENDERER_OPENGL_1_BASE = 1; 148static const GPU_RendererEnum GPU_RENDERER_OPENGL_1 = 2; 149static const GPU_RendererEnum GPU_RENDERER_OPENGL_2 = 3; 150static const GPU_RendererEnum GPU_RENDERER_OPENGL_3 = 4; 151static const GPU_RendererEnum GPU_RENDERER_OPENGL_4 = 5; 152static const GPU_RendererEnum GPU_RENDERER_GLES_1 = 11; 153static const GPU_RendererEnum GPU_RENDERER_GLES_2 = 12; 154static const GPU_RendererEnum GPU_RENDERER_GLES_3 = 13; 155static const GPU_RendererEnum GPU_RENDERER_D3D9 = 21; 156static const GPU_RendererEnum GPU_RENDERER_D3D10 = 22; 157static const GPU_RendererEnum GPU_RENDERER_D3D11 = 23; 158#define GPU_RENDERER_CUSTOM_0 1000 159 160/*! \ingroup Initialization 161 * \ingroup RendererSetup 162 * \ingroup RendererControls 163 * Renderer ID object for identifying a specific renderer. 164 * \see GPU_MakeRendererID() 165 * \see GPU_InitRendererByID() 166 */ 167typedef struct GPU_RendererID 168{ 169 const char* name; 170 GPU_RendererEnum renderer; 171 int major_version; 172 int minor_version; 173 174 GPU_PAD_4_TO_64 175} GPU_RendererID; 176 177 178/*! \ingroup TargetControls 179 * Comparison operations (for depth testing) 180 * \see GPU_SetDepthFunction() 181 * Values chosen for direct OpenGL compatibility. 182 */ 183typedef enum { 184 GPU_NEVER = 0x0200, 185 GPU_LESS = 0x0201, 186 GPU_EQUAL = 0x0202, 187 GPU_LEQUAL = 0x0203, 188 GPU_GREATER = 0x0204, 189 GPU_NOTEQUAL = 0x0205, 190 GPU_GEQUAL = 0x0206, 191 GPU_ALWAYS = 0x0207 192} GPU_ComparisonEnum; 193 194 195/*! \ingroup ImageControls 196 * Blend component functions 197 * \see GPU_SetBlendFunction() 198 * Values chosen for direct OpenGL compatibility. 199 */ 200typedef enum { 201 GPU_FUNC_ZERO = 0, 202 GPU_FUNC_ONE = 1, 203 GPU_FUNC_SRC_COLOR = 0x0300, 204 GPU_FUNC_DST_COLOR = 0x0306, 205 GPU_FUNC_ONE_MINUS_SRC = 0x0301, 206 GPU_FUNC_ONE_MINUS_DST = 0x0307, 207 GPU_FUNC_SRC_ALPHA = 0x0302, 208 GPU_FUNC_DST_ALPHA = 0x0304, 209 GPU_FUNC_ONE_MINUS_SRC_ALPHA = 0x0303, 210 GPU_FUNC_ONE_MINUS_DST_ALPHA = 0x0305 211} GPU_BlendFuncEnum; 212 213/*! \ingroup ImageControls 214 * Blend component equations 215 * \see GPU_SetBlendEquation() 216 * Values chosen for direct OpenGL compatibility. 217 */ 218typedef enum { 219 GPU_EQ_ADD = 0x8006, 220 GPU_EQ_SUBTRACT = 0x800A, 221 GPU_EQ_REVERSE_SUBTRACT = 0x800B 222} GPU_BlendEqEnum; 223 224/*! \ingroup ImageControls 225 * Blend mode storage struct */ 226typedef struct GPU_BlendMode 227{ 228 GPU_BlendFuncEnum source_color; 229 GPU_BlendFuncEnum dest_color; 230 GPU_BlendFuncEnum source_alpha; 231 GPU_BlendFuncEnum dest_alpha; 232 233 GPU_BlendEqEnum color_equation; 234 GPU_BlendEqEnum alpha_equation; 235} GPU_BlendMode; 236 237/*! \ingroup ImageControls 238 * Blend mode presets 239 * \see GPU_SetBlendMode() 240 * \see GPU_GetBlendModeFromPreset() 241 */ 242typedef enum { 243 GPU_BLEND_NORMAL = 0, 244 GPU_BLEND_PREMULTIPLIED_ALPHA = 1, 245 GPU_BLEND_MULTIPLY = 2, 246 GPU_BLEND_ADD = 3, 247 GPU_BLEND_SUBTRACT = 4, 248 GPU_BLEND_MOD_ALPHA = 5, 249 GPU_BLEND_SET_ALPHA = 6, 250 GPU_BLEND_SET = 7, 251 GPU_BLEND_NORMAL_KEEP_ALPHA = 8, 252 GPU_BLEND_NORMAL_ADD_ALPHA = 9, 253 GPU_BLEND_NORMAL_FACTOR_ALPHA = 10 254} GPU_BlendPresetEnum; 255 256/*! \ingroup ImageControls 257 * Image filtering options. These affect the quality/interpolation of colors when images are scaled. 258 * \see GPU_SetImageFilter() 259 */ 260typedef enum { 261 GPU_FILTER_NEAREST = 0, 262 GPU_FILTER_LINEAR = 1, 263 GPU_FILTER_LINEAR_MIPMAP = 2 264} GPU_FilterEnum; 265 266/*! \ingroup ImageControls 267 * Snap modes. Blitting with these modes will align the sprite with the target's pixel grid. 268 * \see GPU_SetSnapMode() 269 * \see GPU_GetSnapMode() 270 */ 271typedef enum { 272 GPU_SNAP_NONE = 0, 273 GPU_SNAP_POSITION = 1, 274 GPU_SNAP_DIMENSIONS = 2, 275 GPU_SNAP_POSITION_AND_DIMENSIONS = 3 276} GPU_SnapEnum; 277 278 279/*! \ingroup ImageControls 280 * Image wrapping options. These affect how images handle src_rect coordinates beyond their dimensions when blitted. 281 * \see GPU_SetWrapMode() 282 */ 283typedef enum { 284 GPU_WRAP_NONE = 0, 285 GPU_WRAP_REPEAT = 1, 286 GPU_WRAP_MIRRORED = 2 287} GPU_WrapEnum; 288 289/*! \ingroup ImageControls 290 * Image format enum 291 * \see GPU_CreateImage() 292 */ 293typedef enum { 294 GPU_FORMAT_LUMINANCE = 1, 295 GPU_FORMAT_LUMINANCE_ALPHA = 2, 296 GPU_FORMAT_RGB = 3, 297 GPU_FORMAT_RGBA = 4, 298 GPU_FORMAT_ALPHA = 5, 299 GPU_FORMAT_RG = 6, 300 GPU_FORMAT_YCbCr422 = 7, 301 GPU_FORMAT_YCbCr420P = 8, 302 GPU_FORMAT_BGR = 9, 303 GPU_FORMAT_BGRA = 10, 304 GPU_FORMAT_ABGR = 11 305} GPU_FormatEnum; 306 307/*! \ingroup ImageControls 308 * File format enum 309 * \see GPU_SaveSurface() 310 * \see GPU_SaveImage() 311 * \see GPU_SaveSurface_RW() 312 * \see GPU_SaveImage_RW() 313 */ 314typedef enum { 315 GPU_FILE_AUTO = 0, 316 GPU_FILE_PNG, 317 GPU_FILE_BMP, 318 GPU_FILE_TGA 319} GPU_FileFormatEnum; 320 321 322 323/*! \ingroup ImageControls 324 * Image object for containing pixel/texture data. 325 * A GPU_Image can be created with GPU_CreateImage(), GPU_LoadImage(), GPU_CopyImage(), or GPU_CopyImageFromSurface(). 326 * Free the memory with GPU_FreeImage() when you're done. 327 * \see GPU_CreateImage() 328 * \see GPU_LoadImage() 329 * \see GPU_CopyImage() 330 * \see GPU_CopyImageFromSurface() 331 * \see GPU_Target 332 */ 333typedef struct GPU_Image 334{ 335 struct GPU_Renderer* renderer; 336 GPU_Target* context_target; 337 GPU_Target* target; 338 void* data; 339 340 Uint16 w, h; 341 GPU_FormatEnum format; 342 int num_layers; 343 int bytes_per_pixel; 344 Uint16 base_w, base_h; // Original image dimensions 345 Uint16 texture_w, texture_h; // Underlying texture dimensions 346 347 float anchor_x; // Normalized coords for the point at which the image is blitted. Default is (0.5, 0.5), that is, the image is drawn centered. 348 float anchor_y; // These are interpreted according to GPU_SetCoordinateMode() and range from (0.0 - 1.0) normally. 349 350 SDL_Color color; 351 GPU_BlendMode blend_mode; 352 GPU_FilterEnum filter_mode; 353 GPU_SnapEnum snap_mode; 354 GPU_WrapEnum wrap_mode_x; 355 GPU_WrapEnum wrap_mode_y; 356 357 int refcount; 358 359 GPU_bool using_virtual_resolution; 360 GPU_bool has_mipmaps; 361 GPU_bool use_blending; 362 GPU_bool is_alias; 363} GPU_Image; 364 365/*! \ingroup ImageControls 366 * A backend-neutral type that is intended to hold a backend-specific handle/pointer to a texture. 367 * \see GPU_CreateImageUsingTexture() 368 * \see GPU_GetTextureHandle() 369 */ 370typedef uintptr_t GPU_TextureHandle; 371 372 373/*! \ingroup TargetControls 374 * Camera object that determines viewing transform. 375 * \see GPU_SetCamera() 376 * \see GPU_GetDefaultCamera() 377 * \see GPU_GetCamera() 378 */ 379typedef struct GPU_Camera 380{ 381 float x, y, z; 382 float angle; 383 float zoom_x, zoom_y; 384 float z_near, z_far; // z clipping planes 385 GPU_bool use_centered_origin; // move rotation/scaling origin to the center of the camera's view 386 387 GPU_PAD_7_TO_64 388} GPU_Camera; 389 390 391/*! \ingroup ShaderInterface 392 * Container for the built-in shader attribute and uniform locations (indices). 393 * \see GPU_LoadShaderBlock() 394 * \see GPU_SetShaderBlock() 395 */ 396typedef struct GPU_ShaderBlock 397{ 398 // Attributes 399 int position_loc; 400 int texcoord_loc; 401 int color_loc; 402 // Uniforms 403 int modelViewProjection_loc; 404} GPU_ShaderBlock; 405 406 407 408 409 410#define GPU_MODEL 0 411#define GPU_VIEW 1 412#define GPU_PROJECTION 2 413 414/*! \ingroup Matrix 415 * Matrix stack data structure for global vertex transforms. */ 416typedef struct GPU_MatrixStack 417{ 418 unsigned int storage_size; 419 unsigned int size; 420 float** matrix; 421} GPU_MatrixStack; 422 423 424/*! \ingroup ContextControls 425 * Rendering context data. Only GPU_Targets which represent windows will store this. */ 426typedef struct GPU_Context 427{ 428 /*! SDL_GLContext */ 429 void* context; 430 431 /*! Last target used */ 432 GPU_Target* active_target; 433 434 GPU_ShaderBlock current_shader_block; 435 GPU_ShaderBlock default_textured_shader_block; 436 GPU_ShaderBlock default_untextured_shader_block; 437 438 439 /*! SDL window ID */ 440 Uint32 windowID; 441 442 /*! Actual window dimensions */ 443 int window_w; 444 int window_h; 445 446 /*! Drawable region dimensions */ 447 int drawable_w; 448 int drawable_h; 449 450 /*! Window dimensions for restoring windowed mode after GPU_SetFullscreen(1,1). */ 451 int stored_window_w; 452 int stored_window_h; 453 454 /*! Shader handles used in the default shader programs */ 455 Uint32 default_textured_vertex_shader_id; 456 Uint32 default_textured_fragment_shader_id; 457 Uint32 default_untextured_vertex_shader_id; 458 Uint32 default_untextured_fragment_shader_id; 459 460 461 462 /*! Internal state */ 463 Uint32 current_shader_program; 464 Uint32 default_textured_shader_program; 465 Uint32 default_untextured_shader_program; 466 467 GPU_BlendMode shapes_blend_mode; 468 float line_thickness; 469 470 int refcount; 471 472 void* data; 473 474 GPU_bool failed; 475 GPU_bool use_texturing; 476 GPU_bool shapes_use_blending; 477 478 GPU_PAD_5_TO_64 479} GPU_Context; 480 481 482/*! \ingroup TargetControls 483 * Render target object for use as a blitting destination. 484 * A GPU_Target can be created from a GPU_Image with GPU_LoadTarget(). 485 * A GPU_Target can also represent a separate window with GPU_CreateTargetFromWindow(). In that case, 'context' is allocated and filled in. 486 * Note: You must have passed the SDL_WINDOW_OPENGL flag to SDL_CreateWindow() for OpenGL renderers to work with new windows. 487 * Free the memory with GPU_FreeTarget() when you're done. 488 * \see GPU_LoadTarget() 489 * \see GPU_CreateTargetFromWindow() 490 * \see GPU_FreeTarget() 491 */ 492struct GPU_Target 493{ 494 struct GPU_Renderer* renderer; 495 GPU_Target* context_target; 496 GPU_Image* image; 497 void* data; 498 Uint16 w, h; 499 Uint16 base_w, base_h; // The true dimensions of the underlying image or window 500 GPU_Rect clip_rect; 501 SDL_Color color; 502 503 GPU_Rect viewport; 504 505 /*! Perspective and object viewing transforms. */ 506 int matrix_mode; 507 GPU_MatrixStack projection_matrix; 508 GPU_MatrixStack view_matrix; 509 GPU_MatrixStack model_matrix; 510 511 GPU_Camera camera; 512 513 GPU_bool using_virtual_resolution; 514 GPU_bool use_clip_rect; 515 GPU_bool use_color; 516 GPU_bool use_camera; 517 518 519 GPU_ComparisonEnum depth_function; 520 521 /*! Renderer context data. NULL if the target does not represent a window or rendering context. */ 522 GPU_Context* context; 523 int refcount; 524 525 GPU_bool use_depth_test; 526 GPU_bool use_depth_write; 527 GPU_bool is_alias; 528 529 GPU_PAD_1_TO_64 530}; 531 532/*! \ingroup Initialization 533 * Important GPU features which may not be supported depending on a device's extension support. Can be bitwise OR'd together. 534 * \see GPU_IsFeatureEnabled() 535 * \see GPU_SetRequiredFeatures() 536 */ 537typedef Uint32 GPU_FeatureEnum; 538static const GPU_FeatureEnum GPU_FEATURE_NON_POWER_OF_TWO = 0x1; 539static const GPU_FeatureEnum GPU_FEATURE_RENDER_TARGETS = 0x2; 540static const GPU_FeatureEnum GPU_FEATURE_BLEND_EQUATIONS = 0x4; 541static const GPU_FeatureEnum GPU_FEATURE_BLEND_FUNC_SEPARATE = 0x8; 542static const GPU_FeatureEnum GPU_FEATURE_BLEND_EQUATIONS_SEPARATE = 0x10; 543static const GPU_FeatureEnum GPU_FEATURE_GL_BGR = 0x20; 544static const GPU_FeatureEnum GPU_FEATURE_GL_BGRA = 0x40; 545static const GPU_FeatureEnum GPU_FEATURE_GL_ABGR = 0x80; 546static const GPU_FeatureEnum GPU_FEATURE_VERTEX_SHADER = 0x100; 547static const GPU_FeatureEnum GPU_FEATURE_FRAGMENT_SHADER = 0x200; 548static const GPU_FeatureEnum GPU_FEATURE_PIXEL_SHADER = 0x200; 549static const GPU_FeatureEnum GPU_FEATURE_GEOMETRY_SHADER = 0x400; 550static const GPU_FeatureEnum GPU_FEATURE_WRAP_REPEAT_MIRRORED = 0x800; 551static const GPU_FeatureEnum GPU_FEATURE_CORE_FRAMEBUFFER_OBJECTS = 0x1000; 552 553/*! Combined feature flags */ 554#define GPU_FEATURE_ALL_BASE GPU_FEATURE_RENDER_TARGETS 555#define GPU_FEATURE_ALL_BLEND_PRESETS (GPU_FEATURE_BLEND_EQUATIONS | GPU_FEATURE_BLEND_FUNC_SEPARATE) 556#define GPU_FEATURE_ALL_GL_FORMATS (GPU_FEATURE_GL_BGR | GPU_FEATURE_GL_BGRA | GPU_FEATURE_GL_ABGR) 557#define GPU_FEATURE_BASIC_SHADERS (GPU_FEATURE_FRAGMENT_SHADER | GPU_FEATURE_VERTEX_SHADER) 558#define GPU_FEATURE_ALL_SHADERS (GPU_FEATURE_FRAGMENT_SHADER | GPU_FEATURE_VERTEX_SHADER | GPU_FEATURE_GEOMETRY_SHADER) 559 560 561typedef Uint32 GPU_WindowFlagEnum; 562 563/*! \ingroup Initialization 564 * Initialization flags for changing default init parameters. Can be bitwise OR'ed together. 565 * Default (0) is to use late swap vsync and double buffering. 566 * \see GPU_SetPreInitFlags() 567 * \see GPU_GetPreInitFlags() 568 */ 569typedef Uint32 GPU_InitFlagEnum; 570static const GPU_InitFlagEnum GPU_INIT_ENABLE_VSYNC = 0x1; 571static const GPU_InitFlagEnum GPU_INIT_DISABLE_VSYNC = 0x2; 572static const GPU_InitFlagEnum GPU_INIT_DISABLE_DOUBLE_BUFFER = 0x4; 573static const GPU_InitFlagEnum GPU_INIT_DISABLE_AUTO_VIRTUAL_RESOLUTION = 0x8; 574static const GPU_InitFlagEnum GPU_INIT_REQUEST_COMPATIBILITY_PROFILE = 0x10; 575static const GPU_InitFlagEnum GPU_INIT_USE_ROW_BY_ROW_TEXTURE_UPLOAD_FALLBACK = 0x20; 576static const GPU_InitFlagEnum GPU_INIT_USE_COPY_TEXTURE_UPLOAD_FALLBACK = 0x40; 577 578#define GPU_DEFAULT_INIT_FLAGS 0 579 580 581static const Uint32 GPU_NONE = 0x0; 582 583/*! \ingroup Rendering 584 * Primitive types for rendering arbitrary geometry. The values are intentionally identical to the GL_* primitives. 585 * \see GPU_PrimitiveBatch() 586 * \see GPU_PrimitiveBatchV() 587 */ 588typedef Uint32 GPU_PrimitiveEnum; 589static const GPU_PrimitiveEnum GPU_POINTS = 0x0; 590static const GPU_PrimitiveEnum GPU_LINES = 0x1; 591static const GPU_PrimitiveEnum GPU_LINE_LOOP = 0x2; 592static const GPU_PrimitiveEnum GPU_LINE_STRIP = 0x3; 593static const GPU_PrimitiveEnum GPU_TRIANGLES = 0x4; 594static const GPU_PrimitiveEnum GPU_TRIANGLE_STRIP = 0x5; 595static const GPU_PrimitiveEnum GPU_TRIANGLE_FAN = 0x6; 596 597 598/*! Bit flags for geometry batching. 599 * \see GPU_TriangleBatch() 600 * \see GPU_TriangleBatchX() 601 * \see GPU_PrimitiveBatch() 602 * \see GPU_PrimitiveBatchV() 603 */ 604typedef Uint32 GPU_BatchFlagEnum; 605static const GPU_BatchFlagEnum GPU_BATCH_XY = 0x1; 606static const GPU_BatchFlagEnum GPU_BATCH_XYZ = 0x2; 607static const GPU_BatchFlagEnum GPU_BATCH_ST = 0x4; 608static const GPU_BatchFlagEnum GPU_BATCH_RGB = 0x8; 609static const GPU_BatchFlagEnum GPU_BATCH_RGBA = 0x10; 610static const GPU_BatchFlagEnum GPU_BATCH_RGB8 = 0x20; 611static const GPU_BatchFlagEnum GPU_BATCH_RGBA8 = 0x40; 612 613#define GPU_BATCH_XY_ST (GPU_BATCH_XY | GPU_BATCH_ST) 614#define GPU_BATCH_XYZ_ST (GPU_BATCH_XYZ | GPU_BATCH_ST) 615#define GPU_BATCH_XY_RGB (GPU_BATCH_XY | GPU_BATCH_RGB) 616#define GPU_BATCH_XYZ_RGB (GPU_BATCH_XYZ | GPU_BATCH_RGB) 617#define GPU_BATCH_XY_RGBA (GPU_BATCH_XY | GPU_BATCH_RGBA) 618#define GPU_BATCH_XYZ_RGBA (GPU_BATCH_XYZ | GPU_BATCH_RGBA) 619#define GPU_BATCH_XY_ST_RGBA (GPU_BATCH_XY | GPU_BATCH_ST | GPU_BATCH_RGBA) 620#define GPU_BATCH_XYZ_ST_RGBA (GPU_BATCH_XYZ | GPU_BATCH_ST | GPU_BATCH_RGBA) 621#define GPU_BATCH_XY_RGB8 (GPU_BATCH_XY | GPU_BATCH_RGB8) 622#define GPU_BATCH_XYZ_RGB8 (GPU_BATCH_XYZ | GPU_BATCH_RGB8) 623#define GPU_BATCH_XY_RGBA8 (GPU_BATCH_XY | GPU_BATCH_RGBA8) 624#define GPU_BATCH_XYZ_RGBA8 (GPU_BATCH_XYZ | GPU_BATCH_RGBA8) 625#define GPU_BATCH_XY_ST_RGBA8 (GPU_BATCH_XY | GPU_BATCH_ST | GPU_BATCH_RGBA8) 626#define GPU_BATCH_XYZ_ST_RGBA8 (GPU_BATCH_XYZ | GPU_BATCH_ST | GPU_BATCH_RGBA8) 627 628 629/*! Bit flags for blitting into a rectangular region. 630 * \see GPU_BlitRect 631 * \see GPU_BlitRectX 632 */ 633typedef Uint32 GPU_FlipEnum; 634static const GPU_FlipEnum GPU_FLIP_NONE = 0x0; 635static const GPU_FlipEnum GPU_FLIP_HORIZONTAL = 0x1; 636static const GPU_FlipEnum GPU_FLIP_VERTICAL = 0x2; 637 638 639/*! \ingroup ShaderInterface 640 * Type enumeration for GPU_AttributeFormat specifications. 641 */ 642typedef Uint32 GPU_TypeEnum; 643// Use OpenGL's values for simpler translation 644static const GPU_TypeEnum GPU_TYPE_BYTE = 0x1400; 645static const GPU_TypeEnum GPU_TYPE_UNSIGNED_BYTE = 0x1401; 646static const GPU_TypeEnum GPU_TYPE_SHORT = 0x1402; 647static const GPU_TypeEnum GPU_TYPE_UNSIGNED_SHORT = 0x1403; 648static const GPU_TypeEnum GPU_TYPE_INT = 0x1404; 649static const GPU_TypeEnum GPU_TYPE_UNSIGNED_INT = 0x1405; 650static const GPU_TypeEnum GPU_TYPE_FLOAT = 0x1406; 651static const GPU_TypeEnum GPU_TYPE_DOUBLE = 0x140A; 652 653 654 655 656 657 658/*! \ingroup ShaderInterface 659 * Shader type enum. 660 * \see GPU_LoadShader() 661 * \see GPU_CompileShader() 662 * \see GPU_CompileShader_RW() 663 */ 664typedef enum { 665 GPU_VERTEX_SHADER = 0, 666 GPU_FRAGMENT_SHADER = 1, 667 GPU_PIXEL_SHADER = 1, 668 GPU_GEOMETRY_SHADER = 2 669} GPU_ShaderEnum; 670 671 672 673/*! \ingroup ShaderInterface 674 * Type enumeration for the shader language used by the renderer. 675 */ 676typedef enum { 677 GPU_LANGUAGE_NONE = 0, 678 GPU_LANGUAGE_ARB_ASSEMBLY = 1, 679 GPU_LANGUAGE_GLSL = 2, 680 GPU_LANGUAGE_GLSLES = 3, 681 GPU_LANGUAGE_HLSL = 4, 682 GPU_LANGUAGE_CG = 5 683} GPU_ShaderLanguageEnum; 684 685/*! \ingroup ShaderInterface */ 686typedef struct GPU_AttributeFormat 687{ 688 int num_elems_per_value; 689 GPU_TypeEnum type; // GPU_TYPE_FLOAT, GPU_TYPE_INT, GPU_TYPE_UNSIGNED_INT, etc. 690 int stride_bytes; // Number of bytes between two vertex specifications 691 int offset_bytes; // Number of bytes to skip at the beginning of 'values' 692 GPU_bool is_per_sprite; // Per-sprite values are expanded to 4 vertices 693 GPU_bool normalize; 694 695 GPU_PAD_2_TO_32 696} GPU_AttributeFormat; 697 698/*! \ingroup ShaderInterface */ 699typedef struct GPU_Attribute 700{ 701 void* values; // Expect 4 values for each sprite 702 GPU_AttributeFormat format; 703 int location; 704 705 GPU_PAD_4_TO_64 706} GPU_Attribute; 707 708/*! \ingroup ShaderInterface */ 709typedef struct GPU_AttributeSource 710{ 711 void* next_value; 712 void* per_vertex_storage; // Could point to the attribute's values or to allocated storage 713 714 int num_values; 715 // Automatic storage format 716 int per_vertex_storage_stride_bytes; 717 int per_vertex_storage_offset_bytes; 718 int per_vertex_storage_size; // Over 0 means that the per-vertex storage has been automatically allocated 719 GPU_Attribute attribute; 720 GPU_bool enabled; 721 722 GPU_PAD_7_TO_64 723} GPU_AttributeSource; 724 725 726/*! \ingroup Logging 727 * Type enumeration for error codes. 728 * \see GPU_PushErrorCode() 729 * \see GPU_PopErrorCode() 730 */ 731typedef enum { 732 GPU_ERROR_NONE = 0, 733 GPU_ERROR_BACKEND_ERROR = 1, 734 GPU_ERROR_DATA_ERROR = 2, 735 GPU_ERROR_USER_ERROR = 3, 736 GPU_ERROR_UNSUPPORTED_FUNCTION = 4, 737 GPU_ERROR_NULL_ARGUMENT = 5, 738 GPU_ERROR_FILE_NOT_FOUND = 6 739} GPU_ErrorEnum; 740 741/*! \ingroup Logging */ 742typedef struct GPU_ErrorObject 743{ 744 char* function; 745 char* details; 746 GPU_ErrorEnum error; 747 748 GPU_PAD_4_TO_64 749} GPU_ErrorObject; 750 751 752/*! \ingroup Logging 753 * Type enumeration for debug levels. 754 * \see GPU_SetDebugLevel() 755 * \see GPU_GetDebugLevel() 756 */ 757typedef enum { 758 GPU_DEBUG_LEVEL_0 = 0, 759 GPU_DEBUG_LEVEL_1 = 1, 760 GPU_DEBUG_LEVEL_2 = 2, 761 GPU_DEBUG_LEVEL_3 = 3, 762 GPU_DEBUG_LEVEL_MAX = 3 763} GPU_DebugLevelEnum; 764 765 766/*! \ingroup Logging 767 * Type enumeration for logging levels. 768 * \see GPU_SetLogCallback() 769 */ 770typedef enum { 771 GPU_LOG_INFO = 0, 772 GPU_LOG_WARNING, 773 GPU_LOG_ERROR 774} GPU_LogLevelEnum; 775 776 777/* Private implementation of renderer members */ 778struct GPU_RendererImpl; 779 780/*! Renderer object which specializes the API to a particular backend. */ 781struct GPU_Renderer 782{ 783 /*! Struct identifier of the renderer. */ 784 GPU_RendererID id; 785 GPU_RendererID requested_id; 786 GPU_WindowFlagEnum SDL_init_flags; 787 GPU_InitFlagEnum GPU_init_flags; 788 789 GPU_ShaderLanguageEnum shader_language; 790 int min_shader_version; 791 int max_shader_version; 792 GPU_FeatureEnum enabled_features; 793 794 /*! Current display target */ 795 GPU_Target* current_context_target; 796 797 /*! Default is (0.5, 0.5) - images draw centered. */ 798 float default_image_anchor_x; 799 float default_image_anchor_y; 800 801 struct GPU_RendererImpl* impl; 802 803 /*! 0 for inverted, 1 for mathematical */ 804 GPU_bool coordinate_mode; 805 806 GPU_PAD_7_TO_64 807}; 808 809 810 811 812 813 814/*! \ingroup Initialization 815 * @{ */ 816 817// Visual C does not support static inline 818#ifdef _MSC_VER 819static SDL_version SDLCALL GPU_GetCompiledVersion(void) 820#else 821static inline SDL_version SDLCALL GPU_GetCompiledVersion(void) 822#endif 823{ 824 SDL_version v = {SDL_GPU_VERSION_MAJOR, SDL_GPU_VERSION_MINOR, SDL_GPU_VERSION_PATCH}; 825 return v; 826} 827 828DECLSPEC SDL_version SDLCALL GPU_GetLinkedVersion(void); 829 830/*! The window corresponding to 'windowID' will be used to create the rendering context instead of creating a new window. */ 831DECLSPEC void SDLCALL GPU_SetInitWindow(Uint32 windowID); 832 833/*! Returns the window ID that has been set via GPU_SetInitWindow(). */ 834DECLSPEC Uint32 SDLCALL GPU_GetInitWindow(void); 835 836/*! Set special flags to use for initialization. Set these before calling GPU_Init(). 837 * \param GPU_flags An OR'ed combination of GPU_InitFlagEnum flags. Default flags (0) enable late swap vsync and double buffering. */ 838DECLSPEC void SDLCALL GPU_SetPreInitFlags(GPU_InitFlagEnum GPU_flags); 839 840/*! Returns the current special flags to use for initialization. */ 841DECLSPEC GPU_InitFlagEnum SDLCALL GPU_GetPreInitFlags(void); 842 843/*! Set required features to use for initialization. Set these before calling GPU_Init(). 844 * \param features An OR'ed combination of GPU_FeatureEnum flags. Required features will force GPU_Init() to create a renderer that supports all of the given flags or else fail. */ 845DECLSPEC void SDLCALL GPU_SetRequiredFeatures(GPU_FeatureEnum features); 846 847/*! Returns the current required features to use for initialization. */ 848DECLSPEC GPU_FeatureEnum SDLCALL GPU_GetRequiredFeatures(void); 849 850/*! Gets the default initialization renderer IDs for the current platform copied into the 'order' array and the number of renderer IDs into 'order_size'. Pass NULL for 'order' to just get the size of the renderer order array. Will return at most GPU_RENDERER_ORDER_MAX renderers. */ 851DECLSPEC void SDLCALL GPU_GetDefaultRendererOrder(int* order_size, GPU_RendererID* order); 852 853/*! Gets the current renderer ID order for initialization copied into the 'order' array and the number of renderer IDs into 'order_size'. Pass NULL for 'order' to just get the size of the renderer order array. */ 854DECLSPEC void SDLCALL GPU_GetRendererOrder(int* order_size, GPU_RendererID* order); 855 856/*! Sets the renderer ID order to use for initialization. If 'order' is NULL, it will restore the default order. */ 857DECLSPEC void SDLCALL GPU_SetRendererOrder(int order_size, GPU_RendererID* order); 858 859/*! Initializes SDL's video subsystem (if necessary) and all of SDL_gpu's internal structures. 860 * Chooses a renderer and creates a window with the given dimensions and window creation flags. 861 * A pointer to the resulting window's render target is returned. 862 * 863 * \param w Desired window width in pixels 864 * \param h Desired window height in pixels 865 * \param SDL_flags The bit flags to pass to SDL when creating the window. Use GPU_DEFAULT_INIT_FLAGS if you don't care. 866 * \return On success, returns the new context target (i.e. render target backed by a window). On failure, returns NULL. 867 * 868 * Initializes these systems: 869 * The 'error queue': Stores error codes and description strings. 870 * The 'renderer registry': An array of information about the supported renderers on the current platform, 871 * such as the renderer name and id and its life cycle functions. 872 * The SDL library and its video subsystem: Calls SDL_Init() if SDL has not already been initialized. 873 * Use SDL_InitSubsystem() to initialize more parts of SDL. 874 * The current renderer: Walks through each renderer in the renderer registry and tries to initialize them until one succeeds. 875 * 876 * \see GPU_RendererID 877 * \see GPU_InitRenderer() 878 * \see GPU_InitRendererByID() 879 * \see GPU_SetRendererOrder() 880 * \see GPU_PushErrorCode() 881 */ 882DECLSPEC GPU_Target* SDLCALL GPU_Init(Uint16 w, Uint16 h, GPU_WindowFlagEnum SDL_flags); 883 884/*! Initializes SDL and SDL_gpu. Creates a window and the requested renderer context. */ 885DECLSPEC GPU_Target* SDLCALL GPU_InitRenderer(GPU_RendererEnum renderer_enum, Uint16 w, Uint16 h, GPU_WindowFlagEnum SDL_flags); 886 887/*! Initializes SDL and SDL_gpu. Creates a window and the requested renderer context. 888 * By requesting a renderer via ID, you can specify the major and minor versions of an individual renderer backend. 889 * \see GPU_MakeRendererID 890 */ 891DECLSPEC GPU_Target* SDLCALL GPU_InitRendererByID(GPU_RendererID renderer_request, Uint16 w, Uint16 h, GPU_WindowFlagEnum SDL_flags); 892 893/*! Checks for important GPU features which may not be supported depending on a device's extension support. Feature flags (GPU_FEATURE_*) can be bitwise OR'd together. 894 * \return 1 if all of the passed features are enabled/supported 895 * \return 0 if any of the passed features are disabled/unsupported 896 */ 897DECLSPEC GPU_bool SDLCALL GPU_IsFeatureEnabled(GPU_FeatureEnum feature); 898 899/*! Clean up the renderer state. */ 900DECLSPEC void SDLCALL GPU_CloseCurrentRenderer(void); 901 902/*! Clean up the renderer state and shut down SDL_gpu. */ 903DECLSPEC void SDLCALL GPU_Quit(void); 904 905// End of Initialization 906/*! @} */ 907 908 909 910// Debugging, logging, and error handling 911 912#define GPU_Log GPU_LogInfo 913/*! \ingroup Logging 914 * @{ */ 915 916/*! Sets the global debug level. 917 * GPU_DEBUG_LEVEL_0: Normal 918 * GPU_DEBUG_LEVEL_1: Prints messages when errors are pushed via GPU_PushErrorCode() 919 * GPU_DEBUG_LEVEL_2: Elevates warning logs to error priority 920 * GPU_DEBUG_LEVEL_3: Elevates info logs to error priority 921 */ 922DECLSPEC void SDLCALL GPU_SetDebugLevel(GPU_DebugLevelEnum level); 923 924/*! Returns the current global debug level. */ 925DECLSPEC GPU_DebugLevelEnum SDLCALL GPU_GetDebugLevel(void); 926 927/*! Prints an informational log message. */ 928DECLSPEC void SDLCALL GPU_LogInfo(const char* format, ...); 929 930/*! Prints a warning log message. */ 931DECLSPEC void SDLCALL GPU_LogWarning(const char* format, ...); 932 933/*! Prints an error log message. */ 934DECLSPEC void SDLCALL GPU_LogError(const char* format, ...); 935 936/*! Sets a custom callback for handling logging. Use stdio's vsnprintf() to process the va_list into a string. Passing NULL as the callback will reset to the default internal logging. */ 937DECLSPEC void SDLCALL GPU_SetLogCallback(int (*callback)(GPU_LogLevelEnum log_level, const char* format, va_list args)); 938 939/*! Pushes a new error code into the error queue. If the queue is full, the queue is not modified. 940 * \param function The name of the function that pushed the error 941 * \param error The error code to push on the error queue 942 * \param details Additional information string, can be NULL. 943 */ 944DECLSPEC void SDLCALL GPU_PushErrorCode(const char* function, GPU_ErrorEnum error, const char* details, ...); 945 946/*! Pops an error object from the error queue and returns it. If the error queue is empty, it returns an error object with NULL function, GPU_ERROR_NONE error, and NULL details. */ 947DECLSPEC GPU_ErrorObject SDLCALL GPU_PopErrorCode(void); 948 949/*! Gets the string representation of an error code. */ 950DECLSPEC const char* SDLCALL GPU_GetErrorString(GPU_ErrorEnum error); 951 952/*! Changes the maximum number of error objects that SDL_gpu will store. This deletes all currently stored errors. */ 953DECLSPEC void SDLCALL GPU_SetErrorQueueMax(unsigned int max); 954 955// End of Logging 956/*! @} */ 957 958 959 960 961 962 963 964/*! \ingroup RendererSetup 965 * @{ */ 966 967/*! Returns an initialized GPU_RendererID. */ 968DECLSPEC GPU_RendererID SDLCALL GPU_MakeRendererID(const char* name, GPU_RendererEnum renderer, int major_version, int minor_version); 969 970/*! Gets the first registered renderer identifier for the given enum value. */ 971DECLSPEC GPU_RendererID SDLCALL GPU_GetRendererID(GPU_RendererEnum renderer); 972 973/*! Gets the number of registered (available) renderers. */ 974DECLSPEC int SDLCALL GPU_GetNumRegisteredRenderers(void); 975 976/*! Gets an array of identifiers for the registered (available) renderers. */ 977DECLSPEC void SDLCALL GPU_GetRegisteredRendererList(GPU_RendererID* renderers_array); 978 979/*! Prepares a renderer for use by SDL_gpu. */ 980DECLSPEC void SDLCALL GPU_RegisterRenderer(GPU_RendererID id, GPU_Renderer* (SDLCALL *create_renderer)(GPU_RendererID request), void (SDLCALL *free_renderer)(GPU_Renderer* renderer)); 981 982// End of RendererSetup 983/*! @} */ 984 985 986 987/*! \ingroup RendererControls 988 * @{ */ 989 990/*! Gets the next enum ID that can be used for a custom renderer. */ 991DECLSPEC GPU_RendererEnum SDLCALL GPU_ReserveNextRendererEnum(void); 992 993/*! Gets the number of active (created) renderers. */ 994DECLSPEC int SDLCALL GPU_GetNumActiveRenderers(void); 995 996/*! Gets an array of identifiers for the active renderers. */ 997DECLSPEC void SDLCALL GPU_GetActiveRendererList(GPU_RendererID* renderers_array); 998 999/*! \return The current renderer */ 1000DECLSPEC GPU_Renderer* SDLCALL GPU_GetCurrentRenderer(void); 1001 1002/*! Switches the current renderer to the renderer matching the given identifier. */ 1003DECLSPEC void SDLCALL GPU_SetCurrentRenderer(GPU_RendererID id); 1004 1005/*! \return The renderer matching the given identifier. */ 1006DECLSPEC GPU_Renderer* SDLCALL GPU_GetRenderer(GPU_RendererID id); 1007 1008DECLSPEC void SDLCALL GPU_FreeRenderer(GPU_Renderer* renderer); 1009 1010/*! Reapplies the renderer state to the backend API (e.g. OpenGL, Direct3D). Use this if you want SDL_gpu to be able to render after you've used direct backend calls. */ 1011DECLSPEC void SDLCALL GPU_ResetRendererState(void); 1012 1013/*! Sets the coordinate mode for this renderer. Target and image coordinates will be either "inverted" (0,0 is the upper left corner, y increases downward) or "mathematical" (0,0 is the bottom-left corner, y increases upward). 1014 * The default is inverted (0), as this is traditional for 2D graphics. 1015 * \param inverted 0 is for inverted coordinates, 1 is for mathematical coordinates */ 1016DECLSPEC void SDLCALL GPU_SetCoordinateMode(GPU_bool use_math_coords); 1017 1018DECLSPEC GPU_bool SDLCALL GPU_GetCoordinateMode(void); 1019 1020/*! Sets the default image blitting anchor for newly created images. 1021 * \see GPU_SetAnchor 1022 */ 1023DECLSPEC void SDLCALL GPU_SetDefaultAnchor(float anchor_x, float anchor_y); 1024 1025/*! Returns the default image blitting anchor through the given variables. 1026 * \see GPU_GetAnchor 1027 */ 1028DECLSPEC void SDLCALL GPU_GetDefaultAnchor(float* anchor_x, float* anchor_y); 1029 1030// End of RendererControls 1031/*! @} */ 1032 1033 1034 1035 1036// Context / window controls 1037 1038/*! \ingroup ContextControls 1039 * @{ */ 1040 1041/*! \return The renderer's current context target. */ 1042DECLSPEC GPU_Target* SDLCALL GPU_GetContextTarget(void); 1043 1044/*! \return The target that is associated with the given windowID. */ 1045DECLSPEC GPU_Target* SDLCALL GPU_GetWindowTarget(Uint32 windowID); 1046 1047/*! Creates a separate context for the given window using the current renderer and returns a GPU_Target that represents it. */ 1048DECLSPEC GPU_Target* SDLCALL GPU_CreateTargetFromWindow(Uint32 windowID); 1049 1050/*! Makes the given window the current rendering destination for the given context target. 1051 * This also makes the target the current context for image loading and window operations. 1052 * If the target does not represent a window, this does nothing. 1053 */ 1054DECLSPEC void SDLCALL GPU_MakeCurrent(GPU_Target* target, Uint32 windowID); 1055 1056/*! Change the actual size of the current context target's window. This resets the virtual resolution and viewport of the context target. 1057 * Aside from direct resolution changes, this should also be called in response to SDL_WINDOWEVENT_RESIZED window events for resizable windows. */ 1058DECLSPEC GPU_bool SDLCALL GPU_SetWindowResolution(Uint16 w, Uint16 h); 1059 1060/*! Enable/disable fullscreen mode for the current context target's window. 1061 * On some platforms, this may destroy the renderer context and require that textures be reloaded. Unfortunately, SDL does not provide a notification mechanism for this. 1062 * \param enable_fullscreen If true, make the application go fullscreen. If false, make the application go to windowed mode. 1063 * \param use_desktop_resolution If true, lets the window change its resolution when it enters fullscreen mode (via SDL_WINDOW_FULLSCREEN_DESKTOP). 1064 * \return 0 if the new mode is windowed, 1 if the new mode is fullscreen. */ 1065DECLSPEC GPU_bool SDLCALL GPU_SetFullscreen(GPU_bool enable_fullscreen, GPU_bool use_desktop_resolution); 1066 1067/*! Returns true if the current context target's window is in fullscreen mode. */ 1068DECLSPEC GPU_bool SDLCALL GPU_GetFullscreen(void); 1069 1070/*! \return Returns the last active target. */ 1071DECLSPEC GPU_Target* SDLCALL GPU_GetActiveTarget(void); 1072 1073/*! \return Sets the currently active target for matrix modification functions. */ 1074DECLSPEC GPU_bool SDLCALL GPU_SetActiveTarget(GPU_Target* target); 1075 1076/*! Enables/disables alpha blending for shape rendering on the current window. */ 1077DECLSPEC void SDLCALL GPU_SetShapeBlending(GPU_bool enable); 1078 1079/*! Translates a blend preset into a blend mode. */ 1080DECLSPEC GPU_BlendMode SDLCALL GPU_GetBlendModeFromPreset(GPU_BlendPresetEnum preset); 1081 1082/*! Sets the blending component functions for shape rendering. */ 1083DECLSPEC void SDLCALL GPU_SetShapeBlendFunction(GPU_BlendFuncEnum source_color, GPU_BlendFuncEnum dest_color, GPU_BlendFuncEnum source_alpha, GPU_BlendFuncEnum dest_alpha); 1084 1085/*! Sets the blending component equations for shape rendering. */ 1086DECLSPEC void SDLCALL GPU_SetShapeBlendEquation(GPU_BlendEqEnum color_equation, GPU_BlendEqEnum alpha_equation); 1087 1088/*! Sets the blending mode for shape rendering on the current window, if supported by the renderer. */ 1089DECLSPEC void SDLCALL GPU_SetShapeBlendMode(GPU_BlendPresetEnum mode); 1090 1091/*! Sets the thickness of lines for the current context. 1092 * \param thickness New line thickness in pixels measured across the line. Default is 1.0f. 1093 * \return The old thickness value 1094 */ 1095DECLSPEC float SDLCALL GPU_SetLineThickness(float thickness); 1096 1097/*! Returns the current line thickness value. */ 1098DECLSPEC float SDLCALL GPU_GetLineThickness(void); 1099 1100 1101// End of ContextControls 1102/*! @} */ 1103 1104 1105 1106 1107/*! \ingroup TargetControls 1108 * @{ */ 1109 1110 1111 1112/*! Creates a target that aliases the given target. Aliases can be used to store target settings (e.g. viewports) for easy switching. 1113 * GPU_FreeTarget() frees the alias's memory, but does not affect the original. */ 1114DECLSPEC GPU_Target* SDLCALL GPU_CreateAliasTarget(GPU_Target* target); 1115 1116/*! Creates a new render target from the given image. It can then be accessed from image->target. This increments the internal refcount of the target, so it should be matched with a GPU_FreeTarget(). */ 1117DECLSPEC GPU_Target* SDLCALL GPU_LoadTarget(GPU_Image* image); 1118 1119/*! Creates a new render target from the given image. It can then be accessed from image->target. This does not increment the internal refcount of the target, so it will be invalidated when the image is freed. */ 1120DECLSPEC GPU_Target* SDLCALL GPU_GetTarget(GPU_Image* image); 1121 1122/*! Deletes a render target in the proper way for this renderer. */ 1123DECLSPEC void SDLCALL GPU_FreeTarget(GPU_Target* target); 1124 1125/*! Change the logical size of the given target. Rendering to this target will be scaled as if the dimensions were actually the ones given. */ 1126DECLSPEC void SDLCALL GPU_SetVirtualResolution(GPU_Target* target, Uint16 w, Uint16 h); 1127 1128/*! Query the logical size of the given target. */ 1129DECLSPEC void SDLCALL GPU_GetVirtualResolution(GPU_Target* target, Uint16* w, Uint16* h); 1130 1131/*! Converts screen space coordinates (such as from mouse input) to logical drawing coordinates. This interacts with GPU_SetCoordinateMode() when the y-axis is flipped (screen space is assumed to be inverted: (0,0) in the upper-left corner). */ 1132DECLSPEC void SDLCALL GPU_GetVirtualCoords(GPU_Target* target, float* x, float* y, float displayX, float displayY); 1133 1134/*! Reset the logical size of the given target to its original value. */ 1135DECLSPEC void SDLCALL GPU_UnsetVirtualResolution(GPU_Target* target); 1136 1137/*! \return A GPU_Rect with the given values. */ 1138DECLSPEC GPU_Rect SDLCALL GPU_MakeRect(float x, float y, float w, float h); 1139 1140/*! \return An SDL_Color with the given values. */ 1141DECLSPEC SDL_Color SDLCALL GPU_MakeColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a); 1142 1143/*! Sets the given target's viewport. */ 1144DECLSPEC void SDLCALL GPU_SetViewport(GPU_Target* target, GPU_Rect viewport); 1145 1146/*! Resets the given target's viewport to the entire target area. */ 1147DECLSPEC void SDLCALL GPU_UnsetViewport(GPU_Target* target); 1148 1149/*! \return A GPU_Camera with position (0, 0, 0), angle of 0, zoom of 1, centered origin, and near/far clipping planes of -100 and 100. */ 1150DECLSPEC GPU_Camera SDLCALL GPU_GetDefaultCamera(void); 1151 1152/*! \return The camera of the given render target. If target is NULL, returns the default camera. */ 1153DECLSPEC GPU_Camera SDLCALL GPU_GetCamera(GPU_Target* target); 1154 1155/*! Sets the current render target's current camera. 1156 * \param target A pointer to the target that will copy this camera. 1157 * \param cam A pointer to the camera data to use or NULL to use the default camera. 1158 * \return The old camera. */ 1159DECLSPEC GPU_Camera SDLCALL GPU_SetCamera(GPU_Target* target, GPU_Camera* cam); 1160 1161/*! Enables or disables using the built-in camera matrix transforms. */ 1162DECLSPEC void SDLCALL GPU_EnableCamera(GPU_Target* target, GPU_bool use_camera); 1163 1164/*! Returns 1 if the camera transforms are enabled, 0 otherwise. */ 1165DECLSPEC GPU_bool SDLCALL GPU_IsCameraEnabled(GPU_Target* target); 1166 1167/*! Attach a new depth buffer to the given target so that it can use depth testing. Context targets automatically have a depth buffer already. 1168 * If successful, also enables depth testing for this target. 1169 */ 1170DECLSPEC GPU_bool SDLCALL GPU_AddDepthBuffer(GPU_Target* target); 1171 1172/*! Enables or disables the depth test, which will skip drawing pixels/fragments behind other fragments. Disabled by default. 1173 * This has implications for alpha blending, where compositing might not work correctly depending on render order. 1174 */ 1175DECLSPEC void SDLCALL GPU_SetDepthTest(GPU_Target* target, GPU_bool enable); 1176 1177/*! Enables or disables writing the depth (effective view z-coordinate) of new pixels to the depth buffer. Enabled by default, but you must call GPU_SetDepthTest() to use it. */ 1178DECLSPEC void SDLCALL GPU_SetDepthWrite(GPU_Target* target, GPU_bool enable); 1179 1180/*! Sets the operation to perform when depth testing. */ 1181DECLSPEC void SDLCALL GPU_SetDepthFunction(GPU_Target* target, GPU_ComparisonEnum compare_operation); 1182 1183/*! \return The RGBA color of a pixel. */ 1184DECLSPEC SDL_Color SDLCALL GPU_GetPixel(GPU_Target* target, Sint16 x, Sint16 y); 1185 1186/*! Sets the clipping rect for the given render target. */ 1187DECLSPEC GPU_Rect SDLCALL GPU_SetClipRect(GPU_Target* target, GPU_Rect rect); 1188 1189/*! Sets the clipping rect for the given render target. */ 1190DECLSPEC GPU_Rect SDLCALL GPU_SetClip(GPU_Target* target, Sint16 x, Sint16 y, Uint16 w, Uint16 h); 1191 1192/*! Turns off clipping for the given target. */ 1193DECLSPEC void SDLCALL GPU_UnsetClip(GPU_Target* target); 1194 1195/*! Returns GPU_TRUE if the given rects A and B overlap, in which case it also fills the given result rect with the intersection. `result` can be NULL if you don't need the intersection. */ 1196DECLSPEC GPU_bool SDLCALL GPU_IntersectRect(GPU_Rect A, GPU_Rect B, GPU_Rect* result); 1197 1198/*! Returns GPU_TRUE if the given target's clip rect and the given B rect overlap, in which case it also fills the given result rect with the intersection. `result` can be NULL if you don't need the intersection. 1199 * If the target doesn't have a clip rect enabled, this uses the whole target area. 1200 */ 1201DECLSPEC GPU_bool SDLCALL GPU_IntersectClipRect(GPU_Target* target, GPU_Rect B, GPU_Rect* result); 1202 1203/*! Sets the modulation color for subsequent drawing of images and shapes on the given target. 1204 * This has a cumulative effect with the image coloring functions. 1205 * e.g. GPU_SetRGB(image, 255, 128, 0); GPU_SetTargetRGB(target, 128, 128, 128); 1206 * Would make the image draw with color of roughly (128, 64, 0). 1207 */ 1208DECLSPEC void SDLCALL GPU_SetTargetColor(GPU_Target* target, SDL_Color color); 1209 1210/*! Sets the modulation color for subsequent drawing of images and shapes on the given target. 1211 * This has a cumulative effect with the image coloring functions. 1212 * e.g. GPU_SetRGB(image, 255, 128, 0); GPU_SetTargetRGB(target, 128, 128, 128); 1213 * Would make the image draw with color of roughly (128, 64, 0). 1214 */ 1215DECLSPEC void SDLCALL GPU_SetTargetRGB(GPU_Target* target, Uint8 r, Uint8 g, Uint8 b); 1216 1217/*! Sets the modulation color for subsequent drawing of images and shapes on the given target. 1218 * This has a cumulative effect with the image coloring functions. 1219 * e.g. GPU_SetRGB(image, 255, 128, 0); GPU_SetTargetRGB(target, 128, 128, 128); 1220 * Would make the image draw with color of roughly (128, 64, 0). 1221 */ 1222DECLSPEC void SDLCALL GPU_SetTargetRGBA(GPU_Target* target, Uint8 r, Uint8 g, Uint8 b, Uint8 a); 1223 1224/*! Unsets the modulation color for subsequent drawing of images and shapes on the given target. 1225 * This has the same effect as coloring with pure opaque white (255, 255, 255, 255). 1226 */ 1227DECLSPEC void SDLCALL GPU_UnsetTargetColor(GPU_Target* target); 1228 1229// End of TargetControls 1230/*! @} */ 1231 1232 1233 1234/*! \ingroup SurfaceControls 1235 * @{ */ 1236 1237/*! Load surface from an image file that is supported by this renderer. Don't forget to SDL_FreeSurface() it. */ 1238DECLSPEC SDL_Surface* SDLCALL GPU_LoadSurface(const char* filename); 1239 1240/*! Load surface from an image file in memory. Don't forget to SDL_FreeSurface() it. */ 1241DECLSPEC SDL_Surface* SDLCALL GPU_LoadSurface_RW(SDL_RWops* rwops, GPU_bool free_rwops); 1242 1243/*! Save surface to a file. 1244 * With a format of GPU_FILE_AUTO, the file type is deduced from the extension. Supported formats are: png, bmp, tga. 1245 * Returns 0 on failure. */ 1246DECLSPEC GPU_bool SDLCALL GPU_SaveSurface(SDL_Surface* surface, const char* filename, GPU_FileFormatEnum format); 1247 1248/*! Save surface to a RWops stream. 1249 * Does not support format of GPU_FILE_AUTO, because the file type cannot be deduced. Supported formats are: png, bmp, tga. 1250 * Returns 0 on failure. */ 1251DECLSPEC GPU_bool SDLCALL GPU_SaveSurface_RW(SDL_Surface* surface, SDL_RWops* rwops, GPU_bool free_rwops, GPU_FileFormatEnum format); 1252 1253// End of SurfaceControls 1254/*! @} */ 1255 1256 1257 1258 1259/*! \ingroup ImageControls 1260 * @{ */ 1261 1262/*! Create a new, blank image with the given format. Don't forget to GPU_FreeImage() it. 1263 * \param w Image width in pixels 1264 * \param h Image height in pixels 1265 * \param format Format of color channels. 1266 */ 1267DECLSPEC GPU_Image* SDLCALL GPU_CreateImage(Uint16 w, Uint16 h, GPU_FormatEnum format); 1268 1269/*! Create a new image that uses the given native texture handle as the image texture. */ 1270DECLSPEC GPU_Image* SDLCALL GPU_CreateImageUsingTexture(GPU_TextureHandle handle, GPU_bool take_ownership); 1271 1272/*! Load image from an image file that is supported by this renderer. Don't forget to GPU_FreeImage() it. */ 1273DECLSPEC GPU_Image* SDLCALL GPU_LoadImage(const char* filename); 1274 1275/*! Load image from an image file in memory. Don't forget to GPU_FreeImage() it. */ 1276DECLSPEC GPU_Image* SDLCALL GPU_LoadImage_RW(SDL_RWops* rwops, GPU_bool free_rwops); 1277 1278/*! Creates an image that aliases the given image. Aliases can be used to store image settings (e.g. modulation color) for easy switching. 1279 * GPU_FreeImage() frees the alias's memory, but does not affect the original. */ 1280DECLSPEC GPU_Image* SDLCALL GPU_CreateAliasImage(GPU_Image* image); 1281 1282/*! Copy an image to a new image. Don't forget to GPU_FreeImage() both. */ 1283DECLSPEC GPU_Image* SDLCALL GPU_CopyImage(GPU_Image* image); 1284 1285/*! Deletes an image in the proper way for this renderer. Also deletes the corresponding GPU_Target if applicable. Be careful not to use that target afterward! */ 1286DECLSPEC void SDLCALL GPU_FreeImage(GPU_Image* image); 1287 1288/*! Change the logical size of the given image. Rendering this image will scaled it as if the dimensions were actually the ones given. */ 1289DECLSPEC void SDLCALL GPU_SetImageVirtualResolution(GPU_Image* image, Uint16 w, Uint16 h); 1290 1291/*! Reset the logical size of the given image to its original value. */ 1292DECLSPEC void SDLCALL GPU_UnsetImageVirtualResolution(GPU_Image* image); 1293 1294/*! Update an image from surface data. Ignores virtual resolution on the image so the number of pixels needed from the surface is known. */ 1295DECLSPEC void SDLCALL GPU_UpdateImage(GPU_Image* image, const GPU_Rect* image_rect, SDL_Surface* surface, const GPU_Rect* surface_rect); 1296 1297/*! Update an image from an array of pixel data. Ignores virtual resolution on the image so the number of pixels needed from the surface is known. */ 1298DECLSPEC void SDLCALL GPU_UpdateImageBytes(GPU_Image* image, const GPU_Rect* image_rect, const unsigned char* bytes, int bytes_per_row); 1299 1300/*! Update an image from surface data, replacing its underlying texture to allow for size changes. Ignores virtual resolution on the image so the number of pixels needed from the surface is known. */ 1301DECLSPEC GPU_bool SDLCALL GPU_ReplaceImage(GPU_Image* image, SDL_Surface* surface, const GPU_Rect* surface_rect); 1302 1303/*! Save image to a file. 1304 * With a format of GPU_FILE_AUTO, the file type is deduced from the extension. Supported formats are: png, bmp, tga. 1305 * Returns 0 on failure. */ 1306DECLSPEC GPU_bool SDLCALL GPU_SaveImage(GPU_Image* image, const char* filename, GPU_FileFormatEnum format); 1307 1308/*! Save image to a RWops stream. 1309 * Does not support format of GPU_FILE_AUTO, because the file type cannot be deduced. Supported formats are: png, bmp, tga. 1310 * Returns 0 on failure. */ 1311DECLSPEC GPU_bool SDLCALL GPU_SaveImage_RW(GPU_Image* image, SDL_RWops* rwops, GPU_bool free_rwops, GPU_FileFormatEnum format); 1312 1313/*! Loads mipmaps for the given image, if supported by the renderer. */ 1314DECLSPEC void SDLCALL GPU_GenerateMipmaps(GPU_Image* image); 1315 1316/*! Sets the modulation color for subsequent drawing of the given image. */ 1317DECLSPEC void SDLCALL GPU_SetColor(GPU_Image* image, SDL_Color color); 1318 1319/*! Sets the modulation color for subsequent drawing of the given image. */ 1320DECLSPEC void SDLCALL GPU_SetRGB(GPU_Image* image, Uint8 r, Uint8 g, Uint8 b); 1321 1322/*! Sets the modulation color for subsequent drawing of the given image. */ 1323DECLSPEC void SDLCALL GPU_SetRGBA(GPU_Image* image, Uint8 r, Uint8 g, Uint8 b, Uint8 a); 1324 1325/*! Unsets the modulation color for subsequent drawing of the given image. 1326 * This is equivalent to coloring with pure opaque white (255, 255, 255, 255). */ 1327DECLSPEC void SDLCALL GPU_UnsetColor(GPU_Image* image); 1328 1329/*! Gets the current alpha blending setting. */ 1330DECLSPEC GPU_bool SDLCALL GPU_GetBlending(GPU_Image* image); 1331 1332/*! Enables/disables alpha blending for the given image. */ 1333DECLSPEC void SDLCALL GPU_SetBlending(GPU_Image* image, GPU_bool enable); 1334 1335/*! Sets the blending component functions. */ 1336DECLSPEC void SDLCALL GPU_SetBlendFunction(GPU_Image* image, GPU_BlendFuncEnum source_color, GPU_BlendFuncEnum dest_color, GPU_BlendFuncEnum source_alpha, GPU_BlendFuncEnum dest_alpha); 1337 1338/*! Sets the blending component equations. */ 1339DECLSPEC void SDLCALL GPU_SetBlendEquation(GPU_Image* image, GPU_BlendEqEnum color_equation, GPU_BlendEqEnum alpha_equation); 1340 1341/*! Sets the blending mode, if supported by the renderer. */ 1342DECLSPEC void SDLCALL GPU_SetBlendMode(GPU_Image* image, GPU_BlendPresetEnum mode); 1343 1344/*! Sets the image filtering mode, if supported by the renderer. */ 1345DECLSPEC void SDLCALL GPU_SetImageFilter(GPU_Image* image, GPU_FilterEnum filter); 1346 1347/*! Sets the image anchor, which is the point about which the image is blitted. The default is to blit the image on-center (0.5, 0.5). The anchor is in normalized coordinates (0.0-1.0). */ 1348DECLSPEC void SDLCALL GPU_SetAnchor(GPU_Image* image, float anchor_x, float anchor_y); 1349 1350/*! Returns the image anchor via the passed parameters. The anchor is in normalized coordinates (0.0-1.0). */ 1351DECLSPEC void SDLCALL GPU_GetAnchor(GPU_Image* image, float* anchor_x, float* anchor_y); 1352 1353/*! Gets the current pixel snap setting. The default value is GPU_SNAP_POSITION_AND_DIMENSIONS. */ 1354DECLSPEC GPU_SnapEnum SDLCALL GPU_GetSnapMode(GPU_Image* image); 1355 1356/*! Sets the pixel grid snapping mode for the given image. */ 1357DECLSPEC void SDLCALL GPU_SetSnapMode(GPU_Image* image, GPU_SnapEnum mode); 1358 1359/*! Sets the image wrapping mode, if supported by the renderer. */ 1360DECLSPEC void SDLCALL GPU_SetWrapMode(GPU_Image* image, GPU_WrapEnum wrap_mode_x, GPU_WrapEnum wrap_mode_y); 1361 1362/*! Returns the backend-specific texture handle associated with the given image. Note that SDL_gpu will be unaware of changes made to the texture. */ 1363DECLSPEC GPU_TextureHandle SDLCALL GPU_GetTextureHandle(GPU_Image* image); 1364 1365// End of ImageControls 1366/*! @} */ 1367 1368 1369// Surface / Image / Target conversions 1370/*! \ingroup Conversions 1371 * @{ */ 1372 1373/*! Copy SDL_Surface data into a new GPU_Image. Don't forget to SDL_FreeSurface() the surface and GPU_FreeImage() the image.*/ 1374DECLSPEC GPU_Image* SDLCALL GPU_CopyImageFromSurface(SDL_Surface* surface); 1375 1376/*! Like GPU_CopyImageFromSurface but enable to copy only part of the surface.*/ 1377DECLSPEC GPU_Image* SDLCALL GPU_CopyImageFromSurfaceRect(SDL_Surface* surface, GPU_Rect* surface_rect); 1378 1379/*! Copy GPU_Target data into a new GPU_Image. Don't forget to GPU_FreeImage() the image.*/ 1380DECLSPEC GPU_Image* SDLCALL GPU_CopyImageFromTarget(GPU_Target* target); 1381 1382/*! Copy GPU_Target data into a new SDL_Surface. Don't forget to SDL_FreeSurface() the surface.*/ 1383DECLSPEC SDL_Surface* SDLCALL GPU_CopySurfaceFromTarget(GPU_Target* target); 1384 1385/*! Copy GPU_Image data into a new SDL_Surface. Don't forget to SDL_FreeSurface() the surface and GPU_FreeImage() the image.*/ 1386DECLSPEC SDL_Surface* SDLCALL GPU_CopySurfaceFromImage(GPU_Image* image); 1387 1388// End of Conversions 1389/*! @} */ 1390 1391 1392 1393 1394 1395/*! \ingroup Matrix 1396 * @{ */ 1397 1398// Basic vector operations (3D) 1399 1400/*! Returns the magnitude (length) of the given vector. */ 1401DECLSPEC float SDLCALL GPU_VectorLength(const float* vec3); 1402 1403/*! Modifies the given vector so that it has a new length of 1. */ 1404DECLSPEC void SDLCALL GPU_VectorNormalize(float* vec3); 1405 1406/*! Returns the dot product of two vectors. */ 1407DECLSPEC float SDLCALL GPU_VectorDot(const float* A, const float* B); 1408 1409/*! Performs the cross product of vectors A and B (result = A x B). Do not use A or B as 'result'. */ 1410DECLSPEC void SDLCALL GPU_VectorCross(float* result, const float* A, const float* B); 1411 1412/*! Overwrite 'result' vector with the values from vector A. */ 1413DECLSPEC void SDLCALL GPU_VectorCopy(float* result, const float* A); 1414 1415/*! Multiplies the given matrix into the given vector (vec3 = matrix*vec3). */ 1416DECLSPEC void SDLCALL GPU_VectorApplyMatrix(float* vec3, const float* matrix_4x4); 1417 1418/*! Multiplies the given matrix into the given vector (vec4 = matrix*vec4). */ 1419DECLSPEC void SDLCALL GPU_Vector4ApplyMatrix(float* vec4, const float* matrix_4x4); 1420 1421 1422 1423// Basic matrix operations (4x4) 1424 1425/*! Overwrite 'result' matrix with the values from matrix A. */ 1426DECLSPEC void SDLCALL GPU_MatrixCopy(float* result, const float* A); 1427 1428/*! Fills 'result' matrix with the identity matrix. */ 1429DECLSPEC void SDLCALL GPU_MatrixIdentity(float* result); 1430 1431/*! Multiplies an orthographic projection matrix into the given matrix. */ 1432DECLSPEC void SDLCALL GPU_MatrixOrtho(float* result, float left, float right, float bottom, float top, float z_near, float z_far); 1433 1434/*! Multiplies a perspective projection matrix into the given matrix. */ 1435DECLSPEC void SDLCALL GPU_MatrixFrustum(float* result, float left, float right, float bottom, float top, float z_near, float z_far); 1436 1437/*! Multiplies a perspective projection matrix into the given matrix. */ 1438DECLSPEC void SDLCALL GPU_MatrixPerspective(float* result, float fovy, float aspect, float z_near, float z_far); 1439 1440/*! Multiplies a view matrix into the given matrix. */ 1441DECLSPEC void SDLCALL GPU_MatrixLookAt(float* matrix, float eye_x, float eye_y, float eye_z, float target_x, float target_y, float target_z, float up_x, float up_y, float up_z); 1442 1443/*! Adds a translation into the given matrix. */ 1444DECLSPEC void SDLCALL GPU_MatrixTranslate(float* result, float x, float y, float z); 1445 1446/*! Multiplies a scaling matrix into the given matrix. */ 1447DECLSPEC void SDLCALL GPU_MatrixScale(float* result, float sx, float sy, float sz); 1448 1449/*! Multiplies a rotation matrix into the given matrix. */ 1450DECLSPEC void SDLCALL GPU_MatrixRotate(float* result, float degrees, float x, float y, float z); 1451 1452/*! Multiplies matrices A and B and stores the result in the given 'result' matrix (result = A*B). Do not use A or B as 'result'. 1453 * \see GPU_MultiplyAndAssign 1454*/ 1455DECLSPEC void SDLCALL GPU_MatrixMultiply(float* result, const float* A, const float* B); 1456 1457/*! Multiplies matrices 'result' and B and stores the result in the given 'result' matrix (result = result * B). */ 1458DECLSPEC void SDLCALL GPU_MultiplyAndAssign(float* result, const float* B); 1459 1460 1461// Matrix stack accessors 1462 1463/*! Returns an internal string that represents the contents of matrix A. */ 1464DECLSPEC const char* SDLCALL GPU_GetMatrixString(const float* A); 1465 1466/*! Returns the current matrix from the active target. Returns NULL if stack is empty. */ 1467DECLSPEC float* SDLCALL GPU_GetCurrentMatrix(void); 1468 1469/*! Returns the current matrix from the top of the matrix stack. Returns NULL if stack is empty. */ 1470DECLSPEC float* SDLCALL GPU_GetTopMatrix(GPU_MatrixStack* stack); 1471 1472/*! Returns the current model matrix from the active target. Returns NULL if stack is empty. */ 1473DECLSPEC float* SDLCALL GPU_GetModel(void); 1474 1475/*! Returns the current view matrix from the active target. Returns NULL if stack is empty. */ 1476DECLSPEC float* SDLCALL GPU_GetView(void); 1477 1478/*! Returns the current projection matrix from the active target. Returns NULL if stack is empty. */ 1479DECLSPEC float* SDLCALL GPU_GetProjection(void); 1480 1481/*! Copies the current modelview-projection matrix from the active target into the given 'result' matrix (result = P*V*M). */ 1482DECLSPEC void SDLCALL GPU_GetModelViewProjection(float* result); 1483 1484 1485// Matrix stack manipulators 1486 1487/*! Returns a newly allocated matrix stack that has already been initialized. */ 1488DECLSPEC GPU_MatrixStack* SDLCALL GPU_CreateMatrixStack(void); 1489 1490/*! Frees the memory for the matrix stack and any matrices it contains. */ 1491DECLSPEC void SDLCALL GPU_FreeMatrixStack(GPU_MatrixStack* stack); 1492 1493/*! Allocate new matrices for the given stack. */ 1494DECLSPEC void SDLCALL GPU_InitMatrixStack(GPU_MatrixStack* stack); 1495 1496/*! Copies matrices from one stack to another. */ 1497DECLSPEC void SDLCALL GPU_CopyMatrixStack(const GPU_MatrixStack* source, GPU_MatrixStack* dest); 1498 1499/*! Deletes matrices in the given stack. */ 1500DECLSPEC void SDLCALL GPU_ClearMatrixStack(GPU_MatrixStack* stack); 1501 1502/*! Reapplies the default orthographic projection matrix, based on camera and coordinate settings. */ 1503DECLSPEC void SDLCALL GPU_ResetProjection(GPU_Target* target); 1504 1505/*! Sets the active target and changes matrix mode to GPU_PROJECTION, GPU_VIEW, or GPU_MODEL. Further matrix stack operations manipulate that particular stack. */ 1506DECLSPEC void SDLCALL GPU_MatrixMode(GPU_Target* target, int matrix_mode); 1507 1508/*! Copies the given matrix to the active target's projection matrix. */ 1509DECLSPEC void SDLCALL GPU_SetProjection(const float* A); 1510 1511/*! Copies the given matrix to the active target's view matrix. */ 1512DECLSPEC void SDLCALL GPU_SetView(const float* A); 1513 1514/*! Copies the given matrix to the active target's model matrix. */ 1515DECLSPEC void SDLCALL GPU_SetModel(const float* A); 1516 1517/*! Copies the given matrix to the active target's projection matrix. */ 1518DECLSPEC void SDLCALL GPU_SetProjectionFromStack(GPU_MatrixStack* stack); 1519 1520/*! Copies the given matrix to the active target's view matrix. */ 1521DECLSPEC void SDLCALL GPU_SetViewFromStack(GPU_MatrixStack* stack); 1522 1523/*! Copies the given matrix to the active target's model matrix. */ 1524DECLSPEC void SDLCALL GPU_SetModelFromStack(GPU_MatrixStack* stack); 1525 1526/*! Pushes the current matrix as a new matrix stack item to be restored later. */ 1527DECLSPEC void SDLCALL GPU_PushMatrix(void); 1528 1529/*! Removes the current matrix from the stack, restoring the previously pushed matrix. */ 1530DECLSPEC void SDLCALL GPU_PopMatrix(void); 1531 1532/*! Fills current matrix with the identity matrix. */ 1533DECLSPEC void SDLCALL GPU_LoadIdentity(void); 1534 1535/*! Copies a given matrix to be the current matrix. */ 1536DECLSPEC void SDLCALL GPU_LoadMatrix(const float* matrix4x4); 1537 1538/*! Multiplies an orthographic projection matrix into the current matrix. */ 1539DECLSPEC void SDLCALL GPU_Ortho(float left, float right, float bottom, float top, float z_near, float z_far); 1540 1541/*! Multiplies a perspective projection matrix into the current matrix. */ 1542DECLSPEC void SDLCALL GPU_Frustum(float left, float right, float bottom, float top, float z_near, float z_far); 1543 1544/*! Multiplies a perspective projection matrix into the current matrix. */ 1545DECLSPEC void SDLCALL GPU_Perspective(float fovy, float aspect, float z_near, float z_far); 1546 1547/*! Multiplies a view matrix into the current matrix. */ 1548DECLSPEC void SDLCALL GPU_LookAt(float eye_x, float eye_y, float eye_z, float target_x, float target_y, float target_z, float up_x, float up_y, float up_z); 1549 1550/*! Adds a translation into the current matrix. */ 1551DECLSPEC void SDLCALL GPU_Translate(float x, float y, float z); 1552 1553/*! Multiplies a scaling matrix into the current matrix. */ 1554DECLSPEC void SDLCALL GPU_Scale(float sx, float sy, float sz); 1555 1556/*! Multiplies a rotation matrix into the current matrix. */ 1557DECLSPEC void SDLCALL GPU_Rotate(float degrees, float x, float y, float z); 1558 1559/*! Multiplies a given matrix into the current matrix. */ 1560DECLSPEC void SDLCALL GPU_MultMatrix(const float* matrix4x4); 1561 1562// End of Matrix 1563/*! @} */ 1564 1565 1566 1567 1568 1569 1570/*! \ingroup Rendering 1571 * @{ */ 1572 1573/*! Clears the contents of the given render target. Fills the target with color {0, 0, 0, 0}. */ 1574DECLSPEC void SDLCALL GPU_Clear(GPU_Target* target); 1575 1576/*! Fills the given render target with a color. */ 1577DECLSPEC void SDLCALL GPU_ClearColor(GPU_Target* target, SDL_Color color); 1578 1579/*! Fills the given render target with a color (alpha is 255, fully opaque). */ 1580DECLSPEC void SDLCALL GPU_ClearRGB(GPU_Target* target, Uint8 r, Uint8 g, Uint8 b); 1581 1582/*! Fills the given render target with a color. */ 1583DECLSPEC void SDLCALL GPU_ClearRGBA(GPU_Target* target, Uint8 r, Uint8 g, Uint8 b, Uint8 a); 1584 1585/*! Draws the given image to the given render target. 1586 * \param src_rect The region of the source image to use. Pass NULL for the entire image. 1587 * \param x Destination x-position 1588 * \param y Destination y-position */ 1589DECLSPEC void SDLCALL GPU_Blit(GPU_Image* image, GPU_Rect* src_rect, GPU_Target* target, float x, float y); 1590 1591/*! Rotates and draws the given image to the given render target. 1592 * \param src_rect The region of the source image to use. Pass NULL for the entire image. 1593 * \param x Destination x-position 1594 * \param y Destination y-position 1595 * \param degrees Rotation angle (in degrees) */ 1596DECLSPEC void SDLCALL GPU_BlitRotate(GPU_Image* image, GPU_Rect* src_rect, GPU_Target* target, float x, float y, float degrees); 1597 1598/*! Scales and draws the given image to the given render target. 1599 * \param src_rect The region of the source image to use. Pass NULL for the entire image. 1600 * \param x Destination x-position 1601 * \param y Destination y-position 1602 * \param scaleX Horizontal stretch factor 1603 * \param scaleY Vertical stretch factor */ 1604DECLSPEC void SDLCALL GPU_BlitScale(GPU_Image* image, GPU_Rect* src_rect, GPU_Target* target, float x, float y, float scaleX, float scaleY); 1605 1606/*! Scales, rotates, and draws the given image to the given render target. 1607 * \param src_rect The region of the source image to use. Pass NULL for the entire image. 1608 * \param x Destination x-position 1609 * \param y Destination y-position 1610 * \param degrees Rotation angle (in degrees) 1611 * \param scaleX Horizontal stretch factor 1612 * \param scaleY Vertical stretch factor */ 1613DECLSPEC void SDLCALL GPU_BlitTransform(GPU_Image* image, GPU_Rect* src_rect, GPU_Target* target, float x, float y, float degrees, float scaleX, float scaleY); 1614 1615/*! Scales, rotates around a pivot point, and draws the given image to the given render target. The drawing point (x, y) coincides with the pivot point on the src image (pivot_x, pivot_y). 1616 * \param src_rect The region of the source image to use. Pass NULL for the entire image. 1617 * \param x Destination x-position 1618 * \param y Destination y-position 1619 * \param pivot_x Pivot x-position (in image coordinates) 1620 * \param pivot_y Pivot y-position (in image coordinates) 1621 * \param degrees Rotation angle (in degrees) 1622 * \param scaleX Horizontal stretch factor 1623 * \param scaleY Vertical stretch factor */ 1624DECLSPEC void SDLCALL GPU_BlitTransformX(GPU_Image* image, GPU_Rect* src_rect, GPU_Target* target, float x, float y, float pivot_x, float pivot_y, float degrees, float scaleX, float scaleY); 1625 1626/*! Draws the given image to the given render target, scaling it to fit the destination region. 1627 * \param src_rect The region of the source image to use. Pass NULL for the entire image. 1628 * \param dest_rect The region of the destination target image to draw upon. Pass NULL for the entire target. 1629 */ 1630DECLSPEC void SDLCALL GPU_BlitRect(GPU_Image* image, GPU_Rect* src_rect, GPU_Target* target, GPU_Rect* dest_rect); 1631 1632/*! Draws the given image to the given render target, scaling it to fit the destination region. 1633 * \param src_rect The region of the source image to use. Pass NULL for the entire image. 1634 * \param dest_rect The region of the destination target image to draw upon. Pass NULL for the entire target. 1635 * \param degrees Rotation angle (in degrees) 1636 * \param pivot_x Pivot x-position (in image coordinates) 1637 * \param pivot_y Pivot y-position (in image coordinates) 1638 * \param flip_direction A GPU_FlipEnum value (or bitwise OR'd combination) that specifies which direction the image should be flipped. 1639 */ 1640DECLSPEC void SDLCALL GPU_BlitRectX(GPU_Image* image, GPU_Rect* src_rect, GPU_Target* target, GPU_Rect* dest_rect, float degrees, float pivot_x, float pivot_y, GPU_FlipEnum flip_direction); 1641 1642 1643/*! Renders triangles from the given set of vertices. This lets you render arbitrary geometry. It is a direct path to the GPU, so the format is different than typical SDL_gpu calls. 1644 * \param values A tightly-packed array of vertex position (e.g. x,y), texture coordinates (e.g. s,t), and color (e.g. r,g,b,a) values. Texture coordinates and color values are expected to be already normalized to 0.0 - 1.0. Pass NULL to render with only custom shader attributes. 1645 * \param indices If not NULL, this is used to specify which vertices to use and in what order (i.e. it indexes the vertices in the 'values' array). 1646 * \param flags Bit flags to control the interpretation of the 'values' array parameters. 1647 */ 1648DECLSPEC void SDLCALL GPU_TriangleBatch(GPU_Image* image, GPU_Target* target, unsigned short num_vertices, float* values, unsigned int num_indices, unsigned short* indices, GPU_BatchFlagEnum flags); 1649 1650/*! Renders triangles from the given set of vertices. This lets you render arbitrary geometry. It is a direct path to the GPU, so the format is different than typical SDL_gpu calls. 1651 * \param values A tightly-packed array of vertex position (e.g. x,y), texture coordinates (e.g. s,t), and color (e.g. r,g,b,a) values. Texture coordinates and color values are expected to be already normalized to 0.0 - 1.0 (or 0 - 255 for 8-bit color components). Pass NULL to render with only custom shader attributes. 1652 * \param indices If not NULL, this is used to specify which vertices to use and in what order (i.e. it indexes the vertices in the 'values' array). 1653 * \param flags Bit flags to control the interpretation of the 'values' array parameters. 1654 */ 1655DECLSPEC void SDLCALL GPU_TriangleBatchX(GPU_Image* image, GPU_Target* target, unsigned short num_vertices, void* values, unsigned int num_indices, unsigned short* indices, GPU_BatchFlagEnum flags); 1656 1657/*! Renders primitives from the given set of vertices. This lets you render arbitrary geometry. It is a direct path to the GPU, so the format is different than typical SDL_gpu calls. 1658 * \param primitive_type The kind of primitive to render. 1659 * \param values A tightly-packed array of vertex position (e.g. x,y), texture coordinates (e.g. s,t), and color (e.g. r,g,b,a) values. Texture coordinates and color values are expected to be already normalized to 0.0 - 1.0 (or 0 - 255 for 8-bit color components). Pass NULL to render with only custom shader attributes. 1660 * \param indices If not NULL, this is used to specify which vertices to use and in what order (i.e. it indexes the vertices in the 'values' array). 1661 * \param flags Bit flags to control the interpretation of the 'values' array parameters. 1662 */ 1663DECLSPEC void SDLCALL GPU_PrimitiveBatch(GPU_Image* image, GPU_Target* target, GPU_PrimitiveEnum primitive_type, unsigned short num_vertices, float* values, unsigned int num_indices, unsigned short* indices, GPU_BatchFlagEnum flags); 1664 1665/*! Renders primitives from the given set of vertices. This lets you render arbitrary geometry. It is a direct path to the GPU, so the format is different than typical SDL_gpu calls. 1666 * \param primitive_type The kind of primitive to render. 1667 * \param values A tightly-packed array of vertex position (e.g. x,y), texture coordinates (e.g. s,t), and color (e.g. r,g,b,a) values. Texture coordinates and color values are expected to be already normalized to 0.0 - 1.0 (or 0 - 255 for 8-bit color components). Pass NULL to render with only custom shader attributes. 1668 * \param indices If not NULL, this is used to specify which vertices to use and in what order (i.e. it indexes the vertices in the 'values' array). 1669 * \param flags Bit flags to control the interpretation of the 'values' array parameters. 1670 */ 1671DECLSPEC void SDLCALL GPU_PrimitiveBatchV(GPU_Image* image, GPU_Target* target, GPU_PrimitiveEnum primitive_type, unsigned short num_vertices, void* values, unsigned int num_indices, unsigned short* indices, GPU_BatchFlagEnum flags); 1672 1673/*! Send all buffered blitting data to the current context target. */ 1674DECLSPEC void SDLCALL GPU_FlushBlitBuffer(void); 1675 1676/*! Updates the given target's associated window. For non-context targets (e.g. image targets), this will flush the blit buffer. */ 1677DECLSPEC void SDLCALL GPU_Flip(GPU_Target* target); 1678 1679// End of Rendering 1680/*! @} */ 1681 1682 1683 1684 1685 1686/*! \ingroup Shapes 1687 * @{ */ 1688 1689/*! Renders a colored point. 1690 * \param target The destination render target 1691 * \param x x-coord of the point 1692 * \param y y-coord of the point 1693 * \param color The color of the shape to render 1694 */ 1695DECLSPEC void SDLCALL GPU_Pixel(GPU_Target* target, float x, float y, SDL_Color color); 1696 1697/*! Renders a colored line. 1698 * \param target The destination render target 1699 * \param x1 x-coord of starting point 1700 * \param y1 y-coord of starting point 1701 * \param x2 x-coord of ending point 1702 * \param y2 y-coord of ending point 1703 * \param color The color of the shape to render 1704 */ 1705DECLSPEC void SDLCALL GPU_Line(GPU_Target* target, float x1, float y1, float x2, float y2, SDL_Color color); 1706 1707/*! Renders a colored arc curve (circle segment). 1708 * \param target The destination render target 1709 * \param x x-coord of center point 1710 * \param y y-coord of center point 1711 * \param radius The radius of the circle / distance from the center point that rendering will occur 1712 * \param start_angle The angle to start from, in degrees. Measured clockwise from the positive x-axis. 1713 * \param end_angle The angle to end at, in degrees. Measured clockwise from the positive x-axis. 1714 * \param color The color of the shape to render 1715 */ 1716DECLSPEC void SDLCALL GPU_Arc(GPU_Target* target, float x, float y, float radius, float start_angle, float end_angle, SDL_Color color); 1717 1718/*! Renders a colored filled arc (circle segment / pie piece). 1719 * \param target The destination render target 1720 * \param x x-coord of center point 1721 * \param y y-coord of center point 1722 * \param radius The radius of the circle / distance from the center point that rendering will occur 1723 * \param start_angle The angle to start from, in degrees. Measured clockwise from the positive x-axis. 1724 * \param end_angle The angle to end at, in degrees. Measured clockwise from the positive x-axis. 1725 * \param color The color of the shape to render 1726 */ 1727DECLSPEC void SDLCALL GPU_ArcFilled(GPU_Target* target, float x, float y, float radius, float start_angle, float end_angle, SDL_Color color); 1728 1729/*! Renders a colored circle outline. 1730 * \param target The destination render target 1731 * \param x x-coord of center point 1732 * \param y y-coord of center point 1733 * \param radius The radius of the circle / distance from the center point that rendering will occur 1734 * \param color The color of the shape to render 1735 */ 1736DECLSPEC void SDLCALL GPU_Circle(GPU_Target* target, float x, float y, float radius, SDL_Color color); 1737 1738/*! Renders a colored filled circle. 1739 * \param target The destination render target 1740 * \param x x-coord of center point 1741 * \param y y-coord of center point 1742 * \param radius The radius of the circle / distance from the center point that rendering will occur 1743 * \param color The color of the shape to render 1744 */ 1745DECLSPEC void SDLCALL GPU_CircleFilled(GPU_Target* target, float x, float y, float radius, SDL_Color color); 1746 1747/*! Renders a colored ellipse outline. 1748 * \param target The destination render target 1749 * \param x x-coord of center point 1750 * \param y y-coord of center point 1751 * \param rx x-radius of ellipse 1752 * \param ry y-radius of ellipse 1753 * \param degrees The angle to rotate the ellipse 1754 * \param color The color of the shape to render 1755 */ 1756DECLSPEC void SDLCALL GPU_Ellipse(GPU_Target* target, float x, float y, float rx, float ry, float degrees, SDL_Color color); 1757 1758/*! Renders a colored filled ellipse. 1759 * \param target The destination render target 1760 * \param x x-coord of center point 1761 * \param y y-coord of center point 1762 * \param rx x-radius of ellipse 1763 * \param ry y-radius of ellipse 1764 * \param degrees The angle to rotate the ellipse 1765 * \param color The color of the shape to render 1766 */ 1767DECLSPEC void SDLCALL GPU_EllipseFilled(GPU_Target* target, float x, float y, float rx, float ry, float degrees, SDL_Color color); 1768 1769/*! Renders a colored annular sector outline (ring segment). 1770 * \param target The destination render target 1771 * \param x x-coord of center point 1772 * \param y y-coord of center point 1773 * \param inner_radius The inner radius of the ring 1774 * \param outer_radius The outer radius of the ring 1775 * \param start_angle The angle to start from, in degrees. Measured clockwise from the positive x-axis. 1776 * \param end_angle The angle to end at, in degrees. Measured clockwise from the positive x-axis. 1777 * \param color The color of the shape to render 1778 */ 1779DECLSPEC void SDLCALL GPU_Sector(GPU_Target* target, float x, float y, float inner_radius, float outer_radius, float start_angle, float end_angle, SDL_Color color); 1780 1781/*! Renders a colored filled annular sector (ring segment). 1782 * \param target The destination render target 1783 * \param x x-coord of center point 1784 * \param y y-coord of center point 1785 * \param inner_radius The inner radius of the ring 1786 * \param outer_radius The outer radius of the ring 1787 * \param start_angle The angle to start from, in degrees. Measured clockwise from the positive x-axis. 1788 * \param end_angle The angle to end at, in degrees. Measured clockwise from the positive x-axis. 1789 * \param color The color of the shape to render 1790 */ 1791DECLSPEC void SDLCALL GPU_SectorFilled(GPU_Target* target, float x, float y, float inner_radius, float outer_radius, float start_angle, float end_angle, SDL_Color color); 1792 1793/*! Renders a colored triangle outline. 1794 * \param target The destination render target 1795 * \param x1 x-coord of first point 1796 * \param y1 y-coord of first point 1797 * \param x2 x-coord of second point 1798 * \param y2 y-coord of second point 1799 * \param x3 x-coord of third point 1800 * \param y3 y-coord of third point 1801 * \param color The color of the shape to render 1802 */ 1803DECLSPEC void SDLCALL GPU_Tri(GPU_Target* target, float x1, float y1, float x2, float y2, float x3, float y3, SDL_Color color); 1804 1805/*! Renders a colored filled triangle. 1806 * \param target The destination render target 1807 * \param x1 x-coord of first point 1808 * \param y1 y-coord of first point 1809 * \param x2 x-coord of second point 1810 * \param y2 y-coord of second point 1811 * \param x3 x-coord of third point 1812 * \param y3 y-coord of third point 1813 * \param color The color of the shape to render 1814 */ 1815DECLSPEC void SDLCALL GPU_TriFilled(GPU_Target* target, float x1, float y1, float x2, float y2, float x3, float y3, SDL_Color color); 1816 1817/*! Renders a colored rectangle outline. 1818 * \param target The destination render target 1819 * \param x1 x-coord of top-left corner 1820 * \param y1 y-coord of top-left corner 1821 * \param x2 x-coord of bottom-right corner 1822 * \param y2 y-coord of bottom-right corner 1823 * \param color The color of the shape to render 1824 */ 1825DECLSPEC void SDLCALL GPU_Rectangle(GPU_Target* target, float x1, float y1, float x2, float y2, SDL_Color color); 1826 1827/*! Renders a colored rectangle outline. 1828 * \param target The destination render target 1829 * \param rect The rectangular area to draw 1830 * \param color The color of the shape to render 1831 */ 1832DECLSPEC void SDLCALL GPU_Rectangle2(GPU_Target* target, GPU_Rect rect, SDL_Color color); 1833 1834/*! Renders a colored filled rectangle. 1835 * \param target The destination render target 1836 * \param x1 x-coord of top-left corner 1837 * \param y1 y-coord of top-left corner 1838 * \param x2 x-coord of bottom-right corner 1839 * \param y2 y-coord of bottom-right corner 1840 * \param color The color of the shape to render 1841 */ 1842DECLSPEC void SDLCALL GPU_RectangleFilled(GPU_Target* target, float x1, float y1, float x2, float y2, SDL_Color color); 1843 1844/*! Renders a colored filled rectangle. 1845 * \param target The destination render target 1846 * \param rect The rectangular area to draw 1847 * \param color The color of the shape to render 1848 */ 1849DECLSPEC void SDLCALL GPU_RectangleFilled2(GPU_Target* target, GPU_Rect rect, SDL_Color color); 1850 1851/*! Renders a colored rounded (filleted) rectangle outline. 1852 * \param target The destination render target 1853 * \param x1 x-coord of top-left corner 1854 * \param y1 y-coord of top-left corner 1855 * \param x2 x-coord of bottom-right corner 1856 * \param y2 y-coord of bottom-right corner 1857 * \param radius The radius of the corners 1858 * \param color The color of the shape to render 1859 */ 1860DECLSPEC void SDLCALL GPU_RectangleRound(GPU_Target* target, float x1, float y1, float x2, float y2, float radius, SDL_Color color); 1861 1862/*! Renders a colored rounded (filleted) rectangle outline. 1863 * \param target The destination render target 1864 * \param rect The rectangular area to draw 1865 * \param radius The radius of the corners 1866 * \param color The color of the shape to render 1867 */ 1868DECLSPEC void SDLCALL GPU_RectangleRound2(GPU_Target* target, GPU_Rect rect, float radius, SDL_Color color); 1869 1870/*! Renders a colored filled rounded (filleted) rectangle. 1871 * \param target The destination render target 1872 * \param x1 x-coord of top-left corner 1873 * \param y1 y-coord of top-left corner 1874 * \param x2 x-coord of bottom-right corner 1875 * \param y2 y-coord of bottom-right corner 1876 * \param radius The radius of the corners 1877 * \param color The color of the shape to render 1878 */ 1879DECLSPEC void SDLCALL GPU_RectangleRoundFilled(GPU_Target* target, float x1, float y1, float x2, float y2, float radius, SDL_Color color); 1880 1881/*! Renders a colored filled rounded (filleted) rectangle. 1882 * \param target The destination render target 1883 * \param rect The rectangular area to draw 1884 * \param radius The radius of the corners 1885 * \param color The color of the shape to render 1886 */ 1887DECLSPEC void SDLCALL GPU_RectangleRoundFilled2(GPU_Target* target, GPU_Rect rect, float radius, SDL_Color color); 1888 1889/*! Renders a colored polygon outline. The vertices are expected to define a convex polygon. 1890 * \param target The destination render target 1891 * \param num_vertices Number of vertices (x and y pairs) 1892 * \param vertices An array of vertex positions stored as interlaced x and y coords, e.g. {x1, y1, x2, y2, ...} 1893 * \param color The color of the shape to render 1894 */ 1895DECLSPEC void SDLCALL GPU_Polygon(GPU_Target* target, unsigned int num_vertices, float* vertices, SDL_Color color); 1896 1897/*! Renders a colored sequence of line segments. 1898 * \param target The destination render target 1899 * \param num_vertices Number of vertices (x and y pairs) 1900 * \param vertices An array of vertex positions stored as interlaced x and y coords, e.g. {x1, y1, x2, y2, ...} 1901 * \param color The color of the shape to render 1902 * \param close_loop Make a closed polygon by drawing a line at the end back to the start point 1903 */ 1904DECLSPEC void SDLCALL GPU_Polyline(GPU_Target* target, unsigned int num_vertices, float* vertices, SDL_Color color, GPU_bool close_loop); 1905 1906/*! Renders a colored filled polygon. The vertices are expected to define a convex polygon. 1907 * \param target The destination render target 1908 * \param num_vertices Number of vertices (x and y pairs) 1909 * \param vertices An array of vertex positions stored as interlaced x and y coords, e.g. {x1, y1, x2, y2, ...} 1910 * \param color The color of the shape to render 1911 */ 1912DECLSPEC void SDLCALL GPU_PolygonFilled(GPU_Target* target, unsigned int num_vertices, float* vertices, SDL_Color color); 1913 1914// End of Shapes 1915/*! @} */ 1916 1917 1918 1919 1920 1921/*! \ingroup ShaderInterface 1922 * @{ */ 1923 1924/*! Creates a new, empty shader program. You will need to compile shaders, attach them to the program, then link the program. 1925 * \see GPU_AttachShader 1926 * \see GPU_LinkShaderProgram 1927 */ 1928DECLSPEC Uint32 SDLCALL GPU_CreateShaderProgram(void); 1929 1930/*! Deletes a shader program. */ 1931DECLSPEC void SDLCALL GPU_FreeShaderProgram(Uint32 program_object); 1932 1933/*! Loads shader source from an SDL_RWops, compiles it, and returns the new shader object. */ 1934DECLSPEC Uint32 SDLCALL GPU_CompileShader_RW(GPU_ShaderEnum shader_type, SDL_RWops* shader_source, GPU_bool free_rwops); 1935 1936/*! Compiles shader source and returns the new shader object. */ 1937DECLSPEC Uint32 SDLCALL GPU_CompileShader(GPU_ShaderEnum shader_type, const char* shader_source); 1938 1939/*! Loads shader source from a file, compiles it, and returns the new shader object. */ 1940DECLSPEC Uint32 SDLCALL GPU_LoadShader(GPU_ShaderEnum shader_type, const char* filename); 1941 1942/*! Creates and links a shader program with the given shader objects. */ 1943DECLSPEC Uint32 SDLCALL GPU_LinkShaders(Uint32 shader_object1, Uint32 shader_object2); 1944 1945/*! Creates and links a shader program with the given shader objects. */ 1946DECLSPEC Uint32 SDLCALL GPU_LinkManyShaders(Uint32 *shader_objects, int count); 1947 1948/*! Deletes a shader object. */ 1949DECLSPEC void SDLCALL GPU_FreeShader(Uint32 shader_object); 1950 1951/*! Attaches a shader object to a shader program for future linking. */ 1952DECLSPEC void SDLCALL GPU_AttachShader(Uint32 program_object, Uint32 shader_object); 1953 1954/*! Detaches a shader object from a shader program. */ 1955DECLSPEC void SDLCALL GPU_DetachShader(Uint32 program_object, Uint32 shader_object); 1956 1957/*! Links a shader program with any attached shader objects. */ 1958DECLSPEC GPU_bool SDLCALL GPU_LinkShaderProgram(Uint32 program_object); 1959 1960/*! \return The current shader program */ 1961DECLSPEC Uint32 SDLCALL GPU_GetCurrentShaderProgram(void); 1962 1963/*! Returns 1 if the given shader program is a default shader for the current context, 0 otherwise. */ 1964DECLSPEC GPU_bool SDLCALL GPU_IsDefaultShaderProgram(Uint32 program_object); 1965 1966/*! Activates the given shader program. Passing NULL for 'block' will disable the built-in shader variables for custom shaders until a GPU_ShaderBlock is set again. */ 1967DECLSPEC void SDLCALL GPU_ActivateShaderProgram(Uint32 program_object, GPU_ShaderBlock* block); 1968 1969/*! Deactivates the current shader program (activates program 0). */ 1970DECLSPEC void SDLCALL GPU_DeactivateShaderProgram(void); 1971 1972/*! Returns the last shader log message. */ 1973DECLSPEC const char* SDLCALL GPU_GetShaderMessage(void); 1974 1975/*! Returns an integer representing the location of the specified attribute shader variable. */ 1976DECLSPEC int SDLCALL GPU_GetAttributeLocation(Uint32 program_object, const char* attrib_name); 1977 1978/*! Returns a filled GPU_AttributeFormat object. */ 1979DECLSPEC GPU_AttributeFormat SDLCALL GPU_MakeAttributeFormat(int num_elems_per_vertex, GPU_TypeEnum type, GPU_bool normalize, int stride_bytes, int offset_bytes); 1980 1981/*! Returns a filled GPU_Attribute object. */ 1982DECLSPEC GPU_Attribute SDLCALL GPU_MakeAttribute(int location, void* values, GPU_AttributeFormat format); 1983 1984/*! Returns an integer representing the location of the specified uniform shader variable. */ 1985DECLSPEC int SDLCALL GPU_GetUniformLocation(Uint32 program_object, const char* uniform_name); 1986 1987/*! Loads the given shader program's built-in attribute and uniform locations. */ 1988DECLSPEC GPU_ShaderBlock SDLCALL GPU_LoadShaderBlock(Uint32 program_object, const char* position_name, const char* texcoord_name, const char* color_name, const char* modelViewMatrix_name); 1989 1990/*! Sets the current shader block to use the given attribute and uniform locations. */ 1991DECLSPEC void SDLCALL GPU_SetShaderBlock(GPU_ShaderBlock block); 1992 1993/*! Gets the shader block for the current shader. */ 1994DECLSPEC GPU_ShaderBlock SDLCALL GPU_GetShaderBlock(void); 1995 1996/*! Sets the given image unit to the given image so that a custom shader can sample multiple textures. 1997 \param image The source image/texture. Pass NULL to disable the image unit. 1998 \param location The uniform location of a texture sampler 1999 \param image_unit The index of the texture unit to set. 0 is the first unit, which is used by SDL_gpu's blitting functions. 1 would be the second unit. */ 2000DECLSPEC void SDLCALL GPU_SetShaderImage(GPU_Image* image, int location, int image_unit); 2001 2002/*! Fills "values" with the value of the uniform shader variable at the given location. */ 2003DECLSPEC void SDLCALL GPU_GetUniformiv(Uint32 program_object, int location, int* values); 2004 2005/*! Sets the value of the integer uniform shader variable at the given location. 2006 This is equivalent to calling GPU_SetUniformiv(location, 1, 1, &value). */ 2007DECLSPEC void SDLCALL GPU_SetUniformi(int location, int value); 2008 2009/*! Sets the value of the integer uniform shader variable at the given location. */ 2010DECLSPEC void SDLCALL GPU_SetUniformiv(int location, int num_elements_per_value, int num_values, int* values); 2011 2012/*! Fills "values" with the value of the uniform shader variable at the given location. */ 2013DECLSPEC void SDLCALL GPU_GetUniformuiv(Uint32 program_object, int location, unsigned int* values); 2014 2015/*! Sets the value of the unsigned integer uniform shader variable at the given location. 2016 This is equivalent to calling GPU_SetUniformuiv(location, 1, 1, &value). */ 2017DECLSPEC void SDLCALL GPU_SetUniformui(int location, unsigned int value); 2018 2019/*! Sets the value of the unsigned integer uniform shader variable at the given location. */ 2020DECLSPEC void SDLCALL GPU_SetUniformuiv(int location, int num_elements_per_value, int num_values, unsigned int* values); 2021 2022/*! Fills "values" with the value of the uniform shader variable at the given location. */ 2023DECLSPEC void SDLCALL GPU_GetUniformfv(Uint32 program_object, int location, float* values); 2024 2025/*! Sets the value of the floating point uniform shader variable at the given location. 2026 This is equivalent to calling GPU_SetUniformfv(location, 1, 1, &value). */ 2027DECLSPEC void SDLCALL GPU_SetUniformf(int location, float value); 2028 2029/*! Sets the value of the floating point uniform shader variable at the given location. */ 2030DECLSPEC void SDLCALL GPU_SetUniformfv(int location, int num_elements_per_value, int num_values, float* values); 2031 2032/*! Fills "values" with the value of the uniform shader variable at the given location. The results are identical to calling GPU_GetUniformfv(). Matrices are gotten in column-major order. */ 2033DECLSPEC void SDLCALL GPU_GetUniformMatrixfv(Uint32 program_object, int location, float* values); 2034 2035/*! Sets the value of the matrix uniform shader variable at the given location. The size of the matrices sent is specified by num_rows and num_columns. Rows and columns must be between 2 and 4. */ 2036DECLSPEC void SDLCALL GPU_SetUniformMatrixfv(int location, int num_matrices, int num_rows, int num_columns, GPU_bool transpose, float* values); 2037 2038/*! Sets a constant-value shader attribute that will be used for each rendered vertex. */ 2039DECLSPEC void SDLCALL GPU_SetAttributef(int location, float value); 2040 2041/*! Sets a constant-value shader attribute that will be used for each rendered vertex. */ 2042DECLSPEC void SDLCALL GPU_SetAttributei(int location, int value); 2043 2044/*! Sets a constant-value shader attribute that will be used for each rendered vertex. */ 2045DECLSPEC void SDLCALL GPU_SetAttributeui(int location, unsigned int value); 2046 2047/*! Sets a constant-value shader attribute that will be used for each rendered vertex. */ 2048DECLSPEC void SDLCALL GPU_SetAttributefv(int location, int num_elements, float* value); 2049 2050/*! Sets a constant-value shader attribute that will be used for each rendered vertex. */ 2051DECLSPEC void SDLCALL GPU_SetAttributeiv(int location, int num_elements, int* value); 2052 2053/*! Sets a constant-value shader attribute that will be used for each rendered vertex. */ 2054DECLSPEC void SDLCALL GPU_SetAttributeuiv(int location, int num_elements, unsigned int* value); 2055 2056/*! Enables a shader attribute and sets its source data. */ 2057DECLSPEC void SDLCALL GPU_SetAttributeSource(int num_values, GPU_Attribute source); 2058 2059// End of ShaderInterface 2060/*! @} */ 2061 2062 2063#ifdef __cplusplus 2064} 2065#endif 2066 2067#include "close_code.h" 2068 2069 2070#endif 2071