Search in sources :

Example 16 with DependencyConnection

use of org.terasology.engine.rendering.dag.dependencyConnections.DependencyConnection in project Terasology by MovingBlocks.

the class RenderGraph method reconnectInputToOutput.

/**
 * API for reconnecting input FBO dependency.
 *
 * Expects 2 existing nodes and an existing output connection on fromNode. Output connection must be created explicitly
 * beforehand or simply exist already.
 *
 * If previous requirements are met, attempts to connectFbo or reconnect toNode's (toNodeUri) input (inputId)
 * to fromNode's (fromNodeUri) output (outputId).
 * @param toNode toNode's SimpleUri name. Node must exist in the renderGraph.
 * @param inputId Id of toNode's input. Input does NOT have to exist beforehand.
 * @param fromNode fromNode's SimpleUri name. Node must exist in the renderGraph.
 * @param outputId Id of fromNode's output. Output must exist.
 */
public void reconnectInputToOutput(Node fromNode, int outputId, Node toNode, int inputId, ConnectionType connectionType, boolean disconnectPrevious) {
    // Would use of Preconditions be clearer?
    if (toNode == null || fromNode == null) {
        throw new RuntimeException("Reconnecting dependency failed. One of the nodes not found in the renderGraph." + "\n toNode: " + toNode + ". fromNode: " + fromNode);
    }
    DependencyConnection fromConnection;
    switch(connectionType) {
        case FBO:
            fromConnection = fromNode.getOutputFboConnection(outputId);
            break;
        case BUFFER_PAIR:
            fromConnection = fromNode.getOutputBufferPairConnection(outputId);
            break;
        default:
            logger.error("Unknown type of output connection: ");
            throw new RuntimeException("Unknown type of output connection: ");
    }
    if (fromConnection == null) {
        throw new RuntimeException("Reconnecting dependency failed. Could not find output connection.");
    }
    // TODO REMOVE RENDERGRAPH CONNECTION if needed
    reconnectInputToOutput(toNode, inputId, fromConnection, connectionType, disconnectPrevious);
// if (!areConnected(fromNode, toNode)) {
// connect(fromNode, toNode);
// }
}
Also used : DependencyConnection(org.terasology.engine.rendering.dag.dependencyConnections.DependencyConnection)

Example 17 with DependencyConnection

use of org.terasology.engine.rendering.dag.dependencyConnections.DependencyConnection in project Terasology by MovingBlocks.

the class RenderGraph method reconnectInputToOutput.

/**
 * API for reconnecting input dependency to another output.
 *
 * Attempts to connectFbo or reconnect toNode's input (inputId)
 * to fromNode's (fromNodeUri) output (outputId).
 * @param toNode toNode's SimpleUri name. Node must exist in the renderGraph.
 * @param inputId Id of toNode's input. Input does NOT have to exist beforehand.
 * @param fromConnection Id of fromNode's output connection. Connection must exist.
 * @param connectionType {@link ConnectionType} saying whether the dependency is Fbo, BufferPair or something else
 * @param disconnectPrevious  TO DEPRECATE; Whether to disconnect previous connection. This should now be always true.
 */
private void reconnectInputToOutput(Node toNode, int inputId, DependencyConnection fromConnection, ConnectionType connectionType, boolean disconnectPrevious) {
    logger.debug("Attempting reconnection of " + toNode.getUri() + " to " + fromConnection.getParentNode() + "'s output.");
    Node fromNode;
    fromNode = findNode(fromConnection.getParentNode());
    if (!fromConnection.getConnectedConnections().isEmpty()) {
        logger.warn("WARNING: destination connection (" + fromConnection + ") is already connected to (" + fromConnection.getConnectedConnections());
    // TODO update the hashmap to string to be pretty
    // throw new RuntimeException("Could not reconnect, destination connection (" + fromConnection + ") is already connected to ("
    // + fromConnection.getConnectedConnections() + "). Remove connection first.");
    }
    // TODO                                   make it getInputConnection
    DependencyConnection connectionToReconnect;
    switch(connectionType) {
        case FBO:
            connectionToReconnect = toNode.getInputFboConnection(inputId);
            break;
        case BUFFER_PAIR:
            connectionToReconnect = toNode.getInputBufferPairConnection(inputId);
            break;
        default:
            logger.error("Unknown type of connection: ");
            throw new RuntimeException("Unknown type of connection: ");
    }
    // If this connection exists
    if (connectionToReconnect != null) {
        // if this is connected to something
        if (!connectionToReconnect.getConnectedConnections().isEmpty()) {
            // Save previous input connection source node to check whether if it's still depending on it after reconnect
            // should work like this, an input connection should have only one connected connection
            DependencyConnection previousFromConnection = (DependencyConnection) connectionToReconnect.getConnectedConnections().values().iterator().next();
            Node previousFromNode = findNode((previousFromConnection).getParentNode());
            connectionToReconnect.getConnectedConnections().clear();
            if (previousFromNode == null) {
                throw new RuntimeException("Node uri " + previousFromNode + " not found in renderGraph.");
            }
            // Sets data and change toNode's connectedConnection to fromConnection.
            // Sets previous fromConnection's connected node to null.
            connectionToReconnect.connectInputToOutput(fromConnection);
            if (!toNode.isDependentOn(previousFromNode) && disconnectPrevious) {
                disconnect(previousFromNode, toNode);
                // DISCONNECT in output connected connections
                previousFromConnection.getConnectedConnections().remove(connectionToReconnect.getName());
            }
        // setDependencies(this.context); - needed here? probably not..
        // either do this after everything is set up, or in renderGraph.addNode
        // and when calling these trough api, call resetDesiredStateChanges();
        } else {
            logger.info(toNode + "'s connection " + connectionToReconnect + " was not connected. Attempting new connection...");
            this.connectFbo(toNode, inputId, fromConnection);
        }
    } else {
        // TODO make it connectionToReconnect
        String connectionName;
        switch(connectionType) {
            case FBO:
                connectionName = FboConnection.getConnectionName(inputId, toNode.getUri());
                break;
            case BUFFER_PAIR:
                connectionName = BufferPairConnection.getConnectionName(inputId, toNode.getUri());
                break;
            default:
                connectionName = "[unsupported connection type]";
        }
        logger.info("No such input connection named " + connectionName + ". Attempting new connection...");
        switch(connectionType) {
            case FBO:
                this.connectFbo(toNode, inputId, fromConnection);
                break;
            case BUFFER_PAIR:
                this.connectBufferPair(toNode, inputId, fromConnection);
                break;
            default:
                logger.error("Unknown type of output connection: ");
                throw new RuntimeException("Unknown type of output connection: ");
        }
    }
    // TODO return errors...connectFbo-true false
    logger.debug("Reconnecting finished.");
}
Also used : DependencyConnection(org.terasology.engine.rendering.dag.dependencyConnections.DependencyConnection)

Example 18 with DependencyConnection

use of org.terasology.engine.rendering.dag.dependencyConnections.DependencyConnection in project Terasology by MovingBlocks.

the class RenderGraph method disconnectOutputFboConnection.

@Deprecated
public void disconnectOutputFboConnection(Node node, int connectionId) {
    logger.debug("Attempting disconnection of " + node + "'s output fbo number " + connectionId + "..");
    if (node != null) {
        DependencyConnection outputConnection = node.getOutputFboConnection(connectionId);
        if (outputConnection != null) {
            outputConnection.disconnect();
            logger.debug("..disconnecting complete.");
        } else {
            logger.warn("Could not find output Fbo connection number " + connectionId + "within " + node + ".");
        }
    } else {
        throw new RuntimeException("Could not find node named " + node + " within renderGraph.");
    }
// TODO disconnect from rendergraph if needed
}
Also used : DependencyConnection(org.terasology.engine.rendering.dag.dependencyConnections.DependencyConnection)

Aggregations

DependencyConnection (org.terasology.engine.rendering.dag.dependencyConnections.DependencyConnection)18 BufferPairConnection (org.terasology.engine.rendering.dag.dependencyConnections.BufferPairConnection)4 FboConnection (org.terasology.engine.rendering.dag.dependencyConnections.FboConnection)3 Nullable (javax.annotation.Nullable)2 SimpleUri (org.terasology.engine.core.SimpleUri)1 RunOrderConnection (org.terasology.engine.rendering.dag.dependencyConnections.RunOrderConnection)1