| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- // Copyright (C) 2009-2015, Panagiotis Christopoulos Charitos.
- // All rights reserved.
- // Code licensed under the BSD License.
- // http://www.anki3d.org/LICENSE
- #pragma once
- #include "anki/util/StringList.h"
- #include "anki/Gr.h"
- #include "anki/resource/Common.h"
- namespace anki {
- // Forward
- class XmlElement;
- /// Material loader variable. It's the information on whatever is inside
- /// \<input\>
- class MaterialProgramCreatorInputVariable: public NonCopyable
- {
- public:
- TempResourceAllocator<U8> m_alloc;
- String m_name;
- String m_typeStr;
- ShaderVariableDataType m_type = ShaderVariableDataType::NONE;
- StringList m_value;
- Bool8 m_constant = false;
- U16 m_arraySize = 0;
- Bool8 m_instanced = false;
- String m_line;
- ShaderTypeBit m_shaderDefinedMask = ShaderTypeBit::NONE; ///< Defined in
- /// Referenced by
- ShaderTypeBit m_shaderReferencedMask = ShaderTypeBit::NONE;
- Bool8 m_inBlock = true;
- I16 m_binding = -1; ///< Texture unit
- I32 m_offset = -1; ///< Offset inside the UBO
- I32 m_arrayStride = -1;
- /// Identifying the stride between columns of a column-major matrix or
- /// rows of a row-major matrix
- I32 m_matrixStride = -1;
- MaterialProgramCreatorInputVariable()
- {}
- MaterialProgramCreatorInputVariable(MaterialProgramCreatorInputVariable&& b)
- {
- move(b);
- }
- ~MaterialProgramCreatorInputVariable()
- {
- m_name.destroy(m_alloc);
- m_typeStr.destroy(m_alloc);
- m_value.destroy(m_alloc);
- m_line.destroy(m_alloc);
- }
- MaterialProgramCreatorInputVariable& operator=(
- MaterialProgramCreatorInputVariable&& b)
- {
- move(b);
- return *this;
- }
- void move(MaterialProgramCreatorInputVariable& b)
- {
- m_alloc = std::move(b.m_alloc);
- m_name = std::move(b.m_name);
- m_type = b.m_type;
- m_typeStr = std::move(b.m_typeStr);
- m_value = std::move(b.m_value);
- m_constant = b.m_constant;
- m_arraySize = b.m_arraySize;
- m_instanced = b.m_instanced;
- m_line = std::move(b.m_line);
- m_shaderDefinedMask = b.m_shaderDefinedMask;
- m_shaderReferencedMask = b.m_shaderReferencedMask;
- m_inBlock = b.m_inBlock;
- m_binding = b.m_binding;
- m_offset = b.m_offset;
- m_arrayStride = b.m_arrayStride;
- m_matrixStride = b.m_matrixStride;
- }
- Bool duplicate(const MaterialProgramCreatorInputVariable& b) const
- {
- return b.m_name == m_name
- && b.m_type == m_type
- && b.m_value == m_value
- && b.m_constant == m_constant
- && b.m_arraySize == m_arraySize
- && b.m_instanced == m_instanced;
- }
- };
- /// Creator of shader programs. This class parses between
- /// @code <shaderProgams></shaderPrograms> @endcode located inside a
- /// @code <material></material> @endcode and creates the source of a custom
- /// program.
- ///
- /// @note Be carefull when you change the methods. Some change may create more
- /// unique shaders and this is never good.
- class MaterialProgramCreator
- {
- public:
- using Input = MaterialProgramCreatorInputVariable;
- explicit MaterialProgramCreator(TempResourceAllocator<U8> alloc);
- ~MaterialProgramCreator();
- /// Parse what is within the
- /// @code <programs></programs> @endcode
- ANKI_USE_RESULT Error parseProgramsTag(const XmlElement& el);
- /// Get the shader program source code
- const String& getProgramSource(ShaderType shaderType_) const
- {
- U shaderType = enumToType(shaderType_);
- ANKI_ASSERT(!m_sourceBaked[shaderType].isEmpty());
- return m_sourceBaked[shaderType];
- }
- const List<Input>& getInputVariables() const
- {
- return m_inputs;
- }
- Bool hasTessellation() const
- {
- return m_tessellation;
- }
- U32 getUniformBlockSize() const
- {
- return m_blockSize;
- }
- private:
- TempResourceAllocator<char> m_alloc;
- Array<StringList, 5> m_source; ///< Shader program final source
- Array<String, 5> m_sourceBaked; ///< Final source baked
- List<Input> m_inputs;
- StringList m_uniformBlock;
- ShaderTypeBit m_uniformBlockReferencedMask = ShaderTypeBit::NONE;
- U32 m_blockSize = 0;
- Bool8 m_instanced = false;
- U32 m_texBinding = 0;
- ShaderTypeBit m_instanceIdMask = ShaderTypeBit::NONE;
- Bool8 m_tessellation = false;
- /// Parse what is within the
- /// @code <program></program> @endcode
- ANKI_USE_RESULT Error parseProgramTag(const XmlElement& el);
- /// Parse what is within the @code <inputs></inputs> @endcode
- ANKI_USE_RESULT Error parseInputsTag(const XmlElement& programEl);
- /// Parse what is within the @code <operation></operation> @endcode
- ANKI_USE_RESULT Error parseOperationTag(
- const XmlElement& el, ShaderType glshader,
- ShaderTypeBit glshaderbit, String& out);
- };
- } // end namespace anki
|