├── .gitignore
├── AUTHORS.md
├── LICENSE
├── README.md
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── java6-android-gldemos
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── assets
│ └── shaders
│ │ ├── gles30
│ │ ├── color
│ │ │ └── invertTexture.frag
│ │ ├── common
│ │ │ ├── directTexture.frag
│ │ │ └── directTexture.vert
│ │ └── effects
│ │ │ └── kuwaharaOptimized.frag
│ │ └── gles31
│ │ ├── color
│ │ ├── invertTexture.comp
│ │ └── invertTextureSampler.comp
│ │ └── raytrace
│ │ └── basicraytrace.comp
│ ├── java
│ └── org
│ │ └── typhonrt
│ │ └── android
│ │ └── java6
│ │ └── gldemo
│ │ ├── GLDemoActivity.java
│ │ ├── GLHeaderAdapter.java
│ │ ├── gles30
│ │ └── effects
│ │ │ ├── GLSLInvert.java
│ │ │ ├── GLSLKuwahara.java
│ │ │ └── GLSLKuwaharaFBO.java
│ │ ├── gles31
│ │ ├── invert
│ │ │ ├── ComputeInvert.java
│ │ │ └── ComputeInvertSampler.java
│ │ └── raytrace
│ │ │ ├── basic
│ │ │ └── ComputeBasicRayTrace.java
│ │ │ └── shared
│ │ │ └── PinholeCamera.java
│ │ └── shared
│ │ └── BaseDemoActivity.java
│ └── res
│ ├── drawable-hdpi
│ └── ic_launcher.png
│ ├── drawable-mdpi
│ └── ic_launcher.png
│ ├── drawable-nodpi
│ └── flower1024.jpg
│ ├── drawable-xhdpi
│ └── ic_launcher.png
│ ├── drawable-xxhdpi
│ └── ic_launcher.png
│ ├── drawable-xxxhdpi
│ └── ic_launcher.png
│ ├── drawable
│ └── gradient.xml
│ ├── layout
│ ├── demo_activity_layout.xml
│ ├── list_activity_layout.xml
│ ├── listview_section.xml
│ └── listview_text.xml
│ ├── values-v19
│ └── styles.xml
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── prebuilt-apk
└── ModernGL.apk
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Gradle
2 | .gradle
3 | /build
4 |
5 | ## Android Studio and Intellij and Android in general
6 | .idea
7 | *.ipr
8 | *.iws
9 | *.iml
10 | local.properties
11 |
12 | ## OS Specific
13 | .DS_Store
--------------------------------------------------------------------------------
/AUTHORS.md:
--------------------------------------------------------------------------------
1 | ####Corporate Copyright Statements
2 | -----
3 |
4 | Copyright (c) 2014-present TyphonRT Inc. [@typhonrt](https://github.com/typhonrt)
5 |
6 | ####Contributors
7 | -----
8 |
9 | Michael Leahy [@typhonrt](https://github.com/typhonrt)
10 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | 
3 | ============================
4 | Modern OpenGL/ES examples in Java are few and far between and this collection of demos showcases what is possible with OpenGL ES 3.0 / 3.1 / 3.2 (forthcoming). The purpose is to inform developers, but also provide a testbed for cross-device testing between various mobile GPUs. This repo contains only demo code and depends on java6-android-glframework and java6-android-demoframework. By separating the GL and demo framework code from the demos this allows you to use it separately as you see fit and also allow for a forthcoming port of the Nvidia Gameworks demos to a separate repo which will carry a different license than MPL v2 or Apache 2. The GL framework code provides concise utility code that makes working with OpenGL with Java easier and updates several utility classes like GLSurfaceView which has been "long in the tooth" in regard to the Android SDK utility code for OpenGL. The demoframework code contains basic utilities for providing an Android GUI for the demos.
5 |
6 | Device requirements: Android 4.4+ / OpenGL ES 3.0+
7 |
8 | IDE requirements: Android Studio 2.x+ / build tools: 23.0.3
9 |
10 | Latest Updates
11 | ========
12 | (4.10.16): Update for Android Studio 2.x+ / moved repos to [modern-java-graphics](https://github.com/modern-java-graphics) organization. Moved Google Groups forum to modern-java-graphics. Lowered API level to 19 / Kitkat. Changed licenses for [java6-android-glframework](https://github.com/modern-java-graphics/java6-android-glframework) and [java6-android-demoframework](https://github.com/modern-java-graphics/java6-android-demoframework) to `MPL v2.0`. This repo (java6-android-gldemos) remains available via `Apache 2`.
13 |
14 | (4.15.15): I finally had the chance to take a look at the Android 5.1 update for the Nexus 6 which brought a GPU driver update from Qualcomm, but it has flaws that prevent the compute shader examples from running which I
15 | discuss in this post on the forums.
16 |
17 | (1.1.15): I finally had a chance to do some refactoring this afternoon, so
18 | check out this post for more information.
19 |
20 | A Google web forum is now available to discuss anything related to this modern OpenGL utility framework. If you have questions or comments about modern OpenGL with Java for Android check out the web forum and post your question.
21 |
22 | These samples require the latest Android Studio 2.x+ developer setup. To install Android Studio please download it here
23 |
24 | There is a prebuilt apk located which can be [downloaded directly](https://github.com/modern-java-graphics/java6-android-gldemos/raw/master/prebuilt-apk/ModernGL.apk). With the Android developers tools installed simply run "adb install ModernGL.apk". An even easier way to install the GL demos app is to view this web page from your Android device after enabling installation of apps from unknown sources. To do this turn on "unknown sources" in the Settings->Security section of your device then click the download link above. When it finishes downloading you should be able to install it directly on your device without needing ADB.
25 |
26 | To navigate in the GL demos app select a demo by a single tap and long press to open a web page to a wiki page. Since the demos just launched the wiki info for each demo will be updated eventually with more details.
27 |
28 | For full source code installation instructions refer to the wiki / install guide. In time an expanded wiki will illuminate the full power of modern OpenGL with Java for Android. Please stay tuned as this effort is taken on by Michael Leahy, the author, in his spare time and more demos are forthcoming.
29 |
30 | If you found these demos useful consider checking out the TyphonRT Video Suite which is his next-gen photo / video engine technology for Android using OpenGL ES 3.0+ and hardware accelerated media encoding / decoding. Click the image below to check it out:
31 |
33 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.0.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/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 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/modern-java-graphics/java6-android-gldemos/7a1b97c7c0c40f7145bea5eb2e7ff28624a90799/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 10 15:27:10 PDT 2013
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/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 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/java6-android-gldemos/.gitignore:
--------------------------------------------------------------------------------
1 | ## Gradle
2 | .gradle/
3 | build/
4 |
5 | ## Android Studio and Intellij and Android in general
6 | .idea/
7 | *.ipr
8 | *.iws
9 | *.iml
10 | local.properties
11 |
12 | ## OS Specific
13 | .DS_Store
--------------------------------------------------------------------------------
/java6-android-gldemos/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion '23.0.3'
6 |
7 | defaultConfig {
8 | applicationId "org.typhonrt.android.java6.gldemo"
9 | minSdkVersion 19
10 | targetSdkVersion 21
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled true
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | compile 'com.android.support:support-v4:23.3.0'
25 | compile 'com.android.support:appcompat-v7:23.3.0'
26 | compile project(':java6-android-demoframework')
27 | compile project(':java6-android-glutils')
28 | compile project(':java6-glutils-commons')
29 | compile project(':java6-math')
30 | }
31 |
--------------------------------------------------------------------------------
/java6-android-gldemos/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Volumes/Data/program/SDK/android-sdk-macosx/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
14 |
15 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
37 |
38 |
45 |
46 |
53 |
54 |
61 |
62 |
69 |
70 |
77 |
78 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/assets/shaders/gles30/color/invertTexture.frag:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | /**
3 | * Copyright 2015 Michael Leahy / TyphonRT, Inc.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | // Invert fragment shader - Inverts texture color by a given intensity between 0.0 (normal) - 1.0 (full invert);
19 |
20 | precision mediump float;
21 |
22 | in vec2 vTexCoord;
23 |
24 | uniform sampler2D uSourceTex;
25 | uniform lowp float intensity;
26 |
27 | out vec4 outColor;
28 |
29 | void main()
30 | {
31 | lowp vec4 textureColor = texture(uSourceTex, vTexCoord);
32 | outColor = vec4(mix(textureColor.rgb, 1.0 - textureColor.rgb, intensity), textureColor.a);
33 | }
34 |
35 |
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/assets/shaders/gles30/common/directTexture.frag:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | /**
3 | * Copyright 2015 Michael Leahy / TyphonRT, Inc.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | // Direct texture fragment shader
19 |
20 | precision mediump float;
21 |
22 | uniform sampler2D uSourceTex;
23 |
24 | in vec2 vTexCoord;
25 | out vec4 color;
26 |
27 | void main(void)
28 | {
29 | color = texture(uSourceTex, vTexCoord);
30 | }
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/assets/shaders/gles30/common/directTexture.vert:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | /**
3 | * Copyright 2015 Michael Leahy / TyphonRT, Inc.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | // Defines a simple shader to forward on vertex and u/v.
19 |
20 | in vec4 inPosition;
21 | in highp vec2 aTexCoord;
22 |
23 | out highp vec2 vTexCoord;
24 |
25 | void main()
26 | {
27 | vTexCoord = aTexCoord;
28 | gl_Position = inPosition;
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/assets/shaders/gles30/effects/kuwaharaOptimized.frag:
--------------------------------------------------------------------------------
1 | #version 300 es
2 | /**
3 | * Copyright 2015 Michael Leahy / TyphonRT, Inc.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | // Sourced from GPUImage which:
19 | // Sourced from Kyprianidis, J. E., Kang, H., and Doellner, J. "Anisotropic Kuwahara Filtering on the GPU,"
20 | // GPU Pro p.247 (2010).
21 | //
22 | // Original header:
23 | //
24 | // Anisotropic Kuwahara Filtering on the GPU
25 | // by Jan Eric Kyprianidis
26 |
27 | precision highp float;
28 | in vec2 vTexCoord;
29 |
30 | uniform sampler2D uSourceTex; //0
31 |
32 | uniform vec2 sampleStep;
33 |
34 | out vec4 outColor;
35 |
36 | void main()
37 | {
38 | vec2 uv = vTexCoord;
39 |
40 | vec4 originalColor = texture(uSourceTex, uv);
41 |
42 | float n = float(16); // radius is assumed to be 3
43 | vec3 m0 = vec3(0.0); vec3 m1 = vec3(0.0); vec3 m2 = vec3(0.0); vec3 m3 = vec3(0.0);
44 | vec3 s0 = vec3(0.0); vec3 s1 = vec3(0.0); vec3 s2 = vec3(0.0); vec3 s3 = vec3(0.0);
45 | vec3 c;
46 | vec3 cSq;
47 |
48 | c = texture(uSourceTex, uv + vec2(-3,-3) * sampleStep).rgb;
49 | m0 += c;
50 | s0 += c * c;
51 | c = texture(uSourceTex, uv + vec2(-3,-2) * sampleStep).rgb;
52 | m0 += c;
53 | s0 += c * c;
54 | c = texture(uSourceTex, uv + vec2(-3,-1) * sampleStep).rgb;
55 | m0 += c;
56 | s0 += c * c;
57 | c = texture(uSourceTex, uv + vec2(-3,0) * sampleStep).rgb;
58 | cSq = c * c;
59 | m0 += c;
60 | s0 += cSq;
61 | m1 += c;
62 | s1 += cSq;
63 |
64 | c = texture(uSourceTex, uv + vec2(-2,-3) * sampleStep).rgb;
65 | m0 += c;
66 | s0 += c * c;
67 | c = texture(uSourceTex, uv + vec2(-2,-2) * sampleStep).rgb;
68 | m0 += c;
69 | s0 += c * c;
70 | c = texture(uSourceTex, uv + vec2(-2,-1) * sampleStep).rgb;
71 | m0 += c;
72 | s0 += c * c;
73 | c = texture(uSourceTex, uv + vec2(-2,0) * sampleStep).rgb;
74 | cSq = c * c;
75 | m0 += c;
76 | s0 += cSq;
77 | m1 += c;
78 | s1 += cSq;
79 |
80 | c = texture(uSourceTex, uv + vec2(-1,-3) * sampleStep).rgb;
81 | m0 += c;
82 | s0 += c * c;
83 | c = texture(uSourceTex, uv + vec2(-1,-2) * sampleStep).rgb;
84 | m0 += c;
85 | s0 += c * c;
86 | c = texture(uSourceTex, uv + vec2(-1,-1) * sampleStep).rgb;
87 | m0 += c;
88 | s0 += c * c;
89 | c = texture(uSourceTex, uv + vec2(-1,0) * sampleStep).rgb;
90 | cSq = c * c;
91 | m0 += c;
92 | s0 += cSq;
93 | m1 += c;
94 | s1 += cSq;
95 |
96 | c = texture(uSourceTex, uv + vec2(0,-3) * sampleStep).rgb;
97 | cSq = c * c;
98 | m0 += c;
99 | s0 += cSq;
100 | m3 += c;
101 | s3 += cSq;
102 | c = texture(uSourceTex, uv + vec2(0,-2) * sampleStep).rgb;
103 | cSq = c * c;
104 | m0 += c;
105 | s0 += cSq;
106 | m3 += c;
107 | s3 += cSq;
108 | c = texture(uSourceTex, uv + vec2(0,-1) * sampleStep).rgb;
109 | cSq = c * c;
110 | m0 += c;
111 | s0 += cSq;
112 | m3 += c;
113 | s3 += cSq;
114 | c = texture(uSourceTex, uv + vec2(0,0) * sampleStep).rgb;
115 | cSq = c * c;
116 | m0 += c;
117 | s0 += cSq;
118 | m1 += c;
119 | s1 += cSq;
120 | m2 += c;
121 | s2 += cSq;
122 | m3 += c;
123 | s3 += cSq;
124 |
125 | c = texture(uSourceTex, uv + vec2(-3,3) * sampleStep).rgb;
126 | m1 += c;
127 | s1 += c * c;
128 | c = texture(uSourceTex, uv + vec2(-3,2) * sampleStep).rgb;
129 | m1 += c;
130 | s1 += c * c;
131 | c = texture(uSourceTex, uv + vec2(-3,1) * sampleStep).rgb;
132 | m1 += c;
133 | s1 += c * c;
134 |
135 | c = texture(uSourceTex, uv + vec2(-2,3) * sampleStep).rgb;
136 | m1 += c;
137 | s1 += c * c;
138 | c = texture(uSourceTex, uv + vec2(-2,2) * sampleStep).rgb;
139 | m1 += c;
140 | s1 += c * c;
141 | c = texture(uSourceTex, uv + vec2(-2,1) * sampleStep).rgb;
142 | m1 += c;
143 | s1 += c * c;
144 |
145 | c = texture(uSourceTex, uv + vec2(-1,3) * sampleStep).rgb;
146 | m1 += c;
147 | s1 += c * c;
148 | c = texture(uSourceTex, uv + vec2(-1,2) * sampleStep).rgb;
149 | m1 += c;
150 | s1 += c * c;
151 | c = texture(uSourceTex, uv + vec2(-1,1) * sampleStep).rgb;
152 | m1 += c;
153 | s1 += c * c;
154 |
155 | c = texture(uSourceTex, uv + vec2(0,3) * sampleStep).rgb;
156 | cSq = c * c;
157 | m1 += c;
158 | s1 += cSq;
159 | m2 += c;
160 | s2 += cSq;
161 | c = texture(uSourceTex, uv + vec2(0,2) * sampleStep).rgb;
162 | cSq = c * c;
163 | m1 += c;
164 | s1 += cSq;
165 | m2 += c;
166 | s2 += cSq;
167 | c = texture(uSourceTex, uv + vec2(0,1) * sampleStep).rgb;
168 | cSq = c * c;
169 | m1 += c;
170 | s1 += cSq;
171 | m2 += c;
172 | s2 += cSq;
173 |
174 | c = texture(uSourceTex, uv + vec2(3,3) * sampleStep).rgb;
175 | m2 += c;
176 | s2 += c * c;
177 | c = texture(uSourceTex, uv + vec2(3,2) * sampleStep).rgb;
178 | m2 += c;
179 | s2 += c * c;
180 | c = texture(uSourceTex, uv + vec2(3,1) * sampleStep).rgb;
181 | m2 += c;
182 | s2 += c * c;
183 | c = texture(uSourceTex, uv + vec2(3,0) * sampleStep).rgb;
184 | cSq = c * c;
185 | m2 += c;
186 | s2 += cSq;
187 | m3 += c;
188 | s3 += cSq;
189 |
190 | c = texture(uSourceTex, uv + vec2(2,3) * sampleStep).rgb;
191 | m2 += c;
192 | s2 += c * c;
193 | c = texture(uSourceTex, uv + vec2(2,2) * sampleStep).rgb;
194 | m2 += c;
195 | s2 += c * c;
196 | c = texture(uSourceTex, uv + vec2(2,1) * sampleStep).rgb;
197 | m2 += c;
198 | s2 += c * c;
199 | c = texture(uSourceTex, uv + vec2(2,0) * sampleStep).rgb;
200 | cSq = c * c;
201 | m2 += c;
202 | s2 += cSq;
203 | m3 += c;
204 | s3 += cSq;
205 |
206 | c = texture(uSourceTex, uv + vec2(1,3) * sampleStep).rgb;
207 | m2 += c;
208 | s2 += c * c;
209 | c = texture(uSourceTex, uv + vec2(1,2) * sampleStep).rgb;
210 | m2 += c;
211 | s2 += c * c;
212 | c = texture(uSourceTex, uv + vec2(1,1) * sampleStep).rgb;
213 | m2 += c;
214 | s2 += c * c;
215 | c = texture(uSourceTex, uv + vec2(1,0) * sampleStep).rgb;
216 | cSq = c * c;
217 | m2 += c;
218 | s2 += cSq;
219 | m3 += c;
220 | s3 += cSq;
221 |
222 | c = texture(uSourceTex, uv + vec2(3,-3) * sampleStep).rgb;
223 | m3 += c;
224 | s3 += c * c;
225 | c = texture(uSourceTex, uv + vec2(3,-2) * sampleStep).rgb;
226 | m3 += c;
227 | s3 += c * c;
228 | c = texture(uSourceTex, uv + vec2(3,-1) * sampleStep).rgb;
229 | m3 += c;
230 | s3 += c * c;
231 |
232 | c = texture(uSourceTex, uv + vec2(2,-3) * sampleStep).rgb;
233 | m3 += c;
234 | s3 += c * c;
235 | c = texture(uSourceTex, uv + vec2(2,-2) * sampleStep).rgb;
236 | m3 += c;
237 | s3 += c * c;
238 | c = texture(uSourceTex, uv + vec2(2,-1) * sampleStep).rgb;
239 | m3 += c;
240 | s3 += c * c;
241 |
242 | c = texture(uSourceTex, uv + vec2(1,-3) * sampleStep).rgb;
243 | m3 += c;
244 | s3 += c * c;
245 | c = texture(uSourceTex, uv + vec2(1,-2) * sampleStep).rgb;
246 | m3 += c;
247 | s3 += c * c;
248 | c = texture(uSourceTex, uv + vec2(1,-1) * sampleStep).rgb;
249 | m3 += c;
250 | s3 += c * c;
251 |
252 | float min_sigma2 = 1e+2;
253 | m0 /= n;
254 | s0 = abs(s0 / n - m0 * m0);
255 |
256 | float sigma2 = s0.r + s0.g + s0.b;
257 | if (sigma2 < min_sigma2)
258 | {
259 | min_sigma2 = sigma2;
260 | outColor = vec4(m0, originalColor.a);
261 | }
262 |
263 | m1 /= n;
264 | s1 = abs(s1 / n - m1 * m1);
265 |
266 | sigma2 = s1.r + s1.g + s1.b;
267 | if (sigma2 < min_sigma2)
268 | {
269 | min_sigma2 = sigma2;
270 | outColor = vec4(m1, originalColor.a);
271 | }
272 |
273 | m2 /= n;
274 | s2 = abs(s2 / n - m2 * m2);
275 |
276 | sigma2 = s2.r + s2.g + s2.b;
277 | if (sigma2 < min_sigma2)
278 | {
279 | min_sigma2 = sigma2;
280 | outColor = vec4(m2, originalColor.a);
281 | }
282 |
283 | m3 /= n;
284 | s3 = abs(s3 / n - m3 * m3);
285 |
286 | sigma2 = s3.r + s3.g + s3.b;
287 | if (sigma2 < min_sigma2)
288 | {
289 | min_sigma2 = sigma2;
290 | outColor = vec4(m3, originalColor.a);
291 | }
292 | }
293 |
294 |
295 |
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/assets/shaders/gles31/color/invertTexture.comp:
--------------------------------------------------------------------------------
1 | // Note: A string header with GLSL version and #defines is added here.
2 |
3 | /**
4 | * Copyright 2015 Michael Leahy / TyphonRT, Inc.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | // Compute shader to invert texture.
20 |
21 | layout(local_size_x = LOCAL_SIZE, local_size_y = LOCAL_SIZE) in;
22 | layout(binding=0, rgba8) uniform mediump readonly image2D inputImage;
23 | layout(binding=1, rgba8) uniform mediump writeonly image2D resultImage;
24 |
25 | void main()
26 | {
27 | ivec2 position = ivec2(gl_GlobalInvocationID.xy);
28 |
29 | vec4 color = 1.0 - imageLoad(inputImage, position);
30 | imageStore(resultImage, position, color);
31 | }
32 |
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/assets/shaders/gles31/color/invertTextureSampler.comp:
--------------------------------------------------------------------------------
1 | // Note: A string header with GLSL version and #defines is added here.
2 |
3 | /**
4 | * Copyright 2015 Michael Leahy / TyphonRT, Inc.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | // Compute shader to invert texture, but use a sampler showing that normal GLSL commands
20 | // can be mixed with compute shaders.
21 |
22 | precision mediump float;
23 |
24 | layout (local_size_x = LOCAL_SIZE, local_size_y = LOCAL_SIZE) in;
25 |
26 | layout(binding=0) uniform sampler2D inputImage;
27 | layout(binding=1, rgba8) uniform mediump writeonly image2D resultImage;
28 |
29 | uniform vec2 imageDimension;
30 |
31 | void main()
32 | {
33 | ivec2 position = ivec2(gl_GlobalInvocationID.xy);
34 |
35 | // Must convert back to normalized U/V
36 | vec2 screenNormalized = vec2(position) / imageDimension;
37 |
38 | vec4 color = 1.0 - texture(inputImage, screenNormalized);
39 |
40 | imageStore(resultImage, position, color);
41 | }
42 |
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/assets/shaders/gles31/raytrace/basicraytrace.comp:
--------------------------------------------------------------------------------
1 | // Note: A string header with GLSL version and #defines is added here.
2 |
3 | /**
4 | * Copyright 2015 Kai Burjack
5 | * See: https://github.com/LWJGL/lwjgl3/wiki/2.6.1.-Ray-tracing-with-OpenGL-Compute-Shaders-%28Part-I%29
6 | *
7 | * Copyright 2015 Michael Leahy / TyphonRT, Inc.
8 | * Converted to OpenGL ES 3.1 by Michael Leahy
9 | *
10 | * Licensed under the Apache License, Version 2.0 (the "License");
11 | * you may not use this file except in compliance with the License.
12 | * You may obtain a copy of the License at
13 | *
14 | * http://www.apache.org/licenses/LICENSE-2.0
15 | *
16 | * Unless required by applicable law or agreed to in writing, software
17 | * distributed under the License is distributed on an "AS IS" BASIS,
18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 | * See the License for the specific language governing permissions and
20 | * limitations under the License.
21 | */
22 |
23 | layout(binding = 0, rgba32f) uniform highp writeonly image2D framebuffer;
24 |
25 | precision mediump float;
26 |
27 | uniform vec3 eye;
28 | uniform vec3 ray00;
29 | uniform vec3 ray01;
30 | uniform vec3 ray10;
31 | uniform vec3 ray11;
32 |
33 | struct box
34 | {
35 | vec3 min;
36 | vec3 max;
37 | };
38 |
39 | struct hitinfo
40 | {
41 | vec2 lambda;
42 | int bi;
43 | };
44 |
45 | #define MAX_SCENE_BOUNDS 1000.0
46 | #define NUM_BOXES 2
47 |
48 | // We would like to use an initialization list, but as of Q2 2015 only Nvidia seemingly supports this properly.
49 |
50 | // const box boxes[NUM_BOXES] =
51 | // {
52 | // /* The ground */
53 | // { vec3(-5.0, -0.1, -5.0), vec3(5.0, 0.0, 5.0) },
54 | //
55 | // /* Box in the middle */
56 | // { vec3(-0.5, 0.0, -0.5), vec3(0.5, 1.0, 0.5) },
57 | //};
58 |
59 | // For some reason the Mali-T760 in the Galaxy S6 doesn't like the standard definition and fails.
60 | const box boxes[2] = box[2](
61 | box(vec3(-5.0, -0.1, -5.0), vec3(5.0, 0.0, 5.0)),
62 | box(vec3(-0.5, 0.0, -0.5), vec3(0.5, 1.0, 0.5))
63 | );
64 |
65 | vec2 intersectBox(vec3 origin, vec3 dir, const box b)
66 | {
67 | vec3 tMin = (b.min - origin) / dir;
68 | vec3 tMax = (b.max - origin) / dir;
69 | vec3 t1 = min(tMin, tMax);
70 | vec3 t2 = max(tMin, tMax);
71 | float tNear = max(max(t1.x, t1.y), t1.z);
72 | float tFar = min(min(t2.x, t2.y), t2.z);
73 | return vec2(tNear, tFar);
74 | }
75 |
76 | bool intersectBoxes(vec3 origin, vec3 dir, out hitinfo info)
77 | {
78 | float smallest = MAX_SCENE_BOUNDS;
79 | bool found = false;
80 |
81 | for (int i = 0; i < NUM_BOXES; i++)
82 | {
83 | vec2 lambda = intersectBox(origin, dir, boxes[i]);
84 |
85 | if (lambda.x > 0.0 && lambda.x < lambda.y && lambda.x < smallest)
86 | {
87 | info.lambda = lambda;
88 | info.bi = i;
89 | smallest = lambda.x;
90 | found = true;
91 | }
92 | }
93 |
94 | return found;
95 | }
96 |
97 | vec4 trace(vec3 origin, vec3 dir)
98 | {
99 | hitinfo i;
100 |
101 | if (intersectBoxes(origin, dir, i))
102 | {
103 | vec4 gray = vec4(float(i.bi) / 10.0 + 0.8);
104 | return vec4(gray.rgb, 1.0);
105 | }
106 |
107 | return vec4(0.0, 0.0, 0.0, 1.0);
108 | }
109 |
110 | layout (local_size_x = LOCAL_SIZE, local_size_y = LOCAL_SIZE) in;
111 | void main(void)
112 | {
113 | ivec2 pix = ivec2(gl_GlobalInvocationID.xy);
114 | ivec2 size = imageSize(framebuffer);
115 |
116 | if (pix.x >= size.x || pix.y >= size.y)
117 | {
118 | return;
119 | }
120 |
121 | vec2 pos = vec2(pix) / vec2(size.x, size.y);
122 |
123 | vec3 dir = mix(mix(ray00, ray01, pos.y), mix(ray10, ray11, pos.y), pos.x);
124 |
125 | vec4 color = trace(eye, dir);
126 |
127 | imageStore(framebuffer, pix, color);
128 | }
129 |
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/java/org/typhonrt/android/java6/gldemo/GLDemoActivity.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015 Michael Leahy / TyphonRT, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.typhonrt.android.java6.gldemo;
17 |
18 | import android.app.AlertDialog;
19 | import android.content.DialogInterface;
20 | import android.content.Intent;
21 | import android.content.res.Resources;
22 | import android.net.Uri;
23 | import android.os.Bundle;
24 | import android.support.v7.app.ActionBarActivity;
25 | import android.support.v7.widget.Toolbar;
26 | import android.view.View;
27 | import android.widget.AdapterView;
28 | import android.widget.ListView;
29 |
30 | import org.typhonrt.android.java6.gldemo.gles30.effects.GLSLInvert;
31 | import org.typhonrt.android.java6.gldemo.gles30.effects.GLSLKuwahara;
32 | import org.typhonrt.android.java6.gldemo.gles30.effects.GLSLKuwaharaFBO;
33 | import org.typhonrt.commons.java6.opengl.utils.*;
34 |
35 | import org.typhonrt.android.java6.gldemo.gles31.invert.*;
36 | import org.typhonrt.android.java6.gldemo.gles31.raytrace.basic.ComputeBasicRayTrace;
37 |
38 | import org.typhonrt.android.java6.opengl.utils.AndroidGLESUtil;
39 |
40 | /**
41 | * GLDemoActivity - Provides a ListView to select OpenGL demo. Warns user if the device GL version is lower than
42 | * the required version from the given GL demo selected.
43 | */
44 | public class GLDemoActivity extends ActionBarActivity implements AdapterView.OnItemClickListener,
45 | AdapterView.OnItemLongClickListener
46 | {
47 | public static final int s_UI_OPTIONS = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
48 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
49 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
50 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
51 | | View.SYSTEM_UI_FLAG_FULLSCREEN
52 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
53 |
54 | private GLHeaderAdapter adapter;
55 |
56 | private IGLVersion deviceGLVersion;
57 |
58 | protected void onCreate(Bundle savedInstanceState)
59 | {
60 | super.onCreate(savedInstanceState);
61 |
62 | setContentView(R.layout.list_activity_layout);
63 |
64 | Resources resources = getResources();
65 |
66 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
67 | toolbar.setLogo(R.drawable.ic_launcher);
68 | toolbar.setTitle(R.string.app_title);
69 | toolbar.setContentInsetsAbsolute(0, 0);
70 |
71 | setSupportActionBar(toolbar);
72 |
73 | deviceGLVersion = AndroidGLESUtil.getGLVersion(this);
74 |
75 | adapter = new GLHeaderAdapter(this);
76 |
77 | adapter.addSectionHeaderItem(resources.getString(R.string.header_gles_3_0));
78 |
79 | adapter.addItem(GLSLInvert.class, XeGLES3.GLES3_0,
80 | "https://github.com/typhonrt/modern-java6-android-gldemos/wiki/gles30demo-glslinvert");
81 |
82 | adapter.addItem(GLSLKuwahara.class, XeGLES3.GLES3_0,
83 | "https://github.com/typhonrt/modern-java6-android-gldemos/wiki/gles30demo-glslkuwahara");
84 |
85 | adapter.addItem(GLSLKuwaharaFBO.class, XeGLES3.GLES3_0,
86 | "https://github.com/typhonrt/modern-java6-android-gldemos/wiki/gles30demo-glslkuwaharafbo");
87 |
88 | adapter.addSectionHeaderItem(resources.getString(R.string.header_gles_3_1));
89 |
90 | adapter.addItem(ComputeBasicRayTrace.class, XeGLES3.GLES3_1,
91 | "https://github.com/typhonrt/modern-java6-android-gldemos/wiki/gles31demo-computebasicraytrace");
92 |
93 | adapter.addItem(ComputeInvert.class, XeGLES3.GLES3_1,
94 | "https://github.com/typhonrt/modern-java6-android-gldemos/wiki/gles31demo-computeinvert");
95 |
96 | adapter.addItem(ComputeInvertSampler.class, XeGLES3.GLES3_1,
97 | "https://github.com/typhonrt/modern-java6-android-gldemos/wiki/gles31demo-computeinvertsampler");
98 |
99 | ListView listView = (ListView)findViewById(R.id.main_listview);
100 |
101 | listView.setAdapter(adapter);
102 | listView.setOnItemClickListener(this);
103 | listView.setOnItemLongClickListener(this);
104 | }
105 |
106 | /**
107 | * Handles setting immersive sticky when the window is focused. Necessary when an Activity is minimized and
108 | * brought back to front.
109 | *
110 | * @param hasFocus
111 | */
112 | @Override
113 | public void onWindowFocusChanged(boolean hasFocus)
114 | {
115 | super.onWindowFocusChanged(hasFocus);
116 |
117 | if (hasFocus)
118 | {
119 | getWindow().getDecorView().setSystemUiVisibility(s_UI_OPTIONS);
120 | }
121 | }
122 |
123 | // OnItemClickedListener Implementation -----------------------------------------------------------------------------
124 |
125 | @Override
126 | public void onItemClick(AdapterView> parent, View view, int position, long id)
127 | {
128 | if (GLHeaderAdapter.s_TYPE_ITEM == adapter.getItemViewType(position))
129 | {
130 | final Intent intent = new Intent(this, adapter.getItem(position));
131 |
132 | IGLVersion demoGLVersion = adapter.getGLVersion(position);
133 |
134 | if (!deviceGLVersion.lessThan(demoGLVersion))
135 | {
136 | startActivity(intent);
137 | }
138 | else
139 | {
140 | AlertDialog.Builder builder = new AlertDialog.Builder(this);
141 |
142 | builder.setIcon(android.R.drawable.ic_dialog_alert);
143 |
144 | builder.setMessage(R.string.dialog_message).setTitle(R.string.dialog_title);
145 |
146 | builder.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener()
147 | {
148 | public void onClick(DialogInterface dialog, int id)
149 | {
150 | startActivity(intent);
151 | }
152 | });
153 |
154 | builder.setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener()
155 | {
156 | public void onClick(DialogInterface dialog, int id) {}
157 | });
158 |
159 | builder.create().show();
160 | }
161 | }
162 | }
163 |
164 | // OnItemLongClickListener Implementation ---------------------------------------------------------------------------
165 |
166 | @Override
167 | public boolean onItemLongClick(AdapterView> parent, View view, int position, long id)
168 | {
169 | if (GLHeaderAdapter.s_TYPE_ITEM == adapter.getItemViewType(position))
170 | {
171 | String webLink = adapter.getWebLink(position);
172 |
173 | if (webLink != null)
174 | {
175 | Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(webLink));
176 | startActivity(i);
177 | }
178 | }
179 |
180 | return true;
181 | }
182 | }
183 |
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/java/org/typhonrt/android/java6/gldemo/GLHeaderAdapter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015 Michael Leahy / TyphonRT, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.typhonrt.android.java6.gldemo;
17 |
18 | import java.util.ArrayList;
19 | import java.util.HashMap;
20 | import java.util.TreeMap;
21 |
22 | import android.content.Context;
23 | import android.graphics.Color;
24 | import android.view.LayoutInflater;
25 | import android.view.View;
26 | import android.view.ViewGroup;
27 | import android.widget.BaseAdapter;
28 | import android.widget.TextView;
29 |
30 | import org.typhonrt.android.java6.opengl.utils.AndroidGLESUtil;
31 |
32 | import org.typhonrt.commons.java6.opengl.utils.IGLVersion;
33 |
34 | /**
35 | * GLHeaderAdapter -- Provides a custom adapter that colors items red if the required OpenGL version for a demo
36 | * does not match the supported version of a given device.
37 | */
38 | public class GLHeaderAdapter extends BaseAdapter
39 | {
40 | public static final int s_TYPE_ITEM = 0;
41 | public static final int s_TYPE_SEPARATOR = 1;
42 |
43 | private ArrayList data = new ArrayList();
44 | private TreeMap sectionHeader = new TreeMap();
45 | private HashMap glVersionMap = new HashMap();
46 | private HashMap webLinkMap = new HashMap();
47 |
48 | private IGLVersion deviceGLVersion;
49 |
50 | private LayoutInflater inflater;
51 |
52 | public GLHeaderAdapter(Context context)
53 | {
54 | inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
55 |
56 | deviceGLVersion = AndroidGLESUtil.getGLVersion(context);
57 | }
58 |
59 | public void addItem(final Class item, final IGLVersion glVersion, final String webLink)
60 | {
61 | data.add(item);
62 | glVersionMap.put(item, glVersion);
63 | webLinkMap.put(item, webLink);
64 | notifyDataSetChanged();
65 | }
66 |
67 | public void addSectionHeaderItem(final String item)
68 | {
69 | data.add(String.class);
70 | sectionHeader.put(data.size() - 1, item);
71 | notifyDataSetChanged();
72 | }
73 |
74 | public IGLVersion getGLVersion(int position)
75 | {
76 | Class clazz = data.get(position);
77 | return glVersionMap.get(clazz);
78 | }
79 |
80 | public String getWebLink(int position)
81 | {
82 | Class clazz = data.get(position);
83 | return webLinkMap.get(clazz);
84 | }
85 |
86 | @Override
87 | public int getItemViewType(int position)
88 | {
89 | return sectionHeader.containsKey(position) ? s_TYPE_SEPARATOR : s_TYPE_ITEM;
90 | }
91 |
92 | @Override
93 | public int getViewTypeCount()
94 | {
95 | return 2;
96 | }
97 |
98 | @Override
99 | public int getCount()
100 | {
101 | return data.size();
102 | }
103 |
104 | @Override
105 | public Class getItem(int position)
106 | {
107 | return data.get(position);
108 | }
109 |
110 | @Override
111 | public long getItemId(int position)
112 | {
113 | return position;
114 | }
115 |
116 | public View getView(int position, View convertView, ViewGroup parent)
117 | {
118 | ViewHolder holder;
119 | int rowType = getItemViewType(position);
120 |
121 | if (convertView == null)
122 | {
123 | holder = new ViewHolder();
124 | switch (rowType)
125 | {
126 | case s_TYPE_ITEM:
127 | convertView = inflater.inflate(R.layout.listview_text, null);
128 | holder.textView = (TextView) convertView.findViewById(R.id.text);
129 | break;
130 | case s_TYPE_SEPARATOR:
131 | convertView = inflater.inflate(R.layout.listview_section, null);
132 | holder.textView = (TextView) convertView.findViewById(R.id.textSeparator);
133 | break;
134 | }
135 | convertView.setTag(holder);
136 | }
137 | else
138 | {
139 | holder = (ViewHolder) convertView.getTag();
140 | }
141 |
142 | String text = null;
143 | int textColor = Color.WHITE;
144 |
145 | switch (rowType)
146 | {
147 | case s_TYPE_ITEM:
148 | Class clazz = data.get(position);
149 | text = clazz.getSimpleName();
150 | IGLVersion glVersion = glVersionMap.get(clazz);
151 | if (glVersion != null)
152 | {
153 | textColor = deviceGLVersion.lessThan(glVersion) ? Color.RED : Color.WHITE;
154 | }
155 | break;
156 | case s_TYPE_SEPARATOR:
157 | text = sectionHeader.get(position);
158 | break;
159 | }
160 |
161 | holder.textView.setText(text);
162 | holder.textView.setTextColor(textColor);
163 |
164 | return convertView;
165 | }
166 |
167 | public static class ViewHolder
168 | {
169 | public TextView textView;
170 | }
171 | }
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/java/org/typhonrt/android/java6/gldemo/gles30/effects/GLSLInvert.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015 Michael Leahy / TyphonRT, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.typhonrt.android.java6.gldemo.gles30.effects;
17 |
18 | import android.content.res.Resources;
19 | import android.os.Bundle;
20 |
21 | import org.typhonrt.android.java6.gldemo.shared.BaseDemoActivity;
22 |
23 | import org.typhonrt.android.java6.opengl.utils.AndroidGLES30Util;
24 | import org.typhonrt.android.java6.opengl.utils.GLBufferUtil;
25 |
26 | import org.typhonrt.android.java6.data.option.model.OptionModel;
27 |
28 | import org.typhonrt.android.java6.gldemo.R;
29 |
30 |
31 | import static android.opengl.GLES30.*;
32 |
33 | public class GLSLInvert extends BaseDemoActivity
34 | {
35 | private static final String s_VERT_SHADER_FILE = "shaders/gles30/common/directTexture.vert";
36 | private static final String s_FRAG_SHADER_FILE = "shaders/gles30/color/invertTexture.frag";
37 |
38 | private static final String s_STR_INTENSITY = "intensity";
39 |
40 | private int shaderProgram;
41 |
42 | private OptionModel invertEnabled = new OptionModel("Invert", false);
43 |
44 | protected void onCreate(Bundle savedInstanceState)
45 | {
46 | super.onCreate(savedInstanceState);
47 |
48 | drawerControl.setOptionModels(new OptionModel[]{invertEnabled});
49 | }
50 |
51 | public void onGLDrawFrame()
52 | {
53 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
54 |
55 | if (drawerControl.isOptionModelDirty())
56 | {
57 | glUniform1f(glGetUniformLocation(shaderProgram, s_STR_INTENSITY), invertEnabled.getBooleanValue() ? 1f : 0f);
58 | }
59 |
60 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
61 | }
62 |
63 | public void onGLSurfaceChanged(int width, int height)
64 | {
65 | glViewport(0, 0, width, height);
66 |
67 | // Setup a VBO (Vertex Buffer Object)
68 | // Note: A VBO is created and binded for the rest of the runtime, so we don't hold onto a GLBuffer reference.
69 | // Quad (vertex + u/v); height / width provides aspect ratio
70 | GLBufferUtil.createQuadVertexUVBuffer((float) height / (float) width).bind();
71 |
72 | glVertexAttribPointer(glGetAttribLocation(shaderProgram, "inPosition"), 3, GL_FLOAT, false,
73 | GLBufferUtil.s_QUAD_BUFFER_STRIDE, 0);
74 |
75 | glVertexAttribPointer(glGetAttribLocation(shaderProgram, "aTexCoord"), 2, GL_FLOAT, false,
76 | GLBufferUtil.s_QUAD_BUFFER_STRIDE, GLBufferUtil.s_QUAD_UV_OFFSET);
77 | }
78 |
79 | public void onGLSurfaceCreated()
80 | {
81 | // Sets the color rendered by glClear
82 | glClearColor(0.2f, 0.0f, 0.2f, 1.0f); // Set background to dark purple
83 |
84 | Resources resources = getResources();
85 |
86 | // Create shader program
87 | shaderProgram = AndroidGLES30Util.buildProgramFromAssets(resources, s_VERT_SHADER_FILE, s_FRAG_SHADER_FILE);
88 |
89 | // Load texture from R.drawable.flower1024 (flip due to GL coordinates)
90 | int textureID = AndroidGLES30Util.loadTexture(resources, R.drawable.flower1024, GL_RGBA8, true);
91 |
92 | glUseProgram(shaderProgram);
93 |
94 | // Bind texture to texture unit 0
95 | glActiveTexture(GL_TEXTURE0);
96 | glBindTexture(GL_TEXTURE_2D, textureID);
97 |
98 | // Set sampler2d in GLSL fragment shader to texture unit 0
99 | glUniform1i(glGetUniformLocation(shaderProgram, "uSourceTex"), 0);
100 |
101 | glEnableVertexAttribArray(0);
102 | glEnableVertexAttribArray(1);
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/java/org/typhonrt/android/java6/gldemo/gles30/effects/GLSLKuwahara.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015 Michael Leahy / TyphonRT, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.typhonrt.android.java6.gldemo.gles30.effects;
17 |
18 | import android.content.res.Resources;
19 | import android.os.Bundle;
20 |
21 |
22 | import org.typhonrt.android.java6.gldemo.shared.BaseDemoActivity;
23 |
24 | import org.typhonrt.android.java6.opengl.utils.AndroidGLES30Util;
25 | import org.typhonrt.android.java6.opengl.utils.GLBufferUtil;
26 |
27 | import org.typhonrt.android.java6.data.option.model.OptionModel;
28 |
29 | import org.typhonrt.android.java6.gldemo.R;
30 |
31 |
32 | import static android.opengl.GLES30.*;
33 |
34 | public class GLSLKuwahara extends BaseDemoActivity
35 | {
36 | private static final String s_VERT_SHADER_FILE = "shaders/gles30/common/directTexture.vert";
37 | private static final String s_FRAG_DIRECT_SHADER_FILE = "shaders/gles30/common/directTexture.frag";
38 | private static final String s_FRAG_KUWAHARA_SHADER_FILE = "shaders/gles30/effects/kuwaharaOptimized.frag";
39 |
40 | private static final String s_STR_SAMPLE_STEP = "sampleStep";
41 |
42 | private int directProgramID, kuwaharaProgramID;
43 |
44 | private OptionModel kuwaharaEnabled = new OptionModel("Enable", false);
45 | private OptionModel kuwaharaSampleStep = new OptionModel("Sample Step", 0, 1f / 1024f, 1f / 64f);
46 |
47 | protected void onCreate(Bundle savedInstanceState)
48 | {
49 | super.onCreate(savedInstanceState);
50 |
51 | drawerControl.setOptionModels(new OptionModel[]{ kuwaharaEnabled, kuwaharaSampleStep});
52 | }
53 |
54 | public void onGLDrawFrame()
55 | {
56 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
57 |
58 | if (drawerControl.isOptionModelDirty())
59 | {
60 | glUseProgram(kuwaharaEnabled.getBooleanValue() ? kuwaharaProgramID : directProgramID);
61 |
62 | float sampleStep = kuwaharaSampleStep.getFloatValue();
63 |
64 | glUniform2f(glGetUniformLocation(kuwaharaProgramID, s_STR_SAMPLE_STEP), sampleStep, sampleStep);
65 | }
66 |
67 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
68 | }
69 |
70 | public void onGLSurfaceChanged(int width, int height)
71 | {
72 | glViewport(0, 0, width, height);
73 |
74 | // Setup a VBO (Vertex Buffer Object)
75 | // Note: A VBO is created and binded for the rest of the runtime, so we don't hold onto a GLBuffer reference.
76 | // Quad (vertex + u/v); height / width provides aspect ratio
77 | GLBufferUtil.createQuadVertexUVBuffer((float) height / (float) width).bind();
78 |
79 | glUseProgram(kuwaharaProgramID);
80 |
81 | glVertexAttribPointer(glGetAttribLocation(directProgramID, "inPosition"), 3, GL_FLOAT, false,
82 | GLBufferUtil.s_QUAD_BUFFER_STRIDE, 0);
83 |
84 | glVertexAttribPointer(glGetAttribLocation(directProgramID, "aTexCoord"), 2, GL_FLOAT, false,
85 | GLBufferUtil.s_QUAD_BUFFER_STRIDE, GLBufferUtil.s_QUAD_UV_OFFSET);
86 |
87 | glUseProgram(directProgramID);
88 |
89 | glVertexAttribPointer(glGetAttribLocation(directProgramID, "inPosition"), 3, GL_FLOAT, false,
90 | GLBufferUtil.s_QUAD_BUFFER_STRIDE, 0);
91 |
92 | glVertexAttribPointer(glGetAttribLocation(directProgramID, "aTexCoord"), 2, GL_FLOAT, false,
93 | GLBufferUtil.s_QUAD_BUFFER_STRIDE, GLBufferUtil.s_QUAD_UV_OFFSET);
94 | }
95 |
96 | public void onGLSurfaceCreated()
97 | {
98 | // Sets the color rendered by glClear
99 | glClearColor(0.2f, 0.0f, 0.2f, 1.0f); // Set background to dark purple
100 |
101 | Resources resources = getResources();
102 |
103 | // Load texture from R.drawable.flower1024 (flip due to GL coordinates)
104 | int textureID = AndroidGLES30Util.loadTexture(resources, R.drawable.flower1024, GL_RGBA8, true);
105 |
106 | // Bind texture to texture unit 0
107 | glActiveTexture(GL_TEXTURE0);
108 | glBindTexture(GL_TEXTURE_2D, textureID);
109 |
110 | glEnableVertexAttribArray(0);
111 | glEnableVertexAttribArray(1);
112 |
113 | // Create shader program
114 | directProgramID = AndroidGLES30Util.buildProgramFromAssets(resources, s_VERT_SHADER_FILE,
115 | s_FRAG_DIRECT_SHADER_FILE);
116 |
117 | glUseProgram(directProgramID);
118 |
119 | // Set sampler2d in GLSL fragment shader to texture unit 0
120 | glUniform1i(glGetUniformLocation(directProgramID, "uSourceTex"), 0);
121 |
122 |
123 | // Create shader program
124 | kuwaharaProgramID = AndroidGLES30Util.buildProgramFromAssets(resources, s_VERT_SHADER_FILE,
125 | s_FRAG_KUWAHARA_SHADER_FILE);
126 |
127 | glUseProgram(kuwaharaProgramID);
128 |
129 | // Set sampler2d in GLSL fragment shader to texture unit 0
130 | glUniform1i(glGetUniformLocation(kuwaharaProgramID, "uSourceTex"), 0);
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/java/org/typhonrt/android/java6/gldemo/gles30/effects/GLSLKuwaharaFBO.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015 Michael Leahy / TyphonRT, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.typhonrt.android.java6.gldemo.gles30.effects;
17 |
18 | import android.content.res.Resources;
19 | import android.os.Bundle;
20 |
21 | import org.typhonrt.commons.java6.opengl.utils.FBOData;
22 |
23 | import org.typhonrt.android.java6.gldemo.shared.BaseDemoActivity;
24 |
25 | import org.typhonrt.android.java6.opengl.utils.AndroidGLES30Util;
26 | import org.typhonrt.android.java6.opengl.utils.FBOUtil;
27 | import org.typhonrt.android.java6.opengl.utils.GLBuffer;
28 | import org.typhonrt.android.java6.opengl.utils.GLBufferUtil;
29 |
30 | import org.typhonrt.android.java6.data.option.model.OptionModel;
31 |
32 | import org.typhonrt.android.java6.gldemo.R;
33 |
34 |
35 | import static android.opengl.GLES30.*;
36 |
37 | public class GLSLKuwaharaFBO extends BaseDemoActivity
38 | {
39 | private static final String s_VERT_SHADER_FILE = "shaders/gles30/common/directTexture.vert";
40 | private static final String s_FRAG_DIRECT_SHADER_FILE = "shaders/gles30/common/directTexture.frag";
41 | private static final String s_FRAG_KUWAHARA_SHADER_FILE = "shaders/gles30/effects/kuwaharaOptimized.frag";
42 |
43 | private static final String s_STR_ATTR_TEX_COORD = "aTexCoord";
44 | private static final String s_STR_SAMPLE_STEP = "sampleStep";
45 | private static final String s_STR_IN_POSITION = "inPosition";
46 |
47 | private int directProgramID, kuwaharaProgramID;
48 |
49 | private int textureID;
50 |
51 | private int surfaceWidth, surfaceHeight;
52 |
53 | private FBOData frameBufferObject;
54 |
55 | private GLBuffer squareBuffer, widthAdjustedBuffer;
56 |
57 | private OptionModel kuwaharaEnabled = new OptionModel("Enable", false);
58 | private OptionModel kuwaharaSampleStep = new OptionModel("Sample Step", 0, 1f / 1024f, 1f / 64f);
59 |
60 | protected void onCreate(Bundle savedInstanceState)
61 | {
62 | super.onCreate(savedInstanceState);
63 |
64 | drawerControl.setOptionModels(new OptionModel[]{ kuwaharaEnabled, kuwaharaSampleStep});
65 | }
66 |
67 | public void onGLDrawFrame()
68 | {
69 | if (kuwaharaEnabled.getBooleanValue())
70 | {
71 | glUseProgram(kuwaharaProgramID);
72 |
73 | if (drawerControl.isOptionModelDirty())
74 | {
75 | float sampleStep = kuwaharaSampleStep.getFloatValue();
76 | glUniform2f(glGetUniformLocation(kuwaharaProgramID, s_STR_SAMPLE_STEP), sampleStep, sampleStep);
77 | }
78 | }
79 | else
80 | {
81 | glUseProgram(directProgramID);
82 | }
83 |
84 | // Bind texture to texture unit 0
85 | glActiveTexture(GL_TEXTURE0);
86 | glBindTexture(GL_TEXTURE_2D, textureID);
87 |
88 | FBOUtil.makeCurrentAndClear(frameBufferObject);
89 |
90 | glViewport(0, 0, 1024, 1024);
91 |
92 | squareBuffer.bind();
93 |
94 | glVertexAttribPointer(glGetAttribLocation(kuwaharaProgramID, s_STR_IN_POSITION), 3, GL_FLOAT, false,
95 | GLBufferUtil.s_QUAD_BUFFER_STRIDE, 0);
96 |
97 | glVertexAttribPointer(glGetAttribLocation(kuwaharaProgramID, s_STR_ATTR_TEX_COORD), 2, GL_FLOAT, false,
98 | GLBufferUtil.s_QUAD_BUFFER_STRIDE, GLBufferUtil.s_QUAD_UV_OFFSET);
99 |
100 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
101 |
102 | FBOUtil.releaseAsRenderTarget();
103 |
104 | squareBuffer.unbind();
105 |
106 | glViewport(0, 0, surfaceWidth, surfaceHeight);
107 |
108 | glClearColor(0.2f, 0.0f, 0.2f, 1.0f); // Set background to dark purple
109 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
110 |
111 | glActiveTexture(GL_TEXTURE0);
112 | glBindTexture(GL_TEXTURE_2D, frameBufferObject.textureID);
113 |
114 | glUseProgram(directProgramID);
115 |
116 | widthAdjustedBuffer.bind();
117 |
118 | glVertexAttribPointer(glGetAttribLocation(directProgramID, s_STR_IN_POSITION), 3, GL_FLOAT, false,
119 | GLBufferUtil.s_QUAD_BUFFER_STRIDE, 0);
120 |
121 | glVertexAttribPointer(glGetAttribLocation(directProgramID, s_STR_ATTR_TEX_COORD), 2, GL_FLOAT, false,
122 | GLBufferUtil.s_QUAD_BUFFER_STRIDE, GLBufferUtil.s_QUAD_UV_OFFSET);
123 |
124 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
125 |
126 | widthAdjustedBuffer.unbind();
127 | }
128 |
129 | public void onGLSurfaceChanged(int width, int height)
130 | {
131 | surfaceWidth = width;
132 | surfaceHeight = height;
133 |
134 | glViewport(0, 0, surfaceWidth, surfaceHeight);
135 |
136 | // Setup a VBO (Vertex Buffer Object)
137 | squareBuffer = GLBufferUtil.createQuadVertexUVBuffer(1);
138 |
139 | // Quad (vertex + u/v); height / width provides aspect ratio
140 | widthAdjustedBuffer = GLBufferUtil.createQuadVertexUVBuffer((float) height / (float) width);
141 | }
142 |
143 | public void onGLSurfaceCreated()
144 | {
145 | // Sets the color rendered by glClear
146 | glClearColor(0.2f, 0.0f, 0.2f, 1.0f); // Set background to dark purple
147 |
148 | Resources resources = getResources();
149 |
150 | frameBufferObject = FBOUtil.initialize(new FBOData(), 1024, 1024);
151 |
152 | // Load texture from R.drawable.flower1024 (flip due to GL coordinates)
153 | textureID = AndroidGLES30Util.loadTexture(resources, R.drawable.flower1024, GL_RGBA8, true);
154 |
155 | // Bind texture to texture unit 0
156 | glActiveTexture(GL_TEXTURE0);
157 | glBindTexture(GL_TEXTURE_2D, textureID);
158 |
159 | glEnableVertexAttribArray(0);
160 | glEnableVertexAttribArray(1);
161 |
162 | // Create shader program
163 | directProgramID = AndroidGLES30Util.buildProgramFromAssets(resources, s_VERT_SHADER_FILE,
164 | s_FRAG_DIRECT_SHADER_FILE);
165 |
166 | glUseProgram(directProgramID);
167 |
168 | // Set sampler2d in GLSL fragment shader to texture unit 0
169 | glUniform1i(glGetUniformLocation(directProgramID, "uSourceTex"), 0);
170 |
171 |
172 | // Create shader program
173 | kuwaharaProgramID = AndroidGLES30Util.buildProgramFromAssets(resources, s_VERT_SHADER_FILE,
174 | s_FRAG_KUWAHARA_SHADER_FILE);
175 |
176 | glUseProgram(kuwaharaProgramID);
177 |
178 | // Set sampler2d in GLSL fragment shader to texture unit 0
179 | glUniform1i(glGetUniformLocation(kuwaharaProgramID, "uSourceTex"), 0);
180 | }
181 | }
182 |
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/java/org/typhonrt/android/java6/gldemo/gles31/invert/ComputeInvert.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015 Michael Leahy / TyphonRT, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.typhonrt.android.java6.gldemo.gles31.invert;
17 |
18 | import android.content.res.Resources;
19 | import android.os.Bundle;
20 |
21 |
22 | import org.typhonrt.android.java6.gldemo.shared.BaseDemoActivity;
23 |
24 | import org.typhonrt.android.java6.opengl.utils.AndroidGLES31Util;
25 | import org.typhonrt.android.java6.opengl.utils.GLBufferUtil;
26 | import org.typhonrt.commons.java6.opengl.utils.XeGLES3;
27 |
28 | import org.typhonrt.android.java6.data.option.model.OptionModel;
29 |
30 | import org.typhonrt.android.java6.gldemo.R;
31 |
32 |
33 | import static android.opengl.GLES31.*;
34 |
35 | public class ComputeInvert extends BaseDemoActivity
36 | {
37 | private static final String s_VERT_SHADER_FILE = "shaders/gles30/common/directTexture.vert";
38 | private static final String s_FRAG_SHADER_FILE = "shaders/gles30/common/directTexture.frag";
39 |
40 | private static final String s_COMP_SHADER_FILE = "shaders/gles31/color/invertTexture.comp";
41 |
42 | private static final String S_COMP_SHADER_HEADER = "#version 310 es\n#define LOCAL_SIZE %d\n";
43 |
44 | private int workgroupSize;
45 |
46 | private int directProgramID, computeProgramID;
47 | private int sourceTextureID, resultTextureID;
48 |
49 | private OptionModel invertEnabled = new OptionModel("Invert", false);
50 |
51 | public ComputeInvert()
52 | {
53 | super(XeGLES3.GLES3_1); // Require OpenGL ES 3.1 context
54 | }
55 |
56 | protected void onCreate(Bundle savedInstanceState)
57 | {
58 | super.onCreate(savedInstanceState);
59 |
60 | drawerControl.setOptionModels(new OptionModel[]{invertEnabled});
61 | }
62 |
63 | public void onGLDrawFrame()
64 | {
65 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
66 |
67 | if (invertEnabled.getBooleanValue())
68 | {
69 | runComputeFilter(sourceTextureID, resultTextureID, 1024, 1024);
70 | drawTexture(resultTextureID);
71 | }
72 | else
73 | {
74 | drawTexture(sourceTextureID);
75 | }
76 | }
77 |
78 | private void drawTexture(int textureID)
79 | {
80 | glUseProgram(directProgramID);
81 |
82 | glActiveTexture(GL_TEXTURE0);
83 | glBindTexture(GL_TEXTURE_2D, textureID);
84 |
85 | glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, 1);
86 | }
87 |
88 | private void runComputeFilter(int sourceTextureID, int resultTextureID, int width, int height)
89 | {
90 | glUseProgram(computeProgramID);
91 |
92 | glBindImageTexture(0, sourceTextureID, 0, false, 0, GL_READ_ONLY, GL_RGBA8);
93 | glBindImageTexture(1, resultTextureID, 0, false, 0, GL_WRITE_ONLY, GL_RGBA8);
94 |
95 | glDispatchCompute(width / workgroupSize, height / workgroupSize, 1);
96 |
97 | // GL_COMPUTE_SHADER_BIT is the same as GL_SHADER_IMAGE_ACCESS_BARRIER_BIT
98 | glMemoryBarrier(GL_COMPUTE_SHADER_BIT);
99 | }
100 |
101 |
102 | public void onGLSurfaceChanged(int width, int height)
103 | {
104 | glViewport(0, 0, width, height);
105 |
106 | // Setup a VBO (Vertex Buffer Object)
107 | // Note: A VBO is created and binded for the rest of the runtime, so we don't hold onto a GLBuffer reference.
108 | // Quad (vertex + u/v); height / width provides aspect ratio when width is wider than height
109 | GLBufferUtil.createQuadVertexUVBuffer((float) height / (float) width).bind();
110 |
111 | glVertexAttribPointer(glGetAttribLocation(directProgramID, "inPosition"), 3, GL_FLOAT, false,
112 | GLBufferUtil.s_QUAD_BUFFER_STRIDE, 0);
113 |
114 | glVertexAttribPointer(glGetAttribLocation(directProgramID, "aTexCoord"), 2, GL_FLOAT, false,
115 | GLBufferUtil.s_QUAD_BUFFER_STRIDE, GLBufferUtil.s_QUAD_UV_OFFSET);
116 | }
117 |
118 | public void onGLSurfaceCreated()
119 | {
120 | // Sets the color rendered by glClear
121 | glClearColor(0.2f, 0.0f, 0.2f, 1.0f); // Set background to dark purple
122 |
123 | Resources resources = getResources();
124 |
125 | workgroupSize = AndroidGLES31Util.getMaxComputePowerWorkGroupSize(2);
126 |
127 | // Create shader programs
128 | directProgramID = AndroidGLES31Util.buildProgramFromAssets(resources, s_VERT_SHADER_FILE, s_FRAG_SHADER_FILE);
129 | computeProgramID = AndroidGLES31Util.buildProgramFromAssets(resources, s_COMP_SHADER_FILE, GL_COMPUTE_SHADER,
130 | String.format(S_COMP_SHADER_HEADER, workgroupSize));
131 |
132 | // Load texture from R.drawable.flower1024 (flip due to GL coordinates)
133 | sourceTextureID = AndroidGLES31Util.loadTexture(resources, R.drawable.flower1024, GL_RGBA8, true);
134 |
135 | resultTextureID = AndroidGLES31Util.createTexture(GL_RGBA8, 1024, 1024);
136 |
137 | glUseProgram(directProgramID);
138 |
139 | // Bind texture to texture unit 0
140 | glActiveTexture(GL_TEXTURE0);
141 | glBindTexture(GL_TEXTURE_2D, sourceTextureID);
142 |
143 | // Set sampler2d in GLSL fragment shader to texture unit 0
144 | glUniform1i(glGetUniformLocation(directProgramID, "uSourceTex"), 0);
145 |
146 | glEnableVertexAttribArray(0);
147 | glEnableVertexAttribArray(1);
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/java/org/typhonrt/android/java6/gldemo/gles31/invert/ComputeInvertSampler.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015 Michael Leahy / TyphonRT, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.typhonrt.android.java6.gldemo.gles31.invert;
17 |
18 | import android.content.res.Resources;
19 | import android.os.Bundle;
20 |
21 | import org.typhonrt.android.java6.gldemo.shared.BaseDemoActivity;
22 |
23 | import org.typhonrt.android.java6.opengl.utils.AndroidGLES31Util;
24 | import org.typhonrt.android.java6.opengl.utils.GLBufferUtil;
25 | import org.typhonrt.commons.java6.opengl.utils.XeGLES3;
26 |
27 | import org.typhonrt.android.java6.data.option.model.OptionModel;
28 |
29 | import org.typhonrt.android.java6.gldemo.R;
30 |
31 |
32 | import static android.opengl.GLES31.*;
33 |
34 | public class ComputeInvertSampler extends BaseDemoActivity
35 | {
36 | private static final String s_VERT_SHADER_FILE = "shaders/gles30/common/directTexture.vert";
37 | private static final String s_FRAG_SHADER_FILE = "shaders/gles30/common/directTexture.frag";
38 |
39 | private static final String s_COMP_SHADER_FILE = "shaders/gles31/color/invertTextureSampler.comp";
40 |
41 | private static final String S_COMP_SHADER_HEADER = "#version 310 es\n#define LOCAL_SIZE %d\n";
42 |
43 | private int workgroupSize;
44 |
45 | private int directProgramID, computeProgramID;
46 | private int sourceTextureID, resultTextureID;
47 |
48 | private OptionModel invertEnabled = new OptionModel("Invert", false);
49 |
50 | public ComputeInvertSampler()
51 | {
52 | super(XeGLES3.GLES3_1); // Require OpenGL ES 3.1 context
53 | }
54 |
55 | protected void onCreate(Bundle savedInstanceState)
56 | {
57 | super.onCreate(savedInstanceState);
58 |
59 | drawerControl.setOptionModels(new OptionModel[]{invertEnabled});
60 | }
61 |
62 | public void onGLDrawFrame()
63 | {
64 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
65 |
66 | if (invertEnabled.getBooleanValue())
67 | {
68 | runComputeFilter(sourceTextureID, resultTextureID, 1024, 1024);
69 | drawTexture(resultTextureID);
70 | }
71 | else
72 | {
73 | drawTexture(sourceTextureID);
74 | }
75 | }
76 |
77 | private void drawTexture(int textureID)
78 | {
79 | glUseProgram(directProgramID);
80 |
81 | glActiveTexture(GL_TEXTURE0);
82 | glBindTexture(GL_TEXTURE_2D, textureID);
83 |
84 | glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, 1);
85 | }
86 |
87 | private void runComputeFilter(int sourceTextureID, int resultTextureID, int width, int height)
88 | {
89 | glUseProgram(computeProgramID);
90 |
91 | // Use sampler for source texture; this shows that compute shaders are still GLSL oriented!
92 | glActiveTexture(GL_TEXTURE0);
93 | glBindTexture(GL_TEXTURE_2D, sourceTextureID);
94 |
95 | glBindImageTexture(1, resultTextureID, 0, false, 0, GL_WRITE_ONLY, GL_RGBA8);
96 |
97 | glDispatchCompute(width / workgroupSize, height / workgroupSize, 1);
98 |
99 | // GL_COMPUTE_SHADER_BIT is the same as GL_SHADER_IMAGE_ACCESS_BARRIER_BIT
100 | glMemoryBarrier(GL_COMPUTE_SHADER_BIT);
101 | }
102 |
103 |
104 | public void onGLSurfaceChanged(int width, int height)
105 | {
106 | glViewport(0, 0, width, height);
107 |
108 | // Setup a VBO (Vertex Buffer Object)
109 | // Note: A VBO is created and binded for the rest of the runtime, so we don't hold onto a GLBuffer reference.
110 | // Quad (vertex + u/v); height / width provides aspect ratio when width is wider than height
111 | GLBufferUtil.createQuadVertexUVBuffer((float) height / (float) width).bind();
112 |
113 | glVertexAttribPointer(glGetAttribLocation(directProgramID, "inPosition"), 3, GL_FLOAT, false,
114 | GLBufferUtil.s_QUAD_BUFFER_STRIDE, 0);
115 |
116 | glVertexAttribPointer(glGetAttribLocation(directProgramID, "aTexCoord"), 2, GL_FLOAT, false,
117 | GLBufferUtil.s_QUAD_BUFFER_STRIDE, GLBufferUtil.s_QUAD_UV_OFFSET);
118 | }
119 |
120 | public void onGLSurfaceCreated()
121 | {
122 | // Sets the color rendered by glClear
123 | glClearColor(0.2f, 0.0f, 0.2f, 1.0f); // Set background to dark purple
124 |
125 | Resources resources = getResources();
126 |
127 | workgroupSize = AndroidGLES31Util.getMaxComputePowerWorkGroupSize(2);
128 |
129 | // Create shader programs
130 | directProgramID = AndroidGLES31Util.buildProgramFromAssets(resources, s_VERT_SHADER_FILE, s_FRAG_SHADER_FILE);
131 | computeProgramID = AndroidGLES31Util.buildProgramFromAssets(resources, s_COMP_SHADER_FILE, GL_COMPUTE_SHADER,
132 | String.format(S_COMP_SHADER_HEADER, workgroupSize));
133 |
134 | // Load texture from R.drawable.flower1024 (flip due to GL coordinates)
135 | sourceTextureID = AndroidGLES31Util.loadTexture(resources, R.drawable.flower1024, GL_RGBA8, true);
136 |
137 | resultTextureID = AndroidGLES31Util.createTexture(GL_RGBA8, 1024, 1024);
138 |
139 | glUseProgram(computeProgramID);
140 |
141 | glUniform2f(glGetUniformLocation(computeProgramID, "imageDimension"), 1024, 1024);
142 |
143 | glUseProgram(directProgramID);
144 |
145 | // Bind texture to texture unit 0
146 | glActiveTexture(GL_TEXTURE0);
147 | glBindTexture(GL_TEXTURE_2D, sourceTextureID);
148 |
149 | // Set sampler2d in GLSL fragment shader to texture unit 0
150 | glUniform1i(glGetUniformLocation(directProgramID, "uSourceTex"), 0);
151 |
152 | glEnableVertexAttribArray(0);
153 | glEnableVertexAttribArray(1);
154 | }
155 | }
156 |
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/java/org/typhonrt/android/java6/gldemo/gles31/raytrace/basic/ComputeBasicRayTrace.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015 Kai Burjack
3 | * See: https://github.com/LWJGL/lwjgl3/wiki/2.6.1.-Ray-tracing-with-OpenGL-Compute-Shaders-%28Part-I%29
4 | *
5 | * Copyright 2015 Michael Leahy / TyphonRT, Inc.
6 | * Converted to OpenGL ES 3.1 by Michael Leahy
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package org.typhonrt.android.java6.gldemo.gles31.raytrace.basic;
21 |
22 | import android.content.res.Resources;
23 |
24 | import org.typhonrt.android.java6.gldemo.gles31.raytrace.shared.PinholeCamera;
25 |
26 | import org.typhonrt.android.java6.gldemo.shared.BaseDemoActivity;
27 |
28 | import org.typhonrt.android.java6.opengl.utils.AndroidGLES31Util;
29 | import org.typhonrt.android.java6.opengl.utils.GLBuffer;
30 | import org.typhonrt.android.java6.opengl.utils.GLBufferUtil;
31 |
32 | import org.typhonrt.commons.java6.opengl.utils.XeGLES3;
33 |
34 | import org.typhonrt.java6.math.MathUtil;
35 | import org.typhonrt.java6.vecmath.Vector3f;
36 |
37 | import static android.opengl.GLES31.*;
38 |
39 | /**
40 | * ComputeBasicRayTrace
41 | */
42 | public class ComputeBasicRayTrace extends BaseDemoActivity
43 | {
44 | private static final String s_VERT_SHADER_FILE = "shaders/gles30/common/directTexture.vert";
45 | private static final String s_FRAG_SHADER_FILE = "shaders/gles30/common/directTexture.frag";
46 |
47 | private static final String s_COMP_SHADER_FILE = "shaders/gles31/raytrace/basicraytrace.comp";
48 |
49 | private static final String S_COMP_SHADER_HEADER = "#version 310 es\n#define LOCAL_SIZE %d\n";
50 |
51 | private static final String s_STR_ATTR_TEX_COORD = "aTexCoord";
52 | private static final String s_STR_IN_POSITION = "inPosition";
53 |
54 | private static final Vector3f s_VEC3_POSITION = new Vector3f(3.0f, 2.0f, 10.0f);
55 | private static final Vector3f s_VEC3_LOOKAT = new Vector3f(0.0f, 0.5f, 0.0f);
56 |
57 | private static final float s_FIELD_OF_VIEW_Y = 60f;
58 | private static final float s_NEAR = 1f;
59 | private static final float s_FAR = 2f;
60 |
61 | private int workgroupSize;
62 |
63 | private int surfaceWidth, surfaceHeight;
64 |
65 | private GLBuffer squareBuffer;
66 |
67 | private int textureID;
68 |
69 | private int computeProgramID;
70 | private int directProgramID;
71 |
72 | private int eyeUniform;
73 | private int ray00Uniform;
74 | private int ray10Uniform;
75 | private int ray01Uniform;
76 | private int ray11Uniform;
77 |
78 | // private int workGroupSizeX, workGroupSizeY;
79 |
80 | private PinholeCamera camera = new PinholeCamera();
81 |
82 | private final Vector3f eyeRay = new Vector3f();
83 |
84 | public ComputeBasicRayTrace()
85 | {
86 | super(XeGLES3.GLES3_1); // Require OpenGL ES 3.1 context
87 | }
88 |
89 | /**
90 | * Perform ray trace and draw "framebuffer" compute texture
91 | */
92 | @Override
93 | public void onGLDrawFrame()
94 | {
95 | glUseProgram(computeProgramID);
96 |
97 | // Set viewing frustum corner rays in shader
98 | glUniform3f(eyeUniform, camera.getPosition().x, camera.getPosition().y, camera.getPosition().z);
99 | camera.getEyeRay(-1, -1, eyeRay);
100 | glUniform3f(ray00Uniform, eyeRay.x, eyeRay.y, eyeRay.z);
101 | camera.getEyeRay(-1, 1, eyeRay);
102 | glUniform3f(ray01Uniform, eyeRay.x, eyeRay.y, eyeRay.z);
103 | camera.getEyeRay(1, -1, eyeRay);
104 | glUniform3f(ray10Uniform, eyeRay.x, eyeRay.y, eyeRay.z);
105 | camera.getEyeRay(1, 1, eyeRay);
106 | glUniform3f(ray11Uniform, eyeRay.x, eyeRay.y, eyeRay.z);
107 |
108 | // Bind level 0 of framebuffer texture as writable image in the shader.
109 | glBindImageTexture(0, textureID, 0, false, 0, GL_WRITE_ONLY, GL_RGBA32F);
110 |
111 | // Compute appropriate invocation dimension.
112 | int worksizeX = MathUtil.nextPow2(surfaceWidth);
113 | int worksizeY = MathUtil.nextPow2(surfaceHeight);
114 |
115 | // Invoke the compute shader, but only if workGroupSize X/Y is defined.
116 | if (workgroupSize > 0)
117 | {
118 | glDispatchCompute(worksizeX / workgroupSize, worksizeY / workgroupSize, 1);
119 | }
120 |
121 | // Reset image binding.
122 | glBindImageTexture(0, 0, 0, false, 0, GL_READ_WRITE, GL_RGBA32F);
123 |
124 | // GL_COMPUTE_SHADER_BIT is the same as GL_SHADER_IMAGE_ACCESS_BARRIER_BIT
125 | glMemoryBarrier(GL_COMPUTE_SHADER_BIT);
126 |
127 |
128 | // Render compute texture ID
129 | glUseProgram(directProgramID);
130 |
131 | squareBuffer.bind();
132 |
133 | glVertexAttribPointer(glGetAttribLocation(directProgramID, s_STR_IN_POSITION), 3, GL_FLOAT, false,
134 | GLBufferUtil.s_QUAD_BUFFER_STRIDE, 0);
135 |
136 | glVertexAttribPointer(glGetAttribLocation(directProgramID, s_STR_ATTR_TEX_COORD), 2, GL_FLOAT, false,
137 | GLBufferUtil.s_QUAD_BUFFER_STRIDE, GLBufferUtil.s_QUAD_UV_OFFSET);
138 |
139 | glBindTexture(GL_TEXTURE_2D, textureID);
140 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
141 | squareBuffer.unbind();
142 | }
143 |
144 | public void onGLSurfaceChanged(int width, int height)
145 | {
146 | surfaceWidth = width;
147 | surfaceHeight = height;
148 |
149 | glViewport(0, 0, surfaceWidth, surfaceHeight);
150 |
151 | textureID = AndroidGLES31Util.createTexture(GL_RGBA32F, surfaceWidth, surfaceHeight);
152 |
153 | // Setup camera
154 | camera.setFrustumPerspective(s_FIELD_OF_VIEW_Y, (float) width / height, s_NEAR, s_FAR);
155 | camera.setLookAt(s_VEC3_POSITION, s_VEC3_LOOKAT, Vector3f.s_Y);
156 | }
157 |
158 | public void onGLSurfaceCreated()
159 | {
160 | Resources resources = getResources();
161 |
162 | glEnableVertexAttribArray(0);
163 | glEnableVertexAttribArray(1);
164 |
165 | squareBuffer = GLBufferUtil.createQuadVertexUVBuffer(1);
166 |
167 | workgroupSize = AndroidGLES31Util.getMaxComputePowerWorkGroupSize(2);
168 |
169 | computeProgramID = AndroidGLES31Util.buildProgramFromAssets(resources, s_COMP_SHADER_FILE, GL_COMPUTE_SHADER,
170 | String.format(S_COMP_SHADER_HEADER, workgroupSize));
171 |
172 | initComputeProgram();
173 |
174 | directProgramID = AndroidGLES31Util.buildProgramFromAssets(resources, s_VERT_SHADER_FILE, s_FRAG_SHADER_FILE);
175 |
176 | glUseProgram(directProgramID);
177 |
178 | // Set sampler2d in GLSL fragment shader to texture unit 0
179 | glUniform1i(glGetUniformLocation(directProgramID, "uSourceTex"), 0);
180 | }
181 |
182 | /**
183 | * Initialize the compute shader.
184 | */
185 | private void initComputeProgram()
186 | {
187 | glUseProgram(computeProgramID);
188 |
189 | eyeUniform = glGetUniformLocation(computeProgramID, "eye");
190 | ray00Uniform = glGetUniformLocation(computeProgramID, "ray00");
191 | ray10Uniform = glGetUniformLocation(computeProgramID, "ray10");
192 | ray01Uniform = glGetUniformLocation(computeProgramID, "ray01");
193 | ray11Uniform = glGetUniformLocation(computeProgramID, "ray11");
194 |
195 | glUseProgram(0);
196 | }
197 | }
198 |
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/java/org/typhonrt/android/java6/gldemo/gles31/raytrace/shared/PinholeCamera.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015 Kai Burjack
3 | * See: https://github.com/LWJGL/lwjgl3/wiki/2.6.1.-Ray-tracing-with-OpenGL-Compute-Shaders-%28Part-I%29
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.typhonrt.android.java6.gldemo.gles31.raytrace.shared;
18 |
19 | import org.typhonrt.java6.vecmath.Matrix4f;
20 | import org.typhonrt.java6.vecmath.Vector3f;
21 | import org.typhonrt.java6.vecmath.Vector4f;
22 |
23 | /**
24 | * PinholeCamera
25 | */
26 | public class PinholeCamera
27 | {
28 | private float fn = 0.001f;
29 | private float ff = 10.0f;
30 | private float fl = -0.05f;
31 | private float fr = 0.05f;
32 | private float ft = 0.05f;
33 | private float fb = -0.05f;
34 |
35 | /**
36 | * Whether view matrix needs to be recalculated when requested through
37 | * {@link #getViewMatrix()}.
38 | */
39 | private boolean refreshViewMatrix = true;
40 |
41 | /**
42 | * Whether projection matrix needs to be recalculated when requested through
43 | * {@link #getProjectionMatrix()}.
44 | */
45 | private boolean refreshProjectionMatrix = true;
46 |
47 | private final Vector3f position = new Vector3f(0.0f, 0.0f, 0.0f);
48 |
49 | private final Vector3f direction = new Vector3f(0.0f, 0.0f, -1.0f);
50 |
51 | private final Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
52 |
53 | private final Vector3f right = new Vector3f(1.0f, 0.0f, 0.0f);
54 |
55 | private final Matrix4f projectionMatrix = new Matrix4f();
56 |
57 | private final Matrix4f viewMatrix = new Matrix4f();
58 |
59 | /**
60 | * Orthographic projection is inherently different from perspective
61 | * projection.
62 | */
63 | private boolean orthographic;
64 |
65 | /* Cached objects reused for computations */
66 | private Vector3f tmp0 = new Vector3f();
67 | private Vector3f tmp1 = new Vector3f();
68 | private Vector3f tmp2 = new Vector3f();
69 | private Vector4f tmp3 = new Vector4f();
70 | private float[] tmpMatArr = new float[16];
71 | private Matrix4f tmpMat = new Matrix4f();
72 |
73 | public Vector3f getDirection()
74 | {
75 | return direction;
76 | }
77 |
78 | /**
79 | * {@inheritDoc}
80 | */
81 | public void setDirection(Vector3f direction)
82 | {
83 | this.direction.set(direction);
84 | this.direction.normalize();
85 | refreshViewMatrix = true;
86 | }
87 |
88 | /**
89 | * Compute the world direction vector based on the given X and Y coordinates
90 | * in normalized-device space.
91 | *
92 | * @param x the X coordinate within [-1..1]
93 | * @param y the Y coordinate within [-1..1]
94 | * @param res will contain the result
95 | */
96 | public void getEyeRay(float x, float y, Vector3f res)
97 | {
98 | tmpMat.set(getProjectionMatrix());
99 | tmpMat.mul(getViewMatrix());
100 | tmpMat.invert();
101 | tmp3.set(x, y, 0.0f, 1.0f);
102 | tmpMat.transform(tmp3);
103 | tmp3.scale(1.0f / tmp3.w);
104 | tmp0.set(tmp3.x, tmp3.y, tmp3.z);
105 | res.set(tmp0);
106 | res.sub(position);
107 | }
108 |
109 | /**
110 | * {@inheritDoc}
111 | */
112 | public void setLookAt(Vector3f position, Vector3f lookAt, Vector3f up)
113 | {
114 | setPosition(position);
115 | tmp0.set(up);
116 | tmp0.normalize();
117 | tmp1.set(lookAt);
118 | tmp1.sub(position);
119 | tmp1.normalize();
120 | setDirection(tmp1);
121 | /* right = direction x up */
122 | right.cross(tmp1, tmp0);
123 | right.normalize();
124 | /* up = right x direction */
125 | tmp0.cross(right, tmp1);
126 | setUp(tmp0);
127 | }
128 |
129 | private void doRefreshViewMatrix()
130 | {
131 | tmp0.set(direction);
132 | /* right = direction x up */
133 | tmp1.cross(tmp0, up);
134 | /* up = right x direction */
135 | tmp2.cross(tmp1, tmp0);
136 | final float[] m = tmpMatArr;
137 | m[0] = tmp1.x;
138 | m[1] = tmp1.y;
139 | m[2] = tmp1.z;
140 | m[3] = -tmp1.x * position.x - tmp1.y * position.y - tmp1.z * position.z;
141 | m[4] = tmp2.x;
142 | m[5] = tmp2.y;
143 | m[6] = tmp2.z;
144 | m[7] = -tmp2.x * position.x - tmp2.y * position.y - tmp2.z * position.z;
145 | m[8] = -tmp0.x;
146 | m[9] = -tmp0.y;
147 | m[10] = -tmp0.z;
148 | m[11] = tmp0.x * position.x + tmp0.y * position.y + tmp0.z * position.z;
149 | m[12] = 0.0f;
150 | m[13] = 0.0f;
151 | m[14] = 0.0f;
152 | m[15] = 1.0f;
153 | viewMatrix.set(m);
154 | refreshViewMatrix = false;
155 | }
156 |
157 | public Vector3f getPosition()
158 | {
159 | return position;
160 | }
161 |
162 | /**
163 | * {@inheritDoc}
164 | */
165 | public void setPosition(Vector3f position)
166 | {
167 | if (this.position.equals(position))
168 | {
169 | return;
170 | }
171 | this.position.set(position);
172 | refreshViewMatrix = true;
173 | }
174 |
175 | public Vector3f getUp()
176 | {
177 | return up;
178 | }
179 |
180 | /**
181 | * {@inheritDoc}
182 | */
183 | public void setUp(Vector3f up)
184 | {
185 | if (this.up.equals(up))
186 | {
187 | return;
188 | }
189 | this.up.set(up);
190 | refreshViewMatrix = true;
191 | }
192 |
193 | public Vector3f getRight()
194 | {
195 | return right;
196 | }
197 |
198 | /**
199 | * Set the distance of the near frustum plane.
200 | *
201 | * @param frustumNear the distance of the near frustum plane
202 | */
203 | protected void setFrustumNear(float frustumNear)
204 | {
205 | if (this.fn == frustumNear)
206 | {
207 | return;
208 | }
209 | this.fn = frustumNear;
210 | refreshProjectionMatrix = true;
211 | }
212 |
213 | public float getFrustumFar()
214 | {
215 | return ff;
216 | }
217 |
218 | /**
219 | * Set the distance of the far frustum plane.
220 | *
221 | * @param frustumFar the distance of the far frustum plane
222 | */
223 | protected void setFrustumFar(float frustumFar)
224 | {
225 | if (this.ff == frustumFar)
226 | {
227 | return;
228 | }
229 | this.ff = frustumFar;
230 | refreshProjectionMatrix = true;
231 | }
232 |
233 | public float getFrustumLeft()
234 | {
235 | return fl;
236 | }
237 |
238 | /**
239 | * Set the distance of the left frustum plane.
240 | *
241 | * @param frustumLeft the distance of the left frustum plane
242 | */
243 | protected void setFrustumLeft(float frustumLeft)
244 | {
245 | if (this.fl == frustumLeft)
246 | {
247 | return;
248 | }
249 | this.fl = frustumLeft;
250 | refreshProjectionMatrix = true;
251 | }
252 |
253 | public float getFrustumRight()
254 | {
255 | return fr;
256 | }
257 |
258 | /**
259 | * Set the distance of the right frustum plane.
260 | *
261 | * @param frustumRight the distance of the right frustum plane
262 | */
263 | protected void setFrustumRight(float frustumRight)
264 | {
265 | if (this.fr == frustumRight)
266 | {
267 | return;
268 | }
269 | this.fr = frustumRight;
270 | refreshProjectionMatrix = true;
271 | }
272 |
273 | public float getFrustumTop()
274 | {
275 | return ft;
276 | }
277 |
278 | /**
279 | * Set the distance of the top frustum plane.
280 | *
281 | * @param frustumTop the distance of the top frustum plane
282 | */
283 | protected void setFrustumTop(float frustumTop)
284 | {
285 | if (this.ft == frustumTop)
286 | {
287 | return;
288 | }
289 | this.ft = frustumTop;
290 | refreshProjectionMatrix = true;
291 | }
292 |
293 | public float getFrustumBottom()
294 | {
295 | return fb;
296 | }
297 |
298 | /**
299 | * Set the distance of the bottom frustum plane.
300 | *
301 | * @param frustumBottom the distance of the bottom frustum plane
302 | */
303 | protected void setFrustumBottom(float frustumBottom)
304 | {
305 | if (this.fb == frustumBottom)
306 | {
307 | return;
308 | }
309 | this.fb = frustumBottom;
310 | refreshProjectionMatrix = true;
311 | }
312 |
313 | public void setOrthographic(boolean orthographic)
314 | {
315 | if (this.orthographic == orthographic)
316 | {
317 | return;
318 | }
319 | this.orthographic = orthographic;
320 | refreshProjectionMatrix = true;
321 | }
322 |
323 | public boolean isOrthographic()
324 | {
325 | return orthographic;
326 | }
327 |
328 | /**
329 | * {@inheritDoc}
330 | */
331 | public Matrix4f getProjectionMatrix()
332 | {
333 | if (refreshProjectionMatrix)
334 | {
335 | doRefreshProjectionMatrix();
336 | }
337 | return projectionMatrix;
338 | }
339 |
340 | private void doRefreshProjectionMatrix()
341 | {
342 | // Reset projection matrix
343 | if (!orthographic)
344 | {
345 | tmpMatArr[0] = 2.0f * fn / (fr - fl);
346 | tmpMatArr[1] = 0.0f;
347 | tmpMatArr[2] = (fr + fl) / (fr - fl);
348 | tmpMatArr[3] = 0.0f;
349 | tmpMatArr[4] = 0.0f;
350 | tmpMatArr[5] = 2.0f * fn / (ft - fb);
351 | tmpMatArr[6] = (ft + fb) / (ft - fb);
352 | tmpMatArr[7] = 0.0f;
353 | tmpMatArr[8] = 0.0f;
354 | tmpMatArr[9] = 0.0f;
355 | tmpMatArr[10] = -(ff + fn) / (ff - fn);
356 | tmpMatArr[11] = -2.0f * ff * fn / (ff - fn);
357 | tmpMatArr[12] = 0.0f;
358 | tmpMatArr[13] = 0.0f;
359 | tmpMatArr[14] = -1.0f;
360 | tmpMatArr[15] = 0.0f;
361 | projectionMatrix.set(tmpMatArr);
362 | }
363 | else
364 | {
365 | tmpMatArr[0] = 2.0f / (fr - fl);
366 | tmpMatArr[1] = 0.0f;
367 | tmpMatArr[2] = 0.0f;
368 | tmpMatArr[3] = -(fr + fl) / (fr - fl);
369 | tmpMatArr[4] = 0.0f;
370 | tmpMatArr[5] = 2.0f / (ft - fb);
371 | tmpMatArr[6] = 0.0f;
372 | tmpMatArr[7] = -(ft + fb) / (ft - fb);
373 | tmpMatArr[8] = 0.0f;
374 | tmpMatArr[9] = 0.0f;
375 | tmpMatArr[10] = -2.0f / (ff - fn);
376 | tmpMatArr[11] = -(ff + fn) / (ff - fn);
377 | tmpMatArr[12] = 0.0f;
378 | tmpMatArr[13] = 0.0f;
379 | tmpMatArr[14] = 0.0f;
380 | tmpMatArr[15] = 1.0f;
381 | projectionMatrix.set(tmpMatArr);
382 | }
383 | refreshProjectionMatrix = false;
384 | }
385 |
386 | /**
387 | * {@inheritDoc}
388 | */
389 | public void setFrustum(float near, float far, float left, float right, float top, float bottom)
390 | {
391 | setOrthographic(true);
392 | setFrustumNear(near);
393 | setFrustumFar(far);
394 | setFrustumLeft(left);
395 | setFrustumRight(right);
396 | setFrustumTop(top);
397 | setFrustumBottom(bottom);
398 | }
399 |
400 | /**
401 | * {@inheritDoc}
402 | */
403 | public void setFrustumPerspective(float fovY, float aspect, float near, float far)
404 | {
405 | setFrustumPerspective(fovY, aspect, near, far, 1, 1, 0, 0);
406 | }
407 |
408 | /**
409 | * {@inheritDoc}
410 | */
411 | public void setFrustumPerspective(float fovY, float aspect, float near, float far, int tilesX, int tilesY,
412 | int tileX, int tileY)
413 | {
414 | if (Float.isNaN(aspect) || Float.isInfinite(aspect))
415 | {
416 | throw new IllegalArgumentException("Illegal value for aspect [" + aspect + "]");
417 | }
418 | if (near >= far)
419 | {
420 | throw new IllegalArgumentException("The passed value for near [" + near + "] must be greater than far ["
421 | + far + "]");
422 | }
423 | if (tileX < 0 || tileX >= tilesX || tileY < 0 || tileY >= tilesY)
424 | {
425 | throw new IllegalArgumentException(
426 | "The tile indices must be at least 0 and at most the total number of tiles minus 1");
427 | }
428 | setOrthographic(false);
429 | final float h = (float) Math.tan(Math.toRadians(fovY) * 0.5f) * near;
430 | final float w = h * aspect;
431 | final float left = -w + (float) tileX / tilesX * 2.0f * w;
432 | final float right = left + (float) 1.0f / tilesX * 2.0f * w;
433 | final float bottom = -h + (float) tileY / tilesY * 2.0f * h;
434 | final float top = bottom + (float) 1.0f / tilesY * 2.0f * h;
435 | setFrustumLeft(left);
436 | setFrustumRight(right);
437 | setFrustumBottom(bottom);
438 | setFrustumTop(top);
439 | setFrustumNear(near);
440 | setFrustumFar(far);
441 | }
442 |
443 | /**
444 | * {@inheritDoc}
445 | */
446 | public Matrix4f getViewMatrix()
447 | {
448 | if (refreshViewMatrix)
449 | {
450 | doRefreshViewMatrix();
451 | }
452 | return viewMatrix;
453 | }
454 | }
455 |
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/java/org/typhonrt/android/java6/gldemo/shared/BaseDemoActivity.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015 Michael Leahy / TyphonRT, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.typhonrt.android.java6.gldemo.shared;
17 |
18 | import android.os.Bundle;
19 | import android.support.v7.app.ActionBarActivity;
20 | import android.support.v7.widget.Toolbar;
21 | import android.view.View;
22 | import android.widget.Toast;
23 |
24 | import org.typhonrt.android.java6.data.option.control.OptionModelDrawerControl;
25 |
26 | import org.typhonrt.android.java6.opengl.utils.GLSurfaceView2;
27 |
28 | import org.typhonrt.commons.java6.opengl.utils.IGLVersion;
29 | import org.typhonrt.commons.java6.opengl.utils.XeGLES3;
30 |
31 | import org.typhonrt.android.java6.gldemo.R;
32 |
33 | /**
34 | * BaseDemoActivity - Only setting the requested OpenGL major version will create the highest major / minor version
35 | * GL context supported by the given device.
36 | */
37 | public abstract class BaseDemoActivity extends ActionBarActivity implements GLSurfaceView2.Renderer
38 | {
39 | public static final int s_UI_OPTIONS = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
40 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
41 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
42 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
43 | | View.SYSTEM_UI_FLAG_FULLSCREEN
44 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
45 |
46 | private static final IGLVersion s_DEFAULT_GL_VERSION = XeGLES3.GLES3_0;
47 |
48 | protected OptionModelDrawerControl drawerControl;
49 |
50 | protected final IGLVersion requestedGLVersion;
51 |
52 | protected BaseDemoActivity()
53 | {
54 | this(s_DEFAULT_GL_VERSION);
55 | }
56 |
57 | protected BaseDemoActivity(IGLVersion requestedGLVersion)
58 | {
59 | this.requestedGLVersion = requestedGLVersion;
60 | }
61 |
62 | @Override
63 | protected void onCreate(Bundle savedInstanceState)
64 | {
65 | super.onCreate(savedInstanceState);
66 |
67 | setContentView(R.layout.demo_activity_layout);
68 |
69 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
70 |
71 | setSupportActionBar(toolbar);
72 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
73 |
74 | drawerControl = new OptionModelDrawerControl(this);
75 |
76 | GLSurfaceView2 surfaceView = (GLSurfaceView2)findViewById(R.id.glsurfaceview);
77 |
78 | surfaceView.setEGLContextGLESVersion(requestedGLVersion);
79 | surfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
80 | surfaceView.setRenderer(this);
81 | surfaceView.setRenderMode(GLSurfaceView2.s_RENDERMODE_CONTINUOUSLY);
82 | }
83 |
84 | @Override
85 | public void onGLContextCreated()
86 | {
87 | GLSurfaceView2 surfaceView = (GLSurfaceView2)findViewById(R.id.glsurfaceview);
88 |
89 | IGLVersion glVersion = surfaceView.getContextGLESVersion();
90 |
91 | final int glMajorVersion = glVersion.getMajorVersion();
92 | final int glMinorVersion = glVersion.getMinorVersion();
93 |
94 | final int requestedMajorVersion = requestedGLVersion.getMajorVersion();
95 | final int requestedMinorVersion = requestedGLVersion.getMinorVersion();
96 |
97 | if (glMajorVersion < requestedMajorVersion || (glMajorVersion == requestedMajorVersion &&
98 | glMinorVersion < requestedMinorVersion))
99 | {
100 | runOnUiThread(new Runnable() {
101 | @Override
102 | public void run()
103 | {
104 | Toast.makeText(BaseDemoActivity.this, "OpenGL ES version less than required!\n"
105 | +"\nRequested: " +requestedMajorVersion +"." +requestedMinorVersion
106 | +"\nCreated: " +glMajorVersion +"." +glMinorVersion, Toast.LENGTH_LONG).show();
107 | }
108 | });
109 | }
110 | }
111 |
112 | /**
113 | * Handles setting immersive sticky when the window is focused. Necessary when an Activity is minimized and
114 | * brought back to front.
115 | *
116 | * @param hasFocus
117 | */
118 | @Override
119 | public void onWindowFocusChanged(boolean hasFocus)
120 | {
121 | super.onWindowFocusChanged(hasFocus);
122 |
123 | if (hasFocus)
124 | {
125 | getWindow().getDecorView().setSystemUiVisibility(s_UI_OPTIONS);
126 | }
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/modern-java-graphics/java6-android-gldemos/7a1b97c7c0c40f7145bea5eb2e7ff28624a90799/java6-android-gldemos/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/modern-java-graphics/java6-android-gldemos/7a1b97c7c0c40f7145bea5eb2e7ff28624a90799/java6-android-gldemos/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/res/drawable-nodpi/flower1024.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/modern-java-graphics/java6-android-gldemos/7a1b97c7c0c40f7145bea5eb2e7ff28624a90799/java6-android-gldemos/src/main/res/drawable-nodpi/flower1024.jpg
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/modern-java-graphics/java6-android-gldemos/7a1b97c7c0c40f7145bea5eb2e7ff28624a90799/java6-android-gldemos/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/modern-java-graphics/java6-android-gldemos/7a1b97c7c0c40f7145bea5eb2e7ff28624a90799/java6-android-gldemos/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/res/drawable-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/modern-java-graphics/java6-android-gldemos/7a1b97c7c0c40f7145bea5eb2e7ff28624a90799/java6-android-gldemos/src/main/res/drawable-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/res/drawable/gradient.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/res/layout/demo_activity_layout.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
14 |
15 |
20 |
21 |
23 |
31 |
32 |
33 |
38 |
39 |
40 |
41 |
44 |
45 |
56 |
57 |
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/res/layout/list_activity_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
13 |
21 |
22 |
25 |
26 |
36 |
37 |
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/res/layout/listview_section.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
21 |
22 |
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/res/layout/listview_text.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
19 |
20 |
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/res/values-v19/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
13 |
14 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | - #220000FF
5 |
6 |
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 40dp
3 | 34dp
4 | 48dp
5 |
6 | 20sp
7 | 22sp
8 | 28sp
9 | 36sp
10 | 48sp
11 | 64sp
12 |
13 | 1dp
14 | 5dp
15 | 120dp
16 | 10dip
17 | 300dp
18 |
19 |
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ModernGL
5 | Modern Java OpenGL Demos (long click items for wiki)
6 |
7 | ComputeParticles
8 | ComputeBasicRayTrace
9 | ComputeInvert
10 | ComputeInvertSampler
11 | GLSLInvert
12 | GLSLKuwahara
13 | GLSLKuwaharaFBO
14 |
15 | Cancel
16 | Your device does not support the required OpenGL ES version. Attempt to run the demo anyway?
17 | Ok
18 | OpenGL ES version unsupported
19 |
20 | "OpenGL ES 3.0 Demos"
21 | "OpenGL ES 3.1 Demos"
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/java6-android-gldemos/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
8 |
9 |
12 |
13 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/prebuilt-apk/ModernGL.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/modern-java-graphics/java6-android-gldemos/7a1b97c7c0c40f7145bea5eb2e7ff28624a90799/prebuilt-apk/ModernGL.apk
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':java6-android-gldemos'
2 |
3 | // External project dependencies
4 | include ':java6-android-demoframework', ':java6-android-glutils', ':java6-glutils-commons', ':java6-math'
5 |
6 | project(':java6-android-demoframework').projectDir = new File(settingsDir, '../java6-android-demoframework/java6-android-demoframework')
7 | project(':java6-android-glutils').projectDir = new File(settingsDir, '../java6-android-glframework/java6-android-glutils')
8 | project(':java6-glutils-commons').projectDir = new File(settingsDir, '../java6-android-glframework/java6-glutils-commons')
9 | project(':java6-math').projectDir = new File(settingsDir, '../java6-android-glframework/java6-math')
10 |
--------------------------------------------------------------------------------