OGLInlineShader (object)¶
バージョン 1.12.0 で追加.
The OGLInlineShader implements the InlineShader interface. It allows the user to specify the GLSL vertex as well as fragment shader code directly in KL. This means also that you can pipe the GLSL shader code from an external editor, a string port etc directly for iterative shader development.
/*
** Example: OGLInlineShader
*/
require InlineDrawing;
operator entry() {
InlineDrawing draw = OGLInlineDrawing();
InlineShader shader = OGLInlineShader(
"flat",
"
#version 120 // We require OpenGL 2.1 for InlineDrawing, which supports GLSL 1.2
uniform mat4 u_viewMatrix;
uniform mat4 u_projection;
uniform mat4 u_modelMatrix;
attribute vec4 positions;
void main(){
gl_Position = u_projection * (u_viewMatrix * (u_modelMatrix * positions));
}
", "
#version 120 // We require OpenGL 2.1 for InlineDrawing, which supports GLSL 1.2
uniform vec4 u_materialColor;
uniform float u_time;
void main(){
gl_FragColor = u_materialColor * u_time;
}
");
shader.defineUniform(InlineUniform("u_viewMatrix", Mat44()));
shader.defineUniform(InlineUniform("u_projection", Mat44()));
shader.defineUniform(InlineUniform("u_modelMatrix", Mat44()));
shader.defineUniform(InlineUniform("u_materialColor", Color(1.0, 0.0, 0.0)));
shader.defineUniform(InlineUniform("u_time", 0.0));
shader.defineAttribute('positions', "Vec3");
}
/*
** Output:
*/
Methods¶
Methods in detail¶
OGLInlineShader ( in OGLInlineShader other )
copy constructor
OGLInlineShader ( in String name )
constructor using just the name
OGLInlineShader ( in String name, in String vertexCode, in String fragmentCode )
default constructor taking a name for the shader as well as vertex and fragment code
default constructor
Boolean OGLInlineShader.bindUniformToLocation! ( io DrawContext context, in InlineUniform uniform, in Integer location )
draws a uniform for the shader, applies the value essentially. this particular method avoid the lookup of the location by name and draws the uniform directly
Boolean OGLInlineShader.clear! ()
clears all of the materials
OGLInlineShader OGLInlineShader.clone? ()
clone method
OGLInlineShader.defineAttribute! ( in String name, in String attributeType )
define a surface attribute with a given name and type
OGLInlineShader.defineUniform! ( in InlineUniform uniform )
define a new uniform on the shader. the uniformType is auxiliary and can be used within the shader later if required.
OGLInlineShader.disableVertexAttribs? ( io DrawContext context )
disable all the vertex data for the next shader to run...
Size OGLInlineShader.getAttributeCount? ()
returns the number of attributes
Integer OGLInlineShader.getAttributeID? ( in String name )
returns true if this shader has an attribute with a given name
String OGLInlineShader.getAttributeName? ( in Index index )
returns the name of an attribute
String OGLInlineShader.getAttributeType? ( in Index index )
returns the type of an attribute
String OGLInlineShader.getFragmentCode? ()
returns the fragment GLSL code
String OGLInlineShader.getGeometryCode? ()
returns the geometry GLSL code
InlineMaterial OGLInlineShader.getMaterial? ( in Index index )
returns an existing material by index
Size OGLInlineShader.getMaterialCount? ()
returns the number of materials in this shader
InlineMaterial OGLInlineShader.getOrCreateMaterial! ( in String name )
returns (and eventually creates) a new matching material with a given name
String[String] OGLInlineShader.getPreprocessorStatements? ()
returns all preprocessor statements
String OGLInlineShader.getTesselationControlCode? ()
returns the tessellation control GLSL code
String OGLInlineShader.getTesselationEvaluateCode? ()
returns the tessellation evaluate GLSL code
String OGLInlineShader.getVertexCode? ()
returns the vertex GLSL code
Boolean OGLInlineShader.hasAttribute? ( in String name )
returns the ID / location of a given attribute inside the shader.
Boolean OGLInlineShader.hasMaterial? ( in String name )
returns true if this shader has a material with a given name
Boolean OGLInlineShader.hasUniform? ( in String name )
returns true if this shader has a uniform with a given name
OGLInlineShader.init! ( in String name, in String vertexCode, in String fragmentCode )
default constructor taking a name for the shader as well as vertex and fragment code
Boolean OGLInlineShader.removeMaterial! ( in String name )
returns (and eventually creates) a new matching material with a given name
OGLInlineShader.removePreprocessorStatement! ( in String name )
removes a single preprocessor statement
OGLInlineShader.setCodeFromFile! ( in String shaderName, in String filePath )
set one of the shaders code from file
OGLInlineShader.setFragmentCode! ( in String fragmentCode )
update the fragment GLSL code
OGLInlineShader.setGeometryCode! ( in String geometryCode )
update the geometry GLSL code
OGLInlineShader.setPreprocessorStatement! ( in String name, in String value )
sets a single preprocessor statement
OGLInlineShader.setTesselationCode! ( in String controlCode, in String evaluateCode )
update the geometry GLSL code
OGLInlineShader.setUniform! ( in InlineUniform uniform )
sets the global value of a uniform this can be changed per material, per instance or even per transform
OGLInlineShader.setVertexCode! ( in String vertexCode )
update the vertex GLSL code
~ OGLInlineShader ()
default destructor will try to delete the GLSL program