simplify IGL 2: Combine BindArrayData and DrawArrays calls into one Draw call: only supports triangle strips (already limitation with D3D9), assumes start is 0, binding and drawing are implicitly merged into a single call (in practice BindArrayData would just save the vertex pointer to some class level variable for DrawArrays, so this is just better all around)
This commit is contained in:
parent
64abeddc2b
commit
3622fe76f9
|
@ -94,15 +94,12 @@ namespace BizHawk.Bizware.BizwareGL
|
|||
void EndScene();
|
||||
|
||||
/// <summary>
|
||||
/// Binds array data for use with the currently-bound pipeline's VertexLayout
|
||||
/// Draws based on the currently set pipeline
|
||||
/// data contains vertexes based on the pipeline's VertexLayout
|
||||
/// count is the vertex count
|
||||
/// Vertexes must form triangle strips
|
||||
/// </summary>
|
||||
void BindArrayData(IntPtr pData);
|
||||
|
||||
/// <summary>
|
||||
/// Draws based on the currently set pipeline, VertexLayout and ArrayData.
|
||||
/// Count is the VERT COUNT not the primitive count
|
||||
/// </summary>
|
||||
void DrawArrays(PrimitiveType mode, int first, int count);
|
||||
void Draw(IntPtr data, int count);
|
||||
|
||||
/// <summary>
|
||||
/// resolves the texture into a new BitmapBuffer
|
||||
|
|
|
@ -37,10 +37,6 @@ namespace BizHawk.Bizware.BizwareGL
|
|||
return null;
|
||||
}
|
||||
|
||||
public void BindArrayData(IntPtr pData)
|
||||
{
|
||||
}
|
||||
|
||||
public void FreeTexture(Texture2d tex)
|
||||
{
|
||||
var tw = (GDIPTextureWrapper)tex.Opaque;
|
||||
|
@ -88,7 +84,7 @@ namespace BizHawk.Bizware.BizwareGL
|
|||
{
|
||||
}
|
||||
|
||||
public void DrawArrays(PrimitiveType mode, int first, int count)
|
||||
public void Draw(IntPtr data, int count)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -126,11 +126,9 @@ namespace BizHawk.Bizware.BizwareGL
|
|||
pData[i++] = 1; pData[i] = v1;
|
||||
|
||||
Owner.SetBlendState(Owner.BlendNoneCopy);
|
||||
Owner.BindArrayData(new(pData));
|
||||
Owner.DrawArrays(PrimitiveType.TriangleStrip, 0, 4);
|
||||
Owner.Draw(new(pData), 4);
|
||||
}
|
||||
|
||||
|
||||
public IGL Owner { get; }
|
||||
|
||||
private readonly VertexLayout VertexLayout;
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
namespace BizHawk.Bizware.BizwareGL
|
||||
{
|
||||
public enum PrimitiveType
|
||||
{
|
||||
Points = 0x0000,
|
||||
Lines = 0x0001,
|
||||
LineLoop = 0x0002,
|
||||
LineStrip = 0x0003,
|
||||
Triangles = 0x0004,
|
||||
TriangleStrip = 0x0005,
|
||||
TriangleFan = 0x0006,
|
||||
Quads = 0x0007,
|
||||
QuadsExt = 0x0007,
|
||||
QuadStrip = 0x0008,
|
||||
Polygon = 0x0009,
|
||||
LinesAdjacency = 0x000A,
|
||||
LinesAdjacencyArb = 0x000A,
|
||||
LinesAdjacencyExt = 0x000A,
|
||||
LineStripAdjacency = 0x000B,
|
||||
LineStripAdjacencyArb = 0x000B,
|
||||
LineStripAdjacencyExt = 0x000B,
|
||||
TrianglesAdjacency = 0x000C,
|
||||
TrianglesAdjacencyArb = 0x000C,
|
||||
TrianglesAdjacencyExt = 0x000C,
|
||||
TriangleStripAdjacency = 0x000D,
|
||||
TriangleStripAdjacencyArb = 0x000D,
|
||||
TriangleStripAdjacencyExt = 0x000D,
|
||||
Patches = 0x000E,
|
||||
PatchesExt = 0x000E,
|
||||
}
|
||||
}
|
|
@ -18,9 +18,6 @@ using SharpDX.Mathematics.Interop;
|
|||
|
||||
using static SDL2.SDL;
|
||||
|
||||
using BizPrimitiveType = BizHawk.Bizware.BizwareGL.PrimitiveType;
|
||||
using D3D9PrimitiveType = SharpDX.Direct3D9.PrimitiveType;
|
||||
|
||||
// todo - do a better job selecting shader model? base on caps somehow? try several and catch compilation exceptions (yuck, exceptions)
|
||||
namespace BizHawk.Bizware.Graphics
|
||||
{
|
||||
|
@ -927,7 +924,7 @@ namespace BizHawk.Bizware.Graphics
|
|||
return ret;
|
||||
}
|
||||
|
||||
private delegate void DrawPrimitiveUPDelegate(Device device, D3D9PrimitiveType primitiveType, int primitiveCount, IntPtr vertexStreamZeroDataRef, int vertexStreamZeroStride);
|
||||
private delegate void DrawPrimitiveUPDelegate(Device device, PrimitiveType primitiveType, int primitiveCount, IntPtr vertexStreamZeroDataRef, int vertexStreamZeroStride);
|
||||
|
||||
private static readonly Lazy<DrawPrimitiveUPDelegate> _drawPrimitiveUP = new(() =>
|
||||
{
|
||||
|
@ -935,23 +932,12 @@ namespace BizHawk.Bizware.Graphics
|
|||
return (DrawPrimitiveUPDelegate)Delegate.CreateDelegate(typeof(DrawPrimitiveUPDelegate), mi!);
|
||||
});
|
||||
|
||||
private void DrawPrimitiveUP(D3D9PrimitiveType primitiveType, int primitiveCount, IntPtr vertexStreamZeroDataRef, int vertexStreamZeroStride)
|
||||
private void DrawPrimitiveUP(PrimitiveType primitiveType, int primitiveCount, IntPtr vertexStreamZeroDataRef, int vertexStreamZeroStride)
|
||||
=> _drawPrimitiveUP.Value(_device, primitiveType, primitiveCount, vertexStreamZeroDataRef, vertexStreamZeroStride);
|
||||
|
||||
/// <exception cref="NotSupportedException"><paramref name="mode"/> is not <see cref="BizwareGL.PrimitiveType.TriangleStrip"/></exception>
|
||||
public void DrawArrays(BizPrimitiveType mode, int first, int count)
|
||||
public void Draw(IntPtr data, int count)
|
||||
{
|
||||
if (mode != BizPrimitiveType.TriangleStrip)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
// for tristrip
|
||||
var primCount = count - 2;
|
||||
|
||||
var pw = (PipelineWrapper)_currPipeline.Opaque;
|
||||
var stride = pw.VertexStride;
|
||||
var ptr = _pVertexData + first * stride;
|
||||
|
||||
// this is stupid, sharpdx only public exposes DrawUserPrimatives
|
||||
// why is this bad? it takes in an array of T
|
||||
|
@ -959,12 +945,9 @@ namespace BizHawk.Bizware.Graphics
|
|||
// since stride for us is just completely variable, this is no good
|
||||
// DrawPrimitiveUP is internal so we have to use this hack to use it directly
|
||||
|
||||
DrawPrimitiveUP(D3D9PrimitiveType.TriangleStrip, primCount, ptr, stride);
|
||||
DrawPrimitiveUP(PrimitiveType.TriangleStrip, count - 2, _pVertexData, pw.VertexStride);
|
||||
}
|
||||
|
||||
public void BindArrayData(IntPtr pData)
|
||||
=> _pVertexData = pData;
|
||||
|
||||
public void BeginScene()
|
||||
{
|
||||
_device.BeginScene();
|
||||
|
|
|
@ -300,8 +300,7 @@ namespace BizHawk.Bizware.Graphics
|
|||
};
|
||||
|
||||
PrepDrawSubrectInternal(art.BaseTexture);
|
||||
Owner.BindArrayData(new(data));
|
||||
Owner.DrawArrays(PrimitiveType.TriangleStrip, 0, 4);
|
||||
Owner.Draw(new(data), 4);
|
||||
}
|
||||
|
||||
private void PrepDrawSubrectInternal(Texture2d tex)
|
||||
|
@ -361,9 +360,7 @@ namespace BizHawk.Bizware.Graphics
|
|||
pData[30] = CornerColors[3].Z;
|
||||
pData[31] = CornerColors[3].W;
|
||||
|
||||
Owner.BindArrayData(new(pData));
|
||||
Owner.DrawArrays(PrimitiveType.TriangleStrip, 0, 4);
|
||||
|
||||
Owner.Draw(new(pData), 4);
|
||||
#if DEBUG
|
||||
Debug.Assert(BlendStateSet);
|
||||
#endif
|
||||
|
|
|
@ -19,14 +19,11 @@ using BizHawk.Common;
|
|||
|
||||
using Silk.NET.OpenGL.Legacy;
|
||||
|
||||
using BizPrimitiveType = BizHawk.Bizware.BizwareGL.PrimitiveType;
|
||||
|
||||
using BizShader = BizHawk.Bizware.BizwareGL.Shader;
|
||||
|
||||
using BizTextureMagFilter = BizHawk.Bizware.BizwareGL.TextureMagFilter;
|
||||
using BizTextureMinFilter = BizHawk.Bizware.BizwareGL.TextureMinFilter;
|
||||
|
||||
using GLPrimitiveType = Silk.NET.OpenGL.Legacy.PrimitiveType;
|
||||
using GLVertexAttribPointerType = Silk.NET.OpenGL.Legacy.VertexAttribPointerType;
|
||||
|
||||
namespace BizHawk.Bizware.Graphics
|
||||
|
@ -369,11 +366,6 @@ namespace BizHawk.Bizware.Graphics
|
|||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)mode);
|
||||
}
|
||||
|
||||
private IntPtr pVertexData;
|
||||
|
||||
public void BindArrayData(IntPtr pData)
|
||||
=> pVertexData = pData;
|
||||
|
||||
private void LegacyBindArrayData(VertexLayout vertexLayout, IntPtr pData)
|
||||
{
|
||||
// DEPRECATED CRAP USED, NEEDED FOR ANCIENT SHADERS
|
||||
|
@ -426,19 +418,19 @@ namespace BizHawk.Bizware.Graphics
|
|||
#pragma warning restore CS0612
|
||||
}
|
||||
|
||||
public void DrawArrays(BizPrimitiveType mode, int first, int count)
|
||||
public void Draw(IntPtr data, int count)
|
||||
{
|
||||
var vertexLayout = _currPipeline?.VertexLayout;
|
||||
|
||||
if (vertexLayout == null || pVertexData == IntPtr.Zero)
|
||||
if (_currPipeline == null)
|
||||
{
|
||||
throw new InvalidOperationException($"Tried to {nameof(DrawArrays)} without bound vertex info!");
|
||||
throw new InvalidOperationException($"Tried to {nameof(Draw)} without pipeline!");
|
||||
}
|
||||
|
||||
var vertexLayout = _currPipeline.VertexLayout;
|
||||
|
||||
if (_currPipeline.Memo != "xgui")
|
||||
{
|
||||
LegacyBindArrayData(vertexLayout, pVertexData);
|
||||
GL.DrawArrays((GLPrimitiveType)mode, first, (uint)count); // these are the same enum
|
||||
LegacyBindArrayData(vertexLayout, data);
|
||||
GL.DrawArrays(PrimitiveType.TriangleStrip, 0, (uint)count);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -451,7 +443,7 @@ namespace BizHawk.Bizware.Graphics
|
|||
|
||||
unsafe
|
||||
{
|
||||
GL.BufferData(GLEnum.ArrayBuffer, new UIntPtr((uint)(count * stride)), (pVertexData + first * stride).ToPointer(), GLEnum.StaticDraw);
|
||||
GL.BufferData(GLEnum.ArrayBuffer, new UIntPtr((uint)(count * stride)), data.ToPointer(), GLEnum.StaticDraw);
|
||||
|
||||
foreach (var (i, item) in vertexLayout.Items)
|
||||
{
|
||||
|
@ -466,7 +458,7 @@ namespace BizHawk.Bizware.Graphics
|
|||
}
|
||||
}
|
||||
|
||||
GL.DrawArrays((GLPrimitiveType)mode, first, (uint)count); // these are the same enum
|
||||
GL.DrawArrays(PrimitiveType.TriangleStrip, 0, (uint)count);
|
||||
|
||||
foreach (var (i, _) in vertexLayout.Items)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue