picogl.backend.gl.api

This module provides bindings and utilities for interacting with OpenGL buffers, vertex arrays, texture, client states, and draw operations. These functions facilitate working with OpenGL through abstractions and are commonly utilized in graphics programming for setting up and rendering graphics pipelines.

Exports a variety of OpenGL utility functions, including buffer operations, vertex and texture handling, and client state management.

Submodules

Functions

gl_buffer_data([target, size, data, usage_hint])

gl bind buffer

gl_generate_buffers([num]) → Any

Generate buffer object names.

gl_upload_float_buffer(data[, buffer_target]) → None

Upload float vertex/attribute data to the bound buffer.

gl_upload_ushort_buffer(data[, buffer_target]) → None

Upload unsigned-short index data to the bound element buffer.

gl_disable_legacy_client_state(state) → None

gl disable client state

gl_enable_legacy_client_state(state) → None

gl legacy client state

gl_draw_arrays(index_count, mode[, first]) → None

Issue glDrawArrays with PicoGL draw-mode enums or raw gl constants.

gl_draw_arrays_spec(spec)

gl draw arrays from spec

gl_draw_elements(index_count[, dtype, mode, pointer, ...]) → None

Issue glDrawElements.

gl_draw_elements_spec(spec)

gl draw elements from spec

gl_bind_elements(index_buffer, size) → None

Bind ELEMENT buffer and draw triangles (ushort indices).

gl_flush() → None

Flush the OpenGL command pipeline.

gl_color_array_pointer(pointer[, size, num_type, stride])

gl color pointer for mesh binding.

gl_color_pointer_from_spec(attr)

gl color pointer

gl_normal_array_pointer(pointer[, stride, num_type])

gl normal pointer for mesh binding.

gl_normal_pointer_from_spec(attr)

gl normal pointer

gl_texcoord_array_pointer(pointer[, size, stride, ...])

gl texcoord pointer for mesh binding.

gl_vertex_array_pointer(pointer[, size, num_type, stride])

gl vertex pointer for mesh binding.

gl_vertex_pointer_from_spec(attr)

gl legacy client state

gl_bind_vertex_array(vao) → None

Binds a vertex array object (VAO) in OpenGL.

gl_bind_array_buffer(buffer[, index, size, stride]) → None

Bind an ARRAY buffer and set its vertex attrib pointer.

gl_bound_vertex_attrib_arrays(vertex_attrib_arrays) → collections.abc.Iterator[None]

Enable vertex attrib arrays for the block, then disable them.

gl_vertex_attrib_pointer(index, size[, num_type, ...]) → None

Issue glVertexAttribPointer.

gl_enable_vertex_array(location) → Any

gl_enable_vertex_array

gl_generate_vertex_array([num]) → Any

gl_generate_vertex_array

gl_normal_3f(x, y, z) → None

Set the current normal vector.

gl_vertex_3f(x, y, z) → None

vertex 3f

gl_vertex_coord(coord) → None

gl vertex coord

gl_vertex_line(coord_end, coord_start) → None

Emit a GL_LINES segment from start to end.

gl_bind_buffer(target, vbo_id)

Binds a buffer object to a specified binding point in the OpenGL context.

gl_get_integerv(val) → Any

get integer value

gl_active_texture(texture) → None

Issue glActiveTexture.

gl_get_active_texture0() → None

Select texture unit 0.

gl_bind_texture(tex_id[, target]) → None

Issue glBindTexture.

gl_gen_textures([number]) → int

Issue glGenTextures.

gl_compressed_tex_image(byte_array, gl_format, height, ...) → None

Issue glCompressedTexImage2D for a 2D texture.

gl_teximage2d(target, level, internalformat, width, ...) → None

Issue glTexImage2D.

gl_teximage3d(target, level, internalformat, width, ...) → None

Issue glTexImage3D.

gl_generate_mipmap([target]) → None

Generate mipmaps for the currently bound texture.

gl_tex_parameter(target, pname, param) → None

Issue glTexParameteri.

Package Contents

picogl.backend.gl.api.gl_buffer_data(target: picogl.backend.gl.enums.GLBufferTarget = GLBufferTarget.ARRAY, size: int = 0, data=None, usage_hint: picogl.backend.gl.enums.GLUsageHint = GLUsageHint.STATIC_DRAW)[source]

gl bind buffer

picogl.backend.gl.api.gl_generate_buffers(num: int = 1) → Any[source]

Generate buffer object names.

A request for one name returns a Python int. glGenBuffers(1) otherwise returns a length-1 array, which glIsBuffer does not accept as a buffer name.

Parameters:

num – How many names to generate

Returns:

One buffer name, or the array of names when num is greater than 1

picogl.backend.gl.api.gl_upload_float_buffer(data: list[float], buffer_target: picogl.backend.gl.enums.GLBufferTarget = GLBufferTarget.ARRAY) → None[source]

Upload float vertex/attribute data to the bound buffer.

picogl.backend.gl.api.gl_upload_ushort_buffer(data: list[int], buffer_target: picogl.backend.gl.enums.GLBufferTarget = GLBufferTarget.ELEMENT) → None[source]

Upload unsigned-short index data to the bound element buffer.

picogl.backend.gl.api.gl_disable_legacy_client_state(state: picogl.backend.gl.state.client.GLClientState) → None[source]

gl disable client state

picogl.backend.gl.api.gl_enable_legacy_client_state(state: picogl.backend.gl.state.client.GLClientState) → None[source]

gl legacy client state

picogl.backend.gl.api.gl_draw_arrays(index_count: int, mode: picogl.backend.gl.enums.GLDrawMode | int, first: int = 0) → None[source]

Issue glDrawArrays with PicoGL draw-mode enums or raw gl constants.

picogl.backend.gl.api.gl_draw_arrays_spec(spec: picogl.backend.modern.core.vertex.array.draw_spec.DrawSpec)[source]

gl draw arrays from spec

picogl.backend.gl.api.gl_draw_elements(index_count: int, dtype: int | None = GLIndexType.UNSIGNED_INT, mode: picogl.backend.gl.enums.GLDrawMode | int | None = GLDrawMode.TRIANGLES, pointer: Any | None = None, offset: int = 0) → None[source]

Issue glDrawElements.

pointer may be a client index array, None (EBO bound), or omitted to use offset.

picogl.backend.gl.api.gl_draw_elements_spec(spec: picogl.backend.modern.core.vertex.array.draw_spec.DrawSpec)[source]

gl draw elements from spec

picogl.backend.gl.api.gl_bind_elements(index_buffer, size: int) → None[source]

Bind ELEMENT buffer and draw triangles (ushort indices).

picogl.backend.gl.api.gl_flush() → None[source]

Flush the OpenGL command pipeline.

picogl.backend.gl.api.gl_color_array_pointer(pointer: numpy.ndarray, size: int = 4, num_type: picogl.backend.gl.enums.GLNumeric = GLNumeric.FLOAT, stride: int = 0)[source]

gl color pointer for mesh binding.

picogl.backend.gl.api.gl_color_pointer_from_spec(attr: picogl.gpu.buffers.attributes.AttributeSpec)[source]

gl color pointer

picogl.backend.gl.api.gl_normal_array_pointer(pointer: numpy.ndarray, stride: int = 0, num_type: picogl.backend.gl.enums.GLNumeric = GLNumeric.FLOAT)[source]

gl normal pointer for mesh binding.

picogl.backend.gl.api.gl_normal_pointer_from_spec(attr: picogl.gpu.buffers.attributes.AttributeSpec)[source]

gl normal pointer

picogl.backend.gl.api.gl_texcoord_array_pointer(pointer: numpy.ndarray, size: int = 2, stride: int = 0, num_type: picogl.backend.gl.enums.GLNumeric = GLNumeric.FLOAT)[source]

gl texcoord pointer for mesh binding.

picogl.backend.gl.api.gl_vertex_array_pointer(pointer: numpy.ndarray | int, size: int = 3, num_type: picogl.backend.gl.enums.GLNumeric = GLNumeric.FLOAT, stride: int = 0)[source]

gl vertex pointer for mesh binding.

picogl.backend.gl.api.gl_vertex_pointer_from_spec(attr: picogl.gpu.buffers.attributes.AttributeSpec)[source]

gl legacy client state

picogl.backend.gl.api.gl_bind_vertex_array(vao: int) → None[source]

Binds a vertex array object (VAO) in OpenGL.

This function wraps the OpenGL glBindVertexArray function to bind a specific VAO for subsequent OpenGL operations.

Parameters: vao: int

The ID of the vertex array object to bind. Must not be None and must be a non-negative integer.

picogl.backend.gl.api.gl_bind_array_buffer(buffer, index: int = 0, size: int = 3, stride: int = 0) → None[source]

Bind an ARRAY buffer and set its vertex attrib pointer.

picogl.backend.gl.api.gl_bound_vertex_attrib_arrays(vertex_attrib_arrays: list[int]) → collections.abc.Iterator[None][source]

Enable vertex attrib arrays for the block, then disable them.

picogl.backend.gl.api.gl_vertex_attrib_pointer(index: int, size: int, num_type: picogl.backend.gl.enums.GLNumeric = GLNumeric.FLOAT, normalized: picogl.boolean.GLBoolean = GLBoolean.FALSE, stride: int = 0, offset: Any | None = None) → None[source]

Issue glVertexAttribPointer.

offset may be a byte offset (int), None, or a ctypes.c_void_p.

picogl.backend.gl.api.gl_enable_vertex_array(location: int) → Any[source]

gl_enable_vertex_array

Parameters:

location – int

picogl.backend.gl.api.gl_generate_vertex_array(num: int = 1) → Any[source]

gl_generate_vertex_array

Parameters:

num – int

picogl.backend.gl.api.gl_normal_3f(x: float, y: float, z: float) → None[source]

Set the current normal vector.

picogl.backend.gl.api.gl_vertex_3f(x: float, y: float, z: float) → None[source]

vertex 3f

picogl.backend.gl.api.gl_vertex_coord(coord: molib.pdb.coordinate.coordinate.Coordinate3D) → None[source]

gl vertex coord

picogl.backend.gl.api.gl_vertex_line(coord_end: molib.pdb.coordinate.coordinate.Coordinate3D, coord_start: molib.pdb.coordinate.coordinate.Coordinate3D) → None[source]

Emit a GL_LINES segment from start to end.

picogl.backend.gl.api.gl_bind_buffer(target: int, vbo_id: int | None)[source]

Binds a buffer object to a specified binding point in the OpenGL context.

This function wraps the OpenGL glBindBuffer call, which is used to bind a buffer object to the specified target. Once bound, the buffer becomes the active buffer for the target, allowing subsequent OpenGL commands to operate on it.

Parameters: target : int

The target to which the buffer is to be bound. Common examples include GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER, etc.

ebo_idint or None

The name (ID) of the buffer object to bind. If None is provided, the target will be unbound, and no buffer will be associated with it.

picogl.backend.gl.api.gl_get_integerv(val) → Any[source]

get integer value

picogl.backend.gl.api.gl_active_texture(texture: int | picogl.texture.gltexture.GLTexture) → None[source]

Issue glActiveTexture.

picogl.backend.gl.api.gl_get_active_texture0() → None[source]

Select texture unit 0.

picogl.backend.gl.api.gl_bind_texture(tex_id: int, target: picogl.texture.gltexture.GLTexture = GLTexture.TEXTURE_2D) → None[source]

Issue glBindTexture.

picogl.backend.gl.api.gl_gen_textures(number: int = 1) → int[source]

Issue glGenTextures.

picogl.backend.gl.api.gl_compressed_tex_image(byte_array: CompressedTexData, gl_format: OpenGL.constant.FloatConstant | OpenGL.constant.IntConstant | OpenGL.constant.LongConstant | OpenGL.constant.StringConstant | OpenGL.constant.Constant, height: int, level: int, size: int, width: int) → None[source]

Issue glCompressedTexImage2D for a 2D texture.

PyOpenGL’s wrapped glCompressedTexImage2D omits imageSize and derives it from data. Passing an explicit size as the 7th argument makes PyOpenGL treat that int as the data pointer and raises NumberHandler / arrayByteCount.

picogl.backend.gl.api.gl_teximage2d(target: int, level: int, internalformat: OpenGL.constant.FloatConstant | OpenGL.constant.IntConstant | OpenGL.constant.LongConstant | OpenGL.constant.StringConstant | OpenGL.constant.Constant, width: int, height: int, border: int, format: OpenGL.constant.FloatConstant | OpenGL.constant.IntConstant | OpenGL.constant.LongConstant | OpenGL.constant.StringConstant | OpenGL.constant.Constant, num_type: int = GLNumeric.UNSIGNED_BYTE, data: bytes | numpy.ndarray | None = None) → None[source]

Issue glTexImage2D.

picogl.backend.gl.api.gl_teximage3d(target: int, level: int, internalformat: OpenGL.constant.FloatConstant | OpenGL.constant.IntConstant | OpenGL.constant.LongConstant | OpenGL.constant.StringConstant | OpenGL.constant.Constant, width: int, height: int, depth: int, border: int, format: OpenGL.constant.FloatConstant | OpenGL.constant.IntConstant | OpenGL.constant.LongConstant | OpenGL.constant.StringConstant | OpenGL.constant.Constant, num_type: int, data: bytes | numpy.ndarray | None = None) → None[source]

Issue glTexImage3D.

picogl.backend.gl.api.gl_generate_mipmap(target: picogl.texture.gltexture.GLTexture = GLTexture.TEXTURE_2D) → None[source]

Generate mipmaps for the currently bound texture.

picogl.backend.gl.api.gl_tex_parameter(target: int, pname: picogl.texture.gltexture.GLTexture, param: picogl.texture.gltexparam.GLTexParam | picogl.core.texture_clamp.GLTextureClamp) → None[source]

Issue glTexParameteri.