ris-framework 0.2.0-dev.11 → 0.2.0-dev.13
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 +21 -29
- package/README.md +99 -150
- package/dist/Framework.d.ts +26 -8
- package/dist/Framework.d.ts.map +1 -1
- package/dist/api/IFramework.d.ts +43 -0
- package/dist/api/IFramework.d.ts.map +1 -1
- package/dist/api/_export.d.ts +1 -1
- package/dist/api/_export.d.ts.map +1 -1
- package/dist/api/content/ContentManager.d.ts +5 -57
- package/dist/api/content/ContentManager.d.ts.map +1 -1
- package/dist/api/content/IContentManager.d.ts +24 -21
- package/dist/api/content/IContentManager.d.ts.map +1 -1
- package/dist/api/lights/LightsBuffer.d.ts +13 -6
- package/dist/api/lights/LightsBuffer.d.ts.map +1 -1
- package/dist/api/loaders/ObjGeometryMapper.d.ts +2 -2
- package/dist/api/loaders/ObjLoader.d.ts +61 -0
- package/dist/api/loaders/ObjLoader.d.ts.map +1 -0
- package/dist/api/loaders/_export.d.ts +1 -0
- package/dist/api/loaders/_export.d.ts.map +1 -1
- package/dist/api/loaders/obj/{ObjLoader.d.ts → ObjParser.d.ts} +20 -5
- package/dist/api/loaders/obj/ObjParser.d.ts.map +1 -0
- package/dist/api/loaders/obj/ObjTypes.d.ts +17 -1
- package/dist/api/loaders/obj/ObjTypes.d.ts.map +1 -1
- package/dist/api/loaders/obj/index.d.ts +1 -1
- package/dist/api/material/ForwardBlinnPhongMaterial.d.ts +22 -11
- package/dist/api/material/ForwardBlinnPhongMaterial.d.ts.map +1 -1
- package/dist/api/material/ICameraMaterial.d.ts +18 -0
- package/dist/api/material/ICameraMaterial.d.ts.map +1 -0
- package/dist/api/material/ILightsMaterial.d.ts +26 -0
- package/dist/api/material/ILightsMaterial.d.ts.map +1 -0
- package/dist/api/material/IMaterial.d.ts +2 -8
- package/dist/api/material/IMaterial.d.ts.map +1 -1
- package/dist/api/material/InspectTextureMipsMaterial.d.ts +2 -2
- package/dist/api/material/InspectTextureMipsMaterial.d.ts.map +1 -1
- package/dist/api/material/SpriteMaterial.d.ts +2 -2
- package/dist/api/material/SpriteMaterial.d.ts.map +1 -1
- package/dist/api/material/UnlitMaterial.d.ts +4 -3
- package/dist/api/material/UnlitMaterial.d.ts.map +1 -1
- package/dist/api/material/_export.d.ts +2 -0
- package/dist/api/material/_export.d.ts.map +1 -1
- package/dist/api/meshes/IMesh.d.ts +29 -34
- package/dist/api/meshes/IMesh.d.ts.map +1 -1
- package/dist/api/meshes/IMeshFactory.d.ts +13 -8
- package/dist/api/meshes/IMeshFactory.d.ts.map +1 -1
- package/dist/api/meshes/IRenderableMesh.d.ts +47 -0
- package/dist/api/meshes/IRenderableMesh.d.ts.map +1 -0
- package/dist/api/meshes/Mesh.d.ts +11 -57
- package/dist/api/meshes/Mesh.d.ts.map +1 -1
- package/dist/api/meshes/MeshFactory.d.ts +6 -3
- package/dist/api/meshes/MeshFactory.d.ts.map +1 -1
- package/dist/api/meshes/QuadMesh.d.ts +3 -5
- package/dist/api/meshes/QuadMesh.d.ts.map +1 -1
- package/dist/api/meshes/RenderableMesh.d.ts +95 -0
- package/dist/api/meshes/RenderableMesh.d.ts.map +1 -0
- package/dist/api/meshes/_export.d.ts +2 -1
- package/dist/api/meshes/_export.d.ts.map +1 -1
- package/dist/api/rendering/IGraphicsDeviceFeatures.d.ts +8 -2
- package/dist/api/rendering/IGraphicsDeviceFeatures.d.ts.map +1 -1
- package/dist/api/rendering/IRenderer.d.ts +28 -1
- package/dist/api/rendering/IRenderer.d.ts.map +1 -1
- package/dist/api/rendering/enums.d.ts +7 -0
- package/dist/api/rendering/enums.d.ts.map +1 -1
- package/dist/api/rendering/renderer-interface.d.ts +1 -31
- package/dist/api/rendering/renderer-interface.d.ts.map +1 -1
- package/dist/api/rendering/renderpass/RenderPassDescriptor.d.ts +2 -6
- package/dist/api/rendering/renderpass/RenderPassDescriptor.d.ts.map +1 -1
- package/dist/api/rendering/swapchain/ISwapChain.d.ts +1 -3
- package/dist/api/rendering/swapchain/ISwapChain.d.ts.map +1 -1
- package/dist/api/rendering/texture/TextureFormat.d.ts +88 -14
- package/dist/api/rendering/texture/TextureFormat.d.ts.map +1 -1
- package/dist/api/rendering/texture/TextureUtilities.d.ts +23 -0
- package/dist/api/rendering/texture/TextureUtilities.d.ts.map +1 -1
- package/dist/api/scene/Scene.d.ts +30 -21
- package/dist/api/scene/Scene.d.ts.map +1 -1
- package/dist/api/scene/SceneMesh.d.ts +27 -0
- package/dist/api/scene/SceneMesh.d.ts.map +1 -0
- package/dist/api/utilities/AlignUtilities.d.ts.map +1 -1
- package/dist/api/window/WindowManager.d.ts.map +1 -1
- package/dist/core/rendering/ARenderer.d.ts +5 -5
- package/dist/core/rendering/ARenderer.d.ts.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4006 -1355
- package/dist/webgl/WebGLGraphicsDeviceFeatures.d.ts +4 -0
- package/dist/webgl/WebGLGraphicsDeviceFeatures.d.ts.map +1 -1
- package/dist/webgl/WebGlRenderer.d.ts +1 -3
- package/dist/webgl/WebGlRenderer.d.ts.map +1 -1
- package/dist/webgl/lights/WebGlLightsBuffer.d.ts +8 -4
- package/dist/webgl/lights/WebGlLightsBuffer.d.ts.map +1 -1
- package/dist/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.d.ts +2 -0
- package/dist/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.d.ts.map +1 -1
- package/dist/webgl/swap-chain/WebGlSwapChain.d.ts +3 -2
- package/dist/webgl/swap-chain/WebGlSwapChain.d.ts.map +1 -1
- package/dist/webgl/texture/WebGlTextureFactory.d.ts +7 -0
- package/dist/webgl/texture/WebGlTextureFactory.d.ts.map +1 -1
- package/dist/webgl/utilities/WebGlConstants.d.ts +91 -0
- package/dist/webgl/utilities/WebGlConstants.d.ts.map +1 -0
- package/dist/webgl/utilities/WebGlConverter.d.ts +0 -7
- package/dist/webgl/utilities/WebGlConverter.d.ts.map +1 -1
- package/dist/webgl/utilities/WebGlErrorUtilities.d.ts +10 -0
- package/dist/webgl/utilities/WebGlErrorUtilities.d.ts.map +1 -0
- package/dist/webgl/utilities/WebGlTextureUtilities.d.ts.map +1 -1
- package/dist/webgl/utilities/WebGlUtilities.d.ts +3 -0
- package/dist/webgl/utilities/WebGlUtilities.d.ts.map +1 -1
- package/dist/webgpu/WebGpuGpuInfo.d.ts +28 -0
- package/dist/webgpu/WebGpuGpuInfo.d.ts.map +1 -0
- package/dist/webgpu/WebGpuGraphicsDevice.d.ts +80 -0
- package/dist/webgpu/WebGpuGraphicsDevice.d.ts.map +1 -0
- package/dist/webgpu/WebGpuGraphicsDeviceFeatures.d.ts +26 -0
- package/dist/webgpu/WebGpuGraphicsDeviceFeatures.d.ts.map +1 -0
- package/dist/webgpu/WebGpuRenderer.d.ts +26 -0
- package/dist/webgpu/WebGpuRenderer.d.ts.map +1 -0
- package/dist/webgpu/WebGpuTypes.d.ts +355 -0
- package/dist/webgpu/WebGpuTypes.d.ts.map +1 -0
- package/dist/webgpu/blending/WebGpuBlendState.d.ts +30 -0
- package/dist/webgpu/blending/WebGpuBlendState.d.ts.map +1 -0
- package/dist/webgpu/buffers/WebGpuBuffersFactory.d.ts +20 -0
- package/dist/webgpu/buffers/WebGpuBuffersFactory.d.ts.map +1 -0
- package/dist/webgpu/buffers/WebGpuIndexBuffer.d.ts +46 -0
- package/dist/webgpu/buffers/WebGpuIndexBuffer.d.ts.map +1 -0
- package/dist/webgpu/buffers/WebGpuUniformBuffer.d.ts +43 -0
- package/dist/webgpu/buffers/WebGpuUniformBuffer.d.ts.map +1 -0
- package/dist/webgpu/buffers/WebGpuVertexBuffer.d.ts +49 -0
- package/dist/webgpu/buffers/WebGpuVertexBuffer.d.ts.map +1 -0
- package/dist/webgpu/primitive/WebGpuPrimitiveState.d.ts +32 -0
- package/dist/webgpu/primitive/WebGpuPrimitiveState.d.ts.map +1 -0
- package/dist/webgpu/render-pass/WebGpuRenderPass.d.ts +28 -0
- package/dist/webgpu/render-pass/WebGpuRenderPass.d.ts.map +1 -0
- package/dist/webgpu/render-pipelines/AWebGpuRenderPipeline.d.ts +50 -0
- package/dist/webgpu/render-pipelines/AWebGpuRenderPipeline.d.ts.map +1 -0
- package/dist/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.d.ts +34 -0
- package/dist/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.d.ts.map +1 -0
- package/dist/webgpu/render-pipelines/WebGpuRenderPipelineFactory.d.ts +26 -0
- package/dist/webgpu/render-pipelines/WebGpuRenderPipelineFactory.d.ts.map +1 -0
- package/dist/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.d.ts +72 -0
- package/dist/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.d.ts.map +1 -0
- package/dist/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.d.ts +40 -0
- package/dist/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.d.ts.map +1 -0
- package/dist/webgpu/sampler/WebGpuSampler.d.ts +39 -0
- package/dist/webgpu/sampler/WebGpuSampler.d.ts.map +1 -0
- package/dist/webgpu/shader/WebGpuShaderModule.d.ts +29 -0
- package/dist/webgpu/shader/WebGpuShaderModule.d.ts.map +1 -0
- package/dist/webgpu/shader/WebGpuShaderModuleLoader.d.ts +21 -0
- package/dist/webgpu/shader/WebGpuShaderModuleLoader.d.ts.map +1 -0
- package/dist/webgpu/shader/WgslShaderContent.d.ts +9 -0
- package/dist/webgpu/shader/WgslShaderContent.d.ts.map +1 -0
- package/dist/webgpu/swap-chain/WebGpuSwapChain.d.ts +41 -0
- package/dist/webgpu/swap-chain/WebGpuSwapChain.d.ts.map +1 -0
- package/dist/webgpu/texture/WebGpuTexture2D.d.ts +47 -0
- package/dist/webgpu/texture/WebGpuTexture2D.d.ts.map +1 -0
- package/dist/webgpu/texture/WebGpuTextureFactory.d.ts +21 -0
- package/dist/webgpu/texture/WebGpuTextureFactory.d.ts.map +1 -0
- package/dist/webgpu/texture/WebGpuTextureView.d.ts +25 -0
- package/dist/webgpu/texture/WebGpuTextureView.d.ts.map +1 -0
- package/dist/webgpu/utilities/WebGpuConverter.d.ts +45 -0
- package/dist/webgpu/utilities/WebGpuConverter.d.ts.map +1 -0
- package/package.json +2 -2
- package/shaders/glsl/main_render_target_flip_y_fs.glsl +35 -1
- package/shaders/wgsl/forward_blinn_phong_material.wgsl +150 -0
- package/shaders/wgsl/inspect_texture_mips.wgsl +51 -0
- package/shaders/wgsl/main_frame_buffer.wgsl +35 -0
- package/shaders/wgsl/main_render_target_flip_y.wgsl +35 -0
- package/shaders/wgsl/sprite.wgsl +40 -0
- package/shaders/wgsl/unlit_material.wgsl +49 -0
- package/src/Framework.ts +121 -37
- package/src/api/IFramework.ts +55 -0
- package/src/api/_export.ts +1 -1
- package/src/api/content/ContentManager.ts +46 -180
- package/src/api/content/IContentManager.ts +25 -21
- package/src/api/lights/LightsBuffer.ts +13 -6
- package/src/api/loaders/ObjGeometryMapper.ts +2 -2
- package/src/api/loaders/ObjLoader.ts +126 -0
- package/src/api/loaders/_export.ts +1 -0
- package/src/api/loaders/obj/{ObjLoader.ts → ObjParser.ts} +35 -4
- package/src/api/loaders/obj/ObjTypes.ts +19 -1
- package/src/api/loaders/obj/index.ts +1 -1
- package/src/api/material/ForwardBlinnPhongMaterial.ts +48 -22
- package/src/api/material/ICameraMaterial.ts +22 -0
- package/src/api/material/ILightsMaterial.ts +32 -0
- package/src/api/material/IMaterial.ts +2 -9
- package/src/api/material/InspectTextureMipsMaterial.ts +2 -2
- package/src/api/material/SpriteMaterial.ts +2 -2
- package/src/api/material/UnlitMaterial.ts +4 -3
- package/src/api/material/_export.ts +2 -0
- package/src/api/meshes/IMesh.ts +32 -37
- package/src/api/meshes/IMeshFactory.ts +14 -8
- package/src/api/meshes/IRenderableMesh.ts +58 -0
- package/src/api/meshes/Mesh.ts +17 -132
- package/src/api/meshes/MeshFactory.ts +14 -5
- package/src/api/meshes/QuadMesh.ts +4 -6
- package/src/api/meshes/RenderableMesh.ts +207 -0
- package/src/api/meshes/_export.ts +6 -5
- package/src/api/rendering/IGraphicsDeviceFeatures.ts +28 -21
- package/src/api/rendering/IRenderer.ts +34 -1
- package/src/api/rendering/enums.ts +10 -0
- package/src/api/rendering/renderer-interface.ts +1 -36
- package/src/api/rendering/renderpass/RenderPassDescriptor.ts +10 -14
- package/src/api/rendering/swapchain/ISwapChain.ts +1 -3
- package/src/api/rendering/texture/TextureFormat.ts +128 -14
- package/src/api/rendering/texture/TextureUtilities.ts +225 -10
- package/src/api/scene/Scene.ts +102 -69
- package/src/api/scene/SceneMesh.ts +61 -0
- package/src/api/sprites/SpriteBatchMesh.ts +1 -1
- package/src/api/utilities/AlignUtilities.ts +2 -1
- package/src/api/window/WindowManager.ts +1 -1
- package/src/core/rendering/ARenderer.ts +24 -15
- package/src/index.ts +0 -1
- package/src/main.ts +2 -3
- package/src/webgl/WebGLGraphicsDeviceFeatures.ts +12 -2
- package/src/webgl/WebGlGpuInfo.ts +1 -1
- package/src/webgl/WebGlRenderer.ts +2 -5
- package/src/webgl/lights/WebGlLightsBuffer.ts +14 -4
- package/src/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.ts +18 -1
- package/src/webgl/swap-chain/WebGlSwapChain.ts +7 -6
- package/src/webgl/texture/WebGlTextureFactory.ts +49 -7
- package/src/webgl/utilities/WebGlConstants.ts +136 -0
- package/src/webgl/utilities/WebGlConverter.ts +91 -22
- package/src/webgl/utilities/WebGlErrorUtilities.ts +15 -0
- package/src/webgl/utilities/WebGlTextureUtilities.ts +5 -2
- package/src/webgl/utilities/WebGlUtilities.ts +4 -0
- package/src/webgpu/WebGpuGpuInfo.ts +61 -0
- package/src/webgpu/WebGpuGraphicsDevice.ts +199 -0
- package/src/webgpu/WebGpuGraphicsDeviceFeatures.ts +41 -0
- package/src/webgpu/WebGpuRenderer.ts +49 -0
- package/src/webgpu/WebGpuTypes.ts +288 -0
- package/src/webgpu/blending/WebGpuBlendState.ts +53 -0
- package/src/webgpu/buffers/WebGpuBuffersFactory.ts +46 -0
- package/src/webgpu/buffers/WebGpuIndexBuffer.ts +118 -0
- package/src/webgpu/buffers/WebGpuUniformBuffer.ts +102 -0
- package/src/webgpu/buffers/WebGpuVertexBuffer.ts +119 -0
- package/src/webgpu/primitive/WebGpuPrimitiveState.ts +52 -0
- package/src/webgpu/render-pass/WebGpuRenderPass.ts +131 -0
- package/src/webgpu/render-pipelines/AWebGpuRenderPipeline.ts +123 -0
- package/src/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.ts +119 -0
- package/src/webgpu/render-pipelines/WebGpuRenderPipelineFactory.ts +66 -0
- package/src/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.ts +249 -0
- package/src/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.ts +101 -0
- package/src/webgpu/sampler/WebGpuSampler.ts +84 -0
- package/src/webgpu/shader/WebGpuShaderModule.ts +65 -0
- package/src/webgpu/shader/WebGpuShaderModuleLoader.ts +38 -0
- package/src/webgpu/shader/WgslShaderContent.ts +20 -0
- package/src/webgpu/swap-chain/WebGpuSwapChain.ts +93 -0
- package/src/webgpu/texture/WebGpuTexture2D.ts +197 -0
- package/src/webgpu/texture/WebGpuTextureFactory.ts +118 -0
- package/src/webgpu/texture/WebGpuTextureView.ts +43 -0
- package/src/webgpu/utilities/WebGpuConverter.ts +299 -0
- package/src/wgsl-raw.d.ts +4 -0
- package/dist/api/FrameworkConfiguration.d.ts +0 -23
- package/dist/api/FrameworkConfiguration.d.ts.map +0 -1
- package/dist/api/IFrameworkConfiguration.d.ts +0 -25
- package/dist/api/IFrameworkConfiguration.d.ts.map +0 -1
- package/dist/api/loaders/obj/ObjLoader.d.ts.map +0 -1
- package/dist/api/meshes/SubMesh.d.ts +0 -47
- package/dist/api/meshes/SubMesh.d.ts.map +0 -1
- package/src/api/FrameworkConfiguration.ts +0 -29
- package/src/api/IFrameworkConfiguration.ts +0 -30
- package/src/api/meshes/SubMesh.ts +0 -71
|
@@ -6,7 +6,13 @@ import {VertexBufferLayout} from "../../core/rendering/vertex-buffer-layout";
|
|
|
6
6
|
import type {WebGlTexture2D} from "../texture/WebGlTexture2D.ts";
|
|
7
7
|
import WebGlShaderModule from "../shader/WebGlShaderModule.ts";
|
|
8
8
|
import {AWebGlRenderPipeline} from "./AWebGlRenderPipeline.ts";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
BufferUsage,
|
|
11
|
+
type IFramework,
|
|
12
|
+
type IMainRenderTargetRenderPipeline,
|
|
13
|
+
type ITexture2D,
|
|
14
|
+
TextureFormat
|
|
15
|
+
} from "../../api/index.ts";
|
|
10
16
|
|
|
11
17
|
/**
|
|
12
18
|
* The WebGL implementation of the main render target render pipeline.
|
|
@@ -17,6 +23,9 @@ export class WebGlMainRenderTargetRenderPipeline extends AWebGlRenderPipeline im
|
|
|
17
23
|
private _indexBuffer: WebGLIndexBuffer = null!;
|
|
18
24
|
private _mainRenderTarget: WebGlTexture2D = null!;
|
|
19
25
|
|
|
26
|
+
private _colorConversionUniformLocation: WebGLUniformLocation = null!;
|
|
27
|
+
private _colorSpaceValue = 0;
|
|
28
|
+
|
|
20
29
|
/**
|
|
21
30
|
* The constructor.
|
|
22
31
|
* @param framework The framework.
|
|
@@ -25,6 +34,10 @@ export class WebGlMainRenderTargetRenderPipeline extends AWebGlRenderPipeline im
|
|
|
25
34
|
public constructor(framework: IFramework, mainRenderTarget: ITexture2D) {
|
|
26
35
|
super(framework);
|
|
27
36
|
this._mainRenderTarget = mainRenderTarget as WebGlTexture2D;
|
|
37
|
+
|
|
38
|
+
if(framework.renderer.preferredTextureFormat == TextureFormat.RGBA_8_UNORM_SRGB) {
|
|
39
|
+
this._colorSpaceValue = 1;
|
|
40
|
+
}
|
|
28
41
|
}
|
|
29
42
|
|
|
30
43
|
/** @inheritDoc */
|
|
@@ -55,6 +68,8 @@ export class WebGlMainRenderTargetRenderPipeline extends AWebGlRenderPipeline im
|
|
|
55
68
|
this._createResources();
|
|
56
69
|
this.vertexBufferLayouts = [VertexBufferLayout.createFloat3Float2Layout()];
|
|
57
70
|
super.initialize();
|
|
71
|
+
|
|
72
|
+
this._colorConversionUniformLocation = this._gl.getUniformLocation(this._program, "u_colorConversion")!;
|
|
58
73
|
}
|
|
59
74
|
|
|
60
75
|
private _createResources(): void {
|
|
@@ -93,6 +108,8 @@ export class WebGlMainRenderTargetRenderPipeline extends AWebGlRenderPipeline im
|
|
|
93
108
|
this._gl.bindTexture(this._gl.TEXTURE_2D, this._mainRenderTarget.glTexture);
|
|
94
109
|
this._gl.bindSampler(0, this._defaultTextureSampler.glSampler);
|
|
95
110
|
|
|
111
|
+
this._gl.uniform1i(this._colorConversionUniformLocation, this._colorSpaceValue)
|
|
112
|
+
|
|
96
113
|
this._gl.drawElements(this._gl.TRIANGLES, this._indexBuffer.indicesCount, this._gl.UNSIGNED_SHORT, 0);
|
|
97
114
|
}
|
|
98
115
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {vec2} from "gl-matrix";
|
|
2
2
|
import {type IGraphicsDevice, type ISwapChain, TextureFormat} from "../../api/index.ts";
|
|
3
3
|
import type {WebGlGraphicsDevice} from "../WebGlGraphicsDevice.ts";
|
|
4
4
|
|
|
@@ -16,8 +16,9 @@ export class WebGlSwapChain implements ISwapChain {
|
|
|
16
16
|
* The WebGLSwapChain constructor.
|
|
17
17
|
* @param canvas The HTML canvas element that the swap chain will use for rendering.
|
|
18
18
|
* @param graphicsDevice The graphics device.
|
|
19
|
+
* @param srgb Prefer use of
|
|
19
20
|
*/
|
|
20
|
-
public constructor(canvas: HTMLCanvasElement, graphicsDevice: IGraphicsDevice) {
|
|
21
|
+
public constructor(canvas: HTMLCanvasElement, graphicsDevice: IGraphicsDevice, srgb = true) {
|
|
21
22
|
this._canvas = canvas;
|
|
22
23
|
this._graphicsDevice = graphicsDevice as WebGlGraphicsDevice;
|
|
23
24
|
this._backBufferSize = vec2.fromValues(this._canvas.width, this._canvas.height);
|
|
@@ -25,13 +26,13 @@ export class WebGlSwapChain implements ISwapChain {
|
|
|
25
26
|
this._backBufferSize[0] = this._canvas.width;
|
|
26
27
|
this._backBufferSize[1] = this._canvas.height;
|
|
27
28
|
});
|
|
28
|
-
}
|
|
29
29
|
|
|
30
|
+
// Nothing else to do. Typically, framebuffer should be srgb, but that is already handled through canvas.
|
|
31
|
+
this.textureFormat = srgb ? TextureFormat.RGBA_8_UNORM_SRGB : TextureFormat.RGBA_8_UNORM;
|
|
32
|
+
}
|
|
30
33
|
|
|
31
34
|
/** @inheritdoc */
|
|
32
|
-
public
|
|
33
|
-
return TextureFormat.RGBA_8_UNORM;
|
|
34
|
-
}
|
|
35
|
+
public readonly textureFormat: TextureFormat;
|
|
35
36
|
|
|
36
37
|
/** @inheritdoc */
|
|
37
38
|
public get backBufferSize(): vec2 {
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
TextureUtilities
|
|
10
10
|
} from "../../api/index.ts"
|
|
11
11
|
import {WebGlTexture2D} from "./WebGlTexture2D.ts";
|
|
12
|
-
import {type IKtx2Texture, KtxTranscodeFlags, KtxTranscodeFormat,
|
|
12
|
+
import {type IKtx2Texture, KtxTranscodeFlags, KtxTranscodeFormat, VkFormat} from "ris-ktx2";
|
|
13
13
|
import {vec2} from "gl-matrix";
|
|
14
14
|
|
|
15
15
|
export class WebGlTextureFactory implements ITextureFactory {
|
|
@@ -31,13 +31,13 @@ export class WebGlTextureFactory implements ITextureFactory {
|
|
|
31
31
|
let transcodeFormat = KtxTranscodeFormat.NO_SELECTION;
|
|
32
32
|
let textureFormat = descriptor.textureFormat;
|
|
33
33
|
const gpuFeatures = this._framework.graphicsDevice.features;
|
|
34
|
-
let texFormatInfo: TextureFormatInfo | null = null;
|
|
35
34
|
|
|
36
35
|
if (ktxTexture.needsTranscoding && vkFormat == VkFormat.UNDEFINED)
|
|
37
36
|
{
|
|
38
37
|
// If descriptor format is UNDEFINED, we will use format according to the GPU features.
|
|
39
38
|
if(descriptor.textureFormat == TextureFormat.UNDEFINED)
|
|
40
39
|
{
|
|
40
|
+
// BC7 needs BPTC (supportsTextureCompressionBC), BC3 needs S3TC.
|
|
41
41
|
if(gpuFeatures.supportsTextureCompressionBC)
|
|
42
42
|
{
|
|
43
43
|
transcodeFormat = KtxTranscodeFormat.BC7_RGBA;
|
|
@@ -46,7 +46,7 @@ export class WebGlTextureFactory implements ITextureFactory {
|
|
|
46
46
|
else if(gpuFeatures.supportsTextureCompressionASTC)
|
|
47
47
|
{
|
|
48
48
|
transcodeFormat = KtxTranscodeFormat.ASTC_4X4_RGBA;
|
|
49
|
-
textureFormat = TextureFormat.
|
|
49
|
+
textureFormat = TextureFormat.ASTC_4X4_RGBA_UNORM
|
|
50
50
|
}
|
|
51
51
|
else if(gpuFeatures.supportsTextureCompressionS3TC)
|
|
52
52
|
{
|
|
@@ -58,6 +58,16 @@ export class WebGlTextureFactory implements ITextureFactory {
|
|
|
58
58
|
transcodeFormat = KtxTranscodeFormat.ETC2_RGBA;
|
|
59
59
|
textureFormat = TextureFormat.ETC2_RGBA8_UNORM;
|
|
60
60
|
}
|
|
61
|
+
else if(gpuFeatures.supportsTextureCompressionPVRTC)
|
|
62
|
+
{
|
|
63
|
+
transcodeFormat = KtxTranscodeFormat.PVRTC1_4_RGBA;
|
|
64
|
+
textureFormat = TextureFormat.PVRTC_4BPPV1_RGBA;
|
|
65
|
+
}
|
|
66
|
+
else
|
|
67
|
+
{
|
|
68
|
+
transcodeFormat = KtxTranscodeFormat.RGBA32;
|
|
69
|
+
textureFormat = TextureFormat.RGBA_8_UNORM;
|
|
70
|
+
}
|
|
61
71
|
}
|
|
62
72
|
else
|
|
63
73
|
{
|
|
@@ -65,12 +75,23 @@ export class WebGlTextureFactory implements ITextureFactory {
|
|
|
65
75
|
}
|
|
66
76
|
|
|
67
77
|
ktxTexture.transcodeBasis(transcodeFormat, KtxTranscodeFlags.HIGH_QUALITY);
|
|
68
|
-
|
|
78
|
+
|
|
79
|
+
// After transcoding, libktx reports the sRGB vkFormat when the file's DFD transfer function is sRGB.
|
|
80
|
+
if (descriptor.textureFormat == TextureFormat.UNDEFINED && WebGlTextureFactory._isSrgbVkFormat(ktxTexture.vkFormat))
|
|
81
|
+
{
|
|
82
|
+
textureFormat = TextureUtilities.toSrgbFormat(textureFormat);
|
|
83
|
+
}
|
|
69
84
|
}
|
|
70
85
|
else {
|
|
71
|
-
// No transcoding path,
|
|
86
|
+
// No transcoding path, the vkFormat already says linear or sRGB.
|
|
72
87
|
textureFormat = TextureUtilities.convertVkFormatToTextureFormat(vkFormat);
|
|
73
|
-
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
textureFormat = this._ensureSrgbSupported(textureFormat, ktxTexture.filePath);
|
|
91
|
+
|
|
92
|
+
const blockSize = TextureUtilities.getBlockSize(textureFormat);
|
|
93
|
+
if (!blockSize) {
|
|
94
|
+
throw new Error(`Unknown block size for texture format ${textureFormat}.`);
|
|
74
95
|
}
|
|
75
96
|
|
|
76
97
|
const data: Uint8Array[] = [];
|
|
@@ -85,13 +106,34 @@ export class WebGlTextureFactory implements ITextureFactory {
|
|
|
85
106
|
textureDescriptor.data = data;
|
|
86
107
|
textureDescriptor.textureFormat = textureFormat;
|
|
87
108
|
textureDescriptor.generateMipmaps = descriptor.generateMipmaps;
|
|
88
|
-
textureDescriptor.blockSize = vec2.fromValues(
|
|
109
|
+
textureDescriptor.blockSize = vec2.fromValues(blockSize[0], blockSize[1]);
|
|
89
110
|
|
|
90
111
|
const texture = new WebGlTexture2D(this._framework, textureDescriptor);
|
|
91
112
|
texture.initialize();
|
|
92
113
|
return texture;
|
|
93
114
|
}
|
|
94
115
|
|
|
116
|
+
/** Whether the Vulkan format is an sRGB format. */
|
|
117
|
+
private static _isSrgbVkFormat(vkFormat: VkFormat): boolean {
|
|
118
|
+
const name = (VkFormat as unknown as Record<number, string>)[vkFormat];
|
|
119
|
+
return typeof name === "string" && name.includes("_SRGB");
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Falls back to the linear variant (with a warning) when the GPU cannot sample the sRGB format.
|
|
124
|
+
* Only S3TC sRGB (BC1/BC3) has its own WebGL extension; BC7, ETC2 and ASTC sRGB ship with their base extension.
|
|
125
|
+
*/
|
|
126
|
+
private _ensureSrgbSupported(textureFormat: TextureFormat, source?: string): TextureFormat {
|
|
127
|
+
const isS3tcSrgb = textureFormat === TextureFormat.BC3_RGBA_SRGB || textureFormat === TextureFormat.BC1_RGB_SRGB;
|
|
128
|
+
if (isS3tcSrgb && !this._framework.graphicsDevice.features.supportsTextureCompressionS3TCSrgb) {
|
|
129
|
+
const linear = TextureUtilities.toLinearFormat(textureFormat);
|
|
130
|
+
console.warn(`sRGB S3TC is not supported (WEBGL_compressed_texture_s3tc_srgb missing); ` +
|
|
131
|
+
`loading ${source ?? "texture"} as ${linear}. Colours will look washed out.`);
|
|
132
|
+
return linear;
|
|
133
|
+
}
|
|
134
|
+
return textureFormat;
|
|
135
|
+
}
|
|
136
|
+
|
|
95
137
|
/** @inheritdoc */
|
|
96
138
|
public create(
|
|
97
139
|
width: number, height: number,
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebGL extension constants that WebGL2RenderingContext does not expose.
|
|
3
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants
|
|
4
|
+
*/
|
|
5
|
+
export class WebGlConstants {
|
|
6
|
+
|
|
7
|
+
/** BC1 RGB */
|
|
8
|
+
public static readonly GL_COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83F0;
|
|
9
|
+
|
|
10
|
+
/** BC1 RGB sRGB (WEBGL_compressed_texture_s3tc_srgb) */
|
|
11
|
+
public static readonly GL_COMPRESSED_SRGB_S3TC_DXT1_EXT = 0x8C4C;
|
|
12
|
+
|
|
13
|
+
/** BC3 sRGB (WEBGL_compressed_texture_s3tc_srgb) */
|
|
14
|
+
public static readonly GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT = 0x8C4F;
|
|
15
|
+
|
|
16
|
+
/** BC7 sRGB (EXT_texture_compression_bptc) */
|
|
17
|
+
public static readonly GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM = 0x8E8D;
|
|
18
|
+
|
|
19
|
+
/** ETC2 RGB8 */
|
|
20
|
+
public static readonly GL_COMPRESSED_RGB8_ETC2 = 0x9274;
|
|
21
|
+
|
|
22
|
+
/** ETC2 RGB8 sRGB */
|
|
23
|
+
public static readonly GL_COMPRESSED_SRGB8_ETC2 = 0x9275;
|
|
24
|
+
|
|
25
|
+
/** ETC2 RGBA8 sRGB */
|
|
26
|
+
public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = 0x9279;
|
|
27
|
+
|
|
28
|
+
/** BC3 */
|
|
29
|
+
public static readonly GL_COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83F3;
|
|
30
|
+
|
|
31
|
+
/** BC7 */
|
|
32
|
+
public static readonly GL_COMPRESSED_RGBA_BPTC_UNORM = 0x8E8C;
|
|
33
|
+
|
|
34
|
+
/** ETC2 */
|
|
35
|
+
public static readonly GL_COMPRESSED_RGBA8_ETC2_EAC = 0x9278;
|
|
36
|
+
|
|
37
|
+
// ASTC (WEBGL_compressed_texture_astc).
|
|
38
|
+
|
|
39
|
+
/** ASTC 4x4 */
|
|
40
|
+
public static readonly GL_COMPRESSED_RGBA_ASTC_4x4_KHR = 0x93B0;
|
|
41
|
+
|
|
42
|
+
/** ASTC 4x4 sRGB */
|
|
43
|
+
public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR = 0x93D0;
|
|
44
|
+
|
|
45
|
+
/** ASTC 5x4 */
|
|
46
|
+
public static readonly GL_COMPRESSED_RGBA_ASTC_5x4_KHR = 0x93B1;
|
|
47
|
+
|
|
48
|
+
/** ASTC 5x4 sRGB */
|
|
49
|
+
public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR = 0x93D1;
|
|
50
|
+
|
|
51
|
+
/** ASTC 5x5 */
|
|
52
|
+
public static readonly GL_COMPRESSED_RGBA_ASTC_5x5_KHR = 0x93B2;
|
|
53
|
+
|
|
54
|
+
/** ASTC 5x5 sRGB */
|
|
55
|
+
public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR = 0x93D2;
|
|
56
|
+
|
|
57
|
+
/** ASTC 6x5 */
|
|
58
|
+
public static readonly GL_COMPRESSED_RGBA_ASTC_6x5_KHR = 0x93B3;
|
|
59
|
+
|
|
60
|
+
/** ASTC 6x5 sRGB */
|
|
61
|
+
public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR = 0x93D3;
|
|
62
|
+
|
|
63
|
+
/** ASTC 6x6 */
|
|
64
|
+
public static readonly GL_COMPRESSED_RGBA_ASTC_6x6_KHR = 0x93B4;
|
|
65
|
+
|
|
66
|
+
/** ASTC 6x6 sRGB */
|
|
67
|
+
public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR = 0x93D4;
|
|
68
|
+
|
|
69
|
+
/** ASTC 8x5 */
|
|
70
|
+
public static readonly GL_COMPRESSED_RGBA_ASTC_8x5_KHR = 0x93B5;
|
|
71
|
+
|
|
72
|
+
/** ASTC 8x5 sRGB */
|
|
73
|
+
public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR = 0x93D5;
|
|
74
|
+
|
|
75
|
+
/** ASTC 8x6 */
|
|
76
|
+
public static readonly GL_COMPRESSED_RGBA_ASTC_8x6_KHR = 0x93B6;
|
|
77
|
+
|
|
78
|
+
/** ASTC 8x6 sRGB */
|
|
79
|
+
public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR = 0x93D6;
|
|
80
|
+
|
|
81
|
+
/** ASTC 8x8 */
|
|
82
|
+
public static readonly GL_COMPRESSED_RGBA_ASTC_8x8_KHR = 0x93B7;
|
|
83
|
+
|
|
84
|
+
/** ASTC 8x8 sRGB */
|
|
85
|
+
public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR = 0x93D7;
|
|
86
|
+
|
|
87
|
+
/** ASTC 10x5 */
|
|
88
|
+
public static readonly GL_COMPRESSED_RGBA_ASTC_10x5_KHR = 0x93B8;
|
|
89
|
+
|
|
90
|
+
/** ASTC 10x5 sRGB */
|
|
91
|
+
public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR = 0x93D8;
|
|
92
|
+
|
|
93
|
+
/** ASTC 10x6 */
|
|
94
|
+
public static readonly GL_COMPRESSED_RGBA_ASTC_10x6_KHR = 0x93B9;
|
|
95
|
+
|
|
96
|
+
/** ASTC 10x6 sRGB */
|
|
97
|
+
public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR = 0x93D9;
|
|
98
|
+
|
|
99
|
+
/** ASTC 10x8 */
|
|
100
|
+
public static readonly GL_COMPRESSED_RGBA_ASTC_10x8_KHR = 0x93BA;
|
|
101
|
+
|
|
102
|
+
/** ASTC 10x8 sRGB */
|
|
103
|
+
public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR = 0x93DA;
|
|
104
|
+
|
|
105
|
+
/** ASTC 10x10 */
|
|
106
|
+
public static readonly GL_COMPRESSED_RGBA_ASTC_10x10_KHR = 0x93BB;
|
|
107
|
+
|
|
108
|
+
/** ASTC 10x10 sRGB */
|
|
109
|
+
public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR = 0x93DB;
|
|
110
|
+
|
|
111
|
+
/** ASTC 12x10 */
|
|
112
|
+
public static readonly GL_COMPRESSED_RGBA_ASTC_12x10_KHR = 0x93BC;
|
|
113
|
+
|
|
114
|
+
/** ASTC 12x10 sRGB */
|
|
115
|
+
public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR = 0x93DC;
|
|
116
|
+
|
|
117
|
+
/** ASTC 12x12 */
|
|
118
|
+
public static readonly GL_COMPRESSED_RGBA_ASTC_12x12_KHR = 0x93BD;
|
|
119
|
+
|
|
120
|
+
/** ASTC 12x12 sRGB */
|
|
121
|
+
public static readonly GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR = 0x93DD;
|
|
122
|
+
|
|
123
|
+
// PVRTC (WEBGL_compressed_texture_pvrtc).
|
|
124
|
+
|
|
125
|
+
/** PVRTC 4 bits per pixel, RGB */
|
|
126
|
+
public static readonly GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 0x8C00;
|
|
127
|
+
|
|
128
|
+
/** PVRTC 2 bits per pixel, RGB */
|
|
129
|
+
public static readonly GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG = 0x8C01;
|
|
130
|
+
|
|
131
|
+
/** PVRTC 4 bits per pixel, RGBA */
|
|
132
|
+
public static readonly GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 0x8C02;
|
|
133
|
+
|
|
134
|
+
/** PVRTC 2 bits per pixel, RGBA */
|
|
135
|
+
public static readonly GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG = 0x8C03;
|
|
136
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {WebGlConstants} from "./WebGlConstants.ts";
|
|
1
2
|
import {Culling} from "../../api/rendering/enums.ts";
|
|
2
3
|
import {BlendFactor, BlendOperation} from "../../core/rendering/blending/enums";
|
|
3
4
|
import {VertexFormat} from "../../api/geometry/VertexFormat.ts";
|
|
@@ -14,20 +15,6 @@ import {
|
|
|
14
15
|
|
|
15
16
|
export class WebGlConverter {
|
|
16
17
|
|
|
17
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants
|
|
18
|
-
|
|
19
|
-
/** BC3 */
|
|
20
|
-
private static GL_COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83F3;
|
|
21
|
-
|
|
22
|
-
/** BC7 */
|
|
23
|
-
private static GL_COMPRESSED_RGBA_BPTC_UNORM = 0x8E8C;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
/** ETC2 */
|
|
27
|
-
private static GL_COMPRESSED_RGBA8_ETC2_EAC = 0x9278;
|
|
28
|
-
|
|
29
|
-
private static GL_COMPRESSED_RGBA_ASTC_4x4_KHR = 0x93B0;
|
|
30
|
-
|
|
31
18
|
/**
|
|
32
19
|
* Converts PrimitiveTopology to WebGL enum.
|
|
33
20
|
* @param topology The PrimitiveTopology.
|
|
@@ -65,7 +52,8 @@ export class WebGlConverter {
|
|
|
65
52
|
return WebGL2RenderingContext.BACK;
|
|
66
53
|
case CullMode.FRONT:
|
|
67
54
|
return WebGL2RenderingContext.FRONT;
|
|
68
|
-
default:
|
|
55
|
+
default:
|
|
56
|
+
throw new Error("Method not implemented.");
|
|
69
57
|
}
|
|
70
58
|
|
|
71
59
|
}
|
|
@@ -95,13 +83,13 @@ export class WebGlConverter {
|
|
|
95
83
|
|
|
96
84
|
let bufferUsage: number = WebGL2RenderingContext.STATIC_DRAW;
|
|
97
85
|
|
|
98
|
-
if((usage & BufferUsage.COPY_DST) == BufferUsage.COPY_DST)
|
|
99
|
-
{
|
|
86
|
+
if ((usage & BufferUsage.COPY_DST) == BufferUsage.COPY_DST) {
|
|
100
87
|
bufferUsage = WebGL2RenderingContext.DYNAMIC_DRAW;
|
|
101
88
|
}
|
|
102
89
|
|
|
103
90
|
return bufferUsage;
|
|
104
91
|
}
|
|
92
|
+
|
|
105
93
|
/**
|
|
106
94
|
* Converts BlendOperation to WebGL enum.
|
|
107
95
|
* @param gl The WebGL2RenderingContext.
|
|
@@ -195,13 +183,94 @@ export class WebGlConverter {
|
|
|
195
183
|
case TextureFormat.DEPTH_24_STENCIL_8:
|
|
196
184
|
return gl.DEPTH24_STENCIL8;
|
|
197
185
|
case TextureFormat.BC3_RGBA_UNORM:
|
|
198
|
-
return
|
|
186
|
+
return WebGlConstants.GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
|
199
187
|
case TextureFormat.ETC2_RGBA8_UNORM:
|
|
200
|
-
return
|
|
188
|
+
return WebGlConstants.GL_COMPRESSED_RGBA8_ETC2_EAC;
|
|
201
189
|
case TextureFormat.BC7_RGBA_UNORM:
|
|
202
|
-
return
|
|
203
|
-
case TextureFormat.
|
|
204
|
-
return
|
|
190
|
+
return WebGlConstants.GL_COMPRESSED_RGBA_BPTC_UNORM;
|
|
191
|
+
case TextureFormat.BC7_RGBA_SRGB:
|
|
192
|
+
return WebGlConstants.GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM;
|
|
193
|
+
case TextureFormat.BC3_RGBA_SRGB:
|
|
194
|
+
return WebGlConstants.GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
|
|
195
|
+
case TextureFormat.BC1_RGB_UNORM:
|
|
196
|
+
return WebGlConstants.GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
|
|
197
|
+
case TextureFormat.BC1_RGB_SRGB:
|
|
198
|
+
return WebGlConstants.GL_COMPRESSED_SRGB_S3TC_DXT1_EXT;
|
|
199
|
+
case TextureFormat.ETC2_RGBA8_SRGB:
|
|
200
|
+
return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
|
|
201
|
+
case TextureFormat.ETC2_RGB8_UNORM:
|
|
202
|
+
return WebGlConstants.GL_COMPRESSED_RGB8_ETC2;
|
|
203
|
+
case TextureFormat.ETC2_RGB8_SRGB:
|
|
204
|
+
return WebGlConstants.GL_COMPRESSED_SRGB8_ETC2;
|
|
205
|
+
|
|
206
|
+
// ASTC
|
|
207
|
+
case TextureFormat.ASTC_4X4_RGBA_UNORM:
|
|
208
|
+
return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_4x4_KHR;
|
|
209
|
+
case TextureFormat.ASTC_4X4_RGBA_SRGB:
|
|
210
|
+
return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
|
|
211
|
+
case TextureFormat.ASTC_5X4_RGBA_UNORM:
|
|
212
|
+
return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_5x4_KHR;
|
|
213
|
+
case TextureFormat.ASTC_5X4_RGBA_SRGB:
|
|
214
|
+
return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR;
|
|
215
|
+
case TextureFormat.ASTC_5X5_RGBA_UNORM:
|
|
216
|
+
return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_5x5_KHR;
|
|
217
|
+
case TextureFormat.ASTC_5X5_RGBA_SRGB:
|
|
218
|
+
return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR;
|
|
219
|
+
case TextureFormat.ASTC_6X5_RGBA_UNORM:
|
|
220
|
+
return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_6x5_KHR;
|
|
221
|
+
case TextureFormat.ASTC_6X5_RGBA_SRGB:
|
|
222
|
+
return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR;
|
|
223
|
+
case TextureFormat.ASTC_6X6_RGBA_UNORM:
|
|
224
|
+
return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_6x6_KHR;
|
|
225
|
+
case TextureFormat.ASTC_6X6_RGBA_SRGB:
|
|
226
|
+
return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR;
|
|
227
|
+
case TextureFormat.ASTC_8X5_RGBA_UNORM:
|
|
228
|
+
return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_8x5_KHR;
|
|
229
|
+
case TextureFormat.ASTC_8X5_RGBA_SRGB:
|
|
230
|
+
return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR;
|
|
231
|
+
case TextureFormat.ASTC_8X6_RGBA_UNORM:
|
|
232
|
+
return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_8x6_KHR;
|
|
233
|
+
case TextureFormat.ASTC_8X6_RGBA_SRGB:
|
|
234
|
+
return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR;
|
|
235
|
+
case TextureFormat.ASTC_8X8_RGBA_UNORM:
|
|
236
|
+
return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_8x8_KHR;
|
|
237
|
+
case TextureFormat.ASTC_8X8_RGBA_SRGB:
|
|
238
|
+
return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR;
|
|
239
|
+
case TextureFormat.ASTC_10X5_RGBA_UNORM:
|
|
240
|
+
return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_10x5_KHR;
|
|
241
|
+
case TextureFormat.ASTC_10X5_RGBA_SRGB:
|
|
242
|
+
return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR;
|
|
243
|
+
case TextureFormat.ASTC_10X6_RGBA_UNORM:
|
|
244
|
+
return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_10x6_KHR;
|
|
245
|
+
case TextureFormat.ASTC_10X6_RGBA_SRGB:
|
|
246
|
+
return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR;
|
|
247
|
+
case TextureFormat.ASTC_10X8_RGBA_UNORM:
|
|
248
|
+
return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_10x8_KHR;
|
|
249
|
+
case TextureFormat.ASTC_10X8_RGBA_SRGB:
|
|
250
|
+
return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR;
|
|
251
|
+
case TextureFormat.ASTC_10X10_RGBA_UNORM:
|
|
252
|
+
return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_10x10_KHR;
|
|
253
|
+
case TextureFormat.ASTC_10X10_RGBA_SRGB:
|
|
254
|
+
return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR;
|
|
255
|
+
case TextureFormat.ASTC_12X10_RGBA_UNORM:
|
|
256
|
+
return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_12x10_KHR;
|
|
257
|
+
case TextureFormat.ASTC_12X10_RGBA_SRGB:
|
|
258
|
+
return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR;
|
|
259
|
+
case TextureFormat.ASTC_12X12_RGBA_UNORM:
|
|
260
|
+
return WebGlConstants.GL_COMPRESSED_RGBA_ASTC_12x12_KHR;
|
|
261
|
+
case TextureFormat.ASTC_12X12_RGBA_SRGB:
|
|
262
|
+
return WebGlConstants.GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR;
|
|
263
|
+
|
|
264
|
+
// PVRTC
|
|
265
|
+
case TextureFormat.PVRTC_4BPPV1_RGBA:
|
|
266
|
+
return WebGlConstants.GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
|
|
267
|
+
case TextureFormat.PVRTC_4BPPV1_RGB:
|
|
268
|
+
return WebGlConstants.GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
|
|
269
|
+
|
|
270
|
+
case TextureFormat.PVRTC_2BPPV1_RGBA:
|
|
271
|
+
return WebGlConstants.GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
|
|
272
|
+
case TextureFormat.PVRTC_2BPPV1_RGB:
|
|
273
|
+
return WebGlConstants.GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
|
|
205
274
|
|
|
206
275
|
default:
|
|
207
276
|
throw new Error("NotImplementedException");
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export class WebGlErrorUtilities {
|
|
2
|
+
|
|
3
|
+
private readonly _map: Record<number, string> = {
|
|
4
|
+
1282: "INVALID_OPERATION"
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Maps the WebGL2 error code to string.
|
|
9
|
+
* @param error The error code.
|
|
10
|
+
* @return The string of error code.
|
|
11
|
+
*/
|
|
12
|
+
public errorToStr(error: number) : string {
|
|
13
|
+
return this._map[error] ?? error.toString();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {WebGlConverter} from "./WebGlConverter.ts";
|
|
2
2
|
import {AlignUtilities, TextureFormat} from "../../api/index.ts";
|
|
3
3
|
import {vec2} from "gl-matrix";
|
|
4
|
+
import {WebGlUtilities} from "./WebGlUtilities.ts";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* The utilities for working with WebGL textures.
|
|
@@ -120,8 +121,8 @@ export class WebGlTextureUtilities {
|
|
|
120
121
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
121
122
|
|
|
122
123
|
const internalFormat = WebGlConverter.convertInternalFormat(gl, textureFormat);
|
|
123
|
-
|
|
124
124
|
const useTexStorage = baseWidth % blockSize[0] == 0 && baseHeight % blockSize[1] == 0;
|
|
125
|
+
|
|
125
126
|
if (useTexStorage) {
|
|
126
127
|
gl.texStorage2D(gl.TEXTURE_2D, mipLevels, internalFormat, baseWidth, baseHeight);
|
|
127
128
|
}
|
|
@@ -163,7 +164,9 @@ export class WebGlTextureUtilities {
|
|
|
163
164
|
|
|
164
165
|
const error = gl.getError();
|
|
165
166
|
if (error != gl.NO_ERROR) {
|
|
166
|
-
|
|
167
|
+
const errorStr ="WebGlTextureUtilities error " + WebGlUtilities.error.errorToStr(error);
|
|
168
|
+
console.error(errorStr);
|
|
169
|
+
throw new Error(errorStr);
|
|
167
170
|
}
|
|
168
171
|
|
|
169
172
|
return texture;
|
|
@@ -8,6 +8,7 @@ import { WebGLRenderbufferUtilities } from "./webgl-renderbuffer-utilities";
|
|
|
8
8
|
import { WebGlSamplerUtilities } from "./WebGlSamplerUtilities.ts";
|
|
9
9
|
import { WebGlShaderUtilities } from "./WebGlShaderUtilities.ts";
|
|
10
10
|
import { WebGlTextureUtilities } from "./WebGlTextureUtilities.ts";
|
|
11
|
+
import {WebGlErrorUtilities} from "./WebGlErrorUtilities.ts";
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* The utility class for WebGL operations.
|
|
@@ -68,4 +69,7 @@ export class WebGlUtilities {
|
|
|
68
69
|
* The WebGL program utilities.
|
|
69
70
|
*/
|
|
70
71
|
public static readonly program = new WebGLProgramUtilities();
|
|
72
|
+
|
|
73
|
+
/** The WebGL error utilities. Helper class for working with errors. */
|
|
74
|
+
public static readonly error = new WebGlErrorUtilities();
|
|
71
75
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {type IGPUInfo, RenderingBackend, TextureFormat} from "../api/index.ts";
|
|
2
|
+
import type {GpuAdapter} from "./WebGpuTypes.ts";
|
|
3
|
+
import type {WebGpuGraphicsDeviceFeatures} from "./WebGpuGraphicsDeviceFeatures.ts";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The WebGPU GPU info, read from the adapter info.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export class WebGpuGpuInfo implements IGPUInfo {
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The constructor.
|
|
13
|
+
* @param adapter The adapter.
|
|
14
|
+
* @param features The device features.
|
|
15
|
+
*/
|
|
16
|
+
public constructor(adapter: GpuAdapter, features: WebGpuGraphicsDeviceFeatures) {
|
|
17
|
+
const info = adapter.info;
|
|
18
|
+
this.name = info?.description || info?.device || info?.architecture || "Unknown";
|
|
19
|
+
this.vendor = info?.vendor || "Unknown";
|
|
20
|
+
this.apiVersion = "WebGPU";
|
|
21
|
+
this.api = RenderingBackend.WEB_GPU;
|
|
22
|
+
// The native API behind WebGPU (Vulkan, Metal, D3D12) is hidden from the page.
|
|
23
|
+
this.underlyingBackend = RenderingBackend.DEFAULT;
|
|
24
|
+
|
|
25
|
+
// Features are read from the device (only requested features are enabled), so this lists what can be created.
|
|
26
|
+
const formats: TextureFormat[] = [];
|
|
27
|
+
if (features.supportsTextureCompressionASTC) {
|
|
28
|
+
formats.push(TextureFormat.ASTC_4X4_RGBA_UNORM, TextureFormat.ASTC_4X4_RGBA_SRGB);
|
|
29
|
+
}
|
|
30
|
+
if (features.supportsTextureCompressionS3TC) {
|
|
31
|
+
formats.push(TextureFormat.BC1_RGB_UNORM, TextureFormat.BC1_RGB_SRGB,
|
|
32
|
+
TextureFormat.BC3_RGBA_UNORM, TextureFormat.BC3_RGBA_SRGB);
|
|
33
|
+
}
|
|
34
|
+
if (features.supportsTextureCompressionETC2) {
|
|
35
|
+
formats.push(TextureFormat.ETC2_RGB8_UNORM, TextureFormat.ETC2_RGB8_SRGB,
|
|
36
|
+
TextureFormat.ETC2_RGBA8_UNORM, TextureFormat.ETC2_RGBA8_SRGB);
|
|
37
|
+
}
|
|
38
|
+
if (features.supportsTextureCompressionBC) {
|
|
39
|
+
formats.push(TextureFormat.BC7_RGBA_UNORM, TextureFormat.BC7_RGBA_SRGB);
|
|
40
|
+
}
|
|
41
|
+
this.supportedCompressedTextureFormats = formats;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** @inheritDoc */
|
|
45
|
+
public readonly name: string;
|
|
46
|
+
|
|
47
|
+
/** @inheritDoc */
|
|
48
|
+
public readonly vendor: string;
|
|
49
|
+
|
|
50
|
+
/** @inheritDoc */
|
|
51
|
+
public readonly apiVersion: string;
|
|
52
|
+
|
|
53
|
+
/** @inheritDoc */
|
|
54
|
+
public readonly api: RenderingBackend;
|
|
55
|
+
|
|
56
|
+
/** @inheritDoc */
|
|
57
|
+
public readonly underlyingBackend: RenderingBackend;
|
|
58
|
+
|
|
59
|
+
/** @inheritDoc */
|
|
60
|
+
public readonly supportedCompressedTextureFormats: TextureFormat[];
|
|
61
|
+
}
|