GLData.java 1.71 KB
Newer Older
Gaëtan Renaudeau's avatar
WIP  
Gaëtan Renaudeau committed
1 2 3 4 5 6 7 8 9 10 11 12
package com.projectseptember.RNGL;

import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;

import java.util.ArrayList;
import java.util.List;

public class GLData {

    final Integer shader;
    final ReadableMap uniforms;
13 14 15
    final Double width;
    final Double height;
    final Double pixelRatio;
Gaëtan Renaudeau's avatar
WIP  
Gaëtan Renaudeau committed
16 17 18 19
    final Integer fboId;
    final List<GLData> contextChildren;
    final List<GLData> children;

20
    public GLData(Integer shader, ReadableMap uniforms, Double width, Double height, Double pixelRatio, Integer fboId, List<GLData> contextChildren, List<GLData> children) {
Gaëtan Renaudeau's avatar
WIP  
Gaëtan Renaudeau committed
21 22 23 24
        this.shader = shader;
        this.uniforms = uniforms;
        this.width = width;
        this.height = height;
25
        this.pixelRatio = pixelRatio;
Gaëtan Renaudeau's avatar
WIP  
Gaëtan Renaudeau committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
        this.fboId = fboId;
        this.contextChildren = contextChildren;
        this.children = children;
    }

    public static List<GLData> fromArray (ReadableArray arr) {
        ArrayList<GLData> list = new ArrayList<>();
        for (int i=0; i < arr.size(); i++) {
            list.add(fromMap(arr.getMap(i)));
        }
        return list;
    }

    public static GLData fromMap (ReadableMap map) {
        Integer shader = map.getInt("shader");
        ReadableMap uniforms = map.getMap("uniforms");
42 43 44
        Double width = map.getDouble("width");
        Double height = map.getDouble("height");
        Double pixelRatio = map.getDouble("pixelRatio");
Gaëtan Renaudeau's avatar
WIP  
Gaëtan Renaudeau committed
45 46 47
        Integer fboId = map.getInt("fboId");
        List<GLData> children = fromArray(map.getArray("children"));
        List<GLData> contextChildren = fromArray(map.getArray("contextChildren"));
48
        return new GLData(shader, uniforms, width, height, pixelRatio, fboId, contextChildren, children);
Gaëtan Renaudeau's avatar
WIP  
Gaëtan Renaudeau committed
49 50
    }
}