![]() |
FPLBase
An open source project by
FPL.
|
Represents a shader consisting of a vertex and pixel shader. More...
#include <shader.h>
Represents a shader consisting of a vertex and pixel shader.
Represents a shader consisting of a vertex and pixel shader. Also stores ids of standard uniforms. Use the Renderer class below to create these.
Public Member Functions | |
Shader (const char *filename, const std::vector< std::string > &local_defines, Renderer *renderer) | |
Shader (ShaderHandle program, ShaderHandle vs, ShaderHandle ps) | |
void | UpdateGlobalDefines (const std::vector< std::string > &global_defines_to_add, const std::vector< std::string > &global_defines_to_omit) |
Recalculates the defines of this shader, and marks dirty if they differ from the last Reload(). More... | |
bool | ReloadIfDirty () |
If the shader has been marked dirty, reload it and clear the dirty flag. More... | |
virtual void | Load () |
Loads and unpacks the Shader from filename_ into data_ . | |
virtual bool | Finalize () |
Creates a Shader from data_ . | |
bool | IsValid () |
Whether this object loaded and finalized correctly. Call after Finalize has been called (by AssetManager::TryFinalize). | |
void | Set (const Renderer &renderer) const |
Activate this shader for subsequent draw calls. More... | |
UniformHandle | FindUniform (const char *uniform_name) |
Find a non-standard uniform by name. More... | |
void | SetUniform (UniformHandle uniform_loc, const float *value, size_t num_components) |
Raw call to set any uniform (with 1/2/3/4/16 components). More... | |
template<int N> | |
void | SetUniform (UniformHandle uniform_loc, const mathfu::Vector< float, N > &value) |
Set an non-standard uniform to a vec2/3/4 value. More... | |
template<int N> | |
bool | SetUniform (const char *uniform_name, const mathfu::Vector< float, N > &value) |
Convenience call that does a Lookup and a Set if found. More... | |
bool | SetUniform (const char *uniform_name, float value) |
Set a non-standard uniform to a float value. More... | |
bool | SetUniform (const char *uniform_name, const mathfu::mat4 &value) |
Set a non-standard uniform to a mat4 value. More... | |
void | InitializeUniforms () |
ShaderHandle | program () const |
bool | HasDefine (const char *define) const |
bool | IsDirty () const |
void | MarkDirty () |
Call to mark the shader as needing to be reloaded. More... | |
ShaderImpl * | impl () |
![]() | |
AsyncAsset () | |
Default constructor for an empty AsyncAsset. | |
AsyncAsset (const char *filename) | |
Construct an AsyncAsset with a given file name. More... | |
virtual | ~AsyncAsset () |
AsyncAsset destructor. | |
bool | LoadNow () |
Performs a synchronous load by calling Load & Finalize. More... | |
void | set_filename (const std::string &filename) |
Sets the filename that should be loaded. More... | |
const std::string & | filename () const |
The name of the file associated with the resource. More... | |
void | AddFinalizeCallback (AssetFinalizedCallback callback) |
Adds a callback to be called when the asset is finalized. More... | |
![]() | |
void | IncreaseRefCount () |
indicate there is an additional owner of this asset. By default, when you call any of the UnLoad*() functions in the AssetManager, that will directly delete the asset since they all start out with a single reference count. Call this function to indicate multiple owners will call Unload*() independently, and only have the asset deleted by the last one. | |
Static Public Member Functions | |
static Shader * | LoadFromShaderDef (const char *filename) |
Loads a .fplshader file from disk. Used by the more convenient AssetManager interface, but can also be used without it. | |
Friends | |
class | RendererBase |
Additional Inherited Members | |
![]() | |
typedef std::function< void()> | AssetFinalizedCallback |
A function pointer to an asset loaded callback function. | |
![]() | |
void | CallFinalizeCallback () |
Calls app callbacks when an asset is ready to be used. More... | |
![]() | |
std::string | filename_ |
The resource file name. | |
const uint8_t * | data_ |
The resource data. | |
std::vector < AssetFinalizedCallback > | finalize_callbacks_ |
UniformHandle fplbase::Shader::FindUniform | ( | const char * | uniform_name | ) |
Find a non-standard uniform by name.
uniform_name | The name of the uniform to find. |
|
inline |
Call to mark the shader as needing to be reloaded.
Useful when you've changed the shader source and want to dynamically re-compile the shader.
bool fplbase::Shader::ReloadIfDirty | ( | ) |
If the shader has been marked dirty, reload it and clear the dirty flag.
Lazy loading ensures shaders are only loaded and compiled when they are used. Also allows the caller to ensure that the reload is happening on the correct thread.
void fplbase::Shader::Set | ( | const Renderer & | renderer | ) | const |
Activate this shader for subsequent draw calls.
Will make this shader active for any subsequent draw calls, and sets all standard uniforms (e.g. mvp matrix) based on current values in Renderer, if this shader refers to them.
renderer | The renderer that has the standard uniforms set. |
void fplbase::Shader::SetUniform | ( | UniformHandle | uniform_loc, |
const float * | value, | ||
size_t | num_components | ||
) |
Raw call to set any uniform (with 1/2/3/4/16 components).
More convenient variants below.
uniform_loc | Handle to the uniform that will be set. |
value | The value to set the uniform to. |
num_components | The number of components used by the uniform. |
|
inline |
Set an non-standard uniform to a vec2/3/4 value.
Call this after Set() or FindUniform().
uniform_loc | Handle to the uniform that will be set. |
value | The vector to set the uniform to. |
|
inline |
Convenience call that does a Lookup and a Set if found.
Call this after Set().
uniform_name | The name of the uniform that will be set. |
value | The vector to set the uniform to. |
|
inline |
Set a non-standard uniform to a float value.
Call this after Set().
uniform_name | The name of the uniform that will be set. |
value | The float to set the uniform to. |
|
inline |
Set a non-standard uniform to a mat4 value.
Call this after Set().
uniform_name | The name of the uniform that will be set. |
value | The mat4 to set the uniform to. |
void fplbase::Shader::UpdateGlobalDefines | ( | const std::vector< std::string > & | global_defines_to_add, |
const std::vector< std::string > & | global_defines_to_omit | ||
) |
Recalculates the defines of this shader, and marks dirty if they differ from the last Reload().
Defines change the shader source code when it is preprocessed. Typically, you have one uber-shader that contains all possible shader features, and enable the features using preprocessor defines. This function allows you to specify which features are enabled.
global_defines_to_add | the defines to be added into 'local_defines' above. These are generally global rendering settings, for example, enabling shadows or specular. |
global_defines_to_omit | the defines to forcefully omit from 'local_defines'. Generally used to globally disable expensive features such as shadows, on low-powered hardware. |