Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug Node (New) #3058

Merged
merged 9 commits into from
Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -294,5 +294,4 @@ public int compare(RenderableChunk o1, RenderableChunk o2) {
return distance2 > distance ? -1 : 1;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
public abstract class AbstractNode implements Node {
protected static final Logger logger = LoggerFactory.getLogger(AbstractNode.class);

private SimpleUri nodeUri;

private Set<StateChange> desiredStateChanges = Sets.newLinkedHashSet();
private Map<SimpleUri, BaseFBOsManager> fboUsages = Maps.newHashMap();
private boolean enabled = true;
Expand Down Expand Up @@ -95,6 +97,19 @@ public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

@Override
public void setUri(SimpleUri nodeUri) {
this.nodeUri = nodeUri;
}

@Override
public SimpleUri getUri() {
return nodeUri;
}

@Override
public void handleCommand(String command, String... arguments) { }

/**
* Utility method to conveniently retrieve materials from the Assets system,
* hiding the relative complexity of the exception handling.
Expand Down
8 changes: 8 additions & 0 deletions engine/src/main/java/org/terasology/rendering/dag/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

//TODO: consider removing the word "Node" from the name of all Node implementations now that they are in the dag.nodes package.

import org.terasology.engine.SimpleUri;

import java.util.Set;

/**
Expand All @@ -31,4 +33,10 @@ public interface Node extends RenderPipelineTask {
boolean isEnabled();

void setEnabled(boolean enabled);

void setUri(SimpleUri nodeUri);

SimpleUri getUri();

void handleCommand(String command, String... arguments);
}
21 changes: 19 additions & 2 deletions engine/src/main/java/org/terasology/rendering/dag/RenderGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package org.terasology.rendering.dag;

import com.google.common.collect.Lists;
import org.terasology.engine.SimpleUri;

import java.util.List;

/**
Expand All @@ -28,9 +30,24 @@ public RenderGraph() {
nodes = Lists.newArrayList();
}

public String addNode(Node node, String suggestedId) {
public SimpleUri addNode(Node node, String suggestedUri) {
nodes.add(node);
return suggestedId; // TODO: for instance if "blur" present make id "blur1" and return it

// TODO: make sure URIs are actually unique: if "myModule:blur" is present the node gets the uri "myModule:blur2" instead.
// TODO: make sure the namespace in the uri is engine-assigned, so that only engine nodes can have the "engine:" namespace - everything else gets the namespace of the module.
SimpleUri nodeUri = new SimpleUri("engine:" + suggestedUri);
node.setUri(nodeUri);
return nodeUri;
}

public Node findNode(SimpleUri nodeUri) {
for (Node node: nodes) {
if (node.getUri().equals(nodeUri)) {
return node;
}
}

return null;
}

// TODO: add remove, get, addEdge, removeEdge methods here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import static org.terasology.rendering.opengl.ScalingFactors.FULL_SCALE;
import static org.terasology.rendering.opengl.fbms.DisplayResolutionDependentFBOs.FINAL_BUFFER;

public class CopyImageToHMDNode extends ConditionDependentNode {
public class OutputToHMDNode extends ConditionDependentNode {
private static final SimpleUri LEFT_EYE_FBO_URI = new SimpleUri("engine:fbo.leftEye");
private static final SimpleUri RIGHT_EYE_FBO_URI = new SimpleUri("engine:fbo.rightEye");
private static final ResourceUrn DEFAULT_TEXTURED_MATERIAL_URN = new ResourceUrn("engine:prog.defaultTextured");
Expand All @@ -57,7 +57,7 @@ public class CopyImageToHMDNode extends ConditionDependentNode {
* Constructs an instance of this node. Specifically, initialize the vrProvider and pass the frame buffer
* information for the vrProvider to use.
*/
public CopyImageToHMDNode(Context context) {
public OutputToHMDNode(Context context) {
super(context);

vrProvider = context.get(OpenVRProvider.class);
Expand Down Expand Up @@ -89,7 +89,7 @@ public CopyImageToHMDNode(Context context) {
*/
@Override
public void process() {
PerformanceMonitor.startActivity("rendering/copyImageToHMD");
PerformanceMonitor.startActivity("rendering/outputToHMD");
finalFbo.bindTexture();
renderFinalStereoImage(worldRenderer.getCurrentRenderStage());
PerformanceMonitor.endActivity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
import org.lwjgl.opengl.Display;
import org.terasology.assets.ResourceUrn;
import org.terasology.context.Context;
import org.terasology.engine.SimpleUri;
import org.terasology.monitoring.PerformanceMonitor;
import org.terasology.rendering.dag.ConditionDependentNode;
import org.terasology.rendering.dag.StateChange;
import org.terasology.rendering.dag.stateChanges.EnableMaterial;
import org.terasology.rendering.dag.stateChanges.SetInputTextureFromFbo;
import org.terasology.rendering.opengl.FBO;
import org.terasology.rendering.opengl.FBOManagerSubscriber;
import org.terasology.rendering.opengl.SwappableFBO;
import org.terasology.rendering.opengl.fbms.DisplayResolutionDependentFBOs;
import org.terasology.rendering.world.WorldRenderer;

Expand All @@ -34,29 +36,85 @@
import static org.terasology.rendering.world.WorldRenderer.RenderingStage.LEFT_EYE;
import static org.terasology.rendering.world.WorldRenderer.RenderingStage.MONO;

public class CopyImageToScreenNode extends ConditionDependentNode {
public class OutputToScreenNode extends ConditionDependentNode {
private static final ResourceUrn DEFAULT_TEXTURED_MATERIAL_URN = new ResourceUrn("engine:prog.defaultTextured");

public CopyImageToScreenNode(Context context) {
private DisplayResolutionDependentFBOs displayResolutionDependentFBOs;
private WorldRenderer worldRenderer;

private FBO lastUpdatedGBuffer;
private FBO staleGBuffer;

private StateChange bindFbo;

public OutputToScreenNode(Context context) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to rename PerformanceMonitor line 75:

PerformanceMonitor.startActivity("rendering/copyImageToScreen");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted, I'll take care of this in the next commit!

super(context);

displayResolutionDependentFBOs = context.get(DisplayResolutionDependentFBOs.class);
worldRenderer = context.get(WorldRenderer.class);

WorldRenderer worldRenderer = context.get(WorldRenderer.class);
requiresCondition(() -> worldRenderer.getCurrentRenderStage() == MONO || worldRenderer.getCurrentRenderStage() == LEFT_EYE);

addDesiredStateChange(new EnableMaterial(DEFAULT_TEXTURED_MATERIAL_URN));

addDesiredStateChange(new SetInputTextureFromFbo(0, FINAL_BUFFER, ColorTexture,
context.get(DisplayResolutionDependentFBOs.class), DEFAULT_TEXTURED_MATERIAL_URN, "texture"));
bindFbo = new SetInputTextureFromFbo(0, FINAL_BUFFER, ColorTexture, displayResolutionDependentFBOs, DEFAULT_TEXTURED_MATERIAL_URN, "texture");
addDesiredStateChange(bindFbo);

SwappableFBO gBufferPair = displayResolutionDependentFBOs.getGBufferPair();
lastUpdatedGBuffer = gBufferPair.getLastUpdatedFbo();
staleGBuffer = gBufferPair.getStaleFbo();
}

@Override
public void process() {
PerformanceMonitor.startActivity("rendering/copyImageToScreen");
PerformanceMonitor.startActivity("rendering/outputToScreen");
// The way things are set-up right now, we can have FBOs that are not the same size as the display (if scale != 100%).
// However, when drawing the final image to the screen, we always want the viewport to match the size of display,
// and not that of some FBO. Hence, we are manually setting the viewport via glViewport over here.
glViewport(0, 0, Display.getWidth(), Display.getHeight());
renderFullscreenQuad();
PerformanceMonitor.endActivity();
}

@Override
public void handleCommand(String command, String... arguments) {
switch (command) {
case "setFbo":
if (arguments.length != 1) {
throw new RuntimeException("Invalid number of arguments; expected 1, received " + arguments.length + "!");
}

FBO fbo;
switch (arguments[0]) {
case "engine:fbo.gBuffer":
case "engine:fbo.lastUpdatedGBuffer":
fbo = lastUpdatedGBuffer;
break;
case "engine:fbo.staleGBuffer":
fbo = staleGBuffer;
break;
default:
fbo = displayResolutionDependentFBOs.get(new SimpleUri(arguments[0]));

if (fbo == null) {
throw new RuntimeException(("No FBO is associated with URI '" + arguments[0] + "'"));
}

break;
}
setFbo(fbo);

break;
default:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's be more specific the line below. Let's write:

throw new RuntimeException("Unrecognized command: '" + command + "'");

And please notice the apostrophes between quotes...

throw new RuntimeException("Unrecognized command: '" + command + "'");
}
}

private void setFbo(FBO fbo) {
removeDesiredStateChange(bindFbo);
bindFbo = new SetInputTextureFromFbo(0, fbo, ColorTexture, displayResolutionDependentFBOs, DEFAULT_TEXTURED_MATERIAL_URN, "texture");
addDesiredStateChange(bindFbo);
worldRenderer.requestTaskListRefresh();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
* TODO: Better naming
*/
public class DisplayResolutionDependentFBOs extends AbstractFBOsManager {
public static final SimpleUri READONLY_GBUFFER = new SimpleUri("engine:fbo.readOnlyGBuffer");
public static final SimpleUri WRITEONLY_GBUFFER = new SimpleUri("engine:fbo.writeOnlyGBuffer");
public static final SimpleUri FINAL_BUFFER = new SimpleUri("engine:fbo.finalBuffer");

private SwappableFBO gBufferPair;
Expand All @@ -50,13 +48,13 @@ public DisplayResolutionDependentFBOs(RenderingConfig renderingConfig, ScreenGra
}

private void generateDefaultFBOs() {
FBO readOnlyGBuffer = generateWithDimensions(new FBOConfig(READONLY_GBUFFER, FULL_SCALE, FBO.Type.HDR)
FBO gBuffer1 = generateWithDimensions(new FBOConfig(new SimpleUri("engine:fbo.gBuffer1"), FULL_SCALE, FBO.Type.HDR)
.useDepthBuffer().useNormalBuffer().useLightBuffer().useStencilBuffer(), fullScale);
FBO writeOnlyGBuffer = generateWithDimensions(new FBOConfig(WRITEONLY_GBUFFER, FULL_SCALE, FBO.Type.HDR)
FBO gBuffer2 = generateWithDimensions(new FBOConfig(new SimpleUri("engine:fbo.gBuffer2"), FULL_SCALE, FBO.Type.HDR)
.useDepthBuffer().useNormalBuffer().useLightBuffer().useStencilBuffer(), fullScale);
generateWithDimensions(new FBOConfig(FINAL_BUFFER, FULL_SCALE, FBO.Type.DEFAULT), fullScale);

gBufferPair = new SwappableFBO(readOnlyGBuffer, writeOnlyGBuffer);
gBufferPair = new SwappableFBO(gBuffer1, gBuffer2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't these be named right away staleGBuffer and lastUpdatedGBuffer? Both in terms of variables and URIs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was discussed via slack and the new naming is correct, as at this stage there is no stale nor lastUpdated FBO: both haven't been touched yet.

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.terasology.rendering.world;

import org.terasology.entitySystem.systems.ComponentSystem;
import org.terasology.math.geom.Vector3f;
import org.terasology.math.geom.Vector3i;
import org.terasology.rendering.assets.material.Material;
Expand Down
Loading