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 | Pass* pass,
|
---|
20 | OgreRenderable* parentRenderable,
|
---|
21 | OgreTechniqueGroup* parentTechniqueGroup,
|
---|
22 | bool createCubeRun)
|
---|
23 | :OgreRenderTechnique( pass, parentRenderable, parentTechniqueGroup),
|
---|
24 | CubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, renderEnvironment, layer, parentRenderable, parentTechniqueGroup),
|
---|
25 | RenderTechnique(parentRenderable, parentTechniqueGroup)
|
---|
26 | {
|
---|
27 | this->texID = texID;
|
---|
28 | this->selfMaterial = selfMaterial;
|
---|
29 | this->environmentMaterial = environmentMaterial;
|
---|
30 | texturePostFix = "_CUBEMAP";
|
---|
31 |
|
---|
32 | if(createCubeRun)
|
---|
33 | {
|
---|
34 | if(sharedRuns->getRun(ILLUMRUN_CUBEMAP) == 0)
|
---|
35 | sharedRuns->addRun(ILLUMRUN_CUBEMAP, createCubeMapRun());
|
---|
36 |
|
---|
37 | cubeMapRunChanged(sharedRuns->getRun(ILLUMRUN_CUBEMAP));
|
---|
38 | }
|
---|
39 | }
|
---|
40 |
|
---|
41 |
|
---|
42 | OgreCubeMapRenderTechnique::~OgreCubeMapRenderTechnique()
|
---|
43 | {
|
---|
44 |
|
---|
45 | }
|
---|
46 |
|
---|
47 | void OgreCubeMapRenderTechnique::cubeMapRunChanged(RenderingRun* run)
|
---|
48 | {
|
---|
49 | OgreCubeMapRenderingRun* cuberun =(OgreCubeMapRenderingRun*) (run->asOgreRenderingRun());
|
---|
50 | String cubemapname = cuberun->getCubeMapTextureName();
|
---|
51 |
|
---|
52 | pass->getTextureUnitState(texID)->setTextureName(cubemapname);
|
---|
53 | }
|
---|
54 |
|
---|
55 | RenderingRun* OgreCubeMapRenderTechnique::createCubeMapRun()
|
---|
56 | {
|
---|
57 | return new OgreCubeMapRenderingRun( (OgreSharedRuns*) parentTechniqueGroup->getSharedRuns(),
|
---|
58 | parentOgreRenderable->getName() + texturePostFix,
|
---|
59 | startFrame,
|
---|
60 | cubeMapUpdateInterval,
|
---|
61 | cubeMapResolution,
|
---|
62 | useDistCalc,
|
---|
63 | useFaceAngleCalc,
|
---|
64 | distTolerance,
|
---|
65 | angleTolerance,
|
---|
66 | updateAllFace,
|
---|
67 | renderSelf,
|
---|
68 | renderEnvironment,
|
---|
69 | selfMaterial,
|
---|
70 | environmentMaterial,
|
---|
71 | cubemapLayer);
|
---|
72 | }
|
---|
73 |
|
---|
74 | ///Technique Parsers
|
---|
75 | namespace CubemapParsers
|
---|
76 | {
|
---|
77 | void parseStartFrame(String& params, RenderTechniqueFactory* factory)
|
---|
78 | {
|
---|
79 | OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
|
---|
80 | f->startFrame = StringConverter::parseUnsignedLong(params);
|
---|
81 | }
|
---|
82 | void parseCubeMapUpdateInterval(String& params, RenderTechniqueFactory* factory)
|
---|
83 | {
|
---|
84 | OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
|
---|
85 | f->cubeMapUpdateInterval = StringConverter::parseUnsignedLong(params);
|
---|
86 | }
|
---|
87 |
|
---|
88 | void parseCubeMapResolution(String& params, RenderTechniqueFactory* factory)
|
---|
89 | {
|
---|
90 | OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
|
---|
91 | f->cubeMapResolution = StringConverter::parseUnsignedInt(params);
|
---|
92 | }
|
---|
93 |
|
---|
94 | void parseTexID(String& params, RenderTechniqueFactory* factory)
|
---|
95 | {
|
---|
96 | OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
|
---|
97 | f->texID = StringConverter::parseUnsignedInt(params);
|
---|
98 | }
|
---|
99 |
|
---|
100 | void parseUseDistCalc(String& params, RenderTechniqueFactory* factory)
|
---|
101 | {
|
---|
102 | OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
|
---|
103 | // format: on/off tolerance(float)
|
---|
104 | StringVector vecparams = StringUtil::split(params, " \t");
|
---|
105 |
|
---|
106 | if(StringConverter::parseBool(vecparams[0]))//on
|
---|
107 | {
|
---|
108 | f->useDistCalc = true;
|
---|
109 |
|
---|
110 | if(vecparams.size()>1)
|
---|
111 | {
|
---|
112 | f->distTolerance = StringConverter::parseReal(vecparams[1]);
|
---|
113 | }
|
---|
114 | }
|
---|
115 | else
|
---|
116 | {
|
---|
117 | f->useDistCalc = false;
|
---|
118 | }
|
---|
119 | }
|
---|
120 |
|
---|
121 | void parseUseFaceAngleCalc(String& params, RenderTechniqueFactory* factory)
|
---|
122 | {
|
---|
123 | OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
|
---|
124 | // format: on/off tolerance(float)
|
---|
125 | StringVector vecparams = StringUtil::split(params, " \t");
|
---|
126 |
|
---|
127 | if(StringConverter::parseBool(vecparams[0]))//on
|
---|
128 | {
|
---|
129 | f->useFaceAngleCalc = true;
|
---|
130 |
|
---|
131 | if(vecparams.size()>1)
|
---|
132 | {
|
---|
133 | f->angleTolerance = StringConverter::parseReal(vecparams[1]);
|
---|
134 | }
|
---|
135 | }
|
---|
136 | else
|
---|
137 | {
|
---|
138 | f->useFaceAngleCalc = false;
|
---|
139 | }
|
---|
140 | }
|
---|
141 |
|
---|
142 | void parseUpdateAllFace(String& params, RenderTechniqueFactory* factory)
|
---|
143 | {
|
---|
144 | OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
|
---|
145 | f->updateAllFace = StringConverter::parseBool(params);
|
---|
146 | }
|
---|
147 |
|
---|
148 | void parseRenderSelf(String& params, RenderTechniqueFactory* factory)
|
---|
149 | {
|
---|
150 | OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
|
---|
151 | f->renderSelf = StringConverter::parseBool(params);
|
---|
152 | }
|
---|
153 |
|
---|
154 | void parseRenderEnv(String& params, RenderTechniqueFactory* factory)
|
---|
155 | {
|
---|
156 | OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
|
---|
157 | f->renderEnvironment = StringConverter::parseBool(params);
|
---|
158 | }
|
---|
159 |
|
---|
160 | void parseSelfMaterial(String& params, RenderTechniqueFactory* factory)
|
---|
161 | {
|
---|
162 | OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
|
---|
163 | f->selfMaterial = params;
|
---|
164 | }
|
---|
165 |
|
---|
166 | void parseEnvMaterial(String& params, RenderTechniqueFactory* factory)
|
---|
167 | {
|
---|
168 | OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
|
---|
169 | f->environmentMaterial = params;
|
---|
170 | }
|
---|
171 | void parseLayer(String& params, RenderTechniqueFactory* factory)
|
---|
172 | {
|
---|
173 | OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
|
---|
174 | f->layer = StringConverter::parseInt(params);
|
---|
175 | }
|
---|
176 |
|
---|
177 | }
|
---|
178 | ///Technique factory
|
---|
179 | OgreCubeMapRenderTechniqueFactory::OgreCubeMapRenderTechniqueFactory()
|
---|
180 | {
|
---|
181 | typeName = "CubeMap";
|
---|
182 |
|
---|
183 | using namespace CubemapParsers;
|
---|
184 |
|
---|
185 | //register parsers
|
---|
186 | this->attributeParsers.insert(AttribParserList::value_type("start_frame", (ILLUM_ATTRIBUTE_PARSER) parseStartFrame));
|
---|
187 | this->attributeParsers.insert(AttribParserList::value_type("update_interval", (ILLUM_ATTRIBUTE_PARSER) parseCubeMapUpdateInterval));
|
---|
188 | this->attributeParsers.insert(AttribParserList::value_type("resolution", (ILLUM_ATTRIBUTE_PARSER) parseCubeMapResolution));
|
---|
189 | this->attributeParsers.insert(AttribParserList::value_type("texture_unit_id", (ILLUM_ATTRIBUTE_PARSER) parseTexID));
|
---|
190 | this->attributeParsers.insert(AttribParserList::value_type("distance_calc", (ILLUM_ATTRIBUTE_PARSER) parseUseDistCalc));
|
---|
191 | this->attributeParsers.insert(AttribParserList::value_type("face_angle_calc", (ILLUM_ATTRIBUTE_PARSER) parseUseFaceAngleCalc));
|
---|
192 | this->attributeParsers.insert(AttribParserList::value_type("update_all_face", (ILLUM_ATTRIBUTE_PARSER) parseUpdateAllFace));
|
---|
193 | this->attributeParsers.insert(AttribParserList::value_type("render_self", (ILLUM_ATTRIBUTE_PARSER) parseRenderSelf));
|
---|
194 | this->attributeParsers.insert(AttribParserList::value_type("render_env", (ILLUM_ATTRIBUTE_PARSER) parseRenderEnv));
|
---|
195 | this->attributeParsers.insert(AttribParserList::value_type("self_material", (ILLUM_ATTRIBUTE_PARSER) parseSelfMaterial));
|
---|
196 | this->attributeParsers.insert(AttribParserList::value_type("env_material", (ILLUM_ATTRIBUTE_PARSER) parseEnvMaterial));
|
---|
197 | this->attributeParsers.insert(AttribParserList::value_type("layer", (ILLUM_ATTRIBUTE_PARSER) parseLayer));
|
---|
198 |
|
---|
199 | }
|
---|
200 |
|
---|
201 | void OgreCubeMapRenderTechniqueFactory::resetParams()
|
---|
202 | {
|
---|
203 | startFrame = 1;
|
---|
204 | cubeMapUpdateInterval = 1;
|
---|
205 | cubeMapResolution = 256;
|
---|
206 | texID = 0;
|
---|
207 | useDistCalc = 1;
|
---|
208 | useFaceAngleCalc = false;
|
---|
209 | distTolerance = 2.0;
|
---|
210 | angleTolerance = 2.0;
|
---|
211 | updateAllFace = false;
|
---|
212 | renderSelf = false;
|
---|
213 | renderEnvironment = true;
|
---|
214 | selfMaterial = "";
|
---|
215 | environmentMaterial = "";
|
---|
216 | layer = 0;
|
---|
217 | }
|
---|
218 |
|
---|
219 | OgreRenderTechnique* OgreCubeMapRenderTechniqueFactory::createInstance(
|
---|
220 | IllumTechniqueParams* params,
|
---|
221 | Pass* pass,
|
---|
222 | OgreRenderable* parentRenderable,
|
---|
223 | OgreTechniqueGroup* parentTechniqueGroup)
|
---|
224 | {
|
---|
225 | resetParams();
|
---|
226 | parseParams(params);
|
---|
227 |
|
---|
228 | OgreCubeMapRenderTechnique* result = new OgreCubeMapRenderTechnique(
|
---|
229 | startFrame,
|
---|
230 | cubeMapUpdateInterval,
|
---|
231 | cubeMapResolution,
|
---|
232 | texID,
|
---|
233 | useDistCalc,
|
---|
234 | useFaceAngleCalc,
|
---|
235 | distTolerance,
|
---|
236 | angleTolerance,
|
---|
237 | updateAllFace,
|
---|
238 | renderSelf,
|
---|
239 | renderEnvironment,
|
---|
240 | selfMaterial,
|
---|
241 | environmentMaterial,
|
---|
242 | layer,
|
---|
243 | pass,
|
---|
244 | parentRenderable,
|
---|
245 | parentTechniqueGroup,
|
---|
246 | true);
|
---|
247 |
|
---|
248 | return result;
|
---|
249 | } |
---|