]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/COpenGLShaderMaterialRenderer.h
80ca43322f9f32d15a98579b923c407380fd48c4
[irrlicht.git] / source / Irrlicht / COpenGLShaderMaterialRenderer.h
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
4 \r
5 #ifndef __C_OPENGL_SHADER_MATERIAL_RENDERER_H_INCLUDED__\r
6 #define __C_OPENGL_SHADER_MATERIAL_RENDERER_H_INCLUDED__\r
7 \r
8 #include "IrrCompileConfig.h"\r
9 \r
10 #ifdef _IRR_COMPILE_WITH_OPENGL_\r
11 \r
12 #include "IMaterialRenderer.h"\r
13 \r
14 #include "COpenGLCommon.h"\r
15 \r
16 namespace irr\r
17 {\r
18 namespace video\r
19 {\r
20 \r
21 class COpenGLDriver;\r
22 class IShaderConstantSetCallBack;\r
23 \r
24 //! Class for using vertex and pixel shaders with OpenGL (asm not glsl!)\r
25 class COpenGLShaderMaterialRenderer : public IMaterialRenderer\r
26 {\r
27 public:\r
28 \r
29         //! Constructor\r
30         COpenGLShaderMaterialRenderer(COpenGLDriver* driver,\r
31                 s32& outMaterialTypeNr, const c8* vertexShaderProgram, const c8* pixelShaderProgram,\r
32                 IShaderConstantSetCallBack* callback, E_MATERIAL_TYPE baseMaterial, s32 userData);\r
33 \r
34         //! Destructor\r
35         virtual ~COpenGLShaderMaterialRenderer();\r
36 \r
37         virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,\r
38                 bool resetAllRenderstates, IMaterialRendererServices* services) override;\r
39 \r
40         bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype) override;\r
41 \r
42         void OnUnsetMaterial() override;\r
43 \r
44         //! Returns if the material is transparent.\r
45         bool isTransparent() const override;\r
46 \r
47         //! Access the callback provided by the users when creating shader materials\r
48         IShaderConstantSetCallBack* getShaderConstantSetCallBack() const override\r
49         { \r
50                 return CallBack;\r
51         }\r
52 \r
53 protected:\r
54 \r
55         //! constructor only for use by derived classes who want to\r
56         //! create a fall back material for example.\r
57         COpenGLShaderMaterialRenderer(COpenGLDriver* driver,\r
58                                         IShaderConstantSetCallBack* callback,\r
59                                         E_MATERIAL_TYPE baseMaterial, s32 userData=0);\r
60 \r
61         // must not be called more than once!\r
62         void init(s32& outMaterialTypeNr, const c8* vertexShaderProgram,\r
63                 const c8* pixelShaderProgram, E_VERTEX_TYPE type);\r
64 \r
65         bool createPixelShader(const c8* pxsh);\r
66         bool createVertexShader(const c8* vtxsh);\r
67         bool checkError(const irr::c8* type);\r
68 \r
69         COpenGLDriver* Driver;\r
70         IShaderConstantSetCallBack* CallBack;\r
71 \r
72         // I didn't write this, but here's my understanding:\r
73         // Those flags seem to be exclusive so far (so could be an enum). \r
74         // Maybe the idea was to make them non-exclusive in future (basically having a shader-material)\r
75         // Actually currently there's not even any need to cache them (probably even slower than not doing so).\r
76         // They seem to be mostly for downward compatibility. \r
77         // 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
78         // Note that SMaterial.BlendOperation + SMaterial.BlendFactor are in some drivers already evaluated before OnSetMaterial.\r
79         bool Alpha;\r
80         bool Blending;\r
81         bool FixedBlending;\r
82         bool AlphaTest;\r
83 \r
84         GLuint VertexShader;\r
85         // We have 4 values here, [0] is the non-fog version, the other three are\r
86         // ARB_fog_linear, ARB_fog_exp, and ARB_fog_exp2 in that order\r
87         core::array<GLuint> PixelShader;\r
88         s32 UserData;\r
89 };\r
90 \r
91 \r
92 } // end namespace video\r
93 } // end namespace irr\r
94 \r
95 #endif\r
96 #endif\r
97 \r