64 enum { USE_GLSL_BASE_VERSION = -1,
65 USE_SHADER_GLSL_VERSION = 0 };
67 RE_Shader(
const char *program_name,
int shader_version);
74 virtual int64 getMemoryUsage(
bool inclusive)
const;
78 void setRegisterProgram(
bool register_program);
95 int shader_version = 0,
105 const char **shader_files,
106 int shader_version = USE_SHADER_GLSL_VERSION,
108 bool use_houdini_libs =
true,
110 bool register_program =
true,
111 const char *extra_defines =
nullptr,
113 bool dump_src_on_error =
true);
118 const char *shader_files,
119 int shader_version = USE_SHADER_GLSL_VERSION,
121 bool use_houdini_libs =
true,
123 bool register_program =
true,
124 const char *extra_defines =
nullptr,
126 bool dump_src_on_error =
true);
129 const char *
getName()
const {
return myProgramName; }
147 static int getBaseGLSLVersion();
154 static int determineCodeVersion(
const char *shader_string);
159 const char *
name = 0) = 0;
172 const char *shader_name =
nullptr,
173 const char *defines =
"",
174 int default_code_version=USE_GLSL_BASE_VERSION,
175 int geom_max_verts = -1,
177 bool print_source =
true);
181 const char *shader_source,
182 const char *shader_name,
185 bool print_source =
true,
187 bool preprocess =
false);
191 void useHoudiniLibraryFuncs();
194 void useDefaultAttribMap(
bool enable =
true);
198 void useExplicitAttribMap(
bool enable =
true);
279 maxverts = myGeoShaderMaxVertices;
280 input_type = myGeoShaderInputPrims;
281 output_type= myGeoShaderOutputPrims;
302 bool give_ownership =
false);
305 RE_Geometry *getCaptureGeometry(
bool take_ownership =
false);
308 bool addFeedbackBuffer(
const char *attrib_name);
311 bool removeFeedbackBuffer(
const char *attrib_name);
314 void setFeedbackBufferSize(
int num_vertices);
317 void clearAllFeedbackBuffers();
320 bool hasTransformFeedback()
const;
335 int texlevel = 0)
const;
342 bool isFeedbackBufferUsed(
const char *attrib)
const;
345 virtual bool bindForTransformFeedback(
RE_Render *
r);
359 { myShadingRate =
SYSclamp(rate,0.0,1.0); }
361 {
return SYSmax(myShadingRate,0.0); }
426 const char *relative_to) = 0;
443 const char *getTextureSamplerName(
int tex_index)
const;
456 int array_index = 0)
const;
478 const char *getUniformName(
int idx)
const;
481 int getUniformLocation(
int idx)
const;
487 int getBlockIndexForUniform(
int idx)
const;
501 int array_size=1,
int *saved_idx=0)=0;
505 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;
518 int array_size = 1,
int *saved_idx=0) =0;
522 int array_size=1,
int *saved_idx=0)=0;
525 int array_size=1,
int *saved_idx=0)=0;
528 int array_size=1,
int *saved_idx=0)=0;
531 int array_size=1,
int *saved_idx=0)=0;
535 int array_size=1,
int *saved_idx=0)=0;
538 int array_size=1,
int *saved_idx=0)=0;
541 int array_size=1,
int *saved_idx=0)=0;
544 int array_size=1,
int *saved_idx=0)=0;
548 int array_size=1,
int *saved_idx=0)=0;
551 int array_size=1,
int *saved_idx=0)=0;
554 int array_size=1,
int *saved_idx=0)=0;
558 int array_size=1,
int *saved_idx=0)=0;
561 int array_size=1,
int *saved_idx=0)=0;
564 int array_size=1,
int *saved_idx=0)=0;
623 {
return myBuiltInUniforms; }
629 bool force_update =
false);
637 std::ostream *os =
nullptr)
const {}
703 int index = -1)
const
721 int block_index = -1)
729 { myLightsId=-1; myLightsSerial=-1; }
781 {
return myAttribNames.entries() > 0; }
785 {
return myAttribNames.entries(); }
788 {
return myTessEvalShaders.entries()>0; }
792 {
return myAttribNames(i); }
800 {
return myAttribLocations(i); }
804 {
return myAttribTypes(i); }
808 {
return myAttribSizes(i); }
812 {
return myAttribNames; }
816 {
return myAttribLocations; }
820 {
return myAttribSizes; }
823 const char * getAttribNameForLocation(
int loc)
const;
827 {
return myAttrModeLocs(t); }
831 {
return myAttrSamplerLocs(t); }
835 {
return myBuiltInAttribNames.entries(); }
838 {
return myBuiltInAttribNames(i); }
842 {
return myBufferAttribNames.entries(); }
845 {
return myBufferAttribNames(i); }
847 {
return myBufferAttribGenIDs(i); }
850 int getNumBufferTextures()
const;
852 const char * getBufferTextureName(
int i)
const;
856 bool hasBufferTexture(
const char *
name)
const;
863 bool getAttribute(
const char *attrib_name,
873 return getAttribute(attrib_name,loc,t,size);
880 bool getAttributeIndex(
int index,
886 void printAttributes(std::ostream *os =
nullptr)
const;
897 virtual void loadShaderTexMaps(
RE_Render *) = 0;
898 virtual void loadBoundTextures(
RE_Render *
r) = 0;
899 virtual void unloadBoundTextures(
RE_Render *
r) = 0;
915 void limitTextureSize(
bool limit,
int w,
int h);
937 { myTextureAnisotropy =
samples; }
939 {
return myTextureAnisotropy; }
954 unsigned int vertex_stride = 0,
956 int instance_group = 0);
965 bool matchesLights(
int light_serial,
int light_id)
const;
966 void setLightID(
int light_serial,
int light_id,
int mask);
981 static RE_Shader *getShader(
int program_object);
985 static bool loadFile(
const char *
filename,
990 int default_code_version = 0,
992 bool adjust_line_num =
false,
993 bool loadingInclude =
false,
1004 : myFunc(
func), myFile(file), myDeps(deps), myType(
t),
1005 myGLMajor(glmaj), myGLMinor(glmin)
1016 static bool getCodeBlock(
const char *block_name,
1026 virtual int getAttributeIndex(
const char *
name)
const;
1038 const char **getTransformFeedbackAttribs(
int &num_attribs);
1045 : myFile(file), myFunc(func), myStage(s), myLoaded(false) {}
1052 virtual re_LibFunc* getShaderLibrary()
const;
1054 static void scanSourceForFuncs(
const char *line,
1061 static void processCodeLine(
const char *line,
1063 const char *defines,
1067 int default_code_version,
1068 bool &found_codeversion,
1070 bool adjust_line_num,
1074 { myGeoShaderMaxVertices = max_verts; }
1154 virtual void applyShader(
RE_Render *
r,
bool update_re =
true) = 0;
1156 virtual void removeShader(
RE_Render *
r,
bool update_re =
true) = 0;
1161 static void unregisterProgram(
int program_object);
1167 const char *basepath,
1177 bool &use_attrib_map,
1178 bool &explicit_attrib_map,
1189 const char *
name = 0);
1196 int64 mem = inclusive ?
sizeof(*this) : 0;
1197 mem += myName.getMemoryUsage(
false);
1198 mem += myFilename.getMemoryUsage(
false);
1207 { myFilename.harden(fname); }
1214 bool dump_source_on_error =
true,
1215 const char *defines =
nullptr,
1216 int default_code_version
1223 const char *source_code,
1226 bool dump_source_on_error =
true) = 0;
1281 int64 mem = inclusive ?
sizeof(*this) : 0;
1282 mem +=
name.getMemoryUsage(
false);
1307 return bindVariableInt(r, name, &v);
1313 return bindVariable1(r, name, &v);
1319 return bindVariable1(r, name, &v);
1325 return bindVariable2(r, name, v.
data());
1333 c.
getRGB(col, col+1, col+2);
1334 return bindVariable3(r, name, col);
1343 c.
getRGB(col, col+1, col+2);
1345 return bindVariable4(r, name, col);
1352 return bindVariable3(r, name, v.
data());
1358 return bindVariable4(r, name, v.
data());
1364 return bindVariable2(r, name, v.
data());
1370 return bindVariable3(r, name, v.
data());
1376 return bindVariable4(r, name, v.
data());
1383 return bindVariableInt2(r, name, v.
data());
1389 return bindVariableInt3(r, name, v.
data());
1395 return bindVariableInt4(r, name, v.
data());
1403 return bindVariable2(r, name, vals(0).
data(), vals.
entries());
1411 return bindVariable4(r, name, vals(0).
data(), vals.
entries());
1418 return bindVariable2(r, name, vals(0).
data(), vals.
entries());
1425 return bindVariable4(r, name, vals(0).
data(), vals.
entries());
1431 return bindMatrix2(r, name, m.
data());
1437 return bindMatrix3(r, name, m.
data());
1443 return bindMatrix4(r, name, m.
data());
1449 return bindMatrix2(r, name, m.
data());
1455 return bindMatrix3(r, name, m.
data());
1461 return bindMatrix4(r, name, m.
data());
1467 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 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
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.
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'.
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.
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