···539539540540void GPU_GetVirtualResolution(GPU_Target* target, Uint16* w, Uint16* h)
541541{
542542+ // No checking here for NULL w or h... Should we?
542543 if (target == NULL)
543543- RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL target");
544544-545545- _gpu_current_renderer->impl->GetVirtualResolution(target, w, h);
544544+ {
545545+ *w = 0;
546546+ *h = 0;
547547+ }
548548+ else {
549549+ *w = target->w;
550550+ *h = target->h;
551551+ }
546552}
547553548554void GPU_SetVirtualResolution(GPU_Target* target, Uint16 w, Uint16 h)
+22-22
src/SDL_gpu_matrix.c
···2020 #endif
2121#endif
22222323-// Visual C does not support C99 (which includes a safe snprintf)
2424-#ifdef _MSC_VER
2525-#define snprintf c99_snprintf
2626-// From Valentin Milea: http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
2727-static_inline int c99_vsnprintf(char* str, size_t size, const char* format, va_list ap)
2828-{
2929- int count = -1;
2323+// Old Visual C did not support C99 (which includes a safe snprintf)
2424+#if defined(_MSC_VER) && (_MSC_VER < 1900)
2525+ #define snprintf c99_snprintf
2626+ // From Valentin Milea: http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
2727+ static_inline int c99_vsnprintf(char* str, size_t size, const char* format, va_list ap)
2828+ {
2929+ int count = -1;
30303131- if (size != 0)
3232- count = _vsnprintf_s(str, size, _TRUNCATE, format, ap);
3333- if (count == -1)
3434- count = _vscprintf(format, ap);
3131+ if (size != 0)
3232+ count = _vsnprintf_s(str, size, _TRUNCATE, format, ap);
3333+ if (count == -1)
3434+ count = _vscprintf(format, ap);
35353636- return count;
3737-}
3636+ return count;
3737+ }
38383939-static_inline int c99_snprintf(char* str, size_t size, const char* format, ...)
4040-{
4141- int count;
4242- va_list ap;
3939+ static_inline int c99_snprintf(char* str, size_t size, const char* format, ...)
4040+ {
4141+ int count;
4242+ va_list ap;
43434444- va_start(ap, format);
4545- count = c99_vsnprintf(str, size, format, ap);
4646- va_end(ap);
4444+ va_start(ap, format);
4545+ count = c99_vsnprintf(str, size, format, ap);
4646+ va_end(ap);
47474848- return count;
4949-}
4848+ return count;
4949+ }
5050#endif
51515252
+1
src/groups.dox
···88 *
99 * Other functions in the Initialization module control how initialization is performed.
1010 *
1111+ *
1112 * \defgroup Logging Debugging, Logging, and Error Handling
1213 * Use GPU_Log() for normal logging output (e.g. to replace printf). Other logging priorities are handled by GPU_LogWarning() and GPU_LogError().
1314 *
···3535#define __func__ __FUNCTION__
3636#endif
37373838-// Visual C does not support C99 (which includes a safe snprintf)
3939-#ifdef _MSC_VER
3838+// Old Visual C did not support C99 (which includes a safe snprintf)
3939+#if defined(_MSC_VER) && (_MSC_VER < 1900)
4040 #define snprintf c99_snprintf
4141 // From Valentin Milea: http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
4242 static_inline int c99_vsnprintf(char* str, size_t size, const char* format, va_list ap)
···8989909091919292+// SDL 1.2 / SDL 2.0 translation layer
929393949495#ifdef SDL_GPU_USE_SDL2
9595- #define GET_ALPHA(sdl_color) ((sdl_color).a)
9696+9797+#define GET_ALPHA(sdl_color) ((sdl_color).a)
9898+9999+static_inline SDL_Window* get_window(Uint32 windowID)
100100+{
101101+ return SDL_GetWindowFromID(windowID);
102102+}
103103+104104+static_inline Uint32 get_window_id(SDL_Window* window)
105105+{
106106+ return SDL_GetWindowID(window);
107107+}
108108+109109+static_inline void get_window_dimensions(SDL_Window* window, int* w, int* h)
110110+{
111111+ SDL_GetWindowSize(window, w, h);
112112+}
113113+114114+static_inline void get_drawable_dimensions(SDL_Window* window, int* w, int* h)
115115+{
116116+ SDL_GL_GetDrawableSize(window, w, h);
117117+}
118118+119119+static_inline void resize_window(GPU_Target* target, int w, int h)
120120+{
121121+ SDL_SetWindowSize(SDL_GetWindowFromID(target->context->windowID), w, h);
122122+}
123123+124124+static_inline Uint8 get_fullscreen_state(SDL_Window* window)
125125+{
126126+ return (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN);
127127+}
128128+129129+static_inline Uint8 has_colorkey(SDL_Surface* surface)
130130+{
131131+ return (SDL_GetColorKey(surface, NULL) == 0);
132132+}
133133+96134#else
9797- #define GET_ALPHA(sdl_color) ((sdl_color).unused)
135135+136136+#define SDL_Window SDL_Surface
137137+#define GET_ALPHA(sdl_color) ((sdl_color).unused)
138138+139139+static_inline SDL_Window* get_window(Uint32 windowID)
140140+{
141141+ return (windowID == 1? SDL_GetVideoSurface() : NULL);
142142+}
143143+144144+static_inline Uint32 get_window_id(SDL_Surface* window)
145145+{
146146+ return (SDL_GetVideoSurface() == window? 1 : 0);
147147+}
148148+149149+static_inline void get_window_dimensions(SDL_Window* window, int* w, int* h)
150150+{
151151+ if(window == NULL)
152152+ return;
153153+ *w = window->w;
154154+ *h = window->h;
155155+}
156156+157157+static_inline void get_drawable_dimensions(SDL_Window* window, int* w, int* h)
158158+{
159159+ get_window_dimensions(window, w, h);
160160+}
161161+162162+static_inline void resize_window(GPU_Target* target, int w, int h)
163163+{
164164+ SDL_Surface* screen = SDL_GetVideoSurface();
165165+ Uint32 flags = screen->flags;
166166+167167+ screen = SDL_SetVideoMode(w, h, 0, flags);
168168+ // NOTE: There's a bug in SDL 1.2. This is a workaround. Let's resize again:
169169+ screen = SDL_SetVideoMode(w, h, 0, flags);
170170+}
171171+172172+static_inline Uint8 get_fullscreen_state(SDL_Window* window)
173173+{
174174+ return (window->flags & SDL_FULLSCREEN);
175175+}
176176+177177+static_inline Uint8 has_colorkey(SDL_Surface* surface)
178178+{
179179+ return (surface->flags & SDL_SRCCOLORKEY);
180180+}
181181+98182#endif
99183100184185185+186186+static_inline void get_target_window_dimensions(GPU_Target* target, int* w, int* h)
187187+{
188188+ SDL_Window* window;
189189+ if(target == NULL || target->context == NULL)
190190+ return;
191191+ window = get_window(target->context->windowID);
192192+ get_window_dimensions(window, w, h);
193193+}
194194+195195+static_inline void get_target_drawable_dimensions(GPU_Target* target, int* w, int* h)
196196+{
197197+ SDL_Window* window;
198198+ if(target == NULL || target->context == NULL)
199199+ return;
200200+ window = get_window(target->context->windowID);
201201+ get_drawable_dimensions(window, w, h);
202202+}
203203+204204+205205+206206+101207#ifndef GL_VERTEX_SHADER
102208 #ifndef SDL_GPU_DISABLE_SHADERS
103209 #define SDL_GPU_DISABLE_SHADERS
···837943static GPU_Target* Init(GPU_Renderer* renderer, GPU_RendererID renderer_request, Uint16 w, Uint16 h, GPU_WindowFlagEnum SDL_flags)
838944{
839945 GPU_InitFlagEnum GPU_flags;
840840-#ifdef SDL_GPU_USE_SDL2
841946 SDL_Window* window;
842842-#else
843843- SDL_Surface* screen;
844844-#endif
845947846948#ifdef SDL_GPU_USE_OPENGL
847949 const char* vendor_string;
···9411043 return NULL;
9421044 }
9431045944944- GPU_SetInitWindow(SDL_GetWindowID(window));
10461046+ GPU_SetInitWindow(get_window_id(window));
9451047 }
9461048 else
9471049 renderer->SDL_init_flags = SDL_flags;
···9491051#else
9501052 SDL_flags |= SDL_OPENGL;
9511053 renderer->SDL_init_flags = SDL_flags;
952952- screen = SDL_SetVideoMode(w, h, 0, SDL_flags);
10541054+ window = SDL_SetVideoMode(w, h, 0, SDL_flags);
9531055954954- if(screen == NULL)
10561056+ if(window == NULL)
9551057 {
9561058 GPU_PushErrorCode("GPU_Init", GPU_ERROR_BACKEND_ERROR, "Screen surface creation failed.");
9571059 return NULL;
···962106496310659641066 // Create or re-init the current target. This also creates the GL context and initializes enabled_features.
965965- #ifdef SDL_GPU_USE_SDL2
966966- if(renderer->impl->CreateTargetFromWindow(renderer, SDL_GetWindowID(window), renderer->current_context_target) == NULL)
967967- return NULL;
968968- #else
969969- if(renderer->impl->CreateTargetFromWindow(renderer, 0, renderer->current_context_target) == NULL)
10671067+ if(renderer->impl->CreateTargetFromWindow(renderer, get_window_id(window), renderer->current_context_target) == NULL)
9701068 return NULL;
971971- #endif
97210699731070 // If the dimensions of the window don't match what we asked for, then set up a virtual resolution to pretend like they are.
9741071 if(!(GPU_flags & GPU_INIT_DISABLE_AUTO_VIRTUAL_RESOLUTION) && w != 0 && h != 0 && (w != renderer->current_context_target->w || h != renderer->current_context_target->h))
···10781175 && get_GLSL_version(&renderer->max_shader_version));
10791176}
1080117711781178+11791179+static void update_stored_dimensions(GPU_Target* target)
11801180+{
11811181+ Uint8 is_fullscreen;
11821182+ SDL_Window* window;
11831183+11841184+ if(target->context == NULL)
11851185+ return;
11861186+11871187+ window = get_window(target->context->windowID);
11881188+ get_window_dimensions(window, &target->context->window_w, &target->context->window_h);
11891189+ is_fullscreen = get_fullscreen_state(window);
11901190+11911191+ if(!is_fullscreen)
11921192+ {
11931193+ target->context->stored_window_w = target->context->window_w;
11941194+ target->context->stored_window_h = target->context->window_h;
11951195+ }
11961196+}
11971197+10811198static GPU_Target* CreateTargetFromWindow(GPU_Renderer* renderer, Uint32 windowID, GPU_Target* target)
10821199{
10831200 Uint8 created = 0; // Make a new one or repurpose an existing target?
10841201 GPU_CONTEXT_DATA* cdata;
10851085-#ifdef SDL_GPU_USE_SDL2
10861202 SDL_Window* window;
10871087-#else
10881088- SDL_Surface* screen;
10891089-#endif
12031203+10901204 int framebuffer_handle;
10911205 SDL_Color white = { 255, 255, 255, 255 };
10921206#ifdef SDL_GPU_USE_OPENGL
···11331247 cdata = (GPU_CONTEXT_DATA*)target->context->data;
11341248 }
1135124911361136- #ifdef SDL_GPU_USE_SDL2
1137125011381138- window = SDL_GetWindowFromID(windowID);
12511251+ window = get_window(windowID);
11391252 if(window == NULL)
11401253 {
11411254 GPU_PushErrorCode("GPU_CreateTargetFromWindow", GPU_ERROR_BACKEND_ERROR, "Failed to acquire the window from the given ID.");
···11521265 }
1153126611541267 // Store the window info
11551155- target->context->windowID = SDL_GetWindowID(window);
12681268+ target->context->windowID = get_window_id(window);
1156126912701270+ #ifdef SDL_GPU_USE_SDL2
11571271 // Make a new context if needed and make it current
11581272 if(created || target->context->context == NULL)
11591273 {
11601274 target->context->context = SDL_GL_CreateContext(window);
11611275 GPU_AddWindowMapping(target);
11621276 }
11631163-11641164- // Get window dimensions
11651165- SDL_GetWindowSize(window, &target->context->window_w, &target->context->window_h);
11661166- target->context->stored_window_w = target->context->window_w;
11671167- target->context->stored_window_h = target->context->window_h;
12771277+11681278 // We need a GL context before we can get the drawable size.
11691279 SDL_GL_GetDrawableSize(window, &target->context->drawable_w, &target->context->drawable_h);
1170128011711281 #else
1172128211731173- screen = SDL_GetVideoSurface();
11741174- if(screen == NULL)
11751175- {
11761176- GPU_PushErrorCode("GPU_CreateTargetFromWindow", GPU_ERROR_BACKEND_ERROR, "Failed to acquire the video surface.");
11771177- if(created)
11781178- {
11791179- SDL_free(cdata->blit_buffer);
11801180- SDL_free(cdata->index_buffer);
11811181- SDL_free(target->context->data);
11821182- SDL_free(target->context);
11831183- SDL_free(target->data);
11841184- SDL_free(target);
11851185- }
11861186- return NULL;
11871187- }
11881188-11891189- target->context->windowID = 1;
11901190- target->context->window_w = target->context->drawable_w = screen->w;
11911191- target->context->window_h = target->context->drawable_h = screen->h;
11921192- target->context->stored_window_w = target->context->window_w;
11931193- target->context->stored_window_h = target->context->window_h;
12831283+ target->context->drawable_w = window->w;
12841284+ target->context->drawable_h = window->h;
1194128511951286 #endif
12871287+12881288+ update_stored_dimensions(target);
12891289+1196129011971291 ((GPU_TARGET_DATA*)target->data)->handle = 0;
11981292 ((GPU_TARGET_DATA*)target->data)->format = GL_RGBA;
···1486158014871581static void MakeCurrent(GPU_Renderer* renderer, GPU_Target* target, Uint32 windowID)
14881582{
14891489-#ifdef SDL_GPU_USE_SDL2
14901490- SDL_GLContext c;
14911491-#else
14921492- SDL_Surface* screen;
14931493-#endif
15831583+ SDL_Window* window;
1494158414951585 if(target == NULL)
14961586 return;
14971497- #ifdef SDL_GPU_USE_SDL2
15871587+14981588 if(target->image != NULL)
14991589 return;
15901590+1500159115011501- c = target->context->context;
15021502- if(c != NULL)
15921592+ if(target->context->context != NULL)
15031593 {
15041594 renderer->current_context_target = target;
15051505- SDL_GL_MakeCurrent(SDL_GetWindowFromID(windowID), c);
15061506- // Reset camera if the target's window was changed
15951595+ #ifdef SDL_GPU_USE_SDL2
15961596+ SDL_GL_MakeCurrent(SDL_GetWindowFromID(windowID), target->context->context);
15971597+ #endif
15981598+15991599+ // Reset window mapping, base size, and camera if the target's window was changed
15071600 if(target->context->windowID != windowID)
15081601 {
15091509- SDL_Window* window;
15101510-15111602 renderer->impl->FlushBlitBuffer(renderer);
1512160315131604 // Update the window mappings
···15171608 GPU_AddWindowMapping(target);
1518160915191610 // Update target's window size
15201520- window = SDL_GetWindowFromID(windowID);
16111611+ window = get_window(windowID);
15211612 if(window != NULL)
15221613 {
15231523- SDL_GetWindowSize(window, &target->context->window_w, &target->context->window_h);
15241524- SDL_GL_GetDrawableSize(window, &target->context->drawable_w, &target->context->drawable_h);
16141614+ get_window_dimensions(window, &target->context->window_w, &target->context->window_h);
16151615+ get_drawable_dimensions(window, &target->context->drawable_w, &target->context->drawable_h);
15251616 target->base_w = target->context->drawable_w;
15261617 target->base_h = target->context->drawable_h;
15271618 }
···15301621 applyTargetCamera(((GPU_CONTEXT_DATA*)renderer->current_context_target->context->data)->last_target);
15311622 }
15321623 }
15331533- #else
15341534- renderer->current_context_target = target;
15351535- // Only one window...
15361536- GPU_RemoveWindowMapping(1);
15371537- target->context->windowID = 1;
15381538- GPU_AddWindowMapping(target);
15391539-15401540- // Update target's window size
15411541- screen = SDL_GetVideoSurface();
15421542- if(screen != NULL)
15431543- {
15441544- target->context->window_w = target->context->drawable_w = screen->w;
15451545- target->context->window_h = target->context->drawable_h = screen->h;
15461546- target->base_w = target->context->drawable_w;
15471547- target->base_h = target->context->drawable_h;
15481548- }
15491549- #endif
15501624}
1551162515521626···16161690 if(isCurrent)
16171691 renderer->impl->FlushBlitBuffer(renderer);
1618169216191619-#ifdef SDL_GPU_USE_SDL2
16201620-16931693+ // Don't need to resize (only update internals) when resolution isn't changing.
16941694+ get_target_window_dimensions(target, &target->context->window_w, &target->context->window_h);
16951695+ get_target_drawable_dimensions(target, &target->context->drawable_w, &target->context->drawable_h);
16961696+ if(target->context->window_w != w || target->context->window_h != h)
16211697 {
16221622- SDL_Window* window = SDL_GetWindowFromID(target->context->windowID);
16231623-16241624- // Don't need to resize (only update internals) when resolution isn't changing.
16251625- SDL_GetWindowSize(window, &target->context->window_w, &target->context->window_h);
16261626- SDL_GL_GetDrawableSize(window, &target->context->drawable_w, &target->context->drawable_h);
16271627- if(target->context->window_w != w || target->context->window_h != h)
16281628- {
16291629- SDL_SetWindowSize(window, w, h);
16301630- SDL_GetWindowSize(window, &target->context->window_w, &target->context->window_h);
16311631- SDL_GL_GetDrawableSize(window, &target->context->drawable_w, &target->context->drawable_h);
16321632- }
16981698+ resize_window(target, w, h);
16991699+ get_target_window_dimensions(target, &target->context->window_w, &target->context->window_h);
17001700+ get_target_drawable_dimensions(target, &target->context->drawable_w, &target->context->drawable_h);
16331701 }
1634170216351635-#else
16361636- SDL_Surface* screen = SDL_GetVideoSurface();
16371637- Uint32 flags = screen->flags;
16381638- GPU_Context* context;
17031703+#ifdef SDL_GPU_USE_SDL1
1639170416401640- // Don't need to resize (only update internals) when resolution isn't changing.
16411641- if(screen->w != w || screen->h != h)
17051705+ // FIXME: Does the entire GL state need to be reset because the screen was recreated?
16421706 {
16431643- screen = SDL_SetVideoMode(w, h, 0, flags);
16441644- // There's a bug in SDL. This is a workaround. Let's resize again:
16451645- screen = SDL_SetVideoMode(w, h, 0, flags);
17071707+ GPU_Context* context;
1646170816471647- if(screen == NULL)
16481648- return 0;
17091709+ // Reset texturing state
17101710+ context = renderer->current_context_target->context;
17111711+ context->use_texturing = 1;
17121712+ ((GPU_CONTEXT_DATA*)context->data)->last_use_texturing = 0;
16491713 }
1650171416511651- target->context->window_w = target->context->drawable_w = screen->w;
16521652- target->context->window_h = target->context->drawable_h = screen->h;
16531653-16541654- // FIXME: Does the entire GL state need to be reset because the screen was recreated?
16551655-16561656- // Reset texturing state
16571657- context = renderer->current_context_target->context;
16581658- context->use_texturing = 1;
16591659- ((GPU_CONTEXT_DATA*)context->data)->last_use_texturing = 0;
16601660-16611715 // Clear target (no state change)
16621716 glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
16631717 glClear( GL_COLOR_BUFFER_BIT );
16641718#endif
1665171916661720 // Store the resolution for fullscreen_desktop changes
16671667- target->context->stored_window_w = target->context->window_w;
16681668- target->context->stored_window_h = target->context->window_h;
17211721+ update_stored_dimensions(target);
1669172216701723 // Update base dimensions
16711724 target->base_w = target->context->drawable_w;
···16861739 applyTargetCamera(target);
1687174016881741 return 1;
16891689-}
16901690-16911691-static void GetVirtualResolution(GPU_Target* target, Uint16* w, Uint16* h)
16921692-{
16931693- if (target == NULL)
16941694- {
16951695- *w = 0;
16961696- *h = 0;
16971697- }
16981698- else {
16991699- *w = target->w;
17001700- *h = target->h;
17011701- }
17021742}
1703174317041744static void SetVirtualResolution(GPU_Renderer* renderer, GPU_Target* target, Uint16 w, Uint16 h)
···17851825 // If we're in windowed mode now and a resolution was stored, restore the original window resolution
17861826 if(was_fullscreen && !is_fullscreen && (target->context->stored_window_w != 0 && target->context->stored_window_h != 0))
17871827 SDL_SetWindowSize(window, target->context->stored_window_w, target->context->stored_window_h);
17881788-17891789- // Update window dims
17901790- SDL_GetWindowSize(window, &target->context->window_w, &target->context->window_h);
17911791- SDL_GL_GetDrawableSize(window, &target->context->drawable_w, &target->context->drawable_h);
17921828 }
1793182917941830#else
···18001836 {
18011837 SDL_WM_ToggleFullScreen(surf);
18021838 is_fullscreen = (surf->flags & SDL_FULLSCREEN);
18031803-18041804- // Update window dims
18051805- target->context->window_w = target->context->drawable_w = surf->w;
18061806- target->context->window_h = target->context->drawable_h = surf->h;
18071839 }
1808184018091841#endif
1810184218111843 if(is_fullscreen != was_fullscreen)
18121844 {
18451845+ // Update window dims
18461846+ get_target_window_dimensions(target, &target->context->window_w, &target->context->window_h);
18471847+ get_target_drawable_dimensions(target, &target->context->drawable_w, &target->context->drawable_h);
18481848+18131849 // If virtual res is not set, we need to update the target dims and reset stuff that no longer is right
18141850 if(!target->using_virtual_resolution)
18151851 {
···23882424 return data;
23892425}
2390242623912391-// From http://stackoverflow.com/questions/5309471/getting-file-extension-in-c
23922392-static const char *get_filename_ext(const char *filename)
23932393-{
23942394- const char *dot = strrchr(filename, '.');
23952395- if(!dot || dot == filename)
23962396- return "";
23972397- return dot + 1;
23982398-}
23992399-24002427static Uint8 SaveImage(GPU_Renderer* renderer, GPU_Image* image, const char* filename, GPU_FileFormatEnum format)
24012428{
24022429 Uint8 result;
24032403- unsigned char* data;
24302430+ SDL_Surface* surface;
2404243124052432 if(image == NULL || filename == NULL ||
24062433 image->texture_w < 1 || image->texture_h < 1 || image->bytes_per_pixel < 1 || image->bytes_per_pixel > 4)
···24082435 return 0;
24092436 }
2410243724112411- data = getRawImageData(renderer, image);
24382438+ surface = renderer->impl->CopySurfaceFromImage(renderer, image);
2412243924132413- if(data == NULL)
24142414- {
24152415- GPU_PushErrorCode("GPU_SaveImage", GPU_ERROR_BACKEND_ERROR, "Could not retrieve texture data.");
24402440+ if(surface == NULL)
24162441 return 0;
24172417- }
24182418-24192419- if(format == GPU_FILE_AUTO)
24202420- {
24212421- const char* extension = get_filename_ext(filename);
24222422- if(gpu_strcasecmp(extension, "png") == 0)
24232423- format = GPU_FILE_PNG;
24242424- else if(gpu_strcasecmp(extension, "bmp") == 0)
24252425- format = GPU_FILE_BMP;
24262426- else if(gpu_strcasecmp(extension, "tga") == 0)
24272427- format = GPU_FILE_TGA;
24282428- else
24292429- {
24302430- GPU_PushErrorCode("GPU_SaveImage", GPU_ERROR_DATA_ERROR, "Could not detect output file format from file name");
24312431- SDL_free(data);
24322432- return 0;
24332433- }
24342434- }
24352435-24362436- switch(format)
24372437- {
24382438- case GPU_FILE_PNG:
24392439- result = (stbi_write_png(filename, image->texture_w, image->texture_h, image->bytes_per_pixel, (const unsigned char *const)data, 0) > 0);
24402440- break;
24412441- case GPU_FILE_BMP:
24422442- result = (stbi_write_bmp(filename, image->texture_w, image->texture_h, image->bytes_per_pixel, (void*)data) > 0);
24432443- break;
24442444- case GPU_FILE_TGA:
24452445- result = (stbi_write_tga(filename, image->texture_w, image->texture_h, image->bytes_per_pixel, (void*)data) > 0);
24462446- break;
24472447- default:
24482448- GPU_PushErrorCode("GPU_SaveImage", GPU_ERROR_DATA_ERROR, "Unsupported output file format");
24492449- result = 0;
24502450- break;
24512451- }
24422442+24432443+ result = GPU_SaveSurface(surface, filename, format);
2452244424532453- SDL_free(data);
24452445+ SDL_FreeSurface(surface);
24542446 return result;
24552447}
24562448···25112503 unsigned char* data;
25122504 SDL_Surface* result;
25132505 SDL_PixelFormat* format;
25062506+ int w, h;
2514250725152508 if(image == NULL)
25162509 {
25172510 GPU_PushErrorCode("GPU_CopySurfaceFromImage", GPU_ERROR_NULL_ARGUMENT, "image");
25182511 return NULL;
25192512 }
25202520- if(image->texture_w < 1 || image->texture_h < 1)
25132513+ if(image->w < 1 || image->h < 1)
25212514 {
25222515 GPU_PushErrorCode("GPU_CopySurfaceFromImage", GPU_ERROR_DATA_ERROR, "Invalid image dimensions (%dx%d)", image->base_w, image->base_h);
25232516 return NULL;
25242517 }
2525251825192519+ // FIXME: Virtual resolutions overwrite the NPOT dimensions when NPOT textures are not supported!
25202520+ if(image->using_virtual_resolution)
25212521+ {
25222522+ w = image->texture_w;
25232523+ h = image->texture_h;
25242524+ }
25252525+ else
25262526+ {
25272527+ w = image->w;
25282528+ h = image->h;
25292529+ }
25262530 data = getRawImageData(renderer, image);
2527253125282532 if(data == NULL)
···2533253725342538 format = AllocFormat(((GPU_IMAGE_DATA*)image->data)->format);
2535253925362536- result = SDL_CreateRGBSurface(SDL_SWSURFACE, image->texture_w, image->texture_h, format->BitsPerPixel, format->Rmask, format->Gmask, format->Bmask, format->Amask);
25402540+ result = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, format->BitsPerPixel, format->Rmask, format->Gmask, format->Bmask, format->Amask);
2537254125382542 if(result == NULL)
25392543 {
25402540- GPU_PushErrorCode("GPU_CopySurfaceFromImage", GPU_ERROR_DATA_ERROR, "Failed to create new %dx%d surface", image->texture_w, image->texture_h);
25442544+ GPU_PushErrorCode("GPU_CopySurfaceFromImage", GPU_ERROR_DATA_ERROR, "Failed to create new %dx%d surface", w, h);
25412545 SDL_free(data);
25422546 return NULL;
25432547 }
···25452549 // Copy row-by-row in case the pitch doesn't match
25462550 {
25472551 int i;
25482548- int source_pitch = image->texture_w*format->BytesPerPixel;
25492549- for(i = 0; i < image->texture_h; ++i)
25522552+ int source_pitch = image->texture_w*format->BytesPerPixel; // Use the actual texture width to pull from the data
25532553+ for(i = 0; i < h; ++i)
25502554 {
25512555 memcpy((Uint8*)result->pixels + i*result->pitch, data + source_pitch*i, source_pitch);
25522556 }
···28252829 }
2826283028272831 return result;
28282828-}
28292829-28302830-static Uint8 hasColorkey(SDL_Surface* surface)
28312831-{
28322832-#ifdef SDL_GPU_USE_SDL2
28332833- return (SDL_GetColorKey(surface, NULL) == 0);
28342834-#else
28352835- return (surface->flags & SDL_SRCCOLORKEY);
28362836-#endif
28372832}
2838283328392834static void FreeFormat(SDL_PixelFormat* format)
···35333528 // See what the best image format is.
35343529 if(surface->format->Amask == 0)
35353530 {
35363536- if(hasColorkey(surface))
35313531+ if(has_colorkey(surface))
35373532 format = GPU_FORMAT_RGBA;
35383533 else
35393534 format = GPU_FORMAT_RGB;
+1
src/renderer_OpenGL_1_BASE.c
···1313// Most of the code pulled in from here...
1414#define SDL_GPU_USE_OPENGL
1515#define SDL_GPU_DISABLE_SHADERS
1616+#define SDL_GPU_DISABLE_RENDER_TO_TEXTURE
1617#define SDL_GPU_USE_FIXED_FUNCTION_PIPELINE
1718#define SDL_GPU_GL_TIER 1
1819#define SDL_GPU_GL_MAJOR_VERSION 1