-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.c
751 lines (628 loc) · 16.5 KB
/
main.c
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
#include "util.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <kernel_ex.h>
#include <sysmodule_ex.h>
#include <system_service_ex.h>
#include <shellcore_util.h>
#include <piglet.h>
#define RENDER_WIDTH 1920
#define RENDER_HEIGHT 1080
#define PIGLET_MODULE_NAME "libScePigletv2VSH.sprx"
#define SHCOMP_MODULE_NAME "libSceShaccVSH.sprx"
#if 1
# define MODULE_PATH_PREFIX "/app0/sce_module"
#else
# define MODULE_PATH_PREFIX "/data/self/system/common/lib"
#endif
static SceKernelModule s_piglet_module = -1;
static SceKernelModule s_shcomp_module = -1;
static EGLDisplay s_display = EGL_NO_DISPLAY;
static EGLSurface s_surface = EGL_NO_SURFACE;
static EGLContext s_context = EGL_NO_CONTEXT;
static GLuint s_texture_id = 0;
static GLuint s_program_id = 0;
static GLint s_xyz_loc;
static GLint s_uv_loc;
static GLint s_sampler_loc;
static const GLfloat s_obj_vertices[] = {
-0.5f, 0.5f, 0.0f, /* XYZ #0 */
0.0f, 0.0f, /* UV #0 */
-0.5f, -0.5f, 0.0f, /* XYZ #1 */
0.0f, 1.0f, /* UV #1 */
0.5f, -0.5f, 0.0f, /* XYZ #2 */
1.0f, 1.0f, /* UV #2 */
0.5f, 0.5f, 0.0f, /* XYZ #3 */
1.0f, 0.0f /* UV #3 */
};
static const GLushort s_obj_indices[] = {
0, 1, 2, 0, 2, 3,
};
static const GLubyte s_texture_data[4 * 3] = {
255, 0, 0, /* red */
0, 255, 0, /* green */
0, 0, 255, /* blue */
255, 255, 0, /* yellow */
};
static const GLchar s_vertex_shader_code[] =
"attribute vec4 a_xyz;\n"
"attribute vec2 a_uv;\n"
"varying vec2 v_uv;\n"
"\n"
"void main() {\n"
" gl_Position = a_xyz;\n"
" v_uv = a_uv;\n"
"}\n";
static const GLchar s_fragment_shader_code[] =
"precision mediump float;\n"
"varying vec2 v_uv;\n"
"uniform sampler2D s_texture;\n"
"\n"
"void main() {\n"
" gl_FragColor = texture2D(s_texture, v_uv);\n"
"}\n";
const char* g_sandbox_word = NULL;
static bool load_modules(void) {
int ret;
ret = sceKernelLoadStartModule(MODULE_PATH_PREFIX "/" PIGLET_MODULE_NAME, 0, NULL, 0, NULL, NULL);
if (ret < 0) {
EPRINTF("sceKernelLoadStartModule(%s) failed: 0x%08X\n", PIGLET_MODULE_NAME, ret);
goto err;
}
s_piglet_module = ret;
ret = sceKernelLoadStartModule(MODULE_PATH_PREFIX "/" SHCOMP_MODULE_NAME, 0, NULL, 0, NULL, NULL);
if (ret < 0) {
EPRINTF("sceKernelLoadStartModule(%s) failed: 0x%08X\n", SHCOMP_MODULE_NAME, ret);
goto err;
}
s_shcomp_module = ret;
return true;
err_unload_shcompt:
ret = sceKernelStopUnloadModule(s_shcomp_module, 0, NULL, 0, NULL, NULL);
if (ret < 0) {
EPRINTF("sceKernelStopUnloadModule(%s) failed: 0x%08X\n", SHCOMP_MODULE_NAME, ret);
} else {
s_shcomp_module = -1;
}
err_unload_piglet:
ret = sceKernelStopUnloadModule(s_piglet_module, 0, NULL, 0, NULL, NULL);
if (ret < 0) {
EPRINTF("sceKernelStopUnloadModule(%s) failed: 0x%08X\n", PIGLET_MODULE_NAME, ret);
} else {
s_piglet_module = -1;
}
err:
return false;
}
static void unload_modules(void) {
int ret;
if (s_shcomp_module > 0) {
ret = sceKernelStopUnloadModule(s_shcomp_module, 0, NULL, 0, NULL, NULL);
if (ret < 0) {
EPRINTF("sceKernelStopUnloadModule(%s) failed: 0x%08X\n", SHCOMP_MODULE_NAME, ret);
} else {
s_shcomp_module = -1;
}
}
if (s_piglet_module > 0) {
ret = sceKernelStopUnloadModule(s_piglet_module, 0, NULL, 0, NULL, NULL);
if (ret < 0) {
EPRINTF("sceKernelStopUnloadModule(%s) failed: 0x%08X\n", PIGLET_MODULE_NAME, ret);
} else {
s_piglet_module = -1;
}
}
}
/* XXX: patches below are given for Piglet module from 4.74 Devkit PUP */
static void pgl_patches_cb(void* arg, uint8_t* base, uint64_t size) {
/* Patch runtime compiler check */
const uint8_t p_set_eax_to_1[] = {
0x31, 0xC0, 0xFF, 0xC0, 0x90,
};
memcpy(base + 0x5451F, p_set_eax_to_1, sizeof(p_set_eax_to_1));
/* Tell that runtime compiler exists */
*(uint8_t*)(base + 0xB2DEC) = 0;
*(uint8_t*)(base + 0xB2DED) = 0;
*(uint8_t*)(base + 0xB2DEE) = 1;
*(uint8_t*)(base + 0xB2E21) = 1;
/* Inform Piglet that we have shader compiler module loaded */
*(int32_t*)(base + 0xB2E24) = s_shcomp_module;
}
static bool do_patches(void) {
if (!patch_module(PIGLET_MODULE_NAME, &pgl_patches_cb, NULL)) {
EPRINTF("Unable to patch PGL module.\n");
goto err;
}
return true;
err:
return false;
}
static void cleanup(void) {
int ret;
unload_modules();
ret = sceSysmoduleUnloadModuleInternal(SCE_SYSMODULE_INTERNAL_SYSTEM_SERVICE);
if (ret) {
EPRINTF("sceSysmoduleUnloadModuleInternal(%s) failed: 0x%08X\n", "SCE_SYSMODULE_INTERNAL_SYSTEM_SERVICE", ret);
}
}
static bool create_context(unsigned int width, unsigned int height) {
ScePglConfig pgl_config;
SceWindow render_window = { 0, width, height };
EGLConfig config = NULL;
EGLint num_configs;
EGLint attribs[] = {
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_DEPTH_SIZE, 0,
EGL_STENCIL_SIZE, 0,
EGL_SAMPLE_BUFFERS, 0,
EGL_SAMPLES, 0,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_NONE,
};
EGLint ctx_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE,
};
EGLint window_attribs[] = {
EGL_RENDER_BUFFER, EGL_BACK_BUFFER,
EGL_NONE,
};
int major, minor;
int ret;
memset(&pgl_config, 0, sizeof(pgl_config));
{
pgl_config.size = sizeof(pgl_config);
pgl_config.flags = SCE_PGL_FLAGS_USE_COMPOSITE_EXT | SCE_PGL_FLAGS_USE_FLEXIBLE_MEMORY | 0x60;
pgl_config.processOrder = 1;
pgl_config.systemSharedMemorySize = 0x200000;
pgl_config.videoSharedMemorySize = 0x2400000;
pgl_config.maxMappedFlexibleMemory = 0xAA00000;
pgl_config.drawCommandBufferSize = 0xC0000;
pgl_config.lcueResourceBufferSize = 0x10000;
pgl_config.dbgPosCmd_0x40 = 1920;
pgl_config.dbgPosCmd_0x44 = 1080;
pgl_config.dbgPosCmd_0x48 = 0;
pgl_config.dbgPosCmd_0x4C = 0;
pgl_config.unk_0x5C = 2;
}
if (!scePigletSetConfigurationVSH(&pgl_config)) {
EPRINTF("scePigletSetConfigurationVSH failed.\n");
goto err;
}
s_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (s_display == EGL_NO_DISPLAY) {
EPRINTF("eglGetDisplay failed.\n");
goto err;
}
if (!eglInitialize(s_display, &major, &minor)) {
ret = eglGetError();
EPRINTF("eglInitialize failed: 0x%08X\n", ret);
goto err;
}
printf("EGL version major:%d, minor:%d\n", major, minor);
if (!eglBindAPI(EGL_OPENGL_ES_API)) {
ret = eglGetError();
EPRINTF("eglBindAPI failed: 0x%08X\n", ret);
goto err;
}
if (!eglSwapInterval(s_display, 0)) {
ret = eglGetError();
EPRINTF("eglSwapInterval failed: 0x%08X\n", ret);
goto err;
}
if (!eglChooseConfig(s_display, attribs, &config, 1, &num_configs)) {
ret = eglGetError();
EPRINTF("eglChooseConfig failed: 0x%08X\n", ret);
goto err;
}
if (num_configs != 1) {
EPRINTF("No available configuration found.\n");
goto err;
}
s_surface = eglCreateWindowSurface(s_display, config, &render_window, window_attribs);
if (s_surface == EGL_NO_SURFACE) {
ret = eglGetError();
EPRINTF("eglCreateWindowSurface failed: 0x%08X\n", ret);
goto err;
}
s_context = eglCreateContext(s_display, config, EGL_NO_CONTEXT, ctx_attribs);
if (s_context == EGL_NO_CONTEXT) {
ret = eglGetError();
EPRINTF("eglCreateContext failed: 0x%08X\n", ret);
goto err;
}
if (!eglMakeCurrent(s_display, s_surface, s_surface, s_context)) {
ret = eglGetError();
EPRINTF("eglMakeCurrent failed: 0x%08X\n", ret);
goto err;
}
printf("GL_VERSION: %s\n", glGetString(GL_VERSION));
printf("GL_RENDERER: %s\n", glGetString(GL_RENDERER));
return true;
err:
return false;
}
static void destroy_context(void) {
int ret;
if (!eglDestroyContext(s_display, s_context)) {
ret = eglGetError();
EPRINTF("eglDestroyContext failed: 0x%08X\n", ret);
}
s_context = EGL_NO_CONTEXT;
if (!eglDestroySurface(s_display, s_surface)) {
ret = eglGetError();
EPRINTF("eglDestroySurface failed: 0x%08X\n", ret);
}
s_surface = EGL_NO_SURFACE;
if (!eglTerminate(s_display)) {
ret = eglGetError();
EPRINTF("eglTerminate failed: 0x%08X\n", ret);
}
s_display = EGL_NO_DISPLAY;
}
static bool create_texture(void) {
int ret;
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
ret = glGetError();
if (ret) {
EPRINTF("glPixelStorei failed: 0x%08X\n", ret);
goto err;
}
glGenTextures(1, &s_texture_id);
ret = glGetError();
if (ret) {
EPRINTF("glGenTextures failed: 0x%08X\n", ret);
goto err;
}
glBindTexture(GL_TEXTURE_2D, s_texture_id);
ret = glGetError();
if (ret) {
EPRINTF("glBindTexture failed: 0x%08X\n", ret);
goto err;
}
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, s_texture_data);
ret = glGetError();
if (ret) {
EPRINTF("glTexImage2D failed: 0x%08X\n", ret);
goto err;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
ret = glGetError();
if (ret) {
EPRINTF("glTexParameteri failed: 0x%08X\n", ret);
goto err;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
ret = glGetError();
if (ret) {
EPRINTF("glTexParameteri failed: 0x%08X\n", ret);
goto err;
}
return true;
err:
return false;
}
static bool destroy_texture(void) {
int ret;
glDeleteTextures(1, &s_texture_id);
ret = glGetError();
if (ret) {
EPRINTF("glDeleteTextures failed: 0x%08X\n", ret);
goto err;
}
return true;
err:
return false;
}
static bool compile_shader(GLenum type, const char* source, size_t length, GLuint* pShader) {
GLuint shader;
GLint tmp_length = (int)length;
GLint success;
char log_buf[256];
int ret;
shader = glCreateShader(type);
if (!shader) {
ret = glGetError();
EPRINTF("glCreateShader failed: 0x%08X\n", ret);
goto err;
}
glShaderSource(shader, 1, &source, &tmp_length);
ret = glGetError();
if (ret) {
EPRINTF("glShaderSource failed: 0x%08X\n", ret);
goto err;
}
glCompileShader(shader);
ret = glGetError();
if (ret) {
EPRINTF("glCompileShader failed: 0x%08X\n", ret);
goto err;
}
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
ret = glGetError();
if (ret) {
EPRINTF("glGetShaderiv failed: 0x%08X\n", ret);
goto err;
}
if (!success) {
glGetShaderInfoLog(shader, sizeof(log_buf), NULL, log_buf);
ret = glGetError();
if (ret) {
EPRINTF("glGetShaderInfoLog failed: 0x%08X\n", ret);
goto err;
}
if (strlen(log_buf) > 1) {
EPRINTF("shader compilation failed with log:\n%s\n", log_buf);
} else {
EPRINTF("shader compilation failed\n");
}
goto err;
}
if (pShader) {
*pShader = shader;
}
return true;
err:
return false;
}
static bool create_program(void) {
GLuint vertex_shader_id = 0;
GLuint fragment_shader_id = 0;
GLuint program_id = 0;
GLint success;
char log[256];
int ret;
if (!compile_shader(GL_VERTEX_SHADER, s_vertex_shader_code, strlen(s_vertex_shader_code), &vertex_shader_id)) {
EPRINTF("Unable to compile vertex shader.\n");
goto err;
}
if (!compile_shader(GL_FRAGMENT_SHADER, s_fragment_shader_code, strlen(s_fragment_shader_code), &fragment_shader_id)) {
EPRINTF("Unable to compile fragment shader.\n");
goto err;
}
program_id = glCreateProgram();
if (!program_id) {
ret = glGetError();
EPRINTF("glCreateProgram failed: 0x%08X\n", ret);
goto err;
}
glAttachShader(program_id, vertex_shader_id);
ret = glGetError();
if (ret) {
EPRINTF("glAttachShader(vertex_shader) failed: 0x%08X\n", ret);
goto err;
}
glAttachShader(program_id, fragment_shader_id);
ret = glGetError();
if (ret) {
EPRINTF("glAttachShader(fragment_shader) failed: 0x%08X\n", ret);
goto err;
}
glLinkProgram(program_id);
ret = glGetError();
if (ret) {
EPRINTF("glLinkProgram() failed: 0x%08X\n", ret);
goto err;
}
glGetProgramiv(program_id, GL_LINK_STATUS, &success);
ret = glGetError();
if (ret) {
EPRINTF("glGetProgramiv() failed: 0x%08X\n", ret);
goto err;
}
if (!success) {
glGetProgramInfoLog(program_id, sizeof(log), NULL, log);
ret = glGetError();
if (ret) {
EPRINTF("glGetProgramInfoLog failed: 0x%08X\n", ret);
goto err;
}
if (strlen(log) > 1) {
EPRINTF("Unable to link shader program:\n%s\n", log);
} else {
EPRINTF("Unable to link shader program.\n");
}
goto err;
}
glDeleteShader(fragment_shader_id);
ret = glGetError();
if (ret) {
EPRINTF("glDeleteShader(fragment_shader) failed: 0x%08X\n", ret);
goto err;
}
glDeleteShader(vertex_shader_id);
ret = glGetError();
if (ret) {
EPRINTF("glDeleteShader(vertex_shader) failed: 0x%08X\n", ret);
goto err;
}
s_xyz_loc = glGetAttribLocation(program_id, "a_xyz");
s_uv_loc = glGetAttribLocation(program_id, "a_uv");
s_sampler_loc = glGetUniformLocation(program_id, "s_texture");
s_program_id = program_id;
return true;
err:
if (program_id > 0) {
glDeleteProgram(program_id);
ret = glGetError();
if (ret) {
EPRINTF("glDeleteProgram failed: 0x%08X\n", ret);
goto err;
}
}
if (fragment_shader_id > 0) {
glDeleteShader(fragment_shader_id);
ret = glGetError();
if (ret) {
EPRINTF("glDeleteShader(fragment_shader) failed: 0x%08X\n", ret);
goto err;
}
fragment_shader_id = 0;
}
if (vertex_shader_id > 0) {
glDeleteShader(vertex_shader_id);
ret = glGetError();
if (ret) {
EPRINTF("glDeleteShader(vertex_shader) failed: 0x%08X\n", ret);
goto err;
}
vertex_shader_id = 0;
}
return false;
}
static bool destroy_program(void) {
int ret;
glDeleteProgram(s_program_id);
ret = glGetError();
if (ret) {
EPRINTF("glDeleteProgram failed: 0x%08X\n", ret);
goto err;
}
return true;
err:
return false;
}
static bool main_loop(void) {
int ret;
while (1) {
glClear(GL_COLOR_BUFFER_BIT);
ret = glGetError();
if (ret) {
EPRINTF("glClear failed: 0x%08X\n", ret);
goto err;
}
glUseProgram(s_program_id);
ret = glGetError();
if (ret) {
EPRINTF("glUseProgram failed: 0x%08X\n", ret);
goto err;
}
glVertexAttribPointer(s_xyz_loc, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), s_obj_vertices);
ret = glGetError();
if (ret) {
EPRINTF("glVertexAttribPointer failed: 0x%08X\n", ret);
goto err;
}
glVertexAttribPointer(s_uv_loc, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &s_obj_vertices[3]);
ret = glGetError();
if (ret) {
EPRINTF("glVertexAttribPointer failed: 0x%08X\n", ret);
goto err;
}
glEnableVertexAttribArray(s_xyz_loc);
ret = glGetError();
if (ret) {
EPRINTF("glEnableVertexAttribArray failed: 0x%08X\n", ret);
goto err;
}
glEnableVertexAttribArray(s_uv_loc);
ret = glGetError();
if (ret) {
EPRINTF("glEnableVertexAttribArray failed: 0x%08X\n", ret);
goto err;
}
glActiveTexture(GL_TEXTURE0);
ret = glGetError();
if (ret) {
EPRINTF("glActiveTexture failed: 0x%08X\n", ret);
goto err;
}
glBindTexture(GL_TEXTURE_2D, s_texture_id);
ret = glGetError();
if (ret) {
EPRINTF("glBindTexture failed: 0x%08X\n", ret);
goto err;
}
glUniform1i(s_sampler_loc, 0);
ret = glGetError();
if (ret) {
EPRINTF("glUniform1i failed: 0x%08X\n", ret);
goto err;
}
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, s_obj_indices);
ret = glGetError();
if (ret) {
EPRINTF("glDrawElements failed: 0x%08X\n", ret);
goto err;
}
if (!eglSwapBuffers(s_display, s_surface)) {
ret = eglGetError();
EPRINTF("eglSwapBuffers failed: 0x%08X\n", ret);
goto err;
}
}
return true;
err:
return false;
}
int main(int argc, const char* const argv[]) {
int ret;
atexit(&cleanup);
ret = sceSysmoduleLoadModuleInternal(SCE_SYSMODULE_INTERNAL_SYSTEM_SERVICE);
if (ret) {
EPRINTF("sceSysmoduleLoadModuleInternal(%s) failed: 0x%08X\n", "SCE_SYSMODULE_INTERNAL_SYSTEM_SERVICE", ret);
goto err;
}
g_sandbox_word = sceKernelGetFsSandboxRandomWord();
if (!g_sandbox_word) {
EPRINTF("sceKernelGetFsSandboxRandomWord failed.\n");
goto err;
}
if (!load_modules()) {
EPRINTF("Unable to load modules.\n");
goto err;
}
if (!do_patches()) {
EPRINTF("Unable to patch modules.\n");
goto err;
}
ret = sceSystemServiceHideSplashScreen();
if (ret) {
EPRINTF("sceSystemServiceHideSplashScreen failed: 0x%08X\n", ret);
goto err;
}
if (!create_context(RENDER_WIDTH, RENDER_HEIGHT)) {
EPRINTF("Unable to create context.\n");
goto err;
}
if (!create_texture()) {
EPRINTF("Unable to create texture.\n");
goto err_destroy_context;
}
if (!create_program()) {
EPRINTF("Unable to create shader program.\n");
goto err_destroy_texture;
}
glViewport(0, 0, RENDER_WIDTH, RENDER_HEIGHT);
ret = glGetError();
if (ret) {
EPRINTF("glViewport failed: 0x%08X\n", ret);
goto err_destroy_program;
}
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
ret = glGetError();
if (ret) {
EPRINTF("glClearColor failed: 0x%08X\n", ret);
goto err_destroy_program;
}
if (!main_loop()) {
EPRINTF("Main loop failed.\n");
goto err_destroy_program;
}
err_destroy_program:
destroy_program();
err_destroy_texture:
destroy_texture();
err_destroy_context:
destroy_context();
err:
return 0;
}
void catchReturnFromMain(int exit_code) {
/* dummy */
}