update SDL3 to latest commit

This commit is contained in:
Sasha Szpakowski
2024-10-06 20:30:44 -03:00
parent 1b0fdc338b
commit 9e5eb1b018
1426 changed files with 242456 additions and 103496 deletions
+111 -19
View File
@@ -40,6 +40,8 @@ enum
{
StageClearBackground,
StageDrawBackground,
StageTextureBackground,
StageTargetBackground,
StageBlendDrawing,
StageBlendTexture,
StageGradientDrawing,
@@ -57,10 +59,10 @@ static void FreeRenderer(void)
static void UpdateHDRState(void)
{
SDL_PropertiesID props;
SDL_bool HDR_enabled;
bool HDR_enabled;
props = SDL_GetDisplayProperties(SDL_GetDisplayForWindow(window));
HDR_enabled = SDL_GetBooleanProperty(props, SDL_PROP_DISPLAY_HDR_ENABLED_BOOLEAN, SDL_FALSE);
props = SDL_GetWindowProperties(window);
HDR_enabled = SDL_GetBooleanProperty(props, SDL_PROP_WINDOW_HDR_ENABLED_BOOLEAN, false);
SDL_Log("HDR %s\n", HDR_enabled ? "enabled" : "disabled");
@@ -76,10 +78,9 @@ static void UpdateHDRState(void)
static void CreateRenderer(void)
{
SDL_PropertiesID props;
SDL_RendererInfo info;
props = SDL_CreateProperties();
SDL_SetProperty(props, SDL_PROP_RENDERER_CREATE_WINDOW_POINTER, window);
SDL_SetPointerProperty(props, SDL_PROP_RENDERER_CREATE_WINDOW_POINTER, window);
SDL_SetStringProperty(props, SDL_PROP_RENDERER_CREATE_NAME_STRING, SDL_GetRenderDriver(renderer_index));
SDL_SetNumberProperty(props, SDL_PROP_RENDERER_CREATE_OUTPUT_COLORSPACE_NUMBER, colorspace);
renderer = SDL_CreateRendererWithProperties(props);
@@ -89,9 +90,8 @@ static void CreateRenderer(void)
return;
}
SDL_GetRendererInfo(renderer, &info);
SDL_Log("Created renderer %s\n", info.name);
renderer_name = info.name;
renderer_name = SDL_GetRendererName(renderer);
SDL_Log("Created renderer %s\n", renderer_name);
UpdateHDRState();
}
@@ -126,10 +126,6 @@ static void PrevRenderer(void)
static void NextStage(void)
{
if (StageCount <= 0) {
return;
}
++stage_index;
if (stage_index == StageCount) {
stage_index = 0;
@@ -144,11 +140,11 @@ static void PrevStage(void)
}
}
static SDL_bool ReadPixel(int x, int y, SDL_Color *c)
static bool ReadPixel(int x, int y, SDL_Color *c)
{
SDL_Surface *surface;
SDL_Rect r;
SDL_bool result = SDL_FALSE;
bool result = false;
r.x = x;
r.y = y;
@@ -157,8 +153,11 @@ static SDL_bool ReadPixel(int x, int y, SDL_Color *c)
surface = SDL_RenderReadPixels(renderer, &r);
if (surface) {
if (SDL_ReadSurfacePixel(surface, 0, 0, &c->r, &c->g, &c->b, &c->a) == 0) {
result = SDL_TRUE;
/* Don't tonemap back to SDR, our source content was SDR */
SDL_SetStringProperty(SDL_GetSurfaceProperties(surface), SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING, "*=1");
if (SDL_ReadSurfacePixel(surface, 0, 0, &c->r, &c->g, &c->b, &c->a)) {
result = true;
} else {
SDL_Log("Couldn't read pixel: %s\n", SDL_GetError());
}
@@ -241,6 +240,93 @@ static void RenderDrawBackground(void)
}
}
static SDL_Texture *CreateGrayTexture(void)
{
SDL_Texture *texture;
Uint8 pixels[4];
/* Floating point textures are in the linear colorspace by default */
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STATIC, 1, 1);
if (!texture) {
return NULL;
}
pixels[0] = 128;
pixels[1] = 128;
pixels[2] = 128;
pixels[3] = 255;
SDL_UpdateTexture(texture, NULL, pixels, sizeof(pixels));
return texture;
}
static void RenderTextureBackground(void)
{
/* Fill the background with a 50% gray texture.
* This will be darker when using sRGB colors and lighter using linear colors
*/
SDL_Texture *texture = CreateGrayTexture();
SDL_RenderTexture(renderer, texture, NULL, NULL);
SDL_DestroyTexture(texture);
/* Check the renderered pixels */
SDL_Color c;
if (!ReadPixel(0, 0, &c)) {
return;
}
float x = TEXT_START_X;
float y = TEXT_START_Y;
DrawText(x, y, "%s %s", renderer_name, colorspace_name);
y += TEXT_LINE_ADVANCE;
DrawText(x, y, "Test: Fill 50%% Gray Texture");
y += TEXT_LINE_ADVANCE;
DrawText(x, y, "Background color written: 0x808080, read: 0x%.2x%.2x%.2x", c.r, c.g, c.b);
y += TEXT_LINE_ADVANCE;
if (c.r != 128) {
DrawText(x, y, "Incorrect background color, unknown reason");
y += TEXT_LINE_ADVANCE;
}
}
static void RenderTargetBackground(void)
{
/* Fill the background with a 50% gray texture.
* This will be darker when using sRGB colors and lighter using linear colors
*/
SDL_Texture *target = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_TARGET, 1, 1);
SDL_Texture *texture = CreateGrayTexture();
/* Fill the render target with the gray texture */
SDL_SetRenderTarget(renderer, target);
SDL_RenderTexture(renderer, texture, NULL, NULL);
SDL_DestroyTexture(texture);
/* Fill the output with the render target */
SDL_SetRenderTarget(renderer, NULL);
SDL_RenderTexture(renderer, target, NULL, NULL);
SDL_DestroyTexture(target);
/* Check the renderered pixels */
SDL_Color c;
if (!ReadPixel(0, 0, &c)) {
return;
}
float x = TEXT_START_X;
float y = TEXT_START_Y;
DrawText(x, y, "%s %s", renderer_name, colorspace_name);
y += TEXT_LINE_ADVANCE;
DrawText(x, y, "Test: Fill 50%% Gray Render Target");
y += TEXT_LINE_ADVANCE;
DrawText(x, y, "Background color written: 0x808080, read: 0x%.2x%.2x%.2x", c.r, c.g, c.b);
y += TEXT_LINE_ADVANCE;
if (c.r != 128) {
DrawText(x, y, "Incorrect background color, unknown reason");
y += TEXT_LINE_ADVANCE;
}
}
static void RenderBlendDrawing(void)
{
SDL_Color a = { 238, 70, 166, 255 }; /* red square */
@@ -390,7 +476,7 @@ static void DrawGradient(float x, float y, float width, float height, float star
color[2] = max_color;
color[3] = min_color;
SDL_RenderGeometryRawFloat(renderer, NULL, xy, xy_stride, color, color_stride, NULL, 0, num_vertices, indices, num_indices, size_indices);
SDL_RenderGeometryRaw(renderer, NULL, xy, xy_stride, color, color_stride, NULL, 0, num_vertices, indices, num_indices, size_indices);
}
static void RenderGradientDrawing(void)
@@ -505,7 +591,7 @@ static void loop(void)
/* Check for events */
while (SDL_PollEvent(&event)) {
if (event.type == SDL_EVENT_KEY_DOWN) {
switch (event.key.keysym.sym) {
switch (event.key.key) {
case SDLK_ESCAPE:
done = 1;
break;
@@ -525,7 +611,7 @@ static void loop(void)
default:
break;
}
} else if (event.type == SDL_EVENT_DISPLAY_HDR_STATE_CHANGED) {
} else if (event.type == SDL_EVENT_WINDOW_HDR_STATE_CHANGED) {
UpdateHDRState();
} else if (event.type == SDL_EVENT_QUIT) {
done = 1;
@@ -543,6 +629,12 @@ static void loop(void)
case StageDrawBackground:
RenderDrawBackground();
break;
case StageTextureBackground:
RenderTextureBackground();
break;
case StageTargetBackground:
RenderTargetBackground();
break;
case StageBlendDrawing:
RenderBlendDrawing();
break;