From d361acdd4e02a0607db2f83e4fbaffa1d41445b9 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Fri, 19 May 2023 15:24:52 +0200 Subject: [PATCH] testgles2_sdf: build with CMake + fix build errors/warnings --- test/CMakeLists.txt | 5 +-- test/testgles2_sdf.c | 86 +++++++++++++++----------------------------- 2 files changed, 32 insertions(+), 59 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 676a8e791..778cb79d5 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -127,6 +127,7 @@ add_sdl_test_executable(testgesture testgesture.c) add_sdl_test_executable(testgl2 testgl2.c) add_sdl_test_executable(testgles testgles.c) add_sdl_test_executable(testgles2 testgles2.c) +add_sdl_test_executable(testgles2_sdf NEEDS_RESOURCES testgles2_sdf.c testutils.c) add_sdl_test_executable(testhaptic testhaptic.c) add_sdl_test_executable(testhotplug testhotplug.c) add_sdl_test_executable(testrumble testrumble.c) @@ -329,7 +330,7 @@ if(N3DS) foreach(APP IN LISTS SDL_TEST_EXECUTABLES) get_target_property(TARGET_BINARY_DIR ${APP} BINARY_DIR) set(SMDH_FILE "${TARGET_BINARY_DIR}/${APP}.smdh") - ctr_generate_smdh("${SMDH_FILE}" + ctr_generate_smdh("${SMDH_FILE}" NAME "SDL-${APP}" DESCRIPTION "SDL2 Test suite" AUTHOR "SDL2 Contributors" @@ -366,7 +367,7 @@ foreach(APP IN LISTS SDL_TESTS_NEEDS_RESOURCES) endif() endforeach(RESOURCE_FILE) if(APPLE) - # Make sure resource files get installed into macOS/iOS .app bundles. + # Make sure resource files get installed into macOS/iOS .app bundles. target_sources(${APP} PRIVATE "${RESOURCE_FILES}") set_target_properties(${APP} PROPERTIES RESOURCE "${RESOURCE_FILES}") endif() diff --git a/test/testgles2_sdf.c b/test/testgles2_sdf.c index 93c21b9b7..a61f9bacf 100644 --- a/test/testgles2_sdf.c +++ b/test/testgles2_sdf.c @@ -10,9 +10,6 @@ freely. */ #include -#include -#include -#include #ifdef __EMSCRIPTEN__ #include @@ -29,6 +26,8 @@ #include "SDL_opengles2.h" +#include "testutils.h" + typedef struct GLES2_Context { #define SDL_PROC(ret, func, params) ret (APIENTRY *func) params; @@ -56,7 +55,7 @@ typedef enum } GLES2_Uniform; -GLuint g_uniform_locations[16]; +GLint g_uniform_locations[16]; static SDLTest_CommonState *state; static SDL_GLContext *context = NULL; @@ -127,8 +126,8 @@ quit(int rc) * source: Passed-in shader source code. * shader_type: Passed to GL, e.g. GL_VERTEX_SHADER. */ -void -process_shader(GLuint *shader, const char * source, GLint shader_type) +void +process_shader(GLint *shader, const char *source, GLenum shader_type) { GLint status = GL_FALSE; const char *shaders[1] = { NULL }; @@ -153,7 +152,7 @@ process_shader(GLuint *shader, const char * source, GLint shader_type) if (status != GL_TRUE) { 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); quit(-1); } } @@ -163,7 +162,7 @@ process_shader(GLuint *shader, const char * source, GLint shader_type) * To get correct rotation for most cases when a_angle is disabled cosine * value is decremented by 1.0 to get proper output with 0.0 which is default value */ -static const Uint8 GLES2_VertexSrc_Default_[] = " \ +static const char GLES2_VertexSrc_Default_[] = " \ uniform mat4 u_projection; \ attribute vec2 a_position; \ attribute vec2 a_texCoord; \ @@ -183,7 +182,7 @@ static const Uint8 GLES2_VertexSrc_Default_[] = " \ } \ "; -static const Uint8 GLES2_FragmentSrc_TextureABGRSrc_[] = " \ +static const char GLES2_FragmentSrc_TextureABGRSrc_[] = " \ precision mediump float; \ uniform sampler2D u_texture; \ uniform vec4 u_color; \ @@ -197,7 +196,7 @@ static const Uint8 GLES2_FragmentSrc_TextureABGRSrc_[] = " \ "; /* RGB to ABGR conversion */ -static const Uint8 GLES2_FragmentSrc_TextureABGRSrc_SDF[] = " \ +static const char GLES2_FragmentSrc_TextureABGRSrc_SDF[] = " \ #extension GL_OES_standard_derivatives : enable\n\ \ precision mediump float; \ @@ -246,7 +245,7 @@ static float matrix_mvp[4][4]; typedef struct shader_data { - GLuint shader_program, shader_frag, shader_vert; + GLint shader_program, shader_frag, shader_vert; GLint attr_position; GLint attr_color, attr_mvp; @@ -254,7 +253,7 @@ typedef struct shader_data } shader_data; static void -Render(unsigned int width, unsigned int height, shader_data* data) +Render(int width, int height, shader_data* data) { float *verts = g_verts; ctx.glViewport(0, 0, 640, 480); @@ -273,7 +272,7 @@ Render(unsigned int width, unsigned int height, shader_data* data) void renderCopy_angle(float degree_angle) { - const float radian_angle = (float)(3.141592 * degree_angle) / 180.0; + const float radian_angle = (float)(3.141592 * degree_angle) / 180.0f; const GLfloat s = (GLfloat) SDL_sin(radian_angle); const GLfloat c = (GLfloat) SDL_cos(radian_angle) - 1.0f; GLfloat *verts = g_verts + 16; @@ -293,15 +292,15 @@ void renderCopy_position(SDL_Rect *srcrect, SDL_Rect *dstrect) GLfloat minu, maxu, minv, maxv; GLfloat *verts = g_verts; - minx = dstrect->x; - miny = dstrect->y; - maxx = dstrect->x + dstrect->w; - maxy = dstrect->y + dstrect->h; + minx = (GLfloat)dstrect->x; + miny = (GLfloat)dstrect->y; + maxx = (GLfloat)dstrect->x + dstrect->w; + maxy = (GLfloat)dstrect->y + dstrect->h; - minu = (GLfloat) srcrect->x / g_surf_sdf->w; - maxu = (GLfloat) (srcrect->x + srcrect->w) / g_surf_sdf->w; - minv = (GLfloat) srcrect->y / g_surf_sdf->h; - maxv = (GLfloat) (srcrect->y + srcrect->h) / g_surf_sdf->h; + minu = (GLfloat) srcrect->x / (GLfloat)g_surf_sdf->w; + maxu = (GLfloat) (srcrect->x + srcrect->w) / (GLfloat)g_surf_sdf->w; + minv = (GLfloat) srcrect->y / (GLfloat)g_surf_sdf->h; + maxv = (GLfloat) (srcrect->y + srcrect->h) / (GLfloat)g_surf_sdf->h; *(verts++) = minx; *(verts++) = miny; @@ -342,43 +341,26 @@ void loop() if (sym == SDLK_TAB) { SDL_Log("Tab"); - - } if (sym == SDLK_LEFT) { - g_val -= 0.05; + g_val -= 0.05f; } if (sym == SDLK_RIGHT) { - g_val += 0.05; + g_val += 0.05f; } if (sym == SDLK_UP) { - g_angle -= 1; + g_angle -= 1.0f; } if (sym == SDLK_DOWN) { - g_angle += 1; + g_angle += 1.0f; } - break; } - if (sym == SDLK_LEFT) { - g_val -= 0.05f; - } - if (sym == SDLK_RIGHT) { - g_val += 0.05f; - } - if (sym == SDLK_UP) { - g_angle -= 1.0f; - } - if (sym == SDLK_DOWN) { - g_angle += 1.0f; - } - break; - } case SDL_WINDOWEVENT: switch (event.window.event) { @@ -411,19 +393,9 @@ void loop() matrix_mvp[3][0] = -1.0f; matrix_mvp[3][3] = 1.0f; - matrix_mvp[0][0] = 2.0f / 640.0; - matrix_mvp[1][1] = -2.0f / 480.0; + matrix_mvp[0][0] = 2.0f / 640.0f; + matrix_mvp[1][1] = -2.0f / 480.0f; matrix_mvp[3][1] = 1.0f; - - if (0) { - float *f = (float *) matrix_mvp; - SDL_Log("-----------------------------------"); - SDL_Log("[ %f, %f, %f, %f ]", *f++, *f++, *f++, *f++); - SDL_Log("[ %f, %f, %f, %f ]", *f++, *f++, *f++, *f++); - SDL_Log("[ %f, %f, %f, %f ]", *f++, *f++, *f++, *f++); - SDL_Log("[ %f, %f, %f, %f ]", *f++, *f++, *f++, *f++); - SDL_Log("-----------------------------------"); - } renderCopy_angle(g_angle); @@ -434,7 +406,7 @@ void loop() SDL_GL_GetDrawableSize(state->windows[0], &w, &h); rs.x = 0; rs.y = 0; rs.w = g_surf_sdf->w; rs.h = g_surf_sdf->h; - rd.w = g_surf_sdf->w * g_val; rd.h = g_surf_sdf->h * g_val; + rd.w = (int)((float)g_surf_sdf->w * g_val); rd.h = (int)((float)g_surf_sdf->h * g_val); rd.x = (w - rd.w) / 2; rd.y = (h - rd.h) / 2; renderCopy_position(&rs, &rd); } @@ -803,9 +775,9 @@ int main(int argc, char *argv[]) SDL_Log("%2.2f frames per second\n", ((double)frames * 1000) / (now - then)); } -#if !defined(__ANDROID__) && !defined(__NACL__) +#if !defined(__ANDROID__) && !defined(__NACL__) quit(0); -#endif +#endif return 0; }