this repo has no description
0
fork

Configure Feed

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

Added extra GL texture formats as GPU_FEATUREs.

+205 -68
+180 -65
SDL_gpu/OpenGL_common/SDL_gpu_OpenGL.c
··· 15 15 16 16 static Uint8 isExtensionSupported(const char* extension_str) 17 17 { 18 + #ifdef SDL_GPU_USE_OPENGL 19 + return glewIsExtensionSupported(extension_str); 20 + #else 18 21 return (strstr((const char*)glGetString(GL_EXTENSIONS), extension_str ) != NULL); 22 + #endif 19 23 } 20 24 21 25 static Uint8 checkExtension(const char* str) ··· 28 32 return 1; 29 33 } 30 34 31 - static GPU_FeatureEnum enabled_features = 0xFFFFFF; //GPU_FEATURE_ALL; 35 + static GPU_FeatureEnum enabled_features = 0xFFFFFFFF; // Pretend to support them all if using incompatible headers 32 36 33 - static void initNPOT(void) 37 + static void init_features(void) 34 38 { 39 + // NPOT textures 35 40 #ifdef SDL_GPU_USE_OPENGL 36 - if(glewIsExtensionSupported("GL_ARB_texture_non_power_of_two")) 41 + if(isExtensionSupported("GL_ARB_texture_non_power_of_two")) 37 42 enabled_features |= GPU_FEATURE_NON_POWER_OF_TWO; 38 43 else 39 44 enabled_features &= ~GPU_FEATURE_NON_POWER_OF_TWO; ··· 43 48 else 44 49 enabled_features &= ~GPU_FEATURE_NON_POWER_OF_TWO; 45 50 #endif 46 - } 47 - 48 - static void initFBO(void) 49 - { 51 + 52 + // FBO 50 53 #ifdef SDL_GPU_USE_OPENGL 51 - if(glewIsExtensionSupported("GL_EXT_framebuffer_object")) 54 + if(isExtensionSupported("GL_EXT_framebuffer_object")) 52 55 enabled_features |= GPU_FEATURE_RENDER_TARGETS; 53 56 else 54 57 enabled_features &= ~GPU_FEATURE_RENDER_TARGETS; ··· 58 61 else 59 62 enabled_features &= ~GPU_FEATURE_RENDER_TARGETS; 60 63 #endif 61 - } 62 64 63 - static void initBLEND(void) 64 - { 65 + // Blending 65 66 #ifdef SDL_GPU_USE_OPENGL 66 67 enabled_features |= GPU_FEATURE_BLEND_EQUATIONS; 67 68 enabled_features |= GPU_FEATURE_BLEND_FUNC_SEPARATE; ··· 75 76 else 76 77 enabled_features &= ~GPU_FEATURE_BLEND_FUNC_SEPARATE; 77 78 #endif 79 + 80 + // GL texture formats 81 + if(isExtensionSupported("GL_EXT_bgr")) 82 + enabled_features |= GPU_FEATURE_GL_BGR; 83 + if(isExtensionSupported("GL_EXT_bgra")) 84 + enabled_features |= GPU_FEATURE_GL_BGRA; 85 + if(isExtensionSupported("GL_EXT_abgr")) 86 + enabled_features |= GPU_FEATURE_GL_ABGR; 87 + 78 88 } 79 89 80 90 void extBindFramebuffer(GLuint handle) ··· 263 273 264 274 #endif 265 275 266 - initNPOT(); 267 - initFBO(); 268 - initBLEND(); 276 + init_features(); 269 277 270 278 glEnable( GL_TEXTURE_2D ); 271 279 glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); ··· 718 726 719 727 720 728 721 - // Returns 0 if a direct conversion is safe. Returns 1 if a copy is needed. Returns -1 on error. 729 + // Returns 0 if a direct conversion (asking OpenGL to do it) is safe. Returns 1 if a copy is needed. Returns -1 on error. 730 + // The surfaceFormatResult is used to specify what direct conversion format the surface pixels are in (source format). 731 + #ifdef SDL_GPU_USE_OPENGLES 732 + // OpenGLES does not do direct conversion. Internal format (glFormat) and original format (surfaceFormatResult) must be the same. 722 733 static int compareFormats(GLenum glFormat, SDL_Surface* surface, GLenum* surfaceFormatResult) 723 734 { 724 735 SDL_PixelFormat* format = surface->format; 725 736 switch(glFormat) 726 737 { 738 + // 3-channel formats 727 739 case GL_RGB: 740 + if(format->BytesPerPixel != 3) 741 + return 1; 742 + if(format->Rmask == 0xFF0000 && format->Gmask == 0x00FF00 && format->Bmask == 0x0000FF) 743 + { 744 + if(surfaceFormatResult != NULL) 745 + *surfaceFormatResult = GL_RGB; 746 + return 0; 747 + } 748 + return 1; 728 749 #ifdef GL_BGR 729 750 case GL_BGR: 751 + if(format->BytesPerPixel != 3) 752 + return 1; 753 + if(format->Rmask == 0x0000FF && format->Gmask == 0x00FF00 && format->Bmask == 0xFF0000) 754 + { 755 + if(enabled_features & GPU_FEATURE_GL_BGR) 756 + { 757 + if(surfaceFormatResult != NULL) 758 + *surfaceFormatResult = GL_BGR; 759 + } 760 + else 761 + return 1; 762 + return 0; 763 + } 764 + return 1; 730 765 #endif 731 - //GPU_LogError("Wanted 3 channels, got %d\n", format->BytesPerPixel); 732 - if(format->BytesPerPixel != 3) return 1; 733 766 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; 767 + // 4-channel formats 768 + case GL_RGBA: 769 + if(format->BytesPerPixel != 4) 770 + return 1; 771 + if (format->Rmask == 0xFF000000 && format->Gmask == 0x00FF0000 && format->Bmask == 0x0000FF00) 772 + { 773 + if(surfaceFormatResult != NULL) 774 + *surfaceFormatResult = GL_RGBA; 775 + return 0; 776 + } 777 + return 1; 778 + #ifdef GL_BGRA 779 + case GL_BGRA: 780 + if(format->BytesPerPixel != 4) 781 + return 1; 782 + if (format->Rmask == 0x0000FF00 && format->Gmask == 0x00FF0000 && format->Bmask == 0xFF000000) 783 + { 784 + if(surfaceFormatResult != NULL) 785 + *surfaceFormatResult = GL_BGRA; 786 + return 0; 787 + } 788 + return 1; 789 + #endif 790 + #ifdef GL_ABGR 791 + case GL_ABGR: 792 + if(format->BytesPerPixel != 4) 793 + return 1; 794 + if (format->Rmask == 0x000000FF && format->Gmask == 0x0000FF00 && format->Bmask == 0x00FF0000) 795 + { 796 + if(surfaceFormatResult != NULL) 797 + *surfaceFormatResult = GL_ABGR; 798 + return 0; 799 + } 800 + return 1; 801 + #endif 802 + default: 803 + GPU_LogError("GPU_UpdateImage() was passed an image with an invalid format.\n"); 804 + return -1; 805 + } 806 + } 739 807 #else 740 - GPU_LogError("GL_BGR is unsupported, using GL_RGB\n"); 808 + static int compareFormats(GLenum glFormat, SDL_Surface* surface, GLenum* surfaceFormatResult) 809 + { 810 + SDL_PixelFormat* format = surface->format; 811 + switch(glFormat) 812 + { 813 + // 3-channel formats 814 + case GL_RGB: 815 + case GL_BGR: 816 + if(format->BytesPerPixel != 3) 817 + return 1; 818 + 819 + // Looks like RGB? Easy! 820 + if(format->Rmask == 0xFF0000 && format->Gmask == 0x00FF00 && format->Bmask == 0x0000FF) 821 + { 822 + if(surfaceFormatResult != NULL) 741 823 *surfaceFormatResult = GL_RGB; 742 - #endif 743 - } 744 824 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; 825 + } 826 + // Looks like BGR? 827 + else if(format->Rmask == 0x0000FF && format->Gmask == 0x00FF00 && format->Bmask == 0xFF0000) 828 + { 829 + #ifdef GL_BGR 830 + if(enabled_features & GPU_FEATURE_GL_BGR) 831 + { 832 + if(surfaceFormatResult != NULL) 833 + *surfaceFormatResult = GL_BGR; 834 + return 0; 749 835 } 750 - return 0; 751 - } else { 752 - return 1; 836 + #endif 753 837 } 754 - 838 + return 1; 839 + 840 + // 4-channel formats 755 841 case GL_RGBA: 756 842 #ifdef GL_BGRA 757 843 case GL_BGRA: 758 844 #endif 759 - #ifdef GL_ABGR_EXT 760 - case GL_ABGR_EXT: 845 + #ifdef GL_ABGR 846 + case GL_ABGR: 761 847 #endif 762 - //GPU_LogError("Wanted 4 channels, got %d\n", format->BytesPerPixel); 763 - if(format->BytesPerPixel != 4) return 1; 848 + if(format->BytesPerPixel != 4) 849 + return 1; 764 850 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"); 851 + // Looks like RGBA? Easy! 852 + if(format->Rmask == 0xFF000000 && format->Gmask == 0x00FF0000 && format->Bmask == 0x0000FF00) 853 + { 854 + if(surfaceFormatResult != NULL) 772 855 *surfaceFormatResult = GL_RGBA; 773 - #endif 774 - } 775 856 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; 857 + } 858 + // Looks like ABGR? 859 + else if(format->Rmask == 0x000000FF && format->Gmask == 0x0000FF00 && format->Bmask == 0x00FF0000) 860 + { 861 + #ifdef GL_ABGR 862 + if(enabled_features & GPU_FEATURE_GL_ABGR) 863 + { 864 + if(surfaceFormatResult != NULL) 865 + *surfaceFormatResult = GL_ABGR; 866 + return 0; 780 867 } 781 - return 0; 782 - //Something custom BGRA 868 + #endif 869 + } 870 + // Looks like BGRA? 871 + else if(format->Rmask == 0x0000FF00 && format->Gmask == 0x00FF0000 && format->Bmask == 0xFF000000) 872 + { 783 873 #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; 874 + if(enabled_features & GPU_FEATURE_GL_BGRA) 875 + { 876 + if(surfaceFormatResult != NULL) 877 + *surfaceFormatResult = GL_BGRA; 878 + return 0; 879 + } 787 880 #endif 788 881 } 789 - //GPU_LogError("Masks don't match: %X, %X, %X\n", format->Rmask, format->Gmask, format->Bmask); 790 882 return 1; 791 883 default: 792 884 GPU_LogError("GPU_UpdateImage() was passed an image with an invalid format.\n"); 793 885 return -1; 794 886 } 795 887 } 888 + #endif 796 889 797 890 798 - // From SDL_AllocFormat() 891 + // Adapted from SDL_AllocFormat() 799 892 static SDL_PixelFormat* AllocFormat(GLenum glFormat) 800 893 { 801 894 // Yes, I need to do the whole thing myself... :( ··· 806 899 { 807 900 case GL_RGB: 808 901 channels = 3; 902 + #if SDL_BYTEORDER == SDL_BIG_ENDIAN 903 + Rmask = 0xFF0000; 904 + Gmask = 0x00FF00; 905 + Bmask = 0x0000FF; 906 + #else 809 907 Rmask = 0x0000FF; 810 908 Gmask = 0x00FF00; 811 909 Bmask = 0xFF0000; 910 + #endif 812 911 break; 813 912 #ifdef GL_BGR 814 913 case GL_BGR: 815 914 channels = 3; 816 - Rmask = 0xFF0000; 915 + #if SDL_BYTEORDER == SDL_BIG_ENDIAN 916 + Bmask = 0xFF0000; 817 917 Gmask = 0x00FF00; 918 + Rmask = 0x0000FF; 919 + #else 818 920 Bmask = 0x0000FF; 921 + Gmask = 0x00FF00; 922 + Rmask = 0xFF0000; 923 + #endif 819 924 break; 820 925 #endif 821 926 case GL_RGBA: 822 927 channels = 4; 823 - Rmask = 0x000000FF; 824 - Gmask = 0x0000FF00; 825 - Bmask = 0x00FF0000; 826 - Amask = 0xFF000000; 928 + Rmask = 0xFF000000; 929 + Gmask = 0x00FF0000; 930 + Bmask = 0x0000FF00; 931 + Amask = 0x000000FF; 827 932 break; 828 933 #ifdef GL_BGRA 829 934 case GL_BGRA: 830 935 channels = 4; 831 - Rmask = 0xFF000000; 936 + Bmask = 0xFF000000; 832 937 Gmask = 0x00FF0000; 833 - Bmask = 0x0000FF00; 938 + Rmask = 0x0000FF00; 834 939 Amask = 0x000000FF; 940 + break; 941 + #endif 942 + #ifdef GL_ABGR 943 + case GL_ABGR: 944 + channels = 4; 945 + Amask = 0xFF000000; 946 + Bmask = 0x00FF0000; 947 + Gmask = 0x0000FF00; 948 + Rmask = 0x000000FF; 835 949 break; 836 950 #endif 837 951 default: ··· 976 1090 // From SDL_UpdateTexture() 977 1091 static int InitImageWithSurface(GPU_Renderer* renderer, GPU_Image* image, SDL_Surface* surface) 978 1092 { 979 - ImageData_OpenGL* data = (ImageData_OpenGL*)image->data; 980 1093 if(renderer == NULL || image == NULL || surface == NULL) 981 1094 return 0; 982 1095 1096 + ImageData_OpenGL* data = (ImageData_OpenGL*)image->data; 1097 + 983 1098 GLenum internal_format = data->format; 984 1099 GLenum original_format = internal_format; 985 1100
+10
SDL_gpu/OpenGL_common/SDL_gpu_OpenGL.h
··· 30 30 #define GL_FUNC_REVERSE_SUBTRACT GL_FUNC_REVERSE_SUBTRACT_OES 31 31 #endif 32 32 33 + #if defined(GL_EXT_bgr) && !defined(GL_BGR) 34 + #define GL_BGR GL_BGR_EXT 35 + #endif 36 + #if defined(GL_EXT_bgra) && !defined(GL_BGRA) 37 + #define GL_BGRA GL_BGRA_EXT 38 + #endif 39 + #if defined(GL_EXT_abgr) && !defined(GL_ABGR) 40 + #define GL_ABGR GL_ABGR_EXT 41 + #endif 42 + 33 43 // Forces a flush when limit is reached (roughly 1000 sprites) 34 44 #define GPU_BLIT_BUFFER_INIT_MAX_SIZE 6000 35 45 // x, y, z, s, t
+9 -2
SDL_gpu/SDL_gpu.h
··· 59 59 /*! Important GPU features which may not be supported depending on a device's extension support. Can be OR'd together. 60 60 * \see GPU_IsFeatureEnabled() 61 61 */ 62 - typedef unsigned int GPU_FeatureEnum; 62 + typedef Uint32 GPU_FeatureEnum; 63 63 static const GPU_FeatureEnum GPU_FEATURE_NON_POWER_OF_TWO = 0x1; 64 64 static const GPU_FeatureEnum GPU_FEATURE_RENDER_TARGETS = 0x2; 65 65 static const GPU_FeatureEnum GPU_FEATURE_BLEND_EQUATIONS = 0x4; 66 66 static const GPU_FeatureEnum GPU_FEATURE_BLEND_FUNC_SEPARATE = 0x8; 67 - static const GPU_FeatureEnum GPU_FEATURE_ALL = 0xFFFFFF; 67 + static const GPU_FeatureEnum GPU_FEATURE_GL_BGR = 0x10; 68 + static const GPU_FeatureEnum GPU_FEATURE_GL_BGRA = 0x20; 69 + static const GPU_FeatureEnum GPU_FEATURE_GL_ABGR = 0x40; 70 + 71 + /*! Combined feature flags */ 72 + #define GPU_FEATURE_ALL_BASE GPU_FEATURE_RENDER_TARGETS 73 + #define GPU_FEATURE_ALL_BLEND_MODES (GPU_FEATURE_BLEND_EQUATIONS | GPU_FEATURE_BLEND_FUNC_SEPARATE) 74 + #define GPU_FEATURE_ALL_GL_FORMATS (GPU_FEATURE_GL_BGR | GPU_FEATURE_GL_BGRA | GPU_FEATURE_GL_ABGR) 68 75 69 76 /*! Texture filtering options. These affect the quality/interpolation of colors when images are scaled. 70 77 * \see GPU_SetImageFilter()
+6 -1
demos/features/main.c
··· 30 30 31 31 GPU_LogError("Using renderer: %s\n", GPU_GetCurrentRendererID()); 32 32 33 - GPU_LogError("Supports GPU_FEATURE_ALL: %s\n", bool_string(GPU_IsFeatureEnabled(GPU_FEATURE_ALL))); 33 + GPU_LogError("Supports GPU_FEATURE_ALL_BASE: %s\n", bool_string(GPU_IsFeatureEnabled(GPU_FEATURE_ALL_BASE))); 34 + GPU_LogError("Supports GPU_FEATURE_ALL_BLEND_MODES: %s\n", bool_string(GPU_IsFeatureEnabled(GPU_FEATURE_ALL_BLEND_MODES))); 35 + GPU_LogError("Supports GPU_FEATURE_ALL_GL_FORMATS: %s\n", bool_string(GPU_IsFeatureEnabled(GPU_FEATURE_ALL_GL_FORMATS))); 34 36 35 37 GPU_LogError("Supports GPU_FEATURE_NON_POWER_OF_TWO: %s\n", bool_string(GPU_IsFeatureEnabled(GPU_FEATURE_NON_POWER_OF_TWO))); 36 38 GPU_LogError("Supports GPU_FEATURE_RENDER_TARGETS: %s\n", bool_string(GPU_IsFeatureEnabled(GPU_FEATURE_RENDER_TARGETS))); 37 39 GPU_LogError("Supports GPU_FEATURE_BLEND_EQUATIONS: %s\n", bool_string(GPU_IsFeatureEnabled(GPU_FEATURE_BLEND_EQUATIONS))); 38 40 GPU_LogError("Supports GPU_FEATURE_BLEND_FUNC_SEPARATE: %s\n", bool_string(GPU_IsFeatureEnabled(GPU_FEATURE_BLEND_FUNC_SEPARATE))); 41 + GPU_LogError("Supports GPU_FEATURE_GL_BGR: %s\n", bool_string(GPU_IsFeatureEnabled(GPU_FEATURE_GL_BGR))); 42 + GPU_LogError("Supports GPU_FEATURE_GL_BGRA: %s\n", bool_string(GPU_IsFeatureEnabled(GPU_FEATURE_GL_BGRA))); 43 + GPU_LogError("Supports GPU_FEATURE_GL_ABGR: %s\n", bool_string(GPU_IsFeatureEnabled(GPU_FEATURE_GL_ABGR))); 39 44 40 45 GPU_Quit(); 41 46