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