this repo has no description
0
fork

Configure Feed

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

Applied new version of compareFormats() (thanks Vitaly!).

+311 -333
+311 -320
SDL_gpu/OpenGL_common/SDL_gpu_OpenGL.c
··· 38 38 else 39 39 enabled_features &= ~GPU_FEATURE_NON_POWER_OF_TWO; 40 40 #elif defined(SDL_GPU_USE_OPENGLES) 41 - if(isExtensionSupported("GL_OES_texture_npot")) 41 + if(isExtensionSupported("GL_OES_texture_npot")) 42 42 enabled_features |= GPU_FEATURE_NON_POWER_OF_TWO; 43 43 else 44 44 enabled_features &= ~GPU_FEATURE_NON_POWER_OF_TWO; ··· 53 53 else 54 54 enabled_features &= ~GPU_FEATURE_RENDER_TARGETS; 55 55 #elif defined(SDL_GPU_USE_OPENGLES) 56 - if(isExtensionSupported("GL_OES_framebuffer_object")) 56 + if(isExtensionSupported("GL_OES_framebuffer_object")) 57 57 enabled_features |= GPU_FEATURE_RENDER_TARGETS; 58 58 else 59 59 enabled_features &= ~GPU_FEATURE_RENDER_TARGETS; ··· 66 66 enabled_features |= GPU_FEATURE_BLEND_EQUATIONS; 67 67 enabled_features |= GPU_FEATURE_BLEND_FUNC_SEPARATE; 68 68 #elif defined(SDL_GPU_USE_OPENGLES) 69 - if(isExtensionSupported("GL_OES_blend_subtract")) 69 + if(isExtensionSupported("GL_OES_blend_subtract")) 70 70 enabled_features |= GPU_FEATURE_BLEND_EQUATIONS; 71 71 else 72 72 enabled_features &= ~GPU_FEATURE_BLEND_EQUATIONS; 73 - if(isExtensionSupported("GL_OES_blend_func_separate")) 73 + if(isExtensionSupported("GL_OES_blend_func_separate")) 74 74 enabled_features |= GPU_FEATURE_BLEND_FUNC_SEPARATE; 75 75 else 76 76 enabled_features &= ~GPU_FEATURE_BLEND_FUNC_SEPARATE; ··· 86 86 87 87 static inline Uint8 isPowerOfTwo(unsigned int x) 88 88 { 89 - return ((x != 0) && !(x & (x - 1))); 89 + return ((x != 0) && !(x & (x - 1))); 90 90 } 91 91 92 92 static inline unsigned int getNearestPowerOf2(unsigned int n) 93 93 { 94 - unsigned int x = 1; 95 - while(x < n) 96 - { 97 - x <<= 1; 98 - } 99 - return x; 94 + unsigned int x = 1; 95 + while(x < n) 96 + { 97 + x <<= 1; 98 + } 99 + return x; 100 100 } 101 101 102 102 void bindTexture(GPU_Renderer* renderer, GPU_Image* image) ··· 106 106 { 107 107 GLuint handle = ((ImageData_OpenGL*)image->data)->handle; 108 108 renderer->FlushBlitBuffer(renderer); 109 - 109 + 110 110 glBindTexture( GL_TEXTURE_2D, handle ); 111 111 ((RendererData_OpenGL*)renderer->data)->last_image = image; 112 112 } ··· 116 116 { 117 117 // Bind the texture to which subsequent calls refer 118 118 renderer->FlushBlitBuffer(renderer); 119 - 119 + 120 120 glBindTexture( GL_TEXTURE_2D, handle ); 121 121 ((RendererData_OpenGL*)renderer->data)->last_image = NULL; 122 122 } ··· 131 131 { 132 132 GLuint handle = ((TargetData_OpenGL*)target->data)->handle; 133 133 renderer->FlushBlitBuffer(renderer); 134 - 134 + 135 135 extBindFramebuffer(handle); 136 136 ((RendererData_OpenGL*)renderer->data)->last_target = target; 137 137 } ··· 147 147 { 148 148 // Bind the FBO 149 149 renderer->FlushBlitBuffer(renderer); 150 - 150 + 151 151 extBindFramebuffer(handle); 152 152 ((RendererData_OpenGL*)renderer->data)->last_target = NULL; 153 153 } ··· 172 172 static inline void flushBlitBufferIfCurrentFramebuffer(GPU_Renderer* renderer, GPU_Target* target) 173 173 { 174 174 if(target == ((RendererData_OpenGL*)renderer->data)->last_target 175 - || ((RendererData_OpenGL*)renderer->data)->last_target == NULL) 175 + || ((RendererData_OpenGL*)renderer->data)->last_target == NULL) 176 176 { 177 177 renderer->FlushBlitBuffer(renderer); 178 178 } ··· 181 181 static inline void flushAndClearBlitBufferIfCurrentFramebuffer(GPU_Renderer* renderer, GPU_Target* target) 182 182 { 183 183 if(target == ((RendererData_OpenGL*)renderer->data)->last_target 184 - || ((RendererData_OpenGL*)renderer->data)->last_target == NULL) 184 + || ((RendererData_OpenGL*)renderer->data)->last_target == NULL) 185 185 { 186 186 renderer->FlushBlitBuffer(renderer); 187 187 ((RendererData_OpenGL*)renderer->data)->last_target = NULL; ··· 216 216 if(window == NULL) 217 217 { 218 218 window = SDL_CreateWindow("", 219 - SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 220 - w, h, 221 - SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL); 219 + SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 220 + w, h, 221 + SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL); 222 222 223 223 ((RendererData_OpenGL*)renderer->data)->window = window; 224 224 if(window == NULL) ··· 226 226 GPU_LogError("Window creation failed.\n"); 227 227 return NULL; 228 228 } 229 - 229 + 230 230 SDL_GLContext context = SDL_GL_CreateContext(window); 231 231 ((RendererData_OpenGL*)renderer->data)->context = context; 232 232 } ··· 254 254 checkExtension("GL_EXT_framebuffer_object"); 255 255 checkExtension("GL_ARB_framebuffer_object"); // glGenerateMipmap 256 256 checkExtension("GL_EXT_framebuffer_blit"); 257 - 257 + 258 258 #elif defined(SDL_GPU_USE_OPENGLES) 259 - 259 + 260 260 checkExtension("GL_OES_framebuffer_object"); 261 261 checkExtension("GL_OES_blend_func_separate"); 262 262 checkExtension("GL_OES_blend_subtract"); // for glBlendEquationOES 263 - 263 + 264 264 #endif 265 - 265 + 266 266 initNPOT(); 267 267 initFBO(); 268 268 initBLEND(); 269 - 269 + 270 270 glEnable( GL_TEXTURE_2D ); 271 271 glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); 272 272 ··· 305 305 renderer->display->clipRect.y = 0; 306 306 renderer->display->clipRect.w = renderer->display->w; 307 307 renderer->display->clipRect.h = renderer->display->h; 308 - 308 + 309 309 RendererData_OpenGL* rdata = (RendererData_OpenGL*)renderer->data; 310 310 rdata->blit_buffer_max_size = GPU_BLIT_BUFFER_INIT_MAX_SIZE; 311 311 rdata->blit_buffer_size = 0; ··· 391 391 392 392 renderer->display->w = w; 393 393 renderer->display->h = h; 394 - 394 + 395 395 renderer->FlushBlitBuffer(renderer); 396 396 397 397 glMatrixMode( GL_PROJECTION ); ··· 453 453 { 454 454 renderer->camera = *cam; 455 455 } 456 - 456 + 457 457 renderer->FlushBlitBuffer(renderer); 458 458 459 459 glMatrixMode( GL_PROJECTION ); ··· 498 498 GPU_LogError("GPU_CreateUninitializedImage() could not create an image with %d color channels. Try 3 or 4 instead.\n", channels); 499 499 return NULL; 500 500 } 501 - 502 - GLuint handle; 503 - GLenum format; 504 - if(channels == 3) 505 - format = GL_RGB; 506 - else 507 - format = GL_RGBA; 508 - 509 - glGenTextures( 1, &handle ); 501 + 502 + GLuint handle; 503 + GLenum format; 504 + if(channels == 3) 505 + format = GL_RGB; 506 + else 507 + format = GL_RGBA; 508 + 509 + glGenTextures( 1, &handle ); 510 510 if(handle == 0) 511 511 { 512 512 GPU_LogError("GPU_CreateUninitializedImage() failed to generate a texture handle.\n"); 513 513 return NULL; 514 514 } 515 - 515 + 516 516 flushAndBindTexture( renderer, handle ); 517 517 518 518 // Set the texture's stretching properties ··· 553 553 } 554 554 555 555 GPU_Image* result = CreateUninitializedImage(renderer, w, h, channels); 556 - 556 + 557 557 if(result == NULL) 558 558 { 559 559 GPU_LogError("GPU_CreateImage() could not create %ux%ux%u image.\n", w, h, channels); 560 560 return NULL; 561 561 } 562 - 562 + 563 563 glEnable(GL_TEXTURE_2D); 564 564 bindTexture(renderer, result); 565 - 565 + 566 566 GLenum internal_format = ((ImageData_OpenGL*)(result->data))->format; 567 567 w = result->w; 568 568 h = result->h; ··· 573 573 if(!isPowerOfTwo(h)) 574 574 h = getNearestPowerOf2(h); 575 575 } 576 - 576 + 577 577 // Initialize texture 578 - glTexImage2D(GL_TEXTURE_2D, 0, internal_format, w, h, 0, 579 - internal_format, GL_UNSIGNED_BYTE, NULL); 578 + glTexImage2D(GL_TEXTURE_2D, 0, internal_format, w, h, 0, 579 + internal_format, GL_UNSIGNED_BYTE, NULL); 580 580 // Tell SDL_gpu what we got. 581 581 ((ImageData_OpenGL*)(result->data))->tex_w = w; 582 582 ((ImageData_OpenGL*)(result->data))->tex_h = h; 583 - 583 + 584 584 return result; 585 585 } 586 586 ··· 592 592 GPU_LogError("Failed to load image \"%s\"\n", filename); 593 593 return NULL; 594 594 } 595 - 595 + 596 596 GPU_Image* result = renderer->CopyImageFromSurface(renderer, surface); 597 597 SDL_FreeSurface(surface); 598 - 598 + 599 599 return result; 600 600 } 601 601 ··· 624 624 const char* extension; 625 625 Uint8 result; 626 626 unsigned char* data; 627 - 628 - if(image == NULL || filename == NULL || 629 - image->w < 1 || image->h < 1 || image->channels < 1 || image->channels > 4) 630 - { 631 - return 0; 632 - } 627 + 628 + if(image == NULL || filename == NULL || 629 + image->w < 1 || image->h < 1 || image->channels < 1 || image->channels > 4) 630 + { 631 + return 0; 632 + } 633 633 634 634 if(strlen(filename) < 5) 635 635 { ··· 647 647 } 648 648 649 649 data = getRawImageData(renderer, image); 650 - 650 + 651 651 if(data == NULL) 652 652 { 653 653 GPU_LogError("GPU_SaveImage() failed: Could not retrieve image data.\n"); ··· 724 724 SDL_PixelFormat* format = surface->format; 725 725 switch(glFormat) 726 726 { 727 - case GL_RGB: 728 - #ifdef GL_BGR 729 - case GL_BGR: 730 - #endif 731 - //GPU_LogError("Wanted 3 channels, got %d\n", format->BytesPerPixel); 732 - if(format->BytesPerPixel != 3) 733 - return 1; 734 - 735 - if(format->Rmask == 0x0000FF && 736 - format->Gmask == 0x00FF00 && 737 - format->Bmask == 0xFF0000) 738 - { 739 - if(surfaceFormatResult != NULL) 740 - *surfaceFormatResult = GL_RGB; 741 - return 0; 742 - } 743 - #ifdef GL_BGR 744 - if(format->Rmask == 0xFF0000 && 745 - format->Gmask == 0x00FF00 && 746 - format->Bmask == 0x0000FF) 747 - { 748 - if(surfaceFormatResult != NULL) 749 - *surfaceFormatResult = GL_BGR; 750 - return 0; 751 - } 752 - #endif 753 - //GPU_LogError("Masks don't match\n"); 754 - return 1; 755 - 756 - case GL_RGBA: 757 - #ifdef GL_BGRA 758 - case GL_BGRA: 759 - #endif 760 - //GPU_LogError("Wanted 4 channels, got %d\n", format->BytesPerPixel); 761 - if(format->BytesPerPixel != 4) 762 - return 1; 763 - 764 - if(format->Rmask == 0x000000FF && 765 - format->Gmask == 0x0000FF00 && 766 - format->Bmask == 0x00FF0000) 767 - { 768 - if(surfaceFormatResult != NULL) 769 - *surfaceFormatResult = GL_RGBA; 770 - return 0; 771 - } 772 - if(format->Rmask == 0x0000FF && 773 - format->Gmask == 0x00FF00 && 774 - format->Bmask == 0xFF0000) 775 - { 776 - if(surfaceFormatResult != NULL) 777 - *surfaceFormatResult = GL_RGBA; 778 - return 0; 779 - } 780 - #ifdef GL_BGRA 781 - if(format->Rmask == 0xFF000000 && 782 - format->Gmask == 0x00FF0000 && 783 - format->Bmask == 0x0000FF00) 784 - { 785 - if(surfaceFormatResult != NULL) 786 - *surfaceFormatResult = GL_BGRA; 787 - return 0; 788 - } 789 - if(format->Rmask == 0xFF0000 && 790 - format->Gmask == 0x00FF00 && 791 - format->Bmask == 0x0000FF) 792 - { 793 - if(surfaceFormatResult != NULL) 794 - *surfaceFormatResult = GL_BGRA; 795 - return 0; 796 - } 797 - #endif 798 - //GPU_LogError("Masks don't match: %X, %X, %X\n", format->Rmask, format->Gmask, format->Bmask); 799 - return 1; 800 - default: 801 - GPU_LogError("GPU_UpdateImage() was passed an image with an invalid format.\n"); 802 - return -1; 727 + case GL_RGB: 728 + #ifdef GL_BGR 729 + case GL_BGR: 730 + #endif 731 + //GPU_LogError("Wanted 3 channels, got %d\n", format->BytesPerPixel); 732 + if(format->BytesPerPixel != 3) return 1; 733 + 734 + //SDL_BYTEORDER == SDL_LIL_ENDIAN case BGR 735 + if (format->Rmask == 0x0000FF && format->Gmask == 0x00FF00 && format->Bmask == 0xFF0000) { 736 + if ( surfaceFormatResult != NULL) { 737 + #ifdef GL_BGR 738 + *surfaceFormatResult = GL_BGR; 739 + #else 740 + GPU_LogError("GL_BGR is unsupported, using GL_RGB\n"); 741 + *surfaceFormatResult = GL_RGB; 742 + #endif 743 + } 744 + return 0; 745 + //SDL_BYTEORDER == SDL_BIG_ENDIAN case RGB 746 + } else if (format->Rmask == 0xFF0000 && format->Gmask == 0x00FF00 && format->Bmask == 0x0000FF) { 747 + if ( surfaceFormatResult != NULL) { 748 + *surfaceFormatResult = GL_RGB; 749 + } 750 + return 0; 751 + } else { 752 + return 1; 753 + } 754 + 755 + case GL_RGBA: 756 + #ifdef GL_BGRA 757 + case GL_BGRA: 758 + #endif 759 + #ifdef GL_ABGR_EXT 760 + case GL_ABGR_EXT: 761 + #endif 762 + //GPU_LogError("Wanted 4 channels, got %d\n", format->BytesPerPixel); 763 + if(format->BytesPerPixel != 4) return 1; 764 + 765 + //SDL_BYTEORDER == SDL_LIL_ENDIAN case ABGR 766 + if(format->Rmask == 0x000000FF && format->Gmask == 0x0000FF00 && format->Bmask == 0x00FF0000) { 767 + if ( surfaceFormatResult != NULL) { 768 + #ifdef GL_ABGR_EXT 769 + *surfaceFormatResult = GL_ABGR_EXT; 770 + #else 771 + GPU_LogError("GL_ABGR_EXT is unsupported, using GL_RGBA\n"); 772 + *surfaceFormatResult = GL_RGBA; 773 + #endif 774 + } 775 + return 0; 776 + //SDL_BYTEORDER == SDL_BIG_ENDIAN case RGBA 777 + } else if (format->Rmask == 0xFF000000 && format->Gmask == 0x00FF0000 && format->Bmask == 0x0000FF00) { 778 + if ( surfaceFormatResult != NULL) { 779 + *surfaceFormatResult = GL_RGBA; 780 + } 781 + return 0; 782 + //Something custom BGRA 783 + #ifdef GL_BGRA 784 + } else if (format->Rmask == 0x0000FF00 && format->Gmask == 0x00FF0000 && format->Bmask == 0xFF000000) { 785 + if(surfaceFormatResult != NULL) *surfaceFormatResult = GL_BGRA; 786 + return 0; 787 + #endif 788 + } 789 + //GPU_LogError("Masks don't match: %X, %X, %X\n", format->Rmask, format->Gmask, format->Bmask); 790 + return 1; 791 + default: 792 + GPU_LogError("GPU_UpdateImage() was passed an image with an invalid format.\n"); 793 + return -1; 803 794 } 804 795 } 805 796 ··· 810 801 // Yes, I need to do the whole thing myself... :( 811 802 int channels; 812 803 Uint32 Rmask, Gmask, Bmask, Amask, mask; 813 - 804 + 814 805 switch(glFormat) 815 806 { 816 - case GL_RGB: 817 - channels = 3; 818 - Rmask = 0x0000FF; 819 - Gmask = 0x00FF00; 820 - Bmask = 0xFF0000; 821 - break; 822 - #ifdef GL_BGR 823 - case GL_BGR: 824 - channels = 3; 825 - Rmask = 0xFF0000; 826 - Gmask = 0x00FF00; 827 - Bmask = 0x0000FF; 828 - break; 829 - #endif 830 - case GL_RGBA: 831 - channels = 4; 832 - Rmask = 0x000000FF; 833 - Gmask = 0x0000FF00; 834 - Bmask = 0x00FF0000; 835 - Amask = 0xFF000000; 836 - break; 837 - #ifdef GL_BGRA 838 - case GL_BGRA: 839 - channels = 4; 840 - Rmask = 0xFF000000; 841 - Gmask = 0x00FF0000; 842 - Bmask = 0x0000FF00; 843 - Amask = 0x000000FF; 844 - break; 845 - #endif 846 - default: 847 - return NULL; 807 + case GL_RGB: 808 + channels = 3; 809 + Rmask = 0x0000FF; 810 + Gmask = 0x00FF00; 811 + Bmask = 0xFF0000; 812 + break; 813 + #ifdef GL_BGR 814 + case GL_BGR: 815 + channels = 3; 816 + Rmask = 0xFF0000; 817 + Gmask = 0x00FF00; 818 + Bmask = 0x0000FF; 819 + break; 820 + #endif 821 + case GL_RGBA: 822 + channels = 4; 823 + Rmask = 0x000000FF; 824 + Gmask = 0x0000FF00; 825 + Bmask = 0x00FF0000; 826 + Amask = 0xFF000000; 827 + break; 828 + #ifdef GL_BGRA 829 + case GL_BGRA: 830 + channels = 4; 831 + Rmask = 0xFF000000; 832 + Gmask = 0x00FF0000; 833 + Bmask = 0x0000FF00; 834 + Amask = 0x000000FF; 835 + break; 836 + #endif 837 + default: 838 + return NULL; 848 839 } 849 - 840 + 850 841 SDL_PixelFormat* result = (SDL_PixelFormat*)malloc(sizeof(SDL_PixelFormat)); 851 842 memset(result, 0, sizeof(SDL_PixelFormat)); 852 - 853 - result->BitsPerPixel = 8*channels; 854 - result->BytesPerPixel = channels; 855 - 843 + 844 + result->BitsPerPixel = 8*channels; 845 + result->BytesPerPixel = channels; 846 + 856 847 result->Rmask = Rmask; 857 848 result->Rshift = 0; 858 849 result->Rloss = 8; ··· 898 889 899 890 static Uint8 hasColorkey(SDL_Surface* surface) 900 891 { 901 - #ifdef SDL_GPU_USE_SDL2 892 + #ifdef SDL_GPU_USE_SDL2 902 893 return (SDL_GetColorKey(surface, NULL) == 0); 903 - #else 894 + #else 904 895 return (surface->flags & SDL_SRCCOLORKEY); 905 - #endif 896 + #endif 906 897 } 907 898 908 899 static void FreeFormat(SDL_PixelFormat* format) ··· 913 904 // Returns NULL on failure. Returns the original surface if no copy is needed. Returns a new surface converted to the right format otherwise. 914 905 static SDL_Surface* copySurfaceIfNeeded(GLenum glFormat, SDL_Surface* surface, GLenum* surfaceFormatResult) 915 906 { 916 - // If format doesn't match, we need to do a copy 907 + // If format doesn't match, we need to do a copy 917 908 int format_compare = compareFormats(glFormat, surface, surfaceFormatResult); 918 - 919 - // There's a problem 909 + 910 + // There's a problem 920 911 if(format_compare < 0) 921 - return NULL; 922 - 912 + return NULL; 913 + 923 914 // Copy it 924 915 if(format_compare > 0) 925 916 { 926 - // Convert to the right format 917 + // Convert to the right format 927 918 SDL_PixelFormat* dst_fmt = AllocFormat(glFormat); 928 919 surface = SDL_ConvertSurface(surface, dst_fmt, 0); 929 920 FreeFormat(dst_fmt); 930 - if(surfaceFormatResult != NULL && surface != NULL) 931 - *surfaceFormatResult = glFormat; 921 + if(surfaceFormatResult != NULL && surface != NULL) 922 + *surfaceFormatResult = glFormat; 932 923 } 933 - 924 + 934 925 // No copy needed 935 926 return surface; 936 927 } ··· 940 931 { 941 932 if(renderer == NULL || image == NULL || surface == NULL) 942 933 return; 943 - 934 + 944 935 ImageData_OpenGL* data = (ImageData_OpenGL*)image->data; 945 - 936 + 946 937 SDL_Surface* newSurface = copySurfaceIfNeeded(data->format, surface, NULL); 947 938 if(newSurface == NULL) 948 939 { 949 940 GPU_LogError("GPU_UpdateImage() failed to convert surface to proper pixel format.\n"); 950 941 return; 951 942 } 952 - 953 - 943 + 944 + 954 945 SDL_Rect updateRect; 955 946 if(rect != NULL) 956 947 updateRect = *rect; ··· 961 952 updateRect.w = newSurface->w; 962 953 updateRect.h = newSurface->h; 963 954 } 964 - 965 - 955 + 956 + 966 957 glEnable(GL_TEXTURE_2D); 967 958 if(image->target != NULL) 968 959 flushBlitBufferIfCurrentFramebuffer(renderer, image->target); ··· 974 965 //glPixelStorei(GL_UNPACK_ROW_LENGTH, 975 966 // (newSurface->pitch / newSurface->format->BytesPerPixel)); 976 967 glTexSubImage2D(GL_TEXTURE_2D, 0, updateRect.x, updateRect.y, updateRect.w, 977 - updateRect.h, data->format, GL_UNSIGNED_BYTE, 978 - newSurface->pixels); 979 - 980 - // Delete temporary surface 968 + updateRect.h, data->format, GL_UNSIGNED_BYTE, 969 + newSurface->pixels); 970 + 971 + // Delete temporary surface 981 972 if(surface != newSurface) 982 973 SDL_FreeSurface(newSurface); 983 974 } ··· 988 979 ImageData_OpenGL* data = (ImageData_OpenGL*)image->data; 989 980 if(renderer == NULL || image == NULL || surface == NULL) 990 981 return 0; 991 - 982 + 992 983 GLenum internal_format = data->format; 993 984 GLenum original_format = internal_format; 994 - 985 + 995 986 SDL_Surface* newSurface = copySurfaceIfNeeded(internal_format, surface, &original_format); 996 987 if(newSurface == NULL) 997 - { 988 + { 998 989 GPU_LogError("GPU_InitImageWithSurface() failed to convert surface to proper pixel format.\n"); 999 - return 0; 1000 - } 1001 - 990 + return 0; 991 + } 992 + 1002 993 Uint8 need_power_of_two_upload = 0; 1003 994 unsigned int w = newSurface->w; 1004 995 unsigned int h = newSurface->h; ··· 1015 1006 need_power_of_two_upload = 1; 1016 1007 } 1017 1008 } 1018 - 1009 + 1019 1010 glEnable(GL_TEXTURE_2D); 1020 1011 bindTexture(renderer, image); 1021 1012 int alignment = 1; 1022 1013 if(newSurface->format->BytesPerPixel == 4) 1023 1014 alignment = 4; 1024 - 1015 + 1025 1016 glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); 1026 1017 //glPixelStorei(GL_UNPACK_ROW_LENGTH, 1027 1018 // (newSurface->pitch / newSurface->format->BytesPerPixel)); 1028 1019 if(!need_power_of_two_upload) 1029 1020 { 1030 - glTexImage2D(GL_TEXTURE_2D, 0, internal_format, newSurface->w, newSurface->h, 0, 1031 - original_format, GL_UNSIGNED_BYTE, newSurface->pixels); 1021 + glTexImage2D(GL_TEXTURE_2D, 0, internal_format, newSurface->w, newSurface->h, 0, 1022 + original_format, GL_UNSIGNED_BYTE, newSurface->pixels); 1032 1023 } 1033 1024 else 1034 1025 { 1035 1026 // Create POT texture 1036 - glTexImage2D(GL_TEXTURE_2D, 0, internal_format, w, h, 0, 1037 - original_format, GL_UNSIGNED_BYTE, NULL); 1038 - 1027 + glTexImage2D(GL_TEXTURE_2D, 0, internal_format, w, h, 0, 1028 + original_format, GL_UNSIGNED_BYTE, NULL); 1029 + 1039 1030 // Upload NPOT data 1040 1031 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, newSurface->w, newSurface->h, 1041 - original_format, GL_UNSIGNED_BYTE, newSurface->pixels); 1042 - 1032 + original_format, GL_UNSIGNED_BYTE, newSurface->pixels); 1033 + 1043 1034 // Tell everyone what we did. 1044 1035 ((ImageData_OpenGL*)(image->data))->tex_w = w; 1045 1036 ((ImageData_OpenGL*)(image->data))->tex_h = h; 1046 1037 } 1047 - 1048 - // Delete temporary surface 1038 + 1039 + // Delete temporary surface 1049 1040 if(surface != newSurface) 1050 1041 SDL_FreeSurface(newSurface); 1051 1042 return 1; ··· 1074 1065 } else { 1075 1066 needAlpha = 0; 1076 1067 } 1077 - 1068 + 1078 1069 // Get appropriate storage format 1079 1070 // TODO: More options would be nice... 1080 1071 if(needAlpha) ··· 1085 1076 { 1086 1077 channels = 3; 1087 1078 } 1088 - 1079 + 1089 1080 image = CreateUninitializedImage(renderer, surface->w, surface->h, channels); 1090 1081 if(image == NULL) 1091 1082 return NULL; ··· 1107 1098 { 1108 1099 if(image == NULL) 1109 1100 return; 1110 - 1101 + 1111 1102 // Delete the attached target first 1112 1103 if(image->target != NULL) 1113 1104 renderer->FreeTarget(renderer, image->target); 1114 - 1105 + 1115 1106 flushAndClearBlitBufferIfCurrentTexture(renderer, image); 1116 1107 glDeleteTextures( 1, &((ImageData_OpenGL*)image->data)->handle); 1117 1108 free(image->data); ··· 1204 1195 1205 1196 if(image->target != NULL) 1206 1197 return image->target; 1207 - 1198 + 1208 1199 if(!(enabled_features & GPU_FEATURE_RENDER_TARGETS)) 1209 1200 return NULL; 1210 - 1201 + 1211 1202 GLuint handle; 1212 1203 // Create framebuffer object 1213 1204 glGenFramebuffers(1, &handle); ··· 1235 1226 result->clipRect.y = 0; 1236 1227 result->clipRect.w = image->w; 1237 1228 result->clipRect.h = image->h; 1238 - 1229 + 1239 1230 image->target = result; 1240 1231 return result; 1241 1232 } ··· 1246 1237 { 1247 1238 if(target == NULL || target == renderer->display) 1248 1239 return; 1249 - 1240 + 1250 1241 if(enabled_features & GPU_FEATURE_RENDER_TARGETS) 1251 1242 { 1252 1243 flushAndClearBlitBufferIfCurrentFramebuffer(renderer, target); 1253 1244 glDeleteFramebuffers(1, &((TargetData_OpenGL*)target->data)->handle); 1254 1245 } 1255 - 1246 + 1256 1247 if(target->image != NULL) 1257 1248 target->image->target = NULL; // Remove reference to this object 1258 1249 free(target->data); ··· 1306 1297 dx2 = x + srcrect->w/2.0f; 1307 1298 dy2 = y + srcrect->h/2.0f; 1308 1299 } 1309 - 1300 + 1310 1301 RendererData_OpenGL* rdata = (RendererData_OpenGL*)renderer->data; 1311 1302 float* blit_buffer = rdata->blit_buffer; 1312 - 1303 + 1313 1304 if(rdata->blit_buffer_size + 6 >= rdata->blit_buffer_max_size) 1314 1305 renderer->FlushBlitBuffer(renderer); 1315 - 1306 + 1316 1307 int vert_index = GPU_BLIT_BUFFER_VERTEX_OFFSET + rdata->blit_buffer_size*GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 1317 1308 int tex_index = GPU_BLIT_BUFFER_TEX_COORD_OFFSET + rdata->blit_buffer_size*GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 1318 1309 ··· 1321 1312 blit_buffer[vert_index+2] = 0.0f; 1322 1313 blit_buffer[tex_index] = x1; 1323 1314 blit_buffer[tex_index+1] = y1; 1324 - 1315 + 1325 1316 vert_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 1326 1317 tex_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 1327 1318 blit_buffer[vert_index] = dx2; ··· 1329 1320 blit_buffer[vert_index+2] = 0.0f; 1330 1321 blit_buffer[tex_index] = x2; 1331 1322 blit_buffer[tex_index+1] = y1; 1332 - 1323 + 1333 1324 vert_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 1334 1325 tex_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 1335 1326 blit_buffer[vert_index] = dx2; ··· 1337 1328 blit_buffer[vert_index+2] = 0.0f; 1338 1329 blit_buffer[tex_index] = x2; 1339 1330 blit_buffer[tex_index+1] = y2; 1340 - 1341 - 1331 + 1332 + 1342 1333 // Second tri 1343 - 1334 + 1344 1335 vert_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 1345 1336 tex_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 1346 1337 blit_buffer[vert_index] = dx1; ··· 1348 1339 blit_buffer[vert_index+2] = 0.0f; 1349 1340 blit_buffer[tex_index] = x1; 1350 1341 blit_buffer[tex_index+1] = y1; 1351 - 1342 + 1352 1343 vert_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 1353 1344 tex_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 1354 1345 blit_buffer[vert_index] = dx2; ··· 1356 1347 blit_buffer[vert_index+2] = 0.0f; 1357 1348 blit_buffer[tex_index] = x2; 1358 1349 blit_buffer[tex_index+1] = y2; 1359 - 1350 + 1360 1351 vert_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 1361 1352 tex_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 1362 1353 blit_buffer[vert_index] = dx1; ··· 1364 1355 blit_buffer[vert_index+2] = 0.0f; 1365 1356 blit_buffer[tex_index] = x1; 1366 1357 blit_buffer[tex_index+1] = y2; 1367 - 1358 + 1368 1359 rdata->blit_buffer_size += 6; 1369 1360 } 1370 1361 ··· 1376 1367 { 1377 1368 if(src == NULL || dest == NULL) 1378 1369 return -1; 1379 - 1370 + 1380 1371 return renderer->BlitTransformX(renderer, src, srcrect, dest, x, y, src->w/2.0f, src->h/2.0f, angle, 1.0f, 1.0f); 1381 1372 } 1382 1373 ··· 1384 1375 { 1385 1376 if(src == NULL || dest == NULL) 1386 1377 return -1; 1387 - 1378 + 1388 1379 return renderer->BlitTransformX(renderer, src, srcrect, dest, x, y, src->w/2.0f, src->h/2.0f, 0.0f, scaleX, scaleY); 1389 1380 } 1390 1381 ··· 1392 1383 { 1393 1384 if(src == NULL || dest == NULL) 1394 1385 return -1; 1395 - 1386 + 1396 1387 return renderer->BlitTransformX(renderer, src, srcrect, dest, x, y, src->w/2.0f, src->h/2.0f, angle, scaleX, scaleY); 1397 1388 } 1398 1389 ··· 1447 1438 dx2 = srcrect->w/2.0f; 1448 1439 dy2 = srcrect->h/2.0f; 1449 1440 } 1450 - 1441 + 1451 1442 // Apply transforms 1452 - 1443 + 1453 1444 // Scale 1454 1445 if(scaleX != 1.0f || scaleY != 1.0f) 1455 1446 { ··· 1460 1451 dy1 = (dy2 + dy1)/2 - h/2; 1461 1452 dy2 = dy1 + h; 1462 1453 } 1463 - 1454 + 1464 1455 // Shift away from the center (these are relative to the image corner) 1465 1456 pivot_x -= src->w/2.0f; 1466 1457 pivot_y -= src->h/2.0f; ··· 1470 1461 dy1 -= pivot_y*scaleY; 1471 1462 dx2 -= pivot_x*scaleX; 1472 1463 dy2 -= pivot_y*scaleY; 1473 - 1464 + 1474 1465 // Get extra vertices for rotation 1475 1466 dx3 = dx2; 1476 1467 dy3 = dy1; 1477 1468 dx4 = dx1; 1478 1469 dy4 = dy2; 1479 - 1470 + 1480 1471 // Rotate about origin (the pivot) 1481 1472 if(angle != 0.0f) 1482 1473 { ··· 1495 1486 dx4 = dx4*cosA - dy4*sinA; 1496 1487 dy4 = tempX*sinA + dy4*cosA; 1497 1488 } 1498 - 1489 + 1499 1490 // Translate to pos 1500 1491 dx1 += x; 1501 1492 dx2 += x; ··· 1505 1496 dy2 += y; 1506 1497 dy3 += y; 1507 1498 dy4 += y; 1508 - 1499 + 1509 1500 RendererData_OpenGL* rdata = (RendererData_OpenGL*)renderer->data; 1510 1501 float* blit_buffer = rdata->blit_buffer; 1511 - 1502 + 1512 1503 if(rdata->blit_buffer_size + 6 >= rdata->blit_buffer_max_size) 1513 1504 renderer->FlushBlitBuffer(renderer); 1514 - 1505 + 1515 1506 int vert_index = GPU_BLIT_BUFFER_VERTEX_OFFSET + rdata->blit_buffer_size*GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 1516 1507 int tex_index = GPU_BLIT_BUFFER_TEX_COORD_OFFSET + rdata->blit_buffer_size*GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 1517 1508 ··· 1520 1511 blit_buffer[vert_index+2] = 0.0f; 1521 1512 blit_buffer[tex_index] = x1; 1522 1513 blit_buffer[tex_index+1] = y1; 1523 - 1514 + 1524 1515 vert_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 1525 1516 tex_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 1526 1517 blit_buffer[vert_index] = dx3; ··· 1528 1519 blit_buffer[vert_index+2] = 0.0f; 1529 1520 blit_buffer[tex_index] = x2; 1530 1521 blit_buffer[tex_index+1] = y1; 1531 - 1522 + 1532 1523 vert_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 1533 1524 tex_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 1534 1525 blit_buffer[vert_index] = dx2; ··· 1536 1527 blit_buffer[vert_index+2] = 0.0f; 1537 1528 blit_buffer[tex_index] = x2; 1538 1529 blit_buffer[tex_index+1] = y2; 1539 - 1540 - 1530 + 1531 + 1541 1532 // Second tri 1542 - 1533 + 1543 1534 vert_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 1544 1535 tex_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 1545 1536 blit_buffer[vert_index] = dx1; ··· 1547 1538 blit_buffer[vert_index+2] = 0.0f; 1548 1539 blit_buffer[tex_index] = x1; 1549 1540 blit_buffer[tex_index+1] = y1; 1550 - 1541 + 1551 1542 vert_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 1552 1543 tex_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 1553 1544 blit_buffer[vert_index] = dx2; ··· 1555 1546 blit_buffer[vert_index+2] = 0.0f; 1556 1547 blit_buffer[tex_index] = x2; 1557 1548 blit_buffer[tex_index+1] = y2; 1558 - 1549 + 1559 1550 vert_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 1560 1551 tex_index += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 1561 1552 blit_buffer[vert_index] = dx4; ··· 1563 1554 blit_buffer[vert_index+2] = 0.0f; 1564 1555 blit_buffer[tex_index] = x1; 1565 1556 blit_buffer[tex_index+1] = y2; 1566 - 1557 + 1567 1558 rdata->blit_buffer_size += 6; 1568 1559 } 1569 - 1560 + 1570 1561 return 0; 1571 1562 } 1572 1563 ··· 1617 1608 { 1618 1609 if(image == NULL) 1619 1610 return; 1620 - 1611 + 1621 1612 if(image->target != NULL) 1622 1613 flushBlitBufferIfCurrentFramebuffer(renderer, image->target); 1623 1614 bindTexture(renderer, image); ··· 1635 1626 1636 1627 static SDL_Rect SetClip(GPU_Renderer* renderer, GPU_Target* target, Sint16 x, Sint16 y, Uint16 w, Uint16 h) 1637 1628 { 1638 - if(target == NULL) 1639 - { 1640 - SDL_Rect r = {0,0,0,0}; 1641 - return r; 1642 - } 1643 - 1644 - flushBlitBufferIfCurrentFramebuffer(renderer, target); 1645 - target->useClip = 1; 1646 - 1647 - SDL_Rect r = target->clipRect; 1648 - 1649 - target->clipRect.x = x; 1650 - target->clipRect.y = y; 1651 - target->clipRect.w = w; 1652 - target->clipRect.h = h; 1653 - 1654 - return r; 1629 + if(target == NULL) 1630 + { 1631 + SDL_Rect r = {0,0,0,0}; 1632 + return r; 1633 + } 1634 + 1635 + flushBlitBufferIfCurrentFramebuffer(renderer, target); 1636 + target->useClip = 1; 1637 + 1638 + SDL_Rect r = target->clipRect; 1639 + 1640 + target->clipRect.x = x; 1641 + target->clipRect.y = y; 1642 + target->clipRect.w = w; 1643 + target->clipRect.h = h; 1644 + 1645 + return r; 1655 1646 } 1656 1647 1657 1648 static void ClearClip(GPU_Renderer* renderer, GPU_Target* target) 1658 1649 { 1659 - if(target == NULL) 1660 - return; 1661 - 1662 - flushBlitBufferIfCurrentFramebuffer(renderer, target); 1663 - target->useClip = 0; 1664 - target->clipRect.x = 0; 1665 - target->clipRect.y = 0; 1666 - target->clipRect.w = target->w; 1667 - target->clipRect.h = target->h; 1650 + if(target == NULL) 1651 + return; 1652 + 1653 + flushBlitBufferIfCurrentFramebuffer(renderer, target); 1654 + target->useClip = 0; 1655 + target->clipRect.x = 0; 1656 + target->clipRect.y = 0; 1657 + target->clipRect.w = target->w; 1658 + target->clipRect.h = target->h; 1668 1659 } 1669 1660 1670 1661 ··· 1680 1671 static void SetBlending(GPU_Renderer* renderer, Uint8 enable) 1681 1672 { 1682 1673 renderer->FlushBlitBuffer(renderer); 1683 - 1674 + 1684 1675 if(enable) 1685 1676 glEnable(GL_BLEND); 1686 1677 else ··· 1889 1880 return; 1890 1881 if(renderer != image->renderer) 1891 1882 return; 1892 - 1883 + 1893 1884 if(image->target != NULL) 1894 1885 flushBlitBufferIfCurrentFramebuffer(renderer, image->target); 1895 1886 bindTexture(renderer, image); ··· 2047 2038 result.r = pixels[0]; 2048 2039 result.g = pixels[1]; 2049 2040 result.b = pixels[2]; 2050 - #ifdef SDL_GPU_USE_SDL2 2041 + #ifdef SDL_GPU_USE_SDL2 2051 2042 result.a = pixels[3]; 2052 - #else 2043 + #else 2053 2044 result.unused = pixels[3]; 2054 - #endif 2045 + #endif 2055 2046 } 2056 2047 2057 2048 return result; ··· 2096 2087 static void SetBlendMode(GPU_Renderer* renderer, GPU_BlendEnum mode) 2097 2088 { 2098 2089 renderer->FlushBlitBuffer(renderer); 2099 - 2090 + 2100 2091 if(mode == GPU_BLEND_NORMAL) 2101 2092 { 2102 - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2093 + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2103 2094 if(!(enabled_features & GPU_FEATURE_BLEND_EQUATIONS)) 2104 2095 return; // TODO: Return false so we can avoid depending on it if it fails 2105 - glBlendEquation(GL_FUNC_ADD); 2096 + glBlendEquation(GL_FUNC_ADD); 2106 2097 } 2107 2098 else if(mode == GPU_BLEND_MULTIPLY) 2108 2099 { 2109 2100 if(!(enabled_features & GPU_FEATURE_BLEND_FUNC_SEPARATE)) 2110 2101 return; 2111 - glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2102 + glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2112 2103 if(!(enabled_features & GPU_FEATURE_BLEND_EQUATIONS)) 2113 2104 return; 2114 - glBlendEquation(GL_FUNC_ADD); 2105 + glBlendEquation(GL_FUNC_ADD); 2115 2106 } 2116 2107 else if(mode == GPU_BLEND_ADD) 2117 2108 { 2118 - glBlendFunc(GL_ONE, GL_ONE); 2109 + glBlendFunc(GL_ONE, GL_ONE); 2119 2110 if(!(enabled_features & GPU_FEATURE_BLEND_EQUATIONS)) 2120 2111 return; 2121 - glBlendEquation(GL_FUNC_ADD); 2112 + glBlendEquation(GL_FUNC_ADD); 2122 2113 } 2123 2114 else if(mode == GPU_BLEND_SUBTRACT) 2124 2115 { 2125 2116 if(!(enabled_features & GPU_FEATURE_BLEND_EQUATIONS)) 2126 2117 return; 2127 - glBlendFunc(GL_ONE, GL_ONE); 2128 - glBlendEquation(GL_FUNC_SUBTRACT); 2118 + glBlendFunc(GL_ONE, GL_ONE); 2119 + glBlendEquation(GL_FUNC_SUBTRACT); 2129 2120 } 2130 2121 else if(mode == GPU_BLEND_ADD_COLOR) 2131 2122 { 2132 2123 if(!(enabled_features & GPU_FEATURE_BLEND_FUNC_SEPARATE)) 2133 2124 return; 2134 - glBlendFuncSeparate(GL_ONE, GL_ONE, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2125 + glBlendFuncSeparate(GL_ONE, GL_ONE, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2135 2126 if(!(enabled_features & GPU_FEATURE_BLEND_EQUATIONS)) 2136 2127 return; 2137 - glBlendEquation(GL_FUNC_ADD); 2128 + glBlendEquation(GL_FUNC_ADD); 2138 2129 } 2139 2130 else if(mode == GPU_BLEND_SUBTRACT_COLOR) 2140 2131 { ··· 2152 2143 if(!(enabled_features & GPU_FEATURE_BLEND_EQUATIONS)) 2153 2144 return; 2154 2145 glBlendFuncSeparate(GL_ONE, GL_ONE, GL_ONE, GL_ZERO); 2155 - glBlendEquation(GL_FUNC_SUBTRACT); 2146 + glBlendEquation(GL_FUNC_SUBTRACT); 2156 2147 } 2157 2148 else if(mode == GPU_BLEND_PUNCHOUT) 2158 2149 { 2159 2150 if(!(enabled_features & GPU_FEATURE_BLEND_EQUATIONS)) 2160 2151 return; 2161 - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2162 - glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); 2152 + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2153 + glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); 2163 2154 } 2164 2155 else if(mode == GPU_BLEND_CUTOUT) 2165 2156 { 2166 2157 if(!(enabled_features & GPU_FEATURE_BLEND_EQUATIONS)) 2167 2158 return; 2168 - glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA); 2169 - glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); 2159 + glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA); 2160 + glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); 2170 2161 } 2171 2162 } 2172 2163 ··· 2268 2259 if(rdata->blit_buffer_size > 0 && rdata->last_target != NULL && rdata->last_image != NULL) 2269 2260 { 2270 2261 Uint8 isRTT = (renderer->display != rdata->last_target); 2271 - 2262 + 2272 2263 glEnable(GL_TEXTURE_2D); 2273 2264 GPU_Target* dest = rdata->last_target; 2274 - 2265 + 2275 2266 // Modify the viewport and projection matrix if rendering to a texture 2276 2267 GLint vp[4]; 2277 2268 if(isRTT) ··· 2301 2292 float yFactor = ((float)renderer->window_h)/renderer->display->h; 2302 2293 glScissor(dest->clipRect.x * xFactor, y * yFactor, dest->clipRect.w * xFactor, dest->clipRect.h * yFactor); 2303 2294 } 2304 - 2305 - 2306 - 2307 - #ifdef SDL_GPU_USE_OPENGLv1 2308 - 2295 + 2296 + 2297 + 2298 + #ifdef SDL_GPU_USE_OPENGLv1 2299 + 2309 2300 float* vertex_pointer = rdata->blit_buffer + GPU_BLIT_BUFFER_VERTEX_OFFSET; 2310 2301 float* texcoord_pointer = rdata->blit_buffer + GPU_BLIT_BUFFER_TEX_COORD_OFFSET; 2311 2302 int i; 2312 2303 for(i = 0; i < rdata->blit_buffer_size; i++) 2313 2304 { 2314 2305 glBegin( GL_TRIANGLES ); 2315 - 2306 + 2316 2307 glTexCoord2f( *texcoord_pointer, *(texcoord_pointer+1) ); 2317 2308 glVertex3f( *vertex_pointer, *(vertex_pointer+1), *(vertex_pointer+2) ); 2318 2309 texcoord_pointer += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 2319 2310 vertex_pointer += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 2320 - 2311 + 2321 2312 glTexCoord2f( *texcoord_pointer, *(texcoord_pointer+1) ); 2322 2313 glVertex3f( *vertex_pointer, *(vertex_pointer+1), *(vertex_pointer+2) ); 2323 2314 texcoord_pointer += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 2324 2315 vertex_pointer += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 2325 - 2316 + 2326 2317 glTexCoord2f( *texcoord_pointer, *(texcoord_pointer+1) ); 2327 2318 glVertex3f( *vertex_pointer, *(vertex_pointer+1), *(vertex_pointer+2) ); 2328 2319 texcoord_pointer += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 2329 2320 vertex_pointer += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 2330 - 2321 + 2331 2322 glTexCoord2f( *texcoord_pointer, *(texcoord_pointer+1) ); 2332 2323 glVertex3f( *vertex_pointer, *(vertex_pointer+1), *(vertex_pointer+2) ); 2333 2324 texcoord_pointer += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 2334 2325 vertex_pointer += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 2335 - 2326 + 2336 2327 glTexCoord2f( *texcoord_pointer, *(texcoord_pointer+1) ); 2337 2328 glVertex3f( *vertex_pointer, *(vertex_pointer+1), *(vertex_pointer+2) ); 2338 2329 texcoord_pointer += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 2339 2330 vertex_pointer += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 2340 - 2331 + 2341 2332 glTexCoord2f( *texcoord_pointer, *(texcoord_pointer+1) ); 2342 2333 glVertex3f( *vertex_pointer, *(vertex_pointer+1), *(vertex_pointer+2) ); 2343 2334 texcoord_pointer += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 2344 2335 vertex_pointer += GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; 2345 - 2336 + 2346 2337 glEnd(); 2347 2338 } 2348 - #else 2349 - 2339 + #else 2340 + 2350 2341 glEnableClientState(GL_VERTEX_ARRAY); 2351 2342 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 2352 2343 glVertexPointer(3, GL_FLOAT, GPU_BLIT_BUFFER_STRIDE, rdata->blit_buffer + GPU_BLIT_BUFFER_VERTEX_OFFSET); 2353 2344 glTexCoordPointer(2, GL_FLOAT, GPU_BLIT_BUFFER_STRIDE, rdata->blit_buffer + GPU_BLIT_BUFFER_TEX_COORD_OFFSET); 2354 2345 2355 2346 glDrawArrays(GL_TRIANGLES, 0, rdata->blit_buffer_size); 2356 - 2347 + 2357 2348 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 2358 2349 glDisableClientState(GL_VERTEX_ARRAY); 2359 - 2360 - #endif 2361 - 2350 + 2351 + #endif 2352 + 2362 2353 rdata->blit_buffer_size = 0; 2363 - 2354 + 2364 2355 if(dest->useClip) 2365 2356 { 2366 2357 glDisable(GL_SCISSOR_TEST); ··· 2379 2370 glPopMatrix(); 2380 2371 glMatrixMode( GL_MODELVIEW ); 2381 2372 } 2382 - 2373 + 2383 2374 } 2384 2375 } 2385 2376 2386 2377 static void Flip(GPU_Renderer* renderer) 2387 2378 { 2388 2379 renderer->FlushBlitBuffer(renderer); 2389 - 2380 + 2390 2381 #ifdef SDL_GPU_USE_SDL2 2391 2382 SDL_GL_SwapWindow(((RendererData_OpenGL*)renderer->data)->window); 2392 2383 #else
-13
SDL_gpu/SDL_gpu.c
··· 325 325 326 326 if(channels == 3) 327 327 { 328 - #if SDL_BYTEORDER == SDL_BIG_ENDIAN 329 328 Rmask = 0xff0000; 330 329 Gmask = 0x00ff00; 331 330 Bmask = 0x0000ff; 332 - #else 333 - Rmask = 0x0000ff; 334 - Gmask = 0x00ff00; 335 - Bmask = 0xff0000; 336 - #endif 337 331 } 338 332 else 339 333 { 340 - #if SDL_BYTEORDER == SDL_BIG_ENDIAN 341 334 Rmask = 0xff000000; 342 335 Gmask = 0x00ff0000; 343 336 Bmask = 0x0000ff00; 344 337 Amask = 0x000000ff; 345 - #else 346 - Rmask = 0x000000ff; 347 - Gmask = 0x0000ff00; 348 - Bmask = 0x00ff0000; 349 - Amask = 0xff000000; 350 - #endif 351 338 } 352 339 353 340 SDL_Surface* result = SDL_CreateRGBSurfaceFrom(data, width, height, channels*8, width*channels, Rmask, Gmask, Bmask, Amask);