[docs]classQuery:""" A query object to perform low level measurements of OpenGL rendering calls. The best way to create a program instance is through :py:meth:`arcade.gl.Context.query` Example usage:: query = ctx.query() with query: geometry.render(..) print('samples_passed:', query.samples_passed) print('time_elapsed:', query.time_elapsed) print('primitives_generated:', query.primitives_generated) """__slots__=("_ctx","_glo_samples_passed","_glo_time_elapsed","_glo_primitives_generated","__weakref__","_samples_enabled","_time_enabled","_primitives_enabled","_samples","_time","_primitives",)def__init__(self,ctx:"Context",samples=True,time=True,primitives=True):# TODO: Support querying a subset of these queries (faster)# TODO: Evalute of this query should be included# gl.GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN# gl.GL_ANY_SAMPLES_PASSEDself._ctx=ctxself._samples_enabled=samplesself._time_enabled=timeself._primitives_enabled=primitivesself._samples=0self._time=0self._primitives=0glos=[]self._glo_samples_passed=glo_samples_passed=gl.GLuint()ifself._samples_enabled:gl.glGenQueries(1,self._glo_samples_passed)glos.append(glo_samples_passed)self._glo_time_elapsed=glo_time_elapsed=gl.GLuint()ifself._time_enabled:gl.glGenQueries(1,self._glo_time_elapsed)glos.append(glo_time_elapsed)self._glo_primitives_generated=glo_primitives_generated=gl.GLuint()ifself._primitives_enabled:gl.glGenQueries(1,self._glo_primitives_generated)glos.append(glo_primitives_generated)self.ctx.stats.incr("query")ifself._ctx.gc_mode=="auto":weakref.finalize(self,Query.delete_glo,self._ctx,glos)def__del__(self):ifself._ctx.gc_mode=="context_gc":self._ctx.objects.append(self)@propertydefctx(self)->"Context":""" The context this query object belongs to :type: :py:class:`arcade.gl.Context` """returnself._ctx@propertydefsamples_passed(self)->int:""" How many samples was written. These are per component (RGBA) :type: int """returnself._samples@propertydeftime_elapsed(self)->int:""" The time elapsed in nanoseconds :type: int """returnself._time@propertydefprimitives_generated(self)->int:""" How many primitives a vertex or geometry shader processed. When using a geometry shader this only counts the primitives actually emitted. :type: int """returnself._primitivesdef__enter__(self):ifself._ctx.gl_api=="gl":ifself._samples_enabled:gl.glBeginQuery(gl.GL_SAMPLES_PASSED,self._glo_samples_passed)ifself._time_enabled:gl.glBeginQuery(gl.GL_TIME_ELAPSED,self._glo_time_elapsed)ifself._primitives_enabled:gl.glBeginQuery(gl.GL_PRIMITIVES_GENERATED,self._glo_primitives_generated)def__exit__(self,exc_type,exc_val,exc_tb):ifself._ctx.gl_api=="gl":ifself._samples_enabled:gl.glEndQuery(gl.GL_SAMPLES_PASSED)value=gl.GLint()gl.glGetQueryObjectiv(self._glo_samples_passed,gl.GL_QUERY_RESULT,value)self._samples=value.valueifself._time_enabled:gl.glEndQuery(gl.GL_TIME_ELAPSED)value=gl.GLint()gl.glGetQueryObjectiv(self._glo_time_elapsed,gl.GL_QUERY_RESULT,value)self._time=value.valueifself._primitives_enabled:gl.glEndQuery(gl.GL_PRIMITIVES_GENERATED)value=gl.GLint()gl.glGetQueryObjectiv(self._glo_primitives_generated,gl.GL_QUERY_RESULT,value)self._primitives=value.value
[docs]defdelete(self):""" Destroy the underlying OpenGL resource. Don't use this unless you know exactly what you are doing. """Query.delete_glo(self._ctx,[self._glo_samples_passed,self._glo_time_elapsed,self._glo_primitives_generated,])
[docs]@staticmethoddefdelete_glo(ctx,glos)->None:""" Delete this query object. This is automatically called when the object is garbage collected. """ifgl.current_contextisNone:returnforgloinglos:gl.glDeleteQueries(1,glo)ctx.stats.decr("query")