00001
00002 #ifndef _GL_STREAM_QUERY_H
00003 #define _GL_STREAM_QUERY_H
00004
00005 #include "GL/GLPlatform.h"
00006 #include "GLResource.h"
00007
00008
00009 namespace gk {
00010
00011
00012 class GLStreamQuery : public GLResource
00013 {
00014 GLuint *m_names;
00015 GLenum m_target;
00016 unsigned int m_count;
00017 GLint m_bits_n;
00018
00019 public:
00020
00021 GLStreamQuery( const GLenum target, const unsigned int count )
00022 :
00023 GLResource(),
00024 m_names(NULL),
00025 m_target(target),
00026 m_count(count),
00027 m_bits_n(0)
00028 {
00029 m_names= new GLuint [m_count];
00030 glGenQueries(m_count, m_names);
00031 glGetQueryiv(m_target, GL_QUERY_COUNTER_BITS, &m_bits_n);
00032 #ifdef VERBOSE_DEBUG
00033 printf("GLStreamQuery( ): %d bits result\n", m_bits_n);
00034 #endif
00035 }
00036
00037
00038 ~GLStreamQuery( )
00039 {
00040 glDeleteQueries(m_count, m_names);
00041 delete [] m_names;
00042 }
00043
00044
00045 int createGLResource( )
00046 {
00047 return (m_names != NULL) ? 0 : -1;
00048 }
00049
00050
00051 int releaseGLResource( )
00052 {
00053 return (m_names != NULL) ? 0 : -1;
00054 }
00055
00056
00057 GLuint name( const unsigned int index ) const
00058 {
00059 if(m_names == NULL || index >= m_count)
00060 return 0;
00061 return m_names[index];
00062 }
00063
00064
00065 int begin( const unsigned int index )
00066 {
00067 if(m_names == NULL || index >= m_count || m_names[index] == 0)
00068 return -1;
00069
00070 glBeginQueryIndexed(m_target, index, m_names[index]);
00071 return 0;
00072 }
00073
00074
00075 int end( const unsigned int index )
00076 {
00077 if(m_names == NULL || index >= m_count || m_names[index] == 0)
00078 return -1;
00079 glEndQueryIndexed(m_target, index);
00080 return 0;
00081 }
00082
00083
00084 bool isAvailable( const unsigned int index )
00085 {
00086 if(m_names == NULL || index >= m_count || m_names[index] == 0)
00087 return -1;
00088 GLint available= 0;
00089
00090 glGetQueryObjectiv(m_names[index], GL_QUERY_RESULT_AVAILABLE, &available);
00091
00092 #ifdef VERBOSE
00093 {
00094 GLint name;
00095 GLint tmp;
00096 glGetQueryIndexediv(m_target, index, GL_CURRENT_QUERY, &name);
00097 glGetQueryObjectiv(name, GL_QUERY_RESULT_AVAILABLE, &tmp);
00098 printf("GLStreamQuery( ): available: %d (%d).\n", available, tmp);
00099 }
00100 #endif
00101
00102 return (available == GL_TRUE);
00103 }
00104
00105
00106 int is64bits( )
00107 {
00108 if(m_names == NULL)
00109 return -1;
00110 return (m_bits_n == 64) ? 1 : 0;
00111 }
00112
00113
00114 int result( const unsigned int index )
00115 {
00116 if(m_names == NULL || index >= m_count || m_names[index] == 0)
00117 return -1;
00118
00119 GLint n= 0;
00120 glGetQueryObjectiv(m_names[index], GL_QUERY_RESULT, &n);
00121 return n;
00122 }
00123
00124
00125 long long int result64( const unsigned int index )
00126 {
00127 if(m_names == NULL || index >= m_count || m_names[index] == 0)
00128 return -1;
00129
00130 GLint64 n= 0;
00131 glGetQueryObjecti64v(m_names[index], GL_QUERY_RESULT, &n);
00132 return n;
00133 }
00134 };
00135
00136
00137 class GLStreamPrimitivesGenerated : public GLStreamQuery
00138 {
00139 public:
00140 GLStreamPrimitivesGenerated( const unsigned int count )
00141 :
00142 GLStreamQuery(GL_PRIMITIVES_GENERATED, count)
00143 {}
00144
00145 ~GLStreamPrimitivesGenerated( ) {}
00146 };
00147
00148
00149 class GLStreamFeedbackPrimitives : public GLStreamQuery
00150 {
00151 public:
00152 GLStreamFeedbackPrimitives( const unsigned int count )
00153 :
00154 GLStreamQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, count)
00155 {}
00156
00157 ~GLStreamFeedbackPrimitives( ) {}
00158 };
00159
00160 }
00161
00162 #endif