clang-format

This commit is contained in:
Jenny White 2018-04-30 17:23:57 +03:00
parent d8bbae7579
commit 8772b9266d
19 changed files with 99 additions and 127 deletions

View File

@ -16,7 +16,7 @@ struct rgba
{
}
inline constexpr rgba(int r, int g, int b, int a)
: r(r / 255.0f), g(g / 255.0f), b(b / 255.0f), a(a / 255.0f)
: r(r / 255.0f), g(g / 255.0f), b(b / 255.0f), a(a / 255.0f)
{
}
@ -35,7 +35,5 @@ constexpr rgba black(0, 0, 0);
constexpr rgba red(255, 0, 0);
constexpr rgba green(0, 255, 0);
constexpr rgba blue(0, 0, 255);
}
}

View File

@ -16,10 +16,11 @@ class Builder
public:
Builder(int mode, GLuint texture);
Builder& setColor(types::rgba color);
Builder &setColor(types::rgba color);
Builder &push(float x, float y, float u, float v);
Builder &push(float x, float y);
Builder& push(float x, float y, float u, float v);
Builder& push(float x, float y);
protected:
types::rgba color;
@ -27,5 +28,4 @@ protected:
int mode{ 0 };
std::vector<render::vertex> vertices{};
};
}

View File

@ -14,9 +14,9 @@ namespace glez::detail::font
struct font
{
void load(const std::string& path, float size);
void load(const std::string &path, float size);
void unload();
void stringSize(const std::string& string, float *width, float *height);
void stringSize(const std::string &string, float *width, float *height);
bool init{ false };
@ -28,6 +28,5 @@ void init();
void shutdown();
unsigned create();
font& get(unsigned handle);
font &get(unsigned handle);
}

View File

@ -28,5 +28,4 @@ void reset();
unsigned next_index();
extern vertex_buffer_t *buffer;
};

View File

@ -23,5 +23,4 @@ void begin();
void end();
void bind(GLuint texture);
}

View File

@ -15,7 +15,7 @@ namespace glez::detail::texture
struct texture
{
void bind();
void load(const std::string& path);
void load(const std::string &path);
void unload();
bool init{ false };
@ -32,6 +32,5 @@ void init();
void shutdown();
unsigned create();
texture& get(unsigned handle);
texture &get(unsigned handle);
}

View File

@ -16,10 +16,12 @@ namespace glez::draw
void line(int x, int y, int dx, int dy, rgba color, int thickness);
void rect(int x, int y, int w, int h, rgba color);
void rect_outline(int x, int y, int w, int h, rgba color, int thickness);
void rect_textured(int x, int y, int w, int h, rgba color, texture& texture, int tx, int ty, int tw, int th, float angle);
void rect_textured(int x, int y, int w, int h, rgba color, texture &texture,
int tx, int ty, int tw, int th, float angle);
void circle(int x, int y, int radius, rgba color, int thickness, int steps);
void string(int x, int y, const std::string& string, font& font, rgba color, int *width, int *height);
void outlined_string(int x, int y, const std::string& string, font& font, rgba color, rgba outline, int *width, int *height);
void string(int x, int y, const std::string &string, font &font, rgba color,
int *width, int *height);
void outlined_string(int x, int y, const std::string &string, font &font,
rgba color, rgba outline, int *width, int *height);
}

View File

@ -15,7 +15,7 @@ class font
{
public:
inline font(std::string path, float size)
: path(std::move(path)), size(size)
: path(std::move(path)), size(size)
{
}
~font();
@ -41,5 +41,4 @@ protected:
unsigned handle{ std::numeric_limits<unsigned>::max() };
};
}

View File

@ -15,5 +15,4 @@ void resize(int width, int height);
void begin();
void end();
};

View File

@ -14,8 +14,7 @@ namespace glez
class texture
{
public:
inline explicit texture(std::string path)
: path(std::move(path))
inline explicit texture(std::string path) : path(std::move(path))
{
}
~texture();
@ -52,5 +51,4 @@ protected:
unsigned handle{ std::numeric_limits<unsigned>::max() };
};
}

View File

@ -81,7 +81,7 @@ void font::stringSize(const std::string &string, float *width, float *height)
unsigned create()
{
for (auto i = 0u; i < cache->size(); ++i)
if (not (*cache)[i].init)
if (not(*cache)[i].init)
return i;
auto result = cache->size();
cache->push_back(font{});
@ -92,5 +92,4 @@ font &get(unsigned handle)
{
return (*cache)[handle];
}
}

View File

@ -117,9 +117,10 @@ void resize(int width, int height)
void init(int width, int height)
{
buffer = ftgl::vertex_buffer_new("vertex:2f,tex_coord:2f,color:4f,drawmode:1i");
shader = link(compile(shader_vertex, GL_VERTEX_SHADER), compile(shader_fragment, GL_FRAGMENT_SHADER));
buffer =
ftgl::vertex_buffer_new("vertex:2f,tex_coord:2f,color:4f,drawmode:1i");
shader = link(compile(shader_vertex, GL_VERTEX_SHADER),
compile(shader_fragment, GL_FRAGMENT_SHADER));
mat4 model, view;
@ -157,5 +158,4 @@ unsigned next_index()
{
return buffer->vertices->size;
}
}

View File

@ -60,5 +60,4 @@ void bind(GLuint texture)
glBindTexture(GL_TEXTURE_2D, texture);
}
}
}

View File

@ -10,7 +10,9 @@
#include <png.hpp>
#include <memory>
static std::unique_ptr<std::vector<glez::detail::texture::texture>> cache{ nullptr };
static std::unique_ptr<std::vector<glez::detail::texture::texture>> cache{
nullptr
};
namespace glez::detail::texture
{
@ -32,8 +34,8 @@ void texture::bind()
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height,
0, GL_RGBA, GL_UNSIGNED_BYTE, data);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,
GL_UNSIGNED_BYTE, data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@ -47,17 +49,18 @@ void texture::bind()
void texture::load(const std::string &path)
{
png::image<png::rgba_pixel> image(path);
width = image.get_width();
height = image.get_height();
init = true;
bound = false;
id = 0;
width = image.get_width();
height = image.get_height();
init = true;
bound = false;
id = 0;
auto bytes = image.get_width() * image.get_height() * 4;
data = new GLubyte[bytes];
data = new GLubyte[bytes];
for (int i = 0; i < image.get_height(); ++i)
{
memcpy(data + image.get_width() * 4 * i, image.get_pixbuf().get_row(i).data(), image.get_width() * 4);
memcpy(data + image.get_width() * 4 * i,
image.get_pixbuf().get_row(i).data(), image.get_width() * 4);
}
}
@ -70,7 +73,7 @@ void texture::unload()
init = false;
}
texture& get(unsigned handle)
texture &get(unsigned handle)
{
return (*cache)[handle];
}
@ -78,11 +81,10 @@ texture& get(unsigned handle)
unsigned create()
{
for (auto i = 0u; i < cache->size(); ++i)
if (not (*cache)[i].init)
if (not(*cache)[i].init)
return i;
auto result = cache->size();
cache->push_back(texture{});
return result;
}
}

View File

@ -17,10 +17,11 @@ namespace indices
{
static GLuint rectangle[6] = { 0, 1, 2, 2, 3, 0 };
}
void internal_draw_string(int x, int y, const std::string& string, texture_font_t *fnt, glez::rgba color, int *width, int *height)
void internal_draw_string(int x, int y, const std::string &string,
texture_font_t *fnt, glez::rgba color, int *width,
int *height)
{
float pen_x = x;
float pen_y = y + fnt->height / 1.5f;
@ -56,10 +57,11 @@ void internal_draw_string(int x, int y, const std::string& string, texture_font_
continue;
}
glez::detail::render::vertex vertices[4];
for (auto& vertex: vertices)
for (auto &vertex : vertices)
{
vertex.color = color;
vertex.mode = static_cast<int>(glez::detail::program::mode::FREETYPE);
vertex.mode =
static_cast<int>(glez::detail::program::mode::FREETYPE);
}
if (i > 0)
@ -67,33 +69,34 @@ void internal_draw_string(int x, int y, const std::string& string, texture_font_
x += texture_glyph_get_kerning(glyph, &sstring[i - 1]);
}
float x0 = (int)(pen_x + glyph->offset_x);
float y0 = (int)(pen_y - glyph->offset_y);
float x1 = (int)(x0 + glyph->width);
float y1 = (int)(y0 + glyph->height);
float x0 = (int) (pen_x + glyph->offset_x);
float y0 = (int) (pen_y - glyph->offset_y);
float x1 = (int) (x0 + glyph->width);
float y1 = (int) (y0 + glyph->height);
float s0 = glyph->s0;
float t0 = glyph->t0;
float s1 = glyph->s1;
float t1 = glyph->t1;
vertices[0].position = {x0, y0};
vertices[0].uv = {s0, t0};
vertices[0].position = { x0, y0 };
vertices[0].uv = { s0, t0 };
vertices[1].position = {x0, y1};
vertices[1].uv = {s0, t1};
vertices[1].position = { x0, y1 };
vertices[1].uv = { s0, t1 };
vertices[2].position = {x1, y1};
vertices[2].uv = {s1, t1};
vertices[2].position = { x1, y1 };
vertices[2].uv = { s1, t1 };
vertices[3].position = {x1, y0};
vertices[3].uv = {s1, t0};
vertices[3].position = { x1, y0 };
vertices[3].uv = { s1, t0 };
pen_x += glyph->advance_x;
//pen_x = (int) pen_x + 1;
// pen_x = (int) pen_x + 1;
if (glyph->height > size_y)
size_y = glyph->height;
vertex_buffer_push_back(glez::detail::program::buffer, vertices, 4, indices::rectangle, 6);
vertex_buffer_push_back(glez::detail::program::buffer, vertices, 4,
indices::rectangle, 6);
}
if (width)
@ -105,14 +108,13 @@ void internal_draw_string(int x, int y, const std::string& string, texture_font_
namespace glez::draw
{
void line(int x, int y, int dx, int dy, rgba color, int thickness)
{
detail::render::vertex vertices[4];
for (auto &vertex : vertices)
{
vertex.mode = static_cast<int>(detail::program::mode::PLAIN);
vertex.mode = static_cast<int>(detail::program::mode::PLAIN);
vertex.color = color;
}
@ -141,7 +143,8 @@ void line(int x, int y, int dx, int dy, rgba color, int thickness)
vertices[2].position = { x + dx + nx - px, y + dy + ny - py };
vertices[3].position = { x + dx - nx - px, y + dy - ny - py };
ftgl::vertex_buffer_push_back(detail::program::buffer, vertices, 4, indices::rectangle, 6);
ftgl::vertex_buffer_push_back(detail::program::buffer, vertices, 4,
indices::rectangle, 6);
}
void rect(int x, int y, int w, int h, rgba color)
@ -150,7 +153,7 @@ void rect(int x, int y, int w, int h, rgba color)
for (auto &vertex : vertices)
{
vertex.mode = static_cast<int>(detail::program::mode::PLAIN);
vertex.mode = static_cast<int>(detail::program::mode::PLAIN);
vertex.color = color;
}
@ -159,7 +162,8 @@ void rect(int x, int y, int w, int h, rgba color)
vertices[2].position = { x + w, y + h };
vertices[3].position = { x + w, y };
ftgl::vertex_buffer_push_back(detail::program::buffer, vertices, 4, indices::rectangle, 6);
ftgl::vertex_buffer_push_back(detail::program::buffer, vertices, 4,
indices::rectangle, 6);
}
void rect_outline(int x, int y, int w, int h, rgba color, int thickness)
@ -170,8 +174,7 @@ void rect_outline(int x, int y, int w, int h, rgba color, int thickness)
rect(x, y + h - 1, w, 1, color);
}
void circle(int x, int y, int radius, rgba color, int thickness,
int steps)
void circle(int x, int y, int radius, rgba color, int thickness, int steps)
{
float px = 0;
float py = 0;
@ -181,56 +184,54 @@ void circle(int x, int y, int radius, rgba color, int thickness,
if (!i)
ang = 2 * float(M_PI) * (float(steps - 1) / float(steps));
if (i)
line(px, py, x - px + radius * cos(ang),
y - py + radius * sin(ang), color, thickness);
line(px, py, x - px + radius * cos(ang), y - py + radius * sin(ang),
color, thickness);
px = x + radius * cos(ang);
py = y + radius * sin(ang);
}
}
void string(int x, int y, const std::string &string, font& font,
rgba color, int *width, int *height)
void string(int x, int y, const std::string &string, font &font, rgba color,
int *width, int *height)
{
if (!font.isLoaded())
font.load();
auto fnt = glez::detail::font::get(font.getHandle()).font;
fnt->rendermode = RENDER_NORMAL;
auto fnt = glez::detail::font::get(font.getHandle()).font;
fnt->rendermode = RENDER_NORMAL;
fnt->outline_thickness = 0.0f;
internal_draw_string(x, y, string, fnt, color, width, height);
}
void outlined_string(int x, int y, const std::string &string,
font& font, rgba color,
rgba outline, int *width, int *height)
void outlined_string(int x, int y, const std::string &string, font &font,
rgba color, rgba outline, int *width, int *height)
{
if (!font.isLoaded())
font.load();
auto fnt = glez::detail::font::get(font.getHandle()).font;
fnt->rendermode = RENDER_OUTLINE_POSITIVE;
auto fnt = glez::detail::font::get(font.getHandle()).font;
fnt->rendermode = RENDER_OUTLINE_POSITIVE;
fnt->outline_thickness = 1.0f;
internal_draw_string(x, y, string, fnt, outline, width, height);
fnt->rendermode = RENDER_NORMAL;
fnt->rendermode = RENDER_NORMAL;
fnt->outline_thickness = 0.0f;
internal_draw_string(x, y, string, fnt, color, width, height);
}
void
rect_textured(int x, int y, int w, int h, rgba color, texture &texture, int tx, int ty, int tw, int th, float angle)
void rect_textured(int x, int y, int w, int h, rgba color, texture &texture,
int tx, int ty, int tw, int th, float angle)
{
if (!texture.isLoaded())
texture.load();
auto& tex = detail::texture::get(texture.getHandle());
auto &tex = detail::texture::get(texture.getHandle());
tex.bind();
detail::render::vertex vertices[4];
for (auto &vertex : vertices)
{
vertex.mode = static_cast<int>(detail::program::mode::TEXTURED);
vertex.mode = static_cast<int>(detail::program::mode::TEXTURED);
vertex.color = color;
}
@ -244,13 +245,15 @@ rect_textured(int x, int y, int w, int h, rgba color, texture &texture, int tx,
float cx = x + float(w) / 2.0f;
float cy = y + float(h) / 2.0f;
for (auto& v: vertices)
for (auto &v : vertices)
{
float ox = v.position.x;
float oy = v.position.y;
v.position.x = cx + cosf(angle) * (ox - cx) - sinf(angle) * (oy - cy);
v.position.y = cy + sinf(angle) * (ox - cx) + cosf(angle) * (oy - cy);
v.position.x =
cx + cosf(angle) * (ox - cx) - sinf(angle) * (oy - cy);
v.position.y =
cy + sinf(angle) * (ox - cx) + cosf(angle) * (oy - cy);
}
}
@ -259,13 +262,12 @@ rect_textured(int x, int y, int w, int h, rgba color, texture &texture, int tx,
float t0 = float(ty) / texture.getHeight();
float t1 = float(ty + th) / texture.getHeight();
vertices[0].uv = {s0, t0};
vertices[1].uv = {s0, t1};
vertices[2].uv = {s1, t1};
vertices[3].uv = {s1, t0};
vertices[0].uv = { s0, t0 };
vertices[1].uv = { s0, t1 };
vertices[2].uv = { s1, t1 };
vertices[3].uv = { s1, t0 };
ftgl::vertex_buffer_push_back(detail::program::buffer, vertices, 4, indices::rectangle, 6);
ftgl::vertex_buffer_push_back(detail::program::buffer, vertices, 4,
indices::rectangle, 6);
}
}

View File

@ -17,16 +17,15 @@ font::~font()
void font::load()
{
handle = detail::font::create();
auto& font = detail::font::get(handle);
handle = detail::font::create();
auto &font = detail::font::get(handle);
font.load(path, size);
loaded = true;
}
void font::unload()
{
auto& font = detail::font::get(handle);
auto &font = detail::font::get(handle);
font.unload();
}
}

View File

@ -1,19 +0,0 @@
/*
* glez.c
*
* Created on: Dec 7, 2017
* Author: nullifiedcat
*/
#include "glez.h"
#include "internal/program.h"
#include "internal/draw.h"
#include "internal/fonts.h"
#include "internal/textures.h"
#include <vec234.h>
#include <math.h>
#include <string.h>
/* Drawing functions

View File

@ -39,5 +39,4 @@ void end()
{
detail::render::end();
}
}

View File

@ -17,18 +17,17 @@ texture::~texture()
void texture::load()
{
handle = detail::texture::create();
auto& texture = detail::texture::get(handle);
handle = detail::texture::create();
auto &texture = detail::texture::get(handle);
texture.load(path);
width = texture.width;
width = texture.width;
height = texture.height;
loaded = true;
}
void texture::unload()
{
auto& texture = detail::texture::get(handle);
auto &texture = detail::texture::get(handle);
texture.unload();
}
}