this repo has no description
0
fork

Configure Feed

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

Merge branch 'official' into Blurrr

* official:
Updated renderer-test for the previous change.
Changed renderer's shader_version to min_shader_version and max_shader_version for more flexibility when considering GPU capability.
Removed SDL_PREALLOC hack and stbi allocator override. Replaced them with a copy of the data instead to try to avoid crashes with Visual Studio. Lots of whitespace changes because I forgot to configure my editor first.

Eric Wing f3f86c9f e8e8c444

+1511 -1432
+5 -3
common/common.c
··· 42 42 43 43 void printCurrentRenderer(void) 44 44 { 45 - GPU_RendererID id = GPU_GetCurrentRenderer()->id; 45 + GPU_Renderer* renderer = GPU_GetCurrentRenderer(); 46 + GPU_RendererID id = renderer->id; 46 47 47 - GPU_Log("Using renderer: %s (%d.%d)\n\n", id.name, id.major_version, id.minor_version); 48 + GPU_Log("Using renderer: %s (%d.%d)\n", id.name, id.major_version, id.minor_version); 49 + GPU_Log(" Shader versions supported: %d to %d\n\n", renderer->min_shader_version, renderer->max_shader_version); 48 50 } 49 51 50 52 GPU_Target* initialize_demo(int argc, char** argv, Uint16 w, Uint16 h) ··· 125 127 // Get size from header 126 128 if(renderer->shader_language == GPU_LANGUAGE_GLSL) 127 129 { 128 - if(renderer->shader_version >= 120) 130 + if(renderer->max_shader_version >= 120) 129 131 header = "#version 120\n"; 130 132 else 131 133 header = "#version 110\n"; // Maybe this is good enough?
+9 -3
demos/CMakeLists.txt
··· 1 1 include_directories (${SDL_gpu_SOURCE_DIR}) 2 2 3 + set(DEMO_LIBS SDL_gpu) 4 + 5 + if(MINGW) 6 + set(DEMO_LIBS ${DEMO_LIBS} mingw32) 7 + endif(MINGW) 8 + 3 9 add_executable(init-demo init/main.c) 4 - target_link_libraries (init-demo SDL_gpu) 10 + target_link_libraries (init-demo ${DEMO_LIBS}) 5 11 6 12 add_executable(3d-demo 3d/main.c ../src/externals/glew/glew.c) 7 - target_link_libraries (3d-demo SDL_gpu) 13 + target_link_libraries (3d-demo ${DEMO_LIBS}) 8 14 9 15 add_executable(tutorial-space-demo tutorial-space/main.c) 10 - target_link_libraries (tutorial-space-demo SDL_gpu) 16 + target_link_libraries (tutorial-space-demo ${DEMO_LIBS})
+2 -1
include/SDL_gpu.h
··· 590 590 GPU_InitFlagEnum GPU_init_flags; 591 591 592 592 GPU_ShaderLanguageEnum shader_language; 593 - int shader_version; 593 + int min_shader_version; 594 + int max_shader_version; 594 595 GPU_FeatureEnum enabled_features; 595 596 596 597 /*! Current display target */
+827 -813
src/SDL_gpu.c
··· 80 80 81 81 void GPU_SetCurrentRenderer(GPU_RendererID id) 82 82 { 83 - _gpu_current_renderer = GPU_GetRenderer(id); 84 - 85 - if(_gpu_current_renderer != NULL) 86 - _gpu_current_renderer->impl->SetAsCurrent(_gpu_current_renderer); 83 + _gpu_current_renderer = GPU_GetRenderer(id); 84 + 85 + if(_gpu_current_renderer != NULL) 86 + _gpu_current_renderer->impl->SetAsCurrent(_gpu_current_renderer); 87 87 } 88 88 89 89 void GPU_ResetRendererState(void) 90 90 { 91 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 92 - return; 93 - 94 - _gpu_current_renderer->impl->ResetRendererState(_gpu_current_renderer); 91 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 92 + return; 93 + 94 + _gpu_current_renderer->impl->ResetRendererState(_gpu_current_renderer); 95 95 } 96 96 97 97 void GPU_SetCoordinateMode(Uint8 use_math_coords) 98 98 { 99 - if(_gpu_current_renderer == NULL) 100 - return; 101 - 102 - _gpu_current_renderer->coordinate_mode = use_math_coords; 99 + if(_gpu_current_renderer == NULL) 100 + return; 101 + 102 + _gpu_current_renderer->coordinate_mode = use_math_coords; 103 103 } 104 104 105 105 Uint8 GPU_GetCoordinateMode(void) 106 106 { 107 - if(_gpu_current_renderer == NULL) 108 - return 0; 109 - 110 - return _gpu_current_renderer->coordinate_mode; 107 + if(_gpu_current_renderer == NULL) 108 + return 0; 109 + 110 + return _gpu_current_renderer->coordinate_mode; 111 111 } 112 112 113 113 GPU_Renderer* GPU_GetCurrentRenderer(void) 114 114 { 115 - return _gpu_current_renderer; 115 + return _gpu_current_renderer; 116 116 } 117 117 118 118 Uint32 GPU_GetCurrentShaderProgram(void) ··· 128 128 { 129 129 switch(log_level) 130 130 { 131 - #ifdef __ANDROID__ 132 - case GPU_LOG_INFO: 133 - return __android_log_vprint((GPU_GetDebugLevel() >= GPU_DEBUG_LEVEL_3? ANDROID_LOG_ERROR : ANDROID_LOG_INFO), "APPLICATION", format, args); 134 - case GPU_LOG_WARNING: 135 - return __android_log_vprint((GPU_GetDebugLevel() >= GPU_DEBUG_LEVEL_2? ANDROID_LOG_ERROR : ANDROID_LOG_WARN), "APPLICATION", format, args); 136 - case GPU_LOG_ERROR: 137 - return __android_log_vprint(ANDROID_LOG_ERROR, "APPLICATION", format, args); 138 - #else 139 - case GPU_LOG_INFO: 140 - return vfprintf((GPU_GetDebugLevel() >= GPU_DEBUG_LEVEL_3? stderr : stdout), format, args); 141 - case GPU_LOG_WARNING: 142 - return vfprintf((GPU_GetDebugLevel() >= GPU_DEBUG_LEVEL_2? stderr : stdout), format, args); 143 - case GPU_LOG_ERROR: 144 - return vfprintf(stderr, format, args); 145 - #endif 131 + #ifdef __ANDROID__ 132 + case GPU_LOG_INFO: 133 + return __android_log_vprint((GPU_GetDebugLevel() >= GPU_DEBUG_LEVEL_3? ANDROID_LOG_ERROR : ANDROID_LOG_INFO), "APPLICATION", format, args); 134 + case GPU_LOG_WARNING: 135 + return __android_log_vprint((GPU_GetDebugLevel() >= GPU_DEBUG_LEVEL_2? ANDROID_LOG_ERROR : ANDROID_LOG_WARN), "APPLICATION", format, args); 136 + case GPU_LOG_ERROR: 137 + return __android_log_vprint(ANDROID_LOG_ERROR, "APPLICATION", format, args); 138 + #else 139 + case GPU_LOG_INFO: 140 + return vfprintf((GPU_GetDebugLevel() >= GPU_DEBUG_LEVEL_3? stderr : stdout), format, args); 141 + case GPU_LOG_WARNING: 142 + return vfprintf((GPU_GetDebugLevel() >= GPU_DEBUG_LEVEL_2? stderr : stdout), format, args); 143 + case GPU_LOG_ERROR: 144 + return vfprintf(stderr, format, args); 145 + #endif 146 146 default: 147 147 return 0; 148 148 } ··· 158 158 159 159 void GPU_LogInfo(const char* format, ...) 160 160 { 161 - va_list args; 162 - va_start(args, format); 161 + va_list args; 162 + va_start(args, format); 163 163 _gpu_print(GPU_LOG_INFO, format, args); 164 - va_end(args); 164 + va_end(args); 165 165 } 166 166 167 167 void GPU_LogWarning(const char* format, ...) 168 168 { 169 - va_list args; 170 - va_start(args, format); 169 + va_list args; 170 + va_start(args, format); 171 171 _gpu_print(GPU_LOG_WARNING, format, args); 172 - va_end(args); 172 + va_end(args); 173 173 } 174 174 175 175 void GPU_LogError(const char* format, ...) 176 176 { 177 - va_list args; 178 - va_start(args, format); 177 + va_list args; 178 + va_start(args, format); 179 179 _gpu_print(GPU_LOG_ERROR, format, args); 180 - va_end(args); 180 + va_end(args); 181 181 } 182 182 183 183 184 184 static Uint8 gpu_init_SDL(void) 185 185 { 186 - if(!_gpu_initialized_SDL) 187 - { 188 - if(!_gpu_initialized_SDL_core && !SDL_WasInit(SDL_INIT_EVERYTHING)) 186 + if(!_gpu_initialized_SDL) 187 + { 188 + if(!_gpu_initialized_SDL_core && !SDL_WasInit(SDL_INIT_EVERYTHING)) 189 189 { 190 190 // Nothing has been set up, so init SDL and the video subsystem. 191 191 if(SDL_Init(SDL_INIT_VIDEO) < 0) ··· 195 195 } 196 196 _gpu_initialized_SDL_core = 1; 197 197 } 198 - 198 + 199 199 // SDL is definitely ready now, but we're going to init the video subsystem to be sure that SDL_gpu keeps it available until GPU_Quit(). 200 200 if(SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) 201 201 { ··· 203 203 return 0; 204 204 } 205 205 _gpu_initialized_SDL = 1; 206 - } 207 - return 1; 206 + } 207 + return 1; 208 208 } 209 209 210 210 void GPU_SetInitWindow(Uint32 windowID) ··· 243 243 { 244 244 unsigned int i; 245 245 _gpu_error_code_queue = (GPU_ErrorObject*)SDL_malloc(sizeof(GPU_ErrorObject)*_gpu_error_code_queue_size); 246 - 246 + 247 247 for(i = 0; i < _gpu_error_code_queue_size; i++) 248 248 { 249 249 _gpu_error_code_queue[i].function = (char*)SDL_malloc(GPU_ERROR_FUNCTION_STRING_MAX+1); ··· 251 251 _gpu_error_code_queue[i].details = (char*)SDL_malloc(GPU_ERROR_DETAILS_STRING_MAX+1); 252 252 } 253 253 _gpu_num_error_codes = 0; 254 - 254 + 255 255 _gpu_error_code_result.function = (char*)SDL_malloc(GPU_ERROR_FUNCTION_STRING_MAX+1); 256 256 _gpu_error_code_result.error = GPU_ERROR_NONE; 257 257 _gpu_error_code_result.details = (char*)SDL_malloc(GPU_ERROR_DETAILS_STRING_MAX+1); ··· 270 270 271 271 void GPU_AddWindowMapping(GPU_Target* target) 272 272 { 273 - Uint32 windowID; 274 - int i; 273 + Uint32 windowID; 274 + int i; 275 275 276 - if(_gpu_window_mappings == NULL) 276 + if(_gpu_window_mappings == NULL) 277 277 gpu_init_window_mappings(); 278 - 278 + 279 279 if(target == NULL || target->context == NULL) 280 280 return; 281 - 281 + 282 282 windowID = target->context->windowID; 283 283 if(windowID == 0) // Invalid window ID 284 284 return; 285 - 285 + 286 286 // Check for duplicates 287 287 for(i = 0; i < _gpu_num_window_mappings; i++) 288 288 { ··· 294 294 } 295 295 // Don't check the target because it's okay for a single target to be used with multiple windows 296 296 } 297 - 297 + 298 298 // Check if list is big enough to hold another 299 299 if(_gpu_num_window_mappings >= _gpu_window_mappings_size) 300 300 { 301 - GPU_WindowMapping* new_array; 301 + GPU_WindowMapping* new_array; 302 302 _gpu_window_mappings_size *= 2; 303 303 new_array = (GPU_WindowMapping*)SDL_malloc(_gpu_window_mappings_size * sizeof(GPU_WindowMapping)); 304 304 memcpy(new_array, _gpu_window_mappings, _gpu_num_window_mappings * sizeof(GPU_WindowMapping)); 305 305 SDL_free(_gpu_window_mappings); 306 306 _gpu_window_mappings = new_array; 307 307 } 308 - 308 + 309 309 // Add to end of list 310 - { 311 - GPU_WindowMapping m; 312 - m.windowID = windowID; 313 - m.target = target; 314 - _gpu_window_mappings[_gpu_num_window_mappings] = m; 315 - } 310 + { 311 + GPU_WindowMapping m; 312 + m.windowID = windowID; 313 + m.target = target; 314 + _gpu_window_mappings[_gpu_num_window_mappings] = m; 315 + } 316 316 _gpu_num_window_mappings++; 317 317 } 318 318 319 319 void GPU_RemoveWindowMapping(Uint32 windowID) 320 320 { 321 - int i; 321 + int i; 322 322 323 323 if(_gpu_window_mappings == NULL) 324 324 gpu_init_window_mappings(); 325 - 325 + 326 326 if(windowID == 0) // Invalid window ID 327 327 return; 328 - 328 + 329 329 // Find the occurrence 330 330 for(i = 0; i < _gpu_num_window_mappings; i++) 331 331 { 332 332 if(_gpu_window_mappings[i].windowID == windowID) 333 333 { 334 - int num_to_move; 334 + int num_to_move; 335 335 336 336 // Unset the target's window 337 337 _gpu_window_mappings[i].target->context->windowID = 0; 338 - 338 + 339 339 // Move the remaining entries to replace the removed one 340 340 _gpu_num_window_mappings--; 341 341 num_to_move = _gpu_num_window_mappings - i; ··· 344 344 return; 345 345 } 346 346 } 347 - 347 + 348 348 } 349 349 350 350 void GPU_RemoveWindowMappingByTarget(GPU_Target* target) 351 351 { 352 - Uint32 windowID; 353 - int i; 352 + Uint32 windowID; 353 + int i; 354 354 355 355 if(_gpu_window_mappings == NULL) 356 356 gpu_init_window_mappings(); 357 - 357 + 358 358 if(target == NULL || target->context == NULL) 359 359 return; 360 - 360 + 361 361 windowID = target->context->windowID; 362 362 if(windowID == 0) // Invalid window ID 363 363 return; 364 - 364 + 365 365 // Unset the target's window 366 366 target->context->windowID = 0; 367 - 367 + 368 368 // Find the occurrences 369 369 for(i = 0; i < _gpu_num_window_mappings; ) 370 370 { 371 371 if(_gpu_window_mappings[i].target == target) 372 372 { 373 373 // Move the remaining entries to replace the removed one 374 - int num_to_move; 374 + int num_to_move; 375 375 _gpu_num_window_mappings--; 376 376 num_to_move = _gpu_num_window_mappings - i; 377 377 if(num_to_move > 0) ··· 381 381 else 382 382 i++; 383 383 } 384 - 384 + 385 385 } 386 386 387 387 GPU_Target* GPU_GetWindowTarget(Uint32 windowID) ··· 390 390 391 391 if(_gpu_window_mappings == NULL) 392 392 gpu_init_window_mappings(); 393 - 393 + 394 394 if(windowID == 0) // Invalid window ID 395 395 return NULL; 396 - 396 + 397 397 // Find the occurrence 398 398 for(i = 0; i < _gpu_num_window_mappings; i++) 399 399 { 400 400 if(_gpu_window_mappings[i].windowID == windowID) 401 401 return _gpu_window_mappings[i].target; 402 402 } 403 - 403 + 404 404 return NULL; 405 405 } 406 406 407 407 GPU_Target* GPU_Init(Uint16 w, Uint16 h, GPU_WindowFlagEnum SDL_flags) 408 408 { 409 - int renderer_order_size; 410 - int i; 409 + int renderer_order_size; 410 + int i; 411 411 GPU_RendererID renderer_order[GPU_RENDERER_ORDER_MAX]; 412 412 413 413 gpu_init_error_queue(); 414 - 415 - gpu_init_renderer_register(); 416 - 417 - if(!gpu_init_SDL()) 414 + 415 + gpu_init_renderer_register(); 416 + 417 + if(!gpu_init_SDL()) 418 418 return NULL; 419 - 419 + 420 420 renderer_order_size = 0; 421 421 GPU_GetRendererOrder(&renderer_order_size, renderer_order); 422 - 422 + 423 423 // Init the renderers in order 424 424 for(i = 0; i < renderer_order_size; i++) 425 425 { ··· 427 427 if(screen != NULL) 428 428 return screen; 429 429 } 430 - 430 + 431 431 GPU_PushErrorCode("GPU_Init", GPU_ERROR_BACKEND_ERROR, "No renderer out of %d was able to initialize properly", renderer_order_size); 432 432 return NULL; 433 433 } ··· 440 440 441 441 GPU_Target* GPU_InitRendererByID(GPU_RendererID renderer_request, Uint16 w, Uint16 h, GPU_WindowFlagEnum SDL_flags) 442 442 { 443 - GPU_Renderer* renderer; 444 - GPU_Target* screen; 443 + GPU_Renderer* renderer; 444 + GPU_Target* screen; 445 445 446 446 gpu_init_error_queue(); 447 - gpu_init_renderer_register(); 448 - 449 - if(!gpu_init_SDL()) 447 + gpu_init_renderer_register(); 448 + 449 + if(!gpu_init_SDL()) 450 + return NULL; 451 + 452 + renderer = gpu_create_and_add_renderer(renderer_request); 453 + if(renderer == NULL) 450 454 return NULL; 451 - 452 - renderer = gpu_create_and_add_renderer(renderer_request); 453 - if(renderer == NULL) 454 - return NULL; 455 - 456 - GPU_SetCurrentRenderer(renderer->id); 457 - 458 - screen = renderer->impl->Init(renderer, renderer_request, w, h, SDL_flags); 459 - if(screen == NULL) 455 + 456 + GPU_SetCurrentRenderer(renderer->id); 457 + 458 + screen = renderer->impl->Init(renderer, renderer_request, w, h, SDL_flags); 459 + if(screen == NULL) 460 460 { 461 461 GPU_PushErrorCode("GPU_InitRendererByID", GPU_ERROR_BACKEND_ERROR, "Renderer %s failed to initialize properly", renderer->id.name); 462 462 // Init failed, destroy the renderer... ··· 471 471 472 472 Uint8 GPU_IsFeatureEnabled(GPU_FeatureEnum feature) 473 473 { 474 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 475 - return 0; 476 - 477 - return ((_gpu_current_renderer->enabled_features & feature) == feature); 474 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 475 + return 0; 476 + 477 + return ((_gpu_current_renderer->enabled_features & feature) == feature); 478 478 } 479 479 480 480 GPU_Target* GPU_CreateTargetFromWindow(Uint32 windowID) 481 481 { 482 - if(_gpu_current_renderer == NULL) 483 - return NULL; 484 - 485 - return _gpu_current_renderer->impl->CreateTargetFromWindow(_gpu_current_renderer, windowID, NULL); 482 + if(_gpu_current_renderer == NULL) 483 + return NULL; 484 + 485 + return _gpu_current_renderer->impl->CreateTargetFromWindow(_gpu_current_renderer, windowID, NULL); 486 486 } 487 487 488 488 GPU_Target* GPU_CreateAliasTarget(GPU_Target* target) ··· 492 492 MAKE_CURRENT_IF_NONE(target); 493 493 if(!CHECK_CONTEXT) 494 494 return NULL; 495 - 496 - return _gpu_current_renderer->impl->CreateAliasTarget(_gpu_current_renderer, target); 495 + 496 + return _gpu_current_renderer->impl->CreateAliasTarget(_gpu_current_renderer, target); 497 497 } 498 498 499 499 void GPU_MakeCurrent(GPU_Target* target, Uint32 windowID) 500 500 { 501 - if(_gpu_current_renderer == NULL) 502 - return; 503 - 504 - _gpu_current_renderer->impl->MakeCurrent(_gpu_current_renderer, target, windowID); 501 + if(_gpu_current_renderer == NULL) 502 + return; 503 + 504 + _gpu_current_renderer->impl->MakeCurrent(_gpu_current_renderer, target, windowID); 505 505 } 506 506 507 507 Uint8 GPU_SetFullscreen(Uint8 enable_fullscreen, Uint8 use_desktop_resolution) 508 508 { 509 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 510 - return 0; 511 - 512 - return _gpu_current_renderer->impl->SetFullscreen(_gpu_current_renderer, enable_fullscreen, use_desktop_resolution); 509 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 510 + return 0; 511 + 512 + return _gpu_current_renderer->impl->SetFullscreen(_gpu_current_renderer, enable_fullscreen, use_desktop_resolution); 513 513 } 514 514 515 515 Uint8 GPU_GetFullscreen(void) ··· 519 519 if(target == NULL) 520 520 return 0; 521 521 return (Uint8)(SDL_GetWindowFlags(SDL_GetWindowFromID(target->context->windowID)) 522 - & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_FULLSCREEN_DESKTOP)); 522 + & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_FULLSCREEN_DESKTOP)); 523 523 #else 524 524 SDL_Surface* surf = SDL_GetVideoSurface(); 525 525 if(surf == NULL) ··· 530 530 531 531 Uint8 GPU_SetWindowResolution(Uint16 w, Uint16 h) 532 532 { 533 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL || w == 0 || h == 0) 534 - return 0; 535 - 536 - return _gpu_current_renderer->impl->SetWindowResolution(_gpu_current_renderer, w, h); 533 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL || w == 0 || h == 0) 534 + return 0; 535 + 536 + return _gpu_current_renderer->impl->SetWindowResolution(_gpu_current_renderer, w, h); 537 537 } 538 538 539 539 ··· 544 544 MAKE_CURRENT_IF_NONE(target); 545 545 if(!CHECK_CONTEXT) 546 546 RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL context"); 547 - if(w == 0 || h == 0) 548 - return; 549 - 550 - _gpu_current_renderer->impl->SetVirtualResolution(_gpu_current_renderer, target, w, h); 547 + if(w == 0 || h == 0) 548 + return; 549 + 550 + _gpu_current_renderer->impl->SetVirtualResolution(_gpu_current_renderer, target, w, h); 551 551 } 552 552 553 553 void GPU_UnsetVirtualResolution(GPU_Target* target) ··· 557 557 MAKE_CURRENT_IF_NONE(target); 558 558 if(!CHECK_CONTEXT) 559 559 RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL context"); 560 - 561 - _gpu_current_renderer->impl->UnsetVirtualResolution(_gpu_current_renderer, target); 560 + 561 + _gpu_current_renderer->impl->UnsetVirtualResolution(_gpu_current_renderer, target); 562 562 } 563 563 564 564 void GPU_SetImageVirtualResolution(GPU_Image* image, Uint16 w, Uint16 h) 565 565 { 566 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL || w == 0 || h == 0) 567 - return; 568 - 569 - if(image == NULL) 566 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL || w == 0 || h == 0) 570 567 return; 571 - 568 + 569 + if(image == NULL) 570 + return; 571 + 572 572 image->w = w; 573 573 image->h = h; 574 574 image->using_virtual_resolution = 1; ··· 576 576 577 577 void GPU_UnsetImageVirtualResolution(GPU_Image* image) 578 578 { 579 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 580 - return; 581 - 582 - if(image == NULL) 579 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 580 + return; 581 + 582 + if(image == NULL) 583 583 return; 584 - 584 + 585 585 image->w = image->base_w; 586 586 image->h = image->base_h; 587 587 image->using_virtual_resolution = 0; ··· 601 601 SDL_free(_gpu_error_code_queue); 602 602 _gpu_error_code_queue = NULL; 603 603 _gpu_num_error_codes = 0; 604 - 604 + 605 605 SDL_free(_gpu_error_code_result.function); 606 606 _gpu_error_code_result.function = NULL; 607 607 SDL_free(_gpu_error_code_result.details); ··· 612 612 void GPU_SetErrorQueueMax(unsigned int max) 613 613 { 614 614 gpu_free_error_queue(); 615 - 615 + 616 616 // Reallocate with new size 617 617 _gpu_error_code_queue_size = max; 618 618 gpu_init_error_queue(); ··· 620 620 621 621 void GPU_CloseCurrentRenderer(void) 622 622 { 623 - if(_gpu_current_renderer == NULL) 624 - return; 625 - 626 - _gpu_current_renderer->impl->Quit(_gpu_current_renderer); 627 - GPU_FreeRenderer(_gpu_current_renderer); 623 + if(_gpu_current_renderer == NULL) 624 + return; 625 + 626 + _gpu_current_renderer->impl->Quit(_gpu_current_renderer); 627 + GPU_FreeRenderer(_gpu_current_renderer); 628 628 } 629 629 630 630 void GPU_Quit(void) 631 631 { 632 632 if(_gpu_num_error_codes > 0 && GPU_GetDebugLevel() >= GPU_DEBUG_LEVEL_1) 633 633 GPU_LogError("GPU_Quit: %d uncleared error%s.\n", _gpu_num_error_codes, (_gpu_num_error_codes > 1? "s" : "")); 634 - 634 + 635 635 gpu_free_error_queue(); 636 - 637 - if(_gpu_current_renderer == NULL) 638 - return; 639 - 640 - _gpu_current_renderer->impl->Quit(_gpu_current_renderer); 641 - GPU_FreeRenderer(_gpu_current_renderer); 642 - // FIXME: Free all renderers 643 - _gpu_current_renderer = NULL; 644 - 645 - _gpu_init_windowID = 0; 646 - 647 - // Free window mappings 648 - SDL_free(_gpu_window_mappings); 649 - _gpu_window_mappings = NULL; 650 - _gpu_window_mappings_size = 0; 651 - _gpu_num_window_mappings = 0; 652 - 636 + 637 + if(_gpu_current_renderer == NULL) 638 + return; 639 + 640 + _gpu_current_renderer->impl->Quit(_gpu_current_renderer); 641 + GPU_FreeRenderer(_gpu_current_renderer); 642 + // FIXME: Free all renderers 643 + _gpu_current_renderer = NULL; 644 + 645 + _gpu_init_windowID = 0; 646 + 647 + // Free window mappings 648 + SDL_free(_gpu_window_mappings); 649 + _gpu_window_mappings = NULL; 650 + _gpu_window_mappings_size = 0; 651 + _gpu_num_window_mappings = 0; 652 + 653 653 gpu_free_renderer_register(); 654 - 654 + 655 655 if(_gpu_initialized_SDL) 656 656 { 657 657 SDL_QuitSubSystem(SDL_INIT_VIDEO); 658 658 _gpu_initialized_SDL = 0; 659 - 659 + 660 660 if(_gpu_initialized_SDL_core) 661 661 { 662 662 SDL_Quit(); ··· 680 680 void GPU_PushErrorCode(const char* function, GPU_ErrorEnum error, const char* details, ...) 681 681 { 682 682 gpu_init_error_queue(); 683 - 683 + 684 684 if(GPU_GetDebugLevel() >= GPU_DEBUG_LEVEL_1) 685 685 { 686 686 // Print the message ··· 691 691 va_start(lst, details); 692 692 vsnprintf(buf, GPU_ERROR_DETAILS_STRING_MAX, details, lst); 693 693 va_end(lst); 694 - 694 + 695 695 GPU_LogError("%s: %s - %s\n", (function == NULL? "NULL" : function), GPU_GetErrorString(error), buf); 696 696 } 697 697 else 698 698 GPU_LogError("%s: %s\n", (function == NULL? "NULL" : function), GPU_GetErrorString(error)); 699 699 } 700 - 700 + 701 701 if(_gpu_num_error_codes < _gpu_error_code_queue_size) 702 702 { 703 703 if(function == NULL) ··· 725 725 { 726 726 unsigned int i; 727 727 GPU_ErrorObject result = {NULL, GPU_ERROR_NONE, NULL}; 728 - 728 + 729 729 gpu_init_error_queue(); 730 - 730 + 731 731 if(_gpu_num_error_codes <= 0) 732 732 return result; 733 - 733 + 734 734 // Pop the oldest 735 735 strcpy(_gpu_error_code_result.function, _gpu_error_code_queue[0].function); 736 736 _gpu_error_code_result.error = _gpu_error_code_queue[0].error; 737 737 strcpy(_gpu_error_code_result.details, _gpu_error_code_queue[0].details); 738 - 738 + 739 739 // We'll be returning that one 740 740 result = _gpu_error_code_result; 741 - 741 + 742 742 // Move the rest down 743 743 _gpu_num_error_codes--; 744 744 for(i = 0; i < _gpu_num_error_codes; i++) ··· 754 754 { 755 755 switch(error) 756 756 { 757 - case GPU_ERROR_NONE: 758 - return "NO ERROR"; 759 - case GPU_ERROR_BACKEND_ERROR: 760 - return "BACKEND ERROR"; 761 - case GPU_ERROR_DATA_ERROR: 762 - return "DATA ERROR"; 763 - case GPU_ERROR_USER_ERROR: 764 - return "USER ERROR"; 765 - case GPU_ERROR_UNSUPPORTED_FUNCTION: 766 - return "UNSUPPORTED FUNCTION"; 767 - case GPU_ERROR_NULL_ARGUMENT: 768 - return "NULL ARGUMENT"; 769 - case GPU_ERROR_FILE_NOT_FOUND: 770 - return "FILE NOT FOUND"; 757 + case GPU_ERROR_NONE: 758 + return "NO ERROR"; 759 + case GPU_ERROR_BACKEND_ERROR: 760 + return "BACKEND ERROR"; 761 + case GPU_ERROR_DATA_ERROR: 762 + return "DATA ERROR"; 763 + case GPU_ERROR_USER_ERROR: 764 + return "USER ERROR"; 765 + case GPU_ERROR_UNSUPPORTED_FUNCTION: 766 + return "UNSUPPORTED FUNCTION"; 767 + case GPU_ERROR_NULL_ARGUMENT: 768 + return "NULL ARGUMENT"; 769 + case GPU_ERROR_FILE_NOT_FOUND: 770 + return "FILE NOT FOUND"; 771 771 } 772 772 return "UNKNOWN ERROR"; 773 773 } ··· 775 775 776 776 void GPU_GetVirtualCoords(GPU_Target* target, float* x, float* y, float displayX, float displayY) 777 777 { 778 - if(target == NULL) 779 - return; 780 - 781 - if(target->context != NULL) 778 + if(target == NULL) 779 + return; 780 + 781 + if(target->context != NULL) 782 782 { 783 783 if(x != NULL) 784 784 *x = (displayX*target->w)/target->context->window_w; 785 785 if(y != NULL) 786 786 *y = (displayY*target->h)/target->context->window_h; 787 787 } 788 - else if(target->image != NULL) 788 + else if(target->image != NULL) 789 789 { 790 790 if(x != NULL) 791 791 *x = (displayX*target->w)/target->image->w; ··· 803 803 804 804 GPU_Rect GPU_MakeRect(float x, float y, float w, float h) 805 805 { 806 - GPU_Rect r; 807 - r.x = x; 808 - r.y = y; 809 - r.w = w; 810 - r.h = h; 806 + GPU_Rect r; 807 + r.x = x; 808 + r.y = y; 809 + r.w = w; 810 + r.h = h; 811 811 812 812 return r; 813 813 } 814 814 815 815 SDL_Color GPU_MakeColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a) 816 816 { 817 - SDL_Color c; 818 - c.r = r; 819 - c.g = g; 820 - c.b = b; 821 - GET_ALPHA(c) = a; 817 + SDL_Color c; 818 + c.r = r; 819 + c.g = g; 820 + c.b = b; 821 + GET_ALPHA(c) = a; 822 822 823 823 return c; 824 824 } 825 825 826 826 GPU_RendererID GPU_MakeRendererID(const char* name, GPU_RendererEnum renderer, int major_version, int minor_version) 827 827 { 828 - GPU_RendererID r; 829 - r.name = name; 830 - r.renderer = renderer; 831 - r.major_version = major_version; 832 - r.minor_version = minor_version; 833 - 828 + GPU_RendererID r; 829 + r.name = name; 830 + r.renderer = renderer; 831 + r.major_version = major_version; 832 + r.minor_version = minor_version; 833 + 834 834 return r; 835 835 } 836 836 ··· 848 848 849 849 GPU_Camera GPU_GetDefaultCamera(void) 850 850 { 851 - GPU_Camera cam = {0.0f, 0.0f, -10.0f, 0.0f, 1.0f}; 852 - return cam; 851 + GPU_Camera cam = {0.0f, 0.0f, -10.0f, 0.0f, 1.0f}; 852 + return cam; 853 853 } 854 854 855 855 GPU_Camera GPU_GetCamera(GPU_Target* target) 856 856 { 857 - if(target == NULL) 858 - return GPU_GetDefaultCamera(); 859 - return target->camera; 857 + if(target == NULL) 858 + return GPU_GetDefaultCamera(); 859 + return target->camera; 860 860 } 861 861 862 862 GPU_Camera GPU_SetCamera(GPU_Target* target, GPU_Camera* cam) 863 863 { 864 - if(_gpu_current_renderer == NULL) 865 - return GPU_GetDefaultCamera(); 864 + if(_gpu_current_renderer == NULL) 865 + return GPU_GetDefaultCamera(); 866 866 MAKE_CURRENT_IF_NONE(target); 867 - if(_gpu_current_renderer->current_context_target == NULL) 868 - return GPU_GetDefaultCamera(); 869 - 870 - return _gpu_current_renderer->impl->SetCamera(_gpu_current_renderer, target, cam); 867 + if(_gpu_current_renderer->current_context_target == NULL) 868 + return GPU_GetDefaultCamera(); 869 + 870 + return _gpu_current_renderer->impl->SetCamera(_gpu_current_renderer, target, cam); 871 871 } 872 872 873 873 GPU_Image* GPU_CreateImage(Uint16 w, Uint16 h, GPU_FormatEnum format) 874 874 { 875 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 876 - return NULL; 877 - 878 - return _gpu_current_renderer->impl->CreateImage(_gpu_current_renderer, w, h, format); 875 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 876 + return NULL; 877 + 878 + return _gpu_current_renderer->impl->CreateImage(_gpu_current_renderer, w, h, format); 879 879 } 880 880 881 881 GPU_Image* GPU_CreateImageUsingTexture(Uint32 handle, Uint8 take_ownership) 882 882 { 883 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 884 - return NULL; 885 - 886 - return _gpu_current_renderer->impl->CreateImageUsingTexture(_gpu_current_renderer, handle, take_ownership); 883 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 884 + return NULL; 885 + 886 + return _gpu_current_renderer->impl->CreateImageUsingTexture(_gpu_current_renderer, handle, take_ownership); 887 887 } 888 888 889 889 GPU_Image* GPU_LoadImage(const char* filename) 890 890 { 891 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 892 - return NULL; 893 - 894 - return _gpu_current_renderer->impl->LoadImage(_gpu_current_renderer, filename); 891 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 892 + return NULL; 893 + 894 + return _gpu_current_renderer->impl->LoadImage(_gpu_current_renderer, filename); 895 895 } 896 896 897 897 GPU_Image* GPU_CreateAliasImage(GPU_Image* image) 898 898 { 899 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 900 - return NULL; 901 - 902 - return _gpu_current_renderer->impl->CreateAliasImage(_gpu_current_renderer, image); 899 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 900 + return NULL; 901 + 902 + return _gpu_current_renderer->impl->CreateAliasImage(_gpu_current_renderer, image); 903 903 } 904 904 905 905 Uint8 GPU_SaveImage(GPU_Image* image, const char* filename, GPU_FileFormatEnum format) 906 906 { 907 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 908 - return 0; 909 - 910 - return _gpu_current_renderer->impl->SaveImage(_gpu_current_renderer, image, filename, format); 907 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 908 + return 0; 909 + 910 + return _gpu_current_renderer->impl->SaveImage(_gpu_current_renderer, image, filename, format); 911 911 } 912 912 913 913 GPU_Image* GPU_CopyImage(GPU_Image* image) 914 914 { 915 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 916 - return NULL; 917 - 918 - return _gpu_current_renderer->impl->CopyImage(_gpu_current_renderer, image); 915 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 916 + return NULL; 917 + 918 + return _gpu_current_renderer->impl->CopyImage(_gpu_current_renderer, image); 919 919 } 920 920 921 921 void GPU_UpdateImage(GPU_Image* image, const GPU_Rect* image_rect, SDL_Surface* surface, const GPU_Rect* surface_rect) 922 922 { 923 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 924 - return; 925 - 926 - _gpu_current_renderer->impl->UpdateImage(_gpu_current_renderer, image, image_rect, surface, surface_rect); 923 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 924 + return; 925 + 926 + _gpu_current_renderer->impl->UpdateImage(_gpu_current_renderer, image, image_rect, surface, surface_rect); 927 927 } 928 928 929 929 void GPU_UpdateImageBytes(GPU_Image* image, const GPU_Rect* image_rect, const unsigned char* bytes, int bytes_per_row) 930 930 { 931 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 932 - return; 933 - 934 - _gpu_current_renderer->impl->UpdateImageBytes(_gpu_current_renderer, image, image_rect, bytes, bytes_per_row); 931 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 932 + return; 933 + 934 + _gpu_current_renderer->impl->UpdateImageBytes(_gpu_current_renderer, image, image_rect, bytes, bytes_per_row); 935 935 } 936 936 937 937 Uint8 GPU_ReplaceImage(GPU_Image* image, SDL_Surface* surface, const GPU_Rect* surface_rect) 938 938 { 939 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 940 - return 0; 941 - 942 - return _gpu_current_renderer->impl->ReplaceImage(_gpu_current_renderer, image, surface, surface_rect); 939 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 940 + return 0; 941 + 942 + return _gpu_current_renderer->impl->ReplaceImage(_gpu_current_renderer, image, surface, surface_rect); 943 943 } 944 944 945 945 SDL_Surface* GPU_LoadSurface(const char* filename) 946 946 { 947 - int width, height, channels; 948 - Uint32 Rmask, Gmask, Bmask, Amask = 0; 949 - unsigned char* data; 950 - SDL_Surface* result; 951 - 952 - if(filename == NULL) 947 + int i; 948 + int width, height, channels; 949 + Uint32 Rmask, Gmask, Bmask, Amask = 0; 950 + unsigned char* data; 951 + SDL_Surface* result; 952 + 953 + if(filename == NULL) 953 954 { 954 955 GPU_PushErrorCode("GPU_LoadSurface", GPU_ERROR_NULL_ARGUMENT, "filename"); 955 956 return NULL; 956 957 } 957 - 958 - #ifdef __ANDROID__ 959 - if(strlen(filename) > 0 && filename[0] != '/') 960 - { 958 + 959 + #ifdef __ANDROID__ 960 + if(strlen(filename) > 0 && filename[0] != '/') 961 + { 961 962 // Must use SDL_RWops to access the assets directory automatically 962 963 SDL_RWops* rwops = SDL_RWFromFile(filename, "r"); 963 964 if(rwops == NULL) ··· 969 970 data = stbi_load_from_memory(c_data, data_bytes, &width, &height, &channels, 0); 970 971 SDL_free(c_data); 971 972 SDL_FreeRW(rwops); 972 - } 973 - else 973 + } 974 + else 974 975 { 975 976 // Absolute filename 976 977 data = stbi_load(filename, &width, &height, &channels, 0); 977 978 } 978 - #else 979 - data = stbi_load(filename, &width, &height, &channels, 0); 980 - #endif 981 - 982 - if(data == NULL) 983 - { 984 - GPU_PushErrorCode(__func__, GPU_ERROR_DATA_ERROR, "Failed to load \"%s\": %s", filename, stbi_failure_reason()); 985 - return NULL; 986 - } 987 - if(channels < 1 || channels > 4) 988 - { 989 - GPU_PushErrorCode(__func__, GPU_ERROR_DATA_ERROR, "Failed to load \"%s\": Unsupported pixel format", filename); 990 - stbi_image_free(data); 991 - return NULL; 992 - } 993 - 994 - switch(channels) 995 - { 996 - case 1: 997 - Rmask = Gmask = Bmask = 0; // Use default RGB masks for 8-bit 998 - break; 999 - case 2: 1000 - Rmask = Gmask = Bmask = 0; // Use default RGB masks for 16-bit 1001 - break; 1002 - case 3: 1003 - // These are reversed from what SDL_image uses... That is bad. :( Needs testing. 1004 - #if SDL_BYTEORDER == SDL_BIG_ENDIAN 1005 - Rmask = 0xff0000; 1006 - Gmask = 0x00ff00; 1007 - Bmask = 0x0000ff; 1008 - #else 1009 - Rmask = 0x0000ff; 1010 - Gmask = 0x00ff00; 1011 - Bmask = 0xff0000; 1012 - #endif 1013 - break; 1014 - case 4: 1015 - Rmask = 0x000000ff; 1016 - Gmask = 0x0000ff00; 1017 - Bmask = 0x00ff0000; 1018 - Amask = 0xff000000; 1019 - break; 1020 - default: 1021 - Rmask = Gmask = Bmask = 0; 1022 - break; 1023 - } 1024 - 1025 - result = SDL_CreateRGBSurfaceFrom(data, width, height, channels*8, width*channels, Rmask, Gmask, Bmask, Amask); 1026 - if(result != NULL) 1027 - result->flags &= ~SDL_PREALLOC; // Make SDL take ownership of the data memory 1028 - 1029 - if(result != NULL && result->format->palette != NULL) 979 + #else 980 + data = stbi_load(filename, &width, &height, &channels, 0); 981 + #endif 982 + 983 + if(data == NULL) 984 + { 985 + GPU_PushErrorCode(__func__, GPU_ERROR_DATA_ERROR, "Failed to load \"%s\": %s", filename, stbi_failure_reason()); 986 + return NULL; 987 + } 988 + if(channels < 1 || channels > 4) 989 + { 990 + GPU_PushErrorCode(__func__, GPU_ERROR_DATA_ERROR, "Failed to load \"%s\": Unsupported pixel format", filename); 991 + stbi_image_free(data); 992 + return NULL; 993 + } 994 + 995 + switch(channels) 996 + { 997 + case 1: 998 + Rmask = Gmask = Bmask = 0; // Use default RGB masks for 8-bit 999 + break; 1000 + case 2: 1001 + Rmask = Gmask = Bmask = 0; // Use default RGB masks for 16-bit 1002 + break; 1003 + case 3: 1004 + // These are reversed from what SDL_image uses... That is bad. :( Needs testing. 1005 + #if SDL_BYTEORDER == SDL_BIG_ENDIAN 1006 + Rmask = 0xff0000; 1007 + Gmask = 0x00ff00; 1008 + Bmask = 0x0000ff; 1009 + #else 1010 + Rmask = 0x0000ff; 1011 + Gmask = 0x00ff00; 1012 + Bmask = 0xff0000; 1013 + #endif 1014 + break; 1015 + case 4: 1016 + Rmask = 0x000000ff; 1017 + Gmask = 0x0000ff00; 1018 + Bmask = 0x00ff0000; 1019 + Amask = 0xff000000; 1020 + break; 1021 + default: 1022 + Rmask = Gmask = Bmask = 0; 1023 + break; 1024 + } 1025 + 1026 + result = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, channels*8, Rmask, Gmask, Bmask, Amask); 1027 + if(result == NULL) 1028 + { 1029 + GPU_PushErrorCode(__func__, GPU_ERROR_DATA_ERROR, "Failed to create new %dx%d surface", width, height); 1030 + stbi_image_free(data); 1031 + return NULL; 1032 + } 1033 + 1034 + // Copy row-by-row in case the pitch doesn't match 1035 + for(i = 0; i < height; ++i) 1036 + { 1037 + memcpy((Uint8*)result->pixels + i*result->pitch, data + channels*width*i, channels*width); 1038 + } 1039 + 1040 + stbi_image_free(data); 1041 + 1042 + if(result != NULL && result->format->palette != NULL) 1030 1043 { 1031 1044 // SDL_CreateRGBSurface has no idea what palette to use, so it uses a blank one. 1032 1045 // We'll at least create a grayscale one, but it's not ideal... 1033 1046 // Better would be to get the palette from stbi, but stbi doesn't do that! 1034 1047 SDL_Color colors[256]; 1035 1048 int i; 1036 - 1049 + 1037 1050 for(i = 0; i < 256; i++) 1038 1051 { 1039 1052 colors[i].r = colors[i].g = colors[i].b = (Uint8)i; 1040 1053 } 1041 1054 1042 1055 /* Set palette */ 1043 - #ifdef SDL_GPU_USE_SDL2 1056 + #ifdef SDL_GPU_USE_SDL2 1044 1057 SDL_SetPaletteColors(result->format->palette, colors, 0, 256); 1045 - #else 1058 + #else 1046 1059 SDL_SetPalette(result, SDL_LOGPAL, colors, 0, 256); 1047 - #endif 1060 + #endif 1048 1061 } 1049 - 1050 - return result; 1062 + 1063 + return result; 1051 1064 } 1052 1065 1053 1066 // From http://stackoverflow.com/questions/5309471/getting-file-extension-in-c ··· 1072 1085 1073 1086 1074 1087 data = surface->pixels; 1075 - 1088 + 1076 1089 if(format == GPU_FILE_AUTO) 1077 1090 { 1078 1091 const char* extension = get_filename_ext(filename); ··· 1088 1101 return 0; 1089 1102 } 1090 1103 } 1091 - 1104 + 1092 1105 switch(format) 1093 1106 { 1094 - case GPU_FILE_PNG: 1095 - result = (stbi_write_png(filename, surface->w, surface->h, surface->format->BytesPerPixel, (const unsigned char *const)data, 0) > 0); 1096 - break; 1097 - case GPU_FILE_BMP: 1098 - result = (stbi_write_bmp(filename, surface->w, surface->h, surface->format->BytesPerPixel, (void*)data) > 0); 1099 - break; 1100 - case GPU_FILE_TGA: 1101 - result = (stbi_write_tga(filename, surface->w, surface->h, surface->format->BytesPerPixel, (void*)data) > 0); 1102 - break; 1103 - default: 1104 - GPU_PushErrorCode(__func__, GPU_ERROR_DATA_ERROR, "Unsupported output file format"); 1105 - result = 0; 1106 - break; 1107 + case GPU_FILE_PNG: 1108 + result = (stbi_write_png(filename, surface->w, surface->h, surface->format->BytesPerPixel, (const unsigned char *const)data, 0) > 0); 1109 + break; 1110 + case GPU_FILE_BMP: 1111 + result = (stbi_write_bmp(filename, surface->w, surface->h, surface->format->BytesPerPixel, (void*)data) > 0); 1112 + break; 1113 + case GPU_FILE_TGA: 1114 + result = (stbi_write_tga(filename, surface->w, surface->h, surface->format->BytesPerPixel, (void*)data) > 0); 1115 + break; 1116 + default: 1117 + GPU_PushErrorCode(__func__, GPU_ERROR_DATA_ERROR, "Unsupported output file format"); 1118 + result = 0; 1119 + break; 1107 1120 } 1108 1121 1109 1122 return result; ··· 1111 1124 1112 1125 GPU_Image* GPU_CopyImageFromSurface(SDL_Surface* surface) 1113 1126 { 1114 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1115 - return NULL; 1116 - 1117 - return _gpu_current_renderer->impl->CopyImageFromSurface(_gpu_current_renderer, surface); 1127 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1128 + return NULL; 1129 + 1130 + return _gpu_current_renderer->impl->CopyImageFromSurface(_gpu_current_renderer, surface); 1118 1131 } 1119 1132 1120 1133 GPU_Image* GPU_CopyImageFromTarget(GPU_Target* target) 1121 1134 { 1122 - if(_gpu_current_renderer == NULL) 1123 - return NULL; 1135 + if(_gpu_current_renderer == NULL) 1136 + return NULL; 1124 1137 MAKE_CURRENT_IF_NONE(target); 1125 - if(_gpu_current_renderer->current_context_target == NULL) 1126 - return NULL; 1127 - 1128 - return _gpu_current_renderer->impl->CopyImageFromTarget(_gpu_current_renderer, target); 1138 + if(_gpu_current_renderer->current_context_target == NULL) 1139 + return NULL; 1140 + 1141 + return _gpu_current_renderer->impl->CopyImageFromTarget(_gpu_current_renderer, target); 1129 1142 } 1130 1143 1131 1144 SDL_Surface* GPU_CopySurfaceFromTarget(GPU_Target* target) 1132 1145 { 1133 - if(_gpu_current_renderer == NULL) 1134 - return NULL; 1146 + if(_gpu_current_renderer == NULL) 1147 + return NULL; 1135 1148 MAKE_CURRENT_IF_NONE(target); 1136 - if(_gpu_current_renderer->current_context_target == NULL) 1137 - return NULL; 1138 - 1139 - return _gpu_current_renderer->impl->CopySurfaceFromTarget(_gpu_current_renderer, target); 1149 + if(_gpu_current_renderer->current_context_target == NULL) 1150 + return NULL; 1151 + 1152 + return _gpu_current_renderer->impl->CopySurfaceFromTarget(_gpu_current_renderer, target); 1140 1153 } 1141 1154 1142 1155 SDL_Surface* GPU_CopySurfaceFromImage(GPU_Image* image) 1143 1156 { 1144 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1145 - return NULL; 1146 - 1147 - return _gpu_current_renderer->impl->CopySurfaceFromImage(_gpu_current_renderer, image); 1157 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1158 + return NULL; 1159 + 1160 + return _gpu_current_renderer->impl->CopySurfaceFromImage(_gpu_current_renderer, image); 1148 1161 } 1149 1162 1150 1163 void GPU_FreeImage(GPU_Image* image) 1151 1164 { 1152 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1153 - return; 1154 - 1155 - _gpu_current_renderer->impl->FreeImage(_gpu_current_renderer, image); 1165 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1166 + return; 1167 + 1168 + _gpu_current_renderer->impl->FreeImage(_gpu_current_renderer, image); 1156 1169 } 1157 1170 1158 1171 1159 1172 GPU_Target* GPU_GetContextTarget(void) 1160 1173 { 1161 - if(_gpu_current_renderer == NULL) 1162 - return NULL; 1163 - 1164 - return _gpu_current_renderer->current_context_target; 1174 + if(_gpu_current_renderer == NULL) 1175 + return NULL; 1176 + 1177 + return _gpu_current_renderer->current_context_target; 1165 1178 } 1166 1179 1167 1180 1168 1181 GPU_Target* GPU_LoadTarget(GPU_Image* image) 1169 1182 { 1170 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1171 - return NULL; 1172 - 1173 - return _gpu_current_renderer->impl->LoadTarget(_gpu_current_renderer, image); 1183 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1184 + return NULL; 1185 + 1186 + return _gpu_current_renderer->impl->LoadTarget(_gpu_current_renderer, image); 1174 1187 } 1175 1188 1176 1189 1177 1190 1178 1191 void GPU_FreeTarget(GPU_Target* target) 1179 1192 { 1180 - if(_gpu_current_renderer == NULL) 1181 - return; 1182 - 1183 - _gpu_current_renderer->impl->FreeTarget(_gpu_current_renderer, target); 1193 + if(_gpu_current_renderer == NULL) 1194 + return; 1195 + 1196 + _gpu_current_renderer->impl->FreeTarget(_gpu_current_renderer, target); 1184 1197 } 1185 1198 1186 1199 ··· 1192 1205 MAKE_CURRENT_IF_NONE(target); 1193 1206 if(!CHECK_CONTEXT) 1194 1207 RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL context"); 1195 - 1196 - if(image == NULL) 1208 + 1209 + if(image == NULL) 1197 1210 RETURN_ERROR(GPU_ERROR_NULL_ARGUMENT, "image"); 1198 - if(target == NULL) 1211 + if(target == NULL) 1199 1212 RETURN_ERROR(GPU_ERROR_NULL_ARGUMENT, "target"); 1200 - 1201 - _gpu_current_renderer->impl->Blit(_gpu_current_renderer, image, src_rect, target, x, y); 1213 + 1214 + _gpu_current_renderer->impl->Blit(_gpu_current_renderer, image, src_rect, target, x, y); 1202 1215 } 1203 1216 1204 1217 ··· 1209 1222 MAKE_CURRENT_IF_NONE(target); 1210 1223 if(!CHECK_CONTEXT) 1211 1224 RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL context"); 1212 - 1213 - if(image == NULL) 1225 + 1226 + if(image == NULL) 1214 1227 RETURN_ERROR(GPU_ERROR_NULL_ARGUMENT, "image"); 1215 - if(target == NULL) 1228 + if(target == NULL) 1216 1229 RETURN_ERROR(GPU_ERROR_NULL_ARGUMENT, "target"); 1217 - 1218 - _gpu_current_renderer->impl->BlitRotate(_gpu_current_renderer, image, src_rect, target, x, y, angle); 1230 + 1231 + _gpu_current_renderer->impl->BlitRotate(_gpu_current_renderer, image, src_rect, target, x, y, angle); 1219 1232 } 1220 1233 1221 1234 void GPU_BlitScale(GPU_Image* image, GPU_Rect* src_rect, GPU_Target* target, float x, float y, float scaleX, float scaleY) ··· 1225 1238 MAKE_CURRENT_IF_NONE(target); 1226 1239 if(!CHECK_CONTEXT) 1227 1240 RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL context"); 1228 - 1229 - if(image == NULL) 1241 + 1242 + if(image == NULL) 1230 1243 RETURN_ERROR(GPU_ERROR_NULL_ARGUMENT, "image"); 1231 - if(target == NULL) 1244 + if(target == NULL) 1232 1245 RETURN_ERROR(GPU_ERROR_NULL_ARGUMENT, "target"); 1233 - 1234 - _gpu_current_renderer->impl->BlitScale(_gpu_current_renderer, image, src_rect, target, x, y, scaleX, scaleY); 1246 + 1247 + _gpu_current_renderer->impl->BlitScale(_gpu_current_renderer, image, src_rect, target, x, y, scaleX, scaleY); 1235 1248 } 1236 1249 1237 1250 void GPU_BlitTransform(GPU_Image* image, GPU_Rect* src_rect, GPU_Target* target, float x, float y, float angle, float scaleX, float scaleY) ··· 1241 1254 MAKE_CURRENT_IF_NONE(target); 1242 1255 if(!CHECK_CONTEXT) 1243 1256 RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL context"); 1244 - 1245 - if(image == NULL) 1257 + 1258 + if(image == NULL) 1246 1259 RETURN_ERROR(GPU_ERROR_NULL_ARGUMENT, "image"); 1247 - if(target == NULL) 1260 + if(target == NULL) 1248 1261 RETURN_ERROR(GPU_ERROR_NULL_ARGUMENT, "target"); 1249 - 1250 - _gpu_current_renderer->impl->BlitTransform(_gpu_current_renderer, image, src_rect, target, x, y, angle, scaleX, scaleY); 1262 + 1263 + _gpu_current_renderer->impl->BlitTransform(_gpu_current_renderer, image, src_rect, target, x, y, angle, scaleX, scaleY); 1251 1264 } 1252 1265 1253 1266 void GPU_BlitTransformX(GPU_Image* image, GPU_Rect* src_rect, GPU_Target* target, float x, float y, float pivot_x, float pivot_y, float angle, float scaleX, float scaleY) ··· 1257 1270 MAKE_CURRENT_IF_NONE(target); 1258 1271 if(!CHECK_CONTEXT) 1259 1272 RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL context"); 1260 - 1261 - if(image == NULL) 1273 + 1274 + if(image == NULL) 1262 1275 RETURN_ERROR(GPU_ERROR_NULL_ARGUMENT, "image"); 1263 - if(target == NULL) 1276 + if(target == NULL) 1264 1277 RETURN_ERROR(GPU_ERROR_NULL_ARGUMENT, "target"); 1265 - 1266 - _gpu_current_renderer->impl->BlitTransformX(_gpu_current_renderer, image, src_rect, target, x, y, pivot_x, pivot_y, angle, scaleX, scaleY); 1278 + 1279 + _gpu_current_renderer->impl->BlitTransformX(_gpu_current_renderer, image, src_rect, target, x, y, pivot_x, pivot_y, angle, scaleX, scaleY); 1267 1280 } 1268 1281 1269 1282 void GPU_TriangleBatch(GPU_Image* image, GPU_Target* target, unsigned short num_vertices, float* values, unsigned int num_indices, unsigned short* indices, GPU_BatchFlagEnum flags) ··· 1273 1286 MAKE_CURRENT_IF_NONE(target); 1274 1287 if(!CHECK_CONTEXT) 1275 1288 RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL context"); 1276 - 1277 - if(target == NULL) 1289 + 1290 + if(target == NULL) 1278 1291 RETURN_ERROR(GPU_ERROR_NULL_ARGUMENT, "target"); 1279 - 1292 + 1280 1293 if(num_vertices == 0) 1281 1294 return; 1282 - 1283 - 1295 + 1296 + 1284 1297 _gpu_current_renderer->impl->TriangleBatch(_gpu_current_renderer, image, target, num_vertices, values, num_indices, indices, flags); 1285 1298 } 1286 1299 ··· 1289 1302 1290 1303 void GPU_GenerateMipmaps(GPU_Image* image) 1291 1304 { 1292 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1293 - return; 1294 - 1295 - _gpu_current_renderer->impl->GenerateMipmaps(_gpu_current_renderer, image); 1305 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1306 + return; 1307 + 1308 + _gpu_current_renderer->impl->GenerateMipmaps(_gpu_current_renderer, image); 1296 1309 } 1297 1310 1298 1311 ··· 1300 1313 1301 1314 GPU_Rect GPU_SetClipRect(GPU_Target* target, GPU_Rect rect) 1302 1315 { 1303 - if(target == NULL || _gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1304 - { 1305 - GPU_Rect r = {0,0,0,0}; 1306 - return r; 1307 - } 1308 - 1309 - return _gpu_current_renderer->impl->SetClip(_gpu_current_renderer, target, (Sint16)rect.x, (Sint16)rect.y, (Uint16)rect.w, (Uint16)rect.h); 1316 + if(target == NULL || _gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1317 + { 1318 + GPU_Rect r = {0,0,0,0}; 1319 + return r; 1320 + } 1321 + 1322 + return _gpu_current_renderer->impl->SetClip(_gpu_current_renderer, target, (Sint16)rect.x, (Sint16)rect.y, (Uint16)rect.w, (Uint16)rect.h); 1310 1323 } 1311 1324 1312 1325 GPU_Rect GPU_SetClip(GPU_Target* target, Sint16 x, Sint16 y, Uint16 w, Uint16 h) 1313 1326 { 1314 - if(target == NULL || _gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1315 - { 1316 - GPU_Rect r = {0,0,0,0}; 1317 - return r; 1318 - } 1319 - 1320 - return _gpu_current_renderer->impl->SetClip(_gpu_current_renderer, target, x, y, w, h); 1327 + if(target == NULL || _gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1328 + { 1329 + GPU_Rect r = {0,0,0,0}; 1330 + return r; 1331 + } 1332 + 1333 + return _gpu_current_renderer->impl->SetClip(_gpu_current_renderer, target, x, y, w, h); 1321 1334 } 1322 1335 1323 1336 void GPU_UnsetClip(GPU_Target* target) 1324 1337 { 1325 - if(target == NULL || _gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1338 + if(target == NULL || _gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1326 1339 return; 1327 - 1328 - _gpu_current_renderer->impl->UnsetClip(_gpu_current_renderer, target); 1340 + 1341 + _gpu_current_renderer->impl->UnsetClip(_gpu_current_renderer, target); 1329 1342 } 1330 1343 1331 1344 ··· 1333 1346 1334 1347 void GPU_SetColor(GPU_Image* image, SDL_Color color) 1335 1348 { 1336 - if(image == NULL) 1337 - return; 1338 - 1339 - image->color = color; 1349 + if(image == NULL) 1350 + return; 1351 + 1352 + image->color = color; 1340 1353 } 1341 1354 1342 1355 void GPU_SetRGB(GPU_Image* image, Uint8 r, Uint8 g, Uint8 b) 1343 1356 { 1344 - SDL_Color c; 1345 - c.r = r; 1346 - c.g = g; 1347 - c.b = b; 1348 - GET_ALPHA(c) = 255; 1357 + SDL_Color c; 1358 + c.r = r; 1359 + c.g = g; 1360 + c.b = b; 1361 + GET_ALPHA(c) = 255; 1362 + 1363 + if(image == NULL) 1364 + return; 1349 1365 1350 - if(image == NULL) 1351 - return; 1352 - 1353 - image->color = c; 1366 + image->color = c; 1354 1367 } 1355 1368 1356 1369 void GPU_SetRGBA(GPU_Image* image, Uint8 r, Uint8 g, Uint8 b, Uint8 a) 1357 1370 { 1358 - SDL_Color c; 1359 - c.r = r; 1360 - c.g = g; 1361 - c.b = b; 1362 - GET_ALPHA(c) = a; 1371 + SDL_Color c; 1372 + c.r = r; 1373 + c.g = g; 1374 + c.b = b; 1375 + GET_ALPHA(c) = a; 1376 + 1377 + if(image == NULL) 1378 + return; 1363 1379 1364 - if(image == NULL) 1365 - return; 1366 - 1367 - image->color = c; 1380 + image->color = c; 1368 1381 } 1369 1382 1370 1383 void GPU_UnsetColor(GPU_Image* image) 1371 1384 { 1372 1385 SDL_Color c = {255, 255, 255, 255}; 1373 - if(image == NULL) 1374 - return; 1375 - 1386 + if(image == NULL) 1387 + return; 1388 + 1376 1389 image->color = c; 1377 1390 } 1378 1391 1379 1392 void GPU_SetTargetColor(GPU_Target* target, SDL_Color color) 1380 1393 { 1381 - if(target == NULL) 1382 - return; 1383 - 1394 + if(target == NULL) 1395 + return; 1396 + 1384 1397 target->use_color = 1; 1385 1398 target->color = color; 1386 1399 } 1387 1400 1388 1401 void GPU_SetTargetRGB(GPU_Target* target, Uint8 r, Uint8 g, Uint8 b) 1389 1402 { 1390 - SDL_Color c; 1391 - c.r = r; 1392 - c.g = g; 1393 - c.b = b; 1394 - GET_ALPHA(c) = 255; 1403 + SDL_Color c; 1404 + c.r = r; 1405 + c.g = g; 1406 + c.b = b; 1407 + GET_ALPHA(c) = 255; 1408 + 1409 + if(target == NULL) 1410 + return; 1395 1411 1396 - if(target == NULL) 1397 - return; 1398 - 1399 1412 target->use_color = !(r == 255 && g == 255 && b == 255); 1400 1413 target->color = c; 1401 1414 } 1402 1415 1403 1416 void GPU_SetTargetRGBA(GPU_Target* target, Uint8 r, Uint8 g, Uint8 b, Uint8 a) 1404 1417 { 1405 - SDL_Color c; 1406 - c.r = r; 1407 - c.g = g; 1408 - c.b = b; 1409 - GET_ALPHA(c) = a; 1418 + SDL_Color c; 1419 + c.r = r; 1420 + c.g = g; 1421 + c.b = b; 1422 + GET_ALPHA(c) = a; 1423 + 1424 + if(target == NULL) 1425 + return; 1410 1426 1411 - if(target == NULL) 1412 - return; 1413 - 1414 1427 target->use_color = !(r == 255 && g == 255 && b == 255 && a == 255); 1415 1428 target->color = c; 1416 1429 } ··· 1418 1431 void GPU_UnsetTargetColor(GPU_Target* target) 1419 1432 { 1420 1433 SDL_Color c = {255, 255, 255, 255}; 1421 - if(target == NULL) 1422 - return; 1423 - 1434 + if(target == NULL) 1435 + return; 1436 + 1424 1437 target->use_color = 0; 1425 1438 target->color = c; 1426 1439 } 1427 1440 1428 1441 Uint8 GPU_GetBlending(GPU_Image* image) 1429 1442 { 1430 - if(image == NULL) 1431 - return 0; 1432 - 1433 - return image->use_blending; 1443 + if(image == NULL) 1444 + return 0; 1445 + 1446 + return image->use_blending; 1434 1447 } 1435 1448 1436 1449 1437 1450 void GPU_SetBlending(GPU_Image* image, Uint8 enable) 1438 1451 { 1439 - if(image == NULL) 1440 - return; 1441 - 1442 - image->use_blending = enable; 1452 + if(image == NULL) 1453 + return; 1454 + 1455 + image->use_blending = enable; 1443 1456 } 1444 1457 1445 1458 void GPU_SetShapeBlending(Uint8 enable) 1446 1459 { 1447 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1448 - return; 1449 - 1450 - _gpu_current_renderer->current_context_target->context->shapes_use_blending = enable; 1460 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1461 + return; 1462 + 1463 + _gpu_current_renderer->current_context_target->context->shapes_use_blending = enable; 1451 1464 } 1452 1465 1453 1466 1454 1467 GPU_BlendMode GPU_GetBlendModeFromPreset(GPU_BlendPresetEnum preset) 1455 1468 { 1456 - switch(preset) 1457 - { 1469 + switch(preset) 1470 + { 1458 1471 case GPU_BLEND_NORMAL: 1459 - { 1460 - GPU_BlendMode b = {GPU_FUNC_SRC_ALPHA, GPU_FUNC_ONE_MINUS_SRC_ALPHA, GPU_FUNC_SRC_ALPHA, GPU_FUNC_ONE_MINUS_SRC_ALPHA, GPU_EQ_ADD, GPU_EQ_ADD}; 1461 - return b; 1462 - } 1463 - break; 1472 + { 1473 + GPU_BlendMode b = {GPU_FUNC_SRC_ALPHA, GPU_FUNC_ONE_MINUS_SRC_ALPHA, GPU_FUNC_SRC_ALPHA, GPU_FUNC_ONE_MINUS_SRC_ALPHA, GPU_EQ_ADD, GPU_EQ_ADD}; 1474 + return b; 1475 + } 1476 + break; 1464 1477 case GPU_BLEND_PREMULTIPLIED_ALPHA: 1465 - { 1466 - GPU_BlendMode b = {GPU_FUNC_ONE, GPU_FUNC_ONE_MINUS_SRC_ALPHA, GPU_FUNC_ONE, GPU_FUNC_ONE_MINUS_SRC_ALPHA, GPU_EQ_ADD, GPU_EQ_ADD}; 1467 - return b; 1468 - } 1469 - break; 1478 + { 1479 + GPU_BlendMode b = {GPU_FUNC_ONE, GPU_FUNC_ONE_MINUS_SRC_ALPHA, GPU_FUNC_ONE, GPU_FUNC_ONE_MINUS_SRC_ALPHA, GPU_EQ_ADD, GPU_EQ_ADD}; 1480 + return b; 1481 + } 1482 + break; 1470 1483 case GPU_BLEND_MULTIPLY: 1471 - { 1472 - GPU_BlendMode b = {GPU_FUNC_DST_COLOR, GPU_FUNC_ZERO, GPU_FUNC_SRC_ALPHA, GPU_FUNC_ONE_MINUS_SRC_ALPHA, GPU_EQ_ADD, GPU_EQ_ADD}; 1473 - return b; 1474 - } 1475 - break; 1484 + { 1485 + GPU_BlendMode b = {GPU_FUNC_DST_COLOR, GPU_FUNC_ZERO, GPU_FUNC_SRC_ALPHA, GPU_FUNC_ONE_MINUS_SRC_ALPHA, GPU_EQ_ADD, GPU_EQ_ADD}; 1486 + return b; 1487 + } 1488 + break; 1476 1489 case GPU_BLEND_ADD: 1477 - { 1478 - GPU_BlendMode b = {GPU_FUNC_SRC_ALPHA, GPU_FUNC_ONE, GPU_FUNC_SRC_ALPHA, GPU_FUNC_ONE, GPU_EQ_ADD, GPU_EQ_ADD}; 1479 - return b; 1480 - } 1481 - break; 1490 + { 1491 + GPU_BlendMode b = {GPU_FUNC_SRC_ALPHA, GPU_FUNC_ONE, GPU_FUNC_SRC_ALPHA, GPU_FUNC_ONE, GPU_EQ_ADD, GPU_EQ_ADD}; 1492 + return b; 1493 + } 1494 + break; 1482 1495 case GPU_BLEND_SUBTRACT: 1483 1496 // FIXME: Use src alpha for source components? 1484 - { 1485 - GPU_BlendMode b = {GPU_FUNC_ONE, GPU_FUNC_ONE, GPU_FUNC_ONE, GPU_FUNC_ONE, GPU_EQ_SUBTRACT, GPU_EQ_SUBTRACT}; 1486 - return b; 1487 - } 1488 - break; 1497 + { 1498 + GPU_BlendMode b = {GPU_FUNC_ONE, GPU_FUNC_ONE, GPU_FUNC_ONE, GPU_FUNC_ONE, GPU_EQ_SUBTRACT, GPU_EQ_SUBTRACT}; 1499 + return b; 1500 + } 1501 + break; 1489 1502 case GPU_BLEND_MOD_ALPHA: 1490 1503 // Don't disturb the colors, but multiply the dest alpha by the src alpha 1491 - { 1492 - GPU_BlendMode b = {GPU_FUNC_ZERO, GPU_FUNC_ONE, GPU_FUNC_ZERO, GPU_FUNC_SRC_ALPHA, GPU_EQ_ADD, GPU_EQ_ADD}; 1493 - return b; 1494 - } 1495 - break; 1504 + { 1505 + GPU_BlendMode b = {GPU_FUNC_ZERO, GPU_FUNC_ONE, GPU_FUNC_ZERO, GPU_FUNC_SRC_ALPHA, GPU_EQ_ADD, GPU_EQ_ADD}; 1506 + return b; 1507 + } 1508 + break; 1496 1509 case GPU_BLEND_SET_ALPHA: 1497 1510 // Don't disturb the colors, but set the alpha to the src alpha 1498 - { 1499 - GPU_BlendMode b = {GPU_FUNC_ZERO, GPU_FUNC_ONE, GPU_FUNC_ONE, GPU_FUNC_ZERO, GPU_EQ_ADD, GPU_EQ_ADD}; 1500 - return b; 1501 - } 1502 - break; 1511 + { 1512 + GPU_BlendMode b = {GPU_FUNC_ZERO, GPU_FUNC_ONE, GPU_FUNC_ONE, GPU_FUNC_ZERO, GPU_EQ_ADD, GPU_EQ_ADD}; 1513 + return b; 1514 + } 1515 + break; 1503 1516 case GPU_BLEND_SET: 1504 - { 1505 - GPU_BlendMode b = {GPU_FUNC_ONE, GPU_FUNC_ZERO, GPU_FUNC_ONE, GPU_FUNC_ZERO, GPU_EQ_ADD, GPU_EQ_ADD}; 1506 - return b; 1507 - } 1508 - break; 1517 + { 1518 + GPU_BlendMode b = {GPU_FUNC_ONE, GPU_FUNC_ZERO, GPU_FUNC_ONE, GPU_FUNC_ZERO, GPU_EQ_ADD, GPU_EQ_ADD}; 1519 + return b; 1520 + } 1521 + break; 1509 1522 case GPU_BLEND_NORMAL_KEEP_ALPHA: 1510 - { 1511 - GPU_BlendMode b = {GPU_FUNC_SRC_ALPHA, GPU_FUNC_ONE_MINUS_SRC_ALPHA, GPU_FUNC_ZERO, GPU_FUNC_ONE, GPU_EQ_ADD, GPU_EQ_ADD}; 1512 - return b; 1513 - } 1514 - break; 1523 + { 1524 + GPU_BlendMode b = {GPU_FUNC_SRC_ALPHA, GPU_FUNC_ONE_MINUS_SRC_ALPHA, GPU_FUNC_ZERO, GPU_FUNC_ONE, GPU_EQ_ADD, GPU_EQ_ADD}; 1525 + return b; 1526 + } 1527 + break; 1515 1528 case GPU_BLEND_NORMAL_ADD_ALPHA: 1516 - { 1517 - GPU_BlendMode b = {GPU_FUNC_SRC_ALPHA, GPU_FUNC_ONE_MINUS_SRC_ALPHA, GPU_FUNC_ONE, GPU_FUNC_ONE, GPU_EQ_ADD, GPU_EQ_ADD}; 1518 - return b; 1519 - } 1520 - break; 1529 + { 1530 + GPU_BlendMode b = {GPU_FUNC_SRC_ALPHA, GPU_FUNC_ONE_MINUS_SRC_ALPHA, GPU_FUNC_ONE, GPU_FUNC_ONE, GPU_EQ_ADD, GPU_EQ_ADD}; 1531 + return b; 1532 + } 1533 + break; 1521 1534 default: 1522 1535 GPU_PushErrorCode(__func__, GPU_ERROR_USER_ERROR, "Blend preset not supported: %d", preset); 1523 1536 { ··· 1525 1538 return b; 1526 1539 } 1527 1540 break; 1528 - } 1541 + } 1529 1542 } 1530 1543 1531 1544 1532 1545 void GPU_SetBlendFunction(GPU_Image* image, GPU_BlendFuncEnum source_color, GPU_BlendFuncEnum dest_color, GPU_BlendFuncEnum source_alpha, GPU_BlendFuncEnum dest_alpha) 1533 1546 { 1534 - if(image == NULL) 1535 - return; 1536 - 1537 - image->blend_mode.source_color = source_color; 1538 - image->blend_mode.dest_color = dest_color; 1539 - image->blend_mode.source_alpha = source_alpha; 1540 - image->blend_mode.dest_alpha = dest_alpha; 1547 + if(image == NULL) 1548 + return; 1549 + 1550 + image->blend_mode.source_color = source_color; 1551 + image->blend_mode.dest_color = dest_color; 1552 + image->blend_mode.source_alpha = source_alpha; 1553 + image->blend_mode.dest_alpha = dest_alpha; 1541 1554 } 1542 1555 1543 1556 void GPU_SetBlendEquation(GPU_Image* image, GPU_BlendEqEnum color_equation, GPU_BlendEqEnum alpha_equation) 1544 1557 { 1545 - if(image == NULL) 1546 - return; 1547 - 1558 + if(image == NULL) 1559 + return; 1560 + 1548 1561 image->blend_mode.color_equation = color_equation; 1549 1562 image->blend_mode.alpha_equation = alpha_equation; 1550 1563 } ··· 1552 1565 void GPU_SetBlendMode(GPU_Image* image, GPU_BlendPresetEnum preset) 1553 1566 { 1554 1567 GPU_BlendMode b; 1555 - if(image == NULL) 1556 - return; 1557 - 1558 - b = GPU_GetBlendModeFromPreset(preset); 1568 + if(image == NULL) 1569 + return; 1570 + 1571 + b = GPU_GetBlendModeFromPreset(preset); 1559 1572 GPU_SetBlendFunction(image, b.source_color, b.dest_color, b.source_alpha, b.dest_alpha); 1560 1573 GPU_SetBlendEquation(image, b.color_equation, b.alpha_equation); 1561 1574 } ··· 1563 1576 void GPU_SetShapeBlendFunction(GPU_BlendFuncEnum source_color, GPU_BlendFuncEnum dest_color, GPU_BlendFuncEnum source_alpha, GPU_BlendFuncEnum dest_alpha) 1564 1577 { 1565 1578 GPU_Context* context; 1566 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1567 - return; 1568 - 1569 - context = _gpu_current_renderer->current_context_target->context; 1570 - 1571 - context->shapes_blend_mode.source_color = source_color; 1572 - context->shapes_blend_mode.dest_color = dest_color; 1573 - context->shapes_blend_mode.source_alpha = source_alpha; 1574 - context->shapes_blend_mode.dest_alpha = dest_alpha; 1579 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1580 + return; 1581 + 1582 + context = _gpu_current_renderer->current_context_target->context; 1583 + 1584 + context->shapes_blend_mode.source_color = source_color; 1585 + context->shapes_blend_mode.dest_color = dest_color; 1586 + context->shapes_blend_mode.source_alpha = source_alpha; 1587 + context->shapes_blend_mode.dest_alpha = dest_alpha; 1575 1588 } 1576 1589 1577 1590 void GPU_SetShapeBlendEquation(GPU_BlendEqEnum color_equation, GPU_BlendEqEnum alpha_equation) 1578 1591 { 1579 1592 GPU_Context* context; 1580 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1581 - return; 1582 - 1583 - context = _gpu_current_renderer->current_context_target->context; 1584 - 1593 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1594 + return; 1595 + 1596 + context = _gpu_current_renderer->current_context_target->context; 1597 + 1585 1598 context->shapes_blend_mode.color_equation = color_equation; 1586 1599 context->shapes_blend_mode.alpha_equation = alpha_equation; 1587 1600 } ··· 1589 1602 void GPU_SetShapeBlendMode(GPU_BlendPresetEnum preset) 1590 1603 { 1591 1604 GPU_BlendMode b; 1592 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1593 - return; 1594 - 1595 - b = GPU_GetBlendModeFromPreset(preset); 1605 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1606 + return; 1607 + 1608 + b = GPU_GetBlendModeFromPreset(preset); 1596 1609 GPU_SetShapeBlendFunction(b.source_color, b.dest_color, b.source_alpha, b.dest_alpha); 1597 1610 GPU_SetShapeBlendEquation(b.color_equation, b.alpha_equation); 1598 1611 } 1599 1612 1600 1613 void GPU_SetImageFilter(GPU_Image* image, GPU_FilterEnum filter) 1601 1614 { 1602 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1603 - return; 1604 - if(image == NULL) 1605 - return; 1606 - 1607 - _gpu_current_renderer->impl->SetImageFilter(_gpu_current_renderer, image, filter); 1615 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1616 + return; 1617 + if(image == NULL) 1618 + return; 1619 + 1620 + _gpu_current_renderer->impl->SetImageFilter(_gpu_current_renderer, image, filter); 1608 1621 } 1609 1622 1610 1623 GPU_SnapEnum GPU_GetSnapMode(GPU_Image* image) 1611 1624 { 1612 - if(image == NULL) 1613 - return 0; 1614 - 1615 - return image->snap_mode; 1625 + if(image == NULL) 1626 + return 0; 1627 + 1628 + return image->snap_mode; 1616 1629 } 1617 1630 1618 1631 void GPU_SetSnapMode(GPU_Image* image, GPU_SnapEnum mode) 1619 1632 { 1620 - if(image == NULL) 1621 - return; 1622 - 1623 - image->snap_mode = mode; 1633 + if(image == NULL) 1634 + return; 1635 + 1636 + image->snap_mode = mode; 1624 1637 } 1625 1638 1626 1639 void GPU_SetWrapMode(GPU_Image* image, GPU_WrapEnum wrap_mode_x, GPU_WrapEnum wrap_mode_y) 1627 1640 { 1628 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1629 - return; 1630 - if(image == NULL) 1631 - return; 1632 - 1633 - _gpu_current_renderer->impl->SetWrapMode(_gpu_current_renderer, image, wrap_mode_x, wrap_mode_y); 1641 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1642 + return; 1643 + if(image == NULL) 1644 + return; 1645 + 1646 + _gpu_current_renderer->impl->SetWrapMode(_gpu_current_renderer, image, wrap_mode_x, wrap_mode_y); 1634 1647 } 1635 1648 1636 1649 1637 1650 SDL_Color GPU_GetPixel(GPU_Target* target, Sint16 x, Sint16 y) 1638 1651 { 1639 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1640 - { 1641 - SDL_Color c = {0,0,0,0}; 1642 - return c; 1643 - } 1644 - 1645 - return _gpu_current_renderer->impl->GetPixel(_gpu_current_renderer, target, x, y); 1652 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1653 + { 1654 + SDL_Color c = {0,0,0,0}; 1655 + return c; 1656 + } 1657 + 1658 + return _gpu_current_renderer->impl->GetPixel(_gpu_current_renderer, target, x, y); 1646 1659 } 1647 1660 1648 1661 ··· 1658 1671 MAKE_CURRENT_IF_NONE(target); 1659 1672 if(!CHECK_CONTEXT) 1660 1673 RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL context"); 1661 - 1662 - _gpu_current_renderer->impl->ClearRGBA(_gpu_current_renderer, target, 0, 0, 0, 0); 1674 + 1675 + _gpu_current_renderer->impl->ClearRGBA(_gpu_current_renderer, target, 0, 0, 0, 0); 1663 1676 } 1664 1677 1665 1678 void GPU_ClearColor(GPU_Target* target, SDL_Color color) ··· 1669 1682 MAKE_CURRENT_IF_NONE(target); 1670 1683 if(!CHECK_CONTEXT) 1671 1684 RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL context"); 1672 - 1685 + 1673 1686 _gpu_current_renderer->impl->ClearRGBA(_gpu_current_renderer, target, color.r, color.g, color.b, GET_ALPHA(color)); 1674 1687 } 1675 1688 ··· 1680 1693 MAKE_CURRENT_IF_NONE(target); 1681 1694 if(!CHECK_CONTEXT) 1682 1695 RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL context"); 1683 - 1684 - _gpu_current_renderer->impl->ClearRGBA(_gpu_current_renderer, target, r, g, b, 255); 1696 + 1697 + _gpu_current_renderer->impl->ClearRGBA(_gpu_current_renderer, target, r, g, b, 255); 1685 1698 } 1686 1699 1687 1700 void GPU_ClearRGBA(GPU_Target* target, Uint8 r, Uint8 g, Uint8 b, Uint8 a) ··· 1691 1704 MAKE_CURRENT_IF_NONE(target); 1692 1705 if(!CHECK_CONTEXT) 1693 1706 RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL context"); 1694 - 1695 - _gpu_current_renderer->impl->ClearRGBA(_gpu_current_renderer, target, r, g, b, a); 1707 + 1708 + _gpu_current_renderer->impl->ClearRGBA(_gpu_current_renderer, target, r, g, b, a); 1696 1709 } 1697 1710 1698 1711 void GPU_FlushBlitBuffer(void) 1699 1712 { 1700 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1701 - return; 1702 - 1703 - _gpu_current_renderer->impl->FlushBlitBuffer(_gpu_current_renderer); 1713 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1714 + return; 1715 + 1716 + _gpu_current_renderer->impl->FlushBlitBuffer(_gpu_current_renderer); 1704 1717 } 1705 1718 1706 1719 void GPU_Flip(GPU_Target* target) ··· 1710 1723 MAKE_CURRENT_IF_NONE(target); 1711 1724 if(!CHECK_CONTEXT) 1712 1725 RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL context"); 1713 - 1714 - _gpu_current_renderer->impl->Flip(_gpu_current_renderer, target); 1726 + 1727 + _gpu_current_renderer->impl->Flip(_gpu_current_renderer, target); 1715 1728 } 1716 1729 1717 1730 ··· 1723 1736 1724 1737 Uint32 GPU_CompileShader_RW(GPU_ShaderEnum shader_type, SDL_RWops* shader_source) 1725 1738 { 1726 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1727 - return 0; 1728 - 1729 - return _gpu_current_renderer->impl->CompileShader_RW(_gpu_current_renderer, shader_type, shader_source); 1739 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1740 + return 0; 1741 + 1742 + return _gpu_current_renderer->impl->CompileShader_RW(_gpu_current_renderer, shader_type, shader_source); 1730 1743 } 1731 1744 1732 1745 Uint32 GPU_LoadShader(GPU_ShaderEnum shader_type, const char* filename) 1733 1746 { 1734 - SDL_RWops* rwops; 1735 - Uint32 result; 1747 + SDL_RWops* rwops; 1748 + Uint32 result; 1736 1749 1737 1750 if(filename == NULL) 1738 1751 { ··· 1752 1765 1753 1766 Uint32 GPU_CompileShader(GPU_ShaderEnum shader_type, const char* shader_source) 1754 1767 { 1755 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1756 - return 0; 1757 - 1758 - return _gpu_current_renderer->impl->CompileShader(_gpu_current_renderer, shader_type, shader_source); 1768 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1769 + return 0; 1770 + 1771 + return _gpu_current_renderer->impl->CompileShader(_gpu_current_renderer, shader_type, shader_source); 1759 1772 } 1760 1773 1761 1774 Uint8 GPU_LinkShaderProgram(Uint32 program_object) 1762 1775 { 1763 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1764 - return 0; 1765 - 1766 - return _gpu_current_renderer->impl->LinkShaderProgram(_gpu_current_renderer, program_object); 1776 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1777 + return 0; 1778 + 1779 + return _gpu_current_renderer->impl->LinkShaderProgram(_gpu_current_renderer, program_object); 1767 1780 } 1768 1781 1769 1782 Uint32 GPU_CreateShaderProgram(void) 1770 1783 { 1771 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1772 - return 0; 1773 - 1774 - return _gpu_current_renderer->impl->CreateShaderProgram(_gpu_current_renderer); 1784 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1785 + return 0; 1786 + 1787 + return _gpu_current_renderer->impl->CreateShaderProgram(_gpu_current_renderer); 1775 1788 } 1776 1789 1777 1790 Uint32 GPU_LinkShaders(Uint32 shader_object1, Uint32 shader_object2) 1778 1791 { 1779 1792 Uint32 p; 1780 - 1781 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1782 - return 0; 1783 - 1793 + 1794 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1795 + return 0; 1796 + 1784 1797 if((_gpu_current_renderer->enabled_features & GPU_FEATURE_BASIC_SHADERS) != GPU_FEATURE_BASIC_SHADERS) 1785 1798 return 0; 1786 - 1799 + 1787 1800 p = _gpu_current_renderer->impl->CreateShaderProgram(_gpu_current_renderer); 1788 1801 1789 - _gpu_current_renderer->impl->AttachShader(_gpu_current_renderer, p, shader_object1); 1790 - _gpu_current_renderer->impl->AttachShader(_gpu_current_renderer, p, shader_object2); 1791 - 1792 - if(_gpu_current_renderer->impl->LinkShaderProgram(_gpu_current_renderer, p)) 1802 + _gpu_current_renderer->impl->AttachShader(_gpu_current_renderer, p, shader_object1); 1803 + _gpu_current_renderer->impl->AttachShader(_gpu_current_renderer, p, shader_object2); 1804 + 1805 + if(_gpu_current_renderer->impl->LinkShaderProgram(_gpu_current_renderer, p)) 1793 1806 return p; 1794 - 1807 + 1795 1808 _gpu_current_renderer->impl->FreeShaderProgram(_gpu_current_renderer, p); 1796 1809 return 0; 1797 1810 } 1798 1811 1799 1812 void GPU_FreeShader(Uint32 shader_object) 1800 1813 { 1801 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1802 - return; 1803 - 1804 - _gpu_current_renderer->impl->FreeShader(_gpu_current_renderer, shader_object); 1814 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1815 + return; 1816 + 1817 + _gpu_current_renderer->impl->FreeShader(_gpu_current_renderer, shader_object); 1805 1818 } 1806 1819 1807 1820 void GPU_FreeShaderProgram(Uint32 program_object) 1808 1821 { 1809 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1810 - return; 1811 - 1812 - _gpu_current_renderer->impl->FreeShaderProgram(_gpu_current_renderer, program_object); 1822 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1823 + return; 1824 + 1825 + _gpu_current_renderer->impl->FreeShaderProgram(_gpu_current_renderer, program_object); 1813 1826 } 1814 1827 1815 1828 void GPU_AttachShader(Uint32 program_object, Uint32 shader_object) 1816 1829 { 1817 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1818 - return; 1819 - 1820 - _gpu_current_renderer->impl->AttachShader(_gpu_current_renderer, program_object, shader_object); 1830 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1831 + return; 1832 + 1833 + _gpu_current_renderer->impl->AttachShader(_gpu_current_renderer, program_object, shader_object); 1821 1834 } 1822 1835 1823 1836 void GPU_DetachShader(Uint32 program_object, Uint32 shader_object) 1824 1837 { 1825 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1826 - return; 1827 - 1828 - _gpu_current_renderer->impl->DetachShader(_gpu_current_renderer, program_object, shader_object); 1838 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1839 + return; 1840 + 1841 + _gpu_current_renderer->impl->DetachShader(_gpu_current_renderer, program_object, shader_object); 1829 1842 } 1830 1843 1831 1844 Uint8 GPU_IsDefaultShaderProgram(Uint32 program_object) 1832 1845 { 1833 1846 GPU_Context* context; 1834 - 1835 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1836 - return 0; 1837 - 1847 + 1848 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1849 + return 0; 1850 + 1838 1851 context = _gpu_current_renderer->current_context_target->context; 1839 1852 return (program_object == context->default_textured_shader_program || program_object == context->default_untextured_shader_program); 1840 1853 } 1841 1854 1842 1855 void GPU_ActivateShaderProgram(Uint32 program_object, GPU_ShaderBlock* block) 1843 1856 { 1844 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1845 - return; 1846 - 1847 - _gpu_current_renderer->impl->ActivateShaderProgram(_gpu_current_renderer, program_object, block); 1857 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1858 + return; 1859 + 1860 + _gpu_current_renderer->impl->ActivateShaderProgram(_gpu_current_renderer, program_object, block); 1848 1861 } 1849 1862 1850 1863 void GPU_DeactivateShaderProgram(void) 1851 1864 { 1852 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1853 - return; 1854 - 1855 - _gpu_current_renderer->impl->DeactivateShaderProgram(_gpu_current_renderer); 1865 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1866 + return; 1867 + 1868 + _gpu_current_renderer->impl->DeactivateShaderProgram(_gpu_current_renderer); 1856 1869 } 1857 1870 1858 1871 const char* GPU_GetShaderMessage(void) 1859 1872 { 1860 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1861 - return NULL; 1862 - 1863 - return _gpu_current_renderer->impl->GetShaderMessage(_gpu_current_renderer); 1873 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1874 + return NULL; 1875 + 1876 + return _gpu_current_renderer->impl->GetShaderMessage(_gpu_current_renderer); 1864 1877 } 1865 1878 1866 1879 int GPU_GetAttributeLocation(Uint32 program_object, const char* attrib_name) 1867 1880 { 1868 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1869 - return 0; 1870 - 1871 - return _gpu_current_renderer->impl->GetAttributeLocation(_gpu_current_renderer, program_object, attrib_name); 1881 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1882 + return 0; 1883 + 1884 + return _gpu_current_renderer->impl->GetAttributeLocation(_gpu_current_renderer, program_object, attrib_name); 1872 1885 } 1873 1886 1874 1887 GPU_AttributeFormat GPU_MakeAttributeFormat(int num_elems_per_vertex, GPU_TypeEnum type, Uint8 normalize, int stride_bytes, int offset_bytes) 1875 1888 { 1876 - GPU_AttributeFormat f; 1877 - f.is_per_sprite = 0; 1878 - f.num_elems_per_value = num_elems_per_vertex; 1879 - f.type = type; 1880 - f.normalize = normalize; 1881 - f.stride_bytes = stride_bytes; 1882 - f.offset_bytes = offset_bytes; 1889 + GPU_AttributeFormat f; 1890 + f.is_per_sprite = 0; 1891 + f.num_elems_per_value = num_elems_per_vertex; 1892 + f.type = type; 1893 + f.normalize = normalize; 1894 + f.stride_bytes = stride_bytes; 1895 + f.offset_bytes = offset_bytes; 1883 1896 return f; 1884 1897 } 1885 1898 1886 1899 GPU_Attribute GPU_MakeAttribute(int location, void* values, GPU_AttributeFormat format) 1887 1900 { 1888 - GPU_Attribute a; 1889 - a.location = location; 1890 - a.values = values; 1891 - a.format = format; 1901 + GPU_Attribute a; 1902 + a.location = location; 1903 + a.values = values; 1904 + a.format = format; 1892 1905 return a; 1893 1906 } 1894 1907 1895 1908 int GPU_GetUniformLocation(Uint32 program_object, const char* uniform_name) 1896 1909 { 1897 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1898 - return 0; 1899 - 1900 - return _gpu_current_renderer->impl->GetUniformLocation(_gpu_current_renderer, program_object, uniform_name); 1910 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1911 + return 0; 1912 + 1913 + return _gpu_current_renderer->impl->GetUniformLocation(_gpu_current_renderer, program_object, uniform_name); 1901 1914 } 1902 1915 1903 1916 GPU_ShaderBlock GPU_LoadShaderBlock(Uint32 program_object, const char* position_name, const char* texcoord_name, const char* color_name, const char* modelViewMatrix_name) 1904 1917 { 1905 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1918 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1906 1919 { 1907 1920 GPU_ShaderBlock b; 1908 1921 b.position_loc = -1; 1909 1922 b.texcoord_loc = -1; 1910 1923 b.color_loc = -1; 1911 1924 b.modelViewProjection_loc = -1; 1912 - return b; 1925 + return b; 1913 1926 } 1914 - 1915 - return _gpu_current_renderer->impl->LoadShaderBlock(_gpu_current_renderer, program_object, position_name, texcoord_name, color_name, modelViewMatrix_name); 1927 + 1928 + return _gpu_current_renderer->impl->LoadShaderBlock(_gpu_current_renderer, program_object, position_name, texcoord_name, color_name, modelViewMatrix_name); 1916 1929 } 1917 1930 1918 1931 void GPU_SetShaderBlock(GPU_ShaderBlock block) 1919 1932 { 1920 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1921 - return; 1922 - 1923 - _gpu_current_renderer->impl->SetShaderBlock(_gpu_current_renderer, block); 1933 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1934 + return; 1935 + 1936 + _gpu_current_renderer->impl->SetShaderBlock(_gpu_current_renderer, block); 1924 1937 } 1925 1938 1926 1939 void GPU_SetShaderImage(GPU_Image* image, int location, int image_unit) 1927 1940 { 1928 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1929 - return; 1930 - 1931 - _gpu_current_renderer->impl->SetShaderImage(_gpu_current_renderer, image, location, image_unit); 1941 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1942 + return; 1943 + 1944 + _gpu_current_renderer->impl->SetShaderImage(_gpu_current_renderer, image, location, image_unit); 1932 1945 } 1933 1946 1934 1947 void GPU_GetUniformiv(Uint32 program_object, int location, int* values) 1935 1948 { 1936 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1937 - return; 1938 - 1939 - _gpu_current_renderer->impl->GetUniformiv(_gpu_current_renderer, program_object, location, values); 1949 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1950 + return; 1951 + 1952 + _gpu_current_renderer->impl->GetUniformiv(_gpu_current_renderer, program_object, location, values); 1940 1953 } 1941 1954 1942 1955 void GPU_SetUniformi(int location, int value) 1943 1956 { 1944 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1945 - return; 1946 - 1947 - _gpu_current_renderer->impl->SetUniformi(_gpu_current_renderer, location, value); 1957 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1958 + return; 1959 + 1960 + _gpu_current_renderer->impl->SetUniformi(_gpu_current_renderer, location, value); 1948 1961 } 1949 1962 1950 1963 void GPU_SetUniformiv(int location, int num_elements_per_value, int num_values, int* values) 1951 1964 { 1952 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1953 - return; 1954 - 1955 - _gpu_current_renderer->impl->SetUniformiv(_gpu_current_renderer, location, num_elements_per_value, num_values, values); 1965 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1966 + return; 1967 + 1968 + _gpu_current_renderer->impl->SetUniformiv(_gpu_current_renderer, location, num_elements_per_value, num_values, values); 1956 1969 } 1957 1970 1958 1971 1959 1972 void GPU_GetUniformuiv(Uint32 program_object, int location, unsigned int* values) 1960 1973 { 1961 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1962 - return; 1963 - 1964 - _gpu_current_renderer->impl->GetUniformuiv(_gpu_current_renderer, program_object, location, values); 1974 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1975 + return; 1976 + 1977 + _gpu_current_renderer->impl->GetUniformuiv(_gpu_current_renderer, program_object, location, values); 1965 1978 } 1966 1979 1967 1980 void GPU_SetUniformui(int location, unsigned int value) 1968 1981 { 1969 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1970 - return; 1971 - 1972 - _gpu_current_renderer->impl->SetUniformui(_gpu_current_renderer, location, value); 1982 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1983 + return; 1984 + 1985 + _gpu_current_renderer->impl->SetUniformui(_gpu_current_renderer, location, value); 1973 1986 } 1974 1987 1975 1988 void GPU_SetUniformuiv(int location, int num_elements_per_value, int num_values, unsigned int* values) 1976 1989 { 1977 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1978 - return; 1979 - 1980 - _gpu_current_renderer->impl->SetUniformuiv(_gpu_current_renderer, location, num_elements_per_value, num_values, values); 1990 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1991 + return; 1992 + 1993 + _gpu_current_renderer->impl->SetUniformuiv(_gpu_current_renderer, location, num_elements_per_value, num_values, values); 1981 1994 } 1982 1995 1983 1996 1984 1997 void GPU_GetUniformfv(Uint32 program_object, int location, float* values) 1985 1998 { 1986 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1987 - return; 1988 - 1989 - _gpu_current_renderer->impl->GetUniformfv(_gpu_current_renderer, program_object, location, values); 1999 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 2000 + return; 2001 + 2002 + _gpu_current_renderer->impl->GetUniformfv(_gpu_current_renderer, program_object, location, values); 1990 2003 } 1991 2004 1992 2005 void GPU_SetUniformf(int location, float value) 1993 2006 { 1994 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1995 - return; 1996 - 1997 - _gpu_current_renderer->impl->SetUniformf(_gpu_current_renderer, location, value); 2007 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 2008 + return; 2009 + 2010 + _gpu_current_renderer->impl->SetUniformf(_gpu_current_renderer, location, value); 1998 2011 } 1999 2012 2000 2013 void GPU_SetUniformfv(int location, int num_elements_per_value, int num_values, float* values) 2001 2014 { 2002 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 2003 - return; 2004 - 2005 - _gpu_current_renderer->impl->SetUniformfv(_gpu_current_renderer, location, num_elements_per_value, num_values, values); 2015 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 2016 + return; 2017 + 2018 + _gpu_current_renderer->impl->SetUniformfv(_gpu_current_renderer, location, num_elements_per_value, num_values, values); 2006 2019 } 2007 2020 2008 2021 // Same as GPU_GetUniformfv() 2009 2022 void GPU_GetUniformMatrixfv(Uint32 program_object, int location, float* values) 2010 2023 { 2011 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 2012 - return; 2013 - 2014 - _gpu_current_renderer->impl->GetUniformfv(_gpu_current_renderer, program_object, location, values); 2024 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 2025 + return; 2026 + 2027 + _gpu_current_renderer->impl->GetUniformfv(_gpu_current_renderer, program_object, location, values); 2015 2028 } 2016 2029 2017 2030 void GPU_SetUniformMatrixfv(int location, int num_matrices, int num_rows, int num_columns, Uint8 transpose, float* values) 2018 2031 { 2019 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 2020 - return; 2021 - 2022 - _gpu_current_renderer->impl->SetUniformMatrixfv(_gpu_current_renderer, location, num_matrices, num_rows, num_columns, transpose, values); 2032 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 2033 + return; 2034 + 2035 + _gpu_current_renderer->impl->SetUniformMatrixfv(_gpu_current_renderer, location, num_matrices, num_rows, num_columns, transpose, values); 2023 2036 } 2024 2037 2025 2038 2026 2039 void GPU_SetAttributef(int location, float value) 2027 2040 { 2028 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 2029 - return; 2030 - 2031 - _gpu_current_renderer->impl->SetAttributef(_gpu_current_renderer, location, value); 2041 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 2042 + return; 2043 + 2044 + _gpu_current_renderer->impl->SetAttributef(_gpu_current_renderer, location, value); 2032 2045 } 2033 2046 2034 2047 void GPU_SetAttributei(int location, int value) 2035 2048 { 2036 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 2037 - return; 2038 - 2039 - _gpu_current_renderer->impl->SetAttributei(_gpu_current_renderer, location, value); 2049 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 2050 + return; 2051 + 2052 + _gpu_current_renderer->impl->SetAttributei(_gpu_current_renderer, location, value); 2040 2053 } 2041 2054 2042 2055 void GPU_SetAttributeui(int location, unsigned int value) 2043 2056 { 2044 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 2045 - return; 2046 - 2047 - _gpu_current_renderer->impl->SetAttributeui(_gpu_current_renderer, location, value); 2057 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 2058 + return; 2059 + 2060 + _gpu_current_renderer->impl->SetAttributeui(_gpu_current_renderer, location, value); 2048 2061 } 2049 2062 2050 2063 void GPU_SetAttributefv(int location, int num_elements, float* value) 2051 2064 { 2052 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 2053 - return; 2054 - 2055 - _gpu_current_renderer->impl->SetAttributefv(_gpu_current_renderer, location, num_elements, value); 2065 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 2066 + return; 2067 + 2068 + _gpu_current_renderer->impl->SetAttributefv(_gpu_current_renderer, location, num_elements, value); 2056 2069 } 2057 2070 2058 2071 void GPU_SetAttributeiv(int location, int num_elements, int* value) 2059 2072 { 2060 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 2061 - return; 2062 - 2063 - _gpu_current_renderer->impl->SetAttributeiv(_gpu_current_renderer, location, num_elements, value); 2073 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 2074 + return; 2075 + 2076 + _gpu_current_renderer->impl->SetAttributeiv(_gpu_current_renderer, location, num_elements, value); 2064 2077 } 2065 2078 2066 2079 void GPU_SetAttributeuiv(int location, int num_elements, unsigned int* value) 2067 2080 { 2068 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 2069 - return; 2070 - 2071 - _gpu_current_renderer->impl->SetAttributeuiv(_gpu_current_renderer, location, num_elements, value); 2081 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 2082 + return; 2083 + 2084 + _gpu_current_renderer->impl->SetAttributeuiv(_gpu_current_renderer, location, num_elements, value); 2072 2085 } 2073 2086 2074 2087 void GPU_SetAttributeSource(int num_values, GPU_Attribute source) 2075 2088 { 2076 - if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 2077 - return; 2078 - 2079 - _gpu_current_renderer->impl->SetAttributeSource(_gpu_current_renderer, num_values, source); 2089 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 2090 + return; 2091 + 2092 + _gpu_current_renderer->impl->SetAttributeSource(_gpu_current_renderer, num_values, source); 2080 2093 } 2081 2094 2082 2095 ··· 2101 2114 * together for a case independent comparison. The mappings are 2102 2115 * based upon ascii character sequences. 2103 2116 */ 2104 - static const unsigned char caseless_charmap[] = { 2105 - '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007', 2106 - '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017', 2107 - '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027', 2108 - '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037', 2109 - '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047', 2110 - '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057', 2111 - '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067', 2112 - '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077', 2113 - '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147', 2114 - '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', 2115 - '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', 2116 - '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137', 2117 - '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147', 2118 - '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', 2119 - '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', 2120 - '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177', 2121 - '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207', 2122 - '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217', 2123 - '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227', 2124 - '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237', 2125 - '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247', 2126 - '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257', 2127 - '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267', 2128 - '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277', 2129 - '\300', '\341', '\342', '\343', '\344', '\345', '\346', '\347', 2130 - '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', 2131 - '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', 2132 - '\370', '\371', '\372', '\333', '\334', '\335', '\336', '\337', 2133 - '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347', 2134 - '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', 2135 - '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', 2136 - '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377', 2117 + static const unsigned char caseless_charmap[] = 2118 + { 2119 + '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007', 2120 + '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017', 2121 + '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027', 2122 + '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037', 2123 + '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047', 2124 + '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057', 2125 + '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067', 2126 + '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077', 2127 + '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147', 2128 + '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', 2129 + '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', 2130 + '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137', 2131 + '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147', 2132 + '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', 2133 + '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', 2134 + '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177', 2135 + '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207', 2136 + '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217', 2137 + '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227', 2138 + '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237', 2139 + '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247', 2140 + '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257', 2141 + '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267', 2142 + '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277', 2143 + '\300', '\341', '\342', '\343', '\344', '\345', '\346', '\347', 2144 + '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', 2145 + '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', 2146 + '\370', '\371', '\372', '\333', '\334', '\335', '\336', '\337', 2147 + '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347', 2148 + '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', 2149 + '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', 2150 + '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377', 2137 2151 }; 2138 2152 2139 2153 int gpu_strcasecmp(const char* s1, const char* s2) ··· 2154 2168 2155 2169 2156 2170 #ifdef _MSC_VER 2157 - #pragma warning(pop) 2171 + #pragma warning(pop) 2158 2172 #endif 2159 2173
-9
src/externals/stb_image/stb_image.c
··· 1 1 2 2 #define STB_IMAGE_IMPLEMENTATION 3 3 4 - // Make stb-image use SDL's allocator so we can let SDL handle the memory that stb allocates. 5 - // To do this, we'll redefine malloc and free. 6 - #include "SDL.h" 7 - #include <stdlib.h> 8 - #undef malloc 9 - #undef free 10 - #define malloc SDL_malloc 11 - #define free SDL_free 12 - 13 4 #include "stb_image.h"
+3 -8
src/externals/stb_image/stb_image_write.c
··· 1 1 2 2 #define STB_IMAGE_WRITE_IMPLEMENTATION 3 3 4 - // stbi_write_png_to_mem() returns a malloc'ed array, 5 - // so let's do the same thing as done with stb_image.c so it is more compatible with SDL's allocator. 6 - #include "SDL.h" 7 - #include <stdlib.h> 8 - #undef malloc 9 - #undef free 10 - #define malloc SDL_malloc 11 - #define free SDL_free 4 + // NOTE: stbi_write_png_to_mem() returns a malloc'ed array, 5 + // This might be bad for making sure the allocator and deallocator match 6 + // and for crossing DLL boundaries with incompatible C runtimes. 12 7 13 8 14 9 #include "stb_image_write.h"
+2 -1
src/renderer_GLES_1.c
··· 36 36 renderer->id = request; 37 37 renderer->id.renderer = GPU_RENDERER_GLES_1; 38 38 renderer->shader_language = GPU_LANGUAGE_NONE; 39 - renderer->shader_version = 0; 39 + renderer->min_shader_version = 0; 40 + renderer->max_shader_version = 0; 40 41 41 42 renderer->current_context_target = NULL; 42 43
+2 -1
src/renderer_GLES_2.c
··· 41 41 renderer->id = request; 42 42 renderer->id.renderer = GPU_RENDERER_GLES_2; 43 43 renderer->shader_language = GPU_LANGUAGE_GLSLES; 44 - renderer->shader_version = SDL_GPU_GLSL_VERSION; 44 + renderer->min_shader_version = 100; 45 + renderer->max_shader_version = SDL_GPU_GLSL_VERSION; 45 46 46 47 renderer->current_context_target = NULL; 47 48
+637 -583
src/renderer_GL_common.inl
··· 136 136 unsigned long n = strcspn(p, " "); 137 137 if((extNameLen == n) && (strncmp(extension_str, p, n) == 0)) 138 138 return 1; 139 - 139 + 140 140 p += (n + 1); 141 141 } 142 142 return 0; ··· 147 147 { 148 148 // Reset supported features 149 149 renderer->enabled_features = 0; 150 - 150 + 151 151 // NPOT textures 152 152 #ifdef SDL_GPU_USE_OPENGL 153 153 if(isExtensionSupported("GL_ARB_texture_non_power_of_two")) ··· 183 183 #ifdef SDL_GPU_USE_OPENGL 184 184 renderer->enabled_features |= GPU_FEATURE_BLEND_EQUATIONS; 185 185 renderer->enabled_features |= GPU_FEATURE_BLEND_FUNC_SEPARATE; 186 - 186 + 187 187 #if SDL_GPU_GL_MAJOR_VERSION > 1 188 188 // Core in GL 2+ 189 189 renderer->enabled_features |= GPU_FEATURE_BLEND_EQUATIONS_SEPARATE; ··· 193 193 else 194 194 renderer->enabled_features &= ~GPU_FEATURE_BLEND_EQUATIONS_SEPARATE; 195 195 #endif 196 - 196 + 197 197 #elif defined(SDL_GPU_USE_GLES) 198 198 199 199 #if SDL_GPU_GLES_MAJOR_VERSION > 1 ··· 206 206 renderer->enabled_features |= GPU_FEATURE_BLEND_EQUATIONS; 207 207 else 208 208 renderer->enabled_features &= ~GPU_FEATURE_BLEND_EQUATIONS; 209 - 209 + 210 210 if(isExtensionSupported("GL_OES_blend_func_separate")) 211 211 renderer->enabled_features |= GPU_FEATURE_BLEND_FUNC_SEPARATE; 212 212 else 213 213 renderer->enabled_features &= ~GPU_FEATURE_BLEND_FUNC_SEPARATE; 214 - 214 + 215 215 if(isExtensionSupported("GL_OES_blend_equation_separate")) 216 216 renderer->enabled_features |= GPU_FEATURE_BLEND_EQUATIONS_SEPARATE; 217 217 else ··· 247 247 renderer->enabled_features |= GPU_FEATURE_GL_BGRA; 248 248 if(isExtensionSupported("GL_EXT_abgr")) 249 249 renderer->enabled_features |= GPU_FEATURE_GL_ABGR; 250 - 250 + 251 251 // Disable other texture formats for GLES. 252 252 // TODO: Add better (static) checking for format support. Some GL versions do not report previously non-core features as extensions. 253 253 #ifdef SDL_GPU_USE_GLES ··· 401 401 new_max_num_vertices = ((unsigned int)cdata->blit_buffer_max_num_vertices) * 2; 402 402 while(new_max_num_vertices <= minimum_vertices_needed) 403 403 new_max_num_vertices *= 2; 404 - 404 + 405 405 if(new_max_num_vertices > GPU_BLIT_BUFFER_ABSOLUTE_MAX_VERTICES) 406 406 new_max_num_vertices = GPU_BLIT_BUFFER_ABSOLUTE_MAX_VERTICES; 407 - 407 + 408 408 //GPU_LogError("Growing to %d vertices\n", new_max_num_vertices); 409 409 // Resize the blit buffer 410 410 new_buffer = (float*)SDL_malloc(new_max_num_vertices * GPU_BLIT_BUFFER_STRIDE); ··· 412 412 SDL_free(cdata->blit_buffer); 413 413 cdata->blit_buffer = new_buffer; 414 414 cdata->blit_buffer_max_num_vertices = new_max_num_vertices; 415 - 415 + 416 416 #ifdef SDL_GPU_USE_BUFFER_PIPELINE 417 417 // Resize the VBOs 418 418 #if !defined(SDL_GPU_NO_VAO) 419 419 glBindVertexArray(cdata->blit_VAO); 420 420 #endif 421 - 421 + 422 422 glBindBuffer(GL_ARRAY_BUFFER, cdata->blit_VBO[0]); 423 423 glBufferData(GL_ARRAY_BUFFER, GPU_BLIT_BUFFER_STRIDE * cdata->blit_buffer_max_num_vertices, NULL, GL_STREAM_DRAW); 424 424 glBindBuffer(GL_ARRAY_BUFFER, cdata->blit_VBO[1]); 425 425 glBufferData(GL_ARRAY_BUFFER, GPU_BLIT_BUFFER_STRIDE * cdata->blit_buffer_max_num_vertices, NULL, GL_STREAM_DRAW); 426 - 426 + 427 427 #if !defined(SDL_GPU_NO_VAO) 428 428 glBindVertexArray(0); 429 429 #endif 430 430 #endif 431 - 431 + 432 432 return 1; 433 433 } 434 434 ··· 441 441 return 1; 442 442 if(cdata->index_buffer_max_num_vertices == GPU_INDEX_BUFFER_ABSOLUTE_MAX_VERTICES) 443 443 return 0; 444 - 444 + 445 445 // Calculate new size (in vertices) 446 446 new_max_num_vertices = cdata->index_buffer_max_num_vertices * 2; 447 447 while(new_max_num_vertices <= minimum_vertices_needed) 448 448 new_max_num_vertices *= 2; 449 - 449 + 450 450 if(new_max_num_vertices > GPU_INDEX_BUFFER_ABSOLUTE_MAX_VERTICES) 451 451 new_max_num_vertices = GPU_INDEX_BUFFER_ABSOLUTE_MAX_VERTICES; 452 - 452 + 453 453 //GPU_LogError("Growing to %d indices\n", new_max_num_vertices); 454 454 // Resize the index buffer 455 455 new_indices = (unsigned short*)SDL_malloc(new_max_num_vertices * sizeof(unsigned short)); ··· 457 457 SDL_free(cdata->index_buffer); 458 458 cdata->index_buffer = new_indices; 459 459 cdata->index_buffer_max_num_vertices = new_max_num_vertices; 460 - 460 + 461 461 #ifdef SDL_GPU_USE_BUFFER_PIPELINE 462 462 // Resize the IBO 463 463 #if !defined(SDL_GPU_NO_VAO) 464 464 glBindVertexArray(cdata->blit_VAO); 465 465 #endif 466 - 466 + 467 467 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cdata->blit_IBO); 468 468 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned short) * cdata->index_buffer_max_num_vertices, NULL, GL_DYNAMIC_DRAW); 469 - 469 + 470 470 #if !defined(SDL_GPU_NO_VAO) 471 471 glBindVertexArray(0); 472 472 #endif 473 473 #endif 474 - 474 + 475 475 return 1; 476 476 } 477 477 ··· 481 481 { 482 482 if(target == NULL || target->context == NULL || renderer->current_context_target == target) 483 483 return; 484 - 484 + 485 485 renderer->impl->FlushBlitBuffer(renderer); 486 - 486 + 487 487 #ifdef SDL_GPU_USE_SDL2 488 488 SDL_GL_MakeCurrent(SDL_GetWindowFromID(target->context->windowID), target->context->context); 489 489 #endif ··· 552 552 GPU_CONTEXT_DATA* cdata = (GPU_CONTEXT_DATA*)renderer->current_context_target->context->data; 553 553 if(cdata->last_use_blending == enable) 554 554 return; 555 - 555 + 556 556 renderer->impl->FlushBlitBuffer(renderer); 557 557 558 558 if(enable) ··· 566 566 static void forceChangeBlendMode(GPU_Renderer* renderer, GPU_BlendMode mode) 567 567 { 568 568 GPU_CONTEXT_DATA* cdata = (GPU_CONTEXT_DATA*)renderer->current_context_target->context->data; 569 - 569 + 570 570 renderer->impl->FlushBlitBuffer(renderer); 571 571 572 572 cdata->last_blend_mode = mode; 573 - 573 + 574 574 if(mode.source_color == mode.source_alpha && mode.dest_color == mode.dest_alpha) 575 575 { 576 576 glBlendFunc(mode.source_color, mode.dest_color); ··· 583 583 { 584 584 GPU_PushErrorCode("(SDL_gpu internal)", GPU_ERROR_BACKEND_ERROR, "Could not set blend function because GPU_FEATURE_BLEND_FUNC_SEPARATE is not supported."); 585 585 } 586 - 586 + 587 587 if(renderer->enabled_features & GPU_FEATURE_BLEND_EQUATIONS) 588 588 { 589 589 if(mode.color_equation == mode.alpha_equation) ··· 611 611 && cdata->last_blend_mode.color_equation == mode.color_equation 612 612 && cdata->last_blend_mode.alpha_equation == mode.alpha_equation) 613 613 return; 614 - 614 + 615 615 forceChangeBlendMode(renderer, mode); 616 616 } 617 617 ··· 622 622 GPU_Context* context = renderer->current_context_target->context; 623 623 if(context->default_textured_shader_program == 0) // No shaders loaded! 624 624 return 0; 625 - 625 + 626 626 if(program_object == 0) 627 627 return context->default_textured_shader_program; 628 - 628 + 629 629 return program_object; 630 630 } 631 631 ··· 652 652 if(enable != ((GPU_CONTEXT_DATA*)context->data)->last_use_texturing) 653 653 { 654 654 renderer->impl->FlushBlitBuffer(renderer); 655 - 655 + 656 656 ((GPU_CONTEXT_DATA*)context->data)->last_use_texturing = enable; 657 657 #ifndef SDL_GPU_SKIP_ENABLE_TEXTURE_2D 658 658 if(enable) ··· 687 687 static void prepareToRenderImage(GPU_Renderer* renderer, GPU_Target* target, GPU_Image* image) 688 688 { 689 689 GPU_Context* context = renderer->current_context_target->context; 690 - 690 + 691 691 enableTexturing(renderer); 692 692 if(GL_TRIANGLES != ((GPU_CONTEXT_DATA*)context->data)->last_shape) 693 693 { 694 694 renderer->impl->FlushBlitBuffer(renderer); 695 695 ((GPU_CONTEXT_DATA*)context->data)->last_shape = GL_TRIANGLES; 696 696 } 697 - 697 + 698 698 // Blitting 699 699 if(target->use_color) 700 700 { ··· 703 703 color.g = MIX_COLOR_COMPONENT(target->color.g, image->color.g); 704 704 color.b = MIX_COLOR_COMPONENT(target->color.b, image->color.b); 705 705 GET_ALPHA(color) = MIX_COLOR_COMPONENT(GET_ALPHA(target->color), GET_ALPHA(image->color)); 706 - 706 + 707 707 changeColor(renderer, color); 708 708 } 709 709 else 710 710 changeColor(renderer, image->color); 711 711 changeBlending(renderer, image->use_blending); 712 712 changeBlendMode(renderer, image->blend_mode); 713 - 713 + 714 714 // If we're using the untextured shader, switch it. 715 715 if(context->current_shader_program == context->default_untextured_shader_program) 716 716 renderer->impl->ActivateShaderProgram(renderer, context->default_textured_shader_program, NULL); ··· 719 719 static void prepareToRenderShapes(GPU_Renderer* renderer, unsigned int shape) 720 720 { 721 721 GPU_Context* context = renderer->current_context_target->context; 722 - 722 + 723 723 disableTexturing(renderer); 724 724 if(shape != ((GPU_CONTEXT_DATA*)context->data)->last_shape) 725 725 { 726 726 renderer->impl->FlushBlitBuffer(renderer); 727 727 ((GPU_CONTEXT_DATA*)context->data)->last_shape = shape; 728 728 } 729 - 729 + 730 730 // Shape rendering 731 731 // Color is set elsewhere for shapes 732 732 changeBlending(renderer, context->shapes_use_blending); 733 733 changeBlendMode(renderer, context->shapes_blend_mode); 734 - 734 + 735 735 // If we're using the textured shader, switch it. 736 736 if(context->current_shader_program == context->default_textured_shader_program) 737 737 renderer->impl->ActivateShaderProgram(renderer, context->default_untextured_shader_program, NULL); ··· 743 743 { 744 744 float y; 745 745 GPU_CONTEXT_DATA* cdata = (GPU_CONTEXT_DATA*)(GPU_GetContextTarget()->context->data); 746 - 746 + 747 747 cdata->last_viewport = viewport; 748 - 748 + 749 749 y = viewport.y; 750 750 if(GPU_GetCoordinateMode() == 0) 751 751 { ··· 755 755 else if(target->context != NULL) 756 756 y = target->context->drawable_h - viewport.h - viewport.y; 757 757 } 758 - 758 + 759 759 glViewport(viewport.x, y, viewport.w, viewport.h); 760 760 } 761 761 ··· 765 765 766 766 if(cdata->last_viewport.x == target->viewport.x && cdata->last_viewport.y == target->viewport.y && cdata->last_viewport.w == target->viewport.w && cdata->last_viewport.h == target->viewport.h) 767 767 return; 768 - 768 + 769 769 forceChangeViewport(target, target->viewport); 770 770 } 771 771 ··· 776 776 float offsetX, offsetY; 777 777 778 778 cdata->last_camera = target->camera; 779 - 779 + 780 780 cdata->last_camera_inverted = invert; 781 - 781 + 782 782 GPU_MatrixMode( GPU_PROJECTION ); 783 783 GPU_LoadIdentity(); 784 - 784 + 785 785 if((!invert ^ GPU_GetCoordinateMode())) 786 786 GPU_Ortho(target->camera.x, target->w + target->camera.x, target->h + target->camera.y, target->camera.y, -1.0f, 1.0f); 787 787 else 788 788 GPU_Ortho(target->camera.x, target->w + target->camera.x, target->camera.y, target->h + target->camera.y, -1.0f, 1.0f); // Special inverted orthographic projection because tex coords are inverted already for render-to-texture 789 - 789 + 790 790 GPU_MatrixMode( GPU_MODELVIEW ); 791 791 GPU_LoadIdentity(); 792 792 ··· 810 810 static void changeCamera(GPU_Target* target) 811 811 { 812 812 //GPU_CONTEXT_DATA* cdata = (GPU_CONTEXT_DATA*)GPU_GetContextTarget()->context->data; 813 - 813 + 814 814 //if(cdata->last_camera_target != target || !equal_cameras(cdata->last_camera, target->camera)) 815 815 { 816 816 applyTargetCamera(target); ··· 848 848 renderer_request.major_version = 1; 849 849 renderer_request.minor_version = 1; 850 850 } 851 - 851 + 852 852 // Tell SDL what we require for the GL context. 853 853 GPU_flags = GPU_GetPreInitFlags(); 854 - 854 + 855 855 renderer->GPU_init_flags = GPU_flags; 856 856 if(GPU_flags & GPU_INIT_DISABLE_DOUBLE_BUFFER) 857 857 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0); ··· 872 872 if(GPU_flags & GPU_INIT_REQUEST_COMPATIBILITY_PROFILE) 873 873 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); 874 874 else 875 + { 875 876 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); 876 - 877 - // Set newer default shader version for core-capable contexts 878 - renderer->shader_version = SDL_GPU_GLSL_VERSION_CORE; 877 + // Force newer default shader version for core contexts because they don't support lower versions 878 + renderer->min_shader_version = SDL_GPU_GLSL_VERSION_CORE; 879 + if(renderer->min_shader_version > renderer->max_shader_version) 880 + renderer->max_shader_version = SDL_GPU_GLSL_VERSION_CORE; 881 + } 882 + 879 883 } 880 884 #endif 881 - 885 + 882 886 // GL version 883 887 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, renderer_request.major_version); 884 888 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, renderer_request.minor_version); ··· 894 898 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); 895 899 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); 896 900 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); 897 - 901 + 898 902 renderer->requested_id = renderer_request; 899 903 900 904 #ifdef SDL_GPU_USE_SDL2 901 - 905 + 902 906 window = NULL; 903 907 // Is there a window already set up that we are supposed to use? 904 908 if(renderer->current_context_target != NULL) 905 909 window = SDL_GetWindowFromID(renderer->current_context_target->context->windowID); 906 910 else 907 911 window = SDL_GetWindowFromID(GPU_GetInitWindow()); 908 - 912 + 909 913 if(window == NULL) 910 914 { 911 915 int win_w, win_h; ··· 915 919 win_w = w; 916 920 win_h = h; 917 921 #endif 918 - 922 + 919 923 // Set up window flags 920 924 SDL_flags |= SDL_WINDOW_OPENGL; 921 925 if(!(SDL_flags & SDL_WINDOW_HIDDEN)) 922 926 SDL_flags |= SDL_WINDOW_SHOWN; 923 - 927 + 924 928 renderer->SDL_init_flags = SDL_flags; 925 929 window = SDL_CreateWindow("", 926 930 SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, ··· 932 936 GPU_PushErrorCode("GPU_Init", GPU_ERROR_BACKEND_ERROR, "Window creation failed."); 933 937 return NULL; 934 938 } 935 - 939 + 936 940 GPU_SetInitWindow(SDL_GetWindowID(window)); 937 941 } 938 942 else ··· 949 953 return NULL; 950 954 } 951 955 #endif 952 - 956 + 953 957 renderer->enabled_features = 0xFFFFFFFF; // Pretend to support them all if using incompatible headers 954 - 955 - 958 + 959 + 956 960 // Create or re-init the current target. This also creates the GL context and initializes enabled_features. 957 961 #ifdef SDL_GPU_USE_SDL2 958 962 if(renderer->impl->CreateTargetFromWindow(renderer, SDL_GetWindowID(window), renderer->current_context_target) == NULL) ··· 961 965 if(renderer->impl->CreateTargetFromWindow(renderer, 0, renderer->current_context_target) == NULL) 962 966 return NULL; 963 967 #endif 964 - 968 + 965 969 // If the dimensions of the window don't match what we asked for, then set up a virtual resolution to pretend like they are. 966 970 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)) 967 971 renderer->impl->SetVirtualResolution(renderer, renderer->current_context_target, w, h); 968 - 972 + 969 973 // Init glVertexAttrib workaround 970 974 #ifdef SDL_GPU_USE_OPENGL 971 975 vendor_string = (const char*)glGetString(GL_VENDOR); ··· 975 979 apply_Intel_attrib_workaround = 1; 976 980 } 977 981 #endif 978 - 982 + 979 983 return renderer->current_context_target; 980 984 } 981 985 ··· 1023 1027 memset(cdata, 0, sizeof(GPU_CONTEXT_DATA)); 1024 1028 target->context->data = cdata; 1025 1029 target->context->context = NULL; 1026 - 1030 + 1027 1031 cdata->last_image = NULL; 1028 1032 cdata->last_target = NULL; 1029 1033 // Initialize the blit buffer ··· 1041 1045 GPU_RemoveWindowMapping(target->context->windowID); 1042 1046 cdata = (GPU_CONTEXT_DATA*)target->context->data; 1043 1047 } 1044 - 1048 + 1045 1049 #ifdef SDL_GPU_USE_SDL2 1046 - 1050 + 1047 1051 window = SDL_GetWindowFromID(windowID); 1048 1052 if(window == NULL) 1049 1053 { ··· 1059 1063 } 1060 1064 return NULL; 1061 1065 } 1062 - 1066 + 1063 1067 // Store the window info 1064 1068 target->context->windowID = SDL_GetWindowID(window); 1065 - 1069 + 1066 1070 // Make a new context if needed and make it current 1067 1071 if(created || target->context->context == NULL) 1068 1072 { 1069 1073 target->context->context = SDL_GL_CreateContext(window); 1070 1074 GPU_AddWindowMapping(target); 1071 1075 } 1072 - 1076 + 1073 1077 // Get window dimensions 1074 1078 SDL_GetWindowSize(window, &target->context->window_w, &target->context->window_h); 1075 1079 target->context->stored_window_w = target->context->window_w; 1076 1080 target->context->stored_window_h = target->context->window_h; 1077 1081 // We need a GL context before we can get the drawable size. 1078 1082 SDL_GL_GetDrawableSize(window, &target->context->drawable_w, &target->context->drawable_h); 1079 - 1083 + 1080 1084 #else 1081 - 1085 + 1082 1086 screen = SDL_GetVideoSurface(); 1083 1087 if(screen == NULL) 1084 1088 { ··· 1094 1098 } 1095 1099 return NULL; 1096 1100 } 1097 - 1101 + 1098 1102 target->context->windowID = 1; 1099 1103 target->context->window_w = target->context->drawable_w = screen->w; 1100 1104 target->context->window_h = target->context->drawable_h = screen->h; 1101 1105 target->context->stored_window_w = target->context->window_w; 1102 1106 target->context->stored_window_h = target->context->window_h; 1103 - 1107 + 1104 1108 #endif 1105 - 1109 + 1106 1110 ((GPU_TARGET_DATA*)target->data)->handle = 0; 1107 1111 ((GPU_TARGET_DATA*)target->data)->format = GL_RGBA; 1108 1112 ··· 1118 1122 target->clip_rect.w = target->w; 1119 1123 target->clip_rect.h = target->h; 1120 1124 target->use_color = 0; 1121 - 1125 + 1122 1126 target->viewport = GPU_MakeRect(0, 0, target->context->drawable_w, target->context->drawable_h); 1123 1127 target->camera = GPU_GetDefaultCamera(); 1124 - 1128 + 1125 1129 target->context->line_thickness = 1.0f; 1126 1130 target->context->use_texturing = 1; 1127 1131 target->context->shapes_use_blending = 1; 1128 1132 target->context->shapes_blend_mode = GPU_GetBlendModeFromPreset(GPU_BLEND_NORMAL); 1129 - 1133 + 1130 1134 cdata->last_color = white; 1131 - 1135 + 1132 1136 cdata->last_use_texturing = 1; 1133 1137 cdata->last_shape = GL_TRIANGLES; 1134 - 1138 + 1135 1139 cdata->last_use_blending = 0; 1136 1140 cdata->last_blend_mode = GPU_GetBlendModeFromPreset(GPU_BLEND_NORMAL); 1137 - 1141 + 1138 1142 cdata->last_viewport = target->viewport; 1139 1143 cdata->last_camera = target->camera; // Redundant due to applyTargetCamera(), below 1140 1144 cdata->last_camera_inverted = 0; ··· 1150 1154 return NULL; 1151 1155 } 1152 1156 #endif 1153 - 1157 + 1154 1158 renderer->impl->MakeCurrent(renderer, target, target->context->windowID); 1155 - 1159 + 1156 1160 framebuffer_handle = 0; 1157 1161 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &framebuffer_handle); 1158 1162 ((GPU_TARGET_DATA*)target->data)->handle = framebuffer_handle; 1159 - 1163 + 1160 1164 // Update our renderer info from the current GL context. 1161 1165 #ifdef SDL_GPU_USE_OPENGL 1162 1166 // OpenGL < 3.0 doesn't have GL_MAJOR_VERSION. Check via version string instead. ··· 1169 1173 #else 1170 1174 renderer->id.minor_version = 0; 1171 1175 #endif 1172 - 1176 + 1173 1177 GPU_PushErrorCode("GPU_CreateTargetFromWindow", GPU_ERROR_BACKEND_ERROR, "Failed to parse OpenGL version string: \"%s\"", version_string); 1174 1178 } 1179 + #ifndef SDL_GPU_DISABLE_SHADERS 1180 + // Check max GLSL version 1181 + { 1182 + int major, minor; 1183 + version_string = (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION); 1184 + if(sscanf(version_string, "%d.%d", &major, &minor) <= 0) 1185 + { 1186 + GPU_PushErrorCode("GPU_CreateTargetFromWindow", GPU_ERROR_BACKEND_ERROR, "Failed to parse GLSL version string: \"%s\"", version_string); 1187 + } 1188 + else 1189 + renderer->max_shader_version = major*100 + minor; 1190 + } 1191 + #endif 1175 1192 #else 1176 1193 // GLES doesn't have GL_MAJOR_VERSION. Check via version string instead. 1177 1194 version_string = (const char*)glGetString(GL_VERSION); ··· 1187 1204 #else 1188 1205 renderer->id.minor_version = 0; 1189 1206 #endif 1190 - 1207 + 1191 1208 GPU_PushErrorCode("GPU_CreateTargetFromWindow", GPU_ERROR_BACKEND_ERROR, "Failed to parse OpenGL version string: \"%s\"", version_string); 1192 1209 } 1193 1210 } 1211 + #ifndef SDL_GPU_DISABLE_SHADERS 1212 + // Check max GLSL version 1213 + { 1214 + int major, minor; 1215 + version_string = (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION); 1216 + if(sscanf(version_string, "OpenGL ES GLSL ES %d.%d", &major, &minor) <= 0) 1217 + { 1218 + GPU_PushErrorCode("GPU_CreateTargetFromWindow", GPU_ERROR_BACKEND_ERROR, "Failed to parse GLSL version string: \"%s\"", version_string); 1219 + } 1220 + else 1221 + renderer->max_shader_version = major*100 + minor; 1222 + } 1194 1223 #endif 1195 - 1224 + #endif 1225 + 1196 1226 // Did the wrong runtime library try to use a later versioned renderer? 1197 1227 if(renderer->id.major_version < renderer->requested_id.major_version) 1198 1228 { ··· 1202 1232 } 1203 1233 1204 1234 init_features(renderer); 1205 - 1235 + 1206 1236 if(!IsFeatureEnabled(renderer, required_features)) 1207 1237 { 1208 1238 GPU_PushErrorCode("GPU_CreateTargetFromWindow", GPU_ERROR_BACKEND_ERROR, "Renderer does not support required features."); 1209 1239 target->context->failed = 1; 1210 1240 return NULL; 1211 1241 } 1212 - 1242 + 1213 1243 #ifdef SDL_GPU_USE_SDL2 1214 1244 // No preference for vsync? 1215 1245 if(!(renderer->GPU_init_flags & (GPU_INIT_DISABLE_VSYNC | GPU_INIT_ENABLE_VSYNC))) ··· 1223 1253 else if(renderer->GPU_init_flags & GPU_INIT_DISABLE_VSYNC) 1224 1254 SDL_GL_SetSwapInterval(0); 1225 1255 #endif 1226 - 1256 + 1227 1257 // Set up GL state 1228 - 1258 + 1229 1259 target->context->projection_matrix.size = 1; 1230 1260 GPU_MatrixIdentity(target->context->projection_matrix.matrix[0]); 1231 - 1261 + 1232 1262 target->context->modelview_matrix.size = 1; 1233 1263 GPU_MatrixIdentity(target->context->modelview_matrix.matrix[0]); 1234 - 1264 + 1235 1265 target->context->matrix_mode = GPU_MODELVIEW; 1236 - 1266 + 1237 1267 // Modes 1238 1268 #ifndef SDL_GPU_SKIP_ENABLE_TEXTURE_2D 1239 1269 glEnable(GL_TEXTURE_2D); ··· 1250 1280 #if SDL_GPU_GL_TIER < 3 1251 1281 glColor4f(1.0f, 1.0f, 1.0f, 1.0f); 1252 1282 #endif 1253 - 1283 + 1254 1284 // Set up camera 1255 1285 applyTargetCamera(target); 1256 - 1286 + 1257 1287 renderer->impl->SetLineThickness(renderer, 1.0f); 1258 - 1259 - 1288 + 1289 + 1260 1290 #ifdef SDL_GPU_USE_BUFFER_PIPELINE 1261 1291 // Create vertex array container and buffer 1262 1292 #if !defined(SDL_GPU_NO_VAO) ··· 1264 1294 glBindVertexArray(cdata->blit_VAO); 1265 1295 #endif 1266 1296 #endif 1267 - 1297 + 1268 1298 target->context->default_textured_shader_program = 0; 1269 1299 target->context->default_untextured_shader_program = 0; 1270 1300 target->context->current_shader_program = 0; 1271 - 1301 + 1272 1302 #ifndef SDL_GPU_DISABLE_SHADERS 1273 1303 // Load default shaders 1274 - 1304 + 1275 1305 if(IsFeatureEnabled(renderer, GPU_FEATURE_BASIC_SHADERS)) 1276 1306 { 1277 1307 Uint32 v, f, p; ··· 1279 1309 const char* textured_fragment_shader_source = GPU_DEFAULT_TEXTURED_FRAGMENT_SHADER_SOURCE; 1280 1310 const char* untextured_vertex_shader_source = GPU_DEFAULT_UNTEXTURED_VERTEX_SHADER_SOURCE; 1281 1311 const char* untextured_fragment_shader_source = GPU_DEFAULT_UNTEXTURED_FRAGMENT_SHADER_SOURCE; 1282 - 1312 + 1283 1313 #ifdef SDL_GPU_ENABLE_CORE_SHADERS 1284 1314 // Use core shaders only when supported by the actual context we got 1285 1315 if(renderer->id.major_version > 3 || (renderer->id.major_version == 3 && renderer->id.minor_version >= 2)) ··· 1290 1320 untextured_fragment_shader_source = GPU_DEFAULT_UNTEXTURED_FRAGMENT_SHADER_SOURCE_CORE; 1291 1321 } 1292 1322 #endif 1293 - 1323 + 1294 1324 // Textured shader 1295 1325 v = renderer->impl->CompileShader(renderer, GPU_VERTEX_SHADER, textured_vertex_shader_source); 1296 - 1326 + 1297 1327 if(!v) 1298 1328 { 1299 1329 GPU_PushErrorCode("GPU_CreateTargetFromWindow", GPU_ERROR_BACKEND_ERROR, "Failed to load default textured vertex shader: %s.", GPU_GetShaderMessage()); 1300 1330 target->context->failed = 1; 1301 1331 return NULL; 1302 1332 } 1303 - 1333 + 1304 1334 f = renderer->impl->CompileShader(renderer, GPU_FRAGMENT_SHADER, textured_fragment_shader_source); 1305 - 1335 + 1306 1336 if(!f) 1307 1337 { 1308 1338 GPU_PushErrorCode("GPU_CreateTargetFromWindow", GPU_ERROR_BACKEND_ERROR, "Failed to load default textured fragment shader: %s.", GPU_GetShaderMessage()); 1309 1339 target->context->failed = 1; 1310 1340 return NULL; 1311 1341 } 1312 - 1342 + 1313 1343 p = renderer->impl->CreateShaderProgram(renderer); 1314 1344 renderer->impl->AttachShader(renderer, p, v); 1315 1345 renderer->impl->AttachShader(renderer, p, f); 1316 1346 renderer->impl->LinkShaderProgram(renderer, p); 1317 - 1347 + 1318 1348 if(!p) 1319 1349 { 1320 1350 GPU_PushErrorCode("GPU_CreateTargetFromWindow", GPU_ERROR_BACKEND_ERROR, "Failed to link default textured shader program: %s.", GPU_GetShaderMessage()); 1321 1351 target->context->failed = 1; 1322 1352 return NULL; 1323 1353 } 1324 - 1354 + 1325 1355 target->context->default_textured_shader_program = p; 1326 - 1356 + 1327 1357 // Get locations of the attributes in the shader 1328 1358 cdata->shader_block[0] = GPU_LoadShaderBlock(p, "gpu_Vertex", "gpu_TexCoord", "gpu_Color", "gpu_ModelViewProjectionMatrix"); 1329 - 1330 - 1359 + 1360 + 1331 1361 // Untextured shader 1332 1362 v = renderer->impl->CompileShader(renderer, GPU_VERTEX_SHADER, untextured_vertex_shader_source); 1333 - 1363 + 1334 1364 if(!v) 1335 1365 { 1336 1366 GPU_PushErrorCode("GPU_CreateTargetFromWindow", GPU_ERROR_BACKEND_ERROR, "Failed to load default untextured vertex shader: %s.", GPU_GetShaderMessage()); 1337 1367 target->context->failed = 1; 1338 1368 return NULL; 1339 1369 } 1340 - 1370 + 1341 1371 f = renderer->impl->CompileShader(renderer, GPU_FRAGMENT_SHADER, untextured_fragment_shader_source); 1342 - 1372 + 1343 1373 if(!f) 1344 1374 { 1345 1375 GPU_PushErrorCode("GPU_CreateTargetFromWindow", GPU_ERROR_BACKEND_ERROR, "Failed to load default untextured fragment shader: %s.", GPU_GetShaderMessage()); 1346 1376 target->context->failed = 1; 1347 1377 return NULL; 1348 1378 } 1349 - 1379 + 1350 1380 p = renderer->impl->CreateShaderProgram(renderer); 1351 1381 renderer->impl->AttachShader(renderer, p, v); 1352 1382 renderer->impl->AttachShader(renderer, p, f); 1353 1383 renderer->impl->LinkShaderProgram(renderer, p); 1354 - 1384 + 1355 1385 if(!p) 1356 1386 { 1357 1387 GPU_PushErrorCode("GPU_CreateTargetFromWindow", GPU_ERROR_BACKEND_ERROR, "Failed to link default untextured shader program: %s.", GPU_GetShaderMessage()); 1358 1388 target->context->failed = 1; 1359 1389 return NULL; 1360 1390 } 1361 - 1391 + 1362 1392 glUseProgram(p); 1363 - 1393 + 1364 1394 target->context->default_untextured_shader_program = target->context->current_shader_program = p; 1365 - 1395 + 1366 1396 // Get locations of the attributes in the shader 1367 1397 cdata->shader_block[1] = GPU_LoadShaderBlock(p, "gpu_Vertex", NULL, "gpu_Color", "gpu_ModelViewProjectionMatrix"); 1368 1398 GPU_SetShaderBlock(cdata->shader_block[1]); 1369 - 1399 + 1370 1400 } 1371 1401 else 1372 1402 { 1373 1403 snprintf(shader_message, 256, "Shaders not supported by this hardware. Default shaders are disabled.\n"); 1374 1404 target->context->default_untextured_shader_program = target->context->current_shader_program = 0; 1375 1405 } 1376 - 1406 + 1377 1407 #ifdef SDL_GPU_USE_BUFFER_PIPELINE 1378 1408 // Create vertex array container and buffer 1379 - 1409 + 1380 1410 glGenBuffers(2, cdata->blit_VBO); 1381 1411 // Create space on the GPU 1382 1412 glBindBuffer(GL_ARRAY_BUFFER, cdata->blit_VBO[0]); ··· 1384 1414 glBindBuffer(GL_ARRAY_BUFFER, cdata->blit_VBO[1]); 1385 1415 glBufferData(GL_ARRAY_BUFFER, GPU_BLIT_BUFFER_STRIDE * cdata->blit_buffer_max_num_vertices, NULL, GL_STREAM_DRAW); 1386 1416 cdata->blit_VBO_flop = 0; 1387 - 1417 + 1388 1418 glGenBuffers(1, &cdata->blit_IBO); 1389 1419 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cdata->blit_IBO); 1390 1420 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned short) * cdata->blit_buffer_max_num_vertices, NULL, GL_DYNAMIC_DRAW); 1391 - 1421 + 1392 1422 glGenBuffers(16, cdata->attribute_VBO); 1393 - 1423 + 1394 1424 // Init 16 attributes to 0 / NULL. 1395 1425 memset(cdata->shader_attributes, 0, 16*sizeof(GPU_AttributeSource)); 1396 1426 #endif 1397 1427 #endif 1398 - 1428 + 1399 1429 return target; 1400 1430 } 1401 1431 ··· 1407 1437 1408 1438 if(target == NULL) 1409 1439 return NULL; 1410 - 1440 + 1411 1441 result = (GPU_Target*)SDL_malloc(sizeof(GPU_Target)); 1412 - 1442 + 1413 1443 // Copy the members 1414 1444 *result = *target; 1415 - 1445 + 1416 1446 // Alias info 1417 1447 if(target->image != NULL) 1418 1448 target->image->refcount++; ··· 1436 1466 #ifdef SDL_GPU_USE_SDL2 1437 1467 if(target->image != NULL) 1438 1468 return; 1439 - 1469 + 1440 1470 c = target->context->context; 1441 1471 if(c != NULL) 1442 1472 { ··· 1448 1478 SDL_Window* window; 1449 1479 1450 1480 renderer->impl->FlushBlitBuffer(renderer); 1451 - 1481 + 1452 1482 // Update the window mappings 1453 1483 GPU_RemoveWindowMapping(windowID); 1454 1484 // Don't remove the target's current mapping. That lets other windows refer to it. 1455 1485 target->context->windowID = windowID; 1456 1486 GPU_AddWindowMapping(target); 1457 - 1487 + 1458 1488 // Update target's window size 1459 1489 window = SDL_GetWindowFromID(windowID); 1460 1490 if(window != NULL) ··· 1464 1494 target->base_w = target->context->drawable_w; 1465 1495 target->base_h = target->context->drawable_h; 1466 1496 } 1467 - 1497 + 1468 1498 // Reset the camera for this window 1469 1499 applyTargetCamera(((GPU_CONTEXT_DATA*)renderer->current_context_target->context->data)->last_target); 1470 1500 } ··· 1475 1505 GPU_RemoveWindowMapping(1); 1476 1506 target->context->windowID = 1; 1477 1507 GPU_AddWindowMapping(target); 1478 - 1508 + 1479 1509 // Update target's window size 1480 1510 screen = SDL_GetVideoSurface(); 1481 1511 if(screen != NULL) ··· 1493 1523 { 1494 1524 if(renderer->current_context_target == NULL) 1495 1525 return; 1496 - 1526 + 1497 1527 renderer->impl->MakeCurrent(renderer, renderer->current_context_target, renderer->current_context_target->context->windowID); 1498 1528 } 1499 1529 ··· 1501 1531 { 1502 1532 GPU_Target* target; 1503 1533 GPU_CONTEXT_DATA* cdata; 1504 - 1534 + 1505 1535 if(renderer->current_context_target == NULL) 1506 1536 return; 1507 - 1537 + 1508 1538 target = renderer->current_context_target; 1509 1539 cdata = (GPU_CONTEXT_DATA*)target->context->data; 1510 - 1511 - 1540 + 1541 + 1512 1542 #ifndef SDL_GPU_DISABLE_SHADERS 1513 1543 if(IsFeatureEnabled(renderer, GPU_FEATURE_BASIC_SHADERS)) 1514 1544 glUseProgram(target->context->current_shader_program); 1515 1545 #endif 1516 - 1546 + 1517 1547 #ifdef SDL_GPU_USE_SDL2 1518 1548 SDL_GL_MakeCurrent(SDL_GetWindowFromID(target->context->windowID), target->context->context); 1519 1549 #endif 1520 - 1521 - 1550 + 1551 + 1522 1552 #ifndef SDL_GPU_USE_BUFFER_PIPELINE 1523 1553 glColor4f(cdata->last_color.r/255.01f, cdata->last_color.g/255.01f, cdata->last_color.b/255.01f, GET_ALPHA(cdata->last_color)/255.01f); 1524 1554 #endif ··· 1528 1558 else 1529 1559 glDisable(GL_TEXTURE_2D); 1530 1560 #endif 1531 - 1561 + 1532 1562 if(cdata->last_use_blending) 1533 1563 glEnable(GL_BLEND); 1534 1564 else 1535 1565 glDisable(GL_BLEND); 1536 - 1566 + 1537 1567 forceChangeBlendMode(renderer, cdata->last_blend_mode); 1538 - 1568 + 1539 1569 forceChangeViewport(target, target->viewport); 1540 - 1570 + 1541 1571 if(cdata->last_image != NULL) 1542 1572 glBindTexture(GL_TEXTURE_2D, ((GPU_IMAGE_DATA*)(cdata->last_image)->data)->handle); 1543 - 1573 + 1544 1574 if(cdata->last_target != NULL) 1545 1575 extBindFramebuffer(renderer, ((GPU_TARGET_DATA*)cdata->last_target->data)->handle); 1546 1576 else ··· 1550 1580 static Uint8 SetWindowResolution(GPU_Renderer* renderer, Uint16 w, Uint16 h) 1551 1581 { 1552 1582 GPU_Target* target = renderer->current_context_target; 1553 - 1583 + 1554 1584 Uint8 isCurrent = isCurrentTarget(renderer, target); 1555 1585 if(isCurrent) 1556 1586 renderer->impl->FlushBlitBuffer(renderer); 1557 - 1587 + 1558 1588 #ifdef SDL_GPU_USE_SDL2 1559 - 1589 + 1560 1590 { 1561 1591 SDL_Window* window = SDL_GetWindowFromID(target->context->windowID); 1562 - 1592 + 1563 1593 // Don't need to resize (only update internals) when resolution isn't changing. 1564 1594 SDL_GetWindowSize(window, &target->context->window_w, &target->context->window_h); 1565 1595 SDL_GL_GetDrawableSize(window, &target->context->drawable_w, &target->context->drawable_h); ··· 1570 1600 SDL_GL_GetDrawableSize(window, &target->context->drawable_w, &target->context->drawable_h); 1571 1601 } 1572 1602 } 1573 - 1603 + 1574 1604 #else 1575 1605 SDL_Surface* screen = SDL_GetVideoSurface(); 1576 1606 Uint32 flags = screen->flags; ··· 1589 1619 1590 1620 target->context->window_w = target->context->drawable_w = screen->w; 1591 1621 target->context->window_h = target->context->drawable_h = screen->h; 1592 - 1622 + 1593 1623 // FIXME: Does the entire GL state need to be reset because the screen was recreated? 1594 - 1624 + 1595 1625 // Reset texturing state 1596 1626 context = renderer->current_context_target->context; 1597 1627 context->use_texturing = 1; 1598 1628 ((GPU_CONTEXT_DATA*)context->data)->last_use_texturing = 0; 1599 - 1629 + 1600 1630 // Clear target (no state change) 1601 1631 glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); 1602 1632 glClear( GL_COLOR_BUFFER_BIT ); 1603 1633 #endif 1604 - 1634 + 1605 1635 // Store the resolution for fullscreen_desktop changes 1606 1636 target->context->stored_window_w = target->context->window_w; 1607 1637 target->context->stored_window_h = target->context->window_h; 1608 - 1638 + 1609 1639 // Update base dimensions 1610 1640 target->base_w = target->context->drawable_w; 1611 1641 target->base_h = target->context->drawable_h; 1612 - 1642 + 1613 1643 // Resets virtual resolution 1614 1644 target->w = target->base_w; 1615 1645 target->h = target->base_h; ··· 1620 1650 changeViewport(target); 1621 1651 1622 1652 GPU_UnsetClip(target); 1623 - 1653 + 1624 1654 if(isCurrent) 1625 1655 applyTargetCamera(target); 1626 1656 ··· 1633 1663 1634 1664 if(target == NULL) 1635 1665 return; 1636 - 1666 + 1637 1667 isCurrent = isCurrentTarget(renderer, target); 1638 1668 if(isCurrent) 1639 1669 renderer->impl->FlushBlitBuffer(renderer); ··· 1641 1671 target->w = w; 1642 1672 target->h = h; 1643 1673 target->using_virtual_resolution = 1; 1644 - 1674 + 1645 1675 if(isCurrent) 1646 1676 applyTargetCamera(target); 1647 1677 } ··· 1652 1682 1653 1683 if(target == NULL) 1654 1684 return; 1655 - 1685 + 1656 1686 isCurrent = isCurrentTarget(renderer, target); 1657 1687 if(isCurrent) 1658 1688 renderer->impl->FlushBlitBuffer(renderer); 1659 - 1689 + 1660 1690 target->w = target->base_w; 1661 1691 target->h = target->base_h; 1662 - 1692 + 1663 1693 target->using_virtual_resolution = 0; 1664 - 1694 + 1665 1695 if(isCurrent) 1666 1696 applyTargetCamera(target); 1667 1697 } ··· 1677 1707 static Uint8 SetFullscreen(GPU_Renderer* renderer, Uint8 enable_fullscreen, Uint8 use_desktop_resolution) 1678 1708 { 1679 1709 GPU_Target* target = renderer->current_context_target; 1680 - 1710 + 1681 1711 #ifdef SDL_GPU_USE_SDL2 1682 1712 SDL_Window* window = SDL_GetWindowFromID(target->context->windowID); 1683 1713 Uint32 old_flags = SDL_GetWindowFlags(window); 1684 1714 Uint8 was_fullscreen = (old_flags & SDL_WINDOW_FULLSCREEN); 1685 1715 Uint8 is_fullscreen = was_fullscreen; 1686 - 1716 + 1687 1717 Uint32 flags = 0; 1688 1718 1689 1719 if(enable_fullscreen) ··· 1693 1723 else 1694 1724 flags = SDL_WINDOW_FULLSCREEN; 1695 1725 } 1696 - 1726 + 1697 1727 if(SDL_SetWindowFullscreen(window, flags) >= 0) 1698 1728 { 1699 1729 flags = SDL_GetWindowFlags(window); 1700 1730 is_fullscreen = (flags & SDL_WINDOW_FULLSCREEN); 1701 - 1731 + 1702 1732 // If we just went fullscreen, save the original resolution 1703 1733 // We do this because you can't depend on the resolution to be preserved by SDL 1704 1734 // SDL_WINDOW_FULLSCREEN_DESKTOP changes the resolution and SDL_WINDOW_FULLSCREEN can change it when a given mode is not available ··· 1707 1737 target->context->stored_window_w = target->context->window_w; 1708 1738 target->context->stored_window_h = target->context->window_h; 1709 1739 } 1710 - 1740 + 1711 1741 // If we're in windowed mode now and a resolution was stored, restore the original window resolution 1712 1742 if(was_fullscreen && !is_fullscreen && (target->context->stored_window_w != 0 && target->context->stored_window_h != 0)) 1713 1743 SDL_SetWindowSize(window, target->context->stored_window_w, target->context->stored_window_h); 1714 - 1744 + 1715 1745 // Update window dims 1716 1746 SDL_GetWindowSize(window, &target->context->window_w, &target->context->window_h); 1717 1747 SDL_GL_GetDrawableSize(window, &target->context->drawable_w, &target->context->drawable_h); 1718 1748 } 1719 - 1749 + 1720 1750 #else 1721 1751 SDL_Surface* surf = SDL_GetVideoSurface(); 1722 1752 Uint8 was_fullscreen = (surf->flags & SDL_FULLSCREEN); 1723 1753 Uint8 is_fullscreen = was_fullscreen; 1724 - 1754 + 1725 1755 if(was_fullscreen ^ enable_fullscreen) 1726 1756 { 1727 1757 SDL_WM_ToggleFullScreen(surf); 1728 1758 is_fullscreen = (surf->flags & SDL_FULLSCREEN); 1729 - 1759 + 1730 1760 // Update window dims 1731 1761 target->context->window_w = target->context->drawable_w = surf->w; 1732 1762 target->context->window_h = target->context->drawable_h = surf->h; 1733 1763 } 1734 - 1764 + 1735 1765 #endif 1736 1766 1737 1767 if(is_fullscreen != was_fullscreen) ··· 1747 1777 // Reset viewport 1748 1778 target->viewport = GPU_MakeRect(0, 0, target->context->drawable_w, target->context->drawable_h); 1749 1779 changeViewport(target); 1750 - 1780 + 1751 1781 // Reset clip 1752 1782 GPU_UnsetClip(target); 1753 - 1783 + 1754 1784 // Update camera 1755 1785 if(isCurrentTarget(renderer, target)) 1756 1786 applyTargetCamera(target); 1757 1787 } 1758 - 1788 + 1759 1789 target->base_w = target->context->drawable_w; 1760 1790 target->base_h = target->context->drawable_h; 1761 - 1791 + 1762 1792 return is_fullscreen; 1763 1793 } 1764 1794 ··· 1773 1803 GPU_PushErrorCode("GPU_SetCamera", GPU_ERROR_NULL_ARGUMENT, "target"); 1774 1804 return GPU_GetDefaultCamera(); 1775 1805 } 1776 - 1806 + 1777 1807 if(cam == NULL) 1778 1808 new_camera = GPU_GetDefaultCamera(); 1779 1809 else 1780 1810 new_camera = *cam; 1781 - 1811 + 1782 1812 old_camera = target->camera; 1783 - 1813 + 1784 1814 if(!equal_cameras(new_camera, old_camera)) 1785 1815 { 1786 1816 if(isCurrentTarget(renderer, target)) 1787 1817 renderer->impl->FlushBlitBuffer(renderer); 1788 - 1818 + 1789 1819 target->camera = new_camera; 1790 1820 } 1791 1821 ··· 1795 1825 static GLuint CreateUninitializedTexture(GPU_Renderer* renderer) 1796 1826 { 1797 1827 GLuint handle; 1798 - 1828 + 1799 1829 glGenTextures(1, &handle); 1800 1830 if(handle == 0) 1801 1831 return 0; ··· 1812 1842 1813 1843 glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); 1814 1844 #endif 1815 - 1845 + 1816 1846 return handle; 1817 1847 } 1818 1848 ··· 1872 1902 GPU_PushErrorCode("GPU_CreateUninitializedImage", GPU_ERROR_DATA_ERROR, "Unsupported image format (0x%x)", format); 1873 1903 return NULL; 1874 1904 } 1875 - 1905 + 1876 1906 if(bytes_per_pixel < 1 || bytes_per_pixel > 4) 1877 1907 { 1878 1908 GPU_PushErrorCode("GPU_CreateUninitializedImage", GPU_ERROR_DATA_ERROR, "Unsupported number of bytes per pixel (%d)", bytes_per_pixel); 1879 1909 return NULL; 1880 1910 } 1881 - 1911 + 1882 1912 // Create the underlying texture 1883 1913 handle = CreateUninitializedTexture(renderer); 1884 1914 if(handle == 0) ··· 1886 1916 GPU_PushErrorCode("GPU_CreateUninitializedImage", GPU_ERROR_BACKEND_ERROR, "Failed to generate a texture handle."); 1887 1917 return NULL; 1888 1918 } 1889 - 1919 + 1890 1920 // Create the GPU_Image 1891 1921 result = (GPU_Image*)SDL_malloc(sizeof(GPU_Image)); 1892 1922 result->refcount = 1; ··· 1898 1928 result->num_layers = num_layers; 1899 1929 result->bytes_per_pixel = bytes_per_pixel; 1900 1930 result->has_mipmaps = 0; 1901 - 1931 + 1902 1932 result->color = white; 1903 1933 result->use_blending = 1; 1904 1934 result->blend_mode = GPU_GetBlendModeFromPreset(GPU_BLEND_NORMAL); ··· 1906 1936 result->snap_mode = GPU_SNAP_POSITION_AND_DIMENSIONS; 1907 1937 result->wrap_mode_x = GPU_WRAP_NONE; 1908 1938 result->wrap_mode_y = GPU_WRAP_NONE; 1909 - 1939 + 1910 1940 result->data = data; 1911 1941 result->is_alias = 0; 1912 1942 data->handle = handle; ··· 1969 1999 zero_buffer = (unsigned char*)SDL_malloc(zero_buffer_size); 1970 2000 memset(zero_buffer, 0, zero_buffer_size); 1971 2001 } 1972 - 2002 + 1973 2003 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 1974 2004 #ifdef SDL_GPU_USE_OPENGL 1975 2005 glPixelStorei(GL_UNPACK_ROW_LENGTH, w); 1976 2006 #endif 1977 - 2007 + 1978 2008 glTexImage2D(GL_TEXTURE_2D, 0, internal_format, w, h, 0, 1979 2009 internal_format, GL_UNSIGNED_BYTE, zero_buffer); 1980 2010 // Tell SDL_gpu what we got (power-of-two requirements have made this change) 1981 2011 result->texture_w = w; 1982 2012 result->texture_h = h; 1983 - 2013 + 1984 2014 // Restore GL defaults 1985 2015 glPixelStorei(GL_UNPACK_ALIGNMENT, 4); 1986 2016 #ifdef SDL_GPU_USE_OPENGL ··· 1997 2027 GPU_PushErrorCode("GPU_CreateImageUsingTexture", GPU_ERROR_UNSUPPORTED_FUNCTION, "Renderer %s does not support this function", renderer->id.name); 1998 2028 return NULL; 1999 2029 #else 2000 - 2030 + 2001 2031 GLint w, h; 2002 2032 GLuint num_layers, bytes_per_pixel; 2003 2033 GLint gl_format; 2004 2034 GLint wrap_s, wrap_t; 2005 2035 GLint min_filter; 2006 - 2036 + 2007 2037 GPU_FormatEnum format; 2008 2038 GPU_WrapEnum wrap_x, wrap_y; 2009 2039 GPU_FilterEnum filter_mode; 2010 2040 SDL_Color white = { 255, 255, 255, 255 }; 2011 - 2041 + 2012 2042 GPU_Image* result; 2013 2043 GPU_IMAGE_DATA* data; 2014 2044 2015 2045 flushAndBindTexture(renderer, handle); 2016 - 2046 + 2017 2047 glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &gl_format); 2018 2048 2019 2049 switch(gl_format) ··· 2054 2084 GPU_PushErrorCode("GPU_CreateImageUsingTexture", GPU_ERROR_DATA_ERROR, "Unsupported GL image format (0x%x)", gl_format); 2055 2085 return NULL; 2056 2086 } 2057 - 2087 + 2058 2088 glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w); 2059 2089 glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h); 2060 - 2061 - 2090 + 2091 + 2062 2092 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, &min_filter); 2063 2093 // Ignore mag filter... Maybe the wrong thing to do? 2064 - 2094 + 2065 2095 // Let the user use one that we don't support and pretend that we're okay with that. 2066 2096 switch(min_filter) 2067 2097 { ··· 2080 2110 filter_mode = GPU_FILTER_LINEAR; 2081 2111 break; 2082 2112 } 2083 - 2084 - 2113 + 2114 + 2085 2115 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, &wrap_s); 2086 2116 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, &wrap_t); 2087 - 2117 + 2088 2118 // Let the user use one that we don't support and pretend that we're okay with that. 2089 2119 switch(wrap_s) 2090 2120 { ··· 2102 2132 wrap_x = GPU_WRAP_NONE; 2103 2133 break; 2104 2134 } 2105 - 2135 + 2106 2136 switch(wrap_t) 2107 2137 { 2108 2138 case GL_CLAMP_TO_EDGE: ··· 2119 2149 wrap_y = GPU_WRAP_NONE; 2120 2150 break; 2121 2151 } 2122 - 2152 + 2123 2153 // Finally create the image 2124 - 2154 + 2125 2155 data = (GPU_IMAGE_DATA*)SDL_malloc(sizeof(GPU_IMAGE_DATA)); 2126 2156 data->refcount = 1; 2127 2157 data->handle = handle; 2128 2158 data->owns_handle = take_ownership; 2129 2159 data->format = gl_format; 2130 - 2160 + 2131 2161 2132 2162 result = (GPU_Image*)SDL_malloc(sizeof(GPU_Image)); 2133 2163 result->refcount = 1; ··· 2137 2167 result->num_layers = num_layers; 2138 2168 result->bytes_per_pixel = bytes_per_pixel; 2139 2169 result->has_mipmaps = 0; 2140 - 2170 + 2141 2171 result->color = white; 2142 2172 result->use_blending = 1; 2143 2173 result->blend_mode = GPU_GetBlendModeFromPreset(GPU_BLEND_NORMAL); ··· 2145 2175 result->filter_mode = filter_mode; 2146 2176 result->wrap_mode_x = wrap_x; 2147 2177 result->wrap_mode_y = wrap_y; 2148 - 2178 + 2149 2179 result->data = data; 2150 2180 result->is_alias = 0; 2151 2181 2152 2182 result->using_virtual_resolution = 0; 2153 2183 result->w = w; 2154 2184 result->h = h; 2155 - 2185 + 2156 2186 result->base_w = w; 2157 2187 result->base_h = h; 2158 2188 result->texture_w = w; ··· 2190 2220 result = (GPU_Image*)SDL_malloc(sizeof(GPU_Image)); 2191 2221 // Copy the members 2192 2222 *result = *image; 2193 - 2223 + 2194 2224 // Alias info 2195 2225 ((GPU_IMAGE_DATA*)image->data)->refcount++; 2196 2226 result->refcount = 1; ··· 2204 2234 { 2205 2235 if(source == NULL) 2206 2236 return 0; 2207 - 2237 + 2208 2238 if(isCurrentTarget(renderer, source)) 2209 2239 renderer->impl->FlushBlitBuffer(renderer); 2210 - 2240 + 2211 2241 if(bindFramebuffer(renderer, source)) 2212 2242 { 2213 2243 glReadPixels(0, 0, source->base_w, source->base_h, format, GL_UNSIGNED_BYTE, pixels); ··· 2225 2255 2226 2256 if(source == NULL) 2227 2257 return 0; 2228 - 2258 + 2229 2259 // No glGetTexImage() in OpenGLES 2230 2260 #ifdef SDL_GPU_USE_GLES 2231 2261 // Load up the target ··· 2265 2295 2266 2296 if(isCurrentTarget(renderer, target)) 2267 2297 renderer->impl->FlushBlitBuffer(renderer); 2268 - 2298 + 2269 2299 bytes_per_pixel = 4; 2270 2300 if(target->image != NULL) 2271 2301 bytes_per_pixel = target->image->bytes_per_pixel; 2272 2302 data = (unsigned char*)SDL_malloc(target->base_w * target->base_h * bytes_per_pixel); 2273 - 2303 + 2274 2304 // This can take regions of pixels, so using base_w and base_h with an image target should be fine. 2275 2305 if(!readTargetPixels(renderer, target, ((GPU_TARGET_DATA*)target->data)->format, data)) 2276 2306 { 2277 2307 SDL_free(data); 2278 2308 return NULL; 2279 2309 } 2280 - 2310 + 2281 2311 // Flip the data vertically (OpenGL framebuffer is read upside down) 2282 2312 pitch = target->base_w * bytes_per_pixel; 2283 2313 copy = (unsigned char*)SDL_malloc(pitch); 2284 - 2314 + 2285 2315 for(y = 0; y < target->base_h/2; y++) 2286 2316 { 2287 2317 unsigned char* top = &data[target->base_w * y * bytes_per_pixel]; ··· 2301 2331 2302 2332 if(image->target != NULL && isCurrentTarget(renderer, image->target)) 2303 2333 renderer->impl->FlushBlitBuffer(renderer); 2304 - 2334 + 2305 2335 data = (unsigned char*)SDL_malloc(image->texture_w * image->texture_h * image->bytes_per_pixel); 2306 - 2336 + 2307 2337 // FIXME: Sometimes the texture is stored and read in RGBA even when I specify RGB. getRawImageData() might need to return the stored format or Bpp. 2308 2338 if(!readImagePixels(renderer, image, ((GPU_IMAGE_DATA*)image->data)->format, data)) 2309 2339 { ··· 2358 2388 return 0; 2359 2389 } 2360 2390 } 2361 - 2391 + 2362 2392 switch(format) 2363 2393 { 2364 2394 case GPU_FILE_PNG: ··· 2404 2434 GPU_PushErrorCode("GPU_CopySurfaceFromTarget", GPU_ERROR_BACKEND_ERROR, "Could not retrieve target data."); 2405 2435 return NULL; 2406 2436 } 2407 - 2437 + 2408 2438 format = AllocFormat(((GPU_TARGET_DATA*)target->data)->format); 2409 - 2410 - result = SDL_CreateRGBSurfaceFrom(data, target->base_w, target->base_h, format->BitsPerPixel, target->base_w*format->BytesPerPixel, format->Rmask, format->Gmask, format->Bmask, format->Amask); 2411 - if(result != NULL) 2412 - result->flags &= ~SDL_PREALLOC; // Make SDL take ownership of the data memory 2413 - 2439 + 2440 + result = SDL_CreateRGBSurface(SDL_SWSURFACE, target->base_w, target->base_h, format->BitsPerPixel, format->Rmask, format->Gmask, format->Bmask, format->Amask); 2441 + 2442 + if(result == NULL) 2443 + { 2444 + GPU_PushErrorCode("GPU_CopySurfaceFromTarget", GPU_ERROR_DATA_ERROR, "Failed to create new %dx%d surface", target->base_w, target->base_h); 2445 + SDL_free(data); 2446 + return NULL; 2447 + } 2448 + 2449 + // Copy row-by-row in case the pitch doesn't match 2450 + { 2451 + int i; 2452 + int source_pitch = target->base_w*format->BytesPerPixel; 2453 + for(i = 0; i < target->base_h; ++i) 2454 + { 2455 + memcpy((Uint8*)result->pixels + i*result->pitch, data + source_pitch*i, source_pitch); 2456 + } 2457 + } 2458 + 2459 + SDL_free(data); 2460 + 2414 2461 FreeFormat(format); 2415 2462 return result; 2416 2463 } ··· 2439 2486 GPU_PushErrorCode("GPU_CopySurfaceFromImage", GPU_ERROR_BACKEND_ERROR, "Could not retrieve target data."); 2440 2487 return NULL; 2441 2488 } 2442 - 2489 + 2443 2490 format = AllocFormat(((GPU_IMAGE_DATA*)image->data)->format); 2444 - 2445 - result = SDL_CreateRGBSurfaceFrom(data, image->texture_w, image->texture_h, format->BitsPerPixel, image->base_w*format->BytesPerPixel, format->Rmask, format->Gmask, format->Bmask, format->Amask); 2446 - if(result != NULL) 2447 - result->flags &= ~SDL_PREALLOC; // Make SDL take ownership of the data memory 2448 - 2491 + 2492 + result = SDL_CreateRGBSurface(SDL_SWSURFACE, image->texture_w, image->texture_h, format->BitsPerPixel, format->Rmask, format->Gmask, format->Bmask, format->Amask); 2493 + 2494 + if(result == NULL) 2495 + { 2496 + GPU_PushErrorCode("GPU_CopySurfaceFromImage", GPU_ERROR_DATA_ERROR, "Failed to create new %dx%d surface", image->texture_w, image->texture_h); 2497 + SDL_free(data); 2498 + return NULL; 2499 + } 2500 + 2501 + // Copy row-by-row in case the pitch doesn't match 2502 + { 2503 + int i; 2504 + int source_pitch = image->texture_w*format->BytesPerPixel; 2505 + for(i = 0; i < image->texture_h; ++i) 2506 + { 2507 + memcpy((Uint8*)result->pixels + i*result->pitch, data + source_pitch*i, source_pitch); 2508 + } 2509 + } 2510 + 2511 + SDL_free(data); 2512 + 2449 2513 FreeFormat(format); 2450 2514 return result; 2451 2515 } ··· 2733 2797 SDL_free(format); 2734 2798 } 2735 2799 2736 - // Returns NULL on failure. Returns the original surface if no copy is needed. Returns a new surface converted to the right format otherwise. 2737 - static SDL_Surface* copySurfaceIfNeeded(GPU_Renderer* renderer, GLenum glFormat, SDL_Surface* surface, GLenum* surfaceFormatResult) 2738 - { 2739 2800 #ifdef SDL_GPU_USE_GLES 2740 - SDL_Surface* newSurface; 2741 - Uint8 *blob; 2742 - SDL_Rect rect; 2743 - int srcPitch; 2801 + // Based on SDL_UpdateTexture() 2802 + static SDL_Surface* pack_surface_if_needed(SDL_Surface* surface) 2803 + { 2804 + SDL_Surface* result; 2805 + int width, height; 2806 + int packed_pitch; 2744 2807 int pitch; 2745 - #endif 2746 2808 2747 - // If format doesn't match, we need to do a copy 2748 - int format_compare = compareFormats(renderer, glFormat, surface, surfaceFormatResult); 2809 + // NULL or already packed? 2810 + if(surface == NULL || surface->pitch == surface->w * surface->format->BytesPerPixel) 2811 + return surface; 2749 2812 2750 - // There's a problem 2751 - if(format_compare < 0) 2752 - return NULL; 2753 - 2754 - #ifdef SDL_GPU_USE_GLES 2755 - // GLES needs a tightly-packed pixel array 2756 - // Based on SDL_UpdateTexture() 2757 - newSurface = NULL; 2758 - blob = NULL; 2759 - rect.x = 0; 2760 - rect.y = 0; 2761 - rect.w = surface->w; 2762 - rect.h = surface->h; 2763 - srcPitch = rect.w * surface->format->BytesPerPixel; 2813 + width = surface->w; 2814 + height = surface->h; 2815 + packed_pitch = width * surface->format->BytesPerPixel; 2764 2816 pitch = surface->pitch; 2765 - if(srcPitch != pitch) 2817 + 2818 + // Bail out if we're supposed to update an empty rectangle 2819 + if(width <= 0 || height <= 0) 2820 + return NULL; 2821 + 2822 + // Reformat the data into a tightly packed array 2823 + result = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, surface->format->BytesPerPixel, surface->format->Rmask, surface->format->Gmask, surface->format->Bmask, surface->format->Amask); 2824 + 2825 + if(result == NULL) 2766 2826 { 2767 - Uint8 *src; 2768 - Uint8 *pixels = (Uint8*)surface->pixels; 2769 - int y; 2770 - 2771 - /* Bail out if we're supposed to update an empty rectangle */ 2772 - if(rect.w <= 0 || rect.h <= 0) 2773 - return NULL; 2774 - 2775 - /* Reformat the texture data into a tightly packed array */ 2776 - src = pixels; 2777 - if(pitch != srcPitch) 2778 - { 2779 - blob = (Uint8*)SDL_malloc(srcPitch * rect.h); 2780 - if(blob == NULL) 2781 - { 2782 - // Out of memory 2783 - return NULL; 2784 - } 2785 - src = blob; 2786 - for(y = 0; y < rect.h; ++y) 2787 - { 2788 - memcpy(src, pixels, srcPitch); 2789 - src += srcPitch; 2790 - pixels += pitch; 2791 - } 2792 - src = blob; 2793 - } 2794 - 2795 - newSurface = SDL_CreateRGBSurfaceFrom(src, rect.w, rect.h, surface->format->BytesPerPixel, srcPitch, surface->format->Rmask, surface->format->Gmask, surface->format->Bmask, surface->format->Amask); 2796 - if(newSurface != NULL) 2797 - newSurface->flags &= ~SDL_PREALLOC; // Make SDL take ownership of the src memory 2827 + GPU_PushErrorCode(__func__, GPU_ERROR_DATA_ERROR, "Failed to create new %dx%d surface", width, height); 2828 + return NULL; 2798 2829 } 2799 - 2800 - // Copy it to a different format 2801 - if(format_compare > 0) 2830 + 2831 + // Force a new pitch in spite of SDL's alignment calculations 2832 + result->pitch = packed_pitch; 2833 + 2834 + // Copy to the new surface 2802 2835 { 2803 - // Convert to the right format 2804 - SDL_PixelFormat* dst_fmt = AllocFormat(glFormat); 2805 - if(newSurface != NULL) 2836 + int i; 2837 + for(i = 0; i < width; ++i) 2806 2838 { 2807 - surface = SDL_ConvertSurface(newSurface, dst_fmt, 0); 2808 - SDL_FreeSurface(newSurface); 2809 - SDL_free(blob); 2839 + memcpy((Uint8*)result->pixels + i*packed_pitch, surface->pixels + surface->pitch*i, packed_pitch); 2810 2840 } 2811 - else 2812 - surface = SDL_ConvertSurface(surface, dst_fmt, 0); 2813 - FreeFormat(dst_fmt); 2814 - if(surfaceFormatResult != NULL && surface != NULL) 2815 - *surfaceFormatResult = glFormat; 2816 2841 } 2817 - 2818 - #else 2842 + 2843 + return result; 2844 + } 2845 + #endif 2846 + 2847 + // Returns NULL on failure. Returns the original surface if no copy is needed. Returns a new surface converted to the right format otherwise. 2848 + static SDL_Surface* copySurfaceIfNeeded(GPU_Renderer* renderer, GLenum glFormat, SDL_Surface* surface, GLenum* surfaceFormatResult) 2849 + { 2850 + #ifdef SDL_GPU_USE_GLES 2851 + SDL_Surface* original = surface; 2852 + #endif 2853 + 2854 + // If format doesn't match, we need to do a copy 2855 + int format_compare = compareFormats(renderer, glFormat, surface, surfaceFormatResult); 2856 + 2857 + // There's a problem, logged in compareFormats() 2858 + if(format_compare < 0) 2859 + return NULL; 2860 + 2861 + 2819 2862 // Copy it to a different format 2820 2863 if(format_compare > 0) 2821 2864 { ··· 2825 2868 FreeFormat(dst_fmt); 2826 2869 if(surfaceFormatResult != NULL && surface != NULL) 2827 2870 *surfaceFormatResult = glFormat; 2871 + } 2872 + 2873 + #ifdef SDL_GPU_USE_GLES 2874 + // GLES needs a tightly-packed pixel array 2875 + { 2876 + SDL_Surface* intermediate_surface = surface; 2877 + surface = pack_surface_if_needed(intermediate_surface); 2878 + 2879 + // Delete the intermediate surface since it won't be used. 2880 + if(intermediate_surface != surface && intermediate_surface != original) 2881 + SDL_FreeSurface(intermediate_surface); 2828 2882 } 2829 2883 #endif 2830 2884 ··· 2838 2892 2839 2893 if(image == NULL) 2840 2894 return NULL; 2841 - 2895 + 2842 2896 switch(image->format) 2843 2897 { 2844 2898 case GPU_FORMAT_RGB: ··· 2846 2900 // Copy via framebuffer blitting (fast) 2847 2901 { 2848 2902 GPU_Target* target; 2849 - 2903 + 2850 2904 result = renderer->impl->CreateImage(renderer, image->texture_w, image->texture_h, image->format); 2851 2905 if(result == NULL) 2852 2906 { 2853 2907 GPU_PushErrorCode("GPU_CopyImage", GPU_ERROR_BACKEND_ERROR, "Failed to create new image."); 2854 2908 return NULL; 2855 2909 } 2856 - 2910 + 2857 2911 target = GPU_LoadTarget(result); 2858 2912 if(target == NULL) 2859 2913 { ··· 2861 2915 GPU_PushErrorCode("GPU_CopyImage", GPU_ERROR_BACKEND_ERROR, "Failed to load target."); 2862 2916 return NULL; 2863 2917 } 2864 - 2918 + 2865 2919 // For some reason, I wasn't able to get glCopyTexImage2D() or glCopyTexSubImage2D() working without getting GL_INVALID_ENUM (0x500). 2866 2920 // It seemed to only work for the default framebuffer... 2867 - 2921 + 2868 2922 { 2869 2923 // Clear the color, blending, and filter mode 2870 2924 SDL_Color color = image->color; ··· 2893 2947 GPU_SetImageVirtualResolution(image, w, h); 2894 2948 } 2895 2949 } 2896 - 2950 + 2897 2951 // Don't free the target yet (a waste of perf), but let it be freed next time... 2898 2952 target->refcount--; 2899 2953 } ··· 2913 2967 GPU_PushErrorCode("GPU_CopyImage", GPU_ERROR_BACKEND_ERROR, "Failed to get raw texture data."); 2914 2968 return NULL; 2915 2969 } 2916 - 2970 + 2917 2971 result = CreateUninitializedImage(renderer, image->texture_w, image->texture_h, image->format); 2918 2972 if(result == NULL) 2919 2973 { ··· 2921 2975 GPU_PushErrorCode("GPU_CopyImage", GPU_ERROR_BACKEND_ERROR, "Failed to create new image."); 2922 2976 return NULL; 2923 2977 } 2924 - 2978 + 2925 2979 changeTexturing(renderer, 1); 2926 2980 bindTexture(renderer, result); 2927 2981 ··· 2935 2989 if(!isPowerOfTwo(h)) 2936 2990 h = getNearestPowerOf2(h); 2937 2991 } 2938 - 2992 + 2939 2993 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 2940 2994 #ifdef SDL_GPU_USE_OPENGL 2941 2995 glPixelStorei(GL_UNPACK_ROW_LENGTH, w); 2942 2996 #endif 2943 - 2997 + 2944 2998 glTexImage2D(GL_TEXTURE_2D, 0, internal_format, w, h, 0, 2945 2999 internal_format, GL_UNSIGNED_BYTE, texture_data); 2946 3000 // Tell SDL_gpu what we got. 2947 3001 result->texture_w = w; 2948 3002 result->texture_h = h; 2949 - 3003 + 2950 3004 // Restore GL defaults 2951 3005 glPixelStorei(GL_UNPACK_ALIGNMENT, 4); 2952 3006 #ifdef SDL_GPU_USE_OPENGL 2953 3007 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); 2954 3008 #endif 2955 - 3009 + 2956 3010 SDL_free(texture_data); 2957 3011 } 2958 3012 break; ··· 2960 3014 GPU_PushErrorCode("GPU_CopyImage", GPU_ERROR_BACKEND_ERROR, "Could not copy the given image format."); 2961 3015 break; 2962 3016 } 2963 - 3017 + 2964 3018 if(result != NULL) 2965 3019 { 2966 3020 // Copy the image settings ··· 2975 3029 if(image->using_virtual_resolution) 2976 3030 GPU_SetImageVirtualResolution(result, image->w, image->h); 2977 3031 } 2978 - 3032 + 2979 3033 return result; 2980 3034 } 2981 3035 ··· 3022 3076 updateRect.w += image->base_w - (updateRect.x + updateRect.w); 3023 3077 if(updateRect.y + updateRect.h > image->base_h) 3024 3078 updateRect.h += image->base_h - (updateRect.y + updateRect.h); 3025 - 3079 + 3026 3080 if(updateRect.w <= 0) 3027 3081 updateRect.w = 0; 3028 3082 if(updateRect.h <= 0) ··· 3040 3094 return; 3041 3095 } 3042 3096 } 3043 - 3097 + 3044 3098 if(surface_rect != NULL) 3045 3099 { 3046 3100 sourceRect = *surface_rect; ··· 3058 3112 sourceRect.w += newSurface->w - (sourceRect.x + sourceRect.w); 3059 3113 if(sourceRect.y + sourceRect.h > newSurface->h) 3060 3114 sourceRect.h += newSurface->h - (sourceRect.y + sourceRect.h); 3061 - 3115 + 3062 3116 if(sourceRect.w <= 0) 3063 3117 sourceRect.w = 0; 3064 3118 if(sourceRect.h <= 0) ··· 3084 3138 #ifdef SDL_GPU_USE_OPENGL 3085 3139 glPixelStorei(GL_UNPACK_ROW_LENGTH, (newSurface->pitch / newSurface->format->BytesPerPixel)); 3086 3140 #endif 3087 - 3141 + 3088 3142 // Use the smaller of the image and surface rect dimensions 3089 3143 if(sourceRect.w < updateRect.w) 3090 3144 updateRect.w = sourceRect.w; 3091 3145 if(sourceRect.h < updateRect.h) 3092 3146 updateRect.h = sourceRect.h; 3093 - 3147 + 3094 3148 pixels = (Uint8*)newSurface->pixels; 3095 3149 // Shift the pixels pointer to the proper source position 3096 3150 pixels += (int)(newSurface->pitch * sourceRect.y + (newSurface->format->BytesPerPixel)*sourceRect.x); 3097 - 3151 + 3098 3152 glTexSubImage2D(GL_TEXTURE_2D, 0, 3099 3153 updateRect.x, updateRect.y, updateRect.w, updateRect.h, 3100 3154 original_format, GL_UNSIGNED_BYTE, pixels); ··· 3102 3156 // Delete temporary surface 3103 3157 if(surface != newSurface) 3104 3158 SDL_FreeSurface(newSurface); 3105 - 3159 + 3106 3160 // Restore GL defaults 3107 3161 glPixelStorei(GL_UNPACK_ALIGNMENT, 4); 3108 3162 #ifdef SDL_GPU_USE_OPENGL ··· 3142 3196 updateRect.w += image->base_w - (updateRect.x + updateRect.w); 3143 3197 if(updateRect.y + updateRect.h > image->base_h) 3144 3198 updateRect.h += image->base_h - (updateRect.y + updateRect.h); 3145 - 3199 + 3146 3200 if(updateRect.w <= 0) 3147 3201 updateRect.w = 0; 3148 3202 if(updateRect.h <= 0) ··· 3173 3227 #ifdef SDL_GPU_USE_OPENGL 3174 3228 glPixelStorei(GL_UNPACK_ROW_LENGTH, (bytes_per_row / image->bytes_per_pixel)); 3175 3229 #endif 3176 - 3230 + 3177 3231 glTexSubImage2D(GL_TEXTURE_2D, 0, 3178 3232 updateRect.x, updateRect.y, updateRect.w, updateRect.h, 3179 3233 original_format, GL_UNSIGNED_BYTE, bytes); 3180 - 3234 + 3181 3235 // Restore GL defaults 3182 3236 glPixelStorei(GL_UNPACK_ALIGNMENT, 4); 3183 3237 #ifdef SDL_GPU_USE_OPENGL ··· 3202 3256 GPU_PushErrorCode("GPU_ReplaceImage", GPU_ERROR_NULL_ARGUMENT, "image"); 3203 3257 return 0; 3204 3258 } 3205 - 3259 + 3206 3260 if(surface == NULL) 3207 3261 { 3208 3262 GPU_PushErrorCode("GPU_ReplaceImage", GPU_ERROR_NULL_ARGUMENT, "surface"); 3209 3263 return 0; 3210 3264 } 3211 - 3265 + 3212 3266 data = (GPU_IMAGE_DATA*)image->data; 3213 3267 internal_format = data->format; 3214 3268 ··· 3218 3272 GPU_PushErrorCode("GPU_ReplaceImage", GPU_ERROR_BACKEND_ERROR, "Failed to convert surface to proper pixel format."); 3219 3273 return 0; 3220 3274 } 3221 - 3275 + 3222 3276 // Free the attached framebuffer 3223 3277 if((renderer->enabled_features & GPU_FEATURE_RENDER_TARGETS) && image->target != NULL) 3224 3278 { ··· 3229 3283 glDeleteFramebuffers(1, &tdata->handle); 3230 3284 tdata->handle = 0; 3231 3285 } 3232 - 3286 + 3233 3287 // Free the old texture 3234 3288 if(data->owns_handle) 3235 3289 glDeleteTextures( 1, &data->handle); 3236 3290 data->handle = 0; 3237 - 3291 + 3238 3292 // Get the area of the surface we'll use 3239 3293 if(surface_rect == NULL) 3240 3294 { ··· 3245 3299 } 3246 3300 else 3247 3301 sourceRect = *surface_rect; 3248 - 3302 + 3249 3303 // Clip the source rect to the surface 3250 3304 if(sourceRect.x < 0) 3251 3305 { ··· 3261 3315 sourceRect.x = surface->w - 1; 3262 3316 if(sourceRect.y >= surface->h) 3263 3317 sourceRect.y = surface->h - 1; 3264 - 3318 + 3265 3319 if(sourceRect.x + sourceRect.w > surface->w) 3266 3320 sourceRect.w = surface->w - sourceRect.x; 3267 3321 if(sourceRect.y + sourceRect.h > surface->h) 3268 3322 sourceRect.h = surface->h - sourceRect.y; 3269 - 3323 + 3270 3324 if(sourceRect.w <= 0 || sourceRect.h <= 0) 3271 3325 { 3272 3326 GPU_PushErrorCode("GPU_ReplaceImage", GPU_ERROR_DATA_ERROR, "Clipped source rect has zero size."); 3273 3327 return 0; 3274 3328 } 3275 - 3329 + 3276 3330 // Allocate new texture 3277 3331 data->handle = CreateUninitializedTexture(renderer); 3278 3332 data->owns_handle = 1; ··· 3281 3335 GPU_PushErrorCode("GPU_ReplaceImage", GPU_ERROR_BACKEND_ERROR, "Failed to create a new texture handle."); 3282 3336 return 0; 3283 3337 } 3284 - 3338 + 3285 3339 // Update image members 3286 3340 w = sourceRect.w; 3287 3341 h = sourceRect.h; 3288 - 3342 + 3289 3343 if(!image->using_virtual_resolution) 3290 3344 { 3291 3345 image->w = w; ··· 3293 3347 } 3294 3348 image->base_w = w; 3295 3349 image->base_h = h; 3296 - 3350 + 3297 3351 if(!(renderer->enabled_features & GPU_FEATURE_NON_POWER_OF_TWO)) 3298 3352 { 3299 3353 if(!isPowerOfTwo(w)) ··· 3303 3357 } 3304 3358 image->texture_w = w; 3305 3359 image->texture_h = h; 3306 - 3360 + 3307 3361 image->has_mipmaps = 0; 3308 - 3309 - 3362 + 3363 + 3310 3364 // Upload surface pixel data 3311 3365 alignment = 8; 3312 3366 while(newSurface->pitch % alignment) ··· 3315 3369 #ifdef SDL_GPU_USE_OPENGL 3316 3370 glPixelStorei(GL_UNPACK_ROW_LENGTH, (newSurface->pitch / newSurface->format->BytesPerPixel)); 3317 3371 #endif 3318 - 3372 + 3319 3373 pixels = (Uint8*)newSurface->pixels; 3320 3374 // Shift the pixels pointer to the proper source position 3321 3375 pixels += (int)(newSurface->pitch * sourceRect.y + (newSurface->format->BytesPerPixel)*sourceRect.x); 3322 - 3376 + 3323 3377 glTexImage2D(GL_TEXTURE_2D, 0, internal_format, w, h, 0, 3324 3378 internal_format, GL_UNSIGNED_BYTE, pixels); 3325 3379 3326 3380 // Delete temporary surface 3327 3381 if(surface != newSurface) 3328 3382 SDL_FreeSurface(newSurface); 3329 - 3383 + 3330 3384 // Restore GL defaults 3331 3385 glPixelStorei(GL_UNPACK_ALIGNMENT, 4); 3332 3386 #ifdef SDL_GPU_USE_OPENGL 3333 3387 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); 3334 3388 #endif 3335 - 3336 - 3337 - 3389 + 3390 + 3391 + 3338 3392 // Update target members 3339 3393 if((renderer->enabled_features & GPU_FEATURE_RENDER_TARGETS) && image->target != NULL) 3340 3394 { 3341 3395 GLenum status; 3342 3396 GPU_Target* target = image->target; 3343 3397 GPU_TARGET_DATA* tdata = (GPU_TARGET_DATA*)target->data; 3344 - 3398 + 3345 3399 // Create framebuffer object 3346 3400 glGenFramebuffers(1, &tdata->handle); 3347 3401 if(tdata->handle == 0) ··· 3349 3403 GPU_PushErrorCode("GPU_ReplaceImage", GPU_ERROR_BACKEND_ERROR, "Failed to create new framebuffer target."); 3350 3404 return 0; 3351 3405 } 3352 - 3406 + 3353 3407 flushAndBindFramebuffer(renderer, tdata->handle); 3354 3408 3355 3409 // Attach the texture to it ··· 3361 3415 GPU_PushErrorCode("GPU_ReplaceImage", GPU_ERROR_BACKEND_ERROR, "Failed to recreate framebuffer target."); 3362 3416 return 0; 3363 3417 } 3364 - 3418 + 3365 3419 if(!target->using_virtual_resolution) 3366 3420 { 3367 3421 target->w = image->base_w; ··· 3369 3423 } 3370 3424 target->base_w = image->texture_w; 3371 3425 target->base_h = image->texture_h; 3372 - 3426 + 3373 3427 // Reset viewport? 3374 3428 target->viewport = GPU_MakeRect(0, 0, target->w, target->h); 3375 3429 } ··· 3442 3496 } 3443 3497 else 3444 3498 format = GPU_FORMAT_RGBA; 3445 - 3499 + 3446 3500 image = renderer->impl->CreateImage(renderer, surface->w, surface->h, format); 3447 3501 if(image == NULL) 3448 3502 return NULL; ··· 3460 3514 3461 3515 if(target == NULL) 3462 3516 return NULL; 3463 - 3517 + 3464 3518 surface = renderer->impl->CopySurfaceFromTarget(renderer, target); 3465 3519 image = renderer->impl->CopyImageFromSurface(renderer, surface); 3466 3520 SDL_FreeSurface(surface); 3467 - 3521 + 3468 3522 return image; 3469 3523 } 3470 3524 ··· 3475 3529 3476 3530 if(image == NULL) 3477 3531 return; 3478 - 3532 + 3479 3533 if(image->refcount > 1) 3480 3534 { 3481 3535 image->refcount--; ··· 3491 3545 } 3492 3546 3493 3547 flushAndClearBlitBufferIfCurrentTexture(renderer, image); 3494 - 3548 + 3495 3549 // Does the renderer data need to be freed too? 3496 3550 data = (GPU_IMAGE_DATA*)image->data; 3497 3551 if(data->refcount > 1) ··· 3504 3558 glDeleteTextures( 1, &data->handle); 3505 3559 SDL_free(data); 3506 3560 } 3507 - 3561 + 3508 3562 SDL_free(image); 3509 3563 } 3510 3564 ··· 3549 3603 result->data = data; 3550 3604 data->handle = handle; 3551 3605 data->format = ((GPU_IMAGE_DATA*)image->data)->format; 3552 - 3606 + 3553 3607 result->renderer = renderer; 3554 3608 result->context = NULL; 3555 3609 result->image = image; ··· 3558 3612 result->base_w = image->texture_w; 3559 3613 result->base_h = image->texture_h; 3560 3614 result->using_virtual_resolution = image->using_virtual_resolution; 3561 - 3615 + 3562 3616 result->viewport = GPU_MakeRect(0, 0, result->w, result->h); 3563 - 3617 + 3564 3618 result->camera = GPU_GetDefaultCamera(); 3565 - 3619 + 3566 3620 result->use_clip_rect = 0; 3567 3621 result->clip_rect.x = 0; 3568 3622 result->clip_rect.y = 0; ··· 3582 3636 3583 3637 if(target == NULL) 3584 3638 return; 3585 - 3639 + 3586 3640 if(target->refcount > 1) 3587 3641 { 3588 3642 target->refcount--; 3589 3643 return; 3590 3644 } 3591 - 3645 + 3592 3646 if(target->context != NULL && target->context->failed) 3593 3647 { 3594 3648 GPU_CONTEXT_DATA* cdata = (GPU_CONTEXT_DATA*)target->context->data; 3595 - 3649 + 3596 3650 if(target == renderer->current_context_target) 3597 3651 renderer->current_context_target = NULL; 3598 - 3652 + 3599 3653 SDL_free(cdata->blit_buffer); 3600 3654 SDL_free(cdata->index_buffer); 3601 - 3655 + 3602 3656 #ifdef SDL_GPU_USE_SDL2 3603 3657 if(target->context->context != 0) 3604 3658 SDL_GL_DeleteContext(target->context->context); 3605 3659 #endif 3606 - 3660 + 3607 3661 // Remove all of the window mappings that refer to this target 3608 3662 GPU_RemoveWindowMappingByTarget(target); 3609 - 3663 + 3610 3664 SDL_free(target->context->data); 3611 3665 SDL_free(target->context); 3612 - 3666 + 3613 3667 // Does the renderer data need to be freed too? 3614 3668 data = ((GPU_TARGET_DATA*)target->data); 3615 - 3669 + 3616 3670 SDL_free(data); 3617 3671 SDL_free(target); 3618 - 3672 + 3619 3673 return; 3620 3674 } 3621 - 3675 + 3622 3676 if(target == renderer->current_context_target) 3623 3677 { 3624 3678 renderer->impl->FlushBlitBuffer(renderer); 3625 3679 renderer->current_context_target = NULL; 3626 3680 } 3627 - 3681 + 3628 3682 if(!target->is_alias && target->image != NULL) 3629 3683 target->image->target = NULL; // Remove reference to this object 3630 - 3684 + 3631 3685 3632 3686 // Does the renderer data need to be freed too? 3633 3687 data = ((GPU_TARGET_DATA*)target->data); ··· 3637 3691 SDL_free(target); 3638 3692 return; 3639 3693 } 3640 - 3694 + 3641 3695 if(renderer->enabled_features & GPU_FEATURE_RENDER_TARGETS) 3642 3696 { 3643 3697 if(renderer->current_context_target != NULL) ··· 3645 3699 if(data->handle != 0) 3646 3700 glDeleteFramebuffers(1, &data->handle); 3647 3701 } 3648 - 3702 + 3649 3703 if(target->context != NULL) 3650 3704 { 3651 3705 GPU_CONTEXT_DATA* cdata = (GPU_CONTEXT_DATA*)target->context->data; 3652 - 3706 + 3653 3707 SDL_free(cdata->blit_buffer); 3654 3708 SDL_free(cdata->index_buffer); 3655 - 3709 + 3656 3710 #ifdef SDL_GPU_USE_BUFFER_PIPELINE 3657 3711 glDeleteBuffers(2, cdata->blit_VBO); 3658 3712 glDeleteBuffers(1, &cdata->blit_IBO); ··· 3661 3715 glDeleteVertexArrays(1, &cdata->blit_VAO); 3662 3716 #endif 3663 3717 #endif 3664 - 3718 + 3665 3719 #ifdef SDL_GPU_USE_SDL2 3666 3720 if(target->context->context != 0) 3667 3721 SDL_GL_DeleteContext(target->context->context); 3668 3722 #endif 3669 - 3723 + 3670 3724 // Remove all of the window mappings that refer to this target 3671 3725 GPU_RemoveWindowMappingByTarget(target); 3672 - 3726 + 3673 3727 SDL_free(target->context->data); 3674 3728 SDL_free(target->context); 3675 3729 target->context = NULL; 3676 3730 } 3677 - 3731 + 3678 3732 SDL_free(data); 3679 3733 SDL_free(target); 3680 3734 } ··· 3709 3763 vert_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; \ 3710 3764 tex_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; \ 3711 3765 color_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 3712 - 3766 + 3713 3767 #define SET_UNTEXTURED_VERTEX(x, y, r, g, b, a) \ 3714 3768 blit_buffer[vert_index] = x; \ 3715 3769 blit_buffer[vert_index+1] = y; \ ··· 3720 3774 index_buffer[cdata->index_buffer_num_vertices++] = cdata->blit_buffer_num_vertices++; \ 3721 3775 vert_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; \ 3722 3776 color_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 3723 - 3777 + 3724 3778 #define SET_UNTEXTURED_VERTEX_UNINDEXED(x, y, r, g, b, a) \ 3725 3779 blit_buffer[vert_index] = x; \ 3726 3780 blit_buffer[vert_index+1] = y; \ ··· 3736 3790 3737 3791 #define SET_RELATIVE_INDEXED_VERTEX(offset) \ 3738 3792 index_buffer[cdata->index_buffer_num_vertices++] = cdata->blit_buffer_num_vertices + (offset); 3739 - 3793 + 3740 3794 3741 3795 3742 3796 #define BEGIN_UNTEXTURED_SEGMENTS(x1, y1, x2, y2, r, g, b, a) \ ··· 3798 3852 GPU_PushErrorCode("GPU_Blit", GPU_ERROR_USER_ERROR, "Mismatched renderer"); 3799 3853 return; 3800 3854 } 3801 - 3855 + 3802 3856 makeContextCurrent(renderer, target); 3803 3857 if(renderer->current_context_target == NULL) 3804 3858 { 3805 3859 GPU_PushErrorCode("GPU_Blit", GPU_ERROR_USER_ERROR, "NULL context"); 3806 3860 return; 3807 3861 } 3808 - 3862 + 3809 3863 prepareToRenderToTarget(renderer, target); 3810 3864 prepareToRenderImage(renderer, target, image); 3811 3865 ··· 3818 3872 GPU_PushErrorCode("GPU_Blit", GPU_ERROR_BACKEND_ERROR, "Failed to bind framebuffer."); 3819 3873 return; 3820 3874 } 3821 - 3875 + 3822 3876 tex_w = image->texture_w; 3823 3877 tex_h = image->texture_h; 3824 - 3878 + 3825 3879 if(image->snap_mode == GPU_SNAP_POSITION || image->snap_mode == GPU_SNAP_POSITION_AND_DIMENSIONS) 3826 3880 { 3827 3881 // Avoid rounding errors in texture sampling by insisting on integral pixel positions 3828 3882 x = floorf(x); 3829 3883 y = floorf(y); 3830 3884 } 3831 - 3885 + 3832 3886 if(src_rect == NULL) 3833 3887 { 3834 3888 // Scale tex coords according to actual texture dims ··· 3849 3903 w = src_rect->w; 3850 3904 h = src_rect->h; 3851 3905 } 3852 - 3906 + 3853 3907 if(image->using_virtual_resolution) 3854 3908 { 3855 3909 // Scale texture coords to fit the original dims ··· 3858 3912 x2 *= image->base_w/(float)image->w; 3859 3913 y2 *= image->base_h/(float)image->h; 3860 3914 } 3861 - 3915 + 3862 3916 // Center the image on the given coords 3863 3917 dx1 = x - w/2.0f; 3864 3918 dy1 = y - h/2.0f; 3865 3919 dx2 = x + w/2.0f; 3866 3920 dy2 = y + h/2.0f; 3867 - 3921 + 3868 3922 if(image->snap_mode == GPU_SNAP_DIMENSIONS || image->snap_mode == GPU_SNAP_POSITION_AND_DIMENSIONS) 3869 3923 { 3870 3924 float fractional; ··· 3875 3929 dy1 += fractional; 3876 3930 dy2 += fractional; 3877 3931 } 3878 - 3932 + 3879 3933 if(renderer->coordinate_mode == 1) 3880 3934 { 3881 3935 float temp = dy1; ··· 3895 3949 if(!growIndexBuffer(cdata, cdata->index_buffer_num_vertices + 6)) 3896 3950 renderer->impl->FlushBlitBuffer(renderer); 3897 3951 } 3898 - 3952 + 3899 3953 blit_buffer = cdata->blit_buffer; 3900 3954 index_buffer = cdata->index_buffer; 3901 3955 3902 3956 blit_buffer_starting_index = cdata->blit_buffer_num_vertices; 3903 - 3957 + 3904 3958 vert_index = GPU_BLIT_BUFFER_VERTEX_OFFSET + cdata->blit_buffer_num_vertices*GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 3905 3959 tex_index = GPU_BLIT_BUFFER_TEX_COORD_OFFSET + cdata->blit_buffer_num_vertices*GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 3906 3960 color_index = GPU_BLIT_BUFFER_COLOR_OFFSET + cdata->blit_buffer_num_vertices*GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; ··· 3918 3972 b = image->color.b/255.0f; 3919 3973 a = GET_ALPHA(image->color)/255.0f; 3920 3974 } 3921 - 3975 + 3922 3976 // 4 Quad vertices 3923 3977 SET_TEXTURED_VERTEX_UNINDEXED(dx1, dy1, x1, y1, r, g, b, a); 3924 3978 SET_TEXTURED_VERTEX_UNINDEXED(dx2, dy1, x2, y1, r, g, b, a); ··· 3951 4005 GPU_PushErrorCode("GPU_BlitRotate", GPU_ERROR_NULL_ARGUMENT, "target"); 3952 4006 return; 3953 4007 } 3954 - 4008 + 3955 4009 w = (src_rect == NULL? image->w : src_rect->w); 3956 4010 h = (src_rect == NULL? image->h : src_rect->h); 3957 4011 renderer->impl->BlitTransformX(renderer, image, src_rect, target, x, y, w/2.0f, h/2.0f, degrees, 1.0f, 1.0f); ··· 4028 4082 4029 4083 4030 4084 makeContextCurrent(renderer, target); 4031 - 4085 + 4032 4086 prepareToRenderToTarget(renderer, target); 4033 4087 prepareToRenderImage(renderer, target, image); 4034 - 4088 + 4035 4089 // Bind the texture to which subsequent calls refer 4036 4090 bindTexture(renderer, image); 4037 4091 ··· 4041 4095 GPU_PushErrorCode("GPU_BlitTransformX", GPU_ERROR_BACKEND_ERROR, "Failed to bind framebuffer."); 4042 4096 return; 4043 4097 } 4044 - 4098 + 4045 4099 tex_w = image->texture_w; 4046 4100 tex_h = image->texture_h; 4047 - 4101 + 4048 4102 if(image->snap_mode == GPU_SNAP_POSITION || image->snap_mode == GPU_SNAP_POSITION_AND_DIMENSIONS) 4049 4103 { 4050 4104 // Avoid rounding errors in texture sampling by insisting on integral pixel positions ··· 4078 4132 w = src_rect->w; 4079 4133 h = src_rect->h; 4080 4134 } 4081 - 4135 + 4082 4136 if(image->using_virtual_resolution) 4083 4137 { 4084 4138 // Scale texture coords to fit the original dims ··· 4087 4141 x2 *= image->base_w/(float)image->w; 4088 4142 y2 *= image->base_h/(float)image->h; 4089 4143 } 4090 - 4144 + 4091 4145 // Center the image on the given coords (offset later) 4092 4146 dx1 = -w/2.0f; 4093 4147 dy1 = -h/2.0f; 4094 4148 dx2 = w/2.0f; 4095 4149 dy2 = h/2.0f; 4096 - 4150 + 4097 4151 if(image->snap_mode == GPU_SNAP_DIMENSIONS || image->snap_mode == GPU_SNAP_POSITION_AND_DIMENSIONS) 4098 4152 { 4099 4153 // This is a little weird for rotating sprites, but oh well. ··· 4105 4159 dy1 += fractional; 4106 4160 dy2 += fractional; 4107 4161 } 4108 - 4162 + 4109 4163 if(renderer->coordinate_mode == 1) 4110 4164 { 4111 4165 float temp = dy1; ··· 4183 4237 if(!growIndexBuffer(cdata, cdata->index_buffer_num_vertices + 6)) 4184 4238 renderer->impl->FlushBlitBuffer(renderer); 4185 4239 } 4186 - 4240 + 4187 4241 blit_buffer = cdata->blit_buffer; 4188 4242 index_buffer = cdata->index_buffer; 4189 4243 4190 4244 blit_buffer_starting_index = cdata->blit_buffer_num_vertices; 4191 - 4245 + 4192 4246 vert_index = GPU_BLIT_BUFFER_VERTEX_OFFSET + cdata->blit_buffer_num_vertices*GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 4193 4247 tex_index = GPU_BLIT_BUFFER_TEX_COORD_OFFSET + cdata->blit_buffer_num_vertices*GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 4194 4248 color_index = GPU_BLIT_BUFFER_COLOR_OFFSET + cdata->blit_buffer_num_vertices*GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 4195 - 4249 + 4196 4250 if(target->use_color) 4197 4251 { 4198 4252 r = MIX_COLOR_COMPONENT_NORMALIZED_RESULT(target->color.r, image->color.r); ··· 4207 4261 b = image->color.b/255.0f; 4208 4262 a = GET_ALPHA(image->color)/255.0f; 4209 4263 } 4210 - 4264 + 4211 4265 // 4 Quad vertices 4212 4266 SET_TEXTURED_VERTEX_UNINDEXED(dx1, dy1, x1, y1, r, g, b, a); 4213 4267 SET_TEXTURED_VERTEX_UNINDEXED(dx3, dy3, x2, y1, r, g, b, a); ··· 4267 4321 storage_ptr = (void*)((char*)storage_ptr + a->per_vertex_storage_stride_bytes); 4268 4322 memcpy(storage_ptr, values_ptr, value_size_bytes); 4269 4323 storage_ptr = (void*)((char*)storage_ptr + a->per_vertex_storage_stride_bytes); 4270 - 4324 + 4271 4325 values_ptr = (void*)((char*)values_ptr + a->attribute.format.stride_bytes); 4272 4326 } 4273 4327 } ··· 4287 4341 4288 4342 if(a->num_values < num_values_used) 4289 4343 num_values_used = a->num_values; 4290 - 4344 + 4291 4345 glBindBuffer(GL_ARRAY_BUFFER, cdata->attribute_VBO[i]); 4292 - 4346 + 4293 4347 bytes_used = a->per_vertex_storage_stride_bytes * num_values_used; 4294 4348 glBufferData(GL_ARRAY_BUFFER, bytes_used, a->next_value, GL_STREAM_DRAW); 4295 - 4349 + 4296 4350 glEnableVertexAttribArray(a->attribute.location); 4297 4351 glVertexAttribPointer(a->attribute.location, a->attribute.format.num_elems_per_value, a->attribute.format.type, a->attribute.format.normalize, a->per_vertex_storage_stride_bytes, (void*)(intptr_t)a->per_vertex_storage_offset_bytes); 4298 - 4352 + 4299 4353 a->enabled = 1; 4300 4354 // Move the data along so we use the next values for the next flush 4301 4355 a->num_values -= num_values_used; ··· 4326 4380 static int get_lowest_attribute_num_values(GPU_CONTEXT_DATA* cdata, int cap) 4327 4381 { 4328 4382 int lowest = cap; 4329 - 4383 + 4330 4384 #ifdef SDL_GPU_USE_BUFFER_PIPELINE 4331 4385 int i; 4332 4386 for(i = 0; i < 16; i++) ··· 4339 4393 } 4340 4394 } 4341 4395 #endif 4342 - 4396 + 4343 4397 return lowest; 4344 4398 } 4345 4399 ··· 4375 4429 GPU_CONTEXT_DATA* cdata; 4376 4430 int stride, offset_texcoords, offset_colors; 4377 4431 int size_vertices, size_texcoords, size_colors; 4378 - 4432 + 4379 4433 Uint8 using_texture = (image != NULL); 4380 4434 Uint8 use_vertices = (flags & (GPU_BATCH_XY | GPU_BATCH_XYZ)); 4381 4435 Uint8 use_texcoords = (flags & GPU_BATCH_ST); 4382 4436 Uint8 use_colors = (flags & (GPU_BATCH_RGB | GPU_BATCH_RGBA)); 4383 4437 Uint8 use_z = (flags & GPU_BATCH_XYZ); 4384 4438 Uint8 use_a = (flags & GPU_BATCH_RGBA); 4385 - 4439 + 4386 4440 if(num_vertices == 0) 4387 4441 return; 4388 - 4442 + 4389 4443 if(target == NULL) 4390 4444 { 4391 4445 GPU_PushErrorCode("GPU_TriangleBatch", GPU_ERROR_NULL_ARGUMENT, "target"); ··· 4396 4450 GPU_PushErrorCode("GPU_TriangleBatch", GPU_ERROR_USER_ERROR, "Mismatched renderer"); 4397 4451 return; 4398 4452 } 4399 - 4453 + 4400 4454 makeContextCurrent(renderer, target); 4401 4455 4402 4456 // Bind the texture to which subsequent calls refer ··· 4409 4463 GPU_PushErrorCode("GPU_TriangleBatch", GPU_ERROR_BACKEND_ERROR, "Failed to bind framebuffer."); 4410 4464 return; 4411 4465 } 4412 - 4466 + 4413 4467 prepareToRenderToTarget(renderer, target); 4414 4468 if(using_texture) 4415 4469 prepareToRenderImage(renderer, target, image); ··· 4417 4471 prepareToRenderShapes(renderer, GL_TRIANGLES); 4418 4472 changeViewport(target); 4419 4473 changeCamera(target); 4420 - 4474 + 4421 4475 if(using_texture) 4422 4476 changeTexturing(renderer, 1); 4423 4477 4424 4478 setClipRect(renderer, target); 4425 - 4479 + 4426 4480 #ifdef SDL_GPU_APPLY_TRANSFORMS_TO_GL_STACK 4427 4481 if(!IsFeatureEnabled(renderer, GPU_FEATURE_VERTEX_SHADER)) 4428 4482 applyTransforms(); 4429 4483 #endif 4430 - 4484 + 4431 4485 4432 4486 cdata = (GPU_CONTEXT_DATA*)renderer->current_context_target->context->data; 4433 4487 ··· 4441 4495 { 4442 4496 growBlitBuffer(cdata, cdata->blit_buffer_num_vertices + num_vertices); 4443 4497 } 4444 - 4498 + 4445 4499 // Only need to check the blit buffer because of the VBO storage 4446 4500 if(cdata->blit_buffer_num_vertices + num_vertices >= cdata->blit_buffer_max_num_vertices) 4447 4501 { ··· 4459 4513 num_indices = (cdata->index_buffer_max_num_vertices - cdata->index_buffer_num_vertices); 4460 4514 } 4461 4515 } 4462 - 4516 + 4463 4517 #ifdef SDL_GPU_USE_BUFFER_PIPELINE 4464 4518 refresh_attribute_data(cdata); 4465 4519 #endif 4466 - 4520 + 4467 4521 if(indices == NULL) 4468 4522 num_indices = num_vertices; 4469 - 4523 + 4470 4524 (void)stride; 4471 4525 (void)offset_texcoords; 4472 4526 (void)offset_colors; 4473 4527 (void)size_vertices; 4474 4528 (void)size_texcoords; 4475 4529 (void)size_colors; 4476 - 4530 + 4477 4531 stride = 0; 4478 4532 offset_texcoords = offset_colors = 0; 4479 4533 size_vertices = size_texcoords = size_colors = 0; 4480 - 4534 + 4481 4535 // Determine stride, size, and offsets 4482 4536 if(use_vertices) 4483 4537 { ··· 4485 4539 size_vertices = 3; 4486 4540 else 4487 4541 size_vertices = 2; 4488 - 4542 + 4489 4543 stride += size_vertices; 4490 - 4544 + 4491 4545 offset_texcoords = stride; 4492 4546 offset_colors = stride; 4493 4547 } 4494 - 4548 + 4495 4549 if(use_texcoords) 4496 4550 { 4497 4551 size_texcoords = 2; 4498 - 4552 + 4499 4553 stride += size_texcoords; 4500 - 4554 + 4501 4555 offset_colors = stride; 4502 4556 } 4503 - 4557 + 4504 4558 if(use_colors) 4505 4559 { 4506 4560 if(use_a) 4507 4561 size_colors = 4; 4508 4562 else 4509 4563 size_colors = 3; 4510 - 4564 + 4511 4565 stride += size_colors; 4512 4566 } 4513 - 4567 + 4514 4568 // Convert to a number of bytes 4515 4569 stride *= sizeof(float); 4516 - 4517 - 4570 + 4571 + 4518 4572 #ifdef SDL_GPU_USE_ARRAY_PIPELINE 4519 - 4573 + 4520 4574 { 4521 4575 // Enable 4522 4576 if(use_vertices) ··· 4525 4579 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 4526 4580 if(use_colors) 4527 4581 glEnableClientState(GL_COLOR_ARRAY); 4528 - 4582 + 4529 4583 // Set pointers 4530 4584 if(use_vertices) 4531 4585 glVertexPointer(size_vertices, GL_FLOAT, stride, values); ··· 4564 4618 float* vertex_pointer = values; 4565 4619 float* texcoord_pointer = values + offset_texcoords; 4566 4620 float* color_pointer = values + offset_colors; 4567 - 4621 + 4568 4622 glBegin(GL_TRIANGLES); 4569 4623 for(i = 0; i < num_indices; i++) 4570 4624 { ··· 4603 4657 #if !defined(SDL_GPU_NO_VAO) 4604 4658 glBindVertexArray(cdata->blit_VAO); 4605 4659 #endif 4606 - 4660 + 4607 4661 // Upload our modelviewprojection matrix 4608 4662 if(cdata->current_shader_block.modelViewProjection_loc >= 0) 4609 4663 { ··· 4611 4665 GPU_GetModelViewProjection(mvp); 4612 4666 glUniformMatrix4fv(cdata->current_shader_block.modelViewProjection_loc, 1, 0, mvp); 4613 4667 } 4614 - 4668 + 4615 4669 if(values != NULL) 4616 4670 { 4617 4671 // Upload blit buffer to a single buffer object 4618 4672 glBindBuffer(GL_ARRAY_BUFFER, cdata->blit_VBO[cdata->blit_VBO_flop]); 4619 4673 cdata->blit_VBO_flop = !cdata->blit_VBO_flop; 4620 4674 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cdata->blit_IBO); 4621 - 4675 + 4622 4676 // Copy the whole blit buffer to the GPU 4623 4677 submit_buffer_data(stride * num_vertices, values, sizeof(unsigned short)*num_indices, indices); // Fills GPU buffer with data. 4624 - 4678 + 4625 4679 // Specify the formatting of the blit buffer 4626 4680 if(use_vertices) 4627 4681 { ··· 4639 4693 glVertexAttribPointer(cdata->current_shader_block.color_loc, size_colors, GL_FLOAT, GL_FALSE, stride, (void*)(offset_colors * sizeof(float))); 4640 4694 } 4641 4695 } 4642 - 4696 + 4643 4697 upload_attribute_data(cdata, num_indices); 4644 - 4698 + 4645 4699 if(indices == NULL) 4646 4700 glDrawArrays(GL_TRIANGLES, 0, num_indices); 4647 4701 else 4648 4702 glDrawElements(GL_TRIANGLES, num_indices, GL_UNSIGNED_SHORT, (void*)0); 4649 - 4703 + 4650 4704 // Disable the vertex arrays again 4651 4705 if(use_vertices) 4652 4706 glDisableVertexAttribArray(cdata->current_shader_block.position_loc); ··· 4654 4708 glDisableVertexAttribArray(cdata->current_shader_block.texcoord_loc); 4655 4709 if(use_colors) 4656 4710 glDisableVertexAttribArray(cdata->current_shader_block.color_loc); 4657 - 4711 + 4658 4712 disable_attribute_data(cdata); 4659 - 4713 + 4660 4714 #if !defined(SDL_GPU_NO_VAO) 4661 4715 glBindVertexArray(0); 4662 4716 #endif 4663 4717 } 4664 4718 #endif 4665 - 4666 - 4719 + 4720 + 4667 4721 cdata->blit_buffer_num_vertices = 0; 4668 4722 cdata->index_buffer_num_vertices = 0; 4669 4723 ··· 4676 4730 GLint filter; 4677 4731 if(image == NULL) 4678 4732 return; 4679 - 4733 + 4680 4734 if(image->target != NULL && isCurrentTarget(renderer, image->target)) 4681 4735 renderer->impl->FlushBlitBuffer(renderer); 4682 4736 bindTexture(renderer, image); ··· 4721 4775 return; 4722 4776 4723 4777 makeContextCurrent(renderer, target); 4724 - 4778 + 4725 4779 if(isCurrentTarget(renderer, target)) 4726 4780 renderer->impl->FlushBlitBuffer(renderer); 4727 4781 // Leave the clip rect values intact so they can still be useful as storage ··· 4803 4857 4804 4858 flushBlitBufferIfCurrentTexture(renderer, image); 4805 4859 bindTexture(renderer, image); 4806 - 4860 + 4807 4861 image->filter_mode = filter; 4808 4862 4809 4863 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter); ··· 4813 4867 static void SetWrapMode(GPU_Renderer* renderer, GPU_Image* image, GPU_WrapEnum wrap_mode_x, GPU_WrapEnum wrap_mode_y) 4814 4868 { 4815 4869 GLenum wrap_x, wrap_y; 4816 - 4870 + 4817 4871 if(image == NULL) 4818 4872 { 4819 4873 GPU_PushErrorCode("GPU_SetWrapMode", GPU_ERROR_NULL_ARGUMENT, "image"); ··· 4824 4878 GPU_PushErrorCode("GPU_SetWrapMode", GPU_ERROR_USER_ERROR, "Mismatched renderer"); 4825 4879 return; 4826 4880 } 4827 - 4881 + 4828 4882 switch(wrap_mode_x) 4829 4883 { 4830 4884 case GPU_WRAP_NONE: ··· 4846 4900 GPU_PushErrorCode("GPU_SetWrapMode", GPU_ERROR_USER_ERROR, "Unsupported value for wrap_mode_x (0x%x)", wrap_mode_x); 4847 4901 return; 4848 4902 } 4849 - 4903 + 4850 4904 switch(wrap_mode_y) 4851 4905 { 4852 4906 case GPU_WRAP_NONE: ··· 4868 4922 GPU_PushErrorCode("GPU_SetWrapMode", GPU_ERROR_USER_ERROR, "Unsupported value for wrap_mode_y (0x%x)", wrap_mode_y); 4869 4923 return; 4870 4924 } 4871 - 4925 + 4872 4926 flushBlitBufferIfCurrentTexture(renderer, image); 4873 4927 bindTexture(renderer, image); 4874 - 4928 + 4875 4929 image->wrap_mode_x = wrap_mode_x; 4876 4930 image->wrap_mode_y = wrap_mode_y; 4877 - 4931 + 4878 4932 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_x ); 4879 4933 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_y ); 4880 4934 } ··· 4891 4945 return; 4892 4946 4893 4947 makeContextCurrent(renderer, target); 4894 - 4948 + 4895 4949 if(isCurrentTarget(renderer, target)) 4896 4950 renderer->impl->FlushBlitBuffer(renderer); 4897 4951 if(bindFramebuffer(renderer, target)) ··· 4912 4966 glEnableClientState(GL_VERTEX_ARRAY); 4913 4967 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 4914 4968 glEnableClientState(GL_COLOR_ARRAY); 4915 - 4969 + 4916 4970 glVertexPointer(2, GL_FLOAT, GPU_BLIT_BUFFER_STRIDE, blit_buffer + GPU_BLIT_BUFFER_VERTEX_OFFSET); 4917 4971 glTexCoordPointer(2, GL_FLOAT, GPU_BLIT_BUFFER_STRIDE, blit_buffer + GPU_BLIT_BUFFER_TEX_COORD_OFFSET); 4918 4972 glColorPointer(4, GL_FLOAT, GPU_BLIT_BUFFER_STRIDE, blit_buffer + GPU_BLIT_BUFFER_COLOR_OFFSET); ··· 4937 4991 float* vertex_pointer = blit_buffer + GPU_BLIT_BUFFER_VERTEX_OFFSET; 4938 4992 float* texcoord_pointer = blit_buffer + GPU_BLIT_BUFFER_TEX_COORD_OFFSET; 4939 4993 float* color_pointer = blit_buffer + GPU_BLIT_BUFFER_COLOR_OFFSET; 4940 - 4994 + 4941 4995 glBegin(cdata->last_shape); 4942 4996 for(i = 0; i < num_indices; i++) 4943 4997 { ··· 4947 5001 glVertex3f( vertex_pointer[index], vertex_pointer[index+1], 0.0f ); 4948 5002 } 4949 5003 glEnd(); 4950 - 5004 + 4951 5005 return; 4952 5006 } 4953 5007 #endif ··· 4961 5015 #if !defined(SDL_GPU_NO_VAO) 4962 5016 glBindVertexArray(cdata->blit_VAO); 4963 5017 #endif 4964 - 5018 + 4965 5019 // Upload our modelviewprojection matrix 4966 5020 if(cdata->current_shader_block.modelViewProjection_loc >= 0) 4967 5021 { ··· 4969 5023 GPU_GetModelViewProjection(mvp); 4970 5024 glUniformMatrix4fv(cdata->current_shader_block.modelViewProjection_loc, 1, 0, mvp); 4971 5025 } 4972 - 5026 + 4973 5027 // Upload blit buffer to a single buffer object 4974 5028 glBindBuffer(GL_ARRAY_BUFFER, cdata->blit_VBO[cdata->blit_VBO_flop]); 4975 5029 cdata->blit_VBO_flop = !cdata->blit_VBO_flop; 4976 5030 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cdata->blit_IBO); 4977 - 5031 + 4978 5032 // Copy the whole blit buffer to the GPU 4979 5033 submit_buffer_data(GPU_BLIT_BUFFER_STRIDE * num_vertices, blit_buffer, sizeof(unsigned short)*num_indices, index_buffer); // Fills GPU buffer with data. 4980 - 5034 + 4981 5035 // Specify the formatting of the blit buffer 4982 5036 if(cdata->current_shader_block.position_loc >= 0) 4983 5037 { ··· 4994 5048 glEnableVertexAttribArray(cdata->current_shader_block.color_loc); 4995 5049 glVertexAttribPointer(cdata->current_shader_block.color_loc, 4, GL_FLOAT, GL_FALSE, GPU_BLIT_BUFFER_STRIDE, (void*)(GPU_BLIT_BUFFER_COLOR_OFFSET * sizeof(float))); 4996 5050 } 4997 - 5051 + 4998 5052 upload_attribute_data(cdata, num_vertices); 4999 - 5053 + 5000 5054 glDrawElements(cdata->last_shape, num_indices, GL_UNSIGNED_SHORT, (void*)0); 5001 - 5055 + 5002 5056 // Disable the vertex arrays again 5003 5057 if(cdata->current_shader_block.position_loc >= 0) 5004 5058 glDisableVertexAttribArray(cdata->current_shader_block.position_loc); ··· 5006 5060 glDisableVertexAttribArray(cdata->current_shader_block.texcoord_loc); 5007 5061 if(cdata->current_shader_block.color_loc >= 0) 5008 5062 glDisableVertexAttribArray(cdata->current_shader_block.color_loc); 5009 - 5063 + 5010 5064 disable_attribute_data(cdata); 5011 - 5065 + 5012 5066 #if !defined(SDL_GPU_NO_VAO) 5013 5067 glBindVertexArray(0); 5014 5068 #endif ··· 5023 5077 #ifdef SDL_GPU_USE_ARRAY_PIPELINE 5024 5078 glEnableClientState(GL_VERTEX_ARRAY); 5025 5079 glEnableClientState(GL_COLOR_ARRAY); 5026 - 5080 + 5027 5081 glVertexPointer(2, GL_FLOAT, GPU_BLIT_BUFFER_STRIDE, blit_buffer + GPU_BLIT_BUFFER_VERTEX_OFFSET); 5028 5082 glColorPointer(4, GL_FLOAT, GPU_BLIT_BUFFER_STRIDE, blit_buffer + GPU_BLIT_BUFFER_COLOR_OFFSET); 5029 5083 ··· 5043 5097 unsigned int index; 5044 5098 float* vertex_pointer = blit_buffer + GPU_BLIT_BUFFER_VERTEX_OFFSET; 5045 5099 float* color_pointer = blit_buffer + GPU_BLIT_BUFFER_COLOR_OFFSET; 5046 - 5100 + 5047 5101 glBegin(cdata->last_shape); 5048 5102 for(i = 0; i < num_indices; i++) 5049 5103 { ··· 5052 5106 glVertex3f( vertex_pointer[index], vertex_pointer[index+1], 0.0f ); 5053 5107 } 5054 5108 glEnd(); 5055 - 5109 + 5056 5110 return; 5057 5111 } 5058 5112 #endif ··· 5063 5117 #if !defined(SDL_GPU_NO_VAO) 5064 5118 glBindVertexArray(cdata->blit_VAO); 5065 5119 #endif 5066 - 5120 + 5067 5121 // Upload our modelviewprojection matrix 5068 5122 if(cdata->current_shader_block.modelViewProjection_loc >= 0) 5069 5123 { ··· 5071 5125 GPU_GetModelViewProjection(mvp); 5072 5126 glUniformMatrix4fv(cdata->current_shader_block.modelViewProjection_loc, 1, 0, mvp); 5073 5127 } 5074 - 5128 + 5075 5129 // Upload blit buffer to a single buffer object 5076 5130 glBindBuffer(GL_ARRAY_BUFFER, cdata->blit_VBO[cdata->blit_VBO_flop]); 5077 5131 cdata->blit_VBO_flop = !cdata->blit_VBO_flop; 5078 5132 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cdata->blit_IBO); 5079 - 5133 + 5080 5134 // Copy the whole blit buffer to the GPU 5081 5135 submit_buffer_data(GPU_BLIT_BUFFER_STRIDE * num_vertices, blit_buffer, sizeof(unsigned short)*num_indices, index_buffer); // Fills GPU buffer with data. 5082 - 5136 + 5083 5137 // Specify the formatting of the blit buffer 5084 5138 if(cdata->current_shader_block.position_loc >= 0) 5085 5139 { ··· 5091 5145 glEnableVertexAttribArray(cdata->current_shader_block.color_loc); 5092 5146 glVertexAttribPointer(cdata->current_shader_block.color_loc, 4, GL_FLOAT, GL_FALSE, GPU_BLIT_BUFFER_STRIDE, (void*)(GPU_BLIT_BUFFER_COLOR_OFFSET * sizeof(float))); 5093 5147 } 5094 - 5148 + 5095 5149 upload_attribute_data(cdata, num_vertices); 5096 - 5150 + 5097 5151 glDrawElements(cdata->last_shape, num_indices, GL_UNSIGNED_SHORT, (void*)0); 5098 - 5152 + 5099 5153 // Disable the vertex arrays again 5100 5154 if(cdata->current_shader_block.position_loc >= 0) 5101 5155 glDisableVertexAttribArray(cdata->current_shader_block.position_loc); 5102 5156 if(cdata->current_shader_block.color_loc >= 0) 5103 5157 glDisableVertexAttribArray(cdata->current_shader_block.color_loc); 5104 - 5158 + 5105 5159 disable_attribute_data(cdata); 5106 - 5160 + 5107 5161 #if !defined(SDL_GPU_NO_VAO) 5108 5162 glBindVertexArray(0); 5109 5163 #endif ··· 5118 5172 GPU_CONTEXT_DATA* cdata; 5119 5173 if(renderer->current_context_target == NULL) 5120 5174 return; 5121 - 5175 + 5122 5176 cdata = (GPU_CONTEXT_DATA*)renderer->current_context_target->context->data; 5123 5177 if(cdata->blit_buffer_num_vertices > 0 && cdata->last_target != NULL) 5124 5178 { ··· 5127 5181 int num_indices; 5128 5182 float* blit_buffer; 5129 5183 unsigned short* index_buffer; 5130 - 5184 + 5131 5185 changeViewport(dest); 5132 5186 changeCamera(dest); 5133 - 5187 + 5134 5188 applyTexturing(renderer); 5135 - 5189 + 5136 5190 #ifdef SDL_GPU_APPLY_TRANSFORMS_TO_GL_STACK 5137 5191 if(!IsFeatureEnabled(renderer, GPU_FEATURE_VERTEX_SHADER)) 5138 5192 applyTransforms(); 5139 5193 #endif 5140 - 5194 + 5141 5195 setClipRect(renderer, dest); 5142 - 5196 + 5143 5197 #ifdef SDL_GPU_USE_BUFFER_PIPELINE 5144 5198 refresh_attribute_data(cdata); 5145 5199 #endif 5146 - 5200 + 5147 5201 blit_buffer = cdata->blit_buffer; 5148 5202 index_buffer = cdata->index_buffer; 5149 - 5203 + 5150 5204 if(cdata->last_use_texturing) 5151 5205 { 5152 5206 while(cdata->blit_buffer_num_vertices > 0) 5153 5207 { 5154 5208 num_vertices = MAX(cdata->blit_buffer_num_vertices, get_lowest_attribute_num_values(cdata, cdata->blit_buffer_num_vertices)); 5155 5209 num_indices = num_vertices * 3 / 2; // 6 indices per sprite / 4 vertices per sprite = 3/2 5156 - 5210 + 5157 5211 DoPartialFlush(renderer, cdata, num_vertices, blit_buffer, num_indices, index_buffer); 5158 - 5212 + 5159 5213 cdata->blit_buffer_num_vertices -= num_vertices; 5160 5214 // Move our pointers ahead 5161 5215 blit_buffer += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX*num_vertices; ··· 5177 5231 static void Flip(GPU_Renderer* renderer, GPU_Target* target) 5178 5232 { 5179 5233 renderer->impl->FlushBlitBuffer(renderer); 5180 - 5234 + 5181 5235 makeContextCurrent(renderer, target); 5182 5236 5183 5237 #ifdef SDL_GPU_USE_SDL2 ··· 5237 5291 5238 5292 if(shader_source == NULL) 5239 5293 return 0; 5240 - 5294 + 5241 5295 size = 0; 5242 - 5296 + 5243 5297 // Read 1 byte at a time until we reach the end 5244 5298 last_char = ' '; 5245 5299 len = 0; ··· 5259 5313 break; 5260 5314 } 5261 5315 buffer[line_size] = '\0'; 5262 - 5316 + 5263 5317 // Is there "include" after '#'? 5264 5318 token = strtok(buffer, "# \t"); 5265 - 5319 + 5266 5320 if(token != NULL && strcmp(token, "include") == 0) 5267 5321 { 5268 5322 // Get filename token ··· 5278 5332 last_char = ' '; 5279 5333 continue; 5280 5334 } 5281 - 5335 + 5282 5336 size += len; 5283 - 5337 + 5284 5338 if(last_char == '/') 5285 5339 { 5286 5340 if(buffer[0] == '/') ··· 5298 5352 else 5299 5353 last_char = buffer[0]; 5300 5354 } 5301 - 5355 + 5302 5356 // Go back to the beginning of the stream 5303 5357 SDL_RWseek(shader_source, 0, SEEK_SET); 5304 5358 return size; ··· 5317 5371 result[0] = '\0'; 5318 5372 return 0; 5319 5373 } 5320 - 5374 + 5321 5375 size = 0; 5322 - 5376 + 5323 5377 // Read 1 byte at a time until we reach the end 5324 5378 last_char = ' '; 5325 5379 len = 0; ··· 5339 5393 if(buffer[line_size - line_len] == '\n') 5340 5394 break; 5341 5395 } 5342 - 5396 + 5343 5397 // Is there "include" after '#'? 5344 5398 memcpy(token_buffer, buffer, line_size+1); 5345 5399 token_buffer[line_size] = '\0'; 5346 5400 token = strtok(token_buffer, "# \t"); 5347 - 5401 + 5348 5402 if(token != NULL && strcmp(token, "include") == 0) 5349 5403 { 5350 5404 // Get filename token ··· 5365 5419 last_char = ' '; 5366 5420 continue; 5367 5421 } 5368 - 5422 + 5369 5423 memcpy(result + size, buffer, len); 5370 5424 size += len; 5371 - 5425 + 5372 5426 if(last_char == '/') 5373 5427 { 5374 5428 if(buffer[0] == '/') ··· 5389 5443 last_char = buffer[0]; 5390 5444 } 5391 5445 result[size] = '\0'; 5392 - 5446 + 5393 5447 // Go back to the beginning of the stream 5394 5448 SDL_RWseek(shader_source, 0, SEEK_SET); 5395 5449 return size; ··· 5403 5457 if(filename == NULL) 5404 5458 return 0; 5405 5459 rwops = SDL_RWFromFile(filename, "r"); 5406 - 5460 + 5407 5461 size = GetShaderSource_RW(rwops, result); 5408 - 5462 + 5409 5463 SDL_RWclose(rwops); 5410 5464 return size; 5411 5465 } ··· 5418 5472 if(filename == NULL) 5419 5473 return 0; 5420 5474 rwops = SDL_RWFromFile(filename, "r"); 5421 - 5475 + 5422 5476 result = GetShaderSourceSize_RW(rwops); 5423 - 5477 + 5424 5478 SDL_RWclose(rwops); 5425 5479 return result; 5426 5480 } ··· 5432 5486 GLuint shader_object = 0; 5433 5487 (void)shader_type; 5434 5488 (void)shader_source; 5435 - 5489 + 5436 5490 #ifndef SDL_GPU_DISABLE_SHADERS 5437 5491 GLint compiled; 5438 - 5492 + 5439 5493 switch(shader_type) 5440 5494 { 5441 5495 case GPU_VERTEX_SHADER: ··· 5454 5508 #endif 5455 5509 break; 5456 5510 } 5457 - 5511 + 5458 5512 if(shader_object == 0) 5459 5513 { 5460 5514 GPU_PushErrorCode("GPU_CompileShader", GPU_ERROR_BACKEND_ERROR, "Failed to create new shader object"); 5461 5515 snprintf(shader_message, 256, "Failed to create new shader object.\n"); 5462 5516 return 0; 5463 5517 } 5464 - 5518 + 5465 5519 glShaderSource(shader_object, 1, &shader_source, NULL); 5466 - 5520 + 5467 5521 // Compile the shader source 5468 - 5522 + 5469 5523 glCompileShader(shader_object); 5470 - 5524 + 5471 5525 glGetShaderiv(shader_object, GL_COMPILE_STATUS, &compiled); 5472 5526 if(!compiled) 5473 5527 { ··· 5476 5530 glDeleteShader(shader_object); 5477 5531 return 0; 5478 5532 } 5479 - 5533 + 5480 5534 #endif 5481 - 5535 + 5482 5536 return shader_object; 5483 5537 } 5484 5538 ··· 5499 5553 SDL_free(source_string); 5500 5554 return 0; 5501 5555 } 5502 - 5556 + 5503 5557 result2 = compile_shader_source(shader_type, source_string); 5504 5558 SDL_free(source_string); 5505 - 5559 + 5506 5560 return result2; 5507 5561 } 5508 5562 ··· 5522 5576 { 5523 5577 #ifndef SDL_GPU_DISABLE_SHADERS 5524 5578 GLuint p; 5525 - 5579 + 5526 5580 if(!IsFeatureEnabled(renderer, GPU_FEATURE_BASIC_SHADERS)) 5527 5581 return 0; 5528 - 5582 + 5529 5583 p = glCreateProgram(); 5530 - 5584 + 5531 5585 return p; 5532 5586 #else 5533 5587 (void)renderer; ··· 5539 5593 { 5540 5594 #ifndef SDL_GPU_DISABLE_SHADERS 5541 5595 int linked; 5542 - 5596 + 5543 5597 if(!IsFeatureEnabled(renderer, GPU_FEATURE_BASIC_SHADERS)) 5544 5598 return 0; 5545 - 5599 + 5546 5600 glLinkProgram(program_object); 5547 - 5601 + 5548 5602 glGetProgramiv(program_object, GL_LINK_STATUS, &linked); 5549 - 5603 + 5550 5604 if(!linked) 5551 5605 { 5552 5606 GPU_PushErrorCode("GPU_LinkShaderProgram", GPU_ERROR_BACKEND_ERROR, "Failed to link shader program"); ··· 5554 5608 glDeleteProgram(program_object); 5555 5609 return 0; 5556 5610 } 5557 - 5611 + 5558 5612 return 1; 5559 - 5613 + 5560 5614 #else 5561 5615 (void)renderer; 5562 5616 (void)program_object; 5563 5617 return 0; 5564 - 5618 + 5565 5619 #endif 5566 5620 } 5567 5621 ··· 5620 5674 if(target->context->current_shader_program == target->context->default_textured_shader_program 5621 5675 || target->context->current_shader_program == target->context->default_untextured_shader_program) 5622 5676 return; 5623 - 5677 + 5624 5678 program_object = target->context->default_untextured_shader_program; 5625 5679 } 5626 - 5680 + 5627 5681 renderer->impl->FlushBlitBuffer(renderer); 5628 5682 glUseProgram(program_object); 5629 - 5683 + 5630 5684 { 5631 5685 // Set up our shader attribute and uniform locations 5632 5686 GPU_CONTEXT_DATA* cdata = ((GPU_CONTEXT_DATA*)target->context->data); ··· 5651 5705 } 5652 5706 } 5653 5707 #endif 5654 - 5708 + 5655 5709 target->context->current_shader_program = program_object; 5656 5710 } 5657 5711 ··· 5712 5766 b.modelViewProjection_loc = -1; 5713 5767 return b; 5714 5768 } 5715 - 5769 + 5716 5770 if(position_name == NULL) 5717 5771 b.position_loc = -1; 5718 5772 else 5719 5773 b.position_loc = renderer->impl->GetAttributeLocation(renderer, program_object, position_name); 5720 - 5774 + 5721 5775 if(texcoord_name == NULL) 5722 5776 b.texcoord_loc = -1; 5723 5777 else 5724 5778 b.texcoord_loc = renderer->impl->GetAttributeLocation(renderer, program_object, texcoord_name); 5725 - 5779 + 5726 5780 if(color_name == NULL) 5727 5781 b.color_loc = -1; 5728 5782 else 5729 5783 b.color_loc = renderer->impl->GetAttributeLocation(renderer, program_object, color_name); 5730 - 5784 + 5731 5785 if(modelViewMatrix_name == NULL) 5732 5786 b.modelViewProjection_loc = -1; 5733 5787 else 5734 5788 b.modelViewProjection_loc = renderer->impl->GetUniformLocation(renderer, program_object, modelViewMatrix_name); 5735 - 5789 + 5736 5790 return b; 5737 5791 } 5738 5792 ··· 5750 5804 // TODO: OpenGL 1 needs to check for ARB_multitexture to use glActiveTexture(). 5751 5805 #ifndef SDL_GPU_DISABLE_SHADERS 5752 5806 Uint32 new_texture; 5753 - 5807 + 5754 5808 if(!IsFeatureEnabled(renderer, GPU_FEATURE_BASIC_SHADERS)) 5755 5809 return; 5756 - 5810 + 5757 5811 renderer->impl->FlushBlitBuffer(renderer); 5758 5812 if(renderer->current_context_target->context->current_shader_program == 0 || image_unit < 0) 5759 5813 return; 5760 - 5814 + 5761 5815 new_texture = 0; 5762 5816 if(image != NULL) 5763 5817 new_texture = ((GPU_IMAGE_DATA*)image->data)->handle; 5764 - 5818 + 5765 5819 // Set the new image unit 5766 5820 glUniform1i(location, image_unit); 5767 5821 glActiveTexture(GL_TEXTURE0 + image_unit); 5768 5822 glBindTexture(GL_TEXTURE_2D, new_texture); 5769 - 5823 + 5770 5824 if(image_unit != 0) 5771 5825 glActiveTexture(GL_TEXTURE0); 5772 - 5826 + 5773 5827 #endif 5774 5828 5775 5829 (void)renderer; ··· 6034 6088 return; 6035 6089 } 6036 6090 #endif 6037 - 6091 + 6038 6092 switch(num_rows) 6039 6093 { 6040 6094 case 2: ··· 6078 6132 renderer->impl->FlushBlitBuffer(renderer); 6079 6133 if(renderer->current_context_target->context->current_shader_program == 0) 6080 6134 return; 6081 - 6135 + 6082 6136 #ifdef SDL_GPU_USE_OPENGL 6083 6137 if(apply_Intel_attrib_workaround && location == 0) 6084 6138 { ··· 6087 6141 glEnd(); 6088 6142 } 6089 6143 #endif 6090 - 6144 + 6091 6145 glVertexAttrib1f(location, value); 6092 - 6146 + 6093 6147 #endif 6094 6148 } 6095 6149 ··· 6105 6159 renderer->impl->FlushBlitBuffer(renderer); 6106 6160 if(renderer->current_context_target->context->current_shader_program == 0) 6107 6161 return; 6108 - 6162 + 6109 6163 #ifdef SDL_GPU_USE_OPENGL 6110 6164 if(apply_Intel_attrib_workaround && location == 0) 6111 6165 { ··· 6114 6168 glEnd(); 6115 6169 } 6116 6170 #endif 6117 - 6171 + 6118 6172 glVertexAttribI1i(location, value); 6119 - 6173 + 6120 6174 #endif 6121 6175 } 6122 6176 ··· 6132 6186 renderer->impl->FlushBlitBuffer(renderer); 6133 6187 if(renderer->current_context_target->context->current_shader_program == 0) 6134 6188 return; 6135 - 6189 + 6136 6190 #ifdef SDL_GPU_USE_OPENGL 6137 6191 if(apply_Intel_attrib_workaround && location == 0) 6138 6192 { ··· 6141 6195 glEnd(); 6142 6196 } 6143 6197 #endif 6144 - 6198 + 6145 6199 glVertexAttribI1ui(location, value); 6146 - 6200 + 6147 6201 #endif 6148 6202 } 6149 6203 ··· 6161 6215 renderer->impl->FlushBlitBuffer(renderer); 6162 6216 if(renderer->current_context_target->context->current_shader_program == 0) 6163 6217 return; 6164 - 6218 + 6165 6219 #ifdef SDL_GPU_USE_OPENGL 6166 6220 if(apply_Intel_attrib_workaround && location == 0) 6167 6221 { ··· 6170 6224 glEnd(); 6171 6225 } 6172 6226 #endif 6173 - 6227 + 6174 6228 switch(num_elements) 6175 6229 { 6176 6230 case 1: ··· 6186 6240 glVertexAttrib4f(location, value[0], value[1], value[2], value[3]); 6187 6241 break; 6188 6242 } 6189 - 6243 + 6190 6244 #endif 6191 6245 } 6192 6246 ··· 6202 6256 renderer->impl->FlushBlitBuffer(renderer); 6203 6257 if(renderer->current_context_target->context->current_shader_program == 0) 6204 6258 return; 6205 - 6259 + 6206 6260 #ifdef SDL_GPU_USE_OPENGL 6207 6261 if(apply_Intel_attrib_workaround && location == 0) 6208 6262 { ··· 6211 6265 glEnd(); 6212 6266 } 6213 6267 #endif 6214 - 6268 + 6215 6269 switch(num_elements) 6216 6270 { 6217 6271 case 1: ··· 6227 6281 glVertexAttribI4i(location, value[0], value[1], value[2], value[3]); 6228 6282 break; 6229 6283 } 6230 - 6284 + 6231 6285 #endif 6232 6286 } 6233 6287 ··· 6244 6298 renderer->impl->FlushBlitBuffer(renderer); 6245 6299 if(renderer->current_context_target->context->current_shader_program == 0) 6246 6300 return; 6247 - 6301 + 6248 6302 #ifdef SDL_GPU_USE_OPENGL 6249 6303 if(apply_Intel_attrib_workaround && location == 0) 6250 6304 { ··· 6253 6307 glEnd(); 6254 6308 } 6255 6309 #endif 6256 - 6310 + 6257 6311 switch(num_elements) 6258 6312 { 6259 6313 case 1: ··· 6269 6323 glVertexAttribI4ui(location, value[0], value[1], value[2], value[3]); 6270 6324 break; 6271 6325 } 6272 - 6326 + 6273 6327 #endif 6274 6328 } 6275 6329 ··· 6293 6347 a->per_vertex_storage_stride_bytes = source.format.num_elems_per_value * sizeof_GPU_type(source.format.type); 6294 6348 a->num_values = 4 * num_values; // 4 vertices now 6295 6349 needed_size = a->num_values * a->per_vertex_storage_stride_bytes; 6296 - 6350 + 6297 6351 // Make sure we have enough room for converted per-vertex data 6298 6352 if(a->per_vertex_storage_size < needed_size) 6299 6353 { ··· 6308 6362 a->per_vertex_storage = NULL; 6309 6363 a->per_vertex_storage_size = 0; 6310 6364 } 6311 - 6365 + 6312 6366 a->enabled = 0; 6313 6367 a->attribute = source; 6314 - 6368 + 6315 6369 if(!source.format.is_per_sprite) 6316 6370 { 6317 6371 a->per_vertex_storage = source.values; ··· 6319 6373 a->per_vertex_storage_stride_bytes = source.format.stride_bytes; 6320 6374 a->per_vertex_storage_offset_bytes = source.format.offset_bytes; 6321 6375 } 6322 - 6376 + 6323 6377 a->next_value = a->per_vertex_storage; 6324 - 6378 + 6325 6379 #endif 6326 6380 6327 6381 (void)renderer;
+2 -1
src/renderer_OpenGL_1.c
··· 36 36 renderer->id = request; 37 37 renderer->id.renderer = GPU_RENDERER_OPENGL_1; 38 38 renderer->shader_language = GPU_LANGUAGE_GLSL; 39 - renderer->shader_version = SDL_GPU_GLSL_VERSION; 39 + renderer->min_shader_version = 110; 40 + renderer->max_shader_version = SDL_GPU_GLSL_VERSION; 40 41 41 42 renderer->current_context_target = NULL; 42 43
+2 -1
src/renderer_OpenGL_1_BASE.c
··· 34 34 renderer->id = request; 35 35 renderer->id.renderer = GPU_RENDERER_OPENGL_1_BASE; 36 36 renderer->shader_language = GPU_LANGUAGE_NONE; 37 - renderer->shader_version = 0; 37 + renderer->min_shader_version = 0; 38 + renderer->max_shader_version = 0; 38 39 39 40 renderer->current_context_target = NULL; 40 41
+2 -1
src/renderer_OpenGL_2.c
··· 34 34 renderer->id = request; 35 35 renderer->id.renderer = GPU_RENDERER_OPENGL_2; 36 36 renderer->shader_language = GPU_LANGUAGE_GLSL; 37 - renderer->shader_version = SDL_GPU_GLSL_VERSION; 37 + renderer->min_shader_version = 110; 38 + renderer->max_shader_version = SDL_GPU_GLSL_VERSION; 38 39 39 40 renderer->current_context_target = NULL; 40 41
+2 -1
src/renderer_OpenGL_3.c
··· 38 38 renderer->id = request; 39 39 renderer->id.renderer = GPU_RENDERER_OPENGL_3; 40 40 renderer->shader_language = GPU_LANGUAGE_GLSL; 41 - renderer->shader_version = SDL_GPU_GLSL_VERSION; 41 + renderer->min_shader_version = 110; 42 + renderer->max_shader_version = SDL_GPU_GLSL_VERSION; 42 43 43 44 renderer->current_context_target = NULL; 44 45
+4
tests/CMakeLists.txt
··· 3 3 4 4 set(TEST_LIBS test-common SDL_gpu) 5 5 6 + if(MINGW) 7 + set(TEST_LIBS ${TEST_LIBS} mingw32) 8 + endif(MINGW) 9 + 6 10 add_executable(create-test create/main.c) 7 11 target_link_libraries (create-test ${TEST_LIBS}) 8 12
+10 -5
tests/render-target/main.c
··· 12 12 13 13 screen = initialize_demo(argc, argv, 800, 600); 14 14 if(screen == NULL) 15 - return -1; 15 + return 1; 16 16 17 17 { 18 18 GPU_Image* image2; ··· 34 34 35 35 image2 = GPU_LoadImage("data/test2.bmp"); 36 36 if (image2 == NULL) 37 - return -1; 37 + return 2; 38 38 39 39 image3 = GPU_LoadImage("data/test.bmp"); 40 40 if (image3 == NULL) 41 - return -1; 41 + return 3; 42 42 43 43 font_surface = GPU_LoadSurface("data/comic14.png"); 44 44 font = FONT_Alloc(font_surface); 45 + if(font == NULL) 46 + { 47 + GPU_LogError("Failed to load font.\n"); 48 + return 4; 49 + } 45 50 GPU_SetRGB(font->image, 255, 0, 0); 46 51 SDL_FreeSurface(font_surface); 47 52 48 53 mode1image = GPU_CreateImage(300, 300, GPU_FORMAT_RGBA); 49 54 if (mode1image == NULL) 50 - return -1; 55 + return 5; 51 56 52 57 mode2image = GPU_CreateImage(400, 400, GPU_FORMAT_RGBA); 53 58 if (mode2image == NULL) 54 - return -1; 59 + return 6; 55 60 56 61 GPU_LoadTarget(mode1image); 57 62 GPU_LoadTarget(mode2image);
+2 -1
tests/renderer/main.c
··· 1302 1302 1303 1303 renderer->id = request; 1304 1304 renderer->shader_language = GPU_LANGUAGE_NONE; 1305 - renderer->shader_version = 0; 1305 + renderer->min_shader_version = 0; 1306 + renderer->max_shader_version = 0; 1306 1307 1307 1308 renderer->current_context_target = NULL; 1308 1309