]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/CNullDriver.h
81993085291a963876ae750388baf35ccf1616d7
[irrlicht.git] / source / Irrlicht / CNullDriver.h
1 // Copyright (C) 2002-2012 Nikolaus Gebhardt\r
2 // This file is part of the "Irrlicht Engine".\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h\r
4 \r
5 #ifndef __C_VIDEO_NULL_H_INCLUDED__\r
6 #define __C_VIDEO_NULL_H_INCLUDED__\r
7 \r
8 #include "IVideoDriver.h"\r
9 #include "IFileSystem.h"\r
10 #include "IImagePresenter.h"\r
11 #include "IGPUProgrammingServices.h"\r
12 #include "irrArray.h"\r
13 #include "irrString.h"\r
14 #include "IAttributes.h"\r
15 #include "IMesh.h"\r
16 #include "IMeshBuffer.h"\r
17 #include "IMeshSceneNode.h"\r
18 #include "CFPSCounter.h"\r
19 #include "S3DVertex.h"\r
20 #include "SVertexIndex.h"\r
21 #include "SExposedVideoData.h"\r
22 #include <list>\r
23 \r
24 namespace irr\r
25 {\r
26 namespace io\r
27 {\r
28         class IWriteFile;\r
29         class IReadFile;\r
30 } // end namespace io\r
31 namespace video\r
32 {\r
33         class IImageLoader;\r
34         class IImageWriter;\r
35 \r
36         class CNullDriver : public IVideoDriver, public IGPUProgrammingServices\r
37         {\r
38         public:\r
39 \r
40                 //! constructor\r
41                 CNullDriver(io::IFileSystem* io, const core::dimension2d<u32>& screenSize);\r
42 \r
43                 //! destructor\r
44                 virtual ~CNullDriver();\r
45 \r
46                 virtual bool beginScene(u16 clearFlag, SColor clearColor = SColor(255,0,0,0), f32 clearDepth = 1.f, u8 clearStencil = 0,\r
47                         const SExposedVideoData& videoData = SExposedVideoData(), core::rect<s32>* sourceRect = 0) override;\r
48 \r
49                 bool endScene() override;\r
50 \r
51                 //! Disable a feature of the driver.\r
52                 void disableFeature(E_VIDEO_DRIVER_FEATURE feature, bool flag=true) override;\r
53 \r
54                 //! queries the features of the driver, returns true if feature is available\r
55                 bool queryFeature(E_VIDEO_DRIVER_FEATURE feature) const override;\r
56 \r
57                 //! Get attributes of the actual video driver\r
58                 const io::IAttributes& getDriverAttributes() const override;\r
59 \r
60                 //! sets transformation\r
61                 void setTransform(E_TRANSFORMATION_STATE state, const core::matrix4& mat) override;\r
62 \r
63                 //! Retrieve the number of image loaders\r
64                 u32 getImageLoaderCount() const override;\r
65 \r
66                 //! Retrieve the given image loader\r
67                 IImageLoader* getImageLoader(u32 n) override;\r
68 \r
69                 //! Retrieve the number of image writers\r
70                 u32 getImageWriterCount() const override;\r
71 \r
72                 //! Retrieve the given image writer\r
73                 IImageWriter* getImageWriter(u32 n) override;\r
74 \r
75                 //! sets a material\r
76                 void setMaterial(const SMaterial& material) override;\r
77 \r
78                 //! loads a Texture\r
79                 ITexture* getTexture(const io::path& filename) override;\r
80 \r
81                 //! loads a Texture\r
82                 ITexture* getTexture(io::IReadFile* file) override;\r
83 \r
84                 //! Returns a texture by index\r
85                 ITexture* getTextureByIndex(u32 index) override;\r
86 \r
87                 //! Returns amount of textures currently loaded\r
88                 u32 getTextureCount() const override;\r
89 \r
90                 //! Renames a texture\r
91                 void renameTexture(ITexture* texture, const io::path& newName) override;\r
92 \r
93                 ITexture* addTexture(const core::dimension2d<u32>& size, const io::path& name, ECOLOR_FORMAT format = ECF_A8R8G8B8) override;\r
94 \r
95                 ITexture* addTexture(const io::path& name, IImage* image) override;\r
96 \r
97                 virtual ITexture* addTextureCubemap(const io::path& name, IImage* imagePosX, IImage* imageNegX, IImage* imagePosY,\r
98                         IImage* imageNegY, IImage* imagePosZ, IImage* imageNegZ) override;\r
99 \r
100                 ITexture* addTextureCubemap(const irr::u32 sideLen, const io::path& name, ECOLOR_FORMAT format = ECF_A8R8G8B8) override;\r
101 \r
102                 virtual bool setRenderTargetEx(IRenderTarget* target, u16 clearFlag, SColor clearColor = SColor(255,0,0,0),\r
103                         f32 clearDepth = 1.f, u8 clearStencil = 0) override;\r
104 \r
105                 virtual bool setRenderTarget(ITexture* texture, u16 clearFlag, SColor clearColor = SColor(255,0,0,0),\r
106                         f32 clearDepth = 1.f, u8 clearStencil = 0) override;\r
107 \r
108                 //! sets a viewport\r
109                 void setViewPort(const core::rect<s32>& area) override;\r
110 \r
111                 //! gets the area of the current viewport\r
112                 const core::rect<s32>& getViewPort() const override;\r
113 \r
114                 //! draws a vertex primitive list\r
115                 virtual void drawVertexPrimitiveList(const void* vertices, u32 vertexCount,\r
116                                 const void* indexList, u32 primitiveCount,\r
117                                 E_VERTEX_TYPE vType=EVT_STANDARD, scene::E_PRIMITIVE_TYPE pType=scene::EPT_TRIANGLES,\r
118                                 E_INDEX_TYPE iType=EIT_16BIT) override;\r
119 \r
120                 //! draws a vertex primitive list in 2d\r
121                 virtual void draw2DVertexPrimitiveList(const void* vertices, u32 vertexCount,\r
122                                 const void* indexList, u32 primitiveCount,\r
123                                 E_VERTEX_TYPE vType=EVT_STANDARD, scene::E_PRIMITIVE_TYPE pType=scene::EPT_TRIANGLES,\r
124                                 E_INDEX_TYPE iType=EIT_16BIT) override;\r
125 \r
126                 //! Draws a 3d line.\r
127                 virtual void draw3DLine(const core::vector3df& start,\r
128                         const core::vector3df& end, SColor color = SColor(255,255,255,255)) override;\r
129 \r
130                 //! Draws a 3d triangle.\r
131                 virtual void draw3DTriangle(const core::triangle3df& triangle,\r
132                         SColor color = SColor(255,255,255,255)) override;\r
133 \r
134                 //! Draws a 3d axis aligned box.\r
135                 virtual void draw3DBox(const core::aabbox3d<f32>& box,\r
136                         SColor color = SColor(255,255,255,255)) override;\r
137 \r
138                 //! draws an 2d image\r
139                 void draw2DImage(const video::ITexture* texture, const core::position2d<s32>& destPos, bool useAlphaChannelOfTexture) override;\r
140 \r
141                 //! draws a set of 2d images, using a color and the alpha\r
142                 /** channel of the texture if desired. The images are drawn\r
143                 beginning at pos and concatenated in one line. All drawings\r
144                 are clipped against clipRect (if != 0).\r
145                 The subtextures are defined by the array of sourceRects\r
146                 and are chosen by the indices given.\r
147                 \param texture: Texture to be drawn.\r
148                 \param pos: Upper left 2d destination position where the image will be drawn.\r
149                 \param sourceRects: Source rectangles of the image.\r
150                 \param indices: List of indices which choose the actual rectangle used each time.\r
151                 \param kerningWidth: offset on position\r
152                 \param clipRect: Pointer to rectangle on the screen where the image is clipped to.\r
153                 This pointer can be 0. Then the image is not clipped.\r
154                 \param color: Color with which the image is colored.\r
155                 Note that the alpha component is used: If alpha is other than 255, the image will be transparent.\r
156                 \param useAlphaChannelOfTexture: If true, the alpha channel of the texture is\r
157                 used to draw the image. */\r
158                 virtual void draw2DImageBatch(const video::ITexture* texture,\r
159                                 const core::position2d<s32>& pos,\r
160                                 const core::array<core::rect<s32> >& sourceRects,\r
161                                 const core::array<s32>& indices,\r
162                                 s32 kerningWidth = 0,\r
163                                 const core::rect<s32>* clipRect = 0,\r
164                                 SColor color=SColor(255,255,255,255),\r
165                                 bool useAlphaChannelOfTexture=false) override;\r
166 \r
167                 //! Draws a set of 2d images, using a color and the alpha channel of the texture.\r
168                 /** All drawings are clipped against clipRect (if != 0).\r
169                 The subtextures are defined by the array of sourceRects and are\r
170                 positioned using the array of positions.\r
171                 \param texture Texture to be drawn.\r
172                 \param pos Array of upper left 2d destinations where the images\r
173                 will be drawn.\r
174                 \param sourceRects Source rectangles of the image.\r
175                 \param clipRect Pointer to rectangle on the screen where the\r
176                 images are clipped to.\r
177                 If this pointer is 0 then the image is not clipped.\r
178                 \param color Color with which the image is drawn.\r
179                 Note that the alpha component is used. If alpha is other than\r
180                 255, the image will be transparent.\r
181                 \param useAlphaChannelOfTexture: If true, the alpha channel of\r
182                 the texture is used to draw the image. */\r
183                 virtual void draw2DImageBatch(const video::ITexture* texture,\r
184                                 const core::array<core::position2d<s32> >& positions,\r
185                                 const core::array<core::rect<s32> >& sourceRects,\r
186                                 const core::rect<s32>* clipRect=0,\r
187                                 SColor color=SColor(255,255,255,255),\r
188                                 bool useAlphaChannelOfTexture=false) override;\r
189 \r
190                 //! 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.\r
191                 virtual void draw2DImage(const video::ITexture* texture, const core::position2d<s32>& destPos,\r
192                         const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,\r
193                         SColor color=SColor(255,255,255,255), bool useAlphaChannelOfTexture=false) override;\r
194 \r
195                 //! Draws a part of the texture into the rectangle.\r
196                 virtual void draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect,\r
197                         const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,\r
198                         const video::SColor* const colors=0, bool useAlphaChannelOfTexture=false) override;\r
199 \r
200                 //! Draws a 2d rectangle\r
201                 void draw2DRectangle(SColor color, const core::rect<s32>& pos, const core::rect<s32>* clip = 0) override;\r
202 \r
203                 //! Draws a 2d rectangle with a gradient.\r
204                 virtual void draw2DRectangle(const core::rect<s32>& pos,\r
205                         SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown,\r
206                         const core::rect<s32>* clip = 0) override;\r
207 \r
208                 //! Draws the outline of a 2d rectangle\r
209                 void draw2DRectangleOutline(const core::recti& pos, SColor color=SColor(255,255,255,255)) override;\r
210 \r
211                 //! Draws a 2d line.\r
212                 virtual void draw2DLine(const core::position2d<s32>& start,\r
213                                         const core::position2d<s32>& end,\r
214                                         SColor color=SColor(255,255,255,255)) override;\r
215 \r
216                 //! Draws a pixel\r
217                 void drawPixel(u32 x, u32 y, const SColor & color) override;\r
218 \r
219                 //! Draws a non filled concyclic reqular 2d polygon.\r
220                 virtual void draw2DPolygon(core::position2d<s32> center,\r
221                         f32 radius, video::SColor Color, s32 vertexCount) override;\r
222 \r
223                 virtual void setFog(SColor color=SColor(0,255,255,255),\r
224                                 E_FOG_TYPE fogType=EFT_FOG_LINEAR,\r
225                                 f32 start=50.0f, f32 end=100.0f, f32 density=0.01f,\r
226                                 bool pixelFog=false, bool rangeFog=false) override;\r
227 \r
228                 virtual void getFog(SColor& color, E_FOG_TYPE& fogType,\r
229                                 f32& start, f32& end, f32& density,\r
230                                 bool& pixelFog, bool& rangeFog) override;\r
231 \r
232                 //! get color format of the current color buffer\r
233                 ECOLOR_FORMAT getColorFormat() const override;\r
234 \r
235                 //! get screen size\r
236                 const core::dimension2d<u32>& getScreenSize() const override;\r
237 \r
238                 //! get current render target\r
239                 IRenderTarget* getCurrentRenderTarget() const;\r
240 \r
241                 //! get render target size\r
242                 const core::dimension2d<u32>& getCurrentRenderTargetSize() const override;\r
243 \r
244                 // get current frames per second value\r
245                 s32 getFPS() const override;\r
246 \r
247                 //! returns amount of primitives (mostly triangles) were drawn in the last frame.\r
248                 //! very useful method for statistics.\r
249                 u32 getPrimitiveCountDrawn( u32 param = 0 ) const override;\r
250 \r
251                 //! \return Returns the name of the video driver. Example: In case of the DIRECT3D8\r
252                 //! driver, it would return "Direct3D8.1".\r
253                 const wchar_t* getName() const override;\r
254 \r
255                 //! Sets the dynamic ambient light color. The default color is\r
256                 //! (0,0,0,0) which means it is dark.\r
257                 //! \param color: New color of the ambient light.\r
258                 void setAmbientLight(const SColorf& color) override;\r
259 \r
260                 //! Get the global ambient light currently used by the driver\r
261                 const SColorf& getAmbientLight() const override;\r
262 \r
263                 //! Adds an external image loader to the engine.\r
264                 void addExternalImageLoader(IImageLoader* loader) override;\r
265 \r
266                 //! Adds an external image writer to the engine.\r
267                 void addExternalImageWriter(IImageWriter* writer) override;\r
268 \r
269                 //! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do\r
270                 //! this: First, draw all geometry. Then use this method, to draw the shadow\r
271                 //! volume. Then, use IVideoDriver::drawStencilShadow() to visualize the shadow.\r
272                 virtual void drawStencilShadowVolume(const core::array<core::vector3df>& triangles,\r
273                         bool zfail=true, u32 debugDataVisible=0) override;\r
274 \r
275                 //! Fills the stencil shadow with color. After the shadow volume has been drawn\r
276                 //! into the stencil buffer using IVideoDriver::drawStencilShadowVolume(), use this\r
277                 //! to draw the color of the shadow.\r
278                 virtual void drawStencilShadow(bool clearStencilBuffer=false,\r
279                         video::SColor leftUpEdge = video::SColor(0,0,0,0),\r
280                         video::SColor rightUpEdge = video::SColor(0,0,0,0),\r
281                         video::SColor leftDownEdge = video::SColor(0,0,0,0),\r
282                         video::SColor rightDownEdge = video::SColor(0,0,0,0)) override;\r
283 \r
284 \r
285                 //! Removes a texture from the texture cache and deletes it, freeing lot of\r
286                 //! memory.\r
287                 void removeTexture(ITexture* texture) override;\r
288 \r
289                 //! Removes all texture from the texture cache and deletes them, freeing lot of\r
290                 //! memory.\r
291                 void removeAllTextures() override;\r
292 \r
293                 //! Creates a render target texture.\r
294                 virtual ITexture* addRenderTargetTexture(const core::dimension2d<u32>& size,\r
295                         const io::path& name, const ECOLOR_FORMAT format = ECF_UNKNOWN) override;\r
296 \r
297                 //! Creates a render target texture for a cubemap\r
298                 ITexture* addRenderTargetTextureCubemap(const irr::u32 sideLen,\r
299                                 const io::path& name, const ECOLOR_FORMAT format) override;\r
300 \r
301                 //! Creates an 1bit alpha channel of the texture based of an color key.\r
302                 void makeColorKeyTexture(video::ITexture* texture, video::SColor color, bool zeroTexels) const override;\r
303 \r
304                 //! Creates an 1bit alpha channel of the texture based of an color key position.\r
305                 virtual void makeColorKeyTexture(video::ITexture* texture, core::position2d<s32> colorKeyPixelPos,\r
306                         bool zeroTexels) const override;\r
307 \r
308                 //! Returns the maximum amount of primitives (mostly vertices) which\r
309                 //! the device is able to render with one drawIndexedTriangleList\r
310                 //! call.\r
311                 u32 getMaximalPrimitiveCount() const override;\r
312 \r
313                 //! Enables or disables a texture creation flag.\r
314                 void setTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag, bool enabled) override;\r
315 \r
316                 //! Returns if a texture creation flag is enabled or disabled.\r
317                 bool getTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag) const override;\r
318 \r
319                 core::array<IImage*> createImagesFromFile(const io::path& filename, E_TEXTURE_TYPE* type = 0) override;\r
320 \r
321                 core::array<IImage*> createImagesFromFile(io::IReadFile* file, E_TEXTURE_TYPE* type = 0) override;\r
322 \r
323                 //! Creates a software image from a byte array.\r
324                 /** \param useForeignMemory: If true, the image will use the data pointer\r
325                 directly and own it from now on, which means it will also try to delete [] the\r
326                 data when the image will be destructed. If false, the memory will by copied. */\r
327                 virtual IImage* createImageFromData(ECOLOR_FORMAT format,\r
328                         const core::dimension2d<u32>& size, void *data, bool ownForeignMemory = false,\r
329                         bool deleteMemory = true) override;\r
330 \r
331                 //! Creates an empty software image.\r
332                 IImage* createImage(ECOLOR_FORMAT format, const core::dimension2d<u32>& size) override;\r
333 \r
334                 //! Creates a software image from another image.\r
335                 IImage* createImage(ECOLOR_FORMAT format, IImage *imageToCopy) override;\r
336 \r
337                 //! Creates a software image from part of another image.\r
338                 virtual IImage* createImage(IImage* imageToCopy,\r
339                                 const core::position2d<s32>& pos,\r
340                                 const core::dimension2d<u32>& size) override;\r
341 \r
342                 //! Creates a software image from part of a texture.\r
343                 virtual IImage* createImage(ITexture* texture,\r
344                                 const core::position2d<s32>& pos,\r
345                                 const core::dimension2d<u32>& size) override;\r
346 \r
347                 //! Draws a mesh buffer\r
348                 void drawMeshBuffer(const scene::IMeshBuffer* mb) override;\r
349 \r
350                 //! Draws the normals of a mesh buffer\r
351                 virtual void drawMeshBufferNormals(const scene::IMeshBuffer* mb, f32 length=10.f,\r
352                         SColor color=0xffffffff) override;\r
353 \r
354                 //! Check if the driver supports creating textures with the given color format\r
355                 bool queryTextureFormat(ECOLOR_FORMAT format) const override\r
356                 {\r
357                         return false;\r
358                 }\r
359 \r
360         protected:\r
361                 struct SHWBufferLink\r
362                 {\r
363                         SHWBufferLink(const scene::IMeshBuffer *_MeshBuffer)\r
364                                 :MeshBuffer(_MeshBuffer),\r
365                                 ChangedID_Vertex(0),ChangedID_Index(0),\r
366                                 Mapped_Vertex(scene::EHM_NEVER),Mapped_Index(scene::EHM_NEVER)\r
367                         {\r
368                                 if (MeshBuffer) {\r
369                                         MeshBuffer->grab();\r
370                                         MeshBuffer->setHWBuffer(reinterpret_cast<void*>(this));\r
371                                 }\r
372                         }\r
373 \r
374                         virtual ~SHWBufferLink()\r
375                         {\r
376                                 if (MeshBuffer) {\r
377                                         MeshBuffer->setHWBuffer(NULL);\r
378                                         MeshBuffer->drop();\r
379                                 }\r
380                         }\r
381 \r
382                         const scene::IMeshBuffer *MeshBuffer;\r
383                         u32 ChangedID_Vertex;\r
384                         u32 ChangedID_Index;\r
385                         scene::E_HARDWARE_MAPPING Mapped_Vertex;\r
386                         scene::E_HARDWARE_MAPPING Mapped_Index;\r
387                         std::list<SHWBufferLink*>::iterator listPosition;\r
388                 };\r
389 \r
390                 //! Gets hardware buffer link from a meshbuffer (may create or update buffer)\r
391                 virtual SHWBufferLink *getBufferLink(const scene::IMeshBuffer* mb);\r
392 \r
393                 //! updates hardware buffer if needed  (only some drivers can)\r
394                 virtual bool updateHardwareBuffer(SHWBufferLink *HWBuffer) {return false;}\r
395 \r
396                 //! Draw hardware buffer (only some drivers can)\r
397                 virtual void drawHardwareBuffer(SHWBufferLink *HWBuffer) {}\r
398 \r
399                 //! Delete hardware buffer\r
400                 virtual void deleteHardwareBuffer(SHWBufferLink *HWBuffer);\r
401 \r
402                 //! Create hardware buffer from mesh (only some drivers can)\r
403                 virtual SHWBufferLink *createHardwareBuffer(const scene::IMeshBuffer* mb) {return 0;}\r
404 \r
405         public:\r
406                 //! Remove hardware buffer\r
407                 void removeHardwareBuffer(const scene::IMeshBuffer* mb) override;\r
408 \r
409                 //! Remove all hardware buffers\r
410                 void removeAllHardwareBuffers() override;\r
411 \r
412                 //! Update all hardware buffers, remove unused ones\r
413                 virtual void updateAllHardwareBuffers();\r
414 \r
415                 //! is vbo recommended on this mesh?\r
416                 virtual bool isHardwareBufferRecommend(const scene::IMeshBuffer* mb);\r
417 \r
418                 //! Create occlusion query.\r
419                 /** Use node for identification and mesh for occlusion test. */\r
420                 virtual void addOcclusionQuery(scene::ISceneNode* node,\r
421                                 const scene::IMesh* mesh=0) override;\r
422 \r
423                 //! Remove occlusion query.\r
424                 void removeOcclusionQuery(scene::ISceneNode* node) override;\r
425 \r
426                 //! Remove all occlusion queries.\r
427                 void removeAllOcclusionQueries() override;\r
428 \r
429                 //! Run occlusion query. Draws mesh stored in query.\r
430                 /** If the mesh shall not be rendered visible, use\r
431                 overrideMaterial to disable the color and depth buffer. */\r
432                 void runOcclusionQuery(scene::ISceneNode* node, bool visible=false) override;\r
433 \r
434                 //! Run all occlusion queries. Draws all meshes stored in queries.\r
435                 /** If the meshes shall not be rendered visible, use\r
436                 overrideMaterial to disable the color and depth buffer. */\r
437                 void runAllOcclusionQueries(bool visible=false) override;\r
438 \r
439                 //! Update occlusion query. Retrieves results from GPU.\r
440                 /** If the query shall not block, set the flag to false.\r
441                 Update might not occur in this case, though */\r
442                 void updateOcclusionQuery(scene::ISceneNode* node, bool block=true) override;\r
443 \r
444                 //! Update all occlusion queries. Retrieves results from GPU.\r
445                 /** If the query shall not block, set the flag to false.\r
446                 Update might not occur in this case, though */\r
447                 void updateAllOcclusionQueries(bool block=true) override;\r
448 \r
449                 //! Return query result.\r
450                 /** Return value is the number of visible pixels/fragments.\r
451                 The value is a safe approximation, i.e. can be larger than the\r
452                 actual value of pixels. */\r
453                 u32 getOcclusionQueryResult(scene::ISceneNode* node) const override;\r
454 \r
455                 //! Create render target.\r
456                 IRenderTarget* addRenderTarget() override;\r
457 \r
458                 //! Remove render target.\r
459                 void removeRenderTarget(IRenderTarget* renderTarget) override;\r
460 \r
461                 //! Remove all render targets.\r
462                 void removeAllRenderTargets() override;\r
463 \r
464                 //! Only used by the engine internally.\r
465                 /** Used to notify the driver that the window was resized. */\r
466                 void OnResize(const core::dimension2d<u32>& size) override;\r
467 \r
468                 //! Adds a new material renderer to the video device.\r
469                 virtual s32 addMaterialRenderer(IMaterialRenderer* renderer,\r
470                                 const char* name = 0) override;\r
471 \r
472                 //! Returns driver and operating system specific data about the IVideoDriver.\r
473                 const SExposedVideoData& getExposedVideoData() override;\r
474 \r
475                 //! Returns type of video driver\r
476                 E_DRIVER_TYPE getDriverType() const override;\r
477 \r
478                 //! Returns the transformation set by setTransform\r
479                 const core::matrix4& getTransform(E_TRANSFORMATION_STATE state) const override;\r
480 \r
481                 //! Returns pointer to the IGPUProgrammingServices interface.\r
482                 IGPUProgrammingServices* getGPUProgrammingServices() override;\r
483 \r
484                 //! Adds a new material renderer to the VideoDriver, using pixel and/or\r
485                 //! vertex shaders to render geometry.\r
486                 virtual s32 addShaderMaterial(const c8* vertexShaderProgram = 0,\r
487                         const c8* pixelShaderProgram = 0,\r
488                         IShaderConstantSetCallBack* callback = 0,\r
489                         E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,\r
490                         s32 userData=0) override;\r
491 \r
492                 //! Like IGPUProgrammingServices::addShaderMaterial(), but tries to load the\r
493                 //! programs from files.\r
494                 virtual s32 addShaderMaterialFromFiles(io::IReadFile* vertexShaderProgram = 0,\r
495                         io::IReadFile* pixelShaderProgram = 0,\r
496                         IShaderConstantSetCallBack* callback = 0,\r
497                         E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,\r
498                         s32 userData=0) override;\r
499 \r
500                 //! Like IGPUProgrammingServices::addShaderMaterial(), but tries to load the\r
501                 //! programs from files.\r
502                 virtual s32 addShaderMaterialFromFiles(const io::path& vertexShaderProgramFileName,\r
503                         const io::path& pixelShaderProgramFileName,\r
504                         IShaderConstantSetCallBack* callback = 0,\r
505                         E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,\r
506                         s32 userData=0) override;\r
507 \r
508                 //! Returns pointer to material renderer or null\r
509                 IMaterialRenderer* getMaterialRenderer(u32 idx) const override;\r
510 \r
511                 //! Returns amount of currently available material renderers.\r
512                 u32 getMaterialRendererCount() const override;\r
513 \r
514                 //! Returns name of the material renderer\r
515                 const char* getMaterialRendererName(u32 idx) const override;\r
516 \r
517                 //! Adds a new material renderer to the VideoDriver, based on a high level shading\r
518                 //! language. Currently only HLSL in D3D9 is supported.\r
519                 virtual s32 addHighLevelShaderMaterial(\r
520                         const c8* vertexShaderProgram,\r
521                         const c8* vertexShaderEntryPointName = 0,\r
522                         E_VERTEX_SHADER_TYPE vsCompileTarget = EVST_VS_1_1,\r
523                         const c8* pixelShaderProgram = 0,\r
524                         const c8* pixelShaderEntryPointName = 0,\r
525                         E_PIXEL_SHADER_TYPE psCompileTarget = EPST_PS_1_1,\r
526                         const c8* geometryShaderProgram = 0,\r
527                         const c8* geometryShaderEntryPointName = "main",\r
528                         E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0,\r
529                         scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES,\r
530                         scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP,\r
531                         u32 verticesOut = 0,\r
532                         IShaderConstantSetCallBack* callback = 0,\r
533                         E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,\r
534                         s32 userData = 0) override;\r
535 \r
536                 //! Like IGPUProgrammingServices::addShaderMaterial() (look there for a detailed description),\r
537                 //! but tries to load the programs from files.\r
538                 virtual s32 addHighLevelShaderMaterialFromFiles(\r
539                         const io::path& vertexShaderProgramFile,\r
540                         const c8* vertexShaderEntryPointName = "main",\r
541                         E_VERTEX_SHADER_TYPE vsCompileTarget = EVST_VS_1_1,\r
542                         const io::path& pixelShaderProgramFile = "",\r
543                         const c8* pixelShaderEntryPointName = "main",\r
544                         E_PIXEL_SHADER_TYPE psCompileTarget = EPST_PS_1_1,\r
545                         const io::path& geometryShaderProgramFileName="",\r
546                         const c8* geometryShaderEntryPointName = "main",\r
547                         E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0,\r
548                         scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES,\r
549                         scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP,\r
550                         u32 verticesOut = 0,\r
551                         IShaderConstantSetCallBack* callback = 0,\r
552                         E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,\r
553                         s32 userData = 0) override;\r
554 \r
555                 //! Like IGPUProgrammingServices::addShaderMaterial() (look there for a detailed description),\r
556                 //! but tries to load the programs from files.\r
557                 virtual s32 addHighLevelShaderMaterialFromFiles(\r
558                         io::IReadFile* vertexShaderProgram,\r
559                         const c8* vertexShaderEntryPointName = "main",\r
560                         E_VERTEX_SHADER_TYPE vsCompileTarget = EVST_VS_1_1,\r
561                         io::IReadFile* pixelShaderProgram = 0,\r
562                         const c8* pixelShaderEntryPointName = "main",\r
563                         E_PIXEL_SHADER_TYPE psCompileTarget = EPST_PS_1_1,\r
564                         io::IReadFile* geometryShaderProgram= 0,\r
565                         const c8* geometryShaderEntryPointName = "main",\r
566                         E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0,\r
567                         scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES,\r
568                         scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP,\r
569                         u32 verticesOut = 0,\r
570                         IShaderConstantSetCallBack* callback = 0,\r
571                         E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,\r
572                         s32 userData = 0) override;\r
573 \r
574                 //! Returns a pointer to the mesh manipulator.\r
575                 scene::IMeshManipulator* getMeshManipulator() override;\r
576 \r
577                 void clearBuffers(u16 flag, SColor color = SColor(255,0,0,0), f32 depth = 1.f, u8 stencil = 0) override;\r
578 \r
579                 //! Returns an image created from the last rendered frame.\r
580                 IImage* createScreenShot(video::ECOLOR_FORMAT format=video::ECF_UNKNOWN, video::E_RENDER_TARGET target=video::ERT_FRAME_BUFFER) override;\r
581 \r
582                 //! Writes the provided image to disk file\r
583                 bool writeImageToFile(IImage* image, const io::path& filename, u32 param = 0) override;\r
584 \r
585                 //! Writes the provided image to a file.\r
586                 bool writeImageToFile(IImage* image, io::IWriteFile * file, u32 param = 0) override;\r
587 \r
588                 //! Sets the name of a material renderer.\r
589                 void setMaterialRendererName(s32 idx, const char* name) override;\r
590 \r
591                 //! Swap the material renderers used for certain id's\r
592                 void swapMaterialRenderers(u32 idx1, u32 idx2, bool swapNames) override;\r
593 \r
594                 //! looks if the image is already loaded\r
595                 video::ITexture* findTexture(const io::path& filename) override;\r
596 \r
597                 //! Set/unset a clipping plane.\r
598                 //! There are at least 6 clipping planes available for the user to set at will.\r
599                 //! \param index: The plane index. Must be between 0 and MaxUserClipPlanes.\r
600                 //! \param plane: The plane itself.\r
601                 //! \param enable: If true, enable the clipping plane else disable it.\r
602                 bool setClipPlane(u32 index, const core::plane3df& plane, bool enable=false) override;\r
603 \r
604                 //! Enable/disable a clipping plane.\r
605                 //! There are at least 6 clipping planes available for the user to set at will.\r
606                 //! \param index: The plane index. Must be between 0 and MaxUserClipPlanes.\r
607                 //! \param enable: If true, enable the clipping plane else disable it.\r
608                 void enableClipPlane(u32 index, bool enable) override;\r
609 \r
610                 //! Returns the graphics card vendor name.\r
611                 core::stringc getVendorInfo() override {return "Not available on this driver.";}\r
612 \r
613                 //! Set the minimum number of vertices for which a hw buffer will be created\r
614                 /** \param count Number of vertices to set as minimum. */\r
615                 void setMinHardwareBufferVertexCount(u32 count) override;\r
616 \r
617                 //! Get the global Material, which might override local materials.\r
618                 /** Depending on the enable flags, values from this Material\r
619                 are used to override those of local materials of some\r
620                 meshbuffer being rendered. */\r
621                 SOverrideMaterial& getOverrideMaterial() override;\r
622 \r
623                 //! Get the 2d override material for altering its values\r
624                 SMaterial& getMaterial2D() override;\r
625 \r
626                 //! Enable the 2d override material\r
627                 void enableMaterial2D(bool enable=true) override;\r
628 \r
629                 //! Only used by the engine internally.\r
630                 void setAllowZWriteOnTransparent(bool flag) override\r
631                 { AllowZWriteOnTransparent=flag; }\r
632 \r
633                 //! Returns the maximum texture size supported.\r
634                 core::dimension2du getMaxTextureSize() const override;\r
635 \r
636                 //! Used by some SceneNodes to check if a material should be rendered in the transparent render pass\r
637                 bool needsTransparentRenderPass(const irr::video::SMaterial& material) const override;\r
638 \r
639                 //! Color conversion convenience function\r
640                 /** Convert an image (as array of pixels) from source to destination\r
641                 array, thereby converting the color format. The pixel size is\r
642                 determined by the color formats.\r
643                 \param sP Pointer to source\r
644                 \param sF Color format of source\r
645                 \param sN Number of pixels to convert, both array must be large enough\r
646                 \param dP Pointer to destination\r
647                 \param dF Color format of destination\r
648                 */\r
649                 virtual void convertColor(const void* sP, ECOLOR_FORMAT sF, s32 sN,\r
650                                 void* dP, ECOLOR_FORMAT dF) const override;\r
651 \r
652                 //! deprecated method\r
653                 virtual ITexture* createRenderTargetTexture(const core::dimension2d<u32>& size,\r
654                                 const c8* name=0);\r
655 \r
656                 bool checkDriverReset() override {return false;}\r
657         protected:\r
658 \r
659                 //! deletes all textures\r
660                 void deleteAllTextures();\r
661 \r
662                 //! opens the file and loads it into the surface\r
663                 ITexture* loadTextureFromFile(io::IReadFile* file, const io::path& hashName = "");\r
664 \r
665                 //! adds a surface, not loaded or created by the Irrlicht Engine\r
666                 void addTexture(ITexture* surface);\r
667                 \r
668                 virtual ITexture* createDeviceDependentTexture(const io::path& name, IImage* image);\r
669 \r
670                 virtual ITexture* createDeviceDependentTextureCubemap(const io::path& name, const core::array<IImage*>& image);\r
671 \r
672                 //! checks triangle count and print warning if wrong\r
673                 bool checkPrimitiveCount(u32 prmcnt) const;\r
674 \r
675                 bool checkImage(const core::array<IImage*>& image) const;\r
676 \r
677                 // adds a material renderer and drops it afterwards. To be used for internal creation\r
678                 s32 addAndDropMaterialRenderer(IMaterialRenderer* m);\r
679 \r
680                 //! deletes all material renderers\r
681                 void deleteMaterialRenders();\r
682 \r
683                 // prints renderer version\r
684                 void printVersion();\r
685 \r
686                 inline bool getWriteZBuffer(const SMaterial& material) const\r
687                 {\r
688                         switch ( material.ZWriteEnable )\r
689                         {\r
690                                 case video::EZW_OFF:\r
691                                         return false;\r
692                                 case video::EZW_AUTO:\r
693                                         return AllowZWriteOnTransparent || ! needsTransparentRenderPass(material);\r
694                                 case video::EZW_ON:\r
695                                         return true;\r
696                         }\r
697                         return true; // never should get here, but some compilers don't know and complain\r
698                 }\r
699 \r
700                 struct SSurface\r
701                 {\r
702                         video::ITexture* Surface;\r
703 \r
704                         bool operator < (const SSurface& other) const\r
705                         {\r
706                                 return Surface->getName() < other.Surface->getName();\r
707                         }\r
708                 };\r
709 \r
710                 struct SMaterialRenderer\r
711                 {\r
712                         core::stringc Name;\r
713                         IMaterialRenderer* Renderer;\r
714                 };\r
715 \r
716                 struct SDummyTexture : public ITexture\r
717                 {\r
718                         SDummyTexture(const io::path& name, E_TEXTURE_TYPE type) : ITexture(name, type) {};\r
719 \r
720                         void setSize(const core::dimension2d<u32>& size) { Size = OriginalSize = size; }\r
721 \r
722                         void* lock(E_TEXTURE_LOCK_MODE mode = ETLM_READ_WRITE, u32 mipmapLevel=0, u32 layer = 0, E_TEXTURE_LOCK_FLAGS lockFlags = ETLF_FLIP_Y_UP_RTT) override { return 0; }\r
723                         void unlock()override {}\r
724                         void regenerateMipMapLevels(void* data = 0, u32 layer = 0) override {}\r
725                 };\r
726                 core::array<SSurface> Textures;\r
727 \r
728                 struct SOccQuery\r
729                 {\r
730                         SOccQuery(scene::ISceneNode* node, const scene::IMesh* mesh=0) : Node(node), Mesh(mesh), PID(0), Result(0xffffffff), Run(0xffffffff)\r
731                         {\r
732                                 if (Node)\r
733                                         Node->grab();\r
734                                 if (Mesh)\r
735                                         Mesh->grab();\r
736                         }\r
737 \r
738                         SOccQuery(const SOccQuery& other) : Node(other.Node), Mesh(other.Mesh), PID(other.PID), Result(other.Result), Run(other.Run)\r
739                         {\r
740                                 if (Node)\r
741                                         Node->grab();\r
742                                 if (Mesh)\r
743                                         Mesh->grab();\r
744                         }\r
745 \r
746                         ~SOccQuery()\r
747                         {\r
748                                 if (Node)\r
749                                         Node->drop();\r
750                                 if (Mesh)\r
751                                         Mesh->drop();\r
752                         }\r
753 \r
754                         SOccQuery& operator=(const SOccQuery& other)\r
755                         {\r
756                                 Node=other.Node;\r
757                                 Mesh=other.Mesh;\r
758                                 PID=other.PID;\r
759                                 Result=other.Result;\r
760                                 Run=other.Run;\r
761                                 if (Node)\r
762                                         Node->grab();\r
763                                 if (Mesh)\r
764                                         Mesh->grab();\r
765                                 return *this;\r
766                         }\r
767 \r
768                         bool operator==(const SOccQuery& other) const\r
769                         {\r
770                                 return other.Node==Node;\r
771                         }\r
772 \r
773                         scene::ISceneNode* Node;\r
774                         const scene::IMesh* Mesh;\r
775                         union\r
776                         {\r
777                                 void* PID;\r
778                                 unsigned int UID;\r
779                         };\r
780                         u32 Result;\r
781                         u32 Run;\r
782                 };\r
783                 core::array<SOccQuery> OcclusionQueries;\r
784 \r
785                 core::array<IRenderTarget*> RenderTargets;\r
786 \r
787                 // Shared objects used with simplified IVideoDriver::setRenderTarget method with ITexture* param.\r
788                 IRenderTarget* SharedRenderTarget;\r
789                 core::array<ITexture*> SharedDepthTextures;\r
790 \r
791                 IRenderTarget* CurrentRenderTarget;\r
792                 core::dimension2d<u32> CurrentRenderTargetSize;\r
793 \r
794                 core::array<video::IImageLoader*> SurfaceLoader;\r
795                 core::array<video::IImageWriter*> SurfaceWriter;\r
796                 core::array<SMaterialRenderer> MaterialRenderers;\r
797 \r
798                 std::list<SHWBufferLink*> HWBufferList;\r
799 \r
800                 io::IFileSystem* FileSystem;\r
801 \r
802                 //! mesh manipulator\r
803                 scene::IMeshManipulator* MeshManipulator;\r
804 \r
805                 core::rect<s32> ViewPort;\r
806                 core::dimension2d<u32> ScreenSize;\r
807                 core::matrix4 TransformationMatrix;\r
808 \r
809                 CFPSCounter FPSCounter;\r
810 \r
811                 u32 PrimitivesDrawn;\r
812                 u32 MinVertexCountForVBO;\r
813 \r
814                 u32 TextureCreationFlags;\r
815 \r
816                 f32 FogStart;\r
817                 f32 FogEnd;\r
818                 f32 FogDensity;\r
819                 SColor FogColor;\r
820                 SExposedVideoData ExposedData;\r
821 \r
822                 io::IAttributes* DriverAttributes;\r
823 \r
824                 SOverrideMaterial OverrideMaterial;\r
825                 SMaterial OverrideMaterial2D;\r
826                 SMaterial InitMaterial2D;\r
827                 bool OverrideMaterial2DEnabled;\r
828 \r
829                 E_FOG_TYPE FogType;\r
830                 bool PixelFog;\r
831                 bool RangeFog;\r
832                 bool AllowZWriteOnTransparent;\r
833 \r
834                 bool FeatureEnabled[video::EVDF_COUNT];\r
835 \r
836                 SColorf AmbientLight;\r
837         };\r
838 \r
839 } // end namespace video\r
840 } // end namespace irr\r
841 \r
842 \r
843 #endif\r