1 #include "idlib/precompiled.h"
2 #include "renderer/tr_local.h"
3 #include "sys/linux/local.h"
4 #include "glimp_local.h"
8 #define ID_LOG_TO_STDOUT 0
10 dnl =====================================================
12 dnl =====================================================
15 `pushdef(`$1', `$2')_forloop(`$1', `$2', `$3', `$4')popdef(`$1')')
17 `$4`'ifelse($1, `$3', ,
18 `define(`$1', incr($1))_forloop(`$1', `$2', `$3', `$4')')')
20 dnl =====================================================
21 dnl the gl wgl glX definitions
22 dnl =====================================================
23 include(../gllog/gl_def.m4)
25 dnl =====================================================
27 dnl =====================================================
34 #define DEF(x) { x, #x },
36 glEnumName_t glEnumNames[] = {
37 #include "sys/linux/glimp_glenum.h"
42 ======================
44 ======================
46 static const char *EnumString( GLenum t )
48 static char buffer[8][1024];
51 for ( glEnumName_t *n = glEnumNames ; n->name ; n++ ) {
58 index = ( index + 1 ) & 7;
59 sprintf( buffer[oldIndex], "0x%x", t );
61 return buffer[oldIndex];
65 ======================
67 ======================
69 static const char *FloatData( const GLfloat *v, int count ) {
70 static char buffer[8][1024];
74 name = buffer[index&7];
75 sprintf( name, "f%i", index );
78 fprintf( tr.logFile, "static float %s[%i] = {", name, count );
79 for( int i = 0 ; i < count ; i++ ) {
80 if ( i < count - 1 ) {
81 fprintf( tr.logFile, "%f,", v[i] );
83 fprintf( tr.logFile, "%f};\n", v[i] );
90 #include "glimp_logfuncs.cpp"
92 dnl define(`log_func', `static `$1' APIENTRY log`$2'(`$3') {
94 dnl forloop(`i', gl_start, gl_end, `log_func(indir(`f'i`_ret'), indir(`f'i`_name'), indir(`f'i`_params'))
96 dnl forloop(`i', glX_start, glX_end, `log_func(indir(`f'i`_ret'), indir(`f'i`_name'), indir(`f'i`_params'))
100 ======================
102 ======================
104 void GLimp_BindLogging() {
105 define(`assign_funcptr', `qgl`$1' = log`$1';')
106 forloop(`i', gl_start, gl_end, `assign_funcptr(indir(`f'i`_name'))
109 define(`assign_funcptr', `qglX`$1' = log`$1';')
110 forloop(`i', glX_start, glX_end, `assign_funcptr(indir(`f'i`_name'))
115 ======================
117 ======================
119 void GLimp_EnableLogging(bool enable) {
120 static bool isEnabled = false;
122 static int initialFrames;
124 // return if we're already active
125 if ( isEnabled && enable ) {
126 // decrement log counter and stop if it has reached 0
127 r_logFile.SetInteger( r_logFile.GetInteger() - 1 );
128 if ( r_logFile.GetInteger() ) {
132 common->Printf( "end stdout GL loggging after %i frames.\n", initialFrames );
134 common->Printf( "closing GL logfile '%s' after %i frames.\n", ospath.c_str(), initialFrames );
136 fclose( tr.logFile );
142 // return if we're already disabled
143 if ( !enable && !isEnabled ) {
156 initialFrames = r_logFile.GetInteger();
159 tr.logFile = fdopen( STDOUT_FILENO, "w" );
161 // scan for an unused filename
162 for ( i = 0 ; i < 9999 ; i++ ) {
163 sprintf( qpath, "renderlog_%i.txt", i );
164 if ( fileSystem->ReadFile( qpath, NULL, NULL ) == -1 ) {
165 break; // use this name
169 ospath = fileSystem->RelativePathToOSPath( qpath );
170 tr.logFile = fopen( ospath, "wt" );
173 // write the time out to the top of the file
175 newtime = localtime( &aclock );
176 fprintf( tr.logFile, "// %s", asctime( newtime ) );
177 fprintf( tr.logFile, "// %s\n\n", com_version.GetString() );