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);
86 int shader_version = 0,
95 const char **shader_files,
96 int shader_version = USE_SHADER_GLSL_VERSION,
98 bool use_houdini_libs =
true,
100 bool register_program =
true,
101 const char *extra_defines =
nullptr);
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);
115 const char *
getName()
const {
return myProgramName; }
133 static int getBaseGLSLVersion();
137 static int determineCodeVersion(
const char *shader_string);
142 const char *
name = 0) = 0;
155 const char *shader_name =
nullptr,
156 const char *defines =
"",
157 int default_code_version=USE_GLSL_BASE_VERSION,
158 int geom_max_verts = -1);
162 const char *shader_source,
163 const char *shader_name,
169 void useHoudiniLibraryFuncs();
172 void useDefaultAttribMap(
bool enable =
true);
176 void useExplicitAttribMap(
bool enable =
true);
257 maxverts = myGeoShaderMaxVertices;
258 input_type = myGeoShaderInputPrims;
259 output_type= myGeoShaderOutputPrims;
280 bool give_ownership =
false);
283 RE_Geometry *getCaptureGeometry(
bool take_ownership =
false);
286 bool addFeedbackBuffer(
const char *attrib_name);
289 bool removeFeedbackBuffer(
const char *attrib_name);
292 void setFeedbackBufferSize(
int num_vertices);
295 void clearAllFeedbackBuffers();
298 bool hasTransformFeedback()
const;
313 int texlevel = 0)
const;
320 bool isFeedbackBufferUsed(
const char *attrib)
const;
323 virtual bool bindForTransformFeedback(
RE_Render *
r);
337 { myShadingRate =
SYSclamp(rate,0.0,1.0); }
339 {
return SYSmax(myShadingRate,0.0); }
404 const char *relative_to) = 0;
421 const char *getTextureSamplerName(
int tex_index)
const;
434 int array_index = 0)
const;
456 const char *getUniformName(
int idx)
const;
459 int getUniformLocation(
int idx)
const;
465 int getBlockIndexForUniform(
int idx)
const;
479 int array_size=1,
int *saved_idx=0)=0;
483 int array_size=1,
int *saved_idx=0)=0;
487 int array_size=1,
int *saved_idx=0)=0;
491 int array_size=1,
int *saved_idx=0)=0;
496 int array_size = 1,
int *saved_idx=0) =0;
500 int array_size=1,
int *saved_idx=0)=0;
503 int array_size=1,
int *saved_idx=0)=0;
506 int array_size=1,
int *saved_idx=0)=0;
509 int array_size=1,
int *saved_idx=0)=0;
513 int array_size=1,
int *saved_idx=0)=0;
516 int array_size=1,
int *saved_idx=0)=0;
519 int array_size=1,
int *saved_idx=0)=0;
522 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;
601 {
return myBuiltInUniforms; }
607 bool force_update =
false);
615 std::ostream *os =
nullptr)
const {}
681 int index = -1)
const
699 int block_index = -1)
707 { myLightsId=-1; myLightsSerial=-1; }
759 {
return myAttribNames.entries() > 0; }
763 {
return myAttribNames.entries(); }
766 {
return myTessEvalShaders.entries()>0; }
770 {
return myAttribNames(i); }
778 {
return myAttribLocations(i); }
782 {
return myAttribTypes(i); }
786 {
return myAttribSizes(i); }
790 {
return myAttribNames; }
794 {
return myAttribLocations; }
798 {
return myAttribSizes; }
801 const char * getAttribNameForLocation(
int loc)
const;
805 {
return myAttrModeLocs(t); }
809 {
return myAttrSamplerLocs(t); }
813 {
return myBuiltInAttribNames.entries(); }
816 {
return myBuiltInAttribNames(i); }
820 {
return myBufferAttribNames.entries(); }
823 {
return myBufferAttribNames(i); }
825 {
return myBufferAttribGenIDs(i); }
828 int getNumBufferTextures()
const;
830 const char * getBufferTextureName(
int i)
const;
834 bool hasBufferTexture(
const char *
name)
const;
841 bool getAttribute(
const char *attrib_name,
851 return getAttribute(attrib_name,loc,t,size);
858 bool getAttributeIndex(
int index,
864 void printAttributes(std::ostream *os =
nullptr)
const;
875 virtual void loadShaderTexMaps(
RE_Render *) = 0;
876 virtual void loadBoundTextures(
RE_Render *
r) = 0;
877 virtual void unloadBoundTextures(
RE_Render *
r) = 0;
893 void limitTextureSize(
bool limit,
int w,
int h);
915 { myTextureAnisotropy =
samples; }
917 {
return myTextureAnisotropy; }
932 unsigned int vertex_stride = 0,
934 int instance_group = 0);
943 bool matchesLights(
int light_serial,
int light_id)
const;
944 void setLightID(
int light_serial,
int light_id,
int mask);
959 static RE_Shader *getShader(
int program_object);
963 static bool loadFile(
const char *
filename,
968 int default_code_version = 0,
970 bool loadingInclude =
false);
977 virtual int getAttributeIndex(
const char *
name)
const;
988 const char **getTransformFeedbackAttribs(
int &num_attribs);
993 const char *basepath,
1003 bool &use_attrib_map,
1004 bool &explicit_attrib_map,
1014 : myFile(file), myFunc(func), myStage(s), myLoaded(false) {}
1020 static void scanSourceForFuncs(
const char *line,
1023 re_LibFunc *library,
1026 static bool getCodeBlock(
const char *block_name,
1030 { myGeoShaderMaxVertices = max_verts; }
1110 virtual void applyShader(
RE_Render *
r,
bool update_re =
true) = 0;
1112 virtual void removeShader(
RE_Render *
r,
bool update_re =
true) = 0;
1117 static void unregisterProgram(
int program_object);
1126 const char *
name = 0);
1133 int64 mem = inclusive ?
sizeof(*this) : 0;
1134 mem += myName.getMemoryUsage(
false);
1135 mem += myFilename.getMemoryUsage(
false);
1144 { myFilename.harden(fname); }
1151 bool dump_source_on_error =
true,
1152 const char *defines =
nullptr,
1153 int default_code_version
1155 int max_verts = -1);
1158 const char *source_code,
1161 bool dump_source_on_error =
true) = 0;
1216 int64 mem = inclusive ?
sizeof(*this) : 0;
1217 mem +=
name.getMemoryUsage(
false);
1242 return bindVariableInt(r, name, &v);
1248 return bindVariable1(r, name, &v);
1254 return bindVariable1(r, name, &v);
1260 return bindVariable2(r, name, v.
data());
1268 c.
getRGB(col, col+1, col+2);
1269 return bindVariable3(r, name, col);
1278 c.
getRGB(col, col+1, col+2);
1280 return bindVariable4(r, name, col);
1287 return bindVariable3(r, name, v.
data());
1293 return bindVariable4(r, name, v.
data());
1299 return bindVariable2(r, name, v.
data());
1305 return bindVariable3(r, name, v.
data());
1311 return bindVariable4(r, name, v.
data());
1318 return bindVariableInt2(r, name, v.
data());
1324 return bindVariableInt3(r, name, v.
data());
1330 return bindVariableInt4(r, name, v.
data());
1338 return bindVariable2(r, name, vals(0).
data(), vals.
entries());
1346 return bindVariable4(r, name, vals(0).
data(), vals.
entries());
1353 return bindVariable2(r, name, vals(0).
data(), vals.
entries());
1360 return bindVariable4(r, name, vals(0).
data(), vals.
entries());
1366 return bindMatrix2(r, name, m.
data());
1372 return bindMatrix3(r, name, m.
data());
1378 return bindMatrix4(r, name, m.
data());
1384 return bindMatrix2(r, name, m.
data());
1390 return bindMatrix3(r, name, m.
data());
1396 return bindMatrix4(r, name, m.
data());
1402 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
GLboolean GLboolean GLboolean b
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.
GLenum GLuint GLint GLint layer
virtual int64 getMemoryUsage(bool inclusive) const
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
GLenum GLenum GLenum input
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.
GLenum GLsizei GLenum GLenum const void * image
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)
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
GLuint const GLchar * name
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...
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)
GLubyte GLubyte GLubyte GLubyte w
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.
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
GLsizei GLsizei GLchar * source
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)
int getAttributeModeLoc(RE_GenericAttribID t) const
Return the default GL location of generic vertex attribute 't'.
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'.
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)
virtual bool detachUniformBlock(RE_UniformBlock *)
Detach a specific RE_UniformBlock from this shader.
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()
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.
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)
GLint GLint GLsizei GLint GLenum format
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
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
GLfloat GLfloat GLfloat alpha
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