Skip to content

Commit 4f8191a

Browse files
committed
geometry module should not access context
1 parent 3b3f9df commit 4f8191a

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

demosys/geometry/bbox.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import moderngl
21
import numpy
32

3+
import moderngl
44
from demosys.opengl import VAO
55

66

demosys/geometry/points.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import random
2+
3+
import numpy
4+
15
import moderngl
26
from demosys.opengl import VAO
3-
import numpy
4-
import random
57

68

79
def points_random_3d(count, range_x=(-10.0, 10.0), range_y=(-10.0, 10.0), range_z=(-10.0, 10.0), seed=None) -> VAO:

demosys/geometry/quad.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import moderngl
21
import numpy
2+
3+
import moderngl
34
from demosys.opengl import VAO
4-
from demosys import context
55

66
# Cache fullscreen quad
77
QUAD_FS = None
@@ -26,32 +26,32 @@ def quad_2d(width, height, xpos=0.0, ypos=0.0) -> VAO:
2626
:param xpos: Center position x
2727
:param ypos: Center position y
2828
"""
29-
pos = context.ctx().buffer(numpy.array([
29+
pos = numpy.array([
3030
xpos - width / 2.0, ypos + height / 2.0, 0.0,
3131
xpos - width / 2.0, ypos - height / 2.0, 0.0,
3232
xpos + width / 2.0, ypos - height / 2.0, 0.0,
3333
xpos - width / 2.0, ypos + height / 2.0, 0.0,
3434
xpos + width / 2.0, ypos - height / 2.0, 0.0,
3535
xpos + width / 2.0, ypos + height / 2.0, 0.0,
36-
], dtype=numpy.float32).tobytes())
36+
], dtype=numpy.float32)
3737

38-
normals = context.ctx().buffer(numpy.array([
38+
normals = numpy.array([
3939
0.0, 0.0, 1.0,
4040
0.0, 0.0, 1.0,
4141
0.0, 0.0, 1.0,
4242
0.0, 0.0, 1.0,
4343
0.0, 0.0, 1.0,
4444
0.0, 0.0, 1.0,
45-
], dtype=numpy.float32).tobytes())
45+
], dtype=numpy.float32)
4646

47-
uvs = context.ctx().buffer(numpy.array([
47+
uvs = numpy.array([
4848
0.0, 1.0,
4949
0.0, 0.0,
5050
1.0, 0.0,
5151
0.0, 1.0,
5252
1.0, 0.0,
5353
1.0, 1.0,
54-
], dtype=numpy.float32).tobytes())
54+
], dtype=numpy.float32)
5555

5656
vao = VAO("geometry:quad", mode=moderngl.TRIANGLES)
5757
vao.buffer(pos, '3f', ["in_position"])

demosys/geometry/sphere.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import math
2-
import moderngl as mlg
2+
33
import numpy
44

5-
from demosys import context
5+
import moderngl as mlg
66
from demosys.opengl import VAO
77

88

@@ -57,10 +57,10 @@ def sphere(radius=0.5, sectors=32, rings=16) -> VAO:
5757
indices[i + 5] = (r + 1) * sectors + (s + 1)
5858
i += 6
5959

60-
vbo_vertices = context.ctx().buffer(numpy.array(vertices, dtype=numpy.float32).tobytes())
61-
vbo_normals = context.ctx().buffer(numpy.array(normals, dtype=numpy.float32).tobytes())
62-
vbo_uvs = context.ctx().buffer(numpy.array(uvs, dtype=numpy.float32).tobytes())
63-
vbo_elements = context.ctx().buffer(numpy.array(indices, dtype=numpy.uint32).tobytes())
60+
vbo_vertices = numpy.array(vertices, dtype=numpy.float32)
61+
vbo_normals = numpy.array(normals, dtype=numpy.float32)
62+
vbo_uvs = numpy.array(uvs, dtype=numpy.float32)
63+
vbo_elements = numpy.array(indices, dtype=numpy.uint32)
6464

6565
vao = VAO("sphere", mode=mlg.TRIANGLES)
6666
# VBOs

0 commit comments

Comments
 (0)