OgreTextureUnitState.h 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088
  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. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #ifndef __TextureUnitState_H__
  25. #define __TextureUnitState_H__
  26. #include "OgrePrerequisites.h"
  27. #include "OgreCommon.h"
  28. #include "OgreBlendMode.h"
  29. #include "OgreMatrix4.h"
  30. #include "OgreString.h"
  31. #include "OgrePixelFormat.h"
  32. #include "OgreTexture.h"
  33. namespace Ogre {
  34. /** \addtogroup Core
  35. * @{
  36. */
  37. /** \addtogroup Materials
  38. * @{
  39. */
  40. /** Class representing the state of a single texture unit during a Pass of a
  41. Technique, of a Material.
  42. @remarks
  43. Texture units are pipelines for retrieving texture data for rendering onto
  44. your objects in the world. Using them is common to both the fixed-function and
  45. the programmable (vertex and fragment program) pipeline, but some of the
  46. settings will only have an effect in the fixed-function pipeline (for example,
  47. setting a texture rotation will have no effect if you use the programmable
  48. pipeline, because this is overridden by the fragment program). The effect
  49. of each setting as regards the 2 pipelines is commented in each setting.
  50. @par
  51. When I use the term 'fixed-function pipeline' I mean traditional rendering
  52. where you do not use vertex or fragment programs (shaders). Programmable
  53. pipeline means that for this pass you are using vertex or fragment programs.
  54. */
  55. class _OgreExport TextureUnitState
  56. {
  57. friend class RenderSystem;
  58. public:
  59. /** Definition of the broad types of texture effect you can apply to a texture unit.
  60. @note
  61. Note that these have no effect when using the programmable pipeline, since their
  62. effect is overridden by the vertex / fragment programs.
  63. */
  64. enum TextureEffectType
  65. {
  66. /// Generate all texture coords based on angle between camera and vertex
  67. ET_ENVIRONMENT_MAP,
  68. /// Generate texture coords based on a frustum
  69. ET_PROJECTIVE_TEXTURE,
  70. /// Constant u/v scrolling effect
  71. ET_UVSCROLL,
  72. /// Constant u scrolling effect
  73. ET_USCROLL,
  74. /// Constant u/v scrolling effect
  75. ET_VSCROLL,
  76. /// Constant rotation
  77. ET_ROTATE,
  78. /// More complex transform
  79. ET_TRANSFORM
  80. };
  81. /** Enumeration to specify type of envmap.
  82. @note
  83. Note that these have no effect when using the programmable pipeline, since their
  84. effect is overridden by the vertex / fragment programs.
  85. */
  86. enum EnvMapType
  87. {
  88. /// Envmap based on vector from camera to vertex position, good for planar geometry
  89. ENV_PLANAR,
  90. /// Envmap based on dot of vector from camera to vertex and vertex normal, good for curves
  91. ENV_CURVED,
  92. /// Envmap intended to supply reflection vectors for cube mapping
  93. ENV_REFLECTION,
  94. /// Envmap intended to supply normal vectors for cube mapping
  95. ENV_NORMAL
  96. };
  97. /** Useful enumeration when dealing with procedural transforms.
  98. @note
  99. Note that these have no effect when using the programmable pipeline, since their
  100. effect is overridden by the vertex / fragment programs.
  101. */
  102. enum TextureTransformType
  103. {
  104. TT_TRANSLATE_U,
  105. TT_TRANSLATE_V,
  106. TT_SCALE_U,
  107. TT_SCALE_V,
  108. TT_ROTATE
  109. };
  110. /** Texture addressing modes - default is TAM_WRAP.
  111. @note
  112. These settings are relevant in both the fixed-function and the
  113. programmable pipeline.
  114. */
  115. enum TextureAddressingMode
  116. {
  117. /// Texture wraps at values over 1.0
  118. TAM_WRAP,
  119. /// Texture mirrors (flips) at joins over 1.0
  120. TAM_MIRROR,
  121. /// Texture clamps at 1.0
  122. TAM_CLAMP,
  123. /// Texture coordinates outside the range [0.0, 1.0] are set to the border colour
  124. TAM_BORDER
  125. };
  126. /** Texture addressing mode for each texture coordinate. */
  127. struct UVWAddressingMode
  128. {
  129. TextureAddressingMode u, v, w;
  130. };
  131. /** Enum identifying the frame indexes for faces of a cube map (not the composite 3D type.
  132. */
  133. enum TextureCubeFace
  134. {
  135. CUBE_FRONT = 0,
  136. CUBE_BACK = 1,
  137. CUBE_LEFT = 2,
  138. CUBE_RIGHT = 3,
  139. CUBE_UP = 4,
  140. CUBE_DOWN = 5
  141. };
  142. /** Internal structure defining a texture effect.
  143. */
  144. struct TextureEffect {
  145. TextureEffectType type;
  146. int subtype;
  147. Real arg1, arg2;
  148. WaveformType waveType;
  149. Real base;
  150. Real frequency;
  151. Real phase;
  152. Real amplitude;
  153. Controller<Real>* controller;
  154. const Frustum* frustum;
  155. };
  156. /** Texture effects in a multimap paired array
  157. */
  158. typedef multimap<TextureEffectType, TextureEffect>::type EffectMap;
  159. /** Default constructor.
  160. */
  161. TextureUnitState(Pass* parent);
  162. TextureUnitState(Pass* parent, const TextureUnitState& oth );
  163. TextureUnitState & operator = ( const TextureUnitState& oth );
  164. /** Default destructor.
  165. */
  166. ~TextureUnitState();
  167. /** Name-based constructor.
  168. @param
  169. name The basic name of the texture e.g. brickwall.jpg, stonefloor.png
  170. @param
  171. texCoordSet The index of the texture coordinate set to use.
  172. */
  173. TextureUnitState( Pass* parent, const String& texName, unsigned int texCoordSet = 0);
  174. /** Get the name of current texture image for this layer.
  175. @remarks
  176. This will either always be a single name for this layer,
  177. or will be the name of the current frame for an animated
  178. or otherwise multi-frame texture.
  179. @note
  180. Applies to both fixed-function and programmable pipeline.
  181. */
  182. const String& getTextureName(void) const;
  183. /** Sets this texture layer to use a single texture, given the
  184. name of the texture to use on this layer.
  185. @note
  186. Applies to both fixed-function and programmable pipeline.
  187. */
  188. void setTextureName( const String& name, TextureType ttype = TEX_TYPE_2D);
  189. /** Sets this texture layer to use a combination of 6 texture maps, each one relating to a face of a cube.
  190. @remarks
  191. Cubic textures are made up of 6 separate texture images. Each one of these is an orthoganal view of the
  192. world with a FOV of 90 degrees and an aspect ratio of 1:1. You can generate these from 3D Studio by
  193. rendering a scene to a reflection map of a transparent cube and saving the output files.
  194. @par
  195. Cubic maps can be used either for skyboxes (complete wrap-around skies, like space) or as environment
  196. maps to simulate reflections. The system deals with these 2 scenarios in different ways:
  197. <ol>
  198. <li>
  199. <p>
  200. for cubic environment maps, the 6 textures are combined into a single 'cubic' texture map which
  201. is then addressed using 3D texture coordinates. This is required because you don't know what
  202. face of the box you're going to need to address when you render an object, and typically you
  203. need to reflect more than one face on the one object, so all 6 textures are needed to be
  204. 'active' at once. Cubic environment maps are enabled by calling this method with the forUVW
  205. parameter set to true, and then calling setEnvironmentMap(true).
  206. </p>
  207. <p>
  208. Note that not all cards support cubic environment mapping.
  209. </p>
  210. </li>
  211. <li>
  212. <p>
  213. for skyboxes, the 6 textures are kept separate and used independently for each face of the skybox.
  214. This is done because not all cards support 3D cubic maps and skyboxes do not need to use 3D
  215. texture coordinates so it is simpler to render each face of the box with 2D coordinates, changing
  216. texture between faces.
  217. </p>
  218. <p>
  219. Skyboxes are created by calling SceneManager::setSkyBox.
  220. </p>
  221. </li>
  222. </ul>
  223. @note
  224. Applies to both fixed-function and programmable pipeline.
  225. @param
  226. name The basic name of the texture e.g. brickwall.jpg, stonefloor.png. There must be 6 versions
  227. of this texture with the suffixes _fr, _bk, _up, _dn, _lf, and _rt (before the extension) which
  228. make up the 6 sides of the box. The textures must all be the same size and be powers of 2 in width & height.
  229. If you can't make your texture names conform to this, use the alternative method of the same name which takes
  230. an array of texture names instead.
  231. @param
  232. forUVW Set to true if you want a single 3D texture addressable with 3D texture coordinates rather than
  233. 6 separate textures. Useful for cubic environment mapping.
  234. */
  235. void setCubicTextureName( const String& name, bool forUVW = false );
  236. /** Sets this texture layer to use a combination of 6 texture maps, each one relating to a face of a cube.
  237. @remarks
  238. Cubic textures are made up of 6 separate texture images. Each one of these is an orthoganal view of the
  239. world with a FOV of 90 degrees and an aspect ratio of 1:1. You can generate these from 3D Studio by
  240. rendering a scene to a reflection map of a transparent cube and saving the output files.
  241. @par
  242. Cubic maps can be used either for skyboxes (complete wrap-around skies, like space) or as environment
  243. maps to simulate reflections. The system deals with these 2 scenarios in different ways:
  244. <ol>
  245. <li>
  246. <p>
  247. for cubic environment maps, the 6 textures are combined into a single 'cubic' texture map which
  248. is then addressed using 3D texture coordinates. This is required because you don't know what
  249. face of the box you're going to need to address when you render an object, and typically you
  250. need to reflect more than one face on the one object, so all 6 textures are needed to be
  251. 'active' at once. Cubic environment maps are enabled by calling this method with the forUVW
  252. parameter set to true, and then calling setEnvironmentMap(true).
  253. </p>
  254. <p>
  255. Note that not all cards support cubic environment mapping.
  256. </p>
  257. </li>
  258. <li>
  259. <p>
  260. for skyboxes, the 6 textures are kept separate and used independently for each face of the skybox.
  261. This is done because not all cards support 3D cubic maps and skyboxes do not need to use 3D
  262. texture coordinates so it is simpler to render each face of the box with 2D coordinates, changing
  263. texture between faces.
  264. </p>
  265. <p>
  266. Skyboxes are created by calling SceneManager::setSkyBox.
  267. </p>
  268. </li>
  269. </ul>
  270. @note
  271. Applies to both fixed-function and programmable pipeline.
  272. @param
  273. name The basic name of the texture e.g. brickwall.jpg, stonefloor.png. There must be 6 versions
  274. of this texture with the suffixes _fr, _bk, _up, _dn, _lf, and _rt (before the extension) which
  275. make up the 6 sides of the box. The textures must all be the same size and be powers of 2 in width & height.
  276. If you can't make your texture names conform to this, use the alternative method of the same name which takes
  277. an array of texture names instead.
  278. @param
  279. forUVW Set to true if you want a single 3D texture addressable with 3D texture coordinates rather than
  280. 6 separate textures. Useful for cubic environment mapping.
  281. */
  282. void setCubicTextureName( const String* const names, bool forUVW = false );
  283. /** Sets the names of the texture images for an animated texture.
  284. @remarks
  285. Animated textures are just a series of images making up the frames of the animation. All the images
  286. must be the same size, and their names must have a frame number appended before the extension, e.g.
  287. if you specify a name of "wall.jpg" with 3 frames, the image names must be "wall_0.jpg", "wall_1.jpg"
  288. and "wall_2.jpg".
  289. @par
  290. You can change the active frame on a texture layer by calling the setCurrentFrame method.
  291. @note
  292. If you can't make your texture images conform to the naming standard layed out here, you
  293. can call the alternative setAnimatedTextureName method which takes an array of names instead.
  294. @note
  295. Applies to both fixed-function and programmable pipeline.
  296. @param
  297. name The base name of the textures to use e.g. wall.jpg for frames wall_0.jpg, wall_1.jpg etc.
  298. @param
  299. numFrames The number of frames in the sequence.
  300. @param
  301. duration The length of time it takes to display the whole animation sequence, in seconds.
  302. If 0, no automatic transition occurs.
  303. */
  304. void setAnimatedTextureName( const String& name, unsigned int numFrames, Real duration = 0 );
  305. /** Sets the names of the texture images for an animated texture.
  306. @remarks
  307. This an alternative method to the one where you specify a single name and let the system derive
  308. the names of each frame, incase your images can't conform to this naming standard.
  309. @par
  310. Animated textures are just a series of images making up the frames of the animation. All the images
  311. must be the same size, and you must provide their names as an array in the first parameter.
  312. You can change the active frame on a texture layer by calling the setCurrentFrame method.
  313. @note
  314. If you can make your texture images conform to a naming standard of basicName_frame.ext, you
  315. can call the alternative setAnimatedTextureName method which just takes a base name instead.
  316. @note
  317. Applies to both fixed-function and programmable pipeline.
  318. @param
  319. names Pointer to array of names of the textures to use, in frame order.
  320. @param
  321. numFrames The number of frames in the sequence.
  322. @param
  323. duration The length of time it takes to display the whole animation sequence, in seconds.
  324. If 0, no automatic transition occurs.
  325. */
  326. void setAnimatedTextureName( const String* const names, unsigned int numFrames, Real duration = 0 );
  327. /** Returns the width and height of the texture in the given frame.
  328. */
  329. std::pair< size_t, size_t > getTextureDimensions( unsigned int frame = 0 ) const;
  330. /** Changes the active frame in an animated or multi-image texture.
  331. @remarks
  332. An animated texture (or a cubic texture where the images are not combined for 3D use) is made up of
  333. a number of frames. This method sets the active frame.
  334. @note
  335. Applies to both fixed-function and programmable pipeline.
  336. */
  337. void setCurrentFrame( unsigned int frameNumber );
  338. /** Gets the active frame in an animated or multi-image texture layer.
  339. @note
  340. Applies to both fixed-function and programmable pipeline.
  341. */
  342. unsigned int getCurrentFrame(void) const;
  343. /** Gets the name of the texture associated with a frame number.
  344. Throws an exception if frameNumber exceeds the number of stored frames.
  345. @note
  346. Applies to both fixed-function and programmable pipeline.
  347. */
  348. const String& getFrameTextureName(unsigned int frameNumber) const;
  349. /** Sets the name of the texture associated with a frame.
  350. @param name The name of the texture
  351. @param frameNumber The frame the texture name is to be placed in
  352. @note
  353. Throws an exception if frameNumber exceeds the number of stored frames.
  354. Applies to both fixed-function and programmable pipeline.
  355. */
  356. void setFrameTextureName(const String& name, unsigned int frameNumber);
  357. /** Add a Texture name to the end of the frame container.
  358. @param name The name of the texture
  359. @note
  360. Applies to both fixed-function and programmable pipeline.
  361. */
  362. void addFrameTextureName(const String& name);
  363. /** deletes a specific texture frame. The texture used is not deleted but the
  364. texture will no longer be used by the Texture Unit. An exception is raised
  365. if the frame number exceeds the number of actual frames.
  366. @param frameNumber The frame number of the texture to be deleted.
  367. @note
  368. Applies to both fixed-function and programmable pipeline.
  369. */
  370. void deleteFrameTextureName(const size_t frameNumber);
  371. /** Gets the number of frames for a texture.
  372. @note
  373. Applies to both fixed-function and programmable pipeline.
  374. */
  375. unsigned int getNumFrames(void) const;
  376. /** The type of unit to bind the texture settings to. */
  377. enum BindingType
  378. {
  379. /** Regular fragment processing unit - the default. */
  380. BT_FRAGMENT = 0,
  381. /** Vertex processing unit - indicates this unit will be used for
  382. a vertex texture fetch.
  383. */
  384. BT_VERTEX = 1
  385. };
  386. /** Enum identifying the type of content this texture unit contains.
  387. */
  388. enum ContentType
  389. {
  390. /// Normal texture identified by name
  391. CONTENT_NAMED = 0,
  392. /// A shadow texture, automatically bound by engine
  393. CONTENT_SHADOW = 1,
  394. /// A compositor texture, automatically linked to active viewport's chain
  395. CONTENT_COMPOSITOR = 2
  396. };
  397. /** Sets the type of unit these texture settings should be bound to.
  398. @remarks
  399. Some render systems, when implementing vertex texture fetch, separate
  400. the binding of textures for use in the vertex program versus those
  401. used in fragment programs. This setting allows you to target the
  402. vertex processing unit with a texture binding, in those cases. For
  403. rendersystems which have a unified binding for the vertex and fragment
  404. units, this setting makes no difference.
  405. */
  406. void setBindingType(BindingType bt);
  407. /** Gets the type of unit these texture settings should be bound to.
  408. */
  409. BindingType getBindingType(void) const;
  410. /** Set the type of content this TextureUnitState references.
  411. @remarks
  412. The default is to reference a standard named texture, but this unit
  413. can also reference automated content like a shadow texture.
  414. */
  415. void setContentType(ContentType ct);
  416. /** Get the type of content this TextureUnitState references. */
  417. ContentType getContentType(void) const;
  418. /** Returns true if this texture unit is either a series of 6 2D textures, each
  419. in it's own frame, or is a full 3D cube map. You can tell which by checking
  420. getTextureType.
  421. @note
  422. Applies to both fixed-function and programmable pipeline.
  423. */
  424. bool isCubic(void) const;
  425. /** Returns true if this texture layer uses a composite 3D cubic texture.
  426. @note
  427. Applies to both fixed-function and programmable pipeline.
  428. */
  429. bool is3D(void) const;
  430. /** Returns the type of this texture.
  431. @note
  432. Applies to both fixed-function and programmable pipeline.
  433. */
  434. TextureType getTextureType(void) const;
  435. /** Sets the desired pixel format when load the texture.
  436. */
  437. void setDesiredFormat(PixelFormat desiredFormat);
  438. /** Gets the desired pixel format when load the texture.
  439. */
  440. PixelFormat getDesiredFormat(void) const;
  441. /** Sets how many mipmaps have been requested for the texture.
  442. */
  443. void setNumMipmaps(int numMipmaps);
  444. /** Gets how many mipmaps have been requested for the texture.
  445. */
  446. int getNumMipmaps(void) const;
  447. /** Sets whether this texture is requested to be loaded as alpha if single channel
  448. */
  449. void setIsAlpha(bool isAlpha);
  450. /** Gets whether this texture is requested to be loaded as alpha if single channel
  451. */
  452. bool getIsAlpha(void) const;
  453. /// @copydoc Texture::setHardwareGammaEnabled
  454. void setHardwareGammaEnabled(bool enabled);
  455. /// @copydoc Texture::isHardwareGammaEnabled
  456. bool isHardwareGammaEnabled() const;
  457. /** Gets the index of the set of texture co-ords this layer uses.
  458. @note
  459. Applies to both fixed-function and programmable pipeline.
  460. */
  461. unsigned int getTextureCoordSet(void) const;
  462. /** Sets the index of the set of texture co-ords this layer uses.
  463. @note
  464. Default is 0 for all layers. Only change this if you have provided multiple texture co-ords per
  465. vertex.
  466. @note
  467. Applies to both fixed-function and programmable pipeline.
  468. */
  469. void setTextureCoordSet(unsigned int set);
  470. /** Sets a matrix used to transform any texture coordinates on this layer.
  471. @remarks
  472. Texture coordinates can be modified on a texture layer to create effects like scrolling
  473. textures. A texture transform can either be applied to a layer which takes the source coordinates
  474. from a fixed set in the geometry, or to one which generates them dynamically (e.g. environment mapping).
  475. @par
  476. It's obviously a bit impractical to create scrolling effects by calling this method manually since you
  477. would have to call it every framw with a slight alteration each time, which is tedious. Instead
  478. you can use the ControllerManager class to create a Controller object which will manage the
  479. effect over time for you. See the ControllerManager::createTextureScroller and it's sibling methods for details.<BR>
  480. In addition, if you want to set the individual texture transformations rather than concatenating them
  481. yourself, use setTextureScroll, setTextureScale and setTextureRotate.
  482. @note
  483. Has no effect in the programmable pipeline.
  484. */
  485. void setTextureTransform(const Matrix4& xform);
  486. /** Gets the current texture transformation matrix.
  487. @remarks
  488. Causes a reclaculation of the matrix if any parameters have been changed via
  489. setTextureScroll, setTextureScale and setTextureRotate.
  490. @note
  491. Has no effect in the programmable pipeline.
  492. */
  493. const Matrix4& getTextureTransform(void) const;
  494. /** Sets the translation offset of the texture, ie scrolls the texture.
  495. @remarks
  496. This method sets the translation element of the texture transformation, and is easier to use than setTextureTransform if
  497. you are combining translation, scaling and rotation in your texture transformation. Again if you want
  498. to animate these values you need to use a Controller
  499. @note
  500. Has no effect in the programmable pipeline.
  501. @param u The amount the texture should be moved horizontally (u direction).
  502. @param v The amount the texture should be moved vertically (v direction).
  503. @see
  504. ControllerManager, Controller
  505. */
  506. void setTextureScroll(Real u, Real v);
  507. /** As setTextureScroll, but sets only U value.
  508. @note
  509. Has no effect in the programmable pipeline.
  510. */
  511. void setTextureUScroll(Real value);
  512. // get texture uscroll value
  513. Real getTextureUScroll(void) const;
  514. /** As setTextureScroll, but sets only V value.
  515. @note
  516. Has no effect in the programmable pipeline.
  517. */
  518. void setTextureVScroll(Real value);
  519. // get texture vscroll value
  520. Real getTextureVScroll(void) const;
  521. /** As setTextureScale, but sets only U value.
  522. @note
  523. Has no effect in the programmable pipeline.
  524. */
  525. void setTextureUScale(Real value);
  526. // get texture uscale value
  527. Real getTextureUScale(void) const;
  528. /** As setTextureScale, but sets only V value.
  529. @note
  530. Has no effect in the programmable pipeline.
  531. */
  532. void setTextureVScale(Real value);
  533. // get texture vscale value
  534. Real getTextureVScale(void) const;
  535. /** Sets the scaling factor applied to texture coordinates.
  536. @remarks
  537. This method sets the scale element of the texture transformation, and is easier to use than
  538. setTextureTransform if you are combining translation, scaling and rotation in your texture transformation. Again if you want
  539. to animate these values you need to use a Controller (see ControllerManager and it's methods for
  540. more information).
  541. @note
  542. Has no effect in the programmable pipeline.
  543. @param
  544. uScale The value by which the texture is to be scaled horizontally.
  545. @param
  546. vScale The value by which the texture is to be scaled vertically.
  547. */
  548. void setTextureScale(Real uScale, Real vScale);
  549. /** Sets the anticlockwise rotation factor applied to texture coordinates.
  550. @remarks
  551. This sets a fixed rotation angle - if you wish to animate this, see the
  552. ControllerManager::createTextureRotater method.
  553. @note
  554. Has no effect in the programmable pipeline.
  555. @param
  556. angle The angle of rotation (anticlockwise).
  557. */
  558. void setTextureRotate(const Radian& angle);
  559. // get texture rotation effects angle value
  560. const Radian& getTextureRotate(void) const;
  561. /** Gets the texture addressing mode for a given coordinate,
  562. i.e. what happens at uv values above 1.0.
  563. @note
  564. The default is TAM_WRAP i.e. the texture repeats over values of 1.0.
  565. */
  566. const UVWAddressingMode& getTextureAddressingMode(void) const;
  567. /** Sets the texture addressing mode, i.e. what happens at uv values above 1.0.
  568. @note
  569. The default is TAM_WRAP i.e. the texture repeats over values of 1.0.
  570. @note This is a shortcut method which sets the addressing mode for all
  571. coordinates at once; you can also call the more specific method
  572. to set the addressing mode per coordinate.
  573. @note
  574. This applies for both the fixed-function and programmable pipelines.
  575. */
  576. void setTextureAddressingMode( TextureAddressingMode tam);
  577. /** Sets the texture addressing mode, i.e. what happens at uv values above 1.0.
  578. @note
  579. The default is TAM_WRAP i.e. the texture repeats over values of 1.0.
  580. @note
  581. This applies for both the fixed-function and programmable pipelines.
  582. */
  583. void setTextureAddressingMode( TextureAddressingMode u,
  584. TextureAddressingMode v, TextureAddressingMode w);
  585. /** Sets the texture addressing mode, i.e. what happens at uv values above 1.0.
  586. @note
  587. The default is TAM_WRAP i.e. the texture repeats over values of 1.0.
  588. @note
  589. This applies for both the fixed-function and programmable pipelines.
  590. */
  591. void setTextureAddressingMode( const UVWAddressingMode& uvw);
  592. /** Sets the texture border colour.
  593. @note
  594. The default is ColourValue::Black, and this value only used when addressing mode
  595. is TAM_BORDER.
  596. @note
  597. This applies for both the fixed-function and programmable pipelines.
  598. */
  599. void setTextureBorderColour(const ColourValue& colour);
  600. /** Sets the texture border colour.
  601. @note
  602. The default is ColourValue::Black, and this value only used when addressing mode
  603. is TAM_BORDER.
  604. */
  605. const ColourValue& getTextureBorderColour(void) const;
  606. /** Setting advanced blending options.
  607. @remarks
  608. This is an extended version of the TextureUnitState::setColourOperation method which allows
  609. extremely detailed control over the blending applied between this and earlier layers.
  610. See the IMPORTANT note below about the issues between mulitpass and multitexturing that
  611. using this method can create.
  612. @par
  613. Texture colour operations determine how the final colour of the surface appears when
  614. rendered. Texture units are used to combine colour values from various sources (ie. the
  615. diffuse colour of the surface from lighting calculations, combined with the colour of
  616. the texture). This method allows you to specify the 'operation' to be used, ie. the
  617. calculation such as adds or multiplies, and which values to use as arguments, such as
  618. a fixed value or a value from a previous calculation.
  619. @par
  620. The defaults for each layer are:
  621. <ul>
  622. <li>op = LBX_MODULATE</li>
  623. <li>source1 = LBS_TEXTURE</li>
  624. <li>source2 = LBS_CURRENT</li>
  625. </ul>
  626. ie. each layer takes the colour results of the previous layer, and multiplies them
  627. with the new texture being applied. Bear in mind that colours are RGB values from
  628. 0.0 - 1.0 so multiplying them together will result in values in the same range,
  629. 'tinted' by the multiply. Note however that a straight multiply normally has the
  630. effect of darkening the textures - for this reason there are brightening operations
  631. like LBO_MODULATE_X2. See the LayerBlendOperation and LayerBlendSource enumerated
  632. types for full details.
  633. @note
  634. Because of the limitations on some underlying APIs (Direct3D included)
  635. the LBS_TEXTURE argument can only be used as the first argument, not the second.
  636. @par
  637. The final 3 parameters are only required if you decide to pass values manually
  638. into the operation, i.e. you want one or more of the inputs to the colour calculation
  639. to come from a fixed value that you supply. Hence you only need to fill these in if
  640. you supply LBS_MANUAL to the corresponding source, or use the LBX_BLEND_MANUAL
  641. operation.
  642. @warning
  643. Ogre tries to use multitexturing hardware to blend texture layers
  644. together. However, if it runs out of texturing units (e.g. 2 of a GeForce2, 4 on a
  645. GeForce3) it has to fall back on multipass rendering, i.e. rendering the same object
  646. multiple times with different textures. This is both less efficient and there is a smaller
  647. range of blending operations which can be performed. For this reason, if you use this method
  648. you MUST also call TextureUnitState::setColourOpMultipassFallback to specify which effect you
  649. want to fall back on if sufficient hardware is not available.
  650. @note
  651. This has no effect in the programmable pipeline.
  652. @param
  653. If you wish to avoid having to do this, use the simpler TextureUnitState::setColourOperation method
  654. which allows less flexible blending options but sets up the multipass fallback automatically,
  655. since it only allows operations which have direct multipass equivalents.
  656. @param
  657. op The operation to be used, e.g. modulate (multiply), add, subtract
  658. @param
  659. source1 The source of the first colour to the operation e.g. texture colour
  660. @param
  661. source2 The source of the second colour to the operation e.g. current surface colour
  662. @param
  663. arg1 Manually supplied colour value (only required if source1 = LBS_MANUAL)
  664. @param
  665. arg2 Manually supplied colour value (only required if source2 = LBS_MANUAL)
  666. @param
  667. manualBlend Manually supplied 'blend' value - only required for operations
  668. which require manual blend e.g. LBX_BLEND_MANUAL
  669. */
  670. void setColourOperationEx(
  671. LayerBlendOperationEx op,
  672. LayerBlendSource source1 = LBS_TEXTURE,
  673. LayerBlendSource source2 = LBS_CURRENT,
  674. const ColourValue& arg1 = ColourValue::White,
  675. const ColourValue& arg2 = ColourValue::White,
  676. Real manualBlend = 0.0);
  677. /** Determines how this texture layer is combined with the one below it (or the diffuse colour of
  678. the geometry if this is layer 0).
  679. @remarks
  680. This method is the simplest way to blend tetxure layers, because it requires only one parameter,
  681. gives you the most common blending types, and automatically sets up 2 blending methods: one for
  682. if single-pass multitexturing hardware is available, and another for if it is not and the blending must
  683. be achieved through multiple rendering passes. It is, however, quite limited and does not expose
  684. the more flexible multitexturing operations, simply because these can't be automatically supported in
  685. multipass fallback mode. If want to use the fancier options, use TextureUnitState::setColourOperationEx,
  686. but you'll either have to be sure that enough multitexturing units will be available, or you should
  687. explicitly set a fallback using TextureUnitState::setColourOpMultipassFallback.
  688. @note
  689. The default method is LBO_MODULATE for all layers.
  690. @note
  691. This option has no effect in the programmable pipeline.
  692. @param
  693. op One of the LayerBlendOperation enumerated blending types.
  694. */
  695. void setColourOperation( const LayerBlendOperation op);
  696. /** Sets the multipass fallback operation for this layer, if you used TextureUnitState::setColourOperationEx
  697. and not enough multitexturing hardware is available.
  698. @remarks
  699. Because some effects exposed using TextureUnitState::setColourOperationEx are only supported under
  700. multitexturing hardware, if the hardware is lacking the system must fallback on multipass rendering,
  701. which unfortunately doesn't support as many effects. This method is for you to specify the fallback
  702. operation which most suits you.
  703. @par
  704. You'll notice that the interface is the same as the Material::setSceneBlending method; this is
  705. because multipass rendering IS effectively scene blending, since each layer is rendered on top
  706. of the last using the same mechanism as making an object transparent, it's just being rendered
  707. in the same place repeatedly to get the multitexture effect.
  708. @par
  709. If you use the simpler (and hence less flexible) TextureUnitState::setColourOperation method you
  710. don't need to call this as the system sets up the fallback for you.
  711. @note
  712. This option has no effect in the programmable pipeline, because there is no multipass fallback
  713. and multitexture blending is handled by the fragment shader.
  714. */
  715. void setColourOpMultipassFallback( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor);
  716. /** Get multitexturing colour blending mode.
  717. */
  718. const LayerBlendModeEx& getColourBlendMode(void) const;
  719. /** Get multitexturing alpha blending mode.
  720. */
  721. const LayerBlendModeEx& getAlphaBlendMode(void) const;
  722. /** Get the multipass fallback for colour blending operation source factor.
  723. */
  724. SceneBlendFactor getColourBlendFallbackSrc(void) const;
  725. /** Get the multipass fallback for colour blending operation destination factor.
  726. */
  727. SceneBlendFactor getColourBlendFallbackDest(void) const;
  728. /** Sets the alpha operation to be applied to this texture.
  729. @remarks
  730. This works in exactly the same way as setColourOperation, except
  731. that the effect is applied to the level of alpha (i.e. transparency)
  732. of the texture rather than its colour. When the alpha of a texel (a pixel
  733. on a texture) is 1.0, it is opaque, wheras it is fully transparent if the
  734. alpha is 0.0. Please refer to the setColourOperation method for more info.
  735. @param
  736. op The operation to be used, e.g. modulate (multiply), add, subtract
  737. @param
  738. source1 The source of the first alpha value to the operation e.g. texture alpha
  739. @param
  740. source2 The source of the second alpha value to the operation e.g. current surface alpha
  741. @param
  742. arg1 Manually supplied alpha value (only required if source1 = LBS_MANUAL)
  743. @param
  744. arg2 Manually supplied alpha value (only required if source2 = LBS_MANUAL)
  745. @param
  746. manualBlend Manually supplied 'blend' value - only required for operations
  747. which require manual blend e.g. LBX_BLEND_MANUAL
  748. @see
  749. setColourOperation
  750. @note
  751. This option has no effect in the programmable pipeline.
  752. */
  753. void setAlphaOperation(LayerBlendOperationEx op,
  754. LayerBlendSource source1 = LBS_TEXTURE,
  755. LayerBlendSource source2 = LBS_CURRENT,
  756. Real arg1 = 1.0,
  757. Real arg2 = 1.0,
  758. Real manualBlend = 0.0);
  759. /** Determines if this texture layer is currently blank.
  760. @note
  761. This can happen if a texture fails to load or some other non-fatal error. Worth checking after
  762. setting texture name.
  763. */
  764. bool isBlank(void) const;
  765. /** Sets this texture layer to be blank.
  766. */
  767. void setBlank(void);
  768. /** Tests if the texture associated with this unit has failed to load.
  769. */
  770. bool isTextureLoadFailing() const { return mTextureLoadFailed; }
  771. /** Tells the unit to retry loading the texture if it had failed to load.
  772. */
  773. void retryTextureLoad() { mTextureLoadFailed = false; }
  774. // get texture effects in a multimap paired array
  775. const EffectMap& getEffects(void) const;
  776. // get the animated-texture animation duration
  777. Real getAnimationDuration(void) const;
  778. /** Set the texture filtering for this unit, using the simplified interface.
  779. @remarks
  780. You also have the option of specifying the minification, magnification
  781. and mip filter individually if you want more control over filtering
  782. options. See the alternative setTextureFiltering methods for details.
  783. @note
  784. This option applies in both the fixed function and the programmable pipeline.
  785. @param filterType The high-level filter type to use.
  786. */
  787. void setTextureFiltering(TextureFilterOptions filterType);
  788. /** Set a single filtering option on this texture unit.
  789. @params ftype The filtering type to set
  790. @params opts The filtering option to set
  791. */
  792. void setTextureFiltering(FilterType ftype, FilterOptions opts);
  793. /** Set a the detailed filtering options on this texture unit.
  794. @params minFilter The filtering to use when reducing the size of the texture.
  795. Can be FO_POINT, FO_LINEAR or FO_ANISOTROPIC
  796. @params magFilter The filtering to use when increasing the size of the texture
  797. Can be FO_POINT, FO_LINEAR or FO_ANISOTROPIC
  798. @params mipFilter The filtering to use between mip levels
  799. Can be FO_NONE (turns off mipmapping), FO_POINT or FO_LINEAR (trilinear filtering)
  800. */
  801. void setTextureFiltering(FilterOptions minFilter, FilterOptions magFilter, FilterOptions mipFilter);
  802. // get the texture filtering for the given type
  803. FilterOptions getTextureFiltering(FilterType ftpye) const;
  804. /** Sets the anisotropy level to be used for this texture level.
  805. @par maxAniso The maximal anisotropy level, should be between 2 and the maximum supported by hardware (1 is the default, ie. no anisotrophy).
  806. @note
  807. This option applies in both the fixed function and the programmable pipeline.
  808. */
  809. void setTextureAnisotropy(unsigned int maxAniso);
  810. // get this layer texture anisotropy level
  811. unsigned int getTextureAnisotropy() const;
  812. /** Sets the bias value applied to the mipmap calculation.
  813. @remarks
  814. You can alter the mipmap calculation by biasing the result with a
  815. single floating point value. After the mip level has been calculated,
  816. this bias value is added to the result to give the final mip level.
  817. Lower mip levels are larger (higher detail), so a negative bias will
  818. force the larger mip levels to be used, and a positive bias
  819. will cause smaller mip levels to be used. The bias values are in
  820. mip levels, so a -1 bias will force mip levels one larger than by the
  821. default calculation.
  822. @param bias The bias value as described above, can be positive or negative.
  823. */
  824. void setTextureMipmapBias(float bias) { mMipmapBias = bias; }
  825. /** Gets the bias value applied to the mipmap calculation.
  826. @see TextureUnitState::setTextureMipmapBias
  827. */
  828. float getTextureMipmapBias(void) const { return mMipmapBias; }
  829. /** Set the compositor reference for this texture unit state.
  830. @remarks
  831. Only valid when content type is compositor.
  832. @param compositorName the name of the compositor to reference
  833. @param textureName the name of the texture to reference
  834. @param mrtIndex the index of the wanted texture, if referencing an MRT
  835. */
  836. void setCompositorReference(const String& compositorName, const String& textureName, size_t mrtIndex = 0);
  837. /** Gets the name of the compositor that this texture referneces */
  838. const String& getReferencedCompositorName() const { return mCompositorRefName; }
  839. /** Gets the name of the texture in the compositor that this texture references */
  840. const String& getReferencedTextureName() const { return mCompositorRefTexName; }
  841. /** Gets the MRT index of the texture in the compositor that this texture references */
  842. size_t getReferencedMRTIndex() const { return mCompositorRefMrtIndex; }
  843. /// Gets the parent Pass object
  844. Pass* getParent(void) const { return mParent; }
  845. /** Internal method for preparing this object for load, as part of Material::prepare*/
  846. void _prepare(void);
  847. /** Internal method for undoing the preparation this object as part of Material::unprepare*/
  848. void _unprepare(void);
  849. /** Internal method for loading this object as part of Material::load */
  850. void _load(void);
  851. /** Internal method for unloading this object as part of Material::unload */
  852. void _unload(void);
  853. /// Returns whether this unit has texture coordinate generation that depends on the camera
  854. bool hasViewRelativeTextureCoordinateGeneration(void) const;
  855. // Is this loaded?
  856. bool isLoaded(void) const;
  857. /** Tells the class that it needs recompilation. */
  858. void _notifyNeedsRecompile(void);
  859. /** Set the name of the Texture Unit State
  860. @remarks
  861. The name of the Texture Unit State is optional. Its usefull in material scripts where a material could inherit
  862. from another material and only want to modify a particalar Texture Unit State.
  863. */
  864. void setName(const String& name);
  865. /// get the name of the Texture Unit State
  866. const String& getName(void) const { return mName; }
  867. /** Set the alias name used for texture frame names
  868. @param name can be any sequence of characters and does not have to be unique
  869. */
  870. void setTextureNameAlias(const String& name);
  871. /** gets the Texture Name Alias of the Texture Unit.
  872. */
  873. const String& getTextureNameAlias(void) const { return mTextureNameAlias;}
  874. /** Applies texture names to Texture Unit State with matching texture name aliases.
  875. If no matching aliases are found then the TUS state does not change.
  876. @remarks
  877. Cubic, 1d, 2d, and 3d textures are determined from current state of the Texture Unit.
  878. Assumes animated frames are sequentially numbered in the name.
  879. If matching texture aliases are found then true is returned.
  880. @param
  881. aliasList is a map container of texture alias, texture name pairs
  882. @param
  883. apply set true to apply the texture aliases else just test to see if texture alias matches are found.
  884. @return
  885. True if matching texture aliases were found in the Texture Unit State.
  886. */
  887. bool applyTextureAliases(const AliasTextureNamePairList& aliasList, const bool apply = true);
  888. /** Notify this object that its parent has changed */
  889. void _notifyParent(Pass* parent);
  890. /** Get the texture pointer for the current frame. */
  891. const TexturePtr& _getTexturePtr(void) const;
  892. /** Get the texture pointer for a given frame. */
  893. const TexturePtr& _getTexturePtr(size_t frame) const;
  894. /** Set the texture pointer for the current frame (internal use only!). */
  895. void _setTexturePtr(const TexturePtr& texptr);
  896. /** Set the texture pointer for a given frame (internal use only!). */
  897. void _setTexturePtr(const TexturePtr& texptr, size_t frame);
  898. /** Gets the animation controller (as created because of setAnimatedTexture)
  899. if it exists.
  900. */
  901. Controller<Real>* _getAnimController() const { return mAnimController; }
  902. protected:
  903. // State
  904. /// The current animation frame.
  905. unsigned int mCurrentFrame;
  906. /// Duration of animation in seconds
  907. Real mAnimDuration;
  908. bool mCubic; // is this a series of 6 2D textures to make up a cube?
  909. TextureType mTextureType;
  910. PixelFormat mDesiredFormat;
  911. int mTextureSrcMipmaps; // Request number of mipmaps
  912. unsigned int mTextureCoordSetIndex;
  913. UVWAddressingMode mAddressMode;
  914. ColourValue mBorderColour;
  915. LayerBlendModeEx mColourBlendMode;
  916. SceneBlendFactor mColourBlendFallbackSrc;
  917. SceneBlendFactor mColourBlendFallbackDest;
  918. LayerBlendModeEx mAlphaBlendMode;
  919. mutable bool mTextureLoadFailed;
  920. bool mIsAlpha;
  921. bool mHwGamma;
  922. mutable bool mRecalcTexMatrix;
  923. Real mUMod, mVMod;
  924. Real mUScale, mVScale;
  925. Radian mRotate;
  926. mutable Matrix4 mTexModMatrix;
  927. /// Texture filtering - minification
  928. FilterOptions mMinFilter;
  929. /// Texture filtering - magnification
  930. FilterOptions mMagFilter;
  931. /// Texture filtering - mipmapping
  932. FilterOptions mMipFilter;
  933. ///Texture anisotropy
  934. unsigned int mMaxAniso;
  935. /// Mipmap bias (always float, not Real)
  936. float mMipmapBias;
  937. bool mIsDefaultAniso;
  938. bool mIsDefaultFiltering;
  939. /// Binding type (fragment or vertex pipeline)
  940. BindingType mBindingType;
  941. /// Content type of texture (normal loaded texture, auto-texture)
  942. ContentType mContentType;
  943. /// The index of the referenced texture if referencing an MRT in a compositor
  944. size_t mCompositorRefMrtIndex;
  945. //-----------------------------------------------------------------------------
  946. // Complex members (those that can't be copied using memcpy) are at the end to
  947. // allow for fast copying of the basic members.
  948. //
  949. vector<String>::type mFrames;
  950. mutable vector<TexturePtr>::type mFramePtrs;
  951. String mName; // optional name for the TUS
  952. String mTextureNameAlias; // optional alias for texture frames
  953. EffectMap mEffects;
  954. ///The data that references the compositor
  955. String mCompositorRefName;
  956. String mCompositorRefTexName;
  957. //-----------------------------------------------------------------------------
  958. //-----------------------------------------------------------------------------
  959. // Pointer members (those that can't be copied using memcpy), and MUST
  960. // preserving even if assign from others
  961. //
  962. Pass* mParent;
  963. Controller<Real>* mAnimController;
  964. //-----------------------------------------------------------------------------
  965. /** Internal method for calculating texture matrix.
  966. */
  967. void recalcTextureMatrix(void) const;
  968. /** Internal method for ensuring the texture for a given frame is prepared. */
  969. void ensurePrepared(size_t frame) const;
  970. /** Internal method for ensuring the texture for a given frame is loaded. */
  971. void ensureLoaded(size_t frame) const;
  972. };
  973. /** @} */
  974. /** @} */
  975. }
  976. #endif