Class TextureData

java.lang.Object
com.jogamp.opengl.util.texture.TextureData
Direct Known Subclasses:
AWTTextureData

public class TextureData extends Object
Represents the data for an OpenGL texture. This is separated from the notion of a Texture to support things like streaming in of textures in a background thread without requiring an OpenGL context to be current on that thread.
Author:
Chris Campbell, Kenneth Russell, Sven Gothel
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    ColorSpace of pixel data.
    static interface 
    Defines a callback mechanism to allow the user to explicitly deallocate native resources (memory-mapped files, etc.) associated with a particular TextureData.
  • Constructor Summary

    Constructors
    Constructor
    Description
    TextureData(GLProfile glp, int internalFormat, int width, int height, int border, int pixelFormat, int pixelType, boolean mipmap, boolean dataIsCompressed, boolean mustFlipVertically, Buffer buffer, TextureData.Flusher flusher)
    Constructs a new TextureData object with the specified parameters and data contained in the given Buffer.
    TextureData(GLProfile glp, int internalFormat, int width, int height, int border, int pixelFormat, int pixelType, boolean dataIsCompressed, boolean mustFlipVertically, Buffer[] mipmapData, TextureData.Flusher flusher)
    Constructs a new TextureData object with the specified parameters and data for multiple mipmap levels contained in the given array of Buffers.
    TextureData(GLProfile glp, int internalFormat, int width, int height, int border, GLPixelBuffer.GLPixelAttributes pixelAttributes, boolean mipmap, boolean dataIsCompressed, boolean mustFlipVertically, Buffer buffer, TextureData.Flusher flusher)
    Constructs a new TextureData object with the specified parameters and data contained in the given Buffer.
    TextureData(GLProfile glp, int internalFormat, int width, int height, int border, GLPixelBuffer.GLPixelAttributes pixelAttributes, boolean dataIsCompressed, boolean mustFlipVertically, Buffer[] mipmapData, TextureData.Flusher flusher)
    Constructs a new TextureData object with the specified parameters and data for multiple mipmap levels contained in the given array of Buffers.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Calls flush()
    void
    Flushes resources associated with this TextureData by calling Flusher.flush().
    int
    Returns the required byte alignment for the texture data.
    int
    Returns the border in pixels of the texture data.
    Returns the texture data, or null if it is specified as a set of mipmaps.
    Returns the color space of the pixel data.
    int
    Returns an estimate of the amount of memory in bytes this TextureData will consume once uploaded to the graphics card.
    Returns the GLProfile this texture data is intended and created for.
    int
    Returns the height in pixels of the texture data.
    int
    Returns the intended OpenGL internal format of the texture data.
    boolean
    Returns whether mipmaps should be generated for the texture data.
    Returns all mipmap levels for the texture data, or null if it is specified as a single image.
    boolean
    Indicates whether the texture coordinates must be flipped vertically for proper display.
    Returns the intended OpenGL GLPixelBuffer.GLPixelAttributes of the texture data, i.e.
    int
    Returns the intended OpenGL pixel format of the texture data using getPixelAttributes().
    int
    Returns the intended OpenGL pixel type of the texture data using getPixelAttributes().
    int
    Returns the row length needed for correct GL_UNPACK_ROW_LENGTH specification.
    final ImageType
    Returns the source ImageType if applicable and known, otherwise null.
    int
    Returns the width in pixels of the texture data.
    boolean
    Indicates whether the texture data is in compressed form.
    void
    setAlignment(int alignment)
    Sets the required byte alignment for the texture data.
    void
    setBorder(int border)
    Sets the border in pixels of the texture data.
    void
    setBuffer(Buffer buffer)
    Sets the texture data.
    void
    Set the color space of the pixel data, which defaults to TextureData.ColorSpace.RGB.
    void
    setHaveEXTABGR(boolean haveEXTABGR)
    Indicates to this TextureData whether the GL_EXT_abgr extension is available.
    void
    setHaveGL12(boolean haveGL12)
    Indicates to this TextureData whether OpenGL version 1.2 is available.
    void
    setHeight(int height)
    Sets the height in pixels of the texture data.
    void
    setInternalFormat(int internalFormat)
    Sets the intended OpenGL internal format of the texture data.
    void
    setIsDataCompressed(boolean compressed)
    Sets whether the texture data is in compressed form.
    void
    setMipmap(boolean mipmap)
    Sets whether mipmaps should be generated for the texture data.
    void
    setMustFlipVertically(boolean mustFlipVertically)
    Sets whether the texture coordinates must be flipped vertically for proper display.
    void
    Sets the intended OpenGL pixel format of the texture data.
    void
    setPixelFormat(int pixelFormat)
    Sets the intended OpenGL pixel format component of GLPixelBuffer.GLPixelAttributes of the texture data.
    void
    setPixelType(int pixelType)
    Sets the intended OpenGL pixel type component of GLPixelBuffer.GLPixelAttributes of the texture data.
    void
    setRowLength(int rowLength)
    Sets the row length needed for correct GL_UNPACK_ROW_LENGTH specification.
    void
    setWidth(int width)
    Sets the width in pixels of the texture data.
     

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • TextureData

      public TextureData(GLProfile glp, int internalFormat, int width, int height, int border, int pixelFormat, int pixelType, boolean mipmap, boolean dataIsCompressed, boolean mustFlipVertically, Buffer buffer, TextureData.Flusher flusher) throws IllegalArgumentException
      Constructs a new TextureData object with the specified parameters and data contained in the given Buffer. The optional Flusher can be used to clean up native resources associated with this TextureData when processing is complete; for example, closing of memory-mapped files that might otherwise require a garbage collection to reclaim and close.
      Parameters:
      glp - the OpenGL Profile this texture data should be created for.
      internalFormat - the OpenGL internal format for the resulting texture; must be specified, may not be 0
      width - the width in pixels of the texture
      height - the height in pixels of the texture
      border - the number of pixels of border this texture data has (0 or 1)
      pixelFormat - the OpenGL pixel format for the resulting texture; must be specified, may not be 0
      pixelType - the OpenGL type of the pixels of the texture
      mipmap - indicates whether mipmaps should be autogenerated (using GLU) for the resulting texture. Currently if mipmap is true then dataIsCompressed may not be true.
      dataIsCompressed - indicates whether the texture data is in compressed form (e.g. GL_COMPRESSED_RGB_S3TC_DXT1_EXT)
      mustFlipVertically - indicates whether the texture coordinates must be flipped vertically in order to properly display the texture
      buffer - the buffer containing the texture data
      flusher - optional flusher to perform cleanup tasks upon call to flush()
      Throws:
      IllegalArgumentException - if any parameters of the texture data were invalid, such as requesting mipmap generation for a compressed texture
    • TextureData

      public TextureData(GLProfile glp, int internalFormat, int width, int height, int border, GLPixelBuffer.GLPixelAttributes pixelAttributes, boolean mipmap, boolean dataIsCompressed, boolean mustFlipVertically, Buffer buffer, TextureData.Flusher flusher) throws IllegalArgumentException
      Constructs a new TextureData object with the specified parameters and data contained in the given Buffer. The optional Flusher can be used to clean up native resources associated with this TextureData when processing is complete; for example, closing of memory-mapped files that might otherwise require a garbage collection to reclaim and close.
      Parameters:
      glp - the OpenGL Profile this texture data should be created for.
      internalFormat - the OpenGL internal format for the resulting texture; must be specified, may not be 0
      width - the width in pixels of the texture
      height - the height in pixels of the texture
      border - the number of pixels of border this texture data has (0 or 1)
      pixelAttributes - the OpenGL pixel format and type for the resulting texture; must be specified, may not be 0
      mipmap - indicates whether mipmaps should be autogenerated (using GLU) for the resulting texture. Currently if mipmap is true then dataIsCompressed may not be true.
      dataIsCompressed - indicates whether the texture data is in compressed form (e.g. GL_COMPRESSED_RGB_S3TC_DXT1_EXT)
      mustFlipVertically - indicates whether the texture coordinates must be flipped vertically in order to properly display the texture
      buffer - the buffer containing the texture data
      flusher - optional flusher to perform cleanup tasks upon call to flush()
      Throws:
      IllegalArgumentException - if any parameters of the texture data were invalid, such as requesting mipmap generation for a compressed texture
    • TextureData

      public TextureData(GLProfile glp, int internalFormat, int width, int height, int border, int pixelFormat, int pixelType, boolean dataIsCompressed, boolean mustFlipVertically, Buffer[] mipmapData, TextureData.Flusher flusher) throws IllegalArgumentException
      Constructs a new TextureData object with the specified parameters and data for multiple mipmap levels contained in the given array of Buffers. The optional Flusher can be used to clean up native resources associated with this TextureData when processing is complete; for example, closing of memory-mapped files that might otherwise require a garbage collection to reclaim and close.
      Parameters:
      glp - the OpenGL Profile this texture data should be created for.
      internalFormat - the OpenGL internal format for the resulting texture; must be specified, may not be 0
      width - the width in pixels of the topmost mipmap level of the texture
      height - the height in pixels of the topmost mipmap level of the texture
      border - the number of pixels of border this texture data has (0 or 1)
      pixelFormat - the OpenGL pixel format for the resulting texture; must be specified, may not be 0
      pixelType - the OpenGL type of the pixels of the texture
      dataIsCompressed - indicates whether the texture data is in compressed form (e.g. GL_COMPRESSED_RGB_S3TC_DXT1_EXT)
      mustFlipVertically - indicates whether the texture coordinates must be flipped vertically in order to properly display the texture
      mipmapData - the buffers containing all mipmap levels of the texture's data
      flusher - optional flusher to perform cleanup tasks upon call to flush()
      Throws:
      IllegalArgumentException - if any parameters of the texture data were invalid, such as requesting mipmap generation for a compressed texture
    • TextureData

      public TextureData(GLProfile glp, int internalFormat, int width, int height, int border, GLPixelBuffer.GLPixelAttributes pixelAttributes, boolean dataIsCompressed, boolean mustFlipVertically, Buffer[] mipmapData, TextureData.Flusher flusher) throws IllegalArgumentException
      Constructs a new TextureData object with the specified parameters and data for multiple mipmap levels contained in the given array of Buffers. The optional Flusher can be used to clean up native resources associated with this TextureData when processing is complete; for example, closing of memory-mapped files that might otherwise require a garbage collection to reclaim and close.
      Parameters:
      glp - the OpenGL Profile this texture data should be created for.
      internalFormat - the OpenGL internal format for the resulting texture; must be specified, may not be 0
      width - the width in pixels of the topmost mipmap level of the texture
      height - the height in pixels of the topmost mipmap level of the texture
      border - the number of pixels of border this texture data has (0 or 1)
      pixelAttributes - the OpenGL pixel format and type for the resulting texture; must be specified, may not be 0
      dataIsCompressed - indicates whether the texture data is in compressed form (e.g. GL_COMPRESSED_RGB_S3TC_DXT1_EXT)
      mustFlipVertically - indicates whether the texture coordinates must be flipped vertically in order to properly display the texture
      mipmapData - the buffers containing all mipmap levels of the texture's data
      flusher - optional flusher to perform cleanup tasks upon call to flush()
      Throws:
      IllegalArgumentException - if any parameters of the texture data were invalid, such as requesting mipmap generation for a compressed texture
  • Method Details

    • getColorSpace

      public TextureData.ColorSpace getColorSpace()
      Returns the color space of the pixel data.
      See Also:
    • setColorSpace

      public void setColorSpace(TextureData.ColorSpace cs)
      Set the color space of the pixel data, which defaults to TextureData.ColorSpace.RGB.
      See Also:
    • getSourceImageType

      public final ImageType getSourceImageType()
      Returns the source ImageType if applicable and known, otherwise null.
      Since:
      2.3.2
    • getWidth

      public int getWidth()
      Returns the width in pixels of the texture data.
    • getHeight

      public int getHeight()
      Returns the height in pixels of the texture data.
    • getBorder

      public int getBorder()
      Returns the border in pixels of the texture data.
    • getPixelAttributes

      public GLPixelBuffer.GLPixelAttributes getPixelAttributes()
      Returns the intended OpenGL GLPixelBuffer.GLPixelAttributes of the texture data, i.e. format and type.
    • getPixelFormat

      public int getPixelFormat()
      Returns the intended OpenGL pixel format of the texture data using getPixelAttributes().
    • getPixelType

      public int getPixelType()
      Returns the intended OpenGL pixel type of the texture data using getPixelAttributes().
    • getInternalFormat

      public int getInternalFormat()
      Returns the intended OpenGL internal format of the texture data.
    • getMipmap

      public boolean getMipmap()
      Returns whether mipmaps should be generated for the texture data.
    • isDataCompressed

      public boolean isDataCompressed()
      Indicates whether the texture data is in compressed form.
    • getMustFlipVertically

      public boolean getMustFlipVertically()
      Indicates whether the texture coordinates must be flipped vertically for proper display.
    • getBuffer

      public Buffer getBuffer()
      Returns the texture data, or null if it is specified as a set of mipmaps.
    • getMipmapData

      public Buffer[] getMipmapData()
      Returns all mipmap levels for the texture data, or null if it is specified as a single image.
    • getAlignment

      public int getAlignment()
      Returns the required byte alignment for the texture data.
    • getRowLength

      public int getRowLength()
      Returns the row length needed for correct GL_UNPACK_ROW_LENGTH specification. This is currently only supported for non-mipmapped, non-compressed textures.
    • setWidth

      public void setWidth(int width)
      Sets the width in pixels of the texture data.
    • setHeight

      public void setHeight(int height)
      Sets the height in pixels of the texture data.
    • setBorder

      public void setBorder(int border)
      Sets the border in pixels of the texture data.
    • setPixelAttributes

      public void setPixelAttributes(GLPixelBuffer.GLPixelAttributes pixelAttributes)
      Sets the intended OpenGL pixel format of the texture data.
    • setPixelFormat

      public void setPixelFormat(int pixelFormat)
      Sets the intended OpenGL pixel format component of GLPixelBuffer.GLPixelAttributes of the texture data.

      Use setPixelAttributes(GLPixelAttributes), if setting format and type.

    • setPixelType

      public void setPixelType(int pixelType)
      Sets the intended OpenGL pixel type component of GLPixelBuffer.GLPixelAttributes of the texture data.

      Use setPixelAttributes(GLPixelAttributes), if setting format and type.

    • setInternalFormat

      public void setInternalFormat(int internalFormat)
      Sets the intended OpenGL internal format of the texture data.
    • setMipmap

      public void setMipmap(boolean mipmap)
      Sets whether mipmaps should be generated for the texture data.
    • setIsDataCompressed

      public void setIsDataCompressed(boolean compressed)
      Sets whether the texture data is in compressed form.
    • setMustFlipVertically

      public void setMustFlipVertically(boolean mustFlipVertically)
      Sets whether the texture coordinates must be flipped vertically for proper display.
    • setBuffer

      public void setBuffer(Buffer buffer)
      Sets the texture data.
    • setAlignment

      public void setAlignment(int alignment)
      Sets the required byte alignment for the texture data.
    • setRowLength

      public void setRowLength(int rowLength)
      Sets the row length needed for correct GL_UNPACK_ROW_LENGTH specification. This is currently only supported for non-mipmapped, non-compressed textures.
    • setHaveEXTABGR

      public void setHaveEXTABGR(boolean haveEXTABGR)
      Indicates to this TextureData whether the GL_EXT_abgr extension is available. Used for optimization along some code paths to avoid data copies.
    • setHaveGL12

      public void setHaveGL12(boolean haveGL12)
      Indicates to this TextureData whether OpenGL version 1.2 is available. If not, falls back to relatively inefficient code paths for several input data types (several kinds of packed pixel formats, in particular).
    • getGLProfile

      public GLProfile getGLProfile()
      Returns the GLProfile this texture data is intended and created for.
    • getEstimatedMemorySize

      public int getEstimatedMemorySize()
      Returns an estimate of the amount of memory in bytes this TextureData will consume once uploaded to the graphics card. It should only be treated as an estimate; most applications should not need to query this but instead let the OpenGL implementation page textures in and out as necessary.
    • flush

      public void flush()
      Flushes resources associated with this TextureData by calling Flusher.flush().
    • destroy

      public void destroy()
      Calls flush()
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object