aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/CD3D8Driver.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/CD3D8Driver.h341
1 files changed, 341 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CD3D8Driver.h b/libraries/irrlicht-1.8/source/Irrlicht/CD3D8Driver.h
new file mode 100644
index 0000000..e9428a9
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/CD3D8Driver.h
@@ -0,0 +1,341 @@
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
5#ifndef __C_VIDEO_DIRECTX_8_H_INCLUDED__
6#define __C_VIDEO_DIRECTX_8_H_INCLUDED__
7
8#include "IrrCompileConfig.h"
9
10#ifdef _IRR_COMPILE_WITH_DIRECT3D_8_
11
12#ifdef _IRR_WINDOWS_
13 #define WIN32_LEAN_AND_MEAN
14 #include <windows.h>
15#endif
16
17#include "SIrrCreationParameters.h"
18// always included for static createDriver function
19#include "CNullDriver.h"
20#include "IMaterialRendererServices.h"
21
22#include <d3d8.h>
23
24namespace irr
25{
26namespace video
27{
28 class CD3D8Driver : public CNullDriver, IMaterialRendererServices
29 {
30 friend class CD3D8Texture;
31
32 public:
33
34 //! constructor
35 CD3D8Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io);
36
37 //! destructor
38 virtual ~CD3D8Driver();
39
40 //! applications must call this method before performing any rendering. returns false if failed.
41 virtual bool beginScene(bool backBuffer=true, bool zBuffer=true,
42 SColor color=SColor(255,0,0,0),
43 const SExposedVideoData& videoData=SExposedVideoData(),
44 core::rect<s32>* sourceRect=0);
45
46 //! applications must call this method after performing any rendering. returns false if failed.
47 virtual bool endScene();
48
49 //! queries the features of the driver, returns true if feature is available
50 virtual bool queryFeature(E_VIDEO_DRIVER_FEATURE feature) const;
51
52 //! sets transformation
53 virtual void setTransform(E_TRANSFORMATION_STATE state, const core::matrix4& mat);
54
55 //! sets a material
56 virtual void setMaterial(const SMaterial& material);
57
58 //! sets a render target
59 virtual bool setRenderTarget(video::ITexture* texture,
60 bool clearBackBuffer=true, bool clearZBuffer=true,
61 SColor color=video::SColor(0,0,0,0));
62
63 //! sets a viewport
64 virtual void setViewPort(const core::rect<s32>& area);
65
66 //! gets the area of the current viewport
67 virtual const core::rect<s32>& getViewPort() const;
68
69 //! draws a vertex primitive list
70 virtual void drawVertexPrimitiveList(const void* vertices, u32 vertexCount,
71 const void* indexList, u32 primitiveCount,
72 E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType,
73 E_INDEX_TYPE iType);
74
75 //! draws a vertex primitive list in 2d
76 virtual void draw2DVertexPrimitiveList(const void* vertices, u32 vertexCount,
77 const void* indexList, u32 primitiveCount,
78 E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType,
79 E_INDEX_TYPE iType);
80
81 //! draws an 2d image, using a color (if color is other then Color(255,255,255,255)) and the alpha channel of the texture if wanted.
82 virtual void draw2DImage(const video::ITexture* texture, const core::position2d<s32>& destPos,
83 const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
84 SColor color=SColor(255,255,255,255), bool useAlphaChannelOfTexture=false);
85
86 //! Draws a part of the texture into the rectangle.
87 virtual void draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect,
88 const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
89 const video::SColor* const colors=0, bool useAlphaChannelOfTexture=false);
90
91 //!Draws an 2d rectangle with a gradient.
92 virtual void draw2DRectangle(const core::rect<s32>& pos,
93 SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown,
94 const core::rect<s32>* clip = 0);
95
96 //! Draws a 2d line.
97 virtual void draw2DLine(const core::position2d<s32>& start,
98 const core::position2d<s32>& end,
99 SColor color=SColor(255,255,255,255));
100
101 //! Draws a pixel.
102 virtual void drawPixel(u32 x, u32 y, const SColor & color);
103
104 //! Draws a 3d line.
105 virtual void draw3DLine(const core::vector3df& start,
106 const core::vector3df& end, SColor color = SColor(255,255,255,255));
107
108 //! initialises the Direct3D API
109 bool initDriver(HWND hwnd, bool pureSoftware);
110
111 //! \return Returns the name of the video driver. Example: In case of the DIRECT3D8
112 //! driver, it would return "Direct3D8.1".
113 virtual const wchar_t* getName() const;
114
115 //! deletes all dynamic lights there are
116 virtual void deleteAllDynamicLights();
117
118 //! adds a dynamic light, returning an index to the light
119 //! \param light: the light data to use to create the light
120 //! \return An index to the light, or -1 if an error occurs
121 virtual s32 addDynamicLight(const SLight& light);
122
123 //! Turns a dynamic light on or off
124 //! \param lightIndex: the index returned by addDynamicLight
125 //! \param turnOn: true to turn the light on, false to turn it off
126 virtual void turnLightOn(s32 lightIndex, bool turnOn);
127
128 //! returns the maximal amount of dynamic lights the device can handle
129 virtual u32 getMaximalDynamicLightAmount() const;
130
131 //! Sets the dynamic ambient light color. The default color is
132 //! (0,0,0,0) which means it is dark.
133 //! \param color: New color of the ambient light.
134 virtual void setAmbientLight(const SColorf& color);
135
136 //! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do
137 //! this: Frist, draw all geometry. Then use this method, to draw the shadow
138 //! volume. Then, use IVideoDriver::drawStencilShadow() to visualize the shadow.
139 virtual void drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail=true, u32 debugDataVisible=0);
140
141 //! Fills the stencil shadow with color. After the shadow volume has been drawn
142 //! into the stencil buffer using IVideoDriver::drawStencilShadowVolume(), use this
143 //! to draw the color of the shadow.
144 virtual void drawStencilShadow(bool clearStencilBuffer=false,
145 video::SColor leftUpEdge = video::SColor(0,0,0,0),
146 video::SColor rightUpEdge = video::SColor(0,0,0,0),
147 video::SColor leftDownEdge = video::SColor(0,0,0,0),
148 video::SColor rightDownEdge = video::SColor(0,0,0,0));
149
150 //! Returns the maximum amount of primitives (mostly vertices) which
151 //! the device is able to render with one drawIndexedTriangleList
152 //! call.
153 virtual u32 getMaximalPrimitiveCount() const;
154
155 //! Enables or disables a texture creation flag.
156 virtual void setTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag, bool enabled);
157
158 //! Sets the fog mode.
159 virtual void setFog(SColor color, E_FOG_TYPE fogType, f32 start,
160 f32 end, f32 density, bool pixelFog, bool rangeFog);
161
162 //! Only used by the internal engine. Used to notify the driver that
163 //! the window was resized.
164 virtual void OnResize(const core::dimension2d<u32>& size);
165
166 //! Returns type of video driver
167 virtual E_DRIVER_TYPE getDriverType() const;
168
169 //! Returns the transformation set by setTransform
170 virtual const core::matrix4& getTransform(E_TRANSFORMATION_STATE state) const;
171
172 //! Can be called by an IMaterialRenderer to make its work easier.
173 virtual void setBasicRenderStates(const SMaterial& material, const SMaterial& lastMaterial,
174 bool resetAllRenderstates);
175
176 //! Sets a vertex shader constant.
177 virtual void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1);
178
179 //! Sets a pixel shader constant.
180 virtual void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1);
181
182 //! Sets a constant for the vertex shader based on a name.
183 virtual bool setVertexShaderConstant(const c8* name, const f32* floats, int count);
184
185 //! Bool interface for the above.
186 virtual bool setVertexShaderConstant(const c8* name, const bool* bools, int count);
187
188 //! Int interface for the above.
189 virtual bool setVertexShaderConstant(const c8* name, const s32* ints, int count);
190
191 //! Sets a constant for the pixel shader based on a name.
192 virtual bool setPixelShaderConstant(const c8* name, const f32* floats, int count);
193
194 //! Bool interface for the above.
195 virtual bool setPixelShaderConstant(const c8* name, const bool* bools, int count);
196
197 //! Int interface for the above.
198 virtual bool setPixelShaderConstant(const c8* name, const s32* ints, int count);
199
200 //! Returns a pointer to the IVideoDriver interface. (Implementation for
201 //! IMaterialRendererServices)
202 virtual IVideoDriver* getVideoDriver();
203
204 //! Creates a render target texture.
205 virtual ITexture* addRenderTargetTexture(const core::dimension2d<u32>& size,
206 const io::path& name, const ECOLOR_FORMAT format = ECF_UNKNOWN);
207
208 //! Clears the ZBuffer.
209 virtual void clearZBuffer();
210
211 //! Returns an image created from the last rendered frame.
212 virtual IImage* createScreenShot(video::ECOLOR_FORMAT format=video::ECF_UNKNOWN, video::E_RENDER_TARGET target=video::ERT_FRAME_BUFFER);
213
214 //! Set/unset a clipping plane.
215 //! There are at least 6 clipping planes available for the user to set at will.
216 //! \param index: The plane index. Must be between 0 and MaxUserClipPlanes.
217 //! \param plane: The plane itself.
218 //! \param enable: If true, enable the clipping plane else disable it.
219 virtual bool setClipPlane(u32 index, const core::plane3df& plane, bool enable=false);
220
221 //! Enable/disable a clipping plane.
222 //! There are at least 6 clipping planes available for the user to set at will.
223 //! \param index: The plane index. Must be between 0 and MaxUserClipPlanes.
224 //! \param enable: If true, enable the clipping plane else disable it.
225 virtual void enableClipPlane(u32 index, bool enable);
226
227 //! Returns the maximum texture size supported.
228 virtual core::dimension2du getMaxTextureSize() const;
229
230 virtual bool checkDriverReset() {return DriverWasReset;}
231 private:
232
233 // enumeration for rendering modes such as 2d and 3d for minizing the switching of renderStates.
234 enum E_RENDER_MODE
235 {
236 ERM_NONE = 0, // no render state has been set yet.
237 ERM_2D, // 2d drawing rendermode
238 ERM_3D, // 3d rendering mode
239 ERM_STENCIL_FILL, // stencil fill mode
240 ERM_SHADOW_VOLUME_ZFAIL, // stencil volume draw mode
241 ERM_SHADOW_VOLUME_ZPASS // stencil volume draw mode
242 };
243
244 //! sets right vertex shader
245 void setVertexShader(video::E_VERTEX_TYPE newType);
246
247 //! sets the needed renderstates
248 bool setRenderStates3DMode();
249
250 //! sets the needed renderstates
251 void setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel);
252
253 //! sets the needed renderstates
254 void setRenderStatesStencilFillMode(bool alpha);
255
256 //! sets the needed renderstates
257 void setRenderStatesStencilShadowMode(bool zfail, u32 debugDataVisible);
258
259 //! sets the current Texture
260 bool setActiveTexture(u32 stage, const video::ITexture* texture);
261
262 //! resets the device
263 bool reset();
264
265 //! returns a device dependent texture from a software surface (IImage)
266 //! THIS METHOD HAS TO BE OVERRIDDEN BY DERIVED DRIVERS WITH OWN TEXTURES
267 virtual video::ITexture* createDeviceDependentTexture(IImage* surface, const io::path& name, void* mipmapData=0);
268
269 // returns the current size of the screen or rendertarget
270 virtual const core::dimension2d<u32>& getCurrentRenderTargetSize() const;
271
272 //! Adds a new material renderer to the VideoDriver, using pixel and/or
273 //! vertex shaders to render geometry.
274 s32 addShaderMaterial(const c8* vertexShaderProgram, const c8* pixelShaderProgram,
275 IShaderConstantSetCallBack* callback,
276 E_MATERIAL_TYPE baseMaterial, s32 userData);
277
278 void createMaterialRenderers();
279
280 void draw2D3DVertexPrimitiveList(const void* vertices,
281 u32 vertexCount, const void* indexList, u32 primitiveCount,
282 E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType,
283 E_INDEX_TYPE iType, bool is3D);
284
285 D3DTEXTUREADDRESS getTextureWrapMode(const u8 clamp);
286
287 inline D3DCOLORVALUE colorToD3D(const SColor& col)
288 {
289 const f32 f = 1.0f / 255.0f;
290 D3DCOLORVALUE v;
291 v.r = col.getRed() * f;
292 v.g = col.getGreen() * f;
293 v.b = col.getBlue() * f;
294 v.a = col.getAlpha() * f;
295 return v;
296 }
297
298 E_RENDER_MODE CurrentRenderMode;
299 D3DPRESENT_PARAMETERS present;
300
301 SMaterial Material, LastMaterial;
302 bool ResetRenderStates; // bool to make all renderstates be reseted if set.
303 bool Transformation3DChanged;
304 const ITexture* CurrentTexture[MATERIAL_MAX_TEXTURES];
305 core::matrix4 Matrices[ETS_COUNT]; // matrices of the 3d mode we need to restore when we switch back from the 2d mode.
306
307 HINSTANCE D3DLibrary;
308 IDirect3D8* pID3D;
309 IDirect3DDevice8* pID3DDevice;
310
311 IDirect3DSurface8* PrevRenderTarget;
312 core::dimension2d<u32> CurrentRendertargetSize;
313
314 HWND WindowId;
315 core::rect<s32>* SceneSourceRect;
316
317 D3DCAPS8 Caps;
318
319 E_VERTEX_TYPE LastVertexType;
320
321 D3DMATRIX UnitMatrix;
322
323 u32 MaxTextureUnits;
324 u32 MaxUserClipPlanes;
325 f32 MaxLightDistance;
326 s32 LastSetLight;
327 bool DeviceLost;
328 bool DriverWasReset;
329
330 SColorf AmbientLight;
331
332 SIrrlichtCreationParameters Params;
333 };
334
335} // end namespace video
336} // end namespace irr
337
338#endif // _IRR_COMPILE_WITH_DIRECT3D_8_
339
340#endif // __C_VIDEO_DIRECTX_8_H_INCLUDED__
341