├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── onzhou
│ │ │ └── opengles
│ │ │ ├── main
│ │ │ └── SampleApplication.java
│ │ │ └── sample
│ │ │ └── SampleActivity.java
│ └── res
│ │ ├── layout
│ │ └── activity_opengles_sample.xml
│ │ └── values
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── onzhou
│ └── opengles
│ └── sample
│ └── ExampleUnitTest.java
├── build.gradle
├── common-base
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── onzhou
│ │ │ └── opengles
│ │ │ ├── base
│ │ │ ├── AbsBaseActivity.java
│ │ │ ├── AbsGLSurfaceActivity.java
│ │ │ └── BaseApplication.java
│ │ │ ├── core
│ │ │ └── AppCore.java
│ │ │ ├── task
│ │ │ └── AssertReleaseTask.java
│ │ │ └── utils
│ │ │ ├── LogUtils.java
│ │ │ ├── ResReadUtils.java
│ │ │ ├── ShaderUtils.java
│ │ │ └── TextureUtils.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable-xxhdpi
│ │ └── main.jpg
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── onzhou
│ └── opengles
│ └── ExampleUnitTest.java
├── config.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── module.gradle
├── readme
├── android平台下OpenGL ES 3.0给图片添加黑白滤镜.md
├── android平台下OpenGLES3.0从矩形中看矩阵和正交投影.md
├── android平台下OpenGLES3.0从零开始.md
├── android平台下OpenGLES3.0使用GLSurfaceView对相机Camera预览实时处理.md
├── android平台下OpenGLES3.0使用TextureView对相机Camera预览实时处理.md
├── android平台下OpenGLES3.0实例详解顶点属性、顶点数组.md
├── android平台下OpenGLES3.0实例详解顶点缓冲区对象(VBO)和顶点数组对象(VAO).md
├── android平台下OpenGLES3.0实现2D纹理贴图显示bitmap.md
├── android平台下OpenGLES3.0着色语言基础知识上.md
├── android平台下OpenGLES3.0着色语言基础知识下.md
├── android平台下OpenGLES3.0绘制圆点、直线和三角形.md
├── android平台下OpenGLES3.0绘制彩色三角形.md
├── android平台下OpenGLES3.0绘制立方体的几种方式.md
├── android平台下OpenGLES3.0绘制纯色背景.md
├── android平台下基于ANativeWindow实现渲染bitmap对像.md
└── images
│ ├── 20181104142344498.png
│ ├── 20181104144052178.png
│ ├── 20181104145208118.png
│ ├── 20181104151331670.png
│ ├── 20181104151943322.png
│ ├── 20181104152722938.png
│ ├── 20181104164419781.png
│ ├── 20181104165427818.png
│ ├── 2018110420590915.png
│ ├── 20181104212813161.png
│ ├── 20181104215322927.png
│ ├── 20181104215339364.png
│ ├── 20181104221645167.png
│ ├── 20181104223035672.png
│ ├── 20181105121623778.png
│ ├── 20181106000828349.png
│ ├── 20181106000835992.png
│ ├── 20181106110857961.png
│ ├── 20181106110905679.png
│ ├── 20181106111558844.png
│ ├── 20181106115350397.png
│ ├── 20181106115420645.png
│ ├── 20181108124632149.png
│ ├── 20181108124712983.png
│ ├── 2018110812474381.png
│ ├── 20181108125551557.png
│ ├── 20181108145715297.png
│ ├── 20181109133849605.png
│ ├── 20181109133909448.png
│ ├── 20181109133926509.png
│ ├── 20181109171605263.png
│ ├── 20181110164009917.png
│ ├── 2018111016442284.png
│ ├── 20181110165328638.png
│ ├── 20181110172117581.png
│ ├── 20181110174836154.png
│ ├── 20181110175440780.png
│ ├── 20181110175449693.png
│ ├── 20181110183239249.png
│ ├── 20181110183646999.png
│ ├── 20181111110630635.png
│ ├── 20181111130839622.png
│ ├── 20181111131217947.png
│ ├── 20181111132530649.png
│ ├── 20181111132543694.png
│ ├── 20181111133402205.png
│ ├── 20181111140010643.png
│ ├── 20181112222945107.png
│ ├── 20181113134235686.png
│ ├── 20181113134654161.png
│ ├── 201811131505362001.png
│ ├── 201811131506362001.png
│ ├── 201811131506362002.png
│ ├── 201811131506362003.png
│ ├── 201811131506362004.png
│ ├── 201811131506362005.png
│ ├── 201811131506362006.png
│ ├── 201811131506362007.png
│ ├── 201811131506362008.png
│ ├── 201811131506362009.png
│ ├── 201811131506362010.png
│ ├── 201811131506362011.png
│ ├── 201811131506362012.png
│ ├── 201811131545252001.png
│ ├── 201811131545252002.png
│ ├── 201811131545252003.png
│ ├── 201811131545252004.png
│ ├── device-2019-03-28-095109.png
│ ├── device-2019-03-28-095128.png
│ └── device-2019-03-28-095140.png
├── sample-basis
├── .gitignore
├── CMakeLists.txt
├── build.gradle
├── gradle.properties
├── proguard-rules.pro
└── src
│ ├── main
│ ├── cpp
│ │ ├── native_simple.cpp
│ │ └── native_simple.h
│ ├── debug
│ │ └── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── onzhou
│ │ │ └── opengles
│ │ │ ├── main
│ │ │ └── SimpleActivity.java
│ │ │ └── simple
│ │ │ ├── ColorCubeRenderer.java
│ │ │ ├── EnableVertexRenderer.java
│ │ │ ├── IndicesCubeRenderer.java
│ │ │ ├── LineCubeRenderer.java
│ │ │ ├── MapBufferRenderer.java
│ │ │ ├── NativeSimpleRenderer.java
│ │ │ ├── RectangleRenderer.java
│ │ │ ├── RectangleWRenderer.java
│ │ │ ├── SimpleRenderer.java
│ │ │ ├── UniformRenderer.java
│ │ │ ├── VertexArrayRenderer.java
│ │ │ ├── VertexBufferRenderer.java
│ │ │ └── VertexPointerRenderer.java
│ ├── release
│ │ └── AndroidManifest.xml
│ └── res
│ │ ├── layout
│ │ └── activity_triangle.xml
│ │ ├── raw
│ │ ├── fragment_array_shader.glsl
│ │ ├── fragment_buffer_shader.glsl
│ │ ├── fragment_colorcube_shader.glsl
│ │ ├── fragment_enable_shader.glsl
│ │ ├── fragment_linecube_shader.glsl
│ │ ├── fragment_map_buffer_shader.glsl
│ │ ├── fragment_pointer_shader.glsl
│ │ ├── fragment_uniform_shader.glsl
│ │ ├── fragment_w_shader.glsl
│ │ ├── triangle_fragment_shader.glsl
│ │ ├── triangle_vertex_shader.glsl
│ │ ├── vertex_array_shader.glsl
│ │ ├── vertex_buffer_shader.glsl
│ │ ├── vertex_colorcube_shader.glsl
│ │ ├── vertex_enable_shader.glsl
│ │ ├── vertex_linecube_shader.glsl
│ │ ├── vertex_map_buffer_shader.glsl
│ │ ├── vertex_pointer_shader.glsl
│ │ ├── vertex_uniform_shader.glsl
│ │ └── vertex_w_shader.glsl
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── onzhou
│ └── opengles
│ └── shader
│ └── ExampleUnitTest.java
├── sample-camera
├── .gitignore
├── build.gradle
├── gradle.properties
├── proguard-rules.pro
└── src
│ ├── main
│ ├── debug
│ │ └── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── onzhou
│ │ │ └── opengles
│ │ │ ├── api
│ │ │ ├── ICamera.java
│ │ │ └── ITextureRenderer.java
│ │ │ ├── camera
│ │ │ ├── CameraV1.java
│ │ │ ├── CameraV1Pick.java
│ │ │ └── TextureEGLHelper.java
│ │ │ ├── main
│ │ │ ├── CameraSurfaceActivity.java
│ │ │ └── CameraTextureActivity.java
│ │ │ └── renderer
│ │ │ ├── CameraSurfaceRenderer.java
│ │ │ └── CameraTextureRenderer.java
│ ├── release
│ │ └── AndroidManifest.xml
│ └── res
│ │ ├── raw
│ │ ├── fragment_camera_shader.glsl
│ │ ├── fragment_texture_shader.glsl
│ │ ├── vertex_camera_shader.glsl
│ │ └── vertex_texture_shader.glsl
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── onzhou
│ └── opengles
│ └── camera
│ └── ExampleUnitTest.java
├── sample-color
├── .gitignore
├── CMakeLists.txt
├── build.gradle
├── gradle.properties
├── proguard-rules.pro
└── src
│ ├── main
│ ├── cpp
│ │ ├── native_color.cpp
│ │ └── native_color.h
│ ├── debug
│ │ └── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── onzhou
│ │ │ └── opengles
│ │ │ ├── color
│ │ │ ├── ColorRenderer.java
│ │ │ └── NativeColorRenderer.java
│ │ │ └── main
│ │ │ └── ColorActivity.java
│ ├── release
│ │ └── AndroidManifest.xml
│ └── res
│ │ ├── raw
│ │ ├── triangle_fragment_shader.glsl
│ │ └── triangle_vertex_shader.glsl
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── onzhou
│ └── opengles
│ └── shader
│ └── ExampleUnitTest.java
├── sample-filter
├── .gitignore
├── build.gradle
├── gradle.properties
├── proguard-rules.pro
└── src
│ ├── main
│ ├── debug
│ │ └── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── onzhou
│ │ │ └── opengles
│ │ │ ├── filter
│ │ │ ├── BaseFilter.java
│ │ │ ├── GrayFilter.java
│ │ │ ├── OriginFilter.java
│ │ │ ├── QuarterMirrorFilter.java
│ │ │ └── RendererFilter.java
│ │ │ ├── main
│ │ │ └── FilterActivity.java
│ │ │ ├── renderer
│ │ │ └── FilterRenderer.java
│ │ │ └── view
│ │ │ └── OpenGLView.java
│ ├── release
│ │ └── AndroidManifest.xml
│ └── res
│ │ ├── layout
│ │ └── activity_filter.xml
│ │ ├── menu
│ │ └── menu_filter.xml
│ │ ├── raw
│ │ ├── gray_filter_fragment_shader.glsl
│ │ ├── gray_filter_vertex_shader.glsl
│ │ ├── no_filter_fragment_shader.glsl
│ │ ├── no_filter_vertex_shader.glsl
│ │ ├── quarter_mirror_filter_fragment_shader.glsl
│ │ └── quarter_mirror_filter_vertex_shader.glsl
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── onzhou
│ └── opengles
│ └── filter
│ └── ExampleUnitTest.java
├── sample-native
├── .gitignore
├── CMakeLists.txt
├── build.gradle
├── gradle.properties
├── proguard-rules.pro
└── src
│ ├── main
│ ├── cpp
│ │ ├── native_window.cpp
│ │ └── native_window.h
│ ├── debug
│ │ └── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── onzhou
│ │ │ └── opengles
│ │ │ ├── main
│ │ │ └── NativeWindowActivity.java
│ │ │ └── nativewindow
│ │ │ └── NativeWindowSample.java
│ ├── release
│ │ └── AndroidManifest.xml
│ └── res
│ │ ├── drawable-xxhdpi
│ │ └── main.jpg
│ │ ├── layout
│ │ └── activity_native_window.xml
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── onzhou
│ └── opengles
│ └── nativewindow
│ └── ExampleUnitTest.java
├── sample-texture
├── .gitignore
├── build.gradle
├── gradle.properties
├── proguard-rules.pro
└── src
│ ├── main
│ ├── debug
│ │ └── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── onzhou
│ │ │ └── opengles
│ │ │ ├── main
│ │ │ └── TextureActivity.java
│ │ │ └── texture
│ │ │ └── TextureRenderer.java
│ ├── release
│ │ └── AndroidManifest.xml
│ └── res
│ │ ├── drawable-xxhdpi
│ │ └── main.jpg
│ │ ├── raw
│ │ ├── fragment_texture_shader.glsl
│ │ └── vertex_texture_shader.glsl
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── onzhou
│ └── opengles
│ └── texture
│ └── ExampleUnitTest.java
├── screenshots
├── 20181105121623778.png
├── 20181109133909448.png
├── 20181110174836154.png
└── 20181112222945107.png
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | ### Android Studio Eclipse template
2 | .gradle
3 | .idea
4 | .settings
5 | bin
6 | build
7 | gen
8 | .classpath
9 | .project
10 | local.properties
11 | *.iml
12 | obj
13 | .externalNativeBuild
14 | .cxx
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | ## android平台opengles3.0实践学习
4 |
5 | - [android平台下OpenGLES3.0从零开始](https://github.com/byhook/opengles4android/blob/master/readme/android平台下OpenGLES3.0从零开始.md)
6 | - [android平台下OpenGLES3.0绘制纯色背景](https://github.com/byhook/opengles4android/blob/master/readme/android平台下OpenGLES3.0绘制纯色背景.md)
7 | - [android平台下OpenGLES3.0绘制圆点、直线和三角形](https://github.com/byhook/opengles4android/blob/master/readme/android平台下OpenGLES3.0绘制圆点、直线和三角形.md)
8 | - [android平台下OpenGLES3.0绘制彩色三角形](https://github.com/byhook/opengles4android/blob/master/readme/android平台下OpenGLES3.0绘制彩色三角形.md)
9 | - [android平台下OpenGLES3.0从矩形中看矩阵和正交投影](https://github.com/byhook/opengles4android/blob/master/readme/android平台下OpenGLES3.0从矩形中看矩阵和正交投影.md)
10 | - [android平台下OpenGLES3.0着色语言基础知识(上)](https://github.com/byhook/opengles4android/blob/master/readme/android平台下OpenGLES3.0着色语言基础知识上.md)
11 | - [android平台下OpenGLES3.0着色语言基础知识(下)](https://github.com/byhook/opengles4android/blob/master/readme/android平台下OpenGLES3.0着色语言基础知识下.md)
12 | - [android平台下OpenGLES3.0实例详解顶点属性、顶点数组](https://github.com/byhook/opengles4android/blob/master/readme/android平台下OpenGLES3.0实例详解顶点属性、顶点数组.md)
13 | - [android平台下OpenGLES3.0实例详解顶点缓冲区对象(VBO)和顶点数组对象(VAO)](https://github.com/byhook/opengles4android/blob/master/readme/android平台下OpenGLES3.0实例详解顶点缓冲区对象VBO和顶点数组对象VAO.md)
14 | - [android平台下OpenGLES3.0绘制立方体的几种方式](https://github.com/byhook/opengles4android/blob/master/readme/android平台下OpenGLES3.0绘制立方体的几种方式.md)
15 | - [android平台下OpenGLES3.0实现2D纹理贴图显示bitmap](https://github.com/byhook/opengles4android/blob/master/readme/android平台下OpenGLES3.0实现2D纹理贴图显示bitmap.md)
16 | - [android平台下OpenGLES3.0使用GLSurfaceView对相机Camera预览实时处理](https://github.com/byhook/opengles4android/blob/master/readme/android平台下OpenGLES3.0使用GLSurfaceView对相机Camera预览实时处理.md)
17 | - [android平台下OpenGLES3.0使用TextureView对相机Camera预览实时处理](https://github.com/byhook/opengles4android/blob/master/readme/android平台下OpenGLES3.0使用TextureView对相机Camera预览实时处理.md)
18 | - [android平台下基于ANativeWindow实现渲染bitmap对象](https://github.com/byhook/opengles4android/blob/master/readme/android平台下基于ANativeWindow实现渲染bitmap对像.md)
19 |
20 |
21 | ## 效果预览
22 |
23 |
24 |

25 |

26 |
27 |
28 |
29 |
30 |

31 |

32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | //构建版本
5 | compileSdkVersion rootProject.ext.android.compileSdkVersion
6 | //默认的配置
7 | defaultConfig {
8 | minSdkVersion rootProject.ext.android.minSdkVersion
9 | targetSdkVersion rootProject.ext.android.targetSdkVersion
10 | versionCode rootProject.ext.android.versionCode
11 | versionName rootProject.ext.android.versionName
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 |
20 | sourceSets {
21 | main {
22 | //库地址
23 | jniLibs.srcDirs = ['libs']
24 | }
25 | }
26 | }
27 |
28 | dependencies {
29 | implementation fileTree(include: ['*.jar'], dir: 'libs')
30 |
31 | implementation "androidx.core:core-ktx:${versions.coreKtxVersion}"
32 | implementation "androidx.appcompat:appcompat:${versions.appcompatVersion}"
33 | implementation "com.google.android.material:material:${versions.materialVersion}"
34 | implementation "androidx.constraintlayout:constraintlayout:${versions.constraintlayoutVersion}"
35 | testImplementation "junit:junit:${versions.junitVersion}"
36 | androidTestImplementation "androidx.test.ext:junit:${versions.junitExtVersion}"
37 | androidTestImplementation "androidx.test.espresso:espresso-core:${versions.espressoVersion}"
38 |
39 | implementation project(':common-base')
40 | //示例组件
41 | implementation project(':sample-basis')
42 | implementation project(':sample-color')
43 | implementation project(':sample-native')
44 | implementation project(':sample-texture')
45 | implementation project(':sample-camera')
46 | implementation project(':sample-filter')
47 | }
48 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
8 |
9 |
18 |
19 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/onzhou/opengles/main/SampleApplication.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.main;
2 |
3 | import android.app.Application;
4 |
5 | import com.onzhou.opengles.core.AppCore;
6 |
7 | /**
8 | * @anchor: andy
9 | * @date: 2019-03-27
10 | * @description:
11 | */
12 | public class SampleApplication extends Application {
13 |
14 | @Override
15 | public void onCreate() {
16 | super.onCreate();
17 | AppCore.getInstance().init(this);
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/onzhou/opengles/sample/SampleActivity.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.sample;
2 |
3 | import android.app.NativeActivity;
4 | import android.os.Bundle;
5 | import android.view.View;
6 |
7 | import androidx.annotation.Nullable;
8 |
9 | import com.onzhou.opengles.base.AbsBaseActivity;
10 | import com.onzhou.opengles.main.CameraSurfaceActivity;
11 | import com.onzhou.opengles.main.ColorActivity;
12 | import com.onzhou.opengles.main.FilterActivity;
13 | import com.onzhou.opengles.main.NativeWindowActivity;
14 | import com.onzhou.opengles.main.SimpleActivity;
15 | import com.onzhou.opengles.main.TextureActivity;
16 |
17 |
18 | /**
19 | * @anchor: andy
20 | * @date: 2019-03-27
21 | * @description:
22 | */
23 | public class SampleActivity extends AbsBaseActivity {
24 |
25 | @Override
26 | protected void onCreate(@Nullable Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_opengles_sample);
29 | }
30 |
31 | public void onBasisClick(View view) {
32 | SimpleActivity.intentStart(this);
33 | }
34 |
35 | public void onColorClick(View view) {
36 | ColorActivity.intentStart(this);
37 | }
38 |
39 | /**
40 | * 基于JNI实现的OpenGLES相关操作
41 | *
42 | * @param view
43 | */
44 | public void onNativeClick(View view) {
45 | NativeWindowActivity.intentStart(this);
46 | }
47 |
48 | /**
49 | * 图片纹理处理
50 | *
51 | * @param view
52 | */
53 | public void onTextureClick(View view) {
54 | TextureActivity.intentStart(this);
55 | }
56 |
57 | /**
58 | * 黑白相机实现
59 | *
60 | * @param view
61 | */
62 | public void onCameraClick(View view) {
63 | CameraSurfaceActivity.intentStart(this);
64 | }
65 |
66 | /**
67 | * 滤镜实现
68 | *
69 | * @param view
70 | */
71 | public void onFilterClick(View view) {
72 | FilterActivity.intentStart(this);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_opengles_sample.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
19 |
20 |
26 |
27 |
33 |
34 |
40 |
41 |
47 |
48 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | OpenGLES Sample
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/test/java/com/onzhou/opengles/sample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.sample;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | apply from: "config.gradle"
2 |
3 | buildscript {
4 |
5 | repositories {
6 | mavenLocal()
7 | mavenCentral()
8 | google()
9 | }
10 | dependencies {
11 | classpath 'com.android.tools.build:gradle:7.2.1'
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | mavenLocal()
21 | mavenCentral()
22 | google()
23 | }
24 | }
25 |
26 | task clean(type: Delete) {
27 | delete rootProject.buildDir
28 | }
29 |
--------------------------------------------------------------------------------
/common-base/.gitignore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/common-base/.gitignore
--------------------------------------------------------------------------------
/common-base/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | //构建版本
5 | compileSdkVersion rootProject.ext.android.compileSdkVersion
6 | //默认的配置
7 | defaultConfig {
8 | minSdkVersion rootProject.ext.android.minSdkVersion
9 | targetSdkVersion rootProject.ext.android.targetSdkVersion
10 |
11 | versionCode rootProject.ext.android.versionCode
12 | versionName rootProject.ext.android.versionName
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | implementation fileTree(dir: 'libs', include: ['*.jar'])
26 | implementation "androidx.core:core-ktx:${versions.coreKtxVersion}"
27 | implementation "androidx.appcompat:appcompat:${versions.appcompatVersion}"
28 |
29 | testImplementation "junit:junit:${versions.junitVersion}"
30 | androidTestImplementation "androidx.test.ext:junit:${versions.junitExtVersion}"
31 | }
32 |
--------------------------------------------------------------------------------
/common-base/proguard-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/common-base/proguard-rules.pro
--------------------------------------------------------------------------------
/common-base/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
--------------------------------------------------------------------------------
/common-base/src/main/java/com/onzhou/opengles/base/AbsBaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.base;
2 |
3 |
4 | import androidx.appcompat.app.AppCompatActivity;
5 |
6 | /**
7 | * @anchor: andy
8 | * @date: 2018-11-02
9 | * @description:
10 | */
11 | public abstract class AbsBaseActivity extends AppCompatActivity {
12 | }
13 |
--------------------------------------------------------------------------------
/common-base/src/main/java/com/onzhou/opengles/base/AbsGLSurfaceActivity.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.base;
2 |
3 | import android.opengl.GLSurfaceView;
4 | import android.os.Bundle;
5 |
6 | import androidx.annotation.Nullable;
7 |
8 | /**
9 | * @anchor: andy
10 | * @date: 2018-11-02
11 | * @description:
12 | */
13 | public abstract class AbsGLSurfaceActivity extends AbsBaseActivity {
14 |
15 | private GLSurfaceView mGLSurfaceView;
16 |
17 | protected abstract GLSurfaceView.Renderer bindRenderer();
18 |
19 | @Override
20 | protected void onCreate(@Nullable Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setupViews();
23 | }
24 |
25 | private void setupViews() {
26 | mGLSurfaceView = new GLSurfaceView(this);
27 | setContentView(mGLSurfaceView);
28 | //设置版本
29 | mGLSurfaceView.setEGLContextClientVersion(3);
30 | GLSurfaceView.Renderer renderer = bindRenderer();
31 | mGLSurfaceView.setRenderer(renderer);
32 | }
33 |
34 | }
--------------------------------------------------------------------------------
/common-base/src/main/java/com/onzhou/opengles/base/BaseApplication.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.base;
2 |
3 | import android.app.Application;
4 |
5 | import com.onzhou.opengles.core.AppCore;
6 |
7 | /**
8 | * @anchor: andy
9 | * @date: 2018-11-07
10 | * @description:
11 | */
12 | public class BaseApplication extends Application {
13 |
14 | @Override
15 | public void onCreate() {
16 | super.onCreate();
17 | AppCore.getInstance().init(this);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/common-base/src/main/java/com/onzhou/opengles/core/AppCore.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.core;
2 |
3 | import android.app.Application;
4 | import android.content.res.Resources;
5 |
6 | /**
7 | * @anchor: andy
8 | * @date: 2018-11-07
9 | * @description:
10 | */
11 | public class AppCore {
12 |
13 | private static AppCore sInstance;
14 |
15 | private Application application;
16 |
17 | public static AppCore getInstance() {
18 | if (sInstance == null) {
19 | sInstance = new AppCore();
20 | }
21 | return sInstance;
22 | }
23 |
24 | public void init(Application application) {
25 | this.application = application;
26 | }
27 |
28 | public Application getContext() {
29 | return application;
30 | }
31 |
32 | public Resources getResources() {
33 | return application.getResources();
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/common-base/src/main/java/com/onzhou/opengles/task/AssertReleaseTask.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.task;
2 |
3 | import android.content.Context;
4 | import android.os.AsyncTask;
5 |
6 | import java.io.Closeable;
7 | import java.io.File;
8 | import java.io.FileOutputStream;
9 | import java.io.IOException;
10 | import java.io.InputStream;
11 | import java.lang.ref.WeakReference;
12 |
13 | public class AssertReleaseTask extends AsyncTask {
14 |
15 | private WeakReference weakContext;
16 |
17 | private String fileName;
18 |
19 | private ReleaseCallback releaseCallback;
20 |
21 | public AssertReleaseTask(Context context, String fileName, ReleaseCallback releaseCallback) {
22 | this.weakContext = new WeakReference<>(context);
23 | this.fileName = fileName;
24 | this.releaseCallback = releaseCallback;
25 | }
26 |
27 | @Override
28 | protected String doInBackground(Void... voids) {
29 | InputStream inputStream = null;
30 | FileOutputStream fos = null;
31 | try {
32 | Context appContext = weakContext.get();
33 | if (appContext != null) {
34 | inputStream = appContext.getAssets().open(fileName);
35 | File targetFile = new File(appContext.getExternalFilesDir(null), fileName);
36 | fos = new FileOutputStream(targetFile);
37 | int length;
38 | byte[] buffer = new byte[8 * 1024];
39 | while ((length = inputStream.read(buffer)) != -1) {
40 | fos.write(buffer, 0, length);
41 | fos.flush();
42 | }
43 | return targetFile.getAbsolutePath();
44 | }
45 | } catch (IOException e) {
46 | e.printStackTrace();
47 | } finally {
48 | ioClose(fos);
49 | ioClose(inputStream);
50 | }
51 | return null;
52 | }
53 |
54 | @Override
55 | protected void onPostExecute(String filePath) {
56 | super.onPostExecute(filePath);
57 | if (releaseCallback != null) {
58 | releaseCallback.onReleaseSuccess(filePath);
59 | }
60 | }
61 |
62 | private void ioClose(Closeable closeable) {
63 | if (closeable != null) {
64 | try {
65 | closeable.close();
66 | } catch (IOException e) {
67 | e.printStackTrace();
68 | }
69 | }
70 | }
71 |
72 | public interface ReleaseCallback {
73 |
74 | void onReleaseSuccess(String filePath);
75 |
76 | }
77 |
78 | }
--------------------------------------------------------------------------------
/common-base/src/main/java/com/onzhou/opengles/utils/LogUtils.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.utils;
2 |
3 | import android.util.Log;
4 |
5 | /**
6 | * 作者: Andy
7 | * 时间: 2016-12-20
8 | * 描述:
9 | * 日志工具类
10 | */
11 |
12 | public class LogUtils {
13 |
14 | protected static final String TAG = "LogUtils";
15 |
16 | /**
17 | * 对应多个参数
18 | *
19 | * @param tag
20 | * @param content
21 | * @param args
22 | */
23 | public static void v(String tag, String content, Object... args) {
24 | if (args != null && args.length > 0) {
25 | final String msg = String.format(content, args);
26 | Log.v(tag, msg);
27 | }
28 | }
29 |
30 | public static void i(String tag, String content, Object... args) {
31 | if (args != null && args.length > 0) {
32 | final String msg = String.format(content, args);
33 | Log.i(tag, msg);
34 | }
35 | }
36 |
37 | public static void d(String tag, String content, Object... args) {
38 | if (args != null && args.length > 0) {
39 | Log.d(tag, String.format(content, args));
40 | }
41 | }
42 |
43 | public static void e(String tag, String content, Object... args) {
44 | if (args != null && args.length > 0) {
45 | Log.e(tag, String.format(content, args));
46 | }
47 | }
48 |
49 | /**
50 | * 基本包装
51 | *
52 | * @param tag
53 | * @param content
54 | */
55 | public static void v(String tag, Object content) {
56 | Log.v(tag, String.valueOf(content));
57 | }
58 |
59 | public static void i(String tag, Object content) {
60 | Log.i(tag, String.valueOf(content));
61 | }
62 |
63 | public static void d(String tag, Object content) {
64 | Log.d(tag, String.valueOf(content));
65 | }
66 |
67 | public static void e(String tag, Object content) {
68 | Log.e(tag, String.valueOf(content));
69 | }
70 |
71 | public static void e(Exception content) {
72 | e(TAG, content);
73 | }
74 |
75 | public static void e(Throwable content) {
76 | e(TAG, content);
77 | }
78 |
79 | /**
80 | * 打印异常信息
81 | *
82 | * @param tag
83 | * @param exception
84 | */
85 | public static void e(String tag, Exception exception) {
86 | if (exception != null) {
87 | e(tag, exception.toString());
88 | }
89 | }
90 |
91 | /**
92 | * 打印异常信息
93 | *
94 | * @param tag
95 | * @param throwable
96 | */
97 | public static void e(String tag, Throwable throwable) {
98 | if (throwable != null) {
99 | e(tag, throwable.toString());
100 | }
101 | }
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/common-base/src/main/java/com/onzhou/opengles/utils/ResReadUtils.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.utils;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 |
6 | import com.onzhou.opengles.core.AppCore;
7 |
8 | import java.io.BufferedReader;
9 | import java.io.IOException;
10 | import java.io.InputStream;
11 | import java.io.InputStreamReader;
12 |
13 | /**
14 | * @anchor: andy
15 | * @date: 2018-09-13
16 | * @description:
17 | */
18 | public class ResReadUtils {
19 |
20 | /**
21 | * 读取资源
22 | *
23 | * @param resourceId
24 | * @return
25 | */
26 | public static String readResource(int resourceId) {
27 | StringBuilder builder = new StringBuilder();
28 | try {
29 | InputStream inputStream = AppCore.getInstance().getResources().openRawResource(resourceId);
30 | InputStreamReader streamReader = new InputStreamReader(inputStream);
31 |
32 | BufferedReader bufferedReader = new BufferedReader(streamReader);
33 | String textLine;
34 | while ((textLine = bufferedReader.readLine()) != null) {
35 | builder.append(textLine);
36 | builder.append("\n");
37 | }
38 | } catch (IOException e) {
39 | e.printStackTrace();
40 | } catch (Resources.NotFoundException e) {
41 | e.printStackTrace();
42 | }
43 | return builder.toString();
44 | }
45 |
46 | }
--------------------------------------------------------------------------------
/common-base/src/main/java/com/onzhou/opengles/utils/ShaderUtils.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.utils;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 | import android.opengl.GLES30;
6 |
7 | import com.onzhou.opengles.core.AppCore;
8 |
9 | /**
10 | * @anchor: andy
11 | * @date: 2018-09-13
12 | * @description:
13 | */
14 | public class ShaderUtils {
15 |
16 | private static final String TAG = "ShaderUtils";
17 |
18 | /**
19 | * 编译顶点着色器
20 | *
21 | * @param shaderCode
22 | * @return
23 | */
24 | public static int compileVertexShader(String shaderCode) {
25 | return compileShader(GLES30.GL_VERTEX_SHADER, shaderCode);
26 | }
27 |
28 | /**
29 | * 编译片段着色器
30 | *
31 | * @param shaderCode
32 | * @return
33 | */
34 | public static int compileFragmentShader(String shaderCode) {
35 | return compileShader(GLES30.GL_FRAGMENT_SHADER, shaderCode);
36 | }
37 |
38 | /**
39 | * 编译
40 | *
41 | * @param type 顶点着色器:GLES30.GL_VERTEX_SHADER
42 | * 片段着色器:GLES30.GL_FRAGMENT_SHADER
43 | * @param shaderCode
44 | * @return
45 | */
46 | private static int compileShader(int type, String shaderCode) {
47 | //创建一个着色器
48 | final int shaderId = GLES30.glCreateShader(type);
49 | if (shaderId != 0) {
50 | GLES30.glShaderSource(shaderId, shaderCode);
51 | GLES30.glCompileShader(shaderId);
52 | //检测状态
53 | final int[] compileStatus = new int[1];
54 | GLES30.glGetShaderiv(shaderId, GLES30.GL_COMPILE_STATUS, compileStatus, 0);
55 | if (compileStatus[0] == 0) {
56 | String logInfo = GLES30.glGetShaderInfoLog(shaderId);
57 | System.err.println(logInfo);
58 | //创建失败
59 | GLES30.glDeleteShader(shaderId);
60 | return 0;
61 | }
62 | return shaderId;
63 | } else {
64 | //创建失败
65 | return 0;
66 | }
67 | }
68 |
69 | /**
70 | * 链接小程序
71 | *
72 | * @param vertexShaderId 顶点着色器
73 | * @param fragmentShaderId 片段着色器
74 | * @return
75 | */
76 | public static int linkProgram(int vertexShaderId, int fragmentShaderId) {
77 | final int programId = GLES30.glCreateProgram();
78 | if (programId != 0) {
79 | //将顶点着色器加入到程序
80 | GLES30.glAttachShader(programId, vertexShaderId);
81 | //将片元着色器加入到程序中
82 | GLES30.glAttachShader(programId, fragmentShaderId);
83 | //链接着色器程序
84 | GLES30.glLinkProgram(programId);
85 | final int[] linkStatus = new int[1];
86 |
87 | GLES30.glGetProgramiv(programId, GLES30.GL_LINK_STATUS, linkStatus, 0);
88 | if (linkStatus[0] == 0) {
89 | String logInfo = GLES30.glGetProgramInfoLog(programId);
90 | System.err.println(logInfo);
91 | GLES30.glDeleteProgram(programId);
92 | return 0;
93 | }
94 | return programId;
95 | } else {
96 | //创建失败
97 | return 0;
98 | }
99 | }
100 |
101 | /**
102 | * 验证程序片段是否有效
103 | *
104 | * @param programObjectId
105 | * @return
106 | */
107 | public static boolean validProgram(int programObjectId) {
108 | GLES30.glValidateProgram(programObjectId);
109 | final int[] programStatus = new int[1];
110 | GLES30.glGetProgramiv(programObjectId, GLES30.GL_VALIDATE_STATUS, programStatus, 0);
111 | return programStatus[0] != 0;
112 | }
113 |
114 | }
115 |
--------------------------------------------------------------------------------
/common-base/src/main/java/com/onzhou/opengles/utils/TextureUtils.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.utils;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.opengl.GLES11Ext;
7 | import android.opengl.GLES20;
8 | import android.opengl.GLES30;
9 | import android.opengl.GLUtils;
10 | import android.util.Log;
11 |
12 | import javax.microedition.khronos.opengles.GL10;
13 |
14 | /**
15 | * @anchor: andy
16 | * @date: 18-11-10
17 | */
18 |
19 | public class TextureUtils {
20 |
21 | private static final String TAG = "TextureUtils";
22 |
23 | public static int loadTexture(Context context, int resourceId) {
24 | final int[] textureIds = new int[1];
25 | GLES30.glGenTextures(1, textureIds, 0);
26 | if (textureIds[0] == 0) {
27 | Log.e(TAG, "Could not generate a new OpenGL textureId object.");
28 | return 0;
29 | }
30 | final BitmapFactory.Options options = new BitmapFactory.Options();
31 | options.inScaled = false;
32 | final Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId, options);
33 | if (bitmap == null) {
34 | Log.e(TAG, "Resource ID " + resourceId + " could not be decoded.");
35 | GLES30.glDeleteTextures(1, textureIds, 0);
36 | return 0;
37 | }
38 | // 绑定纹理到OpenGL
39 | GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, textureIds[0]);
40 |
41 | GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_LINEAR_MIPMAP_LINEAR);
42 | GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR);
43 |
44 | // 加载bitmap到纹理中
45 | GLUtils.texImage2D(GLES30.GL_TEXTURE_2D, 0, bitmap, 0);
46 |
47 | // 生成MIP贴图
48 | GLES30.glGenerateMipmap(GLES30.GL_TEXTURE_2D);
49 |
50 | // 数据如果已经被加载进OpenGL,则可以回收该bitmap
51 | bitmap.recycle();
52 |
53 | // 取消绑定纹理
54 | GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0);
55 |
56 | return textureIds[0];
57 | }
58 |
59 | /**
60 | * 加载OES Texture
61 | *
62 | * @return
63 | */
64 | public static int loadOESTexture() {
65 | int[] textureIds = new int[1];
66 | GLES20.glGenTextures(1, textureIds, 0);
67 | GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textureIds[0]);
68 | GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
69 | GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
70 | GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
71 | GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
72 | GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
73 | GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
74 | GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
75 | GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);
76 | GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0);
77 | return textureIds[0];
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/common-base/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/common-base/src/main/res/drawable-xxhdpi/main.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/common-base/src/main/res/drawable-xxhdpi/main.jpg
--------------------------------------------------------------------------------
/common-base/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/common-base/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/common-base/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/common-base/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/common-base/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/common-base/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/common-base/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/common-base/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/common-base/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/common-base/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/common-base/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/common-base/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/common-base/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/common-base/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/common-base/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/common-base/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/common-base/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/common-base/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/common-base/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/common-base/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/common-base/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/common-base/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/common-base/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/common-base/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | opengles4android
3 |
4 |
--------------------------------------------------------------------------------
/common-base/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/common-base/src/test/java/com/onzhou/opengles/ExampleUnitTest.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/common-base/src/test/java/com/onzhou/opengles/ExampleUnitTest.java
--------------------------------------------------------------------------------
/config.gradle:
--------------------------------------------------------------------------------
1 | ext {
2 | android = [
3 | compileSdkVersion: 33,
4 | applicationId : "com.onzhou.opengles",
5 | minSdkVersion : 21,
6 | targetSdkVersion : 33,
7 | versionCode : 1,
8 | versionName : "1.0.0"
9 | ]
10 |
11 | versions = [
12 | 'appcompatVersion' : '1.4.1',
13 | 'materialVersion' : '1.6.0',
14 | 'constraintlayoutVersion' : '2.1.3',
15 | 'junitVersion' : '4.13.2',
16 | 'junitExtVersion' : '1.1.3',
17 | 'espressoVersion' : '3.4.0',
18 |
19 | 'coreKtxVersion' : '1.9.0',
20 | 'coroutinesCoreVersion' : '1.5.0',
21 | 'coroutinesAndroidVersion': '1.5.0',
22 | ]
23 |
24 |
25 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 | android.useAndroidX=true
19 | # Automatically convert third-party libraries to use AndroidX
20 | android.enableJetifier=true
21 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Nov 24 00:12:02 CST 2020
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-7.3.3-all.zip
7 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/module.gradle:
--------------------------------------------------------------------------------
1 | if (library.toBoolean()) {
2 | apply plugin: 'com.android.library'
3 | } else {
4 | apply plugin: 'com.android.application'
5 | }
6 |
7 | android {
8 |
9 | //构建版本
10 | compileSdkVersion rootProject.ext.android.compileSdkVersion
11 | //默认的配置
12 | defaultConfig {
13 |
14 | minSdkVersion rootProject.ext.android.minSdkVersion
15 | targetSdkVersion rootProject.ext.android.targetSdkVersion
16 | versionCode rootProject.ext.android.versionCode
17 | versionName rootProject.ext.android.versionName
18 |
19 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
20 |
21 | ndk {
22 | abiFilters "armeabi-v7a","arm64-v8a"
23 | }
24 |
25 | javaCompileOptions {
26 | annotationProcessorOptions {
27 | arguments = [AROUTER_MODULE_NAME: project.getName()]
28 | }
29 | }
30 | }
31 |
32 | buildTypes {
33 | release {
34 | minifyEnabled false
35 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
36 | }
37 | }
38 |
39 | dexOptions {
40 | javaMaxHeapSize "4g"
41 | }
42 |
43 | lintOptions {
44 | checkReleaseBuilds false
45 | abortOnError false
46 | }
47 |
48 | sourceSets {
49 | main {
50 | //清单配置
51 | if (library.toBoolean()) {
52 | manifest.srcFile 'src/main/release/AndroidManifest.xml'
53 | } else {
54 | manifest.srcFile 'src/main/debug/AndroidManifest.xml'
55 | }
56 | //库地址
57 | java.srcDirs = ['src/main/java', 'src/main/aidl']
58 | jniLibs.srcDirs = ['libs']
59 | }
60 | }
61 | }
62 |
63 | dependencies {
64 | implementation fileTree(include: ['*.jar'], dir: 'libs')
65 | implementation "androidx.core:core-ktx:${versions.coreKtxVersion}"
66 | implementation "androidx.appcompat:appcompat:${versions.appcompatVersion}"
67 | implementation "com.google.android.material:material:${versions.materialVersion}"
68 | implementation "androidx.constraintlayout:constraintlayout:${versions.constraintlayoutVersion}"
69 | testImplementation "junit:junit:${versions.junitVersion}"
70 | androidTestImplementation "androidx.test.ext:junit:${versions.junitExtVersion}"
71 | androidTestImplementation "androidx.test.espresso:espresso-core:${versions.espressoVersion}"
72 |
73 | implementation project(':common-base')
74 | }
75 |
--------------------------------------------------------------------------------
/readme/android平台下OpenGL ES 3.0给图片添加黑白滤镜.md:
--------------------------------------------------------------------------------
1 |
2 | ## 概述
3 |
4 | 之前了解的一些第三方库,各种动态切换滤镜,比较神奇,于是自己研究了一番,基础原理倒也不是很难,下面记录一下过程
5 |
6 | ## 配置环境
7 |
8 | 操作系统:`ubuntu 16.05`
9 |
10 | ## 效果预览
11 |
12 |
17 |
18 | ## 实现方案
19 |
20 | 笔者这里封装了一个渲染控件`GLView`,继承自`GLSurfaceView`
21 |
22 | ```java
23 | /**
24 | * @anchor: andy
25 | * @date: 2019-03-27
26 | * @description:
27 | */
28 | public class GLView extends GLSurfaceView implements IFilter {
29 |
30 | private FilterRenderer mGLRender;
31 |
32 | public GLView(Context context) {
33 | this(context, null);
34 | }
35 |
36 | public GLView(Context context, AttributeSet attrs) {
37 | super(context, attrs);
38 | setupSurfaceView();
39 | }
40 |
41 | private void setupSurfaceView() {
42 | //设置版本
43 | setEGLContextClientVersion(3);
44 | mGLRender = new FilterRenderer();
45 | setRenderer(mGLRender);
46 |
47 | try {
48 | requestRender();
49 | } catch (Exception e) {
50 | e.printStackTrace();
51 | }
52 | }
53 |
54 | /**
55 | * 设置滤镜
56 | * 滤镜由于可能存在多种类型
57 | * 这里抽象了一个基础的滤镜类
58 | * @param baseFilter
59 | */
60 | @Override
61 | public void setFilter(BaseFilter baseFilter) {
62 | if (mGLRender != null) {
63 | mGLRender.setFilter(baseFilter);
64 | }
65 | }
66 | }
67 | ```
68 |
69 | **抽象类BaseFilter的实现**
70 |
71 | ```java
72 | public abstract class BaseFilter {
73 |
74 | /**
75 | * 滤镜类型声明
76 | */
77 | interface FilterType {
78 |
79 | int TYPE_ORIGIN = 0;
80 |
81 | int TYPE_GRAY = 1;
82 |
83 | }
84 |
85 | /**
86 | * 获取滤镜类型
87 | *
88 | * @return
89 | */
90 | public abstract int getType();
91 |
92 | /**
93 | * 获取滤镜数据
94 | *
95 | * @return
96 | */
97 | public abstract float[] getFilter();
98 |
99 | }
100 | ```
101 |
102 | 笔者这里以黑白滤镜为例:
103 |
104 | ```java
105 | /**
106 | * @anchor: andy
107 | * @date: 2019-03-27
108 | * @description:
109 | */
110 | public class GrayFilter extends BaseFilter {
111 |
112 | @Override
113 | public int getType() {
114 | return FilterType.TYPE_GRAY;
115 | }
116 |
117 | @Override
118 | public float[] getFilter() {
119 | return new float[]{0.299f, 0.587f, 0.114f};
120 | }
121 |
122 | }
123 | ```
124 |
125 | 看到这里,你肯定很疑惑,这里`getFilter`返回的`float数组`是怎么来的,不用急,先往下看
126 |
127 | 还记得之前入门的一些博客内容吗?笔者之前也写过一些简单的片段着色器:
128 |
129 | ```java
130 | #version 300 es
131 | precision mediump float;
132 | uniform sampler2D uTextureUnit;
133 | in vec2 vTexCoord;
134 | out vec4 vFragColor;
135 | void main() {
136 | vFragColor = texture(uTextureUnit,vTexCoord);
137 | }
138 | ```
139 |
140 | 但是这个着色器只能输出原图的数据,那么我们应该如何更改输出之后的数据呢?这个时候我们就需要动态的修改`统一变量`
141 |
142 | ```java
143 | #version 300 es
144 | precision mediump float;
145 | uniform sampler2D uTextureUnit;
146 | //传入滤镜类型
147 | uniform int vFilterType;
148 | //传入滤镜数据
149 | in vec3 vFilter;
150 | in vec2 vTexCoord;
151 |
152 | //输出
153 | out vec4 vFragColor;
154 | void main() {
155 | vec4 vTextureColor = texture(uTextureUnit,vTexCoord);
156 | switch(vFilterType){
157 | case 1:
158 | //黑白滤镜
159 | float vFilterColor = (vFilter.x * vTextureColor.r + vFilter.y * vTextureColor.g + vFilter.z * vTextureColor.b);
160 | vFragColor = vec4(vFilterColor, vFilterColor, vFilterColor, 1.0);
161 | break;
162 | case 0:
163 | //默认原图
164 | default:
165 | //原图显示
166 | vFragColor = vTextureColor;
167 | break;
168 | }
169 | }
170 | ```
171 | 上面的例子,相信有`C语言基础`的基本都能看懂,大致意思就是暴露
172 |
173 |
174 | 项目地址:[sample-filter](https://github.com/byhook/opengles4android)
175 |
176 | https://github.com/byhook/opengles4android
177 |
--------------------------------------------------------------------------------
/readme/android平台下OpenGLES3.0从零开始.md:
--------------------------------------------------------------------------------
1 |
2 | ## 目录
3 |
4 | - [OpenGL ES对Android平台的支持情况]()
5 | - [OpenGL ES 3.0概述]()
6 | - [OpenGL ES 3.0图形管线图]()
7 | - [顶点着色器]()
8 | - [片段着色器]()
9 | - [图元装配]()
10 | - [光栅化]()
11 | - [逐片段操作]()
12 | - [虚拟机和OpenGL ES 3.0的数据传输]()
13 |
14 | #### OpenGL ES对Android平台的支持情况
15 |
16 | `OpenGL ES当前主要版本有1.0/1.1/2.0/3.0/3.1`。
17 |
18 | |OpenGL ES版本|Android版本|描述|
19 | |:-|:-|:-|
20 | |OpenGL ES1.0|Android 1.0+|OpenGL ES 1.x是针对固定硬件管线的,Android 1.0和更高的版本支持这个API规范。|
21 | |**OpenGL ES2.0**|**Android 2.2(API 8)+**|OpenGL ES 2.x是针对可编程硬件管线的,不兼容OpenGL ES 1.x,Android 2.2(API 8)和更高的版本支持这个API规范。|
22 | |**OpenGL ES3.0**|**Android 4.3(API 18)+**|向下兼容OpenGL ES 2.x,Android 4.3(API 18)及更高的版本支持这个API规范。|
23 | |OpenGL ES3.1|Android 5.0 (API 21)+|向下兼容OpenGL ES3.0/2.0,Android 5.0(API 21)和更高的版本支持这个API规范|
24 |
25 | #### OpenGL ES 3.0概述
26 |
27 | OpenGL ES 3.0实现了具有可编程着色功能的图形管线,由两个规范组成:`OpenGL ES 3.0 API 规范`和`OpenGL ES着色语言3.0规范(OpenGL ES SL)`。
28 |
29 | #### OpenGL ES 3.0图形管线图
30 |
31 | 
32 |
33 | #### 顶点着色器
34 | 顶点着色器实现了顶点操作的通用可编程方法,`着色器(Shader)是在GPU上运行的小程序`。
35 | 顶点着色器的输入包括:
36 | - 着色器程序一一描述顶点上执行操作的顶点着色器程序源代码或者可执行文件。
37 | - 顶点着色器输人(或者属性)一一用顶点数组提供的每个顶点的数据。
38 | - 统一变量(`uniform`)一一顶点(或者片段)着色器使用的不变数据。
39 | - 采样器一一代表顶点着色器使用纹理的特殊统一变量类型。
40 |
41 |
42 | `顶点着色器的输入输出模型`
43 |
44 | 
45 |
46 | `顶点着色器取得一个位置及相关的颜色数据作为输入属性,用一个 4x4矩阵变换位置,并输出变换后的位置和颜色。`
47 | ```java
48 | #version 300 es
49 | uniform mat4 u_mvpMatrix;
50 |
51 | int vec4 a_postion;
52 | int vec4 a_color;
53 |
54 | out vec4 v_color;
55 | void main(){
56 | v_color = a_color;
57 | gl_Position = u_mvpMatrix * a_postion
58 | }
59 | ```
60 |
61 | #### 片段着色器
62 | 片段着色器片段着色器为片段上的操作实现了通用的可编程方法。
63 | 对光栅化阶段生成的每个片段执行这个着色器,采用如下输入:
64 | - 着色器程序——描述片段上所执行操作的片段着色器程序源代码或者可执行文件。
65 | - 输人变量——光姗化单元用插值为每个片段生成的顶点着色器钧出。
66 | - 统一变量——片段(或者顶点)着色器使用的不变数据。
67 | - 采样器——讨七表片段着色器所用纹理的特殊统一变量类型。
68 |
69 | 
70 |
71 | #### 图元装配
72 | 图元装配顶点着色器之后, 0pennGL ES 3.0 图形管线的下一阶段就是图元装配。
73 | `图元(Primitive)是三角形、直线或者点精灵等几何对象。图元的每个顶点被发送到顶点着色器的不同拷贝。
74 | 在图元装配期间,这些顶点被组合成图元。对于每个图元,必须确定图元是否位于视锥体(屏幕上可见的 3D 空间区域)内。如果图元没有完全在视锥体内,则可能需要进行裁剪。如果图元完全处于该区域之外,它就会被抛弃。裁剪之后,顶点位置被转换为屏幕坐标。也可以执行一次淘汰操作,根据图元面向前方或者后方抛弃它们。裁剪和淘汰之后,图元便准备传递给管线的下一阶段 ― 光栅化阶段。
75 |
76 | #### 光栅化
77 | 下一阶段是光栅化,在此阶段绘制对应的图元(点精灵、直线或者三角形)。光栅化是将图元转化为一组二维片段的过程,然后,这些片段由片段着色器处理。这些二维片段代表着可在屏幕上绘制的像素。
78 |
79 | `OpenGL ES 3.0 光栅化阶段`
80 |
81 | 
82 |
83 | #### 逐片段操作
84 |
85 | 片段着色器之后,下一个阶段就是`逐片段操作`。
86 |
87 | 
88 |
89 | #### OpenGL ES 数据存储
90 | android中的程序都是运行在`虚拟机`中的,而`OpenGL`作为本地系统库是运行在硬件上的,虚拟机与`OpenGL`数据传输的方式由两种
91 | - 第一种:使用Java调用本地接口`JNI`的方式,当我们使用`GLES20包`里的方法时,内部实现其实就是调用本地方法。
92 | - 第二种:改变内存的分配方式,Java当中有个特殊的类(如`ByteBuffer`)集合,可以直接分配本地内存块,并把Java的数据复制到本地内存,本地内存可以被本地环境存取,而不受垃圾回收器管控。
93 |
94 | `从虚拟机到本地环境的数据传输过程`
95 |
96 | 
97 |
98 | 参考:
99 | 《OpenGL ES 3.0 编程指南第2版》
100 | 《OpenGL ES应用开发实践指南Android卷》
101 |
--------------------------------------------------------------------------------
/readme/android平台下OpenGLES3.0着色语言基础知识上.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | 本篇整理自《OpenGL ES 3.0 编程指南第2版》
4 |
5 | #### 着色器版本规范
6 |
7 | OpenGL ES 3.0 `顶点着色器`和`片段着色器`的第1行总是声明着色器版本。声明着色器版本通知`着色器编译器`预期在着色器中出现的语法和结构。编译器按照声明的着色语言版本`检查着色器语法`。采用如下语法声明着色器使用`OpenGL ES`着色语言`3.00`版本:
8 |
9 | ```java
10 | #version 300 es
11 | ```
12 |
13 | 没有声明版本号的着色器被认定为使用OpenGL ES着色语言的`1.00版本`。着色语言的`1.00版本`用于`OpenGLES2.0`。对于`OpenGLES3.0`,作者决定匹配API和着色语言的版本号,这就是版本号从`1.00跳到3.00`的原因。
14 |
15 | #### 变量和变量类型
16 |
17 | 在计算机图形中,两个基本数据类型组成了变换的基础:向量和矩阵。这两种数据类型 在OpenGLES着色语言中也是核心。
18 |
19 | `OpenGLES着色语言中的数据类型`
20 |
21 | |变置分类|类 型|描 述|
22 | |:-|:-|:-|
23 | |标量|float,int,uint,bool|用于浮点、整数、无符号整数和布尔值的基于标标量的数据类型|
24 | |浮点向量|float,vec2,vec3,vec4|有1、2、3、4个分量的基于浮点的向量类型|
25 | |整数向量|int,ivec2,ivec3,ivec4 |有1、2、3、4个分量的基于整数的向量类型|
26 | |无符号整数向量|uint,uvec2,uvec3,uvec4|有1、2、3、4个分量的基于无符号整数的向量类型|
27 | |布尔向量|bool,bvec2,bvec3,bvec4,|有1、2.3、4个分量的基于布尔的向量类型|
28 | |矩阵|mat2(或mat2x2),mat2x3,2x2,2x3,2x4,3x2,3x3,3x4,4x2,4x3mat2x4,mat3x2, mat3(或mat3x3),mat3x4,mat4x2,mat4x3,mat4(或mat4x4)||
29 |
30 | >着色语言中的变量必须以某个类型声明。例如,下面的声明描述如何声明`一个标量、一 个向量和一个矩阵`:
31 |
32 | ```java
33 | vec4 vPosition;
34 | mat4 mMatirx;
35 | vec2 vOffset;
36 | ```
37 |
38 | >变量可以在声明时或者声明以后初始化。初始化通过使用构造器进行,构造器也用于类
39 | 型转换。
40 |
41 | #### 变量构造器
42 |
43 | `OpenGLES`着色语言在类型转换方面有非常严格的规则。也就是说`变量只能陚值为相同类型的其他变量`或者与相同类型的变量进行运算。
44 |
45 | 来看看如何使用构造器初始化和转换标量值。
46 |
47 | ```java
48 | float myFloat = 1.0;
49 | float myFloat2 = 1; //ERROR: 整数类型转换浮点类型错误
50 | bool myBool = true;
51 | int mylnt = 0;
52 | int mylnt2 = 0.0; // ERROR: 浮点类型转换整数类型错误
53 | myFloat = float(myBool); // 布尔值转换为浮点型
54 | myFloat = float(mylnt); // 整型转换为浮点型
55 | myBool = bool(mylnt); // 整型转换为布尔值
56 | ```
57 |
58 | 构造器可以用于转换和初始化向量数据类型。向量构造器的参数将被转换为与被构造的向量相同的基本类型(float、int或bool)。向量构造器的参数传递有两种基本方法:
59 |
60 | - 如果只为向量构造器提供一个标量参数,则该值用于设置向量的所有值。
61 | - 如果提供了多个标量或者向量参数,则向量的值从左到右使用这些参数设置。如果提供了多个标量参数,那么在向量中必须有至少和参数中一样多的分量。
62 |
63 | `构造向量的例子:`
64 |
65 | ```java
66 | vec4 myVec4 = vec4(1.0); // myVec4 = {l.0, 1.0, 1.0, 1.0}
67 | vec3 myVec3 = vec3(1.0,0.0,0.5);// myVec3 = {1.0, 0.0, 0.5}
68 | vec3 temp = vec3(myVec3); // temp = myVec3
69 | vec2 myVec2 = vec2(myVec3); // myVec2 = {myVec3.x,myVec3.y}
70 | myVec4 = vec4(myVec2, temp); //myVec4 » {myVec2.x,myVec2.y,temp.x,temp.y}
71 | ```
72 |
73 | `下面是构造矩阵的一些基本规则:`
74 |
75 | - 如果只为矩阵构造器提供一个标量参数,则该值被放在矩阵的对角线上。例如:` mat4(1.0)`将创建一个`4 x 4`的单位矩阵。
76 | - 矩阵可以从多个向量参数构造。例如: `mat2可以从两个vec2构造`。
77 | - 矩阵可以从多个标量参数构造一每个参数代表矩阵中的一个值,从左到右使用。矩阵的构造比刚才说明的基本规则更灵活,只要在矩阵初始化时提供足够多的分量,矩阵基本上可以从任何`标量和向量`的组合构造。`OpenGLES中的矩阵以列优先顺序存储`。使用矩阵构造器时,参数按列填充矩阵。
78 |
79 | ```java
80 | mat3 myMat3 = mat3(1.0, 0.0, 0.0, //第一列
81 | 0.0, 1.0, 0.0, //第二列
82 | 0.0, 1.0, 1.0);//第三列
83 | ```
84 | #### 向量和矩阵分量
85 |
86 | 向量的单独分量可以用两种方式访问:
87 |
88 | >使用`'.'`运算符或者通过数组下标。根据组成向量的分量数,每个分量可以通过使用`{x,y,z,w}`、`{r,g,b,a}`或者`{s,t,p,q}`组合访问。3种不同命名方案的原因是向量可以互换地用于表示数学上的向量、颜色和纹理坐标。
89 |
90 | 使用运算符时,可以在操作中重新排列向量的分量:
91 |
92 | ```java
93 | vec3 myVec3 = vec3(0.0, 1.0, 2.0); // myVec3 = {0.0, 1.0, 2.0}
94 | vec3 temp;
95 | temp = myVec3.xyz; // temp = {0.0, 1.0, 2.0}
96 | temp = myVec3.xxx; // temp = {0.0, 0.0, 0.0}
97 | temp = myVec3.zyx; // temp = {2.0, 1.0, 0.0}
98 | ```
99 |
100 | >除了`'.'`运算符之外,向量还可以使用数组下标`"[]"`运算符访问。在数组下标中,`元素[0]`对应于`x`,元索[1]对应于`y`,等等。
101 | 矩阵被看成由一些向量组成。例如:` mat2可以看作两个vec2,mat3可以看作3个vec3`,等等。
102 | 对于矩阵,单独的列可以用数组下标运算符`"[]"`选择,然后每个向量可以通过向量访问行为来访问。
103 |
104 | ```java
105 | mat4 myMat4 = mat4(1.0); // 将对角线初始化为1.0
106 | vec4 myVec4 = myMat4[0]; // 从矩阵中获取myVec4向量
107 | float m1_1 = myMat4[1][1]; // 在矩阵中获取 [1][1]处的元素
108 | float m2_2 = myMat4[2][2]; // 在矩阵中获取 [2][2]处的元素
109 | ```
110 |
111 | #### 常量
112 | 可以将任何基本类型声明为常数变量。常数变量是着色器中不变的值。声明常量时,在声明中加入`const限定符`。常数必须在声明时初始化。
113 |
114 | ```java
115 | const float zero = 0.0;
116 | const float pi = 3.14159;
117 | const vec4 red = vec4(0.0, 0.0, 1.0);
118 | const mat4 identity = mat4(1.0);
119 | ```
120 |
121 | `正如在C或者C++中那样,声明为const的变量是只读的,不能在源代码中修改。`
122 |
123 | #### 结构
124 |
125 | 除了使用语言中提供的基本类型之外,还可以和c语言一样将`变量聚合成结构`。 `OpenGL ES`着色语言中声明结构的语法如下例所示:
126 |
127 | ```java
128 | struct fogStruct
129 | {
130 | vec4 color;
131 | float start;
132 | float end;
133 | } fogVar;
134 | ```
135 |
136 | 上述定义的是一个名为`fogStruct`的新结构类型和一个新变量`fogVar`。
137 | 结构可以用构造器初始化。在定义新的结构类型之后,也用与类型相同的名称定义一个新的结构构造器。结构中的类型和构造器中的类型必须是一对一的。
138 |
139 | ```java
140 | struct fogStruct
141 | {
142 | vec4 color;
143 | float start;
144 | float end;
145 | } fogVar;
146 |
147 | //构造初始化
148 | fogVar = fogStruct(vec4(0.0, 1.0, 0.0, 0.0), //初始化颜色
149 | 0.5, //初始化 start
150 | 2.0); //初始化end
151 | ```
152 |
153 |
154 | #### 数组
155 |
156 | 数组的语法与C语言很相似,索引从0开始。数组可以用数组初始化构造器初始化
157 |
158 | ```java
159 | float a[4] = float[](1.0, 2.0, 3.0, 4.0);
160 | float b[4] = float(4](1.0, 2.0, 3,0, 4.0);
161 | vec2 c[2] = vec2[2](vec2(1.0), vec2(1.0));
162 | ```
163 |
164 | #### 函数
165 |
166 | 函数的声明方法和C语言中相同。如果函数在定义前使用,则必须提供原型声明。 OpenGLES着色语言函数和C语言函数的最明显的不同之处在于函数参数的传递方法。 OpenGLES着色语言提供特殊的限定符,定义函数是否可以修改可变参数。
167 |
168 | `OpenGL ES`中也提供了很多`内建函数`。
169 |
170 | |限定符|描述|
171 | |:-|:-|
172 | |`in`|(没有指定时的默认限定符) 这个限定符指定参数按值传送,函数不能修改|
173 | |`inout`|这个限定符规定变量按照引用传入函数,如果该值被修改,它将在函数退出后变化|
174 | |`out`|这个限定符表示该变量的值不被传入函数,但在函数返冋时将被修改|
175 |
176 | `注意:`函数不能递归。GPU没有堆栈。
177 |
178 | #### 控制流语句
179 |
180 | OpcnGL ES着色语言中的控制流语句的语法类似于C语言。
181 |
182 | ```java
183 | if(color.a < 0.25){
184 | color *= color.a;
185 | }
186 | else{
187 | color = vec4(0.0);
188 | }
189 | ```
190 | 条件语句中测试的表达式求出的必须是一个布尔值。
191 |
192 | 参考
193 | 《OpenGL ES 3.0 编程指南第2版》
194 |
--------------------------------------------------------------------------------
/readme/android平台下OpenGLES3.0绘制彩色三角形.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | 本例基于[android平台下OpenGLES3.0绘制圆点、直线和三角形](https://blog.csdn.net/byhook/article/details/83719500)
4 |
5 | ## 目录
6 |
7 | - [顶点着色器]()
8 | - [片段着色器]()
9 | - [基于sdk绘制彩色三角形]()
10 | - [基于ndk绘制彩色三角形]()
11 |
12 | #### 顶点着色器
13 |
14 | ```java
15 | #version 300 es
16 | layout (location = 0) in vec4 vPosition;
17 | layout (location = 1) in vec4 aColor;
18 | out vec4 vColor;
19 | void main() {
20 | gl_Position = vPosition;
21 | gl_PointSize = 10.0;
22 | vColor = aColor;
23 | }
24 | ```
25 | 上述顶点着色器的描述:
26 | - 第一行表示:着色器的版本,OpenGL ES 2.0版本可以不写。
27 | - 第二行表示:输入一个名为`vPosition`的4分量向量,`layout (location = 0)`表示这个变量的位置是顶点属性0。
28 | - 第三行表示:输入一个名为`aColor`的4分量向量,`layout (location = 1)`表示这个变量的位置是顶点属性1。
29 | - 第四行表示:输出一个名为`vColor`的4分量向量
30 | - 第八行表示:将输入数据`aColor`拷贝到`vColor`的变量中。
31 |
32 | #### 片段着色器
33 | ```java
34 | #version 300 es
35 | precision mediump float;
36 | in vec4 vColor;
37 | out vec4 fragColor;
38 | void main() {
39 | fragColor = vColor;
40 | }
41 |
42 | ```
43 | 上述片段着色器的描述:
44 | - 第一行表示:着色器的版本,OpenGL ES 2.0版本可以不写。
45 | - 第二行表示:声明着色器中浮点变量的默认精度。
46 | - 第三行表示: 声明一个输入名为`vColor`的4分向量
47 | - 第四行表示:着色器声明一个`输出变量fragColor`,这个是一个4分量的向量。
48 | - 第六行表示:表示将输入的颜色值数据拷贝到`fragColor`变量中,输出到颜色缓冲区。
49 |
50 | #### 基于sdk绘制彩色三角形
51 |
52 | ```java
53 | private float color[] = {
54 | 0.0f, 1.0f, 0.0f, 1.0f,
55 | 1.0f, 0.0f, 0.0f, 1.0f,
56 | 0.0f, 0.0f, 1.0f, 1.0f
57 | };
58 | ```
59 |
60 | 由于`虚拟机`和`OpenGL`运行环境不同,需要将`虚拟机数据传输到native层供其使用`
61 |
62 | 构造函数中: 将颜色数据传输到`native`层
63 | ```java
64 | colorBuffer = ByteBuffer.allocateDirect(color.length * 4)
65 | .order(ByteOrder.nativeOrder())
66 | .asFloatBuffer();
67 | //传入指定的数据
68 | colorBuffer.put(color);
69 | colorBuffer.position(0);
70 | ```
71 |
72 | 开始绘制:
73 |
74 | ```java
75 | @Override
76 | public void onDrawFrame(GL10 gl) {
77 | GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
78 |
79 | //准备坐标数据
80 | GLES30.glVertexAttribPointer(0, POSITION_COMPONENT_COUNT, GLES30.GL_FLOAT, false, 0, vertexBuffer);
81 | //启用顶点的句柄
82 | GLES30.glEnableVertexAttribArray(0);
83 |
84 | //绘制三角形颜色
85 | GLES30.glEnableVertexAttribArray(1);
86 | GLES30.glVertexAttribPointer(1, 4, GLES30.GL_FLOAT, false, 0, colorBuffer);
87 |
88 | GLES30.glDrawArrays(GLES30.GL_TRIANGLES, 0, 3);
89 |
90 | //禁止顶点数组的句柄
91 | GLES30.glDisableVertexAttribArray(0);
92 | GLES30.glDisableVertexAttribArray(1);
93 | }
94 | ```
95 |
96 | #### 基于ndk绘制彩色三角形
97 |
98 | 基于ndk的绘制示例在下面的地址中,需要定义好`jni的接口`,原理跟上述方式类型,不再赘述
99 |
100 | 
101 |
102 | 项目地址:
103 | https://github.com/byhook/opengles4android
104 |
105 | 参考:
106 |
107 | 《OpenGL ES 3.0 编程指南第2版》
108 |
109 | 《OpenGL ES应用开发实践指南Android卷》
110 |
--------------------------------------------------------------------------------
/readme/android平台下基于ANativeWindow实现渲染bitmap对像.md:
--------------------------------------------------------------------------------
1 |
2 | ## 概述
3 |
4 | `原生Window API`支持我们在`ndk下`开发原生的绘制功能,后续的一些视频渲染,包括相机采集预览等都可以通过这些`API`来实现,笔者今天通过几个简单的API来实践一下`native层`的绘制功能
5 |
6 | ## 配置环境
7 |
8 | 笔者`Android Studio`配置的是`android-ndk-r16b`版本,操作系统是`ubuntu 16.05`
9 |
10 | ## 绘制背景色
11 |
12 | 还是从最简单的入手,开始尝试绘制背景颜色,我们此次使用的方案是`SurfaceView+ANativeWindow`的方式,基于之前的[项目工程](https://github.com/byhook/opengles4android)
13 |
14 | 先定义`Java层的本地方法`:
15 |
16 | ```java
17 | /**
18 | * @anchor: andy
19 | * @date: 2018-11-13
20 | * @description:
21 | */
22 | public class NativeWindowSample {
23 |
24 | static {
25 | System.loadLibrary("native-window");
26 | }
27 |
28 | /**
29 | * 绘制指定颜色背景
30 | *
31 | * @param surface
32 | * @param color
33 | */
34 | public native void drawColor(Object surface, int color);
35 |
36 | /**
37 | * 绘制指定颜色背景
38 | *
39 | * @param surface
40 | * @param bitmap
41 | */
42 | public native void drawBitmap(Object surface, Object bitmap);
43 |
44 | }
45 | ```
46 |
47 | 配置`CMakeLists.txt`文件内容如下:
48 |
49 | ```java
50 |
51 | cmake_minimum_required(VERSION 3.4.1)
52 |
53 | ##官方标准配置
54 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
55 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-rtti -fno-exceptions -Wall")
56 |
57 | add_library(native-window
58 | SHARED
59 | src/main/cpp/native_window.cpp)
60 |
61 | target_link_libraries(native-window
62 | ${OPENGL_LIB}
63 | android
64 | jnigraphics
65 | log)
66 |
67 | ```
68 |
69 | `build.gradle`中的配置,这里不赘述,比较简单
70 |
71 | 在我们的子工程目录`src/main/cpp`下新建我们的`native_window.cpp`和`native_window.h`文件:
72 |
73 | 来看看`native_window.cpp`中`drawColor`的实现:
74 |
75 | ```java
76 | void drawColor(JNIEnv *env, jobject obj, jobject surface, jint colorARGB) {
77 | //分离ARGB
78 | int alpha = (colorARGB >> 24) & 0xFF;
79 | int red = (colorARGB >> 16) & 0xFF;
80 | int green = (colorARGB >> 8) & 0xFF;
81 | int blue = colorARGB & 0xFF;
82 |
83 | int colorABGR = (alpha << 24) | (blue << 16) | (green << 8) | red;
84 |
85 | //获取目标surface
86 | ANativeWindow *window = ANativeWindow_fromSurface(env, surface);
87 | //默认的是RGB_565
88 | ANativeWindow_setBuffersGeometry(window, 640, 640, WINDOW_FORMAT_RGBA_8888);
89 | ANativeWindow_acquire(window);
90 |
91 | ANativeWindow_Buffer buffer;
92 | ANativeWindow_lock(window, &buffer, NULL);
93 |
94 | uint32_t *line = (uint32_t *) buffer.bits;
95 | for (int y = 0; y < buffer.height; y++) {
96 | for (int x = 0; x < buffer.width; x++) {
97 | line[x] = colorABGR;
98 | }
99 | line = line + buffer.stride;
100 | }
101 |
102 | ANativeWindow_unlockAndPost(window);
103 | //释放窗口
104 | ANativeWindow_release(window);
105 | }
106 | ```
107 | 这里要注意的就是,我们从Java层传入的是`32位的ARGB`的颜色,直接写入我们的`windowBuffer`,颜色显示可能不正确,需要按照`ANativeWindow_Buffer`指定的颜色顺序作一次转换
108 |
109 | `绘制一个灰色背景:`
110 |
111 | ```java
112 | mNativeWindowSample.drawColor(mSurfaceView.getHolder().getSurface(), Color.GRAY);
113 | ```
114 |
115 | 
116 |
117 | ## 绘制bitmap
118 |
119 | 直接绘制`bitmap`也比较简单,但是我们需要通过`AndroidBitmap_lockPixels`方法获取`bitmap`对应的本地的数据的指针,通过这个指针来读取对应的像素数据,注释也比较清楚
120 |
121 | ```java
122 | void drawBitmap(JNIEnv *env, jobject obj, jobject surface, jobject bitmap) {
123 | //获取bitmap的信息,比如宽和高
124 | AndroidBitmapInfo info;
125 | AndroidBitmap_getInfo(env, bitmap, &info);
126 |
127 | char *data = NULL;
128 | //获取bitmap对应的native指针
129 | AndroidBitmap_lockPixels(env, bitmap, (void **) &data);
130 | AndroidBitmap_unlockPixels(env, bitmap);
131 |
132 | //获取目标surface
133 | ANativeWindow *window = ANativeWindow_fromSurface(env, surface);
134 | //这里设置为RGBA的方式,总共是4字节32位
135 | ANativeWindow_setBuffersGeometry(window, info.width, info.height, WINDOW_FORMAT_RGBA_8888);
136 | ANativeWindow_acquire(window);
137 |
138 | ANativeWindow_Buffer buffer;
139 | //锁定窗口的绘图表面
140 | ANativeWindow_lock(window, &buffer, NULL);
141 |
142 | //转换为像素点来处理
143 | int32_t *bitmapPixes = (int32_t *) data;
144 | uint32_t *line = (uint32_t *) buffer.bits;
145 | for (int y = 0; y < buffer.height; y++) {
146 | for (int x = 0; x < buffer.width; x++) {
147 | line[x] = bitmapPixes[buffer.height * y + x];
148 | }
149 | line = line + buffer.stride;
150 | }
151 | //解锁窗口的绘图表面
152 | ANativeWindow_unlockAndPost(window);
153 | //释放
154 | ANativeWindow_release(window);
155 |
156 | }
157 | ```
158 |
159 | `绘制一个bitmap对象`
160 |
161 | ```java
162 | BitmapFactory.Options options = new BitmapFactory.Options();
163 | options.inScaled = false;
164 | Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.main, options);
165 | mNativeWindowSample.drawBitmap(mSurfaceView.getHolder().getSurface(), bitmap);
166 | ```
167 |
168 | 
169 |
170 | 项目地址:
171 | https://github.com/byhook/opengles4android
172 |
--------------------------------------------------------------------------------
/readme/images/20181104142344498.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181104142344498.png
--------------------------------------------------------------------------------
/readme/images/20181104144052178.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181104144052178.png
--------------------------------------------------------------------------------
/readme/images/20181104145208118.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181104145208118.png
--------------------------------------------------------------------------------
/readme/images/20181104151331670.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181104151331670.png
--------------------------------------------------------------------------------
/readme/images/20181104151943322.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181104151943322.png
--------------------------------------------------------------------------------
/readme/images/20181104152722938.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181104152722938.png
--------------------------------------------------------------------------------
/readme/images/20181104164419781.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181104164419781.png
--------------------------------------------------------------------------------
/readme/images/20181104165427818.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181104165427818.png
--------------------------------------------------------------------------------
/readme/images/2018110420590915.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/2018110420590915.png
--------------------------------------------------------------------------------
/readme/images/20181104212813161.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181104212813161.png
--------------------------------------------------------------------------------
/readme/images/20181104215322927.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181104215322927.png
--------------------------------------------------------------------------------
/readme/images/20181104215339364.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181104215339364.png
--------------------------------------------------------------------------------
/readme/images/20181104221645167.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181104221645167.png
--------------------------------------------------------------------------------
/readme/images/20181104223035672.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181104223035672.png
--------------------------------------------------------------------------------
/readme/images/20181105121623778.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181105121623778.png
--------------------------------------------------------------------------------
/readme/images/20181106000828349.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181106000828349.png
--------------------------------------------------------------------------------
/readme/images/20181106000835992.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181106000835992.png
--------------------------------------------------------------------------------
/readme/images/20181106110857961.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181106110857961.png
--------------------------------------------------------------------------------
/readme/images/20181106110905679.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181106110905679.png
--------------------------------------------------------------------------------
/readme/images/20181106111558844.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181106111558844.png
--------------------------------------------------------------------------------
/readme/images/20181106115350397.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181106115350397.png
--------------------------------------------------------------------------------
/readme/images/20181106115420645.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181106115420645.png
--------------------------------------------------------------------------------
/readme/images/20181108124632149.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181108124632149.png
--------------------------------------------------------------------------------
/readme/images/20181108124712983.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181108124712983.png
--------------------------------------------------------------------------------
/readme/images/2018110812474381.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/2018110812474381.png
--------------------------------------------------------------------------------
/readme/images/20181108125551557.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181108125551557.png
--------------------------------------------------------------------------------
/readme/images/20181108145715297.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181108145715297.png
--------------------------------------------------------------------------------
/readme/images/20181109133849605.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181109133849605.png
--------------------------------------------------------------------------------
/readme/images/20181109133909448.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181109133909448.png
--------------------------------------------------------------------------------
/readme/images/20181109133926509.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181109133926509.png
--------------------------------------------------------------------------------
/readme/images/20181109171605263.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181109171605263.png
--------------------------------------------------------------------------------
/readme/images/20181110164009917.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181110164009917.png
--------------------------------------------------------------------------------
/readme/images/2018111016442284.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/2018111016442284.png
--------------------------------------------------------------------------------
/readme/images/20181110165328638.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181110165328638.png
--------------------------------------------------------------------------------
/readme/images/20181110172117581.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181110172117581.png
--------------------------------------------------------------------------------
/readme/images/20181110174836154.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181110174836154.png
--------------------------------------------------------------------------------
/readme/images/20181110175440780.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181110175440780.png
--------------------------------------------------------------------------------
/readme/images/20181110175449693.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181110175449693.png
--------------------------------------------------------------------------------
/readme/images/20181110183239249.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181110183239249.png
--------------------------------------------------------------------------------
/readme/images/20181110183646999.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181110183646999.png
--------------------------------------------------------------------------------
/readme/images/20181111110630635.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181111110630635.png
--------------------------------------------------------------------------------
/readme/images/20181111130839622.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181111130839622.png
--------------------------------------------------------------------------------
/readme/images/20181111131217947.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181111131217947.png
--------------------------------------------------------------------------------
/readme/images/20181111132530649.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181111132530649.png
--------------------------------------------------------------------------------
/readme/images/20181111132543694.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181111132543694.png
--------------------------------------------------------------------------------
/readme/images/20181111133402205.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181111133402205.png
--------------------------------------------------------------------------------
/readme/images/20181111140010643.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181111140010643.png
--------------------------------------------------------------------------------
/readme/images/20181112222945107.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181112222945107.png
--------------------------------------------------------------------------------
/readme/images/20181113134235686.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181113134235686.png
--------------------------------------------------------------------------------
/readme/images/20181113134654161.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/20181113134654161.png
--------------------------------------------------------------------------------
/readme/images/201811131505362001.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/201811131505362001.png
--------------------------------------------------------------------------------
/readme/images/201811131506362001.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/201811131506362001.png
--------------------------------------------------------------------------------
/readme/images/201811131506362002.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/201811131506362002.png
--------------------------------------------------------------------------------
/readme/images/201811131506362003.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/201811131506362003.png
--------------------------------------------------------------------------------
/readme/images/201811131506362004.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/201811131506362004.png
--------------------------------------------------------------------------------
/readme/images/201811131506362005.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/201811131506362005.png
--------------------------------------------------------------------------------
/readme/images/201811131506362006.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/201811131506362006.png
--------------------------------------------------------------------------------
/readme/images/201811131506362007.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/201811131506362007.png
--------------------------------------------------------------------------------
/readme/images/201811131506362008.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/201811131506362008.png
--------------------------------------------------------------------------------
/readme/images/201811131506362009.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/201811131506362009.png
--------------------------------------------------------------------------------
/readme/images/201811131506362010.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/201811131506362010.png
--------------------------------------------------------------------------------
/readme/images/201811131506362011.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/201811131506362011.png
--------------------------------------------------------------------------------
/readme/images/201811131506362012.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/201811131506362012.png
--------------------------------------------------------------------------------
/readme/images/201811131545252001.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/201811131545252001.png
--------------------------------------------------------------------------------
/readme/images/201811131545252002.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/201811131545252002.png
--------------------------------------------------------------------------------
/readme/images/201811131545252003.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/201811131545252003.png
--------------------------------------------------------------------------------
/readme/images/201811131545252004.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/201811131545252004.png
--------------------------------------------------------------------------------
/readme/images/device-2019-03-28-095109.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/device-2019-03-28-095109.png
--------------------------------------------------------------------------------
/readme/images/device-2019-03-28-095128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/device-2019-03-28-095128.png
--------------------------------------------------------------------------------
/readme/images/device-2019-03-28-095140.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/readme/images/device-2019-03-28-095140.png
--------------------------------------------------------------------------------
/sample-basis/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sample-basis/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | cmake_minimum_required(VERSION 3.4.1)
3 |
4 |
5 | ##官方标准配置
6 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
7 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-rtti -fno-exceptions -Wall")
8 |
9 |
10 | ##ANDROID_PLATFORM_LEVEL=18
11 | add_definitions("-DDYNAMIC_ES3")
12 | set(OPENGL_LIB GLESv3)
13 |
14 |
15 | add_library(native-simple
16 | SHARED
17 | src/main/cpp/native_simple.cpp)
18 |
19 | target_link_libraries(native-simple
20 | ${OPENGL_LIB}
21 | android
22 | EGL
23 | log
24 | m)
25 |
--------------------------------------------------------------------------------
/sample-basis/build.gradle:
--------------------------------------------------------------------------------
1 | apply from: "$rootDir/module.gradle"
2 |
3 | android {
4 | defaultConfig {
5 | externalNativeBuild {
6 | cmake {
7 | cppFlags ""
8 | arguments '-DANDROID_STL=c++_static'
9 | }
10 | ndk {
11 | abiFilters "armeabi-v7a","arm64-v8a"
12 | }
13 | }
14 | }
15 | externalNativeBuild {
16 | cmake {
17 | path "CMakeLists.txt"
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/sample-basis/gradle.properties:
--------------------------------------------------------------------------------
1 |
2 |
3 | library=true
--------------------------------------------------------------------------------
/sample-basis/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/sample-basis/src/main/cpp/native_simple.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 | #include
5 | #include "native_simple.h"
6 |
7 | #ifdef ANDROID
8 |
9 | #include
10 |
11 | #define LOG_TAG "HelloTriangle"
12 | #define LOGE(format, ...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, format, ##__VA_ARGS__)
13 | #define LOGI(format, ...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, format, ##__VA_ARGS__)
14 | #else
15 | #define LOGE(format, ...) printf(LOG_TAG format "\n", ##__VA_ARGS__)
16 | #define LOGI(format, ...) printf(LOG_TAG format "\n", ##__VA_ARGS__)
17 | #endif
18 |
19 |
20 | /**
21 | * 动态注册
22 | */
23 | JNINativeMethod methods[] = {
24 | {"surfaceCreated", "()V", (void *) surfaceCreated},
25 | {"surfaceChanged", "(II)V", (void *) surfaceChanged},
26 | {"onDrawFrame", "()V", (void *) onDrawFrame}
27 | };
28 |
29 | /**
30 | * 动态注册
31 | * @param env
32 | * @return
33 | */
34 | jint registerNativeMethod(JNIEnv *env) {
35 | jclass cl = env->FindClass("com/onzhou/opengles/simple/NativeSimpleRenderer");
36 | if ((env->RegisterNatives(cl, methods, sizeof(methods) / sizeof(methods[0]))) < 0) {
37 | return -1;
38 | }
39 | return 0;
40 | }
41 |
42 | /**
43 | * 加载默认回调
44 | * @param vm
45 | * @param reserved
46 | * @return
47 | */
48 | jint JNI_OnLoad(JavaVM *vm, void *reserved) {
49 | JNIEnv *env = NULL;
50 | if (vm->GetEnv((void **) &env, JNI_VERSION_1_6) != JNI_OK) {
51 | return -1;
52 | }
53 | //注册方法
54 | if (registerNativeMethod(env) != JNI_OK) {
55 | return -1;
56 | }
57 | return JNI_VERSION_1_6;
58 | }
59 |
60 | const GLfloat TRIANGLE_VERTICES[] = {0.0f, 0.5f, 0.0f,
61 | -0.5f, -0.5f, 0.0f,
62 | 0.5f, -0.5f, 0.0f};
63 |
64 | const char VERTEX_SHADER[] =
65 | "#version 300 es \n"
66 | "layout (location = 0) in vec4 vPosition;\n"
67 | "layout (location = 1) in vec4 aColor;\n"
68 | "out vec4 vColor;\n"
69 | "void main() { \n"
70 | "gl_Position = vPosition;\n"
71 | "gl_PointSize = 10.0;\n"
72 | "vColor = aColor;\n"
73 | "}\n";
74 |
75 | const char FRAGMENT_SHADER[] =
76 | "#version 300 es \n"
77 | "precision mediump float;\n"
78 | "in vec4 vColor;\n"
79 | "out vec4 fragColor;\n"
80 | "void main() { \n"
81 | "fragColor = vColor;\n"
82 | "}\n";
83 |
84 | float color[] = {
85 | 0.0f, 1.0f, 0.0f, 1.0f,
86 | 1.0f, 0.0f, 0.0f, 1.0f,
87 | 0.0f, 0.0f, 1.0f, 1.0f
88 | };
89 |
90 | GLuint CompileShader(GLenum type, const char *shaderCode) {
91 | GLint shader = glCreateShader(type);
92 | if (shader != 0) {
93 | glShaderSource(shader, 1, &shaderCode, NULL);
94 | glCompileShader(shader);
95 | //检测状态
96 | GLint glResult = GL_FALSE;
97 | glGetShaderiv(shader, GL_COMPILE_STATUS, &glResult);
98 | if (glResult == GL_FALSE) {
99 | //创建失败
100 | glDeleteShader(shader);
101 | return 0;
102 | }
103 | return shader;
104 | }
105 | //创建失败
106 | return 0;
107 | }
108 |
109 | GLint LinkProgram(GLint vertexShader, GLint fragmentShader) {
110 | GLint program = glCreateProgram();
111 | if (program != 0) {
112 | //将顶点着色器加入到程序
113 | glAttachShader(program, vertexShader);
114 | //将片元着色器加入到程序中
115 | glAttachShader(program, fragmentShader);
116 | //链接着色器程序
117 | glLinkProgram(program);
118 | GLint linkStatus = GL_FALSE;
119 | glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
120 | if (linkStatus == GL_FALSE) {
121 | glDeleteProgram(program);
122 | return 0;
123 | }
124 | return program;
125 | }
126 | //创建失败
127 | return 0;
128 | }
129 |
130 | JNIEXPORT void JNICALL surfaceCreated(JNIEnv *env, jobject obj) {
131 | //创建顶点着色器
132 | GLint vertexShader = CompileShader(GL_VERTEX_SHADER, VERTEX_SHADER);
133 | if (vertexShader == 0) {
134 | LOGE("loadVertexShader Failed");
135 | return;
136 | }
137 | //创建片段着色器
138 | GLint fragmentShader = CompileShader(GL_FRAGMENT_SHADER, FRAGMENT_SHADER);
139 | if (fragmentShader == 0) {
140 | LOGE("loadFragmentShader Failed");
141 | return;
142 | }
143 | GLint program = LinkProgram(vertexShader, fragmentShader);
144 | //在OpenGLES环境中使用程序片段
145 | glUseProgram(program);
146 |
147 | //设置背景颜色
148 | glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
149 | }
150 |
151 | JNIEXPORT void JNICALL surfaceChanged(JNIEnv *env, jobject obj, jint width, jint height) {
152 | glViewport(0, 0, width, height);
153 | }
154 |
155 | JNIEXPORT void JNICALL onDrawFrame(JNIEnv *env, jobject obj) {
156 | //把颜色缓冲区设置为我们预设的颜色
157 | glClear(GL_COLOR_BUFFER_BIT);
158 | //准备坐标数据
159 | glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, TRIANGLE_VERTICES);
160 | //启用顶点的句柄
161 | glEnableVertexAttribArray(0);
162 |
163 | //绘制三角形颜色
164 | glEnableVertexAttribArray(1);
165 | glVertexAttribPointer(1, 4, GL_FLOAT, false, 0, color);
166 |
167 | //绘制
168 | glDrawArrays(GL_TRIANGLES, 0, 3);
169 | //禁止顶点数组的句柄
170 | glDisableVertexAttribArray(0);
171 | glDisableVertexAttribArray(1);
172 | }
--------------------------------------------------------------------------------
/sample-basis/src/main/cpp/native_simple.h:
--------------------------------------------------------------------------------
1 | /* DO NOT EDIT THIS FILE - it is machine generated */
2 | #include
3 | /* Header for class com_onzhou_opengles_triangle_NativeTriangleRenderer */
4 |
5 | #ifndef _Included_com_onzhou_opengles_triangle_NativeTriangleRenderer
6 | #define _Included_com_onzhou_opengles_triangle_NativeTriangleRenderer
7 | #ifdef __cplusplus
8 | extern "C" {
9 | #endif
10 |
11 | JNIEXPORT void JNICALL surfaceCreated(JNIEnv *, jobject);
12 |
13 | JNIEXPORT void JNICALL surfaceChanged(JNIEnv *, jobject, jint, jint);
14 |
15 | JNIEXPORT void JNICALL onDrawFrame(JNIEnv *, jobject);
16 |
17 |
18 | #ifdef __cplusplus
19 | }
20 | #endif
21 | #endif
22 |
--------------------------------------------------------------------------------
/sample-basis/src/main/debug/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
7 |
8 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/sample-basis/src/main/java/com/onzhou/opengles/main/SimpleActivity.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.main;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.opengl.GLSurfaceView;
6 |
7 | import com.onzhou.opengles.base.AbsGLSurfaceActivity;
8 | import com.onzhou.opengles.simple.IndicesCubeRenderer;
9 |
10 | /**
11 | * @anchor: andy
12 | * @date: 2018-11-02
13 | * @description:
14 | */
15 | public class SimpleActivity extends AbsGLSurfaceActivity {
16 |
17 | public static void intentStart(Context context) {
18 | Intent intent = new Intent(context, SimpleActivity.class);
19 | context.startActivity(intent);
20 | }
21 |
22 | @Override
23 | protected GLSurfaceView.Renderer bindRenderer() {
24 | return new IndicesCubeRenderer();
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/sample-basis/src/main/java/com/onzhou/opengles/simple/EnableVertexRenderer.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.simple;
2 |
3 | import android.opengl.GLES30;
4 | import android.opengl.GLSurfaceView;
5 |
6 | import com.onzhou.opengles.shader.R;
7 | import com.onzhou.opengles.utils.ResReadUtils;
8 | import com.onzhou.opengles.utils.ShaderUtils;
9 |
10 | import java.nio.ByteBuffer;
11 | import java.nio.ByteOrder;
12 | import java.nio.FloatBuffer;
13 |
14 | import javax.microedition.khronos.egl.EGLConfig;
15 | import javax.microedition.khronos.opengles.GL10;
16 |
17 | /**
18 | * @anchor: andy
19 | * @date: 2018-11-02
20 | * @description:
21 | */
22 | public class EnableVertexRenderer implements GLSurfaceView.Renderer {
23 |
24 | private final FloatBuffer vertexBuffer, colorBuffer;
25 |
26 | private int mProgram;
27 |
28 | /**
29 | * 点的坐标
30 | */
31 | private float[] vertexPoints = new float[]{
32 | 0.0f, 0.5f, 0.0f,
33 | -0.5f, -0.5f, 0.0f,
34 | 0.5f, -0.5f, 0.0f
35 | };
36 |
37 | private float[] vertexColors = new float[]{
38 | 0.5f, 0.5f, 0.8f, 1.0f
39 | };
40 |
41 | public EnableVertexRenderer() {
42 | //分配内存空间,每个浮点型占4字节空间
43 | vertexBuffer = ByteBuffer.allocateDirect(vertexPoints.length * 4)
44 | .order(ByteOrder.nativeOrder())
45 | .asFloatBuffer();
46 | //传入指定的坐标数据
47 | vertexBuffer.put(vertexPoints);
48 | vertexBuffer.position(0);
49 | //为颜色数据分配本地内存空间
50 | colorBuffer = ByteBuffer.allocateDirect(vertexColors.length * 4)
51 | .order(ByteOrder.nativeOrder())
52 | .asFloatBuffer();
53 | //传入指定的坐标数据
54 | colorBuffer.put(vertexColors);
55 | colorBuffer.position(0);
56 | }
57 |
58 | @Override
59 | public void onSurfaceCreated(GL10 gl, EGLConfig config) {
60 | //设置背景颜色
61 | GLES30.glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
62 | //编译
63 | final int vertexShaderId = ShaderUtils.compileVertexShader(ResReadUtils.readResource(R.raw.vertex_enable_shader));
64 | final int fragmentShaderId = ShaderUtils.compileFragmentShader(ResReadUtils.readResource(R.raw.fragment_enable_shader));
65 | //鏈接程序片段
66 | mProgram = ShaderUtils.linkProgram(vertexShaderId, fragmentShaderId);
67 | //使用程序片段
68 | GLES30.glUseProgram(mProgram);
69 | }
70 |
71 | @Override
72 | public void onSurfaceChanged(GL10 gl, int width, int height) {
73 | GLES30.glViewport(0, 0, width, height);
74 | }
75 |
76 | @Override
77 | public void onDrawFrame(GL10 gl) {
78 |
79 | GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
80 | //颜色数据都是一致的
81 | GLES30.glVertexAttrib4fv(1, colorBuffer);
82 |
83 | //获取位置的顶点数组
84 | GLES30.glVertexAttribPointer(0, 3, GLES30.GL_FLOAT, false, 0, vertexBuffer);
85 | //启用位置顶点属性
86 | GLES30.glEnableVertexAttribArray(0);
87 |
88 | //绘制矩形
89 | GLES30.glDrawArrays(GLES30.GL_TRIANGLES, 0, 3);
90 |
91 | //禁用顶点属性
92 | GLES30.glDisableVertexAttribArray(0);
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/sample-basis/src/main/java/com/onzhou/opengles/simple/IndicesCubeRenderer.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.simple;
2 |
3 | import android.opengl.GLES30;
4 | import android.opengl.GLSurfaceView;
5 |
6 | import com.onzhou.opengles.shader.R;
7 | import com.onzhou.opengles.utils.ResReadUtils;
8 | import com.onzhou.opengles.utils.ShaderUtils;
9 |
10 | import java.nio.ByteBuffer;
11 | import java.nio.ByteOrder;
12 | import java.nio.FloatBuffer;
13 | import java.nio.ShortBuffer;
14 |
15 | import javax.microedition.khronos.egl.EGLConfig;
16 | import javax.microedition.khronos.opengles.GL10;
17 |
18 | /**
19 | * @anchor: andy
20 | * @date: 2018-11-09
21 | * @description: 基于索引法绘制立方体
22 | */
23 | public class IndicesCubeRenderer implements GLSurfaceView.Renderer {
24 |
25 | private final FloatBuffer vertexBuffer, colorBuffer;
26 |
27 | private final ShortBuffer indicesBuffer;
28 |
29 | private int mProgram;
30 |
31 | private static final int VERTEX_POSITION_SIZE = 3;
32 |
33 | private static final int VERTEX_COLOR_SIZE = 4;
34 |
35 | /**
36 | * 点的坐标
37 | */
38 | private float[] vertexPoints = new float[]{
39 | //正面矩形
40 | 0.25f, 0.25f, 0.0f, //V0
41 | -0.75f, 0.25f, 0.0f, //V1
42 | -0.75f, -0.75f, 0.0f, //V2
43 | 0.25f, -0.75f, 0.0f, //V3
44 |
45 | //背面矩形
46 | 0.75f, -0.25f, 0.0f, //V4
47 | 0.75f, 0.75f, 0.0f, //V5
48 | -0.25f, 0.75f, 0.0f, //V6
49 | -0.25f, -0.25f, 0.0f //V7
50 | };
51 |
52 | /**
53 | * 定义索引
54 | */
55 | private short[] indices = {
56 | //背面
57 | 5, 6, 7, 5, 7, 4,
58 | //左侧
59 | 6, 1, 2, 6, 2, 7,
60 | //底部
61 | 4, 7, 2, 4, 2, 3,
62 | //顶面
63 | 5, 6, 7, 5, 7, 4,
64 | //右侧
65 | 5, 0, 3, 5, 3, 4,
66 | //正面
67 | 0, 1, 2, 0, 2, 3
68 | };
69 |
70 | //立方体的顶点颜色
71 | private float[] colors = {
72 | 0.3f, 0.4f, 0.5f, 1f, //V0
73 | 0.3f, 0.4f, 0.5f, 1f, //V1
74 | 0.3f, 0.4f, 0.5f, 1f, //V2
75 | 0.3f, 0.4f, 0.5f, 1f, //V3
76 | 0.6f, 0.5f, 0.4f, 1f, //V4
77 | 0.6f, 0.5f, 0.4f, 1f, //V5
78 | 0.6f, 0.5f, 0.4f, 1f, //V6
79 | 0.6f, 0.5f, 0.4f, 1f //V7
80 | };
81 |
82 | public IndicesCubeRenderer() {
83 | //分配内存空间,每个浮点型占4字节空间
84 | vertexBuffer = ByteBuffer.allocateDirect(vertexPoints.length * 4)
85 | .order(ByteOrder.nativeOrder())
86 | .asFloatBuffer();
87 | //传入指定的坐标数据
88 | vertexBuffer.put(vertexPoints);
89 | vertexBuffer.position(0);
90 |
91 | //分配内存空间,每个浮点型占4字节空间
92 | colorBuffer = ByteBuffer.allocateDirect(colors.length * 4)
93 | .order(ByteOrder.nativeOrder())
94 | .asFloatBuffer();
95 | //传入指定的数据
96 | colorBuffer.put(colors);
97 | colorBuffer.position(0);
98 |
99 | //分配内存空间,每个浮点型占4字节空间
100 | indicesBuffer = ByteBuffer.allocateDirect(indices.length * 4)
101 | .order(ByteOrder.nativeOrder())
102 | .asShortBuffer();
103 | //传入指定的数据
104 | indicesBuffer.put(indices);
105 | indicesBuffer.position(0);
106 | }
107 |
108 | @Override
109 | public void onSurfaceCreated(GL10 gl, EGLConfig config) {
110 | //设置背景颜色
111 | GLES30.glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
112 | //编译
113 | final int vertexShaderId = ShaderUtils.compileVertexShader(ResReadUtils.readResource(R.raw.vertex_colorcube_shader));
114 | final int fragmentShaderId = ShaderUtils.compileFragmentShader(ResReadUtils.readResource(R.raw.fragment_colorcube_shader));
115 | //链接程序片段
116 | mProgram = ShaderUtils.linkProgram(vertexShaderId, fragmentShaderId);
117 | //使用程序片段
118 | GLES30.glUseProgram(mProgram);
119 |
120 | GLES30.glVertexAttribPointer(0, VERTEX_POSITION_SIZE, GLES30.GL_FLOAT, false, 0, vertexBuffer);
121 | //启用位置顶点属性
122 | GLES30.glEnableVertexAttribArray(0);
123 |
124 | GLES30.glVertexAttribPointer(1, VERTEX_COLOR_SIZE, GLES30.GL_FLOAT, false, 0, colorBuffer);
125 | //启用颜色顶点属性
126 | GLES30.glEnableVertexAttribArray(1);
127 |
128 | }
129 |
130 | @Override
131 | public void onSurfaceChanged(GL10 gl, int width, int height) {
132 | GLES30.glViewport(0, 0, width, height);
133 | }
134 |
135 | @Override
136 | public void onDrawFrame(GL10 gl) {
137 | GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
138 |
139 | GLES30.glDrawElements(GL10.GL_TRIANGLES, indices.length, GL10.GL_UNSIGNED_SHORT, indicesBuffer);
140 |
141 | }
142 | }
143 |
--------------------------------------------------------------------------------
/sample-basis/src/main/java/com/onzhou/opengles/simple/LineCubeRenderer.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.simple;
2 |
3 | import android.opengl.GLES30;
4 | import android.opengl.GLSurfaceView;
5 |
6 | import com.onzhou.opengles.shader.R;
7 | import com.onzhou.opengles.utils.ResReadUtils;
8 | import com.onzhou.opengles.utils.ShaderUtils;
9 |
10 | import java.nio.ByteBuffer;
11 | import java.nio.ByteOrder;
12 | import java.nio.FloatBuffer;
13 |
14 | import javax.microedition.khronos.egl.EGLConfig;
15 | import javax.microedition.khronos.opengles.GL10;
16 |
17 | /**
18 | * @anchor: andy
19 | * @date: 2018-11-09
20 | * @description:
21 | */
22 | public class LineCubeRenderer implements GLSurfaceView.Renderer {
23 |
24 | private final FloatBuffer vertexBuffer;
25 |
26 | private int mProgram;
27 |
28 | private static final int POSITION_COMPONENT_COUNT = 3;
29 |
30 | /**
31 | * 点的坐标
32 | */
33 | private float[] vertexPoints = new float[]{
34 | 0.25f, 0.25f, 0.0f, //V0
35 | -0.75f, 0.25f, 0.0f, //V1
36 | -0.75f, -0.75f, 0.0f, //V2
37 | 0.25f, -0.75f, 0.0f, //V3
38 |
39 | 0.75f, -0.25f, 0.0f, //V4
40 | 0.75f, 0.75f, 0.0f, //V5
41 | -0.25f, 0.75f, 0.0f, //V6
42 | -0.25f, -0.25f, 0.0f, //V7
43 |
44 | -0.25f, 0.75f, 0.0f, //V6
45 | -0.75f, 0.25f, 0.0f, //V1
46 |
47 | 0.75f, 0.75f, 0.0f, //V5
48 | 0.25f, 0.25f, 0.0f, //V0
49 |
50 | -0.25f, -0.25f, 0.0f, //V7
51 | -0.75f, -0.75f, 0.0f, //V2
52 |
53 | 0.75f, -0.25f, 0.0f, //V4
54 | 0.25f, -0.75f, 0.0f //V3
55 | };
56 |
57 | public LineCubeRenderer() {
58 | //分配内存空间,每个浮点型占4字节空间
59 | vertexBuffer = ByteBuffer.allocateDirect(vertexPoints.length * 4)
60 | .order(ByteOrder.nativeOrder())
61 | .asFloatBuffer();
62 | //传入指定的坐标数据
63 | vertexBuffer.put(vertexPoints);
64 | vertexBuffer.position(0);
65 | }
66 |
67 | @Override
68 | public void onSurfaceCreated(GL10 gl, EGLConfig config) {
69 | //设置背景颜色
70 | GLES30.glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
71 | //编译
72 | final int vertexShaderId = ShaderUtils.compileVertexShader(ResReadUtils.readResource(R.raw.vertex_linecube_shader));
73 | final int fragmentShaderId = ShaderUtils.compileFragmentShader(ResReadUtils.readResource(R.raw.fragment_linecube_shader));
74 | //链接程序片段
75 | mProgram = ShaderUtils.linkProgram(vertexShaderId, fragmentShaderId);
76 | //使用程序片段
77 | GLES30.glUseProgram(mProgram);
78 |
79 | GLES30.glVertexAttribPointer(0, POSITION_COMPONENT_COUNT, GLES30.GL_FLOAT, false, 0, vertexBuffer);
80 |
81 | GLES30.glEnableVertexAttribArray(0);
82 |
83 | }
84 |
85 | @Override
86 | public void onSurfaceChanged(GL10 gl, int width, int height) {
87 | GLES30.glViewport(0, 0, width, height);
88 | }
89 |
90 | @Override
91 | public void onDrawFrame(GL10 gl) {
92 | GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
93 |
94 | //指定线宽
95 | GLES30.glLineWidth(5);
96 |
97 | GLES30.glDrawArrays(GLES30.GL_LINE_LOOP, 0, 4);
98 |
99 | GLES30.glDrawArrays(GLES30.GL_LINE_LOOP, 4, 4);
100 |
101 | GLES30.glDrawArrays(GLES30.GL_LINES, 8, 8);
102 |
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/sample-basis/src/main/java/com/onzhou/opengles/simple/MapBufferRenderer.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.simple;
2 |
3 | import android.opengl.GLES30;
4 | import android.opengl.GLSurfaceView;
5 | import android.util.Log;
6 |
7 | import com.onzhou.opengles.shader.R;
8 | import com.onzhou.opengles.utils.ResReadUtils;
9 | import com.onzhou.opengles.utils.ShaderUtils;
10 |
11 | import java.nio.Buffer;
12 | import java.nio.ByteBuffer;
13 | import java.nio.ByteOrder;
14 | import java.nio.FloatBuffer;
15 |
16 | import javax.microedition.khronos.egl.EGLConfig;
17 | import javax.microedition.khronos.opengles.GL10;
18 |
19 | /**
20 | * @anchor: andy
21 | * @date: 2018-11-02
22 | * @description: 映射缓冲区对象
23 | */
24 | public class MapBufferRenderer implements GLSurfaceView.Renderer {
25 |
26 | private static final String TAG = "VertexBufferRenderer";
27 |
28 | private static final int VERTEX_POS_INDEX = 0;
29 |
30 | private static final int VERTEX_POS_SIZE = 3;
31 |
32 | private static final int VERTEX_STRIDE = VERTEX_POS_SIZE * 4;
33 |
34 | private int mProgram;
35 |
36 | /**
37 | * 点的坐标
38 | */
39 | private float[] vertexPoints = new float[]{
40 | 0.0f, 0.5f, 0.0f,
41 | -0.5f, -0.5f, 0.0f,
42 | 0.5f, -0.5f, 0.0f
43 | };
44 |
45 | private int[] vboIds = new int[1];
46 |
47 | @Override
48 | public void onSurfaceCreated(GL10 gl, EGLConfig config) {
49 | //设置背景颜色
50 | GLES30.glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
51 | //编译
52 | final int vertexShaderId = ShaderUtils.compileVertexShader(ResReadUtils.readResource(R.raw.vertex_map_buffer_shader));
53 | final int fragmentShaderId = ShaderUtils.compileFragmentShader(ResReadUtils.readResource(R.raw.fragment_map_buffer_shader));
54 | //鏈接程序片段
55 | mProgram = ShaderUtils.linkProgram(vertexShaderId, fragmentShaderId);
56 |
57 | //1. 生成1个缓冲ID
58 | GLES30.glGenBuffers(1, vboIds, 0);
59 | //2. 向顶点坐标数据缓冲送入数据把顶点数组复制到缓冲中
60 | GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, vboIds[0]);
61 | GLES30.glBufferData(GLES30.GL_ARRAY_BUFFER, vertexPoints.length * 4, null, GLES30.GL_STATIC_DRAW);
62 |
63 | //3. 映射缓冲区对象
64 | ByteBuffer buffer = (ByteBuffer) GLES30.glMapBufferRange(GLES30.GL_ARRAY_BUFFER, 0, vertexPoints.length * 4, GLES30.GL_MAP_WRITE_BIT | GLES30.GL_MAP_INVALIDATE_BUFFER_BIT);
65 | //4. 填充数据
66 | buffer.order(ByteOrder.nativeOrder()).asFloatBuffer().put(vertexPoints).position(0);
67 |
68 | //5. 将顶点位置数据送入渲染管线
69 | GLES30.glVertexAttribPointer(VERTEX_POS_INDEX, VERTEX_POS_SIZE, GLES30.GL_FLOAT, false, VERTEX_STRIDE, 0);
70 | //启用顶点位置属性
71 | GLES30.glEnableVertexAttribArray(VERTEX_POS_INDEX);
72 |
73 | //解除映射
74 | GLES30.glUnmapBuffer(GLES30.GL_ARRAY_BUFFER);
75 | }
76 |
77 | @Override
78 | public void onSurfaceChanged(GL10 gl, int width, int height) {
79 | GLES30.glViewport(0, 0, width, height);
80 | }
81 |
82 | @Override
83 | public void onDrawFrame(GL10 gl) {
84 | GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
85 | //使用程序片段
86 | GLES30.glUseProgram(mProgram);
87 |
88 | //6. 开始绘制三角形
89 | GLES30.glDrawArrays(GLES30.GL_TRIANGLES, 0, 3);
90 |
91 | GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0);
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/sample-basis/src/main/java/com/onzhou/opengles/simple/NativeSimpleRenderer.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.simple;
2 |
3 | import android.opengl.GLES30;
4 | import android.opengl.GLSurfaceView;
5 |
6 | import com.onzhou.opengles.utils.ShaderUtils;
7 |
8 | import java.nio.ByteBuffer;
9 | import java.nio.ByteOrder;
10 | import java.nio.FloatBuffer;
11 |
12 | import javax.microedition.khronos.egl.EGLConfig;
13 | import javax.microedition.khronos.opengles.GL10;
14 |
15 | /**
16 | * @anchor: andy
17 | * @date: 2018-11-02
18 | * @description:
19 | */
20 | public class NativeSimpleRenderer implements GLSurfaceView.Renderer {
21 |
22 | static {
23 | System.loadLibrary("native-simple");
24 | }
25 |
26 | public native void surfaceCreated();
27 |
28 | public native void surfaceChanged(int width, int height);
29 |
30 | public native void onDrawFrame();
31 |
32 | @Override
33 | public void onSurfaceCreated(GL10 gl, EGLConfig config) {
34 | surfaceCreated();
35 | }
36 |
37 | @Override
38 | public void onSurfaceChanged(GL10 gl, int width, int height) {
39 | surfaceChanged(width, height);
40 | }
41 |
42 | @Override
43 | public void onDrawFrame(GL10 gl) {
44 | onDrawFrame();
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/sample-basis/src/main/java/com/onzhou/opengles/simple/RectangleWRenderer.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.simple;
2 |
3 | import android.opengl.GLES30;
4 | import android.opengl.GLSurfaceView;
5 |
6 | import com.onzhou.opengles.shader.R;
7 | import com.onzhou.opengles.utils.ResReadUtils;
8 | import com.onzhou.opengles.utils.ShaderUtils;
9 |
10 | import java.nio.ByteBuffer;
11 | import java.nio.ByteOrder;
12 | import java.nio.FloatBuffer;
13 |
14 | import javax.microedition.khronos.egl.EGLConfig;
15 | import javax.microedition.khronos.opengles.GL10;
16 |
17 | /**
18 | * @anchor: andy
19 | * @date: 2018-11-02
20 | * @description:
21 | */
22 | public class RectangleWRenderer implements GLSurfaceView.Renderer {
23 |
24 | private final FloatBuffer vertexBuffer;
25 |
26 | private int mProgram;
27 |
28 | private static final int POSITION_COMPONENT_COUNT = 4;
29 |
30 | private static final int COLOR_COMPONENT_COUNT = 3;
31 |
32 | private static final int BYTES_PER_FLOAT = 4;
33 |
34 | private static final int STRIDE =
35 | (POSITION_COMPONENT_COUNT + COLOR_COMPONENT_COUNT) * BYTES_PER_FLOAT;
36 |
37 | /**
38 | * 点的坐标
39 | * (X, Y, Z, W, R, G, B)
40 | */
41 | private float[] vertexPoints = new float[]{
42 | 0.0f, 0.0f, 0.0f, 1.5f, 1.0f, 1.0f, 1.0f,
43 | -0.5f, -0.6f, 0.0f, 1f, 1.0f, 1.0f, 1.0f,
44 | 0.5f, -0.6f, 0.0f, 1f, 1.0f, 1.0f, 1.0f,
45 | 0.5f, 0.6f, 0.0f, 2f, 1.0f, 1.0f, 1.0f,
46 | -0.5f, 0.6f, 0.0f, 2f, 1.0f, 1.0f, 1.0f,
47 | -0.5f, -0.6f, 0.0f, 1f, 1.0f, 1.0f, 1.0f,
48 |
49 | 0.0f, -0.4f, 0.0f, 1.25f, 0.5f, 0.5f, 0.5f,
50 | 0.0f, 0.4f, 0.0f, 1.75f, 0.5f, 0.5f, 0.5f,
51 | };
52 |
53 | private int aPositionLocation;
54 |
55 | private int aColorLocation;
56 |
57 | public RectangleWRenderer() {
58 | //分配内存空间,每个浮点型占4字节空间
59 | vertexBuffer = ByteBuffer.allocateDirect(vertexPoints.length * 4)
60 | .order(ByteOrder.nativeOrder())
61 | .asFloatBuffer();
62 | //传入指定的坐标数据
63 | vertexBuffer.put(vertexPoints);
64 | vertexBuffer.position(0);
65 | }
66 |
67 | @Override
68 | public void onSurfaceCreated(GL10 gl, EGLConfig config) {
69 | //设置背景颜色
70 | GLES30.glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
71 |
72 | //编译
73 | final int vertexShaderId = ShaderUtils.compileVertexShader(ResReadUtils.readResource(R.raw.vertex_w_shader));
74 | final int fragmentShaderId = ShaderUtils.compileFragmentShader(ResReadUtils.readResource(R.raw.fragment_w_shader));
75 | //鏈接程序片段
76 | mProgram = ShaderUtils.linkProgram(vertexShaderId, fragmentShaderId);
77 | //在OpenGLES环境中使用程序片段
78 | GLES30.glUseProgram(mProgram);
79 |
80 | //uMatrixLocation = GLES30.glGetUniformLocation(mProgram, "u_Matrix");
81 |
82 | aPositionLocation = GLES30.glGetAttribLocation(mProgram, "vPosition");
83 | aColorLocation = GLES30.glGetAttribLocation(mProgram, "aColor");
84 |
85 | vertexBuffer.position(0);
86 | GLES30.glVertexAttribPointer(aPositionLocation,
87 | POSITION_COMPONENT_COUNT, GLES30.GL_FLOAT, false, STRIDE, vertexBuffer);
88 |
89 | GLES30.glEnableVertexAttribArray(aPositionLocation);
90 |
91 | vertexBuffer.position(POSITION_COMPONENT_COUNT);
92 | GLES30.glVertexAttribPointer(aColorLocation,
93 | COLOR_COMPONENT_COUNT, GLES30.GL_FLOAT, false, STRIDE, vertexBuffer);
94 |
95 | GLES30.glEnableVertexAttribArray(aColorLocation);
96 |
97 | }
98 |
99 | @Override
100 | public void onSurfaceChanged(GL10 gl, int width, int height) {
101 | GLES30.glViewport(0, 0, width, height);
102 | }
103 |
104 | @Override
105 | public void onDrawFrame(GL10 gl) {
106 | GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
107 |
108 | //绘制矩形
109 | GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 6);
110 |
111 | //绘制两个点
112 | GLES30.glDrawArrays(GLES30.GL_POINTS, 6, 2);
113 |
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/sample-basis/src/main/java/com/onzhou/opengles/simple/SimpleRenderer.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.simple;
2 |
3 | import android.opengl.GLES30;
4 | import android.opengl.GLSurfaceView;
5 |
6 | import com.onzhou.opengles.utils.ShaderUtils;
7 |
8 | import java.nio.ByteBuffer;
9 | import java.nio.ByteOrder;
10 | import java.nio.FloatBuffer;
11 |
12 | import javax.microedition.khronos.egl.EGLConfig;
13 | import javax.microedition.khronos.opengles.GL10;
14 |
15 | /**
16 | * @anchor: andy
17 | * @date: 2018-11-02
18 | * @description:
19 | */
20 | public class SimpleRenderer implements GLSurfaceView.Renderer {
21 |
22 | private static final int POSITION_COMPONENT_COUNT = 3;
23 |
24 | private final FloatBuffer vertexBuffer;
25 |
26 | private final FloatBuffer colorBuffer;
27 |
28 | private int mProgram;
29 |
30 | /**
31 | * 点的坐标
32 | */
33 | private float[] vertexPoints = new float[]{
34 | 0.0f, 0.5f, 0.0f,
35 | -0.5f, -0.5f, 0.0f,
36 | 0.5f, -0.5f, 0.0f
37 | };
38 |
39 | /**
40 | * 顶点着色器
41 | */
42 | private String vertextShader =
43 | "#version 300 es \n" +
44 | "layout (location = 0) in vec4 vPosition;\n"
45 | + "layout (location = 1) in vec4 aColor;\n"
46 | + "out vec4 vColor;\n"
47 | + "void main() { \n"
48 | + "gl_Position = vPosition;\n"
49 | + "gl_PointSize = 10.0;\n"
50 | + "vColor = aColor;\n"
51 | + "}\n";
52 |
53 | private String fragmentShader =
54 | "#version 300 es \n" +
55 | "precision mediump float;\n"
56 | + "in vec4 vColor;\n"
57 | + "out vec4 fragColor;\n"
58 | + "void main() { \n"
59 | + "fragColor = vColor; \n"
60 | + "}\n";
61 |
62 | private float color[] = {
63 | 0.0f, 1.0f, 0.0f, 1.0f,
64 | 1.0f, 0.0f, 0.0f, 1.0f,
65 | 0.0f, 0.0f, 1.0f, 1.0f
66 | };
67 |
68 | public SimpleRenderer() {
69 | //分配内存空间,每个浮点型占4字节空间
70 | vertexBuffer = ByteBuffer.allocateDirect(vertexPoints.length * 4)
71 | .order(ByteOrder.nativeOrder())
72 | .asFloatBuffer();
73 | //传入指定的坐标数据
74 | vertexBuffer.put(vertexPoints);
75 | vertexBuffer.position(0);
76 |
77 | colorBuffer = ByteBuffer.allocateDirect(color.length * 4)
78 | .order(ByteOrder.nativeOrder())
79 | .asFloatBuffer();
80 | //传入指定的数据
81 | colorBuffer.put(color);
82 | colorBuffer.position(0);
83 | }
84 |
85 | @Override
86 | public void onSurfaceCreated(GL10 gl, EGLConfig config) {
87 | //设置背景颜色
88 | GLES30.glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
89 |
90 | //编译
91 | final int vertexShaderId = ShaderUtils.compileVertexShader(vertextShader);
92 | final int fragmentShaderId = ShaderUtils.compileFragmentShader(fragmentShader);
93 | //鏈接程序片段
94 | mProgram = ShaderUtils.linkProgram(vertexShaderId, fragmentShaderId);
95 | //在OpenGLES环境中使用程序片段
96 | GLES30.glUseProgram(mProgram);
97 | }
98 |
99 | @Override
100 | public void onSurfaceChanged(GL10 gl, int width, int height) {
101 | GLES30.glViewport(0, 0, width, height);
102 | }
103 |
104 | @Override
105 | public void onDrawFrame(GL10 gl) {
106 | GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
107 |
108 | //准备坐标数据
109 | GLES30.glVertexAttribPointer(0, POSITION_COMPONENT_COUNT, GLES30.GL_FLOAT, false, 0, vertexBuffer);
110 | //启用顶点的句柄
111 | GLES30.glEnableVertexAttribArray(0);
112 |
113 | //绘制三角形颜色
114 | GLES30.glEnableVertexAttribArray(1);
115 | GLES30.glVertexAttribPointer(1, 4, GLES30.GL_FLOAT, false, 0, colorBuffer);
116 |
117 | GLES30.glDrawArrays(GLES30.GL_TRIANGLES, 0, 3);
118 |
119 | //禁止顶点数组的句柄
120 | GLES30.glDisableVertexAttribArray(0);
121 | GLES30.glDisableVertexAttribArray(1);
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/sample-basis/src/main/java/com/onzhou/opengles/simple/UniformRenderer.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.simple;
2 |
3 | import android.opengl.GLES30;
4 | import android.opengl.GLSurfaceView;
5 | import android.opengl.Matrix;
6 | import android.util.Log;
7 |
8 | import com.onzhou.opengles.shader.R;
9 | import com.onzhou.opengles.utils.ResReadUtils;
10 | import com.onzhou.opengles.utils.ShaderUtils;
11 |
12 | import java.io.UnsupportedEncodingException;
13 | import java.nio.ByteBuffer;
14 | import java.nio.ByteOrder;
15 | import java.nio.FloatBuffer;
16 |
17 | import javax.microedition.khronos.egl.EGLConfig;
18 | import javax.microedition.khronos.opengles.GL10;
19 |
20 | /**
21 | * @anchor: andy
22 | * @date: 2018-11-02
23 | * @description:
24 | */
25 | public class UniformRenderer implements GLSurfaceView.Renderer {
26 |
27 | private static final String TAG = "UniformRenderer";
28 |
29 | private int mProgram;
30 |
31 | @Override
32 | public void onSurfaceCreated(GL10 gl, EGLConfig config) {
33 | //设置背景颜色
34 | GLES30.glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
35 | //编译
36 | final int vertexShaderId = ShaderUtils.compileVertexShader(ResReadUtils.readResource(R.raw.vertex_uniform_shader));
37 | final int fragmentShaderId = ShaderUtils.compileFragmentShader(ResReadUtils.readResource(R.raw.fragment_uniform_shader));
38 | //鏈接程序片段
39 | mProgram = ShaderUtils.linkProgram(vertexShaderId, fragmentShaderId);
40 | //在OpenGLES环境中使用程序片段
41 | GLES30.glUseProgram(mProgram);
42 |
43 |
44 | final int[] maxUniforms = new int[1];
45 | GLES30.glGetProgramiv(mProgram, GLES30.GL_ACTIVE_UNIFORM_MAX_LENGTH, maxUniforms, 0);
46 | final int[] numUniforms = new int[1];
47 | GLES30.glGetProgramiv(mProgram, GLES30.GL_ACTIVE_UNIFORMS, numUniforms, 0);
48 |
49 | Log.d(TAG, "maxUniforms=" + maxUniforms[0] + " numUniforms=" + numUniforms[0]);
50 |
51 | int[] length = new int[1];
52 | int[] size = new int[1];
53 | int[] type = new int[1];
54 | byte[] nameBuffer = new byte[maxUniforms[0] - 1];
55 |
56 | for (int index = 0; index < numUniforms[0]; index++) {
57 | GLES30.glGetActiveUniform(mProgram, index, maxUniforms[0], length, 0, size, 0, type, 0, nameBuffer, 0);
58 | String uniformName = new String(nameBuffer);
59 | int location = GLES30.glGetUniformLocation(mProgram, uniformName);
60 |
61 | Log.d(TAG, "uniformName=" + uniformName + " location=" + location + " type=" + type[0] + " size=" + size[0]);
62 | }
63 | }
64 |
65 | @Override
66 | public void onSurfaceChanged(GL10 gl, int width, int height) {
67 | GLES30.glViewport(0, 0, width, height);
68 | }
69 |
70 | @Override
71 | public void onDrawFrame(GL10 gl) {
72 | GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/sample-basis/src/main/java/com/onzhou/opengles/simple/VertexArrayRenderer.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.simple;
2 |
3 | import android.opengl.GLES30;
4 | import android.opengl.GLSurfaceView;
5 |
6 | import com.onzhou.opengles.shader.R;
7 | import com.onzhou.opengles.utils.ResReadUtils;
8 | import com.onzhou.opengles.utils.ShaderUtils;
9 |
10 | import java.nio.ByteBuffer;
11 | import java.nio.ByteOrder;
12 | import java.nio.FloatBuffer;
13 |
14 | import javax.microedition.khronos.egl.EGLConfig;
15 | import javax.microedition.khronos.opengles.GL10;
16 |
17 | /**
18 | * @anchor: andy
19 | * @date: 2018-11-02
20 | * @description: 顶点数组对象
21 | */
22 | public class VertexArrayRenderer implements GLSurfaceView.Renderer {
23 |
24 | private static final String TAG = "VertexBufferRenderer";
25 |
26 | private static final int VERTEX_POS_INDEX = 0;
27 |
28 | private final FloatBuffer vertexBuffer;
29 |
30 | private static final int VERTEX_POS_SIZE = 3;
31 |
32 | private static final int VERTEX_STRIDE = VERTEX_POS_SIZE * 4;
33 |
34 | private int mProgram;
35 |
36 | /**
37 | * 点的坐标
38 | */
39 | private float[] vertexPoints = new float[]{
40 | 0.0f, 0.5f, 0.0f,
41 | -0.5f, -0.5f, 0.0f,
42 | 0.5f, -0.5f, 0.0f
43 | };
44 |
45 | /**
46 | * 缓冲数组
47 | */
48 | private int[] vaoIds = new int[1];
49 |
50 | private int[] vboIds = new int[1];
51 |
52 | public VertexArrayRenderer() {
53 | //分配内存空间,每个浮点型占4字节空间
54 | vertexBuffer = ByteBuffer.allocateDirect(vertexPoints.length * 4)
55 | .order(ByteOrder.nativeOrder())
56 | .asFloatBuffer();
57 | //传入指定的坐标数据
58 | vertexBuffer.put(vertexPoints);
59 | vertexBuffer.position(0);
60 | }
61 |
62 | @Override
63 | public void onSurfaceCreated(GL10 gl, EGLConfig config) {
64 | //设置背景颜色
65 | GLES30.glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
66 | //编译
67 | final int vertexShaderId = ShaderUtils.compileVertexShader(ResReadUtils.readResource(R.raw.vertex_array_shader));
68 | final int fragmentShaderId = ShaderUtils.compileFragmentShader(ResReadUtils.readResource(R.raw.fragment_array_shader));
69 | //鏈接程序片段
70 | mProgram = ShaderUtils.linkProgram(vertexShaderId, fragmentShaderId);
71 |
72 | //生成1个缓冲ID
73 | GLES30.glGenVertexArrays(1, vaoIds, 0);
74 |
75 | //绑定VAO
76 | GLES30.glBindVertexArray(vaoIds[0]);
77 |
78 | //1. 生成1个缓冲ID
79 | GLES30.glGenBuffers(1, vboIds, 0);
80 | //2. 向顶点坐标数据缓冲送入数据把顶点数组复制到缓冲中
81 | GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, vboIds[0]);
82 | GLES30.glBufferData(GLES30.GL_ARRAY_BUFFER, vertexPoints.length * 4, vertexBuffer, GLES30.GL_STATIC_DRAW);
83 |
84 | //3. 将顶点位置数据送入渲染管线
85 | GLES30.glVertexAttribPointer(VERTEX_POS_INDEX, VERTEX_POS_SIZE, GLES30.GL_FLOAT, false, VERTEX_STRIDE, 0);
86 | //启用顶点位置属性
87 | GLES30.glEnableVertexAttribArray(VERTEX_POS_INDEX);
88 |
89 | //4. 解绑VAO
90 | GLES30.glBindVertexArray(0);
91 | }
92 |
93 | @Override
94 | public void onSurfaceChanged(GL10 gl, int width, int height) {
95 | GLES30.glViewport(0, 0, width, height);
96 | }
97 |
98 | @Override
99 | public void onDrawFrame(GL10 gl) {
100 |
101 | GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
102 | //使用程序片段
103 | GLES30.glUseProgram(mProgram);
104 |
105 | //5. 绑定VAO
106 | GLES30.glBindVertexArray(vaoIds[0]);
107 |
108 | //6. 开始绘制三角形
109 | GLES30.glDrawArrays(GLES30.GL_TRIANGLES, 0, 3);
110 |
111 | //7. 解绑VAO
112 | GLES30.glBindVertexArray(0);
113 |
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/sample-basis/src/main/java/com/onzhou/opengles/simple/VertexBufferRenderer.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.simple;
2 |
3 | import android.opengl.GLES30;
4 | import android.opengl.GLSurfaceView;
5 | import android.util.Log;
6 |
7 | import com.onzhou.opengles.shader.R;
8 | import com.onzhou.opengles.utils.ResReadUtils;
9 | import com.onzhou.opengles.utils.ShaderUtils;
10 |
11 | import java.nio.ByteBuffer;
12 | import java.nio.ByteOrder;
13 | import java.nio.FloatBuffer;
14 | import java.nio.ShortBuffer;
15 |
16 | import javax.microedition.khronos.egl.EGLConfig;
17 | import javax.microedition.khronos.opengles.GL10;
18 |
19 | /**
20 | * @anchor: andy
21 | * @date: 2018-11-02
22 | * @description: 顶点缓冲区
23 | */
24 | public class VertexBufferRenderer implements GLSurfaceView.Renderer {
25 |
26 | private static final String TAG = "VertexBufferRenderer";
27 |
28 | private static final int VERTEX_POS_INDEX = 0;
29 |
30 | private final FloatBuffer vertexBuffer;
31 |
32 | private static final int VERTEX_POS_SIZE = 3;
33 |
34 | private static final int VERTEX_STRIDE = VERTEX_POS_SIZE * 4;
35 |
36 | private int mProgram;
37 |
38 | /**
39 | * 点的坐标
40 | */
41 | private float[] vertexPoints = new float[]{
42 | 0.0f, 0.5f, 0.0f,
43 | -0.5f, -0.5f, 0.0f,
44 | 0.5f, -0.5f, 0.0f
45 | };
46 |
47 | /**
48 | * 缓冲数组
49 | */
50 | private int[] vboIds = new int[1];
51 |
52 | public VertexBufferRenderer() {
53 | //分配内存空间,每个浮点型占4字节空间
54 | vertexBuffer = ByteBuffer.allocateDirect(vertexPoints.length * 4)
55 | .order(ByteOrder.nativeOrder())
56 | .asFloatBuffer();
57 | //传入指定的坐标数据
58 | vertexBuffer.put(vertexPoints);
59 | vertexBuffer.position(0);
60 | }
61 |
62 | @Override
63 | public void onSurfaceCreated(GL10 gl, EGLConfig config) {
64 | //设置背景颜色
65 | GLES30.glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
66 | //编译
67 | final int vertexShaderId = ShaderUtils.compileVertexShader(ResReadUtils.readResource(R.raw.vertex_buffer_shader));
68 | final int fragmentShaderId = ShaderUtils.compileFragmentShader(ResReadUtils.readResource(R.raw.fragment_buffer_shader));
69 | //鏈接程序片段
70 | mProgram = ShaderUtils.linkProgram(vertexShaderId, fragmentShaderId);
71 |
72 | //1. 生成1个缓冲ID
73 | GLES30.glGenBuffers(1, vboIds, 0);
74 |
75 | //2. 绑定到顶点坐标数据缓冲
76 | GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, vboIds[0]);
77 | //3. 向顶点坐标数据缓冲送入数据
78 | GLES30.glBufferData(GLES30.GL_ARRAY_BUFFER, vertexPoints.length * 4, vertexBuffer, GLES30.GL_STATIC_DRAW);
79 |
80 | //4. 将顶点位置数据送入渲染管线
81 | GLES30.glVertexAttribPointer(VERTEX_POS_INDEX, VERTEX_POS_SIZE, GLES30.GL_FLOAT, false, VERTEX_STRIDE, 0);
82 | //5. 启用顶点位置属性
83 | GLES30.glEnableVertexAttribArray(VERTEX_POS_INDEX);
84 |
85 | }
86 |
87 | @Override
88 | public void onSurfaceChanged(GL10 gl, int width, int height) {
89 | GLES30.glViewport(0, 0, width, height);
90 | }
91 |
92 | @Override
93 | public void onDrawFrame(GL10 gl) {
94 | GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
95 | //6. 使用程序片段
96 | GLES30.glUseProgram(mProgram);
97 |
98 | //7. 开始绘制三角形
99 | GLES30.glDrawArrays(GLES30.GL_TRIANGLES, 0, 3);
100 |
101 | //8. 解绑VBO
102 | GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER,0);
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/sample-basis/src/main/java/com/onzhou/opengles/simple/VertexPointerRenderer.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.simple;
2 |
3 | import android.opengl.GLES30;
4 | import android.opengl.GLSurfaceView;
5 |
6 | import com.onzhou.opengles.shader.R;
7 | import com.onzhou.opengles.utils.ResReadUtils;
8 | import com.onzhou.opengles.utils.ShaderUtils;
9 |
10 | import java.nio.ByteBuffer;
11 | import java.nio.ByteOrder;
12 | import java.nio.FloatBuffer;
13 |
14 | import javax.microedition.khronos.egl.EGLConfig;
15 | import javax.microedition.khronos.opengles.GL10;
16 |
17 | /**
18 | * @anchor: andy
19 | * @date: 2018-11-02
20 | * @description:
21 | */
22 | public class VertexPointerRenderer implements GLSurfaceView.Renderer {
23 |
24 | private final FloatBuffer vertexBuffer;
25 |
26 | private int mProgram;
27 |
28 | /**
29 | * 位置顶点属性的大小
30 | * 包含(x,y)
31 | */
32 | private static final int VERTEX_POSITION_SIZE = 2;
33 |
34 | /**
35 | * 颜色顶点属性的大小
36 | * 包含(r,g,b)
37 | */
38 | private static final int VERTEX_COLOR_SIZE = 3;
39 |
40 | /**
41 | * 浮点型数据占用字节数
42 | */
43 | private static final int BYTES_PER_FLOAT = 4;
44 |
45 | /**
46 | * 跨距
47 | */
48 | private static final int VERTEX_ATTRIBUTES_SIZE = (VERTEX_POSITION_SIZE + VERTEX_COLOR_SIZE) * BYTES_PER_FLOAT;
49 |
50 | /**
51 | * 点的坐标
52 | */
53 | private float[] vertexPoints = new float[]{
54 | //前两个为坐标,后三个为颜色
55 | 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
56 | -0.5f, -0.5f, 1.0f, 1.0f, 1.0f,
57 | 0.5f, -0.5f, 1.0f, 1.0f, 1.0f,
58 | 0.5f, 0.5f, 1.0f, 1.0f, 1.0f,
59 | -0.5f, 0.5f, 1.0f, 1.0f, 1.0f,
60 | -0.5f, -0.5f, 1.0f, 1.0f, 1.0f,
61 | //两个点的顶点属性
62 | 0.0f, 0.25f, 0.5f, 0.5f, 0.5f,
63 | 0.0f, -0.25f, 0.5f, 0.5f, 0.5f,
64 | };
65 |
66 | public VertexPointerRenderer() {
67 | //分配内存空间,每个浮点型占4字节空间
68 | vertexBuffer = ByteBuffer.allocateDirect(vertexPoints.length * 4)
69 | .order(ByteOrder.nativeOrder())
70 | .asFloatBuffer();
71 | //传入指定的坐标数据
72 | vertexBuffer.put(vertexPoints);
73 | vertexBuffer.position(0);
74 | }
75 |
76 | @Override
77 | public void onSurfaceCreated(GL10 gl, EGLConfig config) {
78 | //设置背景颜色
79 | GLES30.glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
80 | //编译
81 | final int vertexShaderId = ShaderUtils.compileVertexShader(ResReadUtils.readResource(R.raw.vertex_pointer_shader));
82 | final int fragmentShaderId = ShaderUtils.compileFragmentShader(ResReadUtils.readResource(R.raw.fragment_pointer_shader));
83 | //鏈接程序片段
84 | mProgram = ShaderUtils.linkProgram(vertexShaderId, fragmentShaderId);
85 | //使用程序片段
86 | GLES30.glUseProgram(mProgram);
87 |
88 | vertexBuffer.position(0);
89 | GLES30.glVertexAttribPointer(0, VERTEX_POSITION_SIZE, GLES30.GL_FLOAT, false, VERTEX_ATTRIBUTES_SIZE, vertexBuffer);
90 | //启用顶点属性
91 | GLES30.glEnableVertexAttribArray(0);
92 | //定位本地内存的位置
93 | vertexBuffer.position(VERTEX_POSITION_SIZE);
94 | GLES30.glVertexAttribPointer(1, VERTEX_COLOR_SIZE, GLES30.GL_FLOAT, false, VERTEX_ATTRIBUTES_SIZE, vertexBuffer);
95 |
96 | GLES30.glEnableVertexAttribArray(1);
97 | }
98 |
99 | @Override
100 | public void onSurfaceChanged(GL10 gl, int width, int height) {
101 | GLES30.glViewport(0, 0, width, height);
102 | }
103 |
104 | @Override
105 | public void onDrawFrame(GL10 gl) {
106 | GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
107 |
108 | //绘制矩形
109 | GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 6);
110 |
111 | //绘制两个点
112 | GLES30.glDrawArrays(GLES30.GL_POINTS, 6, 2);
113 |
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/sample-basis/src/main/release/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
8 |
9 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/sample-basis/src/main/res/layout/activity_triangle.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
--------------------------------------------------------------------------------
/sample-basis/src/main/res/raw/fragment_array_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | precision mediump float;
3 | in vec4 vColor;
4 | out vec4 fragColor;
5 | void main() {
6 | fragColor = vColor;
7 | }
--------------------------------------------------------------------------------
/sample-basis/src/main/res/raw/fragment_buffer_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | precision mediump float;
3 | in vec4 vColor;
4 | out vec4 fragColor;
5 | void main() {
6 | fragColor = vColor;
7 | }
--------------------------------------------------------------------------------
/sample-basis/src/main/res/raw/fragment_colorcube_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | precision mediump float;
3 | in vec4 vColor;
4 | out vec4 fragColor;
5 | void main() {
6 | fragColor = vColor;
7 | }
--------------------------------------------------------------------------------
/sample-basis/src/main/res/raw/fragment_enable_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | precision mediump float;
3 | in vec4 vColor;
4 | out vec4 fragColor;
5 | void main() {
6 | fragColor = vColor;
7 | }
--------------------------------------------------------------------------------
/sample-basis/src/main/res/raw/fragment_linecube_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | precision mediump float;
3 | in vec4 vColor;
4 | out vec4 fragColor;
5 | void main() {
6 | fragColor = vColor;
7 | }
--------------------------------------------------------------------------------
/sample-basis/src/main/res/raw/fragment_map_buffer_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | precision mediump float;
3 | in vec4 vColor;
4 | out vec4 fragColor;
5 | void main() {
6 | fragColor = vColor;
7 | }
--------------------------------------------------------------------------------
/sample-basis/src/main/res/raw/fragment_pointer_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | precision mediump float;
3 | in vec4 vColor;
4 | out vec4 fragColor;
5 | void main() {
6 | fragColor = vColor;
7 | }
--------------------------------------------------------------------------------
/sample-basis/src/main/res/raw/fragment_uniform_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | precision mediump float;
3 | in vec4 vColor;
4 | out vec4 fragColor;
5 | void main() {
6 | fragColor = vColor;
7 | }
--------------------------------------------------------------------------------
/sample-basis/src/main/res/raw/fragment_w_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | precision mediump float;
3 | in vec4 vColor;
4 | out vec4 fragColor;
5 | void main() {
6 | fragColor = vColor;
7 | }
--------------------------------------------------------------------------------
/sample-basis/src/main/res/raw/triangle_fragment_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | precision mediump float;
3 | in vec4 vColor;
4 | out vec4 fragColor;
5 | void main() {
6 | fragColor = vColor;
7 | }
8 |
--------------------------------------------------------------------------------
/sample-basis/src/main/res/raw/triangle_vertex_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | layout (location = 0) in vec4 vPosition;
3 | layout (location = 1) in vec4 aColor;
4 | out vec4 vColor;
5 | void main() {
6 | gl_Position = vPosition;
7 | gl_PointSize = 10.0;
8 | vColor = aColor;
9 | }
--------------------------------------------------------------------------------
/sample-basis/src/main/res/raw/vertex_array_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | layout (location = 0) in vec4 vPosition;
3 | out vec4 vColor;
4 | void main() {
5 | gl_Position = vPosition;
6 | gl_PointSize = 10.0;
7 | vColor = vec4(0.3f,0.3f,0.3f,1.0f);
8 | }
--------------------------------------------------------------------------------
/sample-basis/src/main/res/raw/vertex_buffer_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | layout (location = 0) in vec4 vPosition;
3 | out vec4 vColor;
4 | void main() {
5 | gl_Position = vPosition;
6 | gl_PointSize = 10.0;
7 | vColor = vec4(0.2f,0.4f,0.6f,1.0f);
8 | }
--------------------------------------------------------------------------------
/sample-basis/src/main/res/raw/vertex_colorcube_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | layout (location = 0) in vec4 vPosition;
3 | layout (location = 1) in vec4 aColor;
4 | out vec4 vColor;
5 | void main() {
6 | gl_Position = vPosition;
7 | gl_PointSize = 10.0;
8 | vColor = aColor;
9 | }
--------------------------------------------------------------------------------
/sample-basis/src/main/res/raw/vertex_enable_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | layout (location = 0) in vec4 vPosition;
3 | layout (location = 1) in vec4 aColor;
4 | out vec4 vColor;
5 | void main() {
6 | gl_Position = vPosition;
7 | gl_PointSize = 10.0;
8 | vColor = aColor;
9 | }
--------------------------------------------------------------------------------
/sample-basis/src/main/res/raw/vertex_linecube_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | layout (location = 0) in vec4 vPosition;
3 | out vec4 vColor;
4 | void main() {
5 | gl_Position = vPosition;
6 | gl_PointSize = 10.0;
7 | vColor = vec4(0.8,0.8,0.8,1.0);
8 | }
--------------------------------------------------------------------------------
/sample-basis/src/main/res/raw/vertex_map_buffer_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | layout (location = 0) in vec4 vPosition;
3 | out vec4 vColor;
4 | void main() {
5 | gl_Position = vPosition;
6 | gl_PointSize = 10.0;
7 | vColor = vec4(0.1f,0.2f,0.3f,1.0f);
8 | }
--------------------------------------------------------------------------------
/sample-basis/src/main/res/raw/vertex_pointer_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | layout (location = 0) in vec4 vPosition;
3 | layout (location = 1) in vec4 aColor;
4 | out vec4 vColor;
5 | void main() {
6 | gl_Position = vPosition;
7 | gl_PointSize = 10.0;
8 | vColor = aColor;
9 | }
--------------------------------------------------------------------------------
/sample-basis/src/main/res/raw/vertex_uniform_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | uniform mat4 mMatrix4;
3 | uniform mat3 mMatrix3;
4 |
5 | layout (location = 0) in vec4 vPosition;
6 | layout (location = 1) in vec4 aColor;
7 | out vec4 vColor;
8 | void main() {
9 | gl_Position = mMatrix4 * vPosition;
10 | gl_PointSize = 10.0;
11 | vColor = aColor;
12 | }
--------------------------------------------------------------------------------
/sample-basis/src/main/res/raw/vertex_w_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | layout (location = 0) in vec4 vPosition;
3 | layout (location = 1) in vec4 aColor;
4 | out vec4 vColor;
5 | void main() {
6 | gl_Position = vPosition;
7 | gl_PointSize = 10.0;
8 | vColor = aColor;
9 | }
--------------------------------------------------------------------------------
/sample-basis/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 基础示例
3 |
4 |
--------------------------------------------------------------------------------
/sample-basis/src/test/java/com/onzhou/opengles/shader/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.shader;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/sample-camera/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sample-camera/build.gradle:
--------------------------------------------------------------------------------
1 | apply from: "$rootDir/module.gradle"
--------------------------------------------------------------------------------
/sample-camera/gradle.properties:
--------------------------------------------------------------------------------
1 |
2 |
3 | library=true
--------------------------------------------------------------------------------
/sample-camera/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/sample-camera/src/main/debug/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
10 |
11 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/sample-camera/src/main/java/com/onzhou/opengles/api/ICamera.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.api;
2 |
3 | import android.graphics.SurfaceTexture;
4 |
5 | import java.io.IOException;
6 |
7 | /**
8 | * @anchor: andy
9 | * @date: 2018-11-12
10 | * @description:
11 | */
12 | public interface ICamera {
13 |
14 | boolean openCamera(int cameraId);
15 |
16 | void enablePreview(boolean enable);
17 |
18 | void setPreviewTexture(SurfaceTexture surfaceTexture);
19 |
20 | void closeCamera();
21 | }
22 |
--------------------------------------------------------------------------------
/sample-camera/src/main/java/com/onzhou/opengles/api/ITextureRenderer.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.api;
2 |
3 | import android.graphics.SurfaceTexture;
4 |
5 | /**
6 | * @anchor: andy
7 | * @date: 2018-11-11
8 | * @description:
9 | */
10 | public interface ITextureRenderer {
11 |
12 | void onSurfaceCreated();
13 |
14 | void onSurfaceChanged(int width, int height);
15 |
16 | void onDrawFrame(SurfaceTexture surfaceTexture);
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/sample-camera/src/main/java/com/onzhou/opengles/camera/CameraV1.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.camera;
2 |
3 | import android.app.Activity;
4 | import android.graphics.SurfaceTexture;
5 | import android.hardware.Camera;
6 | import android.util.Log;
7 | import android.view.Surface;
8 |
9 | import com.onzhou.opengles.api.ICamera;
10 |
11 | import java.io.IOException;
12 |
13 | /**
14 | * @anchor: andy
15 | * @date: 2018-11-11
16 | * @description: 基于CameraV1
17 | */
18 | public class CameraV1 implements ICamera {
19 |
20 | private Activity mActivity;
21 |
22 | private int mCameraId;
23 |
24 | private Camera mCamera;
25 |
26 | public CameraV1(Activity activity) {
27 | mActivity = activity;
28 | }
29 |
30 | /**
31 | * 打开相机
32 | *
33 | * @param cameraId
34 | * @return
35 | */
36 | public boolean openCamera(int cameraId) {
37 | try {
38 | mCameraId = cameraId;
39 | mCamera = Camera.open(mCameraId);
40 | setCameraDisplayOrientation(mActivity, mCameraId, mCamera);
41 | } catch (Exception e) {
42 | e.printStackTrace();
43 | return false;
44 | }
45 | return true;
46 | }
47 |
48 | /**
49 | * 释放开启预览
50 | *
51 | * @param enable
52 | */
53 | @Override
54 | public void enablePreview(boolean enable) {
55 | if (mCamera != null) {
56 | if (enable) {
57 | mCamera.startPreview();
58 | } else {
59 | mCamera.stopPreview();
60 | }
61 | }
62 | }
63 |
64 | /**
65 | * 设置相机的旋转角度
66 | * 前置相机旋转270度
67 | * 后置相机旋转90度
68 | *
69 | * @param activity
70 | * @param cameraId
71 | * @param camera
72 | */
73 | private void setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera) {
74 | Camera.CameraInfo info =
75 | new Camera.CameraInfo();
76 | Camera.getCameraInfo(cameraId, info);
77 | int rotation = activity.getWindowManager().getDefaultDisplay()
78 | .getRotation();
79 | int degrees = 0;
80 | switch (rotation) {
81 | case Surface.ROTATION_0:
82 | degrees = 0;
83 | break;
84 | case Surface.ROTATION_90:
85 | degrees = 90;
86 | break;
87 | case Surface.ROTATION_180:
88 | degrees = 180;
89 | break;
90 | case Surface.ROTATION_270:
91 | degrees = 270;
92 | break;
93 | }
94 | int result;
95 | if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
96 | result = (info.orientation + degrees) % 360;
97 | result = (360 - result) % 360; // compensate the mirror
98 | } else { // back-facing
99 | result = (info.orientation - degrees + 360) % 360;
100 | }
101 | camera.setDisplayOrientation(result);
102 | }
103 |
104 | public void setPreviewTexture(SurfaceTexture surfaceTexture) {
105 | if (mCamera != null) {
106 | try {
107 | mCamera.setPreviewTexture(surfaceTexture);
108 | } catch (IOException e) {
109 | e.printStackTrace();
110 | }
111 | }
112 | }
113 |
114 | /**
115 | * 关闭相机释放资源
116 | */
117 | @Override
118 | public void closeCamera() {
119 | if (mCamera != null) {
120 | mCamera.release();
121 | mCamera = null;
122 | }
123 | mActivity = null;
124 | }
125 |
126 | }
127 |
--------------------------------------------------------------------------------
/sample-camera/src/main/java/com/onzhou/opengles/camera/CameraV1Pick.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.camera;
2 |
3 | import android.app.Activity;
4 | import android.graphics.SurfaceTexture;
5 | import android.hardware.Camera;
6 | import android.util.Log;
7 | import android.view.TextureView;
8 |
9 | import com.onzhou.opengles.api.ICamera;
10 | import com.onzhou.opengles.utils.TextureUtils;
11 |
12 | /**
13 | * @anchor: andy
14 | * @date: 18-11-11
15 | */
16 |
17 | public class CameraV1Pick implements TextureView.SurfaceTextureListener {
18 |
19 | private static final String TAG = "CameraV1Pick";
20 |
21 | private TextureView mTextureView;
22 |
23 | private int mCameraId;
24 |
25 | private ICamera mCamera;
26 |
27 | private TextureEGLHelper mTextureEglHelper;
28 |
29 | public void bindTextureView(TextureView textureView) {
30 | this.mTextureView = textureView;
31 | mTextureEglHelper = new TextureEGLHelper();
32 | mTextureView.setSurfaceTextureListener(this);
33 | }
34 |
35 | @Override
36 | public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
37 | //加载OES纹理ID
38 | final int textureId = TextureUtils.loadOESTexture();
39 | //初始化操作
40 | mTextureEglHelper.initEgl(mTextureView, textureId);
41 | //自定义的SurfaceTexture
42 | SurfaceTexture surfaceTexture = mTextureEglHelper.loadOESTexture();
43 | //前置摄像头
44 | mCameraId = Camera.CameraInfo.CAMERA_FACING_FRONT;
45 | mCamera = new CameraV1((Activity) mTextureView.getContext());
46 | if (mCamera.openCamera(mCameraId)) {
47 | mCamera.setPreviewTexture(surfaceTexture);
48 | mCamera.enablePreview(true);
49 | } else {
50 | Log.e(TAG, "openCamera failed");
51 | }
52 | }
53 |
54 | @Override
55 | public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
56 | mTextureEglHelper.onSurfaceChanged(width, height);
57 | }
58 |
59 | @Override
60 | public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
61 | if (mCamera != null) {
62 | mCamera.enablePreview(false);
63 | mCamera.closeCamera();
64 | mCamera = null;
65 | }
66 | return true;
67 | }
68 |
69 | @Override
70 | public void onSurfaceTextureUpdated(SurfaceTexture surface) {
71 |
72 | }
73 |
74 | public void onDestroy() {
75 | if (mTextureEglHelper != null) {
76 | mTextureEglHelper.onDestroy();
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/sample-camera/src/main/java/com/onzhou/opengles/main/CameraSurfaceActivity.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.main;
2 |
3 | import android.Manifest;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.content.pm.PackageManager;
7 | import android.opengl.GLSurfaceView;
8 | import android.os.Bundle;
9 |
10 | import androidx.core.app.ActivityCompat;
11 |
12 | import com.onzhou.opengles.base.AbsBaseActivity;
13 | import com.onzhou.opengles.renderer.CameraSurfaceRenderer;
14 |
15 | /**
16 | * @anchor: andy
17 | * @date: 18-11-10
18 | */
19 | public class CameraSurfaceActivity extends AbsBaseActivity {
20 |
21 | private static final int PERMISSION_CODE = 100;
22 |
23 | private GLSurfaceView mGLSurfaceView;
24 |
25 | public static void intentStart(Context context) {
26 | Intent intent = new Intent(context, CameraSurfaceActivity.class);
27 | context.startActivity(intent);
28 | }
29 |
30 | @Override
31 | protected void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | applyPermission();
34 | }
35 |
36 | private void applyPermission() {
37 | if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
38 | ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, PERMISSION_CODE);
39 | } else {
40 | setupView();
41 | }
42 | }
43 |
44 | @Override
45 | public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
46 | super.onRequestPermissionsResult(requestCode, permissions, grantResults);
47 | if (requestCode == PERMISSION_CODE && grantResults != null && grantResults.length > 0) {
48 | if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
49 | setupView();
50 | }
51 | }
52 | }
53 |
54 | private void setupView() {
55 | //实例化一个GLSurfaceView
56 | mGLSurfaceView = new GLSurfaceView(this);
57 | mGLSurfaceView.setEGLContextClientVersion(3);
58 | mGLSurfaceView.setRenderer(new CameraSurfaceRenderer(mGLSurfaceView));
59 | setContentView(mGLSurfaceView);
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/sample-camera/src/main/java/com/onzhou/opengles/main/CameraTextureActivity.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.main;
2 |
3 | import android.Manifest;
4 | import android.app.Activity;
5 | import android.content.pm.PackageManager;
6 | import android.os.Bundle;
7 | import android.view.TextureView;
8 |
9 | import androidx.core.app.ActivityCompat;
10 |
11 | import com.onzhou.opengles.camera.CameraV1Pick;
12 |
13 | /**
14 | * @anchor: andy
15 | * @date: 18-11-10
16 | */
17 | public class CameraTextureActivity extends Activity {
18 |
19 | private static final int PERMISSION_CODE = 1000;
20 |
21 | private TextureView mTextureView;
22 |
23 | private CameraV1Pick mCameraPick;
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | applyPermission();
29 | }
30 |
31 | private void applyPermission() {
32 | if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
33 | ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, PERMISSION_CODE);
34 | } else {
35 | setupView();
36 | }
37 | }
38 |
39 | @Override
40 | public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
41 | super.onRequestPermissionsResult(requestCode, permissions, grantResults);
42 | if (requestCode == PERMISSION_CODE && grantResults != null && grantResults.length > 0) {
43 | if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
44 | setupView();
45 | }
46 | }
47 | }
48 |
49 | private void setupView() {
50 | mTextureView = new TextureView(this);
51 | setContentView(mTextureView);
52 |
53 | mCameraPick = new CameraV1Pick();
54 | mCameraPick.bindTextureView(mTextureView);
55 | }
56 |
57 | @Override
58 | protected void onDestroy() {
59 | super.onDestroy();
60 | if (mCameraPick != null) {
61 | mCameraPick.onDestroy();
62 | mCameraPick = null;
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/sample-camera/src/main/java/com/onzhou/opengles/renderer/CameraTextureRenderer.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.renderer;
2 |
3 |
4 | import android.graphics.SurfaceTexture;
5 | import android.opengl.GLES11Ext;
6 | import android.opengl.GLES20;
7 | import android.opengl.GLES30;
8 |
9 | import com.onzhou.opengles.api.ITextureRenderer;
10 | import com.onzhou.opengles.camera.R;
11 | import com.onzhou.opengles.utils.ResReadUtils;
12 | import com.onzhou.opengles.utils.ShaderUtils;
13 |
14 | import java.nio.ByteBuffer;
15 | import java.nio.ByteOrder;
16 | import java.nio.FloatBuffer;
17 |
18 | /**
19 | * @anchor: andy
20 | * @date: 2018-11-11
21 | * @description: 基于相机
22 | */
23 | public class CameraTextureRenderer implements ITextureRenderer {
24 |
25 | private FloatBuffer mVertexBuffer;
26 |
27 | /**
28 | * OES纹理ID
29 | */
30 | private int mOESTextureId = -1;
31 |
32 | /**
33 | * 程序
34 | */
35 | private int mShaderProgram = -1;
36 |
37 | private int aPositionLocation = -1;
38 | private int aTextureCoordLocation = -1;
39 | private int uTextureMatrixLocation = -1;
40 | private int uTextureSamplerLocation = -1;
41 |
42 | public static final String POSITION_ATTRIBUTE = "aPosition";
43 | public static final String TEXTURE_COORD_ATTRIBUTE = "aTextureCoord";
44 | public static final String TEXTURE_MATRIX_UNIFORM = "uTextureMatrix";
45 | public static final String TEXTURE_SAMPLER_UNIFORM = "uTextureSampler";
46 |
47 | private static final int POSITION_SIZE = 2;
48 |
49 | private static final int TEXTURE_SIZE = 2;
50 |
51 | private static final int STRIDE = (POSITION_SIZE + TEXTURE_SIZE) * 4;
52 |
53 | /**
54 | * 前两个为顶点坐标
55 | * 后两个为纹理坐标
56 | */
57 | private static final float[] VERTEX_DATA = {
58 | 1.0f, 1.0f, 1.0f, 1.0f,
59 | -1.0f, 1.0f, 0.0f, 1.0f,
60 | -1.0f, -1f, 0.0f, 0.0f,
61 | 1.0f, 1.0f, 1.0f, 1.0f,
62 | -1.0f, -1.0f, 0f, 0.0f,
63 | 1.0f, -1.0f, 1.0f, 0.0f
64 | };
65 |
66 | /**
67 | * 变换矩阵
68 | */
69 | private float[] transformMatrix = new float[16];
70 |
71 | public CameraTextureRenderer(int OESTextureId) {
72 | mOESTextureId = OESTextureId;
73 | mVertexBuffer = loadVertexBuffer(VERTEX_DATA);
74 | }
75 |
76 | public FloatBuffer loadVertexBuffer(float[] vertexData) {
77 | FloatBuffer buffer = ByteBuffer.allocateDirect(vertexData.length * 4)
78 | .order(ByteOrder.nativeOrder())
79 | .asFloatBuffer();
80 | buffer.put(vertexData, 0, vertexData.length).position(0);
81 | return buffer;
82 | }
83 |
84 | @Override
85 | public void onSurfaceCreated() {
86 | final int vertexShader = ShaderUtils.compileVertexShader(ResReadUtils.readResource(R.raw.vertex_texture_shader));
87 | final int fragmentShader = ShaderUtils.compileFragmentShader(ResReadUtils.readResource(R.raw.fragment_texture_shader));
88 | mShaderProgram = ShaderUtils.linkProgram(vertexShader, fragmentShader);
89 |
90 | aPositionLocation = GLES30.glGetAttribLocation(mShaderProgram, CameraTextureRenderer.POSITION_ATTRIBUTE);
91 | aTextureCoordLocation = GLES30.glGetAttribLocation(mShaderProgram, CameraTextureRenderer.TEXTURE_COORD_ATTRIBUTE);
92 | uTextureMatrixLocation = GLES30.glGetUniformLocation(mShaderProgram, CameraTextureRenderer.TEXTURE_MATRIX_UNIFORM);
93 | uTextureSamplerLocation = GLES30.glGetUniformLocation(mShaderProgram, CameraTextureRenderer.TEXTURE_SAMPLER_UNIFORM);
94 | }
95 |
96 | @Override
97 | public void onSurfaceChanged(int width, int height) {
98 | GLES30.glViewport(0, 0, width, height);
99 | }
100 |
101 | @Override
102 | public void onDrawFrame(SurfaceTexture surfaceTexture) {
103 | GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
104 |
105 | //开始使用程序
106 | GLES30.glUseProgram(mShaderProgram);
107 |
108 | surfaceTexture.updateTexImage();
109 | surfaceTexture.getTransformMatrix(transformMatrix);
110 |
111 | GLES30.glActiveTexture(GLES30.GL_TEXTURE0);
112 | GLES30.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mOESTextureId);
113 | GLES30.glUniform1i(uTextureSamplerLocation, 0);
114 | GLES30.glUniformMatrix4fv(uTextureMatrixLocation, 1, false, transformMatrix, 0);
115 |
116 | mVertexBuffer.position(0);
117 | GLES30.glEnableVertexAttribArray(aPositionLocation);
118 | GLES30.glVertexAttribPointer(aPositionLocation, 2, GLES30.GL_FLOAT, false, STRIDE, mVertexBuffer);
119 |
120 | mVertexBuffer.position(2);
121 | GLES30.glEnableVertexAttribArray(aTextureCoordLocation);
122 | GLES30.glVertexAttribPointer(aTextureCoordLocation, 2, GLES30.GL_FLOAT, false, STRIDE, mVertexBuffer);
123 |
124 | GLES30.glDrawArrays(GLES30.GL_TRIANGLES, 0, 6);
125 |
126 | }
127 | }
128 |
129 |
--------------------------------------------------------------------------------
/sample-camera/src/main/release/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
10 |
11 |
18 |
19 |
22 |
23 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/sample-camera/src/main/res/raw/fragment_camera_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | //OpenGL ES3.0外部纹理扩展
3 | #extension GL_OES_EGL_image_external_essl3 : require
4 | precision mediump float;
5 | uniform samplerExternalOES yuvTexSampler;
6 | in vec2 yuvTexCoords;
7 | out vec4 vFragColor;
8 | void main() {
9 | vec4 vCameraColor = texture(yuvTexSampler,yuvTexCoords);
10 | float fGrayColor = (0.3*vCameraColor.r + 0.59*vCameraColor.g + 0.11*vCameraColor.b);
11 | vFragColor = vec4(fGrayColor, fGrayColor, fGrayColor, 1.0);
12 | }
--------------------------------------------------------------------------------
/sample-camera/src/main/res/raw/fragment_texture_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | #extension GL_OES_EGL_image_external_essl3 : require
3 | precision mediump float;
4 | uniform samplerExternalOES uTextureSampler;
5 | in vec2 vTextureCoord;
6 | out vec4 vFragColor;
7 | void main()
8 | {
9 | vFragColor = texture(uTextureSampler, vTextureCoord);
10 | }
11 |
--------------------------------------------------------------------------------
/sample-camera/src/main/res/raw/vertex_camera_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | layout (location = 0) in vec4 vPosition;
3 | layout (location = 1) in vec4 aTextureCoord;
4 | uniform mat4 uTextureMatrix;
5 | out vec2 yuvTexCoords;
6 | void main() {
7 | gl_Position = vPosition;
8 | yuvTexCoords = (uTextureMatrix * aTextureCoord).xy;
9 | }
--------------------------------------------------------------------------------
/sample-camera/src/main/res/raw/vertex_texture_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 |
3 | layout (location = 0) in vec4 aPosition;
4 | layout (location = 1) in vec4 aTextureCoord;
5 |
6 | uniform mat4 uTextureMatrix;
7 | out vec2 vTextureCoord;
8 |
9 | void main() {
10 | gl_Position = aPosition;
11 | vTextureCoord = (uTextureMatrix * aTextureCoord).xy;
12 | }
--------------------------------------------------------------------------------
/sample-camera/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | opengles-camera
3 |
4 |
--------------------------------------------------------------------------------
/sample-camera/src/test/java/com/onzhou/opengles/camera/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.camera;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/sample-color/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sample-color/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | cmake_minimum_required(VERSION 3.4.1)
3 |
4 | ##官方标准配置
5 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
6 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-rtti -fno-exceptions -Wall")
7 |
8 | ##ANDROID_PLATFORM_LEVEL=18
9 | add_definitions("-DDYNAMIC_ES3")
10 | set(OPENGL_LIB GLESv3)
11 |
12 | add_library(native-color
13 | SHARED
14 | src/main/cpp/native_color.cpp)
15 |
16 | target_link_libraries(native-color
17 | ${OPENGL_LIB}
18 | android
19 | EGL
20 | log
21 | m)
22 |
--------------------------------------------------------------------------------
/sample-color/build.gradle:
--------------------------------------------------------------------------------
1 | apply from: "$rootDir/module.gradle"
2 |
3 | android {
4 | defaultConfig {
5 | externalNativeBuild {
6 | cmake {
7 | cppFlags ""
8 | arguments '-DANDROID_STL=c++_static'
9 | }
10 | ndk {
11 | abiFilters "armeabi-v7a","arm64-v8a"
12 | }
13 | }
14 | }
15 | externalNativeBuild {
16 | cmake {
17 | path "CMakeLists.txt"
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/sample-color/gradle.properties:
--------------------------------------------------------------------------------
1 |
2 |
3 | library=true
--------------------------------------------------------------------------------
/sample-color/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/sample-color/src/main/cpp/native_color.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 | #include
5 |
6 | #include "native_color.h"
7 |
8 | /**
9 | * 动态注册
10 | */
11 | JNINativeMethod methods[] = {
12 | {"surfaceCreated", "(I)V", (void *) surfaceCreated},
13 | {"surfaceChanged", "(II)V", (void *) surfaceChanged},
14 | {"onDrawFrame", "()V", (void *) onDrawFrame}
15 | };
16 |
17 | /**
18 | * 动态注册
19 | * @param env
20 | * @return
21 | */
22 | jint registerNativeMethod(JNIEnv *env) {
23 | jclass cl = env->FindClass("com/onzhou/opengles/color/NativeColorRenderer");
24 | if ((env->RegisterNatives(cl, methods, sizeof(methods) / sizeof(methods[0]))) < 0) {
25 | return -1;
26 | }
27 | return 0;
28 | }
29 |
30 | /**
31 | * 加载默认回调
32 | * @param vm
33 | * @param reserved
34 | * @return
35 | */
36 | jint JNI_OnLoad(JavaVM *vm, void *reserved) {
37 | JNIEnv *env = NULL;
38 | if (vm->GetEnv((void **) &env, JNI_VERSION_1_6) != JNI_OK) {
39 | return -1;
40 | }
41 | //注册方法
42 | if (registerNativeMethod(env) != JNI_OK) {
43 | return -1;
44 | }
45 | return JNI_VERSION_1_6;
46 | }
47 |
48 | JNIEXPORT void JNICALL surfaceCreated(JNIEnv *env, jobject obj, jint color) {
49 | GLfloat redF = ((color >> 16) & 0xFF) * 1.0f / 255;
50 | GLfloat greenF = ((color >> 8) & 0xFF) * 1.0f / 255;
51 | GLfloat blueF = (color & 0xFF) * 1.0f / 255;
52 | GLfloat alphaF = ((color >> 24) & 0xFF) * 1.0f / 255;
53 | glClearColor(redF, greenF, blueF, alphaF);
54 | }
55 |
56 | JNIEXPORT void JNICALL surfaceChanged(JNIEnv *env, jobject obj, jint width, jint height) {
57 | glViewport(0, 0, width, height);
58 | }
59 |
60 | JNIEXPORT void JNICALL onDrawFrame(JNIEnv *env, jobject obj) {
61 | //把颜色缓冲区设置为我们预设的颜色
62 | glClear(GL_COLOR_BUFFER_BIT);
63 | }
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/sample-color/src/main/cpp/native_color.h:
--------------------------------------------------------------------------------
1 | /* DO NOT EDIT THIS FILE - it is machine generated */
2 | #include
3 | /* Header for class com_onzhou_opengles_color_NativeColorRenderer */
4 |
5 | #ifndef COM_ONZHOU_OPENGLES_COLOR_NATIVECOLORRENDERER
6 | #define COM_ONZHOU_OPENGLES_COLOR_NATIVECOLORRENDERER
7 | #ifdef __cplusplus
8 | extern "C" {
9 | #endif
10 |
11 | JNIEXPORT void JNICALL surfaceCreated(JNIEnv *, jobject, jint);
12 |
13 | JNIEXPORT void JNICALL surfaceChanged(JNIEnv *, jobject, jint, jint);
14 |
15 | JNIEXPORT void JNICALL onDrawFrame(JNIEnv *, jobject);
16 |
17 | #ifdef __cplusplus
18 | }
19 | #endif
20 | #endif
21 |
--------------------------------------------------------------------------------
/sample-color/src/main/debug/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/sample-color/src/main/java/com/onzhou/opengles/color/ColorRenderer.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.color;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.opengl.GLES30;
6 | import android.opengl.GLSurfaceView;
7 |
8 | import com.onzhou.opengles.utils.ResReadUtils;
9 | import com.onzhou.opengles.utils.ShaderUtils;
10 |
11 | import java.nio.ByteBuffer;
12 | import java.nio.ByteOrder;
13 | import java.nio.FloatBuffer;
14 |
15 | import javax.microedition.khronos.egl.EGLConfig;
16 | import javax.microedition.khronos.opengles.GL10;
17 |
18 | /**
19 | * @anchor: andy
20 | * @date: 2018-11-02
21 | * @description:
22 | */
23 | public class ColorRenderer implements GLSurfaceView.Renderer {
24 |
25 | private int color;
26 |
27 | public ColorRenderer(int color) {
28 | this.color = color;
29 | }
30 |
31 | @Override
32 | public void onSurfaceCreated(GL10 gl, EGLConfig config) {
33 | //设置背景颜色
34 | float redF = (float) Color.red(color) / 255;
35 | float greenF = (float) Color.green(color) / 255;
36 | float blueF = (float) Color.blue(color) / 255;
37 | float alphaF = (float) Color.alpha(color) / 255;
38 | GLES30.glClearColor(redF, greenF, blueF, alphaF);
39 | }
40 |
41 | @Override
42 | public void onSurfaceChanged(GL10 gl, int width, int height) {
43 | //设置视图窗口
44 | GLES30.glViewport(0, 0, width, height);
45 | }
46 |
47 | @Override
48 | public void onDrawFrame(GL10 gl) {
49 | //把颜色缓冲区设置为我们预设的颜色
50 | GLES30.glClear(GL10.GL_COLOR_BUFFER_BIT);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/sample-color/src/main/java/com/onzhou/opengles/color/NativeColorRenderer.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.color;
2 |
3 | import android.graphics.Color;
4 | import android.opengl.GLSurfaceView;
5 |
6 | import javax.microedition.khronos.egl.EGLConfig;
7 | import javax.microedition.khronos.opengles.GL10;
8 |
9 | /**
10 | * @anchor: andy
11 | * @date: 2018-11-02
12 | * @description: 自定义三角形渲染器
13 | */
14 | public class NativeColorRenderer implements GLSurfaceView.Renderer {
15 |
16 | static {
17 | System.loadLibrary("native-color");
18 | }
19 |
20 | public native void surfaceCreated(int color);
21 |
22 | public native void surfaceChanged(int width, int height);
23 |
24 | public native void onDrawFrame();
25 |
26 | private int color;
27 |
28 | public NativeColorRenderer(int color) {
29 | this.color = color;
30 | }
31 |
32 | @Override
33 | public void onSurfaceCreated(GL10 gl, EGLConfig config) {
34 | surfaceCreated(color);
35 | }
36 |
37 | @Override
38 | public void onSurfaceChanged(GL10 gl, int width, int height) {
39 | surfaceChanged(width, height);
40 | }
41 |
42 | @Override
43 | public void onDrawFrame(GL10 gl) {
44 | onDrawFrame();
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/sample-color/src/main/java/com/onzhou/opengles/main/ColorActivity.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.main;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.graphics.Color;
6 | import android.opengl.GLSurfaceView;
7 |
8 | import com.onzhou.opengles.base.AbsGLSurfaceActivity;
9 | import com.onzhou.opengles.color.NativeColorRenderer;
10 |
11 | /**
12 | * @anchor: andy
13 | * @date: 2018-11-02
14 | * @description:
15 | */
16 | public class ColorActivity extends AbsGLSurfaceActivity {
17 |
18 | public static void intentStart(Context context) {
19 | Intent intent = new Intent(context, ColorActivity.class);
20 | context.startActivity(intent);
21 | }
22 |
23 | @Override
24 | protected GLSurfaceView.Renderer bindRenderer() {
25 | return new NativeColorRenderer(Color.GRAY);
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/sample-color/src/main/release/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
7 |
8 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/sample-color/src/main/res/raw/triangle_fragment_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | precision mediump float;
3 | out vec4 fragColor;
4 | void main() {
5 | fragColor = vec4(1.0,1.0,1.0,1.0);
6 | }
--------------------------------------------------------------------------------
/sample-color/src/main/res/raw/triangle_vertex_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | layout (location = 0) in vec4 vPosition;
3 | void main() {
4 | gl_Position = vPosition;
5 | gl_PointSize = 10.0;
6 | };
--------------------------------------------------------------------------------
/sample-color/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | opengles-color
3 |
4 |
--------------------------------------------------------------------------------
/sample-color/src/test/java/com/onzhou/opengles/shader/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.shader;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/sample-filter/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sample-filter/build.gradle:
--------------------------------------------------------------------------------
1 | apply from: "$rootDir/module.gradle"
--------------------------------------------------------------------------------
/sample-filter/gradle.properties:
--------------------------------------------------------------------------------
1 | library=true
--------------------------------------------------------------------------------
/sample-filter/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/sample-filter/src/main/debug/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
7 |
8 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/sample-filter/src/main/java/com/onzhou/opengles/filter/GrayFilter.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.filter;
2 |
3 | import android.opengl.GLES30;
4 |
5 | import com.onzhou.opengles.utils.ResReadUtils;
6 |
7 | /**
8 | * @anchor: andy
9 | * @date: 2019-03-27
10 | * @description:
11 | */
12 | public class GrayFilter extends BaseFilter {
13 |
14 | private int aFilterLocation;
15 |
16 | private float[] filterValue = new float[]{0.299f, 0.587f, 0.114f};
17 |
18 | public GrayFilter() {
19 | super(ResReadUtils.readResource(R.raw.gray_filter_vertex_shader), ResReadUtils.readResource(R.raw.gray_filter_fragment_shader));
20 | }
21 |
22 | @Override
23 | public void setupProgram() {
24 | super.setupProgram();
25 | aFilterLocation = GLES30.glGetUniformLocation(mProgram, "a_Filter");
26 | }
27 |
28 | @Override
29 | public void onUpdateDrawFrame() {
30 | //更新参数
31 | GLES30.glUniform3fv(aFilterLocation, 1, filterValue, 0);
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/sample-filter/src/main/java/com/onzhou/opengles/filter/OriginFilter.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.filter;
2 |
3 | /**
4 | * @anchor: andy
5 | * @date: 2019-03-27
6 | * @description:
7 | */
8 | public class OriginFilter extends BaseFilter {
9 |
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/sample-filter/src/main/java/com/onzhou/opengles/filter/QuarterMirrorFilter.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.filter;
2 |
3 | import android.opengl.GLES30;
4 |
5 | import com.onzhou.opengles.utils.ResReadUtils;
6 |
7 | /**
8 | * @anchor: andy
9 | * @date: 2019-03-27
10 | * @description:
11 | */
12 | public class QuarterMirrorFilter extends BaseFilter {
13 |
14 | public QuarterMirrorFilter() {
15 | super(ResReadUtils.readResource(R.raw.quarter_mirror_filter_vertex_shader), ResReadUtils.readResource(R.raw.quarter_mirror_filter_fragment_shader));
16 | }
17 |
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/sample-filter/src/main/java/com/onzhou/opengles/filter/RendererFilter.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.filter;
2 |
3 |
4 | /**
5 | * @anchor: andy
6 | * @date: 2019-03-27
7 | * @description:
8 | */
9 | public interface RendererFilter {
10 |
11 | /**
12 | * 创建回调
13 | */
14 | void onSurfaceCreated();
15 |
16 | /**
17 | * 宽高改变回调
18 | *
19 | * @param width
20 | * @param height
21 | */
22 | void onSurfaceChanged(int width, int height);
23 |
24 | /**
25 | * 绘制回调
26 | */
27 | void onDrawFrame();
28 |
29 | /**
30 | * 销毁回调
31 | */
32 | void onDestroy();
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/sample-filter/src/main/java/com/onzhou/opengles/main/FilterActivity.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.main;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.view.Menu;
7 | import android.view.MenuItem;
8 | import android.view.ViewGroup;
9 |
10 | import com.onzhou.opengles.base.AbsBaseActivity;
11 | import com.onzhou.opengles.filter.GrayFilter;
12 | import com.onzhou.opengles.filter.OriginFilter;
13 | import com.onzhou.opengles.filter.QuarterMirrorFilter;
14 | import com.onzhou.opengles.view.OpenGLView;
15 | import com.onzhou.opengles.filter.R;
16 |
17 | /**
18 | * @anchor: andy
19 | * @date: 2019-03-15
20 | * @description:
21 | */
22 | public class FilterActivity extends AbsBaseActivity {
23 |
24 | private ViewGroup mRootLayer;
25 |
26 | private OpenGLView mGlView;
27 |
28 | public static void intentStart(Context context) {
29 | Intent intent = new Intent(context, FilterActivity.class);
30 | context.startActivity(intent);
31 | }
32 |
33 | @Override
34 | protected void onCreate(Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 | setContentView(R.layout.activity_filter);
37 | setupViews();
38 | }
39 |
40 | private void setupViews() {
41 | mRootLayer = (ViewGroup) findViewById(R.id.linear_root_layer);
42 |
43 | mGlView = new OpenGLView(this);
44 | mRootLayer.addView(mGlView, 0);
45 | }
46 |
47 | @Override
48 | public boolean onCreateOptionsMenu(Menu menu) {
49 | getMenuInflater().inflate(R.menu.menu_filter, menu);
50 | return super.onCreateOptionsMenu(menu);
51 | }
52 |
53 | @Override
54 | public boolean onOptionsItemSelected(MenuItem item) {
55 | int itemId = item.getItemId();
56 | if (itemId == R.id.filter_default) {
57 | mGlView.setFilter(new OriginFilter());
58 | } else if (itemId == R.id.filter_gray) {
59 | mGlView.setFilter(new GrayFilter());
60 | } else if (itemId == R.id.filter_quarter_mirror) {
61 | mGlView.setFilter(new QuarterMirrorFilter());
62 | }
63 | return super.onOptionsItemSelected(item);
64 | }
65 | }
--------------------------------------------------------------------------------
/sample-filter/src/main/java/com/onzhou/opengles/renderer/FilterRenderer.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.renderer;
2 |
3 | import android.opengl.GLSurfaceView;
4 |
5 | import com.onzhou.opengles.filter.BaseFilter;
6 | import com.onzhou.opengles.filter.OriginFilter;
7 |
8 | import javax.microedition.khronos.egl.EGLConfig;
9 | import javax.microedition.khronos.opengles.GL10;
10 |
11 | /**
12 | * @anchor: andy
13 | * @date: 2018-11-09
14 | * @description:
15 | */
16 | public class FilterRenderer implements GLSurfaceView.Renderer {
17 |
18 | private static final String TAG = "FilterRenderer";
19 |
20 | private int mSurfaceWidth, mSurfaceHeight;
21 |
22 | private BaseFilter mTargetFilter = new OriginFilter();
23 |
24 | @Override
25 | public void onSurfaceCreated(GL10 gl, EGLConfig config) {
26 | mTargetFilter.onSurfaceCreated();
27 | }
28 |
29 | @Override
30 | public void onSurfaceChanged(GL10 gl, int width, int height) {
31 | mSurfaceWidth = width;
32 | mSurfaceHeight = height;
33 | mTargetFilter.onSurfaceChanged(width, height);
34 | }
35 |
36 | @Override
37 | public void onDrawFrame(GL10 gl) {
38 | mTargetFilter.onDrawFrame();
39 | }
40 |
41 | public void setFilter(BaseFilter baseFilter) {
42 | if (mTargetFilter != null) {
43 | mTargetFilter.onDestroy();
44 | }
45 | mTargetFilter = baseFilter;
46 | if (mTargetFilter != null) {
47 | mTargetFilter.onSurfaceCreated();
48 | mTargetFilter.onSurfaceChanged(mSurfaceWidth, mSurfaceHeight);
49 | }
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/sample-filter/src/main/java/com/onzhou/opengles/view/OpenGLView.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.view;
2 |
3 | import android.content.Context;
4 | import android.opengl.GLSurfaceView;
5 | import android.util.AttributeSet;
6 |
7 | import com.onzhou.opengles.filter.BaseFilter;
8 | import com.onzhou.opengles.renderer.FilterRenderer;
9 |
10 | /**
11 | * @anchor: andy
12 | * @date: 2019-03-27
13 | * @description:
14 | */
15 | public class OpenGLView extends GLSurfaceView {
16 |
17 | private FilterRenderer mGLRender;
18 |
19 | public OpenGLView(Context context) {
20 | this(context, null);
21 | }
22 |
23 | public OpenGLView(Context context, AttributeSet attrs) {
24 | super(context, attrs);
25 | setupSurfaceView();
26 | }
27 |
28 | private void setupSurfaceView() {
29 | //设置版本
30 | setEGLContextClientVersion(3);
31 | mGLRender = new FilterRenderer();
32 | setRenderer(mGLRender);
33 |
34 | try {
35 | requestRender();
36 | } catch (Exception e) {
37 | e.printStackTrace();
38 | }
39 | }
40 |
41 | /**
42 | * 设置滤镜
43 | * 滤镜由于可能存在多种类型
44 | * 这里抽象了一个基础的滤镜类
45 | * queueEvent
46 | *
47 | * @param baseFilter
48 | */
49 | public void setFilter(final BaseFilter baseFilter) {
50 | queueEvent(new Runnable() {
51 | @Override
52 | public void run() {
53 | if (mGLRender != null) {
54 | mGLRender.setFilter(baseFilter);
55 | }
56 | }
57 | });
58 | try {
59 | requestRender();
60 | } catch (Exception e) {
61 | e.printStackTrace();
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/sample-filter/src/main/release/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
8 |
9 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/sample-filter/src/main/res/layout/activity_filter.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/sample-filter/src/main/res/menu/menu_filter.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/sample-filter/src/main/res/raw/gray_filter_fragment_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | precision mediump float;
3 | uniform sampler2D uTextureUnit;
4 |
5 | //传入滤镜数据
6 | in vec3 vFilter;
7 | in vec2 vTexCoord;
8 |
9 | //输出
10 | out vec4 vFragColor;
11 | void main() {
12 | vec4 vTextureColor = texture(uTextureUnit,vTexCoord);
13 | //黑白滤镜
14 | float vFilterColor = (vFilter.x * vTextureColor.r + vFilter.y * vTextureColor.g + vFilter.z * vTextureColor.b);
15 | vFragColor = vec4(vFilterColor, vFilterColor, vFilterColor, 1.0);
16 | }
--------------------------------------------------------------------------------
/sample-filter/src/main/res/raw/gray_filter_vertex_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | layout (location = 0) in vec4 vPosition;
3 | layout (location = 1) in vec2 aTextureCoord;
4 |
5 | uniform mat4 u_Matrix;
6 | uniform vec3 a_Filter;
7 |
8 | out vec3 vFilter;
9 | out vec2 vTexCoord;
10 | void main() {
11 | gl_Position = u_Matrix * vPosition;
12 | vTexCoord = aTextureCoord;
13 |
14 | vFilter = a_Filter;
15 | }
--------------------------------------------------------------------------------
/sample-filter/src/main/res/raw/no_filter_fragment_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | precision mediump float;
3 | uniform sampler2D uTextureUnit;
4 | in vec2 vTexCoord;
5 |
6 | //输出
7 | out vec4 vFragColor;
8 | void main() {
9 | vFragColor = texture(uTextureUnit,vTexCoord);
10 | }
--------------------------------------------------------------------------------
/sample-filter/src/main/res/raw/no_filter_vertex_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | layout (location = 0) in vec4 vPosition;
3 | layout (location = 1) in vec2 aTextureCoord;
4 |
5 | uniform mat4 u_Matrix;
6 |
7 | out vec2 vTexCoord;
8 | void main() {
9 | gl_Position = u_Matrix * vPosition;
10 | vTexCoord = aTextureCoord;
11 | }
--------------------------------------------------------------------------------
/sample-filter/src/main/res/raw/quarter_mirror_filter_fragment_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | precision mediump float;
3 | uniform sampler2D uTextureUnit;
4 | in vec2 vTexCoord;
5 |
6 | //输出
7 | out vec4 vFragColor;
8 | void main() {
9 | vec2 uv = vTexCoord;
10 | if (uv.x <= 0.5) {
11 | uv.x = uv.x * 2.0;
12 | } else {
13 | uv.x = (uv.x - 0.5) * 2.0;
14 | }
15 | if (uv.y <= 0.5) {
16 | uv.y = uv.y * 2.0;
17 | } else {
18 | uv.y = (uv.y - 0.5) * 2.0;
19 | }
20 | vFragColor = texture(uTextureUnit,fract(uv));
21 | }
--------------------------------------------------------------------------------
/sample-filter/src/main/res/raw/quarter_mirror_filter_vertex_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | layout (location = 0) in vec4 vPosition;
3 | layout (location = 1) in vec2 aTextureCoord;
4 |
5 | uniform mat4 u_Matrix;
6 |
7 | out vec2 vTexCoord;
8 | void main() {
9 | gl_Position = u_Matrix * vPosition;
10 | vTexCoord = aTextureCoord;
11 | }
--------------------------------------------------------------------------------
/sample-filter/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 滤镜组件
3 |
4 |
--------------------------------------------------------------------------------
/sample-filter/src/test/java/com/onzhou/opengles/filter/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.filter;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/sample-native/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sample-native/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | cmake_minimum_required(VERSION 3.4.1)
3 |
4 | ##官方标准配置
5 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
6 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-rtti -fno-exceptions -Wall")
7 |
8 | add_library(native-window
9 | SHARED
10 | src/main/cpp/native_window.cpp)
11 |
12 | target_link_libraries(native-window
13 | ${OPENGL_LIB}
14 | android
15 | jnigraphics
16 | log)
17 |
--------------------------------------------------------------------------------
/sample-native/build.gradle:
--------------------------------------------------------------------------------
1 | apply from: "$rootDir/module.gradle"
2 |
3 | android {
4 | defaultConfig {
5 | externalNativeBuild {
6 | cmake {
7 | cppFlags ""
8 | arguments '-DANDROID_STL=c++_static'
9 | }
10 | ndk {
11 | abiFilters "armeabi-v7a","arm64-v8a"
12 | }
13 | }
14 | }
15 | externalNativeBuild {
16 | cmake {
17 | path "CMakeLists.txt"
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/sample-native/gradle.properties:
--------------------------------------------------------------------------------
1 |
2 |
3 | library=true
--------------------------------------------------------------------------------
/sample-native/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/sample-native/src/main/cpp/native_window.h:
--------------------------------------------------------------------------------
1 | /* DO NOT EDIT THIS FILE - it is machine generated */
2 | #include
3 | /* Header for class com_onzhou_opengles_color_NativeColorRenderer */
4 |
5 | #ifndef COM_ONZHOU_OPENGLES_COLOR_NATIVECOLORRENDERER
6 | #define COM_ONZHOU_OPENGLES_COLOR_NATIVECOLORRENDERER
7 | #ifdef __cplusplus
8 | extern "C" {
9 | #endif
10 |
11 | JNIEXPORT void JNICALL drawColor(JNIEnv *, jobject, jobject, jint);
12 |
13 | JNIEXPORT void JNICALL drawBitmap(JNIEnv *, jobject, jobject, jobject);
14 |
15 | #ifdef __cplusplus
16 | }
17 | #endif
18 | #endif
19 |
--------------------------------------------------------------------------------
/sample-native/src/main/debug/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
7 |
8 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/sample-native/src/main/java/com/onzhou/opengles/main/NativeWindowActivity.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.main;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.graphics.Bitmap;
6 | import android.graphics.BitmapFactory;
7 | import android.graphics.Color;
8 | import android.os.Bundle;
9 | import android.view.SurfaceHolder;
10 | import android.view.SurfaceView;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.widget.Button;
14 |
15 | import androidx.annotation.Nullable;
16 |
17 | import com.onzhou.opengles.base.AbsBaseActivity;
18 | import com.onzhou.opengles.nativewindow.NativeWindowSample;
19 | import com.onzhou.opengles.nativewindow.R;
20 |
21 | /**
22 | * @anchor: andy
23 | * @date: 2018-11-13
24 | * @description:
25 | */
26 | public class NativeWindowActivity extends AbsBaseActivity {
27 |
28 | /**
29 | * 根容器
30 | */
31 | private ViewGroup mRootLayer;
32 |
33 | private Button mBtnColor, mBtnBitmap;
34 |
35 | private NativeWindowSample mNativeWindowSample;
36 |
37 | private SurfaceView mSurfaceView;
38 |
39 | public static void intentStart(Context context) {
40 | Intent intent = new Intent(context, NativeWindowActivity.class);
41 | context.startActivity(intent);
42 | }
43 |
44 | @Override
45 | protected void onCreate(@Nullable Bundle savedInstanceState) {
46 | super.onCreate(savedInstanceState);
47 | setContentView(R.layout.activity_native_window);
48 | }
49 |
50 | @Override
51 | protected void onPostCreate(@Nullable Bundle savedInstanceState) {
52 | super.onPostCreate(savedInstanceState);
53 | mNativeWindowSample = new NativeWindowSample();
54 | setupView();
55 | }
56 |
57 | private void setupView() {
58 | mRootLayer = (ViewGroup) findViewById(R.id.root_layer);
59 | mBtnColor = (Button) findViewById(R.id.btn_draw_color);
60 | mBtnBitmap = (Button) findViewById(R.id.btn_draw_bitmap);
61 | mSurfaceView = new SurfaceView(this);
62 | mRootLayer.addView(mSurfaceView);
63 | mSurfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
64 | @Override
65 | public void surfaceCreated(SurfaceHolder holder) {
66 | mBtnColor.setEnabled(true);
67 | mBtnBitmap.setEnabled(true);
68 | }
69 |
70 | @Override
71 | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
72 |
73 | }
74 |
75 | @Override
76 | public void surfaceDestroyed(SurfaceHolder holder) {
77 |
78 | }
79 | });
80 | }
81 |
82 | public void onDrawColorClick(View view) {
83 | mNativeWindowSample.drawColor(mSurfaceView.getHolder().getSurface(), Color.GRAY);
84 | }
85 |
86 | public void onDrawBitmapClick(View view) {
87 | BitmapFactory.Options options = new BitmapFactory.Options();
88 | options.inScaled = false;
89 | Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.main, options);
90 | mNativeWindowSample.drawBitmap(mSurfaceView.getHolder().getSurface(), bitmap);
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/sample-native/src/main/java/com/onzhou/opengles/nativewindow/NativeWindowSample.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.nativewindow;
2 |
3 | /**
4 | * @anchor: andy
5 | * @date: 2018-11-13
6 | * @description:
7 | */
8 | public class NativeWindowSample {
9 |
10 | static {
11 | System.loadLibrary("native-window");
12 | }
13 |
14 | /**
15 | * 绘制指定颜色背景
16 | *
17 | * @param surface
18 | * @param color
19 | */
20 | public native void drawColor(Object surface, int color);
21 |
22 | /**
23 | * 绘制指定颜色背景
24 | *
25 | * @param surface
26 | * @param bitmap
27 | */
28 | public native void drawBitmap(Object surface, Object bitmap);
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/sample-native/src/main/release/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
7 |
8 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/sample-native/src/main/res/drawable-xxhdpi/main.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/sample-native/src/main/res/drawable-xxhdpi/main.jpg
--------------------------------------------------------------------------------
/sample-native/src/main/res/layout/activity_native_window.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
23 |
24 |
--------------------------------------------------------------------------------
/sample-native/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | opengles-native
3 |
4 |
--------------------------------------------------------------------------------
/sample-native/src/test/java/com/onzhou/opengles/nativewindow/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.nativewindow;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/sample-texture/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sample-texture/build.gradle:
--------------------------------------------------------------------------------
1 | apply from: "$rootDir/module.gradle"
2 |
--------------------------------------------------------------------------------
/sample-texture/gradle.properties:
--------------------------------------------------------------------------------
1 |
2 |
3 | library=true
--------------------------------------------------------------------------------
/sample-texture/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/sample-texture/src/main/debug/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
7 |
8 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/sample-texture/src/main/java/com/onzhou/opengles/main/TextureActivity.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.main;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.opengl.GLSurfaceView;
6 | import com.onzhou.opengles.base.AbsGLSurfaceActivity;
7 | import com.onzhou.opengles.texture.TextureRenderer;
8 |
9 | /**
10 | * @anchor: andy
11 | * @date: 18-11-10
12 | */
13 | public class TextureActivity extends AbsGLSurfaceActivity {
14 |
15 | public static void intentStart(Context context) {
16 | Intent intent = new Intent(context, TextureActivity.class);
17 | context.startActivity(intent);
18 | }
19 |
20 | @Override
21 | protected GLSurfaceView.Renderer bindRenderer() {
22 | return new TextureRenderer();
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/sample-texture/src/main/release/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
7 |
8 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/sample-texture/src/main/res/drawable-xxhdpi/main.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/sample-texture/src/main/res/drawable-xxhdpi/main.jpg
--------------------------------------------------------------------------------
/sample-texture/src/main/res/raw/fragment_texture_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | precision mediump float;
3 | uniform sampler2D uTextureUnit;
4 | in vec2 vTexCoord;
5 | out vec4 vFragColor;
6 | void main() {
7 | vFragColor = texture(uTextureUnit,vTexCoord);
8 | }
--------------------------------------------------------------------------------
/sample-texture/src/main/res/raw/vertex_texture_shader.glsl:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | layout (location = 0) in vec4 vPosition;
3 | layout (location = 1) in vec2 aTextureCoord;
4 | uniform mat4 u_Matrix;
5 | out vec2 vTexCoord;
6 | void main() {
7 | gl_Position = u_Matrix * vPosition;
8 | gl_PointSize = 10.0;
9 | vTexCoord = aTextureCoord;
10 | }
--------------------------------------------------------------------------------
/sample-texture/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | opengles-texture
3 |
4 |
--------------------------------------------------------------------------------
/sample-texture/src/test/java/com/onzhou/opengles/texture/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.onzhou.opengles.texture;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/screenshots/20181105121623778.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/screenshots/20181105121623778.png
--------------------------------------------------------------------------------
/screenshots/20181109133909448.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/screenshots/20181109133909448.png
--------------------------------------------------------------------------------
/screenshots/20181110174836154.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/screenshots/20181110174836154.png
--------------------------------------------------------------------------------
/screenshots/20181112222945107.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byhook/opengles4android/0d3f55cd0b32c478065650f2ca60537f9eea7667/screenshots/20181112222945107.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 | include ':sample-texture'
3 | include ':sample-camera'
4 | include ':sample-native'
5 | include ':sample-filter'
6 | include ':sample-color'
7 | include ':sample-basis'
8 |
9 | include ':common-base'
--------------------------------------------------------------------------------