6 /*############################################################################*/
8 #define TRACE_FILE "/run/log"
10 #define TRACE(...) trace((void*)__func__, __VA_ARGS__)
13 static FILE *trace_file
;
14 static void trace_init(void)
16 trace_file
= fopen(TRACE_FILE
, "a");
17 setvbuf(trace_file
, NULL
, _IONBF
, 0);
18 fcntl(fileno(trace_file
), F_SETFL
, fcntl(fileno(trace_file
),
21 static void trace(void *fn
, void *fmt
, ...)
27 flock(fileno(trace_file
), LOCK_EX
); /* process level */
28 flockfile(trace_file
); /* thread level */
29 fprintf(trace_file
, "%d:%d:%s:", getpid(), gettid(), fn
);
31 vfprintf(trace_file
, fmt
, ap
);
33 fprintf(trace_file
, "\n");
35 funlockfile(trace_file
); /* thread level */
36 flock(fileno(trace_file
), LOCK_UN
); /* process level */
38 #define STRING(x) case x: return #x
39 static void *getstring_str(unsigned int e
)
45 STRING(GL_SHADING_LANGUAGE_VERSION
);
46 /* unavailable thru glGetString in core profile */
47 STRING(GL_EXTENSIONS
);
54 #define TARGET(x) case x: return #x
55 static void *tex_target_str(GLenum target
)
58 TARGET(GL_TEXTURE_2D
);
64 #define MODE_STR(x) case x: return #x
65 static void *matrixmode_mode_str(unsigned int mode
)
68 MODE_STR(GL_MODELVIEW
);
69 MODE_STR(GL_PROJECTION
);
77 #define TARGET(x) case x: return #x
78 static void *texenv_target_str(unsigned int t
)
81 TARGET(GL_TEXTURE_ENV
);
82 TARGET(GL_TEXTURE_FILTER_CONTROL
);
83 TARGET(GL_POINT_SPRITE
);
89 #define PNAME(x) case x: return #x
90 static void *texenv_pname_str(unsigned int pname
)
93 PNAME(GL_TEXTURE_ENV_MODE
);
99 #define MODE(x) case x: return #x
100 static void *rendermode_str(unsigned int mode
)
111 #define PNAME(x) case x: return #x
112 static void *getinteger_pname_str(unsigned int pname
)
116 PNAME(GL_NUM_EXTENSIONS
);
122 #define FMT(x) case x: return #x
123 static void *tex_format_str(GLint fmt
)
134 #define TYPE(x) case x: return #x
135 static void *pixel_data_format_str(GLenum type
)
138 TYPE(GL_UNSIGNED_BYTE
);
144 #define PNAME(x) case x: return #x
145 static void *pixelstore_pname_str(GLenum pname
)
148 PNAME(GL_PACK_ALIGNMENT
); /* alignment to write data to client */
149 PNAME(GL_PACK_SWAP_BYTES
);
150 PNAME(GL_PACK_LSB_FIRST
);
151 PNAME(GL_PACK_ROW_LENGTH
);
152 PNAME(GL_PACK_IMAGE_HEIGHT
);
153 PNAME(GL_PACK_SKIP_PIXELS
);
154 PNAME(GL_PACK_SKIP_ROWS
);
155 PNAME(GL_PACK_SKIP_IMAGES
);
156 PNAME(GL_UNPACK_ALIGNMENT
); /* alignment to read data from client */
157 PNAME(GL_UNPACK_SWAP_BYTES
);
158 PNAME(GL_UNPACK_LSB_FIRST
);
159 PNAME(GL_UNPACK_ROW_LENGTH
);
160 PNAME(GL_UNPACK_IMAGE_HEIGHT
);
161 PNAME(GL_UNPACK_SKIP_PIXELS
);
162 PNAME(GL_UNPACK_SKIP_ROWS
);
168 #define MODE(x) case x: return #x
169 static void *begin_mode(GLenum mode
)
177 MODE(GL_TRIANGLE_STRIP
);
178 MODE(GL_TRIANGLE_FAN
);
187 #define PNAME(x) case x: return #x
188 static void *texparameter_pname_str(GLenum pname
)
191 PNAME(GL_DEPTH_STENCIL_TEXTURE_MODE
);
192 PNAME(GL_TEXTURE_BASE_LEVEL
);
193 PNAME(GL_TEXTURE_COMPARE_FUNC
);
194 PNAME(GL_TEXTURE_COMPARE_MODE
);
195 PNAME(GL_TEXTURE_LOD_BIAS
);
196 PNAME(GL_TEXTURE_MIN_FILTER
);
197 PNAME(GL_TEXTURE_MAG_FILTER
);
198 PNAME(GL_TEXTURE_MIN_LOD
);
199 PNAME(GL_TEXTURE_MAX_LOD
);
200 PNAME(GL_TEXTURE_MAX_LEVEL
);
201 PNAME(GL_TEXTURE_SWIZZLE_R
);
202 PNAME(GL_TEXTURE_SWIZZLE_G
);
203 PNAME(GL_TEXTURE_SWIZZLE_B
);
204 PNAME(GL_TEXTURE_SWIZZLE_A
);
205 PNAME(GL_TEXTURE_WRAP_S
);
206 PNAME(GL_TEXTURE_WRAP_T
);
207 PNAME(GL_TEXTURE_WRAP_R
);
213 static void *texparameterf_param_str(GLenum pname
, GLfloat param
)
215 if (pname
== GL_TEXTURE_WRAP_S
|| pname
== GL_TEXTURE_WRAP_T
216 || GL_TEXTURE_WRAP_R
) {
219 param_u
= (int)param
;
220 #define WRAP(x) case x: return #x
222 WRAP(GL_CLAMP_TO_EDGE
);
223 WRAP(GL_CLAMP_TO_BORDER
);
224 WRAP(GL_MIRRORED_REPEAT
);
226 WRAP(GL_MIRROR_CLAMP_TO_EDGE
);
234 #define CAP(x) case x: return #x
235 static void *disable_enable_cap_str(GLenum cap
)
247 CAP(GL_COLOR_LOGIC_OP
);
248 CAP(GL_COLOR_MATERIAL
);
251 CAP(GL_CONVOLUTION_1D
);
252 CAP(GL_CONVOLUTION_2D
);
258 CAP(GL_INDEX_LOGIC_OP
);
269 CAP(GL_LINE_STIPPLE
);
270 CAP(GL_MAP1_COLOR_4
);
273 CAP(GL_MAP1_TEXTURE_COORD_1
);
274 CAP(GL_MAP1_TEXTURE_COORD_2
);
275 CAP(GL_MAP1_TEXTURE_COORD_3
);
276 CAP(GL_MAP1_TEXTURE_COORD_4
);
277 CAP(GL_MAP1_VERTEX_3
);
278 CAP(GL_MAP1_VERTEX_4
);
279 CAP(GL_MAP2_COLOR_4
);
282 CAP(GL_MAP2_TEXTURE_COORD_1
);
283 CAP(GL_MAP2_TEXTURE_COORD_2
);
284 CAP(GL_MAP2_TEXTURE_COORD_3
);
285 CAP(GL_MAP2_TEXTURE_COORD_4
);
286 CAP(GL_MAP2_VERTEX_3
);
287 CAP(GL_MAP2_VERTEX_4
);
291 CAP(GL_POINT_SMOOTH
);
292 CAP(GL_POINT_SPRITE
);
293 CAP(GL_POLYGON_OFFSET_FILL
);
294 CAP(GL_POLYGON_OFFSET_LINE
);
295 CAP(GL_POLYGON_OFFSET_POINT
);
296 CAP(GL_POLYGON_SMOOTH
);
297 CAP(GL_POLYGON_STIPPLE
);
298 CAP(GL_POST_COLOR_MATRIX_COLOR_TABLE
);
299 CAP(GL_POST_CONVOLUTION_COLOR_TABLE
);
300 CAP(GL_RESCALE_NORMAL
);
301 CAP(GL_SAMPLE_ALPHA_TO_COVERAGE
);
302 CAP(GL_SAMPLE_ALPHA_TO_ONE
);
303 CAP(GL_SAMPLE_COVERAGE
);
304 CAP(GL_SEPARABLE_2D
);
305 CAP(GL_SCISSOR_TEST
);
306 CAP(GL_STENCIL_TEST
);
310 CAP(GL_TEXTURE_CUBE_MAP
);
311 CAP(GL_TEXTURE_GEN_Q
);
312 CAP(GL_TEXTURE_GEN_R
);
313 CAP(GL_TEXTURE_GEN_S
);
314 CAP(GL_TEXTURE_GEN_T
);
315 CAP(GL_VERTEX_PROGRAM_POINT_SIZE
);
316 CAP(GL_VERTEX_PROGRAM_TWO_SIDE
);
317 CAP(GL_VERTEX_PROGRAM_ARB
);
318 CAP(GL_FRAGMENT_PROGRAM_ARB
);
320 CAP(GL_EDGE_FLAG_ARRAY
);
322 CAP(GL_NORMAL_ARRAY
);
323 CAP(GL_TEXTURE_COORD_ARRAY
);
324 CAP(GL_VERTEX_ARRAY
);
329 #define MODE(x) case x: return #x
330 static void *shademodel_mode_str(GLenum mode
)
340 #define FACTOR(x) case x: return #x
341 static void *blendfunc_factor_str(GLenum factor
)
346 FACTOR(GL_SRC_COLOR
);
347 FACTOR(GL_ONE_MINUS_SRC_COLOR
);
348 FACTOR(GL_DST_COLOR
);
349 FACTOR(GL_ONE_MINUS_DST_COLOR
);
350 FACTOR(GL_SRC_ALPHA
);
351 FACTOR(GL_ONE_MINUS_SRC_ALPHA
);
352 FACTOR(GL_DST_ALPHA
);
353 FACTOR(GL_ONE_MINUS_DST_ALPHA
);
354 FACTOR(GL_CONSTANT_COLOR
);
355 FACTOR(GL_ONE_MINUS_CONSTANT_COLOR
);
356 FACTOR(GL_CONSTANT_ALPHA
);
357 FACTOR(GL_ONE_MINUS_CONSTANT_ALPHA
);
358 FACTOR(GL_SRC_ALPHA_SATURATE
);
359 FACTOR(GL_SRC1_COLOR
);
360 FACTOR(GL_ONE_MINUS_SRC1_COLOR
);
361 FACTOR(GL_SRC1_ALPHA
);
362 FACTOR(GL_ONE_MINUS_SRC1_ALPHA
);
368 static void *texenv_param_str(unsigned int pname
, float param
)
370 if (param
== (float)GL_MODULATE
)
371 return "GL_MODULATE";
374 static void printf_visualinfo(const void *str
, XVisualInfo
*i
)
376 TRACE("%s:visualid=%lu", str
, i
->visualid
);
377 TRACE("%s:red_mask=%x", str
, i
->red_mask
);
378 TRACE("%s:green_mask=%x", str
, i
->green_mask
);
379 TRACE("%s:blue_mask=%x", str
, i
->blue_mask
);
380 TRACE("%s:class=%d", str
, i
->class);
381 TRACE("%s:bits_per_rgb=%d", str
, i
->bits_per_rgb
);
382 TRACE("%s:depth=%u", str
, i
->depth
);
383 TRACE("%s:colormap_size=%u", str
, i
->colormap_size
);
384 TRACE("%s:screen=%d", str
, i
->screen
);
386 static void attribList_parse(int *l
)
395 TRACE("attriblist:GLX_USE_GL");
398 case GLX_BUFFER_SIZE
:
399 TRACE("attriblist:GLX_BUFFER_SIZE=%d", l
[1]);
403 TRACE("attriblist:GLX_LEVEL=%d", l
[1]);
407 TRACE("attriblist:GLX_RGBA");
410 case GLX_DOUBLEBUFFER
:
411 TRACE("attriblist:GLX_DOUBLEBUFFER");
415 TRACE("attriblist:GLX_STEREO");
418 case GLX_AUX_BUFFERS
:
419 TRACE("attriblist:GLX_AUX_BUFFERS=%d", l
[1]);
423 TRACE("attriblist:GLX_RED_SIZE=%d bits", l
[1]);
427 TRACE("attriblist:GLX_GREEN_SIZE=%d bits", l
[1]);
431 TRACE("attriblist:GLX_BLUE_SIZE=%d bits", l
[1]);
435 TRACE("attriblist:GLX_ALPHA_SIZE=%d bits", l
[1]);
439 TRACE("attriblist:GLX_DEPTH_SIZE=%d", l
[1]);
442 case GLX_STENCIL_SIZE
:
443 TRACE("attriblist:GLX_STENCIL_SIZE=%d", l
[1]);
446 case GLX_ACCUM_RED_SIZE
:
447 TRACE("attriblist:GLX_ACCUM_RED_SIZE=%d", l
[1]);
450 case GLX_ACCUM_GREEN_SIZE
:
451 TRACE("attriblist:GLX_ACCUM_GREEN_SIZE=%d", l
[1]);
454 case GLX_ACCUM_BLUE_SIZE
:
455 TRACE("attriblist:GLX_ACCUM_BLUE_SIZE=%d", l
[1]);
458 case GLX_ACCUM_ALPHA_SIZE
:
459 TRACE("attriblist:GLX_ACCUM_ALPHA_SIZE=%d", l
[1]);
463 TRACE("attriblist:UNKNOWN=%d", *l
);
469 #else /* !TRACE_ON */
471 * we rely on dead code elimination... mmmmmh... we don't know if it is
472 * a feature expensive for a naive and simple C89(with bits of C99) compiler
474 static void trace_init(){};
475 static void trace(void *fn
, void *fmt
, ...){}
476 static void attribList_parse(int *l
){}
477 static void printf_visualinfo(const void *str
, XVisualInfo
*i
){}
478 static void *getstring_str(unsigned int e
){}
479 static void *tex_target_str(GLenum target
){}
480 static void *matrixmode_mode_str(unsigned int mode
){}
481 static void *texenv_target_str(unsigned int t
){}
482 static void *texenv_pname_str(unsigned int pname
){}
483 static void *rendermode_str(unsigned int mode
){}
484 static void *getinteger_pname_str(unsigned int pname
){}
485 static void *tex_format_str(GLint fmt
){}
486 static void *pixel_data_format_str(GLenum type
){}
487 static void *pixelstore_pname_str(GLenum pname
){}
488 static void *begin_mode(GLenum mode
){}
489 static void *texparameter_pname_str(GLenum pname
){}
490 static void *texparameterf_param_str(GLenum pname
, GLfloat param
){}
491 static void *disable_enable_cap_str(GLenum cap
){}
492 static void *shademodel_mode_str(GLenum mode
){}
493 static void *blendfunc_factor_str(GLenum factor
){}
494 static void *texenv_param_str(unsigned int pname
, float param
){}
496 /*############################################################################*/
499 /*############################################################################*/
500 #define LOG(...) vlog((void*)__func__, __VA_ARGS__)
501 static void vlog(void *fn
, void *fmt
, ...)
504 #if defined(TRACE_ON) && defined(REDIRECT_LOG_TO_TRACE_FILE)
505 flock(fileno(trace_file
), LOCK_EX
); /* process level */
506 flockfile(trace_file
); /* thread level */
507 fprintf(trace_file
, "%d:%s:", getpid(), fn
);
509 vfprintf(trace_file
, fmt
, ap
);
511 fprintf(trace_file
, "\n");
513 funlockfile(trace_file
); /* thread level */
514 flock(fileno(trace_file
), LOCK_UN
); /* process level */
516 flockfile(stderr
); /* thread level */
517 fprintf(stderr
, "MINI2DGL:%s:", fn
);
519 vfprintf(stderr
, fmt
, ap
);
521 fprintf(stderr
, "\n");
523 funlockfile(stderr
); /* thread level */
526 /*############################################################################*/