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

feature: wgpu rendering rewrite #5124

Draft
wants to merge 13 commits into
base: develop
Choose a base branch
from
17 changes: 17 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ ext {
subDirLibs = 'libs'

LwjglVersion = '3.3.1'
rustCoreVersion = '0.0.1'
}


Expand Down Expand Up @@ -114,6 +115,11 @@ dependencies {
// Natives for JNBullet
natives group: 'org.terasology.jnbullet', name: 'JNBullet', version: '1.0.2', ext: 'zip'

// Natives for core
natives(group: 'org.terasology.rust', name: 'core-rust', version: rustCoreVersion){
transitive = true
}

}

task extractWindowsNatives(type: Copy) {
Expand Down Expand Up @@ -159,6 +165,16 @@ task extractNativeBulletNatives(type: Copy) {
into("$dirNatives")
}

task extractRustCoreNatives(type:Copy) {
description = "Extracts the JNBullet natives from the downloaded zip"
from configurations.natives
from {
configurations.natives.collect { it.getName().contains('core-rust') ? zipTree(it) : [] }
}
into ("$dirNatives")
}



task extractNatives {
description = "Extracts all the native lwjgl libraries from the downloaded zip"
Expand All @@ -167,6 +183,7 @@ task extractNatives {
dependsOn extractMacOSXNatives
dependsOn extractJNLuaNatives
dependsOn extractNativeBulletNatives
dependsOn extractRustCoreNatives
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 2 additions & 0 deletions engine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins {
id "org.jetbrains.gradle.plugin.idea-ext"
id "com.google.protobuf"
id "terasology-common"

}

// Grab all the common stuff like plugins to use, artifact repositories, code analysis config, etc
Expand Down Expand Up @@ -150,6 +151,7 @@ dependencies {
api group: 'org.terasology.nui', name: 'nui-reflect', version: '3.0.0'
api group: 'org.terasology.nui', name: 'nui-gestalt7', version: '3.0.0'

api group: 'org.terasology.rust', name: 'core', version: rustCoreVersion

// Wildcard dependency to catch any libs provided with the project (remote repo preferred instead)
api fileTree(dir: 'libs', include: '*.jar')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.terasology.engine.recording.RecordAndReplayUtils;
import org.terasology.engine.registry.CoreRegistry;
import org.terasology.engine.rendering.gltf.ByteBufferAsset;
import org.terasology.engine.rust.EngineKernel;
import org.terasology.engine.version.TerasologyVersion;
import org.terasology.engine.world.block.loader.BlockFamilyDefinition;
import org.terasology.engine.world.block.loader.BlockFamilyDefinitionData;
Expand Down Expand Up @@ -161,6 +162,7 @@ public TerasologyEngine(TimeSubsystem timeSubsystem, Collection<EngineSubsystem>
rootContext.put(CharacterStateEventPositionMap.class, characterStateEventPositionMap);
DirectionAndOriginPosRecorderList directionAndOriginPosRecorderList = new DirectionAndOriginPosRecorderList();
rootContext.put(DirectionAndOriginPosRecorderList.class, directionAndOriginPosRecorderList);

/*
* We can't load the engine without core registry yet.
* e.g. the statically created MaterialLoader needs the CoreRegistry to get the AssetManager.
Expand Down Expand Up @@ -564,6 +566,7 @@ public void cleanup() {
*/
@Override
public void shutdown() {

shutdownRequested = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.terasology.engine.rendering.backdrop.BackdropProvider;
import org.terasology.engine.rendering.backdrop.Skysphere;
import org.terasology.engine.rendering.cameras.Camera;
import org.terasology.engine.rendering.world.DeferredRenderer;
import org.terasology.engine.rendering.world.WorldRenderer;
import org.terasology.engine.utilities.random.FastRandom;
import org.terasology.engine.world.BlockEntityRegistry;
Expand Down Expand Up @@ -159,8 +160,7 @@ public boolean step() {
BackdropProvider backdropProvider = skysphere;
context.put(BackdropProvider.class, backdropProvider);

RenderingSubsystemFactory engineSubsystemFactory = context.get(RenderingSubsystemFactory.class);
WorldRenderer worldRenderer = engineSubsystemFactory.createWorldRenderer(context);
WorldRenderer worldRenderer = new DeferredRenderer(context);
context.put(WorldRenderer.class, worldRenderer);

// TODO: These shouldn't be done here, nor so strongly tied to the world renderer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ public LwjglDisplayDevice(Context context) {

@Override
public boolean hasFocus() {
return GLFW.GLFW_TRUE == GLFW.glfwGetWindowAttrib(GLFW.glfwGetCurrentContext(), GLFW.GLFW_FOCUSED);
return GLFW.GLFW_TRUE == GLFW.glfwGetWindowAttrib(LwjglGraphics.primaryWindow, GLFW.GLFW_FOCUSED);
}

@Override
public boolean isCloseRequested() {
return GLFW.glfwWindowShouldClose(GLFW.glfwGetCurrentContext());
return GLFW.glfwWindowShouldClose(LwjglGraphics.primaryWindow);
}

@Override
public boolean isFullscreen() {
return MemoryUtil.NULL != GLFW.glfwGetWindowMonitor(GLFW.glfwGetCurrentContext());
return MemoryUtil.NULL != GLFW.glfwGetWindowMonitor(LwjglGraphics.primaryWindow);
}

@Override
Expand All @@ -79,7 +79,7 @@ public void setDisplayModeSetting(DisplayModeSetting displayModeSetting) {
}

public void setDisplayModeSetting(DisplayModeSetting displayModeSetting, boolean resize) {
long window = GLFW.glfwGetCurrentContext();
// long window = GLFW.glfwGetCurrentContext();
switch (displayModeSetting) {
case FULLSCREEN:
updateFullScreenDisplay();
Expand All @@ -88,21 +88,21 @@ public void setDisplayModeSetting(DisplayModeSetting displayModeSetting, boolean
break;
case WINDOWED_FULLSCREEN:
GLFWVidMode vidMode = desktopResolution.get();
GLFW.glfwSetWindowMonitor(window,
GLFW.glfwSetWindowMonitor(LwjglGraphics.primaryWindow,
MemoryUtil.NULL,
0,
0,
vidMode.width(),
vidMode.height(),
GLFW.GLFW_DONT_CARE);
GLFW.glfwSetWindowAttrib(window, GLFW.GLFW_DECORATED, GLFW.GLFW_FALSE);
GLFW.glfwSetWindowAttrib(LwjglGraphics.primaryWindow, GLFW.GLFW_DECORATED, GLFW.GLFW_FALSE);
config.setDisplayModeSetting(displayModeSetting);
config.setWindowedFullscreen(true);
break;
case WINDOWED:
GLFW.glfwSetWindowAttrib(window, GLFW.GLFW_DECORATED, GLFW.GLFW_TRUE);
GLFW.glfwSetWindowAttrib(window, GLFW.GLFW_RESIZABLE, GLFW.GLFW_TRUE);
GLFW.glfwSetWindowMonitor(window,
GLFW.glfwSetWindowAttrib(LwjglGraphics.primaryWindow, GLFW.GLFW_DECORATED, GLFW.GLFW_TRUE);
GLFW.glfwSetWindowAttrib(LwjglGraphics.primaryWindow, GLFW.GLFW_RESIZABLE, GLFW.GLFW_TRUE);
GLFW.glfwSetWindowMonitor(LwjglGraphics.primaryWindow,
MemoryUtil.NULL,
config.getWindowPosX(),
config.getWindowPosY(),
Expand Down Expand Up @@ -150,7 +150,7 @@ private void updateWindow() {
if (isWindowDirty) {
int[] windowWidth = new int[1];
int[] windowHeight = new int[1];
GLFW.glfwGetWindowSize(GLFW.glfwGetCurrentContext(), windowWidth, windowHeight);
GLFW.glfwGetWindowSize(LwjglGraphics.primaryWindow, windowWidth, windowHeight);
this.windowWidth = windowWidth[0];
this.windowHeight = windowHeight[0];
isWindowDirty = false;
Expand Down Expand Up @@ -178,18 +178,18 @@ public boolean isHeadless() {

@Override
public void prepareToRender() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}

@Override
public DisplayDeviceInfo getInfo() {
LwjglGraphicsUtil.updateDisplayDeviceInfo(displayDeviceInfo);
// LwjglGraphicsUtil.updateDisplayDeviceInfo(displayDeviceInfo);
return displayDeviceInfo;
}

public void update() {
processMessages();
GLFW.glfwSwapBuffers(GLFW.glfwGetCurrentContext());
// GLFW.glfwSwapBuffers(GLFW.glfwGetCurrentContext());
isWindowDirty = true;

}
Expand All @@ -199,10 +199,10 @@ private void updateViewport() {
}

protected void updateViewport(int width, int height) {
glViewport(0, 0, width, height);
// glViewport(0, 0, width, height);

//If the screen is minimized, resolution change is stopped to avoid the width and height of FBO being set to 0.
boolean isMinimized = GLFW.glfwGetWindowAttrib(GLFW.glfwGetCurrentContext(), GLFW.GLFW_ICONIFIED) == GLFW.GLFW_TRUE;
boolean isMinimized = GLFW.glfwGetWindowAttrib(LwjglGraphics.primaryWindow, GLFW.GLFW_ICONIFIED) == GLFW.GLFW_TRUE;
int i = isMinimized ? 0 : 1;
propertyChangeSupport.firePropertyChange(DISPLAY_RESOLUTION_CHANGE, i, 1);
}
Expand All @@ -217,9 +217,8 @@ private GLFWVidMode getFullScreenDisplayMode() {
}

private void updateFullScreenDisplay() {
long window = GLFW.glfwGetCurrentContext();
GLFWVidMode vidMode = getFullScreenDisplayMode();
GLFW.glfwSetWindowMonitor(window,
GLFW.glfwSetWindowMonitor(LwjglGraphics.primaryWindow,
GLFW.glfwGetPrimaryMonitor(),
0,
0,
Expand Down
Loading
Loading