IVideoDriver.h 52 KB

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