this repo has no description
0
fork

Configure Feed

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

Added using_virtual_resolution to GPU_Image. Added GPU_SetImageVirtualResolution() and GPU_UnsetImageVirtualResolution(). These new functions don't need to flush because they don't change the interpretation of data already in the blit buffer.

Replaced GPU_UpdateImage() with what used to be GPU_UpdateSubImage(). An additional parameter is fine for simplifying the API.

+105 -59
+9 -5
include/SDL_gpu.h
··· 234 234 struct GPU_Renderer* renderer; 235 235 GPU_Target* target; 236 236 Uint16 w, h; 237 + Uint8 using_virtual_resolution; 237 238 GPU_FormatEnum format; 238 239 int num_layers; 239 240 int bytes_per_pixel; ··· 954 955 /*! Deletes an image in the proper way for this renderer. Also deletes the corresponding GPU_Target if applicable. Be careful not to use that target afterward! */ 955 956 DECLSPEC void SDLCALL GPU_FreeImage(GPU_Image* image); 956 957 957 - /*! Update an image from surface data. */ 958 - DECLSPEC void SDLCALL GPU_UpdateImage(GPU_Image* image, SDL_Surface* surface, const GPU_Rect* surface_rect); 958 + /*! Change the logical size of the given image. Rendering this image will scaled it as if the dimensions were actually the ones given. */ 959 + DECLSPEC void SDLCALL GPU_SetImageVirtualResolution(GPU_Image* image, Uint16 w, Uint16 h); 960 + 961 + /*! Reset the logical size of the given image to its original value. */ 962 + DECLSPEC void SDLCALL GPU_UnsetImageVirtualResolution(GPU_Image* image); 959 963 960 - /*! Update an image from surface data. */ 961 - DECLSPEC void SDLCALL GPU_UpdateSubImage(GPU_Image* image, const GPU_Rect* image_rect, SDL_Surface* surface, const GPU_Rect* surface_rect); 964 + /*! Update an image from surface data. Ignores virtual resolution on the image so the number of pixels needed from the surface is known. */ 965 + DECLSPEC void SDLCALL GPU_UpdateImage(GPU_Image* image, const GPU_Rect* image_rect, SDL_Surface* surface, const GPU_Rect* surface_rect); 962 966 963 - /*! Update an image from an array of pixel data. */ 967 + /*! Update an image from an array of pixel data. Ignores virtual resolution on the image so the number of pixels needed from the surface is known. */ 964 968 DECLSPEC void SDLCALL GPU_UpdateImageBytes(GPU_Image* image, const GPU_Rect* image_rect, const unsigned char* bytes, int bytes_per_row); 965 969 966 970 /*! Save image to a file.
+1 -4
include/SDL_gpu_RendererImpl.h
··· 74 74 GPU_Image* (SDLCALL *CopyImage)(GPU_Renderer* renderer, GPU_Image* image); 75 75 76 76 /*! \see GPU_UpdateImage */ 77 - void (SDLCALL *UpdateImage)(GPU_Renderer* renderer, GPU_Image* image, SDL_Surface* surface, const GPU_Rect* surface_rect); 78 - 79 - /*! \see GPU_UpdateSubImage */ 80 - void (SDLCALL *UpdateSubImage)(GPU_Renderer* renderer, GPU_Image* image, const GPU_Rect* image_rect, SDL_Surface* surface, const GPU_Rect* surface_rect); 77 + void (SDLCALL *UpdateImage)(GPU_Renderer* renderer, GPU_Image* image, const GPU_Rect* image_rect, SDL_Surface* surface, const GPU_Rect* surface_rect); 81 78 82 79 /*! \see GPU_UpdateImageBytes */ 83 80 void (SDLCALL *UpdateImageBytes)(GPU_Renderer* renderer, GPU_Image* image, const GPU_Rect* image_rect, const unsigned char* bytes, int bytes_per_row);
+28 -10
src/SDL_gpu.c
··· 493 493 current_renderer->impl->UnsetVirtualResolution(current_renderer, target); 494 494 } 495 495 496 + void GPU_SetImageVirtualResolution(GPU_Image* image, Uint16 w, Uint16 h) 497 + { 498 + if(current_renderer == NULL || current_renderer->current_context_target == NULL || w == 0 || h == 0) 499 + return; 500 + 501 + if(image == NULL) 502 + return; 503 + 504 + image->w = w; 505 + image->h = h; 506 + image->using_virtual_resolution = 1; 507 + } 508 + 509 + void GPU_UnsetImageVirtualResolution(GPU_Image* image) 510 + { 511 + if(current_renderer == NULL || current_renderer->current_context_target == NULL) 512 + return; 513 + 514 + if(image == NULL) 515 + return; 516 + 517 + image->w = image->base_w; 518 + image->h = image->base_h; 519 + image->using_virtual_resolution = 0; 520 + } 521 + 496 522 void GPU_CloseCurrentRenderer(void) 497 523 { 498 524 if(current_renderer == NULL) ··· 753 779 return current_renderer->impl->CopyImage(current_renderer, image); 754 780 } 755 781 756 - void GPU_UpdateImage(GPU_Image* image, SDL_Surface* surface, const GPU_Rect* surface_rect) 757 - { 758 - if(current_renderer == NULL || current_renderer->current_context_target == NULL) 759 - return; 760 - 761 - current_renderer->impl->UpdateImage(current_renderer, image, surface, surface_rect); 762 - } 763 - 764 - void GPU_UpdateSubImage(GPU_Image* image, const GPU_Rect* image_rect, SDL_Surface* surface, const GPU_Rect* surface_rect) 782 + void GPU_UpdateImage(GPU_Image* image, const GPU_Rect* image_rect, SDL_Surface* surface, const GPU_Rect* surface_rect) 765 783 { 766 784 if(current_renderer == NULL || current_renderer->current_context_target == NULL) 767 785 return; 768 786 769 - current_renderer->impl->UpdateSubImage(current_renderer, image, image_rect, surface, surface_rect); 787 + current_renderer->impl->UpdateImage(current_renderer, image, image_rect, surface, surface_rect); 770 788 } 771 789 772 790 void GPU_UpdateImageBytes(GPU_Image* image, const GPU_Rect* image_rect, const unsigned char* bytes, int bytes_per_row)
+54 -27
src/renderer_GL_common.inl
··· 1809 1809 data->owns_handle = 1; 1810 1810 data->format = gl_format; 1811 1811 1812 + result->using_virtual_resolution = 0; 1812 1813 result->w = w; 1813 1814 result->h = h; 1814 1815 result->base_w = w; ··· 2039 2040 result->data = data; 2040 2041 result->is_alias = 0; 2041 2042 2043 + result->using_virtual_resolution = 0; 2042 2044 result->w = w; 2043 2045 result->h = h; 2044 2046 ··· 2735 2737 { 2736 2738 GPU_Target* target; 2737 2739 2738 - result = renderer->impl->CreateImage(renderer, image->w, image->h, image->format); 2740 + result = renderer->impl->CreateImage(renderer, image->texture_w, image->texture_h, image->format); 2739 2741 if(result == NULL) 2740 2742 { 2741 2743 GPU_PushErrorCode("GPU_CopyImage", GPU_ERROR_BACKEND_ERROR, "Failed to create new image."); ··· 2758 2760 SDL_Color color = image->color; 2759 2761 Uint8 use_blending = image->use_blending; 2760 2762 GPU_FilterEnum filter_mode = image->filter_mode; 2763 + Uint8 use_virtual = image->using_virtual_resolution; 2764 + Uint16 w, h; 2761 2765 GPU_UnsetColor(image); 2762 2766 GPU_SetBlending(image, 0); 2763 2767 GPU_SetImageFilter(image, GPU_FILTER_NEAREST); 2768 + if(use_virtual) 2769 + { 2770 + w = image->w; 2771 + h = image->h; 2772 + GPU_UnsetImageVirtualResolution(image); 2773 + } 2764 2774 2765 2775 renderer->impl->Blit(renderer, image, NULL, target, image->w / 2, image->h / 2); 2766 2776 ··· 2768 2778 GPU_SetColor(image, color); 2769 2779 GPU_SetBlending(image, use_blending); 2770 2780 GPU_SetImageFilter(image, filter_mode); 2781 + if(use_virtual) 2782 + { 2783 + GPU_SetImageVirtualResolution(image, w, h); 2784 + } 2771 2785 } 2772 2786 2773 2787 // Don't free the target yet (a waste of perf), but let it be freed next time... ··· 2790 2804 return NULL; 2791 2805 } 2792 2806 2793 - result = CreateUninitializedImage(renderer, image->w, image->h, image->format); 2807 + result = CreateUninitializedImage(renderer, image->texture_w, image->texture_h, image->format); 2794 2808 if(result == NULL) 2795 2809 { 2796 2810 free(texture_data); ··· 2848 2862 GPU_SetWrapMode(result, image->wrap_mode_x, image->wrap_mode_y); 2849 2863 if(image->has_mipmaps) 2850 2864 GPU_GenerateMipmaps(result); 2865 + if(image->using_virtual_resolution) 2866 + GPU_SetImageVirtualResolution(result, image->w, image->h); 2851 2867 } 2852 2868 2853 2869 return result; 2854 2870 } 2855 - 2856 2871 2857 2872 2858 2873 2859 - static void UpdateImage(GPU_Renderer* renderer, GPU_Image* image, SDL_Surface* surface, const GPU_Rect* surface_rect) 2860 - { 2861 - renderer->impl->UpdateSubImage(renderer, image, NULL, surface, surface_rect); 2862 - } 2863 - 2864 - 2865 - static void UpdateSubImage(GPU_Renderer* renderer, GPU_Image* image, const GPU_Rect* image_rect, SDL_Surface* surface, const GPU_Rect* surface_rect) 2874 + static void UpdateImage(GPU_Renderer* renderer, GPU_Image* image, const GPU_Rect* image_rect, SDL_Surface* surface, const GPU_Rect* surface_rect) 2866 2875 { 2867 2876 GPU_IMAGE_DATA* data; 2868 2877 GLenum original_format; ··· 2882 2891 newSurface = copySurfaceIfNeeded(renderer, data->format, surface, &original_format); 2883 2892 if(newSurface == NULL) 2884 2893 { 2885 - GPU_PushErrorCode("GPU_UpdateSubImage", GPU_ERROR_BACKEND_ERROR, "Failed to convert surface to proper pixel format."); 2894 + GPU_PushErrorCode("GPU_UpdateImage", GPU_ERROR_BACKEND_ERROR, "Failed to convert surface to proper pixel format."); 2886 2895 return; 2887 2896 } 2888 2897 ··· 2899 2908 updateRect.h += updateRect.y; 2900 2909 updateRect.y = 0; 2901 2910 } 2902 - if(updateRect.x + updateRect.w > image->w) 2903 - updateRect.w += image->w - (updateRect.x + updateRect.w); 2904 - if(updateRect.y + updateRect.h > image->h) 2905 - updateRect.h += image->h - (updateRect.y + updateRect.h); 2911 + if(updateRect.x + updateRect.w > image->base_w) 2912 + updateRect.w += image->base_w - (updateRect.x + updateRect.w); 2913 + if(updateRect.y + updateRect.h > image->base_h) 2914 + updateRect.h += image->base_h - (updateRect.y + updateRect.h); 2906 2915 2907 2916 if(updateRect.w <= 0) 2908 2917 updateRect.w = 0; ··· 2913 2922 { 2914 2923 updateRect.x = 0; 2915 2924 updateRect.y = 0; 2916 - updateRect.w = image->w; 2917 - updateRect.h = image->h; 2925 + updateRect.w = image->base_w; 2926 + updateRect.h = image->base_h; 2918 2927 if(updateRect.w < 0.0f || updateRect.h < 0.0f) 2919 2928 { 2920 - GPU_PushErrorCode("GPU_UpdateSubImage", GPU_ERROR_USER_ERROR, "Given negative image rectangle."); 2929 + GPU_PushErrorCode("GPU_UpdateImage", GPU_ERROR_USER_ERROR, "Given negative image rectangle."); 2921 2930 return; 2922 2931 } 2923 2932 } ··· 3019 3028 updateRect.h += updateRect.y; 3020 3029 updateRect.y = 0; 3021 3030 } 3022 - if(updateRect.x + updateRect.w > image->w) 3023 - updateRect.w += image->w - (updateRect.x + updateRect.w); 3024 - if(updateRect.y + updateRect.h > image->h) 3025 - updateRect.h += image->h - (updateRect.y + updateRect.h); 3031 + if(updateRect.x + updateRect.w > image->base_w) 3032 + updateRect.w += image->base_w - (updateRect.x + updateRect.w); 3033 + if(updateRect.y + updateRect.h > image->base_h) 3034 + updateRect.h += image->base_h - (updateRect.y + updateRect.h); 3026 3035 3027 3036 if(updateRect.w <= 0) 3028 3037 updateRect.w = 0; ··· 3033 3042 { 3034 3043 updateRect.x = 0; 3035 3044 updateRect.y = 0; 3036 - updateRect.w = image->w; 3037 - updateRect.h = image->h; 3045 + updateRect.w = image->base_w; 3046 + updateRect.h = image->base_h; 3038 3047 if(updateRect.w < 0.0f || updateRect.h < 0.0f) 3039 3048 { 3040 - GPU_PushErrorCode("GPU_UpdateSubImage", GPU_ERROR_USER_ERROR, "Given negative image rectangle."); 3049 + GPU_PushErrorCode("GPU_UpdateImage", GPU_ERROR_USER_ERROR, "Given negative image rectangle."); 3041 3050 return; 3042 3051 } 3043 3052 } ··· 3128 3137 if(image == NULL) 3129 3138 return NULL; 3130 3139 3131 - renderer->impl->UpdateImage(renderer, image, surface, NULL); 3140 + renderer->impl->UpdateImage(renderer, image, NULL, surface, NULL); 3132 3141 3133 3142 return image; 3134 3143 } ··· 3238 3247 result->h = image->h; 3239 3248 result->base_w = image->texture_w; 3240 3249 result->base_h = image->texture_h; 3250 + result->using_virtual_resolution = image->using_virtual_resolution; 3241 3251 3242 3252 result->viewport = GPU_MakeRect(0, 0, result->w, result->h); 3243 3253 ··· 3529 3539 h = src_rect->h; 3530 3540 } 3531 3541 3542 + if(image->using_virtual_resolution) 3543 + { 3544 + // Scale texture coords to fit the original dims 3545 + x1 *= image->base_w/(float)image->w; 3546 + y1 *= image->base_h/(float)image->h; 3547 + x2 *= image->base_w/(float)image->w; 3548 + y2 *= image->base_h/(float)image->h; 3549 + } 3550 + 3532 3551 // Center the image on the given coords 3533 3552 dx1 = x - w/2.0f; 3534 3553 dy1 = y - h/2.0f; ··· 3740 3759 y2 = (src_rect->y + src_rect->h)/(float)tex_h; 3741 3760 w = src_rect->w; 3742 3761 h = src_rect->h; 3762 + } 3763 + 3764 + if(image->using_virtual_resolution) 3765 + { 3766 + // Scale texture coords to fit the original dims 3767 + x1 *= image->base_w/(float)image->w; 3768 + y1 *= image->base_h/(float)image->h; 3769 + x2 *= image->base_w/(float)image->w; 3770 + y2 *= image->base_h/(float)image->h; 3743 3771 } 3744 3772 3745 3773 // Center the image on the given coords (offset later) ··· 6196 6224 impl->SaveImage = &SaveImage; \ 6197 6225 impl->CopyImage = &CopyImage; \ 6198 6226 impl->UpdateImage = &UpdateImage; \ 6199 - impl->UpdateSubImage = &UpdateSubImage; \ 6200 6227 impl->UpdateImageBytes = &UpdateImageBytes; \ 6201 6228 impl->CopyImageFromSurface = &CopyImageFromSurface; \ 6202 6229 impl->CopyImageFromTarget = &CopyImageFromTarget; \
+4 -4
tests/color/main.c
··· 19 19 } 20 20 } 21 21 22 - GPU_UpdateImage(image, surface, NULL); 22 + GPU_UpdateImage(image, NULL, surface, NULL); 23 23 SDL_FreeSurface(surface); 24 24 } 25 25 ··· 43 43 } 44 44 } 45 45 46 - GPU_UpdateImage(image, surface, NULL); 46 + GPU_UpdateImage(image, NULL, surface, NULL); 47 47 SDL_FreeSurface(surface); 48 48 } 49 49 ··· 192 192 } 193 193 } 194 194 195 - GPU_UpdateImage(image, surface, NULL); 195 + GPU_UpdateImage(image, NULL, surface, NULL); 196 196 SDL_FreeSurface(surface); 197 197 } 198 198 ··· 242 242 } 243 243 } 244 244 245 - GPU_UpdateImage(image, surface, NULL); 245 + GPU_UpdateImage(image, NULL, surface, NULL); 246 246 SDL_FreeSurface(surface); 247 247 } 248 248
+8 -8
tests/renderer/main.c
··· 451 451 result->data = NULL; // Allocate a data structure as needed for other image data 452 452 result->is_alias = 0; 453 453 454 + result->using_virtual_resolution = 0; 454 455 result->w = w; 455 456 result->h = h; 456 457 result->base_w = w; ··· 501 502 502 503 static Uint8 SaveImage(GPU_Renderer* renderer, GPU_Image* image, const char* filename, GPU_FileFormatEnum format) 503 504 { 505 + SDL_Surface* surface; 506 + 504 507 GPU_Log(" %s (dummy)\n", __func__); 505 508 509 + surface = GPU_CopySurfaceFromImage(image); 510 + GPU_SaveSurface(surface, filename, format); 511 + 512 + SDL_FreeSurface(surface); 506 513 return 1; 507 514 } 508 515 ··· 518 525 } 519 526 520 527 521 - static void UpdateImage(GPU_Renderer* renderer, GPU_Image* image, SDL_Surface* surface, const GPU_Rect* surface_rect) 522 - { 523 - GPU_Log(" %s (dummy)\n", __func__); 524 - } 525 - 526 - 527 - static void UpdateSubImage(GPU_Renderer* renderer, GPU_Image* image, const GPU_Rect* image_rect, SDL_Surface* surface, const GPU_Rect* surface_rect) 528 + static void UpdateImage(GPU_Renderer* renderer, GPU_Image* image, const GPU_Rect* image_rect, SDL_Surface* surface, const GPU_Rect* surface_rect) 528 529 { 529 530 GPU_Log(" %s (dummy)\n", __func__); 530 531 } ··· 1207 1208 impl->SaveImage = &SaveImage; 1208 1209 impl->CopyImage = &CopyImage; 1209 1210 impl->UpdateImage = &UpdateImage; 1210 - impl->UpdateSubImage = &UpdateSubImage; 1211 1211 impl->UpdateImageBytes = &UpdateImageBytes; 1212 1212 impl->CopyImageFromSurface = &CopyImageFromSurface; 1213 1213 impl->CopyImageFromTarget = &CopyImageFromTarget;
+1 -1
tests/upload-image/main.c
··· 196 196 197 197 GPU_Clear(screen); 198 198 199 - GPU_UpdateSubImage(image, &image_rect, surface, &surface_rect); 199 + GPU_UpdateImage(image, &image_rect, surface, &surface_rect); 200 200 201 201 GPU_Blit(image, NULL, screen, screen->w/2, screen->h/2); 202 202 GPU_Rectangle(screen, screen->w/2 - image->w/2, screen->h/2 - image->h/2,