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_OPEN_GL_H_INCLUDED__
6 #define __C_VIDEO_OPEN_GL_H_INCLUDED__
7 
8 #include "IrrCompileConfig.h"
9 
10 #include "SIrrCreationParameters.h"
11 
12 namespace irr
13 {
14 	class CIrrDeviceWin32;
15 	class CIrrDeviceLinux;
16 	class CIrrDeviceSDL;
17 	class CIrrDeviceMacOSX;
18 }
19 
20 #ifdef _IRR_COMPILE_WITH_OPENGL_
21 
22 #include "CNullDriver.h"
23 #include "IMaterialRendererServices.h"
24 // also includes the OpenGL stuff
25 #include "COpenGLExtensionHandler.h"
26 
27 #ifdef _IRR_COMPILE_WITH_CG_
28 #include "Cg/cg.h"
29 #endif
30 
31 namespace irr
32 {
33 
34 namespace video
35 {
36 	class COpenGLTexture;
37 
38 	class COpenGLDriver : public CNullDriver, public IMaterialRendererServices, public COpenGLExtensionHandler
39 	{
40 		friend class COpenGLTexture;
41 	public:
42 
43 		#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
44 		COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceWin32* device);
45 		//! inits the windows specific parts of the open gl driver
46 		bool initDriver(CIrrDeviceWin32* device);
47 		bool changeRenderContext(const SExposedVideoData& videoData, CIrrDeviceWin32* device);
48 		#endif
49 
50 		#ifdef _IRR_COMPILE_WITH_X11_DEVICE_
51 		COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceLinux* device);
52 		//! inits the GLX specific parts of the open gl driver
53 		bool initDriver(CIrrDeviceLinux* device);
54 		bool changeRenderContext(const SExposedVideoData& videoData, CIrrDeviceLinux* device);
55 		#endif
56 
57 		#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
58 		COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceSDL* device);
59 		#endif
60 
61 		#ifdef _IRR_COMPILE_WITH_OSX_DEVICE_
62 		COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceMacOSX *device);
63 		#endif
64 
65 		//! generic version which overloads the unimplemented versions
changeRenderContext(const SExposedVideoData & videoData,void * device)66 		bool changeRenderContext(const SExposedVideoData& videoData, void* device) {return false;}
67 
68 		//! destructor
69 		virtual ~COpenGLDriver();
70 
71 		//! clears the zbuffer
72 		virtual bool beginScene(bool backBuffer=true, bool zBuffer=true,
73 				SColor color=SColor(255,0,0,0),
74 				const SExposedVideoData& videoData=SExposedVideoData(),
75 				core::rect<s32>* sourceRect=0);
76 
77 		//! presents the rendered scene on the screen, returns false if failed
78 		virtual bool endScene();
79 
80 		//! sets transformation
81 		virtual void setTransform(E_TRANSFORMATION_STATE state, const core::matrix4& mat);
82 
83 
84 		struct SHWBufferLink_opengl : public SHWBufferLink
85 		{
SHWBufferLink_openglSHWBufferLink_opengl86 			SHWBufferLink_opengl(const scene::IMeshBuffer *_MeshBuffer): SHWBufferLink(_MeshBuffer), vbo_verticesID(0),vbo_indicesID(0){}
87 
88 			GLuint vbo_verticesID; //tmp
89 			GLuint vbo_indicesID; //tmp
90 
91 			GLuint vbo_verticesSize; //tmp
92 			GLuint vbo_indicesSize; //tmp
93 		};
94 
95 		//! updates hardware buffer if needed
96 		virtual bool updateHardwareBuffer(SHWBufferLink *HWBuffer);
97 
98 		//! Create hardware buffer from mesh
99 		virtual SHWBufferLink *createHardwareBuffer(const scene::IMeshBuffer* mb);
100 
101 		//! Delete hardware buffer (only some drivers can)
102 		virtual void deleteHardwareBuffer(SHWBufferLink *HWBuffer);
103 
104 		//! Draw hardware buffer
105 		virtual void drawHardwareBuffer(SHWBufferLink *HWBuffer);
106 
107 		//! Create occlusion query.
108 		/** Use node for identification and mesh for occlusion test. */
109 		virtual void addOcclusionQuery(scene::ISceneNode* node,
110 				const scene::IMesh* mesh=0);
111 
112 		//! Remove occlusion query.
113 		virtual void removeOcclusionQuery(scene::ISceneNode* node);
114 
115 		//! Run occlusion query. Draws mesh stored in query.
116 		/** If the mesh shall not be rendered visible, use
117 		overrideMaterial to disable the color and depth buffer. */
118 		virtual void runOcclusionQuery(scene::ISceneNode* node, bool visible=false);
119 
120 		//! Update occlusion query. Retrieves results from GPU.
121 		/** If the query shall not block, set the flag to false.
122 		Update might not occur in this case, though */
123 		virtual void updateOcclusionQuery(scene::ISceneNode* node, bool block=true);
124 
125 		//! Return query result.
126 		/** Return value is the number of visible pixels/fragments.
127 		The value is a safe approximation, i.e. can be larger then the
128 		actual value of pixels. */
129 		virtual u32 getOcclusionQueryResult(scene::ISceneNode* node) const;
130 
131 		//! draws a vertex primitive list
132 		virtual void drawVertexPrimitiveList(const void* vertices, u32 vertexCount,
133 				const void* indexList, u32 primitiveCount,
134 				E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType);
135 
136 		//! draws a vertex primitive list in 2d
137 		virtual void draw2DVertexPrimitiveList(const void* vertices, u32 vertexCount,
138 				const void* indexList, u32 primitiveCount,
139 				E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType);
140 
141 		//! queries the features of the driver, returns true if feature is available
queryFeature(E_VIDEO_DRIVER_FEATURE feature)142 		virtual bool queryFeature(E_VIDEO_DRIVER_FEATURE feature) const
143 		{
144 			return FeatureEnabled[feature] && COpenGLExtensionHandler::queryFeature(feature);
145 		}
146 
147 		//! Sets a material. All 3d drawing functions draw geometry now
148 		//! using this material.
149 		//! \param material: Material to be used from now on.
150 		virtual void setMaterial(const SMaterial& material);
151 
152 		//! draws a set of 2d images, using a color and the alpha channel of the
153 		//! texture if desired.
154 		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,
158 				SColor color,
159 				bool useAlphaChannelOfTexture);
160 
161 		//! 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.
162 		virtual void draw2DImage(const video::ITexture* texture, const core::position2d<s32>& destPos,
163 			const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
164 			SColor color=SColor(255,255,255,255), bool useAlphaChannelOfTexture=false);
165 
166 		//! draws a set of 2d images, using a color and the alpha
167 		/** channel of the texture if desired. The images are drawn
168 		beginning at pos and concatenated in one line. All drawings
169 		are clipped against clipRect (if != 0).
170 		The subtextures are defined by the array of sourceRects
171 		and are chosen by the indices given.
172 		\param texture: Texture to be drawn.
173 		\param pos: Upper left 2d destination position where the image will be drawn.
174 		\param sourceRects: Source rectangles of the image.
175 		\param indices: List of indices which choose the actual rectangle used each time.
176 		\param clipRect: Pointer to rectangle on the screen where the image is clipped to.
177 		This pointer can be 0. Then the image is not clipped.
178 		\param color: Color with which the image is colored.
179 		Note that the alpha component is used: If alpha is other than 255, the image will be transparent.
180 		\param useAlphaChannelOfTexture: If true, the alpha channel of the texture is
181 		used to draw the image. */
182 		virtual void draw2DImage(const video::ITexture* texture,
183 				const core::position2d<s32>& pos,
184 				const core::array<core::rect<s32> >& sourceRects,
185 				const core::array<s32>& indices,
186 				const core::rect<s32>* clipRect=0,
187 				SColor color=SColor(255,255,255,255),
188 				bool useAlphaChannelOfTexture=false);
189 
190 		//! Draws a part of the texture into the rectangle.
191 		virtual void draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect,
192 			const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
193 			const video::SColor* const colors=0, bool useAlphaChannelOfTexture=false);
194 
195 		//! draw an 2d rectangle
196 		virtual void draw2DRectangle(SColor color, const core::rect<s32>& pos,
197 			const core::rect<s32>* clip = 0);
198 
199 		//!Draws an 2d rectangle with a gradient.
200 		virtual void draw2DRectangle(const core::rect<s32>& pos,
201 			SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown,
202 			const core::rect<s32>* clip = 0);
203 
204 		//! Draws a 2d line.
205 		virtual void draw2DLine(const core::position2d<s32>& start,
206 					const core::position2d<s32>& end,
207 					SColor color=SColor(255,255,255,255));
208 
209 		//! Draws a single pixel
210 		virtual void drawPixel(u32 x, u32 y, const SColor & color);
211 
212 		//! Draws a 3d line.
213 		virtual void draw3DLine(const core::vector3df& start,
214 					const core::vector3df& end,
215 					SColor color = SColor(255,255,255,255));
216 
217 		//! \return Returns the name of the video driver. Example: In case of the Direct3D8
218 		//! driver, it would return "Direct3D8.1".
219 		virtual const wchar_t* getName() const;
220 
221 		//! deletes all dynamic lights there are
222 		virtual void deleteAllDynamicLights();
223 
224 		//! adds a dynamic light, returning an index to the light
225 		//! \param light: the light data to use to create the light
226 		//! \return An index to the light, or -1 if an error occurs
227 		virtual s32 addDynamicLight(const SLight& light);
228 
229 		//! Turns a dynamic light on or off
230 		//! \param lightIndex: the index returned by addDynamicLight
231 		//! \param turnOn: true to turn the light on, false to turn it off
232 		virtual void turnLightOn(s32 lightIndex, bool turnOn);
233 
234 		//! returns the maximal amount of dynamic lights the device can handle
235 		virtual u32 getMaximalDynamicLightAmount() const;
236 
237 		//! Sets the dynamic ambient light color. The default color is
238 		//! (0,0,0,0) which means it is dark.
239 		//! \param color: New color of the ambient light.
240 		virtual void setAmbientLight(const SColorf& color);
241 
242 		//! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do
243 		//! this: First, draw all geometry. Then use this method, to draw the shadow
244 		//! volume. Then, use IVideoDriver::drawStencilShadow() to visualize the shadow.
245 		virtual void drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail, u32 debugDataVisible=0);
246 
247 		//! Fills the stencil shadow with color. After the shadow volume has been drawn
248 		//! into the stencil buffer using IVideoDriver::drawStencilShadowVolume(), use this
249 		//! to draw the color of the shadow.
250 		virtual void drawStencilShadow(bool clearStencilBuffer=false,
251 			video::SColor leftUpEdge = video::SColor(0,0,0,0),
252 			video::SColor rightUpEdge = video::SColor(0,0,0,0),
253 			video::SColor leftDownEdge = video::SColor(0,0,0,0),
254 			video::SColor rightDownEdge = video::SColor(0,0,0,0));
255 
256 		//! sets a viewport
257 		virtual void setViewPort(const core::rect<s32>& area);
258 
259 		//! Sets the fog mode.
260 		virtual void setFog(SColor color, E_FOG_TYPE fogType, f32 start,
261 			f32 end, f32 density, bool pixelFog, bool rangeFog);
262 
263 		//! Only used by the internal engine. Used to notify the driver that
264 		//! the window was resized.
265 		virtual void OnResize(const core::dimension2d<u32>& size);
266 
267 		//! Returns type of video driver
268 		virtual E_DRIVER_TYPE getDriverType() const;
269 
270 		//! get color format of the current color buffer
271 		virtual ECOLOR_FORMAT getColorFormat() const;
272 
273 		//! Returns the transformation set by setTransform
274 		virtual const core::matrix4& getTransform(E_TRANSFORMATION_STATE state) const;
275 
276 		//! Can be called by an IMaterialRenderer to make its work easier.
277 		virtual void setBasicRenderStates(const SMaterial& material, const SMaterial& lastmaterial,
278 			bool resetAllRenderstates);
279 
280 		//! Sets a vertex shader constant.
281 		virtual void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1);
282 
283 		//! Sets a pixel shader constant.
284 		virtual void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1);
285 
286 		//! Sets a constant for the vertex shader based on a name.
287 		virtual bool setVertexShaderConstant(const c8* name, const f32* floats, int count);
288 
289 		//! Bool interface for the above.
290 		virtual bool setVertexShaderConstant(const c8* name, const bool* bools, int count);
291 
292 		//! Int interface for the above.
293 		virtual bool setVertexShaderConstant(const c8* name, const s32* ints, int count);
294 
295 		//! Sets a constant for the pixel shader based on a name.
296 		virtual bool setPixelShaderConstant(const c8* name, const f32* floats, int count);
297 
298 		//! Bool interface for the above.
299 		virtual bool setPixelShaderConstant(const c8* name, const bool* bools, int count);
300 
301 		//! Int interface for the above.
302 		virtual bool setPixelShaderConstant(const c8* name, const s32* ints, int count);
303 
304 		//! sets the current Texture
305 		//! Returns whether setting was a success or not.
306 		bool setActiveTexture(u32 stage, const video::ITexture* texture);
307 
308 		//! disables all textures beginning with the optional fromStage parameter. Otherwise all texture stages are disabled.
309 		//! Returns whether disabling was successful or not.
310 		bool disableTextures(u32 fromStage=0);
311 
312 		//! Adds a new material renderer to the VideoDriver, using
313 		//! extGLGetObjectParameteriv(shaderHandle, GL_OBJECT_COMPILE_STATUS_ARB, &status)
314 		//! pixel and/or vertex shaders to render geometry.
315 		virtual s32 addShaderMaterial(const c8* vertexShaderProgram, const c8* pixelShaderProgram,
316 			IShaderConstantSetCallBack* callback, E_MATERIAL_TYPE baseMaterial, s32 userData);
317 
318 		//! Adds a new material renderer to the VideoDriver, using GLSL to render geometry.
319 		virtual s32 addHighLevelShaderMaterial(
320 				const c8* vertexShaderProgram,
321 				const c8* vertexShaderEntryPointName,
322 				E_VERTEX_SHADER_TYPE vsCompileTarget,
323 				const c8* pixelShaderProgram,
324 				const c8* pixelShaderEntryPointName,
325 				E_PIXEL_SHADER_TYPE psCompileTarget,
326 				const c8* geometryShaderProgram,
327 				const c8* geometryShaderEntryPointName = "main",
328 				E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0,
329 				scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES,
330 				scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP,
331 				u32 verticesOut = 0,
332 				IShaderConstantSetCallBack* callback = 0,
333 				E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
334 				s32 userData = 0,
335 				E_GPU_SHADING_LANGUAGE shadingLang = EGSL_DEFAULT);
336 
337 		//! Returns a pointer to the IVideoDriver interface. (Implementation for
338 		//! IMaterialRendererServices)
339 		virtual IVideoDriver* getVideoDriver();
340 
341 		//! Returns the maximum amount of primitives (mostly vertices) which
342 		//! the device is able to render with one drawIndexedTriangleList
343 		//! call.
344 		virtual u32 getMaximalPrimitiveCount() const;
345 
346 		virtual ITexture* addRenderTargetTexture(const core::dimension2d<u32>& size,
347 				const io::path& name, const ECOLOR_FORMAT format = ECF_UNKNOWN);
348 
349 		//! set or reset render target
350 		virtual bool setRenderTarget(video::E_RENDER_TARGET target, bool clearTarget,
351 					bool clearZBuffer, SColor color);
352 
353 		//! set or reset render target texture
354 		virtual bool setRenderTarget(video::ITexture* texture, bool clearBackBuffer,
355 					bool clearZBuffer, SColor color);
356 
357 		//! Sets multiple render targets
358 		virtual bool setRenderTarget(const core::array<video::IRenderTarget>& texture,
359 			bool clearBackBuffer=true, bool clearZBuffer=true, SColor color=SColor(0,0,0,0));
360 
361 		//! Clears the ZBuffer.
362 		virtual void clearZBuffer();
363 
364 		//! Returns an image created from the last rendered frame.
365 		virtual IImage* createScreenShot(video::ECOLOR_FORMAT format=video::ECF_UNKNOWN, video::E_RENDER_TARGET target=video::ERT_FRAME_BUFFER);
366 
367 		//! checks if an OpenGL error has happend and prints it
368 		//! for performance reasons only available in debug mode
369 		bool testGLError();
370 
371 		//! Set/unset a clipping plane.
372 		//! There are at least 6 clipping planes available for the user to set at will.
373 		//! \param index: The plane index. Must be between 0 and MaxUserClipPlanes.
374 		//! \param plane: The plane itself.
375 		//! \param enable: If true, enable the clipping plane else disable it.
376 		virtual bool setClipPlane(u32 index, const core::plane3df& plane, bool enable=false);
377 
378 		//! Enable/disable a clipping plane.
379 		//! There are at least 6 clipping planes available for the user to set at will.
380 		//! \param index: The plane index. Must be between 0 and MaxUserClipPlanes.
381 		//! \param enable: If true, enable the clipping plane else disable it.
382 		virtual void enableClipPlane(u32 index, bool enable);
383 
384 		//! Enable the 2d override material
385 		virtual void enableMaterial2D(bool enable=true);
386 
387 		//! Returns the graphics card vendor name.
getVendorInfo()388 		virtual core::stringc getVendorInfo() {return VendorName;}
389 
390 		//! Returns the maximum texture size supported.
391 		virtual core::dimension2du getMaxTextureSize() const;
392 
393 		ITexture* createDepthTexture(ITexture* texture, bool shared=true);
394 		void removeDepthTexture(ITexture* texture);
395 
396 		//! Removes a texture from the texture cache and deletes it, freeing lot of memory.
397 		void removeTexture(ITexture* texture);
398 
399 		//! Convert E_PRIMITIVE_TYPE to OpenGL equivalent
400 		GLenum primitiveTypeToGL(scene::E_PRIMITIVE_TYPE type) const;
401 
402 		//! Convert E_BLEND_FACTOR to OpenGL equivalent
403 		GLenum getGLBlend(E_BLEND_FACTOR factor) const;
404 
405 		//! Get ZBuffer bits.
406 		GLenum getZBufferBits() const;
407 
408 		//! Get Cg context
409 		#ifdef _IRR_COMPILE_WITH_CG_
410 		const CGcontext& getCgContext();
411 		#endif
412 
413 	private:
414 
415 		//! clears the zbuffer and color buffer
416 		void clearBuffers(bool backBuffer, bool zBuffer, bool stencilBuffer, SColor color);
417 
418 		bool updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer);
419 		bool updateIndexHardwareBuffer(SHWBufferLink_opengl *HWBuffer);
420 
421 		void uploadClipPlane(u32 index);
422 
423 		//! inits the parts of the open gl driver used on all platforms
424 		bool genericDriverInit();
425 		//! returns a device dependent texture from a software surface (IImage)
426 		virtual video::ITexture* createDeviceDependentTexture(IImage* surface, const io::path& name, void* mipmapData);
427 
428 		//! creates a transposed matrix in supplied GLfloat array to pass to OpenGL
429 		inline void getGLMatrix(GLfloat gl_matrix[16], const core::matrix4& m);
430 		inline void getGLTextureMatrix(GLfloat gl_matrix[16], const core::matrix4& m);
431 
432 		//! Set GL pipeline to desired texture wrap modes of the material
433 		void setWrapMode(const SMaterial& material);
434 
435 		//! get native wrap mode value
436 		GLint getTextureWrapMode(const u8 clamp);
437 
438 		//! sets the needed renderstates
439 		void setRenderStates3DMode();
440 
441 		//! sets the needed renderstates
442 		void setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel);
443 
444 		// returns the current size of the screen or rendertarget
445 		virtual const core::dimension2d<u32>& getCurrentRenderTargetSize() const;
446 
447 		void createMaterialRenderers();
448 
449 		//! Assign a hardware light to the specified requested light, if any
450 		//! free hardware lights exist.
451 		//! \param[in] lightIndex: the index of the requesting light
452 		void assignHardwareLight(u32 lightIndex);
453 
454 		//! helper function for render setup.
455 		void getColorBuffer(const void* vertices, u32 vertexCount, E_VERTEX_TYPE vType);
456 
457 		//! helper function doing the actual rendering.
458 		void renderArray(const void* indexList, u32 primitiveCount,
459 				scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType);
460 
461 		core::stringw Name;
462 		core::matrix4 Matrices[ETS_COUNT];
463 		core::array<u8> ColorBuffer;
464 
465 		//! enumeration for rendering modes such as 2d and 3d for minizing the switching of renderStates.
466 		enum E_RENDER_MODE
467 		{
468 			ERM_NONE = 0,	// no render state has been set yet.
469 			ERM_2D,		// 2d drawing rendermode
470 			ERM_3D		// 3d rendering mode
471 		};
472 
473 		E_RENDER_MODE CurrentRenderMode;
474 		//! bool to make all renderstates reset if set to true.
475 		bool ResetRenderStates;
476 		bool Transformation3DChanged;
477 		u8 AntiAlias;
478 
479 		SMaterial Material, LastMaterial;
480 		COpenGLTexture* RenderTargetTexture;
481 		core::array<video::IRenderTarget> MRTargets;
482 		class STextureStageCache
483 		{
484 			const ITexture* CurrentTexture[MATERIAL_MAX_TEXTURES];
485 		public:
STextureStageCache()486 			STextureStageCache()
487 			{
488 				for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
489 				{
490 					CurrentTexture[i] = 0;
491 				}
492 			}
493 
~STextureStageCache()494 			~STextureStageCache()
495 			{
496 				clear();
497 			}
498 
set(u32 stage,const ITexture * tex)499 			void set(u32 stage, const ITexture* tex)
500 			{
501 				if (stage<MATERIAL_MAX_TEXTURES)
502 				{
503 					const ITexture* oldTexture=CurrentTexture[stage];
504 					if (tex)
505 						tex->grab();
506 					CurrentTexture[stage]=tex;
507 					if (oldTexture)
508 						oldTexture->drop();
509 				}
510 			}
511 
512 			const ITexture* operator[](int stage) const
513 			{
514 				if ((u32)stage<MATERIAL_MAX_TEXTURES)
515 					return CurrentTexture[stage];
516 				else
517 					return 0;
518 			}
519 
remove(const ITexture * tex)520 			void remove(const ITexture* tex)
521 			{
522 				for (s32 i = MATERIAL_MAX_TEXTURES-1; i>= 0; --i)
523 				{
524 					if (CurrentTexture[i] == tex)
525 					{
526 						tex->drop();
527 						CurrentTexture[i] = 0;
528 					}
529 				}
530 			}
531 
clear()532 			void clear()
533 			{
534 				// Drop all the CurrentTexture handles
535 				for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
536 				{
537 					if (CurrentTexture[i])
538 					{
539 						CurrentTexture[i]->drop();
540 						CurrentTexture[i] = 0;
541 					}
542 				}
543 			}
544 		};
545 		STextureStageCache CurrentTexture;
546 		core::array<ITexture*> DepthTextures;
547 		struct SUserClipPlane
548 		{
SUserClipPlaneSUserClipPlane549 			SUserClipPlane() : Enabled(false) {}
550 			core::plane3df Plane;
551 			bool Enabled;
552 		};
553 		core::array<SUserClipPlane> UserClipPlanes;
554 
555 		core::dimension2d<u32> CurrentRendertargetSize;
556 
557 		core::stringc VendorName;
558 
559 		core::matrix4 TextureFlipMatrix;
560 
561 		//! Color buffer format
562 		ECOLOR_FORMAT ColorFormat;
563 
564 		//! Render target type for render operations
565 		E_RENDER_TARGET CurrentTarget;
566 
567 		SIrrlichtCreationParameters Params;
568 
569 		//! All the lights that have been requested; a hardware limited
570 		//! number of them will be used at once.
571 		struct RequestedLight
572 		{
RequestedLightRequestedLight573 			RequestedLight(SLight const & lightData)
574 				: LightData(lightData), HardwareLightIndex(-1), DesireToBeOn(true) { }
575 
576 			SLight	LightData;
577 			s32	HardwareLightIndex; // GL_LIGHT0 - GL_LIGHT7
578 			bool	DesireToBeOn;
579 		};
580 		core::array<RequestedLight> RequestedLights;
581 
582 		#ifdef _IRR_WINDOWS_API_
583 			HDC HDc; // Private GDI Device Context
584 			HWND Window;
585 		#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
586 			CIrrDeviceWin32 *Win32Device;
587 		#endif
588 		#endif
589 		#ifdef _IRR_COMPILE_WITH_X11_DEVICE_
590 			GLXDrawable Drawable;
591 			Display* X11Display;
592 			CIrrDeviceLinux *X11Device;
593 		#endif
594 		#ifdef _IRR_COMPILE_WITH_OSX_DEVICE_
595 			CIrrDeviceMacOSX *OSXDevice;
596 		#endif
597 		#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
598 			CIrrDeviceSDL *SDLDevice;
599 		#endif
600 		#ifdef _IRR_COMPILE_WITH_CG_
601 		CGcontext CgContext;
602 		#endif
603 
604 		E_DEVICE_TYPE DeviceType;
605 	};
606 
607 } // end namespace video
608 } // end namespace irr
609 
610 
611 #endif // _IRR_COMPILE_WITH_OPENGL_
612 #endif
613 
614