19 template <
typename T >
26 gscalar& operator= (
const T& v ) { x= v;
return *
this; }
27 operator T ( ) {
return x; }
36 template <
typename T >
43 gvec2( const ::vec2& v ) : x(v.x), y(v.y) {}
44 gvec2& operator= (
const gvec2<T>& v ) { x= v.x; y= v.y;
return *
this; }
45 gvec2& operator= ( const ::vec2& v ) { x= v.x; y= v.y;
return *
this; }
46 operator ::vec2 ( ) { return ::vec2(
float(x),
float(y)); }
55 template <
typename T >
62 gvec3( const ::vec3& v ) : x(v.x), y(v.y), z(v.z) {}
63 gvec3(
const Point& v ) : x(v.x), y(v.y), z(v.z) {}
64 gvec3(
const Vector& v ) : x(v.x), y(v.y), z(v.z) {}
65 gvec3& operator= (
const gvec3<T>& v ) { x= v.x; y= v.y; z= v.z;
return *
this; }
66 gvec3& operator= ( const ::vec3& v ) { x= v.x; y= v.y; z= v.z;
return *
this; }
67 gvec3& operator= (
const Point& v ) { x= v.x; y= v.y; z= v.z;
return *
this; }
68 gvec3& operator= (
const Vector& v ) { x= v.x; y= v.y; z= v.z;
return *
this; }
69 operator ::vec3 ( ) { return ::vec3(
float(x),
float(y),
float(y)); }
78 template <
typename T >
81 alignas(4) T x, y, z, w;
84 gvec4(
const gvec4<T>& v ) : x(v.x), y(v.y), z(v.z), w(v.w) {}
85 gvec4( const ::vec4& v ) : x(v.x), y(v.y), z(v.z), w(v.w) {}
86 gvec4& operator= (
const gvec4<T>& v ) { x(v.x), y(v.y), z(v.z), w(v.w) ;
return *
this; }
87 gvec4& operator= ( const ::vec4& v ) { x(v.x), y(v.y), z(v.z), w(v.w) ;
return *
this; }
88 gvec4& operator= (
const Color& c ) { x= c.r; y= c.g; z= c.b; w= c.a;
return *
this; }
89 operator ::vec4 ( ) { return ::vec4(
float(x),
float(y),
float(y),
float(w)); }
100 const char *glsl_string(
const GLenum type )
106 case GL_UNSIGNED_INT:
126 int print_storage(
const GLuint program )
130 printf(
"[error] program 0, no storage buffers...\n");
135 GLint buffer_count= 0;
136 glGetProgramInterfaceiv(program, GL_SHADER_STORAGE_BLOCK, GL_ACTIVE_RESOURCES, &buffer_count);
137 if(buffer_count == 0)
140 for(
int i= 0; i < buffer_count; i++)
143 char bname[1024]= { 0 };
144 glGetProgramResourceName(program, GL_SHADER_STORAGE_BLOCK, i,
sizeof(bname), NULL, bname);
149 GLenum prop[]= { GL_BUFFER_BINDING };
150 glGetProgramResourceiv(program, GL_SHADER_STORAGE_BLOCK, i, 1, prop, 1, NULL, &binding);
153 printf(
" buffer '%s' binding %d\n", bname, binding);
156 GLint variable_count= 0;
158 GLenum prop[]= { GL_NUM_ACTIVE_VARIABLES };
159 glGetProgramResourceiv(program, GL_SHADER_STORAGE_BLOCK, i, 1, prop, 1, NULL, &variable_count);
163 std::vector<GLint> variables(variable_count);
165 GLenum prop[]= { GL_ACTIVE_VARIABLES };
166 glGetProgramResourceiv(program, GL_SHADER_STORAGE_BLOCK, i, 1, prop, variable_count, NULL, variables.data());
169 for(
int k= 0; k < variable_count; k++)
172 GLenum props[]= { GL_OFFSET, GL_TYPE, GL_ARRAY_SIZE, GL_ARRAY_STRIDE, GL_MATRIX_STRIDE, GL_IS_ROW_MAJOR, GL_TOP_LEVEL_ARRAY_STRIDE };
173 const int size=
sizeof(props) /
sizeof(GLenum);
175 GLint params[size]= {};
176 glGetProgramResourceiv(program, GL_BUFFER_VARIABLE, variables[k], size, props, size, NULL, params);
179 char vname[1024]= { 0 };
180 glGetProgramResourceName(program, GL_BUFFER_VARIABLE, variables[k],
sizeof(vname), NULL, vname);
182 printf(
" '%s %s': offset %d", glsl_string(params[1]), vname, params[0]);
184 printf(
", array size %d", params[2]);
186 printf(
", stride %d", params[3]);
189 if(params[1] == GL_FLOAT_MAT4 || params[1] == GL_FLOAT_MAT3)
190 printf(
", %s, matrix stride %d", params[5] ?
"row major" :
"column major", params[4]);
192 printf(
", top level stride %d\n", params[6]);
209 print_storage(program);
220 printf(
" a %d\n", (
int) offsetof(TriangleCPU, a));
221 printf(
" a.x %d\n", (
int) offsetof(TriangleCPU, a.x));
222 printf(
" a.y %d\n", (
int) offsetof(TriangleCPU, a.y));
223 printf(
" a.z %d\n", (
int) offsetof(TriangleCPU, a.z));
224 printf(
" b %d\n", (
int) offsetof(TriangleCPU, b));
225 printf(
" c %d\n", (
int) offsetof(TriangleCPU, c));
226 printf(
"= %dB\n", (
int)
sizeof(TriangleCPU));
235 TriangleGLSL(
const Point& _a,
const Point& _b,
const Point& _c ) : a(_a), b(_b), c(_c) {}
236 TriangleGLSL(
const vec3& _a,
const vec3& _b,
const vec3& _c ) : a(_a), b(_b), c(_c) {}
240 printf(
" a %d\n", (
int) offsetof(TriangleGLSL, a));
241 printf(
" a.x %d\n", (
int) offsetof(TriangleGLSL, a.x));
242 printf(
" a.y %d\n", (
int) offsetof(TriangleGLSL, a.y));
243 printf(
" a.z %d\n", (
int) offsetof(TriangleGLSL, a.z));
244 printf(
" b %d\n", (
int) offsetof(TriangleGLSL, b));
245 printf(
" c %d\n", (
int) offsetof(TriangleGLSL, c));
246 printf(
"= %dB\n", (
int)
sizeof(TriangleGLSL));
258 int main(
int argc,
char **argv )
262 if(window ==
nullptr)
267 if(context ==
nullptr)
273 printf(
"[error] init failed.\n");
Context create_context(Window window)
cree et configure un contexte opengl
void release_window(Window window)
destruction de la fenetre.
void printf(Text &text, const int px, const int py, const char *format,...)
affiche un texte a la position x, y. meme utilisation que printf().
Window create_window(const int w, const int h, const int major, const int minor, const int samples)
creation d'une fenetre pour l'application.
void release_context(Context context)
detruit le contexte openGL.
GLuint read_program(const char *filename, const char *definitions)
int program_print_errors(const GLuint program)
affiche les erreurs de compilation.
int release_program(const GLuint program)
detruit les shaders et le program.
int init(std::vector< const char * > &options)
representation d'une couleur (rgba) transparente ou opaque.
representation d'un point 3d.
representation d'un vecteur 3d.
vecteur generique, utilitaire.