|
Shinya Kitaoka |
810553 |
#pragma once
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TRENDERRESOURCEMANAGER_INCLUDED
|
|
Toshihiro Shimizu |
890ddd |
#define TRENDERRESOURCEMANAGER_INCLUDED
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "trasterfx.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#undef DVAPI
|
|
Toshihiro Shimizu |
890ddd |
#undef DVVAR
|
|
Toshihiro Shimizu |
890ddd |
#ifdef TFX_EXPORTS
|
|
Toshihiro Shimizu |
890ddd |
#define DVAPI DV_EXPORT_API
|
|
Toshihiro Shimizu |
890ddd |
#define DVVAR DV_EXPORT_VAR
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#define DVAPI DV_IMPORT_API
|
|
Toshihiro Shimizu |
890ddd |
#define DVVAR DV_IMPORT_VAR
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//===============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class TRenderer;
|
|
Toshihiro Shimizu |
890ddd |
class TRenderResourceManager;
|
|
Toshihiro Shimizu |
890ddd |
class TRenderResourceManagerGenerator;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//===============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=================================
|
|
Toshihiro Shimizu |
890ddd |
// Render Resource Managers
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
The TRenderResourceManager is a base class used to develop resource
|
|
Toshihiro Shimizu |
890ddd |
handlers for Toonz rendering contexts.
|
|
Toshihiro Shimizu |
890ddd |
\a Resources are hereby intended as data which possess special scope and
|
|
Toshihiro Shimizu |
890ddd |
duration with respect to one or more rendering processes. A most notable
|
|
Toshihiro Shimizu |
890ddd |
example of this is the internal Fxs cache, which is specialized to
|
|
Toshihiro Shimizu |
890ddd |
maintain a group of intermediate rendered tiles which may be shared in input
|
|
Toshihiro Shimizu |
890ddd |
by multiple fxs.
|
|
Toshihiro Shimizu |
890ddd |
\n \n
|
|
Toshihiro Shimizu |
890ddd |
Creation of a resource manager requires the implementation of both the
|
|
Toshihiro Shimizu |
890ddd |
manager itself, and that of a TRenderResourceManagerGenerator class which
|
|
Toshihiro Shimizu |
890ddd |
is used internally to allocate manager instances at the most appropriate times.
|
|
Toshihiro Shimizu |
890ddd |
The manager's generator needs to be instanced at file scope <\b> to
|
|
Toshihiro Shimizu |
890ddd |
be correctly registered by Toonz.
|
|
Toshihiro Shimizu |
890ddd |
\n \n
|
|
Toshihiro Shimizu |
890ddd |
Observe that the default scope of a resource manager is limited to a TRenderer
|
|
Toshihiro Shimizu |
890ddd |
instance; specifically meaning that the swatch viewer, preview fx command,
|
|
Toshihiro Shimizu |
890ddd |
camstand preview and render/preview commands build different managers.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class TRenderResourceManager
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TRenderResourceManager() {}
|
|
Toshihiro Shimizu |
890ddd |
virtual ~TRenderResourceManager() {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
virtual void onRenderInstanceStart(unsigned long id) {}
|
|
Toshihiro Shimizu |
890ddd |
virtual void onRenderInstanceEnd(unsigned long id) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
virtual void onRenderFrameStart(double f) {}
|
|
Toshihiro Shimizu |
890ddd |
virtual void onRenderFrameEnd(double f) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
virtual void onRenderStatusStart(int renderStatus) {}
|
|
Toshihiro Shimizu |
890ddd |
virtual void onRenderStatusEnd(int renderStatus) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
virtual bool renderHasOwnership() { return true; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//===============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//===========================================
|
|
Toshihiro Shimizu |
890ddd |
// Render Resource Manager Generators
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
The TRenderResourceManagerGenerator class is used to construct resource managers
|
|
Toshihiro Shimizu |
890ddd |
that will be used by TRenderers.
|
|
Toshihiro Shimizu |
890ddd |
Please refer to the TRenderResourceManager documentation for the details.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
\note Resource managers may be constructed with a render instance <\i> scope rather
|
|
Toshihiro Shimizu |
890ddd |
than the default render context (ie TRenderer) scope. This can be achieved by passing
|
|
Toshihiro Shimizu |
890ddd |
\c true at the generator's constructor, proving especially useful considering
|
|
Toshihiro Shimizu |
890ddd |
that the same TRenderer may virtually start multiple render instances at the same time.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class DVAPI TRenderResourceManagerGenerator
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int m_managerIndex;
|
|
Toshihiro Shimizu |
890ddd |
bool m_instanceScope;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TRenderResourceManagerGenerator(bool renderInstanceScope = false);
|
|
Toshihiro Shimizu |
890ddd |
~TRenderResourceManagerGenerator() {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int getGeneratorIndex() const { return m_managerIndex; }
|
|
Toshihiro Shimizu |
890ddd |
static std::vector<trenderresourcemanagergenerator *=""> &generators();</trenderresourcemanagergenerator>
|
|
Toshihiro Shimizu |
890ddd |
static std::vector<trenderresourcemanagergenerator *=""> &generators(bool instanceScope);</trenderresourcemanagergenerator>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
virtual TRenderResourceManager *operator()(void) = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool hasInstanceScope() const { return m_instanceScope; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRenderResourceManager *getManager(const TRenderer &renderer) const;
|
|
Toshihiro Shimizu |
890ddd |
TRenderResourceManager *getManager(unsigned long renderId) const;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//===============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//===========================
|
|
Toshihiro Shimizu |
890ddd |
// Declaration macros
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*! \def MANAGER_DECLARATION(managerClass)
|
|
Toshihiro Shimizu |
890ddd |
Declares a TRenderResourceManager class, it must be used inside the manager
|
|
Toshihiro Shimizu |
890ddd |
definition.
|
|
Toshihiro Shimizu |
890ddd |
For example:
|
|
Toshihiro Shimizu |
890ddd |
\code
|
|
Toshihiro Shimizu |
890ddd |
class MyManager : public TRenderResourceManager
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
T_RENDER_RESOURCE_MANAGER
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
...
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
\endcode
|
|
Toshihiro Shimizu |
890ddd |
In particular, this macro is used to decorate the manager definition with the
|
|
Toshihiro Shimizu |
890ddd |
static method \c gen(), which can be used to access the manager's generator.
|
|
Toshihiro Shimizu |
890ddd |
The method declaration is:
|
|
Toshihiro Shimizu |
890ddd |
\code
|
|
Toshihiro Shimizu |
890ddd |
static TRenderResourceManagerGenerator* gen();
|
|
Toshihiro Shimizu |
890ddd |
\endcode
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define T_RENDER_RESOURCE_MANAGER \
|
|
Toshihiro Shimizu |
890ddd |
public: \
|
|
Toshihiro Shimizu |
890ddd |
static TRenderResourceManagerGenerator *gen(); \
|
|
Toshihiro Shimizu |
890ddd |
static TRenderResourceManagerGenerator *deps(); \
|
|
Toshihiro Shimizu |
890ddd |
\
|
|
Toshihiro Shimizu |
890ddd |
private:
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*! \def MANAGER_FILESCOPE_DECLARATION(managerClass, generatorClass)
|
|
Toshihiro Shimizu |
890ddd |
This macro must be used at file scope to bind the manager to its generator
|
|
Toshihiro Shimizu |
890ddd |
instance - just place it after the generator definition.
|
|
Toshihiro Shimizu |
890ddd |
\note In case the manager is dependant on some other manager, use the
|
|
Toshihiro Shimizu |
890ddd |
\c MANAGER_FILESCOPE_DECLARATION_DEP macro instead.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define MANAGER_FILESCOPE_DECLARATION(managerClass, generatorClass) \
|
|
Toshihiro Shimizu |
890ddd |
\
|
|
Toshihiro Shimizu |
890ddd |
TRenderResourceManagerGenerator *managerClass::gen() \
|
|
Toshihiro Shimizu |
890ddd |
{ \
|
|
Toshihiro Shimizu |
890ddd |
static generatorClass theInstance; \
|
|
Toshihiro Shimizu |
890ddd |
return &theInstance; \
|
|
Toshihiro Shimizu |
890ddd |
} \
|
|
Toshihiro Shimizu |
890ddd |
TRenderResourceManagerGenerator *managerClass::deps() \
|
|
Toshihiro Shimizu |
890ddd |
{ \
|
|
Toshihiro Shimizu |
890ddd |
return managerClass::gen(); \
|
|
Toshihiro Shimizu |
890ddd |
} \
|
|
Toshihiro Shimizu |
890ddd |
\
|
|
Toshihiro Shimizu |
890ddd |
namespace \
|
|
Toshihiro Shimizu |
890ddd |
{ \
|
|
Toshihiro Shimizu |
890ddd |
generatorClass *generatorClass##Instance = \
|
|
Toshihiro Shimizu |
890ddd |
(generatorClass *)managerClass::deps(); \
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*! \def MANAGER_FILESCOPE_DECLARATION_DEP(managerClass, generatorClass, depsList)
|
|
Toshihiro Shimizu |
890ddd |
A variation of the MANAGER_FILESCOPE_DECLARATION macro used to declare dependencies between
|
|
Toshihiro Shimizu |
890ddd |
resource managers. A manager always receives start notifications \a after those from which
|
|
Toshihiro Shimizu |
890ddd |
it depends, and viceversa for end notifications. The same applies for constructors and destructors.
|
|
Toshihiro Shimizu |
890ddd |
\n \n
|
|
Toshihiro Shimizu |
890ddd |
The dependencies declarations list is a sequence of static \c <dependencyresourcemanager>::deps()</dependencyresourcemanager>
|
|
Toshihiro Shimizu |
890ddd |
calls separated by a comma.
|
|
Toshihiro Shimizu |
890ddd |
Here is an example:
|
|
Toshihiro Shimizu |
890ddd |
\code
|
|
Toshihiro Shimizu |
890ddd |
MANAGER_FILESCOPE_DECLARATION_DEP(
|
|
Toshihiro Shimizu |
890ddd |
MyResourceManager,
|
|
Toshihiro Shimizu |
890ddd |
MyResourceManagerGenerator,
|
|
Toshihiro Shimizu |
890ddd |
TPredictiveCacheManager::deps(); TOfflineGLManager::deps(); \\etc...
|
|
Toshihiro Shimizu |
890ddd |
)
|
|
Toshihiro Shimizu |
890ddd |
\endcode
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define MANAGER_FILESCOPE_DECLARATION_DEP(managerClass, generatorClass, depsList) \
|
|
Toshihiro Shimizu |
890ddd |
\
|
|
Toshihiro Shimizu |
890ddd |
TRenderResourceManagerGenerator *managerClass::gen() \
|
|
Toshihiro Shimizu |
890ddd |
{ \
|
|
Toshihiro Shimizu |
890ddd |
static generatorClass theInstance; \
|
|
Toshihiro Shimizu |
890ddd |
return &theInstance; \
|
|
Toshihiro Shimizu |
890ddd |
} \
|
|
Toshihiro Shimizu |
890ddd |
TRenderResourceManagerGenerator *managerClass::deps() \
|
|
Toshihiro Shimizu |
890ddd |
{ \
|
|
Toshihiro Shimizu |
890ddd |
depsList; \
|
|
Toshihiro Shimizu |
890ddd |
return managerClass::gen(); \
|
|
Toshihiro Shimizu |
890ddd |
} \
|
|
Toshihiro Shimizu |
890ddd |
\
|
|
Toshihiro Shimizu |
890ddd |
namespace \
|
|
Toshihiro Shimizu |
890ddd |
{ \
|
|
Toshihiro Shimizu |
890ddd |
generatorClass *generatorClass##Instance = \
|
|
Toshihiro Shimizu |
890ddd |
(generatorClass *)managerClass::deps(); \
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//===============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif //TRENDERRESOURCEMANAGER_INCLUDED
|