H3D API  2.4.1
Classes | Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
H3D::ShaderPart Class Reference

The ShaderPart node defines the source for a single object to be used by a ComposedShader node. More...

#include <H3D/ShaderPart.h>

Inheritance diagram for H3D::ShaderPart:
Inheritance graph

Classes

class  SFShaderString
 Update the string to use as shader depending from the urls given. More...
 

Public Member Functions

 ShaderPart (Inst< SFNode > _metadata=0, Inst< MFString > _url=0, Inst< SFString > _type=0, Inst< SFShaderString > _shaderString=0, Inst< SFBool > _forceReload=0)
 Constructor.
 
virtual GLhandleARB compileShader ()
 Compile the shader using the shader_string field as text input. More...
 
void setParentComposedShader (ComposedShader *s)
 Set the ComposedShader instance.that this ShaderPart is a child to.
 
ComposedShadergetParentComposedShader ()
 Get the ComposedShader instance that this ShaderPart is a child to.
 
bool modifyShaderConstants (Field *field)
 Look for a constant with the name matching field->getName(). More...
 
bool replaceString (string &string_to_update, const std::string &string_start, const std::string &string_end, const std::string &to_insert, const std::string &conditional_string="")
 Look for string_start and string_end. More...
 
GLhandleARB getShaderHandle ()
 Get the handle to the shader object that currently is used for this ShaderPart.
 
virtual bool isCompiled ()
 Returns true if the shader part is compiled and up to date. More...
 
virtual string defaultXMLContainerField ()
 Returns the default xml containerField attribute value. More...
 
virtual X3DUrlObject::LoadStatus loadStatus ()
 The loadStatus function returns the status of the loading of the current urls in order to be used with the LoadSensor node.
 
- Public Member Functions inherited from H3D::X3DNode
 X3DNode (Inst< SFNode > _metadata=0)
 Constructor.
 
X3DMetadataObjectgetMetadataByName (const string &_name)
 Given a name, the first X3DMetadataObject in the metadata field that matches that name is returned. More...
 
- Public Member Functions inherited from H3D::Node
 Node ()
 Constructor.
 
virtual Nodeclone (bool deepCopy=true, DeepCopyMap *deepCopyMap=NULL)
 Returns a new instance of this node type with the same state as this one. More...
 
virtual ~Node ()
 Destructor.
 
X3DPrototypeInstancegetProtoInstanceParent ()
 If this node is the root node in the proto body of a X3DPrototypeInstance then this will return that node. More...
 
void setProtoInstanceParent (X3DPrototypeInstance *p)
 Set the X3DPrototypeInstance this node is the the root node if applicaple.
 
virtual void render ()
 the render() function is used for the depth-first rendering traversal of the scene-graph. More...
 
virtual void traverseSG (TraverseInfo &ti)
 traverseSG is called once per scenegraph loop on the scene in order to traverse the scenegraph. More...
 
virtual bool lineIntersect (const Vec3f &from, const Vec3f &to, LineIntersectResult &result)
 Detect intersection between a line segment and the Node. More...
 
virtual void closestPoint (const Vec3f &p, NodeIntersectResult &result)
 Find closest point on Node to p. More...
 
virtual bool movingSphereIntersect (H3DFloat radius, const Vec3f &from, const Vec3f &to, NodeIntersectResult &result)
 Detect collision between a moving sphere and the Node. More...
 
virtual FieldgetField (const string &_name) const
 return a pointer to the field specified by name within this instance
 
int addDestructCallback (void(*func)(Node *, void *), void *args)
 Add a callback function to be run on destruction of node. More...
 
int removeDestructCallback (void(*func)(Node *, void *), void *args)
 Add a callback function to be run on destruction of node. More...
 
- Public Member Functions inherited from H3D::X3DUrlObject
 X3DUrlObject (Inst< MFString > _url=0)
 Constructor.
 
virtual H3DFloat loadProgress ()
 The loadProgress() functions returns a value between 0 and 1 indicating how much of the current url has been loaded. More...
 
void setURLUsed (const string &_url_used)
 Set the url that is currently loaded.
 
const string & getURLUsed ()
 Get the url that is currently loaded.
 
void setURLBase (const string &_url_base)
 Set the url base address.
 
const string & getURLBase ()
 Get the current url base address.
 
string resolveURLAsFile (const string &url, bool *is_tmp_file=NULL)
 Get the url as a local file.
 
string resolveURLAsString (const string &url)
 Get the content of the URL as a string.
 
bool removeTmpFile (const string &file)
 Remove a tmpfile with the given name. More...
 

Public Attributes

H3DUniquePtr< SFStringtype
 The type field indicates whether this object shall be compiled as a vertex shader, fragment shader, or other future-defined shader type. More...
 
H3DUniquePtr< SFShaderStringshaderString
 A field that contains the string loaded from file and to be used as input to the shader. More...
 
H3DUniquePtr< SFBoolforceReload
 The forceReload field is used to force the reloading of this shaderPart and also cause the composed shader recompile and relink. More...
 
- Public Attributes inherited from H3D::X3DNode
H3DUniquePtr< SFNodemetadata
 Meta data about the node. More...
 
- Public Attributes inherited from H3D::X3DUrlObject
H3DUniquePtr< MFStringurl
 The urls in decreasing order of preference.
 

Static Public Attributes

static H3DNodeDatabase database
 The H3DNodeDatabase for this node.
 
- Static Public Attributes inherited from H3D::X3DNode
static H3DNodeDatabase database
 The H3DNodeDatabase for this node.
 

Protected Member Functions

bool getConstantVariableString (Field *const in_variable, std::string &out_name, std::string &out_type, std::string &out_field_value)
 Extract all necessary data from a field.
 
std::string shaderStringFromURL (const std::string &shader_url)
 Given the URL of a shader source, return the source code, or "" on failure.
 
std::string preProcess (const std::string &input, const std::string &_url, int depth=0)
 Given the raw shader source, return the preprocessed source having parsed all preprocessor commands, e.g., includes etc. More...
 
void updateShaderConstantValues (std::string &input, bool update_all_values)
 Update shader string with new values for constants. More...
 
void updateSinglePassStereoValues (std::string &input)
 Update shader string for us in single pass stereo render mode.
 
- Protected Member Functions inherited from H3D::Node
void cloneFieldValue (Field &_from, Field &_to, bool deepCopy, DeepCopyMap &deepCopyMap)
 A helper function for the clone() method. More...
 
- Protected Member Functions inherited from H3D::X3DUrlObject
string resolveURL (const string &_url, bool return_contents, bool *is_tmp_file=NULL)
 Helper function for resolveURLAs*() functions.
 
void addInlinePrefix (const string &s)
 Add a inline prefix that this node supports.
 
int getInlinedContentOffset (const std::string &url)
 If the URL contains any inline prefix, return the index of the start of the inlined content. More...
 

Protected Attributes

ComposedShaderparent_composed_shader
 The ComposedShader instance that this ShaderPart is a child to.
 
GLhandleARB shader_handle
 The handle to the shader object used for this ShaderPart.
 
- Protected Attributes inherited from H3D::X3DUrlObject
string url_used
 If loadStatus() returns LOADED this string should contain the url that is loaded. More...
 
string url_base
 The base URL for urls in this url object. More...
 
list< string > supported_inline_prefixes
 A list of inline prefixes that are supported by this url object. More...
 

Additional Inherited Members

- Public Types inherited from H3D::Node
typedef std::map< Node *, Node * > DeepCopyMap
 A map type used during a deep copy clone() to map from original nodes to cloned nodes.
 
- Public Types inherited from H3D::X3DUrlObject
enum  LoadStatus { INIT , LOADED , LOADING , FAILED }
 The load status of the given url. More...
 
- Static Public Member Functions inherited from H3D::Node
static unsigned int nrNodesAlive ()
 Returns the nr of nodes currently alive, i.e. nodes created but not destructed.
 
static int nrNodesCreated ()
 Returns the number of nodes created in total since the start of the program.
 
- Static Protected Member Functions inherited from H3D::Node
static NodegetClonedInstance (Node *original, bool deepCopy, DeepCopyMap &deepCopyMap)
 A helper function for nodes that implement clone() More...
 

Detailed Description

The ShaderPart node defines the source for a single object to be used by a ComposedShader node.

The source is not required to be a complete shader for all of the vertex/fragment processing.

The type field indicates whether this object shall be compiled as a vertex shader, fragment shader, or other future-defined shader type.

The shader source is read from the URL specified by the url field. When the url field contains no values ([]), this object instance is ignored. Shader source files shall be plain text encoded as specified for MIME type text/plain and interpreted according to the type field.

Preprocessor
Preprocessor commands are supported as an extension to the X3D standard. These begin "#pragma h3dapi [command] [arguments]".

Supported commands:

Examples:

Internal routes:

Member Function Documentation

◆ compileShader()

GLhandleARB ShaderPart::compileShader ( )
virtual

Compile the shader using the shader_string field as text input.

Returns a handle to the compiled shader or 0 if compiling failed.

References shader_handle, and shaderString.

Referenced by H3D::ComposedShader::render().

◆ defaultXMLContainerField()

virtual string H3D::ShaderPart::defaultXMLContainerField ( )
inlinevirtual

Returns the default xml containerField attribute value.

For this node it is "parts".

Reimplemented from H3D::Node.

◆ isCompiled()

bool ShaderPart::isCompiled ( )
virtual

Returns true if the shader part is compiled and up to date.

False if compilation is required.

References shaderString.

Referenced by H3D::ComposedShader::render().

◆ modifyShaderConstants()

bool H3D::ShaderPart::modifyShaderConstants ( Field field)

Look for a constant with the name matching field->getName().

Then replace the value of that constant with the value of field->getValue(). Returns true on success.

References shaderString.

◆ preProcess()

std::string ShaderPart::preProcess ( const std::string &  input,
const std::string &  _url,
int  depth = 0 
)
protected

Given the raw shader source, return the preprocessed source having parsed all preprocessor commands, e.g., includes etc.

Parameters
inputThe raw shader source code, including preprocessor commands
_urlThe URL from which the raw source code was loaded (used for base of relative includes)
depthThe current recursion depth. The root caller should always leave this as the default 0.
Returns
The preprocessed shader source, with all preprocessor commands applied.

◆ replaceString()

bool H3D::ShaderPart::replaceString ( std::string &  shader_string,
const std::string &  string_start,
const std::string &  string_end,
const std::string &  to_insert,
const std::string &  conditional_string = "" 
)

Look for string_start and string_end.

If to_insert can fit in properly, we replace. Returns true on success.

If conditional_string isn't empty, we need to be able to find it, else we return false;

◆ updateShaderConstantValues()

void ShaderPart::updateShaderConstantValues ( std::string &  input,
bool  update_all_values 
)
protected

Update shader string with new values for constants.

Parameters
inputShader string to update.
update_all_valuesIf true, all constants will be updated, if false, only the constants that have changed will be updated.

Member Data Documentation

◆ forceReload

H3DUniquePtr< SFBool > H3D::ShaderPart::forceReload

The forceReload field is used to force the reloading of this shaderPart and also cause the composed shader recompile and relink.

Directly change its value from tree view of h3dviewer, or route someother field to it will both work.

Access type: inputOutput

Referenced by H3D::ShaderPart::SFShaderString::doFullRebuild(), and ShaderPart().

◆ shaderString

H3DUniquePtr< SFShaderString > H3D::ShaderPart::shaderString

A field that contains the string loaded from file and to be used as input to the shader.

Access should logically be outputOnly, but is inputOutput for backward compatibility (to avoid access exceptions in external code). It may be changed in future (major) releases.

Access type: inputOutput

Referenced by compileShader(), isCompiled(), modifyShaderConstants(), setParentComposedShader(), and ShaderPart().

◆ type

H3DUniquePtr< SFString > H3D::ShaderPart::type

The type field indicates whether this object shall be compiled as a vertex shader, fragment shader, or other future-defined shader type.

Valid values are "VERTEX", "FRAGMENT","GEOMETRY" "TESS_CONTROL" or "TESS_EVALUATION".

Access type: initializeOnly

Referenced by H3D::H3DGeneratedShaderNode::H3DGeneratedShaderNode(), and ShaderPart().


The documentation for this class was generated from the following files: