65 enum { USE_GLSL_BASE_VERSION = -1,
66 USE_SHADER_GLSL_VERSION = 0 };
68 RE_Shader(
const char *program_name,
int shader_version);
75 virtual int64 getMemoryUsage(
bool inclusive)
const;
79 void setRegisterProgram(
bool register_program);
96 int shader_version = 0,
106 const char **shader_files,
107 int shader_version = USE_SHADER_GLSL_VERSION,
109 bool use_houdini_libs =
true,
111 bool register_program =
true,
112 const char *extra_defines =
nullptr,
114 bool dump_src_on_error =
true);
119 const char *shader_files,
120 int shader_version = USE_SHADER_GLSL_VERSION,
122 bool use_houdini_libs =
true,
124 bool register_program =
true,
125 const char *extra_defines =
nullptr,
127 bool dump_src_on_error =
true);
130 const char *
getName()
const {
return myProgramName; }
148 static int getBaseGLSLVersion();
155 static int determineCodeVersion(
const char *shader_string);
160 const char *
name = 0) = 0;
173 const char *shader_name =
nullptr,
174 const char *defines =
"",
175 int default_code_version=USE_GLSL_BASE_VERSION,
176 int geom_max_verts = -1,
178 bool print_source =
true);
182 const char *shader_source,
183 const char *shader_name,
186 bool print_source =
true,
188 bool preprocess =
false);
192 void useHoudiniLibraryFuncs();
195 void useDefaultAttribMap(
bool enable =
true);
199 void useExplicitAttribMap(
bool enable =
true);
280 maxverts = myGeoShaderMaxVertices;
281 input_type = myGeoShaderInputPrims;
282 output_type= myGeoShaderOutputPrims;
303 bool give_ownership =
false);
306 RE_Geometry *getCaptureGeometry(
bool take_ownership =
false);
309 bool addFeedbackBuffer(
const char *attrib_name);
312 bool removeFeedbackBuffer(
const char *attrib_name);
315 void setFeedbackBufferSize(
int num_vertices);
318 void clearAllFeedbackBuffers();
321 bool hasTransformFeedback()
const;
336 int texlevel = 0)
const;
343 bool isFeedbackBufferUsed(
const char *attrib)
const;
346 virtual bool bindForTransformFeedback(
RE_Render *
r);
360 { myShadingRate =
SYSclamp(rate,0.0,1.0); }
362 {
return SYSmax(myShadingRate,0.0); }
427 const char *relative_to) = 0;
444 const char *getTextureSamplerName(
int tex_index)
const;
457 int array_index = 0)
const;
479 const char *getUniformName(
int idx)
const;
482 int getUniformLocation(
int idx)
const;
488 int getBlockIndexForUniform(
int idx)
const;
502 int array_size=1,
int *saved_idx=0)=0;
506 int array_size=1,
int *saved_idx=0)=0;
510 int array_size=1,
int *saved_idx=0)=0;
514 int array_size=1,
int *saved_idx=0)=0;
519 int array_size = 1,
int *saved_idx=0) =0;
523 int array_size=1,
int *saved_idx=0)=0;
526 int array_size=1,
int *saved_idx=0)=0;
529 int array_size=1,
int *saved_idx=0)=0;
532 int array_size=1,
int *saved_idx=0)=0;
536 int array_size=1,
int *saved_idx=0)=0;
539 int array_size=1,
int *saved_idx=0)=0;
542 int array_size=1,
int *saved_idx=0)=0;
545 int array_size=1,
int *saved_idx=0)=0;
549 int array_size=1,
int *saved_idx=0)=0;
552 int array_size=1,
int *saved_idx=0)=0;
555 int array_size=1,
int *saved_idx=0)=0;
559 int array_size=1,
int *saved_idx=0)=0;
562 int array_size=1,
int *saved_idx=0)=0;
565 int array_size=1,
int *saved_idx=0)=0;
624 {
return myBuiltInUniforms; }
630 bool force_update =
false);
638 std::ostream *os =
nullptr)
const {}
704 int index = -1)
const
722 int block_index = -1)
730 { myLightsId=-1; myLightsSerial=-1; }
782 {
return myAttribNames.entries() > 0; }
786 {
return myAttribNames.entries(); }
789 {
return myTessEvalShaders.entries()>0; }
793 {
return myAttribNames(i); }
801 {
return myAttribLocations(i); }
805 {
return myAttribTypes(i); }
809 {
return myAttribSizes(i); }
813 {
return myAttribNames; }
817 {
return myAttribLocations; }
821 {
return myAttribSizes; }
824 const char * getAttribNameForLocation(
int loc)
const;
828 {
return myAttrModeLocs(t); }
832 {
return myAttrSamplerLocs(t); }
836 {
return myBuiltInAttribNames.entries(); }
839 {
return myBuiltInAttribNames(i); }
843 {
return myBufferAttribNames.entries(); }
846 {
return myBufferAttribNames(i); }
848 {
return myBufferAttribGenIDs(i); }
851 int getNumBufferTextures()
const;
853 const char * getBufferTextureName(
int i)
const;
857 bool hasBufferTexture(
const char *
name)
const;
864 bool getAttribute(
const char *attrib_name,
874 return getAttribute(attrib_name,loc,t,size);
881 bool getAttributeIndex(
int index,
887 void printAttributes(std::ostream *os =
nullptr)
const;
898 virtual void loadShaderTexMaps(
RE_Render *) = 0;
899 virtual void loadBoundTextures(
RE_Render *
r) = 0;
900 virtual void unloadBoundTextures(
RE_Render *
r) = 0;
916 void limitTextureSize(
bool limit,
int w,
int h);
938 { myTextureAnisotropy =
samples; }
940 {
return myTextureAnisotropy; }
955 unsigned int vertex_stride = 0,
957 int instance_group = 0);
966 bool matchesLights(
int light_serial,
int light_id)
const;
967 void setLightID(
int light_serial,
int light_id,
int mask);
982 static RE_Shader *getShader(
int program_object);
986 static bool loadFile(
const char *
filename,
991 int default_code_version = 0,
993 bool adjust_line_num =
false,
994 bool loadingInclude =
false,
1005 : myFunc(
func), myFile(file), myDeps(deps), myType(
t),
1006 myGLMajor(glmaj), myGLMinor(glmin)
1017 static bool getCodeBlock(
const char *block_name,
1027 virtual int getAttributeIndex(
const char *
name)
const;
1039 const char **getTransformFeedbackAttribs(
int &num_attribs);
1046 : myFile(file), myFunc(func), myStage(s), myLoaded(false) {}
1053 virtual re_LibFunc* getShaderLibrary()
const;
1055 virtual const char* getPlatformDefines(
RE_Render*
r)
const;
1057 static void scanSourceForFuncs(
const char *line,
1064 static void processCodeLine(
const char *line,
1066 const char *defines,
1070 int default_code_version,
1071 bool &found_codeversion,
1073 bool adjust_line_num,
1077 { myGeoShaderMaxVertices = max_verts; }
1157 virtual void applyShader(
RE_Render *
r,
bool update_re =
true) = 0;
1159 virtual void removeShader(
RE_Render *
r,
bool update_re =
true) = 0;
1164 static void unregisterProgram(
int program_object);
1170 const char *basepath,
1180 bool &use_attrib_map,
1181 bool &explicit_attrib_map,
1192 const char *
name = 0);
1199 virtual
int64 getMemoryUsage(
bool inclusive)
const
1201 int64 mem = inclusive ?
sizeof(*this) : 0;
1202 mem += myName.getMemoryUsage(
false);
1203 mem += myFilename.getMemoryUsage(
false);
1212 { myFilename.harden(fname); }
1219 bool dump_source_on_error =
true,
1220 const char *defines =
nullptr,
1221 int default_code_version
1228 const char *source_code,
1231 bool dump_source_on_error =
true) = 0;
1286 int64 mem = inclusive ?
sizeof(*this) : 0;
1287 mem +=
name.getMemoryUsage(
false);
1312 return bindVariableInt(r, name, &v);
1318 return bindVariable1(r, name, &v);
1324 return bindVariable1(r, name, &v);
1330 return bindVariable2(r, name, v.
data());
1338 c.
getRGB(col, col+1, col+2);
1339 return bindVariable3(r, name, col);
1348 c.
getRGB(col, col+1, col+2);
1350 return bindVariable4(r, name, col);
1357 return bindVariable3(r, name, v.
data());
1363 return bindVariable4(r, name, v.
data());
1369 return bindVariable2(r, name, v.
data());
1375 return bindVariable3(r, name, v.
data());
1381 return bindVariable4(r, name, v.
data());
1388 return bindVariableInt2(r, name, v.
data());
1394 return bindVariableInt3(r, name, v.
data());
1400 return bindVariableInt4(r, name, v.
data());
1408 return bindVariable2(r, name, vals(0).
data(), vals.
entries());
1416 return bindVariable4(r, name, vals(0).
data(), vals.
entries());
1423 return bindVariable2(r, name, vals(0).
data(), vals.
entries());
1430 return bindVariable4(r, name, vals(0).
data(), vals.
entries());
1436 return bindMatrix2(r, name, m.
data());
1442 return bindMatrix3(r, name, m.
data());
1448 return bindMatrix4(r, name, m.
data());
1454 return bindMatrix2(r, name, m.
data());
1460 return bindMatrix3(r, name, m.
data());
1466 return bindMatrix4(r, name, m.
data());
1472 return myAttribGenIDs(i);
const char * getBuiltinAttrib(int i) const
Return the name of GL-builtin vertex shader input at index 'i'.
int getCodeVersion() const
const UT_String & getFilename() const
virtual RE_UniformBlockHandle copyUniformBlock(const char *name, bool data_too) const
Copies the structure of the named uniform block, and possibly the data.
virtual bool updateUniformBlock(const RE_UniformBlockHandle &b) const
UT_Matrix4T< fpreal64 > UT_Matrix4D
bool hasShaderAttribs() const
Return if the vertex shader has input attributes.
RE_GPUType getShaderAttribType(int i) const
Return the type of vertex shader input at index 'i'.
int getProgram() const
Raw GL id of the shader.
GT_API const UT_StringHolder filename
UT_IntArray myAttribSizes
UT_ValArray< RE_ShaderStage * > myTessEvalShaders
virtual int getMaxUniformBlockSizeB(RE_Render *)
Returns the OpenGL maximum size of a uniform block, in bytes.
virtual RE_UniformBlockHandle createStorageBlock(const char *name, int array_size)
bool isSampleShading() const
UT_StringList myBufferAttribNames
void getRGB(float *r, float *g, float *b) const
virtual void printUniforms(RE_Render *r, std::ostream *os=nullptr) const
Prints all the active uniforms plus their values to stream os (or cerr)
UT_Array< RE_GenericAttribID > myBufferAttribGenIDs
void setFilename(const char *fname)
UT_IntArray myImageUniforms
UT_IntrusivePtr< RE_UniformBlock > RE_UniformBlockHandle
virtual int getUniformBlockIndex(const char *name) const
Returns the block binding point of the named block.
const UT_IntArray & getShaderAttribSizes() const
Return an int array of all vertex shader input sizes.
RE_TextureCompress myTexFormat
A collection of vertex arrays defining a geometry object. This class acts as a wrapper around multipl...
int getMaxTextureWidth() const
Limit the resolution of the textures to a max width and height.
bool hasTessellation() const
virtual bool detachStorageBinding(const char *bind_name)
Unbind the block or buffer attached to binding point 'bind_name'.
virtual void removeOverrideBlock(RE_UniformBlock *b)
Remove a specific override block from the shader.
virtual RE_UniformBlockHandle getStorageBlock(const char *name)
Return the block definition for storage block 'name'.
void setCodeVersion(int v)
GLenum GLenum GLsizei void * image
bool bindColor(RE_Render *r, const UT_StringHolder &name, const UT_Color &c)
Set the value of a uniform. Set uniform value(s) for a specific type. False will be returned if the s...
UT_StringList myAttribNames
bool bindMatrix(RE_Render *r, const UT_StringHolder &name, const UT_Matrix2F &m)
Set the value of a uniform. Set uniform value(s) for a specific type. False will be returned if the s...
virtual RE_UniformBlockHandle getStorageBlockBinding(const char *name)
Return the storage block bound to 'name' (bound by attachStorageBlock)
unsigned long long uint64
virtual RE_UniformBlockHandle getOverrideBlock(int) const
Return the currently bound override block for an index, if any is bound.
const char * getName() const
Readable name of the shader.
UT_ValArray< re_VertexName * > myTransformFeedbackVertices
void disableShadingRate()
const T * data() const
Return the raw matrix data.
constexpr SYS_FORCE_INLINE const T * data() const noexcept
bool bindInt(RE_Render *r, const UT_StringHolder &name, int v)
Set the value of a uniform. Set uniform value(s) for a specific type. False will be returned if the s...
void setAnisotropySamples(int samples)
Set anisotropic filtering for textures bound via bindTextureMap()
int getMaxTextureHeight() const
Limit the resolution of the textures to a max width and height.
UT_ValArray< RE_UniformData * > myUniforms
int getCodeVersion() const
Returns the version of the shader (110,120,130,140,150,330,400,410).
RE_GenericAttribID getShaderAttribGenID(int i) const
UT_Array< RE_GenericAttribID > myAttribGenIDs
UT_Array< re_NeededLibFuncs > * myNeededLibraryFuncs
virtual bool initUniformBlock(RE_Render *r, RE_UniformBlock *block, int index=-1) const
Initialize a uniform block based on this shader's block layout Initializes a uniform block with the p...
GLenum GLuint GLint GLint layer
bool hasAttribute(const char *attrib_name) const
Simpler version of getAttribute() - just returns if the attribute exists.
re_NeededLibFuncs(const char *file, const char *func, RE_ShaderType s)
RE_VertexMap * myVertexMap
virtual RE_UniformBlockHandle getUniformBlock(int) const
Return an attached uniform block by index.
UT_StringList myBuiltInAttribNames
RE_Geometry * myTransformFeedbackGeometry
virtual int getNumUniformBlocks() const
Returns the number of blocks and specific uniform blocks.
GLint GLint GLsizei GLint GLenum GLenum type
int getNumTextures() const
Return the number of samplers this shader references.
UT_IntArray myAttrModeLocs
UT_IntArray myNumTexturesPerStage
UT_IntArray myDrawBoundTextures
virtual bool detachAllUniformBlocks()
Detaches all blocks referenced by this shader.
int getShaderAttribSize(int i) const
Return the vector size of vertex shader input at index 'i'.
virtual RE_UniformBlockHandle detachUniformBlock(const char *)
Detach a named RE_UniformBlock from this shader Detach a single uniform block by name or pointer...
virtual bool detachStorageBuffer(RE_VertexArray *raw_buffer)
bool mipMapTextures() const
Enable or disable mipmapping for textures bound via bindTextureMap()
UT_ValArray< RE_ShaderStage * > myGeometryShaders
bool bindDouble(RE_Render *r, const UT_StringHolder &name, double v)
Set the value of a uniform. Set uniform value(s) for a specific type. False will be returned if the s...
UT_ValArray< const RE_Uniform * > myBuiltInLastUniform
UT_IntArray myAttribLocations
UT_Vector3T< T > SYSclamp(const UT_Vector3T< T > &v, const UT_Vector3T< T > &min, const UT_Vector3T< T > &max)
GLint GLint GLsizei GLint GLenum format
int getAttributeModeLoc(RE_GenericAttribID t) const
Return the default GL location of generic vertex attribute 't'.
GLsizei GLsizei GLchar * source
UT_ValArray< RE_ShaderStage * > myTessControlShaders
bool bindVectors(RE_Render *r, const UT_StringHolder &name, const UT_Vector2FArray &vals)
Set the value of a uniform. Set uniform value(s) for a specific type. False will be returned if the s...
UT_SymbolMap< int > myUniformBlockTable
const char * getShaderAttribName(int i) const
Return the name of vertex shader input at index 'i'.
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
int getNumUniforms() const
Returns the number of active uniforms in this shader.
bool bindFloat(RE_Render *r, const UT_StringHolder &name, float v)
Set the value of a uniform. Set uniform value(s) for a specific type. False will be returned if the s...
bool isLinked() const
True if the shader has been successfully linked.
constexpr SYS_FORCE_INLINE const T * data() const noexcept
UT_IntArray myAttrSamplerLocs
virtual int overrideUniformBlock(RE_UniformBlock *block, int block_index=-1)
GLfloat GLfloat GLfloat alpha
virtual bool detachUniformBlock(RE_UniformBlock *)
Detach a specific RE_UniformBlock from this shader.
GLuint const GLchar * name
virtual bool attachUniformBlock(RE_UniformBlock *)
Attach an RE_UniformBlock to this shader Attach a single uniform block to the shader. The shader owns the block while attached, and will delete it if the shader is deleted, or may delete it if linkShaders() is called and it is no longer in use. If you want to cache a block, detach it when you're done with the shader. If a block with the same name is already attached to this shader, it will be deleted.
int getAnisotropySamples() const
Set anisotropic filtering for textures bound via bindTextureMap()
GLboolean GLboolean GLboolean b
virtual bool attachStorageBlock(const RE_UniformBlockHandle &block)
const UT_IntArray & getBuiltInUniformList() const
Returns a list of RE_UniformBuiltIn IDs this shader uses.
RE_ShaderType getShaderType() const
UT_ValArray< RE_ShaderStage * > myVertexShaders
int getNumBufferAttribs() const
Return the number of texture-buffer object attributes.
FS_API bool cleanup(UT_StringArray &removed, UT_StringArray &error_files, exint &memory_freed, bool dry_run, const char *override_path=nullptr)
re_LibFunc(const char *func=0, const char *file=0, const char *deps=0, RE_ShaderType t=RE_SHADER_FRAGMENT, int glmaj=0, int glmin=0)
GT_API const UT_StringHolder version
void setTextureScale(float sc)
Scale by a constant scale factor for textures bound via bindTextureMap()
int getLightMask() const
Cached RE_LightList information (uniform blocks)
exint entries() const
Alias of size(). size() is preferred.
void setTextureFormat(RE_TextureCompress format)
Override texture compression for texture bound via bindTextureMap()
fpreal getShadingRate() const
virtual RE_VertexArray * getStorageBufferBinding(const char *name)
Return the raw buffer bound to 'name' (bound by attachStorageBlock)
RE_TextureCompress getTextureFormat() const
Override texture compression for texture bound via bindTextureMap()
void setGeomMaxVerts(int max_verts)
UT_Array< RE_GPUType > myAttribTypes
GLfloat GLfloat GLfloat GLfloat h
const UT_StringList & getShaderAttribNames() const
Return a string array of all vertex shader input names.
void setShadingRate(fpreal rate)
const T * data() const
Return the raw matrix data.
UT_IntArray myBufferTextures
virtual void removeOverrideBlock(int)
Remove an override block from the shader, by index.
int getAttributeSamplerLoc(RE_GenericAttribID t) const
Return the texture sampler unit of a texture buffer object for 't'.
virtual int getMaxUniformBlocks(RE_Render *)
Returns the OpenGL maximum number of supported blocks.
virtual RE_UniformBlockHandle getUniformBlock(const char *name) const
Return an attached uniform block by name.
constexpr SYS_FORCE_INLINE const T * data() const noexcept
const char * getBufferAttrib(int i) const
Return the name of texture-buffer object attribute at index 'i'.
virtual void removeOverrideBlocks()
Remove all override blocks from the shader.
UT_ValArray< RE_ShaderStage * > myComputeShaders
const char * getDefines() const
Any define commands used to alter this shader.
UT_SymbolMap< int > myUniformTable
bool myTransformFeedbackGeometryOwned
UT_IntArray myBuiltInVersion
const UT_IntArray & getShaderAttribLocations() const
Return an int array of all vertex shader input locations.
void mipMapTextures(bool yes)
Enable or disable mipmapping for textures bound via bindTextureMap()
float getTextureScale() const
Scale by a constant scale factor for textures bound via bindTextureMap()
MX_RENDER_API ShaderPtr createShader(const string &shaderName, GenContext &context, ElementPtr elem)
Create a shader for a given element.
bool limitTextureSize() const
Limit the resolution of the textures to a max width and height.
virtual bool bindAllUniformBlocks(RE_Render *)
int64 myBuiltInUniformSerial
RE_PrimType myGeoShaderOutputPrims
GLubyte GLubyte GLubyte GLubyte w
bool myUseExplicitAttribMap
UT_StringList myFeedbackNames
bool bindVector(RE_Render *r, const UT_StringHolder &name, const UT_Vector2F &v)
Set the value of a uniform. Set uniform value(s) for a specific type. False will be returned if the s...
const char * getName() const
void getGeometryParms(int &maxverts, RE_PrimType &input_type, RE_PrimType &output_type) const
Fetch current geometry shader values. Return the geometry shader parameters specified by setGeometryP...
GLsizei GLenum GLenum * types
UT_ValArray< RE_ShaderStage * > myFragmentShaders
RE_PrimType myGeoShaderInputPrims
virtual bool detachStorageBlock(const RE_UniformBlockHandle &block)
const T * data() const
Return the raw matrix data.
int getNumShaderAttribs() const
Return the number of vertex shader input attributes.
bool myUseDefaultAttribMap
int getLinkSerial() const
Bumped every time a link is performed (uniforms invalidated, etc).
virtual bool attachStorageBuffer(RE_VertexArray *raw_buffer)
int getShaderAttribLocation(int i) const
Return the GL attribute location of vertex shader input at index 'i'.
int getNumBuiltinAttribs() const
Return the number of GL-builtin vertex shader inputs (gl_Vertex, gl_*)
exint getUniqueID() const
virtual void removeTextureRefs(RE_OGLTexture *)
UT_IntArray myTextureUniforms
UT_WorkBuffer myWorkBuffer
int myGeoShaderMaxVertices
UT_IntArray myBuiltInUniforms
RE_GenericAttribID getBufferAttribID(int i) const