examples;
56 | private TabLayoutPanel tabs;
57 |
58 | @Override
59 | public void onModuleLoad()
60 | {
61 | RootLayoutPanel.get().add(new HTML(
62 | " " +
64 | "" +
65 | " Examples "));
66 |
67 | examples = new ArrayList<>();
68 |
69 | tabs = new TabLayoutPanel(190, Style.Unit.PX);
70 | tabs.add(new ScrollPanel(createInformationTab()), "Information");
71 |
72 | Example triangleExample = new TriangleExample(createCanvas());
73 | examples.add(triangleExample);
74 | tabs.add(triangleExample.canvas, "Triangle");
75 |
76 | Example rectangleExample = new RectangleExample(createCanvas());
77 | examples.add(rectangleExample);
78 | tabs.add(rectangleExample.canvas, "Rectangle");
79 |
80 | Example textureExample = new TextureExample(createCanvas());
81 | examples.add(textureExample);
82 | tabs.add(textureExample.canvas, "Texture");
83 |
84 | Example cubeExample = new CubeExample(createCanvas());
85 | examples.add(cubeExample);
86 | tabs.add(cubeExample.canvas, "Cube");
87 |
88 | Example texturedCubeExample = new TexturedCubeExample(createCanvas());
89 | examples.add(texturedCubeExample);
90 | tabs.add(texturedCubeExample.canvas, "Textured Cube");
91 |
92 | RootLayoutPanel.get().add(tabs);
93 |
94 | // Init all examples
95 | for (Example example : examples)
96 | {
97 | example.context.makeCurrent();
98 | example.init();
99 | }
100 |
101 | AnimationScheduler.get().requestAnimationFrame(this::animationCallback);
102 | }
103 |
104 | private void animationCallback(double timestamp)
105 | {
106 | for (Example example : examples)
107 | {
108 | if (tabs.getWidget(tabs.getSelectedIndex()) == example.canvas)
109 | {
110 | example.context.makeCurrent();
111 | example.render();
112 | break;
113 | }
114 | }
115 |
116 | AnimationScheduler.get().requestAnimationFrame(this::animationCallback);
117 | }
118 |
119 | private Widget createInformationTab()
120 | {
121 | WebGLContext infoContext = (WebGL20.isSupported()) ? WebGL20.createContext(Canvas.createIfSupported())
122 | : WebGL10.createContext(Canvas.createIfSupported());
123 | infoContext.makeCurrent();
124 |
125 | String webglInfo = "Browser ";
126 | webglInfo += "";
127 | {
128 | webglInfo += "User Agent: " + Window.Navigator.getUserAgent() + "";
129 | webglInfo += "Platform: " + Window.Navigator.getPlatform() + "";
130 | }
131 | webglInfo += "
";
132 |
133 | webglInfo += "WebGL context ";
134 | webglInfo += "";
135 | {
136 | webglInfo += isSupportedHTML("WebGL 1.0", WebGL10.isSupported());
137 | webglInfo += isSupportedHTML("WebGL 2.0", WebGL20.isSupported());
138 |
139 | webglInfo += "WebGL version: " + glGetParameter(GL_VERSION) + "";
140 | webglInfo += "GLSL version: " + glGetParameter(GL_SHADING_LANGUAGE_VERSION) + "";
141 | webglInfo += "WebGL renderer: " + glGetParameter(GL_RENDERER) + "";
142 | webglInfo += "WebGL vendor: " + glGetParameter(GL_VENDOR) + "";
143 |
144 | if (WEBGL_debug_renderer_info.isSupported())
145 | {
146 | WEBGL_debug_renderer_info.enableExtension();
147 |
148 | webglInfo += "Unmasked renderer: " + glGetParameter(GL_UNMASKED_RENDERER_WEBGL) + "";
149 | webglInfo += "Unmasked vendor: " + glGetParameter(GL_UNMASKED_VENDOR_WEBGL) + "";
150 | }
151 | }
152 | webglInfo += "
";
153 |
154 | webglInfo += "WebGL Extensions ";
155 | webglInfo += "";
156 | {
157 | webglInfo += isSupportedHTML("ANGLE_instanced_arrays", ANGLE_instanced_arrays.isSupported());
158 |
159 | webglInfo += isSupportedHTML("EXT_blend_minmax", EXT_blend_minmax.isSupported());
160 | webglInfo += isSupportedHTML("EXT_frag_depth", EXT_frag_depth.isSupported());
161 | webglInfo += isSupportedHTML("EXT_shader_texture_lod", EXT_shader_texture_lod.isSupported());
162 | webglInfo += isSupportedHTML("EXT_texture_filter_anisotropic", EXT_texture_filter_anisotropic.isSupported());
163 |
164 | webglInfo += isSupportedHTML("OES_element_index_uint", OES_element_index_uint.isSupported());
165 | webglInfo += isSupportedHTML("OES_standard_derivatives", OES_standard_derivatives.isSupported());
166 | webglInfo += isSupportedHTML("OES_texture_float", OES_texture_float.isSupported());
167 | webglInfo += isSupportedHTML("OES_texture_float_linear", OES_texture_float_linear.isSupported());
168 | webglInfo += isSupportedHTML("OES_texture_half_float", OES_texture_half_float.isSupported());
169 | webglInfo += isSupportedHTML("OES_texture_half_float_linear", OES_texture_half_float_linear.isSupported());
170 | webglInfo += isSupportedHTML("OES_vertex_array_object", OES_vertex_array_object.isSupported());
171 |
172 | webglInfo += isSupportedHTML("WEBGL_compressed_texture_s3tc", WEBGL_compressed_texture_s3tc.isSupported());
173 | webglInfo += isSupportedHTML("WEBGL_debug_renderer_info", WEBGL_debug_renderer_info.isSupported());
174 | webglInfo += isSupportedHTML("WEBGL_debug_shaders", WEBGL_debug_shaders.isSupported());
175 | webglInfo += isSupportedHTML("WEBGL_depth_texture", WEBGL_depth_texture.isSupported());
176 | webglInfo += isSupportedHTML("WEBGL_draw_buffers", WEBGL_draw_buffers.isSupported());
177 | webglInfo += isSupportedHTML("WEBGL_lose_context", WEBGL_lose_context.isSupported());
178 | }
179 | webglInfo += "
";
180 |
181 | WebGLContext.Attributes attributes = WebGLContext.getCurrent().getAttributes();
182 |
183 | webglInfo += "Context Attributes ";
184 | webglInfo += "";
185 | {
186 | webglInfo += "Alpha: " + attributes.getAlpha() + "";
187 | webglInfo += "Antialias: " + attributes.getAntialias() + "";
188 | webglInfo += "Depth: " + attributes.getDepth() + "";
189 | webglInfo += "FailIfMajorPerformanceCaveat: " + attributes.getFailIfMajorPerformanceCaveat() + "";
190 | webglInfo += "PremultipliedAlpha: " + attributes.getPremultipliedAlpha() + "";
191 | webglInfo += "PreserveDrawingBuffer: " + attributes.getPreserveDrawingBuffer() + "";
192 | webglInfo += "Stencil: " + attributes.getStencil() + "";
193 | }
194 | webglInfo += "
";
195 |
196 | return new HTML(webglInfo);
197 | }
198 |
199 | private Canvas createCanvas()
200 | {
201 | Canvas canvas = Canvas.createIfSupported();
202 | canvas.setCoordinateSpaceWidth(640);
203 | canvas.setCoordinateSpaceHeight(480);
204 | return canvas;
205 | }
206 | }
207 |
--------------------------------------------------------------------------------
/examples/src/main/resources/texture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sriharshachilakapati/WebGL4J/7daa425300b08b338b50cef2935289849c92d415/examples/src/main/resources/texture.png
--------------------------------------------------------------------------------
/examples/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 | index.html
9 |
10 |
--------------------------------------------------------------------------------
/examples/src/main/webapp/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | WebGL Test
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sriharshachilakapati/WebGL4J/7daa425300b08b338b50cef2935289849c92d415/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Jan 05 19:05:37 IST 2016
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-bin.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include 'webgl4j', 'examples'
2 |
--------------------------------------------------------------------------------
/webgl4j/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 | apply plugin: 'maven'
3 | apply plugin: 'signing'
4 |
5 | sourceCompatibility = 1.8
6 | targetCompatibility = 1.8
7 |
8 | group = "com.goharsha"
9 | archivesBaseName = "webgl4j"
10 | version = "0.3.0-SNAPSHOT"
11 |
12 | // Check if the required properties are included, so we prevent our
13 | // build from failing.
14 | if (project.hasProperty('ossrhUsername'))
15 | {
16 | project.ext.ossrhUsername = ossrhUsername
17 | project.ext.ossrhPassword = ossrhPassword
18 | }
19 | else
20 | {
21 | // We might be running on another system where he is not
22 | // the owner who can push to OSSRH through maven. Set
23 | // default values so he can still build the library locally.
24 | project.ext.ossrhUsername = ''
25 | project.ext.ossrhPassword = ''
26 | }
27 |
28 | dependencies {
29 | compile 'com.google.gwt:gwt-user:2.8.0'
30 | }
31 |
32 | jar {
33 | from project(":webgl4j").sourceSets.main.allSource
34 | }
35 |
36 | javadoc {
37 | options.addStringOption("sourcepath", "")
38 | }
39 |
40 | task javadocJar(type: Jar) {
41 | classifier = 'javadoc'
42 | from javadoc
43 | }
44 |
45 | task sourcesJar(type: Jar) {
46 | classifier = 'sources'
47 | from sourceSets.main.allSource
48 | }
49 |
50 | artifacts {
51 | archives javadocJar, sourcesJar
52 | }
53 |
54 | signing {
55 | // Only sign the archives if there is a username. This allows one to build the library
56 | // on systems with no username set.
57 | if (ossrhUsername != '')
58 | sign configurations.archives
59 | }
60 |
61 | uploadArchives {
62 | repositories {
63 | mavenDeployer {
64 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
65 |
66 | repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
67 | authentication(userName: project.ext.ossrhUsername, password: project.ext.ossrhPassword)
68 | }
69 |
70 | snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
71 | authentication(userName: project.ext.ossrhUsername, password: project.ext.ossrhPassword)
72 | }
73 |
74 | pom.project {
75 | name 'WebGL4J'
76 | packaging 'jar'
77 | description 'A WebGL wrapper for the GWT platform using Java'
78 | url 'http://goharsha.com/WebGL4J'
79 |
80 | scm {
81 | connection 'scm:git:git@github.com:sriharshachilakapati/WebGL4J.git'
82 | developerConnection 'scm:git:git@github.com:sriharshachilakapati/WebGL4J.git'
83 | url 'git@github.com:sriharshachilakapati/WebGL4J.git'
84 | }
85 |
86 | licenses {
87 | license {
88 | name 'The MIT License (MIT)'
89 | url 'https://opensource.org/licenses/MIT'
90 | }
91 | }
92 |
93 | developers {
94 | developer {
95 | id 'sriharshachilakapati'
96 | name 'Sri Harsha Chilakapati'
97 | email 'sriharshachilakapati@gmail.com'
98 | }
99 | }
100 | }
101 | }
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/webgl4j/src/main/java/com/shc/webgl4j/client.gwt.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/webgl4j/src/main/java/com/shc/webgl4j/client/ANGLE_instanced_arrays.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014-2015 Sri Harsha Chilakapati
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.shc.webgl4j.client;
26 |
27 | /**
28 | * @author Sri Harsha Chilakapati
29 | */
30 | public final class ANGLE_instanced_arrays
31 | {
32 | public static final int VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE = 0x88FE;
33 |
34 | /* Prevent instantiation */
35 | private ANGLE_instanced_arrays()
36 | {
37 | }
38 |
39 | public static boolean isSupported()
40 | {
41 | if (!WebGL10.isSupported())
42 | return false;
43 |
44 | if (!WebGL10.isContextCompatible())
45 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to check if extension is supported.");
46 |
47 | for (String supportedExtension : WebGL10.glGetSupportedExtensions())
48 | {
49 | switch (supportedExtension)
50 | {
51 | case "ANGLE_instanced_arrays":
52 | case "O_ANGLE_instanced_arrays":
53 | case "IE_ANGLE_instanced_arrays":
54 | case "MOZ_ANGLE_instanced_arrays":
55 | case "WEBKIT_ANGLE_instanced_arrays":
56 | return true;
57 | }
58 | }
59 |
60 | return false;
61 | }
62 |
63 | public static void enableExtension()
64 | {
65 | if (!WebGL10.isContextCompatible())
66 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to enable this extension.");
67 |
68 | if (!isSupported())
69 | throw new RuntimeException("This browser does not support the ANGLE_instanced_arrays extension.");
70 |
71 | if (!isExtensionEnabled())
72 | nEnableExtension();
73 | }
74 |
75 | private static void checkExtension()
76 | {
77 | if (!WebGL10.isContextCompatible())
78 | throw new RuntimeException("You must have a WebGL context >= 1.0 before accessing extension methods.");
79 |
80 | if (!isExtensionEnabled())
81 | throw new IllegalStateException("Extension must be enabled before using any functions.");
82 | }
83 |
84 | public static native boolean isExtensionEnabled() /*-{
85 | return typeof ($wnd.gl.aia_ext) !== 'undefined';
86 | }-*/;
87 |
88 | public static void glDrawArraysInstancedANGLE(int mode, int first, int count, int primCount)
89 | {
90 | checkExtension();
91 | nglDrawArraysInstancedANGLE(mode, first, count, primCount);
92 | }
93 |
94 | public static void glDrawElementsInstancedANGLE(int mode, int count, int type, int offset, int primCount)
95 | {
96 | checkExtension();
97 | nglDrawElementsInstancedANGLE(mode, count, type, offset, primCount);
98 | }
99 |
100 | public static void glVertexAttribDivisorANGLE(int index, int divisor)
101 | {
102 | checkExtension();
103 | nglVertexAttribDivisorANGLE(index, divisor);
104 | }
105 |
106 | private static native void nEnableExtension() /*-{
107 | $wnd.gl.aia_ext = $wnd.gl.getExtension('ANGLE_instanced_arrays') ||
108 | $wnd.gl.getExtension('O_ANGLE_instanced_arrays') ||
109 | $wnd.gl.getExtension('IE_ANGLE_instanced_arrays') ||
110 | $wnd.gl.getExtension('MOZ_ANGLE_instanced_arrays') ||
111 | $wnd.gl.getExtension('WEBKIT_ANGLE_instanced_arrays');
112 | }-*/;
113 |
114 | private static native void nglDrawArraysInstancedANGLE(int mode, int first, int count, int primCount) /*-{
115 | $wnd.gl.aia_ext.drawArraysInstancedANGLE(mode, first, count, primCount);
116 | }-*/;
117 |
118 | private static native void nglDrawElementsInstancedANGLE(int mode, int count, int type, int offset, int primCount) /*-{
119 | $wnd.gl.aia_ext.drawElementsInstancedANGLE(mode, count, type, offset, primCount);
120 | }-*/;
121 |
122 | private static native void nglVertexAttribDivisorANGLE(int index, int divisor) /*-{
123 | $wnd.gl.aia_ext.vertexAttribDivisorANGLE(index, divisor);
124 | }-*/;
125 | }
126 |
--------------------------------------------------------------------------------
/webgl4j/src/main/java/com/shc/webgl4j/client/EXT_blend_minmax.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014-2015 Sri Harsha Chilakapati
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.shc.webgl4j.client;
26 |
27 | /**
28 | * @author Sri Harsha Chilakapati
29 | */
30 | public final class EXT_blend_minmax
31 | {
32 | public static final int GL_MIN_EXT = 0x8007;
33 | public static final int GL_MAX_EXT = 0x8008;
34 |
35 | /* Prevent instantiation */
36 | private EXT_blend_minmax()
37 | {
38 | }
39 |
40 | public static boolean isSupported()
41 | {
42 | if (!WebGL10.isSupported())
43 | return false;
44 |
45 | if (!WebGL10.isContextCompatible())
46 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to check if extension is supported.");
47 |
48 | for (String supportedExtension : WebGL10.glGetSupportedExtensions())
49 | {
50 | switch (supportedExtension)
51 | {
52 | case "EXT_blend_minmax":
53 | case "O_EXT_blend_minmax":
54 | case "IE_EXT_blend_minmax":
55 | case "MOZ_EXT_blend_minmax":
56 | case "WEBKIT_EXT_blend_minmax":
57 | return true;
58 | }
59 | }
60 |
61 | return false;
62 | }
63 |
64 | public static void enableExtension()
65 | {
66 | if (!WebGL10.isContextCompatible())
67 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to enable this extension.");
68 |
69 | if (!isSupported())
70 | throw new RuntimeException("This browser does not support the EXT_blend_minmax extension.");
71 |
72 | if (!isExtensionEnabled())
73 | nEnableExtension();
74 | }
75 |
76 | public static native boolean isExtensionEnabled() /*-{
77 | return typeof ($wnd.gl.ebb_ext) !== 'undefined';
78 | }-*/;
79 |
80 | private static native void nEnableExtension() /*-{
81 | $wnd.gl.ebb_ext = $wnd.gl.getExtension('EXT_blend_minmax') ||
82 | $wnd.gl.getExtension('O_EXT_blend_minmax') ||
83 | $wnd.gl.getExtension('IE_EXT_blend_minmax') ||
84 | $wnd.gl.getExtension('MOZ_EXT_blend_minmax') ||
85 | $wnd.gl.getExtension('WEBKIT_EXT_blend_minmax');
86 | }-*/;
87 | }
88 |
--------------------------------------------------------------------------------
/webgl4j/src/main/java/com/shc/webgl4j/client/EXT_frag_depth.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014-2015 Sri Harsha Chilakapati
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.shc.webgl4j.client;
26 |
27 | /**
28 | * @author Sri Harsha Chilakapati
29 | */
30 | public final class EXT_frag_depth
31 | {
32 | /* Prevent instantiation */
33 | private EXT_frag_depth()
34 | {
35 | }
36 |
37 | public static boolean isSupported()
38 | {
39 | if (!WebGL10.isSupported())
40 | return false;
41 |
42 | if (!WebGL10.isContextCompatible())
43 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to check if extension is supported.");
44 |
45 | for (String supportedExtension : WebGL10.glGetSupportedExtensions())
46 | {
47 | switch (supportedExtension)
48 | {
49 | case "EXT_frag_depth":
50 | case "O_EXT_frag_depth":
51 | case "IE_EXT_frag_depth":
52 | case "MOZ_EXT_frag_depth":
53 | case "WEBKIT_EXT_frag_depth":
54 | return true;
55 | }
56 | }
57 |
58 | return false;
59 | }
60 |
61 | public static void enableExtension()
62 | {
63 | if (!WebGL10.isContextCompatible())
64 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to enable this extension.");
65 |
66 | if (!isSupported())
67 | throw new RuntimeException("This browser does not support the EXT_frag_depth extension.");
68 |
69 | if (!isExtensionEnabled())
70 | nEnableExtension();
71 | }
72 |
73 | public static native boolean isExtensionEnabled() /*-{
74 | return typeof ($wnd.gl.efd_ext) !== 'undefined';
75 | }-*/;
76 |
77 | private static native void nEnableExtension() /*-{
78 | $wnd.gl.efd_ext = $wnd.gl.getExtension('EXT_frag_depth') ||
79 | $wnd.gl.getExtension('O_EXT_frag_depth') ||
80 | $wnd.gl.getExtension('IE_EXT_frag_depth') ||
81 | $wnd.gl.getExtension('MOZ_EXT_frag_depth') ||
82 | $wnd.gl.getExtension('WEBKIT_EXT_frag_depth');
83 | }-*/;
84 | }
85 |
--------------------------------------------------------------------------------
/webgl4j/src/main/java/com/shc/webgl4j/client/EXT_shader_texture_lod.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014-2015 Sri Harsha Chilakapati
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.shc.webgl4j.client;
26 |
27 | /**
28 | * @author Sri Harsha Chilakapati
29 | */
30 | public final class EXT_shader_texture_lod
31 | {
32 | /* Prevent instantiation */
33 | private EXT_shader_texture_lod()
34 | {
35 | }
36 |
37 | public static boolean isSupported()
38 | {
39 | if (!WebGL10.isSupported())
40 | return false;
41 |
42 | if (!WebGL10.isContextCompatible())
43 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to check if extension is supported.");
44 |
45 | for (String supportedExtension : WebGL10.glGetSupportedExtensions())
46 | {
47 | switch (supportedExtension)
48 | {
49 | case "EXT_shader_texture_lod":
50 | case "O_EXT_shader_texture_lod":
51 | case "IE_EXT_shader_texture_lod":
52 | case "MOZ_EXT_shader_texture_lod":
53 | case "WEBKIT_EXT_shader_texture_lod":
54 | return true;
55 | }
56 | }
57 |
58 | return false;
59 | }
60 |
61 | public static void enableExtension()
62 | {
63 | if (!WebGL10.isContextCompatible())
64 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to enable this extension.");
65 |
66 | if (!isSupported())
67 | throw new RuntimeException("This browser does not support the EXT_shader_texture_lod extension.");
68 |
69 | if (!isExtensionEnabled())
70 | nEnableExtension();
71 | }
72 |
73 | public static native boolean isExtensionEnabled() /*-{
74 | return typeof ($wnd.gl.estl_ext) !== 'undefined';
75 | }-*/;
76 |
77 | private static native void nEnableExtension() /*-{
78 | $wnd.gl.estl_ext = $wnd.gl.getExtension('EXT_shader_texture_lod') ||
79 | $wnd.gl.getExtension('O_EXT_shader_texture_lod') ||
80 | $wnd.gl.getExtension('IE_EXT_shader_texture_lod') ||
81 | $wnd.gl.getExtension('MOZ_EXT_shader_texture_lod') ||
82 | $wnd.gl.getExtension('WEBKIT_EXT_shader_texture_lod');
83 | }-*/;
84 | }
85 |
--------------------------------------------------------------------------------
/webgl4j/src/main/java/com/shc/webgl4j/client/EXT_texture_filter_anisotropic.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014-2015 Sri Harsha Chilakapati
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.shc.webgl4j.client;
26 |
27 | /**
28 | * @author Sri Harsha Chilakapati
29 | */
30 | public final class EXT_texture_filter_anisotropic
31 | {
32 | public static final int GL_TEXTURE_MAX_ANISOTROPY_EXT = 0x84FE;
33 | public static final int GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT = 0x84FF;
34 |
35 | /* Prevent instantiation */
36 | private EXT_texture_filter_anisotropic()
37 | {
38 | }
39 |
40 | public static boolean isSupported()
41 | {
42 | if (!WebGL10.isSupported())
43 | return false;
44 |
45 | if (!WebGL10.isContextCompatible())
46 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to check if extension is supported.");
47 |
48 | for (String supportedExtension : WebGL10.glGetSupportedExtensions())
49 | {
50 | switch (supportedExtension)
51 | {
52 | case "EXT_texture_filter_anisotropic":
53 | case "O_EXT_texture_filter_anisotropic":
54 | case "IE_EXT_texture_filter_anisotropic":
55 | case "MOZ_EXT_texture_filter_anisotropic":
56 | case "WEBKIT_EXT_texture_filter_anisotropic":
57 | return true;
58 | }
59 | }
60 |
61 | return false;
62 | }
63 |
64 | public static void enableExtension()
65 | {
66 | if (!WebGL10.isContextCompatible())
67 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to enable this extension.");
68 |
69 | if (!isSupported())
70 | throw new RuntimeException("This browser does not support the EXT_texture_filter_anisotropic extension.");
71 |
72 | if (!isExtensionEnabled())
73 | nEnableExtension();
74 | }
75 |
76 | public static native boolean isExtensionEnabled() /*-{
77 | return typeof ($wnd.gl.etfa_ext) !== 'undefined';
78 | }-*/;
79 |
80 | private static native void nEnableExtension() /*-{
81 | $wnd.gl.etfa_ext = $wnd.gl.getExtension('EXT_texture_filter_anisotropic') ||
82 | $wnd.gl.getExtension('O_EXT_texture_filter_anisotropic') ||
83 | $wnd.gl.getExtension('IE_EXT_texture_filter_anisotropic') ||
84 | $wnd.gl.getExtension('MOZ_EXT_texture_filter_anisotropic') ||
85 | $wnd.gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic');
86 | }-*/;
87 | }
88 |
--------------------------------------------------------------------------------
/webgl4j/src/main/java/com/shc/webgl4j/client/OES_element_index_uint.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014-2015 Sri Harsha Chilakapati
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.shc.webgl4j.client;
26 |
27 | /**
28 | * @author Sri Harsha Chilakapati
29 | */
30 | public final class OES_element_index_uint
31 | {
32 | /* Prevent instantiation */
33 | private OES_element_index_uint()
34 | {
35 | }
36 |
37 | public static boolean isSupported()
38 | {
39 | if (!WebGL10.isSupported())
40 | return false;
41 |
42 | if (!WebGL10.isContextCompatible())
43 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to check if extension is supported.");
44 |
45 | for (String supportedExtension : WebGL10.glGetSupportedExtensions())
46 | {
47 | switch (supportedExtension)
48 | {
49 | case "OES_element_index_uint":
50 | case "O_OES_element_index_uint":
51 | case "IE_OES_element_index_uint":
52 | case "MOZ_OES_element_index_uint":
53 | case "WEBKIT_OES_element_index_uint":
54 | return true;
55 | }
56 | }
57 |
58 | return false;
59 | }
60 |
61 | public static void enableExtension()
62 | {
63 | if (!WebGL10.isContextCompatible())
64 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to enable this extension.");
65 |
66 | if (!isSupported())
67 | throw new RuntimeException("This browser does not support the OES_element_index_uint extension.");
68 |
69 | if (!isExtensionEnabled())
70 | nEnableExtension();
71 | }
72 |
73 | public static native boolean isExtensionEnabled() /*-{
74 | return typeof ($wnd.gl.oeiu_ext) !== 'undefined';
75 | }-*/;
76 |
77 | private static native void nEnableExtension() /*-{
78 | $wnd.gl.oeiu_ext = $wnd.gl.getExtension('OES_element_index_uint') ||
79 | $wnd.gl.getExtension('O_OES_element_index_uint') ||
80 | $wnd.gl.getExtension('IE_OES_element_index_uint') ||
81 | $wnd.gl.getExtension('MOZ_OES_element_index_uint') ||
82 | $wnd.gl.getExtension('WEBKIT_OES_element_index_uint');
83 | }-*/;
84 | }
85 |
--------------------------------------------------------------------------------
/webgl4j/src/main/java/com/shc/webgl4j/client/OES_standard_derivatives.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014-2015 Sri Harsha Chilakapati
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.shc.webgl4j.client;
26 |
27 | /**
28 | * @author Sri Harsha Chilakapati
29 | */
30 | public final class OES_standard_derivatives
31 | {
32 | public static final int GL_FRAGMENT_SHADER_DERIVATIVE_HINT = 0x8B8B;
33 |
34 | /* Prevent instantiation */
35 | private OES_standard_derivatives()
36 | {
37 | }
38 |
39 | public static boolean isSupported()
40 | {
41 | if (!WebGL10.isSupported())
42 | return false;
43 |
44 | if (!WebGL10.isContextCompatible())
45 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to check if extension is supported.");
46 |
47 | for (String supportedExtension : WebGL10.glGetSupportedExtensions())
48 | {
49 | switch (supportedExtension)
50 | {
51 | case "OES_standard_derivatives":
52 | case "O_OES_standard_derivatives":
53 | case "IE_OES_standard_derivatives":
54 | case "MOZ_OES_standard_derivatives":
55 | case "WEBKIT_OES_standard_derivatives":
56 | return true;
57 | }
58 | }
59 |
60 | return false;
61 | }
62 |
63 | public static void enableExtension()
64 | {
65 | if (!WebGL10.isContextCompatible())
66 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to enable this extension.");
67 |
68 | if (!isSupported())
69 | throw new RuntimeException("This browser does not support the OES_standard_derivatives extension.");
70 |
71 | if (!isExtensionEnabled())
72 | nEnableExtension();
73 | }
74 |
75 | public static native boolean isExtensionEnabled() /*-{
76 | return typeof ($wnd.gl.osd_ext) !== 'undefined';
77 | }-*/;
78 |
79 | private static native void nEnableExtension() /*-{
80 | $wnd.gl.osd_ext = $wnd.gl.getExtension('OES_standard_derivatives') ||
81 | $wnd.gl.getExtension('O_OES_standard_derivatives') ||
82 | $wnd.gl.getExtension('IE_OES_standard_derivatives') ||
83 | $wnd.gl.getExtension('MOZ_OES_standard_derivatives') ||
84 | $wnd.gl.getExtension('WEBKIT_OES_standard_derivatives');
85 | }-*/;
86 | }
87 |
--------------------------------------------------------------------------------
/webgl4j/src/main/java/com/shc/webgl4j/client/OES_texture_float.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014-2015 Sri Harsha Chilakapati
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.shc.webgl4j.client;
26 |
27 | /**
28 | * @author Sri Harsha Chilakapati
29 | */
30 | public final class OES_texture_float
31 | {
32 | /* Prevent instantiation */
33 | private OES_texture_float()
34 | {
35 | }
36 |
37 | public static boolean isSupported()
38 | {
39 | if (!WebGL10.isSupported())
40 | return false;
41 |
42 | if (!WebGL10.isContextCompatible())
43 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to check if extension is supported.");
44 |
45 | for (String supportedExtension : WebGL10.glGetSupportedExtensions())
46 | {
47 | switch (supportedExtension)
48 | {
49 | case "OES_texture_float":
50 | case "O_OES_texture_float":
51 | case "IE_OES_texture_float":
52 | case "MOZ_OES_texture_float":
53 | case "WEBKIT_OES_texture_float":
54 | return true;
55 | }
56 | }
57 |
58 | return false;
59 | }
60 |
61 | public static void enableExtension()
62 | {
63 | if (!WebGL10.isContextCompatible())
64 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to enable this extension.");
65 |
66 | if (!isSupported())
67 | throw new RuntimeException("This browser does not support the OES_texture_float extension.");
68 |
69 | if (!isExtensionEnabled())
70 | nEnableExtension();
71 | }
72 |
73 | public static native boolean isExtensionEnabled() /*-{
74 | return typeof ($wnd.gl.otf_ext) !== 'undefined';
75 | }-*/;
76 |
77 | private static native void nEnableExtension() /*-{
78 | $wnd.gl.otf_ext = $wnd.gl.getExtension('OES_texture_float') ||
79 | $wnd.gl.getExtension('O_OES_texture_float') ||
80 | $wnd.gl.getExtension('IE_OES_texture_float') ||
81 | $wnd.gl.getExtension('MOZ_OES_texture_float') ||
82 | $wnd.gl.getExtension('WEBKIT_OES_texture_float');
83 | }-*/;
84 | }
85 |
--------------------------------------------------------------------------------
/webgl4j/src/main/java/com/shc/webgl4j/client/OES_texture_float_linear.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014-2015 Sri Harsha Chilakapati
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.shc.webgl4j.client;
26 |
27 | /**
28 | * @author Sri Harsha Chilakapati
29 | */
30 | public final class OES_texture_float_linear
31 | {
32 | /* Prevent instantiation */
33 | private OES_texture_float_linear()
34 | {
35 | }
36 |
37 | public static boolean isSupported()
38 | {
39 | if (!WebGL10.isSupported())
40 | return false;
41 |
42 | if (!WebGL10.isContextCompatible())
43 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to check if extension is supported.");
44 |
45 | for (String supportedExtension : WebGL10.glGetSupportedExtensions())
46 | {
47 | switch (supportedExtension)
48 | {
49 | case "OES_texture_float_linear":
50 | case "O_OES_texture_float_linear":
51 | case "IE_OES_texture_float_linear":
52 | case "MOZ_OES_texture_float_linear":
53 | case "WEBKIT_OES_texture_float_linear":
54 | return true;
55 | }
56 | }
57 |
58 | return false;
59 | }
60 |
61 | public static void enableExtension()
62 | {
63 | if (!WebGL10.isContextCompatible())
64 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to enable this extension.");
65 |
66 | if (!isSupported())
67 | throw new RuntimeException("This browser does not support the OES_texture_float_linear extension.");
68 |
69 | if (!isExtensionEnabled())
70 | nEnableExtension();
71 | }
72 |
73 | public static native boolean isExtensionEnabled() /*-{
74 | return typeof ($wnd.gl.otfl_ext) !== 'undefined';
75 | }-*/;
76 |
77 | private static native void nEnableExtension() /*-{
78 | $wnd.gl.otfl_ext = $wnd.gl.getExtension('OES_texture_float_linear') ||
79 | $wnd.gl.getExtension('O_OES_texture_float_linear') ||
80 | $wnd.gl.getExtension('IE_OES_texture_float_linear') ||
81 | $wnd.gl.getExtension('MOZ_OES_texture_float_linear') ||
82 | $wnd.gl.getExtension('WEBKIT_OES_texture_float_linear');
83 | }-*/;
84 | }
85 |
--------------------------------------------------------------------------------
/webgl4j/src/main/java/com/shc/webgl4j/client/OES_texture_half_float.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014-2015 Sri Harsha Chilakapati
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.shc.webgl4j.client;
26 |
27 | /**
28 | * @author Sri Harsha Chilakapati
29 | */
30 | public final class OES_texture_half_float
31 | {
32 | public static final int GL_HALF_FLOAT_OES = 0x8D61;
33 |
34 | /* Prevent instantiation */
35 | private OES_texture_half_float()
36 | {
37 | }
38 |
39 | public static boolean isSupported()
40 | {
41 | if (!WebGL10.isSupported())
42 | return false;
43 |
44 | if (!WebGL10.isContextCompatible())
45 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to check if extension is supported.");
46 |
47 | for (String supportedExtension : WebGL10.glGetSupportedExtensions())
48 | {
49 | switch (supportedExtension)
50 | {
51 | case "OES_texture_half_float":
52 | case "O_OES_texture_half_float":
53 | case "IE_OES_texture_half_float":
54 | case "MOZ_OES_texture_half_float":
55 | case "WEBKIT_OES_texture_half_float":
56 | return true;
57 | }
58 | }
59 |
60 | return false;
61 | }
62 |
63 | public static void enableExtension()
64 | {
65 | if (!WebGL10.isContextCompatible())
66 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to enable this extension.");
67 |
68 | if (!isSupported())
69 | throw new RuntimeException("This browser does not support the OES_texture_half_float extension.");
70 |
71 | if (!isExtensionEnabled())
72 | nEnableExtension();
73 | }
74 |
75 | public static native boolean isExtensionEnabled() /*-{
76 | return typeof ($wnd.gl.othf_ext) !== 'undefined';
77 | }-*/;
78 |
79 | private static native void nEnableExtension() /*-{
80 | $wnd.gl.othf_ext = $wnd.gl.getExtension('OES_texture_half_float') ||
81 | $wnd.gl.getExtension('O_OES_texture_half_float') ||
82 | $wnd.gl.getExtension('IE_OES_texture_half_float') ||
83 | $wnd.gl.getExtension('MOZ_OES_texture_half_float') ||
84 | $wnd.gl.getExtension('WEBKIT_OES_texture_half_float');
85 | }-*/;
86 | }
87 |
--------------------------------------------------------------------------------
/webgl4j/src/main/java/com/shc/webgl4j/client/OES_texture_half_float_linear.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014-2015 Sri Harsha Chilakapati
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.shc.webgl4j.client;
26 |
27 | /**
28 | * @author Sri Harsha Chilakapati
29 | */
30 | public final class OES_texture_half_float_linear
31 | {
32 | /* Prevent instantiation */
33 | private OES_texture_half_float_linear()
34 | {
35 | }
36 |
37 | public static boolean isSupported()
38 | {
39 | if (!WebGL10.isSupported())
40 | return false;
41 |
42 | if (!WebGL10.isContextCompatible())
43 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to check if extension is supported.");
44 |
45 | for (String supportedExtension : WebGL10.glGetSupportedExtensions())
46 | {
47 | switch (supportedExtension)
48 | {
49 | case "OES_texture_half_float_linear":
50 | case "O_OES_texture_half_float_linear":
51 | case "IE_OES_texture_half_float_linear":
52 | case "MOZ_OES_texture_half_float_linear":
53 | case "WEBKIT_OES_texture_half_float_linear":
54 | return true;
55 | }
56 | }
57 |
58 | return false;
59 | }
60 |
61 | public static void enableExtension()
62 | {
63 | if (!WebGL10.isContextCompatible())
64 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to enable this extension.");
65 |
66 | if (!isSupported())
67 | throw new RuntimeException("This browser does not support the OES_texture_half_float_linear extension.");
68 |
69 | if (!isExtensionEnabled())
70 | nEnableExtension();
71 | }
72 |
73 | public static native boolean isExtensionEnabled() /*-{
74 | return typeof ($wnd.gl.othfl_ext) !== 'undefined';
75 | }-*/;
76 |
77 | private static native void nEnableExtension() /*-{
78 | $wnd.gl.othfl_ext = $wnd.gl.getExtension('OES_texture_half_float_linear') ||
79 | $wnd.gl.getExtension('O_OES_texture_half_float_linear') ||
80 | $wnd.gl.getExtension('IE_OES_texture_half_float_linear') ||
81 | $wnd.gl.getExtension('MOZ_OES_texture_half_float_linear') ||
82 | $wnd.gl.getExtension('WEBKIT_OES_texture_half_float_linear');
83 | }-*/;
84 | }
85 |
--------------------------------------------------------------------------------
/webgl4j/src/main/java/com/shc/webgl4j/client/OES_vertex_array_object.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014-2015 Sri Harsha Chilakapati
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.shc.webgl4j.client;
26 |
27 | import com.google.gwt.core.client.JavaScriptObject;
28 |
29 | /**
30 | * @author Sri Harsha Chilakapati
31 | */
32 | public final class OES_vertex_array_object
33 | {
34 | public static final int GL_VERTEX_ARRAY_BINDING_OES = 0x85B5;
35 |
36 | /* Prevent instantiation */
37 | private OES_vertex_array_object()
38 | {
39 | }
40 |
41 | public static boolean isSupported()
42 | {
43 | if (!WebGL10.isSupported())
44 | return false;
45 |
46 | if (!WebGL10.isContextCompatible())
47 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to check if extension is supported.");
48 |
49 | for (String supportedExtension : WebGL10.glGetSupportedExtensions())
50 | {
51 | switch (supportedExtension)
52 | {
53 | case "OES_vertex_array_object":
54 | case "O_OES_vertex_array_object":
55 | case "IE_OES_vertex_array_object":
56 | case "MOZ_OES_vertex_array_object":
57 | case "WEBKIT_OES_vertex_array_object":
58 | return true;
59 | }
60 | }
61 |
62 | return false;
63 | }
64 |
65 | public static void enableExtension()
66 | {
67 | if (!WebGL10.isContextCompatible())
68 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to enable this extension.");
69 |
70 | if (!isSupported())
71 | throw new RuntimeException("This browser does not support the OES_vertex_array_object extension.");
72 |
73 | if (!isExtensionEnabled())
74 | nEnableExtension();
75 | }
76 |
77 | private static void checkExtension()
78 | {
79 | if (!WebGL10.isContextCompatible())
80 | throw new RuntimeException("You must create a WebGL context before accessing extension methods.");
81 |
82 | if (!isExtensionEnabled())
83 | throw new IllegalStateException("Extension must be enabled before using any members.");
84 | }
85 |
86 | public static native boolean isExtensionEnabled() /*-{
87 | return typeof ($wnd.gl.ovao_ext) !== 'undefined';
88 | }-*/;
89 |
90 | public static void glBindVertexArrayOES(int vertexArrayOES)
91 | {
92 | checkExtension();
93 | nglBindVertexArrayOES(WebGLObjectMap.get().toVertexArrayObject(vertexArrayOES));
94 | }
95 |
96 | public static int glCreateVertexArrayOES()
97 | {
98 | checkExtension();
99 | return WebGLObjectMap.get().createVertexArrayObject(nglCreateVertexArrayOES());
100 | }
101 |
102 | public static void glDeleteVertexArrayOES(int vertexArrayOES)
103 | {
104 | checkExtension();
105 | nglDeleteVertexArrayOES(WebGLObjectMap.get().toVertexArrayObject(vertexArrayOES));
106 | WebGLObjectMap.get().deleteVertexArrayObject(vertexArrayOES);
107 | }
108 |
109 | @WebGLContext.HandlesContextLoss
110 | public static boolean glIsVertexArrayOES(int vertexArrayOES)
111 | {
112 | checkExtension();
113 | return nglIsVertexArrayOES(WebGLObjectMap.get().toVertexArrayObject(vertexArrayOES));
114 | }
115 |
116 | private static native void nEnableExtension() /*-{
117 | $wnd.gl.ovao_ext = $wnd.gl.getExtension('OES_vertex_array_object') ||
118 | $wnd.gl.getExtension('O_OES_vertex_array_object') ||
119 | $wnd.gl.getExtension('IE_OES_vertex_array_object') ||
120 | $wnd.gl.getExtension('MOZ_OES_vertex_array_object') ||
121 | $wnd.gl.getExtension('WEBKIT_OES_vertex_array_object');
122 | }-*/;
123 |
124 | private static native void nglBindVertexArrayOES(JavaScriptObject vertexArrayOES) /*-{
125 | $wnd.gl.ovao_ext.bindVertexArrayOES(vertexArrayOES);
126 | }-*/;
127 |
128 | private static native JavaScriptObject nglCreateVertexArrayOES() /*-{
129 | return $wnd.gl.ovao_ext.createVertexArrayOES();
130 | }-*/;
131 |
132 | private static native void nglDeleteVertexArrayOES(JavaScriptObject vertexArrayOES) /*-{
133 | $wnd.gl.ovao_ext.deleteVertexArrayOES(vertexArrayOES);
134 | }-*/;
135 |
136 | private static native boolean nglIsVertexArrayOES(JavaScriptObject vertexArrayOES) /*-{
137 | return $wnd.gl.ovao_ext.isVertexArrayOES(vertexArrayOES);
138 | }-*/;
139 | }
140 |
--------------------------------------------------------------------------------
/webgl4j/src/main/java/com/shc/webgl4j/client/TimeUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014-2015 Sri Harsha Chilakapati
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.shc.webgl4j.client;
26 |
27 | /**
28 | * Provides access to a high performance timer. This class creates a polyfill function on first access that uses the
29 | * following APIs in the priority of given order.
30 | *
31 | *
32 | * {@code window.performance.now()} → {@code window.performance.webkitNow()} → {@code Date.now()}
33 | *
34 | *
35 | * The first two are high performance timers, which provide timestamps with microsecond precision. The last one is a
36 | * low performance timer and is used as a fallback when the first two are not available. At first we check if the
37 | * {@code window.performance.now()} is supported or not. If not then a check is performed for {@code window.performance
38 | * .webkitNow()} and finally if everything fails we use {@code Date.now()} as the last option.
39 | *
40 | * @author Sri Harsha Chilakapati
41 | */
42 | public final class TimeUtil
43 | {
44 | private static Implementation implementation = Implementation.HIGH_PERFORMANCE;
45 |
46 | /**
47 | * Prevent instantiation
48 | */
49 | private TimeUtil()
50 | {
51 | }
52 |
53 | private static native boolean isInitialized() /*-{
54 | return !!$wnd['currentMillis'];
55 | }-*/;
56 |
57 | private static native void initialize() /*-{
58 | var currentMillis;
59 | if ($wnd.performance.now)
60 | {
61 | @com.shc.webgl4j.client.TimeUtil::implementation
62 | = @com.shc.webgl4j.client.TimeUtil.Implementation::HIGH_PERFORMANCE;
63 |
64 | currentMillis = function (){ return $wnd.performance.now(); }
65 | }
66 | else if ($wnd.performance.webkitNow)
67 | {
68 | @com.shc.webgl4j.client.TimeUtil::implementation
69 | = @com.shc.webgl4j.client.TimeUtil.Implementation::HIGH_PERFORMANCE_WEBKIT;
70 |
71 | currentMillis = function (){ return $wnd.performance.webkitNow(); }
72 | }
73 | else
74 | {
75 | @com.shc.webgl4j.client.TimeUtil::implementation
76 | = @com.shc.webgl4j.client.TimeUtil.Implementation::LOW_PERFORMANCE;
77 |
78 | currentMillis = function (){ return Date.now(); }
79 | }
80 |
81 | $wnd.currentMillis = currentMillis;
82 | }-*/;
83 |
84 | private static native double nGetTimeStamp() /*-{
85 | return $wnd.currentMillis();
86 | }-*/;
87 |
88 | /**
89 | * Returns the current time stamp in the unit of seconds. This method does multiply the current milli seconds by
90 | * {@literal 0.001} to convert them into seconds.
91 | *
92 | * @return The current time stamp in the unit of seconds.
93 | */
94 | public static double currentSeconds()
95 | {
96 | return currentMillis() * 0.001;
97 | }
98 |
99 | /**
100 | * Returns the current time stamp in the unit of milli seconds. This method simply returns the value returned by the
101 | * underlying high performance timer which by default returns milli seconds.
102 | *
103 | * @return The current time stamp in the unit of milli seconds.
104 | */
105 | public static double currentMillis()
106 | {
107 | if (!isInitialized())
108 | initialize();
109 |
110 | return nGetTimeStamp();
111 | }
112 |
113 | /**
114 | * Returns the current time stamp in the unit of micro seconds. This method does multiply the current milli seconds
115 | * by {@literal 1000} to convert them into micro seconds.
116 | *
117 | * @return The current time stamp in the unit of micro seconds.
118 | */
119 | public static double currentMicros()
120 | {
121 | return currentMillis() * 1000;
122 | }
123 |
124 | /**
125 | * Returns the current time stamp in the unit of nano seconds. This method does multiply the current milli seconds
126 | * by {@literal 1000000} to convert them into nano seconds. This however will not be so accurate as the browsers as
127 | * of now only provide timers to the microsecond resolution.
128 | *
129 | * @return The current time stamp in the unit of nano seconds.
130 | */
131 | public static double currentNanos()
132 | {
133 | return currentMicros() * 1000;
134 | }
135 |
136 | /**
137 | * Returns the implementation that this polyfill uses. It might be {@code window.performance.now()} in the best case
138 | * or {@code window.performance.webkitNow()} in the average case. In the worst case if both those timers are not
139 | * available, that is we are using {@code Date.now()} it returns {@link Implementation#LOW_PERFORMANCE}.
140 | *
141 | * @return Returns an enum describing which implementation that this timer polyfill is using.
142 | */
143 | public static Implementation getImplementation()
144 | {
145 | if (!isInitialized())
146 | initialize();
147 |
148 | return implementation;
149 | }
150 |
151 | /**
152 | * An enumeration used to describe the method this polyfill is using to report time stamps.
153 | */
154 | public enum Implementation
155 | {
156 | /**
157 | * Corresponds to {@code window.performance.now()}
158 | */
159 | HIGH_PERFORMANCE,
160 |
161 | /**
162 | * Corresponds to {@code window.performance.webkitNow()}
163 | */
164 | HIGH_PERFORMANCE_WEBKIT,
165 |
166 | /**
167 | * Corresponds to {@code Date.now()}
168 | */
169 | LOW_PERFORMANCE
170 | }
171 | }
172 |
--------------------------------------------------------------------------------
/webgl4j/src/main/java/com/shc/webgl4j/client/WEBGL_compressed_texture_s3tc.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014-2015 Sri Harsha Chilakapati
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.shc.webgl4j.client;
26 |
27 | /**
28 | * @author Sri Harsha Chilakapati
29 | */
30 | public final class WEBGL_compressed_texture_s3tc
31 | {
32 | public static final int GL_COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83F0;
33 | public static final int GL_COMPRESSED_RGBA_S3TC_DXT1_EXT = 0x83F1;
34 | public static final int GL_COMPRESSED_RGBA_S3TC_DXT3_EXT = 0x83F2;
35 | public static final int GL_COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83F3;
36 |
37 | /* Prevent instantiation */
38 | private WEBGL_compressed_texture_s3tc()
39 | {
40 | }
41 |
42 | public static boolean isSupported()
43 | {
44 | if (!WebGL10.isSupported())
45 | return false;
46 |
47 | if (!WebGL10.isContextCompatible())
48 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to check if extension is supported.");
49 |
50 | for (String supportedExtension : WebGL10.glGetSupportedExtensions())
51 | {
52 | switch (supportedExtension)
53 | {
54 | case "WEBGL_compressed_texture_s3tc":
55 | case "O_WEBGL_compressed_texture_s3tc":
56 | case "IE_WEBGL_compressed_texture_s3tc":
57 | case "MOZ_WEBGL_compressed_texture_s3tc":
58 | case "WEBKIT_WEBGL_compressed_texture_s3tc":
59 | return true;
60 | }
61 | }
62 |
63 | return false;
64 | }
65 |
66 | public static void enableExtension()
67 | {
68 | if (!WebGL10.isContextCompatible())
69 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to enable this extension.");
70 |
71 | if (!isSupported())
72 | throw new RuntimeException("This browser does not support the WEBGL_compressed_texture_s3tc extension.");
73 |
74 | if (!isExtensionEnabled())
75 | nEnableExtension();
76 | }
77 |
78 | public static native boolean isExtensionEnabled() /*-{
79 | return typeof ($wnd.gl.wcts_ext) !== 'undefined';
80 | }-*/;
81 |
82 | private static native void nEnableExtension() /*-{
83 | $wnd.gl.wcts_ext = $wnd.gl.getExtension('WEBGL_compressed_texture_s3tc') ||
84 | $wnd.gl.getExtension('O_WEBGL_compressed_texture_s3tc') ||
85 | $wnd.gl.getExtension('IE_WEBGL_compressed_texture_s3tc') ||
86 | $wnd.gl.getExtension('MOZ_WEBGL_compressed_texture_s3tc') ||
87 | $wnd.gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');
88 | }-*/;
89 | }
90 |
--------------------------------------------------------------------------------
/webgl4j/src/main/java/com/shc/webgl4j/client/WEBGL_debug_renderer_info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014-2015 Sri Harsha Chilakapati
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.shc.webgl4j.client;
26 |
27 | /**
28 | * @author Sri Harsha Chilakapati
29 | */
30 | public final class WEBGL_debug_renderer_info
31 | {
32 | public static final int GL_UNMASKED_VENDOR_WEBGL = 0x9245;
33 | public static final int GL_UNMASKED_RENDERER_WEBGL = 0x9246;
34 |
35 | /* Prevent instantiation */
36 | private WEBGL_debug_renderer_info()
37 | {
38 | }
39 |
40 | public static boolean isSupported()
41 | {
42 | if (!WebGL10.isSupported())
43 | return false;
44 |
45 | if (!WebGL10.isContextCompatible())
46 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to check if extension is supported.");
47 |
48 | for (String supportedExtension : WebGL10.glGetSupportedExtensions())
49 | {
50 | switch (supportedExtension)
51 | {
52 | case "WEBGL_debug_renderer_info":
53 | case "O_WEBGL_debug_renderer_info":
54 | case "IE_WEBGL_debug_renderer_info":
55 | case "MOZ_WEBGL_debug_renderer_info":
56 | case "WEBKIT_WEBGL_debug_renderer_info":
57 | return true;
58 | }
59 | }
60 |
61 | return false;
62 | }
63 |
64 | public static void enableExtension()
65 | {
66 | if (!WebGL10.isContextCompatible())
67 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to enable this extension.");
68 |
69 | if (!isSupported())
70 | throw new RuntimeException("This browser does not support the WEBGL_debug_renderer_info extension.");
71 |
72 | if (!isExtensionEnabled())
73 | nEnableExtension();
74 | }
75 |
76 | public static native boolean isExtensionEnabled() /*-{
77 | return typeof ($wnd.gl.wdri_ext) !== 'undefined';
78 | }-*/;
79 |
80 | private static native void nEnableExtension() /*-{
81 | $wnd.gl.wdri_ext = $wnd.gl.getExtension('WEBGL_debug_renderer_info') ||
82 | $wnd.gl.getExtension('O_WEBGL_debug_renderer_info') ||
83 | $wnd.gl.getExtension('IE_WEBGL_debug_renderer_info') ||
84 | $wnd.gl.getExtension('MOZ_WEBGL_debug_renderer_info') ||
85 | $wnd.gl.getExtension('WEBKIT_WEBGL_debug_renderer_info');
86 | }-*/;
87 | }
88 |
--------------------------------------------------------------------------------
/webgl4j/src/main/java/com/shc/webgl4j/client/WEBGL_debug_shaders.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014-2015 Sri Harsha Chilakapati
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.shc.webgl4j.client;
26 |
27 | import com.google.gwt.core.client.JavaScriptObject;
28 |
29 | /**
30 | * @author Sri Harsha Chilakapati
31 | */
32 | public final class WEBGL_debug_shaders
33 | {
34 | /* Prevent instantiation */
35 | private WEBGL_debug_shaders()
36 | {
37 | }
38 |
39 | public static boolean isSupported()
40 | {
41 | if (!WebGL10.isSupported())
42 | return false;
43 |
44 | if (!WebGL10.isContextCompatible())
45 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to check if extension is supported.");
46 |
47 | for (String supportedExtension : WebGL10.glGetSupportedExtensions())
48 | {
49 | switch (supportedExtension)
50 | {
51 | case "WEBGL_debug_shaders":
52 | case "O_WEBGL_debug_shaders":
53 | case "IE_WEBGL_debug_shaders":
54 | case "MOZ_WEBGL_debug_shaders":
55 | case "WEBKIT_WEBGL_debug_shaders":
56 | return true;
57 | }
58 | }
59 |
60 | return false;
61 | }
62 |
63 | public static void enableExtension()
64 | {
65 | if (!WebGL10.isContextCompatible())
66 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to enable this extension.");
67 |
68 | if (!isSupported())
69 | throw new RuntimeException("This browser does not support the WEBGL_debug_shaders extension.");
70 |
71 | if (!isExtensionEnabled())
72 | nEnableExtension();
73 | }
74 |
75 | private static void checkExtension()
76 | {
77 | if (!WebGL10.isContextCompatible())
78 | throw new RuntimeException("You must create a WebGL context before accessing extension methods.");
79 |
80 | if (!isExtensionEnabled())
81 | throw new IllegalStateException("Extension must be enabled before using any members.");
82 | }
83 |
84 | public static String glGetTranslatedShaderSource(int shader)
85 | {
86 | checkExtension();
87 | return nglGetTranslatedShaderSource(WebGLObjectMap.get().toShader(shader));
88 | }
89 |
90 | public static native boolean isExtensionEnabled() /*-{
91 | return typeof ($wnd.gl.wds_ext) !== 'undefined';
92 | }-*/;
93 |
94 | private static native void nEnableExtension() /*-{
95 | $wnd.gl.wds_ext = $wnd.gl.getExtension('WEBGL_debug_shaders') ||
96 | $wnd.gl.getExtension('O_WEBGL_debug_shaders') ||
97 | $wnd.gl.getExtension('IE_WEBGL_debug_shaders') ||
98 | $wnd.gl.getExtension('MOZ_WEBGL_debug_shaders') ||
99 | $wnd.gl.getExtension('WEBKIT_WEBGL_debug_shaders');
100 | }-*/;
101 |
102 | private static native String nglGetTranslatedShaderSource(JavaScriptObject shader) /*-{
103 | return $wnd.gl.wds_ext.getTranslatedShaderSource(shader);
104 | }-*/;
105 | }
106 |
--------------------------------------------------------------------------------
/webgl4j/src/main/java/com/shc/webgl4j/client/WEBGL_depth_texture.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014-2015 Sri Harsha Chilakapati
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.shc.webgl4j.client;
26 |
27 | /**
28 | * @author Sri Harsha Chilakapati
29 | */
30 | public final class WEBGL_depth_texture
31 | {
32 | public static final int GL_UNSIGNED_INT_24_8_WEBGL = 0x84FA;
33 |
34 | /* Prevent instantiation */
35 | private WEBGL_depth_texture()
36 | {
37 | }
38 |
39 | public static boolean isSupported()
40 | {
41 | if (!WebGL10.isSupported())
42 | return false;
43 |
44 | if (!WebGL10.isContextCompatible())
45 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to check if extension is supported.");
46 |
47 | for (String supportedExtension : WebGL10.glGetSupportedExtensions())
48 | {
49 | switch (supportedExtension)
50 | {
51 | case "WEBGL_depth_texture":
52 | case "O_WEBGL_depth_texture":
53 | case "IE_WEBGL_depth_texture":
54 | case "MOZ_WEBGL_depth_texture":
55 | case "WEBKIT_WEBGL_depth_texture":
56 | return true;
57 | }
58 | }
59 |
60 | return false;
61 | }
62 |
63 | public static void enableExtension()
64 | {
65 | if (!WebGL10.isContextCompatible())
66 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to enable this extension.");
67 |
68 | if (!isSupported())
69 | throw new RuntimeException("This browser does not support the WEBGL_depth_texture extension.");
70 |
71 | if (!isExtensionEnabled())
72 | nEnableExtension();
73 | }
74 |
75 | public static native boolean isExtensionEnabled() /*-{
76 | return typeof ($wnd.gl.wdt_ext) !== 'undefined';
77 | }-*/;
78 |
79 | private static native void nEnableExtension() /*-{
80 | $wnd.gl.wdt_ext = $wnd.gl.getExtension('WEBGL_depth_texture') ||
81 | $wnd.gl.getExtension('O_WEBGL_depth_texture') ||
82 | $wnd.gl.getExtension('IE_WEBGL_depth_texture') ||
83 | $wnd.gl.getExtension('MOZ_WEBGL_depth_texture') ||
84 | $wnd.gl.getExtension('WEBKIT_WEBGL_depth_texture');
85 | }-*/;
86 | }
87 |
--------------------------------------------------------------------------------
/webgl4j/src/main/java/com/shc/webgl4j/client/WEBGL_draw_buffers.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014-2015 Sri Harsha Chilakapati
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.shc.webgl4j.client;
26 |
27 | import com.google.gwt.core.client.JsArrayInteger;
28 | import com.google.gwt.typedarrays.shared.Int32Array;
29 |
30 | /**
31 | * @author Sri Harsha Chilakapati
32 | */
33 | public final class WEBGL_draw_buffers
34 | {
35 | public static final int GL_COLOR_ATTACHMENT0_WEBGL = 0x8CE0;
36 | public static final int GL_COLOR_ATTACHMENT1_WEBGL = 0x8CE1;
37 | public static final int GL_COLOR_ATTACHMENT2_WEBGL = 0x8CE2;
38 | public static final int GL_COLOR_ATTACHMENT3_WEBGL = 0x8CE3;
39 | public static final int GL_COLOR_ATTACHMENT4_WEBGL = 0x8CE4;
40 | public static final int GL_COLOR_ATTACHMENT5_WEBGL = 0x8CE5;
41 | public static final int GL_COLOR_ATTACHMENT6_WEBGL = 0x8CE6;
42 | public static final int GL_COLOR_ATTACHMENT7_WEBGL = 0x8CE7;
43 | public static final int GL_COLOR_ATTACHMENT8_WEBGL = 0x8CE8;
44 | public static final int GL_COLOR_ATTACHMENT9_WEBGL = 0x8CE9;
45 | public static final int GL_COLOR_ATTACHMENT10_WEBGL = 0x8CEA;
46 | public static final int GL_COLOR_ATTACHMENT11_WEBGL = 0x8CEB;
47 | public static final int GL_COLOR_ATTACHMENT12_WEBGL = 0x8CEC;
48 | public static final int GL_COLOR_ATTACHMENT13_WEBGL = 0x8CED;
49 | public static final int GL_COLOR_ATTACHMENT14_WEBGL = 0x8CEE;
50 | public static final int GL_COLOR_ATTACHMENT15_WEBGL = 0x8CEF;
51 |
52 | public static final int GL_DRAW_BUFFER0_WEBGL = 0x8825;
53 | public static final int GL_DRAW_BUFFER1_WEBGL = 0x8826;
54 | public static final int GL_DRAW_BUFFER2_WEBGL = 0x8827;
55 | public static final int GL_DRAW_BUFFER3_WEBGL = 0x8828;
56 | public static final int GL_DRAW_BUFFER4_WEBGL = 0x8829;
57 | public static final int GL_DRAW_BUFFER5_WEBGL = 0x882A;
58 | public static final int GL_DRAW_BUFFER6_WEBGL = 0x882B;
59 | public static final int GL_DRAW_BUFFER7_WEBGL = 0x882C;
60 | public static final int GL_DRAW_BUFFER8_WEBGL = 0x882D;
61 | public static final int GL_DRAW_BUFFER9_WEBGL = 0x882E;
62 | public static final int GL_DRAW_BUFFER10_WEBGL = 0x882F;
63 | public static final int GL_DRAW_BUFFER11_WEBGL = 0x8830;
64 | public static final int GL_DRAW_BUFFER12_WEBGL = 0x8831;
65 | public static final int GL_DRAW_BUFFER13_WEBGL = 0x8832;
66 | public static final int GL_DRAW_BUFFER14_WEBGL = 0x8833;
67 | public static final int GL_DRAW_BUFFER15_WEBGL = 0x8834;
68 |
69 | public static final int GL_MAX_COLOR_ATTACHMENTS_WEBGL = 0x8CDF;
70 | public static final int GL_MAX_DRAW_BUFFERS_WEBGL = 0x8824;
71 |
72 | /* Prevent instantiation */
73 | private WEBGL_draw_buffers()
74 | {
75 | }
76 |
77 | public static boolean isSupported()
78 | {
79 | if (!WebGL10.isSupported())
80 | return false;
81 |
82 | if (!WebGL10.isContextCompatible())
83 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to check if extension is supported.");
84 |
85 | for (String supportedExtension : WebGL10.glGetSupportedExtensions())
86 | {
87 | switch (supportedExtension)
88 | {
89 | case "WEBGL_draw_buffers":
90 | case "O_WEBGL_draw_buffers":
91 | case "IE_WEBGL_draw_buffers":
92 | case "MOZ_WEBGL_draw_buffers":
93 | case "WEBKIT_WEBGL_draw_buffers":
94 | return true;
95 | }
96 | }
97 |
98 | return false;
99 | }
100 |
101 | public static void enableExtension()
102 | {
103 | if (!WebGL10.isContextCompatible())
104 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to enable this extension.");
105 |
106 | if (!isSupported())
107 | throw new RuntimeException("This browser does not support the WEBGL_draw_buffers extension.");
108 |
109 | if (!isExtensionEnabled())
110 | nEnableExtension();
111 | }
112 |
113 | private static void checkExtension()
114 | {
115 | if (!WebGL10.isContextCompatible())
116 | throw new RuntimeException("You must create a WebGL context before accessing extension methods.");
117 |
118 | if (!isExtensionEnabled())
119 | throw new IllegalStateException("Extension must be enabled before using any members.");
120 | }
121 |
122 | public static void glDrawBuffersWEBGL(JsArrayInteger buffers)
123 | {
124 | checkExtension();
125 | nglDrawBuffersWEBGL(buffers);
126 | }
127 |
128 | public static void glDrawBuffersWEBGL(int... buffers)
129 | {
130 | JsArrayInteger array = JsArrayInteger.createArray(buffers.length).cast();
131 |
132 | for (int buffer : buffers)
133 | array.push(buffer);
134 |
135 | glDrawBuffersWEBGL(array);
136 | }
137 |
138 | public static void glDrawBuffersWEBGL(Int32Array buffers)
139 | {
140 | JsArrayInteger array = JsArrayInteger.createArray(buffers.length()).cast();
141 |
142 | for (int i = 0; i < buffers.length(); i++)
143 | array.push(buffers.get(i));
144 |
145 | glDrawBuffersWEBGL(array);
146 | }
147 |
148 | public static native boolean isExtensionEnabled() /*-{
149 | return typeof ($wnd.gl.wdb_ext) !== 'undefined';
150 | }-*/;
151 |
152 | private static native void nEnableExtension() /*-{
153 | $wnd.gl.wdb_ext = $wnd.gl.getExtension('WEBGL_draw_buffers') ||
154 | $wnd.gl.getExtension('O_WEBGL_draw_buffers') ||
155 | $wnd.gl.getExtension('IE_WEBGL_draw_buffers') ||
156 | $wnd.gl.getExtension('MOZ_WEBGL_draw_buffers') ||
157 | $wnd.gl.getExtension('WEBKIT_WEBGL_draw_buffers');
158 | }-*/;
159 |
160 | private static native void nglDrawBuffersWEBGL(JsArrayInteger buffers) /*-{
161 | $wnd.gl.wdb_ext.drawBuffersWEBGL(buffers);
162 | }-*/;
163 | }
164 |
--------------------------------------------------------------------------------
/webgl4j/src/main/java/com/shc/webgl4j/client/WEBGL_lose_context.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014-2015 Sri Harsha Chilakapati
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.shc.webgl4j.client;
26 |
27 | /**
28 | * @author Sri Harsha Chilakapati
29 | */
30 | public final class WEBGL_lose_context
31 | {
32 | /* Prevent instantiation */
33 | private WEBGL_lose_context()
34 | {
35 | }
36 |
37 | public static boolean isSupported()
38 | {
39 | if (!WebGL10.isSupported())
40 | return false;
41 |
42 | if (!WebGL10.isContextCompatible())
43 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to check if extension is supported.");
44 |
45 | for (String supportedExtension : WebGL10.glGetSupportedExtensions())
46 | {
47 | switch (supportedExtension)
48 | {
49 | case "WEBGL_lose_context":
50 | case "O_WEBGL_lose_context":
51 | case "IE_WEBGL_lose_context":
52 | case "MOZ_WEBGL_lose_context":
53 | case "WEBKIT_WEBGL_lose_context":
54 | return true;
55 | }
56 | }
57 |
58 | return false;
59 | }
60 |
61 | public static void enableExtension()
62 | {
63 | if (!WebGL10.isContextCompatible())
64 | throw new IllegalStateException("You must have a WebGL context >= 1.0 to enable this extension.");
65 |
66 | if (!isSupported())
67 | throw new RuntimeException("This browser does not support the WEBGL_lose_context extension.");
68 |
69 | if (!isExtensionEnabled())
70 | nEnableExtension();
71 | }
72 |
73 | private static void checkExtension()
74 | {
75 | if (!WebGL10.isContextCompatible())
76 | throw new RuntimeException("You must create a WebGL context before accessing extension methods.");
77 |
78 | if (!isExtensionEnabled())
79 | throw new IllegalStateException("Extension must be enabled before using any members.");
80 | }
81 |
82 | public static void glLoseContext()
83 | {
84 | checkExtension();
85 | nglLoseContext();
86 | }
87 |
88 | public static void glRestoreContext()
89 | {
90 | checkExtension();
91 | nglRestoreContext();
92 | }
93 |
94 | public static native boolean isExtensionEnabled() /*-{
95 | return typeof ($wnd.gl.wlc_ext) !== 'undefined';
96 | }-*/;
97 |
98 | private static native void nEnableExtension() /*-{
99 | $wnd.gl.wlc_ext = $wnd.gl.getExtension('WEBGL_lose_context') ||
100 | $wnd.gl.getExtension('O_WEBGL_lose_context') ||
101 | $wnd.gl.getExtension('IE_WEBGL_lose_context') ||
102 | $wnd.gl.getExtension('MOZ_WEBGL_lose_context') ||
103 | $wnd.gl.getExtension('WEBKIT_WEBGL_lose_context');
104 | }-*/;
105 |
106 | private static native void nglLoseContext() /*-{
107 | $wnd.gl.wlc_ext.loseContext();
108 | }-*/;
109 |
110 | private static native void nglRestoreContext() /*-{
111 | $wnd.gl.wlc_ext.restoreContext();
112 | }-*/;
113 | }
114 |
--------------------------------------------------------------------------------
/webgl4j/src/main/java/com/shc/webgl4j/client/WebGLContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014-2015 Sri Harsha Chilakapati
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.shc.webgl4j.client;
26 |
27 | import com.google.gwt.core.client.JavaScriptObject;
28 |
29 | import java.lang.annotation.Documented;
30 | import java.lang.annotation.ElementType;
31 | import java.lang.annotation.Retention;
32 | import java.lang.annotation.RetentionPolicy;
33 | import java.lang.annotation.Target;
34 |
35 | /**
36 | * A {@link WebGLContext} represents a WebGL rendering context that is used to draw WebGL graphics onto a HTML5
37 | * canvas. A context can represent many things, such as which objects are bound to which targets, and the state
38 | * associated with this instance of WebGL. It also provides the WebGL version that is used for it's functions, and also
39 | * the {@link WebGLContext.Attributes} of the context.
40 | *
41 | * This also contains the WebGL functions that does the drawing on a canvas. The static methods in {@link WebGL10}
42 | * class call the same methods present in the context which is 'current' at that time. This allows for grouping
43 | * the methods by the version of WebGL they were first introduced, allowing to easily keep track of which version your
44 | * application is using.
45 | *
46 | * In order to render anything, a context must be current. If not, the {@link WebGL10} class will not
47 | * know from where to call the functions upon, and hence a ReferenceError will be generated.
48 | *
49 | * @author Sri Harsha Chilakapati
50 | */
51 | public final class WebGLContext extends JavaScriptObject
52 | {
53 | protected WebGLContext()
54 | {
55 | }
56 |
57 | /**
58 | * A cross-browser polyfill for FullScreen API. Works on Google Chrome 15 and above, Firefox 9 and above, Safari,
59 | * Opera 32 and above, Internet Explorer 11 and the new Microsoft Edge. Returns true if any of the context or even
60 | * any other element in the page is fullscreen.
61 | *
62 | * @return True if any context is in fullscreen mode, false otherwise.
63 | */
64 | public static native boolean isFullscreen() /*-{
65 | if ($doc['fullscreenElement'])
66 | return $doc['fullscreenElement'] != null;
67 |
68 | if ($doc['msFullscreenElement'])
69 | return $doc['msFullscreenElement'] != null;
70 |
71 | if ($doc['mozFullScreenElement'])
72 | return $doc['mozFullScreenElement'] != null;
73 |
74 | if ($doc['webkitFullscreenElement'])
75 | return $doc['webkitFullscreenElement'] != null;
76 |
77 | return false;
78 | }-*/;
79 |
80 | /**
81 | * A cross-browser polyfill for FullScreen API. Works on Google Chrome 15 and above, Firefox 9 and above, Safari,
82 | * Opera 32 and above, Internet Explorer 11 and the new Microsoft Edge. This method requests the browser to exit the
83 | * fullscreen state.
84 | *
85 | * @return Returns whether the request is successful.
86 | */
87 | public static native boolean exitFullscreen() /*-{
88 | if ($doc['exitFullscreen'])
89 | $doc['exitFullscreen']();
90 |
91 | else if ($doc['msExitFullscreen'])
92 | $doc['msExitFullscreen']();
93 |
94 | else if ($doc['mozCancelFullScreen'])
95 | $doc['mozCancelFullScreen']();
96 |
97 | else if ($doc['webkitExitFullscreen'])
98 | $doc['webkitExitFullscreen']();
99 |
100 | else
101 | return false;
102 |
103 | return !(@com.shc.webgl4j.client.WebGLContext::isFullscreen()());
104 | }-*/;
105 |
106 | /**
107 | * Returns the current context. If there is no context that is current, then {@code null} is returned.
108 | *
109 | * @return The current context.
110 | */
111 | public static native WebGLContext getCurrent() /*-{
112 | if ($wnd['context'] === undefined)
113 | return null;
114 |
115 | return $wnd['context'];
116 | }-*/;
117 |
118 | /**
119 | * Returns the native JS WebGL context object that this class wraps upon. This is a javascript object that contains
120 | * all the methods that are called by {@link WebGL10} and such classes.
121 | *
122 | * @return The native JS WebGL context object that this class wraps upon.
123 | */
124 | public native JavaScriptObject getGL() /*-{
125 | return this['gl'];
126 | }-*/;
127 |
128 | /**
129 | * Returns the WebGL context version as a float. This is {@code 1.0} for {@link WebGL10} context, and {@code 2.0}
130 | * for WebGL20 contexts.
131 | *
132 | * @return The WebGL context version as a float.
133 | */
134 | public native float getVersion() /*-{
135 | return this['glv'];
136 | }-*/;
137 |
138 | /**
139 | * Returns the WebGL context attributes that are used to create this context.
140 | *
141 | * @return The context attributes that are used to create this context.
142 | */
143 | public native Attributes getAttributes() /*-{
144 | return this['attribs'];
145 | }-*/;
146 |
147 | /**
148 | * Makes this context current, so that it will be used to render when the static WebGL methods are called. This will
149 | * result in the following WebGL calls have effect only on the canvas that this context is based upon.
150 | */
151 | public native void makeCurrent() /*-{
152 | $wnd.gl = this.gl;
153 | $wnd.attribs = this.attribs;
154 | $wnd.glv = this.glv;
155 | $wnd.context = this;
156 | }-*/;
157 |
158 | /**
159 | * A cross browser polyfill for the fullscreen API. Works on Google Chrome 15 and above, Firefox 9 and above,
160 | * Safari, Opera 32 and above, Internet Explorer 11 and the new Microsoft Edge. This method requests the browser to
161 | * enable fullscreen for the canvas that this WebGLContext uses.
162 | *
163 | * @return Returns whether the request succeeded or not.
164 | */
165 | public native boolean requestFullscreen() /*-{
166 | var canvas = $wnd['context']['gl']['canvas'];
167 |
168 | // For a modern browser that support the fullscreen API
169 | if (canvas['requestFullscreen'])
170 | canvas['requestFullscreen']();
171 |
172 | // For Microsoft browsers (Internet Explorer 11 and Microsoft Edge)
173 | else if (canvas['msRequestFullscreen'])
174 | canvas['msRequestFullscreen']();
175 |
176 | // For Mozilla browsers (Firefox)
177 | else if (canvas['mozRequestFullScreen'])
178 | canvas['mozRequestFullScreen']();
179 |
180 | // For WebKit browsers (Chrome, Safari, Chromium, Opera)
181 | else if (canvas['webkitRequestFullscreen'])
182 | canvas['webkitRequestFullscreen'](Element['ALLOW_KEYBOARD_INPUT']);
183 |
184 | // Simply return if not available
185 | else
186 | return false;
187 |
188 | // Return whether we are now in fullscreen (request succeeded)
189 | return @com.shc.webgl4j.client.WebGLContext::isFullscreen()();
190 | }-*/;
191 |
192 | /**
193 | * This class represents the context attributes that were used to create a context, or the attributes that will be
194 | * used to create a context. The attributes are nothing but the properties of the context. Note that there will be
195 | * no effect to the context even if you change the attributes once the context is created. To be sure that the
196 | * requested attributes are accepted by the implementation, compare the attributes of the created context.
197 | *
198 | * @author Sri Harsha Chilakapati
199 | */
200 | public static class Attributes extends JavaScriptObject
201 | {
202 | protected Attributes()
203 | {
204 | }
205 |
206 | /**
207 | * Creates an Attributes object with the default values as specified in the WebGL 1.0 Specification. The
208 | * default values for the properties are as follows.
209 | *
210 | *
211 | * alpha: true
212 | * depth: true
213 | * stencil: false
214 | * antiAlias: true
215 | * preMultipliedAlpha: true
216 | * preserveDrawingBuffer: false
217 | * failIfMajorPerformanceCaveat: false
218 | *
219 | *
220 | * @return An attributes object that contain the default values.
221 | */
222 | public static native Attributes create() /*-{
223 | return {
224 | alpha: true,
225 | depth: true,
226 | stencil: false,
227 | antiAlias: true,
228 | preMultipliedAlpha: true,
229 | preserveDrawingBuffer: false,
230 | failIfMajorPerformanceCaveat: false
231 | };
232 | }-*/;
233 |
234 | /**
235 | * Returns whether the draw buffer has an alpha channel. An alpha channel is required for OpenGL to performing
236 | * the destination alpha operations and composition with the page. The default value for this is {@code true}.
237 | *
238 | * @return Whether the draw buffer has an Alpha-channel.
239 | */
240 | public final native boolean getAlpha() /*-{
241 | return this.alpha;
242 | }-*/;
243 |
244 | /**
245 | * Sets the existence of the alpha channel on the drawing buffer. If the value is true, the drawing buffer has
246 | * an alpha channel for the purposes of performing OpenGL destination alpha operations and compositing with the
247 | * page. If the value is false, no alpha buffer is available. The default value for this is {@code true}.
248 | *
249 | * @param alpha The value of the alpha channel.
250 | */
251 | public final native void setAlpha(boolean alpha) /*-{
252 | this.alpha = alpha;
253 | }-*/;
254 |
255 | /**
256 | * Returns whether anti aliasing is enabled. This is dependent on the implementation. So there is no guarantee
257 | * that the implementation respects this property. The default value for this is {@code true}.
258 | *
259 | * @return Whether anti aliasing is enabled.
260 | */
261 | public final native boolean getAntialias() /*-{
262 | return this.antialias;
263 | }-*/;
264 |
265 | /**
266 | * Sets the antialias property of the to be created context. If the value is true and the implementation
267 | * supports antialiasing the drawing buffer will perform antialiasing using its choice of technique
268 | * (multisample/supersample) and quality. If the value is false or the implementation does not support
269 | * antialiasing, no antialiasing is performed. The default value for this property is {@code true}.
270 | *
271 | * @param antialias The new value of the antialiasing property.
272 | */
273 | public final native void setAntialias(boolean antialias) /*-{
274 | this.antialias = antialias;
275 | }-*/;
276 |
277 | /**
278 | * Returns the depth property of the WebGLContext. If the value is true, then the drawing buffer has a depth
279 | * buffer of at least 8 bits. If the value is false, then no depth buffer is available for that context.
280 | *
281 | * @return The depth property of WebGLContext.
282 | */
283 | public final native boolean getDepth() /*-{
284 | return this.depth;
285 | }-*/;
286 |
287 | /**
288 | * Sets the depth property of the WebGLContext. If the new value is true, then the drawing buffer will have a
289 | * depth buffer that is at least 8 bits. If the value is false, then no depth buffer is available for the
290 | * context. However, this is just a request, you have to check the property after the context is created.
291 | *
292 | * @param depth The depth property of WebGLContext.
293 | */
294 | public final native void setDepth(boolean depth) /*-{
295 | this.depth = depth;
296 | }-*/;
297 |
298 | /**
299 | * If the value is true, context creation will fail if the implementation determines that the performance of
300 | * the created WebGL context would be dramatically lower than that of a native application making equivalent
301 | * OpenGL calls. This could happen for a number of reasons, including:
302 | *
303 | * An implementation might switch to a software rasterizer if the user's GPU driver is known to be
304 | * unstable. An implementation might require reading back the framebuffer from GPU memory to system
305 | * memory before compositing it with the rest of the page, significantly reducing performance.
306 | *
307 | * Applications that don't require high performance should leave this parameter at its default value of
308 | * false. Applications that require high performance may set this parameter to true, and if context creation
309 | * fails then the application may prefer to use a fallback rendering path.
310 | *
311 | * @return Whether the context fails if there is a major performance caveat.
312 | */
313 | public final native boolean getFailIfMajorPerformanceCaveat() /*-{
314 | return this.failIfMajorPerformanceCaveat;
315 | }-*/;
316 |
317 | /**
318 | * If the value is true, context creation will fail if the implementation determines that the performance of
319 | * the created WebGL context would be dramatically lower than that of a native application making equivalent
320 | * OpenGL calls. This could happen for a number of reasons, including:
321 | *
322 | * An implementation might switch to a software rasterizer if the user's GPU driver is known to be
323 | * unstable. An implementation might require reading back the framebuffer from GPU memory to system
324 | * memory before compositing it with the rest of the page, significantly reducing performance.
325 | *
326 | * Applications that don't require high performance should leave this parameter at its default value of
327 | * false. Applications that require high performance may set this parameter to true, and if context creation
328 | * fails then the application may prefer to use a fallback rendering path.
329 | *
330 | * @param fail Whether the context should fail if there is a major performance caveat.
331 | */
332 | public final native void setFailIfMajorPerformanceCaveat(boolean fail) /*-{
333 | this.failIfMajorPerformanceCaveat = fail;
334 | }-*/;
335 |
336 | /**
337 | * If the value is true the page compositor will assume the drawing buffer contains colors with premultiplied
338 | * alpha. If the value is false the page compositor will assume that colors in the drawing buffer are not
339 | * premultiplied. This flag is ignored if the alpha flag is false. See Premultiplied
340 | * Alpha for more information on the effects of the premultipliedAlpha
flag.
341 | *
342 | * @return Whether the drawing buffer contains colors with premultiplied alpha.
343 | */
344 | public final native boolean getPremultipliedAlpha() /*-{
345 | return this.premultipliedAlpha;
346 | }-*/;
347 |
348 | /**
349 | * If the value is true the page compositor will assume the drawing buffer contains colors with premultiplied
350 | * alpha. If the value is false the page compositor will assume that colors in the drawing buffer are not
351 | * premultiplied. This flag is ignored if the alpha flag is false. See Premultiplied
352 | * Alpha for more information on the effects of the premultipliedAlpha
flag.
353 | *
354 | * @param premultipliedAlpha Whether the drawing buffer should accept colors with premultiplied alpha.
355 | */
356 | public final native void setPremultipliedAlpha(boolean premultipliedAlpha) /*-{
357 | this.premultipliedAlpha = premultipliedAlpha;
358 | }-*/;
359 |
360 | /**
361 | * If false, once the drawing buffer is presented as described in the Drawing Buffer section, the
363 | * contents of the drawing buffer are cleared to their default values. All elements of the drawing buffer
364 | * (color, depth and stencil) are cleared. If the value is true the buffers will not be cleared and will
365 | * preserve their values until cleared or overwritten by the author.
366 | *
367 | * On some hardware setting the preserveDrawingBuffer flag to true can have significant performance
368 | * implications.
369 | *
370 | * @return Whether the drawing buffer is preserved after presenting.
371 | */
372 | public final native boolean getPreserveDrawingBuffer() /*-{
373 | return this.preserveDrawingBuffer;
374 | }-*/;
375 |
376 | /**
377 | * If false, once the drawing buffer is presented as described in the Drawing Buffer section, the
379 | * contents of the drawing buffer are cleared to their default values. All elements of the drawing buffer
380 | * (color, depth and stencil) are cleared. If the value is true the buffers will not be cleared and will
381 | * preserve their values until cleared or overwritten by the author.
382 | *
383 | * On some hardware setting the preserveDrawingBuffer flag to true can have significant performance
384 | * implications.
385 | *
386 | * @param preserveDrawingBuffer Whether the drawing buffer should be preserved after presenting.
387 | */
388 | public final native void setPreserveDrawingBuffer(boolean preserveDrawingBuffer) /*-{
389 | this.preserveDrawingBuffer = preserveDrawingBuffer;
390 | }-*/;
391 |
392 | /**
393 | * Returns whether there is a stencil buffer associated with the context. If the value is true, the drawing
394 | * buffer has a stencil buffer of at least 8 bits. If the value is false, no stencil buffer is available.
395 | *
396 | * @return Whether there is a stencil buffer of at least 8 bits.
397 | */
398 | public final native boolean getStencil() /*-{
399 | return this.stencil;
400 | }-*/;
401 |
402 | /**
403 | * Sets whether there is a stencil buffer associated with the context. If the value is true, the drawing buffer
404 | * has a stencil buffer of at least 8 bits. If the value is false, no stencil buffer is available.
405 | *
406 | * @param stencil Whether a stencil buffer of at least 8 bits should be used.
407 | */
408 | public final native void setStencil(boolean stencil) /*-{
409 | this.stencil = stencil;
410 | }-*/;
411 | }
412 |
413 | /**
414 | * Handles Context Loss is an attribute that specifies that a method defined by WebGL API handles the context loss
415 | * automatically. This does nothing but notifies the user by sitting in the documentation.
416 | */
417 | @Documented
418 | @Target(ElementType.METHOD)
419 | @Retention(RetentionPolicy.SOURCE)
420 | public @interface HandlesContextLoss
421 | {
422 | }
423 | }
424 |
--------------------------------------------------------------------------------
/webgl4j/src/main/java/com/shc/webgl4j/client/WebGLObjectMap.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014-2015 Sri Harsha Chilakapati
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.shc.webgl4j.client;
26 |
27 | import com.google.gwt.core.client.JavaScriptObject;
28 |
29 | import java.util.HashMap;
30 | import java.util.Map;
31 |
32 | /**
33 | * A class used to convert WebGL objects (WebGLTexture, WebGLBuffer etc.,) to integers just like the desktop OpenGL.
34 | * This class is package-private since there is no direct use of this class for users. It is simply expected to work in
35 | * the background. That is the reason this class is declared as package private.
36 | *
37 | * @author Sri Harsha Chilakapati
38 | */
39 | final class WebGLObjectMap
40 | {
41 | private final static Map contexts = new HashMap<>();
42 |
43 | // WebGL10 objects
44 | private final Map shaders = new HashMap<>();
45 | private final Map buffers = new HashMap<>();
46 | private final Map programs = new HashMap<>();
47 | private final Map textures = new HashMap<>();
48 | private final Map frameBuffers = new HashMap<>();
49 | private final Map renderBuffers = new HashMap<>();
50 |
51 | private final Map> uniforms = new HashMap<>();
52 |
53 | // WebGL20 objects
54 | private final Map queries = new HashMap<>();
55 | private final Map samplers = new HashMap<>();
56 | private final Map syncs = new HashMap<>();
57 | private final Map transformFeedbacks = new HashMap<>();
58 | private final Map vertexArrayObjects = new HashMap<>();
59 |
60 | // Field to store the current program
61 | int currentProgram = 0;
62 |
63 | // Fields for last generated IDs of WebGL objects
64 | private int lastShaderID = 0;
65 | private int lastBufferID = 0;
66 | private int lastProgramID = 0;
67 | private int lastTextureID = 0;
68 | private int lastFramebufferID = 0;
69 | private int lastRenderbufferID = 0;
70 | private int lastUniformID = 0;
71 | private int lastQueryID = 0;
72 | private int lastSamplerID = 0;
73 | private int lastSyncID = 0;
74 | private int lastTransformFeedbackID = 0;
75 | private int lastVertexArrayObjectID = 0;
76 |
77 | private WebGLObjectMap()
78 | {
79 | }
80 |
81 | public static WebGLObjectMap get()
82 | {
83 | WebGLObjectMap map = contexts.get(WebGLContext.getCurrent());
84 |
85 | if (map == null)
86 | {
87 | map = new WebGLObjectMap();
88 | contexts.put(WebGLContext.getCurrent(), map);
89 | }
90 |
91 | return map;
92 | }
93 |
94 | int createShader(JavaScriptObject shader)
95 | {
96 | if (shader == null)
97 | return 0;
98 |
99 | if (shaders.values().contains(shader))
100 | {
101 | for (int key : shaders.keySet())
102 | if (shaders.get(key) == shader)
103 | return key;
104 | }
105 |
106 | shaders.put(++lastShaderID, shader);
107 | return lastShaderID;
108 | }
109 |
110 | JavaScriptObject toShader(int shaderID)
111 | {
112 | return shaders.get(shaderID);
113 | }
114 |
115 | int createBuffer(JavaScriptObject buffer)
116 | {
117 | if (buffer == null)
118 | return 0;
119 |
120 | if (buffers.values().contains(buffer))
121 | {
122 | for (int key : buffers.keySet())
123 | if (buffers.get(key) == buffer)
124 | return key;
125 | }
126 |
127 | buffers.put(++lastBufferID, buffer);
128 | return lastBufferID;
129 | }
130 |
131 | JavaScriptObject toBuffer(int bufferID)
132 | {
133 | return buffers.get(bufferID);
134 | }
135 |
136 | int createProgram(JavaScriptObject program)
137 | {
138 | if (program == null)
139 | return 0;
140 |
141 | if (programs.values().contains(program))
142 | {
143 | for (int key : programs.keySet())
144 | if (programs.get(key) == program)
145 | return key;
146 | }
147 |
148 | programs.put(++lastProgramID, program);
149 | return lastProgramID;
150 | }
151 |
152 | JavaScriptObject toProgram(int programID)
153 | {
154 | return programs.get(programID);
155 | }
156 |
157 | int createTexture(JavaScriptObject texture)
158 | {
159 | if (texture == null)
160 | return 0;
161 |
162 | if (textures.values().contains(texture))
163 | {
164 | for (int key : textures.keySet())
165 | if (textures.get(key) == texture)
166 | return key;
167 | }
168 |
169 | textures.put(++lastTextureID, texture);
170 | return lastTextureID;
171 | }
172 |
173 | JavaScriptObject toTexture(int textureID)
174 | {
175 | return textures.get(textureID);
176 | }
177 |
178 | int createFramebuffer(JavaScriptObject frameBuffer)
179 | {
180 | if (frameBuffer == null)
181 | return 0;
182 |
183 | if (frameBuffers.values().contains(frameBuffer))
184 | {
185 | for (int key : frameBuffers.keySet())
186 | if (frameBuffers.get(key) == frameBuffer)
187 | return key;
188 | }
189 |
190 | frameBuffers.put(++lastFramebufferID, frameBuffer);
191 | return lastFramebufferID;
192 | }
193 |
194 | JavaScriptObject toFramebuffer(int frameBuffer)
195 | {
196 | return frameBuffers.get(frameBuffer);
197 | }
198 |
199 | int createRenderBuffer(JavaScriptObject renderBuffer)
200 | {
201 | if (renderBuffer == null)
202 | return 0;
203 |
204 | if (renderBuffers.values().contains(renderBuffer))
205 | {
206 | for (int key : renderBuffers.keySet())
207 | if (renderBuffers.get(key) == renderBuffer)
208 | return key;
209 | }
210 |
211 | renderBuffers.put(++lastRenderbufferID, renderBuffer);
212 | return lastRenderbufferID;
213 | }
214 |
215 | JavaScriptObject toRenderBuffer(int renderBuffer)
216 | {
217 | return renderBuffers.get(renderBuffer);
218 | }
219 |
220 | int createUniform(JavaScriptObject uniform)
221 | {
222 | if (uniform == null)
223 | return -1;
224 |
225 | Map progUniforms = uniforms.get(currentProgram);
226 |
227 | if (progUniforms == null)
228 | {
229 | progUniforms = new HashMap<>();
230 | uniforms.put(currentProgram, progUniforms);
231 | }
232 |
233 | if (progUniforms.values().contains(uniform))
234 | {
235 | for (int key : progUniforms.keySet())
236 | if (progUniforms.get(key) == uniform)
237 | return key;
238 | }
239 |
240 | progUniforms.put(++lastUniformID, uniform);
241 | return lastUniformID;
242 | }
243 |
244 | JavaScriptObject toUniform(int programID, int uniform)
245 | {
246 | return uniform == -1 ? null : uniforms.get(programID).get(uniform);
247 | }
248 |
249 | JavaScriptObject toUniform(int uniform)
250 | {
251 | return toUniform(currentProgram, uniform);
252 | }
253 |
254 | void deleteShader(int shader)
255 | {
256 | if (shader != 0)
257 | shaders.remove(shader);
258 | }
259 |
260 | void deleteBuffer(int buffer)
261 | {
262 | if (buffer != 0)
263 | buffers.remove(buffer);
264 | }
265 |
266 | void deleteProgram(int program)
267 | {
268 | if (program != 0)
269 | {
270 | programs.remove(program);
271 | uniforms.remove(program);
272 | }
273 | }
274 |
275 | void deleteTexture(int texture)
276 | {
277 | if (texture != 0)
278 | textures.remove(texture);
279 | }
280 |
281 | void deleteFramebuffer(int frameBuffer)
282 | {
283 | if (frameBuffer != 0)
284 | frameBuffers.remove(frameBuffer);
285 | }
286 |
287 | void deleteRenderBuffer(int renderBuffer)
288 | {
289 | if (renderBuffer != 0)
290 | renderBuffers.remove(renderBuffer);
291 | }
292 |
293 | int createQuery(JavaScriptObject query)
294 | {
295 | if (query == null)
296 | return 0;
297 |
298 | if (queries.values().contains(query))
299 | {
300 | for (int key : queries.keySet())
301 | if (queries.get(key) == query)
302 | return key;
303 | }
304 |
305 | queries.put(++lastQueryID, query);
306 | return lastQueryID;
307 | }
308 |
309 | JavaScriptObject toQuery(int query)
310 | {
311 | return queries.get(query);
312 | }
313 |
314 | int createSampler(JavaScriptObject sampler)
315 | {
316 | if (sampler == null)
317 | return 0;
318 |
319 | if (samplers.values().contains(sampler))
320 | {
321 | for (int key : samplers.keySet())
322 | if (samplers.get(key) == sampler)
323 | return key;
324 | }
325 |
326 | samplers.put(++lastSamplerID, sampler);
327 | return lastSamplerID;
328 | }
329 |
330 | JavaScriptObject toSampler(int sampler)
331 | {
332 | return samplers.get(sampler);
333 | }
334 |
335 | int createSync(JavaScriptObject sync)
336 | {
337 | if (sync == null)
338 | return 0;
339 |
340 | if (syncs.values().contains(sync))
341 | {
342 | for (int key : syncs.keySet())
343 | if (syncs.get(key) == sync)
344 | return key;
345 | }
346 |
347 | syncs.put(++lastSyncID, sync);
348 | return lastSyncID;
349 | }
350 |
351 | JavaScriptObject toSync(int sync)
352 | {
353 | return syncs.get(sync);
354 | }
355 |
356 | int createTransformFeedback(JavaScriptObject transformFeedback)
357 | {
358 | if (transformFeedback == null)
359 | return 0;
360 |
361 | if (transformFeedbacks.values().contains(transformFeedback))
362 | {
363 | for (int key : transformFeedbacks.keySet())
364 | if (transformFeedbacks.get(key) == transformFeedback)
365 | return key;
366 | }
367 |
368 | transformFeedbacks.put(++lastTransformFeedbackID, transformFeedback);
369 | return lastTransformFeedbackID;
370 | }
371 |
372 | JavaScriptObject toTransformFeedback(int transformFeedback)
373 | {
374 | return transformFeedbacks.get(transformFeedback);
375 | }
376 |
377 | int createVertexArrayObject(JavaScriptObject vertexArrayObject)
378 | {
379 | if (vertexArrayObject == null)
380 | return 0;
381 |
382 | if (vertexArrayObjects.values().contains(vertexArrayObject))
383 | {
384 | for (int key : vertexArrayObjects.keySet())
385 | if (vertexArrayObjects.get(key) == vertexArrayObject)
386 | return key;
387 | }
388 |
389 | vertexArrayObjects.put(++lastVertexArrayObjectID, vertexArrayObject);
390 | return lastVertexArrayObjectID;
391 | }
392 |
393 | JavaScriptObject toVertexArrayObject(int vertexArrayObject)
394 | {
395 | return vertexArrayObjects.get(vertexArrayObject);
396 | }
397 |
398 | void deleteQuery(int query)
399 | {
400 | if (query != 0)
401 | queries.remove(query);
402 | }
403 |
404 | void deleteSampler(int sampler)
405 | {
406 | if (sampler != 0)
407 | samplers.remove(sampler);
408 | }
409 |
410 | void deleteSync(int sync)
411 | {
412 | if (sync != 0)
413 | syncs.remove(sync);
414 | }
415 |
416 | void deleteTransformFeedback(int transformFeedback)
417 | {
418 | if (transformFeedback != 0)
419 | transformFeedbacks.remove(transformFeedback);
420 | }
421 |
422 | void deleteVertexArrayObject(int vertexArrayObject)
423 | {
424 | if (vertexArrayObject != 0)
425 | vertexArrayObjects.remove(vertexArrayObject);
426 | }
427 | }
428 |
--------------------------------------------------------------------------------