Started refactor to lazily compilable shaders.

This commit is contained in:
zy4n
2025-03-02 22:56:53 +01:00
parent 447146b7f5
commit 925125e99b
50 changed files with 2181 additions and 738 deletions

View File

@@ -2,82 +2,42 @@
#include "opengl/shader_program_variable.hpp"
#include <array>
#include "util/enum_bitfield_operators.hpp"
#include <string_view>
namespace shader_program::attributes::mesh
{
enum class flags : int {
enum class flags : unsigned {
none = 0,
position = 1 << 0,
normal = 1 << 1,
tex_coord = 1 << 2
luminance = 1 << 2,
color = 1 << 3,
alpha = 1 << 4,
tex_coord = 1 << 5
};
constexpr inline auto position = zgl::shader_program_variable({ GL_FLOAT_VEC3, 0 }, "vertex_position");
constexpr inline auto normal = zgl::shader_program_variable({ GL_FLOAT_VEC3, 1 }, "vertex_normal");
constexpr inline auto tex_coord = zgl::shader_program_variable({ GL_FLOAT_VEC2, 2 }, "vertex_tex_coord");
constexpr inline auto position = zgl::shader_program_variable({ GL_FLOAT_VEC3, 0 }, "model_vertex_position");
constexpr inline auto normal = zgl::shader_program_variable({ GL_FLOAT_VEC3, 1 }, "model_vertex_normal");
constexpr inline auto luminance = zgl::shader_program_variable({ GL_FLOAT, 2 }, "model_vertex_l");
constexpr inline auto color = zgl::shader_program_variable({ GL_FLOAT_VEC3, 2 }, "model_vertex_rgb");
constexpr inline auto alpha = zgl::shader_program_variable({ GL_FLOAT, 3 }, "model_vertex_a");
constexpr inline auto tex_coord = zgl::shader_program_variable({ GL_FLOAT_VEC2, 2 }, "model_vertex_tex_coord");
constexpr inline auto all = std::array{
position, normal, tex_coord
position, normal, luminance, color, alpha, tex_coord
};
constexpr inline auto names = std::array<std::string_view, 6>{
"position",
"normal",
"luminance",
"color",
"alpha",
"tex_coord"
};
}
[[nodiscard]] constexpr shader_program::attributes::mesh::flags operator|(
const shader_program::attributes::mesh::flags& a, const shader_program::attributes::mesh::flags& b
) {
return static_cast<shader_program::attributes::mesh::flags>(static_cast<int>(a) | static_cast<int>(b));
}
[[nodiscard]] constexpr shader_program::attributes::mesh::flags operator&(
const shader_program::attributes::mesh::flags& a, const shader_program::attributes::mesh::flags& b
) {
return static_cast<shader_program::attributes::mesh::flags>(static_cast<int>(a) & static_cast<int>(b));
}
[[nodiscard]] constexpr shader_program::attributes::mesh::flags operator^(
const shader_program::attributes::mesh::flags& a, const shader_program::attributes::mesh::flags& b
) {
return static_cast<shader_program::attributes::mesh::flags>(static_cast<int>(a) ^ static_cast<int>(b));
}
[[nodiscard]] constexpr shader_program::attributes::mesh::flags operator~(const shader_program::attributes::mesh::flags& a) {
return static_cast<shader_program::attributes::mesh::flags>(~static_cast<int>(a));
}
constexpr shader_program::attributes::mesh::flags& operator|=(shader_program::attributes::mesh::flags& a, const shader_program::attributes::mesh::flags& b) {
return a = a | b;
}
constexpr shader_program::attributes::mesh::flags& operator&=(shader_program::attributes::mesh::flags& a, const shader_program::attributes::mesh::flags& b) {
return a = a & b;
}
constexpr shader_program::attributes::mesh::flags& operator^=(shader_program::attributes::mesh::flags& a, const shader_program::attributes::mesh::flags& b) {
return a = a ^ b;
}
[[nodiscard]] constexpr bool operator<(
shader_program::attributes::mesh::flags lhs, shader_program::attributes::mesh::flags rhs
) {
return static_cast<int>(lhs) < static_cast<int>(rhs);
}
[[nodiscard]] constexpr bool operator<=(
shader_program::attributes::mesh::flags lhs, shader_program::attributes::mesh::flags rhs
) {
return static_cast<int>(lhs) <= static_cast<int>(rhs);
}
[[nodiscard]] constexpr bool operator>(
shader_program::attributes::mesh::flags lhs, shader_program::attributes::mesh::flags rhs
) {
return static_cast<int>(lhs) > static_cast<int>(rhs);
}
[[nodiscard]] constexpr bool operator>=(
shader_program::attributes::mesh::flags lhs, shader_program::attributes::mesh::flags rhs
) {
return static_cast<int>(lhs) >= static_cast<int>(rhs);
}
DEFINE_ENUM_BITFIELD_OPERATORS(shader_program::attributes::mesh::flags)

View File

@@ -2,83 +2,40 @@
#include "opengl/shader_program_variable.hpp"
#include <array>
#include "util/enum_bitfield_operators.hpp"
#include <string_view>
namespace shader_program::attributes::point_cloud
{
enum class flags : int {
enum class flags : unsigned {
none = 0,
position = 1 << 0,
normal = 1 << 1,
luminance = 1 << 2,
color = 1 << 2,
reflectance = 1 << 3
alpha = 1 << 3
};
constexpr inline auto position = zgl::shader_program_variable({ GL_FLOAT_VEC3, 0 }, "vertex_position");
constexpr inline auto normal = zgl::shader_program_variable({ GL_FLOAT_VEC3, 1 }, "vertex_normal");
constexpr inline auto color = zgl::shader_program_variable({ GL_FLOAT_VEC3, 2 }, "vertex_color");
constexpr inline auto reflectance = zgl::shader_program_variable({ GL_FLOAT, 2 }, "vertex_reflectance");
constexpr inline auto position = zgl::shader_program_variable({ GL_FLOAT_VEC3, 0 }, "model_vertex_position");
constexpr inline auto normal = zgl::shader_program_variable({ GL_FLOAT_VEC3, 1 }, "model_vertex_normal");
constexpr inline auto luminance = zgl::shader_program_variable({ GL_FLOAT_VEC3, 1 }, "model_vertex_l");
constexpr inline auto color = zgl::shader_program_variable({ GL_FLOAT_VEC3, 1 }, "model_vertex_rgb");
constexpr inline auto alpha = zgl::shader_program_variable({ GL_FLOAT_VEC3, 1 }, "model_vertex_a");
constexpr inline auto all = std::array{
position, normal, color, reflectance
position, normal, luminance, color, alpha
};
constexpr inline auto names = std::array<std::string_view, 5>{
"position",
"normal",
"luminance",
"color",
"alpha"
};
}
[[nodiscard]] constexpr shader_program::attributes::point_cloud::flags operator|(
const shader_program::attributes::point_cloud::flags& a, const shader_program::attributes::point_cloud::flags& b
) {
return static_cast<shader_program::attributes::point_cloud::flags>(static_cast<int>(a) | static_cast<int>(b));
}
[[nodiscard]] constexpr shader_program::attributes::point_cloud::flags operator&(
const shader_program::attributes::point_cloud::flags& a, const shader_program::attributes::point_cloud::flags& b
) {
return static_cast<shader_program::attributes::point_cloud::flags>(static_cast<int>(a) & static_cast<int>(b));
}
[[nodiscard]] constexpr shader_program::attributes::point_cloud::flags operator^(
const shader_program::attributes::point_cloud::flags& a, const shader_program::attributes::point_cloud::flags& b
) {
return static_cast<shader_program::attributes::point_cloud::flags>(static_cast<int>(a) ^ static_cast<int>(b));
}
[[nodiscard]] constexpr shader_program::attributes::point_cloud::flags operator~(const shader_program::attributes::point_cloud::flags& a) {
return static_cast<shader_program::attributes::point_cloud::flags>(~static_cast<int>(a));
}
constexpr shader_program::attributes::point_cloud::flags& operator|=(shader_program::attributes::point_cloud::flags& a, const shader_program::attributes::point_cloud::flags& b) {
return a = a | b;
}
constexpr shader_program::attributes::point_cloud::flags& operator&=(shader_program::attributes::point_cloud::flags& a, const shader_program::attributes::point_cloud::flags& b) {
return a = a & b;
}
constexpr shader_program::attributes::point_cloud::flags& operator^=(shader_program::attributes::point_cloud::flags& a, const shader_program::attributes::point_cloud::flags& b) {
return a = a ^ b;
}
[[nodiscard]] constexpr bool operator<(
shader_program::attributes::point_cloud::flags lhs, shader_program::attributes::point_cloud::flags rhs
) {
return static_cast<int>(lhs) < static_cast<int>(rhs);
}
[[nodiscard]] constexpr bool operator<=(
shader_program::attributes::point_cloud::flags lhs, shader_program::attributes::point_cloud::flags rhs
) {
return static_cast<int>(lhs) <= static_cast<int>(rhs);
}
[[nodiscard]] constexpr bool operator>(
shader_program::attributes::point_cloud::flags lhs, shader_program::attributes::point_cloud::flags rhs
) {
return static_cast<int>(lhs) > static_cast<int>(rhs);
}
[[nodiscard]] constexpr bool operator>=(
shader_program::attributes::point_cloud::flags lhs, shader_program::attributes::point_cloud::flags rhs
) {
return static_cast<int>(lhs) >= static_cast<int>(rhs);
}
DEFINE_ENUM_BITFIELD_OPERATORS(shader_program::attributes::point_cloud::flags)

View File

@@ -1,85 +0,0 @@
#pragma once
#include "assets/components/mesh_vertex_components.hpp"
#include "assets/components/point_cloud_vertex_components.hpp"
#include "assets/components/material_components.hpp"
#include "shader_program/attributes/mesh_attributes.hpp"
#include "shader_program/uniforms/mesh_uniforms.hpp"
namespace shader_program::capabilities::mesh
{
struct type
{
attributes::mesh::flags attributes{
attributes::mesh::flags::none
};
uniforms::mesh::flags uniforms{
uniforms::mesh::flags::none
};
};
namespace indices
{
using type = ztu::u8;
constexpr inline type position = 0;
constexpr inline type lit = 1;
constexpr inline type textured = 2;
constexpr inline type uniform_color = 3;
constexpr inline type uniform_alpha = 4;
constexpr inline type point = 5;
}
enum class flags : int
{
none = 0,
position = 1 << indices::position,
lit = 1 << indices::lit,
textured = 1 << indices::textured,
uniform_color = 1 << indices::uniform_color,
uniform_alpha = 1 << indices::uniform_alpha,
point = 1 << indices::point
};
constexpr inline auto position = type{
.attributes = attributes::mesh::flags::position,
.uniforms = uniforms::mesh::flags::mvp
};
constexpr inline auto lit = type{
.attributes = attributes::mesh::flags::normal,
.uniforms = (
uniforms::mesh::flags::model_matrix |
uniforms::mesh::flags::view_pos |
uniforms::mesh::flags::point_light_direction |
uniforms::mesh::flags::point_light_color |
uniforms::mesh::flags::ambient_light_color |
uniforms::mesh::flags::ambient_filter |
uniforms::mesh::flags::diffuse_filter |
uniforms::mesh::flags::specular_filter |
uniforms::mesh::flags::shininess
)
};
constexpr inline auto point = type{
.uniforms = uniforms::mesh::flags::point_size
};
constexpr inline auto textured = type{
.attributes = attributes::mesh::flags::tex_coord,
.uniforms = uniforms::mesh::flags::tex
};
constexpr inline auto uniform_color = type{
.uniforms = uniforms::mesh::flags::color
};
constexpr inline auto uniform_alpha = type{
.uniforms = uniforms::mesh::flags::alpha
};
constexpr inline auto all = std::array{
position, lit, textured, uniform_color, uniform_alpha, point
};
}

View File

@@ -1,77 +0,0 @@
#pragma once
#include "shader_program/attributes/point_cloud_attributes.hpp"
#include "shader_program/uniforms/point_cloud_uniforms.hpp"
#include "assets/components/mesh_vertex_components.hpp"
#include "assets/components/point_cloud_vertex_components.hpp"
#include <array>
namespace shader_program::capabilities::point_cloud
{
struct type
{
attributes::point_cloud::flags attributes{
attributes::point_cloud::flags::none
};
uniforms::point_cloud::flags uniforms{
uniforms::point_cloud::flags::none
};
};
namespace indices
{
using type = ztu::u8;
constexpr inline type position = 0;
constexpr inline type vertex_color = 1;
constexpr inline type uniform_color = 2;
constexpr inline type normal = 3;
constexpr inline type reflectance = 4;
constexpr inline type rainbow = 5;
}
enum class flags : int
{
none = 0,
position = 1 << indices::position,
vertex_color = 1 << indices::vertex_color,
uniform_color = 1 << indices::uniform_color,
normal = 1 << indices::normal,
reflectance = 1 << indices::reflectance,
rainbow = 1 << indices::rainbow
};
constexpr inline auto position = type{
.attributes = attributes::point_cloud::flags::position,
.uniforms = uniforms::point_cloud::flags::mvp
};
constexpr inline auto rainbow = type{};
constexpr inline auto vertex_color = type{
.attributes = attributes::point_cloud::flags::color
};
constexpr inline auto uniform_color = type{
.uniforms = uniforms::point_cloud::flags::color
};
constexpr inline auto normal = type{
.attributes = attributes::point_cloud::flags::normal,
.uniforms = (
uniforms::point_cloud::flags::model |
uniforms::point_cloud::flags::camera_position
)
};
constexpr inline auto reflectance = type{
.attributes = attributes::point_cloud::flags::reflectance
};
constexpr inline auto all = std::array{
position, vertex_color, uniform_color, normal, reflectance, rainbow
};
}

View File

@@ -0,0 +1,134 @@
#pragma once
#include "assets/components/mesh_vertex_components.hpp"
#include "assets/components/point_cloud_vertex_components.hpp"
#include "assets/components/material_components.hpp"
#include "shader_program/attributes/mesh_attributes.hpp"
#include "shader_program/uniforms/mesh_uniforms.hpp"
#include <array>
#include <string_view>
namespace shader_program::features::mesh
{
struct type
{
attributes::mesh::flags attributes{
attributes::mesh::flags::none
};
uniforms::mesh::flags uniforms{
uniforms::mesh::flags::none
};
};
namespace indices
{
using type = ztu::u8;
constexpr inline type face = 0;
constexpr inline type line = 1;
constexpr inline type point = 2;
constexpr inline type luminance = 3;
constexpr inline type color = 4;
constexpr inline type alpha = 5;
constexpr inline type lighting = 6;
constexpr inline type texture = 7;
constexpr inline type uniform_color = 8;
}
enum class flags : unsigned
{
none = 0,
face = 1 << indices::face,
line = 1 << indices::line,
point = 1 << indices::point,
luminance = 1 << indices::luminance,
color = 1 << indices::color,
alpha = 1 << indices::alpha,
lighting = 1 << indices::lighting,
texture = 1 << indices::texture,
uniform_color = 1 << indices::uniform_color,
};
constexpr inline auto face = type{
.attributes = attributes::mesh::flags::position,
.uniforms = uniforms::mesh::flags::mvp_matrix
};
constexpr inline auto line = type{
.attributes = attributes::mesh::flags::position,
.uniforms = uniforms::mesh::flags::mvp_matrix
};
constexpr inline auto point = type{
.attributes = attributes::mesh::flags::position,
.uniforms = (
uniforms::mesh::flags::mvp_matrix |
uniforms::mesh::flags::point_size
)
};
constexpr inline auto luminance = type{
.attributes = attributes::mesh::flags::luminance
};
constexpr inline auto color = type{
.attributes = attributes::mesh::flags::color
};
constexpr inline auto alpha = type{
.attributes = attributes::mesh::flags::alpha
};
constexpr inline auto lighting = type{
.attributes = attributes::mesh::flags::normal,
.uniforms = (
uniforms::mesh::flags::model_matrix |
uniforms::mesh::flags::view_pos |
uniforms::mesh::flags::point_light_direction |
uniforms::mesh::flags::point_light_color |
uniforms::mesh::flags::ambient_light_color |
uniforms::mesh::flags::ambient_filter |
uniforms::mesh::flags::diffuse_filter |
uniforms::mesh::flags::specular_filter |
uniforms::mesh::flags::shininess
)
};
constexpr inline auto texture = type{
.attributes = attributes::mesh::flags::tex_coord,
.uniforms = uniforms::mesh::flags::tex
};
constexpr inline auto uniform_color = type{
.uniforms = uniforms::mesh::flags::color
};
constexpr inline auto all = std::array{
face, line, point, luminance, color, alpha, lighting, texture, uniform_color
};
constexpr inline auto names = std::array<std::string_view, 9>{
"face",
"line",
"point",
"luminance",
"color",
"alpha",
"lighting",
"texture",
"uniform_color"
};
constexpr inline auto defines = std::array<std::string_view, 9>{
"FACE",
"LINE",
"POINT",
"V_L",
"V_RGB",
"V_A",
"LIGHTING",
"TEXTURE",
"U_RGBA"
};
}

View File

@@ -0,0 +1,112 @@
#pragma once
#include "shader_program/attributes/point_cloud_attributes.hpp"
#include "shader_program/uniforms/point_cloud_uniforms.hpp"
#include "assets/components/mesh_vertex_components.hpp"
#include "assets/components/point_cloud_vertex_components.hpp"
#include <array>
namespace shader_program::features::point_cloud
{
struct type
{
attributes::point_cloud::flags attributes{
attributes::point_cloud::flags::none
};
uniforms::point_cloud::flags uniforms{
uniforms::point_cloud::flags::none
};
};
namespace indices
{
using type = ztu::u8;
constexpr inline type square = 0;
constexpr inline type lighting = 1;
constexpr inline type luminance = 2;
constexpr inline type color = 3;
constexpr inline type alpha = 4;
constexpr inline type uniform_color = 5;
constexpr inline type rainbow = 6;
}
enum class flags : unsigned
{
none = 0,
square = 1 << indices::square,
lighting = 1 << indices::lighting,
luminance = 1 << indices::luminance,
color = 1 << indices::color,
alpha = 1 << indices::alpha,
uniform_color = 1 << indices::uniform_color,
rainbow = 1 << indices::rainbow
};
constexpr inline auto square = type{
.attributes = attributes::point_cloud::flags::position,
.uniforms = (
uniforms::point_cloud::flags::mvp_matrix |
uniforms::point_cloud::flags::point_size
)
};
constexpr inline auto lighting = type{
.attributes = attributes::point_cloud::flags::normal,
.uniforms = (
uniforms::point_cloud::flags::model_matrix |
uniforms::point_cloud::flags::camera_position
)
};
constexpr inline auto luminance = type{
.attributes = attributes::point_cloud::flags::luminance
};
constexpr inline auto color = type{
.attributes = attributes::point_cloud::flags::color
};
constexpr inline auto alpha = type{
.attributes = attributes::point_cloud::flags::alpha
};
constexpr inline auto uniform_color = type{
.uniforms = uniforms::point_cloud::flags::color
};
constexpr inline auto rainbow = type{
.uniforms = (
uniforms::point_cloud::flags::rainbow_offset_y |
uniforms::point_cloud::flags::rainbow_scale_y
)
};
constexpr inline auto all = std::array{
square, lighting, luminance, color, alpha, uniform_color, rainbow
};
constexpr inline auto names = std::array{
"square",
"lighting",
"luminance",
"color",
"alpha",
"uniform_color",
"rainbow"
};
constexpr inline auto defines = std::array{
"SQUARE",
"LIGHTING",
"V_L",
"V_RGB",
"V_A",
"U_RGBA",
"RAINBOW"
};
}

View File

@@ -0,0 +1,219 @@
#pragma once
#include <limits>
#include <utility>
#include "features/mesh_features.hpp"
#include "features/point_cloud_features.hpp"
namespace shader_program
{
enum class geometries : int
{
mesh = 0,
point_cloud = 1
};
enum class stages : GLenum
{
vertex = GL_VERTEX_SHADER,
geometry = GL_GEOMETRY_SHADER,
fragment = GL_FRAGMENT_SHADER
};
union combined_feature_type
{
features::mesh::flags mesh;
features::point_cloud::flags point_cloud;
using generic_type = std::common_type_t<
std::underlying_type_t<features::mesh::flags>,
std::underlying_type_t<features::point_cloud::flags>
>;
generic_type generic(const geometries geometry) const noexcept
{
switch (geometry)
{
case geometries::mesh:
return static_cast<generic_type>(mesh);
case geometries::point_cloud:
return static_cast<generic_type>(point_cloud);
}
std::unreachable();
}
void from_generic(
const geometries geometry,
generic_type new_features
) noexcept {
switch (geometry)
{
case geometries::mesh:
mesh = static_cast<features::mesh::flags>(new_features);
case geometries::point_cloud:
point_cloud = static_cast<features::point_cloud::flags>(new_features);
}
std::unreachable();
}
};
struct metadata_type
{
geometries geometry;
stages stage;
combined_feature_type features;
combined_feature_type feature_toggles;
std::pair<combined_feature_type::generic_type, combined_feature_type::generic_type> generic() const noexcept
{
switch (geometry)
{
case geometries::mesh:
return {
static_cast<combined_feature_type::generic_type>(features.mesh),
static_cast<combined_feature_type::generic_type>(feature_toggles.mesh)
};
case geometries::point_cloud:
return {
static_cast<combined_feature_type::generic_type>(features.point_cloud),
static_cast<combined_feature_type::generic_type>(feature_toggles.point_cloud)
};
}
std::unreachable();
}
void from_generic(
combined_feature_type::generic_type new_features,
combined_feature_type::generic_type new_feature_toggles
) noexcept {
switch (geometry)
{
case geometries::mesh:
features.mesh = static_cast<features::mesh::flags>(new_features);
feature_toggles.mesh = static_cast<features::mesh::flags>(new_feature_toggles);
case geometries::point_cloud:
features.point_cloud = static_cast<features::point_cloud::flags>(new_features);
feature_toggles.point_cloud = static_cast<features::point_cloud::flags>(new_feature_toggles);
}
std::unreachable();
}
auto operator<=>(const metadata_type& other) const noexcept
{
if (this->geometry == other.geometry)
{
switch (this->geometry)
{
case geometries::mesh:
return (
std::tie(this->stage, this->features.mesh, this->feature_toggles.mesh) <=>
std::tie(other.stage, other.features.mesh, other.feature_toggles.mesh)
);
case geometries::point_cloud:
return (
std::tie(this->stage, this->features.point_cloud, this->feature_toggles.point_cloud) <=>
std::tie(other.stage, other.features.point_cloud, other.feature_toggles.point_cloud)
);
}
std::unreachable();
}
else
{
return this->geometry <=> other.geometry;
}
}
bool operator==(const metadata_type& other) const noexcept
{
if (this->geometry == other.geometry)
{
switch (this->geometry)
{
case geometries::mesh:
return (
std::tie(this->stage, this->features.mesh, this->feature_toggles.mesh) ==
std::tie(other.stage, other.features.mesh, other.feature_toggles.mesh)
);
case geometries::point_cloud:
return (
std::tie(this->stage, this->features.point_cloud, this->feature_toggles.point_cloud) ==
std::tie(other.stage, other.features.point_cloud, other.feature_toggles.point_cloud)
);
}
std::unreachable();
}
return false;
}
struct feature_ignorant_less
{
bool operator()(const metadata_type& a, const metadata_type& b) const
{
return (
std::tie(a.geometry, a.stage) <
std::tie(a.geometry, b.stage)
);
}
};
struct feature_count_less
{
bool operator()(const metadata_type& a, const metadata_type& b) const
{
if (a.geometry == b.geometry)
{
int feature_count{}, feature_toggle_count{};
int other_feature_count{}, other_feature_toggle_count{};
constexpr auto count_features = []<typename T>(const T features)
{
using int_type = std::underlying_type_t<T>;
using uint_type = std::make_unsigned_t<int_type>;
return std::popcount(static_cast<uint_type>(static_cast<int_type>(features)));
};
switch (a.geometry)
{
case geometries::mesh:
for (auto& [ count, features ] : {
std::tie(feature_count, a.features.mesh),
std::tie(feature_toggle_count, a.feature_toggles.mesh),
std::tie(other_feature_count, b.features.mesh),
std::tie(other_feature_toggle_count, b.feature_toggles.mesh)
}) {
count = count_features(features);
}
case geometries::point_cloud:
for (auto& [ count, features ] : {
std::tie(feature_count, a.features.point_cloud),
std::tie(feature_toggle_count, a.feature_toggles.point_cloud),
std::tie(other_feature_count, b.features.point_cloud),
std::tie(other_feature_toggle_count, b.feature_toggles.point_cloud)
}) {
count = count_features(features);
}
default:
std::unreachable();
}
return (
std::tie(a.stage, feature_count, feature_toggle_count) <
std::tie(b.stage, other_feature_count, other_feature_toggle_count)
);
}
else
{
return a.geometry < b.geometry;
}
}
};
};
}

View File

@@ -2,14 +2,15 @@
#include "opengl/shader_program_variable.hpp"
#include <array>
#include "util/enum_bitfield_operators.hpp"
namespace shader_program::uniforms::mesh
{
enum class flags : int
enum class flags : unsigned
{
none = 0,
mvp = 1 << 0,
mvp_matrix = 1 << 0,
model_matrix = 1 << 1,
point_size = 1 << 2,
color = 1 << 3,
@@ -21,27 +22,25 @@ enum class flags : int
ambient_filter = 1 << 9,
diffuse_filter = 1 << 10,
specular_filter = 1 << 11,
shininess = 1 << 12,
alpha = 1 << 13
shininess = 1 << 12
};
constexpr inline auto mvp = zgl::shader_program_variable({ GL_FLOAT_MAT4, 0 }, "mvp_matrix");
constexpr inline auto mvp_matrix = zgl::shader_program_variable({ GL_FLOAT_MAT4, 0 }, "mvp_matrix");
constexpr inline auto model_matrix = zgl::shader_program_variable({ GL_FLOAT_MAT4, 1 }, "model_matrix");
constexpr inline auto point_size = zgl::shader_program_variable({ GL_FLOAT, 2 }, "point_size");
constexpr inline auto color = zgl::shader_program_variable({ GL_FLOAT_VEC4, 3 }, "color");
constexpr inline auto tex = zgl::shader_program_variable({ GL_SAMPLER_2D, 3 }, "tex");
constexpr inline auto view_pos = zgl::shader_program_variable({ GL_FLOAT_VEC3, 4 }, "view_pos");
constexpr inline auto point_light_direction = zgl::shader_program_variable({ GL_FLOAT_VEC3, 5 }, "point_light_direction");
constexpr inline auto point_light_color = zgl::shader_program_variable({ GL_FLOAT_VEC3, 6 }, "point_light_color");
constexpr inline auto ambient_light_color = zgl::shader_program_variable({ GL_FLOAT_VEC3, 7 }, "ambient_light_color");
constexpr inline auto ambient_filter = zgl::shader_program_variable({ GL_FLOAT_VEC3, 8 }, "ambient_filter");
constexpr inline auto diffuse_filter = zgl::shader_program_variable({ GL_FLOAT_VEC3, 9 }, "diffuse_filter");
constexpr inline auto specular_filter = zgl::shader_program_variable({ GL_FLOAT_VEC3, 10 }, "specular_filter");
constexpr inline auto shininess = zgl::shader_program_variable({ GL_FLOAT, 11 }, "shininess");
constexpr inline auto alpha = zgl::shader_program_variable({ GL_FLOAT, 12 }, "alpha");
constexpr inline auto color = zgl::shader_program_variable({ GL_FLOAT_VEC4, 4 }, "color");
constexpr inline auto view_pos = zgl::shader_program_variable({ GL_FLOAT_VEC3, 5 }, "view_pos");
constexpr inline auto point_light_direction = zgl::shader_program_variable({ GL_FLOAT_VEC3, 6 }, "point_light_direction");
constexpr inline auto point_light_color = zgl::shader_program_variable({ GL_FLOAT_VEC3, 7 }, "point_light_color");
constexpr inline auto ambient_light_color = zgl::shader_program_variable({ GL_FLOAT_VEC3, 8 }, "ambient_light_color");
constexpr inline auto ambient_filter = zgl::shader_program_variable({ GL_FLOAT_VEC3, 9 }, "ambient_filter");
constexpr inline auto diffuse_filter = zgl::shader_program_variable({ GL_FLOAT_VEC3, 10 }, "diffuse_filter");
constexpr inline auto specular_filter = zgl::shader_program_variable({ GL_FLOAT_VEC3, 11 }, "specular_filter");
constexpr inline auto shininess = zgl::shader_program_variable({ GL_FLOAT, 12 }, "shininess");
constexpr inline auto all = std::array{
mvp,
mvp_matrix,
model_matrix,
point_size,
color,
@@ -53,65 +52,24 @@ constexpr inline auto all = std::array{
ambient_filter,
diffuse_filter,
specular_filter,
shininess,
alpha
shininess
};
constexpr inline auto names = std::array{
"mvp_matrix",
"model_matrix",
"point_size",
"color",
"tex",
"view_pos",
"point_light_direction",
"point_light_color",
"ambient_light_color",
"ambient_filter",
"diffuse_filter",
"specular_filter",
"shininess"
};
}
[[nodiscard]] constexpr shader_program::uniforms::mesh::flags operator|(
const shader_program::uniforms::mesh::flags& a, const shader_program::uniforms::mesh::flags& b
) {
return static_cast<shader_program::uniforms::mesh::flags>(static_cast<int>(a) | static_cast<int>(b));
}
[[nodiscard]] constexpr shader_program::uniforms::mesh::flags operator&(
const shader_program::uniforms::mesh::flags& a, const shader_program::uniforms::mesh::flags& b
) {
return static_cast<shader_program::uniforms::mesh::flags>(static_cast<int>(a) & static_cast<int>(b));
}
[[nodiscard]] constexpr shader_program::uniforms::mesh::flags operator^(
const shader_program::uniforms::mesh::flags& a, const shader_program::uniforms::mesh::flags& b
) {
return static_cast<shader_program::uniforms::mesh::flags>(static_cast<int>(a) ^ static_cast<int>(b));
}
[[nodiscard]] constexpr shader_program::uniforms::mesh::flags operator~(const shader_program::uniforms::mesh::flags& a) {
return static_cast<shader_program::uniforms::mesh::flags>(~static_cast<int>(a));
}
constexpr shader_program::uniforms::mesh::flags& operator|=(shader_program::uniforms::mesh::flags& a, const shader_program::uniforms::mesh::flags& b) {
return a = a | b;
}
constexpr shader_program::uniforms::mesh::flags& operator&=(shader_program::uniforms::mesh::flags& a, const shader_program::uniforms::mesh::flags& b) {
return a = a & b;
}
constexpr shader_program::uniforms::mesh::flags& operator^=(shader_program::uniforms::mesh::flags& a, const shader_program::uniforms::mesh::flags& b) {
return a = a ^ b;
}
[[nodiscard]] constexpr bool operator<(
shader_program::uniforms::mesh::flags lhs, shader_program::uniforms::mesh::flags rhs
) {
return static_cast<int>(lhs) < static_cast<int>(rhs);
}
[[nodiscard]] constexpr bool operator<=(
shader_program::uniforms::mesh::flags lhs, shader_program::uniforms::mesh::flags rhs
) {
return static_cast<int>(lhs) <= static_cast<int>(rhs);
}
[[nodiscard]] constexpr bool operator>(
shader_program::uniforms::mesh::flags lhs, shader_program::uniforms::mesh::flags rhs
) {
return static_cast<int>(lhs) > static_cast<int>(rhs);
}
[[nodiscard]] constexpr bool operator>=(
shader_program::uniforms::mesh::flags lhs, shader_program::uniforms::mesh::flags rhs
) {
return static_cast<int>(lhs) >= static_cast<int>(rhs);
}
DEFINE_ENUM_BITFIELD_OPERATORS(shader_program::uniforms::mesh::flags)

View File

@@ -6,92 +6,46 @@
namespace shader_program::uniforms::point_cloud
{
enum class flags : int
enum class flags : unsigned
{
none = 0,
mvp = 1 << 0,
mvp_matrix = 1 << 0,
point_size = 1 << 1,
color = 1 << 2,
model = 1 << 3,
model_matrix = 1 << 3,
camera_position = 1 << 4,
rainbow_offset_y = 1 << 5,
rainbow_scale_y = 1 << 6,
rainbow_scale_y = 1 << 6
};
constexpr inline auto mvp = zgl::shader_program_variable({ GL_FLOAT_MAT4, 0 }, "mvp");
constexpr inline auto point_size = zgl::shader_program_variable({ GL_FLOAT, 2 }, "point_size");
constexpr inline auto color = zgl::shader_program_variable({ GL_FLOAT_VEC4, 3 }, "color");
constexpr inline auto model = zgl::shader_program_variable({ GL_FLOAT_MAT4, 4 }, "model");
constexpr inline auto camera_position = zgl::shader_program_variable({ GL_FLOAT_VEC3, 5 }, "camera_position");
constexpr inline auto rainbow_offset_y = zgl::shader_program_variable({ GL_FLOAT, 6 }, "rainbow_offset_y");
constexpr inline auto rainbow_scale_y = zgl::shader_program_variable({ GL_FLOAT, 7 }, "rainbow_scale_y");
constexpr inline auto mvp_matrix = zgl::shader_program_variable({ GL_FLOAT_MAT4, 0 }, "mvp_matrix");
constexpr inline auto point_size = zgl::shader_program_variable({ GL_FLOAT, 1 }, "point_size");
constexpr inline auto color = zgl::shader_program_variable({ GL_FLOAT_VEC4, 2 }, "color");
constexpr inline auto model_matrix = zgl::shader_program_variable({ GL_FLOAT_MAT4, 3 }, "model_matrix");
constexpr inline auto camera_position = zgl::shader_program_variable({ GL_FLOAT_VEC3, 4 }, "camera_position");
constexpr inline auto rainbow_offset_y = zgl::shader_program_variable({ GL_FLOAT, 5 }, "rainbow_offset_y");
constexpr inline auto rainbow_scale_y = zgl::shader_program_variable({ GL_FLOAT, 6 }, "rainbow_scale_y");
constexpr inline auto all = std::array{
mvp,
mvp_matrix,
point_size,
color,
model,
model_matrix,
camera_position,
rainbow_offset_y,
rainbow_scale_y
};
constexpr inline auto names = std::array{
"mvp_matrix",
"point_size",
"color",
"model_matrix",
"camera_position",
"rainbow_offset_y",
"rainbow_scale_y"
};
}
[[nodiscard]] constexpr shader_program::uniforms::point_cloud::flags operator|(
const shader_program::uniforms::point_cloud::flags& a, const shader_program::uniforms::point_cloud::flags& b
) {
return static_cast<shader_program::uniforms::point_cloud::flags>(static_cast<int>(a) | static_cast<int>(b));
}
[[nodiscard]] constexpr shader_program::uniforms::point_cloud::flags operator&(
const shader_program::uniforms::point_cloud::flags& a, const shader_program::uniforms::point_cloud::flags& b
) {
return static_cast<shader_program::uniforms::point_cloud::flags>(static_cast<int>(a) & static_cast<int>(b));
}
[[nodiscard]] constexpr shader_program::uniforms::point_cloud::flags operator^(
const shader_program::uniforms::point_cloud::flags& a, const shader_program::uniforms::point_cloud::flags& b
) {
return static_cast<shader_program::uniforms::point_cloud::flags>(static_cast<int>(a) ^ static_cast<int>(b));
}
[[nodiscard]] constexpr shader_program::uniforms::point_cloud::flags operator~(const shader_program::uniforms::point_cloud::flags& a) {
return static_cast<shader_program::uniforms::point_cloud::flags>(~static_cast<int>(a));
}
constexpr shader_program::uniforms::point_cloud::flags& operator|=(shader_program::uniforms::point_cloud::flags& a, const shader_program::uniforms::point_cloud::flags& b) {
return a = a | b;
}
constexpr shader_program::uniforms::point_cloud::flags& operator&=(shader_program::uniforms::point_cloud::flags& a, const shader_program::uniforms::point_cloud::flags& b) {
return a = a & b;
}
constexpr shader_program::uniforms::point_cloud::flags& operator^=(shader_program::uniforms::point_cloud::flags& a, const shader_program::uniforms::point_cloud::flags& b) {
return a = a ^ b;
}
[[nodiscard]] constexpr bool operator<(
shader_program::uniforms::point_cloud::flags lhs, shader_program::uniforms::point_cloud::flags rhs
) {
return static_cast<int>(lhs) < static_cast<int>(rhs);
}
[[nodiscard]] constexpr bool operator<=(
shader_program::uniforms::point_cloud::flags lhs, shader_program::uniforms::point_cloud::flags rhs
) {
return static_cast<int>(lhs) <= static_cast<int>(rhs);
}
[[nodiscard]] constexpr bool operator>(
shader_program::uniforms::point_cloud::flags lhs, shader_program::uniforms::point_cloud::flags rhs
) {
return static_cast<int>(lhs) > static_cast<int>(rhs);
}
[[nodiscard]] constexpr bool operator>=(
shader_program::uniforms::point_cloud::flags lhs, shader_program::uniforms::point_cloud::flags rhs
) {
return static_cast<int>(lhs) >= static_cast<int>(rhs);
}
DEFINE_ENUM_BITFIELD_OPERATORS(shader_program::uniforms::point_cloud::flags)