Move OpenGL shape draw mappings

This commit is contained in:
2026-06-01 17:52:59 +02:00
parent aa32c47e18
commit 05064b3a0d
6 changed files with 83 additions and 15 deletions

View File

@@ -5,8 +5,13 @@ namespace pp::renderer::gl {
namespace {
constexpr std::uint32_t gl_unsigned_byte = 0x1401U;
constexpr std::uint32_t gl_unsigned_short = 0x1403U;
constexpr std::uint32_t gl_unsigned_int = 0x1405U;
constexpr std::uint32_t gl_float = 0x1406U;
constexpr std::uint32_t gl_half_float = 0x140BU;
constexpr std::uint32_t gl_points = 0x0000U;
constexpr std::uint32_t gl_lines = 0x0001U;
constexpr std::uint32_t gl_triangles = 0x0004U;
constexpr std::uint32_t gl_red = 0x1903U;
constexpr std::uint32_t gl_rgb = 0x1907U;
constexpr std::uint32_t gl_rgba = 0x1908U;
@@ -124,4 +129,38 @@ const char* framebuffer_status_name(std::uint32_t status) noexcept
}
}
std::uint32_t index_type_for_index_size(std::uint32_t index_size_bytes) noexcept
{
switch (index_size_bytes) {
case 2:
return gl_unsigned_short;
case 4:
return gl_unsigned_int;
default:
return 0U;
}
}
std::uint32_t primitive_mode_for_fill_count(std::uint32_t vertex_or_index_count) noexcept
{
if (vertex_or_index_count == 1U) {
return gl_points;
}
if (vertex_or_index_count == 2U) {
return gl_lines;
}
return gl_triangles;
}
std::uint32_t primitive_mode_for_stroke_count(std::uint32_t vertex_or_index_count) noexcept
{
if (vertex_or_index_count == 1U) {
return gl_points;
}
return gl_lines;
}
}

View File

@@ -33,5 +33,8 @@ struct OpenGlPixelFormat {
[[nodiscard]] std::uint32_t texture_upload_type_for_internal_format(std::uint32_t internal_format) noexcept;
[[nodiscard]] OpenGlPixelFormat texture_format_for_channel_count(std::uint32_t channel_count) noexcept;
[[nodiscard]] const char* framebuffer_status_name(std::uint32_t status) noexcept;
[[nodiscard]] std::uint32_t index_type_for_index_size(std::uint32_t index_size_bytes) noexcept;
[[nodiscard]] std::uint32_t primitive_mode_for_fill_count(std::uint32_t vertex_or_index_count) noexcept;
[[nodiscard]] std::uint32_t primitive_mode_for_stroke_count(std::uint32_t vertex_or_index_count) noexcept;
}

View File

@@ -2,17 +2,20 @@
#include "log.h"
#include "shape.h"
#include "app.h"
#include "renderer_gl/opengl_capabilities.h"
#include <cstdint>
bool Shape::create_buffers(GLushort * idx, GLvoid * vertices, int isize, int vsize)
{
index_type = GL_UNSIGNED_SHORT;
index_type = static_cast<GLenum>(pp::renderer::gl::index_type_for_index_size(sizeof(GLushort)));
create_buffers_imp(idx, vertices, isize, vsize);
return false;
}
bool Shape::create_buffers(GLuint* idx, GLvoid * vertices, int isize, int vsize)
{
index_type = GL_UNSIGNED_INT;
index_type = static_cast<GLenum>(pp::renderer::gl::index_type_for_index_size(sizeof(GLuint)));
create_buffers_imp(idx, vertices, isize, vsize);
return false;
}
@@ -119,11 +122,7 @@ void Shape::draw_fill() const
{
if (count[0] == 0) return;
GLenum type = GL_TRIANGLES;
if (count[0] == 1)
type = GL_POINTS;
if (count[0] == 2)
type = GL_LINES;
const auto type = static_cast<GLenum>(pp::renderer::gl::primitive_mode_for_fill_count(count[0]));
App::I->render_task([=]
{
#if USE_VBO
@@ -157,9 +156,7 @@ void Shape::draw_stroke() const
{
if (count[0] == 0) return;
GLenum type = GL_LINES;
if (count[1] == 1)
type = GL_POINTS;
const auto type = static_cast<GLenum>(pp::renderer::gl::primitive_mode_for_stroke_count(count[1]));
App::I->render_task([=]
{
#if USE_VBO