this repo has no description
0
fork

Configure Feed

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

Added GPU_IsFeatureEnabled(). Added corresponding feature-demo. Updated get-pixel-demo and shapes-demo for SDL2 compatibility.

+142 -37
+54 -32
SDL_gpu/OpenGL_common/SDL_gpu_OpenGL.c
··· 28 28 return 1; 29 29 } 30 30 31 - static Uint8 NPOT_enabled = 0; 32 - static Uint8 FBO_enabled = 0; 33 - static Uint8 BLENDEQ_enabled = 0; 34 - static Uint8 BLENDFUNCSEP_enabled = 0; 31 + static GPU_FeatureEnum enabled_features = 0xFFFFFF; //GPU_FEATURE_ALL; 35 32 36 33 static void initNPOT(void) 37 34 { 38 35 #ifdef SDL_GPU_USE_OPENGL 39 - NPOT_enabled = glewIsExtensionSupported("GL_ARB_texture_non_power_of_two"); 36 + if(glewIsExtensionSupported("GL_ARB_texture_non_power_of_two")) 37 + enabled_features |= GPU_FEATURE_NON_POWER_OF_TWO; 38 + else 39 + enabled_features &= ~GPU_FEATURE_NON_POWER_OF_TWO; 40 40 #elif defined(SDL_GPU_USE_OPENGLES) 41 - NPOT_enabled = isExtensionSupported("GL_OES_texture_npot"); 41 + if(isExtensionSupported("GL_OES_texture_npot")) 42 + enabled_features |= GPU_FEATURE_NON_POWER_OF_TWO; 43 + else 44 + enabled_features &= ~GPU_FEATURE_NON_POWER_OF_TWO; 42 45 #endif 43 46 } 44 47 45 48 static void initFBO(void) 46 49 { 47 50 #ifdef SDL_GPU_USE_OPENGL 48 - FBO_enabled = glewIsExtensionSupported("GL_EXT_framebuffer_object"); 51 + if(glewIsExtensionSupported("GL_EXT_framebuffer_object")) 52 + enabled_features |= GPU_FEATURE_RENDER_TARGETS; 53 + else 54 + enabled_features &= ~GPU_FEATURE_RENDER_TARGETS; 49 55 #elif defined(SDL_GPU_USE_OPENGLES) 50 - FBO_enabled = isExtensionSupported("GL_OES_framebuffer_object"); 56 + if(isExtensionSupported("GL_OES_framebuffer_object")) 57 + enabled_features |= GPU_FEATURE_RENDER_TARGETS; 58 + else 59 + enabled_features &= ~GPU_FEATURE_RENDER_TARGETS; 51 60 #endif 52 61 } 53 62 54 63 static void initBLEND(void) 55 64 { 56 65 #ifdef SDL_GPU_USE_OPENGL 57 - BLENDEQ_enabled = 1; 58 - BLENDFUNCSEP_enabled = 1; 66 + enabled_features |= GPU_FEATURE_BLEND_EQUATIONS; 67 + enabled_features |= GPU_FEATURE_BLEND_FUNC_SEPARATE; 59 68 #elif defined(SDL_GPU_USE_OPENGLES) 60 - BLENDEQ_enabled = isExtensionSupported("GL_OES_blend_subtract"); 61 - BLENDFUNCSEP_enabled = isExtensionSupported("GL_OES_blend_func_separate"); 69 + if(isExtensionSupported("GL_OES_blend_subtract")) 70 + enabled_features |= GPU_FEATURE_BLEND_EQUATIONS; 71 + else 72 + enabled_features &= ~GPU_FEATURE_BLEND_EQUATIONS; 73 + if(isExtensionSupported("GL_OES_blend_func_separate")) 74 + enabled_features |= GPU_FEATURE_BLEND_FUNC_SEPARATE; 75 + else 76 + enabled_features &= ~GPU_FEATURE_BLEND_FUNC_SEPARATE; 62 77 #endif 63 78 } 64 79 65 80 void extBindFramebuffer(GLuint handle) 66 81 { 67 - if(FBO_enabled) 82 + if(enabled_features & GPU_FEATURE_RENDER_TARGETS) 68 83 glBindFramebuffer(GL_FRAMEBUFFER, handle); 69 84 } 70 85 ··· 109 124 // Returns false if it can't be bound 110 125 Uint8 bindFramebuffer(GPU_Renderer* renderer, GPU_Target* target) 111 126 { 112 - if(FBO_enabled) 127 + if(enabled_features & GPU_FEATURE_RENDER_TARGETS) 113 128 { 114 129 // Bind the FBO 115 130 if(target != ((RendererData_OpenGL*)renderer->data)->last_target) ··· 173 188 } 174 189 } 175 190 176 - 177 191 static GPU_Target* Init(GPU_Renderer* renderer, Uint16 w, Uint16 h, Uint32 flags) 178 192 { 179 193 #ifdef SDL_GPU_USE_SDL2 ··· 302 316 } 303 317 304 318 319 + static Uint8 IsFeatureEnabled(GPU_Renderer* renderer, GPU_FeatureEnum feature) 320 + { 321 + return ((enabled_features & feature) == feature); 322 + } 323 + 324 + 305 325 static void SetAsCurrent(GPU_Renderer* renderer) 306 326 { 307 327 #ifdef SDL_GPU_USE_SDL2 ··· 546 566 GLenum internal_format = ((ImageData_OpenGL*)(result->data))->format; 547 567 w = result->w; 548 568 h = result->h; 549 - if(!NPOT_enabled) 569 + if(!(enabled_features & GPU_FEATURE_NON_POWER_OF_TWO)) 550 570 { 551 571 if(!isPowerOfTwo(w)) 552 572 w = getNearestPowerOf2(w); ··· 783 803 } 784 804 } 785 805 806 + 786 807 // From SDL_AllocFormat() 787 808 static SDL_PixelFormat* AllocFormat(GLenum glFormat) 788 809 { ··· 981 1002 Uint8 need_power_of_two_upload = 0; 982 1003 unsigned int w = newSurface->w; 983 1004 unsigned int h = newSurface->h; 984 - if(!NPOT_enabled) 1005 + if(!(enabled_features & GPU_FEATURE_NON_POWER_OF_TWO)) 985 1006 { 986 1007 if(!isPowerOfTwo(w)) 987 1008 { ··· 1184 1205 if(image->target != NULL) 1185 1206 return image->target; 1186 1207 1187 - if(!FBO_enabled) 1208 + if(!(enabled_features & GPU_FEATURE_RENDER_TARGETS)) 1188 1209 return NULL; 1189 1210 1190 1211 GLuint handle; ··· 1226 1247 if(target == NULL || target == renderer->display) 1227 1248 return; 1228 1249 1229 - if(FBO_enabled) 1250 + if(enabled_features & GPU_FEATURE_RENDER_TARGETS) 1230 1251 { 1231 1252 flushAndClearBlitBufferIfCurrentFramebuffer(renderer, target); 1232 1253 glDeleteFramebuffers(1, &((TargetData_OpenGL*)target->data)->handle); ··· 2079 2100 if(mode == GPU_BLEND_NORMAL) 2080 2101 { 2081 2102 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2082 - if(!BLENDEQ_enabled) 2103 + if(!(enabled_features & GPU_FEATURE_BLEND_EQUATIONS)) 2083 2104 return; // TODO: Return false so we can avoid depending on it if it fails 2084 2105 glBlendEquation(GL_FUNC_ADD); 2085 2106 } 2086 2107 else if(mode == GPU_BLEND_MULTIPLY) 2087 2108 { 2088 - if(!BLENDFUNCSEP_enabled) 2109 + if(!(enabled_features & GPU_FEATURE_BLEND_FUNC_SEPARATE)) 2089 2110 return; 2090 2111 glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2091 - if(!BLENDEQ_enabled) 2112 + if(!(enabled_features & GPU_FEATURE_BLEND_EQUATIONS)) 2092 2113 return; 2093 2114 glBlendEquation(GL_FUNC_ADD); 2094 2115 } 2095 2116 else if(mode == GPU_BLEND_ADD) 2096 2117 { 2097 2118 glBlendFunc(GL_ONE, GL_ONE); 2098 - if(!BLENDEQ_enabled) 2119 + if(!(enabled_features & GPU_FEATURE_BLEND_EQUATIONS)) 2099 2120 return; 2100 2121 glBlendEquation(GL_FUNC_ADD); 2101 2122 } 2102 2123 else if(mode == GPU_BLEND_SUBTRACT) 2103 2124 { 2104 - if(!BLENDEQ_enabled) 2125 + if(!(enabled_features & GPU_FEATURE_BLEND_EQUATIONS)) 2105 2126 return; 2106 2127 glBlendFunc(GL_ONE, GL_ONE); 2107 2128 glBlendEquation(GL_FUNC_SUBTRACT); 2108 2129 } 2109 2130 else if(mode == GPU_BLEND_ADD_COLOR) 2110 2131 { 2111 - if(!BLENDFUNCSEP_enabled) 2132 + if(!(enabled_features & GPU_FEATURE_BLEND_FUNC_SEPARATE)) 2112 2133 return; 2113 2134 glBlendFuncSeparate(GL_ONE, GL_ONE, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2114 - if(!BLENDEQ_enabled) 2135 + if(!(enabled_features & GPU_FEATURE_BLEND_EQUATIONS)) 2115 2136 return; 2116 2137 glBlendEquation(GL_FUNC_ADD); 2117 2138 } 2118 2139 else if(mode == GPU_BLEND_SUBTRACT_COLOR) 2119 2140 { 2120 - if(!BLENDFUNCSEP_enabled) 2141 + if(!(enabled_features & GPU_FEATURE_BLEND_FUNC_SEPARATE)) 2121 2142 return; 2122 - if(!BLENDEQ_enabled) 2143 + if(!(enabled_features & GPU_FEATURE_BLEND_EQUATIONS)) 2123 2144 return; 2124 2145 glBlendFuncSeparate(GL_ONE, GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA); 2125 2146 glBlendEquation(GL_FUNC_SUBTRACT); 2126 2147 } 2127 2148 else if(mode == GPU_BLEND_DIFFERENCE) 2128 2149 { 2129 - if(!BLENDFUNCSEP_enabled) 2150 + if(!(enabled_features & GPU_FEATURE_BLEND_FUNC_SEPARATE)) 2130 2151 return; 2131 - if(!BLENDEQ_enabled) 2152 + if(!(enabled_features & GPU_FEATURE_BLEND_EQUATIONS)) 2132 2153 return; 2133 2154 glBlendFuncSeparate(GL_ONE, GL_ONE, GL_ONE, GL_ZERO); 2134 2155 glBlendEquation(GL_FUNC_SUBTRACT); 2135 2156 } 2136 2157 else if(mode == GPU_BLEND_PUNCHOUT) 2137 2158 { 2138 - if(!BLENDEQ_enabled) 2159 + if(!(enabled_features & GPU_FEATURE_BLEND_EQUATIONS)) 2139 2160 return; 2140 2161 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2141 2162 glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); 2142 2163 } 2143 2164 else if(mode == GPU_BLEND_CUTOUT) 2144 2165 { 2145 - if(!BLENDEQ_enabled) 2166 + if(!(enabled_features & GPU_FEATURE_BLEND_EQUATIONS)) 2146 2167 return; 2147 2168 glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA); 2148 2169 glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); ··· 2393 2414 memset(renderer->data, 0, sizeof(RendererData_OpenGL)); 2394 2415 2395 2416 renderer->Init = &Init; 2417 + renderer->IsFeatureEnabled = &IsFeatureEnabled; 2396 2418 renderer->SetAsCurrent = &SetAsCurrent; 2397 2419 renderer->SetDisplayResolution = &SetDisplayResolution; 2398 2420 renderer->SetVirtualResolution = &SetVirtualResolution;
+8
SDL_gpu/SDL_gpu.c
··· 120 120 return renderer->Init(renderer, w, h, flags); 121 121 } 122 122 123 + Uint8 GPU_IsFeatureEnabled(GPU_FeatureEnum feature) 124 + { 125 + if(current_renderer == NULL || current_renderer->IsFeatureEnabled == NULL) 126 + return 0; 127 + 128 + return current_renderer->IsFeatureEnabled(current_renderer, feature); 129 + } 130 + 123 131 int GPU_ToggleFullscreen(void) 124 132 { 125 133 if(current_renderer == NULL || current_renderer->ToggleFullscreen == NULL)
+19
SDL_gpu/SDL_gpu.h
··· 56 56 SDL_Rect clipRect; 57 57 }; 58 58 59 + /*! Important GPU features which may not be supported depending on a device's extension support. Can be OR'd together. 60 + * \see GPU_IsFeatureEnabled() 61 + */ 62 + typedef unsigned int GPU_FeatureEnum; 63 + static const GPU_FeatureEnum GPU_FEATURE_NON_POWER_OF_TWO = 0x1; 64 + static const GPU_FeatureEnum GPU_FEATURE_RENDER_TARGETS = 0x2; 65 + static const GPU_FeatureEnum GPU_FEATURE_BLEND_EQUATIONS = 0x4; 66 + static const GPU_FeatureEnum GPU_FEATURE_BLEND_FUNC_SEPARATE = 0x8; 67 + static const GPU_FeatureEnum GPU_FEATURE_ALL = 0xFFFFFF; 68 + 59 69 /*! Texture filtering options. These affect the quality/interpolation of colors when images are scaled. 60 70 * \see GPU_SetImageFilter() 61 71 */ ··· 112 122 113 123 /*! \see GPU_Init() */ 114 124 GPU_Target* (*Init)(GPU_Renderer* renderer, Uint16 w, Uint16 h, Uint32 flags); 125 + 126 + /*! \see GPU_IsFeatureEnabled() */ 127 + Uint8 (*IsFeatureEnabled)(GPU_Renderer* renderer, GPU_FeatureEnum feature); 115 128 116 129 /*! Sets up this renderer to act as the current renderer. Called automatically by GPU_SetCurrentRenderer(). */ 117 130 void (*SetAsCurrent)(GPU_Renderer* renderer); ··· 258 271 // Setup calls 259 272 /*! Initializes SDL and SDL_gpu. Creates a window and renderer context. */ 260 273 GPU_Target* GPU_Init(const char* renderer_id, Uint16 w, Uint16 h, Uint32 flags); 274 + 275 + /*! Checks for important GPU features which may not be supported depending on a device's extension support. Feature flags (GPU_FEATURE_*) can be bitwise OR'd together. 276 + * \return 1 is all of the passed features are enabled/supported 277 + * \return 0 if any of the passed features are disabled/unsupported 278 + */ 279 + Uint8 GPU_IsFeatureEnabled(GPU_FeatureEnum feature); 261 280 262 281 /*! Get the actual resolution of the window. */ 263 282 void GPU_GetDisplayResolution(int* w, int* h);
+4 -1
demos/CMakeLists.txt
··· 63 63 target_link_libraries (npot-demo SDL_gpu) 64 64 65 65 add_executable(subsurface-demo subsurface/main.c) 66 - target_link_libraries (subsurface-demo SDL_gpu) 66 + target_link_libraries (subsurface-demo SDL_gpu) 67 + 68 + add_executable(features-demo features/main.c) 69 + target_link_libraries (features-demo SDL_gpu)
+6
demos/common/compat.h
··· 37 37 #endif 38 38 39 39 40 + #ifdef SDL_GPU_USE_SDL2 41 + #define GET_ALPHA(sdl_color) (sdl_color.a) 42 + #else 43 + #define GET_ALPHA(sdl_color) (sdl_color.unused) 44 + #endif 45 + 40 46 #endif
+45
demos/features/main.c
··· 1 + #include "SDL.h" 2 + #include "SDL_gpu.h" 3 + #include <math.h> 4 + 5 + void printRenderers(void) 6 + { 7 + const char* renderers[GPU_GetNumRegisteredRenderers()]; 8 + GPU_GetRegisteredRendererList(renderers); 9 + 10 + printf("Available renderers:\n"); 11 + int i; 12 + for(i = 0; i < GPU_GetNumRegisteredRenderers(); i++) 13 + { 14 + printf("%d) %s\n", i+1, renderers[i]); 15 + } 16 + } 17 + 18 + static inline const char* bool_string(Uint8 value) 19 + { 20 + return (value? "true" : "false"); 21 + } 22 + 23 + int main(int argc, char* argv[]) 24 + { 25 + printRenderers(); 26 + 27 + GPU_Target* screen = GPU_Init(NULL, 800, 600, 0); 28 + if(screen == NULL) 29 + return -1; 30 + 31 + GPU_LogError("Using renderer: %s\n", GPU_GetCurrentRendererID()); 32 + 33 + GPU_LogError("Supports GPU_FEATURE_ALL: %s\n", bool_string(GPU_IsFeatureEnabled(GPU_FEATURE_ALL))); 34 + 35 + GPU_LogError("Supports GPU_FEATURE_NON_POWER_OF_TWO: %s\n", bool_string(GPU_IsFeatureEnabled(GPU_FEATURE_NON_POWER_OF_TWO))); 36 + GPU_LogError("Supports GPU_FEATURE_RENDER_TARGETS: %s\n", bool_string(GPU_IsFeatureEnabled(GPU_FEATURE_RENDER_TARGETS))); 37 + GPU_LogError("Supports GPU_FEATURE_BLEND_EQUATIONS: %s\n", bool_string(GPU_IsFeatureEnabled(GPU_FEATURE_BLEND_EQUATIONS))); 38 + GPU_LogError("Supports GPU_FEATURE_BLEND_FUNC_SEPARATE: %s\n", bool_string(GPU_IsFeatureEnabled(GPU_FEATURE_BLEND_FUNC_SEPARATE))); 39 + 40 + GPU_Quit(); 41 + 42 + return 0; 43 + } 44 + 45 +
+3 -2
demos/get-pixel/main.c
··· 1 1 #include "SDL.h" 2 2 #include "SDL_gpu.h" 3 - #include <math.h> 3 + #include <math.h> 4 + #include "../common/compat.h" 4 5 5 6 void printRenderers(void) 6 7 { ··· 53 54 SDL_GetMouseState(&mx, &my); 54 55 SDL_Color c = GPU_GetPixel(target, mx - 50, my - 50); 55 56 56 - GPU_ClearRGBA(screen, c.r, c.g, c.b, c.unused); 57 + GPU_ClearRGBA(screen, c.r, c.g, c.b, GET_ALPHA(c)); 57 58 58 59 GPU_Blit(image, NULL, screen, image->w/2 + 50, image->h/2 + 50); 59 60
+3 -2
demos/shapes/main.c
··· 1 1 #include "SDL.h" 2 2 #include "SDL_gpu.h" 3 - #include <math.h> 3 + #include <math.h> 4 + #include "../common/compat.h" 4 5 5 6 void printRenderers(void) 6 7 { ··· 41 42 colors[i].r = rand()%256; 42 43 colors[i].g = rand()%256; 43 44 colors[i].b = rand()%256; 44 - colors[i].unused = rand()%256; 45 + GET_ALPHA(colors[i]) = rand()%256; 45 46 } 46 47 47 48