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
+179
-111
@@ -33,7 +33,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;
|
||||
@@ -63,7 +63,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__
|
||||
@@ -74,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"
|
||||
@@ -110,19 +110,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)
|
||||
@@ -161,16 +161,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;
|
||||
@@ -184,7 +184,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.
|
||||
*/
|
||||
@@ -209,7 +209,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.
|
||||
@@ -217,7 +217,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 };
|
||||
@@ -270,67 +270,137 @@ link_program(struct shader_data *data)
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
@@ -387,32 +457,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);
|
||||
|
||||
@@ -425,7 +495,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));
|
||||
@@ -486,7 +556,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;
|
||||
|
||||
@@ -549,8 +619,7 @@ loop()
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int fsaa, accel, threaded;
|
||||
int value;
|
||||
@@ -615,11 +684,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);
|
||||
@@ -631,7 +700,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]);
|
||||
@@ -648,8 +717,6 @@ main(int argc, char *argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
|
||||
SDL_GL_SetSwapInterval(1);
|
||||
} else {
|
||||
@@ -670,28 +737,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) {
|
||||
@@ -699,15 +766,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());
|
||||
}
|
||||
}
|
||||
@@ -716,7 +783,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());
|
||||
}
|
||||
}
|
||||
@@ -738,7 +805,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);
|
||||
@@ -792,7 +861,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) {
|
||||
@@ -822,7 +891,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);
|
||||
@@ -832,8 +901,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