├── .gitattributes ├── .gitignore ├── README.md ├── javadoc ├── allclasses-frame.html ├── allclasses-noframe.html ├── constant-values.html ├── deprecated-list.html ├── help-doc.html ├── index-files │ ├── index-1.html │ ├── index-10.html │ ├── index-11.html │ ├── index-2.html │ ├── index-3.html │ ├── index-4.html │ ├── index-5.html │ ├── index-6.html │ ├── index-7.html │ ├── index-8.html │ └── index-9.html ├── index.html ├── minus │ └── android │ │ └── support │ │ └── opengl │ │ ├── GLTextureView.EGLConfigChooser.html │ │ ├── GLTextureView.EGLContextFactory.html │ │ ├── GLTextureView.EGLWindowSurfaceFactory.html │ │ ├── GLTextureView.GLWrapper.html │ │ ├── GLTextureView.Renderer.html │ │ ├── GLTextureView.html │ │ ├── SystemProperties.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ └── package-tree.html ├── overview-tree.html ├── package-list ├── script.js └── stylesheet.css └── src ├── .gitignore ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── minus │ │ └── android │ │ └── opengl │ │ ├── GLES20ConfigChooser.java │ │ ├── GLES20ContextFactory.java │ │ ├── GLShape.java │ │ └── MainActivity.java │ └── res │ ├── drawable │ └── opengl_logo.png │ ├── layout │ └── activity_main.xml │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── libAndroidSupport ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── minus │ │ └── android │ │ └── support │ │ └── opengl │ │ ├── GLTextureView.java │ │ └── SystemProperties.java │ └── res │ └── values │ └── strings.xml └── settings.gradle /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | src/gradle.properties 20 | 21 | # Local configuration file (sdk path, etc) 22 | local.properties 23 | 24 | # Proguard folder generated by Eclipse 25 | proguard/ 26 | 27 | # Log Files 28 | *.log 29 | 30 | # Android Studio Navigation editor temp files 31 | .navigation/ 32 | 33 | # Android Studio captures folder 34 | captures/ 35 | 36 | # Intellij 37 | *.iml 38 | *.idea 39 | 40 | # Keystore files 41 | *.jks 42 | 43 | # ========================= 44 | # Operating System Files 45 | # ========================= 46 | 47 | # OSX 48 | # ========================= 49 | 50 | .DS_Store 51 | .AppleDouble 52 | .LSOverride 53 | 54 | # Thumbnails 55 | ._* 56 | 57 | # Files that might appear in the root of a volume 58 | .DocumentRevisions-V100 59 | .fseventsd 60 | .Spotlight-V100 61 | .TemporaryItems 62 | .Trashes 63 | .VolumeIcon.icns 64 | 65 | # Directories potentially created on remote AFP share 66 | .AppleDB 67 | .AppleDesktop 68 | Network Trash Folder 69 | Temporary Items 70 | .apdisk 71 | 72 | # Windows 73 | # ========================= 74 | 75 | # Windows image file caches 76 | Thumbs.db 77 | ehthumbs.db 78 | 79 | # Folder config file 80 | Desktop.ini 81 | 82 | # Recycle Bin used on file shares 83 | $RECYCLE.BIN/ 84 | 85 | # Windows Installer files 86 | *.cab 87 | *.msi 88 | *.msm 89 | *.msp 90 | 91 | # Windows shortcuts 92 | *.lnk 93 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GLTextureView 2 | 3 | ## Another Easy-way to Use OpenGL 4 | 5 | > GLSurfaceView is just one way to incorporate OpenGL ES graphics into your application. For a full-screen or near-full screen graphics view, it is a reasonable choice. Developers who want to incorporate OpenGL ES graphics in a small portion of their layouts should take a look at TextureView. For real, do-it-yourself developers, it is also possible to build up an OpenGL ES view using SurfaceView, but this requires writing quite a bit of additional code. 6 | See more on https://developer.android.com/training/graphics/opengl/environment.html 7 | 8 | ## GLSurfaceView v.s. GLTextureView 9 | 10 | ### GLSurfaceView 11 | - Two window. Host window manager the view hierarchy; And other surface window attarch to the host 12 | - 'Punches' a hole in its host window to allow its surface to be displayed, make it transparent region 13 | - GLSurfaceView.updateWindow() on onPreDraw(), different UI update time 14 | 15 | ### GLTextureView 16 | - Only one window 17 | - Behave the same as usual view, such as alpha and animation 18 | - Only be used in a hardware accelerated window 19 | 20 | GLTextureView can avoid drawing transparent region. In this case, user will see blocked graph not drawn by the current visible window. 21 | 22 | # Javadoc 23 | https://wtao901231.github.io/GLTextureView/javadoc/index.html 24 | -------------------------------------------------------------------------------- /javadoc/allclasses-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | All Classes 7 | 8 | 9 | 10 | 11 | 12 |

All Classes

13 |
14 | 23 |
24 | 25 | 26 | -------------------------------------------------------------------------------- /javadoc/allclasses-noframe.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | All Classes 7 | 8 | 9 | 10 | 11 | 12 |

All Classes

13 |
14 | 23 |
24 | 25 | 26 | -------------------------------------------------------------------------------- /javadoc/constant-values.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Constant Field Values 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
71 |

Constant Field Values

72 |

Contents

73 | 76 |
77 |
78 | 79 | 80 |

minus.android.*

81 | 149 |
150 | 151 |
152 | 153 | 154 |
Skip navigation links
155 | 156 | 157 | 158 | 166 |
167 | 194 | 195 | 196 | 197 | -------------------------------------------------------------------------------- /javadoc/deprecated-list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Deprecated List 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
71 |

Deprecated API

72 |

Contents

73 | 76 |
77 |
78 | 79 | 80 | 95 |
96 | 97 |
98 | 99 | 100 |
Skip navigation links
101 | 102 | 103 | 104 | 112 |
113 | 140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /javadoc/help-doc.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | API Help 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
71 |

How This API Document Is Organized

72 |
This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.
73 |
74 |
75 | 170 | This help file applies to API documentation generated using the standard doclet.
171 | 172 |
173 | 174 | 175 |
Skip navigation links
176 | 177 | 178 | 179 | 187 |
188 | 215 | 216 | 217 | 218 | -------------------------------------------------------------------------------- /javadoc/index-files/index-1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | C-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
C D F G M O P Q R S W  71 | 72 | 73 |

C

74 |
75 |
chooseConfig(EGL10, EGLDisplay) - Method in interface minus.android.support.opengl.GLTextureView.EGLConfigChooser
76 |
77 |
Choose a configuration from the list.
78 |
79 |
createContext(EGL10, EGLDisplay, EGLConfig) - Method in interface minus.android.support.opengl.GLTextureView.EGLContextFactory
80 |
 
81 |
createWindowSurface(EGL10, EGLDisplay, EGLConfig, Object) - Method in interface minus.android.support.opengl.GLTextureView.EGLWindowSurfaceFactory
82 |
 
83 |
84 | C D F G M O P Q R S W 
85 | 86 |
87 | 88 | 89 |
Skip navigation links
90 | 91 | 92 | 93 | 101 |
102 | 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /javadoc/index-files/index-10.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | S-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
C D F G M O P Q R S W  71 | 72 | 73 |

S

74 |
75 |
setDebugFlags(int) - Method in class minus.android.support.opengl.GLTextureView
76 |
77 |
Set the debug flags to a new value.
78 |
79 |
setEGLConfigChooser(GLTextureView.EGLConfigChooser) - Method in class minus.android.support.opengl.GLTextureView
80 |
81 |
Install a custom EGLConfigChooser.
82 |
83 |
setEGLConfigChooser(boolean) - Method in class minus.android.support.opengl.GLTextureView
84 |
85 |
Install a config chooser which will choose a config 86 | as close to 16-bit RGB as possible, with or without an optional depth 87 | buffer as close to 16-bits as possible.
88 |
89 |
setEGLConfigChooser(int, int, int, int, int, int) - Method in class minus.android.support.opengl.GLTextureView
90 |
91 |
Install a config chooser which will choose a config 92 | with at least the specified depthSize and stencilSize, 93 | and exactly the specified redSize, greenSize, blueSize and alphaSize.
94 |
95 |
setEGLContextClientVersion(int) - Method in class minus.android.support.opengl.GLTextureView
96 |
97 |
Inform the default EGLContextFactory and default EGLConfigChooser 98 | which EGLContext client version to pick.
99 |
100 |
setEGLContextFactory(GLTextureView.EGLContextFactory) - Method in class minus.android.support.opengl.GLTextureView
101 |
102 |
Install a custom EGLContextFactory.
103 |
104 |
setEGLWindowSurfaceFactory(GLTextureView.EGLWindowSurfaceFactory) - Method in class minus.android.support.opengl.GLTextureView
105 |
106 |
Install a custom EGLWindowSurfaceFactory.
107 |
108 |
setGLWrapper(GLTextureView.GLWrapper) - Method in class minus.android.support.opengl.GLTextureView
109 |
110 |
Set the glWrapper.
111 |
112 |
setPreserveEGLContextOnPause(boolean) - Method in class minus.android.support.opengl.GLTextureView
113 |
114 |
Control whether the EGL context is preserved when the GLTextureView is paused and 115 | resumed.
116 |
117 |
setRenderer(GLTextureView.Renderer) - Method in class minus.android.support.opengl.GLTextureView
118 |
119 |
Set the renderer associated with this view.
120 |
121 |
setRenderMode(int) - Method in class minus.android.support.opengl.GLTextureView
122 |
123 |
Set the rendering mode.
124 |
125 |
setSurfaceTextureListener(SurfaceTextureListener) - Method in class minus.android.support.opengl.GLTextureView
126 |
127 |
Deprecated.
128 |
129 |
SystemProperties - Class in minus.android.support.opengl
130 |
131 |
Gives access to the system properties store.
132 |
133 |
SystemProperties() - Constructor for class minus.android.support.opengl.SystemProperties
134 |
 
135 |
136 | C D F G M O P Q R S W 
137 | 138 |
139 | 140 | 141 |
Skip navigation links
142 | 143 | 144 | 145 | 153 |
154 | 181 | 182 | 183 | 184 | -------------------------------------------------------------------------------- /javadoc/index-files/index-11.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | W-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
C D F G M O P Q R S W  71 | 72 | 73 |

W

74 |
75 |
wrap(GL) - Method in interface minus.android.support.opengl.GLTextureView.GLWrapper
76 |
77 |
Wraps a gl interface in another gl interface.
78 |
79 |
80 | C D F G M O P Q R S W 
81 | 82 |
83 | 84 | 85 |
Skip navigation links
86 | 87 | 88 | 89 | 97 |
98 | 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /javadoc/index-files/index-2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | D-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
C D F G M O P Q R S W  71 | 72 | 73 |

D

74 |
75 |
DEBUG_CHECK_GL_ERROR - Static variable in class minus.android.support.opengl.GLTextureView
76 |
77 |
Check glError() after every GL call and throw an exception if glError indicates 78 | that an error has occurred.
79 |
80 |
DEBUG_LOG_GL_CALLS - Static variable in class minus.android.support.opengl.GLTextureView
81 |
82 |
Log GL calls to the system log at "verbose" level with tag "GLTextureView".
83 |
84 |
destroyContext(EGL10, EGLDisplay, EGLContext) - Method in interface minus.android.support.opengl.GLTextureView.EGLContextFactory
85 |
 
86 |
destroySurface(EGL10, EGLDisplay, EGLSurface) - Method in interface minus.android.support.opengl.GLTextureView.EGLWindowSurfaceFactory
87 |
 
88 |
89 | C D F G M O P Q R S W 
90 | 91 |
92 | 93 | 94 |
Skip navigation links
95 | 96 | 97 | 98 | 106 |
107 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /javadoc/index-files/index-3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | F-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
C D F G M O P Q R S W  71 | 72 | 73 |

F

74 |
75 |
finalize() - Method in class minus.android.support.opengl.GLTextureView
76 |
 
77 |
78 | C D F G M O P Q R S W 
79 | 80 |
81 | 82 | 83 |
Skip navigation links
84 | 85 | 86 | 87 | 95 |
96 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /javadoc/index-files/index-4.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | G-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
C D F G M O P Q R S W  71 | 72 | 73 |

G

74 |
75 |
get(String) - Static method in class minus.android.support.opengl.SystemProperties
76 |
77 |
Get the value for the given key.
78 |
79 |
get(String, String) - Static method in class minus.android.support.opengl.SystemProperties
80 |
81 |
Get the value for the given key.
82 |
83 |
getBoolean(String, boolean) - Static method in class minus.android.support.opengl.SystemProperties
84 |
85 |
Get the value for the given key, returned as a boolean.
86 |
87 |
getDebugFlags() - Method in class minus.android.support.opengl.GLTextureView
88 |
89 |
Get the current value of the debug flags.
90 |
91 |
getInt(String, int) - Static method in class minus.android.support.opengl.SystemProperties
92 |
93 |
Get the value for the given key, and return as an integer.
94 |
95 |
getLong(String, long) - Static method in class minus.android.support.opengl.SystemProperties
96 |
97 |
Get the value for the given key, and return as a long.
98 |
99 |
getPreserveEGLContextOnPause() - Method in class minus.android.support.opengl.GLTextureView
100 |
 
101 |
getRenderMode() - Method in class minus.android.support.opengl.GLTextureView
102 |
103 |
Get the current rendering mode.
104 |
105 |
GLTextureView - Class in minus.android.support.opengl
106 |
107 |
An implementation of TextureView that uses the dedicated surface for 108 | displaying OpenGL rendering.
109 |
110 |
GLTextureView(Context) - Constructor for class minus.android.support.opengl.GLTextureView
111 |
112 |
Standard View constructor.
113 |
114 |
GLTextureView(Context, AttributeSet) - Constructor for class minus.android.support.opengl.GLTextureView
115 |
116 |
Standard View constructor.
117 |
118 |
GLTextureView.EGLConfigChooser - Interface in minus.android.support.opengl
119 |
120 |
An interface for choosing an EGLConfig configuration from a list of 121 | potential configurations.
122 |
123 |
GLTextureView.EGLContextFactory - Interface in minus.android.support.opengl
124 |
125 |
An interface for customizing the eglCreateContext and eglDestroyContext calls.
126 |
127 |
GLTextureView.EGLWindowSurfaceFactory - Interface in minus.android.support.opengl
128 |
129 |
An interface for customizing the eglCreateWindowSurface and eglDestroySurface calls.
130 |
131 |
GLTextureView.GLWrapper - Interface in minus.android.support.opengl
132 |
133 |
An interface used to wrap a GL interface.
134 |
135 |
GLTextureView.Renderer - Interface in minus.android.support.opengl
136 |
137 |
A generic renderer interface.
138 |
139 |
140 | C D F G M O P Q R S W 
141 | 142 |
143 | 144 | 145 |
Skip navigation links
146 | 147 | 148 | 149 | 157 |
158 | 185 | 186 | 187 | 188 | -------------------------------------------------------------------------------- /javadoc/index-files/index-5.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | M-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
C D F G M O P Q R S W  71 | 72 | 73 |

M

74 |
75 |
minus.android.support.opengl - package minus.android.support.opengl
76 |
 
77 |
78 | C D F G M O P Q R S W 
79 | 80 |
81 | 82 | 83 |
Skip navigation links
84 | 85 | 86 | 87 | 95 |
96 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /javadoc/index-files/index-6.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | O-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
C D F G M O P Q R S W  71 | 72 | 73 |

O

74 |
75 |
onAttachedToWindow() - Method in class minus.android.support.opengl.GLTextureView
76 |
77 |
This method is used as part of the View class and is not normally 78 | called or subclassed by clients of GLTextureView.
79 |
80 |
onDetachedFromWindow() - Method in class minus.android.support.opengl.GLTextureView
81 |
 
82 |
onDrawFrame(GL10) - Method in interface minus.android.support.opengl.GLTextureView.Renderer
83 |
84 |
Called to draw the current frame.
85 |
86 |
onPause() - Method in class minus.android.support.opengl.GLTextureView
87 |
88 |
Inform the view that the activity is paused.
89 |
90 |
onResume() - Method in class minus.android.support.opengl.GLTextureView
91 |
92 |
Inform the view that the activity is resumed.
93 |
94 |
onSurfaceChanged(GL10, int, int) - Method in interface minus.android.support.opengl.GLTextureView.Renderer
95 |
96 |
Called when the surface changed size.
97 |
98 |
onSurfaceCreated(GL10, EGLConfig) - Method in interface minus.android.support.opengl.GLTextureView.Renderer
99 |
100 |
Called when the surface is created or recreated.
101 |
102 |
onSurfaceDestroyed() - Method in interface minus.android.support.opengl.GLTextureView.Renderer
103 |
 
104 |
onSurfaceTextureAvailable(SurfaceTexture, int, int) - Method in class minus.android.support.opengl.GLTextureView
105 |
 
106 |
onSurfaceTextureDestroyed(SurfaceTexture) - Method in class minus.android.support.opengl.GLTextureView
107 |
 
108 |
onSurfaceTextureSizeChanged(SurfaceTexture, int, int) - Method in class minus.android.support.opengl.GLTextureView
109 |
 
110 |
onSurfaceTextureUpdated(SurfaceTexture) - Method in class minus.android.support.opengl.GLTextureView
111 |
 
112 |
113 | C D F G M O P Q R S W 
114 | 115 |
116 | 117 | 118 |
Skip navigation links
119 | 120 | 121 | 122 | 130 |
131 | 158 | 159 | 160 | 161 | -------------------------------------------------------------------------------- /javadoc/index-files/index-7.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | P-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
C D F G M O P Q R S W  71 | 72 | 73 |

P

74 |
75 |
PROP_NAME_MAX - Static variable in class minus.android.support.opengl.SystemProperties
76 |
 
77 |
PROP_VALUE_MAX - Static variable in class minus.android.support.opengl.SystemProperties
78 |
 
79 |
80 | C D F G M O P Q R S W 
81 | 82 |
83 | 84 | 85 |
Skip navigation links
86 | 87 | 88 | 89 | 97 |
98 | 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /javadoc/index-files/index-8.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Q-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
C D F G M O P Q R S W  71 | 72 | 73 |

Q

74 |
75 |
queueEvent(Runnable) - Method in class minus.android.support.opengl.GLTextureView
76 |
77 |
Queue a runnable to be run on the GL rendering thread.
78 |
79 |
80 | C D F G M O P Q R S W 
81 | 82 |
83 | 84 | 85 |
Skip navigation links
86 | 87 | 88 | 89 | 97 |
98 | 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /javadoc/index-files/index-9.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | R-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
C D F G M O P Q R S W  71 | 72 | 73 |

R

74 |
75 |
RENDERMODE_CONTINUOUSLY - Static variable in class minus.android.support.opengl.GLTextureView
76 |
77 |
The renderer is called 78 | continuously to re-render the scene.
79 |
80 |
RENDERMODE_WHEN_DIRTY - Static variable in class minus.android.support.opengl.GLTextureView
81 |
82 |
The renderer only renders 83 | when the surface is created, or when GLTextureView.requestRender() is called.
84 |
85 |
requestRender() - Method in class minus.android.support.opengl.GLTextureView
86 |
87 |
Request that the renderer render a frame.
88 |
89 |
90 | C D F G M O P Q R S W 
91 | 92 |
93 | 94 | 95 |
Skip navigation links
96 | 97 | 98 | 99 | 107 |
108 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /javadoc/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Generated Documentation (Untitled) 7 | 59 | 60 | 61 | 62 | 63 | 64 | <noscript> 65 | <div>JavaScript is disabled on your browser.</div> 66 | </noscript> 67 | <h2>Frame Alert</h2> 68 | <p>This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to <a href="minus/android/support/opengl/package-summary.html">Non-frame version</a>.</p> 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /javadoc/minus/android/support/opengl/GLTextureView.EGLConfigChooser.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | GLTextureView.EGLConfigChooser 7 | 8 | 9 | 10 | 11 | 12 | 28 | 31 | 32 |
33 | 34 | 35 |
Skip navigation links
36 | 37 | 38 | 39 | 47 |
48 | 90 | 91 | 92 |
93 |
minus.android.support.opengl
94 |

Interface GLTextureView.EGLConfigChooser

95 |
96 |
97 |
98 | 114 |
115 |
116 | 142 |
143 |
144 | 177 |
178 |
179 | 180 | 181 |
182 | 183 | 184 |
Skip navigation links
185 | 186 | 187 | 188 | 196 |
197 | 239 | 240 | 241 | 242 | -------------------------------------------------------------------------------- /javadoc/minus/android/support/opengl/GLTextureView.EGLContextFactory.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | GLTextureView.EGLContextFactory 7 | 8 | 9 | 10 | 11 | 12 | 28 | 31 | 32 |
33 | 34 | 35 |
Skip navigation links
36 | 37 | 38 | 39 | 47 |
48 | 90 | 91 | 92 |
93 |
minus.android.support.opengl
94 |

Interface GLTextureView.EGLContextFactory

95 |
96 |
97 |
98 | 113 |
114 |
115 | 146 |
147 |
148 | 182 |
183 |
184 | 185 | 186 |
187 | 188 | 189 |
Skip navigation links
190 | 191 | 192 | 193 | 201 |
202 | 244 | 245 | 246 | 247 | -------------------------------------------------------------------------------- /javadoc/minus/android/support/opengl/GLTextureView.EGLWindowSurfaceFactory.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | GLTextureView.EGLWindowSurfaceFactory 7 | 8 | 9 | 10 | 11 | 12 | 28 | 31 | 32 |
33 | 34 | 35 |
Skip navigation links
36 | 37 | 38 | 39 | 47 |
48 | 90 | 91 | 92 |
93 |
minus.android.support.opengl
94 |

Interface GLTextureView.EGLWindowSurfaceFactory

95 |
96 |
97 |
98 | 113 |
114 |
115 | 147 |
148 |
149 | 188 |
189 |
190 | 191 | 192 |
193 | 194 | 195 |
Skip navigation links
196 | 197 | 198 | 199 | 207 |
208 | 250 | 251 | 252 | 253 | -------------------------------------------------------------------------------- /javadoc/minus/android/support/opengl/GLTextureView.GLWrapper.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | GLTextureView.GLWrapper 7 | 8 | 9 | 10 | 11 | 12 | 28 | 31 | 32 |
33 | 34 | 35 |
Skip navigation links
36 | 37 | 38 | 39 | 47 |
48 | 90 | 91 | 92 |
93 |
minus.android.support.opengl
94 |

Interface GLTextureView.GLWrapper

95 |
96 |
97 |
98 | 131 |
132 |
133 | 158 |
159 |
160 | 188 |
189 |
190 | 191 | 192 |
193 | 194 | 195 |
Skip navigation links
196 | 197 | 198 | 199 | 207 |
208 | 250 | 251 | 252 | 253 | -------------------------------------------------------------------------------- /javadoc/minus/android/support/opengl/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | minus.android.support.opengl 7 | 8 | 9 | 10 | 11 | 12 |

minus.android.support.opengl

13 |
14 |

Interfaces

15 | 22 |

Classes

23 | 27 |
28 | 29 | 30 | -------------------------------------------------------------------------------- /javadoc/minus/android/support/opengl/package-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | minus.android.support.opengl 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
71 |

Package minus.android.support.opengl

72 |
73 |
74 | 142 |
143 | 144 |
145 | 146 | 147 |
Skip navigation links
148 | 149 | 150 | 151 | 159 |
160 | 187 | 188 | 189 | 190 | -------------------------------------------------------------------------------- /javadoc/minus/android/support/opengl/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | minus.android.support.opengl Class Hierarchy 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
71 |

Hierarchy For Package minus.android.support.opengl

72 |
73 |
74 |

Class Hierarchy

75 | 87 |

Interface Hierarchy

88 | 95 |
96 | 97 |
98 | 99 | 100 |
Skip navigation links
101 | 102 | 103 | 104 | 112 |
113 | 140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /javadoc/overview-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Class Hierarchy 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
71 |

Hierarchy For All Packages

72 | Package Hierarchies: 73 | 76 |
77 |
78 |

Class Hierarchy

79 | 91 |

Interface Hierarchy

92 | 99 |
100 | 101 |
102 | 103 | 104 |
Skip navigation links
105 | 106 | 107 | 108 | 116 |
117 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /javadoc/package-list: -------------------------------------------------------------------------------- 1 | minus.android.support.opengl 2 | -------------------------------------------------------------------------------- /javadoc/script.js: -------------------------------------------------------------------------------- 1 | function show(type) 2 | { 3 | count = 0; 4 | for (var key in methods) { 5 | var row = document.getElementById(key); 6 | if ((methods[key] & type) != 0) { 7 | row.style.display = ''; 8 | row.className = (count++ % 2) ? rowColor : altColor; 9 | } 10 | else 11 | row.style.display = 'none'; 12 | } 13 | updateTabs(type); 14 | } 15 | 16 | function updateTabs(type) 17 | { 18 | for (var value in tabs) { 19 | var sNode = document.getElementById(tabs[value][0]); 20 | var spanNode = sNode.firstChild; 21 | if (value == type) { 22 | sNode.className = activeTableTab; 23 | spanNode.innerHTML = tabs[value][1]; 24 | } 25 | else { 26 | sNode.className = tableTab; 27 | spanNode.innerHTML = "" + tabs[value][1] + ""; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /src/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /src/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.3" 6 | defaultConfig { 7 | applicationId "minus.android.opengl" 8 | minSdkVersion 15 9 | targetSdkVersion 23 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | compile fileTree(dir: 'libs', include: ['*.jar']) 23 | compile project(':libAndroidSupport') 24 | } 25 | -------------------------------------------------------------------------------- /src/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /src/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 15 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/app/src/main/java/minus/android/opengl/GLES20ConfigChooser.java: -------------------------------------------------------------------------------- 1 | package minus.android.opengl; 2 | 3 | import android.opengl.GLSurfaceView; 4 | 5 | import javax.microedition.khronos.egl.EGL10; 6 | import javax.microedition.khronos.egl.EGLConfig; 7 | import javax.microedition.khronos.egl.EGLDisplay; 8 | 9 | import minus.android.support.opengl.GLTextureView; 10 | 11 | 12 | /** 13 | * Created by tagorewang on 2016/6/23. 14 | */ 15 | 16 | public class GLES20ConfigChooser implements GLSurfaceView.EGLConfigChooser, GLTextureView.EGLConfigChooser { 17 | 18 | private static int EGL_OPENGL_ES2_BIT = 4; 19 | private static int[] s_configAttribs2 = { 20 | EGL10.EGL_RED_SIZE, 4, 21 | EGL10.EGL_GREEN_SIZE, 4, 22 | EGL10.EGL_BLUE_SIZE, 4, 23 | EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, 24 | EGL10.EGL_NONE 25 | }; 26 | 27 | protected int mRedSize; 28 | protected int mGreenSize; 29 | protected int mBlueSize; 30 | protected int mAlphaSize; 31 | protected int mDepthSize; 32 | protected int mStencilSize; 33 | 34 | public GLES20ConfigChooser(int r, int g, int b, int a, int depth, int stencil) { 35 | mRedSize = r; 36 | mGreenSize = g; 37 | mBlueSize = b; 38 | mAlphaSize = a; 39 | mDepthSize = depth; 40 | mStencilSize = stencil; 41 | } 42 | 43 | @Override 44 | public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) { 45 | 46 | int[] num_config = new int[1]; 47 | egl.eglChooseConfig(display, s_configAttribs2, null, 0, num_config); 48 | 49 | int numConfigs = num_config[0]; 50 | 51 | if (numConfigs <= 0) { 52 | throw new IllegalArgumentException("No configs match configSpec"); 53 | } 54 | 55 | EGLConfig[] configs = new EGLConfig[numConfigs]; 56 | egl.eglChooseConfig(display, s_configAttribs2, configs, numConfigs, num_config); 57 | 58 | return chooseConfig(egl, display, configs); 59 | } 60 | 61 | public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display, EGLConfig[] configs) { 62 | for (EGLConfig config : configs) { 63 | int d = findConfigAttrib(egl, display, config, 64 | EGL10.EGL_DEPTH_SIZE, 0); 65 | int s = findConfigAttrib(egl, display, config, 66 | EGL10.EGL_STENCIL_SIZE, 0); 67 | 68 | if (d < mDepthSize || s < mStencilSize) 69 | continue; 70 | 71 | int r = findConfigAttrib(egl, display, config, 72 | EGL10.EGL_RED_SIZE, 0); 73 | int g = findConfigAttrib(egl, display, config, 74 | EGL10.EGL_GREEN_SIZE, 0); 75 | int b = findConfigAttrib(egl, display, config, 76 | EGL10.EGL_BLUE_SIZE, 0); 77 | int a = findConfigAttrib(egl, display, config, 78 | EGL10.EGL_ALPHA_SIZE, 0); 79 | 80 | if (r == mRedSize && g == mGreenSize && b == mBlueSize && a == mAlphaSize) 81 | return config; 82 | } 83 | return null; 84 | } 85 | 86 | private int findConfigAttrib(EGL10 egl, EGLDisplay display, EGLConfig config, int attribute, int defValue) { 87 | int[] outValue = new int[1]; 88 | if (egl.eglGetConfigAttrib(display, config, attribute, outValue)) { 89 | return outValue[0]; 90 | } 91 | return defValue; 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/app/src/main/java/minus/android/opengl/GLES20ContextFactory.java: -------------------------------------------------------------------------------- 1 | package minus.android.opengl; 2 | 3 | import android.opengl.GLSurfaceView; 4 | 5 | import javax.microedition.khronos.egl.EGL10; 6 | import javax.microedition.khronos.egl.EGLConfig; 7 | import javax.microedition.khronos.egl.EGLContext; 8 | import javax.microedition.khronos.egl.EGLDisplay; 9 | 10 | import minus.android.support.opengl.GLTextureView; 11 | 12 | 13 | /** 14 | * Created by tagorewang on 2016/6/23. 15 | */ 16 | 17 | public class GLES20ContextFactory implements GLSurfaceView.EGLContextFactory, GLTextureView.EGLContextFactory { 18 | 19 | private static int EGL_CONTEXT_CLIENT_VERSION = 0x3098; 20 | 21 | public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig) { 22 | int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE}; // gl20 23 | EGLContext context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list); 24 | return context; 25 | } 26 | 27 | @Override 28 | public void destroyContext(EGL10 egl, EGLDisplay display, EGLContext context) { 29 | egl.eglDestroyContext(display, context); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/app/src/main/java/minus/android/opengl/GLShape.java: -------------------------------------------------------------------------------- 1 | package minus.android.opengl; 2 | 3 | import android.graphics.Color; 4 | import android.opengl.GLES20; 5 | import android.opengl.Matrix; 6 | 7 | import java.nio.ByteBuffer; 8 | import java.nio.ByteOrder; 9 | import java.nio.FloatBuffer; 10 | import java.nio.ShortBuffer; 11 | 12 | class Circle extends GLShape { 13 | 14 | final float centerX = -0.5f; 15 | final float centerY = -0.5f; 16 | final float r = 0.5f; 17 | final int sectionCount = 360; 18 | 19 | public float[] getCounterClockWiseVertex() { 20 | float[] v = new float[3 * (sectionCount + 1)]; 21 | v[0] = centerX; 22 | v[1] = centerY; 23 | v[2] = 0; 24 | double incr = 2 * Math.PI / sectionCount; 25 | for (int i = 1; i <= sectionCount; ++i) { 26 | v[3 * i] = (float) (centerX + r * Math.sin(i * incr)); 27 | v[3 * i + 1] = (float) (centerY + r * Math.cos(i * incr)); 28 | v[3 * i + 2] = 0; 29 | } 30 | return v; 31 | } 32 | 33 | @Override 34 | protected int getDrawMode() { 35 | return GLES20.GL_TRIANGLES; 36 | } 37 | 38 | @Override 39 | protected short[] getDrawOrder() { 40 | short[] order = new short[3 * sectionCount]; 41 | order[0] = 0; 42 | order[1] = sectionCount; 43 | order[2] = 1; 44 | for(int i = 1; i < sectionCount; ++i) { 45 | order[3 * i] = 0; 46 | order[3 * i + 1] = (short) i; 47 | order[3 * i + 2] = (short) (i + 1); 48 | } 49 | return order; 50 | } 51 | 52 | @Override 53 | protected int getFillColorRGBA() { 54 | return Color.parseColor("#0000ff00"); 55 | } 56 | 57 | } 58 | 59 | class Square extends GLShape { 60 | 61 | static float squareCoords[] = { 62 | -0.5f, 0.5f, 0f, // top left 63 | -0.5f, -0.5f, 0.0f, // bottom left 64 | 0.5f, -0.5f, 0.0f, // bottom right 65 | 0.5f, 0.5f, 0.0f }; // top right 66 | 67 | public float[] getCounterClockWiseVertex() { 68 | return squareCoords; 69 | } 70 | 71 | @Override 72 | protected short[] getDrawOrder() { 73 | return new short[] { 0, 1, 2, 0, 2, 3 }; 74 | } 75 | 76 | @Override 77 | protected int getFillColorRGBA() { 78 | return Color.parseColor("#ffffffff"); 79 | } 80 | 81 | @Override 82 | protected int getDrawMode() { 83 | return GLES20.GL_TRIANGLES; 84 | } 85 | 86 | } 87 | 88 | class Triangle extends GLShape { 89 | 90 | static float triangleCoords[] = { // in counterclockwise order: 91 | 0.0f, 0.622008459f, 0.0f, // top 92 | -0.5f, -0.311004243f, 0.0f, // bottom left 93 | 0.5f, -0.311004243f, 0.0f // bottom right 94 | }; 95 | 96 | public float[] getCounterClockWiseVertex() { 97 | return triangleCoords; 98 | } 99 | 100 | @Override 101 | protected int getFillColorRGBA() { 102 | return Color.parseColor("#00ff0000"); 103 | } 104 | 105 | @Override 106 | protected short[] getDrawOrder() { 107 | return new short[] {0, 1, 2}; 108 | } 109 | 110 | @Override 111 | protected int getDrawMode() { 112 | return GLES20.GL_LINE_LOOP; 113 | } 114 | 115 | } 116 | 117 | public abstract class GLShape { 118 | 119 | public enum Rotate { 120 | 121 | NONE(0), FLIP_DEGREE_90(90), FLIP_DEGREE_180(180), FLIP_DEGREE_270(270); 122 | 123 | private final int degree; 124 | 125 | Rotate(int degree) { 126 | this.degree = degree; 127 | } 128 | 129 | public int value() { 130 | return degree; 131 | } 132 | 133 | } 134 | 135 | public static int loadShader(int type, String shaderCode){ 136 | 137 | // create a vertex shader type (GLES20.GL_VERTEX_SHADER) 138 | // or a fragment shader type (GLES20.GL_FRAGMENT_SHADER) 139 | int shader = GLES20.glCreateShader(type); 140 | 141 | // add the source code to the shader and compile it 142 | GLES20.glShaderSource(shader, shaderCode); 143 | GLES20.glCompileShader(shader); 144 | 145 | return shader; 146 | } 147 | 148 | public static int setupShaderProgram(String vs, String fs) { 149 | int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vs); 150 | int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fs); 151 | 152 | 153 | // create empty OpenGL ES Program 154 | int mProgram = GLES20.glCreateProgram(); 155 | 156 | // add the vertex shader to program 157 | GLES20.glAttachShader(mProgram, vertexShader); 158 | 159 | // add the fragment shader to program 160 | GLES20.glAttachShader(mProgram, fragmentShader); 161 | 162 | // creates OpenGL ES program executables 163 | GLES20.glLinkProgram(mProgram); 164 | 165 | return mProgram; 166 | } 167 | 168 | static float[] toColorFloatArray(int colorInt) { 169 | float r = (0xff & (colorInt >> 24)) / (float)0xff; 170 | float g = (0xff & (colorInt >> 16)) / (float)0xff; 171 | float b = (0xff & (colorInt >> 8)) / (float)0xff; 172 | float a = (0xff & colorInt) / (float)0xff; 173 | return new float[] { r, g, b, a }; 174 | } 175 | 176 | // number of coordinates per vertex in this array 177 | static final int COORDS_PER_VERTEX = 3; 178 | static final int vertexStride = COORDS_PER_VERTEX * 4; // 4 bytes per vertex 179 | 180 | private final String vertexShaderCode = 181 | // This matrix member variable provides a hook to manipulate 182 | // the coordinates of the objects that use this vertex shader 183 | "uniform mat4 uMVPMatrix;" + 184 | "attribute vec4 vPosition;" + 185 | "void main() {" + 186 | // the matrix must be included as a modifier of gl_Position 187 | // Note that the uMVPMatrix factor *must be first* in order 188 | // for the matrix multiplication product to be correct. 189 | " gl_Position = uMVPMatrix * vPosition;" + 190 | "}"; 191 | 192 | private final String fragmentShaderCode = 193 | "precision mediump float;" + 194 | "uniform vec4 vColor;" + 195 | "void main() {" + 196 | " gl_FragColor = vColor;" + 197 | "}"; 198 | 199 | private int mProgram; 200 | 201 | private int mPositionHandle; 202 | private int mColorHandle; 203 | private int mMVPMatrixHandle; 204 | 205 | private FloatBuffer vertexBuffer; 206 | 207 | final int drawCount; 208 | final ShortBuffer drawBuffer; 209 | 210 | final float vertexCoords[]; 211 | final int vertexCount; 212 | 213 | // Set color with red, green, blue and alpha (opacity) values 214 | final float color[]; 215 | 216 | public GLShape() { 217 | short[] drawOrderArray = getDrawOrder(); 218 | vertexCoords = getCounterClockWiseVertex(); 219 | vertexCount = vertexCoords.length / COORDS_PER_VERTEX; 220 | 221 | color = toColorFloatArray(getFillColorRGBA()); 222 | 223 | // initialize vertex byte buffer for shape coordinates 224 | ByteBuffer fbb = ByteBuffer.allocateDirect( 225 | // (number of coordinate values * 4 bytes per float) 226 | vertexCoords.length * Float.SIZE); 227 | // use the device hardware's native byte order 228 | fbb.order(ByteOrder.nativeOrder()); 229 | 230 | // create a floating point buffer from the ByteBuffer 231 | vertexBuffer = fbb.asFloatBuffer(); 232 | // add the coordinates to the FloatBuffer 233 | vertexBuffer.put(vertexCoords); 234 | // set the buffer to read the first coordinate 235 | vertexBuffer.position(0); 236 | 237 | drawCount = drawOrderArray.length; 238 | ByteBuffer sbb = ByteBuffer.allocateDirect(drawOrderArray.length * Short.SIZE); 239 | sbb.order(ByteOrder.nativeOrder()); 240 | drawBuffer = sbb.asShortBuffer(); 241 | drawBuffer.put(drawOrderArray); 242 | drawBuffer.position(0); 243 | } 244 | 245 | public GLShape draw(float[] mvpMatrix) { 246 | return draw(mvpMatrix, color, getDrawMode()); 247 | } 248 | 249 | public GLShape draw(float[] m, float scaleX, float scaleY, Rotate flip, boolean mirror) { 250 | Matrix.scaleM(m, 0, scaleX, scaleY, 1); 251 | if(Rotate.NONE != flip) { 252 | Matrix.rotateM(m, 0, flip.value(), 0, 0, 1); 253 | } 254 | if(mirror) { 255 | Matrix.rotateM(m, 0, 180, 0, 1, 0); // TODO: 256 | } 257 | return draw(m, color, getDrawMode()); 258 | } 259 | 260 | public GLShape draw(float[] mvpMatrix, float[] color, int drawMode) { 261 | // Add program to OpenGL ES environment 262 | GLES20.glUseProgram(mProgram); 263 | 264 | // get handle to vertex shader's vPosition member 265 | mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition"); 266 | 267 | // Enable a handle to the triangle vertices 268 | GLES20.glEnableVertexAttribArray(mPositionHandle); 269 | 270 | // Prepare the triangle coordinate data 271 | GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX, 272 | GLES20.GL_FLOAT, false, 273 | vertexStride, vertexBuffer); 274 | 275 | // get handle to fragment shader's vColor member 276 | mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor"); 277 | // Set color for drawing the triangle 278 | GLES20.glUniform4fv(mColorHandle, 1, color, 0); 279 | 280 | // get handle to shape's transformation matrix 281 | mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix"); 282 | 283 | // Pass the projection and view transformation to the shader 284 | GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0); 285 | 286 | // Draw the triangle 287 | GLES20.glDrawElements(drawMode, drawCount, GLES20.GL_UNSIGNED_SHORT, drawBuffer); 288 | 289 | // Disable vertex array 290 | GLES20.glDisableVertexAttribArray(mPositionHandle); 291 | 292 | return this; 293 | } 294 | 295 | public GLShape setupShaderProgram() { 296 | mProgram = setupShaderProgram(getVertexShaderCode(), getFragmentShaderCode()); 297 | return this; 298 | } 299 | 300 | protected String getVertexShaderCode() { 301 | return vertexShaderCode; 302 | } 303 | 304 | protected String getFragmentShaderCode() { 305 | return fragmentShaderCode; 306 | } 307 | 308 | protected int getDrawMode() { 309 | return GLES20.GL_LINE_LOOP; 310 | } 311 | 312 | protected abstract short[] getDrawOrder(); 313 | protected abstract float[] getCounterClockWiseVertex(); 314 | protected abstract int getFillColorRGBA(); 315 | 316 | } 317 | -------------------------------------------------------------------------------- /src/app/src/main/java/minus/android/opengl/MainActivity.java: -------------------------------------------------------------------------------- 1 | package minus.android.opengl; 2 | 3 | import android.app.Activity; 4 | import android.opengl.GLES20; 5 | import android.opengl.GLSurfaceView; 6 | import android.opengl.Matrix; 7 | import android.os.Bundle; 8 | 9 | import javax.microedition.khronos.egl.EGLConfig; 10 | import javax.microedition.khronos.opengles.GL10; 11 | 12 | import minus.android.support.opengl.GLTextureView; 13 | 14 | public class MainActivity extends Activity { 15 | 16 | private GLSurfaceView mGLSurfaceView; 17 | private GLTextureView mGLTextureView; 18 | 19 | @Override 20 | protected void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | setContentView(R.layout.activity_main); 23 | 24 | GLES20ContextFactory contextFactory = new GLES20ContextFactory(); 25 | GLES20ConfigChooser chooser = new GLES20ConfigChooser(5, 6, 5, 0, 0, 0); // arg565 26 | 27 | mGLSurfaceView = (GLSurfaceView) findViewById(R.id.gl_surface_view); 28 | mGLSurfaceView.setEGLContextFactory(contextFactory); 29 | mGLSurfaceView.setEGLConfigChooser(chooser); 30 | mGLSurfaceView.setRenderer(new GLSurfaceView.Renderer() { 31 | 32 | private GLShape shape = new Triangle(); 33 | private GlMVPMatrix mvpMatrix = new GlMVPMatrix(); 34 | 35 | @Override 36 | public void onSurfaceCreated(GL10 gl, EGLConfig config) { 37 | shape.setupShaderProgram(); 38 | } 39 | 40 | @Override 41 | public void onSurfaceChanged(GL10 gl, int width, int height) { 42 | mvpMatrix.adjustViewPort(width, height); 43 | } 44 | 45 | @Override 46 | public void onDrawFrame(GL10 gl) { 47 | shape.draw(mvpMatrix.getMVPMatrixFloatArray()); 48 | } 49 | }); 50 | 51 | mGLTextureView = (GLTextureView) findViewById(R.id.gl_texture_view); 52 | mGLTextureView.setEGLContextFactory(contextFactory); 53 | mGLTextureView.setEGLConfigChooser(chooser); 54 | mGLTextureView.setRenderer(new GLTextureView.Renderer() { 55 | 56 | private GLShape shape = new Square(); 57 | private GlMVPMatrix mvpMatrix = new GlMVPMatrix(); 58 | 59 | @Override 60 | public void onSurfaceCreated(GL10 gl, EGLConfig config) { 61 | shape.setupShaderProgram(); 62 | } 63 | 64 | @Override 65 | public void onSurfaceChanged(GL10 gl, int width, int height) { 66 | mvpMatrix.adjustViewPort(width, height); 67 | } 68 | 69 | @Override 70 | public boolean onDrawFrame(GL10 gl) { 71 | shape.draw(mvpMatrix.getMVPMatrixFloatArray()); 72 | return true; 73 | } 74 | 75 | @Override 76 | public void onSurfaceDestroyed() { 77 | 78 | } 79 | }); 80 | } 81 | 82 | @Override 83 | protected void onResume() { 84 | super.onResume(); 85 | mGLSurfaceView.onResume(); 86 | mGLTextureView.onResume(); 87 | } 88 | 89 | @Override 90 | protected void onPause() { 91 | super.onPause(); 92 | mGLSurfaceView.onPause(); 93 | mGLTextureView.onPause(); 94 | } 95 | 96 | } 97 | 98 | class GlMVPMatrix { 99 | 100 | private final float[] mProjectionMatrix = new float[16]; 101 | private final float[] mViewMatrix = new float[16]; 102 | private final float[] mMVPMatrix = new float[16]; 103 | 104 | public void adjustViewPort(int w, int h) { 105 | GLES20.glViewport(0, 0, w, h); 106 | float ratio = (float) w / h; 107 | Matrix.frustumM(mProjectionMatrix, 0, -1, 1, -ratio, ratio, 3, 4); 108 | Matrix.setLookAtM(mViewMatrix, 0, 109 | 0, 0, 3, 110 | 0f, 0, 0f, 111 | 0f, 1.0f, 0.0f); 112 | Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0); 113 | } 114 | 115 | public float[] getMVPMatrixFloatArray() { 116 | return mMVPMatrix.clone(); 117 | } 118 | 119 | } -------------------------------------------------------------------------------- /src/app/src/main/res/drawable/opengl_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wtao901231/GLTextureView/b3fd496824938baef5c7a698aef80b9e7e0b8cd0/src/app/src/main/res/drawable/opengl_logo.png -------------------------------------------------------------------------------- /src/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 16 | 17 | 21 | 22 | 29 | 30 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /src/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /src/app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /src/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | GLDemo 3 | 4 | -------------------------------------------------------------------------------- /src/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.0-alpha1' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /src/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wtao901231/GLTextureView/b3fd496824938baef5c7a698aef80b9e7e0b8cd0/src/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /src/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip 7 | -------------------------------------------------------------------------------- /src/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /src/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /src/libAndroidSupport/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /src/libAndroidSupport/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.3" 6 | 7 | defaultConfig { 8 | minSdkVersion 15 9 | targetSdkVersion 23 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | compile fileTree(dir: 'libs', include: ['*.jar']) 23 | } 24 | -------------------------------------------------------------------------------- /src/libAndroidSupport/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /src/libAndroidSupport/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/libAndroidSupport/src/main/java/minus/android/support/opengl/SystemProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 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 minus.android.support.opengl; 17 | 18 | import android.text.TextUtils; 19 | 20 | import java.io.BufferedReader; 21 | import java.io.InputStreamReader; 22 | import java.util.HashMap; 23 | import java.util.Map; 24 | 25 | /** 26 | * Gives access to the system properties store. The system properties 27 | * store contains a list of string key-value pairs. 28 | * 29 | * {@hide} 30 | */ 31 | public class SystemProperties 32 | { 33 | public static final int PROP_NAME_MAX = 31; 34 | public static final int PROP_VALUE_MAX = 91; 35 | 36 | /** 37 | * Get the value for the given key. 38 | * @return an empty string if the key isn't found 39 | * @throws IllegalArgumentException if the key exceeds 32 characters 40 | */ 41 | public static String get(String key) { 42 | if (key.length() > PROP_NAME_MAX) { 43 | throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX); 44 | } 45 | try { 46 | return native_get(key); 47 | } catch (Exception e) { 48 | return ""; 49 | } 50 | } 51 | /** 52 | * Get the value for the given key. 53 | * @return if the key isn't found, return def if it isn't null, or an empty string otherwise 54 | * @throws IllegalArgumentException if the key exceeds 32 characters 55 | */ 56 | public static String get(String key, String def) { 57 | if (key.length() > PROP_NAME_MAX) { 58 | throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX); 59 | } 60 | try { 61 | String ret = native_get(key); 62 | if(TextUtils.isEmpty(ret)) { 63 | return def; 64 | } 65 | return ret; 66 | } catch (Exception e) { 67 | return def; 68 | } 69 | } 70 | /** 71 | * Get the value for the given key, and return as an integer. 72 | * @param key the key to lookup 73 | * @param def a default value to return 74 | * @return the key parsed as an integer, or def if the key isn't found or 75 | * cannot be parsed 76 | * @throws IllegalArgumentException if the key exceeds 32 characters 77 | */ 78 | public static int getInt(String key, int def) { 79 | if (key.length() > PROP_NAME_MAX) { 80 | throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX); 81 | } 82 | try { 83 | return Integer.parseInt(native_get(key)); 84 | } catch (Exception e) { 85 | return def; 86 | } 87 | } 88 | /** 89 | * Get the value for the given key, and return as a long. 90 | * @param key the key to lookup 91 | * @param def a default value to return 92 | * @return the key parsed as a long, or def if the key isn't found or 93 | * cannot be parsed 94 | * @throws IllegalArgumentException if the key exceeds 32 characters 95 | */ 96 | public static long getLong(String key, long def) { 97 | if (key.length() > PROP_NAME_MAX) { 98 | throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX); 99 | } 100 | try { 101 | return Long.parseLong(native_get(key)); 102 | } catch (Exception e) { 103 | return def; 104 | } 105 | } 106 | /** 107 | * Get the value for the given key, returned as a boolean. 108 | * Values 'n', 'no', '0', 'false' or 'off' are considered false. 109 | * Values 'y', 'yes', '1', 'true' or 'on' are considered true. 110 | * (case sensitive). 111 | * If the key does not exist, or has any other value, then the default 112 | * result is returned. 113 | * @param key the key to lookup 114 | * @param def a default value to return 115 | * @return the key parsed as a boolean, or def if the key isn't found or is 116 | * not able to be parsed as a boolean. 117 | * @throws IllegalArgumentException if the key exceeds 32 characters 118 | */ 119 | public static boolean getBoolean(String key, boolean def) { 120 | if (key.length() > PROP_NAME_MAX) { 121 | throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX); 122 | } 123 | try { 124 | return Boolean.parseBoolean(native_get(key)); 125 | } catch (Exception e) { 126 | return def; 127 | } 128 | } 129 | 130 | private static Map cache = new HashMap(); 131 | private static String native_get(String key) throws Exception { 132 | if(cache.containsKey(key)) { 133 | return cache.get(key); 134 | } 135 | 136 | Process p = Runtime.getRuntime().exec("/system/bin/getprop " + key); 137 | p.waitFor(); 138 | BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); 139 | String ln = reader.readLine(); 140 | reader.close(); 141 | p.destroy(); 142 | 143 | cache.put(key, ln); 144 | return ln; 145 | } 146 | 147 | } 148 | -------------------------------------------------------------------------------- /src/libAndroidSupport/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | libAndroidSupport 3 | 4 | -------------------------------------------------------------------------------- /src/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':libAndroidSupport' 2 | --------------------------------------------------------------------------------