wip records
This commit is contained in:
parent
3a37c925eb
commit
a987fc42a6
@ -3,6 +3,7 @@ target_sources(glez PRIVATE
|
||||
"${CMAKE_CURRENT_LIST_DIR}/glez.hpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/font.hpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/texture.hpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/draw.hpp")
|
||||
"${CMAKE_CURRENT_LIST_DIR}/draw.hpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/record.hpp")
|
||||
|
||||
add_subdirectory(detail)
|
@ -2,4 +2,5 @@ target_sources(glez PRIVATE
|
||||
"${CMAKE_CURRENT_LIST_DIR}/font.hpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/texture.hpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/render.hpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/program.hpp")
|
||||
"${CMAKE_CURRENT_LIST_DIR}/program.hpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/record.hpp")
|
43
include/glez/detail/record.hpp
Normal file
43
include/glez/detail/record.hpp
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
Created on 19.06.18.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include "render.hpp"
|
||||
#include "../../../ftgl/vertex-buffer.h"
|
||||
|
||||
namespace glez::detail::record
|
||||
{
|
||||
|
||||
class RecordedCommands
|
||||
{
|
||||
public:
|
||||
struct segment
|
||||
{
|
||||
std::size_t start{};
|
||||
std::size_t size{};
|
||||
uint32_t texture{};
|
||||
};
|
||||
|
||||
RecordedCommands();
|
||||
~RecordedCommands();
|
||||
|
||||
void reset();
|
||||
void store(glez::detail::render::vertex *vertices, size_t vcount, uint32_t *indices, size_t icount);
|
||||
void bind(uint32_t texture);
|
||||
void render();
|
||||
protected:
|
||||
void drawSegment(std::size_t index);
|
||||
|
||||
uint32_t currentTexture{ 0 };
|
||||
size_t nextStart{ 0 };
|
||||
ftgl::vertex_buffer_t *vertex_buffer{};
|
||||
std::vector<segment> segments{};
|
||||
};
|
||||
|
||||
extern RecordedCommands *currentRecord;
|
||||
|
||||
}
|
@ -15,5 +15,8 @@ void shutdown();
|
||||
void resize(int width, int height);
|
||||
|
||||
void begin();
|
||||
void recordBegin();
|
||||
void recordEnd();
|
||||
void recordReplay();
|
||||
void end();
|
||||
};
|
24
include/glez/record.hpp
Normal file
24
include/glez/record.hpp
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
Created on 19.06.18.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace glez::detail::record
|
||||
{
|
||||
class RecordedCommands;
|
||||
}
|
||||
|
||||
namespace glez::record
|
||||
{
|
||||
|
||||
class Record
|
||||
{
|
||||
public:
|
||||
Record();
|
||||
~Record();
|
||||
|
||||
detail::record::RecordedCommands *commands{ nullptr };
|
||||
};
|
||||
|
||||
}
|
@ -2,4 +2,5 @@ target_sources(glez PRIVATE
|
||||
"${CMAKE_CURRENT_LIST_DIR}/program.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/render.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/texture.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/font.cpp")
|
||||
"${CMAKE_CURRENT_LIST_DIR}/font.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/record.cpp")
|
67
src/detail/record.cpp
Normal file
67
src/detail/record.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
Created on 19.06.18.
|
||||
*/
|
||||
|
||||
#include <cstddef>
|
||||
#include <glez/detail/record.hpp>
|
||||
#include <glez/record.hpp>
|
||||
|
||||
namespace glez::detail::record
|
||||
{
|
||||
|
||||
void RecordedCommands::drawSegment(std::size_t index)
|
||||
{
|
||||
glDrawElements(GL_TRIANGLES, segments[index].size, GL_UNSIGNED_INT, (void *)(segments[index].start * sizeof(glez::detail::render::vertex)));
|
||||
}
|
||||
|
||||
void RecordedCommands::render()
|
||||
{
|
||||
vertex_buffer_render_setup(vertex_buffer, GL_TRIANGLES);
|
||||
vertex_buffer_render_finish(vertex_buffer);
|
||||
}
|
||||
|
||||
void RecordedCommands::bind(uint32_t texture)
|
||||
{
|
||||
if (currentTexture != texture)
|
||||
{
|
||||
segments.push_back(segment{ nextStart, vertex_buffer->indices->size - nextStart, texture });
|
||||
currentTexture = texture;
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
RecordedCommands::~RecordedCommands()
|
||||
{
|
||||
vertex_buffer_delete(vertex_buffer);
|
||||
}
|
||||
|
||||
void RecordedCommands::reset()
|
||||
{
|
||||
vertex_buffer_clear(vertex_buffer);
|
||||
segments.clear();
|
||||
}
|
||||
|
||||
RecordedCommands *currentRecord{ nullptr };
|
||||
|
||||
}
|
||||
|
||||
glez::record::Record::Record()
|
||||
{
|
||||
commands = new glez::detail::record::RecordedCommands{};
|
||||
}
|
||||
|
||||
glez::record::Record::~Record()
|
||||
{
|
||||
delete commands;
|
||||
}
|
21
src/draw.cpp
21
src/draw.cpp
@ -12,6 +12,7 @@
|
||||
#include <cstring>
|
||||
#include <glez/detail/texture.hpp>
|
||||
#include <cmath>
|
||||
#include <glez/detail/record.hpp>
|
||||
|
||||
namespace indices
|
||||
{
|
||||
@ -95,7 +96,10 @@ void internal_draw_string(float x, float y, const std::string &string,
|
||||
if (glyph->height > size_y)
|
||||
size_y = glyph->height;
|
||||
|
||||
vertex_buffer_push_back(glez::detail::program::buffer, vertices, 4,
|
||||
if (glez::detail::record::currentRecord)
|
||||
glez::detail::record::currentRecord->store(vertices, 4, indices::rectangle, 6);
|
||||
else
|
||||
vertex_buffer_push_back(glez::detail::program::buffer, vertices, 4,
|
||||
indices::rectangle, 6);
|
||||
}
|
||||
|
||||
@ -151,7 +155,10 @@ 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 };
|
||||
|
||||
ftgl::vertex_buffer_push_back(detail::program::buffer, vertices, 4,
|
||||
if (detail::record::currentRecord)
|
||||
detail::record::currentRecord->store(vertices, 4, indices::rectangle, 6);
|
||||
else
|
||||
ftgl::vertex_buffer_push_back(detail::program::buffer, vertices, 4,
|
||||
indices::rectangle, 6);
|
||||
}
|
||||
|
||||
@ -170,7 +177,10 @@ 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 };
|
||||
|
||||
ftgl::vertex_buffer_push_back(detail::program::buffer, vertices, 4,
|
||||
if (detail::record::currentRecord)
|
||||
detail::record::currentRecord->store(vertices, 4, indices::rectangle, 6);
|
||||
else
|
||||
ftgl::vertex_buffer_push_back(detail::program::buffer, vertices, 4,
|
||||
indices::rectangle, 6);
|
||||
}
|
||||
|
||||
@ -275,7 +285,10 @@ 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 };
|
||||
|
||||
ftgl::vertex_buffer_push_back(detail::program::buffer, vertices, 4,
|
||||
if (detail::record::currentRecord)
|
||||
detail::record::currentRecord->store(vertices, 4, indices::rectangle, 6);
|
||||
else
|
||||
ftgl::vertex_buffer_push_back(detail::program::buffer, vertices, 4,
|
||||
indices::rectangle, 6);
|
||||
}
|
||||
}
|
17
src/glez.cpp
17
src/glez.cpp
@ -7,6 +7,8 @@
|
||||
#include <glez/detail/program.hpp>
|
||||
#include <glez/detail/render.hpp>
|
||||
#include <glez/detail/texture.hpp>
|
||||
#include <glez/record.hpp>
|
||||
#include <glez/detail/record.hpp>
|
||||
|
||||
namespace glez
|
||||
{
|
||||
@ -43,4 +45,19 @@ void preInit()
|
||||
{
|
||||
detail::font::init();
|
||||
}
|
||||
|
||||
void glez::recordBegin(record::Record& rc)
|
||||
{
|
||||
detail::record::currentRecord = rc.commands;
|
||||
}
|
||||
|
||||
void glez::recordEnd()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void glez::recordReplay()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user