Skip to content

SUPPORT_OPENGL_ES - fix for modify vertex buffer #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions PluginSource/source/RenderAPI_OpenGLCoreES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
};


Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down