Initial commit, includes Lua with broken Luabind as a backup for branching purposes
[terrastrategy.git] / include / renderer / effect.h
blobd158fa7bacb2d75f6b86d9d147cc7fa501b76401
1 //
2 // Copyright (C) 2007 by Martin Moracek
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 /**
20 * @file effect.h
22 * Ble.
25 #pragma once
27 #include <string>
28 #include <vector>
29 #include <boost/utility.hpp>
30 #include <boost/array.hpp>
31 #include <boost/smart_ptr.hpp>
33 #include <tr1/unordered_map>
35 #include "types.h"
36 #include "cpair.h"
37 #include "renderer/texture.h"
39 namespace tre {
41 // data types for uniform variables
42 enum EffectVarType {
43 vtFloat1,
44 vtFloat2,
45 vtFloat3,
46 vtFloat4,
47 vtInt1,
48 vtInt2,
49 vtInt3,
50 vtInt4,
51 vtTexture
54 // builtins for all shader types
55 enum InternalsType { // Semantic, annotations...
56 itTime, // Time
57 itSysTime, // Time, type = "system"
58 // state matrices
59 itMVPMatrix, // ModelViewProjection
60 itMVPMatrixInv, // ModelViewProjection, inverse = true
61 itMVPMatrixTrans, // ModelViewProjection, transpose=true
62 itMVPMatrixInvTrans,// ModelViewProjection, inverse = true, transpose=true
63 itMVMatrix, // ModelView
64 itMVMatrixInv, // ModelView, inverse = true
65 itMVMatrixTrans, // ModelView, transpose=true
66 itMVMatrixInvTrans, // ModelView, transpose=true
67 itPMatrix, // Projection
68 itPMatrixInv, // Projection, inverse = true
69 itPMatrixTrans, // Projection, transpose=true
70 itPMatrixInvTrans, // Projection, transpose=true
71 itTMatrix, // Texture
72 itTMatrixInv, // Texture, inverse = true
73 itTMatrixTrans, // Texture, transpose=true
74 itTMatrixInvTrans, // Texture, transpose=true
75 // last entry
76 itLast
79 // variable declarations for general use
80 typedef boost::array<float, 4> FxFVar;
81 typedef boost::array<int, 4> FxIVar;
83 typedef cpair<std::string, FxFVar> FxFPair;
84 typedef cpair<std::string, FxIVar> FxIPair;
85 typedef cpair<std::string, TexturePtr> FxSPair;
87 typedef std::vector<FxFPair> FVarVector;
88 typedef std::vector<FxIPair> IVarVector;
89 typedef std::vector<FxSPair> SVarVector;
91 struct EffectVars {
92 FVarVector fvars;
93 IVarVector ivars;
94 SVarVector samplers;
96 EffectVars();
97 ~EffectVars();
99 void SetTexture(const std::string & name, const std::string & var);
100 void SetTexture(const std::string & name, const TexturePtr & var);
104 * Effect class
106 class Effect;
108 typedef boost::shared_ptr<Effect> EffectPtr;
109 typedef boost::weak_ptr<Effect> EffectRef;
111 class EffectFactory {
112 public:
113 const EffectPtr CreateInstance(const std::string & name);
115 private:
116 typedef std::tr1::unordered_map<std::string, EffectRef> EffectMap;
118 private:
119 EffectMap map_;
122 class Effect : private boost::noncopyable {
123 public:
124 static EffectFactory & Factory(void)
126 static EffectFactory fac;
127 return fac;
130 public:
131 virtual ~Effect() {}