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
This commit is contained in:
Sam Lantinga
2022-11-30 12:51:59 -08:00
committed by GitHub
parent 14b902faca
commit 5750bcb174
781 changed files with 51659 additions and 55763 deletions

View File

@@ -27,7 +27,7 @@
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;
@@ -57,7 +57,7 @@ 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__
@@ -66,15 +66,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"
@@ -102,19 +102,19 @@ 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); \
} \
}
/*
* Simulates desktop's glRotatef. The matrix is returned in column-major
* order.
/*
* Simulates desktop's glRotatef. The matrix is returned in column-major
* order.
*/
static void
rotate_matrix(float angle, float x, float y, float z, float *r)
@@ -153,16 +153,16 @@ rotate_matrix(float angle, float x, float y, float z, float *r)
}
}
/*
* Simulates gluPerspectiveMatrix
/*
* Simulates gluPerspectiveMatrix
*/
static void
static void
perspective_matrix(float fovy, float aspect, float znear, float zfar, float *r)
{
int i;
float f;
f = 1.0f/SDL_tanf(fovy * 0.5f);
f = 1.0f / SDL_tanf(fovy * 0.5f);
for (i = 0; i < 16; i++) {
r[i] = 0.0;
@@ -176,7 +176,7 @@ perspective_matrix(float fovy, float aspect, float znear, float zfar, float *r)
r[15] = 0.0f;
}
/*
/*
* Multiplies lhs by rhs and writes out to r. All matrices are 4x4 and column
* major. In-place multiplication is supported.
*/
@@ -201,7 +201,7 @@ multiply_matrix(float *lhs, float *rhs, float *r)
}
}
/*
/*
* Create shader, load in source, compile, dump debug as necessary.
*
* shader: Pointer to return created shader ID.
@@ -209,7 +209,7 @@ multiply_matrix(float *lhs, float *rhs, float *r)
* shader_type: Passed to GL, e.g. GL_VERTEX_SHADER.
*/
static void
process_shader(GLuint *shader, const char * source, GLint shader_type)
process_shader(GLuint *shader, const char *source, GLint shader_type)
{
GLint status = GL_FALSE;
const char *shaders[1] = { NULL };
@@ -252,75 +252,145 @@ link_program(struct shader_data *data)
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);
quit(-1);
ctx.glGetProgramInfoLog(data->shader_program, sizeof(buffer), &length, &buffer[0]);
buffer[length] = '\0';
SDL_Log("Program linking failed: %s", buffer);
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[] =
{
* Z -0.5 is near, 0.5 is far. */
const float _vertices[] = {
/* Front face. */
/* Bottom left */
-0.5, 0.5, -0.5,
0.5, -0.5, -0.5,
-0.5, -0.5, -0.5,
-0.5,
0.5,
-0.5,
0.5,
-0.5,
-0.5,
-0.5,
-0.5,
-0.5,
/* Top right */
-0.5, 0.5, -0.5,
0.5, 0.5, -0.5,
0.5, -0.5, -0.5,
-0.5,
0.5,
-0.5,
0.5,
0.5,
-0.5,
0.5,
-0.5,
-0.5,
/* Left face */
/* Bottom left */
-0.5, 0.5, 0.5,
-0.5, -0.5, -0.5,
-0.5, -0.5, 0.5,
-0.5,
0.5,
0.5,
-0.5,
-0.5,
-0.5,
-0.5,
-0.5,
0.5,
/* Top right */
-0.5, 0.5, 0.5,
-0.5, 0.5, -0.5,
-0.5, -0.5, -0.5,
-0.5,
0.5,
0.5,
-0.5,
0.5,
-0.5,
-0.5,
-0.5,
-0.5,
/* Top face */
/* Bottom left */
-0.5, 0.5, 0.5,
0.5, 0.5, -0.5,
-0.5, 0.5, -0.5,
-0.5,
0.5,
0.5,
0.5,
0.5,
-0.5,
-0.5,
0.5,
-0.5,
/* Top right */
-0.5, 0.5, 0.5,
0.5, 0.5, 0.5,
0.5, 0.5, -0.5,
-0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
-0.5,
/* Right face */
/* Bottom left */
0.5, 0.5, -0.5,
0.5, -0.5, 0.5,
0.5, -0.5, -0.5,
0.5,
0.5,
-0.5,
0.5,
-0.5,
0.5,
0.5,
-0.5,
-0.5,
/* Top right */
0.5, 0.5, -0.5,
0.5, 0.5, 0.5,
0.5, -0.5, 0.5,
0.5,
0.5,
-0.5,
0.5,
0.5,
0.5,
0.5,
-0.5,
0.5,
/* Back face */
/* Bottom left */
0.5, 0.5, 0.5,
-0.5, -0.5, 0.5,
0.5, -0.5, 0.5,
0.5,
0.5,
0.5,
-0.5,
-0.5,
0.5,
0.5,
-0.5,
0.5,
/* Top right */
0.5, 0.5, 0.5,
-0.5, 0.5, 0.5,
-0.5, -0.5, 0.5,
0.5,
0.5,
0.5,
-0.5,
0.5,
0.5,
-0.5,
-0.5,
0.5,
/* Bottom face */
/* Bottom left */
-0.5, -0.5, -0.5,
0.5, -0.5, 0.5,
-0.5, -0.5, 0.5,
-0.5,
-0.5,
-0.5,
0.5,
-0.5,
0.5,
-0.5,
-0.5,
0.5,
/* Top right */
-0.5, -0.5, -0.5,
0.5, -0.5, -0.5,
0.5, -0.5, 0.5,
-0.5,
-0.5,
-0.5,
0.5,
-0.5,
-0.5,
0.5,
-0.5,
0.5,
};
const float _colors[] =
{
const float _colors[] = {
/* Front face */
/* Bottom left */
1.0, 0.0, 0.0, /* red */
@@ -377,32 +447,32 @@ const float _colors[] =
1.0, 0.0, 1.0, /* magenta */
};
const char* _shader_vert_src =
" attribute vec4 av4position; "
" attribute vec3 av3color; "
" uniform mat4 mvp; "
" varying vec3 vv3color; "
" void main() { "
" vv3color = av3color; "
" gl_Position = mvp * av4position; "
" } ";
const char *_shader_vert_src =
" attribute vec4 av4position; "
" attribute vec3 av3color; "
" uniform mat4 mvp; "
" varying vec3 vv3color; "
" void main() { "
" vv3color = av3color; "
" gl_Position = mvp * av4position; "
" } ";
const char* _shader_frag_src =
" precision lowp float; "
" varying vec3 vv3color; "
" void main() { "
" gl_FragColor = vec4(vv3color, 1.0); "
" } ";
const char *_shader_frag_src =
" precision lowp float; "
" varying vec3 vv3color; "
" void main() { "
" gl_FragColor = vec4(vv3color, 1.0); "
" } ";
static void
Render(unsigned int width, unsigned int height, shader_data* data)
Render(unsigned int width, unsigned int height, shader_data *data)
{
float matrix_rotate[16], matrix_modelview[16], matrix_perspective[16], matrix_mvp[16];
/*
* Do some rotation with Euler angles. It is not a fixed axis as
* quaterions would be, but the effect is cool.
*/
/*
* Do some rotation with Euler angles. It is not a fixed axis as
* quaterions would be, but the effect is cool.
*/
rotate_matrix((float)data->angle_x, 1.0f, 0.0f, 0.0f, matrix_modelview);
rotate_matrix((float)data->angle_y, 0.0f, 1.0f, 0.0f, matrix_rotate);
@@ -415,7 +485,7 @@ Render(unsigned int width, unsigned int height, shader_data* data)
/* Pull the camera back from the cube */
matrix_modelview[14] -= 2.5;
perspective_matrix(45.0f, (float)width/height, 0.01f, 100.0f, matrix_perspective);
perspective_matrix(45.0f, (float)width / height, 0.01f, 100.0f, matrix_perspective);
multiply_matrix(matrix_perspective, matrix_modelview, matrix_mvp);
GL_CHECK(ctx.glUniformMatrix4fv(data->attr_mvp, 1, GL_FALSE, matrix_mvp));
@@ -476,7 +546,7 @@ render_window(int index)
#ifndef __EMSCRIPTEN__
static int SDLCALL
render_thread_fn(void* render_ctx)
render_thread_fn(void *render_ctx)
{
thread_data *thread = render_ctx;
@@ -539,8 +609,7 @@ loop()
#endif
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int fsaa, accel, threaded;
int value;
@@ -605,11 +674,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);
@@ -621,7 +690,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]);
@@ -638,8 +707,6 @@ main(int argc, char *argv[])
return 0;
}
if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
SDL_GL_SetSwapInterval(1);
} else {
@@ -660,28 +727,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) {
@@ -689,15 +756,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());
}
}
@@ -706,7 +773,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 +795,9 @@ main(int argc, char *argv[])
ctx.glViewport(0, 0, w, h);
data = &datas[i];
data->angle_x = 0; data->angle_y = 0; data->angle_z = 0;
data->angle_x = 0;
data->angle_y = 0;
data->angle_z = 0;
/* Shader Initialization */
process_shader(&data->shader_vert, _shader_vert_src, GL_VERTEX_SHADER);
@@ -782,7 +851,7 @@ main(int argc, char *argv[])
emscripten_set_main_loop(loop, 0, 1);
#else
if (threaded) {
threads = (thread_data*)SDL_calloc(state->num_windows, sizeof(thread_data));
threads = (thread_data *)SDL_calloc(state->num_windows, sizeof(thread_data));
/* Start a render thread for each window */
for (i = 0; i < state->num_windows; ++i) {
@@ -812,7 +881,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__)
quit(0);
@@ -822,8 +891,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;