2
0

IVideoDriver.h 54 KB

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