![]() |
OGRE 2.1
Object-Oriented Graphics Rendering Engine
|
HLMS stands for "High Level Material System". More...
#include <OgreHlms.h>
Classes | |
struct | DatablockEntry |
struct | Library |
Public Types | |
typedef std::map< IdString, DatablockEntry > | HlmsDatablockMap |
typedef vector< Library >::type | LibraryVec |
enum | LightGatheringMode { LightGatherForward , LightGatherForwardPlus , LightGatherDeferred , LightGatherNone } |
Static Public Member Functions | |
static bool | findParamInVec (const HlmsParamVec ¶mVec, IdString key, String &inOut) |
Finds the parameter with key 'key' in the given 'paramVec'. | |
static int32 | getProperty (const HlmsPropertyVec &properties, IdString key, int32 defaultVal=0) |
Utility helper, mostly useful to HlmsListener implementations. | |
static void | setProperty (HlmsPropertyVec &properties, IdString key, int32 value) |
Utility helper, mostly useful to HlmsListener implementations. | |
Friends | |
class | HlmsDiskCache |
HLMS stands for "High Level Material System".
The Hlms has multiple caches:
mRenderableCache This cache contains all the properties set to a Renderable class and can be evaluated early, when a Renderable is assigned a datablock i.e. inside Renderable::setDatablock. Contains properties such as whether the material has normal mapping, if the mesh has UV sets, evaluates if the material requires tangents for normal mapping, etc. The main function in charge of filling this cache is Hlms::calculateHashFor
mPassCache This cache contains per-pass information, such as how many lights are in the scene, whether this is a shadow mapping pass, etc. The main function in charge of filling this cache is Hlms::preparePassHash
mShaderCodeCache Contains a cache of unique shaders (from Hlms templates -> actual valid shader code) based on the properties merged from mRenderableCache & mPassCache. However it is possible that two shaders are exactly the same and thus be duplicated, this can happen if two combinations of properties end up producing the exact same code. The Microcode cache (GpuProgramManager::setSaveMicrocodesToCache) can help with that issue.
mShaderCache Contains a cache of the PSOs. The difference between this and mShaderCodeCache is that PSOs require additional information, such as HlmsMacroblock. HlmsBlendblock. For more information of all that is required, see HlmsPso
Ogre::Hlms::Hlms | ( | HlmsTypes | type, |
const String & | typeName, | ||
Archive * | dataFolder, | ||
ArchiveVec * | libraryFolders | ||
) |
libraryFolders | Path to folders to be processed first for collecting pieces. Will be processed in order. Pointer can be null. |
|
virtual |
|
virtual |
Reimplemented in Ogre::HlmsBufferManager, Ogre::HlmsPbs, Ogre::HlmsUnlit, and Ogre::HlmsCompute.
|
inlinevirtual |
Reimplemented in Ogre::HlmsPbs, and Ogre::HlmsUnlit.
void Ogre::Hlms::_compileShaderFromPreprocessedSource | ( | const RenderableCache & | mergedCache, |
const String | source[NumShaderTypes] | ||
) |
|
inlinevirtual |
Loads datablock values from a JSON value.
jsonValue | JSON Object containing the definition of this datablock. |
blocks | All the loaded Macro-, Blend- & Samplerblocks the JSON has defined and may be referenced by the datablock declaration. |
datablock | Datablock to fill the values. |
Reimplemented in Ogre::HlmsPbs, and Ogre::HlmsUnlit.
|
inline |
Internal use.
|
inlinevirtual |
Reimplemented in Ogre::HlmsPbs, and Ogre::HlmsUnlit.
For debugging stuff. I.e. the Command line uses it for testing manually set properties.
|
virtual |
Called by the renderable when either it changes the material, or its properties change (e.g.
the mesh' uvs are stripped)
renderable | The renderable the material will be used on. |
movableObject | The MovableObject the material will be used on (usually the parent of renderable) |
Reimplemented in Ogre::HlmsUnlitMobile, and Ogre::HlmsLowLevel.
void Ogre::Hlms::compileShaderCode | ( | ShaderCodeCache & | codeCache | ) |
Compiles input properties and adds it to the shader code cache.
codeCache | [in/out] All variables must be filled except for ShaderCodeCache::shaders which is the output |
HlmsDatablock * Ogre::Hlms::createDatablock | ( | IdString | name, |
const String & | refName, | ||
const HlmsMacroblock & | macroblockRef, | ||
const HlmsBlendblock & | blendblockRef, | ||
const HlmsParamVec & | paramVec, | ||
bool | visibleToManager = true , |
||
const String & | filename = BLANKSTRING , |
||
const String & | resourceGroup = BLANKSTRING |
||
) |
Creates a unique datablock that can be shared by multiple renderables.
name | Name of the Datablock, must be unique within all Hlms types, not just this one. 99% you want this to be IdString( refName ); however this is not enforced. |
refName | Name of the Datablock. The engine doesn't use this value at all. It is only useful for UI editors which want to enumerate all existing datablocks and display its name to the user. |
macroblockRef | @See HlmsManager::getMacroblock |
blendblockRef | @See HlmsManager::getBlendblock |
paramVec | Key - String Value list of paramters. MUST BE SORTED. |
visibleToManager | When false, HlmsManager::getDatablock won't find this datablock. True by default |
filename | Filename in which it was defined, so that this information can be retrieved later by the user if needed. This is only for informational purposes. |
resourceGroup | ResourceGroup. See filename param. |
Destroys all datablocks created with @createDatablock.
Caller is responsible for ensuring those pointers aren't still in use (i.e. dangling pointers) The default datablock will be recreated.
Destroys a datablocks given its name.
Caller is responsible for ensuring those pointers aren't still in use (i.e. dangling pointers)
|
pure virtual |
Fills the constant buffers.
Gets executed right before drawing the mesh.
cache | Current cache of Shaders to be used. |
queuedRenderable | The Renderable-MovableObject pair about to be rendered. |
casterPass | Whether this is a shadow mapping caster pass. |
lastCacheHash | The hash of the cache of shaders that was the used by the previous renderable. |
lastTextureHash | Last Texture Hash, used to let the Hlms know whether the textures should be changed again |
Implemented in Ogre::HlmsPbs, Ogre::HlmsPbsMobile, Ogre::HlmsUnlit, Ogre::HlmsUnlitMobile, Ogre::HlmsCompute, and Ogre::HlmsLowLevel.
|
pure virtual |
Implemented in Ogre::HlmsPbs, Ogre::HlmsUnlit, Ogre::HlmsCompute, and Ogre::HlmsLowLevel.
|
pure virtual |
Implemented in Ogre::HlmsPbs, Ogre::HlmsUnlit, Ogre::HlmsCompute, and Ogre::HlmsLowLevel.
|
static |
Finds the parameter with key 'key' in the given 'paramVec'.
If found, outputs the value to 'inOut', otherwise leaves 'inOut' as is.
Called when the frame has fully ended (ALL passes have been executed to all RTTs)
Reimplemented in Ogre::HlmsBufferManager, Ogre::HlmsPbs, and Ogre::HlmsUnlit.
HlmsDatablock * Ogre::Hlms::getDatablock | ( | IdString | name | ) | const |
Finds an existing datablock based on its name (.
|
inline |
Returns all datablocks owned by this Hlms, including the default one.
HlmsDatablock * Ogre::Hlms::getDefaultDatablock | ( | void | ) | const |
Datablock to use when another datablock failed or none was specified.
void Ogre::Hlms::getFilenameAndResourceGroup | ( | IdString | name, |
String const ** | outFilename, | ||
String const ** | outResourceGroup | ||
) | const |
Returns the filaname & resource group a datablock was created from, and is associated with its hashed name (this was passed as in @createDatablock).
Returns null ptr if not found. Note that it may also be a valid pointer but contain an empty string. The reason this String doesn't live in HlmsDatablock is to prevent cache trashing (datablocks are hot iterated every frame, and the filename & resource groups are rarely ever used) Usage: String const *filename; String const *resourceGroup; datablock->getFilenameAndResourceGroup( &filename, &resourceGroup ); if( filename && resourceGroup && !filename->empty() && !resourceGroup->empty() ) { //Valid filename & resource group. }
|
inline |
HlmsListener * Ogre::Hlms::getListener | ( | void | ) | const |
Returns the current listener.
const HlmsCache * Ogre::Hlms::getMaterial | ( | HlmsCache const * | lastReturnedValue, |
const HlmsCache & | passCache, | ||
const QueuedRenderable & | queuedRenderable, | ||
bool | casterPass | ||
) |
Retrieves an HlmsCache filled with the GPU programs to be used by the given renderable.
If the shaders have already been created (i.e. whether for this renderable, or another one) it gets them from a cache. Otherwise we create it. It assumes that renderable->setHlms( this, parameters ) has already called.
lastReturnedValue | The last value returned by getMaterial. |
passCache | The cache returned by @preparePassHash. |
renderable | The renderable the caller wants us to give the shaders. |
movableObject | The MovableObject owner of the renderable (we need it to know if renderable should cast shadows) |
casterPass | True if this pass is the shadow mapping caster pass, false otherwise |
Returns the string name associated with its hashed name (this was passed as refName in @createDatablock).
Returns null ptr if not found. The reason this String doesn't live in HlmsDatablock is to prevent cache trashing (datablocks are hot iterated every frame, and the full name is rarely ever used)
|
inline |
ArchiveVec Ogre::Hlms::getPiecesLibraryAsArchiveVec | ( | void | ) | const |
|
static |
Utility helper, mostly useful to HlmsListener implementations.
|
inline |
|
inline |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
operator new, with debug line info
placement operator new
|
inlineinherited |
|
inlineinherited |
array operator new, with debug line info
|
inlinevirtual |
This gets called after executing the command buffer.
Reimplemented in Ogre::HlmsBufferManager, and Ogre::HlmsPbs.
|
inlinevirtual |
This gets called right before executing the command buffer.
Reimplemented in Ogre::HlmsBufferManager.
|
virtual |
Called every frame by the Render Queue to cache the properties needed by this pass.
i.e. Number of PSSM splits, number of shadow casting lights, etc
shadowNode | The shadow node currently in effect. Can be null. |
Reimplemented in Ogre::HlmsBufferManager, Ogre::HlmsPbs, Ogre::HlmsPbsMobile, Ogre::HlmsUnlit, Ogre::HlmsUnlitMobile, and Ogre::HlmsLowLevel.
|
virtual |
Destroys all the cached shaders and in the next opportunity will recreate them from the new location.
This is very useful for fast iteration and real-time editing of Hlms shader templates.
libraryFolders | When null pointer, the library folders paths won't be changed at all (but still will be reloaded). When non-null pointer, the library folders will be overwriten. Pass an empty container if you want to stop using libraries. |
Reimplemented in Ogre::HlmsCompute.
void Ogre::Hlms::saveAllTexturesFromDatablocks | ( | const String & | folderPath, |
set< String >::type & | savedTextures, | ||
bool | saveOitd, | ||
bool | saveOriginal, | ||
HlmsTextureExportListener * | listener | ||
) |
void Ogre::Hlms::setAreaLightForwardSettings | ( | uint16 | areaLightsLimit, |
uint8 | areaLightsRoundMultiple | ||
) |
Area lights use regular Forward.
areaLightsLimit | Maximum number of area lights that will be considered by the shader. Default value is 1. Use 0 to disable area lights. |
areaLightsRoundMultiple | To prevent frequent shader recompiles, you can round the number of area lights to the next multiple. |
For example when areaLightsRoundMultiple = 1, if there are two area lights in the frustum, shader 'A' will be used. If the camera moves and now only one are light is in the frustum, shader 'B' will be used.
This maximizes GPU performance, but if the number of area lights is constantly jumping, you may see a lot of recompiles until all variations are cached, which can be very slow.
By setting for example, areaLightsRoundMultiple = 2, we will always generate shader variations that use 2 area lights, even if there's only 1 area light in the camera (if there's none, we use a different variation). The unused slot will just output black. If there's 3 area lights, the shader variation will be compiled to use 4. This sacrifices some pixel shader GPU performance, but prevents permutation explosion.
By setting areaLightsLimit = areaLightsRoundMultiple, you will minimize the number of permutations and stabilize frame rates; but average framerate may be lower if there are less area lights.
Default value is 1. This value cannot be 0. This value must be <= areaLightsLimit, unless areaLightsLimit is 0.
void Ogre::Hlms::setDebugOutputPath | ( | bool | enableDebugOutput, |
bool | outputProperties, | ||
const String & | path = BLANKSTRING |
||
) |
Call to output the automatically generated shaders (which are usually made from templates) on the given folder for inspection, analyzing, debugging, etc.
enableDebugOutput | Whether to enable or disable dumping the shaders into a folder |
outputProperties | Whether to dump properties and pieces at the beginning of the shader file. This is very useful for determining what caused Ogre to compile a new variation. Note that this setting may not always produce valid shader code in the dumped files (but it we'll still produce valid shader code while at runtime) If you want to compile the dumped file and it is invalid, just strip this info. |
path | Path location on where to dump it. Should end with slash for proper concatenation (i.e. C:/path/ instead of C:/path; or /home/user/ instead of /home/user) |
Sets the quality of the Hlms.
This function is most relevant for mobile and almost or completely ignored by Desktop. The default value is false.
void Ogre::Hlms::setListener | ( | HlmsListener * | listener | ) |
Sets a listener to extend an existing Hlms implementation's with custom code, without having to rewrite it or modify the source code directly.
listener | Listener pointer. Use null to disable. |
|
static |
Utility helper, mostly useful to HlmsListener implementations.
|
friend |