From 3fdc6eb4f2cbeffce9b250beec4d3a2d52a3f534 Mon Sep 17 00:00:00 2001 From: hnOsmium0001 Date: Wed, 6 Apr 2022 20:52:51 -0700 Subject: Work on moving infrastruture to this project --- source/Material.hpp | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 source/Material.hpp (limited to 'source/Material.hpp') 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 +#include +#include +#include +#include +#include +#include +#include + +// 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 value; + GLint location; + }; + + RcPtr mShader; + std::vector mBoundScalars; + std::vector mBoundVectors; + std::vector mBoundMatrices; + std::vector 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 + void SetVector(const char* name, const glm::vec& vec); + + /// Instanciated for sizes (2,2) (3,3) (4,4) (2,3) (3,2) (2,4) (4,2) (3,4) (4,3) + template + void SetMatrix(const char* name, const glm::mat& mat); + + void SetTexture(const char* name, Texture* texture); + + std::span GetVectors() const; + std::span GetMatrices() const; + std::span GetTextures() const; + const Shader& GetShader() const; + + void UseUniforms() const; +}; -- cgit v1.2.3-70-g09d2