Skip to content

Latest commit

 

History

History
197 lines (151 loc) · 6.37 KB

context.rst

File metadata and controls

197 lines (151 loc) · 6.37 KB

Context

moderngl.Context

Create

moderngl.create_context(require=None) -> Context

moderngl.create_standalone_context(require=None) -> Context

ModernGL Objects

Context.program(vertex_shader, fragment_shader=None, geometry_shader=None, tess_control_shader=None, tess_evaluation_shader=None, varyings=()) -> Program

Context.simple_vertex_array(program, buffer, *attributes, index_buffer=None, index_element_size=4) -> VertexArray

Context.vertex_array(args,*kwargs) -> VertexArray

Context.buffer(data=None, reserve=0, dynamic=False) -> Buffer

Context.texture(size, components, data=None, samples=0, alignment=1, dtype='f1') -> Texture

Context.depth_texture(size, data=None, samples=0, alignment=4) -> Texture

Context.texture3d(size, components, data=None, alignment=1, dtype='f1') -> Texture3D

Context.texture_array(size, components, data=None, alignment=1, dtype='f1') -> TextureArray

Context.texture_cube(size, components, data=None, alignment=1, dtype='f1') -> TextureCube

Context.simple_framebuffer(size, components=4, samples=0, dtype='f1') -> Framebuffer

Context.framebuffer(color_attachments=(), depth_attachment=None) -> Framebuffer

Context.renderbuffer(size, components=4, samples=0, dtype='f1') -> Renderbuffer

Context.depth_renderbuffer(size, samples=0) -> Renderbuffer

Context.scope(framebuffer=None, enable_only=None, textures=(), uniform_buffers=(), storage_buffers=(), samplers=(), enable=None) -> Scope

Context.query(samples=False, any_samples=False, time=False, primitives=False) -> Query

Context.compute_shader(source) -> ComputeShader

Context.sampler(repeat_x=True, repeat_y=True, repeat_z=True, filter=None, anisotropy=1.0, compare_func='?', border_color=None, min_lod=-1000.0, max_lod=1000.0, texture=None) -> Sampler

Context.clear_samplers(start=0, end=-1)

Context.release()

Methods

Context.clear(red=0.0, green=0.0, blue=0.0, alpha=0.0, depth=1.0, viewport=None, color=None)

Context.enable_only(flags)

Context.enable(flags)

Context.disable(flags)

Context.finish()

Context.copy_buffer(dst, src, size=-1, read_offset=0, write_offset=0)

Context.copy_framebuffer(dst, src)

Context.detect_framebuffer(glo=None) -> Framebuffer

Context.__enter__()

Context.__exit__(exc_type, exc_val, exc_tb)

Attributes

Context.line_width

Context.point_size

Context.depth_func

Context.blend_func

Context.blend_equation

Context.viewport

Context.scissor

Context.version_code

Context.screen

Context.fbo

Context.front_face

Context.cull_face

Context.wireframe

Context.max_samples

Context.max_integer_samples

Context.max_texture_units

Context.default_texture_unit

Context.max_anisotropy

Context.multisample

Context.patch_vertices

Context.provoking_vertex

Context.error

Context.info

Context.mglo

Context.extra

Context Flags

Context flags are used to enable or disable states in the context. These are not the same enum values as in opengl, but are rather bit flags so we can or them together setting multiple states in a simple way.

These values are available in the Context object and in the moderngl module when you don't have access to the context.

import moderngl

# From moderngl
ctx.enable_only(moderngl.DEPTH_TEST | moderngl.CULL_FACE)

# From context
ctx.enable_only(ctx.DEPTH_TEST | ctx.CULL_FACE)

Context.NOTHING

Context.BLEND

Context.DEPTH_TEST

Context.CULL_FACE

Context.RASTERIZER_DISCARD

Context.PROGRAM_POINT_SIZE

Blend Functions

Blend functions are used with :pyContext.blend_func to control blending operations.

# Default value
ctx.blend_func = ctx.SRC_ALPHA, ctx.ONE_MINUS_SRC_ALPHA

Context.ZERO

Context.ONE

Context.SRC_COLOR

Context.ONE_MINUS_SRC_COLOR

Context.SRC_ALPHA

Context.ONE_MINUS_SRC_ALPHA

Context.DST_ALPHA

Context.ONE_MINUS_DST_ALPHA

Context.DST_COLOR

Context.ONE_MINUS_DST_COLOR

Blend Function Shortcuts

Context.DEFAULT_BLENDING

Context.ADDITIVE_BLENDING

Context.PREMULTIPLIED_ALPHA

Blend Equations

Used with :pyContext.blend_equation.

Context.FUNC_ADD

Context.FUNC_SUBTRACT

Context.FUNC_REVERSE_SUBTRACT

Context.MIN

Context.MAX

Other Enums

Context.FIRST_VERTEX_CONVENTION

Context.LAST_VERTEX_CONVENTION

Examples

ModernGL Context

import moderngl
# create a window
ctx = moderngl.create_context()
print(ctx.version_code)

Standalone ModernGL Context

import moderngl
ctx = moderngl.create_standalone_context()
print(ctx.version_code)

ContextManager

context_manager.py

../../examples/context_manager.py

example.py

from context_manager import ContextManager

ctx = ContextManager.get_default_context()
print(ctx.version_code)