API Reference

This module is exposing a part of the WebGL2 context. Is is assumed that you are familiar with the concepts and commands. You can find more information about it here : https://webgl2fundamentals.org/

There is some major differences still :

  • All the WebGL2 commands are called on the GLViewer instead of a gl context.

  • All the API is written in snake_case instead of camelCase, so for example gl.drawArrays(...) in JavaScript becomes widget.draw_arrays(...) in Python

  • Masks parameters are replace by positional attribute, so for example gl.clear(gl.DEPTH_BUFFER_BIT | gl.COLOR_BUFFER_BIT); in JavaScript becomes widget.clear(depth_buffer_bit=True, color_buffer_bit=True) in Python

  • Enums are replaced by strings, so for example gl.bufferData(gl.ARRAY_BUFFER, data, gl.DYNAMIC_DRAW); in JavaScript becomes widget.buffer_data("array_buffer", data, "dynamic_draw") in Python

All the commands you call on the GLViewer are push to a commands buffer. That commands buffer is only flushed when you call the execute_commands() method.

class ipywebgl.glviewer.GLViewer(**kwargs: Any)[source]

The main widget of the module.

This widget is in charge of creating the canvas, the webgl context and all the opengl resources you will need.

It also manage the mouse and keyboard interaction with the widget to move the camera around. For the camera to work, by default the viewer will update the uniform mat4 ViewProjection if you have defined it in your shader code.

All OpenGL commands are sent through this widget.

All the commands you call will be stacked on a commands buffer that will be sent only when you call the render method.

width

the width of the canvas. Defaults to 640.

Type

int

height

the height of the canvas. Defaults to 480.

Type

int

camera_pos

the camera position in the scene. Defaults to [0,50,200].

Type

[float, float, float]

camera_yaw

the camera yaw angle in degree. Defaults to 0.

Type

float

camera_pitch

the camera pitch angle in degree. Defaults to 0.

Type

float

camera_fov

the camera field of view in degree. Defaults to 50.

Type

float

camera_near

the camera near plane distance. Defaults to 1.

Type

float

camera_far

the camera far plane distance. Defaults to 5000.

Type

float

mouse_speed

mouse speed (camera rotation speed). Defaults to 1.

Type

float

move_speed

move speed (camera translation speed). Defaults to 1.

Type

float

move_keys

the move keys as a string. Forward, Left, Back, Right. Defaults to ‘wasd’.

Type

str

shader_matrix_major

the type of matrix (for the ViewProjection for instance) to send to the shader {‘row_major’ or ‘column_major’}. Defaults to ‘row_major’.

Type

str

sync_image_data

do we store the rendered imaged in python. This will significantly slow the rendering. Defaults to False.

Type

bool

image_data

the stored image as bytes. If the sync_image_data is set to True.

Type

bytes

verbose

with verbose set to 1, all the commands executed by the frontend will be logged in the console. Defaults to 0.

Type

int

resource(index)[source]

return the resource used by the viewer

resource_count()[source]

return the number of resources used by the viewer

execute_commands(execute_once=False, clear_previous=True)[source]

Send the commands buffer to the webgl frontend.

When the commands buffer is sent, it will be cleared. You can then start to build a new commands buffer.

By default the command buffers will stay in memory in the frontend, so it can be reexecuted everytime you need to redraw the scene (camera move for instance) If you set the execute_once to True, it will not be stored in the frontend.

Parameters
  • execute_once (bool, optional) – Do we execute this only once. Defaults to False.

  • clear_previous (bool, optional) – Do we replace the current commands or just append?. Defaults to False.

clear_commands()[source]

Clear the commands buffer without sending it to the frontend.

enable(blend=False, cull_face=False, depth_test=False, dither=False, polygon_offset_fill=False, sample_alpha_to_coverage=False, sample_coverage=False, scissor_test=False, stencil_test=False, rasterizer_discard=False)[source]

Append a enable command to the commands buffer

Parameters
  • blend (bool, optional) – Activates blending of the computed fragment color values. Defaults to False.

  • cull_face (bool, optional) – Activates culling of polygons. Defaults to False.

  • depth_test (bool, optional) – Activates depth comparisons and updates to the depth buffer. Defaults to False.

  • dither (bool, optional) – Activates dithering of color components before they get written to the color buffer. Defaults to False.

  • polygon_offset_fill (bool, optional) – Activates adding an offset to depth values of polygon’s fragments. Defaults to False.

  • sample_alpha_to_coverage (bool, optional) – Activates the computation of a temporary coverage value determined by the alpha value. Defaults to False.

  • sample_coverage (bool, optional) – Activates ANDing the fragment’s coverage with the temporary coverage value. Defaults to False.

  • scissor_test (bool, optional) – Activates the scissor test that discards fragments that are outside of the scissor rectangle. Defaults to False.

  • stencil_test (bool, optional) – Activates stencil testing and updates to the stencil buffer. Defaults to False.

  • rasterizer_discard (bool, optional) – Primitives are discarded immediately before the rasterization stage, but after the optional transform feedback stage. Defaults to False.

disable(blend=False, cull_face=False, depth_test=False, dither=False, polygon_offset_fill=False, sample_alpha_to_coverage=False, sample_coverage=False, scissor_test=False, stencil_test=False, rasterizer_discard=False)[source]

Append a disable command to the commands buffer

Parameters
  • blend (bool, optional) – Deactivates blending of the computed fragment color values. Defaults to False.

  • cull_face (bool, optional) – Deactivates culling of polygons. Defaults to False.

  • depth_test (bool, optional) – Deactivates depth comparisons and updates to the depth buffer. Defaults to False.

  • dither (bool, optional) – Deactivates dithering of color components before they get written to the color buffer. Defaults to False.

  • polygon_offset_fill (bool, optional) – Deactivates adding an offset to depth values of polygon’s fragments. Defaults to False.

  • sample_alpha_to_coverage (bool, optional) – Deactivates ates the computation of a temporary coverage value determined by the alpha value. Defaults to False.

  • sample_coverage (bool, optional) – Deactivates ANDing the fragment’s coverage with the temporary coverage value. Defaults to False.

  • scissor_test (bool, optional) – Deactivates the scissor test that discards fragments that are outside of the scissor rectangle. Defaults to False.

  • stencil_test (bool, optional) – Deactivates stencil testing and updates to the stencil buffer. Defaults to False.

  • rasterizer_discard (bool, optional) – Deactivates that primitives are discarded immediately before the rasterization stage, but after the optional transform feedback stage. Defaults to False.

clear_color(r: float, g: float, b: float, a: float)[source]

Append a clearColor command to the commands buffer.

Parameters
  • r (float) – red [0, 1]

  • g (float) – green [0, 1]

  • b (float) – blue [0, 1]

  • a (float) – alpha [0, 1]

clear(color_bit_buffer=True, depth_buffer_bit=True, stencil_buffer_bit=False)[source]

Append a clear command to the commands buffer.

Parameters
  • color_bit_buffer (bool, optional) – clear the depth buffer. Defaults to True.

  • depth_buffer_bit (bool, optional) – clear the color buffer. Defaults to True.

  • stencil_buffer_bit (bool, optional) – clear the stencil buffer. Defaults to False.

cull_face(mode='BACK')[source]

Append a cullFace command to the commands buffer

Polygon culling is disabled by default. To enable or disable culling, use the enable().

Parameters

mode ({'FRONT', 'BACK', 'FRONT_AND_BACK'}, optional) – specifying whether front- or back-facing polygons are candidates for culling. Defaults to ‘BACK’.

front_face(mode='CCW')[source]

Append a frontFace command to the commands buffer

Parameters

mode ({'CW', 'CCW'}, optional) – type winding orientation. Defaults to ‘CCW’.

depth_func(func='LESS')[source]

Append a depthFunc command to the commands buffer

specifying the depth comparison function, which sets the conditions under which the pixel will be drawn.

Parameters

func ({'NEVER', 'LESS', 'EQUAL', 'LEQUAL', 'GREATER', 'NOTEQUAL', 'GEQUAL', 'ALWAYS'}, optional) – Defaults to ‘LESS’.

depth_mask(flag=True)[source]

Append a depthMask command to the commands buffer.

Parameters

flag (bool, optional) – specifying whether or not writing into the depth buffer is enabled. Defaults to True.

depth_range(z_near=0.0, z_far=1.0)[source]

Append a depthRange command to the commands buffer.

Parameters
  • z_near (float, optional) – specifying the mapping of the near clipping plane to window or viewport coordinates. Clamped to the range 0 to 1 and must be less than or equal to z_far. Defaults to 0.0.

  • z_far (float, optional) – specifying the mapping of the far clipping plane to window or viewport coordinates. Clamped to the range 0 to 1. Defaults to 1.0.

blend_color(r: float, g: float, b: float, a: float)[source]

Append a blendColor command to the commands buffer.

Parameters
  • r (float) – red [0, 1]

  • g (float) – green [0, 1]

  • b (float) – blue [0, 1]

  • a (float) – alpha [0, 1]

blend_equation(mode: str)[source]

Append a blendEquation to the command buffer.

[‘FUNC_ADD’, ‘FUNC_SUBTRACT’, ‘FUNC_REVERSE_SUBTRACT’, ‘MIN’, ‘MAX’]

Parameters

mode (str) – how source and destination colors are combined

blend_equation_separate(mode_rgb: str, mode_alpha: str)[source]

Append a blendEquationSeparate to the command buffer

[‘FUNC_ADD’, ‘FUNC_SUBTRACT’, ‘FUNC_REVERSE_SUBTRACT’, ‘MIN’, ‘MAX’]

Parameters
  • mode_rgb (str) – how the red, green and blue components of source and destination colors are combined

  • mode_alpha (str) – how the alpha component (transparency) of source and destination colors are combined

blend_func(s_factor: str, d_factor: str)[source]

Append a blendFunc to the command buffer

[‘ZERO’, ‘ONE’, ‘SRC_COLOR’, ‘ONE_MINUS_SRC_COLOR’, ‘DST_COLOR’, ‘ONE_MINUS_DST_COLOR’, ‘SRC_ALPHA’, ‘ONE_MINUS_SRC_ALPHA’, ‘DST_ALPHA’, ‘ONE_MINUS_DST_ALPHA’, ‘CONSTANT_COLOR’, ‘ONE_MINUS_CONSTANT_COLOR’, ‘CONSTANT_ALPHA’, ‘ONE_MINUS_CONSTANT_ALPHA’, ‘SRC_ALPHA_SATURATE’]

Parameters
  • s_factor (str) – a multiplier for the source blending factors

  • d_factor (str) – a multiplier for the destination blending factors

Raises
blend_func_separate(src_rgb: str, dst_rgb: str, src_alpha: str, dst_alpha: str)[source]

Append a blendFuncSeparate to the command buffer

[‘ZERO’, ‘ONE’, ‘SRC_COLOR’, ‘ONE_MINUS_SRC_COLOR’, ‘DST_COLOR’, ‘ONE_MINUS_DST_COLOR’, ‘SRC_ALPHA’, ‘ONE_MINUS_SRC_ALPHA’, ‘DST_ALPHA’, ‘ONE_MINUS_DST_ALPHA’, ‘CONSTANT_COLOR’, ‘ONE_MINUS_CONSTANT_COLOR’, ‘CONSTANT_ALPHA’, ‘ONE_MINUS_CONSTANT_ALPHA’, ‘SRC_ALPHA_SATURATE’]

Parameters
  • src_rgb (str) – a multiplier for the source blending factors

  • dst_rgb (str) – a multiplier for the destination blending factors

  • src_alpha (str) – a multiplier for the source blending factors

  • dst_alpa (str) – a multiplier for the destination blending factors

create_texture() GLResourceWidget[source]

Append a createTexture command to the command list

Returns

the resource that will hold the texture

Return type

GLResourceWidget

bind_texture(target: str, texture: Optional[GLResourceWidget] = None)[source]

Append a bindTexture command to the command list

Parameters
  • target (str) – the binding point [“TEXTURE_2D”, “TEXTURE_CUBE_MAP”, “TEXTURE_3D”, “TEXTURE_2D_ARRAY”]

  • texture (GLResourceWidget) – the texture resource

active_texture(texture: int)[source]

Append an activeTexture command

Parameters

texture (int) – The texture unit to make active. The value is a gl.TEXTURE0 + texture

generate_mipmap(target: str)[source]

Append a generateMipmap command

Parameters

target (str) – the binding point [“TEXTURE_2D”, “TEXTURE_CUBE_MAP”, “TEXTURE_3D”, “TEXTURE_2D_ARRAY”]

tex_image_2d(target: str, level: int, internal_format: str, width: int, height: int, border: int, format: str, data_type: str, pixel: array)[source]

Append a texImage2D command

target = [‘TEXTURE_2D’, ‘TEXTURE_CUBE_MAP_POSITIVE_X’, ‘TEXTURE_CUBE_MAP_NEGATIVE_X’, ‘TEXTURE_CUBE_MAP_POSITIVE_Y’, ‘TEXTURE_CUBE_MAP_NEGATIVE_Y’, ‘TEXTURE_CUBE_MAP_POSITIVE_Z’, ‘TEXTURE_CUBE_MAP_NEGATIVE_Z’]

internal_format = [‘RGBA’, ‘RGB’, ‘LUMINANCE_ALPHA’, ‘LUMINANCE’, ‘ALPHA’, ‘R8’, ‘R8_SNORM’, ‘RG8’, ‘RG8_SNORM’, ‘RGB8’, ‘RGB8_SNORM’, ‘RGB565’, ‘RGBA4’, ‘RGB5_A1’, ‘RGBA8’, ‘RGBA8_SNORM’, ‘RGB10_A2’, ‘RGB10_A2UI’, ‘SRGB8’, ‘SRGB8_ALPHA8’, ‘R16F’, ‘RG16F’, ‘RGB16F’, ‘RGBA16F’, ‘R32F’, ‘RG32F’, ‘RGB32F’, ‘RGBA32F’, ‘R11F_G11F_B10F’, ‘RGB9_E5’, ‘R8I’, ‘R8UI’, ‘R16I’, ‘R16UI’, ‘R32I’, ‘R32UI’, ‘RG8I’, ‘RG8UI’, ‘RG16I’, ‘RG16UI’, ‘RG32I’, ‘RG32UI’, ‘RGB8I’, ‘RGB8UI’, ‘RGB16I’, ‘RGB16UI’, ‘RGB32I’, ‘RGB32UI’, ‘RGBA8I’, ‘RGBA8UI’, ‘RGBA16I’, ‘RGBA16UI’, ‘RGBA32I’, ‘RGBA32UI’, ‘DEPTH_COMPONENT24’, ‘DEPTH_COMPONENT32F’, ‘DEPTH32F_STENCIL8’, ‘DEPTH24_STENCIL8’]

format = [‘RGB’, ‘RGBA’, ‘LUMINANCE_ALPHA’, ‘LUMINANCE’, ‘ALPHA’, ‘RED’, ‘RED_INTEGER’, ‘RG’, ‘RG_INTEGER’, ‘RGB’, ‘RGB_INTEGER’, ‘RGBA_INTEGER’, ‘DEPTH_COMPONENT’]

data_type = [‘UNSIGNED_BYTE’, ‘UNSIGNED_SHORT_5_6_5’, ‘UNSIGNED_SHORT_4_4_4_4’, ‘UNSIGNED_SHORT_5_5_5_1’, ‘BYTE’, ‘UNSIGNED_SHORT’, ‘SHORT’, ‘UNSIGNED_INT’, ‘INT’, ‘HALF_FLOAT’, ‘FLOAT’, ‘UNSIGNED_INT_2_10_10_10_REV’, ‘UNSIGNED_INT_10F_11F_11F_REV’, ‘UNSIGNED_INT_5_9_9_9_REV’, ‘UNSIGNED_INT_24_8’, ‘FLOAT_32_UNSIGNED_INT_24_8_REV’]

link between internal_format, format and type; https://registry.khronos.org/webgl/specs/latest/2.0/#TEXTURE_TYPES_FORMATS_FROM_DOM_ELEMENTS_TABLE

Parameters
  • target (str) – the binding point (target) of the active texture

  • level (int) – the level of detail. Level 0 is the base image level and level n is the n-th mipmap reduction level.

  • internal_format (str) – the color components in the texture

  • width (int) – the width of the texture.

  • height (int) – the height of the texture.

  • border (int) – specifying the width of the border. Must be 0.

  • format (str) – the format of the texel data

  • data_type (str) – the data type of the texel data

  • pixel (np.array) – the buffer

tex_storage_2d(target: str, levels: int, internal_format: str, width: int, height: int)[source]

append a texStorage2D command

internal format[“R8”, “R16F”, “R32F”, “R8UI”, “RG8”, “RG16F”, “RG32F”, “RG8UI”, “RGB8”, “SRGB8”, “RGB565”, “R11F_G11F_B10F”, “RGB9_E5”, “RGB16F”, “RGB32F”, “RGB8UI”, “RGBA8”, “SRGB8_ALPHA8”, “RGB5_A1”, “RGBA4”, “RGBA16F”, “RGBA32F”, “RGBA8UI”,

‘DEPTH_COMPONENT16’, ‘DEPTH_COMPONENT24’, ‘DEPTH_COMPONENT32F’, ‘DEPTH32F_STENCIL8’, ‘DEPTH24_STENCIL8’]

Parameters
  • target (str) – ‘TEXTURE_2D’, ‘TEXTURE_CUBE_MAP’

  • levels (int) – the number of mipmap

  • internal_format (str) – the internal format

  • width (int) – the width of the texture

  • height (int) – the heifht of the texture

Raises
tex_image_3d(target: str, level: int, internal_format: str, width: int, height: int, depth: int, border: int, format: str, data_type: str, pixel: array)[source]

Append a texImage3D command

target = [‘TEXTURE_3D’, ‘TEXTURE_2D_ARRAY’]

internal_format = [‘RGBA’, ‘RGB’, ‘LUMINANCE_ALPHA’, ‘LUMINANCE’, ‘ALPHA’, ‘R8’, ‘R16F’, ‘R32F’, ‘R8UI’, ‘RG8’, ‘RG16F’, ‘RG32F’, ‘RGUI’, ‘RGB8’, ‘SRGB8’, ‘RGB565’, ‘R11F_G11F_B10F’, ‘RGB9_E5’, ‘RGB16F’, ‘RGB32F’, ‘RGB8UI’, ‘RGBA8’, ‘SRGB8_ALPHA8’, ‘RGB5_A1’, ‘RGBA4444’, ‘RGBA16F’, ‘RGBA32F’, ‘RGBA8UI’]

format = [‘RGB’, ‘RGBA’, ‘LUMINANCE_ALPHA’, ‘LUMINANCE’, ‘ALPHA’, ‘RED’, ‘RED_INTEGER’, ‘RG’, ‘RG_INTEGER’, ‘RGB’, ‘RGB_INTEGER’, ‘RGBA_INTEGER’]

data_type = [‘UNSIGNED_BYTE’, ‘UNSIGNED_SHORT_5_6_5’, ‘UNSIGNED_SHORT_4_4_4_4’, ‘UNSIGNED_SHORT_5_5_5_1’, ‘BYTE’, ‘UNSIGNED_SHORT’, ‘SHORT’, ‘UNSIGNED_INT’, ‘INT’, ‘HALF_FLOAT’, ‘FLOAT’, ‘UNSIGNED_INT_2_10_10_10_REV’, ‘UNSIGNED_INT_10F_11F_11F_REV’, ‘UNSIGNED_INT_5_9_9_9_REV’, ‘UNSIGNED_INT_24_8’, ‘FLOAT_32_UNSIGNED_INT_24_8_REV’]

link between internal_format, format and type; https://registry.khronos.org/webgl/specs/latest/2.0/#TEXTURE_TYPES_FORMATS_FROM_DOM_ELEMENTS_TABLE

Parameters
  • target (str) – the binding point (target) of the active texture

  • level (int) – the level of detail. Level 0 is the base image level and level n is the n-th mipmap reduction level.

  • internal_format (str) – the color components in the texture

  • width (int) – the width of the texture.

  • height (int) – the height of the texture.

  • depth (int) – the depth of the texture.

  • border (int) – specifying the width of the border. Must be 0.

  • format (str) – the format of the texel data

  • data_type (str) – the data type of the texel data

  • pixel (np.array) – the buffer

tex_storage_3d(target: str, levels: int, internal_format: str, width: int, height: int, depth: int)[source]

Append a texStorage3D command

Parameters
  • target (str) – ‘TEXTURE_3D’, ‘TEXTURE_2D_ARRAY’

  • levels (int) – the number of mipmap

  • internal_format (str) – the internal format

  • width (int) – the width of the texture

  • height (int) – the heifht of the texture

Raises
tex_parameter(target: str, pname: str, param)[source]

Append a texParameteri or texParameterf to the command list

pname = [“TEXTURE_MAG_FILTER”, “TEXTURE_MIN_FILTER”, “TEXTURE_WRAP_S”, “TEXTURE_WRAP_T”,

‘TEXTURE_BASE_LEVEL’, ‘TEXTURE_COMPARE_FUNC’, ‘TEXTURE_COMPARE_MODE’, ‘TEXTURE_MAX_LEVEL’, ‘TEXTURE_MAX_LOD’, ‘TEXTURE_MIN_LOD’, ‘TEXTURE_WRAP_R’]

param = int or float or [‘LINEAR’, ‘NEAREST’, ‘NEAREST_MIPMAP_NEAREST’, ‘LINEAR_MIPMAP_NEAREST’, ‘NEAREST_MIPMAP_LINEAR’, ‘LINEAR_MIPMAP_LINEAR’,

‘REPEAT’, ‘CLAMP_TO_EDGE’, ‘MIRRORED_REPEAT’, ‘LEQUAL’, ‘GEQUAL’, ‘LESS’, ‘GREATER’, ‘EQUAL’, ‘NOTEQUAL’, ‘ALWAYS’, ‘NEVER’, ‘NONE’, ‘COMPARE_REF_TO_TEXTURE’]

Parameters
  • target (str) – the binding point [“TEXTURE_2D”, “TEXTURE_CUBE_MAP”, “TEXTURE_3D”, “TEXTURE_2D_ARRAY”]

  • pname (str) – the texture parameter to set.

  • param (str | int | float) – the value for the specified parameter.

pixel_store_i(pname: str, param)[source]

Append a pixelStorei command

create_shader(shadertype: str) GLResourceWidget[source]

Append a createShader command to the command list

Parameters

shadertype (str) – type of shader [“VERTEX_SHADER” or “FRAGMENT_SHADER”]

Returns

the resource that will hold the shader

Return type

GLResourceWidget

shader_source(shader: GLResourceWidget, source: str)[source]

Append a shaderSource command to the buffer. Sets the source code for a shader object.

Parameters
  • shader (GLResourceWidget) – a resource with a shader.

  • source (str) – A string of GLSL code that defines the shader.

compile_shader(shader: GLResourceWidget)[source]

Append a compileShader command to the command buffer.

Parameters

shader (GLResourceWidget) – a resource with a shader.

create_program() GLResourceWidget[source]

Append a createProgram command to the command list

Returns

the resource that will hold the program

Return type

GLResourceWidget

create_program_ext(vertex_source: str, fargment_source: str, attribute_location: {} = None, auto_execute=True) GLResourceWidget[source]

Extended function to quickly create a program

This will build the command buffer with all the needed commands for you. It creates the shaders, compiles them, creates the program, and links it.

And if the auto_execute is on, it will send the command buffer to the frontend.

Parameters
  • vertex_source (str) – the vertex source code

  • fargment_source (str) – the shader source code

  • {str (attribute_location() – int, ..}): the force attribute location if we don’t want to use the default location.

  • auto_execute (bool) – do we execute all the commands automatically?

Returns

the resource that hold the program

Return type

GLResourceWidget

attach_shader(program: GLResourceWidget, shader: GLResourceWidget)[source]

Append a attachShader command to the command buffer

Parameters
bind_attrib_location(program: GLResourceWidget, index, name)[source]

Append a bindAttribLocation command to the command buffer.

Parameters
  • program (int) – The WebGL program object.

  • index (int) – The index of the attribute variable to assign to the bound location.

  • name (str) – The name of the attribute variable.

Append a linkProgram command to the command buffer

Parameters

program (GLResourceWidget) – the program to link

use_program(program: Optional[GLResourceWidget] = None)[source]

Append a useProgram command to the commands buffer.

Parameters

program (GLResourceWidget) – the program to use. Default to None.

uniform(name: str, array: array)[source]

Append a uniform command to the commands buffer.

Parameters
  • name (str) – the name of the uniform

  • array (np.array) – the numpy array with the data. Even if you send one value it must be an array.

uniform_matrix(name: str, array: array)[source]

Append a uniformMatrix command to the commands buffer.

Parameters
  • name (str) – the name of the uniform

  • array (np.array) – the matrix(matrices) to send. It must be a np.array(dtype=np.float32)

uniform_block_binding(program: GLResourceWidget, uniform_block_name: str, uniform_block_binding: int)[source]

Append a uniformBlockBinding command

create_buffer() GLResourceWidget[source]

Append a createBuffer command to the command list

Returns

a resource that (will) hold the buffer after you call ‘execute’

Return type

GLResourceWidget

create_buffer_ext(target='ARRAY_BUFFER', src_data=None, usage='STATIC_DRAW', auto_execute=True) GLResourceWidget[source]

Extended create buffer command

This build the command list with the create, bind, and buffer_data. at the end it unbind the buffer. If autoexecute is set it will send the command buffer to the frontend.

Parameters
  • target (str, optional) – _description_. Defaults to ‘ARRAY_BUFFER’.

  • src_data (np.array, optional) – the data to send. Defaults to None.

  • usage (str, optional) – _description_. Defaults to ‘STATIC_DRAW’.

  • auto_execute (bool, optional) – do we execute the commands. Defaults to True

Returns

the resource for the buffer

Return type

GLResourceWidget

create_uniform_buffer_ext(program: GLResourceWidget, block_name: str, usage='STATIC_DRAW', auto_execute=True) GLResourceWidget[source]

create a uniform buffer

We have to use this funciton to create a uniform buffer because the type of data passed to the buffer is out of sync with the front end.

Parameters
  • program (GLResourceWidget,) – the program where the block is found.

  • block_name (str) – the name of the block. Defaults to None.

  • usage (str, optional) – _description_. Defaults to ‘STATIC_DRAW’.

  • auto_execute (bool, optional) – do we execute the commands. Defaults to True

Returns

the resource for the buffer

Return type

GLResourceWidget

bind_buffer(target: str = 'ARRAY_BUFFER', buffer: Optional[GLResourceWidget] = None)[source]

Append a bindBuffer command to the command list

This function binds a given WebGLBuffer to a target. The target must be one of the following strings:

“ARRAY_BUFFER” “ELEMENT_ARRAY_BUFFER” “COPY_READ_BUFFER” “COPY_WRITE_BUFFER” “PIXEL_PACK_BUFFER” “PIXEL_UNPACK_BUFFER” “TRANSFORM_FEEDBACK_BUFFER” “UNIFORM_BUFFER”

Parameters
  • target (str) – the target string. Defaults to “ARRAY_BUFFER”

  • buffer (GLResourceWidget) – resource that hold the buffer. Defaults to None

Raises

AttributeError – string not matching the values

bind_buffer_base(target: str, index: int, buffer: Optional[GLResourceWidget] = None)[source]

Append a bindBufferBase command

buffer_data(target='ARRAY_BUFFER', src_data=None, usage='STATIC_DRAW', update_info=False)[source]

Append a bufferData command to the command list

Parameters
  • target (str, optional) – _description_. Defaults to ‘ARRAY_BUFFER’.

  • src_data (np.array, optional) – the data to send. Defaults to None.

  • usage (str, optional) – _description_. Defaults to ‘STATIC_DRAW’.

  • update_info (bool, optional) – do we update the buffer info that are displayed in the widget. Defaults to False

Raises
buffer_sub_data(target='ARRAY_BUFFER', dst_byte_offset=0, src_data=None, src_offset=0)[source]

Append a BufferSubData to the command list

target values : [“ARRAY_BUFFER”, “ELEMENT_ARRAY_BUFFER”, “COPY_READ_BUFFER”, “COPY_WRITE_BUFFER”, “TRANSFORM_FEEDBACK_BUFFER”, “UNIFORM_BUFFER”]

Parameters
  • target (str, optional) – specifying the binding point (target). Defaults to ‘ARRAY_BUFFER’.

  • dst_byte_offset (int | str, optional) – specifying an offset in bytes where the data replacement will start. in the case of UNIFORM_BUFFER, it can be a string with name of the uniform. Defaults to 0.

  • src_data (np.array, optional) – the array that will be copied into the data store. Defaults to None.

  • src_offset (int, optional) – specifying the element index offset where to start reading the buffer. Defaults to 0.

Raises

AttributeError – _description_

create_vertex_array() GLResourceWidget[source]

Append a createVertexArray command to the command list

Returns

a resource that (will) hold the vao after you call ‘execute’

Return type

GLResourceWidget

create_vertex_array_ext(program: GLResourceWidget, bindings, indices=None, auto_execute=True) GLResourceWidget[source]

extended vertex array function

This creates the vertex array and link all the attributes using the bindings.

The bindings are a list of tuples with * [(buffer, “3f32 3f32”, “in_vertex”, “in_normal”), …] * or [(buffer, “3f32 3f32”, 0, 1), …] * or [(buffer, “1mat4:1”, “in_world”), …] * the buffer is a buffer resource * supported type for buffer definitions : [1, 2, 3, 4][i8, i16, i32, u8, u16, u32, f16, f32, mat4](:[1,2,…]) * the optional ‘:’ is used to set the vertexAttribDivisor on that attribute.

Parameters
  • program (GLResourceWidget) – the program to use

  • bindings (List of tuple) – [(buffer, “3f32 3f32”, “in_vertex”, “in_normal”), …]”

  • indices (np.array(dtype=u8 or dtype=u16)) – the indices buffer to create. Defaults to None.

  • auto_execute (bool) – do we execute the commands ?. Defaults to True.

bind_vertex_array(vertex_array: Optional[GLResourceWidget] = None)[source]

Append a bindVertexArray command to the commands buffer.

Parameters

vertex_array (GLResourceWidget) – the vertex array to bind. Defaults to None.

vertex_attrib_pointer(index, size: int, attribtype: str, normalized: bool, stride: int, offset: int, index_offset: int = 0)[source]

Append a vertexAttribPointer command to the command buffer.

Parameters
  • index (int or str) – The index of the generic vertex attribute to be modified or the name of the attribute to find in the shader.

  • size (int) – Specifies the number of components per generic vertex attribute. Must be 1, 2, 3, 4.

  • attribtype (str) – Specifies the data type of each component in the array. Can be one of “BYTE”, “UNSIGNED_BYTE”, “SHORT”, “UNSIGNED_SHORT”, “FLOAT”, “HALF_FLOAT”, “INT”, “UNSIGNED_INT”.

  • normalized (bool) – Specifies whether integer data values should be normalized when being casted to a float.

  • stride (int) – Specifies the byte offset between consecutive generic vertex attributes.

  • offset (int) – Specifies a offset, in bytes, of the first component in the vertex attribute array.

  • index_offset (int) – add an offset to the index (location) found.

vertex_attrib_i_pointer(index, size: int, attribtype: str, stride: int, offset: int, index_offset: int = 0)[source]

Append a vertexAttribIPointer command to the command buffer.

Parameters
  • index (int or str) – The index of the generic vertex attribute to be modified or the name of the attribute to find in the shader.

  • size (int) – Specifies the number of components per generic vertex attribute. Must be 1, 2, 3, 4.

  • attribtype (str) – Specifies the data type of each component in the array. Can be one of “BYTE”, “UNSIGNED_BYTE”, “SHORT”, “UNSIGNED_SHORT”, “INT”, “UNSIGNED_INT”.

  • stride (int) – Specifies the byte offset between consecutive generic vertex attributes.

  • offset (int) – Specifies a offset, in bytes, of the first component in the vertex attribute array.

  • index_offset (int) – add an offset to the index (location) found.

enable_vertex_attrib_array(index, index_offset: int = 0)[source]

Append an enableVertexAttribArray command to the command buffer.

Parameters
  • index (int or str) – Specifies the index of the generic vertex attribute to be enabled or the name of the attribute to find in the shader.

  • index_offset (int) – add an offset to the index (location) found.

disable_vertex_attrib_array(index, index_offset: int = 0)[source]

Append an disableVertexAttribArray command to the command buffer.

Parameters
  • index (int or str) – Specifies the index of the generic vertex attribute to be enabled or the name of the attribute to find in the shader.

  • index_offset (int) – add an offset to the index (location) found.

vertex_attrib_divisor(index, divisor: int, index_offset: int = 0)[source]

Append an vertexAttribDivisor command to the command buffer.

modifies the rate at which generic vertex attributes advance when rendering multiple instances of primitives with gl.drawArraysInstanced() and gl.drawElementsInstanced().

Parameters
  • index (int or str) – Specifies the index of the generic vertex attribute to be enabled or the name of the attribute to find in the shader.

  • divisor (int) – specifying the number of instances that will pass between updates of the generic attribute.

  • index_offset (int) – add an offset to the index (location) found.

vertex_attrib_fv(index, value: array, index_offset: int = 0)[source]

Append an vertexAttrib[1234]fv command to the command buffer.

the type of vertexAttrib function to call will be decided from the shape of the array.

Parameters
  • index (int or str) – Specifies the index of the generic vertex attribute or the name of the attribute to find in the shader.

  • value (np.array(dtype=np.float32)) – values to push.

  • index_offset (int) – add an offset to the index (location) found.

vertex_attrib_i4_fv(index, value: array, index_offset: int = 0)[source]

Append an vertexAttribI4[u]iv command to the command buffer.

the type of vertexAttrib function to call will be decided from the type of the array.

Parameters
  • index (int or str) – Specifies the index of the generic vertex attribute or the name of the attribute to find in the shader.

  • value (np.array(dtype=np.uint32 or dtype=np.int32)) – values to push.

  • index_offset (int) – add an offset to the index (location) found.

draw_arrays(mode: str, first: int, count: int)[source]

Append a drawArrays command to the commands buffer

Parameters
  • mode ({'POINTS', 'LINE_STRIP', 'LINE_LOOP', 'LINES', 'TRIANGLE_STRIP', 'TRIANGLE_FAN', 'TRIANGLES'}) – type of drawing operation.

  • first (int) – the starting index in the array of vector points.

  • count (int) – the number of indices to be rendered.

draw_arrays_instanced(mode: str, first: int, count: int, instance_count: int)[source]

Append a drawArraysInstanced command to the commands buffer

Parameters
  • mode ({'POINTS', 'LINE_STRIP', 'LINE_LOOP', 'LINES', 'TRIANGLE_STRIP', 'TRIANGLE_FAN', 'TRIANGLES'}) – type of drawing operation.

  • first (int) – the starting index in the array of vector points.

  • count (int) – the number of indices to be rendered.

  • instance_count (int) – the number of instances fo the range of elements to execute.

draw_elements(mode: str, count: int, bytetype: str, offset: int)[source]

Append a drawElements command to the commands buffer

Parameters
  • mode ({'POINTS', 'LINE_STRIP', 'LINE_LOOP', 'LINES', 'TRIANGLE_STRIP', 'TRIANGLE_FAN', 'TRIANGLES'}) – type of drawing operation.

  • count (int) – specifying the number of elements of the bound element array buffer to be rendered.

  • bytetype ({'UNSIGNED_BYTE', 'UNSIGNED_SHORT'}) – type of data in the index buffer.

  • offset (int) – a byte offset in the element array buffer. Must be a valid multiple of the size of the given type.

draw_elements_instanced(mode: str, count: int, bytetype: str, offset: int, instance_count: int)[source]

Append a drawElementsInstanced command to the commands buffer

Parameters
  • mode ({'POINTS', 'LINE_STRIP', 'LINE_LOOP', 'LINES', 'TRIANGLE_STRIP', 'TRIANGLE_FAN', 'TRIANGLES'}) – type of drawing operation.

  • count (int) – specifying the number of elements of the bound element array buffer to be rendered.

  • bytetype ({'UNSIGNED_BYTE', 'UNSIGNED_SHORT'}) – type of data in the index buffer.

  • offset (int) – a byte offset in the element array buffer. Must be a valid multiple of the size of the given type.

  • instance_count (int) – the number of instances of the set of elements to execute.

create_framebuffer() GLResourceWidget[source]

Append a createFramebuffer command to the command list

Returns

the resource that will hold the framebuffer

Return type

GLResourceWidget

bind_framebuffer(target: str, framebuffer: Optional[GLResourceWidget] = None)[source]

Append a bindFramebuffer command

Parameters
  • target (str) – the binding point (target) [“FRAMEBUFFER”, “DRAW_FRAMEBUFFER”, “READ_FRAMEBUFFER”]

  • framebuffer (GLResourceWidget) – the framebuffer

framebuffer_texture_2d(target: str, attachement: str, textarget: str, texture: GLResourceWidget, level: int)[source]

Append a framebufferTexture2D command

Parameters
  • target (str) – the binding point (target). [“FRAMEBUFFER”, “DRAW_FRAMEBUFFER”, “READ_FRAMEBUFFER”]

  • attachement (str) – the attachment point for the texture. [“COLOR_ATTACHMENT0”, “DEPTH_ATTACHMENT”, “STENCIL_ATTACHMENT”, ‘DEPTH_STENCIL_ATTACHMENT’, ‘COLOR_ATTACHMENT1’, ‘COLOR_ATTACHMENT2’, ‘COLOR_ATTACHMENT3’, ‘COLOR_ATTACHMENT4’, ‘COLOR_ATTACHMENT5’, ‘COLOR_ATTACHMENT6’, ‘COLOR_ATTACHMENT7’, ‘COLOR_ATTACHMENT8’, ‘COLOR_ATTACHMENT9’, ‘COLOR_ATTACHMENT10’, ‘COLOR_ATTACHMENT11’, ‘COLOR_ATTACHMENT12’, ‘COLOR_ATTACHMENT13’, ‘COLOR_ATTACHMENT14’, ‘COLOR_ATTACHMENT15’]:

  • textarget (str) – the texture target. [‘TEXTURE_2D’, ‘TEXTURE_CUBE_MAP_POSITIVE_X’, ‘TEXTURE_CUBE_MAP_NEGATIVE_X’, ‘TEXTURE_CUBE_MAP_POSITIVE_Y’, ‘TEXTURE_CUBE_MAP_NEGATIVE_Y’, ‘TEXTURE_CUBE_MAP_POSITIVE_Z’, ‘TEXTURE_CUBE_MAP_NEGATIVE_Z’]

  • texture (GLResourceWidget) – the texture.

  • level (int) – the mipmap level of the texture image to be attached. Must be 0.

draw_buffers(buffers)[source]

Append a drawBuffers command

class ipywebgl.glresource.GLResourceWidget(**kwargs: Any)[source]