chorama 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.configs/tsconfig.lib.json +43 -0
- package/.configs/tsconfig.website.json +34 -0
- package/.github/workflows/static.yml +88 -0
- package/.vscode/launch.json +29 -0
- package/.vscode/tasks.json +19 -0
- package/README.md +127 -0
- package/assets/images/disappointed.jpg +0 -0
- package/assets/images/skybox/grimmnight_back.png +0 -0
- package/assets/images/skybox/grimmnight_bottom.png +0 -0
- package/assets/images/skybox/grimmnight_front.png +0 -0
- package/assets/images/skybox/grimmnight_left.png +0 -0
- package/assets/images/skybox/grimmnight_right.png +0 -0
- package/assets/images/skybox/grimmnight_top.png +0 -0
- package/assets/images/skybox/miramar_back.png +0 -0
- package/assets/images/skybox/miramar_bottom.png +0 -0
- package/assets/images/skybox/miramar_front.png +0 -0
- package/assets/images/skybox/miramar_left.png +0 -0
- package/assets/images/skybox/miramar_right.png +0 -0
- package/assets/images/skybox/miramar_top.png +0 -0
- package/assets/images/uv.jpg +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_GlassPlasticMat_BaseColor.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_GlassPlasticMat_Normal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_GlassPlasticMat_OcclusionRoughMetal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LeatherPartsMat_BaseColor.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LeatherPartsMat_Normal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LeatherPartsMat_OcclusionRoughMetal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LensesMat_BaseColor.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LensesMat_Normal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LensesMat_OcclusionRoughMetal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_MetalPartsMat_BaseColor.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_MetalPartsMat_Normal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_MetalPartsMat_OcclusionRoughMetal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_RubberWoodMat_BaseColor.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_RubberWoodMat_Normal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_RubberWoodMat_OcclusionRoughMetal.png +0 -0
- package/assets/models/gltf/flight_helmet/index.bin +0 -0
- package/assets/models/gltf/flight_helmet/index.gltf +705 -0
- package/assets/models/gltf/object.gltf +23 -0
- package/assets/models/gltf/pirate_girl/index.bin +0 -0
- package/assets/models/gltf/pirate_girl/index.gltf +2082 -0
- package/assets/models/obj/pirate_girl/pirate_girl.obj +18459 -0
- package/assets/models/obj/pirate_girl/pirate_girl.png +0 -0
- package/astro.config.mjs +45 -0
- package/content/guide/api-map.md +89 -0
- package/content/guide/camera-and-controls.md +98 -0
- package/content/guide/first-scene.md +176 -0
- package/content/guide/index.md +72 -0
- package/content/guide/installation.md +179 -0
- package/content/guide/materials-and-lighting.md +138 -0
- package/content/guide/plugins-and-render-pipeline.md +124 -0
- package/content/guide/render-targets-and-views.md +147 -0
- package/content/guide/scene-graph-and-transforms.md +113 -0
- package/content/guide/textures-and-assets.md +120 -0
- package/content/guide/troubleshooting.md +49 -0
- package/env.d.ts +19 -0
- package/examples/addons/rendergraph_gui.js +580 -0
- package/examples/camera/orthographic.js +120 -0
- package/examples/camera/perspective.js +138 -0
- package/examples/lights/directional.js +397 -0
- package/examples/lights/multiple_spot_lights.js +304 -0
- package/examples/lights/point.js +337 -0
- package/examples/lights/spot.js +366 -0
- package/examples/loader/gltf_material.js +111 -0
- package/examples/loader/gltfloader.js +78 -0
- package/examples/loader/objloader.js +95 -0
- package/examples/material/cullface.js +111 -0
- package/examples/material/materials.js +126 -0
- package/examples/material/standard/basic.js +164 -0
- package/examples/mesh/circle.js +117 -0
- package/examples/mesh/cuboid.js +151 -0
- package/examples/mesh/cylinder.js +139 -0
- package/examples/mesh/geometries.js +108 -0
- package/examples/mesh/meshTopology.js +103 -0
- package/examples/mesh/plane.js +117 -0
- package/examples/mesh/skinning.js +136 -0
- package/examples/mesh/uvsphere.js +113 -0
- package/examples/other/rotatingCube.js +93 -0
- package/examples/other/rotatingSphere.js +96 -0
- package/examples/rendertarget/basic_canvas.js +130 -0
- package/examples/rendertarget/depth_texture.js +130 -0
- package/examples/rendertarget/image_target.js +140 -0
- package/examples/rendertarget/multiple_views.js +158 -0
- package/examples/rendertarget/render_masks.js +173 -0
- package/examples/rendertarget/split_screen.js +123 -0
- package/examples/rendertarget/split_view.js +137 -0
- package/examples/skybox/skybox.js +111 -0
- package/examples/texture/arrays.js +156 -0
- package/examples/texture/textureWrap.js +118 -0
- package/examples/transform/propagation.js +92 -0
- package/package.json +55 -0
- package/rollup.config.js +66 -0
- package/scripts/stage-chorama.mjs +29 -0
- package/src/caches/cache.js +420 -0
- package/src/caches/index.js +2 -0
- package/src/caches/uniformbuffers.js +104 -0
- package/src/cameracontrols/index.js +258 -0
- package/src/constants/index.js +3 -0
- package/src/constants/mesh.js +197 -0
- package/src/constants/others.js +218 -0
- package/src/constants/texture.js +183 -0
- package/src/core/constants.js +14 -0
- package/src/core/extensions.js +42 -0
- package/src/core/index.js +7 -0
- package/src/core/layouts/index.js +4 -0
- package/src/core/layouts/meshvertex.js +60 -0
- package/src/core/layouts/uniform.js +21 -0
- package/src/core/layouts/uniformbuffer.js +15 -0
- package/src/core/layouts/vertexbuffer.js +43 -0
- package/src/core/limits.js +247 -0
- package/src/core/resources/blendparams.js +89 -0
- package/src/core/resources/framebuffer.js +127 -0
- package/src/core/resources/gpubuffer.js +32 -0
- package/src/core/resources/gpumesh.js +43 -0
- package/src/core/resources/gputexture.js +73 -0
- package/src/core/resources/index.js +5 -0
- package/src/core/shader.js +62 -0
- package/src/core/webgl/bindgroup.js +89 -0
- package/src/core/webgl/descriptors.js +104 -0
- package/src/core/webgl/index.js +5 -0
- package/src/core/webgl/renderpassencoder.js +96 -0
- package/src/core/webgl/renderpipeline.js +54 -0
- package/src/core/webgl/utils.js +371 -0
- package/src/core/webgl/webglrenderdevice.js +235 -0
- package/src/function.js +358 -0
- package/src/index.js +15 -0
- package/src/loader/gltf.js +2172 -0
- package/src/loader/index.js +3 -0
- package/src/loader/loader.js +174 -0
- package/src/loader/obj.js +188 -0
- package/src/loader/texture.js +85 -0
- package/src/loader/utils.js +16 -0
- package/src/material/basic.js +75 -0
- package/src/material/depth.js +73 -0
- package/src/material/index.js +8 -0
- package/src/material/lambert.js +73 -0
- package/src/material/material.js +106 -0
- package/src/material/normal.js +30 -0
- package/src/material/phong.js +86 -0
- package/src/material/raw.js +52 -0
- package/src/material/standard.js +221 -0
- package/src/math/index.js +3 -0
- package/src/math/transform.js +38 -0
- package/src/mesh/attribute/attribute.js +79 -0
- package/src/mesh/attribute/index.js +1 -0
- package/src/mesh/attributedata/index.js +1 -0
- package/src/mesh/attributedata/separate.js +180 -0
- package/src/mesh/builders/base.js +41 -0
- package/src/mesh/builders/circle.js +63 -0
- package/src/mesh/builders/cuboid.js +135 -0
- package/src/mesh/builders/cylinder.js +131 -0
- package/src/mesh/builders/index.js +7 -0
- package/src/mesh/builders/plane.js +73 -0
- package/src/mesh/builders/utils.js +20 -0
- package/src/mesh/builders/uvsphere.js +80 -0
- package/src/mesh/builders/wireframe.js +62 -0
- package/src/mesh/index.js +4 -0
- package/src/mesh/mesh.js +149 -0
- package/src/objects/bone.js +17 -0
- package/src/objects/camera/camera.js +56 -0
- package/src/objects/camera/index.js +2 -0
- package/src/objects/camera/projection.js +203 -0
- package/src/objects/debug/index.js +1 -0
- package/src/objects/debug/skeleton.js +28 -0
- package/src/objects/index.js +7 -0
- package/src/objects/light/ambient.js +20 -0
- package/src/objects/light/directional.js +29 -0
- package/src/objects/light/index.js +5 -0
- package/src/objects/light/point.js +32 -0
- package/src/objects/light/shadow/index.js +1 -0
- package/src/objects/light/shadow/shadow.js +67 -0
- package/src/objects/light/spot.js +56 -0
- package/src/objects/mesh.js +141 -0
- package/src/objects/object3d.js +167 -0
- package/src/objects/skybox.js +38 -0
- package/src/plugins/camera/camera.js +19 -0
- package/src/plugins/camera/index.js +2 -0
- package/src/plugins/camera/nodes/cameraview.js +46 -0
- package/src/plugins/camera/nodes/index.js +2 -0
- package/src/plugins/camera/nodes/opaquepass.js +79 -0
- package/src/plugins/index.js +6 -0
- package/src/plugins/light/index.js +2 -0
- package/src/plugins/light/light.js +23 -0
- package/src/plugins/light/nodes/index.js +1 -0
- package/src/plugins/light/nodes/light.js +127 -0
- package/src/plugins/meshmaterial/index.js +3 -0
- package/src/plugins/meshmaterial/meshmaterial.js +381 -0
- package/src/plugins/meshmaterial/nodes/index.js +1 -0
- package/src/plugins/meshmaterial/nodes/meshmaterial.js +50 -0
- package/src/plugins/meshmaterial/resources/index.js +1 -0
- package/src/plugins/meshmaterial/resources/meshmaterialpipelines.js +50 -0
- package/src/plugins/shadow/index.js +3 -0
- package/src/plugins/shadow/nodes/index.js +3 -0
- package/src/plugins/shadow/nodes/shadow.js +272 -0
- package/src/plugins/shadow/nodes/shadowOccluder.js +112 -0
- package/src/plugins/shadow/nodes/shadowOpaquePass.js +73 -0
- package/src/plugins/shadow/resources/ShadowMap.js +99 -0
- package/src/plugins/shadow/resources/index.js +2 -0
- package/src/plugins/shadow/resources/shadowpipelines.js +25 -0
- package/src/plugins/shadow/shadow.js +31 -0
- package/src/plugins/skeletonhelper/index.js +1 -0
- package/src/plugins/skeletonhelper/skeletonhelper.js +160 -0
- package/src/plugins/skybox/index.js +3 -0
- package/src/plugins/skybox/nodes/index.js +1 -0
- package/src/plugins/skybox/nodes/skybox.js +143 -0
- package/src/plugins/skybox/resources/index.js +2 -0
- package/src/plugins/skybox/resources/skyboxmesh.js +14 -0
- package/src/plugins/skybox/resources/skyboxpipeline.js +6 -0
- package/src/plugins/skybox/skybox.js +137 -0
- package/src/renderer/core/index.js +179 -0
- package/src/renderer/graph/index.js +3 -0
- package/src/renderer/graph/nodes.js +34 -0
- package/src/renderer/graph/rendergraph.js +182 -0
- package/src/renderer/index.js +5 -0
- package/src/renderer/plugin.js +36 -0
- package/src/renderer/renderer.js +179 -0
- package/src/renderer/views.js +28 -0
- package/src/rendertarget/canvastarget.js +30 -0
- package/src/rendertarget/image.js +132 -0
- package/src/rendertarget/index.js +3 -0
- package/src/rendertarget/rendertarget.js +89 -0
- package/src/shader/basicFragment.glsl +30 -0
- package/src/shader/basicVertex.glsl +87 -0
- package/src/shader/common/color.glsl +7 -0
- package/src/shader/common/common.glsl +25 -0
- package/src/shader/common/index.js +4 -0
- package/src/shader/common/light.glsl +437 -0
- package/src/shader/common/math.glsl +12 -0
- package/src/shader/debug/index.js +2 -0
- package/src/shader/debug/skeletonFragment.glsl +8 -0
- package/src/shader/debug/skeletonVertex.glsl +27 -0
- package/src/shader/depthFragment.glsl +37 -0
- package/src/shader/index.js +11 -0
- package/src/shader/lambertFragment.glsl +126 -0
- package/src/shader/normalFragment.glsl +25 -0
- package/src/shader/phongFragment.glsl +140 -0
- package/src/shader/skyboxFragment.glsl +16 -0
- package/src/shader/skyboxVertex.glsl +20 -0
- package/src/shader/standardFragment.glsl +274 -0
- package/src/texture/index.js +2 -0
- package/src/texture/sampler.js +111 -0
- package/src/texture/texture.js +234 -0
- package/src/utils/index.js +115 -0
- package/tsconfig.json +11 -0
- package/website/config/index.ts +1 -0
- package/website/config/navigation.ts +53 -0
- package/website/content.config.ts +92 -0
- package/website/layouts/DocLayout.astro +501 -0
- package/website/layouts/Example.astro +91 -0
- package/website/pages/examples/[...slug].astro +77 -0
- package/website/pages/examples/index.astro +98 -0
- package/website/pages/examples/samples/[...slug].astro +17 -0
- package/website/pages/guide/[slug].astro +30 -0
- package/website/pages/guide/index.astro +21 -0
- package/website/pages/index.astro +9 -0
- package/website/plugins/remark-link-base.js +23 -0
- package/website/utils/url.ts +30 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { BlendEquation, BlendMode } from "../../constants/index.js"
|
|
2
|
+
|
|
3
|
+
export class BlendParams {
|
|
4
|
+
/**
|
|
5
|
+
* @type {BlendEquation}
|
|
6
|
+
*/
|
|
7
|
+
operation
|
|
8
|
+
/**
|
|
9
|
+
* @type {BlendMode}
|
|
10
|
+
*/
|
|
11
|
+
source
|
|
12
|
+
/**
|
|
13
|
+
* @type {BlendMode}
|
|
14
|
+
*/
|
|
15
|
+
destination
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {BlendEquation} operation
|
|
19
|
+
* @param {BlendMode} source
|
|
20
|
+
* @param {BlendMode} destination
|
|
21
|
+
*/
|
|
22
|
+
constructor(operation, source, destination) {
|
|
23
|
+
this.operation = operation
|
|
24
|
+
this.source = source
|
|
25
|
+
this.destination = destination
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
clone() {
|
|
29
|
+
return new BlendParams(
|
|
30
|
+
this.operation,
|
|
31
|
+
this.source,
|
|
32
|
+
this.destination,
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static Opaque = Object.freeze(new BlendParams(
|
|
37
|
+
BlendEquation.Add,
|
|
38
|
+
BlendMode.One,
|
|
39
|
+
BlendMode.Zero
|
|
40
|
+
))
|
|
41
|
+
|
|
42
|
+
static AlphaBlend = Object.freeze(new BlendParams(
|
|
43
|
+
BlendEquation.Add,
|
|
44
|
+
BlendMode.SrcAlpha,
|
|
45
|
+
BlendMode.OneMinusSrcAlpha,
|
|
46
|
+
))
|
|
47
|
+
|
|
48
|
+
static PremultiplyAlpha = Object.freeze(new BlendParams(
|
|
49
|
+
BlendEquation.Add,
|
|
50
|
+
BlendMode.One,
|
|
51
|
+
BlendMode.OneMinusSrcAlpha,
|
|
52
|
+
))
|
|
53
|
+
|
|
54
|
+
static AdditiveAlpha = Object.freeze(new BlendParams(
|
|
55
|
+
BlendEquation.Add,
|
|
56
|
+
BlendMode.SrcAlpha,
|
|
57
|
+
BlendMode.One,
|
|
58
|
+
))
|
|
59
|
+
|
|
60
|
+
static AdditiveColor = Object.freeze(new BlendParams(
|
|
61
|
+
BlendEquation.Add,
|
|
62
|
+
BlendMode.One,
|
|
63
|
+
BlendMode.One,
|
|
64
|
+
))
|
|
65
|
+
|
|
66
|
+
static Multiply = Object.freeze(new BlendParams(
|
|
67
|
+
BlendEquation.Add,
|
|
68
|
+
BlendMode.DstColor,
|
|
69
|
+
BlendMode.Zero,
|
|
70
|
+
))
|
|
71
|
+
|
|
72
|
+
static Screen = Object.freeze(new BlendParams(
|
|
73
|
+
BlendEquation.Add,
|
|
74
|
+
BlendMode.OneMinusDstColor,
|
|
75
|
+
BlendMode.One,
|
|
76
|
+
))
|
|
77
|
+
|
|
78
|
+
static Min = Object.freeze(new BlendParams(
|
|
79
|
+
BlendEquation.Min,
|
|
80
|
+
BlendMode.One,
|
|
81
|
+
BlendMode.One,
|
|
82
|
+
))
|
|
83
|
+
|
|
84
|
+
static Max = Object.freeze(new BlendParams(
|
|
85
|
+
BlendEquation.Max,
|
|
86
|
+
BlendMode.One,
|
|
87
|
+
BlendMode.One,
|
|
88
|
+
))
|
|
89
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { hasDepthComponent, hasStencilComponent } from "../../constants/texture.js"
|
|
2
|
+
import { Color } from "../../math/index.js"
|
|
3
|
+
import { ViewRectangle } from "../../utils/index.js"
|
|
4
|
+
import { GPUTexture } from "./gputexture.js"
|
|
5
|
+
|
|
6
|
+
export class FrameBuffer {
|
|
7
|
+
/**
|
|
8
|
+
* @type {number}
|
|
9
|
+
*/
|
|
10
|
+
width
|
|
11
|
+
/**
|
|
12
|
+
* @type {number}
|
|
13
|
+
*/
|
|
14
|
+
height
|
|
15
|
+
/**
|
|
16
|
+
* @type {WebGLFramebuffer | null}
|
|
17
|
+
*/
|
|
18
|
+
buffer
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @type {GPUTexture[]}
|
|
22
|
+
*/
|
|
23
|
+
colorAttachments
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @type {GLenum[]}
|
|
27
|
+
*/
|
|
28
|
+
drawBuffers
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @type {GPUTexture | undefined}
|
|
32
|
+
*/
|
|
33
|
+
depthBuffer
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param {WebGLFramebuffer | null} frameBuffer
|
|
37
|
+
* @param {GPUTexture[]} colorAttachments
|
|
38
|
+
* @param {GLenum[]} drawBuffers
|
|
39
|
+
* @param {GPUTexture | undefined} depthBuffer
|
|
40
|
+
* @param {number} width
|
|
41
|
+
* @param {number} height
|
|
42
|
+
*/
|
|
43
|
+
constructor(frameBuffer, colorAttachments, drawBuffers, depthBuffer, width, height) {
|
|
44
|
+
this.buffer = frameBuffer
|
|
45
|
+
this.colorAttachments = colorAttachments
|
|
46
|
+
this.depthBuffer = depthBuffer
|
|
47
|
+
this.drawBuffers = drawBuffers
|
|
48
|
+
this.width = width
|
|
49
|
+
this.height = height
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @param {WebGL2RenderingContext} context
|
|
54
|
+
* @param {Color | undefined} clearColor
|
|
55
|
+
* @param {number | undefined} clearDepth
|
|
56
|
+
* @param {number | undefined} clearStencil
|
|
57
|
+
*/
|
|
58
|
+
clear(context, clearColor, clearDepth, clearStencil) {
|
|
59
|
+
let bit = 0
|
|
60
|
+
context.stencilMask(0xFF);
|
|
61
|
+
|
|
62
|
+
if (clearColor) {
|
|
63
|
+
const { r, g, b, a } = clearColor
|
|
64
|
+
bit |= context.COLOR_BUFFER_BIT
|
|
65
|
+
context.colorMask(true, true, true, true)
|
|
66
|
+
context.clearColor(r, g, b, a)
|
|
67
|
+
}
|
|
68
|
+
if (clearDepth !== undefined) {
|
|
69
|
+
bit |= context.DEPTH_BUFFER_BIT
|
|
70
|
+
context.depthRange(0, 1)
|
|
71
|
+
context.depthMask(true)
|
|
72
|
+
context.clearDepth(clearDepth)
|
|
73
|
+
}
|
|
74
|
+
if (clearStencil !== undefined) {
|
|
75
|
+
bit |= context.STENCIL_BUFFER_BIT
|
|
76
|
+
context.stencilMask(0xFF)
|
|
77
|
+
context.clearStencil(clearStencil)
|
|
78
|
+
}
|
|
79
|
+
context.clear(bit)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @param {WebGL2RenderingContext} context
|
|
84
|
+
* @param {ViewRectangle} viewport
|
|
85
|
+
* @param {ViewRectangle} scissors
|
|
86
|
+
*/
|
|
87
|
+
setViewport(context, viewport, scissors) {
|
|
88
|
+
const { width, height } = this
|
|
89
|
+
|
|
90
|
+
context.bindFramebuffer(context.FRAMEBUFFER, this.buffer)
|
|
91
|
+
context.drawBuffers(this.drawBuffers)
|
|
92
|
+
context.enable(context.SCISSOR_TEST)
|
|
93
|
+
context.scissor(
|
|
94
|
+
scissors.offset.x * width,
|
|
95
|
+
scissors.offset.y * height,
|
|
96
|
+
scissors.size.x * width,
|
|
97
|
+
scissors.size.y * height
|
|
98
|
+
)
|
|
99
|
+
context.viewport(
|
|
100
|
+
viewport.offset.x * width,
|
|
101
|
+
viewport.offset.y * height,
|
|
102
|
+
viewport.size.x * width,
|
|
103
|
+
viewport.size.y * height
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
if(this.buffer){
|
|
107
|
+
if(this.depthBuffer){
|
|
108
|
+
if(hasDepthComponent(this.depthBuffer.actualFormat)){
|
|
109
|
+
context.enable(WebGL2RenderingContext.DEPTH_TEST)
|
|
110
|
+
} else {
|
|
111
|
+
context.disable(WebGL2RenderingContext.DEPTH_TEST)
|
|
112
|
+
}
|
|
113
|
+
if(hasStencilComponent(this.depthBuffer.actualFormat)){
|
|
114
|
+
context.enable(WebGL2RenderingContext.STENCIL_TEST)
|
|
115
|
+
}else {
|
|
116
|
+
context.disable(WebGL2RenderingContext.STENCIL_TEST)
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
context.disable(WebGL2RenderingContext.DEPTH_TEST)
|
|
120
|
+
context.disable(WebGL2RenderingContext.STENCIL_TEST)
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
context.enable(WebGL2RenderingContext.DEPTH_TEST)
|
|
124
|
+
context.enable(WebGL2RenderingContext.STENCIL_TEST)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { BufferType } from "../../constants/index.js"
|
|
2
|
+
|
|
3
|
+
export class GPUBuffer {
|
|
4
|
+
/**
|
|
5
|
+
* @readonly
|
|
6
|
+
* @type {WebGLBuffer}
|
|
7
|
+
*/
|
|
8
|
+
inner
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @readonly
|
|
12
|
+
* @type {BufferType}
|
|
13
|
+
*/
|
|
14
|
+
type
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @readonly
|
|
18
|
+
* @type {number}
|
|
19
|
+
*/
|
|
20
|
+
size
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {WebGLBuffer} buffer
|
|
24
|
+
* @param {number} type
|
|
25
|
+
* @param {number} size
|
|
26
|
+
*/
|
|
27
|
+
constructor(buffer, type, size) {
|
|
28
|
+
this.inner = buffer
|
|
29
|
+
this.type = type
|
|
30
|
+
this.size = size
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export class GPUMesh {
|
|
2
|
+
/**
|
|
3
|
+
* @readonly
|
|
4
|
+
* @type {WebGLVertexArrayObject}
|
|
5
|
+
*/
|
|
6
|
+
inner
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @type {WebGLBuffer[]}
|
|
10
|
+
*/
|
|
11
|
+
attributeBuffers = []
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @type {WebGLBuffer | undefined}
|
|
15
|
+
*/
|
|
16
|
+
indexBuffer
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @type {GLenum | undefined}
|
|
20
|
+
*/
|
|
21
|
+
indexType
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @type {number}
|
|
25
|
+
*/
|
|
26
|
+
count
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @type {number}
|
|
30
|
+
*/
|
|
31
|
+
layoutHash
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param {WebGLVertexArrayObject} vao
|
|
35
|
+
* @param {number} count
|
|
36
|
+
* @param {number} layoutHash
|
|
37
|
+
*/
|
|
38
|
+
constructor(vao, count, layoutHash) {
|
|
39
|
+
this.inner = vao
|
|
40
|
+
this.count = count
|
|
41
|
+
this.layoutHash = layoutHash
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { TextureFormat, TextureType } from "../../constants/index.js"
|
|
2
|
+
import { WebGLTextureFormat } from "../../function.js"
|
|
3
|
+
|
|
4
|
+
export class GPUTexture {
|
|
5
|
+
/**
|
|
6
|
+
* @readonly
|
|
7
|
+
* @type {WebGLTexture}
|
|
8
|
+
*/
|
|
9
|
+
inner
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @readonly
|
|
13
|
+
* @type {TextureType}
|
|
14
|
+
*/
|
|
15
|
+
type
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @readonly
|
|
19
|
+
* @type {number}
|
|
20
|
+
*/
|
|
21
|
+
width
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @readonly
|
|
25
|
+
* @type {number}
|
|
26
|
+
*/
|
|
27
|
+
height
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @readonly
|
|
31
|
+
* @type {number}
|
|
32
|
+
*/
|
|
33
|
+
depth
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @readonly
|
|
37
|
+
* @type {WebGLTextureFormat}
|
|
38
|
+
*/
|
|
39
|
+
format
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @readonly
|
|
43
|
+
* @type {TextureFormat}
|
|
44
|
+
*/
|
|
45
|
+
actualFormat
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @readonly
|
|
49
|
+
* @type {number}
|
|
50
|
+
*/
|
|
51
|
+
pixelSize
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @param {WebGLTexture} texture
|
|
55
|
+
* @param {TextureType} type
|
|
56
|
+
* @param {WebGLTextureFormat} format
|
|
57
|
+
* @param {TextureFormat} actualFormat
|
|
58
|
+
* @param {number} width
|
|
59
|
+
* @param {number} height
|
|
60
|
+
* @param {number} depth
|
|
61
|
+
* @param {number} pixelSize
|
|
62
|
+
*/
|
|
63
|
+
constructor(texture, type, format, actualFormat, width, height, depth, pixelSize){
|
|
64
|
+
this.inner = texture
|
|
65
|
+
this.type = type
|
|
66
|
+
this.format = format
|
|
67
|
+
this.width = width
|
|
68
|
+
this.height = height
|
|
69
|
+
this.depth = depth
|
|
70
|
+
this.pixelSize = pixelSize
|
|
71
|
+
this.actualFormat = actualFormat
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export class Shader {
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @readonly
|
|
5
|
+
* @type {string}
|
|
6
|
+
*/
|
|
7
|
+
source
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @type {Map<string,string>}
|
|
11
|
+
*/
|
|
12
|
+
includes = new Map()
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @type {Map<string,string>}
|
|
16
|
+
*/
|
|
17
|
+
defines = new Map()
|
|
18
|
+
/**
|
|
19
|
+
* @param {ShaderModuleDescriptor} descriptor
|
|
20
|
+
*/
|
|
21
|
+
constructor({ source }) {
|
|
22
|
+
this.source = source
|
|
23
|
+
this.defines = new Map()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @returns {string}
|
|
28
|
+
*/
|
|
29
|
+
compile() {
|
|
30
|
+
const { source, defines, includes } = this
|
|
31
|
+
return preprocessShader(source, includes, defines)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @typedef ShaderModuleDescriptor
|
|
37
|
+
* @property {string} source
|
|
38
|
+
* @property {Map<string,string>} [defines]
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
// TODO: Maybe add error as a return type when something unexpected happens
|
|
42
|
+
// e.g when an include in the shader does not exist.
|
|
43
|
+
/**
|
|
44
|
+
* @param {string} source
|
|
45
|
+
* @param {ReadonlyMap<string,string>} includes
|
|
46
|
+
* @param {ReadonlyMap<string,string>} defines
|
|
47
|
+
* @returns {string}
|
|
48
|
+
*/
|
|
49
|
+
function preprocessShader(source, includes, defines) {
|
|
50
|
+
const version = "#version 300 es\n"
|
|
51
|
+
const mergedDefines = [...defines.entries()]
|
|
52
|
+
.map(([name, value]) => `#define ${name} ${value}`)
|
|
53
|
+
.join("\n")
|
|
54
|
+
const preprocessed = source.replace(/#include <(.*?)>/g, (_, name) => {
|
|
55
|
+
const include = includes.get(name)
|
|
56
|
+
if (!include) {
|
|
57
|
+
console.error(`Could not find the include "${name}"`)
|
|
58
|
+
}
|
|
59
|
+
return include || ""
|
|
60
|
+
})
|
|
61
|
+
return version + mergedDefines + "\n" + preprocessed
|
|
62
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/** @import { WebGLBindGroupDescriptor, WebGLBindGroupEntry, WebGLBindGroupLayoutDescriptor, WebGLBindGroupLayoutEntry } from "./descriptors.js" */
|
|
2
|
+
import { assert } from "../../utils/index.js"
|
|
3
|
+
|
|
4
|
+
export class WebGLBindGroupLayout {
|
|
5
|
+
/**
|
|
6
|
+
* @readonly
|
|
7
|
+
* @type {string | undefined}
|
|
8
|
+
*/
|
|
9
|
+
label
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @readonly
|
|
13
|
+
* @type {readonly WebGLBindGroupLayoutEntry[]}
|
|
14
|
+
*/
|
|
15
|
+
entries
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @private
|
|
19
|
+
* @type {Map<number, WebGLBindGroupLayoutEntry>}
|
|
20
|
+
*/
|
|
21
|
+
entryMap = new Map()
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param {WebGLBindGroupLayoutDescriptor} descriptor
|
|
25
|
+
*/
|
|
26
|
+
constructor({ label, entries }) {
|
|
27
|
+
this.label = label
|
|
28
|
+
this.entries = [...entries]
|
|
29
|
+
|
|
30
|
+
for (const entry of entries) {
|
|
31
|
+
assert(!this.entryMap.has(entry.binding) ? {} : undefined, `Duplicate bind group layout binding ${entry.binding}`)
|
|
32
|
+
this.entryMap.set(entry.binding, entry)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {number} binding
|
|
38
|
+
*/
|
|
39
|
+
getEntry(binding) {
|
|
40
|
+
return this.entryMap.get(binding)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class WebGLBindGroup {
|
|
45
|
+
/**
|
|
46
|
+
* @readonly
|
|
47
|
+
* @type {string | undefined}
|
|
48
|
+
*/
|
|
49
|
+
label
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @readonly
|
|
53
|
+
* @type {WebGLBindGroupLayout}
|
|
54
|
+
*/
|
|
55
|
+
layout
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @readonly
|
|
59
|
+
* @type {readonly WebGLBindGroupEntry[]}
|
|
60
|
+
*/
|
|
61
|
+
entries
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @private
|
|
65
|
+
* @type {Map<number, WebGLBindGroupEntry>}
|
|
66
|
+
*/
|
|
67
|
+
entryMap = new Map()
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @param {WebGLBindGroupDescriptor} descriptor
|
|
71
|
+
*/
|
|
72
|
+
constructor({ label, layout, entries }) {
|
|
73
|
+
this.label = label
|
|
74
|
+
this.layout = layout
|
|
75
|
+
this.entries = [...entries]
|
|
76
|
+
|
|
77
|
+
for (const entry of entries) {
|
|
78
|
+
assert(!this.entryMap.has(entry.binding) ? {} : undefined, `Duplicate bind group binding ${entry.binding}`)
|
|
79
|
+
this.entryMap.set(entry.binding, entry)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @param {number} binding
|
|
85
|
+
*/
|
|
86
|
+
getEntry(binding) {
|
|
87
|
+
return this.entryMap.get(binding)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { BufferUsage, BufferType, TextureType, TextureFormat, CullFace, FrontFaceDirection, PrimitiveTopology } from "../../constants/index.js";
|
|
2
|
+
import { Vector3 } from "../../math/index.js";
|
|
3
|
+
import { CompareFunction } from "../constants.js";
|
|
4
|
+
import { MeshVertexLayout } from "../layouts/index.js";
|
|
5
|
+
import { BlendParams, GPUTexture } from "../resources/index.js";
|
|
6
|
+
import { Shader } from "../shader.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @typedef WebGLBindGroupLayoutDescriptor
|
|
10
|
+
* @property {string} [label]
|
|
11
|
+
* @property {WebGLBindGroupLayoutEntry[]} entries
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @typedef WebGLBindGroupLayoutEntry
|
|
16
|
+
* @property {number} binding
|
|
17
|
+
* @property {number} visibility
|
|
18
|
+
* @property {WebGLBufferBindingLayout} [buffer]
|
|
19
|
+
* @property {WebGLSamplerBindingLayout} [sampler]
|
|
20
|
+
* @property {WebGLTextureBindingLayout} [texture]
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @typedef WebGLBufferBindingLayout
|
|
25
|
+
* @property {"uniform"} [type]
|
|
26
|
+
* @property {boolean} [hasDynamicOffset]
|
|
27
|
+
* @property {number} [minBindingSize]
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @typedef WebGLSamplerBindingLayout
|
|
32
|
+
* @property {"filtering" | "non-filtering" | "comparison"} [type]
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @typedef WebGLTextureBindingLayout
|
|
37
|
+
* @property {"float" | "unfilterable-float" | "depth" | "sint" | "uint"} [sampleType]
|
|
38
|
+
* @property {"1d" | "2d" | "2d-array" | "cube" | "cube-array" | "3d"} [viewDimension]
|
|
39
|
+
* @property {boolean} [multisampled]
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @typedef WebGLBindGroupDescriptor
|
|
44
|
+
* @property {string} [label]
|
|
45
|
+
* @property {import("./bindgroup.js").WebGLBindGroupLayout} layout
|
|
46
|
+
* @property {WebGLBindGroupEntry[]} entries
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @typedef WebGLBindGroupEntry
|
|
51
|
+
* @property {number} binding
|
|
52
|
+
* @property {any} resource
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @typedef WebGLBufferDescriptor
|
|
57
|
+
* @property {number} size
|
|
58
|
+
* @property {BufferUsage} usage
|
|
59
|
+
* @property {BufferType} type
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @typedef WebGLTextureDescriptor
|
|
64
|
+
* @property {TextureType} type
|
|
65
|
+
* @property {TextureFormat} format
|
|
66
|
+
* @property {number} width
|
|
67
|
+
* @property {number} height
|
|
68
|
+
* @property {number} [depth = 1]
|
|
69
|
+
* @property {number} [mipmapCount = 1]
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @typedef WebGLWriteTextureDescriptor
|
|
74
|
+
* @property {GPUTexture} texture
|
|
75
|
+
* @property {ArrayBufferLike} data
|
|
76
|
+
* @property {number} [mipmapLevel]
|
|
77
|
+
* @property {Vector3} [offset]
|
|
78
|
+
* @property {Vector3} [size]
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @typedef WebGLRenderPipelineDescriptor
|
|
83
|
+
* @property {Shader} vertex
|
|
84
|
+
* @property {{ source: Shader, targets:RenderTargetDescriptor[]}} [fragment]
|
|
85
|
+
* @property {MeshVertexLayout} vertexLayout
|
|
86
|
+
* @property {PrimitiveTopology} topology
|
|
87
|
+
* @property {CullFace} [cullFace]
|
|
88
|
+
* @property {boolean} [depthWrite]
|
|
89
|
+
* @property {CompareFunction} [depthCompare]
|
|
90
|
+
* @property {FrontFaceDirection} [frontFace]
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @typedef RenderTargetDescriptor
|
|
95
|
+
* @property {TextureFormat} format
|
|
96
|
+
* @property {BlendDescriptor} [blend]
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @typedef BlendDescriptor
|
|
101
|
+
* @property {BlendParams} color
|
|
102
|
+
* @property {BlendParams} alpha
|
|
103
|
+
*/
|
|
104
|
+
export default {}
|