source: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCubeMapRenderTechnique.cpp @ 1886

Revision 1886, 10.8 KB checked in by szirmay, 18 years ago (diff)
Line 
1#include "OgreCubeMapRenderTechnique.h"
2#include "OgreTechniqueGroup.h"
3#include "OgreCubeMapRenderingRun.h"
4
5OgreCubeMapRenderTechnique::OgreCubeMapRenderTechnique(unsigned long startFrame,
6                                                                                                                unsigned long cubeMapUpdateInterval,
7                                                                                                                unsigned int cubeMapResolution,                                                                                         
8                                                                                                                unsigned char texID,
9                                                                                                                bool useDistCalc,
10                                                                                                                bool useFaceAngleCalc,
11                                                                                                                float distTolerance,
12                                                                                                                float angleTolerance,
13                                                                                                                bool updateAllFace,
14                                                                                                                bool renderSelf,
15                                                                                                                bool renderEnvironment,
16                                                                                                                String selfMaterial,
17                                                                                                                String environmentMaterial,
18                                                                                                                int layer,
19                                                                                                                bool getMinMax,
20                                                                                                                bool attachToTexUnit,
21                                                                                                                String minVariableName,
22                                                                                                                String maxVariableName,
23                                                                                                                Pass* pass,
24                                                                                                                OgreRenderable* parentRenderable,
25                                                                                                                OgreTechniqueGroup* parentTechniqueGroup,
26                                                                                                                bool createCubeRun)
27                                                        :OgreRenderTechnique( pass, parentRenderable, parentTechniqueGroup),
28                                                        CubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, renderEnvironment, layer, parentRenderable, parentTechniqueGroup),
29                                                        RenderTechnique(parentRenderable, parentTechniqueGroup)
30{       
31        this->minVariableName = minVariableName;
32        this->maxVariableName = maxVariableName;
33        this->attachToTexUnit = attachToTexUnit;
34        this->getMinMax = getMinMax;
35
36        this->texID = texID;
37        this->selfMaterial = selfMaterial;
38        this->environmentMaterial = environmentMaterial;
39        texturePostFix = "_CUBEMAP";
40
41        if(createCubeRun)
42        {
43                if(sharedRuns->getRun(ILLUMRUN_CUBEMAP) == 0)
44                sharedRuns->addRun(ILLUMRUN_CUBEMAP, createCubeMapRun());
45
46                cubeMapRunChanged(sharedRuns->getRun(ILLUMRUN_CUBEMAP));
47        }
48}
49
50
51OgreCubeMapRenderTechnique::~OgreCubeMapRenderTechnique()
52{
53
54}
55
56void OgreCubeMapRenderTechnique::cubeMapRunChanged(RenderingRun* run)
57{
58        OgreCubeMapRenderingRun* cuberun =(OgreCubeMapRenderingRun*) (run->asOgreRenderingRun());
59        String cubemapname = cuberun->getCubeMapTextureName();
60       
61        if(attachToTexUnit)
62                pass->getTextureUnitState(texID)->setTextureName(cubemapname);
63        if(getMinMax)
64        {
65                if(minVariableName != "")
66                        pass->getFragmentProgramParameters()->setNamedConstant(minVariableName, cuberun->getMin());
67                if(maxVariableName != "")
68                        pass->getFragmentProgramParameters()->setNamedConstant(maxVariableName, cuberun->getMax());
69        }
70}
71
72RenderingRun* OgreCubeMapRenderTechnique::createCubeMapRun()
73{
74        return new OgreCubeMapRenderingRun( (OgreSharedRuns*) parentTechniqueGroup->getSharedRuns(),
75                                                                                                parentOgreRenderable->getName()  + texturePostFix,
76                                                                                                startFrame,
77                                                                                                cubeMapUpdateInterval,
78                                                                                                cubeMapResolution,
79                                                                                                useDistCalc,
80                                                                                                useFaceAngleCalc,
81                                                                                                distTolerance,
82                                                                                                angleTolerance,
83                                                                                                updateAllFace,
84                                                                                                renderSelf,
85                                                                                                renderEnvironment,
86                                                                                                selfMaterial,
87                                                                                                environmentMaterial,
88                                                                                                getMinMax,
89                                                                                                cubemapLayer);
90}
91
92///Technique Parsers
93namespace CubemapParsers
94{
95        void parseStartFrame(String& params, RenderTechniqueFactory* factory)
96        {
97                OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
98                f->startFrame =  StringConverter::parseUnsignedLong(params);
99        }
100        void parseCubeMapUpdateInterval(String& params, RenderTechniqueFactory* factory)
101        {
102                OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
103                f->cubeMapUpdateInterval =  StringConverter::parseUnsignedLong(params);
104        }
105
106        void parseCubeMapResolution(String& params, RenderTechniqueFactory* factory)
107        {
108                OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
109                f->cubeMapResolution =  StringConverter::parseUnsignedInt(params);
110        }
111
112        void parseTexID(String& params, RenderTechniqueFactory* factory)
113        {
114                OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
115                f->texID =  StringConverter::parseUnsignedInt(params);
116        }
117
118        void parseUseDistCalc(String& params, RenderTechniqueFactory* factory)
119        {
120                OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
121                // format: on/off tolerance(float)
122                StringVector vecparams = StringUtil::split(params, " \t");
123
124                if(StringConverter::parseBool(vecparams[0]))//on
125                {
126                        f->useDistCalc = true;
127
128                        if(vecparams.size()>1)
129                        {                       
130                                f->distTolerance = StringConverter::parseReal(vecparams[1]);
131                        }
132                }
133                else
134                {
135                        f->useDistCalc = false;
136                }
137        }
138
139        void parseUseFaceAngleCalc(String& params, RenderTechniqueFactory* factory)
140        {
141                OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
142                // format: on/off tolerance(float)
143                StringVector vecparams = StringUtil::split(params, " \t");
144
145                if(StringConverter::parseBool(vecparams[0]))//on
146                {
147                        f->useFaceAngleCalc = true;
148
149                        if(vecparams.size()>1)
150                        {                       
151                                f->angleTolerance = StringConverter::parseReal(vecparams[1]);
152                        }
153                }
154                else
155                {
156                        f->useFaceAngleCalc = false;
157                }
158        }
159
160        void parseUpdateAllFace(String& params, RenderTechniqueFactory* factory)
161        {
162                OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
163                f->updateAllFace =  StringConverter::parseBool(params);
164        }
165
166        void parseRenderSelf(String& params, RenderTechniqueFactory* factory)
167        {
168                OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
169                f->renderSelf =  StringConverter::parseBool(params);
170        }
171
172        void parseRenderEnv(String& params, RenderTechniqueFactory* factory)
173        {
174                OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
175                f->renderEnvironment =  StringConverter::parseBool(params);
176        }
177
178        void parseSelfMaterial(String& params, RenderTechniqueFactory* factory)
179        {
180                OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
181                f->selfMaterial =  params;
182        }
183
184        void parseEnvMaterial(String& params, RenderTechniqueFactory* factory)
185        {
186                OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
187                f->environmentMaterial =  params;
188        }
189
190        void parseMinVarName(String& params, RenderTechniqueFactory* factory)
191        {
192                OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
193                f->minVariableName =  params;
194        }
195        void parseMaxVarName(String& params, RenderTechniqueFactory* factory)
196        {
197                OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
198                f->maxVariableName =  params;
199        }
200
201        void parseLayer(String& params, RenderTechniqueFactory* factory)
202        {
203                OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
204                f->layer =  StringConverter::parseInt(params);
205        }
206
207        void parseGetMinMax(String& params, RenderTechniqueFactory* factory)
208        {
209                OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
210                f->getMinMax =  StringConverter::parseBool(params);
211        }
212
213        void parseAttachTexUnit(String& params, RenderTechniqueFactory* factory)
214        {
215                OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
216                f->attachToTexUnit =  StringConverter::parseBool(params);
217        }
218
219}
220///Technique factory
221OgreCubeMapRenderTechniqueFactory::OgreCubeMapRenderTechniqueFactory()
222{
223        typeName = "CubeMap";
224
225        using namespace CubemapParsers;
226
227        //register parsers
228        this->attributeParsers.insert(AttribParserList::value_type("start_frame", (ILLUM_ATTRIBUTE_PARSER) parseStartFrame));
229        this->attributeParsers.insert(AttribParserList::value_type("update_interval", (ILLUM_ATTRIBUTE_PARSER) parseCubeMapUpdateInterval));
230        this->attributeParsers.insert(AttribParserList::value_type("resolution", (ILLUM_ATTRIBUTE_PARSER) parseCubeMapResolution));
231        this->attributeParsers.insert(AttribParserList::value_type("texture_unit_id", (ILLUM_ATTRIBUTE_PARSER) parseTexID));
232        this->attributeParsers.insert(AttribParserList::value_type("distance_calc", (ILLUM_ATTRIBUTE_PARSER) parseUseDistCalc));
233        this->attributeParsers.insert(AttribParserList::value_type("face_angle_calc", (ILLUM_ATTRIBUTE_PARSER) parseUseFaceAngleCalc));
234        this->attributeParsers.insert(AttribParserList::value_type("update_all_face", (ILLUM_ATTRIBUTE_PARSER) parseUpdateAllFace));
235        this->attributeParsers.insert(AttribParserList::value_type("render_self", (ILLUM_ATTRIBUTE_PARSER) parseRenderSelf));
236        this->attributeParsers.insert(AttribParserList::value_type("render_env", (ILLUM_ATTRIBUTE_PARSER) parseRenderEnv));
237        this->attributeParsers.insert(AttribParserList::value_type("self_material", (ILLUM_ATTRIBUTE_PARSER) parseSelfMaterial));
238        this->attributeParsers.insert(AttribParserList::value_type("env_material", (ILLUM_ATTRIBUTE_PARSER) parseEnvMaterial));
239        this->attributeParsers.insert(AttribParserList::value_type("layer", (ILLUM_ATTRIBUTE_PARSER) parseLayer));
240        this->attributeParsers.insert(AttribParserList::value_type("get_minmax", (ILLUM_ATTRIBUTE_PARSER) parseGetMinMax));
241        this->attributeParsers.insert(AttribParserList::value_type("attach_to_texture_unit", (ILLUM_ATTRIBUTE_PARSER) parseAttachTexUnit));
242        this->attributeParsers.insert(AttribParserList::value_type("min_var_name", (ILLUM_ATTRIBUTE_PARSER) parseMinVarName));
243        this->attributeParsers.insert(AttribParserList::value_type("max_var_name", (ILLUM_ATTRIBUTE_PARSER) parseMaxVarName));
244
245}
246
247void OgreCubeMapRenderTechniqueFactory::resetParams()
248{
249        startFrame = 1;
250        cubeMapUpdateInterval = 1;
251        cubeMapResolution = 256;                                                                                               
252        texID = 0;
253        useDistCalc = 1;
254        useFaceAngleCalc = false;
255        distTolerance = 2.0;
256        angleTolerance = 2.0;
257        updateAllFace = false;
258        renderSelf = false;
259        renderEnvironment = true;
260        selfMaterial = "";
261        environmentMaterial = "";
262        layer = 0;
263        getMinMax = false;
264        attachToTexUnit = true;
265        minVariableName = "";
266        maxVariableName = "";
267
268}
269
270OgreRenderTechnique* OgreCubeMapRenderTechniqueFactory::createInstance(
271                                                                                IllumTechniqueParams* params,
272                                                                                Pass* pass,
273                                                                                OgreRenderable* parentRenderable,
274                                                                                OgreTechniqueGroup* parentTechniqueGroup)
275{       
276        resetParams();
277        parseParams(params);
278       
279        OgreCubeMapRenderTechnique* result = new OgreCubeMapRenderTechnique(
280                                                                                                startFrame,
281                                                                                                cubeMapUpdateInterval,
282                                                                                                cubeMapResolution,
283                                                                                                texID,
284                                                                                                useDistCalc,
285                                                                                                useFaceAngleCalc,
286                                                                                                distTolerance,
287                                                                                                angleTolerance,
288                                                                                                updateAllFace,
289                                                                                                renderSelf,
290                                                                                                renderEnvironment,
291                                                                                                selfMaterial,
292                                                                                                environmentMaterial,
293                                                                                                layer,
294                                                                                                getMinMax,
295                                                                                                attachToTexUnit,
296                                                                                                minVariableName,
297                                                                                                maxVariableName,
298                                                                                                pass,
299                                                                                                parentRenderable,
300                                                                                                parentTechniqueGroup,
301                                                                                                true);
302
303        return result;
304}
Note: See TracBrowser for help on using the repository browser.