-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstdafx.h
More file actions
195 lines (181 loc) · 3.76 KB
/
Copy pathstdafx.h
File metadata and controls
195 lines (181 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#pragma once
#define NOMINMAX
#define _CRT_SECURE_NO_WARNINGS
#include <Windows.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
#pragma comment(lib,"opengl32.lib")
#pragma comment(lib,"glfw3.lib")
#pragma comment(lib, "glew32s.lib")
#include <iostream>
#include <sstream>
#include <vector>
#include <fstream>
#include <string>
#include <map>
#include <list>
#include <iomanip>
/* Helpers */
// TODO: Refactor into helper class etc
inline void CheckCompiledShader(GLuint shader)
{
GLint status;
glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
if (status == GL_FALSE)
{
char buffer[512];
glGetShaderInfoLog(shader, 512, nullptr, buffer);
printf("Error: Shader %d is not compiled correctly! \n %s", shader, buffer);
#if DEBUG || _DEBUG
abort();
#endif
// Exit our program
}
}
inline const char* glErrorToString(GLenum error)
{
char* str = nullptr;
switch (error)
{
case GL_INVALID_ENUM:
str = "GL_INVALID_ENUM";
break;
case GL_INVALID_VALUE:
str = "GL_INVALID_VALUE";
break;
case GL_INVALID_OPERATION:
str = "GL_INVALID_OPERATION";
break;
case GL_STACK_OVERFLOW:
str = "GL_STACK_OVERFLOW";
break;
case GL_STACK_UNDERFLOW:
str = "GL_STACK_UNDERFLOW";
break;
case GL_OUT_OF_MEMORY:
str = "GL_OUT_OF_MEMORY";
break;
case GL_INVALID_FRAMEBUFFER_OPERATION:
str = "GL_INVALID_FRAMEBUFFER_OPERATION";
break;
case GL_CONTEXT_LOST:
str = "GL_CONTEXT_LOST";
break;
case GL_TABLE_TOO_LARGE:
str = "GL_TABLE_TOO_LARGE";
break;
default:
str = "NON_SPECIFIED";
break;
}
return str;
}
inline void CheckError()
{
bool hadErrors = false;
for (GLenum err; (err = glGetError()) != GL_NO_ERROR;)
{
hadErrors = true;
printf("OpenGL Error %d: %s \n", err, glErrorToString(err));
}
#if DEBUG | _DEBUG
if (hadErrors)
abort();
#endif
}
inline const char* ReadFile(const std::string& file)
{
std::ifstream ifstream(file, std::ios::ate | std::ios::binary);
int size = (int)ifstream.tellg();
ifstream.seekg(0);
if (ifstream.fail())
{
return nullptr;
}
char * data = new char[size + 1];
ifstream.read(data, size);
ifstream.close();
data[size] = '\0';
return data;
}
class Logger
{
public:
static Logger& GetInstance()
{
static Logger l;
return l;
}
static void LogInfo(const std::string& str)
{
GetInstance().write("[INFO] " + str);
}
static void LogWarning(const std::string& str)
{
GetInstance().write("[WARNING] " + str);
}
static void LogOpCode(unsigned short opCode)
{
if(!GetInstance().m_JustLogged)
LogOpCode(opCode, "",false);
}
static void LogOpCode(unsigned short opCode, const std::string& info, bool abortP = true)
{
std::stringstream ss;
ss << "[OPCODE] " << "0x" <<std::hex << opCode << ((!info.empty())?" - ":"") << info;
GetInstance().write(ss.str());
GetInstance().m_JustLogged = true;
#if defined(DEBUG) | defined(_DEBUG)
if(abortP)
{
std::wstringstream ss2;
ss2 << L"Unkown Operator code: " << std::hex << opCode;
MessageBoxW(NULL, ss2.str().c_str(), L"UNKOWN OPCODE", MB_OK);
abort();
}
#endif
}
static void NewFrame()
{
GetInstance().m_JustLogged = false;
}
const std::list<std::string> GetLog()
{
return log;
}
private:
void write(const std::string& str)
{
#if defined(DEBUG)
std::cout << str << std::endl;
#endif
if (outputFile.is_open())
outputFile << str << std::endl;
log.push_back(str);
if (log.size() > 200)
log.pop_front();
}
Logger()
{
outputFile.open("log.txt");
while(outputFile.fail())
{
outputFile.open("log.txt");
}
}
~Logger()
{
outputFile.close();
}
std::ofstream outputFile;
std::list<std::string> log;
bool m_JustLogged = false;
};
template<typename T>
std::string ToHex(T in)
{
std::stringstream ss;
ss << "0x" << std::setfill('0') << std::setw(sizeof(T) * 2) << std::hex << in;
return ss.str();
}