agate-svn-commit Mailing List for AgateLib (Page 28)
Status: Alpha
Brought to you by:
kanato
You can subscribe to this list here.
| 2009 |
Jan
|
Feb
|
Mar
|
Apr
(86) |
May
(77) |
Jun
|
Jul
(1) |
Aug
(31) |
Sep
(12) |
Oct
(31) |
Nov
(53) |
Dec
(39) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2010 |
Jan
(53) |
Feb
(14) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(2) |
Sep
|
Oct
|
Nov
(7) |
Dec
(13) |
| 2011 |
Jan
(17) |
Feb
(5) |
Mar
(1) |
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(10) |
Nov
(21) |
Dec
|
| 2012 |
Jan
(6) |
Feb
(14) |
Mar
(5) |
Apr
(4) |
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2013 |
Jan
(1) |
Feb
(8) |
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
(2) |
Sep
(1) |
Oct
(5) |
Nov
(9) |
Dec
(5) |
| 2014 |
Jan
(3) |
Feb
(2) |
Mar
(4) |
Apr
(3) |
May
|
Jun
(5) |
Jul
(33) |
Aug
(69) |
Sep
(35) |
Oct
(4) |
Nov
(1) |
Dec
|
|
From: <ka...@us...> - 2009-04-15 03:44:53
|
Revision: 862
http://agate.svn.sourceforge.net/agate/?rev=862&view=rev
Author: kanato
Date: 2009-04-15 03:44:45 +0000 (Wed, 15 Apr 2009)
Log Message:
-----------
Update version number in Doxyfile.
Modified Paths:
--------------
trunk/Documentation/Doxyfile
Modified: trunk/Documentation/Doxyfile
===================================================================
--- trunk/Documentation/Doxyfile 2009-04-15 03:11:46 UTC (rev 861)
+++ trunk/Documentation/Doxyfile 2009-04-15 03:44:45 UTC (rev 862)
@@ -31,7 +31,7 @@
# This could be handy for archiving the generated documentation or
# if some version control system is used.
-PROJECT_NUMBER = 0.3.0
+PROJECT_NUMBER = 0.3.1
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
# base path where the generated documentation will be put.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-04-15 03:12:06
|
Revision: 861
http://agate.svn.sourceforge.net/agate/?rev=861&view=rev
Author: kanato
Date: 2009-04-15 03:11:46 +0000 (Wed, 15 Apr 2009)
Log Message:
-----------
Update release notes for Agate 0.3.1.
Modified Paths:
--------------
trunk/ReleaseNotes.txt
Modified: trunk/ReleaseNotes.txt
===================================================================
--- trunk/ReleaseNotes.txt 2009-04-15 02:54:04 UTC (rev 860)
+++ trunk/ReleaseNotes.txt 2009-04-15 03:11:46 UTC (rev 861)
@@ -1,3 +1,8 @@
+AgateLib 0.3.1 Release Notes
+======================================
+
+This is mainly a minor update to 0.3.0. All features deprecated in 0.3.0 have been removed. There are a few minor bug fixes, and a few properties added. Of note is the addition of the ZipFileProvider, which is an IFileProvider object that allows resources to be loaded from zip files.
+
AgateLib 0.3.0 Release Notes
======================================
@@ -149,4 +154,4 @@
* VSync is not properly supported in the Direct3D driver.
* There's a problem with Display.PackAllSurfaces where it does not copy surfaces correctly.
* Direct3D driver does not work with Mono. If you are running in Mono, delete AgateMDX.dll from your application directory.
-
\ No newline at end of file
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-04-15 02:54:18
|
Revision: 860
http://agate.svn.sourceforge.net/agate/?rev=860&view=rev
Author: kanato
Date: 2009-04-15 02:54:04 +0000 (Wed, 15 Apr 2009)
Log Message:
-----------
Commit Prebuild.exe build from local prebuild source.
Modified Paths:
--------------
trunk/Build/Prebuild/Prebuild.exe
Modified: trunk/Build/Prebuild/Prebuild.exe
===================================================================
(Binary files differ)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-04-15 02:27:53
|
Revision: 859
http://agate.svn.sourceforge.net/agate/?rev=859&view=rev
Author: kanato
Date: 2009-04-15 02:27:40 +0000 (Wed, 15 Apr 2009)
Log Message:
-----------
Make packed sprite creator compile.
Modified Paths:
--------------
trunk/Tools/PackedSpriteCreator/SpriteEditor.cs
Modified: trunk/Tools/PackedSpriteCreator/SpriteEditor.cs
===================================================================
--- trunk/Tools/PackedSpriteCreator/SpriteEditor.cs 2009-04-12 19:50:48 UTC (rev 858)
+++ trunk/Tools/PackedSpriteCreator/SpriteEditor.cs 2009-04-15 02:27:40 UTC (rev 859)
@@ -11,297 +11,297 @@
namespace PackedSpriteCreator
{
- public partial class SpriteEditor : UserControl
- {
- AgateResourceCollection mResources;
- SpriteResource mCurrentSprite;
- SpriteRenderer drawer = new SpriteRenderer();
- AgateLib.DisplayLib.DisplayWindow wind;
- Sprite mAgateSprite;
+ public partial class SpriteEditor : UserControl
+ {
+ AgateResourceCollection mResources;
+ SpriteResource mCurrentSprite;
+ SpriteRenderer drawer = new SpriteRenderer();
+ AgateLib.DisplayLib.DisplayWindow wind;
+ Sprite mAgateSprite;
- public SpriteEditor()
- {
- InitializeComponent();
- }
+ public SpriteEditor()
+ {
+ InitializeComponent();
+ }
- public AgateResourceCollection Resources
- {
- get { return mResources; }
- set
- {
- mResources = value;
+ public AgateResourceCollection Resources
+ {
+ get { return mResources; }
+ set
+ {
+ mResources = value;
- OnResourcesChanged();
- }
- }
+ OnResourcesChanged();
+ }
+ }
- private void OnResourcesChanged()
- {
- lstSprites.Items.Clear();
+ private void OnResourcesChanged()
+ {
+ lstSprites.Items.Clear();
- if (mResources == null)
- {
- lstSprites.Enabled = false;
- return;
- }
+ if (mResources == null)
+ {
+ lstSprites.Enabled = false;
+ return;
+ }
- lstSprites.Enabled = true;
- lstSprites.Items.AddRange(mResources.Sprites.ToArray());
-
- }
+ lstSprites.Enabled = true;
+ lstSprites.Items.AddRange(mResources.Sprites.ToArray());
- bool changingSprite = false;
+ }
- private void lstSprites_SelectedIndexChanged(object sender, EventArgs e)
- {
- mCurrentSprite = lstSprites.SelectedItem as SpriteResource;
+ bool changingSprite = false;
- if (mCurrentSprite == null)
- {
- propertiesPanel.Visible = false;
- return;
- }
+ private void lstSprites_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ mCurrentSprite = lstSprites.SelectedItem as SpriteResource;
- propertiesPanel.Visible = true;
+ if (mCurrentSprite == null)
+ {
+ propertiesPanel.Visible = false;
+ return;
+ }
- try
- {
- changingSprite = true;
- UpdateSprite();
+ propertiesPanel.Visible = true;
- txtName.Text = mCurrentSprite.Name;
- nudTimePerFrame.Value = (decimal)mCurrentSprite.TimePerFrame;
+ try
+ {
+ changingSprite = true;
+ UpdateSprite();
- FillFrameList(-1);
- }
- finally
- {
- changingSprite = false;
- }
- }
+ txtName.Text = mCurrentSprite.Name;
+ nudTimePerFrame.Value = (decimal)mCurrentSprite.TimePerFrame;
- private void UpdateSprite()
- {
- try
- {
- UpdateSprite(new Sprite(Resources, mCurrentSprite.Name));
- }
- catch (Exception e)
- {
- MessageBox.Show(this, string.Format(
- "Failed to load sprite {0}." + Environment.NewLine + "{1}", mCurrentSprite.Name,
- e.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- private void UpdateSprite(Sprite updatedSprite)
- {
- if (mAgateSprite != null)
- mAgateSprite.Dispose();
+ FillFrameList(-1);
+ }
+ finally
+ {
+ changingSprite = false;
+ }
+ }
- mAgateSprite = updatedSprite;
- mAgateSprite.IsAnimating = chkAnimating.Checked;
- }
+ private void UpdateSprite()
+ {
+ try
+ {
+ UpdateSprite(new Sprite(Resources, mCurrentSprite.Name));
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(this, string.Format(
+ "Failed to load sprite {0}." + Environment.NewLine + "{1}", mCurrentSprite.Name,
+ e.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void UpdateSprite(Sprite updatedSprite)
+ {
+ if (mAgateSprite != null)
+ mAgateSprite.Dispose();
- private void FillFrameList(int newSelection)
- {
- FillFrameList(new int[] { newSelection });
- }
- private void FillFrameList(IEnumerable<int> selections)
- {
- lstFrames.Items.Clear();
- lstFrames.Items.AddRange(mCurrentSprite.Frames.ToArray());
+ mAgateSprite = updatedSprite;
+ mAgateSprite.IsAnimating = chkAnimating.Checked;
+ }
- lstFrames.SelectedIndices.Clear();
- foreach (var index in selections)
- lstFrames.SelectedIndices.Add(index);
+ private void FillFrameList(int newSelection)
+ {
+ FillFrameList(new int[] { newSelection });
+ }
+ private void FillFrameList(IEnumerable<int> selections)
+ {
+ lstFrames.Items.Clear();
+ lstFrames.Items.AddRange(mCurrentSprite.ChildElements.ToArray());
- lstFrames_SelectedIndexChanged(this, EventArgs.Empty);
- }
+ lstFrames.SelectedIndices.Clear();
+ foreach (var index in selections)
+ lstFrames.SelectedIndices.Add(index);
- private void timer1_Tick(object sender, EventArgs e)
- {
- if (propertiesPanel.Visible == false)
- return;
+ lstFrames_SelectedIndexChanged(this, EventArgs.Empty);
+ }
- drawer.DrawSprite(wind, mAgateSprite);
- }
+ private void timer1_Tick(object sender, EventArgs e)
+ {
+ if (propertiesPanel.Visible == false)
+ return;
- private void SpriteEditor_Load(object sender, EventArgs e)
- {
- if (DesignMode)
- return;
- if (Parent == null)
- return;
+ drawer.DrawSprite(wind, mAgateSprite);
+ }
- wind = new AgateLib.DisplayLib.DisplayWindow(AgateLib.DisplayLib.CreateWindowParams.FromControl(agateRenderTarget1));
+ private void SpriteEditor_Load(object sender, EventArgs e)
+ {
+ if (DesignMode)
+ return;
+ if (Parent == null)
+ return;
- }
+ wind = new AgateLib.DisplayLib.DisplayWindow(AgateLib.DisplayLib.CreateWindowParams.FromControl(agateRenderTarget1));
- private void txtName_Validating(object sender, CancelEventArgs e)
- {
- if (changingSprite) return;
+ }
- if (Resources.Contains(txtName.Text) == false)
- return;
+ private void txtName_Validating(object sender, CancelEventArgs e)
+ {
+ if (changingSprite) return;
- if (Resources[txtName.Text] == mCurrentSprite)
- return;
+ if (Resources.Contains(txtName.Text) == false)
+ return;
- e.Cancel = true;
- }
+ if (Resources[txtName.Text] == mCurrentSprite)
+ return;
- private void txtName_Validated(object sender, EventArgs e)
- {
- if (changingSprite) return;
+ e.Cancel = true;
+ }
- Resources.Remove(mCurrentSprite);
-
- mCurrentSprite.Name = txtName.Text;
+ private void txtName_Validated(object sender, EventArgs e)
+ {
+ if (changingSprite) return;
- Resources.Add(mCurrentSprite);
+ Resources.Remove(mCurrentSprite);
- int index = lstSprites.SelectedIndex;
- lstSprites.Items.RemoveAt(index);
- lstSprites.Items.Insert(index, mCurrentSprite);
- lstSprites.SelectedIndex = index;
- }
+ mCurrentSprite.Name = txtName.Text;
- private void nudTimePerFrame_ValueChanged(object sender, EventArgs e)
- {
- if (changingSprite) return;
+ Resources.Add(mCurrentSprite);
- mCurrentSprite.TimePerFrame = (double)nudTimePerFrame.Value;
- mAgateSprite.TimePerFrame = (double)nudTimePerFrame.Value;
+ int index = lstSprites.SelectedIndex;
+ lstSprites.Items.RemoveAt(index);
+ lstSprites.Items.Insert(index, mCurrentSprite);
+ lstSprites.SelectedIndex = index;
+ }
- }
+ private void nudTimePerFrame_ValueChanged(object sender, EventArgs e)
+ {
+ if (changingSprite) return;
- private void lstFrames_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (lstFrames.SelectedIndex == -1)
- {
- btnDelete.Enabled = false;
- btnMoveDown.Enabled = false;
- btnMoveUp.Enabled = false;
- }
- else
- {
- btnMoveUp.Enabled = true;
- btnMoveDown.Enabled = true;
- btnDelete.Enabled = true;
+ mCurrentSprite.TimePerFrame = (double)nudTimePerFrame.Value;
+ mAgateSprite.TimePerFrame = (double)nudTimePerFrame.Value;
- if (lstFrames.SelectedIndices.Contains(0))
- {
- btnMoveUp.Enabled = false;
- }
- if (lstFrames.SelectedIndices.Contains(lstFrames.Items.Count-1))
- {
- btnMoveDown.Enabled = false;
- }
- if (lstFrames.SelectedIndices.Count == 0)
- btnDelete.Enabled = false;
- }
+ }
- if (changingSprite)
- return;
+ private void lstFrames_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ if (lstFrames.SelectedIndex == -1)
+ {
+ btnDelete.Enabled = false;
+ btnMoveDown.Enabled = false;
+ btnMoveUp.Enabled = false;
+ }
+ else
+ {
+ btnMoveUp.Enabled = true;
+ btnMoveDown.Enabled = true;
+ btnDelete.Enabled = true;
- if (mAgateSprite != null)
- {
- if (chkAnimating.Checked == false)
- mAgateSprite.CurrentFrameIndex = lstFrames.SelectedIndex;
- }
- }
+ if (lstFrames.SelectedIndices.Contains(0))
+ {
+ btnMoveUp.Enabled = false;
+ }
+ if (lstFrames.SelectedIndices.Contains(lstFrames.Items.Count - 1))
+ {
+ btnMoveDown.Enabled = false;
+ }
+ if (lstFrames.SelectedIndices.Count == 0)
+ btnDelete.Enabled = false;
+ }
- private void btnAdd_Click(object sender, EventArgs e)
- {
- frmAddSpriteFrames frm = new frmAddSpriteFrames();
- frm.SpriteSize = AgateLib.WinForms.Interop.Convert(mCurrentSprite.Size);
+ if (changingSprite)
+ return;
- if (frm.ShowDialog(this) == DialogResult.OK)
- {
+ if (mAgateSprite != null)
+ {
+ if (chkAnimating.Checked == false)
+ mAgateSprite.CurrentFrameIndex = lstFrames.SelectedIndex;
+ }
+ }
- }
- }
- private void btnMoveUp_Click(object sender, EventArgs e)
- {
- List<int> selections = new List<int>();
+ private void btnAdd_Click(object sender, EventArgs e)
+ {
+ frmAddSpriteFrames frm = new frmAddSpriteFrames();
+ frm.SpriteSize = AgateLib.WinForms.Interop.Convert(mCurrentSprite.Size);
- foreach (int index in lstFrames.SelectedIndices)
- {
- var frame = mCurrentSprite.Frames[index];
- mCurrentSprite.Frames.RemoveAt(index);
- mCurrentSprite.Frames.Insert(index - 1, frame);
+ if (frm.ShowDialog(this) == DialogResult.OK)
+ {
- selections.Add(index - 1);
- }
+ }
+ }
+ private void btnMoveUp_Click(object sender, EventArgs e)
+ {
+ List<int> selections = new List<int>();
- UpdateSprite();
- FillFrameList(selections);
+ foreach (int index in lstFrames.SelectedIndices)
+ {
+ var frame = mCurrentSprite.ChildElements[index];
+ mCurrentSprite.ChildElements.RemoveAt(index);
+ mCurrentSprite.ChildElements.Insert(index - 1, frame);
- }
- private void btnMoveDown_Click(object sender, EventArgs e)
- {
- List<int> selections = new List<int>();
+ selections.Add(index - 1);
+ }
- foreach (int index in lstFrames.SelectedIndices)
- {
- var frame = mCurrentSprite.Frames[index];
- mCurrentSprite.Frames.RemoveAt(index);
- mCurrentSprite.Frames.Insert(index + 1, frame);
+ UpdateSprite();
+ FillFrameList(selections);
- selections.Add(index + 1);
- }
+ }
+ private void btnMoveDown_Click(object sender, EventArgs e)
+ {
+ List<int> selections = new List<int>();
- UpdateSprite();
- FillFrameList(selections);
+ foreach (int index in lstFrames.SelectedIndices)
+ {
+ var frame = mCurrentSprite.ChildElements[index];
+ mCurrentSprite.ChildElements.RemoveAt(index);
+ mCurrentSprite.ChildElements.Insert(index + 1, frame);
- }
- private void btnDelete_Click(object sender, EventArgs e)
- {
- List<SpriteResource.SpriteFrameResource> framesToDelete = new List<SpriteResource.SpriteFrameResource>();
+ selections.Add(index + 1);
+ }
- foreach (int index in lstFrames.SelectedIndices)
- {
- framesToDelete.Add(mCurrentSprite.Frames[index]);
- }
+ UpdateSprite();
+ FillFrameList(selections);
- foreach(SpriteResource.SpriteFrameResource frame in framesToDelete)
- {
- mCurrentSprite.Frames.Remove(frame);
- }
+ }
+ private void btnDelete_Click(object sender, EventArgs e)
+ {
+ var framesToDelete = new List<SpriteResource.SpriteSubResource>();
- UpdateSprite();
- FillFrameList(-1);
- }
+ foreach (int index in lstFrames.SelectedIndices)
+ {
+ framesToDelete.Add(mCurrentSprite.ChildElements[index]);
+ }
+ foreach (SpriteResource.SpriteFrameResource frame in framesToDelete)
+ {
+ mCurrentSprite.ChildElements.Remove(frame);
+ }
- private void chkAnimating_CheckedChanged(object sender, EventArgs e)
- {
- if (mAgateSprite == null)
- return;
+ UpdateSprite();
+ FillFrameList(-1);
+ }
- mAgateSprite.IsAnimating = chkAnimating.Checked;
- }
- private void btnNewSprite_Click(object sender, EventArgs e)
- {
- frmNewSprite frm = new frmNewSprite();
+ private void chkAnimating_CheckedChanged(object sender, EventArgs e)
+ {
+ if (mAgateSprite == null)
+ return;
- if (frm.ShowDialog(this, Resources) == DialogResult.Cancel)
- return;
+ mAgateSprite.IsAnimating = chkAnimating.Checked;
+ }
- frmAddSpriteFrames frmAdd = new frmAddSpriteFrames();
- frmAdd.SpriteSize = frm.SpriteFrameSize;
+ private void btnNewSprite_Click(object sender, EventArgs e)
+ {
+ frmNewSprite frm = new frmNewSprite();
- if (frmAdd.ShowDialog(this) == DialogResult.Cancel)
- return;
+ if (frm.ShowDialog(this, Resources) == DialogResult.Cancel)
+ return;
- SpriteResource res = new SpriteResource(frm.SpriteName);
+ frmAddSpriteFrames frmAdd = new frmAddSpriteFrames();
+ frmAdd.SpriteSize = frm.SpriteFrameSize;
-
+ if (frmAdd.ShowDialog(this) == DialogResult.Cancel)
+ return;
- Resources.Add(res);
+ SpriteResource res = new SpriteResource(frm.SpriteName);
- OnResourcesChanged();
- }
- }
+
+
+ Resources.Add(res);
+
+ OnResourcesChanged();
+ }
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-04-12 19:50:59
|
Revision: 858
http://agate.svn.sourceforge.net/agate/?rev=858&view=rev
Author: kanato
Date: 2009-04-12 19:50:48 +0000 (Sun, 12 Apr 2009)
Log Message:
-----------
Change GLSL to use bricks hieight map.
Modified Paths:
--------------
branches/agate-3d/Tests/Display3D/Glsl/Glsl.cs
Modified: branches/agate-3d/Tests/Display3D/Glsl/Glsl.cs
===================================================================
--- branches/agate-3d/Tests/Display3D/Glsl/Glsl.cs 2009-04-12 19:50:12 UTC (rev 857)
+++ branches/agate-3d/Tests/Display3D/Glsl/Glsl.cs 2009-04-12 19:50:48 UTC (rev 858)
@@ -63,7 +63,7 @@
FontSurface font = new FontSurface("Arial", 14.0f);
Surface texture = new Surface("bg-bricks.png");
- Surface height = new Surface("heightmap.png");
+ Surface height = new Surface("bg-bricks-heightmap.png");
//Surface height = new Surface("jellybean.png");
LightManager m = new LightManager();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-04-12 19:50:20
|
Revision: 857
http://agate.svn.sourceforge.net/agate/?rev=857&view=rev
Author: kanato
Date: 2009-04-12 19:50:12 +0000 (Sun, 12 Apr 2009)
Log Message:
-----------
Make normal strength a parameter to NormalMapFromHeightMap.
Modified Paths:
--------------
branches/agate-3d/AgateLib/DisplayLib/PixelBuffer.cs
Modified: branches/agate-3d/AgateLib/DisplayLib/PixelBuffer.cs
===================================================================
--- branches/agate-3d/AgateLib/DisplayLib/PixelBuffer.cs 2009-04-12 17:46:57 UTC (rev 856)
+++ branches/agate-3d/AgateLib/DisplayLib/PixelBuffer.cs 2009-04-12 19:50:12 UTC (rev 857)
@@ -1001,10 +1001,25 @@
#endregion
+ /// <summary>
+ /// Creates a normal map by interpreting the pixel data in the passed buffer
+ /// as a height map.
+ /// </summary>
+ /// <param name="buffer"></param>
+ /// <returns></returns>
public static PixelBuffer NormalMapFromHeightMap(PixelBuffer buffer)
{
- return NormalMapFromHeightMap(buffer, 8.0f);
+ return NormalMapFromHeightMap(buffer, 1.0f);
}
+ /// <summary>
+ /// Creates a normal map by interpreting the pixel data in the passed buffer
+ /// as a height map.
+ /// </summary>
+ /// <param name="buffer"></param>
+ /// <param name="normalStr">The weight for the x-y components of the normals in
+ /// the normal map. Smaller values make the normal map more subtle.
+ /// Values in the range 0.5f to 3.0f are reasonable.</param>
+ /// <returns></returns>
public static PixelBuffer NormalMapFromHeightMap(PixelBuffer buffer, float normalStr)
{
int[,] heights = new int[buffer.Width, buffer.Height];
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-04-12 17:46:59
|
Revision: 856
http://agate.svn.sourceforge.net/agate/?rev=856&view=rev
Author: kanato
Date: 2009-04-12 17:46:57 +0000 (Sun, 12 Apr 2009)
Log Message:
-----------
Fix input tester to not crash when no joysticks are connected.
Modified Paths:
--------------
trunk/Tests/InputTests/Input/frmInputTester.cs
Modified: trunk/Tests/InputTests/Input/frmInputTester.cs
===================================================================
--- trunk/Tests/InputTests/Input/frmInputTester.cs 2009-04-12 17:42:46 UTC (rev 855)
+++ trunk/Tests/InputTests/Input/frmInputTester.cs 2009-04-12 17:46:57 UTC (rev 856)
@@ -15,124 +15,124 @@
namespace Tests.InputTester
{
- public partial class Form1 : Form
- {
-
- public Form1()
- {
- InitializeComponent();
+ public partial class Form1 : Form
+ {
- Keyboard.KeyDown += new InputEventHandler(Keyboard_KeyDown);
- Keyboard.KeyUp += new InputEventHandler(Keyboard_KeyUp);
+ public Form1()
+ {
+ InitializeComponent();
- Mouse.MouseWheel += new InputEventHandler(Mouse_MouseWheel);
- Mouse.MouseMove += new InputEventHandler(Mouse_MouseMove);
- Mouse.MouseDown += new InputEventHandler(Mouse_MouseDown);
- Mouse.MouseUp += new InputEventHandler(Mouse_MouseUp);
- Mouse.MouseDoubleClick += new InputEventHandler(Mouse_MouseDoubleClickEvent);
+ Keyboard.KeyDown += new InputEventHandler(Keyboard_KeyDown);
+ Keyboard.KeyUp += new InputEventHandler(Keyboard_KeyUp);
- new DisplayWindow(CreateWindowParams.FromControl(agateRenderTarget1));
+ Mouse.MouseWheel += new InputEventHandler(Mouse_MouseWheel);
+ Mouse.MouseMove += new InputEventHandler(Mouse_MouseMove);
+ Mouse.MouseDown += new InputEventHandler(Mouse_MouseDown);
+ Mouse.MouseUp += new InputEventHandler(Mouse_MouseUp);
+ Mouse.MouseDoubleClick += new InputEventHandler(Mouse_MouseDoubleClickEvent);
- Application.Idle += new EventHandler(Application_Idle);
- }
+ new DisplayWindow(CreateWindowParams.FromControl(agateRenderTarget1));
- void Application_Idle(object sender, EventArgs e)
- {
- while (this.Visible)
- {
- numericUpDown1.Maximum = JoystickInput.Joysticks.Count - 1;
- Joystick j = JoystickInput.Joysticks[(int)numericUpDown1.Value];
+ Application.Idle += new EventHandler(Application_Idle);
+ }
- StringBuilder b = new StringBuilder();
- b.AppendLine(j.Name);
- b.Append("Axis Count: ");
- b.AppendLine(j.AxisCount.ToString());
+ void Application_Idle(object sender, EventArgs e)
+ {
+ numericUpDown1.Maximum = JoystickInput.Joysticks.Count - 1;
+ if (JoystickInput.Joysticks.Count > 0)
+ {
+ Joystick j = JoystickInput.Joysticks[(int)numericUpDown1.Value];
- for (int i = 0; i < j.AxisCount; i++)
- {
- b.Append("Axis ");
- b.Append(i.ToString());
- b.Append(": ");
- b.Append(j.GetAxisValue(i).ToString());
- b.AppendLine();
- }
+ StringBuilder b = new StringBuilder();
+ b.AppendLine(j.Name);
+ b.Append("Axis Count: ");
+ b.AppendLine(j.AxisCount.ToString());
- b.AppendLine();
+ for (int i = 0; i < j.AxisCount; i++)
+ {
+ b.Append("Axis ");
+ b.Append(i.ToString());
+ b.Append(": ");
+ b.Append(j.GetAxisValue(i).ToString());
+ b.AppendLine();
+ }
- b.Append("X: ");
- b.AppendLine(j.Xaxis.ToString());
- b.Append("Y: ");
- b.AppendLine(j.Yaxis.ToString());
- b.AppendLine();
+ b.AppendLine();
- b.Append("Buttons: ");
+ b.Append("X: ");
+ b.AppendLine(j.Xaxis.ToString());
+ b.Append("Y: ");
+ b.AppendLine(j.Yaxis.ToString());
+ b.AppendLine();
- for (int i = 0; i < j.ButtonCount; i++)
- {
- if (j.GetButtonState(i))
- b.Append(i.ToString());
- }
+ b.Append("Buttons: ");
+ for (int i = 0; i < j.ButtonCount; i++)
+ {
+ if (j.GetButtonState(i))
+ b.Append(i.ToString());
+ }
- lblJoystick.Text = b.ToString();
- Core.KeepAlive();
- }
- }
+ lblJoystick.Text = b.ToString();
+ }
- void Mouse_MouseDoubleClickEvent(InputEventArgs e)
- {
- lblMouseButton.Text = "Mouse Double Click " + e.MouseButtons.ToString();
- }
- void Mouse_MouseUp(InputEventArgs e)
- {
- lblMouseButton.Text = "Mouse Button Up " + e.MouseButtons.ToString();
- }
- void Mouse_MouseDown(InputEventArgs e)
- {
- lblMouseButton.Text = "Mouse Button Down " + e.MouseButtons.ToString();
- }
- void Mouse_MouseMove(InputEventArgs e)
- {
- lblMouseMove.Text = "Mouse Moved " + e.MousePosition.ToString();
- }
- void Mouse_MouseWheel(InputEventArgs e)
- {
- lblMouseButton.Text = "Mouse Wheel " + e.WheelDelta.ToString();
- }
+ Core.KeepAlive();
+ }
- void Keyboard_KeyUp(InputEventArgs e)
- {
- this.lblKeyPress.Text = "Released key " + e.KeyCode;
- }
- void Keyboard_KeyDown(InputEventArgs e)
- {
- this.lblKeyPress.Text = "Pressed key " + e.KeyCode;
- this.lblKeyString.Text = "Pressed key string [" + e.KeyString + "]";
- }
+ void Mouse_MouseDoubleClickEvent(InputEventArgs e)
+ {
+ lblMouseButton.Text = "Mouse Double Click " + e.MouseButtons.ToString();
+ }
+ void Mouse_MouseUp(InputEventArgs e)
+ {
+ lblMouseButton.Text = "Mouse Button Up " + e.MouseButtons.ToString();
+ }
+ void Mouse_MouseDown(InputEventArgs e)
+ {
+ lblMouseButton.Text = "Mouse Button Down " + e.MouseButtons.ToString();
+ }
+ void Mouse_MouseMove(InputEventArgs e)
+ {
+ lblMouseMove.Text = "Mouse Moved " + e.MousePosition.ToString();
+ }
+ void Mouse_MouseWheel(InputEventArgs e)
+ {
+ lblMouseButton.Text = "Mouse Wheel " + e.WheelDelta.ToString();
+ }
- protected override void OnFormClosed(FormClosedEventArgs e)
- {
- base.OnFormClosed(e);
- Display.Dispose();
- }
+ void Keyboard_KeyUp(InputEventArgs e)
+ {
+ this.lblKeyPress.Text = "Released key " + e.KeyCode;
+ }
+ void Keyboard_KeyDown(InputEventArgs e)
+ {
+ this.lblKeyPress.Text = "Pressed key " + e.KeyCode;
+ this.lblKeyString.Text = "Pressed key string [" + e.KeyString + "]";
+ }
- private void Form1_KeyDown(object sender, KeyEventArgs e)
- {
- lblKeyEvent.Text = "KeyCode: " + e.KeyCode.ToString() + "\r\n" +
- "KeyData: " + e.KeyData.ToString() + "\r\n" +
- "KeyValue: " + e.KeyValue.ToString() + "\r\n" +
- "KeyValueChar: " + ((char)e.KeyValue).ToString();
- }
+ protected override void OnFormClosed(FormClosedEventArgs e)
+ {
+ base.OnFormClosed(e);
+ Display.Dispose();
+ }
- private void button1_Click(object sender, EventArgs e)
- {
- Keyboard.ReleaseAllKeys();
- }
+ private void Form1_KeyDown(object sender, KeyEventArgs e)
+ {
+ lblKeyEvent.Text = "KeyCode: " + e.KeyCode.ToString() + "\r\n" +
+ "KeyData: " + e.KeyData.ToString() + "\r\n" +
+ "KeyValue: " + e.KeyValue.ToString() + "\r\n" +
+ "KeyValueChar: " + ((char)e.KeyValue).ToString();
+ }
- private void numericUpDown1_ValueChanged(object sender, EventArgs e)
- {
+ private void button1_Click(object sender, EventArgs e)
+ {
+ Keyboard.ReleaseAllKeys();
+ }
- }
- }
+ private void numericUpDown1_ValueChanged(object sender, EventArgs e)
+ {
+
+ }
+ }
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-04-12 17:42:52
|
Revision: 855
http://agate.svn.sourceforge.net/agate/?rev=855&view=rev
Author: kanato
Date: 2009-04-12 17:42:46 +0000 (Sun, 12 Apr 2009)
Log Message:
-----------
Update resource test to version 0.3.1.
Modified Paths:
--------------
trunk/Tests/CoreTests/Resources.cs
trunk/Tests/Data/TestResourceFile.xml
Modified: trunk/Tests/CoreTests/Resources.cs
===================================================================
--- trunk/Tests/CoreTests/Resources.cs 2009-04-12 17:42:25 UTC (rev 854)
+++ trunk/Tests/CoreTests/Resources.cs 2009-04-12 17:42:46 UTC (rev 855)
@@ -9,52 +9,51 @@
namespace Tests.ResourceTester
{
- class ResourceTester : IAgateTest
- {
- public void Main(string[] args)
- {
+ class ResourceTester : IAgateTest
+ {
+ public void Main(string[] args)
+ {
using (AgateSetup setup = new AgateSetup("Resource Tester", args))
- {
- setup.InitializeAll();
- if (setup.WasCanceled)
- return;
+ {
+ setup.InitializeAll();
+ if (setup.WasCanceled)
+ return;
- AgateFileProvider.Resources.Add(new AgateLib.Utility.FileSystemProvider("Data"));
+ AgateFileProvider.Resources.Add(new AgateLib.Utility.FileSystemProvider("Data"));
- AgateResourceCollection resources =
- AgateResourceLoader.LoadResources("TestResourceFile.xml");
+ AgateResourceCollection resources = new AgateResourceCollection("TestResourceFile.xml");
- DisplayWindow wind = new DisplayWindow(resources, "main_window");
- Surface surf = new Surface(resources, "sample_surf");
- ISprite sprite = new Sprite(resources, "sample_sprite");
- FontSurface font = new FontSurface(resources, "sample_font");
+ DisplayWindow wind = new DisplayWindow(resources, "main_window");
+ Surface surf = new Surface(resources, "sample_surf");
+ ISprite sprite = new Sprite(resources, "sample_sprite");
+ FontSurface font = new FontSurface(resources, "sample_font");
- sprite.StartAnimation();
+ sprite.StartAnimation();
- while (wind.IsClosed == false)
- {
- Display.BeginFrame();
- Display.Clear(Color.Red);
+ while (wind.IsClosed == false)
+ {
+ Display.BeginFrame();
+ Display.Clear(Color.Red);
- font.DrawText(0, 0, "FPS: " + Display.FramesPerSecond.ToString());
+ font.DrawText(0, 0, "FPS: " + Display.FramesPerSecond.ToString());
- surf.Draw(20, 20);
+ surf.Draw(20, 20);
- sprite.Update();
- sprite.Draw(100, 100);
+ sprite.Update();
+ sprite.Draw(100, 100);
- Display.EndFrame();
- Core.KeepAlive();
- }
- }
- }
+ Display.EndFrame();
+ Core.KeepAlive();
+ }
+ }
+ }
- #region IAgateTest Members
+ #region IAgateTest Members
- public string Name { get { return "Resources"; } }
- public string Category { get { return "Core"; } }
+ public string Name { get { return "Resources"; } }
+ public string Category { get { return "Core"; } }
- #endregion
- }
+ #endregion
+ }
}
Modified: trunk/Tests/Data/TestResourceFile.xml
===================================================================
--- trunk/Tests/Data/TestResourceFile.xml 2009-04-12 17:42:25 UTC (rev 854)
+++ trunk/Tests/Data/TestResourceFile.xml 2009-04-12 17:42:46 UTC (rev 855)
@@ -1,4 +1,4 @@
-<AgateResources Version="0.3.0">
+<AgateResources Version="0.3.1">
<StringTable>
<string name="Hello">Hello.</string>
<string name="How are you">How are you?</string>
@@ -120,4 +120,4 @@
<Glyph char="126" source="{X=127,Y=110,Width=11,Height=24}" leftOverhang="1" rightOverhang="1" />
</Metrics>
</BitmapFont>
-</AgateResources>
\ No newline at end of file
+</AgateResources>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-04-12 17:42:28
|
Revision: 854
http://agate.svn.sourceforge.net/agate/?rev=854&view=rev
Author: kanato
Date: 2009-04-12 17:42:25 +0000 (Sun, 12 Apr 2009)
Log Message:
-----------
Fix resources to throw an exception if they can't load instead of failing silently.
Modified Paths:
--------------
trunk/AgateLib/Resources/AgateResourceCollection.cs
trunk/AgateLib/Resources/BitmapFontResource.cs
trunk/AgateLib/Resources/DisplayWindowResource.cs
trunk/AgateLib/Resources/SurfaceResource.cs
Modified: trunk/AgateLib/Resources/AgateResourceCollection.cs
===================================================================
--- trunk/AgateLib/Resources/AgateResourceCollection.cs 2009-04-12 17:28:41 UTC (rev 853)
+++ trunk/AgateLib/Resources/AgateResourceCollection.cs 2009-04-12 17:42:25 UTC (rev 854)
@@ -113,7 +113,13 @@
/// </summary>
public StringTable Strings
{
- get { return (StringTable)this.mStore[mStringTableKey]; }
+ get
+ {
+ if (this.mStore.ContainsKey(mStringTableKey))
+ return (StringTable)this.mStore[mStringTableKey];
+ else
+ return null;
+ }
}
/// <summary>
@@ -135,9 +141,12 @@
/// <param name="table"></param>
private void AddStringsTable(StringTable table)
{
- if (Strings.Count != 0)
+ if (Strings == null)
+ this.mStore[mStringTableKey] = table;
+ else if (Strings.Count != 0)
throw new ArgumentException("The string table for this ResourceGroup is non-empty. Should you add your strings to the existing string table?");
- this.mStore[mStringTableKey] = table;
+ else
+ this.mStore[mStringTableKey] = table;
}
/// <summary>
///
@@ -330,7 +339,9 @@
{
if (mOwnedSurfaces.ContainsKey(filename) == false)
{
- SurfaceImpl impl = Display.Impl.CreateSurface(FileProvider, RootDirectory + "/" + filename);
+ string path = string.IsNullOrEmpty(RootDirectory)? filename :
+ RootDirectory + "/" + filename;
+ SurfaceImpl impl = Display.Impl.CreateSurface(FileProvider, path);
mOwnedSurfaces.Add(filename, impl);
Modified: trunk/AgateLib/Resources/BitmapFontResource.cs
===================================================================
--- trunk/AgateLib/Resources/BitmapFontResource.cs 2009-04-12 17:28:41 UTC (rev 853)
+++ trunk/AgateLib/Resources/BitmapFontResource.cs 2009-04-12 17:42:25 UTC (rev 854)
@@ -27,6 +27,7 @@
{
switch (version)
{
+ case "0.3.1":
case "0.3.0":
Name = node.Attributes["name"].Value;
mImage = XmlHelper.ReadAttributeString(node, "image", string.Empty);
@@ -34,6 +35,10 @@
ReadMetrics030(node);
break;
+
+ default:
+ throw new AgateResourceException("Loading the BitmapFontResource is not supported for " +
+ "version " + version + " yet. ");
}
}
Modified: trunk/AgateLib/Resources/DisplayWindowResource.cs
===================================================================
--- trunk/AgateLib/Resources/DisplayWindowResource.cs 2009-04-12 17:28:41 UTC (rev 853)
+++ trunk/AgateLib/Resources/DisplayWindowResource.cs 2009-04-12 17:42:25 UTC (rev 854)
@@ -110,6 +110,7 @@
{
switch (version)
{
+ case "0.3.1":
case "0.3.0":
Name = node.Attributes["name"].Value;
@@ -124,6 +125,10 @@
break;
+ default:
+ throw new AgateResourceException(
+ "Loading version " + version + " of DisplayWindowResource is not " +
+ "implemented yet.");
}
}
Modified: trunk/AgateLib/Resources/SurfaceResource.cs
===================================================================
--- trunk/AgateLib/Resources/SurfaceResource.cs 2009-04-12 17:28:41 UTC (rev 853)
+++ trunk/AgateLib/Resources/SurfaceResource.cs 2009-04-12 17:42:25 UTC (rev 854)
@@ -58,11 +58,17 @@
{
switch (version)
{
+ case "0.3.1":
case "0.3.0":
Name = node.Attributes["name"].Value;
Filename = node.Attributes["filename"].Value;
break;
+
+ default:
+ throw new AgateResourceException(
+ "Reading Surface data for the version " + version +
+ " is not supported yet. Check the version string in your resource file.");
}
}
internal override void BuildNodes(System.Xml.XmlElement parent, System.Xml.XmlDocument doc)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-04-12 17:28:47
|
Revision: 853
http://agate.svn.sourceforge.net/agate/?rev=853&view=rev
Author: kanato
Date: 2009-04-12 17:28:41 +0000 (Sun, 12 Apr 2009)
Log Message:
-----------
Make performance tester a little more organized.
Modified Paths:
--------------
trunk/Tests/CoreTests/Performance/Performance.cs
trunk/Tests/CoreTests/Performance/frmPerformance.Designer.cs
trunk/Tests/CoreTests/Performance/frmPerformance.cs
Modified: trunk/Tests/CoreTests/Performance/Performance.cs
===================================================================
--- trunk/Tests/CoreTests/Performance/Performance.cs 2009-04-12 07:38:42 UTC (rev 852)
+++ trunk/Tests/CoreTests/Performance/Performance.cs 2009-04-12 17:28:41 UTC (rev 853)
@@ -13,354 +13,369 @@
namespace Tests.PerformanceTester
{
- class PerformanceTester:IAgateTest
- {
- struct Rects
- {
- public Rectangle rect;
- public Color color;
- }
- Random rnd = new Random();
- FontSurface font;
+ class PerformanceTester : IAgateTest
+ {
+ public struct TestResult
+ {
+ public int Frames;
+ public double Time;
+ public string Name;
+ public string Driver;
- const int totalFrames = 300;
+ public double FPS
+ {
+ get { return Frames / Time; }
+ }
+ }
+ struct Rects
+ {
+ public Rectangle rect;
+ public Color color;
+ }
+ Random rnd = new Random();
+ FontSurface font;
- public void Main(string[] args)
+ delegate int TestMethod();
+
+ const int totalFrames = 300;
+
+ public void Main(string[] args)
{
- Core.Initialize();
+ Core.Initialize();
- List<AgateDriverInfo> drivers = Registrar.DisplayDrivers;
-
- frmPerformanceTester frm = new frmPerformanceTester();
- frm.Show();
+ List<AgateDriverInfo> drivers = Registrar.DisplayDrivers;
- Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
+ frmPerformanceTester frm = new frmPerformanceTester();
+ frm.Show();
- foreach (AgateDriverInfo info in drivers)
- {
- Trace.WriteLine(string.Format("Starting driver {0}...", info.FriendlyName));
- Trace.Indent();
- double fps;
+ Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
- Display.Initialize((DisplayTypeID)info.DriverTypeID);
- Display.VSync = false;
-
- DisplayWindow wind = DisplayWindow.CreateWindowed("Performance Test", 300, 300);
- font = new FontSurface("Arial", 11);
-
- Trace.WriteLine("Doing Filled Rect test");
- fps = FilledRectTest() * 1000;
- Trace.WriteLine(string.Format("The driver {0} got {1} fps.", info.FriendlyName, fps));
+ List<TestMethod> tests = new List<TestMethod>();
+ tests.Add(FilledRectTest);
+ tests.Add(DrawRectTest);
+ tests.Add(DrawSurfaceTestColored);
+ tests.Add(DrawSurfaceTestPlain);
+ tests.Add(StretchTestColored);
+ tests.Add(StretchTestPlain);
- Trace.WriteLine("Doing Draw Rect test");
- fps = DrawRectTest() * 1000;
- Trace.WriteLine(string.Format("The driver {0} got {1} fps.", info.FriendlyName, fps));
+ foreach (AgateDriverInfo info in drivers)
+ {
+ Trace.WriteLine(string.Format("Starting driver {0}...", info.FriendlyName));
+ Trace.Indent();
+ double fps;
- Trace.WriteLine("Doing Draw Surface test, no color");
- fps = DrawSurfaceTest(false) * 1000;
- Trace.WriteLine(string.Format("The driver {0} got {1} fps.", info.FriendlyName, fps));
+ Display.Initialize((DisplayTypeID)info.DriverTypeID);
+ Display.VSync = false;
- Trace.WriteLine("Doing Draw Surface test");
- fps = DrawSurfaceTest(true) * 1000;
- Trace.WriteLine(string.Format("The driver {0} got {1} fps.", info.FriendlyName, fps));
+ DisplayWindow wind = DisplayWindow.CreateWindowed("Performance Test", 300, 300);
+ font = new FontSurface("Arial", 11);
- Trace.WriteLine("Doing Stretch test, no color");
- fps = StretchTest(false) * 1000;
- Trace.WriteLine(string.Format("The driver {0} got {1} fps.", info.FriendlyName, fps));
+ for (int i = 0; i < tests.Count; i++)
+ {
+ TestResult r = Execute(tests[i]);
- Trace.WriteLine("Doing Stretch test");
- fps = StretchTest(true) * 1000;
- Trace.WriteLine(string.Format("The driver {0} got {1} fps.", info.FriendlyName, fps));
+ r.Driver = info.FriendlyName;
- //Trace.WriteLine("Doing Stretch test with queued rects");
- //fps = StretchTestQueue(true) * 1000;
- //Trace.WriteLine(string.Format("The driver {0} got {1} fps.", info.Name, fps));
+ frm.AddTestResult(r);
+ }
- Trace.Unindent();
+ if (Display.CurrentWindow.IsClosed)
+ {
+ Display.Dispose();
+ frm.Dispose();
+ return;
+ }
- if (Display.CurrentWindow.IsClosed)
- {
- Display.Dispose();
- frm.Dispose();
- return;
- }
+ Display.Dispose();
+ }
- Display.Dispose();
+ frm.Visible = false;
+ frm.ShowDialog();
+ }
- }
+ private TestResult Execute(TestMethod testMethod)
+ {
+ Timing.StopWatch timer = new Timing.StopWatch();
+ int frames = testMethod();
+ timer.Pause();
- frm.Visible = false;
- frm.ShowDialog();
- }
+ TestResult r = new TestResult();
- private double StretchTestQueue(bool applyColor)
- {
- Timing.StopWatch timer = new Timing.StopWatch();
- Surface surf = new Surface("jellybean.png");
- int frames = 0;
+ r.Name = testMethod.Method.Name;
+ r.Frames = frames;
+ r.Time = timer.TotalSeconds;
- surf.Color = Color.White;
- double count = 1;
+ return r;
+ }
- for (frames = 0; frames < totalFrames; frames++)
- {
- if (Display.CurrentWindow.IsClosed)
- return frames / (double)timer.TotalMilliseconds;
+ private int StretchTestQueue(bool applyColor)
+ {
+ Surface surf = new Surface("jellybean.png");
+ int frames = 0;
- count = 1 + Math.Cos(frames / 60.0);
+ surf.Color = Color.White;
+ double count = 1;
- Display.BeginFrame();
+ for (frames = 0; frames < totalFrames; frames++)
+ {
+ if (Display.CurrentWindow.IsClosed)
+ return frames;
-
- for (int i = 0; i < 15; i++)
- {
- surf.SetScale(1.0, 1.0);
- surf.Color = Color.White;
- surf.Draw(10, 10);
+ count = 1 + Math.Cos(frames / 60.0);
- if (applyColor)
- surf.Color = Color.Orange;
+ Display.BeginFrame();
- surf.SetScale(1.5, 1.5);
- surf.Draw(120, 10);
- if (applyColor)
- surf.Color = Color.LightGreen;
+ for (int i = 0; i < 15; i++)
+ {
+ surf.SetScale(1.0, 1.0);
+ surf.Color = Color.White;
+ surf.Draw(10, 10);
- surf.SetScale(count, 1.25);
- surf.Draw(10, 100);
+ if (applyColor)
+ surf.Color = Color.Orange;
- if (applyColor)
- surf.Color = Color.LightCoral;
+ surf.SetScale(1.5, 1.5);
+ surf.Draw(120, 10);
- surf.SetScale(0.5 + count / 2, 0.5 + count / 2);
- surf.Draw((int)(150 + 40 * Math.Cos(frames / 70.0)),
- (int)(120 + 40 * Math.Sin(frames / 70.0)));
+ if (applyColor)
+ surf.Color = Color.LightGreen;
- font.DrawText(string.Format("{0} frames per second.", Math.Round(Display.FramesPerSecond, 2)));
- }
+ surf.SetScale(count, 1.25);
+ surf.Draw(10, 100);
- Display.EndFrame();
- Core.KeepAlive();
+ if (applyColor)
+ surf.Color = Color.LightCoral;
- if (timer.TotalSeconds > 30)
- break;
- }
+ surf.SetScale(0.5 + count / 2, 0.5 + count / 2);
+ surf.Draw((int)(150 + 40 * Math.Cos(frames / 70.0)),
+ (int)(120 + 40 * Math.Sin(frames / 70.0)));
- return frames / (double)timer.TotalMilliseconds;
- }
-
- private double StretchTest(bool applyColor)
- {
- Timing.StopWatch timer = new Timing.StopWatch();
- Surface surf = new Surface("jellybean.png");
- int frames = 0;
+ font.DrawText(string.Format("{0} frames per second.", Math.Round(Display.FramesPerSecond, 2)));
+ }
- surf.Color = Color.White;
- double count = 1;
+ Display.EndFrame();
+ Core.KeepAlive();
+ }
- for (frames = 0; frames < totalFrames; frames++)
- {
- if (Display.CurrentWindow.IsClosed)
- return frames / (double)timer.TotalMilliseconds;
+ return frames;
+ }
- count = 1 + Math.Cos(frames / 60.0);
+ private int StretchTestColored()
+ {
+ return StretchTest(true);
+ }
+ private int StretchTestPlain()
+ {
+ return StretchTest(false);
+ }
- Display.BeginFrame();
- Display.Clear();
- for (int i = 0; i < 15; i++)
- {
-
- surf.SetScale(1.0, 1.0);
- surf.Color = Color.White;
- surf.Draw(10, 10);
+ private int StretchTest(bool applyColor)
+ {
+ Surface surf = new Surface("jellybean.png");
+ int frames = 0;
- if (applyColor)
- surf.Color = Color.Orange;
+ surf.Color = Color.White;
+ double count = 1;
- surf.SetScale(1.5, 1.5);
- surf.Draw(120, 10);
+ for (frames = 0; frames < totalFrames; frames++)
+ {
+ if (Display.CurrentWindow.IsClosed)
+ return frames;
- if (applyColor)
- surf.Color = Color.LightGreen;
+ count = 1.01 + Math.Cos(frames / 60.0);
- surf.SetScale(count, 1.25);
- surf.Draw(10, 100);
+ Display.BeginFrame();
+ Display.Clear();
+ for (int i = 0; i < 15; i++)
+ {
- if (applyColor)
- surf.Color = Color.LightCoral;
+ surf.SetScale(1.0, 1.0);
+ surf.Color = Color.White;
+ surf.Draw(10, 10);
- surf.SetScale(0.5 + count / 2, 0.5 + count / 2);
- surf.Draw((int)(150 + 40 * Math.Cos(frames / 70.0)),
- (int)(120 + 40 * Math.Sin(frames / 70.0)));
+ if (applyColor)
+ surf.Color = Color.Orange;
+ surf.SetScale(1.5, 1.5);
+ surf.Draw(120, 10);
- }
- font.DrawText(string.Format("{0} frames per second.", Math.Round(Display.FramesPerSecond, 2)));
+ if (applyColor)
+ surf.Color = Color.LightGreen;
- Display.EndFrame();
- Core.KeepAlive();
+ surf.SetScale(count, 1.25);
+ surf.Draw(10, 100);
- if (timer.TotalSeconds > 30)
- break;
- }
+ if (applyColor)
+ surf.Color = Color.LightCoral;
- return frames / (double)timer.TotalMilliseconds;
- }
-
- private double DrawSurfaceTest(bool applyColor)
- {
- Timing.StopWatch timer = new Timing.StopWatch();
- Surface surf = new Surface("jellybean.png");
- List<Rects> rects = new List<Rects>();
- int frames = 0;
+ surf.SetScale(0.5 + count / 2, 0.5 + count / 2);
+ surf.Draw((int)(150 + 40 * Math.Cos(frames / 70.0)),
+ (int)(120 + 40 * Math.Sin(frames / 70.0)));
- surf.Color = Color.White;
- for (int i = 1; i < 10; i++)
- {
- Rects r = CreateRandomRects();
+ }
+ font.DrawText(string.Format("{0} frames per second.", Math.Round(Display.FramesPerSecond, 2)));
- rects.Add(r);
- }
+ Display.EndFrame();
+ Core.KeepAlive();
+ }
- for (frames = 0; frames < totalFrames; frames++)
- {
- if (Display.CurrentWindow.IsClosed)
- return frames / (double)timer.TotalMilliseconds;
+ return frames;
+ }
- rects.Add(CreateRandomRects());
+ private int DrawSurfaceTestColored()
+ {
+ return DrawSurfaceTest(true);
+ }
+ private int DrawSurfaceTestPlain()
+ {
+ return DrawSurfaceTest(false);
+ }
- Display.BeginFrame();
- Display.Clear();
+ private int DrawSurfaceTest(bool applyColor)
+ {
+ Surface surf = new Surface("jellybean.png");
+ List<Rects> rects = new List<Rects>();
+ int frames = 0;
- if (applyColor)
- {
- for (int i = 0; i < rects.Count; i++)
- {
- surf.Color = rects[i].color;
- surf.Draw(rects[i].rect.Location);
- }
- }
- else
+ surf.Color = Color.White;
- for (int i = 0; i < rects.Count; i++)
- {
- surf.Draw(rects[i].rect.Location);
- }
+ for (int i = 1; i < 10; i++)
+ {
+ Rects r = CreateRandomRects();
- font.DrawText(string.Format("{0} frames per second.", Math.Round(Display.FramesPerSecond, 2)));
+ rects.Add(r);
+ }
- Display.EndFrame();
- Core.KeepAlive();
+ for (frames = 0; frames < totalFrames; frames++)
+ {
+ if (Display.CurrentWindow.IsClosed)
+ return frames;
- if (timer.TotalSeconds > 30)
- break;
- }
+ rects.Add(CreateRandomRects());
- return frames / (double)timer.TotalMilliseconds;
- }
+ Display.BeginFrame();
+ Display.Clear();
- private double DrawRectTest()
- {
- Timing.StopWatch timer = new Timing.StopWatch();
- List<Rects> rects = new List<Rects>();
- int frames = 0;
+ if (applyColor)
+ {
+ for (int i = 0; i < rects.Count; i++)
+ {
+ surf.Color = rects[i].color;
+ surf.Draw(rects[i].rect.Location);
+ }
+ }
+ else
- for (int i = 1; i < 10; i++)
- {
- Rects r = CreateRandomRects();
+ for (int i = 0; i < rects.Count; i++)
+ {
+ surf.Draw(rects[i].rect.Location);
+ }
- rects.Add(r);
- }
+ font.DrawText(string.Format("{0} frames per second.", Math.Round(Display.FramesPerSecond, 2)));
- for (frames = 0; frames < totalFrames; frames++)
- {
- if (Display.CurrentWindow.IsClosed)
- return frames / (double)timer.TotalMilliseconds;
+ Display.EndFrame();
+ Core.KeepAlive();
- rects.Add(CreateRandomRects());
+ }
- Display.BeginFrame();
- Display.Clear();
+ return frames;
+ }
- for (int i = 0; i < rects.Count; i++)
- {
- Display.DrawRect(rects[i].rect, rects[i].color);
- }
+ private int DrawRectTest()
+ {
+ List<Rects> rects = new List<Rects>();
+ int frames = 0;
- font.DrawText(string.Format("{0} frames per second.", Math.Round(Display.FramesPerSecond, 2)));
+ for (int i = 1; i < 10; i++)
+ {
+ Rects r = CreateRandomRects();
- Display.EndFrame();
- Core.KeepAlive();
+ rects.Add(r);
+ }
+ for (frames = 0; frames < totalFrames; frames++)
+ {
+ if (Display.CurrentWindow.IsClosed)
+ return frames;
- if (timer.TotalSeconds > 30)
- break;
- }
+ rects.Add(CreateRandomRects());
- return frames / (double)timer.TotalMilliseconds;
- }
+ Display.BeginFrame();
+ Display.Clear();
- private double FilledRectTest()
- {
- Timing.StopWatch timer = new Timing.StopWatch();
- List<Rects> rects = new List<Rects>();
- int frames = 0;
-
- for (int i = 1; i < 10; i++)
- {
- Rects r = CreateRandomRects();
+ for (int i = 0; i < rects.Count; i++)
+ {
+ Display.DrawRect(rects[i].rect, rects[i].color);
+ }
- rects.Add(r);
- }
+ font.DrawText(string.Format("{0} frames per second.", Math.Round(Display.FramesPerSecond, 2)));
- for (frames = 0; frames < totalFrames; frames++)
- {
- if (Display.CurrentWindow.IsClosed)
- return frames / (double)timer.TotalMilliseconds;
+ Display.EndFrame();
+ Core.KeepAlive();
- rects.Add(CreateRandomRects());
+ }
- Display.BeginFrame();
- Display.Clear();
+ return frames;
+ }
- for (int i = 0; i < rects.Count; i++)
- {
- Display.FillRect(rects[i].rect, rects[i].color);
- }
+ private int FilledRectTest()
+ {
+ List<Rects> rects = new List<Rects>();
+ int frames = 0;
- font.DrawText(string.Format("{0} frames per second.", Math.Round(Display.FramesPerSecond, 2)));
+ for (int i = 1; i < 10; i++)
+ {
+ Rects r = CreateRandomRects();
- Display.EndFrame();
- Core.KeepAlive();
+ rects.Add(r);
+ }
+ for (frames = 0; frames < totalFrames; frames++)
+ {
+ if (Display.CurrentWindow.IsClosed)
+ return frames;
- if (timer.TotalSeconds > 30)
- break;
- }
+ rects.Add(CreateRandomRects());
- return frames / (double)timer.TotalMilliseconds;
- }
+ Display.BeginFrame();
+ Display.Clear();
- private Rects CreateRandomRects()
- {
- Rects r = new Rects();
+ for (int i = 0; i < rects.Count; i++)
+ {
+ Display.FillRect(rects[i].rect, rects[i].color);
+ }
- r.rect = new Rectangle(
- rnd.Next(10, 250), rnd.Next(10, 250),
- rnd.Next(10, 40), rnd.Next(10, 40));
- r.color = Color.FromArgb(
- rnd.Next(128, 256), rnd.Next(128, 256), rnd.Next(128, 256), rnd.Next(128, 256));
+ font.DrawText(string.Format("{0} frames per second.", Math.Round(Display.FramesPerSecond, 2)));
- return r;
- }
+ Display.EndFrame();
+ Core.KeepAlive();
- #region IAgateTest Members
+;
+ }
- public string Name { get { return "Performance Tester"; } }
- public string Category { get { return "Core"; } }
+ return frames;
+ }
- #endregion
- }
+ private Rects CreateRandomRects()
+ {
+ Rects r = new Rects();
+
+ r.rect = new Rectangle(
+ rnd.Next(10, 250), rnd.Next(10, 250),
+ rnd.Next(10, 40), rnd.Next(10, 40));
+ r.color = Color.FromArgb(
+ rnd.Next(128, 256), rnd.Next(128, 256), rnd.Next(128, 256), rnd.Next(128, 256));
+
+ return r;
+ }
+
+ #region IAgateTest Members
+
+ public string Name { get { return "Performance Tester"; } }
+ public string Category { get { return "Core"; } }
+
+ #endregion
+ }
}
\ No newline at end of file
Modified: trunk/Tests/CoreTests/Performance/frmPerformance.Designer.cs
===================================================================
--- trunk/Tests/CoreTests/Performance/frmPerformance.Designer.cs 2009-04-12 07:38:42 UTC (rev 852)
+++ trunk/Tests/CoreTests/Performance/frmPerformance.Designer.cs 2009-04-12 17:28:41 UTC (rev 853)
@@ -31,37 +31,70 @@
/// </summary>
private void InitializeComponent()
{
- System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmPerformanceTester));
- this.textBox1 = new System.Windows.Forms.TextBox();
- this.SuspendLayout();
- //
- // textBox1
- //
- this.textBox1.Dock = System.Windows.Forms.DockStyle.Fill;
- this.textBox1.Location = new System.Drawing.Point(0, 0);
- this.textBox1.Multiline = true;
- this.textBox1.Name = "textBox1";
- this.textBox1.ReadOnly = true;
- this.textBox1.Size = new System.Drawing.Size(449, 306);
- this.textBox1.TabIndex = 0;
- //
- // frmPerformanceTester
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(449, 306);
- this.Controls.Add(this.textBox1);
- this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
- this.Name = "frmPerformanceTester";
- this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
- this.Text = "Form1";
- this.ResumeLayout(false);
- this.PerformLayout();
+ System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmPerformanceTester));
+ this.listView1 = new System.Windows.Forms.ListView();
+ this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
+ this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
+ this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
+ this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
+ this.SuspendLayout();
+ //
+ // listView1
+ //
+ this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
+ this.columnHeader1,
+ this.columnHeader2,
+ this.columnHeader3,
+ this.columnHeader4});
+ this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.listView1.Location = new System.Drawing.Point(0, 0);
+ this.listView1.Name = "listView1";
+ this.listView1.Size = new System.Drawing.Size(482, 421);
+ this.listView1.TabIndex = 0;
+ this.listView1.UseCompatibleStateImageBehavior = false;
+ this.listView1.View = System.Windows.Forms.View.Details;
+ //
+ // columnHeader1
+ //
+ this.columnHeader1.Text = "Driver";
+ this.columnHeader1.Width = 194;
+ //
+ // columnHeader2
+ //
+ this.columnHeader2.Text = "Test";
+ this.columnHeader2.Width = 146;
+ //
+ // columnHeader3
+ //
+ this.columnHeader3.Text = "Time";
+ this.columnHeader3.Width = 63;
+ //
+ // columnHeader4
+ //
+ this.columnHeader4.Text = "FPS";
+ this.columnHeader4.Width = 66;
+ //
+ // frmPerformanceTester
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(482, 421);
+ this.Controls.Add(this.listView1);
+ this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
+ this.Name = "frmPerformanceTester";
+ this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
+ this.Text = "Performance Test Results";
+ this.ResumeLayout(false);
}
#endregion
- private System.Windows.Forms.TextBox textBox1;
- }
+ private System.Windows.Forms.ListView listView1;
+ private System.Windows.Forms.ColumnHeader columnHeader1;
+ private System.Windows.Forms.ColumnHeader columnHeader2;
+ private System.Windows.Forms.ColumnHeader columnHeader3;
+ private System.Windows.Forms.ColumnHeader columnHeader4;
+
+ }
}
\ No newline at end of file
Modified: trunk/Tests/CoreTests/Performance/frmPerformance.cs
===================================================================
--- trunk/Tests/CoreTests/Performance/frmPerformance.cs 2009-04-12 07:38:42 UTC (rev 852)
+++ trunk/Tests/CoreTests/Performance/frmPerformance.cs 2009-04-12 17:28:41 UTC (rev 853)
@@ -12,55 +12,20 @@
namespace Tests.PerformanceTester
{
- public partial class frmPerformanceTester : Form
- {
- Listener listen;
+ public partial class frmPerformanceTester : Form
+ {
+ public frmPerformanceTester()
+ {
+ InitializeComponent();
+ this.Location = new Point(Screen.GetBounds(this).Width - this.Width - 10, 10);
+ }
- public class Listener : TraceListener
- {
- frmPerformanceTester frm;
+ internal void AddTestResult(PerformanceTester.TestResult r)
+ {
+ var item = new ListViewItem(
+ new string[] { r.Driver, r.Name, r.Time.ToString("0.000"), r.FPS.ToString("0.0") });
- public Listener(frmPerformanceTester frm)
- {
- this.frm = frm;
- }
-
- public override void Write(string message)
- {
- if (frm.IsDisposed == false)
- {
- if (NeedIndent)
- {
- for (int i = 0; i < IndentLevel * IndentSize; i++)
- message = " " + message;
- }
-
- try
- {
- frm.textBox1.AppendText(message);
- }
- catch
- {
-
- }
-
- }
- }
-
- public override void WriteLine(string message)
- {
- Write(message + "\r\n");
-
- }
- }
- public frmPerformanceTester()
- {
- InitializeComponent();
-
- listen = new Listener(this);
- Trace.Listeners.Add(listen);
-
- this.Location = new Point(Screen.GetBounds(this).Width - this.Width - 10, 10);
- }
- }
+ listView1.Items.Add(item);
+ }
+ }
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-04-12 07:38:43
|
Revision: 852
http://agate.svn.sourceforge.net/agate/?rev=852&view=rev
Author: kanato
Date: 2009-04-12 07:38:42 +0000 (Sun, 12 Apr 2009)
Log Message:
-----------
Add simple heightmap.png
Added Paths:
-----------
branches/agate-3d/Tests/TestImages/heightmap.png
Added: branches/agate-3d/Tests/TestImages/heightmap.png
===================================================================
(Binary files differ)
Property changes on: branches/agate-3d/Tests/TestImages/heightmap.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-04-12 07:28:30
|
Revision: 851
http://agate.svn.sourceforge.net/agate/?rev=851&view=rev
Author: kanato
Date: 2009-04-12 07:28:27 +0000 (Sun, 12 Apr 2009)
Log Message:
-----------
Make normal strength a parameter to NormalMapFromHeightMap.
Modified Paths:
--------------
branches/agate-3d/AgateLib/DisplayLib/PixelBuffer.cs
branches/agate-3d/AgateLib/Geometry/Builders/Cube.cs
Modified: branches/agate-3d/AgateLib/DisplayLib/PixelBuffer.cs
===================================================================
--- branches/agate-3d/AgateLib/DisplayLib/PixelBuffer.cs 2009-04-12 07:27:48 UTC (rev 850)
+++ branches/agate-3d/AgateLib/DisplayLib/PixelBuffer.cs 2009-04-12 07:28:27 UTC (rev 851)
@@ -1003,6 +1003,10 @@
public static PixelBuffer NormalMapFromHeightMap(PixelBuffer buffer)
{
+ return NormalMapFromHeightMap(buffer, 8.0f);
+ }
+ public static PixelBuffer NormalMapFromHeightMap(PixelBuffer buffer, float normalStr)
+ {
int[,] heights = new int[buffer.Width, buffer.Height];
for (int j = 0; j < buffer.Height; j++)
@@ -1015,7 +1019,6 @@
PixelBuffer retval = new PixelBuffer(buffer.PixelFormat, buffer.Size);
int[,] square = new int[3,3];
- float normalStr = 8;
for (int j = 0; j < retval.Height; j++)
{
Modified: branches/agate-3d/AgateLib/Geometry/Builders/Cube.cs
===================================================================
--- branches/agate-3d/AgateLib/Geometry/Builders/Cube.cs 2009-04-12 07:27:48 UTC (rev 850)
+++ branches/agate-3d/AgateLib/Geometry/Builders/Cube.cs 2009-04-12 07:28:27 UTC (rev 851)
@@ -84,12 +84,12 @@
int i = 0;
for (int sign = -1; sign >= 1; sign += 2)
- {
+ {
retval[i++] = new Vector3(0, sign, 0);
retval[i++] = new Vector3(0, sign, 0);
retval[i++] = new Vector3(0, sign, 0);
- retval[i++] = new Vector3(0, sign, 0);
-
+ retval[i++] = new Vector3(0, sign, 0);
+
retval[i++] = new Vector3(sign, 0, 0);
retval[i++] = new Vector3(sign, 0, 0);
retval[i++] = new Vector3(sign, 0, 0);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-04-12 07:27:55
|
Revision: 850
http://agate.svn.sourceforge.net/agate/?rev=850&view=rev
Author: kanato
Date: 2009-04-12 07:27:48 +0000 (Sun, 12 Apr 2009)
Log Message:
-----------
Update bumpmap code.
Modified Paths:
--------------
branches/agate-3d/Tests/Display3D/Glsl/Glsl.cs
Added Paths:
-----------
branches/agate-3d/Tests/Display3D/Glsl/Resources/
branches/agate-3d/Tests/Display3D/Glsl/Resources/BumpMap_fragment.txt
branches/agate-3d/Tests/Display3D/Glsl/Resources/BumpMap_vertex.txt
branches/agate-3d/Tests/Display3D/Glsl/Resources/PerPixelLighting_fragment.txt
branches/agate-3d/Tests/Display3D/Glsl/Resources/PerPixelLighting_vertex.txt
branches/agate-3d/Tests/Display3D/Glsl/Shaders.Designer.cs
branches/agate-3d/Tests/Display3D/Glsl/Shaders.resx
Modified: branches/agate-3d/Tests/Display3D/Glsl/Glsl.cs
===================================================================
--- branches/agate-3d/Tests/Display3D/Glsl/Glsl.cs 2009-04-12 05:06:01 UTC (rev 849)
+++ branches/agate-3d/Tests/Display3D/Glsl/Glsl.cs 2009-04-12 07:27:48 UTC (rev 850)
@@ -63,7 +63,7 @@
FontSurface font = new FontSurface("Arial", 14.0f);
Surface texture = new Surface("bg-bricks.png");
- Surface height = new Surface("bg-bricks-heightmap.png");
+ Surface height = new Surface("heightmap.png");
//Surface height = new Surface("jellybean.png");
LightManager m = new LightManager();
@@ -72,7 +72,7 @@
m.Ambient = Color.FromArgb(0, 255, 0);
m[0].AttenuationConstant = 0.0001f;
m[0].AttenuationLinear = 0.004f;
- m[0].AttenuationQuadratic = 0.00006f;
+ m[0].AttenuationQuadratic = 0.0001f;
m[0].Range = 200;
double time = 0;
@@ -89,7 +89,8 @@
VertexBuffer buffer = b.CreateVertexBuffer();
buffer.Textures[0] = texture;
- buffer.Textures[1] = new Surface(PixelBuffer.NormalMapFromHeightMap(height.ReadPixels()));
+ buffer.Textures[1] = new Surface(
+ PixelBuffer.NormalMapFromHeightMap(height.ReadPixels(), 2.0f));
buffer.Textures[1].SaveTo("normal.png");
//var shader = ShaderCompiler.CompileShader(ShaderLanguage.Glsl,
@@ -107,7 +108,7 @@
if (Core.IsActive)
{
Vector3 move = lookDir * velocity * Display.DeltaTime;
- Vector3 strafe = Vector3.CrossProduct(move, up).Normalize()*velocity * Display.DeltaTime;
+ Vector3 strafe = Vector3.CrossProduct(move, up).Normalize() * velocity * Display.DeltaTime;
Vector3 fly = new Vector3(0, 0, velocity * Display.DeltaTime);
if (Keyboard.Keys[KeyCode.W]) eye += move;
@@ -128,8 +129,8 @@
phi -= mouseDiff.X * mousevelocity;
resetmouse();
- if (phi < -Math.PI) phi += (float)(Math.PI * 2);
- if (phi > Math.PI) phi -= (float)(Math.PI * 2);
+ if (phi < -Math.PI) phi += (float)(Math.PI * 2);
+ if (phi > Math.PI) phi -= (float)(Math.PI * 2);
if (theta < 0) theta = 0;
if (theta > Math.PI) theta = (float)Math.PI;
}
@@ -153,8 +154,8 @@
m[0].Position = eye;
m.DoLighting();
- Display.MatrixWorld = Matrix4.RotateZ((float)(frequency * time))
- * Matrix4.Translation(-size / 2, -size / 2, 0);
+ Display.MatrixWorld =
+ Matrix4.Translation(-size / 2, -size / 2, 0) * Matrix4.RotateZ((float)(frequency * time));
buffer.Draw();
@@ -169,7 +170,10 @@
void Mouse_MouseDown(InputEventArgs e)
{
- rotating = !rotating;
+ if (e.MouseButtons == Mouse.MouseButtons.Secondary)
+ {
+ rotating = !rotating;
+ }
}
}
Added: branches/agate-3d/Tests/Display3D/Glsl/Resources/BumpMap_fragment.txt
===================================================================
--- branches/agate-3d/Tests/Display3D/Glsl/Resources/BumpMap_fragment.txt (rev 0)
+++ branches/agate-3d/Tests/Display3D/Glsl/Resources/BumpMap_fragment.txt 2009-04-12 07:27:48 UTC (rev 850)
@@ -0,0 +1,46 @@
+varying vec4 diffuse,ambientGlobal, ambient;
+varying vec3 normal,lightDir,halfVector;
+varying float dist;
+uniform sampler2D texture0;
+uniform sampler2D texture1;
+
+void main()
+{
+ vec3 n,halfV,viewV,ldir;
+ float NdotL,NdotHV;
+ vec4 color = ambientGlobal;
+ float att;
+
+ /* a fragment shader can't write a varying variable, hence we need
+ a new variable to store the normalized interpolated normal */
+ n = normalize(normal);
+
+ // calculate the bumpmap properties
+ vec4 bumpcolor = texture2D(texture1,gl_TexCoord[0].st);
+ bumpcolor = bumpcolor * 2.0 - 1.0;
+ n = normalize(bumpcolor.rgb);
+ //n = vec3(0.707,0,0.707);
+
+ /* compute the dot product between normal and normalized lightdir */
+ NdotL = max(dot(n,normalize(lightDir)),0.0);
+
+ if (NdotL > 0.0) {
+ att = 1.0 / (gl_LightSource[0].constantAttenuation +
+ gl_LightSource[0].linearAttenuation * dist +
+ gl_LightSource[0].quadraticAttenuation * dist * dist);
+
+ color += att * (diffuse * NdotL + ambient);
+
+ halfV = normalize(halfVector);
+ NdotHV = max(dot(n,halfV),0.0);
+ color += att * gl_FrontMaterial.specular * gl_LightSource[0].specular *
+ pow(NdotHV,gl_FrontMaterial.shininess);
+ }
+
+ vec4 texcolor = texture2D(texture0,gl_TexCoord[0].st);
+
+ color.rgb *= texcolor.rgb;
+
+ gl_FragColor = color;
+}
+
Added: branches/agate-3d/Tests/Display3D/Glsl/Resources/BumpMap_vertex.txt
===================================================================
--- branches/agate-3d/Tests/Display3D/Glsl/Resources/BumpMap_vertex.txt (rev 0)
+++ branches/agate-3d/Tests/Display3D/Glsl/Resources/BumpMap_vertex.txt 2009-04-12 07:27:48 UTC (rev 850)
@@ -0,0 +1,43 @@
+
+attribute vec3 tangent; //The inverse tangent to the geometry
+attribute vec3 bitangent; //The inverse binormal to the geometry
+
+varying vec4 diffuse,ambientGlobal,ambient;
+varying vec3 normal,lightDir,halfVector;
+varying float dist;
+
+void main()
+{
+ vec3 aux;
+
+ normal = normalize(gl_Normal);
+
+ // Building the matrix Eye Space -> Tangent Space
+ vec3 n = normalize (gl_NormalMatrix * gl_Normal);
+ vec3 t = normalize (gl_NormalMatrix * tangent);
+ vec3 b = normalize (gl_NormalMatrix * bitangent);
+
+ vec4 evPos = gl_ModelViewMatrix * gl_Vertex;
+ vec3 lightVec = vec3(gl_LightSource[0].position.xyz - evPos.xyz);
+
+ vec3 v;
+ v.x = dot(lightVec, t);
+ v.y = dot(lightVec, b);
+ v.z = dot(lightVec, n);
+ lightDir = normalize(v);
+
+ dist = length(lightVec);
+
+ halfVector = normalize(gl_LightSource[0].halfVector.xyz);
+
+ /* Compute the diffuse, ambient and globalAmbient terms */
+ diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
+
+ /* The ambient terms have been separated since one of them */
+ /* suffers attenuation */
+ ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
+ ambientGlobal = gl_LightModel.ambient * gl_FrontMaterial.ambient;
+
+ gl_Position = ftransform();
+ gl_TexCoord[0] = gl_MultiTexCoord0;
+}
Added: branches/agate-3d/Tests/Display3D/Glsl/Resources/PerPixelLighting_fragment.txt
===================================================================
--- branches/agate-3d/Tests/Display3D/Glsl/Resources/PerPixelLighting_fragment.txt (rev 0)
+++ branches/agate-3d/Tests/Display3D/Glsl/Resources/PerPixelLighting_fragment.txt 2009-04-12 07:27:48 UTC (rev 850)
@@ -0,0 +1,40 @@
+varying vec4 diffuse,ambientGlobal, ambient;
+varying vec3 normal,lightDir,halfVector;
+varying float dist;
+uniform sampler2D texture0;
+
+
+void main()
+{
+ vec3 n,halfV,viewV,ldir;
+ float NdotL,NdotHV;
+ vec4 color = ambientGlobal;
+ float att;
+
+ /* a fragment shader can't write a varying variable, hence we need
+ a new variable to store the normalized interpolated normal */
+ n = normalize(normal);
+
+ /* compute the dot product between normal and normalized lightdir */
+ NdotL = max(dot(n,normalize(lightDir)),0.0);
+
+ if (NdotL > 0.0) {
+ att = 1.0 / (gl_LightSource[0].constantAttenuation +
+ gl_LightSource[0].linearAttenuation * dist +
+ gl_LightSource[0].quadraticAttenuation * dist * dist);
+
+ color += att * (diffuse * NdotL + ambient);
+
+ halfV = normalize(halfVector);
+ NdotHV = max(dot(n,halfV),0.0);
+ color += att * gl_FrontMaterial.specular * gl_LightSource[0].specular *
+ pow(NdotHV,gl_FrontMaterial.shininess);
+ }
+
+ vec4 texcolor = texture2D(texture0,gl_TexCoord[0].st);
+
+ color.rgb *= texcolor.rgb;
+
+ gl_FragColor = color;
+}
+
Added: branches/agate-3d/Tests/Display3D/Glsl/Resources/PerPixelLighting_vertex.txt
===================================================================
--- branches/agate-3d/Tests/Display3D/Glsl/Resources/PerPixelLighting_vertex.txt (rev 0)
+++ branches/agate-3d/Tests/Display3D/Glsl/Resources/PerPixelLighting_vertex.txt 2009-04-12 07:27:48 UTC (rev 850)
@@ -0,0 +1,31 @@
+varying vec4 diffuse,ambientGlobal,ambient;
+varying vec3 normal,lightDir,halfVector;
+varying float dist;
+
+void main()
+{
+ vec4 ecPos;
+ vec3 aux;
+
+ normal = normalize(gl_NormalMatrix * gl_Normal);
+
+ /* these are the new lines of code to compute the light's direction */
+ ecPos = gl_ModelViewMatrix * gl_Vertex;
+ aux = vec3(gl_LightSource[0].position-ecPos);
+ lightDir = normalize(aux);
+ dist = length(aux);
+
+ halfVector = normalize(gl_LightSource[0].halfVector.xyz);
+
+ /* Compute the diffuse, ambient and globalAmbient terms */
+ diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
+
+ /* The ambient terms have been separated since one of them */
+ /* suffers attenuation */
+ ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
+ ambientGlobal = gl_LightModel.ambient * gl_FrontMaterial.ambient;
+
+
+ gl_Position = ftransform();
+ gl_TexCoord[0] = gl_MultiTexCoord0;
+}
Added: branches/agate-3d/Tests/Display3D/Glsl/Shaders.Designer.cs
===================================================================
--- branches/agate-3d/Tests/Display3D/Glsl/Shaders.Designer.cs (rev 0)
+++ branches/agate-3d/Tests/Display3D/Glsl/Shaders.Designer.cs 2009-04-12 07:27:48 UTC (rev 850)
@@ -0,0 +1,165 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// Runtime Version:2.0.50727.3074
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace Glsl {
+ using System;
+
+
+ /// <summary>
+ /// A strongly-typed resource class, for looking up localized strings, etc.
+ /// </summary>
+ // This class was auto-generated by the StronglyTypedResourceBuilder
+ // class via a tool like ResGen or Visual Studio.
+ // To add or remove a member, edit your .ResX file then rerun ResGen
+ // with the /str option, or rebuild your VS project.
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class Shaders {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal Shaders() {
+ }
+
+ /// <summary>
+ /// Returns the cached ResourceManager instance used by this class.
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Glsl.Shaders", typeof(Shaders).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ /// <summary>
+ /// Overrides the current thread's CurrentUICulture property for all
+ /// resource lookups using this strongly typed resource class.
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to uniform sampler2D DecalTex; //The texture
+ ///uniform sampler2D BumpTex; //The bump-map
+ ///
+ ///varying vec4 passcolor; //Receiving the vertex color from the vertex shader
+ ///varying vec3 LightDir; //Receiving the transformed light direction
+ ///
+ ///void main()
+ ///{
+ /// //Get the color of the bump-map
+ /// vec3 BumpNorm = vec3(texture2D(BumpTex, gl_TexCoord[0].xy));
+ ///
+ /// //Get the color of the texture
+ /// vec3 DecalCol = vec3(texture2D(DecalTex, gl_TexCoord[0].xy));
+ ///
+ /// //Expand the bump-map into a normalized signed vector
+ /// B [rest of string was truncated]";.
+ /// </summary>
+ internal static string BumpMap_fragment {
+ get {
+ return ResourceManager.GetString("BumpMap_fragment", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to varying vec4 passcolor; //The vertex color passed
+ ///varying vec3 LightDir; //The transformed light direction, to pass to the fragment shader
+ ///attribute vec3 tangent; //The inverse tangent to the geometry
+ ///attribute vec3 binormal; //The inverse binormal to the geometry
+ ///uniform vec3 lightdir; //The direction the light is shining
+ ///
+ ///void main()
+ ///{
+ /// //Put the color in a varying variable
+ /// passcolor = gl_Color;
+ ///
+ /// //Put the vertex in the position passed
+ /// gl_Position = ftransform();
+ ///
+ /// //Construct a 3x3 m [rest of string was truncated]";.
+ /// </summary>
+ internal static string BumpMap_vertex {
+ get {
+ return ResourceManager.GetString("BumpMap_vertex", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to varying vec4 diffuse,ambientGlobal, ambient;
+ ///varying vec3 normal,lightDir,halfVector;
+ ///varying float dist;
+ ///uniform sampler2D tex;
+ ///uniform sampler2D tex2;
+ ///
+ ///void main()
+ ///{
+ /// vec3 n,halfV,viewV,ldir;
+ /// float NdotL,NdotHV;
+ /// vec4 color = ambientGlobal;
+ /// float att;
+ ///
+ /// /* a fragment shader can't write a varying variable, hence we need
+ /// a new variable to store the normalized interpolated normal */
+ /// n = normalize(normal);
+ ///
+ /// /* compute the dot product between normal and normalized lightdir */
+ /// NdotL = [rest of string was truncated]";.
+ /// </summary>
+ internal static string PerPixelLighting_fragment {
+ get {
+ return ResourceManager.GetString("PerPixelLighting_fragment", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to varying vec4 diffuse,ambientGlobal,ambient;
+ ///varying vec3 normal,lightDir,halfVector;
+ ///varying float dist;
+ ///
+ ///void main()
+ ///{
+ /// vec4 ecPos;
+ /// vec3 aux;
+ ///
+ /// normal = normalize(gl_NormalMatrix * gl_Normal);
+ ///
+ /// /* these are the new lines of code to compute the light's direction */
+ /// ecPos = gl_ModelViewMatrix * gl_Vertex;
+ /// aux = vec3(gl_LightSource[0].position-ecPos);
+ /// lightDir = normalize(aux);
+ /// dist = length(aux);
+ ///
+ /// halfVector = normalize(gl_LightSource[0].halfVector.xyz);
+ ///
+ /// /* Compute the diffuse [rest of string was truncated]";.
+ /// </summary>
+ internal static string PerPixelLighting_vertex {
+ get {
+ return ResourceManager.GetString("PerPixelLighting_vertex", resourceCulture);
+ }
+ }
+ }
+}
Added: branches/agate-3d/Tests/Display3D/Glsl/Shaders.resx
===================================================================
--- branches/agate-3d/Tests/Display3D/Glsl/Shaders.resx (rev 0)
+++ branches/agate-3d/Tests/Display3D/Glsl/Shaders.resx 2009-04-12 07:27:48 UTC (rev 850)
@@ -0,0 +1,133 @@
+<?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=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+ <data name="BumpMap_fragment" type="System.Resources.ResXFileRef, System.Windows.Forms">
+ <value>Resources\BumpMap_fragment.txt;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
+ </data>
+ <data name="BumpMap_vertex" type="System.Resources.ResXFileRef, System.Windows.Forms">
+ <value>Resources\BumpMap_vertex.txt;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
+ </data>
+ <data name="PerPixelLighting_fragment" type="System.Resources.ResXFileRef, System.Windows.Forms">
+ <value>Resources\PerPixelLighting_fragment.txt;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
+ </data>
+ <data name="PerPixelLighting_vertex" type="System.Resources.ResXFileRef, System.Windows.Forms">
+ <value>Resources\PerPixelLighting_vertex.txt;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
+ </data>
+</root>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-04-12 05:06:06
|
Revision: 849
http://agate.svn.sourceforge.net/agate/?rev=849&view=rev
Author: kanato
Date: 2009-04-12 05:06:01 +0000 (Sun, 12 Apr 2009)
Log Message:
-----------
Preliminary support for multi-texturing shaders.
Modified Paths:
--------------
branches/agate-3d/AgateLib/DisplayLib/PixelBuffer.cs
branches/agate-3d/AgateLib/DisplayLib/Shaders/ShaderProgram.cs
branches/agate-3d/AgateLib/DisplayLib/VertexBuffer.cs
branches/agate-3d/AgateLib/Geometry/Builders/Cube.cs
branches/agate-3d/AgateLib/Geometry/Vector3.cs
branches/agate-3d/AgateLib/ImplementationBase/VertexBufferImpl.cs
branches/agate-3d/AgateLib/InputLib/Mouse.cs
branches/agate-3d/Drivers/AgateOTK/GL_Display.cs
branches/agate-3d/Drivers/AgateOTK/GL_Surface.cs
branches/agate-3d/Drivers/AgateOTK/GL_VertexBuffer.cs
branches/agate-3d/Drivers/AgateOTK/GlslShader.cs
branches/agate-3d/Drivers/AgateOTK/GlslShaderCompiler.cs
branches/agate-3d/Drivers/AgateOTK/OpenTK.Utilities.dll
branches/agate-3d/Drivers/AgateOTK/OpenTK.dll
branches/agate-3d/Tests/Display3D/Glsl/Glsl.cs
branches/agate-3d/Tests/Display3D/Test3D/Test3d.cs
branches/agate-3d/Tests/Display3D/TestMatrices/Matrices.cs
Modified: branches/agate-3d/AgateLib/DisplayLib/PixelBuffer.cs
===================================================================
--- branches/agate-3d/AgateLib/DisplayLib/PixelBuffer.cs 2009-04-11 05:09:45 UTC (rev 848)
+++ branches/agate-3d/AgateLib/DisplayLib/PixelBuffer.cs 2009-04-12 05:06:01 UTC (rev 849)
@@ -1000,5 +1000,77 @@
}
#endregion
- }
+
+ public static PixelBuffer NormalMapFromHeightMap(PixelBuffer buffer)
+ {
+ int[,] heights = new int[buffer.Width, buffer.Height];
+
+ for (int j = 0; j < buffer.Height; j++)
+ {
+ for (int i = 0; i < buffer.Width; i++)
+ {
+ heights[i, j] = (int)(buffer.GetPixel(i, j).Intensity * short.MaxValue);
+ }
+ }
+
+ PixelBuffer retval = new PixelBuffer(buffer.PixelFormat, buffer.Size);
+ int[,] square = new int[3,3];
+ float normalStr = 8;
+
+ for (int j = 0; j < retval.Height; j++)
+ {
+ for (int i = 0; i < retval.Width; i++)
+ {
+ GetSquare(square, heights, i, j);
+
+ // sobel operator:
+ int diffx = square[0, 0] - square[2, 0] +
+ 2 * (square[0, 1] - square[2, 1]) +
+ square[0, 2] - square[2, 0];
+
+ int diffy = square[0, 0] + 2 * square[1, 0] + square[0, 2] +
+ -square[0, 2] - 2 * square[1, 2] - square[2, 2];
+
+ Vector3 vec = new Vector3(diffx / (float)short.MaxValue, diffy / (float)short.MaxValue, 0);
+ vec *= normalStr;
+ vec.Z = 1;
+
+ vec = vec.Normalize();
+ vec = vec / 2;
+ vec.X += 0.5f; vec.Y += 0.5f; vec.Z += 0.5f;
+ Color clr = Color.FromArgb((int)(vec.X * 255),
+ (int)(vec.Y * 255),
+ (int)(vec.Z * 255));
+
+ retval.SetPixel(i, j, clr);
+ }
+ }
+
+ return retval;
+ }
+
+ private static void GetSquare(int[,] square, int[,] heights, int x, int y)
+ {
+ for (int j = -1; j <= 1; j++)
+ {
+ for (int i = -1; i <= 1; i++)
+ {
+ int val = GetValueWrap(heights, x + i, y + j);
+
+ square[i + 1, j + 1] = val;
+ }
+ }
+ }
+
+ private static int GetValueWrap(int[,] heights, int x, int y)
+ {
+ if (x < 0) x += heights.GetUpperBound(0) + 1;
+ if (y < 0) y += heights.GetUpperBound(1) + 1;
+ if (x > heights.GetUpperBound(0)) x -= heights.GetUpperBound(0) + 1;
+ if (y > heights.GetUpperBound(1)) y -= heights.GetUpperBound(1) + 1;
+
+ return heights[x, y];
+ }
+
+ }
}
Modified: branches/agate-3d/AgateLib/DisplayLib/Shaders/ShaderProgram.cs
===================================================================
--- branches/agate-3d/AgateLib/DisplayLib/Shaders/ShaderProgram.cs 2009-04-11 05:09:45 UTC (rev 848)
+++ branches/agate-3d/AgateLib/DisplayLib/Shaders/ShaderProgram.cs 2009-04-12 05:06:01 UTC (rev 849)
@@ -31,5 +31,7 @@
{
SetUniform(name, color.R / 255.0f, color.G / 255.0f, color.B / 255.0f, color.A / 255.0f);
}
+
+ public VertexLayout VertexDefinition { get; set; }
}
}
Modified: branches/agate-3d/AgateLib/DisplayLib/VertexBuffer.cs
===================================================================
--- branches/agate-3d/AgateLib/DisplayLib/VertexBuffer.cs 2009-04-11 05:09:45 UTC (rev 848)
+++ branches/agate-3d/AgateLib/DisplayLib/VertexBuffer.cs 2009-04-12 05:06:01 UTC (rev 849)
@@ -41,6 +41,10 @@
impl.WriteIndices(indices);
impl.Indexed = true;
}
+ public void WriteAttributeData(string attributeName, Vector3[] data)
+ {
+ impl.WriteAttributeData(attributeName, data);
+ }
public bool Indexed
{
@@ -69,13 +73,44 @@
get { return impl.PrimitiveType; }
set { impl.PrimitiveType = value; }
}
- public Surface Texture
+ public TextureList Textures
{
- get { return impl.Texture; }
- set { impl.Texture = value; }
+ get { return impl.Textures; }
}
+
}
+ public class TextureList
+ {
+ Surface[] surfs = new Surface[4];
+
+ public Surface this[int index]
+ {
+ get { return surfs[index]; }
+ set { surfs[index] = value; }
+ }
+ public int Count
+ {
+ get { return surfs.Length; }
+ }
+ public int ActiveTextures
+ {
+ get
+ {
+ int activeCount = 0;
+ for (int i = 0; i < Count; i++)
+ {
+ if (this[i] == null)
+ continue;
+
+ activeCount++;
+ }
+
+ return activeCount;
+ }
+ }
+ }
+
public class VertexLayout : IList<VertexMember>
{
List<VertexMember> items = new List<VertexMember>();
@@ -94,19 +129,44 @@
{
return new VertexLayout
{
- new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Position),
+ new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Position),
new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Normal),
new VertexMember(VertexMemberType.Float2, VertexMemberUsage.Texture),
};
}
}
+ public static VertexLayout PositionNormalTangentBitangentTexture
+ {
+ get
+ {
+ return new VertexLayout
+ {
+ new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Position),
+ new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Normal),
+ new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Tangent),
+ new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Bitangent),
+ new VertexMember(VertexMemberType.Float2, VertexMemberUsage.Texture),
+ };
+ }
+ }
+ public VertexLayout PositionNormal
+ {
+ get
+ {
+ return new VertexLayout
+ {
+ new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Position),
+ new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Normal),
+ };
+ }
+ }
public VertexLayout PositionTexture
{
get
{
return new VertexLayout
{
- new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Position),
+ new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Position),
new VertexMember(VertexMemberType.Float2, VertexMemberUsage.Texture),
};
}
@@ -184,6 +244,15 @@
}
#endregion
+
+ public bool Contains(VertexMemberUsage vertexMemberUsage)
+ {
+ return items.Any(x => x.Usage == vertexMemberUsage);
+ }
+ public bool Contains(string attributeName)
+ {
+ return items.Any(x => x.Usage == VertexMemberUsage.Attribute && x.AttributeString == attributeName);
+ }
}
public class VertexMember
@@ -240,18 +309,18 @@
public enum VertexMemberType
{
+ Float1,
Float2,
Float3,
Float4,
- Int2,
- Int3,
- Int4,
}
public enum VertexMemberUsage
{
Position,
Normal,
+ Tangent,
+ Bitangent,
Color,
Texture,
Texture1,
Modified: branches/agate-3d/AgateLib/Geometry/Builders/Cube.cs
===================================================================
--- branches/agate-3d/AgateLib/Geometry/Builders/Cube.cs 2009-04-11 05:09:45 UTC (rev 848)
+++ branches/agate-3d/AgateLib/Geometry/Builders/Cube.cs 2009-04-12 05:06:01 UTC (rev 849)
@@ -10,17 +10,29 @@
public CubeBuilder()
{
Length = 1;
- GenerateTextureCoords = true;
- GenerateNormals = true;
-
VertexType = VertexLayout.PositionNormalTexture;
}
public float Length { get; set; }
public Vector3 Location { get; set; }
- public bool GenerateTextureCoords { get; set; }
- public bool GenerateNormals { get; set; }
+ bool GenerateTextureCoords
+ {
+ get { return VertexType.Contains(VertexMemberUsage.Texture); }
+ }
+ bool GenerateNormals
+ {
+ get { return VertexType.Contains(VertexMemberUsage.Normal); }
+ }
+ bool GenerateTangent
+ {
+ get { return VertexType.Contains(VertexMemberUsage.Tangent); }
+ }
+ bool GenerateBitangent
+ {
+ get { return VertexType.Contains(VertexMemberUsage.Bitangent); }
+ }
+
public VertexLayout VertexType { get; set; }
public VertexBuffer CreateVertexBuffer()
@@ -35,10 +47,15 @@
retval.WriteTextureCoords(GetTextureCoords());
if (GenerateNormals)
retval.WriteNormalData(GetNormals());
+ if (GenerateTangent)
+ retval.WriteAttributeData("tangent", GetTangent());
+ if (GenerateBitangent)
+ retval.WriteAttributeData("bitangent", GetBitangent());
return retval;
}
+
private short[] GetIndexData()
{
short[] retval = new short[36];
@@ -60,6 +77,59 @@
return retval;
}
+ private Vector3[] GetBitangent()
+ {
+ Vector3[] retval = new Vector3[24];
+
+ int i = 0;
+
+ for (int sign = -1; sign >= 1; sign += 2)
+ {
+ retval[i++] = new Vector3(0, sign, 0);
+ retval[i++] = new Vector3(0, sign, 0);
+ retval[i++] = new Vector3(0, sign, 0);
+ retval[i++] = new Vector3(0, sign, 0);
+
+ retval[i++] = new Vector3(sign, 0, 0);
+ retval[i++] = new Vector3(sign, 0, 0);
+ retval[i++] = new Vector3(sign, 0, 0);
+ retval[i++] = new Vector3(sign, 0, 0);
+
+ retval[i++] = new Vector3(0, 0, sign);
+ retval[i++] = new Vector3(0, 0, sign);
+ retval[i++] = new Vector3(0, 0, sign);
+ retval[i++] = new Vector3(0, 0, sign);
+ }
+
+ return retval;
+ }
+ private Vector3[] GetTangent()
+ {
+ Vector3[] retval = new Vector3[24];
+
+ int i = 0;
+
+ for (int sign = -1; sign <= 1; sign += 2)
+ {
+ retval[i++] = new Vector3(sign, 0, 0);
+ retval[i++] = new Vector3(sign, 0, 0);
+ retval[i++] = new Vector3(sign, 0, 0);
+ retval[i++] = new Vector3(sign, 0, 0);
+
+ retval[i++] = new Vector3(0, 0, sign);
+ retval[i++] = new Vector3(0, 0, sign);
+ retval[i++] = new Vector3(0, 0, sign);
+ retval[i++] = new Vector3(0, 0, sign);
+
+ retval[i++] = new Vector3(0, sign, 0);
+ retval[i++] = new Vector3(0, sign, 0);
+ retval[i++] = new Vector3(0, sign, 0);
+ retval[i++] = new Vector3(0, sign, 0);
+
+ }
+
+ return retval;
+ }
private Vector3[] GetNormals()
{
Vector3[] retval = new Vector3[24];
@@ -133,4 +203,4 @@
return retval;
}
}
-}
+}
\ No newline at end of file
Modified: branches/agate-3d/AgateLib/Geometry/Vector3.cs
===================================================================
--- branches/agate-3d/AgateLib/Geometry/Vector3.cs 2009-04-11 05:09:45 UTC (rev 848)
+++ branches/agate-3d/AgateLib/Geometry/Vector3.cs 2009-04-12 05:06:01 UTC (rev 849)
@@ -167,7 +167,27 @@
{
return new Vector3(a * b.X, a * b.Y, a * b.Z);
}
- /// <summary>
+ /// <summary>
+ /// Scales a vector by a scalar floating point value.
+ /// </summary>
+ /// <param name="a"></param>
+ /// <param name="b"></param>
+ /// <returns></returns>
+ public static Vector3 operator *(Vector3 a, double b)
+ {
+ return a * (float)b;
+ }
+ /// <summary>
+ /// Scales a vector by a scalar floating point value.
+ /// </summary>
+ /// <param name="a"></param>
+ /// <param name="b"></param>
+ /// <returns></returns>
+ public static Vector3 operator *(double a, Vector3 b)
+ {
+ return b * (float)a;
+ }
+ /// <summary>
/// Divides a vector's components by a floating point value.
/// </summary>
/// <param name="a"></param>
@@ -177,7 +197,16 @@
{
return a * (1.0f / b);
}
-
+ /// <summary>
+ /// Divides a vector's components by a floating point value.
+ /// </summary>
+ /// <param name="a"></param>
+ /// <param name="b"></param>
+ /// <returns></returns>
+ public static Vector3 operator /(Vector3 a, double b)
+ {
+ return a * (float)(1.0 / b);
+ }
/// <summary>
/// Computes and returns the dot product with another vector.
/// </summary>
@@ -226,5 +255,13 @@
return string.Format(System.Globalization.CultureInfo.CurrentCulture,
"{0}X={1},Y={2},Z={3}{4}", "{", X, Y, Z, "}");
}
- }
+
+ public static Vector3 FromPolar(int length, float theta, float phi)
+ {
+ return length * new Vector3(
+ Math.Sin(theta) * Math.Cos(phi),
+ Math.Sin(theta) * Math.Sin(phi),
+ Math.Cos(theta));
+ }
+ }
}
Modified: branches/agate-3d/AgateLib/ImplementationBase/VertexBufferImpl.cs
===================================================================
--- branches/agate-3d/AgateLib/ImplementationBase/VertexBufferImpl.cs 2009-04-11 05:09:45 UTC (rev 848)
+++ branches/agate-3d/AgateLib/ImplementationBase/VertexBufferImpl.cs 2009-04-12 05:06:01 UTC (rev 849)
@@ -8,10 +8,16 @@
{
public abstract class VertexBufferImpl
{
+ public VertexBufferImpl()
+ {
+ Textures = new TextureList();
+ }
+
public abstract void WriteVertexData(Vector3[] data);
public abstract void WriteTextureCoords(Vector2[] texCoords);
public abstract void WriteNormalData(Vector3[] data);
public abstract void WriteIndices(short[] indices);
+ public abstract void WriteAttributeData(string attributeName, Vector3[] data);
public abstract int VertexCount { get; }
public abstract int IndexCount { get; }
@@ -19,7 +25,7 @@
public virtual bool Indexed { get; set; }
public virtual PrimitiveType PrimitiveType { get; set; }
- public virtual Surface Texture { get; set; }
+ public TextureList Textures { get; set; }
public virtual void Draw()
{
Modified: branches/agate-3d/AgateLib/InputLib/Mouse.cs
===================================================================
--- branches/agate-3d/AgateLib/InputLib/Mouse.cs 2009-04-11 05:09:45 UTC (rev 848)
+++ branches/agate-3d/AgateLib/InputLib/Mouse.cs 2009-04-12 05:06:01 UTC (rev 849)
@@ -119,12 +119,19 @@
/// Gets or sets the position of the cursor, in client coordinates
/// of the current display window.
/// </summary>
- public static Point Position
- {
- get { return Display.CurrentWindow.MousePosition; }
- set { Display.CurrentWindow.MousePosition = value; }
- }
+ public static Point Position
+ {
+ get { return Display.CurrentWindow.MousePosition; }
+ set
+ {
+ // do not adjust the mouse position if we are not the active application.
+ if (Core.IsActive == false)
+ return;
+ Display.CurrentWindow.MousePosition = value;
+ }
+ }
+
/// <summary>
/// Gets or sets the X position of the cursor, in client coordinates
/// of the current display window.
Modified: branches/agate-3d/Drivers/AgateOTK/GL_Display.cs
===================================================================
--- branches/agate-3d/Drivers/AgateOTK/GL_Display.cs 2009-04-11 05:09:45 UTC (rev 848)
+++ branches/agate-3d/Drivers/AgateOTK/GL_Display.cs 2009-04-12 05:06:01 UTC (rev 849)
@@ -444,6 +444,9 @@
}
set
{
+ if (value == null)
+ return;
+
if (value is GlslShader == false)
throw new AgateLib.AgateException(string.Format(
"Shader type is {0} but must be GlslShader.", typeof(ValueType)));
Modified: branches/agate-3d/Drivers/AgateOTK/GL_Surface.cs
===================================================================
--- branches/agate-3d/Drivers/AgateOTK/GL_Surface.cs 2009-04-11 05:09:45 UTC (rev 848)
+++ branches/agate-3d/Drivers/AgateOTK/GL_Surface.cs 2009-04-12 05:06:01 UTC (rev 849)
@@ -94,7 +94,7 @@
mSourceRect = new Rectangle(Point.Empty, size);
- mTextureSize = new Size(NextPowerOfTwo(size.Width), NextPowerOfTwo(size.Height));
+ mTextureSize = GetOGLSize(size);
//int[] array = new int[1];
//GL.GenTextures(1, array);
@@ -667,7 +667,11 @@
private Size GetOGLSize(System.Drawing.Bitmap image)
{
- Size retval = Interop.Convert(image.Size);
+ return GetOGLSize(Interop.Convert(image.Size));
+ }
+ private Size GetOGLSize(Size size)
+ {
+ Size retval = size;
if (mDisplay.NonPowerOf2Textures)
return retval;
Modified: branches/agate-3d/Drivers/AgateOTK/GL_VertexBuffer.cs
===================================================================
--- branches/agate-3d/Drivers/AgateOTK/GL_VertexBuffer.cs 2009-04-11 05:09:45 UTC (rev 848)
+++ branches/agate-3d/Drivers/AgateOTK/GL_VertexBuffer.cs 2009-04-12 05:06:01 UTC (rev 849)
@@ -14,14 +14,22 @@
{
GL_Display mDisplay;
GLState mState;
- GL_Surface mTexture;
+ struct AttributeData
+ {
+ public string Name;
+ public int BufferID;
+ public VertexAttribPointerType Type;
+ public int ComponentCount;
+ }
+
int mVertexCount, mIndexCount;
int mVertexBufferID;
int mIndexBufferID;
int mTexCoordBufferID;
int mNormalBufferID;
-
+ List<AttributeData> mAttributeBuffers = new List<AttributeData>();
+
VertexLayout layout;
public GL_VertexBuffer(VertexLayout layout)
@@ -31,17 +39,7 @@
this.layout = layout;
}
- public override Surface Texture
- {
- get { return base.Texture; }
- set
- {
- base.Texture = value;
- mTexture = (GL_Surface)value.Impl;
- }
- }
// FYI: use BufferTarget.ElementArrayBuffer to bind to an index buffer.
-
private int CreateBuffer(Vector3[] data)
{
int bufferID;
@@ -123,7 +121,16 @@
mIndexBufferID = CreateIndexBuffer(indices);
mIndexCount = indices.Length;
}
+ public override void WriteAttributeData(string attributeName, Vector3[] data)
+ {
+ AttributeData d = new AttributeData { Name = attributeName };
+ d.BufferID = CreateBuffer(data);
+ d.Type = VertexAttribPointerType.Float;
+ d.ComponentCount = 3;
+
+ mAttributeBuffers.Add(d);
+ }
public override void Draw(int start, int count)
{
SetClientStates();
@@ -146,30 +153,46 @@
GL.BindBuffer(BufferTarget.ArrayBuffer, mVertexBufferID);
GL.VertexPointer(3, VertexPointerType.Float, 0, (IntPtr)start);
- GL.DrawArrays(beginMode, 0, count);
+ GL.DrawArrays(beginMode, start, count);
}
}
+
+ private void SetAttributes()
+ {
+ GlslShader shader = Display.Shader as GlslShader;
+ if (shader == null)
+ return;
+ for (int i = 0; i < mAttributeBuffers.Count; i++)
+ {
+ if (shader.Attributes.Contains(mAttributeBuffers[i].Name) == false)
+ continue;
+
+ int size = mAttributeBuffers[i].ComponentCount;
+ int shaderAttribIndex = shader.GetAttribLocation(mAttributeBuffers[i].Name);
+
+ GL.EnableVertexAttribArray(shaderAttribIndex);
+ GL.BindBuffer(BufferTarget.ArrayBuffer, mAttributeBuffers[i].BufferID);
+ GL.VertexAttribPointer(shaderAttribIndex, size,
+ mAttributeBuffers[i].Type,
+ false, 0, IntPtr.Zero);
+ }
+ }
+
private void SetClientStates()
{
mState.SetGLColor(Color.White);
-
if (UseTexture)
- {
- GL.Enable(EnableCap.Texture2D);
- GL.EnableClientState(EnableCap.TextureCoordArray);
- GL.BindBuffer(BufferTarget.ArrayBuffer, mTexCoordBufferID);
- GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, IntPtr.Zero);
- GL.BindTexture(TextureTarget.Texture2D, mTexture.GLTextureID);
- }
+ SetTextures();
else
{
GL.Disable(EnableCap.Texture2D);
GL.DisableClientState(EnableCap.TextureCoordArray);
GL.BindTexture(TextureTarget.Texture2D, 0);
}
+
if (HasNormals)
{
GL.EnableClientState(EnableCap.NormalArray);
@@ -180,8 +203,55 @@
{
GL.DisableClientState(EnableCap.NormalArray);
}
+
+ SetAttributes();
}
+ private void SetTextures()
+ {
+ GL.Enable(EnableCap.Texture2D);
+ GL.EnableClientState(EnableCap.TextureCoordArray);
+ GL.BindBuffer(BufferTarget.ArrayBuffer, mTexCoordBufferID);
+ GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, IntPtr.Zero);
+
+ GlslShader shader = Display.Shader as GlslShader;
+
+ if (Textures.ActiveTextures > 1)
+ {
+ for (int i = 0; i < Textures.Count; i++)
+ {
+ GL.ActiveTexture((TextureUnit)(TextureUnit.Texture0 + i));
+
+ Surface surf = Textures[i];
+
+ if (surf != null)
+ {
+ GL_Surface gl_surf = (GL_Surface)Textures[i].Impl;
+
+ GL.Enable(EnableCap.Texture2D);
+ GL.BindTexture(TextureTarget.Texture2D, gl_surf.GLTextureID);
+
+ if (shader != null)
+ {
+ if (i < shader.Sampler2DUniforms.Count)
+ {
+ shader.SetUniform(shader.Sampler2DUniforms[i], i);
+ }
+ }
+ }
+ else
+ {
+ GL.Disable(EnableCap.Texture2D);
+ GL.BindTexture(TextureTarget.Texture2D, 0);
+ }
+ }
+ }
+ else
+ {
+ GL.BindTexture(TextureTarget.Texture2D, ((GL_Surface)Textures[0].Impl).GLTextureID);
+ }
+ }
+
private BeginMode SelectBeginMode()
{
BeginMode beginMode;
@@ -217,7 +287,7 @@
bool UseTexture
{
- get { return HasTextureCoords && mTexture != null; }
+ get { return HasTextureCoords && Textures.ActiveTextures != 0; }
}
public bool HasTextureCoords
{
Modified: branches/agate-3d/Drivers/AgateOTK/GlslShader.cs
===================================================================
--- branches/agate-3d/Drivers/AgateOTK/GlslShader.cs 2009-04-11 05:09:45 UTC (rev 848)
+++ branches/agate-3d/Drivers/AgateOTK/GlslShader.cs 2009-04-12 05:06:01 UTC (rev 849)
@@ -21,17 +21,77 @@
return "Uniform: " + Name + " | " + Type.ToString();
}
}
+ struct AttributeInfo
+ {
+ public string Name;
+ public int Location;
+ public ActiveAttribType Type;
+ public int Size;
- Dictionary<string, UniformInfo> mUniforms = new Dictionary<string, UniformInfo>();
+ public override string ToString()
+ {
+ return "Uniform: " + Name + " | " + Type.ToString();
+ }
+ }
+
+ List<UniformInfo> mUniforms = new List<UniformInfo>();
+ List<AttributeInfo> mAttributes = new List<AttributeInfo>();
+ List<string> mAttributeNames;
+
+ List<string> mSampler2DUniforms = new List<string>();
int programHandle;
+ GlslVertexProgram vertex;
+ GlslFragmentProgram pixel;
+
public GlslShader(int handle, GlslVertexProgram vert, GlslFragmentProgram frag)
{
programHandle = handle;
this.vertex = vert;
this.pixel = frag;
+ LoadUniforms();
+ LoadAttributes();
+ }
+
+ private void LoadAttributes()
+ {
int count;
+ GL.GetProgram(programHandle, ProgramParameter.ActiveAttributes, out count);
+
+ StringBuilder b = new StringBuilder(1000);
+ for (int i = 0; i < count; i++)
+ {
+ int length;
+ int size;
+ ActiveAttribType type;
+ string name;
+ GL.GetActiveAttrib(programHandle, i, 1000, out length, out size, out type, b);
+ name = b.ToString();
+
+ int loc = GL.GetAttribLocation(programHandle, name);
+
+ // ignore active attributes that we aren't interested in because we don't set them
+ // with glVertexAttribPointer
+ if (loc == -1)
+ continue;
+
+ AttributeInfo info = new AttributeInfo();
+
+ info.Name = name;
+ info.Location = loc;
+ info.Type = type;
+ info.Size = size;
+
+ mAttributes.Add(info);
+ }
+
+ mAttributeNames = mAttributes.Select(x => x.Name).ToList();
+ }
+
+ private void LoadUniforms()
+ {
+ int count;
GL.GetProgram(programHandle, ProgramParameter.ActiveUniforms, out count);
StringBuilder b = new StringBuilder(1000);
@@ -58,13 +118,28 @@
info.Type = type;
info.Size = size;
- mUniforms.Add(info.Name, info);
+ mUniforms.Add(info);
}
+
+ mSampler2DUniforms = mUniforms
+ .Where(x => x.Type == ActiveUniformType.Sampler2D)
+ .Select(x => x.Name)
+ .ToList();
}
- GlslVertexProgram vertex;
- GlslFragmentProgram pixel;
+ public IList<string> Attributes
+ {
+ get { return mAttributeNames; }
+ }
+ public IList<string> Sampler2DUniforms
+ {
+ get
+ {
+ return mSampler2DUniforms;
+ }
+ }
+
public override PixelShader PixelShader
{
get { return pixel; }
@@ -81,19 +156,29 @@
private int GetUniformLocation(string name)
{
- if (mUniforms.ContainsKey(name))
- return mUniforms[name].Location;
+ if (mUniforms.Any(x => x.Name == name))
+ return mUniforms.First(x => x.Name == name).Location;
int loc = GL.GetUniformLocation(programHandle, name);
if (loc != -1)
- {
return loc;
- }
else
throw new AgateLib.AgateException("Could not find uniform {0} in the GLSL program.", name);
}
+ internal int GetAttribLocation(string name)
+ {
+ if (mAttributes.Any(x => x.Name == name))
+ return mAttributes.First(x => x.Name == name).Location;
+ int loc = GL.GetAttribLocation(programHandle, name);
+
+ if (loc != -1)
+ return loc;
+ else
+ throw new AgateLib.AgateException("Could not find uniform {0} in the GLSL program.", name);
+ }
+
public override void SetUniform(string name, params float[] v)
{
int loc = GetUniformLocation(name);
@@ -158,5 +243,6 @@
GL.UniformMatrix4(loc, 16, true, (float*)&matrix);
}
}
+
}
}
Modified: branches/agate-3d/Drivers/AgateOTK/GlslShaderCompiler.cs
===================================================================
--- branches/agate-3d/Drivers/AgateOTK/GlslShaderCompiler.cs 2009-04-11 05:09:45 UTC (rev 848)
+++ branches/agate-3d/Drivers/AgateOTK/GlslShaderCompiler.cs 2009-04-12 05:06:01 UTC (rev 849)
@@ -55,13 +55,13 @@
GL.ValidateProgram(program);
- int status;
- GL.GetProgram(program, ProgramParameter.ValidateStatus, out status);
+ //int status;
+ //GL.GetProgram(program, ProgramParameter.ValidateStatus, out status);
- if (status == 0)
- {
- throw new AgateLib.AgateException("Failed to validate GLSL shader program.");
- }
+ //if (status == 0)
+ //{
+ // throw new AgateLib.AgateException("Failed to validate GLSL shader program.");
+ //}
return new GlslShader(program, vert, frag);
}
Modified: branches/agate-3d/Drivers/AgateOTK/OpenTK.Utilities.dll
===================================================================
(Binary files differ)
Modified: branches/agate-3d/Drivers/AgateOTK/OpenTK.dll
===================================================================
(Binary files differ)
Modified: branches/agate-3d/Tests/Display3D/Glsl/Glsl.cs
===================================================================
--- branches/agate-3d/Tests/Display3D/Glsl/Glsl.cs 2009-04-11 05:09:45 UTC (rev 848)
+++ branches/agate-3d/Tests/Display3D/Glsl/Glsl.cs 2009-04-12 05:06:01 UTC (rev 849)
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Linq;
using System.Text;
using AgateLib;
@@ -21,8 +22,28 @@
{
new Glsl().Run(args);
}
- bool rotating = true;
+ bool rotating = false;
+ const float velocity = 0.04f;
+ const float mousevelocity = 0.004f;
+ float theta = (float)Math.PI / 2;
+ float phi = (float)-Math.PI / 2;
+ Vector3 eye = new Vector3(0, 70, 20);
+ Vector3 up = new Vector3(0, 0, 1);
+ DisplayWindow wind;
+
+ Vector3 lookDir
+ {
+ get { return Vector3.FromPolar(1, theta, phi); }
+ }
+ Vector2 centerPoint
+ {
+ get { return new Vector2(wind.Width / 2, wind.Height / 2); }
+ }
+ void resetmouse()
+ {
+ Mouse.Position = new Point(wind.Width / 2, wind.Height/ 2);
+ }
private void Run(string[] args)
{
// These two lines are used by AgateLib tests to locate
@@ -32,78 +53,114 @@
using (AgateSetup setup = new AgateSetup(args))
{
- setup.AskUser = true;
setup.Initialize(true, false, false);
if (setup.WasCanceled)
return;
- DisplayWindow wind = new DisplayWindow(CreateWindowParams.Windowed("GLSL", 800, 600, null, true));
+ wind = new DisplayWindow(CreateWindowParams.Windowed("GLSL", 800, 600, null, true));
Mouse.MouseDown += new InputEventHandler(Mouse_MouseDown);
- Vector3 eye = new Vector3(0, 40, 40);
- Vector3 target = new Vector3(0, 0, 0);
- Vector3 up = new Vector3(0, 0, 1);
+ FontSurface font = new FontSurface("Arial", 14.0f);
+
Surface texture = new Surface("bg-bricks.png");
Surface height = new Surface("bg-bricks-heightmap.png");
+ //Surface height = new Surface("jellybean.png");
LightManager m = new LightManager();
- m.AddPointLight(new Vector3(75, 25, 75), Color.White);
+ m.AddPointLight(new Vector3(0, 0, 0), Color.White);
m.Enabled = true;
+ m.Ambient = Color.FromArgb(0, 255, 0);
m[0].AttenuationConstant = 0.0001f;
- m[0].AttenuationLinear = 0.01f;
- m[0].AttenuationQuadratic = 0f;
+ m[0].AttenuationLinear = 0.004f;
+ m[0].AttenuationQuadratic = 0.00006f;
m[0].Range = 200;
double time = 0;
double frequency = 2 * Math.PI / 5;
- const float size = 50;
+ const float size = 25;
//HeightMapTerrain b = new HeightMapTerrain(height.ReadPixels());
//b.Width = size;
//b.Height = size;
//b.MaxPeak = 1;
CubeBuilder b = new CubeBuilder();
+ b.VertexType = VertexLayout.PositionNormalTangentBitangentTexture;
b.Length = size;
VertexBuffer buffer = b.CreateVertexBuffer();
- buffer.Texture = texture;
+ buffer.Textures[0] = texture;
+ buffer.Textures[1] = new Surface(PixelBuffer.NormalMapFromHeightMap(height.ReadPixels()));
+ buffer.Textures[1].SaveTo("normal.png");
+ //var shader = ShaderCompiler.CompileShader(ShaderLanguage.Glsl,
+ // Shaders.PerPixelLighting_vertex, Shaders.PerPixelLighting_fragment);
var shader = ShaderCompiler.CompileShader(ShaderLanguage.Glsl,
- "void main() { gl_Position = ftransform(); } ",
- "uniform vec4 my_color; void main() { gl_FragColor = my_color; }");
+ Shaders.BumpMap_vertex, Shaders.BumpMap_fragment);
+ //var shader = ShaderCompiler.CompileShader(ShaderLanguage.Glsl,
+ // Shaders.BumpMap_vertex, Shaders.PerPixelLighting_fragment);
+ resetmouse();
+ Mouse.Hide();
while (wind.IsClosed == false)
{
+ if (Core.IsActive)
+ {
+ Vector3 move = lookDir * velocity * Display.DeltaTime;
+ Vector3 strafe = Vector3.CrossProduct(move, up).Normalize()*velocity * Display.DeltaTime;
+ Vector3 fly = new Vector3(0, 0, velocity * Display.DeltaTime);
+
+ if (Keyboard.Keys[KeyCode.W]) eye += move;
+ else if (Keyboard.Keys[KeyCode.S]) eye -= move;
+
+ if (Keyboard.Keys[KeyCode.A]) eye -= strafe;
+ else if (Keyboard.Keys[KeyCode.D]) eye += strafe;
+
+ if (Keyboard.Keys[KeyCode.Q]) eye += fly;
+ else if (Keyboard.Keys[KeyCode.E]) eye -= fly;
+
+ if (Keyboard.Keys[KeyCode.Escape])
+ return;
+
+ Vector2 mouseDiff = new Vector2(Mouse.X, Mouse.Y) - centerPoint;
+
+ theta += mouseDiff.Y * mousevelocity;
+ phi -= mouseDiff.X * mousevelocity;
+ resetmouse();
+
+ if (phi < -Math.PI) phi += (float)(Math.PI * 2);
+ if (phi > Math.PI) phi -= (float)(Math.PI * 2);
+ if (theta < 0) theta = 0;
+ if (theta > Math.PI) theta = (float)Math.PI;
+ }
+
if (rotating)
{
time += Display.DeltaTime / 1000.0;
}
Display.BeginFrame();
- Display.Clear(Color.Blue);
+ Display.Clear(Color.Gray);
Display.Shader = shader;
- if (rotating)
- {
- shader.SetUniform("my_color", Color.Red);
- }
- else
- {
- shader.SetUniform("my_color", Color.Green);
- }
- Display.MatrixProjection = Matrix4.Projection(45f, 800 / 600.0f, 1.0f, 1000f);
- Display.MatrixView = Matrix4.LookAt(eye, target, up);
+ Display.MatrixProjection = Matrix4.Projection(45f, wind.Width / (float)wind.Height, 1.0f, 1000f);
Display.MatrixWorld = Matrix4.Identity;
+ Display.MatrixView = Matrix4.Identity;
- Display.MatrixWorld = Matrix4.Translation(-size / 2, -size / 2, 0);
+ Display.MatrixView = Matrix4.LookAt(eye, eye + lookDir, up);
+
+ m[0].Position = eye;
m.DoLighting();
- Display.MatrixWorld = Matrix4.RotateZ((float)(frequency * time)) * Matrix4.Translation(-size / 2, -size / 2, 0);
+ Display.MatrixWorld = Matrix4.RotateZ((float)(frequency * time))
+ * Matrix4.Translation(-size / 2, -size / 2, 0);
buffer.Draw();
+ Debug.Print("x, y, z = {0}", eye.ToString());
+ Debug.Print("angle = {0}", phi * 180/Math.PI);
+
Display.EndFrame();
Core.KeepAlive();
}
Modified: branches/agate-3d/Tests/Display3D/Test3D/Test3d.cs
===================================================================
--- branches/agate-3d/Tests/Display3D/Test3D/Test3d.cs 2009-04-11 05:09:45 UTC (rev 848)
+++ branches/agate-3d/Tests/Display3D/Test3D/Test3d.cs 2009-04-12 05:06:01 UTC (rev 849)
@@ -44,11 +44,10 @@
Surface surf = new Surface("bg-bricks.png");
CubeBuilder cube = new CubeBuilder();
- cube.GenerateTextureCoords = true;
cube.Length = 4;
VertexBuffer b = cube.CreateVertexBuffer();
- b.Texture = surf;
+ b.Textures[0] = surf;
int lastMyMatrix = matrixIndex-1;
Matrix4 myproj = new Matrix4();
Modified: branches/agate-3d/Tests/Display3D/TestMatrices/Matrices.cs
===================================================================
--- branches/agate-3d/Tests/Display3D/TestMatrices/Matrices.cs 2009-04-11 05:09:45 UTC (rev 848)
+++ branches/agate-3d/Tests/Display3D/TestMatrices/Matrices.cs 2009-04-12 05:06:01 UTC (rev 849)
@@ -45,12 +45,11 @@
Surface surf = new Surface("bg-bricks.png");
CubeBuilder cube = new CubeBuilder();
- cube.GenerateTextureCoords = true;
cube.Length = 58;
cube.Location = new Vector3(cube.Length / 2, cube.Length / 2, 0);
VertexBuffer b = cube.CreateVertexBuffer();
- b.Texture = surf;
+ b.Textures[0] = surf;
int lastMyMatrix = matrixIndex - 1;
Matrix4 myproj = new Matrix4();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-04-11 05:09:49
|
Revision: 848
http://agate.svn.sourceforge.net/agate/?rev=848&view=rev
Author: kanato
Date: 2009-04-11 05:09:45 +0000 (Sat, 11 Apr 2009)
Log Message:
-----------
Add vertex definition classes. Remove DrawIndexed method.
Modified Paths:
--------------
branches/agate-3d/AgateLib/DisplayLib/VertexBuffer.cs
branches/agate-3d/AgateLib/Geometry/Builders/Cube.cs
branches/agate-3d/AgateLib/Geometry/Builders/Terrain.cs
branches/agate-3d/AgateLib/ImplementationBase/DisplayImpl.cs
branches/agate-3d/AgateLib/ImplementationBase/VertexBufferImpl.cs
branches/agate-3d/Drivers/AgateOTK/GL_Display.cs
branches/agate-3d/Drivers/AgateOTK/GL_VertexBuffer.cs
branches/agate-3d/Tests/Display3D/Glsl/Glsl.cs
branches/agate-3d/Tests/Display3D/Test3D/Test3d.cs
branches/agate-3d/Tests/Display3D/TestMatrices/Matrices.cs
Modified: branches/agate-3d/AgateLib/DisplayLib/VertexBuffer.cs
===================================================================
--- branches/agate-3d/AgateLib/DisplayLib/VertexBuffer.cs 2009-04-11 03:25:58 UTC (rev 847)
+++ branches/agate-3d/AgateLib/DisplayLib/VertexBuffer.cs 2009-04-11 05:09:45 UTC (rev 848)
@@ -1,74 +1,262 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Text;
using AgateLib.ImplementationBase;
using AgateLib.Geometry;
namespace AgateLib.DisplayLib
{
- public sealed class VertexBuffer
- {
- VertexBufferImpl impl;
+ public sealed class VertexBuffer
+ {
+ VertexBufferImpl impl;
- public VertexBuffer()
- {
- impl = Display.Impl.CreateVertexBuffer();
- }
+ public VertexBuffer(VertexLayout layout, int vertexCount)
+ {
+ if (layout == null)
+ throw new ArgumentNullException(
+ "The supplied VertexLayout must not be null. " +
+ "You may wish to use one of the static members of VertexLayout.");
+ if (layout.Count == 0)
+ throw new ArgumentException(
+ "The supplied VertexLayout has no items in it. You must supply a valid layout.");
- public void WriteVertexData(Vector3[] data)
- {
- impl.WriteVertexData(data);
- }
- public void WriteTextureCoords(Vector2[] texCoords)
- {
- impl.WriteTextureCoords(texCoords);
- }
- public void WriteNormalData(Vector3[] data)
- {
- impl.WriteNormalData(data);
- }
- public void WriteIndices(short[] indices)
- {
- impl.WriteIndices(indices);
- }
+ impl = Display.Impl.CreateVertexBuffer(layout, vertexCount);
+ }
- public void Draw()
- {
- impl.Draw();
- }
- public void Draw(int vertexStart, int vertexCount)
- {
- impl.Draw(vertexStart, vertexCount);
- }
- public void DrawIndexed()
- {
- impl.DrawIndexed();
- }
- public void DrawIndexed(int indexStart, int indexCount)
- {
- impl.DrawIndexed(indexStart, indexCount);
- }
+ public void WriteVertexData(Vector3[] data)
+ {
+ impl.WriteVertexData(data);
+ }
+ public void WriteTextureCoords(Vector2[] texCoords)
+ {
+ impl.WriteTextureCoords(texCoords);
+ }
+ public void WriteNormalData(Vector3[] data)
+ {
+ impl.WriteNormalData(data);
+ }
+ public void WriteIndices(short[] indices)
+ {
+ impl.WriteIndices(indices);
+ impl.Indexed = true;
+ }
- public int VertexCount
- {
- get { return impl.VertexCount; }
- }
- public int IndexCount
- {
- get { return impl.IndexCount; }
- }
- public PrimitiveType PrimitiveType
- {
- get { return impl.PrimitiveType; }
- set { impl.PrimitiveType = value; }
- }
- public Surface Texture
- {
- get { return impl.Texture; }
- set { impl.Texture = value; }
- }
+ public bool Indexed
+ {
+ get { return impl.Indexed; }
+ set { impl.Indexed = value; }
+ }
+ public void Draw()
+ {
+ impl.Draw();
+ }
+ public void Draw(int start, int count)
+ {
+ impl.Draw(start, count);
+ }
+ public int VertexCount
+ {
+ get { return impl.VertexCount; }
+ }
+ public int IndexCount
+ {
+ get { return impl.IndexCount; }
+ }
+ public PrimitiveType PrimitiveType
+ {
+ get { return impl.PrimitiveType; }
+ set { impl.PrimitiveType = value; }
+ }
+ public Surface Texture
+ {
+ get { return impl.Texture; }
+ set { impl.Texture = value; }
+ }
+ }
+ public class VertexLayout : IList<VertexMember>
+ {
+ List<VertexMember> items = new List<VertexMember>();
- }
+ int VertexSize
+ {
+ get
+ {
+ return this.Sum(x => x.ItemSize);
+ }
+ }
+
+ public static VertexLayout PositionNormalTexture
+ {
+ get
+ {
+ return new VertexLayout
+ {
+ new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Position),
+ new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Normal),
+ new VertexMember(VertexMemberType.Float2, VertexMemberUsage.Texture),
+ };
+ }
+ }
+ public VertexLayout PositionTexture
+ {
+ get
+ {
+ return new VertexLayout
+ {
+ new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Position),
+ new VertexMember(VertexMemberType.Float2, VertexMemberUsage.Texture),
+ };
+ }
+ }
+
+ #region --- IList<VertexMember> Members ---
+
+ int IList<VertexMember>.IndexOf(VertexMember item)
+ {
+ return items.IndexOf(item);
+ }
+ void IList<VertexMember>.Insert(int index, VertexMember item)
+ {
+ items.Insert(index, item);
+ }
+ public void RemoveAt(int index)
+ {
+ items.RemoveAt(index);
+ }
+ public VertexMember this[int index]
+ {
+ get { return items[index]; }
+ set { items[index] = value; }
+ }
+
+ #endregion
+ #region --- ICollection<VertexMember> Members ---
+
+ public void Add(VertexMember item)
+ {
+ items.Add(item);
+ }
+ public void Clear()
+ {
+ items.Clear();
+ }
+ bool ICollection<VertexMember>.Contains(VertexMember item)
+ {
+ return items.Contains(item);
+ }
+ public void CopyTo(VertexMember[] array, int arrayIndex)
+ {
+ items.CopyTo(array, arrayIndex);
+ }
+
+ public int Count
+ {
+ get { return items.Count; }
+ }
+
+ bool ICollection<VertexMember>.IsReadOnly
+ {
+ get { return false; }
+ }
+
+ bool ICollection<VertexMember>.Remove(VertexMember item)
+ {
+ return items.Remove(item);
+ }
+
+ #endregion
+ #region --- IEnumerable<VertexMember> Members ---
+
+ IEnumerator<VertexMember> IEnumerable<VertexMember>.GetEnumerator()
+ {
+ return items.GetEnumerator();
+ }
+
+ #endregion
+ #region --- IEnumerable Members ---
+
+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
+ {
+ return items.GetEnumerator();
+ }
+
+ #endregion
+ }
+
+ public class VertexMember
+ {
+ VertexMemberUsage mDef;
+ string mAttributeString;
+
+ public VertexMember(VertexMemberType type, VertexMemberUsage def)
+ {
+ if (def == VertexMemberUsage.Attribute)
+ throw new AgateException("Use the (VertexMemberType, string) overload instead.");
+
+ MemberType = type;
+ Usage = def;
+ }
+
+ public VertexMember(VertexMemberType type, string attributeName)
+ {
+ MemberType = type;
+ Usage = VertexMemberUsage.Attribute;
+ AttributeString = attributeName;
+ }
+
+ public VertexMemberType MemberType { get; private set; }
+ public VertexMemberUsage Usage
+ {
+ get { return mDef; }
+ private set
+ {
+ mDef = value;
+
+ if (mDef != VertexMemberUsage.Attribute)
+ mAttributeString = null;
+ }
+ }
+ public string AttributeString
+ {
+ get { return mAttributeString; }
+ private set
+ {
+ mAttributeString = value;
+ mDef = VertexMemberUsage.Attribute;
+ }
+ }
+
+ public int ItemSize
+ {
+ get
+ {
+ return 1;
+ }
+ }
+ }
+
+ public enum VertexMemberType
+ {
+ Float2,
+ Float3,
+ Float4,
+ Int2,
+ Int3,
+ Int4,
+ }
+
+ public enum VertexMemberUsage
+ {
+ Position,
+ Normal,
+ Color,
+ Texture,
+ Texture1,
+ Texture2,
+ Texture3,
+ Attribute,
+ }
}
Modified: branches/agate-3d/AgateLib/Geometry/Builders/Cube.cs
===================================================================
--- branches/agate-3d/AgateLib/Geometry/Builders/Cube.cs 2009-04-11 03:25:58 UTC (rev 847)
+++ branches/agate-3d/AgateLib/Geometry/Builders/Cube.cs 2009-04-11 05:09:45 UTC (rev 848)
@@ -5,128 +5,132 @@
namespace AgateLib.Geometry.Builders
{
- public class CubeBuilder
- {
- public CubeBuilder()
- {
- Length = 1;
- GenerateTextureCoords = true;
- GenerateNormals = true;
- }
+ public class CubeBuilder
+ {
+ public CubeBuilder()
+ {
+ Length = 1;
+ GenerateTextureCoords = true;
+ GenerateNormals = true;
- public float Length { get; set; }
- public Vector3 Location { get; set; }
- public bool GenerateTextureCoords { get; set; }
- public bool GenerateNormals { get; set; }
+ VertexType = VertexLayout.PositionNormalTexture;
+ }
- public VertexBuffer CreateVertexBuffer()
- {
- VertexBuffer retval = new VertexBuffer();
+ public float Length { get; set; }
+ public Vector3 Location { get; set; }
+ public bool GenerateTextureCoords { get; set; }
+ public bool GenerateNormals { get; set; }
- retval.PrimitiveType = PrimitiveType.TriangleList;
- retval.WriteVertexData(GetVertexData());
- retval.WriteIndices(GetIndexData());
+ public VertexLayout VertexType { get; set; }
- if (GenerateTextureCoords)
- retval.WriteTextureCoords(GetTextureCoords());
- if (GenerateNormals)
- retval.WriteNormalData(GetNormals());
+ public VertexBuffer CreateVertexBuffer()
+ {
+ VertexBuffer retval = new VertexBuffer(VertexType, 24);
- return retval;
- }
+ retval.PrimitiveType = PrimitiveType.TriangleList;
+ retval.WriteVertexData(GetVertexData());
+ retval.WriteIndices(GetIndexData());
- private short[] GetIndexData()
- {
- short[] retval = new short[36];
+ if (GenerateTextureCoords)
+ retval.WriteTextureCoords(GetTextureCoords());
+ if (GenerateNormals)
+ retval.WriteNormalData(GetNormals());
- int i = 0;
- short index = 0;
- for (int face = 0; face < 6; face++)
- {
- retval[i++] = index;
- retval[i++] = (short)(index + 1);
- retval[i++] = (short)(index + 2);
- retval[i++] = (short)(index + 1);
- retval[i++] = (short)(index + 2);
- retval[i++] = (short)(index + 3);
+ return retval;
+ }
- index += 4;
- }
+ private short[] GetIndexData()
+ {
+ short[] retval = new short[36];
- return retval;
- }
+ int i = 0;
+ short index = 0;
+ for (int face = 0; face < 6; face++)
+ {
+ retval[i++] = index;
+ retval[i++] = (short)(index + 1);
+ retval[i++] = (short)(index + 2);
+ retval[i++] = (short)(index + 1);
+ retval[i++] = (short)(index + 2);
+ retval[i++] = (short)(index + 3);
- private Vector3[] GetNormals()
- {
- Vector3[] retval = new Vector3[24];
+ index += 4;
+ }
- int i = 0;
- float length = Length / 2.0f;
+ return retval;
+ }
- for (int sign = -1; sign <= 1; sign += 2)
- {
- retval[i++] = new Vector3(0, 0, sign );
- retval[i++] = new Vector3(0, 0, sign );
- retval[i++] = new Vector3(0, 0, sign );
- retval[i++] = new Vector3(0, 0, sign );
+ private Vector3[] GetNormals()
+ {
+ Vector3[] retval = new Vector3[24];
- retval[i++] = new Vector3(0, sign,0);
- retval[i++] = new Vector3(0, sign,0);
- retval[i++] = new Vector3(0, sign, 0);
- retval[i++] = new Vector3(0, sign, 0);
+ int i = 0;
+ float length = Length / 2.0f;
- retval[i++] = new Vector3(sign, 0, 0);
- retval[i++] = new Vector3(sign, 0, 0);
- retval[i++] = new Vector3(sign, 0, 0);
- retval[i++] = new Vector3(sign, 0, 0);
- }
+ for (int sign = -1; sign <= 1; sign += 2)
+ {
+ retval[i++] = new Vector3(0, 0, sign);
+ retval[i++] = new Vector3(0, 0, sign);
+ retval[i++] = new Vector3(0, 0, sign);
+ retval[i++] = new Vector3(0, 0, sign);
- return retval;
- }
- protected virtual Vector3[] GetVertexData()
- {
- Vector3[] retval = new Vector3[24];
+ retval[i++] = new Vector3(0, sign, 0);
+ retval[i++] = new Vector3(0, sign, 0);
+ retval[i++] = new Vector3(0, sign, 0);
+ retval[i++] = new Vector3(0, sign, 0);
- int i = 0;
- float length = Length / 2.0f;
+ retval[i++] = new Vector3(sign, 0, 0);
+ retval[i++] = new Vector3(sign, 0, 0);
+ retval[i++] = new Vector3(sign, 0, 0);
+ retval[i++] = new Vector3(sign, 0, 0);
+ }
- for (int sign = -1; sign <= 1; sign += 2)
- {
- retval[i++] = new Vector3(length, length, sign*length);
- retval[i++] = new Vector3(length, -length, sign * length);
- retval[i++] = new Vector3(-length, length, sign * length);
- retval[i++] = new Vector3(-length, -length, sign * length);
+ return retval;
+ }
+ protected virtual Vector3[] GetVertexData()
+ {
+ Vector3[] retval = new Vector3[24];
- retval[i++] = new Vector3(length, sign * length, length);
- retval[i++] = new Vector3(length, sign * length, -length);
- retval[i++] = new Vector3(-length, sign * length, length);
- retval[i++] = new Vector3(-length, sign * length, -length);
+ int i = 0;
+ float length = Length / 2.0f;
- retval[i++] = new Vector3(sign * length, length, length);
- retval[i++] = new Vector3(sign * length, length, -length);
- retval[i++] = new Vector3(sign * length, -length, length);
- retval[i++] = new Vector3(sign * length, -length, -length);
- }
+ for (int sign = -1; sign <= 1; sign += 2)
+ {
+ retval[i++] = new Vector3(length, length, sign * length);
+ retval[i++] = new Vector3(length, -length, sign * length);
+ retval[i++] = new Vector3(-length, length, sign * length);
+ retval[i++] = new Vector3(-length, -length, sign * length);
- for (i = 0; i < retval.Length; i++)
- retval[i] += Location;
+ retval[i++] = new Vector3(length, sign * length, length);
+ retval[i++] = new Vector3(length, sign * length, -length);
+ retval[i++] = new Vector3(-length, sign * length, length);
+ retval[i++] = new Vector3(-length, sign * length, -length);
- return retval;
- }
- protected virtual Vector2[] GetTextureCoords()
- {
- Vector2[] retval = new Vector2[24];
-
- int i = 0;
- for (int face = 0; face < 6; face++)
- {
- retval[i++] = new Vector2(0, 0);
- retval[i++] = new Vector2(0, 1);
- retval[i++] = new Vector2(1, 0);
- retval[i++] = new Vector2(1, 1);
- }
+ retval[i++] = new Vector3(sign * length, length, length);
+ retval[i++] = new Vector3(sign * length, length, -length);
+ retval[i++] = new Vector3(sign * length, -length, length);
+ retval[i++] = new Vector3(sign * length, -length, -length);
+ }
- return retval;
- }
- }
+ for (i = 0; i < retval.Length; i++)
+ retval[i] += Location;
+
+ return retval;
+ }
+ protected virtual Vector2[] GetTextureCoords()
+ {
+ Vector2[] retval = new Vector2[24];
+
+ int i = 0;
+ for (int face = 0; face < 6; face++)
+ {
+ retval[i++] = new Vector2(0, 0);
+ retval[i++] = new Vector2(0, 1);
+ retval[i++] = new Vector2(1, 0);
+ retval[i++] = new Vector2(1, 1);
+ }
+
+ return retval;
+ }
+ }
}
Modified: branches/agate-3d/AgateLib/Geometry/Builders/Terrain.cs
===================================================================
--- branches/agate-3d/AgateLib/Geometry/Builders/Terrain.cs 2009-04-11 03:25:58 UTC (rev 847)
+++ branches/agate-3d/AgateLib/Geometry/Builders/Terrain.cs 2009-04-11 05:09:45 UTC (rev 848)
@@ -16,6 +16,8 @@
Width = 1;
Height = 1;
MaxPeak = 1;
+
+ VertexType = VertexLayout.PositionNormalTexture;
}
/// <summary>
@@ -44,6 +46,8 @@
/// </summary>
public float MaxPeak { get; set; }
+ public VertexLayout VertexType { get; set; }
+
public VertexBuffer CreateVertexBuffer()
{
Vector3[] vertices = new Vector3[pixels.Width* pixels.Height];
@@ -54,7 +58,7 @@
FillVertices(vertices, normal, texture, indices);
- VertexBuffer retval = new VertexBuffer();
+ VertexBuffer retval = new VertexBuffer(VertexType, vertices.Length);
retval.WriteVertexData(vertices);
retval.WriteTextureCoords(texture);
Modified: branches/agate-3d/AgateLib/ImplementationBase/DisplayImpl.cs
===================================================================
--- branches/agate-3d/AgateLib/ImplementationBase/DisplayImpl.cs 2009-04-11 03:25:58 UTC (rev 847)
+++ branches/agate-3d/AgateLib/ImplementationBase/DisplayImpl.cs 2009-04-11 05:09:45 UTC (rev 848)
@@ -578,7 +578,7 @@
/// <returns></returns>
protected internal abstract AgateLib.PlatformSpecific.IPlatformServices GetPlatformServices();
- protected internal virtual VertexBufferImpl CreateVertexBuffer()
+ protected internal virtual VertexBufferImpl CreateVertexBuffer(VertexLayout layout, int vertexCount)
{
throw new AgateException("Cannot create a vertex buffer with a driver that does not support 3D.");
}
@@ -611,8 +611,8 @@
public virtual ShaderProgram Shader
{
- get { throw new NotSupportedException(); }
- set { throw new NotSupportedException(); }
+ get { throw new NotSupportedException("The current driver does not support shaders."); }
+ set { throw new NotSupportedException("The current driver does not support shaders."); }
}
@@ -626,5 +626,5 @@
ShaderCompiler.Disable();
}
- }
+ }
}
Modified: branches/agate-3d/AgateLib/ImplementationBase/VertexBufferImpl.cs
===================================================================
--- branches/agate-3d/AgateLib/ImplementationBase/VertexBufferImpl.cs 2009-04-11 03:25:58 UTC (rev 847)
+++ branches/agate-3d/AgateLib/ImplementationBase/VertexBufferImpl.cs 2009-04-11 05:09:45 UTC (rev 848)
@@ -6,31 +6,28 @@
namespace AgateLib.ImplementationBase
{
- public abstract class VertexBufferImpl
- {
- public abstract void WriteVertexData(Vector3[] data);
- public abstract void WriteTextureCoords(Vector2[] texCoords);
- public abstract void WriteNormalData(Vector3[] data);
+ public abstract class VertexBufferImpl
+ {
+ public abstract void WriteVertexData(Vector3[] data);
+ public abstract void WriteTextureCoords(Vector2[] texCoords);
+ public abstract void WriteNormalData(Vector3[] data);
+ public abstract void WriteIndices(short[] indices);
- public virtual PrimitiveType PrimitiveType { get; set; }
- public virtual Surface Texture { get; set; }
+ public abstract int VertexCount { get; }
+ public abstract int IndexCount { get; }
- public virtual void Draw()
- {
- Draw(0, VertexCount);
- }
- public abstract void Draw(int vertexStart, int vertexCount);
- public virtual void DrawIndexed()
- {
- DrawIndexed(0, IndexCount);
- }
- public abstract void DrawIndexed(int indexStart, int indexCount);
+ public virtual bool Indexed { get; set; }
- public abstract void WriteIndices(short[] indices);
+ public virtual PrimitiveType PrimitiveType { get; set; }
+ public virtual Surface Texture { get; set; }
+
+ public virtual void Draw()
+ {
+ Draw(0, Indexed ? IndexCount : VertexCount);
+ }
+ public abstract void Draw(int start, int count);
- public abstract int VertexCount { get; }
- public abstract int IndexCount { get; }
- }
+ }
}
Modified: branches/agate-3d/Drivers/AgateOTK/GL_Display.cs
===================================================================
--- branches/agate-3d/Drivers/AgateOTK/GL_Display.cs 2009-04-11 03:25:58 UTC (rev 847)
+++ branches/agate-3d/Drivers/AgateOTK/GL_Display.cs 2009-04-11 05:09:45 UTC (rev 848)
@@ -101,9 +101,9 @@
{
return new GL_Surface(fileName);
}
- protected override VertexBufferImpl CreateVertexBuffer()
+ protected override VertexBufferImpl CreateVertexBuffer(VertexLayout layout, int vertexCount)
{
- return new GL_VertexBuffer();
+ return new GL_VertexBuffer(layout);
}
public override SurfaceImpl CreateSurface(Size surfaceSize)
{
Modified: branches/agate-3d/Drivers/AgateOTK/GL_VertexBuffer.cs
===================================================================
--- branches/agate-3d/Drivers/AgateOTK/GL_VertexBuffer.cs 2009-04-11 03:25:58 UTC (rev 847)
+++ branches/agate-3d/Drivers/AgateOTK/GL_VertexBuffer.cs 2009-04-11 05:09:45 UTC (rev 848)
@@ -10,219 +10,222 @@
namespace AgateOTK
{
- public class GL_VertexBuffer : VertexBufferImpl
- {
- GL_Display mDisplay;
- GLState mState;
- GL_Surface mTexture;
+ public class GL_VertexBuffer : VertexBufferImpl
+ {
+ GL_Display mDisplay;
+ GLState mState;
+ GL_Surface mTexture;
- int mVertexCount, mIndexCount;
- int mVertexBufferID;
- int mIndexBufferID;
- int mTexCoordBufferID;
- int mNormalBufferID;
+ int mVertexCount, mIndexCount;
+ int mVertexBufferID;
+ int mIndexBufferID;
+ int mTexCoordBufferID;
+ int mNormalBufferID;
- public GL_VertexBuffer()
- {
- mDisplay = Display.Impl as GL_Display;
- mState = mDisplay.State;
- }
+ VertexLayout layout;
- public override Surface Texture
- {
- get { return base.Texture; }
- set
- {
- base.Texture = value;
- mTexture = (GL_Surface)value.Impl;
- }
- }
- // FYI: use BufferTarget.ElementArrayBuffer to bind to an index buffer.
+ public GL_VertexBuffer(VertexLayout layout)
+ {
+ mDisplay = Display.Impl as GL_Display;
+ mState = mDisplay.State;
+ this.layout = layout;
+ }
- private int CreateBuffer(Vector3[] data)
- {
- int bufferID;
- GL.GenBuffers(1, out bufferID);
- GL.BindBuffer(BufferTarget.ArrayBuffer, bufferID);
+ public override Surface Texture
+ {
+ get { return base.Texture; }
+ set
+ {
+ base.Texture = value;
+ mTexture = (GL_Surface)value.Impl;
+ }
+ }
+ // FYI: use BufferTarget.ElementArrayBuffer to bind to an index buffer.
- unsafe
- {
- fixed (Vector3* ptr = data)
- {
- GL.BufferData(
- BufferTarget.ArrayBuffer,
- (IntPtr)(data.Length * Marshal.SizeOf(typeof(Vector3))),
- (IntPtr)ptr,
- BufferUsageHint.StaticDraw);
- }
- }
-
- GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
- return bufferID;
- }
- private int CreateBuffer(Vector2[] data)
- {
- int bufferID;
- GL.GenBuffers(1, out bufferID);
- GL.BindBuffer(BufferTarget.ArrayBuffer, bufferID);
+ private int CreateBuffer(Vector3[] data)
+ {
+ int bufferID;
+ GL.GenBuffers(1, out bufferID);
+ GL.BindBuffer(BufferTarget.ArrayBuffer, bufferID);
- unsafe
- {
- fixed (Vector2* ptr = data)
- {
- GL.BufferData(
- BufferTarget.ArrayBuffer,
- (IntPtr)(data.Length * Marshal.SizeOf(typeof(Vector2))),
- (IntPtr)ptr,
- BufferUsageHint.StaticDraw);
- }
- }
-
- GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
- return bufferID;
- }
- private int CreateIndexBuffer(short[] data)
- {
- int bufferID;
- GL.GenBuffers(1, out bufferID);
- GL.BindBuffer(BufferTarget.ElementArrayBuffer, bufferID);
+ unsafe
+ {
+ fixed (Vector3* ptr = data)
+ {
+ GL.BufferData(
+ BufferTarget.ArrayBuffer,
+ (IntPtr)(data.Length * Marshal.SizeOf(typeof(Vector3))),
+ (IntPtr)ptr,
+ BufferUsageHint.StaticDraw);
+ }
+ }
- unsafe
- {
- fixed (short* ptr = data)
- {
- GL.BufferData(
- BufferTarget.ElementArrayBuffer,
- (IntPtr)(data.Length * Marshal.SizeOf(typeof(short))),
- (IntPtr)ptr,
- BufferUsageHint.StaticDraw);
- }
- }
+ GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
+ return bufferID;
+ }
+ private int CreateBuffer(Vector2[] data)
+ {
+ int bufferID;
+ GL.GenBuffers(1, out bufferID);
+ GL.BindBuffer(BufferTarget.ArrayBuffer, bufferID);
- GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
- return bufferID;
- }
- public override void WriteVertexData(Vector3[] data)
- {
- mVertexBufferID = CreateBuffer(data);
- mVertexCount = data.Length;
- }
- public override void WriteTextureCoords(Vector2[] texCoords)
- {
- mTexCoordBufferID = CreateBuffer(texCoords);
- }
- public override void WriteNormalData(Vector3[] data)
- {
- mNormalBufferID = CreateBuffer(data);
- }
- public override void WriteIndices(short[] indices)
- {
- mIndexBufferID = CreateIndexBuffer(indices);
- mIndexCount = indices.Length;
- }
+ unsafe
+ {
+ fixed (Vector2* ptr = data)
+ {
+ GL.BufferData(
+ BufferTarget.ArrayBuffer,
+ (IntPtr)(data.Length * Marshal.SizeOf(typeof(Vector2))),
+ (IntPtr)ptr,
+ BufferUsageHint.StaticDraw);
+ }
+ }
- public override void Draw(int vertexStart, int vertexCount)
- {
- SetClientStates();
- BeginMode beginMode = SelectBeginMode();
+ GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
+ return bufferID;
+ }
+ private int CreateIndexBuffer(short[] data)
+ {
+ int bufferID;
+ GL.GenBuffers(1, out bufferID);
+ GL.BindBuffer(BufferTarget.ElementArrayBuffer, bufferID);
+ unsafe
+ {
+ fixed (short* ptr = data)
+ {
+ GL.BufferData(
+ BufferTarget.ElementArrayBuffer,
+ (IntPtr)(data.Length * Marshal.SizeOf(typeof(short))),
+ (IntPtr)ptr,
+ BufferUsageHint.StaticDraw);
+ }
+ }
- GL.EnableClientState(EnableCap.VertexArray);
- GL.BindBuffer(BufferTarget.ArrayBuffer, mVertexBufferID);
- GL.VertexPointer(3, VertexPointerType.Float, 0, (IntPtr)vertexStart);
+ GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
+ return bufferID;
+ }
+ public override void WriteVertexData(Vector3[] data)
+ {
+ mVertexBufferID = CreateBuffer(data);
+ mVertexCount = data.Length;
+ }
+ public override void WriteTextureCoords(Vector2[] texCoords)
+ {
+ mTexCoordBufferID = CreateBuffer(texCoords);
+ }
+ public override void WriteNormalData(Vector3[] data)
+ {
+ mNormalBufferID = CreateBuffer(data);
+ }
+ public override void WriteIndices(short[] indices)
+ {
+ mIndexBufferID = CreateIndexBuffer(indices);
+ mIndexCount = indices.Length;
+ }
- GL.DrawArrays(beginMode, 0, vertexCount);
- }
- public override void DrawIndexed(int indexStart, int indexCount)
- {
- SetClientStates();
- BeginMode beginMode = SelectBeginMode();
+ public override void Draw(int start, int count)
+ {
+ SetClientStates();
+ BeginMode beginMode = SelectBeginMode();
- GL.BindBuffer(BufferTarget.ElementArrayBuffer, mIndexBufferID);
- GL.IndexPointer(IndexPointerType.Short, 0, (IntPtr)indexStart);
+ if (Indexed)
+ {
+ GL.BindBuffer(BufferTarget.ElementArrayBuffer, mIndexBufferID);
+ GL.IndexPointer(IndexPointerType.Short, 0, (IntPtr)start);
- GL.EnableClientState(EnableCap.VertexArray);
- GL.BindBuffer(BufferTarget.ArrayBuffer, mVertexBufferID);
- GL.VertexPointer(3, VertexPointerType.Float, 0, (IntPtr)0);
+ GL.EnableClientState(EnableCap.VertexArray);
+ GL.BindBuffer(BufferTarget.ArrayBuffer, mVertexBufferID);
+ GL.VertexPointer(3, VertexPointerType.Float, 0, (IntPtr)0);
- GL.DrawElements(beginMode, indexCount, DrawElementsType.UnsignedShort, (IntPtr)0);
- }
+ GL.DrawElements(beginMode, count, DrawElementsType.UnsignedShort, (IntPtr)0);
+ }
+ else
+ {
+ GL.EnableClientState(EnableCap.VertexArray);
+ GL.BindBuffer(BufferTarget.ArrayBuffer, mVertexBufferID);
+ GL.VertexPointer(3, VertexPointerType.Float, 0, (IntPtr)start);
- private void SetClientStates()
- {
- mState.SetGLColor(Color.White);
+ GL.DrawArrays(beginMode, 0, count);
+ }
+
+ }
+ private void SetClientStates()
+ {
+ mState.SetGLColor(Color.White);
- if (UseTexture)
- {
- GL.Enable(EnableCap.Texture2D);
- GL.EnableClientState(EnableCap.TextureCoordArray);
- GL.BindBuffer(BufferTarget.ArrayBuffer, mTexCoordBufferID);
- GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, IntPtr.Zero);
- GL.BindTexture(TextureTarget.Texture2D, mTexture.GLTextureID);
- }
- else
- {
- GL.Disable(EnableCap.Texture2D);
- GL.DisableClientState(EnableCap.TextureCoordArray);
- GL.BindTexture(TextureTarget.Texture2D, 0);
- }
- if (HasNormals)
- {
- GL.EnableClientState(EnableCap.NormalArray);
- GL.BindBuffer(BufferTarget.ArrayBuffer, mNormalBufferID);
- GL.NormalPointer(NormalPointerType.Float, 0, IntPtr.Zero);
- }
- else
- {
- GL.DisableClientState(EnableCap.NormalArray);
- }
- }
- private BeginMode SelectBeginMode()
- {
- BeginMode beginMode;
- switch (PrimitiveType)
- {
- case PrimitiveType.TriangleList: beginMode = BeginMode.Triangles; break;
- case PrimitiveType.TriangleFan: beginMode = BeginMode.TriangleFan; break;
- case PrimitiveType.TriangleStrip: beginMode = BeginMode.TriangleStrip; break;
+ if (UseTexture)
+ {
+ GL.Enable(EnableCap.Texture2D);
+ GL.EnableClientState(EnableCap.TextureCoordArray);
+ GL.BindBuffer(BufferTarget.ArrayBuffer, mTexCoordBufferID);
+ GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, IntPtr.Zero);
+ GL.BindTexture(TextureTarget.Texture2D, mTexture.GLTextureID);
+ }
+ else
+ {
+ GL.Disable(EnableCap.Texture2D);
+ GL.DisableClientState(EnableCap.TextureCoordArray);
+ GL.BindTexture(TextureTarget.Texture2D, 0);
+ }
+ if (HasNormals)
+ {
+ GL.EnableClientState(EnableCap.NormalArray);
+ GL.BindBuffer(BufferTarget.ArrayBuffer, mNormalBufferID);
+ GL.NormalPointer(NormalPointerType.Float, 0, IntPtr.Zero);
+ }
+ else
+ {
+ GL.DisableClientState(EnableCap.NormalArray);
+ }
+ }
- default:
- throw new AgateException(string.Format(
- "Unsupported PrimitiveType {0}", PrimitiveType));
- }
- return beginMode;
- }
+ private BeginMode SelectBeginMode()
+ {
+ BeginMode beginMode;
+ switch (PrimitiveType)
+ {
+ case PrimitiveType.TriangleList: beginMode = BeginMode.Triangles; break;
+ case PrimitiveType.TriangleFan: beginMode = BeginMode.TriangleFan; break;
+ case PrimitiveType.TriangleStrip: beginMode = BeginMode.TriangleStrip; break;
- private static void CheckError()
- {
- ErrorCode err = GL.GetError();
+ default:
+ throw new AgateException(string.Format(
+ "Unsupported PrimitiveType {0}", PrimitiveType));
+ }
+ return beginMode;
+ }
- if (err != ErrorCode.NoError)
- System.Diagnostics.Debug.Print("Error: {0}", err);
- }
+ private static void CheckError()
+ {
+ ErrorCode err = GL.GetError();
- public override int IndexCount
- {
- get { return mIndexCount; }
- }
- public override int VertexCount
- {
- get { return mVertexCount; }
- }
+ if (err != ErrorCode.NoError)
+ System.Diagnostics.Debug.Print("Error: {0}", err);
+ }
- bool UseTexture
- {
- get { return HasTextureCoords && mTexture != null; }
- }
- public bool HasTextureCoords
- {
- get { return mTexCoordBufferID != 0; }
- }
- public bool HasNormals
- {
- get { return mNormalBufferID != 0; }
- }
- }
+ public override int IndexCount
+ {
+ get { return mIndexCount; }
+ }
+ public override int VertexCount
+ {
+ get { return mVertexCount; }
+ }
+
+ bool UseTexture
+ {
+ get { return HasTextureCoords && mTexture != null; }
+ }
+ public bool HasTextureCoords
+ {
+ get { return mTexCoordBufferID != 0; }
+ }
+ public bool HasNormals
+ {
+ get { return mNormalBufferID != 0; }
+ }
+ }
}
Modified: branches/agate-3d/Tests/Display3D/Glsl/Glsl.cs
===================================================================
--- branches/agate-3d/Tests/Display3D/Glsl/Glsl.cs 2009-04-11 03:25:58 UTC (rev 847)
+++ branches/agate-3d/Tests/Display3D/Glsl/Glsl.cs 2009-04-11 05:09:45 UTC (rev 848)
@@ -102,7 +102,7 @@
Display.MatrixWorld = Matrix4.RotateZ((float)(frequency * time)) * Matrix4.Translation(-size / 2, -size / 2, 0);
- buffer.DrawIndexed();
+ buffer.Draw();
Display.EndFrame();
Core.KeepAlive();
Modified: branches/agate-3d/Tests/Display3D/Test3D/Test3d.cs
===================================================================
--- branches/agate-3d/Tests/Display3D/Test3D/Test3d.cs 2009-04-11 03:25:58 UTC (rev 847)
+++ branches/agate-3d/Tests/Display3D/Test3D/Test3d.cs 2009-04-11 05:09:45 UTC (rev 848)
@@ -141,7 +141,7 @@
Display.DrawRect(new Rectangle(0, 0, 8, 8), Color.Black);
- b.DrawIndexed();
+ b.Draw();
Display.EndFrame();
Core.KeepAlive();
Modified: branches/agate-3d/Tests/Display3D/TestMatrices/Matrices.cs
===================================================================
--- branches/agate-3d/Tests/Display3D/TestMatrices/Matrices.cs 2009-04-11 03:25:58 UTC (rev 847)
+++ branches/agate-3d/Tests/Display3D/TestMatrices/Matrices.cs 2009-04-11 05:09:45 UTC (rev 848)
@@ -143,7 +143,7 @@
Display.DrawRect(new Rectangle(0, 0, 8, 8), Color.Black);
- b.DrawIndexed();
+ b.Draw();
Display.EndFrame();
Core.KeepAlive();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-04-11 03:26:05
|
Revision: 847
http://agate.svn.sourceforge.net/agate/?rev=847&view=rev
Author: kanato
Date: 2009-04-11 03:25:58 +0000 (Sat, 11 Apr 2009)
Log Message:
-----------
Add interpolation hint tester.
Added Paths:
-----------
trunk/Tests/DisplayTests/Interpolation.cs
Added: trunk/Tests/DisplayTests/Interpolation.cs
===================================================================
--- trunk/Tests/DisplayTests/Interpolation.cs (rev 0)
+++ trunk/Tests/DisplayTests/Interpolation.cs 2009-04-11 03:25:58 UTC (rev 847)
@@ -0,0 +1,65 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using AgateLib;
+using AgateLib.DisplayLib;
+using AgateLib.Geometry;
+
+namespace Tests.DisplayTests
+{
+ class Interpolation : AgateLib.AgateApplication, IAgateTest
+ {
+
+ #region IAgateTest Members
+
+ public string Name
+ {
+ get { return "Interpolation Mode"; }
+ }
+
+ public string Category
+ {
+ get { return "Display"; }
+ }
+
+ Surface surf, surf2;
+ FontSurface font;
+
+ protected override void Initialize()
+ {
+ surf = new Surface("jellybean.png");
+ surf2 = new Surface("jellybean.png");
+ font = new FontSurface("Arial", 14);
+
+ surf.SetScale(6.0, 6.0);
+ font.SetScale(3.0, 3.0);
+ surf2.SetScale(6.0, 6.0);
+ }
+
+ protected override void Render()
+ {
+ Display.Clear(Color.Blue);
+
+ surf.InterpolationHint = InterpolationMode.Fastest;
+ surf.Draw(10, 10);
+
+ font.DrawText(10, 500, "Chonky chonk chonk");
+
+ surf2.InterpolationHint = InterpolationMode.Fastest;
+ surf2.Draw(500, 10);
+ }
+
+ #endregion
+
+ #region IAgateTest Members
+
+
+ public void Main(string[] args)
+ {
+ Run(args);
+ }
+
+ #endregion
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-04-11 03:25:29
|
Revision: 846
http://agate.svn.sourceforge.net/agate/?rev=846&view=rev
Author: kanato
Date: 2009-04-11 03:25:27 +0000 (Sat, 11 Apr 2009)
Log Message:
-----------
Fix the interpolation hint to be applied after the texture is switched.
Modified Paths:
--------------
trunk/Drivers/AgateOTK/GLDrawBuffer.cs
Modified: trunk/Drivers/AgateOTK/GLDrawBuffer.cs
===================================================================
--- trunk/Drivers/AgateOTK/GLDrawBuffer.cs 2009-04-09 07:30:58 UTC (rev 845)
+++ trunk/Drivers/AgateOTK/GLDrawBuffer.cs 2009-04-11 03:25:27 UTC (rev 846)
@@ -87,7 +87,7 @@
int mIndex;
int mCurrentTexture;
- InterpolationMode lastInerpolation;
+ InterpolationMode lastInterpolation = (InterpolationMode)(-1);
PointF[] cachePts = new PointF[4];
public GLDrawBuffer(GLState state)
@@ -126,36 +126,11 @@
public void SetInterpolationMode(InterpolationMode mode)
{
- if (mode == lastInerpolation)
+ if (mode == lastInterpolation)
return;
Flush();
- lastInerpolation = mode;
-
- switch (mode)
- {
- case InterpolationMode.Fastest:
- GL.TexParameter(TextureTarget.Texture2D,
- TextureParameterName.TextureMinFilter,
- (int)TextureMinFilter.Nearest);
- GL.TexParameter(TextureTarget.Texture2D,
- TextureParameterName.TextureMagFilter,
- (int)TextureMagFilter.Nearest);
-
- break;
-
- case InterpolationMode.Default:
- case InterpolationMode.Nicest:
- GL.TexParameter(TextureTarget.Texture2D,
- TextureParameterName.TextureMinFilter,
- (int)TextureMinFilter.Linear);
- GL.TexParameter(TextureTarget.Texture2D,
- TextureParameterName.TextureMagFilter,
- (int)TextureMagFilter.Linear);
-
-
- break;
- }
+ lastInterpolation = mode;
}
public void AddQuad(int textureID, Color color, TextureCoordinates texCoord, RectangleF destRect)
@@ -229,6 +204,8 @@
GL.BindTexture(TextureTarget.Texture2D, mCurrentTexture);
+ SetGLInterpolation();
+
GL.EnableClientState(EnableCap.TextureCoordArray);
GL.EnableClientState(EnableCap.ColorArray);
GL.EnableClientState(EnableCap.VertexArray);
@@ -247,6 +224,35 @@
mIndex = 0;
}
+ private void SetGLInterpolation()
+ {
+
+ switch (this.lastInterpolation)
+ {
+ case InterpolationMode.Fastest:
+ GL.TexParameter(TextureTarget.Texture2D,
+ TextureParameterName.TextureMinFilter,
+ (int)TextureMinFilter.Nearest);
+ GL.TexParameter(TextureTarget.Texture2D,
+ TextureParameterName.TextureMagFilter,
+ (int)TextureMagFilter.Nearest);
+
+ break;
+
+ case InterpolationMode.Default:
+ case InterpolationMode.Nicest:
+ GL.TexParameter(TextureTarget.Texture2D,
+ TextureParameterName.TextureMinFilter,
+ (int)TextureMinFilter.Linear);
+ GL.TexParameter(TextureTarget.Texture2D,
+ TextureParameterName.TextureMagFilter,
+ (int)TextureMagFilter.Linear);
+
+
+ break;
+ }
+ }
+
private void oldFlush()
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-04-09 07:31:00
|
Revision: 845
http://agate.svn.sourceforge.net/agate/?rev=845&view=rev
Author: kanato
Date: 2009-04-09 07:30:58 +0000 (Thu, 09 Apr 2009)
Log Message:
-----------
Update comments.
Modified Paths:
--------------
branches/agate-3d/Drivers/AgateOTK/GlslShader.cs
Modified: branches/agate-3d/Drivers/AgateOTK/GlslShader.cs
===================================================================
--- branches/agate-3d/Drivers/AgateOTK/GlslShader.cs 2009-04-09 07:22:05 UTC (rev 844)
+++ branches/agate-3d/Drivers/AgateOTK/GlslShader.cs 2009-04-09 07:30:58 UTC (rev 845)
@@ -44,8 +44,9 @@
GL.GetActiveUniform(programHandle, i, 1000, out length, out size, out type, b);
name = b.ToString();
- // some drivers apparently report uniforms that don't have a location.
- // This is observed on with ATI driver 9.2 I think.
+ // Apparently OpenGL reports not just user uniforms, but also built-in uniforms
+ // that are determined "active" and accessible in program execution. Built-in uniforms
+ // won't return a location because they cannot be directly modified by the OpenGL client.
int loc = GL.GetUniformLocation(programHandle, name);
if (loc == -1)
continue;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-04-09 07:22:11
|
Revision: 844
http://agate.svn.sourceforge.net/agate/?rev=844&view=rev
Author: kanato
Date: 2009-04-09 07:22:05 +0000 (Thu, 09 Apr 2009)
Log Message:
-----------
Skip built-in uniforms reported by GL.GetActiveUniform calls.
Modified Paths:
--------------
branches/agate-3d/Drivers/AgateOTK/GlslShader.cs
Modified: branches/agate-3d/Drivers/AgateOTK/GlslShader.cs
===================================================================
--- branches/agate-3d/Drivers/AgateOTK/GlslShader.cs 2009-04-09 06:49:27 UTC (rev 843)
+++ branches/agate-3d/Drivers/AgateOTK/GlslShader.cs 2009-04-09 07:22:05 UTC (rev 844)
@@ -11,9 +11,15 @@
{
struct UniformInfo
{
+ public string Name;
public int Location;
public ActiveUniformType Type;
public int Size;
+
+ public override string ToString()
+ {
+ return "Uniform: " + Name + " | " + Type.ToString();
+ }
}
Dictionary<string, UniformInfo> mUniforms = new Dictionary<string, UniformInfo>();
@@ -34,15 +40,24 @@
int length;
int size;
ActiveUniformType type;
+ string name;
GL.GetActiveUniform(programHandle, i, 1000, out length, out size, out type, b);
+ name = b.ToString();
+ // some drivers apparently report uniforms that don't have a location.
+ // This is observed on with ATI driver 9.2 I think.
+ int loc = GL.GetUniformLocation(programHandle, name);
+ if (loc == -1)
+ continue;
+
UniformInfo info = new UniformInfo();
- info.Location = GetUniformLocation(b.ToString());
+ info.Name = name;
+ info.Location = loc;
info.Type = type;
info.Size = size;
- mUniforms.Add(b.ToString(), info);
+ mUniforms.Add(info.Name, info);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-04-09 06:49:38
|
Revision: 843
http://agate.svn.sourceforge.net/agate/?rev=843&view=rev
Author: kanato
Date: 2009-04-09 06:49:27 +0000 (Thu, 09 Apr 2009)
Log Message:
-----------
Add missing ArbShader.cs file.
Added Paths:
-----------
branches/agate-3d/Drivers/AgateOTK/ArbShader.cs
Added: branches/agate-3d/Drivers/AgateOTK/ArbShader.cs
===================================================================
--- branches/agate-3d/Drivers/AgateOTK/ArbShader.cs (rev 0)
+++ branches/agate-3d/Drivers/AgateOTK/ArbShader.cs 2009-04-09 06:49:27 UTC (rev 843)
@@ -0,0 +1,60 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using AgateLib.DisplayLib.Shaders;
+using OpenTK.Graphics;
+
+namespace AgateOTK
+{
+ class ArbShader : ShaderProgram
+ {
+ int programHandle;
+ Dictionary<string, int> mUniforms = new Dictionary<string, int>();
+
+ public ArbShader(int handle, GlslVertexProgram vert, GlslFragmentProgram frag)
+ {
+ programHandle = handle;
+ this.vertex = vert;
+ this.pixel = frag;
+ }
+
+ GlslVertexProgram vertex;
+ GlslFragmentProgram pixel;
+
+ public override PixelShader PixelShader
+ {
+ get { return pixel; }
+ }
+ public override VertexShader VertexShader
+ {
+ get { return vertex; }
+ }
+
+ public int Handle
+ {
+ get { return programHandle; }
+ }
+
+ private int GetUniformLocation(string name)
+ {
+ if (mUniforms.ContainsKey(name))
+ return mUniforms[name];
+
+ return GL.Arb.GetUniformLocation(programHandle, name);
+ }
+
+ public override void SetUniform(string name, params float[] v)
+ {
+ int loc = GetUniformLocation(name);
+
+ }
+ public override void SetUniform(string name, params int[] v)
+ {
+ }
+
+ public override void SetUniform(string name, AgateLib.Geometry.Matrix4 matrix)
+ {
+ }
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|