Katana Plug-in APIs 0.1

RendererInfoBase.h

00001 // Copyright (c) 2013 The Foundry Visionmongers Ltd. All Rights Reserved.
00002 
00003 #ifndef FNRENDERERINFO_RENDERERINFOBASE_H
00004 #define FNRENDERERINFO_RENDERERINFOBASE_H
00005 
00006 #include <FnPluginSystem/FnPluginSystem.h>
00007 #include <FnPluginSystem/FnPlugin.h>
00008 
00009 #include <FnAttribute/FnAttribute.h>
00010 #include <FnAttribute/FnGroupBuilder.h>
00011 
00012 #include <FnRendererInfo/suite/RendererObjectDefinitions.h>
00013 #include <FnRendererInfo/suite/FnRendererInfoSuite.h>
00014 
00015 #include <FnRendererInfo/plugin/RenderMethod.h>
00016 #include <FnRendererInfo/plugin/LiveRenderControlModule.h>
00017 #include <FnRendererInfo/plugin/LiveRenderFilter.h>
00018 #include <FnRendererInfo/FnRendererInfoAPI.h>
00019 
00020 #include <FnPlatform/internal/UniquePtr.h>
00021 
00022 #include <iostream>
00023 #include <string>
00024 #include <memory>
00025 #include <map>
00026 #include <set>
00027 #include <deque>
00028 #include <utility>
00029 
00030 namespace Foundry
00031 {
00032 namespace Katana
00033 {
00034 namespace RendererInfo
00035 {
00072     class FNRENDERERINFO_API RendererInfoBase
00073     {
00074     public:
00075         RendererInfoBase();
00076         virtual ~RendererInfoBase() {}
00077 
00084         virtual void configureBatchRenderMethod(RendererInfo::DiskRenderMethod& batchRenderMethod) const = 0;
00085 
00091         virtual void fillRenderMethods(std::vector<RendererInfo::RenderMethod*>& renderMethods) const = 0;
00092 
00115         virtual void fillRendererObjectTypes(std::vector<std::string>& renderObjectTypes,
00116                                              const std::string& type) const = 0;
00117 
00130         virtual std::string getRendererObjectDefaultType(const std::string& type) const;
00131 
00132         typedef std::pair<std::string, FnAttribute::GroupAttribute> OpDefinition;
00133         typedef std::deque<OpDefinition> OpDefinitionQueue;
00134 
00154         virtual void fillLiveRenderTerminalOps(OpDefinitionQueue& terminalOps,
00155                 const FnAttribute::GroupAttribute& stateArgs) const {}
00156 
00176         virtual void fillRenderTerminalOps(OpDefinitionQueue& terminalOps,
00177                 const FnAttribute::GroupAttribute& stateArgs) const {}
00178 
00179 
00198         virtual void fillRendererObjectNames(std::vector<std::string>& rendererObjectNames,
00199                                              const std::string& type,
00200                                              const std::vector<std::string>& typeTags) const = 0;
00201 
00207         virtual std::string getRegisteredRendererName() const = 0;
00208 
00215         virtual std::string getRegisteredRendererVersion() const = 0;
00216 
00224         virtual bool isPresetLocalFileNeeded(const std::string& outputType) const { return false; }
00225 
00234         virtual bool isNodeTypeSupported(const std::string& nodeType) const { return false; }
00235 
00242         virtual bool isPolymeshFacesetSplittingEnabled() const { return false; }
00243 
00252         virtual void fillShaderInputNames(std::vector<std::string>& shaderInputNames,
00253                                           const std::string& shaderName) const;
00254 
00269         virtual void fillShaderInputTags(std::vector<std::string>& shaderInputTags,
00270                                          const std::string& shaderName,
00271                                          const std::string& inputName) const;
00272 
00281         virtual void fillShaderOutputNames(std::vector<std::string>& shaderOutputNames,
00282                                            const std::string& shaderName) const;
00283 
00298         virtual void fillShaderOutputTags(std::vector<std::string>& shaderOutputTags,
00299                                           const std::string& shaderName,
00300                                           const std::string& outputName) const;
00301 
00302         virtual void fillRendererShaderTypeTags(std::vector<std::string>& shaderTypeTags,
00303                                                 const std::string& shaderType) const;
00304 
00311         virtual std::string getRendererCoshaderType() const  { return ""; }
00312 
00321         virtual void buildLiveRenderControlModules(FnAttribute::GroupBuilder& liveRenderControlModules) const {}
00322 
00341         virtual bool buildRendererObjectInfo(FnAttribute::GroupBuilder& rendererObjectInfo,
00342                                              const std::string& name,
00343                                              const std::string& type,
00344                                              const FnAttribute::GroupAttribute inputAttr) const = 0;
00345 
00349         virtual void flushCaches() {}
00350 
00358         std::string getPluginPath() const;
00359 
00369         std::string getPluginRootPath() const;
00370 
00371         void setPluginPath(const std::string& pluginPath);
00372         void setPluginRootPath(const std::string& pluginRootPath);
00373 
00374         void setKatanaPath(const std::string& katana_path);
00375         std::string getKatanaPath() const;
00376 
00377         void setTmpPath(const std::string& tmp_path);
00378         std::string getTmpPath() const;
00379 
00380         // non-virtual implementations to do conversions and cache results from virtual functions above
00381         FnAttribute::Attribute _getRenderMethods();
00382         FnAttribute::Attribute _getBatchRenderMethod();
00383         FnAttribute::Attribute _getRendererObjectNames(const std::string& type,
00384                                           const std::vector<std::string>& typeTags);
00385         FnAttribute::Attribute _getRendererObjectTypes(const std::string& type);
00386         FnAttribute::Attribute _getRendererShaderTypeTags(const std::string& shaderType);
00387         FnAttribute::Attribute _getRendererCoshaderType();
00388         FnAttribute::Attribute _getRegisteredRendererName();
00389         FnAttribute::Attribute _getRegisteredRendererVersion();
00390         FnAttribute::Attribute _getRendererObjectDefaultType(const std::string& type);
00391 
00392         FnAttribute::Attribute _getShaderInputNames(const std::string& shaderName);
00393         FnAttribute::Attribute _getShaderInputTags(const std::string& shaderName,
00394                                       const std::string& inputName);
00395 
00396         FnAttribute::Attribute _getShaderOutputNames(const std::string& shaderName);
00397         FnAttribute::Attribute _getShaderOutputTags(const std::string& shaderName,
00398                                        const std::string& outputName);
00399 
00400         FnAttribute::Attribute _getRendererObjectInfo(const std::string& name,
00401                                          const std::string& typeTag,
00402                                          const FnAttributeHandle inputData = 0x0);
00403 
00404         void _setTypeTagNameFilter(const std::string& filter,
00405                                    const std::string& typeTag);
00406 
00407         void _addObjectLocation(const std::string& type,
00408                                 const std::string& location);
00409 
00410         void _clearObjectLocations(const std::string& type);
00411 
00412         void _flushCaches();
00413 
00414         FnAttribute::Attribute _getLiveRenderTerminalOps(
00415                 const FnAttributeHandle stateArgs);
00416         FnAttribute::Attribute _getRenderTerminalOps(
00417                 const FnAttributeHandle stateArgs);
00418 
00420         static FnPlugStatus                 setHost(FnPluginHost* host);
00421         static FnPluginHost*                getHost();
00422         static RendererInfoPluginSuite_v2   createSuite(RendererInfoPluginHandle (*create)());
00423 
00424         static RendererInfoPluginHandle     newRendererInfoPluginHandle(RendererInfoBase* rendererInfoPlugin);
00425 
00426         static unsigned int                 _apiVersion;
00427         static const char*                  _apiName;
00429 
00450         static void configureBasicRenderObjectInfo(FnAttribute::GroupBuilder& renderObjectInfo,
00451                                                    const std::string& type,
00452                                                    const std::vector<std::string>& typeTags,
00453                                                    const std::string& location,
00454                                                    const std::string& fullPath,
00455                                                    int outputType,
00456                                                    FnAttribute::Attribute containerHints);
00457 
00458     protected:
00459         typedef std::pair<std::string, int> EnumPair;
00460         typedef std::vector<EnumPair> EnumPairVector;
00461 
00478         void addRenderObjectParam(FnAttribute::GroupBuilder& renderObjectInfo,
00479                                   const std::string& name,
00480                                   int type,
00481                                   int arraySize,
00482                                   FnAttribute::Attribute defaultAttr,
00483                                   FnAttribute::Attribute hintsAttr,
00484                                   const EnumPairVector& enumValues) const;
00485 
00500         void setShaderParameterMapping(
00501             FnAttribute::GroupBuilder& renderObjectInfo,
00502             const std::string& metaName, const std::string& actualName) const;
00503 
00519         void setShaderParameterMapping(
00520             FnAttribute::GroupBuilder& renderObjectInfo,
00521             const std::string& metaName,
00522             const std::vector<std::string>& actualNames) const;
00523 
00524         void getTypeTagsUsingNameFilters(const std::string& name,
00525                                          std::set<std::string>& typeTags) const;
00526 
00527         bool findTypeTagsInObjectTypeTags(const std::vector<std::string>& typeTags,
00528                                           const std::set<std::string>& objectTypeTags) const;
00529 
00530         typedef std::map<std::string, std::vector<std::string> > ObjectLocationsMap;
00531 
00532         const ObjectLocationsMap& getAdditionalObjectLocations() const {return _additionalObjectLocations;}
00533         const std::vector<std::string>& getAdditionalObjectLocations(const std::string& type) const {return _additionalObjectLocations[type];}
00534 
00536     private:
00537 
00538         static FnPluginHost* _host;
00539 
00540         typedef std::map<std::string, std::string> StringMap;
00541         typedef std::map<std::string, FnAttribute::Attribute> AttributeMap;
00542 
00543         AttributeMap _objectNames;
00544         AttributeMap _objectTypes;
00545         AttributeMap _shaderInputNames;
00546         AttributeMap _shaderInputTags;
00547         AttributeMap _shaderOutputNames;
00548         AttributeMap _shaderOutputTags;
00549         AttributeMap _objectInfo;
00550 
00551         bool _liveRenderControlModulesCached;
00552         FnAttribute::GroupAttribute _liveRenderControlModules;
00553 
00554         mutable ObjectLocationsMap _additionalObjectLocations;  // (locations by primary type)
00555 
00556         StringMap _typeTagFilters;
00557 
00558         std::string _pluginPath;
00559         std::string _pluginRootPath;
00560         std::string _katanaPath;
00561         std::string _tmpPath;
00562 
00564     };
00565 
00569 }
00570 }
00571 }
00572 
00573 namespace FnKat = Foundry::Katana;
00574 
00576 
00577 #define DEFINE_RENDERERINFO_PLUGIN(RENDERERINFO_CLASS)                                          \
00578                                                                                                 \
00579   FnPlugin RENDERERINFO_CLASS##_plugin;                                                         \
00580                                                                                                 \
00581   RendererInfoPluginHandle RENDERERINFO_CLASS##_create()                                        \
00582   {                                                                                             \
00583         return Foundry::Katana::RendererInfo::RendererInfoBase::newRendererInfoPluginHandle(    \
00584             RENDERERINFO_CLASS::create());                                                      \
00585   }                                                                                             \
00586                                                                                                 \
00587   RendererInfoPluginSuite_v2 RENDERERINFO_CLASS##_suite =                                       \
00588     Foundry::Katana::RendererInfo::RendererInfoBase::createSuite(RENDERERINFO_CLASS##_create);  \
00589                                                                                                 \
00590   const void* RENDERERINFO_CLASS##_getSuite()                                                   \
00591   {                                                                                             \
00592         return &RENDERERINFO_CLASS##_suite;                                                     \
00593   }                                                                                             \
00594 
00595 struct FNRENDERERINFO_API RendererInfoPluginStruct
00596 {
00597 public:
00598     RendererInfoPluginStruct(Foundry::Katana::RendererInfo::RendererInfoBase* rendererInfoPlugin) :
00599     _rendererInfoPlugin(rendererInfoPlugin) { /* Empty */ }
00600     ~RendererInfoPluginStruct() { /* Empty */ }
00601 
00602     Foundry::Katana::RendererInfo::RendererInfoBase& getRendererInfoPlugin()
00603     {
00604         return *_rendererInfoPlugin;
00605     }
00606 
00607 private:
00608     FnPlatform::internal::UniquePtr<
00609         Foundry::Katana::RendererInfo::RendererInfoBase>::type
00610             _rendererInfoPlugin;
00611 };
00612 
00614 
00615 #endif
 All Classes Functions Variables Typedefs Enumerations Enumerator