示例#1
0
文件: texture.py 项目: joe311/vispy
 def _update(self):
     
     # If we use a 3D texture, we need an extension
     if self._target == gl.ext.GL_TEXTURE_3D:
         if not ext_available('GL_texture_3D'):
             raise TextureError('3D Texture not available.')
     
     # Need to update data?
     if self._pending_data:
         pendingData, self._pending_data = self._pending_data, None
         # Process pending data
         self._process_pending_data(*pendingData)
         # If not ok, warn (one time)
         if not gl.glIsTexture(self._handle):
             self._handle = 0
             print('Warning enabling texture, the texture is not valid.')
             return
     
     # Need to update some regions?
     while self._pending_subdata:
         pendingData = self._pending_subdata.pop(0)
         # Process pending data
         self._process_pending_data(*pendingData)
     
     # Check
     if not gl.glIsTexture(self._handle): 
         raise TextureError('This should not happen (texture is invalid)')
     
     # Need to update any parameters?
     self._activate()
     while self._pending_params:
         param, value = self._pending_params.popitem()
         gl.glTexParameter(self._target, param, value)
示例#2
0
文件: texture.py 项目: joe311/vispy
    def _update(self):

        # If we use a 3D texture, we need an extension
        if self._target == gl.ext.GL_TEXTURE_3D:
            if not ext_available('GL_texture_3D'):
                raise TextureError('3D Texture not available.')

        # Need to update data?
        if self._pending_data:
            pendingData, self._pending_data = self._pending_data, None
            # Process pending data
            self._process_pending_data(*pendingData)
            # If not ok, warn (one time)
            if not gl.glIsTexture(self._handle):
                self._handle = 0
                print('Warning enabling texture, the texture is not valid.')
                return

        # Need to update some regions?
        while self._pending_subdata:
            pendingData = self._pending_subdata.pop(0)
            # Process pending data
            self._process_pending_data(*pendingData)

        # Check
        if not gl.glIsTexture(self._handle):
            raise TextureError('This should not happen (texture is invalid)')

        # Need to update any parameters?
        self._activate()
        while self._pending_params:
            param, value = self._pending_params.popitem()
            gl.glTexParameter(self._target, param, value)
示例#3
0
文件: texture.py 项目: joe311/vispy
    def _process_pending_data(self, data, offset, level, format, clim):
        """ Process the pending data. Uploading the data (i.e. create
        a new texture) or updating it (a subsection).
        """

        if isinstance(data, np.ndarray):
            # Convert data type to one supported by OpenGL
            data = convert_data(data, clim)
            # Set shape
            shape = data.shape

            # If data is of same shape as current texture, update is much faster
            if not offset:
                MAP = {gl.GL_TEXTURE_2D: 2, gl.ext.GL_TEXTURE_3D: 3}
                ndim = MAP.get(self._target, 0)
                if data.shape == self._texture_shape and self._valid:
                    offset = [0 for i in self._texture_shape[:ndim]]

        elif isinstance(data, tuple):
            # Set shape
            shape = data
        else:
            raise TextureError('data is not a valid type, should not happen!')

        # Determine format (== internalformat)
        if format is None:
            format = get_format(shape, self._target)

        if offset:
            # Update: fast!
            gl.glBindTexture(self._target, self._handle)
            if self._handle <= 0 or not gl.glIsTexture(self._handle):
                raise TextureError(
                    'Cannot update texture if there is no texture.')
            self._upload_subdata(data, offset, format, level)

        else:
            # (re)upload: slower
            if self._valid:
                # We delete the existing texture first. In theory this
                # should not be necessary, but some implementations cause
                # memory leaks otherwise.
                self.delete()
                self._create()
            # Upload!
            self._activate()
            if isinstance(data, tuple):
                self._allocate_storage(shape, format, level)
            else:
                self._upload_data(data, format, level)
            # Set all parameters that the user set
            for param, value in self._texture_params.items():
                gl.glTexParameter(self._target, param, value)
            self._pending_params = {}  # We just applied all
示例#4
0
 def _update(self):
     
     # If we use a 3D texture, we need an extension
     if self._target == gl.ext.GL_TEXTURE_3D:
         if not ext_available('GL_texture_3D'):
             raise TextureError('3D Texture not available.')
     
     
     # For each level ...
     for texLevel in self._levels.values():
         
         # Need to resize?
         if texLevel.need_resize:
             texLevel.need_resize = False
             new_texture_created = False
             if self._valid and len(self._levels) == 1:
                 # We delete the existing texture first. In theory this
                 # should not be necessary, but some implementations cause
                 # memory leaks otherwise.
                 new_texture_created = True
                 self.delete() 
                 self._create()
             # Allocate texture on GPU
             gl.glBindTexture(self._target, self._handle)  #self._activate()
             self._allocate_shape(texLevel)
             # If not ok, warn (one time)
             if not gl.glIsTexture(self._handle):
                 self._handle = 0
                 print('Warning enabling texture, the texture is not valid.')
                 return
             if new_texture_created:
                 # We have a new texture: apply all parameters that were set
                 for param, value in self._texture_params.items():
                     gl.glTexParameter(self._target, param, value)
                     self._pending_params = {} # We just applied all 
         
         # Need to update some data?
         while texLevel.pending_data:
             data, clim, offset = texLevel.pending_data.pop(0)
             # Apply clim and convert data type to one supported by OpenGL
             data = convert_data(data, clim)
             # Upload
             gl.glBindTexture(self._target, self._handle)  # self._activate()
             self._upload_data(data, texLevel, offset)
     
     # Check
     #if not gl.glIsTexture(self._handle): 
     #    raise TextureError('This should not happen (texture is invalid)')
     
     # Need to update any parameters?
     gl.glBindTexture(self._target, self._handle)  # self._activate()
     while self._pending_params:
         param, value = self._pending_params.popitem()
         gl.glTexParameter(self._target, param, value)
示例#5
0
文件: texture.py 项目: joe311/vispy
 def _process_pending_data(self, data, offset, level, format, clim):
     """ Process the pending data. Uploading the data (i.e. create
     a new texture) or updating it (a subsection).
     """
     
     if isinstance(data, np.ndarray):
         # Convert data type to one supported by OpenGL
         data = convert_data(data, clim)
         # Set shape
         shape = data.shape
         
         # If data is of same shape as current texture, update is much faster
         if not offset:
             MAP = {gl.GL_TEXTURE_2D:2, gl.ext.GL_TEXTURE_3D:3}
             ndim = MAP.get(self._target, 0)
             if data.shape == self._texture_shape and self._valid:
                 offset = [0 for i in self._texture_shape[:ndim]]
     
     elif isinstance(data, tuple):
         # Set shape
         shape = data
     else:
         raise TextureError('data is not a valid type, should not happen!')
     
     # Determine format (== internalformat) 
     if format is None:
         format = get_format(shape, self._target)
     
     if offset:
         # Update: fast!
         gl.glBindTexture(self._target, self._handle)
         if self._handle <= 0 or not gl.glIsTexture(self._handle):
             raise TextureError('Cannot update texture if there is no texture.')
         self._upload_subdata(data, offset, format, level)
         
     else:
         # (re)upload: slower
         if self._valid:
             # We delete the existing texture first. In theory this
             # should not be necessary, but some implementations cause
             # memory leaks otherwise.
             self.delete() 
             self._create()
         # Upload!
         self._activate()
         if isinstance(data, tuple):
             self._allocate_storage(shape, format, level)
         else:
             self._upload_data(data, format, level)
         # Set all parameters that the user set
         for param, value in self._texture_params.items():
            gl.glTexParameter(self._target, param, value)
         self._pending_params = {} # We just applied all