gKitGL
|
00001 00002 #ifndef _GLQUERY_H 00003 #define _GLQUERY_H 00004 00005 #include "GL/GLPlatform.h" 00006 #include "GLResource.h" 00007 00008 00009 namespace gk { 00010 00011 //! utilisation interne. representation d'un objet requete. 00012 class GLQuery : public GLResource 00013 { 00014 GLenum m_target; //!< type de la requete GL_TIME_ELAPSED, GL_SAMPLES_PASSED, etc. 00015 GLint m_bits_n; //!< taille du resultat : 32 ou 64 bits. 00016 00017 public: 00018 //! constructeur. 00019 GLQuery( const GLenum target ) 00020 : 00021 GLResource(), 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 //! destructeur. 00033 ~GLQuery( ) 00034 { 00035 glDeleteQueries(1, &m_name); 00036 } 00037 00038 //! creation de l'objet requete. 00039 int createGLResource( ) 00040 { 00041 return (m_name != 0) ? 0 : -1; 00042 } 00043 00044 //! destruction de l'objet requete. 00045 int releaseGLResource( ) 00046 { 00047 return (m_name != 0) ? 0 : -1; 00048 } 00049 00050 //! debut de la requete, remise a 0 du compteur associe. 00051 int begin( ) 00052 { 00053 if(m_name == 0) 00054 return -1; 00055 glBeginQuery(m_target, m_name); 00056 return 0; 00057 } 00058 00059 //! fin de la requete. le resultat n'est pas necessairement disponible, cf. isAvailable(). 00060 int end( ) 00061 { 00062 if(m_name == 0) 00063 return -1; 00064 glEndQuery(m_target); 00065 return 0; 00066 } 00067 00068 //! determine si le resultat de la requete est disponible. 00069 bool isAvailable( ) 00070 { 00071 if(m_name == 0) 00072 return -1; 00073 GLint available= 0; 00074 glGetQueryObjectiv(m_name, GL_QUERY_RESULT_AVAILABLE, &available); 00075 return (available == GL_TRUE); 00076 } 00077 00078 //! renvoie vrai si le resultat est code sur 64 bits. 00079 int is64bits( ) 00080 { 00081 if(m_name == 0) 00082 return -1; 00083 return (m_bits_n == 64) ? 1 : 0; 00084 } 00085 00086 //! renvoie le resultat de la requete (sur 32 bits), attends le resultat, s'il n'est pas disponible. 00087 int result( ) 00088 { 00089 if(m_name == 0) 00090 return -1; 00091 00092 GLint n= 0; 00093 glGetQueryObjectiv(m_name, GL_QUERY_RESULT, &n); 00094 return n; 00095 } 00096 00097 //! renvoie le resultat de la requete (sur 64 bits), attends le resultat, s'il n'est pas disponible. 00098 long long int result64( ) 00099 { 00100 if(m_name == 0) 00101 return -1; 00102 00103 GLint64 n= 0; 00104 glGetQueryObjecti64v(m_name, GL_QUERY_RESULT, &n); 00105 return n; 00106 } 00107 }; 00108 00109 //! temps gpu necessaire a l'execution des commandes entre begin() et end(). 00110 class GLTimer : public GLQuery 00111 { 00112 public: 00113 GLTimer( ) 00114 : 00115 GLQuery(GL_TIME_ELAPSED) 00116 {} 00117 00118 ~GLTimer( ) {} 00119 }; 00120 00121 //! nombre de fragments ecrits entre begin() et end(). 00122 class GLOcclusion : public GLQuery 00123 { 00124 public: 00125 GLOcclusion( ) 00126 : 00127 GLQuery(GL_SAMPLES_PASSED) 00128 {} 00129 00130 ~GLOcclusion( ) {} 00131 }; 00132 00133 //! nombre de primitives emises en sortie du vertex shader, ou du geometrie shader, s'il existe. 00134 class GLPrimitivesGenerated : public GLQuery 00135 { 00136 public: 00137 GLPrimitivesGenerated( ) 00138 : 00139 GLQuery(GL_PRIMITIVES_GENERATED) 00140 {} 00141 00142 ~GLPrimitivesGenerated( ) {} 00143 }; 00144 00145 //! nombre de primitives ecrites dans les feedback buffers. 00146 class GLFeedbackPrimitives : public GLQuery 00147 { 00148 public: 00149 GLFeedbackPrimitives( ) 00150 : 00151 GLQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN) 00152 {} 00153 00154 ~GLFeedbackPrimitives( ) {} 00155 }; 00156 00157 } 00158 00159 #endif