2
0

IVideoDriver.h 51 KB

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