Class GLTexture

  • All Implemented Interfaces:
    Disposable
    Direct Known Subclasses:
    Cubemap, Texture, Texture3D, TextureArray

    public abstract class GLTexture
    extends java.lang.Object
    implements Disposable
    Class representing an OpenGL texture by its target and handle. Keeps track of its state like the TextureFilter and TextureWrap. Also provides some (protected) static methods to create TextureData and upload image data.
    • Constructor Detail

      • GLTexture

        public GLTexture​(int glTarget)
        Generates a new OpenGL texture with the specified target.
      • GLTexture

        public GLTexture​(int glTarget,
                         int glHandle)
    • Method Detail

      • getWidth

        public abstract int getWidth()
        Returns:
        the width of the texture in pixels
      • getHeight

        public abstract int getHeight()
        Returns:
        the height of the texture in pixels
      • getDepth

        public abstract int getDepth()
        Returns:
        the depth of the texture in pixels
      • isManaged

        public abstract boolean isManaged()
        Returns:
        whether this texture is managed or not.
      • reload

        protected abstract void reload()
      • bind

        public void bind()
        Binds this texture. The texture will be bound to the currently active texture unit specified via GL20.glActiveTexture(int).
      • bind

        public void bind​(int unit)
        Binds the texture to the given texture unit. Sets the currently active texture unit via GL20.glActiveTexture(int).
        Parameters:
        unit - the unit (0 to MAX_TEXTURE_UNITS).
      • getTextureObjectHandle

        public int getTextureObjectHandle()
        Returns:
        The OpenGL handle for this texture.
      • unsafeSetWrap

        public void unsafeSetWrap​(Texture.TextureWrap u,
                                  Texture.TextureWrap v,
                                  boolean force)
        Sets the Texture.TextureWrap for this texture on the u and v axis. Assumes the texture is bound and active!
        Parameters:
        u - the u wrap
        v - the v wrap
        force - True to always set the values, even if they are the same as the current values.
      • unsafeSetFilter

        public void unsafeSetFilter​(Texture.TextureFilter minFilter,
                                    Texture.TextureFilter magFilter)
        Sets the Texture.TextureFilter for this texture for minification and magnification. Assumes the texture is bound and active!
        Parameters:
        minFilter - the minification filter
        magFilter - the magnification filter
      • unsafeSetFilter

        public void unsafeSetFilter​(Texture.TextureFilter minFilter,
                                    Texture.TextureFilter magFilter,
                                    boolean force)
        Sets the Texture.TextureFilter for this texture for minification and magnification. Assumes the texture is bound and active!
        Parameters:
        minFilter - the minification filter
        magFilter - the magnification filter
        force - True to always set the values, even if they are the same as the current values.
      • unsafeSetAnisotropicFilter

        public float unsafeSetAnisotropicFilter​(float level)
        Sets the anisotropic filter level for the texture. Assumes the texture is bound and active!
        Parameters:
        level - The desired level of filtering. The maximum level supported by the device up to this value will be used.
        Returns:
        The actual level set, which may be lower than the provided value due to device limitations.
      • unsafeSetAnisotropicFilter

        public float unsafeSetAnisotropicFilter​(float level,
                                                boolean force)
        Sets the anisotropic filter level for the texture. Assumes the texture is bound and active!
        Parameters:
        level - The desired level of filtering. The maximum level supported by the device up to this value will be used.
        force - True to always set the value, even if it is the same as the current values.
        Returns:
        The actual level set, which may be lower than the provided value due to device limitations.
      • setAnisotropicFilter

        public float setAnisotropicFilter​(float level)
        Sets the anisotropic filter level for the texture. This will bind the texture!
        Parameters:
        level - The desired level of filtering. The maximum level supported by the device up to this value will be used.
        Returns:
        The actual level set, which may be lower than the provided value due to device limitations.
      • getAnisotropicFilter

        public float getAnisotropicFilter()
        Returns:
        The currently set anisotropic filtering level for the texture, or 1.0f if none has been set.
      • getMaxAnisotropicFilterLevel

        public static float getMaxAnisotropicFilterLevel()
        Returns:
        The maximum supported anisotropic filtering level supported by the device.
      • delete

        protected void delete()
        Destroys the OpenGL Texture as specified by the glHandle.
      • dispose

        public void dispose()
        Description copied from interface: Disposable
        Releases all resources of this object.
        Specified by:
        dispose in interface Disposable
      • uploadImageData

        protected static void uploadImageData​(int target,
                                              TextureData data)
      • uploadImageData

        public static void uploadImageData​(int target,
                                           TextureData data,
                                           int miplevel)