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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#pragma once
#ifndef DOXYGEN_GENERATING_OUTPUT
#define NCINE_INCLUDE_OPENGL
#include "../../CommonHeaders.h"
#endif
#include "GLUniform.h"
#include "../../Base/StaticHashMapIterator.h"
namespace nCine
{
class GLShaderProgram;
/// Stores information about an OpenGL uniform block
class GLUniformBlock
{
friend class GLUniformBlockCache;
public:
static constexpr std::uint32_t MaxNameLength = 48;
enum class DiscoverUniforms
{
ENABLED,
DISABLED
};
GLUniformBlock();
GLUniformBlock(GLuint program, GLuint blockIndex, DiscoverUniforms discover);
GLUniformBlock(GLuint program, GLuint blockIndex);
inline GLuint GetIndex() const {
return index_;
}
inline GLint GetBindingIndex() const {
return bindingIndex_;
}
/// Returns the size of the block aligned to the uniform buffer offset
inline GLint GetSize() const {
return size_;
}
/// Returns the uniform buffer offset alignment added to the original size
inline std::uint8_t GetAlignAmount() const {
return alignAmount_;
}
inline const char* GetName() const {
return name_;
}
inline GLUniform* GetUniform(const char* name) {
return blockUniforms_.find(String::nullTerminatedView(name));
}
void SetBlockBinding(GLuint blockBinding);
private:
/// Max number of discoverable uniforms per block
static const std::int32_t MaxNumBlockUniforms = 16;
static const std::uint32_t BlockUniformHashSize = 8;
StaticHashMap<String, GLUniform, BlockUniformHashSize> blockUniforms_;
GLuint program_;
GLuint index_;
/// Offset aligned size for `glBindBufferRange()` calls
GLint size_;
/// Uniform buffer offset alignment added to `size_`
std::uint8_t alignAmount_;
/// Current binding index for the uniform block. Negative if not bound.
GLint bindingIndex_;
char name_[MaxNameLength];
};
}
|