Vuo  2.0.0
Macros | Typedefs | Functions | Variables
VuoShader.cc File Reference

Description

VuoShader implementation.

Definition in file VuoShader.cc.

Go to the source code of this file.

Macros

#define DEFINE_PROGRAM()
 Defines a program variable and initializes it with the relevant program based on inputPrimitiveMode. More...
 

Typedefs

typedef std::map< VuoGlContext, GLuint > VuoShaderContextType
 Type for VuoShaderContextMap. More...
 

Functions

void VuoShader_free (void *shader)
 Frees the CPU memory and GPU objects associated with the shader. More...
 
VuoShader VuoShader_make (const char *name)
 Creates a shader object, which contains multiple GL Program Objects. More...
 
VuoShader VuoShader_makeFromFile (VuoShaderFile *shaderFile)
 Creates a shader object from a VuoShaderFile. More...
 
VuoShader VuoShader_make_VuoColor (VuoColor color)
 Creates an unlit color shader object. More...
 
VuoShader VuoShader_make_VuoShader (VuoShader shader)
 Returns the passed shader (does not make a copy). More...
 
VuoShader VuoShader_make_VuoImage (VuoImage image)
 Creates an unlit image shader. More...
 
void VuoShader_addSource (VuoShader shader, const VuoMesh_ElementAssemblyMethod inputPrimitiveMode, const char *vertexShaderSource, const char *geometryShaderSource, const char *fragmentShaderSource)
 Associates GLSL shader source code with the specified inputPrimitiveMode of the specified shader. More...
 
void VuoShader_setExpectedOutputPrimitiveCount (VuoShader shader, const VuoMesh_ElementAssemblyMethod inputPrimitiveMode, const unsigned int expectedOutputPrimitiveCount)
 Specifies the number of primitives the geometry shader is expected to produce per invocation. More...
 
void VuoShader_setMayChangeOutputPrimitiveCount (VuoShader shader, const VuoMesh_ElementAssemblyMethod inputPrimitiveMode, const bool mayChangeOutputPrimitiveCount)
 Specifies whether the geometry shader may dynamically choose to skip outputting some primitives or output additional primitives. More...
 
void VuoShader_setTransparent (VuoShader shader, const bool isTransparent)
 See VuoShader::isTransparent. More...
 
unsigned int VuoShader_getExpectedOutputPrimitiveCount (VuoShader shader, const VuoMesh_ElementAssemblyMethod inputPrimitiveMode)
 Returns the number of primitives the geometry shader is expected to produce per invocation. More...
 
bool VuoShader_getMayChangeOutputPrimitiveCount (VuoShader shader, const VuoMesh_ElementAssemblyMethod inputPrimitiveMode)
 Returns true if the geometry shader may not output the expected primitive count. More...
 
bool VuoShader_isTransformFeedback (VuoShader shader)
 Returns true if each of shader's defined inputPrimitiveModes has a vertex shader (and optionally a geometry shader) but lacks a fragment shader. More...
 
static void VuoShader_replaceImageMacro (VuoShader shader, string &source, map< string, GLint > &imagesToDeclare, string beforeFunction, bool isThis, string afterFunction2D, string afterFunctionRect, VuoShaderFile::Stage stage, VuoShaderIssues *outIssues)
 Converts gl_FragColor = beforeFunction(inputImage, isf_FragNormCoord.xy); to gl_FragColor = afterFunction2D(inputImage, _inputImage_imgRect, _inputImage_imgSize, _inputImage_flip, isf_FragNormCoord.xy); or afterFunctionRect, depending on the sampler type. More...
 
static void VuoShader_replaceSizeMacro (VuoShader shader, string &source, string before, string after)
 Replaces IMG_SIZE(someImage) with _someImage_imgSize. More...
 
static void VuoShader_replaceImageMacros (VuoShader shader, string &source, VuoShaderFile::Stage stage, VuoShaderIssues *outIssues)
 Replaces the IMG_PIXEL and IMG_NORM_PIXEL macros with the appropriate function call depending on the image's OpenGL target, and fill in the placeholder image declarations. More...
 
static bool VuoShader_ensureUploaded (VuoShader shader, const VuoMesh_ElementAssemblyMethod inputPrimitiveMode, VuoGlContext glContext, VuoShaderIssues *outIssues)
 Ensures that the source code for the specified inputPrimitiveMode is compiled, linked, and uploaded. More...
 
bool VuoShader_upload (VuoShader shader, const VuoMesh_ElementAssemblyMethod inputPrimitiveMode, VuoGlContext glContext, void *outIssues)
 Compiles and uploads the shader, outputting any issues in a VuoShaderIssues instance. More...
 
bool VuoShader_getAttributeLocations (VuoShader shader, const VuoMesh_ElementAssemblyMethod inputPrimitiveMode, VuoGlContext glContext, int *positionLocation, int *normalLocation, int *tangentLocation, int *bitangentLocation, int *textureCoordinateLocation)
 Outputs the shader program's vertex attribute locations (the same values as glGetAttribLocation()). More...
 
void VuoShader_initPerlinTexture (CGLContextObj cgl_ctx)
 Create and load a 2D texture for a combined index permutation and gradient lookup table. More...
 
void VuoShader_initGradTexture (CGLContextObj cgl_ctx)
 Create and load a 2D texture for a 4D gradient lookup table. More...
 
static void __attribute__ ((constructor)) VuoShaderContext_init(void)
 Initializes VuoShaderContext_semaphore. More...
 
bool VuoShader_activate (VuoShader shader, const VuoMesh_ElementAssemblyMethod inputPrimitiveMode, VuoGlContext glContext, VuoGlProgram *outputProgram)
 Activates the shader program (glUseProgram()) on the specified glContext, binds the shader's images to texture units, and uploads its unforms, so that the shader is ready for use in rendering. More...
 
void VuoShader_deactivate (VuoShader shader, const VuoMesh_ElementAssemblyMethod inputPrimitiveMode, VuoGlContext glContext)
 Unbinds the shader's images from their texture units. More...
 
void VuoShader_resetContext (VuoGlContext glContext)
 Disuses whatever shader (if any) is currently active on glContext. More...
 
VuoShader VuoShader_makeFromJson (json_object *js)
 Decodes the JSON object js, expected to contain a 64-bit integer (memory address or 0), to create a new VuoShader. More...
 
json_objectVuoShader_getJson (const VuoShader value)
 Encodes value as a JSON object. More...
 
json_objectVuoShader_getInterprocessJson (const VuoShader value)
 Calls VuoShader_getJson(). More...
 
char * VuoShader_getSummary (const VuoShader value)
 Returns a summary of the shader: the text description provided to VuoShader_make. More...
 
VuoPoint2d VuoShader_samplerCoordinatesFromVuoCoordinates (VuoPoint2d vuoCoordinates, VuoImage image)
 Converts the provided vuoCoordinates into GLSL Sampler Coordinates relative to the provided image. More...
 
VuoReal VuoShader_samplerSizeFromVuoSize (VuoReal vuoSize)
 Converts an x-axis distance in Vuo Coordinates into GLSL Sampler Coordinates. More...
 
VuoPoint2d VuoShader_samplerRectCoordinatesFromNormalizedCoordinates (VuoPoint2d c, VuoInteger imageWidth, VuoInteger imageHeight)
 Converts the provided normalizedCoordinates into GLSL sampler2DRect coordinates relative to the provided width/height. More...
 
bool VuoShader_isOpaque (VuoShader shader)
 Returns true if the shader, as configured, will produce fully opaque output. More...
 

Variables

static GLuint VuoShader_perlinTexture
 GL texture name for the Perlin permutation table. More...
 
static GLuint VuoShader_gradTexture
 GL texture name for the Simplex permutation table. More...
 
VuoShaderContextType VuoShaderContextMap
 The currently-active shader on each context. More...
 
static dispatch_semaphore_t VuoShaderContext_semaphore
 Serializes access to VuoShaderContextMap. More...
 

Macro Definition Documentation

◆ DEFINE_PROGRAM

#define DEFINE_PROGRAM ( )
Value:
VuoSubshader *program; \
VuoMesh_ElementAssemblyMethod epm = VuoMesh_getExpandedPrimitiveMode(inputPrimitiveMode); \
program = &shader->triangleProgram; \
else if (epm == VuoMesh_IndividualLines) \
program = &shader->lineProgram; \
else /* if (inputPrimitiveMode == VuoMesh_Points) */ \
program = &shader->pointProgram;

Defines a program variable and initializes it with the relevant program based on inputPrimitiveMode.

Definition at line 213 of file VuoShader.cc.

Typedef Documentation

◆ VuoShaderContextType

typedef std::map<VuoGlContext, GLuint> VuoShaderContextType

Type for VuoShaderContextMap.

Definition at line 891 of file VuoShader.cc.

Function Documentation

◆ __attribute__()

static void __attribute__ ( (constructor)  )
static

Initializes VuoShaderContext_semaphore.

Definition at line 897 of file VuoShader.cc.

◆ VuoShader_ensureUploaded()

static bool VuoShader_ensureUploaded ( VuoShader  shader,
const VuoMesh_ElementAssemblyMethod  inputPrimitiveMode,
VuoGlContext  glContext,
VuoShaderIssues outIssues 
)
static

Ensures that the source code for the specified inputPrimitiveMode is compiled, linked, and uploaded.

If the shader is NULL, or there is no source code for the specified inputPrimitiveMode, or it fails to compile or link, returns false.

Must be called while shader->lock is locked.

Definition at line 632 of file VuoShader.cc.

◆ VuoShader_free()

void VuoShader_free ( void *  shader)

Frees the CPU memory and GPU objects associated with the shader.

This function may be called from any thread.

Definition at line 72 of file VuoShader.cc.

◆ VuoShader_initGradTexture()

void VuoShader_initGradTexture ( CGLContextObj  cgl_ctx)

Create and load a 2D texture for a 4D gradient lookup table.

This is used for 4D noise only.

Author: Stefan Gustavson (stegu.nosp@m.@itn.nosp@m..liu..nosp@m.se) 2004, 2005, 2011 ("The C code in "noisevsnoise.c" is public domain.")

Definition at line 840 of file VuoShader.cc.

◆ VuoShader_initPerlinTexture()

void VuoShader_initPerlinTexture ( CGLContextObj  cgl_ctx)

Create and load a 2D texture for a combined index permutation and gradient lookup table.

This texture is used for 2D and 3D noise, both classic and simplex.

Author: Stefan Gustavson (stegu.nosp@m.@itn.nosp@m..liu..nosp@m.se) 2004, 2005, 2011 ("The C code in "noisevsnoise.c" is public domain.")

Definition at line 786 of file VuoShader.cc.

◆ VuoShader_replaceImageMacro()

static void VuoShader_replaceImageMacro ( VuoShader  shader,
string &  source,
map< string, GLint > &  imagesToDeclare,
string  beforeFunction,
bool  isThis,
string  afterFunction2D,
string  afterFunctionRect,
VuoShaderFile::Stage  stage,
VuoShaderIssues outIssues 
)
static

Converts gl_FragColor = beforeFunction(inputImage, isf_FragNormCoord.xy); to gl_FragColor = afterFunction2D(inputImage, _inputImage_imgRect, _inputImage_imgSize, _inputImage_flip, isf_FragNormCoord.xy); or afterFunctionRect, depending on the sampler type.

If isThis is true, the function is expected to have 1 argument (the texture coordinate is implicit).

Definition at line 507 of file VuoShader.cc.

◆ VuoShader_replaceImageMacros()

static void VuoShader_replaceImageMacros ( VuoShader  shader,
string &  source,
VuoShaderFile::Stage  stage,
VuoShaderIssues outIssues 
)
static

Replaces the IMG_PIXEL and IMG_NORM_PIXEL macros with the appropriate function call depending on the image's OpenGL target, and fill in the placeholder image declarations.

Definition at line 590 of file VuoShader.cc.

◆ VuoShader_replaceSizeMacro()

static void VuoShader_replaceSizeMacro ( VuoShader  shader,
string &  source,
string  before,
string  after 
)
static

Replaces IMG_SIZE(someImage) with _someImage_imgSize.

Definition at line 569 of file VuoShader.cc.

Variable Documentation

◆ VuoShader_gradTexture

GLuint VuoShader_gradTexture
static

GL texture name for the Simplex permutation table.

Definition at line 833 of file VuoShader.cc.

◆ VuoShader_perlinTexture

GLuint VuoShader_perlinTexture
static

GL texture name for the Perlin permutation table.

Definition at line 778 of file VuoShader.cc.

◆ VuoShaderContext_semaphore

dispatch_semaphore_t VuoShaderContext_semaphore
static

Serializes access to VuoShaderContextMap.

Definition at line 893 of file VuoShader.cc.

◆ VuoShaderContextMap

VuoShaderContextType VuoShaderContextMap

The currently-active shader on each context.

This is placed in VuoGlContext (a dylib) instead of VuoShader (a static module) to ensure there's only one instance per process.

Definition at line 838 of file VuoGlContext.cc.