1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #ifndef __C_OPENGL_SHADER_MATERIAL_RENDERER_H_INCLUDED__
\r
6 #define __C_OPENGL_SHADER_MATERIAL_RENDERER_H_INCLUDED__
\r
9 #ifdef _IRR_COMPILE_WITH_OPENGL_
\r
11 #include "IMaterialRenderer.h"
\r
13 #include "COpenGLCommon.h"
\r
20 class COpenGLDriver;
\r
21 class IShaderConstantSetCallBack;
\r
23 //! Class for using vertex and pixel shaders with OpenGL (asm not glsl!)
\r
24 class COpenGLShaderMaterialRenderer : public IMaterialRenderer
\r
29 COpenGLShaderMaterialRenderer(COpenGLDriver* driver,
\r
30 s32& outMaterialTypeNr, const c8* vertexShaderProgram, const c8* pixelShaderProgram,
\r
31 IShaderConstantSetCallBack* callback, E_MATERIAL_TYPE baseMaterial, s32 userData);
\r
34 virtual ~COpenGLShaderMaterialRenderer();
\r
36 virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
\r
37 bool resetAllRenderstates, IMaterialRendererServices* services) override;
\r
39 bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype) override;
\r
41 void OnUnsetMaterial() override;
\r
43 //! Returns if the material is transparent.
\r
44 bool isTransparent() const override;
\r
46 //! Access the callback provided by the users when creating shader materials
\r
47 IShaderConstantSetCallBack* getShaderConstantSetCallBack() const override
\r
54 //! constructor only for use by derived classes who want to
\r
55 //! create a fall back material for example.
\r
56 COpenGLShaderMaterialRenderer(COpenGLDriver* driver,
\r
57 IShaderConstantSetCallBack* callback,
\r
58 E_MATERIAL_TYPE baseMaterial, s32 userData=0);
\r
60 // must not be called more than once!
\r
61 void init(s32& outMaterialTypeNr, const c8* vertexShaderProgram,
\r
62 const c8* pixelShaderProgram, E_VERTEX_TYPE type);
\r
64 bool createPixelShader(const c8* pxsh);
\r
65 bool createVertexShader(const c8* vtxsh);
\r
66 bool checkError(const irr::c8* type);
\r
68 COpenGLDriver* Driver;
\r
69 IShaderConstantSetCallBack* CallBack;
\r
71 // I didn't write this, but here's my understanding:
\r
72 // Those flags seem to be exclusive so far (so could be an enum).
\r
73 // Maybe the idea was to make them non-exclusive in future (basically having a shader-material)
\r
74 // Actually currently there's not even any need to cache them (probably even slower than not doing so).
\r
75 // They seem to be mostly for downward compatibility.
\r
76 // I suppose the idea is to use SMaterial.BlendOperation + SMaterial.BlendFactor and a simple non-transparent type as base for more flexibility in the future.
\r
77 // Note that SMaterial.BlendOperation + SMaterial.BlendFactor are in some drivers already evaluated before OnSetMaterial.
\r
83 GLuint VertexShader;
\r
84 // We have 4 values here, [0] is the non-fog version, the other three are
\r
85 // ARB_fog_linear, ARB_fog_exp, and ARB_fog_exp2 in that order
\r
86 core::array<GLuint> PixelShader;
\r
91 } // end namespace video
\r
92 } // end namespace irr
\r