Renderer colors now have floating point precision

This commit is contained in:
Sam Lantinga 2024-01-29 13:28:33 -08:00
parent da8fc70a83
commit 554f0625d3
21 changed files with 603 additions and 347 deletions

View file

@ -91,7 +91,7 @@ typedef struct SDL_RendererInfo
typedef struct SDL_Vertex
{
SDL_FPoint position; /**< Vertex position, in SDL_Renderer coordinates */
SDL_Color color; /**< Vertex color */
SDL_FColor color; /**< Vertex color */
SDL_FPoint tex_coord; /**< Normalized texture coordinates, if needed */
} SDL_Vertex;
@ -692,10 +692,39 @@ extern DECLSPEC int SDLCALL SDL_QueryTexture(SDL_Texture *texture, Uint32 *forma
*
* \sa SDL_GetTextureColorMod
* \sa SDL_SetTextureAlphaMod
* \sa SDL_SetTextureColorModFloat
*/
extern DECLSPEC int SDLCALL SDL_SetTextureColorMod(SDL_Texture *texture, Uint8 r, Uint8 g, Uint8 b);
/**
* Set an additional color value multiplied into render copy operations.
*
* When this texture is rendered, during the copy operation each source color
* channel is modulated by the appropriate color value according to the
* following formula:
*
* `srcC = srcC * color`
*
* Color modulation is not always supported by the renderer; it will return -1
* if color modulation is not supported.
*
* \param texture the texture to update
* \param r the red color value multiplied into copy operations
* \param g the green color value multiplied into copy operations
* \param b the blue color value multiplied into copy operations
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetTextureColorModFloat
* \sa SDL_SetTextureAlphaModFloat
* \sa SDL_SetTextureColorMod
*/
extern DECLSPEC int SDLCALL SDL_SetTextureColorModFloat(SDL_Texture *texture, float r, float g, float b);
/**
* Get the additional color value multiplied into render copy operations.
*
@ -709,10 +738,29 @@ extern DECLSPEC int SDLCALL SDL_SetTextureColorMod(SDL_Texture *texture, Uint8 r
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetTextureAlphaMod
* \sa SDL_GetTextureColorModFloat
* \sa SDL_SetTextureColorMod
*/
extern DECLSPEC int SDLCALL SDL_GetTextureColorMod(SDL_Texture *texture, Uint8 *r, Uint8 *g, Uint8 *b);
/**
* Get the additional color value multiplied into render copy operations.
*
* \param texture the texture to query
* \param r a pointer filled in with the current red color value
* \param g a pointer filled in with the current green color value
* \param b a pointer filled in with the current blue color value
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetTextureAlphaModFloat
* \sa SDL_GetTextureColorMod
* \sa SDL_SetTextureColorModFloat
*/
extern DECLSPEC int SDLCALL SDL_GetTextureColorModFloat(SDL_Texture *texture, float *r, float *g, float *b);
/**
* Set an additional alpha value multiplied into render copy operations.
*
@ -732,10 +780,35 @@ extern DECLSPEC int SDLCALL SDL_GetTextureColorMod(SDL_Texture *texture, Uint8 *
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetTextureAlphaMod
* \sa SDL_SetTextureAlphaModFloat
* \sa SDL_SetTextureColorMod
*/
extern DECLSPEC int SDLCALL SDL_SetTextureAlphaMod(SDL_Texture *texture, Uint8 alpha);
/**
* Set an additional alpha value multiplied into render copy operations.
*
* When this texture is rendered, during the copy operation the source alpha
* value is modulated by this alpha value according to the following formula:
*
* `srcA = srcA * alpha`
*
* Alpha modulation is not always supported by the renderer; it will return -1
* if alpha modulation is not supported.
*
* \param texture the texture to update
* \param alpha the source alpha value multiplied into copy operations
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetTextureAlphaModFloat
* \sa SDL_SetTextureAlphaMod
* \sa SDL_SetTextureColorModFloat
*/
extern DECLSPEC int SDLCALL SDL_SetTextureAlphaModFloat(SDL_Texture *texture, float alpha);
/**
* Get the additional alpha value multiplied into render copy operations.
*
@ -746,11 +819,28 @@ extern DECLSPEC int SDLCALL SDL_SetTextureAlphaMod(SDL_Texture *texture, Uint8 a
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetTextureAlphaModFloat
* \sa SDL_GetTextureColorMod
* \sa SDL_SetTextureAlphaMod
*/
extern DECLSPEC int SDLCALL SDL_GetTextureAlphaMod(SDL_Texture *texture, Uint8 *alpha);
/**
* Get the additional alpha value multiplied into render copy operations.
*
* \param texture the texture to query
* \param alpha a pointer filled in with the current alpha value
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetTextureAlphaMod
* \sa SDL_GetTextureColorModFloat
* \sa SDL_SetTextureAlphaModFloat
*/
extern DECLSPEC int SDLCALL SDL_GetTextureAlphaModFloat(SDL_Texture *texture, float *alpha);
/**
* Set the blend mode for a texture, used by SDL_RenderTexture().
*
@ -1263,17 +1353,49 @@ extern DECLSPEC int SDLCALL SDL_GetRenderScale(SDL_Renderer *renderer, float *sc
*
* \sa SDL_GetRenderDrawColor
* \sa SDL_RenderClear
* \sa SDL_RenderFillRect
* \sa SDL_RenderFillRects
* \sa SDL_RenderLine
* \sa SDL_RenderLines
* \sa SDL_RenderPoint
* \sa SDL_RenderPoints
* \sa SDL_RenderRect
* \sa SDL_RenderRects
* \sa SDL_RenderFillRect
* \sa SDL_RenderFillRects
* \sa SDL_SetRenderDrawColorFloat
*/
extern DECLSPEC int SDLCALL SDL_SetRenderDrawColor(SDL_Renderer *renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/**
* Set the color used for drawing operations (Rect, Line and Clear).
*
* Set the color for drawing or filling rectangles, lines, and points, and for
* SDL_RenderClear().
*
* \param renderer the rendering context
* \param r the red value used to draw on the rendering target
* \param g the green value used to draw on the rendering target
* \param b the blue value used to draw on the rendering target
* \param a the alpha value used to draw on the rendering target. Use SDL_SetRenderDrawBlendMode to
* specify how the alpha channel is used
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetRenderDrawColorFloat
* \sa SDL_RenderClear
* \sa SDL_RenderFillRect
* \sa SDL_RenderFillRects
* \sa SDL_RenderLine
* \sa SDL_RenderLines
* \sa SDL_RenderPoint
* \sa SDL_RenderPoints
* \sa SDL_RenderRect
* \sa SDL_RenderRects
* \sa SDL_SetRenderDrawColor
*/
extern DECLSPEC int SDLCALL SDL_SetRenderDrawColorFloat(SDL_Renderer *renderer, float r, float g, float b, float a);
/**
* Get the color used for drawing operations (Rect, Line and Clear).
*
@ -1291,10 +1413,33 @@ extern DECLSPEC int SDLCALL SDL_SetRenderDrawColor(SDL_Renderer *renderer, Uint8
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetRenderDrawColorFloat
* \sa SDL_SetRenderDrawColor
*/
extern DECLSPEC int SDLCALL SDL_GetRenderDrawColor(SDL_Renderer *renderer, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
/**
* Get the color used for drawing operations (Rect, Line and Clear).
*
* \param renderer the rendering context
* \param r a pointer filled in with the red value used to draw on the
* rendering target
* \param g a pointer filled in with the green value used to draw on the
* rendering target
* \param b a pointer filled in with the blue value used to draw on the
* rendering target
* \param a a pointer filled in with the alpha value used to draw on the
* rendering target
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_SetRenderDrawColorFloat
* \sa SDL_GetRenderDrawColor
*/
extern DECLSPEC int SDLCALL SDL_GetRenderDrawColorFloat(SDL_Renderer *renderer, float *r, float *g, float *b, float *a);
/**
* Set the blend mode used for drawing operations (Fill and Line).
*
@ -1532,7 +1677,7 @@ extern DECLSPEC int SDLCALL SDL_RenderGeometry(SDL_Renderer *renderer,
* \param texture (optional) The SDL texture to use.
* \param xy Vertex positions
* \param xy_stride Byte size to move from one element to the next element
* \param color Vertex colors (as SDL_Color)
* \param color Vertex colors (as SDL_FColor)
* \param color_stride Byte size to move from one element to the next element
* \param uv Vertex normalized texture coordinates
* \param uv_stride Byte size to move from one element to the next element
@ -1552,7 +1697,7 @@ extern DECLSPEC int SDLCALL SDL_RenderGeometry(SDL_Renderer *renderer,
extern DECLSPEC int SDLCALL SDL_RenderGeometryRaw(SDL_Renderer *renderer,
SDL_Texture *texture,
const float *xy, int xy_stride,
const SDL_Color *color, int color_stride,
const SDL_FColor *color, int color_stride,
const float *uv, int uv_stride,
int num_vertices,
const void *indices, int num_indices, int size_indices);