Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions Demo/XNA/DefaultEffectProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace SMAADemo
{
/** Implementation of IEffectProvider via XNA content pipeline with optional logging */
public class DefaultEffectProvider : IEffectProvider
{
private readonly Dictionary<string, Effect> Cache;
private readonly ContentManager Content;
private readonly ILogger Logger;
private readonly string Prefix;

/** Construct an effect provider given a ContentManager
*
* @param _Content valid XNA content manager
* @param _Logger optional logging instance
* @param _Prefix prefix to add to all effects before loading them
* using the supplied content manager.
*/
public DefaultEffectProvider(ContentManager _Content, ILogger _Logger = null,
string _Prefix = "shaders/SMAA_")
{
Logger = _Logger;
Content = _Content;
Prefix = _Prefix;

Debug.Assert(_Content != null);
Debug.Assert(_Prefix != null);

Cache = new Dictionary<string, Effect>();
}


/** Get an effect given a resource name.
* @param name Unique resource name to be loaded, the prefix supplied
* to the constructor will be prepended before passing it to
* the content pipeline.
* @throws If the resource could no be loaded */
public Effect Get(string name)
{
if (!Cache.ContainsKey(name))
{
Create(name);
}
return Cache[name];
}


/** Equivalent to Get() in this implementation. */
public void Prefetch(string name)
{
// right now there is no difference between just
// pre-fetching effects and actually using them.
Get(name);
}


private void Create(string name)
{
Cache[name] = Content.Load<Effect>(Prefix + name);

if (Logger != null)
{
Logger.Log("Created effect: " + name);
}
}
}
}
22 changes: 22 additions & 0 deletions Demo/XNA/DefaultLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* This XNA4/C# port of SMAA is (c) 2012, Alexander Christoph Gessler
* It is released as Open Source under the same conditions as SMAA itself.
*
* Check out LICENSE.txt in the root folder of the repository or
* Readme.txt in /Demo/XNA for more information.
*/

using System;
using System.Globalization;

namespace SMAADemo
{
/** Default Logger implementation, prints to console */
public class DefaultLogger : ILogger
{
public void Log(string text, int level = (int)LogLevel.INFO)
{
Console.WriteLine(level.ToString(CultureInfo.InvariantCulture) + ": " + text);
}
}
}
71 changes: 71 additions & 0 deletions Demo/XNA/DefaultTextureProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace SMAADemo
{
/** Implementation of ITextureProvider via XNA content pipeline with optional logging */
public class DefaultTextureProvider : ITextureProvider
{
private readonly Dictionary<string, Texture2D> Cache;
private readonly ContentManager Content;
private readonly ILogger Logger;
private readonly string Prefix;


/** Construct a texture provider given a ContentManager
*
* @param _Content valid XNA content manager
* @param _Logger optional logging instance
* @param _Prefix prefix to add to all textures before loading them
* using the supplied content manager.
*/
public DefaultTextureProvider(ContentManager _Content, ILogger _Logger = null,
string _Prefix = "textures/")
{
Logger = _Logger;
Content = _Content;
Prefix = _Prefix;

Debug.Assert(_Content != null);
Debug.Assert(_Prefix != null);

Cache = new Dictionary<string, Texture2D>();
}


/** Get a texture given a resource name.
* @param name Unique resource name to be loaded, the prefix supplied
* to the constructor will be prepended before passing it to
* the content pipeline.
* @throws If the resource could no be loaded */
public Texture2D Get(string name)
{
if (!Cache.ContainsKey(name))
{
Create(name);
}
return Cache[name];
}


/** Equivalent to Get() in this implementation. */
public void Prefetch(string name)
{
// right now there is no difference between just
// pre-fetching textures and actually using them.
Get(name);
}


private void Create(string name)
{
Cache[name] = Content.Load<Texture2D>(Prefix + name);
if(Logger != null)
{
Logger.Log("Created effect: " + name, 3);
}
}
}
}
150 changes: 150 additions & 0 deletions Demo/XNA/Demo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/**
* This XNA4/C# port of SMAA is (c) 2012, Alexander Christoph Gessler
* It is released as Open Source under the same conditions as SMAA itself.
*
* Check out LICENSE.txt in the root folder of the repository or
* Readme.txt in /Demo/XNA for more information.
*/

using System.Diagnostics;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace SMAADemo
{

public class Demo : Game
{
private GraphicsDeviceManager gd;
SpriteBatch spriteBatch;
SMAA smaa;
Texture2D texture;
RenderTarget2D rt;

int mode;
const int MAX_MODES = 4;
bool wasDown;

private const string baseTitle = "Subpixel Morphological Antialiasing (SMAA) XNA Demo - [Space] to cycle modes - ";

public Demo()
{
gd = new GraphicsDeviceManager(this)
{PreferredBackBufferWidth = 1280, PreferredBackBufferHeight = 720};

Content.RootDirectory = "";

Window.Title = baseTitle + "No SMAA";
}


protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);

smaa = new SMAA(GraphicsDevice, 1280, 720, SMAA.Preset.ULTRA,
Content, null, null, "shaders/SMAA_", "textures/");

texture = Content.Load<Texture2D>("textures/Unigine02");

rt = new RenderTarget2D(GraphicsDevice, 1280, 720);
}


protected override void UnloadContent()
{
smaa.Dispose();
}


protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
Exit();

KeyboardState ks = Keyboard.GetState();
if (ks.IsKeyUp(Keys.Space))
{
if (wasDown)
{
mode = (mode + 1) % MAX_MODES;
wasDown = false;

switch (mode)
{
case 0:
Window.Title = baseTitle + "No SMAA";
break;

case 1:
Window.Title = baseTitle + "Quality Ultra, Edge Detection";
break;

case 2:
Window.Title = baseTitle + "Quality Ultra, Luma Detection";
break;

case 3:
Window.Title = baseTitle + "Quality Ultra, Color Detection";
break;

default:
Debug.Assert(false);
return;
}
}
}
else
{
wasDown = true;
}

base.Update(gameTime);
}


protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);

if (mode > 0)
{
GraphicsDevice.SetRenderTarget(rt);
}

spriteBatch.Begin();
spriteBatch.Draw(texture, new Rectangle(0, 0, 1280, 720), Color.White);
spriteBatch.End();

if (mode > 0)
{
SMAA.Input sinput;
switch (mode)
{
case 1:
sinput = SMAA.Input.DEPTH;
break;

case 2:
sinput = SMAA.Input.LUMA;
break;

case 3:
sinput = SMAA.Input.COLOR;
break;

default:
Debug.Assert(false);
return;
}

smaa.Go(rt, rt, null, sinput);
}

base.Draw(gameTime);
}
}
}
Binary file added Demo/XNA/Game.ico
Binary file not shown.
Binary file added Demo/XNA/GameThumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions Demo/XNA/IEffectProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* This XNA4/C# port of SMAA is (c) 2012, Alexander Christoph Gessler
* It is released as Open Source under the same conditions as SMAA itself.
*
* Check out LICENSE.txt in the root folder of the repository or
* Readme.txt in /Demo/XNA for more information.
*/

using Microsoft.Xna.Framework.Graphics;

namespace SMAADemo
{
public interface IEffectProvider
{
Effect Get(string name);
void Prefetch(string name);
}
}

20 changes: 20 additions & 0 deletions Demo/XNA/ILogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* This XNA4/C# port of SMAA is (c) 2012, Alexander Christoph Gessler
* It is released as Open Source under the same conditions as SMAA itself.
*
* Check out LICENSE.txt in the root folder of the repository or
* Readme.txt in /Demo/XNA for more information.
*/

namespace SMAADemo
{
public enum LogLevel
{
VERBOSE = 0, INFO = 5, WARN = 10, ERROR = 15
}

public interface ILogger
{
void Log(string text, int level = (int)LogLevel.INFO);
}
}
19 changes: 19 additions & 0 deletions Demo/XNA/ITextureProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* This XNA4/C# port of SMAA is (c) 2012, Alexander Christoph Gessler
* It is released as Open Source under the same conditions as SMAA itself.
*
* Check out LICENSE.txt in the root folder of the repository or
* Readme.txt in /Demo/XNA for more information.
*/

using Microsoft.Xna.Framework.Graphics;

namespace SMAADemo
{
public interface ITextureProvider
{
Texture2D Get(string name);
void Prefetch(string name);
}
}

Loading