-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from deno-windowing/rawhandle
feat: raw handle
- Loading branch information
Showing
14 changed files
with
278 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ import { | |
createWindow, | ||
getProcAddress, | ||
mainloop, | ||
} from "https://deno.land/x/[email protected].3/mod.ts"; | ||
} from "https://deno.land/x/[email protected].4/mod.ts"; | ||
import * as gl from "https://deno.land/x/[email protected]/api/gles23.2.ts"; | ||
|
||
const window = createWindow({ | ||
|
@@ -51,7 +51,7 @@ await mainloop(frame); | |
import { | ||
mainloop, | ||
WindowCanvas, | ||
} from "https://deno.land/x/[email protected].3/ext/canvas.ts"; | ||
} from "https://deno.land/x/[email protected].4/ext/canvas.ts"; | ||
|
||
const canvas = new WindowCanvas({ | ||
title: "Skia Canvas", | ||
|
@@ -99,10 +99,10 @@ deno run --unstable --allow-ffi --allow-write --allow-env <file> | |
## Maintainers | ||
|
||
- Dj ([@DjDeveloperr](https://github.com/DjDeveloperr)) | ||
- Loading ([@load1n9](https://github.com/load1n9)) | ||
- Dean Srebnik ([@load1n9](https://github.com/load1n9)) | ||
|
||
## License | ||
|
||
[Apache-2.0](./LICENSE) licensed. | ||
|
||
Copyright 2023 © The Deno Windowing Team | ||
Copyright 2024 © The Deno Windowing Team |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import { | |
Canvas, | ||
CanvasRenderingContext2D, | ||
createCanvas, | ||
} from "https://deno.land/x/[email protected].4/mod.ts"; | ||
} from "https://deno.land/x/[email protected].5/mod.ts"; | ||
|
||
import { | ||
createWindow, | ||
|
@@ -12,7 +12,7 @@ import { | |
WindowClosedEvent, | ||
WindowFramebufferSizeEvent, | ||
WindowRefreshEvent, | ||
} from "https://deno.land/x/[email protected]/mod.ts"; | ||
} from "../../mod.ts"; | ||
|
||
export class WindowCanvas { | ||
canvas: Canvas; | ||
|
@@ -84,5 +84,5 @@ export class WindowCanvas { | |
} | ||
} | ||
|
||
export * from "https://deno.land/x/[email protected].4/mod.ts"; | ||
export { mainloop } from "https://deno.land/x/[email protected]/mod.ts"; | ||
export * from "https://deno.land/x/[email protected].5/mod.ts"; | ||
export { mainloop } from "../../mod.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { createWindow, getProcAddress, mainloop, pollEvents } from "../mod.ts"; | ||
import { createWindow, getProcAddress, mainloop } from "../mod.ts"; | ||
import * as gl from "https://deno.land/x/[email protected]/api/gles23.2.ts"; | ||
import { CBool, createContext, destroyContext, imgui } from "../ext/imgui.ts"; | ||
import { Bool, createContext, destroyContext, imgui } from "../ext/imgui.ts"; | ||
|
||
const window = createWindow({ | ||
title: "Imgui", | ||
|
@@ -19,17 +19,17 @@ addEventListener("close", (event) => { | |
|
||
const imguiContext = createContext(window); | ||
|
||
const showDemo = new CBool(true); | ||
const showDemo = new Bool(true); | ||
await mainloop(() => { | ||
gl.Clear(gl.COLOR_BUFFER_BIT); | ||
imgui.implOpenGL3NewFrame(); | ||
imgui.implGlfwNewFrame(); | ||
imgui.newFrame(); | ||
imgui.begin("control"); | ||
imgui.checkbox("show demo window", showDemo); | ||
imgui.checkbox("show demo window", showDemo.buffer); | ||
imgui.end(); | ||
if (showDemo.value) { | ||
imgui.showDemoWindow(showDemo); | ||
imgui.showDemoWindow(showDemo.buffer); | ||
} | ||
imgui.render(); | ||
const drawData = imgui.getDrawData(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
import { createWindow, mainloop } from "../mod.ts"; | ||
|
||
const adapter = await navigator.gpu.requestAdapter(); | ||
const device = await adapter!.requestDevice(); | ||
|
||
const window = createWindow({ | ||
title: "Deno Window Manager", | ||
width: 512, | ||
height: 512, | ||
resizable: true, | ||
}); | ||
|
||
const { width, height } = window.framebufferSize; | ||
|
||
const surface = window.windowSurface(); | ||
|
||
const context = surface.getContext("webgpu"); | ||
|
||
let pipeline: GPURenderPipeline; | ||
|
||
const uniformLength = 5; | ||
|
||
let uniformValues: Float32Array, | ||
uniformBindGroup: GPUBindGroup, | ||
uniformBuffer: GPUBuffer; | ||
|
||
function createPipeline() { | ||
const fragEntry = "fs_main"; | ||
|
||
const shaderModule = device.createShaderModule({ | ||
code: ` | ||
struct Uniforms { | ||
mouse: vec2f, | ||
clicked: f32, | ||
frame: f32, | ||
}; | ||
@group(0) @binding(0) var<uniform> shaderplay: Uniforms; | ||
$struct VertexInput { | ||
@builtin(vertex_index) vertex_index: u32, | ||
}; | ||
@vertex | ||
fn vs_main(in: VertexInput) -> @builtin(position) vec4<f32> { | ||
let x = f32(i32(in.vertex_index) - 1); | ||
let y = f32(i32(in.vertex_index & 1u) * 2 - 1); | ||
return vec4<f32>(x, y, 0.0, 1.0); | ||
} | ||
@fragment | ||
fn fs_main(@builtin(position) pos: vec4<f32>) -> @location(0) vec4<f32> { | ||
return vec4<f32>(1.0, 0.0, 0.0, 1.0); | ||
} | ||
`, | ||
label: "example", | ||
}); | ||
|
||
const bindGroupLayout = device.createBindGroupLayout({ | ||
entries: [ | ||
{ | ||
binding: 0, | ||
visibility: GPUShaderStage.FRAGMENT | GPUShaderStage.VERTEX, | ||
buffer: { | ||
type: "uniform", | ||
}, | ||
}, | ||
], | ||
}); | ||
pipeline = device.createRenderPipeline({ | ||
// "auto" layout not working in Deno but works in browser | ||
layout: device.createPipelineLayout({ | ||
bindGroupLayouts: [ | ||
bindGroupLayout, | ||
], | ||
}), | ||
vertex: { | ||
module: shaderModule, | ||
entryPoint: "vs_main", | ||
buffers: [], | ||
}, | ||
fragment: { | ||
module: shaderModule, | ||
entryPoint: fragEntry, | ||
targets: [ | ||
{ | ||
format: "bgra8unorm", | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
const value = new Float32Array(uniformLength); | ||
uniformBuffer = device.createBuffer({ | ||
size: value.byteLength, | ||
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST, | ||
}); | ||
uniformValues = value; | ||
|
||
device.queue.writeBuffer(uniformBuffer, 0, value); | ||
|
||
uniformBindGroup = device.createBindGroup({ | ||
layout: bindGroupLayout, | ||
entries: [ | ||
{ binding: 0, resource: { buffer: uniformBuffer } }, | ||
], | ||
}); | ||
|
||
// window.raise(); | ||
} | ||
|
||
createPipeline(); | ||
|
||
context.configure({ | ||
device, | ||
format: "bgra8unorm", | ||
}); | ||
|
||
addEventListener("mousemove", (evt) => { | ||
uniformValues[0] = evt.clientX / width; | ||
uniformValues[1] = evt.clientY / height; | ||
}); | ||
|
||
addEventListener("mousedown", (evt) => { | ||
uniformValues[2] = 1; | ||
}); | ||
|
||
addEventListener("mouseup", (evt) => { | ||
uniformValues[2] = 0; | ||
}); | ||
|
||
await mainloop(() => { | ||
uniformValues[3]++; // frame++ | ||
|
||
const commandEncoder = device.createCommandEncoder(); | ||
const textureView = context.getCurrentTexture().createView(); | ||
|
||
const renderPass = commandEncoder.beginRenderPass({ | ||
colorAttachments: [ | ||
{ | ||
view: textureView, | ||
clearValue: { r: 0, g: 0, b: 0, a: 1 }, | ||
loadOp: "clear", | ||
storeOp: "store", | ||
}, | ||
], | ||
}); | ||
|
||
device.queue.writeBuffer(uniformBuffer, 0, uniformValues); | ||
|
||
renderPass.setPipeline(pipeline); | ||
renderPass.setBindGroup(0, uniformBindGroup); | ||
renderPass.draw(3, 1); | ||
renderPass.end(); | ||
|
||
device.queue.submit([commandEncoder.finish()]); | ||
surface.present(); | ||
}, false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import { | |
Canvas, | ||
CanvasRenderingContext2D, | ||
createCanvas, | ||
} from "https://deno.land/x/[email protected].2/mod.ts"; | ||
} from "https://deno.land/x/[email protected].5/mod.ts"; | ||
|
||
import { | ||
createWindow, | ||
|
@@ -86,4 +86,4 @@ export class WindowCanvas { | |
export * from "../mod.ts"; | ||
// deno-lint-ignore ban-ts-comment | ||
// @ts-expect-error | ||
export * from "https://deno.land/x/[email protected].2/mod.ts"; | ||
export * from "https://deno.land/x/[email protected].5/mod.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.