Routines (alphabetical) > Object Classes > Graphics Object Classes > IDLgrShader::SetUniformVariable

# IDLgrShader::SetUniformVariable

The IDLgrShader::SetUniformVariable procedure method assigns a value to a named uniform variable. A uniform variable provides a way to pass small amounts of data to a shader program. It can enable interactivity by linking user interface control changes to shader program updates.

IDL stores the Name and Value of the uniform variable with the instance of the associated IDLgrShader object the first time this method is called. When SetUniformVariable is called again using the same Name argument, the uniform variable is updated with the current contents of Value. Once a uniform variable is associated with a shader object, there is no way to remove the reference. Any uniform variable that is defined, but not used in the shader program is simply ignored.

The fragment shader program will support a minimum of 64 uniform variables (use IDLgrWindow::GetDeviceInfo to determine the exact number). For maximum shader program portability, define 64 or fewer variables.

In the case of a shader object associated with an IDLgrImage, or an IDLgrPolygon or IDLgrSurface with an associated TEXTURE_MAP image, you do not need to use SetUniformVariable to pass the image data to the shader program if multi-texturing is not occurring. The reserved uniform variable, _IDL_ImageTexture, automatically contains the texture map data associated with the primary IDLgrImage object.

Note: If a shader object is associated with more than a single graphic object, any changes to a uniform variable will be applied to all associated objects. To avoid this, copy and associate an individual instance of a shader object with each individual graphic objects.

## Syntax

Obj->[IDLgrShader::]SetUniformVariable, Name, Value]

## Arguments

### Name

Specifies a case-sensitive string name of the uniform variable.

### Value

Defines an IDL simple scalar value, array or an IDLgrImage object reference to be associated with Name. IDL strings, structures, pointers, and undefined variables are not allowed and will cause an error that halts execution. IDL converts all integer types to 32-bit long and converts all floating types to 32-bit float before submitting the data to the shader program.

If this argument is set to a 1-D or 2-D IDLgrImage object reference (the only type of object reference permitted), IDL loads the image data into an OpenGL texture that can be accessed using the uniform variable specified. This uniform variable must be defined as GLSL type sampler1D or sampler2D in the shader program.

If the dimensions of the IDLgrImage are not a power of 2 then the image will be padded to the next largest power of 2. If the dimensions of the IDLgrImage are larger than MAX_TEXTURE_DIMENSIONS (returned by GetDeviceInfo) then the image will be scaled down to MAX_TEXTURE_DIMENSIONS. Keep this in mind when generating texture coordinates to access the texture map. The IDLgrImage passed to SetUniformVariable cannot be tiled.

## Keywords

None.

## Version History

6.4 | Introduced

## See Also

IDLgrShader::GetUniformVariable