From be4457c28567664b364a2da4fd611620405ca3e3 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Fri, 23 Jan 2015 19:28:12 +0400 Subject: [PATCH] Fix errors in WebGL wrappers. Add support of some typed arrays --- .../java/org/teavm/dom/browser/Window.java | 50 ++++++++++++++----- .../teavm/dom/typedarrays/Float64Array.java | 30 +++++++++++ .../org/teavm/dom/typedarrays/Int16Array.java | 30 +++++++++++ .../org/teavm/dom/typedarrays/Uint8Array.java | 30 +++++++++++ .../org/teavm/dom/webgl/WebGLActiveInfo.java | 8 +++ .../dom/webgl/WebGLRenderingContext.java | 21 ++++++++ .../teavm/dom/webgl/WebGLUniformLocation.java | 9 ---- teavm-jso/src/main/java/org/teavm/jso/JS.java | 33 ++++++++++++ 8 files changed, 190 insertions(+), 21 deletions(-) create mode 100644 teavm-dom/src/main/java/org/teavm/dom/typedarrays/Float64Array.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/typedarrays/Int16Array.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/typedarrays/Uint8Array.java 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 58192a172..b5bc86c4d 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 @@ -17,8 +17,7 @@ package org.teavm.dom.browser; import org.teavm.dom.ajax.XMLHttpRequest; import org.teavm.dom.html.HTMLDocument; -import org.teavm.dom.typedarrays.ArrayBuffer; -import org.teavm.dom.typedarrays.Int8Array; +import org.teavm.dom.typedarrays.*; import org.teavm.jso.JSConstructor; import org.teavm.jso.JSGlobal; import org.teavm.jso.JSObject; @@ -62,30 +61,57 @@ public interface Window extends JSGlobal { @JSConstructor("Int8Array") Int8Array createInt8Array(ArrayBuffer buffer, int offset, int length); - @JSConstructor("Uint8ClampedArray") - Int8Array createUint8ClampedArray(int length); + @JSConstructor("Uint8Array") + Uint8Array createUint8Array(int length); + + @JSConstructor("Uint8Array") + Uint8Array createUint8Array(ArrayBuffer buffer); + + @JSConstructor("Uint8Array") + Uint8Array createUint8Array(ArrayBuffer buffer, int offset, int length); @JSConstructor("Uint8ClampedArray") - Int8Array createUint8ClampedArray(ArrayBuffer buffer); + Uint8ClampedArray createUint8ClampedArray(int length); @JSConstructor("Uint8ClampedArray") - Int8Array createUintClamped8Array(ArrayBuffer buffer, int offset, int length); + Uint8ClampedArray createUint8ClampedArray(ArrayBuffer buffer); + + @JSConstructor("Uint8ClampedArray") + Uint8ClampedArray createUintClamped8Array(ArrayBuffer buffer, int offset, int length); + + @JSConstructor("Int16Array") + Int16Array createInt16Array(int length); + + @JSConstructor("Int16Array") + Int16Array createInt16Array(ArrayBuffer buffer); + + @JSConstructor("Int16Array") + Int16Array createInt16Array(ArrayBuffer buffer, int offset, int length); @JSConstructor("Int32Array") - Int8Array createInt32Array(int length); + Int32Array createInt32Array(int length); @JSConstructor("Int32Array") - Int8Array createInt32Array(ArrayBuffer buffer); + Int32Array createInt32Array(ArrayBuffer buffer); @JSConstructor("Int32Array") - Int8Array createInt32Array(ArrayBuffer buffer, int offset, int length); + Int32Array createInt32Array(ArrayBuffer buffer, int offset, int length); @JSConstructor("Float32Array") - Int8Array createFloat32Array(int length); + Float32Array createFloat32Array(int length); @JSConstructor("Float32Array") - Int8Array createFloat32Array(ArrayBuffer buffer); + Float32Array createFloat32Array(ArrayBuffer buffer); @JSConstructor("Float32Array") - Int8Array createFloat32Array(ArrayBuffer buffer, int offset, int length); + Float32Array createFloat32Array(ArrayBuffer buffer, int offset, int length); + + @JSConstructor("Float64Array") + Float64Array createFloat64Array(int length); + + @JSConstructor("Float64Array") + Float64Array createFloat64Array(ArrayBuffer buffer); + + @JSConstructor("Float64Array") + Float64Array createFloat64Array(ArrayBuffer buffer, int offset, int length); } diff --git a/teavm-dom/src/main/java/org/teavm/dom/typedarrays/Float64Array.java b/teavm-dom/src/main/java/org/teavm/dom/typedarrays/Float64Array.java new file mode 100644 index 000000000..d9faf3f82 --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/typedarrays/Float64Array.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 Float64Array extends ArrayBufferView { + @JSIndexer + double get(int index); + + @JSIndexer + void set(int index, double value); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/typedarrays/Int16Array.java b/teavm-dom/src/main/java/org/teavm/dom/typedarrays/Int16Array.java new file mode 100644 index 000000000..07eac2f3d --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/typedarrays/Int16Array.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 Int16Array extends ArrayBufferView { + @JSIndexer + short get(int index); + + @JSIndexer + void set(int index, short value); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/typedarrays/Uint8Array.java b/teavm-dom/src/main/java/org/teavm/dom/typedarrays/Uint8Array.java new file mode 100644 index 000000000..6983e7d7a --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/typedarrays/Uint8Array.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 Uint8Array extends ArrayBufferView { + @JSIndexer + short get(int index); + + @JSIndexer + void set(int index, short 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 index 637e08cc3..8ee75e8db 100644 --- a/teavm-dom/src/main/java/org/teavm/dom/webgl/WebGLActiveInfo.java +++ b/teavm-dom/src/main/java/org/teavm/dom/webgl/WebGLActiveInfo.java @@ -16,11 +16,19 @@ package org.teavm.dom.webgl; import org.teavm.jso.JSObject; +import org.teavm.jso.JSProperty; /** * * @author Alexey Andreev */ public interface WebGLActiveInfo extends JSObject { + @JSProperty + int getSize(); + @JSProperty + int getType(); + + @JSProperty + String getName(); } 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 1d6479e0d..29da28f1c 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 @@ -527,18 +527,39 @@ public interface WebGLRenderingContext extends JSObject { JSObject getParameter(int pname); + @JSMethod("getParameter") + int getParameteri(int pname); + + @JSMethod("getParameter") + String getParameterString(int pname); + + @JSMethod("getParameter") + float getParameterf(int pname); + int getError(); JSObject getFramebufferAttachmentParameter(int target, int attachment, int pname); JSObject getProgramParameter(WebGLProgram program, int pname); + @JSMethod("getProgramParameter") + boolean getProgramParameterb(WebGLProgram program, int pname); + + @JSMethod("getProgramParameter") + int getProgramParameteri(WebGLProgram program, int pname); + String getProgramInfoLog(WebGLProgram program); JSObject getRenderbufferParameter(int target, int pname); JSObject getShaderParameter(WebGLShader shader, int pname); + @JSMethod("getShaderParameter") + boolean getShaderParameterb(WebGLShader shader, int pname); + + @JSMethod("getShaderParameter") + int getShaderParameteri(WebGLShader shader, int pname); + WebGLShaderPrecisionFormat getShaderPrecisionFormat(int shadertype, int precisiontype); String getShaderInfoLog(WebGLShader shader); 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 index feb44f94a..27fe18d7a 100644 --- a/teavm-dom/src/main/java/org/teavm/dom/webgl/WebGLUniformLocation.java +++ b/teavm-dom/src/main/java/org/teavm/dom/webgl/WebGLUniformLocation.java @@ -16,19 +16,10 @@ 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 0c806dea4..6de56e908 100644 --- a/teavm-jso/src/main/java/org/teavm/jso/JS.java +++ b/teavm-jso/src/main/java/org/teavm/jso/JS.java @@ -77,6 +77,12 @@ public final class JS { @InjectedBy(JSNativeGenerator.class) public static native JSObject wrap(boolean num); + @InjectedBy(JSNativeGenerator.class) + public static native JSObject wrap(byte num); + + @InjectedBy(JSNativeGenerator.class) + public static native JSObject wrap(short num); + public static JSArray wrap(T[] array) { JSArray result = createArray(array.length); for (int i = 0; i < array.length; ++i) { @@ -244,6 +250,33 @@ public final class JS { public static native JSObject invoke(JSObject instance, JSObject method, JSObject a, JSObject b, JSObject c, JSObject d, JSObject e, JSObject f, JSObject g, JSObject h); + @InjectedBy(JSNativeGenerator.class) + @PluggableDependency(JSNativeGenerator.class) + public static native JSObject invoke(JSObject instance, JSObject method, JSObject a, JSObject b, JSObject c, + JSObject d, JSObject e, JSObject f, JSObject g, JSObject h, JSObject i); + + @InjectedBy(JSNativeGenerator.class) + @PluggableDependency(JSNativeGenerator.class) + public static native JSObject invoke(JSObject instance, JSObject method, JSObject a, JSObject b, JSObject c, + JSObject d, JSObject e, JSObject f, JSObject g, JSObject h, JSObject i, JSObject j); + + @InjectedBy(JSNativeGenerator.class) + @PluggableDependency(JSNativeGenerator.class) + public static native JSObject invoke(JSObject instance, JSObject method, JSObject a, JSObject b, JSObject c, + JSObject d, JSObject e, JSObject f, JSObject g, JSObject h, JSObject i, JSObject j, JSObject k); + + @InjectedBy(JSNativeGenerator.class) + @PluggableDependency(JSNativeGenerator.class) + public static native JSObject invoke(JSObject instance, JSObject method, JSObject a, JSObject b, JSObject c, + JSObject d, JSObject e, JSObject f, JSObject g, JSObject h, JSObject i, JSObject j, JSObject k, + JSObject l); + + @InjectedBy(JSNativeGenerator.class) + @PluggableDependency(JSNativeGenerator.class) + public static native JSObject invoke(JSObject instance, JSObject method, JSObject a, JSObject b, JSObject c, + JSObject d, JSObject e, JSObject f, JSObject g, JSObject h, JSObject i, JSObject j, JSObject k, + JSObject l, JSObject m); + @InjectedBy(JSNativeGenerator.class) @PluggableDependency(JSNativeGenerator.class) public static native JSObject instantiate(JSObject instance, JSObject constructor);