diff --git a/include/glez/detail/record.hpp b/include/glez/detail/record.hpp deleted file mode 100644 index 140211f..0000000 --- a/include/glez/detail/record.hpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - Created on 19.06.18. -*/ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -namespace glez::detail::record { - -class RecordedCommands { -public: - struct segment { - std::size_t start { 0 }; - std::size_t size { 0 }; - glez::texture* texture { nullptr }; - glez::font* font { nullptr }; - }; - - RecordedCommands(); - ~RecordedCommands(); - - void reset(); - void store(glez::vertex* vertices, size_t vcount, - uint32_t* indices, size_t icount); - void bindTexture(glez::texture* tx); - void bindFont(glez::font* font); - void render(); - void end(); - -protected: - void cutSegment(); - - ftgl::vertex_buffer_t* vertex_buffer {}; - std::vector segments {}; - segment current {}; -}; - -extern RecordedCommands* currentRecord; -extern bool isReplaying; - -} // namespace glez::detail::record diff --git a/include/glez/record.hpp b/include/glez/record.hpp deleted file mode 100644 index ee9cbde..0000000 --- a/include/glez/record.hpp +++ /dev/null @@ -1,25 +0,0 @@ -/* - Created on 19.06.18. -*/ - -#pragma once - -namespace glez::detail::record { -class RecordedCommands; -} - -namespace glez::record { - -class Record { -public: - Record(); - ~Record(); - - void begin(); - void end(); - void replay(); - - detail::record::RecordedCommands* commands { nullptr }; -}; - -} // namespace glez::record diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 270fa23..523e4e7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,5 +4,4 @@ target_sources(glez PRIVATE "${CMAKE_CURRENT_LIST_DIR}/font.cpp" "${CMAKE_CURRENT_LIST_DIR}/texture.cpp") -add_subdirectory(detail) add_subdirectory(picopng) \ No newline at end of file diff --git a/src/detail/CMakeLists.txt b/src/detail/CMakeLists.txt deleted file mode 100644 index 7103d50..0000000 --- a/src/detail/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -target_sources(glez PRIVATE - "${CMAKE_CURRENT_LIST_DIR}/record.cpp") diff --git a/src/detail/record.cpp b/src/detail/record.cpp deleted file mode 100644 index 2255eb2..0000000 --- a/src/detail/record.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* - Created on 19.06.18. -*/ - -#include -#include -#include -#include -#include - -namespace glez::detail::record { - -void RecordedCommands::render() { - isReplaying = true; - vertex_buffer_render_setup(vertex_buffer, GL_TRIANGLES); - for (const auto& i : segments) { - if (i.texture) { - i.texture->bind(); - } else if (i.font) { - if (i.font->atlas->id == 0) { - glGenTextures(1, &i.font->atlas->id); - } - - glez::bind(i.font->atlas->id); - - 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); - 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)); - } - vertex_buffer_render_finish(vertex_buffer); - isReplaying = false; -} - -void RecordedCommands::store(glez::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"); -} - -RecordedCommands::~RecordedCommands() { - vertex_buffer_delete(vertex_buffer); -} - -void RecordedCommands::reset() { - vertex_buffer_clear(vertex_buffer); - segments.clear(); - memset(¤t, 0, sizeof(current)); -} - -void RecordedCommands::bindTexture(glez::texture* tx) { - if (current.texture != tx) { - cutSegment(); - current.texture = tx; - } -} - -void RecordedCommands::bindFont(glez::font* font) { - if (current.font != font) { - cutSegment(); - current.font = font; - } -} - -void RecordedCommands::cutSegment() { - current.size = vertex_buffer->indices->size - current.start; - if (current.size) - segments.push_back(current); - memset(¤t, 0, sizeof(segment)); - current.start = vertex_buffer->indices->size; -} - -void RecordedCommands::end() { - cutSegment(); -} - -RecordedCommands* currentRecord { nullptr }; -bool isReplaying { false }; - -} // namespace glez::detail::record - -glez::record::Record::Record() { - commands = new glez::detail::record::RecordedCommands {}; -} - -glez::record::Record::~Record() { - delete commands; -} - -void glez::record::Record::begin() { - detail::record::currentRecord = commands; - commands->reset(); -} - -void glez::record::Record::end() { - commands->end(); - detail::record::currentRecord = nullptr; -} - -void glez::record::Record::replay() { - commands->render(); -} diff --git a/src/draw.cpp b/src/draw.cpp index f8f6a37..ca880a5 100644 --- a/src/draw.cpp +++ b/src/draw.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -27,24 +26,20 @@ void internal_draw_string(float x, float y, const std::string& string, float pen_y = y + fnt->height / 1.5f; float size_y = 0; - if (glez::detail::record::currentRecord) { - glez::detail::record::currentRecord->bindFont(&font); - } else { - if (fnt->atlas->id == 0) - glGenTextures(1, &fnt->atlas->id); + if (fnt->atlas->id == 0) + glGenTextures(1, &fnt->atlas->id); - glez::bind(fnt->atlas->id); + glez::bind(fnt->atlas->id); - if (fnt->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); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, fnt->atlas->width, - fnt->atlas->height, 0, GL_RED, GL_UNSIGNED_BYTE, - fnt->atlas->data); - fnt->atlas->dirty = 0; - } + if (fnt->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); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, fnt->atlas->width, + fnt->atlas->height, 0, GL_RED, GL_UNSIGNED_BYTE, + fnt->atlas->data); + fnt->atlas->dirty = 0; } const char* sstring = string.c_str(); @@ -96,10 +91,7 @@ void internal_draw_string(float x, float y, const std::string& string, if (glyph->height > size_y) size_y = glyph->height; - if (glez::detail::record::currentRecord) - glez::detail::record::currentRecord->store(vertices, 4, indices::rectangle, 6); - else - vertex_buffer_push_back(glez::buffer, vertices, 4, indices::rectangle, 6); + vertex_buffer_push_back(glez::buffer, vertices, 4, indices::rectangle, 6); } if (width) @@ -151,12 +143,8 @@ void line(float x, float y, float dx, float dy, rgba color, float thickness) { vertices[3].position = { ex + nx + px, ey + ny + py }; vertices[0].position = { ex + nx - px, ey + ny - py }; - if (detail::record::currentRecord) - detail::record::currentRecord->store(vertices, 4, indices::rectangle, - 6); - else - ftgl::vertex_buffer_push_back(buffer, vertices, 4, - indices::rectangle, 6); + ftgl::vertex_buffer_push_back(buffer, vertices, 4, + indices::rectangle, 6); } void rect(float x, float y, float w, float h, rgba color) { @@ -172,10 +160,7 @@ void rect(float x, float y, float w, float h, rgba color) { vertices[2].position = { x + w, y + h }; vertices[3].position = { x + w, y }; - if (detail::record::currentRecord) - detail::record::currentRecord->store(vertices, 4, indices::rectangle, 6); - else - ftgl::vertex_buffer_push_back(buffer, vertices, 4, indices::rectangle, 6); + ftgl::vertex_buffer_push_back(buffer, vertices, 4, indices::rectangle, 6); } void triangle(float x, float y, float x2, float y2, float x3, float y3, rgba color) { @@ -190,10 +175,7 @@ void triangle(float x, float y, float x2, float y2, float x3, float y3, rgba col vertices[1].position = { x2, y2 }; vertices[2].position = { x3, y3 }; - if (detail::record::currentRecord) - detail::record::currentRecord->store(vertices, 3, indices::rectangle, 3); - else - ftgl::vertex_buffer_push_back(buffer, vertices, 3, indices::rectangle, 3); + ftgl::vertex_buffer_push_back(buffer, vertices, 3, indices::rectangle, 3); } void rect_outline(float x, float y, float w, float h, rgba color, float thickness) { @@ -243,10 +225,7 @@ void rect_textured(float x, float y, float w, float h, rgba color, texture& text // if (!texture.canLoad()) // return; - if (glez::detail::record::currentRecord) - glez::detail::record::currentRecord->bindTexture(&texture); - else - texture.bind(); + texture.bind(); vertex vertices[4]; @@ -283,9 +262,6 @@ void rect_textured(float x, float y, float w, float h, rgba color, texture& text vertices[2].uv = { s1, t1 }; vertices[3].uv = { s1, t0 }; - if (detail::record::currentRecord) - detail::record::currentRecord->store(vertices, 4, indices::rectangle, 6); - else - ftgl::vertex_buffer_push_back(buffer, vertices, 4, indices::rectangle, 6); + ftgl::vertex_buffer_push_back(buffer, vertices, 4, indices::rectangle, 6); } } // namespace glez::draw diff --git a/src/glez.cpp b/src/glez.cpp index 728c947..20916af 100644 --- a/src/glez.cpp +++ b/src/glez.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -169,10 +168,8 @@ void end() { void bind(GLuint texture) { if (current_texture != texture) { - if (!detail::record::isReplaying) { - vertex_buffer_render(buffer, GL_TRIANGLES); - ftgl::vertex_buffer_clear(buffer); - } + vertex_buffer_render(buffer, GL_TRIANGLES); + ftgl::vertex_buffer_clear(buffer); current_texture = texture; glBindTexture(GL_TEXTURE_2D, texture); }