[1092] | 1 | /*
|
---|
| 2 | -----------------------------------------------------------------------------
|
---|
| 3 | This source file is part of OGRE
|
---|
| 4 | (Object-oriented Graphics Rendering Engine)
|
---|
| 5 | For the latest info, see http://www.ogre3d.org/
|
---|
| 6 |
|
---|
| 7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
| 8 | Also see acknowledgements in Readme.html
|
---|
| 9 |
|
---|
| 10 | This program is free software; you can redistribute it and/or modify it under
|
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
| 13 | version.
|
---|
| 14 |
|
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
| 18 |
|
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
| 22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
| 23 | -----------------------------------------------------------------------------
|
---|
| 24 | */
|
---|
| 25 | #ifndef __Technique_H__
|
---|
| 26 | #define __Technique_H__
|
---|
| 27 |
|
---|
| 28 | #include "OgrePrerequisites.h"
|
---|
| 29 | #include "OgreIteratorWrappers.h"
|
---|
| 30 | #include "OgreBlendMode.h"
|
---|
| 31 | #include "OgreCommon.h"
|
---|
| 32 | #include "OgrePass.h"
|
---|
| 33 |
|
---|
| 34 | namespace Ogre {
|
---|
| 35 | /** Class representing an approach to rendering this particular Material.
|
---|
| 36 | @remarks
|
---|
| 37 | Ogre will attempt to use the best technique supported by the active hardware,
|
---|
| 38 | unless you specifically request a lower detail technique (say for distant
|
---|
| 39 | rendering).
|
---|
| 40 | */
|
---|
| 41 | class _OgreExport Technique
|
---|
| 42 | {
|
---|
| 43 | protected:
|
---|
| 44 | // illumination pass state type
|
---|
| 45 | enum IlluminationPassesState
|
---|
| 46 | {
|
---|
| 47 | IPS_COMPILE_DISABLED = -1,
|
---|
| 48 | IPS_NOT_COMPILED = 0,
|
---|
| 49 | IPS_COMPILED = 1
|
---|
| 50 | };
|
---|
| 51 |
|
---|
| 52 | typedef std::vector<Pass*> Passes;
|
---|
| 53 | /// List of primary passes
|
---|
| 54 | Passes mPasses;
|
---|
| 55 | /// List of derived passes, categorised into IlluminationStage (ordered)
|
---|
| 56 | IlluminationPassList mIlluminationPasses;
|
---|
| 57 | Material* mParent; // raw pointer since we don't want child to stop parent's destruction
|
---|
| 58 | bool mIsSupported;
|
---|
| 59 | IlluminationPassesState mIlluminationPassesCompilationPhase;
|
---|
| 60 | unsigned short mLodIndex;
|
---|
| 61 |
|
---|
| 62 | /// Internal method for clearing illumination pass list
|
---|
| 63 | void clearIlluminationPasses(void);
|
---|
| 64 | public:
|
---|
| 65 | /// Constructor
|
---|
| 66 | Technique(Material* parent);
|
---|
| 67 | /// Copy constructor
|
---|
| 68 | Technique(Material* parent, const Technique& oth);
|
---|
| 69 | ~Technique();
|
---|
| 70 | /** Indicates if this technique is supported by the current graphics card.
|
---|
| 71 | @remarks
|
---|
| 72 | This will only be correct after the Technique has been compiled, which is
|
---|
| 73 | usually done from Material::compile.
|
---|
| 74 | */
|
---|
| 75 | bool isSupported(void) const;
|
---|
| 76 | /** Internal compilation method; see Material::compile. */
|
---|
| 77 | void _compile(bool autoManageTextureUnits);
|
---|
| 78 | /** Internal method for splitting the passes into illumination passes. */
|
---|
| 79 | void _compileIlluminationPasses(void);
|
---|
| 80 |
|
---|
| 81 |
|
---|
| 82 | /** Creates a new Pass for this Technique.
|
---|
| 83 | @remarks
|
---|
| 84 | A Pass is a single rendering pass, ie a single draw of the given material.
|
---|
| 85 | Note that if you create a pass without a fragment program, during compilation of the
|
---|
| 86 | material the pass may be split into multiple passes if the graphics card cannot
|
---|
| 87 | handle the number of texture units requested. For passes with fragment programs, however,
|
---|
| 88 | the number of passes you create will never be altered, so you have to make sure
|
---|
| 89 | that you create an alternative fallback Technique for if a card does not have
|
---|
| 90 | enough facilities for what you're asking for.
|
---|
| 91 | */
|
---|
| 92 | Pass* createPass(void);
|
---|
| 93 | /** Retrieves the Pass with the given index. */
|
---|
| 94 | Pass* getPass(unsigned short index);
|
---|
| 95 | /** Retrieves the number of passes. */
|
---|
| 96 | unsigned short getNumPasses(void) const;
|
---|
| 97 | /** Removes the Pass with the given index. */
|
---|
| 98 | void removePass(unsigned short index);
|
---|
| 99 | /** Removes all Passes from this Technique. */
|
---|
| 100 | void removeAllPasses(void);
|
---|
| 101 | typedef VectorIterator<Passes> PassIterator;
|
---|
| 102 | /** Gets an iterator over the passes in this Technique. */
|
---|
| 103 | const PassIterator getPassIterator(void);
|
---|
| 104 | typedef VectorIterator<IlluminationPassList> IlluminationPassIterator;
|
---|
| 105 | /** Gets an iterator over the illumination-stage categorised passes. */
|
---|
| 106 | const IlluminationPassIterator getIlluminationPassIterator(void);
|
---|
| 107 | /// Gets the parent Material
|
---|
| 108 | Material* getParent(void) const { return mParent; }
|
---|
| 109 |
|
---|
| 110 | /** Overloaded operator to copy on Technique to another. */
|
---|
| 111 | Technique& operator=(const Technique& rhs);
|
---|
| 112 |
|
---|
| 113 | /// Gets the resource group of the ultimate parent Material
|
---|
| 114 | const String& getResourceGroup(void) const;
|
---|
| 115 |
|
---|
| 116 | /** Returns true if this Technique involves transparency.
|
---|
| 117 | @remarks
|
---|
| 118 | This basically boils down to whether the first pass
|
---|
| 119 | has a scene blending factor. Even if the other passes
|
---|
| 120 | do not, the base colour, including parts of the original
|
---|
| 121 | scene, may be used for blending, therefore we have to treat
|
---|
| 122 | the whole Technique as transparent.
|
---|
| 123 | */
|
---|
| 124 | bool isTransparent(void) const;
|
---|
| 125 |
|
---|
| 126 | /** Internal load method, derived from call to Material::load. */
|
---|
| 127 | void _load(void);
|
---|
| 128 | /** Internal unload method, derived from call to Material::unload. */
|
---|
| 129 | void _unload(void);
|
---|
| 130 |
|
---|
| 131 | // Is this loaded?
|
---|
| 132 | bool isLoaded(void) const;
|
---|
| 133 |
|
---|
| 134 | /** Tells the technique that it needs recompilation. */
|
---|
| 135 | void _notifyNeedsRecompile(void);
|
---|
| 136 |
|
---|
| 137 |
|
---|
| 138 | // -------------------------------------------------------------------------------
|
---|
| 139 | // The following methods are to make migration from previous versions simpler
|
---|
| 140 | // and to make code easier to write when dealing with simple materials
|
---|
| 141 | // They set the properties which have been moved to Pass for all Techniques and all Passes
|
---|
| 142 |
|
---|
| 143 | /** Sets the ambient colour reflectance properties for every Pass in every Technique.
|
---|
| 144 | @note
|
---|
| 145 | This property actually exists on the Pass class. For simplicity, this method allows
|
---|
| 146 | you to set these properties for every current Pass within this Technique. If
|
---|
| 147 | you need more precision, retrieve the Pass instance and set the
|
---|
| 148 | property there.
|
---|
| 149 | @see Pass::setAmbient
|
---|
| 150 | */
|
---|
| 151 | void setAmbient(Real red, Real green, Real blue);
|
---|
| 152 |
|
---|
| 153 | /** Sets the ambient colour reflectance properties for every Pass in every Technique.
|
---|
| 154 | @note
|
---|
| 155 | This property actually exists on the Pass class. For simplicity, this method allows
|
---|
| 156 | you to set these properties for every current Pass within this Technique. If
|
---|
| 157 | you need more precision, retrieve the Pass instance and set the
|
---|
| 158 | property there.
|
---|
| 159 | @see Pass::setAmbient
|
---|
| 160 | */
|
---|
| 161 | void setAmbient(const ColourValue& ambient);
|
---|
| 162 |
|
---|
| 163 | /** Sets the diffuse colour reflectance properties of every Pass in every Technique.
|
---|
| 164 | @note
|
---|
| 165 | This property actually exists on the Pass class. For simplicity, this method allows
|
---|
| 166 | you to set these properties for every current Pass within this Technique. If
|
---|
| 167 | you need more precision, retrieve the Pass instance and set the
|
---|
| 168 | property there.
|
---|
| 169 | @see Pass::setDiffuse
|
---|
| 170 | */
|
---|
| 171 | void setDiffuse(Real red, Real green, Real blue, Real alpha);
|
---|
| 172 |
|
---|
| 173 | /** Sets the diffuse colour reflectance properties of every Pass in every Technique.
|
---|
| 174 | @note
|
---|
| 175 | This property actually exists on the Pass class. For simplicity, this method allows
|
---|
| 176 | you to set these properties for every current Pass within this Technique. If
|
---|
| 177 | you need more precision, retrieve the Pass instance and set the
|
---|
| 178 | property there.
|
---|
| 179 | @see Pass::setDiffuse
|
---|
| 180 | */
|
---|
| 181 | void setDiffuse(const ColourValue& diffuse);
|
---|
| 182 |
|
---|
| 183 | /** Sets the specular colour reflectance properties of every Pass in every Technique.
|
---|
| 184 | @note
|
---|
| 185 | This property actually exists on the Pass class. For simplicity, this method allows
|
---|
| 186 | you to set these properties for every current Pass within this Technique. If
|
---|
| 187 | you need more precision, retrieve the Pass instance and set the
|
---|
| 188 | property there.
|
---|
| 189 | @see Pass::setSpecular
|
---|
| 190 | */
|
---|
| 191 | void setSpecular(Real red, Real green, Real blue, Real alpha);
|
---|
| 192 |
|
---|
| 193 | /** Sets the specular colour reflectance properties of every Pass in every Technique.
|
---|
| 194 | @note
|
---|
| 195 | This property actually exists on the Pass class. For simplicity, this method allows
|
---|
| 196 | you to set these properties for every current Pass within this Technique. If
|
---|
| 197 | you need more precision, retrieve the Pass instance and set the
|
---|
| 198 | property there.
|
---|
| 199 | @see Pass::setSpecular
|
---|
| 200 | */
|
---|
| 201 | void setSpecular(const ColourValue& specular);
|
---|
| 202 |
|
---|
| 203 | /** Sets the shininess properties of every Pass in every Technique.
|
---|
| 204 | @note
|
---|
| 205 | This property actually exists on the Pass class. For simplicity, this method allows
|
---|
| 206 | you to set these properties for every current Pass within this Technique. If
|
---|
| 207 | you need more precision, retrieve the Pass instance and set the
|
---|
| 208 | property there.
|
---|
| 209 | @see Pass::setShininess
|
---|
| 210 | */
|
---|
| 211 | void setShininess(Real val);
|
---|
| 212 |
|
---|
| 213 | /** Sets the amount of self-illumination of every Pass in every Technique.
|
---|
| 214 | @note
|
---|
| 215 | This property actually exists on the Pass class. For simplicity, this method allows
|
---|
| 216 | you to set these properties for every current Pass within this Technique. If
|
---|
| 217 | you need more precision, retrieve the Pass instance and set the
|
---|
| 218 | property there.
|
---|
| 219 | @see Pass::setSelfIllumination
|
---|
| 220 | */
|
---|
| 221 | void setSelfIllumination(Real red, Real green, Real blue);
|
---|
| 222 |
|
---|
| 223 | /** Sets the amount of self-illumination of every Pass in every Technique.
|
---|
| 224 | @note
|
---|
| 225 | This property actually exists on the Pass class. For simplicity, this method allows
|
---|
| 226 | you to set these properties for every current Pass within this Technique. If
|
---|
| 227 | you need more precision, retrieve the Pass instance and set the
|
---|
| 228 | property there.
|
---|
| 229 | @see Pass::setSelfIllumination
|
---|
| 230 | */
|
---|
| 231 | void setSelfIllumination(const ColourValue& selfIllum);
|
---|
| 232 |
|
---|
| 233 | /** Sets whether or not each Pass renders with depth-buffer checking on or not.
|
---|
| 234 | @note
|
---|
| 235 | This property actually exists on the Pass class. For simplicity, this method allows
|
---|
| 236 | you to set these properties for every current Pass within this Technique. If
|
---|
| 237 | you need more precision, retrieve the Pass instance and set the
|
---|
| 238 | property there.
|
---|
| 239 | @see Pass::setDepthCheckEnabled
|
---|
| 240 | */
|
---|
| 241 | void setDepthCheckEnabled(bool enabled);
|
---|
| 242 |
|
---|
| 243 | /** Sets whether or not each Pass renders with depth-buffer writing on or not.
|
---|
| 244 | @note
|
---|
| 245 | This property actually exists on the Pass class. For simplicity, this method allows
|
---|
| 246 | you to set these properties for every current Pass within this Technique. If
|
---|
| 247 | you need more precision, retrieve the Pass instance and set the
|
---|
| 248 | property there.
|
---|
| 249 | @see Pass::setDepthWriteEnabled
|
---|
| 250 | */
|
---|
| 251 | void setDepthWriteEnabled(bool enabled);
|
---|
| 252 |
|
---|
| 253 | /** Sets the function used to compare depth values when depth checking is on.
|
---|
| 254 | @note
|
---|
| 255 | This property actually exists on the Pass class. For simplicity, this method allows
|
---|
| 256 | you to set these properties for every current Pass within this Technique. If
|
---|
| 257 | you need more precision, retrieve the Pass instance and set the
|
---|
| 258 | property there.
|
---|
| 259 | @see Pass::setDepthFunction
|
---|
| 260 | */
|
---|
| 261 | void setDepthFunction( CompareFunction func );
|
---|
| 262 |
|
---|
| 263 | /** Sets whether or not colour buffer writing is enabled for each Pass.
|
---|
| 264 | @note
|
---|
| 265 | This property actually exists on the Pass class. For simplicity, this method allows
|
---|
| 266 | you to set these properties for every current Pass within this Technique. If
|
---|
| 267 | you need more precision, retrieve the Pass instance and set the
|
---|
| 268 | property there.
|
---|
| 269 | @see Pass::setColourWriteEnabled
|
---|
| 270 | */
|
---|
| 271 | void setColourWriteEnabled(bool enabled);
|
---|
| 272 |
|
---|
| 273 | /** Sets the culling mode for each pass based on the 'vertex winding'.
|
---|
| 274 | @note
|
---|
| 275 | This property actually exists on the Pass class. For simplicity, this method allows
|
---|
| 276 | you to set these properties for every current Pass within this Technique. If
|
---|
| 277 | you need more precision, retrieve the Pass instance and set the
|
---|
| 278 | property there.
|
---|
| 279 | @see Pass::setCullingMode
|
---|
| 280 | */
|
---|
| 281 | void setCullingMode( CullingMode mode );
|
---|
| 282 |
|
---|
| 283 | /** Sets the manual culling mode, performed by CPU rather than hardware.
|
---|
| 284 | @note
|
---|
| 285 | This property actually exists on the Pass class. For simplicity, this method allows
|
---|
| 286 | you to set these properties for every current Pass within this Technique. If
|
---|
| 287 | you need more precision, retrieve the Pass instance and set the
|
---|
| 288 | property there.
|
---|
| 289 | @see Pass::setManualCullingMode
|
---|
| 290 | */
|
---|
| 291 | void setManualCullingMode( ManualCullingMode mode );
|
---|
| 292 |
|
---|
| 293 | /** Sets whether or not dynamic lighting is enabled for every Pass.
|
---|
| 294 | @note
|
---|
| 295 | This property actually exists on the Pass class. For simplicity, this method allows
|
---|
| 296 | you to set these properties for every current Pass within this Technique. If
|
---|
| 297 | you need more precision, retrieve the Pass instance and set the
|
---|
| 298 | property there.
|
---|
| 299 | @see Pass::setLightingEnabled
|
---|
| 300 | */
|
---|
| 301 | void setLightingEnabled(bool enabled);
|
---|
| 302 |
|
---|
| 303 | /** Sets the type of light shading required
|
---|
| 304 | @note
|
---|
| 305 | This property actually exists on the Pass class. For simplicity, this method allows
|
---|
| 306 | you to set these properties for every current Pass within this Technique. If
|
---|
| 307 | you need more precision, retrieve the Pass instance and set the
|
---|
| 308 | property there.
|
---|
| 309 | @see Pass::setShadingMode
|
---|
| 310 | */
|
---|
| 311 | void setShadingMode( ShadeOptions mode );
|
---|
| 312 |
|
---|
| 313 | /** Sets the fogging mode applied to each pass.
|
---|
| 314 | @note
|
---|
| 315 | This property actually exists on the Pass class. For simplicity, this method allows
|
---|
| 316 | you to set these properties for every current Pass within this Technique. If
|
---|
| 317 | you need more precision, retrieve the Pass instance and set the
|
---|
| 318 | property there.
|
---|
| 319 | @see Pass::setFog
|
---|
| 320 | */
|
---|
| 321 | void setFog(
|
---|
| 322 | bool overrideScene,
|
---|
| 323 | FogMode mode = FOG_NONE,
|
---|
| 324 | const ColourValue& colour = ColourValue::White,
|
---|
| 325 | Real expDensity = 0.001, Real linearStart = 0.0, Real linearEnd = 1.0 );
|
---|
| 326 |
|
---|
| 327 | /** Sets the depth bias to be used for each Pass.
|
---|
| 328 | @note
|
---|
| 329 | This property actually exists on the Pass class. For simplicity, this method allows
|
---|
| 330 | you to set these properties for every current Pass within this Technique. If
|
---|
| 331 | you need more precision, retrieve the Pass instance and set the
|
---|
| 332 | property there.
|
---|
| 333 | @see Pass::setDepthBias
|
---|
| 334 | */
|
---|
| 335 | void setDepthBias(ushort bias);
|
---|
| 336 |
|
---|
| 337 | /** Set texture filtering for every texture unit in every Pass
|
---|
| 338 | @note
|
---|
| 339 | This property actually exists on the TextureUnitState class
|
---|
| 340 | For simplicity, this method allows you to set these properties for
|
---|
| 341 | every current TeextureUnitState, If you need more precision, retrieve the
|
---|
| 342 | Pass and TextureUnitState instances and set the property there.
|
---|
| 343 | @see TextureUnitState::setTextureFiltering
|
---|
| 344 | */
|
---|
| 345 | void setTextureFiltering(TextureFilterOptions filterType);
|
---|
| 346 | /** Sets the anisotropy level to be used for all textures.
|
---|
| 347 | @note
|
---|
| 348 | This property has been moved to the TextureUnitState class, which is accessible via the
|
---|
| 349 | Technique and Pass. For simplicity, this method allows you to set these properties for
|
---|
| 350 | every current TeextureUnitState, If you need more precision, retrieve the Technique,
|
---|
| 351 | Pass and TextureUnitState instances and set the property there.
|
---|
| 352 | @see TextureUnitState::setTextureAnisotropy
|
---|
| 353 | */
|
---|
| 354 | void setTextureAnisotropy(unsigned int maxAniso);
|
---|
| 355 |
|
---|
| 356 | /** Sets the kind of blending every pass has with the existing contents of the scene.
|
---|
| 357 | @note
|
---|
| 358 | This property actually exists on the Pass class. For simplicity, this method allows
|
---|
| 359 | you to set these properties for every current Pass within this Technique. If
|
---|
| 360 | you need more precision, retrieve the Pass instance and set the
|
---|
| 361 | property there.
|
---|
| 362 | @see Pass::setSceneBlending
|
---|
| 363 | */
|
---|
| 364 | void setSceneBlending( const SceneBlendType sbt );
|
---|
| 365 |
|
---|
| 366 | /** Allows very fine control of blending every Pass with the existing contents of the scene.
|
---|
| 367 | @note
|
---|
| 368 | This property actually exists on the Pass class. For simplicity, this method allows
|
---|
| 369 | you to set these properties for every current Pass within this Technique. If
|
---|
| 370 | you need more precision, retrieve the Pass instance and set the
|
---|
| 371 | property there.
|
---|
| 372 | @see Pass::setSceneBlending
|
---|
| 373 | */
|
---|
| 374 | void setSceneBlending( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor);
|
---|
| 375 |
|
---|
| 376 | /** Assigns a level-of-detail (LOD) index to this Technique.
|
---|
| 377 | @remarks
|
---|
| 378 | As noted previously, as well as providing fallback support for various
|
---|
| 379 | graphics cards, multiple Technique objects can also be used to implement
|
---|
| 380 | material LOD, where the detail of the material diminishes with distance to
|
---|
| 381 | save rendering power.
|
---|
| 382 | @par
|
---|
| 383 | By default, all Techniques have a LOD index of 0, which means they are the highest
|
---|
| 384 | level of detail. Increasing LOD indexes are lower levels of detail. You can
|
---|
| 385 | assign more than one Technique to the same LOD index, meaning that the best
|
---|
| 386 | Technique that is supported at that LOD index is used.
|
---|
| 387 | @par
|
---|
| 388 | You should not leave gaps in the LOD sequence; Ogre will allow you to do this
|
---|
| 389 | and will continue to function as if the LODs were sequential, but it will
|
---|
| 390 | confuse matters.
|
---|
| 391 | */
|
---|
| 392 | void setLodIndex(unsigned short index);
|
---|
| 393 | /** Gets the level-of-detail index assigned to this Technique. */
|
---|
| 394 | unsigned short getLodIndex(void) const { return mLodIndex; }
|
---|
| 395 |
|
---|
| 396 | /** Is depth writing going to occur on this technique? */
|
---|
| 397 | bool isDepthWriteEnabled(void) const;
|
---|
| 398 |
|
---|
| 399 | /** Is depth checking going to occur on this technique? */
|
---|
| 400 | bool isDepthCheckEnabled(void) const;
|
---|
| 401 |
|
---|
| 402 | };
|
---|
| 403 |
|
---|
| 404 |
|
---|
| 405 | }
|
---|
| 406 | #endif
|
---|