Panda3D
Public Types | Public Member Functions | Static Public Member Functions | List of all members
Shader Class Reference

Summary: The Shader class is meant to select the Shader Language, select the available profile, compile the shader, and finally compile and store the shader parameters in the appropriate structure. More...

Inheritance diagram for Shader:
TypedWritableReferenceCount TypedWritable ReferenceCount TypedObject MemoryBase MemoryBase

Public Types

enum  AutoShaderBit {
  bit_AutoShaderNormal = 0, bit_AutoShaderGlow = 1, bit_AutoShaderGloss = 2, bit_AutoShaderRamp = 3,
  bit_AutoShaderShadow = 4
}
 
enum  AutoShaderSwitch {
  AS_normal = 1, AS_glow = 2, AS_gloss = 4, AS_ramp = 8,
  AS_shadow = 16
}
 
enum  ShaderLanguage { SL_none = 0, SL_Cg = 1, SL_GLSL = 2 }
 
enum  ShaderType {
  ST_none = 0, ST_vertex = 1, ST_fragment = 2, ST_geometry = 3,
  ST_tess_control = 4, ST_tess_evaluation = 5, ST_compute = 6, ST_COUNT = 7
}
 

Public Member Functions

bool getErrorFlag ()
 Returns true if the shader contains a compile-time error. This doesn't tell you whether or not the shader is supported on the current video card. More...
 
Filename getFilename (Shader::ShaderType type)
 Return the Shader's filename for the given shader type. More...
 
Shader::ShaderLanguage getLanguage ()
 Returns the shader language in which this shader was written. More...
 
str getText (Shader::ShaderType type)
 Return the Shader's text for the given shader type. More...
 
bool isPrepared (PreparedGraphicsObjects prepared_objects)
 Returns true if the shader has already been prepared or enqueued for preparation on the indicated GSG, false otherwise. More...
 
 prepare (PreparedGraphicsObjects prepared_objects)
 Indicates that the shader should be enqueued to be prepared in the indicated prepared_objects at the beginning of the next frame. This will ensure the texture is already loaded into texture memory if it is expected to be rendered soon. More...
 
ShaderContext prepareNow (PreparedGraphicsObjects prepared_objects, GraphicsStateGuardianBase gsg)
 Creates a context for the shader on the particular GSG, if it does not already exist. Returns the new (or old) ShaderContext. This assumes that the GraphicsStateGuardian is the currently active rendering context and that it is ready to accept new textures. If this is not necessarily the case, you should use prepare() instead. More...
 
bool release (PreparedGraphicsObjects prepared_objects)
 Frees the texture context only on the indicated object, if it exists there. Returns true if it was released, false if it had not been prepared. More...
 
int releaseAll ()
 Frees the context allocated on all objects for which the texture has been declared. Returns the number of contexts which have been freed. More...
 
- Public Member Functions inherited from TypedWritable
object __reduce__ ()
 
object __reduce_persist__ (object pickler)
 
str encodeToBamStream ()
 Converts the TypedWritable object into a single stream of data using a BamWriter, and returns that data as a string string. Returns empty string on failure. More...
 
bool encodeToBamStream (String data, BamWriter writer)
 Converts the TypedWritable object into a single stream of data using a BamWriter, and stores that data in the indicated string. Returns true on success, false on failure. More...
 
UpdateSeq getBamModified ()
 Returns the current bam_modified counter. This counter is normally incremented automatically whenever the object is modified. More...
 
 markBamModified ()
 Increments the bam_modified counter, so that this object will be invalidated and retransmitted on any open bam streams. This should normally not need to be called by user code; it should be called internally when the object has been changed in a way that legitimately requires its retransmission to any connected clients. More...
 
- Public Member Functions inherited from TypedObject
TypeHandle getType ()
 Derived classes should override this function to return get_class_type(). More...
 
int getTypeIndex ()
 Returns the internal index number associated with this object's TypeHandle, a unique number for each different type. This is equivalent to get_type().get_index(). More...
 
bool isExactType (TypeHandle handle)
 Returns true if the current object is the indicated type exactly. More...
 
bool isOfType (TypeHandle handle)
 Returns true if the current object is or derives from the indicated type. More...
 
- Public Member Functions inherited from ReferenceCount
int getRefCount ()
 Returns the current reference count. More...
 
 ref ()
 Explicitly increments the reference count. User code should avoid using ref() and unref() directly, which can result in missed reference counts. Instead, let a PointerTo object manage the reference counting automatically. More...
 
bool testRefCountIntegrity ()
 Does some easy checks to make sure that the reference count isn't completely bogus. Returns true if ok, false otherwise. More...
 
bool testRefCountNonzero ()
 Does some easy checks to make sure that the reference count isn't zero, or completely bogus. Returns true if ok, false otherwise. More...
 
bool unref ()
 Explicitly decrements the reference count. Note that the object will not be implicitly deleted by unref() simply because the reference count drops to zero. (Having a member function delete itself is problematic.) However, see the helper function unref_delete(). More...
 

Static Public Member Functions

static TypeHandle getClassType ()
 
static ShaderUtilization getShaderUtilization ()
 This flag returns SUT_none, SUT_basic, or SUT_advanced and controls the automatic generation of shaders. It is initialized from the config variable of the same name, but it can be subsequently adjusted. More...
 
static bool haveShaderUtilization ()
 If true, then get_shader_utilization has been set using set_shader_utilization. If false, then get_shader_utilization simply returns the config variable of the same name. More...
 
static Shader load (const Filename file, Shader::ShaderLanguage lang)
 Loads the shader with the given filename. More...
 
static Shader load (Shader::ShaderLanguage lang, const Filename vertex, const Filename fragment, const Filename geometry, const Filename tess_control, const Filename tess_evaluation)
 This variant of Shader::load loads all shader programs separately. More...
 
static Shader loadCompute (Shader::ShaderLanguage lang, const Filename fn)
 Loads a compute shader. More...
 
static Shader make (Shader::ShaderLanguage lang, str vertex, str fragment, str geometry, str tess_control, str tess_evaluation)
 Loads the shader, using the strings as shader bodies. More...
 
static Shader make (str body, Shader::ShaderLanguage lang)
 Loads the shader, using the string as shader body. More...
 
static Shader makeCompute (Shader::ShaderLanguage lang, str body)
 Loads the compute shader from the given string. More...
 
static setShaderUtilization (ShaderUtilization utl)
 Set this flag to SUT_none, SUT_basic, or SUT_advanced to limit panda's automatic shader generation facilities. More...
 
- Static Public Member Functions inherited from TypedWritableReferenceCount
static TypedWritableReferenceCount decodeFromBamStream (str data, BamReader reader)
 Reads the string created by a previous call to encode_to_bam_stream(), and extracts and returns the single object on that string. Returns NULL on error. More...
 
static TypeHandle getClassType ()
 
- Static Public Member Functions inherited from TypedWritable
static TypeHandle getClassType ()
 
- Static Public Member Functions inherited from TypedObject
static TypeHandle getClassType ()
 
- Static Public Member Functions inherited from ReferenceCount
static TypeHandle getClassType ()
 

Detailed Description

Summary: The Shader class is meant to select the Shader Language, select the available profile, compile the shader, and finally compile and store the shader parameters in the appropriate structure.

Member Enumeration Documentation

◆ AutoShaderBit

Enumerator
bit_AutoShaderNormal 

bit for AS_normal

bit_AutoShaderGlow 

bit for AS_glow

bit_AutoShaderGloss 

bit for AS_gloss

bit_AutoShaderRamp 

bit for AS_ramp

bit_AutoShaderShadow 

bit for AS_shadow

◆ AutoShaderSwitch

Enumerator
AS_normal 
AS_glow 
AS_gloss 
AS_ramp 
AS_shadow 

◆ ShaderLanguage

Enumerator
SL_none 
SL_Cg 
SL_GLSL 

◆ ShaderType

enum ShaderType
Enumerator
ST_none 
ST_vertex 
ST_fragment 
ST_geometry 
ST_tess_control 
ST_tess_evaluation 
ST_compute 
ST_COUNT 

Member Function Documentation

◆ getClassType()

static TypeHandle getClassType ( )
static

◆ getErrorFlag()

bool getErrorFlag ( )

Returns true if the shader contains a compile-time error. This doesn't tell you whether or not the shader is supported on the current video card.

◆ getFilename()

Filename getFilename ( Shader::ShaderType  type)

Return the Shader's filename for the given shader type.

◆ getLanguage()

Shader::ShaderLanguage getLanguage ( )

Returns the shader language in which this shader was written.

◆ getShaderUtilization()

static ShaderUtilization getShaderUtilization ( )
static

This flag returns SUT_none, SUT_basic, or SUT_advanced and controls the automatic generation of shaders. It is initialized from the config variable of the same name, but it can be subsequently adjusted.

◆ getText()

str getText ( Shader::ShaderType  type)

Return the Shader's text for the given shader type.

◆ haveShaderUtilization()

static bool haveShaderUtilization ( )
static

If true, then get_shader_utilization has been set using set_shader_utilization. If false, then get_shader_utilization simply returns the config variable of the same name.

◆ isPrepared()

bool isPrepared ( PreparedGraphicsObjects  prepared_objects)

Returns true if the shader has already been prepared or enqueued for preparation on the indicated GSG, false otherwise.

◆ load() [1/2]

static Shader load ( const Filename  file,
Shader::ShaderLanguage  lang 
)
static

Loads the shader with the given filename.

◆ load() [2/2]

static Shader load ( Shader::ShaderLanguage  lang,
const Filename  vertex,
const Filename  fragment,
const Filename  geometry,
const Filename  tess_control,
const Filename  tess_evaluation 
)
static

This variant of Shader::load loads all shader programs separately.

◆ loadCompute()

static Shader loadCompute ( Shader::ShaderLanguage  lang,
const Filename  fn 
)
static

Loads a compute shader.

◆ make() [1/2]

static Shader make ( Shader::ShaderLanguage  lang,
str  vertex,
str  fragment,
str  geometry,
str  tess_control,
str  tess_evaluation 
)
static

Loads the shader, using the strings as shader bodies.

◆ make() [2/2]

static Shader make ( str  body,
Shader::ShaderLanguage  lang 
)
static

Loads the shader, using the string as shader body.

◆ makeCompute()

static Shader makeCompute ( Shader::ShaderLanguage  lang,
str  body 
)
static

Loads the compute shader from the given string.

◆ prepare()

prepare ( PreparedGraphicsObjects  prepared_objects)

Indicates that the shader should be enqueued to be prepared in the indicated prepared_objects at the beginning of the next frame. This will ensure the texture is already loaded into texture memory if it is expected to be rendered soon.

Use this function instead of prepare_now() to preload textures from a user interface standpoint.

◆ prepareNow()

ShaderContext prepareNow ( PreparedGraphicsObjects  prepared_objects,
GraphicsStateGuardianBase  gsg 
)

Creates a context for the shader on the particular GSG, if it does not already exist. Returns the new (or old) ShaderContext. This assumes that the GraphicsStateGuardian is the currently active rendering context and that it is ready to accept new textures. If this is not necessarily the case, you should use prepare() instead.

Normally, this is not called directly except by the GraphicsStateGuardian; a shader does not need to be explicitly prepared by the user before it may be rendered.

◆ release()

bool release ( PreparedGraphicsObjects  prepared_objects)

Frees the texture context only on the indicated object, if it exists there. Returns true if it was released, false if it had not been prepared.

◆ releaseAll()

int releaseAll ( )

Frees the context allocated on all objects for which the texture has been declared. Returns the number of contexts which have been freed.

◆ setShaderUtilization()

static setShaderUtilization ( ShaderUtilization  utl)
static

Set this flag to SUT_none, SUT_basic, or SUT_advanced to limit panda's automatic shader generation facilities.