This commit is contained in:
TotallyNotElite 2018-12-04 16:32:56 +01:00
parent caca15cd63
commit dd0158bcb3
21 changed files with 72 additions and 51 deletions

2
.clang-format Normal file → Executable file
View File

@ -10,6 +10,7 @@ AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: 'false' AllowShortIfStatementsOnASingleLine: 'false'
AllowShortLoopsOnASingleLine: 'false' AllowShortLoopsOnASingleLine: 'false'
BreakBeforeBraces: Allman BreakBeforeBraces: Allman
ColumnLimit: 0
ConstructorInitializerAllOnOneLineOrOnePerLine: 'false' ConstructorInitializerAllOnOneLineOrOnePerLine: 'false'
Cpp11BracedListStyle: 'false' Cpp11BracedListStyle: 'false'
IndentCaseLabels: 'false' IndentCaseLabels: 'false'
@ -31,4 +32,5 @@ Standard: Auto
TabWidth: '4' TabWidth: '4'
UseTab: Never UseTab: Never
... ...

View File

@ -35,5 +35,5 @@ constexpr rgba black(0, 0, 0);
constexpr rgba red(255, 0, 0); constexpr rgba red(255, 0, 0);
constexpr rgba green(0, 255, 0); constexpr rgba green(0, 255, 0);
constexpr rgba blue(0, 0, 255); constexpr rgba blue(0, 0, 255);
} } // namespace color
} } // namespace glez

View File

@ -29,4 +29,4 @@ void shutdown();
unsigned create(); unsigned create();
font &get(unsigned handle); font &get(unsigned handle);
} } // namespace glez::detail::font

View File

@ -29,4 +29,4 @@ void begin();
void end(); void end();
extern vertex_buffer_t *buffer; extern vertex_buffer_t *buffer;
}; }; // namespace glez::detail::program

View File

@ -32,11 +32,13 @@ public:
~RecordedCommands(); ~RecordedCommands();
void reset(); void reset();
void store(glez::detail::render::vertex *vertices, size_t vcount, uint32_t *indices, size_t icount); void store(glez::detail::render::vertex *vertices, size_t vcount,
uint32_t *indices, size_t icount);
void bindTexture(glez::detail::texture::texture *tx); void bindTexture(glez::detail::texture::texture *tx);
void bindFont(ftgl::texture_font_t *font); void bindFont(ftgl::texture_font_t *font);
void render(); void render();
void end(); void end();
protected: protected:
void cutSegment(); void cutSegment();
@ -48,4 +50,4 @@ protected:
extern RecordedCommands *currentRecord; extern RecordedCommands *currentRecord;
extern bool isReplaying; extern bool isReplaying;
} } // namespace glez::detail::record

View File

@ -23,4 +23,4 @@ void begin();
void end(); void end();
void bind(GLuint texture); void bind(GLuint texture);
} } // namespace glez::detail::render

View File

@ -33,4 +33,4 @@ void shutdown();
unsigned create(); unsigned create();
texture &get(unsigned handle); texture &get(unsigned handle);
} } // namespace glez::detail::texture

View File

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

View File

@ -42,4 +42,4 @@ protected:
unsigned handle{ std::numeric_limits<unsigned>::max() }; unsigned handle{ std::numeric_limits<unsigned>::max() };
}; };
} } // namespace glez

View File

@ -16,4 +16,4 @@ void resize(int width, int height);
void begin(); void begin();
void end(); void end();
}; }; // namespace glez

View File

@ -1,3 +1,5 @@
#pragma once #pragma once
#include <vector> #include <vector>
int decodePNG(unsigned char* &out_image, int& image_width, int& image_height, const unsigned char* in_png, size_t in_size, bool convert_to_rgba32 = true); int decodePNG(unsigned char *&out_image, int &image_width, int &image_height,
const unsigned char *in_png, size_t in_size,
bool convert_to_rgba32 = true);

View File

@ -25,4 +25,4 @@ public:
detail::record::RecordedCommands *commands{ nullptr }; detail::record::RecordedCommands *commands{ nullptr };
}; };
} } // namespace glez::record

View File

@ -57,4 +57,4 @@ protected:
unsigned handle{ std::numeric_limits<unsigned>::max() }; unsigned handle{ std::numeric_limits<unsigned>::max() };
}; };
} } // namespace glez

View File

@ -93,4 +93,4 @@ font &get(unsigned handle)
{ {
return (*cache)[handle]; return (*cache)[handle];
} }
} } // namespace glez::detail::font

View File

@ -153,4 +153,4 @@ void end()
glUseProgram(0); glUseProgram(0);
} }
} } // namespace glez::detail::program

View File

@ -14,7 +14,7 @@ void RecordedCommands::render()
{ {
isReplaying = true; isReplaying = true;
vertex_buffer_render_setup(vertex_buffer, GL_TRIANGLES); vertex_buffer_render_setup(vertex_buffer, GL_TRIANGLES);
for (const auto& i: segments) for (const auto &i : segments)
{ {
if (i.texture) if (i.texture)
{ {
@ -31,32 +31,37 @@ void RecordedCommands::render()
if (i.font->atlas->dirty) if (i.font->atlas->dirty)
{ {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, i.font->atlas->width, glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, i.font->atlas->width,
i.font->atlas->height, 0, GL_RED, GL_UNSIGNED_BYTE, i.font->atlas->height, 0, GL_RED, GL_UNSIGNED_BYTE,
i.font->atlas->data); i.font->atlas->data);
i.font->atlas->dirty = 0; i.font->atlas->dirty = 0;
} }
} }
glDrawElements(GL_TRIANGLES, i.size, GL_UNSIGNED_INT, (void *)(i.start * 4)); glDrawElements(GL_TRIANGLES, i.size, GL_UNSIGNED_INT,
(void *) (i.start * 4));
} }
vertex_buffer_render_finish(vertex_buffer); vertex_buffer_render_finish(vertex_buffer);
isReplaying = false; isReplaying = false;
} }
void void RecordedCommands::store(glez::detail::render::vertex *vertices,
RecordedCommands::store(glez::detail::render::vertex *vertices, size_t vcount, size_t vcount, uint32_t *indices, size_t icount)
uint32_t *indices, size_t icount)
{ {
vertex_buffer_push_back(vertex_buffer, vertices, vcount, indices, icount); vertex_buffer_push_back(vertex_buffer, vertices, vcount, indices, icount);
} }
RecordedCommands::RecordedCommands() RecordedCommands::RecordedCommands()
{ {
vertex_buffer = vertex_buffer_new("vertex:2f,tex_coord:2f,color:4f,drawmode:1i"); vertex_buffer =
vertex_buffer_new("vertex:2f,tex_coord:2f,color:4f,drawmode:1i");
} }
RecordedCommands::~RecordedCommands() RecordedCommands::~RecordedCommands()
@ -106,7 +111,7 @@ void RecordedCommands::end()
RecordedCommands *currentRecord{ nullptr }; RecordedCommands *currentRecord{ nullptr };
bool isReplaying{ false }; bool isReplaying{ false };
} } // namespace glez::detail::record
glez::record::Record::Record() glez::record::Record::Record()
{ {

View File

@ -68,4 +68,4 @@ void bind(GLuint texture)
glBindTexture(GL_TEXTURE_2D, texture); glBindTexture(GL_TEXTURE_2D, texture);
} }
} }
} } // namespace glez::detail::render

View File

@ -73,9 +73,9 @@ bool texture::load(const std::string &path)
printf("Error loading texture, error code %i\n", error); printf("Error loading texture, error code %i\n", error);
return false; return false;
} }
init = true; init = true;
bound = false; bound = false;
id = 0; id = 0;
return true; return true;
} }

View File

@ -110,10 +110,11 @@ void internal_draw_string(float x, float y, const std::string &string,
size_y = glyph->height; size_y = glyph->height;
if (glez::detail::record::currentRecord) if (glez::detail::record::currentRecord)
glez::detail::record::currentRecord->store(vertices, 4, indices::rectangle, 6); glez::detail::record::currentRecord->store(vertices, 4,
indices::rectangle, 6);
else else
vertex_buffer_push_back(glez::detail::program::buffer, vertices, 4, vertex_buffer_push_back(glez::detail::program::buffer, vertices, 4,
indices::rectangle, 6); indices::rectangle, 6);
} }
if (width) if (width)
@ -169,10 +170,11 @@ void line(float x, float y, float dx, float dy, rgba color, float thickness)
vertices[0].position = { ex + nx - px, ey + ny - py }; vertices[0].position = { ex + nx - px, ey + ny - py };
if (detail::record::currentRecord) if (detail::record::currentRecord)
detail::record::currentRecord->store(vertices, 4, indices::rectangle, 6); detail::record::currentRecord->store(vertices, 4, indices::rectangle,
6);
else else
ftgl::vertex_buffer_push_back(detail::program::buffer, vertices, 4, ftgl::vertex_buffer_push_back(detail::program::buffer, vertices, 4,
indices::rectangle, 6); indices::rectangle, 6);
} }
void rect(float x, float y, float w, float h, rgba color) void rect(float x, float y, float w, float h, rgba color)
@ -191,13 +193,15 @@ void rect(float x, float y, float w, float h, rgba color)
vertices[3].position = { x + w, y }; vertices[3].position = { x + w, y };
if (detail::record::currentRecord) if (detail::record::currentRecord)
detail::record::currentRecord->store(vertices, 4, indices::rectangle, 6); detail::record::currentRecord->store(vertices, 4, indices::rectangle,
6);
else else
ftgl::vertex_buffer_push_back(detail::program::buffer, vertices, 4, ftgl::vertex_buffer_push_back(detail::program::buffer, vertices, 4,
indices::rectangle, 6); indices::rectangle, 6);
} }
void rect_outline(float x, float y, float w, float h, rgba color, float thickness) void rect_outline(float x, float y, float w, float h, rgba color,
float thickness)
{ {
rect(x, y, w, 1, color); rect(x, y, w, 1, color);
rect(x, y, 1, h, color); rect(x, y, 1, h, color);
@ -205,7 +209,8 @@ void rect_outline(float x, float y, float w, float h, rgba color, float thicknes
rect(x, y + h - 1, w, 1, color); rect(x, y + h - 1, w, 1, color);
} }
void circle(float x, float y, float radius, rgba color, float thickness, int steps) void circle(float x, float y, float radius, rgba color, float thickness,
int steps)
{ {
float px = 0; float px = 0;
float py = 0; float py = 0;
@ -249,12 +254,13 @@ void outlined_string(float x, float y, const std::string &string, font &font,
internal_draw_string(x, y, string, fnt, color, width, height); internal_draw_string(x, y, string, fnt, color, width, height);
} }
void rect_textured(float x, float y, float w, float h, rgba color, texture &texture, void rect_textured(float x, float y, float w, float h, rgba color,
float tx, float ty, float tw, float th, float angle) texture &texture, float tx, float ty, float tw, float th,
float angle)
{ {
if (!texture.isLoaded()) if (!texture.isLoaded())
texture.load(); texture.load();
if (!texture.canLoad()) if (!texture.canLoad())
return; return;
@ -305,9 +311,10 @@ void rect_textured(float x, float y, float w, float h, rgba color, texture &text
vertices[3].uv = { s1, t0 }; vertices[3].uv = { s1, t0 };
if (detail::record::currentRecord) if (detail::record::currentRecord)
detail::record::currentRecord->store(vertices, 4, indices::rectangle, 6); detail::record::currentRecord->store(vertices, 4, indices::rectangle,
6);
else else
ftgl::vertex_buffer_push_back(detail::program::buffer, vertices, 4, ftgl::vertex_buffer_push_back(detail::program::buffer, vertices, 4,
indices::rectangle, 6); indices::rectangle, 6);
}
} }
} // namespace glez::draw

View File

@ -38,4 +38,4 @@ void font::stringSize(const std::string &string, float *width, float *height)
auto &font = detail::font::get(handle); auto &font = detail::font::get(handle);
font.stringSize(string, width, height); font.stringSize(string, width, height);
} }
} } // namespace glez

View File

@ -45,4 +45,4 @@ void preInit()
detail::font::init(); detail::font::init();
detail::texture::init(); detail::texture::init();
} }
} } // namespace glez