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