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
8 #include "IrrCompileConfig.h"
\r
10 #include "SIrrCreationParameters.h"
\r
12 #ifdef _IRR_COMPILE_WITH_WEBGL1_
\r
14 #include "COGLES2Driver.h"
\r
15 #include "CWebGLExtensionHandler.h"
\r
16 #include "CMeshBuffer.h"
\r
17 #include "EHardwareBufferFlags.h"
\r
23 //! WebGL friendly subset of OGL ES 2.0.
\r
24 //! Written for use with emscripten
\r
25 class CWebGL1Driver : public COGLES2Driver
\r
27 friend class COpenGLCoreTexture<CWebGL1Driver>;
\r
28 friend IVideoDriver* createWebGL1Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);
\r
32 CWebGL1Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);
\r
37 virtual ~CWebGL1Driver();
\r
39 //! Returns type of video driver
\r
40 E_DRIVER_TYPE getDriverType() const override;
\r
42 //! Is VBO recommended on this mesh?
\r
43 bool isHardwareBufferRecommend(const scene::IMeshBuffer* mb) override
\r
45 // All buffers must be bound, WebGL doesn't allow sending unbound buffers at all.
\r
49 //! draws a vertex primitive list
\r
50 virtual void drawVertexPrimitiveList(const void* vertices, u32 vertexCount,
\r
51 const void* indexList, u32 primitiveCount,
\r
52 E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType) override;
\r
54 //! Draws a mesh buffer
\r
55 void drawMeshBuffer(const scene::IMeshBuffer* mb) override;
\r
57 virtual void draw2DImage(const video::ITexture* texture,
\r
58 const core::position2d<s32>& destPos,
\r
59 const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
\r
60 SColor color = SColor(255, 255, 255, 255), bool useAlphaChannelOfTexture = false) override;
\r
62 virtual void draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect,
\r
63 const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
\r
64 const video::SColor* const colors = 0, bool useAlphaChannelOfTexture = false) override;
\r
67 void draw2DImage(const video::ITexture* texture, u32 layer, bool flip) override;
\r
69 //! draws a set of 2d images
\r
70 virtual void draw2DImageBatch(const video::ITexture* texture,
\r
71 const core::position2d<s32>& pos,
\r
72 const core::array<core::rect<s32> >& sourceRects,
\r
73 const core::array<s32>& indices, s32 kerningWidth = 0,
\r
74 const core::rect<s32>* clipRect = 0,
\r
75 SColor color = SColor(255, 255, 255, 255),
\r
76 bool useAlphaChannelOfTexture = false) override;
\r
78 void draw2DImageBatch(const video::ITexture* texture,
\r
79 const core::array<core::position2d<s32> >& positions,
\r
80 const core::array<core::rect<s32> >& sourceRects,
\r
81 const core::rect<s32>* clipRect,
\r
83 bool useAlphaChannelOfTexture) override;
\r
85 //! draw an 2d rectangle
\r
86 virtual void draw2DRectangle(SColor color, const core::rect<s32>& pos,
\r
87 const core::rect<s32>* clip = 0) override;
\r
89 //!Draws an 2d rectangle with a gradient.
\r
90 virtual void draw2DRectangle(const core::rect<s32>& pos,
\r
91 SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown,
\r
92 const core::rect<s32>* clip = 0) override;
\r
94 //! Draws a 2d line.
\r
95 virtual void draw2DLine(const core::position2d<s32>& start,
\r
96 const core::position2d<s32>& end,
\r
97 SColor color = SColor(255, 255, 255, 255)) override;
\r
99 //! Draws a single pixel
\r
100 void drawPixel(u32 x, u32 y, const SColor & color) override;
\r
102 //! Draws a 3d line.
\r
103 virtual void draw3DLine(const core::vector3df& start,
\r
104 const core::vector3df& end,
\r
105 SColor color = SColor(255, 255, 255, 255)) override;
\r
107 //! Draws a shadow volume into the stencil buffer.
\r
108 void drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail, u32 debugDataVisible=0) override;
\r
110 //! Fills the stencil shadow with color.
\r
111 virtual void drawStencilShadow(bool clearStencilBuffer=false,
\r
112 video::SColor leftUpEdge = video::SColor(0,0,0,0),
\r
113 video::SColor rightUpEdge = video::SColor(0,0,0,0),
\r
114 video::SColor leftDownEdge = video::SColor(0,0,0,0),
\r
115 video::SColor rightDownEdge = video::SColor(0,0,0,0)) override;
\r
117 //! Get ZBuffer bits.
\r
118 GLenum getZBufferBits() const override;
\r
120 virtual bool getColorFormatParameters(ECOLOR_FORMAT format, GLint& internalFormat, GLenum& pixelFormat,
\r
121 GLenum& pixelType, void(**converter)(const void*, s32, void*)) const override;
\r
124 // create a meshbuffer which has as many vertices as indices
\r
125 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
127 bool genericDriverInit(const core::dimension2d<u32>& screenSize, bool stencilBuffer) override;
\r
128 void initWebGLExtensions();
\r
131 // CWebGL1Driver is derived from COGLES2Driver so it already got an extension handler from that.
\r
132 // But we shouldn't use other extensions most of the time as there are minor differences.
\r
133 CWebGLExtensionHandler WebGLExtensions;
\r
135 // Because we can't have unbound buffers in webgl we give drawing functions bound buffers to use
\r
136 scene::SMeshBuffer* MBTriangleFanSize4;
\r
137 scene::SMeshBuffer* MBLinesSize2;
\r
138 scene::SMeshBuffer* MBPointsSize1;
\r
141 } // end namespace video
\r
142 } // end namespace irr
\r
144 #endif // _IRR_COMPILE_WITH_WEBGL1_
\r
146 #endif // __C_WEBGL1_DRIVER_H_INCLUDED__
\r