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,14 @@
|
|
|
1
|
+
#version 300 es
|
|
2
|
+
precision mediump float;
|
|
3
|
+
|
|
4
|
+
in vec4 v_color;
|
|
5
|
+
in vec2 v_texCoords;
|
|
6
|
+
|
|
7
|
+
layout(location = 0) out vec4 o_outputColor;
|
|
8
|
+
|
|
9
|
+
uniform sampler2D u_texture;
|
|
10
|
+
|
|
11
|
+
void main()
|
|
12
|
+
{
|
|
13
|
+
o_outputColor = texture(u_texture, v_texCoords) * v_color;
|
|
14
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#version 300 es
|
|
2
|
+
|
|
3
|
+
layout(location = 0) in vec3 a_position;
|
|
4
|
+
layout(location = 1) in vec4 a_color;
|
|
5
|
+
layout(location = 2) in vec2 a_texCoord;
|
|
6
|
+
|
|
7
|
+
out vec4 v_color;
|
|
8
|
+
out vec2 v_texCoords;
|
|
9
|
+
|
|
10
|
+
layout(std140) uniform CameraBuffer
|
|
11
|
+
{
|
|
12
|
+
mat4 u_projectionView;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
void main()
|
|
16
|
+
{
|
|
17
|
+
gl_Position = u_projectionView * vec4(a_position, 1.0);
|
|
18
|
+
v_color = a_color;
|
|
19
|
+
v_texCoords = a_texCoord;
|
|
20
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#version 300 es
|
|
2
|
+
precision mediump float;
|
|
3
|
+
|
|
4
|
+
in vec4 v_color;
|
|
5
|
+
in vec2 v_texCoords;
|
|
6
|
+
|
|
7
|
+
layout(location = 0) out vec4 o_outputColor;
|
|
8
|
+
|
|
9
|
+
layout(std140) uniform MaterialBuffer
|
|
10
|
+
{
|
|
11
|
+
vec4 diffuseColor;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
uniform sampler2D u_texture;
|
|
15
|
+
|
|
16
|
+
void main()
|
|
17
|
+
{
|
|
18
|
+
o_outputColor = texture(u_texture, v_texCoords) * v_color * diffuseColor;
|
|
19
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#version 300 es
|
|
2
|
+
|
|
3
|
+
layout(location = 0) in vec3 a_position;
|
|
4
|
+
layout(location = 1) in vec4 a_color;
|
|
5
|
+
layout(location = 2) in vec2 a_texCoord;
|
|
6
|
+
|
|
7
|
+
out vec4 v_color;
|
|
8
|
+
out vec2 v_texCoords;
|
|
9
|
+
|
|
10
|
+
layout(std140) uniform CameraBuffer
|
|
11
|
+
{
|
|
12
|
+
mat4 projectionView;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
layout(std140) uniform ModelBuffer
|
|
16
|
+
{
|
|
17
|
+
mat4 model;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
void main()
|
|
21
|
+
{
|
|
22
|
+
gl_Position = projectionView * model * vec4(a_position, 1.0);
|
|
23
|
+
v_color = a_color;
|
|
24
|
+
v_texCoords = a_texCoord;
|
|
25
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The vertex format. Used to describe the format of a vertex attribute.
|
|
3
|
+
*/
|
|
4
|
+
export enum VertexFormat {
|
|
5
|
+
FLOAT_32 = 0,
|
|
6
|
+
|
|
7
|
+
FLOAT_32X2 = 1,
|
|
8
|
+
|
|
9
|
+
FLOAT_32X3 = 2,
|
|
10
|
+
|
|
11
|
+
FLOAT_32X4 = 3,
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The format of a 32-bit float with 16 components. Used for matrix attributes.
|
|
15
|
+
*/
|
|
16
|
+
FLOAT_32X16 = 4
|
|
17
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The compare function to use when sampling a texture. This is used for depth textures and determines how the sampled depth value is compared to the reference value.
|
|
5
|
+
*/
|
|
6
|
+
export enum SamplerCompareFunction {
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The sampled depth value is never less than the reference value.
|
|
10
|
+
* This means that the comparison will always fail, and the texture will not contribute to the final image.
|
|
11
|
+
*/
|
|
12
|
+
Never,
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The sampled depth value is less than the reference value.
|
|
16
|
+
* This means that the comparison will pass if the sampled depth value is less than the reference value, and the texture will contribute to the final image.
|
|
17
|
+
*/
|
|
18
|
+
LessEqual,
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export enum VertexStepMode {
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The vertex buffer is stepped through once per vertex. This is the default step mode.
|
|
5
|
+
*/
|
|
6
|
+
Vertex = 0,
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The vertex buffer is stepped through once per instance. This is used for instanced rendering.
|
|
10
|
+
*/
|
|
11
|
+
Instance = 1,
|
|
12
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import mainRenderTargetFlipYVS from "../../shaders/glsl/main_render_target_flip_y_vs.glsl?raw";
|
|
2
|
+
import mainRenderTargetFlipYFS from "../../shaders/glsl/main_render_target_flip_y_fs.glsl?raw";
|
|
3
|
+
import spriteVS from "../../shaders/glsl/sprite_vs.glsl?raw";
|
|
4
|
+
import spriteFS from "../../shaders/glsl/sprite_fs.glsl?raw";
|
|
5
|
+
import inspectTextureMipsVS from "../../shaders/glsl/inspect_texture_mips_vs.glsl?raw";
|
|
6
|
+
import inspectTextureMipsFS from "../../shaders/glsl/inspect_texture_mips_fs.glsl?raw";
|
|
7
|
+
import unlitMaterialVS from "../../shaders/glsl/unlit_material_vs.glsl?raw";
|
|
8
|
+
import unlitMaterialFS from "../../shaders/glsl/unlit_material_fs.glsl?raw";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The api should look something like this for internal ones.
|
|
12
|
+
* export const ShaderContent = {
|
|
13
|
+
* "example_shader": {
|
|
14
|
+
* "shader": "{combined_shader}", // WebGPU
|
|
15
|
+
* "vertex": "{some_vertex_code}", // WebGL
|
|
16
|
+
* "fragment": "{some_fragment_code}", // WebGL
|
|
17
|
+
* "reflection": "{reflection_object}", // Both
|
|
18
|
+
* }
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
export const ShaderModuleContent : {[id: string]: any} = {
|
|
23
|
+
|
|
24
|
+
"main_render_target_flip_y": {
|
|
25
|
+
"vertex": mainRenderTargetFlipYVS,
|
|
26
|
+
"fragment": mainRenderTargetFlipYFS,
|
|
27
|
+
"reflection": {}
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
"sprite": {
|
|
31
|
+
"vertex": spriteVS,
|
|
32
|
+
"fragment": spriteFS,
|
|
33
|
+
"reflection": {}
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
"inspect_texture_mips": {
|
|
37
|
+
"vertex": inspectTextureMipsVS,
|
|
38
|
+
"fragment": inspectTextureMipsFS,
|
|
39
|
+
"reflection": {}
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
"unlit_material": {
|
|
43
|
+
"vertex": unlitMaterialVS,
|
|
44
|
+
"fragment": unlitMaterialFS,
|
|
45
|
+
"reflection": {}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import {container, type DependencyContainer} from "tsyringe";
|
|
2
|
+
import {WindowManager} from "./window/window-manager.ts";
|
|
3
|
+
import {FrameworkConfig} from "./FrameworkConfig.ts";
|
|
4
|
+
import {IFrameworkSymbol} from "./dependency-injection/register-services-interface.ts";
|
|
5
|
+
import { RenderConfiguration, RenderConfigurationSymbol} from "./renderer/renderer-interface.ts";
|
|
6
|
+
import {GeometryBuilder} from "../geometry/GeometryBuilder.ts";
|
|
7
|
+
import {ContentManager} from "./content/ContentManager.ts";
|
|
8
|
+
import {WebGlRenderer} from "../webgl/WebGlRenderer.ts";
|
|
9
|
+
import {WebGlBuffersFactory} from "../webgl/buffers/WebGlBuffersFactory.ts";
|
|
10
|
+
import {
|
|
11
|
+
CameraFactory, CpuImageProcessor, GameTime,
|
|
12
|
+
type IBufferFactory, type IGeometryBuilder, type IGraphicsDevice, type IImageProcessor, type IInputManager,
|
|
13
|
+
ImageLoader,
|
|
14
|
+
type IMeshFactory, type ISpriteBatch, type ITextureFactory, type ITimeManager, RenderingBackend, TimeManager
|
|
15
|
+
} from "ris-framework-api";
|
|
16
|
+
import {WebGlShaderModuleLoader} from "../webgl/shader/WebGlShaderModuleLoader.ts";
|
|
17
|
+
import {TextureSamplerFilteringPreset} from "./rendering/enums.ts";
|
|
18
|
+
import {SpriteBatch} from "./sprite-batch/SpriteBatch.ts";
|
|
19
|
+
import type {ICameraFactory, IContentManager, IFramework, IImageLoader,
|
|
20
|
+
IRenderer,
|
|
21
|
+
IWindowManager
|
|
22
|
+
} from "ris-framework-api";
|
|
23
|
+
import {WebGlTextureFactory} from "../webgl/texture/WebGlTextureFactory.ts";
|
|
24
|
+
import {WebGlRenderPipelineFactory} from "../webgl/render-pipelines/WebGlRenderPipelineFactory.ts";
|
|
25
|
+
import type {IRenderPipelineFactory} from "ris-framework-api";
|
|
26
|
+
import {MeshFactory, type IMaterialFactory, MaterialFactory} from "ris-framework-api";
|
|
27
|
+
import {InputManager} from "./input/InputManager.ts";
|
|
28
|
+
import {Ktx2Factory} from "ris-ktx2";
|
|
29
|
+
import type {IKtx2Factory} from "ris-ktx2-api";
|
|
30
|
+
|
|
31
|
+
export class Framework implements IFramework {
|
|
32
|
+
|
|
33
|
+
private readonly _onLoadContentListeners: (() => void)[] = [];
|
|
34
|
+
private readonly _onInitializeListeners: (() => void)[] = [];
|
|
35
|
+
private readonly _onUpdateListeners: ((gameTime: GameTime) => void)[] = [];
|
|
36
|
+
private readonly _onRenderListeners: (() => void)[] = [];
|
|
37
|
+
|
|
38
|
+
private readonly _container: DependencyContainer;
|
|
39
|
+
private readonly _textureFactory: ITextureFactory;
|
|
40
|
+
private readonly _buffersFactory: IBufferFactory;
|
|
41
|
+
private readonly _contentManager: IContentManager;
|
|
42
|
+
private readonly _geometryBuilder: IGeometryBuilder;
|
|
43
|
+
private readonly _meshFactory: IMeshFactory;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The constructor for the Framework class.
|
|
47
|
+
* @param options The optional options for them framework.
|
|
48
|
+
*/
|
|
49
|
+
constructor(options: FrameworkConfig | null = null) {
|
|
50
|
+
options = options ?? new FrameworkConfig();
|
|
51
|
+
|
|
52
|
+
this._container = container.createChildContainer();
|
|
53
|
+
this.windowManager = new WindowManager(options.canvas);
|
|
54
|
+
|
|
55
|
+
// Setup container.
|
|
56
|
+
this._container.registerInstance(IFrameworkSymbol, this);
|
|
57
|
+
const rendererConfig = new RenderConfiguration();
|
|
58
|
+
rendererConfig.backBufferSize = options.backBufferSize;
|
|
59
|
+
rendererConfig.textureFiltering = options.textureFiltering ?? TextureSamplerFilteringPreset.BILINEAR;
|
|
60
|
+
this._container.registerInstance(RenderConfigurationSymbol, rendererConfig);
|
|
61
|
+
this.renderer = new WebGlRenderer(this, rendererConfig);
|
|
62
|
+
this.renderingBackend = RenderingBackend.WEB_GL;
|
|
63
|
+
this._textureFactory = new WebGlTextureFactory(this);
|
|
64
|
+
this._geometryBuilder = new GeometryBuilder();
|
|
65
|
+
this.renderPipelineFactory = new WebGlRenderPipelineFactory(this);
|
|
66
|
+
this._contentManager = new ContentManager(this, new WebGlShaderModuleLoader(this));
|
|
67
|
+
this._meshFactory = new MeshFactory(this);
|
|
68
|
+
this.materialFactory = new MaterialFactory(this);
|
|
69
|
+
|
|
70
|
+
this._buffersFactory = new WebGlBuffersFactory(this);
|
|
71
|
+
this.spriteBatch = new SpriteBatch(this);
|
|
72
|
+
this.cameraFactory = new CameraFactory(this);
|
|
73
|
+
this.timeManager = new TimeManager();
|
|
74
|
+
this.input = new InputManager(this);
|
|
75
|
+
this.imageProcessor = new CpuImageProcessor();
|
|
76
|
+
this.imageLoader = new ImageLoader(this);
|
|
77
|
+
|
|
78
|
+
if(options.useKtx2){
|
|
79
|
+
this.ktx2Factory = new Ktx2Factory();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** @inheritDoc */
|
|
84
|
+
public readonly imageLoader: IImageLoader;
|
|
85
|
+
|
|
86
|
+
renderingBackend: RenderingBackend;
|
|
87
|
+
|
|
88
|
+
/** @inheritDoc */
|
|
89
|
+
public readonly imageProcessor :IImageProcessor;
|
|
90
|
+
|
|
91
|
+
/** @inheritDoc */
|
|
92
|
+
public readonly renderer : IRenderer;
|
|
93
|
+
|
|
94
|
+
/** @inheritDoc */
|
|
95
|
+
public readonly spriteBatch: ISpriteBatch;
|
|
96
|
+
|
|
97
|
+
/** @inheritDoc */
|
|
98
|
+
public cameraFactory: ICameraFactory;
|
|
99
|
+
|
|
100
|
+
/** @inheritDoc */
|
|
101
|
+
public ktx2Factory?: IKtx2Factory;
|
|
102
|
+
|
|
103
|
+
/** @inheritDoc */
|
|
104
|
+
public addOnInitializedListener(event: () => void): void {
|
|
105
|
+
this._onInitializeListeners.push(event);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** @inheritDoc */
|
|
109
|
+
public removeOnInitializedListener(event: () => void): void {
|
|
110
|
+
this._onInitializeListeners.splice(this._onInitializeListeners.indexOf(event), 1);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** @inheritdoc */
|
|
114
|
+
public addOnLoadContentListener(event: () => void): void {
|
|
115
|
+
this._onLoadContentListeners.push(event);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** @inheritdoc */
|
|
119
|
+
public removeOnLoadContentListener(event: () => void): void {
|
|
120
|
+
this._onLoadContentListeners.splice(this._onLoadContentListeners.indexOf(event), 1);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** @inheritdoc */
|
|
124
|
+
public addOnUpdateListener(event: (gameTime: GameTime) => void): void {
|
|
125
|
+
this._onUpdateListeners.push(event);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** @inheritdoc */
|
|
129
|
+
public removeOnUpdateListener(event: (gameTime: GameTime) => void): void {
|
|
130
|
+
this._onUpdateListeners.splice(this._onUpdateListeners.indexOf(event), 1);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** @inheritdoc */
|
|
134
|
+
public addOnRenderListener(event: () => void): void {
|
|
135
|
+
this._onRenderListeners.push(event);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** @inheritdoc */
|
|
139
|
+
public removeOnRenderListener(event: () => void): void {
|
|
140
|
+
this._onRenderListeners.splice(this._onRenderListeners.indexOf(event), 1);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** @inheritdoc */
|
|
144
|
+
public get graphicsDevice(): IGraphicsDevice {
|
|
145
|
+
return this.renderer.graphicsDevice;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** @inheritdoc */
|
|
149
|
+
public renderPipelineFactory: IRenderPipelineFactory;
|
|
150
|
+
|
|
151
|
+
/** @inheritdoc */
|
|
152
|
+
get geometryBuilder(): IGeometryBuilder {
|
|
153
|
+
return this._geometryBuilder;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** @inheritdoc */
|
|
157
|
+
public readonly windowManager: IWindowManager;
|
|
158
|
+
|
|
159
|
+
/** @inheritdoc */
|
|
160
|
+
public get textureFactory(): ITextureFactory {
|
|
161
|
+
return this._textureFactory;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** @inheritdoc */
|
|
165
|
+
public get bufferFactory(): IBufferFactory {
|
|
166
|
+
return this._buffersFactory;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** @inheritdoc */
|
|
170
|
+
public get content(): IContentManager {
|
|
171
|
+
return this._contentManager;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** @inheritdoc */
|
|
175
|
+
public get meshFactory(): IMeshFactory {
|
|
176
|
+
return this._meshFactory;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** @inheritDoc */
|
|
180
|
+
public readonly materialFactory: IMaterialFactory;
|
|
181
|
+
|
|
182
|
+
/** @inheritDoc */
|
|
183
|
+
public readonly timeManager: ITimeManager;
|
|
184
|
+
|
|
185
|
+
/** @inheritDoc */
|
|
186
|
+
public readonly input: IInputManager;
|
|
187
|
+
|
|
188
|
+
/** @inheritdoc */
|
|
189
|
+
public initialize(): void {
|
|
190
|
+
|
|
191
|
+
this.ktx2Factory?.initializeAsync();
|
|
192
|
+
(this.renderer as WebGlRenderer).initialize();
|
|
193
|
+
this.spriteBatch.initialize();
|
|
194
|
+
this.input.initialize();
|
|
195
|
+
|
|
196
|
+
this.timeManager.prepareStart();
|
|
197
|
+
|
|
198
|
+
// Load content events.
|
|
199
|
+
for(const listener of this._onLoadContentListeners){
|
|
200
|
+
listener();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
for(const listener of this._onInitializeListeners){
|
|
204
|
+
listener();
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
this.renderer.afterInitialize();
|
|
208
|
+
|
|
209
|
+
this.windowManager.addUpdateListener(() => {
|
|
210
|
+
// Update logic here
|
|
211
|
+
this.timeManager.frameStart();
|
|
212
|
+
this.input.update();
|
|
213
|
+
|
|
214
|
+
for(const listener of this._onUpdateListeners){
|
|
215
|
+
listener(this.timeManager.time);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
this.input.afterUpdate();
|
|
219
|
+
});
|
|
220
|
+
this.windowManager.addRenderListener(() => {
|
|
221
|
+
this.renderer.beginRenderPass();
|
|
222
|
+
|
|
223
|
+
// Invoke render listeners.
|
|
224
|
+
for (const listener of this._onRenderListeners) {
|
|
225
|
+
listener();
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
this.spriteBatch.frameEnd();
|
|
229
|
+
this.renderer.endRenderPass();
|
|
230
|
+
});
|
|
231
|
+
this.windowManager.runEventLoop();
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** @inheritDoc */
|
|
235
|
+
public dispose() {
|
|
236
|
+
// this.windowManager.dispose();
|
|
237
|
+
|
|
238
|
+
// TODO: dispose of other resources
|
|
239
|
+
}
|
|
240
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { TextureSamplerFilteringPreset } from "./rendering/enums.ts";
|
|
2
|
+
import {vec2} from "gl-matrix";
|
|
3
|
+
import {IFrameworkConfig} from "ris-framework-api";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The options for configuring the Framework.
|
|
7
|
+
*/
|
|
8
|
+
export class FrameworkConfig implements IFrameworkConfig {
|
|
9
|
+
|
|
10
|
+
constructor() {}
|
|
11
|
+
|
|
12
|
+
/** @inheritDoc */
|
|
13
|
+
useKtx2 = false;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The HTMLCanvasElement to use for rendering.
|
|
17
|
+
* If null, a new canvas will be created and added to the document body.
|
|
18
|
+
*/
|
|
19
|
+
canvas: HTMLCanvasElement|null = null;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The size of a back buffer.
|
|
23
|
+
*/
|
|
24
|
+
backBufferSize: vec2 = vec2.fromValues(800,600);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The texture filtering preset to use for textures created by the framework.
|
|
28
|
+
* By default, it is set to BILINEAR, which provides a good balance between performance and quality.
|
|
29
|
+
*/
|
|
30
|
+
textureFiltering? = TextureSamplerFilteringPreset.BILINEAR;
|
|
31
|
+
}
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type IShaderModule,
|
|
3
|
+
type IContentManager,
|
|
4
|
+
type IShaderModuleLoader,
|
|
5
|
+
type ITexture2D,
|
|
6
|
+
type IFramework, TextureDescriptor, TextureFormat, ContentConfig, TextureUsage
|
|
7
|
+
} from "ris-framework-api";
|
|
8
|
+
import {Ktx2Factory} from "ris-ktx2";
|
|
9
|
+
import type {IKtx2Texture} from "ris-ktx2-api";
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The content manager.
|
|
14
|
+
* The content manager is responsible for managing the content modules and loading the content with the given asset file path or identifier.
|
|
15
|
+
*/
|
|
16
|
+
export class ContentManager implements IContentManager {
|
|
17
|
+
|
|
18
|
+
private readonly _ktx2Factory = new Ktx2Factory();
|
|
19
|
+
private readonly _ktx2TextureCache: {[key: string]: IKtx2Texture} = {};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The constructor.
|
|
23
|
+
* @param shaderModuleLoader The shader module loader.
|
|
24
|
+
*/
|
|
25
|
+
public constructor(private readonly _framework: IFramework, public readonly shaderModuleLoader: IShaderModuleLoader) {
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** @inheritDoc */
|
|
29
|
+
public async loadKtx2Async(path: string, contentConfig?: ContentConfig): Promise<IKtx2Texture> {
|
|
30
|
+
|
|
31
|
+
let ktx2Texture = this._ktx2TextureCache[path];
|
|
32
|
+
if(ktx2Texture) {
|
|
33
|
+
return ktx2Texture;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
ktx2Texture = await this._ktx2Factory.loadAsync(path);
|
|
37
|
+
if(contentConfig?.keepDataCached == true){
|
|
38
|
+
this._ktx2TextureCache[path] = ktx2Texture;
|
|
39
|
+
}
|
|
40
|
+
return ktx2Texture;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** @inheritDoc */
|
|
44
|
+
public loadShaderModule(shaderModuleId: string): IShaderModule {
|
|
45
|
+
return this.shaderModuleLoader.load(shaderModuleId);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** @inheritDoc */
|
|
49
|
+
public async loadTexture2DAsync(path: string,
|
|
50
|
+
textureDescriptor?: TextureDescriptor,
|
|
51
|
+
contentConfig?: ContentConfig,
|
|
52
|
+
): Promise<ITexture2D> {
|
|
53
|
+
|
|
54
|
+
if(path.endsWith(".ktx2")) {
|
|
55
|
+
const ktx2Texture = await this.loadKtx2Async(path);
|
|
56
|
+
textureDescriptor = textureDescriptor ?? new TextureDescriptor();
|
|
57
|
+
return this._framework.textureFactory.createFromKtx2(ktx2Texture, textureDescriptor);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let format = this._framework.renderer.preferredTextureFormat;
|
|
61
|
+
|
|
62
|
+
if(textureDescriptor && textureDescriptor.textureFormat != TextureFormat.UNDEFINED) {
|
|
63
|
+
format = textureDescriptor.textureFormat;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// TODO: pass texture descriptor
|
|
67
|
+
const imageLoader = this._framework.imageLoader;
|
|
68
|
+
const data = await imageLoader.loadAsync(path, contentConfig?.keepDataCached);
|
|
69
|
+
return this._framework.textureFactory.create(
|
|
70
|
+
data.baseWidth, data.baseHeight,
|
|
71
|
+
data.getData(0) as Uint8Array,
|
|
72
|
+
data.channels,
|
|
73
|
+
undefined,
|
|
74
|
+
TextureUsage.TEXTURE_BINDING | TextureUsage.COPY_SRC,
|
|
75
|
+
format,
|
|
76
|
+
textureDescriptor?.generateMipmaps
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** @inheritDoc */
|
|
81
|
+
public loadTexture2DFromPixels(width: number, height: number, pixels: ArrayBuffer): ITexture2D {
|
|
82
|
+
const view = new Uint8Array(pixels);
|
|
83
|
+
return this._framework.textureFactory.create(width, height, view);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DependencyContainer } from "tsyringe";
|
|
2
|
+
|
|
3
|
+
export const IFrameworkSymbol = Symbol.for("IFramework");
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The interface for registering services to the dependency injection container.
|
|
7
|
+
*/
|
|
8
|
+
export interface IRegisterServices {
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Register all services to the dependency injection container in this method.
|
|
12
|
+
* @param container The dependency injection container to register services to.
|
|
13
|
+
*/
|
|
14
|
+
register(container: DependencyContainer): void;
|
|
15
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GamePadState,
|
|
3
|
+
type IFramework,
|
|
4
|
+
type IInputManager,
|
|
5
|
+
KeyboardState,
|
|
6
|
+
MouseButton,
|
|
7
|
+
MouseState
|
|
8
|
+
} from "ris-framework-api";
|
|
9
|
+
import {vec2} from "gl-matrix";
|
|
10
|
+
|
|
11
|
+
export class InputManager implements IInputManager {
|
|
12
|
+
|
|
13
|
+
private readonly _mouseButtonMap: { [key: number]: MouseButton } = {
|
|
14
|
+
0: MouseButton.LEFT,
|
|
15
|
+
1: MouseButton.MIDDLE,
|
|
16
|
+
2: MouseButton.RIGHT,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
private readonly _mouseState: MouseState;
|
|
20
|
+
private readonly _mousePosition = vec2.create();
|
|
21
|
+
private readonly _previousMousePosition = vec2.create();
|
|
22
|
+
private readonly _mouseDelta = vec2.create();
|
|
23
|
+
private readonly _scrollWheelPosition = vec2.create();
|
|
24
|
+
private readonly _mouseButtonDown: { [key: number]: boolean } = {};
|
|
25
|
+
private readonly _mouseButtonReleased: { [key: number]: boolean } = {};
|
|
26
|
+
|
|
27
|
+
/** TODO */
|
|
28
|
+
public constructor(private readonly _framework: IFramework) {
|
|
29
|
+
|
|
30
|
+
this._mouseState = new MouseState(
|
|
31
|
+
this._mouseButtonDown, this._mouseButtonReleased,
|
|
32
|
+
this._mousePosition, this._mouseDelta, this._scrollWheelPosition
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
thumbstickDeadZone = 0.2;
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
getGamePadState(_gamePadIndex: number): GamePadState {
|
|
41
|
+
return new GamePadState(false, {}, {}, vec2.create(), vec2.create());
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
getKeyboardState(): KeyboardState {
|
|
45
|
+
return new KeyboardState({}, {});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** @inheritDoc */
|
|
49
|
+
public getMouseState(): MouseState {
|
|
50
|
+
return this._mouseState;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** @inheritDoc */
|
|
54
|
+
public initialize(): void {
|
|
55
|
+
|
|
56
|
+
const canvas = this._framework.windowManager.canvas;
|
|
57
|
+
this._handleMouseEvents(canvas)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private _handleMouseEvents(canvas: HTMLCanvasElement) {
|
|
61
|
+
|
|
62
|
+
canvas.addEventListener("mousemove", (e: MouseEvent) => {
|
|
63
|
+
this._mousePosition[0] = e.clientX;
|
|
64
|
+
this._mousePosition[1] = e.clientY;
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
canvas.addEventListener("mousedown", (e: MouseEvent) => {
|
|
68
|
+
const idx = e.button;
|
|
69
|
+
const btn = this._mouseButtonMap[idx] ?? MouseButton.NONE;
|
|
70
|
+
this._mouseButtonDown[btn] = true;
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
canvas.addEventListener("mouseup", (e: MouseEvent) => {
|
|
74
|
+
const idx = e.button;
|
|
75
|
+
const btn = this._mouseButtonMap[idx] ?? MouseButton.NONE;
|
|
76
|
+
this._mouseButtonDown[btn] = false;
|
|
77
|
+
this._mouseButtonReleased[btn] = true;
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
canvas.addEventListener("wheel", (e: WheelEvent) => {
|
|
81
|
+
|
|
82
|
+
let x = 0;
|
|
83
|
+
let y = 0;
|
|
84
|
+
if (e.deltaX > 0) {
|
|
85
|
+
x = 1;
|
|
86
|
+
} else if (e.deltaX < 0) {
|
|
87
|
+
x = -1;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (e.deltaY > 0) {
|
|
91
|
+
y = 1;
|
|
92
|
+
} else if (e.deltaY < 0) {
|
|
93
|
+
y = -1;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
vec2.set(this._scrollWheelPosition, x, y);
|
|
97
|
+
|
|
98
|
+
e.preventDefault();
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** @inheritDoc */
|
|
103
|
+
public update(): void {
|
|
104
|
+
vec2.sub(this._mouseDelta, this._mousePosition, this._previousMousePosition);
|
|
105
|
+
vec2.copy(this._previousMousePosition, this._mousePosition);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** @inheritDoc */
|
|
109
|
+
public afterUpdate(): void {
|
|
110
|
+
vec2.set(this._scrollWheelPosition, 0, 0);
|
|
111
|
+
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
}
|