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