-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglgetbinary.c
More file actions
101 lines (77 loc) · 1.87 KB
/
Copy pathglgetbinary.c
File metadata and controls
101 lines (77 loc) · 1.87 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
// glgetbinary - Lorenzo Mancini <lmancini80@gmail.com>
#include <stdio.h>
#include <stdint.h>
#include <GL/glew.h>
#include <GL/gl.h>
#include "pez.h"
void init()
{
static const GLchar *vertexShader=\
"void main()"
"{"
"gl_Position = gl_Vertex;"
"}";
static const GLchar *fragmentShader=\
"void main()"
"{"
"gl_FragColor=vec4(1.0, 1.0, 1.0, 1.0);"
"}";
GLuint p = glCreateProgram();
GLuint v = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(v, 1, &vertexShader, 0);
glCompileShader(v);
glAttachShader(p, v);
GLuint f = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(f, 1, &fragmentShader, 0);
glCompileShader(f);
glAttachShader(p, f);
glProgramParameteri(p, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE);
glLinkProgram(p);
glUseProgram(p);
GLint formats = 0;
glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &formats);
printf("%d formats supported\n", formats);
if (formats > 0)
{
int f;
GLint *binary_formats = new GLint[formats];
glGetIntegerv(GL_PROGRAM_BINARY_FORMATS, binary_formats);
for (f = 0; f < formats; ++f)
printf("%d\n", binary_formats[f]);
}
GLint len = 0;
glGetProgramiv(p, GL_PROGRAM_BINARY_LENGTH, &len);
uint8_t* binary = new uint8_t[len];
GLsizei bin_len;
GLenum format;
glGetProgramBinary(p, len, &bin_len, &format, binary);
glUseProgram(0);
printf("Used format 0x%X, wrote %d bytes\n", format, bin_len);
FILE* fp = fopen("shader.bin", "wb");
fwrite(binary, len, 1, fp);
fclose(fp);
delete [] binary;
}
const char* PezInitialize(int width, int height)
{
init();
return "glgetbinary";
}
void PezResize(int width, int height)
{
}
void PezRender()
{
}
void PezUpdate(unsigned int milliseconds)
{
}
void PezHandleMouse(int x, int y, int action)
{
}
void PezHandleKeyPress(char key)
{
}
void PezHandleKeyRelease(char key)
{
}