diff options
author | hnOsmium0001 <[email protected]> | 2022-04-06 20:52:51 -0700 |
---|---|---|
committer | hnOsmium0001 <[email protected]> | 2022-04-06 20:52:51 -0700 |
commit | 3fdc6eb4f2cbeffce9b250beec4d3a2d52a3f534 (patch) | |
tree | 05991741844aa2814b3ac71e2c843ebe07244845 /source/Material.hpp | |
parent | ebd42760caaec8330a3c028f31adc7bc0b339d16 (diff) |
Work on moving infrastruture to this project
Diffstat (limited to 'source/Material.hpp')
-rw-r--r-- | source/Material.hpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/source/Material.hpp b/source/Material.hpp new file mode 100644 index 0000000..6290a25 --- /dev/null +++ b/source/Material.hpp @@ -0,0 +1,76 @@ +#pragma once + +#include "RcPtr.hpp" +#include "Shader.hpp" +#include "Texture.hpp" + +#include <glad/glad.h> +#include <cstddef> +#include <cstdint> +#include <glm/glm.hpp> +#include <memory> +#include <span> +#include <string_view> +#include <vector> + +// TODO support multiple sizes of vectors and matrices +class Material : public RefCounted { +public: + struct ScalarUniform { + union { + float floatValue; + int32_t intValue; + uint32_t uintValue; + }; + GLenum actualType; + GLint location; + }; + + struct VectorUniform { + float value[4]; + int actualLength; + GLint location; + }; + + struct MatrixUniform { + float value[16]; + int actualWidth; + int actualHeight; + GLint location; + }; + + struct TextureUniform { + RcPtr<Texture> value; + GLint location; + }; + + RcPtr<Shader> mShader; + std::vector<ScalarUniform> mBoundScalars; + std::vector<VectorUniform> mBoundVectors; + std::vector<MatrixUniform> mBoundMatrices; + std::vector<TextureUniform> mBoundTextures; + +public: + Material(Shader* shader); + + void SetFloat(const char* name, float value); + void SetInt(const char* name, int32_t value); + void SetUInt(const char* name, uint32_t value); + + /// Instanciated for length == 1, 2, 3, 4 + template <int length> + void SetVector(const char* name, const glm::vec<length, float>& vec); + + /// Instanciated for sizes (2,2) (3,3) (4,4) (2,3) (3,2) (2,4) (4,2) (3,4) (4,3) + template <int width, int height> + void SetMatrix(const char* name, const glm::mat<width, height, float>& mat); + + void SetTexture(const char* name, Texture* texture); + + std::span<const VectorUniform> GetVectors() const; + std::span<const MatrixUniform> GetMatrices() const; + std::span<const TextureUniform> GetTextures() const; + const Shader& GetShader() const; + + void UseUniforms() const; +}; |