Share retained mesh dispatch bridge
This commit is contained in:
124
src/font.cpp
124
src/font.cpp
@@ -1,6 +1,7 @@
|
||||
#include "pch.h"
|
||||
#include "log.h"
|
||||
#include "font.h"
|
||||
#include "legacy_gl_mesh_dispatch.h"
|
||||
#include "shader.h"
|
||||
#include "asset.h"
|
||||
#include "util.h"
|
||||
@@ -23,75 +24,6 @@ namespace {
|
||||
return static_cast<GLint>(pp::renderer::gl::texture_format_for_channel_count(1U).pixel_format);
|
||||
}
|
||||
|
||||
void gen_buffers_adapter(std::uint32_t count, std::uint32_t* ids) noexcept
|
||||
{
|
||||
glGenBuffers(static_cast<GLsizei>(count), ids);
|
||||
}
|
||||
|
||||
void bind_buffer_adapter(std::uint32_t target, std::uint32_t buffer) noexcept
|
||||
{
|
||||
glBindBuffer(static_cast<GLenum>(target), static_cast<GLuint>(buffer));
|
||||
}
|
||||
|
||||
void buffer_data_adapter(
|
||||
std::uint32_t target,
|
||||
std::intptr_t byte_count,
|
||||
const void* data,
|
||||
std::uint32_t usage) noexcept
|
||||
{
|
||||
glBufferData(static_cast<GLenum>(target), static_cast<GLsizeiptr>(byte_count), data, static_cast<GLenum>(usage));
|
||||
}
|
||||
|
||||
void gen_vertex_arrays_adapter(std::uint32_t count, std::uint32_t* ids) noexcept
|
||||
{
|
||||
glGenVertexArrays(static_cast<GLsizei>(count), ids);
|
||||
}
|
||||
|
||||
void bind_vertex_array_adapter(std::uint32_t vertex_array) noexcept
|
||||
{
|
||||
glBindVertexArray(static_cast<GLuint>(vertex_array));
|
||||
}
|
||||
|
||||
void enable_vertex_attrib_array_adapter(std::uint32_t index) noexcept
|
||||
{
|
||||
glEnableVertexAttribArray(static_cast<GLuint>(index));
|
||||
}
|
||||
|
||||
void vertex_attrib_pointer_adapter(
|
||||
std::uint32_t index,
|
||||
std::int32_t component_count,
|
||||
std::uint32_t component_type,
|
||||
std::uint8_t normalized,
|
||||
std::int32_t stride,
|
||||
const void* offset) noexcept
|
||||
{
|
||||
glVertexAttribPointer(
|
||||
static_cast<GLuint>(index),
|
||||
static_cast<GLint>(component_count),
|
||||
static_cast<GLenum>(component_type),
|
||||
static_cast<GLboolean>(normalized),
|
||||
static_cast<GLsizei>(stride),
|
||||
offset);
|
||||
}
|
||||
|
||||
void draw_elements_adapter(
|
||||
std::uint32_t mode,
|
||||
std::int32_t count,
|
||||
std::uint32_t index_type,
|
||||
const void* index_offset) noexcept
|
||||
{
|
||||
glDrawElements(
|
||||
static_cast<GLenum>(mode),
|
||||
static_cast<GLsizei>(count),
|
||||
static_cast<GLenum>(index_type),
|
||||
index_offset);
|
||||
}
|
||||
|
||||
void draw_arrays_adapter(std::uint32_t mode, std::int32_t first, std::int32_t count) noexcept
|
||||
{
|
||||
glDrawArrays(static_cast<GLenum>(mode), static_cast<GLint>(first), static_cast<GLsizei>(count));
|
||||
}
|
||||
|
||||
void activate_texture_adapter(std::uint32_t texture_unit) noexcept
|
||||
{
|
||||
glActiveTexture(static_cast<GLenum>(texture_unit));
|
||||
@@ -131,36 +63,6 @@ void activate_text_texture_unit(std::uint32_t unit_index)
|
||||
return attributes;
|
||||
}
|
||||
|
||||
[[nodiscard]] pp::renderer::gl::OpenGlMeshCreateDispatch text_mesh_create_dispatch() noexcept
|
||||
{
|
||||
return pp::renderer::gl::OpenGlMeshCreateDispatch {
|
||||
.gen_buffers = gen_buffers_adapter,
|
||||
.bind_buffer = bind_buffer_adapter,
|
||||
.buffer_data = buffer_data_adapter,
|
||||
.gen_vertex_arrays = gen_vertex_arrays_adapter,
|
||||
.bind_vertex_array = bind_vertex_array_adapter,
|
||||
.enable_vertex_attrib_array = enable_vertex_attrib_array_adapter,
|
||||
.vertex_attrib_pointer = vertex_attrib_pointer_adapter,
|
||||
};
|
||||
}
|
||||
|
||||
[[nodiscard]] pp::renderer::gl::OpenGlBufferUploadDispatch text_buffer_upload_dispatch() noexcept
|
||||
{
|
||||
return pp::renderer::gl::OpenGlBufferUploadDispatch {
|
||||
.bind_buffer = bind_buffer_adapter,
|
||||
.buffer_data = buffer_data_adapter,
|
||||
};
|
||||
}
|
||||
|
||||
[[nodiscard]] pp::renderer::gl::OpenGlMeshDrawDispatch text_mesh_draw_dispatch() noexcept
|
||||
{
|
||||
return pp::renderer::gl::OpenGlMeshDrawDispatch {
|
||||
.bind_vertex_array = bind_vertex_array_adapter,
|
||||
.draw_elements = draw_elements_adapter,
|
||||
.draw_arrays = draw_arrays_adapter,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::map<std::string, Font> FontManager::m_fonts;
|
||||
@@ -312,7 +214,7 @@ bool TextMesh::create()
|
||||
{
|
||||
App::I->render_task([this]
|
||||
{
|
||||
const auto mesh = pp::renderer::gl::create_opengl_mesh_objects(
|
||||
const auto mesh = pp::legacy::gl_mesh::create_mesh_objects(
|
||||
pp::renderer::gl::OpenGlMeshUpload {
|
||||
.vertex_data = nullptr,
|
||||
.vertex_byte_count = 0,
|
||||
@@ -322,11 +224,11 @@ bool TextMesh::create()
|
||||
.vertex_array_count = 1U,
|
||||
.attributes = text_mesh_vertex_attributes(),
|
||||
},
|
||||
text_mesh_create_dispatch());
|
||||
if (mesh.ok()) {
|
||||
font_buffers[0] = static_cast<GLuint>(mesh.value().vertex_buffer);
|
||||
font_buffers[1] = static_cast<GLuint>(mesh.value().index_buffer);
|
||||
font_array = static_cast<GLuint>(mesh.value().vertex_arrays[0]);
|
||||
"TextMesh::create");
|
||||
if (mesh.vertex_buffer != 0U) {
|
||||
font_buffers[0] = static_cast<GLuint>(mesh.vertex_buffer);
|
||||
font_buffers[1] = static_cast<GLuint>(mesh.index_buffer);
|
||||
font_array = static_cast<GLuint>(mesh.vertex_arrays[0]);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
@@ -415,7 +317,7 @@ void TextMesh::update(const std::string& text, const std::string& font, int size
|
||||
font_array_count = (int)idx.size();
|
||||
App::I->render_task([&]
|
||||
{
|
||||
(void)pp::renderer::gl::upload_opengl_buffer_data(
|
||||
(void)pp::legacy::gl_mesh::upload_buffer_data(
|
||||
pp::renderer::gl::OpenGlBufferUpload {
|
||||
.target = pp::renderer::gl::element_array_buffer_target(),
|
||||
.buffer_id = font_buffers[1],
|
||||
@@ -423,8 +325,8 @@ void TextMesh::update(const std::string& text, const std::string& font, int size
|
||||
.byte_count = static_cast<std::intptr_t>(idx.size() * sizeof(GLushort)),
|
||||
.usage = pp::renderer::gl::static_draw_buffer_usage(),
|
||||
},
|
||||
text_buffer_upload_dispatch());
|
||||
(void)pp::renderer::gl::upload_opengl_buffer_data(
|
||||
"TextMesh::update indices");
|
||||
(void)pp::legacy::gl_mesh::upload_buffer_data(
|
||||
pp::renderer::gl::OpenGlBufferUpload {
|
||||
.target = pp::renderer::gl::array_buffer_target(),
|
||||
.buffer_id = font_buffers[0],
|
||||
@@ -432,7 +334,7 @@ void TextMesh::update(const std::string& text, const std::string& font, int size
|
||||
.byte_count = static_cast<std::intptr_t>(v.size() * sizeof(glm::vec4)),
|
||||
.usage = pp::renderer::gl::static_draw_buffer_usage(),
|
||||
},
|
||||
text_buffer_upload_dispatch());
|
||||
"TextMesh::update vertices");
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -446,7 +348,7 @@ void TextMesh::draw()
|
||||
f.font_tex.bind();
|
||||
FontManager::m_sampler.bind(0);
|
||||
|
||||
(void)pp::renderer::gl::draw_opengl_mesh(
|
||||
(void)pp::legacy::gl_mesh::draw_mesh(
|
||||
pp::renderer::gl::OpenGlMeshDraw {
|
||||
.vertex_array = font_array,
|
||||
.mode = pp::renderer::gl::primitive_mode_for_fill_count(3U),
|
||||
@@ -455,7 +357,7 @@ void TextMesh::draw()
|
||||
.index_type = pp::renderer::gl::index_type_for_index_size(sizeof(GLushort)),
|
||||
.index_offset = nullptr,
|
||||
},
|
||||
text_mesh_draw_dispatch());
|
||||
"TextMesh::draw");
|
||||
|
||||
f.font_tex.unbind();
|
||||
FontManager::m_sampler.unbind();
|
||||
|
||||
Reference in New Issue
Block a user