]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/COGLESDriver.h
Reduce IrrCompileConfig usage to files that actually need it
[irrlicht.git] / source / Irrlicht / COGLESDriver.h
1 // Copyright (C) 2002-20014 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_OGLES1_DRIVER_H_INCLUDED__\r
6 #define __C_OGLES1_DRIVER_H_INCLUDED__\r
7 \r
8 \r
9 #include "SIrrCreationParameters.h"\r
10 \r
11 #ifdef _IRR_COMPILE_WITH_OGLES1_\r
12 \r
13 #include "CNullDriver.h"\r
14 #include "IMaterialRendererServices.h"\r
15 #include "EDriverFeatures.h"\r
16 #include "fast_atof.h"\r
17 #include "COGLESExtensionHandler.h"\r
18 #include "IContextManager.h"\r
19 \r
20 namespace irr\r
21 {\r
22 namespace video\r
23 {\r
24 \r
25         class COGLES1Driver : public CNullDriver, public IMaterialRendererServices, public COGLES1ExtensionHandler\r
26         {\r
27                 friend class COpenGLCoreTexture<COGLES1Driver>;\r
28 \r
29         public:\r
30                 //! constructor\r
31                 COGLES1Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);\r
32 \r
33                 //! destructor\r
34                 virtual ~COGLES1Driver();\r
35 \r
36                 virtual bool beginScene(u16 clearFlag, SColor clearColor = SColor(255, 0, 0, 0), f32 clearDepth = 1.f, u8 clearStencil = 0,\r
37                         const SExposedVideoData& videoData = SExposedVideoData(), core::rect<s32>* sourceRect = 0) override;\r
38 \r
39                 bool endScene() override;\r
40 \r
41                 //! sets transformation\r
42                 void setTransform(E_TRANSFORMATION_STATE state, const core::matrix4& mat) override;\r
43 \r
44 \r
45                 struct SHWBufferLink_opengl : public SHWBufferLink\r
46                 {\r
47                         SHWBufferLink_opengl(const scene::IMeshBuffer *_MeshBuffer): SHWBufferLink(_MeshBuffer), vbo_verticesID(0),vbo_indicesID(0){}\r
48 \r
49                         GLuint vbo_verticesID; //tmp\r
50                         GLuint vbo_indicesID; //tmp\r
51 \r
52                         GLuint vbo_verticesSize; //tmp\r
53                         GLuint vbo_indicesSize; //tmp\r
54 \r
55                 };\r
56 \r
57                 bool updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer);\r
58                 bool updateIndexHardwareBuffer(SHWBufferLink_opengl *HWBuffer);\r
59 \r
60                 //! updates hardware buffer if needed\r
61                 bool updateHardwareBuffer(SHWBufferLink *HWBuffer) override;\r
62 \r
63                 //! Create hardware buffer from mesh\r
64                 SHWBufferLink *createHardwareBuffer(const scene::IMeshBuffer* mb) override;\r
65 \r
66                 //! Delete hardware buffer (only some drivers can)\r
67                 void deleteHardwareBuffer(SHWBufferLink *HWBuffer) override;\r
68 \r
69                 //! Draw hardware buffer\r
70                 void drawHardwareBuffer(SHWBufferLink *HWBuffer) override;\r
71 \r
72                 IRenderTarget* addRenderTarget() override;\r
73 \r
74                 //! draws a vertex primitive list\r
75                 virtual void drawVertexPrimitiveList(const void* vertices, u32 vertexCount,\r
76                                 const void* indexList, u32 primitiveCount,\r
77                                 E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType) override;\r
78 \r
79                 void drawVertexPrimitiveList2d3d(const void* vertices, u32 vertexCount, const void* indexList, u32 primitiveCount, E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType=EIT_16BIT, bool threed=true);\r
80 \r
81                 //! queries the features of the driver, returns true if feature is available\r
82                 bool queryFeature(E_VIDEO_DRIVER_FEATURE feature) const override\r
83                 {\r
84 //                      return FeatureEnabled[feature] && COGLES1ExtensionHandler::queryFeature(feature);\r
85                         return COGLES1ExtensionHandler::queryFeature(feature);\r
86                 }\r
87 \r
88                 //! Sets a material.\r
89                 void setMaterial(const SMaterial& material) override;\r
90 \r
91                 virtual void draw2DImage(const video::ITexture* texture, const core::position2d<s32>& destPos,\r
92                         const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,\r
93                         SColor color = SColor(255, 255, 255, 255), bool useAlphaChannelOfTexture = false) override;\r
94 \r
95                 virtual void draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect,\r
96                         const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,\r
97                         const video::SColor* const colors = 0, bool useAlphaChannelOfTexture = false) override;\r
98 \r
99                 virtual void draw2DImage(const video::ITexture* texture, u32 layer, bool flip);\r
100 \r
101                 //! draws a set of 2d images\r
102                 virtual void draw2DImageBatch(const video::ITexture* texture,\r
103                                 const core::position2d<s32>& pos,\r
104                                 const core::array<core::rect<s32> >& sourceRects,\r
105                                 const core::array<s32>& indices, s32 kerningWidth = 0,\r
106                                 const core::rect<s32>* clipRect=0,\r
107                                 SColor color=SColor(255,255,255,255),\r
108                                 bool useAlphaChannelOfTexture=false) override;\r
109 \r
110                 //! draws a set of 2d images, using a color and the alpha channel of the texture if desired.\r
111                 virtual void draw2DImageBatch(const video::ITexture* texture,\r
112                                 const core::array<core::position2d<s32> >& positions,\r
113                                 const core::array<core::rect<s32> >& sourceRects,\r
114                                 const core::rect<s32>* clipRect=0,\r
115                                 SColor color=SColor(255,255,255,255),\r
116                                 bool useAlphaChannelOfTexture=false) override;\r
117 \r
118                 //! draw an 2d rectangle\r
119                 virtual void draw2DRectangle(SColor color, const core::rect<s32>& pos,\r
120                         const core::rect<s32>* clip = 0) override;\r
121 \r
122                 //!Draws an 2d rectangle with a gradient.\r
123                 virtual void draw2DRectangle(const core::rect<s32>& pos,\r
124                         SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown,\r
125                         const core::rect<s32>* clip = 0) override;\r
126 \r
127                 //! Draws a 2d line.\r
128                 virtual void draw2DLine(const core::position2d<s32>& start,\r
129                                         const core::position2d<s32>& end,\r
130                                         SColor color=SColor(255,255,255,255)) override;\r
131 \r
132                 //! Draws a single pixel\r
133                 void drawPixel(u32 x, u32 y, const SColor & color) override;\r
134 \r
135                 //! Draws a 3d line.\r
136                 virtual void draw3DLine(const core::vector3df& start,\r
137                                         const core::vector3df& end,\r
138                                         SColor color = SColor(255,255,255,255)) override;\r
139 \r
140                 //! Returns the name of the video driver.\r
141                 const wchar_t* getName() const override;\r
142 \r
143                 //! Sets the dynamic ambient light color.\r
144                 void setAmbientLight(const SColorf& color) override;\r
145 \r
146                 //! Draws a shadow volume into the stencil buffer.\r
147                 void drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail, u32 debugDataVisible=0) override;\r
148 \r
149                 //! Fills the stencil shadow with color.\r
150                 virtual void drawStencilShadow(bool clearStencilBuffer=false,\r
151                         video::SColor leftUpEdge = video::SColor(0,0,0,0),\r
152                         video::SColor rightUpEdge = video::SColor(0,0,0,0),\r
153                         video::SColor leftDownEdge = video::SColor(0,0,0,0),\r
154                         video::SColor rightDownEdge = video::SColor(0,0,0,0)) override;\r
155 \r
156                 //! sets a viewport\r
157                 void setViewPort(const core::rect<s32>& area) override;\r
158 \r
159                 //! Sets the fog mode.\r
160                 virtual void setFog(SColor color, E_FOG_TYPE fogType, f32 start,\r
161                         f32 end, f32 density, bool pixelFog, bool rangeFog) override;\r
162 \r
163                 //! Only used internally by the engine\r
164                 void OnResize(const core::dimension2d<u32>& size) override;\r
165 \r
166                 //! Returns type of video driver\r
167                 E_DRIVER_TYPE getDriverType() const override;\r
168 \r
169                 //! get color format of the current color buffer\r
170                 ECOLOR_FORMAT getColorFormat() const override;\r
171 \r
172                 //! Returns the transformation set by setTransform\r
173                 const core::matrix4& getTransform(E_TRANSFORMATION_STATE state) const override;\r
174 \r
175                 //! Can be called by an IMaterialRenderer to make its work easier.\r
176                 virtual void setBasicRenderStates(const SMaterial& material, const SMaterial& lastmaterial,\r
177                         bool resetAllRenderstates) override;\r
178 \r
179                 //! Compare in SMaterial doesn't check texture parameters, so we should call this on each OnRender call.\r
180                 virtual void setTextureRenderStates(const SMaterial& material, bool resetAllRenderstates);\r
181 \r
182                 //! Get a vertex shader constant index.\r
183                 s32 getVertexShaderConstantID(const c8* name) override;\r
184 \r
185                 //! Get a pixel shader constant index.\r
186                 s32 getPixelShaderConstantID(const c8* name) override;\r
187 \r
188                 //! Sets a constant for the vertex shader based on an index.\r
189                 bool setVertexShaderConstant(s32 index, const f32* floats, int count) override;\r
190 \r
191                 //! Int interface for the above.\r
192                 bool setVertexShaderConstant(s32 index, const s32* ints, int count) override;\r
193 \r
194                 //! Uint interface for the above.\r
195                 bool setVertexShaderConstant(s32 index, const u32* ints, int count) override;\r
196 \r
197                 //! Sets a constant for the pixel shader based on an index.\r
198                 bool setPixelShaderConstant(s32 index, const f32* floats, int count) override;\r
199 \r
200                 //! Int interface for the above.\r
201                 bool setPixelShaderConstant(s32 index, const s32* ints, int count) override;\r
202 \r
203                 //! Uint interface for the above.\r
204                 bool setPixelShaderConstant(s32 index, const u32* ints, int count) override;\r
205 \r
206                 //! Sets a vertex shader constant.\r
207                 void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1) override;\r
208 \r
209                 //! Sets a pixel shader constant.\r
210                 void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1) override;\r
211 \r
212                 //! Adds a new material renderer to the VideoDriver\r
213                 virtual s32 addShaderMaterial(const c8* vertexShaderProgram, const c8* pixelShaderProgram,\r
214                         IShaderConstantSetCallBack* callback, E_MATERIAL_TYPE baseMaterial, s32 userData) override;\r
215 \r
216                 //! Adds a new material renderer to the VideoDriver\r
217                 virtual s32 addHighLevelShaderMaterial(const c8* vertexShaderProgram, const c8* vertexShaderEntryPointName,\r
218                         E_VERTEX_SHADER_TYPE vsCompileTarget, const c8* pixelShaderProgram, const c8* pixelShaderEntryPointName,\r
219                         E_PIXEL_SHADER_TYPE psCompileTarget, const c8* geometryShaderProgram, const c8* geometryShaderEntryPointName,\r
220                         E_GEOMETRY_SHADER_TYPE gsCompileTarget, scene::E_PRIMITIVE_TYPE inType, scene::E_PRIMITIVE_TYPE outType,\r
221                         u32 verticesOut, IShaderConstantSetCallBack* callback, E_MATERIAL_TYPE baseMaterial,\r
222                         s32 userData) override;\r
223 \r
224                 //! Returns pointer to the IGPUProgrammingServices interface.\r
225                 IGPUProgrammingServices* getGPUProgrammingServices() override;\r
226 \r
227                 //! Returns a pointer to the IVideoDriver interface.\r
228                 IVideoDriver* getVideoDriver() override;\r
229 \r
230                 //! Returns the maximum amount of primitives\r
231                 u32 getMaximalPrimitiveCount() const override;\r
232 \r
233                 virtual ITexture* addRenderTargetTexture(const core::dimension2d<u32>& size,\r
234                         const io::path& name, const ECOLOR_FORMAT format = ECF_UNKNOWN) override;\r
235 \r
236                 //! Creates a render target texture for a cubemap\r
237                 ITexture* addRenderTargetTextureCubemap(const irr::u32 sideLen,\r
238                                 const io::path& name, const ECOLOR_FORMAT format) override;\r
239 \r
240                 virtual bool setRenderTargetEx(IRenderTarget* target, u16 clearFlag, SColor clearColor = SColor(255, 0, 0, 0),\r
241                         f32 clearDepth = 1.f, u8 clearStencil = 0) override;\r
242 \r
243                 void clearBuffers(u16 flag, SColor color = SColor(255, 0, 0, 0), f32 depth = 1.f, u8 stencil = 0) override;\r
244 \r
245                 //! Returns an image created from the last rendered frame.\r
246                 IImage* createScreenShot(video::ECOLOR_FORMAT format=video::ECF_UNKNOWN, video::E_RENDER_TARGET target=video::ERT_FRAME_BUFFER) override;\r
247 \r
248                 //! checks if an OpenGL error has happened and prints it (+ some internal code which is usually the line number)\r
249                 bool testGLError(int code=0);\r
250 \r
251                 //! Set/unset a clipping plane.\r
252                 bool setClipPlane(u32 index, const core::plane3df& plane, bool enable=false) override;\r
253 \r
254                 //! Enable/disable a clipping plane.\r
255                 void enableClipPlane(u32 index, bool enable) override;\r
256 \r
257                 //! Returns the graphics card vendor name.\r
258                 core::stringc getVendorInfo() override\r
259                 {\r
260                         return VendorName;\r
261                 }\r
262 \r
263                 //! Get the maximal texture size for this driver\r
264                 core::dimension2du getMaxTextureSize() const override;\r
265 \r
266                 void removeTexture(ITexture* texture) override;\r
267 \r
268                 //! Check if the driver supports creating textures with the given color format\r
269                 bool queryTextureFormat(ECOLOR_FORMAT format) const override;\r
270 \r
271                 //! Used by some SceneNodes to check if a material should be rendered in the transparent render pass\r
272                 bool needsTransparentRenderPass(const irr::video::SMaterial& material) const override;\r
273 \r
274                 //! Convert E_BLEND_FACTOR to OpenGL equivalent\r
275                 GLenum getGLBlend(E_BLEND_FACTOR factor) const;\r
276 \r
277                 //! Get ZBuffer bits.\r
278                 GLenum getZBufferBits() const;\r
279 \r
280                 bool getColorFormatParameters(ECOLOR_FORMAT format, GLint& internalFormat, GLenum& pixelFormat,\r
281                         GLenum& pixelType, void(**converter)(const void*, s32, void*)) const;\r
282 \r
283                 COGLES1CacheHandler* getCacheHandler() const;\r
284 \r
285         private:\r
286                 void uploadClipPlane(u32 index);\r
287 \r
288                 //! inits the opengl-es driver\r
289                 bool genericDriverInit(const core::dimension2d<u32>& screenSize, bool stencilBuffer);\r
290 \r
291                 ITexture* createDeviceDependentTexture(const io::path& name, IImage* image) override;\r
292 \r
293                 ITexture* createDeviceDependentTextureCubemap(const io::path& name, const core::array<IImage*>& image) override;\r
294 \r
295                 //! creates a transposed matrix in supplied GLfloat array to pass to OGLES1\r
296                 inline void getGLMatrix(GLfloat gl_matrix[16], const core::matrix4& m);\r
297                 inline void getGLTextureMatrix(GLfloat gl_matrix[16], const core::matrix4& m);\r
298 \r
299                 //! Set GL pipeline to desired texture wrap modes of the material\r
300                 void setWrapMode(const SMaterial& material);\r
301 \r
302                 //! Get OpenGL wrap enum from Irrlicht enum\r
303                 GLint getTextureWrapMode(u8 clamp) const;\r
304 \r
305                 //! sets the needed renderstates\r
306                 void setRenderStates3DMode();\r
307 \r
308                 //! sets the needed renderstates\r
309                 void setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel);\r
310 \r
311                 void createMaterialRenderers();\r
312 \r
313                 //! Assign a hardware light to the specified requested light, if any\r
314                 //! free hardware lights exist.\r
315                 //! \param[in] lightIndex: the index of the requesting light\r
316                 void assignHardwareLight(u32 lightIndex);\r
317 \r
318                 //! Same as `CacheHandler->setViewport`, but also sets `ViewPort`\r
319                 virtual void setViewPortRaw(u32 width, u32 height);\r
320 \r
321                 COGLES1CacheHandler* CacheHandler;\r
322 \r
323                 core::stringw Name;\r
324                 core::matrix4 Matrices[ETS_COUNT];\r
325                 core::array<u8> ColorBuffer;\r
326 \r
327                 //! enumeration for rendering modes such as 2d and 3d for minimizing the switching of renderStates.\r
328                 enum E_RENDER_MODE\r
329                 {\r
330                         ERM_NONE = 0,   // no render state has been set yet.\r
331                         ERM_2D,         // 2d drawing rendermode\r
332                         ERM_3D          // 3d rendering mode\r
333                 };\r
334 \r
335                 E_RENDER_MODE CurrentRenderMode;\r
336                 //! bool to make all renderstates reset if set to true.\r
337                 bool ResetRenderStates;\r
338                 bool Transformation3DChanged;\r
339                 u8 AntiAlias;\r
340 \r
341                 SMaterial Material, LastMaterial;\r
342                 core::array<core::plane3df> UserClipPlane;\r
343                 std::vector<bool> UserClipPlaneEnabled;\r
344 \r
345                 core::stringc VendorName;\r
346 \r
347                 core::matrix4 TextureFlipMatrix;\r
348 \r
349                 //! Color buffer format\r
350                 ECOLOR_FORMAT ColorFormat;\r
351 \r
352                 SIrrlichtCreationParameters Params;\r
353 \r
354                 IContextManager* ContextManager;\r
355         };\r
356 \r
357 } // end namespace video\r
358 } // end namespace irr\r
359 \r
360 #endif // _IRR_COMPILE_WITH_OGLES1_\r
361 \r
362 #endif\r