9 #define static_inline static __inline
11 #define static_inline static inline
14 #define static_inline static inline
20 #define snprintf c99_snprintf
27 count = _vsnprintf_s(str, size, _TRUNCATE, format, ap);
29 count = _vscprintf(format, ap);
40 count = c99_vsnprintf(str, size, format, ap);
49 #include "SDL_platform.h"
56 #define GPU_BLIT_BUFFER_VERTICES_PER_SPRITE 4
57 #define GPU_BLIT_BUFFER_INIT_MAX_NUM_VERTICES (GPU_BLIT_BUFFER_VERTICES_PER_SPRITE*1000)
61 #define GPU_BLIT_BUFFER_ABSOLUTE_MAX_VERTICES 60000
63 #define GPU_INDEX_BUFFER_ABSOLUTE_MAX_VERTICES 4000000000u
67 #define GPU_BLIT_BUFFER_FLOATS_PER_VERTEX 8
70 #define GPU_BLIT_BUFFER_STRIDE (sizeof(float)*GPU_BLIT_BUFFER_FLOATS_PER_VERTEX)
71 #define GPU_BLIT_BUFFER_VERTEX_OFFSET 0
72 #define GPU_BLIT_BUFFER_TEX_COORD_OFFSET 2
73 #define GPU_BLIT_BUFFER_COLOR_OFFSET 4
84 #define M_PI 3.14159265358979323846
88 #ifdef SDL_GPU_USE_SDL2
89 #define GET_ALPHA(sdl_color) ((sdl_color).a)
91 #define GET_ALPHA(sdl_color) ((sdl_color).unused)
95 #ifndef GL_VERTEX_SHADER
96 #ifndef SDL_GPU_DISABLE_SHADERS
97 #define SDL_GPU_DISABLE_SHADERS
115 #ifdef SDL_GPU_USE_OPENGL
121 unsigned long extNameLen;
123 extNameLen = strlen(extension_str);
128 unsigned long n = strcspn(p,
" ");
129 if((extNameLen == n) && (strncmp(extension_str, p, n) == 0))
141 #ifdef SDL_GPU_USE_OPENGL
146 #elif defined(SDL_GPU_USE_GLES)
155 #ifdef SDL_GPU_USE_OPENGL
160 #elif defined(SDL_GPU_USE_GLES)
161 #if SDL_GPU_GL_TIER < 3
172 #ifdef SDL_GPU_USE_OPENGL
181 #elif defined(SDL_GPU_USE_GLES)
199 #ifdef SDL_GPU_USE_OPENGL
200 #if SDL_GPU_GL_MAJOR_VERSION > 1
208 #elif defined(SDL_GPU_USE_GLES)
209 #if SDL_GPU_GLES_MAJOR_VERSION > 1
229 #ifdef SDL_GPU_USE_GLES
252 return ((x != 0) && !(x & (x - 1)));
362 unsigned int new_max_num_vertices;
365 if(minimum_vertices_needed <= cdata->blit_buffer_max_num_vertices)
371 new_max_num_vertices = ((
unsigned int)cdata->blit_buffer_max_num_vertices) * 2;
372 while(new_max_num_vertices <= minimum_vertices_needed)
373 new_max_num_vertices *= 2;
381 memcpy(new_buffer, cdata->blit_buffer, cdata->blit_buffer_num_vertices * GPU_BLIT_BUFFER_STRIDE);
382 free(cdata->blit_buffer);
383 cdata->blit_buffer = new_buffer;
384 cdata->blit_buffer_max_num_vertices = new_max_num_vertices;
386 #ifdef SDL_GPU_USE_GL_TIER3
388 #if !defined(SDL_GPU_NO_VAO)
397 #if !defined(SDL_GPU_NO_VAO)
407 unsigned int new_max_num_vertices;
408 unsigned short* new_indices;
410 if(minimum_vertices_needed <= cdata->index_buffer_max_num_vertices)
416 new_max_num_vertices = cdata->index_buffer_max_num_vertices * 2;
417 while(new_max_num_vertices <= minimum_vertices_needed)
418 new_max_num_vertices *= 2;
425 new_indices = (
unsigned short*)malloc(new_max_num_vertices *
sizeof(
unsigned short));
426 memcpy(new_indices, cdata->index_buffer, cdata->index_buffer_num_vertices *
sizeof(
unsigned short));
427 free(cdata->index_buffer);
428 cdata->index_buffer = new_indices;
429 cdata->index_buffer_max_num_vertices = new_max_num_vertices;
443 #ifdef SDL_GPU_USE_SDL2
458 float xFactor = ((float)context_target->
context->
window_w)/context_target->
w;
459 float yFactor = ((float)context_target->
context->
window_h)/context_target->
h;
485 #ifdef SDL_GPU_USE_GL_TIER3
489 if(cdata->last_color.r != color.r
490 || cdata->last_color.g != color.g
491 || cdata->last_color.b != color.b
495 cdata->last_color =
color;
504 if(cdata->last_use_blending == enable)
514 cdata->last_use_blending =
enable;
520 if(cdata->last_blend_mode.source_color == mode.
source_color
521 && cdata->last_blend_mode.dest_color == mode.
dest_color
522 && cdata->last_blend_mode.source_alpha == mode.
source_alpha
523 && cdata->last_blend_mode.dest_alpha == mode.
dest_alpha
530 cdata->last_blend_mode =
mode;
570 if(program_object == 0)
573 return program_object;
624 #define MIX_COLOR_COMPONENT_NORMALIZED_RESULT(a, b) ((a)/255.0f * (b)/255.0f)
625 #define MIX_COLOR_COMPONENT(a, b) (((a)/255.0f * (b)/255.0f)*255)
626 #define MIX_COLORS(color1, color2) {MIX_COLOR_COMPONENT(color1.r, color2.r), MIX_COLOR_COMPONENT(color1.g, color2.g), MIX_COLOR_COMPONENT(color1.b, color2.b), MIX_COLOR_COMPONENT(GET_ALPHA(color1), GET_ALPHA(color2))}
684 if(cdata->last_viewport.x == viewport.
x && cdata->last_viewport.y == viewport.
y && cdata->last_viewport.w == viewport.
w && cdata->last_viewport.h == viewport.
h)
686 cdata->last_viewport = viewport;
690 if(target->
image != NULL)
691 y = target->
image->
h - viewport.
h - viewport.
y;
692 else if(target->
context != NULL)
702 float offsetX, offsetY;
704 cdata->last_camera = target->
camera;
706 cdata->last_camera_inverted =
invert;
720 offsetX = target->
w/2.0f;
721 offsetY = target->
h/2.0f;
746 #ifdef SDL_GPU_APPLY_TRANSFORMS_TO_GL_STACK
747 static void applyTransforms(
void)
760 #ifdef SDL_GPU_USE_OPENGL
762 static Uint8 apply_Intel_attrib_workaround = 0;
763 static Uint8 vendor_is_Intel = 0;
769 #ifdef SDL_GPU_USE_SDL2
775 #ifdef SDL_GPU_USE_OPENGL
776 const char* vendor_string;
789 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
791 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
792 #ifdef SDL_GPU_USE_SDL2
793 #ifdef SDL_GPU_USE_GLES
794 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
796 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, renderer_request.
major_version);
797 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, renderer_request.
minor_version);
800 SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
803 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
805 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
806 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
807 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
808 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
812 #ifdef SDL_GPU_USE_SDL2
824 SDL_flags |= SDL_WINDOW_OPENGL;
825 if(!(SDL_flags & SDL_WINDOW_HIDDEN))
826 SDL_flags |= SDL_WINDOW_SHOWN;
829 window = SDL_CreateWindow(
"",
830 SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
846 SDL_flags |= SDL_OPENGL;
848 screen = SDL_SetVideoMode(w, h, 0, SDL_flags);
858 #ifdef SDL_GPU_USE_SDL2
871 #ifdef SDL_GPU_USE_OPENGL
873 if(strstr(vendor_string,
"Intel") != NULL)
876 apply_Intel_attrib_workaround = 1;
894 #ifdef SDL_GPU_USE_SDL2
899 int framebuffer_handle;
900 SDL_Color white = { 255, 255, 255, 255 };
901 #ifdef SDL_GPU_USE_OPENGL
904 const char* version_string;
906 #ifndef SDL_GPU_DISABLE_SHADERS
912 int blit_buffer_storage_size;
913 int index_buffer_storage_size;
923 target->
image = NULL;
931 cdata->last_image = NULL;
932 cdata->last_target = NULL;
935 cdata->blit_buffer_num_vertices = 0;
937 cdata->blit_buffer = (
float*)malloc(blit_buffer_storage_size);
939 cdata->index_buffer_num_vertices = 0;
941 cdata->index_buffer = (
unsigned short*)malloc(index_buffer_storage_size);
949 #ifdef SDL_GPU_USE_SDL2
951 window = SDL_GetWindowFromID(windowID);
956 free(cdata->blit_buffer);
957 free(cdata->index_buffer);
984 screen = SDL_GetVideoSurface();
989 free(cdata->blit_buffer);
990 free(cdata->index_buffer);
1009 framebuffer_handle = 0;
1033 cdata->last_color = white;
1035 cdata->last_use_texturing = 1;
1039 cdata->last_use_blending = 0;
1042 cdata->last_viewport = target->
viewport;
1043 cdata->last_camera = target->
camera;
1044 cdata->last_camera_inverted = 0;
1046 #ifdef SDL_GPU_USE_OPENGL
1058 #ifdef SDL_GPU_USE_OPENGL
1064 #if SDL_GPU_GL_MAJOR_VERSION != 3
1082 #if SDL_GPU_GLES_MAJOR_VERSION == 1
1096 #ifdef SDL_GPU_USE_GLES
1113 #ifdef SDL_GPU_USE_SDL2
1118 if(SDL_GL_SetSwapInterval(-1) < 0)
1119 SDL_GL_SetSwapInterval(1);
1122 SDL_GL_SetSwapInterval(1);
1124 SDL_GL_SetSwapInterval(0);
1148 #if SDL_GPU_GL_TIER < 3
1162 #ifndef SDL_GPU_DISABLE_SHADERS
1195 #ifdef SDL_GPU_USE_GL_TIER3
1197 cdata->shader_block[0] =
GPU_LoadShaderBlock(p,
"gpu_Vertex",
"gpu_TexCoord",
"gpu_Color",
"gpu_ModelViewProjectionMatrix");
1232 #ifdef SDL_GPU_USE_GL_TIER3
1234 cdata->shader_block[1] =
GPU_LoadShaderBlock(p,
"gpu_Vertex", NULL,
"gpu_Color",
"gpu_ModelViewProjectionMatrix");
1238 #if !defined(SDL_GPU_NO_VAO)
1249 cdata->blit_VBO_flop = 0;
1276 if(target->
image != NULL)
1287 #ifdef SDL_GPU_USE_SDL2
1295 #ifdef SDL_GPU_USE_SDL2
1296 if(target->
image != NULL)
1303 SDL_GL_MakeCurrent(SDL_GetWindowFromID(windowID), c);
1318 window = SDL_GetWindowFromID(windowID);
1334 screen = SDL_GetVideoSurface();
1360 #ifdef SDL_GPU_USE_SDL2
1362 SDL_SetWindowSize(SDL_GetWindowFromID(target->
context->
windowID), w, h);
1366 SDL_Surface*
surf = SDL_GetVideoSurface();
1367 Uint32
flags = surf->flags;
1370 SDL_Surface*
screen = SDL_SetVideoMode(w, h, 0, flags);
1372 screen = SDL_SetVideoMode(w, h, 0, flags);
1437 if(target->
image != NULL)
1442 else if(target->
context != NULL)
1462 #ifdef SDL_GPU_USE_SDL2
1464 Uint32 old_flags = SDL_GetWindowFlags(SDL_GetWindowFromID(target->
context->
windowID));
1465 Uint8 is_fullscreen = (old_flags & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_FULLSCREEN_DESKTOP));
1472 if(use_desktop_resolution)
1473 flags = SDL_WINDOW_FULLSCREEN_DESKTOP;
1475 flags = SDL_WINDOW_FULLSCREEN;
1483 int stored_w, stored_h;
1484 flags = SDL_GetWindowFlags(SDL_GetWindowFromID(target->
context->
windowID));
1485 is_fullscreen = (flags & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_FULLSCREEN_DESKTOP));
1488 if(is_fullscreen && (flags & SDL_WINDOW_FULLSCREEN_DESKTOP))
1499 if(!is_fullscreen && (stored_w != 0 || stored_h != 0))
1505 SDL_GetWindowSize(SDL_GetWindowFromID(target->
context->
windowID), &w, &h);
1514 return is_fullscreen;
1516 SDL_Surface*
surf = SDL_GetVideoSurface();
1519 if(SDL_WM_ToggleFullScreen(surf))
1547 old_camera = target->
camera;
1554 target->
camera = new_camera;
1567 SDL_Color white = { 255, 255, 255, 255 };
1574 bytes_per_pixel = 1;
1579 bytes_per_pixel = 2;
1584 bytes_per_pixel = 3;
1589 bytes_per_pixel = 4;
1594 bytes_per_pixel = 1;
1596 #ifndef SDL_GPU_USE_GLES
1600 bytes_per_pixel = 2;
1606 bytes_per_pixel = 1;
1611 bytes_per_pixel = 1;
1618 if(bytes_per_pixel < 1 || bytes_per_pixel > 4)
1638 #if defined(SDL_GPU_USE_GLES) && (SDL_GPU_GLES_TIER == 1)
1655 result->
color = white;
1666 data->format = gl_format;
1682 static unsigned char* zero_buffer = NULL;
1683 static unsigned int zero_buffer_size = 0;
1714 if(zero_buffer_size < w*h*result->bytes_per_pixel)
1718 zero_buffer = (
unsigned char*)malloc(zero_buffer_size);
1719 memset(zero_buffer, 0, zero_buffer_size);
1723 #ifdef SDL_GPU_USE_OPENGL
1735 #ifdef SDL_GPU_USE_OPENGL
1753 SDL_FreeSurface(surface);
1797 #ifdef SDL_GPU_USE_GLES
1798 Uint8 created_target;
1806 #ifdef SDL_GPU_USE_GLES
1809 if(source->
target == NULL)
1834 int bytes_per_pixel;
1835 unsigned char*
data;
1837 unsigned char* copy;
1843 bytes_per_pixel = 4;
1844 if(target->
image != NULL)
1846 data = (
unsigned char*)malloc(target->
w * target->
h * bytes_per_pixel);
1855 pitch = target->
w * bytes_per_pixel;
1856 copy = (
unsigned char*)malloc(pitch);
1858 for(y = 0; y < target->
h/2; y++)
1860 unsigned char* top = &data[target->
w * y * bytes_per_pixel];
1861 unsigned char*
bottom = &data[target->
w * (target->
h - y - 1) * bytes_per_pixel];
1862 memcpy(copy, top, pitch);
1863 memcpy(top, bottom, pitch);
1864 memcpy(bottom, copy, pitch);
1873 unsigned char*
data;
1892 const char *dot = strrchr(filename,
'.');
1893 if(!dot || dot == filename)
1900 const char* extension;
1902 unsigned char*
data;
1904 if(image == NULL || filename == NULL ||
1920 if(SDL_strcasecmp(extension,
"png") == 0)
1922 else if(SDL_strcasecmp(extension,
"bmp") == 0)
1924 else if(SDL_strcasecmp(extension,
"tga") == 0)
1938 unsigned char*
data;
1947 if(target->
w < 1 || target->
h < 1)
1963 result = SDL_CreateRGBSurfaceFrom(data, target->
w, target->
h, format->BitsPerPixel, target->
w*format->BytesPerPixel, format->Rmask, format->Gmask, format->Bmask, format->Amask);
1971 unsigned char*
data;
1980 if(image->
w < 1 || image->
h < 1)
1996 result = SDL_CreateRGBSurfaceFrom(data, image->
w, image->
h, format->BitsPerPixel, image->
w*format->BytesPerPixel, format->Rmask, format->Gmask, format->Bmask, format->Amask);
2018 #ifdef SDL_GPU_USE_GLES
2022 SDL_PixelFormat*
format = surface->format;
2027 if(format->BytesPerPixel != 3)
2030 if(format->Rmask == 0x0000FF && format->Gmask == 0x00FF00 && format->Bmask == 0xFF0000)
2032 if(surfaceFormatResult != NULL)
2033 *surfaceFormatResult =
GL_RGB;
2037 if(format->Rmask == 0xFF0000 && format->Gmask == 0x00FF00 && format->Bmask == 0x0000FF)
2041 if(surfaceFormatResult != NULL)
2042 *surfaceFormatResult =
GL_BGR;
2050 if(format->BytesPerPixel != 4)
2053 if (format->Rmask == 0x000000FF && format->Gmask == 0x0000FF00 && format->Bmask == 0x00FF0000)
2055 if(surfaceFormatResult != NULL)
2056 *surfaceFormatResult =
GL_RGBA;
2060 if (format->Rmask == 0x00FF0000 && format->Gmask == 0x0000FF00 && format->Bmask == 0x000000FF)
2064 if(surfaceFormatResult != NULL)
2065 *surfaceFormatResult =
GL_BGRA;
2071 if (format->Rmask == 0xFF000000 && format->Gmask == 0x00FF0000 && format->Bmask == 0x0000FF00)
2075 if(surfaceFormatResult != NULL)
2076 *surfaceFormatResult = GL_ABGR;
2091 SDL_PixelFormat* format = surface->format;
2096 if(format->BytesPerPixel != 3)
2100 if(format->Rmask == 0x0000FF && format->Gmask == 0x00FF00 && format->Bmask == 0xFF0000)
2102 if(surfaceFormatResult != NULL)
2103 *surfaceFormatResult =
GL_RGB;
2107 if(format->Rmask == 0xFF0000 && format->Gmask == 0x00FF00 && format->Bmask == 0x0000FF)
2112 if(surfaceFormatResult != NULL)
2113 *surfaceFormatResult =
GL_BGR;
2123 if(format->BytesPerPixel != 4)
2127 if(format->Rmask == 0x000000FF && format->Gmask == 0x0000FF00 && format->Bmask == 0x00FF0000)
2129 if(surfaceFormatResult != NULL)
2130 *surfaceFormatResult =
GL_RGBA;
2134 if(format->Rmask == 0xFF000000 && format->Gmask == 0x00FF0000 && format->Bmask == 0x0000FF00)
2139 if(surfaceFormatResult != NULL)
2140 *surfaceFormatResult = GL_ABGR;
2146 else if(format->Rmask == 0x00FF0000 && format->Gmask == 0x0000FF00 && format->Bmask == 0x000000FF)
2152 if(surfaceFormatResult != NULL)
2153 *surfaceFormatResult =
GL_BGRA;
2172 Uint32 Rmask, Gmask, Bmask, Amask = 0,
mask;
2222 result = (SDL_PixelFormat*)malloc(
sizeof(SDL_PixelFormat));
2223 memset(result, 0,
sizeof(SDL_PixelFormat));
2225 result->BitsPerPixel = 8*channels;
2226 result->BytesPerPixel = channels;
2228 result->Rmask = Rmask;
2238 result->Gmask = Gmask;
2248 result->Bmask = Bmask;
2258 result->Amask = Amask;
2273 #ifdef SDL_GPU_USE_SDL2
2274 return (SDL_GetColorKey(surface, NULL) == 0);
2276 return (surface->flags & SDL_SRCCOLORKEY);
2288 #ifdef SDL_GPU_USE_GLES
2289 SDL_Surface* newSurface;
2297 int format_compare =
compareFormats(renderer, glFormat, surface, surfaceFormatResult);
2300 if(format_compare < 0)
2303 #ifdef SDL_GPU_USE_GLES
2310 rect.w = surface->w;
2311 rect.h = surface->h;
2312 srcPitch = rect.w * surface->format->BytesPerPixel;
2313 pitch = surface->pitch;
2314 if(srcPitch != pitch)
2317 Uint8 *
pixels = (Uint8*)surface->pixels;
2321 if(rect.w <= 0 || rect.h <= 0)
2326 if(pitch != srcPitch)
2328 blob = (Uint8*)malloc(srcPitch * rect.h);
2335 for(
y = 0;
y < rect.h; ++
y)
2337 memcpy(src, pixels, srcPitch);
2344 newSurface = SDL_CreateRGBSurfaceFrom(src, rect.w, rect.h, surface->format->BytesPerPixel, srcPitch, surface->format->Rmask, surface->format->Gmask, surface->format->Bmask, surface->format->Amask);
2348 if(format_compare > 0)
2352 if(newSurface != NULL)
2354 surface = SDL_ConvertSurface(newSurface, dst_fmt, 0);
2355 SDL_FreeSurface(newSurface);
2359 surface = SDL_ConvertSurface(surface, dst_fmt, 0);
2361 if(surfaceFormatResult != NULL && surface != NULL)
2362 *surfaceFormatResult = glFormat;
2367 if(format_compare > 0)
2371 surface = SDL_ConvertSurface(surface, dst_fmt, 0);
2373 if(surfaceFormatResult != NULL && surface != NULL)
2374 *surfaceFormatResult = glFormat;
2424 renderer->
Blit(renderer, image, NULL, target, image->
w / 2, image->
h / 2);
2446 if(texture_data == NULL)
2475 #ifdef SDL_GPU_USE_OPENGL
2487 #ifdef SDL_GPU_USE_OPENGL
2520 renderer->
UpdateSubImage(renderer, image, NULL, surface, surface_rect);
2529 SDL_Surface* newSurface;
2535 if(image == NULL || surface == NULL)
2539 original_format = data->format;
2542 if(newSurface == NULL)
2548 if(image_rect != NULL)
2550 updateRect = *image_rect;
2551 if(updateRect.
x < 0)
2553 updateRect.
w += updateRect.
x;
2556 if(updateRect.
y < 0)
2558 updateRect.
h += updateRect.
y;
2561 if(updateRect.
x + updateRect.
w > image->
w)
2562 updateRect.
w += image->
w - (updateRect.
x + updateRect.
w);
2563 if(updateRect.
y + updateRect.
h > image->
h)
2564 updateRect.
h += image->
h - (updateRect.
y + updateRect.
h);
2566 if(updateRect.
w <= 0)
2568 if(updateRect.
h <= 0)
2575 updateRect.
w = image->
w;
2576 updateRect.
h = image->
h;
2577 if(updateRect.
w < 0.0f || updateRect.
h < 0.0f)
2584 if(surface_rect != NULL)
2586 sourceRect = *surface_rect;
2587 if(sourceRect.
x < 0)
2589 sourceRect.
w += sourceRect.
x;
2592 if(sourceRect.
y < 0)
2594 sourceRect.
h += sourceRect.
y;
2597 if(sourceRect.
x + sourceRect.
w > newSurface->w)
2598 sourceRect.
w += newSurface->w - (sourceRect.
x + sourceRect.
w);
2599 if(sourceRect.
y + sourceRect.
h > newSurface->h)
2600 sourceRect.
h += newSurface->h - (sourceRect.
y + sourceRect.
h);
2602 if(sourceRect.
w <= 0)
2604 if(sourceRect.
h <= 0)
2611 sourceRect.
w = newSurface->w;
2612 sourceRect.
h = newSurface->h;
2621 if(newSurface->format->BytesPerPixel == 4)
2624 #ifdef SDL_GPU_USE_OPENGL
2629 if(sourceRect.
w < updateRect.
w)
2630 updateRect.
w = sourceRect.
w;
2631 if(sourceRect.
h < updateRect.
h)
2632 updateRect.
h = sourceRect.
h;
2634 pixels = (Uint8*)newSurface->pixels;
2636 pixels += (
int)(newSurface->pitch * sourceRect.
y + (newSurface->format->BytesPerPixel)*sourceRect.
x);
2639 updateRect.
x, updateRect.
y, updateRect.
w, updateRect.
h,
2643 if(surface != newSurface)
2644 SDL_FreeSurface(newSurface);
2648 #ifdef SDL_GPU_USE_OPENGL
2662 if(image == NULL || bytes == NULL)
2666 original_format = data->format;
2668 if(image_rect != NULL)
2670 updateRect = *image_rect;
2671 if(updateRect.
x < 0)
2673 updateRect.
w += updateRect.
x;
2676 if(updateRect.
y < 0)
2678 updateRect.
h += updateRect.
y;
2681 if(updateRect.
x + updateRect.
w > image->
w)
2682 updateRect.
w += image->
w - (updateRect.
x + updateRect.
w);
2683 if(updateRect.
y + updateRect.
h > image->
h)
2684 updateRect.
h += image->
h - (updateRect.
y + updateRect.
h);
2686 if(updateRect.
w <= 0)
2688 if(updateRect.
h <= 0)
2695 updateRect.
w = image->
w;
2696 updateRect.
h = image->
h;
2697 if(updateRect.
w < 0.0f || updateRect.
h < 0.0f)
2711 #ifdef SDL_GPU_USE_OPENGL
2716 updateRect.
x, updateRect.
y, updateRect.
w, updateRect.
h,
2721 #ifdef SDL_GPU_USE_OPENGL
2735 bpp = Surface->format->BytesPerPixel;
2736 bits = ((Uint8*)Surface->pixels) + y*Surface->pitch + x*bpp;
2741 return *((Uint8*)Surface->pixels + y * Surface->pitch + x);
2744 return *((Uint16*)Surface->pixels + y * Surface->pitch/2 + x);
2750 r = *((bits)+Surface->format->Rshift/8);
2751 g = *((bits)+Surface->format->Gshift/8);
2752 b = *((bits)+Surface->format->Bshift/8);
2753 return SDL_MapRGB(Surface->format, r, g, b);
2757 return *((Uint32*)Surface->pixels + y * Surface->pitch/4 + x);
2776 if(surface->format->Amask == 0)
2786 image = renderer->
CreateImage(renderer, surface->w, surface->h, format);
2790 renderer->
UpdateImage(renderer, image, surface, NULL);
2798 SDL_Surface* surface;
2806 SDL_FreeSurface(surface);
2826 if(image->
target != NULL)
2837 if(data->refcount > 1)
2862 if(image->
target != NULL)
2895 result->
w = image->
w;
2896 result->
h = image->
h;
2935 free(cdata->blit_buffer);
2936 free(cdata->index_buffer);
2938 #ifdef SDL_GPU_USE_SDL2
2970 if(data->refcount > 1)
2981 if(data->handle != 0)
2989 free(cdata->blit_buffer);
2990 free(cdata->index_buffer);
2992 #ifdef SDL_GPU_USE_SDL2
2997 #ifdef SDL_GPU_USE_GL_TIER3
3000 #if !defined(SDL_GPU_NO_VAO)
3021 #define SET_TEXTURED_VERTEX(x, y, s, t, r, g, b, a) \
3022 blit_buffer[vert_index] = x; \
3023 blit_buffer[vert_index+1] = y; \
3024 blit_buffer[tex_index] = s; \
3025 blit_buffer[tex_index+1] = t; \
3026 blit_buffer[color_index] = r; \
3027 blit_buffer[color_index+1] = g; \
3028 blit_buffer[color_index+2] = b; \
3029 blit_buffer[color_index+3] = a; \
3030 index_buffer[cdata->index_buffer_num_vertices++] = cdata->blit_buffer_num_vertices++; \
3031 vert_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; \
3032 tex_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; \
3033 color_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX;
3035 #define SET_TEXTURED_VERTEX_UNINDEXED(x, y, s, t, r, g, b, a) \
3036 blit_buffer[vert_index] = x; \
3037 blit_buffer[vert_index+1] = y; \
3038 blit_buffer[tex_index] = s; \
3039 blit_buffer[tex_index+1] = t; \
3040 blit_buffer[color_index] = r; \
3041 blit_buffer[color_index+1] = g; \
3042 blit_buffer[color_index+2] = b; \
3043 blit_buffer[color_index+3] = a; \
3044 vert_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; \
3045 tex_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; \
3046 color_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX;
3048 #define SET_UNTEXTURED_VERTEX(x, y, r, g, b, a) \
3049 blit_buffer[vert_index] = x; \
3050 blit_buffer[vert_index+1] = y; \
3051 blit_buffer[color_index] = r; \
3052 blit_buffer[color_index+1] = g; \
3053 blit_buffer[color_index+2] = b; \
3054 blit_buffer[color_index+3] = a; \
3055 index_buffer[cdata->index_buffer_num_vertices++] = cdata->blit_buffer_num_vertices++; \
3056 vert_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; \
3057 color_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX;
3059 #define SET_UNTEXTURED_VERTEX_UNINDEXED(x, y, r, g, b, a) \
3060 blit_buffer[vert_index] = x; \
3061 blit_buffer[vert_index+1] = y; \
3062 blit_buffer[color_index] = r; \
3063 blit_buffer[color_index+1] = g; \
3064 blit_buffer[color_index+2] = b; \
3065 blit_buffer[color_index+3] = a; \
3066 vert_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; \
3067 color_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX;
3069 #define SET_INDEXED_VERTEX(offset) \
3070 index_buffer[cdata->index_buffer_num_vertices++] = blit_buffer_starting_index + (offset);
3076 Uint16 tex_w, tex_h;
3079 float x1, y1, x2, y2;
3080 float dx1, dy1, dx2, dy2;
3083 unsigned short* index_buffer;
3084 unsigned short blit_buffer_starting_index;
3136 if(src_rect == NULL)
3141 x2 = ((float)image->
w)/tex_w;
3142 y2 = ((float)image->
h)/tex_h;
3149 x1 = src_rect->
x/(float)tex_w;
3150 y1 = src_rect->
y/(float)tex_h;
3151 x2 = (src_rect->
x + src_rect->
w)/(
float)tex_w;
3152 y2 = (src_rect->
y + src_rect->
h)/(
float)tex_h;
3166 fractional = w/2.0f - floorf(w/2.0
f);
3169 fractional = h/2.0f - floorf(h/2.0
f);
3176 if(cdata->blit_buffer_num_vertices + 4 >= cdata->blit_buffer_max_num_vertices)
3181 if(cdata->index_buffer_num_vertices + 6 >= cdata->index_buffer_max_num_vertices)
3187 blit_buffer = cdata->blit_buffer;
3188 index_buffer = cdata->index_buffer;
3190 blit_buffer_starting_index = cdata->blit_buffer_num_vertices;
3204 r = image->
color.r/255.0f;
3205 g = image->
color.g/255.0f;
3206 b = image->
color.b/255.0f;
3243 w = (src_rect == NULL? image->
w : src_rect->
w);
3244 h = (src_rect == NULL? image->
h : src_rect->
h);
3245 renderer->
BlitTransformX(renderer, image, src_rect, target, x, y, w/2.0
f, h/2.0
f, degrees, 1.0
f, 1.0
f);
3262 w = (src_rect == NULL? image->
w : src_rect->
w);
3263 h = (src_rect == NULL? image->
h : src_rect->
h);
3264 renderer->
BlitTransformX(renderer, image, src_rect, target, x, y, w/2.0
f, h/2.0
f, 0.0
f, scaleX, scaleY);
3281 w = (src_rect == NULL? image->
w : src_rect->
w);
3282 h = (src_rect == NULL? image->
h : src_rect->
h);
3283 renderer->
BlitTransformX(renderer, image, src_rect, target, x, y, w/2.0
f, h/2.0
f, degrees, scaleX, scaleY);
3286 static void BlitTransformX(
GPU_Renderer* renderer,
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)
3288 Uint16 tex_w, tex_h;
3289 float x1, y1, x2, y2;
3290 float dx1, dy1, dx2, dy2, dx3, dy3, dx4, dy4;
3294 unsigned short* index_buffer;
3295 unsigned short blit_buffer_starting_index;
3349 if(src_rect == NULL)
3354 x2 = ((float)image->
w)/tex_w;
3355 y2 = ((float)image->
h)/tex_h;
3362 x1 = src_rect->
x/(float)tex_w;
3363 y1 = src_rect->
y/(float)tex_h;
3364 x2 = (src_rect->
x + src_rect->
w)/(
float)tex_w;
3365 y2 = (src_rect->
y + src_rect->
h)/(
float)tex_h;
3380 fractional = w/2.0f - floorf(w/2.0
f);
3383 fractional = h/2.0f - floorf(h/2.0
f);
3391 if(scaleX != 1.0
f || scaleY != 1.0
f)
3393 float w = (dx2 - dx1)*scaleX;
3394 float h = (dy2 - dy1)*scaleY;
3395 dx1 = (dx2 + dx1)/2 - w/2;
3397 dy1 = (dy2 + dy1)/2 - h/2;
3406 dx1 -= pivot_x*scaleX;
3407 dy1 -= pivot_y*scaleY;
3408 dx2 -= pivot_x*scaleX;
3409 dy2 -= pivot_y*scaleY;
3420 float cosA = cos(degrees*
M_PI/180);
3421 float sinA = sin(degrees*
M_PI/180);
3423 dx1 = dx1*cosA - dy1*sinA;
3424 dy1 = tempX*sinA + dy1*cosA;
3426 dx2 = dx2*cosA - dy2*sinA;
3427 dy2 = tempX*sinA + dy2*cosA;
3429 dx3 = dx3*cosA - dy3*sinA;
3430 dy3 = tempX*sinA + dy3*cosA;
3432 dx4 = dx4*cosA - dy4*sinA;
3433 dy4 = tempX*sinA + dy4*cosA;
3448 if(cdata->blit_buffer_num_vertices + 4 >= cdata->blit_buffer_max_num_vertices)
3453 if(cdata->index_buffer_num_vertices + 6 >= cdata->index_buffer_max_num_vertices)
3459 blit_buffer = cdata->blit_buffer;
3460 index_buffer = cdata->index_buffer;
3462 blit_buffer_starting_index = cdata->blit_buffer_num_vertices;
3477 r = image->
color.r/255.0f;
3478 g = image->
color.g/255.0f;
3479 b = image->
color.b/255.0f;
3527 float matrix[16] = {matrix3x3[0], matrix3x3[1], matrix3x3[2], 0,
3528 matrix3x3[3], matrix3x3[4], matrix3x3[5], 0,
3529 0, 0, matrix3x3[8], 0,
3530 matrix3x3[6], matrix3x3[7], 0, 1
3536 renderer->
Blit(renderer, image, src_rect, target, 0, 0);
3547 #ifdef SDL_GPU_USE_GL_TIER3
3566 for(i = 0; i < 16; i++)
3578 memcpy(storage_ptr, values_ptr, value_size_bytes);
3580 memcpy(storage_ptr, values_ptr, value_size_bytes);
3582 memcpy(storage_ptr, values_ptr, value_size_bytes);
3584 memcpy(storage_ptr, values_ptr, value_size_bytes);
3593 static void upload_attribute_data(
GPU_CONTEXT_DATA* cdata,
int num_vertices)
3596 for(i = 0; i < 16; i++)
3601 int num_values_used = num_vertices;
3629 for(i = 0; i < 16; i++)
3646 #ifdef SDL_GPU_USE_GL_TIER3
3648 for(i = 0; i < 16; i++)
3668 unsigned short* index_buffer;
3708 #ifdef SDL_GPU_APPLY_TRANSFORMS_TO_GL_STACK
3718 if(cdata->blit_buffer_num_vertices + num_sprites*4 >= cdata->blit_buffer_max_num_vertices)
3720 if(!
growBlitBuffer(cdata, cdata->blit_buffer_num_vertices + num_sprites*4))
3723 num_sprites = (cdata->blit_buffer_max_num_vertices - cdata->blit_buffer_num_vertices)/4;
3726 if(cdata->index_buffer_num_vertices + num_sprites*6 >= cdata->index_buffer_max_num_vertices)
3728 if(!
growIndexBuffer(cdata, cdata->index_buffer_num_vertices + num_sprites*6))
3731 num_sprites = (cdata->index_buffer_max_num_vertices - cdata->index_buffer_num_vertices)/6;
3735 index_buffer = cdata->index_buffer;
3737 #ifdef SDL_GPU_USE_GL_TIER3
3738 refresh_attribute_data(cdata);
3742 for(i = 0; i < num_sprites; i++)
3744 int buffer_num_vertices = i*4;
3746 index_buffer[cdata->index_buffer_num_vertices++] = buffer_num_vertices;
3747 index_buffer[cdata->index_buffer_num_vertices++] = buffer_num_vertices+1;
3748 index_buffer[cdata->index_buffer_num_vertices++] = buffer_num_vertices+2;
3751 index_buffer[cdata->index_buffer_num_vertices++] = buffer_num_vertices;
3752 index_buffer[cdata->index_buffer_num_vertices++] = buffer_num_vertices+2;
3753 index_buffer[cdata->index_buffer_num_vertices++] = buffer_num_vertices+3;
3756 #ifdef SDL_GPU_USE_GL_TIER1
3759 float* vertex_pointer =
values;
3764 for(i = 0; i < num_sprites; i++)
3766 glColor4f( *color_pointer, *(color_pointer+1), *(color_pointer+2), *(color_pointer+3) );
3767 glTexCoord2f( *texcoord_pointer, *(texcoord_pointer+1) );
3768 glVertex3f( *vertex_pointer, *(vertex_pointer+1), 0.0
f );
3773 glColor4f( *color_pointer, *(color_pointer+1), *(color_pointer+2), *(color_pointer+3) );
3774 glTexCoord2f( *texcoord_pointer, *(texcoord_pointer+1) );
3775 glVertex3f( *vertex_pointer, *(vertex_pointer+1), 0.0
f );
3780 glColor4f( *color_pointer, *(color_pointer+1), *(color_pointer+2), *(color_pointer+3) );
3781 glTexCoord2f( *texcoord_pointer, *(texcoord_pointer+1) );
3782 glVertex3f( *vertex_pointer, *(vertex_pointer+1), 0.0
f );
3787 glColor4f( *color_pointer, *(color_pointer+1), *(color_pointer+2), *(color_pointer+3) );
3788 glTexCoord2f( *texcoord_pointer, *(texcoord_pointer+1) );
3789 glVertex3f( *vertex_pointer, *(vertex_pointer+1), 0.0
f );
3796 #elif defined(SDL_GPU_USE_GL_TIER2)
3803 int stride = 8*
sizeof(float);
3815 #elif defined(SDL_GPU_USE_GL_TIER3)
3818 if(cdata->current_shader_block.modelViewProjection_loc >= 0)
3826 #if !defined(SDL_GPU_NO_VAO)
3834 cdata->blit_VBO_flop = !cdata->blit_VBO_flop;
3840 if(cdata->current_shader_block.position_loc >= 0)
3845 if(cdata->current_shader_block.texcoord_loc >= 0)
3850 if(cdata->current_shader_block.color_loc >= 0)
3857 upload_attribute_data(cdata, num_sprites*4);
3862 if(cdata->current_shader_block.position_loc >= 0)
3864 if(cdata->current_shader_block.texcoord_loc >= 0)
3866 if(cdata->current_shader_block.color_loc >= 0)
3869 disable_attribute_data(cdata);
3871 #if !defined(SDL_GPU_NO_VAO)
3877 cdata->blit_buffer_num_vertices = 0;
3878 cdata->index_buffer_num_vertices = 0;
3889 if(num_vertices == 0)
3929 #ifdef SDL_GPU_APPLY_TRANSFORMS_TO_GL_STACK
3939 if(cdata->index_buffer_num_vertices + num_indices >= cdata->index_buffer_max_num_vertices)
3941 growBlitBuffer(cdata, cdata->index_buffer_num_vertices + num_indices);
3943 if(cdata->blit_buffer_num_vertices + num_vertices >= cdata->blit_buffer_max_num_vertices)
3945 growBlitBuffer(cdata, cdata->blit_buffer_num_vertices + num_vertices);
3949 if(cdata->blit_buffer_num_vertices + num_vertices >= cdata->blit_buffer_max_num_vertices)
3951 if(!
growBlitBuffer(cdata, cdata->blit_buffer_num_vertices + num_vertices))
3954 num_vertices = (cdata->blit_buffer_max_num_vertices - cdata->blit_buffer_num_vertices);
3957 if(cdata->index_buffer_num_vertices + num_indices >= cdata->index_buffer_max_num_vertices)
3959 if(!
growIndexBuffer(cdata, cdata->index_buffer_num_vertices + num_indices))
3962 num_indices = (cdata->index_buffer_max_num_vertices - cdata->index_buffer_num_vertices);
3966 #ifdef SDL_GPU_USE_GL_TIER3
3967 refresh_attribute_data(cdata);
3973 num_indices = num_vertices;
3976 #ifdef SDL_GPU_USE_GL_TIER1
3980 float* vertex_pointer =
values;
3981 float* texcoord_pointer = values + 2;
3982 float* color_pointer = values + 4;
3985 for(i = 0; i < num_vertices; i+=3)
3987 glColor4f( *color_pointer, *(color_pointer+1), *(color_pointer+2), *(color_pointer+3) );
3988 glTexCoord2f( *texcoord_pointer, *(texcoord_pointer+1) );
3989 glVertex3f( *vertex_pointer, *(vertex_pointer+1), 0.0
f );
3994 glColor4f( *color_pointer, *(color_pointer+1), *(color_pointer+2), *(color_pointer+3) );
3995 glTexCoord2f( *texcoord_pointer, *(texcoord_pointer+1) );
3996 glVertex3f( *vertex_pointer, *(vertex_pointer+1), 0.0
f );
4001 glColor4f( *color_pointer, *(color_pointer+1), *(color_pointer+2), *(color_pointer+3) );
4002 glTexCoord2f( *texcoord_pointer, *(texcoord_pointer+1) );
4003 glVertex3f( *vertex_pointer, *(vertex_pointer+1), 0.0
f );
4008 glColor4f( *color_pointer, *(color_pointer+1), *(color_pointer+2), *(color_pointer+3) );
4009 glTexCoord2f( *texcoord_pointer, *(texcoord_pointer+1) );
4010 glVertex3f( *vertex_pointer, *(vertex_pointer+1), 0.0
f );
4017 #elif defined(SDL_GPU_USE_GL_TIER2)
4036 #elif defined(SDL_GPU_USE_GL_TIER3)
4039 if(cdata->current_shader_block.modelViewProjection_loc >= 0)
4047 #if !defined(SDL_GPU_NO_VAO)
4055 cdata->blit_VBO_flop = !cdata->blit_VBO_flop;
4061 if(cdata->current_shader_block.position_loc >= 0)
4066 if(cdata->current_shader_block.texcoord_loc >= 0)
4071 if(cdata->current_shader_block.color_loc >= 0)
4078 upload_attribute_data(cdata, num_indices);
4086 if(cdata->current_shader_block.position_loc >= 0)
4088 if(cdata->current_shader_block.texcoord_loc >= 0)
4090 if(cdata->current_shader_block.color_loc >= 0)
4093 disable_attribute_data(cdata);
4095 #if !defined(SDL_GPU_NO_VAO)
4101 cdata->blit_buffer_num_vertices = 0;
4102 cdata->index_buffer_num_vertices = 0;
4109 #ifndef __IPHONEOS__
4172 SDL_Color
result = {0,0,0,0};
4187 result.r = pixels[0];
4188 result.g = pixels[1];
4189 result.b = pixels[2];
4198 GLenum minFilter, magFilter;
4367 #ifdef SDL_GPU_USE_GL_TIER1
4374 for(i = 0; i < num_vertices; i++)
4376 glTexCoord2f( *texcoord_pointer, *(texcoord_pointer+1) );
4377 glVertex3f( *vertex_pointer, *(vertex_pointer+1), 0.0
f );
4382 #elif defined(SDL_GPU_USE_GL_TIER2)
4394 #elif defined(SDL_GPU_USE_GL_TIER3)
4397 if(cdata->current_shader_block.modelViewProjection_loc >= 0)
4405 #if !defined(SDL_GPU_NO_VAO)
4411 cdata->blit_VBO_flop = !cdata->blit_VBO_flop;
4417 if(cdata->current_shader_block.position_loc >= 0)
4422 if(cdata->current_shader_block.texcoord_loc >= 0)
4427 if(cdata->current_shader_block.color_loc >= 0)
4433 upload_attribute_data(cdata, num_vertices);
4438 if(cdata->current_shader_block.position_loc >= 0)
4440 if(cdata->current_shader_block.texcoord_loc >= 0)
4442 if(cdata->current_shader_block.color_loc >= 0)
4445 disable_attribute_data(cdata);
4447 #if !defined(SDL_GPU_NO_VAO)
4456 #ifdef SDL_GPU_USE_GL_TIER1
4463 for(i = 0; i < num_vertices; i++)
4465 glColor4f( *color_pointer, *(color_pointer+1), *(color_pointer+2), *(color_pointer+3) );
4466 glVertex3f( *vertex_pointer, *(vertex_pointer+1), 0.0
f );
4471 #elif defined(SDL_GPU_USE_GL_TIER2)
4484 #elif defined(SDL_GPU_USE_GL_TIER3)
4487 if(cdata->current_shader_block.modelViewProjection_loc >= 0)
4495 #if !defined(SDL_GPU_NO_VAO)
4501 cdata->blit_VBO_flop = !cdata->blit_VBO_flop;
4507 if(cdata->current_shader_block.position_loc >= 0)
4512 if(cdata->current_shader_block.color_loc >= 0)
4518 upload_attribute_data(cdata, num_vertices);
4523 if(cdata->current_shader_block.position_loc >= 0)
4525 if(cdata->current_shader_block.color_loc >= 0)
4528 disable_attribute_data(cdata);
4530 #if !defined(SDL_GPU_NO_VAO)
4537 #define MAX(a, b) ((a) > (b)? (a) : (b))
4542 if(cdata->blit_buffer_num_vertices > 0 && cdata->last_target != NULL)
4548 unsigned short* index_buffer;
4555 #ifdef SDL_GPU_APPLY_TRANSFORMS_TO_GL_STACK
4562 #ifdef SDL_GPU_USE_GL_TIER3
4563 refresh_attribute_data(cdata);
4566 blit_buffer = cdata->blit_buffer;
4567 index_buffer = cdata->index_buffer;
4569 if(cdata->last_use_texturing)
4571 while(cdata->blit_buffer_num_vertices > 0)
4574 num_indices = num_vertices * 3 / 2;
4576 DoPartialFlush(cdata, num_vertices, blit_buffer, num_indices, index_buffer);
4578 cdata->blit_buffer_num_vertices -= num_vertices;
4581 index_buffer += num_indices;
4586 DoUntexturedFlush(cdata, cdata->blit_buffer_num_vertices, blit_buffer, cdata->index_buffer_num_vertices, index_buffer);
4589 cdata->blit_buffer_num_vertices = 0;
4590 cdata->index_buffer_num_vertices = 0;
4602 #ifdef SDL_GPU_USE_SDL2
4605 SDL_GL_SwapBuffers();
4608 #ifdef SDL_GPU_USE_OPENGL
4610 apply_Intel_attrib_workaround = 1;
4631 while(SDL_RWread(rwops, &buffer, 1, 1) > 0)
4643 if(SDL_RWread(rwops, &buffer, 1, 1) <= 0 || buffer ==
'/')
4657 if(shader_source == NULL)
4665 while((len = SDL_RWread(shader_source, &buffer, 1, 1)) > 0)
4668 if(buffer[0] ==
'#')
4672 unsigned long line_len;
4674 while((line_len = SDL_RWread(shader_source, buffer+line_size, 1, 1)) > 0)
4676 line_size += line_len;
4677 if(buffer[line_size - line_len] ==
'\n')
4683 token = strtok(buffer,
"# \t");
4685 if(token != NULL && strcmp(token,
"include") == 0)
4688 token = strtok(NULL,
"\"");
4703 if(last_char ==
'/')
4705 if(buffer[0] ==
'/')
4710 else if(buffer[0] ==
'*')
4718 last_char = buffer[0];
4722 SDL_RWseek(shader_source, 0, SEEK_SET);
4734 if(shader_source == NULL)
4745 while((len = SDL_RWread(shader_source, &buffer, 1, 1)) > 0)
4748 if(buffer[0] ==
'#')
4752 unsigned long line_len;
4753 char token_buffer[512];
4755 while((line_len = SDL_RWread(shader_source, buffer+line_size, 1, 1)) > 0)
4757 line_size += line_len;
4758 if(buffer[line_size - line_len] ==
'\n')
4763 memcpy(token_buffer, buffer, line_size+1);
4765 token = strtok(token_buffer,
"# \t");
4767 if(token != NULL && strcmp(token,
"include") == 0)
4770 token = strtok(NULL,
"\"");
4775 result[
size] =
'\n';
4781 memcpy(result + size, buffer, line_size);
4788 memcpy(result + size, buffer, len);
4791 if(last_char ==
'/')
4793 if(buffer[0] ==
'/')
4796 memcpy(result + size,
"\n", 1);
4799 else if(buffer[0] ==
'*')
4802 memcpy(result + size,
"*/", 2);
4808 last_char = buffer[0];
4810 result[
size] =
'\0';
4813 SDL_RWseek(shader_source, 0, SEEK_SET);
4822 if(filename == NULL)
4824 rwops = SDL_RWFromFile(filename,
"r");
4837 if(filename == NULL)
4839 rwops = SDL_RWFromFile(filename,
"r");
4853 GLuint shader_object = 0;
4855 #ifndef SDL_GPU_DISABLE_SHADERS
4867 #ifdef GL_GEOMETRY_SHADER
4871 snprintf(shader_message, 256,
"Failed to create geometry shader object.\n");
4877 if(shader_object == 0)
4880 snprintf(shader_message, 256,
"Failed to create new shader object.\n");
4901 return shader_object;
4909 char* source_string = (
char*)malloc(size+1);
4916 snprintf(shader_message, 256,
"Failed to read shader source.\n");
4917 free(source_string);
4922 free(source_string);
4929 Uint32
size = (Uint32)strlen(shader_source);
4933 rwops = SDL_RWFromConstMem(shader_source, size);
4941 #ifndef SDL_GPU_DISABLE_SHADERS
4956 return program_object;
4961 #ifndef SDL_GPU_DISABLE_SHADERS
4975 #ifndef SDL_GPU_DISABLE_SHADERS
4982 #ifndef SDL_GPU_DISABLE_SHADERS
4989 #ifndef SDL_GPU_DISABLE_SHADERS
4996 #ifndef SDL_GPU_DISABLE_SHADERS
5010 #ifndef SDL_GPU_DISABLE_SHADERS
5012 if(program_object == 0)
5025 #ifdef SDL_GPU_USE_GL_TIER3
5032 cdata->current_shader_block = cdata->shader_block[0];
5034 cdata->current_shader_block = cdata->shader_block[1];
5042 cdata->current_shader_block =
b;
5046 cdata->current_shader_block = *
block;
5066 #ifndef SDL_GPU_DISABLE_SHADERS
5068 if(program_object == 0)
5078 #ifndef SDL_GPU_DISABLE_SHADERS
5080 if(program_object == 0)
5092 if(program_object == 0)
5101 if(position_name == NULL)
5106 if(texcoord_name == NULL)
5111 if(color_name == NULL)
5116 if(modelViewMatrix_name == NULL)
5126 #ifdef SDL_GPU_USE_GL_TIER3
5134 #ifndef SDL_GPU_DISABLE_SHADERS
5158 #ifndef SDL_GPU_DISABLE_SHADERS
5160 if(program_object != 0)
5167 #ifndef SDL_GPU_DISABLE_SHADERS
5177 #ifndef SDL_GPU_DISABLE_SHADERS
5181 switch(num_elements_per_value)
5202 #ifndef SDL_GPU_DISABLE_SHADERS
5204 if(program_object != 0)
5205 #if defined(SDL_GPU_USE_GLES) && SDL_GPU_GLES_MAJOR_VERSION < 3
5215 #ifndef SDL_GPU_DISABLE_SHADERS
5219 #if defined(SDL_GPU_USE_GLES) && SDL_GPU_GLES_MAJOR_VERSION < 3
5229 #ifndef SDL_GPU_DISABLE_SHADERS
5233 #if defined(SDL_GPU_USE_GLES) && SDL_GPU_GLES_MAJOR_VERSION < 3
5234 switch(num_elements_per_value)
5250 switch(num_elements_per_value)
5272 #ifndef SDL_GPU_DISABLE_SHADERS
5274 if(program_object != 0)
5281 #ifndef SDL_GPU_DISABLE_SHADERS
5291 #ifndef SDL_GPU_DISABLE_SHADERS
5295 switch(num_elements_per_value)
5315 #ifndef SDL_GPU_DISABLE_SHADERS
5319 if(num_rows < 2 || num_rows > 4 || num_columns < 2 || num_columns > 4)
5324 #if defined(SDL_GPU_USE_GLES)
5326 #define glUniformMatrix2x3fv glUniformMatrix2fv
5327 #define glUniformMatrix2x4fv glUniformMatrix2fv
5328 #define glUniformMatrix3x2fv glUniformMatrix2fv
5329 #define glUniformMatrix3x4fv glUniformMatrix2fv
5330 #define glUniformMatrix4x2fv glUniformMatrix2fv
5331 #define glUniformMatrix4x3fv glUniformMatrix2fv
5332 if(num_rows != num_columns)
5342 if(num_columns == 2)
5344 else if(num_columns == 3)
5346 else if(num_columns == 4)
5350 if(num_columns == 2)
5352 else if(num_columns == 3)
5354 else if(num_columns == 4)
5358 if(num_columns == 2)
5360 else if(num_columns == 3)
5362 else if(num_columns == 4)
5372 #ifndef SDL_GPU_DISABLE_SHADERS
5377 #ifdef SDL_GPU_USE_OPENGL
5378 if(apply_Intel_attrib_workaround && location == 0)
5380 apply_Intel_attrib_workaround = 0;
5393 #ifndef SDL_GPU_DISABLE_SHADERS
5398 #ifdef SDL_GPU_USE_OPENGL
5399 if(apply_Intel_attrib_workaround && location == 0)
5401 apply_Intel_attrib_workaround = 0;
5414 #ifndef SDL_GPU_DISABLE_SHADERS
5419 #ifdef SDL_GPU_USE_OPENGL
5420 if(apply_Intel_attrib_workaround && location == 0)
5422 apply_Intel_attrib_workaround = 0;
5436 #ifndef SDL_GPU_DISABLE_SHADERS
5441 #ifdef SDL_GPU_USE_OPENGL
5442 if(apply_Intel_attrib_workaround && location == 0)
5444 apply_Intel_attrib_workaround = 0;
5450 switch(num_elements)
5471 #ifndef SDL_GPU_DISABLE_SHADERS
5476 #ifdef SDL_GPU_USE_OPENGL
5477 if(apply_Intel_attrib_workaround && location == 0)
5479 apply_Intel_attrib_workaround = 0;
5485 switch(num_elements)
5506 #ifndef SDL_GPU_DISABLE_SHADERS
5511 #ifdef SDL_GPU_USE_OPENGL
5512 if(apply_Intel_attrib_workaround && location == 0)
5514 apply_Intel_attrib_workaround = 0;
5520 switch(num_elements)
5541 #ifdef SDL_GPU_USE_GL_TIER3
5548 a = &cdata->shader_attributes[source.
location];
5591 #define SET_COMMON_FUNCTIONS(renderer) \
5592 renderer->Init = &Init; \
5593 renderer->IsFeatureEnabled = &IsFeatureEnabled; \
5594 renderer->CreateTargetFromWindow = &CreateTargetFromWindow; \
5595 renderer->CreateAliasTarget = &CreateAliasTarget; \
5596 renderer->MakeCurrent = &MakeCurrent; \
5597 renderer->SetAsCurrent = &SetAsCurrent; \
5598 renderer->SetWindowResolution = &SetWindowResolution; \
5599 renderer->SetVirtualResolution = &SetVirtualResolution; \
5600 renderer->UnsetVirtualResolution = &UnsetVirtualResolution; \
5601 renderer->Quit = &Quit; \
5603 renderer->ToggleFullscreen = &ToggleFullscreen; \
5604 renderer->SetCamera = &SetCamera; \
5606 renderer->CreateImage = &CreateImage; \
5607 renderer->LoadImage = &LoadImage; \
5608 renderer->CreateAliasImage = &CreateAliasImage; \
5609 renderer->SaveImage = &SaveImage; \
5610 renderer->CopyImage = &CopyImage; \
5611 renderer->UpdateImage = &UpdateImage; \
5612 renderer->UpdateSubImage = &UpdateSubImage; \
5613 renderer->UpdateImageBytes = &UpdateImageBytes; \
5614 renderer->CopyImageFromSurface = &CopyImageFromSurface; \
5615 renderer->CopyImageFromTarget = &CopyImageFromTarget; \
5616 renderer->CopySurfaceFromTarget = &CopySurfaceFromTarget; \
5617 renderer->CopySurfaceFromImage = &CopySurfaceFromImage; \
5618 renderer->FreeImage = &FreeImage; \
5620 renderer->LoadTarget = &LoadTarget; \
5621 renderer->FreeTarget = &FreeTarget; \
5623 renderer->Blit = &Blit; \
5624 renderer->BlitRotate = &BlitRotate; \
5625 renderer->BlitScale = &BlitScale; \
5626 renderer->BlitTransform = &BlitTransform; \
5627 renderer->BlitTransformX = &BlitTransformX; \
5628 renderer->BlitTransformMatrix = &BlitTransformMatrix; \
5629 renderer->BlitBatch = &BlitBatch; \
5630 renderer->TriangleBatch = &TriangleBatch; \
5632 renderer->GenerateMipmaps = &GenerateMipmaps; \
5634 renderer->SetClip = &SetClip; \
5635 renderer->UnsetClip = &UnsetClip; \
5637 renderer->GetPixel = &GetPixel; \
5638 renderer->SetImageFilter = &SetImageFilter; \
5639 renderer->SetWrapMode = &SetWrapMode; \
5641 renderer->Clear = &Clear; \
5642 renderer->ClearRGBA = &ClearRGBA; \
5643 renderer->FlushBlitBuffer = &FlushBlitBuffer; \
5644 renderer->Flip = &Flip; \
5646 renderer->CompileShader_RW = &CompileShader_RW; \
5647 renderer->CompileShader = &CompileShader; \
5648 renderer->LinkShaderProgram = &LinkShaderProgram; \
5649 renderer->LinkShaders = &LinkShaders; \
5650 renderer->FreeShader = &FreeShader; \
5651 renderer->FreeShaderProgram = &FreeShaderProgram; \
5652 renderer->AttachShader = &AttachShader; \
5653 renderer->DetachShader = &DetachShader; \
5654 renderer->IsDefaultShaderProgram = &IsDefaultShaderProgram; \
5655 renderer->ActivateShaderProgram = &ActivateShaderProgram; \
5656 renderer->DeactivateShaderProgram = &DeactivateShaderProgram; \
5657 renderer->GetShaderMessage = &GetShaderMessage; \
5658 renderer->GetAttributeLocation = &GetAttributeLocation; \
5659 renderer->GetUniformLocation = &GetUniformLocation; \
5660 renderer->LoadShaderBlock = &LoadShaderBlock; \
5661 renderer->SetShaderBlock = &SetShaderBlock; \
5662 renderer->SetShaderImage = &SetShaderImage; \
5663 renderer->GetUniformiv = &GetUniformiv; \
5664 renderer->SetUniformi = &SetUniformi; \
5665 renderer->SetUniformiv = &SetUniformiv; \
5666 renderer->GetUniformuiv = &GetUniformuiv; \
5667 renderer->SetUniformui = &SetUniformui; \
5668 renderer->SetUniformuiv = &SetUniformuiv; \
5669 renderer->GetUniformfv = &GetUniformfv; \
5670 renderer->SetUniformf = &SetUniformf; \
5671 renderer->SetUniformfv = &SetUniformfv; \
5672 renderer->SetUniformMatrixfv = &SetUniformMatrixfv; \
5673 renderer->SetAttributef = &SetAttributef; \
5674 renderer->SetAttributei = &SetAttributei; \
5675 renderer->SetAttributeui = &SetAttributeui; \
5676 renderer->SetAttributefv = &SetAttributefv; \
5677 renderer->SetAttributeiv = &SetAttributeiv; \
5678 renderer->SetAttributeuiv = &SetAttributeuiv; \
5679 renderer->SetAttributeSource = &SetAttributeSource; \
5683 renderer->SetLineThickness = &SetLineThickness; \
5684 renderer->SetLineThickness(renderer, 1.0f); \
5685 renderer->GetLineThickness = &GetLineThickness; \
5686 renderer->Pixel = &Pixel; \
5687 renderer->Line = &Line; \
5688 renderer->Arc = &Arc; \
5689 renderer->ArcFilled = &ArcFilled; \
5690 renderer->Circle = &Circle; \
5691 renderer->CircleFilled = &CircleFilled; \
5692 renderer->Sector = &Sector; \
5693 renderer->SectorFilled = &SectorFilled; \
5694 renderer->Tri = &Tri; \
5695 renderer->TriFilled = &TriFilled; \
5696 renderer->Rectangle = &Rectangle; \
5697 renderer->RectangleFilled = &RectangleFilled; \
5698 renderer->RectangleRound = &RectangleRound; \
5699 renderer->RectangleRoundFilled = &RectangleRoundFilled; \
5700 renderer->Polygon = &Polygon; \
5701 renderer->PolygonFilled = &PolygonFilled;
static void changeCamera(GPU_Target *target)
GLAPI void GLAPIENTRY glDisableClientState(GLenum array)
GLAPI void GLAPIENTRY glDeleteTextures(GLsizei n, const GLuint *textures)
static const GPU_TypeEnum GPU_TYPE_INT
static Uint8 bindFramebuffer(GPU_Renderer *renderer, GPU_Target *target)
#define glewIsExtensionSupported(x)
float matrix[GPU_MATRIX_STACK_MAX][16]
GLAPI void GLAPIENTRY glEnableClientState(GLenum array)
void GPU_UnsetClip(GPU_Target *target)
#define glGenVertexArrays
static void Clear(GPU_Renderer *renderer, GPU_Target *target)
static void BlitTransformX(GPU_Renderer *renderer, 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)
int(* GetAttributeLocation)(GPU_Renderer *renderer, Uint32 program_object, const char *attrib_name)
static Uint8 SaveImage(GPU_Renderer *renderer, GPU_Image *image, const char *filename)
#define glVertexAttribPointer
static GPU_Image * CreateAliasImage(GPU_Renderer *renderer, GPU_Image *image)
static Uint8 isExtensionSupported(const char *extension_str)
static void changeViewport(GPU_Target *target)
static int get_lowest_attribute_num_values(GPU_CONTEXT_DATA *cdata, int cap)
static void SetImageFilter(GPU_Renderer *renderer, GPU_Image *image, GPU_FilterEnum filter)
static void BlitRotate(GPU_Renderer *renderer, GPU_Image *image, GPU_Rect *src_rect, GPU_Target *target, float x, float y, float degrees)
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
GLsizei GLboolean transpose
GLAPI void GLAPIENTRY glGetTexImage(GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels)
GLAPI void GLAPIENTRY glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels)
void GPU_Translate(float x, float y, float z)
static void SetWrapMode(GPU_Renderer *renderer, GPU_Image *image, GPU_WrapEnum wrap_mode_x, GPU_WrapEnum wrap_mode_y)
void GPU_SetSnapMode(GPU_Image *image, GPU_SnapEnum mode)
#define GPU_DEFAULT_UNTEXTURED_VERTEX_SHADER_SOURCE
GPU_ShaderBlock GPU_LoadShaderBlock(Uint32 program_object, const char *position_name, const char *texcoord_name, const char *color_name, const char *modelViewMatrix_name)
static void SetAttributei(GPU_Renderer *renderer, int location, int value)
#define GL_TEXTURE_WRAP_T
#define GL_COLOR_ATTACHMENT0
void GPU_SetShaderBlock(GPU_ShaderBlock block)
static void extBindFramebuffer(GPU_Renderer *renderer, GLuint handle)
#define GPU_DEFAULT_TEXTURED_FRAGMENT_SHADER_SOURCE
static void changeBlendMode(GPU_Renderer *renderer, GPU_BlendMode mode)
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
#define glGenFramebuffers
static const GPU_InitFlagEnum GPU_INIT_DISABLE_DOUBLE_BUFFER
GPU_Rect GPU_MakeRect(float x, float y, float w, float h)
GLAPI void GLAPIENTRY glMatrixMode(GLenum mode)
Uint32 default_untextured_shader_program
static GPU_Rect SetClip(GPU_Renderer *renderer, GPU_Target *target, Sint16 x, Sint16 y, Uint16 w, Uint16 h)
void GPU_Ortho(float left, float right, float bottom, float top, float near, float far)
#define GPU_BLIT_BUFFER_FLOATS_PER_VERTEX
GLAPI void GLAPIENTRY glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
static SDL_Surface * CopySurfaceFromTarget(GPU_Renderer *renderer, GPU_Target *target)
#define GPU_DEFAULT_UNTEXTURED_FRAGMENT_SHADER_SOURCE
void GPU_MatrixMode(int matrix_mode)
int modelViewProjection_loc
GLAPI void GLAPIENTRY glEnable(GLenum cap)
static void SetAttributef(GPU_Renderer *renderer, int location, float value)
static const GPU_TypeEnum GPU_TYPE_DOUBLE
GPU_Camera GPU_GetDefaultCamera(void)
void GPU_RemoveWindowMapping(Uint32 windowID)
static void MakeCurrent(GPU_Renderer *renderer, GPU_Target *target, Uint32 windowID)
static int compareFormats(GPU_Renderer *renderer, GLenum glFormat, SDL_Surface *surface, GLenum *surfaceFormatResult)
static void BlitBatch(GPU_Renderer *renderer, GPU_Image *image, GPU_Target *target, unsigned int num_sprites, float *values, GPU_BlitFlagEnum flags)
static void UpdateImage(GPU_Renderer *renderer, GPU_Image *image, SDL_Surface *surface, const GPU_Rect *surface_rect)
#define glEnableVertexAttribArray
#define glUniformMatrix2x4fv
#define GPU_BLIT_BUFFER_VERTEX_OFFSET
GLuint GLuint GLsizei GLenum type
#define GL_GENERATE_MIPMAP
GLAPI void GLAPIENTRY glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels)
Uint32 GPU_WindowFlagEnum
GPU_MatrixStack projection_matrix
#define glUniformMatrix4x2fv
#define glUniformMatrix3x4fv
static void UpdateSubImage(GPU_Renderer *renderer, GPU_Image *image, const GPU_Rect *image_rect, SDL_Surface *surface, const GPU_Rect *surface_rect)
#define GPU_BLIT_BUFFER_STRIDE
int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data)
static Uint8 growIndexBuffer(GPU_CONTEXT_DATA *cdata, unsigned int minimum_vertices_needed)
static GPU_Image * CreateUninitializedImage(GPU_Renderer *renderer, Uint16 w, Uint16 h, GPU_FormatEnum format)
#define glGetAttribLocation
void GPU_SetColor(GPU_Image *image, SDL_Color *color)
static void SetUniformfv(GPU_Renderer *renderer, int location, int num_elements_per_value, int num_values, float *values)
GLAPI void GLAPIENTRY glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)
static int GetAttributeLocation(GPU_Renderer *renderer, Uint32 program_object, const char *attrib_name)
static Uint32 compile_shader_source(GPU_ShaderEnum shader_type, const char *shader_source)
SDL_Rect line_size(const std::string &line, int font_size, int style)
Determine the size of a line of text given a certain font size.
#define glUniformMatrix2x3fv
static void TriangleBatch(GPU_Renderer *renderer, GPU_Image *image, GPU_Target *target, unsigned short num_vertices, float *values, unsigned int num_indices, unsigned short *indices, GPU_BlitFlagEnum flags)
#define glDeleteVertexArrays
GLenum GLsizei GLenum GLenum const GLvoid * image
#define glVertexAttribI3i
GLAPI void GLAPIENTRY glLoadMatrixf(const GLfloat *m)
SDL_Surface *(* CopySurfaceFromTarget)(GPU_Renderer *renderer, GPU_Target *target)
#define SDL_GPU_GL_MAJOR_VERSION
GPU_Target * GPU_GetContextTarget(void)
static const GPU_FeatureEnum GPU_FEATURE_RENDER_TARGETS
#define glUniformMatrix2fv
static GPU_Target * CreateAliasTarget(GPU_Renderer *renderer, GPU_Target *target)
static const GPU_FeatureEnum GPU_FEATURE_BLEND_FUNC_SEPARATE
static void ClearRGBA(GPU_Renderer *renderer, GPU_Target *target, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
#define glUniformMatrix4x3fv
#define SET_TEXTURED_VERTEX_UNINDEXED(x, y, s, t, r, g, b, a)
static void prepareToRenderImage(GPU_Renderer *renderer, GPU_Target *target, GPU_Image *image)
static void SetUniformMatrixfv(GPU_Renderer *renderer, int location, int num_matrices, int num_rows, int num_columns, Uint8 transpose, float *values)
#define glBlendEquationSeparate
void GPU_Scale(float sx, float sy, float sz)
GPU_InitFlagEnum GPU_GetPreInitFlags(void)
void(* MakeCurrent)(GPU_Renderer *renderer, GPU_Target *target, Uint32 windowID)
#define GL_TEXTURE_COORD_ARRAY
void(* ActivateShaderProgram)(GPU_Renderer *renderer, Uint32 program_object, GPU_ShaderBlock *block)
#define GL_ONE_MINUS_SRC_ALPHA
int(* GetUniformLocation)(GPU_Renderer *renderer, Uint32 program_object, const char *uniform_name)
GLint GLint GLint GLint GLint GLint y
static Uint32 GetShaderSourceSize(const char *filename)
static Uint32 LinkShaderProgram(GPU_Renderer *renderer, Uint32 program_object)
static void changeColor(GPU_Renderer *renderer, SDL_Color color)
#define GL_GEOMETRY_SHADER
#define GET_ALPHA(sdl_color)
static void Blit(GPU_Renderer *renderer, GPU_Image *image, GPU_Rect *src_rect, GPU_Target *target, float x, float y)
#define GPU_BLIT_BUFFER_COLOR_OFFSET
static const GPU_FeatureEnum GPU_FEATURE_GL_BGR
static void applyTargetCamera(GPU_Target *target)
#define glFramebufferTexture2D
static void FreeShader(GPU_Renderer *renderer, Uint32 shader_object)
GLAPI void GLAPIENTRY glTexCoord2f(GLfloat s, GLfloat t)
void(* FlushBlitBuffer)(GPU_Renderer *renderer)
void GPU_Rotate(float degrees, float x, float y, float z)
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
static GPU_Image * CopyImage(GPU_Renderer *renderer, GPU_Image *image)
static const GPU_FeatureEnum GPU_FEATURE_BLEND_EQUATIONS_SEPARATE
#define GL_MIRRORED_REPEAT
static void UnsetVirtualResolution(GPU_Renderer *renderer, GPU_Target *target)
Uint8(* SetWindowResolution)(GPU_Renderer *renderer, Uint16 w, Uint16 h)
static void prepareToRenderToTarget(GPU_Renderer *renderer, GPU_Target *target)
void GPU_SetBlending(GPU_Image *image, Uint8 enable)
#define glVertexAttribI1i
float * GPU_GetProjection(void)
void GPU_PushErrorCode(const char *function, GPU_ErrorEnum error, const char *details,...)
SDL_Surface * GPU_LoadSurface(const char *filename)
#define glBindVertexArray
int per_vertex_storage_size
static Uint32 CompileShader(GPU_Renderer *renderer, GPU_ShaderEnum shader_type, const char *shader_source)
static Uint8 IsDefaultShaderProgram(GPU_Renderer *renderer, Uint32 program_object)
static SDL_Color GetPixel(GPU_Renderer *renderer, GPU_Target *target, Sint16 x, Sint16 y)
GLboolean GLenum GLenum GLvoid * values
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
void GPU_GetModelViewProjection(float *result)
#define GPU_BLIT_BUFFER_INIT_MAX_NUM_VERTICES
static const GPU_FeatureEnum GPU_FEATURE_FRAGMENT_SHADER
#define glUniformMatrix3x2fv
Uint32(* LinkShaders)(GPU_Renderer *renderer, Uint32 shader_object1, Uint32 shader_object2)
static void SetAsCurrent(GPU_Renderer *renderer)
static Uint32 GetShaderSource(const char *filename, char *result)
void(* Blit)(GPU_Renderer *renderer, GPU_Image *image, GPU_Rect *src_rect, GPU_Target *target, float x, float y)
GLdouble GLdouble GLdouble b
#define GPU_DEFAULT_TEXTURED_VERTEX_SHADER_SOURCE
static int GetUniformLocation(GPU_Renderer *renderer, Uint32 program_object, const char *uniform_name)
GLAPI void GLAPIENTRY glBindTexture(GLenum target, GLuint texture)
static const GPU_InitFlagEnum GPU_INIT_DISABLE_VSYNC
static unsigned char * getRawTargetData(GPU_Renderer *renderer, GPU_Target *target)
#define GL_FRAMEBUFFER_BINDING
static const GPU_FeatureEnum GPU_FEATURE_VERTEX_SHADER
#define glGetUniformLocation
int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes)
GLAPI void GLAPIENTRY glGetTexParameteriv(GLenum target, GLenum pname, GLint *params)
#define GL_COLOR_BUFFER_BIT
static Uint8 readTargetPixels(GPU_Renderer *renderer, GPU_Target *source, GLint format, GLubyte *pixels)
static_inline Uint8 isPowerOfTwo(unsigned int x)
#define glGetShaderInfoLog
static void FreeTarget(GPU_Renderer *renderer, GPU_Target *target)
GPU_BlendEqEnum alpha_equation
static const GPU_FeatureEnum GPU_FEATURE_WRAP_REPEAT_MIRRORED
static Uint8 IsFeatureEnabled(GPU_Renderer *renderer, GPU_FeatureEnum feature)
static const GPU_TypeEnum GPU_TYPE_UNSIGNED_INT
static void makeContextCurrent(GPU_Renderer *renderer, GPU_Target *target)
static Uint8 ToggleFullscreen(GPU_Renderer *renderer, Uint8 use_desktop_resolution)
static void FlushBlitBuffer(GPU_Renderer *renderer)
static_inline Uint32 getPixel(SDL_Surface *Surface, int x, int y)
static const GPU_FeatureEnum GPU_FEATURE_GEOMETRY_SHADER
struct GPU_Renderer * renderer
void(* BlitTransformX)(GPU_Renderer *renderer, 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)
GPU_Target * current_context_target
GLAPI void GLAPIENTRY glDrawArrays(GLenum mode, GLint first, GLsizei count)
static void GetUniformiv(GPU_Renderer *renderer, Uint32 program_object, int location, int *values)
#define GPU_BLIT_BUFFER_VERTICES_PER_SPRITE
static void GetUniformfv(GPU_Renderer *renderer, Uint32 program_object, int location, float *values)
static void SetAttributeuiv(GPU_Renderer *renderer, int location, int num_elements, unsigned int *value)
GPU_BlendEqEnum color_equation
#define GPU_BLIT_BUFFER_ABSOLUTE_MAX_VERTICES
GLubyte GLubyte GLubyte GLubyte w
GLsizei const GLfloat * value
static GPU_Image * CopyImageFromSurface(GPU_Renderer *renderer, SDL_Surface *surface)
static const GPU_TypeEnum GPU_TYPE_UNSIGNED_SHORT
GPU_BlendMode shapes_blend_mode
GPU_BlendFuncEnum dest_alpha
static void DoUntexturedFlush(GPU_CONTEXT_DATA *cdata, unsigned short num_vertices, float *blit_buffer, unsigned int num_indices, unsigned short *index_buffer)
static const GPU_FeatureEnum GPU_FEATURE_BLEND_EQUATIONS
#define MIX_COLOR_COMPONENT_NORMALIZED_RESULT(a, b)
static Uint32 get_proper_program_id(GPU_Renderer *renderer, Uint32 program_object)
GLboolean GLboolean GLboolean GLboolean a
void GPU_SetInitWindow(Uint32 windowID)
static void DetachShader(GPU_Renderer *renderer, Uint32 program_object, Uint32 shader_object)
GLAPI void GLAPIENTRY glTexParameteri(GLenum target, GLenum pname, GLint param)
static void SetUniformf(GPU_Renderer *renderer, int location, float value)
static void SetVirtualResolution(GPU_Renderer *renderer, GPU_Target *target, Uint16 w, Uint16 h)
void(* SetVirtualResolution)(GPU_Renderer *renderer, GPU_Target *target, Uint16 w, Uint16 h)
void GPU_AddWindowMapping(GPU_Target *target)
int per_vertex_storage_offset_bytes
static void changeTexturing(GPU_Renderer *renderer, Uint8 enable)
static const char * GetShaderMessage(GPU_Renderer *renderer)
static GPU_Target * LoadTarget(GPU_Renderer *renderer, GPU_Image *image)
GPU_BlendFuncEnum source_color
GPU_BlendMode GPU_GetBlendModeFromPreset(GPU_BlendPresetEnum preset)
#define GPU_INDEX_BUFFER_ABSOLUTE_MAX_VERTICES
static void AttachShader(GPU_Renderer *renderer, Uint32 program_object, Uint32 shader_object)
static void init_features(GPU_Renderer *renderer)
GLAPI void GLAPIENTRY glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)
struct GPU_Renderer * renderer
static const GPU_TypeEnum GPU_TYPE_SHORT
GLAPI void GLAPIENTRY glBegin(GLenum mode)
static void enableTexturing(GPU_Renderer *renderer)
#define GL_COMPILE_STATUS
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
Uint8 shapes_use_blending
float(* SetLineThickness)(GPU_Renderer *renderer, float thickness)
#define GPU_BLIT_BUFFER_TEX_COORD_OFFSET
static Uint8 SetWindowResolution(GPU_Renderer *renderer, Uint16 w, Uint16 h)
static void SetUniformuiv(GPU_Renderer *renderer, int location, int num_elements_per_value, int num_values, unsigned int *values)
GLuint GLuint GLsizei count
static GPU_ShaderBlock LoadShaderBlock(GPU_Renderer *renderer, Uint32 program_object, const char *position_name, const char *texcoord_name, const char *color_name, const char *modelViewMatrix_name)
cl_event GLbitfield flags
static void Quit(GPU_Renderer *renderer)
static void FreeImage(GPU_Renderer *renderer, GPU_Image *image)
static Uint32 GetShaderSourceSize_RW(SDL_RWops *shader_source)
GPU_RendererID requested_id
GLAPI void GLAPIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z)
#define GL_FRAGMENT_SHADER
static void applyTexturing(GPU_Renderer *renderer)
static void UnsetClip(GPU_Renderer *renderer, GPU_Target *target)
static void BlitTransform(GPU_Renderer *renderer, GPU_Image *image, GPU_Rect *src_rect, GPU_Target *target, float x, float y, float degrees, float scaleX, float scaleY)
static void SetShaderBlock(GPU_Renderer *renderer, GPU_ShaderBlock block)
static_inline void flushAndBindTexture(GPU_Renderer *renderer, GLuint handle)
static const GPU_TypeEnum GPU_TYPE_BYTE
GPU_FilterEnum filter_mode
static void prepareToRenderShapes(GPU_Renderer *renderer, unsigned int shape)
Encapsulates the map of the game.
Uint8(* IsFeatureEnabled)(GPU_Renderer *renderer, GPU_FeatureEnum feature)
void GPU_MatrixIdentity(float *result)
static GPU_Image * LoadImage(GPU_Renderer *renderer, const char *filename)
static Uint32 GetShaderSource_RW(SDL_RWops *shader_source, char *result)
#define GL_UNSIGNED_SHORT
static_inline Uint8 isCurrentTarget(GPU_Renderer *renderer, GPU_Target *target)
#define GL_TEXTURE_ENV_MODE
static void block(LexState *ls)
static_inline void flushAndBindFramebuffer(GPU_Renderer *renderer, GLuint handle)
static void disableTexturing(GPU_Renderer *renderer)
GPU_MatrixStack modelview_matrix
static_inline void flushBlitBufferIfCurrentTexture(GPU_Renderer *renderer, GPU_Image *image)
static void read_until_end_of_comment(SDL_RWops *rwops, char multiline)
static void SetUniformui(GPU_Renderer *renderer, int location, unsigned int value)
GLAPI void GLAPIENTRY glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices)
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
static Uint8 equal_cameras(GPU_Camera a, GPU_Camera b)
static const GPU_FeatureEnum GPU_FEATURE_NON_POWER_OF_TWO
#define glUniformMatrix4fv
void GPU_SetImageFilter(GPU_Image *image, GPU_FilterEnum filter)
static void ActivateShaderProgram(GPU_Renderer *renderer, Uint32 program_object, GPU_ShaderBlock *block)
static void setClipRect(GPU_Renderer *renderer, GPU_Target *target)
std::vector< std::string > linked
#define GL_FRAMEBUFFER_COMPLETE
static void SetUniformi(GPU_Renderer *renderer, int location, int value)
#define glVertexAttribI2i
GLAPI void GLAPIENTRY glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
GLAPI void GLAPIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
#define GL_UNPACK_ROW_LENGTH
static void FreeShaderProgram(GPU_Renderer *renderer, Uint32 program_object)
#define GL_TEXTURE_MIN_FILTER
GPU_Target *(* CreateTargetFromWindow)(GPU_Renderer *renderer, Uint32 windowID, GPU_Target *target)
static void GetUniformuiv(GPU_Renderer *renderer, Uint32 program_object, int location, unsigned int *values)
#define GL_UNPACK_ALIGNMENT
GPU_FeatureEnum enabled_features
GPU_Image *(* CreateImage)(GPU_Renderer *renderer, Uint16 w, Uint16 h, GPU_FormatEnum format)
void(* UpdateSubImage)(GPU_Renderer *renderer, GPU_Image *image, const GPU_Rect *image_rect, SDL_Surface *surface, const GPU_Rect *surface_rect)
static SDL_Surface * CopySurfaceFromImage(GPU_Renderer *renderer, GPU_Image *image)
GLfloat GLfloat GLfloat GLfloat h
#define glUniformMatrix3fv
#define GL_TEXTURE_MAG_FILTER
GLint GLint GLint GLint GLint x
GPU_Target * GPU_LoadTarget(GPU_Image *image)
GLAPI const GLubyte *GLAPIENTRY glGetString(GLenum name)
#define glVertexAttribI2ui
static Uint8 readImagePixels(GPU_Renderer *renderer, GPU_Image *source, GLint format, GLubyte *pixels)
GLAPI void GLAPIENTRY glTexEnvf(GLenum target, GLenum pname, GLfloat param)
GLAPI void GLAPIENTRY glGenTextures(GLsizei n, GLuint *textures)
GLdouble GLdouble GLdouble r
static const char * get_filename_ext(const char *filename)
Uint32(* CompileShader)(GPU_Renderer *renderer, GPU_ShaderEnum shader_type, const char *shader_source)
void GPU_RemoveWindowMappingByTarget(GPU_Target *target)
int per_vertex_storage_stride_bytes
void GPU_SetWrapMode(GPU_Image *image, GPU_WrapEnum wrap_mode_x, GPU_WrapEnum wrap_mode_y)
GLAPI void GLAPIENTRY glGetIntegerv(GLenum pname, GLint *params)
GLAPI void GLAPIENTRY glClear(GLbitfield mask)
void(* UpdateImage)(GPU_Renderer *renderer, GPU_Image *image, SDL_Surface *surface, const GPU_Rect *surface_rect)
#define GL_LINEAR_MIPMAP_LINEAR
void GPU_MultMatrix(float *A)
#define glBlendFuncSeparate
Uint32(* CompileShader_RW)(GPU_Renderer *renderer, GPU_ShaderEnum shader_type, SDL_RWops *shader_source)
static void GenerateMipmaps(GPU_Renderer *renderer, GPU_Image *image)
GPU_BlendFuncEnum dest_color
#define glCheckFramebufferStatus
static void DoPartialFlush(GPU_CONTEXT_DATA *cdata, unsigned short num_vertices, float *blit_buffer, unsigned int num_indices, unsigned short *index_buffer)
GLAPI void GLAPIENTRY glEnd(void)
#define glVertexAttribI4i
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
GPU_InitFlagEnum GPU_init_flags
GPU_AttributeFormat format
static const GPU_FeatureEnum GPU_FEATURE_GL_ABGR
static void FreeFormat(SDL_PixelFormat *format)
#define MIX_COLORS(color1, color2)
static SDL_Surface * copySurfaceIfNeeded(GPU_Renderer *renderer, GLenum glFormat, SDL_Surface *surface, GLenum *surfaceFormatResult)
void GPU_GenerateMipmaps(GPU_Image *image)
void GPU_FreeImage(GPU_Image *image)
static GPU_Image * CreateImage(GPU_Renderer *renderer, Uint16 w, Uint16 h, GPU_FormatEnum format)
void GPU_LoadIdentity(void)
static const GPU_FeatureEnum GPU_FEATURE_GL_BGRA
static const GPU_TypeEnum GPU_TYPE_FLOAT
static const GPU_TypeEnum GPU_TYPE_UNSIGNED_BYTE
float * GPU_GetModelView(void)
static void Flip(GPU_Renderer *renderer, GPU_Target *target)
static void DeactivateShaderProgram(GPU_Renderer *renderer)
void * per_vertex_storage
#define glGetProgramInfoLog
this module manages the cache of images.
GPU_WindowFlagEnum SDL_init_flags
GLAPI void GLAPIENTRY glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
#define glVertexAttribI1ui
#define SET_INDEXED_VERTEX(offset)
static void BlitScale(GPU_Renderer *renderer, GPU_Image *image, GPU_Rect *src_rect, GPU_Target *target, float x, float y, float scaleX, float scaleY)
GLuint GLuint GLsizei GLenum const GLvoid * indices
static void SetUniformiv(GPU_Renderer *renderer, int location, int num_elements_per_value, int num_values, int *values)
#define glDeleteFramebuffers
#define glVertexAttribI3ui
static Uint32 LinkShaders(GPU_Renderer *renderer, Uint32 shader_object1, Uint32 shader_object2)
static char shader_message[256]
#define GL_LUMINANCE_ALPHA
Uint32 current_shader_program
Uint32(* LinkShaderProgram)(GPU_Renderer *renderer, Uint32 program_object)
#define glDisableVertexAttribArray
static void changeBlending(GPU_Renderer *renderer, Uint8 enable)
GPU_Target *(* LoadTarget)(GPU_Renderer *renderer, GPU_Image *image)
static GPU_Camera SetCamera(GPU_Renderer *renderer, GPU_Target *target, GPU_Camera *cam)
static void SetShaderImage(GPU_Renderer *renderer, GPU_Image *image, int location, int image_unit)
Uint32 GPU_GetInitWindow(void)
static const GPU_InitFlagEnum GPU_INIT_ENABLE_VSYNC
static Uint8 hasColorkey(SDL_Surface *surface)
static void SetAttributeiv(GPU_Renderer *renderer, int location, int num_elements, int *value)
static unsigned char * getRawImageData(GPU_Renderer *renderer, GPU_Image *image)
#define glBindFramebuffer
GLAPI void GLAPIENTRY glDisable(GLenum cap)
static Uint8 growBlitBuffer(GPU_CONTEXT_DATA *cdata, unsigned int minimum_vertices_needed)
GLAPI void GLAPIENTRY glPixelStorei(GLenum pname, GLint param)
GLAPI void GLAPIENTRY glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)
GPU_Image *(* CopyImageFromSurface)(GPU_Renderer *renderer, SDL_Surface *surface)
static void BlitTransformMatrix(GPU_Renderer *renderer, GPU_Image *image, GPU_Rect *src_rect, GPU_Target *target, float x, float y, float *matrix3x3)
#define GL_TEXTURE_WRAP_S
#define GL_LINEAR_MIPMAP_NEAREST
static void bindTexture(GPU_Renderer *renderer, GPU_Image *image)
int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data)
void(* FreeTarget)(GPU_Renderer *renderer, GPU_Target *target)
static_inline unsigned int getNearestPowerOf2(unsigned int n)
std::vector< std::string > compiled
static GPU_Image * CopyImageFromTarget(GPU_Renderer *renderer, GPU_Target *target)
GPU_Camera(* SetCamera)(GPU_Renderer *renderer, GPU_Target *target, GPU_Camera *cam)
Uint32 default_textured_shader_program
GLsizei GLsizei GLchar * source
static void unsetClipRect(GPU_Renderer *renderer, GPU_Target *target)
static_inline void flushAndClearBlitBufferIfCurrentTexture(GPU_Renderer *renderer, GPU_Image *image)
GLAPI void GLAPIENTRY glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels)
#define SDL_GPU_GLES_MAJOR_VERSION
static void SetAttributeui(GPU_Renderer *renderer, int location, unsigned int value)
static Uint32 CompileShader_RW(GPU_Renderer *renderer, GPU_ShaderEnum shader_type, SDL_RWops *shader_source)
static void SetAttributefv(GPU_Renderer *renderer, int location, int num_elements, float *value)
GPU_BlendFuncEnum source_alpha
static_inline void flushAndClearBlitBufferIfCurrentFramebuffer(GPU_Renderer *renderer, GPU_Target *target)
boost::shared_ptr< halo_record > handle
static SDL_PixelFormat * AllocFormat(GLenum glFormat)
static void UpdateImageBytes(GPU_Renderer *renderer, GPU_Image *image, const GPU_Rect *image_rect, const unsigned char *bytes, int bytes_per_row)
static GPU_Target * CreateTargetFromWindow(GPU_Renderer *renderer, Uint32 windowID, GPU_Target *target)
#define glVertexAttribI4ui
static void SetAttributeSource(GPU_Renderer *renderer, int num_values, GPU_Attribute source)
static GPU_Target * Init(GPU_Renderer *renderer, GPU_RendererID renderer_request, Uint16 w, Uint16 h, GPU_WindowFlagEnum SDL_flags)