demosys.opengl.vao.VAO¶
-
class
demosys.opengl.vao.VAO(name='', mode=4)¶ Represents a vertex array object. This is a wrapper class over
moderngl.VertexArrayto provide helper method.The main purpose is to provide render methods taking a program as parameter. The class will auto detect the programs attributes and add padding when needed to match the vertex object. A new vertexbuffer object is created and stored internally for each unique shader program used.
A secondary purpose is to provide an alternate way to build vertexbuffers This can be practical when loading or creating various geometry.
There is no requirements to use this class, but most methods in the system creating vertexbuffers will return this type. You can obtain a single vertexbuffer instance by calling
VAO.instance()method if you prefer to work directly on moderngl instances.
Create¶
-
VAO.__init__(name='', mode=4)¶ Create and empty VAO
Keyword Arguments: - name (str) – The name for debug purposes
- mode (int) – Default draw mode
-
VAO.buffer(buffer, buffer_format: str, attribute_names, per_instance=False)¶ Register a buffer/vbo for the VAO. This can be called multiple times. adding multiple buffers (interleaved or not)
Parameters: - buffer – The buffer data. Can be
numpy.array,moderngl.Bufferorbytes. - buffer_format (str) – The format of the buffer. (eg.
3f 3ffor interleaved positions and normals). - attribute_names – A list of attribute names this buffer should map to.
Keyword Arguments: per_instance (bool) – Is this buffer per instance data for instanced rendering?
Returns: The
moderngl.Bufferinstance object. This is handy when providingbytesandnumpy.array.- buffer – The buffer data. Can be
-
VAO.index_buffer(buffer, index_element_size=4)¶ Set the index buffer for this VAO
Parameters: buffer – moderngl.Buffer,numpy.arrayorbytesKeyword Arguments: index_element_size (int) – Byte size of each element. 1, 2 or 4
Render Methods¶
-
VAO.render(program: moderngl.program.Program, mode=None, vertices=-1, first=0, instances=1)¶ Render the VAO.
Parameters: program – The
moderngl.ProgramKeyword Arguments: - mode – Override the draw mode (
TRIANGLESetc) - vertices (int) – The number of vertices to transform
- first (int) – The index of the first vertex to start with
- instances (int) – The number of instances
- mode – Override the draw mode (
-
VAO.render_indirect(program: moderngl.program.Program, buffer, mode=None, count=-1, *, first=0)¶ The render primitive (mode) must be the same as the input primitive of the GeometryShader. The draw commands are 5 integers: (count, instanceCount, firstIndex, baseVertex, baseInstance).
Parameters: - program – The
moderngl.Program - buffer – The
moderngl.Buffercontaining indirect draw commands
Keyword Arguments: - mode (int) – By default
TRIANGLESwill be used. - count (int) – The number of draws.
- first (int) – The index of the first indirect draw command.
- program – The
-
VAO.transform(program: moderngl.program.Program, buffer: moderngl.buffer.Buffer, mode=None, vertices=-1, first=0, instances=1)¶ Transform vertices. Stores the output in a single buffer.
Parameters: - program – The
moderngl.Program - buffer – The
moderngl.bufferto store the output
Keyword Arguments: - mode – Draw mode (for example
moderngl.POINTS) - vertices (int) – The number of vertices to transform
- first (int) – The index of the first vertex to start with
- instances (int) – The number of instances
- program – The
Other Methods¶
-
VAO.instance(program:Program) → VertexArray¶ Obtain the
moderngl.VertexArrayinstance for the program. The instance is only created once and cached internally.Returns:
moderngl.VertexArrayinstance
-
VAO.release(buffer=True)¶ Destroy the vao object
Keyword Arguments: buffers (bool) – also release buffers