コード例 #1
0
ファイル: glcontext.py プロジェクト: Parashurama/Kytten
 def delete(self):
     '''
     Destroy this framebuffer and free allocated resources.
     '''
     gl.glDeleteFramebuffersEXT(1, [self._buffer])
     gl.glDeleteTextures(1, [self.rgb_texture])
     self._buffer = None
コード例 #2
0
    def set_current(self):
        if not self.canvas:
            raise RuntimeError('Canvas has not been attached')
        # XXX not per-thread
        gl.current_context = self

        # XXX
        gl_info.set_active_context()
        glu_info.set_active_context()

        # Implement workarounds
        if not self._info:
            self._info = gl_info.GLInfo()
            self._info.set_active_context()
            for attr, check in self._workaround_checks:
                setattr(self, attr, check(self._info))

        # Release textures on this context scheduled for deletion
        if self.object_space._doomed_textures:
            textures = self.object_space._doomed_textures
            textures = (gl.GLuint * len(textures))(*textures)
            gl.glDeleteTextures(len(textures), textures)
            self.object_space._doomed_textures = []

        # Release buffers on this context scheduled for deletion
        if self.object_space._doomed_buffers:
            buffers = self.object_space._doomed_buffers
            buffers = (gl.GLuint * len(buffers))(*buffers)
            gl.glDeleteBuffers(len(buffers), buffers)
            self.object_space._doomed_buffers = []
コード例 #3
0
 def delete(self):
     for buffer in self.buffers:
         if self.buffers[buffer] is not None:
             if buffer != 'texture':
                 gl.glDeleteBuffers(1, self.buffers[buffer])
             else:
                 gl.glDeleteTextures(1, self.buffers['texture'])
コード例 #4
0
ファイル: textures.py プロジェクト: matthew-brett/miniglumpy
 def set_data(self, arr):
     arr = np.asarray(arr)
     self.src_format, self.dst_format = fmts_from_shape(arr.shape,
                                                        self._texture_dim)
     # Float is default type
     if arr.dtype == np.uint8:
         arr = np.ascontiguousarray(arr)
         self.src_type = gl.GL_UNSIGNED_BYTE
     elif arr.dtype == np.float32:
         arr = np.ascontiguousarray(arr)
         self.src_type = gl.GL_FLOAT
     else:
         arr = np.astype(np.float32)
         self.src_type = gl.GL_FLOAT
     self._arr = arr
     if self._id:
         gl.glDeleteTextures(1, gl.byref(self._id))
     id = gl.GLuint()
     gl.glGenTextures(1, gl.byref(id))
     self._id = id
     gl.glPixelStorei (gl.GL_UNPACK_ALIGNMENT, 1)
     gl.glPixelStorei (gl.GL_PACK_ALIGNMENT, 1)
     gl.glBindTexture (self.target, self._id)
     gl.glTexParameterf (self.target,
                         gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST)
     gl.glTexParameterf (self.target,
                         gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
     gl.glTexParameterf (self.target, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP)
     gl.glTexParameterf (self.target, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP)
     self._setup_tex()
     self.update()
コード例 #5
0
    def set_current(self):
        if not self.canvas:
            raise RuntimeError('Canvas has not been attached')

        # XXX not per-thread
        gl.current_context = self

        # XXX
        gl_info.set_active_context()

        if not self._info:
            self._info = gl_info.GLInfo()
            self._info.set_active_context()

        # Release Textures, Buffers, and VAOs on this context scheduled for
        # deletion. Note that the garbage collector may introduce a race
        # condition, so operate on a copy, and clear the list afterwards.
        if self.object_space.doomed_textures:
            textures = self.object_space.doomed_textures[:]
            textures = (gl.GLuint * len(textures))(*textures)
            gl.glDeleteTextures(len(textures), textures)
            self.object_space.doomed_textures.clear()
        if self.object_space.doomed_buffers:
            buffers = self.object_space.doomed_buffers[:]
            buffers = (gl.GLuint * len(buffers))(*buffers)
            gl.glDeleteBuffers(len(buffers), buffers)
            self.object_space.doomed_buffers.clear()
        if self.object_space.doomed_vaos:
            vaos = self.object_space.doomed_vaos[:]
            vaos = (gl.GLuint * len(vaos))(*vaos)
            gl.glDeleteVertexArrays(len(vaos), vaos)
            self.object_space.doomed_vaos.clear()
コード例 #6
0
ファイル: base.py プロジェクト: scotteifel/tasktrack
    def set_current(self):
        if not self.canvas:
            self.is_ok = 0
            raise RuntimeError('Canvas has not been attached')

        # XXX not per-thread
        gl.current_context = self

        # XXX
        gl_info.set_active_context()
        glu_info.set_active_context()

        # Implement workarounds
        if not self._info:
            self._info = gl_info.GLInfo()
            self._info.set_active_context()
            for attr, check in self._workaround_checks:
                setattr(self, attr, check(self._info))

        # Release textures and buffers on this context scheduled for deletion.
        # Note that the garbage collector may introduce a race condition,
        # so operate on a copy of the textures/buffers and remove the deleted
        # items using list slicing (which is an atomic operation)
        if self.object_space._doomed_textures:
            textures = self.object_space._doomed_textures[:]
            textures = (gl.GLuint * len(textures))(*textures)
            gl.glDeleteTextures(len(textures), textures)
            self.object_space._doomed_textures[0:len(textures)] = []
        if self.object_space._doomed_buffers:
            buffers = self.object_space._doomed_buffers[:]
            buffers = (gl.GLuint * len(buffers))(*buffers)
            gl.glDeleteBuffers(len(buffers), buffers)
            self.object_space._doomed_buffers[0:len(buffers)] = []
コード例 #7
0
ファイル: texture.py プロジェクト: encukou/pyglet_helper
 def gl_free(self):
     """
     Returns e.g. GL_TEXTURE_2D - the thing to be enabled to make this
         texture work with the fixed function pipeline.
     """
     print("Deleting texture number " + self.handle)
     glDeleteTextures(1, self.handle)
コード例 #8
0
    def set_current(self):
        if not self.canvas:
            raise RuntimeError('Canvas has not been attached')

        # XXX not per-thread
        gl.current_context = self

        # XXX
        gl_info.set_active_context()
        glu_info.set_active_context()

        # Implement workarounds
        if not self._info:
            self._info = gl_info.GLInfo()
            self._info.set_active_context()
            for attr, check in self._workaround_checks:
                setattr(self, attr, check(self._info))

        # Release textures and buffers on this context scheduled for deletion.
        # Note that the garbage collector may introduce a race condition,
        # so operate on a copy of the textures/buffers and remove the deleted
        # items using list slicing (which is an atomic operation)
        if self.object_space._doomed_textures:
            textures = self.object_space._doomed_textures[:]
            textures = (gl.GLuint * len(textures))(*textures)
            gl.glDeleteTextures(len(textures), textures)
            self.object_space._doomed_textures[0:len(textures)] = []
        if self.object_space._doomed_buffers:
            buffers = self.object_space._doomed_buffers[:]
            buffers = (gl.GLuint * len(buffers))(*buffers)
            gl.glDeleteBuffers(len(buffers), buffers)
            self.object_space._doomed_buffers[0:len(buffers)] = []
コード例 #9
0
 def gl_free(self):
     """
     Returns e.g. GL_TEXTURE_2D - the thing to be enabled to make this
         texture work with the fixed function pipeline.
     """
     print("Deleting texture number " + self.handle)
     glDeleteTextures(1, self.handle)
コード例 #10
0
    def release(texture_id):
        # If we have no context, then we are shutting down, so skip this
        if gl.current_context is None:
            return

        if texture_id.value != 0:
            gl.glDeleteTextures(1, byref(texture_id))
コード例 #11
0
ファイル: base.py プロジェクト: sabotage3d/kv6view
    def set_current(self):
        if not self.canvas:
            raise RuntimeError('Canvas has not been attached')
        # XXX not per-thread
        gl.current_context = self

        # XXX
        gl_info.set_active_context()
        glu_info.set_active_context()

        # Implement workarounds
        if not self._info:
            self._info = gl_info.GLInfo()
            self._info.set_active_context()
            for attr, check in self._workaround_checks:
                setattr(self, attr, check(self._info))

        # Release textures on this context scheduled for deletion
        if self.object_space._doomed_textures:
            textures = self.object_space._doomed_textures
            textures = (gl.GLuint * len(textures))(*textures)
            gl.glDeleteTextures(len(textures), textures)
            self.object_space._doomed_textures = []

        # Release buffers on this context scheduled for deletion
        if self.object_space._doomed_buffers:
            buffers = self.object_space._doomed_buffers
            buffers = (gl.GLuint * len(buffers))(*buffers)
            gl.glDeleteBuffers(len(buffers), buffers)
            self.object_space._doomed_buffers = []
コード例 #12
0
def deleteTexture(texture):
    """Free the resources associated with a texture. This invalidates the
    texture's ID.

    Returns
    -------
    :obj:`None'

    """
    GL.glDeleteTextures(1, texture.id)
コード例 #13
0
ファイル: fbo.py プロジェクト: encukou/gillcup_graphics
 def destroy(self):
     """Free memory"""
     if self.initialized:
         byref = ctypes.byref
         if self.framebuffer_id:
             gl.glDeleteFramebuffersEXT(1, byref(self.framebuffer_id))
         if self.depthbuffer_id:
             gl.glDeleteRenderbuffersEXT(1, byref(self.depthbuffer_id))
         if self.texture_id:
             gl.glDeleteTextures(1, byref(self.texture_id))
     self.initialized = False
コード例 #14
0
    def release(ctx: "Context", glo: gl.GLuint):
        """
        Destroy the texture.
        This is called automatically when the object is garbage collected.

        :param arcade.gl.Context ctx: OpenGL Context
        :param gl.GLuint glo: The OpenGL texture id
        """
        # If we have no context, then we are shutting down, so skip this
        if gl.current_context is None:
            return

        if glo.value != 0:
            gl.glDeleteTextures(1, byref(glo))

        ctx.stats.decr("texture")
コード例 #15
0
    def _invalidate_device_objects(self):
        if self._vao_handle.value > -1:
            gl.glDeleteVertexArrays(1, byref(self._vao_handle))
        if self._vbo_handle.value > -1:
            gl.glDeleteBuffers(1, byref(self._vbo_handle))
        if self._elements_handle.value > -1:
            gl.glDeleteBuffers(1, byref(self._elements_handle))
        self._vao_handle = self._vbo_handle = self._elements_handle = 0

        gl.glDeleteProgram(self._shader_handle)
        self._shader_handle = 0

        if self._font_texture.value > -1:
            gl.glDeleteTextures(1, byref(self._font_texture))
        self.io.fonts.texture_id = 0
        self._font_texture = 0
コード例 #16
0
 def __del__(self):
     self._face=None
     if self.atlas.texid:
         glDeleteTextures(1, self.atlas.texid)
         self.atlas.texid=None
         self.atlas=None
     if self.charcode2displaylist:
         for dl in self.charcode2displaylist.values():
             glDeleteLists(dl, 1)
         self.charcode2displaylist.clear()
     self.charcode2displaylist=None
     if self.charcode2glyph:
         self.charcode2glyph.clear()
         self.charcode2glyph=None
     if self.charcode2unichr:
         self.charcode2unichr.clear()
         self.charcode2unichr=None
コード例 #17
0
ファイル: fontmanager.py プロジェクト: Gianluigi/psychopy
 def __del__(self):
     self._face=None
     if self.atlas.texid:
         glDeleteTextures(1, self.atlas.texid)
         self.atlas.texid=None
         self.atlas=None
     if self.charcode2displaylist:
         for dl in self.charcode2displaylist.values():
             glDeleteLists(dl, 1)
         self.charcode2displaylist.clear()
     self.charcode2displaylist=None
     if self.charcode2glyph:
         self.charcode2glyph.clear()
         self.charcode2glyph=None
     if self.charcode2unichr:
         self.charcode2unichr.clear()
         self.charcode2unichr=None
コード例 #18
0
ファイル: base.py プロジェクト: scotteifel/tasktrack
    def delete_texture(self, texture_id):
        """Safely delete a texture belonging to this context.

        Usually, the texture is released immediately using
        ``glDeleteTextures``, however if another context that does not share
        this context's object space is currently active, the deletion will
        be deferred until an appropriate context is activated.

        :Parameters:
            `texture_id` : int
                The OpenGL name of the texture to delete.

        """
        if self.object_space is gl.current_context.object_space:
            id = gl.GLuint(texture_id)
            gl.glDeleteTextures(1, id)
        else:
            self.object_space._doomed_textures.append(texture_id)
コード例 #19
0
    def delete_texture(self, texture_id):
        '''Safely delete a texture belonging to this context.

        Usually, the texture is released immediately using
        ``glDeleteTextures``, however if another context that does not share
        this context's object space is currently active, the deletion will
        be deferred until an appropriate context is activated.

        :Parameters:
            `texture_id` : int
                The OpenGL name of the texture to delete.

        '''
        if self.object_space is gl.current_context.object_space:
            id = gl.GLuint(texture_id)
            gl.glDeleteTextures(1, id)
        else:
            self.object_space._doomed_textures.append(texture_id)
コード例 #20
0
    def refresh_font_texture(self):
        # save texture state

        last_texture = gl.GLint()
        gl.glGetIntegerv(gl.GL_TEXTURE_BINDING_2D, byref(last_texture))

        width, height, pixels = self.io.fonts.get_tex_data_as_rgba32()

        if self._font_texture is not None:
            gl.glDeleteTextures(1, self._font_texture)

        self._font_texture = gl.GLuint()
        gl.glGenTextures(1, byref(self._font_texture))

        gl.glBindTexture(gl.GL_TEXTURE_2D, self._font_texture)
        gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR)
        gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR)
        gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, width, height, 0, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, pixels)

        self.io.fonts.texture_id = self._font_texture
        gl.glBindTexture(gl.GL_TEXTURE_2D, cast((c_int*1)(last_texture), POINTER(c_uint)).contents)
        self.io.fonts.clear_tex_data()
コード例 #21
0
ファイル: glsl_tools.py プロジェクト: greyhill/volvis
 def __del__(self):
     if self.__value is not None:
         buf = ct.c_uint()
         buf.value = self.__value
         gl.glDeleteTextures(1, ct.byref(buf))
コード例 #22
0
ファイル: texture.py プロジェクト: johanfforsberg/fogl
 def delete(self):
     gl.glDeleteTextures(1, self.name)
コード例 #23
0
ファイル: textures.py プロジェクト: matthew-brett/miniglumpy
 def __del__(self):
     if self._id:
         gl.glDeleteTextures(1, gl.byref(self._id))
コード例 #24
0
ファイル: textureatlas.py プロジェクト: wilberth/psychopy
 def deleteTexture(self):
     if self.texid:
         glDeleteTextures(1, self.texid)
         self.texid=None
コード例 #25
0
def createFBO(width, height, colorFormat=GL.GL_RGBA8):
    """Generate a new Framebuffer object (FBO) for use as a render target.

    Parameters
    ----------
    width : :obj:`int`
        Buffer width in pixels.
    height : :obj:`int`
        Buffer height in pixels.
    colorFormat : :obj:`int`
        Format for color renderbuffer data (e.g. GL_RGBA8).

    Returns
    -------
    :obj:`list` of :obj:`int`
        List of OpenGL ids (FBO, Color Texture, Depth/Stencil RB).

    Examples
    --------
    # create a FBO
    frameBuffer, frameTexture, stencilTexture = createFBO(
        800, 600, GL.GL_RGBA32F_ARB)
    GL.glBindFramebuffer(GL.GL_FRAMEBUFFER, frameBuffer)  # bind it

    """
    # Create a texture render target for color data, same _setupFramebuffer()
    #
    # We should avoid creating a texture here in the future since we might want
    # to bind an existing texture from elsewhere and reuse the same FBO.
    #
    colorTextureId = GL.GLuint()
    GL.glGenTextures(1, ctypes.byref(colorTextureId))
    GL.glBindTexture(GL.GL_TEXTURE_2D, colorTextureId)
    GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER,
                       GL.GL_LINEAR)
    GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER,
                       GL.GL_LINEAR)
    GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, colorFormat, int(width), int(height),
                    0, GL.GL_RGBA, GL.GL_FLOAT, None)
    GL.glBindTexture(GL.GL_TEXTURE_2D, 0)

    fboId = GL.GLuint()
    GL.glGenFramebuffers(1, ctypes.byref(fboId))

    # attach texture to the frame buffer
    GL.glFramebufferTexture2D(GL.GL_FRAMEBUFFER, GL.GL_COLOR_ATTACHMENT0,
                              GL.GL_TEXTURE_2D, colorTextureId, 0)

    # create depth and stencil render buffers
    depthRbId = GL.GLuint()
    GL.glGenRenderbuffers(1, ctypes.byref(depthRbId))
    GL.glBindRenderbuffer(GL.GL_RENDERBUFFER, depthRbId)
    GL.glRenderbufferStorage(GL.GL_RENDERBUFFER, GL.GL_DEPTH24_STENCIL8,
                             int(width), int(height))
    GL.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_DEPTH_ATTACHMENT,
                                 GL.GL_RENDERBUFFER, depthRbId)
    GL.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_STENCIL_ATTACHMENT,
                                 GL.GL_RENDERBUFFER, depthRbId)
    GL.glBindRenderbuffer(GL.GL_RENDERBUFFER, 0)

    # clear VRAM garbage
    GL.glClear(GL.GL_STENCIL_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT
               | GL.GL_STENCIL_BUFFER_BIT)

    GL.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0)

    # check completeness
    if not checkFramebufferComplete(fboId):
        # delete the framebuffer and all the resources associated with it
        GL.glDeleteTextures(1, colorTextureId)
        GL.glDeleteRenderbuffers(1, depthRbId)
        GL.glDeleteFramebuffers(1, fboId)
        raise RuntimeError('Failed to create a framebuffer. Exiting.')

    return fboId, colorTextureId, depthRbId