00001
00002
00003
00004
00005 #ifndef __IRR_I_VIDEO_DRIVER_H_INCLUDED__
00006 #define __IRR_I_VIDEO_DRIVER_H_INCLUDED__
00007
00008 #include "rect.h"
00009 #include "SColor.h"
00010 #include "ITexture.h"
00011 #include "irrArray.h"
00012 #include "matrix4.h"
00013 #include "plane3d.h"
00014 #include "dimension2d.h"
00015 #include "position2d.h"
00016 #include "SMaterial.h"
00017 #include "IMeshBuffer.h"
00018 #include "triangle3d.h"
00019 #include "EDriverTypes.h"
00020 #include "EDriverFeatures.h"
00021 #include "SExposedVideoData.h"
00022
00023 namespace irr
00024 {
00025 namespace io
00026 {
00027 class IAttributes;
00028 class IReadFile;
00029 class IWriteFile;
00030 }
00031 namespace scene
00032 {
00033 class IMeshBuffer;
00034 class IMeshManipulator;
00035 }
00036
00037 namespace video
00038 {
00039 struct S3DVertex;
00040 struct S3DVertex2TCoords;
00041 struct S3DVertexTangents;
00042 struct SLight;
00043 class IImageLoader;
00044 class IImageWriter;
00045 class IMaterialRenderer;
00046 class IGPUProgrammingServices;
00047
00049 enum E_TRANSFORMATION_STATE
00050 {
00052 ETS_VIEW = 0,
00054 ETS_WORLD,
00056 ETS_PROJECTION,
00058 ETS_TEXTURE_0,
00060 ETS_TEXTURE_1,
00062 ETS_TEXTURE_2,
00064 ETS_TEXTURE_3,
00065 #if _IRR_MATERIAL_MAX_TEXTURES_>4
00067 ETS_TEXTURE_4,
00068 #if _IRR_MATERIAL_MAX_TEXTURES_>5
00070 ETS_TEXTURE_5,
00071 #if _IRR_MATERIAL_MAX_TEXTURES_>6
00073 ETS_TEXTURE_6,
00074 #if _IRR_MATERIAL_MAX_TEXTURES_>7
00076 ETS_TEXTURE_7,
00077 #endif
00078 #endif
00079 #endif
00080 #endif
00082 ETS_COUNT
00083 };
00084
00086
00089 enum E_LOST_RESSOURCE
00090 {
00092 ELR_DEVICE = 1,
00094 ELR_TEXTURES = 2,
00096 ELR_RTTS = 4,
00098 ELR_HW_BUFFERS = 8
00099 };
00100
00102
00103 enum E_RENDER_TARGET
00104 {
00106 ERT_FRAME_BUFFER=0,
00108 ERT_RENDER_TEXTURE,
00110 ERT_MULTI_RENDER_TEXTURES,
00112 ERT_STEREO_LEFT_BUFFER,
00114 ERT_STEREO_RIGHT_BUFFER,
00116 ERT_STEREO_BOTH_BUFFERS,
00118 ERT_AUX_BUFFER0,
00120 ERT_AUX_BUFFER1,
00122 ERT_AUX_BUFFER2,
00124 ERT_AUX_BUFFER3,
00126 ERT_AUX_BUFFER4
00127 };
00128
00130 enum E_FOG_TYPE
00131 {
00132 EFT_FOG_EXP=0,
00133 EFT_FOG_LINEAR,
00134 EFT_FOG_EXP2
00135 };
00136
00137 const c8* const FogTypeNames[] =
00138 {
00139 "FogExp",
00140 "FogLinear",
00141 "FogExp2",
00142 0
00143 };
00144
00145 struct SOverrideMaterial
00146 {
00148 SMaterial Material;
00150
00151 u32 EnableFlags;
00153
00154 u16 EnablePasses;
00156
00158 bool Enabled;
00159
00161 SOverrideMaterial() : EnableFlags(0), EnablePasses(0), Enabled(false) {}
00162
00164 void apply(SMaterial& material)
00165 {
00166 if (Enabled)
00167 {
00168 for (u32 i=0; i<32; ++i)
00169 {
00170 const u32 num=(1<<i);
00171 if (EnableFlags & num)
00172 {
00173 switch (num)
00174 {
00175 case EMF_WIREFRAME: material.Wireframe = Material.Wireframe; break;
00176 case EMF_POINTCLOUD: material.PointCloud = Material.PointCloud; break;
00177 case EMF_GOURAUD_SHADING: material.GouraudShading = Material.GouraudShading; break;
00178 case EMF_LIGHTING: material.Lighting = Material.Lighting; break;
00179 case EMF_ZBUFFER: material.ZBuffer = Material.ZBuffer; break;
00180 case EMF_ZWRITE_ENABLE: material.ZWriteEnable = Material.ZWriteEnable; break;
00181 case EMF_BACK_FACE_CULLING: material.BackfaceCulling = Material.BackfaceCulling; break;
00182 case EMF_FRONT_FACE_CULLING: material.FrontfaceCulling = Material.FrontfaceCulling; break;
00183 case EMF_FOG_ENABLE: material.FogEnable = Material.FogEnable; break;
00184 case EMF_NORMALIZE_NORMALS: material.NormalizeNormals = Material.NormalizeNormals; break;
00185 case EMF_ANTI_ALIASING: material.AntiAliasing = Material.AntiAliasing; break;
00186 case EMF_COLOR_MASK: material.ColorMask = Material.ColorMask; break;
00187 case EMF_BILINEAR_FILTER: material.TextureLayer[0].BilinearFilter = Material.TextureLayer[0].BilinearFilter; break;
00188 case EMF_TRILINEAR_FILTER: material.TextureLayer[0].TrilinearFilter = Material.TextureLayer[0].TrilinearFilter; break;
00189 case EMF_ANISOTROPIC_FILTER: material.TextureLayer[0].AnisotropicFilter = Material.TextureLayer[0].AnisotropicFilter; break;
00190 case EMF_TEXTURE_WRAP:
00191 material.TextureLayer[0].TextureWrapU = Material.TextureLayer[0].TextureWrapU;
00192 material.TextureLayer[0].TextureWrapV = Material.TextureLayer[0].TextureWrapV;
00193 break;
00194 }
00195 }
00196 }
00197 }
00198 }
00199
00200 };
00201
00202 struct IRenderTarget
00203 {
00204 IRenderTarget(ITexture* texture,
00205 E_COLOR_PLANE colorMask=ECP_ALL,
00206 E_BLEND_FACTOR blendFuncSrc=EBF_ONE,
00207 E_BLEND_FACTOR blendFuncDst=EBF_ONE_MINUS_SRC_ALPHA,
00208 bool blendEnable=false) :
00209 RenderTexture(texture),
00210 TargetType(ERT_RENDER_TEXTURE), ColorMask(colorMask),
00211 BlendFuncSrc(blendFuncSrc), BlendFuncDst(blendFuncDst),
00212 BlendEnable(blendEnable) {}
00213 IRenderTarget(E_RENDER_TARGET target,
00214 E_COLOR_PLANE colorMask=ECP_ALL,
00215 E_BLEND_FACTOR blendFuncSrc=EBF_ONE,
00216 E_BLEND_FACTOR blendFuncDst=EBF_ONE_MINUS_SRC_ALPHA,
00217 bool blendEnable=false) :
00218 RenderTexture(0),
00219 TargetType(target), ColorMask(colorMask),
00220 BlendFuncSrc(blendFuncSrc), BlendFuncDst(blendFuncDst),
00221 BlendEnable(blendEnable) {}
00222 ITexture* RenderTexture;
00223 E_RENDER_TARGET TargetType:8;
00224 E_COLOR_PLANE ColorMask:8;
00225 E_BLEND_FACTOR BlendFuncSrc:4;
00226 E_BLEND_FACTOR BlendFuncDst:4;
00227 bool BlendEnable;
00228 };
00229
00231
00238 class IVideoDriver : public virtual IReferenceCounted
00239 {
00240 public:
00241
00243
00260 virtual bool beginScene(bool backBuffer=true, bool zBuffer=true,
00261 SColor color=SColor(255,0,0,0),
00262 const SExposedVideoData& videoData=SExposedVideoData(),
00263 core::rect<s32>* sourceRect=0) =0;
00264
00266
00269 virtual bool endScene() =0;
00270
00272
00275 virtual bool queryFeature(E_VIDEO_DRIVER_FEATURE feature) const =0;
00276
00278
00282 virtual void disableFeature(E_VIDEO_DRIVER_FEATURE feature, bool flag=true) =0;
00283
00285
00288 virtual bool checkDriverReset() =0;
00289
00291
00294 virtual void setTransform(E_TRANSFORMATION_STATE state, const core::matrix4& mat) =0;
00295
00297
00299 virtual const core::matrix4& getTransform(E_TRANSFORMATION_STATE state) const =0;
00300
00302
00303 virtual u32 getImageLoaderCount() const = 0;
00304
00306
00309 virtual IImageLoader* getImageLoader(u32 n) = 0;
00310
00312
00313 virtual u32 getImageWriterCount() const = 0;
00314
00316
00319 virtual IImageWriter* getImageWriter(u32 n) = 0;
00320
00322
00324 virtual void setMaterial(const SMaterial& material) =0;
00325
00327
00336 virtual ITexture* getTexture(const io::path& filename) = 0;
00337
00339
00348 virtual ITexture* getTexture(io::IReadFile* file) =0;
00349
00351
00357 virtual ITexture* getTextureByIndex(u32 index) =0;
00358
00360
00361 virtual u32 getTextureCount() const = 0;
00362
00364
00366 virtual void renameTexture(ITexture* texture, const io::path& newName) = 0;
00367
00369
00378 virtual ITexture* addTexture(const core::dimension2d<u32>& size,
00379 const io::path& name, ECOLOR_FORMAT format = ECF_A8R8G8B8) = 0;
00380
00382
00392 virtual ITexture* addTexture(const io::path& name, IImage* image, void* mipmapData=0) = 0;
00393
00395
00404 virtual ITexture* addRenderTargetTexture(const core::dimension2d<u32>& size,
00405 const io::path& name = "rt", const ECOLOR_FORMAT format = ECF_UNKNOWN) =0;
00406
00408
00415 virtual void removeTexture(ITexture* texture) =0;
00416
00418
00424 virtual void removeAllTextures() =0;
00425
00427 virtual void removeHardwareBuffer(const scene::IMeshBuffer* mb) =0;
00428
00430 virtual void removeAllHardwareBuffers() =0;
00431
00433
00448 virtual void makeColorKeyTexture(video::ITexture* texture,
00449 video::SColor color,
00450 bool zeroTexels = false) const =0;
00451
00453
00464 virtual void makeColorKeyTexture(video::ITexture* texture,
00465 core::position2d<s32> colorKeyPixelPos,
00466 bool zeroTexels = false) const =0;
00467
00469
00476 virtual void makeNormalMapTexture(video::ITexture* texture, f32 amplitude=1.0f) const =0;
00477
00479
00510 virtual bool setRenderTarget(video::ITexture* texture,
00511 bool clearBackBuffer=true, bool clearZBuffer=true,
00512 SColor color=video::SColor(0,0,0,0)) =0;
00513
00515
00526 virtual bool setRenderTarget(E_RENDER_TARGET target, bool clearTarget=true,
00527 bool clearZBuffer=true,
00528 SColor color=video::SColor(0,0,0,0)) =0;
00529
00531 virtual bool setRenderTarget(const core::array<video::IRenderTarget>& texture,
00532 bool clearBackBuffer=true, bool clearZBuffer=true,
00533 SColor color=video::SColor(0,0,0,0)) =0;
00534
00536
00539 virtual void setViewPort(const core::rect<s32>& area) =0;
00540
00542
00543 virtual const core::rect<s32>& getViewPort() const =0;
00544
00546
00560 virtual void drawVertexPrimitiveList(const void* vertices, u32 vertexCount,
00561 const void* indexList, u32 primCount,
00562 E_VERTEX_TYPE vType=EVT_STANDARD,
00563 scene::E_PRIMITIVE_TYPE pType=scene::EPT_TRIANGLES,
00564 E_INDEX_TYPE iType=EIT_16BIT) =0;
00565
00567
00586 virtual void draw2DVertexPrimitiveList(const void* vertices, u32 vertexCount,
00587 const void* indexList, u32 primCount,
00588 E_VERTEX_TYPE vType=EVT_STANDARD,
00589 scene::E_PRIMITIVE_TYPE pType=scene::EPT_TRIANGLES,
00590 E_INDEX_TYPE iType=EIT_16BIT) =0;
00591
00593
00601 void drawIndexedTriangleList(const S3DVertex* vertices,
00602 u32 vertexCount, const u16* indexList, u32 triangleCount)
00603 {
00604 drawVertexPrimitiveList(vertices, vertexCount, indexList, triangleCount, EVT_STANDARD, scene::EPT_TRIANGLES, EIT_16BIT);
00605 }
00606
00608
00616 void drawIndexedTriangleList(const S3DVertex2TCoords* vertices,
00617 u32 vertexCount, const u16* indexList, u32 triangleCount)
00618 {
00619 drawVertexPrimitiveList(vertices, vertexCount, indexList, triangleCount, EVT_2TCOORDS, scene::EPT_TRIANGLES, EIT_16BIT);
00620 }
00621
00623
00631 void drawIndexedTriangleList(const S3DVertexTangents* vertices,
00632 u32 vertexCount, const u16* indexList, u32 triangleCount)
00633 {
00634 drawVertexPrimitiveList(vertices, vertexCount, indexList, triangleCount, EVT_TANGENTS, scene::EPT_TRIANGLES, EIT_16BIT);
00635 }
00636
00638
00646 void drawIndexedTriangleFan(const S3DVertex* vertices,
00647 u32 vertexCount, const u16* indexList, u32 triangleCount)
00648 {
00649 drawVertexPrimitiveList(vertices, vertexCount, indexList, triangleCount, EVT_STANDARD, scene::EPT_TRIANGLE_FAN, EIT_16BIT);
00650 }
00651
00653
00661 void drawIndexedTriangleFan(const S3DVertex2TCoords* vertices,
00662 u32 vertexCount, const u16* indexList, u32 triangleCount)
00663 {
00664 drawVertexPrimitiveList(vertices, vertexCount, indexList, triangleCount, EVT_2TCOORDS, scene::EPT_TRIANGLE_FAN, EIT_16BIT);
00665 }
00666
00668
00676 void drawIndexedTriangleFan(const S3DVertexTangents* vertices,
00677 u32 vertexCount, const u16* indexList, u32 triangleCount)
00678 {
00679 drawVertexPrimitiveList(vertices, vertexCount, indexList, triangleCount, EVT_TANGENTS, scene::EPT_TRIANGLE_FAN, EIT_16BIT);
00680 }
00681
00683
00697 virtual void draw3DLine(const core::vector3df& start,
00698 const core::vector3df& end, SColor color = SColor(255,255,255,255)) =0;
00699
00701
00714 virtual void draw3DTriangle(const core::triangle3df& triangle,
00715 SColor color = SColor(255,255,255,255)) =0;
00716
00718
00729 virtual void draw3DBox(const core::aabbox3d<f32>& box,
00730 SColor color = SColor(255,255,255,255)) =0;
00731
00733
00736 virtual void draw2DImage(const video::ITexture* texture,
00737 const core::position2d<s32>& destPos) =0;
00738
00740
00755 virtual void draw2DImage(const video::ITexture* texture, const core::position2d<s32>& destPos,
00756 const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect =0,
00757 SColor color=SColor(255,255,255,255), bool useAlphaChannelOfTexture=false) =0;
00758
00760
00779 virtual void draw2DImageBatch(const video::ITexture* texture,
00780 const core::position2d<s32>& pos,
00781 const core::array<core::rect<s32> >& sourceRects,
00782 const core::array<s32>& indices,
00783 s32 kerningWidth=0,
00784 const core::rect<s32>* clipRect=0,
00785 SColor color=SColor(255,255,255,255),
00786 bool useAlphaChannelOfTexture=false) =0;
00787
00789
00804 virtual void draw2DImageBatch(const video::ITexture* texture,
00805 const core::array<core::position2d<s32> >& positions,
00806 const core::array<core::rect<s32> >& sourceRects,
00807 const core::rect<s32>* clipRect=0,
00808 SColor color=SColor(255,255,255,255),
00809 bool useAlphaChannelOfTexture=false) =0;
00810
00812
00821 virtual void draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect,
00822 const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect =0,
00823 const video::SColor * const colors=0, bool useAlphaChannelOfTexture=false) =0;
00824
00826
00833 virtual void draw2DRectangle(SColor color, const core::rect<s32>& pos,
00834 const core::rect<s32>* clip =0) =0;
00835
00837
00853 virtual void draw2DRectangle(const core::rect<s32>& pos,
00854 SColor colorLeftUp, SColor colorRightUp,
00855 SColor colorLeftDown, SColor colorRightDown,
00856 const core::rect<s32>* clip =0) =0;
00857
00859
00862 virtual void draw2DRectangleOutline(const core::recti& pos,
00863 SColor color=SColor(255,255,255,255)) =0;
00864
00866
00871 virtual void draw2DLine(const core::position2d<s32>& start,
00872 const core::position2d<s32>& end,
00873 SColor color=SColor(255,255,255,255)) =0;
00874
00876
00879 virtual void drawPixel(u32 x, u32 y, const SColor& color) =0;
00880
00882
00894 virtual void draw2DPolygon(core::position2d<s32> center,
00895 f32 radius,
00896 video::SColor color=SColor(100,255,255,255),
00897 s32 vertexCount=10) =0;
00898
00900
00911 virtual void drawStencilShadowVolume(const core::vector3df* triangles, s32 count, bool zfail=true) =0;
00912
00914
00933 virtual void drawStencilShadow(bool clearStencilBuffer=false,
00934 video::SColor leftUpEdge = video::SColor(255,0,0,0),
00935 video::SColor rightUpEdge = video::SColor(255,0,0,0),
00936 video::SColor leftDownEdge = video::SColor(255,0,0,0),
00937 video::SColor rightDownEdge = video::SColor(255,0,0,0)) =0;
00938
00940
00941 virtual void drawMeshBuffer(const scene::IMeshBuffer* mb) =0;
00942
00944
00960 virtual void setFog(SColor color=SColor(0,255,255,255),
00961 E_FOG_TYPE fogType=EFT_FOG_LINEAR,
00962 f32 start=50.0f, f32 end=100.0f, f32 density=0.01f,
00963 bool pixelFog=false, bool rangeFog=false) =0;
00964
00966 virtual void getFog(SColor& color, E_FOG_TYPE& fogType,
00967 f32& start, f32& end, f32& density,
00968 bool& pixelFog, bool& rangeFog) = 0;
00969
00971
00972 virtual ECOLOR_FORMAT getColorFormat() const =0;
00973
00975
00976 virtual const core::dimension2d<u32>& getScreenSize() const =0;
00977
00979
00983 virtual const core::dimension2d<u32>& getCurrentRenderTargetSize() const =0;
00984
00986
00991 virtual s32 getFPS() const =0;
00992
00994
00998 virtual u32 getPrimitiveCountDrawn( u32 mode =0 ) const =0;
00999
01001 virtual void deleteAllDynamicLights() =0;
01002
01006 virtual s32 addDynamicLight(const SLight& light) =0;
01007
01009
01010 virtual u32 getMaximalDynamicLightAmount() const =0;
01011
01013
01014 virtual u32 getDynamicLightCount() const =0;
01015
01017
01020 virtual const SLight& getDynamicLight(u32 idx) const =0;
01021
01025 virtual void turnLightOn(s32 lightIndex, bool turnOn) =0;
01026
01028
01030 virtual const wchar_t* getName() const =0;
01031
01033
01039 virtual void addExternalImageLoader(IImageLoader* loader) =0;
01040
01042
01048 virtual void addExternalImageWriter(IImageWriter* writer) =0;
01049
01051
01054 virtual u32 getMaximalPrimitiveCount() const =0;
01055
01057
01066 virtual void setTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag, bool enabled=true) =0;
01067
01069
01072 virtual bool getTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag) const =0;
01073
01075
01083 virtual IImage* createImageFromFile(const io::path& filename) = 0;
01084
01086
01093 virtual IImage* createImageFromFile(io::IReadFile* file) =0;
01094
01096
01103 virtual bool writeImageToFile(IImage* image, const io::path& filename, u32 param = 0) = 0;
01104
01106
01114 virtual bool writeImageToFile(IImage* image, io::IWriteFile* file, u32 param =0) =0;
01115
01117
01131 virtual IImage* createImageFromData(ECOLOR_FORMAT format,
01132 const core::dimension2d<u32>& size, void *data,
01133 bool ownForeignMemory=false,
01134 bool deleteMemory = true) =0;
01135
01137
01143 virtual IImage* createImage(ECOLOR_FORMAT format, const core::dimension2d<u32>& size) =0;
01144
01146
01152 virtual IImage* createImage(ECOLOR_FORMAT format, IImage *imageToCopy) =0;
01153
01155
01162 virtual IImage* createImage(IImage* imageToCopy,
01163 const core::position2d<s32>& pos,
01164 const core::dimension2d<u32>& size) =0;
01165
01167
01174 virtual IImage* createImage(ITexture* texture,
01175 const core::position2d<s32>& pos,
01176 const core::dimension2d<u32>& size) =0;
01177
01179
01181 virtual void OnResize(const core::dimension2d<u32>& size) =0;
01182
01184
01204 virtual s32 addMaterialRenderer(IMaterialRenderer* renderer, const c8* name =0) =0;
01205
01207
01211 virtual IMaterialRenderer* getMaterialRenderer(u32 idx) =0;
01212
01214
01215 virtual u32 getMaterialRendererCount() const =0;
01216
01218
01227 virtual const c8* getMaterialRendererName(u32 idx) const =0;
01228
01230
01235 virtual void setMaterialRendererName(s32 idx, const c8* name) =0;
01236
01238
01245 virtual io::IAttributes* createAttributesFromMaterial(const video::SMaterial& material) =0;
01246
01248
01254 virtual void fillMaterialStructureFromAttributes(video::SMaterial& outMaterial, io::IAttributes* attributes) =0;
01255
01257
01260 virtual const SExposedVideoData& getExposedVideoData() =0;
01261
01263
01264 virtual E_DRIVER_TYPE getDriverType() const =0;
01265
01267
01270 virtual IGPUProgrammingServices* getGPUProgrammingServices() =0;
01271
01273 virtual scene::IMeshManipulator* getMeshManipulator() =0;
01274
01276
01282 virtual void clearZBuffer() =0;
01283
01285
01286 virtual IImage* createScreenShot() =0;
01287
01289
01293 virtual video::ITexture* findTexture(const io::path& filename) = 0;
01294
01296
01304 virtual bool setClipPlane(u32 index, const core::plane3df& plane, bool enable=false) =0;
01305
01307
01313 virtual void enableClipPlane(u32 index, bool enable) =0;
01314
01316
01317 virtual void setMinHardwareBufferVertexCount(u32 count) =0;
01318
01320
01324 virtual SOverrideMaterial& getOverrideMaterial() =0;
01325
01327
01340 virtual SMaterial& getMaterial2D() =0;
01341
01343
01345 virtual void enableMaterial2D(bool enable=true) =0;
01346
01348 virtual core::stringc getVendorInfo() =0;
01349
01351
01354 virtual void setAmbientLight(const SColorf& color) =0;
01355
01357
01360 virtual void setAllowZWriteOnTransparent(bool flag) =0;
01361
01363 virtual core::dimension2du getMaxTextureSize() const =0;
01364 };
01365
01366 }
01367 }
01368
01369
01370 #endif
01371