COpenGLDriver.h 22 KB

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