├── .gitignore
├── .idea
├── encodings.xml
├── gradle.xml
├── markdown-navigator
│ └── profiles_settings.xml
├── misc.xml
├── modules.xml
└── runConfigurations.xml
├── README.md
├── Untitled Diagram.drawio
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── android
│ │ └── xrj
│ │ └── opengl
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── android
│ │ │ └── xrj
│ │ │ └── opengl
│ │ │ ├── GLLinearLayoutActivity.java
│ │ │ ├── GLWebViewActivity.java
│ │ │ ├── MainActivity.java
│ │ │ └── util
│ │ │ ├── DisplayUtil.java
│ │ │ └── StatusUtil.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ ├── activity_gl_line.xml
│ │ ├── activity_gl_webview.xml
│ │ └── activity_main.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
│ └── android
│ └── xrj
│ └── opengl
│ └── ExampleUnitTest.java
├── art
└── 2.png
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── support.xrj.opengl
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
├── androidTest
└── java
│ └── android
│ └── xrj
│ └── opengl
│ └── support
│ └── ExampleInstrumentedTest.java
├── main
├── AndroidManifest.xml
├── java
│ └── android
│ │ └── xrj
│ │ └── opengl
│ │ └── support
│ │ ├── BaseGLRenderer.java
│ │ ├── FooRenderer.java
│ │ ├── GLRenderable.java
│ │ ├── RawResourceReader.java
│ │ ├── ShaderHelper.java
│ │ └── view
│ │ ├── GLLinearLayout.java
│ │ └── GLWebView.java
└── res
│ ├── raw
│ ├── rect_fragment_shader.glsl
│ └── vertex_shader.glsl
│ └── values
│ └── strings.xml
└── test
└── java
└── android
└── xrj
└── opengl
└── support
└── ExampleUnitTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 | 1.8
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AndroidOpenGLView
2 | 使用OpenGL 渲染 WebView
3 |
4 | ### 图片
5 | 
6 |
--------------------------------------------------------------------------------
/Untitled Diagram.drawio:
--------------------------------------------------------------------------------
1 | 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
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 | defaultConfig {
6 | applicationId "android.xrj.opengl"
7 | minSdkVersion 17
8 | targetSdkVersion 26
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(include: ['*.jar'], dir: 'libs')
23 | implementation 'com.android.support:appcompat-v7:27.1.1'
24 | implementation 'com.android.support.constraint:constraint-layout:1.1.2'
25 | testImplementation 'junit:junit:4.12'
26 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
28 | implementation project(':support.xrj.opengl')
29 | implementation 'com.android.support:design:27.1.1'
30 | }
31 |
--------------------------------------------------------------------------------
/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/androidTest/java/android/xrj/opengl/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package android.xrj.opengl;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("android.xrj.opengl", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/android/xrj/opengl/GLLinearLayoutActivity.java:
--------------------------------------------------------------------------------
1 | package android.xrj.opengl;
2 |
3 | import android.app.Activity;
4 | import android.opengl.GLSurfaceView;
5 | import android.os.Bundle;
6 | import android.webkit.WebChromeClient;
7 | import android.webkit.WebViewClient;
8 | import android.widget.FrameLayout;
9 | import android.xrj.opengl.support.BaseGLRenderer;
10 | import android.xrj.opengl.support.FooRenderer;
11 | import android.xrj.opengl.support.view.GLWebView;
12 | import android.xrj.opengl.util.DisplayUtil;
13 | import android.xrj.opengl.util.StatusUtil;
14 |
15 | /**
16 | * Create by LingYan on 2018-08-27
17 | */
18 |
19 | public class GLLinearLayoutActivity extends Activity {
20 | private static final String TAG = "GLLinearLayoutActivity";
21 |
22 | private FrameLayout root;
23 | private GLSurfaceView glSurfaceView;
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_gl_line);
29 | root = findViewById(R.id.root);
30 | glSurfaceView = findViewById(R.id.gl_surface_view);
31 |
32 | GLWebView webView = new GLWebView(this);
33 |
34 | int width = DisplayUtil.getWidth(this);
35 | int height = DisplayUtil.getHeight(this) - StatusUtil.getStatusHeight(this);
36 |
37 | final BaseGLRenderer baseGlRenderer = new FooRenderer(this, width, height);
38 |
39 | glSurfaceView.setEGLContextClientVersion(2);
40 | glSurfaceView.setRenderer(baseGlRenderer);
41 | webView.setViewToGLRenderer(baseGlRenderer);
42 |
43 | webView.setWebViewClient(new WebViewClient());
44 | webView.setWebChromeClient(new WebChromeClient());
45 | webView.loadUrl("https://www.baidu.com");
46 |
47 | root.addView(webView);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/app/src/main/java/android/xrj/opengl/GLWebViewActivity.java:
--------------------------------------------------------------------------------
1 | package android.xrj.opengl;
2 |
3 | import android.app.Activity;
4 | import android.opengl.GLSurfaceView;
5 | import android.os.Bundle;
6 | import android.support.design.widget.AppBarLayout;
7 | import android.webkit.WebChromeClient;
8 | import android.webkit.WebViewClient;
9 | import android.xrj.opengl.support.BaseGLRenderer;
10 | import android.xrj.opengl.support.FooRenderer;
11 | import android.xrj.opengl.support.view.GLWebView;
12 | import android.xrj.opengl.util.DisplayUtil;
13 | import android.xrj.opengl.util.StatusUtil;
14 |
15 | /**
16 | * Create by LingYan on 2018-08-27
17 | */
18 |
19 | public class GLWebViewActivity extends Activity {
20 | private static final String TAG = "GLWebViewActivity";
21 | private GLSurfaceView mGLSurfaceView;
22 | private GLWebView mWebView;
23 | private AppBarLayout appBarLayout;
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_gl_webview);
29 | mGLSurfaceView = findViewById(R.id.gl_surface_view);
30 | mWebView = findViewById(R.id.web_view);
31 | appBarLayout = findViewById(R.id.appbar_layout);
32 |
33 | int width = DisplayUtil.getWidth(this);
34 | int height = DisplayUtil.getHeight(this) - StatusUtil.getStatusHeight(this) - appBarLayout.getHeight();
35 |
36 | final BaseGLRenderer baseGlRenderer = new FooRenderer(this, width, height);
37 |
38 | mGLSurfaceView.setEGLContextClientVersion(2);
39 | mGLSurfaceView.setRenderer(baseGlRenderer);
40 |
41 | mWebView.setViewToGLRenderer(baseGlRenderer);
42 |
43 | mWebView.setWebViewClient(new WebViewClient());
44 | mWebView.setWebChromeClient(new WebChromeClient());
45 | mWebView.loadUrl("https://www.baidu.com");
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/java/android/xrj/opengl/MainActivity.java:
--------------------------------------------------------------------------------
1 | package android.xrj.opengl;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 |
8 | public class MainActivity extends AppCompatActivity {
9 |
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | setContentView(R.layout.activity_main);
14 |
15 | findViewById(R.id.open_gl_web).setOnClickListener(new View.OnClickListener() {
16 | @Override
17 | public void onClick(View v) {
18 | Intent intent = new Intent(MainActivity.this, GLWebViewActivity.class);
19 | startActivity(intent);
20 | }
21 | });
22 |
23 | findViewById(R.id.open_gl_view).setOnClickListener(new View.OnClickListener() {
24 | @Override
25 | public void onClick(View v) {
26 | Intent intent = new Intent(MainActivity.this, GLLinearLayoutActivity.class);
27 | startActivity(intent);
28 | }
29 | });
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/android/xrj/opengl/util/DisplayUtil.java:
--------------------------------------------------------------------------------
1 | package android.xrj.opengl.util;
2 |
3 | import android.content.Context;
4 |
5 | /**
6 | * Create by LingYan on 2018-08-27
7 | */
8 |
9 | public class DisplayUtil {
10 | public static int getWidth(Context context) {
11 | return context.getResources().getDisplayMetrics().widthPixels;
12 | }
13 |
14 | public static int getHeight(Context context) {
15 | return context.getResources().getDisplayMetrics().heightPixels;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/java/android/xrj/opengl/util/StatusUtil.java:
--------------------------------------------------------------------------------
1 | package android.xrj.opengl.util;
2 |
3 | import android.content.Context;
4 |
5 | /**
6 | * Create by LingYan on 2018-08-27
7 | */
8 |
9 | public class StatusUtil {
10 | public static int getStatusHeight(Context context) {
11 | int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
12 | if (resourceId > 0) {
13 | return context.getResources().getDimensionPixelSize(resourceId);
14 | }
15 | return 0;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_gl_line.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_gl_webview.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
15 |
16 |
22 |
23 |
24 |
25 |
26 |
30 |
31 |
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
16 |
17 |
23 |
24 |
25 |
26 |
27 |
32 |
33 |
38 |
39 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leftcoding/AndroidOpenGLView/1a94c71d1bcf593843671ada9b56b56100a93a46/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leftcoding/AndroidOpenGLView/1a94c71d1bcf593843671ada9b56b56100a93a46/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leftcoding/AndroidOpenGLView/1a94c71d1bcf593843671ada9b56b56100a93a46/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leftcoding/AndroidOpenGLView/1a94c71d1bcf593843671ada9b56b56100a93a46/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leftcoding/AndroidOpenGLView/1a94c71d1bcf593843671ada9b56b56100a93a46/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leftcoding/AndroidOpenGLView/1a94c71d1bcf593843671ada9b56b56100a93a46/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leftcoding/AndroidOpenGLView/1a94c71d1bcf593843671ada9b56b56100a93a46/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leftcoding/AndroidOpenGLView/1a94c71d1bcf593843671ada9b56b56100a93a46/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leftcoding/AndroidOpenGLView/1a94c71d1bcf593843671ada9b56b56100a93a46/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leftcoding/AndroidOpenGLView/1a94c71d1bcf593843671ada9b56b56100a93a46/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AndroidOpenGLView
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/android/xrj/opengl/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package android.xrj.opengl;
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 | }
--------------------------------------------------------------------------------
/art/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leftcoding/AndroidOpenGLView/1a94c71d1bcf593843671ada9b56b56100a93a46/art/2.png
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.0.1'
11 |
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 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leftcoding/AndroidOpenGLView/1a94c71d1bcf593843671ada9b56b56100a93a46/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Aug 27 14:29:26 CST 2018
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-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':support.xrj.opengl'
2 |
--------------------------------------------------------------------------------
/support.xrj.opengl/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/support.xrj.opengl/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 26
5 |
6 |
7 |
8 | defaultConfig {
9 | minSdkVersion 17
10 | targetSdkVersion 26
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: 'libs', include: ['*.jar'])
29 |
30 | implementation 'com.android.support:appcompat-v7:26.1.0'
31 | testImplementation 'junit:junit:4.12'
32 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
33 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
34 | }
35 |
--------------------------------------------------------------------------------
/support.xrj.opengl/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 |
--------------------------------------------------------------------------------
/support.xrj.opengl/src/androidTest/java/android/xrj/opengl/support/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package android.xrj.opengl.support;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("android.xrj.opengl.support.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/support.xrj.opengl/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/support.xrj.opengl/src/main/java/android/xrj/opengl/support/BaseGLRenderer.java:
--------------------------------------------------------------------------------
1 | package android.xrj.opengl.support;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.SurfaceTexture;
5 | import android.opengl.GLES11Ext;
6 | import android.opengl.GLES20;
7 | import android.opengl.GLSurfaceView;
8 | import android.opengl.GLUtils;
9 | import android.util.Log;
10 | import android.view.Surface;
11 |
12 | import javax.microedition.khronos.egl.EGLConfig;
13 | import javax.microedition.khronos.opengles.GL10;
14 |
15 | public class BaseGLRenderer implements GLSurfaceView.Renderer {
16 | private static final String TAG = BaseGLRenderer.class.getSimpleName();
17 |
18 | private SurfaceTexture mSurfaceTexture;
19 | private Surface mSurface;
20 |
21 | private int mGlSurfaceTexture;
22 | private Canvas mSurfaceCanvas;
23 |
24 | private int mTextureWidth;
25 | private int mTextureHeight;
26 |
27 |
28 | public BaseGLRenderer(int mTextureWidth, int mTextureHeight) {
29 | this.mTextureWidth = mTextureWidth;
30 | this.mTextureHeight = mTextureHeight;
31 | }
32 |
33 | @Override
34 | public void onDrawFrame(GL10 gl) {
35 | synchronized (this) {
36 | mSurfaceTexture.updateTexImage();
37 | }
38 | }
39 |
40 | @Override
41 | public void onSurfaceChanged(GL10 gl, int width, int height) {
42 | releaseSurface();
43 | mGlSurfaceTexture = createTexture();
44 | if (mGlSurfaceTexture > 0) {
45 | mSurfaceTexture = new SurfaceTexture(mGlSurfaceTexture);
46 | mSurfaceTexture.setDefaultBufferSize(mTextureWidth, mTextureHeight);
47 | mSurface = new Surface(mSurfaceTexture);
48 | }
49 | }
50 |
51 | public void releaseSurface() {
52 | if (mSurface != null) {
53 | mSurface.release();
54 | }
55 | if (mSurfaceTexture != null) {
56 | mSurfaceTexture.release();
57 | }
58 | mSurface = null;
59 | mSurfaceTexture = null;
60 | }
61 |
62 | @Override
63 | public void onSurfaceCreated(GL10 gl, EGLConfig config) {
64 | final String extensions = GLES20.glGetString(GLES20.GL_EXTENSIONS);
65 | Log.d(TAG, extensions);
66 | }
67 |
68 | private int createTexture() {
69 | int[] textures = new int[1];
70 |
71 | GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
72 | GLES20.glGenTextures(1, textures, 0);
73 | checkGlError("Texture generate");
74 |
75 | GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textures[0]);
76 | checkGlError("Texture bind");
77 |
78 | GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
79 | GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
80 | GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
81 | GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);
82 |
83 | return textures[0];
84 | }
85 |
86 | public int getGLSurfaceTexture() {
87 | return mGlSurfaceTexture;
88 | }
89 |
90 | public Canvas onDrawViewBegin() {
91 | mSurfaceCanvas = null;
92 | if (mSurface != null) {
93 | try {
94 | mSurfaceCanvas = mSurface.lockCanvas(null);
95 | } catch (Exception e) {
96 | Log.e(TAG, "error while rendering view to gl: " + e);
97 | }
98 | }
99 | return mSurfaceCanvas;
100 | }
101 |
102 | public void onDrawViewEnd() {
103 | if (mSurfaceCanvas != null) {
104 | mSurface.unlockCanvasAndPost(mSurfaceCanvas);
105 | }
106 | mSurfaceCanvas = null;
107 | }
108 |
109 |
110 | public void checkGlError(String op) {
111 | int error;
112 | while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
113 | Log.e(TAG, op + ": glError " + GLUtils.getEGLErrorString(error));
114 | }
115 | }
116 |
117 | public int getTextureWidth() {
118 | return mTextureWidth;
119 | }
120 |
121 | public void setTextureWidth(int textureWidth) {
122 | mTextureWidth = textureWidth;
123 | }
124 |
125 | public int getTextureHeight() {
126 | return mTextureHeight;
127 | }
128 |
129 | public void setTextureHeight(int textureHeight) {
130 | mTextureHeight = textureHeight;
131 | }
132 | }
--------------------------------------------------------------------------------
/support.xrj.opengl/src/main/java/android/xrj/opengl/support/FooRenderer.java:
--------------------------------------------------------------------------------
1 | package android.xrj.opengl.support;
2 |
3 | import android.content.Context;
4 | import android.opengl.GLES11Ext;
5 | import android.opengl.GLES20;
6 |
7 | import java.nio.ByteBuffer;
8 | import java.nio.ByteOrder;
9 | import java.nio.FloatBuffer;
10 | import java.util.Calendar;
11 |
12 | import javax.microedition.khronos.egl.EGLConfig;
13 | import javax.microedition.khronos.opengles.GL10;
14 |
15 | public class FooRenderer extends BaseGLRenderer {
16 | private final FloatBuffer mCubePositions;
17 | private final FloatBuffer mCubeTextureCoordinates;
18 |
19 | private int mTextureUniformHandle;
20 | private int mPositionHandle;
21 | private int mTextureCoordinateHandle;
22 | private int mResolutionHandle;
23 | private int mTimeHandle;
24 |
25 | private int mProgramHandle;
26 |
27 | private final int mBytesPerFloat = 4;
28 | private final int mPositionDataSize = 3;
29 | private final int mTextureCoordinateDataSize = 2;
30 |
31 | private Context mContext;
32 | private long startTime;
33 |
34 | private int width;
35 | private int height;
36 |
37 | public FooRenderer(Context context, int width, int height) {
38 | super(width, height);
39 |
40 | mContext = context;
41 | final float[] cubePositionData =
42 | {
43 | // Front face
44 | -1.0f, 1.0f, 1.0f,
45 | -1.0f, -1.0f, 1.0f,
46 | 1.0f, 1.0f, 1.0f,
47 | -1.0f, -1.0f, 1.0f,
48 | 1.0f, -1.0f, 1.0f,
49 | 1.0f, 1.0f, 1.0f,
50 |
51 | };
52 |
53 | final float[] cubeTextureCoordinateData =
54 | {
55 | // Front face
56 | 0.0f, 0.0f,
57 | 0.0f, 1.0f,
58 | 1.0f, 0.0f,
59 | 0.0f, 1.0f,
60 | 1.0f, 1.0f,
61 | 1.0f, 0.0f,
62 | };
63 |
64 | mCubePositions = ByteBuffer.allocateDirect(cubePositionData.length * mBytesPerFloat).order(ByteOrder.nativeOrder()).asFloatBuffer();
65 | mCubePositions.put(cubePositionData).position(0);
66 |
67 | mCubeTextureCoordinates = ByteBuffer.allocateDirect(cubeTextureCoordinateData.length * mBytesPerFloat).order(ByteOrder.nativeOrder()).asFloatBuffer();
68 | mCubeTextureCoordinates.put(cubeTextureCoordinateData).position(0);
69 |
70 | startTime = Calendar.getInstance().getTimeInMillis();
71 | }
72 |
73 | private String getVertexShader() {
74 | return RawResourceReader.readTextFileFromRawResource(mContext, R.raw.vertex_shader);
75 | }
76 |
77 | private String getFragmentShader() {
78 | return RawResourceReader.readTextFileFromRawResource(mContext, R.raw.rect_fragment_shader);
79 | }
80 |
81 |
82 | @Override
83 | public void onSurfaceCreated(GL10 gl, EGLConfig config) {
84 | super.onSurfaceCreated(gl, config);
85 |
86 | GLES20.glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
87 |
88 | final String vertexShader = getVertexShader();
89 | final String fragmentShader = getFragmentShader();
90 |
91 | final int vertexShaderHandle = ShaderHelper.compileShader(GLES20.GL_VERTEX_SHADER, vertexShader);
92 | final int fragmentShaderHandle = ShaderHelper.compileShader(GLES20.GL_FRAGMENT_SHADER, fragmentShader);
93 |
94 | mProgramHandle = ShaderHelper.createAndLinkProgram(vertexShaderHandle, fragmentShaderHandle, new String[]{"a_Position", "a_TexCoordinate"});
95 | }
96 |
97 | @Override
98 | public void onSurfaceChanged(GL10 gl, int width, int height) {
99 | super.onSurfaceChanged(gl, width, height);
100 | GLES20.glViewport(0, 0, width, height);
101 | this.width = width;
102 | this.height = height;
103 |
104 | System.out.println("surface changed");
105 | }
106 |
107 | @Override
108 | public void onDrawFrame(GL10 gl) {
109 | super.onDrawFrame(gl);
110 | // GL Draw code onwards
111 | GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
112 |
113 | final int currentProgramHandle = mProgramHandle;
114 | GLES20.glUseProgram(mProgramHandle);
115 |
116 | mTextureUniformHandle = GLES20.glGetUniformLocation(currentProgramHandle, "u_Texture");
117 | mTimeHandle = GLES20.glGetUniformLocation(currentProgramHandle, "u_GlobalTime");
118 | mResolutionHandle = GLES20.glGetUniformLocation(currentProgramHandle, "u_Resolution");
119 |
120 | mPositionHandle = GLES20.glGetAttribLocation(currentProgramHandle, "a_Position");
121 | mTextureCoordinateHandle = GLES20.glGetAttribLocation(currentProgramHandle, "a_TexCoordinate");
122 |
123 | GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, getGLSurfaceTexture());
124 | GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
125 | GLES20.glUniform1i(mTextureUniformHandle, 0);
126 |
127 | float timeInMs = Calendar.getInstance().getTimeInMillis() - startTime;
128 |
129 | if (timeInMs > 20000) {
130 | startTime = Calendar.getInstance().getTimeInMillis();
131 | }
132 |
133 | GLES20.glUniform2f(mResolutionHandle, (float) width, (float) height);
134 | GLES20.glUniform1f(mTimeHandle, timeInMs / 1000);
135 | drawCube();
136 | }
137 |
138 | /**
139 | * Draws a cube.
140 | */
141 | private void drawCube() {
142 | // Pass in the position information
143 | mCubePositions.position(0);
144 | GLES20.glVertexAttribPointer(mPositionHandle, mPositionDataSize, GLES20.GL_FLOAT, false, 0, mCubePositions);
145 |
146 | GLES20.glEnableVertexAttribArray(mPositionHandle);
147 |
148 | mCubeTextureCoordinates.position(0);
149 | GLES20.glVertexAttribPointer(mTextureCoordinateHandle, mTextureCoordinateDataSize, GLES20.GL_FLOAT, false, 0, mCubeTextureCoordinates);
150 |
151 | GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);
152 |
153 | GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6);
154 | }
155 | }
156 |
--------------------------------------------------------------------------------
/support.xrj.opengl/src/main/java/android/xrj/opengl/support/GLRenderable.java:
--------------------------------------------------------------------------------
1 | package android.xrj.opengl.support;
2 |
3 | public interface GLRenderable {
4 | void setViewToGLRenderer(BaseGLRenderer baseGLRenderer);
5 | }
6 |
--------------------------------------------------------------------------------
/support.xrj.opengl/src/main/java/android/xrj/opengl/support/RawResourceReader.java:
--------------------------------------------------------------------------------
1 | package android.xrj.opengl.support;
2 |
3 | import android.content.Context;
4 |
5 | import java.io.BufferedReader;
6 | import java.io.IOException;
7 | import java.io.InputStream;
8 | import java.io.InputStreamReader;
9 |
10 | public class RawResourceReader {
11 | public static String readTextFileFromRawResource(final Context context,
12 | final int resourceId) {
13 | final InputStream inputStream = context.getResources().openRawResource(
14 | resourceId);
15 | final InputStreamReader inputStreamReader = new InputStreamReader(
16 | inputStream);
17 | final BufferedReader bufferedReader = new BufferedReader(
18 | inputStreamReader);
19 |
20 | String nextLine;
21 | final StringBuilder body = new StringBuilder();
22 |
23 | try {
24 | while ((nextLine = bufferedReader.readLine()) != null) {
25 | body.append(nextLine);
26 | body.append('\n');
27 | }
28 | } catch (IOException e) {
29 | return null;
30 | }
31 |
32 | return body.toString();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/support.xrj.opengl/src/main/java/android/xrj/opengl/support/ShaderHelper.java:
--------------------------------------------------------------------------------
1 | package android.xrj.opengl.support;
2 |
3 | import android.opengl.GLES20;
4 | import android.util.Log;
5 |
6 | public class ShaderHelper {
7 | private static final String TAG = "ShaderHelper";
8 |
9 | /**
10 | * Helper function to compile a shader.
11 | *
12 | * @param shaderType The shader type.
13 | * @param shaderSource The shader source code.
14 | * @return An OpenGL handle to the shader.
15 | */
16 | public static int compileShader(final int shaderType, final String shaderSource) {
17 | int shaderHandle = GLES20.glCreateShader(shaderType);
18 |
19 | if (shaderHandle != 0) {
20 | // Pass in the shader source.
21 | GLES20.glShaderSource(shaderHandle, shaderSource);
22 |
23 | // Compile the shader.
24 | GLES20.glCompileShader(shaderHandle);
25 |
26 | // Get the compilation status.
27 | final int[] compileStatus = new int[1];
28 | GLES20.glGetShaderiv(shaderHandle, GLES20.GL_COMPILE_STATUS, compileStatus, 0);
29 |
30 | // If the compilation failed, delete the shader.
31 | if (compileStatus[0] == 0) {
32 | Log.e(TAG, "Error compiling shader: " + GLES20.glGetShaderInfoLog(shaderHandle));
33 | GLES20.glDeleteShader(shaderHandle);
34 | shaderHandle = 0;
35 | }
36 | }
37 |
38 | if (shaderHandle == 0) {
39 | throw new RuntimeException("Error creating shader.");
40 | }
41 |
42 | return shaderHandle;
43 | }
44 |
45 | /**
46 | * Helper function to compile and link a program.
47 | *
48 | * @param vertexShaderHandle An OpenGL handle to an already-compiled vertex shader.
49 | * @param fragmentShaderHandle An OpenGL handle to an already-compiled fragment shader.
50 | * @param attributes Attributes that need to be bound to the program.
51 | * @return An OpenGL handle to the program.
52 | */
53 | public static int createAndLinkProgram(final int vertexShaderHandle, final int fragmentShaderHandle, final String[] attributes) {
54 | int programHandle = GLES20.glCreateProgram();
55 |
56 | if (programHandle != 0) {
57 | // Bind the vertex shader to the program.
58 | GLES20.glAttachShader(programHandle, vertexShaderHandle);
59 |
60 | // Bind the fragment shader to the program.
61 | GLES20.glAttachShader(programHandle, fragmentShaderHandle);
62 |
63 | // Bind attributes
64 | if (attributes != null) {
65 | final int size = attributes.length;
66 | for (int i = 0; i < size; i++) {
67 | GLES20.glBindAttribLocation(programHandle, i, attributes[i]);
68 | }
69 | }
70 |
71 | // Link the two shaders together into a program.
72 | GLES20.glLinkProgram(programHandle);
73 |
74 | // Get the link status.
75 | final int[] linkStatus = new int[1];
76 | GLES20.glGetProgramiv(programHandle, GLES20.GL_LINK_STATUS, linkStatus, 0);
77 |
78 | // If the link failed, delete the program.
79 | if (linkStatus[0] == 0) {
80 | Log.e(TAG, "Error compiling program: " + GLES20.glGetProgramInfoLog(programHandle));
81 | GLES20.glDeleteProgram(programHandle);
82 | programHandle = 0;
83 | }
84 | }
85 |
86 | if (programHandle == 0) {
87 | throw new RuntimeException("Error creating program.");
88 | }
89 |
90 | return programHandle;
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/support.xrj.opengl/src/main/java/android/xrj/opengl/support/view/GLLinearLayout.java:
--------------------------------------------------------------------------------
1 | package android.xrj.opengl.support.view;
2 |
3 | import android.annotation.TargetApi;
4 | import android.content.Context;
5 | import android.graphics.Canvas;
6 | import android.os.Build;
7 | import android.util.AttributeSet;
8 | import android.widget.LinearLayout;
9 | import android.xrj.opengl.support.BaseGLRenderer;
10 | import android.xrj.opengl.support.GLRenderable;
11 |
12 | public class GLLinearLayout extends LinearLayout implements GLRenderable {
13 | private BaseGLRenderer mBaseGLRenderer;
14 |
15 | // default constructors
16 |
17 | public GLLinearLayout(Context context) {
18 | super(context);
19 | }
20 |
21 | public GLLinearLayout(Context context, AttributeSet attrs) {
22 | super(context, attrs);
23 | }
24 |
25 | @TargetApi(Build.VERSION_CODES.HONEYCOMB)
26 | public GLLinearLayout(Context context, AttributeSet attrs, int defStyle) {
27 | super(context, attrs, defStyle);
28 | }
29 |
30 | // drawing magic
31 | @Override
32 | public void draw(Canvas canvas) {
33 | // super.draw(canvas);
34 | Canvas glAttachedCanvas = mBaseGLRenderer.onDrawViewBegin();
35 | if (glAttachedCanvas != null) {
36 | //prescale canvas to make sure content fits
37 | float xScale = glAttachedCanvas.getWidth() / (float) canvas.getWidth();
38 | glAttachedCanvas.scale(xScale, xScale);
39 | //draw the view to provided canvas
40 | super.draw(glAttachedCanvas);
41 | }
42 | // notify the canvas is updated
43 | mBaseGLRenderer.onDrawViewEnd();
44 |
45 | invalidate();
46 | }
47 |
48 | public void setViewToGLRenderer(BaseGLRenderer baseGLRenderer) {
49 | mBaseGLRenderer = baseGLRenderer;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/support.xrj.opengl/src/main/java/android/xrj/opengl/support/view/GLWebView.java:
--------------------------------------------------------------------------------
1 | package android.xrj.opengl.support.view;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.util.AttributeSet;
6 | import android.webkit.WebView;
7 | import android.xrj.opengl.support.BaseGLRenderer;
8 | import android.xrj.opengl.support.GLRenderable;
9 |
10 | public class GLWebView extends WebView implements GLRenderable {
11 |
12 | private BaseGLRenderer mBaseGLRenderer;
13 |
14 | // default constructors
15 |
16 | public GLWebView(Context context) {
17 | super(context);
18 | }
19 |
20 | public GLWebView(Context context, AttributeSet attrs) {
21 | super(context, attrs);
22 | }
23 |
24 | public GLWebView(Context context, AttributeSet attrs, int defStyle) {
25 | super(context, attrs, defStyle);
26 | }
27 |
28 | // draw magic
29 | @Override
30 | public void draw(Canvas canvas) {
31 | //returns canvas attached to gl texture to draw on
32 | Canvas glAttachedCanvas = mBaseGLRenderer.onDrawViewBegin();
33 | if (glAttachedCanvas != null) {
34 | //translate canvas to reflect view scrolling
35 | float xScale = glAttachedCanvas.getWidth() / (float) canvas.getWidth();
36 | glAttachedCanvas.scale(xScale, xScale);
37 | glAttachedCanvas.translate(-getScrollX(), -getScrollY());
38 | //draw the view to provided canvas
39 | super.draw(glAttachedCanvas);
40 | }
41 | // notify the canvas is updated
42 | mBaseGLRenderer.onDrawViewEnd();
43 | }
44 |
45 | public void setViewToGLRenderer(BaseGLRenderer viewTOGLRenderer) {
46 | mBaseGLRenderer = viewTOGLRenderer;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/support.xrj.opengl/src/main/res/raw/rect_fragment_shader.glsl:
--------------------------------------------------------------------------------
1 | #extension GL_OES_EGL_image_external : require
2 | precision mediump float;
3 |
4 |
5 | struct Rect {
6 | vec4 color;
7 | float left;
8 | float top;
9 | float right;
10 | float bottom;
11 | };
12 |
13 |
14 | // important to include in order to use rendered Android View to gl texture
15 | uniform samplerExternalOES u_Texture;
16 |
17 | uniform float u_GlobalTime;
18 |
19 |
20 | const int MAX_RECTS = 4;
21 | uniform Rect u_Rects[MAX_RECTS];
22 |
23 | varying vec2 v_TexCoordinate;
24 |
25 | void main()
26 | {
27 |
28 | vec2 uv = v_TexCoordinate.xy;
29 |
30 | vec4 primary_color = texture2D(u_Texture, uv);
31 |
32 | vec4 tmpColor = vec4(0.0, 0.0, 0.0, 0.0);
33 |
34 | bool set = false;
35 |
36 | for(int idx = 0; idx < MAX_RECTS; idx++) {
37 | if(uv.x > u_Rects[idx].left && uv.x < u_Rects[idx].right && uv.y > u_Rects[idx].top && uv.y < u_Rects[idx].bottom) {
38 | tmpColor += u_Rects[idx].color;
39 | set = true;
40 | }
41 | }
42 |
43 | if(set) {
44 | primary_color *= tmpColor;
45 | }
46 |
47 | gl_FragColor = primary_color;
48 | }
--------------------------------------------------------------------------------
/support.xrj.opengl/src/main/res/raw/vertex_shader.glsl:
--------------------------------------------------------------------------------
1 | attribute vec4 a_Position;
2 | attribute vec2 a_TexCoordinate;
3 |
4 | varying vec2 v_TexCoordinate;
5 |
6 | void main()
7 | {
8 | v_TexCoordinate = a_TexCoordinate;
9 | gl_Position = a_Position;
10 | }
--------------------------------------------------------------------------------
/support.xrj.opengl/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | support.xrj.opengl
3 |
4 |
--------------------------------------------------------------------------------
/support.xrj.opengl/src/test/java/android/xrj/opengl/support/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package android.xrj.opengl.support;
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 | }
--------------------------------------------------------------------------------