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