Skip to content

Commit

Permalink
updated more example
Browse files Browse the repository at this point in the history
  • Loading branch information
arhik committed Oct 21, 2023
1 parent 0bd96c1 commit c30aae7
Show file tree
Hide file tree
Showing 20 changed files with 281 additions and 352 deletions.
1 change: 0 additions & 1 deletion examples/circle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ using StaticArrays

WGPUCore.SetLogLevel(WGPUCore.WGPULogLevel_Debug)


scene = Scene()
canvas = scene.canvas

Expand Down
28 changes: 12 additions & 16 deletions examples/gridExample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,26 @@ using StaticArrays

WGPUCore.SetLogLevel(WGPUCore.WGPULogLevel_Off)

canvas = WGPUCore.defaultCanvas(WGPUCore.WGPUCanvas);
gpuDevice = WGPUCore.getDefaultDevice();
grid = defaultGrid()

camera = defaultCamera()
light = defaultLighting()
scene = Scene()
canvas = scene.canvas

grid = defaultGrid()
renderer = getRenderer(scene)

scene = Scene(
gpuDevice,
canvas,
camera,
light,
[],
repeat([nothing], 4)...
)
addObject!(renderer, grid)
attachEventSystem(renderer)

addObject!(scene, grid)
attachEventSystem(scene)
function runApp(renderer)
init(renderer)
render(renderer)
deinit(renderer)
end

main = () -> begin
try
while !WindowShouldClose(canvas.windowRef[])
runApp(scene)
runApp(renderer)
PollEvents()
end
finally
Expand Down
32 changes: 17 additions & 15 deletions examples/imageviewer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,32 @@ using StaticArrays
using CoordinateTransformations

WGPUCore.SetLogLevel(WGPUCore.WGPULogLevel_Debug)
canvas = WGPUCore.defaultCanvas(WGPUCore.WGPUCanvas; size=(500, 500));
gpuDevice = WGPUCore.getDefaultDevice();
scene = Scene()
canvas = scene.canvas
gpuDevice = scene.gpuDevice

camera = defaultCamera()
light = defaultLighting()
renderer = getRenderer(scene)

scene = Scene(
gpuDevice,
canvas,
camera,
light,
[],
repeat([nothing], 4)...,
plane = defaultWGPUMesh(
joinpath(pkgdir(WGPUgfx), "assets", "plane.obj");
image = joinpath(pkgdir(WGPUgfx), "assets", "R.png")
)

mesh1 = defaultWGPUMesh(joinpath(pkgdir(WGPUgfx), "assets", "plane.obj"); image="/Users/arhik/Pictures/OIP.jpeg")
addObject!(scene, mesh1)
addObject!(renderer, plane)

attachEventSystem(renderer)

function runApp(renderer)
init(renderer)
render(renderer)
deinit(renderer)
end

attachEventSystem(scene)

main = () -> begin
try
while !WindowShouldClose(canvas.windowRef[])
runApp(gpuDevice, scene)
runApp(renderer)
PollEvents()
end
finally
Expand Down
34 changes: 16 additions & 18 deletions examples/juliaLogo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,32 @@ using StaticArrays
using CoordinateTransformations

WGPUCore.SetLogLevel(WGPUCore.WGPULogLevel_Off)
canvas = WGPUCore.defaultCanvas(WGPUCore.WGPUCanvas; size=(500, 500));
gpuDevice = WGPUCore.getDefaultDevice();

camera = defaultCamera()
light = defaultLighting()
scene = Scene()
renderer = getRenderer(scene)

scene = Scene(
gpuDevice,
canvas,
camera,
light,
[],
repeat([nothing], 4)...,
)
canvas = scene.canvas
gpuDevice = scene.gpuDevice

mesh1 = defaultWGPUMesh(joinpath(pkgdir(WGPUgfx), "assets", "sphere.obj"); color=[0.6, 0.4, 0.5, 1.0])
mesh2 = defaultWGPUMesh(joinpath(pkgdir(WGPUgfx), "assets", "sphere.obj"); color=[0.8, 0.4, 0.3, 0.5])
mesh3 = defaultWGPUMesh(joinpath(pkgdir(WGPUgfx), "assets", "sphere.obj"); color=[0.3, 0.6, 0.9, 0.5])
mesh4 = defaultWGPUMesh(joinpath(pkgdir(WGPUgfx), "assets", "sphere.obj"); color = [0.4, 0.3, 0.5, 0.3])
# mesh5 = defaultWGPUMesh(joinpath(pkgdir(WGPUgfx), "assets", "monkey.obj"); color = [0.4, 0.3, 0.5, 0.3])

addObject!(scene, mesh1)
addObject!(scene, mesh2)
addObject!(scene, mesh3)
addObject!(scene, mesh4)
addObject!(renderer, mesh1)
addObject!(renderer, mesh2)
addObject!(renderer, mesh3)
addObject!(renderer, mesh4)
# addObject!(scene, mesh5)

attachEventSystem(scene)
attachEventSystem(renderer)

function runApp(renderer)
init(renderer)
render(renderer)
deinit(renderer)
end

# @enter runApp(scene, gpuDevice, renderPipeline)
main = () -> begin
Expand Down Expand Up @@ -69,7 +67,7 @@ main = () -> begin
mat = MMatrix{4, 4}(mesh2.uniformData)
mat[1:3, 1:3] .= rot
mesh3.uniformData = mat*mesh3Translation*mat
runApp(gpuDevice, scene)
runApp(renderer)
PollEvents()
end
finally
Expand Down
36 changes: 19 additions & 17 deletions examples/materialCube.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,33 @@ using Rotations
using StaticArrays

WGPUCore.SetLogLevel(WGPUCore.WGPULogLevel_Off)
canvas = WGPUCore.defaultCanvas(WGPUCore.WGPUCanvas);
gpuDevice = WGPUCore.getDefaultDevice();
camera = defaultCamera()

light = defaultLighting()

scene = Scene(
gpuDevice,
canvas,
camera,
light,
[],
repeat([nothing], 4)...

scene = Scene()
renderer = getRenderer(scene)

canvas = scene.canvas
gpuDevice = scene.gpuDevice


cube = defaultWGPUMesh(
joinpath(pkgdir(WGPUgfx), "assets", "cube.obj");
image= "$(pkgdir(WGPUgfx))/assets/R.png"
)

cube = defaultWGPUMesh(joinpath(pkgdir(WGPUgfx), "assets", "cube.obj"); image= "/Users/arhik/Pictures/OIP.jpeg")
addObject!(renderer, cube)

addObject!(scene, cube)
attachEventSystem(renderer)

attachEventSystem(scene)
function runApp(renderer)
init(renderer)
render(renderer)
deinit(renderer)
end

main = () -> begin
try
while !WindowShouldClose(canvas.windowRef[])
runApp(scene)
runApp(renderer)
PollEvents()
end
finally
Expand Down
29 changes: 13 additions & 16 deletions examples/meshCube.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,22 @@ using Rotations
using StaticArrays

WGPUCore.SetLogLevel(WGPUCore.WGPULogLevel_Debug)
canvas = WGPUCore.defaultCanvas(WGPUCore.WGPUCanvas);
gpuDevice = WGPUCore.getDefaultDevice();

camera = defaultCamera()
light = defaultLighting()
scene = Scene(
gpuDevice,
canvas,
camera,
light,
[],
repeat([nothing], 4)...
)
scene = Scene()
renderer = getRenderer(scene)
canvas = scene.canvas
gpuDevice = scene.gpuDevice

mesh = WGPUgfx.defaultWGPUMesh(joinpath(pkgdir(WGPUgfx), "assets", "cube.obj"))

addObject!(scene, mesh)
addObject!(renderer, mesh)

attachEventSystem(renderer)

attachEventSystem(scene)
function runApp(renderer)
init(renderer)
render(renderer)
deinit(renderer)
end

# @enter runApp(scene, gpuDevice, renderPipeline)
main = () -> begin
Expand All @@ -36,7 +33,7 @@ main = () -> begin
# camera = scene.camera
# rotxy = RotXY(pi/3, time())
# camera.scale = [1, 1, 1] .|> Float32
runApp(gpuDevice, scene)
runApp(renderer)
PollEvents()
end
finally
Expand Down
38 changes: 21 additions & 17 deletions examples/meshCubeWireFrame.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# TODO this is a bit incomplete.
# The wireframe does not convert the all vertices and lines yet but a good start for now

using Debugger
using WGPUgfx
using WGPUgfx: RenderType
Expand All @@ -10,33 +13,34 @@ using Rotations
using StaticArrays

WGPUCore.SetLogLevel(WGPUCore.WGPULogLevel_Debug)
canvas = WGPUCore.defaultCanvas(WGPUCore.WGPUCanvas);
gpuDevice = WGPUCore.getDefaultDevice();

camera = defaultCamera()
light = defaultLighting()
scene = Scene(
gpuDevice,
canvas,
camera,
light,
[],
repeat([nothing], 4)...
scene = Scene()
canvas = scene.canvas
gpuDevice = scene.gpuDevice

renderer = getRenderer(scene)

mesh = WGPUgfx.defaultCube(
joinpath(pkgdir(WGPUgfx), "assets", "cube.obj")
)

mesh = WGPUgfx.defaultCube()# (joinpath(pkgdir(WGPUgfx), "assets", "monkey.obj"))
wo = WorldObject{Cube}(
mesh,
RenderType(VISIBLE | SURFACE | WIREFRAME | AXIS),
RenderType(VISIBLE | WIREFRAME | AXIS),
nothing,
nothing,
nothing,
nothing
)

addObject!(scene, wo)
addObject!(renderer, wo)

attachEventSystem(scene)
attachEventSystem(renderer)

function runApp(renderer)
init(renderer)
render(renderer)
deinit(renderer)
end

main = () -> begin
try
Expand All @@ -45,7 +49,7 @@ main = () -> begin
mat = MMatrix{4, 4}(wo.uniformData)
mat .= tz
wo.uniformData = mat
runApp(gpuDevice, scene)
runApp(renderer)
PollEvents()
end
finally
Expand Down
34 changes: 16 additions & 18 deletions examples/meshMonkey.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,27 @@ using Rotations
using StaticArrays

WGPUCore.SetLogLevel(WGPUCore.WGPULogLevel_Debug)
canvas = WGPUCore.defaultCanvas(WGPUCore.WGPUCanvas);
gpuDevice = WGPUCore.getDefaultDevice();

camera = defaultCamera()
light = defaultLighting()
scene = Scene(
gpuDevice,
canvas,
camera,
light,
[],
repeat([nothing], 4)...
)

scene = Scene()
canvas = scene.canvas
gpuDevice = scene.gpuDevice
renderer = getRenderer(scene)

mesh = WGPUgfx.defaultWGPUMesh(joinpath(pkgdir(WGPUgfx), "assets", "monkey.obj"))

bb = defaultBBox(mesh)
wf = defaultWireFrame(mesh)
addObject!(scene, mesh)
addObject!(scene, bb)
addObject!(scene, wf)
addObject!(renderer, mesh)
addObject!(renderer, bb)
addObject!(renderer, wf)

attachEventSystem(renderer)

attachEventSystem(scene)
function runApp(renderer)
init(renderer)
render(renderer)
deinit(renderer)
end

main = () -> begin
try
Expand All @@ -40,7 +38,7 @@ main = () -> begin
mat = MMatrix{4, 4}(mesh.uniformData)
mat .= tz
mesh.uniformData = mat
runApp(gpuDevice, scene)
runApp(renderer)
PollEvents()
end
finally
Expand Down
Loading

0 comments on commit c30aae7

Please sign in to comment.