-
Notifications
You must be signed in to change notification settings - Fork 2
/
common.h
264 lines (224 loc) · 5.99 KB
/
common.h
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#ifndef COMMON_H
#define COMMON_H
// #define DEBUG
#define FALSE (0)
#define TRUE (1)
#define ABS(x) ((x)<0?(-x):(x))
#define sign(x) ((x)<0?-1.:1.)
#ifdef WIN32
# define WIN32_LEAN_AND_MEAN
# define VC_EXTRALEAN
# include <windows.h>
# include <Windowsx.h>
# include <commctrl.h>
# include <mmsystem.h>
# include <Mmreg.h>
#endif
#include <GL/gl.h>
#include <glext.h>
// OpenGL extensions
PFNGLGETPROGRAMIVPROC glGetProgramiv;
PFNGLGETSHADERIVPROC glGetShaderiv;
PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog;
PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog;
PFNGLCREATESHADERPROC glCreateShader;
PFNGLCREATEPROGRAMPROC glCreateProgram;
PFNGLSHADERSOURCEPROC glShaderSource;
PFNGLCOMPILESHADERPROC glCompileShader;
PFNGLATTACHSHADERPROC glAttachShader;
PFNGLLINKPROGRAMPROC glLinkProgram;
PFNGLUSEPROGRAMPROC glUseProgram;
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation;
PFNGLUNIFORM2FPROC glUniform2f;
PFNGLUNIFORM1FPROC glUniform1f;
PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers;
PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer;
PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D;
PFNGLNAMEDRENDERBUFFERSTORAGEEXTPROC glNamedRenderbufferStorageEXT;
PFNGLUNIFORM1IPROC glUniform1i;
#ifdef WIN32
PFNGLACTIVETEXTUREPROC glActiveTexture;
#endif
// Standard library and CRT rewrite for saving executable size
void *memset(void *ptr, int value, size_t num)
{
for(int i=num-1; i>=0; i--)
((unsigned char *)ptr)[i] = value;
return ptr;
}
size_t strlen(const char *str)
{
int len = 0;
while(str[len] != '\0') ++len;
return len;
}
#ifdef DEBUG
#include <stdio.h>
#include <stdlib.h>
// TODO: remove below
void debug(int shader_handle)
{
printf(" Debugging shader with handle %d.\n", shader_handle);
int compile_status = 0;
glGetShaderiv(shader_handle, GL_COMPILE_STATUS, &compile_status);
if(compile_status != GL_TRUE)
{
printf(" FAILED.\n");
GLint len;
glGetShaderiv(shader_handle, GL_INFO_LOG_LENGTH, &len);
printf(" Log length: %d\n", len);
GLchar *CompileLog = (GLchar*)malloc(len*sizeof(GLchar));
glGetShaderInfoLog(shader_handle, len, NULL, CompileLog);
printf(" Error messages:\n%s\n", CompileLog);
free(CompileLog);
}
else
printf(" Shader compilation successful.\n");
}
void debugp(int program)
{
printf(" Debugging program with handle %d.\n", program);
int compile_status = 0;
glGetProgramiv(program, GL_LINK_STATUS, &compile_status);
if(compile_status != GL_TRUE)
{
printf(" FAILED.\n");
GLint len;
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &len);
printf(" Log length: %d\n", len);
GLchar *CompileLog = (GLchar*)malloc(len*sizeof(GLchar));
glGetProgramInfoLog(program, len, NULL, CompileLog);
printf(" Error messages:\n%s\n", CompileLog);
free(CompileLog);
}
else
printf(" Program linking successful.\n");
}
#else // DEBUG
#define printf(a)
#endif //DEBUG
int w = 1920, h = 1080;
int
// SFX
sfx_program,
sfx_handle,
sfx_blockoffset_location,
sfx_samplerate_location,
sfx_volumelocation,
sfx_texs_location,
sfx_sequence_texture_location,
sfx_sequence_width_location,
// Sequence
sequence_texture_handle,
// Loading bar
load_handle,
load_program,
load_resolution_location,
load_time_location,
load_progress_location,
// Post processing
post_handle,
post_program,
post_resolution_location,
post_fsaa_location,
post_channel0_location,
post_time_location,
// Ui shader
ui_handle,
ui_program,
ui_time_location,
ui_maxtime_location,
ui_mouse_location,
ui_playing_location,
ui_resolution_location,
ui_channel0_location,
// Antialiasing
fsaa = 25,
txaa = 1,
// Logo
logo210_time_location,
logo210_resolution_location,
logo210_program,
logo210_handle,
// Text
text_time_location,
text_resolution_location,
text_font_width_location,
text_channel0_location,
text_font_location,
font_texture_handle,
text_program,
text_handle;
double mx, my;
// Demo globals
#define duration 157.
double t_start = 0.,
t_now = 0.,
t_end = duration;
unsigned int loading = 1, music_loading = 0;
int music_block = 0;
unsigned int snd_framebuffer;
unsigned int scene_override = 0, override_index = 0;
// Music shader globals
int sample_rate = 44100, channels = 2;
double duration1 = duration; //3 min running time
float *smusic1;
int music1_size;
float texs = 512;
int block_size = 512 * 512,
nblocks1;
unsigned int paused = 0;
float progress = .0;
double t_paused;
GLuint first_pass_framebuffer = 0, first_pass_texture;
GLenum error;
#define NSHADERS 4.
float t_load_end = 0.;
void load_demo();
unsigned long __stdcall LoadMusicThread(void *lpParam);
unsigned long __stdcall LoadLogo210Thread(void * lpParam);
unsigned long __stdcall LoadTextThread(void * lpParam);
void quad();
void updateBar();
void draw();
#include "sequence.h"
#include "sfx.h"
#define SFX_VAR_IVOLUME "iVolume"
#define SFX_VAR_ISAMPLERATE "iSampleRate"
#define SFX_VAR_IBLOCKOFFSET "iBlockOffset"
#define SFX_VAR_ITEXSIZE "iTexSize"
#define SFX_VAR_ISEQUENCE "iSequence"
#define SFX_VAR_ISEQUENCEWIDTH "iSequenceWidth"
#include "font/font.h"
#include "gfx/load.h"
#define LOAD_VAR_ITIME "iTime"
#define LOAD_VAR_IPROGRESS "iProgress"
#define LOAD_VAR_IRESOLUTION "iResolution"
#include "gfx/logo210.h"
#define LOGO210_VAR_IRESOLUTION "iResolution"
#define LOGO210_VAR_ITIME "iTime"
#include "gfx/post.h"
#define POST_VAR_IFSAA "iFSAA"
#define POST_VAR_IRESOLUTION "iResolution"
#define POST_VAR_ICHANNEL0 "iChannel0"
#define POST_VAR_ITIME "iTime"
#include "gfx/ui.h"
#define UI_VAR_ITIME "iTime"
#define UI_VAR_IMAXTIME "iMaxTime"
#define UI_VAR_IMOUSE "iMouse"
#define UI_VAR_IPLAYING "iPlaying"
#define UI_VAR_IRESOLUTION "iResolution"
#define UI_VAR_ICHANNEL0 "iChannel0"
#include "gfx/symbols.h"
#include "gfx/text.h"
#define TEXT_VAR_IRESOLUTION "iResolution"
#define TEXT_VAR_ITIME "iTime"
#define TEXT_VAR_IFONT "iFont"
#define TEXT_VAR_IFONTWIDTH "iFontWidth"
#define TEXT_VAR_ICHANNEL0 "iChannel0"
#ifdef WIN32
# include "pal_win32.h"
#else
# include "pal_linux.h"
#endif
#endif