Class GLTexture

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class GLTexture
    extends java.lang.Object
    implements java.io.Closeable
    OpenGL texture
    • Constructor Summary

      Constructors 
      Constructor Description
      GLTexture​(int colorComponents)
      Create a new insance of GLTexture
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void associateWithUniformAndTextureUnit​(int uniformLocation, int textureUnitNumber)
      Associate this texture with uniform variable in the shader program, and set texture unit
      void bind()
      Bind this texture and setup texture sampler in the sahder.
      void close()
      Close resources
      int getTextureId()
      Get OpenGL texture ID
      void setTextureData​(java.nio.ByteBuffer data, int width, int height, int strideInPixels)
      Set texture data
      static void unbind()
      Unbind any previously bound shader program
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GLTexture

        public GLTexture​(int colorComponents)
        Create a new insance of GLTexture
        Parameters:
        colorComponents - number of the color components: 1 - for GL_LUMINANCE texture 2 - for GL_RG texture 3 - for GL_RGB texture 4 - for GL_RGBA texture
    • Method Detail

      • associateWithUniformAndTextureUnit

        public void associateWithUniformAndTextureUnit​(int uniformLocation,
                                                       int textureUnitNumber)
        Associate this texture with uniform variable in the shader program, and set texture unit
        Parameters:
        uniformLocation - uniform id
        textureUnitNumber -
        See Also:
        GLShaderProgram.getUniformLocation(String)
      • bind

        public void bind()
        Bind this texture and setup texture sampler in the sahder. (The method must have been called before associateWithUniformAndTextureUnit)
      • unbind

        public static void unbind()
        Unbind any previously bound shader program
      • setTextureData

        public void setTextureData​(java.nio.ByteBuffer data,
                                   int width,
                                   int height,
                                   int strideInPixels)
        Set texture data
        Parameters:
        data - image data
        width - width of the image
        height - height of the image
        strideInPixels - image stride in number of pixels
      • getTextureId

        public int getTextureId()
        Get OpenGL texture ID
        Returns:
        texture Id
      • close

        public void close()
        Close resources
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable