From c30aae78139a5a4714382ad814abab8333cffb53 Mon Sep 17 00:00:00 2001 From: Arhik Date: Sat, 21 Oct 2023 06:09:42 +0530 Subject: [PATCH] updated more example --- examples/circle.jl | 1 - examples/gridExample.jl | 28 +++--- examples/imageviewer.jl | 32 +++---- examples/juliaLogo.jl | 34 ++++--- examples/materialCube.jl | 36 ++++---- examples/meshCube.jl | 29 +++--- examples/meshCubeWireFrame.jl | 38 ++++---- examples/meshMonkey.jl | 34 ++++--- examples/meshMonkeyWireFrame.jl | 32 ++++--- examples/meshPixarLight.jl | 30 +++---- examples/meshTexture.jl | 38 ++++---- examples/meshorangebot.jl | 29 +++--- examples/multiObject.jl | 32 ++++--- examples/plane.jl | 29 +++--- examples/planeFloor.jl | 28 +++--- examples/tri.jl | 21 +++-- src/primitives/circle.jl | 153 +++++++++++--------------------- src/primitives/mesh.jl | 2 +- src/primitives/plane.jl | 6 +- src/renderableUI.jl | 1 - 20 files changed, 281 insertions(+), 352 deletions(-) diff --git a/examples/circle.jl b/examples/circle.jl index d3df8c8..49eb91b 100644 --- a/examples/circle.jl +++ b/examples/circle.jl @@ -11,7 +11,6 @@ using StaticArrays WGPUCore.SetLogLevel(WGPUCore.WGPULogLevel_Debug) - scene = Scene() canvas = scene.canvas diff --git a/examples/gridExample.jl b/examples/gridExample.jl index e3d289a..eaa8955 100644 --- a/examples/gridExample.jl +++ b/examples/gridExample.jl @@ -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 diff --git a/examples/imageviewer.jl b/examples/imageviewer.jl index ad6437d..83a89c0 100644 --- a/examples/imageviewer.jl +++ b/examples/imageviewer.jl @@ -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 diff --git a/examples/juliaLogo.jl b/examples/juliaLogo.jl index 9f131bf..8f8a698 100644 --- a/examples/juliaLogo.jl +++ b/examples/juliaLogo.jl @@ -10,20 +10,12 @@ 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]) @@ -31,13 +23,19 @@ mesh3 = defaultWGPUMesh(joinpath(pkgdir(WGPUgfx), "assets", "sphere.obj"); color 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 @@ -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 diff --git a/examples/materialCube.jl b/examples/materialCube.jl index 38cb06e..7e39b5f 100644 --- a/examples/materialCube.jl +++ b/examples/materialCube.jl @@ -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 diff --git a/examples/meshCube.jl b/examples/meshCube.jl index 4f95ead..2a5fab3 100644 --- a/examples/meshCube.jl +++ b/examples/meshCube.jl @@ -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 @@ -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 diff --git a/examples/meshCubeWireFrame.jl b/examples/meshCubeWireFrame.jl index 3992dab..9198be5 100644 --- a/examples/meshCubeWireFrame.jl +++ b/examples/meshCubeWireFrame.jl @@ -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 @@ -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 @@ -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 diff --git a/examples/meshMonkey.jl b/examples/meshMonkey.jl index 4c4726c..46b488e 100644 --- a/examples/meshMonkey.jl +++ b/examples/meshMonkey.jl @@ -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 @@ -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 diff --git a/examples/meshMonkeyWireFrame.jl b/examples/meshMonkeyWireFrame.jl index 0107e7b..579da73 100644 --- a/examples/meshMonkeyWireFrame.jl +++ b/examples/meshMonkeyWireFrame.jl @@ -9,27 +9,25 @@ 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")) wf = defaultWireFrame(mesh) -addObject!(scene, mesh) -addObject!(scene, wf) +addObject!(renderer, mesh) +addObject!(renderer, wf) + +attachEventSystem(renderer) -attachEventSystem(scene) +function runApp(renderer) + init(renderer) + render(renderer) + deinit(renderer) +end main = () -> begin try @@ -38,7 +36,7 @@ main = () -> begin mat = MMatrix{4, 4}(mesh.uniformData) mat .= tz mesh.uniformData = mat - runApp(gpuDevice, scene) + runApp(renderer) PollEvents() end finally diff --git a/examples/meshPixarLight.jl b/examples/meshPixarLight.jl index 70bc25a..70fa31f 100644 --- a/examples/meshPixarLight.jl +++ b/examples/meshPixarLight.jl @@ -9,27 +9,25 @@ using Rotations using StaticArrays WGPUCore.SetLogLevel(WGPUCore.WGPULogLevel_Off) -canvas = WGPUCore.defaultCanvas(WGPUCore.WGPUCanvas; size=(500, 500)); -gpuDevice = WGPUCore.getDefaultDevice(); -camera = defaultCamera() -light = defaultLighting() +scene = Scene() +canvas = scene.canvas +camera = scene.camera +gpuDevice = scene.gpuDevice -scene = Scene( - gpuDevice, - canvas, - camera, - light, - [], - repeat([nothing], 4)... -) +renderer = getRenderer(scene) mesh = defaultWGPUMesh(joinpath(pkgdir(WGPUgfx), "assets", "pixarlamp.obj")) -addObject!(scene, mesh) +addObject!(renderer, mesh) -attachEventSystem(scene) +attachEventSystem(renderer) + +function runApp(renderer) + init(renderer) + render(renderer) + deinit(renderer) +end -# @enter runApp(scene, gpuDevice, renderPipeline) main = () -> begin try while !WindowShouldClose(canvas.windowRef[]) @@ -37,7 +35,7 @@ main = () -> begin mat = MMatrix{4, 4, Float32}(I) mat[1:3, 1:3] .= rot camera.transform = camera.transform*mat - runApp(scene) + runApp(renderer) PollEvents() end finally diff --git a/examples/meshTexture.jl b/examples/meshTexture.jl index e326dac..0846ac9 100644 --- a/examples/meshTexture.jl +++ b/examples/meshTexture.jl @@ -8,28 +8,28 @@ using LinearAlgebra using Rotations using StaticArrays using CoordinateTransformations + WGPUCore.SetLogLevel(WGPUCore.WGPULogLevel_Debug) -canvas = WGPUCore.defaultCanvas(WGPUCore.WGPUCanvas; size=(500, 500)); -gpuDevice = WGPUCore.getDefaultDevice(); - -camera = defaultCamera() -light = defaultLighting() - -scene = Scene( - gpuDevice, - canvas, - camera, - light, - [], - repeat([nothing], 4)..., + +scene = Scene() +canvas = scene.canvas +gpuDevice = scene.canvas + +renderer = getRenderer(scene) + +mesh1 = defaultWGPUMesh( + joinpath(pkgdir(WGPUgfx), "assets", "sphere.obj"); + image="$(pkgdir(WGPUgfx))/assets/R.png" +) +mesh2 = defaultWGPUMesh( + joinpath(pkgdir(WGPUgfx), "assets", "torus.obj"); + image="$(pkgdir(WGPUgfx))/assets/R.png" ) -mesh1 = defaultWGPUMesh(joinpath(pkgdir(WGPUgfx), "assets", "sphere.obj"); image="/Users/arhik/Pictures/rainbow.jpeg") -mesh2 = defaultWGPUMesh(joinpath(pkgdir(WGPUgfx), "assets", "torus.obj"); image="/Users/arhik/Pictures/people.jpeg") -addObject!(scene, mesh1) -addObject!(scene, mesh2) +addObject!(renderer, mesh1) +addObject!(renderer, mesh2) -attachEventSystem(scene) +attachEventSystem(renderer) main = () -> begin try @@ -40,7 +40,7 @@ main = () -> begin mat[1:3, 1:3] .= rot mesh1.uniformData = mat - runApp(gpuDevice, scene) + runApp(renderer) PollEvents() end finally diff --git a/examples/meshorangebot.jl b/examples/meshorangebot.jl index 8572466..ac4ebf1 100644 --- a/examples/meshorangebot.jl +++ b/examples/meshorangebot.jl @@ -9,31 +9,28 @@ 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 mesh = defaultWGPUMesh(joinpath(pkgdir(WGPUgfx), "assets", "orangebot.obj")) -addObject!(scene, mesh) +addObject!(renderer, mesh) + +attachEventSystem(renderer) -attachEventSystem(scene) +function runApp(renderer) + init(renderer) + render(renderer) + deinit(renderer) +end main = () -> begin try while !WindowShouldClose(canvas.windowRef[]) - runApp(gpuDevice, scene) + runApp(renderer) PollEvents() end finally diff --git a/examples/multiObject.jl b/examples/multiObject.jl index 0af03ea..559e588 100644 --- a/examples/multiObject.jl +++ b/examples/multiObject.jl @@ -10,29 +10,27 @@ using StaticArrays using CoordinateTransformations WGPUCore.SetLogLevel(WGPUCore.WGPULogLevel_Debug) -canvas = WGPUCore.defaultCanvas(WGPUCore.WGPUCanvas; size=(500, 500)); -gpuDevice = WGPUCore.getDefaultDevice(); -camera = defaultCamera() -light = defaultLighting() +scene = Scene() +canvas = scene.canvas +gpuDevice = scene.gpuDevice -scene = Scene( - gpuDevice, - canvas, - camera, - light, - [], - repeat([nothing], 4)..., -) +renderer = getRenderer(scene) grid = defaultGrid() mesh1 = defaultWGPUMesh(joinpath(pkgdir(WGPUgfx), "assets", "sphere.obj")) mesh2 = defaultWGPUMesh(joinpath(pkgdir(WGPUgfx), "assets", "torus.obj")) -addObject!(scene, grid) -addObject!(scene, mesh2) -addObject!(scene, mesh1) +addObject!(renderer, grid) +addObject!(renderer, mesh2) +addObject!(renderer, mesh1) -attachEventSystem(scene) +attachEventSystem(renderer) + +function runApp(renderer) + init(renderer) + render(renderer) + deinit(renderer) +end # @enter runApp(scene, gpuDevice, renderPipeline) main = () -> begin @@ -44,7 +42,7 @@ main = () -> begin mat[1:3, 1:3] .= rot mesh1.uniformData = mat - runApp(gpuDevice, scene) + runApp(renderer) PollEvents() end finally diff --git a/examples/plane.jl b/examples/plane.jl index 0e52224..e2fc8c3 100644 --- a/examples/plane.jl +++ b/examples/plane.jl @@ -9,30 +9,25 @@ using StaticArrays WGPUCore.SetLogLevel(WGPUCore.WGPULogLevel_Off) -canvas = WGPUCore.defaultCanvas(WGPUCore.WGPUCanvas); -gpuDevice = WGPUCore.getDefaultDevice(); - -camera = defaultCamera() -light = defaultLighting() - plane = defaultPlane() -scene = Scene( - gpuDevice, - canvas, - camera, - light, - [], - repeat([nothing], 4)... -) +scene = Scene() +canvas = scene.canvas +renderer = getRenderer(scene) -addObject!(scene, plane) -attachEventSystem(scene) +addObject!(renderer, plane) +attachEventSystem(renderer) + +function runApp(renderer) + init(renderer) + render(renderer) + deinit(renderer) +end main = () -> begin try while !WindowShouldClose(canvas.windowRef[]) - runApp(scene) + runApp(renderer) PollEvents() end finally diff --git a/examples/planeFloor.jl b/examples/planeFloor.jl index 0e52224..e41360b 100644 --- a/examples/planeFloor.jl +++ b/examples/planeFloor.jl @@ -9,30 +9,26 @@ using StaticArrays WGPUCore.SetLogLevel(WGPUCore.WGPULogLevel_Off) -canvas = WGPUCore.defaultCanvas(WGPUCore.WGPUCanvas); -gpuDevice = WGPUCore.getDefaultDevice(); +plane = defaultPlane() -camera = defaultCamera() -light = defaultLighting() +scene = Scene() +renderer = getRenderer(scene) -plane = defaultPlane() +canvas = scene.canvas -scene = Scene( - gpuDevice, - canvas, - camera, - light, - [], - repeat([nothing], 4)... -) +addObject!(renderer, plane) +attachEventSystem(renderer) -addObject!(scene, plane) -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 diff --git a/examples/tri.jl b/examples/tri.jl index 7fbc3e3..6f3e589 100644 --- a/examples/tri.jl +++ b/examples/tri.jl @@ -8,24 +8,27 @@ using StaticArrays WGPUCore.SetLogLevel(WGPUCore.WGPULogLevel_Off) -canvas = WGPUCore.defaultCanvas(WGPUCore.WGPUCanvas); -gpuDevice = WGPUCore.getDefaultDevice(); +scene = Scene() +canvas = scene.canvas -camera = defaultCamera() -light = defaultLighting() - -scene = Scene(gpuDevice, canvas, camera, light, [], repeat([nothing], 4)...) +renderer = getRenderer(scene) triangle = defaultTriangle3D() -addObject!(scene, triangle) +addObject!(renderer, triangle) + +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 diff --git a/src/primitives/circle.jl b/src/primitives/circle.jl index 9e0be8d..04d0855 100644 --- a/src/primitives/circle.jl +++ b/src/primitives/circle.jl @@ -4,29 +4,26 @@ using WGPUCore export defaultCircle, WGPUCircle mutable struct WGPUCircle <: Renderable + radius + nSectors + gpuDevice + topology vertexData colorData indexData -end - -function defaultUniformData(::Type{WGPUCircle}) - uniformData = ones(Float32, (4, 4)) |> Diagonal |> Matrix - return uniformData -end - -function getUniformData(circle::WGPUCircle) - return defaultUniformData(WGPUCircle) -end - -function getUniformBuffer(gpuDevice, circle::WGPUCircle) - uniformData = defaultUniformData(WGPUCircle) - (uniformBuffer, _) = WGPUCore.createBufferWithData( - gpuDevice, - "uniformBuffer", - uniformData, - ["Uniform", "CopyDst"] - ) + normalData + uvData + uniformData uniformBuffer + indexBuffer + vertexBuffer + textureData + texture + textureView + sampler + pipelineLayouts + renderPipelines + cshaders end function generateCircle(nDivs, radius=1) @@ -45,8 +42,8 @@ function generateCircle(nDivs, radius=1) return (vertexData, indexData) end -function defaultCircle(nDivs=100, radius=1, color=[0.4, 0.3, 0.5, 1.0]) - (vertexData, indexData) = generateCircle(nDivs, radius) +function defaultCircle(nSectors=100, radius=1, color=[0.4, 0.3, 0.5, 1.0]) + (vertexData, indexData) = generateCircle(nSectors, radius) unitColor = cat([ color @@ -54,88 +51,40 @@ function defaultCircle(nDivs=100, radius=1, color=[0.4, 0.3, 0.5, 1.0]) colorData = repeat(unitColor, inner=(1, size(vertexData, 2))) - circle = Circle(vertexData, colorData, indexData) - return circle -end - - -function getVertexBuffer(gpuDevice, circle::WGPUCircle) - (vertexBuffer, _) = WGPUCore.createBufferWithData( - gpuDevice, - "vertexBuffer", - vcat([circle.vertexData, circle.colorData]...), - ["Vertex", "CopySrc"] - ) - vertexBuffer -end + indexData = cat([ + 1:size(vertexData, 1) |> collect + ]..., dims=2) .|> UInt32 + faceNormal = cat([ + repeat( + [0, 0, 1, 0], + size(vertexData, 1) + ) + ]..., dims=2) .|> Float32 -function getIndexBuffer(gpuDevice, circle::WGPUCircle) - (indexBuffer, _) = WGPUCore.createBufferWithData( - gpuDevice, - "indexBuffer", - circle.indexData |> flatten, - "Index" + # normalData = repeat(faceNormal, inner=(1, 3)) + + circle = WGPUCircle( + radius, + nSectors, + nothing, + "TriangleList", + vertexData, + colorData, + indexData, + nothing, #normalData + nothing, #uvData, + nothing, #uniformData, + nothing, #uniformBuffer, + nothing, #indexBuffer, + nothing, #vertexBuffer, + nothing, #textureData, + nothing, #texture, + nothing, #textureView, + nothing, #sampler, + Dict(), #pipelineLayout, + Dict(), #renderPipeline + Dict(), #cshader ) - indexBuffer -end - - -function getVertexBufferLayout(::Type{WGPUCircle}; offset = 0) - WGPUCore.GPUVertexBufferLayout => [ - :arrayStride => 8*4, - :stepMode => "Vertex", - :attributes => [ - :attribute => [ - :format => "Float32x4", - :offset => 0, - :shaderLocation => offset + 0 - ], - :attribute => [ - :format => "Float32x4", - :offset => 4*4, - :shaderLocation => offset + 1 - ] - ] - ] -end - - -function getBindingLayouts(::Type{WGPUCircle}; binding=0) - bindingLayouts = [ - WGPUCore.WGPUBufferEntry => [ - :binding => binding, - :visibility => ["Vertex", "Fragment"], - :type => "Uniform" - ], - ] - return bindingLayouts -end - - -function getBindings(::Type{WGPUCircle}, uniformBuffer; binding=0) - bindings = [ - WGPUCore.GPUBuffer => [ - :binding => binding, - :buffer => uniformBuffer, - :offset => 0, - :size => uniformBuffer.size - ], - ] -end - - -function getShaderCode(::Type{WGPUCircle}; binding=0) - shaderSource = quote - struct WGPUCircleUniform - transform::Mat4{Float32} - end - @var Uniform 0 $binding rLocals::@user WGPUCircleUniform - end - - return shaderSource -end - -function toMesh(::Type{WGPUCircle}) - + return circle end diff --git a/src/primitives/mesh.jl b/src/primitives/mesh.jl index d4836f9..c075e6c 100644 --- a/src/primitives/mesh.jl +++ b/src/primitives/mesh.jl @@ -102,7 +102,7 @@ function defaultWGPUMesh(path::String; scale::Union{Vector{Float32}, Float32} = textureView = nothing if image != "" - uvData = scale*reduce(hcat, meshdata.uvs[uIndices[:]]) .|> Float32 + uvData = reduce(hcat, meshdata.uvs[uIndices[:]]) .|> Float32 textureData = begin img = load(image) img = imresize(img, (256, 256)) # TODO hardcoded size diff --git a/src/primitives/plane.jl b/src/primitives/plane.jl index 59298e3..53f53ab 100644 --- a/src/primitives/plane.jl +++ b/src/primitives/plane.jl @@ -1,9 +1,9 @@ using WGPUNative using WGPUCore -export defaultPlane, Plane +export defaultPlane, WGPUPlane -mutable struct Plane <: Renderable +mutable struct WGPUPlane <: Renderable width height wSegments @@ -59,7 +59,7 @@ function defaultPlane(width=1, height=1, wSegments=2, hSegments=2, color=[0.6, 0 normalData = repeat(faceNormal, inner=(1, 3)) - Plane( + WGPUPlane( width, height, wSegments, diff --git a/src/renderableUI.jl b/src/renderableUI.jl index 8ee1f0f..f22bfbb 100644 --- a/src/renderableUI.jl +++ b/src/renderableUI.jl @@ -171,7 +171,6 @@ end function updateUniformBuffer(quad::RenderableUI) data = SMatrix{4, 4}(quad.uniformData[:]) - # @info :UniformBuffer data WGPUCore.writeBuffer( quad.gpuDevice.queue, getfield(quad, :uniformBuffer),