IVideoDriver.h 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #pragma once
  5. #include "rect.h"
  6. #include "SColor.h"
  7. #include "IImage.h"
  8. #include "ITexture.h"
  9. #include "irrArray.h"
  10. #include "matrix4.h"
  11. #include "dimension2d.h"
  12. #include "position2d.h"
  13. #include "EDriverTypes.h"
  14. #include "EDriverFeatures.h"
  15. #include "EPrimitiveTypes.h"
  16. #include "EVideoTypes.h"
  17. #include "SExposedVideoData.h"
  18. #include "SOverrideMaterial.h"
  19. #include "S3DVertex.h" // E_VERTEX_TYPE
  20. #include "SVertexIndex.h" // E_INDEX_TYPE
  21. namespace irr
  22. {
  23. namespace io
  24. {
  25. class IAttributes;
  26. class IReadFile;
  27. class IWriteFile;
  28. } // end namespace io
  29. namespace scene
  30. {
  31. class IMeshBuffer;
  32. class IVertexBuffer;
  33. class IIndexBuffer;
  34. class IMesh;
  35. class IMeshManipulator;
  36. class ISceneNode;
  37. } // end namespace scene
  38. namespace video
  39. {
  40. class IImageLoader;
  41. class IImageWriter;
  42. class IMaterialRenderer;
  43. class IGPUProgrammingServices;
  44. class IRenderTarget;
  45. const c8 *const FogTypeNames[] = {
  46. "FogExp",
  47. "FogLinear",
  48. "FogExp2",
  49. 0,
  50. };
  51. struct SFrameStats {
  52. //! Number of draw calls
  53. u32 Drawcalls = 0;
  54. //! Count of primitives drawn
  55. u32 PrimitivesDrawn = 0;
  56. //! Number of hardware buffers uploaded (new or updated)
  57. u32 HWBuffersUploaded = 0;
  58. //! Sum of uploaded hardware buffer size
  59. u32 HWBuffersUploadedSize = 0;
  60. };
  61. //! Interface to driver which is able to perform 2d and 3d graphics functions.
  62. /** This interface is one of the most important interfaces of
  63. the Irrlicht Engine: All rendering and texture manipulation is done with
  64. this interface. You are able to use the Irrlicht Engine by only
  65. invoking methods of this interface if you like to, although the
  66. irr::scene::ISceneManager interface provides a lot of powerful classes
  67. and methods to make the programmer's life easier.
  68. */
  69. class IVideoDriver : public virtual IReferenceCounted
  70. {
  71. public:
  72. //! Applications must call this method before performing any rendering.
  73. /** This method can clear the back- and the z-buffer.
  74. \param clearFlag A combination of the E_CLEAR_BUFFER_FLAG bit-flags.
  75. \param clearColor The clear color for the color buffer.
  76. \param clearDepth The clear value for the depth buffer.
  77. \param clearStencil The clear value for the stencil buffer.
  78. \param videoData Handle of another window, if you want the
  79. bitmap to be displayed on another window. If this is an empty
  80. element, everything will be displayed in the default window.
  81. Note: This feature is not fully implemented for all devices.
  82. \param sourceRect Pointer to a rectangle defining the source
  83. rectangle of the area to be presented. Set to null to present
  84. everything. Note: not implemented in all devices.
  85. \return False if failed. */
  86. virtual bool beginScene(u16 clearFlag = (u16)(ECBF_COLOR | ECBF_DEPTH), SColor clearColor = SColor(255, 0, 0, 0), f32 clearDepth = 1.f, u8 clearStencil = 0,
  87. const SExposedVideoData &videoData = SExposedVideoData(), core::rect<s32> *sourceRect = 0) = 0;
  88. //! Alternative beginScene implementation. Can't clear stencil buffer, but otherwise identical to other beginScene
  89. bool beginScene(bool backBuffer, bool zBuffer, SColor color = SColor(255, 0, 0, 0),
  90. const SExposedVideoData &videoData = SExposedVideoData(), core::rect<s32> *sourceRect = 0)
  91. {
  92. u16 flag = 0;
  93. if (backBuffer)
  94. flag |= ECBF_COLOR;
  95. if (zBuffer)
  96. flag |= ECBF_DEPTH;
  97. return beginScene(flag, color, 1.f, 0, videoData, sourceRect);
  98. }
  99. //! Presents the rendered image to the screen.
  100. /** Applications must call this method after performing any
  101. rendering.
  102. \return False if failed and true if succeeded. */
  103. virtual bool endScene() = 0;
  104. //! Queries the features of the driver.
  105. /** Returns true if a feature is available
  106. \param feature Feature to query.
  107. \return True if the feature is available, false if not. */
  108. virtual bool queryFeature(E_VIDEO_DRIVER_FEATURE feature) const = 0;
  109. //! Disable a feature of the driver.
  110. /** Can also be used to enable the features again. It is not
  111. possible to enable unsupported features this way, though.
  112. \param feature Feature to disable.
  113. \param flag When true the feature is disabled, otherwise it is enabled. */
  114. virtual void disableFeature(E_VIDEO_DRIVER_FEATURE feature, bool flag = true) = 0;
  115. //! Get attributes of the actual video driver
  116. /** The following names can be queried for the given types:
  117. MaxTextures (int) The maximum number of simultaneous textures supported by the driver. This can be less than the supported number of textures of the driver. Use _IRR_MATERIAL_MAX_TEXTURES_ to adapt the number.
  118. MaxSupportedTextures (int) The maximum number of simultaneous textures supported by the fixed function pipeline of the (hw) driver. The actual supported number of textures supported by the engine can be lower.
  119. MaxLights (int) Number of hardware lights supported in the fixed function pipeline of the driver, typically 6-8. Use light manager or deferred shading for more.
  120. MaxAnisotropy (int) Number of anisotropy levels supported for filtering. At least 1, max is typically at 16 or 32.
  121. MaxAuxBuffers (int) Special render buffers, which are currently not really usable inside Irrlicht. Only supported by OpenGL
  122. MaxMultipleRenderTargets (int) Number of render targets which can be bound simultaneously. Rendering to MRTs is done via shaders.
  123. MaxIndices (int) Number of indices which can be used in one render call (i.e. one mesh buffer).
  124. MaxTextureSize (int) Dimension that a texture may have, both in width and height.
  125. MaxGeometryVerticesOut (int) Number of vertices the geometry shader can output in one pass. Only OpenGL so far.
  126. MaxTextureLODBias (float) Maximum value for LOD bias. Is usually at around 16, but can be lower on some systems.
  127. Version (int) Version of the driver. Should be Major*100+Minor
  128. ShaderLanguageVersion (int) Version of the high level shader language. Should be Major*100+Minor.
  129. AntiAlias (int) Number of Samples the driver uses for each pixel. 0 and 1 means anti aliasing is off, typical values are 2,4,8,16,32
  130. */
  131. virtual const io::IAttributes &getDriverAttributes() const = 0;
  132. //! Sets transformation matrices.
  133. /** \param state Transformation type to be set, e.g. view,
  134. world, or projection.
  135. \param mat Matrix describing the transformation. */
  136. virtual void setTransform(E_TRANSFORMATION_STATE state, const core::matrix4 &mat) = 0;
  137. //! Returns the transformation set by setTransform
  138. /** \param state Transformation type to query
  139. \return Matrix describing the transformation. */
  140. virtual const core::matrix4 &getTransform(E_TRANSFORMATION_STATE state) const = 0;
  141. //! Retrieve the number of image loaders
  142. /** \return Number of image loaders */
  143. virtual u32 getImageLoaderCount() const = 0;
  144. //! Retrieve the given image loader
  145. /** \param n The index of the loader to retrieve. This parameter is an 0-based
  146. array index.
  147. \return A pointer to the specified loader, 0 if the index is incorrect. */
  148. virtual IImageLoader *getImageLoader(u32 n) = 0;
  149. //! Retrieve the number of image writers
  150. /** \return Number of image writers */
  151. virtual u32 getImageWriterCount() const = 0;
  152. //! Retrieve the given image writer
  153. /** \param n The index of the writer to retrieve. This parameter is an 0-based
  154. array index.
  155. \return A pointer to the specified writer, 0 if the index is incorrect. */
  156. virtual IImageWriter *getImageWriter(u32 n) = 0;
  157. //! Sets a material.
  158. /** All 3d drawing functions will draw geometry using this material thereafter.
  159. \param material: Material to be used from now on. */
  160. virtual void setMaterial(const SMaterial &material) = 0;
  161. //! Get access to a named texture.
  162. /** Loads the texture from disk if it is not
  163. already loaded and generates mipmap levels if desired.
  164. Texture loading can be influenced using the
  165. setTextureCreationFlag() method. The texture can be in several
  166. imageformats, such as BMP, JPG, TGA, PCX, PNG, and PSD.
  167. \param filename Filename of the texture to be loaded.
  168. \return Pointer to the texture, or 0 if the texture
  169. could not be loaded. This pointer should not be dropped. See
  170. IReferenceCounted::drop() for more information. */
  171. virtual ITexture *getTexture(const io::path &filename) = 0;
  172. //! Get access to a named texture.
  173. /** Loads the texture from disk if it is not
  174. already loaded and generates mipmap levels if desired.
  175. Texture loading can be influenced using the
  176. setTextureCreationFlag() method. The texture can be in several
  177. imageformats, such as BMP, JPG, TGA, PCX, PNG, and PSD.
  178. \param file Pointer to an already opened file.
  179. \return Pointer to the texture, or 0 if the texture
  180. could not be loaded. This pointer should not be dropped. See
  181. IReferenceCounted::drop() for more information. */
  182. virtual ITexture *getTexture(io::IReadFile *file) = 0;
  183. //! Returns amount of textures currently loaded
  184. /** \return Amount of textures currently loaded */
  185. virtual u32 getTextureCount() const = 0;
  186. //! Creates an empty texture of specified size.
  187. /** \param size: Size of the texture.
  188. \param name A name for the texture. Later calls to
  189. getTexture() with this name will return this texture.
  190. The name can _not_ be empty.
  191. \param format Desired color format of the texture. Please note
  192. that the driver may choose to create the texture in another
  193. color format.
  194. \return Pointer to the newly created texture. This pointer
  195. should not be dropped. See IReferenceCounted::drop() for more
  196. information. */
  197. virtual ITexture *addTexture(const core::dimension2d<u32> &size,
  198. const io::path &name, ECOLOR_FORMAT format = ECF_A8R8G8B8) = 0;
  199. //! Creates a texture from an IImage.
  200. /** \param name A name for the texture. Later calls of
  201. getTexture() with this name will return this texture.
  202. The name can _not_ be empty.
  203. \param image Image the texture is created from.
  204. \return Pointer to the newly created texture. This pointer
  205. should not be dropped. See IReferenceCounted::drop() for more
  206. information. */
  207. virtual ITexture *addTexture(const io::path &name, IImage *image) = 0;
  208. //! Creates a cubemap texture from loaded IImages.
  209. /** \param name A name for the texture. Later calls of getTexture() with this name will return this texture.
  210. The name can _not_ be empty.
  211. \param imagePosX Image (positive X) the texture is created from.
  212. \param imageNegX Image (negative X) the texture is created from.
  213. \param imagePosY Image (positive Y) the texture is created from.
  214. \param imageNegY Image (negative Y) the texture is created from.
  215. \param imagePosZ Image (positive Z) the texture is created from.
  216. \param imageNegZ Image (negative Z) the texture is created from.
  217. \return Pointer to the newly created texture. This pointer should not be dropped. See IReferenceCounted::drop() for more information. */
  218. virtual ITexture *addTextureCubemap(const io::path &name, IImage *imagePosX, IImage *imageNegX, IImage *imagePosY,
  219. IImage *imageNegY, IImage *imagePosZ, IImage *imageNegZ) = 0;
  220. //! Creates an empty cubemap texture of specified size.
  221. /** \param sideLen diameter of one side of the cube
  222. \param name A name for the texture. Later calls of
  223. getTexture() with this name will return this texture.
  224. The name can _not_ be empty.
  225. \param format Desired color format of the texture. Please note
  226. that the driver may choose to create the texture in another
  227. color format.
  228. \return Pointer to the newly created texture. */
  229. virtual ITexture *addTextureCubemap(const irr::u32 sideLen, const io::path &name, ECOLOR_FORMAT format = ECF_A8R8G8B8) = 0;
  230. //! Adds a new render target texture to the texture cache.
  231. /** \param size Size of the texture, in pixels. Width and
  232. height should be a power of two (e.g. 64, 128, 256, 512, ...)
  233. and it should not be bigger than the backbuffer, because it
  234. shares the zbuffer with the screen buffer.
  235. \param name A name for the texture. Later calls of getTexture() with this name will return this texture.
  236. The name can _not_ be empty.
  237. \param format The color format of the render target. Floating point formats are supported.
  238. \return Pointer to the created texture or 0 if the texture
  239. could not be created. This pointer should not be dropped. See
  240. IReferenceCounted::drop() for more information.
  241. You may want to remove it from driver texture cache with removeTexture if you no longer need it.
  242. */
  243. virtual ITexture *addRenderTargetTexture(const core::dimension2d<u32> &size,
  244. const io::path &name = "rt", const ECOLOR_FORMAT format = ECF_UNKNOWN) = 0;
  245. //! Adds a new render target texture with 6 sides for a cubemap map to the texture cache.
  246. /** \param sideLen Length of one cubemap side.
  247. \param name A name for the texture. Later calls of getTexture() with this name will return this texture.
  248. The name can _not_ be empty.
  249. \param format The color format of the render target. Floating point formats are supported.
  250. \return Pointer to the created texture or 0 if the texture
  251. could not be created. This pointer should not be dropped. See
  252. IReferenceCounted::drop() for more information. */
  253. virtual ITexture *addRenderTargetTextureCubemap(const irr::u32 sideLen,
  254. const io::path &name = "rt", const ECOLOR_FORMAT format = ECF_UNKNOWN) = 0;
  255. //! Removes a texture from the texture cache and deletes it.
  256. /** This method can free a lot of memory!
  257. Please note that after calling this, the pointer to the
  258. ITexture may no longer be valid, if it was not grabbed before
  259. by other parts of the engine for storing it longer. So it is a
  260. good idea to set all materials which are using this texture to
  261. 0 or another texture first.
  262. \param texture Texture to delete from the engine cache. */
  263. virtual void removeTexture(ITexture *texture) = 0;
  264. //! Removes all textures from the texture cache and deletes them.
  265. /** This method can free a lot of memory!
  266. Please note that after calling this, the pointer to the
  267. ITexture may no longer be valid, if it was not grabbed before
  268. by other parts of the engine for storing it longer. So it is a
  269. good idea to set all materials which are using this texture to
  270. 0 or another texture first. */
  271. virtual void removeAllTextures() = 0;
  272. //! Remove hardware buffer
  273. virtual void removeHardwareBuffer(const scene::IVertexBuffer *vb) = 0;
  274. //! Remove hardware buffer
  275. virtual void removeHardwareBuffer(const scene::IIndexBuffer *ib) = 0;
  276. //! Remove all hardware buffers
  277. virtual void removeAllHardwareBuffers() = 0;
  278. //! Create occlusion query.
  279. /** Use node for identification and mesh for occlusion test. */
  280. virtual void addOcclusionQuery(scene::ISceneNode *node,
  281. const scene::IMesh *mesh = 0) = 0;
  282. //! Remove occlusion query.
  283. virtual void removeOcclusionQuery(scene::ISceneNode *node) = 0;
  284. //! Remove all occlusion queries.
  285. virtual void removeAllOcclusionQueries() = 0;
  286. //! Run occlusion query. Draws mesh stored in query.
  287. /** If the mesh shall not be rendered visible, use
  288. overrideMaterial to disable the color and depth buffer. */
  289. virtual void runOcclusionQuery(scene::ISceneNode *node, bool visible = false) = 0;
  290. //! Run all occlusion queries. Draws all meshes stored in queries.
  291. /** If the meshes shall not be rendered visible, use
  292. overrideMaterial to disable the color and depth buffer. */
  293. virtual void runAllOcclusionQueries(bool visible = false) = 0;
  294. //! Update occlusion query. Retrieves results from GPU.
  295. /** If the query shall not block, set the flag to false.
  296. Update might not occur in this case, though */
  297. virtual void updateOcclusionQuery(scene::ISceneNode *node, bool block = true) = 0;
  298. //! Update all occlusion queries. Retrieves results from GPU.
  299. /** If the query shall not block, set the flag to false.
  300. Update might not occur in this case, though */
  301. virtual void updateAllOcclusionQueries(bool block = true) = 0;
  302. //! Return query result.
  303. /** Return value is the number of visible pixels/fragments.
  304. The value is a safe approximation, i.e. can be larger than the
  305. actual value of pixels. */
  306. virtual u32 getOcclusionQueryResult(scene::ISceneNode *node) const = 0;
  307. //! Create render target.
  308. virtual IRenderTarget *addRenderTarget() = 0;
  309. //! Remove render target.
  310. virtual void removeRenderTarget(IRenderTarget *renderTarget) = 0;
  311. //! Remove all render targets.
  312. virtual void removeAllRenderTargets() = 0;
  313. //! Sets a boolean alpha channel on the texture based on a color key.
  314. /** This makes the texture fully transparent at the texels where
  315. this color key can be found when using for example draw2DImage
  316. with useAlphachannel==true. The alpha of other texels is not modified.
  317. \param texture Texture whose alpha channel is modified.
  318. \param color Color key color. Every texel with this color will
  319. become fully transparent as described above. Please note that the
  320. colors of a texture may be converted when loading it, so the
  321. color values may not be exactly the same in the engine and for
  322. example in picture edit programs. To avoid this problem, you
  323. could use the makeColorKeyTexture method, which takes the
  324. position of a pixel instead a color value. */
  325. virtual void makeColorKeyTexture(video::ITexture *texture,
  326. video::SColor color) const = 0;
  327. //! Sets a boolean alpha channel on the texture based on the color at a position.
  328. /** This makes the texture fully transparent at the texels where
  329. the color key can be found when using for example draw2DImage
  330. with useAlphachannel==true. The alpha of other texels is not modified.
  331. \param texture Texture whose alpha channel is modified.
  332. \param colorKeyPixelPos Position of a pixel with the color key
  333. color. Every texel with this color will become fully transparent as
  334. described above. */
  335. virtual void makeColorKeyTexture(video::ITexture *texture,
  336. core::position2d<s32> colorKeyPixelPos) const = 0;
  337. //! Set a render target.
  338. /** This will only work if the driver supports the
  339. EVDF_RENDER_TO_TARGET feature, which can be queried with
  340. queryFeature(). Please note that you cannot render 3D or 2D
  341. geometry with a render target as texture on it when you are rendering
  342. the scene into this render target at the same time. It is usually only
  343. possible to render into a texture between the
  344. IVideoDriver::beginScene() and endScene() method calls. If you need the
  345. best performance use this method instead of setRenderTarget.
  346. \param target Render target object. If set to nullptr, it makes the
  347. window the current render target.
  348. \param clearFlag A combination of the E_CLEAR_BUFFER_FLAG bit-flags.
  349. \param clearColor The clear color for the color buffer.
  350. \param clearDepth The clear value for the depth buffer.
  351. \param clearStencil The clear value for the stencil buffer.
  352. \return True if successful and false if not. */
  353. virtual bool setRenderTargetEx(IRenderTarget *target, u16 clearFlag, SColor clearColor = SColor(255, 0, 0, 0),
  354. f32 clearDepth = 1.f, u8 clearStencil = 0) = 0;
  355. //! Sets a new render target.
  356. /** This will only work if the driver supports the
  357. EVDF_RENDER_TO_TARGET feature, which can be queried with
  358. queryFeature(). Usually, rendering to textures is done in this
  359. way:
  360. \code
  361. // create render target
  362. ITexture* target = driver->addRenderTargetTexture(core::dimension2d<u32>(128,128), "rtt1");
  363. // ...
  364. driver->setRenderTarget(target); // set render target
  365. // .. draw stuff here
  366. driver->setRenderTarget(0); // set previous render target
  367. \endcode
  368. Please note that you cannot render 3D or 2D geometry with a
  369. render target as texture on it when you are rendering the scene
  370. into this render target at the same time. It is usually only
  371. possible to render into a texture between the
  372. IVideoDriver::beginScene() and endScene() method calls.
  373. \param texture New render target. Must be a texture created with
  374. IVideoDriver::addRenderTargetTexture(). If set to nullptr, it makes
  375. the window the current render target.
  376. \param clearFlag A combination of the E_CLEAR_BUFFER_FLAG bit-flags.
  377. \param clearColor The clear color for the color buffer.
  378. \param clearDepth The clear value for the depth buffer.
  379. \param clearStencil The clear value for the stencil buffer.
  380. \return True if successful and false if not. */
  381. virtual bool setRenderTarget(ITexture *texture, u16 clearFlag = ECBF_COLOR | ECBF_DEPTH, SColor clearColor = SColor(255, 0, 0, 0),
  382. f32 clearDepth = 1.f, u8 clearStencil = 0) = 0;
  383. //! Sets a new render target.
  384. //! Prefer to use the setRenderTarget function taking flags as parameter as this one can't clear the stencil buffer.
  385. //! It's still offered for backward compatibility.
  386. bool setRenderTarget(ITexture *texture, bool clearBackBuffer, bool clearZBuffer, SColor color = SColor(255, 0, 0, 0))
  387. {
  388. u16 flag = 0;
  389. if (clearBackBuffer)
  390. flag |= ECBF_COLOR;
  391. if (clearZBuffer)
  392. flag |= ECBF_DEPTH;
  393. return setRenderTarget(texture, flag, color);
  394. }
  395. //! Sets a new viewport.
  396. /** Every rendering operation is done into this new area.
  397. \param area: Rectangle defining the new area of rendering
  398. operations. */
  399. virtual void setViewPort(const core::rect<s32> &area) = 0;
  400. //! Gets the area of the current viewport.
  401. /** \return Rectangle of the current viewport. */
  402. virtual const core::rect<s32> &getViewPort() const = 0;
  403. //! Draws a vertex primitive list
  404. /** Note that, depending on the index type, some vertices might be not
  405. accessible through the index list. The limit is at 65535 vertices for 16bit
  406. indices. Please note that currently not all primitives are available for
  407. all drivers, and some might be emulated via triangle renders.
  408. \param vertices Pointer to array of vertices.
  409. \param vertexCount Amount of vertices in the array.
  410. \param indexList Pointer to array of indices. These define the vertices used
  411. for each primitive. Depending on the pType, indices are interpreted as single
  412. objects (for point like primitives), pairs (for lines), triplets (for
  413. triangles), or quads.
  414. \param primCount Amount of Primitives
  415. \param vType Vertex type, e.g. video::EVT_STANDARD for S3DVertex.
  416. \param pType Primitive type, e.g. scene::EPT_TRIANGLE_FAN for a triangle fan.
  417. \param iType Index type, e.g. video::EIT_16BIT for 16bit indices. */
  418. virtual void drawVertexPrimitiveList(const void *vertices, u32 vertexCount,
  419. const void *indexList, u32 primCount,
  420. E_VERTEX_TYPE vType = EVT_STANDARD,
  421. scene::E_PRIMITIVE_TYPE pType = scene::EPT_TRIANGLES,
  422. E_INDEX_TYPE iType = EIT_16BIT) = 0;
  423. //! Draws a vertex primitive list in 2d
  424. /** Compared to the general (3d) version of this method, this
  425. one sets up a 2d render mode, and uses only x and y of vectors.
  426. Note that, depending on the index type, some vertices might be
  427. not accessible through the index list. The limit is at 65535
  428. vertices for 16bit indices. Please note that currently not all
  429. primitives are available for all drivers, and some might be
  430. emulated via triangle renders. This function is not available
  431. for the sw drivers.
  432. \param vertices Pointer to array of vertices.
  433. \param vertexCount Amount of vertices in the array.
  434. \param indexList Pointer to array of indices. These define the
  435. vertices used for each primitive. Depending on the pType,
  436. indices are interpreted as single objects (for point like
  437. primitives), pairs (for lines), triplets (for triangles), or
  438. quads.
  439. \param primCount Amount of Primitives
  440. \param vType Vertex type, e.g. video::EVT_STANDARD for S3DVertex.
  441. \param pType Primitive type, e.g. scene::EPT_TRIANGLE_FAN for a triangle fan.
  442. \param iType Index type, e.g. video::EIT_16BIT for 16bit indices. */
  443. virtual void draw2DVertexPrimitiveList(const void *vertices, u32 vertexCount,
  444. const void *indexList, u32 primCount,
  445. E_VERTEX_TYPE vType = EVT_STANDARD,
  446. scene::E_PRIMITIVE_TYPE pType = scene::EPT_TRIANGLES,
  447. E_INDEX_TYPE iType = EIT_16BIT) = 0;
  448. //! Draws an indexed triangle list.
  449. /** Note that there may be at maximum 65536 vertices, because
  450. the index list is an array of 16 bit values each with a maximum
  451. value of 65536. If there are more than 65536 vertices in the
  452. list, results of this operation are not defined.
  453. \param vertices Pointer to array of vertices.
  454. \param vertexCount Amount of vertices in the array.
  455. \param indexList Pointer to array of indices.
  456. \param triangleCount Amount of Triangles. Usually amount of indices / 3. */
  457. void drawIndexedTriangleList(const S3DVertex *vertices,
  458. u32 vertexCount, const u16 *indexList, u32 triangleCount)
  459. {
  460. drawVertexPrimitiveList(vertices, vertexCount, indexList, triangleCount, EVT_STANDARD, scene::EPT_TRIANGLES, EIT_16BIT);
  461. }
  462. //! Draws an indexed triangle list.
  463. /** Note that there may be at maximum 65536 vertices, because
  464. the index list is an array of 16 bit values each with a maximum
  465. value of 65536. If there are more than 65536 vertices in the
  466. list, results of this operation are not defined.
  467. \param vertices Pointer to array of vertices.
  468. \param vertexCount Amount of vertices in the array.
  469. \param indexList Pointer to array of indices.
  470. \param triangleCount Amount of Triangles. Usually amount of indices / 3. */
  471. void drawIndexedTriangleList(const S3DVertex2TCoords *vertices,
  472. u32 vertexCount, const u16 *indexList, u32 triangleCount)
  473. {
  474. drawVertexPrimitiveList(vertices, vertexCount, indexList, triangleCount, EVT_2TCOORDS, scene::EPT_TRIANGLES, EIT_16BIT);
  475. }
  476. //! Draws an indexed triangle list.
  477. /** Note that there may be at maximum 65536 vertices, because
  478. the index list is an array of 16 bit values each with a maximum
  479. value of 65536. If there are more than 65536 vertices in the
  480. list, results of this operation are not defined.
  481. \param vertices Pointer to array of vertices.
  482. \param vertexCount Amount of vertices in the array.
  483. \param indexList Pointer to array of indices.
  484. \param triangleCount Amount of Triangles. Usually amount of indices / 3. */
  485. void drawIndexedTriangleList(const S3DVertexTangents *vertices,
  486. u32 vertexCount, const u16 *indexList, u32 triangleCount)
  487. {
  488. drawVertexPrimitiveList(vertices, vertexCount, indexList, triangleCount, EVT_TANGENTS, scene::EPT_TRIANGLES, EIT_16BIT);
  489. }
  490. //! Draws an indexed triangle fan.
  491. /** Note that there may be at maximum 65536 vertices, because
  492. the index list is an array of 16 bit values each with a maximum
  493. value of 65536. If there are more than 65536 vertices in the
  494. list, results of this operation are not defined.
  495. \param vertices Pointer to array of vertices.
  496. \param vertexCount Amount of vertices in the array.
  497. \param indexList Pointer to array of indices.
  498. \param triangleCount Amount of Triangles. Usually amount of indices - 2. */
  499. void drawIndexedTriangleFan(const S3DVertex *vertices,
  500. u32 vertexCount, const u16 *indexList, u32 triangleCount)
  501. {
  502. drawVertexPrimitiveList(vertices, vertexCount, indexList, triangleCount, EVT_STANDARD, scene::EPT_TRIANGLE_FAN, EIT_16BIT);
  503. }
  504. //! Draws an indexed triangle fan.
  505. /** Note that there may be at maximum 65536 vertices, because
  506. the index list is an array of 16 bit values each with a maximum
  507. value of 65536. If there are more than 65536 vertices in the
  508. list, results of this operation are not defined.
  509. \param vertices Pointer to array of vertices.
  510. \param vertexCount Amount of vertices in the array.
  511. \param indexList Pointer to array of indices.
  512. \param triangleCount Amount of Triangles. Usually amount of indices - 2. */
  513. void drawIndexedTriangleFan(const S3DVertex2TCoords *vertices,
  514. u32 vertexCount, const u16 *indexList, u32 triangleCount)
  515. {
  516. drawVertexPrimitiveList(vertices, vertexCount, indexList, triangleCount, EVT_2TCOORDS, scene::EPT_TRIANGLE_FAN, EIT_16BIT);
  517. }
  518. //! Draws an indexed triangle fan.
  519. /** Note that there may be at maximum 65536 vertices, because
  520. the index list is an array of 16 bit values each with a maximum
  521. value of 65536. If there are more than 65536 vertices in the
  522. list, results of this operation are not defined.
  523. \param vertices Pointer to array of vertices.
  524. \param vertexCount Amount of vertices in the array.
  525. \param indexList Pointer to array of indices.
  526. \param triangleCount Amount of Triangles. Usually amount of indices - 2. */
  527. void drawIndexedTriangleFan(const S3DVertexTangents *vertices,
  528. u32 vertexCount, const u16 *indexList, u32 triangleCount)
  529. {
  530. drawVertexPrimitiveList(vertices, vertexCount, indexList, triangleCount, EVT_TANGENTS, scene::EPT_TRIANGLE_FAN, EIT_16BIT);
  531. }
  532. //! Draws a 3d line.
  533. /** For some implementations, this method simply calls
  534. drawVertexPrimitiveList for some triangles.
  535. Note that the line is drawn using the current transformation
  536. matrix and material. So if you need to draw the 3D line
  537. independently of the current transformation, use
  538. \code
  539. driver->setMaterial(someMaterial);
  540. driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
  541. \endcode
  542. for some properly set up material before drawing the line.
  543. Some drivers support line thickness set in the material.
  544. \param start Start of the 3d line.
  545. \param end End of the 3d line.
  546. \param color Color of the line. */
  547. virtual void draw3DLine(const core::vector3df &start,
  548. const core::vector3df &end, SColor color = SColor(255, 255, 255, 255)) = 0;
  549. //! Draws a 3d axis aligned box.
  550. /** This method simply calls draw3DLine for the edges of the
  551. box. Note that the box is drawn using the current transformation
  552. matrix and material. So if you need to draw it independently of
  553. the current transformation, use
  554. \code
  555. driver->setMaterial(someMaterial);
  556. driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
  557. \endcode
  558. for some properly set up material before drawing the box.
  559. \param box The axis aligned box to draw
  560. \param color Color to use while drawing the box. */
  561. virtual void draw3DBox(const core::aabbox3d<f32> &box,
  562. SColor color = SColor(255, 255, 255, 255)) = 0;
  563. //! Draws a 2d image without any special effects
  564. /** \param texture Pointer to texture to use.
  565. \param destPos Upper left 2d destination position where the
  566. image will be drawn.
  567. \param useAlphaChannelOfTexture: If true, the alpha channel of
  568. the texture is used to draw the image.*/
  569. virtual void draw2DImage(const video::ITexture *texture,
  570. const core::position2d<s32> &destPos, bool useAlphaChannelOfTexture = false) = 0;
  571. //! Draws a 2d image using a color
  572. /** (if color is other than
  573. Color(255,255,255,255)) and the alpha channel of the texture.
  574. \param texture Texture to be drawn.
  575. \param destPos Upper left 2d destination position where the
  576. image will be drawn.
  577. \param sourceRect Source rectangle in the texture (based on it's OriginalSize)
  578. \param clipRect Pointer to rectangle on the screen where the
  579. image is clipped to.
  580. If this pointer is NULL the image is not clipped.
  581. \param color Color with which the image is drawn. If the color
  582. equals Color(255,255,255,255) it is ignored. Note that the
  583. alpha component is used: If alpha is other than 255, the image
  584. will be transparent.
  585. \param useAlphaChannelOfTexture: If true, the alpha channel of
  586. the texture is used to draw the image.*/
  587. virtual void draw2DImage(const video::ITexture *texture, const core::position2d<s32> &destPos,
  588. const core::rect<s32> &sourceRect, const core::rect<s32> *clipRect = 0,
  589. SColor color = SColor(255, 255, 255, 255), bool useAlphaChannelOfTexture = false) = 0;
  590. //! Draws a set of 2d images, using a color and the alpha channel of the texture.
  591. /** All drawings are clipped against clipRect (if != 0).
  592. The subtextures are defined by the array of sourceRects and are
  593. positioned using the array of positions.
  594. \param texture Texture to be drawn.
  595. \param positions Array of upper left 2d destinations where the
  596. images will be drawn.
  597. \param sourceRects Source rectangles of the texture (based on it's OriginalSize)
  598. \param clipRect Pointer to rectangle on the screen where the
  599. images are clipped to.
  600. If this pointer is 0 then the image is not clipped.
  601. \param color Color with which the image is drawn.
  602. Note that the alpha component is used. If alpha is other than
  603. 255, the image will be transparent.
  604. \param useAlphaChannelOfTexture: If true, the alpha channel of
  605. the texture is used to draw the image. */
  606. virtual void draw2DImageBatch(const video::ITexture *texture,
  607. const core::array<core::position2d<s32>> &positions,
  608. const core::array<core::rect<s32>> &sourceRects,
  609. const core::rect<s32> *clipRect = 0,
  610. SColor color = SColor(255, 255, 255, 255),
  611. bool useAlphaChannelOfTexture = false) = 0;
  612. //! Draws a part of the texture into the rectangle. Note that colors must be an array of 4 colors if used.
  613. /** Suggested and first implemented by zola.
  614. \param texture The texture to draw from
  615. \param destRect The rectangle to draw into
  616. \param sourceRect The rectangle denoting a part of the texture (based on it's OriginalSize)
  617. \param clipRect Clips the destination rectangle (may be 0)
  618. \param colors Array of 4 colors denoting the color values of
  619. the corners of the destRect
  620. \param useAlphaChannelOfTexture True if alpha channel will be
  621. blended. */
  622. virtual void draw2DImage(const video::ITexture *texture, const core::rect<s32> &destRect,
  623. const core::rect<s32> &sourceRect, const core::rect<s32> *clipRect = 0,
  624. const video::SColor *const colors = 0, bool useAlphaChannelOfTexture = false) = 0;
  625. //! Draws a 2d rectangle.
  626. /** \param color Color of the rectangle to draw. The alpha
  627. component will not be ignored and specifies how transparent the
  628. rectangle will be.
  629. \param pos Position of the rectangle.
  630. \param clip Pointer to rectangle against which the rectangle
  631. will be clipped. If the pointer is null, no clipping will be
  632. performed. */
  633. virtual void draw2DRectangle(SColor color, const core::rect<s32> &pos,
  634. const core::rect<s32> *clip = 0) = 0;
  635. //! Draws a 2d rectangle with a gradient.
  636. /** \param colorLeftUp Color of the upper left corner to draw.
  637. The alpha component will not be ignored and specifies how
  638. transparent the rectangle will be.
  639. \param colorRightUp Color of the upper right corner to draw.
  640. The alpha component will not be ignored and specifies how
  641. transparent the rectangle will be.
  642. \param colorLeftDown Color of the lower left corner to draw.
  643. The alpha component will not be ignored and specifies how
  644. transparent the rectangle will be.
  645. \param colorRightDown Color of the lower right corner to draw.
  646. The alpha component will not be ignored and specifies how
  647. transparent the rectangle will be.
  648. \param pos Position of the rectangle.
  649. \param clip Pointer to rectangle against which the rectangle
  650. will be clipped. If the pointer is null, no clipping will be
  651. performed. */
  652. virtual void draw2DRectangle(const core::rect<s32> &pos,
  653. SColor colorLeftUp, SColor colorRightUp,
  654. SColor colorLeftDown, SColor colorRightDown,
  655. const core::rect<s32> *clip = 0) = 0;
  656. //! Draws a 2d line.
  657. /** In theory both start and end will be included in coloring.
  658. BUG: Currently d3d ignores the last pixel
  659. (it uses the so called "diamond exit rule" for drawing lines).
  660. \param start Screen coordinates of the start of the line
  661. in pixels.
  662. \param end Screen coordinates of the start of the line in
  663. pixels.
  664. \param color Color of the line to draw. */
  665. virtual void draw2DLine(const core::position2d<s32> &start,
  666. const core::position2d<s32> &end,
  667. SColor color = SColor(255, 255, 255, 255)) = 0;
  668. //! Draws a mesh buffer
  669. /** \param mb Buffer to draw */
  670. virtual void drawMeshBuffer(const scene::IMeshBuffer *mb) = 0;
  671. /**
  672. * Draws a mesh from individual vertex and index buffers.
  673. * @param vb vertices to use
  674. * @param ib indices to use
  675. * @param primCount amount of primitives
  676. * @param pType primitive type
  677. */
  678. virtual void drawBuffers(const scene::IVertexBuffer *vb,
  679. const scene::IIndexBuffer *ib, u32 primCount,
  680. scene::E_PRIMITIVE_TYPE pType = scene::EPT_TRIANGLES) = 0;
  681. //! Draws normals of a mesh buffer
  682. /** \param mb Buffer to draw the normals of
  683. \param length length scale factor of the normals
  684. \param color Color the normals are rendered with
  685. */
  686. virtual void drawMeshBufferNormals(const scene::IMeshBuffer *mb, f32 length = 10.f, SColor color = 0xffffffff) = 0;
  687. //! Sets the fog mode.
  688. /** These are global values attached to each 3d object rendered,
  689. which has the fog flag enabled in its material.
  690. \param color Color of the fog
  691. \param fogType Type of fog used
  692. \param start Only used in linear fog mode (linearFog=true).
  693. Specifies where fog starts.
  694. \param end Only used in linear fog mode (linearFog=true).
  695. Specifies where fog ends.
  696. \param density Only used in exponential fog mode
  697. (linearFog=false). Must be a value between 0 and 1.
  698. \param pixelFog Set this to false for vertex fog, and true if
  699. you want per-pixel fog.
  700. \param rangeFog Set this to true to enable range-based vertex
  701. fog. The distance from the viewer is used to compute the fog,
  702. not the z-coordinate. This is better, but slower. This might not
  703. be available with all drivers and fog settings. */
  704. virtual void setFog(SColor color = SColor(0, 255, 255, 255),
  705. E_FOG_TYPE fogType = EFT_FOG_LINEAR,
  706. f32 start = 50.0f, f32 end = 100.0f, f32 density = 0.01f,
  707. bool pixelFog = false, bool rangeFog = false) = 0;
  708. //! Gets the fog mode.
  709. virtual void getFog(SColor &color, E_FOG_TYPE &fogType,
  710. f32 &start, f32 &end, f32 &density,
  711. bool &pixelFog, bool &rangeFog) = 0;
  712. //! Get the current color format of the color buffer
  713. /** \return Color format of the color buffer. */
  714. virtual ECOLOR_FORMAT getColorFormat() const = 0;
  715. //! Get the size of the screen or render window.
  716. /** \return Size of screen or render window. */
  717. virtual const core::dimension2d<u32> &getScreenSize() const = 0;
  718. //! Get the size of the current render target
  719. /** This method will return the screen size if the driver
  720. doesn't support render to texture, or if the current render
  721. target is the screen.
  722. \return Size of render target or screen/window */
  723. virtual const core::dimension2d<u32> &getCurrentRenderTargetSize() const = 0;
  724. //! Returns current frames per second value.
  725. /** This value is updated approximately every 1.5 seconds and
  726. is only intended to provide a rough guide to the average frame
  727. rate. It is not suitable for use in performing timing
  728. calculations or framerate independent movement.
  729. \return Approximate amount of frames per second drawn. */
  730. virtual s32 getFPS() const = 0;
  731. //! Return some statistics about the last frame
  732. virtual SFrameStats getFrameStats() const = 0;
  733. //! Gets name of this video driver.
  734. /** \return Returns the name of the video driver, e.g. in case
  735. of the Direct3D8 driver, it would return "Direct3D 8.1". */
  736. virtual const char *getName() const = 0;
  737. //! Adds an external image loader to the engine.
  738. /** This is useful if the Irrlicht Engine should be able to load
  739. textures of currently unsupported file formats (e.g. gif). The
  740. IImageLoader only needs to be implemented for loading this file
  741. format. A pointer to the implementation can be passed to the
  742. engine using this method.
  743. \param loader Pointer to the external loader created. */
  744. virtual void addExternalImageLoader(IImageLoader *loader) = 0;
  745. //! Adds an external image writer to the engine.
  746. /** This is useful if the Irrlicht Engine should be able to
  747. write textures of currently unsupported file formats (e.g
  748. .gif). The IImageWriter only needs to be implemented for
  749. writing this file format. A pointer to the implementation can
  750. be passed to the engine using this method.
  751. \param writer: Pointer to the external writer created. */
  752. virtual void addExternalImageWriter(IImageWriter *writer) = 0;
  753. //! Returns the maximum amount of primitives
  754. /** (mostly vertices) which the device is able to render with
  755. one drawVertexPrimitiveList call.
  756. \return Maximum amount of primitives. */
  757. virtual u32 getMaximalPrimitiveCount() const = 0;
  758. //! Enables or disables a texture creation flag.
  759. /** These flags define how textures should be created. By
  760. changing this value, you can influence for example the speed of
  761. rendering a lot. But please note that the video drivers take
  762. this value only as recommendation. It could happen that you
  763. enable the ETCF_ALWAYS_16_BIT mode, but the driver still creates
  764. 32 bit textures.
  765. \param flag Texture creation flag.
  766. \param enabled Specifies if the given flag should be enabled or
  767. disabled. */
  768. virtual void setTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag, bool enabled = true) = 0;
  769. //! Returns if a texture creation flag is enabled or disabled.
  770. /** You can change this value using setTextureCreationFlag().
  771. \param flag Texture creation flag.
  772. \return The current texture creation flag enabled mode. */
  773. virtual bool getTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag) const = 0;
  774. //! Creates a software image from a file.
  775. /** No hardware texture will be created for this image. This
  776. method is useful for example if you want to read a heightmap
  777. for a terrain renderer.
  778. \param filename Name of the file from which the image is
  779. created.
  780. \return The created image.
  781. If you no longer need the image, you should call IImage::drop().
  782. See IReferenceCounted::drop() for more information. */
  783. virtual IImage *createImageFromFile(const io::path &filename) = 0;
  784. //! Creates a software image from a file.
  785. /** No hardware texture will be created for this image. This
  786. method is useful for example if you want to read a heightmap
  787. for a terrain renderer.
  788. \param file File from which the image is created.
  789. \return The created image.
  790. If you no longer need the image, you should call IImage::drop().
  791. See IReferenceCounted::drop() for more information. */
  792. virtual IImage *createImageFromFile(io::IReadFile *file) = 0;
  793. //! Writes the provided image to a file.
  794. /** Requires that there is a suitable image writer registered
  795. for writing the image.
  796. \param image Image to write.
  797. \param filename Name of the file to write.
  798. \param param Control parameter for the backend (e.g. compression
  799. level).
  800. \return True on successful write. */
  801. virtual bool writeImageToFile(IImage *image, const io::path &filename, u32 param = 0) = 0;
  802. //! Writes the provided image to a file.
  803. /** Requires that there is a suitable image writer registered
  804. for writing the image.
  805. \param image Image to write.
  806. \param file An already open io::IWriteFile object. The name
  807. will be used to determine the appropriate image writer to use.
  808. \param param Control parameter for the backend (e.g. compression
  809. level).
  810. \return True on successful write. */
  811. virtual bool writeImageToFile(IImage *image, io::IWriteFile *file, u32 param = 0) = 0;
  812. //! Creates a software image from a byte array.
  813. /** No hardware texture will be created for this image. This
  814. method is useful for example if you want to read a heightmap
  815. for a terrain renderer.
  816. \param format Desired color format of the texture
  817. \param size Desired size of the image
  818. \param data A byte array with pixel color information
  819. \param ownForeignMemory If true, the image will use the data
  820. pointer directly and own it afterward. If false, the memory
  821. will by copied internally.
  822. WARNING: Setting this to 'true' will not work across dll boundaries.
  823. So unless you link Irrlicht statically you should keep this to 'false'.
  824. The parameter is mainly for internal usage.
  825. \param deleteMemory Whether the memory is deallocated upon
  826. destruction.
  827. \return The created image.
  828. If you no longer need the image, you should call IImage::drop().
  829. See IReferenceCounted::drop() for more information. */
  830. virtual IImage *createImageFromData(ECOLOR_FORMAT format,
  831. const core::dimension2d<u32> &size, void *data, bool ownForeignMemory = false,
  832. bool deleteMemory = true) = 0;
  833. //! Creates an empty software image.
  834. /**
  835. \param format Desired color format of the image.
  836. \param size Size of the image to create.
  837. \return The created image.
  838. If you no longer need the image, you should call IImage::drop().
  839. See IReferenceCounted::drop() for more information. */
  840. virtual IImage *createImage(ECOLOR_FORMAT format, const core::dimension2d<u32> &size) = 0;
  841. //! Creates a software image from a part of a texture.
  842. /**
  843. \param texture Texture to copy to the new image in part.
  844. \param pos Position of rectangle to copy.
  845. \param size Extents of rectangle to copy.
  846. \return The created image.
  847. If you no longer need the image, you should call IImage::drop().
  848. See IReferenceCounted::drop() for more information. */
  849. virtual IImage *createImage(ITexture *texture,
  850. const core::position2d<s32> &pos,
  851. const core::dimension2d<u32> &size) = 0;
  852. //! Event handler for resize events. Only used by the engine internally.
  853. /** Used to notify the driver that the window was resized.
  854. Usually, there is no need to call this method. */
  855. virtual void OnResize(const core::dimension2d<u32> &size) = 0;
  856. //! Adds a new material renderer to the video device.
  857. /** Use this method to extend the VideoDriver with new material
  858. types. To extend the engine using this method do the following:
  859. Derive a class from IMaterialRenderer and override the methods
  860. you need. For setting the right renderstates, you can try to
  861. get a pointer to the real rendering device using
  862. IVideoDriver::getExposedVideoData(). Add your class with
  863. IVideoDriver::addMaterialRenderer(). To use an object being
  864. displayed with your new material, set the MaterialType member of
  865. the SMaterial struct to the value returned by this method.
  866. If you simply want to create a new material using vertex and/or
  867. pixel shaders it would be easier to use the
  868. video::IGPUProgrammingServices interface which you can get
  869. using the getGPUProgrammingServices() method.
  870. \param renderer A pointer to the new renderer.
  871. \param name Optional name for the material renderer entry.
  872. \return The number of the material type which can be set in
  873. SMaterial::MaterialType to use the renderer. -1 is returned if
  874. an error occurred. For example if you tried to add an material
  875. renderer to the software renderer or the null device, which do
  876. not accept material renderers. */
  877. virtual s32 addMaterialRenderer(IMaterialRenderer *renderer, const c8 *name = 0) = 0;
  878. //! Get access to a material renderer by index.
  879. /** \param idx Id of the material renderer. Can be a value of
  880. the E_MATERIAL_TYPE enum or a value which was returned by
  881. addMaterialRenderer().
  882. \return Pointer to material renderer or null if not existing. */
  883. virtual IMaterialRenderer *getMaterialRenderer(u32 idx) const = 0;
  884. //! Get amount of currently available material renderers.
  885. /** \return Amount of currently available material renderers. */
  886. virtual u32 getMaterialRendererCount() const = 0;
  887. //! Get name of a material renderer
  888. /** This string can, e.g., be used to test if a specific
  889. renderer already has been registered/created, or use this
  890. string to store data about materials: This returned name will
  891. be also used when serializing materials.
  892. \param idx Id of the material renderer. Can be a value of the
  893. E_MATERIAL_TYPE enum or a value which was returned by
  894. addMaterialRenderer().
  895. \return String with the name of the renderer, or 0 if not
  896. existing */
  897. virtual const c8 *getMaterialRendererName(u32 idx) const = 0;
  898. //! Sets the name of a material renderer.
  899. /** Will have no effect on built-in material renderers.
  900. \param idx: Id of the material renderer. Can be a value of the
  901. E_MATERIAL_TYPE enum or a value which was returned by
  902. addMaterialRenderer().
  903. \param name: New name of the material renderer. */
  904. virtual void setMaterialRendererName(u32 idx, const c8 *name) = 0;
  905. //! Swap the material renderers used for certain id's
  906. /** Swap the IMaterialRenderers responsible for rendering specific
  907. material-id's. This means every SMaterial using a MaterialType
  908. with one of the indices involved here will now render differently.
  909. \param idx1 First material index to swap. It must already exist or nothing happens.
  910. \param idx2 Second material index to swap. It must already exist or nothing happens.
  911. \param swapNames When true the renderer names also swap
  912. When false the names will stay at the original index */
  913. virtual void swapMaterialRenderers(u32 idx1, u32 idx2, bool swapNames = true) = 0;
  914. //! Returns driver and operating system specific data about the IVideoDriver.
  915. /** This method should only be used if the engine should be
  916. extended without having to modify the source of the engine.
  917. \return Collection of device dependent pointers. */
  918. virtual const SExposedVideoData &getExposedVideoData() = 0;
  919. //! Get type of video driver
  920. /** \return Type of driver. */
  921. virtual E_DRIVER_TYPE getDriverType() const = 0;
  922. //! Gets the IGPUProgrammingServices interface.
  923. /** \return Pointer to the IGPUProgrammingServices. Returns 0
  924. if the video driver does not support this. For example the
  925. Software driver and the Null driver will always return 0. */
  926. virtual IGPUProgrammingServices *getGPUProgrammingServices() = 0;
  927. //! Returns a pointer to the mesh manipulator.
  928. virtual scene::IMeshManipulator *getMeshManipulator() = 0;
  929. //! Clear the color, depth and/or stencil buffers.
  930. virtual void clearBuffers(u16 flag, SColor color = SColor(255, 0, 0, 0), f32 depth = 1.f, u8 stencil = 0) = 0;
  931. //! Clears the ZBuffer.
  932. /** Note that you usually need not to call this method, as it
  933. is automatically done in IVideoDriver::beginScene() or
  934. IVideoDriver::setRenderTarget() if you enable zBuffer. But if
  935. you have to render some special things, you can clear the
  936. zbuffer during the rendering process with this method any time.
  937. */
  938. void clearZBuffer()
  939. {
  940. clearBuffers(ECBF_DEPTH, SColor(255, 0, 0, 0), 1.f, 0);
  941. }
  942. //! Make a screenshot of the last rendered frame.
  943. /** \return An image created from the last rendered frame. */
  944. virtual IImage *createScreenShot(video::ECOLOR_FORMAT format = video::ECF_UNKNOWN, video::E_RENDER_TARGET target = video::ERT_FRAME_BUFFER) = 0;
  945. //! Check if the image is already loaded.
  946. /** Works similar to getTexture(), but does not load the texture
  947. if it is not currently loaded.
  948. \param filename Name of the texture.
  949. \return Pointer to loaded texture, or 0 if not found. */
  950. virtual video::ITexture *findTexture(const io::path &filename) = 0;
  951. //! Set the minimum number of vertices for which a hw buffer will be created
  952. /** \param count Number of vertices to set as minimum. */
  953. virtual void setMinHardwareBufferVertexCount(u32 count) = 0;
  954. //! Get the global Material, which might override local materials.
  955. /** Depending on the enable flags, values from this Material
  956. are used to override those of local materials of some
  957. meshbuffer being rendered.
  958. \return Reference to the Override Material. */
  959. virtual SOverrideMaterial &getOverrideMaterial() = 0;
  960. //! Get the 2d override material for altering its values
  961. /** The 2d override material allows to alter certain render
  962. states of the 2d methods. Not all members of SMaterial are
  963. honored, especially not MaterialType and Textures. Moreover,
  964. the zbuffer is always ignored, and lighting is always off. All
  965. other flags can be changed, though some might have to effect
  966. in most cases.
  967. Please note that you have to enable/disable this effect with
  968. enableMaterial2D(). This effect is costly, as it increases
  969. the number of state changes considerably. Always reset the
  970. values when done.
  971. \return Material reference which should be altered to reflect
  972. the new settings.
  973. */
  974. virtual SMaterial &getMaterial2D() = 0;
  975. //! Enable the 2d override material
  976. /** \param enable Flag which tells whether the material shall be
  977. enabled or disabled. */
  978. virtual void enableMaterial2D(bool enable = true) = 0;
  979. //! Get the graphics card vendor name.
  980. virtual core::stringc getVendorInfo() = 0;
  981. //! Only used by the engine internally.
  982. /** The ambient color is set in the scene manager, see
  983. scene::ISceneManager::setAmbientLight().
  984. \param color New color of the ambient light. */
  985. virtual void setAmbientLight(const SColorf &color) = 0;
  986. //! Get the global ambient light currently used by the driver
  987. virtual const SColorf &getAmbientLight() const = 0;
  988. //! Only used by the engine internally.
  989. /** Passes the global material flag AllowZWriteOnTransparent.
  990. Use the SceneManager attribute to set this value from your app.
  991. \param flag Default behavior is to disable ZWrite, i.e. false. */
  992. virtual void setAllowZWriteOnTransparent(bool flag) = 0;
  993. //! Get the maximum texture size supported.
  994. virtual core::dimension2du getMaxTextureSize() const = 0;
  995. //! Color conversion convenience function
  996. /** Convert an image (as array of pixels) from source to destination
  997. array, thereby converting the color format. The pixel size is
  998. determined by the color formats.
  999. \param sP Pointer to source
  1000. \param sF Color format of source
  1001. \param sN Number of pixels to convert, both array must be large enough
  1002. \param dP Pointer to destination
  1003. \param dF Color format of destination
  1004. */
  1005. virtual void convertColor(const void *sP, ECOLOR_FORMAT sF, s32 sN,
  1006. void *dP, ECOLOR_FORMAT dF) const = 0;
  1007. //! Check if the driver supports creating textures with the given color format
  1008. /** \return True if the format is available, false if not. */
  1009. virtual bool queryTextureFormat(ECOLOR_FORMAT format) const = 0;
  1010. //! Used by some SceneNodes to check if a material should be rendered in the transparent render pass
  1011. virtual bool needsTransparentRenderPass(const irr::video::SMaterial &material) const = 0;
  1012. };
  1013. } // end namespace video
  1014. } // end namespace irr