Formatting

This commit is contained in:
Mario Zechner 2024-07-02 12:32:59 +02:00
parent e9aab1c94e
commit bf0a33876a
10 changed files with 665 additions and 658 deletions

View File

@ -21,12 +21,20 @@ spotless {
'spine-cocos2dx/src/**/*.h',
'spine-cocos2dx/example/Classes/**/*.cpp',
'spine-cocos2dx/example/Classes/**/*.h',
'spine-sdl/**/*.c',
'spine-sdl/**/*.cpp',
'spine-sdl/**/*.h',
'spine-sfml/**/*.c',
'spine-sfml/**/*.cpp',
'spine-sfml/**/*.h',
'spine-glfw/src/**/*.cpp',
'spine-glfw/src/**/*.h',
'spine-glfw/example/**/*.cpp',
'spine-glfw/example/**/*.h',
'spine-sdl/src/**/*.c',
'spine-sdl/src/**/*.cpp',
'spine-sdl/src/**/*.h',
'spine-sdl/example/**/*.c',
'spine-sdl/example/**/*.cpp',
'spine-sdl/example/**/*.h',
'spine-sfml/c/src/**/*.c',
'spine-sfml/c/src/**/*.h',
'spine-sfml/cpp/src/**/*.cpp',
'spine-sfml/cpp/src/**/*.h',
'spine-ue/**/*.cpp',
'spine-ue/**/*.h',
'spine-godot/spine_godot/*.cpp',

View File

@ -39,7 +39,7 @@
using namespace spine;
SkeletonRenderer::SkeletonRenderer(): _allocator(4096), _worldVertices(), _quadIndices(), _clipping(), _renderCommands() {
SkeletonRenderer::SkeletonRenderer() : _allocator(4096), _worldVertices(), _quadIndices(), _clipping(), _renderCommands() {
_quadIndices.add(0);
_quadIndices.add(1);
_quadIndices.add(2);

View File

@ -9,7 +9,7 @@ using namespace spine;
int width = 800, height = 600;
GLFWwindow* init_glfw() {
GLFWwindow *init_glfw() {
if (!glfwInit()) {
std::cerr << "Failed to initialize GLFW" << std::endl;
return nullptr;
@ -17,7 +17,7 @@ GLFWwindow* init_glfw() {
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(width, height, "spine-glfw", NULL, NULL);
GLFWwindow *window = glfwCreateWindow(width, height, "spine-glfw", NULL, NULL);
if (!window) {
std::cerr << "Failed to create GLFW window" << std::endl;
glfwTerminate();

View File

@ -25,11 +25,10 @@ typedef struct {
/// The 4 supported blend modes SPINE_BLEND_MODE_NORMAL, SPINE_BLEND_MODE_ADDITIVE, SPINE_BLEND_MODE_MULTIPLY,
/// and SPINE_BLEND_MODE_SCREEN, expressed as OpenGL blend functions.
blend_mode_t blend_modes[] = {
{(unsigned int)GL_SRC_ALPHA, (unsigned int)GL_ONE, (unsigned int)GL_ONE_MINUS_SRC_ALPHA, (unsigned int)GL_ONE},
{(unsigned int)GL_SRC_ALPHA, (unsigned int)GL_ONE, (unsigned int)GL_ONE, (unsigned int)GL_ONE},
{(unsigned int)GL_DST_COLOR, (unsigned int)GL_DST_COLOR, (unsigned int)GL_ONE_MINUS_SRC_ALPHA, (unsigned int)GL_ONE_MINUS_SRC_ALPHA},
{(unsigned int)GL_ONE, (unsigned int)GL_ONE, (unsigned int)GL_ONE_MINUS_SRC_COLOR, (unsigned int)GL_ONE_MINUS_SRC_COLOR}
};
{(unsigned int) GL_SRC_ALPHA, (unsigned int) GL_ONE, (unsigned int) GL_ONE_MINUS_SRC_ALPHA, (unsigned int) GL_ONE},
{(unsigned int) GL_SRC_ALPHA, (unsigned int) GL_ONE, (unsigned int) GL_ONE, (unsigned int) GL_ONE},
{(unsigned int) GL_DST_COLOR, (unsigned int) GL_DST_COLOR, (unsigned int) GL_ONE_MINUS_SRC_ALPHA, (unsigned int) GL_ONE_MINUS_SRC_ALPHA},
{(unsigned int) GL_ONE, (unsigned int) GL_ONE, (unsigned int) GL_ONE_MINUS_SRC_COLOR, (unsigned int) GL_ONE_MINUS_SRC_COLOR}};
mesh_t *mesh_create() {
GLuint vao, vbo, ibo;
@ -42,21 +41,21 @@ mesh_t *mesh_create() {
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(vertex_t), (void*)offsetof(vertex_t, x));
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(vertex_t), (void *) offsetof(vertex_t, x));
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(vertex_t), (void*)offsetof(vertex_t, color));
glVertexAttribPointer(1, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(vertex_t), (void *) offsetof(vertex_t, color));
glEnableVertexAttribArray(1);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(vertex_t), (void*)offsetof(vertex_t, u));
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(vertex_t), (void *) offsetof(vertex_t, u));
glEnableVertexAttribArray(2);
glVertexAttribPointer(3, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(vertex_t), (void*)offsetof(vertex_t, darkColor));
glVertexAttribPointer(3, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(vertex_t), (void *) offsetof(vertex_t, darkColor));
glEnableVertexAttribArray(3);
glBindVertexArray(0);
auto *mesh = (mesh_t*)malloc(sizeof(mesh_t));
auto *mesh = (mesh_t *) malloc(sizeof(mesh_t));
mesh->vao = vao;
mesh->vbo = vbo;
mesh->num_vertices = 0;
@ -69,10 +68,10 @@ void mesh_update(mesh_t *mesh, vertex_t *vertices, int num_vertices, uint16_t *i
glBindVertexArray(mesh->vao);
glBindBuffer(GL_ARRAY_BUFFER, mesh->vbo);
glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)(num_vertices * sizeof(vertex_t)), vertices, GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr) (num_vertices * sizeof(vertex_t)), vertices, GL_STATIC_DRAW);
mesh->num_vertices = num_vertices;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh->ibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)(num_indices * sizeof(uint16_t)), indices, GL_STATIC_DRAW);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr) (num_indices * sizeof(uint16_t)), indices, GL_STATIC_DRAW);
mesh->num_indices = num_indices;
glBindVertexArray(0);
@ -91,7 +90,7 @@ void mesh_dispose(mesh_t *mesh) {
free(mesh);
}
GLuint compile_shader(const char* source, GLenum type) {
GLuint compile_shader(const char *source, GLenum type) {
GLuint shader = glCreateShader(type);
glShaderSource(shader, 1, &source, nullptr);
glCompileShader(shader);
@ -109,7 +108,7 @@ GLuint compile_shader(const char* source, GLenum type) {
return shader;
}
shader_t shader_create(const char* vertex_shader, const char* fragment_shader) {
shader_t shader_create(const char *vertex_shader, const char *fragment_shader) {
shader_t program;
GLuint vertex_shader_id = compile_shader(vertex_shader, GL_VERTEX_SHADER);
@ -139,19 +138,19 @@ shader_t shader_create(const char* vertex_shader, const char* fragment_shader) {
return program;
}
void shader_set_matrix4(shader_t shader, const char* name, const float *matrix) {
void shader_set_matrix4(shader_t shader, const char *name, const float *matrix) {
shader_use(shader);
GLint location = glGetUniformLocation(shader, name);
glUniformMatrix4fv(location, 1, GL_FALSE, matrix);
}
void shader_set_float(shader_t shader, const char* name, float value) {
void shader_set_float(shader_t shader, const char *name, float value) {
shader_use(shader);
GLint location = glGetUniformLocation(shader, name);
glUniform1f(location, value);
}
void shader_set_int(shader_t shader, const char* name, int value) {
void shader_set_int(shader_t shader, const char *name, int value) {
shader_use(shader);
GLint location = glGetUniformLocation(shader, name);
glUniform1i(location, value);
@ -197,7 +196,7 @@ texture_t texture_load(const char *file_path) {
}
void texture_use(texture_t texture) {
glActiveTexture(GL_TEXTURE0); // Set active texture unit to 0
glActiveTexture(GL_TEXTURE0);// Set active texture unit to 0
glBindTexture(GL_TEXTURE_2D, texture);
}
@ -225,11 +224,11 @@ void matrix_ortho_projection(float *matrix, float width, float height) {
}
void GlTextureLoader::load(spine::AtlasPage &page, const spine::String &path) {
page.texture = (void *)(uintptr_t)texture_load(path.buffer());
page.texture = (void *) (uintptr_t) texture_load(path.buffer());
}
void GlTextureLoader::unload(void *texture) {
texture_dispose((texture_t)(uintptr_t)texture);
texture_dispose((texture_t) (uintptr_t) texture);
}
renderer_t *renderer_create() {
@ -252,7 +251,8 @@ renderer_t *renderer_create() {
texCoord = aTexCoord;
gl_Position = uMatrix * vec4(aPos, 0.0, 1.0);
}
)", R"(
)",
R"(
#version 330 core
in vec4 lightColor;
in vec4 darkColor;
@ -269,7 +269,7 @@ renderer_t *renderer_create() {
)");
if (!shader) return nullptr;
mesh_t *mesh = mesh_create();
auto *renderer = (renderer_t*)malloc(sizeof(renderer_t));
auto *renderer = (renderer_t *) malloc(sizeof(renderer_t));
renderer->shader = shader;
renderer->mesh = mesh;
renderer->vertex_buffer_size = 0;
@ -280,7 +280,7 @@ renderer_t *renderer_create() {
void renderer_set_viewport_size(renderer_t *renderer, int width, int height) {
float matrix[16];
matrix_ortho_projection(matrix, (float)width, (float)height);
matrix_ortho_projection(matrix, (float) width, (float) height);
shader_use(renderer->shader);
shader_set_matrix4(renderer->shader, "uMatrix", matrix);
}
@ -296,7 +296,7 @@ void renderer_draw(renderer_t *renderer, Skeleton *skeleton, bool premultipliedA
if (renderer->vertex_buffer_size < num_command_vertices) {
renderer->vertex_buffer_size = num_command_vertices;
free(renderer->vertex_buffer);
renderer->vertex_buffer = (vertex_t *)malloc(sizeof(vertex_t) * renderer->vertex_buffer_size);
renderer->vertex_buffer = (vertex_t *) malloc(sizeof(vertex_t) * renderer->vertex_buffer_size);
}
float *positions = command->positions;
float *uvs = command->uvs;
@ -307,7 +307,7 @@ void renderer_draw(renderer_t *renderer, Skeleton *skeleton, bool premultipliedA
vertex->x = positions[j];
vertex->y = positions[j + 1];
vertex->u = uvs[j];
vertex->v = uvs[j+1];
vertex->v = uvs[j + 1];
uint32_t color = colors[i];
vertex->color = (color & 0xFF00FF00) | ((color & 0x00FF0000) >> 16) | ((color & 0x000000FF) << 16);
uint32_t darkColor = darkColors[i];
@ -318,9 +318,9 @@ void renderer_draw(renderer_t *renderer, Skeleton *skeleton, bool premultipliedA
mesh_update(renderer->mesh, renderer->vertex_buffer, num_command_vertices, indices, num_command_indices);
blend_mode_t blend_mode = blend_modes[command->blendMode];
glBlendFuncSeparate(premultipliedAlpha ? (GLenum)blend_mode.source_color_pma : (GLenum)blend_mode.source_color, (GLenum)blend_mode.dest_color, (GLenum)blend_mode.source_alpha, (GLenum)blend_mode.dest_color);
glBlendFuncSeparate(premultipliedAlpha ? (GLenum) blend_mode.source_color_pma : (GLenum) blend_mode.source_color, (GLenum) blend_mode.dest_color, (GLenum) blend_mode.source_alpha, (GLenum) blend_mode.dest_color);
auto texture = (texture_t)(uintptr_t)command->texture;
auto texture = (texture_t) (uintptr_t) command->texture;
texture_use(texture);
mesh_draw(renderer->mesh);

View File

@ -33,13 +33,13 @@ typedef unsigned int shader_t;
shader_t shader_create(const char *vertex_shader, const char *fragment_shader);
/// Sets a uniform matrix by name
void shader_set_matrix4(shader_t program, const char* name, const float *matrix);
void shader_set_matrix4(shader_t program, const char *name, const float *matrix);
/// Sets a uniform float by name
void shader_set_float(shader_t program, const char* name, float value);
void shader_set_float(shader_t program, const char *name, float value);
/// Sets a uniform int by name
void shader_set_int(shader_t program, const char* name, int value);
void shader_set_int(shader_t program, const char *name, int value);
/// Binds the shader
void shader_use(shader_t shader);
@ -60,7 +60,7 @@ void texture_use(texture_t texture);
void texture_dispose(texture_t texture);
/// A TextureLoader implementation for OpenGL. Use this with spine::Atlas.
class GlTextureLoader: public spine::TextureLoader {
class GlTextureLoader : public spine::TextureLoader {
public:
void load(spine::AtlasPage &page, const spine::String &path);
void unload(void *texture);

View File

@ -71,7 +71,7 @@ inline void toSDLColor(uint32_t color, SDL_Color *sdlColor) {
void SkeletonDrawable::draw(SDL_Renderer *renderer) {
if (!skeletonRenderer) skeletonRenderer = new (__FILE__, __LINE__) SkeletonRenderer();
RenderCommand *command = skeletonRenderer->render(*skeleton);
while(command) {
while (command) {
float *positions = command->positions;
float *uvs = command->uvs;
uint32_t *colors = command->colors;
@ -91,7 +91,7 @@ void SkeletonDrawable::draw(SDL_Renderer *renderer) {
sdlIndices.add(indices[ii]);
BlendMode blendMode = command->blendMode;
SDL_Texture *texture = (SDL_Texture *)command->texture;
SDL_Texture *texture = (SDL_Texture *) command->texture;
if (!usePremultipliedAlpha) {
switch (blendMode) {
case BlendMode_Normal:

View File

@ -40,8 +40,7 @@ sf::BlendMode blendModes[] = {
sf::BlendMode(sf::BlendMode::SrcAlpha, sf::BlendMode::OneMinusSrcAlpha),
sf::BlendMode(sf::BlendMode::SrcAlpha, sf::BlendMode::One),
sf::BlendMode(sf::BlendMode::DstColor, sf::BlendMode::OneMinusSrcAlpha),
sf::BlendMode(sf::BlendMode::One, sf::BlendMode::OneMinusSrcColor)
};
sf::BlendMode(sf::BlendMode::One, sf::BlendMode::OneMinusSrcColor)};
sf::BlendMode blendModesPma[] = {
sf::BlendMode(sf::BlendMode::One, sf::BlendMode::OneMinusSrcAlpha),
@ -95,7 +94,7 @@ void SkeletonDrawable::draw(RenderTarget &target, RenderStates states) const {
float *uvs = command->uvs;
uint32_t *colors = command->colors;
uint16_t *indices = command->indices;
Texture *texture = (Texture *)command->texture;
Texture *texture = (Texture *) command->texture;
Vector2u size = texture->getSize();
for (int i = 0, n = command->numIndices; i < n; ++i) {
int ii = indices[i];