]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/COpenGLSLMaterialRenderer.h
Reduce IrrCompileConfig usage to files that actually need it
[irrlicht.git] / source / Irrlicht / COpenGLSLMaterialRenderer.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_LANGUAGE_MATERIAL_RENDERER_H_INCLUDED__\r
6 #define __C_OPENGL_SHADER_LANGUAGE_MATERIAL_RENDERER_H_INCLUDED__\r
7 \r
8 \r
9 #ifdef _IRR_COMPILE_WITH_OPENGL_\r
10 \r
11 #include "EMaterialTypes.h"\r
12 #include "IMaterialRenderer.h"\r
13 #include "IMaterialRendererServices.h"\r
14 #include "IGPUProgrammingServices.h"\r
15 #include "irrArray.h"\r
16 #include "irrString.h"\r
17 \r
18 #include "COpenGLCommon.h"\r
19 \r
20 namespace irr\r
21 {\r
22 namespace video\r
23 {\r
24 \r
25 class COpenGLDriver;\r
26 class IShaderConstantSetCallBack;\r
27 \r
28 //! Class for using GLSL shaders with OpenGL\r
29 //! Please note: This renderer implements its own IMaterialRendererServices\r
30 class COpenGLSLMaterialRenderer : public IMaterialRenderer, public IMaterialRendererServices\r
31 {\r
32 public:\r
33 \r
34         //! Constructor\r
35         COpenGLSLMaterialRenderer(\r
36                 COpenGLDriver* driver,\r
37                 s32& outMaterialTypeNr,\r
38                 const c8* vertexShaderProgram = 0,\r
39                 const c8* vertexShaderEntryPointName = 0,\r
40                 E_VERTEX_SHADER_TYPE vsCompileTarget = video::EVST_VS_1_1,\r
41                 const c8* pixelShaderProgram = 0,\r
42                 const c8* pixelShaderEntryPointName = 0,\r
43                 E_PIXEL_SHADER_TYPE psCompileTarget = video::EPST_PS_1_1,\r
44                 const c8* geometryShaderProgram = 0,\r
45                 const c8* geometryShaderEntryPointName = "main",\r
46                 E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0,\r
47                 scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES,\r
48                 scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP,\r
49                 u32 verticesOut = 0,\r
50                 IShaderConstantSetCallBack* callback = 0,\r
51                 E_MATERIAL_TYPE baseMaterial = EMT_SOLID,\r
52                 s32 userData = 0);\r
53 \r
54         //! Destructor\r
55         virtual ~COpenGLSLMaterialRenderer();\r
56 \r
57         virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,\r
58                 bool resetAllRenderstates, IMaterialRendererServices* services) override;\r
59 \r
60         bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype) override;\r
61 \r
62         void OnUnsetMaterial() override;\r
63 \r
64         //! Returns if the material is transparent.\r
65         bool isTransparent() const override;\r
66 \r
67         //! Access the callback provided by the users when creating shader materials\r
68         IShaderConstantSetCallBack* getShaderConstantSetCallBack() const override\r
69         { \r
70                 return CallBack;\r
71         }\r
72 \r
73         // implementations for the render services\r
74         void setBasicRenderStates(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates) override;\r
75         s32 getVertexShaderConstantID(const c8* name) override;\r
76         s32 getPixelShaderConstantID(const c8* name) override;\r
77         void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1) override;\r
78         void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1) override;\r
79         bool setVertexShaderConstant(s32 index, const f32* floats, int count) override;\r
80         bool setVertexShaderConstant(s32 index, const s32* ints, int count) override;\r
81         bool setVertexShaderConstant(s32 index, const u32* ints, int count) override;\r
82         bool setPixelShaderConstant(s32 index, const f32* floats, int count) override;\r
83         bool setPixelShaderConstant(s32 index, const s32* ints, int count) override;\r
84         bool setPixelShaderConstant(s32 index, const u32* ints, int count) override;\r
85         IVideoDriver* getVideoDriver() override;\r
86 \r
87 protected:\r
88 \r
89         //! constructor only for use by derived classes who want to\r
90         //! create a fall back material for example.\r
91         COpenGLSLMaterialRenderer(COpenGLDriver* driver,\r
92                                         IShaderConstantSetCallBack* callback,\r
93                                         E_MATERIAL_TYPE baseMaterial,\r
94                                         s32 userData=0);\r
95 \r
96         void init(s32& outMaterialTypeNr,\r
97                 const c8* vertexShaderProgram,\r
98                 const c8* pixelShaderProgram,\r
99                 const c8* geometryShaderProgram,\r
100                 scene::E_PRIMITIVE_TYPE inType=scene::EPT_TRIANGLES,\r
101                 scene::E_PRIMITIVE_TYPE outType=scene::EPT_TRIANGLE_STRIP,\r
102                 u32 verticesOut=0);\r
103 \r
104         bool createProgram();\r
105         bool createShader(GLenum shaderType, const char* shader);\r
106         bool linkProgram();\r
107 \r
108         COpenGLDriver* Driver;\r
109         IShaderConstantSetCallBack* CallBack;\r
110 \r
111         bool Alpha;\r
112         bool Blending;\r
113         bool FixedBlending;\r
114         bool AlphaTest;\r
115 \r
116         struct SUniformInfo\r
117         {\r
118                 core::stringc name;\r
119                 GLenum type;\r
120                 GLint location;\r
121         };\r
122 \r
123         GLhandleARB Program;\r
124         GLuint Program2;\r
125         core::array<SUniformInfo> UniformInfo;\r
126         s32 UserData;\r
127 };\r
128 \r
129 \r
130 } // end namespace video\r
131 } // end namespace irr\r
132 \r
133 #endif // compile with OpenGL\r
134 #endif // if included\r
135 \r