X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=glwrap.c;h=e92889a7688da5efb636f1fc4503c251e3f91b79;hb=5569357a9fc7189c2bae43773f44ba576583ec2b;hp=beb1c97fd38cb05830e6ce1f37b9680c872804bc;hpb=c0c549440d852153d1777eca3fa962c1b70483b3;p=fips diff --git a/glwrap.c b/glwrap.c index beb1c97..e92889a 100644 --- a/glwrap.c +++ b/glwrap.c @@ -19,12 +19,6 @@ * THE SOFTWARE. */ -#include "fips.h" - -#include "glwrap.h" - -#include "metrics.h" - /* The prototypes for some OpenGL functions changed at one point from: * * const void* *indices @@ -42,11 +36,17 @@ */ #define const -#define GL_GLEXT_PROTOTYPES -#include +#include "fips.h" +#include "fips-dispatch.h" + +#include "glwrap.h" + +#include "metrics.h" #include "dlwrap.h" +static int inside_new_list = 0; + void * glwrap_lookup (char *name) { @@ -65,13 +65,17 @@ glwrap_lookup (char *name) return dlwrap_real_dlsym (libgl_handle, name); } -/* Execute a glBegineQuery/glEndQuery pair around an OpenGL call. */ -#define TIMED_DEFER(function,...) do { \ - unsigned counter; \ - counter = metrics_add_counter (); \ - glBeginQuery (GL_TIME_ELAPSED, counter); \ - GLWRAP_DEFER(function, __VA_ARGS__); \ - glEndQuery (GL_TIME_ELAPSED); \ +/* Execute a glBeginQuery/glEndQuery pair around an OpenGL call. */ +#define TIMED_DEFER(function,...) do { \ + if (! inside_new_list) { \ + unsigned counter; \ + counter = metrics_add_counter (); \ + glBeginQuery (GL_TIME_ELAPSED, counter); \ + } \ + GLWRAP_DEFER(function, __VA_ARGS__); \ + if (! inside_new_list) { \ + glEndQuery (GL_TIME_ELAPSED); \ + } \ } while (0); /* Thanks to apitrace source code for the list of OpenGL draw calls. */ @@ -151,13 +155,12 @@ glMultiModeDrawArraysIBM (const GLenum *mode, const GLint *first, first, count, primcount, modestride); } -/* FIXME? void -glMultiDrawArraysIndirect (...) +glMultiDrawArraysIndirect (GLenum mode, const void *indirect, + GLsizei drawcount, GLsizei stride) { - TIMED_DEFER (glMultiDrawArraysIndirect, ...); + TIMED_DEFER (glMultiDrawArraysIndirect, mode, indirect, drawcount, stride); } -*/ void glMultiDrawArraysIndirectAMD (GLenum mode, const GLvoid *indirect, @@ -297,13 +300,13 @@ glMultiModeDrawElementsIBM (const GLenum *mode, const GLsizei *count, type, indices, primcount, modestride); } -/* FIXME? void -glMultiDrawElementsIndirect (...) +glMultiDrawElementsIndirect (GLenum mode, GLenum type, const void *indirect, + GLsizei drawcount, GLsizei stride) { - TIMED_DEFER (glMultiDrawElementsIndirect, ...); + TIMED_DEFER (glMultiDrawElementsIndirect, mode, type, + indirect, drawcount, stride); } -*/ void glMultiDrawElementsIndirectAMD (GLenum mode, GLenum type, @@ -332,10 +335,46 @@ glClear (GLbitfield mask) TIMED_DEFER (glClear, mask); } +/* We can't just use TIMED_DEFER for glBegin/glEnd since the + * glBeginQuery/glEndQuery calls must both be outside + * glBegin/glEnd. */ +void +glBegin (GLenum mode) +{ + if (! inside_new_list) + { + unsigned counter; + counter = metrics_add_counter (); + glBeginQuery (GL_TIME_ELAPSED, counter); + } + + GLWRAP_DEFER (glBegin, mode); +} + void glEnd (void) { - TIMED_DEFER (glEnd,); + GLWRAP_DEFER (glEnd); + + if (! inside_new_list) { + glEndQuery (GL_TIME_ELAPSED); + } +} + +/* And we need to track display lists to avoid inserting queries + * inside the list while it's being constructed. */ +void +glNewList (GLuint list, GLenum mode) +{ + inside_new_list = 1; + GLWRAP_DEFER (glNewList, list, mode); +} + +void +glEndList (void) +{ + GLWRAP_DEFER (glEndList); + inside_new_list = 0; } void