imaterial.h

Go to the documentation of this file.
00001 
00006 /*
00007  Copyright (C) 1999-2006 Id Software, Inc. and contributors.
00008  For a list of contributors, see the accompanying CONTRIBUTORS file.
00009 
00010  This file is part of GtkRadiant.
00011 
00012  GtkRadiant is free software; you can redistribute it and/or modify
00013  it under the terms of the GNU General Public License as published by
00014  the Free Software Foundation; either version 2 of the License, or
00015  (at your option) any later version.
00016 
00017  GtkRadiant is distributed in the hope that it will be useful,
00018  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  GNU General Public License for more details.
00021 
00022  You should have received a copy of the GNU General Public License
00023  along with GtkRadiant; if not, write to the Free Software
00024  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00025  */
00026 
00027 #ifndef IMATERIAL_H
00028 #define IMATERIAL_H
00029 
00030 #include "modulesystem.h"
00031 #include "modulesystem/moduleregistry.h"
00032 #include "moduleobserver.h"
00033 #include "generic/constant.h"
00034 #include <string>
00035 #include <map>
00036 #include "ifilesystem.h"
00037 #include "ishader.h"
00038 
00039 class MaterialShader: public IShader
00040 {
00041     private:
00042 
00043         std::size_t _refcount;
00044 
00045         std::string _fileName;
00046 
00047         BlendFunc _blendFunc;
00048 
00049         bool _inUse;
00050 
00051         qtexture_t* _texture;
00052 
00053         qtexture_t* _notfound;
00054 
00055     public:
00056 
00057         MaterialShader (const std::string& fileName);
00058 
00059         virtual ~MaterialShader ();
00060 
00061         // IShaders implementation -----------------
00062         void IncRef ();
00063         void DecRef ();
00064 
00065         std::size_t refcount ();
00066 
00067         // get/set the qtexture_t* Radiant uses to represent this shader object
00068         qtexture_t* getTexture () const;
00069 
00070         // get shader name
00071         const char* getName () const;
00072 
00073         bool IsInUse () const;
00074 
00075         void SetInUse (bool inUse);
00076 
00077         // get the shader flags
00078         int getFlags () const;
00079 
00080         // get the transparency value
00081         float getTrans () const;
00082 
00083         // test if it's a true shader, or a default shader created to wrap around a texture
00084         bool IsDefault () const;
00085 
00086         // get the alphaFunc
00087         void getAlphaFunc (EAlphaFunc *func, float *ref);
00088 
00089         BlendFunc getBlendFunc () const;
00090 
00091         // get the cull type
00092         ECull getCull ();
00093 
00094         void realise ();
00095 
00096         void unrealise ();
00097 };
00098 
00099 
00100 class MaterialSystem
00101 {
00102     private:
00103 
00104         void generateMaterialForFace (int contentFlags, int surfaceFlags, std::string& textureName,
00105                 std::stringstream& stream);
00106 
00107         typedef std::map<std::string, MaterialShader*> MaterialShaders;
00108         MaterialShaders _activeMaterialShaders;
00109 
00110     public:
00111         INTEGER_CONSTANT(Version, 1);
00112         STRING_CONSTANT(Name, "material");
00113 
00114         virtual ~MaterialSystem ()
00115         {
00116         }
00117 
00121         MaterialSystem ();
00122 
00127         void showMaterialDefinition (const std::string& append = "");
00128 
00132         const std::string getMaterialFilename () const;
00133 
00138         void importMaterialFile (const std::string& name);
00139 
00143         void generateMaterialFromTexture ();
00144 
00149         IShader* getMaterialForName (const std::string& name);
00150 };
00151 
00152 class MaterialSystemDependencies: public GlobalFileSystemModuleRef
00153 {
00154 };
00155 
00156 // This is needed to be registered as a Radiant dependency
00157 template<typename Type>
00158 class GlobalModule;
00159 typedef GlobalModule<MaterialSystem> GlobalMaterialSystemModule;
00160 
00161 // A reference to the call above.
00162 template<typename Type>
00163 class GlobalModuleRef;
00164 typedef GlobalModuleRef<MaterialSystem> GlobalMaterialSystemModuleRef;
00165 
00166 // Accessor method
00167 inline MaterialSystem * GlobalMaterialSystem ()
00168 {
00169     Module * materialSystem = globalModuleServer().findModule(MaterialSystem::Name_CONSTANT_::evaluate(),
00170             MaterialSystem::Version_CONSTANT_::evaluate(), "*");
00171     ASSERT_MESSAGE(materialSystem,
00172             "Couldn't retrieve GlobalMaterialSystem, is not registered and/or initialized.");
00173     return (MaterialSystem *) materialSystem->getTable(); // findModule returns the pointer to the valid value, DO NOT DELETE!
00174 }
00175 
00176 #endif  /* IMATERIAL_H */

Generated by  doxygen 1.6.2