2023-04-29 14:22:25 +00:00
|
|
|
#ifndef ENGINE_INCLUDE_GFX_H_
|
|
|
|
#define ENGINE_INCLUDE_GFX_H_
|
2022-09-07 09:02:01 +00:00
|
|
|
|
|
|
|
#include <cstdint>
|
2023-03-31 08:08:49 +00:00
|
|
|
#include <functional>
|
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 {
|
|
|
|
kOff,
|
|
|
|
k2X,
|
|
|
|
k4X,
|
|
|
|
k8X,
|
|
|
|
k16X,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GraphicsSettings {
|
2023-04-29 14:56:49 +00:00
|
|
|
GraphicsSettings() {
|
2023-04-29 14:22:25 +00:00
|
|
|
// sane defaults
|
|
|
|
enable_validation = true;
|
|
|
|
vsync = true;
|
|
|
|
// not all GPUs/drivers support immediate present with V-sync enabled
|
|
|
|
wait_for_present = true;
|
|
|
|
msaa_level = MSAALevel::kOff;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool enable_validation;
|
|
|
|
bool vsync;
|
|
|
|
// idle CPU after render until the frame has been presented
|
|
|
|
// (no affect with V-sync disabled)
|
|
|
|
bool wait_for_present;
|
|
|
|
MSAALevel msaa_level;
|
|
|
|
};
|
|
|
|
|
2023-11-05 14:39:19 +00:00
|
|
|
enum class ImageFormat {
|
|
|
|
kLinear,
|
|
|
|
kSRGB,
|
|
|
|
};
|
|
|
|
|
2023-04-29 14:22:25 +00:00
|
|
|
enum class ShaderType {
|
|
|
|
kVertex,
|
|
|
|
kFragment,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class BufferType {
|
|
|
|
kVertex,
|
|
|
|
kIndex,
|
|
|
|
kUniform,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class Primitive {
|
|
|
|
kPoints,
|
|
|
|
kLines,
|
|
|
|
kLineStrip,
|
|
|
|
kTriangles,
|
|
|
|
kTriangleStrip,
|
|
|
|
};
|
|
|
|
|
2023-05-24 17:33:55 +00:00
|
|
|
enum class CullMode {
|
|
|
|
kCullNone,
|
|
|
|
kCullFront,
|
|
|
|
kCullBack,
|
|
|
|
kCullFrontAndBack
|
|
|
|
};
|
|
|
|
|
2023-04-29 14:56:49 +00:00
|
|
|
enum class VertexAttribFormat { kFloat2, kFloat3, kFloat4 };
|
2023-04-29 14:22:25 +00:00
|
|
|
|
|
|
|
enum class Filter : int {
|
|
|
|
kLinear,
|
|
|
|
kNearest,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class DescriptorType {
|
|
|
|
kUniformBuffer,
|
|
|
|
kCombinedImageSampler,
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace ShaderStageFlags {
|
2023-04-29 14:56:49 +00:00
|
|
|
enum Bits : uint32_t {
|
|
|
|
kVertex = 1 << 0,
|
|
|
|
kFragment = 1 << 1,
|
|
|
|
};
|
|
|
|
typedef std::underlying_type<Bits>::type Flags;
|
|
|
|
} // namespace ShaderStageFlags
|
2023-03-31 08:08:49 +00:00
|
|
|
|
2023-04-29 14:22:25 +00:00
|
|
|
struct VertexAttribDescription {
|
|
|
|
VertexAttribDescription(uint32_t location, VertexAttribFormat format,
|
2023-04-29 14:56:49 +00:00
|
|
|
uint32_t offset)
|
|
|
|
: location(location), format(format), offset(offset) {}
|
|
|
|
uint32_t location; // the index to use in the shader
|
2023-04-29 14:22:25 +00:00
|
|
|
VertexAttribFormat format;
|
|
|
|
uint32_t offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VertexFormat {
|
|
|
|
uint32_t stride;
|
|
|
|
std::vector<VertexAttribDescription> attribute_descriptions;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PipelineInfo {
|
|
|
|
const char* vert_shader_path;
|
|
|
|
const char* frag_shader_path;
|
|
|
|
VertexFormat vertex_format;
|
|
|
|
bool alpha_blending;
|
|
|
|
bool backface_culling;
|
2023-05-24 17:33:55 +00:00
|
|
|
bool write_z;
|
2023-04-29 14:22:25 +00:00
|
|
|
std::vector<const DescriptorSetLayout*> descriptor_set_layouts;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DescriptorSetLayoutBinding {
|
|
|
|
DescriptorType descriptor_type = DescriptorType::kUniformBuffer;
|
|
|
|
ShaderStageFlags::Flags stage_flags = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SamplerInfo {
|
|
|
|
Filter minify;
|
|
|
|
Filter magnify;
|
|
|
|
Filter mipmap;
|
|
|
|
bool anisotropic_filtering;
|
|
|
|
|
|
|
|
bool operator==(const SamplerInfo&) const = default;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace gfx
|
|
|
|
} // namespace engine
|
|
|
|
|
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> {
|
2023-04-29 14:56:49 +00:00
|
|
|
std::size_t operator()(const engine::gfx::SamplerInfo& k) const {
|
2023-04-29 14:22:25 +00:00
|
|
|
using std::hash;
|
2023-04-29 14:56:49 +00:00
|
|
|
|
2023-04-29 14:22:25 +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<bool>()(k.anisotropic_filtering);
|
|
|
|
|
2023-04-29 14:56:49 +00:00
|
|
|
return ((h1 & 0xFF) << 24) | ((h2 & 0xFF) << 16) | ((h3 & 0xFF) << 8) |
|
2023-04-29 14:22:25 +00:00
|
|
|
((h4 & 0xFF) << 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace std
|
|
|
|
|
|
|
|
#endif
|