ThreadedGraphicsContext improvements.

- VertexBuffer interface redefined to remove an IntPtr overload for SetData. This removes some unsafe code in TerrainSpriteLayer. This also allows the ThreadedVertexBuffer to use a buffer and post these calls, meaning the SetData call can now be non-blocking.
- ThreadedTexture SetData now checks the incoming array size. As the arrays sent here are usually large (megabytes) this allows us to avoid creating temp arrays in the LOH and skip Array.Copy calls on large arrays. This means the call is now blocking more often, but significantly reduces memory churn and GC Gen2 collections.
This commit is contained in:
RoosterDragon
2020-10-11 09:46:41 +01:00
committed by abcdefg30
parent 5eadd26f66
commit b2b639434c
4 changed files with 44 additions and 46 deletions

View File

@@ -57,10 +57,10 @@ namespace OpenRA.Platforms.Default
public void SetData(T[] data, int length)
{
SetData(data, 0, length);
SetData(data, 0, 0, length);
}
public void SetData(T[] data, int start, int length)
public void SetData(T[] data, int offset, int start, int length)
{
Bind();
@@ -70,7 +70,7 @@ namespace OpenRA.Platforms.Default
OpenGL.glBufferSubData(OpenGL.GL_ARRAY_BUFFER,
new IntPtr(VertexSize * start),
new IntPtr(VertexSize * length),
ptr.AddrOfPinnedObject());
ptr.AddrOfPinnedObject() + VertexSize * offset);
}
finally
{
@@ -80,16 +80,6 @@ namespace OpenRA.Platforms.Default
OpenGL.CheckGLError();
}
public void SetData(IntPtr data, int start, int length)
{
Bind();
OpenGL.glBufferSubData(OpenGL.GL_ARRAY_BUFFER,
new IntPtr(VertexSize * start),
new IntPtr(VertexSize * length),
data);
OpenGL.CheckGLError();
}
public void Bind()
{
VerifyThreadAffinity();