webglmusti 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +2 -0
- package/idea_list.txt +13 -0
- package/index.html +17 -0
- package/package.json +20 -0
- package/public/apple.png +0 -0
- package/public/base.png +0 -0
- package/public/car.png +0 -0
- package/public/drop.png +0 -0
- package/public/font16-Sheet.png +0 -0
- package/public/font16-Sheet.txt +52 -0
- package/public/letters-Sheet.png +0 -0
- package/public/letters-Sheet.txt +27 -0
- package/public/letters_Sheet.png +0 -0
- package/public/letters_Sheet.txt +4 -0
- package/public/vite.svg +1 -0
- package/src/App/ResourceSim/car.ts +172 -0
- package/src/App/ResourceSim/grid.ts +993 -0
- package/src/App/ResourceSim/grid_app.ts +1326 -0
- package/src/App/ResourceSim/grid_test.test.ts +18 -0
- package/src/App/ResourceSim/node_graph.ts +293 -0
- package/src/App/ResourceSim/nodes.ts +151 -0
- package/src/App/ResourceSim/resource.ts +8 -0
- package/src/App/ResourceSim/texts.ts +6 -0
- package/src/App/card/card.test.ts +22 -0
- package/src/App/card/card.ts +763 -0
- package/src/App/puzzle_box/app.ts +10 -0
- package/src/App/puzzle_box/engine.ts +374 -0
- package/src/App/puzzle_box/renderer.ts +102 -0
- package/src/App/puzzle_box/test.test.ts +49 -0
- package/src/App/water/water.ts +206 -0
- package/src/Interface/button.ts +345 -0
- package/src/Interface/interface_element.ts +30 -0
- package/src/Interface/internal_window.ts +100 -0
- package/src/Interface/options.ts +332 -0
- package/src/Interface/text_input.ts +183 -0
- package/src/WebGL/Matrix/matrix.test.ts +30 -0
- package/src/WebGL/Matrix/matrix.ts +293 -0
- package/src/WebGL/Shaders/Fragment/Program/circle.ts +49 -0
- package/src/WebGL/Shaders/Fragment/Program/circle_only.ts +47 -0
- package/src/WebGL/Shaders/Fragment/Program/circle_outline.ts +54 -0
- package/src/WebGL/Shaders/Fragment/Program/colour.ts +39 -0
- package/src/WebGL/Shaders/Fragment/Program/colour_alpha.ts +37 -0
- package/src/WebGL/Shaders/Fragment/Program/line.ts +39 -0
- package/src/WebGL/Shaders/Fragment/Program/multi_colour_centre_circle_path.ts +69 -0
- package/src/WebGL/Shaders/Fragment/Program/multi_colour_path.ts +69 -0
- package/src/WebGL/Shaders/Fragment/Program/path_centre_circle.ts +69 -0
- package/src/WebGL/Shaders/Fragment/Program/rect_outline.ts +39 -0
- package/src/WebGL/Shaders/Fragment/Program/solid_path.ts +64 -0
- package/src/WebGL/Shaders/Fragment/Program/sprite_sheet.ts +54 -0
- package/src/WebGL/Shaders/Fragment/Program/sprite_sheet_colour.ts +62 -0
- package/src/WebGL/Shaders/Fragment/Program/texture.ts +34 -0
- package/src/WebGL/Shaders/Fragment/Source/circle.frag +19 -0
- package/src/WebGL/Shaders/Fragment/Source/circle_only.frag +15 -0
- package/src/WebGL/Shaders/Fragment/Source/circle_outline.frag +23 -0
- package/src/WebGL/Shaders/Fragment/Source/colour.frag +9 -0
- package/src/WebGL/Shaders/Fragment/Source/colour_alpha.frag +7 -0
- package/src/WebGL/Shaders/Fragment/Source/fragment.frag +5 -0
- package/src/WebGL/Shaders/Fragment/Source/fragment_source.ts +15 -0
- package/src/WebGL/Shaders/Fragment/Source/line.frag +12 -0
- package/src/WebGL/Shaders/Fragment/Source/multi_colour_centre_circle_path.frag +36 -0
- package/src/WebGL/Shaders/Fragment/Source/multi_colour_path.frag +34 -0
- package/src/WebGL/Shaders/Fragment/Source/path_centre_circle.frag +29 -0
- package/src/WebGL/Shaders/Fragment/Source/rect_outline.frag +20 -0
- package/src/WebGL/Shaders/Fragment/Source/solid_path.frag +24 -0
- package/src/WebGL/Shaders/Fragment/Source/sprite_sheet.frag +17 -0
- package/src/WebGL/Shaders/Fragment/Source/sprite_sheet_colour.frag +19 -0
- package/src/WebGL/Shaders/Fragment/Source/texture.frag +11 -0
- package/src/WebGL/Shaders/Fragment/fragment.ts +43 -0
- package/src/WebGL/Shaders/Fragment/fragment_old.ts +261 -0
- package/src/WebGL/Shaders/Vertex/Program/mvp2d.ts +41 -0
- package/src/WebGL/Shaders/Vertex/Program/transform2d.ts +39 -0
- package/src/WebGL/Shaders/Vertex/Source/mvp2d.vert +17 -0
- package/src/WebGL/Shaders/Vertex/Source/mvp_i_2d.vert +18 -0
- package/src/WebGL/Shaders/Vertex/Source/simple.vert +9 -0
- package/src/WebGL/Shaders/Vertex/Source/transform2d.vert +13 -0
- package/src/WebGL/Shaders/Vertex/Source/transform2d_rel.vert +16 -0
- package/src/WebGL/Shaders/Vertex/Source/translate2d.vert +7 -0
- package/src/WebGL/Shaders/Vertex/Source/vertex_source.ts +13 -0
- package/src/WebGL/Shaders/Vertex/vertex.ts +10 -0
- package/src/WebGL/Shaders/Vertex/vertex_old.ts +289 -0
- package/src/WebGL/Shaders/custom.ts +129 -0
- package/src/WebGL/Shaders/shader.ts +197 -0
- package/src/WebGL/Shapes/Line.ts +29 -0
- package/src/WebGL/Shapes/Shapes.ts +189 -0
- package/src/WebGL/Texture/texture.ts +214 -0
- package/src/WebGL/Util/file.ts +24 -0
- package/src/WebGL/app.ts +150 -0
- package/src/WebGL/colour.ts +71 -0
- package/src/WebGL/globals.ts +353 -0
- package/src/WebGL/index.ts +3 -0
- package/src/WebGL/mixin.ts +2 -0
- package/src/global.d.ts +13 -0
- package/src/index.ts +4 -0
- package/src/main.ts +139 -0
- package/src/utils/array.ts +154 -0
- package/src/utils/assert.ts +8 -0
- package/src/utils/file.ts +0 -0
- package/src/utils/mixin.ts +22 -0
- package/src/utils/numbers.ts +11 -0
- package/src/utils/utils.test.ts +23 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.json +25 -0
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import WebGL from "../../globals";
|
|
2
|
+
import * as Mixin from "../../mixin"
|
|
3
|
+
import type { Matrix3x3, TransformationMatrix3x3 } from "../../Matrix/matrix";
|
|
4
|
+
import * as Shader from "../shader";
|
|
5
|
+
|
|
6
|
+
//import * as MVP from "./Program/mvp";
|
|
7
|
+
import * as Transform from "./Program/transform2d";
|
|
8
|
+
//export const MvpShaderProgramMix = MVP.MvpShaderProgramMix;
|
|
9
|
+
export const Transform2dShaderProgramMix = Transform.Transform2dShaderProgramMix;
|
|
10
|
+
|
|
11
|
+
import * as VertexSource from "./Source/vertex_source";
|
|
12
|
+
|
|
13
|
+
export function loadVertexShaders(){
|
|
14
|
+
SimpleVertexShader.load();
|
|
15
|
+
TranslateVertexShader.load();
|
|
16
|
+
TransformVertexShader.load();
|
|
17
|
+
TransformRelativeVertexShader.load();
|
|
18
|
+
MVPRelativeVertexShader.load();
|
|
19
|
+
MVPIndividualRelativeVertexShader.load();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class MVPRelativeVertexShader{
|
|
23
|
+
static shader?: Shader.VertexShader;
|
|
24
|
+
static load(){
|
|
25
|
+
if(!this.shader){
|
|
26
|
+
this.shader = new Shader.VertexShader();
|
|
27
|
+
if(!this.shader.addSource(VertexSource.mvp_rel)){
|
|
28
|
+
console.log("MVPVertex: vertex source not added");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class MVPIndividualRelativeVertexShader{
|
|
35
|
+
static shader?: Shader.VertexShader;
|
|
36
|
+
static load(){
|
|
37
|
+
if(!this.shader){
|
|
38
|
+
this.shader = new Shader.VertexShader();
|
|
39
|
+
if(!this.shader.addSource(VertexSource.mvp_i_rel)){
|
|
40
|
+
console.log("MVPVertex: vertex source not added");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
export class SimpleVertexShader{
|
|
48
|
+
static shader?: Shader.VertexShader;
|
|
49
|
+
static load(){
|
|
50
|
+
if(!this.shader){
|
|
51
|
+
this.shader = new Shader.VertexShader();
|
|
52
|
+
if(!this.shader.addSource(VertexSource.simple)){
|
|
53
|
+
console.log("Simple: vertex source not added");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/*
|
|
60
|
+
export class SimpleShaderProgram extends Shader.NewCustomShaderProgram{
|
|
61
|
+
constructor(){
|
|
62
|
+
super();
|
|
63
|
+
this.name = TranslateShaderProgram.name;
|
|
64
|
+
this.setupVertex();
|
|
65
|
+
}
|
|
66
|
+
setupVertex(){
|
|
67
|
+
if(TranslateVertexShader.shader){
|
|
68
|
+
this.program.addVertex(TranslateVertexShader.shader);
|
|
69
|
+
}else{
|
|
70
|
+
console.log(`${this.name} not loaded`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
add_vertex_attribute_locations(): void {};
|
|
74
|
+
add_vertex_uniform_locations(): void {};
|
|
75
|
+
}*/
|
|
76
|
+
|
|
77
|
+
export class TranslateVertexShader{
|
|
78
|
+
static shader?: Shader.VertexShader;
|
|
79
|
+
static load(){
|
|
80
|
+
if(this.shader == undefined){
|
|
81
|
+
this.shader = new Shader.VertexShader();
|
|
82
|
+
if(!this.shader.addSource(VertexSource.translate)){
|
|
83
|
+
console.log("Translate: vertex source not added");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export class TransformRelativeVertexShader{
|
|
90
|
+
static shader?: Shader.VertexShader;
|
|
91
|
+
static load(){
|
|
92
|
+
if(this.shader == undefined){
|
|
93
|
+
this.shader = new Shader.VertexShader();
|
|
94
|
+
if(!this.shader.addSource(VertexSource.transform_rel)){
|
|
95
|
+
console.log("TranslateRelative: vertex source not added");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export class TranslateShaderProgram extends Shader.CustomShaderProgram{
|
|
102
|
+
private translate_uniform_location: WebGLUniformLocation | null;
|
|
103
|
+
constructor(){
|
|
104
|
+
super();
|
|
105
|
+
this.translate_uniform_location = null;
|
|
106
|
+
this.name = TranslateShaderProgram.name;
|
|
107
|
+
this.setupVertex();
|
|
108
|
+
}
|
|
109
|
+
private setupVertex(){
|
|
110
|
+
if(TranslateVertexShader.shader){
|
|
111
|
+
this.program.addVertex(TranslateVertexShader.shader);
|
|
112
|
+
}else{
|
|
113
|
+
console.log(`${this.name} not loaded`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
addAttributeLocations(): void {
|
|
117
|
+
|
|
118
|
+
}
|
|
119
|
+
addUniformLocations(): void {
|
|
120
|
+
this.translate_uniform_location = this.program.getUniformLocation("translate");
|
|
121
|
+
}
|
|
122
|
+
setTranslate(x: number, y:number){
|
|
123
|
+
this.program.setFloat2(this.translate_uniform_location!, x, y)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
class TransformVertexShader{
|
|
128
|
+
static shader?: Shader.VertexShader;
|
|
129
|
+
static load(){
|
|
130
|
+
if(this.shader == undefined){
|
|
131
|
+
this.shader = new Shader.VertexShader();
|
|
132
|
+
if(!this.shader.addSource(VertexSource.transform)){
|
|
133
|
+
console.log("Transform: vertex source not added");
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export class TransformShaderProgram extends Shader.CustomShaderProgram{
|
|
140
|
+
private declare transform_uniform_location: WebGLUniformLocation | null;
|
|
141
|
+
constructor(){
|
|
142
|
+
super();
|
|
143
|
+
this.transform_uniform_location = null;
|
|
144
|
+
this.name = TransformShaderProgram.name;
|
|
145
|
+
this.setupVertex();
|
|
146
|
+
}
|
|
147
|
+
setupVertex(){
|
|
148
|
+
if(TranslateVertexShader.shader){
|
|
149
|
+
this.program.addVertex(TranslateVertexShader.shader);
|
|
150
|
+
}else{
|
|
151
|
+
console.log(`${this.name} not loaded`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
addAttributeLocations(): void {
|
|
155
|
+
|
|
156
|
+
}
|
|
157
|
+
addUniformLocations(): void {
|
|
158
|
+
this.transform_uniform_location = this.program.getUniformLocation("u_matrix");
|
|
159
|
+
}
|
|
160
|
+
setTransform(matrix: Matrix3x3){
|
|
161
|
+
this.program.setMat3(this.transform_uniform_location!, matrix.matrix);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function TransformShaderProgramMixin<TBase extends Shader.CustomShaderProgramable>(Base: TBase){
|
|
166
|
+
return class Transform extends Base{
|
|
167
|
+
private declare transform_uniform_location: WebGLUniformLocation | null;
|
|
168
|
+
protected override setupVertex(){
|
|
169
|
+
if(TransformVertexShader.shader){
|
|
170
|
+
this.program.addVertex(TransformVertexShader.shader);
|
|
171
|
+
}else{
|
|
172
|
+
throw new Error(`${this.vertex_name} not loaded`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
override addVertexAttributeLocations(): void {
|
|
176
|
+
|
|
177
|
+
}
|
|
178
|
+
override addVertexUniformLocations(): void {
|
|
179
|
+
this.transform_uniform_location = this.program.getUniformLocation("u_matrix");
|
|
180
|
+
}
|
|
181
|
+
setTransform(matrix: TransformationMatrix3x3){
|
|
182
|
+
this.program.setMat3(this.transform_uniform_location!, matrix.matrix);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function TranslateShaderProgramMixin<TBase extends Shader.CustomShaderProgramable>(Base: TBase){
|
|
189
|
+
return class Translate extends Base{
|
|
190
|
+
private declare translate_uniform_location: WebGLUniformLocation | null;
|
|
191
|
+
protected override setupVertex(){
|
|
192
|
+
this.vertex_name = "TranslateShader";
|
|
193
|
+
if(TranslateVertexShader.shader){
|
|
194
|
+
this.program.addVertex(TranslateVertexShader.shader);
|
|
195
|
+
}else{
|
|
196
|
+
throw new Error(`${this.vertex_name} not loaded`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
protected override addVertexAttributeLocations(): void {
|
|
200
|
+
|
|
201
|
+
}
|
|
202
|
+
protected override addVertexUniformLocations(): void {
|
|
203
|
+
this.translate_uniform_location = this.program.getUniformLocation("translate");
|
|
204
|
+
}
|
|
205
|
+
setTranslate(x: number, y:number){
|
|
206
|
+
this.program.setFloat2(this.translate_uniform_location!, x, y)
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export function TransformRelativeShaderProgramMixin<TBase extends Shader.CustomShaderProgramable>(Base: TBase){
|
|
212
|
+
return class TransformRelative extends Base{
|
|
213
|
+
private declare transform_uniform_location: WebGLUniformLocation | null;
|
|
214
|
+
//private declare relative_attribute_location: GLint | null;
|
|
215
|
+
protected override setupVertex(){
|
|
216
|
+
this.vertex_name = "TransformRelativeShader";
|
|
217
|
+
if(TransformRelativeVertexShader.shader){
|
|
218
|
+
this.program.addVertex(TransformRelativeVertexShader.shader!);
|
|
219
|
+
}else{
|
|
220
|
+
throw new Error(`${this.vertex_name} not loaded`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
protected override addVertexAttributeLocations(): void {
|
|
224
|
+
//this.relative_attribute_location = this.program.getAttributeLocation("a_relative");
|
|
225
|
+
}
|
|
226
|
+
protected override addVertexUniformLocations(): void {
|
|
227
|
+
this.transform_uniform_location = this.program.getUniformLocation("u_matrix");
|
|
228
|
+
}
|
|
229
|
+
setTransform(matrix: TransformationMatrix3x3){
|
|
230
|
+
this.program.setMat3(this.transform_uniform_location!, matrix.matrix);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export function MVPRelativeShaderProgramMixin<TBase extends Shader.CustomShaderProgramable>(Base: TBase){
|
|
236
|
+
return class MVPRelative extends Base{
|
|
237
|
+
private declare mvp_uniform_location: WebGLUniformLocation | null;
|
|
238
|
+
protected override setupVertex(){
|
|
239
|
+
this.vertex_name = "MVPRelativeShader";
|
|
240
|
+
if(MVPRelativeVertexShader.shader){
|
|
241
|
+
this.program.addVertex(MVPRelativeVertexShader.shader!);
|
|
242
|
+
}else{
|
|
243
|
+
throw new Error(`${this.vertex_name} not loaded`);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
protected override addVertexAttributeLocations(): void {
|
|
247
|
+
//this.relative_attribute_location = this.program.getAttributeLocation("a_relative");
|
|
248
|
+
}
|
|
249
|
+
protected override addVertexUniformLocations(): void {
|
|
250
|
+
this.mvp_uniform_location = this.program.getUniformLocation("u_mvp");
|
|
251
|
+
}
|
|
252
|
+
setMVP(matrix: TransformationMatrix3x3){
|
|
253
|
+
this.program.setMat3(this.mvp_uniform_location!, matrix.matrix);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export function MVPIndividualRelativeShaderProgramMixin<TBase extends Shader.CustomShaderProgramable>(Base: TBase){
|
|
259
|
+
return class MVPIndividualRelative extends Base{
|
|
260
|
+
private declare model_uniform_location: WebGLUniformLocation | null;
|
|
261
|
+
private declare view_uniform_location: WebGLUniformLocation | null;
|
|
262
|
+
private declare perspective_uniform_location: WebGLUniformLocation | null;
|
|
263
|
+
protected override setupVertex(){
|
|
264
|
+
this.vertex_name = "MVPIndividualRelativeShader";
|
|
265
|
+
if(MVPRelativeVertexShader.shader){
|
|
266
|
+
this.program.addVertex(MVPRelativeVertexShader.shader!);
|
|
267
|
+
}else{
|
|
268
|
+
throw new Error(`${this.vertex_name} not loaded`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
protected override addVertexAttributeLocations(): void {
|
|
272
|
+
//this.relative_attribute_location = this.program.getAttributeLocation("a_relative");
|
|
273
|
+
}
|
|
274
|
+
protected override addVertexUniformLocations(): void {
|
|
275
|
+
this.model_uniform_location = this.program.getUniformLocation("u_model");
|
|
276
|
+
this.view_uniform_location = this.program.getUniformLocation("u_view");
|
|
277
|
+
this.perspective_uniform_location = this.program.getUniformLocation("u_perspective");
|
|
278
|
+
}
|
|
279
|
+
setModel(matrix: TransformationMatrix3x3){
|
|
280
|
+
this.program.setMat3(this.model_uniform_location!, matrix.matrix);
|
|
281
|
+
}
|
|
282
|
+
setView(matrix: TransformationMatrix3x3){
|
|
283
|
+
this.program.setMat3(this.view_uniform_location!, matrix.matrix);
|
|
284
|
+
}
|
|
285
|
+
setPerspective(matrix: TransformationMatrix3x3){
|
|
286
|
+
this.program.setMat3(this.perspective_uniform_location!, matrix.matrix);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
|
|
2
|
+
import WebGL from '../globals';
|
|
3
|
+
import * as Vertex from './Vertex/vertex';
|
|
4
|
+
import * as Fragment from './Fragment/fragment';
|
|
5
|
+
import * as Shader from './shader'
|
|
6
|
+
|
|
7
|
+
//TODO add shader programs here
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
//const MVPMixin = Vertex.MvpShaderProgramMix(Shader.ShaderProgramMixin);
|
|
11
|
+
//const TransformMixin = Vertex.Transform2dShaderProgramMix(Shader.ShaderProgramMixin);
|
|
12
|
+
|
|
13
|
+
export class MVPColourProgram extends Fragment.ColourMixin(Vertex.Mvp2dMixin){};
|
|
14
|
+
export class MVPColourAlphaProgram extends Fragment.ColourAlphaMixin(Vertex.Mvp2dMixin){};
|
|
15
|
+
export class TransformColourProgram extends Fragment.ColourMixin(Vertex.Transform2dMixin){};
|
|
16
|
+
export class TransformCircleProgram extends Fragment.CircleMixin(Vertex.Transform2dMixin){};
|
|
17
|
+
export class MVPCircleProgram extends Fragment.CircleMixin(Vertex.Mvp2dMixin){};
|
|
18
|
+
export class MVPCircleOnlyProgram extends Fragment.CircleOnlyMixin(Vertex.Mvp2dMixin){};
|
|
19
|
+
export class MVPOutlineCircleProgram extends Fragment.CircleOutlineMixin(Vertex.Mvp2dMixin){};
|
|
20
|
+
export class MVPSolidPathProgram extends Fragment.SolidPathMixin(Vertex.Mvp2dMixin){};
|
|
21
|
+
export class MVPOutlineRectProgram extends Fragment.RectOutlineMixin(Vertex.Mvp2dMixin){};
|
|
22
|
+
export class MVPSolidLineProgram extends Fragment.LineMixin(Vertex.Mvp2dMixin){};
|
|
23
|
+
export class MVPSpriteSheetProgram extends Fragment.SpriteSheetMixin(Vertex.Mvp2dMixin){};
|
|
24
|
+
export class MVPPathCenterCircleProgram extends Fragment.PathCentreCircleMixin(Vertex.Mvp2dMixin){};
|
|
25
|
+
export class MVPTextureProgram extends Fragment.TextureMixin(Vertex.Mvp2dMixin){};
|
|
26
|
+
|
|
27
|
+
export class MVPMultiColourPathProgram extends Fragment.MultiColourPathMixin(Vertex.Mvp2dMixin){};
|
|
28
|
+
export class MVPMultiColourCentreCirclePathProgram extends Fragment.MultiColourCentreCirclePathMixin(Vertex.Mvp2dMixin){};
|
|
29
|
+
export class MVPSpriteSheetColourProgram extends Fragment.SpriteSheetColourMixin(Vertex.Mvp2dMixin){};
|
|
30
|
+
/*
|
|
31
|
+
interface Colour{
|
|
32
|
+
setColour(r: GLfloat, g: GLfloat, b: GLfloat): void;
|
|
33
|
+
}*/
|
|
34
|
+
|
|
35
|
+
/*
|
|
36
|
+
export class TestSimple extends Vertex.SimpleShaderProgram{
|
|
37
|
+
constructor(){
|
|
38
|
+
super();
|
|
39
|
+
this.setup();
|
|
40
|
+
this.link();
|
|
41
|
+
}
|
|
42
|
+
setupFragment(){
|
|
43
|
+
console.log("loading proper simple");
|
|
44
|
+
if(Fragment.SimpleFragmentShader.shader){
|
|
45
|
+
this.program.addFragment(Fragment.SimpleFragmentShader.shader);
|
|
46
|
+
}else{
|
|
47
|
+
console.log("SimpleFragmentShader not loaded");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}*/
|
|
51
|
+
/*
|
|
52
|
+
export class TestTranslate extends Vertex.TranslateShaderProgram{
|
|
53
|
+
constructor(){
|
|
54
|
+
super();
|
|
55
|
+
this.setupFragment();
|
|
56
|
+
this.link();
|
|
57
|
+
}
|
|
58
|
+
private setupFragment(){
|
|
59
|
+
if(Fragment.SimpleFragmentShader.shader){
|
|
60
|
+
this.program.addFragment(Fragment.SimpleFragmentShader.shader);
|
|
61
|
+
}else{
|
|
62
|
+
console.log("SimpleFragmentShader not loaded");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export class TestColourTranslate extends Vertex.TranslateShaderProgram implements Colour {
|
|
68
|
+
private declare colour_uniform_location: WebGLUniformLocation | null;
|
|
69
|
+
constructor(){
|
|
70
|
+
super();
|
|
71
|
+
this.setupFragment();
|
|
72
|
+
}
|
|
73
|
+
private setupFragment(){
|
|
74
|
+
if(Fragment.ColourFragmentShader.shader){
|
|
75
|
+
this.program.addFragment(Fragment.ColourFragmentShader.shader);
|
|
76
|
+
}else{
|
|
77
|
+
console.log("ColourFragmentShader not loaded");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
addUniformLocations(): void {
|
|
81
|
+
super.addUniformLocations();
|
|
82
|
+
this.colour_uniform_location = this.program.getUniformLocation("colour");
|
|
83
|
+
};
|
|
84
|
+
setColour(r: GLfloat, g: GLfloat, b: GLfloat){
|
|
85
|
+
this.program.setFloat3(this.colour_uniform_location!, r, g, b);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export class TestColourTransform extends Vertex.TransformShaderProgram implements Colour{
|
|
90
|
+
private declare colour_uniform_location: WebGLUniformLocation | null;
|
|
91
|
+
constructor(){
|
|
92
|
+
super();
|
|
93
|
+
this.setupFragment();
|
|
94
|
+
}
|
|
95
|
+
private setupFragment(){
|
|
96
|
+
if(Fragment.ColourFragmentShader.shader){
|
|
97
|
+
this.program.addFragment(Fragment.ColourFragmentShader.shader);
|
|
98
|
+
}else{
|
|
99
|
+
console.log("ColourFragmentShader not loaded");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
addUniformLocations(): void {
|
|
103
|
+
super.addUniformLocations();
|
|
104
|
+
this.colour_uniform_location = this.program.getUniformLocation("colour");
|
|
105
|
+
};
|
|
106
|
+
setColour(r: GLfloat, g: GLfloat, b: GLfloat){
|
|
107
|
+
this.program.setFloat3(this.colour_uniform_location!, r, g, b);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const TransformMixin = Vertex.TransformShaderProgramMixin(Shader.ShaderProgramMixin);
|
|
112
|
+
const TranslateMixin = Vertex.TranslateShaderProgramMixin(Shader.ShaderProgramMixin);
|
|
113
|
+
const TransformRelativeMixin = Vertex.TransformRelativeShaderProgramMixin(Shader.ShaderProgramMixin);
|
|
114
|
+
const MVPRelativeMixin = Vertex.MVPRelativeShaderProgramMixin(Shader.ShaderProgramMixin);
|
|
115
|
+
//export class TransformColourMixin = Fragment.ColourShaderProgramMixin(TransformMixin);
|
|
116
|
+
|
|
117
|
+
//export const TransformColourMixinT = Fragment.ColourShaderProgramMixin(TransformMixin);
|
|
118
|
+
|
|
119
|
+
export class TransformColourProgram extends Fragment.ColourShaderProgramMixin(TransformMixin){};
|
|
120
|
+
export class TranslateColourProgram extends Fragment.ColourShaderProgramMixin(TranslateMixin){};
|
|
121
|
+
|
|
122
|
+
export class TransformCircleProgram extends Fragment.CircleShaderProgramMixin(TransformRelativeMixin){};
|
|
123
|
+
|
|
124
|
+
export class MVPColourProgram extends Fragment.ColourShaderProgramMixin(MVPRelativeMixin){};
|
|
125
|
+
export class MVPOutlineCircleProgram extends Fragment.CircleOutlineShaderProgramMixin(MVPRelativeMixin){};
|
|
126
|
+
export class MVPOutlineRectProgram extends Fragment.RectOutlineShaderProgramMixin(MVPRelativeMixin){};
|
|
127
|
+
|
|
128
|
+
export class MVPSolidLineProgram extends Fragment.SolidLineShaderProgramMixin(MVPRelativeMixin){};
|
|
129
|
+
*/
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import WebGL from '../globals';
|
|
2
|
+
import { TransformationMatrix3x3 } from '../Matrix/matrix';
|
|
3
|
+
import * as Mixin from '../mixin';
|
|
4
|
+
|
|
5
|
+
class RawShader{
|
|
6
|
+
shader: WebGLShader;
|
|
7
|
+
has_source: boolean;
|
|
8
|
+
constructor(type: GLenum){
|
|
9
|
+
if(WebGL.gl){
|
|
10
|
+
this.shader = WebGL.gl.createShader(type)!;
|
|
11
|
+
this.has_source = false;
|
|
12
|
+
}else{
|
|
13
|
+
throw new Error("WebGL not initialised or null");
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
addSource(source: string): boolean{
|
|
17
|
+
if(this.has_source){
|
|
18
|
+
console.log("Shader already has source");
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
WebGL.gl!.shaderSource(this.shader, source);
|
|
22
|
+
WebGL.gl!.compileShader(this.shader);
|
|
23
|
+
const success = WebGL.gl!.getShaderParameter(this.shader, WebGL.gl!.COMPILE_STATUS);
|
|
24
|
+
if(success){
|
|
25
|
+
this.has_source = true;
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
console.log(WebGL.gl!.getShaderInfoLog(this.shader));
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export class VertexShader extends RawShader{
|
|
34
|
+
constructor(){
|
|
35
|
+
super(WebGL.gl!.VERTEX_SHADER);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class FragmentShader extends RawShader{
|
|
40
|
+
constructor(){
|
|
41
|
+
super(WebGL.gl!.FRAGMENT_SHADER);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export class ShaderProgram{
|
|
46
|
+
program: WebGLProgram;
|
|
47
|
+
is_linked: boolean;
|
|
48
|
+
has_vertex: boolean;
|
|
49
|
+
has_fragment: boolean;
|
|
50
|
+
|
|
51
|
+
constructor(){
|
|
52
|
+
if(WebGL.gl){
|
|
53
|
+
this.program = WebGL.gl.createProgram();
|
|
54
|
+
this.is_linked = false;
|
|
55
|
+
this.has_vertex = false;
|
|
56
|
+
this.has_fragment = false;
|
|
57
|
+
}else{
|
|
58
|
+
throw new Error("WebGL not initialised or null");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
addVertex(vs: VertexShader){
|
|
62
|
+
if(this.has_vertex){
|
|
63
|
+
console.log("Already has vertex");
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
WebGL.gl!.attachShader(this.program, vs.shader);
|
|
67
|
+
this.has_vertex = true;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
addFragment(fs: FragmentShader){
|
|
71
|
+
if(this.has_fragment){
|
|
72
|
+
console.log("Already has fragment");
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
WebGL.gl!.attachShader(this.program, fs.shader);
|
|
76
|
+
this.has_fragment = true;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
use(){
|
|
80
|
+
WebGL.gl!.useProgram(this.program);
|
|
81
|
+
}
|
|
82
|
+
link(): boolean{
|
|
83
|
+
if(!this.is_linked){
|
|
84
|
+
WebGL.gl!.linkProgram(this.program);
|
|
85
|
+
const success = WebGL.gl!.getProgramParameter(this.program, WebGL.gl!.LINK_STATUS);
|
|
86
|
+
if (success) {
|
|
87
|
+
this.is_linked = true;
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
console.log(WebGL.gl!.getProgramInfoLog(this.program));
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
getAttributeLocation(attr: string): GLint{
|
|
96
|
+
return WebGL.gl!.getAttribLocation(this.program, attr);
|
|
97
|
+
}
|
|
98
|
+
getUniformLocation(uni_name: string): WebGLUniformLocation | null{
|
|
99
|
+
return WebGL.gl!.getUniformLocation(this.program, uni_name);
|
|
100
|
+
}
|
|
101
|
+
setFloat(uni_location: WebGLUniformLocation, value: GLfloat){
|
|
102
|
+
WebGL.gl!.uniform1f(uni_location, value);
|
|
103
|
+
}
|
|
104
|
+
setFloat2(uni_location: WebGLUniformLocation, f1: GLfloat, f2:GLfloat){
|
|
105
|
+
WebGL.gl!.uniform2f(uni_location, f1, f2);
|
|
106
|
+
}
|
|
107
|
+
setFloat3(uni_location: WebGLUniformLocation, f1: GLfloat, f2:GLfloat, f3: GLfloat){
|
|
108
|
+
WebGL.gl!.uniform3f(uni_location, f1, f2, f3);
|
|
109
|
+
}
|
|
110
|
+
setFloat4(uni_location: WebGLUniformLocation, f1: GLfloat, f2:GLfloat, f3: GLfloat, f4: GLfloat){
|
|
111
|
+
WebGL.gl!.uniform4f(uni_location, f1, f2, f3, f4);
|
|
112
|
+
}
|
|
113
|
+
setInt(uni_location: WebGLUniformLocation, value: GLint){
|
|
114
|
+
WebGL.gl!.uniform1i(uni_location, value);
|
|
115
|
+
}
|
|
116
|
+
setMat3(uni_location: WebGLUniformLocation, matrix: Float32Array){
|
|
117
|
+
WebGL.gl!.uniformMatrix3fv(uni_location, false, matrix);
|
|
118
|
+
}
|
|
119
|
+
setMat4(uni_location: WebGLUniformLocation, matrix: Float32Array){
|
|
120
|
+
WebGL.gl!.uniformMatrix4fv(uni_location, false, matrix);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// custom shader for inheritance
|
|
125
|
+
export abstract class CustomShaderProgram{
|
|
126
|
+
protected program: ShaderProgram;
|
|
127
|
+
protected declare name: string;
|
|
128
|
+
constructor(){
|
|
129
|
+
this.program = new ShaderProgram();
|
|
130
|
+
}
|
|
131
|
+
use(){
|
|
132
|
+
if(this.program.is_linked){
|
|
133
|
+
this.program.use();
|
|
134
|
+
}else{
|
|
135
|
+
console.log(`Cannot use: ${this.name} is not linked`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
link(){
|
|
140
|
+
if(!this.program.is_linked){
|
|
141
|
+
this.program.link();
|
|
142
|
+
}
|
|
143
|
+
this.addAttributeLocations();
|
|
144
|
+
this.addUniformLocations();
|
|
145
|
+
}
|
|
146
|
+
abstract addAttributeLocations(): void;
|
|
147
|
+
abstract addUniformLocations(): void;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// custom shader for mixins
|
|
151
|
+
export class ShaderProgramMixin{
|
|
152
|
+
protected program: ShaderProgram;
|
|
153
|
+
protected declare vertex_name: string;
|
|
154
|
+
protected declare fragment_name: string;
|
|
155
|
+
constructor(){
|
|
156
|
+
this.program = new ShaderProgram();
|
|
157
|
+
this.setup();
|
|
158
|
+
this.link();
|
|
159
|
+
}
|
|
160
|
+
private setup(){
|
|
161
|
+
this.setupVertex();
|
|
162
|
+
this.setupFragment();
|
|
163
|
+
}
|
|
164
|
+
use(){
|
|
165
|
+
if(this.program.is_linked){
|
|
166
|
+
this.program.use();
|
|
167
|
+
}else{
|
|
168
|
+
throw new Error(`Cannot use: ${this.vertex_name} or ${this.fragment_name} is not linked`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
private link(){
|
|
173
|
+
if(!this.program.is_linked){
|
|
174
|
+
this.program.link();
|
|
175
|
+
this.addVertexAttributeLocations();
|
|
176
|
+
this.addVertexUniformLocations();
|
|
177
|
+
this.addFragmentUniformLocations();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
protected setupVertex(): void{
|
|
181
|
+
throw new Error("Setup vertex needs to be overridden");
|
|
182
|
+
}
|
|
183
|
+
protected setupFragment(): void{
|
|
184
|
+
throw new Error("Setup fragment needs to be overridden");
|
|
185
|
+
}
|
|
186
|
+
protected addVertexAttributeLocations(): void{
|
|
187
|
+
throw new Error("Vertex attributes need to be overridden");
|
|
188
|
+
};
|
|
189
|
+
protected addVertexUniformLocations(): void{
|
|
190
|
+
throw new Error("Vertex uniforms need to be overridden");
|
|
191
|
+
};
|
|
192
|
+
protected addFragmentUniformLocations(): void{
|
|
193
|
+
throw new Error("Fragment uniforms need to be overridden");
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export type CustomShaderProgramable = Mixin.GConstructor<ShaderProgramMixin>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
type Float = number;
|
|
3
|
+
export class Line{
|
|
4
|
+
x1: Float;
|
|
5
|
+
y1: Float;
|
|
6
|
+
x2: Float;
|
|
7
|
+
y2: Float;
|
|
8
|
+
constructor(x1: Float, y1: Float, x2: Float, y2: Float){
|
|
9
|
+
this.x1 = x1; this.y1 = y1;
|
|
10
|
+
this.x2 = x2; this.y2 = y2;
|
|
11
|
+
}
|
|
12
|
+
angleInRadians(flip_y:boolean=true): Float{
|
|
13
|
+
const dx = this.x2-this.x1;
|
|
14
|
+
const dy = this.y2-this.y1;
|
|
15
|
+
return Math.atan2(flip_y ? -dy : dy, dx);
|
|
16
|
+
}
|
|
17
|
+
length(){
|
|
18
|
+
const dx = this.x2-this.x1;
|
|
19
|
+
const dy = this.y2-this.y1;
|
|
20
|
+
|
|
21
|
+
return Math.sqrt(dx*dx + dy*dy);
|
|
22
|
+
}
|
|
23
|
+
midPoint(): {x: Float, y: Float}{
|
|
24
|
+
const dx = this.x2-this.x1;
|
|
25
|
+
const dy = this.y2-this.y1;
|
|
26
|
+
|
|
27
|
+
return {x: this.x1+dx/2, y: this.y1+dy/2};
|
|
28
|
+
}
|
|
29
|
+
}
|