Share retained mesh dispatch bridge

This commit is contained in:
2026-06-05 14:51:40 +02:00
parent d719a5a5e5
commit 96ff1c41e2
7 changed files with 298 additions and 325 deletions

View File

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

View File

@@ -0,0 +1,182 @@
#pragma once
#include <array>
#include <cstdint>
#include "log.h"
#include "renderer_gl/opengl_capabilities.h"
namespace pp::legacy::gl_mesh {
inline void gen_opengl_buffers(std::uint32_t count, std::uint32_t* ids) noexcept
{
glGenBuffers(static_cast<GLsizei>(count), reinterpret_cast<GLuint*>(ids));
}
inline void delete_opengl_buffers(std::uint32_t count, const std::uint32_t* ids) noexcept
{
glDeleteBuffers(static_cast<GLsizei>(count), reinterpret_cast<const GLuint*>(ids));
}
inline void bind_opengl_buffer(std::uint32_t target, std::uint32_t buffer) noexcept
{
glBindBuffer(static_cast<GLenum>(target), static_cast<GLuint>(buffer));
}
inline void set_opengl_buffer_data(
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));
}
inline void gen_opengl_vertex_arrays(std::uint32_t count, std::uint32_t* ids) noexcept
{
glGenVertexArrays(static_cast<GLsizei>(count), reinterpret_cast<GLuint*>(ids));
}
inline void delete_opengl_vertex_arrays(std::uint32_t count, const std::uint32_t* ids) noexcept
{
glDeleteVertexArrays(static_cast<GLsizei>(count), reinterpret_cast<const GLuint*>(ids));
}
inline void bind_opengl_vertex_array(std::uint32_t vertex_array) noexcept
{
glBindVertexArray(static_cast<GLuint>(vertex_array));
}
inline void enable_opengl_vertex_attrib_array(std::uint32_t index) noexcept
{
glEnableVertexAttribArray(static_cast<GLuint>(index));
}
inline void set_opengl_vertex_attrib_pointer(
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);
}
inline void draw_opengl_elements(
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);
}
inline void draw_opengl_arrays(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));
}
inline pp::renderer::gl::OpenGlMeshCreateDispatch mesh_create_dispatch() noexcept
{
return pp::renderer::gl::OpenGlMeshCreateDispatch {
.gen_buffers = gen_opengl_buffers,
.bind_buffer = bind_opengl_buffer,
.buffer_data = set_opengl_buffer_data,
.gen_vertex_arrays = gen_opengl_vertex_arrays,
.bind_vertex_array = bind_opengl_vertex_array,
.enable_vertex_attrib_array = enable_opengl_vertex_attrib_array,
.vertex_attrib_pointer = set_opengl_vertex_attrib_pointer,
};
}
inline pp::renderer::gl::OpenGlBufferUploadDispatch buffer_upload_dispatch() noexcept
{
return pp::renderer::gl::OpenGlBufferUploadDispatch {
.bind_buffer = bind_opengl_buffer,
.buffer_data = set_opengl_buffer_data,
};
}
inline pp::renderer::gl::OpenGlMeshDrawDispatch mesh_draw_dispatch() noexcept
{
return pp::renderer::gl::OpenGlMeshDrawDispatch {
.bind_vertex_array = bind_opengl_vertex_array,
.draw_elements = draw_opengl_elements,
.draw_arrays = draw_opengl_arrays,
};
}
inline pp::renderer::gl::OpenGlMeshDeleteDispatch mesh_delete_dispatch() noexcept
{
return pp::renderer::gl::OpenGlMeshDeleteDispatch {
.delete_buffers = delete_opengl_buffers,
.delete_vertex_arrays = delete_opengl_vertex_arrays,
};
}
inline pp::renderer::gl::OpenGlMeshObjects create_mesh_objects(
pp::renderer::gl::OpenGlMeshUpload upload,
const char* context)
{
const auto mesh = pp::renderer::gl::create_opengl_mesh_objects(upload, mesh_create_dispatch());
if (!mesh.ok()) {
LOG("%s failed because: %s", context, mesh.status().message);
return {};
}
return mesh.value();
}
inline bool upload_buffer_data(pp::renderer::gl::OpenGlBufferUpload upload, const char* context)
{
const auto status = pp::renderer::gl::upload_opengl_buffer_data(upload, buffer_upload_dispatch());
if (!status.ok()) {
LOG("%s failed because: %s", context, status.message);
return false;
}
return true;
}
inline bool draw_mesh(pp::renderer::gl::OpenGlMeshDraw draw, const char* context)
{
const auto status = pp::renderer::gl::draw_opengl_mesh(draw, mesh_draw_dispatch());
if (!status.ok()) {
LOG("%s failed because: %s", context, status.message);
return false;
}
return true;
}
inline bool delete_mesh_objects(
std::array<std::uint32_t, 2> buffers,
std::array<std::uint32_t, 2> vertex_arrays,
const char* context)
{
const auto status = pp::renderer::gl::delete_opengl_mesh_objects(
pp::renderer::gl::OpenGlMeshDelete {
.buffers = buffers,
.vertex_arrays = vertex_arrays,
},
mesh_delete_dispatch());
if (!status.ok()) {
LOG("%s failed because: %s", context, status.message);
return false;
}
return true;
}
} // namespace pp::legacy::gl_mesh

View File

@@ -1,4 +1,5 @@
#include "pch.h"
#include "legacy_gl_mesh_dispatch.h"
#include "legacy_ui_gl_dispatch.h"
#include "node_colorwheel.h"
#include "renderer_gl/opengl_capabilities.h"
@@ -6,6 +7,10 @@
#include "log.h"
#include "app.h"
#include <array>
#include <cstddef>
#include <cstdint>
Node* NodeColorWheel::clone_instantiate() const
{
return new NodeColorWheel;
@@ -47,45 +52,47 @@ void NodeColorWheel::loaded()
App::I->render_task([&]
{
const auto buffer_target = pp::renderer::gl::array_buffer_target();
const auto upload_usage = pp::renderer::gl::static_draw_buffer_usage();
const auto attribute_type = pp::renderer::gl::vertex_attribute_float_component_type();
const auto attribute_normalized =
static_cast<GLboolean>(pp::renderer::gl::vertex_attribute_not_normalized());
static_cast<std::uint8_t>(pp::renderer::gl::vertex_attribute_not_normalized());
const std::array<pp::renderer::gl::OpenGlVertexAttribute, 3> attributes {
pp::renderer::gl::OpenGlVertexAttribute {
.index = 0U,
.component_count = 4,
.component_type = attribute_type,
.normalized = attribute_normalized,
.stride = static_cast<std::int32_t>(sizeof(vertex_t)),
.offset = 0U,
},
pp::renderer::gl::OpenGlVertexAttribute {
.index = 1U,
.component_count = 2,
.component_type = attribute_type,
.normalized = attribute_normalized,
.stride = static_cast<std::int32_t>(sizeof(vertex_t)),
.offset = static_cast<std::uintptr_t>(offsetof(vertex_t, uvs)),
},
pp::renderer::gl::OpenGlVertexAttribute {
.index = 2U,
.component_count = 4,
.component_type = attribute_type,
.normalized = attribute_normalized,
.stride = static_cast<std::int32_t>(sizeof(vertex_t)),
.offset = static_cast<std::uintptr_t>(offsetof(vertex_t, col)),
},
};
glGenBuffers(1, &buffers);
glBindBuffer(buffer_target, buffers);
glBufferData(buffer_target, vertices.size() * sizeof(vertex_t), vertices.data(), upload_usage);
glBindBuffer(buffer_target, 0);
glGenVertexArrays(1, &arrays);
glBindVertexArray(arrays);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glBindBuffer(buffer_target, buffers);
glVertexAttribPointer(
0,
4,
attribute_type,
attribute_normalized,
sizeof(vertex_t),
(GLvoid*)0);
glVertexAttribPointer(
1,
2,
attribute_type,
attribute_normalized,
sizeof(vertex_t),
(GLvoid*)offsetof(vertex_t, uvs));
glVertexAttribPointer(
2,
4,
attribute_type,
attribute_normalized,
sizeof(vertex_t),
(GLvoid*)offsetof(vertex_t, col));
glBindVertexArray(0);
const auto mesh = pp::legacy::gl_mesh::create_mesh_objects(
pp::renderer::gl::OpenGlMeshUpload {
.vertex_data = vertices.data(),
.vertex_byte_count = static_cast<std::intptr_t>(vertices.size() * sizeof(vertex_t)),
.indexed = false,
.vertex_array_count = 1U,
.attributes = attributes,
},
"NodeColorWheel::loaded");
buffers = static_cast<GLuint>(mesh.vertex_buffer);
arrays = static_cast<GLuint>(mesh.vertex_arrays[0]);
});
}
@@ -97,13 +104,6 @@ void NodeColorWheel::draw()
ShaderManager::u_int(kShaderUniform::Direction, 0); // set horizontal
m_circle.draw_fill();
// ShaderManager::use(kShader::ColorTri);
// ShaderManager::u_mat4(kShaderUniform::MVP, m_mvp);
// ShaderManager::u_vec4(kShaderUniform::Col, glm::vec4(m_hsv, 0.f));
// glBindVertexArray(arrays);
// glDrawArrays(pp::renderer::gl::primitive_mode_for_fill_count(3U), 0, 3);
// glBindVertexArray(0);
ShaderManager::use(kShader::Color);
ShaderManager::u_mat4(kShaderUniform::MVP, m_mvp * glm::eulerAngleZ(glm::radians(-360.f * m_hsv.x)) * glm::translate(glm::vec3(.45f,0.f,0.f)));
ShaderManager::u_vec4(kShaderUniform::Col, {convert_hsv2rgb({glm::fract(m_hsv.x + 0.5f), 1.f, 1.f}), 1.f});

View File

@@ -1,5 +1,6 @@
#include "pch.h"
#include "log.h"
#include "legacy_gl_mesh_dispatch.h"
#include "shape.h"
#include "app.h"
#include "renderer_gl/opengl_capabilities.h"
@@ -10,85 +11,6 @@
namespace {
void gen_buffers_adapter(std::uint32_t count, std::uint32_t* ids) noexcept
{
glGenBuffers(static_cast<GLsizei>(count), ids);
}
void delete_buffers_adapter(std::uint32_t count, const std::uint32_t* ids) noexcept
{
glDeleteBuffers(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 delete_vertex_arrays_adapter(std::uint32_t count, const std::uint32_t* ids) noexcept
{
glDeleteVertexArrays(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));
}
[[nodiscard]] std::span<const pp::renderer::gl::OpenGlVertexAttribute> shape_vertex_attributes() noexcept
{
static const std::array<pp::renderer::gl::OpenGlVertexAttribute, 4> attributes {
@@ -128,44 +50,6 @@ void draw_arrays_adapter(std::uint32_t mode, std::int32_t first, std::int32_t co
return attributes;
}
[[nodiscard]] pp::renderer::gl::OpenGlMeshCreateDispatch 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 buffer_upload_dispatch() noexcept
{
return pp::renderer::gl::OpenGlBufferUploadDispatch {
.bind_buffer = bind_buffer_adapter,
.buffer_data = buffer_data_adapter,
};
}
[[nodiscard]] pp::renderer::gl::OpenGlMeshDrawDispatch 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,
};
}
[[nodiscard]] pp::renderer::gl::OpenGlMeshDeleteDispatch mesh_delete_dispatch() noexcept
{
return pp::renderer::gl::OpenGlMeshDeleteDispatch {
.delete_buffers = delete_buffers_adapter,
.delete_vertex_arrays = delete_vertex_arrays_adapter,
};
}
}
bool Shape::create_buffers(GLushort * idx, GLvoid * vertices, int isize, int vsize)
@@ -191,7 +75,7 @@ bool Shape::create_buffers_imp(GLvoid* idx, GLvoid* vertices, int isize, int vsi
{
destroy();
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 = vertices,
.vertex_byte_count = vsize,
@@ -200,15 +84,15 @@ bool Shape::create_buffers_imp(GLvoid* idx, GLvoid* vertices, int isize, int vsi
.indexed = true,
.attributes = shape_vertex_attributes(),
},
mesh_create_dispatch());
if (!mesh.ok()) {
"Shape::create_buffers indexed");
if (mesh.vertex_buffer == 0U) {
ret = false;
return;
}
buffers[0] = static_cast<GLuint>(mesh.value().vertex_buffer);
buffers[1] = static_cast<GLuint>(mesh.value().index_buffer);
arrays[0] = static_cast<GLuint>(mesh.value().vertex_arrays[0]);
arrays[1] = static_cast<GLuint>(mesh.value().vertex_arrays[1]);
buffers[0] = static_cast<GLuint>(mesh.vertex_buffer);
buffers[1] = static_cast<GLuint>(mesh.index_buffer);
arrays[0] = static_cast<GLuint>(mesh.vertex_arrays[0]);
arrays[1] = static_cast<GLuint>(mesh.vertex_arrays[1]);
});
return ret;
}
@@ -221,22 +105,22 @@ bool Shape::create_buffers(GLvoid* vertices, int vsize)
{
destroy();
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 = vertices,
.vertex_byte_count = vsize,
.indexed = false,
.attributes = shape_vertex_attributes(),
},
mesh_create_dispatch());
if (!mesh.ok()) {
"Shape::create_buffers");
if (mesh.vertex_buffer == 0U) {
ret = false;
return;
}
buffers[0] = static_cast<GLuint>(mesh.value().vertex_buffer);
buffers[1] = static_cast<GLuint>(mesh.value().index_buffer);
arrays[0] = static_cast<GLuint>(mesh.value().vertex_arrays[0]);
arrays[1] = static_cast<GLuint>(mesh.value().vertex_arrays[1]);
buffers[0] = static_cast<GLuint>(mesh.vertex_buffer);
buffers[1] = static_cast<GLuint>(mesh.index_buffer);
arrays[0] = static_cast<GLuint>(mesh.vertex_arrays[0]);
arrays[1] = static_cast<GLuint>(mesh.vertex_arrays[1]);
});
return ret;
}
@@ -247,7 +131,7 @@ void Shape::draw_fill() const
const auto type = static_cast<GLenum>(pp::renderer::gl::primitive_mode_for_fill_count(count[0]));
App::I->render_task([=]
{
(void)pp::renderer::gl::draw_opengl_mesh(
(void)pp::legacy::gl_mesh::draw_mesh(
pp::renderer::gl::OpenGlMeshDraw {
.vertex_array = arrays[0],
.mode = type,
@@ -256,7 +140,7 @@ void Shape::draw_fill() const
.index_type = index_type,
.index_offset = ioff[0],
},
mesh_draw_dispatch());
"Shape::draw_fill");
});
}
void Shape::draw_stroke() const
@@ -266,7 +150,7 @@ void Shape::draw_stroke() const
const auto type = static_cast<GLenum>(pp::renderer::gl::primitive_mode_for_stroke_count(count[1]));
App::I->render_task([=]
{
(void)pp::renderer::gl::draw_opengl_mesh(
(void)pp::legacy::gl_mesh::draw_mesh(
pp::renderer::gl::OpenGlMeshDraw {
.vertex_array = arrays[1],
.mode = type,
@@ -275,7 +159,7 @@ void Shape::draw_stroke() const
.index_type = index_type,
.index_offset = ioff[1],
},
mesh_draw_dispatch());
"Shape::draw_stroke");
});
}
@@ -283,12 +167,7 @@ void Shape::destroy()
{
if (App::I) App::I->render_task_async([b1=buffers[0],b2=buffers[1],a1=arrays[0],a2=arrays[1]]
{
(void)pp::renderer::gl::delete_opengl_mesh_objects(
pp::renderer::gl::OpenGlMeshDelete {
.buffers = { b1, b2 },
.vertex_arrays = { a1, a2 },
},
mesh_delete_dispatch());
(void)pp::legacy::gl_mesh::delete_mesh_objects({ b1, b2 }, { a1, a2 }, "Shape::destroy");
});
buffers[0] = buffers[1] = 0;
arrays[0] = arrays[1] = 0;
@@ -574,7 +453,7 @@ void Plane::update_vertices(const glm::vec4* data, const glm::vec2* uvs, const g
App::I->render_task([this]
{
(void)pp::renderer::gl::upload_opengl_buffer_data(
(void)pp::legacy::gl_mesh::upload_buffer_data(
pp::renderer::gl::OpenGlBufferUpload {
.target = pp::renderer::gl::array_buffer_target(),
.buffer_id = buffers[0],
@@ -582,7 +461,7 @@ void Plane::update_vertices(const glm::vec4* data, const glm::vec2* uvs, const g
.byte_count = static_cast<std::intptr_t>(sizeof(vertices)),
.usage = pp::renderer::gl::static_draw_buffer_usage(),
},
buffer_upload_dispatch());
"Plane::update_vertices vertices");
static GLushort idx[6 + 8]{
0, 1, 2,
0, 2, 3,
@@ -591,7 +470,7 @@ void Plane::update_vertices(const glm::vec4* data, const glm::vec2* uvs, const g
2, 3,
3, 0,
};
(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 = buffers[1],
@@ -599,7 +478,7 @@ void Plane::update_vertices(const glm::vec4* data, const glm::vec2* uvs, const g
.byte_count = static_cast<std::intptr_t>(sizeof(idx)),
.usage = pp::renderer::gl::static_draw_buffer_usage(),
},
buffer_upload_dispatch());
"Plane::update_vertices indices");
});
}
void Circle::create_impl(float radius, int div, GLushort* idx, vertex_t* vertices)
@@ -858,7 +737,7 @@ void LineSegment::update_vertices(const glm::vec4 data[2])
static vertex_t vertices[2];
vertices[0] = { data[0], { 0, 0 } }; // A
vertices[1] = { data[1], { 0, 1 } }; // B
(void)pp::renderer::gl::upload_opengl_buffer_data(
(void)pp::legacy::gl_mesh::upload_buffer_data(
pp::renderer::gl::OpenGlBufferUpload {
.target = pp::renderer::gl::array_buffer_target(),
.buffer_id = buffers[0],
@@ -866,7 +745,7 @@ void LineSegment::update_vertices(const glm::vec4 data[2])
.byte_count = static_cast<std::intptr_t>(sizeof(vertices)),
.usage = pp::renderer::gl::static_draw_buffer_usage(),
},
buffer_upload_dispatch());
"LineSegment::update_vertices");
});
}
void DynamicShape::update_vertices(vertex_t* vertices, int vcount)
@@ -875,7 +754,7 @@ void DynamicShape::update_vertices(vertex_t* vertices, int vcount)
{
count[0] = vcount;
count[1] = vcount;
(void)pp::renderer::gl::upload_opengl_buffer_data(
(void)pp::legacy::gl_mesh::upload_buffer_data(
pp::renderer::gl::OpenGlBufferUpload {
.target = pp::renderer::gl::array_buffer_target(),
.buffer_id = buffers[0],
@@ -883,6 +762,6 @@ void DynamicShape::update_vertices(vertex_t* vertices, int vcount)
.byte_count = static_cast<std::intptr_t>(sizeof(vertex_t) * vcount),
.usage = pp::renderer::gl::static_draw_buffer_usage(),
},
buffer_upload_dispatch());
"DynamicShape::update_vertices");
});
}