Package ch.bailu.gtk.gsk
Klasse GLShader
java.lang.Object
ch.bailu.gtk.type.Type
ch.bailu.gtk.type.Pointer
ch.bailu.gtk.gobject.Object
ch.bailu.gtk.type.PropertyHolder
ch.bailu.gtk.gsk.GLShader
- Alle implementierten Schnittstellen:
PointerInterface
A `GskGLShader` is a snippet of GLSL that is meant to run in the
fragment shader of the rendering pipeline.
A fragment shader gets the coordinates being rendered as input and
produces the pixel values for that particular pixel. Additionally,
the shader can declare a set of other input arguments, called
uniforms (as they are uniform over all the calls to your shader in
each instance of use). A shader can also receive up to 4
textures that it can use as input when producing the pixel data.
`GskGLShader` is usually used with gtk_snapshot_push_gl_shader()
to produce a [class@Gsk.GLShaderNode] in the rendering hierarchy,
and then its input textures are constructed by rendering the child
nodes to textures before rendering the shader node itself. (You can
pass texture nodes as children if you want to directly use a texture
as input).
The actual shader code is GLSL code that gets combined with
some other code into the fragment shader. Since the exact
capabilities of the GPU driver differs between different OpenGL
drivers and hardware, GTK adds some defines that you can use
to ensure your GLSL code runs on as many drivers as it can.
If the OpenGL driver is GLES, then the shader language version
is set to 100, and GSK_GLES will be defined in the shader.
Otherwise, if the OpenGL driver does not support the 3.2 core profile,
then the shader will run with language version 110 for GL2 and 130 for GL3,
and GSK_LEGACY will be defined in the shader.
If the OpenGL driver supports the 3.2 code profile, it will be used,
the shader language version is set to 150, and GSK_GL3 will be defined
in the shader.
The main function the shader must implement is:
```glsl
void mainImage(out vec4 fragColor,
in vec2 fragCoord,
in vec2 resolution,
in vec2 uv)
```
Where the input @fragCoord is the coordinate of the pixel we're
currently rendering, relative to the boundary rectangle that was
specified in the `GskGLShaderNode`, and @resolution is the width and
height of that rectangle. This is in the typical GTK coordinate
system with the origin in the top left. @uv contains the u and v
coordinates that can be used to index a texture at the
corresponding point. These coordinates are in the [0..1]x[0..1]
region, with 0, 0 being in the lower left corder (which is typical
for OpenGL).
The output @fragColor should be a RGBA color (with
premultiplied alpha) that will be used as the output for the
specified pixel location. Note that this output will be
automatically clipped to the clip region of the glshader node.
In addition to the function arguments the shader can define
up to 4 uniforms for textures which must be called u_textureN
(i.e. u_texture1 to u_texture4) as well as any custom uniforms
you want of types int, uint, bool, float, vec2, vec3 or vec4.
All textures sources contain premultiplied alpha colors, but if some
there are outer sources of colors there is a gsk_premultiply() helper
to compute premultiplication when needed.
Note that GTK parses the uniform declarations, so each uniform has to
be on a line by itself with no other code, like so:
```glsl
uniform float u_time;
uniform vec3 u_color;
uniform sampler2D u_texture1;
uniform sampler2D u_texture2;
```
GTK uses the "gsk" namespace in the symbols it uses in the
shader, so your code should not use any symbols with the prefix gsk
or GSK. There are some helper functions declared that you can use:
```glsl
vec4 GskTexture(sampler2D sampler, vec2 texCoords);
```
This samples a texture (e.g. u_texture1) at the specified
coordinates, and contains some helper ifdefs to ensure that
it works on all OpenGL versions.
You can compile the shader yourself using [method@Gsk.GLShader.compile],
otherwise the GSK renderer will do it when it handling the glshader
node. If errors occurs, the returned @error will include the glsl
sources, so you can see what GSK was passing to the compiler. You
can also set GSK_DEBUG=shaders in the environment to see the sources
and other relevant information about all shaders that GSK is handling.
# An example shader
```glsl
uniform float position;
uniform sampler2D u_texture1;
uniform sampler2D u_texture2;
void mainImage(out vec4 fragColor,
in vec2 fragCoord,
in vec2 resolution,
in vec2 uv) {
vec4 source1 = GskTexture(u_texture1, uv);
vec4 source2 = GskTexture(u_texture2, uv);
fragColor = position * source1 + (1.0 - position) * source2;
}
```
fragment shader of the rendering pipeline.
A fragment shader gets the coordinates being rendered as input and
produces the pixel values for that particular pixel. Additionally,
the shader can declare a set of other input arguments, called
uniforms (as they are uniform over all the calls to your shader in
each instance of use). A shader can also receive up to 4
textures that it can use as input when producing the pixel data.
`GskGLShader` is usually used with gtk_snapshot_push_gl_shader()
to produce a [class@Gsk.GLShaderNode] in the rendering hierarchy,
and then its input textures are constructed by rendering the child
nodes to textures before rendering the shader node itself. (You can
pass texture nodes as children if you want to directly use a texture
as input).
The actual shader code is GLSL code that gets combined with
some other code into the fragment shader. Since the exact
capabilities of the GPU driver differs between different OpenGL
drivers and hardware, GTK adds some defines that you can use
to ensure your GLSL code runs on as many drivers as it can.
If the OpenGL driver is GLES, then the shader language version
is set to 100, and GSK_GLES will be defined in the shader.
Otherwise, if the OpenGL driver does not support the 3.2 core profile,
then the shader will run with language version 110 for GL2 and 130 for GL3,
and GSK_LEGACY will be defined in the shader.
If the OpenGL driver supports the 3.2 code profile, it will be used,
the shader language version is set to 150, and GSK_GL3 will be defined
in the shader.
The main function the shader must implement is:
```glsl
void mainImage(out vec4 fragColor,
in vec2 fragCoord,
in vec2 resolution,
in vec2 uv)
```
Where the input @fragCoord is the coordinate of the pixel we're
currently rendering, relative to the boundary rectangle that was
specified in the `GskGLShaderNode`, and @resolution is the width and
height of that rectangle. This is in the typical GTK coordinate
system with the origin in the top left. @uv contains the u and v
coordinates that can be used to index a texture at the
corresponding point. These coordinates are in the [0..1]x[0..1]
region, with 0, 0 being in the lower left corder (which is typical
for OpenGL).
The output @fragColor should be a RGBA color (with
premultiplied alpha) that will be used as the output for the
specified pixel location. Note that this output will be
automatically clipped to the clip region of the glshader node.
In addition to the function arguments the shader can define
up to 4 uniforms for textures which must be called u_textureN
(i.e. u_texture1 to u_texture4) as well as any custom uniforms
you want of types int, uint, bool, float, vec2, vec3 or vec4.
All textures sources contain premultiplied alpha colors, but if some
there are outer sources of colors there is a gsk_premultiply() helper
to compute premultiplication when needed.
Note that GTK parses the uniform declarations, so each uniform has to
be on a line by itself with no other code, like so:
```glsl
uniform float u_time;
uniform vec3 u_color;
uniform sampler2D u_texture1;
uniform sampler2D u_texture2;
```
GTK uses the "gsk" namespace in the symbols it uses in the
shader, so your code should not use any symbols with the prefix gsk
or GSK. There are some helper functions declared that you can use:
```glsl
vec4 GskTexture(sampler2D sampler, vec2 texCoords);
```
This samples a texture (e.g. u_texture1) at the specified
coordinates, and contains some helper ifdefs to ensure that
it works on all OpenGL versions.
You can compile the shader yourself using [method@Gsk.GLShader.compile],
otherwise the GSK renderer will do it when it handling the glshader
node. If errors occurs, the returned @error will include the glsl
sources, so you can see what GSK was passing to the compiler. You
can also set GSK_DEBUG=shaders in the environment to see the sources
and other relevant information about all shaders that GSK is handling.
# An example shader
```glsl
uniform float position;
uniform sampler2D u_texture1;
uniform sampler2D u_texture2;
void mainImage(out vec4 fragColor,
in vec2 fragCoord,
in vec2 resolution,
in vec2 uv) {
vec4 source1 = GskTexture(u_texture1, uv);
vec4 source2 = GskTexture(u_texture2, uv);
fragColor = position * source1 + (1.0 - position) * source2;
}
```
-
Verschachtelte Klassen - Übersicht
Von Klasse geerbte verschachtelte Klassen/Schnittstellen ch.bailu.gtk.gobject.Object
Object.OnBindingTransformFunc, Object.OnDestroyNotify, Object.OnDuplicateFunc, Object.OnNotify, Object.OnToggleNotify, Object.OnWeakNotify
-
Feldübersicht
Von Klasse geerbte Felder ch.bailu.gtk.gobject.Object
SIGNAL_ON_NOTIFY
-
Konstruktorübersicht
Konstruktoren -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungboolean
Veraltet.int
findUniformByName
(Str name) Veraltet.int
findUniformByName
(String name) Veraltet.formatArgs
(Object... _ellipsis) Veraltet.boolean
getArgBool
(Bytes args, int idx) Veraltet.float
getArgFloat
(Bytes args, int idx) Veraltet.int
Veraltet.long
Veraltet.int
getArgUint
(Bytes args, int idx) Veraltet.void
getArgVec2
(Bytes args, int idx, Vec2 out_value) Veraltet.void
getArgVec3
(Bytes args, int idx, Vec3 out_value) Veraltet.void
getArgVec4
(Bytes args, int idx, Vec4 out_value) Veraltet.static ClassHandler
static int
int
Veraltet.int
Veraltet.static long
static TypeSystem.TypeSize
Veraltet.Veraltet.static long
static TypeSystem.TypeSize
getUniformName
(int idx) Veraltet.int
getUniformOffset
(int idx) Veraltet.int
getUniformType
(int idx) Veraltet.static GLShader
newFromBytesGLShader
(Bytes sourcecode) Veraltet.static GLShader
newFromResourceGLShader
(Str resource_path) Veraltet.static GLShader
newFromResourceGLShader
(String resource_path) Veraltet.Von Klasse geerbte Methoden ch.bailu.gtk.type.PropertyHolder
getBooleanProperty, getIntProperty, getObjectProperty, getStringProperty, getStrProperty, setBooleanProperty, setIntProperty, setObjectProperty, setStringProperty, setStrProperty
Von Klasse geerbte Methoden ch.bailu.gtk.gobject.Object
addToggleRef, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, disconnect, disconnect, dupData, dupData, dupQdata, forceFloating, freezeNotify, get, get, getData, getData, getProperty, getProperty, getQdata, interfaceFindProperty, interfaceInstallProperty, isFloating, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, replaceData, replaceData, replaceQdata, runDispose, set, set, setData, setData, setDataFull, setDataFull, setProperty, setProperty, setQdata, setQdataFull, stealData, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref
Von Klasse geerbte Methoden ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Von Klasse geerbte Methoden ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Von Klasse geerbte Methoden java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Von Schnittstelle geerbte Methoden ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Konstruktordetails
-
GLShader
-
-
Methodendetails
-
getClassHandler
-
newFromBytesGLShader
Veraltet.Creates a `GskGLShader` that will render pixels using the specified code.- Parameter:
sourcecode
- GLSL sourcecode for the shader, as a `GBytes`- Gibt zurück:
- A new `GskGLShader`
-
newFromResourceGLShader
Veraltet.Creates a `GskGLShader` that will render pixels using the specified code.- Parameter:
resource_path
- path to a resource that contains the GLSL sourcecode for the shader- Gibt zurück:
- A new `GskGLShader`
-
newFromResourceGLShader
Veraltet.Creates a `GskGLShader` that will render pixels using the specified code.- Parameter:
resource_path
- path to a resource that contains the GLSL sourcecode for the shader- Gibt zurück:
- A new `GskGLShader`
-
compile
Veraltet.Tries to compile the @shader for the given @renderer.
If there is a problem, this function returns %FALSE and reports
an error. You should use this function before relying on the shader
for rendering and use a fallback with a simpler shader or without
shaders if it fails.
Note that this will modify the rendering state (for example
change the current GL context) and requires the renderer to be
set up. This means that the widget has to be realized. Commonly you
want to call this from the realize signal of a widget, or during
widget snapshot.- Parameter:
renderer
- a `GskRenderer`- Gibt zurück:
- %TRUE on success, %FALSE if an error occurred
- Löst aus:
AllocationError
-
findUniformByName
Veraltet.Looks for a uniform by the name @name, and returns the index
of the uniform, or -1 if it was not found.- Parameter:
name
- uniform name- Gibt zurück:
- The index of the uniform, or -1
-
findUniformByName
Veraltet.Looks for a uniform by the name @name, and returns the index
of the uniform, or -1 if it was not found.- Parameter:
name
- uniform name- Gibt zurück:
- The index of the uniform, or -1
-
formatArgs
Veraltet.Formats the uniform data as needed for feeding the named uniforms
values into the shader.
The argument list is a list of pairs of names, and values for the types
that match the declared uniforms (i.e. double/int/guint/gboolean for
primitive values and `graphene_vecN_t *` for vecN uniforms).
Any uniforms of the shader that are not included in the argument list
are zero-initialized.- Parameter:
_ellipsis
- name-Value pairs for the uniforms of @shader, ending with a %NULL name- Gibt zurück:
- A newly allocated block of data which can be passed to [ctor@Gsk.GLShaderNode.new].
-
getArgBool
Veraltet.Gets the value of the uniform @idx in the @args block.
The uniform must be of bool type.- Parameter:
args
- uniform argumentsidx
- index of the uniform- Gibt zurück:
- The value
-
getArgFloat
Veraltet.Gets the value of the uniform @idx in the @args block.
The uniform must be of float type.- Parameter:
args
- uniform argumentsidx
- index of the uniform- Gibt zurück:
- The value
-
getArgInt
Veraltet.Gets the value of the uniform @idx in the @args block.
The uniform must be of int type.- Parameter:
args
- uniform argumentsidx
- index of the uniform- Gibt zurück:
- The value
-
getArgUint
Veraltet.Gets the value of the uniform @idx in the @args block.
The uniform must be of uint type.- Parameter:
args
- uniform argumentsidx
- index of the uniform- Gibt zurück:
- The value
-
getArgVec2
Veraltet.Gets the value of the uniform @idx in the @args block.
The uniform must be of vec2 type.- Parameter:
args
- uniform argumentsidx
- index of the uniformout_value
- location to store the uniform value in
-
getArgVec3
Veraltet.Gets the value of the uniform @idx in the @args block.
The uniform must be of vec3 type.- Parameter:
args
- uniform argumentsidx
- index of the uniformout_value
- location to store the uniform value in
-
getArgVec4
Veraltet.Gets the value of the uniform @idx in the @args block.
The uniform must be of vec4 type.- Parameter:
args
- uniform argumentsidx
- index of the uniformout_value
- location to store set the uniform value in
-
getArgsSize
Veraltet.Get the size of the data block used to specify arguments for this shader.- Gibt zurück:
- The size of the data block
-
getNTextures
Veraltet.Returns the number of textures that the shader requires.
This can be used to check that the a passed shader works
in your usecase. It is determined by looking at the highest
u_textureN value that the shader defines.- Gibt zurück:
- The number of texture inputs required by @shader
-
getNUniforms
Veraltet.Get the number of declared uniforms for this shader.- Gibt zurück:
- The number of declared uniforms
-
getResource
Veraltet.Gets the resource path for the GLSL sourcecode being used
to render this shader.- Gibt zurück:
- The resource path for the shader
-
getSource
Veraltet.Gets the GLSL sourcecode being used to render this shader.- Gibt zurück:
- The source code for the shader
-
getUniformName
Veraltet.Get the name of the declared uniform for this shader at index @idx.- Parameter:
idx
- index of the uniform- Gibt zurück:
- The name of the declared uniform
-
getUniformOffset
Veraltet.Get the offset into the data block where data for this uniforms is stored.- Parameter:
idx
- index of the uniform- Gibt zurück:
- The data offset
-
getUniformType
Veraltet.Get the type of the declared uniform for this shader at index @idx.- Parameter:
idx
- index of the uniform- Gibt zurück:
- The type of the declared uniform
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-