2024-03-31 10:11:22 +00:00
|
|
|
#pragma once
|
2022-09-07 09:02:01 +00:00
|
|
|
|
|
|
|
#include <cstdint>
|
2024-06-04 22:31:22 +00:00
|
|
|
|
2023-03-31 08:08:49 +00:00
|
|
|
#include <functional>
|
2024-03-03 23:22:23 +00:00
|
|
|
#include <string>
|
2023-04-29 14:22:25 +00:00
|
|
|
#include <type_traits>
|
|
|
|
#include <vector>
|
2022-09-07 09:02:01 +00:00
|
|
|
|
2023-02-19 13:55:08 +00:00
|
|
|
// Enums and structs for the graphics abstraction
|
|
|
|
|
2023-04-29 14:22:25 +00:00
|
|
|
namespace engine {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
// handles (incomplete types)
|
|
|
|
struct Pipeline;
|
|
|
|
struct UniformBuffer;
|
|
|
|
struct Buffer;
|
|
|
|
struct DrawBuffer;
|
|
|
|
struct DescriptorSetLayout;
|
|
|
|
struct DescriptorSet;
|
|
|
|
struct Image;
|
|
|
|
struct Sampler;
|
|
|
|
|
|
|
|
enum class MSAALevel {
|
2024-06-04 22:31:22 +00:00
|
|
|
MSAA_OFF,
|
|
|
|
MSAA_2X,
|
|
|
|
MSAA_4X,
|
|
|
|
MSAA_8X,
|
|
|
|
MSAA_16X,
|
2023-04-29 14:22:25 +00:00
|
|
|
};
|
|
|
|
|
2024-04-26 22:31:34 +00:00
|
|
|
enum class PresentMode {
|
2024-06-04 22:31:22 +00:00
|
|
|
DOUBLE_BUFFERED_NO_VSYNC,
|
|
|
|
DOUBLE_BUFFERED_VSYNC,
|
|
|
|
TRIPLE_BUFFERED,
|
2024-04-26 22:31:34 +00:00
|
|
|
};
|
|
|
|
|
2023-04-29 14:22:25 +00:00
|
|
|
struct GraphicsSettings {
|
2024-03-19 11:32:51 +00:00
|
|
|
GraphicsSettings()
|
|
|
|
{
|
|
|
|
// sane defaults
|
2024-04-26 22:31:34 +00:00
|
|
|
enable_validation = false;
|
2024-06-04 22:31:22 +00:00
|
|
|
present_mode = PresentMode::DOUBLE_BUFFERED_VSYNC;
|
|
|
|
msaa_level = MSAALevel::MSAA_OFF;
|
2024-03-19 11:32:51 +00:00
|
|
|
enable_anisotropy = false; // anisotropic filtering can severely affect performance on intel iGPUs
|
|
|
|
}
|
|
|
|
|
|
|
|
bool enable_validation;
|
2024-04-26 22:31:34 +00:00
|
|
|
PresentMode present_mode;
|
2024-03-19 11:32:51 +00:00
|
|
|
MSAALevel msaa_level;
|
|
|
|
bool enable_anisotropy;
|
2023-04-29 14:22:25 +00:00
|
|
|
};
|
|
|
|
|
2023-11-05 14:39:19 +00:00
|
|
|
enum class ImageFormat {
|
2024-06-04 22:31:22 +00:00
|
|
|
LINEAR,
|
|
|
|
SRGB,
|
2023-11-05 14:39:19 +00:00
|
|
|
};
|
|
|
|
|
2023-04-29 14:22:25 +00:00
|
|
|
enum class ShaderType {
|
2024-06-04 22:31:22 +00:00
|
|
|
VERTEX,
|
|
|
|
FRAGMENT,
|
2023-04-29 14:22:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum class BufferType {
|
2024-06-04 22:31:22 +00:00
|
|
|
VERTEX,
|
|
|
|
INDEX,
|
|
|
|
UNIFORM,
|
2023-04-29 14:22:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum class Primitive {
|
2024-06-04 22:31:22 +00:00
|
|
|
POINTS,
|
|
|
|
LINES,
|
|
|
|
LINE_STRIP,
|
|
|
|
TRIANGLES,
|
|
|
|
TRIANGLE_STRIP,
|
2023-04-29 14:22:25 +00:00
|
|
|
};
|
|
|
|
|
2024-06-04 22:31:22 +00:00
|
|
|
enum class CullMode { CULL_NONE, CULL_FRONT, CULL_BACK, CULL_FRONT_AND_BACK };
|
2023-05-24 17:33:55 +00:00
|
|
|
|
2024-06-04 22:31:22 +00:00
|
|
|
enum class VertexAttribFormat { FLOAT2, FLOAT3, FLOAT4 };
|
2023-04-29 14:22:25 +00:00
|
|
|
|
|
|
|
enum class Filter : int {
|
2024-06-04 22:31:22 +00:00
|
|
|
LINEAR,
|
|
|
|
NEAREST,
|
2024-03-19 11:32:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum class WrapMode : int {
|
2024-06-04 22:31:22 +00:00
|
|
|
REPEAT,
|
|
|
|
MIRRORED_REPEAT,
|
|
|
|
CLAMP_TO_EDGE,
|
|
|
|
CLAMP_TO_BORDER,
|
2023-04-29 14:22:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum class DescriptorType {
|
2024-06-04 22:31:22 +00:00
|
|
|
UNIFORM_BUFFER,
|
|
|
|
COMBINED_IMAGE_SAMPLER,
|
2023-04-29 14:22:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace ShaderStageFlags {
|
2023-04-29 14:56:49 +00:00
|
|
|
enum Bits : uint32_t {
|
2024-06-04 22:31:22 +00:00
|
|
|
VERTEX = 1 << 0,
|
|
|
|
FRAGMENT = 1 << 1,
|
2023-04-29 14:56:49 +00:00
|
|
|
};
|
|
|
|
typedef std::underlying_type<Bits>::type Flags;
|
2024-03-19 11:32:51 +00:00
|
|
|
} // namespace ShaderStageFlags
|
2023-03-31 08:08:49 +00:00
|
|
|
|
2023-04-29 14:22:25 +00:00
|
|
|
struct VertexAttribDescription {
|
2024-03-19 11:32:51 +00:00
|
|
|
uint32_t location; // the index to use in the shader
|
|
|
|
VertexAttribFormat format;
|
|
|
|
uint32_t offset;
|
2023-04-29 14:22:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct VertexFormat {
|
2024-03-19 11:32:51 +00:00
|
|
|
uint32_t stride;
|
|
|
|
std::vector<VertexAttribDescription> attribute_descriptions;
|
2023-04-29 14:22:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PipelineInfo {
|
2024-03-19 11:32:51 +00:00
|
|
|
std::string vert_shader_path;
|
|
|
|
std::string frag_shader_path;
|
|
|
|
VertexFormat vertex_format;
|
2024-03-23 21:16:30 +00:00
|
|
|
CullMode face_cull_mode;
|
2024-03-19 11:32:51 +00:00
|
|
|
bool alpha_blending;
|
|
|
|
bool write_z;
|
2024-03-31 10:11:22 +00:00
|
|
|
bool line_primitives; // false for triangles, true for lines
|
2024-03-26 11:18:50 +00:00
|
|
|
bool depth_attachment_only; // false 99% of the time
|
2024-03-19 11:32:51 +00:00
|
|
|
std::vector<const DescriptorSetLayout*> descriptor_set_layouts;
|
2023-04-29 14:22:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct DescriptorSetLayoutBinding {
|
2024-06-04 22:31:22 +00:00
|
|
|
DescriptorType descriptor_type = DescriptorType::UNIFORM_BUFFER;
|
2024-03-19 11:32:51 +00:00
|
|
|
ShaderStageFlags::Flags stage_flags = 0;
|
2023-04-29 14:22:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SamplerInfo {
|
2024-06-04 22:31:22 +00:00
|
|
|
Filter minify = gfx::Filter::LINEAR;
|
|
|
|
Filter magnify = gfx::Filter::LINEAR;
|
|
|
|
Filter mipmap = gfx::Filter::LINEAR;
|
|
|
|
WrapMode wrap_u = gfx::WrapMode::REPEAT;
|
|
|
|
WrapMode wrap_v = gfx::WrapMode::REPEAT;
|
|
|
|
WrapMode wrap_w = gfx::WrapMode::REPEAT; // only useful for cubemaps AFAIK
|
2024-03-19 11:32:51 +00:00
|
|
|
bool anisotropic_filtering = true; // this can be force disabled by a global setting
|
2023-04-29 14:22:25 +00:00
|
|
|
|
2024-03-19 11:32:51 +00:00
|
|
|
bool operator==(const SamplerInfo&) const = default;
|
2023-04-29 14:22:25 +00:00
|
|
|
};
|
|
|
|
|
2024-03-19 11:32:51 +00:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace engine
|
2023-04-29 14:22:25 +00:00
|
|
|
|
2024-06-04 22:31:22 +00:00
|
|
|
// there has to be another way...
|
2023-03-31 08:08:49 +00:00
|
|
|
namespace std {
|
2023-04-29 14:56:49 +00:00
|
|
|
template <>
|
2023-05-29 14:41:36 +00:00
|
|
|
struct hash<engine::gfx::SamplerInfo> {
|
2024-03-19 11:32:51 +00:00
|
|
|
std::size_t operator()(const engine::gfx::SamplerInfo& k) const
|
|
|
|
{
|
|
|
|
using std::hash;
|
2023-04-29 14:56:49 +00:00
|
|
|
|
2024-03-19 11:32:51 +00:00
|
|
|
size_t h1 = hash<int>()(static_cast<int>(k.minify));
|
|
|
|
size_t h2 = hash<int>()(static_cast<int>(k.magnify));
|
|
|
|
size_t h3 = hash<int>()(static_cast<int>(k.mipmap));
|
|
|
|
size_t h4 = hash<int>()(static_cast<int>(k.wrap_u));
|
|
|
|
size_t h5 = hash<int>()(static_cast<int>(k.wrap_v));
|
|
|
|
size_t h6 = hash<int>()(static_cast<int>(k.wrap_w));
|
|
|
|
size_t h7 = hash<bool>()(k.anisotropic_filtering);
|
2023-04-29 14:22:25 +00:00
|
|
|
|
2024-03-19 11:32:51 +00:00
|
|
|
return ((h1 & 0xFF) << 48) | ((h2 & 0xFF) << 40) | ((h3 & 0xFF) << 32) | ((h4 & 0xFF) << 24) | ((h5 & 0xFF) << 16) | ((h6 & 0xFF) << 8) |
|
|
|
|
((h7 & 0xFF) << 0);
|
|
|
|
}
|
2023-04-29 14:22:25 +00:00
|
|
|
};
|
|
|
|
|
2024-03-31 10:11:22 +00:00
|
|
|
} // namespace std
|