OGRE 2.1
Object-Oriented Graphics Rendering Engine
|
Utility class to cache PSOs. More...
#include <OgrePsoCacheHelper.h>
Public Member Functions | |
PsoCacheHelper (RenderSystem *renderSystem) | |
~PsoCacheHelper () | |
void | clearState (void) |
HlmsPso * | getPso (uint32 renderableHash, bool renderableCacheAlreadySet=false) |
Returns an HlmsPso you can set via renderSystem->_setPipelineStateObject based on the input hash calculated via getRenderableHash. | |
HlmsPso * | getPso (void) |
Returns an HlmsPso you can set via renderSystem->_setPipelineStateObject based on all past calls to setRenderTarget + setVertexFormat + setMacroblock + etc. | |
uint32 | getRenderableHash (void) |
Returns a hash value you can cache into a Renderable (or whatever you're rendering). | |
void | operator delete (void *ptr) |
void | operator delete (void *ptr, const char *, int, const char *) |
void | operator delete (void *ptr, void *) |
void | operator delete[] (void *ptr) |
void | operator delete[] (void *ptr, const char *, int, const char *) |
void * | operator new (size_t sz) |
void * | operator new (size_t sz, const char *file, int line, const char *func) |
operator new, with debug line info | |
void * | operator new (size_t sz, void *ptr) |
placement operator new | |
void * | operator new[] (size_t sz) |
void * | operator new[] (size_t sz, const char *file, int line, const char *func) |
array operator new, with debug line info | |
void | setBlendblock (const HlmsBlendblock *blendblock) |
Calls to this function cannot be skipped unless you have a renderableHash. | |
void | setMacroblock (const HlmsMacroblock *macroblock) |
Calls to this function cannot be skipped unless you have a renderableHash. | |
void | setPixelShader (GpuProgramPtr &shader) |
Calls to this function can be skipped if it's valid to not have a shader set at this stage, or if you have a renderableHash. | |
void | setRenderTarget (RenderTarget *renderTarget) |
You must call this function every frame, and every time the RenderTarget changes. | |
void | setVertexFormat (const VertexElement2VecVec &vertexElements, OperationType operationType, bool enablePrimitiveRestart) |
This function can be skipped if no vertex buffer is used (e.g. | |
void | setVertexShader (GpuProgramPtr &shader) |
Calls to this function can be skipped if it's valid to not have a shader set at this stage, or if you have a renderableHash. | |
Utility class to cache PSOs.
Useful for porting v1 libraries (eg. Gorilla) that render in "immediate mode" style and weren't build with PSOs in mind. Ideally a PSO would be created ahead of time and its pointer stored alongside the renderable you need to render.
void render() { psoCache.clearState(); psoCache.setRenderTarget( renderTarget ); for( int i=0; i<numMaterials; ++i ) { psoCache.setMacroblock( material[i].macroblock ); psoCache.setBlendblock( material[i].blendblock ); psoCache.setVertexShader( material[i].vertexShader ); psoCache.setPixelShader( material[i].pixelShader ); for( int j=0; j<numThingsToRenderPerMaterial; ++j ) { v1::RenderOperation renderOp = renderables[j].renderOp; Consider caching 'vertexElements' somewhere as convertToV2 involves allocations VertexElement2VecVec vertexElements = renderOp.vertexData-> vertexDeclaration->convertToV2(); psoCache.setVertexFormat( vertexElements, renderOp.operationType, enablePrimitiveRestart );
HlmsPso *pso = psoCache.getPso(); renderSystem->_setPipelineStateObject( pso ); } } }
Usage "MUCH better": PsoCacheHelper psoCache( renderSystem ); //Save this variable (i.e. per class)
Outside rendering, just ONCE at loading time or when the material changes (or the vertex layout changes): psoCache.clearState(); psoCache.setMacroblock( material[i].macroblock ); psoCache.setBlendblock( material[i].blendblock ); psoCache.setVertexShader( material[i].vertexShader ); psoCache.setPixelShader( material[i].pixelShader ); for( int j=0; j<numThingsToRenderPerMaterial; ++j ) { v1::RenderOperation renderOp = renderables[j].renderOp; Consider caching 'vertexElements' somewhere as convertToV2 involves allocations VertexElement2VecVec vertexElements = renderOp.vertexData-> vertexDeclaration->convertToV2(); psoCache.setVertexFormat( vertexElements, renderOp.operationType, enablePrimitiveRestart );
renderables[j].customSavedValue = psoCache.getRenderableHash(); }
During render: void render() { psoCache.clearState(); setRenderTarget still needs to be called. psoCache.setRenderTarget( renderTarget ); for( int i=0; i<numMaterials; ++i ) { for( int j=0; j<numThingsToRenderPerMaterial; ++j ) { HlmsPso *pso = psoCache.getPso( renderables[j].customSavedValue ); renderSystem->_setPipelineStateObject( pso ); } } }
Ogre::PsoCacheHelper::PsoCacheHelper | ( | RenderSystem * | renderSystem | ) |
Ogre::PsoCacheHelper::~PsoCacheHelper | ( | ) |
HlmsPso * Ogre::PsoCacheHelper::getPso | ( | uint32 | renderableHash, |
bool | renderableCacheAlreadySet = false |
||
) |
Returns an HlmsPso you can set via renderSystem->_setPipelineStateObject based on the input hash calculated via getRenderableHash.
renderableHash | The hash obtained from getRenderableHash which you should've saved in the Renderable. |
renderableCacheAlreadySet | Internal parameter. Leave the default. Used by the other getPso overload to tell there is no need to perform a linear O(N) search in mRenderableCache because mCurrentState is up to date (this search only happens if the PSO hadn't been already cached). |
Returns an HlmsPso you can set via renderSystem->_setPipelineStateObject based on all past calls to setRenderTarget + setVertexFormat + setMacroblock + etc.
Use this version if for architecture reasons (i.e. legacy code, time constraints) you can't store the hash at loading time into the Renderable for later reuse.
Returns a hash value you can cache into a Renderable (or whatever you're rendering).
This hash will contain VertexFormat, Macroblock, Blendblock information and shaders set, but nothing that is part of the pass (RenderTargets attached, RTT formats, stencil parameters, etc). You would later insert this value to getPso( renderableHash ); See examples in the class description.
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
operator new, with debug line info
placement operator new
|
inlineinherited |
|
inlineinherited |
array operator new, with debug line info
void Ogre::PsoCacheHelper::setBlendblock | ( | const HlmsBlendblock * | blendblock | ) |
Calls to this function cannot be skipped unless you have a renderableHash.
void Ogre::PsoCacheHelper::setMacroblock | ( | const HlmsMacroblock * | macroblock | ) |
Calls to this function cannot be skipped unless you have a renderableHash.
void Ogre::PsoCacheHelper::setPixelShader | ( | GpuProgramPtr & | shader | ) |
Calls to this function can be skipped if it's valid to not have a shader set at this stage, or if you have a renderableHash.
void Ogre::PsoCacheHelper::setRenderTarget | ( | RenderTarget * | renderTarget | ) |
You must call this function every frame, and every time the RenderTarget changes.
This function is a PASS state changing function, and its information is not part of getRenderableHash.
void Ogre::PsoCacheHelper::setVertexFormat | ( | const VertexElement2VecVec & | vertexElements, |
OperationType | operationType, | ||
bool | enablePrimitiveRestart | ||
) |
This function can be skipped if no vertex buffer is used (e.g.
you use gl_VertexID or other trickery) or if you have a renderableHash.
void Ogre::PsoCacheHelper::setVertexShader | ( | GpuProgramPtr & | shader | ) |
Calls to this function can be skipped if it's valid to not have a shader set at this stage, or if you have a renderableHash.