Package glitter :: Package contexts :: Module context
[hide private]
[frames] | no frames]

Source Code for Module glitter.contexts.context

  1  """Base class for OpenGL contexts. 
  2   
  3  This module wraps large parts of per-context state. 
  4   
  5  @todo: Provide convenience setters for C{glBlendFunc} via C{blend_func=("SRC_ALPHA", "ONE_MINUS_SRC_ALPHA")}. 
  6  @todo: Add listing of all bound textures, buffers, etc. 
  7  @todo: Do we need indexed variants for C{glEnable}? 
  8  @todo: Wrap C{glPatchParameter}. 
  9  @todo: Implement multiple viewports using C{glViewportIndexed}, C{glViewportArray}, C{glScissorIndexed}, and C{glScissorArray}. 
 10  @todo: Wrap C{glSampleCoverage}, C{glSampleMaski}, C{glMinSampleShading}, C{GL_SAMPLE_COVERAGE_VALUE}, and C{GL_SAMPLE_COVERAGE_INVERT}. 
 11  @todo: Wrap C{glReadPixels} and related framebuffer copy functions. 
 12  @todo: Add indexed getters for C{GL_TRANSFORM_FEEDBACK_BUFFER_START}, 
 13  C{GL_TRANSFORM_FEEDBACK_BUFFER_SIZE}, C{GL_UNIFORM_BUFFER_SIZE} and 
 14  C{GL_UNIFORM_BUFFER_START}. 
 15  @todo: Add getters for C{GL_CLIP_DISTANCEi}, C{GL_DEPTH_CLAMP}, 
 16  C{GL_FRAMEBUFFER_SRGB}, C{GL_MULTISAMPLE}, C{GL_PRIMITIVE_RESTART},  
 17  C{GL_TEXTURE_CUBE_MAP_SEAMLESS}, C{GL_SAMPLE_ALPHA_TO_ONE}, 
 18  C{GL_SAMPLE_ALPHA_TO_COVERAGE}, C{GL_SAMPLE_COVERAGE}, C{GL_SAMPLE_SHADING}, 
 19  and C{GL_SAMPLE_MASK}. 
 20  @todo: Implement stencil buffers using C{GL_STENCIL_BACK_FUNC}, 
 21  C{GL_STENCIL_FUNC}, C{GL_STENCIL_BACK_REF}, C{GL_STENCIL_REF}, 
 22  C{GL_STENCIL_BACK_VALUE_MASK}, C{GL_STENCIL_BACK_WRITEMASK}, 
 23  C{GL_STENCIL_VALUE_MASK}, C{GL_STENCIL_WRITEMASK}, C{GL_STENCIL_BACK_FAIL}, 
 24  C{GL_STENCIL_BACK_PASS_DEPTH_FAIL}, C{GL_STENCIL_BACK_PASS_DEPTH_PASS}, 
 25  C{GL_STENCIL_FAIL}, C{GL_STENCIL_PASS_DEPTH_FAIL}, 
 26  C{GL_STENCIL_PASS_DEPTH_PASS}, etc. 
 27   
 28  @author: Stephan Wenger 
 29  @date: 2012-02-29 
 30  """ 
 31   
 32  from weakref import WeakValueDictionary 
 33   
 34  import glitter.raw as _gl 
 35  from glitter.utils import blend_functions, blend_equations, depth_functions, draw_buffers, hints, provoking_vertices, logic_op_modes, provoke_modes, color_read_formats, color_read_types, read_buffers, cull_face_modes, front_face_modes, polygon_modes, InstanceDescriptorMixin, State, StateMixin 
 36  from glitter.contexts.contextmanager import context_manager 
 37  from glitter.contexts.proxies import BooleanProxy, FloatProxy, IntegerProxy, Integer64Proxy, EnableDisableProxy, EnumProxy, StringProxy, HintProxy, BindingProxy 
 38  from glitter.contexts.textures import TextureUnitList 
 39  from glitter.contexts.drawbuffers import DrawBufferList, ColorWritemaskList 
 40  from glitter.contexts.multiproxies import BlendFuncProxy, BlendEquationProxy, PolygonOffsetProxy 
 41   
42 -class GLObjectLibrary(object):
43 - def __init__(self, _context):
44 self._context = _context 45 self._objects = WeakValueDictionary()
46
47 - def __getitem__(self, key):
48 return self._objects[key]
49
50 - def __str__(self):
51 return str(dict(self._objects))
52
53 - def __repr__(self):
54 return str(self)
55
56 -class Context(InstanceDescriptorMixin, StateMixin):
57 _frozen = False 58
59 - def __init__(self):
60 self.texture_units = TextureUnitList(self) 61 self.color_writemasks = ColorWritemaskList(self) 62 self.draw_buffers = DrawBufferList(self) 63 self.buffers = GLObjectLibrary(self) 64 self.framebuffers = GLObjectLibrary(self) 65 self.program_pipelines = GLObjectLibrary(self) 66 self.queries = GLObjectLibrary(self) 67 self.renderbuffers = GLObjectLibrary(self) 68 self.samplers = GLObjectLibrary(self) 69 self.shader_programs = GLObjectLibrary(self) 70 self.shaders = GLObjectLibrary(self) 71 self.textures = GLObjectLibrary(self) 72 self.transform_feedbacks = GLObjectLibrary(self) 73 self.vertex_arrays = GLObjectLibrary(self) 74 75 super(Context, self).__init__() 76 77 self._frozen = True
78
79 - def __setattr__(self, name, value):
80 if self._frozen and not name.startswith("_") and not hasattr(self, name): 81 raise AttributeError("'%s' object has no attribute '%s'" % (self.__class__.__name__, name)) 82 return super(Context, self).__setattr__(name, value)
83
84 - def _bind(self):
85 """Make the context active. 86 87 This should be overwritten appropriately by window system dependent subclasses. 88 """ 89 90 raise NotImplementedError
91
92 - def bind(self):
93 old_binding = context_manager.current_context 94 context_manager.current_context = self 95 return old_binding
96
97 - def __enter__(self):
98 context_manager.push(self) 99 return self
100
101 - def __exit__(self, type, value, traceback):
103 104 #{ Enums 105 blend_functions = blend_functions 106 blend_equations = blend_equations 107 depth_functions = depth_functions 108 draw_buffers = draw_buffers 109 hints = hints 110 provoking_vertices = provoking_vertices 111 logic_op_modes = logic_op_modes 112 provoke_modes = provoke_modes 113 color_read_formats = color_read_formats 114 color_read_types = color_read_types 115 read_buffers = read_buffers 116 cull_face_modes = cull_face_modes 117 front_face_modes = front_face_modes 118 polygon_modes = polygon_modes 119 120 #{ Buffer bindings 121 array_buffer_binding = BindingProxy(_gl.glBindBuffer, [_gl.GL_ARRAY_BUFFER ]) 122 atomic_counter_buffer_binding = BindingProxy(_gl.glBindBuffer, [_gl.GL_ATOMIC_COUNTER_BUFFER ]) 123 copy_read_buffer_binding = BindingProxy(_gl.glBindBuffer, [_gl.GL_COPY_READ_BUFFER ]) 124 copy_write_buffer_binding = BindingProxy(_gl.glBindBuffer, [_gl.GL_COPY_WRITE_BUFFER ]) 125 draw_indirect_buffer_binding = BindingProxy(_gl.glBindBuffer, [_gl.GL_DRAW_INDIRECT_BUFFER ]) 126 element_array_buffer_binding = BindingProxy(_gl.glBindBuffer, [_gl.GL_ELEMENT_ARRAY_BUFFER ]) 127 pixel_pack_buffer_binding = BindingProxy(_gl.glBindBuffer, [_gl.GL_PIXEL_PACK_BUFFER ]) 128 pixel_unpack_buffer_binding = BindingProxy(_gl.glBindBuffer, [_gl.GL_PIXEL_UNPACK_BUFFER ]) 129 texture_buffer_binding = BindingProxy(_gl.glBindBuffer, [_gl.GL_TEXTURE_BUFFER ]) 130 transform_feedback_buffer_binding = BindingProxy(_gl.glBindBuffer, [_gl.GL_TRANSFORM_FEEDBACK_BUFFER ]) 131 uniform_buffer_binding = BindingProxy(_gl.glBindBuffer, [_gl.GL_UNIFORM_BUFFER ]) 132 133 #{ Miscellaneous bindings 134 program_pipeline_binding = BindingProxy(_gl.glBindProgramPipeline, [ ]) 135 renderbuffer_binding = BindingProxy(_gl.glBindRenderbuffer, [_gl.GL_RENDERBUFFER ]) 136 vertex_array_binding = BindingProxy(_gl.glBindVertexArray, [ ]) 137 draw_framebuffer_binding = BindingProxy(_gl.glBindFramebuffer, [_gl.GL_DRAW_FRAMEBUFFER ]) 138 read_framebuffer_binding = BindingProxy(_gl.glBindFramebuffer, [_gl.GL_READ_FRAMEBUFFER ]) 139 current_program = BindingProxy(_gl.glUseProgram, [ ]) 140 active_texture = BindingProxy(_gl.glActiveTexture, [ ]) 141 142 #{ Properties with separate getters but joint setters 143 blend_dst_alpha = BlendFuncProxy(_gl.GL_BLEND_DST_ALPHA) 144 blend_dst_rgb = BlendFuncProxy(_gl.GL_BLEND_DST_RGB) 145 blend_src_alpha = BlendFuncProxy(_gl.GL_BLEND_SRC_ALPHA) 146 blend_src_rgb = BlendFuncProxy(_gl.GL_BLEND_SRC_RGB) 147 blend_equation_alpha = BlendEquationProxy(_gl.GL_BLEND_EQUATION_ALPHA) 148 blend_equation_rgb = BlendEquationProxy(_gl.GL_BLEND_EQUATION_RGB) 149 polygon_offset_factor = PolygonOffsetProxy(_gl.GL_POLYGON_OFFSET_FACTOR) 150 polygon_offset_units = PolygonOffsetProxy(_gl.GL_POLYGON_OFFSET_UNITS) 151 152 #{ Miscellaneous enumerations 153 depth_func = EnumProxy(depth_functions, _gl.GL_DEPTH_FUNC, _gl.glDepthFunc) 154 draw_buffer = EnumProxy(draw_buffers, _gl.GL_DRAW_BUFFER, _gl.glDrawBuffer) 155 implementation_color_read_format = EnumProxy(color_read_formats, _gl.GL_IMPLEMENTATION_COLOR_READ_FORMAT) 156 implementation_color_read_type = EnumProxy(color_read_types, _gl.GL_IMPLEMENTATION_COLOR_READ_TYPE) 157 layer_provoking_vertex = EnumProxy(provoking_vertices, _gl.GL_LAYER_PROVOKING_VERTEX) 158 logic_op_mode = EnumProxy(logic_op_modes, _gl.GL_LOGIC_OP_MODE, _gl.glLogicOp) 159 provoking_vertex = EnumProxy(provoke_modes, _gl.GL_PROVOKING_VERTEX, _gl.glProvokingVertex) 160 read_buffer = EnumProxy(read_buffers, _gl.GL_READ_BUFFER, _gl.glReadBuffer) 161 viewport_index_provoking_vertex = EnumProxy(provoking_vertices, _gl.GL_VIEWPORT_INDEX_PROVOKING_VERTEX) 162 cull_face_mode = EnumProxy(cull_face_modes, _gl.GL_CULL_FACE_MODE, _gl.glCullFace) 163 front_face = EnumProxy(front_face_modes, _gl.GL_FRONT_FACE, _gl.glFrontFace) 164 polygon_mode = EnumProxy(polygon_modes, _gl.GL_POLYGON_MODE, _gl.glPolygonMode, [_gl.GL_FRONT_AND_BACK]) 165 166 #{ Hints 167 fragment_shader_derivative_hint = HintProxy(_gl.GL_FRAGMENT_SHADER_DERIVATIVE_HINT) 168 line_smooth_hint = HintProxy(_gl.GL_LINE_SMOOTH_HINT) 169 polygon_smooth_hint = HintProxy(_gl.GL_POLYGON_SMOOTH_HINT) 170 texture_compression_hint = HintProxy(_gl.GL_TEXTURE_COMPRESSION_HINT) 171 172 #{ Enabling and disabling 173 blend = EnableDisableProxy(_gl.GL_BLEND) 174 color_logic_op = EnableDisableProxy(_gl.GL_COLOR_LOGIC_OP) 175 cull_face = EnableDisableProxy(_gl.GL_CULL_FACE) 176 depth_test = EnableDisableProxy(_gl.GL_DEPTH_TEST) 177 dither = EnableDisableProxy(_gl.GL_DITHER) 178 line_smooth = EnableDisableProxy(_gl.GL_LINE_SMOOTH) 179 polygon_offset_fill = EnableDisableProxy(_gl.GL_POLYGON_OFFSET_FILL) 180 polygon_offset_line = EnableDisableProxy(_gl.GL_POLYGON_OFFSET_LINE) 181 polygon_offset_point = EnableDisableProxy(_gl.GL_POLYGON_OFFSET_POINT) 182 polygon_smooth = EnableDisableProxy(_gl.GL_POLYGON_SMOOTH) 183 scissor_test = EnableDisableProxy(_gl.GL_SCISSOR_TEST) 184 stencil_test = EnableDisableProxy(_gl.GL_STENCIL_TEST) 185 vertex_program_point_size = EnableDisableProxy(_gl.GL_VERTEX_PROGRAM_POINT_SIZE) 186 187 #{ Boolean values 188 color_writemask = BooleanProxy([_gl.GL_COLOR_WRITEMASK], _gl.glColorMask, shape=4) 189 depth_writemask = BooleanProxy([_gl.GL_DEPTH_WRITEMASK], _gl.glDepthMask) 190 doublebuffer = BooleanProxy([_gl.GL_DOUBLEBUFFER]) 191 pack_lsb_first = BooleanProxy([_gl.GL_PACK_LSB_FIRST], _gl.glPixelStorei, [_gl.GL_PACK_LSB_FIRST]) 192 pack_swap_bytes = BooleanProxy([_gl.GL_PACK_SWAP_BYTES], _gl.glPixelStorei, [_gl.GL_PACK_SWAP_BYTES]) 193 shader_compiler = BooleanProxy([_gl.GL_SHADER_COMPILER]) 194 stereo = BooleanProxy([_gl.GL_STEREO]) 195 unpack_lsb_first = BooleanProxy([_gl.GL_UNPACK_LSB_FIRST], _gl.glPixelStorei, [_gl.GL_UNPACK_LSB_FIRST]) 196 unpack_swap_bytes = BooleanProxy([_gl.GL_UNPACK_SWAP_BYTES], _gl.glPixelStorei, [_gl.GL_UNPACK_SWAP_BYTES]) 197 198 #{ Float values 199 aliased_line_width_range = FloatProxy([_gl.GL_ALIASED_LINE_WIDTH_RANGE], shape=2) 200 blend_color = FloatProxy([_gl.GL_BLEND_COLOR], _gl.glBlendColor, shape=4) 201 color_clear_value = FloatProxy([_gl.GL_COLOR_CLEAR_VALUE], _gl.glClearColor, shape=4) 202 depth_clear_value = FloatProxy([_gl.GL_DEPTH_CLEAR_VALUE], _gl.glClearDepth) 203 depth_range = FloatProxy([_gl.GL_DEPTH_RANGE], _gl.glDepthRange, shape=2) 204 line_width = FloatProxy([_gl.GL_LINE_WIDTH], _gl.glLineWidth) 205 line_width_granularity = FloatProxy([_gl.GL_LINE_WIDTH_GRANULARITY]) 206 line_width_range = FloatProxy([_gl.GL_LINE_WIDTH_RANGE], shape=2) 207 point_fade_threshold_size = FloatProxy([_gl.GL_POINT_FADE_THRESHOLD_SIZE], _gl.glPointParameterf, [_gl.GL_POINT_FADE_THRESHOLD_SIZE]) 208 point_size = FloatProxy([_gl.GL_POINT_SIZE], _gl.glPointSize) 209 point_size_granularity = FloatProxy([_gl.GL_POINT_SIZE_GRANULARITY]) 210 point_size_range = FloatProxy([_gl.GL_POINT_SIZE_RANGE], shape=2) 211 smooth_line_width_range = FloatProxy([_gl.GL_SMOOTH_LINE_WIDTH_RANGE], shape=2) 212 smooth_line_width_granularity = FloatProxy([_gl.GL_SMOOTH_LINE_WIDTH_GRANULARITY]) 213 214 #{ Integer values 215 major_version = IntegerProxy([_gl.GL_MAJOR_VERSION]) 216 max_3d_texture_size = IntegerProxy([_gl.GL_MAX_3D_TEXTURE_SIZE]) 217 max_array_texture_layers = IntegerProxy([_gl.GL_MAX_3D_TEXTURE_SIZE]) 218 max_clip_distances = IntegerProxy([_gl.GL_MAX_CLIP_DISTANCES]) 219 max_color_texture_samples = IntegerProxy([_gl.GL_MAX_COLOR_TEXTURE_SAMPLES]) 220 max_color_attachments = IntegerProxy([_gl.GL_MAX_COLOR_ATTACHMENTS]) 221 max_combined_fragment_uniform_components = IntegerProxy([_gl.GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS]) 222 max_combined_geometry_uniform_components = IntegerProxy([_gl.GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS]) 223 max_combined_texture_image_units = IntegerProxy([_gl.GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS]) 224 max_combined_uniform_blocks = IntegerProxy([_gl.GL_MAX_COMBINED_UNIFORM_BLOCKS]) 225 max_combined_vertex_uniform_components = IntegerProxy([_gl.GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS]) 226 max_cube_map_texture_size = IntegerProxy([_gl.GL_MAX_CUBE_MAP_TEXTURE_SIZE]) 227 max_depth_texture_samples = IntegerProxy([_gl.GL_MAX_DEPTH_TEXTURE_SAMPLES]) 228 max_draw_buffers = IntegerProxy([_gl.GL_MAX_DRAW_BUFFERS]) 229 max_elements_indices = IntegerProxy([_gl.GL_MAX_ELEMENTS_INDICES]) 230 max_elements_vertices = IntegerProxy([_gl.GL_MAX_ELEMENTS_VERTICES]) 231 max_fragment_input_components = IntegerProxy([_gl.GL_MAX_FRAGMENT_INPUT_COMPONENTS]) 232 max_fragment_uniform_components = IntegerProxy([_gl.GL_MAX_FRAGMENT_UNIFORM_COMPONENTS]) 233 max_fragment_uniform_vectors = IntegerProxy([_gl.GL_MAX_FRAGMENT_UNIFORM_VECTORS]) 234 max_fragment_uniform_blocks = IntegerProxy([_gl.GL_MAX_FRAGMENT_UNIFORM_BLOCKS]) 235 max_geometry_input_components = IntegerProxy([_gl.GL_MAX_GEOMETRY_INPUT_COMPONENTS]) 236 max_geometry_output_components = IntegerProxy([_gl.GL_MAX_GEOMETRY_OUTPUT_COMPONENTS]) 237 max_geometry_texture_image_units = IntegerProxy([_gl.GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS]) 238 max_geometry_uniform_blocks = IntegerProxy([_gl.GL_MAX_GEOMETRY_UNIFORM_BLOCKS]) 239 max_geometry_uniform_components = IntegerProxy([_gl.GL_MAX_GEOMETRY_UNIFORM_COMPONENTS]) 240 max_integer_samples = IntegerProxy([_gl.GL_MAX_INTEGER_SAMPLES]) 241 max_program_texel_offset = IntegerProxy([_gl.GL_MAX_PROGRAM_TEXEL_OFFSET]) 242 min_program_texel_offset = IntegerProxy([_gl.GL_MIN_PROGRAM_TEXEL_OFFSET]) 243 max_rectangle_texture_size = IntegerProxy([_gl.GL_MAX_RECTANGLE_TEXTURE_SIZE]) 244 max_renderbuffer_size = IntegerProxy([_gl.GL_MAX_RENDERBUFFER_SIZE]) 245 max_sample_mask_words = IntegerProxy([_gl.GL_MAX_SAMPLE_MASK_WORDS]) 246 max_server_wait_timeout = IntegerProxy([_gl.GL_MAX_SERVER_WAIT_TIMEOUT]) 247 max_texture_buffer_size = IntegerProxy([_gl.GL_MAX_TEXTURE_BUFFER_SIZE]) 248 max_texture_image_units = IntegerProxy([_gl.GL_MAX_TEXTURE_IMAGE_UNITS]) 249 max_texture_lod_bias = IntegerProxy([_gl.GL_MAX_TEXTURE_LOD_BIAS]) 250 max_texture_size = IntegerProxy([_gl.GL_MAX_TEXTURE_SIZE]) 251 max_uniform_buffer_bindings = IntegerProxy([_gl.GL_MAX_UNIFORM_BUFFER_BINDINGS]) 252 max_uniform_block_size = IntegerProxy([_gl.GL_MAX_UNIFORM_BLOCK_SIZE]) 253 max_varying_vectors = IntegerProxy([_gl.GL_MAX_VARYING_VECTORS]) 254 max_vertex_attribs = IntegerProxy([_gl.GL_MAX_VERTEX_ATTRIBS]) 255 max_vertex_texture_image_units = IntegerProxy([_gl.GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS]) 256 max_vertex_uniform_components = IntegerProxy([_gl.GL_MAX_VERTEX_UNIFORM_COMPONENTS]) 257 max_vertex_uniform_vectors = IntegerProxy([_gl.GL_MAX_VERTEX_UNIFORM_VECTORS]) 258 max_vertex_output_components = IntegerProxy([_gl.GL_MAX_VERTEX_OUTPUT_COMPONENTS]) 259 max_vertex_uniform_blocks = IntegerProxy([_gl.GL_MAX_VERTEX_UNIFORM_BLOCKS]) 260 max_viewport_dims = IntegerProxy([_gl.GL_MAX_VIEWPORT_DIMS]) 261 max_viewports = IntegerProxy([_gl.GL_MAX_VIEWPORTS]) 262 minor_version = IntegerProxy([_gl.GL_MINOR_VERSION]) 263 pack_alignment = IntegerProxy([_gl.GL_PACK_ALIGNMENT]) 264 pack_image_height = IntegerProxy([_gl.GL_PACK_IMAGE_HEIGHT]) 265 pack_row_length = IntegerProxy([_gl.GL_PACK_ROW_LENGTH], _gl.glPixelStorei, [_gl.GL_PACK_ROW_LENGTH]) 266 pack_skip_images = IntegerProxy([_gl.GL_PACK_SKIP_IMAGES], _gl.glPixelStorei, [_gl.GL_PACK_SKIP_IMAGES]) 267 pack_skip_pixels = IntegerProxy([_gl.GL_PACK_SKIP_PIXELS], _gl.glPixelStorei, [_gl.GL_PACK_SKIP_PIXELS]) 268 pack_skip_rows = IntegerProxy([_gl.GL_PACK_SKIP_ROWS], _gl.glPixelStorei, [_gl.GL_PACK_SKIP_ROWS]) 269 primitive_restart_index = IntegerProxy([_gl.GL_PRIMITIVE_RESTART_INDEX], _gl.glPrimitiveRestartIndex) 270 sample_buffers = IntegerProxy([_gl.GL_SAMPLE_BUFFERS]) 271 samples = IntegerProxy([_gl.GL_SAMPLES]) 272 scissor_box = IntegerProxy([_gl.GL_SCISSOR_BOX], _gl.glScissor, shape=4) 273 stencil_clear_value = IntegerProxy([_gl.GL_STENCIL_CLEAR_VALUE], _gl.glClearStencil) 274 subpixel_bits = IntegerProxy([_gl.GL_SUBPIXEL_BITS]) 275 uniform_buffer_offset_alignment = IntegerProxy([_gl.GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT]) 276 unpack_alignment = IntegerProxy([_gl.GL_UNPACK_ALIGNMENT], _gl.glPixelStorei, [_gl.GL_UNPACK_ALIGNMENT]) 277 unpack_image_height = IntegerProxy([_gl.GL_UNPACK_IMAGE_HEIGHT], _gl.glPixelStorei, [_gl.GL_UNPACK_IMAGE_HEIGHT]) 278 unpack_row_length = IntegerProxy([_gl.GL_UNPACK_ROW_LENGTH], _gl.glPixelStorei, [_gl.GL_UNPACK_ROW_LENGTH]) 279 unpack_skip_images = IntegerProxy([_gl.GL_UNPACK_SKIP_IMAGES], _gl.glPixelStorei, [_gl.GL_UNPACK_SKIP_IMAGES]) 280 unpack_skip_pixels = IntegerProxy([_gl.GL_UNPACK_SKIP_PIXELS], _gl.glPixelStorei, [_gl.GL_UNPACK_SKIP_PIXELS]) 281 unpack_skip_rows = IntegerProxy([_gl.GL_UNPACK_SKIP_ROWS], _gl.glPixelStorei, [_gl.GL_UNPACK_SKIP_ROWS]) 282 viewport = IntegerProxy([_gl.GL_VIEWPORT], _gl.glViewport, shape=4) 283 viewport_bounds_range = IntegerProxy([_gl.GL_VIEWPORT_BOUNDS_RANGE], shape=2) 284 viewport_subpixel_bits = IntegerProxy([_gl.GL_VIEWPORT_SUBPIXEL_BITS]) 285 286 #{ 64-bit integer values 287 timestamp = Integer64Proxy([_gl.GL_TIMESTAMP]) 288 289 #{ Strings 290 vendor = StringProxy(_gl.GL_VENDOR) 291 renderer = StringProxy(_gl.GL_RENDERER) 292 version = StringProxy(_gl.GL_VERSION) 293 shading_language_version = StringProxy(_gl.GL_SHADING_LANGUAGE_VERSION) 294 extensions = StringProxy(_gl.GL_EXTENSIONS, _gl.GL_NUM_EXTENSIONS) 295 296 #{ Global actions 297
298 - def _perform_gl_clear(self, color=None, depth=None, stencil=None):
299 """Call C{glClear} with appropriate arguments. 300 301 @param color: Whether to clear the color buffer, and optionally, to which value. 302 @type color: C{bool} or C{numpy.ndarray}. 303 @param depth: Whether to clear the depth buffer, and optionally, to which value. 304 @type depth: C{bool} or C{numpy.ndarray}. 305 @param stencil: Whether to clear the stencil buffer, and optionally, to which value. 306 @type stencil: C{bool} or C{numpy.ndarray}. 307 308 If no parameters are given, color, depth and stencil are cleared with 309 the current clear values. 310 311 @todo: Wrap the C{glClear} call in C{with State()} to set and reset 312 L{color_clear_value}, C{depth_clear_value} and C{stencil_clear_value} 313 if these are given as C{numpy} arrays in C{color}, C{depth}, and 314 C{stencil}, respectively. 315 """ 316 317 if color is None and depth is None and stencil is None: 318 color = depth = stencil = True 319 _gl.glClear( 320 (_gl.GL_COLOR_BUFFER_BIT if color else 0) | 321 (_gl.GL_DEPTH_BUFFER_BIT if depth else 0) | 322 (_gl.GL_STENCIL_BUFFER_BIT if stencil else 0) 323 )
324
325 - def clear(self, color=None, depth=None, stencil=None):
326 """Clear the default framebuffer. 327 328 @param color: Whether to clear the color buffer, and optionally, to which value. 329 @type color: C{bool} or C{numpy.ndarray}. 330 @param depth: Whether to clear the depth buffer, and optionally, to which value. 331 @type depth: C{bool} or C{numpy.ndarray}. 332 @param stencil: Whether to clear the stencil buffer, and optionally, to which value. 333 @type stencil: C{bool} or C{numpy.ndarray}. 334 335 If no parameters are given, color, depth and stencil are cleared with 336 the current clear values. 337 """ 338 339 with self: 340 with State(self, draw_framebuffer_binding=None): 341 self._perform_gl_clear(color, depth, stencil)
342
343 - def finish(self):
344 """Block until all GL execution is complete. 345 346 C{finish} does not return until the effects of all previously called GL 347 commands are complete. Such effects include all changes to GL state, 348 all changes to connection state, and all changes to the frame buffer 349 contents. 350 """ 351 352 with self: 353 _gl.glFinish()
354
355 - def flush(self):
356 """Force execution of GL commands in finite time. 357 358 Different GL implementations buffer commands in several different 359 locations, including network buffers and the graphics accelerator 360 itself. C{flush} empties all of these buffers, causing all issued 361 commands to be executed as quickly as they are accepted by the actual 362 rendering engine. Though this execution may not be completed in any 363 particular time period, it does complete in finite time. 364 365 Because any GL program might be executed over a network, or on an 366 accelerator that buffers commands, all programs should call C{flush} 367 whenever they count on having all of their previously issued commands 368 completed. For example, call C{flush} before waiting for user input 369 that depends on the generated image. 370 371 C{flush} can return at any time. It does not wait until the execution 372 of all previously issued GL commands is complete. 373 """ 374 375 with self: 376 _gl.glFlush()
377
378 - def release_shader_compiler(self):
379 with self: 380 _gl.glReleaseShaderCompiler()
381 382 #} 383 384 __all__ = ["Context"] 385