Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
59 pj 1
#ifdef MESA_TRACE
2
 
3
#include "glheader.h"
4
#include <time.h>  /* XXX move into glheader.h */
5
#include "tr_write.h"
6
#include "tr_context.h"
7
 
8
#define PATH_MAX 4098
9
 
10
 
11
static void trWriteFile( const void * buf, GLint recsize, GLint numrecs, const char * funcname ) {
12
        GLint recswritten;
13
 
14
        if( !(trCtx()->trDoPrint) ) {
15
                return;
16
        }
17
 
18
        recswritten = fwrite( buf, recsize, numrecs, trCtx()->logFP );
19
        if( recswritten != numrecs ) {
20
                fprintf( stderr, "Error writing to file in %s\n", funcname );
21
                fprintf( stderr, "Perhaps the disk is full?\n" );
22
                /* Should we abort ? */
23
                trCtx()->trDoPrint = GL_FALSE;
24
        }
25
}
26
 
27
 
28
static void (*trWrite)( const void *, GLint, GLint, const char *) = trWriteFile;
29
 
30
 
31
void trWriteCMD( GLint cmd ) {
32
        trWrite( (void*)&cmd, sizeof(GLint), 1, "trWriteCMD" );
33
}
34
 
35
void trWriteb( GLbyte b ) {
36
        trWrite( (void*)&b, sizeof(GLbyte), 1, "trWriteb" );
37
}
38
 
39
void trWrited( GLdouble d ) {
40
        trWrite( (void*)&d, sizeof(GLdouble), 1, "trWrited" );
41
}
42
 
43
void trWriteClampd( GLclampd cd ) {
44
        trWrite( (void*)&cd, sizeof(GLclampd), 1, "trWriteClampd" );
45
}
46
 
47
void trWritef( GLfloat f ) {
48
        trWrite( (void*)&f, sizeof(GLfloat), 1, "trWritef" );
49
}
50
 
51
void trWriteClampf( GLclampf cf ) {
52
        trWrite( (void*)&cf, sizeof(GLclampf), 1, "trWriteClampf" );
53
}
54
 
55
void trWritei( GLint i ) {
56
        trWrite( (void*)&i, sizeof(GLint), 1, "trWritei" );
57
}
58
 
59
void trWrites( GLshort s ) {
60
        trWrite( (void*)&s, sizeof(GLshort), 1, "trWrites" );
61
}
62
 
63
void trWriteub( GLubyte ub ) {
64
        trWrite( (void*)&ub, sizeof(GLubyte), 1, "trWriteub" );
65
}
66
 
67
void trWriteui( GLuint ui ) {
68
        trWrite( (void*)&ui, sizeof(GLuint), 1, "trWriteui" );
69
}
70
 
71
void trWriteus( GLushort us ) {
72
        trWrite( (void*)&us, sizeof(GLushort), 1, "trWriteus" );
73
}
74
 
75
void trWriteBool( GLboolean b ) {
76
        trWrite( (void*)&b, sizeof(GLboolean), 1, "trWriteBool" );
77
}
78
 
79
void trWriteBits( GLbitfield bf ) {
80
        trWrite( (void*)&bf, sizeof(GLbitfield), 1, "trWriteBits" );
81
}
82
 
83
void trWriteEnum( GLenum en ) {
84
        trWrite( (void*)&en, sizeof(GLenum), 1, "trWriteEnum" );
85
}
86
 
87
void trWriteSizei( GLsizei si ) {
88
        trWrite( (void*)&si, sizeof(GLsizei), 1, "trWriteSizei" );
89
}
90
 
91
 
92
void trWritePointer( const void * p ) {
93
        trWrite( (void*)&p, sizeof(void *), 1, "trWritePointer" );
94
}
95
 
96
 
97
void trWriteArrayb( GLsizei n, const GLbyte * b ) {
98
        trWrite( (void *)b, sizeof(GLbyte), n, "trWriteArrayb" );
99
}
100
 
101
 
102
void trWriteArrayub( GLsizei n, const GLubyte * ub ) {
103
        trWrite( (void *)ub, sizeof(GLubyte), n, "trWriteArrayub" );
104
}
105
 
106
 
107
void trWriteArrays( GLsizei n, const GLshort * s ) {
108
        trWrite( (void *)s, sizeof(GLshort), n, "trWriteArrays" );
109
}
110
 
111
 
112
void trWriteArrayus( GLsizei n, const GLushort * us ) {
113
        trWrite( (void *)us, sizeof(GLushort), n, "trWriteArrayus" );
114
}
115
 
116
 
117
void trWriteArrayi( GLsizei n, const GLint * i ) {
118
        trWrite( (void *)i, sizeof(GLint), n, "trWriteArrayi" );
119
}
120
 
121
 
122
void trWriteArrayui( GLsizei n, const GLuint * ui ) {
123
        trWrite( (void *)ui, sizeof(GLuint), n, "trWriteArrayui" );
124
}
125
 
126
 
127
void trWriteArrayBool( GLsizei n, const GLboolean * b ) {
128
        trWrite( (void *)b, sizeof(GLboolean), n, "trWriteArrayBool" );
129
}
130
 
131
 
132
void trWriteArrayf( GLsizei n, const GLfloat * f ) {
133
        trWrite( (void *)f, sizeof(GLfloat), n, "trWriteArrayf" );
134
}
135
 
136
 
137
void trWriteArrayd( GLsizei n, const GLdouble * d ) {
138
        trWrite( (void *)d, sizeof(GLdouble), n, "trWriteArrayd" );
139
}
140
 
141
 
142
void trWriteString( const char * str ) {
143
        GLuint length = strlen(str);
144
        trWriteui( length );
145
        trWrite( (void *)str, sizeof(GLubyte), length, "trWriteString" );
146
}
147
 
148
 
149
void trFileFlush( void ) {
150
  fflush( trCtx()->logFP );
151
}
152
 
153
 
154
static void trWriteTypeInformation( void ) {
155
 
156
        trWriteub( sizeof(GLint) );
157
        trWriteub( sizeof(GLshort) );
158
        trWriteub( sizeof(GLfloat) );
159
        trWriteub( sizeof(GLdouble) );
160
        trWriteub( sizeof(GLboolean) );
161
        trWriteub( sizeof(GLenum) );
162
        trWriteub( sizeof(GLsizei) );
163
        trWriteub( sizeof(GLbitfield) );
164
        trWriteub( sizeof(GLclampf) );
165
        trWriteub( sizeof(GLclampd) );
166
        trWriteub( sizeof(GLvoid *) );
167
 
168
}
169
 
170
 
171
static void trWriteHeader( void ) {
172
        struct tm *newtime;
173
        time_t aclock;
174
        char timestring[256];
175
 
176
        trWriteString( "0.0.1" );
177
        trWriteString( trCtx()->traceName );
178
        trWritei( trCtx()->framecounter );
179
 
180
        /* Always print this! */
181
        time( &aclock );
182
        newtime = localtime( &aclock );
183
        asctime( newtime );
184
        snprintf( timestring, sizeof(timestring), "Time: %s", asctime( newtime ) );
185
        trWriteString( timestring );
186
}
187
 
188
 
189
static void trWriteGLState( void ) {
190
        /*
191
         * This function will write all the queryable GL state at
192
         * the time the trace is started.
193
         */
194
}
195
 
196
 
197
void trOpenLogFile( void ) {
198
        GLint numchars;
199
        char buffer[PATH_MAX];
200
 
201
        numchars = snprintf( buffer, sizeof(buffer), "%s-gl.log.%d",
202
                             trCtx()->traceName, trCtx()->framecounter );
203
        if( numchars > -1 && numchars < sizeof(buffer) ) {
204
                trCtx()->logFP = fopen( buffer, "wb" );
205
 
206
                /* This information is needed before we can extract _anything_ */
207
                trWriteTypeInformation();
208
                trWriteHeader();
209
                trWriteGLState();
210
 
211
                (trCtx()->framecounter)++;
212
        } else if( numchars > -1 ) {
213
                fprintf( stderr, "buffer needs to be %d bytes long for logging to work.\n",
214
                         numchars + 1 );
215
                exit( -1 );
216
        } else {
217
                fprintf( stderr, "buffer needs to grow for logging to work.  Try %d bytes.\n",
218
                         sizeof(buffer) * 2 );
219
                exit( -1 );
220
        }
221
}
222
 
223
 
224
void trCloseLogFile( void ) {
225
        if( trCtx()->logFP != NULL ) {
226
                fclose(trCtx()->logFP);
227
        }
228
 
229
        trCtx()->logFP = NULL;
230
}
231
 
232
 
233
#else
234
extern void tr_write_dummy_func(void);
235
void tr_write_dummy_func(void)
236
{
237
}
238
#endif