diff --git a/include/Nazara/OpenGLRenderer/Wrapper/CoreFunctions.hpp b/include/Nazara/OpenGLRenderer/Wrapper/CoreFunctions.hpp index bc7c96bf0..3646986e9 100644 --- a/include/Nazara/OpenGLRenderer/Wrapper/CoreFunctions.hpp +++ b/include/Nazara/OpenGLRenderer/Wrapper/CoreFunctions.hpp @@ -85,6 +85,9 @@ typedef void (GL_APIENTRYP PFNGLSPECIALIZESHADERARBPROC) (GLuint shader, const G cb(glGenVertexArrays, PFNGLGENVERTEXARRAYSPROC) \ cb(glGenerateMipmap, PFNGLGENERATEMIPMAPPROC) \ cb(glGetActiveUniform, PFNGLGETACTIVEUNIFORMPROC) \ + cb(glGetActiveUniformsiv, PFNGLGETACTIVEUNIFORMSIVPROC) \ + cb(glGetActiveUniformBlockiv, PFNGLGETACTIVEUNIFORMBLOCKIVPROC) \ + cb(glGetActiveUniformBlockName, PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC) \ cb(glGetBooleanv, PFNGLGETBOOLEANVPROC) \ cb(glGetBufferParameteriv, PFNGLGETBUFFERPARAMETERIVPROC) \ cb(glGetError, PFNGLGETERRORPROC) \ @@ -105,6 +108,7 @@ typedef void (GL_APIENTRYP PFNGLSPECIALIZESHADERARBPROC) (GLuint shader, const G cb(glGetUniformLocation, PFNGLGETUNIFORMLOCATIONPROC) \ cb(glGetUniformfv, PFNGLGETUNIFORMFVPROC) \ cb(glGetUniformiv, PFNGLGETUNIFORMIVPROC) \ + cb(glGetUniformBlockIndex, PFNGLGETUNIFORMBLOCKINDEXPROC) \ cb(glIsEnabled, PFNGLISENABLEDPROC) \ cb(glLineWidth, PFNGLLINEWIDTHPROC) \ cb(glLinkProgram, PFNGLLINKPROGRAMPROC) \ diff --git a/include/Nazara/OpenGLRenderer/Wrapper/Program.hpp b/include/Nazara/OpenGLRenderer/Wrapper/Program.hpp index a4c4181ac..199c1d51b 100644 --- a/include/Nazara/OpenGLRenderer/Wrapper/Program.hpp +++ b/include/Nazara/OpenGLRenderer/Wrapper/Program.hpp @@ -26,7 +26,18 @@ namespace Nz::GL inline void AttachShader(GLuint shader); + inline void Get(GLenum pname, GLint* params) const; + inline void GetActiveUniform(GLuint index, GLsizei bufSize, GLsizei* length, GLint* size, GLenum* type, GLchar* name) const; + inline void GetActiveUniformBlock(GLuint uniformBlockIndex, GLenum pname, GLint* params) const; + inline std::vector GetActiveUniformBlockUniformIndices(GLuint uniformBlockIndex) const; + inline void GetActiveUniformBlockName(GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName) const; + inline std::string GetActiveUniformBlockName(GLuint uniformBlockIndex) const; + inline std::string GetActiveUniformName(GLuint index) const; + inline std::vector GetActiveUniforms(GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname) const; + inline void GetActiveUniforms(GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params) const; inline bool GetLinkStatus(std::string* error = nullptr) const; + inline GLuint GetUniformBlockIndex(const char* uniformBlockName) const; + inline GLuint GetUniformBlockIndex(const std::string& uniformBlockName) const; inline GLint GetUniformLocation(const char* uniformName) const; inline GLint GetUniformLocation(const std::string& uniformName) const; diff --git a/include/Nazara/OpenGLRenderer/Wrapper/Program.inl b/include/Nazara/OpenGLRenderer/Wrapper/Program.inl index fd5e6030b..63e6d77e1 100644 --- a/include/Nazara/OpenGLRenderer/Wrapper/Program.inl +++ b/include/Nazara/OpenGLRenderer/Wrapper/Program.inl @@ -11,11 +11,126 @@ namespace Nz::GL inline void Program::AttachShader(GLuint shader) { assert(m_objectId); - const Context& context = EnsureDeviceContext(); + context.glAttachShader(m_objectId, shader); } + inline void Program::Get(GLenum pname, GLint* params) const + { + assert(m_objectId); + const Context& context = EnsureDeviceContext(); + + return context.glGetProgramiv(m_objectId, pname, params); + } + + inline void Program::GetActiveUniform(GLuint index, GLsizei bufSize, GLsizei* length, GLint* size, GLenum* type, GLchar* name) const + { + assert(m_objectId); + const Context& context = EnsureDeviceContext(); + + return context.glGetActiveUniform(m_objectId, index, bufSize, length, size, type, name); + } + + inline void Program::GetActiveUniformBlock(GLuint uniformBlockIndex, GLenum pname, GLint* params) const + { + assert(m_objectId); + const Context& context = EnsureDeviceContext(); + + return context.glGetActiveUniformBlockiv(m_objectId, uniformBlockIndex, pname, params); + } + + inline std::vector Program::GetActiveUniformBlockUniformIndices(GLuint uniformBlockIndex) const + { + assert(m_objectId); + const Context& context = EnsureDeviceContext(); + + std::vector uniformIndices; + + GLint activeUniformCount = 0; + context.glGetActiveUniformBlockiv(m_objectId, uniformBlockIndex, GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, &activeUniformCount); + + if (activeUniformCount > 0) + { + uniformIndices.resize(static_cast(activeUniformCount)); + context.glGetActiveUniformBlockiv(m_objectId, uniformBlockIndex, GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES, uniformIndices.data()); + } + + return uniformIndices; + } + + inline void Program::GetActiveUniformBlockName(GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName) const + { + assert(m_objectId); + const Context& context = EnsureDeviceContext(); + + return context.glGetActiveUniformBlockName(m_objectId, uniformBlockIndex, bufSize, length, uniformBlockName); + } + + inline std::vector Program::GetActiveUniforms(GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname) const + { + assert(m_objectId); + const Context& context = EnsureDeviceContext(); + + std::vector values(uniformCount); + context.glGetActiveUniformsiv(m_objectId, uniformCount, uniformIndices, pname, values.data()); + + return values; + } + + inline void Program::GetActiveUniforms(GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params) const + { + assert(m_objectId); + const Context& context = EnsureDeviceContext(); + + return context.glGetActiveUniformsiv(m_objectId, uniformCount, uniformIndices, pname, params); + } + + inline std::string Program::GetActiveUniformBlockName(GLuint uniformBlockIndex) const + { + assert(m_objectId); + const Context& context = EnsureDeviceContext(); + + std::string name; + + GLint nameLength = 0; + context.glGetActiveUniformBlockiv(m_objectId, uniformBlockIndex, GL_UNIFORM_BLOCK_NAME_LENGTH, &nameLength); + + if (nameLength > 0) + { + name.resize(nameLength); + + context.glGetActiveUniformBlockName(m_objectId, uniformBlockIndex, nameLength + 1, nullptr, name.data()); + } + + return name; + } + + inline std::string Program::GetActiveUniformName(GLuint index) const + { + assert(m_objectId); + const Context& context = EnsureDeviceContext(); + + std::string name; + + GLint maxNameLength = 0; + context.glGetProgramiv(m_objectId, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxNameLength); + + if (maxNameLength > 0) + { + name.resize(maxNameLength); + + GLsizei length; + GLint size; + GLenum type; + context.glGetActiveUniform(m_objectId, index, maxNameLength, &length, &size, &type, name.data()); + + name.resize(length); + } + + return name; + } + inline bool Program::GetLinkStatus(std::string* error) const { assert(m_objectId); @@ -45,6 +160,19 @@ namespace Nz::GL return true; } + inline GLuint Program::GetUniformBlockIndex(const char* uniformBlockName) const + { + assert(m_objectId); + const Context& context = EnsureDeviceContext(); + + return context.glGetUniformBlockIndex(m_objectId, uniformBlockName); + } + + inline GLuint Program::GetUniformBlockIndex(const std::string& uniformBlockName) const + { + return GetUniformBlockIndex(uniformBlockName.c_str()); + } + inline GLint Program::GetUniformLocation(const char* uniformName) const { assert(m_objectId);