OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TutorialView.java
Go to the documentation of this file.
1 /* Copyright (c) 2017, ARM Limited and Contributors
2  *
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge,
6  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19  */
20 
21 package com.arm.malideveloper.openglessdk.foveatedrendering;
22 
23 import android.content.Context;
24 import android.opengl.GLSurfaceView;
25 import javax.microedition.khronos.egl.EGL10;
26 import javax.microedition.khronos.egl.EGLConfig;
27 import javax.microedition.khronos.egl.EGLContext;
28 import javax.microedition.khronos.egl.EGLDisplay;
29 import javax.microedition.khronos.opengles.GL10;
30 
31 class TutorialView extends GLSurfaceView
32 {
33  protected int redSize = 5;
34  protected int greenSize = 6;
35  protected int blueSize = 5 ;
36  protected int alphaSize = 0;
37  protected int depthSize = 16;
38  protected int stencilSize = 0;
39  protected int[] value = new int [1];
40  static protected String privateAssetDirectory;
41  public TutorialView(Context context, String localFolder)
42  {
43  super(context);
44  privateAssetDirectory = localFolder;
45  setEGLContextFactory(new ContextFactory());
46  setEGLConfigChooser(new ConfigChooser());
47  setRenderer(new Renderer());
48  }
49 
50  private static class ContextFactory implements GLSurfaceView.EGLContextFactory
51  {
52  public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig)
53  {
54  final int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
55  int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };
56  EGLContext context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);
57  return context;
58  }
59 
60  public void destroyContext(EGL10 egl, EGLDisplay display, EGLContext context)
61  {
62  egl.eglDestroyContext(display, context);
63  }
64  }
65 
66  protected class ConfigChooser implements GLSurfaceView.EGLConfigChooser
67  {
68  public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display)
69  {
70  final int EGL_OPENGL_ES2_BIT = 4;
71  int[] configAttributes =
72  {
73  EGL10.EGL_RED_SIZE, redSize,
74  EGL10.EGL_GREEN_SIZE, greenSize,
75  EGL10.EGL_BLUE_SIZE, blueSize,
76  EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
77  EGL10.EGL_DEPTH_SIZE, depthSize,
78  EGL10.EGL_STENCIL_SIZE, stencilSize,
79  EGL10.EGL_NONE
80  };
81 
82  int[] num_config = new int[1];
83  egl.eglChooseConfig(display, configAttributes, null, 0, num_config);
84  int numConfigs = num_config[0];
85  EGLConfig[] configs = new EGLConfig[numConfigs];
86  egl.eglChooseConfig(display, configAttributes, configs, numConfigs, num_config);
87  return configs[0];
88  }
89 
90  }
91 
92  private static class Renderer implements GLSurfaceView.Renderer
93  {
94  public void onDrawFrame(GL10 gl)
95  {
96  NativeLibrary.step();
97  }
98 
99  public void onSurfaceChanged(GL10 gl, int width, int height)
100  {
101  NativeLibrary.init(width, height, privateAssetDirectory);
102  }
103 
104  public void onSurfaceCreated(GL10 gl, EGLConfig config)
105  {
106  }
107  }
108 }
GLint GLsizei GLsizei height
Definition: gl2ext.h:179
GLint value
Definition: gl2ext.h:558
EGLint configAttributes[]
Definition: ThreadSync.h:160
void destroyContext(EGL10 egl, EGLDisplay display, EGLContext context)
GLint GLsizei width
Definition: gl2ext.h:179
EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig)