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'
AllowShortLoopsOnASingleLine: 'false'
BreakBeforeBraces: Allman
ColumnLimit: 0
ConstructorInitializerAllOnOneLineOrOnePerLine: 'false'
Cpp11BracedListStyle: 'false'
IndentCaseLabels: 'false'
@ -31,4 +32,5 @@ Standard: Auto
TabWidth: '4'
UseTab: Never
...

View File

@ -35,5 +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);
}
}
} // namespace color
} // namespace glez

View File

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

View File

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

View File

@ -32,11 +32,13 @@ public:
~RecordedCommands();
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 bindFont(ftgl::texture_font_t *font);
void render();
void end();
protected:
void cutSegment();
@ -48,4 +50,4 @@ protected:
extern RecordedCommands *currentRecord;
extern bool isReplaying;
}
} // namespace glez::detail::record

View File

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

View File

@ -33,4 +33,4 @@ void shutdown();
unsigned create();
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 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_textured(float x, float y, float w, float h, rgba color, 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 rect_outline(float x, float y, float w, float h, rgba color,
float thickness);
void rect_textured(float x, float y, float w, float h, rgba color,
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,
float *width, float *height);
void outlined_string(float x, float y, const std::string &string, font &font,
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() };
};
}
} // namespace glez

View File

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

View File

@ -1,3 +1,5 @@
#pragma once
#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 };
};
}
} // namespace glez::record

View File

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

View File

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

View File

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

View File

@ -14,7 +14,7 @@ void RecordedCommands::render()
{
isReplaying = true;
vertex_buffer_render_setup(vertex_buffer, GL_TRIANGLES);
for (const auto& i: segments)
for (const auto &i : segments)
{
if (i.texture)
{
@ -31,32 +31,37 @@ void RecordedCommands::render()
if (i.font->atlas->dirty)
{
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_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
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_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, i.font->atlas->width,
i.font->atlas->height, 0, GL_RED, GL_UNSIGNED_BYTE,
i.font->atlas->data);
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);
isReplaying = false;
}
void
RecordedCommands::store(glez::detail::render::vertex *vertices, size_t vcount,
uint32_t *indices, size_t icount)
void RecordedCommands::store(glez::detail::render::vertex *vertices,
size_t vcount, uint32_t *indices, size_t icount)
{
vertex_buffer_push_back(vertex_buffer, vertices, vcount, indices, icount);
}
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()
@ -106,7 +111,7 @@ void RecordedCommands::end()
RecordedCommands *currentRecord{ nullptr };
bool isReplaying{ false };
}
} // namespace glez::detail::record
glez::record::Record::Record()
{

View File

@ -68,4 +68,4 @@ void bind(GLuint 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);
return false;
}
init = true;
bound = false;
id = 0;
init = true;
bound = false;
id = 0;
return true;
}

View File

@ -110,10 +110,11 @@ void internal_draw_string(float x, float y, const std::string &string,
size_y = glyph->height;
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
vertex_buffer_push_back(glez::detail::program::buffer, vertices, 4,
indices::rectangle, 6);
indices::rectangle, 6);
}
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 };
if (detail::record::currentRecord)
detail::record::currentRecord->store(vertices, 4, indices::rectangle, 6);
detail::record::currentRecord->store(vertices, 4, indices::rectangle,
6);
else
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)
@ -191,13 +193,15 @@ void rect(float x, float y, float w, float h, rgba color)
vertices[3].position = { x + w, y };
if (detail::record::currentRecord)
detail::record::currentRecord->store(vertices, 4, indices::rectangle, 6);
detail::record::currentRecord->store(vertices, 4, indices::rectangle,
6);
else
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, 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);
}
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 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);
}
void rect_textured(float x, float y, float w, float h, rgba color, texture &texture,
float tx, float ty, float tw, float th, float angle)
void rect_textured(float x, float y, float w, float h, rgba color,
texture &texture, float tx, float ty, float tw, float th,
float angle)
{
if (!texture.isLoaded())
texture.load();
if (!texture.canLoad())
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 };
if (detail::record::currentRecord)
detail::record::currentRecord->store(vertices, 4, indices::rectangle, 6);
detail::record::currentRecord->store(vertices, 4, indices::rectangle,
6);
else
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);
font.stringSize(string, width, height);
}
}
} // namespace glez

View File

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