Exemple #1
0
    def update_sub_surface( self,
                            texel_data,
                            transfer_pixels,
                            sub_surface_size, # updated region size
                            unpack_offset = None, # crop offset 
                            update_offset = None, # update offset
                            mipmap_level = 0,
                            data_format = None, # automatic guess unless set explicitly
                            data_type = None, # automatic guess unless set explicitly
                            ):
        # make myself the active texture
        gl.glBindTexture(self.target, self.gl_id)

        if data_format is None: # guess the format of the data
            if isinstance(texel_data,pygame.surface.Surface):
                if texel_data.get_alpha():
                    data_format = gl.GL_RGBA
                else:
                    data_format = gl.GL_RGB

        data_type = gl.GL_UNSIGNED_BYTE
        target = gl.GL_TEXTURE_2D
        
        if unpack_offset is None:
            unpack_offset = (0, 0)
        if update_offset is None:
            update_offset = (0, 0)
            
        width, _height = texel_data.get_size()
        if transfer_pixels or self.raw_data is None:
            if texel_data.get_alpha():
                self.raw_data = pygame.image.tostring(texel_data,'RGBA',1)
            else:
                self.raw_data = pygame.image.tostring(texel_data,'RGB',1)

        gl.glPixelStorei( gl.GL_UNPACK_ROW_LENGTH, width)
        gl.glPixelStorei( gl.GL_UNPACK_SKIP_PIXELS, unpack_offset[0])
        gl.glPixelStorei( gl.GL_UNPACK_SKIP_ROWS, unpack_offset[1])
        gl.glTexSubImage2D(target,
                           mipmap_level,
                           update_offset[0],
                           update_offset[1],
                           sub_surface_size[0],
                           sub_surface_size[1],
                           data_format,
                           data_type,
                           self.raw_data)
        gl.glPixelStorei( gl.GL_UNPACK_ROW_LENGTH, 0)
        gl.glPixelStorei( gl.GL_UNPACK_SKIP_PIXELS, 0)
        gl.glPixelStorei( gl.GL_UNPACK_SKIP_ROWS, 0)
Exemple #2
0
    def update_sub_surface( self,
                            texel_data,
                            transfer_pixels,
                            sub_surface_size, # updated region size
                            unpack_offset = None, # crop offset 
                            update_offset = None, # update offset
                            mipmap_level = 0,
                            data_format = None, # automatic guess unless set explicitly
                            data_type = None, # automatic guess unless set explicitly
                            ):
        # make myself the active texture
        gl.glBindTexture(self.target, self.gl_id)
        data_format = gl.GL_RGB
        data_type = gl.GL_UNSIGNED_BYTE
        target = gl.GL_TEXTURE_2D
        
        if unpack_offset is None:
            unpack_offset = (0, 0)
        if update_offset is None:
            update_offset = (0, 0)
            
        width, _height = texel_data.get_size()
        raw_data = np.frombuffer(self.buffer_data, 'B')

        gl.glPixelStorei( gl.GL_UNPACK_ROW_LENGTH, width)
        gl.glPixelStorei( gl.GL_UNPACK_SKIP_PIXELS, unpack_offset[0])
        gl.glPixelStorei( gl.GL_UNPACK_SKIP_ROWS, unpack_offset[1])
        gl.glTexSubImage2D(target,
                           mipmap_level,
                           update_offset[0],
                           update_offset[1],
                           sub_surface_size[0],
                           sub_surface_size[1],
                           data_format,
                           data_type,
                           raw_data)
        gl.glPixelStorei( gl.GL_UNPACK_ROW_LENGTH, 0)
        gl.glPixelStorei( gl.GL_UNPACK_SKIP_PIXELS, 0)
        gl.glPixelStorei( gl.GL_UNPACK_SKIP_ROWS, 0)