1 | /* |
---|
2 | ----------------------------------------------------------------------------- |
---|
3 | This source file is part of OGRE |
---|
4 | (Object-oriented Graphics Rendering Engine) |
---|
5 | For the latest info, see http://www.ogre3d.org/ |
---|
6 | |
---|
7 | Copyright (c) 2000-2006 Torus Knot Software Ltd |
---|
8 | Also see acknowledgements in Readme.html |
---|
9 | |
---|
10 | This program is free software; you can redistribute it and/or modify it under |
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
12 | Foundation; either version 2 of the License, or (at your option) any later |
---|
13 | version. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU Lesser General Public License along with |
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
22 | http://www.gnu.org/copyleft/lesser.txt. |
---|
23 | |
---|
24 | You may alternatively use this source under the terms of a specific version of |
---|
25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
26 | Torus Knot Software Ltd. |
---|
27 | ----------------------------------------------------------------------------- |
---|
28 | */ |
---|
29 | #ifndef __QUAKE3SHADERMANAGER_H__ |
---|
30 | #define __QUAKE3SHADERMANAGER_H__ |
---|
31 | |
---|
32 | #include "OgreBspPrerequisites.h" |
---|
33 | #include "OgreSingleton.h" |
---|
34 | #include "OgreResourceManager.h" |
---|
35 | #include "OgreQuake3Shader.h" |
---|
36 | #include "OgreBlendMode.h" |
---|
37 | |
---|
38 | namespace Ogre { |
---|
39 | |
---|
40 | |
---|
41 | /** Class for managing Quake3 custom shaders. |
---|
42 | Quake3 uses .shader files to define custom shaders, or Materials in Ogre-speak. |
---|
43 | When a surface texture is mentioned in a level file, it includes no file extension |
---|
44 | meaning that it can either be a standard texture image (+lightmap) if there is only a .jpg or .tga |
---|
45 | file, or it may refer to a custom shader if a shader with that name is included in one of the .shader |
---|
46 | files in the scripts/ folder. Because there are multiple shaders per file you have to parse all the |
---|
47 | .shader files available to know if there is a custom shader available. This class is designed to parse |
---|
48 | all the .shader files available and save their settings for future use. </p> |
---|
49 | I choose not to set up Material instances for shaders found since they may or may not be used by a level, |
---|
50 | so it would be very wasteful to set up Materials since they load texture images for each layer (apart from the |
---|
51 | lightmap). Once the usage of a shader is confirmed, a full Material instance can be set up from it.</p> |
---|
52 | Because this is a subclass of ScriptLoader, any files mentioned will be searched for in any path or |
---|
53 | archive added to the ResourceGroupManager::WORLD_GROUP_NAME group. See ResourceGroupManager for details. |
---|
54 | */ |
---|
55 | class Quake3ShaderManager : public ScriptLoader, public Singleton<Quake3ShaderManager> |
---|
56 | { |
---|
57 | protected: |
---|
58 | void parseNewShaderPass(DataStreamPtr& stream, Quake3Shader* pShader); |
---|
59 | void parseShaderAttrib( const String& line, Quake3Shader* pShader); |
---|
60 | void parseShaderPassAttrib( const String& line, Quake3Shader* pShader, Quake3Shader::Pass* pPass); |
---|
61 | SceneBlendFactor convertBlendFunc( const String& q3func); |
---|
62 | |
---|
63 | typedef std::map<String, Quake3Shader*> Quake3ShaderMap; |
---|
64 | Quake3ShaderMap mShaderMap; |
---|
65 | StringVector mScriptPatterns; |
---|
66 | |
---|
67 | |
---|
68 | public: |
---|
69 | Quake3ShaderManager(); |
---|
70 | virtual ~Quake3ShaderManager(); |
---|
71 | |
---|
72 | /** @copydoc ScriptLoader::getScriptPatterns */ |
---|
73 | const StringVector& getScriptPatterns(void) const; |
---|
74 | |
---|
75 | /** @copydoc ScriptLoader::parseScript */ |
---|
76 | void parseScript(DataStreamPtr& stream, const String& groupName); |
---|
77 | |
---|
78 | /** @copydoc ScriptLoader::parseScript */ |
---|
79 | Real getLoadingOrder(void) const; |
---|
80 | |
---|
81 | /** Create implementation. */ |
---|
82 | Quake3Shader* create(const String& name); |
---|
83 | /** Clear all the current shaders */ |
---|
84 | void clear(void); |
---|
85 | /** Retrieve a Quake3Shader by name */ |
---|
86 | Quake3Shader* getByName(const String& name); |
---|
87 | |
---|
88 | /** Override standard Singleton retrieval. |
---|
89 | @remarks |
---|
90 | Why do we do this? Well, it's because the Singleton |
---|
91 | implementation is in a .h file, which means it gets compiled |
---|
92 | into anybody who includes it. This is needed for the |
---|
93 | Singleton template to work, but we actually only want it |
---|
94 | compiled into the implementation of the class based on the |
---|
95 | Singleton, not all of them. If we don't change this, we get |
---|
96 | link errors when trying to use the Singleton-based class from |
---|
97 | an outside dll. |
---|
98 | @par |
---|
99 | This method just delegates to the template version anyway, |
---|
100 | but the implementation stays in this single compilation unit, |
---|
101 | preventing link errors. |
---|
102 | */ |
---|
103 | static Quake3ShaderManager& getSingleton(void); |
---|
104 | /** Override standard Singleton retrieval. |
---|
105 | @remarks |
---|
106 | Why do we do this? Well, it's because the Singleton |
---|
107 | implementation is in a .h file, which means it gets compiled |
---|
108 | into anybody who includes it. This is needed for the |
---|
109 | Singleton template to work, but we actually only want it |
---|
110 | compiled into the implementation of the class based on the |
---|
111 | Singleton, not all of them. If we don't change this, we get |
---|
112 | link errors when trying to use the Singleton-based class from |
---|
113 | an outside dll. |
---|
114 | @par |
---|
115 | This method just delegates to the template version anyway, |
---|
116 | but the implementation stays in this single compilation unit, |
---|
117 | preventing link errors. |
---|
118 | */ |
---|
119 | static Quake3ShaderManager* getSingletonPtr(void); |
---|
120 | |
---|
121 | |
---|
122 | }; |
---|
123 | |
---|
124 | } |
---|
125 | |
---|
126 | #endif |
---|