Fix damage flash when damage disabled
[oweals/minetest.git] / src / shader.h
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2013 Kahrl <kahrl@gmx.net>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21 #ifndef SHADER_HEADER
22 #define SHADER_HEADER
23
24 #include "irrlichttypes_extrabloated.h"
25 #include "threads.h"
26 #include <string>
27
28 class IGameDef;
29
30 /*
31         shader.{h,cpp}: Shader handling stuff.
32 */
33
34 /*
35         Gets the path to a shader by first checking if the file
36           name_of_shader/filename
37         exists in shader_path and if not, using the data path.
38
39         If not found, returns "".
40
41         Utilizes a thread-safe cache.
42 */
43 std::string getShaderPath(const std::string &name_of_shader,
44                 const std::string &filename);
45
46 struct ShaderInfo
47 {
48         std::string name;
49         video::E_MATERIAL_TYPE base_material;
50         video::E_MATERIAL_TYPE material;
51         u8 drawtype;
52         u8 material_type;
53         s32 user_data;
54
55         ShaderInfo(): name(""), base_material(video::EMT_SOLID),
56                 material(video::EMT_SOLID),
57                 drawtype(0), material_type(0) {}
58         virtual ~ShaderInfo() {}
59 };
60
61 /*
62         Setter of constants for shaders
63 */
64
65 namespace irr { namespace video {
66         class IMaterialRendererServices;
67 } }
68
69 class IShaderConstantSetter
70 {
71 public:
72         virtual ~IShaderConstantSetter(){};
73         virtual void onSetConstants(video::IMaterialRendererServices *services,
74                         bool is_highlevel) = 0;
75 };
76
77 /*
78         ShaderSource creates and caches shaders.
79 */
80
81 class IShaderSource
82 {
83 public:
84         IShaderSource(){}
85         virtual ~IShaderSource(){}
86         virtual u32 getShaderIdDirect(const std::string &name,
87                 const u8 material_type, const u8 drawtype){return 0;}
88         virtual ShaderInfo getShaderInfo(u32 id){return ShaderInfo();}
89         virtual u32 getShader(const std::string &name,
90                 const u8 material_type, const u8 drawtype){return 0;}
91 };
92
93 class IWritableShaderSource : public IShaderSource
94 {
95 public:
96         IWritableShaderSource(){}
97         virtual ~IWritableShaderSource(){}
98         virtual u32 getShaderIdDirect(const std::string &name,
99                 const u8 material_type, const u8 drawtype){return 0;}
100         virtual ShaderInfo getShaderInfo(u32 id){return ShaderInfo();}
101         virtual u32 getShader(const std::string &name,
102                 const u8 material_type, const u8 drawtype){return 0;}
103
104         virtual void processQueue()=0;
105         virtual void insertSourceShader(const std::string &name_of_shader,
106                 const std::string &filename, const std::string &program)=0;
107         virtual void rebuildShaders()=0;
108         virtual void addGlobalConstantSetter(IShaderConstantSetter *setter)=0;
109 };
110
111 IWritableShaderSource* createShaderSource(IrrlichtDevice *device);
112
113 #endif