| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
- // All rights reserved.
- // Code licensed under the BSD License.
- // http://www.anki3d.org/LICENSE
- #pragma once
- #include <AnKi/Gr/GrObject.h>
- #include <AnKi/Math.h>
- #include <AnKi/Util/WeakArray.h>
- namespace anki {
- /// @addtogroup graphics
- /// @{
- /// Specialization constant value.
- class ShaderSpecializationConstValue
- {
- public:
- union
- {
- F32 m_float;
- I32 m_int;
- U32 m_uint;
- };
- U32 m_constantId = MAX_U32;
- ShaderVariableDataType m_dataType;
- ShaderSpecializationConstValue()
- : m_int(0)
- , m_dataType(ShaderVariableDataType::NONE)
- {
- }
- explicit ShaderSpecializationConstValue(F32 f)
- : m_float(f)
- , m_dataType(ShaderVariableDataType::F32)
- {
- }
- explicit ShaderSpecializationConstValue(I32 i)
- : m_int(i)
- , m_dataType(ShaderVariableDataType::I32)
- {
- }
- explicit ShaderSpecializationConstValue(U32 i)
- : m_int(i)
- , m_dataType(ShaderVariableDataType::U32)
- {
- }
- ShaderSpecializationConstValue(const ShaderSpecializationConstValue&) = default;
- ShaderSpecializationConstValue& operator=(const ShaderSpecializationConstValue&) = default;
- };
- /// Shader init info.
- class ShaderInitInfo : public GrBaseInitInfo
- {
- public:
- ShaderType m_shaderType = ShaderType::COUNT;
- ConstWeakArray<U8> m_binary = {};
- /// @note It's OK to have entries in that array with consts that do not appear in the shader.
- ConstWeakArray<ShaderSpecializationConstValue> m_constValues;
- ShaderInitInfo()
- {
- }
- ShaderInitInfo(CString name)
- : GrBaseInitInfo(name)
- {
- }
- ShaderInitInfo(ShaderType type, ConstWeakArray<U8> bin, CString name = {})
- : GrBaseInitInfo(name)
- , m_shaderType(type)
- , m_binary(bin)
- {
- }
- };
- /// GPU shader.
- class Shader : public GrObject
- {
- ANKI_GR_OBJECT
- public:
- static const GrObjectType CLASS_TYPE = GrObjectType::SHADER;
- ShaderType getShaderType() const
- {
- ANKI_ASSERT(m_shaderType != ShaderType::COUNT);
- return m_shaderType;
- }
- protected:
- ShaderType m_shaderType = ShaderType::COUNT;
- /// Construct.
- Shader(GrManager* manager, CString name)
- : GrObject(manager, CLASS_TYPE, name)
- {
- }
- /// Destroy.
- ~Shader()
- {
- }
- private:
- /// Allocate and initialize a new instance.
- static ANKI_USE_RESULT Shader* newInstance(GrManager* manager, const ShaderInitInfo& init);
- };
- /// @}
- } // end namespace anki
|