voxel_engine/mesh/base.py
2023-10-19 12:59:58 +02:00

32 lines
No EOL
827 B
Python

#!/usr/bin/python3
import numpy
class BaseMesh:
def __init__(self):
# OpenGL context
self.ctx = None
# shader program
self.program = None
# vertex buffer data type format: "3f 3f"
self.vbo_format = None
# attribute names according to the format: ("in_position", "in_color")
self.attributes: tuple[str, ...] = None
# vertex array object
self.vao = None
def get_vertex_data(self) -> numpy.array: ...
def get_vao(self):
vertex_data = self.get_vertex_data()
vbo = self.ctx.buffer(vertex_data)
vao = self.ctx.vertex_array(
self.program,
[(vbo, self.vbo_format, *self.attributes)],
skip_errors=True
)
return vao
def render(self):
self.vao.render()