|
| Args () |
| Defaults: triangle primitive, 1 instance, 3 vertices per patch, computeGridDim(0,0,0), and uses G3D Args. More...
|
|
void | append (const UniformTable &other, const String &prefix="") |
|
Sets all arguments from other on this. More...
|
|
void | append (const shared_ptr< UniformTable > &other, const String &prefix="") |
|
void | appendIndexStream (const IndexStream &indexStream) |
| Specify an index stream to append in a multidraw call. More...
|
|
void | appendToPreamble (const String &extra) |
|
void | clearAttributeAndIndexBindings () |
|
void | clearAttributeArgs () |
|
void | clearUniform (const String &s) |
|
void | clearUniformBindings () |
|
const Vector3int32 & | computeGroupSize () const |
|
void | enableG3DArgs (bool enable) |
| If true, G3D will set and bind its default arguments, including many matrix uniforms and macro variables. More...
|
|
const Vector3int32 & | getComputeGridDim () const |
|
const IndexStream & | getIndexStream () const |
|
More...
|
|
const IndexStream & | getIndices () const |
|
More...
|
|
bool | getMacro (const String &name, String &value) const |
| Get the value of the macro arg name, and return its value in value, returns true if the macro arg exists. More...
|
|
PrimitiveType | getPrimitiveType () const |
|
const Rect2D & | getRect () const |
|
float | getRectZCoord () const |
|
const Rect2D & | getTexCoordRect () const |
|
const GPUAttributeTable & | gpuAttributeTable () const |
|
bool | hasComputeGrid () const |
| True if there is a nonzero compute grid set. More...
|
|
bool | hasGPUIndexStream () const |
| If this is true, it is invalid to set any CPU index streams, an indirect buffer, or a compute grid. More...
|
|
bool | hasIndirectBuffer () const |
| If this is true, it is invalid to set any index streams or a compute grid. More...
|
|
bool | hasPreambleOrMacros () const |
|
bool | hasRect () const |
|
bool | hasStreamArgs () const |
| If this is true, it is invalid to set a compute grid or and cpu attribute arrays/indexstreams. More...
|
|
bool | hasUniform (const String &s) const |
|
const Array< int > & | indexCountArray () const |
|
const Array< int > & | indexOffsetArray () const |
|
const IndexStream & | indexStream () const |
|
const Array< IndexStream > & | indexStreamArray () const |
|
const shared_ptr< GLPixelTransferBuffer > & | indirectBuffer () const |
|
size_t | indirectOffset () const |
|
String | macro (const String &name) const |
| Returns the empty string if the macro is not bound. More...
|
|
int | numIndices () const |
| If the index array has size > 0, returns its size, otherwise, returns the length of the shortest attached vertex attribute stream (0 if there are none) or the value set by an explicit call to setNumIndices. More...
|
|
int | numInstances () const |
|
String | preamble () const |
|
String | preambleAndMacroString () const |
| The preamble with macro arg definitions appended. More...
|
|
const Rect2D & | rect () const |
|
void | setArrayUniform (const String &name, int index, const shared_ptr< BindlessTextureHandle > &val, bool optional=false) |
|
void | setArrayUniform (const String &name, int index, int val, bool optional=false) |
|
void | setArrayUniform (const String &name, int index, float val, bool optional=false) |
|
void | setArrayUniform (const String &name, int index, const Vector2 &val, bool optional=false) |
|
void | setArrayUniform (const String &name, int index, const Vector3 &val, bool optional=false) |
|
void | setArrayUniform (const String &name, int index, const Vector4 &val, bool optional=false) |
|
void | setArrayUniform (const String &name, int index, const Color1 &val, bool optional=false) |
|
void | setArrayUniform (const String &name, int index, const Color3 &val, bool optional=false) |
|
void | setArrayUniform (const String &name, int index, const Color4 &val, bool optional=false) |
|
void | setArrayUniform (const String &name, int index, const Matrix2 &val, bool optional=false) |
|
void | setArrayUniform (const String &name, int index, const Matrix3 &val, bool optional=false) |
|
void | setArrayUniform (const String &name, int index, const Matrix4 &val, bool optional=false) |
|
void | setArrayUniform (const String &name, int index, const Matrix2x3 &val, bool optional=false) |
| Becomes a GLSL mat3x2. More...
|
|
void | setArrayUniform (const String &name, int index, const CoordinateFrame &val, bool optional=false) |
| Becomes a GLSL mat4x3. More...
|
|
void | setAttributeArray (const String &name, const AttributeArray &val, int instanceDivisor=0) |
|
void | setComputeGridDim (const Vector3int32 &computeGridDim) |
|
void | setComputeGroupSize (const Vector3int32 &computeGroupSize) |
|
void | setImageUniform (const String &name, const shared_ptr< Texture > &val, Access access=Access::READ_WRITE, int mipLevel=0, bool optional=false) |
| Uses the texture as the corresponding image type in the shader. More...
|
|
void | setImageUniform (const String &name, const shared_ptr< BufferTexture > &val, Access access=Access::READ_WRITE, bool optional=false) |
| Uses the texture as the corresponding *imageBuffer type in the shader. More...
|
|
void | setIndexStream (const IndexStream &indStream) |
| Determines the order vertex attribute streams are sent to the GPU. More...
|
|
void | setIndirectBuffer (const shared_ptr< GLPixelTransferBuffer > &b, size_t offset=0) |
| If set, perform a glDrawArraysIndirect or glDispatchComputeIndirect where the parameters for the thread launch come from another device buffer instead of the host, thus avoiding a CPU-GPU synchronization. More...
|
|
void | setMacro (const String &name, const String &value) |
|
void | setMacro (const String &name, const char *value) |
|
void | setMacro (const String &name, bool val) |
| false becomes 0 and true becomes 1 More...
|
|
void | setMacro (const String &name, int val) |
|
void | setMacro (const String &name, uint32 val) |
|
void | setMacro (const String &name, double val) |
|
void | setMacro (const String &name, float val) |
|
void | setMacro (const String &name, const Vector2 &val) |
|
void | setMacro (const String &name, const Vector3 &val) |
|
void | setMacro (const String &name, const Vector4 &val) |
|
void | setMacro (const String &name, const Color1 &val) |
| Becomes float in GLSL. More...
|
|
void | setMacro (const String &name, const Color3 &val) |
|
void | setMacro (const String &name, const Color4 &val) |
|
void | setMacro (const String &name, const Vector2int32 &val) |
|
void | setMacro (const String &name, const Vector2uint32 &val) |
|
void | setMacro (const String &name, const Vector3int32 &val) |
|
void | setMacro (const String &name, const Vector2int16 &val) |
|
void | setMacro (const String &name, const Vector3int16 &val) |
|
void | setMacro (const String &name, const Vector4int16 &val) |
|
void | setMacro (const String &name, const Vector4uint16 &val) |
|
void | setMacro (const String &name, const Matrix2 &val) |
|
void | setMacro (const String &name, const Matrix3 &val) |
|
void | setMacro (const String &name, const Matrix4 &val) |
|
void | setMacro (const String &name, const CoordinateFrame &val) |
| Becomes mat3x4 in GLSL. More...
|
|
void | setMacro (const String &name, const Matrix &val) |
|
void | setMultiDrawArrays (const Array< int > &offsets, const Array< int > &counts) |
|
void | setNumIndices (int n) |
| When rendering without a vertex array or index array, this forces the number of indices. More...
|
|
void | setNumInstances (int num) |
| If you change the number of instances in order to produce multiple copies of a model at different locations using a VisibleEntity subclass, then ensure that you take the following steps to produce consistent results: More...
|
|
void | setPreamble (const String &preamble) |
| Arbitrary string to append to beginning of the shader. More...
|
|
void | setPrimitiveType (PrimitiveType type) |
|
void | setRect (const Rect2D &rect, float zCoord=-1, const Rect2D &texCoordRect=Rect2D(Vector2(1, 1))) |
|
void | setUniform (const String &name, bool val, bool optional) |
|
void | setUniform (const String &name, bool val) |
|
void | setUniform (const String &name, int val, bool optional=false) |
|
void | setUniform (const String &name, float val, bool optional=false) |
|
void | setUniform (const String &name, uint32 val, bool optional=false) |
|
void | setUniform (const String &name, double val, bool optional=false) |
|
void | setUniform (const String &name, uint64 val, bool optional=false) |
|
void | setUniform (const String &name, const Vector2 &val, bool optional=false) |
|
void | setUniform (const String &name, const Vector3 &val, bool optional=false) |
|
void | setUniform (const String &name, const Vector4 &val, bool optional=false) |
|
void | setUniform (const String &name, const Color1 &val, bool optional=false) |
| Becomes float in GLSL. More...
|
|
void | setUniform (const String &name, const Color3 &val, bool optional=false) |
|
void | setUniform (const String &name, const Color4 &val, bool optional=false) |
|
void | setUniform (const String &name, const Vector2int32 &val, bool optional=false) |
|
void | setUniform (const String &name, const Vector2uint32 &val, bool optional=false) |
|
void | setUniform (const String &name, const Vector3int32 &val, bool optional=false) |
|
void | setUniform (const String &name, const Vector2int16 &val, bool optional=false) |
|
void | setUniform (const String &name, const Vector3int16 &val, bool optional=false) |
|
void | setUniform (const String &name, const Vector4int16 &val, bool optional=false) |
|
void | setUniform (const String &name, const Vector4uint16 &val, bool optional=false) |
|
void | setUniform (const String &name, const Matrix2 &val, bool optional=false) |
|
void | setUniform (const String &name, const Matrix3 &val, bool optional=false) |
|
void | setUniform (const String &name, const Matrix4 &val, bool optional=false) |
|
void | setUniform (const String &name, const Matrix2x3 &val, bool optional=false) |
| Becomes a GLSL mat3x2. More...
|
|
void | setUniform (const String &name, const Matrix &val, bool optional=false) |
|
void | setUniform (const String &name, const CoordinateFrame &val, bool optional=false) |
| Becomes a GLSL mat4x3. More...
|
|
void | setUniform (const String &name, const shared_ptr< Texture > &val, const Sampler &settings, bool optional=false) |
|
void | setUniform (const String &name, const shared_ptr< BufferTexture > &val, bool optional) |
|
void | setUniform (const String &name, const shared_ptr< BufferTexture > &val) |
|
void | setUniform (const String &name, const shared_ptr< BindlessTextureHandle > &val, bool optional=false) |
|
const Rect2D & | texCoordRect () const |
|
String | toString () const |
|
const Arg & | uniform (const String &name) const |
| Returns the uniform value bound to this name or throws UnboundArgument. More...
|
|
const UniformTable::ArgTable & | uniformTable () const |
|
bool | useG3DArgs () const |
|
Arguments to use when running a Shader.
Many classes (including Texture, Material, UniversalSurface, and Light) provide a setArgs method that assigns a set of arguments to an Args class.
Many classes (including Framebuffer, ArticulatedModel::Pose, and LightingEnvironment) provide a UniformTable field that allows them to impose additional values on the Args used for shaders that incorporate them. See the documentation on VisibleEntity::create for information about a common case of specifying shader arguments in a file.
There are three major types of arguments stored:
Uniform Args
These correspond exactly to glsl uniform variables. They are constant throughout one shader application. These are set using the overloaded setUniform() functions. The first parameter of this function is the uniform name, the second is the value.
We currently support a subset of the types in glsl, including all floating-point vector and matrix types (vecX, matNxM), most scalar types (float, int, double, uint, bool), and sampler types (which have the CPU type G3D::Texture).
Preamble and Macro Args
The preamble is an arbitrary string that is prepended to the code of all stages of the shader before compilation (before the #version string, which must be the first line of any GLSL program, is prepended). This allows for the addition of arbitrary glsl code to your shader at compile-time.
Macro Args are set using the overloaded setMacro() functions. The first parameter of this function is the uniform name, the second is the value. The values all get formatted into strings internally, and we support string types as a value of macro arguments. This in theory allows you to write arbitrary glsl code inside the value of a macro arg, but it is more sensical to put such things in the preamble if they are necessary.
Macro Args are appended to the preamble before the preamble is prepended to the shader code.
Examples:
setMacro("USE_LAMBERTIAN", 0);
becomes
"#define USE_LAMBERTIAN 0\n"
(note that we also coerce booleans into 1 or 0)
setMacro("MACRO_VECTOR", Vector4::clear());
becomes "#define MACRO_VECTOR vec4(0.0, 0.0, 0.0, 0.0)\n"
Since GLSL has a preprocessor that recognizes #defines, macro args can be used as compile-time constants.
G3D also supports a special way to include macros with newlines and preprocessor commands in them. In your shader, #includestring macroarg
inserts the value of the macroarg (it does not include a file named by the macroarg). It is an error to insert such macros by name only.
NOTE: Shader, when being applied with an Args object, first checks the result preambleAndMacroString(), and uses that as a key into a cache of compiled shader program objects. If such an object is found, the compilation step is skipped, and Shader uses the program object from the cache, otherwise it is compiled and added to the cache.
The number of possible shaders to compile is exponential in the number of macro arguments, use them sparingly!
Stream Args
Steam Args correspond to GLSL vertex attributes.
We support standard OpenGL attributes using pointers into VBOs (which correspond to G3D::AttributeArray), through the setAttributeArray() function The first parameter is the name of the (generic) vertex attribute.
The second parameter is the AttributeArray to use as the data for the attribute.
Indexed rendering is used if the index stream is set with setIndexStream() before Shader application, otherwise, sequential indices are used up to the number of elements in the smallest set AttributeArray.
Note that if no vertex shader is used we provide default.vrt, which uses g3d_Vertex and g3d_TexCoord0, transforming the position by the g3d_ObjectToScreenMatrix. This is useful mostly in the context of our alternate rendering mode using setRect, to set up a screen-space shader pass (basically a compute shader masquerading as a compute shader).
- See also
- Shader