Reformat the code, using:

find -type f |  # list all regular files
  grep -E '\.(h|cpp|mm)$' |  # filter for source files
  grep -v '/mt_' |  # filter out generated files
  grep -v '/vendor/' | # and vendored GL
  grep -v '/test/image_loader_test.cpp' |  # and this file (has giant literals arrays)
  xargs -n 1 -P $(nproc) clang-format -i  # reformat everything

Co-authored-by: numzero <numzer0@yandex.ru>
This commit is contained in:
Desour
2024-03-20 19:35:52 +01:00
committed by sfan5
parent 9814510b1b
commit f5c6d3e945
292 changed files with 37376 additions and 42421 deletions

View File

@ -8,10 +8,10 @@
#include "irrTypes.h"
// even though we have mt_opengl.h our driver code still uses GL_* constants
#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
#include <SDL_video.h>
#include <SDL_opengl.h>
#include <SDL_video.h>
#include <SDL_opengl.h>
#else
#include "vendor/gl.h"
#include "vendor/gl.h"
#endif
namespace irr
@ -19,37 +19,39 @@ namespace irr
namespace video
{
// Forward declarations.
// Forward declarations.
class COpenGLCoreFeature;
class COpenGLCoreFeature;
template <class TOpenGLDriver>
class COpenGLCoreTexture;
template <class TOpenGLDriver>
class COpenGLCoreTexture;
template <class TOpenGLDriver, class TOpenGLTexture>
class COpenGLCoreRenderTarget;
template <class TOpenGLDriver, class TOpenGLTexture>
class COpenGLCoreRenderTarget;
template <class TOpenGLDriver, class TOpenGLTexture>
class COpenGLCoreCacheHandler;
template <class TOpenGLDriver, class TOpenGLTexture>
class COpenGLCoreCacheHandler;
class COpenGL3DriverBase;
typedef COpenGLCoreTexture<COpenGL3DriverBase> COpenGL3Texture;
typedef COpenGLCoreRenderTarget<COpenGL3DriverBase, COpenGL3Texture> COpenGL3RenderTarget;
typedef COpenGLCoreCacheHandler<COpenGL3DriverBase, COpenGL3Texture> COpenGL3CacheHandler;
class COpenGL3DriverBase;
typedef COpenGLCoreTexture<COpenGL3DriverBase> COpenGL3Texture;
typedef COpenGLCoreRenderTarget<COpenGL3DriverBase, COpenGL3Texture> COpenGL3RenderTarget;
typedef COpenGLCoreCacheHandler<COpenGL3DriverBase, COpenGL3Texture> COpenGL3CacheHandler;
enum class OpenGLSpec: u8 {
Core,
Compat,
ES,
// WebGL, // TODO
};
enum class OpenGLSpec : u8
{
Core,
Compat,
ES,
// WebGL, // TODO
};
struct OpenGLVersion {
OpenGLSpec Spec;
u8 Major;
u8 Minor;
u8 Release;
};
struct OpenGLVersion
{
OpenGLSpec Spec;
u8 Major;
u8 Minor;
u8 Release;
};
}
}

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -18,41 +18,44 @@ namespace irr
{
namespace video
{
void COpenGL3ExtensionHandler::initExtensionsOld()
{
auto extensions_string = reinterpret_cast<const char *>(GL.GetString(GL_EXTENSIONS));
const char *pos = extensions_string;
while (const char *next = strchr(pos, ' ')) {
addExtension(std::string{pos, next});
pos = next + 1;
}
addExtension(pos);
extensionsLoaded();
void COpenGL3ExtensionHandler::initExtensionsOld()
{
auto extensions_string = reinterpret_cast<const char *>(GL.GetString(GL_EXTENSIONS));
const char *pos = extensions_string;
while (const char *next = strchr(pos, ' ')) {
addExtension(std::string{pos, next});
pos = next + 1;
}
addExtension(pos);
extensionsLoaded();
}
void COpenGL3ExtensionHandler::initExtensionsNew()
{
int ext_count = GetInteger(GL_NUM_EXTENSIONS);
for (int k = 0; k < ext_count; k++)
addExtension(reinterpret_cast<const char *>(GL.GetStringi(GL_EXTENSIONS, k)));
extensionsLoaded();
}
void COpenGL3ExtensionHandler::initExtensionsNew()
{
int ext_count = GetInteger(GL_NUM_EXTENSIONS);
for (int k = 0; k < ext_count; k++)
addExtension(reinterpret_cast<const char *>(GL.GetStringi(GL_EXTENSIONS, k)));
extensionsLoaded();
}
void COpenGL3ExtensionHandler::addExtension(std::string &&name) {
Extensions.emplace(std::move(name));
}
void COpenGL3ExtensionHandler::addExtension(std::string &&name)
{
Extensions.emplace(std::move(name));
}
bool COpenGL3ExtensionHandler::queryExtension(const std::string &name) const noexcept {
return Extensions.find(name) != Extensions.end();
}
bool COpenGL3ExtensionHandler::queryExtension(const std::string &name) const noexcept
{
return Extensions.find(name) != Extensions.end();
}
void COpenGL3ExtensionHandler::extensionsLoaded() {
os::Printer::log((std::string("Loaded ") + std::to_string(Extensions.size()) + " extensions:").c_str(), ELL_DEBUG);
for (const auto &it : Extensions)
os::Printer::log((std::string(" ") + it).c_str(), ELL_DEBUG);
for (size_t j = 0; j < IRR_OGLES_Feature_Count; ++j)
FeatureAvailable[j] = queryExtension(getFeatureString(j));
}
void COpenGL3ExtensionHandler::extensionsLoaded()
{
os::Printer::log((std::string("Loaded ") + std::to_string(Extensions.size()) + " extensions:").c_str(), ELL_DEBUG);
for (const auto &it : Extensions)
os::Printer::log((std::string(" ") + it).c_str(), ELL_DEBUG);
for (size_t j = 0; j < IRR_OGLES_Feature_Count; ++j)
FeatureAvailable[j] = queryExtension(getFeatureString(j));
}
} // end namespace video
} // end namespace irr

View File

@ -22,148 +22,149 @@ namespace irr
namespace video
{
class COpenGL3ExtensionHandler : public COGLESCoreExtensionHandler
class COpenGL3ExtensionHandler : public COGLESCoreExtensionHandler
{
public:
COpenGL3ExtensionHandler() :
COGLESCoreExtensionHandler() {}
void initExtensionsOld();
void initExtensionsNew();
/// Checks whether a named extension is present
bool queryExtension(const std::string &name) const noexcept;
bool queryFeature(video::E_VIDEO_DRIVER_FEATURE feature) const
{
public:
COpenGL3ExtensionHandler() : COGLESCoreExtensionHandler() {}
void initExtensionsOld();
void initExtensionsNew();
/// Checks whether a named extension is present
bool queryExtension(const std::string &name) const noexcept;
bool queryFeature(video::E_VIDEO_DRIVER_FEATURE feature) const
{
switch (feature)
{
case EVDF_RENDER_TO_TARGET:
case EVDF_HARDWARE_TL:
case EVDF_MULTITEXTURE:
case EVDF_BILINEAR_FILTER:
case EVDF_MIP_MAP:
case EVDF_MIP_MAP_AUTO_UPDATE:
case EVDF_VERTEX_SHADER_1_1:
case EVDF_PIXEL_SHADER_1_1:
case EVDF_PIXEL_SHADER_1_2:
case EVDF_PIXEL_SHADER_2_0:
case EVDF_VERTEX_SHADER_2_0:
case EVDF_ARB_GLSL:
case EVDF_TEXTURE_NSQUARE:
case EVDF_TEXTURE_NPOT:
case EVDF_FRAMEBUFFER_OBJECT:
case EVDF_VERTEX_BUFFER_OBJECT:
case EVDF_COLOR_MASK:
case EVDF_ALPHA_TO_COVERAGE:
case EVDF_POLYGON_OFFSET:
case EVDF_BLEND_OPERATIONS:
case EVDF_BLEND_SEPARATE:
case EVDF_TEXTURE_MATRIX:
case EVDF_TEXTURE_CUBEMAP:
return true;
case EVDF_ARB_VERTEX_PROGRAM_1:
case EVDF_ARB_FRAGMENT_PROGRAM_1:
case EVDF_GEOMETRY_SHADER:
case EVDF_MULTIPLE_RENDER_TARGETS:
case EVDF_MRT_BLEND:
case EVDF_MRT_COLOR_MASK:
case EVDF_MRT_BLEND_FUNC:
case EVDF_OCCLUSION_QUERY:
return false;
case EVDF_STENCIL_BUFFER:
return StencilBuffer;
default:
return false;
};
}
static GLint GetInteger(GLenum key) {
GLint val = 0;
GL.GetIntegerv(key, &val);
return val;
switch (feature) {
case EVDF_RENDER_TO_TARGET:
case EVDF_HARDWARE_TL:
case EVDF_MULTITEXTURE:
case EVDF_BILINEAR_FILTER:
case EVDF_MIP_MAP:
case EVDF_MIP_MAP_AUTO_UPDATE:
case EVDF_VERTEX_SHADER_1_1:
case EVDF_PIXEL_SHADER_1_1:
case EVDF_PIXEL_SHADER_1_2:
case EVDF_PIXEL_SHADER_2_0:
case EVDF_VERTEX_SHADER_2_0:
case EVDF_ARB_GLSL:
case EVDF_TEXTURE_NSQUARE:
case EVDF_TEXTURE_NPOT:
case EVDF_FRAMEBUFFER_OBJECT:
case EVDF_VERTEX_BUFFER_OBJECT:
case EVDF_COLOR_MASK:
case EVDF_ALPHA_TO_COVERAGE:
case EVDF_POLYGON_OFFSET:
case EVDF_BLEND_OPERATIONS:
case EVDF_BLEND_SEPARATE:
case EVDF_TEXTURE_MATRIX:
case EVDF_TEXTURE_CUBEMAP:
return true;
case EVDF_ARB_VERTEX_PROGRAM_1:
case EVDF_ARB_FRAGMENT_PROGRAM_1:
case EVDF_GEOMETRY_SHADER:
case EVDF_MULTIPLE_RENDER_TARGETS:
case EVDF_MRT_BLEND:
case EVDF_MRT_COLOR_MASK:
case EVDF_MRT_BLEND_FUNC:
case EVDF_OCCLUSION_QUERY:
return false;
case EVDF_STENCIL_BUFFER:
return StencilBuffer;
default:
return false;
};
}
inline void irrGlActiveTexture(GLenum texture)
{
GL.ActiveTexture(texture);
}
inline void irrGlCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border,
GLsizei imageSize, const void* data)
{
os::Printer::log("Compressed textures aren't supported", ELL_ERROR);
}
inline void irrGlCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
GLenum format, GLsizei imageSize, const void* data)
{
os::Printer::log("Compressed textures aren't supported", ELL_ERROR);
}
inline void irrGlUseProgram(GLuint prog)
{
GL.UseProgram(prog);
}
inline void irrGlBindFramebuffer(GLenum target, GLuint framebuffer)
{
GL.BindFramebuffer(target, framebuffer);
}
inline void irrGlDeleteFramebuffers(GLsizei n, const GLuint *framebuffers)
{
GL.DeleteFramebuffers(n, framebuffers);
}
inline void irrGlGenFramebuffers(GLsizei n, GLuint *framebuffers)
{
GL.GenFramebuffers(n, framebuffers);
}
inline GLenum irrGlCheckFramebufferStatus(GLenum target)
{
return GL.CheckFramebufferStatus(target);
}
inline void irrGlFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
{
GL.FramebufferTexture2D(target, attachment, textarget, texture, level);
}
inline void irrGlGenerateMipmap(GLenum target)
{
GL.GenerateMipmap(target);
}
inline void irrGlDrawBuffer(GLenum mode)
{
GL.DrawBuffer(mode);
}
inline void irrGlDrawBuffers(GLsizei n, const GLenum *bufs)
{
GL.DrawBuffers(n, bufs);
}
inline void irrGlBlendFuncSeparate(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha)
{
GL.BlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha);
}
inline void irrGlBlendEquation(GLenum mode)
{
GL.BlendEquation(mode);
}
bool AnisotropicFilterSupported = false;
bool BlendMinMaxSupported = false;
private:
void addExtension(std::string &&name);
void extensionsLoaded();
std::unordered_set<std::string> Extensions;
static GLint GetInteger(GLenum key)
{
GLint val = 0;
GL.GetIntegerv(key, &val);
return val;
};
inline void irrGlActiveTexture(GLenum texture)
{
GL.ActiveTexture(texture);
}
inline void irrGlCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border,
GLsizei imageSize, const void *data)
{
os::Printer::log("Compressed textures aren't supported", ELL_ERROR);
}
inline void irrGlCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
GLenum format, GLsizei imageSize, const void *data)
{
os::Printer::log("Compressed textures aren't supported", ELL_ERROR);
}
inline void irrGlUseProgram(GLuint prog)
{
GL.UseProgram(prog);
}
inline void irrGlBindFramebuffer(GLenum target, GLuint framebuffer)
{
GL.BindFramebuffer(target, framebuffer);
}
inline void irrGlDeleteFramebuffers(GLsizei n, const GLuint *framebuffers)
{
GL.DeleteFramebuffers(n, framebuffers);
}
inline void irrGlGenFramebuffers(GLsizei n, GLuint *framebuffers)
{
GL.GenFramebuffers(n, framebuffers);
}
inline GLenum irrGlCheckFramebufferStatus(GLenum target)
{
return GL.CheckFramebufferStatus(target);
}
inline void irrGlFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
{
GL.FramebufferTexture2D(target, attachment, textarget, texture, level);
}
inline void irrGlGenerateMipmap(GLenum target)
{
GL.GenerateMipmap(target);
}
inline void irrGlDrawBuffer(GLenum mode)
{
GL.DrawBuffer(mode);
}
inline void irrGlDrawBuffers(GLsizei n, const GLenum *bufs)
{
GL.DrawBuffers(n, bufs);
}
inline void irrGlBlendFuncSeparate(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha)
{
GL.BlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha);
}
inline void irrGlBlendEquation(GLenum mode)
{
GL.BlendEquation(mode);
}
bool AnisotropicFilterSupported = false;
bool BlendMinMaxSupported = false;
private:
void addExtension(std::string &&name);
void extensionsLoaded();
std::unordered_set<std::string> Extensions;
};
}
}

View File

@ -15,14 +15,14 @@ namespace video
// Base callback
COpenGL3MaterialBaseCB::COpenGL3MaterialBaseCB() :
FirstUpdateBase(true), WVPMatrixID(-1), WVMatrixID(-1), NMatrixID(-1),
FogEnableID(-1), FogTypeID(-1), FogColorID(-1), FogStartID(-1),
FogEndID(-1), FogDensityID(-1), ThicknessID(-1), LightEnable(false), MaterialAmbient(SColorf(0.f, 0.f, 0.f)), MaterialDiffuse(SColorf(0.f, 0.f, 0.f)), MaterialEmissive(SColorf(0.f, 0.f, 0.f)), MaterialSpecular(SColorf(0.f, 0.f, 0.f)),
MaterialShininess(0.f), FogEnable(0), FogType(1), FogColor(SColorf(0.f, 0.f, 0.f, 1.f)), FogStart(0.f), FogEnd(0.f), FogDensity(0.f), Thickness(1.f)
FirstUpdateBase(true), WVPMatrixID(-1), WVMatrixID(-1), NMatrixID(-1),
FogEnableID(-1), FogTypeID(-1), FogColorID(-1), FogStartID(-1),
FogEndID(-1), FogDensityID(-1), ThicknessID(-1), LightEnable(false), MaterialAmbient(SColorf(0.f, 0.f, 0.f)), MaterialDiffuse(SColorf(0.f, 0.f, 0.f)), MaterialEmissive(SColorf(0.f, 0.f, 0.f)), MaterialSpecular(SColorf(0.f, 0.f, 0.f)),
MaterialShininess(0.f), FogEnable(0), FogType(1), FogColor(SColorf(0.f, 0.f, 0.f, 1.f)), FogStart(0.f), FogEnd(0.f), FogDensity(0.f), Thickness(1.f)
{
}
void COpenGL3MaterialBaseCB::OnSetMaterial(const SMaterial& material)
void COpenGL3MaterialBaseCB::OnSetMaterial(const SMaterial &material)
{
LightEnable = material.Lighting;
MaterialAmbient = SColorf(material.AmbientColor);
@ -36,12 +36,11 @@ void COpenGL3MaterialBaseCB::OnSetMaterial(const SMaterial& material)
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");
WVMatrixID = services->getVertexShaderConstantID("uWVMatrix");
NMatrixID = services->getVertexShaderConstantID("uNMatrix");
@ -72,8 +71,7 @@ void COpenGL3MaterialBaseCB::OnSetConstants(IMaterialRendererServices* services,
services->setPixelShaderConstant(FogEnableID, &FogEnable, 1);
if (FogEnable)
{
if (FogEnable) {
SColor TempColor(0);
E_FOG_TYPE TempType = EFT_FOG_LINEAR;
bool TempPerFragment = false;
@ -85,7 +83,7 @@ void COpenGL3MaterialBaseCB::OnSetConstants(IMaterialRendererServices* services,
FogColor = SColorf(TempColor);
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(FogEndID, &FogEnd, 1);
services->setPixelShaderConstant(FogDensityID, &FogDensity, 1);
@ -97,11 +95,11 @@ void COpenGL3MaterialBaseCB::OnSetConstants(IMaterialRendererServices* services,
// EMT_SOLID + EMT_TRANSPARENT_ALPHA_CHANNEL + EMT_TRANSPARENT_VERTEX_ALPHA
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);
@ -109,14 +107,13 @@ void COpenGL3MaterialSolidCB::OnSetMaterial(const SMaterial& material)
TextureUsage0 = (material.TextureLayers[0].Texture) ? 1 : 0;
}
void COpenGL3MaterialSolidCB::OnSetConstants(IMaterialRendererServices* services, s32 userData)
void COpenGL3MaterialSolidCB::OnSetConstants(IMaterialRendererServices *services, s32 userData)
{
COpenGL3MaterialBaseCB::OnSetConstants(services, userData);
IVideoDriver* driver = services->getVideoDriver();
IVideoDriver *driver = services->getVideoDriver();
if (FirstUpdate)
{
if (FirstUpdate) {
TMatrix0ID = services->getVertexShaderConstantID("uTMatrix0");
AlphaRefID = services->getVertexShaderConstantID("uAlphaRef");
TextureUsage0ID = services->getVertexShaderConstantID("uTextureUsage0");
@ -136,29 +133,25 @@ void COpenGL3MaterialSolidCB::OnSetConstants(IMaterialRendererServices* services
// EMT_ONETEXTURE_BLEND
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);
BlendType = 0;
E_BLEND_FACTOR srcRGBFact,dstRGBFact,srcAlphaFact,dstAlphaFact;
E_BLEND_FACTOR srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact;
E_MODULATE_FUNC modulate;
u32 alphaSource;
unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulate, alphaSource, material.MaterialTypeParam);
if (textureBlendFunc_hasAlpha(srcRGBFact) || textureBlendFunc_hasAlpha(dstRGBFact) || textureBlendFunc_hasAlpha(srcAlphaFact) || textureBlendFunc_hasAlpha(dstAlphaFact))
{
if (alphaSource == EAS_VERTEX_COLOR)
{
if (textureBlendFunc_hasAlpha(srcRGBFact) || textureBlendFunc_hasAlpha(dstRGBFact) || textureBlendFunc_hasAlpha(srcAlphaFact) || textureBlendFunc_hasAlpha(dstAlphaFact)) {
if (alphaSource == EAS_VERTEX_COLOR) {
BlendType = 1;
}
else if (alphaSource == EAS_TEXTURE)
{
} else if (alphaSource == EAS_TEXTURE) {
BlendType = 2;
}
}
@ -166,14 +159,13 @@ void COpenGL3MaterialOneTextureBlendCB::OnSetMaterial(const SMaterial& material)
TextureUsage0 = (material.TextureLayers[0].Texture) ? 1 : 0;
}
void COpenGL3MaterialOneTextureBlendCB::OnSetConstants(IMaterialRendererServices* services, s32 userData)
void COpenGL3MaterialOneTextureBlendCB::OnSetConstants(IMaterialRendererServices *services, s32 userData)
{
COpenGL3MaterialBaseCB::OnSetConstants(services, userData);
IVideoDriver* driver = services->getVideoDriver();
IVideoDriver *driver = services->getVideoDriver();
if (FirstUpdate)
{
if (FirstUpdate) {
TMatrix0ID = services->getVertexShaderConstantID("uTMatrix0");
BlendTypeID = services->getVertexShaderConstantID("uBlendType");
TextureUsage0ID = services->getVertexShaderConstantID("uTextureUsage0");

View File

@ -18,8 +18,8 @@ class COpenGL3MaterialBaseCB : public IShaderConstantSetCallBack
public:
COpenGL3MaterialBaseCB();
virtual void OnSetMaterial(const SMaterial& material);
virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData);
virtual void OnSetMaterial(const SMaterial &material);
virtual void OnSetConstants(IMaterialRendererServices *services, s32 userData);
protected:
bool FirstUpdateBase;
@ -60,8 +60,8 @@ class COpenGL3MaterialSolidCB : public COpenGL3MaterialBaseCB
public:
COpenGL3MaterialSolidCB();
virtual void OnSetMaterial(const SMaterial& material);
virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData);
virtual void OnSetMaterial(const SMaterial &material);
virtual void OnSetConstants(IMaterialRendererServices *services, s32 userData);
protected:
bool FirstUpdate;
@ -81,8 +81,8 @@ class COpenGL3MaterialOneTextureBlendCB : public COpenGL3MaterialBaseCB
public:
COpenGL3MaterialOneTextureBlendCB();
virtual void OnSetMaterial(const SMaterial& material);
virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData);
virtual void OnSetMaterial(const SMaterial &material);
virtual void OnSetConstants(IMaterialRendererServices *services, s32 userData);
protected:
bool FirstUpdate;

View File

@ -20,22 +20,21 @@ namespace irr
namespace video
{
COpenGL3MaterialRenderer::COpenGL3MaterialRenderer(COpenGL3DriverBase* driver,
s32& outMaterialTypeNr,
const c8* vertexShaderProgram,
const c8* pixelShaderProgram,
IShaderConstantSetCallBack* callback,
COpenGL3MaterialRenderer::COpenGL3MaterialRenderer(COpenGL3DriverBase *driver,
s32 &outMaterialTypeNr,
const c8 *vertexShaderProgram,
const c8 *pixelShaderProgram,
IShaderConstantSetCallBack *callback,
E_MATERIAL_TYPE baseMaterial,
s32 userData)
: Driver(driver), CallBack(callback), Alpha(false), Blending(false), Program(0), UserData(userData)
s32 userData) :
Driver(driver),
CallBack(callback), Alpha(false), Blending(false), Program(0), UserData(userData)
{
#ifdef _DEBUG
setDebugName("MaterialRenderer");
#endif
switch (baseMaterial)
{
switch (baseMaterial) {
case EMT_TRANSPARENT_VERTEX_ALPHA:
case EMT_TRANSPARENT_ALPHA_CHANNEL:
Alpha = true;
@ -53,14 +52,13 @@ COpenGL3MaterialRenderer::COpenGL3MaterialRenderer(COpenGL3DriverBase* driver,
init(outMaterialTypeNr, vertexShaderProgram, pixelShaderProgram);
}
COpenGL3MaterialRenderer::COpenGL3MaterialRenderer(COpenGL3DriverBase* driver,
IShaderConstantSetCallBack* callback,
E_MATERIAL_TYPE baseMaterial, s32 userData)
: Driver(driver), CallBack(callback), Alpha(false), Blending(false), Program(0), UserData(userData)
COpenGL3MaterialRenderer::COpenGL3MaterialRenderer(COpenGL3DriverBase *driver,
IShaderConstantSetCallBack *callback,
E_MATERIAL_TYPE baseMaterial, s32 userData) :
Driver(driver),
CallBack(callback), Alpha(false), Blending(false), Program(0), UserData(userData)
{
switch (baseMaterial)
{
switch (baseMaterial) {
case EMT_TRANSPARENT_VERTEX_ALPHA:
case EMT_TRANSPARENT_ALPHA_CHANNEL:
Alpha = true;
@ -76,20 +74,18 @@ COpenGL3MaterialRenderer::COpenGL3MaterialRenderer(COpenGL3DriverBase* driver,
CallBack->grab();
}
COpenGL3MaterialRenderer::~COpenGL3MaterialRenderer()
{
if (CallBack)
CallBack->drop();
if (Program)
{
if (Program) {
GLuint shaders[8];
GLint count;
GL.GetAttachedShaders(Program, 8, &count, shaders);
count=core::min_(count,8);
for (GLint i=0; i<count; ++i)
count = core::min_(count, 8);
for (GLint i = 0; i < count; ++i)
GL.DeleteShader(shaders[i]);
GL.DeleteProgram(Program);
Program = 0;
@ -103,9 +99,9 @@ GLuint COpenGL3MaterialRenderer::getProgram() const
return Program;
}
void COpenGL3MaterialRenderer::init(s32& outMaterialTypeNr,
const c8* vertexShaderProgram,
const c8* pixelShaderProgram,
void COpenGL3MaterialRenderer::init(s32 &outMaterialTypeNr,
const c8 *vertexShaderProgram,
const c8 *pixelShaderProgram,
bool addMaterial)
{
outMaterialTypeNr = -1;
@ -123,8 +119,8 @@ void COpenGL3MaterialRenderer::init(s32& outMaterialTypeNr,
if (!createShader(GL_FRAGMENT_SHADER, pixelShaderProgram))
return;
for ( size_t i = 0; i < EVA_COUNT; ++i )
GL.BindAttribLocation( Program, i, sBuiltInVertexAttributeNames[i]);
for (size_t i = 0; i < EVA_COUNT; ++i)
GL.BindAttribLocation(Program, i, sBuiltInVertexAttributeNames[i]);
if (!linkProgram())
return;
@ -133,8 +129,7 @@ void COpenGL3MaterialRenderer::init(s32& outMaterialTypeNr,
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)
CallBack->OnSetConstants(this, UserData);
@ -142,32 +137,28 @@ bool COpenGL3MaterialRenderer::OnRender(IMaterialRendererServices* service, E_VE
return true;
}
void COpenGL3MaterialRenderer::OnSetMaterial(const video::SMaterial& material,
const video::SMaterial& lastMaterial,
bool resetAllRenderstates,
video::IMaterialRendererServices* services)
void COpenGL3MaterialRenderer::OnSetMaterial(const video::SMaterial &material,
const video::SMaterial &lastMaterial,
bool resetAllRenderstates,
video::IMaterialRendererServices *services)
{
COpenGL3CacheHandler* cacheHandler = Driver->getCacheHandler();
COpenGL3CacheHandler *cacheHandler = Driver->getCacheHandler();
cacheHandler->setProgram(Program);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (Alpha)
{
if (Alpha) {
cacheHandler->setBlend(true);
cacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
else if (Blending)
{
E_BLEND_FACTOR srcRGBFact,dstRGBFact,srcAlphaFact,dstAlphaFact;
} else if (Blending) {
E_BLEND_FACTOR srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact;
E_MODULATE_FUNC modulate;
u32 alphaSource;
unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulate, alphaSource, material.MaterialTypeParam);
cacheHandler->setBlendFuncSeparate(Driver->getGLBlend(srcRGBFact), Driver->getGLBlend(dstRGBFact),
Driver->getGLBlend(srcAlphaFact), Driver->getGLBlend(dstAlphaFact));
Driver->getGLBlend(srcAlphaFact), Driver->getGLBlend(dstAlphaFact));
cacheHandler->setBlend(true);
}
@ -176,28 +167,23 @@ void COpenGL3MaterialRenderer::OnSetMaterial(const video::SMaterial& material,
CallBack->OnSetMaterial(material);
}
void COpenGL3MaterialRenderer::OnUnsetMaterial()
{
}
bool COpenGL3MaterialRenderer::isTransparent() const
{
return (Alpha || Blending);
}
s32 COpenGL3MaterialRenderer::getRenderCapability() const
{
return 0;
}
bool COpenGL3MaterialRenderer::createShader(GLenum shaderType, const char* shader)
bool COpenGL3MaterialRenderer::createShader(GLenum shaderType, const char *shader)
{
if (Program)
{
if (Program) {
GLuint shaderHandle = GL.CreateShader(shaderType);
GL.ShaderSource(shaderHandle, 1, &shader, NULL);
GL.CompileShader(shaderHandle);
@ -206,22 +192,20 @@ bool COpenGL3MaterialRenderer::createShader(GLenum shaderType, const char* shade
GL.GetShaderiv(shaderHandle, GL_COMPILE_STATUS, &status);
if (status != GL_TRUE)
{
if (status != GL_TRUE) {
os::Printer::log("GLSL shader failed to compile", ELL_ERROR);
GLint maxLength=0;
GLint maxLength = 0;
GLint length;
GL.GetShaderiv(shaderHandle, GL_INFO_LOG_LENGTH,
&maxLength);
if (maxLength)
{
if (maxLength) {
GLchar *infoLog = new GLchar[maxLength];
GL.GetShaderInfoLog(shaderHandle, maxLength, &length, infoLog);
os::Printer::log(reinterpret_cast<const c8*>(infoLog), ELL_ERROR);
delete [] infoLog;
os::Printer::log(reinterpret_cast<const c8 *>(infoLog), ELL_ERROR);
delete[] infoLog;
}
return false;
@ -233,32 +217,28 @@ bool COpenGL3MaterialRenderer::createShader(GLenum shaderType, const char* shade
return true;
}
bool COpenGL3MaterialRenderer::linkProgram()
{
if (Program)
{
if (Program) {
GL.LinkProgram(Program);
GLint status = 0;
GL.GetProgramiv(Program, GL_LINK_STATUS, &status);
if (!status)
{
if (!status) {
os::Printer::log("GLSL shader program failed to link", ELL_ERROR);
GLint maxLength=0;
GLint maxLength = 0;
GLsizei length;
GL.GetProgramiv(Program, GL_INFO_LOG_LENGTH, &maxLength);
if (maxLength)
{
if (maxLength) {
GLchar *infoLog = new GLchar[maxLength];
GL.GetProgramInfoLog(Program, maxLength, &length, infoLog);
os::Printer::log(reinterpret_cast<const c8*>(infoLog), ELL_ERROR);
delete [] infoLog;
os::Printer::log(reinterpret_cast<const c8 *>(infoLog), ELL_ERROR);
delete[] infoLog;
}
return false;
@ -275,8 +255,7 @@ bool COpenGL3MaterialRenderer::linkProgram()
GL.GetProgramiv(Program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxlen);
if (maxlen == 0)
{
if (maxlen == 0) {
os::Printer::log("GLSL: failed to retrieve uniform information", ELL_ERROR);
return false;
}
@ -288,23 +267,21 @@ bool COpenGL3MaterialRenderer::linkProgram()
UniformInfo.clear();
UniformInfo.reallocate(num);
for (GLint i=0; i < num; ++i)
{
for (GLint i = 0; i < num; ++i) {
SUniformInfo ui;
memset(buf, 0, maxlen);
GLint size;
GL.GetActiveUniform(Program, i, maxlen, 0, &size, &ui.type, reinterpret_cast<GLchar*>(buf));
GL.GetActiveUniform(Program, i, maxlen, 0, &size, &ui.type, reinterpret_cast<GLchar *>(buf));
core::stringc name = "";
core::stringc name = "";
// 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')
break;
name += buf[i];
name += buf[i];
}
ui.name = name;
@ -313,29 +290,27 @@ bool COpenGL3MaterialRenderer::linkProgram()
UniformInfo.push_back(ui);
}
delete [] buf;
delete[] buf;
}
return true;
}
void COpenGL3MaterialRenderer::setBasicRenderStates(const SMaterial& material,
const SMaterial& lastMaterial,
bool resetAllRenderstates)
void COpenGL3MaterialRenderer::setBasicRenderStates(const SMaterial &material,
const SMaterial &lastMaterial,
bool resetAllRenderstates)
{
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
}
s32 COpenGL3MaterialRenderer::getVertexShaderConstantID(const c8* name)
s32 COpenGL3MaterialRenderer::getVertexShaderConstantID(const c8 *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)
return i;
}
@ -343,115 +318,109 @@ s32 COpenGL3MaterialRenderer::getPixelShaderConstantID(const c8* name)
return -1;
}
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);
}
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);
}
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);
}
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;
bool status = true;
switch (UniformInfo[index].type)
{
case GL_FLOAT:
GL.Uniform1fv(UniformInfo[index].location, count, floats);
break;
case GL_FLOAT_VEC2:
GL.Uniform2fv(UniformInfo[index].location, count/2, floats);
break;
case GL_FLOAT_VEC3:
GL.Uniform3fv(UniformInfo[index].location, count/3, floats);
break;
case GL_FLOAT_VEC4:
GL.Uniform4fv(UniformInfo[index].location, count/4, floats);
break;
case GL_FLOAT_MAT2:
GL.UniformMatrix2fv(UniformInfo[index].location, count/4, false, floats);
break;
case GL_FLOAT_MAT3:
GL.UniformMatrix3fv(UniformInfo[index].location, count/9, false, floats);
break;
case GL_FLOAT_MAT4:
GL.UniformMatrix4fv(UniformInfo[index].location, count/16, false, floats);
break;
case GL_SAMPLER_2D:
case GL_SAMPLER_CUBE:
{
if(floats)
{
const GLint id = (GLint)(*floats);
GL.Uniform1iv(UniformInfo[index].location, 1, &id);
}
else
status = false;
}
break;
default:
switch (UniformInfo[index].type) {
case GL_FLOAT:
GL.Uniform1fv(UniformInfo[index].location, count, floats);
break;
case GL_FLOAT_VEC2:
GL.Uniform2fv(UniformInfo[index].location, count / 2, floats);
break;
case GL_FLOAT_VEC3:
GL.Uniform3fv(UniformInfo[index].location, count / 3, floats);
break;
case GL_FLOAT_VEC4:
GL.Uniform4fv(UniformInfo[index].location, count / 4, floats);
break;
case GL_FLOAT_MAT2:
GL.UniformMatrix2fv(UniformInfo[index].location, count / 4, false, floats);
break;
case GL_FLOAT_MAT3:
GL.UniformMatrix3fv(UniformInfo[index].location, count / 9, false, floats);
break;
case GL_FLOAT_MAT4:
GL.UniformMatrix4fv(UniformInfo[index].location, count / 16, false, floats);
break;
case GL_SAMPLER_2D:
case GL_SAMPLER_CUBE: {
if (floats) {
const GLint id = (GLint)(*floats);
GL.Uniform1iv(UniformInfo[index].location, 1, &id);
} else
status = false;
break;
} break;
default:
status = false;
break;
}
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;
bool status = true;
switch (UniformInfo[index].type)
{
case GL_INT:
case GL_BOOL:
GL.Uniform1iv(UniformInfo[index].location, count, ints);
break;
case GL_INT_VEC2:
case GL_BOOL_VEC2:
GL.Uniform2iv(UniformInfo[index].location, count/2, ints);
break;
case GL_INT_VEC3:
case GL_BOOL_VEC3:
GL.Uniform3iv(UniformInfo[index].location, count/3, ints);
break;
case GL_INT_VEC4:
case GL_BOOL_VEC4:
GL.Uniform4iv(UniformInfo[index].location, count/4, ints);
break;
case GL_SAMPLER_2D:
case GL_SAMPLER_CUBE:
GL.Uniform1iv(UniformInfo[index].location, 1, ints);
break;
default:
status = false;
break;
switch (UniformInfo[index].type) {
case GL_INT:
case GL_BOOL:
GL.Uniform1iv(UniformInfo[index].location, count, ints);
break;
case GL_INT_VEC2:
case GL_BOOL_VEC2:
GL.Uniform2iv(UniformInfo[index].location, count / 2, ints);
break;
case GL_INT_VEC3:
case GL_BOOL_VEC3:
GL.Uniform3iv(UniformInfo[index].location, count / 3, ints);
break;
case GL_INT_VEC4:
case GL_BOOL_VEC4:
GL.Uniform4iv(UniformInfo[index].location, count / 4, ints);
break;
case GL_SAMPLER_2D:
case GL_SAMPLER_CUBE:
GL.Uniform1iv(UniformInfo[index].location, 1, ints);
break;
default:
status = false;
break;
}
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);
return false;
}
IVideoDriver* COpenGL3MaterialRenderer::getVideoDriver()
IVideoDriver *COpenGL3MaterialRenderer::getVideoDriver()
{
return Driver;
}

View File

@ -23,24 +23,23 @@ class COpenGL3DriverBase;
class COpenGL3MaterialRenderer : public IMaterialRenderer, public IMaterialRendererServices
{
public:
COpenGL3MaterialRenderer(
COpenGL3DriverBase* driver,
s32& outMaterialTypeNr,
const c8* vertexShaderProgram = 0,
const c8* pixelShaderProgram = 0,
IShaderConstantSetCallBack* callback = 0,
E_MATERIAL_TYPE baseMaterial = EMT_SOLID,
s32 userData = 0);
COpenGL3DriverBase *driver,
s32 &outMaterialTypeNr,
const c8 *vertexShaderProgram = 0,
const c8 *pixelShaderProgram = 0,
IShaderConstantSetCallBack *callback = 0,
E_MATERIAL_TYPE baseMaterial = EMT_SOLID,
s32 userData = 0);
virtual ~COpenGL3MaterialRenderer();
GLuint getProgram() const;
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services);
virtual void OnSetMaterial(const SMaterial &material, const SMaterial &lastMaterial,
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();
@ -48,33 +47,32 @@ public:
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 getPixelShaderConstantID(const c8* name) override;
bool setVertexShaderConstant(s32 index, const f32* floats, int count) override;
bool setVertexShaderConstant(s32 index, const s32* ints, int count) override;
bool setVertexShaderConstant(s32 index, const u32* ints, int count) override;
bool setPixelShaderConstant(s32 index, const f32* floats, int count) override;
bool setPixelShaderConstant(s32 index, const s32* ints, int count) override;
bool setPixelShaderConstant(s32 index, const u32* ints, int count) override;
s32 getVertexShaderConstantID(const c8 *name) override;
s32 getPixelShaderConstantID(const c8 *name) override;
bool setVertexShaderConstant(s32 index, const f32 *floats, int count) override;
bool setVertexShaderConstant(s32 index, const s32 *ints, int count) override;
bool setVertexShaderConstant(s32 index, const u32 *ints, int count) override;
bool setPixelShaderConstant(s32 index, const f32 *floats, int count) override;
bool setPixelShaderConstant(s32 index, const s32 *ints, int count) override;
bool setPixelShaderConstant(s32 index, const u32 *ints, int count) override;
IVideoDriver* getVideoDriver() override;
IVideoDriver *getVideoDriver() override;
protected:
COpenGL3MaterialRenderer(COpenGL3DriverBase *driver,
IShaderConstantSetCallBack *callback = 0,
E_MATERIAL_TYPE baseMaterial = EMT_SOLID,
s32 userData = 0);
COpenGL3MaterialRenderer(COpenGL3DriverBase* driver,
IShaderConstantSetCallBack* callback = 0,
E_MATERIAL_TYPE baseMaterial = EMT_SOLID,
s32 userData = 0);
void init(s32 &outMaterialTypeNr, const c8 *vertexShaderProgram, const c8 *pixelShaderProgram, bool addMaterial = true);
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();
COpenGL3DriverBase* Driver;
IShaderConstantSetCallBack* CallBack;
COpenGL3DriverBase *Driver;
IShaderConstantSetCallBack *CallBack;
bool Alpha;
bool Blending;
@ -91,6 +89,5 @@ protected:
s32 UserData;
};
}
}

View File

@ -18,9 +18,9 @@ namespace irr
namespace video
{
COpenGL3Renderer2D::COpenGL3Renderer2D(const c8* vertexShaderProgram, const c8* pixelShaderProgram, COpenGL3DriverBase* driver, bool withTexture) :
COpenGL3MaterialRenderer(driver, 0, EMT_SOLID),
WithTexture(withTexture)
COpenGL3Renderer2D::COpenGL3Renderer2D(const c8 *vertexShaderProgram, const c8 *pixelShaderProgram, COpenGL3DriverBase *driver, bool withTexture) :
COpenGL3MaterialRenderer(driver, 0, EMT_SOLID),
WithTexture(withTexture)
{
#ifdef _DEBUG
setDebugName("Renderer2D");
@ -30,15 +30,14 @@ COpenGL3Renderer2D::COpenGL3Renderer2D(const c8* vertexShaderProgram, const c8*
init(Temp, vertexShaderProgram, pixelShaderProgram, false);
COpenGL3CacheHandler* cacheHandler = Driver->getCacheHandler();
COpenGL3CacheHandler *cacheHandler = Driver->getCacheHandler();
cacheHandler->setProgram(Program);
// These states don't change later.
ThicknessID = getPixelShaderConstantID("uThickness");
if ( WithTexture )
{
if (WithTexture) {
TextureUsageID = getPixelShaderConstantID("uTextureUsage");
s32 TextureUnitID = getPixelShaderConstantID("uTextureUnit");
@ -56,10 +55,10 @@ COpenGL3Renderer2D::~COpenGL3Renderer2D()
{
}
void COpenGL3Renderer2D::OnSetMaterial(const video::SMaterial& material,
const video::SMaterial& lastMaterial,
bool resetAllRenderstates,
video::IMaterialRendererServices* services)
void COpenGL3Renderer2D::OnSetMaterial(const video::SMaterial &material,
const video::SMaterial &lastMaterial,
bool resetAllRenderstates,
video::IMaterialRendererServices *services)
{
Driver->getCacheHandler()->setProgram(Program);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
@ -67,14 +66,13 @@ void COpenGL3Renderer2D::OnSetMaterial(const video::SMaterial& material,
f32 Thickness = (material.Thickness > 0.f) ? material.Thickness : 1.f;
setPixelShaderConstant(ThicknessID, &Thickness, 1);
if ( WithTexture )
{
if (WithTexture) {
s32 TextureUsage = material.TextureLayers[0].Texture ? 1 : 0;
setPixelShaderConstant(TextureUsageID, &TextureUsage, 1);
}
}
bool COpenGL3Renderer2D::OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype)
bool COpenGL3Renderer2D::OnRender(IMaterialRendererServices *service, E_VERTEX_TYPE vtxtype)
{
return true;
}

View File

@ -14,13 +14,13 @@ namespace video
class COpenGL3Renderer2D : public COpenGL3MaterialRenderer
{
public:
COpenGL3Renderer2D(const c8* vertexShaderProgram, const c8* pixelShaderProgram, COpenGL3DriverBase* driver, bool withTexture);
COpenGL3Renderer2D(const c8 *vertexShaderProgram, const c8 *pixelShaderProgram, COpenGL3DriverBase *driver, bool withTexture);
~COpenGL3Renderer2D();
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services);
virtual void OnSetMaterial(const SMaterial &material, const SMaterial &lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices *services);
virtual bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype);
virtual bool OnRender(IMaterialRendererServices *service, E_VERTEX_TYPE vtxtype);
protected:
bool WithTexture;
@ -28,6 +28,5 @@ protected:
s32 TextureUsageID;
};
}
}