mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2025-02-07 15:31:02 +00:00
- added lock/unlock methods to the buffer implementations.
These are not interchangeable with Map/Unmap! Map/Unmap is for mapping a buffer for updating on old hardware, Lock/Unlock are for manually copying some initialization data directly into a static buffer.
This commit is contained in:
parent
5a4e5a8038
commit
5201501534
3 changed files with 61 additions and 2 deletions
|
@ -60,7 +60,7 @@ void GLVertexBuffer::SetData(size_t size, void *data, bool staticdata)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mPersistent = screen->BuffersArePersistent();
|
mPersistent = screen->BuffersArePersistent() && !staticdata;
|
||||||
if (mPersistent)
|
if (mPersistent)
|
||||||
{
|
{
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
|
glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
|
||||||
|
@ -70,7 +70,7 @@ void GLVertexBuffer::SetData(size_t size, void *data, bool staticdata)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
|
glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
|
||||||
glBufferData(GL_ARRAY_BUFFER, size, NULL, GL_STREAM_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, size, NULL, staticdata ? GL_STATIC_DRAW : GL_STREAM_DRAW);
|
||||||
map = nullptr;
|
map = nullptr;
|
||||||
}
|
}
|
||||||
nomap = false;
|
nomap = false;
|
||||||
|
@ -143,6 +143,31 @@ void GLVertexBuffer::Bind(int *offsets)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//===========================================================================
|
||||||
|
|
||||||
|
void *GLVertexBuffer::Lock(unsigned int size)
|
||||||
|
{
|
||||||
|
SetData(size, nullptr, true);
|
||||||
|
return glMapBufferRange(GL_ARRAY_BUFFER, 0, size, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//===========================================================================
|
||||||
|
|
||||||
|
void GLVertexBuffer::Unlock()
|
||||||
|
{
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
|
||||||
|
glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||||
|
gl_RenderState.ResetVertexBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// Index buffer implementation
|
// Index buffer implementation
|
||||||
|
@ -180,3 +205,29 @@ void GLIndexBuffer::Bind()
|
||||||
{
|
{
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_id);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//===========================================================================
|
||||||
|
|
||||||
|
void *GLIndexBuffer::Lock(unsigned int size)
|
||||||
|
{
|
||||||
|
SetData(size, nullptr, true);
|
||||||
|
return glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER, 0, size, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//===========================================================================
|
||||||
|
|
||||||
|
void GLIndexBuffer::Unlock()
|
||||||
|
{
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_id);
|
||||||
|
glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
|
||||||
|
gl_RenderState.ResetVertexBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,8 @@ public:
|
||||||
void Bind(int *offsets);
|
void Bind(int *offsets);
|
||||||
void Map() override;
|
void Map() override;
|
||||||
void Unmap() override;
|
void Unmap() override;
|
||||||
|
void *Lock(unsigned int size) override;
|
||||||
|
void Unlock() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GLIndexBuffer : public IIndexBuffer
|
class GLIndexBuffer : public IIndexBuffer
|
||||||
|
@ -38,5 +40,7 @@ public:
|
||||||
~GLIndexBuffer();
|
~GLIndexBuffer();
|
||||||
void SetData(size_t size, void *data, bool staticdata) override;
|
void SetData(size_t size, void *data, bool staticdata) override;
|
||||||
void Bind();
|
void Bind();
|
||||||
|
void *Lock(unsigned int size) override;
|
||||||
|
void Unlock() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,8 @@ public:
|
||||||
virtual ~IVertexBuffer() {}
|
virtual ~IVertexBuffer() {}
|
||||||
virtual void SetData(size_t size, void *data, bool staticdata = true) = 0;
|
virtual void SetData(size_t size, void *data, bool staticdata = true) = 0;
|
||||||
virtual void SetFormat(int numBindingPoints, int numAttributes, size_t stride, const FVertexBufferAttribute *attrs) = 0;
|
virtual void SetFormat(int numBindingPoints, int numAttributes, size_t stride, const FVertexBufferAttribute *attrs) = 0;
|
||||||
|
virtual void *Lock(unsigned int size) = 0;
|
||||||
|
virtual void Unlock() = 0;
|
||||||
virtual void Map() {} // Only needed by old OpenGL but this needs to be in the interface.
|
virtual void Map() {} // Only needed by old OpenGL but this needs to be in the interface.
|
||||||
virtual void Unmap() {}
|
virtual void Unmap() {}
|
||||||
void *Memory() { assert(map); return map; }
|
void *Memory() { assert(map); return map; }
|
||||||
|
@ -59,5 +61,7 @@ protected:
|
||||||
public:
|
public:
|
||||||
virtual ~IIndexBuffer() {}
|
virtual ~IIndexBuffer() {}
|
||||||
virtual void SetData(size_t size, void *data, bool staticdata = true) = 0;
|
virtual void SetData(size_t size, void *data, bool staticdata = true) = 0;
|
||||||
|
virtual void *Lock(unsigned int size) = 0;
|
||||||
|
virtual void Unlock() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue