Skip to content

Commit

Permalink
Fix triangle example compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
chances committed Apr 9, 2024
1 parent 47c4973 commit 0b83ed1
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 51 deletions.
11 changes: 0 additions & 11 deletions examples/triangle/assets/shaders/triangle.fs.glsl

This file was deleted.

12 changes: 0 additions & 12 deletions examples/triangle/assets/shaders/triangle.vs.glsl

This file was deleted.

14 changes: 14 additions & 0 deletions examples/triangle/assets/shaders/triangle.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
struct Fragment {
@builtin(position) pos: vec4f,
color: vec4f
}

@vertex
fn vs(@location(0) pos: vec3f, @location(1) color: vec4f) -> Fragment {
return Fragment(pos, color);
}

@fragment
fn fs(frag: Fragment) -> @location(0) vec4f {
return frag.color;
}
11 changes: 2 additions & 9 deletions examples/triangle/dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,16 @@
"Chance Snow"
],
"license": "BSD 3-clause",
"copyright": "Copyright © 2020, Chance Snow",
"copyright": "Copyright © 2020-2024, Chance Snow",
"targetType": "executable",
"targetPath": "../../bin",
"systemDependencies": "glfw >= 3.2.0",
"dependencies": {
"teraflop": {
"path": "../../"
}
},
"preBuildCommands": [
"glslc assets/shaders/triangle.vs.glsl -o assets/shaders/triangle.vs.spv",
"glslc assets/shaders/triangle.fs.glsl -o assets/shaders/triangle.fs.spv"
],
"stringImportPaths": ["."],
"postBuildCommands-linux": [
"patchelf --set-rpath '$$ORIGIN' $PACKAGE_DIR/../../bin/triangle"
],
"lflags-linux": [
"-L../../lib/glfw-3.3.2/src"
]
}
13 changes: 6 additions & 7 deletions examples/triangle/dub.selections.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"fileVersion": 1,
"versions": {
"bindbc-glfw": "1.0.1",
"bindbc-loader": "1.0.1",
"eventcore": "0.9.20",
"bindbc-glfw": "1.0.3",
"bindbc-loader": "1.0.3",
"eventcore": "0.9.30",
"gfm": "8.0.6",
"intel-intrinsics": "1.10.2",
"intel-intrinsics": "1.11.18",
"libasync": "0.8.6",
"memutils": "1.0.4",
"memutils": "1.0.10",
"taggedalgebraic": "0.11.22",
"teraflop": {"path":"../../"},
"wgpu-d": "0.1.0+commit.12.g2aa4be8"
"wgpu-d": {"version":"8c5deeed965fba2903565d4272d5b3146d4f4b5f","repository":"git+https://github.com/chances/wgpu-d.git"}
}
}
4 changes: 2 additions & 2 deletions examples/triangle/source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ private final class Triangle : Game {
this.add(System.from!exitOnEscape);

auto shaders = [
new Shader(ShaderStage.vertex, "examples/triangle/assets/shaders/triangle.vs.spv", SourceLanguage.spirv),
new Shader(ShaderStage.fragment, "examples/triangle/assets/shaders/triangle.fs.spv", SourceLanguage.spirv)
new Shader(ShaderStage.vertex, import("assets/shaders/triangle.wgsl")),
new Shader(ShaderStage.fragment, import("assets/shaders/triangle.wgsl"))
];

world.spawn(Material(shaders, No.depthTest), Mesh!VertexPosColor([
Expand Down
8 changes: 5 additions & 3 deletions source/ecs/components.d
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ struct ObservableFile {
import std.typecons : Flag, No, Yes;
import teraflop.async : Event;

private File* _file;
private File* _file = null;

/// Whether this file is being watched for changes.
const bool hotReload;
const bool hotReload = false;

/// Fired if the file is being actively watched and when the file's contents change.
Event!(const(ubyte)[]) onChanged;
Expand All @@ -107,7 +107,9 @@ struct ObservableFile {
/// Instantiate a static file given its in-memory `contents`.
package (teraflop) this(string contents) {
import std.conv : to;
this(contents.to!(const ubyte[]));
import std.string : representation;

this(contents.representation.to!(const ubyte[]));
}
/// Instantiate a static file given its in-memory `contents`.
package (teraflop) this(const(ubyte)[] contents) {
Expand Down
7 changes: 3 additions & 4 deletions source/game.d
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,16 @@ abstract class Game {
import teraflop.platform.window : initGlfw, terminateGlfw;
import wgpu.api : PowerPreference;

this.instance = Instance.create();

// Setup main window
if (!initGlfw()) {
return;
}
if (!initGlfw()) return;
scope(exit) terminateGlfw();

windows_ ~= _mainWindow = new Window(instance, name);
if (!_mainWindow.valid) return;

// Setup graphics resources
this.instance = Instance.create();
// TODO: Select `PowerPreference.lowPower` on laptops and whatnot
this.adapter = instance.requestAdapter(_mainWindow.surface, PowerPreference.highPerformance);
assert(adapter.ready);
Expand Down
5 changes: 2 additions & 3 deletions source/platform/window.d
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class Window : InputNode, Resource {
private GLFWwindow* window;
private Device device_;
private Surface surface_;
private TextureFormat swapChainFormat_;
private const EventLoop eventLoop_;
private string title_;
private WindowData data;
Expand Down Expand Up @@ -56,7 +55,7 @@ class Window : InputNode, Resource {
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); // Graphics are handled by wgpu

window = glfwCreateWindow(width, height, toStringz(title), null, null);
if (!valid) {
if (window is null) {
errorCallback(0, toStringz("Failed to initialize a new GLFW Window"));
return;
}
Expand Down Expand Up @@ -295,7 +294,7 @@ class Window : InputNode, Resource {

this.device_ = device;

this.swapChainFormat_ = surface.preferredFormat(adapter);
auto surfaceFormat = surface.preferredFormat(adapter);
surface.configure(
device, surfaceSize.width, surfaceSize.height, surfaceFormat,
TextureUsage.renderAttachment,
Expand Down

0 comments on commit 0b83ed1

Please sign in to comment.