CNullDriver.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861
  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. #ifndef __C_VIDEO_NULL_H_INCLUDED__
  5. #define __C_VIDEO_NULL_H_INCLUDED__
  6. #include "IVideoDriver.h"
  7. #include "IFileSystem.h"
  8. #include "IImagePresenter.h"
  9. #include "IGPUProgrammingServices.h"
  10. #include "irrArray.h"
  11. #include "irrString.h"
  12. #include "irrMap.h"
  13. #include "IAttributes.h"
  14. #include "IMesh.h"
  15. #include "IMeshBuffer.h"
  16. #include "IMeshSceneNode.h"
  17. #include "CFPSCounter.h"
  18. #include "S3DVertex.h"
  19. #include "SVertexIndex.h"
  20. #include "SLight.h"
  21. #include "SExposedVideoData.h"
  22. #ifdef _MSC_VER
  23. #pragma warning( disable: 4996)
  24. #endif
  25. namespace irr
  26. {
  27. namespace io
  28. {
  29. class IWriteFile;
  30. class IReadFile;
  31. } // end namespace io
  32. namespace video
  33. {
  34. class IImageLoader;
  35. class IImageWriter;
  36. class CNullDriver : public IVideoDriver, public IGPUProgrammingServices
  37. {
  38. public:
  39. //! constructor
  40. CNullDriver(io::IFileSystem* io, const core::dimension2d<u32>& screenSize);
  41. //! destructor
  42. virtual ~CNullDriver();
  43. virtual bool beginScene(bool backBuffer=true, bool zBuffer=true,
  44. SColor color=SColor(255,0,0,0),
  45. const SExposedVideoData& videoData=SExposedVideoData(),
  46. core::rect<s32>* sourceRect=0);
  47. virtual bool endScene();
  48. //! Disable a feature of the driver.
  49. virtual void disableFeature(E_VIDEO_DRIVER_FEATURE feature, bool flag=true);
  50. //! queries the features of the driver, returns true if feature is available
  51. virtual bool queryFeature(E_VIDEO_DRIVER_FEATURE feature) const;
  52. //! Get attributes of the actual video driver
  53. const io::IAttributes& getDriverAttributes() const;
  54. //! Non-const version (with a different name to avoid involuntary mistakes). */
  55. virtual io::IAttributes& getNonConstDriverAttributes();
  56. //! sets transformation
  57. virtual void setTransform(E_TRANSFORMATION_STATE state, const core::matrix4& mat);
  58. //! Retrieve the number of image loaders
  59. virtual u32 getImageLoaderCount() const;
  60. //! Retrieve the given image loader
  61. virtual IImageLoader* getImageLoader(u32 n);
  62. //! Retrieve the number of image writers
  63. virtual u32 getImageWriterCount() const;
  64. //! Retrieve the given image writer
  65. virtual IImageWriter* getImageWriter(u32 n);
  66. //! sets a material
  67. virtual void setMaterial(const SMaterial& material);
  68. //! loads a Texture
  69. virtual ITexture* getTexture(const io::path& filename);
  70. //! loads a Texture
  71. virtual ITexture* getTexture(io::IReadFile* file);
  72. //! Returns a texture by index
  73. virtual ITexture* getTextureByIndex(u32 index);
  74. //! Returns amount of textures currently loaded
  75. virtual u32 getTextureCount() const;
  76. virtual u32 indiceToPrimitiveCount(scene::E_PRIMITIVE_TYPE pType, u32 count) const;
  77. //! Renames a texture
  78. virtual void renameTexture(ITexture* texture, const io::path& newName);
  79. //! creates a Texture
  80. virtual ITexture* addTexture(const core::dimension2d<u32>& size, const io::path& name, ECOLOR_FORMAT format = ECF_A8R8G8B8);
  81. //! sets a render target
  82. virtual bool setRenderTarget(video::ITexture* texture, bool clearBackBuffer,
  83. bool clearZBuffer, SColor color);
  84. //! set or reset special render targets
  85. virtual bool setRenderTarget(video::E_RENDER_TARGET target, bool clearTarget,
  86. bool clearZBuffer, SColor color);
  87. //! Sets multiple render targets
  88. virtual bool setRenderTarget(const core::array<video::IRenderTarget>& texture,
  89. bool clearBackBuffer=true, bool clearZBuffer=true, SColor color=SColor(0,0,0,0));
  90. //! sets a viewport
  91. virtual void setViewPort(const core::rect<s32>& area);
  92. //! gets the area of the current viewport
  93. virtual const core::rect<s32>& getViewPort() const;
  94. //! draws a vertex primitive list
  95. virtual void drawVertexPrimitiveList(const void* vertices, u32 vertexCount,
  96. const void* indexList, u32 primitiveCount,
  97. E_VERTEX_TYPE vType=EVT_STANDARD, scene::E_PRIMITIVE_TYPE pType=scene::EPT_TRIANGLES, E_INDEX_TYPE iType=EIT_16BIT);
  98. //! draws a vertex primitive list in 2d
  99. virtual void draw2DVertexPrimitiveList(const void* vertices, u32 vertexCount,
  100. const void* indexList, u32 primitiveCount,
  101. E_VERTEX_TYPE vType=EVT_STANDARD, scene::E_PRIMITIVE_TYPE pType=scene::EPT_TRIANGLES, E_INDEX_TYPE iType=EIT_16BIT);
  102. //! Draws a 3d line.
  103. virtual void draw3DLine(const core::vector3df& start,
  104. const core::vector3df& end, SColor color = SColor(255,255,255,255));
  105. //! Draws a 3d triangle.
  106. virtual void draw3DTriangle(const core::triangle3df& triangle,
  107. SColor color = SColor(255,255,255,255));
  108. //! Draws a 3d axis aligned box.
  109. virtual void draw3DBox(const core::aabbox3d<f32>& box,
  110. SColor color = SColor(255,255,255,255));
  111. //! draws an 2d image
  112. virtual void draw2DImage(const video::ITexture* texture, const core::position2d<s32>& destPos);
  113. //! draws a set of 2d images, using a color and the alpha
  114. /** channel of the texture if desired. The images are drawn
  115. beginning at pos and concatenated in one line. All drawings
  116. are clipped against clipRect (if != 0).
  117. The subtextures are defined by the array of sourceRects
  118. and are chosen by the indices given.
  119. \param texture: Texture to be drawn.
  120. \param pos: Upper left 2d destination position where the image will be drawn.
  121. \param sourceRects: Source rectangles of the image.
  122. \param indices: List of indices which choose the actual rectangle used each time.
  123. \param kerningWidth: offset on position
  124. \param clipRect: Pointer to rectangle on the screen where the image is clipped to.
  125. This pointer can be 0. Then the image is not clipped.
  126. \param color: Color with which the image is colored.
  127. Note that the alpha component is used: If alpha is other than 255, the image will be transparent.
  128. \param useAlphaChannelOfTexture: If true, the alpha channel of the texture is
  129. used to draw the image. */
  130. virtual void draw2DImageBatch(const video::ITexture* texture,
  131. const core::position2d<s32>& pos,
  132. const core::array<core::rect<s32> >& sourceRects,
  133. const core::array<s32>& indices,
  134. s32 kerningWidth = 0,
  135. const core::rect<s32>* clipRect = 0,
  136. SColor color=SColor(255,255,255,255),
  137. bool useAlphaChannelOfTexture=false);
  138. //! Draws a set of 2d images, using a color and the alpha channel of the texture.
  139. /** All drawings are clipped against clipRect (if != 0).
  140. The subtextures are defined by the array of sourceRects and are
  141. positioned using the array of positions.
  142. \param texture Texture to be drawn.
  143. \param pos Array of upper left 2d destinations where the images
  144. will be drawn.
  145. \param sourceRects Source rectangles of the image.
  146. \param clipRect Pointer to rectangle on the screen where the
  147. images are clipped to.
  148. If this pointer is 0 then the image is not clipped.
  149. \param color Color with which the image is drawn.
  150. Note that the alpha component is used. If alpha is other than
  151. 255, the image will be transparent.
  152. \param useAlphaChannelOfTexture: If true, the alpha channel of
  153. the texture is used to draw the image. */
  154. virtual void draw2DImageBatch(const video::ITexture* texture,
  155. const core::array<core::position2d<s32> >& positions,
  156. const core::array<core::rect<s32> >& sourceRects,
  157. const core::rect<s32>* clipRect=0,
  158. SColor color=SColor(255,255,255,255),
  159. bool useAlphaChannelOfTexture=false);
  160. //! Draws a 2d image, using a color (if color is other then Color(255,255,255,255)) and the alpha channel of the texture if wanted.
  161. virtual void draw2DImage(const video::ITexture* texture, const core::position2d<s32>& destPos,
  162. const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
  163. SColor color=SColor(255,255,255,255), bool useAlphaChannelOfTexture=false);
  164. //! Draws a part of the texture into the rectangle.
  165. virtual void draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect,
  166. const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
  167. const video::SColor* const colors=0, bool useAlphaChannelOfTexture=false);
  168. //! Draws a 2d rectangle
  169. virtual void draw2DRectangle(SColor color, const core::rect<s32>& pos, const core::rect<s32>* clip = 0);
  170. //! Draws a 2d rectangle with a gradient.
  171. virtual void draw2DRectangle(const core::rect<s32>& pos,
  172. SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown,
  173. const core::rect<s32>* clip = 0);
  174. //! Draws the outline of a 2d rectangle
  175. virtual void draw2DRectangleOutline(const core::recti& pos, SColor color=SColor(255,255,255,255));
  176. //! Draws a 2d line.
  177. virtual void draw2DLine(const core::position2d<s32>& start,
  178. const core::position2d<s32>& end,
  179. SColor color=SColor(255,255,255,255));
  180. //! Draws a pixel
  181. virtual void drawPixel(u32 x, u32 y, const SColor & color);
  182. //! Draws a non filled concyclic reqular 2d polyon.
  183. virtual void draw2DPolygon(core::position2d<s32> center,
  184. f32 radius, video::SColor Color, s32 vertexCount);
  185. virtual void setFog(SColor color=SColor(0,255,255,255),
  186. E_FOG_TYPE fogType=EFT_FOG_LINEAR,
  187. f32 start=50.0f, f32 end=100.0f, f32 density=0.01f,
  188. bool pixelFog=false, bool rangeFog=false);
  189. virtual void getFog(SColor& color, E_FOG_TYPE& fogType,
  190. f32& start, f32& end, f32& density,
  191. bool& pixelFog, bool& rangeFog);
  192. //! get color format of the current color buffer
  193. virtual ECOLOR_FORMAT getColorFormat() const;
  194. //! get screen size
  195. virtual const core::dimension2d<u32>& getScreenSize() const;
  196. //! get render target size
  197. virtual const core::dimension2d<u32>& getCurrentRenderTargetSize() const;
  198. // get current frames per second value
  199. virtual s32 getFPS() const;
  200. //! returns amount of primitives (mostly triangles) were drawn in the last frame.
  201. //! very useful method for statistics.
  202. virtual u32 getPrimitiveCountDrawn( u32 param = 0 ) const;
  203. //! deletes all dynamic lights there are
  204. virtual void deleteAllDynamicLights();
  205. //! adds a dynamic light, returning an index to the light
  206. //! \param light: the light data to use to create the light
  207. //! \return An index to the light, or -1 if an error occurs
  208. virtual s32 addDynamicLight(const SLight& light);
  209. //! Turns a dynamic light on or off
  210. //! \param lightIndex: the index returned by addDynamicLight
  211. //! \param turnOn: true to turn the light on, false to turn it off
  212. virtual void turnLightOn(s32 lightIndex, bool turnOn);
  213. //! returns the maximal amount of dynamic lights the device can handle
  214. virtual u32 getMaximalDynamicLightAmount() const;
  215. //! \return Returns the name of the video driver. Example: In case of the DIRECT3D8
  216. //! driver, it would return "Direct3D8.1".
  217. virtual const wchar_t* getName() const;
  218. //! Sets the dynamic ambient light color. The default color is
  219. //! (0,0,0,0) which means it is dark.
  220. //! \param color: New color of the ambient light.
  221. virtual void setAmbientLight(const SColorf& color);
  222. //! Adds an external image loader to the engine.
  223. virtual void addExternalImageLoader(IImageLoader* loader);
  224. //! Adds an external image writer to the engine.
  225. virtual void addExternalImageWriter(IImageWriter* writer);
  226. //! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do
  227. //! this: Frist, draw all geometry. Then use this method, to draw the shadow
  228. //! volume. Then, use IVideoDriver::drawStencilShadow() to visualize the shadow.
  229. virtual void drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail=true, u32 debugDataVisible=0);
  230. //! Fills the stencil shadow with color. After the shadow volume has been drawn
  231. //! into the stencil buffer using IVideoDriver::drawStencilShadowVolume(), use this
  232. //! to draw the color of the shadow.
  233. virtual void drawStencilShadow(bool clearStencilBuffer=false,
  234. video::SColor leftUpEdge = video::SColor(0,0,0,0),
  235. video::SColor rightUpEdge = video::SColor(0,0,0,0),
  236. video::SColor leftDownEdge = video::SColor(0,0,0,0),
  237. video::SColor rightDownEdge = video::SColor(0,0,0,0));
  238. //! Returns current amount of dynamic lights set
  239. //! \return Current amount of dynamic lights set
  240. virtual u32 getDynamicLightCount() const;
  241. //! Returns light data which was previously set with IVideDriver::addDynamicLight().
  242. //! \param idx: Zero based index of the light. Must be greater than 0 and smaller
  243. //! than IVideoDriver()::getDynamicLightCount.
  244. //! \return Light data.
  245. virtual const SLight& getDynamicLight(u32 idx) const;
  246. //! Removes a texture from the texture cache and deletes it, freeing lot of
  247. //! memory.
  248. virtual void removeTexture(ITexture* texture);
  249. //! Removes all texture from the texture cache and deletes them, freeing lot of
  250. //! memory.
  251. virtual void removeAllTextures();
  252. //! Creates a render target texture.
  253. virtual ITexture* addRenderTargetTexture(const core::dimension2d<u32>& size,
  254. const io::path& name, const ECOLOR_FORMAT format = ECF_UNKNOWN,
  255. const bool useStencil = false);
  256. //! Creates an 1bit alpha channel of the texture based of an color key.
  257. virtual void makeColorKeyTexture(video::ITexture* texture, video::SColor color, bool zeroTexels) const;
  258. //! Creates an 1bit alpha channel of the texture based of an color key position.
  259. virtual void makeColorKeyTexture(video::ITexture* texture, core::position2d<s32> colorKeyPixelPos, bool zeroTexels) const;
  260. //! Creates a normal map from a height map texture.
  261. //! \param amplitude: Constant value by which the height information is multiplied.
  262. virtual void makeNormalMapTexture(video::ITexture* texture, f32 amplitude=1.0f) const;
  263. //! Returns the maximum amount of primitives (mostly vertices) which
  264. //! the device is able to render with one drawIndexedTriangleList
  265. //! call.
  266. virtual u32 getMaximalPrimitiveCount() const;
  267. //! Enables or disables a texture creation flag.
  268. virtual void setTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag, bool enabled);
  269. //! Returns if a texture creation flag is enabled or disabled.
  270. virtual bool getTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag) const;
  271. //! Creates a software image from a file.
  272. virtual IImage* createImageFromFile(const io::path& filename);
  273. //! Creates a software image from a file.
  274. virtual IImage* createImageFromFile(io::IReadFile* file, video::IImageLoader** loader = NULL);
  275. //! Creates a software image from a byte array.
  276. /** \param useForeignMemory: If true, the image will use the data pointer
  277. directly and own it from now on, which means it will also try to delete [] the
  278. data when the image will be destructed. If false, the memory will by copied. */
  279. virtual IImage* createImageFromData(ECOLOR_FORMAT format,
  280. const core::dimension2d<u32>& size, void *data,
  281. bool ownForeignMemory=true, bool deleteForeignMemory = true);
  282. //! Creates an empty software image.
  283. virtual IImage* createImage(ECOLOR_FORMAT format, const core::dimension2d<u32>& size);
  284. //! Creates a software image from another image.
  285. virtual IImage* createImage(ECOLOR_FORMAT format, IImage *imageToCopy);
  286. //! Creates a software image from part of another image.
  287. virtual IImage* createImage(IImage* imageToCopy,
  288. const core::position2d<s32>& pos,
  289. const core::dimension2d<u32>& size);
  290. //! Creates a software image from part of a texture.
  291. virtual IImage* createImage(ITexture* texture,
  292. const core::position2d<s32>& pos,
  293. const core::dimension2d<u32>& size);
  294. //! Draws a mesh buffer
  295. virtual void drawMeshBuffer(const scene::IMeshBuffer* mb);
  296. //! Draws the normals of a mesh buffer
  297. virtual void drawMeshBufferNormals(const scene::IMeshBuffer* mb, f32 length=10.f, SColor color=0xffffffff);
  298. protected:
  299. struct SHWBufferLink
  300. {
  301. SHWBufferLink(const scene::IMeshBuffer *_MeshBuffer)
  302. :MeshBuffer(_MeshBuffer),
  303. ChangedID_Vertex(0),ChangedID_Index(0),LastUsed(0),
  304. Mapped_Vertex(scene::EHM_NEVER),Mapped_Index(scene::EHM_NEVER)
  305. {
  306. if (MeshBuffer)
  307. MeshBuffer->grab();
  308. }
  309. virtual ~SHWBufferLink()
  310. {
  311. if (MeshBuffer)
  312. MeshBuffer->drop();
  313. }
  314. const scene::IMeshBuffer *MeshBuffer;
  315. u32 ChangedID_Vertex;
  316. u32 ChangedID_Index;
  317. u32 LastUsed;
  318. scene::E_HARDWARE_MAPPING Mapped_Vertex;
  319. scene::E_HARDWARE_MAPPING Mapped_Index;
  320. };
  321. //! Gets hardware buffer link from a meshbuffer (may create or update buffer)
  322. virtual SHWBufferLink *getBufferLink(const scene::IMeshBuffer* mb);
  323. //! updates hardware buffer if needed (only some drivers can)
  324. virtual bool updateHardwareBuffer(SHWBufferLink *HWBuffer) {return false;}
  325. //! Draw hardware buffer (only some drivers can)
  326. virtual void drawHardwareBuffer(SHWBufferLink *HWBuffer) {}
  327. //! Delete hardware buffer
  328. virtual void deleteHardwareBuffer(SHWBufferLink *HWBuffer);
  329. //! Create hardware buffer from mesh (only some drivers can)
  330. virtual SHWBufferLink *createHardwareBuffer(const scene::IMeshBuffer* mb) {return 0;}
  331. public:
  332. //! Update all hardware buffers, remove unused ones
  333. virtual void updateAllHardwareBuffers();
  334. //! Remove hardware buffer
  335. virtual void removeHardwareBuffer(const scene::IMeshBuffer* mb);
  336. //! Remove all hardware buffers
  337. virtual void removeAllHardwareBuffers();
  338. //! is vbo recommended on this mesh?
  339. virtual bool isHardwareBufferRecommend(const scene::IMeshBuffer* mb);
  340. //! Create occlusion query.
  341. /** Use node for identification and mesh for occlusion test. */
  342. virtual void addOcclusionQuery(scene::ISceneNode* node,
  343. const scene::IMesh* mesh=0);
  344. //! Remove occlusion query.
  345. virtual void removeOcclusionQuery(scene::ISceneNode* node);
  346. //! Remove all occlusion queries.
  347. virtual void removeAllOcclusionQueries();
  348. //! Run occlusion query. Draws mesh stored in query.
  349. /** If the mesh shall not be rendered visible, use
  350. overrideMaterial to disable the color and depth buffer. */
  351. virtual void runOcclusionQuery(scene::ISceneNode* node, bool visible=false);
  352. //! Run all occlusion queries. Draws all meshes stored in queries.
  353. /** If the meshes shall not be rendered visible, use
  354. overrideMaterial to disable the color and depth buffer. */
  355. virtual void runAllOcclusionQueries(bool visible=false);
  356. //! Update occlusion query. Retrieves results from GPU.
  357. /** If the query shall not block, set the flag to false.
  358. Update might not occur in this case, though */
  359. virtual void updateOcclusionQuery(scene::ISceneNode* node, bool block=true);
  360. //! Update all occlusion queries. Retrieves results from GPU.
  361. /** If the query shall not block, set the flag to false.
  362. Update might not occur in this case, though */
  363. virtual void updateAllOcclusionQueries(bool block=true);
  364. //! Return query result.
  365. /** Return value is the number of visible pixels/fragments.
  366. The value is a safe approximation, i.e. can be larger than the
  367. actual value of pixels. */
  368. virtual u32 getOcclusionQueryResult(scene::ISceneNode* node) const;
  369. //! Only used by the engine internally.
  370. /** Used to notify the driver that the window was resized. */
  371. virtual void OnResize(const core::dimension2d<u32>& size);
  372. //! Adds a new material renderer to the video device.
  373. virtual s32 addMaterialRenderer(IMaterialRenderer* renderer,
  374. const char* name = 0);
  375. //! Returns driver and operating system specific data about the IVideoDriver.
  376. virtual const SExposedVideoData& getExposedVideoData();
  377. //! Returns type of video driver
  378. virtual E_DRIVER_TYPE getDriverType() const;
  379. //! Returns the transformation set by setTransform
  380. virtual const core::matrix4& getTransform(E_TRANSFORMATION_STATE state) const;
  381. //! Returns pointer to the IGPUProgrammingServices interface.
  382. virtual IGPUProgrammingServices* getGPUProgrammingServices();
  383. //! Adds a new material renderer to the VideoDriver, using pixel and/or
  384. //! vertex shaders to render geometry.
  385. virtual s32 addShaderMaterial(const c8* vertexShaderProgram = 0,
  386. const c8* pixelShaderProgram = 0,
  387. IShaderConstantSetCallBack* callback = 0,
  388. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  389. s32 userData=0);
  390. //! Like IGPUProgrammingServices::addShaderMaterial(), but tries to load the
  391. //! programs from files.
  392. virtual s32 addShaderMaterialFromFiles(io::IReadFile* vertexShaderProgram = 0,
  393. io::IReadFile* pixelShaderProgram = 0,
  394. IShaderConstantSetCallBack* callback = 0,
  395. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  396. s32 userData=0);
  397. //! Like IGPUProgrammingServices::addShaderMaterial(), but tries to load the
  398. //! programs from files.
  399. virtual s32 addShaderMaterialFromFiles(const io::path& vertexShaderProgramFileName,
  400. const io::path& pixelShaderProgramFileName,
  401. IShaderConstantSetCallBack* callback = 0,
  402. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  403. s32 userData=0);
  404. //! Returns pointer to material renderer or null
  405. virtual IMaterialRenderer* getMaterialRenderer(u32 idx);
  406. //! Returns amount of currently available material renderers.
  407. virtual u32 getMaterialRendererCount() const;
  408. //! Returns name of the material renderer
  409. virtual const char* getMaterialRendererName(u32 idx) const;
  410. //! Adds a new material renderer to the VideoDriver, based on a high level shading
  411. //! language. Currently only HLSL in D3D9 is supported.
  412. virtual s32 addHighLevelShaderMaterial(
  413. const c8* vertexShaderProgram,
  414. const c8* vertexShaderEntryPointName = 0,
  415. E_VERTEX_SHADER_TYPE vsCompileTarget = EVST_VS_1_1,
  416. const c8* pixelShaderProgram = 0,
  417. const c8* pixelShaderEntryPointName = 0,
  418. E_PIXEL_SHADER_TYPE psCompileTarget = EPST_PS_1_1,
  419. const c8* geometryShaderProgram = 0,
  420. const c8* geometryShaderEntryPointName = "main",
  421. E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0,
  422. scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES,
  423. scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP,
  424. u32 verticesOut = 0,
  425. IShaderConstantSetCallBack* callback = 0,
  426. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  427. s32 userData = 0, E_GPU_SHADING_LANGUAGE shadingLang = EGSL_DEFAULT);
  428. //! Like IGPUProgrammingServices::addShaderMaterial() (look there for a detailed description),
  429. //! but tries to load the programs from files.
  430. virtual s32 addHighLevelShaderMaterialFromFiles(
  431. const io::path& vertexShaderProgramFile,
  432. const c8* vertexShaderEntryPointName = "main",
  433. E_VERTEX_SHADER_TYPE vsCompileTarget = EVST_VS_1_1,
  434. const io::path& pixelShaderProgramFile = "",
  435. const c8* pixelShaderEntryPointName = "main",
  436. E_PIXEL_SHADER_TYPE psCompileTarget = EPST_PS_1_1,
  437. const io::path& geometryShaderProgramFileName="",
  438. const c8* geometryShaderEntryPointName = "main",
  439. E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0,
  440. scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES,
  441. scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP,
  442. u32 verticesOut = 0,
  443. IShaderConstantSetCallBack* callback = 0,
  444. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  445. s32 userData = 0, E_GPU_SHADING_LANGUAGE shadingLang = EGSL_DEFAULT);
  446. //! Like IGPUProgrammingServices::addShaderMaterial() (look there for a detailed description),
  447. //! but tries to load the programs from files.
  448. virtual s32 addHighLevelShaderMaterialFromFiles(
  449. io::IReadFile* vertexShaderProgram,
  450. const c8* vertexShaderEntryPointName = "main",
  451. E_VERTEX_SHADER_TYPE vsCompileTarget = EVST_VS_1_1,
  452. io::IReadFile* pixelShaderProgram = 0,
  453. const c8* pixelShaderEntryPointName = "main",
  454. E_PIXEL_SHADER_TYPE psCompileTarget = EPST_PS_1_1,
  455. io::IReadFile* geometryShaderProgram= 0,
  456. const c8* geometryShaderEntryPointName = "main",
  457. E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0,
  458. scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES,
  459. scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP,
  460. u32 verticesOut = 0,
  461. IShaderConstantSetCallBack* callback = 0,
  462. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  463. s32 userData = 0, E_GPU_SHADING_LANGUAGE shadingLang = EGSL_DEFAULT);
  464. //! Returns a pointer to the mesh manipulator.
  465. virtual scene::IMeshManipulator* getMeshManipulator();
  466. //! Clears the ZBuffer.
  467. virtual void clearZBuffer();
  468. //! Returns an image created from the last rendered frame.
  469. virtual IImage* createScreenShot(video::ECOLOR_FORMAT format=video::ECF_UNKNOWN, video::E_RENDER_TARGET target=video::ERT_FRAME_BUFFER);
  470. //! Writes the provided image to disk file
  471. virtual bool writeImageToFile(IImage* image, const io::path& filename, u32 param = 0);
  472. //! Writes the provided image to a file.
  473. virtual bool writeImageToFile(IImage* image, io::IWriteFile * file, u32 param = 0);
  474. //! Sets the name of a material renderer.
  475. virtual void setMaterialRendererName(s32 idx, const char* name);
  476. //! Creates material attributes list from a material, usable for serialization and more.
  477. virtual io::IAttributes* createAttributesFromMaterial(const video::SMaterial& material,
  478. io::SAttributeReadWriteOptions* options=0);
  479. //! Fills an SMaterial structure from attributes.
  480. virtual void fillMaterialStructureFromAttributes(video::SMaterial& outMaterial, io::IAttributes* attributes);
  481. //! looks if the image is already loaded
  482. virtual video::ITexture* findTexture(const io::path& filename);
  483. //! Set/unset a clipping plane.
  484. //! There are at least 6 clipping planes available for the user to set at will.
  485. //! \param index: The plane index. Must be between 0 and MaxUserClipPlanes.
  486. //! \param plane: The plane itself.
  487. //! \param enable: If true, enable the clipping plane else disable it.
  488. virtual bool setClipPlane(u32 index, const core::plane3df& plane, bool enable=false);
  489. //! Enable/disable a clipping plane.
  490. //! There are at least 6 clipping planes available for the user to set at will.
  491. //! \param index: The plane index. Must be between 0 and MaxUserClipPlanes.
  492. //! \param enable: If true, enable the clipping plane else disable it.
  493. virtual void enableClipPlane(u32 index, bool enable);
  494. //! Returns the graphics card vendor name.
  495. virtual core::stringc getVendorInfo() {return "Not available on this driver.";}
  496. //! Set the minimum number of vertices for which a hw buffer will be created
  497. /** \param count Number of vertices to set as minimum. */
  498. virtual void setMinHardwareBufferVertexCount(u32 count);
  499. //! Get the global Material, which might override local materials.
  500. /** Depending on the enable flags, values from this Material
  501. are used to override those of local materials of some
  502. meshbuffer being rendered. */
  503. virtual SOverrideMaterial& getOverrideMaterial();
  504. //! Get the 2d override material for altering its values
  505. virtual SMaterial& getMaterial2D();
  506. //! Enable the 2d override material
  507. virtual void enableMaterial2D(bool enable=true);
  508. //! Only used by the engine internally.
  509. virtual void setAllowZWriteOnTransparent(bool flag)
  510. { AllowZWriteOnTransparent=flag; }
  511. //! Returns the maximum texture size supported.
  512. virtual core::dimension2du getMaxTextureSize() const;
  513. //! Color conversion convenience function
  514. /** Convert an image (as array of pixels) from source to destination
  515. array, thereby converting the color format. The pixel size is
  516. determined by the color formats.
  517. \param sP Pointer to source
  518. \param sF Color format of source
  519. \param sN Number of pixels to convert, both array must be large enough
  520. \param dP Pointer to destination
  521. \param dF Color format of destination
  522. */
  523. virtual void convertColor(const void* sP, ECOLOR_FORMAT sF, s32 sN,
  524. void* dP, ECOLOR_FORMAT dF) const;
  525. //! deprecated method
  526. virtual ITexture* createRenderTargetTexture(const core::dimension2d<u32>& size,
  527. const c8* name=0);
  528. virtual bool checkDriverReset() {return false;}
  529. protected:
  530. //! deletes all textures
  531. void deleteAllTextures();
  532. //! opens the file and loads it into the surface
  533. video::ITexture* loadTextureFromFile(io::IReadFile* file, const io::path& hashName = "");
  534. //! adds a surface, not loaded or created by the Irrlicht Engine
  535. void addTexture(video::ITexture* surface);
  536. //! Creates a texture from a loaded IImage.
  537. virtual ITexture* addTexture(const io::path& name, IImage* image, void* mipmapData=0);
  538. //! returns a device dependent texture from a software surface (IImage)
  539. //! THIS METHOD HAS TO BE OVERRIDDEN BY DERIVED DRIVERS WITH OWN TEXTURES
  540. virtual video::ITexture* createDeviceDependentTexture(IImage* surface, const io::path& name, void* mipmapData=0);
  541. //! checks triangle count and print warning if wrong
  542. bool checkPrimitiveCount(u32 prmcnt) const;
  543. // adds a material renderer and drops it afterwards. To be used for internal creation
  544. s32 addAndDropMaterialRenderer(IMaterialRenderer* m);
  545. //! deletes all material renderers
  546. void deleteMaterialRenders();
  547. // prints renderer version
  548. void printVersion();
  549. //! normal map lookup 32 bit version
  550. inline f32 nml32(int x, int y, int pitch, int height, s32 *p) const
  551. {
  552. if (x < 0) x = pitch-1;
  553. if (x >= pitch) x = 0;
  554. if (y < 0) y = height-1;
  555. if (y >= height) y = 0;
  556. return (f32)(((p[(y * pitch) + x])>>16) & 0xff);
  557. }
  558. //! normal map lookup 16 bit version
  559. inline f32 nml16(int x, int y, int pitch, int height, s16 *p) const
  560. {
  561. if (x < 0) x = pitch-1;
  562. if (x >= pitch) x = 0;
  563. if (y < 0) y = height-1;
  564. if (y >= height) y = 0;
  565. return (f32) getAverage ( p[(y * pitch) + x] );
  566. }
  567. struct SSurface
  568. {
  569. video::ITexture* Surface;
  570. bool operator < (const SSurface& other) const
  571. {
  572. return Surface->getName() < other.Surface->getName();
  573. }
  574. };
  575. struct SMaterialRenderer
  576. {
  577. core::stringc Name;
  578. IMaterialRenderer* Renderer;
  579. };
  580. struct SDummyTexture : public ITexture
  581. {
  582. SDummyTexture(const io::path& name) : ITexture(name), size(0,0) {};
  583. virtual void* lock(E_TEXTURE_LOCK_MODE mode=ETLM_READ_WRITE, u32 mipmapLevel=0) { return 0; };
  584. virtual void unlock(){}
  585. virtual const core::dimension2d<u32>& getOriginalSize() const { return size; }
  586. virtual const core::dimension2d<u32>& getSize() const { return size; }
  587. virtual E_DRIVER_TYPE getDriverType() const { return video::EDT_NULL; }
  588. virtual ECOLOR_FORMAT getColorFormat() const { return video::ECF_A1R5G5B5; };
  589. virtual u32 getPitch() const { return 0; }
  590. virtual u32 getOpenGLTextureName() const { return 0; }
  591. virtual u64 getHandle() { return 0; }
  592. virtual void regenerateMipMapLevels(void* mipmapData=0) {};
  593. core::dimension2d<u32> size;
  594. };
  595. core::array<SSurface> Textures;
  596. struct SOccQuery
  597. {
  598. SOccQuery(scene::ISceneNode* node, const scene::IMesh* mesh=0) : Node(node), Mesh(mesh), PID(0), Result(~0), Run(~0)
  599. {
  600. if (Node)
  601. Node->grab();
  602. if (Mesh)
  603. Mesh->grab();
  604. }
  605. SOccQuery(const SOccQuery& other) : Node(other.Node), Mesh(other.Mesh), PID(other.PID), Result(other.Result), Run(other.Run)
  606. {
  607. if (Node)
  608. Node->grab();
  609. if (Mesh)
  610. Mesh->grab();
  611. }
  612. ~SOccQuery()
  613. {
  614. if (Node)
  615. Node->drop();
  616. if (Mesh)
  617. Mesh->drop();
  618. }
  619. SOccQuery& operator=(const SOccQuery& other)
  620. {
  621. Node=other.Node;
  622. Mesh=other.Mesh;
  623. PID=other.PID;
  624. Result=other.Result;
  625. Run=other.Run;
  626. if (Node)
  627. Node->grab();
  628. if (Mesh)
  629. Mesh->grab();
  630. return *this;
  631. }
  632. bool operator==(const SOccQuery& other) const
  633. {
  634. return other.Node==Node;
  635. }
  636. scene::ISceneNode* Node;
  637. const scene::IMesh* Mesh;
  638. union
  639. {
  640. void* PID;
  641. unsigned int UID;
  642. };
  643. u32 Result;
  644. u32 Run;
  645. };
  646. core::array<SOccQuery> OcclusionQueries;
  647. core::array<video::IImageLoader*> SurfaceLoader;
  648. core::array<video::IImageWriter*> SurfaceWriter;
  649. core::array<SLight> Lights;
  650. core::array<SMaterialRenderer> MaterialRenderers;
  651. //core::array<SHWBufferLink*> HWBufferLinks;
  652. core::map< const scene::IMeshBuffer* , SHWBufferLink* > HWBufferMap;
  653. io::IFileSystem* FileSystem;
  654. //! mesh manipulator
  655. scene::IMeshManipulator* MeshManipulator;
  656. core::rect<s32> ViewPort;
  657. core::dimension2d<u32> ScreenSize;
  658. core::matrix4 TransformationMatrix;
  659. CFPSCounter FPSCounter;
  660. u32 PrimitivesDrawn;
  661. u32 MinVertexCountForVBO;
  662. u32 TextureCreationFlags;
  663. f32 FogStart;
  664. f32 FogEnd;
  665. f32 FogDensity;
  666. SColor FogColor;
  667. SExposedVideoData ExposedData;
  668. io::IAttributes* DriverAttributes;
  669. SOverrideMaterial OverrideMaterial;
  670. SMaterial OverrideMaterial2D;
  671. SMaterial InitMaterial2D;
  672. bool OverrideMaterial2DEnabled;
  673. E_FOG_TYPE FogType;
  674. bool PixelFog;
  675. bool RangeFog;
  676. bool AllowZWriteOnTransparent;
  677. bool FeatureEnabled[video::EVDF_COUNT];
  678. };
  679. } // end namespace video
  680. } // end namespace irr
  681. #endif