#ifndef ENGINE_INCLUDE_GFX_H_ #define ENGINE_INCLUDE_GFX_H_ #include #include #include #include #include // Enums and structs for the graphics abstraction 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 { GraphicsSettings() { // 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; enable_anisotropy = false; // anisotropic filtering can severely affect performance on intel iGPUs } 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; bool enable_anisotropy; }; enum class ImageFormat { kLinear, kSRGB, }; enum class ShaderType { kVertex, kFragment, }; enum class BufferType { kVertex, kIndex, kUniform, }; enum class Primitive { kPoints, kLines, kLineStrip, kTriangles, kTriangleStrip, }; enum class CullMode { kCullNone, kCullFront, kCullBack, kCullFrontAndBack }; enum class VertexAttribFormat { kFloat2, kFloat3, kFloat4 }; enum class Filter : int { kLinear, kNearest, }; enum class WrapMode : int { kRepeat, kMirroredRepeat, kClampToEdge, }; enum class DescriptorType { kUniformBuffer, kCombinedImageSampler, }; namespace ShaderStageFlags { enum Bits : uint32_t { kVertex = 1 << 0, kFragment = 1 << 1, }; typedef std::underlying_type::type Flags; } // namespace ShaderStageFlags struct VertexAttribDescription { VertexAttribDescription(uint32_t location, VertexAttribFormat format, uint32_t offset) : location(location), format(format), offset(offset) {} uint32_t location; // the index to use in the shader VertexAttribFormat format; uint32_t offset; }; struct VertexFormat { uint32_t stride; std::vector attribute_descriptions; }; struct PipelineInfo { std::string vert_shader_path; std::string frag_shader_path; VertexFormat vertex_format; CullMode face_cull_mode; bool alpha_blending; bool write_z; bool line_primitives; // false for triangles, true for lines bool depth_attachment_only; // false 99% of the time std::vector descriptor_set_layouts; }; struct DescriptorSetLayoutBinding { DescriptorType descriptor_type = DescriptorType::kUniformBuffer; ShaderStageFlags::Flags stage_flags = 0; }; struct SamplerInfo { Filter minify = gfx::Filter::kLinear; Filter magnify = gfx::Filter::kLinear; Filter mipmap = gfx::Filter::kLinear; WrapMode wrap_u = gfx::WrapMode::kRepeat; WrapMode wrap_v = gfx::WrapMode::kRepeat; WrapMode wrap_w = gfx::WrapMode::kRepeat; // only useful for cubemaps AFAIK bool anisotropic_filtering = true; // this can be force disabled by a global setting bool operator==(const SamplerInfo&) const = default; }; } // namespace gfx } // namespace engine namespace std { template <> struct hash { std::size_t operator()(const engine::gfx::SamplerInfo& k) const { using std::hash; size_t h1 = hash()(static_cast(k.minify)); size_t h2 = hash()(static_cast(k.magnify)); size_t h3 = hash()(static_cast(k.mipmap)); size_t h4 = hash()(static_cast(k.wrap_u)); size_t h5 = hash()(static_cast(k.wrap_v)); size_t h6 = hash()(static_cast(k.wrap_w)); size_t h7 = hash()(k.anisotropic_filtering); return ((h1 & 0xFF) << 48) | ((h2 & 0xFF) << 40) | ((h3 & 0xFF) << 32) | ((h4 & 0xFF) << 24) | ((h5 & 0xFF) << 16) | ((h6 & 0xFF) << 8) | ((h7 & 0xFF) << 0); } }; } // namespace std #endif