diff --git a/MobileGL/MG_Impl/GLImpl/Buffer/GL_Buffer.cpp b/MobileGL/MG_Impl/GLImpl/Buffer/GL_Buffer.cpp index 03922ea9..96523e7b 100644 --- a/MobileGL/MG_Impl/GLImpl/Buffer/GL_Buffer.cpp +++ b/MobileGL/MG_Impl/GLImpl/Buffer/GL_Buffer.cpp @@ -494,6 +494,20 @@ namespace MobileGL { return MG_State::pGLContext->ValidateBufferObject(buffer) ? GL_TRUE : GL_FALSE; } + void BindBufferBase_State(GLenum target, GLuint index, GLuint buffer) { + BufferTarget bufferTarget = MG_Util::ConvertGLEnumToBufferTarget(target); + if (!BufferImpl::ValidateBufferBindingPointTarget(bufferTarget)) return; + + auto bufferObject = MG_State::pGLContext->GetBufferObject(buffer); + if (!bufferObject) { + MG_State::pGLContext->CreateBufferObject(buffer); + bufferObject = MG_State::pGLContext->GetBufferObject(buffer); + } + + auto& point = MG_State::pGLContext->GetBufferBindingPoint(bufferTarget, index); + point.Bind(bufferObject); + } + /* @INSERTION_POINT:FUNCTION_IMPLEMENTATION@ */ void GetBufferParameteriv(GLenum target, GLenum pname, GLint* params) { GetBufferParameteriv_State(target, pname, params); @@ -543,5 +557,9 @@ namespace MobileGL { void GenBuffers(GLsizei n, GLuint* buffers) { GenBuffers_State(n, buffers); } + + void BindBufferBase(GLenum target, GLuint index, GLuint buffer) { + BindBufferBase_State(target, index, buffer); + } } // namespace MG_Impl::GLImpl } // namespace MobileGL diff --git a/MobileGL/MG_Impl/GLImpl/Buffer/GL_Buffer.h b/MobileGL/MG_Impl/GLImpl/Buffer/GL_Buffer.h index 4fe9d1ef..a75efc54 100644 --- a/MobileGL/MG_Impl/GLImpl/Buffer/GL_Buffer.h +++ b/MobileGL/MG_Impl/GLImpl/Buffer/GL_Buffer.h @@ -17,5 +17,6 @@ namespace MobileGL { void BufferData(GLenum target, GLsizeiptr size, const void* data, GLenum usage); void BindBuffer(GLenum target, GLuint buffer); void GenBuffers(GLsizei n, GLuint* buffers); + void BindBufferBase(GLenum target, GLuint index, GLuint buffer); } // namespace MG_Impl::GLImpl } // namespace MobileGL diff --git a/MobileGL/MG_Impl/GLImpl/Exporting/Definitions.cpp b/MobileGL/MG_Impl/GLImpl/Exporting/Definitions.cpp index c63dc83a..d2f7369c 100644 --- a/MobileGL/MG_Impl/GLImpl/Exporting/Definitions.cpp +++ b/MobileGL/MG_Impl/GLImpl/Exporting/Definitions.cpp @@ -214,7 +214,7 @@ DECLARE_GL_FUNCTION_STUB_HEAD(void, GetIntegeri_v, GLenum target, GLuint index, DECLARE_GL_FUNCTION_STUB_HEAD(void, BeginTransformFeedback, GLenum primitiveMode) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, BeginTransformFeedback, primitiveMode) DECLARE_GL_FUNCTION_STUB_HEAD(void, EndTransformFeedback) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, EndTransformFeedback) DECLARE_GL_FUNCTION_STUB_HEAD(void, BindBufferRange, GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, BindBufferRange, target, index, buffer, offset, size) -DECLARE_GL_FUNCTION_STUB_HEAD(void, BindBufferBase, GLenum target, GLuint index, GLuint buffer) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, BindBufferBase, target, index, buffer) +DECLARE_GL_FUNCTION_HEAD(void, BindBufferBase, GLenum target, GLuint index, GLuint buffer) DECLARE_GL_FUNCTION_END_NO_RETURN(void, BindBufferBase, target, index, buffer) DECLARE_GL_FUNCTION_STUB_HEAD(void, TransformFeedbackVaryings, GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, TransformFeedbackVaryings, program, count, varyings, bufferMode) DECLARE_GL_FUNCTION_STUB_HEAD(void, GetTransformFeedbackVarying, GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, GetTransformFeedbackVarying, program, index, bufSize, length, size, type, name) DECLARE_GL_FUNCTION_HEAD(void, VertexAttribIPointer, GLuint index, GLint size, GLenum type, GLsizei stride, const void* pointer) DECLARE_GL_FUNCTION_END_NO_RETURN(void, VertexAttribIPointer, index, size, type, stride, pointer) diff --git a/MobileGL/MG_State/GLState/BufferState/BufferState.cpp b/MobileGL/MG_State/GLState/BufferState/BufferState.cpp index e417603f..46268e29 100644 --- a/MobileGL/MG_State/GLState/BufferState/BufferState.cpp +++ b/MobileGL/MG_State/GLState/BufferState/BufferState.cpp @@ -61,6 +61,17 @@ namespace MobileGL { Bool BufferState::ValidateBufferObject(Uint index) const { return m_bufferObjects.find(index) != m_bufferObjects.end(); } + + BindingSlot & + BufferState::GetBindingPoint(BufferTarget target, Uint index) { + for (SizeT i = 0; i < BufferBindPointTargets.size(); ++i) { + if (BufferBindPointTargets[i] == target) { + return m_bufferBindPointTargets[i][index]; + } + } + assert(false); + return m_bufferBindPointTargets[0][index]; + } } // namespace GLState } // namespace MG_State } // namespace MobileGL diff --git a/MobileGL/MG_State/GLState/BufferState/BufferState.h b/MobileGL/MG_State/GLState/BufferState/BufferState.h index 240565c9..c6b2597b 100644 --- a/MobileGL/MG_State/GLState/BufferState/BufferState.h +++ b/MobileGL/MG_State/GLState/BufferState/BufferState.h @@ -11,6 +11,9 @@ namespace MobileGL { BufferTarget::PixelPack, BufferTarget::PixelUnpack, BufferTarget::Query, BufferTarget::Texture, BufferTarget::TransformFeedback, BufferTarget::AtomicCounter, BufferTarget::DispatchIndirect, BufferTarget::DrawIndirect, BufferTarget::ShaderStorage); + constexpr const auto BufferBindPointTargets = + ToArray(BufferTarget::Uniform, BufferTarget::TransformFeedback, + BufferTarget::AtomicCounter, BufferTarget::ShaderStorage); class BufferState { public: @@ -20,6 +23,8 @@ namespace MobileGL { Vector GenerateNames(Uint number); SharedPtr CreateBufferObject(Uint index); BindingSlot& GetBindingSlot(BufferTarget target); + // For glBindBufferBase / glBindBufferRange + BindingSlot& GetBindingPoint(BufferTarget target, Uint index); void MarkBufferObjectForDeletion(Uint index); Bool ValidateName(Uint index) const; Bool ValidateBufferObject(Uint index) const; @@ -28,6 +33,9 @@ namespace MobileGL { UnorderedMap> m_bufferObjects; IndexGenerator m_indexGenerator; Array, GlobalBufferTargets.size()> m_bindingSlots; + // TODO: query the count somewhere globally? + // For glBindBufferBase / glBindBufferRange + Array, 14>, BufferBindPointTargets.size()> m_bufferBindPointTargets; }; } // namespace GLState } // namespace MG_State diff --git a/MobileGL/MG_State/GLState/Core.cpp b/MobileGL/MG_State/GLState/Core.cpp index 2e0d089b..1eab2c7b 100644 --- a/MobileGL/MG_State/GLState/Core.cpp +++ b/MobileGL/MG_State/GLState/Core.cpp @@ -65,6 +65,10 @@ namespace MobileGL { return m_bufferState.GetBindingSlot(target); } + BindingSlot& GLContext::GetBufferBindingPoint(BufferTarget target, Uint index) { + return m_bufferState.GetBindingPoint(target, index); + } + SharedPtr GLContext::CreateBufferObject(Uint index) { return m_bufferState.CreateBufferObject(index); } diff --git a/MobileGL/MG_State/GLState/Core.h b/MobileGL/MG_State/GLState/Core.h index bc508d73..bcfb75be 100644 --- a/MobileGL/MG_State/GLState/Core.h +++ b/MobileGL/MG_State/GLState/Core.h @@ -32,6 +32,7 @@ namespace MobileGL { Vector GenBufferNames(Uint number); SharedPtr GetBufferObject(Uint index); BindingSlot& GetBufferBindingSlot(BufferTarget target); + BindingSlot& GetBufferBindingPoint(BufferTarget target, Uint index); SharedPtr CreateBufferObject(Uint index); void MarkBufferObjectForDeletion(Uint index); Bool ValidateBufferName(Uint index) const;