def __render_circle(self): if not self.__circle_ibo.cache.active_size: return with self.__circle_vao: with self.__circle_prgrm: # update uniforms camera = get_current_ogl( ).manager.window.devices.cameras.current self.__circle_prgrm.uniforms['PM'] = camera.body.PM self.__circle_prgrm.uniforms['VM'] = camera.tripod.VM self.__circle_prgrm.uniforms['MM'] = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]] pane = get_current_ogl().manager.window.devices.panes.current self.__circle_prgrm.uniforms[ 'VPP'] = *pane.pos.xy, *pane.size.xy self.__circle_prgrm.push_uniforms() self.__circle_ibo.push_cache() gl.glDrawElements(gl.GL_POINTS, self.__circle_ibo.cache.active_size, self.__circle_ibo.cache.gldtype[0], ctypes.c_void_p(0))
def enter(self): """ explicit context manager caller :return: """ get_current_ogl().entity_stacker[self.__class__].push(self) self.bind() return self
def render(self): if not self.__ibo.cache.active_size: return devices = get_current_ogl().manager.window.devices camera = devices.cameras.current self.__prgrm.uniforms['PM'] = camera.body.PM self.__prgrm.uniforms['VM'] = camera.tripod.VM self.__prgrm.uniforms['pane_size'] = devices.panes.current.glyph.size self.__prgrm.uniforms['LRBT'] = camera.body.dim[:4] self.__prgrm.uniforms['cam_near'] = camera.body.near self.__prgrm.uniforms['cam_ori'] = camera.tripod.plane.origin.T self.__prgrm.uniforms['fn_coord'] = camera.near_clipping_face self.__prgrm.uniforms['ff_coord'] = camera.far_clipping_face self.__prgrm.push_uniforms() self.__vbo.push_cache() self.__ibo.push_cache() with self.__prgrm: with self.__vao: gl.glDrawElements(gl.GL_POINTS, self.__ibo.cache.active_size, self.__ibo.cache.gldtype[0], ctypes.c_void_p(0))
def __enter__(self): super().enter() # bind draw buffers frame = get_current_ogl().entity_stacker[MetaFrameBffr].peek_if() if frame: self.draw_bffr.bind() return self
def __update_umiforms(self, prgrm): camera = get_current_ogl().manager.window.devices.cameras.current prgrm.uniforms['PM'] = camera.body.PM prgrm.uniforms['VM'] = camera.tripod.VM prgrm.uniforms['MM'] = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]] prgrm.push_uniforms()
def get_concrete(self): """ return correct entity for the context Lazy initiating. If context is not given, entity of current context will be returned. :return: entity for current context """ with self.__lock: c = get_current_ogl() if c is None: raise OpenglUnboundError # serve meta context not context meta = c.manager.meta_context # return if exists already if c in self.__context_entity: return self.__context_entity[c] if meta in self.__context_entity: return self.__context_entity[meta] # if not, create new and store with c: entity = self._create_entity() if not isinstance(entity, OGLEntity): raise Exception( 'creator method is not wrapped, check opengl_hooked') if entity.is_shared: self.__context_entity[meta] = entity else: self.__context_entity[c] = entity return entity
def __update_global_ufrm(self, prgrm): """ update transformation uniforms :return: """ camera = get_current_ogl().manager.window.devices.cameras.current prgrm.uniforms['PM'] = camera.body.PM prgrm.uniforms['VM'] = camera.tripod.VM prgrm.uniforms['MM'] = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]] prgrm.push_uniforms()
def exit(self): """ explicit context manager exit :return: """ stacker = get_current_ogl().entity_stacker[self.__class__] stacker.pop() if stacker.is_empty(): self.unbind() elif stacker.peek() != self: stacker.peek().bind()
def render(self): camera = get_current_ogl().manager.window.devices.cameras.current # update camera properties for block in self.__vbo.cache.blocks: block['near'] = camera.near_clipping_face[:3].T block['far'] = camera.far_clipping_face[:3].T self.__vbo.push_cache() self.__prgrm.uniforms['PM'] = camera.body.PM self.__prgrm.uniforms['VM'] = camera.tripod.VM self.__prgrm.push_uniforms() with self.__prgrm: with self.__vao: gl.glDrawArrays(gl.GL_QUADS, 0, 4)
def __render_sharp(self): if not self.__ibo.cache.active_size: return with self.__vao: with self.__sharp_prgrm: camera = get_current_ogl( ).manager.window.devices.cameras.current self.__sharp_prgrm.uniforms['VM'] = camera.tripod.VM self.__sharp_prgrm.uniforms['PM'] = camera.body.PM self.__sharp_prgrm.uniforms['MM'] = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]] self.__sharp_prgrm.push_uniforms() self.__ibo.push_cache() gl.glDrawElements(gl.GL_LINES, self.__ibo.cache.active_size, self.__ibo.cache.gldtype[0], ctypes.c_void_p(0))
def __render_square(self): if not self.__square_ibo.cache.active_size: return with self.__square_vao: with self.__square_prgrm: # update uniforms camera = get_current_ogl( ).manager.window.devices.cameras.current self.__square_prgrm.uniforms['PM'] = camera.body.PM self.__square_prgrm.uniforms['VM'] = camera.tripod.VM self.__square_prgrm.uniforms['MM'] = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]] self.__square_prgrm.push_uniforms() self.__square_ibo.push_cache() # mode, count, type, indices gl.glDrawElements(gl.GL_POINTS, self.__square_ibo.cache.active_size, self.__square_ibo.cache.gldtype[0], ctypes.c_void_p(0))
def render_world_space(self, texture, quad_pos, domain_x, domain_y): # update vrtx attributes (xs, xe), (ys, ye) = domain_x, domain_y self.__quad_block['tex_coord'] = (xs, ys), (xe, ys), (xe, ye), (xs, ye) self.__quad_block['coord'] = quad_pos self.__quad_vbo.push_cache() # render with texture: with self.__quad_vao: with self.__quad_prgrm: # update uniforms camera = get_current_ogl( ).manager.window.devices.cameras.current self.__quad_prgrm.uniforms['PM'] = camera.body.PM self.__quad_prgrm.uniforms['VM'] = camera.tripod.VM self.__quad_prgrm.uniforms['MM'] = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]] self.__quad_prgrm.push_uniforms() gl.glDrawArrays(gl.GL_QUADS, 0, 4)
def exit(self): stacker = get_current_ogl().entity_stacker[self.__class__] stacker.pop() if stacker and stacker.peek() != self: stacker.peek().bind()
def enter(self): get_current_ogl().entity_stacker.push(self) self.bind()