Fix line endings in the new driver

This commit is contained in:
numzero 2023-03-25 11:11:09 +03:00
parent 28d0e0644c
commit 219b7fd7d2
11 changed files with 4283 additions and 4283 deletions

@ -1,36 +1,36 @@
// Copyright (C) 2023 Vitaliy Lobachevskiy // Copyright (C) 2023 Vitaliy Lobachevskiy
// Copyright (C) 2015 Patryk Nadrowski // Copyright (C) 2015 Patryk Nadrowski
// This file is part of the "Irrlicht Engine". // This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h // For conditions of distribution and use, see copyright notice in irrlicht.h
#pragma once #pragma once
#define GL_GLEXT_PROTOTYPES #define GL_GLEXT_PROTOTYPES
#include <SDL_video.h> #include <SDL_video.h>
#include <SDL_opengl.h> #include <SDL_opengl.h>
namespace irr namespace irr
{ {
namespace video namespace video
{ {
// Forward declarations. // Forward declarations.
class COpenGLCoreFeature; class COpenGLCoreFeature;
template <class TOpenGLDriver> template <class TOpenGLDriver>
class COpenGLCoreTexture; class COpenGLCoreTexture;
template <class TOpenGLDriver, class TOpenGLTexture> template <class TOpenGLDriver, class TOpenGLTexture>
class COpenGLCoreRenderTarget; class COpenGLCoreRenderTarget;
template <class TOpenGLDriver, class TOpenGLTexture> template <class TOpenGLDriver, class TOpenGLTexture>
class COpenGLCoreCacheHandler; class COpenGLCoreCacheHandler;
class COpenGL3DriverBase; class COpenGL3DriverBase;
typedef COpenGLCoreTexture<COpenGL3DriverBase> COpenGL3Texture; typedef COpenGLCoreTexture<COpenGL3DriverBase> COpenGL3Texture;
typedef COpenGLCoreRenderTarget<COpenGL3DriverBase, COpenGL3Texture> COpenGL3RenderTarget; typedef COpenGLCoreRenderTarget<COpenGL3DriverBase, COpenGL3Texture> COpenGL3RenderTarget;
typedef COpenGLCoreCacheHandler<COpenGL3DriverBase, COpenGL3Texture> COpenGL3CacheHandler; typedef COpenGLCoreCacheHandler<COpenGL3DriverBase, COpenGL3Texture> COpenGL3CacheHandler;
} }
} }

File diff suppressed because it is too large Load Diff

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

@ -1,66 +1,66 @@
// Copyright (C) 2015 Patryk Nadrowski // Copyright (C) 2015 Patryk Nadrowski
// Copyright (C) 2009-2010 Amundis // Copyright (C) 2009-2010 Amundis
// 2017 modified by Michael Zeilfelder (unifying extension handlers) // 2017 modified by Michael Zeilfelder (unifying extension handlers)
// This file is part of the "Irrlicht Engine". // This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h // For conditions of distribution and use, see copyright notice in Irrlicht.h
#include "ExtensionHandler.h" #include "ExtensionHandler.h"
#include "irrString.h" #include "irrString.h"
#include "SMaterial.h" #include "SMaterial.h"
#include "fast_atof.h" #include "fast_atof.h"
#include <mt_opengl.h> #include <mt_opengl.h>
namespace irr namespace irr
{ {
namespace video namespace video
{ {
void COpenGL3ExtensionHandler::initExtensions() void COpenGL3ExtensionHandler::initExtensions()
{ {
GLint major, minor; GLint major, minor;
glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MAJOR_VERSION, &major);
glGetIntegerv(GL_MINOR_VERSION, &minor); glGetIntegerv(GL_MINOR_VERSION, &minor);
Version = 100 * major + 10 * minor; Version = 100 * major + 10 * minor;
GLint ext_count = 0; GLint ext_count = 0;
GL.GetIntegerv(GL_NUM_EXTENSIONS, &ext_count); GL.GetIntegerv(GL_NUM_EXTENSIONS, &ext_count);
for (int k = 0; k < ext_count; k++) { for (int k = 0; k < ext_count; k++) {
auto ext_name = (char *)GL.GetStringi(GL_EXTENSIONS, k); auto ext_name = (char *)GL.GetStringi(GL_EXTENSIONS, k);
for (size_t j=0; j<IRR_OGLES_Feature_Count; ++j) { for (size_t j=0; j<IRR_OGLES_Feature_Count; ++j) {
if (!strcmp(getFeatureString(j), ext_name)) { if (!strcmp(getFeatureString(j), ext_name)) {
FeatureAvailable[j] = true; FeatureAvailable[j] = true;
break; break;
} }
} }
} }
GLint val=0; GLint val=0;
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &val); glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &val);
Feature.MaxTextureUnits = static_cast<u8>(val); Feature.MaxTextureUnits = static_cast<u8>(val);
#ifdef GL_EXT_texture_filter_anisotropic #ifdef GL_EXT_texture_filter_anisotropic
if (FeatureAvailable[IRR_GL_EXT_texture_filter_anisotropic]) if (FeatureAvailable[IRR_GL_EXT_texture_filter_anisotropic])
{ {
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &val); glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &val);
MaxAnisotropy = static_cast<u8>(val); MaxAnisotropy = static_cast<u8>(val);
} }
#endif #endif
#ifdef GL_MAX_ELEMENTS_INDICES #ifdef GL_MAX_ELEMENTS_INDICES
glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &val); glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &val);
MaxIndices=val; MaxIndices=val;
#endif #endif
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &val); glGetIntegerv(GL_MAX_TEXTURE_SIZE, &val);
MaxTextureSize=static_cast<u32>(val); MaxTextureSize=static_cast<u32>(val);
#ifdef GL_EXT_texture_lod_bias #ifdef GL_EXT_texture_lod_bias
if (FeatureAvailable[IRR_GL_EXT_texture_lod_bias]) if (FeatureAvailable[IRR_GL_EXT_texture_lod_bias])
glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS_EXT, &MaxTextureLODBias); glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS_EXT, &MaxTextureLODBias);
#endif #endif
glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, DimAliasedLine); glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, DimAliasedLine);
glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, DimAliasedPoint); glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, DimAliasedPoint);
Feature.MaxTextureUnits = core::min_(Feature.MaxTextureUnits, static_cast<u8>(MATERIAL_MAX_TEXTURES)); Feature.MaxTextureUnits = core::min_(Feature.MaxTextureUnits, static_cast<u8>(MATERIAL_MAX_TEXTURES));
Feature.ColorAttachment = 1; Feature.ColorAttachment = 1;
} }
} // end namespace video } // end namespace video
} // end namespace irr } // end namespace irr

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

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

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

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

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

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

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