Removed command recorder

This commit is contained in:
Rebekah 2022-04-05 14:12:17 -04:00
parent ee8da4db09
commit 2a0d014356
Signed by: oneechanhax
GPG Key ID: 183EB7902964DAE5
7 changed files with 21 additions and 236 deletions

View File

@ -1,48 +0,0 @@
/*
Created on 19.06.18.
*/
#pragma once
#include <cstdint>
#include <freetype-gl.h>
#include <glez/font.hpp>
#include <glez/glez.hpp>
#include <glez/texture.hpp>
#include <vector>
#include <vertex-buffer.h>
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<segment> segments {};
segment current {};
};
extern RecordedCommands* currentRecord;
extern bool isReplaying;
} // namespace glez::detail::record

View File

@ -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

View File

@ -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)

View File

@ -1,2 +0,0 @@
target_sources(glez PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/record.cpp")

View File

@ -1,112 +0,0 @@
/*
Created on 19.06.18.
*/
#include <cstddef>
#include <cstring>
#include <glez/detail/record.hpp>
#include <glez/glez.hpp>
#include <glez/record.hpp>
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(&current, 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(&current, 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();
}

View File

@ -6,7 +6,6 @@
#include <cassert>
#include <cmath>
#include <cstring>
#include <glez/detail/record.hpp>
#include <glez/draw.hpp>
#include <glez/font.hpp>
#include <glez/glez.hpp>
@ -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

View File

@ -7,7 +7,6 @@
#include <cstdio>
#include <cstring>
#include <freetype-gl.h>
#include <glez/detail/record.hpp>
#include <glez/font.hpp>
#include <glez/glez.hpp>
#include <glm/glm.hpp>
@ -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);
}