Home | History | Annotate | Download | only in graphics
      1 /*
      2  * Copyright (C) 2013 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
      5  * in compliance with the License. You may obtain a copy of the License at
      6  *
      7  * http://www.apache.org/licenses/LICENSE-2.0
      8  *
      9  * Unless required by applicable law or agreed to in writing, software distributed under the License
     10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
     11  * or implied. See the License for the specific language governing permissions and limitations under
     12  * the License.
     13  */
     14 #ifndef GLUTILS_H
     15 #define GLUTILS_H
     16 
     17 #include <jni.h>
     18 
     19 #include <EGL/egl.h>
     20 #include <GLES2/gl2.h>
     21 #include <GLES2/gl2ext.h>
     22 
     23 #include "Mesh.h"
     24 
     25 class GLUtils {
     26 public:
     27     static void setEnvAndAssetManager(JNIEnv* env, jobject assetManager);
     28     // Loads a file from assets/path into a char array.
     29     static char* openTextFile(const char* path);
     30     // Loads a texture from assets/texture/<name>
     31     static GLuint loadTexture(const char* name);
     32     // Loads a mesh from assets/mesh/<name>
     33     static Mesh* loadMesh(const char* name);
     34     // Creates a program with the given vertex and fragment shader source code.
     35     static GLuint createProgram(const char** vertexSource, const char** fragmentSource);
     36     static double currentTimeMillis();
     37     // Rounds a number up to the smallest power of 2 that is greater than the original number.
     38     static int roundUpToSmallestPowerOf2(int x);
     39     static const int RANDOM_FILL = -1;
     40     // Generates a texture of the given dimensions. The texture can either be filled with the
     41     // specified fill color, else if RANDOM_FILL is passed in the texture will be filled with
     42     // random values.
     43     static GLuint genTexture(int texWidth, int texHeight, int fill);
     44     static bool createFBO(GLuint& fboId, GLuint& rboId, GLuint& cboId, int width, int height);
     45 };
     46 
     47 #endif
     48