[692] | 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-2005 The OGRE Team
|
---|
| 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 | */
|
---|
| 25 | #ifndef __QUAKE3SHADERMANAGER_H__
|
---|
| 26 | #define __QUAKE3SHADERMANAGER_H__
|
---|
| 27 |
|
---|
| 28 | #include "OgreBspPrerequisites.h"
|
---|
| 29 | #include "OgreSingleton.h"
|
---|
| 30 | #include "OgreResourceManager.h"
|
---|
| 31 | #include "OgreQuake3Shader.h"
|
---|
| 32 | #include "OgreBlendMode.h"
|
---|
| 33 |
|
---|
| 34 | namespace Ogre {
|
---|
| 35 |
|
---|
| 36 |
|
---|
| 37 | /** Class for managing Quake3 custom shaders.
|
---|
| 38 | Quake3 uses .shader files to define custom shaders, or Materials in Ogre-speak.
|
---|
| 39 | When a surface texture is mentioned in a level file, it includes no file extension
|
---|
| 40 | meaning that it can either be a standard texture image (+lightmap) if there is only a .jpg or .tga
|
---|
| 41 | file, or it may refer to a custom shader if a shader with that name is included in one of the .shader
|
---|
| 42 | files in the scripts/ folder. Because there are multiple shaders per file you have to parse all the
|
---|
| 43 | .shader files available to know if there is a custom shader available. This class is designed to parse
|
---|
| 44 | all the .shader files available and save their settings for future use. </p>
|
---|
| 45 | I choose not to set up Material instances for shaders found since they may or may not be used by a level,
|
---|
| 46 | so it would be very wasteful to set up Materials since they load texture images for each layer (apart from the
|
---|
| 47 | lightmap). Once the usage of a shader is confirmed, a full Material instance can be set up from it.</p>
|
---|
| 48 | Because this is a subclass of ScriptLoader, any files mentioned will be searched for in any path or
|
---|
| 49 | archive added to the ResourceGroupManager::WORLD_GROUP_NAME group. See ResourceGroupManager for details.
|
---|
| 50 | */
|
---|
| 51 | class Quake3ShaderManager : public ScriptLoader, public Singleton<Quake3ShaderManager>
|
---|
| 52 | {
|
---|
| 53 | protected:
|
---|
| 54 | void parseNewShaderPass(DataStreamPtr& stream, Quake3Shader* pShader);
|
---|
| 55 | void parseShaderAttrib( const String& line, Quake3Shader* pShader);
|
---|
| 56 | void parseShaderPassAttrib( const String& line, Quake3Shader* pShader, Quake3Shader::Pass* pPass);
|
---|
| 57 | SceneBlendFactor convertBlendFunc( const String& q3func);
|
---|
| 58 |
|
---|
| 59 | typedef std::map<String, Quake3Shader*> Quake3ShaderMap;
|
---|
| 60 | Quake3ShaderMap mShaderMap;
|
---|
| 61 | StringVector mScriptPatterns;
|
---|
| 62 |
|
---|
| 63 |
|
---|
| 64 | public:
|
---|
| 65 | Quake3ShaderManager();
|
---|
| 66 | virtual ~Quake3ShaderManager();
|
---|
| 67 |
|
---|
| 68 | /** @copydoc ScriptLoader::getScriptPatterns */
|
---|
| 69 | const StringVector& getScriptPatterns(void) const;
|
---|
| 70 |
|
---|
| 71 | /** @copydoc ScriptLoader::parseScript */
|
---|
| 72 | void parseScript(DataStreamPtr& stream, const String& groupName);
|
---|
| 73 |
|
---|
| 74 | /** @copydoc ScriptLoader::parseScript */
|
---|
| 75 | Real getLoadingOrder(void) const;
|
---|
| 76 |
|
---|
| 77 | /** Create implementation. */
|
---|
| 78 | Quake3Shader* create(const String& name);
|
---|
| 79 | /** Clear all the current shaders */
|
---|
| 80 | void clear(void);
|
---|
| 81 | /** Retrieve a Quake3Shader by name */
|
---|
| 82 | Quake3Shader* getByName(const String& name);
|
---|
| 83 |
|
---|
| 84 | /** Override standard Singleton retrieval.
|
---|
| 85 | @remarks
|
---|
| 86 | Why do we do this? Well, it's because the Singleton
|
---|
| 87 | implementation is in a .h file, which means it gets compiled
|
---|
| 88 | into anybody who includes it. This is needed for the
|
---|
| 89 | Singleton template to work, but we actually only want it
|
---|
| 90 | compiled into the implementation of the class based on the
|
---|
| 91 | Singleton, not all of them. If we don't change this, we get
|
---|
| 92 | link errors when trying to use the Singleton-based class from
|
---|
| 93 | an outside dll.
|
---|
| 94 | @par
|
---|
| 95 | This method just delegates to the template version anyway,
|
---|
| 96 | but the implementation stays in this single compilation unit,
|
---|
| 97 | preventing link errors.
|
---|
| 98 | */
|
---|
| 99 | static Quake3ShaderManager& getSingleton(void);
|
---|
| 100 | /** Override standard Singleton retrieval.
|
---|
| 101 | @remarks
|
---|
| 102 | Why do we do this? Well, it's because the Singleton
|
---|
| 103 | implementation is in a .h file, which means it gets compiled
|
---|
| 104 | into anybody who includes it. This is needed for the
|
---|
| 105 | Singleton template to work, but we actually only want it
|
---|
| 106 | compiled into the implementation of the class based on the
|
---|
| 107 | Singleton, not all of them. If we don't change this, we get
|
---|
| 108 | link errors when trying to use the Singleton-based class from
|
---|
| 109 | an outside dll.
|
---|
| 110 | @par
|
---|
| 111 | This method just delegates to the template version anyway,
|
---|
| 112 | but the implementation stays in this single compilation unit,
|
---|
| 113 | preventing link errors.
|
---|
| 114 | */
|
---|
| 115 | static Quake3ShaderManager* getSingletonPtr(void);
|
---|
| 116 |
|
---|
| 117 |
|
---|
| 118 | };
|
---|
| 119 |
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | #endif
|
---|