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