[790] | 1 | #include "OgreCubeMapRenderTechnique.h"
|
---|
| 2 | #include "OgreTechniqueGroup.h"
|
---|
[1722] | 3 | #include "OgreCubeMapRenderingRun.h"
|
---|
[790] | 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,
|
---|
[1711] | 14 | bool renderSelf,
|
---|
[1722] | 15 | bool renderEnvironment,
|
---|
| 16 | String selfMaterial,
|
---|
| 17 | String environmentMaterial,
|
---|
[1725] | 18 | int layer,
|
---|
[1886] | 19 | bool getMinMax,
|
---|
| 20 | bool attachToTexUnit,
|
---|
| 21 | String minVariableName,
|
---|
| 22 | String maxVariableName,
|
---|
[790] | 23 | Pass* pass,
|
---|
| 24 | OgreRenderable* parentRenderable,
|
---|
[1722] | 25 | OgreTechniqueGroup* parentTechniqueGroup,
|
---|
| 26 | bool createCubeRun)
|
---|
[790] | 27 | :OgreRenderTechnique( pass, parentRenderable, parentTechniqueGroup),
|
---|
[1725] | 28 | CubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, renderEnvironment, layer, parentRenderable, parentTechniqueGroup),
|
---|
[790] | 29 | RenderTechnique(parentRenderable, parentTechniqueGroup)
|
---|
| 30 | {
|
---|
[1886] | 31 | this->minVariableName = minVariableName;
|
---|
| 32 | this->maxVariableName = maxVariableName;
|
---|
| 33 | this->attachToTexUnit = attachToTexUnit;
|
---|
| 34 | this->getMinMax = getMinMax;
|
---|
| 35 |
|
---|
[1722] | 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 | }
|
---|
[790] | 48 | }
|
---|
| 49 |
|
---|
| 50 |
|
---|
| 51 | OgreCubeMapRenderTechnique::~OgreCubeMapRenderTechnique()
|
---|
| 52 | {
|
---|
| 53 |
|
---|
| 54 | }
|
---|
| 55 |
|
---|
[1722] | 56 | void OgreCubeMapRenderTechnique::cubeMapRunChanged(RenderingRun* run)
|
---|
| 57 | {
|
---|
| 58 | OgreCubeMapRenderingRun* cuberun =(OgreCubeMapRenderingRun*) (run->asOgreRenderingRun());
|
---|
| 59 | String cubemapname = cuberun->getCubeMapTextureName();
|
---|
| 60 |
|
---|
[1886] | 61 | if(attachToTexUnit)
|
---|
[1930] | 62 | pass->getTextureUnitState(texID)->setTextureName(cubemapname);
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | void OgreCubeMapRenderTechnique::cubeMapRunUpdated(RenderingRun* run)
|
---|
| 66 | {
|
---|
| 67 | OgreCubeMapRenderingRun* cuberun =(OgreCubeMapRenderingRun*) (run->asOgreRenderingRun());
|
---|
| 68 |
|
---|
[1886] | 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 | }
|
---|
[1722] | 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,
|
---|
[1725] | 93 | environmentMaterial,
|
---|
[1886] | 94 | getMinMax,
|
---|
[1725] | 95 | cubemapLayer);
|
---|
[1722] | 96 | }
|
---|
| 97 |
|
---|
[836] | 98 | ///Technique Parsers
|
---|
[1711] | 99 | namespace CubemapParsers
|
---|
[836] | 100 | {
|
---|
| 101 | void parseStartFrame(String& params, RenderTechniqueFactory* factory)
|
---|
| 102 | {
|
---|
[1711] | 103 | OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
|
---|
[836] | 104 | f->startFrame = StringConverter::parseUnsignedLong(params);
|
---|
| 105 | }
|
---|
| 106 | void parseCubeMapUpdateInterval(String& params, RenderTechniqueFactory* factory)
|
---|
| 107 | {
|
---|
[1711] | 108 | OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
|
---|
[836] | 109 | f->cubeMapUpdateInterval = StringConverter::parseUnsignedLong(params);
|
---|
| 110 | }
|
---|
[790] | 111 |
|
---|
[836] | 112 | void parseCubeMapResolution(String& params, RenderTechniqueFactory* factory)
|
---|
| 113 | {
|
---|
[1711] | 114 | OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
|
---|
[836] | 115 | f->cubeMapResolution = StringConverter::parseUnsignedInt(params);
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | void parseTexID(String& params, RenderTechniqueFactory* factory)
|
---|
| 119 | {
|
---|
[1711] | 120 | OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
|
---|
[836] | 121 | f->texID = StringConverter::parseUnsignedInt(params);
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | void parseUseDistCalc(String& params, RenderTechniqueFactory* factory)
|
---|
| 125 | {
|
---|
[1711] | 126 | OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
|
---|
[836] | 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 | {
|
---|
[1711] | 147 | OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
|
---|
[836] | 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 | {
|
---|
[1711] | 168 | OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
|
---|
[836] | 169 | f->updateAllFace = StringConverter::parseBool(params);
|
---|
| 170 | }
|
---|
[1711] | 171 |
|
---|
| 172 | void parseRenderSelf(String& params, RenderTechniqueFactory* factory)
|
---|
| 173 | {
|
---|
| 174 | OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
|
---|
| 175 | f->renderSelf = StringConverter::parseBool(params);
|
---|
| 176 | }
|
---|
[1722] | 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 | }
|
---|
[1886] | 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 |
|
---|
[1725] | 207 | void parseLayer(String& params, RenderTechniqueFactory* factory)
|
---|
| 208 | {
|
---|
| 209 | OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
|
---|
| 210 | f->layer = StringConverter::parseInt(params);
|
---|
| 211 | }
|
---|
| 212 |
|
---|
[1886] | 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 |
|
---|
[836] | 225 | }
|
---|
| 226 | ///Technique factory
|
---|
[1711] | 227 | OgreCubeMapRenderTechniqueFactory::OgreCubeMapRenderTechniqueFactory()
|
---|
[836] | 228 | {
|
---|
[1725] | 229 | typeName = "CubeMap";
|
---|
| 230 |
|
---|
[1711] | 231 | using namespace CubemapParsers;
|
---|
[836] | 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));
|
---|
[1722] | 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));
|
---|
[1725] | 245 | this->attributeParsers.insert(AttribParserList::value_type("layer", (ILLUM_ATTRIBUTE_PARSER) parseLayer));
|
---|
[1886] | 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));
|
---|
[836] | 250 |
|
---|
| 251 | }
|
---|
| 252 |
|
---|
[1711] | 253 | void OgreCubeMapRenderTechniqueFactory::resetParams()
|
---|
| 254 | {
|
---|
[874] | 255 | startFrame = 1;
|
---|
[836] | 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;
|
---|
[1711] | 264 | renderSelf = false;
|
---|
[1722] | 265 | renderEnvironment = true;
|
---|
| 266 | selfMaterial = "";
|
---|
| 267 | environmentMaterial = "";
|
---|
[1725] | 268 | layer = 0;
|
---|
[1886] | 269 | getMinMax = false;
|
---|
| 270 | attachToTexUnit = true;
|
---|
| 271 | minVariableName = "";
|
---|
| 272 | maxVariableName = "";
|
---|
| 273 |
|
---|
[1722] | 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,
|
---|
[1725] | 299 | layer,
|
---|
[1886] | 300 | getMinMax,
|
---|
| 301 | attachToTexUnit,
|
---|
| 302 | minVariableName,
|
---|
| 303 | maxVariableName,
|
---|
[1722] | 304 | pass,
|
---|
| 305 | parentRenderable,
|
---|
| 306 | parentTechniqueGroup,
|
---|
| 307 | true);
|
---|
| 308 |
|
---|
| 309 | return result;
|
---|
[1711] | 310 | } |
---|