示例#1
0
class QtTexture(Texture):
    def __init__(self):
        super().__init__()

        self._qt_texture = QOpenGLTexture(QOpenGLTexture.Target2D)
        self._gl = OpenGL.getInstance().getBindingsObject()
        self._file_name = None

    def getTextureId(self):
        return self._qt_texture.textureId()

    def bind(self, unit):
        if not self._qt_texture.isCreated():
            if self._file_name != None:
                image = QImage(self._file_name).mirrored()
            else:
                image = QImage(1, 1, QImage.Format_ARGB32)
            self._qt_texture.setData(image)
            self._qt_texture.setMinMagFilters(QOpenGLTexture.Linear, QOpenGLTexture.Linear)

        self._qt_texture.bind(unit)

    def release(self, unit):
        self._qt_texture.release(unit)

    def load(self, file_name):
        self._file_name = file_name
示例#2
0
class Texture:
    """A class describing the interface to be used for texture objects.

    This interface should be implemented by OpenGL implementations to handle texture
    objects.
    """
    def __init__(self,
                 open_gl_binding_object: QAbstractOpenGLFunctions) -> None:
        super().__init__()

        self._qt_texture = QOpenGLTexture(QOpenGLTexture.Target2D)
        self._gl = open_gl_binding_object
        self._file_name = None
        self._image = None

    def getTextureId(self) -> int:
        """Get the OpenGL ID of the texture."""
        return self._qt_texture.textureId()

    def bind(self, texture_unit):
        """Bind the texture to a certain texture unit.

        :param texture_unit: The texture unit to bind to.
        """
        if not self._qt_texture.isCreated():
            if self._file_name != None:
                self._image = QImage(self._file_name).mirrored()
            elif self._image is None:  # No filename or image set.
                self._image = QImage(1, 1, QImage.Format_ARGB32)
                self._image.fill(0)
            self._qt_texture.setData(self._image)
            self._qt_texture.setMinMagFilters(QOpenGLTexture.Linear,
                                              QOpenGLTexture.Linear)

        self._qt_texture.bind(texture_unit)

    def release(self, texture_unit):
        """Release the texture from a certain texture unit.

        :param texture_unit: The texture unit to release from.
        """
        self._qt_texture.release(texture_unit)

    def load(self, file_name):
        """Load an image and upload it to the texture.

        :param file_name: The file name of the image to load.
        """
        self._file_name = file_name
        # Actually loading the texture is postponed until the next bind() call.
        # This makes sure we are on the right thread and have a current context when trying to upload.

    def setImage(self, image):
        self._image = image
示例#3
0
class Texture:
    def __init__(self,
                 open_gl_binding_object: QAbstractOpenGLFunctions) -> None:
        super().__init__()

        self._qt_texture = QOpenGLTexture(QOpenGLTexture.Target2D)
        self._gl = open_gl_binding_object
        self._file_name = None
        self._image = None

    ##  Get the OpenGL ID of the texture.
    def getTextureId(self) -> int:
        return self._qt_texture.textureId()

    ##  Bind the texture to a certain texture unit.
    #
    #   \param texture_unit The texture unit to bind to.
    def bind(self, texture_unit):
        if not self._qt_texture.isCreated():
            if self._file_name != None:
                self._image = QImage(self._file_name).mirrored()
            elif self._image is None:  # No filename or image set.
                self._image = QImage(1, 1, QImage.Format_ARGB32)
                self._image.fill(0)
            self._qt_texture.setData(self._image)
            self._qt_texture.setMinMagFilters(QOpenGLTexture.Linear,
                                              QOpenGLTexture.Linear)

        self._qt_texture.bind(texture_unit)

    ##  Release the texture from a certain texture unit.
    #
    #   \param texture_unit The texture unit to release from.
    def release(self, texture_unit):
        self._qt_texture.release(texture_unit)

    ##  Load an image and upload it to the texture.
    #
    #   \param file_name The file name of the image to load.
    def load(self, file_name):
        self._file_name = file_name
        #Actually loading the texture is postponed until the next bind() call.
        #This makes sure we are on the right thread and have a current context when trying to upload.

    def setImage(self, image):
        self._image = image
示例#4
0
    def setUniformTexture(self, name, file):
        if not self._shader_program:
            return

        if name not in self._uniform_indices:
            self._uniform_indices[name] = self._shader_program.uniformLocation(name)

        index = self._uniform_indices[name]

        texture = QOpenGLTexture(QImage(file).mirrored())
        texture.setMinMagFilters(QOpenGLTexture.Linear, QOpenGLTexture.Linear)
        self._textures[index] = texture

        self._uniform_values[index] = 1

        if self._bound:
            texture = self._textures[index]
            texture.bind()
            self._setUniformValueDirect(index, texture.textureId())
示例#5
0
class Texture(object):
    def __init__(self, open_gl_binding_object):
        super().__init__()

        self._qt_texture = QOpenGLTexture(QOpenGLTexture.Target2D)
        self._gl = open_gl_binding_object
        self._file_name = None
        self._image = None

    ##  Get the OpenGL ID of the texture.
    def getTextureId(self):
        return self._qt_texture.textureId()

    ##  Bind the texture to a certain texture unit.
    #
    #   \param texture_unit The texture unit to bind to.
    def bind(self, texture_unit):
        if not self._qt_texture.isCreated():
            if self._file_name != None:
                self._image = QImage(self._file_name).mirrored()
            elif self._image is None: # No filename or image set.
                self._image = QImage(1, 1, QImage.Format_ARGB32)
                self._image.fill(0)
            self._qt_texture.setData(self._image)
            self._qt_texture.setMinMagFilters(QOpenGLTexture.Linear, QOpenGLTexture.Linear)

        self._qt_texture.bind(texture_unit)
    ##  Release the texture from a certain texture unit.
    #
    #   \param texture_unit The texture unit to release from.
    def release(self, texture_unit):
        self._qt_texture.release(texture_unit)

    ##  Load an image and upload it to the texture.
    #
    #   \param file_name The file name of the image to load.
    def load(self, file_name):
        self._file_name = file_name
        #Actually loading the texture is postponed until the next bind() call.
        #This makes sure we are on the right thread and have a current context when trying to upload.

    def setImage(self, image):
        self._image = image
示例#6
0
    def setUniformTexture(self, name, file):
        if not self._shader_program or self._disable_textures:
            return

        if name not in self._uniform_indices:
            self._uniform_indices[name] = self._shader_program.uniformLocation(
                name)

        index = self._uniform_indices[name]

        texture = QOpenGLTexture(QImage(file).mirrored())
        texture.setMinMagFilters(QOpenGLTexture.Linear, QOpenGLTexture.Linear)
        self._textures[index] = texture

        self._uniform_values[index] = 1

        if self._bound:
            texture = self._textures[index]
            texture.bind()
            self._setUniformValueDirect(index, texture.textureId())
示例#7
0
class QtTexture(Texture):
    def __init__(self):
        super().__init__()

        self._qt_texture = QOpenGLTexture(QOpenGLTexture.Target2D)
        self._qt_texture.setMinMagFilters(QOpenGLTexture.Linear, QOpenGLTexture.Linear)
        self._gl = OpenGL.getInstance().getBindingsObject()

    def getTextureId(self):
        return self._qt_texture.textureId()

    def bind(self, unit):
        self._qt_texture.bind(unit)

    def release(self, unit):
        self._qt_texture.release(unit)

    def load(self, file_name):
        image = QImage(file_name).mirrored()
        self._qt_texture.setData(image)
示例#8
0
class QtTexture(Texture):
    def __init__(self):
        super().__init__()

        self._qt_texture = QOpenGLTexture(QOpenGLTexture.Target2D)
        self._qt_texture.setMinMagFilters(QOpenGLTexture.Linear,
                                          QOpenGLTexture.Linear)
        self._gl = OpenGL.getInstance().getBindingsObject()

    def getTextureId(self):
        return self._qt_texture.textureId()

    def bind(self, unit):
        self._qt_texture.bind(unit)

    def release(self, unit):
        self._qt_texture.release(unit)

    def load(self, file_name):
        image = QImage(file_name).mirrored()
        self._qt_texture.setData(image)