Class GlUtils


  • public final class GlUtils
    extends java.lang.Object
    • Method Detail

      • copyMatrix

        public static void copyMatrix​(@NonNull
                                      float[] src,
                                      @NonNull
                                      float[] dest)
      • getIdentityMatrix

        public static float[] getIdentityMatrix()
      • getNewIdentityMatrix

        public static float[] getNewIdentityMatrix()
      • initFloatBuffer

        public static java.nio.FloatBuffer initFloatBuffer​(float[] inFloatArray)
      • initColorArray

        public static void initColorArray​(float[] colorArray,
                                          int iColor)
      • detectOpenGLES20

        public static boolean detectOpenGLES20​(android.content.Context context)
      • loadShader

        public static int loadShader​(int shaderType,
                                     java.lang.String source)
        Compiles the provided shader source.
        Returns:
        A handle to the shader, or 0 on failure.
      • loadProgram

        public static int loadProgram​(@NonNull
                                      java.lang.String vertShaderSrc,
                                      @NonNull
                                      java.lang.String fragShaderSrc)
      • loadTextureFromFile

        public static int loadTextureFromFile​(@NonNull
                                              java.io.File file)
      • loadTextureFromBitmap

        public static int loadTextureFromBitmap​(@NonNull
                                                android.graphics.Bitmap bitmap)
      • loadTextureFromRawRes

        public static int loadTextureFromRawRes​(@RawRes
                                                int resID,
                                                android.content.Context context)
      • createTextureFromDrawable

        public static int createTextureFromDrawable​(android.graphics.drawable.Drawable drawable,
                                                    int width,
                                                    int height)
      • loadTextureLuminance

        public static int loadTextureLuminance​(@NonNull
                                               java.nio.ByteBuffer buffer,
                                               int width,
                                               int height,
                                               int format)
      • createExternalTextureObject

        public static int createExternalTextureObject()
      • setupBlend

        public static void setupBlend()
      • printGlInfo

        public static void printGlInfo()
      • setupVertexBuffer

        public static int setupVertexBuffer​(float[] vertexArray)
      • setupVertexTextureBuffers

        public static int[] setupVertexTextureBuffers​(float[] vertexArray,
                                                      float[] textureArray)
      • multiplyMM

        public static void multiplyMM​(float[] result,
                                      float[] lhs,
                                      float[] rhs)
      • multiplyMM4

        public static void multiplyMM4​(float[] result,
                                       float[] mat1,
                                       float[] mat2,
                                       float[] mat3,
                                       float[] mat4)
      • checkGlError

        public static void checkGlError​(java.lang.String op)
        Checks to see if a GLES error has been raised.
      • checkGlErrorNoException

        public static void checkGlErrorNoException​(java.lang.String op)
      • setupSampler

        public static void setupSampler​(int samplerIndex,
                                        int location,
                                        int texture,
                                        boolean external)
      • createProgram

        public static int createProgram​(java.lang.String vertexSource,
                                        java.lang.String fragmentSource)
        Creates a new program from the supplied vertex and fragment shaders.
        Returns:
        A handle to the program, or 0 on failure.
      • checkLocation

        public static void checkLocation​(int location,
                                         java.lang.String label)
        Checks to see if the location we obtained is valid. GLES returns -1 if a label could not be found, but does not set the GL error.

        Throws a RuntimeException if the location is invalid.

      • createImageTexture

        public static int createImageTexture​(java.nio.ByteBuffer data,
                                             int width,
                                             int height,
                                             int format)
        Creates a texture from raw data.
        Parameters:
        data - Image data, in a "direct" ByteBuffer.
        width - Texture width, in pixels (not bytes).
        height - Texture height, in pixels.
        format - Image data format (use constant appropriate for glTexImage2D(), e.g. GL_RGBA).
        Returns:
        Handle to texture.
      • createFloatBuffer

        public static java.nio.FloatBuffer createFloatBuffer​(float[] coords)
        Allocates a direct float buffer, and populates it with the float array data.
      • logVersionInfo

        public static void logVersionInfo()
        Writes GL version info to the log.
      • calculateCameraMatrix

        public static void calculateCameraMatrix​(float[] matrix,
                                                 float angle,
                                                 int flip)