this repo has no description
0
fork

Configure Feed

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

Merge pull request #219 from cosmo-ray/GPU_CopyImageFromSurface2

add GPU_CopyImageFromSurfaceRect

authored by

Jonathan Dearborn and committed by
GitHub
a6fbadb9 ffe2c80a

+31 -17
+3
include/SDL_gpu.h
··· 1373 1373 /*! Copy SDL_Surface data into a new GPU_Image. Don't forget to SDL_FreeSurface() the surface and GPU_FreeImage() the image.*/ 1374 1374 DECLSPEC GPU_Image* SDLCALL GPU_CopyImageFromSurface(SDL_Surface* surface); 1375 1375 1376 + /*! Like GPU_CopyImageFromSurface but enable to copy only part of the surface.*/ 1377 + DECLSPEC GPU_Image* SDLCALL GPU_CopyImageFromSurfaceRect(SDL_Surface* surface, GPU_Rect* surface_rect); 1378 + 1376 1379 /*! Copy GPU_Target data into a new GPU_Image. Don't forget to GPU_FreeImage() the image.*/ 1377 1380 DECLSPEC GPU_Image* SDLCALL GPU_CopyImageFromTarget(GPU_Target* target); 1378 1381
+1 -1
include/SDL_gpu_RendererImpl.h
··· 86 86 GPU_bool (SDLCALL *ReplaceImage)(GPU_Renderer* renderer, GPU_Image* image, SDL_Surface* surface, const GPU_Rect* surface_rect); 87 87 88 88 /*! \see GPU_CopyImageFromSurface() */ 89 - GPU_Image* (SDLCALL *CopyImageFromSurface)(GPU_Renderer* renderer, SDL_Surface* surface); 89 + GPU_Image* (SDLCALL *CopyImageFromSurface)(GPU_Renderer* renderer, SDL_Surface* surface, GPU_Rect *surface_rect); 90 90 91 91 /*! \see GPU_CopyImageFromTarget() */ 92 92 GPU_Image* (SDLCALL *CopyImageFromTarget)(GPU_Renderer* renderer, GPU_Target* target);
+10 -2
src/SDL_gpu.c
··· 990 990 return NULL; 991 991 } 992 992 993 - result = _gpu_current_renderer->impl->CopyImageFromSurface(_gpu_current_renderer, surface); 993 + result = _gpu_current_renderer->impl->CopyImageFromSurface(_gpu_current_renderer, surface, NULL); 994 994 SDL_FreeSurface(surface); 995 995 996 996 return result; ··· 1307 1307 if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1308 1308 return NULL; 1309 1309 1310 - return _gpu_current_renderer->impl->CopyImageFromSurface(_gpu_current_renderer, surface); 1310 + return _gpu_current_renderer->impl->CopyImageFromSurface(_gpu_current_renderer, surface, NULL); 1311 + } 1312 + 1313 + GPU_Image* GPU_CopyImageFromSurfaceRect(SDL_Surface* surface, GPU_Rect* surface_rect) 1314 + { 1315 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL) 1316 + return NULL; 1317 + 1318 + return _gpu_current_renderer->impl->CopyImageFromSurface(_gpu_current_renderer, surface, surface_rect); 1311 1319 } 1312 1320 1313 1321 GPU_Image* GPU_CopyImageFromTarget(GPU_Target* target)
+17 -14
src/renderer_GL_common.inl
··· 3470 3470 3471 3471 static void UpdateImage(GPU_Renderer* renderer, GPU_Image* image, const GPU_Rect* image_rect, SDL_Surface* surface, const GPU_Rect* surface_rect) 3472 3472 { 3473 - GPU_IMAGE_DATA* data; 3474 - GLenum original_format; 3473 + GPU_IMAGE_DATA* data; 3474 + GLenum original_format; 3475 3475 3476 - SDL_Surface* newSurface; 3477 - GPU_Rect updateRect; 3478 - GPU_Rect sourceRect; 3479 - int alignment; 3480 - Uint8* pixels; 3476 + SDL_Surface* newSurface; 3477 + GPU_Rect updateRect; 3478 + GPU_Rect sourceRect; 3479 + int alignment; 3480 + Uint8* pixels; 3481 3481 3482 3482 if(image == NULL || surface == NULL) 3483 3483 return; ··· 3870 3870 return 0; // FIXME: Handle errors better 3871 3871 } 3872 3872 3873 - static GPU_Image* CopyImageFromSurface(GPU_Renderer* renderer, SDL_Surface* surface) 3873 + static GPU_Image* CopyImageFromSurface(GPU_Renderer* renderer, SDL_Surface* surface, const GPU_Rect* surface_rect) 3874 3874 { 3875 3875 GPU_FormatEnum format; 3876 - GPU_Image* image; 3876 + GPU_Image* image; 3877 + int sw, sh; 3877 3878 3878 3879 if(surface == NULL) 3879 3880 { 3880 3881 GPU_PushErrorCode("GPU_CopyImageFromSurface", GPU_ERROR_NULL_ARGUMENT, "surface"); 3881 3882 return NULL; 3882 3883 } 3884 + sw = surface_rect == NULL ? surface->w : surface_rect->w; 3885 + sh = surface_rect == NULL ? surface->h : surface_rect->h; 3883 3886 3884 3887 if(surface->w == 0 || surface->h == 0) 3885 3888 { ··· 3901 3904 format = GPU_FORMAT_RGBA; 3902 3905 } 3903 3906 3904 - image = renderer->impl->CreateImage(renderer, (Uint16)surface->w, (Uint16)surface->h, format); 3907 + image = renderer->impl->CreateImage(renderer, (Uint16)sw, (Uint16)sh, format); 3905 3908 if(image == NULL) 3906 3909 return NULL; 3907 3910 3908 - renderer->impl->UpdateImage(renderer, image, NULL, surface, NULL); 3911 + renderer->impl->UpdateImage(renderer, image, NULL, surface, surface_rect); 3909 3912 3910 3913 return image; 3911 3914 } ··· 3913 3916 3914 3917 static GPU_Image* CopyImageFromTarget(GPU_Renderer* renderer, GPU_Target* target) 3915 3918 { 3916 - GPU_Image* result; 3919 + GPU_Image* result; 3917 3920 3918 3921 if(target == NULL) 3919 3922 return NULL; 3920 - 3923 + 3921 3924 if(target->image != NULL) 3922 3925 { 3923 3926 result = gpu_copy_image_pixels_only(renderer, target->image); ··· 3925 3928 else 3926 3929 { 3927 3930 SDL_Surface* surface = renderer->impl->CopySurfaceFromTarget(renderer, target); 3928 - result = renderer->impl->CopyImageFromSurface(renderer, surface); 3931 + result = renderer->impl->CopyImageFromSurface(renderer, surface, NULL); 3929 3932 SDL_FreeSurface(surface); 3930 3933 } 3931 3934