this repo has no description
0
fork

Configure Feed

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

Merge pull request #1 from grimfang4/master

Sync with master

+234 -233
-3
include/SDL_gpu_RendererImpl.h
··· 42 42 43 43 /*! \see GPU_SetVirtualResolution() */ 44 44 void (SDLCALL *SetVirtualResolution)(GPU_Renderer* renderer, GPU_Target* target, Uint16 w, Uint16 h); 45 - 46 - /*! \see GPU_GetVirtualResolution() */ 47 - void (SDLCALL *GetVirtualResolution)(GPU_Target* target, Uint16* w, Uint16* h); 48 45 49 46 /*! \see GPU_UnsetVirtualResolution() */ 50 47 void (SDLCALL *UnsetVirtualResolution)(GPU_Renderer* renderer, GPU_Target* target);
+9 -3
src/SDL_gpu.c
··· 539 539 540 540 void GPU_GetVirtualResolution(GPU_Target* target, Uint16* w, Uint16* h) 541 541 { 542 + // No checking here for NULL w or h... Should we? 542 543 if (target == NULL) 543 - RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL target"); 544 - 545 - _gpu_current_renderer->impl->GetVirtualResolution(target, w, h); 544 + { 545 + *w = 0; 546 + *h = 0; 547 + } 548 + else { 549 + *w = target->w; 550 + *h = target->h; 551 + } 546 552 } 547 553 548 554 void GPU_SetVirtualResolution(GPU_Target* target, Uint16 w, Uint16 h)
+22 -22
src/SDL_gpu_matrix.c
··· 20 20 #endif 21 21 #endif 22 22 23 - // Visual C does not support C99 (which includes a safe snprintf) 24 - #ifdef _MSC_VER 25 - #define snprintf c99_snprintf 26 - // From Valentin Milea: http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010 27 - static_inline int c99_vsnprintf(char* str, size_t size, const char* format, va_list ap) 28 - { 29 - int count = -1; 23 + // Old Visual C did not support C99 (which includes a safe snprintf) 24 + #if defined(_MSC_VER) && (_MSC_VER < 1900) 25 + #define snprintf c99_snprintf 26 + // From Valentin Milea: http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010 27 + static_inline int c99_vsnprintf(char* str, size_t size, const char* format, va_list ap) 28 + { 29 + int count = -1; 30 30 31 - if (size != 0) 32 - count = _vsnprintf_s(str, size, _TRUNCATE, format, ap); 33 - if (count == -1) 34 - count = _vscprintf(format, ap); 31 + if (size != 0) 32 + count = _vsnprintf_s(str, size, _TRUNCATE, format, ap); 33 + if (count == -1) 34 + count = _vscprintf(format, ap); 35 35 36 - return count; 37 - } 36 + return count; 37 + } 38 38 39 - static_inline int c99_snprintf(char* str, size_t size, const char* format, ...) 40 - { 41 - int count; 42 - va_list ap; 39 + static_inline int c99_snprintf(char* str, size_t size, const char* format, ...) 40 + { 41 + int count; 42 + va_list ap; 43 43 44 - va_start(ap, format); 45 - count = c99_vsnprintf(str, size, format, ap); 46 - va_end(ap); 44 + va_start(ap, format); 45 + count = c99_vsnprintf(str, size, format, ap); 46 + va_end(ap); 47 47 48 - return count; 49 - } 48 + return count; 49 + } 50 50 #endif 51 51 52 52
+1
src/groups.dox
··· 8 8 * 9 9 * Other functions in the Initialization module control how initialization is performed. 10 10 * 11 + * 11 12 * \defgroup Logging Debugging, Logging, and Error Handling 12 13 * Use GPU_Log() for normal logging output (e.g. to replace printf). Other logging priorities are handled by GPU_LogWarning() and GPU_LogError(). 13 14 *
+1
src/renderer_GLES_1.c
··· 18 18 #define SDL_GPU_USE_ARRAY_PIPELINE 19 19 #define SDL_GPU_DISABLE_TEXTURE_GETS 20 20 #define SDL_GPU_DISABLE_SHADERS 21 + #define SDL_GPU_DISABLE_RENDER_TO_TEXTURE 21 22 #define SDL_GPU_APPLY_TRANSFORMS_TO_GL_STACK 22 23 #define SDL_GPU_NO_VAO 23 24
+199 -204
src/renderer_GL_common.inl
··· 35 35 #define __func__ __FUNCTION__ 36 36 #endif 37 37 38 - // Visual C does not support C99 (which includes a safe snprintf) 39 - #ifdef _MSC_VER 38 + // Old Visual C did not support C99 (which includes a safe snprintf) 39 + #if defined(_MSC_VER) && (_MSC_VER < 1900) 40 40 #define snprintf c99_snprintf 41 41 // From Valentin Milea: http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010 42 42 static_inline int c99_vsnprintf(char* str, size_t size, const char* format, va_list ap) ··· 89 89 90 90 91 91 92 + // SDL 1.2 / SDL 2.0 translation layer 92 93 93 94 94 95 #ifdef SDL_GPU_USE_SDL2 95 - #define GET_ALPHA(sdl_color) ((sdl_color).a) 96 + 97 + #define GET_ALPHA(sdl_color) ((sdl_color).a) 98 + 99 + static_inline SDL_Window* get_window(Uint32 windowID) 100 + { 101 + return SDL_GetWindowFromID(windowID); 102 + } 103 + 104 + static_inline Uint32 get_window_id(SDL_Window* window) 105 + { 106 + return SDL_GetWindowID(window); 107 + } 108 + 109 + static_inline void get_window_dimensions(SDL_Window* window, int* w, int* h) 110 + { 111 + SDL_GetWindowSize(window, w, h); 112 + } 113 + 114 + static_inline void get_drawable_dimensions(SDL_Window* window, int* w, int* h) 115 + { 116 + SDL_GL_GetDrawableSize(window, w, h); 117 + } 118 + 119 + static_inline void resize_window(GPU_Target* target, int w, int h) 120 + { 121 + SDL_SetWindowSize(SDL_GetWindowFromID(target->context->windowID), w, h); 122 + } 123 + 124 + static_inline Uint8 get_fullscreen_state(SDL_Window* window) 125 + { 126 + return (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN); 127 + } 128 + 129 + static_inline Uint8 has_colorkey(SDL_Surface* surface) 130 + { 131 + return (SDL_GetColorKey(surface, NULL) == 0); 132 + } 133 + 96 134 #else 97 - #define GET_ALPHA(sdl_color) ((sdl_color).unused) 135 + 136 + #define SDL_Window SDL_Surface 137 + #define GET_ALPHA(sdl_color) ((sdl_color).unused) 138 + 139 + static_inline SDL_Window* get_window(Uint32 windowID) 140 + { 141 + return (windowID == 1? SDL_GetVideoSurface() : NULL); 142 + } 143 + 144 + static_inline Uint32 get_window_id(SDL_Surface* window) 145 + { 146 + return (SDL_GetVideoSurface() == window? 1 : 0); 147 + } 148 + 149 + static_inline void get_window_dimensions(SDL_Window* window, int* w, int* h) 150 + { 151 + if(window == NULL) 152 + return; 153 + *w = window->w; 154 + *h = window->h; 155 + } 156 + 157 + static_inline void get_drawable_dimensions(SDL_Window* window, int* w, int* h) 158 + { 159 + get_window_dimensions(window, w, h); 160 + } 161 + 162 + static_inline void resize_window(GPU_Target* target, int w, int h) 163 + { 164 + SDL_Surface* screen = SDL_GetVideoSurface(); 165 + Uint32 flags = screen->flags; 166 + 167 + screen = SDL_SetVideoMode(w, h, 0, flags); 168 + // NOTE: There's a bug in SDL 1.2. This is a workaround. Let's resize again: 169 + screen = SDL_SetVideoMode(w, h, 0, flags); 170 + } 171 + 172 + static_inline Uint8 get_fullscreen_state(SDL_Window* window) 173 + { 174 + return (window->flags & SDL_FULLSCREEN); 175 + } 176 + 177 + static_inline Uint8 has_colorkey(SDL_Surface* surface) 178 + { 179 + return (surface->flags & SDL_SRCCOLORKEY); 180 + } 181 + 98 182 #endif 99 183 100 184 185 + 186 + static_inline void get_target_window_dimensions(GPU_Target* target, int* w, int* h) 187 + { 188 + SDL_Window* window; 189 + if(target == NULL || target->context == NULL) 190 + return; 191 + window = get_window(target->context->windowID); 192 + get_window_dimensions(window, w, h); 193 + } 194 + 195 + static_inline void get_target_drawable_dimensions(GPU_Target* target, int* w, int* h) 196 + { 197 + SDL_Window* window; 198 + if(target == NULL || target->context == NULL) 199 + return; 200 + window = get_window(target->context->windowID); 201 + get_drawable_dimensions(window, w, h); 202 + } 203 + 204 + 205 + 206 + 101 207 #ifndef GL_VERTEX_SHADER 102 208 #ifndef SDL_GPU_DISABLE_SHADERS 103 209 #define SDL_GPU_DISABLE_SHADERS ··· 837 943 static GPU_Target* Init(GPU_Renderer* renderer, GPU_RendererID renderer_request, Uint16 w, Uint16 h, GPU_WindowFlagEnum SDL_flags) 838 944 { 839 945 GPU_InitFlagEnum GPU_flags; 840 - #ifdef SDL_GPU_USE_SDL2 841 946 SDL_Window* window; 842 - #else 843 - SDL_Surface* screen; 844 - #endif 845 947 846 948 #ifdef SDL_GPU_USE_OPENGL 847 949 const char* vendor_string; ··· 941 1043 return NULL; 942 1044 } 943 1045 944 - GPU_SetInitWindow(SDL_GetWindowID(window)); 1046 + GPU_SetInitWindow(get_window_id(window)); 945 1047 } 946 1048 else 947 1049 renderer->SDL_init_flags = SDL_flags; ··· 949 1051 #else 950 1052 SDL_flags |= SDL_OPENGL; 951 1053 renderer->SDL_init_flags = SDL_flags; 952 - screen = SDL_SetVideoMode(w, h, 0, SDL_flags); 1054 + window = SDL_SetVideoMode(w, h, 0, SDL_flags); 953 1055 954 - if(screen == NULL) 1056 + if(window == NULL) 955 1057 { 956 1058 GPU_PushErrorCode("GPU_Init", GPU_ERROR_BACKEND_ERROR, "Screen surface creation failed."); 957 1059 return NULL; ··· 962 1064 963 1065 964 1066 // Create or re-init the current target. This also creates the GL context and initializes enabled_features. 965 - #ifdef SDL_GPU_USE_SDL2 966 - if(renderer->impl->CreateTargetFromWindow(renderer, SDL_GetWindowID(window), renderer->current_context_target) == NULL) 967 - return NULL; 968 - #else 969 - if(renderer->impl->CreateTargetFromWindow(renderer, 0, renderer->current_context_target) == NULL) 1067 + if(renderer->impl->CreateTargetFromWindow(renderer, get_window_id(window), renderer->current_context_target) == NULL) 970 1068 return NULL; 971 - #endif 972 1069 973 1070 // If the dimensions of the window don't match what we asked for, then set up a virtual resolution to pretend like they are. 974 1071 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)) ··· 1078 1175 && get_GLSL_version(&renderer->max_shader_version)); 1079 1176 } 1080 1177 1178 + 1179 + static void update_stored_dimensions(GPU_Target* target) 1180 + { 1181 + Uint8 is_fullscreen; 1182 + SDL_Window* window; 1183 + 1184 + if(target->context == NULL) 1185 + return; 1186 + 1187 + window = get_window(target->context->windowID); 1188 + get_window_dimensions(window, &target->context->window_w, &target->context->window_h); 1189 + is_fullscreen = get_fullscreen_state(window); 1190 + 1191 + if(!is_fullscreen) 1192 + { 1193 + target->context->stored_window_w = target->context->window_w; 1194 + target->context->stored_window_h = target->context->window_h; 1195 + } 1196 + } 1197 + 1081 1198 static GPU_Target* CreateTargetFromWindow(GPU_Renderer* renderer, Uint32 windowID, GPU_Target* target) 1082 1199 { 1083 1200 Uint8 created = 0; // Make a new one or repurpose an existing target? 1084 1201 GPU_CONTEXT_DATA* cdata; 1085 - #ifdef SDL_GPU_USE_SDL2 1086 1202 SDL_Window* window; 1087 - #else 1088 - SDL_Surface* screen; 1089 - #endif 1203 + 1090 1204 int framebuffer_handle; 1091 1205 SDL_Color white = { 255, 255, 255, 255 }; 1092 1206 #ifdef SDL_GPU_USE_OPENGL ··· 1133 1247 cdata = (GPU_CONTEXT_DATA*)target->context->data; 1134 1248 } 1135 1249 1136 - #ifdef SDL_GPU_USE_SDL2 1137 1250 1138 - window = SDL_GetWindowFromID(windowID); 1251 + window = get_window(windowID); 1139 1252 if(window == NULL) 1140 1253 { 1141 1254 GPU_PushErrorCode("GPU_CreateTargetFromWindow", GPU_ERROR_BACKEND_ERROR, "Failed to acquire the window from the given ID."); ··· 1152 1265 } 1153 1266 1154 1267 // Store the window info 1155 - target->context->windowID = SDL_GetWindowID(window); 1268 + target->context->windowID = get_window_id(window); 1156 1269 1270 + #ifdef SDL_GPU_USE_SDL2 1157 1271 // Make a new context if needed and make it current 1158 1272 if(created || target->context->context == NULL) 1159 1273 { 1160 1274 target->context->context = SDL_GL_CreateContext(window); 1161 1275 GPU_AddWindowMapping(target); 1162 1276 } 1163 - 1164 - // Get window dimensions 1165 - SDL_GetWindowSize(window, &target->context->window_w, &target->context->window_h); 1166 - target->context->stored_window_w = target->context->window_w; 1167 - target->context->stored_window_h = target->context->window_h; 1277 + 1168 1278 // We need a GL context before we can get the drawable size. 1169 1279 SDL_GL_GetDrawableSize(window, &target->context->drawable_w, &target->context->drawable_h); 1170 1280 1171 1281 #else 1172 1282 1173 - screen = SDL_GetVideoSurface(); 1174 - if(screen == NULL) 1175 - { 1176 - GPU_PushErrorCode("GPU_CreateTargetFromWindow", GPU_ERROR_BACKEND_ERROR, "Failed to acquire the video surface."); 1177 - if(created) 1178 - { 1179 - SDL_free(cdata->blit_buffer); 1180 - SDL_free(cdata->index_buffer); 1181 - SDL_free(target->context->data); 1182 - SDL_free(target->context); 1183 - SDL_free(target->data); 1184 - SDL_free(target); 1185 - } 1186 - return NULL; 1187 - } 1188 - 1189 - target->context->windowID = 1; 1190 - target->context->window_w = target->context->drawable_w = screen->w; 1191 - target->context->window_h = target->context->drawable_h = screen->h; 1192 - target->context->stored_window_w = target->context->window_w; 1193 - target->context->stored_window_h = target->context->window_h; 1283 + target->context->drawable_w = window->w; 1284 + target->context->drawable_h = window->h; 1194 1285 1195 1286 #endif 1287 + 1288 + update_stored_dimensions(target); 1289 + 1196 1290 1197 1291 ((GPU_TARGET_DATA*)target->data)->handle = 0; 1198 1292 ((GPU_TARGET_DATA*)target->data)->format = GL_RGBA; ··· 1486 1580 1487 1581 static void MakeCurrent(GPU_Renderer* renderer, GPU_Target* target, Uint32 windowID) 1488 1582 { 1489 - #ifdef SDL_GPU_USE_SDL2 1490 - SDL_GLContext c; 1491 - #else 1492 - SDL_Surface* screen; 1493 - #endif 1583 + SDL_Window* window; 1494 1584 1495 1585 if(target == NULL) 1496 1586 return; 1497 - #ifdef SDL_GPU_USE_SDL2 1587 + 1498 1588 if(target->image != NULL) 1499 1589 return; 1590 + 1500 1591 1501 - c = target->context->context; 1502 - if(c != NULL) 1592 + if(target->context->context != NULL) 1503 1593 { 1504 1594 renderer->current_context_target = target; 1505 - SDL_GL_MakeCurrent(SDL_GetWindowFromID(windowID), c); 1506 - // Reset camera if the target's window was changed 1595 + #ifdef SDL_GPU_USE_SDL2 1596 + SDL_GL_MakeCurrent(SDL_GetWindowFromID(windowID), target->context->context); 1597 + #endif 1598 + 1599 + // Reset window mapping, base size, and camera if the target's window was changed 1507 1600 if(target->context->windowID != windowID) 1508 1601 { 1509 - SDL_Window* window; 1510 - 1511 1602 renderer->impl->FlushBlitBuffer(renderer); 1512 1603 1513 1604 // Update the window mappings ··· 1517 1608 GPU_AddWindowMapping(target); 1518 1609 1519 1610 // Update target's window size 1520 - window = SDL_GetWindowFromID(windowID); 1611 + window = get_window(windowID); 1521 1612 if(window != NULL) 1522 1613 { 1523 - SDL_GetWindowSize(window, &target->context->window_w, &target->context->window_h); 1524 - SDL_GL_GetDrawableSize(window, &target->context->drawable_w, &target->context->drawable_h); 1614 + get_window_dimensions(window, &target->context->window_w, &target->context->window_h); 1615 + get_drawable_dimensions(window, &target->context->drawable_w, &target->context->drawable_h); 1525 1616 target->base_w = target->context->drawable_w; 1526 1617 target->base_h = target->context->drawable_h; 1527 1618 } ··· 1530 1621 applyTargetCamera(((GPU_CONTEXT_DATA*)renderer->current_context_target->context->data)->last_target); 1531 1622 } 1532 1623 } 1533 - #else 1534 - renderer->current_context_target = target; 1535 - // Only one window... 1536 - GPU_RemoveWindowMapping(1); 1537 - target->context->windowID = 1; 1538 - GPU_AddWindowMapping(target); 1539 - 1540 - // Update target's window size 1541 - screen = SDL_GetVideoSurface(); 1542 - if(screen != NULL) 1543 - { 1544 - target->context->window_w = target->context->drawable_w = screen->w; 1545 - target->context->window_h = target->context->drawable_h = screen->h; 1546 - target->base_w = target->context->drawable_w; 1547 - target->base_h = target->context->drawable_h; 1548 - } 1549 - #endif 1550 1624 } 1551 1625 1552 1626 ··· 1616 1690 if(isCurrent) 1617 1691 renderer->impl->FlushBlitBuffer(renderer); 1618 1692 1619 - #ifdef SDL_GPU_USE_SDL2 1620 - 1693 + // Don't need to resize (only update internals) when resolution isn't changing. 1694 + get_target_window_dimensions(target, &target->context->window_w, &target->context->window_h); 1695 + get_target_drawable_dimensions(target, &target->context->drawable_w, &target->context->drawable_h); 1696 + if(target->context->window_w != w || target->context->window_h != h) 1621 1697 { 1622 - SDL_Window* window = SDL_GetWindowFromID(target->context->windowID); 1623 - 1624 - // Don't need to resize (only update internals) when resolution isn't changing. 1625 - SDL_GetWindowSize(window, &target->context->window_w, &target->context->window_h); 1626 - SDL_GL_GetDrawableSize(window, &target->context->drawable_w, &target->context->drawable_h); 1627 - if(target->context->window_w != w || target->context->window_h != h) 1628 - { 1629 - SDL_SetWindowSize(window, w, h); 1630 - SDL_GetWindowSize(window, &target->context->window_w, &target->context->window_h); 1631 - SDL_GL_GetDrawableSize(window, &target->context->drawable_w, &target->context->drawable_h); 1632 - } 1698 + resize_window(target, w, h); 1699 + get_target_window_dimensions(target, &target->context->window_w, &target->context->window_h); 1700 + get_target_drawable_dimensions(target, &target->context->drawable_w, &target->context->drawable_h); 1633 1701 } 1634 1702 1635 - #else 1636 - SDL_Surface* screen = SDL_GetVideoSurface(); 1637 - Uint32 flags = screen->flags; 1638 - GPU_Context* context; 1703 + #ifdef SDL_GPU_USE_SDL1 1639 1704 1640 - // Don't need to resize (only update internals) when resolution isn't changing. 1641 - if(screen->w != w || screen->h != h) 1705 + // FIXME: Does the entire GL state need to be reset because the screen was recreated? 1642 1706 { 1643 - screen = SDL_SetVideoMode(w, h, 0, flags); 1644 - // There's a bug in SDL. This is a workaround. Let's resize again: 1645 - screen = SDL_SetVideoMode(w, h, 0, flags); 1707 + GPU_Context* context; 1646 1708 1647 - if(screen == NULL) 1648 - return 0; 1709 + // Reset texturing state 1710 + context = renderer->current_context_target->context; 1711 + context->use_texturing = 1; 1712 + ((GPU_CONTEXT_DATA*)context->data)->last_use_texturing = 0; 1649 1713 } 1650 1714 1651 - target->context->window_w = target->context->drawable_w = screen->w; 1652 - target->context->window_h = target->context->drawable_h = screen->h; 1653 - 1654 - // FIXME: Does the entire GL state need to be reset because the screen was recreated? 1655 - 1656 - // Reset texturing state 1657 - context = renderer->current_context_target->context; 1658 - context->use_texturing = 1; 1659 - ((GPU_CONTEXT_DATA*)context->data)->last_use_texturing = 0; 1660 - 1661 1715 // Clear target (no state change) 1662 1716 glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); 1663 1717 glClear( GL_COLOR_BUFFER_BIT ); 1664 1718 #endif 1665 1719 1666 1720 // Store the resolution for fullscreen_desktop changes 1667 - target->context->stored_window_w = target->context->window_w; 1668 - target->context->stored_window_h = target->context->window_h; 1721 + update_stored_dimensions(target); 1669 1722 1670 1723 // Update base dimensions 1671 1724 target->base_w = target->context->drawable_w; ··· 1686 1739 applyTargetCamera(target); 1687 1740 1688 1741 return 1; 1689 - } 1690 - 1691 - static void GetVirtualResolution(GPU_Target* target, Uint16* w, Uint16* h) 1692 - { 1693 - if (target == NULL) 1694 - { 1695 - *w = 0; 1696 - *h = 0; 1697 - } 1698 - else { 1699 - *w = target->w; 1700 - *h = target->h; 1701 - } 1702 1742 } 1703 1743 1704 1744 static void SetVirtualResolution(GPU_Renderer* renderer, GPU_Target* target, Uint16 w, Uint16 h) ··· 1785 1825 // If we're in windowed mode now and a resolution was stored, restore the original window resolution 1786 1826 if(was_fullscreen && !is_fullscreen && (target->context->stored_window_w != 0 && target->context->stored_window_h != 0)) 1787 1827 SDL_SetWindowSize(window, target->context->stored_window_w, target->context->stored_window_h); 1788 - 1789 - // Update window dims 1790 - SDL_GetWindowSize(window, &target->context->window_w, &target->context->window_h); 1791 - SDL_GL_GetDrawableSize(window, &target->context->drawable_w, &target->context->drawable_h); 1792 1828 } 1793 1829 1794 1830 #else ··· 1800 1836 { 1801 1837 SDL_WM_ToggleFullScreen(surf); 1802 1838 is_fullscreen = (surf->flags & SDL_FULLSCREEN); 1803 - 1804 - // Update window dims 1805 - target->context->window_w = target->context->drawable_w = surf->w; 1806 - target->context->window_h = target->context->drawable_h = surf->h; 1807 1839 } 1808 1840 1809 1841 #endif 1810 1842 1811 1843 if(is_fullscreen != was_fullscreen) 1812 1844 { 1845 + // Update window dims 1846 + get_target_window_dimensions(target, &target->context->window_w, &target->context->window_h); 1847 + get_target_drawable_dimensions(target, &target->context->drawable_w, &target->context->drawable_h); 1848 + 1813 1849 // If virtual res is not set, we need to update the target dims and reset stuff that no longer is right 1814 1850 if(!target->using_virtual_resolution) 1815 1851 { ··· 2388 2424 return data; 2389 2425 } 2390 2426 2391 - // From http://stackoverflow.com/questions/5309471/getting-file-extension-in-c 2392 - static const char *get_filename_ext(const char *filename) 2393 - { 2394 - const char *dot = strrchr(filename, '.'); 2395 - if(!dot || dot == filename) 2396 - return ""; 2397 - return dot + 1; 2398 - } 2399 - 2400 2427 static Uint8 SaveImage(GPU_Renderer* renderer, GPU_Image* image, const char* filename, GPU_FileFormatEnum format) 2401 2428 { 2402 2429 Uint8 result; 2403 - unsigned char* data; 2430 + SDL_Surface* surface; 2404 2431 2405 2432 if(image == NULL || filename == NULL || 2406 2433 image->texture_w < 1 || image->texture_h < 1 || image->bytes_per_pixel < 1 || image->bytes_per_pixel > 4) ··· 2408 2435 return 0; 2409 2436 } 2410 2437 2411 - data = getRawImageData(renderer, image); 2438 + surface = renderer->impl->CopySurfaceFromImage(renderer, image); 2412 2439 2413 - if(data == NULL) 2414 - { 2415 - GPU_PushErrorCode("GPU_SaveImage", GPU_ERROR_BACKEND_ERROR, "Could not retrieve texture data."); 2440 + if(surface == NULL) 2416 2441 return 0; 2417 - } 2418 - 2419 - if(format == GPU_FILE_AUTO) 2420 - { 2421 - const char* extension = get_filename_ext(filename); 2422 - if(gpu_strcasecmp(extension, "png") == 0) 2423 - format = GPU_FILE_PNG; 2424 - else if(gpu_strcasecmp(extension, "bmp") == 0) 2425 - format = GPU_FILE_BMP; 2426 - else if(gpu_strcasecmp(extension, "tga") == 0) 2427 - format = GPU_FILE_TGA; 2428 - else 2429 - { 2430 - GPU_PushErrorCode("GPU_SaveImage", GPU_ERROR_DATA_ERROR, "Could not detect output file format from file name"); 2431 - SDL_free(data); 2432 - return 0; 2433 - } 2434 - } 2435 - 2436 - switch(format) 2437 - { 2438 - case GPU_FILE_PNG: 2439 - result = (stbi_write_png(filename, image->texture_w, image->texture_h, image->bytes_per_pixel, (const unsigned char *const)data, 0) > 0); 2440 - break; 2441 - case GPU_FILE_BMP: 2442 - result = (stbi_write_bmp(filename, image->texture_w, image->texture_h, image->bytes_per_pixel, (void*)data) > 0); 2443 - break; 2444 - case GPU_FILE_TGA: 2445 - result = (stbi_write_tga(filename, image->texture_w, image->texture_h, image->bytes_per_pixel, (void*)data) > 0); 2446 - break; 2447 - default: 2448 - GPU_PushErrorCode("GPU_SaveImage", GPU_ERROR_DATA_ERROR, "Unsupported output file format"); 2449 - result = 0; 2450 - break; 2451 - } 2442 + 2443 + result = GPU_SaveSurface(surface, filename, format); 2452 2444 2453 - SDL_free(data); 2445 + SDL_FreeSurface(surface); 2454 2446 return result; 2455 2447 } 2456 2448 ··· 2511 2503 unsigned char* data; 2512 2504 SDL_Surface* result; 2513 2505 SDL_PixelFormat* format; 2506 + int w, h; 2514 2507 2515 2508 if(image == NULL) 2516 2509 { 2517 2510 GPU_PushErrorCode("GPU_CopySurfaceFromImage", GPU_ERROR_NULL_ARGUMENT, "image"); 2518 2511 return NULL; 2519 2512 } 2520 - if(image->texture_w < 1 || image->texture_h < 1) 2513 + if(image->w < 1 || image->h < 1) 2521 2514 { 2522 2515 GPU_PushErrorCode("GPU_CopySurfaceFromImage", GPU_ERROR_DATA_ERROR, "Invalid image dimensions (%dx%d)", image->base_w, image->base_h); 2523 2516 return NULL; 2524 2517 } 2525 2518 2519 + // FIXME: Virtual resolutions overwrite the NPOT dimensions when NPOT textures are not supported! 2520 + if(image->using_virtual_resolution) 2521 + { 2522 + w = image->texture_w; 2523 + h = image->texture_h; 2524 + } 2525 + else 2526 + { 2527 + w = image->w; 2528 + h = image->h; 2529 + } 2526 2530 data = getRawImageData(renderer, image); 2527 2531 2528 2532 if(data == NULL) ··· 2533 2537 2534 2538 format = AllocFormat(((GPU_IMAGE_DATA*)image->data)->format); 2535 2539 2536 - result = SDL_CreateRGBSurface(SDL_SWSURFACE, image->texture_w, image->texture_h, format->BitsPerPixel, format->Rmask, format->Gmask, format->Bmask, format->Amask); 2540 + result = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, format->BitsPerPixel, format->Rmask, format->Gmask, format->Bmask, format->Amask); 2537 2541 2538 2542 if(result == NULL) 2539 2543 { 2540 - GPU_PushErrorCode("GPU_CopySurfaceFromImage", GPU_ERROR_DATA_ERROR, "Failed to create new %dx%d surface", image->texture_w, image->texture_h); 2544 + GPU_PushErrorCode("GPU_CopySurfaceFromImage", GPU_ERROR_DATA_ERROR, "Failed to create new %dx%d surface", w, h); 2541 2545 SDL_free(data); 2542 2546 return NULL; 2543 2547 } ··· 2545 2549 // Copy row-by-row in case the pitch doesn't match 2546 2550 { 2547 2551 int i; 2548 - int source_pitch = image->texture_w*format->BytesPerPixel; 2549 - for(i = 0; i < image->texture_h; ++i) 2552 + int source_pitch = image->texture_w*format->BytesPerPixel; // Use the actual texture width to pull from the data 2553 + for(i = 0; i < h; ++i) 2550 2554 { 2551 2555 memcpy((Uint8*)result->pixels + i*result->pitch, data + source_pitch*i, source_pitch); 2552 2556 } ··· 2825 2829 } 2826 2830 2827 2831 return result; 2828 - } 2829 - 2830 - static Uint8 hasColorkey(SDL_Surface* surface) 2831 - { 2832 - #ifdef SDL_GPU_USE_SDL2 2833 - return (SDL_GetColorKey(surface, NULL) == 0); 2834 - #else 2835 - return (surface->flags & SDL_SRCCOLORKEY); 2836 - #endif 2837 2832 } 2838 2833 2839 2834 static void FreeFormat(SDL_PixelFormat* format) ··· 3533 3528 // See what the best image format is. 3534 3529 if(surface->format->Amask == 0) 3535 3530 { 3536 - if(hasColorkey(surface)) 3531 + if(has_colorkey(surface)) 3537 3532 format = GPU_FORMAT_RGBA; 3538 3533 else 3539 3534 format = GPU_FORMAT_RGB;
+1
src/renderer_OpenGL_1_BASE.c
··· 13 13 // Most of the code pulled in from here... 14 14 #define SDL_GPU_USE_OPENGL 15 15 #define SDL_GPU_DISABLE_SHADERS 16 + #define SDL_GPU_DISABLE_RENDER_TO_TEXTURE 16 17 #define SDL_GPU_USE_FIXED_FUNCTION_PIPELINE 17 18 #define SDL_GPU_GL_TIER 1 18 19 #define SDL_GPU_GL_MAJOR_VERSION 1
+1 -1
tests/save/main.c
··· 3 3 #include <math.h> 4 4 #include "common.h" 5 5 6 - #define IMAGE_FILE "data/test.bmp" 6 + #define IMAGE_FILE "data/happy_52x63.bmp" 7 7 #define SAVE_FILE "save.bmp" 8 8 9 9