Support Forum       G3D Web Page     
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
G3D::Shader Class Reference

Abstraction of the programmable hardware pipeline with G3D preprocessor extensions. More...

Inherits G3D::ReferenceCountedObject.

Classes

class  PreprocessedShaderSource
 A structure containing the individual parts of the code of a load-time preprocessed (by g3d, not the driver) shader. More...
 
class  ShaderProgram
 A wrapper around an actual openGL shader program object. More...
 
class  Source
 Stores either a filename or a shader source string (that has not gone through the g3d preprocessor) for a single shader stage. More...
 
class  Specification
 Consists of up to one Shader::Source per shader stage. More...
 

Public Types

enum  DomainType {
  STANDARD_INDEXED_RENDERING_MODE,
  STANDARD_NONINDEXED_RENDERING_MODE,
  MULTIDRAW_INDEXED_RENDERING_MODE,
  MULTIDRAW_NONINDEXED_RENDERING_MODE,
  INDIRECT_RENDERING_MODE,
  STANDARD_COMPUTE_MODE,
  INDIRECT_COMPUTE_MODE,
  RECT_MODE,
  ERROR_MODE
}
 
enum  FailureBehavior {
  EXCEPTION,
  PROMPT,
  SILENT
}
 Determines the behavior upon a load-time or compile-time error for all shaders. More...
 
enum  RecoverableErrorType {
  LOAD_ERROR,
  COMPILATION_ERROR
}
 
enum  ShaderStage {
  VERTEX,
  TESSELLATION_CONTROL,
  TESSELLATION_EVAL,
  GEOMETRY,
  PIXEL,
  COMPUTE,
  STAGE_COUNT
}
 
enum  SourceType {
  FILE,
  STRING
}
 

Public Member Functions

void bindG3DArgs (const shared_ptr< ShaderProgram > &p, RenderDevice *renderDevice, const Args &sourceArgs, int &maxModifiedTextureUnit)
 Sets the g3d uniform variables such as g3d_objectToWorldMatrix (using values from renderDevice) args. More...
 
void bindStreamArg (const String &name, const AttributeArray &vertexRange, const ShaderProgram::AttributeDeclaration &decl)
 Bind a single vertex attribute. More...
 
void bindStreamArgs (const shared_ptr< ShaderProgram > &program, const Args &args, RenderDevice *rd)
 Iterate over all formal parameters and bind all vertex attributes appropriately. More...
 
void bindUniformArg (const Args::Arg &arg, const ShaderProgram::UniformDeclaration &decl, int &maxModifiedTextureUnit)
 Bind a single uniform variable. More...
 
void bindUniformArgs (const shared_ptr< ShaderProgram > &program, const Args &args, bool allowG3DArgs, int &maxModifiedTextureUnit)
 Iterate over all formal parameters and bind all non-dummy variables appropriately. More...
 
shared_ptr< ShaderProgramcompileAndBind (const Args &args, RenderDevice *rd, int &maxModifiedTextureUnit)
 Compile the shader and bind the arguments as necessary. More...
 
bool g3dLoadTimePreprocessor (const String &dir, PreprocessedShaderSource &source, String &messages, GLuint stage, const Args &args)
 Execute all steps of the G3D load-time preprocessor engine. More...
 
bool isCompute () const
 
void loadAndPreprocess (const Args &args, Array< PreprocessedShaderSource > &preprocessedSource)
 Load the shaders from files on disk, and run the preprocessor. More...
 
const Stringname () const
 A name for this shader. More...
 
bool processIncludes (const String &dir, String &code, String &messages, const Args &args)
 Replaces all #includes in code with the contents of the appropriate files. More...
 
void reload ()
 Reload this shader from the files on disk, if it was loaded from disk. More...
 
shared_ptr< ShaderProgramretry (const Args &args)
 Reload from files on disk (if it was loaded from disk), run all steps of the g3d preprocessor and recompile. More...
 
void setName (const String &n)
 
void unbindStreamArgs (const shared_ptr< ShaderProgram > &program, const Args &args, RenderDevice *rd)
 Counterpart to bindStreamArgs. More...
 

Static Public Member Functions

static GLenum canonicalType (GLenum e)
 Converts texture types to their canonical value (anything that can be a sampler2D becomes GL_TEXTURE_2D, etc) all others are unmodified. More...
 
static shared_ptr< Shadercreate (const Specification &s)
 Creates a shader from the given specification, loads it from disk, and applies the g3d preprocessor. More...
 
static DomainType domainType (const shared_ptr< Shader > &s, const Args &args)
 The mode to use when applying the shader and args. More...
 
static shared_ptr< ShaderfromFiles (const String &f0, const String &f1="", const String &f2="", const String &f3="", const String &f4="")
 
More...
 
static shared_ptr< ShadergetShaderFromPattern (const String &pattern)
 Create a shader using all shaders specified by the given pattern. More...
 
static bool isImageType (GLenum type)
 True if type corresponding to an OpenGL image type. More...
 
static bool isSamplerType (GLenum type)
 True if type corresponding to an OpenGL sampler type. More...
 
static void processExtensions (String &code, String &extensionLines)
 Reads the code looking for a #extension line (spaces allowed after "#"). More...
 
static bool processVersion (String &code, String &versionLine)
 Reads the code looking for a #version line (spaces allowed after "#"). More...
 
static void reloadAll ()
 Reloads all shaders throughout G3D. More...
 
static void setFailureBehavior (FailureBehavior f)
 Set the global failure behavior. More...
 
static GLuint toGLEnum (ShaderStage s)
 
static shared_ptr< Shaderunlit ()
 A shader that accepts color and textureMap arguments and applies them directly without lighting. More...
 

Static Public Attributes

static FailureBehavior s_failureBehavior
 

Protected Member Functions

 Shader (const Specification &s)
 No compilation, or even loading from files is performed at construction. More...
 
String getLinePragma (int lineNumber, const String &filename)
 Returns a line directive in the format "#line X Y\n", where X is the lineNumber, and Y is an integer that maps to filename. More...
 
void handleRecoverableError (RecoverableErrorType eType, const Args &args, const String &message, shared_ptr< ShaderProgram > &program)
 Handle a compilation or loading error as specified by s_failureBehavior. More...
 
shared_ptr< Shader::ShaderProgramshaderProgram (const Args &args, String &messages)
 Finds a shader program in the cache that matches the supplied args, recompiling if necessary. More...
 

Static Protected Member Functions

template<class T , class ... ArgTypes>
static shared_ptr< T > createShared (ArgTypes &&... args)
 Like std::make_shared, but works for protected constructors. More...
 
static bool expandExpectPragmas (String &source, const Table< int, String > &indexToNameTable, String &errorMessages)
 Expands G3D #expect preprocessor instructions. More...
 
static bool expandForEachPragmas (String &processedSource, const Table< int, String > &indexToNameTable, String &errorMessages)
 Expands G3D #foreach pragmas found in processedSource into valid GLSL code. More...
 
static bool expandForPragmas (String &processedSource, const Args &args, const Table< int, String > &indexToNameTable, String &errorMessages)
 Expands our #for pragmas found in processedSource into valid GLSL code. More...
 
static shared_ptr< ShadergetShaderFromCacheOrCreate (const Specification &spec)
 If a shader of the given Specification exists, return it, otherwise create a new one. More...
 
static bool sameSource (const Source &a, const Source &b)
 True iff a and b have the same SouceType and value. More...
 
static bool sameSpec (const Specification &a, const Specification &b)
 True iff every stage of a and b satisfy sameSource. More...
 
static GLenum toGLType (const String &s)
 Converts a type name to a GL enum. More...
 

Protected Attributes

Table< String, shared_ptr< ShaderProgram > > m_compilationCache
 Maps preamble + macro definitions to compiled shaders. More...
 
Table< String, int > m_fileNameToIndexTable
 Maps filenames to indices, so that we can correctly print #line directives. More...
 
Args m_g3dUniformArgs
 A set of args solely for g3d uniforms. More...
 
Table< int, Stringm_indexToFilenameTable
 Maps indices to filenames, so that we can correctly output filenames when we get file indices back from the shader on error messages. More...
 
bool m_isCompute
 
String m_name
 
int m_nextUnusedFileIndex
 The next index to be used by a previously unprocessed file when #including, so that we can produce proper #line directives. More...
 
Specification m_specification
 Contains the filenames or hardcoded source strings this shader was constructed from. More...
 

Static Protected Attributes

static Array< weak_ptr< Shader > > s_allShaders
 Array of all shaders ever created. More...
 

Friends

class RenderDevice
 

Detailed Description

Abstraction of the programmable hardware pipeline with G3D preprocessor extensions.

Shaders are almost always invoked with the LAUNCH_SHADER macro, with arguments provided by the G3D::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.

Shader supports macro arguments in addition to uniform and streaming (attribute, index) arguments. It caches all needed permutations of a shader that uses macros and then provides the correct instance at invokation time.

Preprocessor

G3D introduces additional preprocessor commands GLSL:

#version

The preprocessor automatically moves GLSL #version directives to the first line of a program before compilation.
The extended syntax "\#version v1 or v2 or ..." allows writing shaders that simultaneously target multiple GLSL versions. Shader will compie for the highest listed version number that the driver provides at runtime. Within the shader code, you can test against the VERSION macro to discover which version version is in use.

#include

#include has three forms:

#include <filename.glsl> Searches for the filename using G3D::System::findDataFile and inlines it.

#include "filename.glsl" Loads the file relative to the including file.

#include MACRONAME Loads the file specified by the fully qualified macro argument's value. The macro must be defined as a shader argument, not as a #define.

Every included file effectively has #pragma once, which is done by the preprocessor to prevent infinitely recursive includes.

#expect

Shader expands

#expect MACRO_NAME "description"

to

#ifndef MACRO_NAME
# error description
#endif

#for

#for (int i = 0; i < macroArgOrIntegerLiteral; ++i)
// ...use $(i) to refer to the index inside of the loop body...
#endfor

The upper bound cannot be a value set via #define...if it is a macro, then the macro must have been passed from C++ as an argument.

Example:

#for (int j = 0; j &lt; NUM_LIGHTS; ++j)
uniform vec3 lightPos$(j);
#endfor

with NUM_LIGHTS a macro arg with value "4", this code expands to:

uniform vec3 lightPos0;
uniform vec3 lightPos1;
uniform vec3 lightPos2;
uniform vec3 lightPos3;

The expression inside the $(...) can also perform a single arithmetic expression of the form $(identifier operator number), where operator may be +, -, /, or *. If the number is an integer and the operator is /, then integer division is performed. Otherwise, the operation is performed at double precision.

The preprocessor inserts #line pragmas before each unrolled loop body, so errors will report correct line numbers.

#foreach

#foreach field in (value0), (value1), (value2)
// ...loop body...
#endforeach

The inner code then gets repeated for each value of field, and any occurence of in the inner code is replaced with the current value of field. Note that field can be replace with any string, and value* can be regular symbols or quoted strings.

#foreach v, w in (v0, w0), (v1, w1), (v2, w2)
// loop body
#endforeach

Example:

#foreach (name, componentCount) in (lambertian, 4), (glossy, 4), (emissive, 3)
uniform vec$(componentCount) $(name)_constant;
uniform sampler2D $(name)_buffer;
#endforeach

becomes:

uniform vec4 lambertian_constant;
uniform sampler2D lambertian_buffer;
uniform vec4 glossy_constant;
uniform sampler2D glossy_buffer;
uniform vec3 emissive_constant;
uniform sampler2D emissive_buffer;

#eval

#eval(macroname) is identical to just using macroname if the macro contains no newlines and is a shader macro argument. It cannot be applied to macros that are defined in the shader using #define.

For shader macro arguments that contain newlines, #eval inserts their values with newlines and preserving surrounding line numbers for error reporting. Those macros are defined as blank for the regular preprocessor. This allows idioms such as:

#ifdef CODE
# eval(CODE)
#endif

G3D Built-in Uniforms and Macros

G3D_SHADER_STAGE will be equal to one of:d G3D_VERTEX_SHADER, G3D_TESS_CONTROL_SHADER, G3D_TESS_EVALUATION_SHADER, G3D_GEOMETRY_SHADER, G3D_FRAGMENT_SHADER, G3D_COMPUTE_SHADER (which are integers equal to their OpenGL counterparts)
One of the following is defined: G3D_OSX, G3D_WINDOWS, G3D_LINUX, G3D_FREEBSD
One of the following may be defined: G3D_NVIDIA, G3D_MESA, G3D_AMD, G3D_INTEL
// RenderDevice properties
uniform mat4x3 g3d_WorldToObjectMatrix;
uniform mat4x3 g3d_ObjectToWorldMatrix;
uniform mat4x4 g3d_ProjectionMatrix; // See Projection::getProjectUnitMatrix
uniform mat4x4 g3d_ProjectToPixelMatrix; // See Projection::getProjectPixelMatrix. Undefined for non-perspective projection
uniform mat3 g3d_WorldToObjectNormalMatrix;
uniform mat3 g3d_ObjectToWorldNormalMatrix;
uniform mat3 g3d_ObjectToCameraNormalMatrix;
uniform mat3 g3d_CameraToObjectNormalMatrix;
uniform vec4 g3d_ProjInfo; // Projection::reconstructFromDepthProjInfo for g3d_ProjectToPixelMatrix
uniform vec3 g3d_ClipInfo; // Projection::reconstructFromDepthClipInfo for g3d_ProjectToPixelMatrix
uniform mat4 g3d_ObjectToScreenMatrix; // includes invertY information
uniform mat4 g3d_ObjectToScreenMatrixTranspose;
uniform mat4x3 g3d_ObjectToCameraMatrix;
uniform mat4x3 g3d_WorldToCameraMatrix;
uniform mat4x3 g3d_CameraToWorldMatrix;
uniform bool g3d_InvertY;
uniform mat3 g3d_WorldToCameraNormalMatrix;
uniform float g3d_SceneTime; // GApp::lastGApp->scene()->time() if valid, otherwise time since first binding of this variable
uniform float g3d_RunTime; // Wall-clock time since the first binding of this variable in any shader
// Rect2D bounds from the draw call
uniform vec2 g3d_FragCoordExtent; // Only if Args::setRect was invoked
uniform vec2 g3d_FragCoordMin; // Only if Args::setRect was invoked
uniform vec2 g3d_FragCoordMax; // Only if Args::setRect was invoked
uniform vec2 g3d_FramebufferSize;
uniform int g3d_NumInstances;
uniform sampler2D g3d_cosHemiRandom; // See the static Texture methods of the same names
uniform sampler2D g3d_sphereRandom;
uniform sampler2D g3d_uniformRandom;

Implementation

G3D has two distinct preprocessing steps for shaders: load-time (e.g. include) and compile-time (for, foreach).

The load-time preprocessor is documented in Shader::g3dLoadTimePreprocessor().

The compile-time preprocessor currently only prepends Args::preambleAndMacroString() and evaluates the #for and #foreach commands ( Shader::expandForPragmas() )

Member Enumeration Documentation

◆ DomainType

Enumerator
STANDARD_INDEXED_RENDERING_MODE 
STANDARD_NONINDEXED_RENDERING_MODE 
MULTIDRAW_INDEXED_RENDERING_MODE 
MULTIDRAW_NONINDEXED_RENDERING_MODE 
INDIRECT_RENDERING_MODE 
STANDARD_COMPUTE_MODE 
INDIRECT_COMPUTE_MODE 
RECT_MODE 
ERROR_MODE 

◆ FailureBehavior

Determines the behavior upon a load-time or compile-time error for all shaders.

Enumerator
EXCEPTION 

Throw an exception on load or compilation failure.

PROMPT 

Prompt the user to throw an exception, abort the program, or retry loading on load or compilation failure.

(default)

SILENT 

ok() will be false if an error occurs

◆ RecoverableErrorType

Enumerator
LOAD_ERROR 
COMPILATION_ERROR 

◆ ShaderStage

Enumerator
VERTEX 
TESSELLATION_CONTROL 

In DirectX, this is called the Hull Shader.

TESSELLATION_EVAL 

In DirectX, this is called the Domain Shader.

GEOMETRY 
PIXEL 

Sometimes referred to as the Fragment Shader.

COMPUTE 
STAGE_COUNT 

◆ SourceType

Enumerator
FILE 
STRING 

Constructor & Destructor Documentation

◆ Shader()

G3D::Shader::Shader ( const Specification s)
protected

No compilation, or even loading from files is performed at construction.

Member Function Documentation

◆ bindG3DArgs()

void G3D::Shader::bindG3DArgs ( const shared_ptr< ShaderProgram > &  p,
RenderDevice renderDevice,
const Args sourceArgs,
int &  maxModifiedTextureUnit 
)

Sets the g3d uniform variables such as g3d_objectToWorldMatrix (using values from renderDevice) args.

See Shader::g3dLoadTimePreprocessor for the declarations of all of the variables of this form that can be set by this function. Also binds them immediately, to avoid overhead of writing and reading into a datastructure

Also sets all uniforms of the form g3d_sz2D_textureName, where textureName is the name of any sampler type bound in sourceArgs. g3d_sz2D_textureName is a vec4 of the form (w, h, 1.0/w, 1.0/h), where w and h are the width and height of the texture named textureName.

◆ bindStreamArg()

void G3D::Shader::bindStreamArg ( const String name,
const AttributeArray vertexRange,
const ShaderProgram::AttributeDeclaration decl 
)

Bind a single vertex attribute.

◆ bindStreamArgs()

void G3D::Shader::bindStreamArgs ( const shared_ptr< ShaderProgram > &  program,
const Args args,
RenderDevice rd 
)

Iterate over all formal parameters and bind all vertex attributes appropriately.

Also sets the glPatchParameter if the primitive type is patch.

◆ bindUniformArg()

void G3D::Shader::bindUniformArg ( const Args::Arg arg,
const ShaderProgram::UniformDeclaration decl,
int &  maxModifiedTextureUnit 
)

Bind a single uniform variable.

◆ bindUniformArgs()

void G3D::Shader::bindUniformArgs ( const shared_ptr< ShaderProgram > &  program,
const Args args,
bool  allowG3DArgs,
int &  maxModifiedTextureUnit 
)

Iterate over all formal parameters and bind all non-dummy variables appropriately.

Writes the maximum value of the texture unit that had a sampler bound to it to maxModifiedTextureUnit, so the caller can revert after the shading pass. (-1 if no samplers were bound).

◆ canonicalType()

static GLenum G3D::Shader::canonicalType ( GLenum  e)
static

Converts texture types to their canonical value (anything that can be a sampler2D becomes GL_TEXTURE_2D, etc) all others are unmodified.

◆ compileAndBind()

shared_ptr<ShaderProgram> G3D::Shader::compileAndBind ( const Args args,
RenderDevice rd,
int &  maxModifiedTextureUnit 
)

Compile the shader and bind the arguments as necessary.

Adds the necessary g3d uniforms to args. Writes the maximum value of the texture unit that had a sampler bound to it to maxModifiedTextureUnit, so the caller can revert after the shading pass. (-1 if no samplers were bound).

◆ create()

static shared_ptr<Shader> G3D::Shader::create ( const Specification s)
static

Creates a shader from the given specification, loads it from disk, and applies the g3d preprocessor.

◆ createShared()

template<class T , class ... ArgTypes>
static shared_ptr<T> G3D::ReferenceCountedObject::createShared ( ArgTypes &&...  args)
inlinestaticprotectedinherited

Like std::make_shared, but works for protected constructors.

Call as createShared<myclass>.

◆ domainType()

static DomainType G3D::Shader::domainType ( const shared_ptr< Shader > &  s,
const Args args 
)
static

The mode to use when applying the shader and args.

◆ expandExpectPragmas()

static bool G3D::Shader::expandExpectPragmas ( String source,
const Table< int, String > &  indexToNameTable,
String errorMessages 
)
staticprotected

Expands G3D #expect preprocessor instructions.

This is a load-time preprocessing step.

See also
expandForEachPragmas

◆ expandForEachPragmas()

static bool G3D::Shader::expandForEachPragmas ( String processedSource,
const Table< int, String > &  indexToNameTable,
String errorMessages 
)
staticprotected

Expands G3D #foreach pragmas found in processedSource into valid GLSL code.

Nested #foreach loops are processed from the outside in.

errorMessages is appended to if any errors are encountered with details.

The return value is true if not errors were encountered.

This is a load-time preprocessing step.

See also
expandForPragmas

◆ expandForPragmas()

static bool G3D::Shader::expandForPragmas ( String processedSource,
const Args args,
const Table< int, String > &  indexToNameTable,
String errorMessages 
)
staticprotected

Expands our #for pragmas found in processedSource into valid GLSL code.

Nested #for loops are processed from the outside in.

errorMessages is appended to if any errors are encountered with details.

The return value is true if no errors were encountered.

This is a load-time preprocessing step.

◆ fromFiles()

static shared_ptr<Shader> G3D::Shader::fromFiles ( const String f0,
const String f1 = "",
const String f2 = "",
const String f3 = "",
const String f4 = "" 
)
static


◆ g3dLoadTimePreprocessor()

bool G3D::Shader::g3dLoadTimePreprocessor ( const String dir,
PreprocessedShaderSource source,
String messages,
GLuint  stage,
const Args args 
)

Execute all steps of the G3D load-time preprocessor engine.

Process Includes (adding #line directives where neccessary) Process Foreach macros (adding #line directives where neccessary) Process expect macros (adding #line directives where neccessary)

Process Version Line

Parameters
messagesAny errors regarding inclusion of files are written here
Returns
True if no error occured during inclusion of other files

◆ getLinePragma()

String G3D::Shader::getLinePragma ( int  lineNumber,
const String filename 
)
protected

Returns a line directive in the format "#line X Y\n", where X is the lineNumber, and Y is an integer that maps to filename.

◆ getShaderFromCacheOrCreate()

static shared_ptr<Shader> G3D::Shader::getShaderFromCacheOrCreate ( const Specification spec)
staticprotected

If a shader of the given Specification exists, return it, otherwise create a new one.

◆ getShaderFromPattern()

static shared_ptr<Shader> G3D::Shader::getShaderFromPattern ( const String pattern)
static

Create a shader using all shaders specified by the given pattern.

Used to implement LAUNCH_SHADER.

//Example:
shared_ptr<Shader> s = getShaderFromPattern("SVO_updateLevelIndexBuffer.*");
rd->apply(s, args);

◆ handleRecoverableError()

void G3D::Shader::handleRecoverableError ( RecoverableErrorType  eType,
const Args args,
const String message,
shared_ptr< ShaderProgram > &  program 
)
protected

Handle a compilation or loading error as specified by s_failureBehavior.

If this handles a compilation error, program can be overwritten with a correctly compiled shader (if s_failureBehaviord is PROMPT and the user reloads).

◆ isCompute()

bool G3D::Shader::isCompute ( ) const
inline

◆ isImageType()

static bool G3D::Shader::isImageType ( GLenum  type)
static

True if type corresponding to an OpenGL image type.

◆ isSamplerType()

static bool G3D::Shader::isSamplerType ( GLenum  type)
static

True if type corresponding to an OpenGL sampler type.

◆ loadAndPreprocess()

void G3D::Shader::loadAndPreprocess ( const Args args,
Array< PreprocessedShaderSource > &  preprocessedSource 
)

Load the shaders from files on disk, and run the preprocessor.

◆ name()

const String& G3D::Shader::name ( ) const
inline

A name for this shader.

By default, this is the filename with a star instead of the extension, e.g., blur.*

See also
setName

◆ processExtensions()

static void G3D::Shader::processExtensions ( String code,
String extensionLines 
)
static

Reads the code looking for a #extension line (spaces allowed after "#").

If one is found, remove it from code and put it in extensionLine.

Returns
True if we found and removed a version line from the code.
Deprecated:

◆ processIncludes()

bool G3D::Shader::processIncludes ( const String dir,
String code,
String messages,
const Args args 
)

Replaces all #includes in code with the contents of the appropriate files.

It is called recursively, so included files may have includes themselves. This is called automatically by the preprocessor, but is public so as to be accessible to code that directly manipulates source strings.

Parameters
dirThe directory from which the parent was loaded.
messagesAny errors regarding inclusion of files are written here
Returns
True if no error occured during inclusion of other files

◆ processVersion()

static bool G3D::Shader::processVersion ( String code,
String versionLine 
)
static

Reads the code looking for a #version line (spaces allowed after "#").

If one is found, remove it from code and put it in versionLine, otherwise set versionLine to "#version 330\n".

Returns
True if we found and removed a version line from the code.

◆ reload()

void G3D::Shader::reload ( )

Reload this shader from the files on disk, if it was loaded from disk.

◆ reloadAll()

static void G3D::Shader::reloadAll ( )
static

Reloads all shaders throughout G3D.

◆ retry()

shared_ptr<ShaderProgram> G3D::Shader::retry ( const Args args)

Reload from files on disk (if it was loaded from disk), run all steps of the g3d preprocessor and recompile.

◆ sameSource()

static bool G3D::Shader::sameSource ( const Source a,
const Source b 
)
staticprotected

True iff a and b have the same SouceType and value.

◆ sameSpec()

static bool G3D::Shader::sameSpec ( const Specification a,
const Specification b 
)
staticprotected

True iff every stage of a and b satisfy sameSource.

◆ setFailureBehavior()

static void G3D::Shader::setFailureBehavior ( FailureBehavior  f)
static

Set the global failure behavior.

See Shader::FailureBehavior

◆ setName()

void G3D::Shader::setName ( const String n)
inline

◆ shaderProgram()

shared_ptr<Shader::ShaderProgram> G3D::Shader::shaderProgram ( const Args args,
String messages 
)
protected

Finds a shader program in the cache that matches the supplied args, recompiling if necessary.

if compilation fails, returns nullptr and fills in messages with a report of what went wrong. Primarily intended for internal use by Shader; called from compileAndBind() and its variants.

◆ toGLEnum()

static GLuint G3D::Shader::toGLEnum ( ShaderStage  s)
static

◆ toGLType()

static GLenum G3D::Shader::toGLType ( const String s)
staticprotected

Converts a type name to a GL enum.

◆ unbindStreamArgs()

void G3D::Shader::unbindStreamArgs ( const shared_ptr< ShaderProgram > &  program,
const Args args,
RenderDevice rd 
)

Counterpart to bindStreamArgs.

Unbinds all vertex attributes that were set.

◆ unlit()

static shared_ptr<Shader> G3D::Shader::unlit ( )
static

A shader that accepts color and textureMap arguments and applies them directly without lighting.

This is like the old OpenGL fixed function, but supports colors and textures outside of the range [0, 1].

e.g., used by GFont and Draw::rect.

Friends And Related Function Documentation

◆ RenderDevice

friend class RenderDevice
friend

Member Data Documentation

◆ m_compilationCache

Table<String, shared_ptr<ShaderProgram> > G3D::Shader::m_compilationCache
protected

Maps preamble + macro definitions to compiled shaders.

◆ m_fileNameToIndexTable

Table<String, int> G3D::Shader::m_fileNameToIndexTable
protected

Maps filenames to indices, so that we can correctly print #line directives.

◆ m_g3dUniformArgs

Args G3D::Shader::m_g3dUniformArgs
protected

A set of args solely for g3d uniforms.

We use this instead of modifying the args passed into compileAndBind(). This needs to be cleared every time we reload, or we will accidentally bind variables that don't exist in the compiled shader

◆ m_indexToFilenameTable

Table<int, String> G3D::Shader::m_indexToFilenameTable
protected

Maps indices to filenames, so that we can correctly output filenames when we get file indices back from the shader on error messages.

◆ m_isCompute

bool G3D::Shader::m_isCompute
protected

Referenced by isCompute().

◆ m_name

String G3D::Shader::m_name
protected

Referenced by name(), and setName().

◆ m_nextUnusedFileIndex

int G3D::Shader::m_nextUnusedFileIndex
protected

The next index to be used by a previously unprocessed file when #including, so that we can produce proper #line directives.

◆ m_specification

Specification G3D::Shader::m_specification
protected

Contains the filenames or hardcoded source strings this shader was constructed from.

◆ s_allShaders

Array< weak_ptr<Shader> > G3D::Shader::s_allShaders
staticprotected

Array of all shaders ever created.

nullptr elements are flushed during reloadAll()

◆ s_failureBehavior

FailureBehavior G3D::Shader::s_failureBehavior
static

documentation generated on Wed Nov 24 2021 08:02:00 using doxygen 1.8.15