Query#
- class Query#
Returned by
Context.query()
This class represents a Query object.
Attributes#
- Query.samples: int#
The number of samples passed.
- Query.primitives: int#
The number of primitives generated.
- Query.elapsed: int#
The time elapsed in nanoseconds.
- Query.crender: ConditionalRender#
- Query.extra: Any#
User defined data.
Examples#
Simple query example
1import moderngl
2import numpy as np
3
4ctx = moderngl.create_standalone_context()
5prog = ctx.program(
6 vertex_shader='''
7 #version 330
8
9 in vec2 in_vert;
10
11 void main() {
12 gl_Position = vec4(in_vert, 0.0, 1.0);
13 }
14 ''',
15 fragment_shader='''
16 #version 330
17
18 out vec4 color;
19
20 void main() {
21 color = vec4(1.0, 0.0, 0.0, 1.0);
22 }
23 ''',
24)
25
26vertices = np.array([
27 0.0, 0.0,
28 1.0, 0.0,
29 0.0, 1.0,
30], dtype='f4')
31
32vbo = ctx.buffer(vertices.tobytes())
33vao = ctx.simple_vertex_array(prog, vbo, 'in_vert')
34
35fbo = ctx.simple_framebuffer((64, 64))
36fbo.use()
37
38query = ctx.query(samples=True, time=True)
39
40with query:
41 vao.render()
42
43print('It took %d nanoseconds' % query.elapsed)
44print('to render %d samples' % query.samples)
Output
It took 13529 nanoseconds
to render 496 samples