this repo has no description
0
fork

Configure Feed

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

Added GPU_CreateImageUsingTexture(), which accepts a native handle (e.g. GL texture handle) and uses that as the image texture.

+177
+163
SDL_gpu/GL_common/SDL_gpu_GL_common.inl
··· 1864 1864 return result; 1865 1865 } 1866 1866 1867 + 1868 + static GPU_Image* CreateImageUsingTexture(GPU_Renderer* renderer, Uint32 handle) 1869 + { 1870 + GLint w, h; 1871 + GLuint num_layers, bytes_per_pixel; 1872 + GLint gl_format; 1873 + GLint wrap_s, wrap_t; 1874 + GLint min_filter; 1875 + 1876 + GPU_FormatEnum format; 1877 + GPU_WrapEnum wrap_x, wrap_y; 1878 + GPU_FilterEnum filter_mode; 1879 + SDL_Color white = { 255, 255, 255, 255 }; 1880 + 1881 + GPU_Image* result; 1882 + GPU_IMAGE_DATA* data; 1883 + 1884 + flushAndBindTexture(renderer, handle); 1885 + 1886 + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &gl_format); 1887 + 1888 + switch(gl_format) 1889 + { 1890 + case GL_LUMINANCE: 1891 + format = GPU_FORMAT_LUMINANCE; 1892 + num_layers = 1; 1893 + bytes_per_pixel = 1; 1894 + break; 1895 + case GL_LUMINANCE_ALPHA: 1896 + format = GPU_FORMAT_LUMINANCE_ALPHA; 1897 + num_layers = 1; 1898 + bytes_per_pixel = 2; 1899 + break; 1900 + case GL_RGB: 1901 + format = GPU_FORMAT_RGB; 1902 + num_layers = 1; 1903 + bytes_per_pixel = 3; 1904 + break; 1905 + case GL_RGBA: 1906 + format = GPU_FORMAT_RGBA; 1907 + num_layers = 1; 1908 + bytes_per_pixel = 4; 1909 + break; 1910 + case GL_ALPHA: 1911 + format = GPU_FORMAT_ALPHA; 1912 + num_layers = 1; 1913 + bytes_per_pixel = 1; 1914 + break; 1915 + #ifndef SDL_GPU_USE_GLES 1916 + case GL_RG: 1917 + format = GPU_FORMAT_RG; 1918 + num_layers = 1; 1919 + bytes_per_pixel = 2; 1920 + break; 1921 + #endif 1922 + default: 1923 + GPU_PushErrorCode("GPU_CreateImageUsingTexture", GPU_ERROR_DATA_ERROR, "Unsupported GL image format (0x%x)", gl_format); 1924 + return NULL; 1925 + } 1926 + 1927 + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w); 1928 + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h); 1929 + 1930 + 1931 + glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, &min_filter); 1932 + // Ignore mag filter... Maybe the wrong thing to do? 1933 + 1934 + // Let the user use one that we don't support and pretend that we're okay with that. 1935 + switch(min_filter) 1936 + { 1937 + case GL_NEAREST: 1938 + filter_mode = GPU_FILTER_NEAREST; 1939 + break; 1940 + case GL_LINEAR: 1941 + case GL_LINEAR_MIPMAP_NEAREST: 1942 + filter_mode = GPU_FILTER_LINEAR; 1943 + break; 1944 + case GL_LINEAR_MIPMAP_LINEAR: 1945 + filter_mode = GPU_FILTER_LINEAR_MIPMAP; 1946 + break; 1947 + default: 1948 + GPU_PushErrorCode("GPU_CreateImageUsingTexture", GPU_ERROR_USER_ERROR, "Unsupported value for GL_TEXTURE_MIN_FILTER (0x%x)", min_filter); 1949 + filter_mode = GPU_FILTER_LINEAR; 1950 + return; 1951 + } 1952 + 1953 + 1954 + glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, &wrap_s); 1955 + glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, &wrap_t); 1956 + 1957 + // Let the user use one that we don't support and pretend that we're okay with that. 1958 + switch(wrap_s) 1959 + { 1960 + case GL_CLAMP_TO_EDGE: 1961 + wrap_x = GPU_WRAP_NONE; 1962 + break; 1963 + case GL_REPEAT: 1964 + wrap_x = GPU_WRAP_REPEAT; 1965 + break; 1966 + case GL_MIRRORED_REPEAT: 1967 + wrap_x = GPU_WRAP_MIRRORED; 1968 + break; 1969 + default: 1970 + GPU_PushErrorCode("GPU_CreateImageUsingTexture", GPU_ERROR_USER_ERROR, "Unsupported value for GL_TEXTURE_WRAP_S (0x%x)", wrap_s); 1971 + wrap_x = GPU_WRAP_NONE; 1972 + return; 1973 + } 1974 + 1975 + switch(wrap_t) 1976 + { 1977 + case GL_CLAMP_TO_EDGE: 1978 + wrap_y = GPU_WRAP_NONE; 1979 + break; 1980 + case GL_REPEAT: 1981 + wrap_y = GPU_WRAP_REPEAT; 1982 + break; 1983 + case GL_MIRRORED_REPEAT: 1984 + wrap_y = GPU_WRAP_MIRRORED; 1985 + break; 1986 + default: 1987 + GPU_PushErrorCode("GPU_CreateImageUsingTexture", GPU_ERROR_USER_ERROR, "Unsupported value for GL_TEXTURE_WRAP_T (0x%x)", wrap_t); 1988 + wrap_y = GPU_WRAP_NONE; 1989 + return; 1990 + } 1991 + 1992 + // Finally create the image 1993 + 1994 + data = (GPU_IMAGE_DATA*)malloc(sizeof(GPU_IMAGE_DATA)); 1995 + data->refcount = 1; 1996 + data->handle = handle; 1997 + data->format = gl_format; 1998 + 1999 + 2000 + result = (GPU_Image*)malloc(sizeof(GPU_Image)); 2001 + result->refcount = 1; 2002 + result->target = NULL; 2003 + result->renderer = renderer; 2004 + result->format = format; 2005 + result->num_layers = num_layers; 2006 + result->bytes_per_pixel = bytes_per_pixel; 2007 + result->has_mipmaps = 0; 2008 + 2009 + result->color = white; 2010 + result->use_blending = ((format == GPU_FORMAT_LUMINANCE_ALPHA || format == GPU_FORMAT_RGBA)? 1 : 0); 2011 + result->blend_mode = GPU_GetBlendModeFromPreset(GPU_BLEND_NORMAL); 2012 + result->snap_mode = GPU_SNAP_POSITION_AND_DIMENSIONS; 2013 + result->filter_mode = filter_mode; 2014 + result->wrap_mode_x = wrap_x; 2015 + result->wrap_mode_y = wrap_y; 2016 + 2017 + result->data = data; 2018 + result->is_alias = 0; 2019 + 2020 + result->w = w; 2021 + result->h = h; 2022 + 2023 + result->texture_w = w; 2024 + result->texture_h = h; 2025 + 2026 + return result; 2027 + } 2028 + 1867 2029 static GPU_Image* LoadImage(GPU_Renderer* renderer, const char* filename) 1868 2030 { 1869 2031 GPU_Image* result; ··· 5895 6057 impl->SetCamera = &SetCamera; \ 5896 6058 \ 5897 6059 impl->CreateImage = &CreateImage; \ 6060 + impl->CreateImageUsingTexture = &CreateImageUsingTexture; \ 5898 6061 impl->LoadImage = &LoadImage; \ 5899 6062 impl->CreateAliasImage = &CreateAliasImage; \ 5900 6063 impl->SaveImage = &SaveImage; \
+8
SDL_gpu/SDL_gpu.c
··· 691 691 return current_renderer->impl->CreateImage(current_renderer, w, h, format); 692 692 } 693 693 694 + GPU_Image* GPU_CreateImageUsingTexture(Uint32 handle) 695 + { 696 + if(current_renderer == NULL || current_renderer->current_context_target == NULL) 697 + return NULL; 698 + 699 + return current_renderer->impl->CreateImageUsingTexture(current_renderer, handle); 700 + } 701 + 694 702 GPU_Image* GPU_LoadImage(const char* filename) 695 703 { 696 704 if(current_renderer == NULL || current_renderer->current_context_target == NULL)
+3
SDL_gpu/SDL_gpu.h
··· 912 912 */ 913 913 GPU_Image* GPU_CreateImage(Uint16 w, Uint16 h, GPU_FormatEnum format); 914 914 915 + /*! Create a new image that uses the given native texture handle as the image texture. */ 916 + GPU_Image* GPU_CreateImageUsingTexture(Uint32 handle); 917 + 915 918 /*! Load image from an image file that is supported by this renderer. Don't forget to GPU_FreeImage() it. */ 916 919 GPU_Image* GPU_LoadImage(const char* filename); 917 920
+3
SDL_gpu/SDL_gpu_RendererImpl.h
··· 52 52 /*! \see GPU_CreateImage() */ 53 53 GPU_Image* (*CreateImage)(GPU_Renderer* renderer, Uint16 w, Uint16 h, GPU_FormatEnum format); 54 54 55 + /*! \see GPU_CreateImageUsingTexture() */ 56 + GPU_Image* (*CreateImageUsingTexture)(GPU_Renderer* renderer, Uint32 handle); 57 + 55 58 /*! \see GPU_LoadImage() */ 56 59 GPU_Image* (*LoadImage)(GPU_Renderer* renderer, const char* filename); 57 60