From 1b0b47985dbfce73a5d6f9cf9f90d0f7aee985d3 Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Thu, 22 Jan 2015 23:03:54 +0400 Subject: [PATCH] WebGL wrappers. Additional core JS wrappers --- .../java/org/teavm/dom/browser/Screen.java | 40 +++ .../java/org/teavm/dom/browser/Window.java | 21 ++ .../teavm/dom/typedarrays/Float32Array.java | 30 ++ .../org/teavm/dom/typedarrays/Int32Array.java | 30 ++ .../org/teavm/dom/webgl/WebGLActiveInfo.java | 26 ++ .../webgl/WebGLContextAttributesFactory.java | 2 +- .../org/teavm/dom/webgl/WebGLProgram.java | 1 - .../dom/webgl/WebGLRenderingContext.java | 319 +++++++++++++++++- .../dom/webgl/WebGLShaderPrecisionFormat.java | 34 ++ .../teavm/dom/webgl/WebGLUniformLocation.java | 34 ++ teavm-jso/src/main/java/org/teavm/jso/JS.java | 78 +++++ .../src/main/java/org/teavm/jso/JSArray.java | 8 +- .../org/teavm/jso/JSBooleanArrayReader.java | 28 ++ .../java/org/teavm/jso/JSByteArrayReader.java | 28 ++ .../org/teavm/jso/JSDoubleArrayReader.java | 28 ++ .../main/java/org/teavm/jso/JSFloatArray.java | 24 ++ .../org/teavm/jso/JSFloatArrayReader.java | 83 +++++ .../org/teavm/jso/JSFloatSortFunction.java | 25 ++ .../src/main/java/org/teavm/jso/JSGlobal.java | 18 + .../main/java/org/teavm/jso/JSIntArray.java | 77 +++++ .../java/org/teavm/jso/JSIntArrayReader.java | 28 ++ .../java/org/teavm/jso/JSIntSortFunction.java | 25 ++ .../org/teavm/jso/JSShortArrayReader.java | 28 ++ .../java/org/teavm/jso/JSStringArray.java | 77 +++++ .../org/teavm/jso/JSStringSortFunction.java | 25 ++ 25 files changed, 1107 insertions(+), 10 deletions(-) create mode 100644 teavm-dom/src/main/java/org/teavm/dom/browser/Screen.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/typedarrays/Float32Array.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/typedarrays/Int32Array.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/webgl/WebGLActiveInfo.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/webgl/WebGLShaderPrecisionFormat.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/webgl/WebGLUniformLocation.java create mode 100644 teavm-jso/src/main/java/org/teavm/jso/JSBooleanArrayReader.java create mode 100644 teavm-jso/src/main/java/org/teavm/jso/JSByteArrayReader.java create mode 100644 teavm-jso/src/main/java/org/teavm/jso/JSDoubleArrayReader.java create mode 100644 teavm-jso/src/main/java/org/teavm/jso/JSFloatArray.java create mode 100644 teavm-jso/src/main/java/org/teavm/jso/JSFloatArrayReader.java create mode 100644 teavm-jso/src/main/java/org/teavm/jso/JSFloatSortFunction.java create mode 100644 teavm-jso/src/main/java/org/teavm/jso/JSIntArray.java create mode 100644 teavm-jso/src/main/java/org/teavm/jso/JSIntArrayReader.java create mode 100644 teavm-jso/src/main/java/org/teavm/jso/JSIntSortFunction.java create mode 100644 teavm-jso/src/main/java/org/teavm/jso/JSShortArrayReader.java create mode 100644 teavm-jso/src/main/java/org/teavm/jso/JSStringArray.java create mode 100644 teavm-jso/src/main/java/org/teavm/jso/JSStringSortFunction.java diff --git a/teavm-dom/src/main/java/org/teavm/dom/browser/Screen.java b/teavm-dom/src/main/java/org/teavm/dom/browser/Screen.java new file mode 100644 index 000000000..87919530e --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/browser/Screen.java @@ -0,0 +1,40 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.browser; + +import org.teavm.jso.JSObject; +import org.teavm.jso.JSProperty; + +/** + * + * @author Alexey Andreev + */ +public interface Screen extends JSObject { + @JSProperty + int getWidth(); + + @JSProperty + int getHeight(); + + @JSProperty + int getAvailWidth(); + + @JSProperty + int getAvailHeight(); + + @JSProperty + int getColorDepth(); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/browser/Window.java b/teavm-dom/src/main/java/org/teavm/dom/browser/Window.java index 2bc3d87e2..58192a172 100644 --- a/teavm-dom/src/main/java/org/teavm/dom/browser/Window.java +++ b/teavm-dom/src/main/java/org/teavm/dom/browser/Window.java @@ -32,6 +32,9 @@ public interface Window extends JSGlobal { @JSProperty HTMLDocument getDocument(); + @JSProperty + Screen getScreen(); + void alert(JSObject message); void alert(String message); @@ -67,4 +70,22 @@ public interface Window extends JSGlobal { @JSConstructor("Uint8ClampedArray") Int8Array createUintClamped8Array(ArrayBuffer buffer, int offset, int length); + + @JSConstructor("Int32Array") + Int8Array createInt32Array(int length); + + @JSConstructor("Int32Array") + Int8Array createInt32Array(ArrayBuffer buffer); + + @JSConstructor("Int32Array") + Int8Array createInt32Array(ArrayBuffer buffer, int offset, int length); + + @JSConstructor("Float32Array") + Int8Array createFloat32Array(int length); + + @JSConstructor("Float32Array") + Int8Array createFloat32Array(ArrayBuffer buffer); + + @JSConstructor("Float32Array") + Int8Array createFloat32Array(ArrayBuffer buffer, int offset, int length); } diff --git a/teavm-dom/src/main/java/org/teavm/dom/typedarrays/Float32Array.java b/teavm-dom/src/main/java/org/teavm/dom/typedarrays/Float32Array.java new file mode 100644 index 000000000..f9759e481 --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/typedarrays/Float32Array.java @@ -0,0 +1,30 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.typedarrays; + +import org.teavm.jso.JSIndexer; + +/** + * + * @author Alexey Andreev + */ +public interface Float32Array extends ArrayBufferView { + @JSIndexer + float get(int index); + + @JSIndexer + void set(int index, float value); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/typedarrays/Int32Array.java b/teavm-dom/src/main/java/org/teavm/dom/typedarrays/Int32Array.java new file mode 100644 index 000000000..715ee137e --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/typedarrays/Int32Array.java @@ -0,0 +1,30 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.typedarrays; + +import org.teavm.jso.JSIndexer; + +/** + * + * @author Alexey Andreev + */ +public interface Int32Array extends ArrayBufferView { + @JSIndexer + int get(int index); + + @JSIndexer + void set(int index, int value); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/webgl/WebGLActiveInfo.java b/teavm-dom/src/main/java/org/teavm/dom/webgl/WebGLActiveInfo.java new file mode 100644 index 000000000..637e08cc3 --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/webgl/WebGLActiveInfo.java @@ -0,0 +1,26 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.webgl; + +import org.teavm.jso.JSObject; + +/** + * + * @author Alexey Andreev + */ +public interface WebGLActiveInfo extends JSObject { + +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/webgl/WebGLContextAttributesFactory.java b/teavm-dom/src/main/java/org/teavm/dom/webgl/WebGLContextAttributesFactory.java index ca4583e16..53d9b0da9 100644 --- a/teavm-dom/src/main/java/org/teavm/dom/webgl/WebGLContextAttributesFactory.java +++ b/teavm-dom/src/main/java/org/teavm/dom/webgl/WebGLContextAttributesFactory.java @@ -23,6 +23,6 @@ import org.teavm.jso.JSObject; * @author Alexey Andreev */ public interface WebGLContextAttributesFactory extends JSObject { - @JSConstructor("WebGLContextAttributes") + @JSConstructor("Object") WebGLContextAttributes createWebGLContextAttributes(); } diff --git a/teavm-dom/src/main/java/org/teavm/dom/webgl/WebGLProgram.java b/teavm-dom/src/main/java/org/teavm/dom/webgl/WebGLProgram.java index e4467d755..dbb955438 100644 --- a/teavm-dom/src/main/java/org/teavm/dom/webgl/WebGLProgram.java +++ b/teavm-dom/src/main/java/org/teavm/dom/webgl/WebGLProgram.java @@ -22,5 +22,4 @@ import org.teavm.jso.JSObject; * @author Alexey Andreev */ public interface WebGLProgram extends JSObject { - } diff --git a/teavm-dom/src/main/java/org/teavm/dom/webgl/WebGLRenderingContext.java b/teavm-dom/src/main/java/org/teavm/dom/webgl/WebGLRenderingContext.java index 4b0632764..1d6479e0d 100644 --- a/teavm-dom/src/main/java/org/teavm/dom/webgl/WebGLRenderingContext.java +++ b/teavm-dom/src/main/java/org/teavm/dom/webgl/WebGLRenderingContext.java @@ -15,12 +15,14 @@ */ package org.teavm.dom.webgl; +import org.teavm.dom.canvas.ImageData; import org.teavm.dom.html.HTMLCanvasElement; +import org.teavm.dom.html.HTMLImageElement; import org.teavm.dom.typedarrays.ArrayBuffer; import org.teavm.dom.typedarrays.ArrayBufferView; -import org.teavm.jso.JSArrayReader; -import org.teavm.jso.JSObject; -import org.teavm.jso.JSProperty; +import org.teavm.dom.typedarrays.Float32Array; +import org.teavm.dom.typedarrays.Int32Array; +import org.teavm.jso.*; /** * @@ -385,7 +387,10 @@ public interface WebGLRenderingContext extends JSObject { boolean isContextLost(); - JSArrayReader getSupportedExtensions(); + JSStringArrayReader getSupportedExtensions(); + + @JSMethod("getSupportedExtensions") + String[] getSupportedExtensionArray(); JSObject getExtension(String name); @@ -437,4 +442,310 @@ public interface WebGLRenderingContext extends JSObject { void colorMask(boolean red, boolean green, boolean blue, boolean alpha); void compileShader(WebGLShader shader); + + void compressedTexImage2D(int target, int level, int internalformat, int width, int height, int border, + ArrayBufferView data); + + void compressedTexSubImage2D(int target, int level, int xoffset, int yoffset, int width, int height, int format, + ArrayBufferView data); + + void copyTexImage2D(int target, int level, int internalformat, int x, int y, int width, int height, int border); + + void copyTexSubImage2D(int target, int level, int xoffset, int yoffset, int x, int y, int width, int height); + + + WebGLBuffer createBuffer(); + + WebGLFramebuffer createFramebuffer(); + + WebGLProgram createProgram(); + + WebGLRenderbuffer createRenderbuffer(); + + WebGLShader createShader(int type); + + WebGLTexture createTexture(); + + void cullFace(int mode); + + void deleteBuffer(WebGLBuffer buffer); + + void deleteFramebuffer(WebGLFramebuffer framebuffer); + + void deleteProgram(WebGLProgram program); + + void deleteRenderbuffer(WebGLRenderbuffer renderbuffer); + + void deleteShader(WebGLShader shader); + + void deleteTexture(WebGLTexture texture); + + void depthFunc(int func); + + void depthMask(boolean flag); + + void depthRange(float zNear, float zFar); + + void detachShader(WebGLProgram program, WebGLShader shader); + + void disable(int cap); + + void disableVertexAttribArray(int index); + + void drawArrays(int mode, int first, int count); + + void drawElements(int mode, int count, int type, int offset); + + void enable(int cap); + + void enableVertexAttribArray(int index); + + void finish(); + + void flush(); + + void framebufferRenderbuffer(int target, int attachment, int renderbuffertarget, WebGLRenderbuffer renderbuffer); + + void framebufferTexture2D(int target, int attachment, int textarget, WebGLTexture texture, int level); + + void frontFace(int mode); + + void generateMipmap(int target); + + WebGLActiveInfo getActiveAttrib(WebGLProgram program, int index); + + WebGLActiveInfo getActiveUniform(WebGLProgram program, int index); + + JSArrayReader getAttachedShaders(WebGLProgram program); + + @JSMethod("getAttachedShaders") + WebGLShader[] getAttachedShadersArray(WebGLProgram program); + + int getAttribLocation(WebGLProgram program, String name); + + JSObject getBufferParameter(int target, int pname); + + JSObject getParameter(int pname); + + int getError(); + + JSObject getFramebufferAttachmentParameter(int target, int attachment, int pname); + + JSObject getProgramParameter(WebGLProgram program, int pname); + + String getProgramInfoLog(WebGLProgram program); + + JSObject getRenderbufferParameter(int target, int pname); + + JSObject getShaderParameter(WebGLShader shader, int pname); + + WebGLShaderPrecisionFormat getShaderPrecisionFormat(int shadertype, int precisiontype); + + String getShaderInfoLog(WebGLShader shader); + + String getShaderSource(WebGLShader shader); + + JSObject getTexParameter(int target, int pname); + + JSObject getUniform(WebGLProgram program, WebGLUniformLocation location); + + WebGLUniformLocation getUniformLocation(WebGLProgram program, String name); + + JSObject getVertexAttrib(int index, int pname); + + int getVertexAttribOffset(int index, int pname); + + void hint(int target, int mode); + + boolean isBuffer(WebGLBuffer buffer); + + boolean isEnabled(int cap); + + boolean isFramebuffer(WebGLFramebuffer framebuffer); + + boolean isProgram(WebGLProgram program); + + boolean isRenderbuffer(WebGLRenderbuffer renderbuffer); + + boolean isShader(WebGLShader shader); + + boolean isTexture(WebGLTexture texture); + + void lineWidth(float width); + + void linkProgram(WebGLProgram program); + + void pixelStorei(int pname, int param); + + void polygonOffset(float factor, float units); + + void readPixels(int x, int y, int width, int height, int format, int type, ArrayBufferView pixels); + + void renderbufferStorage(int target, int internalformat, int width, int height); + + void sampleCoverage(float value, boolean invert); + + void scissor(int x, int y, int width, int height); + + void shaderSource(WebGLShader shader, String source); + + void stencilFunc(int func, int ref, int mask); + + void stencilFuncSeparate(int face, int func, int ref, int mask); + + void stencilMask(int mask); + + void stencilMaskSeparate(int face, int mask); + + void stencilOp(int fail, int zfail, int zpass); + + void stencilOpSeparate(int face, int fail, int zfail, int zpass); + + void texImage2D(int target, int level, int internalformat, int width, int height, int border, int format, + int type, ArrayBufferView pixels); + + void texImage2D(int target, int level, int internalformat, int format, int type, ImageData pixels); + + void texImage2D(int target, int level, int internalformat, int format, int type, HTMLImageElement image); + + void texImage2D(int target, int level, int internalformat, int format, int type, HTMLCanvasElement canvas); + + //void texImage2D(int target, int level, int internalformat, int format, int type, HTMLVideoElement video); + + void texParameterf(int target, int pname, float param); + + void texParameteri(int target, int pname, int param); + + void texSubImage2D(int target, int level, int xoffset, int yoffset, int width, int height, int format, int type, + ArrayBufferView pixels); + + void texSubImage2D(int target, int level, int xoffset, int yoffset, int format, int type, ImageData pixels); + + void texSubImage2D(int target, int level, int xoffset, int yoffset, int format, int type, HTMLImageElement image); + + void texSubImage2D(int target, int level, int xoffset, int yoffset, int format, int type, HTMLCanvasElement canvas); + + //void texSubImage2D(int target, int level, int xoffset, int yoffset, int format, int type, HTMLVideoElement video); + + void uniform1f(WebGLUniformLocation location, float x); + + void uniform1fv(WebGLUniformLocation location, Float32Array v); + + void uniform1fv(WebGLUniformLocation location, JSFloatArrayReader v); + + void uniform1fv(WebGLUniformLocation location, float[] v); + + void uniform1i(WebGLUniformLocation location, int x); + + void uniform1iv(WebGLUniformLocation location, Int32Array v); + + void uniform1iv(WebGLUniformLocation location, JSIntArrayReader v); + + void uniform1iv(WebGLUniformLocation location, int[] v); + + void uniform2f(WebGLUniformLocation location, float x, float y); + + void uniform2fv(WebGLUniformLocation location, Float32Array v); + + void uniform2fv(WebGLUniformLocation location, JSFloatArrayReader v); + + void uniform2fv(WebGLUniformLocation location, float[] v); + + void uniform2i(WebGLUniformLocation location, int x, int y); + + void uniform2iv(WebGLUniformLocation location, Int32Array v); + + void uniform2iv(WebGLUniformLocation location, JSIntArrayReader v); + + void uniform2iv(WebGLUniformLocation location, int[] v); + + void uniform3f(WebGLUniformLocation location, float x, float y, float z); + + void uniform3fv(WebGLUniformLocation location, Float32Array v); + + void uniform3fv(WebGLUniformLocation location, JSFloatArrayReader v); + + void uniform3fv(WebGLUniformLocation location, float[] v); + + void uniform3i(WebGLUniformLocation location, int x, int y, int z); + + void uniform3iv(WebGLUniformLocation location, Int32Array v); + + void uniform3iv(WebGLUniformLocation location, JSIntArrayReader v); + + void uniform3iv(WebGLUniformLocation location, int[] v); + + void uniform4f(WebGLUniformLocation location, float x, float y, float z, float w); + + void uniform4fv(WebGLUniformLocation location, Float32Array v); + + void uniform4fv(WebGLUniformLocation location, JSFloatArrayReader v); + + void uniform4fv(WebGLUniformLocation location, float[] v); + + void uniform4i(WebGLUniformLocation location, int x, int y, int z, int w); + + void uniform4iv(WebGLUniformLocation location, Int32Array v); + + void uniform4iv(WebGLUniformLocation location, JSIntArrayReader v); + + void uniform4iv(WebGLUniformLocation location, int[] v); + + void uniformMatrix2fv(WebGLUniformLocation location, boolean transpose, Float32Array value); + + void uniformMatrix2fv(WebGLUniformLocation location, boolean transpose, JSFloatArrayReader value); + + void uniformMatrix2fv(WebGLUniformLocation location, boolean transpose, float[] value); + + void uniformMatrix3fv(WebGLUniformLocation location, boolean transpose, Float32Array value); + + void uniformMatrix3fv(WebGLUniformLocation location, boolean transpose, JSFloatArrayReader value); + + void uniformMatrix3fv(WebGLUniformLocation location, boolean transpose, float[] value); + + void uniformMatrix4fv(WebGLUniformLocation location, boolean transpose, Float32Array value); + + void uniformMatrix4fv(WebGLUniformLocation location, boolean transpose, JSFloatArrayReader value); + + void uniformMatrix4fv(WebGLUniformLocation location, boolean transpose, float[] value); + + void useProgram(WebGLProgram program); + + void validateProgram(WebGLProgram program); + + void vertexAttrib1f(int indx, float x); + + void vertexAttrib1fv(int indx, Float32Array values); + + void vertexAttrib1fv(int indx, JSFloatArrayReader values); + + void vertexAttrib1fv(int indx, float[] values); + + void vertexAttrib2f(int indx, float x, float y); + + void vertexAttrib2fv(int indx, Float32Array values); + + void vertexAttrib2fv(int indx, JSFloatArrayReader values); + + void vertexAttrib2fv(int indx, float[] values); + + void vertexAttrib3f(int indx, float x, float y, float z); + + void vertexAttrib3fv(int indx, Float32Array values); + + void vertexAttrib3fv(int indx, JSFloatArrayReader values); + + void vertexAttrib3fv(int indx, float[] values); + + void vertexAttrib4f(int indx, float x, float y, float z, float w); + + void vertexAttrib4fv(int indx, Float32Array values); + + void vertexAttrib4fv(int indx, JSFloatArrayReader values); + + void vertexAttrib4fv(int indx, float[] values); + + void vertexAttribPointer(int indx, int size, int type, boolean normalized, int stride, int offset); + + void viewport(int x, int y, int width, int height); } diff --git a/teavm-dom/src/main/java/org/teavm/dom/webgl/WebGLShaderPrecisionFormat.java b/teavm-dom/src/main/java/org/teavm/dom/webgl/WebGLShaderPrecisionFormat.java new file mode 100644 index 000000000..30904f3a0 --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/webgl/WebGLShaderPrecisionFormat.java @@ -0,0 +1,34 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.webgl; + +import org.teavm.jso.JSObject; +import org.teavm.jso.JSProperty; + +/** + * + * @author Alexey Andreev + */ +public interface WebGLShaderPrecisionFormat extends JSObject { + @JSProperty + int getRangeMin(); + + @JSProperty + int getRangeMax(); + + @JSProperty + int getPrecision(); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/webgl/WebGLUniformLocation.java b/teavm-dom/src/main/java/org/teavm/dom/webgl/WebGLUniformLocation.java new file mode 100644 index 000000000..feb44f94a --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/webgl/WebGLUniformLocation.java @@ -0,0 +1,34 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.webgl; + +import org.teavm.jso.JSObject; +import org.teavm.jso.JSProperty; + +/** + * + * @author Alexey Andreev + */ +public interface WebGLUniformLocation extends JSObject { + @JSProperty + int getSize(); + + @JSProperty + int getType(); + + @JSProperty + String getName(); +} diff --git a/teavm-jso/src/main/java/org/teavm/jso/JS.java b/teavm-jso/src/main/java/org/teavm/jso/JS.java index 2f1e73325..0c806dea4 100644 --- a/teavm-jso/src/main/java/org/teavm/jso/JS.java +++ b/teavm-jso/src/main/java/org/teavm/jso/JS.java @@ -47,6 +47,12 @@ public final class JS { public static native JSArray createArray(int size); + public static native JSIntArray createIntArray(int size); + + public static native JSStringArray createStringArray(int size); + + public static native JSFloatArray createFloatArray(int size); + @InjectedBy(JSNativeGenerator.class) public static native JSObject getTypeName(JSObject obj); @@ -95,6 +101,78 @@ public final class JS { return result; } + public static JSIntArray wrap(int[] array) { + JSIntArray result = createIntArray(array.length); + for (int i = 0; i < array.length; ++i) { + result.set(i, array[i]); + } + return result; + } + + public static JSArray wrap(int[][] array) { + JSArray result = createArray(array.length); + for (int i = 0; i < array.length; ++i) { + result.set(i, wrap(array[i])); + } + return result; + } + + public static JSArray> wrap(int[][][] array) { + JSArray> result = createArray(array.length); + for (int i = 0; i < array.length; ++i) { + result.set(i, wrap(array[i])); + } + return result; + } + + public static JSStringArray wrap(String[] array) { + JSStringArray result = createStringArray(array.length); + for (int i = 0; i < array.length; ++i) { + result.set(i, array[i]); + } + return result; + } + + public static JSArray wrap(String[][] array) { + JSArray result = createArray(array.length); + for (int i = 0; i < array.length; ++i) { + result.set(i, wrap(array[i])); + } + return result; + } + + public static JSArray> wrap(String[][][] array) { + JSArray> result = createArray(array.length); + for (int i = 0; i < array.length; ++i) { + result.set(i, wrap(array[i])); + } + return result; + } + + public static JSFloatArray wrap(float[] array) { + JSFloatArray result = createFloatArray(array.length); + for (int i = 0; i < array.length; ++i) { + result.set(i, array[i]); + } + return result; + } + + public static JSArray wrap(float[][] array) { + JSArray result = createArray(array.length); + for (int i = 0; i < array.length; ++i) { + result.set(i, wrap(array[i])); + } + return result; + } + + public static JSArray> wrap(float[][][] array) { + JSArray> result = createArray(array.length); + for (int i = 0; i < array.length; ++i) { + result.set(i, wrap(array[i])); + } + return result; + } + @InjectedBy(JSNativeGenerator.class) public static native boolean unwrapBoolean(JSObject obj); diff --git a/teavm-jso/src/main/java/org/teavm/jso/JSArray.java b/teavm-jso/src/main/java/org/teavm/jso/JSArray.java index 44049df4d..402582300 100644 --- a/teavm-jso/src/main/java/org/teavm/jso/JSArray.java +++ b/teavm-jso/src/main/java/org/teavm/jso/JSArray.java @@ -37,13 +37,13 @@ public interface JSArray extends JSArrayReader { String join(); - JSArray concat(JSArray a); + JSArray concat(JSArrayReader a); - JSArray concat(JSArray a, JSArray b); + JSArray concat(JSArrayReader a, JSArrayReader b); - JSArray concat(JSArray a, JSArray b, JSArray c); + JSArray concat(JSArrayReader a, JSArrayReader b, JSArrayReader c); - JSArray concat(JSArray a, JSArray b, JSArray c, JSArray d); + JSArray concat(JSArrayReader a, JSArrayReader b, JSArrayReader c, JSArrayReader d); T pop(); diff --git a/teavm-jso/src/main/java/org/teavm/jso/JSBooleanArrayReader.java b/teavm-jso/src/main/java/org/teavm/jso/JSBooleanArrayReader.java new file mode 100644 index 000000000..a4356215f --- /dev/null +++ b/teavm-jso/src/main/java/org/teavm/jso/JSBooleanArrayReader.java @@ -0,0 +1,28 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso; + +/** + * + * @author Alexey Andreev + */ +public interface JSBooleanArrayReader extends JSObject { + @JSProperty + int getLength(); + + @JSIndexer + boolean get(int index); +} diff --git a/teavm-jso/src/main/java/org/teavm/jso/JSByteArrayReader.java b/teavm-jso/src/main/java/org/teavm/jso/JSByteArrayReader.java new file mode 100644 index 000000000..4124e45d6 --- /dev/null +++ b/teavm-jso/src/main/java/org/teavm/jso/JSByteArrayReader.java @@ -0,0 +1,28 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso; + +/** + * + * @author Alexey Andreev + */ +public interface JSByteArrayReader extends JSObject { + @JSProperty + int getLength(); + + @JSIndexer + byte get(int index); +} diff --git a/teavm-jso/src/main/java/org/teavm/jso/JSDoubleArrayReader.java b/teavm-jso/src/main/java/org/teavm/jso/JSDoubleArrayReader.java new file mode 100644 index 000000000..ddb30155b --- /dev/null +++ b/teavm-jso/src/main/java/org/teavm/jso/JSDoubleArrayReader.java @@ -0,0 +1,28 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso; + +/** + * + * @author Alexey Andreev + */ +public interface JSDoubleArrayReader extends JSObject { + @JSProperty + int getLength(); + + @JSIndexer + double get(int index); +} diff --git a/teavm-jso/src/main/java/org/teavm/jso/JSFloatArray.java b/teavm-jso/src/main/java/org/teavm/jso/JSFloatArray.java new file mode 100644 index 000000000..d6f05133a --- /dev/null +++ b/teavm-jso/src/main/java/org/teavm/jso/JSFloatArray.java @@ -0,0 +1,24 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso; + +/** + * + * @author Alexey Andreev + */ +public interface JSFloatArray extends JSFloatArrayReader { + +} diff --git a/teavm-jso/src/main/java/org/teavm/jso/JSFloatArrayReader.java b/teavm-jso/src/main/java/org/teavm/jso/JSFloatArrayReader.java new file mode 100644 index 000000000..da2aed665 --- /dev/null +++ b/teavm-jso/src/main/java/org/teavm/jso/JSFloatArrayReader.java @@ -0,0 +1,83 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso; + +/** + * + * @author Alexey Andreev + */ +public interface JSFloatArrayReader extends JSObject { + @JSProperty + int getLength(); + + @JSIndexer + float get(int index); + + @JSIndexer + void set(int index, float value); + + int push(float a); + + int push(float a, float b); + + int push(float a, float b, float c); + + int push(float a, float b, float c, float d); + + float shift(); + + String join(String separator); + + String join(); + + JSFloatArray concat(JSFloatArrayReader a); + + JSFloatArray concat(JSFloatArray a, JSFloatArray b); + + JSFloatArray concat(JSFloatArray a, JSFloatArray b, JSFloatArray c); + + JSFloatArray concat(JSFloatArray a, JSFloatArray b, JSFloatArray c, JSFloatArray d); + + float pop(); + + int unshift(float a); + + int unshift(float a, float b); + + int unshift(float a, float b, float c); + + int unshift(float a, float b, float c, float d); + + JSFloatArray slice(int start); + + JSFloatArray slice(int start, int end); + + JSFloatArray reverse(); + + JSFloatArray sort(JSFloatSortFunction function); + + JSFloatArray sort(); + + JSFloatArray splice(int start, int count); + + JSFloatArray splice(int start, int count, float a); + + JSFloatArray splice(int start, int count, float a, float b); + + JSFloatArray splice(int start, int count, float a, float b, float c); + + JSFloatArray splice(int start, int count, float a, float b, float c, float d); +} diff --git a/teavm-jso/src/main/java/org/teavm/jso/JSFloatSortFunction.java b/teavm-jso/src/main/java/org/teavm/jso/JSFloatSortFunction.java new file mode 100644 index 000000000..a5a0a95ac --- /dev/null +++ b/teavm-jso/src/main/java/org/teavm/jso/JSFloatSortFunction.java @@ -0,0 +1,25 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso; + +/** + * + * @author Alexey Andreev + */ +@JSFunctor +public interface JSFloatSortFunction { + int compare(float a, float b); +} diff --git a/teavm-jso/src/main/java/org/teavm/jso/JSGlobal.java b/teavm-jso/src/main/java/org/teavm/jso/JSGlobal.java index 797c45660..fe29c8038 100644 --- a/teavm-jso/src/main/java/org/teavm/jso/JSGlobal.java +++ b/teavm-jso/src/main/java/org/teavm/jso/JSGlobal.java @@ -28,4 +28,22 @@ public interface JSGlobal extends JSObject { @JSConstructor JSArray newArray(int sz); + + @JSConstructor("Array") + JSStringArray newStringArray(); + + @JSConstructor("Array") + JSStringArray newStringArray(int sz); + + @JSConstructor("Array") + JSIntArray newIntArray(); + + @JSConstructor("Array") + JSIntArray newIntArray(int sz); + + @JSConstructor("Array") + JSFloatArray newFloatArray(); + + @JSConstructor("Array") + JSFloatArray newFloatArray(int sz); } diff --git a/teavm-jso/src/main/java/org/teavm/jso/JSIntArray.java b/teavm-jso/src/main/java/org/teavm/jso/JSIntArray.java new file mode 100644 index 000000000..662d7f326 --- /dev/null +++ b/teavm-jso/src/main/java/org/teavm/jso/JSIntArray.java @@ -0,0 +1,77 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso; + +/** + * + * @author Alexey Andreev + */ +public interface JSIntArray extends JSIntArrayReader { + @JSIndexer + void set(int index, int value); + + int push(int a); + + int push(int a, int b); + + int push(int a, int b, int c); + + int push(int a, int b, int c, int d); + + int shift(); + + int join(int separator); + + int join(); + + JSIntArray concat(JSIntArrayReader a); + + JSIntArray concat(JSIntArrayReader a, JSIntArrayReader b); + + JSIntArray concat(JSIntArrayReader a, JSIntArrayReader b, JSIntArrayReader c); + + JSIntArray concat(JSIntArrayReader a, JSIntArrayReader b, JSIntArrayReader c, JSIntArrayReader d); + + int pop(); + + int unshift(int a); + + int unshift(int a, int b); + + int unshift(int a, int b, int c); + + int unshift(int a, int b, int c, int d); + + JSIntArray slice(int start); + + JSIntArray slice(int start, int end); + + JSIntArray reverse(); + + JSIntArray sort(JSIntSortFunction function); + + JSIntArray sort(); + + JSIntArray splice(int start, int count); + + JSIntArray splice(int start, int count, int a); + + JSIntArray splice(int start, int count, int a, int b); + + JSIntArray splice(int start, int count, int a, int b, int c); + + JSIntArray splice(int start, int count, int a, int b, int c, int d); +} diff --git a/teavm-jso/src/main/java/org/teavm/jso/JSIntArrayReader.java b/teavm-jso/src/main/java/org/teavm/jso/JSIntArrayReader.java new file mode 100644 index 000000000..cc52d6e69 --- /dev/null +++ b/teavm-jso/src/main/java/org/teavm/jso/JSIntArrayReader.java @@ -0,0 +1,28 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso; + +/** + * + * @author Alexey Andreev + */ +public interface JSIntArrayReader extends JSObject { + @JSProperty + int getLength(); + + @JSIndexer + int get(int index); +} diff --git a/teavm-jso/src/main/java/org/teavm/jso/JSIntSortFunction.java b/teavm-jso/src/main/java/org/teavm/jso/JSIntSortFunction.java new file mode 100644 index 000000000..17c513c01 --- /dev/null +++ b/teavm-jso/src/main/java/org/teavm/jso/JSIntSortFunction.java @@ -0,0 +1,25 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso; + +/** + * + * @author Alexey Andreev + */ +@JSFunctor +public interface JSIntSortFunction extends JSObject { + int compare(int a, int b); +} diff --git a/teavm-jso/src/main/java/org/teavm/jso/JSShortArrayReader.java b/teavm-jso/src/main/java/org/teavm/jso/JSShortArrayReader.java new file mode 100644 index 000000000..d9d195403 --- /dev/null +++ b/teavm-jso/src/main/java/org/teavm/jso/JSShortArrayReader.java @@ -0,0 +1,28 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso; + +/** + * + * @author Alexey Andreev + */ +public interface JSShortArrayReader extends JSObject { + @JSProperty + int getLength(); + + @JSIndexer + short get(int index); +} diff --git a/teavm-jso/src/main/java/org/teavm/jso/JSStringArray.java b/teavm-jso/src/main/java/org/teavm/jso/JSStringArray.java new file mode 100644 index 000000000..ee539c322 --- /dev/null +++ b/teavm-jso/src/main/java/org/teavm/jso/JSStringArray.java @@ -0,0 +1,77 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso; + +/** + * + * @author Alexey Andreev + */ +public interface JSStringArray extends JSStringArrayReader { + @JSIndexer + void set(int index, String value); + + int push(String a); + + int push(String a, String b); + + int push(String a, String b, String c); + + int push(String a, String b, String c, String d); + + String shift(); + + String join(String separator); + + String join(); + + JSStringArray concat(JSStringArrayReader a); + + JSStringArray concat(JSStringArrayReader a, JSStringArrayReader b); + + JSStringArray concat(JSStringArrayReader a, JSStringArrayReader b, JSStringArrayReader c); + + JSStringArray concat(JSStringArrayReader a, JSStringArrayReader b, JSStringArrayReader c, JSStringArrayReader d); + + String pop(); + + int unshift(String a); + + int unshift(String a, String b); + + int unshift(String a, String b, String c); + + int unshift(String a, String b, String c, String d); + + JSStringArray slice(int start); + + JSStringArray slice(int start, int end); + + JSStringArray reverse(); + + JSStringArray sort(JSStringSortFunction function); + + JSStringArray sort(); + + JSStringArray splice(int start, int count); + + JSStringArray splice(int start, int count, String a); + + JSStringArray splice(int start, int count, String a, String b); + + JSStringArray splice(int start, int count, String a, String b, String c); + + JSStringArray splice(int start, int count, String a, String b, String c, String d); +} diff --git a/teavm-jso/src/main/java/org/teavm/jso/JSStringSortFunction.java b/teavm-jso/src/main/java/org/teavm/jso/JSStringSortFunction.java new file mode 100644 index 000000000..4562d3dce --- /dev/null +++ b/teavm-jso/src/main/java/org/teavm/jso/JSStringSortFunction.java @@ -0,0 +1,25 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso; + +/** + * + * @author Alexey Andreev + */ +@JSFunctor +public interface JSStringSortFunction extends JSObject { + int compare(String a, String b); +}