mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-04-05 07:09:32 +00:00
Added the concept of colorspace to the SDL renderer
This allows color operations to happen in linear space between sRGB input and sRGB output. This is currently supported on the direct3d11, direct3d12 and opengl renderers. This is a good resource on blending in linear space vs sRGB space: https://blog.johnnovak.net/2016/09/21/what-every-coder-should-know-about-gamma/ Also added testcolorspace to verify colorspace changes
This commit is contained in:
@@ -196,8 +196,14 @@ typedef enum
|
||||
(SDL_PIXELORDER(format) == SDL_PACKEDORDER_BGRA))))
|
||||
|
||||
#define SDL_ISPIXELFORMAT_10BIT(format) \
|
||||
((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED32) && \
|
||||
(SDL_PIXELLAYOUT(format) == SDL_PACKEDLAYOUT_2101010))
|
||||
(!SDL_ISPIXELFORMAT_FOURCC(format) && \
|
||||
((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED32) && \
|
||||
(SDL_PIXELLAYOUT(format) == SDL_PACKEDLAYOUT_2101010)))
|
||||
|
||||
#define SDL_ISPIXELFORMAT_FLOAT(format) \
|
||||
(!SDL_ISPIXELFORMAT_FOURCC(format) && \
|
||||
((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF16) || \
|
||||
(SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF32)))
|
||||
|
||||
/* The flag is set to 1 because 0x1? is not in the printable ASCII range */
|
||||
#define SDL_ISPIXELFORMAT_FOURCC(format) \
|
||||
|
||||
@@ -240,9 +240,14 @@ extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRenderer(SDL_Window *window, co
|
||||
* is displayed, if you want a software renderer without a window
|
||||
* - `SDL_PROP_RENDERER_CREATE_NAME_STRING`: the name of the rendering driver
|
||||
* to use, if a specific one is desired
|
||||
* - `SDL_PROP_RENDERER_CREATE_INPUT_COLORSPACE_NUMBER`: an SDL_ColorSpace value describing the colorspace for input colors, defaults to SDL_COLORSPACE_SRGB
|
||||
* - `SDL_PROP_RENDERER_CREATE_OUTPUT_COLORSPACE_NUMBER`: an SDL_ColorSpace value describing the colorspace for output to the display, defaults to SDL_COLORSPACE_SRGB
|
||||
* - `SDL_PROP_RENDERER_CREATE_COLORSPACE_CONVERSION_BOOLEAN`: true if you want conversion between the input colorspace and the output colorspace, defaults to SDL_TRUE
|
||||
* - `SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_BOOLEAN`: true if you want
|
||||
* present synchronized with the refresh rate
|
||||
*
|
||||
* Note that enabling colorspace conversion between sRGB input and sRGB output implies that the rendering is done in a linear colorspace for more correct blending results. If colorspace conversion is disabled, then input colors are passed directly through to the output.
|
||||
*
|
||||
* \param props the properties to use
|
||||
* \returns a valid rendering context or NULL if there was an error; call
|
||||
* SDL_GetError() for more information.
|
||||
@@ -256,10 +261,13 @@ extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRenderer(SDL_Window *window, co
|
||||
*/
|
||||
extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRendererWithProperties(SDL_PropertiesID props);
|
||||
|
||||
#define SDL_PROP_RENDERER_CREATE_WINDOW_POINTER "window"
|
||||
#define SDL_PROP_RENDERER_CREATE_SURFACE_POINTER "surface"
|
||||
#define SDL_PROP_RENDERER_CREATE_NAME_STRING "name"
|
||||
#define SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_BOOLEAN "present_vsync"
|
||||
#define SDL_PROP_RENDERER_CREATE_WINDOW_POINTER "window"
|
||||
#define SDL_PROP_RENDERER_CREATE_SURFACE_POINTER "surface"
|
||||
#define SDL_PROP_RENDERER_CREATE_NAME_STRING "name"
|
||||
#define SDL_PROP_RENDERER_CREATE_INPUT_COLORSPACE_NUMBER "input_colorspace"
|
||||
#define SDL_PROP_RENDERER_CREATE_OUTPUT_COLORSPACE_NUMBER "output_colorspace"
|
||||
#define SDL_PROP_RENDERER_CREATE_COLORSPACE_CONVERSION_BOOLEAN "colorspace_conversion"
|
||||
#define SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_BOOLEAN "present_vsync"
|
||||
|
||||
/**
|
||||
* Create a 2D software rendering context for a surface.
|
||||
@@ -447,6 +455,7 @@ extern DECLSPEC SDL_Texture *SDLCALL SDL_CreateTextureFromSurface(SDL_Renderer *
|
||||
*
|
||||
* These are the supported properties:
|
||||
*
|
||||
* - `SDL_PROP_TEXTURE_CREATE_COLORSPACE_NUMBER`: an SDL_ColorSpace value describing the texture colorspace, defaults to SDL_COLORSPACE_SCRGB for floating point textures, SDL_COLORSPACE_HDR10 for 10-bit textures, SDL_COLORSPACE_SRGB for other RGB textures and SDL_COLORSPACE_BT709_FULL for YUV textures.
|
||||
* - `SDL_PROP_TEXTURE_CREATE_FORMAT_NUMBER`: one of the enumerated values in
|
||||
* SDL_PixelFormatEnum, defaults to the best RGBA format for the renderer
|
||||
* - `SDL_PROP_TEXTURE_CREATE_ACCESS_NUMBER`: one of the enumerated values in
|
||||
@@ -524,6 +533,7 @@ extern DECLSPEC SDL_Texture *SDLCALL SDL_CreateTextureFromSurface(SDL_Renderer *
|
||||
*/
|
||||
extern DECLSPEC SDL_Texture *SDLCALL SDL_CreateTextureWithProperties(SDL_Renderer *renderer, SDL_PropertiesID props);
|
||||
|
||||
#define SDL_PROP_TEXTURE_CREATE_COLORSPACE_NUMBER "colorspace"
|
||||
#define SDL_PROP_TEXTURE_CREATE_FORMAT_NUMBER "format"
|
||||
#define SDL_PROP_TEXTURE_CREATE_ACCESS_NUMBER "access"
|
||||
#define SDL_PROP_TEXTURE_CREATE_WIDTH_NUMBER "width"
|
||||
@@ -550,6 +560,8 @@ extern DECLSPEC SDL_Texture *SDLCALL SDL_CreateTextureWithProperties(SDL_Rendere
|
||||
*
|
||||
* The following read-only properties are provided by SDL:
|
||||
*
|
||||
* - `SDL_PROP_TEXTURE_COLORSPACE_NUMBER`: an SDL_ColorSpace value describing the colorspace used by the texture
|
||||
*
|
||||
* With the direct3d11 renderer:
|
||||
*
|
||||
* - `SDL_PROP_TEXTURE_D3D11_TEXTURE_POINTER`: the ID3D11Texture2D associated
|
||||
@@ -609,6 +621,7 @@ extern DECLSPEC SDL_Texture *SDLCALL SDL_CreateTextureWithProperties(SDL_Rendere
|
||||
*/
|
||||
extern DECLSPEC SDL_PropertiesID SDLCALL SDL_GetTextureProperties(SDL_Texture *texture);
|
||||
|
||||
#define SDL_PROP_TEXTURE_COLORSPACE_NUMBER "SDL.texture.colorspace"
|
||||
#define SDL_PROP_TEXTURE_D3D11_TEXTURE_POINTER "SDL.texture.d3d11.texture"
|
||||
#define SDL_PROP_TEXTURE_D3D11_TEXTURE_U_POINTER "SDL.texture.d3d11.texture_u"
|
||||
#define SDL_PROP_TEXTURE_D3D11_TEXTURE_V_POINTER "SDL.texture.d3d11.texture_v"
|
||||
|
||||
Reference in New Issue
Block a user