gKitGL
|
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 //! utilisation interne. representation d'un objet requete. 00012 class GLStreamQuery : public GLResource 00013 { 00014 GLuint *m_names; //!< identifiant de la requete 00015 GLenum m_target; //!< type de la requete GL_TIME_ELAPSED, GL_SAMPLES_PASSED, etc. 00016 unsigned int m_count; //!< index de la requete / identifiant du flux pour "transform feedback" ou "primitive generated". 00017 GLint m_bits_n; //!< taille du resultat : 32 ou 64 bits. 00018 00019 public: 00020 //! constructeur. 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 //! destructeur. 00038 ~GLStreamQuery( ) 00039 { 00040 glDeleteQueries(m_count, m_names); 00041 delete [] m_names; 00042 } 00043 00044 //! creation de l'objet requete. 00045 int createGLResource( ) 00046 { 00047 return (m_names != NULL) ? 0 : -1; 00048 } 00049 00050 //! destruction de l'objet requete. 00051 int releaseGLResource( ) 00052 { 00053 return (m_names != NULL) ? 0 : -1; 00054 } 00055 00056 //! renvoie le nom opengl d'une requete. 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 //! debut de la requete, remise a 0 du compteur associe. 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 //! fin de la requete. le resultat n'est pas necessairement disponible, cf. isAvailable(). 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 //! determine si le resultat de la requete est disponible. 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 //! renvoie vrai si le resultat est code sur 64 bits. 00106 int is64bits( ) 00107 { 00108 if(m_names == NULL) 00109 return -1; 00110 return (m_bits_n == 64) ? 1 : 0; 00111 } 00112 00113 //! renvoie le resultat de la requete (sur 32 bits), attends le resultat, s'il n'est pas disponible. 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 //! renvoie le resultat de la requete (sur 64 bits), attends le resultat, s'il n'est pas disponible. 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 //! nombre de primitives emises en sortie du vertex shader, ou du geometry shader, s'il existe. 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 //! nombre de primitives ecrites dans les feedback buffers. 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