master #5

Merged
BRNSystems merged 45 commits from Mirrorlandia_minetest/irrlicht:master into master 2024-02-27 13:26:18 +01:00
24 changed files with 3 additions and 6177 deletions
Showing only changes of commit 8189b2338a - Show all commits

@ -1,75 +0,0 @@
precision mediump float;
/* Uniforms */
uniform int uTextureUsage0;
uniform sampler2D uTextureUnit0;
uniform int uBlendType;
uniform int uFogEnable;
uniform int uFogType;
uniform vec4 uFogColor;
uniform float uFogStart;
uniform float uFogEnd;
uniform float uFogDensity;
/* Varyings */
varying vec2 vTextureCoord0;
varying vec4 vVertexColor;
varying vec4 vSpecularColor;
varying float vFogCoord;
float computeFog()
{
const float LOG2 = 1.442695;
float FogFactor = 0.0;
if (uFogType == 0) // Exp
{
FogFactor = exp2(-uFogDensity * vFogCoord * LOG2);
}
else if (uFogType == 1) // Linear
{
float Scale = 1.0 / (uFogEnd - uFogStart);
FogFactor = (uFogEnd - vFogCoord) * Scale;
}
else if (uFogType == 2) // Exp2
{
FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2);
}
FogFactor = clamp(FogFactor, 0.0, 1.0);
return FogFactor;
}
void main()
{
vec4 Color0 = vVertexColor;
vec4 Color1 = vec4(1.0, 1.0, 1.0, 1.0);
if (bool(uTextureUsage0))
Color1 = texture2D(uTextureUnit0, vTextureCoord0);
vec4 FinalColor = Color0 * Color1;
FinalColor += vSpecularColor;
if (uBlendType == 1)
{
FinalColor.w = Color0.w;
}
else if (uBlendType == 2)
{
FinalColor.w = Color1.w;
}
if (bool(uFogEnable))
{
float FogFactor = computeFog();
vec4 FogColor = uFogColor;
FogColor.a = 1.0;
FinalColor = mix(FogColor, FinalColor, FogFactor);
}
gl_FragColor = FinalColor;
}

@ -1,21 +0,0 @@
precision mediump float;
/* Uniforms */
uniform int uTextureUsage;
uniform sampler2D uTextureUnit;
/* Varyings */
varying vec2 vTextureCoord;
varying vec4 vVertexColor;
void main()
{
vec4 Color = vVertexColor;
if (bool(uTextureUsage))
Color *= texture2D(uTextureUnit, vTextureCoord);
gl_FragColor = Color;
}

@ -1,22 +0,0 @@
/* Attributes */
attribute vec4 inVertexPosition;
attribute vec4 inVertexColor;
attribute vec2 inTexCoord0;
/* Uniforms */
uniform float uThickness;
/* Varyings */
varying vec2 vTextureCoord;
varying vec4 vVertexColor;
void main()
{
gl_Position = inVertexPosition;
gl_PointSize = uThickness;
vTextureCoord = inTexCoord0;
vVertexColor = inVertexColor.bgra;
}

@ -1,9 +0,0 @@
precision mediump float;
/* Varyings */
varying vec4 vVertexColor;
void main()
{
gl_FragColor = vVertexColor;
}

@ -1,62 +0,0 @@
precision mediump float;
/* Uniforms */
uniform int uTextureUsage0;
uniform sampler2D uTextureUnit0;
uniform int uFogEnable;
uniform int uFogType;
uniform vec4 uFogColor;
uniform float uFogStart;
uniform float uFogEnd;
uniform float uFogDensity;
/* Varyings */
varying vec2 vTextureCoord0;
varying vec4 vVertexColor;
varying vec4 vSpecularColor;
varying float vFogCoord;
float computeFog()
{
const float LOG2 = 1.442695;
float FogFactor = 0.0;
if (uFogType == 0) // Exp
{
FogFactor = exp2(-uFogDensity * vFogCoord * LOG2);
}
else if (uFogType == 1) // Linear
{
float Scale = 1.0 / (uFogEnd - uFogStart);
FogFactor = (uFogEnd - vFogCoord) * Scale;
}
else if (uFogType == 2) // Exp2
{
FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2);
}
FogFactor = clamp(FogFactor, 0.0, 1.0);
return FogFactor;
}
void main()
{
vec4 Color = vVertexColor;
if (bool(uTextureUsage0))
Color *= texture2D(uTextureUnit0, vTextureCoord0);
Color += vSpecularColor;
if (bool(uFogEnable))
{
float FogFactor = computeFog();
vec4 FogColor = uFogColor;
FogColor.a = 1.0;
Color = mix(FogColor, Color, FogFactor);
}
gl_FragColor = Color;
}

@ -1,45 +0,0 @@
/* Attributes */
attribute vec3 inVertexPosition;
attribute vec3 inVertexNormal;
attribute vec4 inVertexColor;
attribute vec2 inTexCoord0;
/* Uniforms */
uniform mat4 uWVPMatrix;
uniform mat4 uWVMatrix;
uniform mat4 uNMatrix;
uniform mat4 uTMatrix0;
uniform vec4 uGlobalAmbient;
uniform vec4 uMaterialAmbient;
uniform vec4 uMaterialDiffuse;
uniform vec4 uMaterialEmissive;
uniform vec4 uMaterialSpecular;
uniform float uMaterialShininess;
uniform float uThickness;
/* Varyings */
varying vec2 vTextureCoord0;
varying vec4 vVertexColor;
varying vec4 vSpecularColor;
varying float vFogCoord;
void main()
{
gl_Position = uWVPMatrix * vec4(inVertexPosition, 1.0);
gl_PointSize = uThickness;
vec4 TextureCoord0 = vec4(inTexCoord0.x, inTexCoord0.y, 1.0, 1.0);
vTextureCoord0 = vec4(uTMatrix0 * TextureCoord0).xy;
vVertexColor = inVertexColor.bgra;
vSpecularColor = vec4(0.0, 0.0, 0.0, 0.0);
vec3 Position = (uWVMatrix * vec4(inVertexPosition, 1.0)).xyz;
vFogCoord = length(Position);
}

@ -1,69 +0,0 @@
precision mediump float;
/* Uniforms */
uniform float uAlphaRef;
uniform int uTextureUsage0;
uniform sampler2D uTextureUnit0;
uniform int uFogEnable;
uniform int uFogType;
uniform vec4 uFogColor;
uniform float uFogStart;
uniform float uFogEnd;
uniform float uFogDensity;
/* Varyings */
varying vec2 vTextureCoord0;
varying vec4 vVertexColor;
varying vec4 vSpecularColor;
varying float vFogCoord;
float computeFog()
{
const float LOG2 = 1.442695;
float FogFactor = 0.0;
if (uFogType == 0) // Exp
{
FogFactor = exp2(-uFogDensity * vFogCoord * LOG2);
}
else if (uFogType == 1) // Linear
{
float Scale = 1.0 / (uFogEnd - uFogStart);
FogFactor = (uFogEnd - vFogCoord) * Scale;
}
else if (uFogType == 2) // Exp2
{
FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2);
}
FogFactor = clamp(FogFactor, 0.0, 1.0);
return FogFactor;
}
void main()
{
vec4 Color = vVertexColor;
if (bool(uTextureUsage0))
{
Color *= texture2D(uTextureUnit0, vTextureCoord0);
// TODO: uAlphaRef should rather control sharpness of alpha, don't know how to do that right now and this works in most cases.
if (Color.a < uAlphaRef)
discard;
}
Color += vSpecularColor;
if (bool(uFogEnable))
{
float FogFactor = computeFog();
vec4 FogColor = uFogColor;
FogColor.a = 1.0;
Color = mix(FogColor, Color, FogFactor);
}
gl_FragColor = Color;
}

@ -1,67 +0,0 @@
precision mediump float;
/* Uniforms */
uniform float uAlphaRef;
uniform int uTextureUsage0;
uniform sampler2D uTextureUnit0;
uniform int uFogEnable;
uniform int uFogType;
uniform vec4 uFogColor;
uniform float uFogStart;
uniform float uFogEnd;
uniform float uFogDensity;
/* Varyings */
varying vec2 vTextureCoord0;
varying vec4 vVertexColor;
varying vec4 vSpecularColor;
varying float vFogCoord;
float computeFog()
{
const float LOG2 = 1.442695;
float FogFactor = 0.0;
if (uFogType == 0) // Exp
{
FogFactor = exp2(-uFogDensity * vFogCoord * LOG2);
}
else if (uFogType == 1) // Linear
{
float Scale = 1.0 / (uFogEnd - uFogStart);
FogFactor = (uFogEnd - vFogCoord) * Scale;
}
else if (uFogType == 2) // Exp2
{
FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2);
}
FogFactor = clamp(FogFactor, 0.0, 1.0);
return FogFactor;
}
void main()
{
vec4 Color = vVertexColor;
if (bool(uTextureUsage0))
Color *= texture2D(uTextureUnit0, vTextureCoord0);
if (Color.a < uAlphaRef)
discard;
Color += vSpecularColor;
if (bool(uFogEnable))
{
float FogFactor = computeFog();
vec4 FogColor = uFogColor;
FogColor.a = 1.0;
Color = mix(FogColor, Color, FogFactor);
}
gl_FragColor = Color;
}

@ -1,62 +0,0 @@
precision mediump float;
/* Uniforms */
uniform int uTextureUsage0;
uniform sampler2D uTextureUnit0;
uniform int uFogEnable;
uniform int uFogType;
uniform vec4 uFogColor;
uniform float uFogStart;
uniform float uFogEnd;
uniform float uFogDensity;
/* Varyings */
varying vec2 vTextureCoord0;
varying vec4 vVertexColor;
varying vec4 vSpecularColor;
varying float vFogCoord;
float computeFog()
{
const float LOG2 = 1.442695;
float FogFactor = 0.0;
if (uFogType == 0) // Exp
{
FogFactor = exp2(-uFogDensity * vFogCoord * LOG2);
}
else if (uFogType == 1) // Linear
{
float Scale = 1.0 / (uFogEnd - uFogStart);
FogFactor = (uFogEnd - vFogCoord) * Scale;
}
else if (uFogType == 2) // Exp2
{
FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2);
}
FogFactor = clamp(FogFactor, 0.0, 1.0);
return FogFactor;
}
void main()
{
vec4 Color = vVertexColor;
if (bool(uTextureUsage0))
Color *= texture2D(uTextureUnit0, vTextureCoord0);
Color += vSpecularColor;
if (bool(uFogEnable))
{
float FogFactor = computeFog();
vec4 FogColor = uFogColor;
FogColor.a = 1.0;
Color = mix(FogColor, Color, FogFactor);
}
gl_FragColor = Color;
}

@ -176,7 +176,8 @@ else()
set(DEFAULT_WEBGL1 TRUE)
endif()
option(ENABLE_GLES2 "Enable OpenGL ES 2+" ${DEFAULT_GLES2})
option(ENABLE_WEBGL1 "Enable WebGL (requires GLES2)" ${DEFAULT_WEBGL1})
#option(ENABLE_WEBGL1 "Enable WebGL (requires GLES2)" ${DEFAULT_WEBGL1})
set(ENABLE_WEBGL1 FALSE) # not working currently
if(ENABLE_WEBGL1)
set(ENABLE_GLES2 TRUE)
endif()
@ -242,7 +243,7 @@ if (ENABLE_GLES2)
else()
message(STATUS "OpenGL ES 2: OFF")
endif()
message(STATUS "WebGL: ${ENABLE_WEBGL1}")
#message(STATUS "WebGL: ${ENABLE_WEBGL1}")
# Required libs

@ -1,68 +0,0 @@
// Copyright (C) 2015 Patryk Nadrowski
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#pragma once
#ifdef _IRR_COMPILE_WITH_OGLES2_
#if defined(_IRR_COMPILE_WITH_IOS_DEVICE_)
#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h>
#elif defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_)
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <EGL/eglplatform.h>
#elif defined(_IRR_EMSCRIPTEN_PLATFORM_)
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <EGL/eglplatform.h>
#else
#define GL_GLEXT_PROTOTYPES 1
#define GLX_GLXEXT_PROTOTYPES 1
#include <GLES2/gl2.h>
#include <EGL/eglplatform.h>
typedef char GLchar;
#include <GLES2/gl2ext.h>
#endif
#ifndef GL_BGRA
#define GL_BGRA 0x80E1;
#endif
// FBO definitions.
#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 1
#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 2
#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS 3
// to check if this header is in the current compile unit (different GL implementation used different "GLCommon" headers in Irrlicht
#define IRR_COMPILE_GLES2_COMMON
namespace irr
{
namespace video
{
// Forward declarations.
class COpenGLCoreFeature;
template <class TOpenGLDriver>
class COpenGLCoreTexture;
template <class TOpenGLDriver, class TOpenGLTexture>
class COpenGLCoreRenderTarget;
template <class TOpenGLDriver, class TOpenGLTexture>
class COpenGLCoreCacheHandler;
class COGLES2Driver;
typedef COpenGLCoreTexture<COGLES2Driver> COGLES2Texture;
typedef COpenGLCoreRenderTarget<COGLES2Driver, COGLES2Texture> COGLES2RenderTarget;
typedef COpenGLCoreCacheHandler<COGLES2Driver, COGLES2Texture> COGLES2CacheHandler;
}
}
#endif

File diff suppressed because it is too large Load Diff

@ -1,395 +0,0 @@
// Copyright (C) 2014 Patryk Nadrowski
// Copyright (C) 2009-2010 Amundis
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#pragma once
#include "SIrrCreationParameters.h"
#ifdef _IRR_COMPILE_WITH_OGLES2_
#include "CNullDriver.h"
#include "IMaterialRendererServices.h"
#include "EDriverFeatures.h"
#include "fast_atof.h"
#include "COGLES2ExtensionHandler.h"
#include "IContextManager.h"
namespace irr
{
namespace video
{
class COGLES2FixedPipelineRenderer;
class COGLES2Renderer2D;
class COGLES2Driver : public CNullDriver, public IMaterialRendererServices, public COGLES2ExtensionHandler
{
friend class COpenGLCoreTexture<COGLES2Driver>;
friend IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);
protected:
//! constructor (use createOGLES2Driver instead)
COGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);
public:
//! destructor
virtual ~COGLES2Driver();
virtual bool beginScene(u16 clearFlag, SColor clearColor = SColor(255, 0, 0, 0), f32 clearDepth = 1.f, u8 clearStencil = 0,
const SExposedVideoData& videoData = SExposedVideoData(), core::rect<s32>* sourceRect = 0) override;
bool endScene() override;
//! sets transformation
void setTransform(E_TRANSFORMATION_STATE state, const core::matrix4& mat) override;
struct SHWBufferLink_opengl : public SHWBufferLink
{
SHWBufferLink_opengl(const scene::IMeshBuffer *meshBuffer)
: SHWBufferLink(meshBuffer), vbo_verticesID(0), vbo_indicesID(0)
, vbo_verticesSize(0), vbo_indicesSize(0)
{}
u32 vbo_verticesID; //tmp
u32 vbo_indicesID; //tmp
u32 vbo_verticesSize; //tmp
u32 vbo_indicesSize; //tmp
};
bool updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer);
bool updateIndexHardwareBuffer(SHWBufferLink_opengl *HWBuffer);
//! updates hardware buffer if needed
bool updateHardwareBuffer(SHWBufferLink *HWBuffer) override;
//! Create hardware buffer from mesh
SHWBufferLink *createHardwareBuffer(const scene::IMeshBuffer* mb) override;
//! Delete hardware buffer (only some drivers can)
void deleteHardwareBuffer(SHWBufferLink *HWBuffer) override;
//! Draw hardware buffer
void drawHardwareBuffer(SHWBufferLink *HWBuffer) override;
IRenderTarget* addRenderTarget() override;
//! draws a vertex primitive list
virtual void drawVertexPrimitiveList(const void* vertices, u32 vertexCount,
const void* indexList, u32 primitiveCount,
E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType) override;
//! queries the features of the driver, returns true if feature is available
bool queryFeature(E_VIDEO_DRIVER_FEATURE feature) const override
{
return FeatureEnabled[feature] && COGLES2ExtensionHandler::queryFeature(feature);
}
//! Sets a material.
void setMaterial(const SMaterial& material) override;
virtual void draw2DImage(const video::ITexture* texture,
const core::position2d<s32>& destPos,
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
SColor color = SColor(255, 255, 255, 255), bool useAlphaChannelOfTexture = false) override;
virtual void draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect,
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
const video::SColor* const colors = 0, bool useAlphaChannelOfTexture = false) override;
// internally used
virtual void draw2DImage(const video::ITexture* texture, u32 layer, bool flip);
//! draws a set of 2d images
virtual void draw2DImageBatch(const video::ITexture* texture,
const core::position2d<s32>& pos,
const core::array<core::rect<s32> >& sourceRects,
const core::array<s32>& indices, s32 kerningWidth = 0,
const core::rect<s32>* clipRect = 0,
SColor color = SColor(255, 255, 255, 255),
bool useAlphaChannelOfTexture = false) override;
void draw2DImageBatch(const video::ITexture* texture,
const core::array<core::position2d<s32> >& positions,
const core::array<core::rect<s32> >& sourceRects,
const core::rect<s32>* clipRect,
SColor color,
bool useAlphaChannelOfTexture) override;
//! draw an 2d rectangle
virtual void draw2DRectangle(SColor color, const core::rect<s32>& pos,
const core::rect<s32>* clip = 0) override;
//!Draws an 2d rectangle with a gradient.
virtual void draw2DRectangle(const core::rect<s32>& pos,
SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown,
const core::rect<s32>* clip = 0) override;
//! Draws a 2d line.
virtual void draw2DLine(const core::position2d<s32>& start,
const core::position2d<s32>& end,
SColor color = SColor(255, 255, 255, 255)) override;
//! Draws a single pixel
void drawPixel(u32 x, u32 y, const SColor & color) override;
//! Draws a 3d line.
virtual void draw3DLine(const core::vector3df& start,
const core::vector3df& end,
SColor color = SColor(255, 255, 255, 255)) override;
//! Draws a pixel
// virtual void drawPixel(u32 x, u32 y, const SColor & color);
//! Returns the name of the video driver.
const char* getName() const override;
//! Returns the maximum texture size supported.
core::dimension2du getMaxTextureSize() const override;
//! Draws a shadow volume into the stencil buffer.
void drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail, u32 debugDataVisible=0) override;
//! Fills the stencil shadow with color.
virtual void drawStencilShadow(bool clearStencilBuffer=false,
video::SColor leftUpEdge = video::SColor(0,0,0,0),
video::SColor rightUpEdge = video::SColor(0,0,0,0),
video::SColor leftDownEdge = video::SColor(0,0,0,0),
video::SColor rightDownEdge = video::SColor(0,0,0,0)) override;
//! sets a viewport
void setViewPort(const core::rect<s32>& area) override;
//! Only used internally by the engine
void OnResize(const core::dimension2d<u32>& size) override;
//! Returns type of video driver
E_DRIVER_TYPE getDriverType() const override;
//! get color format of the current color buffer
ECOLOR_FORMAT getColorFormat() const override;
//! Returns the transformation set by setTransform
const core::matrix4& getTransform(E_TRANSFORMATION_STATE state) const override;
//! Can be called by an IMaterialRenderer to make its work easier.
void setBasicRenderStates(const SMaterial& material, const SMaterial& lastmaterial, bool resetAllRenderstates) override;
//! Compare in SMaterial doesn't check texture parameters, so we should call this on each OnRender call.
void setTextureRenderStates(const SMaterial& material, bool resetAllRenderstates);
//! Get a vertex shader constant index.
s32 getVertexShaderConstantID(const c8* name) override;
//! Get a pixel shader constant index.
s32 getPixelShaderConstantID(const c8* name) override;
//! Sets a constant for the vertex shader based on an index.
bool setVertexShaderConstant(s32 index, const f32* floats, int count) override;
//! Int interface for the above.
bool setVertexShaderConstant(s32 index, const s32* ints, int count) override;
//! Uint interface for the above.
bool setVertexShaderConstant(s32 index, const u32* ints, int count) override;
//! Sets a constant for the pixel shader based on an index.
bool setPixelShaderConstant(s32 index, const f32* floats, int count) override;
//! Int interface for the above.
bool setPixelShaderConstant(s32 index, const s32* ints, int count) override;
//! Uint interface for the above.
bool setPixelShaderConstant(s32 index, const u32* ints, int count) override;
//! Adds a new material renderer to the VideoDriver
virtual s32 addHighLevelShaderMaterial(
const c8* vertexShaderProgram,
const c8* vertexShaderEntryPointName = 0,
E_VERTEX_SHADER_TYPE vsCompileTarget = EVST_VS_1_1,
const c8* pixelShaderProgram = 0,
const c8* pixelShaderEntryPointName = 0,
E_PIXEL_SHADER_TYPE psCompileTarget = EPST_PS_1_1,
const c8* geometryShaderProgram = 0,
const c8* geometryShaderEntryPointName = "main",
E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0,
scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES,
scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP,
u32 verticesOut = 0,
IShaderConstantSetCallBack* callback = 0,
E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
s32 userData=0) override;
//! Returns pointer to the IGPUProgrammingServices interface.
IGPUProgrammingServices* getGPUProgrammingServices() override;
//! Returns a pointer to the IVideoDriver interface.
IVideoDriver* getVideoDriver() override;
//! Returns the maximum amount of primitives
u32 getMaximalPrimitiveCount() const override;
virtual ITexture* addRenderTargetTexture(const core::dimension2d<u32>& size,
const io::path& name, const ECOLOR_FORMAT format = ECF_UNKNOWN) override;
//! Creates a render target texture for a cubemap
ITexture* addRenderTargetTextureCubemap(const irr::u32 sideLen,
const io::path& name, const ECOLOR_FORMAT format) override;
virtual bool setRenderTargetEx(IRenderTarget* target, u16 clearFlag, SColor clearColor = SColor(255, 0, 0, 0),
f32 clearDepth = 1.f, u8 clearStencil = 0) override;
void clearBuffers(u16 flag, SColor color = SColor(255, 0, 0, 0), f32 depth = 1.f, u8 stencil = 0) override;
//! Returns an image created from the last rendered frame.
IImage* createScreenShot(video::ECOLOR_FORMAT format=video::ECF_UNKNOWN, video::E_RENDER_TARGET target=video::ERT_FRAME_BUFFER) override;
//! checks if an OpenGL error has happened and prints it (+ some internal code which is usually the line number)
bool testGLError(int code=0);
//! checks if an OGLES1 error has happened and prints it
bool testEGLError();
//! Set/unset a clipping plane.
bool setClipPlane(u32 index, const core::plane3df& plane, bool enable = false) override;
//! returns the current amount of user clip planes set.
u32 getClipPlaneCount() const;
//! returns the 0 indexed Plane
const core::plane3df& getClipPlane(u32 index) const;
//! Enable/disable a clipping plane.
void enableClipPlane(u32 index, bool enable) override;
//! Returns the graphics card vendor name.
core::stringc getVendorInfo() override
{
return VendorName;
};
void removeTexture(ITexture* texture) override;
//! Check if the driver supports creating textures with the given color format
bool queryTextureFormat(ECOLOR_FORMAT format) const override;
//! Used by some SceneNodes to check if a material should be rendered in the transparent render pass
bool needsTransparentRenderPass(const irr::video::SMaterial& material) const override;
//! Convert E_BLEND_FACTOR to OpenGL equivalent
GLenum getGLBlend(E_BLEND_FACTOR factor) const;
//! Get ZBuffer bits.
virtual GLenum getZBufferBits() const;
virtual bool getColorFormatParameters(ECOLOR_FORMAT format, GLint& internalFormat, GLenum& pixelFormat,
GLenum& pixelType, void(**converter)(const void*, s32, void*)) const;
//! Get current material.
const SMaterial& getCurrentMaterial() const;
COGLES2CacheHandler* getCacheHandler() const;
protected:
//! inits the opengl-es driver
virtual bool genericDriverInit(const core::dimension2d<u32>& screenSize, bool stencilBuffer);
void chooseMaterial2D();
ITexture* createDeviceDependentTexture(const io::path& name, IImage* image) override;
ITexture* createDeviceDependentTextureCubemap(const io::path& name, const core::array<IImage*>& image) override;
//! Map Irrlicht wrap mode to OpenGL enum
GLint getTextureWrapMode(u8 clamp) const;
//! sets the needed renderstates
void setRenderStates3DMode();
//! sets the needed renderstates
void setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel);
//! Prevent setRenderStateMode calls to do anything.
// hack to allow drawing meshbuffers in 2D mode.
// Better solution would be passing this flag through meshbuffers,
// but the way this is currently implemented in Irrlicht makes this tricky to implement
void lockRenderStateMode()
{
LockRenderStateMode = true;
}
//! Allow setRenderStateMode calls to work again
void unlockRenderStateMode()
{
LockRenderStateMode = false;
}
void draw2D3DVertexPrimitiveList(const void* vertices,
u32 vertexCount, const void* indexList, u32 primitiveCount,
E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType,
E_INDEX_TYPE iType, bool is3D);
void createMaterialRenderers();
void loadShaderData(const io::path& vertexShaderName, const io::path& fragmentShaderName, c8** vertexShaderData, c8** fragmentShaderData);
bool setMaterialTexture(irr::u32 layerIdx, const irr::video::ITexture* texture);
//! Same as `CacheHandler->setViewport`, but also sets `ViewPort`
virtual void setViewPortRaw(u32 width, u32 height);
COGLES2CacheHandler* CacheHandler;
core::stringc Name;
core::stringc VendorName;
SIrrlichtCreationParameters Params;
//! bool to make all renderstates reset if set to true.
bool ResetRenderStates;
bool LockRenderStateMode;
u8 AntiAlias;
struct SUserClipPlane
{
core::plane3df Plane;
bool Enabled;
};
core::array<SUserClipPlane> UserClipPlane;
core::matrix4 TextureFlipMatrix;
private:
COGLES2Renderer2D* MaterialRenderer2DActive;
COGLES2Renderer2D* MaterialRenderer2DTexture;
COGLES2Renderer2D* MaterialRenderer2DNoTexture;
core::matrix4 Matrices[ETS_COUNT];
//! enumeration for rendering modes such as 2d and 3d for minimizing the switching of renderStates.
enum E_RENDER_MODE
{
ERM_NONE = 0, // no render state has been set yet.
ERM_2D, // 2d drawing rendermode
ERM_3D // 3d rendering mode
};
E_RENDER_MODE CurrentRenderMode;
bool Transformation3DChanged;
irr::io::path OGLES2ShaderPath;
SMaterial Material, LastMaterial;
//! Color buffer format
ECOLOR_FORMAT ColorFormat;
IContextManager* ContextManager;
};
} // end namespace video
} // end namespace irr
#endif // _IRR_COMPILE_WITH_OGLES2_

@ -1,57 +0,0 @@
// Copyright (C) 2015 Patryk Nadrowski
// Copyright (C) 2009-2010 Amundis
// 2017 modified by Michael Zeilfelder (unifying extension handlers)
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#include "COGLES2ExtensionHandler.h"
#ifdef _IRR_COMPILE_WITH_OGLES2_
#include "irrString.h"
#include "SMaterial.h"
#include "fast_atof.h"
namespace irr
{
namespace video
{
void COGLES2ExtensionHandler::initExtensions()
{
getGLVersion();
getGLExtensions();
GLint val=0;
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &val);
Feature.MaxTextureUnits = static_cast<u8>(val);
#ifdef GL_EXT_texture_filter_anisotropic
if (FeatureAvailable[IRR_GL_EXT_texture_filter_anisotropic])
{
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &val);
MaxAnisotropy = static_cast<u8>(val);
}
#endif
#ifdef GL_MAX_ELEMENTS_INDICES
glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &val);
MaxIndices=val;
#endif
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &val);
MaxTextureSize=static_cast<u32>(val);
#ifdef GL_EXT_texture_lod_bias
if (FeatureAvailable[IRR_EXT_texture_lod_bias])
glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS_EXT, &MaxTextureLODBias);
#endif
glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, DimAliasedLine);
glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, DimAliasedPoint);
Feature.MaxTextureUnits = core::min_(Feature.MaxTextureUnits, static_cast<u8>(MATERIAL_MAX_TEXTURES));
Feature.ColorAttachment = 1;
}
} // end namespace video
} // end namespace irr
#endif // _IRR_COMPILE_WITH_OGLES2_

@ -1,180 +0,0 @@
// Copyright (C) 2015 Patryk Nadrowski
// Copyright (C) 2009-2010 Amundis
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#pragma once
#ifdef _IRR_COMPILE_WITH_OGLES2_
#include "EDriverFeatures.h"
#include "irrTypes.h"
#include "os.h"
#include "COGLES2Common.h"
#include "COGLESCoreExtensionHandler.h"
namespace irr
{
namespace video
{
class COGLES2ExtensionHandler : public COGLESCoreExtensionHandler
{
public:
COGLES2ExtensionHandler() : COGLESCoreExtensionHandler() {}
void initExtensions();
bool queryFeature(video::E_VIDEO_DRIVER_FEATURE feature) const
{
switch (feature)
{
case EVDF_RENDER_TO_TARGET:
case EVDF_HARDWARE_TL:
case EVDF_MULTITEXTURE:
case EVDF_BILINEAR_FILTER:
case EVDF_MIP_MAP:
case EVDF_MIP_MAP_AUTO_UPDATE:
case EVDF_VERTEX_SHADER_1_1:
case EVDF_PIXEL_SHADER_1_1:
case EVDF_PIXEL_SHADER_1_2:
case EVDF_PIXEL_SHADER_2_0:
case EVDF_VERTEX_SHADER_2_0:
case EVDF_ARB_GLSL:
case EVDF_TEXTURE_NSQUARE:
case EVDF_TEXTURE_NPOT:
case EVDF_FRAMEBUFFER_OBJECT:
case EVDF_VERTEX_BUFFER_OBJECT:
case EVDF_COLOR_MASK:
case EVDF_ALPHA_TO_COVERAGE:
case EVDF_POLYGON_OFFSET:
case EVDF_BLEND_OPERATIONS:
case EVDF_BLEND_SEPARATE:
case EVDF_TEXTURE_MATRIX:
case EVDF_TEXTURE_CUBEMAP:
return true;
case EVDF_ARB_VERTEX_PROGRAM_1:
case EVDF_ARB_FRAGMENT_PROGRAM_1:
case EVDF_GEOMETRY_SHADER:
case EVDF_MULTIPLE_RENDER_TARGETS:
case EVDF_MRT_BLEND:
case EVDF_MRT_COLOR_MASK:
case EVDF_MRT_BLEND_FUNC:
case EVDF_OCCLUSION_QUERY:
return false;
case EVDF_STENCIL_BUFFER:
return StencilBuffer;
default:
return false;
};
}
inline void irrGlActiveTexture(GLenum texture)
{
glActiveTexture(texture);
}
inline void irrGlCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border,
GLsizei imageSize, const void* data)
{
glCompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
}
inline void irrGlCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
GLenum format, GLsizei imageSize, const void* data)
{
glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data);
}
inline void irrGlUseProgram(GLuint prog)
{
glUseProgram(prog);
}
inline void irrGlBindFramebuffer(GLenum target, GLuint framebuffer)
{
glBindFramebuffer(target, framebuffer);
}
inline void irrGlDeleteFramebuffers(GLsizei n, const GLuint *framebuffers)
{
glDeleteFramebuffers(n, framebuffers);
}
inline void irrGlGenFramebuffers(GLsizei n, GLuint *framebuffers)
{
glGenFramebuffers(n, framebuffers);
}
inline GLenum irrGlCheckFramebufferStatus(GLenum target)
{
return glCheckFramebufferStatus(target);
}
inline void irrGlFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
{
glFramebufferTexture2D(target, attachment, textarget, texture, level);
}
inline void irrGlGenerateMipmap(GLenum target)
{
glGenerateMipmap(target);
}
inline void irrGlActiveStencilFace(GLenum face)
{
}
inline void irrGlDrawBuffer(GLenum mode)
{
}
inline void irrGlDrawBuffers(GLsizei n, const GLenum *bufs)
{
}
inline void irrGlBlendFuncSeparate(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha)
{
glBlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha);
}
inline void irrGlBlendEquation(GLenum mode)
{
glBlendEquation(mode);
}
inline void irrGlEnableIndexed(GLenum target, GLuint index)
{
}
inline void irrGlDisableIndexed(GLenum target, GLuint index)
{
}
inline void irrGlColorMaskIndexed(GLuint buf, GLboolean r, GLboolean g, GLboolean b, GLboolean a)
{
}
inline void irrGlBlendFuncIndexed(GLuint buf, GLenum src, GLenum dst)
{
}
inline void irrGlBlendFuncSeparateIndexed(GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
{
}
inline void irrGlBlendEquationIndexed(GLuint buf, GLenum mode)
{
}
inline void irrGlBlendEquationSeparateIndexed(GLuint buf, GLenum modeRGB, GLenum modeAlpha)
{
}
};
}
}
#endif

@ -1,203 +0,0 @@
// Copyright (C) 2014 Patryk Nadrowski
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#include "COGLES2FixedPipelineRenderer.h"
#ifdef _IRR_COMPILE_WITH_OGLES2_
#include "IVideoDriver.h"
namespace irr
{
namespace video
{
// Base callback
COGLES2MaterialBaseCB::COGLES2MaterialBaseCB() :
FirstUpdateBase(true), WVPMatrixID(-1), WVMatrixID(-1), NMatrixID(-1), GlobalAmbientID(-1), MaterialAmbientID(-1), MaterialDiffuseID(-1), MaterialEmissiveID(-1), MaterialSpecularID(-1), MaterialShininessID(-1),
FogEnableID(-1), FogTypeID(-1), FogColorID(-1), FogStartID(-1),
FogEndID(-1), FogDensityID(-1), ThicknessID(-1), LightEnable(false), MaterialAmbient(SColorf(0.f, 0.f, 0.f)), MaterialDiffuse(SColorf(0.f, 0.f, 0.f)), MaterialEmissive(SColorf(0.f, 0.f, 0.f)), MaterialSpecular(SColorf(0.f, 0.f, 0.f)),
MaterialShininess(0.f), FogEnable(0), FogType(1), FogColor(SColorf(0.f, 0.f, 0.f, 1.f)), FogStart(0.f), FogEnd(0.f), FogDensity(0.f), Thickness(1.f)
{
}
void COGLES2MaterialBaseCB::OnSetMaterial(const SMaterial& material)
{
LightEnable = material.Lighting;
MaterialAmbient = SColorf(material.AmbientColor);
MaterialDiffuse = SColorf(material.DiffuseColor);
MaterialEmissive = SColorf(material.EmissiveColor);
MaterialSpecular = SColorf(material.SpecularColor);
MaterialShininess = material.Shininess;
FogEnable = material.FogEnable ? 1 : 0;
Thickness = (material.Thickness > 0.f) ? material.Thickness : 1.f;
}
void COGLES2MaterialBaseCB::OnSetConstants(IMaterialRendererServices* services, s32 userData)
{
IVideoDriver* driver = services->getVideoDriver();
if (FirstUpdateBase)
{
WVPMatrixID = services->getVertexShaderConstantID("uWVPMatrix");
WVMatrixID = services->getVertexShaderConstantID("uWVMatrix");
NMatrixID = services->getVertexShaderConstantID("uNMatrix");
GlobalAmbientID = services->getVertexShaderConstantID("uGlobalAmbient");
MaterialAmbientID = services->getVertexShaderConstantID("uMaterialAmbient");
MaterialDiffuseID = services->getVertexShaderConstantID("uMaterialDiffuse");
MaterialEmissiveID = services->getVertexShaderConstantID("uMaterialEmissive");
MaterialSpecularID = services->getVertexShaderConstantID("uMaterialSpecular");
MaterialShininessID = services->getVertexShaderConstantID("uMaterialShininess");
FogEnableID = services->getVertexShaderConstantID("uFogEnable");
FogTypeID = services->getVertexShaderConstantID("uFogType");
FogColorID = services->getVertexShaderConstantID("uFogColor");
FogStartID = services->getVertexShaderConstantID("uFogStart");
FogEndID = services->getVertexShaderConstantID("uFogEnd");
FogDensityID = services->getVertexShaderConstantID("uFogDensity");
ThicknessID = services->getVertexShaderConstantID("uThickness");
FirstUpdateBase = false;
}
const core::matrix4 W = driver->getTransform(ETS_WORLD);
const core::matrix4 V = driver->getTransform(ETS_VIEW);
const core::matrix4 P = driver->getTransform(ETS_PROJECTION);
core::matrix4 Matrix = P * V * W;
services->setPixelShaderConstant(WVPMatrixID, Matrix.pointer(), 16);
Matrix = V * W;
services->setPixelShaderConstant(WVMatrixID, Matrix.pointer(), 16);
Matrix.makeInverse();
services->setPixelShaderConstant(NMatrixID, Matrix.getTransposed().pointer(), 16);
services->setPixelShaderConstant(FogEnableID, &FogEnable, 1);
if (FogEnable)
{
SColor TempColor(0);
E_FOG_TYPE TempType = EFT_FOG_LINEAR;
bool TempPerFragment = false;
bool TempRange = false;
driver->getFog(TempColor, TempType, FogStart, FogEnd, FogDensity, TempPerFragment, TempRange);
FogType = (s32)TempType;
FogColor = SColorf(TempColor);
services->setPixelShaderConstant(FogTypeID, &FogType, 1);
services->setPixelShaderConstant(FogColorID, reinterpret_cast<f32*>(&FogColor), 4);
services->setPixelShaderConstant(FogStartID, &FogStart, 1);
services->setPixelShaderConstant(FogEndID, &FogEnd, 1);
services->setPixelShaderConstant(FogDensityID, &FogDensity, 1);
}
services->setPixelShaderConstant(ThicknessID, &Thickness, 1);
}
// EMT_SOLID + EMT_TRANSPARENT_ALPHA_CHANNEL + EMT_TRANSPARENT_VERTEX_ALPHA
COGLES2MaterialSolidCB::COGLES2MaterialSolidCB() :
FirstUpdate(true), TMatrix0ID(-1), AlphaRefID(-1), TextureUsage0ID(-1), TextureUnit0ID(-1), AlphaRef(0.5f), TextureUsage0(0), TextureUnit0(0)
{
}
void COGLES2MaterialSolidCB::OnSetMaterial(const SMaterial& material)
{
COGLES2MaterialBaseCB::OnSetMaterial(material);
AlphaRef = material.MaterialTypeParam;
TextureUsage0 = (material.TextureLayers[0].Texture) ? 1 : 0;
}
void COGLES2MaterialSolidCB::OnSetConstants(IMaterialRendererServices* services, s32 userData)
{
COGLES2MaterialBaseCB::OnSetConstants(services, userData);
IVideoDriver* driver = services->getVideoDriver();
if (FirstUpdate)
{
TMatrix0ID = services->getVertexShaderConstantID("uTMatrix0");
AlphaRefID = services->getVertexShaderConstantID("uAlphaRef");
TextureUsage0ID = services->getVertexShaderConstantID("uTextureUsage0");
TextureUnit0ID = services->getVertexShaderConstantID("uTextureUnit0");
FirstUpdate = false;
}
core::matrix4 Matrix = driver->getTransform(ETS_TEXTURE_0);
services->setPixelShaderConstant(TMatrix0ID, Matrix.pointer(), 16);
services->setPixelShaderConstant(AlphaRefID, &AlphaRef, 1);
services->setPixelShaderConstant(TextureUsage0ID, &TextureUsage0, 1);
services->setPixelShaderConstant(TextureUnit0ID, &TextureUnit0, 1);
}
// EMT_ONETEXTURE_BLEND
COGLES2MaterialOneTextureBlendCB::COGLES2MaterialOneTextureBlendCB() :
FirstUpdate(true), TMatrix0ID(-1), BlendTypeID(-1), TextureUsage0ID(-1), TextureUnit0ID(-1), BlendType(0), TextureUsage0(0), TextureUnit0(0)
{
}
void COGLES2MaterialOneTextureBlendCB::OnSetMaterial(const SMaterial& material)
{
COGLES2MaterialBaseCB::OnSetMaterial(material);
BlendType = 0;
E_BLEND_FACTOR srcRGBFact,dstRGBFact,srcAlphaFact,dstAlphaFact;
E_MODULATE_FUNC modulate;
u32 alphaSource;
unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulate, alphaSource, material.MaterialTypeParam);
if (textureBlendFunc_hasAlpha(srcRGBFact) || textureBlendFunc_hasAlpha(dstRGBFact) || textureBlendFunc_hasAlpha(srcAlphaFact) || textureBlendFunc_hasAlpha(dstAlphaFact))
{
if (alphaSource == EAS_VERTEX_COLOR)
{
BlendType = 1;
}
else if (alphaSource == EAS_TEXTURE)
{
BlendType = 2;
}
}
TextureUsage0 = (material.TextureLayers[0].Texture) ? 1 : 0;
}
void COGLES2MaterialOneTextureBlendCB::OnSetConstants(IMaterialRendererServices* services, s32 userData)
{
COGLES2MaterialBaseCB::OnSetConstants(services, userData);
IVideoDriver* driver = services->getVideoDriver();
if (FirstUpdate)
{
TMatrix0ID = services->getVertexShaderConstantID("uTMatrix0");
BlendTypeID = services->getVertexShaderConstantID("uBlendType");
TextureUsage0ID = services->getVertexShaderConstantID("uTextureUsage0");
TextureUnit0ID = services->getVertexShaderConstantID("uTextureUnit0");
FirstUpdate = false;
}
core::matrix4 Matrix = driver->getTransform(ETS_TEXTURE_0);
services->setPixelShaderConstant(TMatrix0ID, Matrix.pointer(), 16);
services->setPixelShaderConstant(BlendTypeID, &BlendType, 1);
services->setPixelShaderConstant(TextureUsage0ID, &TextureUsage0, 1);
services->setPixelShaderConstant(TextureUnit0ID, &TextureUnit0, 1);
}
}
}
#endif

@ -1,111 +0,0 @@
// Copyright (C) 2014 Patryk Nadrowski
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#pragma once
#ifdef _IRR_COMPILE_WITH_OGLES2_
#include "IShaderConstantSetCallBack.h"
#include "IMaterialRendererServices.h"
namespace irr
{
namespace video
{
class COGLES2MaterialBaseCB : public IShaderConstantSetCallBack
{
public:
COGLES2MaterialBaseCB();
virtual void OnSetMaterial(const SMaterial& material);
virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData);
protected:
bool FirstUpdateBase;
s32 WVPMatrixID;
s32 WVMatrixID;
s32 NMatrixID;
s32 GlobalAmbientID;
s32 MaterialAmbientID;
s32 MaterialDiffuseID;
s32 MaterialEmissiveID;
s32 MaterialSpecularID;
s32 MaterialShininessID;
s32 FogEnableID;
s32 FogTypeID;
s32 FogColorID;
s32 FogStartID;
s32 FogEndID;
s32 FogDensityID;
s32 ThicknessID;
bool LightEnable;
SColorf GlobalAmbient;
SColorf MaterialAmbient;
SColorf MaterialDiffuse;
SColorf MaterialEmissive;
SColorf MaterialSpecular;
f32 MaterialShininess;
s32 FogEnable;
s32 FogType;
SColorf FogColor;
f32 FogStart;
f32 FogEnd;
f32 FogDensity;
f32 Thickness;
};
class COGLES2MaterialSolidCB : public COGLES2MaterialBaseCB
{
public:
COGLES2MaterialSolidCB();
virtual void OnSetMaterial(const SMaterial& material);
virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData);
protected:
bool FirstUpdate;
s32 TMatrix0ID;
s32 AlphaRefID;
s32 TextureUsage0ID;
s32 TextureUnit0ID;
f32 AlphaRef;
s32 TextureUsage0;
s32 TextureUnit0;
};
class COGLES2MaterialOneTextureBlendCB : public COGLES2MaterialBaseCB
{
public:
COGLES2MaterialOneTextureBlendCB();
virtual void OnSetMaterial(const SMaterial& material);
virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData);
protected:
bool FirstUpdate;
s32 TMatrix0ID;
s32 BlendTypeID;
s32 TextureUsage0ID;
s32 TextureUnit0ID;
s32 BlendType;
s32 TextureUsage0;
s32 TextureUnit0;
};
}
}
#endif

@ -1,466 +0,0 @@
// Copyright (C) 2014 Patryk Nadrowski
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "COGLES2MaterialRenderer.h"
#ifdef _IRR_COMPILE_WITH_OGLES2_
#include "EVertexAttributes.h"
#include "IGPUProgrammingServices.h"
#include "IShaderConstantSetCallBack.h"
#include "IVideoDriver.h"
#include "os.h"
#include "COGLES2Driver.h"
#include "COpenGLCoreTexture.h"
#include "COpenGLCoreCacheHandler.h"
namespace irr
{
namespace video
{
COGLES2MaterialRenderer::COGLES2MaterialRenderer(COGLES2Driver* driver,
s32& outMaterialTypeNr,
const c8* vertexShaderProgram,
const c8* pixelShaderProgram,
IShaderConstantSetCallBack* callback,
E_MATERIAL_TYPE baseMaterial,
s32 userData)
: Driver(driver), CallBack(callback), Alpha(false), Blending(false), Program(0), UserData(userData)
{
#ifdef _DEBUG
setDebugName("COGLES2MaterialRenderer");
#endif
switch (baseMaterial)
{
case EMT_TRANSPARENT_VERTEX_ALPHA:
case EMT_TRANSPARENT_ALPHA_CHANNEL:
Alpha = true;
break;
case EMT_ONETEXTURE_BLEND:
Blending = true;
break;
default:
break;
}
if (CallBack)
CallBack->grab();
init(outMaterialTypeNr, vertexShaderProgram, pixelShaderProgram);
}
COGLES2MaterialRenderer::COGLES2MaterialRenderer(COGLES2Driver* driver,
IShaderConstantSetCallBack* callback,
E_MATERIAL_TYPE baseMaterial, s32 userData)
: Driver(driver), CallBack(callback), Alpha(false), Blending(false), Program(0), UserData(userData)
{
switch (baseMaterial)
{
case EMT_TRANSPARENT_VERTEX_ALPHA:
case EMT_TRANSPARENT_ALPHA_CHANNEL:
Alpha = true;
break;
case EMT_ONETEXTURE_BLEND:
Blending = true;
break;
default:
break;
}
if (CallBack)
CallBack->grab();
}
COGLES2MaterialRenderer::~COGLES2MaterialRenderer()
{
if (CallBack)
CallBack->drop();
if (Program)
{
GLuint shaders[8];
GLint count;
glGetAttachedShaders(Program, 8, &count, shaders);
count=core::min_(count,8);
for (GLint i=0; i<count; ++i)
glDeleteShader(shaders[i]);
glDeleteProgram(Program);
Program = 0;
}
UniformInfo.clear();
}
GLuint COGLES2MaterialRenderer::getProgram() const
{
return Program;
}
void COGLES2MaterialRenderer::init(s32& outMaterialTypeNr,
const c8* vertexShaderProgram,
const c8* pixelShaderProgram,
bool addMaterial)
{
outMaterialTypeNr = -1;
Program = glCreateProgram();
if (!Program)
return;
if (vertexShaderProgram)
if (!createShader(GL_VERTEX_SHADER, vertexShaderProgram))
return;
if (pixelShaderProgram)
if (!createShader(GL_FRAGMENT_SHADER, pixelShaderProgram))
return;
for ( size_t i = 0; i < EVA_COUNT; ++i )
glBindAttribLocation( Program, i, sBuiltInVertexAttributeNames[i]);
if (!linkProgram())
return;
if (addMaterial)
outMaterialTypeNr = Driver->addMaterialRenderer(this);
}
bool COGLES2MaterialRenderer::OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype)
{
if (CallBack && Program)
CallBack->OnSetConstants(this, UserData);
return true;
}
void COGLES2MaterialRenderer::OnSetMaterial(const video::SMaterial& material,
const video::SMaterial& lastMaterial,
bool resetAllRenderstates,
video::IMaterialRendererServices* services)
{
COGLES2CacheHandler* cacheHandler = Driver->getCacheHandler();
cacheHandler->setProgram(Program);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (Alpha)
{
cacheHandler->setBlend(true);
cacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
else if (Blending)
{
E_BLEND_FACTOR srcRGBFact,dstRGBFact,srcAlphaFact,dstAlphaFact;
E_MODULATE_FUNC modulate;
u32 alphaSource;
unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulate, alphaSource, material.MaterialTypeParam);
cacheHandler->setBlendFuncSeparate(Driver->getGLBlend(srcRGBFact), Driver->getGLBlend(dstRGBFact),
Driver->getGLBlend(srcAlphaFact), Driver->getGLBlend(dstAlphaFact));
cacheHandler->setBlend(true);
}
if (CallBack)
CallBack->OnSetMaterial(material);
}
void COGLES2MaterialRenderer::OnUnsetMaterial()
{
}
bool COGLES2MaterialRenderer::isTransparent() const
{
return (Alpha || Blending);
}
s32 COGLES2MaterialRenderer::getRenderCapability() const
{
return 0;
}
bool COGLES2MaterialRenderer::createShader(GLenum shaderType, const char* shader)
{
if (Program)
{
GLuint shaderHandle = glCreateShader(shaderType);
glShaderSource(shaderHandle, 1, &shader, NULL);
glCompileShader(shaderHandle);
GLint status = 0;
glGetShaderiv(shaderHandle, GL_COMPILE_STATUS, &status);
if (status != GL_TRUE)
{
os::Printer::log("GLSL shader failed to compile", ELL_ERROR);
GLint maxLength=0;
GLint length;
glGetShaderiv(shaderHandle, GL_INFO_LOG_LENGTH,
&maxLength);
if (maxLength)
{
GLchar *infoLog = new GLchar[maxLength];
glGetShaderInfoLog(shaderHandle, maxLength, &length, infoLog);
os::Printer::log(reinterpret_cast<const c8*>(infoLog), ELL_ERROR);
delete [] infoLog;
}
return false;
}
glAttachShader(Program, shaderHandle);
}
return true;
}
bool COGLES2MaterialRenderer::linkProgram()
{
if (Program)
{
glLinkProgram(Program);
GLint status = 0;
glGetProgramiv(Program, GL_LINK_STATUS, &status);
if (!status)
{
os::Printer::log("GLSL shader program failed to link", ELL_ERROR);
GLint maxLength=0;
GLsizei length;
glGetProgramiv(Program, GL_INFO_LOG_LENGTH, &maxLength);
if (maxLength)
{
GLchar *infoLog = new GLchar[maxLength];
glGetProgramInfoLog(Program, maxLength, &length, infoLog);
os::Printer::log(reinterpret_cast<const c8*>(infoLog), ELL_ERROR);
delete [] infoLog;
}
return false;
}
GLint num = 0;
glGetProgramiv(Program, GL_ACTIVE_UNIFORMS, &num);
if (num == 0)
return true;
GLint maxlen = 0;
glGetProgramiv(Program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxlen);
if (maxlen == 0)
{
os::Printer::log("GLSL: failed to retrieve uniform information", ELL_ERROR);
return false;
}
// seems that some implementations use an extra null terminator.
++maxlen;
c8 *buf = new c8[maxlen];
UniformInfo.clear();
UniformInfo.reallocate(num);
for (GLint i=0; i < num; ++i)
{
SUniformInfo ui;
memset(buf, 0, maxlen);
GLint size;
glGetActiveUniform(Program, i, maxlen, 0, &size, &ui.type, reinterpret_cast<GLchar*>(buf));
core::stringc name = "";
// array support, workaround for some bugged drivers.
for (s32 i = 0; i < maxlen; ++i)
{
if (buf[i] == '[' || buf[i] == '\0')
break;
name += buf[i];
}
ui.name = name;
ui.location = glGetUniformLocation(Program, buf);
UniformInfo.push_back(ui);
}
delete [] buf;
}
return true;
}
void COGLES2MaterialRenderer::setBasicRenderStates(const SMaterial& material,
const SMaterial& lastMaterial,
bool resetAllRenderstates)
{
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
}
s32 COGLES2MaterialRenderer::getVertexShaderConstantID(const c8* name)
{
return getPixelShaderConstantID(name);
}
s32 COGLES2MaterialRenderer::getPixelShaderConstantID(const c8* name)
{
for (u32 i = 0; i < UniformInfo.size(); ++i)
{
if (UniformInfo[i].name == name)
return i;
}
return -1;
}
bool COGLES2MaterialRenderer::setVertexShaderConstant(s32 index, const f32* floats, int count)
{
return setPixelShaderConstant(index, floats, count);
}
bool COGLES2MaterialRenderer::setVertexShaderConstant(s32 index, const s32* ints, int count)
{
return setPixelShaderConstant(index, ints, count);
}
bool COGLES2MaterialRenderer::setVertexShaderConstant(s32 index, const u32* ints, int count)
{
return setPixelShaderConstant(index, ints, count);
}
bool COGLES2MaterialRenderer::setPixelShaderConstant(s32 index, const f32* floats, int count)
{
if(index < 0 || UniformInfo[index].location < 0)
return false;
bool status = true;
switch (UniformInfo[index].type)
{
case GL_FLOAT:
glUniform1fv(UniformInfo[index].location, count, floats);
break;
case GL_FLOAT_VEC2:
glUniform2fv(UniformInfo[index].location, count/2, floats);
break;
case GL_FLOAT_VEC3:
glUniform3fv(UniformInfo[index].location, count/3, floats);
break;
case GL_FLOAT_VEC4:
glUniform4fv(UniformInfo[index].location, count/4, floats);
break;
case GL_FLOAT_MAT2:
glUniformMatrix2fv(UniformInfo[index].location, count/4, false, floats);
break;
case GL_FLOAT_MAT3:
glUniformMatrix3fv(UniformInfo[index].location, count/9, false, floats);
break;
case GL_FLOAT_MAT4:
glUniformMatrix4fv(UniformInfo[index].location, count/16, false, floats);
break;
case GL_SAMPLER_2D:
case GL_SAMPLER_CUBE:
{
if(floats)
{
const GLint id = (GLint)(*floats);
glUniform1iv(UniformInfo[index].location, 1, &id);
}
else
status = false;
}
break;
default:
status = false;
break;
}
return status;
}
bool COGLES2MaterialRenderer::setPixelShaderConstant(s32 index, const s32* ints, int count)
{
if(index < 0 || UniformInfo[index].location < 0)
return false;
bool status = true;
switch (UniformInfo[index].type)
{
case GL_INT:
case GL_BOOL:
glUniform1iv(UniformInfo[index].location, count, ints);
break;
case GL_INT_VEC2:
case GL_BOOL_VEC2:
glUniform2iv(UniformInfo[index].location, count/2, ints);
break;
case GL_INT_VEC3:
case GL_BOOL_VEC3:
glUniform3iv(UniformInfo[index].location, count/3, ints);
break;
case GL_INT_VEC4:
case GL_BOOL_VEC4:
glUniform4iv(UniformInfo[index].location, count/4, ints);
break;
case GL_SAMPLER_2D:
case GL_SAMPLER_CUBE:
glUniform1iv(UniformInfo[index].location, 1, ints);
break;
default:
status = false;
break;
}
return status;
}
bool COGLES2MaterialRenderer::setPixelShaderConstant(s32 index, const u32* ints, int count)
{
os::Printer::log("Unsigned int support needs at least GLES 3.0", ELL_WARNING);
return false;
}
IVideoDriver* COGLES2MaterialRenderer::getVideoDriver()
{
return Driver;
}
}
}
#endif

@ -1,100 +0,0 @@
// Copyright (C) 2014 Patryk Nadrowski
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#pragma once
#ifdef _IRR_COMPILE_WITH_OGLES2_
#include "EMaterialTypes.h"
#include "IMaterialRenderer.h"
#include "IMaterialRendererServices.h"
#include "IGPUProgrammingServices.h"
#include "irrArray.h"
#include "irrString.h"
#include "COGLES2Common.h"
namespace irr
{
namespace video
{
class COGLES2Driver;
class COGLES2MaterialRenderer : public IMaterialRenderer, public IMaterialRendererServices
{
public:
COGLES2MaterialRenderer(
COGLES2Driver* driver,
s32& outMaterialTypeNr,
const c8* vertexShaderProgram = 0,
const c8* pixelShaderProgram = 0,
IShaderConstantSetCallBack* callback = 0,
E_MATERIAL_TYPE baseMaterial = EMT_SOLID,
s32 userData = 0);
virtual ~COGLES2MaterialRenderer();
GLuint getProgram() const;
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services);
virtual bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype);
virtual void OnUnsetMaterial();
virtual bool isTransparent() const;
virtual s32 getRenderCapability() const;
void setBasicRenderStates(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates) override;
s32 getVertexShaderConstantID(const c8* name) override;
s32 getPixelShaderConstantID(const c8* name) override;
bool setVertexShaderConstant(s32 index, const f32* floats, int count) override;
bool setVertexShaderConstant(s32 index, const s32* ints, int count) override;
bool setVertexShaderConstant(s32 index, const u32* ints, int count) override;
bool setPixelShaderConstant(s32 index, const f32* floats, int count) override;
bool setPixelShaderConstant(s32 index, const s32* ints, int count) override;
bool setPixelShaderConstant(s32 index, const u32* ints, int count) override;
IVideoDriver* getVideoDriver() override;
protected:
COGLES2MaterialRenderer(COGLES2Driver* driver,
IShaderConstantSetCallBack* callback = 0,
E_MATERIAL_TYPE baseMaterial = EMT_SOLID,
s32 userData = 0);
void init(s32& outMaterialTypeNr, const c8* vertexShaderProgram, const c8* pixelShaderProgram, bool addMaterial = true);
bool createShader(GLenum shaderType, const char* shader);
bool linkProgram();
COGLES2Driver* Driver;
IShaderConstantSetCallBack* CallBack;
bool Alpha;
bool Blending;
struct SUniformInfo
{
core::stringc name;
GLenum type;
GLint location;
};
GLuint Program;
core::array<SUniformInfo> UniformInfo;
s32 UserData;
};
}
}
#endif

@ -1,87 +0,0 @@
// Copyright (C) 2014 Patryk Nadrowski
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#include "COGLES2Renderer2D.h"
#ifdef _IRR_COMPILE_WITH_OGLES2_
#include "IGPUProgrammingServices.h"
#include "os.h"
#include "COGLES2Driver.h"
#include "COpenGLCoreFeature.h"
#include "COpenGLCoreTexture.h"
#include "COpenGLCoreCacheHandler.h"
namespace irr
{
namespace video
{
COGLES2Renderer2D::COGLES2Renderer2D(const c8* vertexShaderProgram, const c8* pixelShaderProgram, COGLES2Driver* driver, bool withTexture) :
COGLES2MaterialRenderer(driver, 0, EMT_SOLID),
WithTexture(withTexture)
{
#ifdef _DEBUG
setDebugName("COGLES2Renderer2D");
#endif
int Temp = 0;
init(Temp, vertexShaderProgram, pixelShaderProgram, false);
COGLES2CacheHandler* cacheHandler = Driver->getCacheHandler();
cacheHandler->setProgram(Program);
// These states don't change later.
ThicknessID = getPixelShaderConstantID("uThickness");
if ( WithTexture )
{
TextureUsageID = getPixelShaderConstantID("uTextureUsage");
s32 TextureUnitID = getPixelShaderConstantID("uTextureUnit");
s32 TextureUnit = 0;
setPixelShaderConstant(TextureUnitID, &TextureUnit, 1);
s32 TextureUsage = 0;
setPixelShaderConstant(TextureUsageID, &TextureUsage, 1);
}
cacheHandler->setProgram(0);
}
COGLES2Renderer2D::~COGLES2Renderer2D()
{
}
void COGLES2Renderer2D::OnSetMaterial(const video::SMaterial& material,
const video::SMaterial& lastMaterial,
bool resetAllRenderstates,
video::IMaterialRendererServices* services)
{
Driver->getCacheHandler()->setProgram(Program);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
f32 Thickness = (material.Thickness > 0.f) ? material.Thickness : 1.f;
setPixelShaderConstant(ThicknessID, &Thickness, 1);
if ( WithTexture )
{
s32 TextureUsage = material.TextureLayers[0].Texture ? 1 : 0;
setPixelShaderConstant(TextureUsageID, &TextureUsage, 1);
}
}
bool COGLES2Renderer2D::OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype)
{
return true;
}
}
}
#endif

@ -1,37 +0,0 @@
// Copyright (C) 2014 Patryk Nadrowski
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#pragma once
#ifdef _IRR_COMPILE_WITH_OGLES2_
#include "COGLES2MaterialRenderer.h"
namespace irr
{
namespace video
{
class COGLES2Renderer2D : public COGLES2MaterialRenderer
{
public:
COGLES2Renderer2D(const c8* vertexShaderProgram, const c8* pixelShaderProgram, COGLES2Driver* driver, bool withTexture);
~COGLES2Renderer2D();
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services);
virtual bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype);
protected:
bool WithTexture;
s32 ThicknessID;
s32 TextureUsageID;
};
}
}
#endif

File diff suppressed because it is too large Load Diff

@ -1,141 +0,0 @@
// Copyright (C) 2017 Michael Zeilfelder
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#pragma once
#include "SIrrCreationParameters.h"
#ifdef _IRR_COMPILE_WITH_WEBGL1_
#include "COGLES2Driver.h"
#include "CWebGLExtensionHandler.h"
#include "CMeshBuffer.h"
#include "EHardwareBufferFlags.h"
namespace irr
{
namespace video
{
//! WebGL friendly subset of OGL ES 2.0.
//! Written for use with emscripten
class CWebGL1Driver : public COGLES2Driver
{
friend class COpenGLCoreTexture<CWebGL1Driver>;
friend IVideoDriver* createWebGL1Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);
protected:
//! constructor
CWebGL1Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);
public:
//! destructor
virtual ~CWebGL1Driver();
//! Returns type of video driver
E_DRIVER_TYPE getDriverType() const override;
//! Is VBO recommended on this mesh?
bool isHardwareBufferRecommend(const scene::IMeshBuffer* mb) override
{
// All buffers must be bound, WebGL doesn't allow sending unbound buffers at all.
return true;
}
//! draws a vertex primitive list
virtual void drawVertexPrimitiveList(const void* vertices, u32 vertexCount,
const void* indexList, u32 primitiveCount,
E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType) override;
//! Draws a mesh buffer
void drawMeshBuffer(const scene::IMeshBuffer* mb) override;
virtual void draw2DImage(const video::ITexture* texture,
const core::position2d<s32>& destPos,
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
SColor color = SColor(255, 255, 255, 255), bool useAlphaChannelOfTexture = false) override;
virtual void draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect,
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
const video::SColor* const colors = 0, bool useAlphaChannelOfTexture = false) override;
// internally used
void draw2DImage(const video::ITexture* texture, u32 layer, bool flip) override;
//! draws a set of 2d images
virtual void draw2DImageBatch(const video::ITexture* texture,
const core::position2d<s32>& pos,
const core::array<core::rect<s32> >& sourceRects,
const core::array<s32>& indices, s32 kerningWidth = 0,
const core::rect<s32>* clipRect = 0,
SColor color = SColor(255, 255, 255, 255),
bool useAlphaChannelOfTexture = false) override;
void draw2DImageBatch(const video::ITexture* texture,
const core::array<core::position2d<s32> >& positions,
const core::array<core::rect<s32> >& sourceRects,
const core::rect<s32>* clipRect,
SColor color,
bool useAlphaChannelOfTexture) override;
//! draw an 2d rectangle
virtual void draw2DRectangle(SColor color, const core::rect<s32>& pos,
const core::rect<s32>* clip = 0) override;
//!Draws an 2d rectangle with a gradient.
virtual void draw2DRectangle(const core::rect<s32>& pos,
SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown,
const core::rect<s32>* clip = 0) override;
//! Draws a 2d line.
virtual void draw2DLine(const core::position2d<s32>& start,
const core::position2d<s32>& end,
SColor color = SColor(255, 255, 255, 255)) override;
//! Draws a single pixel
void drawPixel(u32 x, u32 y, const SColor & color) override;
//! Draws a 3d line.
virtual void draw3DLine(const core::vector3df& start,
const core::vector3df& end,
SColor color = SColor(255, 255, 255, 255)) override;
//! Draws a shadow volume into the stencil buffer.
void drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail, u32 debugDataVisible=0) override;
//! Fills the stencil shadow with color.
virtual void drawStencilShadow(bool clearStencilBuffer=false,
video::SColor leftUpEdge = video::SColor(0,0,0,0),
video::SColor rightUpEdge = video::SColor(0,0,0,0),
video::SColor leftDownEdge = video::SColor(0,0,0,0),
video::SColor rightDownEdge = video::SColor(0,0,0,0)) override;
//! Get ZBuffer bits.
GLenum getZBufferBits() const override;
virtual bool getColorFormatParameters(ECOLOR_FORMAT format, GLint& internalFormat, GLenum& pixelFormat,
GLenum& pixelType, void(**converter)(const void*, s32, void*)) const override;
protected:
// create a meshbuffer which has as many vertices as indices
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;
bool genericDriverInit(const core::dimension2d<u32>& screenSize, bool stencilBuffer) override;
void initWebGLExtensions();
private:
// CWebGL1Driver is derived from COGLES2Driver so it already got an extension handler from that.
// But we shouldn't use other extensions most of the time as there are minor differences.
CWebGLExtensionHandler WebGLExtensions;
// Because we can't have unbound buffers in webgl we give drawing functions bound buffers to use
scene::SMeshBuffer* MBTriangleFanSize4;
scene::SMeshBuffer* MBLinesSize2;
scene::SMeshBuffer* MBPointsSize1;
};
} // end namespace video
} // end namespace irr
#endif // _IRR_COMPILE_WITH_WEBGL1_

@ -1,178 +0,0 @@
// Copyright (C) 2017 Michael Zeilfelder
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#pragma once
#if defined(_IRR_COMPILE_WITH_WEBGL1_) // Note: should also work with WebGL2 once we add that to Irrlicht
#include "COpenGLCoreFeature.h"
namespace irr
{
namespace video
{
// Extension handling for WebGL.
class CWebGLExtensionHandler
{
public:
// Enums used internally to check for WebGL extensions quickly.
// We buffer all extensions on start once in an array.
enum EWebGLFeatures
{
// If you update this enum also update the corresponding WebGLFeatureStrings string-array
// Last updated was up to (including) extension number 35 (EXT_float_blend)
// Khronos ratified WebGL Extensions
IRR_OES_texture_float, // 1
IRR_OES_texture_half_float, // 2
IRR_WEBGL_lose_context, // 3
IRR_OES_standard_derivatives, // 4
IRR_OES_vertex_array_object, // 5
IRR_WEBGL_debug_renderer_info, // 6
IRR_WEBGL_debug_shaders, // 7
IRR_WEBGL_compressed_texture_s3tc, // 8
IRR_WEBGL_depth_texture, // 9
IRR_OES_element_index_uint, // 10
IRR_EXT_texture_filter_anisotropic, // 11
IRR_EXT_frag_depth, // 16
IRR_WEBGL_draw_buffers, // 18
IRR_ANGLE_instanced_arrays, // 19
IRR_OES_texture_float_linear, // 20
IRR_OES_texture_half_float_linear, // 21
IRR_EXT_blend_minmax, // 25
IRR_EXT_shader_texture_lod, // 27
// Community approved WebGL Extensions
IRR_WEBGL_compressed_texture_atc, // 12
IRR_WEBGL_compressed_texture_pvrtc, // 13
IRR_EXT_color_buffer_half_float, // 14
IRR_WEBGL_color_buffer_float, // 15
IRR_EXT_sRGB, // 17
IRR_WEBGL_compressed_texture_etc1, // 24
IRR_EXT_disjoint_timer_query, // 26
IRR_WEBGL_compressed_texture_etc, // 29
IRR_WEBGL_compressed_texture_astc, // 30
IRR_EXT_color_buffer_float, // 31
IRR_WEBGL_compressed_texture_s3tc_srgb, // 32
IRR_EXT_disjoint_timer_query_webgl2, // 33
// Draft WebGL Extensions
IRR_WEBGL_shared_resources, // 22
IRR_WEBGL_security_sensitive_resources, // 23
IRR_OES_fbo_render_mipmap, // 28
IRR_WEBGL_get_buffer_sub_data_async, // 34
IRR_EXT_float_blend, // 35
IRR_WEBGL_Feature_Count
};
CWebGLExtensionHandler()
{
for (u32 i = 0; i < IRR_WEBGL_Feature_Count; ++i)
FeatureAvailable[i] = false;
}
virtual ~CWebGLExtensionHandler() {}
void dump() const
{
for (u32 i = 0; i < IRR_WEBGL_Feature_Count; ++i)
os::Printer::log(getFeatureString(i), FeatureAvailable[i] ? " true" : " false");
}
bool queryWebGLFeature(EWebGLFeatures feature) const
{
return FeatureAvailable[feature];
}
void getGLExtensions()
{
core::stringc extensions = glGetString(GL_EXTENSIONS);
os::Printer::log(extensions.c_str());
const u32 size = extensions.size() + 1;
c8* str = new c8[size];
strncpy(str, extensions.c_str(), extensions.size());
str[extensions.size()] = ' ';
c8* p = str;
for (u32 i=0; i<size; ++i)
{
if (str[i] == ' ')
{
str[i] = 0;
if (*p)
for (size_t j=0; j<IRR_WEBGL_Feature_Count; ++j)
{
if (!strcmp(getFeatureString(j), p))
{
FeatureAvailable[j] = true;
break;
}
}
p = p + strlen(p) + 1;
}
}
delete[] str;
}
protected:
const char* getFeatureString(size_t index) const
{
// Based on https://www.khronos.org/registry/webgl/extensions
// One for each EWebGLFeatures
static const char* const WebGLFeatureStrings[IRR_WEBGL_Feature_Count] =
{
"OES_texture_float",
"OES_texture_half_float",
"WEBGL_lose_context",
"OES_standard_derivatives",
"OES_vertex_array_object",
"WEBGL_debug_renderer_info",
"WEBGL_debug_shaders",
"WEBGL_compressed_texture_s3tc",
"WEBGL_depth_texture",
"OES_element_index_uint",
"EXT_texture_filter_anisotropic",
"EXT_frag_depth",
"WEBGL_draw_buffers",
"ANGLE_instanced_arrays",
"OES_texture_float_linear",
"OES_texture_half_float_linear",
"EXT_blend_minmax",
"EXT_shader_texture_lod",
"WEBGL_compressed_texture_atc",
"WEBGL_compressed_texture_pvrtc",
"EXT_color_buffer_half_float",
"WEBGL_color_buffer_float",
"EXT_sRGB",
"WEBGL_compressed_texture_etc1",
"EXT_disjoint_timer_query",
"WEBGL_compressed_texture_etc",
"WEBGL_compressed_texture_astc",
"EXT_color_buffer_float",
"WEBGL_compressed_texture_s3tc_srgb",
"EXT_disjoint_timer_query_webgl2",
"WEBGL_shared_resources",
"WEBGL_security_sensitive_resources",
"OES_fbo_render_mipmap",
"WEBGL_get_buffer_sub_data_async",
"EXT_float_blend"
};
return WebGLFeatureStrings[index];
}
bool FeatureAvailable[IRR_WEBGL_Feature_Count];
};
}
}
#endif // defined(_IRR_COMPILE_WITH_WEBGL1_)