- // @TODO: trashing vertex binding, better find target that is rarely used
- buffer->Bind(Graphics::BufferUsage::VERTEX_BUFFER);
- void* ptr = nullptr;
- ptr = gl->MapBufferRange(GL_ARRAY_BUFFER, mMapBufferInfo.offset, mMapBufferInfo.size, GL_MAP_WRITE_BIT);
- mMappedPointer = ptr;
+ auto buffer = static_cast<GLES::Buffer*>(mMapBufferInfo.buffer);
+
+ if(buffer->IsCPUAllocated())
+ {
+ using Ptr = char*;
+ mMappedPointer = Ptr(buffer->GetCPUAllocatedAddress()) + offset;
+ }
+ else
+ {
+ gl->BindBuffer(GL_COPY_WRITE_BUFFER, buffer->GetGLBuffer());
+ void* ptr = nullptr;
+ ptr = gl->MapBufferRange(GL_COPY_WRITE_BUFFER, GLintptr(mMapBufferInfo.offset), GLsizeiptr(mMapBufferInfo.size), GL_MAP_WRITE_BIT);
+ mMappedPointer = ptr;
+ }
+ return mMappedPointer;