this repo has no description
0
fork

Configure Feed

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

Merging patch for texture upload fallback for GLES 2. Thanks Vitaly!

+105 -59
+2
include/SDL_gpu.h
··· 465 465 static const GPU_InitFlagEnum GPU_INIT_DISABLE_DOUBLE_BUFFER = 0x4; 466 466 static const GPU_InitFlagEnum GPU_INIT_DISABLE_AUTO_VIRTUAL_RESOLUTION = 0x8; 467 467 static const GPU_InitFlagEnum GPU_INIT_REQUEST_COMPATIBILITY_PROFILE = 0x10; 468 + static const GPU_InitFlagEnum GPU_INIT_USE_ROW_BY_ROW_TEXTURE_UPLOAD_FALLBACK = 0x20; 469 + static const GPU_InitFlagEnum GPU_INIT_USE_COPY_TEXTURE_UPLOAD_FALLBACK = 0x40; 468 470 469 471 #define GPU_DEFAULT_INIT_FLAGS 0 470 472
+103 -59
src/renderer_GL_common.inl
··· 263 263 #endif 264 264 } 265 265 266 + static_inline void fast_upload_texture(const void* pixels, GPU_Rect update_rect, Uint32 format, int alignment, int row_length) 267 + { 268 + glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); 269 + #if defined(SDL_GPU_USE_OPENGL) || SDL_GPU_GLES_MAJOR_VERSION > 2 270 + glPixelStorei(GL_UNPACK_ROW_LENGTH, row_length); 271 + #endif 272 + 273 + glTexSubImage2D(GL_TEXTURE_2D, 0, 274 + update_rect.x, update_rect.y, update_rect.w, update_rect.h, 275 + format, GL_UNSIGNED_BYTE, pixels); 276 + 277 + #if defined(SDL_GPU_USE_OPENGL) || SDL_GPU_GLES_MAJOR_VERSION > 2 278 + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); 279 + #endif 280 + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); 281 + } 282 + 283 + static void row_upload_texture(const unsigned char* pixels, GPU_Rect update_rect, Uint32 format, int alignment, unsigned int pitch, int bytes_per_pixel) 284 + { 285 + unsigned int i; 286 + unsigned int h = update_rect.h; 287 + glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); 288 + if(h > 0 && update_rect.w > 0.0f) 289 + { 290 + // Must upload row by row to account for row length 291 + for(i = 0; i < h; ++i) 292 + { 293 + glTexSubImage2D(GL_TEXTURE_2D, 0, 294 + update_rect.x, update_rect.y + i, update_rect.w, 1, 295 + format, GL_UNSIGNED_BYTE, pixels); 296 + pixels += pitch; 297 + } 298 + } 299 + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); 300 + } 301 + 302 + static void copy_upload_texture(const unsigned char* pixels, GPU_Rect update_rect, Uint32 format, int alignment, unsigned int pitch, int bytes_per_pixel) 303 + { 304 + unsigned int i; 305 + unsigned int h = update_rect.h; 306 + unsigned int w = update_rect.w*bytes_per_pixel; 307 + 308 + if(h > 0 && w > 0) 309 + { 310 + // Account for padding 311 + w += w % alignment; 312 + 313 + unsigned char *copy = (unsigned char*)SDL_malloc(update_rect.h*w); 314 + unsigned char *dst = copy; 315 + 316 + for(i = 0; i < h; ++i) 317 + { 318 + memcpy(dst, pixels, w); 319 + pixels += pitch; 320 + dst += w; 321 + } 322 + fast_upload_texture(copy, update_rect, format, alignment, update_rect.w); 323 + SDL_free(copy); 324 + } 325 + } 326 + 327 + static void (*slow_upload_texture)(const unsigned char* pixels, GPU_Rect update_rect, Uint32 format, int alignment, unsigned int pitch, int bytes_per_pixel) = NULL; 328 + 329 + static_inline void upload_texture(const void* pixels, GPU_Rect update_rect, Uint32 format, int alignment, int row_length, unsigned int pitch, int bytes_per_pixel) 330 + { 331 + #if defined(SDL_GPU_USE_OPENGL) || SDL_GPU_GLES_MAJOR_VERSION > 2 332 + fast_upload_texture(pixels, update_rect, format, alignment, row_length); 333 + #else 334 + if(row_length == update_rect.w) 335 + fast_upload_texture(pixels, update_rect, format, alignment, row_length); 336 + else 337 + slow_upload_texture(pixels, update_rect, format, alignment, pitch, bytes_per_pixel); 338 + 339 + #endif 340 + } 341 + 342 + static_inline void upload_new_texture(void* pixels, GPU_Rect update_rect, Uint32 format, int alignment, int row_length, int bytes_per_pixel) 343 + { 344 + #if defined(SDL_GPU_USE_OPENGL) || SDL_GPU_GLES_MAJOR_VERSION > 2 345 + glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); 346 + glPixelStorei(GL_UNPACK_ROW_LENGTH, row_length); 347 + glTexImage2D(GL_TEXTURE_2D, 0, format, update_rect.w, update_rect.h, 0, 348 + format, GL_UNSIGNED_BYTE, pixels); 349 + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); 350 + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); 351 + #else 352 + glTexImage2D(GL_TEXTURE_2D, 0, format, update_rect.w, update_rect.h, 0, 353 + format, GL_UNSIGNED_BYTE, NULL); 354 + upload_texture(pixels, update_rect, format, alignment, row_length, row_length*bytes_per_pixel, bytes_per_pixel); 355 + #endif 356 + } 357 + 358 + 266 359 static void init_features(GPU_Renderer* renderer) 267 360 { 268 361 // Reset supported features ··· 822 915 } 823 916 } 824 917 825 - static void upload_texture(const void* pixels, GPU_Rect update_rect, Uint32 format, int alignment, int row_length, unsigned int pitch) 826 - { 827 - glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); 828 - #if defined(SDL_GPU_USE_OPENGL) || SDL_GPU_GLES_MAJOR_VERSION > 2 829 - glPixelStorei(GL_UNPACK_ROW_LENGTH, row_length); 830 - 831 - glTexSubImage2D(GL_TEXTURE_2D, 0, 832 - update_rect.x, update_rect.y, update_rect.w, update_rect.h, 833 - format, GL_UNSIGNED_BYTE, pixels); 834 - 835 - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); 836 - #else 837 - unsigned int i; 838 - unsigned int h = update_rect.h; 839 - if(h > 0 && update_rect.w > 0.0f) 840 - { 841 - // Must upload row by row to account for row length 842 - 843 - for(i = 0; i < h; ++i) 844 - { 845 - glTexSubImage2D(GL_TEXTURE_2D, 0, 846 - update_rect.x, update_rect.y + i, update_rect.w, 1, 847 - format, GL_UNSIGNED_BYTE, pixels); 848 - pixels += pitch; 849 - } 850 - } 851 - #endif 852 - glPixelStorei(GL_UNPACK_ALIGNMENT, 4); 853 - } 854 - 855 - static void upload_new_texture(void* pixels, GPU_Rect update_rect, Uint32 format, int alignment, int row_length, int bytes_per_pixel) 856 - { 857 - glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); 858 - #if defined(SDL_GPU_USE_OPENGL) || SDL_GPU_GLES_MAJOR_VERSION > 2 859 - glPixelStorei(GL_UNPACK_ROW_LENGTH, row_length); 860 - 861 - glTexImage2D(GL_TEXTURE_2D, 0, format, update_rect.w, update_rect.h, 0, 862 - format, GL_UNSIGNED_BYTE, pixels); 863 - 864 - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); 865 - glPixelStorei(GL_UNPACK_ALIGNMENT, 4); 866 - #else 867 - glTexImage2D(GL_TEXTURE_2D, 0, format, update_rect.w, update_rect.h, 0, 868 - format, GL_UNSIGNED_BYTE, NULL); 869 - 870 - // Alignment is reset in upload_texture() 871 - upload_texture(pixels, update_rect, format, alignment, row_length, row_length*bytes_per_pixel); 872 - #endif 873 - } 874 - 875 918 #define MIX_COLOR_COMPONENT_NORMALIZED_RESULT(a, b) ((a)/255.0f * (b)/255.0f) 876 919 #define MIX_COLOR_COMPONENT(a, b) (((a)/255.0f * (b)/255.0f)*255) 877 920 ··· 1491 1534 else if(renderer->GPU_init_flags & GPU_INIT_DISABLE_VSYNC) 1492 1535 SDL_GL_SetSwapInterval(0); 1493 1536 #endif 1494 - 1537 + 1538 + // Set fallback texture upload method 1539 + if(renderer->GPU_init_flags & GPU_INIT_USE_COPY_TEXTURE_UPLOAD_FALLBACK) 1540 + slow_upload_texture = copy_upload_texture; 1541 + else 1542 + slow_upload_texture = row_upload_texture; 1543 + 1544 + 1495 1545 // Set up GL state 1496 1546 1497 1547 target->context->projection_matrix.size = 1; ··· 2949 2999 // Returns NULL on failure. Returns the original surface if no copy is needed. Returns a new surface converted to the right format otherwise. 2950 3000 static SDL_Surface* copySurfaceIfNeeded(GPU_Renderer* renderer, GLenum glFormat, SDL_Surface* surface, GLenum* surfaceFormatResult) 2951 3001 { 2952 - #ifdef SDL_GPU_USE_GLES 2953 - SDL_Surface* original = surface; 2954 - #endif 2955 - 2956 3002 // If format doesn't match, we need to do a copy 2957 3003 int format_compare = compareFormats(renderer, glFormat, surface, surfaceFormatResult); 2958 3004 ··· 3238 3284 // Shift the pixels pointer to the proper source position 3239 3285 pixels += (int)(newSurface->pitch * sourceRect.y + (newSurface->format->BytesPerPixel)*sourceRect.x); 3240 3286 3241 - upload_texture(pixels, updateRect, original_format, alignment, (newSurface->pitch / newSurface->format->BytesPerPixel), newSurface->pitch); 3242 - 3287 + upload_texture(pixels, updateRect, original_format, alignment, newSurface->pitch/newSurface->format->BytesPerPixel, newSurface->pitch, newSurface->format->BytesPerPixel); 3243 3288 3244 3289 // Delete temporary surface 3245 3290 if(surface != newSurface) ··· 3307 3352 while(bytes_per_row % alignment) 3308 3353 alignment >>= 1; 3309 3354 3310 - upload_texture(bytes, updateRect, original_format, alignment, (bytes_per_row / image->bytes_per_pixel), bytes_per_row); 3311 - 3355 + upload_texture(bytes, updateRect, original_format, alignment, bytes_per_row / image->bytes_per_pixel, bytes_per_row, image->bytes_per_pixel); 3312 3356 } 3313 3357 3314 3358