this repo has no description
0
fork

Configure Feed

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

Factored out more version-specific SDL code to clean up several renderer functions.

+142 -137
+142 -137
src/renderer_GL_common.inl
··· 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 183 + 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 + 99 205 100 206 101 207 #ifndef GL_VERTEX_SHADER ··· 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 + 1081 1179 static void update_stored_dimensions(GPU_Target* target) 1082 1180 { 1083 1181 Uint8 is_fullscreen; 1182 + SDL_Window* window; 1084 1183 1085 1184 if(target->context == NULL) 1086 1185 return; 1087 1186 1088 - #ifdef SDL_GPU_USE_SDL2 1089 - { 1090 - SDL_Window* window = SDL_GetWindowFromID(target->context->windowID); 1091 - SDL_GetWindowSize(window, &target->context->window_w, &target->context->window_h); 1092 - is_fullscreen = (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN); 1093 - } 1094 - #else 1095 - { 1096 - SDL_Surface* screen = SDL_GetVideoSurface(); 1097 - target->context->window_w = screen->w; 1098 - target->context->window_h = screen->h; 1099 - is_fullscreen = (screen->flags & SDL_FULLSCREEN); 1100 - } 1101 - #endif 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); 1102 1190 1103 1191 if(!is_fullscreen) 1104 1192 { ··· 1111 1199 { 1112 1200 Uint8 created = 0; // Make a new one or repurpose an existing target? 1113 1201 GPU_CONTEXT_DATA* cdata; 1114 - #ifdef SDL_GPU_USE_SDL2 1115 1202 SDL_Window* window; 1116 - #else 1117 - SDL_Surface* screen; 1118 - #endif 1203 + 1119 1204 int framebuffer_handle; 1120 1205 SDL_Color white = { 255, 255, 255, 255 }; 1121 1206 #ifdef SDL_GPU_USE_OPENGL ··· 1162 1247 cdata = (GPU_CONTEXT_DATA*)target->context->data; 1163 1248 } 1164 1249 1165 - #ifdef SDL_GPU_USE_SDL2 1166 1250 1167 - window = SDL_GetWindowFromID(windowID); 1251 + window = get_window(windowID); 1168 1252 if(window == NULL) 1169 1253 { 1170 1254 GPU_PushErrorCode("GPU_CreateTargetFromWindow", GPU_ERROR_BACKEND_ERROR, "Failed to acquire the window from the given ID."); ··· 1181 1265 } 1182 1266 1183 1267 // Store the window info 1184 - target->context->windowID = SDL_GetWindowID(window); 1268 + target->context->windowID = get_window_id(window); 1185 1269 1270 + #ifdef SDL_GPU_USE_SDL2 1186 1271 // Make a new context if needed and make it current 1187 1272 if(created || target->context->context == NULL) 1188 1273 { ··· 1195 1280 1196 1281 #else 1197 1282 1198 - screen = SDL_GetVideoSurface(); 1199 - if(screen == NULL) 1200 - { 1201 - GPU_PushErrorCode("GPU_CreateTargetFromWindow", GPU_ERROR_BACKEND_ERROR, "Failed to acquire the video surface."); 1202 - if(created) 1203 - { 1204 - SDL_free(cdata->blit_buffer); 1205 - SDL_free(cdata->index_buffer); 1206 - SDL_free(target->context->data); 1207 - SDL_free(target->context); 1208 - SDL_free(target->data); 1209 - SDL_free(target); 1210 - } 1211 - return NULL; 1212 - } 1213 - 1214 - target->context->windowID = 1; 1215 - target->context->drawable_w = screen->w; 1216 - target->context->drawable_h = screen->h; 1283 + target->context->drawable_w = window->w; 1284 + target->context->drawable_h = window->h; 1217 1285 1218 1286 #endif 1219 1287 ··· 1512 1580 1513 1581 static void MakeCurrent(GPU_Renderer* renderer, GPU_Target* target, Uint32 windowID) 1514 1582 { 1515 - #ifdef SDL_GPU_USE_SDL2 1516 - SDL_GLContext c; 1517 - #else 1518 - SDL_Surface* screen; 1519 - #endif 1583 + SDL_Window* window; 1520 1584 1521 1585 if(target == NULL) 1522 1586 return; 1523 - #ifdef SDL_GPU_USE_SDL2 1587 + 1524 1588 if(target->image != NULL) 1525 1589 return; 1590 + 1526 1591 1527 - c = target->context->context; 1528 - if(c != NULL) 1592 + if(target->context->context != NULL) 1529 1593 { 1530 1594 renderer->current_context_target = target; 1531 - SDL_GL_MakeCurrent(SDL_GetWindowFromID(windowID), c); 1532 - // 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 1533 1600 if(target->context->windowID != windowID) 1534 1601 { 1535 - SDL_Window* window; 1536 - 1537 1602 renderer->impl->FlushBlitBuffer(renderer); 1538 1603 1539 1604 // Update the window mappings ··· 1543 1608 GPU_AddWindowMapping(target); 1544 1609 1545 1610 // Update target's window size 1546 - window = SDL_GetWindowFromID(windowID); 1611 + window = get_window(windowID); 1547 1612 if(window != NULL) 1548 1613 { 1549 - SDL_GetWindowSize(window, &target->context->window_w, &target->context->window_h); 1550 - 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); 1551 1616 target->base_w = target->context->drawable_w; 1552 1617 target->base_h = target->context->drawable_h; 1553 1618 } ··· 1556 1621 applyTargetCamera(((GPU_CONTEXT_DATA*)renderer->current_context_target->context->data)->last_target); 1557 1622 } 1558 1623 } 1559 - #else 1560 - renderer->current_context_target = target; 1561 - // Only one window... 1562 - GPU_RemoveWindowMapping(1); 1563 - target->context->windowID = 1; 1564 - GPU_AddWindowMapping(target); 1565 - 1566 - // Update target's window size 1567 - screen = SDL_GetVideoSurface(); 1568 - if(screen != NULL) 1569 - { 1570 - target->context->window_w = target->context->drawable_w = screen->w; 1571 - target->context->window_h = target->context->drawable_h = screen->h; 1572 - target->base_w = target->context->drawable_w; 1573 - target->base_h = target->context->drawable_h; 1574 - } 1575 - #endif 1576 1624 } 1577 1625 1578 1626 ··· 1634 1682 extBindFramebuffer(renderer, ((GPU_TARGET_DATA*)target->data)->handle); 1635 1683 } 1636 1684 1637 - static void get_window_dimensions(GPU_Target* target, int* w, int* h) 1638 - { 1639 - #ifdef SDL_GPU_USE_SDL2 1640 - SDL_GetWindowSize(SDL_GetWindowFromID(target->context->windowID), w, h); 1641 - #else 1642 - SDL_Surface* screen = SDL_GetVideoSurface(); 1643 - *w = screen->w; 1644 - *h = screen->h; 1645 - #endif 1646 - } 1647 - 1648 - static void get_drawable_dimensions(GPU_Target* target, int* w, int* h) 1649 - { 1650 - #ifdef SDL_GPU_USE_SDL2 1651 - SDL_GL_GetDrawableSize(SDL_GetWindowFromID(target->context->windowID), w, h); 1652 - #else 1653 - get_window_dimensions(target, w, h); 1654 - #endif 1655 - } 1656 - 1657 - static void resize_window(GPU_Target* target, int w, int h) 1658 - { 1659 - #ifdef SDL_GPU_USE_SDL2 1660 - SDL_SetWindowSize(SDL_GetWindowFromID(target->context->windowID), w, h); 1661 - #else 1662 - SDL_Surface* screen = SDL_GetVideoSurface(); 1663 - Uint32 flags = screen->flags; 1664 - 1665 - screen = SDL_SetVideoMode(w, h, 0, flags); 1666 - // NOTE: There's a bug in SDL 1.2. This is a workaround. Let's resize again: 1667 - screen = SDL_SetVideoMode(w, h, 0, flags); 1668 - #endif 1669 - } 1670 - 1671 1685 static Uint8 SetWindowResolution(GPU_Renderer* renderer, Uint16 w, Uint16 h) 1672 1686 { 1673 1687 GPU_Target* target = renderer->current_context_target; ··· 1677 1691 renderer->impl->FlushBlitBuffer(renderer); 1678 1692 1679 1693 // Don't need to resize (only update internals) when resolution isn't changing. 1680 - get_window_dimensions(target, &target->context->window_w, &target->context->window_h); 1681 - get_drawable_dimensions(target, &target->context->drawable_w, &target->context->drawable_h); 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); 1682 1696 if(target->context->window_w != w || target->context->window_h != h) 1683 1697 { 1684 1698 resize_window(target, w, h); 1685 - get_window_dimensions(target, &target->context->window_w, &target->context->window_h); 1686 - get_drawable_dimensions(target, &target->context->drawable_w, &target->context->drawable_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); 1687 1701 } 1688 1702 1689 1703 #ifdef SDL_GPU_USE_SDL1 ··· 1829 1843 if(is_fullscreen != was_fullscreen) 1830 1844 { 1831 1845 // Update window dims 1832 - get_window_dimensions(target, &target->context->window_w, &target->context->window_h); 1833 - get_drawable_dimensions(target, &target->context->drawable_w, &target->context->drawable_h); 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); 1834 1848 1835 1849 // If virtual res is not set, we need to update the target dims and reset stuff that no longer is right 1836 1850 if(!target->using_virtual_resolution) ··· 2817 2831 return result; 2818 2832 } 2819 2833 2820 - static Uint8 hasColorkey(SDL_Surface* surface) 2821 - { 2822 - #ifdef SDL_GPU_USE_SDL2 2823 - return (SDL_GetColorKey(surface, NULL) == 0); 2824 - #else 2825 - return (surface->flags & SDL_SRCCOLORKEY); 2826 - #endif 2827 - } 2828 - 2829 2834 static void FreeFormat(SDL_PixelFormat* format) 2830 2835 { 2831 2836 SDL_free(format); ··· 3523 3528 // See what the best image format is. 3524 3529 if(surface->format->Amask == 0) 3525 3530 { 3526 - if(hasColorkey(surface)) 3531 + if(has_colorkey(surface)) 3527 3532 format = GPU_FORMAT_RGBA; 3528 3533 else 3529 3534 format = GPU_FORMAT_RGB;