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