public class Shader extends SFMLNativeObject implements ConstShader
| Modifier and Type | Class and Description |
|---|---|
static class |
Shader.CurrentTextureType
Special type denoting that the texture of the object being drawn
should be used, which cannot be known before it is actually being drawn.
|
static class |
Shader.Type
Enumeration of shader types.
|
| Modifier and Type | Field and Description |
|---|---|
static Shader.CurrentTextureType |
CURRENT_TEXTURE
Special value denoting that the texture of the object being drawn
should be used, which cannot be known before it is actually being drawn.
|
| Constructor and Description |
|---|
Shader()
Constructs a new shader.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
bind(ConstShader shader)
Activates a shader for rendering.
|
static boolean |
isAvailable()
Checks if shaders are available on this system.
|
void |
loadFromFile(Path vertexShaderFile,
Path fragmentShaderFile)
Attempts to load the shader from files.
|
void |
loadFromFile(Path path,
Shader.Type shaderType)
Attempts to load the shader from a file.
|
void |
loadFromSource(String source,
Shader.Type shaderType)
Attempts to load a shader from GLSL source code.
|
void |
loadFromSource(String vertexShaderSource,
String fragmentShaderSource)
Attempts to load a shader from GLSL source code.
|
void |
loadFromStream(InputStream vertexShaderIn,
InputStream fragmentShaderIn)
Fully loads all available bytes from an
InputStream
and attempts to load the shader from it. |
void |
loadFromStream(InputStream in,
Shader.Type shaderType)
Fully loads all available bytes from an
InputStream
and attempts to load the shader from it. |
protected long |
nativeCreate()
Deprecated.
|
protected void |
nativeDelete()
Deprecated.
|
protected void |
nativeSetExPtr()
Deprecated.
|
void |
setParameter(String name,
Color color)
Sets a color (vec4) parameter value in the shader.
|
void |
setParameter(String name,
ConstTexture texture)
Sets a texture (sampler2D) parameter value in the shader.
|
void |
setParameter(String name,
float value)
Sets a float parameter (
float) value in the shader. |
void |
setParameter(String name,
float x,
float y)
Sets a 2-component-float (
vec2) parameter value in the shader. |
void |
setParameter(String name,
float x,
float y,
float z)
Sets a 3-component-float (
vec3) parameter value in the shader. |
void |
setParameter(String name,
float x,
float y,
float z,
float w)
Sets a 4-component-float (
vec4) parameter value in the shader. |
void |
setParameter(String name,
Shader.CurrentTextureType currentTexture)
Sets a texture (sampler2D) parameter value in the shader to the texture
of the object being drawn in the moment the shader is applied.
|
void |
setParameter(String name,
Transform xform)
Sets a matrix (mat4) parameter value in the shader.
|
void |
setParameter(String name,
Vector2f v)
Sets a 2-component-float (
vec2) parameter value in the shader. |
void |
setParameter(String name,
Vector3f v)
Sets a 3-component-float (
vec3) parameter value in the shader. |
finalizepublic static final Shader.CurrentTextureType CURRENT_TEXTURE
public static void bind(ConstShader shader)
shader - the shader to activate, or null to indicate that no shader
is to be used.public static boolean isAvailable()
true if shaders are available, false otherwise.@Deprecated protected long nativeCreate()
SFMLNativeObjectnativeCreate in class SFMLNativeObject@Deprecated protected void nativeSetExPtr()
SFMLNativeObjectnativeSetExPtr in class SFMLNativeObject@Deprecated protected void nativeDelete()
SFMLNativeObjectnativeDelete in class SFMLNativeObjectpublic void loadFromSource(String source, Shader.Type shaderType) throws IOException, ShaderSourceException
source - the GLSL source code.shaderType - the shader type.IOException - in case an I/O error occurs.ShaderSourceException - in case the shader could not be compiled or linked.public void loadFromSource(String vertexShaderSource, String fragmentShaderSource) throws IOException, ShaderSourceException
vertexShaderSource - the vertex shader's GLSL source code.fragmentShaderSource - the fragment shader's GLSL source code.IOException - in case an I/O error occurs.ShaderSourceException - in case the shader could not be compiled or linked.public void loadFromStream(InputStream in, Shader.Type shaderType) throws IOException, ShaderSourceException
InputStream
and attempts to load the shader from it.in - the input stream to read from.shaderType - the shader type.IOException - in case an I/O error occurs.ShaderSourceException - in case the shader could not be compiled or linked.public void loadFromStream(InputStream vertexShaderIn, InputStream fragmentShaderIn) throws IOException, ShaderSourceException
InputStream
and attempts to load the shader from it.vertexShaderIn - the input stream to read the vertex shader from.fragmentShaderIn - the input stream to read the fragment shader from.IOException - in case an I/O error occurs.ShaderSourceException - in case the shader could not be compiled or linked.public void loadFromFile(Path path, Shader.Type shaderType) throws IOException, ShaderSourceException
path - the path to the file to load.shaderType - the shader type.IOException - in case an I/O error occurs.ShaderSourceException - in case the shader could not be compiled or linked.public void loadFromFile(Path vertexShaderFile, Path fragmentShaderFile) throws IOException, ShaderSourceException
vertexShaderFile - the path to the file to read the vertex shader from.fragmentShaderFile - the path to the file to read the fragment shader from.IOException - in case an I/O error occurs.ShaderSourceException - in case the shader could not be compiled or linked.public void setParameter(String name, float value)
float) value in the shader.name - the parameter's name.value - the parameter's value.public void setParameter(String name, float x, float y)
vec2) parameter value in the shader.name - the parameter's name.x - the parameter's value.y - the parameter's value.public void setParameter(String name, Vector2f v)
vec2) parameter value in the shader.name - the parameter's name.v - the parameter's value.public void setParameter(String name, float x, float y, float z)
vec3) parameter value in the shader.name - the parameter's name.x - the parameter's value.y - the parameter's value.z - the parameter's value.public void setParameter(String name, Vector3f v)
vec3) parameter value in the shader.name - the parameter's name.v - the parameter's value.public void setParameter(String name, float x, float y, float z, float w)
vec4) parameter value in the shader.name - the parameter's name.x - the parameter's value.y - the parameter's value.z - the parameter's value.w - the parameter's value.public void setParameter(String name, Color color)
name - the parameter's name.color - the parameter's value.public void setParameter(String name, Transform xform)
name - the parameter's name.xform - the parameter's value.public void setParameter(String name, ConstTexture texture)
name - the parameter's name.texture - the parameter's value.public void setParameter(String name, Shader.CurrentTextureType currentTexture)
name - the parameter's name.currentTexture - should be CURRENT_TEXTURE.