GLData.java 1.56 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 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
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;
    final Integer width;
    final Integer height;
    final Integer fboId;
    final List<GLData> contextChildren;
    final List<GLData> children;

    public GLData(Integer shader, ReadableMap uniforms, Integer width, Integer height, Integer fboId, List<GLData> contextChildren, List<GLData> children) {
        this.shader = shader;
        this.uniforms = uniforms;
        this.width = width;
        this.height = height;
        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");
        Integer width = map.getInt("width");
        Integer height = map.getInt("height");
        Integer fboId = map.getInt("fboId");
        List<GLData> children = fromArray(map.getArray("children"));
        List<GLData> contextChildren = fromArray(map.getArray("contextChildren"));
        return new GLData(shader, uniforms, width, height, fboId, contextChildren, children);
    }
}