update sdl to release 2.0.22

This commit is contained in:
AzaezelX 2022-04-26 09:17:21 -05:00
parent 3f796d2a06
commit d4307ea413
135 changed files with 5746 additions and 1161 deletions

View file

@ -364,6 +364,7 @@ DATA = \
testgles2_sdf_img_sdf.bmp \
testyuv.bmp \
unifont-13.0.06.hex \
utf8.txt \
$(NULL)
ifneq ($(srcdir), .)

View file

@ -408,6 +408,32 @@ void _validateRectEqualsResults(
refRectB->x, refRectB->y, refRectB->w, refRectB->h);
}
/* !
* \brief Private helper to check SDL_FRectEquals results
*/
void _validateFRectEqualsResults(
SDL_bool equals, SDL_bool expectedEquals,
SDL_FRect *rectA, SDL_FRect *rectB, SDL_FRect *refRectA, SDL_FRect *refRectB)
{
int cmpRes;
SDLTest_AssertCheck(equals == expectedEquals,
"Check for correct equals result: expected %s, got %s testing (%f,%f,%f,%f) and (%f,%f,%f,%f)",
(expectedEquals == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
(equals == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
rectA->x, rectA->y, rectA->w, rectA->h,
rectB->x, rectB->y, rectB->w, rectB->h);
cmpRes = SDL_memcmp(rectA, refRectA, sizeof(*rectA));
SDLTest_AssertCheck(cmpRes == 0,
"Check that source rectangle A was not modified: got (%f,%f,%f,%f) expected (%f,%f,%f,%f)",
rectA->x, rectA->y, rectA->w, rectA->h,
refRectA->x, refRectA->y, refRectA->w, refRectA->h);
cmpRes = SDL_memcmp(rectB, refRectB, sizeof(*rectB));
SDLTest_AssertCheck(cmpRes == 0,
"Check that source rectangle B was not modified: got (%f,%f,%f,%f) expected (%f,%f,%f,%f)",
rectB->x, rectB->y, rectB->w, rectB->h,
refRectB->x, refRectB->y, refRectB->w, refRectB->h);
}
/* !
* \brief Tests SDL_IntersectRect() with B fully inside A
*
@ -1574,6 +1600,69 @@ int rect_testRectEqualsParam(void *arg)
return TEST_COMPLETED;
}
/* !
* \brief Tests SDL_FRectEquals() with various inputs
*
* \sa
* http://wiki.libsdl.org/SDL_FRectEquals
*/
int rect_testFRectEquals(void *arg)
{
SDL_FRect refRectA;
SDL_FRect refRectB;
SDL_FRect rectA;
SDL_FRect rectB;
SDL_bool expectedResult;
SDL_bool result;
/* Equals */
refRectA.x=(float)SDLTest_RandomIntegerInRange(-1024, 1024);
refRectA.y=(float)SDLTest_RandomIntegerInRange(-1024, 1024);
refRectA.w=(float)SDLTest_RandomIntegerInRange(1, 1024);
refRectA.h=(float)SDLTest_RandomIntegerInRange(1, 1024);
refRectB = refRectA;
expectedResult = SDL_TRUE;
rectA = refRectA;
rectB = refRectB;
result = (SDL_bool)SDL_FRectEquals((const SDL_FRect *)&rectA, (const SDL_FRect *)&rectB);
_validateFRectEqualsResults(result, expectedResult, &rectA, &rectB, &refRectA, &refRectB);
return TEST_COMPLETED;
}
/* !
* \brief Negative tests against SDL_FRectEquals() with invalid parameters
*
* \sa
* http://wiki.libsdl.org/SDL_FRectEquals
*/
int rect_testFRectEqualsParam(void *arg)
{
SDL_FRect rectA;
SDL_FRect rectB;
SDL_bool result;
/* data setup -- For the purpose of this test, the values don't matter. */
rectA.x=SDLTest_RandomFloat();
rectA.y=SDLTest_RandomFloat();
rectA.w=SDLTest_RandomFloat();
rectA.h=SDLTest_RandomFloat();
rectB.x=SDLTest_RandomFloat();
rectB.y=SDLTest_RandomFloat();
rectB.w=SDLTest_RandomFloat();
rectB.h=SDLTest_RandomFloat();
/* invalid parameter combinations */
result = (SDL_bool)SDL_FRectEquals((const SDL_FRect *)NULL, (const SDL_FRect *)&rectB);
SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
result = (SDL_bool)SDL_FRectEquals((const SDL_FRect *)&rectA, (const SDL_FRect *)NULL);
SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 2nd parameter is NULL");
result = (SDL_bool)SDL_FRectEquals((const SDL_FRect *)NULL, (const SDL_FRect *)NULL);
SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 2nd parameter are NULL");
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* Rect test cases */
@ -1673,6 +1762,13 @@ static const SDLTest_TestCaseReference rectTest28 =
static const SDLTest_TestCaseReference rectTest29 =
{ (SDLTest_TestCaseFp)rect_testRectEqualsParam, "rect_testRectEqualsParam", "Negative tests against SDL_RectEquals with invalid parameters", TEST_ENABLED };
/* SDL_FRectEquals */
static const SDLTest_TestCaseReference rectTest30 =
{ (SDLTest_TestCaseFp)rect_testFRectEquals, "rect_testFRectEquals", "Tests SDL_FRectEquals with various inputs", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest31 =
{ (SDLTest_TestCaseFp)rect_testFRectEqualsParam, "rect_testFRectEqualsParam", "Negative tests against SDL_FRectEquals with invalid parameters", TEST_ENABLED };
/* !
* \brief Sequence of Rect test cases; functions that handle simple rectangles including overlaps and merges.
@ -1683,7 +1779,7 @@ static const SDLTest_TestCaseReference rectTest29 =
static const SDLTest_TestCaseReference *rectTests[] = {
&rectTest1, &rectTest2, &rectTest3, &rectTest4, &rectTest5, &rectTest6, &rectTest7, &rectTest8, &rectTest9, &rectTest10, &rectTest11, &rectTest12, &rectTest13, &rectTest14,
&rectTest15, &rectTest16, &rectTest17, &rectTest18, &rectTest19, &rectTest20, &rectTest21, &rectTest22, &rectTest23, &rectTest24, &rectTest25, &rectTest26, &rectTest27,
&rectTest28, &rectTest29, NULL
&rectTest28, &rectTest29, &rectTest30, &rectTest31, NULL
};

View file

@ -41,6 +41,7 @@ static const struct
CLS(SOUND),
CLS(TOUCHSCREEN),
CLS(ACCELEROMETER),
CLS(TOUCHPAD),
#undef CLS
{ 0, NULL }
};
@ -185,9 +186,7 @@ static const GuessTest guess_tests[] =
.bus_type = 0x0003,
.vendor_id = 0x054c,
.product_id = 0x09cc,
/* TODO: Should this be MOUSE? That's what it most closely
* resembles */
.expected = SDL_UDEV_DEVICE_UNKNOWN,
.expected = SDL_UDEV_DEVICE_TOUCHPAD,
/* SYN, KEY, ABS */
.ev = { 0x0b },
/* X, Y, multitouch */
@ -596,7 +595,7 @@ static const GuessTest guess_tests[] =
* to the arrow, page up and page down keys, so it's a joystick
* with a subset of a keyboard attached. */
/* TODO: Should this be JOYSTICK, or even JOYSTICK|KEYBOARD? */
.expected = SDL_UDEV_DEVICE_UNKNOWN,
.expected = SDL_UDEV_DEVICE_KEYBOARD,
/* SYN, KEY */
.ev = { 0x03 },
.keys = {
@ -608,7 +607,7 @@ static const GuessTest guess_tests[] =
/* BTN_1, BTN_2, BTN_A, BTN_B, BTN_MODE */
/* 0x100 */ 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x10,
/* 0x140 */ ZEROx8,
/* next, previous */
/* next (keyboard page down), previous (keyboard page up) */
/* 0x180 */ 0x00, 0x00, 0x80, 0x10, ZEROx4,
},
},
@ -659,7 +658,7 @@ static const GuessTest guess_tests[] =
.name = "Wiimote - Classic Controller",
/* TODO: Should this be JOYSTICK, or maybe JOYSTICK|KEYBOARD?
* It's unusual in the same ways as the Wiimote */
.expected = SDL_UDEV_DEVICE_UNKNOWN,
.expected = SDL_UDEV_DEVICE_KEYBOARD,
/* SYN, KEY, ABS */
.ev = { 0x0b },
/* Hat 1-3 */
@ -673,7 +672,7 @@ static const GuessTest guess_tests[] =
/* A, B, X, Y, MODE, TL, TL2, TR, TR2 */
/* 0x100 */ ZEROx4, 0x00, 0x13, 0xdb, 0x10,
/* 0x140 */ ZEROx8,
/* next, previous */
/* next (keyboard page down), previous (keyboard page up) */
/* 0x180 */ 0x00, 0x00, 0x80, 0x10, ZEROx4,
},
},
@ -718,9 +717,7 @@ static const GuessTest guess_tests[] =
.vendor_id = 0x06cb,
.product_id = 0x0000,
.version = 0x0000,
/* TODO: Should this be MOUSE? That's what it most closely
* resembles */
.expected = SDL_UDEV_DEVICE_UNKNOWN,
.expected = SDL_UDEV_DEVICE_TOUCHPAD,
/* SYN, KEY, ABS */
.ev = { 0x0b },
/* X, Y, pressure, multitouch */
@ -756,7 +753,8 @@ static const GuessTest guess_tests[] =
},
{
.name = "Thinkpad ACPI buttons",
.expected = SDL_UDEV_DEVICE_UNKNOWN,
/* SDL treats this as a keyboard because it has a power button */
.expected = SDL_UDEV_DEVICE_KEYBOARD,
/* SYN, KEY, MSC, SW */
.ev = { 0x33 },
.keys = {
@ -815,7 +813,8 @@ static const GuessTest guess_tests[] =
.vendor_id = 0x0000,
.product_id = 0x0003,
.version = 0x0000,
.expected = SDL_UDEV_DEVICE_UNKNOWN,
/* SDL treats KEY_SLEEP as indicating a keyboard */
.expected = SDL_UDEV_DEVICE_KEYBOARD,
/* SYN, KEY */
.ev = { 0x03 },
.keys = {
@ -841,7 +840,8 @@ static const GuessTest guess_tests[] =
.vendor_id = 0x0000,
.product_id = 0x0001,
.version = 0x0000,
.expected = SDL_UDEV_DEVICE_UNKNOWN,
/* SDL treats KEY_POWER as indicating a keyboard */
.expected = SDL_UDEV_DEVICE_KEYBOARD,
/* SYN, KEY */
.ev = { 0x03 },
.keys = {
@ -856,7 +856,8 @@ static const GuessTest guess_tests[] =
.vendor_id = 0x0000,
.product_id = 0x0006,
.version = 0x0000,
.expected = SDL_UDEV_DEVICE_UNKNOWN,
/* SDL treats brightness control, etc. as keyboard keys */
.expected = SDL_UDEV_DEVICE_KEYBOARD,
/* SYN, KEY */
.ev = { 0x03 },
.keys = {
@ -873,7 +874,7 @@ static const GuessTest guess_tests[] =
.vendor_id = 0x17aa,
.product_id = 0x5054,
.version = 0x4101,
.expected = SDL_UDEV_DEVICE_UNKNOWN,
.expected = SDL_UDEV_DEVICE_KEYBOARD,
/* SYN, KEY */
.ev = { 0x03 },
.keys = {
@ -911,9 +912,8 @@ static const GuessTest guess_tests[] =
.product_id = 0x6009,
/* For some reason the special keys like mute and wlan toggle
* show up here instead of, or in addition to, as part of
* the keyboard - so udev reports this as having keys too.
* SDL currently doesn't. */
.expected = SDL_UDEV_DEVICE_MOUSE,
* the keyboard - so both udev and SDL report this as having keys too. */
.expected = SDL_UDEV_DEVICE_MOUSE | SDL_UDEV_DEVICE_KEYBOARD,
/* SYN, KEY, REL, MSC, LED */
.ev = { 0x17, 0x00, 0x02 },
/* X, Y */

View file

@ -38,6 +38,18 @@ typedef struct GLES2_Context
#undef SDL_PROC
} GLES2_Context;
typedef struct shader_data
{
GLuint shader_program, shader_frag, shader_vert;
GLint attr_position;
GLint attr_color, attr_mvp;
int angle_x, angle_y, angle_z;
GLuint position_buffer;
GLuint color_buffer;
} shader_data;
static SDLTest_CommonState *state;
static SDL_GLContext *context = NULL;
@ -197,13 +209,13 @@ multiply_matrix(float *lhs, float *rhs, float *r)
* source: Passed-in shader source code.
* shader_type: Passed to GL, e.g. GL_VERTEX_SHADER.
*/
void
static void
process_shader(GLuint *shader, const char * source, GLint shader_type)
{
GLint status = GL_FALSE;
const char *shaders[1] = { NULL };
char buffer[1024];
GLsizei length;
GLsizei length = 0;
/* Create shader and load into GL. */
*shader = GL_CHECK(ctx.glCreateShader(shader_type));
@ -221,13 +233,35 @@ process_shader(GLuint *shader, const char * source, GLint shader_type)
/* Dump debug info (source and log) if compilation failed. */
if(status != GL_TRUE) {
ctx.glGetProgramInfoLog(*shader, sizeof(buffer), &length, &buffer[0]);
ctx.glGetShaderInfoLog(*shader, sizeof(buffer), &length, &buffer[0]);
buffer[length] = '\0';
SDL_Log("Shader compilation failed: %s", buffer);fflush(stderr);
SDL_Log("Shader compilation failed: %s", buffer);
fflush(stderr);
quit(-1);
}
}
static void
link_program(struct shader_data *data)
{
GLint status = GL_FALSE;
char buffer[1024];
GLsizei length = 0;
GL_CHECK(ctx.glAttachShader(data->shader_program, data->shader_vert));
GL_CHECK(ctx.glAttachShader(data->shader_program, data->shader_frag));
GL_CHECK(ctx.glLinkProgram(data->shader_program));
GL_CHECK(ctx.glGetProgramiv(data->shader_program, GL_LINK_STATUS, &status));
if(status != GL_TRUE) {
ctx.glGetProgramInfoLog(data->shader_program, sizeof(buffer), &length, &buffer[0]);
buffer[length] = '\0';
SDL_Log("Program linking failed: %s", buffer);
fflush(stderr);
quit(-1);
}
}
/* 3D data. Vertex range -0.5..0.5 in all axes.
* Z -0.5 is near, 0.5 is far. */
const float _vertices[] =
@ -363,19 +397,6 @@ const char* _shader_frag_src =
" gl_FragColor = vec4(vv3color, 1.0); "
" } ";
typedef struct shader_data
{
GLuint shader_program, shader_frag, shader_vert;
GLint attr_position;
GLint attr_color, attr_mvp;
int angle_x, angle_y, angle_z;
GLuint position_buffer;
GLuint color_buffer;
} shader_data;
static void
Render(unsigned int width, unsigned int height, shader_data* data)
{
@ -672,9 +693,7 @@ main(int argc, char *argv[])
data->shader_program = GL_CHECK(ctx.glCreateProgram());
/* Attach shaders and link shader_program */
GL_CHECK(ctx.glAttachShader(data->shader_program, data->shader_vert));
GL_CHECK(ctx.glAttachShader(data->shader_program, data->shader_frag));
GL_CHECK(ctx.glLinkProgram(data->shader_program));
link_program(data);
/* Get attribute locations of non-fixed attributes like color and texture coordinates. */
data->attr_position = GL_CHECK(ctx.glGetAttribLocation(data->shader_program, "av4position"));
@ -693,13 +712,13 @@ main(int argc, char *argv[])
GL_CHECK(ctx.glGenBuffers(1, &data->position_buffer));
GL_CHECK(ctx.glBindBuffer(GL_ARRAY_BUFFER, data->position_buffer));
GL_CHECK(ctx.glBufferData(GL_ARRAY_BUFFER, sizeof(_vertices) * 4, _vertices, GL_STATIC_DRAW));
GL_CHECK(ctx.glBufferData(GL_ARRAY_BUFFER, sizeof(_vertices), _vertices, GL_STATIC_DRAW));
GL_CHECK(ctx.glVertexAttribPointer(data->attr_position, 3, GL_FLOAT, GL_FALSE, 0, 0));
GL_CHECK(ctx.glBindBuffer(GL_ARRAY_BUFFER, 0));
GL_CHECK(ctx.glGenBuffers(1, &data->color_buffer));
GL_CHECK(ctx.glBindBuffer(GL_ARRAY_BUFFER, data->color_buffer));
GL_CHECK(ctx.glBufferData(GL_ARRAY_BUFFER, sizeof(_colors) * 4, _colors, GL_STATIC_DRAW));
GL_CHECK(ctx.glBufferData(GL_ARRAY_BUFFER, sizeof(_colors), _colors, GL_STATIC_DRAW));
GL_CHECK(ctx.glVertexAttribPointer(data->attr_color, 3, GL_FLOAT, GL_FALSE, 0, 0));
GL_CHECK(ctx.glBindBuffer(GL_ARRAY_BUFFER, 0));

View file

@ -39,6 +39,11 @@ static Line *active = NULL;
static Line *lines = NULL;
static int buttons = 0;
static SDL_bool wheel_x_active = SDL_FALSE;
static SDL_bool wheel_y_active = SDL_FALSE;
static float wheel_x = SCREEN_WIDTH * 0.5f;
static float wheel_y = SCREEN_HEIGHT * 0.5f;
static SDL_bool done = SDL_FALSE;
void
@ -81,6 +86,25 @@ loop(void *arg)
/* Check for events */
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_MOUSEWHEEL:
if (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) {
event.wheel.preciseX *= -1.0f;
event.wheel.preciseY *= -1.0f;
event.wheel.x *= -1;
event.wheel.y *= -1;
}
if (event.wheel.preciseX != 0.0f) {
wheel_x_active = SDL_TRUE;
/* "positive to the right and negative to the left" */
wheel_x += event.wheel.preciseX * 10.0f;
}
if (event.wheel.preciseY != 0.0f) {
wheel_y_active = SDL_TRUE;
/* "positive away from the user and negative towards the user" */
wheel_y -= event.wheel.preciseY * 10.0f;
}
break;
case SDL_MOUSEMOTION:
if (!active)
break;
@ -134,6 +158,16 @@ loop(void *arg)
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
/* Mouse wheel */
SDL_SetRenderDrawColor(renderer, 0, 255, 128, 255);
if (wheel_x_active) {
SDL_RenderDrawLine(renderer, wheel_x, 0, wheel_x, SCREEN_HEIGHT);
}
if (wheel_y_active) {
SDL_RenderDrawLine(renderer, 0, wheel_y, SCREEN_WIDTH, wheel_y);
}
/* Lines from mouse clicks */
DrawLines(renderer);
if (active)
DrawLine(renderer, active);

View file

@ -126,21 +126,52 @@ static PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB;
static SDL_bool CompileShader(GLhandleARB shader, const char *source)
{
GLint status;
GLint status = 0;
glShaderSourceARB(shader, 1, &source, NULL);
glCompileShaderARB(shader);
glGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &status);
if (status == 0) {
GLint length;
GLint length = 0;
char *info;
glGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
info = SDL_stack_alloc(char, length+1);
glGetInfoLogARB(shader, length, NULL, info);
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to compile shader:\n%s\n%s", source, info);
SDL_stack_free(info);
info = (char *) SDL_malloc(length + 1);
if (!info) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!");
} else {
glGetInfoLogARB(shader, length, NULL, info);
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to compile shader:\n%s\n%s", source, info);
SDL_free(info);
}
return SDL_FALSE;
} else {
return SDL_TRUE;
}
}
static SDL_bool LinkProgram(ShaderData *data)
{
GLint status = 0;
glAttachObjectARB(data->program, data->vert_shader);
glAttachObjectARB(data->program, data->frag_shader);
glLinkProgramARB(data->program);
glGetObjectParameterivARB(data->program, GL_OBJECT_LINK_STATUS_ARB, &status);
if (status == 0) {
GLint length = 0;
char *info;
glGetObjectParameterivARB(data->program, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
info = (char *) SDL_malloc(length + 1);
if (!info) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!");
} else {
glGetInfoLogARB(data->program, length, NULL, info);
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to link program:\n%s", info);
SDL_free(info);
}
return SDL_FALSE;
} else {
return SDL_TRUE;
@ -171,9 +202,9 @@ static SDL_bool CompileShaderProgram(ShaderData *data)
}
/* ... and in the darkness bind them */
glAttachObjectARB(data->program, data->vert_shader);
glAttachObjectARB(data->program, data->frag_shader);
glLinkProgramARB(data->program);
if (!LinkProgram(data)) {
return SDL_FALSE;
}
/* Set up some uniform variables */
glUseProgramObjectARB(data->program);