2
0

IVideoDriver.h 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  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 multisampled render target texture to the texture cache.
  246. /** \param msaa The number of samples to use, values that make sense are > 1.
  247. Only works if the driver supports the EVDF_TEXTURE_MULTISAMPLE feature,
  248. check via queryFeature.
  249. \see addRenderTargetTexture */
  250. virtual ITexture *addRenderTargetTextureMs(const core::dimension2d<u32> &size, u8 msaa,
  251. const io::path &name = "rt", const ECOLOR_FORMAT format = ECF_UNKNOWN) = 0;
  252. //! Adds a new render target texture with 6 sides for a cubemap map to the texture cache.
  253. /** \param sideLen Length of one cubemap side.
  254. \param name A name for the texture. Later calls of getTexture() with this name will return this texture.
  255. The name can _not_ be empty.
  256. \param format The color format of the render target. Floating point formats are supported.
  257. \return Pointer to the created texture or 0 if the texture
  258. could not be created. This pointer should not be dropped. See
  259. IReferenceCounted::drop() for more information. */
  260. virtual ITexture *addRenderTargetTextureCubemap(const irr::u32 sideLen,
  261. const io::path &name = "rt", const ECOLOR_FORMAT format = ECF_UNKNOWN) = 0;
  262. //! Removes a texture from the texture cache and deletes it.
  263. /** This method can free a lot of memory!
  264. Please note that after calling this, the pointer to the
  265. ITexture may no longer be valid, if it was not grabbed before
  266. by other parts of the engine for storing it longer. So it is a
  267. good idea to set all materials which are using this texture to
  268. 0 or another texture first.
  269. \param texture Texture to delete from the engine cache. */
  270. virtual void removeTexture(ITexture *texture) = 0;
  271. //! Removes all textures from the texture cache and deletes them.
  272. /** This method can free a lot of memory!
  273. Please note that after calling this, the pointer to the
  274. ITexture may no longer be valid, if it was not grabbed before
  275. by other parts of the engine for storing it longer. So it is a
  276. good idea to set all materials which are using this texture to
  277. 0 or another texture first. */
  278. virtual void removeAllTextures() = 0;
  279. //! Remove hardware buffer
  280. virtual void removeHardwareBuffer(const scene::IVertexBuffer *vb) = 0;
  281. //! Remove hardware buffer
  282. virtual void removeHardwareBuffer(const scene::IIndexBuffer *ib) = 0;
  283. //! Remove all hardware buffers
  284. virtual void removeAllHardwareBuffers() = 0;
  285. //! Create occlusion query.
  286. /** Use node for identification and mesh for occlusion test. */
  287. virtual void addOcclusionQuery(scene::ISceneNode *node,
  288. const scene::IMesh *mesh = 0) = 0;
  289. //! Remove occlusion query.
  290. virtual void removeOcclusionQuery(scene::ISceneNode *node) = 0;
  291. //! Remove all occlusion queries.
  292. virtual void removeAllOcclusionQueries() = 0;
  293. //! Run occlusion query. Draws mesh stored in query.
  294. /** If the mesh shall not be rendered visible, use
  295. overrideMaterial to disable the color and depth buffer. */
  296. virtual void runOcclusionQuery(scene::ISceneNode *node, bool visible = false) = 0;
  297. //! Run all occlusion queries. Draws all meshes stored in queries.
  298. /** If the meshes shall not be rendered visible, use
  299. overrideMaterial to disable the color and depth buffer. */
  300. virtual void runAllOcclusionQueries(bool visible = false) = 0;
  301. //! Update occlusion query. Retrieves results from GPU.
  302. /** If the query shall not block, set the flag to false.
  303. Update might not occur in this case, though */
  304. virtual void updateOcclusionQuery(scene::ISceneNode *node, bool block = true) = 0;
  305. //! Update all occlusion queries. Retrieves results from GPU.
  306. /** If the query shall not block, set the flag to false.
  307. Update might not occur in this case, though */
  308. virtual void updateAllOcclusionQueries(bool block = true) = 0;
  309. //! Return query result.
  310. /** Return value is the number of visible pixels/fragments.
  311. The value is a safe approximation, i.e. can be larger than the
  312. actual value of pixels. */
  313. virtual u32 getOcclusionQueryResult(scene::ISceneNode *node) const = 0;
  314. //! Create render target.
  315. virtual IRenderTarget *addRenderTarget() = 0;
  316. //! Remove render target.
  317. virtual void removeRenderTarget(IRenderTarget *renderTarget) = 0;
  318. //! Remove all render targets.
  319. virtual void removeAllRenderTargets() = 0;
  320. //! Blit contents of one render target to another one.
  321. /** This is glBlitFramebuffer in OpenGL. */
  322. virtual void blitRenderTarget(IRenderTarget *from, IRenderTarget *to) = 0;
  323. //! Sets a boolean alpha channel on the texture based on a color key.
  324. /** This makes the texture fully transparent at the texels where
  325. this color key can be found when using for example draw2DImage
  326. with useAlphachannel==true. The alpha of other texels is not modified.
  327. \param texture Texture whose alpha channel is modified.
  328. \param color Color key color. Every texel with this color will
  329. become fully transparent as described above. Please note that the
  330. colors of a texture may be converted when loading it, so the
  331. color values may not be exactly the same in the engine and for
  332. example in picture edit programs. To avoid this problem, you
  333. could use the makeColorKeyTexture method, which takes the
  334. position of a pixel instead a color value. */
  335. virtual void makeColorKeyTexture(video::ITexture *texture,
  336. video::SColor color) const = 0;
  337. //! Sets a boolean alpha channel on the texture based on the color at a position.
  338. /** This makes the texture fully transparent at the texels where
  339. the color key can be found when using for example draw2DImage
  340. with useAlphachannel==true. The alpha of other texels is not modified.
  341. \param texture Texture whose alpha channel is modified.
  342. \param colorKeyPixelPos Position of a pixel with the color key
  343. color. Every texel with this color will become fully transparent as
  344. described above. */
  345. virtual void makeColorKeyTexture(video::ITexture *texture,
  346. core::position2d<s32> colorKeyPixelPos) const = 0;
  347. //! Set a render target.
  348. /** This will only work if the driver supports the
  349. EVDF_RENDER_TO_TARGET feature, which can be queried with
  350. queryFeature(). Please note that you cannot render 3D or 2D
  351. geometry with a render target as texture on it when you are rendering
  352. the scene into this render target at the same time. It is usually only
  353. possible to render into a texture between the
  354. IVideoDriver::beginScene() and endScene() method calls. If you need the
  355. best performance use this method instead of setRenderTarget.
  356. \param target Render target object. If set to nullptr, it makes the
  357. window the current render target.
  358. \param clearFlag A combination of the E_CLEAR_BUFFER_FLAG bit-flags.
  359. \param clearColor The clear color for the color buffer.
  360. \param clearDepth The clear value for the depth buffer.
  361. \param clearStencil The clear value for the stencil buffer.
  362. \return True if successful and false if not. */
  363. virtual bool setRenderTargetEx(IRenderTarget *target, u16 clearFlag, SColor clearColor = SColor(255, 0, 0, 0),
  364. f32 clearDepth = 1.f, u8 clearStencil = 0) = 0;
  365. //! Sets a new render target.
  366. /** This will only work if the driver supports the
  367. EVDF_RENDER_TO_TARGET feature, which can be queried with
  368. queryFeature(). Usually, rendering to textures is done in this
  369. way:
  370. \code
  371. // create render target
  372. ITexture* target = driver->addRenderTargetTexture(core::dimension2d<u32>(128,128), "rtt1");
  373. // ...
  374. driver->setRenderTarget(target); // set render target
  375. // .. draw stuff here
  376. driver->setRenderTarget(0); // set previous render target
  377. \endcode
  378. Please note that you cannot render 3D or 2D geometry with a
  379. render target as texture on it when you are rendering the scene
  380. into this render target at the same time. It is usually only
  381. possible to render into a texture between the
  382. IVideoDriver::beginScene() and endScene() method calls.
  383. \param texture New render target. Must be a texture created with
  384. IVideoDriver::addRenderTargetTexture(). If set to nullptr, it makes
  385. the window the current render target.
  386. \param clearFlag A combination of the E_CLEAR_BUFFER_FLAG bit-flags.
  387. \param clearColor The clear color for the color buffer.
  388. \param clearDepth The clear value for the depth buffer.
  389. \param clearStencil The clear value for the stencil buffer.
  390. \return True if successful and false if not. */
  391. virtual bool setRenderTarget(ITexture *texture, u16 clearFlag = ECBF_COLOR | ECBF_DEPTH, SColor clearColor = SColor(255, 0, 0, 0),
  392. f32 clearDepth = 1.f, u8 clearStencil = 0) = 0;
  393. //! Sets a new render target.
  394. //! Prefer to use the setRenderTarget function taking flags as parameter as this one can't clear the stencil buffer.
  395. //! It's still offered for backward compatibility.
  396. bool setRenderTarget(ITexture *texture, bool clearBackBuffer, bool clearZBuffer, SColor color = SColor(255, 0, 0, 0))
  397. {
  398. u16 flag = 0;
  399. if (clearBackBuffer)
  400. flag |= ECBF_COLOR;
  401. if (clearZBuffer)
  402. flag |= ECBF_DEPTH;
  403. return setRenderTarget(texture, flag, color);
  404. }
  405. //! Sets a new viewport.
  406. /** Every rendering operation is done into this new area.
  407. \param area: Rectangle defining the new area of rendering
  408. operations. */
  409. virtual void setViewPort(const core::rect<s32> &area) = 0;
  410. //! Gets the area of the current viewport.
  411. /** \return Rectangle of the current viewport. */
  412. virtual const core::rect<s32> &getViewPort() const = 0;
  413. //! Draws a vertex primitive list
  414. /** Note that, depending on the index type, some vertices might be not
  415. accessible through the index list. The limit is at 65535 vertices for 16bit
  416. indices. Please note that currently not all primitives are available for
  417. all drivers, and some might be emulated via triangle renders.
  418. \param vertices Pointer to array of vertices.
  419. \param vertexCount Amount of vertices in the array.
  420. \param indexList Pointer to array of indices. These define the vertices used
  421. for each primitive. Depending on the pType, indices are interpreted as single
  422. objects (for point like primitives), pairs (for lines), triplets (for
  423. triangles), or quads.
  424. \param primCount Amount of Primitives
  425. \param vType Vertex type, e.g. video::EVT_STANDARD for S3DVertex.
  426. \param pType Primitive type, e.g. scene::EPT_TRIANGLE_FAN for a triangle fan.
  427. \param iType Index type, e.g. video::EIT_16BIT for 16bit indices. */
  428. virtual void drawVertexPrimitiveList(const void *vertices, u32 vertexCount,
  429. const void *indexList, u32 primCount,
  430. E_VERTEX_TYPE vType = EVT_STANDARD,
  431. scene::E_PRIMITIVE_TYPE pType = scene::EPT_TRIANGLES,
  432. E_INDEX_TYPE iType = EIT_16BIT) = 0;
  433. //! Draws a vertex primitive list in 2d
  434. /** Compared to the general (3d) version of this method, this
  435. one sets up a 2d render mode, and uses only x and y of vectors.
  436. Note that, depending on the index type, some vertices might be
  437. not accessible through the index list. The limit is at 65535
  438. vertices for 16bit indices. Please note that currently not all
  439. primitives are available for all drivers, and some might be
  440. emulated via triangle renders. This function is not available
  441. for the sw drivers.
  442. \param vertices Pointer to array of vertices.
  443. \param vertexCount Amount of vertices in the array.
  444. \param indexList Pointer to array of indices. These define the
  445. vertices used for each primitive. Depending on the pType,
  446. indices are interpreted as single objects (for point like
  447. primitives), pairs (for lines), triplets (for triangles), or
  448. quads.
  449. \param primCount Amount of Primitives
  450. \param vType Vertex type, e.g. video::EVT_STANDARD for S3DVertex.
  451. \param pType Primitive type, e.g. scene::EPT_TRIANGLE_FAN for a triangle fan.
  452. \param iType Index type, e.g. video::EIT_16BIT for 16bit indices. */
  453. virtual void draw2DVertexPrimitiveList(const void *vertices, u32 vertexCount,
  454. const void *indexList, u32 primCount,
  455. E_VERTEX_TYPE vType = EVT_STANDARD,
  456. scene::E_PRIMITIVE_TYPE pType = scene::EPT_TRIANGLES,
  457. E_INDEX_TYPE iType = EIT_16BIT) = 0;
  458. //! Draws an indexed triangle list.
  459. /** Note that there may be at maximum 65536 vertices, because
  460. the index list is an array of 16 bit values each with a maximum
  461. value of 65536. If there are more than 65536 vertices in the
  462. list, results of this operation are not defined.
  463. \param vertices Pointer to array of vertices.
  464. \param vertexCount Amount of vertices in the array.
  465. \param indexList Pointer to array of indices.
  466. \param triangleCount Amount of Triangles. Usually amount of indices / 3. */
  467. void drawIndexedTriangleList(const S3DVertex *vertices,
  468. u32 vertexCount, const u16 *indexList, u32 triangleCount)
  469. {
  470. drawVertexPrimitiveList(vertices, vertexCount, indexList, triangleCount, EVT_STANDARD, scene::EPT_TRIANGLES, EIT_16BIT);
  471. }
  472. //! Draws an indexed triangle list.
  473. /** Note that there may be at maximum 65536 vertices, because
  474. the index list is an array of 16 bit values each with a maximum
  475. value of 65536. If there are more than 65536 vertices in the
  476. list, results of this operation are not defined.
  477. \param vertices Pointer to array of vertices.
  478. \param vertexCount Amount of vertices in the array.
  479. \param indexList Pointer to array of indices.
  480. \param triangleCount Amount of Triangles. Usually amount of indices / 3. */
  481. void drawIndexedTriangleList(const S3DVertex2TCoords *vertices,
  482. u32 vertexCount, const u16 *indexList, u32 triangleCount)
  483. {
  484. drawVertexPrimitiveList(vertices, vertexCount, indexList, triangleCount, EVT_2TCOORDS, scene::EPT_TRIANGLES, EIT_16BIT);
  485. }
  486. //! Draws an indexed triangle list.
  487. /** Note that there may be at maximum 65536 vertices, because
  488. the index list is an array of 16 bit values each with a maximum
  489. value of 65536. If there are more than 65536 vertices in the
  490. list, results of this operation are not defined.
  491. \param vertices Pointer to array of vertices.
  492. \param vertexCount Amount of vertices in the array.
  493. \param indexList Pointer to array of indices.
  494. \param triangleCount Amount of Triangles. Usually amount of indices / 3. */
  495. void drawIndexedTriangleList(const S3DVertexTangents *vertices,
  496. u32 vertexCount, const u16 *indexList, u32 triangleCount)
  497. {
  498. drawVertexPrimitiveList(vertices, vertexCount, indexList, triangleCount, EVT_TANGENTS, scene::EPT_TRIANGLES, EIT_16BIT);
  499. }
  500. //! Draws an indexed triangle fan.
  501. /** Note that there may be at maximum 65536 vertices, because
  502. the index list is an array of 16 bit values each with a maximum
  503. value of 65536. If there are more than 65536 vertices in the
  504. list, results of this operation are not defined.
  505. \param vertices Pointer to array of vertices.
  506. \param vertexCount Amount of vertices in the array.
  507. \param indexList Pointer to array of indices.
  508. \param triangleCount Amount of Triangles. Usually amount of indices - 2. */
  509. void drawIndexedTriangleFan(const S3DVertex *vertices,
  510. u32 vertexCount, const u16 *indexList, u32 triangleCount)
  511. {
  512. drawVertexPrimitiveList(vertices, vertexCount, indexList, triangleCount, EVT_STANDARD, scene::EPT_TRIANGLE_FAN, EIT_16BIT);
  513. }
  514. //! Draws an indexed triangle fan.
  515. /** Note that there may be at maximum 65536 vertices, because
  516. the index list is an array of 16 bit values each with a maximum
  517. value of 65536. If there are more than 65536 vertices in the
  518. list, results of this operation are not defined.
  519. \param vertices Pointer to array of vertices.
  520. \param vertexCount Amount of vertices in the array.
  521. \param indexList Pointer to array of indices.
  522. \param triangleCount Amount of Triangles. Usually amount of indices - 2. */
  523. void drawIndexedTriangleFan(const S3DVertex2TCoords *vertices,
  524. u32 vertexCount, const u16 *indexList, u32 triangleCount)
  525. {
  526. drawVertexPrimitiveList(vertices, vertexCount, indexList, triangleCount, EVT_2TCOORDS, scene::EPT_TRIANGLE_FAN, EIT_16BIT);
  527. }
  528. //! Draws an indexed triangle fan.
  529. /** Note that there may be at maximum 65536 vertices, because
  530. the index list is an array of 16 bit values each with a maximum
  531. value of 65536. If there are more than 65536 vertices in the
  532. list, results of this operation are not defined.
  533. \param vertices Pointer to array of vertices.
  534. \param vertexCount Amount of vertices in the array.
  535. \param indexList Pointer to array of indices.
  536. \param triangleCount Amount of Triangles. Usually amount of indices - 2. */
  537. void drawIndexedTriangleFan(const S3DVertexTangents *vertices,
  538. u32 vertexCount, const u16 *indexList, u32 triangleCount)
  539. {
  540. drawVertexPrimitiveList(vertices, vertexCount, indexList, triangleCount, EVT_TANGENTS, scene::EPT_TRIANGLE_FAN, EIT_16BIT);
  541. }
  542. //! Draws a 3d line.
  543. /** For some implementations, this method simply calls
  544. drawVertexPrimitiveList for some triangles.
  545. Note that the line is drawn using the current transformation
  546. matrix and material. So if you need to draw the 3D line
  547. independently of the current transformation, use
  548. \code
  549. driver->setMaterial(someMaterial);
  550. driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
  551. \endcode
  552. for some properly set up material before drawing the line.
  553. Some drivers support line thickness set in the material.
  554. \param start Start of the 3d line.
  555. \param end End of the 3d line.
  556. \param color Color of the line. */
  557. virtual void draw3DLine(const core::vector3df &start,
  558. const core::vector3df &end, SColor color = SColor(255, 255, 255, 255)) = 0;
  559. //! Draws a 3d axis aligned box.
  560. /** This method simply calls draw3DLine for the edges of the
  561. box. Note that the box is drawn using the current transformation
  562. matrix and material. So if you need to draw it independently of
  563. the current transformation, use
  564. \code
  565. driver->setMaterial(someMaterial);
  566. driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
  567. \endcode
  568. for some properly set up material before drawing the box.
  569. \param box The axis aligned box to draw
  570. \param color Color to use while drawing the box. */
  571. virtual void draw3DBox(const core::aabbox3d<f32> &box,
  572. SColor color = SColor(255, 255, 255, 255)) = 0;
  573. //! Draws a 2d image without any special effects
  574. /** \param texture Pointer to texture to use.
  575. \param destPos Upper left 2d destination position where the
  576. image will be drawn.
  577. \param useAlphaChannelOfTexture: If true, the alpha channel of
  578. the texture is used to draw the image.*/
  579. virtual void draw2DImage(const video::ITexture *texture,
  580. const core::position2d<s32> &destPos, bool useAlphaChannelOfTexture = false) = 0;
  581. //! Draws a 2d image using a color
  582. /** (if color is other than
  583. Color(255,255,255,255)) and the alpha channel of the texture.
  584. \param texture Texture to be drawn.
  585. \param destPos Upper left 2d destination position where the
  586. image will be drawn.
  587. \param sourceRect Source rectangle in the texture (based on it's OriginalSize)
  588. \param clipRect Pointer to rectangle on the screen where the
  589. image is clipped to.
  590. If this pointer is NULL the image is not clipped.
  591. \param color Color with which the image is drawn. If the color
  592. equals Color(255,255,255,255) it is ignored. Note that the
  593. alpha component is used: If alpha is other than 255, the image
  594. will be transparent.
  595. \param useAlphaChannelOfTexture: If true, the alpha channel of
  596. the texture is used to draw the image.*/
  597. virtual void draw2DImage(const video::ITexture *texture, const core::position2d<s32> &destPos,
  598. const core::rect<s32> &sourceRect, const core::rect<s32> *clipRect = 0,
  599. SColor color = SColor(255, 255, 255, 255), bool useAlphaChannelOfTexture = false) = 0;
  600. //! Draws a set of 2d images, using a color and the alpha channel of the texture.
  601. /** All drawings are clipped against clipRect (if != 0).
  602. The subtextures are defined by the array of sourceRects and are
  603. positioned using the array of positions.
  604. \param texture Texture to be drawn.
  605. \param positions Array of upper left 2d destinations where the
  606. images will be drawn.
  607. \param sourceRects Source rectangles of the texture (based on it's OriginalSize)
  608. \param clipRect Pointer to rectangle on the screen where the
  609. images are clipped to.
  610. If this pointer is 0 then the image is not clipped.
  611. \param color Color with which the image is drawn.
  612. Note that the alpha component is used. If alpha is other than
  613. 255, the image will be transparent.
  614. \param useAlphaChannelOfTexture: If true, the alpha channel of
  615. the texture is used to draw the image. */
  616. virtual void draw2DImageBatch(const video::ITexture *texture,
  617. const core::array<core::position2d<s32>> &positions,
  618. const core::array<core::rect<s32>> &sourceRects,
  619. const core::rect<s32> *clipRect = 0,
  620. SColor color = SColor(255, 255, 255, 255),
  621. bool useAlphaChannelOfTexture = false) = 0;
  622. //! Draws a part of the texture into the rectangle. Note that colors must be an array of 4 colors if used.
  623. /** Suggested and first implemented by zola.
  624. \param texture The texture to draw from
  625. \param destRect The rectangle to draw into
  626. \param sourceRect The rectangle denoting a part of the texture (based on it's OriginalSize)
  627. \param clipRect Clips the destination rectangle (may be 0)
  628. \param colors Array of 4 colors denoting the color values of
  629. the corners of the destRect
  630. \param useAlphaChannelOfTexture True if alpha channel will be
  631. blended. */
  632. virtual void draw2DImage(const video::ITexture *texture, const core::rect<s32> &destRect,
  633. const core::rect<s32> &sourceRect, const core::rect<s32> *clipRect = 0,
  634. const video::SColor *const colors = 0, bool useAlphaChannelOfTexture = false) = 0;
  635. //! Draws a 2d rectangle.
  636. /** \param color Color of the rectangle to draw. The alpha
  637. component will not be ignored and specifies how transparent the
  638. rectangle will be.
  639. \param pos Position of the rectangle.
  640. \param clip Pointer to rectangle against which the rectangle
  641. will be clipped. If the pointer is null, no clipping will be
  642. performed. */
  643. virtual void draw2DRectangle(SColor color, const core::rect<s32> &pos,
  644. const core::rect<s32> *clip = 0) = 0;
  645. //! Draws a 2d rectangle with a gradient.
  646. /** \param colorLeftUp Color of the upper left corner to draw.
  647. The alpha component will not be ignored and specifies how
  648. transparent the rectangle will be.
  649. \param colorRightUp Color of the upper right corner to draw.
  650. The alpha component will not be ignored and specifies how
  651. transparent the rectangle will be.
  652. \param colorLeftDown Color of the lower left corner to draw.
  653. The alpha component will not be ignored and specifies how
  654. transparent the rectangle will be.
  655. \param colorRightDown Color of the lower right corner to draw.
  656. The alpha component will not be ignored and specifies how
  657. transparent the rectangle will be.
  658. \param pos Position of the rectangle.
  659. \param clip Pointer to rectangle against which the rectangle
  660. will be clipped. If the pointer is null, no clipping will be
  661. performed. */
  662. virtual void draw2DRectangle(const core::rect<s32> &pos,
  663. SColor colorLeftUp, SColor colorRightUp,
  664. SColor colorLeftDown, SColor colorRightDown,
  665. const core::rect<s32> *clip = 0) = 0;
  666. //! Draws a 2d line.
  667. /** In theory both start and end will be included in coloring.
  668. BUG: Currently d3d ignores the last pixel
  669. (it uses the so called "diamond exit rule" for drawing lines).
  670. \param start Screen coordinates of the start of the line
  671. in pixels.
  672. \param end Screen coordinates of the start of the line in
  673. pixels.
  674. \param color Color of the line to draw. */
  675. virtual void draw2DLine(const core::position2d<s32> &start,
  676. const core::position2d<s32> &end,
  677. SColor color = SColor(255, 255, 255, 255)) = 0;
  678. //! Draws a mesh buffer
  679. /** \param mb Buffer to draw */
  680. virtual void drawMeshBuffer(const scene::IMeshBuffer *mb) = 0;
  681. /**
  682. * Draws a mesh from individual vertex and index buffers.
  683. * @param vb vertices to use
  684. * @param ib indices to use
  685. * @param primCount amount of primitives
  686. * @param pType primitive type
  687. */
  688. virtual void drawBuffers(const scene::IVertexBuffer *vb,
  689. const scene::IIndexBuffer *ib, u32 primCount,
  690. scene::E_PRIMITIVE_TYPE pType = scene::EPT_TRIANGLES) = 0;
  691. //! Draws normals of a mesh buffer
  692. /** \param mb Buffer to draw the normals of
  693. \param length length scale factor of the normals
  694. \param color Color the normals are rendered with
  695. */
  696. virtual void drawMeshBufferNormals(const scene::IMeshBuffer *mb, f32 length = 10.f, SColor color = 0xffffffff) = 0;
  697. //! Sets the fog mode.
  698. /** These are global values attached to each 3d object rendered,
  699. which has the fog flag enabled in its material.
  700. \param color Color of the fog
  701. \param fogType Type of fog used
  702. \param start Only used in linear fog mode (linearFog=true).
  703. Specifies where fog starts.
  704. \param end Only used in linear fog mode (linearFog=true).
  705. Specifies where fog ends.
  706. \param density Only used in exponential fog mode
  707. (linearFog=false). Must be a value between 0 and 1.
  708. \param pixelFog Set this to false for vertex fog, and true if
  709. you want per-pixel fog.
  710. \param rangeFog Set this to true to enable range-based vertex
  711. fog. The distance from the viewer is used to compute the fog,
  712. not the z-coordinate. This is better, but slower. This might not
  713. be available with all drivers and fog settings. */
  714. virtual void setFog(SColor color = SColor(0, 255, 255, 255),
  715. E_FOG_TYPE fogType = EFT_FOG_LINEAR,
  716. f32 start = 50.0f, f32 end = 100.0f, f32 density = 0.01f,
  717. bool pixelFog = false, bool rangeFog = false) = 0;
  718. //! Gets the fog mode.
  719. virtual void getFog(SColor &color, E_FOG_TYPE &fogType,
  720. f32 &start, f32 &end, f32 &density,
  721. bool &pixelFog, bool &rangeFog) = 0;
  722. //! Get the current color format of the color buffer
  723. /** \return Color format of the color buffer. */
  724. virtual ECOLOR_FORMAT getColorFormat() const = 0;
  725. //! Get the size of the screen or render window.
  726. /** \return Size of screen or render window. */
  727. virtual const core::dimension2d<u32> &getScreenSize() const = 0;
  728. //! Get the size of the current render target
  729. /** This method will return the screen size if the driver
  730. doesn't support render to texture, or if the current render
  731. target is the screen.
  732. \return Size of render target or screen/window */
  733. virtual const core::dimension2d<u32> &getCurrentRenderTargetSize() const = 0;
  734. //! Returns current frames per second value.
  735. /** This value is updated approximately every 1.5 seconds and
  736. is only intended to provide a rough guide to the average frame
  737. rate. It is not suitable for use in performing timing
  738. calculations or framerate independent movement.
  739. \return Approximate amount of frames per second drawn. */
  740. virtual s32 getFPS() const = 0;
  741. //! Return some statistics about the last frame
  742. virtual SFrameStats getFrameStats() const = 0;
  743. //! Gets name of this video driver.
  744. /** \return Returns the name of the video driver, e.g. in case
  745. of the Direct3D8 driver, it would return "Direct3D 8.1". */
  746. virtual const char *getName() const = 0;
  747. //! Adds an external image loader to the engine.
  748. /** This is useful if the Irrlicht Engine should be able to load
  749. textures of currently unsupported file formats (e.g. gif). The
  750. IImageLoader only needs to be implemented for loading this file
  751. format. A pointer to the implementation can be passed to the
  752. engine using this method.
  753. \param loader Pointer to the external loader created. */
  754. virtual void addExternalImageLoader(IImageLoader *loader) = 0;
  755. //! Adds an external image writer to the engine.
  756. /** This is useful if the Irrlicht Engine should be able to
  757. write textures of currently unsupported file formats (e.g
  758. .gif). The IImageWriter only needs to be implemented for
  759. writing this file format. A pointer to the implementation can
  760. be passed to the engine using this method.
  761. \param writer: Pointer to the external writer created. */
  762. virtual void addExternalImageWriter(IImageWriter *writer) = 0;
  763. //! Returns the maximum amount of primitives
  764. /** (mostly vertices) which the device is able to render with
  765. one drawVertexPrimitiveList call.
  766. \return Maximum amount of primitives. */
  767. virtual u32 getMaximalPrimitiveCount() const = 0;
  768. //! Enables or disables a texture creation flag.
  769. /** These flags define how textures should be created. By
  770. changing this value, you can influence for example the speed of
  771. rendering a lot. But please note that the video drivers take
  772. this value only as recommendation. It could happen that you
  773. enable the ETCF_ALWAYS_16_BIT mode, but the driver still creates
  774. 32 bit textures.
  775. \param flag Texture creation flag.
  776. \param enabled Specifies if the given flag should be enabled or
  777. disabled. */
  778. virtual void setTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag, bool enabled = true) = 0;
  779. //! Returns if a texture creation flag is enabled or disabled.
  780. /** You can change this value using setTextureCreationFlag().
  781. \param flag Texture creation flag.
  782. \return The current texture creation flag enabled mode. */
  783. virtual bool getTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag) const = 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 filename Name of the file from which the image is
  789. created.
  790. \return The created image.
  791. If you no longer need the image, you should call IImage::drop().
  792. See IReferenceCounted::drop() for more information. */
  793. virtual IImage *createImageFromFile(const io::path &filename) = 0;
  794. //! Creates a software image from a file.
  795. /** No hardware texture will be created for this image. This
  796. method is useful for example if you want to read a heightmap
  797. for a terrain renderer.
  798. \param file File from which the image is created.
  799. \return The created image.
  800. If you no longer need the image, you should call IImage::drop().
  801. See IReferenceCounted::drop() for more information. */
  802. virtual IImage *createImageFromFile(io::IReadFile *file) = 0;
  803. //! Writes the provided image to a file.
  804. /** Requires that there is a suitable image writer registered
  805. for writing the image.
  806. \param image Image to write.
  807. \param filename Name of the file to write.
  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, const io::path &filename, u32 param = 0) = 0;
  812. //! Writes the provided image to a file.
  813. /** Requires that there is a suitable image writer registered
  814. for writing the image.
  815. \param image Image to write.
  816. \param file An already open io::IWriteFile object. The name
  817. will be used to determine the appropriate image writer to use.
  818. \param param Control parameter for the backend (e.g. compression
  819. level).
  820. \return True on successful write. */
  821. virtual bool writeImageToFile(IImage *image, io::IWriteFile *file, u32 param = 0) = 0;
  822. //! Creates a software image from a byte array.
  823. /** No hardware texture will be created for this image. This
  824. method is useful for example if you want to read a heightmap
  825. for a terrain renderer.
  826. \param format Desired color format of the texture
  827. \param size Desired size of the image
  828. \param data A byte array with pixel color information
  829. \param ownForeignMemory If true, the image will use the data
  830. pointer directly and own it afterward. If false, the memory
  831. will by copied internally.
  832. WARNING: Setting this to 'true' will not work across dll boundaries.
  833. So unless you link Irrlicht statically you should keep this to 'false'.
  834. The parameter is mainly for internal usage.
  835. \param deleteMemory Whether the memory is deallocated upon
  836. destruction.
  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 *createImageFromData(ECOLOR_FORMAT format,
  841. const core::dimension2d<u32> &size, void *data, bool ownForeignMemory = false,
  842. bool deleteMemory = true) = 0;
  843. //! Creates an empty software image.
  844. /**
  845. \param format Desired color format of the image.
  846. \param size Size of the image to create.
  847. \return The created image.
  848. If you no longer need the image, you should call IImage::drop().
  849. See IReferenceCounted::drop() for more information. */
  850. virtual IImage *createImage(ECOLOR_FORMAT format, const core::dimension2d<u32> &size) = 0;
  851. //! Creates a software image from a part of a texture.
  852. /**
  853. \param texture Texture to copy to the new image in part.
  854. \param pos Position of rectangle to copy.
  855. \param size Extents of rectangle to copy.
  856. \return The created image.
  857. If you no longer need the image, you should call IImage::drop().
  858. See IReferenceCounted::drop() for more information. */
  859. virtual IImage *createImage(ITexture *texture,
  860. const core::position2d<s32> &pos,
  861. const core::dimension2d<u32> &size) = 0;
  862. //! Event handler for resize events. Only used by the engine internally.
  863. /** Used to notify the driver that the window was resized.
  864. Usually, there is no need to call this method. */
  865. virtual void OnResize(const core::dimension2d<u32> &size) = 0;
  866. //! Adds a new material renderer to the video device.
  867. /** Use this method to extend the VideoDriver with new material
  868. types. To extend the engine using this method do the following:
  869. Derive a class from IMaterialRenderer and override the methods
  870. you need. For setting the right renderstates, you can try to
  871. get a pointer to the real rendering device using
  872. IVideoDriver::getExposedVideoData(). Add your class with
  873. IVideoDriver::addMaterialRenderer(). To use an object being
  874. displayed with your new material, set the MaterialType member of
  875. the SMaterial struct to the value returned by this method.
  876. If you simply want to create a new material using vertex and/or
  877. pixel shaders it would be easier to use the
  878. video::IGPUProgrammingServices interface which you can get
  879. using the getGPUProgrammingServices() method.
  880. \param renderer A pointer to the new renderer.
  881. \param name Optional name for the material renderer entry.
  882. \return The number of the material type which can be set in
  883. SMaterial::MaterialType to use the renderer. -1 is returned if
  884. an error occurred. For example if you tried to add an material
  885. renderer to the software renderer or the null device, which do
  886. not accept material renderers. */
  887. virtual s32 addMaterialRenderer(IMaterialRenderer *renderer, const c8 *name = 0) = 0;
  888. //! Get access to a material renderer by index.
  889. /** \param idx Id of the material renderer. Can be a value of
  890. the E_MATERIAL_TYPE enum or a value which was returned by
  891. addMaterialRenderer().
  892. \return Pointer to material renderer or null if not existing. */
  893. virtual IMaterialRenderer *getMaterialRenderer(u32 idx) const = 0;
  894. //! Get amount of currently available material renderers.
  895. /** \return Amount of currently available material renderers. */
  896. virtual u32 getMaterialRendererCount() const = 0;
  897. //! Get name of a material renderer
  898. /** This string can, e.g., be used to test if a specific
  899. renderer already has been registered/created, or use this
  900. string to store data about materials: This returned name will
  901. be also used when serializing materials.
  902. \param idx Id of the material renderer. Can be a value of the
  903. E_MATERIAL_TYPE enum or a value which was returned by
  904. addMaterialRenderer().
  905. \return String with the name of the renderer, or 0 if not
  906. existing */
  907. virtual const c8 *getMaterialRendererName(u32 idx) const = 0;
  908. //! Sets the name of a material renderer.
  909. /** Will have no effect on built-in material renderers.
  910. \param idx: Id of the material renderer. Can be a value of the
  911. E_MATERIAL_TYPE enum or a value which was returned by
  912. addMaterialRenderer().
  913. \param name: New name of the material renderer. */
  914. virtual void setMaterialRendererName(u32 idx, const c8 *name) = 0;
  915. //! Swap the material renderers used for certain id's
  916. /** Swap the IMaterialRenderers responsible for rendering specific
  917. material-id's. This means every SMaterial using a MaterialType
  918. with one of the indices involved here will now render differently.
  919. \param idx1 First material index to swap. It must already exist or nothing happens.
  920. \param idx2 Second material index to swap. It must already exist or nothing happens.
  921. \param swapNames When true the renderer names also swap
  922. When false the names will stay at the original index */
  923. virtual void swapMaterialRenderers(u32 idx1, u32 idx2, bool swapNames = true) = 0;
  924. //! Returns driver and operating system specific data about the IVideoDriver.
  925. /** This method should only be used if the engine should be
  926. extended without having to modify the source of the engine.
  927. \return Collection of device dependent pointers. */
  928. virtual const SExposedVideoData &getExposedVideoData() = 0;
  929. //! Get type of video driver
  930. /** \return Type of driver. */
  931. virtual E_DRIVER_TYPE getDriverType() const = 0;
  932. //! Gets the IGPUProgrammingServices interface.
  933. /** \return Pointer to the IGPUProgrammingServices. Returns 0
  934. if the video driver does not support this. For example the
  935. Software driver and the Null driver will always return 0. */
  936. virtual IGPUProgrammingServices *getGPUProgrammingServices() = 0;
  937. //! Returns a pointer to the mesh manipulator.
  938. virtual scene::IMeshManipulator *getMeshManipulator() = 0;
  939. //! Clear the color, depth and/or stencil buffers.
  940. virtual void clearBuffers(u16 flag, SColor color = SColor(255, 0, 0, 0), f32 depth = 1.f, u8 stencil = 0) = 0;
  941. //! Clears the ZBuffer.
  942. /** Note that you usually need not to call this method, as it
  943. is automatically done in IVideoDriver::beginScene() or
  944. IVideoDriver::setRenderTarget() if you enable zBuffer. But if
  945. you have to render some special things, you can clear the
  946. zbuffer during the rendering process with this method any time.
  947. */
  948. void clearZBuffer()
  949. {
  950. clearBuffers(ECBF_DEPTH, SColor(255, 0, 0, 0), 1.f, 0);
  951. }
  952. //! Make a screenshot of the last rendered frame.
  953. /** \return An image created from the last rendered frame. */
  954. virtual IImage *createScreenShot(video::ECOLOR_FORMAT format = video::ECF_UNKNOWN, video::E_RENDER_TARGET target = video::ERT_FRAME_BUFFER) = 0;
  955. //! Check if the image is already loaded.
  956. /** Works similar to getTexture(), but does not load the texture
  957. if it is not currently loaded.
  958. \param filename Name of the texture.
  959. \return Pointer to loaded texture, or 0 if not found. */
  960. virtual video::ITexture *findTexture(const io::path &filename) = 0;
  961. //! Set the minimum number of vertices for which a hw buffer will be created
  962. /** \param count Number of vertices to set as minimum. */
  963. virtual void setMinHardwareBufferVertexCount(u32 count) = 0;
  964. //! Get the global Material, which might override local materials.
  965. /** Depending on the enable flags, values from this Material
  966. are used to override those of local materials of some
  967. meshbuffer being rendered.
  968. \return Reference to the Override Material. */
  969. virtual SOverrideMaterial &getOverrideMaterial() = 0;
  970. //! Get the 2d override material for altering its values
  971. /** The 2d override material allows to alter certain render
  972. states of the 2d methods. Not all members of SMaterial are
  973. honored, especially not MaterialType and Textures. Moreover,
  974. the zbuffer is always ignored, and lighting is always off. All
  975. other flags can be changed, though some might have to effect
  976. in most cases.
  977. Please note that you have to enable/disable this effect with
  978. enableMaterial2D(). This effect is costly, as it increases
  979. the number of state changes considerably. Always reset the
  980. values when done.
  981. \return Material reference which should be altered to reflect
  982. the new settings.
  983. */
  984. virtual SMaterial &getMaterial2D() = 0;
  985. //! Enable the 2d override material
  986. /** \param enable Flag which tells whether the material shall be
  987. enabled or disabled. */
  988. virtual void enableMaterial2D(bool enable = true) = 0;
  989. //! Get the graphics card vendor name.
  990. virtual core::stringc getVendorInfo() = 0;
  991. //! Only used by the engine internally.
  992. /** The ambient color is set in the scene manager, see
  993. scene::ISceneManager::setAmbientLight().
  994. \param color New color of the ambient light. */
  995. virtual void setAmbientLight(const SColorf &color) = 0;
  996. //! Get the global ambient light currently used by the driver
  997. virtual const SColorf &getAmbientLight() const = 0;
  998. //! Only used by the engine internally.
  999. /** Passes the global material flag AllowZWriteOnTransparent.
  1000. Use the SceneManager attribute to set this value from your app.
  1001. \param flag Default behavior is to disable ZWrite, i.e. false. */
  1002. virtual void setAllowZWriteOnTransparent(bool flag) = 0;
  1003. //! Get the maximum texture size supported.
  1004. virtual core::dimension2du getMaxTextureSize() const = 0;
  1005. //! Color conversion convenience function
  1006. /** Convert an image (as array of pixels) from source to destination
  1007. array, thereby converting the color format. The pixel size is
  1008. determined by the color formats.
  1009. \param sP Pointer to source
  1010. \param sF Color format of source
  1011. \param sN Number of pixels to convert, both array must be large enough
  1012. \param dP Pointer to destination
  1013. \param dF Color format of destination
  1014. */
  1015. virtual void convertColor(const void *sP, ECOLOR_FORMAT sF, s32 sN,
  1016. void *dP, ECOLOR_FORMAT dF) const = 0;
  1017. //! Check if the driver supports creating textures with the given color format
  1018. /** \return True if the format is available, false if not. */
  1019. virtual bool queryTextureFormat(ECOLOR_FORMAT format) const = 0;
  1020. //! Used by some SceneNodes to check if a material should be rendered in the transparent render pass
  1021. virtual bool needsTransparentRenderPass(const irr::video::SMaterial &material) const = 0;
  1022. };
  1023. } // end namespace video
  1024. } // end namespace irr