Add quadIndexBuffer to Renderer

This commit is contained in:
Gustas
2023-08-28 11:14:02 +03:00
committed by Matthias Mailänder
parent 0b90622251
commit 2763e1502b
6 changed files with 29 additions and 21 deletions

View File

@@ -16,9 +16,9 @@ namespace OpenRA.Platforms.Default
{
public class DefaultPlatform : IPlatform
{
public IPlatformWindow CreateWindow(Size size, WindowMode windowMode, float scaleModifier, int batchSize, int videoDisplay, GLProfile profile, bool enableLegacyGL)
public IPlatformWindow CreateWindow(Size size, WindowMode windowMode, float scaleModifier, int vertexBatchSize, int indexBatchSize, int videoDisplay, GLProfile profile, bool enableLegacyGL)
{
return new Sdl2PlatformWindow(size, windowMode, scaleModifier, batchSize, videoDisplay, profile, enableLegacyGL);
return new Sdl2PlatformWindow(size, windowMode, scaleModifier, vertexBatchSize, indexBatchSize, videoDisplay, profile, enableLegacyGL);
}
public ISoundEngine CreateSound(string device)

View File

@@ -133,7 +133,7 @@ namespace OpenRA.Platforms.Default
static extern IntPtr XFlush(IntPtr display);
public Sdl2PlatformWindow(Size requestEffectiveWindowSize, WindowMode windowMode,
float scaleModifier, int batchSize, int videoDisplay, GLProfile requestProfile, bool enableLegacyGL)
float scaleModifier, int vertexBatchSize, int indexBatchSize, int videoDisplay, GLProfile requestProfile, bool enableLegacyGL)
{
// Lock the Window/Surface properties until initialization is complete
lock (syncObject)
@@ -348,7 +348,7 @@ namespace OpenRA.Platforms.Default
Context = ctx;
}
else
Context = new ThreadedGraphicsContext(new Sdl2GraphicsContext(this), batchSize);
Context = new ThreadedGraphicsContext(new Sdl2GraphicsContext(this), vertexBatchSize, indexBatchSize);
Context.SetVSyncEnabled(Game.Settings.Graphics.VSync);

View File

@@ -29,7 +29,8 @@ namespace OpenRA.Platforms.Default
readonly Stack<Message> messagePool = new();
readonly Queue<Message> messages = new();
public readonly int BatchSize;
public readonly int VertexBatchSize;
public readonly int IndexBatchSize;
readonly object syncObject = new();
readonly Thread renderThread;
volatile ExceptionDispatchInfo messageException;
@@ -53,9 +54,10 @@ namespace OpenRA.Platforms.Default
Action<object> doSetBlendMode;
Action<object> doSetVSync;
public ThreadedGraphicsContext(Sdl2GraphicsContext context, int batchSize)
public ThreadedGraphicsContext(Sdl2GraphicsContext context, int vertexBatchSize, int indexBatchSize)
{
BatchSize = batchSize;
VertexBatchSize = vertexBatchSize;
IndexBatchSize = indexBatchSize;
renderThread = new Thread(RenderThread)
{
Name = "ThreadedGraphicsContext RenderThread",
@@ -151,15 +153,15 @@ namespace OpenRA.Platforms.Default
internal Vertex[] GetVertices(int size)
{
lock (verticesPool)
if (size <= BatchSize && verticesPool.Count > 0)
if (size <= VertexBatchSize && verticesPool.Count > 0)
return verticesPool.Pop();
return new Vertex[size < BatchSize ? BatchSize : size];
return new Vertex[size < VertexBatchSize ? VertexBatchSize : size];
}
internal void ReturnVertices(Vertex[] vertices)
{
if (vertices.Length == BatchSize)
if (vertices.Length == VertexBatchSize)
lock (verticesPool)
verticesPool.Push(vertices);
}
@@ -562,7 +564,7 @@ namespace OpenRA.Platforms.Default
public void SetData(Vertex[] vertices, int offset, int start, int length)
{
if (length <= device.BatchSize)
if (length <= device.VertexBatchSize)
{
// If we are able to use a buffer without allocation, post a message to avoid blocking.
var buffer = device.GetVertices(length);