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
Shinya Kitaoka 120a6e
class TRenderResourceManager {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TRenderResourceManager() {}
Shinya Kitaoka 120a6e
  virtual ~TRenderResourceManager() {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  virtual void onRenderInstanceStart(unsigned long id) {}
Shinya Kitaoka 120a6e
  virtual void onRenderInstanceEnd(unsigned long id) {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  virtual void onRenderFrameStart(double f) {}
Shinya Kitaoka 120a6e
  virtual void onRenderFrameEnd(double f) {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  virtual void onRenderStatusStart(int renderStatus) {}
Shinya Kitaoka 120a6e
  virtual void onRenderStatusEnd(int renderStatus) {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  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
Shinya Kitaoka 120a6e
\note Resource managers may be constructed with a  render instance <\i> scope
Shinya Kitaoka 120a6e
rather
Shinya Kitaoka 120a6e
than the default render context (ie TRenderer) scope. This can be achieved by
Shinya Kitaoka 120a6e
passing
Toshihiro Shimizu 890ddd
\c true at the generator's constructor, proving especially useful considering
Shinya Kitaoka 120a6e
that the same TRenderer may virtually start multiple render instances at the
Shinya Kitaoka 120a6e
same time.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TRenderResourceManagerGenerator {
Shinya Kitaoka 120a6e
  int m_managerIndex;
Shinya Kitaoka 120a6e
  bool m_instanceScope;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TRenderResourceManagerGenerator(bool renderInstanceScope = false);
Shinya Kitaoka 120a6e
  ~TRenderResourceManagerGenerator() {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int getGeneratorIndex() const { return m_managerIndex; }
Shinya Kitaoka 120a6e
  static std::vector<trenderresourcemanagergenerator *=""> &generators();</trenderresourcemanagergenerator>
Shinya Kitaoka 120a6e
  static std::vector<trenderresourcemanagergenerator *=""> &generators(</trenderresourcemanagergenerator>
Shinya Kitaoka 120a6e
      bool instanceScope);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  virtual TRenderResourceManager *operator()(void) = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool hasInstanceScope() const { return m_instanceScope; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRenderResourceManager *getManager(const TRenderer &renderer) const;
Shinya Kitaoka 120a6e
  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
Shinya Kitaoka d1f6c4
class MyManager final : 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
Shinya Kitaoka 120a6e
#define T_RENDER_RESOURCE_MANAGER                                              \
shun-iwasawa 5b7b9f
  \
Shinya Kitaoka 120a6e
public:                                                                        \
Shinya Kitaoka 120a6e
  static TRenderResourceManagerGenerator *gen();                               \
Shinya Kitaoka 120a6e
  static TRenderResourceManagerGenerator *deps();                              \
shun-iwasawa 5b7b9f
  \
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
Shinya Kitaoka 120a6e
#define MANAGER_FILESCOPE_DECLARATION(managerClass, generatorClass)            \
Shinya Kitaoka 120a6e
                                                                               \
Shinya Kitaoka 120a6e
  TRenderResourceManagerGenerator *managerClass::gen() {                       \
Shinya Kitaoka 120a6e
    static generatorClass theInstance;                                         \
Shinya Kitaoka 120a6e
    return &theInstance;                                                       \
Shinya Kitaoka 120a6e
  }                                                                            \
Shinya Kitaoka 120a6e
  TRenderResourceManagerGenerator *managerClass::deps() {                      \
Shinya Kitaoka 120a6e
    return managerClass::gen();                                                \
Shinya Kitaoka 120a6e
  }                                                                            \
Shinya Kitaoka 120a6e
                                                                               \
Shinya Kitaoka 120a6e
  namespace {                                                                  \
Shinya Kitaoka 120a6e
  generatorClass *generatorClass##Instance =                                   \
Shinya Kitaoka 120a6e
      (generatorClass *)managerClass::deps();                                  \
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
/*!  \def MANAGER_FILESCOPE_DECLARATION_DEP(managerClass, generatorClass,
Shinya Kitaoka 120a6e
depsList)
Shinya Kitaoka 120a6e
A variation of the MANAGER_FILESCOPE_DECLARATION macro used to declare
Shinya Kitaoka 120a6e
dependencies between
Shinya Kitaoka 120a6e
resource managers. A manager always receives start notifications \a after those
Shinya Kitaoka 120a6e
from which
Shinya Kitaoka 120a6e
it depends, and viceversa for end notifications. The same applies for
Shinya Kitaoka 120a6e
constructors and destructors.
Toshihiro Shimizu 890ddd
\n \n
Shinya Kitaoka 120a6e
The dependencies declarations list is a sequence of static \c
Shinya Kitaoka 120a6e
<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(
Shinya Kitaoka 120a6e
  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
Shinya Kitaoka 120a6e
#define MANAGER_FILESCOPE_DECLARATION_DEP(managerClass, generatorClass,        \
Shinya Kitaoka 120a6e
                                          depsList)                            \
Shinya Kitaoka 120a6e
                                                                               \
Shinya Kitaoka 120a6e
  TRenderResourceManagerGenerator *managerClass::gen() {                       \
Shinya Kitaoka 120a6e
    static generatorClass theInstance;                                         \
Shinya Kitaoka 120a6e
    return &theInstance;                                                       \
Shinya Kitaoka 120a6e
  }                                                                            \
Shinya Kitaoka 120a6e
  TRenderResourceManagerGenerator *managerClass::deps() {                      \
Shinya Kitaoka 120a6e
    depsList;                                                                  \
Shinya Kitaoka 120a6e
    return managerClass::gen();                                                \
Shinya Kitaoka 120a6e
  }                                                                            \
Shinya Kitaoka 120a6e
                                                                               \
Shinya Kitaoka 120a6e
  namespace {                                                                  \
Shinya Kitaoka 120a6e
  generatorClass *generatorClass##Instance =                                   \
Shinya Kitaoka 120a6e
      (generatorClass *)managerClass::deps();                                  \
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#endif  // TRENDERRESOURCEMANAGER_INCLUDED