コード例 #1
0
ファイル: Texture.py プロジェクト: vupham26/pi3d
    def update_ndarray(self, new_array=None):
        """to allow numpy arrays to be patched in to textures without regenerating
    new glTextureBuffers i.e. for movie textures"""
        if new_array is not None:
            self.image = new_array
        opengles.glBindTexture(GL_TEXTURE_2D, self._tex)
        # set filters according to mipmap and filter request
        for t in [GL_TEXTURE_MIN_FILTER, GL_TEXTURE_MAG_FILTER]:
            opengles.glTexParameteri(GL_TEXTURE_2D, t, self._get_filter(t))

        opengles.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
                                 self.m_repeat)
        opengles.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
                                 self.m_repeat)

        iformat = self._get_format_from_array(self.image, self.i_format)
        opengles.glTexImage2D(
            GL_TEXTURE_2D, 0, iformat, self.ix, self.iy, 0, iformat,
            GL_UNSIGNED_BYTE,
            self.image.ctypes.data_as(ctypes.POINTER(ctypes.c_ubyte)))
        if opengles.glGetError() == GL_OUT_OF_MEMORY:
            LOGGER.critical('Out of GPU memory')
        #opengles.glEnable(GL_TEXTURE_2D) # invalid in OpenGLES 2
        if self.mipmap:
            opengles.glGenerateMipmap(GL_TEXTURE_2D)

        if self.free_after_load:
            self.image = None
            self._loaded = False
コード例 #2
0
    def update_ndarray(self, new_array=None, texture_num=None):
        """to allow numpy arrays to be patched in to textures without regenerating
    new glTextureBuffers i.e. for movie textures
    
      *new_array*
        ndarray, if supplied this will be the pixel data for the new
        Texture2D
        
      *texture_num*
        int, if supplied this will make the update effective for a specific
        sampler number i.e. as held in the Buffer.textures array. This
        will be required where multiple textures are used on some of the
        Buffers being drawn in the scene"""

        if new_array is not None:
            self.image = new_array
        if texture_num is not None:
            opengles.glActiveTexture(GL_TEXTURE0 + texture_num)
        opengles.glBindTexture(GL_TEXTURE_2D, self._tex)
        # set filters according to mipmap and filter request
        for t in [GL_TEXTURE_MIN_FILTER, GL_TEXTURE_MAG_FILTER]:
            opengles.glTexParameteri(GL_TEXTURE_2D, t, self._get_filter(t))

        opengles.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
                                 self.m_repeat)
        opengles.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
                                 self.m_repeat)

        iformat = self._get_format_from_array(self.image, self.i_format)
        opengles.glTexImage2D(
            GL_TEXTURE_2D, 0, iformat, self.ix, self.iy, 0, iformat,
            GL_UNSIGNED_BYTE,
            self.image.ctypes.data_as(ctypes.POINTER(ctypes.c_ubyte)))
        if opengles.glGetError() == GL_OUT_OF_MEMORY:
            LOGGER.critical('Out of GPU memory in Texture.update_ndarray')
        #opengles.glEnable(GL_TEXTURE_2D) # invalid in OpenGLES 2
        if self.mipmap:
            opengles.glGenerateMipmap(GL_TEXTURE_2D)

        if self.free_after_load:
            self.image = None
            self.file_string = None
            self._loaded = False