From 9c27d5f1b51e44a25693f9c26136b3759fedefde Mon Sep 17 00:00:00 2001 From: Tungstend Date: Wed, 26 Mar 2025 14:52:53 +0800 Subject: [PATCH] Fix(binding): bind real buffer when glBindVertexBuffer is called --- src/main/cpp/gl/buffer.cpp | 21 ++++++++++++++++++++- src/main/cpp/gl/buffer.h | 2 ++ src/main/cpp/gl/gl_native.cpp | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main/cpp/gl/buffer.cpp b/src/main/cpp/gl/buffer.cpp index f3ea251..7009fe3 100644 --- a/src/main/cpp/gl/buffer.cpp +++ b/src/main/cpp/gl/buffer.cpp @@ -13,7 +13,7 @@ GLint maxArrayId = 0; std::unordered_map g_gen_buffers; std::unordered_map g_gen_arrays; -std::unordered_map g_bound_buffers; +std::unordered_map g_bound_buffers; GLuint bound_array = 0; std::unordered_map g_active_mappings; @@ -222,6 +222,25 @@ void glBindBufferBase(GLenum target, GLuint index, GLuint buffer) { CHECK_GL_ERROR } +void glBindVertexBuffer(GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride) { + LOG() + LOG_D("glBindVertexBuffer, bindingindex = %d, buffer = %d, offset = %p, stride = %i", bindingindex, buffer, offset, stride) + // Todo: should record fake buffer binding here, when glGetVertexArrayIntegeri_v is called, should return fake buffer id + if (!has_buffer(buffer) || buffer == 0) { + GLES.glBindVertexBuffer(bindingindex, buffer, offset, stride); + CHECK_GL_ERROR + return; + } + GLuint real_buffer = find_real_buffer(buffer); + if (!real_buffer) { + GLES.glGenBuffers(1, &real_buffer); + modify_buffer(buffer, real_buffer); + CHECK_GL_ERROR + } + GLES.glBindVertexBuffer(bindingindex, real_buffer, offset, stride); + CHECK_GL_ERROR +} + void glBufferData(GLenum target, GLsizeiptr size, const void *data, GLenum usage) { LOG() LOG_D("glBufferData, target = %s, size = %d, data = 0x%x, usage = %s", diff --git a/src/main/cpp/gl/buffer.h b/src/main/cpp/gl/buffer.h index a8dae3e..fde3056 100644 --- a/src/main/cpp/gl/buffer.h +++ b/src/main/cpp/gl/buffer.h @@ -67,6 +67,8 @@ GLAPI GLAPIENTRY void glBindBufferRange(GLenum target, GLuint index, GLuint buff GLAPI GLAPIENTRY void glBindBufferBase(GLenum target, GLuint index, GLuint buffer); +GLAPI GLAPIENTRY void glBindVertexBuffer(GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); + GLAPI GLAPIENTRY GLboolean glUnmapBuffer(GLenum target); GLAPI GLAPIENTRY void *glMapBuffer(GLenum target, GLenum access); diff --git a/src/main/cpp/gl/gl_native.cpp b/src/main/cpp/gl/gl_native.cpp index e9c1dd5..42a3886 100644 --- a/src/main/cpp/gl/gl_native.cpp +++ b/src/main/cpp/gl/gl_native.cpp @@ -318,7 +318,7 @@ NATIVE_FUNCTION_HEAD(void, glGetMultisamplefv, GLenum pname, GLuint index, GLflo NATIVE_FUNCTION_HEAD(void, glSampleMaski, GLuint maskNumber, GLbitfield mask) NATIVE_FUNCTION_END_NO_RETURN(void, glSampleMaski, maskNumber,mask) //NATIVE_FUNCTION_HEAD(void, glGetTexLevelParameteriv, GLenum target, GLint level, GLenum pname, GLint *params) NATIVE_FUNCTION_END_NO_RETURN(void, glGetTexLevelParameteriv, target,level,pname,params) //NATIVE_FUNCTION_HEAD(void, glGetTexLevelParameterfv, GLenum target, GLint level, GLenum pname, GLfloat *params) NATIVE_FUNCTION_END_NO_RETURN(void, glGetTexLevelParameterfv, target,level,pname,params) -NATIVE_FUNCTION_HEAD(void, glBindVertexBuffer, GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride) NATIVE_FUNCTION_END_NO_RETURN(void, glBindVertexBuffer, bindingindex,buffer,offset,stride) +//NATIVE_FUNCTION_HEAD(void, glBindVertexBuffer, GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride) NATIVE_FUNCTION_END_NO_RETURN(void, glBindVertexBuffer, bindingindex,buffer,offset,stride) NATIVE_FUNCTION_HEAD(void, glVertexAttribFormat, GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset) NATIVE_FUNCTION_END_NO_RETURN(void, glVertexAttribFormat, attribindex,size,type,normalized,relativeoffset) NATIVE_FUNCTION_HEAD(void, glVertexAttribIFormat, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset) NATIVE_FUNCTION_END_NO_RETURN(void, glVertexAttribIFormat, attribindex,size,type,relativeoffset) NATIVE_FUNCTION_HEAD(void, glVertexAttribBinding, GLuint attribindex, GLuint bindingindex) NATIVE_FUNCTION_END_NO_RETURN(void, glVertexAttribBinding, attribindex,bindingindex)