1/****************************************************************************************
2
3 Copyright (C) 2015 Autodesk, Inc.
4 All rights reserved.
5
6 Use of this software is subject to the terms of the Autodesk license agreement
7 provided at the time of installation or download, or which otherwise accompanies
8 this software in either electronic or hard copy form.
9
10****************************************************************************************/
11
12//! \file fbxprocessorshaderdependency.h
13#ifndef _FBXSDK_UTILS_PROCESSOR_SHADER_DEPENDENCY_H_
14#define _FBXSDK_UTILS_PROCESSOR_SHADER_DEPENDENCY_H_
15
16#include <fbxsdk/fbxsdk_def.h>
17
18#include <fbxsdk/core/base/fbxhashmap.h>
19#include <fbxsdk/core/base/fbxdynamicarray.h>
20#include <fbxsdk/scene/shading/fbxbindingtable.h>
21
22#include <fbxsdk/fbxsdk_nsbegin.h>
23
24/** Crawls CgFx and HLSL shader files, copies them, and all dependent
25 * shader files into the location specified by RootProcessPath.
26 */
27class FBXSDK_DLL FbxProcessorShaderDependency : public FbxProcessor
28{
29 FBXSDK_OBJECT_DECLARE(FbxProcessorShaderDependency, FbxProcessor);
30
31public:
32 FbxPropertyT<FbxString> RootProcessPath;
33
34 FbxPropertyT<FbxBool> CleanupOnDestroy;
35
36 FbxPropertyT<FbxString> AdditionalIncludePaths;
37
38 void ClearProcessedFiles();
39
40 /**
41 * \name Overridable internal function */
42 //@{
43protected:
44 virtual bool internal_ProcessObject(FbxObject* pObject);
45 //@}
46
47/*****************************************************************************************************************************
48** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
49*****************************************************************************************************************************/
50#ifndef DOXYGEN_SHOULD_SKIP_THIS
51// Constructor / Destructor
52protected:
53 virtual void ConstructProperties(bool pForceSet);
54 virtual void Destruct(bool pRecursive);
55
56public:
57
58 class StringHash
59 {
60 public:
61 unsigned int operator()( const FbxString& pValue ) const
62 {
63 // from wikipedia.org
64 // Jenkins One-at-a-time hash
65
66 size_t lLen = pValue.GetLen();
67 unsigned int lHashValue = 0;
68 const char* lData = pValue.Buffer();
69 for( size_t i = 0; i < lLen; ++i )
70 {
71 lHashValue += lData[i];
72 lHashValue += (lHashValue << 10);
73 lHashValue ^= (lHashValue >> 16);
74 }
75 lHashValue += (lHashValue << 3);
76 lHashValue ^= (lHashValue >> 11);
77 lHashValue += (lHashValue << 15);
78
79 return lHashValue;
80 }
81 };
82
83protected:
84
85 class FileDeleter
86 {
87 public:
88 FileDeleter( const char* pFileUrl ) : mFileUrl( pFileUrl) {};
89 ~FileDeleter()
90 {
91 if( !mFileUrl.IsEmpty() )
92 {
93 remove( mFileUrl );
94 }
95 };
96
97 void Release() { mFileUrl = ""; }
98
99 private: FbxString mFileUrl;
100 };
101
102 // first == string as it appears in the file
103 // second == string URL
104 struct FilePathData
105 {
106 FbxString mOriginalStr;
107 FbxString mOriginalAbsUrl;
108
109 FbxString mNewStr;
110 };
111
112 typedef FbxDynamicArray< FilePathData > FilePathList;
113
114 virtual bool GetIncludePaths( FbxString& pFile, FilePathList& pPaths, FbxXRefManager& pManager ) const;
115 virtual bool ReplaceUrls( const FbxString& pFileUrl, const FbxString& pNewFileUrl,
116 const FilePathList& pPaths ) const;
117
118private:
119 struct Dependency
120 {
121 FbxString mNewUrl;
122 FbxString mOriginalUrl;
123 };
124
125 typedef FbxHashMap< FbxString, Dependency, StringHash > DependMap;
126
127 DependMap mDependMap;
128
129 FbxString mRootPath;
130
131 FbxXRefManager mResolver;
132 int mSystemIndex;
133
134 // magic number to limit the size of files we can parse =(
135 static const int sMaxFileSize;
136
137 bool ParseDependencies( const FbxBindingTable& pTable );
138 bool AddDependency( FbxString& pFileUrl );
139 bool AddSystemPaths();
140#endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
141};
142
143#include <fbxsdk/fbxsdk_nsend.h>
144
145#endif /* _FBXSDK_UTILS_PROCESSOR_SHADER_DEPENDENCY_H_ */
146