From 8e4b1c1c990ee1f4c5be0cbea088c7a79f7dacfe Mon Sep 17 00:00:00 2001 From: nfynt Date: Sat, 1 Apr 2023 14:52:26 +0100 Subject: [PATCH] * fixed mesh vertex buffer modify for OpenGLES support (affecting platforms - WebGL, Android, linux embed, and iOS) --- .../source/RenderAPI_OpenGLCoreES.cpp | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/PluginSource/source/RenderAPI_OpenGLCoreES.cpp b/PluginSource/source/RenderAPI_OpenGLCoreES.cpp index 742e4884..d1e111c4 100644 --- a/PluginSource/source/RenderAPI_OpenGLCoreES.cpp +++ b/PluginSource/source/RenderAPI_OpenGLCoreES.cpp @@ -38,7 +38,12 @@ class RenderAPI_OpenGLCoreES : public RenderAPI { public: RenderAPI_OpenGLCoreES(UnityGfxRenderer apiType); - virtual ~RenderAPI_OpenGLCoreES() { } + virtual ~RenderAPI_OpenGLCoreES() + { +# if SUPPORT_OPENGL_ES + if(m_VertexBufferPtr!=nullptr) free(m_VertexBufferPtr); +# endif + } virtual void ProcessDeviceEvent(UnityGfxDeviceEventType type, IUnityInterfaces* interfaces); @@ -64,6 +69,10 @@ class RenderAPI_OpenGLCoreES : public RenderAPI GLuint m_VertexBuffer; int m_UniformWorldMatrix; int m_UniformProjMatrix; +# if SUPPORT_OPENGL_ES + void* m_VertexBufferPtr; + size_t m_VertexBufferPtrSize; +# endif }; @@ -288,13 +297,20 @@ void RenderAPI_OpenGLCoreES::EndModifyTexture(void* textureHandle, int textureWi void* RenderAPI_OpenGLCoreES::BeginModifyVertexBuffer(void* bufferHandle, size_t* outBufferSize) { -# if SUPPORT_OPENGL_ES - return 0; -# else glBindBuffer(GL_ARRAY_BUFFER, (GLuint)(size_t)bufferHandle); GLint size = 0; glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); *outBufferSize = size; +# if SUPPORT_OPENGL_ES + if(m_VertexBufferPtrSize!=size && m_VertexBufferPtr!=nullptr) + { + free(m_VertexBufferPtr); + m_VertexBufferPtr=nullptr; + } + m_VertexBufferPtr = (m_VertexBufferPtr==nullptr)?malloc(size):m_VertexBufferPtr; + m_VertexBufferPtrSize = size; + return m_VertexBufferPtr; +# else void* mapped = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); return mapped; # endif @@ -303,7 +319,9 @@ void* RenderAPI_OpenGLCoreES::BeginModifyVertexBuffer(void* bufferHandle, size_t void RenderAPI_OpenGLCoreES::EndModifyVertexBuffer(void* bufferHandle) { -# if !SUPPORT_OPENGL_ES +# if SUPPORT_OPENGL_ES + glBufferSubData(GL_ARRAY_BUFFER,0,m_VertexBufferPtrSize,m_VertexBufferPtr); +# else glBindBuffer(GL_ARRAY_BUFFER, (GLuint)(size_t)bufferHandle); glUnmapBuffer(GL_ARRAY_BUFFER); # endif