test: build + fix test/testgles2_sdf.c

This commit is contained in:
Anonymous Maarten 2022-11-29 22:43:46 +01:00 committed by GitHub
parent f9f7db4e08
commit e26e893daf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 34 deletions

View File

@ -139,6 +139,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 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)

View File

@ -16,6 +16,7 @@
#endif
#include <SDL3/SDL_test_common.h>
#include "testutils.h"
#if defined(__IOS__) || defined(__ANDROID__) || defined(__EMSCRIPTEN__) || defined(__WINDOWS__) || defined(__LINUX__)
#define HAVE_OPENGLES2
@ -53,7 +54,7 @@ typedef enum
} GLES2_Uniform;
GLuint g_uniform_locations[16];
GLint g_uniform_locations[16];
@ -126,7 +127,7 @@ quit(int rc)
* shader_type: Passed to GL, e.g. GL_VERTEX_SHADER.
*/
void
process_shader(GLuint *shader, const char * source, GLint shader_type)
process_shader(GLenum *shader, const char * source, GLenum shader_type)
{
GLint status = GL_FALSE;
const char *shaders[1] = { NULL };
@ -151,7 +152,7 @@ process_shader(GLuint *shader, const char * source, GLint shader_type)
if (status != GL_TRUE) {
ctx.glGetProgramInfoLog(*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);
}
}
@ -161,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; \
@ -181,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; \
@ -195,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; \
@ -248,7 +249,8 @@ static float matrix_mvp[4][4];
typedef struct shader_data
{
GLuint shader_program, shader_frag, shader_vert;
GLint shader_program;
GLenum shader_frag, shader_vert;
GLint attr_position;
GLint attr_color, attr_mvp;
@ -256,7 +258,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);
@ -276,7 +278,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;
@ -297,15 +299,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;
@ -352,16 +354,16 @@ void loop()
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;
}
@ -400,19 +402,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);
@ -423,7 +415,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);
}