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 becomeswidget.draw_arrays(...)in PythonMasks parameters are replace by positional attribute, so for example
gl.clear(gl.DEPTH_BUFFER_BIT | gl.COLOR_BUFFER_BIT);in JavaScript becomeswidget.clear(depth_buffer_bit=True, color_buffer_bit=True)in PythonEnums are replaced by strings, so for example
gl.bufferData(gl.ARRAY_BUFFER, data, gl.DYNAMIC_DRAW);in JavaScript becomeswidget.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.
- 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
- sync_image_data¶
do we store the rendered imaged in python. This will significantly slow the rendering. Defaults to False.
- Type
- verbose¶
with verbose set to 1, all the commands executed by the frontend will be logged in the console. Defaults to 0.
- Type
- 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.
- 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.
- clear(color_bit_buffer=True, depth_buffer_bit=True, stencil_buffer_bit=False)[source]¶
Append a clear command to the commands buffer.
- 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.
- 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’]
- 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
- Raises
AttributeError – s_factor
AttributeError – d_factor
- 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’]
- create_texture() GLResourceWidget[source]¶
Append a createTexture command to the command list
- Returns
the resource that will hold the texture
- Return type
- 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
- Raises
AttributeError – _description_
AttributeError – _description_
- 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
- Raises
AttributeError – _description_
AttributeError – _description_
- 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’]
- 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
- 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
- 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
- Returns
the resource that hold the program
- Return type
- attach_shader(program: GLResourceWidget, shader: GLResourceWidget)[source]¶
Append a attachShader command to the command buffer
- Parameters
program (GLResourceWidget) – the program
shader (GLResourceWidget) – the shader
- bind_attrib_location(program: GLResourceWidget, index, name)[source]¶
Append a bindAttribLocation command to the command buffer.
- link_program(program: GLResourceWidget)[source]¶
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
- 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
- Returns
the resource for the buffer
- Return type
- 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
- 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
AttributeError – _description_
AttributeError – _description_
- 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
- 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.
- disable_vertex_attrib_array(index, index_offset: int = 0)[source]¶
Append an disableVertexAttribArray command to the command buffer.
- 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.
- 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.
- draw_arrays(mode: str, first: int, count: int)[source]¶
Append a drawArrays command to the commands buffer
- 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
- 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.