Skip to content

Commit 21bbdc4

Browse files
committed
Merge PR #2425 by @tdgunes - rendering work.
2 parents 182fa88 + bec343b commit 21bbdc4

File tree

9 files changed

+38
-78
lines changed

9 files changed

+38
-78
lines changed

engine/src/main/java/org/terasology/rendering/dag/StateChange.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* TODO: Add javadocs
2020
*/
2121
public interface StateChange {
22+
2223
StateChange getDefaultInstance();
2324

2425
RenderPipelineTask generateTask();

engine/src/main/java/org/terasology/rendering/dag/nodes/ShadowMapNode.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.terasology.rendering.dag.AbstractNode;
2929
import org.terasology.rendering.dag.stateChanges.BindFBO;
3030
import org.terasology.rendering.dag.stateChanges.SetViewportSizeOf;
31-
import org.terasology.rendering.opengl.FrameBuffersManager;
3231
import org.terasology.rendering.primitives.ChunkMesh;
3332
import org.terasology.rendering.world.RenderQueuesHelper;
3433
import org.terasology.rendering.world.RenderableWorld;
@@ -51,9 +50,6 @@ public class ShadowMapNode extends AbstractNode {
5150
private static final int SHADOW_FRUSTUM_BOUNDS = 500;
5251
public Camera shadowMapCamera = new OrthographicCamera(-SHADOW_FRUSTUM_BOUNDS, SHADOW_FRUSTUM_BOUNDS, SHADOW_FRUSTUM_BOUNDS, -SHADOW_FRUSTUM_BOUNDS);
5352

54-
@In
55-
private FrameBuffersManager frameBuffersManager;
56-
5753
@In
5854
private RenderableWorld renderableWorld;
5955

@@ -83,8 +79,8 @@ public void initialise() {
8379
this.renderingConfig = config.getRendering();
8480
renderableWorld.setShadowMapCamera(shadowMapCamera);
8581

86-
addDesiredStateChange(new BindFBO(SCENE_SHADOW_MAP, frameBuffersManager));
87-
addDesiredStateChange(new SetViewportSizeOf(SCENE_SHADOW_MAP, frameBuffersManager));
82+
addDesiredStateChange(new BindFBO(SCENE_SHADOW_MAP));
83+
addDesiredStateChange(new SetViewportSizeOf(SCENE_SHADOW_MAP));
8884
}
8985

9086
@Override

engine/src/main/java/org/terasology/rendering/dag/nodes/SimpleBlendMaterialsNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class SimpleBlendMaterialsNode extends AbstractNode {
4343

4444
@Override
4545
public void initialise() {
46-
addDesiredStateChange(new BindFBO(SCENE_OPAQUE_FBO, frameBuffersManager));
46+
addDesiredStateChange(new BindFBO(SCENE_OPAQUE_FBO));
4747
// TODO: review - might be redundant to setRenderBufferMask(sceneOpaque) again at the end of the process() method
4848
}
4949

engine/src/main/java/org/terasology/rendering/dag/nodes/WorldReflectionNode.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.terasology.rendering.dag.AbstractNode;
2828
import org.terasology.rendering.dag.stateChanges.BindFBO;
2929
import org.terasology.rendering.dag.stateChanges.SetViewportSizeOf;
30-
import org.terasology.rendering.opengl.FrameBuffersManager;
3130
import org.terasology.rendering.primitives.ChunkMesh;
3231
import org.terasology.rendering.world.RenderQueuesHelper;
3332
import org.terasology.rendering.world.WorldRenderer;
@@ -44,9 +43,6 @@
4443
public class WorldReflectionNode extends AbstractNode {
4544
private static final String SCENE_REFLECTED_FBO = "sceneReflected";
4645

47-
@In
48-
private FrameBuffersManager frameBuffersManager;
49-
5046
@In
5147
private RenderQueuesHelper renderQueues;
5248

@@ -69,9 +65,8 @@ public void initialise() {
6965
this.renderingConfig = config.getRendering();
7066
this.chunkShader = worldRenderer.getMaterial("engine:prog.chunk");
7167
this.playerCamera = worldRenderer.getActiveCamera();
72-
addDesiredStateChange(new BindFBO(SCENE_REFLECTED_FBO, frameBuffersManager));
73-
addDesiredStateChange(new SetViewportSizeOf(SCENE_REFLECTED_FBO, frameBuffersManager));
74-
68+
addDesiredStateChange(new BindFBO(SCENE_REFLECTED_FBO));
69+
addDesiredStateChange(new SetViewportSizeOf(SCENE_REFLECTED_FBO));
7570
}
7671

7772
@Override

engine/src/main/java/org/terasology/rendering/dag/stateChanges/BindFBO.java

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,28 @@ public final class BindFBO implements FBOManagerSubscriber, StateChange {
2828
private static final Integer DEFAULT_FRAME_BUFFER_ID = 0;
2929
// TODO: add necessary checks for ensuring generating FBO with the name "display" is not possible.
3030
private static final String DEFAULT_FRAME_BUFFER_NAME = "display";
31-
private static BindFBO defaultInstance = new BindFBO();
31+
private static FrameBuffersManager frameBuffersManager;
32+
private static BindFBO defaultInstance = new BindFBO(DEFAULT_FRAME_BUFFER_NAME);
3233
private String fboName;
33-
private FrameBuffersManager frameBuffersManager;
34-
private int fboId;
3534
private BindFBOTask task;
3635

37-
public BindFBO(String fboName, FrameBuffersManager frameBuffersManager) {
36+
public BindFBO(String fboName) {
3837
this.fboName = fboName;
39-
this.frameBuffersManager = frameBuffersManager;
40-
fboId = frameBuffersManager.getFBO(fboName).fboId;
4138
}
4239

43-
public BindFBO() {
44-
this.fboName = DEFAULT_FRAME_BUFFER_NAME;
45-
fboId = DEFAULT_FRAME_BUFFER_ID;
40+
public String getFboName() {
41+
return fboName;
42+
}
43+
44+
public static void setFrameBuffersManager(FrameBuffersManager frameBuffersManager) {
45+
BindFBO.frameBuffersManager = frameBuffersManager;
4646
}
4747

4848
@Override
4949
public StateChange getDefaultInstance() {
5050
return defaultInstance;
5151
}
5252

53-
54-
public static void setDefaultInstance(BindFBO defaultInstance) {
55-
BindFBO.defaultInstance = defaultInstance;
56-
}
57-
5853
@Override
5954
public boolean isTheDefaultInstance() {
6055
return this == defaultInstance;
@@ -63,13 +58,15 @@ public boolean isTheDefaultInstance() {
6358
@Override
6459
public RenderPipelineTask generateTask() {
6560
if (task == null) {
66-
task = new BindFBOTask(fboId, fboName);
6761
// Subscription is only needed if fboID is different than default frame buffer id.
68-
if (fboId != DEFAULT_FRAME_BUFFER_ID) {
62+
if (!fboName.equals(DEFAULT_FRAME_BUFFER_NAME)) {
63+
task = new BindFBOTask(frameBuffersManager.getFBO(fboName).fboId, fboName);
6964
frameBuffersManager.subscribe(this);
65+
} else {
66+
task = new BindFBOTask(DEFAULT_FRAME_BUFFER_ID, DEFAULT_FRAME_BUFFER_NAME);
7067
}
7168
} else {
72-
if (fboId != DEFAULT_FRAME_BUFFER_ID) {
69+
if (!fboName.equals(DEFAULT_FRAME_BUFFER_NAME)) {
7370
update();
7471
}
7572
}
@@ -86,16 +83,11 @@ public boolean isEqualTo(StateChange stateChange) {
8683

8784
@Override
8885
public void update() {
89-
fboId = frameBuffersManager.getFBO(fboName).fboId;
90-
task.setFboId(fboId);
86+
task.setFboId(frameBuffersManager.getFBO(fboName).fboId);
9187
}
9288

9389
@Override
9490
public String toString() { // TODO: used for logging purposes at the moment, investigate different methods
95-
return String.format("%21s: %s(%s)", this.getClass().getSimpleName(), fboName, fboId);
96-
}
97-
98-
public String getFboName() {
99-
return fboName;
91+
return String.format("%21s: %s", this.getClass().getSimpleName(), fboName);
10092
}
10193
}

engine/src/main/java/org/terasology/rendering/dag/stateChanges/SetViewportSizeOf.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,38 +27,30 @@
2727
*/
2828
public final class SetViewportSizeOf implements FBOManagerSubscriber, StateChange {
2929
private static final String DEFAULT_FBO = "sceneOpaque";
30-
private static SetViewportSizeOf defaultInstance;
30+
private static SetViewportSizeOf defaultInstance = new SetViewportSizeOf(DEFAULT_FBO);
31+
private static FrameBuffersManager frameBuffersManager;
3132
private SetViewportSizeOfTask task;
3233

33-
private FBO fbo;
3434
private String fboName;
35-
private FrameBuffersManager frameBuffersManager;
3635

37-
public SetViewportSizeOf(String fboName, FrameBuffersManager frameBuffersManager) {
36+
public SetViewportSizeOf(String fboName) {
3837
this.fboName = fboName;
39-
this.frameBuffersManager = frameBuffersManager;
40-
fbo = frameBuffersManager.getFBO(fboName);
4138
}
4239

43-
public SetViewportSizeOf(FrameBuffersManager frameBuffersManager) {
44-
this(DEFAULT_FBO, frameBuffersManager);
40+
public static void setFrameBuffersManager(FrameBuffersManager frameBuffersManager) {
41+
SetViewportSizeOf.frameBuffersManager = frameBuffersManager;
4542
}
4643

4744
@Override
4845
public StateChange getDefaultInstance() {
4946
return defaultInstance;
5047
}
5148

52-
public static void setDefaultInstance(SetViewportSizeOf defaultInstance) {
53-
SetViewportSizeOf.defaultInstance = defaultInstance;
54-
}
55-
5649
@Override
5750
public RenderPipelineTask generateTask() {
5851
if (task == null) {
59-
task = new SetViewportSizeOfTask(fboName, fbo.width(), fbo.height());
52+
task = new SetViewportSizeOfTask(fboName);
6053
frameBuffersManager.subscribe(this);
61-
} else {
6254
update();
6355
}
6456

@@ -80,13 +72,13 @@ public boolean isTheDefaultInstance() {
8072

8173
@Override
8274
public void update() {
83-
fbo = frameBuffersManager.getFBO(fboName);
75+
FBO fbo = frameBuffersManager.getFBO(fboName);
8476
task.setDimensions(fbo.width(), fbo.height());
8577
}
8678

8779
@Override
8880
public String toString() { // TODO: used for logging purposes at the moment, investigate different methods
89-
return String.format("%21s: %s(%sx%s)", this.getClass().getSimpleName(), fboName, fbo.width(), fbo.height());
81+
return String.format("%21s: %s", this.getClass().getSimpleName(), fboName);
9082
}
9183

9284
public String getFboName() {

engine/src/main/java/org/terasology/rendering/dag/stateChanges/SetWireframe.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
* TODO: Add javadocs
2424
*/
2525
public final class SetWireframe implements StateChange {
26-
private static final boolean DEFAULT_VALUE = false;
27-
28-
private static SetWireframe defaultInstance;
26+
private static SetWireframe defaultInstance = new SetWireframe(false);
2927
private static SetWireframeTask enablingTask;
3028
private static SetWireframeTask disablingTask;
3129

@@ -35,21 +33,11 @@ public SetWireframe(boolean enabled) {
3533
this.enabled = enabled;
3634
}
3735

38-
public SetWireframe() {
39-
this(DEFAULT_VALUE);
40-
}
41-
42-
4336
@Override
4437
public StateChange getDefaultInstance() {
4538
return defaultInstance;
4639
}
4740

48-
49-
public static void setDefaultInstance(SetWireframe defaultInstance) {
50-
SetWireframe.defaultInstance = defaultInstance;
51-
}
52-
5341
@Override
5442
public RenderPipelineTask generateTask() {
5543
if (enabled) {

engine/src/main/java/org/terasology/rendering/dag/tasks/SetViewportSizeOfTask.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@
2121
/**
2222
* TODO: Add javadocs
2323
*/
24-
public class SetViewportSizeOfTask implements RenderPipelineTask {
24+
public final class SetViewportSizeOfTask implements RenderPipelineTask {
2525
private int width;
2626
private int height;
2727
private String fboName;
2828

29-
public SetViewportSizeOfTask(String fboName, int width, int height) {
29+
public SetViewportSizeOfTask(String fboName) {
3030
this.fboName = fboName;
31-
this.width = width;
32-
this.height = height;
3331
}
3432

3533
public void setDimensions(int w, int h) {

engine/src/main/java/org/terasology/rendering/world/WorldRendererImpl.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
import org.terasology.rendering.dag.nodes.WorldReflectionNode;
6666
import org.terasology.rendering.dag.stateChanges.BindFBO;
6767
import org.terasology.rendering.dag.stateChanges.SetViewportSizeOf;
68-
import org.terasology.rendering.dag.stateChanges.SetWireframe;
6968
import org.terasology.rendering.logic.LightComponent;
7069
import org.terasology.rendering.opengl.FrameBuffersManager;
7170
import org.terasology.rendering.opengl.PostProcessor;
@@ -202,6 +201,8 @@ private void initMaterials() {
202201

203202
private void initRenderGraph() {
204203
// FIXME: init pipeline without specifying them as a field in this class
204+
initStateChanges();
205+
205206
NodeFactory nodeFactory = new NodeFactory(context);
206207
shadowMapNode = nodeFactory.createInstance(ShadowMapNode.class);
207208
Node worldReflectionNode = nodeFactory.createInstance(WorldReflectionNode.class);
@@ -253,18 +254,15 @@ private void initRenderGraph() {
253254
renderGraph.addNode(blurPassesNode, "blurPassesNode");
254255
renderGraph.addNode(finalPostProcessingNode, "finalPostProcessingNode");
255256

256-
initDefaultStateChanges();
257-
258257
RenderTaskListGenerator renderTaskListGenerator = new RenderTaskListGenerator();
259258
List<Node> orderedNodes = renderGraph.getNodesInTopologicalOrder();
260259

261260
renderPipelineTaskList = renderTaskListGenerator.generateFrom(orderedNodes);
262261
}
263262

264-
private void initDefaultStateChanges() {
265-
SetViewportSizeOf.setDefaultInstance(new SetViewportSizeOf(frameBuffersManager));
266-
BindFBO.setDefaultInstance(new BindFBO());
267-
SetWireframe.setDefaultInstance(new SetWireframe());
263+
private void initStateChanges() {
264+
SetViewportSizeOf.setFrameBuffersManager(frameBuffersManager);
265+
BindFBO.setFrameBuffersManager(frameBuffersManager);
268266
}
269267

270268
@Override

0 commit comments

Comments
 (0)