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

@@ -465,10 +465,11 @@ powershell -ExecutionPolicy Bypass -File scripts\automation\apple-remote-build.p
validates renderer API primitive-topology to OpenGL draw-mode mapping, Shape
index-type, fill/stroke primitive-mode, buffer target, static upload usage,
and vertex attribute component/normalization mapping used by
the legacy mesh draw path. Legacy `Shape` mesh buffer/VAO creation, zero-byte
dynamic-buffer creation, dynamic vertex/index uploads, fill/stroke draw
calls, and buffer/VAO deletion now consume tested dispatch contracts here,
plus the PanoPainter cube-face to OpenGL
the legacy mesh draw path. Retained `Shape`, `TextMesh`, and
`NodeColorWheel` mesh buffer/VAO creation, zero-byte dynamic-buffer creation,
dynamic vertex/index uploads, fill/stroke/text draw calls, and buffer/VAO
deletion now consume tested dispatch contracts here through
`legacy_gl_mesh_dispatch`, plus the PanoPainter cube-face to OpenGL
texture-target mapping used by `TextureCube`.
It also owns and validates sampler wrap S/T/R, min/mag filter, and desktop
border-color parameter mapping used by legacy `Sampler`, plus renderer API
@@ -511,7 +512,7 @@ powershell -ExecutionPolicy Bypass -File scripts\automation\apple-remote-build.p
texture unit selection also consume the backend mapping. Text mesh
buffer/VAO creation, deferred index/vertex uploads, indexed draw calls, and
draw-time texture-unit activation now consume tested `pp_renderer_gl`
dispatch contracts too. Canvas undo/redo dirty-region texture updates and
dispatch contracts through the shared retained mesh bridge too. Canvas undo/redo dirty-region texture updates and
readbacks also consume the backend-owned 2D texture target, RGBA pixel
format, and unsigned-byte component mapping; canvas stroke commit, thumbnail,
and object-draw history paths now consume tested capability-state query
@@ -523,9 +524,8 @@ powershell -ExecutionPolicy Bypass -File scripts\automation\apple-remote-build.p
`NodeImage` drawing and remote-image texture creation also consume
backend-owned mipmapped sampler filters, blend-state tokens, and RGBA8/RGBA
texture format mapping.
`NodeColorWheel` triangle-buffer setup and draw-state handling also consume
backend-owned array-buffer, static-upload, vertex-attribute, primitive-mode,
and blend-state tokens.
`NodeColorWheel` triangle-buffer setup now shares the retained mesh bridge,
and its draw-state handling also consumes backend-owned blend-state tokens.
Simple UI text, text-input, border, scroll, and animation timeline draw
paths also consume backend-owned blend-state tokens.
Canvas layer cube/equirect generation, clear, restore, and snapshot paths

File diff suppressed because one or more lines are too long

View File

@@ -1176,10 +1176,11 @@ there. `RTT` no longer spells GL enum names directly.
Renderer API primitive-topology to OpenGL draw-mode mapping, mesh index-type
and primitive-mode decisions used by legacy `Shape` drawing, plus Shape buffer
targets, static upload usage, and vertex attribute component/normalization
tokens, also live in `pp_renderer_gl`. Legacy `Shape` mesh buffer/VAO
creation, dynamic vertex/index uploads, fill/stroke draws, and buffer/VAO
deletion now execute through tested `pp_renderer_gl` dispatch contracts,
leaving the retained shape utility with thin GL adapter functions. The
tokens, also live in `pp_renderer_gl`. Retained `Shape`, `TextMesh`, and
`NodeColorWheel` mesh buffer/VAO creation, dynamic vertex/index uploads,
fill/stroke/text draws, and buffer/VAO deletion now execute through tested
`pp_renderer_gl` dispatch contracts via the shared retained
`legacy_gl_mesh_dispatch` raw callback bridge. The
PanoPainter cube-face to
OpenGL texture-target mapping used by `TextureCube` also lives in
`pp_renderer_gl`. The legacy app delegates extension, upload-format,
@@ -1216,8 +1217,8 @@ formats, text mesh buffer targets, attribute component/normalization, draw
primitive/index type, upload usage, and active texture unit selection also
delegate to `pp_renderer_gl`; text mesh buffer/VAO creation, deferred index
and vertex uploads, indexed draw calls, and text draw texture-unit activation
now execute through the same tested dispatch contracts used by `Shape`, leaving
the retained `Font` utility with thin GL adapter functions for mesh operations.
now execute through the same tested dispatch contracts used by `Shape` through
`legacy_gl_mesh_dispatch`.
Canvas undo/redo dirty-region texture updates and readbacks now also execute
through retained `RTT` helpers backed by `pp_renderer_gl`, including 2D texture
target, dirty-region offsets, RGBA pixel format, and unsigned-byte component
@@ -2322,13 +2323,10 @@ Results:
attribute rebinding, active-uniform count/enumeration, and uniform-location
discovery also execute through tested `pp_renderer_gl` dispatch contracts,
leaving only thin GL adapter functions in the retained `Shader` utility.
Legacy `Shape` mesh buffer/VAO creation, zero-byte dynamic-buffer creation,
dynamic buffer uploads, indexed and non-indexed draws, and resource deletion
now execute through tested `pp_renderer_gl` dispatch contracts, leaving only
thin GL adapter functions in the retained shape utility.
Legacy `Font` text mesh creation now covers the one-VAO/deferred-upload case,
and its dynamic index/vertex uploads and indexed draw calls execute through
the same tested dispatch contracts.
Retained `Shape`, `TextMesh`, and `NodeColorWheel` mesh buffer/VAO creation,
zero-byte dynamic-buffer creation, dynamic buffer uploads, indexed and
non-indexed draws, and resource deletion now execute through tested
`pp_renderer_gl` dispatch contracts via `legacy_gl_mesh_dispatch`.
- `pp_renderer_gl_command_plan_tests` covers the headless OpenGL command
planner for recorded render-pass clear masks/values, viewport/scissor state,
blend/depth/sampler state, texture format mapping, mesh/draw primitive modes,
@@ -2573,6 +2571,11 @@ Results:
`legacy_gl_pixel_buffer_dispatch`; this removes another pair of raw resource
callback clusters from `src/texture.cpp` and `src/rtt.cpp` while sampler and
pixel-buffer ownership remain retained under DEBT-0036.
- Retained `Shape`, `TextMesh`, and `NodeColorWheel` mesh buffer/VAO creation,
dynamic vertex/index uploads, fill/stroke/text draws, and buffer/VAO deletion
now share `legacy_gl_mesh_dispatch`, removing duplicated raw mesh callback
clusters from `src/shape.cpp`, `src/font.cpp`, and `src/node_colorwheel.cpp`
while mesh resource ownership remains retained under DEBT-0036.
- Canvas draw-merge shader-blend selection now consumes the extracted
`pp_paint_renderer` stroke composite planner for current layer and primary
brush blend modes, while preserving legacy OpenGL compositing execution under

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");
});
}