From f11ba3f11bf8391cf07b29a6e90dca1c0c03fa1b Mon Sep 17 00:00:00 2001 From: Tungstend Date: Sun, 30 Mar 2025 19:21:22 +0800 Subject: [PATCH] Fix(buffer): use real buffer when glTexBuffer(Range) --- src/main/cpp/gl/buffer.cpp | 37 +++++++++++++++++++++++++++++++++++ src/main/cpp/gl/buffer.h | 4 ++++ src/main/cpp/gl/gl_native.cpp | 4 ++-- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/main/cpp/gl/buffer.cpp b/src/main/cpp/gl/buffer.cpp index 7009fe3..56295b9 100644 --- a/src/main/cpp/gl/buffer.cpp +++ b/src/main/cpp/gl/buffer.cpp @@ -241,6 +241,43 @@ void glBindVertexBuffer(GLuint bindingindex, GLuint buffer, GLintptr offset, GLs CHECK_GL_ERROR } +// Todo: any glGet* related to this function? +void glTexBuffer(GLenum target, GLenum internalformat, GLuint buffer) { + LOG() + LOG_D("glTexBuffer, target = %s, internalformat = %s, buffer = %d", glEnumToString(target), glEnumToString(internalformat), buffer) + if (!has_buffer(buffer) || buffer == 0) { + GLES.glTexBuffer(target, internalformat, buffer); + 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.glTexBuffer(target, internalformat, real_buffer); + CHECK_GL_ERROR +} + +void glTexBufferRange(GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size) { + LOG() + LOG_D("glTexBufferRange, target = %s, internalformat = %s, buffer = %d, offset = %p, size = %zi", glEnumToString(target), glEnumToString(internalformat), buffer, (void*) offset, size) + if (!has_buffer(buffer) || buffer == 0) { + GLES.glTexBufferRange(target, internalformat, buffer, offset, size); + 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.glTexBufferRange(target, internalformat, real_buffer, offset, size); + 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 fde3056..4624af4 100644 --- a/src/main/cpp/gl/buffer.h +++ b/src/main/cpp/gl/buffer.h @@ -69,6 +69,10 @@ GLAPI GLAPIENTRY void glBindBufferBase(GLenum target, GLuint index, GLuint buffe GLAPI GLAPIENTRY void glBindVertexBuffer(GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); +GLAPI GLAPIENTRY void glTexBuffer(GLenum target, GLenum internalformat, GLuint buffer); + +GLAPI GLAPIENTRY void glTexBufferRange(GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); + 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 42a3886..f2b64bc 100644 --- a/src/main/cpp/gl/gl_native.cpp +++ b/src/main/cpp/gl/gl_native.cpp @@ -364,7 +364,7 @@ NATIVE_FUNCTION_HEAD(void, glSamplerParameterIiv, GLuint sampler, GLenum pname, NATIVE_FUNCTION_HEAD(void, glSamplerParameterIuiv, GLuint sampler, GLenum pname, const GLuint *param) NATIVE_FUNCTION_END_NO_RETURN(void, glSamplerParameterIuiv, sampler,pname,param) NATIVE_FUNCTION_HEAD(void, glGetSamplerParameterIiv, GLuint sampler, GLenum pname, GLint *params) NATIVE_FUNCTION_END_NO_RETURN(void, glGetSamplerParameterIiv, sampler,pname,params) NATIVE_FUNCTION_HEAD(void, glGetSamplerParameterIuiv, GLuint sampler, GLenum pname, GLuint *params) NATIVE_FUNCTION_END_NO_RETURN(void, glGetSamplerParameterIuiv, sampler,pname,params) -NATIVE_FUNCTION_HEAD(void, glTexBuffer, GLenum target, GLenum internalformat, GLuint buffer) NATIVE_FUNCTION_END_NO_RETURN(void, glTexBuffer, target,internalformat,buffer) -NATIVE_FUNCTION_HEAD(void, glTexBufferRange, GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size) NATIVE_FUNCTION_END_NO_RETURN(void, glTexBufferRange, target,internalformat,buffer,offset,size) +//NATIVE_FUNCTION_HEAD(void, glTexBuffer, GLenum target, GLenum internalformat, GLuint buffer) NATIVE_FUNCTION_END_NO_RETURN(void, glTexBuffer, target,internalformat,buffer) +//NATIVE_FUNCTION_HEAD(void, glTexBufferRange, GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size) NATIVE_FUNCTION_END_NO_RETURN(void, glTexBufferRange, target,internalformat,buffer,offset,size) NATIVE_FUNCTION_HEAD(void, glTexStorage3DMultisample, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations) NATIVE_FUNCTION_END_NO_RETURN(void, glTexStorage3DMultisample, target,samples,internalformat,width,height,depth,fixedsamplelocations) NATIVE_FUNCTION_HEAD(void*, glMapBufferRange, GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access) NATIVE_FUNCTION_END(void*, glMapBufferRange, target,offset,length,access)