re-add hq2x via shader. add a new Display Configuration dialog (its simple for now).

This commit is contained in:
zeromus 2014-02-03 05:27:59 +00:00
parent 28c1347b75
commit 151b074563
23 changed files with 851 additions and 140 deletions

View File

@ -50,6 +50,7 @@ namespace BizHawk.Client.Common
public bool StackOSDMessages = true;
public int TargetZoomFactor = 2;
public int TargetScanlineFilterIntensity = 0; // choose between 0 and 256
public int TargetDisplayFilter = 0;
public RecentFiles RecentRoms = new RecentFiles(8);
public bool PauseWhenMenuActivated = true;
public bool SaveWindowPosition = true;

View File

@ -191,6 +191,12 @@
<Compile Include="config\ControllerConfig\ControllerConfigPanel.Designer.cs">
<DependentUpon>ControllerConfigPanel.cs</DependentUpon>
</Compile>
<Compile Include="config\DisplayConfigLite.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="config\DisplayConfigLite.Designer.cs">
<DependentUpon>DisplayConfigLite.cs</DependentUpon>
</Compile>
<Compile Include="config\FirmwaresConfig.cs">
<SubType>Form</SubType>
</Compile>
@ -388,7 +394,9 @@
<Compile Include="CustomControls\Win32.cs" />
<Compile Include="DisplayManager\DisplayManager.cs" />
<Compile Include="DisplayManager\DisplaySurface.cs" />
<Compile Include="DisplayManager\FilterManager.cs" />
<Compile Include="DisplayManager\OSDManager.cs" />
<Compile Include="DisplayManager\RenderTargetFrugalizer.cs" />
<Compile Include="DisplayManager\SwappableDisplaySurfaceSet.cs" />
<Compile Include="DisplayManager\TextureFrugalizer.cs" />
<Compile Include="GlobalWin.cs" />
@ -896,6 +904,9 @@
<EmbeddedResource Include="config\DisplayConfig.resx">
<DependentUpon>DisplayConfig.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="config\DisplayConfigLite.resx">
<DependentUpon>DisplayConfigLite.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="config\FirmwaresConfig.resx">
<DependentUpon>FirmwaresConfig.cs</DependentUpon>
</EmbeddedResource>
@ -1149,6 +1160,7 @@
<EmbeddedResource Include="tools\Watch\WatchEditor.resx">
<DependentUpon>WatchEditor.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="DisplayManager\Filters\hq2x.glsl" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>

View File

@ -37,12 +37,22 @@ namespace BizHawk.Client.EmuHawk
Renderer = new GuiRenderer(GL);
VideoTextureFrugalizer = new TextureFrugalizer(GL);
LuaEmuTextureFrugalizer = new TextureFrugalizer(GL);
Video2xFrugalizer = new RenderTargetFrugalizer(GL);
using (var xml = typeof(Program).Assembly.GetManifestResourceStream("BizHawk.Client.EmuHawk.Resources.courier16px.fnt"))
using (var tex = typeof(Program).Assembly.GetManifestResourceStream("BizHawk.Client.EmuHawk.Resources.courier16px_0.png"))
TheOneFont = new StringRenderer(GL, xml, tex);
using (var stream = typeof(Program).Assembly.GetManifestResourceStream("BizHawk.Client.EmuHawk.DisplayManager.Filters.hq2x.glsl"))
{
var str = new System.IO.StreamReader(stream).ReadToEnd();
RetroShader_Hq2x = new Bizware.BizwareGL.Drivers.OpenTK.RetroShader(GL, str);
}
}
Bizware.BizwareGL.Drivers.OpenTK.RetroShader RetroShader_Hq2x;
public bool Disposed { get; private set; }
public void Dispose()
@ -78,6 +88,7 @@ namespace BizHawk.Client.EmuHawk
int currEmuWidth, currEmuHeight;
TextureFrugalizer VideoTextureFrugalizer, LuaEmuTextureFrugalizer;
RenderTargetFrugalizer Video2xFrugalizer;
/// <summary>
/// This will receive an emulated output frame from an IVideoProvider and run it through the complete frame processing pipeline
@ -101,18 +112,31 @@ namespace BizHawk.Client.EmuHawk
luaEmuTexture = LuaEmuTextureFrugalizer.Get(luaEmuSurface);
//apply filter chain (currently, over-simplified)
Texture2d currentTexture = videoTexture;
if (Global.Config.TargetDisplayFilter == 1)
{
var rt = Video2xFrugalizer.Get(videoTexture.IntWidth*2,videoTexture.IntHeight*2);
rt.Bind();
Size outSize = new Size(videoTexture.IntWidth * 2, videoTexture.IntHeight * 2);
RetroShader_Hq2x.Run(videoTexture, videoTexture.Size, outSize, true);
currentTexture = rt.Texture2d;
}
//begin drawing to the PresentationPanel:
GraphicsControl.Begin();
//1. clear it with the background color that the emulator specified
GL.SetClearColor(Color.FromArgb(videoProvider.BackgroundColor));
GL.Clear(OpenTK.Graphics.OpenGL.ClearBufferMask.ColorBufferBit);
//2. begin 2d rendering
Renderer.Begin(GraphicsControl.Width, GraphicsControl.Height);
//3. figure out how to draw the emulator output content
var LL = new LetterboxingLogic(GraphicsControl.Width, GraphicsControl.Height, bb.Width, bb.Height);
var LL = new LetterboxingLogic(GraphicsControl.Width, GraphicsControl.Height, currentTexture.IntWidth, currentTexture.IntHeight);
//4. draw the emulator content
Renderer.SetBlendState(GL.BlendNone);
@ -123,7 +147,7 @@ namespace BizHawk.Client.EmuHawk
videoTexture.SetFilterLinear();
else
videoTexture.SetFilterNearest();
Renderer.Draw(videoTexture);
Renderer.Draw(currentTexture);
//4.b draw the "lua emu surface" which is designed for art matching up exactly with the emulator output
Renderer.SetBlendState(GL.BlendNormal);
if(luaEmuTexture != null) Renderer.Draw(luaEmuTexture);

View File

@ -0,0 +1,77 @@
//https://github.com/Themaister/RetroArch/wiki/GLSL-shaders
//https://github.com/Themaister/Emulator-Shader-Pack/blob/master/Cg/README
using System;
using System.Drawing;
using BizHawk.Common;
using BizHawk.Client.Common;
using BizHawk.Bizware.BizwareGL;
//Here, I started making code to support GUI editing of filter chains.
//I decided to go for broke and implement retroarch's system first, and then the GUI editing should be able to internally produce a metashader
//namespace BizHawk.Client.EmuHawk
//{
// class FilterManager
// {
// class PipelineState
// {
// public PipelineState(PipelineState other)
// {
// Size = other.Size;
// Format = other.Format;
// }
// public Size Size;
// public string Format;
// }
// abstract class BaseFilter
// {
// bool Connect(FilterChain chain, BaseFilter parent)
// {
// Chain = chain;
// Parent = parent;
// return OnConnect();
// }
// public PipelineState OutputState;
// public FilterChain Chain;
// public BaseFilter Parent;
// public abstract bool OnConnect();
// }
// class FilterChain
// {
// public void AddFilter(BaseFilter filter)
// {
// }
// }
// class Filter_Grayscale : BaseFilter
// {
// public override bool OnConnect()
// {
// if(Parent.OutputState.Format != "rgb") return false;
// OutputState = new PipelineState { Parent.OutputState; }
// }
// }
// class Filter_EmuOutput_RGBA : BaseFilter
// {
// public Filter_EmuOutput_RGBA(int width, int height)
// {
// OutputState = new PipelineState() { Size = new Size(width, height), Format = "rgb" };
// }
// public override bool OnConnect()
// {
// return true;
// }
// }
// }
//}

View File

@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Client.Common;
using BizHawk.Bizware.BizwareGL;
namespace BizHawk.Client.EmuHawk
{
/// <summary>
/// Recycles a pair of temporary render targets, as long as the dimensions match.
/// When the dimensions dont match, a new one will be allocated
/// </summary>
class RenderTargetFrugalizer : IDisposable
{
public RenderTargetFrugalizer(IGL gl)
{
GL = gl;
ResetList();
}
public void Dispose()
{
foreach (var ct in CurrentRenderTargets)
if (ct != null)
ct.Dispose();
ResetList();
}
void ResetList()
{
CurrentRenderTargets = new List<RenderTarget>();
CurrentRenderTargets.Add(null);
CurrentRenderTargets.Add(null);
}
IGL GL;
List<RenderTarget> CurrentRenderTargets;
public RenderTarget Get(int width, int height)
{
//get the current entry
RenderTarget CurrentRenderTarget = CurrentRenderTargets[0];
//check if its rotten and needs recreating
if (CurrentRenderTarget == null || CurrentRenderTarget.Texture2d.IntWidth != width || CurrentRenderTarget.Texture2d.IntHeight != height)
{
//needs recreating. be sure to kill the old one...
if (CurrentRenderTarget != null)
CurrentRenderTarget.Dispose();
//and make a new one
CurrentRenderTarget = GL.CreateRenderTarget(width, height);
}
else
{
//its good! nothing more to do
}
//now shuffle the buffers
CurrentRenderTargets.Insert(0, CurrentRenderTargets[1]);
CurrentRenderTargets[1] = CurrentRenderTarget;
return CurrentRenderTarget;
}
}
}

View File

@ -132,6 +132,7 @@
this.SoundMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.AutofireMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.RewindOptionsMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.DisplayConfigMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.FirmwaresMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator9 = new System.Windows.Forms.ToolStripSeparator();
this.ConfigEnableSubMenu = new System.Windows.Forms.ToolStripMenuItem();
@ -1098,42 +1099,42 @@
// x1MenuItem
//
this.x1MenuItem.Name = "x1MenuItem";
this.x1MenuItem.Size = new System.Drawing.Size(152, 22);
this.x1MenuItem.Size = new System.Drawing.Size(94, 22);
this.x1MenuItem.Text = "&1x";
this.x1MenuItem.Click += new System.EventHandler(this.WindowSize_Click);
//
// x2MenuItem
//
this.x2MenuItem.Name = "x2MenuItem";
this.x2MenuItem.Size = new System.Drawing.Size(152, 22);
this.x2MenuItem.Size = new System.Drawing.Size(94, 22);
this.x2MenuItem.Text = "&2x";
this.x2MenuItem.Click += new System.EventHandler(this.WindowSize_Click);
//
// x3MenuItem
//
this.x3MenuItem.Name = "x3MenuItem";
this.x3MenuItem.Size = new System.Drawing.Size(152, 22);
this.x3MenuItem.Size = new System.Drawing.Size(94, 22);
this.x3MenuItem.Text = "&3x";
this.x3MenuItem.Click += new System.EventHandler(this.WindowSize_Click);
//
// x4MenuItem
//
this.x4MenuItem.Name = "x4MenuItem";
this.x4MenuItem.Size = new System.Drawing.Size(152, 22);
this.x4MenuItem.Size = new System.Drawing.Size(94, 22);
this.x4MenuItem.Text = "&4x";
this.x4MenuItem.Click += new System.EventHandler(this.WindowSize_Click);
//
// x5MenuItem
//
this.x5MenuItem.Name = "x5MenuItem";
this.x5MenuItem.Size = new System.Drawing.Size(152, 22);
this.x5MenuItem.Size = new System.Drawing.Size(94, 22);
this.x5MenuItem.Text = "&5x";
this.x5MenuItem.Click += new System.EventHandler(this.WindowSize_Click);
//
// mzMenuItem
//
this.mzMenuItem.Name = "mzMenuItem";
this.mzMenuItem.Size = new System.Drawing.Size(152, 22);
this.mzMenuItem.Size = new System.Drawing.Size(94, 22);
this.mzMenuItem.Text = "&Max";
this.mzMenuItem.Click += new System.EventHandler(this.WindowSize_Click);
//
@ -1221,6 +1222,7 @@
this.SoundMenuItem,
this.AutofireMenuItem,
this.RewindOptionsMenuItem,
this.DisplayConfigMenuItem,
this.FirmwaresMenuItem,
this.toolStripSeparator9,
this.ConfigEnableSubMenu,
@ -1294,6 +1296,13 @@
this.RewindOptionsMenuItem.Text = "&Rewind...";
this.RewindOptionsMenuItem.Click += new System.EventHandler(this.RewindOptionsMenuItem_Click);
//
// DisplayConfigMenuItem
//
this.DisplayConfigMenuItem.Name = "DisplayConfigMenuItem";
this.DisplayConfigMenuItem.Size = new System.Drawing.Size(152, 22);
this.DisplayConfigMenuItem.Text = "Display...";
this.DisplayConfigMenuItem.Click += new System.EventHandler(this.DisplayConfigMenuItem_Click);
//
// FirmwaresMenuItem
//
this.FirmwaresMenuItem.Name = "FirmwaresMenuItem";
@ -3335,6 +3344,7 @@
private System.Windows.Forms.ToolStripMenuItem gBInSGBToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem nESInQuickNESToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem batchRunnerToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem DisplayConfigMenuItem;
}
}

View File

@ -3005,5 +3005,13 @@ namespace BizHawk.Client.EmuHawk
gBInSGBToolStripMenuItem.Checked = Global.Config.GB_AsSGB;
nESInQuickNESToolStripMenuItem.Checked = Global.Config.NES_InQuickNES;
}
private void DisplayConfigMenuItem_Click(object sender, EventArgs e)
{
new config.DisplayConfigLite().ShowDialog();
}
}
}

View File

@ -29,23 +29,23 @@
private void InitializeComponent()
{
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.button1 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.listView2 = new System.Windows.Forms.ListView();
this.label1 = new System.Windows.Forms.Label();
this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.panel1 = new System.Windows.Forms.Panel();
this.listView2 = new System.Windows.Forms.ListView();
this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.label1 = new System.Windows.Forms.Label();
this.panel2 = new System.Windows.Forms.Panel();
this.button2 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.panel3 = new System.Windows.Forms.Panel();
this.label2 = new System.Windows.Forms.Label();
this.panel4 = new System.Windows.Forms.Panel();
this.listView1 = new System.Windows.Forms.ListView();
this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.label2 = new System.Windows.Forms.Label();
this.panel4 = new System.Windows.Forms.Panel();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.tableLayoutPanel1.SuspendLayout();
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
@ -73,16 +73,6 @@
this.tableLayoutPanel1.Size = new System.Drawing.Size(557, 433);
this.tableLayoutPanel1.TabIndex = 1;
//
// button1
//
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button1.Location = new System.Drawing.Point(74, 3);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 2;
this.button1.Text = "OK";
this.button1.UseVisualStyleBackColor = true;
//
// button3
//
this.button3.Location = new System.Drawing.Point(3, 407);
@ -92,6 +82,16 @@
this.button3.Text = "Defaults";
this.button3.UseVisualStyleBackColor = true;
//
// panel1
//
this.panel1.Controls.Add(this.listView2);
this.panel1.Controls.Add(this.label1);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(330, 3);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(224, 398);
this.panel1.TabIndex = 7;
//
// listView2
//
this.listView2.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
@ -104,6 +104,11 @@
this.listView2.UseCompatibleStateImageBehavior = false;
this.listView2.View = System.Windows.Forms.View.Details;
//
// columnHeader4
//
this.columnHeader4.Text = "";
this.columnHeader4.Width = 101;
//
// label1
//
this.label1.AutoSize = true;
@ -114,21 +119,6 @@
this.label1.TabIndex = 6;
this.label1.Text = "Library";
//
// columnHeader4
//
this.columnHeader4.Text = "";
this.columnHeader4.Width = 101;
//
// panel1
//
this.panel1.Controls.Add(this.listView2);
this.panel1.Controls.Add(this.label1);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(330, 3);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(224, 398);
this.panel1.TabIndex = 7;
//
// panel2
//
this.panel2.AutoSize = true;
@ -151,6 +141,16 @@
this.button2.Text = "Cancel";
this.button2.UseVisualStyleBackColor = true;
//
// button1
//
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button1.Location = new System.Drawing.Point(74, 3);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 2;
this.button1.Text = "OK";
this.button1.UseVisualStyleBackColor = true;
//
// panel3
//
this.panel3.Controls.Add(this.listView1);
@ -162,26 +162,6 @@
this.panel3.Size = new System.Drawing.Size(321, 398);
this.panel3.TabIndex = 9;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Dock = System.Windows.Forms.DockStyle.Top;
this.label2.Location = new System.Drawing.Point(0, 0);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(172, 13);
this.label2.TabIndex = 7;
this.label2.Text = "Current Layers/Filters Configuration";
//
// panel4
//
this.panel4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panel4.Controls.Add(this.groupBox1);
this.panel4.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel4.Location = new System.Drawing.Point(0, 298);
this.panel4.Name = "panel4";
this.panel4.Size = new System.Drawing.Size(321, 100);
this.panel4.TabIndex = 4;
//
// listView1
//
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
@ -211,15 +191,25 @@
this.columnHeader3.Text = "Description";
this.columnHeader3.Width = 88;
//
// checkBox1
// label2
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(6, 19);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(85, 17);
this.checkBox1.TabIndex = 0;
this.checkBox1.Text = "Bilinear Filter";
this.checkBox1.UseVisualStyleBackColor = true;
this.label2.AutoSize = true;
this.label2.Dock = System.Windows.Forms.DockStyle.Top;
this.label2.Location = new System.Drawing.Point(0, 0);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(172, 13);
this.label2.TabIndex = 7;
this.label2.Text = "Current Layers/Filters Configuration";
//
// panel4
//
this.panel4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panel4.Controls.Add(this.groupBox1);
this.panel4.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel4.Location = new System.Drawing.Point(0, 298);
this.panel4.Name = "panel4";
this.panel4.Size = new System.Drawing.Size(321, 100);
this.panel4.TabIndex = 4;
//
// groupBox1
//
@ -231,6 +221,16 @@
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Final Presentation:";
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(6, 19);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(85, 17);
this.checkBox1.TabIndex = 0;
this.checkBox1.Text = "Bilinear Filter";
this.checkBox1.UseVisualStyleBackColor = true;
//
// DisplayConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

View File

@ -0,0 +1,161 @@
namespace BizHawk.Client.EmuHawk.config
{
partial class DisplayConfigLite
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnCancel = new System.Windows.Forms.Button();
this.btnOk = new System.Windows.Forms.Button();
this.checkBilinearFilter = new System.Windows.Forms.CheckBox();
this.label1 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.rbHq2x = new System.Windows.Forms.RadioButton();
this.rbScanlines = new System.Windows.Forms.RadioButton();
this.rbNone = new System.Windows.Forms.RadioButton();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// btnCancel
//
this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Location = new System.Drawing.Point(205, 201);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(75, 23);
this.btnCancel.TabIndex = 5;
this.btnCancel.Text = "Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
//
// btnOk
//
this.btnOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnOk.Location = new System.Drawing.Point(124, 201);
this.btnOk.Name = "btnOk";
this.btnOk.Size = new System.Drawing.Size(75, 23);
this.btnOk.TabIndex = 4;
this.btnOk.Text = "OK";
this.btnOk.UseVisualStyleBackColor = true;
this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
//
// checkBilinearFilter
//
this.checkBilinearFilter.AutoSize = true;
this.checkBilinearFilter.Location = new System.Drawing.Point(12, 143);
this.checkBilinearFilter.Name = "checkBilinearFilter";
this.checkBilinearFilter.Size = new System.Drawing.Size(85, 17);
this.checkBilinearFilter.TabIndex = 0;
this.checkBilinearFilter.Text = "Bilinear Filter";
this.checkBilinearFilter.UseVisualStyleBackColor = true;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(269, 13);
this.label1.TabIndex = 6;
this.label1.Text = "This is a staging ground for more complex configuration.";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.rbNone);
this.groupBox1.Controls.Add(this.rbScanlines);
this.groupBox1.Controls.Add(this.rbHq2x);
this.groupBox1.Location = new System.Drawing.Point(12, 34);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(200, 92);
this.groupBox1.TabIndex = 7;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Filter";
//
// rbHq2x
//
this.rbHq2x.AutoSize = true;
this.rbHq2x.Location = new System.Drawing.Point(14, 42);
this.rbHq2x.Name = "rbHq2x";
this.rbHq2x.Size = new System.Drawing.Size(50, 17);
this.rbHq2x.TabIndex = 0;
this.rbHq2x.TabStop = true;
this.rbHq2x.Text = "Hq2x";
this.rbHq2x.UseVisualStyleBackColor = true;
//
// rbScanlines
//
this.rbScanlines.AutoSize = true;
this.rbScanlines.Location = new System.Drawing.Point(14, 65);
this.rbScanlines.Name = "rbScanlines";
this.rbScanlines.Size = new System.Drawing.Size(71, 17);
this.rbScanlines.TabIndex = 1;
this.rbScanlines.TabStop = true;
this.rbScanlines.Text = "Scanlines";
this.rbScanlines.UseVisualStyleBackColor = true;
//
// rbNone
//
this.rbNone.AutoSize = true;
this.rbNone.Location = new System.Drawing.Point(14, 19);
this.rbNone.Name = "rbNone";
this.rbNone.Size = new System.Drawing.Size(51, 17);
this.rbNone.TabIndex = 2;
this.rbNone.TabStop = true;
this.rbNone.Text = "None";
this.rbNone.UseVisualStyleBackColor = true;
//
// DisplayConfigLite
//
this.AcceptButton = this.btnOk;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.btnCancel;
this.ClientSize = new System.Drawing.Size(292, 236);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.checkBilinearFilter);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOk);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "DisplayConfigLite";
this.Text = "Display Configuration";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Button btnOk;
private System.Windows.Forms.CheckBox checkBilinearFilter;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.RadioButton rbNone;
private System.Windows.Forms.RadioButton rbScanlines;
private System.Windows.Forms.RadioButton rbHq2x;
}
}

View File

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BizHawk.Emulation.Common;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk.config
{
public partial class DisplayConfigLite : Form
{
public DisplayConfigLite()
{
InitializeComponent();
rbNone.Checked = Global.Config.TargetDisplayFilter == 0;
rbHq2x.Checked = Global.Config.TargetDisplayFilter == 1;
rbScanlines.Checked = Global.Config.TargetDisplayFilter == 2;
checkBilinearFilter.Checked = Global.Config.DispBlurry;
}
private void btnOk_Click(object sender, EventArgs e)
{
if(rbNone.Checked)
Global.Config.TargetDisplayFilter = 0;
if (rbHq2x.Checked)
Global.Config.TargetDisplayFilter = 1;
if (rbScanlines.Checked)
Global.Config.TargetDisplayFilter = 2;
Global.Config.DispBlurry = checkBilinearFilter.Checked;
DialogResult = System.Windows.Forms.DialogResult.OK;
Close();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -63,6 +63,7 @@
<SubType>UserControl</SubType>
</Compile>
<Compile Include="IGL_TK.cs" />
<Compile Include="RetroShader.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@ -66,16 +66,16 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
GraphicsContext.Dispose(); GraphicsContext = null;
}
void IGL.Clear(ClearBufferMask mask)
public void Clear(ClearBufferMask mask)
{
GL.Clear((global::OpenTK.Graphics.OpenGL.ClearBufferMask)mask);
}
void IGL.SetClearColor(sd.Color color)
public void SetClearColor(sd.Color color)
{
GL.ClearColor(color);
}
IGraphicsControl IGL.Internal_CreateGraphicsControl()
public IGraphicsControl Internal_CreateGraphicsControl()
{
var glc = new GLControlWrapper(this);
glc.CreateControl();
@ -87,18 +87,18 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
return glc;
}
IntPtr IGL.GenTexture() { return new IntPtr(GL.GenTexture()); }
void IGL.FreeTexture(IntPtr texHandle) { GL.DeleteTexture(texHandle.ToInt32()); }
IntPtr IGL.GetEmptyHandle() { return new IntPtr(0); }
IntPtr IGL.GetEmptyUniformHandle() { return new IntPtr(-1); }
public IntPtr GenTexture() { return new IntPtr(GL.GenTexture()); }
public void FreeTexture(IntPtr texHandle) { GL.DeleteTexture(texHandle.ToInt32()); }
public IntPtr GetEmptyHandle() { return new IntPtr(0); }
public IntPtr GetEmptyUniformHandle() { return new IntPtr(-1); }
Shader IGL.CreateFragmentShader(string source)
public Shader CreateFragmentShader(string source)
{
int sid = GL.CreateShader(ShaderType.FragmentShader);
CompileShaderSimple(sid,source);
return new Shader(this,new IntPtr(sid));
}
Shader IGL.CreateVertexShader(string source)
public Shader CreateVertexShader(string source)
{
int sid = GL.CreateShader(ShaderType.VertexShader);
CompileShaderSimple(sid, source);
@ -106,7 +106,7 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
return new Shader(this, new IntPtr(sid));
}
void IGL.FreeShader(IntPtr shader) { GL.DeleteShader(shader.ToInt32()); }
public void FreeShader(IntPtr shader) { GL.DeleteShader(shader.ToInt32()); }
class MyBlendState : IBlendState
{
@ -129,13 +129,13 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
this.alphaDest = (global::OpenTK.Graphics.OpenGL.BlendingFactorDest)alphaDest;
}
}
IBlendState IGL.CreateBlendState(BlendingFactorSrc colorSource, BlendEquationMode colorEquation, BlendingFactorDest colorDest,
public IBlendState CreateBlendState(BlendingFactorSrc colorSource, BlendEquationMode colorEquation, BlendingFactorDest colorDest,
BlendingFactorSrc alphaSource, BlendEquationMode alphaEquation, BlendingFactorDest alphaDest)
{
return new MyBlendState(true, colorSource, colorEquation, colorDest, alphaSource, alphaEquation, alphaDest);
}
void IGL.SetBlendState(IBlendState rsBlend)
public void SetBlendState(IBlendState rsBlend)
{
var mybs = rsBlend as MyBlendState;
if (mybs.enabled)
@ -147,10 +147,10 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
else GL.Disable(EnableCap.Blend);
}
IBlendState IGL.BlendNone { get { return _rsBlendNone; } }
IBlendState IGL.BlendNormal { get { return _rsBlendNormal; } }
public IBlendState BlendNone { get { return _rsBlendNone; } }
public IBlendState BlendNormal { get { return _rsBlendNormal; } }
Pipeline IGL.CreatePipeline(Shader vertexShader, Shader fragmentShader)
public Pipeline CreatePipeline(VertexLayout vertexLayout, Shader vertexShader, Shader fragmentShader)
{
ErrorCode errcode;
int pid = GL.CreateProgram();
@ -158,6 +158,10 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
errcode = GL.GetError();
GL.AttachShader(pid, fragmentShader.Id.ToInt32());
errcode = GL.GetError();
//bind the attribute locations from the vertex layout
foreach (var kvp in vertexLayout.Items)
GL.BindAttribLocation(pid, kvp.Key, kvp.Value.Name);
GL.LinkProgram(pid);
errcode = GL.GetError();
@ -196,6 +200,19 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
//set the program to active, in case we need to set sampler uniforms on it
GL.UseProgram(pid);
////get all the attributes (not needed)
//List<AttributeInfo> attributes = new List<AttributeInfo>();
//int nAttributes;
//GL.GetProgram(pid, GetProgramParameterName.ActiveAttributes, out nAttributes);
//for (int i = 0; i < nAttributes; i++)
//{
// int size, length;
// var sbName = new System.Text.StringBuilder();
// ActiveAttribType type;
// GL.GetActiveAttrib(pid, i, 1024, out length, out size, out type, sbName);
// attributes.Add(new AttributeInfo() { Handle = new IntPtr(i), Name = sbName.ToString() });
//}
//get all the uniforms
List<UniformInfo> uniforms = new List<UniformInfo>();
int nUniforms;
@ -230,53 +247,59 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
//deactivate the program, so we dont accidentally use it
GL.UseProgram(0);
return new Pipeline(this, new IntPtr(pid), uniforms);
return new Pipeline(this, new IntPtr(pid), vertexLayout, uniforms);
}
VertexLayout IGL.CreateVertexLayout() { return new VertexLayout(this,new IntPtr(0)); }
public VertexLayout CreateVertexLayout() { return new VertexLayout(this, new IntPtr(0)); }
void IGL.BindTexture2d(Texture2d tex)
public void BindTexture2d(Texture2d tex)
{
GL.BindTexture(TextureTarget.Texture2D, tex.Id.ToInt32());
}
unsafe void IGL.BindVertexLayout(VertexLayout layout)
{
sStatePendingVertexLayout = layout;
}
unsafe void IGL.BindArrayData(void* pData)
public unsafe void BindArrayData(void* pData)
{
MyBindArrayData(sStatePendingVertexLayout, pData);
}
void IGL.DrawArrays(PrimitiveType mode, int first, int count)
public void DrawArrays(PrimitiveType mode, int first, int count)
{
GL.DrawArrays((global::OpenTK.Graphics.OpenGL.PrimitiveType)mode, first, count);
}
void IGL.BindPipeline(Pipeline pipeline)
public void BindPipeline(Pipeline pipeline)
{
sStatePendingVertexLayout = pipeline.VertexLayout;
GL.UseProgram(pipeline.Id.ToInt32());
}
unsafe void IGL.SetPipelineUniformMatrix(PipelineUniform uniform, Matrix4 mat, bool transpose)
public unsafe void SetPipelineUniformMatrix(PipelineUniform uniform, Matrix4 mat, bool transpose)
{
GL.UniformMatrix4(uniform.Id.ToInt32(), 1, transpose, (float*)&mat);
}
unsafe void IGL.SetPipelineUniformMatrix(PipelineUniform uniform, ref Matrix4 mat, bool transpose)
public unsafe void SetPipelineUniformMatrix(PipelineUniform uniform, ref Matrix4 mat, bool transpose)
{
fixed(Matrix4* pMat = &mat)
GL.UniformMatrix4(uniform.Id.ToInt32(), 1, transpose, (float*)pMat);
}
void IGL.SetPipelineUniform(PipelineUniform uniform, Vector4 value)
public void SetPipelineUniform(PipelineUniform uniform, Vector4 value)
{
GL.Uniform4(uniform.Id.ToInt32(), value.X, value.Y, value.Z, value.W);
}
void IGL.SetPipelineUniformSampler(PipelineUniform uniform, IntPtr texHandle)
public void SetPipelineUniform(PipelineUniform uniform, Vector2 value)
{
GL.Uniform2(uniform.Id.ToInt32(), value.X, value.Y);
}
public void SetPipelineUniform(PipelineUniform uniform, float value)
{
GL.Uniform1(uniform.Id.ToInt32(), value);
}
public void SetPipelineUniformSampler(PipelineUniform uniform, IntPtr texHandle)
{
//set the sampler index into the uniform first
//now bind the texture
@ -289,30 +312,30 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
GL.BindTexture(TextureTarget.Texture2D, texHandle.ToInt32());
}
void IGL.TexParameter2d(TextureParameterName pname, int param)
public void TexParameter2d(TextureParameterName pname, int param)
{
GL.TexParameter(TextureTarget.Texture2D, (global::OpenTK.Graphics.OpenGL.TextureParameterName)pname, param);
}
Texture2d IGL.LoadTexture(sd.Bitmap bitmap)
public Texture2d LoadTexture(sd.Bitmap bitmap)
{
using (var bmp = new BitmapBuffer(bitmap, new BitmapLoadOptions()))
return (this as IGL).LoadTexture(bmp);
}
Texture2d IGL.LoadTexture(Stream stream)
public Texture2d LoadTexture(Stream stream)
{
using(var bmp = new BitmapBuffer(stream,new BitmapLoadOptions()))
return (this as IGL).LoadTexture(bmp);
}
Texture2d IGL.CreateTexture(int width, int height)
public Texture2d CreateTexture(int width, int height)
{
IntPtr id = (this as IGL).GenTexture();
return new Texture2d(this, id, width, height);
}
void IGL.LoadTextureData(Texture2d tex, BitmapBuffer bmp)
public void LoadTextureData(Texture2d tex, BitmapBuffer bmp)
{
sdi.BitmapData bmp_data = bmp.LockBits();
try
@ -326,13 +349,13 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
}
}
void IGL.FreeRenderTarget(RenderTarget rt)
public void FreeRenderTarget(RenderTarget rt)
{
rt.Texture2d.Dispose();
GL.DeleteFramebuffer(rt.Id.ToInt32());
}
unsafe RenderTarget IGL.CreateRenderTarget(int w, int h)
public unsafe RenderTarget CreateRenderTarget(int w, int h)
{
//create a texture for it
IntPtr texid = (this as IGL).GenTexture();
@ -363,7 +386,7 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
return new RenderTarget(this, new IntPtr(fbid), tex);
}
void IGL.BindRenderTarget(RenderTarget rt)
public void BindRenderTarget(RenderTarget rt)
{
if(rt == null)
GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
@ -371,7 +394,7 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
GL.BindFramebuffer(FramebufferTarget.Framebuffer, rt.Id.ToInt32());
}
Texture2d IGL.LoadTexture(BitmapBuffer bmp)
public Texture2d LoadTexture(BitmapBuffer bmp)
{
Texture2d ret = null;
IntPtr id = (this as IGL).GenTexture();
@ -395,40 +418,55 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
return ret;
}
Texture2d IGL.LoadTexture(string path)
public Texture2d LoadTexture(string path)
{
using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
return (this as IGL).LoadTexture(fs);
}
Matrix4 IGL.CreateGuiProjectionMatrix(int w, int h)
public Matrix4 CreateGuiProjectionMatrix(int w, int h)
{
return CreateGuiProjectionMatrix(new sd.Size(w, h));
}
public Matrix4 CreateGuiViewMatrix(int w, int h)
{
return CreateGuiViewMatrix(new sd.Size(w, h));
}
public Matrix4 CreateGuiProjectionMatrix(sd.Size dims)
{
Matrix4 ret = Matrix4.Identity;
ret.M11 = 2.0f / (float)w;
ret.M22 = 2.0f / (float)h;
ret.M11 = 2.0f / (float)dims.Width;
ret.M22 = 2.0f / (float)dims.Height;
return ret;
}
Matrix4 IGL.CreateGuiViewMatrix(int w, int h)
public Matrix4 CreateGuiViewMatrix(sd.Size dims)
{
Matrix4 ret = Matrix4.Identity;
ret.M22 = -1.0f;
ret.M41 = -w * 0.5f; // -0.5f;
ret.M42 = h * 0.5f; // +0.5f;
ret.M41 = -(float)dims.Width * 0.5f; // -0.5f;
ret.M42 = (float)dims.Height * 0.5f; // +0.5f;
return ret;
}
void IGL.SetViewport(int x, int y, int width, int height)
public void SetViewport(int x, int y, int width, int height)
{
GL.Viewport(x, y, width, height);
}
void IGL.SetViewport(int width, int height)
public void SetViewport(int width, int height)
{
GL.Viewport(0, 0, width, height);
}
void IGL.SetViewport(swf.Control control)
public void SetViewport(sd.Size size)
{
SetViewport(size.Width, size.Height);
}
public void SetViewport(swf.Control control)
{
var r = control.ClientRectangle;
GL.Viewport(r.Left, r.Top, r.Width, r.Height);

View File

@ -0,0 +1,88 @@
using System;
using System.Drawing;
using System.Windows.Forms;
using OpenTK;
using OpenTK.Graphics.OpenGL;
namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
{
/// <summary>
/// Handles RetroArch's GLSL shader pass format
/// This isnt implemented in BizwareGL abstract layer because it relies too much on GLSL peculiarities
/// </summary>
public class RetroShader : IDisposable
{
public RetroShader(IGL owner, string source)
{
Owner = owner as IGL_TK;
VertexLayout = owner.CreateVertexLayout();
VertexLayout.DefineVertexAttribute("VertexCoord", 0, 4, VertexAttribPointerType.Float, false, 40, 0); //VertexCoord
VertexLayout.DefineVertexAttribute("ColorShit", 1, 4, VertexAttribPointerType.Float, false, 40, 16); //COLOR
VertexLayout.DefineVertexAttribute("TexCoord", 2, 2, VertexAttribPointerType.Float, false, 40, 32); //TexCoord (is this vec2 or vec4? the glsl converted from cg had vec4 but the cg had vec2...)
VertexLayout.Close();
string vsSource = "#define VERTEX\r\n" + source;
string psSource = "#define FRAGMENT\r\n" + source;
var vs = Owner.CreateVertexShader(vsSource);
var ps = Owner.CreateFragmentShader(psSource);
Pipeline = Owner.CreatePipeline(VertexLayout, vs, ps);
}
public void Dispose()
{
VertexLayout.Dispose();
VertexLayout = null;
}
public unsafe void Run(Texture2d tex, Size InputSize, Size OutputSize, bool flip)
{
//ack! make sure to set the pipeline before setting
Owner.BindPipeline(Pipeline);
Pipeline["InputSize"].Set(new Vector2(InputSize.Width,InputSize.Height));
Pipeline["TextureSize"].Set(new Vector2(InputSize.Width, InputSize.Height));
Pipeline["OutputSize"].Set(new Vector2(OutputSize.Width, OutputSize.Height));
Pipeline["FrameCount"].Set(0); //todo
Pipeline["FrameDirection"].Set(1); //todo
var Projection = Owner.CreateGuiProjectionMatrix(OutputSize);
var Modelview = Owner.CreateGuiViewMatrix(OutputSize);
Pipeline["MVPMatrix"].Set(Modelview * Projection, false);
Pipeline["Texture"].Set(tex);
Owner.SetViewport(OutputSize);
int w = OutputSize.Width;
int h = OutputSize.Height;
float v0,v1;
if (flip) { v0 = 1; v1 = 0; }
else { v0 = 0; v1 = 1; }
float* pData = stackalloc float[10*4];
int i=0;
pData[i++] = 0; pData[i++] = 0; pData[i++] = 0; pData[i++] = 1; //topleft vert
pData[i++] = 0; pData[i++] = 0; pData[i++] = 0; pData[i++] = 0; //junk
pData[i++] = 0; pData[i++] = v0; //texcoord
pData[i++] = w; pData[i++] = 0; pData[i++] = 0; pData[i++] = 1; //topright vert
pData[i++] = 0; pData[i++] = 0; pData[i++] = 0; pData[i++] = 0; //junk
pData[i++] = 1; pData[i++] = v0; //texcoord
pData[i++] = 0; pData[i++] = h; pData[i++] = 0; pData[i++] = 1; //bottomleft vert
pData[i++] = 0; pData[i++] = 0; pData[i++] = 0; pData[i++] = 0; //junk
pData[i++] = 0; pData[i++] = v1; //texcoord
pData[i++] = w; pData[i++] = h; pData[i++] = 0; pData[i++] = 1; //bottomright vert
pData[i++] = 0; pData[i++] = 0; pData[i++] = 0; pData[i++] = 0; //junk
pData[i++] = 1; pData[i++] = v1; //texcoord
Owner.BindArrayData(pData);
Owner.DrawArrays(PrimitiveType.TriangleStrip, 0, 4);
}
public IGL_TK Owner { get; private set; }
VertexLayout VertexLayout;
public Pipeline Pipeline;
}
}

View File

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
namespace BizHawk.Bizware.BizwareGL
{
public class AttributeInfo
{
public IntPtr Handle;
public string Name;
}
}

View File

@ -49,6 +49,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AttributeInfo.cs" />
<Compile Include="BitmapBuffer.cs" />
<Compile Include="BitmapLoadOptions.cs" />
<Compile Include="Borrowed\BitmapFontParser\BitmapFont.cs" />

View File

@ -21,8 +21,8 @@ namespace BizHawk.Bizware.BizwareGL
Owner = owner;
VertexLayout = owner.CreateVertexLayout();
VertexLayout.DefineVertexAttribute(0, 2, VertexAttribPointerType.Float, false, 16, 0);
VertexLayout.DefineVertexAttribute(1, 2, VertexAttribPointerType.Float, false, 16, 8);
VertexLayout.DefineVertexAttribute("aPosition", 0, 2, VertexAttribPointerType.Float, false, 16, 0);
VertexLayout.DefineVertexAttribute("aTexcoord", 1, 2, VertexAttribPointerType.Float, false, 16, 8);
VertexLayout.Close();
_Projection = new MatrixStack();
@ -30,7 +30,7 @@ namespace BizHawk.Bizware.BizwareGL
var vs = Owner.CreateVertexShader(DefaultVertexShader);
var ps = Owner.CreateFragmentShader(DefaultPixelShader);
CurrPipeline = DefaultPipeline = Owner.CreatePipeline(vs, ps);
CurrPipeline = DefaultPipeline = Owner.CreatePipeline(VertexLayout, vs, ps);
}
public void Dispose()
@ -131,7 +131,6 @@ namespace BizHawk.Bizware.BizwareGL
throw new InvalidOperationException("Pipeline hasn't been set!");
IsActive = true;
Owner.BindVertexLayout(VertexLayout);
Owner.BindPipeline(CurrPipeline);
//clear state cache

View File

@ -1,6 +1,6 @@
using System;
using System.IO;
using sd=System.Drawing;
using System.Drawing;
using swf=System.Windows.Forms;
using OpenTK;
@ -29,7 +29,7 @@ namespace BizHawk.Bizware.BizwareGL
/// <summary>
/// Sets the current clear color
/// </summary>
void SetClearColor(sd.Color color);
void SetClearColor(Color color);
/// <summary>
/// generates a texture handle
@ -59,7 +59,7 @@ namespace BizHawk.Bizware.BizwareGL
/// <summary>
/// Creates a complete pipeline from the provided vertex and fragment shader handles
/// </summary>
Pipeline CreatePipeline(Shader vertexShader, Shader fragmentShader);
Pipeline CreatePipeline(VertexLayout vertexLayout, Shader vertexShader, Shader fragmentShader);
/// <summary>
/// Binds this pipeline as the current used for rendering
@ -87,9 +87,14 @@ namespace BizHawk.Bizware.BizwareGL
void SetPipelineUniform(PipelineUniform uniform, Vector4 value);
/// <summary>
/// Binds this VertexLayout for use in rendering (in OpenGL's case, by glVertexAttribPointer calls)
/// sets a uniform value
/// </summary>
void BindVertexLayout(VertexLayout layout);
void SetPipelineUniform(PipelineUniform uniform, Vector2 value);
/// <summary>
/// sets a uniform value
/// </summary>
void SetPipelineUniform(PipelineUniform uniform, float value);
/// <summary>
/// Binds array data for use with the currently-bound VertexLayout
@ -184,7 +189,7 @@ namespace BizHawk.Bizware.BizwareGL
/// <summary>
/// Loads a texture from the System.Drawing.Bitmap
/// </summary>
Texture2d LoadTexture(sd.Bitmap bitmap);
Texture2d LoadTexture(Bitmap bitmap);
/// <summary>
/// sets the viewport according to the provided specifications
@ -201,17 +206,33 @@ namespace BizHawk.Bizware.BizwareGL
/// </summary>
void SetViewport(swf.Control control);
/// <summary>
/// sets the viewport according to the provided specifications
/// </summary>
void SetViewport(Size size);
/// <summary>
/// generates a proper 2d othographic projection for the given destination size, suitable for use in a GUI
/// </summary>
Matrix4 CreateGuiProjectionMatrix(int w, int h);
/// <summary>
/// generates a proper 2d othographic projection for the given destination size, suitable for use in a GUI
/// </summary>
Matrix4 CreateGuiProjectionMatrix(Size dims);
/// <summary>
/// generates a proper view transform for a standard 2d ortho projection, including half-pixel jitter if necessary and
/// re-establishing of a normal 2d graphics top-left origin. suitable for use in a GUI
/// </summary>
Matrix4 CreateGuiViewMatrix(int w, int h);
/// <summary>
/// generates a proper view transform for a standard 2d ortho projection, including half-pixel jitter if necessary and
/// re-establishing of a normal 2d graphics top-left origin. suitable for use in a GUI
/// </summary>
Matrix4 CreateGuiViewMatrix(Size dims);
/// <summary>
/// Creates a render target. Includes a color buffer. Pixel format control TBD
/// </summary>

View File

@ -3,12 +3,16 @@ using System.Collections.Generic;
namespace BizHawk.Bizware.BizwareGL
{
/// <summary>
/// WARNING! PLEASE SET THIS PIPELINE CURRENT BEFORE SETTING UNIFORMS IN IT! NOT TOO GREAT, I KNOW.
/// </summary>
public class Pipeline : IDisposable
{
public Pipeline(IGL owner, IntPtr id, IEnumerable<UniformInfo> uniforms)
public Pipeline(IGL owner, IntPtr id, VertexLayout vertexLayout, IEnumerable<UniformInfo> uniforms)
{
Owner = owner;
Id = id;
VertexLayout = vertexLayout;
//create the uniforms from the info list we got
UniformsDictionary = new SpecialWorkingDictionary(this);
@ -62,6 +66,7 @@ namespace BizHawk.Bizware.BizwareGL
public IGL Owner { get; private set; }
public IntPtr Id { get; private set; }
public VertexLayout VertexLayout { get; private set; }
///// <summary>
///// Makes the pipeline current

View File

@ -23,11 +23,21 @@ namespace BizHawk.Bizware.BizwareGL
Owner.Owner.SetPipelineUniformMatrix(this, mat, transpose);
}
public void Set(Vector4 vec, bool transpose = false)
public void Set(Vector4 vec)
{
Owner.Owner.SetPipelineUniform(this, vec);
}
public void Set(Vector2 vec)
{
Owner.Owner.SetPipelineUniform(this, vec);
}
public void Set(float f)
{
Owner.Owner.SetPipelineUniform(this, f);
}
public void Set(ref Matrix4 mat, bool transpose = false)
{
Owner.Owner.SetPipelineUniformMatrix(this, ref mat, transpose);

View File

@ -1,5 +1,8 @@
using System;
using System.Drawing;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
namespace BizHawk.Bizware.BizwareGL
@ -74,11 +77,12 @@ namespace BizHawk.Bizware.BizwareGL
public IGL Owner { get; private set; }
public IntPtr Id { get; private set; }
//note.. it is commonly helpful to have these as floats, since we're more often using them for rendering than for raster logic
//note.. this was a lame idea. convenient, but weird. lets just change this back to ints.
public float Width { get; private set; }
public float Height { get; private set; }
public int IntWidth { get { return (int)Width; } }
public int IntHeight { get { return (int)Height; } }
public Size Size { get { return new Size(IntWidth, IntHeight); } }
}
}

View File

@ -47,16 +47,11 @@ namespace BizHawk.Bizware.BizwareGL
//nothing to do yet..
}
public void Bind()
{
Owner.BindVertexLayout(this);
}
public void DefineVertexAttribute(int index, int components, VertexAttribPointerType attribType, bool normalized, int stride, int offset = 0)
public void DefineVertexAttribute(string name, int index, int components, VertexAttribPointerType attribType, bool normalized, int stride, int offset = 0)
{
if (Closed)
throw new InvalidOperationException("Type is Closed and is now immutable.");
Items[index] = new LayoutItem { Components = components, AttribType = attribType, Normalized = normalized, Stride = stride, Offset = offset };
Items[index] = new LayoutItem { Name = name, Components = components, AttribType = attribType, Normalized = normalized, Stride = stride, Offset = offset };
}
/// <summary>
@ -69,6 +64,7 @@ namespace BizHawk.Bizware.BizwareGL
public class LayoutItem
{
public string Name { get; internal set; }
public int Components { get; internal set; }
public VertexAttribPointerType AttribType { get; internal set; }
public bool Normalized { get; internal set; }

View File

@ -6,6 +6,8 @@ using System.Linq;
using System.Text;
using BizHawk.Bizware.BizwareGL;
using BizHawk.Bizware.BizwareGL.Drivers.OpenTK;
using OpenTK.Graphics.OpenGL;
namespace BizHawk.Bizware.Test
@ -47,8 +49,7 @@ namespace BizHawk.Bizware.Test
c.SetVsync(false);
//create a render target, in the control context
c.Begin();
//create a render target
RenderTarget rt = igl.CreateRenderTarget(60, 60);
rt.Bind();
igl.SetClearColor(Color.Blue);
@ -57,7 +58,16 @@ namespace BizHawk.Bizware.Test
gr.Draw(smile);
gr.End();
rt.Unbind();
c.End();
//test retroarch shader
RenderTarget rt2 = igl.CreateRenderTarget(240, 240);
rt2.Bind();
igl.SetClearColor(Color.CornflowerBlue);
igl.Clear(ClearBufferMask.ColorBufferBit);
RetroShader shader = new RetroShader(igl, System.IO.File.ReadAllText(@"B:\svn\bizhawk8\trunk\Bizware\4xSoft.glsl"));
igl.SetBlendState(igl.BlendNone);
shader.Run(rt.Texture2d, new Size(60, 60), new Size(240, 240), true);
bool running = true;
c.MouseClick += (object sender, MouseEventArgs e) =>
@ -90,6 +100,9 @@ namespace BizHawk.Bizware.Test
gr.SetBlendState(igl.BlendNormal);
sr.RenderString(gr, 0, 0, "?? fps");
gr.SetModulateColor(Color.FromArgb(255, 255, 255, 255));
gr.Draw(rt2.Texture2d, 0, 0);
gr.SetModulateColorWhite();
gr.Modelview.Translate((float)Math.Sin(wobble / 360.0f) * 50, 0);
gr.Modelview.Translate(100, 100);
gr.Modelview.Push();
@ -104,6 +117,7 @@ namespace BizHawk.Bizware.Test
gr.Draw(smile);
gr.End();
c.SwapBuffers();
c.End();
}