cleanups in Bizware, mostly higher language features like null propagation and expression bodies

This commit is contained in:
adelikat 2020-02-22 12:02:40 -06:00
parent 9008bf269a
commit 9e7bdd2424
24 changed files with 173 additions and 227 deletions

View File

@ -8,8 +8,8 @@ using System.Linq;
using BizHawk.Common.StringExtensions; using BizHawk.Common.StringExtensions;
// the HawkFile class is excessively engineered with the IHawkFileArchiveHandler to decouple the archive handling from the basic file handling. // the HawkFile class is excessively engineered with the IHawkFileArchiveHandler to decouple the archive handling from the basic file handling.
// This is so we could drop in an unamanged dearchiver library optionally later as a performance optimization without ruining the portability of the code. // This is so we could drop in an unmanaged dearchiver library optionally later as a performance optimization without ruining the portability of the code.
// Also, we want to be able to use HawkFiles in BizHawk.Common withuot bringing in a large 7-zip dependency // Also, we want to be able to use HawkFiles in BizHawk.Common without bringing in a large 7-zip dependency
namespace BizHawk.Common namespace BizHawk.Common
{ {
// TODO: // TODO:
@ -165,12 +165,10 @@ namespace BizHawk.Common
/// </summary> /// </summary>
public byte[] ReadAllBytes() public byte[] ReadAllBytes()
{ {
using (Stream stream = GetStream()) using Stream stream = GetStream();
{ var ms = new MemoryStream((int)stream.Length);
var ms = new MemoryStream((int)stream.Length); stream.CopyTo(ms);
stream.CopyTo(ms); return ms.GetBuffer();
return ms.GetBuffer();
}
} }
/// <summary> /// <summary>

View File

@ -376,9 +376,11 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=quicksave/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=quicksave/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Regionable/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Regionable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=regs/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=regs/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Renderers/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=resampling/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=resampling/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=resizer/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=resizer/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=resync/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=resync/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=retroarch/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Rewinder/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Rewinder/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=RLCA/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=RLCA/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Roms/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Roms/@EntryIndexedValue">True</s:Boolean>

View File

@ -20,7 +20,7 @@ namespace BizHawk.Bizware.BizwareGL
Owner = owner; Owner = owner;
} }
public ArtManager Owner { get; private set; } public ArtManager Owner { get; }
public Texture2d BaseTexture { get; internal set; } public Texture2d BaseTexture { get; internal set; }
public float Width, Height; public float Width, Height;

View File

@ -44,8 +44,8 @@ namespace BizHawk.Bizware.BizwareGL
/// </summary> /// </summary>
public Art LoadArt(string path) public Art LoadArt(string path)
{ {
using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) using var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
return LoadArtInternal(new BitmapBuffer(path, new BitmapLoadOptions())); return LoadArtInternal(new BitmapBuffer(path, new BitmapLoadOptions()));
} }
Art LoadArtInternal(BitmapBuffer tex) Art LoadArtInternal(BitmapBuffer tex)
@ -70,23 +70,23 @@ namespace BizHawk.Bizware.BizwareGL
IsOpened = false; IsOpened = false;
IsClosedForever = forever; IsClosedForever = forever;
//first, cleanup old stuff // first, cleanup old stuff
foreach (var tex in ManagedTextures) foreach (var tex in ManagedTextures)
tex.Dispose(); tex.Dispose();
ManagedTextures.Clear(); ManagedTextures.Clear();
//prepare input for atlas process and perform atlas // prepare input for atlas process and perform atlas
//add 2 extra pixels for padding on all sides // add 2 extra pixels for padding on all sides
List<TexAtlas.RectItem> atlasItems = new List<TexAtlas.RectItem>(); var atlasItems = new List<TexAtlas.RectItem>();
foreach (var kvp in ArtLooseTextureAssociation) foreach (var kvp in ArtLooseTextureAssociation)
atlasItems.Add(new TexAtlas.RectItem(kvp.Value.Width+2, kvp.Value.Height+2, kvp)); atlasItems.Add(new TexAtlas.RectItem(kvp.Value.Width+2, kvp.Value.Height+2, kvp));
var results = TexAtlas.PackAtlas(atlasItems); var results = TexAtlas.PackAtlas(atlasItems);
//this isnt supported yet: // this isn't supported yet:
if (results.Atlases.Count > 1) if (results.Atlases.Count > 1)
throw new InvalidOperationException("Art files too big for atlas"); throw new InvalidOperationException("Art files too big for atlas");
//prepare the output buffer // prepare the output buffer
BitmapBuffer bmpResult = new BitmapBuffer(results.Atlases[0].Size); BitmapBuffer bmpResult = new BitmapBuffer(results.Atlases[0].Size);
//for each item, copy it into the output buffer and set the tex parameters on them //for each item, copy it into the output buffer and set the tex parameters on them
@ -142,7 +142,7 @@ namespace BizHawk.Bizware.BizwareGL
/// </summary> /// </summary>
private void AssertIsOpen(bool state) { if (IsOpened != state) throw new InvalidOperationException($"{nameof(ArtManager)} instance is not open!"); } private void AssertIsOpen(bool state) { if (IsOpened != state) throw new InvalidOperationException($"{nameof(ArtManager)} instance is not open!"); }
public IGL Owner { get; private set; } public IGL Owner { get; }
public bool IsOpened { get; private set; } public bool IsOpened { get; private set; }
public bool IsClosedForever { get; private set; } public bool IsClosedForever { get; private set; }
@ -150,16 +150,16 @@ namespace BizHawk.Bizware.BizwareGL
/// <summary> /// <summary>
/// This is used to remember the original bitmap sources for art files. Once the ArtManager is closed forever, this will be purged /// This is used to remember the original bitmap sources for art files. Once the ArtManager is closed forever, this will be purged
/// </summary> /// </summary>
Dictionary<Art, BitmapBuffer> ArtLooseTextureAssociation = new Dictionary<Art, BitmapBuffer>(); readonly Dictionary<Art, BitmapBuffer> ArtLooseTextureAssociation = new Dictionary<Art, BitmapBuffer>();
/// <summary> /// <summary>
/// Physical texture resources, which exist after this ArtManager has been closed /// Physical texture resources, which exist after this ArtManager has been closed
/// </summary> /// </summary>
List<Texture2d> ManagedTextures = new List<Texture2d>(); readonly List<Texture2d> ManagedTextures = new List<Texture2d>();
/// <summary> /// <summary>
/// All the Arts managed by this instance /// All the Arts managed by this instance
/// </summary> /// </summary>
List<Art> ManagedArts = new List<Art>(); readonly List<Art> ManagedArts = new List<Art>();
} }
} }

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
namespace BizHawk.Bizware.BizwareGL namespace BizHawk.Bizware.BizwareGL
{ {

View File

@ -1,6 +1,5 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.Text;
namespace BizHawk.Bizware.BizwareGL namespace BizHawk.Bizware.BizwareGL
{ {

View File

@ -165,10 +165,9 @@ namespace Cyotek.Drawing.BitmapFont
public Size TextureSize { get; set; } public Size TextureSize { get; set; }
public Character this[char character] public Character this[char character] => this.Characters[character];
{ get { return this.Characters[character]; } }
public bool Unicode { get; set; } public bool Unicode { get; set; }
#endregion  Public Properties #endregion  Public Properties

View File

@ -1,7 +1,6 @@
//public domain assumed from cyotek.com //public domain assumed from cyotek.com
using System; using System;
using System.Reflection;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;

View File

@ -32,7 +32,7 @@ namespace BizHawk.Bizware.BizwareGL
public Dictionary<string, string> MapNativeToCode = new Dictionary<string, string>(); public Dictionary<string, string> MapNativeToCode = new Dictionary<string, string>();
} }
Regex rxHlslSamplerCrashWorkaround = new Regex(@"\((.*?)(in sampler2D)(.*?)\)", RegexOptions.Multiline | RegexOptions.IgnoreCase); readonly Regex rxHlslSamplerCrashWorkaround = new Regex(@"\((.*?)(in sampler2D)(.*?)\)", RegexOptions.Multiline | RegexOptions.IgnoreCase);
public Results Run(string code, string entry, string profile, bool hlslHacks) public Results Run(string code, string entry, string profile, bool hlslHacks)
{ {
@ -48,93 +48,97 @@ namespace BizHawk.Bizware.BizwareGL
} }
//http://stackoverflow.com/questions/139593/processstartinfo-hanging-on-waitforexit-why //http://stackoverflow.com/questions/139593/processstartinfo-hanging-on-waitforexit-why
using (Process proc = new Process()) using var proc = new Process
{ {
proc.StartInfo.UseShellExecute = false; StartInfo =
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.Arguments = sbCmdline.ToString();
proc.StartInfo.FileName = CGCBinPath;
StringBuilder output = new StringBuilder(), error = new StringBuilder();
using (AutoResetEvent outputWaitHandle = new AutoResetEvent(false))
using (AutoResetEvent errorWaitHandle = new AutoResetEvent(false))
{ {
proc.OutputDataReceived += (sender, e) => UseShellExecute = false,
{ CreateNoWindow = true,
if (e.Data == null) outputWaitHandle.Set(); RedirectStandardInput = true,
else output.AppendLine(e.Data); RedirectStandardOutput = true,
}; RedirectStandardError = true,
proc.ErrorDataReceived += (sender, e) => Arguments = sbCmdline.ToString(),
{ FileName = CGCBinPath
if (e.Data == null) errorWaitHandle.Set();
else error.AppendLine(e.Data);
};
proc.Start();
new Thread(() =>
{
proc.StandardInput.AutoFlush = true;
proc.StandardInput.Write(code);
proc.StandardInput.Flush();
proc.StandardInput.Close();
}).Start();
proc.BeginOutputReadLine();
proc.BeginErrorReadLine();
proc.WaitForExit();
outputWaitHandle.WaitOne();
errorWaitHandle.WaitOne();
} }
};
bool ok = (proc.ExitCode == 0); StringBuilder output = new StringBuilder(), error = new StringBuilder();
var ret = new Results() using (AutoResetEvent outputWaitHandle = new AutoResetEvent(false))
{
using var errorWaitHandle = new AutoResetEvent(false);
proc.OutputDataReceived += (sender, e) =>
{ {
Succeeded = ok, if (e.Data == null) outputWaitHandle.Set();
Code = output.ToString(), else output.AppendLine(e.Data);
Errors = error.ToString() };
proc.ErrorDataReceived += (sender, e) =>
{
if (e.Data == null) errorWaitHandle.Set();
else error.AppendLine(e.Data);
}; };
if (!ok)
Console.WriteLine(ret.Errors);
if (hlslHacks) proc.Start();
new Thread(() =>
{ {
ret.Code = rxHlslSamplerCrashWorkaround.Replace(ret.Code, m => $"({m.Groups[1].Value}uniform sampler2D{m.Groups[3].Value})"); proc.StandardInput.AutoFlush = true;
} proc.StandardInput.Write(code);
proc.StandardInput.Flush();
proc.StandardInput.Close();
}).Start();
//make variable name map proc.BeginOutputReadLine();
//loop until the first line that doesnt start with a comment proc.BeginErrorReadLine();
var reader = new StringReader(ret.Code); proc.WaitForExit();
for(;;) outputWaitHandle.WaitOne();
{ errorWaitHandle.WaitOne();
var line = reader.ReadLine();
if (line == null) break;
if (!line.StartsWith("//")) break;
if (!line.StartsWith("//var")) continue;
var parts = line.Split(':');
var native_name = parts[0].Split(' ')[2];
var code_name = parts[1].Trim();
if (code_name.StartsWith("TEXUNIT")) code_name = ""; //need parsing differently
if (code_name == "")
code_name = parts[2].Trim();
//remove some array indicators. example: `modelViewProj1[0], 4`
code_name = code_name.Split(',')[0];
code_name = code_name.Split(' ')[0];
if (code_name != "")
{
ret.MapCodeToNative[code_name] = native_name;
ret.MapNativeToCode[native_name] = code_name;
}
}
return ret;
} }
bool ok = (proc.ExitCode == 0);
var ret = new Results
{
Succeeded = ok,
Code = output.ToString(),
Errors = error.ToString()
};
if (!ok)
Console.WriteLine(ret.Errors);
if (hlslHacks)
{
ret.Code = rxHlslSamplerCrashWorkaround.Replace(ret.Code, m => $"({m.Groups[1].Value}uniform sampler2D{m.Groups[3].Value})");
}
//make variable name map
//loop until the first line that doesn't start with a comment
var reader = new StringReader(ret.Code);
for(;;)
{
var line = reader.ReadLine();
if (line == null) break;
if (!line.StartsWith("//")) break;
if (!line.StartsWith("//var")) continue;
var parts = line.Split(':');
var native_name = parts[0].Split(' ')[2];
var code_name = parts[1].Trim();
if (code_name.StartsWith("TEXUNIT")) code_name = ""; //need parsing differently
if (code_name == "")
code_name = parts[2].Trim();
// remove some array indicators. example: `modelViewProj1[0], 4`
code_name = code_name.Split(',')[0];
code_name = code_name.Split(' ')[0];
if (code_name != "")
{
ret.MapCodeToNative[code_name] = native_name;
ret.MapNativeToCode[native_name] = code_name;
}
}
return ret;
} }
} }
} }

View File

@ -1,9 +1,5 @@
using System; using System.Drawing;
using System.Drawing;
using System.Text;
using OpenTK; using OpenTK;
using OpenTK.Graphics;
namespace BizHawk.Bizware.BizwareGL namespace BizHawk.Bizware.BizwareGL
{ {

View File

@ -1,9 +1,6 @@
//this is full of bugs probably, related to state from old rendering sessions being all messed up. its only barely good enough to work at all //this is full of bugs probably, related to state from old rendering sessions being all messed up. its only barely good enough to work at all
using System; using System;
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using OpenTK; using OpenTK;
@ -20,7 +17,7 @@ namespace BizHawk.Bizware.BizwareGL
Owner = gl; Owner = gl;
} }
OpenTK.Graphics.Color4[] CornerColors = new OpenTK.Graphics.Color4[4] { readonly OpenTK.Graphics.Color4[] CornerColors = new OpenTK.Graphics.Color4[4] {
new OpenTK.Graphics.Color4(1.0f,1.0f,1.0f,1.0f),new OpenTK.Graphics.Color4(1.0f,1.0f,1.0f,1.0f),new OpenTK.Graphics.Color4(1.0f,1.0f,1.0f,1.0f),new OpenTK.Graphics.Color4(1.0f,1.0f,1.0f,1.0f) new OpenTK.Graphics.Color4(1.0f,1.0f,1.0f,1.0f),new OpenTK.Graphics.Color4(1.0f,1.0f,1.0f,1.0f),new OpenTK.Graphics.Color4(1.0f,1.0f,1.0f,1.0f),new OpenTK.Graphics.Color4(1.0f,1.0f,1.0f,1.0f)
}; };
@ -41,8 +38,7 @@ namespace BizHawk.Bizware.BizwareGL
public void Dispose() public void Dispose()
{ {
if (CurrentImageAttributes != null) CurrentImageAttributes?.Dispose();
CurrentImageAttributes.Dispose();
} }
@ -273,7 +269,7 @@ namespace BizHawk.Bizware.BizwareGL
var tw = tex.Opaque as GDIPTextureWrapper; var tw = tex.Opaque as GDIPTextureWrapper;
g.PixelOffsetMode = sd.Drawing2D.PixelOffsetMode.Half; g.PixelOffsetMode = sd.Drawing2D.PixelOffsetMode.Half;
g.DrawImage(tw.SDBitmap, destPoints, new sd.RectangleF(sx, sy, sw, sh), sd.GraphicsUnit.Pixel, CurrentImageAttributes); g.DrawImage(tw.SDBitmap, destPoints, new sd.RectangleF(sx, sy, sw, sh), sd.GraphicsUnit.Pixel, CurrentImageAttributes);
g.Transform = new sd.Drawing2D.Matrix(); //.Reset() doesnt work ? ? g.Transform = new sd.Drawing2D.Matrix(); //.Reset() doesn't work ? ?
} }
unsafe void DrawInternal(Art art, float x, float y, float w, float h, bool fx, bool fy) unsafe void DrawInternal(Art art, float x, float y, float w, float h, bool fx, bool fy)
@ -283,8 +279,7 @@ namespace BizHawk.Bizware.BizwareGL
public bool IsActive { get; private set; } public bool IsActive { get; private set; }
public IGL Owner { get; private set; } public IGL Owner { get; }
public IGL Gdi => Owner; public IGL Gdi => Owner;
} }
} }

View File

@ -3,10 +3,6 @@
//why this stupid assert on the blendstate. just set one by default, geeze. //why this stupid assert on the blendstate. just set one by default, geeze.
using System; using System;
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using OpenTK; using OpenTK;
using OpenTK.Graphics.OpenGL; using OpenTK.Graphics.OpenGL;
@ -17,7 +13,7 @@ namespace BizHawk.Bizware.BizwareGL
/// <summary> /// <summary>
/// A simple renderer useful for rendering GUI stuff. /// A simple renderer useful for rendering GUI stuff.
/// When doing GUI rendering, run everything through here (if you need a GL feature not done through here, run it through here first) /// When doing GUI rendering, run everything through here (if you need a GL feature not done through here, run it through here first)
/// Call Begin, then draw, then End, and dont use other Renderers or GL calls in the meantime, unless you know what youre doing. /// Call Begin, then draw, then End, and don't use other Renderers or GL calls in the meantime, unless you know what you're doing.
/// This can perform batching (well.. maybe not yet), which is occasionally necessary for drawing large quantities of things. /// This can perform batching (well.. maybe not yet), which is occasionally necessary for drawing large quantities of things.
/// </summary> /// </summary>
public class GuiRenderer : IDisposable, IGuiRenderer public class GuiRenderer : IDisposable, IGuiRenderer
@ -53,7 +49,7 @@ namespace BizHawk.Bizware.BizwareGL
CurrPipeline = DefaultPipeline = Owner.CreatePipeline(VertexLayout, vs, ps, true, "xgui"); CurrPipeline = DefaultPipeline = Owner.CreatePipeline(VertexLayout, vs, ps, true, "xgui");
} }
OpenTK.Graphics.Color4[] CornerColors = new OpenTK.Graphics.Color4[4] { readonly OpenTK.Graphics.Color4[] CornerColors = new OpenTK.Graphics.Color4[4] {
new OpenTK.Graphics.Color4(1.0f,1.0f,1.0f,1.0f),new OpenTK.Graphics.Color4(1.0f,1.0f,1.0f,1.0f),new OpenTK.Graphics.Color4(1.0f,1.0f,1.0f,1.0f),new OpenTK.Graphics.Color4(1.0f,1.0f,1.0f,1.0f) new OpenTK.Graphics.Color4(1.0f,1.0f,1.0f,1.0f),new OpenTK.Graphics.Color4(1.0f,1.0f,1.0f,1.0f),new OpenTK.Graphics.Color4(1.0f,1.0f,1.0f,1.0f),new OpenTK.Graphics.Color4(1.0f,1.0f,1.0f,1.0f)
}; };
@ -343,10 +339,11 @@ namespace BizHawk.Bizware.BizwareGL
} }
public bool IsActive { get; private set; } public bool IsActive { get; private set; }
public IGL Owner { get; private set; } public IGL Owner { get; }
VertexLayout VertexLayout; readonly VertexLayout VertexLayout;
Pipeline CurrPipeline, DefaultPipeline; Pipeline CurrPipeline;
readonly Pipeline DefaultPipeline;
//state cache //state cache
Texture2d sTexture; Texture2d sTexture;

View File

@ -1,4 +1,3 @@
using System;
using System.Drawing; using System.Drawing;
using System.Collections.Generic; using System.Collections.Generic;
@ -21,7 +20,7 @@ namespace BizHawk.Bizware.BizwareGL
public bool IsDirty; public bool IsDirty;
Stack<Matrix4> stack = new Stack<Matrix4>(); readonly Stack<Matrix4> stack = new Stack<Matrix4>();
/// <summary> /// <summary>
/// This is made public for performance reasons, to avoid lame copies of the matrix when necessary. Don't mess it up! /// This is made public for performance reasons, to avoid lame copies of the matrix when necessary. Don't mess it up!

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
namespace BizHawk.Bizware.BizwareGL namespace BizHawk.Bizware.BizwareGL
@ -59,15 +58,12 @@ namespace BizHawk.Bizware.BizwareGL
return temp; return temp;
} }
internal set internal set => base[key] = value;
{
base[key] = value;
}
} }
} }
SpecialWorkingDictionary UniformsDictionary; readonly SpecialWorkingDictionary UniformsDictionary;
IDictionary<string, PipelineUniform> Uniforms { get { return UniformsDictionary; } } IDictionary<string, PipelineUniform> Uniforms => UniformsDictionary;
public IEnumerable<PipelineUniform> GetUniforms() { return Uniforms.Values; } public IEnumerable<PipelineUniform> GetUniforms() { return Uniforms.Values; }
@ -78,15 +74,12 @@ namespace BizHawk.Bizware.BizwareGL
return ret; return ret;
} }
public PipelineUniform this[string key] public PipelineUniform this[string key] => UniformsDictionary[key];
{
get { return UniformsDictionary[key]; }
}
public IGL Owner { get; private set; } public IGL Owner { get; }
public object Opaque { get; private set; } public object Opaque { get; }
public VertexLayout VertexLayout { get; private set; } public VertexLayout VertexLayout { get; }
public bool Available { get; private set; } public bool Available { get; }
public string Errors { get; set; } public string Errors { get; set; }
public void Dispose() public void Dispose()

View File

@ -23,8 +23,8 @@ namespace BizHawk.Bizware.BizwareGL
_UniformInfos.Add(ui); _UniformInfos.Add(ui);
} }
public IEnumerable<UniformInfo> UniformInfos { get { return _UniformInfos; } } public IEnumerable<UniformInfo> UniformInfos => _UniformInfos;
List<UniformInfo> _UniformInfos = new List<UniformInfo>(); readonly List<UniformInfo> _UniformInfos = new List<UniformInfo>();
/// <returns>the first and only <see cref="UniformInfo"/></returns> /// <returns>the first and only <see cref="UniformInfo"/></returns>
/// <exception cref="InvalidOperationException">more than one <see cref="UniformInfo"/> exists</exception> /// <exception cref="InvalidOperationException">more than one <see cref="UniformInfo"/> exists</exception>
@ -37,54 +37,46 @@ namespace BizHawk.Bizware.BizwareGL
} }
} }
public Pipeline Owner { get; private set; } public Pipeline Owner { get; }
public void Set(Matrix4 mat, bool transpose = false) public void Set(Matrix4 mat, bool transpose = false)
{ {
if (Owner == null) return; //uniform was optimized out Owner?.Owner.SetPipelineUniformMatrix(this, mat, transpose);
Owner.Owner.SetPipelineUniformMatrix(this, mat, transpose);
} }
public void Set(Vector4 vec) public void Set(Vector4 vec)
{ {
if (Owner == null) return; //uniform was optimized out Owner?.Owner.SetPipelineUniform(this, vec);
Owner.Owner.SetPipelineUniform(this, vec);
} }
public void Set(Vector2 vec) public void Set(Vector2 vec)
{ {
if (Owner == null) return; //uniform was optimized out Owner?.Owner.SetPipelineUniform(this, vec);
Owner.Owner.SetPipelineUniform(this, vec);
} }
public void Set(float f) public void Set(float f)
{ {
if (Owner == null) return; //uniform was optimized out Owner?.Owner.SetPipelineUniform(this, f);
Owner.Owner.SetPipelineUniform(this, f);
} }
public void Set(Vector4[] vecs) public void Set(Vector4[] vecs)
{ {
if (Owner == null) return; //uniform was optimized out Owner?.Owner.SetPipelineUniform(this, vecs);
Owner.Owner.SetPipelineUniform(this, vecs);
} }
public void Set(ref Matrix4 mat, bool transpose = false) public void Set(ref Matrix4 mat, bool transpose = false)
{ {
if (Owner == null) return; //uniform was optimized out Owner?.Owner.SetPipelineUniformMatrix(this, ref mat, transpose);
Owner.Owner.SetPipelineUniformMatrix(this, ref mat, transpose);
} }
public void Set(bool value) public void Set(bool value)
{ {
if (Owner == null) return; //uniform was optimized out Owner?.Owner.SetPipelineUniform(this, value);
Owner.Owner.SetPipelineUniform(this, value);
} }
public void Set(Texture2d tex) public void Set(Texture2d tex)
{ {
if (Owner == null) return; //uniform was optimized out Owner?.Owner.SetPipelineUniformSampler(this, tex);
Owner.Owner.SetPipelineUniformSampler(this, tex);
} }
} }
} }

View File

@ -1,6 +1,3 @@
using System;
using System.Collections.Generic;
namespace BizHawk.Bizware.BizwareGL namespace BizHawk.Bizware.BizwareGL
{ {
public interface IBlendState { } public interface IBlendState { }

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
namespace BizHawk.Bizware.BizwareGL namespace BizHawk.Bizware.BizwareGL
{ {
@ -18,9 +17,9 @@ namespace BizHawk.Bizware.BizwareGL
return $"GL RT: {Texture2d.Width}x{Texture2d.Height}"; return $"GL RT: {Texture2d.Width}x{Texture2d.Height}";
} }
public object Opaque { get; private set; } public object Opaque { get; }
public IGL Owner { get; private set; } public IGL Owner { get; }
public Texture2d Texture2d { get; private set; } public Texture2d Texture2d { get; }
public void Unbind() public void Unbind()
{ {

View File

@ -11,9 +11,8 @@ namespace BizHawk.Bizware.BizwareGL
/// </summary> /// </summary>
public class RetroShader : IDisposable public class RetroShader : IDisposable
{ {
//NOTE: we may need to overhaul uniform-setting infrastructure later. // NOTE: we may need to overhaul uniform-setting infrastructure later.
//maybe samplers will need to be set by index and not by name (I think the specs dont dictate what the sampler must be named) // maybe samplers will need to be set by index and not by name (I think the specs don't dictate what the sampler must be named)
public RetroShader(IGL owner, string source, bool debug = false) public RetroShader(IGL owner, string source, bool debug = false)
{ {
Owner = owner; Owner = owner;
@ -37,9 +36,9 @@ namespace BizHawk.Bizware.BizwareGL
return; return;
} }
//retroarch shaders will sometimes not have the right sampler name // retroarch shaders will sometimes not have the right sampler name
//it's unclear whether we should bind to s_p or sampler0 // it's unclear whether we should bind to s_p or sampler0
//lets bind to sampler0 in case we dont have s_p // lets bind to sampler0 in case we don't have s_p
sampler0 = Pipeline.TryGetUniform("s_p"); sampler0 = Pipeline.TryGetUniform("s_p");
if (sampler0 == null) if (sampler0 == null)
{ {
@ -60,10 +59,10 @@ namespace BizHawk.Bizware.BizwareGL
Available = true; Available = true;
} }
public bool Available { get; private set; } public bool Available { get; }
public string Errors { get { return Pipeline.Errors; } } public string Errors => Pipeline.Errors;
PipelineUniform sampler0; private readonly PipelineUniform sampler0;
public void Dispose() public void Dispose()
{ {
@ -131,9 +130,9 @@ namespace BizHawk.Bizware.BizwareGL
} }
public IGL Owner { get; private set; } public IGL Owner { get; }
VertexLayout VertexLayout; readonly VertexLayout VertexLayout;
public Pipeline Pipeline; public Pipeline Pipeline;
} }
} }

View File

@ -1,11 +1,8 @@
using System;
using System.Collections.Generic;
namespace BizHawk.Bizware.BizwareGL namespace BizHawk.Bizware.BizwareGL
{ {
/// <summary> /// <summary>
/// Represents an individual (fragment,vertex) shader. /// Represents an individual (fragment,vertex) shader.
/// It isnt IDisposable because itll be lifecycle-managed by the IGL (disposed when all dependent pipelines are disposed) /// It isn't IDisposable because it'll be lifecycle-managed by the IGL (disposed when all dependent pipelines are disposed)
/// But if you want to be sure to save it for later, use AddRef /// But if you want to be sure to save it for later, use AddRef
/// </summary> /// </summary>
public class Shader public class Shader
@ -18,8 +15,8 @@ namespace BizHawk.Bizware.BizwareGL
Errors = ""; Errors = "";
} }
public IGL Owner { get; private set; } public IGL Owner { get; }
public object Opaque { get; private set; } public object Opaque { get; }
public bool Available { get; private set; } public bool Available { get; private set; }
public string Errors { get; set; } public string Errors { get; set; }

View File

@ -102,7 +102,7 @@ namespace BizHawk.Bizware.BizwareGL
if (!FontInfo.Characters.TryGetValue((char)c, out bfc)) if (!FontInfo.Characters.TryGetValue((char)c, out bfc))
bfc = FontInfo.Characters[unchecked((char)-1)]; bfc = FontInfo.Characters[unchecked((char)-1)];
//calculate texcoords (we shouldve already had this cached, but im speedcoding now) // calculate texcoords (we shouldve already had this cached, but im speedcoding now)
Texture2d tex = TexturePages[bfc.TexturePage]; Texture2d tex = TexturePages[bfc.TexturePage];
float w = tex.Width; float w = tex.Width;
float h = tex.Height; float h = tex.Height;
@ -119,9 +119,9 @@ namespace BizHawk.Bizware.BizwareGL
} }
} }
public IGL Owner { get; private set; } public IGL Owner { get; }
Cyotek.Drawing.BitmapFont.BitmapFont FontInfo; readonly Cyotek.Drawing.BitmapFont.BitmapFont FontInfo;
List<Texture2d> TexturePages = new List<Texture2d>(); List<Texture2d> TexturePages = new List<Texture2d>();
} }

View File

@ -1,9 +1,5 @@
using System; using System;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Drawing; using System.Drawing;
@ -29,10 +25,11 @@ namespace BizHawk.Bizware.BizwareGL
class TryFitParam class TryFitParam
{ {
public TryFitParam(int _w, int _h) { this.w = _w; this.h = _h; } public TryFitParam(int _w, int _h) { this.w = _w; this.h = _h; }
public int w, h; public readonly int w;
public readonly int h;
public bool ok = true; public bool ok = true;
public RectangleBinPack rbp = new RectangleBinPack(); public readonly RectangleBinPack rbp = new RectangleBinPack();
public List<RectangleBinPack.Node> nodes = new List<RectangleBinPack.Node>(); public readonly List<RectangleBinPack.Node> nodes = new List<RectangleBinPack.Node>();
} }
public class PackedAtlasResults public class PackedAtlasResults

View File

@ -1,8 +1,5 @@
using System; using System;
using System.Drawing; using System.Drawing;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL; using OpenTK.Graphics.OpenGL;
namespace BizHawk.Bizware.BizwareGL namespace BizHawk.Bizware.BizwareGL
@ -66,21 +63,21 @@ namespace BizHawk.Bizware.BizwareGL
SetMagFilter(TextureMagFilter.Nearest); SetMagFilter(TextureMagFilter.Nearest);
} }
public IGL Owner { get; private set; } public IGL Owner { get; }
public object Opaque { get; private set; } public object Opaque { get; private set; }
//note.. this was a lame idea. convenient, but weird. lets just change this back to ints. // note.. this was a lame idea. convenient, but weird. lets just change this back to ints.
public float Width { get; private set; } public float Width { get; }
public float Height { get; private set; } public float Height { get; }
public int IntWidth { get { return (int)Width; } } public int IntWidth => (int)Width;
public int IntHeight { get { return (int)Height; } } public int IntHeight => (int)Height;
public Rectangle Rectangle { get { return new Rectangle(0, 0, IntWidth, IntHeight); } } public Rectangle Rectangle => new Rectangle(0, 0, IntWidth, IntHeight);
public Size Size { get { return new Size(IntWidth, IntHeight); } } public Size Size => new Size(IntWidth, IntHeight);
/// <summary> /// <summary>
/// opengl sucks, man. seriously, screw this (textures from render targets are upside down) /// opengl sucks, man. seriously, screw this (textures from render targets are upside down)
/// (couldnt we fix it up in the matrices somewhere?) /// (couldn't we fix it up in the matrices somewhere?)
/// </summary> /// </summary>
public bool IsUpsideDown; public bool IsUpsideDown;
} }

View File

@ -1,6 +1,3 @@
using System;
using System.Collections.Generic;
namespace BizHawk.Bizware.BizwareGL namespace BizHawk.Bizware.BizwareGL
{ {
public class UniformInfo public class UniformInfo

View File

@ -1,6 +1,4 @@
using System; using System;
using System.Collections.Generic;
using BizHawk.Common; using BizHawk.Common;
using OpenTK.Graphics.OpenGL; using OpenTK.Graphics.OpenGL;
@ -9,12 +7,12 @@ namespace BizHawk.Bizware.BizwareGL
{ {
/// <summary> /// <summary>
/// Represents a vertex layout, really a kind of a peer of the vertex and fragment shaders. /// Represents a vertex layout, really a kind of a peer of the vertex and fragment shaders.
/// It isnt IDisposable because itll be lifecycle-managed by the IGL (disposed when all dependent pipelines are disposed) /// It isn't IDisposable because it'll be lifecycle-managed by the IGL (disposed when all dependent pipelines are disposed)
/// But if you want to be sure to save it for later, use AddRef /// But if you want to be sure to save it for later, use AddRef
/// </summary> /// </summary>
public class VertexLayout public class VertexLayout
{ {
//TODO - could refactor to use vertex array objects? check opengl profile requirements (answer: 3.0. dont want to do this.) //TODO - could refactor to use vertex array objects? check opengl profile requirements (answer: 3.0. don't want to do this.)
public VertexLayout(IGL owner, object opaque) public VertexLayout(IGL owner, object opaque)
{ {
@ -23,8 +21,8 @@ namespace BizHawk.Bizware.BizwareGL
Items = new MyDictionary(); Items = new MyDictionary();
} }
public object Opaque { get; private set; } public object Opaque { get; }
public IGL Owner { get; private set; } public IGL Owner { get; }
int RefCount; int RefCount;
@ -74,19 +72,12 @@ namespace BizHawk.Bizware.BizwareGL
{ {
public new LayoutItem this[int key] public new LayoutItem this[int key]
{ {
get get => base[key];
{ internal set => base[key] = value;
return base[key];
}
internal set
{
base[key] = value;
}
} }
} }
public MyDictionary Items { get; private set; } public MyDictionary Items { get; }
bool Closed = false; bool Closed = false;
} }