70 BufferElement(ShaderDataType type,
const std::string& name,
bool normalized =
false, uint64_t offset = 0)
71 : Name(name), Type(type), Size(ShaderDataTypeSize(type)), Offset(offset), Normalized(normalized)
75 uint32_t GetComponentCount()
const
79 case Karma::ShaderDataType::None:
81 case Karma::ShaderDataType::Float:
83 case Karma::ShaderDataType::Float2:
85 case Karma::ShaderDataType::Float3:
87 case Karma::ShaderDataType::Float4:
89 case Karma::ShaderDataType::Mat3:
91 case Karma::ShaderDataType::Mat4:
93 case Karma::ShaderDataType::Int:
95 case Karma::ShaderDataType::Int2:
97 case Karma::ShaderDataType::Int3:
99 case Karma::ShaderDataType::Int4:
101 case Karma::ShaderDataType::Bool:
105 KR_CORE_ASSERT(
false,
"Unknown ShaderDataType!");
117 BufferLayout(
const std::initializer_list<BufferElement>& elements)
118 : m_Elements(elements)
120 CalculateOffsetsAndStride();
123 inline uint32_t GetStride()
const {
return m_Stride; }
124 inline const std::vector<BufferElement>& GetElements()
const {
return m_Elements; }
126 inline void PushElement(
const BufferElement& element) { m_Elements.push_back(element); CalculateOffsetsAndStride(); }
128 std::vector<BufferElement>::iterator begin()
130 return m_Elements.begin();
133 std::vector<BufferElement>::iterator end()
135 return m_Elements.end();
138 std::vector<BufferElement>::const_iterator begin()
const
140 return m_Elements.begin();
143 std::vector<BufferElement>::const_iterator end()
const
145 return m_Elements.end();
149 void CalculateOffsetsAndStride()
153 for (
auto& element : m_Elements)
155 element.Offset = offset;
156 offset += element.Size;
157 m_Stride += element.Size;
162 std::vector<BufferElement> m_Elements;
163 uint32_t m_Stride = 0;
221 static UniformBufferObject* Create(std::vector<ShaderDataType> dataTypes, uint32_t bindingPointIndex);
226 template<
typename... T>
227 void UpdateUniforms(T&&... uniforms)
229 m_UniformList = { uniforms... };
232 virtual void UploadUniformBuffer() {}
234 uint32_t GetBufferSize()
const
239 const std::vector<UBODataPointer>& GetUniformList()
const
241 return m_UniformList;
244 const std::vector<ShaderDataType>& GetUniformDataType()
const
246 return m_UniformDataType;
249 const std::vector<uint32_t>& GetAlignedOffsets()
const
251 return m_UniformAlignedOffsets;
254 const std::vector<uint32_t>& GetUniformSize()
const
256 return m_UniformSizes;
259 uint32_t GetBindingPointIndex()
const
261 return m_BindingPoint;
265 void CalculateOffsetsAndBufferSize();
268 uint32_t m_BufferSize;
269 uint32_t m_BindingPoint;
270 std::vector<UBODataPointer> m_UniformList;
271 std::vector<ShaderDataType> m_UniformDataType;
272 std::vector<uint32_t> m_UniformAlignedOffsets;
273 std::vector<uint32_t> m_UniformSizes;
276 uint32_t ComputeBaseAlignment(ShaderDataType dataType);