1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#pragma once
#include "../../Base/StaticHashMap.h"
#include "GLUniformBlockCache.h"
#include "../RenderBuffersManager.h"
namespace nCine
{
class GLShaderProgram;
class GLBufferObject;
/// Handles all the uniform blocks of a shader program
class GLShaderUniformBlocks
{
public:
static constexpr std::int32_t UniformBlockCachesHashSize = 4;
using UniformHashMapType = StaticHashMap<String, GLUniformBlockCache, UniformBlockCachesHashSize>;
GLShaderUniformBlocks();
explicit GLShaderUniformBlocks(GLShaderProgram* shaderProgram);
GLShaderUniformBlocks(GLShaderProgram* shaderProgram, const char* includeOnly, const char* exclude);
inline void SetProgram(GLShaderProgram* shaderProgram) {
SetProgram(shaderProgram, nullptr, nullptr);
}
void SetProgram(GLShaderProgram* shaderProgram, const char* includeOnly, const char* exclude);
void SetUniformsDataPointer(GLubyte* dataPointer);
inline unsigned int GetUniformBlockCount() const {
return uniformBlockCaches_.size();
}
inline bool HasUniformBlock(const char* name) const {
return (uniformBlockCaches_.find(String::nullTerminatedView(name)) != nullptr);
}
GLUniformBlockCache* GetUniformBlock(const char* name);
inline const UniformHashMapType GetAllUniformBlocks() const {
return uniformBlockCaches_;
}
void CommitUniformBlocks();
void Bind();
private:
GLShaderProgram* shaderProgram_;
/// Pointer to the data of the first uniform block
GLubyte* dataPointer_;
/// Uniform buffer parameters for binding
RenderBuffersManager::Parameters uboParams_;
UniformHashMapType uniformBlockCaches_;
/// Imports the uniform blocks with the option of including only some or excluding others
void ImportUniformBlocks(const char* includeOnly, const char* exclude);
};
}
|