SuperTuxKart
Loading...
Searching...
No Matches
sp_base.hpp
1// SuperTuxKart - a fun racing game with go-kart
2// Copyright (C) 2018 SuperTuxKart-Team
3//
4// This program is free software; you can redistribute it and/or
5// modify it under the terms of the GNU General Public License
6// as published by the Free Software Foundation; either version 3
7// of the License, or (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18#ifndef HEADER_SP_BASE_HPP
19#define HEADER_SP_BASE_HPP
20
21#include "graphics/gl_headers.hpp"
22#include "utils/constants.hpp"
23#include "utils/no_copy.hpp"
24
25#include "irrMath.h"
26#include "vector3d.h"
27
28#include <array>
29#include <atomic>
30#include <cmath>
31#include <functional>
32#include <ostream>
33#include <memory>
34#include <string>
35#include <vector>
36
37namespace irr
38{
39 namespace scene { class ICameraSceneNode; class IMesh; }
40 namespace video { class SColor; }
41}
42
44
45namespace SP
46{
47class SPMesh;
48
49enum DrawCallType: unsigned int
50{
51 DCT_NORMAL = 0,
52 DCT_SHADOW1,
53 DCT_SHADOW2,
54 DCT_SHADOW3,
55 DCT_SHADOW4,
56 DCT_TRANSPARENT,
57 DCT_FOR_VAO
58};
59
60inline std::ostream& operator<<(std::ostream& os, const DrawCallType& dct)
61{
62 switch (dct)
63 {
64 case DCT_NORMAL:
65 return os << "normal";
66 case DCT_TRANSPARENT:
67 return os << "transparent";
68 case DCT_SHADOW1:
69 return os << "shadow cam 1";
70 case DCT_SHADOW2:
71 return os << "shadow cam 2";
72 case DCT_SHADOW3:
73 return os << "shadow cam 3";
74 case DCT_SHADOW4:
75 return os << "shadow cam 4";
76 default:
77 return os;
78 }
79}
80
81enum SamplerType: unsigned int;
82enum RenderPass: unsigned int;
83class SPDynamicDrawCall;
84class SPMaterial;
85class SPMeshNode;
86class SPShader;
87class SPMeshBuffer;
88
89extern GLuint sp_mat_ubo[MAX_PLAYER_COUNT][3];
90extern GLuint sp_fog_ubo;
91extern std::array<GLuint, 1> sp_prefilled_tex;
92extern std::atomic<uint32_t> sp_max_texture_size;
93extern unsigned sp_solid_poly_count;
94extern unsigned sp_shadow_poly_count;
95extern int sp_cur_shadow_cascade;
96extern bool sp_culling;
97extern bool sp_debug_view;
98extern bool sp_apitrace;
99extern unsigned sp_cur_player;
100extern unsigned sp_cur_buf_id[MAX_PLAYER_COUNT];
101extern irr::core::vector3df sp_wind_dir;
102// ----------------------------------------------------------------------------
103void init();
104// ----------------------------------------------------------------------------
105void destroy();
106// ----------------------------------------------------------------------------
107GLuint getSampler(SamplerType);
108// ----------------------------------------------------------------------------
109SPShader* getNormalVisualizer();
110// ----------------------------------------------------------------------------
111SPShader* getGlowShader();
112// ----------------------------------------------------------------------------
113void prepareDrawCalls();
114// ----------------------------------------------------------------------------
115void draw(RenderPass, DrawCallType dct = DCT_NORMAL);
116// ----------------------------------------------------------------------------
117void drawGlow();
118// ----------------------------------------------------------------------------
119void drawSPDebugView();
120// ----------------------------------------------------------------------------
121void addObject(SPMeshNode*);
122// ----------------------------------------------------------------------------
123void initSTKRenderer(ShaderBasedRenderer*);
124// ----------------------------------------------------------------------------
125void prepareScene();
126// ----------------------------------------------------------------------------
127void handleDynamicDrawCall();
128// ----------------------------------------------------------------------------
129void addDynamicDrawCall(std::shared_ptr<SPDynamicDrawCall>);
130// ----------------------------------------------------------------------------
131void updateModelMatrix();
132// ----------------------------------------------------------------------------
133void uploadAll();
134// ----------------------------------------------------------------------------
135void resetEmptyFogColor();
136// ----------------------------------------------------------------------------
137void drawBoundingBoxes();
138// ----------------------------------------------------------------------------
139void loadShaders();
140// ----------------------------------------------------------------------------
141SPMesh* convertEVTStandard(irr::scene::IMesh* mesh,
142 const irr::video::SColor* color = NULL);
143// ----------------------------------------------------------------------------
144void uploadSPM(irr::scene::IMesh* mesh);
145// ----------------------------------------------------------------------------
146#ifdef SERVER_ONLY
147inline void setMaxTextureSize() {}
148#else
149void setMaxTextureSize();
150#endif
151// ----------------------------------------------------------------------------
152inline void unsetMaxTextureSize() { sp_max_texture_size.store(2048); }
153// ----------------------------------------------------------------------------
154inline uint8_t srgbToLinear(float color_srgb)
155{
156 int ret;
157 if (color_srgb <= 0.04045f)
158 {
159 ret = (int)(255.0f * (color_srgb / 12.92f));
160 }
161 else
162 {
163 ret = (int)(255.0f * (powf((color_srgb + 0.055f) / 1.055f, 2.4f)));
164 }
165 return uint8_t(irr::core::clamp(ret, 0, 255));
166}
167// ----------------------------------------------------------------------------
168inline uint8_t srgb255ToLinear(unsigned color_srgb_255)
169{
170 static unsigned srgb_linear_map[256] =
171 {
172 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
173 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
174 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4,
175 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7,
176 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11,
177 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16,
178 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 22, 22,
179 23, 23, 24, 24, 25, 26, 26, 27, 27, 28, 29, 29,
180 30, 31, 31, 32, 33, 33, 34, 35, 36, 36, 37, 38,
181 38, 39, 40, 41, 42, 42, 43, 44, 45, 46, 47, 47,
182 48, 49, 50, 51, 52, 53, 54, 55, 55, 56, 57, 58,
183 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 70, 71,
184 72, 73, 74, 75, 76, 77, 78, 80, 81, 82, 83, 84,
185 85, 87, 88, 89, 90, 92, 93, 94, 95, 97, 98, 99,
186 101, 102, 103, 105, 106, 107, 109, 110, 112, 113, 114, 116,
187 117, 119, 120, 122, 123, 125, 126, 128, 129, 131, 132, 134,
188 135, 137, 139, 140, 142, 144, 145, 147, 148, 150, 152, 153,
189 155, 157, 159, 160, 162, 164, 166, 167, 169, 171, 173, 175,
190 176, 178, 180, 182, 184, 186, 188, 190, 192, 193, 195, 197,
191 199, 201, 203, 205, 207, 209, 211, 213, 215, 218, 220, 222,
192 224, 226, 228, 230, 232, 235, 237, 239, 241, 243, 245, 248,
193 250, 252, 255
194 };
195 return uint8_t(srgb_linear_map[color_srgb_255]);
196}
197
198// ----------------------------------------------------------------------------
199inline uint8_t linearToSrgb(float color_linear)
200{
201 if (color_linear <= 0.0031308f)
202 {
203 color_linear = color_linear * 12.92f;
204 }
205 else
206 {
207 color_linear = 1.055f * powf(color_linear, 1.0f / 2.4f) - 0.055f;
208 }
209 return uint8_t(irr::core::clamp(int(color_linear * 255.0f), 0, 255));
210}
211// ----------------------------------------------------------------------------
212ShaderBasedRenderer* getRenderer();
213}
214
215
216#endif
Definition: shader_based_renderer.hpp:49