├── .gitignore ├── LICENCE ├── README.md ├── build.gradle ├── examples ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── shc │ │ └── webgl4j │ │ └── examples │ │ ├── client.gwt.xml │ │ └── client │ │ ├── CubeExample.java │ │ ├── Example.java │ │ ├── RectangleExample.java │ │ ├── TextureExample.java │ │ ├── TexturedCubeExample.java │ │ ├── TriangleExample.java │ │ └── WebGL4J.java │ ├── resources │ └── texture.png │ └── webapp │ ├── WEB-INF │ └── web.xml │ └── index.html ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── webgl4j ├── build.gradle └── src └── main └── java └── com └── shc └── webgl4j ├── client.gwt.xml └── client ├── ANGLE_instanced_arrays.java ├── EXT_blend_minmax.java ├── EXT_frag_depth.java ├── EXT_shader_texture_lod.java ├── EXT_texture_filter_anisotropic.java ├── OES_element_index_uint.java ├── OES_standard_derivatives.java ├── OES_texture_float.java ├── OES_texture_float_linear.java ├── OES_texture_half_float.java ├── OES_texture_half_float_linear.java ├── OES_vertex_array_object.java ├── TimeUtil.java ├── WEBGL_compressed_texture_s3tc.java ├── WEBGL_debug_renderer_info.java ├── WEBGL_debug_shaders.java ├── WEBGL_depth_texture.java ├── WEBGL_draw_buffers.java ├── WEBGL_lose_context.java ├── WebGL10.java ├── WebGL20.java ├── WebGLContext.java └── WebGLObjectMap.java /.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle temporary directory 2 | .gradle/ 3 | 4 | # The build directory 5 | build/ 6 | webgl4j/build/ 7 | examples/build/ 8 | 9 | # The war directory 10 | examples/war/ 11 | 12 | # IDEA project files 13 | *.iml 14 | *.ipr 15 | *.iws 16 | webgl4j/*.iml 17 | webgl4j/*.ipr 18 | webgl4j/*.iws 19 | examples/*.iml 20 | examples/*.ipr 21 | examples/*.iws 22 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2015 Sri Harsha Chilakapati 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | WebGL4J is a WebGL wrapper library for the Java programming language which allows to use Java to write HTML5 applications using GWT (Google Web Toolkit) which uses WebGL to draw 2D / 3D hardware accelerated graphics using a HTML5 Canvas. 4 | 5 | ## Design 6 | 7 | WebGL4J aims to provide static methods to all the WebGL functions, and also the extensions present in the Khronos WebGL Registry. This provides a similar interface to people who are coming from legacy OpenGL environments (by legacy, I mean desktop) to use WebGL easily, yet having the same interface to the users coming from JavaScript. 8 | 9 | | Class | Description | 10 | |-----------|---------------------------------------------------------------------------------| 11 | | WebGL10 | Contains all the constants and functions defined in the WebGL 1.0 specification | 12 | | WebGL20 | Contains all the constants and functions defined in the WebGL 2.0 specification | 13 | | {ExtName} | Contains all the constants and functions defined in the extension {ExtName} | 14 | 15 | As you have seen above, that is how the functions are structured in the wrapper, allowing to use WebGL functions from any where in the app once the context is created. All the functions have the OpenGL prefixes and suffixes, to help the users coming from the native desktop OpenGL. 16 | 17 | ## Installation 18 | 19 | You can get WebGL4J in three ways, either from the central maven repository, or downloading from the GitHub releases, and finally building yourself. 20 | 21 | ```xml 22 | 23 | com.goharsha 24 | webgl4j 25 | 0.2.9 26 | compile 27 | 28 | ``` 29 | 30 | That is for maven. The repository is maven central repository. For gradle users, you can add it to your dependencies like the following. 31 | 32 | ```gradle 33 | compile group: 'com.goharsha', name: 'webgl4j', version: '0.2.9' 34 | 35 | // or shorthand notation 36 | compile 'com.goharsha:webgl4j:0.2.9' 37 | ``` 38 | 39 | Add that and you'll be getting your dependencies downloaded to you. The second way is to download the JAR from the GitHub releases and add it to the classpath in your webapp. You can build your own version of the library in the following way. 40 | 41 | ```bash 42 | ./gradlew clean build javadoc 43 | ``` 44 | 45 | Then copy the `webgl4j.jar` from the `webgl4j/build/libs` directory and add it in the classpath of your GWT application. Now inherit the `WebGL4J` in your modules that use this library by adding the following line to your GWT module XML file. 46 | 47 | ```xml 48 | 49 | ``` 50 | 51 | That should let you use WebGL4J in your project. You can now start writing WebGL applications using GWT. 52 | 53 | ## Creating the context 54 | 55 | To create a WebGL context, you first need a `` element in your HTML template. 56 | 57 | ```html 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | ``` 69 | 70 | With that template, you can get the canvas element and create the context on module load in your entrypoint. This is how it looks. 71 | 72 | ```java 73 | // Get the CanvasElement 74 | CanvasElement canvas = (CanvasElement) Document.get().getElementById("webgl"); 75 | 76 | // Create the context 77 | WebGL10.createContext(canvas); 78 | ``` 79 | 80 | Creating the context and canvas at runtime without declaring it at runtime is also supported. You can simply create a canvas and call `WebGL10.createContext()` on it. 81 | 82 | ```java 83 | // Create the Canvas 84 | Canvas canvas = Canvas.createIfSupported(); 85 | canvas.setCoordinateSpaceWidth(640); 86 | canvas.setCoordinateSpaceHeight(480); 87 | 88 | // Create the context 89 | WebGL10.createContext(canvas); 90 | ``` 91 | 92 | Creating a context with a set of context attributes is also supported. Here is an example for creating a context with a stencil buffer. 93 | 94 | ```java 95 | WebGLContext.Attributes ctxAttributes = WebGLContext.Attributes.create(); 96 | ctxAttributes.setStencil(true); 97 | 98 | // Create the context now 99 | WebGL10.createContext(canvas, ctxAttributes); 100 | ``` 101 | 102 | To create WebGL2 contexts, you can use the `createContext` method in the `WebGL20` class. Just like the `createContext` method in the `WebGL10` class, the context attributes are not necessary and are optional. 103 | 104 | ```java 105 | WebGL20.createContext(canvas, ctxAttributes); 106 | ``` 107 | 108 | You can call `WebGL10` methods when you have a `WebGL20` context, but you cannot call WebGL 2.0 functions when you have a WebGL 1.0 context. 109 | 110 | ## Using multiple contexts 111 | 112 | WebGL4J has support for rendering using multiple contexts. All the overloads to the method `createContext` returns a `WebGLContext` object which you can store. Then depending on your usage, you make a context 'current'. 113 | 114 | ```java 115 | // Create the contexts and store their handles 116 | WebGLContext ctx1 = WebGL10.createContext(canvas1); 117 | WebGLContext ctx2 = WebGL10.createContext(canvas2); 118 | 119 | // Make context 1 current 120 | ctx1.makeCurrent(); 121 | 122 | // [... Draw using context 1 ...] 123 | // [... Drawing happens on canvas1 ...] 124 | 125 | // Make context 2 current 126 | ctx2.makeCurrent(); 127 | 128 | // [... Draw using context 2 ...] 129 | // [... Drawing happens on canvas2 ...] 130 | ``` 131 | 132 | You don't need to make the context current if you are only using one context. If you are using multiple contexts, the context that is just created will be the current, so in the above example, `ctx2` will be current since it is the latest created context. 133 | 134 | ## Using extensions 135 | 136 | Extensions in WebGL are a bit different when compared to the standard desktop OpenGL extensions. One notable difference is that here the extension needs to be enabled first, unlike the traditional desktop OpenGL where all the extensions are enabled by default. 137 | 138 | ```java 139 | // Check if the extension is supported 140 | if (OES_vertex_array_object.isSupported()) 141 | OES_vertex_array_object.enableExtension(); 142 | ``` 143 | 144 | The above example demonstrates the `OES_vertex_array_object` extension, and how to enable it. Once it's enabled, you can call any of it's static functions just like you call the WebGL functions. If you try to use an extension without enabling it, an `IllegalStateException` will be thrown at you. 145 | 146 | ## Fullscreen mode 147 | 148 | You can use the built in polyfill to request the fullscreen mode on a context. This works in most browsers (Chrome, Safari, Opera, Firefox, IE 11 and the new Edge), with the ones that are tested being Chrome, Firefox, IE 11 and Edge. This is how you request fullscreen mode. 149 | 150 | ```java 151 | boolean success = WebGLContext.getCurrent().requestFullscreen(); 152 | ``` 153 | 154 | This method returns a success value, to notify you whether the request is accepted. However, there are some restrictions on this, you can't simply request fullscreen, the request will only be accepted if the user has pressed a key or clicked a button which initiated the request. 155 | 156 | ## Running the examples 157 | 158 | You can see the examples in action by navigating your browser to [https://goharsha.com/WebGL4J/](https://goharsha.com/WebGL4J/). Instead if you want to compile them yourself, enter the following command into the console. 159 | 160 | ```bash 161 | ./gradlew clean build superDev 162 | ``` 163 | 164 | Once the terminal says that the server is ready at **http://localhost:9876**, fire up your browser to go to **http://localhost:8080/examples/** and you will see the examples in live. 165 | 166 | ## Licence 167 | 168 | This project is covered by MIT licence. You can read the terms [here](http://opensource.org/licenses/MIT). 169 | 170 | The logos were designed by [NegativeZero](https://github.com/NegativeXero/) (Twitter: [@NegativeZeroDEV](https://twitter.com/NegativeZeroDEV/)) and is licenced under Creative Commons. 171 | 172 | ## Contact 173 | 174 | If you want to contact me about this project, or ask any questions, you can e-mail me at [hello@goharsha.com](mailto://hello@goharsha.com). Alternatively, if you are not comfortable with e-mail, you can join the IRC at [#WebGL4J@Freenode](https://kiwiirc.com/client/irc.freenode.net/#WebGL4J) 175 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | } 5 | dependencies { 6 | classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6' 7 | } 8 | } 9 | 10 | allprojects { 11 | apply plugin: 'idea' 12 | apply plugin: 'maven' 13 | 14 | repositories { 15 | jcenter() 16 | mavenCentral() 17 | maven { 18 | url 'https://oss.sonatype.org/content/repositories/snapshots/' 19 | } 20 | } 21 | } 22 | 23 | project(":examples") { 24 | apply plugin: 'gwt' 25 | apply plugin: 'war' 26 | 27 | dependencies { 28 | compile project(":webgl4j") 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /examples/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'jetty' 3 | 4 | sourceCompatibility = 1.8 5 | targetCompatibility = 1.8 6 | 7 | gwt { 8 | minHeapSize = "512M"; 9 | maxHeapSize = "1024M"; 10 | 11 | gwtVersion = '2.8.0' 12 | modules 'com.shc.webgl4j.examples.client' 13 | devModules 'com.shc.webgl4j.examples.client' 14 | 15 | compiler { 16 | strict = true 17 | } 18 | } 19 | 20 | javadoc { 21 | options.addStringOption("sourcepath", "") 22 | } 23 | 24 | dependencies { 25 | providedCompile 'com.google.gwt:gwt-user:2.8.0' 26 | providedCompile 'com.google.gwt:gwt-servlet:2.8.0' 27 | providedCompile 'org.joml:joml-gwt:1.9.3-SNAPSHOT' 28 | providedCompile fileTree('libs') 29 | providedCompile project(":webgl4j") 30 | } 31 | 32 | task run(type: JettyRunWar) { 33 | dependsOn war 34 | webApp=war.archivePath 35 | daemon=true 36 | } 37 | 38 | task superDev(type: de.richsource.gradle.plugins.gwt.GwtSuperDev) { 39 | dependsOn run 40 | doFirst { 41 | gwt.modules = gwt.devModules 42 | } 43 | } 44 | 45 | war { 46 | from sourceSets.main.resources 47 | } 48 | 49 | task addSource << { 50 | sourceSets.main.compileClasspath += files(project(':webgl4j').sourceSets.main.allSource) 51 | } 52 | 53 | tasks.compileGwt.dependsOn(addSource) 54 | tasks.draftCompileGwt.dependsOn(addSource) 55 | -------------------------------------------------------------------------------- /examples/src/main/java/com/shc/webgl4j/examples/client.gwt.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /examples/src/main/java/com/shc/webgl4j/examples/client/CubeExample.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.examples.client; 26 | 27 | import com.google.gwt.canvas.client.Canvas; 28 | import org.joml.Matrix4f; 29 | 30 | import static com.shc.webgl4j.client.WebGL10.*; 31 | 32 | /** 33 | * @author Sri Harsha Chilakapati 34 | */ 35 | public class CubeExample extends Example 36 | { 37 | private int programID; 38 | private Matrix4f projView; 39 | 40 | public CubeExample(Canvas canvas) 41 | { 42 | super(canvas); 43 | } 44 | 45 | @Override 46 | public void init() 47 | { 48 | glClearColor(0, 0, 0, 1); 49 | 50 | glEnable(GL_DEPTH_TEST); 51 | 52 | // The vertex shader source 53 | String vsSource = "precision mediump float; \n" + 54 | " \n" + 55 | "uniform mat4 proj; \n" + 56 | " \n" + 57 | "attribute vec3 position; \n" + 58 | "attribute vec4 color; \n" + 59 | " \n" + 60 | "varying vec4 vColor; \n" + 61 | " \n" + 62 | "void main() \n" + 63 | "{ \n" + 64 | " vColor = color; \n" + 65 | " gl_Position = proj * vec4(position, 1.0); \n" + 66 | "}"; 67 | 68 | // The fragment shader source 69 | String fsSource = "precision mediump float; \n" + 70 | "varying vec4 vColor; \n" + 71 | " \n" + 72 | "void main() \n" + 73 | "{ \n" + 74 | " gl_FragColor = vColor; \n" + 75 | "}"; 76 | 77 | // Create the vertex shader 78 | int vsShaderID = glCreateShader(GL_VERTEX_SHADER); 79 | glShaderSource(vsShaderID, vsSource); 80 | glCompileShader(vsShaderID); 81 | 82 | // Create the fragment shader 83 | int fsShaderID = glCreateShader(GL_FRAGMENT_SHADER); 84 | glShaderSource(fsShaderID, fsSource); 85 | glCompileShader(fsShaderID); 86 | 87 | // Create the program 88 | programID = glCreateProgram(); 89 | glAttachShader(programID, vsShaderID); 90 | glAttachShader(programID, fsShaderID); 91 | glLinkProgram(programID); 92 | glUseProgram(programID); 93 | 94 | // Create the positions VBO 95 | float[] vertices = 96 | { 97 | // Front face 98 | -1, +1, +1, 99 | -1, -1, +1, 100 | +1, +1, +1, 101 | +1, +1, +1, 102 | -1, -1, +1, 103 | +1, -1, +1, 104 | 105 | // Right face 106 | +1, +1, +1, 107 | +1, -1, +1, 108 | +1, +1, -1, 109 | +1, +1, -1, 110 | +1, -1, +1, 111 | +1, -1, -1, 112 | 113 | // Back face 114 | +1, +1, -1, 115 | +1, -1, -1, 116 | -1, -1, -1, 117 | -1, -1, -1, 118 | -1, +1, -1, 119 | +1, +1, -1, 120 | 121 | // Left face 122 | -1, +1, -1, 123 | -1, -1, -1, 124 | -1, -1, +1, 125 | -1, -1, +1, 126 | -1, +1, +1, 127 | -1, +1, -1, 128 | 129 | // Top face 130 | -1, +1, -1, 131 | -1, +1, +1, 132 | +1, +1, -1, 133 | +1, +1, -1, 134 | -1, +1, +1, 135 | +1, +1, +1, 136 | 137 | // Bottom face 138 | -1, -1, -1, 139 | -1, -1, +1, 140 | +1, -1, -1, 141 | +1, -1, -1, 142 | -1, -1, +1, 143 | +1, -1, +1 144 | }; 145 | 146 | int vboPosID = glCreateBuffer(); 147 | glBindBuffer(GL_ARRAY_BUFFER, vboPosID); 148 | glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW); 149 | 150 | int positionLoc = glGetAttribLocation(programID, "position"); 151 | glVertexAttribPointer(positionLoc, 3, GL_FLOAT, false, 0, 0); 152 | glEnableVertexAttribArray(positionLoc); 153 | 154 | // Create the colors VBO 155 | float[] colors = 156 | { 157 | // Front face 158 | 1, 1, 1, 1, 159 | 0, 0, 1, 1, 160 | 1, 1, 1, 1, 161 | 1, 1, 1, 1, 162 | 0, 0, 1, 1, 163 | 0, 0, 1, 1, 164 | 165 | // Right face 166 | 1, 1, 1, 1, 167 | 0, 0, 1, 1, 168 | 1, 1, 1, 1, 169 | 1, 1, 1, 1, 170 | 0, 0, 1, 1, 171 | 0, 0 ,1, 1, 172 | 173 | // Back face 174 | 1, 1, 1, 1, 175 | 0, 0, 1, 1, 176 | 0, 0, 1, 1, 177 | 0, 0, 1, 1, 178 | 1, 1, 1, 1, 179 | 1, 1, 1, 1, 180 | 181 | // Left face 182 | 1, 1, 1, 1, 183 | 0, 0, 1, 1, 184 | 0, 0, 1, 1, 185 | 0, 0, 1, 1, 186 | 1, 1, 1, 1, 187 | 1, 1, 1, 1, 188 | 189 | // Top face 190 | 1, 1, 1, 1, 191 | 1, 1, 1, 1, 192 | 1, 1, 1, 1, 193 | 1, 1, 1, 1, 194 | 1, 1, 1, 1, 195 | 1, 1, 1, 1, 196 | 197 | // Bottom face 198 | 0, 0, 1, 1, 199 | 0, 0, 1, 1, 200 | 0, 0, 1, 1, 201 | 0, 0, 1, 1, 202 | 0, 0, 1, 1, 203 | 0, 0, 1, 1 204 | }; 205 | 206 | int vboColID = glCreateBuffer(); 207 | glBindBuffer(GL_ARRAY_BUFFER, vboColID); 208 | glBufferData(GL_ARRAY_BUFFER, colors, GL_STATIC_DRAW); 209 | 210 | int colorLoc = glGetAttribLocation(programID, "color"); 211 | glVertexAttribPointer(colorLoc, 4, GL_FLOAT, false, 0, 0); 212 | glEnableVertexAttribArray(colorLoc); 213 | 214 | projView = new Matrix4f(); 215 | } 216 | 217 | private float angle = 0; 218 | 219 | @Override 220 | public void render() 221 | { 222 | angle++; 223 | 224 | projView.setPerspective((float) Math.toRadians(70), 640f / 480f, 0.1f, 100) 225 | .translate(0, 0, -4) 226 | .rotateX((float) Math.toRadians(angle)) 227 | .rotateY((float) Math.toRadians(angle)) 228 | .rotateZ((float) Math.toRadians(angle)); 229 | 230 | glUniformMatrix4fv(glGetUniformLocation(programID, "proj"), false, projView.get(new float[16])); 231 | 232 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 233 | glDrawArrays(GL_TRIANGLES, 0, 36); 234 | } 235 | } 236 | -------------------------------------------------------------------------------- /examples/src/main/java/com/shc/webgl4j/examples/client/Example.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.examples.client; 26 | 27 | import com.google.gwt.canvas.client.Canvas; 28 | import com.shc.webgl4j.client.WebGL10; 29 | import com.shc.webgl4j.client.WebGLContext; 30 | 31 | /** 32 | * The abstract class that represents an example. Contains the context, the canvas, and a simple animation loop. 33 | * 34 | * @author Sri Harsha Chilakapati 35 | */ 36 | public abstract class Example 37 | { 38 | protected WebGLContext context; 39 | protected Canvas canvas; 40 | 41 | public Example(Canvas canvas) 42 | { 43 | this(canvas, WebGL10.createContext(canvas)); 44 | } 45 | 46 | public Example(Canvas canvas, WebGLContext context) 47 | { 48 | this.canvas = canvas; 49 | this.context = context; 50 | } 51 | 52 | /** 53 | * Initializes the WebGL resources, and also the example. 54 | */ 55 | public abstract void init(); 56 | 57 | /** 58 | * Called every frame to draw the example onto the canvas. 59 | */ 60 | public abstract void render(); 61 | } 62 | -------------------------------------------------------------------------------- /examples/src/main/java/com/shc/webgl4j/examples/client/RectangleExample.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.examples.client; 26 | 27 | import com.google.gwt.canvas.client.Canvas; 28 | import org.joml.Matrix4f; 29 | 30 | import static com.shc.webgl4j.client.WebGL10.*; 31 | 32 | /** 33 | * @author Sri Harsha Chilakapati 34 | */ 35 | public class RectangleExample extends Example 36 | { 37 | private int programID; 38 | private Matrix4f projView; 39 | 40 | public RectangleExample(Canvas canvas) 41 | { 42 | super(canvas); 43 | } 44 | 45 | @Override 46 | public void init() 47 | { 48 | glClearColor(0, 0, 0, 1); 49 | 50 | // The vertex shader source 51 | String vsSource = "precision mediump float; \n" + 52 | " \n" + 53 | "uniform mat4 proj; \n" + 54 | " \n" + 55 | "attribute vec2 position; \n" + 56 | "attribute vec4 color; \n" + 57 | " \n" + 58 | "varying vec4 vColor; \n" + 59 | " \n" + 60 | "void main() \n" + 61 | "{ \n" + 62 | " vColor = color; \n" + 63 | " gl_Position = proj * vec4(position, 0.0, 1.0); \n" + 64 | "}"; 65 | 66 | // The fragment shader source 67 | String fsSource = "precision mediump float; \n" + 68 | "varying vec4 vColor; \n" + 69 | " \n" + 70 | "void main() \n" + 71 | "{ \n" + 72 | " gl_FragColor = vColor; \n" + 73 | "}"; 74 | 75 | // Create the vertex shader 76 | int vsShaderID = glCreateShader(GL_VERTEX_SHADER); 77 | glShaderSource(vsShaderID, vsSource); 78 | glCompileShader(vsShaderID); 79 | 80 | // Create the fragment shader 81 | int fsShaderID = glCreateShader(GL_FRAGMENT_SHADER); 82 | glShaderSource(fsShaderID, fsSource); 83 | glCompileShader(fsShaderID); 84 | 85 | // Create the program 86 | programID = glCreateProgram(); 87 | glAttachShader(programID, vsShaderID); 88 | glAttachShader(programID, fsShaderID); 89 | glLinkProgram(programID); 90 | glUseProgram(programID); 91 | 92 | // Create the positions VBO 93 | float[] vertices = 94 | { 95 | -0.8f, +0.8f, 96 | +0.8f, +0.8f, 97 | -0.8f, -0.8f, 98 | +0.8f, +0.8f, 99 | +0.8f, -0.8f, 100 | -0.8f, -0.8f 101 | }; 102 | 103 | int vboPosID = glCreateBuffer(); 104 | glBindBuffer(GL_ARRAY_BUFFER, vboPosID); 105 | glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW); 106 | 107 | int positionLoc = glGetAttribLocation(programID, "position"); 108 | glVertexAttribPointer(positionLoc, 2, GL_FLOAT, false, 0, 0); 109 | glEnableVertexAttribArray(positionLoc); 110 | 111 | // Create the colors VBO 112 | float[] colors = 113 | { 114 | 1, 0, 0, 1, 115 | 0, 1, 0, 1, 116 | 0, 0, 1, 1, 117 | 0, 1, 0, 1, 118 | 1, 1, 1, 1, 119 | 0, 0, 1, 1 120 | }; 121 | 122 | int vboColID = glCreateBuffer(); 123 | glBindBuffer(GL_ARRAY_BUFFER, vboColID); 124 | glBufferData(GL_ARRAY_BUFFER, colors, GL_STATIC_DRAW); 125 | 126 | int colorLoc = glGetAttribLocation(programID, "color"); 127 | glVertexAttribPointer(colorLoc, 4, GL_FLOAT, false, 0, 0); 128 | glEnableVertexAttribArray(colorLoc); 129 | 130 | projView = new Matrix4f(); 131 | } 132 | 133 | private float angle = 0; 134 | 135 | @Override 136 | public void render() 137 | { 138 | angle++; 139 | 140 | projView.setPerspective((float) Math.toRadians(70), 640f / 480f, 0.1f, 100) 141 | .translate(0, 0, -2) 142 | .rotateZ((float) Math.toRadians(angle)); 143 | 144 | glUniformMatrix4fv(glGetUniformLocation(programID, "proj"), false, projView.get(new float[16])); 145 | 146 | glClear(GL_COLOR_BUFFER_BIT); 147 | glDrawArrays(GL_TRIANGLES, 0, 6); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /examples/src/main/java/com/shc/webgl4j/examples/client/TextureExample.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.examples.client; 26 | 27 | import com.google.gwt.canvas.client.Canvas; 28 | import com.google.gwt.user.client.ui.Image; 29 | import com.google.gwt.user.client.ui.RootPanel; 30 | import org.joml.Matrix4f; 31 | 32 | import static com.shc.webgl4j.client.WebGL10.*; 33 | 34 | /** 35 | * @author Sri Harsha Chilakapati 36 | */ 37 | public class TextureExample extends Example 38 | { 39 | private int programID; 40 | private Matrix4f projView; 41 | private float angle = 0; 42 | 43 | public TextureExample(Canvas canvas) 44 | { 45 | super(canvas); 46 | } 47 | 48 | @Override 49 | public void init() 50 | { 51 | glClearColor(0, 0, 0, 1); 52 | 53 | // The vertex shader source 54 | String vsSource = "precision mediump float; \n" + 55 | " \n" + 56 | "uniform mat4 proj; \n" + 57 | " \n" + 58 | "attribute vec2 position; \n" + 59 | "attribute vec2 texCoords; \n" + 60 | " \n" + 61 | "varying vec2 vTexCoords; \n" + 62 | " \n" + 63 | "void main() \n" + 64 | "{ \n" + 65 | " vTexCoords = texCoords; \n" + 66 | " gl_Position = proj * vec4(position, 0.0, 1.0); \n" + 67 | "}"; 68 | 69 | // The fragment shader source 70 | String fsSource = "precision mediump float; \n" + 71 | " \n" + 72 | "uniform sampler2D tex; \n" + 73 | " \n" + 74 | "varying vec2 vTexCoords; \n" + 75 | " \n" + 76 | "void main() \n" + 77 | "{ \n" + 78 | " gl_FragColor = texture2D(tex, vTexCoords); \n" + 79 | "}"; 80 | 81 | // Create the vertex shader 82 | int vsShaderID = glCreateShader(GL_VERTEX_SHADER); 83 | glShaderSource(vsShaderID, vsSource); 84 | glCompileShader(vsShaderID); 85 | 86 | // Create the fragment shader 87 | int fsShaderID = glCreateShader(GL_FRAGMENT_SHADER); 88 | glShaderSource(fsShaderID, fsSource); 89 | glCompileShader(fsShaderID); 90 | 91 | // Create the program 92 | programID = glCreateProgram(); 93 | glAttachShader(programID, vsShaderID); 94 | glAttachShader(programID, fsShaderID); 95 | glLinkProgram(programID); 96 | glUseProgram(programID); 97 | 98 | // Create the positions VBO 99 | float[] vertices = 100 | { 101 | -0.8f, +0.8f, 102 | +0.8f, +0.8f, 103 | -0.8f, -0.8f, 104 | +0.8f, +0.8f, 105 | +0.8f, -0.8f, 106 | -0.8f, -0.8f 107 | }; 108 | 109 | int vboPosID = glCreateBuffer(); 110 | glBindBuffer(GL_ARRAY_BUFFER, vboPosID); 111 | glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW); 112 | 113 | int positionLoc = glGetAttribLocation(programID, "position"); 114 | glVertexAttribPointer(positionLoc, 2, GL_FLOAT, false, 0, 0); 115 | glEnableVertexAttribArray(positionLoc); 116 | 117 | // Create the texcoords VBO 118 | float[] texCoords = 119 | { 120 | 0, 0, 121 | 1, 0, 122 | 0, 1, 123 | 1, 0, 124 | 1, 1, 125 | 0, 1 126 | }; 127 | 128 | int vboTexID = glCreateBuffer(); 129 | glBindBuffer(GL_ARRAY_BUFFER, vboTexID); 130 | glBufferData(GL_ARRAY_BUFFER, texCoords, GL_STATIC_DRAW); 131 | 132 | int texcoordLoc = glGetAttribLocation(programID, "texCoords"); 133 | glVertexAttribPointer(texcoordLoc, 2, GL_FLOAT, false, 0, 0); 134 | glEnableVertexAttribArray(texcoordLoc); 135 | 136 | final Image image = new Image("texture.png"); 137 | image.addLoadHandler(event -> 138 | { 139 | // Make current again, this is asynchronous event 140 | context.makeCurrent(); 141 | int texID = glCreateTexture(); 142 | glBindTexture(GL_TEXTURE_2D, texID); 143 | 144 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, image); 145 | 146 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 147 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 148 | 149 | glUniform1i(glGetUniformLocation(programID, "tex"), 0); 150 | }); 151 | image.setVisible(false); 152 | RootPanel.get().add(image); 153 | 154 | projView = new Matrix4f(); 155 | } 156 | 157 | @Override 158 | public void render() 159 | { 160 | angle++; 161 | 162 | projView.setPerspective((float) Math.toRadians(70), 640f / 480f, 0.1f, 100) 163 | .translate(0, 0, -2) 164 | .rotateY((float) Math.toRadians(angle)) 165 | .rotateZ((float) Math.toRadians(angle)); 166 | 167 | glUniformMatrix4fv(glGetUniformLocation(programID, "proj"), false, projView.get(new float[16])); 168 | 169 | glClear(GL_COLOR_BUFFER_BIT); 170 | glDrawArrays(GL_TRIANGLES, 0, 6); 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /examples/src/main/java/com/shc/webgl4j/examples/client/TexturedCubeExample.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.examples.client; 26 | 27 | import com.google.gwt.canvas.client.Canvas; 28 | import com.google.gwt.user.client.ui.Image; 29 | import com.google.gwt.user.client.ui.RootPanel; 30 | import org.joml.Matrix4f; 31 | 32 | import static com.shc.webgl4j.client.WebGL10.*; 33 | 34 | /** 35 | * @author Sri Harsha Chilakapati 36 | */ 37 | public class TexturedCubeExample extends Example 38 | { 39 | private int programID; 40 | private Matrix4f projView; 41 | 42 | public TexturedCubeExample(Canvas canvas) 43 | { 44 | super(canvas); 45 | } 46 | 47 | @Override 48 | public void init() 49 | { 50 | glClearColor(0, 0, 0, 1); 51 | 52 | glEnable(GL_DEPTH_TEST); 53 | 54 | // The vertex shader source 55 | String vsSource = "precision mediump float; \n" + 56 | " \n" + 57 | "uniform mat4 proj; \n" + 58 | " \n" + 59 | "attribute vec3 position; \n" + 60 | "attribute vec2 texCoords; \n" + 61 | " \n" + 62 | "varying vec2 vTexCoords; \n" + 63 | " \n" + 64 | "void main() \n" + 65 | "{ \n" + 66 | " vTexCoords = texCoords; \n" + 67 | " gl_Position = proj * vec4(position, 1.0); \n" + 68 | "}"; 69 | 70 | // The fragment shader source 71 | String fsSource = "precision mediump float; \n" + 72 | " \n" + 73 | "uniform sampler2D tex; \n" + 74 | " \n" + 75 | "varying vec2 vTexCoords; \n" + 76 | " \n" + 77 | "void main() \n" + 78 | "{ \n" + 79 | " gl_FragColor = texture2D(tex, vTexCoords); \n" + 80 | "}"; 81 | 82 | // Create the vertex shader 83 | int vsShaderID = glCreateShader(GL_VERTEX_SHADER); 84 | glShaderSource(vsShaderID, vsSource); 85 | glCompileShader(vsShaderID); 86 | 87 | // Create the fragment shader 88 | int fsShaderID = glCreateShader(GL_FRAGMENT_SHADER); 89 | glShaderSource(fsShaderID, fsSource); 90 | glCompileShader(fsShaderID); 91 | 92 | // Create the program 93 | programID = glCreateProgram(); 94 | glAttachShader(programID, vsShaderID); 95 | glAttachShader(programID, fsShaderID); 96 | glLinkProgram(programID); 97 | glUseProgram(programID); 98 | 99 | // Create the positions VBO 100 | float[] vertices = 101 | { 102 | // Front face 103 | -1, +1, +1, 104 | -1, -1, +1, 105 | +1, +1, +1, 106 | +1, +1, +1, 107 | -1, -1, +1, 108 | +1, -1, +1, 109 | 110 | // Right face 111 | +1, +1, +1, 112 | +1, -1, +1, 113 | +1, +1, -1, 114 | +1, +1, -1, 115 | +1, -1, +1, 116 | +1, -1, -1, 117 | 118 | // Back face 119 | +1, +1, -1, 120 | +1, -1, -1, 121 | -1, -1, -1, 122 | -1, -1, -1, 123 | -1, +1, -1, 124 | +1, +1, -1, 125 | 126 | // Left face 127 | -1, +1, -1, 128 | -1, -1, -1, 129 | -1, -1, +1, 130 | -1, -1, +1, 131 | -1, +1, +1, 132 | -1, +1, -1, 133 | 134 | // Top face 135 | -1, +1, -1, 136 | -1, +1, +1, 137 | +1, +1, -1, 138 | +1, +1, -1, 139 | -1, +1, +1, 140 | +1, +1, +1, 141 | 142 | // Bottom face 143 | -1, -1, -1, 144 | -1, -1, +1, 145 | +1, -1, -1, 146 | +1, -1, -1, 147 | -1, -1, +1, 148 | +1, -1, +1 149 | }; 150 | 151 | int vboPosID = glCreateBuffer(); 152 | glBindBuffer(GL_ARRAY_BUFFER, vboPosID); 153 | glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW); 154 | 155 | int positionLoc = glGetAttribLocation(programID, "position"); 156 | glVertexAttribPointer(positionLoc, 3, GL_FLOAT, false, 0, 0); 157 | glEnableVertexAttribArray(positionLoc); 158 | 159 | // Create the colors VBO 160 | float[] texCoords = 161 | { 162 | // Front face 163 | 0, 0, 164 | 0, 1, 165 | 1, 0, 166 | 1, 0, 167 | 0, 1, 168 | 1, 1, 169 | 170 | // Right face 171 | 0, 0, 172 | 0, 1, 173 | 1, 0, 174 | 1, 0, 175 | 0, 1, 176 | 1, 1, 177 | 178 | // Back face 179 | 0, 0, 180 | 0, 1, 181 | 1, 0, 182 | 1, 0, 183 | 0, 1, 184 | 1, 1, 185 | 186 | // Left face 187 | 0, 0, 188 | 0, 1, 189 | 1, 0, 190 | 1, 0, 191 | 0, 1, 192 | 1, 1, 193 | 194 | // Top face 195 | 0, 0, 196 | 0, 1, 197 | 1, 0, 198 | 1, 0, 199 | 0, 1, 200 | 1, 1, 201 | 202 | // Bottom face 203 | 0, 0, 204 | 0, 1, 205 | 1, 0, 206 | 1, 0, 207 | 0, 1, 208 | 1, 1, 209 | }; 210 | 211 | int vboTexID = glCreateBuffer(); 212 | glBindBuffer(GL_ARRAY_BUFFER, vboTexID); 213 | glBufferData(GL_ARRAY_BUFFER, texCoords, GL_STATIC_DRAW); 214 | 215 | int texcoordLoc = glGetAttribLocation(programID, "texCoords"); 216 | glVertexAttribPointer(texcoordLoc, 2, GL_FLOAT, false, 0, 0); 217 | glEnableVertexAttribArray(texcoordLoc); 218 | 219 | final Image image = new Image("texture.png"); 220 | image.addLoadHandler(event -> 221 | { 222 | // Make current again, this is asynchronous event 223 | context.makeCurrent(); 224 | int texID = glCreateTexture(); 225 | glBindTexture(GL_TEXTURE_2D, texID); 226 | 227 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, image); 228 | 229 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 230 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 231 | 232 | glUniform1i(glGetUniformLocation(programID, "tex"), 0); 233 | }); 234 | image.setVisible(false); 235 | RootPanel.get().add(image); 236 | 237 | projView = new Matrix4f(); 238 | } 239 | 240 | private float angle = 0; 241 | 242 | @Override 243 | public void render() 244 | { 245 | angle++; 246 | 247 | projView.setPerspective((float) Math.toRadians(70), 640f / 480f, 0.1f, 100) 248 | .translate(0, 0, -4) 249 | .rotateX((float) Math.toRadians(angle)) 250 | .rotateY((float) Math.toRadians(angle)) 251 | .rotateZ((float) Math.toRadians(angle)); 252 | 253 | glUniformMatrix4fv(glGetUniformLocation(programID, "proj"), false, projView.get(new float[16])); 254 | 255 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 256 | glDrawArrays(GL_TRIANGLES, 0, 36); 257 | } 258 | } 259 | -------------------------------------------------------------------------------- /examples/src/main/java/com/shc/webgl4j/examples/client/TriangleExample.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.examples.client; 26 | 27 | import com.google.gwt.canvas.client.Canvas; 28 | import com.shc.webgl4j.client.TimeUtil; 29 | import org.joml.Matrix4f; 30 | 31 | import static com.shc.webgl4j.client.WebGL10.*; 32 | 33 | /** 34 | * @author Sri Harsha Chilakapati 35 | */ 36 | public class TriangleExample extends Example 37 | { 38 | private int programID; 39 | private Matrix4f projView; 40 | 41 | public TriangleExample(Canvas canvas) 42 | { 43 | super(canvas); 44 | } 45 | 46 | @Override 47 | public void init() 48 | { 49 | glClearColor(0, 0, 0, 1); 50 | 51 | // The vertex shader source 52 | String vsSource = "precision mediump float; \n" + 53 | " \n" + 54 | "uniform mat4 proj; \n" + 55 | " \n" + 56 | "attribute vec2 position; \n" + 57 | "attribute vec4 color; \n" + 58 | " \n" + 59 | "varying vec4 vColor; \n" + 60 | " \n" + 61 | "void main() \n" + 62 | "{ \n" + 63 | " vColor = color; \n" + 64 | " gl_Position = proj * vec4(position, 0.0, 1.0); \n" + 65 | "}"; 66 | 67 | // The fragment shader source 68 | String fsSource = "precision mediump float; \n" + 69 | "varying vec4 vColor; \n" + 70 | " \n" + 71 | "void main() \n" + 72 | "{ \n" + 73 | " gl_FragColor = vColor; \n" + 74 | "}"; 75 | 76 | // Create the vertex shader 77 | int vsShaderID = glCreateShader(GL_VERTEX_SHADER); 78 | glShaderSource(vsShaderID, vsSource); 79 | glCompileShader(vsShaderID); 80 | 81 | // Create the fragment shader 82 | int fsShaderID = glCreateShader(GL_FRAGMENT_SHADER); 83 | glShaderSource(fsShaderID, fsSource); 84 | glCompileShader(fsShaderID); 85 | 86 | // Create the program 87 | programID = glCreateProgram(); 88 | glAttachShader(programID, vsShaderID); 89 | glAttachShader(programID, fsShaderID); 90 | glLinkProgram(programID); 91 | glUseProgram(programID); 92 | 93 | // Create the positions VBO 94 | float[] vertices = 95 | { 96 | +0.0f, +0.8f, 97 | +0.8f, -0.8f, 98 | -0.8f, -0.8f 99 | }; 100 | 101 | int vboPosID = glCreateBuffer(); 102 | glBindBuffer(GL_ARRAY_BUFFER, vboPosID); 103 | glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW); 104 | 105 | int positionLoc = glGetAttribLocation(programID, "position"); 106 | glVertexAttribPointer(positionLoc, 2, GL_FLOAT, false, 0, 0); 107 | glEnableVertexAttribArray(positionLoc); 108 | 109 | // Create the colors VBO 110 | float[] colors = 111 | { 112 | 1, 0, 0, 1, 113 | 0, 1, 0, 1, 114 | 0, 0, 1, 1 115 | }; 116 | 117 | int vboColID = glCreateBuffer(); 118 | glBindBuffer(GL_ARRAY_BUFFER, vboColID); 119 | glBufferData(GL_ARRAY_BUFFER, colors, GL_STATIC_DRAW); 120 | 121 | int colorLoc = glGetAttribLocation(programID, "color"); 122 | glVertexAttribPointer(colorLoc, 4, GL_FLOAT, false, 0, 0); 123 | glEnableVertexAttribArray(colorLoc); 124 | 125 | projView = new Matrix4f(); 126 | } 127 | 128 | private float angle = 0; 129 | 130 | @Override 131 | public void render() 132 | { 133 | angle++; 134 | float z = -3 + (float) Math.sin(TimeUtil.currentSeconds()) * 2; 135 | 136 | projView.setPerspective((float) Math.toRadians(70), 640f / 480f, 0.1f, 100) 137 | .translate(0, 0, z) 138 | .rotateY((float) Math.toRadians(angle)); 139 | 140 | glUniformMatrix4fv(glGetUniformLocation(programID, "proj"), false, projView.get(new float[16])); 141 | 142 | glClear(GL_COLOR_BUFFER_BIT); 143 | glDrawArrays(GL_TRIANGLES, 0, 3); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /examples/src/main/java/com/shc/webgl4j/examples/client/WebGL4J.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.examples.client; 26 | 27 | import com.google.gwt.animation.client.AnimationScheduler; 28 | import com.google.gwt.canvas.client.Canvas; 29 | import com.google.gwt.core.client.EntryPoint; 30 | import com.google.gwt.dom.client.Style; 31 | import com.google.gwt.user.client.Window; 32 | import com.google.gwt.user.client.ui.HTML; 33 | import com.google.gwt.user.client.ui.RootLayoutPanel; 34 | import com.google.gwt.user.client.ui.ScrollPanel; 35 | import com.google.gwt.user.client.ui.TabLayoutPanel; 36 | import com.google.gwt.user.client.ui.Widget; 37 | import com.shc.webgl4j.client.*; 38 | 39 | import java.util.List; 40 | import java.util.ArrayList; 41 | 42 | import static com.shc.webgl4j.client.WEBGL_debug_renderer_info.*; 43 | import static com.shc.webgl4j.client.WebGL10.*; 44 | 45 | /** 46 | * @author Sri Harsha Chilakapati 47 | */ 48 | public class WebGL4J implements EntryPoint 49 | { 50 | private static String isSupportedHTML(String name, boolean value) 51 | { 52 | return "" + name + ": " + (value ? "Supported" : "Not Supported") + "
"; 53 | } 54 | 55 | private List 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 | --------------------------------------------------------------------------------