1 // Copyright (C) 2017 Michael Zeilfelder
\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_WEBGL1_DRIVER_H_INCLUDED__
\r
6 #define __C_WEBGL1_DRIVER_H_INCLUDED__
\r
9 #include "SIrrCreationParameters.h"
\r
11 #ifdef _IRR_COMPILE_WITH_WEBGL1_
\r
13 #include "COGLES2Driver.h"
\r
14 #include "CWebGLExtensionHandler.h"
\r
15 #include "CMeshBuffer.h"
\r
16 #include "EHardwareBufferFlags.h"
\r
22 //! WebGL friendly subset of OGL ES 2.0.
\r
23 //! Written for use with emscripten
\r
24 class CWebGL1Driver : public COGLES2Driver
\r
26 friend class COpenGLCoreTexture<CWebGL1Driver>;
\r
27 friend IVideoDriver* createWebGL1Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);
\r
31 CWebGL1Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);
\r
36 virtual ~CWebGL1Driver();
\r
38 //! Returns type of video driver
\r
39 E_DRIVER_TYPE getDriverType() const override;
\r
41 //! Is VBO recommended on this mesh?
\r
42 bool isHardwareBufferRecommend(const scene::IMeshBuffer* mb) override
\r
44 // All buffers must be bound, WebGL doesn't allow sending unbound buffers at all.
\r
48 //! draws a vertex primitive list
\r
49 virtual void drawVertexPrimitiveList(const void* vertices, u32 vertexCount,
\r
50 const void* indexList, u32 primitiveCount,
\r
51 E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType) override;
\r
53 //! Draws a mesh buffer
\r
54 void drawMeshBuffer(const scene::IMeshBuffer* mb) override;
\r
56 virtual void draw2DImage(const video::ITexture* texture,
\r
57 const core::position2d<s32>& destPos,
\r
58 const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
\r
59 SColor color = SColor(255, 255, 255, 255), bool useAlphaChannelOfTexture = false) override;
\r
61 virtual void draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect,
\r
62 const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
\r
63 const video::SColor* const colors = 0, bool useAlphaChannelOfTexture = false) override;
\r
66 void draw2DImage(const video::ITexture* texture, u32 layer, bool flip) override;
\r
68 //! draws a set of 2d images
\r
69 virtual void draw2DImageBatch(const video::ITexture* texture,
\r
70 const core::position2d<s32>& pos,
\r
71 const core::array<core::rect<s32> >& sourceRects,
\r
72 const core::array<s32>& indices, s32 kerningWidth = 0,
\r
73 const core::rect<s32>* clipRect = 0,
\r
74 SColor color = SColor(255, 255, 255, 255),
\r
75 bool useAlphaChannelOfTexture = false) override;
\r
77 void draw2DImageBatch(const video::ITexture* texture,
\r
78 const core::array<core::position2d<s32> >& positions,
\r
79 const core::array<core::rect<s32> >& sourceRects,
\r
80 const core::rect<s32>* clipRect,
\r
82 bool useAlphaChannelOfTexture) override;
\r
84 //! draw an 2d rectangle
\r
85 virtual void draw2DRectangle(SColor color, const core::rect<s32>& pos,
\r
86 const core::rect<s32>* clip = 0) override;
\r
88 //!Draws an 2d rectangle with a gradient.
\r
89 virtual void draw2DRectangle(const core::rect<s32>& pos,
\r
90 SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown,
\r
91 const core::rect<s32>* clip = 0) override;
\r
93 //! Draws a 2d line.
\r
94 virtual void draw2DLine(const core::position2d<s32>& start,
\r
95 const core::position2d<s32>& end,
\r
96 SColor color = SColor(255, 255, 255, 255)) override;
\r
98 //! Draws a single pixel
\r
99 void drawPixel(u32 x, u32 y, const SColor & color) override;
\r
101 //! Draws a 3d line.
\r
102 virtual void draw3DLine(const core::vector3df& start,
\r
103 const core::vector3df& end,
\r
104 SColor color = SColor(255, 255, 255, 255)) override;
\r
106 //! Draws a shadow volume into the stencil buffer.
\r
107 void drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail, u32 debugDataVisible=0) override;
\r
109 //! Fills the stencil shadow with color.
\r
110 virtual void drawStencilShadow(bool clearStencilBuffer=false,
\r
111 video::SColor leftUpEdge = video::SColor(0,0,0,0),
\r
112 video::SColor rightUpEdge = video::SColor(0,0,0,0),
\r
113 video::SColor leftDownEdge = video::SColor(0,0,0,0),
\r
114 video::SColor rightDownEdge = video::SColor(0,0,0,0)) override;
\r
116 //! Get ZBuffer bits.
\r
117 GLenum getZBufferBits() const override;
\r
119 virtual bool getColorFormatParameters(ECOLOR_FORMAT format, GLint& internalFormat, GLenum& pixelFormat,
\r
120 GLenum& pixelType, void(**converter)(const void*, s32, void*)) const override;
\r
123 // create a meshbuffer which has as many vertices as indices
\r
124 scene::SMeshBuffer* createSimpleMeshBuffer(irr::u32 numVertices, scene::E_PRIMITIVE_TYPE primitiveType, scene::E_HARDWARE_MAPPING vertexMappingHint=scene::EHM_STREAM, scene::E_HARDWARE_MAPPING indexMappingHint=scene::EHM_STATIC) const;
\r
126 bool genericDriverInit(const core::dimension2d<u32>& screenSize, bool stencilBuffer) override;
\r
127 void initWebGLExtensions();
\r
130 // CWebGL1Driver is derived from COGLES2Driver so it already got an extension handler from that.
\r
131 // But we shouldn't use other extensions most of the time as there are minor differences.
\r
132 CWebGLExtensionHandler WebGLExtensions;
\r
134 // Because we can't have unbound buffers in webgl we give drawing functions bound buffers to use
\r
135 scene::SMeshBuffer* MBTriangleFanSize4;
\r
136 scene::SMeshBuffer* MBLinesSize2;
\r
137 scene::SMeshBuffer* MBPointsSize1;
\r
140 } // end namespace video
\r
141 } // end namespace irr
\r
143 #endif // _IRR_COMPILE_WITH_WEBGL1_
\r
145 #endif // __C_WEBGL1_DRIVER_H_INCLUDED__
\r