The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SDL_gpu.c
Go to the documentation of this file.
1 #include "SDL_gpu.h"
2 #include "SDL_platform.h"
3 
4 #ifdef __ANDROID__
5 #include <android/log.h>
6 #endif
7 
8 #ifdef _MSC_VER
9  #define __func__ __FUNCTION__
10 #endif
11 
12 #include "stb_image.h"
13 
14 #ifdef SDL_GPU_USE_SDL2
15  #define GET_ALPHA(sdl_color) ((sdl_color).a)
16 #else
17  #define GET_ALPHA(sdl_color) ((sdl_color).unused)
18 #endif
19 
20 #define CHECK_RENDERER (current_renderer != NULL)
21 #define CHECK_CONTEXT (current_renderer->current_context_target != NULL)
22 #define CHECK_FUNCTION_POINTER(fn) (current_renderer->fn != NULL)
23 #define RETURN_ERROR(code, details) do{ GPU_PushErrorCode(__func__, code, "%s", details); return; } while(0)
24 
25 void GPU_InitRendererRegister(void);
26 
28 
30 
31 #define GPU_MAX_NUM_ERRORS 20
32 #define GPU_ERROR_FUNCTION_STRING_MAX 128
33 #define GPU_ERROR_DETAILS_STRING_MAX 512
35 static int num_error_codes = 0;
36 static int inited_error_code_stack = 0;
37 
38 /*! A mapping of windowID to a GPU_Target to facilitate GPU_GetWindowTarget(). */
39 typedef struct GPU_WindowMapping
40 {
41  Uint32 windowID;
44 
45 #define GPU_INITIAL_WINDOW_MAPPINGS_SIZE 10
47 static int window_mappings_size = 0;
48 static int num_window_mappings = 0;
49 
50 
51 SDL_version GPU_GetLinkedVersion(void)
52 {
53  return GPU_GetCompiledVersion();
54 }
55 
57 {
58  current_renderer = GPU_GetRendererByID(id);
59 
60  if(current_renderer != NULL && current_renderer->SetAsCurrent != NULL)
61  current_renderer->SetAsCurrent(current_renderer);
62 }
63 
65 {
66  return current_renderer;
67 }
68 
70 {
71  if(current_renderer == NULL || current_renderer->current_context_target == NULL)
72  return 0;
73 
74  return current_renderer->current_context_target->context->current_shader_program;
75 }
76 
77 
78 
79 void GPU_LogInfo(const char* format, ...)
80 {
81  va_list args;
82  va_start(args, format);
83  #ifdef __ANDROID__
84  __android_log_vprint((GPU_GetDebugLevel() >= GPU_DEBUG_LEVEL_3? ANDROID_LOG_ERROR : ANDROID_LOG_INFO), "APPLICATION", format, args);
85  #else
86  vfprintf((GPU_GetDebugLevel() >= GPU_DEBUG_LEVEL_3? stderr : stdout), format, args);
87  #endif
88  va_end(args);
89 }
90 
91 void GPU_LogWarning(const char* format, ...)
92 {
93  va_list args;
94  va_start(args, format);
95  #ifdef __ANDROID__
96  __android_log_vprint((GPU_GetDebugLevel() >= GPU_DEBUG_LEVEL_2? ANDROID_LOG_ERROR : ANDROID_LOG_WARN), "APPLICATION", format, args);
97  #else
98  vfprintf((GPU_GetDebugLevel() >= GPU_DEBUG_LEVEL_2? stderr : stdout), format, args);
99  #endif
100  va_end(args);
101 }
102 
103 void GPU_LogError(const char* format, ...)
104 {
105  va_list args;
106  va_start(args, format);
107  #ifdef __ANDROID__
108  __android_log_vprint(ANDROID_LOG_ERROR, "APPLICATION", format, args);
109  #else
110  vfprintf(stderr, format, args);
111  #endif
112  va_end(args);
113 }
114 
115 
116 static Uint8 init_SDL(void)
117 {
118  if(GPU_GetNumActiveRenderers() == 0)
119  {
120  Uint32 subsystems = SDL_WasInit(SDL_INIT_EVERYTHING);
121  if(!subsystems)
122  {
123  // Nothing has been set up, so init SDL and the video subsystem.
124  if(SDL_Init(SDL_INIT_VIDEO) < 0)
125  {
126  GPU_PushErrorCode("GPU_Init", GPU_ERROR_BACKEND_ERROR, "Failed to initialize SDL video subsystem");
127  return 0;
128  }
129  }
130  else if(!(subsystems & SDL_INIT_VIDEO))
131  {
132  // Something already set up SDL, so just init video.
133  if(SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
134  {
135  GPU_PushErrorCode("GPU_Init", GPU_ERROR_BACKEND_ERROR, "Failed to initialize SDL video subsystem");
136  return 0;
137  }
138  }
139  }
140  return 1;
141 }
142 
143 static Uint32 init_windowID = 0;
144 
145 void GPU_SetInitWindow(Uint32 windowID)
146 {
147  init_windowID = windowID;
148 }
149 
150 Uint32 GPU_GetInitWindow(void)
151 {
152  return init_windowID;
153 }
154 
156 
158 {
159  preinit_flags = GPU_flags;
160 }
161 
163 {
164  return preinit_flags;
165 }
166 
167 static void init_error_stack()
168 {
170  {
171  int i;
173  for(i = 0; i < GPU_MAX_NUM_ERRORS; i++)
174  {
175  error_code_stack[i].function = (char*)malloc(GPU_ERROR_FUNCTION_STRING_MAX+1);
176  error_code_stack[i].details = (char*)malloc(GPU_ERROR_DETAILS_STRING_MAX+1);
177  }
178  }
179 }
180 
181 static void init_window_mappings()
182 {
183  if(window_mappings == NULL)
184  {
186  window_mappings = (GPU_WindowMapping*)malloc(window_mappings_size * sizeof(GPU_WindowMapping));
188  }
189 }
190 
192 {
193  Uint32 windowID;
194  int i;
195 
196  if(window_mappings == NULL)
198 
199  if(target == NULL || target->context == NULL)
200  return;
201 
202  windowID = target->context->windowID;
203  if(windowID == 0) // Invalid window ID
204  return;
205 
206  // Check for duplicates
207  for(i = 0; i < num_window_mappings; i++)
208  {
209  if(window_mappings[i].windowID == windowID)
210  {
211  if(window_mappings[i].target != target)
212  GPU_PushErrorCode(__func__, GPU_ERROR_DATA_ERROR, "WindowID %u already has a mapping.", windowID);
213  return;
214  }
215  // Don't check the target because it's okay for a single target to be used with multiple windows
216  }
217 
218  // Check if list is big enough to hold another
219  if(num_window_mappings >= window_mappings_size)
220  {
221  GPU_WindowMapping* new_array;
223  new_array = (GPU_WindowMapping*)malloc(window_mappings_size * sizeof(GPU_WindowMapping));
224  memcpy(new_array, window_mappings, num_window_mappings * sizeof(GPU_WindowMapping));
225  free(window_mappings);
226  window_mappings = new_array;
227  }
228 
229  // Add to end of list
230  {
231  GPU_WindowMapping m = { windowID, target };
232  window_mappings[num_window_mappings] = m;
233  }
234  num_window_mappings++;
235 }
236 
237 void GPU_RemoveWindowMapping(Uint32 windowID)
238 {
239  int i;
240 
241  if(window_mappings == NULL)
243 
244  if(windowID == 0) // Invalid window ID
245  return;
246 
247  // Find the occurrence
248  for(i = 0; i < num_window_mappings; i++)
249  {
250  if(window_mappings[i].windowID == windowID)
251  {
252  int num_to_move;
253 
254  // Unset the target's window
255  window_mappings[i].target->context->windowID = 0;
256 
257  // Move the remaining entries to replace the removed one
258  num_window_mappings--;
259  num_to_move = num_window_mappings - i;
260  if(num_to_move > 0)
261  memmove(&window_mappings[i], &window_mappings[i+1], num_to_move * sizeof(GPU_WindowMapping));
262  return;
263  }
264  }
265 
266 }
267 
269 {
270  Uint32 windowID;
271  int i;
272 
273  if(window_mappings == NULL)
275 
276  if(target == NULL || target->context == NULL)
277  return;
278 
279  windowID = target->context->windowID;
280  if(windowID == 0) // Invalid window ID
281  return;
282 
283  // Unset the target's window
284  target->context->windowID = 0;
285 
286  // Find the occurrences
287  for(i = 0; i < num_window_mappings; )
288  {
289  if(window_mappings[i].target == target)
290  {
291  // Move the remaining entries to replace the removed one
292  int num_to_move;
293  num_window_mappings--;
294  num_to_move = num_window_mappings - i;
295  if(num_to_move > 0)
296  memmove(&window_mappings[i], &window_mappings[i+1], num_to_move * sizeof(GPU_WindowMapping));
297  return;
298  }
299  else
300  i++;
301  }
302 
303 }
304 
306 {
307  int i;
308 
309  if(window_mappings == NULL)
311 
312  if(windowID == 0) // Invalid window ID
313  return NULL;
314 
315  // Find the occurrence
316  for(i = 0; i < num_window_mappings; i++)
317  {
318  if(window_mappings[i].windowID == windowID)
319  return window_mappings[i].target;
320  }
321 
322  return NULL;
323 }
324 
325 GPU_Target* GPU_Init(Uint16 w, Uint16 h, GPU_WindowFlagEnum SDL_flags)
326 {
328  int i;
330 
332 
334 
335  if(!init_SDL())
336  return NULL;
337 
338  renderer_order_size = 0;
339  GPU_GetRendererOrder(&renderer_order_size, renderer_order);
340 
341  // Init the renderers in order
342  for(i = 0; i < renderer_order_size; i++)
343  {
344  GPU_Target* screen = GPU_InitRendererByID(renderer_order[i], w, h, SDL_flags);
345  if(screen != NULL)
346  return screen;
347  }
348 
349  return NULL;
350 }
351 
352 GPU_Target* GPU_InitRenderer(GPU_RendererEnum renderer_enum, Uint16 w, Uint16 h, GPU_WindowFlagEnum SDL_flags)
353 {
354  return GPU_InitRendererByID(GPU_MakeRendererID(renderer_enum, 0, 0), w, h, SDL_flags);
355 }
356 
357 GPU_Target* GPU_InitRendererByID(GPU_RendererID renderer_request, Uint16 w, Uint16 h, GPU_WindowFlagEnum SDL_flags)
358 {
359  GPU_Renderer* renderer;
361 
364 
365  if(!init_SDL())
366  return NULL;
367 
368  renderer = GPU_AddRenderer(renderer_request);
369  if(renderer == NULL || renderer->Init == NULL)
370  return NULL;
371 
372  GPU_SetCurrentRenderer(renderer->id);
373 
374  screen = renderer->Init(renderer, renderer_request, w, h, SDL_flags);
375  if(screen == NULL)
376  {
377  // Init failed, destroy the renderer...
378  // Erase the window mappings
381  }
382  else
384  return screen;
385 }
386 
388 {
389  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->IsFeatureEnabled == NULL)
390  return 0;
391 
392  return current_renderer->IsFeatureEnabled(current_renderer, feature);
393 }
394 
396 {
397  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->CreateTargetFromWindow == NULL)
398  return NULL;
399 
400  return current_renderer->CreateTargetFromWindow(current_renderer, windowID, NULL);
401 }
402 
404 {
405  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->CreateAliasTarget == NULL)
406  return NULL;
407 
408  return current_renderer->CreateAliasTarget(current_renderer, target);
409 }
410 
411 void GPU_MakeCurrent(GPU_Target* target, Uint32 windowID)
412 {
413  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->MakeCurrent == NULL)
414  return;
415 
416  current_renderer->MakeCurrent(current_renderer, target, windowID);
417 }
418 
419 Uint8 GPU_ToggleFullscreen(Uint8 use_desktop_resolution)
420 {
421  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->ToggleFullscreen == NULL)
422  return 0;
423 
424  return current_renderer->ToggleFullscreen(current_renderer, use_desktop_resolution);
425 }
426 
427 Uint8 GPU_SetWindowResolution(Uint16 w, Uint16 h)
428 {
429  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->SetWindowResolution == NULL || w == 0 || h == 0)
430  return 0;
431 
432  return current_renderer->SetWindowResolution(current_renderer, w, h);
433 }
434 
435 
437 {
438  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->SetVirtualResolution == NULL || w == 0 || h == 0)
439  return;
440 
441  current_renderer->SetVirtualResolution(current_renderer, target, w, h);
442 }
443 
445 {
446  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->UnsetVirtualResolution == NULL)
447  return;
448 
449  current_renderer->UnsetVirtualResolution(current_renderer, target);
450 }
451 
453 {
454  if(current_renderer == NULL)
455  return;
456 
457  if(current_renderer->Quit != NULL)
458  current_renderer->Quit(current_renderer);
459  GPU_RemoveRenderer(current_renderer->id);
460  current_renderer = NULL;
461 }
462 
463 void GPU_Quit(void)
464 {
465  int i;
467  GPU_LogError("GPU_Quit: %d uncleared errors.\n", num_error_codes);
468 
469  // Free the error stack
470  for(i = 0; i < GPU_MAX_NUM_ERRORS; i++)
471  {
472  free(error_code_stack[i].function);
473  error_code_stack[i].function = NULL;
474  free(error_code_stack[i].details);
475  error_code_stack[i].details = NULL;
476  }
478 
479  // FIXME: Remove all renderers
480  if(current_renderer == NULL)
481  return;
482 
483  if(current_renderer->Quit != NULL)
484  current_renderer->Quit(current_renderer);
485  GPU_RemoveRenderer(current_renderer->id);
486 
487  if(GPU_GetNumActiveRenderers() == 0)
488  SDL_Quit();
489 }
490 
492 {
493  if(level > GPU_DEBUG_LEVEL_MAX)
494  level = GPU_DEBUG_LEVEL_MAX;
495  debug_level = level;
496 }
497 
499 {
500  return debug_level;
501 }
502 
503 void GPU_PushErrorCode(const char* function, GPU_ErrorEnum error, const char* details, ...)
504 {
506  {
507  // Print the message
508  if(details != NULL)
509  {
511  va_list lst;
512  va_start(lst, details);
513  vsnprintf(buf, GPU_ERROR_DETAILS_STRING_MAX, details, lst);
514  va_end(lst);
515 
516  GPU_LogError("%s: %s - %s\n", (function == NULL? "NULL" : function), GPU_GetErrorString(error), buf);
517  }
518  else
519  GPU_LogError("%s: %s\n", (function == NULL? "NULL" : function), GPU_GetErrorString(error));
520  }
521 
523  {
524  if(function == NULL)
525  error_code_stack[num_error_codes].function[0] = '\0';
526  else
527  {
528  strncpy(error_code_stack[num_error_codes].function, function, GPU_ERROR_FUNCTION_STRING_MAX);
529  error_code_stack[num_error_codes].function[GPU_ERROR_FUNCTION_STRING_MAX] = '\0';
530  }
531  error_code_stack[num_error_codes].error = error;
532  if(details == NULL)
533  error_code_stack[num_error_codes].details[0] = '\0';
534  else
535  {
536  va_list lst;
537  va_start(lst, details);
538  vsnprintf(error_code_stack[num_error_codes].details, GPU_ERROR_DETAILS_STRING_MAX, details, lst);
539  va_end(lst);
540  }
541  num_error_codes++;
542  }
543 }
544 
546 {
547  if(num_error_codes <= 0)
548  {
549  GPU_ErrorObject e = {NULL, GPU_ERROR_NONE, NULL};
550  return e;
551  }
552 
553  return error_code_stack[--num_error_codes];
554 }
555 
557 {
558  switch(error)
559  {
560  case GPU_ERROR_NONE:
561  return "NO ERROR";
563  return "BACKEND ERROR";
565  return "DATA ERROR";
567  return "USER ERROR";
569  return "UNSUPPORTED FUNCTION";
571  return "NULL ARGUMENT";
573  return "FILE NOT FOUND";
574  }
575  return "UNKNOWN ERROR";
576 }
577 
578 
579 void GPU_GetVirtualCoords(GPU_Target* target, float* x, float* y, float displayX, float displayY)
580 {
581  if(target == NULL)
582  return;
583 
584  if(target->context != NULL)
585  {
586  if(x != NULL)
587  *x = (displayX*target->w)/target->context->window_w;
588  if(y != NULL)
589  *y = (displayY*target->h)/target->context->window_h;
590  }
591  else if(target->image != NULL)
592  {
593  if(x != NULL)
594  *x = (displayX*target->w)/target->image->w;
595  if(y != NULL)
596  *y = (displayY*target->h)/target->image->h;
597  }
598  else
599  {
600  if(x != NULL)
601  *x = displayX;
602  if(y != NULL)
603  *y = displayY;
604  }
605 }
606 
607 GPU_Rect GPU_MakeRect(float x, float y, float w, float h)
608 {
609  GPU_Rect r = {x, y, w, h};
610  return r;
611 }
612 
613 SDL_Color GPU_MakeColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a)
614 {
615  SDL_Color c = {r, g, b, a};
616  return c;
617 }
618 
619 GPU_RendererID GPU_MakeRendererID(GPU_RendererEnum id, int major_version, int minor_version)
620 {
621  GPU_RendererID r = {id, major_version, minor_version, -1};
622  return r;
623 }
624 
626 {
627  if(target != NULL)
628  target->viewport = viewport;
629 }
630 
632 {
633  GPU_Camera cam = {0.0f, 0.0f, -10.0f, 0.0f, 1.0f};
634  return cam;
635 }
636 
638 {
639  if(target == NULL)
640  return GPU_GetDefaultCamera();
641  return target->camera;
642 }
643 
645 {
646  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->SetCamera == NULL)
647  return GPU_GetDefaultCamera();
648 
649  return current_renderer->SetCamera(current_renderer, target, cam);
650 }
651 
653 {
654  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->CreateImage == NULL)
655  return NULL;
656 
657  return current_renderer->CreateImage(current_renderer, w, h, format);
658 }
659 
660 GPU_Image* GPU_LoadImage(const char* filename)
661 {
662  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->LoadImage == NULL)
663  return NULL;
664 
665  return current_renderer->LoadImage(current_renderer, filename);
666 }
667 
669 {
670  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->CreateAliasImage == NULL)
671  return NULL;
672 
673  return current_renderer->CreateAliasImage(current_renderer, image);
674 }
675 
676 Uint8 GPU_SaveImage(GPU_Image* image, const char* filename)
677 {
678  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->SaveImage == NULL)
679  return 0;
680 
681  return current_renderer->SaveImage(current_renderer, image, filename);
682 }
683 
685 {
686  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->CopyImage == NULL)
687  return NULL;
688 
689  return current_renderer->CopyImage(current_renderer, image);
690 }
691 
692 void GPU_UpdateImage(GPU_Image* image, SDL_Surface* surface, const GPU_Rect* surface_rect)
693 {
694  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->UpdateImage == NULL)
695  return;
696 
697  current_renderer->UpdateImage(current_renderer, image, surface, surface_rect);
698 }
699 
700 void GPU_UpdateSubImage(GPU_Image* image, const GPU_Rect* image_rect, SDL_Surface* surface, const GPU_Rect* surface_rect)
701 {
702  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->UpdateSubImage == NULL)
703  return;
704 
705  current_renderer->UpdateSubImage(current_renderer, image, image_rect, surface, surface_rect);
706 }
707 
708 void GPU_UpdateImageBytes(GPU_Image* image, const GPU_Rect* image_rect, const unsigned char* bytes, int bytes_per_row)
709 {
710  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->UpdateImageBytes == NULL)
711  return;
712 
713  current_renderer->UpdateImageBytes(current_renderer, image, image_rect, bytes, bytes_per_row);
714 }
715 
716 SDL_Surface* GPU_LoadSurface(const char* filename)
717 {
718  int width, height, channels;
719  Uint32 Rmask, Gmask, Bmask, Amask = 0;
720  unsigned char* data;
721  SDL_Surface* result;
722 
723  if(filename == NULL)
724  {
725  GPU_PushErrorCode("GPU_LoadSurface", GPU_ERROR_NULL_ARGUMENT, "filename");
726  return NULL;
727  }
728 
729  #ifdef __ANDROID__
730  if(strlen(filename) > 0 && filename[0] != '/')
731  {
732  // Must use SDL_RWops to access the assets directory automatically
733  SDL_RWops* rwops = SDL_RWFromFile(filename, "r");
734  if(rwops == NULL)
735  return NULL;
736  int data_bytes = SDL_RWseek(rwops, 0, SEEK_END);
737  SDL_RWseek(rwops, 0, SEEK_SET);
738  unsigned char* c_data = (unsigned char*)malloc(data_bytes);
739  SDL_RWread(rwops, c_data, 1, data_bytes);
740  data = stbi_load_from_memory(c_data, data_bytes, &width, &height, &channels, 0);
741  free(c_data);
742  SDL_FreeRW(rwops);
743  }
744  else
745  {
746  // Absolute filename
747  data = stbi_load(filename, &width, &height, &channels, 0);
748  }
749  #else
750  data = stbi_load(filename, &width, &height, &channels, 0);
751  #endif
752 
753  if(data == NULL)
754  {
755  GPU_PushErrorCode(__func__, GPU_ERROR_DATA_ERROR, "Failed to load \"%s\": %s", filename, stbi_failure_reason());
756  return NULL;
757  }
758  if(channels < 1 || channels > 4)
759  {
760  GPU_PushErrorCode(__func__, GPU_ERROR_DATA_ERROR, "Failed to load \"%s\": Unsupported pixel format", filename);
761  stbi_image_free(data);
762  return NULL;
763  }
764 
765  switch(channels)
766  {
767  case 1:
768  Rmask = Gmask = Bmask = 0; // Use default RGB masks for 8-bit
769  break;
770  case 2:
771  Rmask = Gmask = Bmask = 0; // Use default RGB masks for 16-bit
772  break;
773  case 3:
774  // These are reversed from what SDL_image uses... That is bad. :( Needs testing.
775  #if SDL_BYTEORDER == SDL_BIG_ENDIAN
776  Rmask = 0xff0000;
777  Gmask = 0x00ff00;
778  Bmask = 0x0000ff;
779  #else
780  Rmask = 0x0000ff;
781  Gmask = 0x00ff00;
782  Bmask = 0xff0000;
783  #endif
784  break;
785  case 4:
786  Rmask = 0x000000ff;
787  Gmask = 0x0000ff00;
788  Bmask = 0x00ff0000;
789  Amask = 0xff000000;
790  break;
791  }
792 
793  result = SDL_CreateRGBSurfaceFrom(data, width, height, channels*8, width*channels, Rmask, Gmask, Bmask, Amask);
794 
795  return result;
796 }
797 
798 #include "stb_image.h"
799 #include "stb_image_write.h"
800 
801 // From http://stackoverflow.com/questions/5309471/getting-file-extension-in-c
802 static const char *get_filename_ext(const char *filename)
803 {
804  const char *dot = strrchr(filename, '.');
805  if(!dot || dot == filename)
806  return "";
807  return dot + 1;
808 }
809 
810 Uint8 GPU_SaveSurface(SDL_Surface* surface, const char* filename)
811 {
812  const char* extension;
813  Uint8 result;
814  unsigned char* data;
815 
816  if(surface == NULL || filename == NULL ||
817  surface->w < 1 || surface->h < 1)
818  {
819  return 0;
820  }
821 
822  extension = get_filename_ext(filename);
823 
824  data = surface->pixels;
825 
826  if(SDL_strcasecmp(extension, "png") == 0)
827  result = stbi_write_png(filename, surface->w, surface->h, surface->format->BytesPerPixel, (const unsigned char *const)data, 0);
828  else if(SDL_strcasecmp(extension, "bmp") == 0)
829  result = stbi_write_bmp(filename, surface->w, surface->h, surface->format->BytesPerPixel, (void*)data);
830  else if(SDL_strcasecmp(extension, "tga") == 0)
831  result = stbi_write_tga(filename, surface->w, surface->h, surface->format->BytesPerPixel, (void*)data);
832  else
833  {
834  GPU_PushErrorCode(__func__, GPU_ERROR_DATA_ERROR, "Unsupported output file format");
835  result = 0;
836  }
837 
838  return result;
839 }
840 
842 {
843  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->CopyImageFromSurface == NULL)
844  return NULL;
845 
846  return current_renderer->CopyImageFromSurface(current_renderer, surface);
847 }
848 
850 {
851  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->CopyImageFromTarget == NULL)
852  return NULL;
853 
854  return current_renderer->CopyImageFromTarget(current_renderer, target);
855 }
856 
858 {
859  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->CopySurfaceFromTarget == NULL)
860  return NULL;
861 
862  return current_renderer->CopySurfaceFromTarget(current_renderer, target);
863 }
864 
866 {
867  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->CopySurfaceFromImage == NULL)
868  return NULL;
869 
870  return current_renderer->CopySurfaceFromImage(current_renderer, image);
871 }
872 
874 {
875  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->FreeImage == NULL)
876  return;
877 
878  current_renderer->FreeImage(current_renderer, image);
879 }
880 
881 
883 {
884  if(current_renderer == NULL)
885  return NULL;
886 
887  return current_renderer->current_context_target;
888 }
889 
890 
892 {
893  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->LoadTarget == NULL)
894  return NULL;
895 
896  return current_renderer->LoadTarget(current_renderer, image);
897 }
898 
899 
900 
902 {
903  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->FreeTarget == NULL)
904  return;
905 
906  current_renderer->FreeTarget(current_renderer, target);
907 }
908 
909 
910 
911 void GPU_Blit(GPU_Image* image, GPU_Rect* src_rect, GPU_Target* target, float x, float y)
912 {
913  if(!CHECK_RENDERER)
914  RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL renderer");
915  if(!CHECK_CONTEXT)
916  RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL context");
919 
920  if(image == NULL)
922  if(target == NULL)
924 
925  current_renderer->Blit(current_renderer, image, src_rect, target, x, y);
926 }
927 
928 
929 void GPU_BlitRotate(GPU_Image* image, GPU_Rect* src_rect, GPU_Target* target, float x, float y, float angle)
930 {
931  if(!CHECK_RENDERER)
932  RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL renderer");
933  if(!CHECK_CONTEXT)
934  RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL context");
937 
938  if(image == NULL)
940  if(target == NULL)
942 
943  current_renderer->BlitRotate(current_renderer, image, src_rect, target, x, y, angle);
944 }
945 
946 void GPU_BlitScale(GPU_Image* image, GPU_Rect* src_rect, GPU_Target* target, float x, float y, float scaleX, float scaleY)
947 {
948  if(!CHECK_RENDERER)
949  RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL renderer");
950  if(!CHECK_CONTEXT)
951  RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL context");
954 
955  if(image == NULL)
957  if(target == NULL)
959 
960  current_renderer->BlitScale(current_renderer, image, src_rect, target, x, y, scaleX, scaleY);
961 }
962 
963 void GPU_BlitTransform(GPU_Image* image, GPU_Rect* src_rect, GPU_Target* target, float x, float y, float angle, float scaleX, float scaleY)
964 {
965  if(!CHECK_RENDERER)
966  RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL renderer");
967  if(!CHECK_CONTEXT)
968  RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL context");
971 
972  if(image == NULL)
974  if(target == NULL)
976 
977  current_renderer->BlitTransform(current_renderer, image, src_rect, target, x, y, angle, scaleX, scaleY);
978 }
979 
980 void GPU_BlitTransformX(GPU_Image* image, GPU_Rect* src_rect, GPU_Target* target, float x, float y, float pivot_x, float pivot_y, float angle, float scaleX, float scaleY)
981 {
982  if(!CHECK_RENDERER)
983  RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL renderer");
984  if(!CHECK_CONTEXT)
985  RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL context");
988 
989  if(image == NULL)
991  if(target == NULL)
993 
994  current_renderer->BlitTransformX(current_renderer, image, src_rect, target, x, y, pivot_x, pivot_y, angle, scaleX, scaleY);
995 }
996 
997 void GPU_BlitTransformMatrix(GPU_Image* image, GPU_Rect* src_rect, GPU_Target* target, float x, float y, float* matrix3x3)
998 {
999  if(!CHECK_RENDERER)
1000  RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL renderer");
1001  if(!CHECK_CONTEXT)
1002  RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL context");
1005 
1006  if(image == NULL)
1008  if(target == NULL)
1010 
1011  if(matrix3x3 == NULL)
1012  return;
1013 
1014  current_renderer->BlitTransformMatrix(current_renderer, image, src_rect, target, x, y, matrix3x3);
1015 }
1016 
1017 void GPU_BlitBatch(GPU_Image* image, GPU_Target* target, unsigned int num_sprites, float* values, GPU_BlitFlagEnum flags)
1018 {
1019  int src_position_floats_per_sprite;
1020  int src_rect_floats_per_sprite;
1021  int src_color_floats_per_sprite;
1022 
1023  Uint8 no_positions;
1024  Uint8 no_rects;
1025  Uint8 no_colors;
1026  Uint8 pass_vertices;
1027  Uint8 pass_texcoords;
1028  Uint8 pass_colors;
1029 
1030  int src_floats_per_sprite;
1031 
1032  int size;
1033  float* new_values;
1034 
1035  int n; // The sprite number iteration variable.
1036  // Source indices (per sprite)
1037  int pos_n;
1038  int rect_n;
1039  int color_n;
1040  // Dest indices
1041  int vert_i;
1042  int texcoord_i;
1043  int color_i;
1044  // Dest float stride
1045  int floats_per_vertex;
1046 
1047  float w2; // texcoord helpers for position expansion
1048  float h2;
1049 
1050  float tex_w;
1051  float tex_h;
1052 
1053  if(!CHECK_RENDERER)
1054  RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL renderer");
1055  if(!CHECK_CONTEXT)
1056  RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL context");
1059 
1060  if(image == NULL)
1062  if(target == NULL)
1064 
1065  if(num_sprites == 0)
1066  return;
1067 
1068  // Is it already in the right format?
1069  if((flags & GPU_PASSTHROUGH_ALL) == GPU_PASSTHROUGH_ALL || values == NULL)
1070  {
1071  current_renderer->BlitBatch(current_renderer, image, target, num_sprites, values, flags);
1072  return;
1073  }
1074 
1075  // Conversion time...
1076 
1077  // Convert condensed interleaved format into full interleaved format for the renderer to use.
1078  // Condensed: Each vertex has 2 pos, 4 rect, 4 color
1079 
1080  // Default values: Each sprite is defined by a position, a rect, and a color.
1081  src_position_floats_per_sprite = 2;
1082  src_rect_floats_per_sprite = 4;
1083  src_color_floats_per_sprite = 4;
1084 
1085  no_positions = (flags & GPU_USE_DEFAULT_POSITIONS);
1086  no_rects = (flags & GPU_USE_DEFAULT_SRC_RECTS);
1087  no_colors = (flags & GPU_USE_DEFAULT_COLORS);
1088  pass_vertices = (flags & GPU_PASSTHROUGH_VERTICES);
1089  pass_texcoords = (flags & GPU_PASSTHROUGH_TEXCOORDS);
1090  pass_colors = (flags & GPU_PASSTHROUGH_COLORS);
1091 
1092  // Passthrough data is per-vertex. Non-passthrough is per-sprite. They can't interleave cleanly.
1093  if(flags & GPU_PASSTHROUGH_ALL && (flags & GPU_PASSTHROUGH_ALL) != GPU_PASSTHROUGH_ALL)
1094  {
1095  GPU_PushErrorCode(__func__, GPU_ERROR_USER_ERROR, "Cannot interpret interleaved data using partial passthrough");
1096  return;
1097  }
1098 
1099  if(pass_vertices)
1100  src_position_floats_per_sprite = 8; // 4 vertices of x, y
1101  if(pass_texcoords)
1102  src_rect_floats_per_sprite = 8; // 4 vertices of s, t
1103  if(pass_colors)
1104  src_color_floats_per_sprite = 16; // 4 vertices of r, g, b, a
1105  if(no_positions)
1106  src_position_floats_per_sprite = 0;
1107  if(no_rects)
1108  src_rect_floats_per_sprite = 0;
1109  if(no_colors)
1110  src_color_floats_per_sprite = 0;
1111 
1112  src_floats_per_sprite = src_position_floats_per_sprite + src_rect_floats_per_sprite + src_color_floats_per_sprite;
1113 
1114  size = num_sprites*(8 + 8 + 16);
1115  new_values = (float*)malloc(sizeof(float)*size);
1116 
1117  // Source indices (per sprite)
1118  pos_n = 0;
1119  rect_n = src_position_floats_per_sprite;
1120  color_n = src_position_floats_per_sprite + src_rect_floats_per_sprite;
1121  // Dest indices
1122  vert_i = 0;
1123  texcoord_i = 2;
1124  color_i = 4;
1125  // Dest float stride
1126  floats_per_vertex = 8;
1127 
1128  w2 = 0.5f*image->w; // texcoord helpers for position expansion
1129  h2 = 0.5f*image->h;
1130 
1131  tex_w = image->texture_w;
1132  tex_h = image->texture_h;
1133 
1134  for(n = 0; n < num_sprites; n++)
1135  {
1136  if(no_rects)
1137  {
1138  new_values[texcoord_i] = 0.0f;
1139  new_values[texcoord_i+1] = 0.0f;
1140  texcoord_i += floats_per_vertex;
1141  new_values[texcoord_i] = 1.0f;
1142  new_values[texcoord_i+1] = 0.0f;
1143  texcoord_i += floats_per_vertex;
1144  new_values[texcoord_i] = 1.0f;
1145  new_values[texcoord_i+1] = 1.0f;
1146  texcoord_i += floats_per_vertex;
1147  new_values[texcoord_i] = 0.0f;
1148  new_values[texcoord_i+1] = 1.0f;
1149  texcoord_i += floats_per_vertex;
1150  }
1151  else
1152  {
1153  if(!pass_texcoords)
1154  {
1155  float s1 = values[rect_n]/tex_w;
1156  float t1 = values[rect_n+1]/tex_h;
1157  float s3 = s1 + values[rect_n+2]/tex_w;
1158  float t3 = t1 + values[rect_n+3]/tex_h;
1159  rect_n += src_floats_per_sprite;
1160 
1161  new_values[texcoord_i] = s1;
1162  new_values[texcoord_i+1] = t1;
1163  texcoord_i += floats_per_vertex;
1164  new_values[texcoord_i] = s3;
1165  new_values[texcoord_i+1] = t1;
1166  texcoord_i += floats_per_vertex;
1167  new_values[texcoord_i] = s3;
1168  new_values[texcoord_i+1] = t3;
1169  texcoord_i += floats_per_vertex;
1170  new_values[texcoord_i] = s1;
1171  new_values[texcoord_i+1] = t3;
1172  texcoord_i += floats_per_vertex;
1173 
1174  if(!pass_vertices)
1175  {
1176  w2 = 0.5f*(s3-s1)*image->w;
1177  h2 = 0.5f*(t3-t1)*image->h;
1178  }
1179  }
1180  else
1181  {
1182  // 4 vertices all in a row
1183  float s1, t1, s3, t3;
1184  s1 = new_values[texcoord_i] = values[rect_n];
1185  t1 = new_values[texcoord_i+1] = values[rect_n+1];
1186  texcoord_i += floats_per_vertex;
1187  new_values[texcoord_i] = values[rect_n+2];
1188  new_values[texcoord_i+1] = values[rect_n+3];
1189  texcoord_i += floats_per_vertex;
1190  s3 = new_values[texcoord_i] = values[rect_n+4];
1191  t3 = new_values[texcoord_i+1] = values[rect_n+5];
1192  texcoord_i += floats_per_vertex;
1193  new_values[texcoord_i] = values[rect_n+6];
1194  new_values[texcoord_i+1] = values[rect_n+7];
1195  texcoord_i += floats_per_vertex;
1196  rect_n += src_floats_per_sprite;
1197 
1198  if(!pass_vertices)
1199  {
1200  w2 = 0.5f*(s3-s1)*image->w;
1201  h2 = 0.5f*(t3-t1)*image->h;
1202  }
1203  }
1204  }
1205 
1206  if(no_positions)
1207  {
1208  new_values[vert_i] = 0.0f;
1209  new_values[vert_i+1] = 0.0f;
1210  vert_i += floats_per_vertex;
1211  new_values[vert_i] = 0.0f;
1212  new_values[vert_i+1] = 0.0f;
1213  vert_i += floats_per_vertex;
1214  new_values[vert_i] = 0.0f;
1215  new_values[vert_i+1] = 0.0f;
1216  vert_i += floats_per_vertex;
1217  new_values[vert_i] = 0.0f;
1218  new_values[vert_i+1] = 0.0f;
1219  vert_i += floats_per_vertex;
1220  }
1221  else
1222  {
1223  if(!pass_vertices)
1224  {
1225  // Expand vertices from the position and dimensions
1226  float x = values[pos_n];
1227  float y = values[pos_n+1];
1228  pos_n += src_floats_per_sprite;
1229 
1230  new_values[vert_i] = x - w2;
1231  new_values[vert_i+1] = y - h2;
1232  vert_i += floats_per_vertex;
1233  new_values[vert_i] = x + w2;
1234  new_values[vert_i+1] = y - h2;
1235  vert_i += floats_per_vertex;
1236  new_values[vert_i] = x + w2;
1237  new_values[vert_i+1] = y + h2;
1238  vert_i += floats_per_vertex;
1239  new_values[vert_i] = x - w2;
1240  new_values[vert_i+1] = y + h2;
1241  vert_i += floats_per_vertex;
1242  }
1243  else
1244  {
1245  // 4 vertices all in a row
1246  new_values[vert_i] = values[pos_n];
1247  new_values[vert_i+1] = values[pos_n+1];
1248  vert_i += floats_per_vertex;
1249  new_values[vert_i] = values[pos_n+2];
1250  new_values[vert_i+1] = values[pos_n+3];
1251  vert_i += floats_per_vertex;
1252  new_values[vert_i] = values[pos_n+4];
1253  new_values[vert_i+1] = values[pos_n+5];
1254  vert_i += floats_per_vertex;
1255  new_values[vert_i] = values[pos_n+6];
1256  new_values[vert_i+1] = values[pos_n+7];
1257  vert_i += floats_per_vertex;
1258  pos_n += src_floats_per_sprite;
1259  }
1260  }
1261 
1262  if(no_colors)
1263  {
1264  new_values[color_i] = 1.0f;
1265  new_values[color_i+1] = 1.0f;
1266  new_values[color_i+2] = 1.0f;
1267  new_values[color_i+3] = 1.0f;
1268  color_i += floats_per_vertex;
1269  new_values[color_i] = 1.0f;
1270  new_values[color_i+1] = 1.0f;
1271  new_values[color_i+2] = 1.0f;
1272  new_values[color_i+3] = 1.0f;
1273  color_i += floats_per_vertex;
1274  new_values[color_i] = 1.0f;
1275  new_values[color_i+1] = 1.0f;
1276  new_values[color_i+2] = 1.0f;
1277  new_values[color_i+3] = 1.0f;
1278  color_i += floats_per_vertex;
1279  new_values[color_i] = 1.0f;
1280  new_values[color_i+1] = 1.0f;
1281  new_values[color_i+2] = 1.0f;
1282  new_values[color_i+3] = 1.0f;
1283  color_i += floats_per_vertex;
1284  }
1285  else
1286  {
1287  if(!pass_colors)
1288  {
1289  float r = values[color_n]/255.0f;
1290  float g = values[color_n+1]/255.0f;
1291  float b = values[color_n+2]/255.0f;
1292  float a = values[color_n+3]/255.0f;
1293  color_n += src_floats_per_sprite;
1294 
1295  new_values[color_i] = r;
1296  new_values[color_i+1] = g;
1297  new_values[color_i+2] = b;
1298  new_values[color_i+3] = a;
1299  color_i += floats_per_vertex;
1300  new_values[color_i] = r;
1301  new_values[color_i+1] = g;
1302  new_values[color_i+2] = b;
1303  new_values[color_i+3] = a;
1304  color_i += floats_per_vertex;
1305  new_values[color_i] = r;
1306  new_values[color_i+1] = g;
1307  new_values[color_i+2] = b;
1308  new_values[color_i+3] = a;
1309  color_i += floats_per_vertex;
1310  new_values[color_i] = r;
1311  new_values[color_i+1] = g;
1312  new_values[color_i+2] = b;
1313  new_values[color_i+3] = a;
1314  color_i += floats_per_vertex;
1315  }
1316  else
1317  {
1318  // 4 vertices all in a row
1319  new_values[color_i] = values[color_n];
1320  new_values[color_i+1] = values[color_n+1];
1321  new_values[color_i+2] = values[color_n+2];
1322  new_values[color_i+3] = values[color_n+3];
1323  color_i += floats_per_vertex;
1324  new_values[color_i] = values[color_n+4];
1325  new_values[color_i+1] = values[color_n+5];
1326  new_values[color_i+2] = values[color_n+6];
1327  new_values[color_i+3] = values[color_n+7];
1328  color_i += floats_per_vertex;
1329  new_values[color_i] = values[color_n+8];
1330  new_values[color_i+1] = values[color_n+9];
1331  new_values[color_i+2] = values[color_n+10];
1332  new_values[color_i+3] = values[color_n+11];
1333  color_i += floats_per_vertex;
1334  new_values[color_i] = values[color_n+12];
1335  new_values[color_i+1] = values[color_n+13];
1336  new_values[color_i+2] = values[color_n+14];
1337  new_values[color_i+3] = values[color_n+15];
1338  color_i += floats_per_vertex;
1339  color_n += src_floats_per_sprite;
1340  }
1341  }
1342  }
1343 
1344  current_renderer->BlitBatch(current_renderer, image, target, num_sprites, new_values, flags | GPU_PASSTHROUGH_ALL);
1345 
1346  free(new_values);
1347 }
1348 
1349 void GPU_BlitBatchSeparate(GPU_Image* image, GPU_Target* target, unsigned int num_sprites, float* positions, float* src_rects, float* colors, GPU_BlitFlagEnum flags)
1350 {
1351  Uint8 pass_vertices;
1352  Uint8 pass_texcoords;
1353  Uint8 pass_colors;
1354 
1355  int size; // 4 vertices of x, y... s, t... r, g, b, a
1356  float* values;
1357 
1358  int n; // The sprite number iteration variable.
1359  // Source indices
1360  int pos_n;
1361  int rect_n;
1362  int color_n;
1363  // Dest indices
1364  int vert_i;
1365  int texcoord_i;
1366  int color_i;
1367  // Dest float stride
1368  int floats_per_vertex;
1369 
1370  float w2; // texcoord helpers for position expansion
1371  float h2;
1372 
1373  float tex_w;
1374  float tex_h;
1375 
1376  if(!CHECK_RENDERER)
1377  RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL renderer");
1378  if(!CHECK_CONTEXT)
1379  RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL context");
1382 
1383  if(image == NULL)
1385  if(target == NULL)
1387 
1388  if(num_sprites == 0)
1389  return;
1390 
1391  // No data to repack? Skip it.
1392  if(positions == NULL && src_rects == NULL && colors == NULL)
1393  {
1394  current_renderer->BlitBatch(current_renderer, image, target, num_sprites, NULL, flags);
1395  return;
1396  }
1397 
1398  // Repack the given arrays into an interleaved array for more efficient access
1399  // Default values: Each sprite is defined by a position, a rect, and a color.
1400 
1401  pass_vertices = (flags & GPU_PASSTHROUGH_VERTICES);
1402  pass_texcoords = (flags & GPU_PASSTHROUGH_TEXCOORDS);
1403  pass_colors = (flags & GPU_PASSTHROUGH_COLORS);
1404 
1405  size = num_sprites*(8 + 8 + 16); // 4 vertices of x, y... s, t... r, g, b, a
1406  values = (float*)malloc(sizeof(float)*size);
1407 
1408  // Source indices
1409  pos_n = 0;
1410  rect_n = 0;
1411  color_n = 0;
1412  // Dest indices
1413  vert_i = 0;
1414  texcoord_i = 2;
1415  color_i = 4;
1416  // Dest float stride
1417  floats_per_vertex = 8;
1418 
1419  w2 = 0.5f*image->w; // texcoord helpers for position expansion
1420  h2 = 0.5f*image->h;
1421 
1422  tex_w = image->texture_w;
1423  tex_h = image->texture_h;
1424 
1425  for(n = 0; n < num_sprites; n++)
1426  {
1427  // Unpack the arrays
1428 
1429  if(src_rects == NULL)
1430  {
1431  values[texcoord_i] = 0.0f;
1432  values[texcoord_i+1] = 0.0f;
1433  texcoord_i += floats_per_vertex;
1434  values[texcoord_i] = 1.0f;
1435  values[texcoord_i+1] = 0.0f;
1436  texcoord_i += floats_per_vertex;
1437  values[texcoord_i] = 1.0f;
1438  values[texcoord_i+1] = 1.0f;
1439  texcoord_i += floats_per_vertex;
1440  values[texcoord_i] = 0.0f;
1441  values[texcoord_i+1] = 1.0f;
1442  texcoord_i += floats_per_vertex;
1443  }
1444  else
1445  {
1446  if(!pass_texcoords)
1447  {
1448  float s1 = src_rects[rect_n++]/tex_w;
1449  float t1 = src_rects[rect_n++]/tex_h;
1450  float s3 = s1 + src_rects[rect_n++]/tex_w;
1451  float t3 = t1 + src_rects[rect_n++]/tex_h;
1452 
1453  values[texcoord_i] = s1;
1454  values[texcoord_i+1] = t1;
1455  texcoord_i += floats_per_vertex;
1456  values[texcoord_i] = s3;
1457  values[texcoord_i+1] = t1;
1458  texcoord_i += floats_per_vertex;
1459  values[texcoord_i] = s3;
1460  values[texcoord_i+1] = t3;
1461  texcoord_i += floats_per_vertex;
1462  values[texcoord_i] = s1;
1463  values[texcoord_i+1] = t3;
1464  texcoord_i += floats_per_vertex;
1465 
1466  if(!pass_vertices)
1467  {
1468  w2 = 0.5f*(s3-s1)*image->w;
1469  h2 = 0.5f*(t3-t1)*image->h;
1470  }
1471  }
1472  else
1473  {
1474  // 4 vertices all in a row
1475  float s1, t1, s3, t3;
1476  s1 = values[texcoord_i] = src_rects[rect_n++];
1477  t1 = values[texcoord_i+1] = src_rects[rect_n++];
1478  texcoord_i += floats_per_vertex;
1479  values[texcoord_i] = src_rects[rect_n++];
1480  values[texcoord_i+1] = src_rects[rect_n++];
1481  texcoord_i += floats_per_vertex;
1482  s3 = values[texcoord_i] = src_rects[rect_n++];
1483  t3 = values[texcoord_i+1] = src_rects[rect_n++];
1484  texcoord_i += floats_per_vertex;
1485  values[texcoord_i] = src_rects[rect_n++];
1486  values[texcoord_i+1] = src_rects[rect_n++];
1487  texcoord_i += floats_per_vertex;
1488 
1489  if(!pass_vertices)
1490  {
1491  w2 = 0.5f*(s3-s1)*image->w;
1492  h2 = 0.5f*(t3-t1)*image->h;
1493  }
1494  }
1495  }
1496 
1497  if(positions == NULL)
1498  {
1499  values[vert_i] = 0.0f;
1500  values[vert_i+1] = 0.0f;
1501  vert_i += floats_per_vertex;
1502  values[vert_i] = 0.0f;
1503  values[vert_i+1] = 0.0f;
1504  vert_i += floats_per_vertex;
1505  values[vert_i] = 0.0f;
1506  values[vert_i+1] = 0.0f;
1507  vert_i += floats_per_vertex;
1508  values[vert_i] = 0.0f;
1509  values[vert_i+1] = 0.0f;
1510  vert_i += floats_per_vertex;
1511  }
1512  else
1513  {
1514  if(!pass_vertices)
1515  {
1516  // Expand vertices from the position and dimensions
1517  float x = positions[pos_n++];
1518  float y = positions[pos_n++];
1519  values[vert_i] = x - w2;
1520  values[vert_i+1] = y - h2;
1521  vert_i += floats_per_vertex;
1522  values[vert_i] = x + w2;
1523  values[vert_i+1] = y - h2;
1524  vert_i += floats_per_vertex;
1525  values[vert_i] = x + w2;
1526  values[vert_i+1] = y + h2;
1527  vert_i += floats_per_vertex;
1528  values[vert_i] = x - w2;
1529  values[vert_i+1] = y + h2;
1530  vert_i += floats_per_vertex;
1531  }
1532  else
1533  {
1534  // 4 vertices all in a row
1535  values[vert_i] = positions[pos_n++];
1536  values[vert_i+1] = positions[pos_n++];
1537  vert_i += floats_per_vertex;
1538  values[vert_i] = positions[pos_n++];
1539  values[vert_i+1] = positions[pos_n++];
1540  vert_i += floats_per_vertex;
1541  values[vert_i] = positions[pos_n++];
1542  values[vert_i+1] = positions[pos_n++];
1543  vert_i += floats_per_vertex;
1544  values[vert_i] = positions[pos_n++];
1545  values[vert_i+1] = positions[pos_n++];
1546  vert_i += floats_per_vertex;
1547  }
1548  }
1549 
1550  if(colors == NULL)
1551  {
1552  values[color_i] = 1.0f;
1553  values[color_i+1] = 1.0f;
1554  values[color_i+2] = 1.0f;
1555  values[color_i+3] = 1.0f;
1556  color_i += floats_per_vertex;
1557  values[color_i] = 1.0f;
1558  values[color_i+1] = 1.0f;
1559  values[color_i+2] = 1.0f;
1560  values[color_i+3] = 1.0f;
1561  color_i += floats_per_vertex;
1562  values[color_i] = 1.0f;
1563  values[color_i+1] = 1.0f;
1564  values[color_i+2] = 1.0f;
1565  values[color_i+3] = 1.0f;
1566  color_i += floats_per_vertex;
1567  values[color_i] = 1.0f;
1568  values[color_i+1] = 1.0f;
1569  values[color_i+2] = 1.0f;
1570  values[color_i+3] = 1.0f;
1571  color_i += floats_per_vertex;
1572  }
1573  else
1574  {
1575  if(!pass_colors)
1576  {
1577  float r = colors[color_n++]/255.0f;
1578  float g = colors[color_n++]/255.0f;
1579  float b = colors[color_n++]/255.0f;
1580  float a = colors[color_n++]/255.0f;
1581 
1582  values[color_i] = r;
1583  values[color_i+1] = g;
1584  values[color_i+2] = b;
1585  values[color_i+3] = a;
1586  color_i += floats_per_vertex;
1587  values[color_i] = r;
1588  values[color_i+1] = g;
1589  values[color_i+2] = b;
1590  values[color_i+3] = a;
1591  color_i += floats_per_vertex;
1592  values[color_i] = r;
1593  values[color_i+1] = g;
1594  values[color_i+2] = b;
1595  values[color_i+3] = a;
1596  color_i += floats_per_vertex;
1597  values[color_i] = r;
1598  values[color_i+1] = g;
1599  values[color_i+2] = b;
1600  values[color_i+3] = a;
1601  color_i += floats_per_vertex;
1602  }
1603  else
1604  {
1605  // 4 vertices all in a row
1606  values[color_i] = colors[color_n++];
1607  values[color_i+1] = colors[color_n++];
1608  values[color_i+2] = colors[color_n++];
1609  values[color_i+3] = colors[color_n++];
1610  color_i += floats_per_vertex;
1611  values[color_i] = colors[color_n++];
1612  values[color_i+1] = colors[color_n++];
1613  values[color_i+2] = colors[color_n++];
1614  values[color_i+3] = colors[color_n++];
1615  color_i += floats_per_vertex;
1616  values[color_i] = colors[color_n++];
1617  values[color_i+1] = colors[color_n++];
1618  values[color_i+2] = colors[color_n++];
1619  values[color_i+3] = colors[color_n++];
1620  color_i += floats_per_vertex;
1621  values[color_i] = colors[color_n++];
1622  values[color_i+1] = colors[color_n++];
1623  values[color_i+2] = colors[color_n++];
1624  values[color_i+3] = colors[color_n++];
1625  color_i += floats_per_vertex;
1626  }
1627  }
1628  }
1629 
1630  current_renderer->BlitBatch(current_renderer, image, target, num_sprites, values, flags | GPU_PASSTHROUGH_ALL);
1631  free(values);
1632 }
1633 
1634 void GPU_TriangleBatch(GPU_Image* image, GPU_Target* target, unsigned short num_vertices, float* values, unsigned int num_indices, unsigned short* indices, GPU_BlitFlagEnum flags)
1635 {
1636  int src_position_floats_per_vertex;
1637  int src_texcoord_floats_per_vertex;
1638  int src_color_floats_per_vertex;
1639 
1640  Uint8 no_positions;
1641  Uint8 no_texcoords;
1642  Uint8 no_colors;
1643  Uint8 pass_texcoords;
1644  Uint8 pass_colors;
1645 
1646  int src_floats_per_vertex;
1647 
1648  int size;
1649  float* new_values;
1650 
1651  int n; // Vertex number iteration variable
1652  // Source indices
1653  int pos_n;
1654  int texcoord_n;
1655  int color_n;
1656  // Dest indices
1657  int vert_i;
1658 
1659  float tex_w;
1660  float tex_h;
1661 
1662  if(!CHECK_RENDERER)
1663  RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL renderer");
1664  if(!CHECK_CONTEXT)
1665  RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL context");
1668 
1669  if(image == NULL)
1671  if(target == NULL)
1673 
1674  if(num_vertices == 0)
1675  return;
1676 
1677  // Is it already in the right format?
1678  if((flags & GPU_PASSTHROUGH_ALL) == GPU_PASSTHROUGH_ALL || values == NULL)
1679  {
1680  current_renderer->TriangleBatch(current_renderer, image, target, num_vertices, values, num_indices, indices, flags);
1681  return;
1682  }
1683 
1684  // Conversion time...
1685 
1686  // Convert texcoords and colors for the renderer to use.
1687  // Condensed: Each vertex has 2 pos, 2 texcoords, 4 color components
1688 
1689  // Default values: Each vertex is defined by a position, texcoords, and a color.
1690  src_position_floats_per_vertex = 2;
1691  src_texcoord_floats_per_vertex = 2;
1692  src_color_floats_per_vertex = 4;
1693 
1694  no_positions = (flags & GPU_USE_DEFAULT_POSITIONS);
1695  no_texcoords = (flags & GPU_USE_DEFAULT_SRC_RECTS);
1696  no_colors = (flags & GPU_USE_DEFAULT_COLORS);
1697  pass_texcoords = (flags & GPU_PASSTHROUGH_TEXCOORDS);
1698  pass_colors = (flags & GPU_PASSTHROUGH_COLORS);
1699 
1700  // Vertex position passthrough is ignored (we're not positioning triangles, we're positioning vertices already)
1701  src_position_floats_per_vertex = 2; // x, y
1702  if(pass_texcoords)
1703  src_texcoord_floats_per_vertex = 2; // s, t
1704  if(pass_colors)
1705  src_color_floats_per_vertex = 4; // r, g, b, a
1706  if(no_positions)
1707  src_position_floats_per_vertex = 0;
1708  if(no_texcoords)
1709  src_texcoord_floats_per_vertex = 0;
1710  if(no_colors)
1711  src_color_floats_per_vertex = 0;
1712 
1713  src_floats_per_vertex = src_position_floats_per_vertex + src_texcoord_floats_per_vertex + src_color_floats_per_vertex;
1714 
1715  size = num_vertices*(2 + 2 + 4);
1716  new_values = (float*)malloc(sizeof(float)*size);
1717 
1718  // Source indices
1719  pos_n = 0;
1720  texcoord_n = src_position_floats_per_vertex;
1721  color_n = src_position_floats_per_vertex + src_texcoord_floats_per_vertex;
1722  // Dest indices
1723  vert_i = 0;
1724 
1725  tex_w = image->texture_w;
1726  tex_h = image->texture_h;
1727 
1728  for(n = 0; n < num_vertices; n++)
1729  {
1730  // 2 floats from position
1731  if(no_positions)
1732  {
1733  new_values[vert_i++] = 0.0f;
1734  new_values[vert_i++] = 0.0f;
1735  }
1736  else
1737  {
1738  new_values[vert_i++] = values[pos_n];
1739  new_values[vert_i++] = values[pos_n+1];
1740  pos_n += src_floats_per_vertex;
1741  }
1742 
1743  // 2 floats from texcoords
1744  if(no_texcoords)
1745  {
1746  new_values[vert_i++] = 0.0f;
1747  new_values[vert_i++] = 0.0f;
1748  }
1749  else
1750  {
1751  if(!pass_texcoords)
1752  {
1753  new_values[vert_i++] = values[texcoord_n]/tex_w;
1754  new_values[vert_i++] = values[texcoord_n+1]/tex_h;
1755  texcoord_n += src_floats_per_vertex;
1756  }
1757  else
1758  {
1759  new_values[vert_i++] = values[texcoord_n];
1760  new_values[vert_i++] = values[texcoord_n+1];
1761  }
1762  }
1763 
1764  if(no_colors)
1765  {
1766  new_values[vert_i++] = 1.0f;
1767  new_values[vert_i++] = 1.0f;
1768  new_values[vert_i++] = 1.0f;
1769  new_values[vert_i++] = 1.0f;
1770  }
1771  else
1772  {
1773  if(!pass_colors)
1774  {
1775  new_values[vert_i++] = values[color_n]/255.0f;
1776  new_values[vert_i++] = values[color_n+1]/255.0f;
1777  new_values[vert_i++] = values[color_n+2]/255.0f;
1778  new_values[vert_i++] = values[color_n+3]/255.0f;
1779  color_n += src_floats_per_vertex;
1780  }
1781  else
1782  {
1783  new_values[vert_i++] = values[color_n];
1784  new_values[vert_i++] = values[color_n+1];
1785  new_values[vert_i++] = values[color_n+2];
1786  new_values[vert_i++] = values[color_n+3];
1787  color_n += src_floats_per_vertex;
1788  }
1789  }
1790  }
1791 
1792  current_renderer->TriangleBatch(current_renderer, image, target, num_vertices, new_values, num_indices, indices, flags | GPU_PASSTHROUGH_ALL);
1793 
1794  free(new_values);
1795 }
1796 
1797 
1798 
1799 
1801 {
1802  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->GenerateMipmaps == NULL)
1803  return;
1804 
1805  current_renderer->GenerateMipmaps(current_renderer, image);
1806 }
1807 
1808 
1809 
1810 
1812 {
1813  if(target == NULL || current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->SetClip == NULL)
1814  {
1815  GPU_Rect r = {0,0,0,0};
1816  return r;
1817  }
1818 
1819  return current_renderer->SetClip(current_renderer, target, rect.x, rect.y, rect.w, rect.h);
1820 }
1821 
1822 GPU_Rect GPU_SetClip(GPU_Target* target, Sint16 x, Sint16 y, Uint16 w, Uint16 h)
1823 {
1824  if(target == NULL || current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->SetClip == NULL)
1825  {
1826  GPU_Rect r = {0,0,0,0};
1827  return r;
1828  }
1829 
1830  return current_renderer->SetClip(current_renderer, target, x, y, w, h);
1831 }
1832 
1834 {
1835  if(target == NULL || current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->UnsetClip == NULL)
1836  return;
1837 
1838  current_renderer->UnsetClip(current_renderer, target);
1839 }
1840 
1841 
1842 
1843 
1844 void GPU_SetColor(GPU_Image* image, SDL_Color* color)
1845 {
1846  if(image == NULL)
1847  return;
1848 
1849  if(color == NULL)
1850  {
1851  SDL_Color c = {255, 255, 255, 255};
1852  image->color = c;
1853  }
1854  else
1855  image->color = *color;
1856 }
1857 
1858 void GPU_SetRGB(GPU_Image* image, Uint8 r, Uint8 g, Uint8 b)
1859 {
1860  SDL_Color c = {r, g, b, 255};
1861 
1862  if(image == NULL)
1863  return;
1864 
1865  image->color = c;
1866 }
1867 
1868 void GPU_SetRGBA(GPU_Image* image, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
1869 {
1870  SDL_Color c = {r, g, b, a};
1871 
1872  if(image == NULL)
1873  return;
1874 
1875  image->color = c;
1876 }
1877 
1879 {
1880  if(target == NULL)
1881  return;
1882 
1883  if(color == NULL)
1884  target->use_color = 0;
1885  else
1886  {
1887  target->use_color = 1;
1888  target->color = *color;
1889  }
1890 }
1891 
1892 void GPU_SetTargetRGB(GPU_Target* target, Uint8 r, Uint8 g, Uint8 b)
1893 {
1894  if(target == NULL)
1895  return;
1896 
1897  if(r == 255 && g == 255 && b == 255)
1898  target->use_color = 0;
1899  else
1900  {
1901  SDL_Color c = {r, g, b, 255};
1902  target->use_color = 1;
1903  target->color = c;
1904  }
1905 }
1906 
1907 void GPU_SetTargetRGBA(GPU_Target* target, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
1908 {
1909  if(target == NULL)
1910  return;
1911 
1912  if(r == 255 && g == 255 && b == 255 && a == 255)
1913  target->use_color = 0;
1914  else
1915  {
1916  SDL_Color c = {r, g, b, a};
1917  target->use_color = 1;
1918  target->color = c;
1919  }
1920 }
1921 
1923 {
1924  if(image == NULL)
1925  return 0;
1926 
1927  return image->use_blending;
1928 }
1929 
1930 
1932 {
1933  if(image == NULL)
1934  return;
1935 
1936  image->use_blending = enable;
1937 }
1938 
1940 {
1941  if(current_renderer == NULL || current_renderer->current_context_target == NULL)
1942  return;
1943 
1945 }
1946 
1947 
1949 {
1950  switch(preset)
1951  {
1952  case GPU_BLEND_NORMAL:
1953  {
1955  return b;
1956  }
1957  break;
1959  {
1961  return b;
1962  }
1963  break;
1964  case GPU_BLEND_MULTIPLY:
1965  {
1967  return b;
1968  }
1969  break;
1970  case GPU_BLEND_ADD:
1971  {
1973  return b;
1974  }
1975  break;
1976  case GPU_BLEND_SUBTRACT:
1977  // FIXME: Use src alpha for source components?
1978  {
1980  return b;
1981  }
1982  break;
1983  case GPU_BLEND_MOD_ALPHA:
1984  // Don't disturb the colors, but multiply the dest alpha by the src alpha
1985  {
1987  return b;
1988  }
1989  break;
1990  case GPU_BLEND_SET_ALPHA:
1991  // Don't disturb the colors, but set the alpha to the src alpha
1992  {
1994  return b;
1995  }
1996  break;
1997  case GPU_BLEND_SET:
1998  {
2000  return b;
2001  }
2002  break;
2004  {
2006  return b;
2007  }
2008  break;
2010  {
2012  return b;
2013  }
2014  break;
2015  default:
2016  GPU_PushErrorCode(__func__, GPU_ERROR_USER_ERROR, "Blend preset not supported: %d", preset);
2017  {
2019  return b;
2020  }
2021  break;
2022  }
2023 }
2024 
2025 
2027 {
2028  if(image == NULL)
2029  return;
2030 
2031  image->blend_mode.source_color = source_color;
2032  image->blend_mode.dest_color = dest_color;
2033  image->blend_mode.source_alpha = source_alpha;
2034  image->blend_mode.dest_alpha = dest_alpha;
2035 }
2036 
2038 {
2039  if(image == NULL)
2040  return;
2041 
2042  image->blend_mode.color_equation = color_equation;
2043  image->blend_mode.alpha_equation = alpha_equation;
2044 }
2045 
2047 {
2048  GPU_BlendMode b;
2049  if(image == NULL)
2050  return;
2051 
2052  b = GPU_GetBlendModeFromPreset(preset);
2055 }
2056 
2058 {
2059  GPU_Context* context;
2060  if(current_renderer == NULL || current_renderer->current_context_target == NULL)
2061  return;
2062 
2063  context = current_renderer->current_context_target->context;
2064 
2065  context->shapes_blend_mode.source_color = source_color;
2066  context->shapes_blend_mode.dest_color = dest_color;
2067  context->shapes_blend_mode.source_alpha = source_alpha;
2068  context->shapes_blend_mode.dest_alpha = dest_alpha;
2069 }
2070 
2071 void GPU_SetShapeBlendEquation(GPU_BlendEqEnum color_equation, GPU_BlendEqEnum alpha_equation)
2072 {
2073  GPU_Context* context;
2074  if(current_renderer == NULL || current_renderer->current_context_target == NULL)
2075  return;
2076 
2077  context = current_renderer->current_context_target->context;
2078 
2079  context->shapes_blend_mode.color_equation = color_equation;
2080  context->shapes_blend_mode.alpha_equation = alpha_equation;
2081 }
2082 
2084 {
2085  GPU_BlendMode b;
2086  if(current_renderer == NULL || current_renderer->current_context_target == NULL)
2087  return;
2088 
2089  b = GPU_GetBlendModeFromPreset(preset);
2092 }
2093 
2095 {
2096  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->SetImageFilter == NULL)
2097  return;
2098  if(image == NULL)
2099  return;
2100 
2101  current_renderer->SetImageFilter(current_renderer, image, filter);
2102 }
2103 
2105 {
2106  if(image == NULL)
2107  return 0;
2108 
2109  return image->snap_mode;
2110 }
2111 
2113 {
2114  if(image == NULL)
2115  return;
2116 
2117  image->snap_mode = mode;
2118 }
2119 
2120 void GPU_SetWrapMode(GPU_Image* image, GPU_WrapEnum wrap_mode_x, GPU_WrapEnum wrap_mode_y)
2121 {
2122  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->SetWrapMode == NULL)
2123  return;
2124  if(image == NULL)
2125  return;
2126 
2127  current_renderer->SetWrapMode(current_renderer, image, wrap_mode_x, wrap_mode_y);
2128 }
2129 
2130 
2131 SDL_Color GPU_GetPixel(GPU_Target* target, Sint16 x, Sint16 y)
2132 {
2133  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->GetPixel == NULL)
2134  {
2135  SDL_Color c = {0,0,0,0};
2136  return c;
2137  }
2138 
2139  return current_renderer->GetPixel(current_renderer, target, x, y);
2140 }
2141 
2142 
2143 
2144 
2145 
2146 
2147 
2149 {
2150  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->Clear == NULL)
2151  return;
2152 
2153  current_renderer->Clear(current_renderer, target);
2154 }
2155 
2157 {
2158  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->ClearRGBA == NULL)
2159  return;
2160 
2161  if(color == NULL)
2162  current_renderer->ClearRGBA(current_renderer, target, 0, 0, 0, 0);
2163  else
2164  current_renderer->ClearRGBA(current_renderer, target, color->r, color->g, color->b, GET_ALPHA(*color));
2165 }
2166 
2167 void GPU_ClearRGBA(GPU_Target* target, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
2168 {
2169  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->ClearRGBA == NULL)
2170  return;
2171 
2172  current_renderer->ClearRGBA(current_renderer, target, r, g, b, a);
2173 }
2174 
2176 {
2177  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->FlushBlitBuffer == NULL)
2178  return;
2179 
2180  current_renderer->FlushBlitBuffer(current_renderer);
2181 }
2182 
2184 {
2185  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->Flip == NULL)
2186  return;
2187 
2188  current_renderer->Flip(current_renderer, target);
2189 }
2190 
2191 
2192 
2193 
2194 
2195 // Shader API
2196 
2197 
2198 Uint32 GPU_CompileShader_RW(GPU_ShaderEnum shader_type, SDL_RWops* shader_source)
2199 {
2200  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->CompileShader_RW == NULL)
2201  return 0;
2202 
2203  return current_renderer->CompileShader_RW(current_renderer, shader_type, shader_source);
2204 }
2205 
2206 Uint32 GPU_LoadShader(GPU_ShaderEnum shader_type, const char* filename)
2207 {
2208  SDL_RWops* rwops;
2209  Uint32 result;
2210 
2211  if(filename == NULL)
2212  {
2213  GPU_PushErrorCode(__func__, GPU_ERROR_NULL_ARGUMENT, "filename");
2214  return 0;
2215  }
2216  rwops = SDL_RWFromFile(filename, "r");
2217  if(rwops == NULL)
2218  {
2219  GPU_PushErrorCode(__func__, GPU_ERROR_FILE_NOT_FOUND, "%s", filename);
2220  return 0;
2221  }
2222  result = GPU_CompileShader_RW(shader_type, rwops);
2223  SDL_RWclose(rwops);
2224  return result;
2225 }
2226 
2227 Uint32 GPU_CompileShader(GPU_ShaderEnum shader_type, const char* shader_source)
2228 {
2229  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->CompileShader == NULL)
2230  return 0;
2231 
2232  return current_renderer->CompileShader(current_renderer, shader_type, shader_source);
2233 }
2234 
2235 Uint32 GPU_LinkShaderProgram(Uint32 program_object)
2236 {
2237  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->LinkShaderProgram == NULL)
2238  return 0;
2239 
2240  return current_renderer->LinkShaderProgram(current_renderer, program_object);
2241 }
2242 
2243 Uint32 GPU_LinkShaders(Uint32 shader_object1, Uint32 shader_object2)
2244 {
2245  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->LinkShaders == NULL)
2246  return 0;
2247 
2248  return current_renderer->LinkShaders(current_renderer, shader_object1, shader_object2);
2249 }
2250 
2251 void GPU_FreeShader(Uint32 shader_object)
2252 {
2253  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->FreeShader == NULL)
2254  return;
2255 
2256  current_renderer->FreeShader(current_renderer, shader_object);
2257 }
2258 
2259 void GPU_FreeShaderProgram(Uint32 program_object)
2260 {
2261  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->FreeShaderProgram == NULL)
2262  return;
2263 
2264  current_renderer->FreeShaderProgram(current_renderer, program_object);
2265 }
2266 
2267 void GPU_AttachShader(Uint32 program_object, Uint32 shader_object)
2268 {
2269  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->AttachShader == NULL)
2270  return;
2271 
2272  current_renderer->AttachShader(current_renderer, program_object, shader_object);
2273 }
2274 
2275 void GPU_DetachShader(Uint32 program_object, Uint32 shader_object)
2276 {
2277  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->DetachShader == NULL)
2278  return;
2279 
2280  current_renderer->DetachShader(current_renderer, program_object, shader_object);
2281 }
2282 
2283 Uint8 GPU_IsDefaultShaderProgram(Uint32 program_object)
2284 {
2285  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->IsDefaultShaderProgram == NULL)
2286  return 0;
2287 
2288  return current_renderer->IsDefaultShaderProgram(current_renderer, program_object);
2289 }
2290 
2291 void GPU_ActivateShaderProgram(Uint32 program_object, GPU_ShaderBlock* block)
2292 {
2293  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->ActivateShaderProgram == NULL)
2294  return;
2295 
2296  current_renderer->ActivateShaderProgram(current_renderer, program_object, block);
2297 }
2298 
2300 {
2301  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->DeactivateShaderProgram == NULL)
2302  return;
2303 
2304  current_renderer->DeactivateShaderProgram(current_renderer);
2305 }
2306 
2307 const char* GPU_GetShaderMessage(void)
2308 {
2309  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->GetShaderMessage == NULL)
2310  return NULL;
2311 
2312  return current_renderer->GetShaderMessage(current_renderer);
2313 }
2314 
2315 int GPU_GetAttributeLocation(Uint32 program_object, const char* attrib_name)
2316 {
2317  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->GetAttributeLocation == NULL)
2318  return 0;
2319 
2320  return current_renderer->GetAttributeLocation(current_renderer, program_object, attrib_name);
2321 }
2322 
2323 GPU_AttributeFormat GPU_MakeAttributeFormat(int num_elems_per_vertex, GPU_TypeEnum type, Uint8 normalize, int stride_bytes, int offset_bytes)
2324 {
2325  GPU_AttributeFormat f = {0, num_elems_per_vertex, type, normalize, stride_bytes, offset_bytes};
2326  return f;
2327 }
2328 
2330 {
2331  GPU_Attribute a;
2332  a.location = location;
2333  a.values = values;
2334  a.format = format;
2335  return a;
2336 }
2337 
2338 int GPU_GetUniformLocation(Uint32 program_object, const char* uniform_name)
2339 {
2340  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->GetUniformLocation == NULL)
2341  return 0;
2342 
2343  return current_renderer->GetUniformLocation(current_renderer, program_object, uniform_name);
2344 }
2345 
2346 GPU_ShaderBlock GPU_LoadShaderBlock(Uint32 program_object, const char* position_name, const char* texcoord_name, const char* color_name, const char* modelViewMatrix_name)
2347 {
2348  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->LoadShaderBlock == NULL)
2349  {
2351  b.position_loc = -1;
2352  b.texcoord_loc = -1;
2353  b.color_loc = -1;
2354  b.modelViewProjection_loc = -1;
2355  return b;
2356  }
2357 
2358  return current_renderer->LoadShaderBlock(current_renderer, program_object, position_name, texcoord_name, color_name, modelViewMatrix_name);
2359 }
2360 
2362 {
2363  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->SetShaderBlock == NULL)
2364  return;
2365 
2366  current_renderer->SetShaderBlock(current_renderer, block);
2367 }
2368 
2369 void GPU_SetShaderImage(GPU_Image* image, int location, int image_unit)
2370 {
2371  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->SetShaderImage == NULL)
2372  return;
2373 
2374  current_renderer->SetShaderImage(current_renderer, image, location, image_unit);
2375 }
2376 
2377 void GPU_GetUniformiv(Uint32 program_object, int location, int* values)
2378 {
2379  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->GetUniformiv == NULL)
2380  return;
2381 
2382  current_renderer->GetUniformiv(current_renderer, program_object, location, values);
2383 }
2384 
2386 {
2387  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->SetUniformi == NULL)
2388  return;
2389 
2390  current_renderer->SetUniformi(current_renderer, location, value);
2391 }
2392 
2393 void GPU_SetUniformiv(int location, int num_elements_per_value, int num_values, int* values)
2394 {
2395  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->SetUniformiv == NULL)
2396  return;
2397 
2398  current_renderer->SetUniformiv(current_renderer, location, num_elements_per_value, num_values, values);
2399 }
2400 
2401 
2402 void GPU_GetUniformuiv(Uint32 program_object, int location, unsigned int* values)
2403 {
2404  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->GetUniformuiv == NULL)
2405  return;
2406 
2407  current_renderer->GetUniformuiv(current_renderer, program_object, location, values);
2408 }
2409 
2410 void GPU_SetUniformui(int location, unsigned int value)
2411 {
2412  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->SetUniformui == NULL)
2413  return;
2414 
2415  current_renderer->SetUniformui(current_renderer, location, value);
2416 }
2417 
2418 void GPU_SetUniformuiv(int location, int num_elements_per_value, int num_values, unsigned int* values)
2419 {
2420  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->SetUniformuiv == NULL)
2421  return;
2422 
2423  current_renderer->SetUniformuiv(current_renderer, location, num_elements_per_value, num_values, values);
2424 }
2425 
2426 
2427 void GPU_GetUniformfv(Uint32 program_object, int location, float* values)
2428 {
2429  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->GetUniformfv == NULL)
2430  return;
2431 
2432  current_renderer->GetUniformfv(current_renderer, program_object, location, values);
2433 }
2434 
2436 {
2437  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->SetUniformf == NULL)
2438  return;
2439 
2440  current_renderer->SetUniformf(current_renderer, location, value);
2441 }
2442 
2443 void GPU_SetUniformfv(int location, int num_elements_per_value, int num_values, float* values)
2444 {
2445  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->SetUniformfv == NULL)
2446  return;
2447 
2448  current_renderer->SetUniformfv(current_renderer, location, num_elements_per_value, num_values, values);
2449 }
2450 
2451 // Same as GPU_GetUniformfv()
2452 void GPU_GetUniformMatrixfv(Uint32 program_object, int location, float* values)
2453 {
2454  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->GetUniformfv == NULL)
2455  return;
2456 
2457  current_renderer->GetUniformfv(current_renderer, program_object, location, values);
2458 }
2459 
2460 void GPU_SetUniformMatrixfv(int location, int num_matrices, int num_rows, int num_columns, Uint8 transpose, float* values)
2461 {
2462  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->SetUniformMatrixfv == NULL)
2463  return;
2464 
2465  current_renderer->SetUniformMatrixfv(current_renderer, location, num_matrices, num_rows, num_columns, transpose, values);
2466 }
2467 
2468 
2470 {
2471  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->SetAttributef == NULL)
2472  return;
2473 
2474  current_renderer->SetAttributef(current_renderer, location, value);
2475 }
2476 
2478 {
2479  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->SetAttributei == NULL)
2480  return;
2481 
2482  current_renderer->SetAttributei(current_renderer, location, value);
2483 }
2484 
2485 void GPU_SetAttributeui(int location, unsigned int value)
2486 {
2487  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->SetAttributeui == NULL)
2488  return;
2489 
2490  current_renderer->SetAttributeui(current_renderer, location, value);
2491 }
2492 
2493 void GPU_SetAttributefv(int location, int num_elements, float* value)
2494 {
2495  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->SetAttributefv == NULL)
2496  return;
2497 
2498  current_renderer->SetAttributefv(current_renderer, location, num_elements, value);
2499 }
2500 
2501 void GPU_SetAttributeiv(int location, int num_elements, int* value)
2502 {
2503  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->SetAttributeiv == NULL)
2504  return;
2505 
2506  current_renderer->SetAttributeiv(current_renderer, location, num_elements, value);
2507 }
2508 
2509 void GPU_SetAttributeuiv(int location, int num_elements, unsigned int* value)
2510 {
2511  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->SetAttributeuiv == NULL)
2512  return;
2513 
2514  current_renderer->SetAttributeuiv(current_renderer, location, num_elements, value);
2515 }
2516 
2518 {
2519  if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->SetAttributeSource == NULL)
2520  return;
2521 
2522  current_renderer->SetAttributeSource(current_renderer, num_values, source);
2523 }
2524 
void GPU_SetUniformuiv(int location, int num_elements_per_value, int num_values, unsigned int *values)
Definition: SDL_gpu.c:2418
static Uint32 init_windowID
Definition: SDL_gpu.c:143
void GPU_UnsetClip(GPU_Target *target)
Definition: SDL_gpu.c:1833
GPU_Rect viewport
Definition: SDL_gpu.h:297
SDL_Color color
Definition: SDL_gpu.h:295
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)
void GPU_AddWindowMapping(GPU_Target *target)
Definition: SDL_gpu.c:191
static int renderer_order_size
int(* GetAttributeLocation)(GPU_Renderer *renderer, Uint32 program_object, const char *attrib_name)
Definition: SDL_gpu.h:671
GPU_Image * GPU_CopyImageFromSurface(SDL_Surface *surface)
Definition: SDL_gpu.c:841
GPU_SnapEnum snap_mode
Definition: SDL_gpu.h:189
void(* SetShaderImage)(GPU_Renderer *renderer, GPU_Image *image, int location, int image_unit)
Definition: SDL_gpu.h:683
void GPU_ClearRGBA(GPU_Target *target, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Definition: SDL_gpu.c:2167
GLboolean enable
Definition: glew.h:2589
static void BlitRotate(GPU_Renderer *renderer, GPU_Image *image, GPU_Rect *src_rect, GPU_Target *target, float x, float y, float degrees)
GLsizei GLboolean transpose
Definition: glew.h:1832
Uint32 texture_w
Definition: SDL_gpu.h:182
GPU_Target *(* Init)(GPU_Renderer *renderer, GPU_RendererID renderer_request, Uint16 w, Uint16 h, GPU_WindowFlagEnum SDL_flags)
Definition: SDL_gpu.h:501
void GPU_SetRGBA(GPU_Image *image, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Definition: SDL_gpu.c:1868
GPU_Target * GPU_CreateAliasTarget(GPU_Target *target)
Definition: SDL_gpu.c:403
void(* FreeShaderProgram)(GPU_Renderer *renderer, Uint32 program_object)
Definition: SDL_gpu.h:650
Uint32 GPU_BlitFlagEnum
Definition: SDL_gpu.h:360
void GPU_SetSnapMode(GPU_Image *image, GPU_SnapEnum mode)
Definition: SDL_gpu.c:2112
GPU_ShaderBlock GPU_LoadShaderBlock(Uint32 program_object, const char *position_name, const char *texcoord_name, const char *color_name, const char *modelViewMatrix_name)
Definition: SDL_gpu.c:2346
SDL_Color GPU_GetPixel(GPU_Target *target, Sint16 x, Sint16 y)
Definition: SDL_gpu.c:2131
void GPU_UpdateSubImage(GPU_Image *image, const GPU_Rect *image_rect, SDL_Surface *surface, const GPU_Rect *surface_rect)
Definition: SDL_gpu.c:700
static int window_mappings_size
Definition: SDL_gpu.c:47
void GPU_SetShaderBlock(GPU_ShaderBlock block)
Definition: SDL_gpu.c:2361
void GPU_SetTargetRGB(GPU_Target *target, Uint8 r, Uint8 g, Uint8 b)
Definition: SDL_gpu.c:1892
void(* SetAttributef)(GPU_Renderer *renderer, int location, float value)
Definition: SDL_gpu.h:716
GPU_Rect GPU_MakeRect(float x, float y, float w, float h)
Definition: SDL_gpu.c:607
GPU_Target * target
Definition: SDL_gpu.c:42
void GPU_BlitTransformX(GPU_Image *image, GPU_Rect *src_rect, GPU_Target *target, float x, float y, float pivot_x, float pivot_y, float angle, float scaleX, float scaleY)
Definition: SDL_gpu.c:980
#define RETURN_ERROR(code, details)
Definition: SDL_gpu.c:23
static const GPU_BlitFlagEnum GPU_PASSTHROUGH_VERTICES
Definition: SDL_gpu.h:361
STBIDEF const char * stbi_failure_reason(void)
GLint level
Definition: glew.h:1220
int modelViewProjection_loc
Definition: SDL_gpu.h:223
void(* SetShaderBlock)(GPU_Renderer *renderer, GPU_ShaderBlock block)
Definition: SDL_gpu.h:680
void(* BlitTransformMatrix)(GPU_Renderer *renderer, GPU_Image *image, GPU_Rect *src_rect, GPU_Target *target, float x, float y, float *matrix3x3)
Definition: SDL_gpu.h:598
void GPU_SetUniformui(int location, unsigned int value)
Definition: SDL_gpu.c:2410
GPU_Camera GPU_GetDefaultCamera(void)
Definition: SDL_gpu.c:631
static void BlitBatch(GPU_Renderer *renderer, GPU_Image *image, GPU_Target *target, unsigned int num_sprites, float *values, GPU_BlitFlagEnum flags)
Uint32 GPU_RendererEnum
Definition: SDL_gpu.h:35
#define GPU_PASSTHROUGH_ALL
Definition: SDL_gpu.h:368
void GPU_FreeTarget(GPU_Target *target)
Definition: SDL_gpu.c:901
#define GPU_MAX_NUM_ERRORS
Definition: SDL_gpu.c:31
const GLfloat * c
Definition: glew.h:12741
static const GPU_BlitFlagEnum GPU_PASSTHROUGH_COLORS
Definition: SDL_gpu.h:363
Uint8 GPU_GetBlending(GPU_Image *image)
Definition: SDL_gpu.c:1922
GPU_FormatEnum
Definition: SDL_gpu.h:152
void(* BlitRotate)(GPU_Renderer *renderer, GPU_Image *image, GPU_Rect *src_rect, GPU_Target *target, float x, float y, float degrees)
Definition: SDL_gpu.h:586
void GPU_BlitTransformMatrix(GPU_Image *image, GPU_Rect *src_rect, GPU_Target *target, float x, float y, float *matrix3x3)
Definition: SDL_gpu.c:997
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1221
void(* FreeImage)(GPU_Renderer *renderer, GPU_Image *image)
Definition: SDL_gpu.h:574
static l_noret error(LoadState *S, const char *why)
Definition: lundump.cpp:29
void GPU_GetUniformuiv(Uint32 program_object, int location, unsigned int *values)
Definition: SDL_gpu.c:2402
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)
Definition: SDL_gpu.h:604
Uint32 GPU_WindowFlagEnum
Definition: SDL_gpu.h:339
Uint32 GPU_LinkShaders(Uint32 shader_object1, Uint32 shader_object2)
Definition: SDL_gpu.c:2243
game_display * screen
Definition: resources.cpp:27
void(* BlitScale)(GPU_Renderer *renderer, GPU_Image *image, GPU_Rect *src_rect, GPU_Target *target, float x, float y, float scaleX, float scaleY)
Definition: SDL_gpu.h:589
int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data)
void GPU_SetColor(GPU_Image *image, SDL_Color *color)
Definition: SDL_gpu.c:1844
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)
Definition: SDL_gpu.h:677
GPU_Target * GPU_Init(Uint16 w, Uint16 h, GPU_WindowFlagEnum SDL_flags)
Definition: SDL_gpu.c:325
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)
void(* AttachShader)(GPU_Renderer *renderer, Uint32 program_object, Uint32 shader_object)
Definition: SDL_gpu.h:653
float y
Definition: SDL_gpu.h:29
SDL_Surface *(* CopySurfaceFromTarget)(GPU_Renderer *renderer, GPU_Target *target)
Definition: SDL_gpu.h:568
GPU_Target * GPU_GetContextTarget(void)
Definition: SDL_gpu.c:882
GPU_DebugLevelEnum GPU_GetDebugLevel(void)
Definition: SDL_gpu.c:498
void GPU_SetTargetColor(GPU_Target *target, SDL_Color *color)
Definition: SDL_gpu.c:1878
void GPU_SetUniformi(int location, int value)
Definition: SDL_gpu.c:2385
const char * GPU_GetShaderMessage(void)
Definition: SDL_gpu.c:2307
void GPU_SetTargetRGBA(GPU_Target *target, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Definition: SDL_gpu.c:1907
GPU_RendererID GPU_MakeRendererID(GPU_RendererEnum id, int major_version, int minor_version)
Definition: SDL_gpu.c:619
void(* SetUniformi)(GPU_Renderer *renderer, int location, int value)
Definition: SDL_gpu.h:689
void GPU_GetVirtualCoords(GPU_Target *target, float *x, float *y, float displayX, float displayY)
Definition: SDL_gpu.c:579
void GPU_BlitTransform(GPU_Image *image, GPU_Rect *src_rect, GPU_Target *target, float x, float y, float angle, float scaleX, float scaleY)
Definition: SDL_gpu.c:963
static GPU_DebugLevelEnum debug_level
Definition: SDL_gpu.c:29
Uint32 GPU_LinkShaderProgram(Uint32 program_object)
Definition: SDL_gpu.c:2235
GPU_InitFlagEnum GPU_GetPreInitFlags(void)
Definition: SDL_gpu.c:162
STBIDEF stbi_uc * stbi_load_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp)
void(* MakeCurrent)(GPU_Renderer *renderer, GPU_Target *target, Uint32 windowID)
Definition: SDL_gpu.h:514
void(* ActivateShaderProgram)(GPU_Renderer *renderer, Uint32 program_object, GPU_ShaderBlock *block)
Definition: SDL_gpu.h:662
static const GPU_BlitFlagEnum GPU_USE_DEFAULT_COLORS
Definition: SDL_gpu.h:366
void(* BlitBatch)(GPU_Renderer *renderer, GPU_Image *image, GPU_Target *target, unsigned int num_sprites, float *values, GPU_BlitFlagEnum flags)
Definition: SDL_gpu.h:601
Uint8 GPU_ToggleFullscreen(Uint8 use_desktop_resolution)
Definition: SDL_gpu.c:419
void GPU_SetViewport(GPU_Target *target, GPU_Rect viewport)
Definition: SDL_gpu.c:625
#define GPU_ERROR_FUNCTION_STRING_MAX
Definition: SDL_gpu.c:32
void GPU_SetBlendFunction(GPU_Image *image, GPU_BlendFuncEnum source_color, GPU_BlendFuncEnum dest_color, GPU_BlendFuncEnum source_alpha, GPU_BlendFuncEnum dest_alpha)
Definition: SDL_gpu.c:2026
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)
Definition: SDL_gpu.h:592
GLboolean GLboolean g
Definition: glew.h:7319
int(* GetUniformLocation)(GPU_Renderer *renderer, Uint32 program_object, const char *uniform_name)
Definition: SDL_gpu.h:674
void(* UnsetClip)(GPU_Renderer *renderer, GPU_Target *target)
Definition: SDL_gpu.h:613
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1220
GPU_ErrorEnum
Definition: SDL_gpu.h:446
static void Blit(GPU_Renderer *renderer, GPU_Image *image, GPU_Rect *src_rect, GPU_Target *target, float x, float y)
GPU_FilterEnum
Definition: SDL_gpu.h:122
GPU_Rect(* SetClip)(GPU_Renderer *renderer, GPU_Target *target, Sint16 x, Sint16 y, Uint16 w, Uint16 h)
Definition: SDL_gpu.h:610
Uint32 GPU_LoadShader(GPU_ShaderEnum shader_type, const char *filename)
Definition: SDL_gpu.c:2206
GPU_Camera camera
Definition: SDL_gpu.h:300
void(* FlushBlitBuffer)(GPU_Renderer *renderer)
Definition: SDL_gpu.h:629
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definition: glew.h:1347
GPU_BlendFuncEnum
Definition: SDL_gpu.h:67
void GPU_SetShapeBlendEquation(GPU_BlendEqEnum color_equation, GPU_BlendEqEnum alpha_equation)
Definition: SDL_gpu.c:2071
void(* SetAttributeSource)(GPU_Renderer *renderer, int num_values, GPU_Attribute source)
Definition: SDL_gpu.h:734
GLenum mode
Definition: glew.h:2390
Uint32 GPU_CompileShader(GPU_ShaderEnum shader_type, const char *shader_source)
Definition: SDL_gpu.c:2227
void GPU_MakeCurrent(GPU_Target *target, Uint32 windowID)
Definition: SDL_gpu.c:411
Uint8(* SetWindowResolution)(GPU_Renderer *renderer, Uint16 w, Uint16 h)
Definition: SDL_gpu.h:520
#define GPU_DEFAULT_INIT_FLAGS
Definition: SDL_gpu.h:351
Uint16 h
Definition: SDL_gpu.h:291
void GPU_SetBlending(GPU_Image *image, Uint8 enable)
Definition: SDL_gpu.c:1931
static const char * get_filename_ext(const char *filename)
Definition: SDL_gpu.c:802
void(* SetAsCurrent)(GPU_Renderer *renderer)
Definition: SDL_gpu.h:517
char * details
Definition: SDL_gpu.h:461
void GPU_PushErrorCode(const char *function, GPU_ErrorEnum error, const char *details,...)
Definition: SDL_gpu.c:503
const char *(* GetShaderMessage)(GPU_Renderer *renderer)
Definition: SDL_gpu.h:668
void GPU_SetShapeBlendFunction(GPU_BlendFuncEnum source_color, GPU_BlendFuncEnum dest_color, GPU_BlendFuncEnum source_alpha, GPU_BlendFuncEnum dest_alpha)
Definition: SDL_gpu.c:2057
static GPU_WindowMapping * window_mappings
Definition: SDL_gpu.c:46
SDL_Surface * GPU_LoadSurface(const char *filename)
Definition: SDL_gpu.c:716
void(* Quit)(GPU_Renderer *renderer)
Definition: SDL_gpu.h:529
static void init_error_stack()
Definition: SDL_gpu.c:167
GLboolean GLenum GLenum GLvoid * values
Definition: glew.h:3799
GPU_Image * GPU_CopyImageFromTarget(GPU_Target *target)
Definition: SDL_gpu.c:849
void(* FreeShader)(GPU_Renderer *renderer, Uint32 shader_object)
Definition: SDL_gpu.h:647
Uint32(* LinkShaders)(GPU_Renderer *renderer, Uint32 shader_object1, Uint32 shader_object2)
Definition: SDL_gpu.h:644
void(* Blit)(GPU_Renderer *renderer, GPU_Image *image, GPU_Rect *src_rect, GPU_Target *target, float x, float y)
Definition: SDL_gpu.h:583
void GPU_Clear(GPU_Target *target)
Definition: SDL_gpu.c:2148
GLdouble GLdouble GLdouble b
Definition: glew.h:6966
Uint32 texture_h
Definition: SDL_gpu.h:182
void(* Flip)(GPU_Renderer *renderer, GPU_Target *target)
Definition: SDL_gpu.h:631
int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes)
static const GPU_BlitFlagEnum GPU_PASSTHROUGH_TEXCOORDS
Definition: SDL_gpu.h:362
GPU_BlendEqEnum alpha_equation
Definition: SDL_gpu.h:99
GPU_Image * GPU_CreateAliasImage(GPU_Image *image)
Definition: SDL_gpu.c:668
int location
Definition: SDL_gpu.h:423
GPU_Renderer * GPU_GetRendererByID(GPU_RendererID id)
void GPU_SetShaderImage(GPU_Image *image, int location, int image_unit)
Definition: SDL_gpu.c:2369
GLuint64EXT * result
Definition: glew.h:10727
GPU_Renderer * GPU_GetCurrentRenderer(void)
Definition: SDL_gpu.c:64
GPU_Renderer * GPU_AddRenderer(GPU_RendererID id)
void GPU_SetPreInitFlags(GPU_InitFlagEnum GPU_flags)
Definition: SDL_gpu.c:157
Uint32 windowID
Definition: SDL_gpu.h:249
GLuint id
Definition: glew.h:1647
void(* ClearRGBA)(GPU_Renderer *renderer, GPU_Target *target, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Definition: SDL_gpu.h:627
void GPU_GetRendererOrder(int *order_size, GPU_RendererID *order)
void(* SetAttributeuiv)(GPU_Renderer *renderer, int location, int num_elements, unsigned int *value)
Definition: SDL_gpu.h:731
SDL_version GPU_GetLinkedVersion(void)
Definition: SDL_gpu.c:51
GPU_BlendMode blend_mode
Definition: SDL_gpu.h:187
void GPU_SetAttributefv(int location, int num_elements, float *value)
Definition: SDL_gpu.c:2493
#define GPU_INITIAL_WINDOW_MAPPINGS_SIZE
Definition: SDL_gpu.c:45
static GPU_Renderer * current_renderer
Definition: SDL_gpu.c:27
void GPU_BlitRotate(GPU_Image *image, GPU_Rect *src_rect, GPU_Target *target, float x, float y, float angle)
Definition: SDL_gpu.c:929
void GPU_Flip(GPU_Target *target)
Definition: SDL_gpu.c:2183
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)
Definition: SDL_gpu.h:595
GPU_Target * current_context_target
Definition: SDL_gpu.h:494
void GPU_ActivateShaderProgram(Uint32 program_object, GPU_ShaderBlock *block)
Definition: SDL_gpu.c:2291
Uint32 windowID
Definition: SDL_gpu.c:41
void GPU_UpdateImage(GPU_Image *image, SDL_Surface *surface, const GPU_Rect *surface_rect)
Definition: SDL_gpu.c:692
GPU_BlendEqEnum color_equation
Definition: SDL_gpu.h:98
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1858
char * function
Definition: SDL_gpu.h:459
GLsizei const GLfloat * value
Definition: glew.h:1817
void GPU_SetAttributeui(int location, unsigned int value)
Definition: SDL_gpu.c:2485
GPU_Target * GPU_InitRendererByID(GPU_RendererID renderer_request, Uint16 w, Uint16 h, GPU_WindowFlagEnum SDL_flags)
Definition: SDL_gpu.c:357
GPU_BlendMode shapes_blend_mode
Definition: SDL_gpu.h:265
GPU_BlendFuncEnum dest_alpha
Definition: SDL_gpu.h:96
SDL_Surface * GPU_CopySurfaceFromTarget(GPU_Target *target)
Definition: SDL_gpu.c:857
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:7319
void GPU_SetInitWindow(Uint32 windowID)
Definition: SDL_gpu.c:145
void(* SetVirtualResolution)(GPU_Renderer *renderer, GPU_Target *target, Uint16 w, Uint16 h)
Definition: SDL_gpu.h:523
int window_w
Definition: SDL_gpu.h:252
GPU_Target * GPU_GetWindowTarget(Uint32 windowID)
Definition: SDL_gpu.c:305
GPU_Image * GPU_LoadImage(const char *filename)
Definition: SDL_gpu.c:660
void(* SetUniformMatrixfv)(GPU_Renderer *renderer, int location, int num_matrices, int num_rows, int num_columns, Uint8 transpose, float *values)
Definition: SDL_gpu.h:713
int position_loc
Definition: SDL_gpu.h:219
Uint8 use_color
Definition: SDL_gpu.h:294
void GPU_SetUniformMatrixfv(int location, int num_matrices, int num_rows, int num_columns, Uint8 transpose, float *values)
Definition: SDL_gpu.c:2460
void GPU_SetUniformfv(int location, int num_elements_per_value, int num_values, float *values)
Definition: SDL_gpu.c:2443
void(* SetAttributefv)(GPU_Renderer *renderer, int location, int num_elements, float *value)
Definition: SDL_gpu.h:725
#define GPU_RENDERER_ORDER_MAX
Definition: SDL_gpu.h:33
GLenum GLuint GLsizei const char * buf
Definition: glew.h:2498
Uint8(* ToggleFullscreen)(GPU_Renderer *renderer, Uint8 use_desktop_resolution)
Definition: SDL_gpu.h:532
static const GPU_BlitFlagEnum GPU_USE_DEFAULT_SRC_RECTS
Definition: SDL_gpu.h:365
GPU_Image * image
Definition: SDL_gpu.h:289
static void init_window_mappings()
Definition: SDL_gpu.c:181
GPU_BlendFuncEnum source_color
Definition: SDL_gpu.h:93
GPU_Image *(* LoadImage)(GPU_Renderer *renderer, const char *filename)
Definition: SDL_gpu.h:541
SDL_Color GPU_MakeColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Definition: SDL_gpu.c:613
GPU_BlendMode GPU_GetBlendModeFromPreset(GPU_BlendPresetEnum preset)
Definition: SDL_gpu.c:1948
void(* SetUniformui)(GPU_Renderer *renderer, int location, unsigned int value)
Definition: SDL_gpu.h:698
GPU_ErrorObject GPU_PopErrorCode(void)
Definition: SDL_gpu.c:545
void(* SetAttributei)(GPU_Renderer *renderer, int location, int value)
Definition: SDL_gpu.h:719
Uint8 GPU_SaveSurface(SDL_Surface *surface, const char *filename)
Definition: SDL_gpu.c:810
static int num_window_mappings
Definition: SDL_gpu.c:48
void GPU_FreeShaderProgram(Uint32 program_object)
Definition: SDL_gpu.c:2259
void(* GetUniformuiv)(GPU_Renderer *renderer, Uint32 program_object, int location, unsigned int *values)
Definition: SDL_gpu.h:695
Uint16 h
Definition: SDL_gpu.h:178
void GPU_SetCurrentRenderer(GPU_RendererID id)
Definition: SDL_gpu.c:56
Uint32 GPU_InitFlagEnum
Definition: SDL_gpu.h:346
Uint16 w
Definition: SDL_gpu.h:291
Uint8 shapes_use_blending
Definition: SDL_gpu.h:264
cl_event GLbitfield flags
Definition: glew.h:3070
GPU_Rect GPU_SetClip(GPU_Target *target, Sint16 x, Sint16 y, Uint16 w, Uint16 h)
Definition: SDL_gpu.c:1822
GLuint color
Definition: glew.h:5801
void GPU_ClearColor(GPU_Target *target, SDL_Color *color)
Definition: SDL_gpu.c:2156
void GPU_SetVirtualResolution(GPU_Target *target, Uint16 w, Uint16 h)
Definition: SDL_gpu.c:436
void GPU_DetachShader(Uint32 program_object, Uint32 shader_object)
Definition: SDL_gpu.c:2275
SDL_Color(* GetPixel)(GPU_Renderer *renderer, GPU_Target *target, Sint16 x, Sint16 y)
Definition: SDL_gpu.h:616
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)
Encapsulates the map of the game.
Definition: location.hpp:38
GPU_Image * GPU_CopyImage(GPU_Image *image)
Definition: SDL_gpu.c:684
Uint8(* IsFeatureEnabled)(GPU_Renderer *renderer, GPU_FeatureEnum feature)
Definition: SDL_gpu.h:504
GPU_SnapEnum
Definition: SDL_gpu.h:132
GPU_RendererID id
Definition: SDL_gpu.h:484
static GPU_ErrorObject error_code_stack[GPU_MAX_NUM_ERRORS]
Definition: SDL_gpu.c:34
static const GPU_BlitFlagEnum GPU_USE_DEFAULT_POSITIONS
Definition: SDL_gpu.h:364
void GPU_SetAttributef(int location, float value)
Definition: SDL_gpu.c:2469
GPU_Image *(* CopyImageFromTarget)(GPU_Renderer *renderer, GPU_Target *target)
Definition: SDL_gpu.h:565
struct GPU_WindowMapping GPU_WindowMapping
static void block(LexState *ls)
Definition: lparser.cpp:1081
GPU_BlendEqEnum
Definition: SDL_gpu.h:84
void GPU_UpdateImageBytes(GPU_Image *image, const GPU_Rect *image_rect, const unsigned char *bytes, int bytes_per_row)
Definition: SDL_gpu.c:708
void GPU_SetDebugLevel(GPU_DebugLevelEnum level)
Definition: SDL_gpu.c:491
void(* SetAttributeui)(GPU_Renderer *renderer, int location, unsigned int value)
Definition: SDL_gpu.h:722
GPU_SnapEnum GPU_GetSnapMode(GPU_Image *image)
Definition: SDL_gpu.c:2104
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: glew.h:1222
GPU_Image *(* CreateAliasImage)(GPU_Renderer *renderer, GPU_Image *image)
Definition: SDL_gpu.h:544
void GPU_SetImageFilter(GPU_Image *image, GPU_FilterEnum filter)
Definition: SDL_gpu.c:2094
GPU_Target * GPU_InitRenderer(GPU_RendererEnum renderer_enum, Uint16 w, Uint16 h, GPU_WindowFlagEnum SDL_flags)
Definition: SDL_gpu.c:352
void GPU_BlitScale(GPU_Image *image, GPU_Rect *src_rect, GPU_Target *target, float x, float y, float scaleX, float scaleY)
Definition: SDL_gpu.c:946
void GPU_DeactivateShaderProgram(void)
Definition: SDL_gpu.c:2299
GPU_ShaderEnum
Definition: SDL_gpu.h:392
void GPU_RemoveWindowMappingByTarget(GPU_Target *target)
Definition: SDL_gpu.c:268
GPU_Target *(* CreateTargetFromWindow)(GPU_Renderer *renderer, Uint32 windowID, GPU_Target *target)
Definition: SDL_gpu.h:508
void(* GetUniformiv)(GPU_Renderer *renderer, Uint32 program_object, int location, int *values)
Definition: SDL_gpu.h:686
void GPU_UnsetVirtualResolution(GPU_Target *target)
Definition: SDL_gpu.c:444
GPU_Image *(* CreateImage)(GPU_Renderer *renderer, Uint16 w, Uint16 h, GPU_FormatEnum format)
Definition: SDL_gpu.h:538
int GPU_GetUniformLocation(Uint32 program_object, const char *uniform_name)
Definition: SDL_gpu.c:2338
void(* UpdateSubImage)(GPU_Renderer *renderer, GPU_Image *image, const GPU_Rect *image_rect, SDL_Surface *surface, const GPU_Rect *surface_rect)
Definition: SDL_gpu.h:556
GLfloat GLfloat GLfloat GLfloat h
Definition: glew.h:5910
size_t i
Definition: function.cpp:1057
int GPU_GetNumActiveRenderers(void)
void(* SetImageFilter)(GPU_Renderer *renderer, GPU_Image *image, GPU_FilterEnum filter)
Definition: SDL_gpu.h:619
void GPU_LogWarning(const char *format,...)
Definition: SDL_gpu.c:91
GPU_Camera GPU_SetCamera(GPU_Target *target, GPU_Camera *cam)
Definition: SDL_gpu.c:644
GLint GLint GLint GLint GLint x
Definition: glew.h:1220
GPU_Target * GPU_LoadTarget(GPU_Image *image)
Definition: SDL_gpu.c:891
GPU_Image * GPU_CreateImage(Uint16 w, Uint16 h, GPU_FormatEnum format)
Definition: SDL_gpu.c:652
GPU_Rect GPU_SetClipRect(GPU_Target *target, GPU_Rect rect)
Definition: SDL_gpu.c:1811
#define GET_ALPHA(sdl_color)
Definition: SDL_gpu.c:15
GLdouble GLdouble GLdouble r
Definition: glew.h:1374
Uint32(* CompileShader)(GPU_Renderer *renderer, GPU_ShaderEnum shader_type, const char *shader_source)
Definition: SDL_gpu.h:638
void GPU_RemoveWindowMapping(Uint32 windowID)
Definition: SDL_gpu.c:237
void GPU_SetWrapMode(GPU_Image *image, GPU_WrapEnum wrap_mode_x, GPU_WrapEnum wrap_mode_y)
Definition: SDL_gpu.c:2120
GPU_Context * context
Definition: SDL_gpu.h:303
Uint32 GPU_CompileShader_RW(GPU_ShaderEnum shader_type, SDL_RWops *shader_source)
Definition: SDL_gpu.c:2198
void(* UpdateImage)(GPU_Renderer *renderer, GPU_Image *image, SDL_Surface *surface, const GPU_Rect *surface_rect)
Definition: SDL_gpu.h:553
void GPU_SetAttributeuiv(int location, int num_elements, unsigned int *value)
Definition: SDL_gpu.c:2509
void GPU_SetUniformf(int location, float value)
Definition: SDL_gpu.c:2435
void GPU_FreeShader(Uint32 shader_object)
Definition: SDL_gpu.c:2251
Uint32(* CompileShader_RW)(GPU_Renderer *renderer, GPU_ShaderEnum shader_type, SDL_RWops *shader_source)
Definition: SDL_gpu.h:635
void GPU_BlitBatchSeparate(GPU_Image *image, GPU_Target *target, unsigned int num_sprites, float *positions, float *src_rects, float *colors, GPU_BlitFlagEnum flags)
Definition: SDL_gpu.c:1349
GPU_BlendFuncEnum dest_color
Definition: SDL_gpu.h:94
GPU_DebugLevelEnum
Definition: SDL_gpu.h:469
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
Definition: glew.h:1220
void GPU_SetShapeBlendMode(GPU_BlendPresetEnum preset)
Definition: SDL_gpu.c:2083
GPU_Target * GPU_CreateTargetFromWindow(Uint32 windowID)
Definition: SDL_gpu.c:395
void GPU_AttachShader(Uint32 program_object, Uint32 shader_object)
Definition: SDL_gpu.c:2267
void * values
Definition: SDL_gpu.h:424
void GPU_SetUniformiv(int location, int num_elements_per_value, int num_values, int *values)
Definition: SDL_gpu.c:2393
GLsizeiptr size
Definition: glew.h:1649
void GPU_SetBlendEquation(GPU_Image *image, GPU_BlendEqEnum color_equation, GPU_BlendEqEnum alpha_equation)
Definition: SDL_gpu.c:2037
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glew.h:3448
Uint8 GPU_IsFeatureEnabled(GPU_FeatureEnum feature)
Definition: SDL_gpu.c:387
static int inited_error_code_stack
Definition: SDL_gpu.c:36
static SDL_version GPU_GetCompiledVersion(void)
Definition: SDL_gpu.h:809
GPU_AttributeFormat format
Definition: SDL_gpu.h:425
Uint8 GPU_SetWindowResolution(Uint16 w, Uint16 h)
Definition: SDL_gpu.c:427
STBIDEF void stbi_image_free(void *retval_from_stbi_load)
GLclampd n
Definition: glew.h:5903
void(* SetUniformfv)(GPU_Renderer *renderer, int location, int num_elements_per_value, int num_values, float *values)
Definition: SDL_gpu.h:710
float w
Definition: SDL_gpu.h:30
void(* GetUniformfv)(GPU_Renderer *renderer, Uint32 program_object, int location, float *values)
Definition: SDL_gpu.h:704
const GLdouble * m
Definition: glew.h:6968
void GPU_SetShapeBlending(Uint8 enable)
Definition: SDL_gpu.c:1939
void GPU_GenerateMipmaps(GPU_Image *image)
Definition: SDL_gpu.c:1800
void GPU_FreeImage(GPU_Image *image)
Definition: SDL_gpu.c:873
#define g
Definition: glew.h:12730
float h
Definition: SDL_gpu.h:30
void GPU_FlushBlitBuffer(void)
Definition: SDL_gpu.c:2175
static Uint8 init_SDL(void)
Definition: SDL_gpu.c:116
void(* DetachShader)(GPU_Renderer *renderer, Uint32 program_object, Uint32 shader_object)
Definition: SDL_gpu.h:656
void(* UpdateImageBytes)(GPU_Renderer *renderer, GPU_Image *image, const GPU_Rect *image_rect, const unsigned char *bytes, int bytes_per_row)
Definition: SDL_gpu.h:559
void(* GenerateMipmaps)(GPU_Renderer *renderer, GPU_Image *image)
Definition: SDL_gpu.h:607
int window_h
Definition: SDL_gpu.h:253
Uint8(* IsDefaultShaderProgram)(GPU_Renderer *renderer, Uint32 program_object)
Definition: SDL_gpu.h:659
SDL_Surface *(* CopySurfaceFromImage)(GPU_Renderer *renderer, GPU_Image *image)
Definition: SDL_gpu.h:571
void(* SetUniformiv)(GPU_Renderer *renderer, int location, int num_elements_per_value, int num_values, int *values)
Definition: SDL_gpu.h:692
GLdouble angle
Definition: glew.h:6979
this module manages the cache of images.
Definition: image.cpp:75
GPU_BlendPresetEnum
Definition: SDL_gpu.h:106
int GPU_GetAttributeLocation(Uint32 program_object, const char *attrib_name)
Definition: SDL_gpu.c:2315
Uint8(* SaveImage)(GPU_Renderer *renderer, GPU_Image *image, const char *filename)
Definition: SDL_gpu.h:547
Uint8 GPU_IsDefaultShaderProgram(Uint32 program_object)
Definition: SDL_gpu.c:2283
static void BlitScale(GPU_Renderer *renderer, GPU_Image *image, GPU_Rect *src_rect, GPU_Target *target, float x, float y, float scaleX, float scaleY)
Uint32 GPU_FeatureEnum
Definition: SDL_gpu.h:313
SDL_Color color
Definition: SDL_gpu.h:185
GLuint GLuint GLsizei GLenum const GLvoid * indices
Definition: glew.h:1221
Uint16 w
Definition: SDL_gpu.h:178
void GPU_SetAttributeiv(int location, int num_elements, int *value)
Definition: SDL_gpu.c:2501
const char * GPU_GetErrorString(GPU_ErrorEnum error)
Definition: SDL_gpu.c:556
GPU_WrapEnum
Definition: SDL_gpu.h:143
#define c
Definition: glew.h:12743
Uint32 GPU_TypeEnum
Definition: SDL_gpu.h:371
static int num_error_codes
Definition: SDL_gpu.c:35
void GPU_SetBlendMode(GPU_Image *image, GPU_BlendPresetEnum preset)
Definition: SDL_gpu.c:2046
void GPU_GetUniformiv(Uint32 program_object, int location, int *values)
Definition: SDL_gpu.c:2377
Uint32 current_shader_program
Definition: SDL_gpu.h:260
Uint32(* LinkShaderProgram)(GPU_Renderer *renderer, Uint32 program_object)
Definition: SDL_gpu.h:641
void GPU_Blit(GPU_Image *image, GPU_Rect *src_rect, GPU_Target *target, float x, float y)
Definition: SDL_gpu.c:911
GPU_Target *(* LoadTarget)(GPU_Renderer *renderer, GPU_Image *image)
Definition: SDL_gpu.h:577
GLint GLint GLint GLint GLint GLint GLsizei width
Definition: glew.h:1220
void(* UnsetVirtualResolution)(GPU_Renderer *renderer, GPU_Target *target)
Definition: SDL_gpu.h:526
void GPU_LogError(const char *format,...)
Definition: SDL_gpu.c:103
#define e
void GPU_TriangleBatch(GPU_Image *image, GPU_Target *target, unsigned short num_vertices, float *values, unsigned int num_indices, unsigned short *indices, GPU_BlitFlagEnum flags)
Definition: SDL_gpu.c:1634
GPU_Target *(* CreateAliasTarget)(GPU_Renderer *renderer, GPU_Target *target)
Definition: SDL_gpu.h:511
void GPU_SetRGB(GPU_Image *image, Uint8 r, Uint8 g, Uint8 b)
Definition: SDL_gpu.c:1858
void(* SetUniformf)(GPU_Renderer *renderer, int location, float value)
Definition: SDL_gpu.h:707
Uint32 GPU_GetInitWindow(void)
Definition: SDL_gpu.c:150
void GPU_CloseCurrentRenderer(void)
Definition: SDL_gpu.c:452
void GPU_SetAttributeSource(int num_values, GPU_Attribute source)
Definition: SDL_gpu.c:2517
map_location location
static GPU_RendererID renderer_order[GPU_RENDERER_ORDER_MAX]
static GPU_InitFlagEnum preinit_flags
Definition: SDL_gpu.c:155
void(* DeactivateShaderProgram)(GPU_Renderer *renderer)
Definition: SDL_gpu.h:665
GPU_Image *(* CopyImage)(GPU_Renderer *renderer, GPU_Image *image)
Definition: SDL_gpu.h:550
void(* SetAttributeiv)(GPU_Renderer *renderer, int location, int num_elements, int *value)
Definition: SDL_gpu.h:728
STBIDEF stbi_uc * stbi_load(char const *filename, int *x, int *y, int *comp, int req_comp)
GPU_Image *(* CopyImageFromSurface)(GPU_Renderer *renderer, SDL_Surface *surface)
Definition: SDL_gpu.h:562
static void BlitTransformMatrix(GPU_Renderer *renderer, GPU_Image *image, GPU_Rect *src_rect, GPU_Target *target, float x, float y, float *matrix3x3)
void GPU_InitRendererRegister(void)
void GPU_RemoveRenderer(GPU_RendererID id)
#define GPU_ERROR_DETAILS_STRING_MAX
Definition: SDL_gpu.c:33
int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data)
void(* Clear)(GPU_Renderer *renderer, GPU_Target *target)
Definition: SDL_gpu.h:625
void(* SetWrapMode)(GPU_Renderer *renderer, GPU_Image *image, GPU_WrapEnum wrap_mode_x, GPU_WrapEnum wrap_mode_y)
Definition: SDL_gpu.h:622
#define CHECK_CONTEXT
Definition: SDL_gpu.c:21
void(* FreeTarget)(GPU_Renderer *renderer, GPU_Target *target)
Definition: SDL_gpu.h:580
GPU_Camera GPU_GetCamera(GPU_Target *target)
Definition: SDL_gpu.c:637
void GPU_LogInfo(const char *format,...)
Definition: SDL_gpu.c:79
Uint32 GPU_GetCurrentShaderProgram(void)
Definition: SDL_gpu.c:69
GPU_Camera(* SetCamera)(GPU_Renderer *renderer, GPU_Target *target, GPU_Camera *cam)
Definition: SDL_gpu.h:535
void GPU_GetUniformfv(Uint32 program_object, int location, float *values)
Definition: SDL_gpu.c:2427
GLsizei GLsizei GLchar * source
Definition: glew.h:1800
#define CHECK_FUNCTION_POINTER(fn)
Definition: SDL_gpu.c:22
void GPU_SetAttributei(int location, int value)
Definition: SDL_gpu.c:2477
void GPU_GetUniformMatrixfv(Uint32 program_object, int location, float *values)
Definition: SDL_gpu.c:2452
float x
Definition: SDL_gpu.h:29
void(* SetUniformuiv)(GPU_Renderer *renderer, int location, int num_elements_per_value, int num_values, unsigned int *values)
Definition: SDL_gpu.h:701
Uint8 GPU_SaveImage(GPU_Image *image, const char *filename)
Definition: SDL_gpu.c:676
Uint8 use_blending
Definition: SDL_gpu.h:186
GPU_Attribute GPU_MakeAttribute(int location, void *values, GPU_AttributeFormat format)
Definition: SDL_gpu.c:2329
GLenum target
Definition: glew.h:5190
int texcoord_loc
Definition: SDL_gpu.h:220
SDL_Surface * GPU_CopySurfaceFromImage(GPU_Image *image)
Definition: SDL_gpu.c:865
void GPU_Quit(void)
Definition: SDL_gpu.c:463
GPU_BlendFuncEnum source_alpha
Definition: SDL_gpu.h:95
GPU_AttributeFormat GPU_MakeAttributeFormat(int num_elems_per_vertex, GPU_TypeEnum type, Uint8 normalize, int stride_bytes, int offset_bytes)
Definition: SDL_gpu.c:2323
GLclampf f
Definition: glew.h:3024
void GPU_BlitBatch(GPU_Image *image, GPU_Target *target, unsigned int num_sprites, float *values, GPU_BlitFlagEnum flags)
Definition: SDL_gpu.c:1017
GPU_ErrorEnum error
Definition: SDL_gpu.h:460
#define CHECK_RENDERER
Definition: SDL_gpu.c:20