Skip to content

Commit e76799e

Browse files
committed
feat: starteded working on deferred pipeline
Signed-off-by: Michael Pollind <[email protected]>
1 parent af5fa40 commit e76799e

File tree

12 files changed

+419
-387
lines changed

12 files changed

+419
-387
lines changed

engine/src/main/java/org/terasology/engine/core/modes/loadProcesses/InitialiseWorld.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.terasology.engine.rendering.backdrop.BackdropProvider;
3232
import org.terasology.engine.rendering.backdrop.Skysphere;
3333
import org.terasology.engine.rendering.cameras.Camera;
34+
import org.terasology.engine.rendering.world.DeferredRenderer;
3435
import org.terasology.engine.rendering.world.WorldRenderer;
3536
import org.terasology.engine.utilities.random.FastRandom;
3637
import org.terasology.engine.world.BlockEntityRegistry;
@@ -159,8 +160,7 @@ public boolean step() {
159160
BackdropProvider backdropProvider = skysphere;
160161
context.put(BackdropProvider.class, backdropProvider);
161162

162-
RenderingSubsystemFactory engineSubsystemFactory = context.get(RenderingSubsystemFactory.class);
163-
WorldRenderer worldRenderer = engineSubsystemFactory.createWorldRenderer(context);
163+
WorldRenderer worldRenderer = new DeferredRenderer(context);
164164
context.put(WorldRenderer.class, worldRenderer);
165165

166166
// TODO: These shouldn't be done here, nor so strongly tied to the world renderer

engine/src/main/java/org/terasology/engine/core/subsystem/lwjgl/LwjglDisplayDevice.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public boolean isHeadless() {
178178

179179
@Override
180180
public void prepareToRender() {
181-
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
181+
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
182182
}
183183

184184
@Override

engine/src/main/java/org/terasology/engine/core/subsystem/lwjgl/LwjglGraphicsManager.java

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,18 @@
44

55
import com.google.common.collect.Lists;
66
import com.google.common.collect.Queues;
7-
import org.lwjgl.opengl.GL11;
8-
import org.lwjgl.opengl.GL12;
97
import org.terasology.engine.context.Context;
108
import org.terasology.engine.core.GameThread;
119
import org.terasology.engine.core.subsystem.DisplayDeviceInfo;
1210
import org.terasology.engine.core.subsystem.RenderingSubsystemFactory;
13-
import org.terasology.engine.rendering.assets.animation.MeshAnimation;
14-
import org.terasology.engine.rendering.assets.animation.MeshAnimationBundle;
15-
import org.terasology.engine.rendering.assets.animation.MeshAnimationImpl;
16-
import org.terasology.engine.rendering.assets.atlas.Atlas;
17-
import org.terasology.engine.rendering.assets.font.Font;
18-
import org.terasology.engine.rendering.assets.font.FontImpl;
19-
import org.terasology.engine.rendering.assets.material.Material;
20-
import org.terasology.engine.rendering.assets.mesh.Mesh;
21-
import org.terasology.engine.rendering.assets.shader.Shader;
22-
import org.terasology.engine.rendering.assets.skeletalmesh.SkeletalMesh;
23-
import org.terasology.engine.rendering.assets.texture.PNGTextureFormat;
2411
import org.terasology.engine.rendering.assets.texture.Texture;
25-
import org.terasology.engine.rendering.assets.texture.TextureData;
26-
import org.terasology.engine.rendering.assets.texture.subtexture.Subtexture;
27-
import org.terasology.engine.rendering.opengl.GLSLMaterial;
28-
import org.terasology.engine.rendering.opengl.GLSLShader;
29-
import org.terasology.engine.rendering.opengl.OpenGLMesh;
30-
import org.terasology.engine.rendering.opengl.OpenGLSkeletalMesh;
31-
import org.terasology.engine.rendering.opengl.OpenGLTexture;
32-
import org.terasology.engine.rendering.opengl.WgpuTexture;
33-
import org.terasology.gestalt.assets.AssetType;
34-
import org.terasology.gestalt.assets.module.ModuleAssetScanner;
35-
import org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager;
3612

3713
import java.nio.ByteBuffer;
3814
import java.util.List;
3915
import java.util.concurrent.BlockingDeque;
4016
import java.util.function.Consumer;
4117

42-
import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
43-
import static org.lwjgl.opengl.GL11.GL_TEXTURE_WRAP_S;
44-
import static org.lwjgl.opengl.GL11.GL_TEXTURE_WRAP_T;
45-
import static org.lwjgl.opengl.GL11.glBindTexture;
4618
import static org.lwjgl.opengl.GL11.glDeleteTextures;
47-
import static org.lwjgl.opengl.GL11.glGenTextures;
48-
import static org.lwjgl.opengl.GL11.glTexParameterf;
4919

5020
public class LwjglGraphicsManager implements LwjglGraphicsProcessing {
5121

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public abstract class ModuleRendering {
2626
protected Context context;
2727
protected ModuleManager moduleManager;
2828
protected Name providingModule;
29-
protected RenderGraph renderGraph;
29+
// protected RenderGraph renderGraph;
3030
protected WorldRenderer worldRenderer;
3131
protected Boolean isEnabled = true;
3232

@@ -61,7 +61,7 @@ public void toggleEnabled() {
6161
}
6262

6363
public void initialise() {
64-
renderGraph = context.get(RenderGraph.class);
64+
// renderGraph = context.get(RenderGraph.class);
6565
worldRenderer = context.get(WorldRenderer.class);
6666
}
6767

engine/src/main/java/org/terasology/engine/rendering/opengl/GLSLMaterial.java

Lines changed: 53 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
import org.joml.Matrix3fc;
1616
import org.joml.Matrix4fc;
1717
import org.lwjgl.BufferUtils;
18-
import org.lwjgl.opengl.GL13;
19-
import org.lwjgl.opengl.GL20;
2018
import org.slf4j.Logger;
2119
import org.slf4j.LoggerFactory;
2220
import org.terasology.engine.core.GameThread;
@@ -37,7 +35,6 @@
3735
import java.util.Collections;
3836
import java.util.EnumSet;
3937
import java.util.Map;
40-
import java.util.Set;
4138

4239
public class GLSLMaterial extends BaseMaterial {
4340

@@ -50,7 +47,6 @@ public class GLSLMaterial extends BaseMaterial {
5047
private TIntObjectMap<Texture> textureMap = new TIntObjectHashMap<>();
5148

5249
private GLSLShader shader;
53-
private boolean activeFeaturesChanged;
5450
private TObjectIntMap<UniformId> uniformLocationMap = new TObjectIntHashMap<>();
5551

5652
private EnumSet<ShaderProgramFeature> activeFeatures = Sets.newEnumSet(Collections.emptyList(), ShaderProgramFeature.class);
@@ -83,14 +79,14 @@ public static GLSLMaterial create(ResourceUrn urn, LwjglGraphicsProcessing graph
8379

8480
@Override
8581
public void enable() {
86-
if (shaderManager.getActiveMaterial() != this || activeFeaturesChanged) {
87-
GL13.glActiveTexture(GL13.GL_TEXTURE0);
88-
GL20.glUseProgram(getActiveShaderProgramId());
89-
90-
// Make sure the shader manager knows that this program is currently active
91-
shaderManager.setActiveMaterial(this);
92-
activeFeaturesChanged = false;
93-
}
82+
// if (shaderManager.getActiveMaterial() != this || activeFeaturesChanged) {
83+
// GL13.glActiveTexture(GL13.GL_TEXTURE0);
84+
// GL20.glUseProgram(getActiveShaderProgramId());
85+
//
86+
// // Make sure the shader manager knows that this program is currently active
87+
// shaderManager.setActiveMaterial(this);
88+
// activeFeaturesChanged = false;
89+
// }
9490
}
9591

9692
@Override
@@ -123,25 +119,25 @@ public boolean isRenderable() {
123119

124120
@Override
125121
public void recompile() {
126-
TIntIntIterator it = disposalAction.shaderPrograms.iterator();
127-
while (it.hasNext()) {
128-
it.advance();
129-
GL20.glDeleteProgram(it.value());
130-
}
131-
disposalAction.shaderPrograms.clear();
132-
uniformLocationMap.clear();
133-
bindMap.clear();
134-
135-
disposalAction.shaderPrograms.put(0, shader.linkShaderProgram(0));
136-
for (Set<ShaderProgramFeature> permutation : Sets.powerSet(shader.getAvailableFeatures())) {
137-
int featureMask = ShaderProgramFeature.getBitset(permutation);
138-
disposalAction.shaderPrograms.put(featureMask, shader.linkShaderProgram(featureMask));
139-
}
140-
141-
//resolves #966
142-
//Some of the uniforms are not updated constantly between frames
143-
//this function will rebind any uniforms that are not bound
144-
rebindVariables(materialData);
122+
// TIntIntIterator it = disposalAction.shaderPrograms.iterator();
123+
// while (it.hasNext()) {
124+
// it.advance();
125+
// GL20.glDeleteProgram(it.value());
126+
// }
127+
// disposalAction.shaderPrograms.clear();
128+
// uniformLocationMap.clear();
129+
// bindMap.clear();
130+
//
131+
// disposalAction.shaderPrograms.put(0, shader.linkShaderProgram(0));
132+
// for (Set<ShaderProgramFeature> permutation : Sets.powerSet(shader.getAvailableFeatures())) {
133+
// int featureMask = ShaderProgramFeature.getBitset(permutation);
134+
// disposalAction.shaderPrograms.put(featureMask, shader.linkShaderProgram(featureMask));
135+
// }
136+
//
137+
// //resolves #966
138+
// //Some of the uniforms are not updated constantly between frames
139+
// //this function will rebind any uniforms that are not bound
140+
// rebindVariables(materialData);
145141
}
146142

147143
@Override
@@ -226,7 +222,7 @@ public void activateFeature(ShaderProgramFeature feature) {
226222
if (shader.getAvailableFeatures().contains(feature)) {
227223
activeFeatures.add(feature);
228224
activeFeaturesMask = ShaderProgramFeature.getBitset(activeFeatures);
229-
activeFeaturesChanged = true;
225+
// activeFeaturesChanged = true;
230226
} else {
231227
logger.error("Attempt to activate unsupported feature {} for material {} using shader {}", feature, getUrn(), shader.getUrn());
232228
}
@@ -236,7 +232,7 @@ public void activateFeature(ShaderProgramFeature feature) {
236232
public void deactivateFeature(ShaderProgramFeature feature) {
237233
if (activeFeatures.remove(feature)) {
238234
activeFeaturesMask = ShaderProgramFeature.getBitset(activeFeatures);
239-
activeFeaturesChanged = true;
235+
// activeFeaturesChanged = true;
240236
}
241237
}
242238

@@ -275,25 +271,25 @@ public void setFloat(String desc, float f, boolean currentOnly) {
275271

276272
@Override
277273
public void setFloat1(String desc, FloatBuffer buffer, boolean currentOnly) {
278-
if (isDisposed()) {
279-
return;
280-
}
281-
if (currentOnly) {
282-
enable();
283-
int id = getUniformLocation(getActiveShaderProgramId(), desc);
284-
GL20.glUniform1fv(id, buffer);
285-
} else {
286-
TIntIntIterator it = disposalAction.shaderPrograms.iterator();
287-
while (it.hasNext()) {
288-
it.advance();
289-
290-
GL20.glUseProgram(it.value());
291-
int id = getUniformLocation(it.value(), desc);
292-
GL20.glUniform1fv(id, buffer);
293-
}
294-
295-
restoreStateAfterUniformsSet();
296-
}
274+
// if (isDisposed()) {
275+
// return;
276+
// }
277+
// if (currentOnly) {
278+
// enable();
279+
// int id = getUniformLocation(getActiveShaderProgramId(), desc);
280+
// GL20.glUniform1fv(id, buffer);
281+
// } else {
282+
// TIntIntIterator it = disposalAction.shaderPrograms.iterator();
283+
// while (it.hasNext()) {
284+
// it.advance();
285+
//
286+
// GL20.glUseProgram(it.value());
287+
// int id = getUniformLocation(it.value(), desc);
288+
// GL20.glUniform1fv(id, buffer);
289+
// }
290+
//
291+
// restoreStateAfterUniformsSet();
292+
// }
297293
}
298294

299295
@Override
@@ -581,25 +577,12 @@ private int getActiveShaderProgramId() {
581577
return disposalAction.shaderPrograms.get(activeFeaturesMask);
582578
}
583579

584-
private int getUniformLocation(int activeShaderProgramId, String desc) {
585-
UniformId id = new UniformId(activeShaderProgramId, desc);
586-
587-
if (uniformLocationMap.containsKey(id)) {
588-
return uniformLocationMap.get(id);
589-
}
590-
591-
int loc = GL20.glGetUniformLocation(activeShaderProgramId, desc);
592-
uniformLocationMap.put(id, loc);
593-
594-
return loc;
595-
}
596-
597580
private void restoreStateAfterUniformsSet() {
598-
if (shaderManager.getActiveMaterial() == this) {
599-
GL20.glUseProgram(getActiveShaderProgramId());
600-
} else {
601-
enable();
602-
}
581+
// if (shaderManager.getActiveMaterial() == this) {
582+
// GL20.glUseProgram(getActiveShaderProgramId());
583+
// } else {
584+
// enable();
585+
// }
603586
}
604587

605588
private static final class UniformId {

engine/src/main/java/org/terasology/engine/rendering/opengl/GLSLShader.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,25 +116,9 @@ Set<ShaderProgramFeature> getAvailableFeatures() {
116116
return availableFeatures;
117117
}
118118

119-
// made package-private after CheckStyle suggestion
120-
int linkShaderProgram(int featureHash) {
121-
// int shaderProgram = GL20.glCreateProgram();
122-
//
123-
// GL20.glAttachShader(shaderProgram, disposalAction.fragmentPrograms.get(featureHash));
124-
// GL20.glAttachShader(shaderProgram, disposalAction.vertexPrograms.get(featureHash));
125-
// if (shaderProgramBase.getGeometryProgram() != null) {
126-
// GL20.glAttachShader(shaderProgram, disposalAction.geometryPrograms.get(featureHash));
127-
// }
128-
// GL20.glLinkProgram(shaderProgram);
129-
// GL20.glValidateProgram(shaderProgram);
130-
return 0;
131-
}
132119

133120
@Override
134121
public void recompile() {
135-
graphicsProcessing.asynchToDisplayThread(() -> {
136-
// registerAllShaderPermutations();
137-
});
138122
}
139123

140124

0 commit comments

Comments
 (0)