C# Class SFML.Graphics.Shader

Wrapper for pixel shaders
Inheritance: SFML.System.ObjectBase
Mostra file Open project: SFML/SFML.Net Class Usage Examples

Public Properties

Property Type Description
CurrentTexture CurrentTextureType

Public Methods

Method Description
Bind ( Shader shader ) : void

Bind a shader for rendering

FromString ( string vertexShader, string geometryShader, string fragmentShader ) : Shader

Load the vertex, geometry and fragment shaders from source code in memory

This function loads the vertex, geometry and fragment shaders. Pass NULL if you don't want to load a specific shader. The sources must be valid shaders in GLSL language. GLSL is a C-like language dedicated to OpenGL shaders; you'll probably need to read a good documentation for it before writing your own shaders.

SetUniform ( string name, CurrentTextureType current ) : void

Specify current texture as \p sampler2D uniform

This overload maps a shader texture variable to the texture of the object being drawn, which cannot be known in advance. The second argument must be CurrentTexture. The corresponding parameter in the shader must be a 2D texture (sampler2D GLSL type).

Example: uniform sampler2D current; // this is the variable in the shader shader.setUniform("current", Shader.CurrentTexture);

SetUniform ( string name, Glsl vector ) : void

Specify value for vec2 uniform

SetUniform ( string name, Texture texture ) : void

Specify a texture as sampler2D uniform

name is the name of the variable to change in the shader. The corresponding parameter in the shader must be a 2D texture (sampler2D GLSL type).

Example: uniform sampler2D the_texture; // this is the variable in the shader sf::Texture texture; ... shader.setUniform("the_texture", texture); It is important to note that texture must remain alive as long as the shader uses it, no copy is made internally.

To use the texture of the object being drawn, which cannot be known in advance, you can pass the special value Shader.CurrentTexture: shader.setUniform("the_texture", Shader.CurrentTexture);

SetUniform ( string name, bool x ) : void

Specify value for bool uniform

SetUniform ( string name, float x ) : void

Specify value for float uniform

SetUniform ( string name, int x ) : void

Specify value for int uniform

SetUniformArray ( string name, Glsl array ) : void

Specify values for vec2[] array uniforms

SetUniformArray ( string name, float array ) : void

Specify values for float[] array uniforms

Shader ( IntPtr ptr ) : System

Construct the shader from a pointer

Shader ( Stream vertexShaderStream, Stream geometryShaderStream, Stream fragmentShaderStream ) : System

Load the vertex, geometry and fragment shaders from custom streams

This function loads the vertex, geometry and fragment shaders. Pass NULL if you don't want to load a specific shader. The sources must be valid shaders in GLSL language. GLSL is a C-like language dedicated to OpenGL shaders; you'll probably need to read a good documentation for it before writing your own shaders.

Shader ( string vertexShaderFilename, string geometryShaderFilename, string fragmentShaderFilename ) : System

Load the vertex, geometry and fragment shaders from files

This function loads the vertex, geometry and fragment shaders. Pass NULL if you don't want to load a specific shader. The sources must be text files containing valid shaders in GLSL language. GLSL is a C-like language dedicated to OpenGL shaders; you'll probably need to read a good documentation for it before writing your own shaders.

ToString ( ) : string

Provide a string describing the object

Protected Methods

Method Description
Destroy ( bool disposing ) : void

Handle the destruction of the object

Private Methods

Method Description
SetParameter ( string name, System.Color color ) : void
SetParameter ( string name, CurrentTextureType current ) : void
SetParameter ( string name, Texture texture ) : void
SetParameter ( string name, Transform transform ) : void
SetParameter ( string name, Vector2f vector ) : void
SetParameter ( string name, float x ) : void
SetParameter ( string name, float x, float y ) : void
SetParameter ( string name, float x, float y, float z ) : void
SetParameter ( string name, float x, float y, float z, float w ) : void
sfShader_bind ( IntPtr shader ) : void
sfShader_createFromFile ( string vertexShaderFilename, string geometryShaderFilename, string fragmentShaderFilename ) : IntPtr
sfShader_createFromMemory ( string vertexShader, string geometryShader, string fragmentShader ) : IntPtr
sfShader_createFromStream ( IntPtr vertexShaderStream, IntPtr geometryShaderStream, IntPtr fragmentShaderStream ) : IntPtr
sfShader_destroy ( IntPtr shader ) : void
sfShader_getNativeHandle ( IntPtr shader ) : uint
sfShader_isAvailable ( ) : bool
sfShader_isGeometryAvailable ( ) : bool
sfShader_setBoolUniform ( IntPtr shader, string name, bool x ) : void
sfShader_setBvec2Uniform ( IntPtr shader, string name, Glsl vector ) : void
sfShader_setBvec3Uniform ( IntPtr shader, string name, Glsl vector ) : void
sfShader_setBvec4Uniform ( IntPtr shader, string name, Glsl vector ) : void
sfShader_setColorParameter ( IntPtr shader, string name, System.Color color ) : void
sfShader_setCurrentTextureParameter ( IntPtr shader, string name ) : void
sfShader_setCurrentTextureUniform ( IntPtr shader, string name ) : void
sfShader_setFloat2Parameter ( IntPtr shader, string name, float x, float y ) : void
sfShader_setFloat3Parameter ( IntPtr shader, string name, float x, float y, float z ) : void
sfShader_setFloat4Parameter ( IntPtr shader, string name, float x, float y, float z, float w ) : void
sfShader_setFloatParameter ( IntPtr shader, string name, float x ) : void
sfShader_setFloatUniform ( IntPtr shader, string name, float x ) : void
sfShader_setFloatUniformArray ( IntPtr shader, string name, float data, uint length ) : void
sfShader_setIntUniform ( IntPtr shader, string name, int x ) : void
sfShader_setIvec2Uniform ( IntPtr shader, string name, Glsl vector ) : void
sfShader_setIvec3Uniform ( IntPtr shader, string name, Glsl vector ) : void
sfShader_setIvec4Uniform ( IntPtr shader, string name, Glsl vector ) : void
sfShader_setMat3Uniform ( IntPtr shader, string name, Glsl matrix ) : void
sfShader_setMat3UniformArray ( IntPtr shader, string name, Glsl data, uint length ) : void
sfShader_setMat4Uniform ( IntPtr shader, string name, Glsl matrix ) : void
sfShader_setMat4UniformArray ( IntPtr shader, string name, Glsl data, uint length ) : void
sfShader_setTextureParameter ( IntPtr shader, string name, IntPtr texture ) : void
sfShader_setTextureUniform ( IntPtr shader, string name, IntPtr texture ) : void
sfShader_setTransformParameter ( IntPtr shader, string name, Transform transform ) : void
sfShader_setVec2Uniform ( IntPtr shader, string name, Glsl vector ) : void
sfShader_setVec2UniformArray ( IntPtr shader, string name, Glsl data, uint length ) : void
sfShader_setVec3Uniform ( IntPtr shader, string name, Glsl vector ) : void
sfShader_setVec3UniformArray ( IntPtr shader, string name, Glsl data, uint length ) : void
sfShader_setVec4Uniform ( IntPtr shader, string name, Glsl vector ) : void
sfShader_setVec4UniformArray ( IntPtr shader, string name, Glsl data, uint length ) : void

Method Details

Bind() public static method

Bind a shader for rendering
public static Bind ( Shader shader ) : void
shader Shader Shader to bind (can be null to use no shader)
return void

Destroy() protected method

Handle the destruction of the object
protected Destroy ( bool disposing ) : void
disposing bool Is the GC disposing the object, or is it an explicit call ?
return void

FromString() public static method

Load the vertex, geometry and fragment shaders from source code in memory
This function loads the vertex, geometry and fragment shaders. Pass NULL if you don't want to load a specific shader. The sources must be valid shaders in GLSL language. GLSL is a C-like language dedicated to OpenGL shaders; you'll probably need to read a good documentation for it before writing your own shaders.
public static FromString ( string vertexShader, string geometryShader, string fragmentShader ) : Shader
vertexShader string String containing the source code of the vertex shader
geometryShader string String containing the source code of the geometry shader
fragmentShader string String containing the source code of the fragment shader
return Shader

SetUniform() public method

Specify current texture as \p sampler2D uniform

This overload maps a shader texture variable to the texture of the object being drawn, which cannot be known in advance. The second argument must be CurrentTexture. The corresponding parameter in the shader must be a 2D texture (sampler2D GLSL type).

Example: uniform sampler2D current; // this is the variable in the shader shader.setUniform("current", Shader.CurrentTexture);

public SetUniform ( string name, CurrentTextureType current ) : void
name string Name of the texture in the shader
current CurrentTextureType
return void

SetUniform() public method

Specify value for vec2 uniform
public SetUniform ( string name, Glsl vector ) : void
name string Name of the uniform variable in GLSL
vector Glsl Value of the vec2 vector
return void

SetUniform() public method

Specify a texture as sampler2D uniform

name is the name of the variable to change in the shader. The corresponding parameter in the shader must be a 2D texture (sampler2D GLSL type).

Example: uniform sampler2D the_texture; // this is the variable in the shader sf::Texture texture; ... shader.setUniform("the_texture", texture); It is important to note that texture must remain alive as long as the shader uses it, no copy is made internally.

To use the texture of the object being drawn, which cannot be known in advance, you can pass the special value Shader.CurrentTexture: shader.setUniform("the_texture", Shader.CurrentTexture);

public SetUniform ( string name, Texture texture ) : void
name string Name of the texture in the shader
texture Texture Texture to assign
return void

SetUniform() public method

Specify value for bool uniform
public SetUniform ( string name, bool x ) : void
name string Name of the uniform variable in GLSL
x bool Value of the bool scalar
return void

SetUniform() public method

Specify value for float uniform
public SetUniform ( string name, float x ) : void
name string Name of the uniform variable in GLSL
x float Value of the float scalar
return void

SetUniform() public method

Specify value for int uniform
public SetUniform ( string name, int x ) : void
name string Name of the uniform variable in GLSL
x int Value of the int scalar
return void

SetUniformArray() public method

Specify values for vec2[] array uniforms
public SetUniformArray ( string name, Glsl array ) : void
name string Name of the uniform variable in GLSL
array Glsl array of vec2 values
return void

SetUniformArray() public method

Specify values for float[] array uniforms
public SetUniformArray ( string name, float array ) : void
name string Name of the uniform variable in GLSL
array float array of float values
return void

Shader() public method

Construct the shader from a pointer
public Shader ( IntPtr ptr ) : System
ptr System.IntPtr Pointer to the shader instance
return System

Shader() public method

Load the vertex, geometry and fragment shaders from custom streams
This function loads the vertex, geometry and fragment shaders. Pass NULL if you don't want to load a specific shader. The sources must be valid shaders in GLSL language. GLSL is a C-like language dedicated to OpenGL shaders; you'll probably need to read a good documentation for it before writing your own shaders.
public Shader ( Stream vertexShaderStream, Stream geometryShaderStream, Stream fragmentShaderStream ) : System
vertexShaderStream Stream Source stream to read the vertex shader from, or null to skip this shader
geometryShaderStream Stream Source stream to read the geometry shader from, or null to skip this shader
fragmentShaderStream Stream Source stream to read the fragment shader from, or null to skip this shader
return System

Shader() public method

Load the vertex, geometry and fragment shaders from files
This function loads the vertex, geometry and fragment shaders. Pass NULL if you don't want to load a specific shader. The sources must be text files containing valid shaders in GLSL language. GLSL is a C-like language dedicated to OpenGL shaders; you'll probably need to read a good documentation for it before writing your own shaders.
public Shader ( string vertexShaderFilename, string geometryShaderFilename, string fragmentShaderFilename ) : System
vertexShaderFilename string Path of the vertex shader file to load, or null to skip this shader
geometryShaderFilename string Path of the geometry shader file to load, or null to skip this shader
fragmentShaderFilename string Path of the fragment shader file to load, or null to skip this shader
return System

ToString() public method

Provide a string describing the object
public ToString ( ) : string
return string

Property Details

CurrentTexture public_oe static_oe property

Special value that can be passed to SetParameter, and that represents the texture of the object being drawn
public static CurrentTextureType CurrentTexture
return CurrentTextureType