SO3Engine
SO3ShaderGenerator.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
32#ifndef __SO3SHADERGENERATOR_H__
33#define __SO3SHADERGENERATOR_H__
34
36#include <sstream>
37
38namespace SO3
39{
40
41class _SO3_Export SShaderGenerator
42{
43public:
44 typedef std::list<Ogre::GpuProgramPtr> GeneratedShaders;
46
47 static void Reset()
48 {
49 for (std::list<Ogre::GpuProgramPtr>::iterator it = mGeneratedShaders.begin(); it != mGeneratedShaders.end(); it++)
50 {
51 Ogre::GpuProgramPtr shaderPtr = (*it);
52 shaderPtr->unload();
53 Ogre::GpuProgramManager::getSingleton().remove(shaderPtr);
54 }
55 mGeneratedShaders.clear();
56 }
57
59 {
62 ShaderGeneratorRTSS
63 };
64
66 {
67 MAP_DUMMY = 1,
68 MAP_AMBIENT = 2,
69 MAP_DIFFUSE = 4,
70 MAP_BUMP = 8,
71 MAP_NORMAL = 16,
72 MAP_SPECULAR = 32,
73 MAP_SHININESS = 64,
74 MAP_EMISSIVE = 128,
75 MAP_REFLECTION = 256,
76 MAP_FRESNEL = 512,
77 MAP_REFMASK = 1024,
78 MAP_OPACITY = 2048,
79 MAP_ROUGHNESS = 4096
80 };
81
82protected:
83
85 Ogre::Pass* mPass;
86 Ogre::Technique* mTechnique;
88 std::string mShaderName;
89 std::vector<ShaderMapType> mTexTypes;
90 std::vector<unsigned int> mTexUnits;
91 std::vector<unsigned int> mSortedTexUnits;
92 std::vector<bool> mAnimatedUv;
93 std::vector<bool> mCubeUv;
94 std::vector<bool> mSortedCubeUv;
95 std::stringstream mSource;
96 std::string mParams;
97 std::string mProgram;
104 unsigned int mNbLights;
105private:
106
107public:
110 SShaderGenerator(Ogre::Technique*, Ogre::Pass* pass, ShaderType type, bool ignoreSlicePlane = false);
111
115
118 std::string GetShaderName();
119
122 bool IsUvAnimated(int uvindex);
123
126 bool IsAlphaRejected();
127
130 int GetConfig();
131
134 virtual void ComputeShaderCode();
135
138 virtual std::string GetUniformParams();
139
142 virtual std::string GetProgram();
143
146 virtual void ApplyShader();
147protected:
148private:
153
156 void ComputePass();
157};
158
159}
160
161#endif
librairies include
std::vector< unsigned int > mSortedTexUnits
std::list< Ogre::GpuProgramPtr > GeneratedShaders
Ogre::Technique * mTechnique
std::vector< ShaderMapType > mTexTypes
std::vector< bool > mSortedCubeUv
std::stringstream mSource
std::vector< unsigned int > mTexUnits
std::vector< bool > mCubeUv
std::vector< bool > mAnimatedUv
static GeneratedShaders mGeneratedShaders