Made entire pipeline class based.
This commit is contained in:
4
src/script/api/asset.d.ts
vendored
4
src/script/api/asset.d.ts
vendored
@ -3,6 +3,6 @@
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
declare function assetShaderLoad(shader:Shader, vert:string, frag:string):void;
|
||||
declare function assetShaderLoad(shader:CShader, vert:string, frag:string):void;
|
||||
|
||||
declare function assetTextureLoad(texture:Texture, file:string):void;
|
||||
declare function assetTextureLoad(texture:CTexture, file:string):void;
|
50
src/script/api/display.d.ts
vendored
50
src/script/api/display.d.ts
vendored
@ -1,71 +1,71 @@
|
||||
type Primitive = Pointer<'PRIMITIVE'>;
|
||||
type Camera = Pointer<'CAMERA'>;
|
||||
type Shader = Pointer<'SHADER'>;
|
||||
type Texture = Pointer<'TEXTURE'>;
|
||||
type CPrimitive = Pointer<'PRIMITIVE'>;
|
||||
type CCamera = Pointer<'CAMERA'>;
|
||||
type CShader = Pointer<'SHADER'>;
|
||||
type CTexture = Pointer<'TEXTURE'>;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
declare function primitiveCreate():Primitive;
|
||||
declare function primitiveCreate():CPrimitive;
|
||||
|
||||
declare function primitiveInit(
|
||||
primitive:Primitive, verticeCount:number, indiceCount:number
|
||||
primitive:CPrimitive, verticeCount:number, indiceCount:number
|
||||
):void;
|
||||
|
||||
declare function primitiveDraw(
|
||||
primitive:Primitive, start:number, end:number
|
||||
primitive:CPrimitive, start:number, count:number
|
||||
):void;
|
||||
|
||||
declare function primitiveDispose(primitive:Primitive):void;
|
||||
declare function primitiveDispose(primitive:CPrimitive):void;
|
||||
|
||||
declare function quadInit(primitive:Primitive, z:number,
|
||||
declare function quadInit(primitive:CPrimitive, z:number,
|
||||
x0:number, y0:number, u0:number, v0:number,
|
||||
x1:number, y1:number, u1:number, v1:number
|
||||
):void;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
declare function cameraCreate():Camera;
|
||||
declare function cameraCreate():CCamera;
|
||||
|
||||
declare function cameraLookAt(camera:Camera,
|
||||
declare function cameraLookAt(camera:CCamera,
|
||||
x:number, y:number, z:number,
|
||||
lookX:number, lookY:number, lookZ:number
|
||||
):void;
|
||||
|
||||
declare function cameraLook(camera:Camera,
|
||||
declare function cameraLook(camera:CCamera,
|
||||
x:number, y:number, z:number,
|
||||
pitch:number, yaw:number, roll:number
|
||||
):void;
|
||||
|
||||
declare function cameraPerspective(camera:Camera,
|
||||
declare function cameraPerspective(camera:CCamera,
|
||||
fov:number, aspect:number, near:number, far:number
|
||||
):void;
|
||||
|
||||
declare function cameraOrtho(camera:Camera,
|
||||
declare function cameraOrtho(camera:CCamera,
|
||||
left:number, right:number, bottom:number, top:number, near:number, far:number
|
||||
):void;
|
||||
|
||||
declare function cameraDispose(camera:Camera):void;
|
||||
declare function cameraDispose(camera:CCamera):void;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
declare function shaderCreate():Shader;
|
||||
declare function shaderCreate():CShader;
|
||||
|
||||
declare function shaderInit(shader:Shader, vert:string, frag:string):void;
|
||||
declare function shaderInit(shader:CShader, vert:string, frag:string):void;
|
||||
|
||||
declare function shaderDispose(shader:Shader):void;
|
||||
declare function shaderDispose(shader:CShader):void;
|
||||
|
||||
declare function shaderUse(shader:Shader):void;
|
||||
declare function shaderUse(shader:CShader):void;
|
||||
|
||||
declare function shaderUseTexture(shader:Shader, texture:Texture):void;
|
||||
declare function shaderUseTexture(shader:CShader, texture:CTexture):void;
|
||||
|
||||
declare function shaderUseCamera(shader:Shader, camera:Camera):void;
|
||||
declare function shaderUseCamera(shader:CShader, camera:CCamera):void;
|
||||
|
||||
declare function shaderUsePosition(shader:Shader,
|
||||
declare function shaderUsePosition(shader:CShader,
|
||||
x:number, y:number, z:number,
|
||||
pitch:number, yaw:number, roll:number
|
||||
):void;
|
||||
|
||||
declare function shaderUsePositionAndScale(shader:Shader,
|
||||
declare function shaderUsePositionAndScale(shader:CShader,
|
||||
x:number, y:number, z:number,
|
||||
pitch:number, yaw:number, roll:number,
|
||||
sx:number, sy:number, sz:number
|
||||
@ -73,6 +73,6 @@ declare function shaderUsePositionAndScale(shader:Shader,
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
declare function textureCreate():Texture;
|
||||
declare function textureCreate():CTexture;
|
||||
|
||||
declare function textureDispose(texture:Texture):void;
|
||||
declare function textureDispose(texture:CTexture):void;
|
@ -1,10 +1,12 @@
|
||||
import { Shader } from "../display/Shader";
|
||||
|
||||
export interface IAssetOwner {
|
||||
|
||||
}
|
||||
|
||||
export class AssetManager {
|
||||
private owners:{ [key:string]:IAssetOwner[] };
|
||||
private textures:{ [key:string]:Texture };
|
||||
private textures:{ [key:string]:CTexture };
|
||||
private shaders:{ [key:string]:Shader };
|
||||
|
||||
constructor() {
|
||||
@ -18,7 +20,7 @@ export class AssetManager {
|
||||
this.owners[name].push(owner);
|
||||
}
|
||||
|
||||
public textureLoad(name:string, owner:IAssetOwner):Texture {
|
||||
public textureLoad(name:string, owner:IAssetOwner):CTexture {
|
||||
this.addOwner(name, owner);
|
||||
if(this.textures[name]) return this.textures[name];
|
||||
this.textures[name] = textureCreate();
|
||||
@ -29,8 +31,8 @@ export class AssetManager {
|
||||
public shaderLoad(vert:string, frag:string, owner:IAssetOwner):Shader {
|
||||
this.addOwner(vert, owner);
|
||||
if(this.shaders[vert]) return this.shaders[vert];
|
||||
this.shaders[vert] = shaderCreate();
|
||||
assetShaderLoad(this.shaders[vert], vert, frag);
|
||||
this.shaders[vert] = new Shader();
|
||||
assetShaderLoad(this.shaders[vert]._shader, vert, frag);
|
||||
return this.shaders[vert];
|
||||
}
|
||||
|
||||
|
32
ts/display/Camera.ts
Normal file
32
ts/display/Camera.ts
Normal file
@ -0,0 +1,32 @@
|
||||
export class Camera {
|
||||
public _camera:CCamera;
|
||||
|
||||
constructor() {
|
||||
this._camera = cameraCreate();
|
||||
}
|
||||
|
||||
public lookAt(x:number, y:number, z:number, lx:number, ly:number, lz:number) {
|
||||
cameraLookAt(this._camera, x, y, z, lx, ly, lz);
|
||||
}
|
||||
|
||||
public look(
|
||||
x:number, y:number, z:number, pitch:number, yaw:number, roll:number
|
||||
) {
|
||||
cameraLook(this._camera, x, y, z, pitch, yaw, roll);
|
||||
}
|
||||
|
||||
public perspective(fov:number, aspect:number, near:number, far:number) {
|
||||
cameraPerspective(this._camera, fov, aspect, near, far);
|
||||
}
|
||||
|
||||
public ortho(
|
||||
left:number, right:number, bottom:number, top:number,
|
||||
near:number, far:number
|
||||
) {
|
||||
cameraOrtho(this._camera, left, right, bottom, top, near, far);
|
||||
}
|
||||
|
||||
public dispose() {
|
||||
cameraDispose(this._camera);
|
||||
}
|
||||
}
|
15
ts/display/Primitive.ts
Normal file
15
ts/display/Primitive.ts
Normal file
@ -0,0 +1,15 @@
|
||||
export class Primitive {
|
||||
public _primitive:CPrimitive;
|
||||
|
||||
public constructor() {
|
||||
this._primitive = primitiveCreate();
|
||||
}
|
||||
|
||||
draw(start:number=0, count:number=-1) {
|
||||
primitiveDraw(this._primitive, start, count);
|
||||
}
|
||||
|
||||
public dispose() {
|
||||
primitiveDispose(this._primitive);
|
||||
}
|
||||
}
|
11
ts/display/Quad.ts
Normal file
11
ts/display/Quad.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { Primitive } from "./Primitive";
|
||||
|
||||
export class Quad extends Primitive {
|
||||
constructor(z:number = 0,
|
||||
x0:number = -1, y0:number = -1, u0:number = 0, v0:number = 0,
|
||||
x1:number = 1, y1:number = 1, u1:number = 1, v1:number = 1
|
||||
) {
|
||||
super();
|
||||
quadInit(this._primitive, z, x0, y0, u0, v0, x1, y1, u1, v1);
|
||||
}
|
||||
}
|
39
ts/display/Shader.ts
Normal file
39
ts/display/Shader.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import { Camera } from "./Camera";
|
||||
|
||||
export class Shader {
|
||||
public _shader:CShader;
|
||||
|
||||
constructor() {
|
||||
this._shader = shaderCreate();
|
||||
}
|
||||
|
||||
public use() {
|
||||
shaderUse(this._shader);
|
||||
}
|
||||
|
||||
public setCamera(camera:Camera) {
|
||||
shaderUseCamera(this._shader, camera._camera);
|
||||
}
|
||||
|
||||
public setPosition(
|
||||
x:number, y:number, z:number, pitch:number, yaw:number, roll:number
|
||||
) {
|
||||
shaderUsePosition(this._shader, x,y,z, pitch,yaw,roll);
|
||||
}
|
||||
|
||||
public setPositionAndScale(
|
||||
x:number, y:number, z:number,
|
||||
pitch:number, yaw:number, roll:number,
|
||||
sx:number, sy:number, sz:number
|
||||
) {
|
||||
shaderUsePositionAndScale(this._shader, x,y,z, pitch,yaw,roll, sx,sy,sz);
|
||||
}
|
||||
|
||||
public setTexture(texture:CTexture) {
|
||||
shaderUseTexture(this._shader, texture);
|
||||
}
|
||||
|
||||
public dispose() {
|
||||
shaderDispose(this._shader);
|
||||
}
|
||||
}
|
30
ts/main.ts
30
ts/main.ts
@ -1,35 +1,35 @@
|
||||
import { Camera } from "./display/Camera";
|
||||
import { Quad } from "./display/Quad";
|
||||
import { Shader } from "./display/Shader";
|
||||
import { Game, gameSetMain } from "./game/Game";
|
||||
import { Scene } from "./scene/Scene";
|
||||
|
||||
class TestScene extends Scene {
|
||||
private quad:Primitive;
|
||||
private quad:Quad;
|
||||
private camera:Camera;
|
||||
private shader:Shader;
|
||||
private texture:Texture;
|
||||
private texture:CTexture;
|
||||
|
||||
init() {
|
||||
this.quad = primitiveCreate();
|
||||
quadInit(this.quad, 0,
|
||||
-1, -1, 0, 0,
|
||||
1, 1, 1, 1
|
||||
);
|
||||
this.quad = new Quad();
|
||||
|
||||
this.shader = this.game.assets.shaderLoad(
|
||||
"shaders/textured.vert", "shaders/textured.frag", this
|
||||
);
|
||||
this.texture = this.game.assets.textureLoad("test_texture.png", this);
|
||||
|
||||
this.camera = cameraCreate();
|
||||
cameraLookAt(this.camera, 3,3,3, 0,0,0);
|
||||
cameraPerspective(this.camera, 45, 16/9, 0.01, 1000);
|
||||
this.camera = new Camera();
|
||||
}
|
||||
|
||||
update() {
|
||||
shaderUse(this.shader);
|
||||
shaderUseCamera(this.shader, this.camera);
|
||||
shaderUsePosition(this.shader, 0,0,0, 0,this.game.time.current,0);
|
||||
shaderUseTexture(this.shader, this.texture);
|
||||
primitiveDraw(this.quad, 0, -1);
|
||||
this.camera.perspective(45, 16/9, 0.01, 100);
|
||||
this.camera.lookAt(3,3,3, 0,0,0);
|
||||
|
||||
this.shader.use();
|
||||
this.shader.setCamera(this.camera);
|
||||
this.shader.setPosition(0,0,0, 0,this.game.time.current,0);
|
||||
this.shader.setTexture(this.texture);
|
||||
this.quad.draw();
|
||||
}
|
||||
|
||||
dispose() {
|
||||
|
Reference in New Issue
Block a user