Share retained shader dispatch bridge
This commit is contained in:
@@ -490,12 +490,11 @@ powershell -ExecutionPolicy Bypass -File scripts\automation\apple-remote-build.p
|
||||
`Shader` no longer spells GL enum
|
||||
names directly. It also owns the PanoPainter shader uniform catalog and legacy hash
|
||||
mapping used by `Shader` active-uniform discovery and the uniform uniqueness
|
||||
check. Legacy `Shader` program use/delete, uniform writes, and
|
||||
attribute-location lookup now consume tested dispatch contracts here.
|
||||
Legacy shader source compilation, shader deletion, program attach/link,
|
||||
attribute rebinding, active-uniform count/enumeration, and uniform-location
|
||||
discovery now consume tested dispatch contracts as well, leaving the retained
|
||||
shader utility with thin GL adapter functions.
|
||||
check. Legacy `Shader` program use/delete, uniform writes,
|
||||
attribute-location lookup, shader source compilation, shader deletion,
|
||||
program attach/link, attribute rebinding, active-uniform count/enumeration,
|
||||
and uniform-location discovery now consume tested dispatch contracts here
|
||||
through `legacy_gl_shader_dispatch`.
|
||||
App OpenGL initialization debug severity, debug output, GL info string,
|
||||
renderer API viewport/scissor rect conversion, default depth/program-point/
|
||||
line-smooth state, blend factor/equation, and UI render-target RGBA8 format
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1193,7 +1193,11 @@ mapping, including mirrored-repeat, and aggregate renderer API sampler-state to
|
||||
OpenGL min/mag/wrap mapping are also tested there. The PanoPainter shader attribute
|
||||
binding catalog, shader stage tokens, compile/link status queries, active-uniform
|
||||
count query, and matrix-uniform transpose token also live in `pp_renderer_gl`
|
||||
and are consumed by legacy `Shader` creation. Renderer API blend factor/op to
|
||||
and are consumed by legacy `Shader` creation; retained shader source
|
||||
compilation/deletion, program attach/link/use/delete, attribute rebinding and
|
||||
location lookup, active-uniform enumeration, uniform-location discovery, and
|
||||
uniform writes now share the retained `legacy_gl_shader_dispatch` raw callback
|
||||
bridge. Renderer API blend factor/op to
|
||||
OpenGL token mapping also lives in `pp_renderer_gl`, with explicit support flags
|
||||
so `GL_ZERO` remains distinguishable from unsupported enum values. Aggregate
|
||||
renderer API blend-state to OpenGL enable/factor/equation/color-mask mapping,
|
||||
@@ -2317,12 +2321,11 @@ Results:
|
||||
uniform catalog validation covers the 43 legacy uniform
|
||||
names used by `Shader`, preserves the legacy hash ids, and rejects empty,
|
||||
unnamed, null-name, mismatched-hash, and duplicate-name catalogs.
|
||||
Legacy `Shader` program use/delete, uniform writes, and attribute-location
|
||||
lookups now execute through tested `pp_renderer_gl` dispatch contracts.
|
||||
Legacy shader source compilation, shader deletion, program attach/link,
|
||||
Legacy `Shader` program use/delete, uniform writes, attribute-location
|
||||
lookups, shader source compilation, shader deletion, program attach/link,
|
||||
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.
|
||||
discovery now execute through tested `pp_renderer_gl` dispatch contracts via
|
||||
`legacy_gl_shader_dispatch`.
|
||||
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
|
||||
@@ -2576,6 +2579,12 @@ Results:
|
||||
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.
|
||||
- Retained shader source compilation/deletion, program attach/link/use/delete,
|
||||
attribute rebinding and location lookup, active-uniform enumeration,
|
||||
uniform-location discovery, and vec/mat/scalar uniform writes now share
|
||||
`legacy_gl_shader_dispatch`, removing duplicated raw shader/program/uniform
|
||||
callback ownership from `src/shader.cpp` while shader-program 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
|
||||
|
||||
298
src/legacy_gl_shader_dispatch.h
Normal file
298
src/legacy_gl_shader_dispatch.h
Normal file
@@ -0,0 +1,298 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
|
||||
namespace pp::legacy::gl_shader {
|
||||
|
||||
inline void use_opengl_program(std::uint32_t program) noexcept
|
||||
{
|
||||
glUseProgram(static_cast<GLuint>(program));
|
||||
}
|
||||
|
||||
inline void delete_opengl_program(std::uint32_t program) noexcept
|
||||
{
|
||||
glDeleteProgram(static_cast<GLuint>(program));
|
||||
}
|
||||
|
||||
inline void set_opengl_uniform_4fv(std::int32_t location, std::int32_t count, const float* values) noexcept
|
||||
{
|
||||
glUniform4fv(static_cast<GLint>(location), static_cast<GLsizei>(count), values);
|
||||
}
|
||||
|
||||
inline void set_opengl_uniform_3fv(std::int32_t location, std::int32_t count, const float* values) noexcept
|
||||
{
|
||||
glUniform3fv(static_cast<GLint>(location), static_cast<GLsizei>(count), values);
|
||||
}
|
||||
|
||||
inline void set_opengl_uniform_2fv(std::int32_t location, std::int32_t count, const float* values) noexcept
|
||||
{
|
||||
glUniform2fv(static_cast<GLint>(location), static_cast<GLsizei>(count), values);
|
||||
}
|
||||
|
||||
inline void set_opengl_uniform_matrix_4fv(
|
||||
std::int32_t location,
|
||||
std::int32_t count,
|
||||
std::uint8_t transpose,
|
||||
const float* values) noexcept
|
||||
{
|
||||
glUniformMatrix4fv(
|
||||
static_cast<GLint>(location),
|
||||
static_cast<GLsizei>(count),
|
||||
static_cast<GLboolean>(transpose),
|
||||
values);
|
||||
}
|
||||
|
||||
inline void set_opengl_uniform_1i(std::int32_t location, std::int32_t value) noexcept
|
||||
{
|
||||
glUniform1i(static_cast<GLint>(location), static_cast<GLint>(value));
|
||||
}
|
||||
|
||||
inline void set_opengl_uniform_1f(std::int32_t location, float value) noexcept
|
||||
{
|
||||
glUniform1f(static_cast<GLint>(location), value);
|
||||
}
|
||||
|
||||
inline std::int32_t get_opengl_attrib_location(std::uint32_t program, const char* name) noexcept
|
||||
{
|
||||
return static_cast<std::int32_t>(glGetAttribLocation(static_cast<GLuint>(program), name));
|
||||
}
|
||||
|
||||
inline std::uint32_t create_opengl_shader(std::uint32_t stage) noexcept
|
||||
{
|
||||
return static_cast<std::uint32_t>(glCreateShader(static_cast<GLenum>(stage)));
|
||||
}
|
||||
|
||||
inline void set_opengl_shader_source(
|
||||
std::uint32_t shader,
|
||||
std::int32_t count,
|
||||
const char* const* sources) noexcept
|
||||
{
|
||||
glShaderSource(
|
||||
static_cast<GLuint>(shader),
|
||||
static_cast<GLsizei>(count),
|
||||
reinterpret_cast<const GLchar* const*>(sources),
|
||||
nullptr);
|
||||
}
|
||||
|
||||
inline void compile_opengl_shader(std::uint32_t shader) noexcept
|
||||
{
|
||||
glCompileShader(static_cast<GLuint>(shader));
|
||||
}
|
||||
|
||||
inline void query_opengl_shader_integer(
|
||||
std::uint32_t shader,
|
||||
std::uint32_t query,
|
||||
std::int32_t* value) noexcept
|
||||
{
|
||||
glGetShaderiv(
|
||||
static_cast<GLuint>(shader),
|
||||
static_cast<GLenum>(query),
|
||||
reinterpret_cast<GLint*>(value));
|
||||
}
|
||||
|
||||
inline void get_opengl_shader_info_log(
|
||||
std::uint32_t shader,
|
||||
std::int32_t capacity,
|
||||
std::int32_t* length,
|
||||
char* info_log) noexcept
|
||||
{
|
||||
glGetShaderInfoLog(
|
||||
static_cast<GLuint>(shader),
|
||||
static_cast<GLsizei>(capacity),
|
||||
reinterpret_cast<GLsizei*>(length),
|
||||
reinterpret_cast<GLchar*>(info_log));
|
||||
}
|
||||
|
||||
inline void delete_opengl_shader(std::uint32_t shader) noexcept
|
||||
{
|
||||
glDeleteShader(static_cast<GLuint>(shader));
|
||||
}
|
||||
|
||||
inline std::uint32_t create_opengl_program() noexcept
|
||||
{
|
||||
return static_cast<std::uint32_t>(glCreateProgram());
|
||||
}
|
||||
|
||||
inline void attach_opengl_shader(std::uint32_t program, std::uint32_t shader) noexcept
|
||||
{
|
||||
glAttachShader(static_cast<GLuint>(program), static_cast<GLuint>(shader));
|
||||
}
|
||||
|
||||
inline void link_opengl_program(std::uint32_t program) noexcept
|
||||
{
|
||||
glLinkProgram(static_cast<GLuint>(program));
|
||||
}
|
||||
|
||||
inline void bind_opengl_attrib_location(std::uint32_t program, std::uint32_t location, const char* name) noexcept
|
||||
{
|
||||
glBindAttribLocation(static_cast<GLuint>(program), static_cast<GLuint>(location), name);
|
||||
}
|
||||
|
||||
inline void query_opengl_program_integer(
|
||||
std::uint32_t program,
|
||||
std::uint32_t query,
|
||||
std::int32_t* value) noexcept
|
||||
{
|
||||
glGetProgramiv(
|
||||
static_cast<GLuint>(program),
|
||||
static_cast<GLenum>(query),
|
||||
reinterpret_cast<GLint*>(value));
|
||||
}
|
||||
|
||||
inline void get_opengl_program_info_log(
|
||||
std::uint32_t program,
|
||||
std::int32_t capacity,
|
||||
std::int32_t* length,
|
||||
char* info_log) noexcept
|
||||
{
|
||||
glGetProgramInfoLog(
|
||||
static_cast<GLuint>(program),
|
||||
static_cast<GLsizei>(capacity),
|
||||
reinterpret_cast<GLsizei*>(length),
|
||||
reinterpret_cast<GLchar*>(info_log));
|
||||
}
|
||||
|
||||
inline void get_opengl_active_uniform(
|
||||
std::uint32_t program,
|
||||
std::uint32_t index,
|
||||
std::int32_t capacity,
|
||||
std::int32_t* length,
|
||||
std::int32_t* size,
|
||||
std::uint32_t* type,
|
||||
char* name) noexcept
|
||||
{
|
||||
glGetActiveUniform(
|
||||
static_cast<GLuint>(program),
|
||||
static_cast<GLuint>(index),
|
||||
static_cast<GLsizei>(capacity),
|
||||
reinterpret_cast<GLsizei*>(length),
|
||||
reinterpret_cast<GLint*>(size),
|
||||
reinterpret_cast<GLenum*>(type),
|
||||
reinterpret_cast<GLchar*>(name));
|
||||
}
|
||||
|
||||
inline std::int32_t get_opengl_uniform_location(std::uint32_t program, const char* name) noexcept
|
||||
{
|
||||
return static_cast<std::int32_t>(glGetUniformLocation(static_cast<GLuint>(program), name));
|
||||
}
|
||||
|
||||
inline pp::renderer::gl::OpenGlProgramUseDispatch program_use_dispatch() noexcept
|
||||
{
|
||||
return pp::renderer::gl::OpenGlProgramUseDispatch {
|
||||
.use_program = use_opengl_program,
|
||||
};
|
||||
}
|
||||
|
||||
inline pp::renderer::gl::OpenGlProgramDeleteDispatch program_delete_dispatch() noexcept
|
||||
{
|
||||
return pp::renderer::gl::OpenGlProgramDeleteDispatch {
|
||||
.use_program = use_opengl_program,
|
||||
.delete_program = delete_opengl_program,
|
||||
};
|
||||
}
|
||||
|
||||
inline pp::renderer::gl::OpenGlUniformVec4Dispatch uniform_vec4_dispatch() noexcept
|
||||
{
|
||||
return pp::renderer::gl::OpenGlUniformVec4Dispatch {
|
||||
.uniform_4fv = set_opengl_uniform_4fv,
|
||||
};
|
||||
}
|
||||
|
||||
inline pp::renderer::gl::OpenGlUniformVec3Dispatch uniform_vec3_dispatch() noexcept
|
||||
{
|
||||
return pp::renderer::gl::OpenGlUniformVec3Dispatch {
|
||||
.uniform_3fv = set_opengl_uniform_3fv,
|
||||
};
|
||||
}
|
||||
|
||||
inline pp::renderer::gl::OpenGlUniformVec2Dispatch uniform_vec2_dispatch() noexcept
|
||||
{
|
||||
return pp::renderer::gl::OpenGlUniformVec2Dispatch {
|
||||
.uniform_2fv = set_opengl_uniform_2fv,
|
||||
};
|
||||
}
|
||||
|
||||
inline pp::renderer::gl::OpenGlUniformMat4Dispatch uniform_mat4_dispatch() noexcept
|
||||
{
|
||||
return pp::renderer::gl::OpenGlUniformMat4Dispatch {
|
||||
.uniform_matrix_4fv = set_opengl_uniform_matrix_4fv,
|
||||
};
|
||||
}
|
||||
|
||||
inline pp::renderer::gl::OpenGlUniformIntDispatch uniform_int_dispatch() noexcept
|
||||
{
|
||||
return pp::renderer::gl::OpenGlUniformIntDispatch {
|
||||
.uniform_1i = set_opengl_uniform_1i,
|
||||
};
|
||||
}
|
||||
|
||||
inline pp::renderer::gl::OpenGlUniformFloatDispatch uniform_float_dispatch() noexcept
|
||||
{
|
||||
return pp::renderer::gl::OpenGlUniformFloatDispatch {
|
||||
.uniform_1f = set_opengl_uniform_1f,
|
||||
};
|
||||
}
|
||||
|
||||
inline pp::renderer::gl::OpenGlAttributeLocationDispatch attribute_location_dispatch() noexcept
|
||||
{
|
||||
return pp::renderer::gl::OpenGlAttributeLocationDispatch {
|
||||
.get_attrib_location = get_opengl_attrib_location,
|
||||
};
|
||||
}
|
||||
|
||||
inline pp::renderer::gl::OpenGlShaderCompileDispatch shader_compile_dispatch() noexcept
|
||||
{
|
||||
return pp::renderer::gl::OpenGlShaderCompileDispatch {
|
||||
.create_shader = create_opengl_shader,
|
||||
.shader_source = set_opengl_shader_source,
|
||||
.compile_shader = compile_opengl_shader,
|
||||
.get_shader_integer = query_opengl_shader_integer,
|
||||
.get_shader_info_log = get_opengl_shader_info_log,
|
||||
};
|
||||
}
|
||||
|
||||
inline pp::renderer::gl::OpenGlShaderDeleteDispatch shader_delete_dispatch() noexcept
|
||||
{
|
||||
return pp::renderer::gl::OpenGlShaderDeleteDispatch {
|
||||
.delete_shader = delete_opengl_shader,
|
||||
};
|
||||
}
|
||||
|
||||
inline pp::renderer::gl::OpenGlProgramLinkDispatch program_link_dispatch() noexcept
|
||||
{
|
||||
return pp::renderer::gl::OpenGlProgramLinkDispatch {
|
||||
.create_program = create_opengl_program,
|
||||
.attach_shader = attach_opengl_shader,
|
||||
.delete_shader = delete_opengl_shader,
|
||||
.link_program = link_opengl_program,
|
||||
.get_attrib_location = get_opengl_attrib_location,
|
||||
.bind_attrib_location = bind_opengl_attrib_location,
|
||||
.get_program_integer = query_opengl_program_integer,
|
||||
.get_program_info_log = get_opengl_program_info_log,
|
||||
};
|
||||
}
|
||||
|
||||
inline pp::renderer::gl::OpenGlProgramIntegerDispatch program_integer_dispatch() noexcept
|
||||
{
|
||||
return pp::renderer::gl::OpenGlProgramIntegerDispatch {
|
||||
.get_program_integer = query_opengl_program_integer,
|
||||
};
|
||||
}
|
||||
|
||||
inline pp::renderer::gl::OpenGlActiveUniformDispatch active_uniform_dispatch() noexcept
|
||||
{
|
||||
return pp::renderer::gl::OpenGlActiveUniformDispatch {
|
||||
.get_active_uniform = get_opengl_active_uniform,
|
||||
};
|
||||
}
|
||||
|
||||
inline pp::renderer::gl::OpenGlUniformLocationDispatch uniform_location_dispatch() noexcept
|
||||
{
|
||||
return pp::renderer::gl::OpenGlUniformLocationDispatch {
|
||||
.get_uniform_location = get_opengl_uniform_location,
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace pp::legacy::gl_shader
|
||||
320
src/shader.cpp
320
src/shader.cpp
@@ -3,212 +3,12 @@
|
||||
#include "shader.h"
|
||||
#include "asset.h"
|
||||
#include "app.h"
|
||||
#include "legacy_gl_shader_dispatch.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
#include "renderer_gl/shader_bindings.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace {
|
||||
|
||||
[[nodiscard]] GLenum vertex_shader_stage() noexcept
|
||||
{
|
||||
return static_cast<GLenum>(pp::renderer::gl::vertex_shader_stage());
|
||||
}
|
||||
|
||||
[[nodiscard]] GLenum fragment_shader_stage() noexcept
|
||||
{
|
||||
return static_cast<GLenum>(pp::renderer::gl::fragment_shader_stage());
|
||||
}
|
||||
|
||||
[[nodiscard]] GLenum shader_compile_status_query() noexcept
|
||||
{
|
||||
return static_cast<GLenum>(pp::renderer::gl::shader_compile_status_query());
|
||||
}
|
||||
|
||||
[[nodiscard]] GLenum program_link_status_query() noexcept
|
||||
{
|
||||
return static_cast<GLenum>(pp::renderer::gl::program_link_status_query());
|
||||
}
|
||||
|
||||
[[nodiscard]] GLenum active_uniform_count_query() noexcept
|
||||
{
|
||||
return static_cast<GLenum>(pp::renderer::gl::active_uniform_count_query());
|
||||
}
|
||||
|
||||
void use_opengl_program(std::uint32_t program) noexcept
|
||||
{
|
||||
glUseProgram(static_cast<GLuint>(program));
|
||||
}
|
||||
|
||||
void delete_opengl_program(std::uint32_t program) noexcept
|
||||
{
|
||||
glDeleteProgram(static_cast<GLuint>(program));
|
||||
}
|
||||
|
||||
void set_opengl_uniform_4fv(std::int32_t location, std::int32_t count, const float* values) noexcept
|
||||
{
|
||||
glUniform4fv(static_cast<GLint>(location), static_cast<GLsizei>(count), values);
|
||||
}
|
||||
|
||||
void set_opengl_uniform_3fv(std::int32_t location, std::int32_t count, const float* values) noexcept
|
||||
{
|
||||
glUniform3fv(static_cast<GLint>(location), static_cast<GLsizei>(count), values);
|
||||
}
|
||||
|
||||
void set_opengl_uniform_2fv(std::int32_t location, std::int32_t count, const float* values) noexcept
|
||||
{
|
||||
glUniform2fv(static_cast<GLint>(location), static_cast<GLsizei>(count), values);
|
||||
}
|
||||
|
||||
void set_opengl_uniform_matrix_4fv(
|
||||
std::int32_t location,
|
||||
std::int32_t count,
|
||||
std::uint8_t transpose,
|
||||
const float* values) noexcept
|
||||
{
|
||||
glUniformMatrix4fv(
|
||||
static_cast<GLint>(location),
|
||||
static_cast<GLsizei>(count),
|
||||
static_cast<GLboolean>(transpose),
|
||||
values);
|
||||
}
|
||||
|
||||
void set_opengl_uniform_1i(std::int32_t location, std::int32_t value) noexcept
|
||||
{
|
||||
glUniform1i(static_cast<GLint>(location), static_cast<GLint>(value));
|
||||
}
|
||||
|
||||
void set_opengl_uniform_1f(std::int32_t location, float value) noexcept
|
||||
{
|
||||
glUniform1f(static_cast<GLint>(location), value);
|
||||
}
|
||||
|
||||
std::int32_t get_opengl_attrib_location(std::uint32_t program, const char* name) noexcept
|
||||
{
|
||||
return static_cast<std::int32_t>(glGetAttribLocation(static_cast<GLuint>(program), name));
|
||||
}
|
||||
|
||||
std::uint32_t create_opengl_shader(std::uint32_t stage) noexcept
|
||||
{
|
||||
return static_cast<std::uint32_t>(glCreateShader(static_cast<GLenum>(stage)));
|
||||
}
|
||||
|
||||
void set_opengl_shader_source(
|
||||
std::uint32_t shader,
|
||||
std::int32_t count,
|
||||
const char* const* sources) noexcept
|
||||
{
|
||||
glShaderSource(
|
||||
static_cast<GLuint>(shader),
|
||||
static_cast<GLsizei>(count),
|
||||
reinterpret_cast<const GLchar* const*>(sources),
|
||||
nullptr);
|
||||
}
|
||||
|
||||
void compile_opengl_shader(std::uint32_t shader) noexcept
|
||||
{
|
||||
glCompileShader(static_cast<GLuint>(shader));
|
||||
}
|
||||
|
||||
void query_opengl_shader_integer(
|
||||
std::uint32_t shader,
|
||||
std::uint32_t query,
|
||||
std::int32_t* value) noexcept
|
||||
{
|
||||
glGetShaderiv(
|
||||
static_cast<GLuint>(shader),
|
||||
static_cast<GLenum>(query),
|
||||
reinterpret_cast<GLint*>(value));
|
||||
}
|
||||
|
||||
void get_opengl_shader_info_log(
|
||||
std::uint32_t shader,
|
||||
std::int32_t capacity,
|
||||
std::int32_t* length,
|
||||
char* info_log) noexcept
|
||||
{
|
||||
glGetShaderInfoLog(
|
||||
static_cast<GLuint>(shader),
|
||||
static_cast<GLsizei>(capacity),
|
||||
reinterpret_cast<GLsizei*>(length),
|
||||
reinterpret_cast<GLchar*>(info_log));
|
||||
}
|
||||
|
||||
void delete_opengl_shader(std::uint32_t shader) noexcept
|
||||
{
|
||||
glDeleteShader(static_cast<GLuint>(shader));
|
||||
}
|
||||
|
||||
std::uint32_t create_opengl_program() noexcept
|
||||
{
|
||||
return static_cast<std::uint32_t>(glCreateProgram());
|
||||
}
|
||||
|
||||
void attach_opengl_shader(std::uint32_t program, std::uint32_t shader) noexcept
|
||||
{
|
||||
glAttachShader(static_cast<GLuint>(program), static_cast<GLuint>(shader));
|
||||
}
|
||||
|
||||
void link_opengl_program(std::uint32_t program) noexcept
|
||||
{
|
||||
glLinkProgram(static_cast<GLuint>(program));
|
||||
}
|
||||
|
||||
void bind_opengl_attrib_location(std::uint32_t program, std::uint32_t location, const char* name) noexcept
|
||||
{
|
||||
glBindAttribLocation(static_cast<GLuint>(program), static_cast<GLuint>(location), name);
|
||||
}
|
||||
|
||||
void query_opengl_program_integer(
|
||||
std::uint32_t program,
|
||||
std::uint32_t query,
|
||||
std::int32_t* value) noexcept
|
||||
{
|
||||
glGetProgramiv(
|
||||
static_cast<GLuint>(program),
|
||||
static_cast<GLenum>(query),
|
||||
reinterpret_cast<GLint*>(value));
|
||||
}
|
||||
|
||||
void get_opengl_program_info_log(
|
||||
std::uint32_t program,
|
||||
std::int32_t capacity,
|
||||
std::int32_t* length,
|
||||
char* info_log) noexcept
|
||||
{
|
||||
glGetProgramInfoLog(
|
||||
static_cast<GLuint>(program),
|
||||
static_cast<GLsizei>(capacity),
|
||||
reinterpret_cast<GLsizei*>(length),
|
||||
reinterpret_cast<GLchar*>(info_log));
|
||||
}
|
||||
|
||||
void get_opengl_active_uniform(
|
||||
std::uint32_t program,
|
||||
std::uint32_t index,
|
||||
std::int32_t capacity,
|
||||
std::int32_t* length,
|
||||
std::int32_t* size,
|
||||
std::uint32_t* type,
|
||||
char* name) noexcept
|
||||
{
|
||||
glGetActiveUniform(
|
||||
static_cast<GLuint>(program),
|
||||
static_cast<GLuint>(index),
|
||||
static_cast<GLsizei>(capacity),
|
||||
reinterpret_cast<GLsizei*>(length),
|
||||
reinterpret_cast<GLint*>(size),
|
||||
reinterpret_cast<GLenum*>(type),
|
||||
reinterpret_cast<GLchar*>(name));
|
||||
}
|
||||
|
||||
std::int32_t get_opengl_uniform_location(std::uint32_t program, const char* name) noexcept
|
||||
{
|
||||
return static_cast<std::int32_t>(glGetUniformLocation(static_cast<GLuint>(program), name));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::map<kShader, Shader> ShaderManager::m_shaders;
|
||||
Shader* ShaderManager::m_current;
|
||||
pp::renderer::RenderDeviceFeatures ShaderManager::m_render_device_features {};
|
||||
@@ -373,13 +173,7 @@ bool Shader::create(const std::string& vertex, const std::string& fragment)
|
||||
vertex.c_str(),
|
||||
infolog,
|
||||
static_cast<std::int32_t>(sizeof(infolog)),
|
||||
pp::renderer::gl::OpenGlShaderCompileDispatch {
|
||||
.create_shader = create_opengl_shader,
|
||||
.shader_source = set_opengl_shader_source,
|
||||
.compile_shader = compile_opengl_shader,
|
||||
.get_shader_integer = query_opengl_shader_integer,
|
||||
.get_shader_info_log = get_opengl_shader_info_log,
|
||||
});
|
||||
pp::legacy::gl_shader::shader_compile_dispatch());
|
||||
if (!vertex_shader.ok())
|
||||
{
|
||||
ret = false;
|
||||
@@ -395,9 +189,7 @@ bool Shader::create(const std::string& vertex, const std::string& fragment)
|
||||
{
|
||||
const auto status = pp::renderer::gl::delete_opengl_shader(
|
||||
vertex_shader.value().shader_id,
|
||||
pp::renderer::gl::OpenGlShaderDeleteDispatch {
|
||||
.delete_shader = delete_opengl_shader,
|
||||
});
|
||||
pp::legacy::gl_shader::shader_delete_dispatch());
|
||||
if (!status.ok())
|
||||
LOG("Shader::create() vertex shader cleanup failed because: %s", status.message);
|
||||
ret = false;
|
||||
@@ -409,20 +201,12 @@ bool Shader::create(const std::string& vertex, const std::string& fragment)
|
||||
fragment.c_str(),
|
||||
infolog,
|
||||
static_cast<std::int32_t>(sizeof(infolog)),
|
||||
pp::renderer::gl::OpenGlShaderCompileDispatch {
|
||||
.create_shader = create_opengl_shader,
|
||||
.shader_source = set_opengl_shader_source,
|
||||
.compile_shader = compile_opengl_shader,
|
||||
.get_shader_integer = query_opengl_shader_integer,
|
||||
.get_shader_info_log = get_opengl_shader_info_log,
|
||||
});
|
||||
pp::legacy::gl_shader::shader_compile_dispatch());
|
||||
if (!fragment_shader.ok())
|
||||
{
|
||||
const auto status = pp::renderer::gl::delete_opengl_shader(
|
||||
vertex_shader.value().shader_id,
|
||||
pp::renderer::gl::OpenGlShaderDeleteDispatch {
|
||||
.delete_shader = delete_opengl_shader,
|
||||
});
|
||||
pp::legacy::gl_shader::shader_delete_dispatch());
|
||||
if (!status.ok())
|
||||
LOG("Shader::create() vertex shader cleanup failed because: %s", status.message);
|
||||
ret = false;
|
||||
@@ -438,14 +222,10 @@ bool Shader::create(const std::string& vertex, const std::string& fragment)
|
||||
{
|
||||
const auto vertex_cleanup = pp::renderer::gl::delete_opengl_shader(
|
||||
vertex_shader.value().shader_id,
|
||||
pp::renderer::gl::OpenGlShaderDeleteDispatch {
|
||||
.delete_shader = delete_opengl_shader,
|
||||
});
|
||||
pp::legacy::gl_shader::shader_delete_dispatch());
|
||||
const auto fragment_cleanup = pp::renderer::gl::delete_opengl_shader(
|
||||
fragment_shader.value().shader_id,
|
||||
pp::renderer::gl::OpenGlShaderDeleteDispatch {
|
||||
.delete_shader = delete_opengl_shader,
|
||||
});
|
||||
pp::legacy::gl_shader::shader_delete_dispatch());
|
||||
if (!vertex_cleanup.ok())
|
||||
LOG("Shader::create() vertex shader cleanup failed because: %s", vertex_cleanup.message);
|
||||
if (!fragment_cleanup.ok())
|
||||
@@ -460,28 +240,15 @@ bool Shader::create(const std::string& vertex, const std::string& fragment)
|
||||
pp::renderer::gl::panopainter_shader_attribute_bindings(),
|
||||
infolog,
|
||||
static_cast<std::int32_t>(sizeof(infolog)),
|
||||
pp::renderer::gl::OpenGlProgramLinkDispatch {
|
||||
.create_program = create_opengl_program,
|
||||
.attach_shader = attach_opengl_shader,
|
||||
.delete_shader = delete_opengl_shader,
|
||||
.link_program = link_opengl_program,
|
||||
.get_attrib_location = get_opengl_attrib_location,
|
||||
.bind_attrib_location = bind_opengl_attrib_location,
|
||||
.get_program_integer = query_opengl_program_integer,
|
||||
.get_program_info_log = get_opengl_program_info_log,
|
||||
});
|
||||
pp::legacy::gl_shader::program_link_dispatch());
|
||||
if (!program.ok())
|
||||
{
|
||||
const auto vertex_cleanup = pp::renderer::gl::delete_opengl_shader(
|
||||
vertex_shader.value().shader_id,
|
||||
pp::renderer::gl::OpenGlShaderDeleteDispatch {
|
||||
.delete_shader = delete_opengl_shader,
|
||||
});
|
||||
pp::legacy::gl_shader::shader_delete_dispatch());
|
||||
const auto fragment_cleanup = pp::renderer::gl::delete_opengl_shader(
|
||||
fragment_shader.value().shader_id,
|
||||
pp::renderer::gl::OpenGlShaderDeleteDispatch {
|
||||
.delete_shader = delete_opengl_shader,
|
||||
});
|
||||
pp::legacy::gl_shader::shader_delete_dispatch());
|
||||
if (!vertex_cleanup.ok())
|
||||
LOG("Shader::create() vertex shader cleanup failed because: %s", vertex_cleanup.message);
|
||||
if (!fragment_cleanup.ok())
|
||||
@@ -496,10 +263,7 @@ bool Shader::create(const std::string& vertex, const std::string& fragment)
|
||||
{
|
||||
const auto status = pp::renderer::gl::delete_opengl_program(
|
||||
program.value().program_id,
|
||||
pp::renderer::gl::OpenGlProgramDeleteDispatch {
|
||||
.use_program = use_opengl_program,
|
||||
.delete_program = delete_opengl_program,
|
||||
});
|
||||
pp::legacy::gl_shader::program_delete_dispatch());
|
||||
if (!status.ok())
|
||||
LOG("Shader::create() program cleanup failed because: %s", status.message);
|
||||
ret = false;
|
||||
@@ -509,10 +273,7 @@ bool Shader::create(const std::string& vertex, const std::string& fragment)
|
||||
const auto cleanup_program = [](std::uint32_t program_id) noexcept {
|
||||
const auto status = pp::renderer::gl::delete_opengl_program(
|
||||
program_id,
|
||||
pp::renderer::gl::OpenGlProgramDeleteDispatch {
|
||||
.use_program = use_opengl_program,
|
||||
.delete_program = delete_opengl_program,
|
||||
});
|
||||
pp::legacy::gl_shader::program_delete_dispatch());
|
||||
if (!status.ok())
|
||||
LOG("Shader::create() program cleanup failed because: %s", status.message);
|
||||
};
|
||||
@@ -522,9 +283,7 @@ bool Shader::create(const std::string& vertex, const std::string& fragment)
|
||||
const auto uniform_count = pp::renderer::gl::query_opengl_program_integer(
|
||||
program.value().program_id,
|
||||
pp::renderer::gl::active_uniform_count_query(),
|
||||
pp::renderer::gl::OpenGlProgramIntegerDispatch {
|
||||
.get_program_integer = query_opengl_program_integer,
|
||||
});
|
||||
pp::legacy::gl_shader::program_integer_dispatch());
|
||||
if (!uniform_count.ok())
|
||||
{
|
||||
LOG("Shader::create() uniform discovery failed because: %s", uniform_count.status().message);
|
||||
@@ -542,9 +301,7 @@ bool Shader::create(const std::string& vertex, const std::string& fragment)
|
||||
static_cast<std::uint32_t>(i),
|
||||
uniform_name,
|
||||
bufSize,
|
||||
pp::renderer::gl::OpenGlActiveUniformDispatch {
|
||||
.get_active_uniform = get_opengl_active_uniform,
|
||||
});
|
||||
pp::legacy::gl_shader::active_uniform_dispatch());
|
||||
if (!uniform.ok())
|
||||
{
|
||||
LOG("Shader::create() active uniform discovery failed because: %s", uniform.status().message);
|
||||
@@ -558,9 +315,7 @@ bool Shader::create(const std::string& vertex, const std::string& fragment)
|
||||
const auto location = pp::renderer::gl::get_opengl_uniform_location(
|
||||
program.value().program_id,
|
||||
uniform_name,
|
||||
pp::renderer::gl::OpenGlUniformLocationDispatch {
|
||||
.get_uniform_location = get_opengl_uniform_location,
|
||||
});
|
||||
pp::legacy::gl_shader::uniform_location_dispatch());
|
||||
if (!location.ok())
|
||||
{
|
||||
LOG("Shader::create() uniform location failed because: %s", location.status().message);
|
||||
@@ -586,10 +341,7 @@ void Shader::destroy()
|
||||
{
|
||||
const auto status = pp::renderer::gl::delete_opengl_program(
|
||||
static_cast<std::uint32_t>(prog),
|
||||
pp::renderer::gl::OpenGlProgramDeleteDispatch {
|
||||
.use_program = use_opengl_program,
|
||||
.delete_program = delete_opengl_program,
|
||||
});
|
||||
pp::legacy::gl_shader::program_delete_dispatch());
|
||||
if (!status.ok())
|
||||
LOG("Shader::destroy() failed because: %s", status.message);
|
||||
});
|
||||
@@ -602,9 +354,7 @@ void Shader::use()
|
||||
{
|
||||
const auto status = pp::renderer::gl::use_opengl_program(
|
||||
static_cast<std::uint32_t>(prog),
|
||||
pp::renderer::gl::OpenGlProgramUseDispatch {
|
||||
.use_program = use_opengl_program,
|
||||
});
|
||||
pp::legacy::gl_shader::program_use_dispatch());
|
||||
if (!status.ok())
|
||||
LOG("Shader::use() failed because: %s", status.message);
|
||||
}
|
||||
@@ -617,9 +367,7 @@ void Shader::u_vec4(kShaderUniform id, const glm::vec4& v)
|
||||
const auto status = pp::renderer::gl::set_opengl_uniform_vec4(
|
||||
static_cast<std::int32_t>(m_umap[id]),
|
||||
glm::value_ptr(v),
|
||||
pp::renderer::gl::OpenGlUniformVec4Dispatch {
|
||||
.uniform_4fv = set_opengl_uniform_4fv,
|
||||
});
|
||||
pp::legacy::gl_shader::uniform_vec4_dispatch());
|
||||
if (!status.ok())
|
||||
LOG("Shader::u_vec4() failed because: %s", status.message);
|
||||
}
|
||||
@@ -633,9 +381,7 @@ void Shader::u_vec3(kShaderUniform id, const glm::vec3& v)
|
||||
const auto status = pp::renderer::gl::set_opengl_uniform_vec3(
|
||||
static_cast<std::int32_t>(m_umap[id]),
|
||||
glm::value_ptr(v),
|
||||
pp::renderer::gl::OpenGlUniformVec3Dispatch {
|
||||
.uniform_3fv = set_opengl_uniform_3fv,
|
||||
});
|
||||
pp::legacy::gl_shader::uniform_vec3_dispatch());
|
||||
if (!status.ok())
|
||||
LOG("Shader::u_vec3() failed because: %s", status.message);
|
||||
}
|
||||
@@ -650,9 +396,7 @@ void Shader::u_vec2(kShaderUniform id, const glm::vec2& v)
|
||||
const auto status = pp::renderer::gl::set_opengl_uniform_vec2(
|
||||
static_cast<std::int32_t>(m_umap[id]),
|
||||
glm::value_ptr(v),
|
||||
pp::renderer::gl::OpenGlUniformVec2Dispatch {
|
||||
.uniform_2fv = set_opengl_uniform_2fv,
|
||||
});
|
||||
pp::legacy::gl_shader::uniform_vec2_dispatch());
|
||||
if (!status.ok())
|
||||
LOG("Shader::u_vec2() failed because: %s", status.message);
|
||||
}
|
||||
@@ -667,9 +411,7 @@ void Shader::u_mat4(kShaderUniform id, const glm::mat4& m)
|
||||
const auto status = pp::renderer::gl::set_opengl_uniform_mat4(
|
||||
static_cast<std::int32_t>(m_umap[id]),
|
||||
glm::value_ptr(m),
|
||||
pp::renderer::gl::OpenGlUniformMat4Dispatch {
|
||||
.uniform_matrix_4fv = set_opengl_uniform_matrix_4fv,
|
||||
});
|
||||
pp::legacy::gl_shader::uniform_mat4_dispatch());
|
||||
if (!status.ok())
|
||||
LOG("Shader::u_mat4() failed because: %s", status.message);
|
||||
}
|
||||
@@ -683,9 +425,7 @@ void Shader::u_int(kShaderUniform id, int i)
|
||||
const auto status = pp::renderer::gl::set_opengl_uniform_int(
|
||||
static_cast<std::int32_t>(m_umap[id]),
|
||||
static_cast<std::int32_t>(i),
|
||||
pp::renderer::gl::OpenGlUniformIntDispatch {
|
||||
.uniform_1i = set_opengl_uniform_1i,
|
||||
});
|
||||
pp::legacy::gl_shader::uniform_int_dispatch());
|
||||
if (!status.ok())
|
||||
LOG("Shader::u_int() failed because: %s", status.message);
|
||||
}
|
||||
@@ -695,9 +435,7 @@ void Shader::u_int(const char* uniform_name, int i)
|
||||
const auto location = pp::renderer::gl::get_opengl_attribute_location(
|
||||
static_cast<std::uint32_t>(prog),
|
||||
uniform_name,
|
||||
pp::renderer::gl::OpenGlAttributeLocationDispatch {
|
||||
.get_attrib_location = get_opengl_attrib_location,
|
||||
});
|
||||
pp::legacy::gl_shader::attribute_location_dispatch());
|
||||
if (!location.ok())
|
||||
{
|
||||
LOG("Shader::u_int(name) lookup failed because: %s", location.status().message);
|
||||
@@ -706,9 +444,7 @@ void Shader::u_int(const char* uniform_name, int i)
|
||||
const auto status = pp::renderer::gl::set_opengl_uniform_int(
|
||||
location.value(),
|
||||
static_cast<std::int32_t>(i),
|
||||
pp::renderer::gl::OpenGlUniformIntDispatch {
|
||||
.uniform_1i = set_opengl_uniform_1i,
|
||||
});
|
||||
pp::legacy::gl_shader::uniform_int_dispatch());
|
||||
if (!status.ok())
|
||||
LOG("Shader::u_int(name) failed because: %s", status.message);
|
||||
}
|
||||
@@ -721,9 +457,7 @@ void Shader::u_float(kShaderUniform id, float f)
|
||||
const auto status = pp::renderer::gl::set_opengl_uniform_float(
|
||||
static_cast<std::int32_t>(m_umap[id]),
|
||||
f,
|
||||
pp::renderer::gl::OpenGlUniformFloatDispatch {
|
||||
.uniform_1f = set_opengl_uniform_1f,
|
||||
});
|
||||
pp::legacy::gl_shader::uniform_float_dispatch());
|
||||
if (!status.ok())
|
||||
LOG("Shader::u_float() failed because: %s", status.message);
|
||||
}
|
||||
@@ -733,9 +467,7 @@ GLint Shader::GetAttribLocation(const char* attribute_name)
|
||||
const auto location = pp::renderer::gl::get_opengl_attribute_location(
|
||||
static_cast<std::uint32_t>(prog),
|
||||
attribute_name,
|
||||
pp::renderer::gl::OpenGlAttributeLocationDispatch {
|
||||
.get_attrib_location = get_opengl_attrib_location,
|
||||
});
|
||||
pp::legacy::gl_shader::attribute_location_dispatch());
|
||||
if (!location.ok())
|
||||
{
|
||||
LOG("Shader::GetAttribLocation() failed because: %s", location.status().message);
|
||||
|
||||
Reference in New Issue
Block a user