class Shader

Bases: TypedWritableReferenceCount

Inheritance diagram

Inheritance diagram of Shader

enum AutoShaderBit
enumerator bit_AutoShaderNormal = 0

bit for AS_normal

enumerator bit_AutoShaderGlow = 1

bit for AS_glow

enumerator bit_AutoShaderGloss = 2

bit for AS_gloss

enumerator bit_AutoShaderRamp = 3

bit for AS_ramp

enumerator bit_AutoShaderShadow = 4

bit for AS_shadow

enum AutoShaderSwitch
enumerator AS_normal = 1
enumerator AS_glow = 2
enumerator AS_gloss = 4
enumerator AS_ramp = 8
enumerator AS_shadow = 16
enum ShaderLanguage
enumerator SL_none = 0
enumerator SL_Cg = 1
enumerator SL_GLSL = 2
enumerator SL_HLSL = 3
enumerator SL_SPIR_V = 4
enum ShaderType
enumerator ST_none = 0
enumerator ST_vertex = 1
enumerator ST_fragment = 2
enumerator ST_geometry = 3
enumerator ST_tess_control = 4
enumerator ST_tess_evaluation = 5
enumerator ST_compute = 6
enumerator ST_COUNT = 7
Shader(Shader const&) = default

Construct a Shader that will be filled in using fillin() or read() later.

bool get_cache_compiled_shader(void) const

Returns the setting of the cache_compiled_shader flag. See set_cache_compiled_shader().

static TypeHandle get_class_type(void)
bool get_error_flag(void) const

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.

Filename get_filename(Shader::ShaderType type = ST_none) const

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

Filename const &get_fullpath(void) const

Returns the fullpath that has been set. This is the full path to the file as it was found along the model-path.

ShaderLanguage get_language(void) const

Returns the shader language in which this shader was written.

std::string const &get_text(Shader::ShaderType type = ST_none) const

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

bool has_fullpath(void) const

Returns true if the fullpath has been set and is available. See set_fullpath().

bool is_prepared(PreparedGraphicsObjects *prepared_objects) const

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

static PointerTo<Shader> load(Filename const &file, ShaderLanguage lang = SL_none)
static PointerTo<Shader> load(Shader::ShaderLanguage lang, Filename const &vertex, Filename const &fragment, Filename const &geometry = "", Filename const &tess_control = "", Filename const &tess_evaluation = "")

Loads the shader from the given string(s). Returns a boolean indicating success or failure.

Loads the shader with the given filename.

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

static PointerTo<Shader> load_compute(Shader::ShaderLanguage lang, Filename const &fn)

Loads a compute shader.

static PointerTo<Shader> make(std::string body, ShaderLanguage lang = SL_none)
static PointerTo<Shader> make(Shader::ShaderLanguage lang, std::string vertex, std::string fragment, std::string geometry = "", std::string tess_control = "", std::string tess_evaluation = "")

Loads the shader, using the string as shader body.

Loads the shader, using the strings as shader bodies.

static PointerTo<Shader> make_compute(Shader::ShaderLanguage lang, std::string body)

Loads the compute shader from the given string.

PointerTo<AsyncFuture> 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.

ShaderContext *prepare_now(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.

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.

int release_all(void)

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

void set_cache_compiled_shader(bool flag)

Sets the cache_compiled_shader flag. When this is set, the next time the Shader is loaded on a GSG, it will automatically extract the compiled shader from the GSG and save it to the global BamCache.

This is used to store compiled shaders in the BamCache. This flag should not be set explicitly; it is set automatically by the ShaderPool when model-cache-compiled-shaders is set true.

void set_filename(Shader::ShaderType type, Filename const &filename)

Sets the Shader’s filename for the given shader type. Useful for associating a shader created with Shader.make with a name for diagnostics.