ris-framework 0.1.0-dev.4
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/CHANGELOG.md +5 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/dist/assets/_ris-ktx2-node-module-stub-DwDS30PT.js +1 -0
- package/dist/assets/cat.jpg +0 -0
- package/dist/assets/index-BmeGit54.css +1 -0
- package/dist/assets/index-qyn4pzGw.js +151 -0
- package/dist/assets/libktx-Cjh8w7XG-Ci1Fm_MH.js +1 -0
- package/dist/assets/test.png +0 -0
- package/dist/index.html +16 -0
- package/dist/vite.svg +1 -0
- package/package.json +37 -0
- package/shaders/glsl/inspect_texture_mips_fs.glsl +18 -0
- package/shaders/glsl/inspect_texture_mips_vs.glsl +25 -0
- package/shaders/glsl/main_render_target_flip_y_fs.glsl +9 -0
- package/shaders/glsl/main_render_target_flip_y_vs.glsl +9 -0
- package/shaders/glsl/sprite_fs.glsl +14 -0
- package/shaders/glsl/sprite_vs.glsl +20 -0
- package/shaders/glsl/unlit_material_fs.glsl +19 -0
- package/shaders/glsl/unlit_material_vs.glsl +25 -0
- package/src/TextureFormat.ts +0 -0
- package/src/VertexFormat.ts +17 -0
- package/src/common/sampler-enums.ts +21 -0
- package/src/common/vertex-step-mode.ts +12 -0
- package/src/content/ShaderModuleContent.ts +47 -0
- package/src/core/Framework.ts +240 -0
- package/src/core/FrameworkConfig.ts +31 -0
- package/src/core/buffers/buffers-factory-interface.ts +0 -0
- package/src/core/buffers/vertex-buffer-interface.ts +0 -0
- package/src/core/content/ContentManager.ts +86 -0
- package/src/core/dependency-injection/register-services-interface.ts +15 -0
- package/src/core/framework-interface.ts +0 -0
- package/src/core/input/InputManager.ts +115 -0
- package/src/core/renderer/enums.ts +20 -0
- package/src/core/renderer/renderer-interface.ts +92 -0
- package/src/core/renderer/rendering-limits.ts +20 -0
- package/src/core/rendering/AGraphicsDevice.ts +119 -0
- package/src/core/rendering/ARenderer.ts +247 -0
- package/src/core/rendering/blending/blend-component-descriptor.ts +33 -0
- package/src/core/rendering/blending/blend-state-descriptor.ts +51 -0
- package/src/core/rendering/blending/enums.ts +50 -0
- package/src/core/rendering/enums.ts +22 -0
- package/src/core/rendering/primitive/PrimitiveStateDescriptor.ts +32 -0
- package/src/core/rendering/primitive/enums.ts +68 -0
- package/src/core/rendering/render-pass/render-pass-descriptor.ts +0 -0
- package/src/core/rendering/render-pass/render-pass-interface.ts +17 -0
- package/src/core/rendering/sampler/sampler-descriptor.ts +33 -0
- package/src/core/rendering/texture/texture.ts +146 -0
- package/src/core/rendering/vertex-attribute.ts +20 -0
- package/src/core/rendering/vertex-buffer-layout.ts +84 -0
- package/src/core/shader/shader-loader.ts +27 -0
- package/src/core/shader/shader-module-interface.ts +1 -0
- package/src/core/sprite-batch/SpriteBatch.ts +216 -0
- package/src/core/sprite-batch/SpriteBatchDrawable.ts +146 -0
- package/src/core/sprite-batch/SpriteBatchMesh.ts +243 -0
- package/src/core/window/window-manager.ts +76 -0
- package/src/counter.ts +9 -0
- package/src/geometry/BaseGeometry.ts +148 -0
- package/src/geometry/GeometryBuilder.ts +58 -0
- package/src/geometry/GeometryFormat.ts +37 -0
- package/src/main.ts +97 -0
- package/src/style.css +96 -0
- package/src/typescript.svg +1 -0
- package/src/webgl/WebGLGraphicsDeviceFeatures.ts +57 -0
- package/src/webgl/WebGlGpuInfo.ts +76 -0
- package/src/webgl/WebGlGraphicsDevice.ts +129 -0
- package/src/webgl/WebGlRenderer.ts +31 -0
- package/src/webgl/blending/webgl-blend-state.ts +59 -0
- package/src/webgl/buffers/WebGlBuffersFactory.ts +75 -0
- package/src/webgl/buffers/WebGlUniformBuffer.ts +87 -0
- package/src/webgl/buffers/WebGlVertexBuffer.ts +100 -0
- package/src/webgl/buffers/webgl-index-buffer.ts +110 -0
- package/src/webgl/cast/cast.ts +100 -0
- package/src/webgl/primitive/WebGlPrimitiveState.ts +60 -0
- package/src/webgl/render-pass/WebGlRenderPass.ts +186 -0
- package/src/webgl/render-pipelines/AWebGlRenderPipeline.ts +129 -0
- package/src/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.ts +95 -0
- package/src/webgl/render-pipelines/WebGlRenderPipelineFactory.ts +75 -0
- package/src/webgl/render-pipelines/inspect/WebGlInspectTextureMipsRenderPipeline.ts +200 -0
- package/src/webgl/render-pipelines/material/WebGlUnlitRenderPipeline.ts +197 -0
- package/src/webgl/render-pipelines/sprite/WebGlSpriteRenderPipeline.ts +148 -0
- package/src/webgl/rendering/webgl-vertex-attribute.ts +16 -0
- package/src/webgl/rendering/webgl-vertex-buffer-layout.ts +64 -0
- package/src/webgl/sampler/webgl-sampler.ts +110 -0
- package/src/webgl/shader/WebGlShaderModule.ts +110 -0
- package/src/webgl/shader/WebGlShaderModuleLoader.ts +40 -0
- package/src/webgl/swap-chain/WebGlSwapChain.ts +56 -0
- package/src/webgl/texture/WebGlTexture2D.ts +133 -0
- package/src/webgl/texture/WebGlTextureFactory.ts +184 -0
- package/src/webgl/utilities/WebGlBufferUtilities.ts +124 -0
- package/src/webgl/utilities/WebGlConverter.ts +391 -0
- package/src/webgl/utilities/WebGlFrameBufferUtilities.ts +240 -0
- package/src/webgl/utilities/WebGlSamplerUtilities.ts +81 -0
- package/src/webgl/utilities/WebGlShaderUtilities.ts +48 -0
- package/src/webgl/utilities/WebGlTextureUtilities.ts +162 -0
- package/src/webgl/utilities/WebGlUtilities.ts +71 -0
- package/src/webgl/utilities/spector-js-utilities.ts +13 -0
- package/src/webgl/utilities/webgl-blending-utilities.ts +85 -0
- package/src/webgl/utilities/webgl-culling-utilities.ts +23 -0
- package/src/webgl/utilities/webgl-filter-anisotropic-utilities.ts +37 -0
- package/src/webgl/utilities/webgl-program-utilities.ts +29 -0
- package/src/webgl/utilities/webgl-render-buffer-utilities.ts +23 -0
- package/src/webgl/utilities/webgl-renderbuffer-utilities.ts +35 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The geometry format.
|
|
3
|
+
*/
|
|
4
|
+
export enum GeometryFormat {
|
|
5
|
+
/**
|
|
6
|
+
* Geometry format where:
|
|
7
|
+
* First 3 floats are reserved for vertex position.Following 4 floats are reserved for vertex color.
|
|
8
|
+
*/
|
|
9
|
+
POS3_COLOR4 = 0,
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Geometry format where:
|
|
13
|
+
* First 3 floats are reserved for vertex position.Following 4 floats are reserved for vertex color.Following 2 floats are reserved for vertex texture coordinates.
|
|
14
|
+
*/
|
|
15
|
+
POS3_COLOR4_TEXTURECOORDS2 = 1,
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Geometry format where:
|
|
19
|
+
* First 3 floats are reserved for vertex position.Following 4 floats are reserved for vertex color.Following 2 floats are reserved for vertex texture coordinates.
|
|
20
|
+
* When aligned, the vertex format is aligned to 4 floats.
|
|
21
|
+
* Meaning:
|
|
22
|
+
* First 4 floats are reserved for vertex position, but only 3 are used.Following 4 floats are reserved for vertex color.Following 4 floats are reserved for vertex texture coordinates, but only 2 are used.
|
|
23
|
+
*/
|
|
24
|
+
POS3_COLOR4_TEXTURECOORDS2_ALIGNED = 2,
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Geometry format where:
|
|
28
|
+
* First 3 floats are reserved for vertex position.Following 4 floats are reserved for vertex color.Following 2 floats are reserved for vertex texture coordinates.Following 3 floats are reserved for vertex normal.
|
|
29
|
+
*/
|
|
30
|
+
POS3_COLOR4_TEXTURECOORDS2_NORMAL3 = 3,
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Geometry format where:
|
|
34
|
+
* First 3 floats are reserved for vertex position.Following 2 floats are reserved for texture coordinates.
|
|
35
|
+
*/
|
|
36
|
+
POS3_TEXTURECOORDS2 = 4
|
|
37
|
+
}
|
package/src/main.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import './style.css'
|
|
2
|
+
import "reflect-metadata";
|
|
3
|
+
|
|
4
|
+
import typescriptLogo from './typescript.svg'
|
|
5
|
+
import viteLogo from '/vite.svg'
|
|
6
|
+
import {setupCounter} from './counter.ts'
|
|
7
|
+
import {Framework} from './core/Framework.ts';
|
|
8
|
+
import {FrameworkConfig} from "./core/FrameworkConfig.ts";
|
|
9
|
+
import {TextureSamplerFilteringPreset} from "./core/rendering/enums.ts";
|
|
10
|
+
import {
|
|
11
|
+
Color,
|
|
12
|
+
type IFramework,
|
|
13
|
+
type ISampler,
|
|
14
|
+
type ITexture2D,
|
|
15
|
+
Rect,
|
|
16
|
+
SamplerDescriptor,
|
|
17
|
+
SamplerFilter, TextureDescriptor, TextureFormat
|
|
18
|
+
} from "ris-framework-api";
|
|
19
|
+
|
|
20
|
+
document.querySelector<HTMLDivElement>('#app')!.innerHTML = `
|
|
21
|
+
<div>
|
|
22
|
+
<a href="https://vite.dev" target="_blank">
|
|
23
|
+
<img src="${viteLogo}" class="logo" alt="Vite logo" />
|
|
24
|
+
</a>
|
|
25
|
+
<a href="https://www.typescriptlang.org/" target="_blank">
|
|
26
|
+
<img src="${typescriptLogo}" class="logo vanilla" alt="TypeScript logo" />
|
|
27
|
+
</a>
|
|
28
|
+
<h1>Vite + TypeScript</h1>
|
|
29
|
+
<div class="card">
|
|
30
|
+
<button id="counter" type="button"></button>
|
|
31
|
+
</div>
|
|
32
|
+
<p class="read-the-docs">
|
|
33
|
+
Click on the Vite and TypeScript logos to learn more
|
|
34
|
+
</p>
|
|
35
|
+
</div>
|
|
36
|
+
`
|
|
37
|
+
|
|
38
|
+
setupCounter(document.querySelector<HTMLButtonElement>('#counter')!)
|
|
39
|
+
|
|
40
|
+
const frameworkConfig = new FrameworkConfig();
|
|
41
|
+
frameworkConfig.canvas = document.getElementById("game-canvas") as HTMLCanvasElement;
|
|
42
|
+
frameworkConfig.textureFiltering = TextureSamplerFilteringPreset.BILINEAR;
|
|
43
|
+
const framework : IFramework = new Framework(frameworkConfig);
|
|
44
|
+
|
|
45
|
+
const rect = new Rect(200, 200, 200, 200);
|
|
46
|
+
const texRect = new Rect(500, 200, 200, 200);
|
|
47
|
+
const texRect2 = new Rect(200, 500, 200, 200);
|
|
48
|
+
const color = Color.blue();
|
|
49
|
+
const whiteColor = Color.white();
|
|
50
|
+
let tex: ITexture2D;
|
|
51
|
+
let tex2 : ITexture2D;
|
|
52
|
+
let sampler: ISampler;
|
|
53
|
+
framework.addOnLoadContentListener(async () =>
|
|
54
|
+
{
|
|
55
|
+
|
|
56
|
+
const texDesc = new TextureDescriptor();
|
|
57
|
+
texDesc.generateMipmaps = true;
|
|
58
|
+
texDesc.textureFormat = TextureFormat.RGBA_8_UNORM;
|
|
59
|
+
|
|
60
|
+
tex = await framework.content.loadTexture2DAsync("/assets/test.png", texDesc);
|
|
61
|
+
tex2 = await framework.content.loadTexture2DAsync("/assets/cat.jpg", texDesc);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
framework.addOnInitializedListener(() => {
|
|
65
|
+
const desc = new SamplerDescriptor();
|
|
66
|
+
desc.minFilter = SamplerFilter.NEAREST;
|
|
67
|
+
desc.magFilter = SamplerFilter.NEAREST;
|
|
68
|
+
// desc.label = "Label";
|
|
69
|
+
sampler = framework.graphicsDevice.createSampler(desc);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
framework.addOnRenderListener(() =>
|
|
73
|
+
{
|
|
74
|
+
let spriteBatch = framework.spriteBatch;
|
|
75
|
+
|
|
76
|
+
spriteBatch.begin(undefined, sampler);
|
|
77
|
+
spriteBatch.drawRect(rect, color);
|
|
78
|
+
if(tex != null){
|
|
79
|
+
spriteBatch.draw(tex, texRect, whiteColor);
|
|
80
|
+
}
|
|
81
|
+
if(tex2 != null){
|
|
82
|
+
spriteBatch.draw(tex2, texRect2, whiteColor);
|
|
83
|
+
}
|
|
84
|
+
spriteBatch.end();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
framework.initialize();
|
|
88
|
+
framework.renderer.clearColor = Color.lightPink();
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
// We need to load geometry and create vertex buffer and index buffer from it.
|
|
92
|
+
// const geometry = framework.geometryBuilder.quadGeometry();
|
|
93
|
+
// const vertexBuffer =
|
|
94
|
+
// const indexBuffer =
|
|
95
|
+
|
|
96
|
+
// Next we need to create unlit pipeline for geometry.
|
|
97
|
+
|
package/src/style.css
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
|
|
3
|
+
line-height: 1.5;
|
|
4
|
+
font-weight: 400;
|
|
5
|
+
|
|
6
|
+
color-scheme: light dark;
|
|
7
|
+
color: rgba(255, 255, 255, 0.87);
|
|
8
|
+
background-color: #242424;
|
|
9
|
+
|
|
10
|
+
font-synthesis: none;
|
|
11
|
+
text-rendering: optimizeLegibility;
|
|
12
|
+
-webkit-font-smoothing: antialiased;
|
|
13
|
+
-moz-osx-font-smoothing: grayscale;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
a {
|
|
17
|
+
font-weight: 500;
|
|
18
|
+
color: #646cff;
|
|
19
|
+
text-decoration: inherit;
|
|
20
|
+
}
|
|
21
|
+
a:hover {
|
|
22
|
+
color: #535bf2;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
body {
|
|
26
|
+
margin: 0;
|
|
27
|
+
display: flex;
|
|
28
|
+
place-items: center;
|
|
29
|
+
min-width: 320px;
|
|
30
|
+
min-height: 100vh;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
h1 {
|
|
34
|
+
font-size: 3.2em;
|
|
35
|
+
line-height: 1.1;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
#app {
|
|
39
|
+
max-width: 1280px;
|
|
40
|
+
margin: 0 auto;
|
|
41
|
+
padding: 2rem;
|
|
42
|
+
text-align: center;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.logo {
|
|
46
|
+
height: 6em;
|
|
47
|
+
padding: 1.5em;
|
|
48
|
+
will-change: filter;
|
|
49
|
+
transition: filter 300ms;
|
|
50
|
+
}
|
|
51
|
+
.logo:hover {
|
|
52
|
+
filter: drop-shadow(0 0 2em #646cffaa);
|
|
53
|
+
}
|
|
54
|
+
.logo.vanilla:hover {
|
|
55
|
+
filter: drop-shadow(0 0 2em #3178c6aa);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.card {
|
|
59
|
+
padding: 2em;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.read-the-docs {
|
|
63
|
+
color: #888;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
button {
|
|
67
|
+
border-radius: 8px;
|
|
68
|
+
border: 1px solid transparent;
|
|
69
|
+
padding: 0.6em 1.2em;
|
|
70
|
+
font-size: 1em;
|
|
71
|
+
font-weight: 500;
|
|
72
|
+
font-family: inherit;
|
|
73
|
+
background-color: #1a1a1a;
|
|
74
|
+
cursor: pointer;
|
|
75
|
+
transition: border-color 0.25s;
|
|
76
|
+
}
|
|
77
|
+
button:hover {
|
|
78
|
+
border-color: #646cff;
|
|
79
|
+
}
|
|
80
|
+
button:focus,
|
|
81
|
+
button:focus-visible {
|
|
82
|
+
outline: 4px auto -webkit-focus-ring-color;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@media (prefers-color-scheme: light) {
|
|
86
|
+
:root {
|
|
87
|
+
color: #213547;
|
|
88
|
+
background-color: #ffffff;
|
|
89
|
+
}
|
|
90
|
+
a:hover {
|
|
91
|
+
color: #747bff;
|
|
92
|
+
}
|
|
93
|
+
button {
|
|
94
|
+
background-color: #f9f9f9;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="32" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path fill="#007ACC" d="M0 128v128h256V0H0z"></path><path fill="#FFF" d="m56.612 128.85l-.081 10.483h33.32v94.68h23.568v-94.68h33.321v-10.28c0-5.69-.122-10.444-.284-10.566c-.122-.162-20.4-.244-44.983-.203l-44.74.122l-.121 10.443Zm149.955-10.742c6.501 1.625 11.459 4.51 16.01 9.224c2.357 2.52 5.851 7.111 6.136 8.208c.08.325-11.053 7.802-17.798 11.988c-.244.162-1.22-.894-2.317-2.52c-3.291-4.795-6.745-6.867-12.028-7.233c-7.76-.528-12.759 3.535-12.718 10.321c0 1.992.284 3.17 1.097 4.795c1.707 3.536 4.876 5.649 14.832 9.956c18.326 7.883 26.168 13.084 31.045 20.48c5.445 8.249 6.664 21.415 2.966 31.208c-4.063 10.646-14.14 17.879-28.323 20.276c-4.388.772-14.79.65-19.504-.203c-10.28-1.828-20.033-6.908-26.047-13.572c-2.357-2.6-6.949-9.387-6.664-9.874c.122-.163 1.178-.813 2.356-1.504c1.138-.65 5.446-3.129 9.509-5.485l7.355-4.267l1.544 2.276c2.154 3.29 6.867 7.801 9.712 9.305c8.167 4.307 19.383 3.698 24.909-1.26c2.357-2.153 3.332-4.388 3.332-7.68c0-2.966-.366-4.266-1.91-6.501c-1.99-2.845-6.054-5.242-17.595-10.24c-13.206-5.69-18.895-9.224-24.096-14.832c-3.007-3.25-5.852-8.452-7.03-12.8c-.975-3.617-1.22-12.678-.447-16.335c2.723-12.76 12.353-21.659 26.25-24.3c4.51-.853 14.994-.528 19.424.569Z"></path></svg>
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type {IGraphicsDeviceFeatures} from "ris-framework-api";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The WebGL implementation of the IGraphicsDeviceFeatures interface.
|
|
5
|
+
*/
|
|
6
|
+
export class WebGLGraphicsDeviceFeatures implements IGraphicsDeviceFeatures {
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new instance of WebGLGraphicsDeviceFeatures.
|
|
10
|
+
* @param webgl The WebGL2RenderingContext.
|
|
11
|
+
*/
|
|
12
|
+
public constructor(webgl: WebGL2RenderingContext) {
|
|
13
|
+
this.astcExtension = webgl.getExtension("WEBGL_compressed_texture_astc") as WEBGL_compressed_texture_astc;
|
|
14
|
+
this.supportsTextureCompressionASTC = !!this.astcExtension;
|
|
15
|
+
|
|
16
|
+
this.bptcExtension = webgl.getExtension("EXT_texture_compression_bptc") as EXT_texture_compression_bptc;
|
|
17
|
+
this.supportsTextureCompressionS3TC = !!this.bptcExtension;
|
|
18
|
+
|
|
19
|
+
this.etcExtension = webgl.getExtension("WEBGL_compressed_texture_etc") as WEBGL_compressed_texture_etc;
|
|
20
|
+
this.supportsTextureCompressionETC2 = !!this.etcExtension;
|
|
21
|
+
|
|
22
|
+
this.s3tcExtension = webgl.getExtension("WEBGL_compressed_texture_s3tc") as WEBGL_compressed_texture_s3tc;
|
|
23
|
+
this.supportsTextureCompressionBC = !!this.s3tcExtension;
|
|
24
|
+
|
|
25
|
+
this.pvrtcExtension = webgl.getExtension("WEBGL_compressed_texture_pvrtc") as WEBGL_compressed_texture_pvrtc;
|
|
26
|
+
this.supportsTextureCompressionPVRTC = !!this.pvrtcExtension;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The WEBGL_compressed_texture_astc extension. */
|
|
30
|
+
readonly astcExtension?: WEBGL_compressed_texture_astc;
|
|
31
|
+
|
|
32
|
+
/** @inheritdoc */
|
|
33
|
+
readonly supportsTextureCompressionASTC: boolean;
|
|
34
|
+
|
|
35
|
+
/** The EXT_texture_compression_bptc extension. */
|
|
36
|
+
readonly bptcExtension?: EXT_texture_compression_bptc;
|
|
37
|
+
|
|
38
|
+
/** @inheritdoc */
|
|
39
|
+
readonly supportsTextureCompressionBC: boolean;
|
|
40
|
+
|
|
41
|
+
/** The WEBGL_compressed_texture_etc extension. */
|
|
42
|
+
readonly etcExtension: WEBGL_compressed_texture_etc;
|
|
43
|
+
|
|
44
|
+
/** @inheritdoc */
|
|
45
|
+
readonly supportsTextureCompressionETC2: boolean;
|
|
46
|
+
|
|
47
|
+
/** The WEBGL_compressed_texture_pvrtc extension. */
|
|
48
|
+
readonly pvrtcExtension?: WEBGL_compressed_texture_pvrtc;
|
|
49
|
+
|
|
50
|
+
readonly supportsTextureCompressionPVRTC: boolean;
|
|
51
|
+
|
|
52
|
+
/** The WEBGL_compressed_texture_s3tc extension. */
|
|
53
|
+
readonly s3tcExtension?: WEBGL_compressed_texture_s3tc
|
|
54
|
+
|
|
55
|
+
/** @inheritdoc */
|
|
56
|
+
readonly supportsTextureCompressionS3TC: boolean;
|
|
57
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import {type IGPUInfo, RenderingBackend, TextureFormat} from "ris-framework-api";
|
|
2
|
+
import type {WebGlGraphicsDevice} from "./WebGlGraphicsDevice.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The WebGL implementation of IGPUInfo
|
|
6
|
+
*/
|
|
7
|
+
export class WebGlGpuInfo implements IGPUInfo {
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The constructor.
|
|
11
|
+
* @param graphicsDevice The graphics device.
|
|
12
|
+
*/
|
|
13
|
+
public constructor(graphicsDevice: WebGlGraphicsDevice) {
|
|
14
|
+
|
|
15
|
+
var gl = graphicsDevice.gl;
|
|
16
|
+
|
|
17
|
+
// Get name of the graphics device.
|
|
18
|
+
const debugExt = gl.getExtension("WEBGL_debug_renderer_info");
|
|
19
|
+
if(debugExt) {
|
|
20
|
+
this.name = gl.getParameter(debugExt.UNMASKED_RENDERER_WEBGL);
|
|
21
|
+
this.vendor = gl.getParameter(debugExt.UNMASKED_VENDOR_WEBGL);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
this.name = gl.getParameter(gl.RENDERER);
|
|
25
|
+
this.vendor = gl.getParameter(gl.VENDOR);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
this.apiVersion = gl.getParameter(gl.VERSION);
|
|
29
|
+
this.api = RenderingBackend.WEB_GL;
|
|
30
|
+
|
|
31
|
+
// This info is hidden, therefore default.
|
|
32
|
+
this.underlyingBackend = RenderingBackend.DEFAULT;
|
|
33
|
+
|
|
34
|
+
const supportedCompressedTextureFormats = [];
|
|
35
|
+
|
|
36
|
+
if(graphicsDevice.features.supportsTextureCompressionASTC){
|
|
37
|
+
supportedCompressedTextureFormats.push(TextureFormat.ASTC_4X4_RGBA)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if(graphicsDevice.features.supportsTextureCompressionS3TC) {
|
|
41
|
+
supportedCompressedTextureFormats.push(TextureFormat.BC3_RGBA_UNORM)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if(graphicsDevice.features.supportsTextureCompressionETC2) {
|
|
45
|
+
supportedCompressedTextureFormats.push(TextureFormat.ETC2_RGBA8_UNORM);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if(graphicsDevice.features.supportsTextureCompressionBC) {
|
|
49
|
+
supportedCompressedTextureFormats.push(TextureFormat.BC7_RGBA_UNORM);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// TODO: PVRC
|
|
53
|
+
|
|
54
|
+
this.supportedCompressedTextureFormats = supportedCompressedTextureFormats;
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** @inheritDoc */
|
|
59
|
+
readonly api: RenderingBackend;
|
|
60
|
+
|
|
61
|
+
/** @inheritDoc */
|
|
62
|
+
readonly apiVersion: string;
|
|
63
|
+
|
|
64
|
+
/** @inheritDoc */
|
|
65
|
+
readonly name: string;
|
|
66
|
+
|
|
67
|
+
/** @inheritDoc */
|
|
68
|
+
readonly supportedCompressedTextureFormats: TextureFormat[];
|
|
69
|
+
|
|
70
|
+
/** @inheritDoc */
|
|
71
|
+
readonly underlyingBackend: RenderingBackend;
|
|
72
|
+
|
|
73
|
+
/** @inheritDoc */
|
|
74
|
+
readonly vendor: string;
|
|
75
|
+
|
|
76
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type {IRenderPass} from "../core/rendering/render-pass/render-pass-interface";
|
|
2
|
+
import {WebGlSampler} from "./sampler/webgl-sampler";
|
|
3
|
+
import {WebGlRenderPass} from "./render-pass/WebGlRenderPass.ts";
|
|
4
|
+
import {AGraphicsDevice, GraphicsDeviceDescriptor} from "../core/rendering/AGraphicsDevice.ts";
|
|
5
|
+
import {type BlendStateDescriptor} from "../core/rendering/blending/blend-state-descriptor";
|
|
6
|
+
import {WebGlBlendState} from "./blending/webgl-blend-state";
|
|
7
|
+
import {WebGlPrimitiveState} from "./primitive/WebGlPrimitiveState.ts";
|
|
8
|
+
import {PrimitiveStateDescriptor} from "../core/rendering/primitive/PrimitiveStateDescriptor.ts";
|
|
9
|
+
import {WebGLGraphicsDeviceFeatures} from "./WebGLGraphicsDeviceFeatures.ts";
|
|
10
|
+
import {WebGlSwapChain} from "./swap-chain/WebGlSwapChain.ts";
|
|
11
|
+
import {WebGlGpuInfo} from "./WebGlGpuInfo.ts";
|
|
12
|
+
import type {
|
|
13
|
+
IBlendState,
|
|
14
|
+
IGPUInfo, IPrimitiveState,
|
|
15
|
+
ISampler,
|
|
16
|
+
ISwapChain,
|
|
17
|
+
IWindowManager,
|
|
18
|
+
RenderPassDescriptor,
|
|
19
|
+
SwapChainDescriptor
|
|
20
|
+
} from "ris-framework-api";
|
|
21
|
+
import type {SamplerDescriptor} from "../core/rendering/sampler/sampler-descriptor.ts";
|
|
22
|
+
|
|
23
|
+
export class WebGlGraphicsDevice extends AGraphicsDevice {
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
public setupDebugCallback(): void {
|
|
27
|
+
throw new Error("Method not implemented.");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public frameEnd(): void {
|
|
31
|
+
throw new Error("Method not implemented.");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public pushDebugGroup(_groupName: string): void {
|
|
35
|
+
throw new Error("Method not implemented.");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public popDebugGroup(): void {
|
|
39
|
+
throw new Error("Method not implemented.");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
private readonly _windowManager: IWindowManager;
|
|
44
|
+
private _canvas: HTMLCanvasElement = null!;
|
|
45
|
+
private _gl: WebGL2RenderingContext = null!;
|
|
46
|
+
private _features: WebGLGraphicsDeviceFeatures = null!;
|
|
47
|
+
private _gpuInfo: WebGlGpuInfo = null!;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The constructor.
|
|
51
|
+
* @param windowManager The window manager that provides access to the canvas element and other window-related functionalities needed for initializing the graphics device and creating rendering contexts.
|
|
52
|
+
* @param descriptor The descriptor for the graphics device. This is used to configure the graphics device during initialization.
|
|
53
|
+
*/
|
|
54
|
+
public constructor(windowManager: IWindowManager, descriptor: GraphicsDeviceDescriptor) {
|
|
55
|
+
|
|
56
|
+
super(descriptor);
|
|
57
|
+
this._windowManager = windowManager;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The WebGL rendering context.
|
|
62
|
+
*/
|
|
63
|
+
public get gl(): WebGL2RenderingContext {
|
|
64
|
+
return this._gl;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** @inheritdoc */
|
|
68
|
+
public get features() {
|
|
69
|
+
return this._features;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** @inheritdoc */
|
|
73
|
+
public get gpuInfo(): IGPUInfo {
|
|
74
|
+
return this._gpuInfo;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
/** @inheritdoc */
|
|
79
|
+
public initialize(): void {
|
|
80
|
+
|
|
81
|
+
this._canvas = this._windowManager.canvas;
|
|
82
|
+
|
|
83
|
+
const contextOptions: WebGLContextAttributes = {
|
|
84
|
+
antialias: false,
|
|
85
|
+
powerPreference: "high-performance", // TODO: Make configurable.
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
this._gl = this._canvas.getContext(
|
|
89
|
+
"webgl2",
|
|
90
|
+
contextOptions,
|
|
91
|
+
) as WebGL2RenderingContext;
|
|
92
|
+
|
|
93
|
+
// If not supported, throw an error.
|
|
94
|
+
if (!this._gl) {
|
|
95
|
+
throw new Error("WebGL not supported.");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
this._features = new WebGLGraphicsDeviceFeatures(this._gl);
|
|
99
|
+
this._gpuInfo = new WebGlGpuInfo(this);
|
|
100
|
+
|
|
101
|
+
super.initialize();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** @inheritdoc */
|
|
105
|
+
public createSwapChain(canvas: HTMLCanvasElement, _: SwapChainDescriptor): ISwapChain {
|
|
106
|
+
return new WebGlSwapChain(canvas, this);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** @inheritdoc */
|
|
110
|
+
public createSampler(descriptor?: SamplerDescriptor): ISampler {
|
|
111
|
+
return new WebGlSampler(this, descriptor);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** @inheritdoc */
|
|
115
|
+
public createRenderPass(descriptor: RenderPassDescriptor): IRenderPass {
|
|
116
|
+
return new WebGlRenderPass(this, descriptor);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** @inheritdoc */
|
|
120
|
+
public createBlendState(descriptor: BlendStateDescriptor): IBlendState {
|
|
121
|
+
return new WebGlBlendState(this, descriptor);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** @inheritdoc */
|
|
125
|
+
public createPrimitiveState(descriptor?: PrimitiveStateDescriptor): IPrimitiveState {
|
|
126
|
+
descriptor = descriptor ?? new PrimitiveStateDescriptor();
|
|
127
|
+
return new WebGlPrimitiveState(this._gl, descriptor);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type RenderConfiguration } from "../core/renderer/renderer-interface";
|
|
2
|
+
import { ARenderer } from "../core/rendering/ARenderer.ts";
|
|
3
|
+
import { WebGlGraphicsDevice } from "./WebGlGraphicsDevice.ts";
|
|
4
|
+
import type {IFramework, IGraphicsDevice} from "ris-framework-api";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The WebGL implementation of the IRenderer interface.
|
|
8
|
+
*/
|
|
9
|
+
export class WebGlRenderer extends ARenderer {
|
|
10
|
+
|
|
11
|
+
private _renderConfiguration: RenderConfiguration;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The constructor.
|
|
15
|
+
* @param framework The framework.
|
|
16
|
+
* @param renderConfiguration The render configuration. This is used to initialize the renderer.
|
|
17
|
+
*/
|
|
18
|
+
constructor(
|
|
19
|
+
framework: IFramework,
|
|
20
|
+
renderConfiguration: RenderConfiguration) {
|
|
21
|
+
super(framework);
|
|
22
|
+
this._renderConfiguration = renderConfiguration;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** @inheritdoc */
|
|
26
|
+
protected createGraphicsDevice(): IGraphicsDevice {
|
|
27
|
+
return new WebGlGraphicsDevice(this._framework.windowManager, {
|
|
28
|
+
samplerFilteringPreset: this._renderConfiguration.textureFiltering
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { BlendStateDescriptor } from "../../core/rendering/blending/blend-state-descriptor";
|
|
2
|
+
import { WebGlConverter } from "../utilities/WebGlConverter.ts";
|
|
3
|
+
import type { WebGlGraphicsDevice } from "../WebGlGraphicsDevice.ts";
|
|
4
|
+
import type {IBlendState} from "ris-framework-api";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The WebGL blend state.
|
|
8
|
+
*/
|
|
9
|
+
export class WebGlBlendState implements IBlendState {
|
|
10
|
+
|
|
11
|
+
private readonly _gl: WebGL2RenderingContext;
|
|
12
|
+
|
|
13
|
+
private _blendEnabled: boolean;
|
|
14
|
+
private _srcColorFactor: GLenum;
|
|
15
|
+
private _dstColorFactor: GLenum;
|
|
16
|
+
private _colorBlendOperation: GLenum;
|
|
17
|
+
private _srcAlphaFactor: GLenum;
|
|
18
|
+
private _dstAlphaFactor: GLenum;
|
|
19
|
+
private _alphaBlendOperation: GLenum;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The constructor.
|
|
23
|
+
* @param _graphicsDevice The graphics device.
|
|
24
|
+
* @param descriptor The blend state descriptor.
|
|
25
|
+
*/
|
|
26
|
+
public constructor(private readonly _graphicsDevice: WebGlGraphicsDevice, descriptor: BlendStateDescriptor) {
|
|
27
|
+
this._gl = this._graphicsDevice.gl;
|
|
28
|
+
this._blendEnabled = descriptor.blendingEnabled;
|
|
29
|
+
this._srcColorFactor = WebGlConverter.convertBlendFactor(this._gl, descriptor.color.srcFactor);
|
|
30
|
+
this._dstColorFactor = WebGlConverter.convertBlendFactor(this._gl, descriptor.color.dstFactor);
|
|
31
|
+
this._colorBlendOperation = WebGlConverter.convertBlendOperation(this._gl, descriptor.color.operation);
|
|
32
|
+
this._srcAlphaFactor = WebGlConverter.convertBlendFactor(this._gl, descriptor.alpha.srcFactor);
|
|
33
|
+
this._dstAlphaFactor = WebGlConverter.convertBlendFactor(this._gl, descriptor.alpha.dstFactor);
|
|
34
|
+
this._alphaBlendOperation = WebGlConverter.convertBlendOperation(this._gl, descriptor.alpha.operation);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** @inheritdoc */
|
|
38
|
+
public nativePtr: any;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* For internal use only. Applies the blend state to the WebGL context.
|
|
42
|
+
* @param gl The WebGL context to apply the blend state to.
|
|
43
|
+
*/
|
|
44
|
+
public apply(gl: WebGL2RenderingContext): void {
|
|
45
|
+
if (this._blendEnabled) {
|
|
46
|
+
gl.enable(gl.BLEND);
|
|
47
|
+
gl.blendFuncSeparate(this._srcColorFactor, this._dstColorFactor, this._srcAlphaFactor, this._dstAlphaFactor);
|
|
48
|
+
gl.blendEquationSeparate(this._colorBlendOperation, this._alphaBlendOperation);
|
|
49
|
+
} else {
|
|
50
|
+
gl.disable(gl.BLEND);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** @inheritdoc */
|
|
55
|
+
public dispose(): void {
|
|
56
|
+
// No resources to dispose for blend state in WebGL, as the state is applied directly to the WebGL context.
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { WebGlVertexBuffer as WebGlVertexBuffer } from "./WebGlVertexBuffer.ts";
|
|
2
|
+
import {WebGLIndexBuffer} from "./webgl-index-buffer.ts";
|
|
3
|
+
import {
|
|
4
|
+
BufferUsage,
|
|
5
|
+
type IBufferFactory,
|
|
6
|
+
type IFramework,
|
|
7
|
+
type IIndexBuffer,
|
|
8
|
+
type IUniformBuffer,
|
|
9
|
+
type IVertexBuffer
|
|
10
|
+
} from "ris-framework-api";
|
|
11
|
+
import {WebGlUniformBuffer} from "./WebGlUniformBuffer.ts";
|
|
12
|
+
|
|
13
|
+
export class WebGlBuffersFactory implements IBufferFactory {
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The constructor of the WebGLBuffersFactory class.
|
|
17
|
+
* @param _framework The framework instance to use for creating buffers.
|
|
18
|
+
*/
|
|
19
|
+
public constructor(private readonly _framework: IFramework) {
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** @inheritDoc */
|
|
23
|
+
public createVertexBuffer(data: ArrayLike<number>, vertexStride: number, usage: BufferUsage, label?: string): IVertexBuffer {
|
|
24
|
+
const vertexBuffer = new WebGlVertexBuffer(this._framework, data, vertexStride, usage, label );
|
|
25
|
+
vertexBuffer.initialize();
|
|
26
|
+
return vertexBuffer;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** @inheritDoc */
|
|
30
|
+
public createUniformBuffer(data: ArrayLike<number>, usage: BufferUsage, label?: string): IUniformBuffer {
|
|
31
|
+
const uniformBuffer = new WebGlUniformBuffer(this._framework, data, usage, label);
|
|
32
|
+
uniformBuffer.initialize();
|
|
33
|
+
return uniformBuffer;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** @inheritdoc */
|
|
37
|
+
public createIndexBuffer(data: ArrayLike<number>, label?: string): IIndexBuffer {
|
|
38
|
+
const buffer = new WebGLIndexBuffer(this._framework, label);
|
|
39
|
+
buffer.initialize(data);
|
|
40
|
+
return buffer;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
/** @inheritdoc */
|
|
45
|
+
/*
|
|
46
|
+
public createIndexBuffer(data: Uint16Array | Uint32Array, label: string | null): IIndexBuffer {
|
|
47
|
+
const indexBuffer = new WebGlIndexBuffer(this._framework, label);
|
|
48
|
+
indexBuffer.initialize(data);
|
|
49
|
+
return indexBuffer;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
public createVertexBuffer(
|
|
55
|
+
dataOrByteSize: number[] | number,
|
|
56
|
+
byteStride: number,
|
|
57
|
+
vertexCount: number,
|
|
58
|
+
bufferUsage: BufferUsage = BufferUsage.VERTEX | BufferUsage.COPYDST,
|
|
59
|
+
label: string | null = null): IVertexBuffer {
|
|
60
|
+
|
|
61
|
+
const vertexBuffer = new WebGlVertexBuffer(this._framework, label);
|
|
62
|
+
vertexBuffer.initialize(dataOrByteSize, byteStride, vertexCount, bufferUsage);
|
|
63
|
+
return vertexBuffer;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** @inheritdoc */
|
|
67
|
+
/*
|
|
68
|
+
public createUniformBuffer(dataOrByteLength: ArrayBuffer | ArrayBufferView | number, bufferUsage: BufferUsage = BufferUsage.UNIFORM | BufferUsage.COPY_DST, label: string | null = null): IUniformBuffer {
|
|
69
|
+
const uniformBuffer = new WebGlUniformBuffer(this._graphicsDevice, bufferUsage, label ?? "");
|
|
70
|
+
uniformBuffer.initialize(dataOrByteLength);
|
|
71
|
+
return uniformBuffer;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
*/
|
|
75
|
+
}
|