Extra2D/include/resource/material.h

111 lines
2.3 KiB
C
Raw Normal View History

#pragma once
#include <resource/resource.h>
#include <resource/shader.h>
#include <resource/texture.h>
#include <types/math/color.h>
#include <types/math/vec2.h>
#include <types/math/vec3.h>
#include <types/ptr/intrusive_ptr.h>
#include <string>
#include <unordered_map>
#include <variant>
namespace extra2d {
// 材质属性类型定义
using MaterialProperty = std::variant<
bool,
int,
float,
Vec2,
Vec3,
Color,
Ptr<Texture>
>;
/**
* @brief
*
*
*/
class Material : public Resource {
public:
Material();
~Material() override;
/**
* @brief
*/
ResourceType getType() const override { return ResourceType::Material; }
/**
* @brief
* @param shader
*/
void setShader(Ptr<Shader> shader);
/**
* @brief
*/
Shader* getShader() const { return shader_.get(); }
/**
* @brief
*/
void setBool(const std::string& name, bool value);
/**
* @brief
*/
void setInt(const std::string& name, int value);
/**
* @brief
*/
void setFloat(const std::string& name, float value);
/**
* @brief Vec2
*/
void setVec2(const std::string& name, const Vec2& value);
/**
* @brief Vec3
*/
void setVec3(const std::string& name, const Vec3& value);
/**
* @brief
*/
void setColor(const std::string& name, const Color& value);
/**
* @brief
*/
void setTexture(const std::string& name, Ptr<Texture> texture);
/**
* @brief
*/
void apply();
/**
* @brief
* @return
*/
Ptr<Material> clone() const;
private:
Ptr<Shader> shader_; // 着色器
std::unordered_map<std::string, MaterialProperty> properties_; // 属性表
mutable uint32 textureUnit_ = 0; // 当前纹理单元
/**
* @brief
*/
void applyProperties();
};
} // namespace extra2d