SuperTuxKart
Loading...
Searching...
No Matches
glwrap.hpp
1// SuperTuxKart - a fun racing game with go-kart
2// Copyright (C) 2014-2015 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 SERVER_ONLY
19
20#ifndef GLWRAP_HEADER_H
21#define GLWRAP_HEADER_H
22
23#include "graphics/gl_headers.hpp"
24
25#include "utils/log.hpp"
26#include "utils/leak_check.hpp"
27#include "utils/no_copy.hpp"
28
29#include <array>
30#include <vector>
31
32#include <S3DVertex.h>
33#include <SColor.h>
34#include <vector3d.h>
35using namespace irr;
36
37namespace HardwareStats
38{
39 class Json;
40}
41
42void initGL();
43
44class GPUTimer;
45
47{
48protected:
49 GPUTimer &timer;
50public:
53};
54
56{
57 friend class ScopedGPUTimer;
58 GLuint query;
59 bool initialised;
60 unsigned lastResult;
61 bool canSubmitQuery;
62 const char* m_name;
63public:
64 GPUTimer(const char* name);
65 unsigned elapsedTimeus();
66 const char* getName() const { return m_name; }
67 void reset()
68 {
69 initialised = false;
70 lastResult = 0;
71 canSubmitQuery = true;
72 }
73};
74
76{
77public:
78 static void bindVertexArrayAttrib(enum video::E_VERTEX_TYPE tp)
79 {
80 switch (tp)
81 {
82 case video::EVT_STANDARD:
83 // Position
84 glEnableVertexAttribArray(0);
85 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), 0);
86 // Normal
87 glEnableVertexAttribArray(1);
88 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), (GLvoid*)12);
89 // Color
90 glEnableVertexAttribArray(2);
91 glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, getVertexPitchFromType(tp), (GLvoid*)24);
92 // Texcoord
93 glEnableVertexAttribArray(3);
94 glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), (GLvoid*)28);
95 break;
96 case video::EVT_2TCOORDS:
97 // Position
98 glEnableVertexAttribArray(0);
99 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), 0);
100 // Normal
101 glEnableVertexAttribArray(1);
102 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), (GLvoid*)12);
103 // Color
104 glEnableVertexAttribArray(2);
105 glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, getVertexPitchFromType(tp), (GLvoid*)24);
106 // Texcoord
107 glEnableVertexAttribArray(3);
108 glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), (GLvoid*)28);
109 // SecondTexcoord
110 glEnableVertexAttribArray(4);
111 glVertexAttribPointer(4, 2, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), (GLvoid*)36);
112 break;
113 case video::EVT_TANGENTS:
114 // Position
115 glEnableVertexAttribArray(0);
116 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), 0);
117 // Normal
118 glEnableVertexAttribArray(1);
119 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), (GLvoid*)12);
120 // Color
121 glEnableVertexAttribArray(2);
122 glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, getVertexPitchFromType(tp), (GLvoid*)24);
123 // Texcoord
124 glEnableVertexAttribArray(3);
125 glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), (GLvoid*)28);
126 // Tangent
127 glEnableVertexAttribArray(5);
128 glVertexAttribPointer(5, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), (GLvoid*)36);
129 // Bitangent
130 glEnableVertexAttribArray(6);
131 glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), (GLvoid*)48);
132 break;
133 case video::EVT_SKINNED_MESH:
134 glEnableVertexAttribArray(0);
135 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), 0);
136 glEnableVertexAttribArray(1);
137 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), (GLvoid*)12);
138 glEnableVertexAttribArray(2);
139 glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, getVertexPitchFromType(tp), (GLvoid*)24);
140 glEnableVertexAttribArray(3);
141 glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), (GLvoid*)28);
142 glEnableVertexAttribArray(4);
143 glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), (GLvoid*)36);
144 glEnableVertexAttribArray(11);
145 glVertexAttribPointer(11, 4, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), (GLvoid*)48);
146 glEnableVertexAttribArray(5);
147 glVertexAttribIPointer(5, 4, GL_SHORT, getVertexPitchFromType(tp), (GLvoid*)64);
148 glEnableVertexAttribArray(6);
149 glVertexAttribPointer(6, 4, GL_HALF_FLOAT, GL_FALSE, getVertexPitchFromType(tp), (GLvoid*)72);
150 break;
151 }
152 }
153};
154
155void draw3DLine(const core::vector3df& start,
156 const core::vector3df& end, irr::video::SColor color);
157
158const std::string getGLExtensions();
159void getGLLimits(HardwareStats::Json *json);
160bool checkGLError();
161
162#endif
163
164#endif // supertuxkart
165
Definition: glwrap.hpp:56
A class to manage json data.
Definition: hardware_stats.hpp:33
Definition: glwrap.hpp:47
Definition: glwrap.hpp:76