FS#25 - Change sf::PostFx to a more general purpose pixel shader class (sf::Shader)

Updated the PostFx sample, renamed to Shader
Renamed all the static X::CanUseX() functions to X::IsAvailable() to make the API more consistent
Moved .def files from /build/VC200X to /src in CSFML
Minors fixes in CSFML

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1258 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
LaurentGom 2009-11-03 09:04:40 +00:00
parent 63e07cec84
commit d7bd00afc0
125 changed files with 1606 additions and 2348 deletions

View file

@ -11,12 +11,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sample-opengl", "..\..\samp
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sample-window", "..\..\samples\window\sample-window.csproj", "{C1FBB9AF-B69A-4D06-9BDC-EAC7606296FF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sample-postfx", "..\..\samples\post-fx\sample-postfx.csproj", "{9D4738F7-34EA-433A-A765-AF85A52A174D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sample-sound", "..\..\samples\sound\sample-sound.csproj", "{16E177F3-A0FF-4091-8521-562E0EBAA3AB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sample-soundcapture", "..\..\samples\sound_capture\sample-soundcapture.csproj", "{F2F48990-F81E-41BA-AD01-168F6178C807}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sample-shader", "..\..\samples\shader\sample-shader.csproj", "{9D4738F7-34EA-433A-A765-AF85A52A174D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -43,10 +43,6 @@ Global
{C1FBB9AF-B69A-4D06-9BDC-EAC7606296FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C1FBB9AF-B69A-4D06-9BDC-EAC7606296FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C1FBB9AF-B69A-4D06-9BDC-EAC7606296FF}.Release|Any CPU.Build.0 = Release|Any CPU
{9D4738F7-34EA-433A-A765-AF85A52A174D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9D4738F7-34EA-433A-A765-AF85A52A174D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D4738F7-34EA-433A-A765-AF85A52A174D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D4738F7-34EA-433A-A765-AF85A52A174D}.Release|Any CPU.Build.0 = Release|Any CPU
{16E177F3-A0FF-4091-8521-562E0EBAA3AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{16E177F3-A0FF-4091-8521-562E0EBAA3AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{16E177F3-A0FF-4091-8521-562E0EBAA3AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
@ -55,6 +51,10 @@ Global
{F2F48990-F81E-41BA-AD01-168F6178C807}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F2F48990-F81E-41BA-AD01-168F6178C807}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F2F48990-F81E-41BA-AD01-168F6178C807}.Release|Any CPU.Build.0 = Release|Any CPU
{9D4738F7-34EA-433A-A765-AF85A52A174D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9D4738F7-34EA-433A-A765-AF85A52A174D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D4738F7-34EA-433A-A765-AF85A52A174D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D4738F7-34EA-433A-A765-AF85A52A174D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -1,16 +0,0 @@
texture framebuffer
float offset
effect
{
vec2 offx = vec2(offset, 0.0);
vec2 offy = vec2(0.0, offset);
vec4 c0 = framebuffer(_in);
vec4 c1 = framebuffer(_in - offy);
vec4 c2 = framebuffer(_in + offy);
vec4 c3 = framebuffer(_in - offx);
vec4 c4 = framebuffer(_in + offx);
_out = c0 * 0.2 + c1 * 0.2 + c2 * 0.2 + c3 * 0.2 + c4 * 0.2;
}

View file

@ -1,10 +0,0 @@
texture framebuffer
vec3 color
effect
{
vec4 pixel = framebuffer(_in);
float gray = pixel.r * 0.39 + pixel.g * 0.50 + pixel.b * 0.11;
_out = vec4(gray * color, 1.0) * 0.6 + pixel * 0.4;
}

View file

@ -1,12 +0,0 @@
texture framebuffer
vec2 mouse
effect
{
float len = distance(_in, mouse) * 7.0;
if (len < 1.0)
_out = framebuffer(_in + (_in - mouse) * len);
else
_out = framebuffer(_in);
}

View file

@ -1,6 +0,0 @@
texture framebuffer
effect
{
_out = framebuffer(_in);
}

View file

@ -1,11 +0,0 @@
texture framebuffer
vec2 mouse
effect
{
float factor = 5 + 100 * length(mouse);
vec2 pos = floor(_in * factor) / factor;
_out = framebuffer(pos);
}

View file

@ -1,12 +0,0 @@
texture framebuffer
texture wave
vec2 offset
effect
{
vec2 texoffset = wave(_in * offset).xy;
texoffset -= vec2(0.5, 0.5);
texoffset *= 0.05;
_out = framebuffer(_in + texoffset);
}

Binary file not shown.

View file

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 52 KiB

Before After
Before After

View file

@ -0,0 +1,16 @@
uniform sampler2D texture;
uniform float offset;
void main()
{
vec2 offx = vec2(offset, 0.0);
vec2 offy = vec2(0.0, offset);
vec4 c0 = texture2D(texture, gl_TexCoord[0].xy);
vec4 c1 = texture2D(texture, gl_TexCoord[0].xy - offy);
vec4 c2 = texture2D(texture, gl_TexCoord[0].xy + offy);
vec4 c3 = texture2D(texture, gl_TexCoord[0].xy - offx);
vec4 c4 = texture2D(texture, gl_TexCoord[0].xy + offx);
gl_FragColor = gl_Color * (c0 * 0.2 + c1 * 0.2 + c2 * 0.2 + c3 * 0.2 + c4 * 0.2);
}

View file

@ -0,0 +1,11 @@
uniform sampler2D texture;
uniform vec3 color;
void main()
{
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy) * gl_Color;
float gray = pixel.r * 0.39 + pixel.g * 0.50 + pixel.b * 0.11;
gl_FragColor = vec4(gray * color, 1.0) * 0.6 + pixel * 0.4;
gl_FragColor.a = pixel.a;
}

View file

@ -0,0 +1,13 @@
uniform sampler2D texture;
uniform vec2 mouse;
void main()
{
float len = distance(gl_TexCoord[0].xy, mouse) * 7.0;
vec2 coords = gl_TexCoord[0].xy;
if (len < 1.0)
coords += (gl_TexCoord[0].xy - mouse) * len;
gl_FragColor = texture2D(texture, coords) * gl_Color;
}

View file

@ -0,0 +1,6 @@
uniform sampler2D texture;
void main()
{
gl_FragColor = texture2D(texture, gl_TexCoord[0].xy) * gl_Color;
}

View file

@ -0,0 +1,10 @@
uniform sampler2D texture;
uniform vec2 mouse;
void main()
{
float factor = 5 + 100 * length(mouse);
vec2 pos = floor(gl_TexCoord[0].xy * factor + 0.5) / factor;
gl_FragColor = texture2D(texture, pos) * gl_Color;
}

View file

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Before After
Before After

View file

@ -0,0 +1,12 @@
uniform sampler2D texture;
uniform sampler2D wave;
uniform vec2 offset;
void main()
{
vec2 texoffset = texture2D(wave, (gl_TexCoord[0].xy * offset).xy);
texoffset -= vec2(0.5, 0.5);
texoffset *= 0.05;
gl_FragColor = texture2D(texture, gl_TexCoord[0].xy + texoffset) * gl_Color;
}

View file

@ -1,184 +0,0 @@
using System;
using System.Collections.Generic;
using SFML;
using SFML.Graphics;
using SFML.Window;
namespace sample_postfx
{
static class Program
{
private static Dictionary<string, PostFx> effects;
private static Dictionary<string, PostFx>.Enumerator currentEffect;
private static String2D curFXStr;
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
// Create the main window
RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML.Net PostFX");
// Setup event handlers
window.Closed += new EventHandler(OnClosed);
window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
// Check that the system can use post effects
if (PostFx.CanUsePostFX == false)
{
DisplayError(window);
return;
}
// Load a background image to display
Sprite background = new Sprite(new Image("datas/post-fx/background.jpg"));
// Load a sprite which we'll move into the scene
Sprite entity = new Sprite(new Image("datas/post-fx/sprite.png"));
// Load the text font
Font cheeseburger = new Font("datas/post-fx/cheeseburger.ttf");
// Load the image needed for the wave effect
Image waveImage = new Image("datas/post-fx/wave.jpg");
// Load all effects
effects = new Dictionary<string, PostFx>();
effects["nothing"] = new PostFx("datas/post-fx/nothing.sfx");
effects["blur"] = new PostFx("datas/post-fx/blur.sfx");
effects["colorize"] = new PostFx("datas/post-fx/colorize.sfx");
effects["fisheye"] = new PostFx("datas/post-fx/fisheye.sfx");
effects["wave"] = new PostFx("datas/post-fx/wave.sfx");
effects["pixelate"] = new PostFx("datas/post-fx/pixelate.sfx");
currentEffect = effects.GetEnumerator();
currentEffect.MoveNext();
// Do specific initializations
effects["nothing"].SetTexture("framebuffer", null);
effects["blur"].SetTexture("framebuffer", null);
effects["blur"].SetParameter("offset", 0.0F);
effects["colorize"].SetTexture("framebuffer", null);
effects["colorize"].SetParameter("color", 1.0F, 1.0F, 1.0F);
effects["fisheye"].SetTexture("framebuffer", null);
effects["wave"].SetTexture("framebuffer", null);
effects["wave"].SetTexture("wave", waveImage);
effects["pixelate"].SetTexture("framebuffer", null);
// Define a string for displaying current effect description
curFXStr = new String2D();
curFXStr.Text = "Current effect is \"" + currentEffect.Current.Key + "\"";
curFXStr.Font = cheeseburger;
curFXStr.Position = new Vector2(20.0F, 0.0F);
curFXStr.Color = new Color(150, 70, 110);
// Define a string for displaying help
String2D infoStr = new String2D();
infoStr.Text = "Move your mouse to change the effect parameters\nPress numpad + to change effect\nWarning : some effects may not work\ndepending on your graphics card";
infoStr.Font = cheeseburger;
infoStr.Position = new Vector2(20.0F, 460.0F);
infoStr.Color = new Color(200, 100, 150);
// Start the game loop
float time = 0.0F;
while (window.IsOpened())
{
// Process events
window.DispatchEvents();
// Get the mouse position in the range [0, 1]
float x = window.Input.GetMouseX() / (float)window.Width;
float y = window.Input.GetMouseY() / (float)window.Height;
// Update the current effect
if (currentEffect.Current.Key == "blur") currentEffect.Current.Value.SetParameter("offset", x * y * 0.1f);
else if (currentEffect.Current.Key == "colorize") currentEffect.Current.Value.SetParameter("color", 0.3f, x, y);
else if (currentEffect.Current.Key == "fisheye") currentEffect.Current.Value.SetParameter("mouse", x, 1.0F - y);
else if (currentEffect.Current.Key == "wave") currentEffect.Current.Value.SetParameter("offset", x, y);
else if (currentEffect.Current.Key == "pixelate") currentEffect.Current.Value.SetParameter("mouse", x, y);
// Animate the sprite
time += window.GetFrameTime();
float entityX = (float)(Math.Cos(time * 1.3) + 1.2) * 300;
float entityY = (float)(Math.Cos(time * 0.8) + 1.2) * 200;
entity.Position = new Vector2(entityX, entityY);
entity.Rotation = time * 100;
// Clear the window
window.Clear();
// Draw background, the sprite and apply the post-fx
window.Draw(background);
window.Draw(entity);
window.Draw(currentEffect.Current.Value);
// Draw interface strings
window.Draw(curFXStr);
window.Draw(infoStr);
// Finally, display the rendered frame on screen
window.Display();
}
}
/// <summary>
/// Fonction called when the post-effects are not supported ;
/// Display an error message and wait until the user exits
/// </summary>
private static void DisplayError(RenderWindow window)
{
// Define a string for displaying the error message
String2D errorStr = new String2D("Sorry, your system doesn't support post-effects");
errorStr.Position = new Vector2(100.0F, 250.0F);
errorStr.Color = new Color(200, 100, 150);
// Start the game loop
while (window.IsOpened())
{
// Process events
window.DispatchEvents();
// Clear the window
window.Clear();
// Draw the error message
window.Draw(errorStr);
// Finally, display the rendered frame on screen
window.Display();
}
}
/// <summary>
/// Function called when the window is closed
/// </summary>
static void OnClosed(object sender, EventArgs e)
{
RenderWindow window = (RenderWindow)sender;
window.Close();
}
/// <summary>
/// Function called when a key is pressed
/// </summary>
static void OnKeyPressed(object sender, KeyEventArgs e)
{
RenderWindow window = (RenderWindow)sender;
if (e.Code == KeyCode.Escape)
{
// Close the window
window.Close();
}
else if (e.Code == KeyCode.Add)
{
// Advance to the next effect
if (currentEffect.MoveNext() == false)
{
currentEffect = effects.GetEnumerator();
currentEffect.MoveNext();
}
curFXStr.Text = "Current effect is \"" + currentEffect.Current.Key + "\"";
}
}
}
}

View file

@ -0,0 +1,249 @@
using System;
using System.Collections.Generic;
using SFML;
using SFML.Graphics;
using SFML.Window;
namespace sample_shader
{
/// <summary>
/// A class to simplify shader selection
/// </summary>
class ShaderSelector
{
// Constructor
public ShaderSelector(Dictionary<string, Shader> owner)
{
myOwner = owner;
myIterator = owner.GetEnumerator();
myIterator.MoveNext();
}
// Select the next shader
public void GotoNext()
{
if (myIterator.MoveNext() == false)
{
myIterator = myOwner.GetEnumerator();
myIterator.MoveNext();
}
}
// Update the shader parameters
public void Update(float x, float y)
{
if (myIterator.Current.Key == "blur") myIterator.Current.Value.SetParameter("offset", x * y * 0.05f);
else if (myIterator.Current.Key == "colorize") myIterator.Current.Value.SetParameter("color", 0.3f, x, y);
else if (myIterator.Current.Key == "fisheye") myIterator.Current.Value.SetParameter("mouse", x, y);
else if (myIterator.Current.Key == "wave") myIterator.Current.Value.SetParameter("offset", x, y);
else if (myIterator.Current.Key == "pixelate") myIterator.Current.Value.SetParameter("mouse", x, y);
}
// Get the name of the current shader
public string Name
{
get {return myIterator.Current.Key;}
}
// Get the current shader
public Shader Shader
{
get {return myIterator.Current.Value;}
}
private Dictionary<string, Shader> myOwner;
private Dictionary<string, Shader>.Enumerator myIterator;
};
static class Program
{
private static Dictionary<string, Shader> shaders;
private static ShaderSelector backgroundShader;
private static ShaderSelector entityShader;
private static ShaderSelector globalShader;
private static String2D shaderStr;
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
// Create the main window
RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML.Net Shader");
// Setup event handlers
window.Closed += new EventHandler(OnClosed);
window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
// Check that the system can use shaders
if (Shader.IsAvailable == false)
{
DisplayError(window);
return;
}
// Create the render image
RenderImage image = new RenderImage(window.Width, window.Height);
// Load a background image to display
Sprite background = new Sprite(new Image("datas/shader/background.jpg"));
background.Image.Smooth = false;
// Load a sprite which we'll move into the scene
Sprite entity = new Sprite(new Image("datas/shader/sprite.png"));
// Load the text font
Font font = new Font("datas/shader/arial.ttf", 20);
// Load the image needed for the wave effect
Image waveImage = new Image("datas/shader/wave.jpg");
// Load all effects
shaders = new Dictionary<string, Shader>();
shaders["nothing"] = new Shader("datas/shader/nothing.sfx");
shaders["blur"] = new Shader("datas/shader/blur.sfx");
shaders["colorize"] = new Shader("datas/shader/colorize.sfx");
shaders["fisheye"] = new Shader("datas/shader/fisheye.sfx");
shaders["wave"] = new Shader("datas/shader/wave.sfx");
shaders["pixelate"] = new Shader("datas/shader/pixelate.sfx");
backgroundShader = new ShaderSelector(shaders);
entityShader = new ShaderSelector(shaders);
globalShader = new ShaderSelector(shaders);
// Do specific initializations
shaders["nothing"].SetTexture("texture", Shader.CurrentTexture);
shaders["blur"].SetTexture("texture", Shader.CurrentTexture);
shaders["blur"].SetParameter("offset", 0.0F);
shaders["colorize"].SetTexture("texture", Shader.CurrentTexture);
shaders["colorize"].SetParameter("color", 1.0F, 1.0F, 1.0F);
shaders["fisheye"].SetTexture("texture", Shader.CurrentTexture);
shaders["wave"].SetTexture("texture", Shader.CurrentTexture);
shaders["wave"].SetTexture("wave", waveImage);
shaders["pixelate"].SetTexture("texture", Shader.CurrentTexture);
// Define a string for displaying current effect description
shaderStr = new String2D();
shaderStr.Font = font;
shaderStr.Size = 20;
shaderStr.Position = new Vector2(5.0F, 0.0F);
shaderStr.Color = new Color(250, 100, 30);
shaderStr.Text = "Background shader: \"" + backgroundShader.Name + "\"\n" +
"Flower shader: \"" + entityShader.Name + "\"\n" +
"Global shader: \"" + globalShader.Name + "\"\n";
// Define a string for displaying help
String2D infoStr = new String2D();
infoStr.Font = font;
infoStr.Size = 20;
infoStr.Position = new Vector2(5.0F, 510.0F);
infoStr.Color = new Color(250, 100, 30);
infoStr.Text = "Move your mouse to change the shaders' parameters\n" +
"Press numpad 1 to change the background shader\n" +
"Press numpad 2 to change the flower shader\n" +
"Press numpad 3 to change the global shader";
// Start the game loop
float time = 0.0F;
while (window.IsOpened())
{
// Process events
window.DispatchEvents();
// Get the mouse position in the range [0, 1]
//float x = window.Input.GetMouseX() / (float)window.Width;
//float y = window.Input.GetMouseY() / (float)window.Height;
float x = (float)(Math.Cos(time * 1.3) + 1) * 0.5F;
float y = (float)(Math.Sin(time * 0.8) + 1) * 0.5F;
// Update the shaders
backgroundShader.Update(x, y);
entityShader.Update(x, y);
globalShader.Update(x, y);
// Animate the sprite
time += window.GetFrameTime();
float entityX = (float)(Math.Cos(time * 1.3) + 1.2) * 300;
float entityY = (float)(Math.Cos(time * 0.8) + 1.2) * 200;
entity.Position = new Vector2(entityX, entityY);
entity.Rotation = time * 100;
// Draw the background and the moving entity to the render image
image.Draw(background, backgroundShader.Shader);
image.Draw(entity, entityShader.Shader);
image.Display();
// Draw the contents of the render image to the window
window.Draw(new Sprite(image.Image), globalShader.Shader);
// Draw interface strings
window.Draw(shaderStr);
window.Draw(infoStr);
// Finally, display the rendered frame on screen
window.Display();
}
}
/// <summary>
/// Fonction called when the post-effects are not supported ;
/// Display an error message and wait until the user exits
/// </summary>
private static void DisplayError(RenderWindow window)
{
// Define a string for displaying the error message
String2D errorStr = new String2D("Sorry, your system doesn't support shaders");
errorStr.Position = new Vector2(100.0F, 250.0F);
errorStr.Color = new Color(200, 100, 150);
// Start the game loop
while (window.IsOpened())
{
// Process events
window.DispatchEvents();
// Clear the window
window.Clear();
// Draw the error message
window.Draw(errorStr);
// Finally, display the rendered frame on screen
window.Display();
}
}
/// <summary>
/// Function called when the window is closed
/// </summary>
static void OnClosed(object sender, EventArgs e)
{
RenderWindow window = (RenderWindow)sender;
window.Close();
}
/// <summary>
/// Function called when a key is pressed
/// </summary>
static void OnKeyPressed(object sender, KeyEventArgs e)
{
RenderWindow window = (RenderWindow)sender;
// Escape key : exit
if (e.Code == KeyCode.Escape)
window.Close();
// Numpad : switch effect
switch (e.Code)
{
case KeyCode.Numpad1 : backgroundShader.GotoNext(); break;
case KeyCode.Numpad2 : entityShader.GotoNext(); break;
case KeyCode.Numpad3 : globalShader.GotoNext(); break;
}
// Update the text
shaderStr.Text = "Background shader: \"" + backgroundShader.Name + "\"\n" +
"Flower shader: \"" + entityShader.Name + "\"\n" +
"Global shader: \"" + globalShader.Name + "\"\n";
}
}
}

View file

@ -7,13 +7,14 @@
<ProjectGuid>{9D4738F7-34EA-433A-A765-AF85A52A174D}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>sample_postfx</RootNamespace>
<AssemblyName>post-fx</AssemblyName>
<RootNamespace>sample_shader</RootNamespace>
<AssemblyName>shader</AssemblyName>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>2.0</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<StartupObject>sample_shader.Program</StartupObject>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -43,7 +44,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="PostFx.cs" />
<Compile Include="Shader.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />

View file

@ -13,7 +13,7 @@ namespace sample_soundcapture
static void Main(string[] args)
{
// Check that the device can capture audio
if (SoundRecorder.CanCapture == false)
if (SoundRecorder.IsAvailable == false)
{
Console.WriteLine("Sorry, audio capture is not supported by your system");
return;

View file

@ -78,9 +78,9 @@ namespace SFML
/// If not, this class won't be usable
/// </summary>
////////////////////////////////////////////////////////////
public static bool CanCapture
public static bool IsAvailable
{
get {return sfSoundRecorder_CanCapture();}
get {return sfSoundRecorder_IsAvailable();}
}
////////////////////////////////////////////////////////////
@ -173,7 +173,7 @@ namespace SFML
static extern uint sfSoundRecorder_GetSampleRate(IntPtr SoundRecorder);
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
static extern bool sfSoundRecorder_CanCapture();
static extern bool sfSoundRecorder_IsAvailable();
#endregion
}
}

View file

@ -101,16 +101,18 @@ namespace SFML
/// Render the object into the given render window
/// </summary>
/// <param name="target">Target render window</param>
/// <param name="shader">Shader to apply</param>
////////////////////////////////////////////////////////////
internal abstract void Render(RenderWindow target);
internal abstract void Render(RenderWindow target, Shader shader);
////////////////////////////////////////////////////////////
/// <summary>
/// Render the object into the given render image
/// </summary>
/// <param name="target">Target render image</param>
/// <param name="shader">Shader to apply</param>
////////////////////////////////////////////////////////////
internal abstract void Render(RenderImage target);
internal abstract void Render(RenderImage target, Shader shader);
////////////////////////////////////////////////////////////
/// <summary>

View file

@ -36,14 +36,14 @@ namespace SFML
/// </summary>
/// <param name="width">Width of the render image</param>
/// <param name="height">Height of the render image</param>
/// <param name="depthBuffer">Do you wxant a depth-buffer attached?</param>
/// <param name="depthBuffer">Do you want a depth-buffer attached?</param>
////////////////////////////////////////////////////////////
public RenderImage(uint width, uint height, bool depthBuffer) :
base(sfRenderImage_Create(width, height, depthBuffer))
{
myDefaultView = new View(sfRenderImage_GetDefaultView(This));
myCurrentView = myDefaultView;
myImage = new Image(sfRenderImage_GetImage(This));
myCurrentView = myDefaultView;
GC.SuppressFinalize(myDefaultView);
GC.SuppressFinalize(myImage);
}
@ -177,18 +177,19 @@ namespace SFML
////////////////////////////////////////////////////////////
public void Draw(Drawable objectToDraw)
{
objectToDraw.Render(this);
objectToDraw.Render(this, null);
}
////////////////////////////////////////////////////////////
/// <summary>
/// Apply a post-fx to the render image
/// Draw something into the render image with a shader
/// </summary>
/// <param name="postFx">PostFx to apply</param>
/// <param name="objectToDraw">Object to draw</param>
/// <param name="shader">Shader to apply</param>
////////////////////////////////////////////////////////////
public void Draw(PostFx postFx)
public void Draw(Drawable objectToDraw, Shader shader)
{
sfRenderImage_DrawPostFX(This, postFx != null ? postFx.This : IntPtr.Zero);
objectToDraw.Render(this, shader);
}
////////////////////////////////////////////////////////////
@ -236,9 +237,9 @@ namespace SFML
/// Tell whether or not the system supports render images
/// </summary>
////////////////////////////////////////////////////////////
public static bool CanUseRenderImage
public static bool IsAvailable
{
get {return sfRenderImage_CanUseRenderImage();}
get {return sfRenderImage_IsAvailable();}
}
////////////////////////////////////////////////////////////
@ -308,14 +309,11 @@ namespace SFML
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfRenderImage_ConvertCoords(IntPtr This, uint WindowX, uint WindowY, out float ViewX, out float ViewY, IntPtr TargetView);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfRenderImage_DrawPostFX(IntPtr This, IntPtr PostFx);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern IntPtr sfRenderImage_GetImage(IntPtr This);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern bool sfRenderImage_CanUseRenderImage();
static extern bool sfRenderImage_IsAvailable();
#endregion
}

View file

@ -99,11 +99,12 @@ namespace SFML
////////////////////////////////////////////////////////////
/// <summary>
/// Apply a post-fx to the window
/// Draw something into the render image with a shader
/// </summary>
/// <param name="postFx">PostFx to apply</param>
/// <param name="objectToDraw">Object to draw</param>
/// <param name="shader">Shader to apply</param>
////////////////////////////////////////////////////////////
void Draw(PostFx postFx);
void Draw(Drawable objectToDraw, Shader shader);
////////////////////////////////////////////////////////////
/// <summary>

View file

@ -390,18 +390,19 @@ namespace SFML
////////////////////////////////////////////////////////////
public void Draw(Drawable objectToDraw)
{
objectToDraw.Render(this);
objectToDraw.Render(this, null);
}
////////////////////////////////////////////////////////////
/// <summary>
/// Apply a post-fx to the window
/// Draw something into the window with a shader
/// </summary>
/// <param name="postFx">PostFx to apply</param>
/// <param name="objectToDraw">Object to draw</param>
/// <param name="shader">Shader to apply</param>
////////////////////////////////////////////////////////////
public void Draw(PostFx postFx)
public void Draw(Drawable objectToDraw, Shader shader)
{
sfRenderWindow_DrawPostFX(This, postFx != null ? postFx.This : IntPtr.Zero);
objectToDraw.Render(this, shader);
}
////////////////////////////////////////////////////////////
@ -572,9 +573,6 @@ namespace SFML
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfRenderWindow_ConvertCoords(IntPtr This, uint WindowX, uint WindowY, out float ViewX, out float ViewY, IntPtr TargetView);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfRenderWindow_DrawPostFX(IntPtr This, IntPtr PostFx);
#endregion
}
}

View file

@ -9,97 +9,109 @@ namespace SFML
{
////////////////////////////////////////////////////////////
/// <summary>
/// PostFX is used to apply a post effect to a window
/// Wrapper for pixel shaders
/// </summary>
////////////////////////////////////////////////////////////
public class PostFx : ObjectBase
public class Shader : ObjectBase
{
////////////////////////////////////////////////////////////
/// <summary>
/// Default constructor (invalid effect)
/// Default constructor (invalid shader)
/// </summary>
/// <exception cref="LoadingFailedException" />
////////////////////////////////////////////////////////////
public PostFx() :
base(sfPostFx_Create())
public Shader() :
base(sfShader_Create())
{
if (This == IntPtr.Zero)
throw new LoadingFailedException("post-fx");
throw new LoadingFailedException("shader");
}
////////////////////////////////////////////////////////////
/// <summary>
/// Load the effect from a file
/// Load the shader from a file
/// </summary>
/// <param name="filename">Path of the effect file to load</param>
/// <param name="filename">Path of the shader file to load</param>
/// <exception cref="LoadingFailedException" />
////////////////////////////////////////////////////////////
public PostFx(string filename) :
base(sfPostFX_CreateFromFile(filename))
public Shader(string filename) :
base(sfShader_CreateFromFile(filename))
{
if (This == IntPtr.Zero)
throw new LoadingFailedException("post-fx", filename);
throw new LoadingFailedException("shader", filename);
}
////////////////////////////////////////////////////////////
/// <summary>
/// Load the effect from a text in memory
/// Load the shader from a text in memory
/// </summary>
/// <param name="effect">String containing the effect code</param>
/// <param name="shader">String containing the shader code</param>
/// <exception cref="LoadingFailedException" />
////////////////////////////////////////////////////////////
void LoadFromString(string effect)
void LoadFromString(string shader)
{
SetThis(sfPostFX_CreateFromMemory(effect));
SetThis(sfShader_CreateFromMemory(shader));
if (This == IntPtr.Zero)
throw new LoadingFailedException("post-fx");
throw new LoadingFailedException("shader");
}
////////////////////////////////////////////////////////////
/// <summary>
/// Change a 1-component parameter of the effect
/// Change a vector2 parameter of the shader
/// </summary>
/// <param name="name">Name of the parameter in the effect</param>
/// <param name="name">Name of the parameter in the shader</param>
/// <param name="v">Value of the parameter</param>
////////////////////////////////////////////////////////////
public void SetParameter(string name, Vector2 v)
{
SetParameter(name, v.X, v.Y);
}
////////////////////////////////////////////////////////////
/// <summary>
/// Change a 1-component parameter of the shader
/// </summary>
/// <param name="name">Name of the parameter in the shader</param>
/// <param name="x">Value of the parameter</param>
////////////////////////////////////////////////////////////
public void SetParameter(string name, float x)
{
sfPostFX_SetParameter1(This, name, x);
sfShader_SetParameter1(This, name, x);
}
////////////////////////////////////////////////////////////
/// <summary>
/// Change a 2-component parameter of the effect
/// Change a 2-component parameter of the shader
/// </summary>
/// <param name="name">Name of the parameter in the effect</param>
/// <param name="name">Name of the parameter in the shader</param>
/// <param name="x">X component of the value</param>
/// <param name="y">Y component of the value</param>
////////////////////////////////////////////////////////////
public void SetParameter(string name, float x, float y)
{
sfPostFX_SetParameter2(This, name, x, y);
sfShader_SetParameter2(This, name, x, y);
}
////////////////////////////////////////////////////////////
/// <summary>
/// Change a 3-component parameter of the effect
/// Change a 3-component parameter of the shader
/// </summary>
/// <param name="name">Name of the parameter in the effect</param>
/// <param name="name">Name of the parameter in the shader</param>
/// <param name="x">X component of the value</param>
/// <param name="y">Y component of the value</param>
/// <param name="z">Z component of the value</param>
////////////////////////////////////////////////////////////
public void SetParameter(string name, float x, float y, float z)
{
sfPostFX_SetParameter3(This, name, x, y, z);
sfShader_SetParameter3(This, name, x, y, z);
}
////////////////////////////////////////////////////////////
/// <summary>
/// Change a 4-component parameter of the effect
/// Change a 4-component parameter of the shader
/// </summary>
/// <param name="name">Name of the parameter in the effect</param>
/// <param name="name">Name of the parameter in the shader</param>
/// <param name="x">X component of the value</param>
/// <param name="y">Y component of the value</param>
/// <param name="z">Z component of the value</param>
@ -107,30 +119,60 @@ namespace SFML
////////////////////////////////////////////////////////////
public void SetParameter(string name, float x, float y, float z, float w)
{
sfPostFX_SetParameter4(This, name, x, y, z, w);
sfShader_SetParameter4(This, name, x, y, z, w);
}
////////////////////////////////////////////////////////////
/// <summary>
/// Set a texture parameter
/// </summary>
/// <param name="name">Name of the texture in the effect</param>
/// <param name="texture">Image to set (pass null to use the contents of the screen)</param>
/// <param name="name">Name of the texture in the shader</param>
/// <param name="texture">Image to set (pass null to use the texture of the object being drawn)</param>
////////////////////////////////////////////////////////////
public void SetTexture(string name, Image texture)
{
myTextures[name] = texture;
sfPostFX_SetTexture(This, name, texture != null ? texture.This : IntPtr.Zero);
sfShader_SetTexture(This, name, texture != null ? texture.This : IntPtr.Zero);
}
////////////////////////////////////////////////////////////
/// <summary>
/// Tell whether or not the system supports post-effects
/// Bind the shader for rendering
/// </summary>
////////////////////////////////////////////////////////////
public static bool CanUsePostFX
public void Bind()
{
get {return sfPostFX_CanUsePostFX();}
sfShader_Bind(This);
}
////////////////////////////////////////////////////////////
/// <summary>
/// Unbind the shader
/// </summary>
////////////////////////////////////////////////////////////
public void Unbind()
{
sfShader_Unbind(This);
}
////////////////////////////////////////////////////////////
/// <summary>
/// Tell whether or not the system supports shaders
/// </summary>
////////////////////////////////////////////////////////////
public static bool IsAvailable
{
get {return sfShader_IsAvailable();}
}
////////////////////////////////////////////////////////////
/// <summary>
/// Special image representing the texture used by the object being drawn
/// </summary>
////////////////////////////////////////////////////////////
public static Image CurrentTexture
{
get {return null;}
}
////////////////////////////////////////////////////////////
@ -145,7 +187,7 @@ namespace SFML
Context.Global.SetActive(true);
myTextures.Clear();
sfPostFX_Destroy(This);
sfShader_Destroy(This);
if (!disposing)
Context.Global.SetActive(false);
@ -155,37 +197,40 @@ namespace SFML
#region Imports
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern IntPtr sfPostFx_Create();
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfPostFx_Destroy(IntPtr This);
static extern IntPtr sfShader_Create();
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern IntPtr sfPostFX_CreateFromFile(string Filename);
static extern IntPtr sfShader_CreateFromFile(string Filename);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern IntPtr sfPostFX_CreateFromMemory(string Effect);
static extern IntPtr sfShader_CreateFromMemory(string Shader);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfPostFX_Destroy(IntPtr PostFX);
static extern void sfShader_Destroy(IntPtr Shader);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfPostFX_SetParameter1(IntPtr PostFX, string Name, float X);
static extern void sfShader_SetParameter1(IntPtr Shader, string Name, float X);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfPostFX_SetParameter2(IntPtr PostFX, string Name, float X, float Y);
static extern void sfShader_SetParameter2(IntPtr Shader, string Name, float X, float Y);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfPostFX_SetParameter3(IntPtr PostFX, string Name, float X, float Y, float Z);
static extern void sfShader_SetParameter3(IntPtr Shader, string Name, float X, float Y, float Z);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfPostFX_SetParameter4(IntPtr PostFX, string Name, float X, float Y, float Z, float W);
static extern void sfShader_SetParameter4(IntPtr Shader, string Name, float X, float Y, float Z, float W);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfPostFX_SetTexture(IntPtr PostFX, string Name, IntPtr Texture);
static extern void sfShader_SetTexture(IntPtr Shader, string Name, IntPtr Texture);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern bool sfPostFX_CanUsePostFX();
static extern void sfShader_Bind(IntPtr Shader);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfShader_Unbind(IntPtr Shader);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern bool sfShader_IsAvailable();
#endregion
}

View file

@ -366,10 +366,14 @@ namespace SFML
/// Render the object into the given render window
/// </summary>
/// <param name="target">Target render window</param>
/// <param name="shader">Shader to apply</param>
////////////////////////////////////////////////////////////
internal override void Render(RenderWindow target)
internal override void Render(RenderWindow target, Shader shader)
{
sfRenderWindow_DrawShape(target.This, This);
if (shader == null)
sfRenderWindow_DrawShape(target.This, This);
else
sfRenderWindow_DrawShapeWithShader(target.This, This, shader.This);
}
////////////////////////////////////////////////////////////
@ -377,10 +381,14 @@ namespace SFML
/// Render the object into the given render image
/// </summary>
/// <param name="target">Target render image</param>
/// <param name="shader">Shader to apply</param>
////////////////////////////////////////////////////////////
internal override void Render(RenderImage target)
internal override void Render(RenderImage target, Shader shader)
{
sfRenderImage_DrawShape(target.This, This);
if (shader == null)
sfRenderImage_DrawShape(target.This, This);
else
sfRenderImage_DrawShapeWithShader(target.This, This, shader.This);
}
////////////////////////////////////////////////////////////
@ -466,9 +474,15 @@ namespace SFML
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfRenderWindow_DrawShape(IntPtr This, IntPtr Shape);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfRenderWindow_DrawShapeWithShader(IntPtr This, IntPtr Shape, IntPtr Shader);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfRenderImage_DrawShape(IntPtr This, IntPtr Shape);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfRenderImage_DrawShapeWithShader(IntPtr This, IntPtr Shape, IntPtr Shader);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern IntPtr sfShape_CreateLine(float P1X, float P1Y, float P2X, float P2Y, float Thickness, Color Col, float Outline, Color OutlineCol);

View file

@ -220,10 +220,14 @@ namespace SFML
/// Render the object into the given render window
/// </summary>
/// <param name="target">Target render window</param>
/// <param name="shader">Shader to apply</param>
////////////////////////////////////////////////////////////
internal override void Render(RenderWindow target)
internal override void Render(RenderWindow target, Shader shader)
{
sfRenderWindow_DrawSprite(target.This, This);
if (shader == null)
sfRenderWindow_DrawSprite(target.This, This);
else
sfRenderWindow_DrawSpriteWithShader(target.This, This, shader.This);
}
////////////////////////////////////////////////////////////
@ -231,10 +235,14 @@ namespace SFML
/// Render the object into the given render image
/// </summary>
/// <param name="target">Target render image</param>
/// <param name="shader">Shader to apply</param>
////////////////////////////////////////////////////////////
internal override void Render(RenderImage target)
internal override void Render(RenderImage target, Shader shader)
{
sfRenderImage_DrawSprite(target.This, This);
if (shader == null)
sfRenderImage_DrawSprite(target.This, This);
else
sfRenderImage_DrawSpriteWithShader(target.This, This, shader.This);
}
////////////////////////////////////////////////////////////
@ -311,9 +319,15 @@ namespace SFML
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfRenderWindow_DrawSprite(IntPtr This, IntPtr Sprite);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfRenderWindow_DrawSpriteWithShader(IntPtr This, IntPtr Sprite, IntPtr Shader);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfRenderImage_DrawSprite(IntPtr This, IntPtr Sprite);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfRenderImage_DrawSpriteWithShader(IntPtr This, IntPtr Sprite, IntPtr Shader);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfSprite_Resize(IntPtr This, float Width, float Height);

View file

@ -261,10 +261,14 @@ namespace SFML
/// Render the object into the given render window
/// </summary>
/// <param name="target">Target render window</param>
/// <param name="shader">Shader to apply</param>
////////////////////////////////////////////////////////////
internal override void Render(RenderWindow target)
internal override void Render(RenderWindow target, Shader shader)
{
sfRenderWindow_DrawString(target.This, This);
if (shader == null)
sfRenderWindow_DrawString(target.This, This);
else
sfRenderWindow_DrawStringWithShader(target.This, This, shader.This);
}
////////////////////////////////////////////////////////////
@ -272,10 +276,14 @@ namespace SFML
/// Render the object into the given render image
/// </summary>
/// <param name="target">Target render image</param>
/// <param name="shader">Shader to apply</param>
////////////////////////////////////////////////////////////
internal override void Render(RenderImage target)
internal override void Render(RenderImage target, Shader shader)
{
sfRenderImage_DrawString(target.This, This);
if (shader == null)
sfRenderImage_DrawString(target.This, This);
else
sfRenderImage_DrawStringWithShader(target.This, This, shader.This);
}
////////////////////////////////////////////////////////////
@ -352,9 +360,15 @@ namespace SFML
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfRenderWindow_DrawString(IntPtr This, IntPtr String);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfRenderWindow_DrawStringWithShader(IntPtr This, IntPtr String, IntPtr Shader);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfRenderImage_DrawString(IntPtr This, IntPtr String);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfRenderImage_DrawStringWithShader(IntPtr This, IntPtr String, IntPtr Shader);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern float sfString_GetWidth(IntPtr This);

View file

@ -3,7 +3,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{46786269-57B9-48E7-AA4F-8F4D84609FE6}</ProjectGuid>
<OutputType>Library</OutputType>
@ -53,11 +53,11 @@
<Compile Include="Drawable.cs" />
<Compile Include="Font.cs" />
<Compile Include="Image.cs" />
<Compile Include="PostFx.cs" />
<Compile Include="Rect.cs" />
<Compile Include="RenderImage.cs" />
<Compile Include="RenderTarget.cs" />
<Compile Include="RenderWindow.cs" />
<Compile Include="Shader.cs" />
<Compile Include="Shape.cs" />
<Compile Include="Sprite.cs" />
<Compile Include="String2D.cs" />