Commit 7eea4594 authored by iSergio's avatar iSergio
Browse files

Add TextureUniform

parent ce11881f
Loading
Loading
Loading
Loading
+76 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 iserge, Gis4Fun.
 *
 * 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.cesiumjs.cs.scene.experimental;

import com.google.gwt.typedarrays.shared.Uint8Array;
import jsinterop.annotations.JsConstructor;
import jsinterop.annotations.JsOverlay;
import jsinterop.annotations.JsProperty;
import jsinterop.annotations.JsType;
import org.cesiumjs.cs.core.Resource;
import org.cesiumjs.cs.core.enums.PixelDatatype;
import org.cesiumjs.cs.core.enums.PixelFormat;
import org.cesiumjs.cs.scene.experimental.options.TextureUniformOptions;

/**
 * A simple struct that serves as a value of a sampler2D-valued uniform.
 * This is used with {@link CustomShader} and {@link TextureManager}.
 */
@JsType(isNative = true, namespace = "Cesium", name = "TextureUniform")
public class TextureUniform {
    /**
     * A typed array storing the contents of a texture. Values are stored in row-major order. Since WebGL uses a y-up
     * convention for textures, rows are listed from bottom to top.
     */
    @JsProperty(name = "typedArray")
    public native Uint8Array typedArray();
    /**
     * The width of the image. Required when {@link this#typedArray} is present.
     */
    @JsProperty(name = "width")
    public native Number width();
    /**
     * The height of the image. Required when {@link this#typedArray} is present.
     */
    @JsProperty(name = "height")
    public native Number height();
    /**
     * When {@link this#typedArray} is defined, this is used to determine the pixel format of the texture
     * Default: {@link PixelFormat#RGBA()}
     */
    @JsProperty(name = "pixelFormat")
    public native Number pixelFormat();
    /**
     * When {@link this#typedArray} is defined, this is the data type of pixel values in the typed array.
     * Default: {@link PixelDatatype#UNSIGNED_BYTE()}
     */
    @JsProperty(name = "pixelDatatype")
    public native Number pixelDatatype();

    @JsConstructor
    public TextureUniform(TextureUniformOptions options) {}

    @JsOverlay
    public static TextureUniform create(String url) {
        return new TextureUniform(new TextureUniformOptions().setUrl(url));
    }

    @JsOverlay
    public static TextureUniform create(Resource url) {
        return new TextureUniform(new TextureUniformOptions().setUrl(url));
    }
}
+163 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 iserge, Gis4Fun.
 *
 * 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.cesiumjs.cs.scene.experimental.options;

import com.google.gwt.typedarrays.shared.Uint8Array;
import jsinterop.annotations.*;
import org.cesiumjs.cs.core.Resource;
import org.cesiumjs.cs.core.enums.PixelDatatype;
import org.cesiumjs.cs.core.enums.PixelFormat;
import org.cesiumjs.cs.scene.enums.TextureMagnificationFilter;
import org.cesiumjs.cs.scene.enums.TextureMinificationFilter;

/**
 * Options for {@link org.cesiumjs.cs.scene.experimental.TextureUniform}.
 */
@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object")
public class TextureUniformOptions {
    /**
     * A typed array storing the contents of a texture. Values are stored in row-major order. Since WebGL uses a y-up
     * convention for textures, rows are listed from bottom to top.
     */
    @JsProperty
    public Uint8Array typedArray;
    /**
     * The width of the image. Required when {@link this#typedArray} is present.
     */
    @JsProperty
    public int width;
    /**
     * The height of the image. Required when {@link this#typedArray} is present.
     */
    @JsProperty
    public int height;
    /**
     * A URL string or resource pointing to a texture image.
     */
    @JsProperty
    public String url;
    /**
     * A URL resource or resource pointing to a texture image.
     */
    @JsProperty(name = "url")
    public Resource urlRes;
    /**
     * When defined, the texture sampler will be set to wrap in both directions.
     * Default: true
     */
    @JsProperty
    public boolean repeat;
    /**
     * When {@link this#typedArray} is defined, this is used to determine the pixel format of the texture
     * Default: {@link PixelFormat#RGBA()}
     */
    @JsProperty
    public Number pixelFormat;
    /**
     * When {@link this#typedArray} is defined, this is the data type of pixel values in the typed array.
     * Default: {@link PixelDatatype#UNSIGNED_BYTE()}
     */
    @JsProperty
    public Number pixelDatatype;
    /**
     * The minification filter of the texture sampler.
     * Default: {@link TextureMinificationFilter#LINEAR()}
     */
    @JsProperty
    public Number minificationFilter;
    /**
     * The magnification filter of the texture sampler.
     * Default: {@link TextureMagnificationFilter#LINEAR()}
     */
    @JsProperty
    public Number magnificationFilter;
    /**
     * The maximum anisotropy of the texture sampler.
     * Default: 1.0
     */
    @JsProperty
    public Number maximumAnisotropy;

    @JsConstructor
    public TextureUniformOptions() {}

    @JsOverlay
    public final TextureUniformOptions setTypedArray(Uint8Array typedArray) {
        this.typedArray = typedArray;
        return this;
    }

    @JsOverlay
    public final TextureUniformOptions setWidth(int width) {
        this.width = width;
        return this;
    }

    @JsOverlay
    public final TextureUniformOptions setHeight(int height) {
        this.height = height;
        return this;
    }

    @JsOverlay
    public final TextureUniformOptions setUrl(String url) {
        this.url = url;
        return this;
    }

    @JsOverlay
    public final TextureUniformOptions setUrl(Resource url) {
        this.urlRes = url;
        return this;
    }

    @JsOverlay
    public final TextureUniformOptions setRepeat(boolean repeat) {
        this.repeat = repeat;
        return this;
    }

    @JsOverlay
    public final TextureUniformOptions setPixelFormat(Number pixelFormat) {
        this.pixelFormat = pixelFormat;
        return this;
    }

    @JsOverlay
    public final TextureUniformOptions setPixelDatatype(Number pixelDatatype) {
        this.pixelDatatype = pixelDatatype;
        return this;
    }

    @JsOverlay
    public final TextureUniformOptions setMinificationFilter(Number minificationFilter) {
        this.minificationFilter = minificationFilter;
        return this;
    }

    @JsOverlay
    public final TextureUniformOptions setMagnificationFilter(Number magnificationFilter) {
        this.magnificationFilter = magnificationFilter;
        return this;
    }

    @JsOverlay
    public final TextureUniformOptions setMaximumAnisotropy(Number maximumAnisotropy) {
        this.maximumAnisotropy = maximumAnisotropy;
        return this;
    }
}