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