19 template <
typename T >
20 struct alignas(4) gscalar
24 gscalar( ) : x(T()) {}
25 gscalar(
const T& v ) : x(v) {}
26 gscalar& operator= (
const T& v ) { x= v;
return *
this; }
27 operator T ( ) {
return x; }
30 typedef gscalar<float> gfloat;
31 typedef gscalar<int> gint;
32 typedef gscalar<unsigned int> guint;
33 typedef gscalar<bool> gbool;
36 template <
typename T >
37 struct alignas(8) gvec2
42 gvec2(
const gvec2<T>& v ) : x(v.x), y(v.y) {}
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)); }
49 typedef gvec2<float>
vec2;
50 typedef gvec2<int> ivec2;
51 typedef gvec2<unsigned int> uvec2;
52 typedef gvec2<int> bvec2;
55 template <
typename T >
56 struct alignas(16) gvec3
61 gvec3(
const gvec3<T>& v ) : x(v.x), y(v.y), z(v.z) {}
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)); }
72 typedef gvec3<float>
vec3;
73 typedef gvec3<int> ivec3;
74 typedef gvec3<unsigned int> uvec3;
75 typedef gvec3<int> bvec3;
78 template <
typename T >
79 struct alignas(16) gvec4
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)); }
92 typedef gvec4<float>
vec4;
93 typedef gvec4<int> ivec4;
94 typedef gvec4<unsigned int> uvec4;
95 typedef gvec4<int> bvec4;
100 template <
typename T >
106 gscalar(
const T& v ) : x(v) {}
107 gscalar& operator= (
const T& v ) { x= v;
return *
this; }
108 operator T ( ) {
return x; }
116 template <
typename T >
123 gvec2( const ::vec2& v ) : x(v.x), y(v.y) {}
124 gvec2& operator= (
const gvec2<T>& v ) { x= v.x; y= v.y;
return *
this; }
125 gvec2& operator= ( const ::vec2& v ) { x= v.x; y= v.y;
return *
this; }
126 operator ::vec2 ( ) { return ::vec2(
float(x),
float(y)); }
134 template <
typename T >
137 alignas(4) T x, y, z;
141 gvec3( const ::vec3& v ) : x(v.x), y(v.y), z(v.z) {}
142 gvec3(
const Point& v ) : x(v.x), y(v.y), z(v.z) {}
143 gvec3(
const Vector& v ) : x(v.x), y(v.y), z(v.z) {}
144 gvec3& operator= (
const gvec3<T>& v ) { x= v.x; y= v.y; z= v.z;
return *
this; }
145 gvec3& operator= ( const ::vec3& v ) { x= v.x; y= v.y; z= v.z;
return *
this; }
146 gvec3& operator= (
const Point& v ) { x= v.x; y= v.y; z= v.z;
return *
this; }
147 gvec3& operator= (
const Vector& v ) { x= v.x; y= v.y; z= v.z;
return *
this; }
148 operator ::vec3 ( ) { return ::vec3(
float(x),
float(y),
float(y)); }
156 template <
typename T >
159 alignas(4) T x, y, z, w;
162 gvec4(
const gvec4<T>& v ) : x(v.x), y(v.y), z(v.z), w(v.w) {}
163 gvec4( const ::vec4& v ) : x(v.x), y(v.y), z(v.z), w(v.w) {}
164 gvec4& operator= (
const gvec4<T>& v ) { x(v.x), y(v.y), z(v.z), w(v.w) ;
return *
this; }
165 gvec4& operator= ( const ::vec4& v ) { x(v.x), y(v.y), z(v.z), w(v.w) ;
return *
this; }
166 gvec4& operator= (
const Color& c ) { x= c.r; y= c.g; z= c.b; w= c.a;
return *
this; }
167 operator ::vec4 ( ) { return ::vec4(
float(x),
float(y),
float(y),
float(w)); }
180 const char *glsl_string(
const GLenum type )
186 case GL_UNSIGNED_INT:
208 int print_uniform(
const GLuint program )
212 printf(
"[error] program 0, no buffers...\n");
217 GLint buffer_count= 0;
218 glGetProgramiv(program, GL_ACTIVE_UNIFORM_BLOCKS, &buffer_count);
220 for(
int i= 0; i < buffer_count; i++)
223 char bname[1024]= { 0 };
224 glGetActiveUniformBlockName(program, i,
sizeof(bname),
nullptr, bname);
227 glGetActiveUniformBlockiv(program, i, GL_UNIFORM_BLOCK_BINDING, &binding);
229 printf(
" uniform '%s' binding %d\n", bname, binding);
231 GLint variable_count= 0;
232 glGetActiveUniformBlockiv(program, i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, &variable_count);
234 std::vector<GLint> variables(variable_count);
235 glGetActiveUniformBlockiv(program, i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES, variables.data());
236 for(
int k= 0; k < variable_count; k++)
240 glGetActiveUniformsiv(program, 1, (GLuint *) &variables[k], GL_UNIFORM_TYPE, &glsl_type);
242 glGetActiveUniformsiv(program, 1, (GLuint *) &variables[k], GL_UNIFORM_OFFSET, &offset);
245 glGetActiveUniformsiv(program, 1, (GLuint *) &variables[k], GL_UNIFORM_SIZE, &array_size);
246 GLint array_stride= 0;
247 glGetActiveUniformsiv(program, 1, (GLuint *) &variables[k], GL_UNIFORM_ARRAY_STRIDE, &array_stride);
249 GLint matrix_stride= 0;
250 glGetActiveUniformsiv(program, 1, (GLuint *) &variables[k], GL_UNIFORM_MATRIX_STRIDE, &matrix_stride);
251 GLint matrix_row_major= 0;
252 glGetActiveUniformsiv(program, 1, (GLuint *) &variables[k], GL_UNIFORM_IS_ROW_MAJOR, &matrix_row_major);
255 char vname[1024]= { 0 };
256 glGetActiveUniformName(program, variables[k],
sizeof(vname),
nullptr, vname);
258 printf(
" '%s %s': offset %d", glsl_string(glsl_type), vname, offset);
260 printf(
", array size %d, stride %d", array_size, array_stride);
263 if(glsl_type == GL_FLOAT_MAT4 || glsl_type == GL_FLOAT_MAT3)
264 printf(
", %s, matrix stride %d", matrix_row_major ?
"row major" :
"column major", matrix_stride);
269 GLint buffer_size= 0;
270 glGetActiveUniformBlockiv(program, i, GL_UNIFORM_BLOCK_DATA_SIZE, &buffer_size);
271 printf(
" buffer size %d\n\n", buffer_size);
287 print_uniform(program);
310 printf(
"a %ld\n", offsetof(buffer, a));
311 printf(
"a.x %ld\n", offsetof(buffer, a.x));
312 printf(
"a.y %ld\n", offsetof(buffer, a.y));
314 printf(
"b %ld\n", offsetof(buffer, b));
315 printf(
"b.x %ld\n", offsetof(buffer, b.x));
316 printf(
"b.y %ld\n", offsetof(buffer, b.y));
317 printf(
"b.z %ld\n", offsetof(buffer, b.z));
319 printf(
"c %ld\n", offsetof(buffer, c));
320 printf(
"c.x %ld\n", offsetof(buffer, c.x));
321 printf(
"c.y %ld\n", offsetof(buffer, c.y));
322 printf(
"c.z %ld\n", offsetof(buffer, c.z));
323 printf(
"c.w %ld\n", offsetof(buffer, c.w));
325 printf(
"d %ld\n", offsetof(buffer, d));
326 printf(
"d[0] %ld\n", offsetof(buffer, d[0]));
327 printf(
"d[1] %ld\n", offsetof(buffer, d[1]));
328 printf(
"d[2] %ld\n", offsetof(buffer, d[2]));
337 printf(
"%f %f\n", d0.x, d0.y);
348 int main(
int argc,
char **argv )
352 if(window ==
nullptr)
357 if(context ==
nullptr)
363 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.
vecteur generique, utilitaire.
vecteur generique 4d, ou 3d homogene, utilitaire.