GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
shaders.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Ivar Härnqvist
2// SPDX-License-Identifier: MIT
3
4#ifndef GREM_GRAPHICS_SHADERS_HPP
5#define GREM_GRAPHICS_SHADERS_HPP
6
8
28
29#include <type_traits> // std::is_empty_v, std::remove_cvref_t, std::bool_constant, std::false_type, std::true_type
30#include <typeindex> // std::type_index
31#include <typeinfo> // IWYU pragma: keep // typeid
32#include <utility> // std::move
33#include <vector> // std::vector
34
35namespace grem {
36
37class Filesystem; // Forward declaration, to avoid including Filesystem.hpp.
38
39} // namespace grem
40
41namespace grem::graphics {
42
43class Device; // Forward declaration, to avoid including Device.hpp.
44class RenderPass; // Forward declaration, to avoid a circular include of RenderPass.hpp.
45
46struct VertexShaderImplementation;
47struct FragmentShaderImplementation;
48struct ShaderPipelineImplementation;
49
86
139
145enum class StencilBufferMode : uint8_t {
150
159};
160
231
283
290enum class PrimitiveType : uint8_t {
291 POINTS = 0,
292 LINES = 1,
293 // Note: LINE_LOOP is intentionally omitted since Vulkan does not support it.
297};
298
304enum class PolygonMode : uint8_t {
308};
309
337
343enum class FrontFace : uint8_t {
346};
347
370
383
410
412 .sourceColorBlendFactor = BlendFactor::SOURCE_ALPHA,
413 .destinationColorBlendFactor = BlendFactor::ONE_MINUS_SOURCE_ALPHA,
414 .sourceAlphaBlendFactor = BlendFactor::ONE,
415 .destinationAlphaBlendFactor = BlendFactor::ONE_MINUS_SOURCE_ALPHA,
416};
417
418inline constexpr BlendState BlendState::ALPHA_BLENDING_PREMULTIPLIED{
419 .sourceColorBlendFactor = BlendFactor::ONE,
420 .destinationColorBlendFactor = BlendFactor::ONE_MINUS_SOURCE_ALPHA,
421 .sourceAlphaBlendFactor = BlendFactor::ONE,
422 .destinationAlphaBlendFactor = BlendFactor::ONE_MINUS_SOURCE_ALPHA,
423};
424
435
442
460
472
485
501
514
527
540
552
565
581
594
607
620
625
630
641
648
653
660
667
675 [[nodiscard]] constexpr bool operator==(const ShaderPipelineOptions& other) const noexcept = default;
676};
677
685 bool optimize = true;
686};
687
708
729
730namespace detail {
731
732class VertexShaderBase {
733public:
742 [[nodiscard]] SharedPointer<VertexShaderImplementation> lock() const noexcept {
743 return implementation;
744 }
745
754 [[nodiscard]] VertexShaderImplementation* get() noexcept { // NOLINT(readability-make-member-function-const)
755 return implementation.get();
756 }
757
766 [[nodiscard]] const VertexShaderImplementation* get() const noexcept {
767 return implementation.get();
768 }
769
770protected:
771 [[nodiscard]] GREM_API(graphics) static std::vector<uint32_t> compileGLSLToVulkanSPIRVImplementation(CStringView sourceCode, const Filesystem* filesystem, CStringView filepath,
772 const ShaderCompilationOptions& compilationOptions, Span<const ConstantDescription> constantDescriptions,
773 Span<const VertexAttributeDescription> vertexAttributeDescriptions, Span<const ParameterDescription> parameterDescriptions,
774 Span<const FieldDescription> instanceAttributeDescriptions, Span<const FieldDescription> outputFieldDescriptions, Span<const BufferLayoutReference> bufferLayouts);
775
776 GREM_API(graphics)
777 VertexShaderBase(Device& device, CStringView sourceCode, const Filesystem* filesystem, CStringView filepath, Span<const ConstantDescription> constantDescriptions,
778 std::type_index meshTypeIndex, Span<const VertexAttributeDescription> vertexAttributeDescriptions, Optional<MeshIndexType> indexType,
779 Span<const ParameterDescription> parameterDescriptions, Span<const FieldDescription> instanceAttributeDescriptions, uint32_t instanceStride,
780 Span<const FieldDescription> outputFieldDescriptions, Span<const BufferLayoutReference> bufferLayouts);
781
782 GREM_API(graphics)
783 VertexShaderBase(Device& device, Span<const uint32_t> code, Span<const ConstantDescription> constantDescriptions, std::type_index meshTypeIndex,
784 Span<const VertexAttributeDescription> vertexAttributeDescriptions, Optional<MeshIndexType> indexType, Span<const ParameterDescription> parameterDescriptions,
785 Span<const FieldDescription> instanceAttributeDescriptions, uint32_t instanceStride, Span<const FieldDescription> outputFieldDescriptions,
787
788 GREM_API(graphics)
789 VertexShaderBase(Device& device, const Filesystem& filesystem, CStringView filepath, const VertexShaderOptions& options, Span<const ConstantDescription> constantDescriptions,
790 std::type_index meshTypeIndex, Span<const VertexAttributeDescription> vertexAttributeDescriptions, Optional<MeshIndexType> indexType,
791 Span<const ParameterDescription> parameterDescriptions, Span<const FieldDescription> instanceAttributeDescriptions, uint32_t instanceStride,
792 Span<const FieldDescription> outputFieldDescriptions, Span<const BufferLayoutReference> bufferLayouts);
793
794private:
795 SharedPointer<VertexShaderImplementation> implementation{};
796};
797
798class FragmentShaderBase {
799public:
808 [[nodiscard]] SharedPointer<FragmentShaderImplementation> lock() const noexcept {
809 return implementation;
810 }
811
820 [[nodiscard]] FragmentShaderImplementation* get() noexcept { // NOLINT(readability-make-member-function-const)
821 return implementation.get();
822 }
823
832 [[nodiscard]] const FragmentShaderImplementation* get() const noexcept {
833 return implementation.get();
834 }
835
836protected:
837 [[nodiscard]] GREM_API(graphics) static std::vector<uint32_t> compileGLSLToVulkanSPIRVImplementation(CStringView sourceCode, const Filesystem* filesystem, CStringView filepath,
838 const ShaderCompilationOptions& compilationOptions, Span<const ConstantDescription> constantDescriptions, Span<const ParameterDescription> parameterDescriptions,
839 Span<const FieldDescription> instanceAttributeDescriptions, Span<const FieldDescription> inputFieldDescriptions, Span<const FieldDescription> outputFieldDescriptions,
841
842 GREM_API(graphics)
843 FragmentShaderBase(Device& device, CStringView sourceCode, const Filesystem* filesystem, CStringView filepath, Span<const ConstantDescription> constantDescriptions,
844 std::type_index meshTypeIndex, Span<const VertexAttributeDescription> vertexAttributeDescriptions, Optional<MeshIndexType> indexType,
845 Span<const ParameterDescription> parameterDescriptions, Span<const FieldDescription> instanceAttributeDescriptions, uint32_t instanceStride,
846 Span<const FieldDescription> inputFieldDescriptions, Span<const FieldDescription> outputFieldDescriptions, Span<const BufferLayoutReference> bufferLayouts);
847
848 GREM_API(graphics)
849 FragmentShaderBase(Device& device, Span<const uint32_t> code, Span<const ConstantDescription> constantDescriptions, std::type_index meshTypeIndex,
850 Span<const VertexAttributeDescription> vertexAttributeDescriptions, Optional<MeshIndexType> indexType, Span<const ParameterDescription> parameterDescriptions,
851 Span<const FieldDescription> instanceAttributeDescriptions, uint32_t instanceStride, Span<const FieldDescription> inputFieldDescriptions,
852 Span<const FieldDescription> outputFieldDescriptions, Span<const BufferLayoutReference> bufferLayouts);
853
854 GREM_API(graphics)
855 FragmentShaderBase(Device& device, const Filesystem& filesystem, CStringView filepath, const FragmentShaderOptions& options,
856 Span<const ConstantDescription> constantDescriptions, std::type_index meshTypeIndex, Span<const VertexAttributeDescription> vertexAttributeDescriptions,
857 Optional<MeshIndexType> indexType, Span<const ParameterDescription> parameterDescriptions, Span<const FieldDescription> instanceAttributeDescriptions,
858 uint32_t instanceStride, Span<const FieldDescription> inputFieldDescriptions, Span<const FieldDescription> outputFieldDescriptions,
860
861private:
862 SharedPointer<FragmentShaderImplementation> implementation{};
863};
864
865class ShaderPipelineBase {
866public:
875 [[nodiscard]] SharedPointer<ShaderPipelineImplementation> lock() const noexcept {
876 return implementation;
877 }
878
887 [[nodiscard]] ShaderPipelineImplementation* get() noexcept { // NOLINT(readability-make-member-function-const)
888 return implementation.get();
889 }
890
899 [[nodiscard]] const ShaderPipelineImplementation* get() const noexcept {
900 return implementation.get();
901 }
902
903protected:
904 GREM_API(graphics)
905 ShaderPipelineBase(Device& device, std::type_index meshTypeIndex, SharedPointer<VertexShaderImplementation> vertexShaderHandle,
906 Span<const ConstantDescription> vertexShaderConstantDescriptions, Span<const byte> vertexShaderConstantData,
907 SharedPointer<FragmentShaderImplementation> fragmentShaderHandle, Span<const ConstantDescription> fragmentShaderConstantDescriptions,
908 Span<const byte> fragmentShaderConstantData, const ShaderPipelineOptions& shaderPipelineOptions);
909
910private:
911 SharedPointer<ShaderPipelineImplementation> implementation{};
912};
913
914[[nodiscard]] inline StringView getVertexAttributeTypeName(VertexAttributeType vertexAttributeType) noexcept {
915 switch (vertexAttributeType) {
916 case VertexAttributeType::U8NORM: [[fallthrough]];
917 case VertexAttributeType::I8NORM: [[fallthrough]];
918 case VertexAttributeType::U16NORM: [[fallthrough]];
919 case VertexAttributeType::I16NORM: [[fallthrough]];
920 case VertexAttributeType::F16: [[fallthrough]];
921 case VertexAttributeType::F32: return "float";
922 case VertexAttributeType::U8: [[fallthrough]];
923 case VertexAttributeType::U16: [[fallthrough]];
924 case VertexAttributeType::U32: return "uint";
925 case VertexAttributeType::I8: [[fallthrough]];
926 case VertexAttributeType::I16: [[fallthrough]];
927 case VertexAttributeType::I32: return "int";
928 case VertexAttributeType::U8VEC2NORM: [[fallthrough]];
929 case VertexAttributeType::I8VEC2NORM: [[fallthrough]];
930 case VertexAttributeType::U16VEC2NORM: [[fallthrough]];
931 case VertexAttributeType::I16VEC2NORM: [[fallthrough]];
932 case VertexAttributeType::F16VEC2: [[fallthrough]];
933 case VertexAttributeType::F32VEC2: return "vec2";
934 case VertexAttributeType::U8VEC2: [[fallthrough]];
935 case VertexAttributeType::U16VEC2: [[fallthrough]];
936 case VertexAttributeType::U32VEC2: return "uvec2";
937 case VertexAttributeType::I8VEC2: [[fallthrough]];
938 case VertexAttributeType::I16VEC2: [[fallthrough]];
939 case VertexAttributeType::I32VEC2: return "ivec2";
940 case VertexAttributeType::F32VEC3: return "vec3";
941 case VertexAttributeType::U32VEC3: return "uvec3";
942 case VertexAttributeType::I32VEC3: return "ivec3";
943 case VertexAttributeType::U8VEC4NORM: [[fallthrough]];
944 case VertexAttributeType::I8VEC4NORM: [[fallthrough]];
945 case VertexAttributeType::UA2B10G10R10VEC4NORM: [[fallthrough]];
946 case VertexAttributeType::IA2B10G10R10VEC4NORM: [[fallthrough]];
947 case VertexAttributeType::U16VEC4NORM: [[fallthrough]];
948 case VertexAttributeType::I16VEC4NORM: [[fallthrough]];
949 case VertexAttributeType::F16VEC4: [[fallthrough]];
950 case VertexAttributeType::F32VEC4: return "vec4";
951 case VertexAttributeType::U8VEC4: [[fallthrough]];
952 case VertexAttributeType::U16VEC4: [[fallthrough]];
953 case VertexAttributeType::U32VEC4: return "uvec4";
954 case VertexAttributeType::I8VEC4: [[fallthrough]];
955 case VertexAttributeType::I16VEC4: [[fallthrough]];
956 case VertexAttributeType::I32VEC4: return "ivec4";
957 }
958 return {};
959}
960
961[[nodiscard]] inline size_t getFieldAttributeCount(FieldType fieldType) noexcept {
962 switch (fieldType) {
963 case FieldType::INT: [[fallthrough]];
964 case FieldType::IVEC2: [[fallthrough]];
965 case FieldType::IVEC3: [[fallthrough]];
966 case FieldType::IVEC4: [[fallthrough]];
967 case FieldType::UINT: [[fallthrough]];
968 case FieldType::UVEC2: [[fallthrough]];
969 case FieldType::UVEC3: [[fallthrough]];
970 case FieldType::UVEC4: [[fallthrough]];
971 case FieldType::FLOAT: [[fallthrough]];
972 case FieldType::VEC2: [[fallthrough]];
973 case FieldType::VEC3: [[fallthrough]];
974 case FieldType::VEC4: return 1;
975 case FieldType::MAT2: return 2;
976 case FieldType::MAT3: return 3;
977 case FieldType::MAT4: return 4;
978 }
979 return 0;
980}
981
982[[nodiscard]] inline StringView getFieldTypeName(FieldType fieldType) noexcept {
983 switch (fieldType) {
984 case FieldType::INT: return "int";
985 case FieldType::IVEC2: return "ivec2";
986 case FieldType::IVEC3: return "ivec3";
987 case FieldType::IVEC4: return "ivec4";
988 case FieldType::UINT: return "uint";
989 case FieldType::UVEC2: return "uvec2";
990 case FieldType::UVEC3: return "uvec3";
991 case FieldType::UVEC4: return "uvec4";
992 case FieldType::FLOAT: return "float";
993 case FieldType::VEC2: return "vec2";
994 case FieldType::VEC3: return "vec3";
995 case FieldType::VEC4: return "vec4";
996 case FieldType::MAT2: return "mat2";
997 case FieldType::MAT3: return "mat3";
998 case FieldType::MAT4: return "mat4";
999 }
1000 return {};
1001}
1002
1003[[nodiscard]] inline char getVec4ComponentCharacter(size_t componentIndex) {
1004 switch (componentIndex) {
1005 case 0: return 'x';
1006 case 1: return 'y';
1007 case 2: return 'z';
1008 case 3: return 'w';
1009 }
1010 unreachable();
1011}
1012
1013[[nodiscard]] inline bool isValidNameStartCharacter(char ch) noexcept {
1014 return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z');
1015}
1016
1017[[nodiscard]] inline bool isValidNameCharacter(char ch) noexcept {
1018 return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch == '_') || (ch >= '0' && ch <= '9');
1019}
1020
1021[[nodiscard]] inline bool isValidName(CStringView name) noexcept {
1022 if (name.empty() || !isValidNameStartCharacter(name.front())) {
1023 return false;
1024 }
1025 for (const char ch : name) { // NOLINT(readability-use-anyofallof) // std::all_of doesn't support sentinels.
1026 if (!isValidNameCharacter(ch)) {
1027 return false;
1028 }
1029 }
1030 return true;
1031}
1032
1033GREM_API(graphics) void writeInputAttributeDeclarations(String& output, size_t& attributeIndex, Span<const VertexAttributeDescription> vertexAttributeDescriptions);
1034GREM_API(graphics) void writeInputAttributeDeclarations(String& output, size_t& attributeIndex, Span<const FieldDescription> fieldDescriptions);
1035
1036GREM_API(graphics)
1037void writeVec4BufferGetters(String& output, StringView getterFunctionNamePrefix, Span<const FieldDescription> fieldDescriptions,
1038 FunctionView<void(String& output, StringView nameString, StringView indexString)> writeFetchDeclaration);
1039
1040using AllocatedStringBuffer = SmallArrayList<Allocation<char>, 16>;
1041using ExpandedStringBuffer = SmallArrayList<const char*, 16>;
1042
1043[[nodiscard]] GREM_API(graphics) ExpandedStringBuffer
1044 expandIncludes(AllocatedStringBuffer& allocatedStrings, Span<const char* const> sourceStrings, const Filesystem* filesystem, CStringView filepath);
1045
1046} // namespace detail
1047
1059template <typename Mesh, typename Constants, typename Outputs, typename... Buffers>
1061
1062template <typename Vertex, typename Index, typename Parameters, typename Instance, typename Constants, typename Outputs, typename... Buffers>
1063class VertexShader<graphics::Mesh<Vertex, Index, Parameters, Instance>, Constants, Outputs, Buffers...> : public detail::VertexShaderBase {
1064public:
1065 static_assert(shader_constant_struct<Constants>);
1066 static_assert(field_struct<Outputs>);
1067
1070
1072 using constants_type = Constants;
1073
1075 using outputs_type = Outputs;
1076
1078 using buffer_types = meta::TypeList<Buffers...>;
1079
1100 [[nodiscard]] static std::vector<uint32_t> compileGLSLToVulkanSPIRV(CStringView sourceCode, const ShaderCompilationOptions& compilationOptions = {}) {
1101 return detail::VertexShaderBase::compileGLSLToVulkanSPIRVImplementation(sourceCode, nullptr, {}, compilationOptions, detail::CONSTANT_DESCRIPTIONS<Constants>,
1102 detail::VERTEX_ATTRIBUTE_DESCRIPTIONS<Vertex>, detail::PARAMETER_DESCRIPTIONS<Parameters>, detail::FIELD_DESCRIPTIONS<Instance>, detail::FIELD_DESCRIPTIONS<Outputs>,
1103 detail::BUFFER_LAYOUT_REFERENCES<Buffers...>);
1104 }
1105
1130 [[nodiscard]] static std::vector<uint32_t> compileGLSLToVulkanSPIRV(CStringView sourceCode, const Filesystem& filesystem, CStringView filepath = {},
1131 const ShaderCompilationOptions& compilationOptions = {}) {
1132 return detail::VertexShaderBase::compileGLSLToVulkanSPIRVImplementation(sourceCode, &filesystem, filepath, compilationOptions, detail::CONSTANT_DESCRIPTIONS<Constants>,
1133 detail::VERTEX_ATTRIBUTE_DESCRIPTIONS<Vertex>, detail::PARAMETER_DESCRIPTIONS<Parameters>, detail::FIELD_DESCRIPTIONS<Instance>, detail::FIELD_DESCRIPTIONS<Outputs>,
1134 detail::BUFFER_LAYOUT_REFERENCES<Buffers...>);
1135 }
1136
1156 [[nodiscard]] static VertexShader create(Device& device, CStringView sourceCode) {
1157 return VertexShader{device, sourceCode, nullptr, {}};
1158 }
1159
1184 [[nodiscard]] static VertexShader create(Device& device, CStringView sourceCode, const Filesystem& filesystem, CStringView filepath = {}) {
1185 return VertexShader{device, sourceCode, &filesystem, filepath};
1186 }
1187
1211 [[nodiscard]] static VertexShader create(Device& device, Span<const uint32_t> code) {
1212 return VertexShader{device, code};
1213 }
1214
1244 explicit VertexShader(Device& device, const Filesystem& filesystem, CStringView filepath, const VertexShaderOptions& options = {})
1245 : detail::VertexShaderBase(device, filesystem, filepath, options, detail::CONSTANT_DESCRIPTIONS<Constants>, typeid(mesh_type),
1246 detail::VERTEX_ATTRIBUTE_DESCRIPTIONS<Vertex>, detail::MESH_INDEX_TYPE<Index>, detail::PARAMETER_DESCRIPTIONS<Parameters>, detail::FIELD_DESCRIPTIONS<Instance>,
1247 (std::is_empty_v<Instance>) ? 0 : sizeof(Instance), detail::FIELD_DESCRIPTIONS<Outputs>, detail::BUFFER_LAYOUT_REFERENCES<Buffers...>) {}
1248
1249private:
1250 explicit VertexShader(Device& device, CStringView sourceCode, const Filesystem* filesystem, CStringView filepath)
1251 : detail::VertexShaderBase(device, sourceCode, filesystem, filepath, detail::CONSTANT_DESCRIPTIONS<Constants>, typeid(mesh_type),
1252 detail::VERTEX_ATTRIBUTE_DESCRIPTIONS<Vertex>, detail::MESH_INDEX_TYPE<Index>, detail::PARAMETER_DESCRIPTIONS<Parameters>, detail::FIELD_DESCRIPTIONS<Instance>,
1253 (std::is_empty_v<Instance>) ? 0 : sizeof(Instance), detail::FIELD_DESCRIPTIONS<Outputs>, detail::BUFFER_LAYOUT_REFERENCES<Buffers...>) {}
1254
1255 explicit VertexShader(Device& device, Span<const uint32_t> code)
1256 : detail::VertexShaderBase(device, code, detail::CONSTANT_DESCRIPTIONS<Constants>, typeid(mesh_type), detail::VERTEX_ATTRIBUTE_DESCRIPTIONS<Vertex>,
1257 detail::MESH_INDEX_TYPE<Index>, detail::PARAMETER_DESCRIPTIONS<Parameters>, detail::FIELD_DESCRIPTIONS<Instance>, (std::is_empty_v<Instance>) ? 0 : sizeof(Instance),
1258 detail::FIELD_DESCRIPTIONS<Outputs>, detail::BUFFER_LAYOUT_REFERENCES<Buffers...>) {}
1259};
1260
1273template <typename Mesh, typename Inputs, typename Constants, typename Outputs, typename... Buffers>
1275
1276template <typename Vertex, typename Index, typename Parameters, typename Instance, typename Inputs, typename Constants, typename Outputs, typename... Buffers>
1277class FragmentShader<graphics::Mesh<Vertex, Index, Parameters, Instance>, Inputs, Constants, Outputs, Buffers...> : public detail::FragmentShaderBase {
1278public:
1279 static_assert(shader_constant_struct<Constants>);
1280 static_assert(field_struct<Inputs>);
1281 static_assert(field_struct<Outputs>);
1282
1285
1287 using inputs_type = Inputs;
1288
1290 using constants_type = Constants;
1291
1293 using outputs_type = Outputs;
1294
1296 using buffer_types = meta::TypeList<Buffers...>;
1297
1318 [[nodiscard]] static std::vector<uint32_t> compileGLSLToVulkanSPIRV(CStringView sourceCode, const ShaderCompilationOptions& compilationOptions = {}) {
1319 return detail::FragmentShaderBase::compileGLSLToVulkanSPIRVImplementation(sourceCode, nullptr, {}, compilationOptions, detail::CONSTANT_DESCRIPTIONS<Constants>,
1320 detail::PARAMETER_DESCRIPTIONS<Parameters>, detail::FIELD_DESCRIPTIONS<Instance>, detail::FIELD_DESCRIPTIONS<Inputs>, detail::FIELD_DESCRIPTIONS<Outputs>,
1321 detail::BUFFER_LAYOUT_REFERENCES<Buffers...>);
1322 }
1323
1348 [[nodiscard]] static std::vector<uint32_t> compileGLSLToVulkanSPIRV(CStringView sourceCode, const Filesystem& filesystem, CStringView filepath = {},
1349 const ShaderCompilationOptions& compilationOptions = {}) {
1350 return detail::FragmentShaderBase::compileGLSLToVulkanSPIRVImplementation(sourceCode, &filesystem, filepath, compilationOptions, detail::CONSTANT_DESCRIPTIONS<Constants>,
1351 detail::PARAMETER_DESCRIPTIONS<Parameters>, detail::FIELD_DESCRIPTIONS<Instance>, detail::FIELD_DESCRIPTIONS<Inputs>, detail::FIELD_DESCRIPTIONS<Outputs>,
1352 detail::BUFFER_LAYOUT_REFERENCES<Buffers...>);
1353 }
1354
1374 [[nodiscard]] static FragmentShader create(Device& device, CStringView sourceCode) {
1375 return FragmentShader{device, sourceCode, nullptr, {}};
1376 }
1377
1402 [[nodiscard]] static FragmentShader create(Device& device, CStringView sourceCode, const Filesystem& filesystem, CStringView filepath = {}) {
1403 return FragmentShader{device, sourceCode, &filesystem, filepath};
1404 }
1405
1429 [[nodiscard]] static FragmentShader create(Device& device, Span<const uint32_t> code) {
1430 return FragmentShader{device, code};
1431 }
1432
1462 explicit FragmentShader(Device& device, const Filesystem& filesystem, CStringView filepath, const FragmentShaderOptions& options = {})
1463 : detail::FragmentShaderBase(device, filesystem, filepath, options, detail::CONSTANT_DESCRIPTIONS<Constants>, typeid(mesh_type),
1464 detail::VERTEX_ATTRIBUTE_DESCRIPTIONS<Vertex>, detail::MESH_INDEX_TYPE<Index>, detail::PARAMETER_DESCRIPTIONS<Parameters>, detail::FIELD_DESCRIPTIONS<Instance>,
1465 (std::is_empty_v<Instance>) ? 0 : sizeof(Instance), detail::FIELD_DESCRIPTIONS<Inputs>, detail::FIELD_DESCRIPTIONS<Outputs>,
1466 detail::BUFFER_LAYOUT_REFERENCES<Buffers...>) {}
1467
1468private:
1469 explicit FragmentShader(Device& device, CStringView sourceCode, const Filesystem* filesystem, CStringView filepath)
1470 : detail::FragmentShaderBase(device, sourceCode, filesystem, filepath, detail::CONSTANT_DESCRIPTIONS<Constants>, typeid(mesh_type),
1471 detail::VERTEX_ATTRIBUTE_DESCRIPTIONS<Vertex>, detail::MESH_INDEX_TYPE<Index>, detail::PARAMETER_DESCRIPTIONS<Parameters>, detail::FIELD_DESCRIPTIONS<Instance>,
1472 (std::is_empty_v<Instance>) ? 0 : sizeof(Instance), detail::FIELD_DESCRIPTIONS<Inputs>, detail::FIELD_DESCRIPTIONS<Outputs>,
1473 detail::BUFFER_LAYOUT_REFERENCES<Buffers...>) {}
1474
1475 explicit FragmentShader(Device& device, Span<const uint32_t> code)
1476 : detail::FragmentShaderBase(device, code, detail::CONSTANT_DESCRIPTIONS<Constants>, typeid(mesh_type), detail::VERTEX_ATTRIBUTE_DESCRIPTIONS<Vertex>,
1477 detail::MESH_INDEX_TYPE<Index>, detail::PARAMETER_DESCRIPTIONS<Parameters>, detail::FIELD_DESCRIPTIONS<Instance>, (std::is_empty_v<Instance>) ? 0 : sizeof(Instance),
1478 detail::FIELD_DESCRIPTIONS<Inputs>, detail::FIELD_DESCRIPTIONS<Outputs>, detail::BUFFER_LAYOUT_REFERENCES<Buffers...>) {}
1479};
1480
1481namespace detail {
1482
1483template <typename VertexShader, typename FragmentShader>
1484struct is_valid_shader_pipeline_combination : std::false_type {};
1485
1486template <typename Mesh, typename VertexShaderConstants, typename VertexShaderOutputs, typename... VertexShaderBuffers, typename FragmentShaderConstants,
1487 typename FragmentShaderOutputs, typename... FragmentShaderBuffers>
1488struct is_valid_shader_pipeline_combination<VertexShader<Mesh, VertexShaderConstants, VertexShaderOutputs, VertexShaderBuffers...>,
1489 FragmentShader<Mesh, VertexShaderOutputs, FragmentShaderConstants, FragmentShaderOutputs, FragmentShaderBuffers...>>
1490 : meta::type_list_starts_with<meta::TypeList<FragmentShaderBuffers...>, meta::TypeList<VertexShaderBuffers...>> {};
1491
1492template <typename Mesh, typename VertexShaderConstants, typename VertexShaderOutputs, typename... VertexShaderBuffers, typename FragmentShaderConstants,
1493 typename FragmentShaderOutputs>
1494struct is_valid_shader_pipeline_combination<VertexShader<Mesh, VertexShaderConstants, VertexShaderOutputs, VertexShaderBuffers...>,
1495 FragmentShader<Mesh, VertexShaderOutputs, FragmentShaderConstants, FragmentShaderOutputs>> : std::true_type {};
1496
1497template <typename VertexShader, typename FragmentShader>
1498inline constexpr bool is_valid_shader_pipeline_combination_v = is_valid_shader_pipeline_combination<VertexShader, FragmentShader>::value;
1499
1500}; // namespace detail
1501
1507template <typename Mesh>
1508class ShaderPipeline : public detail::ShaderPipelineBase {
1509public:
1512
1533 template <typename VertexShaderMesh, typename VertexShaderConstants, typename VertexShaderOutputs, typename... VertexShaderBuffers, typename FragmentShaderMesh,
1534 typename FragmentShaderInputs, typename FragmentShaderConstants, typename FragmentShaderOutputs, typename... FragmentShaderBuffers>
1536 const VertexShaderConstants& vertexShaderConstants,
1538 const FragmentShaderConstants& fragmentShaderConstants, const ShaderPipelineOptions& shaderPipelineOptions)
1539 : ShaderPipeline(device, vertexShader.lock(), vertexShaderConstants, fragmentShader.lock(), fragmentShaderConstants, shaderPipelineOptions) {
1540 static_assert(same_as<VertexShaderMesh, Mesh>, "Vertex shader's' mesh type does not match the shader pipeline.");
1541 static_assert(same_as<FragmentShaderMesh, Mesh>, "Fragment shader's' mesh type does not match the shader pipeline.");
1542 static_assert(same_as<VertexShaderOutputs, FragmentShaderInputs>, "Fragment shader's input type does not match the vertex shader's output type.");
1543 static_assert(detail::is_valid_shader_pipeline_combination_v<std::remove_cvref_t<decltype(vertexShader)>, std::remove_cvref_t<decltype(fragmentShader)>>,
1544 "Incompatible vertex and fragment shaders.");
1545 }
1546
1582 template <typename VertexShaderConstants, typename FragmentShaderConstants>
1583 ShaderPipeline(Device& device, SharedPointer<VertexShaderImplementation> vertexShaderHandle, const VertexShaderConstants& vertexShaderConstants,
1584 SharedPointer<FragmentShaderImplementation> fragmentShaderHandle, const FragmentShaderConstants& fragmentShaderConstants,
1585 const ShaderPipelineOptions& shaderPipelineOptions)
1586 : detail::ShaderPipelineBase(device, typeid(Mesh), std::move(vertexShaderHandle), detail::CONSTANT_DESCRIPTIONS<VertexShaderConstants>,
1587 asBytes(Span{&vertexShaderConstants, 1}), std::move(fragmentShaderHandle), detail::CONSTANT_DESCRIPTIONS<FragmentShaderConstants>,
1588 asBytes(Span{&fragmentShaderConstants, 1}), shaderPipelineOptions) {}
1589};
1590
1591} // namespace grem::graphics
1592
1593#endif
Floating-point linear RGBA color in the Rec.
Definition Color.hpp:60
static const Color WHITE
Definition Color.hpp:215
Base interface for a filesystem.
Definition Filesystem.hpp:25
Optional value type that holds either a value or no value.
Definition Optional.hpp:58
Definition SharedPointer.hpp:65
Definition Span.hpp:146
Persistent system managing the rendering context of a Window.
Definition Device.hpp:68
FragmentShader(Device &device, const Filesystem &filesystem, CStringView filepath, const FragmentShaderOptions &options={})
Load a fragment shader from a file.
Definition shaders.hpp:1462
static FragmentShader create(Device &device, CStringView sourceCode)
Create a fragment shader from GLSL source code.
Definition shaders.hpp:1374
static std::vector< uint32_t > compileGLSLToVulkanSPIRV(CStringView sourceCode, const ShaderCompilationOptions &compilationOptions={})
Compile a fragment shader from GLSL source code into SPIR-V code for Vulkan for this specic shader ty...
Definition shaders.hpp:1318
static FragmentShader create(Device &device, Span< const uint32_t > code)
Create a fragment shader from SPIR-V code.
Definition shaders.hpp:1429
meta::TypeList< Buffers... > buffer_types
Buffer type list of the shader.
Definition shaders.hpp:1296
graphics::Mesh< Vertex, Index, Parameters, Instance > mesh_type
Mesh type of the shader.
Definition shaders.hpp:1284
static std::vector< uint32_t > compileGLSLToVulkanSPIRV(CStringView sourceCode, const Filesystem &filesystem, CStringView filepath={}, const ShaderCompilationOptions &compilationOptions={})
Compile a fragment shader from GLSL source code into SPIR-V code for Vulkan for this specic shader ty...
Definition shaders.hpp:1348
static FragmentShader create(Device &device, CStringView sourceCode, const Filesystem &filesystem, CStringView filepath={})
Create a fragment shader from GLSL source code, with support for file inclusion.
Definition shaders.hpp:1402
Compiled GPU fragment shader stage.
Definition shaders.hpp:1274
Generic abstraction of a GPU vertex array object and its associated buffers.
Definition Mesh.hpp:209
Backend-specific implementation of RenderPass.
Definition RenderPass.hpp:38
ShaderPipeline(Device &device, SharedPointer< VertexShaderImplementation > vertexShaderHandle, const VertexShaderConstants &vertexShaderConstants, SharedPointer< FragmentShaderImplementation > fragmentShaderHandle, const FragmentShaderConstants &fragmentShaderConstants, const ShaderPipelineOptions &shaderPipelineOptions)
Link a shader pipeline.
Definition shaders.hpp:1583
Mesh mesh_type
Mesh type of the shader pipeline.
Definition shaders.hpp:1511
ShaderPipeline(Device &device, const VertexShader< VertexShaderMesh, VertexShaderConstants, VertexShaderOutputs, VertexShaderBuffers... > &vertexShader, const VertexShaderConstants &vertexShaderConstants, const FragmentShader< FragmentShaderMesh, FragmentShaderInputs, FragmentShaderConstants, FragmentShaderOutputs, FragmentShaderBuffers... > &fragmentShader, const FragmentShaderConstants &fragmentShaderConstants, const ShaderPipelineOptions &shaderPipelineOptions)
Link a shader pipeline.
Definition shaders.hpp:1535
static VertexShader create(Device &device, CStringView sourceCode, const Filesystem &filesystem, CStringView filepath={})
Create a vertex shader from GLSL source code, with support for file inclusion.
Definition shaders.hpp:1184
VertexShader(Device &device, const Filesystem &filesystem, CStringView filepath, const VertexShaderOptions &options={})
Load a vertex shader from a file.
Definition shaders.hpp:1244
static VertexShader create(Device &device, Span< const uint32_t > code)
Create a vertex shader from SPIR-V code.
Definition shaders.hpp:1211
graphics::Mesh< Vertex, Index, Parameters, Instance > mesh_type
Mesh type of the shader.
Definition shaders.hpp:1069
static std::vector< uint32_t > compileGLSLToVulkanSPIRV(CStringView sourceCode, const Filesystem &filesystem, CStringView filepath={}, const ShaderCompilationOptions &compilationOptions={})
Compile a vertex shader from GLSL source code into SPIR-V code for Vulkan for this specic shader type...
Definition shaders.hpp:1130
static VertexShader create(Device &device, CStringView sourceCode)
Create a vertex shader from GLSL source code.
Definition shaders.hpp:1156
meta::TypeList< Buffers... > buffer_types
Buffer type list of the shader.
Definition shaders.hpp:1078
static std::vector< uint32_t > compileGLSLToVulkanSPIRV(CStringView sourceCode, const ShaderCompilationOptions &compilationOptions={})
Compile a vertex shader from GLSL source code into SPIR-V code for Vulkan for this specic shader type...
Definition shaders.hpp:1100
Compiled GPU vertex shader stage.
Definition shaders.hpp:1060
Concept that checks if a type is a valid field struct type for a shader-read buffer.
Definition FieldDescription.hpp:123
Concept that checks if a type is a valid shader constant struct type.
Definition ConstantDescription.hpp:84
Definition concepts.hpp:35
Definition buffer_layouts.hpp:20
PrimitiveType
Graphical primitive type formed by mesh vertices, used in a ShaderPipelineOptions.
Definition shaders.hpp:290
@ TRIANGLE_STRIP
Each point, except the first two, forms a filled triangle with the previous two points.
Definition shaders.hpp:296
@ POINTS
Individual points.
Definition shaders.hpp:291
@ TRIANGLES
Each consecutive triple of points forms an individual filled triangle.
Definition shaders.hpp:295
@ LINES
Each consecutive pair of points forms an individual line segment.
Definition shaders.hpp:292
@ LINE_STRIP
Each point, except the first, forms a line segment to the previous point.
Definition shaders.hpp:294
BlendFactor
Blend factor used in the BlendState of a ShaderPipelineOptions.
Definition shaders.hpp:353
@ DESTINATION_COLOR
Multiply all components by the destination components.
Definition shaders.hpp:358
@ ONE_MINUS_DESTINATION__ALPHA
Multiply all components by 1 minus the destination alpha.
Definition shaders.hpp:363
@ CONSTANT_COLOR
Multiply all components by the constant components.
Definition shaders.hpp:364
@ SOURCE_COLOR
Multiply all components by the source components.
Definition shaders.hpp:356
@ ONE_MINUS_CONSTANT_ALPHA
Multiply all components by 1 minus the constant alpha.
Definition shaders.hpp:367
@ SOURCE_ALPHA
Multiply all components by the source alpha.
Definition shaders.hpp:360
@ ONE_MINUS_CONSTANT_COLOR
Multiply all components by 1 minus each constant component.
Definition shaders.hpp:365
@ ZERO
Multiply all components by 0.
Definition shaders.hpp:354
@ ONE_MINUS_SOURCE_ALPHA
Multiply all components by 1 minus the source alpha.
Definition shaders.hpp:361
@ ONE_MINUS_SOURCE_COLOR
Multiply all components by 1 minus each source component.
Definition shaders.hpp:357
@ SOURCE_ALPHA_SATURATE
Multiply the color components by the smaller of the source alpha or 1 minus the destination alpha,...
Definition shaders.hpp:368
@ DESTINATION_ALPHA
Multiply all components by the destination alpha.
Definition shaders.hpp:362
@ CONSTANT_ALPHA
Multiply all components by the constant alpha.
Definition shaders.hpp:366
@ ONE_MINUS_DESTINATION_COLOR
Multiply all components by 1 minus each destination component.
Definition shaders.hpp:359
@ ONE
Multiply all components by 1.
Definition shaders.hpp:355
PolygonMode
Polygon mode used in a ShaderPipelineOptions.
Definition shaders.hpp:304
@ LINE
Polygon edges are drawn as single-pixel-wide line segments.
Definition shaders.hpp:306
@ POINT
Polygon vertices are drawn as single-pixel points.
Definition shaders.hpp:305
@ FILL
Polygon faces are filled in.
Definition shaders.hpp:307
DepthBufferMode
Backend-specific implementation of ShaderPipeline.
Definition shaders.hpp:55
@ USE_DEPTH_TEST
Evaluate the depth test defined by the DepthTestPredicate to determine whether the pixel should be re...
Definition shaders.hpp:74
@ NONE
Ignore the depth buffer.
Definition shaders.hpp:59
@ USE_DEPTH_TEST_READ_ONLY
Evaluate the depth test defined by the DepthTestPredicate to determine whether the pixel should be re...
Definition shaders.hpp:84
FaceCullingMode
Face culling mode used in a ShaderPipelineOptions.
Definition shaders.hpp:315
@ CULL_FRONT_AND_BACK_FACES
Discard all faces, only render primitives without faces, such as lines and points.
Definition shaders.hpp:335
@ CULL_BACK_FACES
Discard back-facing faces.
Definition shaders.hpp:324
@ CULL_FRONT_FACES
Discard front-facing faces.
Definition shaders.hpp:329
BlendOperation
Blend operation used in the BlendState of a ShaderPipelineOptions.
Definition shaders.hpp:376
@ MAX
Take the maximum of the components.
Definition shaders.hpp:381
@ REVERSE_SUBTRACT
Subtract the blended source components from the blended destination components.
Definition shaders.hpp:379
@ ADD
Add the blended components.
Definition shaders.hpp:377
@ MIN
Take the minimum of the components.
Definition shaders.hpp:380
StencilTestPredicate
Stencil test predicate used in a ShaderPipelineOptions.
Definition shaders.hpp:166
@ ALWAYS_PASS
The stencil test always passes.
Definition shaders.hpp:229
FieldType
Specification of the underlying value type of a field of a shader-read buffer.
Definition FieldDescription.hpp:52
@ UINT
C++: uint32_t, GLSL: uint.
Definition FieldDescription.hpp:57
@ MAT3
C++: mat3, GLSL: mat3.
Definition FieldDescription.hpp:66
@ IVEC4
C++: i32vec4, GLSL: ivec4.
Definition FieldDescription.hpp:56
@ MAT4
C++: mat4, GLSL: mat4.
Definition FieldDescription.hpp:67
@ INT
C++: int32_t, GLSL: int.
Definition FieldDescription.hpp:53
@ UVEC2
C++: u32vec2, GLSL: uvec2.
Definition FieldDescription.hpp:58
@ IVEC3
C++: i32vec3, GLSL: ivec3.
Definition FieldDescription.hpp:55
@ VEC2
C++: vec2, GLSL: vec2.
Definition FieldDescription.hpp:62
@ UVEC4
C++: u32vec4, GLSL: uvec4.
Definition FieldDescription.hpp:60
@ VEC3
C++: vec3, GLSL: vec3.
Definition FieldDescription.hpp:63
@ UVEC3
C++: u32vec3, GLSL: uvec3.
Definition FieldDescription.hpp:59
@ MAT2
C++: mat2, GLSL: mat2.
Definition FieldDescription.hpp:65
@ FLOAT
C++: float, GLSL: float.
Definition FieldDescription.hpp:61
@ VEC4
C++: vec4, GLSL: vec4.
Definition FieldDescription.hpp:64
@ IVEC2
C++: i32vec2, GLSL: ivec2.
Definition FieldDescription.hpp:54
StencilBufferMode
Stencil buffer mode used in a ShaderPipelineOptions.
Definition shaders.hpp:145
@ NONE
Ignore the stencil buffer.
Definition shaders.hpp:149
@ USE_STENCIL_TEST
Evaluate the stencil test defined by the StencilTestPredicate to determine whether the pixel should b...
Definition shaders.hpp:158
FrontFace
Front face winding order used in a ShaderPipelineOptions.
Definition shaders.hpp:343
@ COUNTERCLOCKWISE
Consider faces with counterclockwise winding order to be front-facing.
Definition shaders.hpp:344
@ CLOCKWISE
Consider faces with clockwise winding order to be front-facing.
Definition shaders.hpp:345
StencilBufferOperation
Operation to perform after evaluating the stencil test in a ShaderPipelineOptions.
Definition shaders.hpp:240
@ REPLACE
Set the stencil buffer value to the given reference value.
Definition shaders.hpp:254
@ SET_TO_ZERO
Set the stencil buffer value to 0.
Definition shaders.hpp:249
@ BITWISE_INVERT
Toggle each bit in the stencil buffer value.
Definition shaders.hpp:281
@ KEEP
Keep the current value in the stencil buffer.
Definition shaders.hpp:244
@ INCREMENT_AND_WRAP
Increment the stencil buffer value by 1, or wrap around to 0 if it was maxed out.
Definition shaders.hpp:265
@ DECREMENT_AND_WRAP
Decrement the stencil buffer value by 1, or wrap around to the maximum value if it was 0.
Definition shaders.hpp:276
@ INCREMENT_AND_CLAMP
Increment the stencil buffer value by 1, unless it is already maxed out.
Definition shaders.hpp:259
@ DECREMENT_AND_CLAMP
Decrement the stencil buffer value by 1, unless it is already 0.
Definition shaders.hpp:270
VertexAttributeType
Specification of the underlying value type of a vertex attribute.
Definition VertexAttributeDescription.hpp:75
@ I8NORM
Definition VertexAttributeDescription.hpp:77
@ U32VEC3
Definition VertexAttributeDescription.hpp:111
@ I8VEC2
Definition VertexAttributeDescription.hpp:83
@ I16VEC4NORM
Definition VertexAttributeDescription.hpp:101
@ I16VEC4
Definition VertexAttributeDescription.hpp:103
@ U8VEC2NORM
Definition VertexAttributeDescription.hpp:80
@ U16VEC2
Definition VertexAttributeDescription.hpp:97
@ I32VEC3
Definition VertexAttributeDescription.hpp:112
@ I32VEC2
Definition VertexAttributeDescription.hpp:109
@ U32VEC4
Definition VertexAttributeDescription.hpp:114
@ I16VEC2NORM
Definition VertexAttributeDescription.hpp:96
@ F32
Definition VertexAttributeDescription.hpp:107
@ U8NORM
Definition VertexAttributeDescription.hpp:76
@ I16VEC2
Definition VertexAttributeDescription.hpp:98
@ F16
Definition VertexAttributeDescription.hpp:94
@ I8
Definition VertexAttributeDescription.hpp:79
@ U8
Definition VertexAttributeDescription.hpp:78
@ U8VEC2
Definition VertexAttributeDescription.hpp:82
@ UA2B10G10R10VEC4NORM
Definition VertexAttributeDescription.hpp:88
@ U8VEC4NORM
Definition VertexAttributeDescription.hpp:84
@ I8VEC2NORM
Definition VertexAttributeDescription.hpp:81
@ F16VEC4
Definition VertexAttributeDescription.hpp:104
@ U16VEC4
Definition VertexAttributeDescription.hpp:102
@ U16VEC2NORM
Definition VertexAttributeDescription.hpp:95
@ IA2B10G10R10VEC4NORM
Definition VertexAttributeDescription.hpp:89
@ U16VEC4NORM
Definition VertexAttributeDescription.hpp:100
@ I16
Definition VertexAttributeDescription.hpp:93
@ F32VEC4
Definition VertexAttributeDescription.hpp:116
@ U16NORM
Definition VertexAttributeDescription.hpp:90
@ U32
Definition VertexAttributeDescription.hpp:105
@ I32VEC4
Definition VertexAttributeDescription.hpp:115
@ I16NORM
Definition VertexAttributeDescription.hpp:91
@ F32VEC3
Definition VertexAttributeDescription.hpp:113
@ I32
Definition VertexAttributeDescription.hpp:106
@ F32VEC2
Definition VertexAttributeDescription.hpp:110
@ I8VEC4NORM
Definition VertexAttributeDescription.hpp:85
@ U32VEC2
Definition VertexAttributeDescription.hpp:108
@ F16VEC2
Definition VertexAttributeDescription.hpp:99
@ U16
Definition VertexAttributeDescription.hpp:92
@ U8VEC4
Definition VertexAttributeDescription.hpp:86
@ I8VEC4
Definition VertexAttributeDescription.hpp:87
DepthTestPredicate
Depth test predicate used in a ShaderPipelineOptions.
Definition shaders.hpp:92
@ ALWAYS_PASS
The depth test always passes.
Definition shaders.hpp:137
@ LESS
The depth test passes if and only if the new depth value is less than the old depth value.
Definition shaders.hpp:102
@ NOT_EQUAL
The depth test passes if and only if the new depth value is not equal to the old depth value.
Definition shaders.hpp:132
@ NEVER_PASS
The depth test always fails.
Definition shaders.hpp:96
@ LESS_OR_EQUAL
The depth test passes if and only if the new depth value is less than or equal to the old depth value...
Definition shaders.hpp:108
@ EQUAL
The depth test passes if and only if the new depth value is equal to the old depth value.
Definition shaders.hpp:126
@ GREATER_OR_EQUAL
The depth test passes if and only if the new depth value is greater than or equal to the old depth va...
Definition shaders.hpp:120
@ GREATER
The depth test passes if and only if the new depth value is greater than the old depth value.
Definition shaders.hpp:114
Definition aliases.hpp:9
constexpr Add ADD
Definition algorithms.hpp:76
constexpr Subtract SUBTRACT
Definition algorithms.hpp:84
GREM_ALWAYS_INLINE void lock(Lockable1 &lock1, Lockable2 &lock2, LockableN &... lockN)
Definition synchronization.hpp:1268
constexpr auto move(input_range auto &&range, auto outputIterator)
Definition algorithms.hpp:669
Span(R &&range) -> Span< std::remove_reference_t< decltype(*std::data(range))> >
void unreachable()
Definition assertions.hpp:125
StringBase< char, std::char_traits< char >, std::allocator< char > > String
Definition String.hpp:17
StringViewBase< char, std::char_traits< char > > StringView
Definition StringView.hpp:16
auto asBytes(Span< T, N > s) noexcept
Definition Span.hpp:359
CStringViewBase< char, std::char_traits< char > > CStringView
Definition CStringView.hpp:635
Blend state used in a ShaderPipelineOptions.
Definition shaders.hpp:389
BlendOperation alphaBlendOperation
Alpha blend operation.
Definition shaders.hpp:398
BlendFactor destinationColorBlendFactor
Blend factor of the destination color.
Definition shaders.hpp:394
Color blendConstants
Constant blend color.
Definition shaders.hpp:399
constexpr bool operator==(const BlendState &other) const noexcept=default
Compare this blend state to another for equality.
BlendFactor sourceColorBlendFactor
Blend factor of the source color.
Definition shaders.hpp:393
BlendOperation colorBlendOperation
Color blend operation.
Definition shaders.hpp:395
BlendFactor destinationAlphaBlendFactor
Blend factor of the destination alpha.
Definition shaders.hpp:397
static const BlendState ALPHA_BLENDING_STRAIGHT
Blend state to use for straight alpha blending using the standard "over" operator.
Definition shaders.hpp:390
BlendFactor sourceAlphaBlendFactor
Blend factor of the source alpha.
Definition shaders.hpp:396
static const BlendState ALPHA_BLENDING_PREMULTIPLIED
Blend state to use for pre-multiplied alpha blending using the standard "over" operator.
Definition shaders.hpp:391
Configuration options for loading a FragmentShader.
Definition shaders.hpp:712
bool useCorrespondingCompiledFileIfAvailable
Under the Vulkan backend, if appending ".spv" to the specified filepath yields the path of a valid fi...
Definition shaders.hpp:720
String compiledFileDirectory
If non-empty, and useCorrespondingCompiledFileIfAvailable is true, specifies the directory in which t...
Definition shaders.hpp:727
Options for compiling shader code.
Definition shaders.hpp:681
bool optimize
Whether to optimize the generated code or leave it more debuggable.
Definition shaders.hpp:685
Configuration of a graphics pipeline.
Definition shaders.hpp:428
StencilBufferOperation stencilBufferOperationOnBackFaceStencilTestFail
The operation to perform on the stencil buffer when the stencil test fails for back faces.
Definition shaders.hpp:593
StencilBufferMode stencilBufferMode
How to treat the stencil buffer for each pixel being rendered.
Definition shaders.hpp:459
PolygonMode polygonMode
How to render polygons.
Definition shaders.hpp:629
FaceCullingMode faceCullingMode
How to treat the facing of primitives while rendering.
Definition shaders.hpp:640
StencilBufferOperation stencilBufferOperationOnFrontFacePass
The operation to perform on the stencil buffer when the stencil test and the depth test both pass for...
Definition shaders.hpp:539
DepthBufferMode depthBufferMode
How to treat the depth buffer for each pixel being rendered.
Definition shaders.hpp:434
float depthBiasSlopeFactor
Slope-scaled depth bias factor.
Definition shaders.hpp:659
Optional< BlendState > blendState
How to blend the pixel color with the output while rendering.
Definition shaders.hpp:652
uint8_t stencilTestBackFaceMask
The bit pattern to mask the reference value and stencil value with before performing the stencil test...
Definition shaders.hpp:580
FrontFace frontFace
The winding order of front-facing faces.
Definition shaders.hpp:647
DepthTestPredicate depthTestPredicate
The condition to check when evaluating the depth test.
Definition shaders.hpp:441
uint8_t stencilTestFrontFaceMask
The bit pattern to mask the reference value and stencil value with before performing the stencil test...
Definition shaders.hpp:500
int8_t stencilTestBackFaceReferenceValue
The reference value to compare the stencil buffer value against when evaluating the stencil test for ...
Definition shaders.hpp:564
StencilTestPredicate stencilTestFrontFacePredicate
The condition to check when evaluating the stencil test for front faces.
Definition shaders.hpp:471
StencilBufferOperation stencilBufferOperationOnBackFacePass
The operation to perform on the stencil buffer when the stencil test and the depth test both pass for...
Definition shaders.hpp:619
StencilTestPredicate stencilTestBackFacePredicate
The condition to check when evaluating the stencil test for back faces.
Definition shaders.hpp:551
PrimitiveType primitiveType
How to form primitives out of consecutive mesh vertices.
Definition shaders.hpp:624
float depthBiasConstantFactor
Constant depth bias factor.
Definition shaders.hpp:666
StencilBufferOperation stencilBufferOperationOnFrontFaceStencilTestFail
The operation to perform on the stencil buffer when the stencil test fails for front faces.
Definition shaders.hpp:513
StencilBufferOperation stencilBufferOperationOnBackFaceDepthTestFail
The operation to perform on the stencil buffer when the stencil test passes, but the depth test fails...
Definition shaders.hpp:606
StencilBufferOperation stencilBufferOperationOnFrontFaceDepthTestFail
The operation to perform on the stencil buffer when the stencil test passes, but the depth test fails...
Definition shaders.hpp:526
constexpr bool operator==(const ShaderPipelineOptions &other) const noexcept=default
Compare this configuration to another for equality.
int8_t stencilTestFrontFaceReferenceValue
The reference value to compare the stencil buffer value against when evaluating the stencil test for ...
Definition shaders.hpp:484
Configuration options for loading a VertexShader.
Definition shaders.hpp:691
bool useCorrespondingCompiledFileIfAvailable
Under the Vulkan backend, if appending ".spv" to the specified filepath yields the path of a valid fi...
Definition shaders.hpp:699
String compiledFileDirectory
If non-empty, and useCorrespondingCompiledFileIfAvailable is true, specifies the directory in which t...
Definition shaders.hpp:706
Compile-time list of types.
Definition metaprogramming.hpp:347