1 | #include "OgreCubeMapRenderTechnique.h"
|
---|
2 | #include "OgreTechniqueGroup.h"
|
---|
3 | #include "OgreColorCubeMapRenderingRun.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 | Pass* pass,
|
---|
15 | OgreRenderable* parentRenderable,
|
---|
16 | OgreTechniqueGroup* parentTechniqueGroup)
|
---|
17 | :OgreRenderTechnique( pass, parentRenderable, parentTechniqueGroup),
|
---|
18 | CubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, parentRenderable, parentTechniqueGroup),
|
---|
19 | RenderTechnique(parentRenderable, parentTechniqueGroup)
|
---|
20 | {
|
---|
21 | this->texID = texID;
|
---|
22 |
|
---|
23 | if(sharedRuns->getRun(ILLUMRUN_COLOR_CUBEMAP) == 0)
|
---|
24 | sharedRuns->addRun(ILLUMRUN_COLOR_CUBEMAP, createColorCubeMapRun());
|
---|
25 |
|
---|
26 | colorCubeMapRunChanged(sharedRuns->getRun(ILLUMRUN_COLOR_CUBEMAP));
|
---|
27 | }
|
---|
28 |
|
---|
29 |
|
---|
30 | OgreCubeMapRenderTechnique::~OgreCubeMapRenderTechnique()
|
---|
31 | {
|
---|
32 |
|
---|
33 | }
|
---|
34 |
|
---|
35 | void OgreCubeMapRenderTechnique::update(unsigned long frameNum)
|
---|
36 | {
|
---|
37 | CubeMapRenderTechnique::update(frameNum);
|
---|
38 | /*
|
---|
39 | GpuProgramParametersSharedPtr fpParams = pass->getFragmentProgramParameters();
|
---|
40 | Vector3 center = ((OgreSharedRuns*) sharedRuns)->getRootPosition();
|
---|
41 | fpParams->setNamedConstant("lastCenter",center);
|
---|
42 | pass->setFragmentProgramParameters(fpParams); */
|
---|
43 |
|
---|
44 | }
|
---|
45 |
|
---|
46 | void OgreCubeMapRenderTechnique::colorCubeMapRunChanged(RenderingRun* run)
|
---|
47 | {
|
---|
48 | OgreColorCubeMapRenderingRun* cuberun =(OgreColorCubeMapRenderingRun*) (run->asOgreRenderingRun());
|
---|
49 | String cubemapname = cuberun->getColorCubeMapTextureName();
|
---|
50 |
|
---|
51 | pass->getTextureUnitState(texID)->setTextureName(cubemapname);
|
---|
52 | }
|
---|
53 |
|
---|
54 | RenderingRun* OgreCubeMapRenderTechnique::createColorCubeMapRun()
|
---|
55 | {
|
---|
56 | return new OgreColorCubeMapRenderingRun( (OgreSharedRuns*) parentTechniqueGroup->getSharedRuns(),
|
---|
57 | parentOgreRenderable->getName() + "_COLORCUBEMAP",
|
---|
58 | startFrame,
|
---|
59 | cubeMapUpdateInterval,
|
---|
60 | cubeMapResolution,
|
---|
61 | useDistCalc,
|
---|
62 | useFaceAngleCalc,
|
---|
63 | distTolerance,
|
---|
64 | angleTolerance,
|
---|
65 | updateAllFace);
|
---|
66 | }
|
---|
67 |
|
---|
68 | ///Technique Parsers
|
---|
69 | namespace ColorCubemapParsers
|
---|
70 | {
|
---|
71 | void parseStartFrame(String& params, RenderTechniqueFactory* factory)
|
---|
72 | {
|
---|
73 | OgreColorCubeMapRenderTechniqueFactory* f = (OgreColorCubeMapRenderTechniqueFactory*) factory;
|
---|
74 | f->startFrame = StringConverter::parseUnsignedLong(params);
|
---|
75 | }
|
---|
76 | void parseCubeMapUpdateInterval(String& params, RenderTechniqueFactory* factory)
|
---|
77 | {
|
---|
78 | OgreColorCubeMapRenderTechniqueFactory* f = (OgreColorCubeMapRenderTechniqueFactory*) factory;
|
---|
79 | f->cubeMapUpdateInterval = StringConverter::parseUnsignedLong(params);
|
---|
80 | }
|
---|
81 |
|
---|
82 | void parseCubeMapResolution(String& params, RenderTechniqueFactory* factory)
|
---|
83 | {
|
---|
84 | OgreColorCubeMapRenderTechniqueFactory* f = (OgreColorCubeMapRenderTechniqueFactory*) factory;
|
---|
85 | f->cubeMapResolution = StringConverter::parseUnsignedInt(params);
|
---|
86 | }
|
---|
87 |
|
---|
88 | void parseTexID(String& params, RenderTechniqueFactory* factory)
|
---|
89 | {
|
---|
90 | OgreColorCubeMapRenderTechniqueFactory* f = (OgreColorCubeMapRenderTechniqueFactory*) factory;
|
---|
91 | f->texID = StringConverter::parseUnsignedInt(params);
|
---|
92 | }
|
---|
93 |
|
---|
94 | void parseUseDistCalc(String& params, RenderTechniqueFactory* factory)
|
---|
95 | {
|
---|
96 | OgreColorCubeMapRenderTechniqueFactory* f = (OgreColorCubeMapRenderTechniqueFactory*) factory;
|
---|
97 | // format: on/off tolerance(float)
|
---|
98 | StringVector vecparams = StringUtil::split(params, " \t");
|
---|
99 |
|
---|
100 | if(StringConverter::parseBool(vecparams[0]))//on
|
---|
101 | {
|
---|
102 | f->useDistCalc = true;
|
---|
103 |
|
---|
104 | if(vecparams.size()>1)
|
---|
105 | {
|
---|
106 | f->distTolerance = StringConverter::parseReal(vecparams[1]);
|
---|
107 | }
|
---|
108 | }
|
---|
109 | else
|
---|
110 | {
|
---|
111 | f->useDistCalc = false;
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | void parseUseFaceAngleCalc(String& params, RenderTechniqueFactory* factory)
|
---|
116 | {
|
---|
117 | OgreColorCubeMapRenderTechniqueFactory* f = (OgreColorCubeMapRenderTechniqueFactory*) factory;
|
---|
118 | // format: on/off tolerance(float)
|
---|
119 | StringVector vecparams = StringUtil::split(params, " \t");
|
---|
120 |
|
---|
121 | if(StringConverter::parseBool(vecparams[0]))//on
|
---|
122 | {
|
---|
123 | f->useFaceAngleCalc = true;
|
---|
124 |
|
---|
125 | if(vecparams.size()>1)
|
---|
126 | {
|
---|
127 | f->angleTolerance = StringConverter::parseReal(vecparams[1]);
|
---|
128 | }
|
---|
129 | }
|
---|
130 | else
|
---|
131 | {
|
---|
132 | f->useFaceAngleCalc = false;
|
---|
133 | }
|
---|
134 | }
|
---|
135 |
|
---|
136 | void parseUpdateAllFace(String& params, RenderTechniqueFactory* factory)
|
---|
137 | {
|
---|
138 | OgreColorCubeMapRenderTechniqueFactory* f = (OgreColorCubeMapRenderTechniqueFactory*) factory;
|
---|
139 | f->updateAllFace = StringConverter::parseBool(params);
|
---|
140 | }
|
---|
141 | }
|
---|
142 | ///Technique factory
|
---|
143 | OgreColorCubeMapRenderTechniqueFactory::OgreColorCubeMapRenderTechniqueFactory()
|
---|
144 | {
|
---|
145 | typeName = "ColorCubeMap";
|
---|
146 |
|
---|
147 | using namespace ColorCubemapParsers;
|
---|
148 |
|
---|
149 | //register parsers
|
---|
150 | this->attributeParsers.insert(AttribParserList::value_type("start_frame", (ILLUM_ATTRIBUTE_PARSER) parseStartFrame));
|
---|
151 | this->attributeParsers.insert(AttribParserList::value_type("update_interval", (ILLUM_ATTRIBUTE_PARSER) parseCubeMapUpdateInterval));
|
---|
152 | this->attributeParsers.insert(AttribParserList::value_type("resolution", (ILLUM_ATTRIBUTE_PARSER) parseCubeMapResolution));
|
---|
153 | this->attributeParsers.insert(AttribParserList::value_type("texture_unit_id", (ILLUM_ATTRIBUTE_PARSER) parseTexID));
|
---|
154 | this->attributeParsers.insert(AttribParserList::value_type("distance_calc", (ILLUM_ATTRIBUTE_PARSER) parseUseDistCalc));
|
---|
155 | this->attributeParsers.insert(AttribParserList::value_type("face_angle_calc", (ILLUM_ATTRIBUTE_PARSER) parseUseFaceAngleCalc));
|
---|
156 | this->attributeParsers.insert(AttribParserList::value_type("update_all_face", (ILLUM_ATTRIBUTE_PARSER) parseUpdateAllFace));
|
---|
157 |
|
---|
158 | }
|
---|
159 |
|
---|
160 | OgreRenderTechnique* OgreColorCubeMapRenderTechniqueFactory::createInstance(
|
---|
161 | IllumTechniqueParams* params,
|
---|
162 | Pass* pass,
|
---|
163 | OgreRenderable* parentRenderable,
|
---|
164 | OgreTechniqueGroup* parentTechniqueGroup)
|
---|
165 | {
|
---|
166 | //reset parameters
|
---|
167 | startFrame = 1;
|
---|
168 | cubeMapUpdateInterval = 1;
|
---|
169 | cubeMapResolution = 256;
|
---|
170 | texID = 0;
|
---|
171 | useDistCalc = 1;
|
---|
172 | useFaceAngleCalc = false;
|
---|
173 | distTolerance = 2.0;
|
---|
174 | angleTolerance = 2.0;
|
---|
175 | updateAllFace = false;
|
---|
176 |
|
---|
177 | parseParams(params);
|
---|
178 |
|
---|
179 | OgreCubeMapRenderTechnique* result = new OgreCubeMapRenderTechnique(
|
---|
180 | startFrame,
|
---|
181 | cubeMapUpdateInterval,
|
---|
182 | cubeMapResolution,
|
---|
183 | texID,
|
---|
184 | useDistCalc,
|
---|
185 | useFaceAngleCalc,
|
---|
186 | distTolerance,
|
---|
187 | angleTolerance,
|
---|
188 | updateAllFace,
|
---|
189 | pass,
|
---|
190 | parentRenderable,
|
---|
191 | parentTechniqueGroup);
|
---|
192 |
|
---|
193 | return result;
|
---|
194 | }
|
---|
195 |
|
---|