• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package android.opengl.cts;
17 
18 import java.nio.FloatBuffer;
19 
20 import javax.microedition.khronos.opengles.GL10;
21 
22 import android.opengl.GLES20;
23 import android.opengl.GLSurfaceView;
24 import android.opengl.GLSurfaceView.Renderer;
25 
26 import java.util.concurrent.CountDownLatch;
27 
28 public abstract class RendererBase implements GLSurfaceView.Renderer {
29 
30     FloatBuffer floatBuffer;
31     int mProgram;
32     int maPositionHandle;
33     float[] mColorOne = new float[4];
34 
35     int[] mShaderCount = null;
36     int mError;
37     String mInfoLog = null;
38 
39     // child may need to manipulate them directly
40     protected CountDownLatch mLatch;
41     protected boolean mDrawn = false;
42 
RendererBase(CountDownLatch latch)43     public RendererBase(CountDownLatch latch) {
44         mLatch = latch;
45     }
46 
47     @Override
onSurfaceChanged(GL10 gl, int width, int height)48     public void onSurfaceChanged(GL10 gl, int width, int height) {
49 
50     }
51 
loadShader(int type, String shaderCode)52     public int loadShader(int type, String shaderCode) {
53         int shader = GLES20.glCreateShader(type);
54         GLES20.glShaderSource(shader, shaderCode);
55         GLES20.glCompileShader(shader);
56         mInfoLog = GLES20.glGetShaderInfoLog(shader);
57         return shader;
58     }
59 
60     @Override
onDrawFrame(GL10 gl)61     public void onDrawFrame(GL10 gl) {
62         if (mDrawn) {
63             return;
64         }
65         mDrawn = true;
66         doOnDrawFrame(gl);
67         mLatch.countDown();
68     }
69 
70     /// dummy method to be overridden by child
doOnDrawFrame(GL10 gl)71     public void doOnDrawFrame(GL10 gl) {
72     }
73 }
74