Skip to content

Commit

Permalink
Merge PR #3058 by @vampcat - rendering work
Browse files Browse the repository at this point in the history
  • Loading branch information
Cervator committed Aug 24, 2017
2 parents 5c5d877 + e32a352 commit 44088b5
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 55 deletions.
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) {
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:
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);
}

@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

0 comments on commit 44088b5

Please sign in to comment.