diff --git a/src/BizHawk.Bizware.BizwareGL/IGL.cs b/src/BizHawk.Bizware.BizwareGL/IGL.cs index b921dcfd16..ed7b6d2d23 100644 --- a/src/BizHawk.Bizware.BizwareGL/IGL.cs +++ b/src/BizHawk.Bizware.BizwareGL/IGL.cs @@ -94,15 +94,12 @@ namespace BizHawk.Bizware.BizwareGL void EndScene(); /// - /// 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 /// - void BindArrayData(IntPtr pData); - - /// - /// Draws based on the currently set pipeline, VertexLayout and ArrayData. - /// Count is the VERT COUNT not the primitive count - /// - void DrawArrays(PrimitiveType mode, int first, int count); + void Draw(IntPtr data, int count); /// /// resolves the texture into a new BitmapBuffer diff --git a/src/BizHawk.Bizware.BizwareGL/IGL_GdiPlus.cs b/src/BizHawk.Bizware.BizwareGL/IGL_GdiPlus.cs index 5b1bbe53e2..2dfabc7bdd 100644 --- a/src/BizHawk.Bizware.BizwareGL/IGL_GdiPlus.cs +++ b/src/BizHawk.Bizware.BizwareGL/IGL_GdiPlus.cs @@ -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) { } diff --git a/src/BizHawk.Bizware.BizwareGL/RetroShader.cs b/src/BizHawk.Bizware.BizwareGL/RetroShader.cs index cb1d5db21c..26feb43745 100644 --- a/src/BizHawk.Bizware.BizwareGL/RetroShader.cs +++ b/src/BizHawk.Bizware.BizwareGL/RetroShader.cs @@ -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; diff --git a/src/BizHawk.Bizware.BizwareGL/enums/PrimitiveType.cs b/src/BizHawk.Bizware.BizwareGL/enums/PrimitiveType.cs deleted file mode 100644 index 23643f8ee0..0000000000 --- a/src/BizHawk.Bizware.BizwareGL/enums/PrimitiveType.cs +++ /dev/null @@ -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, - } -} diff --git a/src/BizHawk.Bizware.Graphics/D3D9/IGL_D3D9.cs b/src/BizHawk.Bizware.Graphics/D3D9/IGL_D3D9.cs index d4527ed658..c496a0e875 100644 --- a/src/BizHawk.Bizware.Graphics/D3D9/IGL_D3D9.cs +++ b/src/BizHawk.Bizware.Graphics/D3D9/IGL_D3D9.cs @@ -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 _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); - /// is not - 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(); diff --git a/src/BizHawk.Bizware.Graphics/GuiRenderer.cs b/src/BizHawk.Bizware.Graphics/GuiRenderer.cs index 2bb426694c..69b97978ec 100644 --- a/src/BizHawk.Bizware.Graphics/GuiRenderer.cs +++ b/src/BizHawk.Bizware.Graphics/GuiRenderer.cs @@ -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 diff --git a/src/BizHawk.Bizware.Graphics/OpenGL/IGL_OpenGL.cs b/src/BizHawk.Bizware.Graphics/OpenGL/IGL_OpenGL.cs index abe5f9339e..5b7a34a195 100644 --- a/src/BizHawk.Bizware.Graphics/OpenGL/IGL_OpenGL.cs +++ b/src/BizHawk.Bizware.Graphics/OpenGL/IGL_OpenGL.cs @@ -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) {