mirror of
https://github.com/love2d/megasource.git
synced 2026-08-18 19:54:37 +02:00
update SDL3 to 3.2.10.
This commit is contained in:
@@ -1512,6 +1512,132 @@ static int SDLCALL render_testUVWrapping(void *arg)
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests texture state changes
|
||||
*/
|
||||
static int SDLCALL render_testTextureState(void *arg)
|
||||
{
|
||||
const Uint8 pixels[8] = {
|
||||
0x00, 0x00, 0x00, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF
|
||||
};
|
||||
const SDL_Color expected[] = {
|
||||
/* Step 0: plain copy */
|
||||
{ 0x00, 0x00, 0x00, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
/* Step 1: color mod to red */
|
||||
{ 0x00, 0x00, 0x00, 0xFF },
|
||||
{ 0xFF, 0x00, 0x00, 0xFF },
|
||||
/* Step 2: alpha mod to 128 (cleared to green) */
|
||||
{ 0x00, 0x7F, 0x00, 0xFF },
|
||||
{ 0x80, 0xFF, 0x80, 0xFF },
|
||||
/* Step 3: nearest stretch */
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0x00, 0xFF, 0x00, 0xFF },
|
||||
/* Step 4: linear stretch */
|
||||
{ 0x80, 0x80, 0x80, 0xFF },
|
||||
{ 0x00, 0xFF, 0x00, 0xFF },
|
||||
};
|
||||
SDL_Texture *texture;
|
||||
SDL_Rect rect;
|
||||
SDL_FRect dst;
|
||||
int i;
|
||||
|
||||
/* Clear surface to green */
|
||||
SDL_SetRenderDrawColor(renderer, 0, 255, 0, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
/* Create 2-pixel surface. */
|
||||
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STATIC, 2, 1);
|
||||
SDLTest_AssertCheck(texture != NULL, "Verify SDL_CreateTexture() result");
|
||||
if (texture == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
SDL_UpdateTexture(texture, NULL, pixels, sizeof(pixels));
|
||||
|
||||
dst.x = 0.0f;
|
||||
dst.y = 0.0f;
|
||||
dst.w = 2.0f;
|
||||
dst.h = 1.0f;
|
||||
|
||||
/* Step 0: plain copy */
|
||||
SDL_RenderTexture(renderer, texture, NULL, &dst);
|
||||
dst.y += 1;
|
||||
|
||||
/* Step 1: color mod to red */
|
||||
SDL_SetTextureColorMod(texture, 0xFF, 0x00, 0x00);
|
||||
SDL_RenderTexture(renderer, texture, NULL, &dst);
|
||||
SDL_SetTextureColorMod(texture, 0xFF, 0xFF, 0xFF);
|
||||
dst.y += 1;
|
||||
|
||||
/* Step 2: alpha mod to 128 */
|
||||
SDL_SetTextureAlphaMod(texture, 0x80);
|
||||
SDL_RenderTexture(renderer, texture, NULL, &dst);
|
||||
SDL_SetTextureAlphaMod(texture, 0xFF);
|
||||
dst.y += 1;
|
||||
|
||||
/* Step 3: nearest stretch */
|
||||
dst.w = 1;
|
||||
SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST);
|
||||
SDL_RenderTexture(renderer, texture, NULL, &dst);
|
||||
dst.y += 1;
|
||||
|
||||
/* Step 4: linear stretch */
|
||||
dst.w = 1;
|
||||
SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_LINEAR);
|
||||
SDL_RenderTexture(renderer, texture, NULL, &dst);
|
||||
dst.y += 1;
|
||||
|
||||
/* Verify results */
|
||||
rect.x = 0;
|
||||
rect.y = 0;
|
||||
rect.w = 2;
|
||||
rect.h = 1;
|
||||
for (i = 0; i < SDL_arraysize(expected); ) {
|
||||
const int MAX_DELTA = 1;
|
||||
SDL_Color actual;
|
||||
int deltaR, deltaG, deltaB, deltaA;
|
||||
SDL_Surface *surface = SDL_RenderReadPixels(renderer, &rect);
|
||||
|
||||
SDL_ReadSurfacePixel(surface, 0, 0, &actual.r, &actual.g, &actual.b, &actual.a);
|
||||
deltaR = (actual.r - expected[i].r);
|
||||
deltaG = (actual.g - expected[i].g);
|
||||
deltaB = (actual.b - expected[i].b);
|
||||
deltaA = (actual.a - expected[i].a);
|
||||
SDLTest_AssertCheck(SDL_abs(deltaR) <= MAX_DELTA &&
|
||||
SDL_abs(deltaG) <= MAX_DELTA &&
|
||||
SDL_abs(deltaB) <= MAX_DELTA &&
|
||||
SDL_abs(deltaA) <= MAX_DELTA,
|
||||
"Validate left pixel at step %d, expected %d,%d,%d,%d, got %d,%d,%d,%d", i/2,
|
||||
expected[i].r, expected[i].g, expected[i].b, expected[i].a,
|
||||
actual.r, actual.g, actual.b, actual.a);
|
||||
++i;
|
||||
|
||||
SDL_ReadSurfacePixel(surface, 1, 0, &actual.r, &actual.g, &actual.b, &actual.a);
|
||||
deltaR = (actual.r - expected[i].r);
|
||||
deltaG = (actual.g - expected[i].g);
|
||||
deltaB = (actual.b - expected[i].b);
|
||||
deltaA = (actual.a - expected[i].a);
|
||||
SDLTest_AssertCheck(SDL_abs(deltaR) <= MAX_DELTA &&
|
||||
SDL_abs(deltaG) <= MAX_DELTA &&
|
||||
SDL_abs(deltaB) <= MAX_DELTA &&
|
||||
SDL_abs(deltaA) <= MAX_DELTA,
|
||||
"Validate right pixel at step %d, expected %d,%d,%d,%d, got %d,%d,%d,%d", i/2,
|
||||
expected[i].r, expected[i].g, expected[i].b, expected[i].a,
|
||||
actual.r, actual.g, actual.b, actual.a);
|
||||
++i;
|
||||
|
||||
SDL_DestroySurface(surface);
|
||||
|
||||
rect.y += 1;
|
||||
}
|
||||
|
||||
/* Clean up. */
|
||||
SDL_DestroyTexture(texture);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* ================= Test References ================== */
|
||||
|
||||
/* Render test cases */
|
||||
@@ -1563,6 +1689,10 @@ static const SDLTest_TestCaseReference renderTestUVWrapping = {
|
||||
render_testUVWrapping, "render_testUVWrapping", "Tests geometry UV wrapping", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference renderTestTextureState = {
|
||||
render_testTextureState, "render_testTextureState", "Tests texture state changes", TEST_ENABLED
|
||||
};
|
||||
|
||||
/* Sequence of Render test cases */
|
||||
static const SDLTest_TestCaseReference *renderTests[] = {
|
||||
&renderTestGetNumRenderDrivers,
|
||||
@@ -1577,6 +1707,7 @@ static const SDLTest_TestCaseReference *renderTests[] = {
|
||||
&renderTestClipRect,
|
||||
&renderTestLogicalSize,
|
||||
&renderTestUVWrapping,
|
||||
&renderTestTextureState,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
@@ -750,6 +750,7 @@ static int SDLCALL stdlib_sscanf(void *arg)
|
||||
size_t size_output, expected_size_output;
|
||||
void *ptr_output, *expected_ptr_output;
|
||||
char text[128], text2[128];
|
||||
unsigned int r = 0, g = 0, b = 0;
|
||||
|
||||
expected_output = output = 123;
|
||||
expected_result = -1;
|
||||
@@ -785,6 +786,17 @@ static int SDLCALL stdlib_sscanf(void *arg)
|
||||
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
|
||||
SDLTest_AssertCheck(length == 1, "Check length, expected: 1, got: %i", length);
|
||||
|
||||
expected_result = 3;
|
||||
result = SDL_sscanf("#026", "#%1x%1x%1x", &r, &g, &b);
|
||||
SDLTest_AssertPass("Call to SDL_sscanf(\"#026\", \"#%%1x%%1x%%1x\", &r, &g, &b)");
|
||||
expected_output = 0;
|
||||
SDLTest_AssertCheck(r == expected_output, "Check output for r, expected: %i, got: %i", expected_output, r);
|
||||
expected_output = 2;
|
||||
SDLTest_AssertCheck(g == expected_output, "Check output for g, expected: %i, got: %i", expected_output, g);
|
||||
expected_output = 6;
|
||||
SDLTest_AssertCheck(b == expected_output, "Check output for b, expected: %i, got: %i", expected_output, b);
|
||||
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
|
||||
|
||||
#define SIZED_TEST_CASE(type, var, printf_specifier, scanf_specifier) \
|
||||
var##_output = 123; \
|
||||
var##_length = 0; \
|
||||
|
||||
@@ -112,7 +112,7 @@ static void testBlitBlendModeWithFormats(int mode, SDL_PixelFormat src_format, S
|
||||
int deltaR, deltaG, deltaB, deltaA;
|
||||
|
||||
/* Create dst surface */
|
||||
dst = SDL_CreateSurface(1, 1, dst_format);
|
||||
dst = SDL_CreateSurface(9, 1, dst_format);
|
||||
SDLTest_AssertCheck(dst != NULL, "Verify dst surface is not NULL");
|
||||
if (dst == NULL) {
|
||||
return;
|
||||
@@ -137,7 +137,7 @@ static void testBlitBlendModeWithFormats(int mode, SDL_PixelFormat src_format, S
|
||||
SDL_GetRGBA(color, SDL_GetPixelFormatDetails(dst->format), SDL_GetSurfacePalette(dst), &dstR, &dstG, &dstB, &dstA);
|
||||
|
||||
/* Create src surface */
|
||||
src = SDL_CreateSurface(1, 1, src_format);
|
||||
src = SDL_CreateSurface(9, 1, src_format);
|
||||
SDLTest_AssertCheck(src != NULL, "Verify src surface is not NULL");
|
||||
if (src == NULL) {
|
||||
return;
|
||||
@@ -313,6 +313,24 @@ static void AssertFileExist(const char *filename)
|
||||
|
||||
/* Test case functions */
|
||||
|
||||
/**
|
||||
* Tests creating surface with invalid format
|
||||
*/
|
||||
static int SDLCALL surface_testInvalidFormat(void *arg)
|
||||
{
|
||||
SDL_Surface *surface;
|
||||
|
||||
surface = SDL_CreateSurface(32, 32, SDL_PIXELFORMAT_UNKNOWN);
|
||||
SDLTest_AssertCheck(surface == NULL, "Verify SDL_CreateSurface(SDL_PIXELFORMAT_UNKNOWN) returned NULL");
|
||||
SDL_DestroySurface(surface);
|
||||
|
||||
surface = SDL_CreateSurfaceFrom(32, 32, SDL_PIXELFORMAT_UNKNOWN, NULL, 0);
|
||||
SDLTest_AssertCheck(surface == NULL, "Verify SDL_CreateSurfaceFrom(SDL_PIXELFORMAT_UNKNOWN) returned NULL");
|
||||
SDL_DestroySurface(surface);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests sprite saving and loading
|
||||
*/
|
||||
@@ -1540,6 +1558,10 @@ static int SDLCALL surface_testScale(void *arg)
|
||||
/* ================= Test References ================== */
|
||||
|
||||
/* Surface test cases */
|
||||
static const SDLTest_TestCaseReference surfaceTestInvalidFormat = {
|
||||
surface_testInvalidFormat, "surface_testInvalidFormat", "Tests creating surface with invalid format", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference surfaceTestSaveLoadBitmap = {
|
||||
surface_testSaveLoadBitmap, "surface_testSaveLoadBitmap", "Tests sprite saving and loading.", TEST_ENABLED
|
||||
};
|
||||
@@ -1638,6 +1660,7 @@ static const SDLTest_TestCaseReference surfaceTestScale = {
|
||||
|
||||
/* Sequence of Surface test cases */
|
||||
static const SDLTest_TestCaseReference *surfaceTests[] = {
|
||||
&surfaceTestInvalidFormat,
|
||||
&surfaceTestSaveLoadBitmap,
|
||||
&surfaceTestBlitZeroSource,
|
||||
&surfaceTestBlit,
|
||||
|
||||
Reference in New Issue
Block a user