Update for SDL3 coding style (#6717)
I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base.
In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted.
The script I ran for the src directory is added as build-scripts/clang-format-src.sh
This fixes:
#6592
#6593
#6594
(cherry picked from commit 5750bcb174)
This commit is contained in:
1 parent
5c4bc807f7
commit
b8d85c6939
764 files changed
+50574
-54383
No files matched your search
+102
-105
@@ -31,12 +31,11 @@
|
||||
|
||||
typedef struct GLES2_Context
|
||||
{
|
||||
#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
|
||||
#define SDL_PROC(ret, func, params) ret(APIENTRY *func) params;
|
||||
#include "../src/render/opengles2/SDL_gles2funcs.h"
|
||||
#undef SDL_PROC
|
||||
} GLES2_Context;
|
||||
|
||||
|
||||
static SDL_Surface *g_surf_sdf = NULL;
|
||||
GLenum g_texture;
|
||||
GLenum g_texture_type = GL_TEXTURE_2D;
|
||||
@@ -59,14 +58,12 @@ typedef enum
|
||||
|
||||
GLuint g_uniform_locations[16];
|
||||
|
||||
|
||||
|
||||
static SDLTest_CommonState *state;
|
||||
static SDL_GLContext *context = NULL;
|
||||
static int depth = 16;
|
||||
static GLES2_Context ctx;
|
||||
|
||||
static int LoadContext(GLES2_Context * data)
|
||||
static int LoadContext(GLES2_Context *data)
|
||||
{
|
||||
#if SDL_VIDEO_DRIVER_UIKIT
|
||||
#define __SDL_NOGETPROCADDR__
|
||||
@@ -77,15 +74,15 @@ static int LoadContext(GLES2_Context * data)
|
||||
#endif
|
||||
|
||||
#if defined __SDL_NOGETPROCADDR__
|
||||
#define SDL_PROC(ret,func,params) data->func=func;
|
||||
#define SDL_PROC(ret, func, params) data->func = func;
|
||||
#else
|
||||
#define SDL_PROC(ret,func,params) \
|
||||
do { \
|
||||
data->func = SDL_GL_GetProcAddress(#func); \
|
||||
if ( ! data->func ) { \
|
||||
#define SDL_PROC(ret, func, params) \
|
||||
do { \
|
||||
data->func = SDL_GL_GetProcAddress(#func); \
|
||||
if (!data->func) { \
|
||||
return SDL_SetError("Couldn't load GLES2 function %s: %s", #func, SDL_GetError()); \
|
||||
} \
|
||||
} while ( 0 );
|
||||
} \
|
||||
} while (0);
|
||||
#endif /* __SDL_NOGETPROCADDR__ */
|
||||
|
||||
#include "../src/render/opengles2/SDL_gles2funcs.h"
|
||||
@@ -113,18 +110,17 @@ quit(int rc)
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
#define GL_CHECK(x) \
|
||||
x; \
|
||||
{ \
|
||||
GLenum glError = ctx.glGetError(); \
|
||||
if (glError != GL_NO_ERROR) { \
|
||||
#define GL_CHECK(x) \
|
||||
x; \
|
||||
{ \
|
||||
GLenum glError = ctx.glGetError(); \
|
||||
if (glError != GL_NO_ERROR) { \
|
||||
SDL_Log("glGetError() = %i (0x%.8x) at line %i\n", glError, glError, __LINE__); \
|
||||
quit(1); \
|
||||
} \
|
||||
}
|
||||
quit(1); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
* Create shader, load in source, compile, dump debug as necessary.
|
||||
*
|
||||
* shader: Pointer to return created shader ID.
|
||||
@@ -242,16 +238,12 @@ static const char *GLES2_FragmentSrc_TextureABGRSrc_SDF_dbg = " \
|
||||
} \
|
||||
";
|
||||
|
||||
|
||||
static float g_val = 1.0f;
|
||||
static int g_use_SDF = 1;
|
||||
static int g_use_SDF_debug = 0;
|
||||
static int g_use_SDF = 1;
|
||||
static int g_use_SDF_debug = 0;
|
||||
static float g_angle = 0.0f;
|
||||
static float matrix_mvp[4][4];
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct shader_data
|
||||
{
|
||||
GLuint shader_program, shader_frag, shader_vert;
|
||||
@@ -272,15 +264,14 @@ Render(unsigned int width, unsigned int height, shader_data* data)
|
||||
GL_CHECK(ctx.glUniformMatrix4fv(g_uniform_locations[GLES2_UNIFORM_PROJECTION], 1, GL_FALSE, (const float *)matrix_mvp));
|
||||
GL_CHECK(ctx.glUniform4f(g_uniform_locations[GLES2_UNIFORM_COLOR], 1.0f, 1.0f, 1.0f, 1.0f));
|
||||
|
||||
GL_CHECK(ctx.glVertexAttribPointer(GLES2_ATTRIBUTE_ANGLE, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid *) (verts + 16)));
|
||||
GL_CHECK(ctx.glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid *) (verts + 8)));
|
||||
GL_CHECK(ctx.glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid *) verts));
|
||||
GL_CHECK(ctx.glVertexAttribPointer(GLES2_ATTRIBUTE_ANGLE, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid *)(verts + 16)));
|
||||
GL_CHECK(ctx.glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid *)(verts + 8)));
|
||||
GL_CHECK(ctx.glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid *)verts));
|
||||
|
||||
GL_CHECK(ctx.glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||
}
|
||||
|
||||
|
||||
void renderCopy_angle(float degree_angle)
|
||||
void renderCopy_angle(float degree_angle)
|
||||
{
|
||||
const float radian_angle = (float)(3.141592 * degree_angle) / 180.0;
|
||||
const GLfloat s = (GLfloat) SDL_sin(radian_angle);
|
||||
@@ -296,8 +287,7 @@ void renderCopy_angle(float degree_angle)
|
||||
*(verts++) = c;
|
||||
}
|
||||
|
||||
|
||||
void renderCopy_position(SDL_Rect *srcrect, SDL_Rect *dstrect)
|
||||
void renderCopy_position(SDL_Rect *srcrect, SDL_Rect *dstrect)
|
||||
{
|
||||
GLfloat minx, miny, maxx, maxy;
|
||||
GLfloat minu, maxu, minv, maxv;
|
||||
@@ -347,8 +337,8 @@ void loop()
|
||||
while (SDL_PollEvent(&event) && !done) {
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
{
|
||||
const int sym = event.key.keysym.sym;
|
||||
{
|
||||
const int sym = event.key.keysym.sym;
|
||||
|
||||
if (sym == SDLK_TAB) {
|
||||
SDL_Log("Tab");
|
||||
@@ -374,35 +364,50 @@ void loop()
|
||||
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) {
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (event.window.windowID == SDL_GetWindowID(state->windows[i])) {
|
||||
int w, h;
|
||||
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
|
||||
if (status) {
|
||||
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
|
||||
break;
|
||||
}
|
||||
/* Change view port to the new window dimensions */
|
||||
SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
|
||||
ctx.glViewport(0, 0, w, h);
|
||||
state->window_w = event.window.data1;
|
||||
state->window_h = event.window.data2;
|
||||
/* Update window content */
|
||||
Render(event.window.data1, event.window.data2, &datas[i]);
|
||||
SDL_GL_SwapWindow(state->windows[i]);
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (event.window.windowID == SDL_GetWindowID(state->windows[i])) {
|
||||
int w, h;
|
||||
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
|
||||
if (status) {
|
||||
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
|
||||
break;
|
||||
}
|
||||
/* Change view port to the new window dimensions */
|
||||
SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
|
||||
ctx.glViewport(0, 0, w, h);
|
||||
state->window_w = event.window.data1;
|
||||
state->window_h = event.window.data2;
|
||||
/* Update window content */
|
||||
Render(event.window.data1, event.window.data2, &datas[i]);
|
||||
SDL_GL_SwapWindow(state->windows[i]);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
|
||||
|
||||
matrix_mvp[3][0] = -1.0f;
|
||||
matrix_mvp[3][3] = 1.0f;
|
||||
|
||||
@@ -433,20 +438,19 @@ void loop()
|
||||
rd.x = (w - rd.w) / 2; rd.y = (h - rd.h) / 2;
|
||||
renderCopy_position(&rs, &rd);
|
||||
}
|
||||
|
||||
|
||||
if (!done) {
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
|
||||
if (status) {
|
||||
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
|
||||
if (status) {
|
||||
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
|
||||
|
||||
/* Continue for next window */
|
||||
continue;
|
||||
}
|
||||
Render(state->window_w, state->window_h, &datas[i]);
|
||||
SDL_GL_SwapWindow(state->windows[i]);
|
||||
}
|
||||
/* Continue for next window */
|
||||
continue;
|
||||
}
|
||||
Render(state->window_w, state->window_h, &datas[i]);
|
||||
SDL_GL_SwapWindow(state->windows[i]);
|
||||
}
|
||||
}
|
||||
#ifdef __EMSCRIPTEN__
|
||||
else {
|
||||
@@ -455,8 +459,7 @@ void loop()
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int fsaa, accel;
|
||||
int value;
|
||||
@@ -518,11 +521,11 @@ main(int argc, char *argv[])
|
||||
state->gl_profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
|
||||
|
||||
if (fsaa) {
|
||||
state->gl_multisamplebuffers=1;
|
||||
state->gl_multisamplesamples=fsaa;
|
||||
state->gl_multisamplebuffers = 1;
|
||||
state->gl_multisamplesamples = fsaa;
|
||||
}
|
||||
if (accel) {
|
||||
state->gl_accelerated=1;
|
||||
state->gl_accelerated = 1;
|
||||
}
|
||||
if (!SDLTest_CommonInit(state)) {
|
||||
quit(2);
|
||||
@@ -534,7 +537,7 @@ main(int argc, char *argv[])
|
||||
SDL_Log("Out of memory!\n");
|
||||
quit(2);
|
||||
}
|
||||
|
||||
|
||||
/* Create OpenGL ES contexts */
|
||||
for (i = 0; i < state->num_windows; i++) {
|
||||
context[i] = SDL_GL_CreateContext(state->windows[i]);
|
||||
@@ -551,8 +554,8 @@ main(int argc, char *argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_memset(matrix_mvp, 0, sizeof (matrix_mvp));
|
||||
|
||||
SDL_memset(matrix_mvp, 0, sizeof(matrix_mvp));
|
||||
|
||||
{
|
||||
SDL_Surface *tmp;
|
||||
char *f;
|
||||
@@ -564,7 +567,7 @@ main(int argc, char *argv[])
|
||||
} else {
|
||||
f = "testgles2_sdf_img_normal.bmp";
|
||||
}
|
||||
|
||||
|
||||
SDL_Log("SDF is %s", g_use_SDF ? "enabled" : "disabled");
|
||||
|
||||
/* Load SDF BMP image */
|
||||
@@ -592,10 +595,10 @@ main(int argc, char *argv[])
|
||||
#else
|
||||
/* Generate SDF image using SDL_ttf */
|
||||
|
||||
#include "SDL_ttf.h"
|
||||
#include "SDL_ttf.h"
|
||||
char *font_file = "./font/DroidSansFallback.ttf";
|
||||
char *str = "Abcde";
|
||||
SDL_Color color = { 0, 0,0, 255};
|
||||
SDL_Color color = { 0, 0, 0, 255 };
|
||||
|
||||
TTF_Init();
|
||||
TTF_Font *font = TTF_OpenFont(font_file, 72);
|
||||
@@ -623,7 +626,6 @@ main(int argc, char *argv[])
|
||||
SDL_SetSurfaceBlendMode(g_surf_sdf, SDL_BLENDMODE_BLEND);
|
||||
}
|
||||
|
||||
|
||||
if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
|
||||
SDL_GL_SetSwapInterval(1);
|
||||
} else {
|
||||
@@ -643,28 +645,28 @@ main(int argc, char *argv[])
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_RED_SIZE: %s\n",
|
||||
SDL_Log("Failed to get SDL_GL_RED_SIZE: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_GREEN_SIZE: %s\n",
|
||||
SDL_Log("Failed to get SDL_GL_GREEN_SIZE: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_BLUE_SIZE: %s\n",
|
||||
SDL_Log("Failed to get SDL_GL_BLUE_SIZE: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", depth, value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_DEPTH_SIZE: %s\n",
|
||||
SDL_Log("Failed to get SDL_GL_DEPTH_SIZE: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
if (fsaa) {
|
||||
@@ -672,15 +674,15 @@ main(int argc, char *argv[])
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
|
||||
SDL_Log("Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
|
||||
value);
|
||||
value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
|
||||
SDL_Log("Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
}
|
||||
@@ -689,7 +691,7 @@ main(int argc, char *argv[])
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
|
||||
SDL_Log("Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
}
|
||||
@@ -728,7 +730,6 @@ main(int argc, char *argv[])
|
||||
GL_CHECK(ctx.glTexSubImage2D(g_texture_type, 0, 0 /* xoffset */, 0 /* yoffset */, g_surf_sdf->w, g_surf_sdf->h, format, type, g_surf_sdf->pixels));
|
||||
}
|
||||
|
||||
|
||||
SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
|
||||
ctx.glViewport(0, 0, w, h);
|
||||
|
||||
@@ -767,23 +768,20 @@ main(int argc, char *argv[])
|
||||
|
||||
GL_CHECK(ctx.glUseProgram(data->shader_program));
|
||||
|
||||
ctx.glEnableVertexAttribArray((GLenum) GLES2_ATTRIBUTE_ANGLE);
|
||||
ctx.glDisableVertexAttribArray((GLenum) GLES2_ATTRIBUTE_CENTER);
|
||||
ctx.glEnableVertexAttribArray((GLenum)GLES2_ATTRIBUTE_ANGLE);
|
||||
ctx.glDisableVertexAttribArray((GLenum)GLES2_ATTRIBUTE_CENTER);
|
||||
ctx.glEnableVertexAttribArray(GLES2_ATTRIBUTE_POSITION);
|
||||
ctx.glEnableVertexAttribArray((GLenum) GLES2_ATTRIBUTE_TEXCOORD);
|
||||
|
||||
|
||||
ctx.glUniform1i(g_uniform_locations[GLES2_UNIFORM_TEXTURE], 0); /* always texture unit 0. */
|
||||
ctx.glActiveTexture(GL_TEXTURE0);
|
||||
ctx.glBindTexture(g_texture_type, g_texture);
|
||||
GL_CHECK(ctx.glClearColor(1, 1, 1, 1));
|
||||
|
||||
// SDL_BLENDMODE_BLEND
|
||||
GL_CHECK(ctx.glEnable(GL_BLEND));
|
||||
ctx.glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
ctx.glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
|
||||
ctx.glEnableVertexAttribArray((GLenum)GLES2_ATTRIBUTE_TEXCOORD);
|
||||
|
||||
ctx.glUniform1i(g_uniform_locations[GLES2_UNIFORM_TEXTURE], 0); /* always texture unit 0. */
|
||||
ctx.glActiveTexture(GL_TEXTURE0);
|
||||
ctx.glBindTexture(g_texture_type, g_texture);
|
||||
GL_CHECK(ctx.glClearColor(1, 1, 1, 1));
|
||||
|
||||
// SDL_BLENDMODE_BLEND
|
||||
GL_CHECK(ctx.glEnable(GL_BLEND));
|
||||
ctx.glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
ctx.glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
|
||||
}
|
||||
|
||||
/* Main render loop */
|
||||
@@ -803,7 +801,7 @@ main(int argc, char *argv[])
|
||||
now = SDL_GetTicks();
|
||||
if (now > then) {
|
||||
SDL_Log("%2.2f frames per second\n",
|
||||
((double) frames * 1000) / (now - then));
|
||||
((double)frames * 1000) / (now - then));
|
||||
}
|
||||
#if !defined(__ANDROID__) && !defined(__NACL__)
|
||||
quit(0);
|
||||
@@ -813,8 +811,7 @@ main(int argc, char *argv[])
|
||||
|
||||
#else /* HAVE_OPENGLES2 */
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Log("No OpenGL ES support on this system\n");
|
||||
return 1;
|
||||
|
||||
Reference in new issue
Block a user