Geometry#

Geometry Methods#

arcade.gl.geometry.quad_2d_fs() Geometry[source]#

Creates a screen aligned quad using normalized device coordinates

arcade.gl.geometry.quad_2d(size: Tuple[float, float] = (1.0, 1.0), pos: Tuple[float, float] = (0.0, 0.0)) Geometry[source]#

Creates 2D quad Geometry using 2 triangle strip with texture coordinates.

Parameters:
  • size (tuple) – width and height

  • pos (float) – Center position x and y

Return type:

A Geometry instance.

arcade.gl.geometry.screen_rectangle(bottom_left_x: float, bottom_left_y: float, width: float, height: float) Geometry[source]#

Creates screen rectangle using 2 triangle strip with texture coordinates.

Parameters:
  • bottom_left_x (float) – Bottom left x position

  • bottom_left_y (float) – Bottom left y position

  • width (float) – Width of the rectangle

  • height (float) – Height of the rectangle

arcade.gl.geometry.cube(size: Tuple[float, float, float] = (1.0, 1.0, 1.0), center: Tuple[float, float, float] = (0.0, 0.0, 0.0)) Geometry[source]#

Creates a cube with normals and texture coordinates.

Parameters:
  • size (tuple) – size of the cube as a 3-component tuple

  • center (tuple) – center of the cube as a 3-component tuple

Return type:

arcade.gl.Geometry

Returns:

A cube

Geometry#

class arcade.gl.Geometry(ctx: Context, content: Optional[Sequence[BufferDescription]], index_buffer: Optional[Buffer] = None, mode: int = None, index_element_size: int = 4)[source]#

Bases: object

A higher level abstraction of the VertexArray. It generates VertexArray instances on the fly internally matching the incoming program. This means we can render the same geometry with different programs as long as the Program and BufferDescription have compatible attributes.

Geometry objects should be created through arcade.gl.Context.geometry()

Parameters:
  • ctx (Context) – The context this object belongs to

  • content (list) – List of BufferDescriptions

  • index_buffer (Buffer) – Index/element buffer

  • mode (int) – The default draw mode

property ctx: Context#

The context this geometry belongs to.

Type:

Geometry

property index_buffer: Optional[Buffer]#

Index/element buffer if supplied at creation.

Type:

Buffer

property num_vertices: int#

Get or set the number of vertices. Be careful when modifying this properly and be absolutely sure what you are doing.

Type:

int

instance(program: Program) VertexArray[source]#

Get the arcade.gl.VertexArray compatible with this program

render(program: Program, *, mode: Optional[c_uint] = None, first: int = 0, vertices: Optional[int] = None, instances: int = 1) None[source]#

Render the geometry with a specific program.

The geometry object will know how many vertices your buffers contains so overriding vertices is not needed unless you have a special case or have resized the buffers after the geometry instance was created.

Parameters:
  • program (Program) – The Program to render with

  • mode (gl.GLenum) – Override what primitive mode should be used

  • first (int) – Offset start vertex

  • vertices (int) – Override the number of vertices to render

  • instances (int) – Number of instances to render

render_indirect(program: Program, buffer: Buffer, *, mode: Optional[c_uint] = None, count: int = -1, first: int = 0, stride: int = 0)[source]#

Render the VertexArray to the framebuffer using indirect rendering.

Warning

This requires OpenGL 4.3

The following structs are expected for the buffer:

// Array rendering - no index buffer (16 bytes)
typedef  struct {
    uint  count;
    uint  instanceCount;
    uint  first;
    uint  baseInstance;
} DrawArraysIndirectCommand;

// Index rendering - with index buffer 20 bytes
typedef  struct {
    GLuint  count;
    GLuint  instanceCount;
    GLuint  firstIndex;
    GLuint  baseVertex;
    GLuint  baseInstance;
} DrawElementsIndirectCommand;

The stride is the byte stride between every redering command in the buffer. By default we assume this is 16 for array rendering (no index buffer) and 20 for indexed rendering (with index buffer)

Parameters:
  • program (Program) – The program to execute

  • buffer (Buffer) – The buffer containing one or multiple draw parameters

  • mode (GLuint) – Primitive type to render. TRIANGLES, LINES etc.

  • count (int) – The number if indirect draw calls to run. If omitted all draw commands in the buffer will be executed.

  • first (int) – The first indirect draw call to start on

  • stride (int) – The byte stride of the draw command buffer. Keep the default (0) if the buffer is tightly packed.

transform(program: Program, buffer: Union[Buffer, List[Buffer]], *, first: int = 0, vertices: Optional[int] = None, instances: int = 1, buffer_offset: int = 0) None[source]#

Render with transform feedback. Instead of rendering to the screen or a framebuffer the result will instead end up in the buffer we supply.

If a geometry shader is used the output primitive mode is automatically detected.

Parameters:
  • program (Program) – The Program to render with

  • buffer (Union[Buffer, Sequence[Buffer]]) – The buffer(s) we transform into. This depends on the programs varyings_capture_mode. We can transform into one buffer interlaved or transform each attribute into separate buffers.

  • first (int) – Offset start vertex

  • vertices (int) – Number of vertices to render

  • instances (int) – Number of instances to render

  • buffer_offset (int) – Byte offset for the buffer

flush() None[source]#

Flush all the internally generated VertexArrays.

The Geometry instance will store a VertexArray for every unique set of input attributes it stumbles over when redering and transform calls are issued. This data is usually pretty light weight and usually don’t need flushing.

VertexArray#

class arcade.gl.VertexArray(ctx: Context, program: Program, content: Sequence[BufferDescription], index_buffer: Buffer = None, index_element_size: int = 4)[source]#

Bases: object

Wrapper for Vertex Array Objects (VAOs).

This objects should not be instantiated from user code. Use arcade.gl.Geometry instead. It will create VAO instances for you automatically. There is a lot of complex interaction between programs and vertex arrays that will be done for you automatically.

property ctx: Context#

The Context this object belongs to

Type:

arcade.gl.Context

property program: Program#

The assigned program

Type:

arcade.gl.Program

property ibo: Optional[Buffer]#

Element/index buffer

Type:

arcade.gl.Buffer

property num_vertices: int#

The number of vertices

Type:

int

delete()[source]#

Destroy the underlying OpenGL resource. Don’t use this unless you know exactly what you are doing.

static delete_glo(ctx: Context, glo: c_uint)[source]#

Delete this object. This is automatically called when this object is garbage collected.

render(mode: c_uint, first: int = 0, vertices: int = 0, instances: int = 1)[source]#

Render the VertexArray to the currently active framebuffer.

Parameters:
  • mode (GLuint) – Primitive type to render. TRIANGLES, LINES etc.

  • first (int) – The first vertex to render from

  • vertices (int) – Number of vertices to render

  • instances (int) – OpenGL instance, used in using vertices over and over

render_indirect(buffer: Buffer, mode: c_uint, count, first, stride)[source]#

Render the VertexArray to the framebuffer using indirect rendering.

Warning

This requires OpenGL 4.3

Parameters:
  • buffer (Buffer) – The buffer containing one or multiple draw parameters

  • mode (GLuint) – Primitive type to render. TRIANGLES, LINES etc.

  • count (int) – The number if indirect draw calls to run

  • first (int) – The first indirect draw call to start on

  • stride (int) – The byte stride of the draw command buffer. Keep the default (0) if the buffer is tightly packed.

transform_interleaved(buffer: Buffer, mode: c_uint, output_mode: c_uint, first: int = 0, vertices: int = 0, instances: int = 1, buffer_offset=0)[source]#

Run a transform feedback.

Parameters:
  • buffer (Buffer) – The buffer to write the output

  • mode (gl.GLenum) – The input primitive mode

  • output_mode (gl.GLenum) – The output primitive mode

  • first (int) – Offset start vertex

  • vertices (int) – Number of vertices to render

  • instances (int) – Number of instances to render

  • buffer_offset (int) – Byte offset for the buffer (target)

transform_separate(buffers: List[Buffer], mode: c_uint, output_mode: c_uint, first: int = 0, vertices: int = 0, instances: int = 1, buffer_offset=0)[source]#
glo#