// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com) // This file is part of the "Nazara Engine - Graphics module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once #ifndef NAZARA_GRAPHICS_BASICMATERIAL_HPP #define NAZARA_GRAPHICS_BASICMATERIAL_HPP #include #include namespace Nz { class FieldOffsets; class NAZARA_GRAPHICS_API BasicMaterial { friend class MaterialPipeline; public: struct BasicUniformOffsets; BasicMaterial(MaterialPass& material); ~BasicMaterial() = default; inline void EnableAlphaTest(bool alphaTest); inline const std::shared_ptr& GetAlphaMap() const; inline const TextureSamplerInfo& GetAlphaSampler() const; float GetAlphaTestThreshold() const; Color GetDiffuseColor() const; inline const std::shared_ptr& GetDiffuseMap() const; inline const TextureSamplerInfo& GetDiffuseSampler() const; inline bool IsAlphaTestEnabled() const; inline bool HasAlphaMap() const; inline bool HasAlphaTest() const; inline bool HasAlphaTestThreshold() const; inline bool HasDiffuseColor() const; inline bool HasDiffuseMap() const; inline void SetAlphaMap(std::shared_ptr alphaMap); inline void SetAlphaSampler(TextureSamplerInfo alphaSampler); void SetAlphaTestThreshold(float alphaThreshold); void SetDiffuseColor(const Color& diffuse); inline void SetDiffuseMap(std::shared_ptr diffuseMap); inline void SetDiffuseSampler(TextureSamplerInfo diffuseSampler); static inline const BasicUniformOffsets& GetOffsets(); static inline const std::shared_ptr& GetSettings(); struct BasicUniformOffsets { std::size_t alphaThreshold; std::size_t diffuseColor; std::size_t totalSize; }; protected: struct NoInit {}; inline BasicMaterial(MaterialPass& material, NoInit); struct BasicOptionIndexes { std::size_t alphaTest; std::size_t hasAlphaMap; std::size_t hasDiffuseMap; }; struct BasicTextureIndexes { std::size_t alpha; std::size_t diffuse; }; struct BasicBuildOptions { // Common std::vector defaultValues; std::size_t* uniformBlockIndex = nullptr; std::vector> shaders; // Basic BasicUniformOffsets basicOffsets; BasicOptionIndexes* basicOptionIndexes = nullptr; BasicTextureIndexes* basicTextureIndexes = nullptr; }; inline MaterialPass& GetMaterial(); inline const MaterialPass& GetMaterial() const; static MaterialSettings::Builder Build(BasicBuildOptions& options); static std::vector> BuildShaders(); static std::pair BuildUniformOffsets(); std::size_t m_uniformBlockIndex; BasicOptionIndexes m_basicOptionIndexes; BasicTextureIndexes m_basicTextureIndexes; BasicUniformOffsets m_basicUniformOffsets; static std::shared_ptr s_basicMaterialSettings; static std::size_t s_uniformBlockIndex; static BasicOptionIndexes s_basicOptionIndexes; static BasicTextureIndexes s_basicTextureIndexes; static BasicUniformOffsets s_basicUniformOffsets; private: static bool Initialize(); static void Uninitialize(); MaterialPass& m_material; }; } #include #endif // NAZARA_GRAPHICS_BASICMATERIAL_HPP