From 1e7735a30ef0c95a0522b8e68045451f9e778c70 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 10 Sep 2024 17:34:00 +0000 Subject: [PATCH 01/59] Initial Stage3D Stuff --- .gitignore | 3 +- lib/SecurityDomain.ts | 2 + lib/display/Stage.ts | 9 ++- lib/display/Stage3D.ts | 54 +++++++++++++++++ lib/display3D/Context3D.ts | 84 ++++++++++++++++++++++++++- lib/display3D/Context3DProfile.ts | 9 +++ lib/display3D/Context3DProgramType.ts | 5 +- lib/display3D/Context3DRenderMode.ts | 4 ++ lib/link.ts | 6 +- 9 files changed, 167 insertions(+), 9 deletions(-) create mode 100644 lib/display/Stage3D.ts create mode 100644 lib/display3D/Context3DProfile.ts create mode 100644 lib/display3D/Context3DRenderMode.ts diff --git a/.gitignore b/.gitignore index 070094f9..03c3e8dc 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,5 @@ npm-debug.log # Misc deploy_key -deploy_key.pub \ No newline at end of file +deploy_key.pub +.vscode/settings.json diff --git a/lib/SecurityDomain.ts b/lib/SecurityDomain.ts index 682aed1a..dc786dec 100644 --- a/lib/SecurityDomain.ts +++ b/lib/SecurityDomain.ts @@ -17,6 +17,8 @@ import { EventDispatcher } from './events/EventDispatcher'; import { DisplayObject } from './display/DisplayObject'; import { DisplayObjectContainer } from './display/DisplayObjectContainer'; import { Stage } from './display/Stage'; +import { Stage3D } from './display/Stage3D'; +// TODO: Add display3d stuff import { Loader } from './display/Loader'; import { LoaderInfo } from './display/LoaderInfo'; import { MovieClip } from './display/MovieClip'; diff --git a/lib/display/Stage.ts b/lib/display/Stage.ts index f853575f..000a8a06 100644 --- a/lib/display/Stage.ts +++ b/lib/display/Stage.ts @@ -6,7 +6,7 @@ import { DisplayObjectContainer } from './DisplayObjectContainer'; import { DisplayObject } from './DisplayObject'; import { FrameScriptManager } from '@awayjs/scene'; import { View } from '@awayjs/view'; -import { Stage as AwayStage } from '@awayjs/stage'; +import { Stage3D } from './Stage3D'; import { DisplayObjectContainer as AwayDisplayObjectContainer, MouseEvent as MouseEventAway } from '@awayjs/scene'; import { Transform } from '../geom/Transform'; import { Rectangle } from '../geom/Rectangle'; @@ -153,7 +153,7 @@ import { InteractiveObject } from './InteractiveObject'; export class Stage extends DisplayObjectContainer { - private _stage3Ds: AwayStage[]; + private _stage3Ds: Array; private _sendEventRender: boolean; @@ -163,6 +163,9 @@ export class Stage extends DisplayObjectContainer { this._isStage = true; this._stage3Ds = []; + for (let i:number=0; i < 8; i++) { + this.stage3Ds.push(new Stage3D) + } // resize event listens on window this._resizeCallbackDelegate = (event: any) => this.resizeCallback(event); @@ -808,7 +811,7 @@ export class Stage extends DisplayObjectContainer { } - public get stage3Ds (): AwayStage[] { + public get stage3Ds (): Stage3D[] { // @todo Debug.throwPIR('playerglobals/display/Stage', 'get stage3Ds', ''); return this._stage3Ds; diff --git a/lib/display/Stage3D.ts b/lib/display/Stage3D.ts new file mode 100644 index 00000000..cbe04a24 --- /dev/null +++ b/lib/display/Stage3D.ts @@ -0,0 +1,54 @@ +import { ContextGLProfile, ContextMode, Stage as AwayStage, Stage, StageManager } from "@awayjs/stage"; +import { EventDispatcher } from "../events/EventDispatcher"; +import { Context3D } from "../display3D/Context3D"; +import { Context3DProfile } from "../display3D/Context3DProfile"; +import { AVMStage } from "@awayfl/swf-loader"; + +export class Stage3D extends EventDispatcher { + private _context3D:Context3D + private _visible:Boolean + private _x:number + private _y:number + + private _adapteeStage3Ds:AwayStage[] = AVMStage.instance().stage3Ds + private _adaptee:AwayStage + + constructor(){ + super() + + console.log("numSlotsTotal: " + StageManager.getInstance().numSlotsTotal); + console.log("numSlotsUsed: " + StageManager.getInstance().numSlotsUsed); + console.log("numSlotsFree: " + StageManager.getInstance().numSlotsFree); + this._adapteeStage3Ds[this._adapteeStage3Ds.length] = StageManager.getInstance().getFreeStage() + console.log("Created Stage3D " + (this._adapteeStage3Ds.length-1)) + + } + + public requestContext3D(context3DRenderMode:String = "auto", profile:String = "baseline"):void + { + this._context3D = new Context3D(this._adaptee, profile) + var forceSoftware:boolean = (context3DRenderMode == "auto"); + switch(profile) { + case Context3DProfile.BASELINE: + this._adaptee.requestContext(forceSoftware, ContextGLProfile.BASELINE); + break; + case Context3DProfile.BASELINE_CONSTRAINED: + this._adaptee.requestContext(forceSoftware, ContextGLProfile.BASELINE); + break; + case Context3DProfile.BASELINE_EXTENDED: + this._adaptee.requestContext(forceSoftware, ContextGLProfile.BASELINE); + break; + case Context3DProfile.STANDARD: + console.log("Unsupported Context3D Profile 'standard' Requested"); + break; + case Context3DProfile.STANDARD_CONSTRAINED: + console.log("Unsupported Context3D Profile 'standard_constrained' Requested"); + break; + case Context3DProfile.STANDARD_EXTENDED: + console.log("Unsupported Context3D Profile 'standard_extended' Requested"); + break; + + } + + } +} \ No newline at end of file diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index 882b07c6..5abb5cda 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -1 +1,83 @@ -export { ContextWebGL as Context3D } from '@awayjs/stage'; +import { ContextWebGL, Stage as AwayStage, StageEvent } from '@awayjs/stage'; +import { EventDispatcher } from "../events/EventDispatcher"; + +export class Context3D extends EventDispatcher { + private _adaptee:AwayStage + private _errorChecking:boolean + + constructor(awayStage:AwayStage, profile) { + super() + awayStage.addEventListener(StageEvent.CONTEXT_CREATED, function() { + this._adaptee = awayStage } + )} + + // Properties + public get backBufferHeight():number { + return this._adaptee.height + } + + public set backBufferHeight(value:number) { + this._adaptee.height = value + } + + public get backBufferWidth():number { + return this._adaptee.width + } + + public set backBufferWidth(value:number) { + this._adaptee.width = value + } + + public get driverInfo():string { + return "" + } + + public get enableErrorChecking():boolean { + return this._errorChecking + } + + public set enableErrorChecking(value:boolean) { + this._errorChecking = value + } + + + public get maxBackBufferHeight():number { + return + } + + public set maxBackBufferHeight(value:number) { + + } + + public get maxBackBufferWidth():number { + return this._adaptee.width + } + + public set maxBackBufferWidth(value:number) { + + } + + public get profile():string { + return this.profile + } + + public static get supportsVideoTexture():boolean { + return false + } + + public get totalGPUMemory():number{ + return 512 + } + + //Functions + public clear(red:number = 0.0, green:number = 0.0, blue:number = 0.0, alpha:number = 1.0, depth:number = 1.0, stencil:number = 0, mask:number = 0xffffffff):void + { + console.log("Mask: " + mask) + this._adaptee.clear(red, green, blue, alpha, depth, stencil, mask) + } + + public configureBackBuffer(width:number, height:number, antiAlias:number, enableDepthAndStencil:boolean = true, wantsBestResolution:Boolean = false, wantsBestResolutionOnBrowserZoom:Boolean = false):void { + this._adaptee.configureBackBuffer(width, height, antiAlias, enableDepthAndStencil) + } + +} \ No newline at end of file diff --git a/lib/display3D/Context3DProfile.ts b/lib/display3D/Context3DProfile.ts new file mode 100644 index 00000000..fa41ddfe --- /dev/null +++ b/lib/display3D/Context3DProfile.ts @@ -0,0 +1,9 @@ +export enum Context3DProfile { + BASELINE = "baseline", + BASELINE_CONSTRAINED = "baselineConstrained", + BASELINE_EXTENDED = "baselineExtended", + STANDARD = "standard", + STANDARD_CONSTRAINED = "standardConstrained", + STANDARD_EXTENDED = "standardExtended", + +} \ No newline at end of file diff --git a/lib/display3D/Context3DProgramType.ts b/lib/display3D/Context3DProgramType.ts index 325b76b5..26d69ea0 100644 --- a/lib/display3D/Context3DProgramType.ts +++ b/lib/display3D/Context3DProgramType.ts @@ -1 +1,4 @@ -export { ContextGLProgramType as Context3DProgramType } from '@awayjs/stage'; +export enum Context3DProgramType{ + FRAGMENT = "fragment", + VERTEX = "vertex" +} \ No newline at end of file diff --git a/lib/display3D/Context3DRenderMode.ts b/lib/display3D/Context3DRenderMode.ts new file mode 100644 index 00000000..b8b1a34f --- /dev/null +++ b/lib/display3D/Context3DRenderMode.ts @@ -0,0 +1,4 @@ +export enum Context3DRenderMode{ + AUTO = "auto", + SOFTWARE = "software" +} \ No newline at end of file diff --git a/lib/link.ts b/lib/link.ts index d4ffa7fc..bcb0d7aa 100644 --- a/lib/link.ts +++ b/lib/link.ts @@ -25,6 +25,7 @@ import { Shape } from './display/Shape'; import { SimpleButton } from './display/SimpleButton'; import { Sprite } from './display/Sprite'; import { Stage } from './display/Stage'; +import { Stage3D } from './display/Stage3D'; import { EOFError } from './errors/EOFError'; import { IllegalOperationError } from './errors/IllegalOperationError'; @@ -286,7 +287,7 @@ export function initLink() { //M('flash.display.SpreadMethod', SpreadMethod); M('flash.display.Sprite', Sprite); M('flash.display.Stage', Stage); - //M('flash.display.Stage3D', Stage3D); + M('flash.display.Stage3D', Stage3D); //M('flash.display.StageAlign', StageAlign); //M('flash.display.StageAspectRatio', StageAspectRatio);//AIR //M('flash.display.StageDisplayState', StageDisplayState); @@ -294,8 +295,7 @@ export function initLink() { //M('flash.display.StageScaleMode', StageScaleMode); //M('flash.display.TriangleCulling', TriangleCulling); - // flash.display3D - // flash.display3D.textures + // TODO: Add display3d stuff //M('flash.errors.DRMManagerError', DRMManagerError);//AIR M('flash.errors.EOFError', EOFError); From 2279ccd976e7c3fa8c1cffb0b3c495ab7826888e Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 10 Sep 2024 17:37:34 +0000 Subject: [PATCH 02/59] Add Stage3D to SecurityDomain --- lib/SecurityDomain.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/SecurityDomain.ts b/lib/SecurityDomain.ts index dc786dec..508f0c0a 100644 --- a/lib/SecurityDomain.ts +++ b/lib/SecurityDomain.ts @@ -18,7 +18,6 @@ import { DisplayObject } from './display/DisplayObject'; import { DisplayObjectContainer } from './display/DisplayObjectContainer'; import { Stage } from './display/Stage'; import { Stage3D } from './display/Stage3D'; -// TODO: Add display3d stuff import { Loader } from './display/Loader'; import { LoaderInfo } from './display/LoaderInfo'; import { MovieClip } from './display/MovieClip'; @@ -89,6 +88,7 @@ export class SecurityDomain extends AXSecurityDomain { DisplayObject: DisplayObject, DisplayObjectContainer: DisplayObjectContainer, Stage: Stage, + Stage3D: Stage3D, Loader: Loader, LoaderInfo: LoaderInfo, MovieClip: MovieClip, From 6e6fdf8ac4826b9a87e98bb5b9735de18f1a05f2 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 10 Sep 2024 19:25:11 +0000 Subject: [PATCH 03/59] Commit Progress --- lib/display/Stage3D.ts | 7 +- lib/display3D/Context3D.ts | 108 ++++++++++--------- lib/display3D/Context3DVertexBufferFormat.ts | 7 ++ lib/display3D/IndexBuffer3D.ts | 21 ++++ lib/display3D/Program3D.ts | 27 +++++ lib/display3D/VertexBuffer3D.ts | 20 ++++ 6 files changed, 136 insertions(+), 54 deletions(-) create mode 100644 lib/display3D/Context3DVertexBufferFormat.ts create mode 100644 lib/display3D/IndexBuffer3D.ts create mode 100644 lib/display3D/Program3D.ts create mode 100644 lib/display3D/VertexBuffer3D.ts diff --git a/lib/display/Stage3D.ts b/lib/display/Stage3D.ts index cbe04a24..699d1fff 100644 --- a/lib/display/Stage3D.ts +++ b/lib/display/Stage3D.ts @@ -1,6 +1,7 @@ import { ContextGLProfile, ContextMode, Stage as AwayStage, Stage, StageManager } from "@awayjs/stage"; import { EventDispatcher } from "../events/EventDispatcher"; import { Context3D } from "../display3D/Context3D"; +import { Event } from '../events/Event'; import { Context3DProfile } from "../display3D/Context3DProfile"; import { AVMStage } from "@awayfl/swf-loader"; @@ -24,6 +25,10 @@ export class Stage3D extends EventDispatcher { } + public get context3D():Context3D { + return this._context3D + } + public requestContext3D(context3DRenderMode:String = "auto", profile:String = "baseline"):void { this._context3D = new Context3D(this._adaptee, profile) @@ -49,6 +54,6 @@ export class Stage3D extends EventDispatcher { break; } - + super.dispatchEvent(new Event(Event.CONTEXT3D_CREATE)) } } \ No newline at end of file diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index 5abb5cda..41720493 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -1,83 +1,85 @@ -import { ContextWebGL, Stage as AwayStage, StageEvent } from '@awayjs/stage'; +import { ContextGLDrawMode, ContextGLVertexBufferFormat, Stage as AwayStage, StageEvent } from '@awayjs/stage'; import { EventDispatcher } from "../events/EventDispatcher"; +import { Context3DVertexBufferFormat } from "../display3D/Context3DVertexBufferFormat" +import { IndexBuffer3D } from "../display3D/IndexBuffer3D" +import { VertexBuffer3D } from "../display3D/VertexBuffer3D" +import { Program3D } from "../display3D/Program3D" +import { Matrix3D } from "../geom/Matrix3D" + export class Context3D extends EventDispatcher { private _adaptee:AwayStage - private _errorChecking:boolean constructor(awayStage:AwayStage, profile) { super() - awayStage.addEventListener(StageEvent.CONTEXT_CREATED, function() { - this._adaptee = awayStage } + awayStage.addEventListener(StageEvent.CONTEXT_CREATED, + function() { + this._adaptee = awayStage + } )} - // Properties - public get backBufferHeight():number { - return this._adaptee.height - } - - public set backBufferHeight(value:number) { - this._adaptee.height = value - } - - public get backBufferWidth():number { - return this._adaptee.width - } - - public set backBufferWidth(value:number) { - this._adaptee.width = value - } - - public get driverInfo():string { - return "" - } - - public get enableErrorChecking():boolean { - return this._errorChecking - } - - public set enableErrorChecking(value:boolean) { - this._errorChecking = value + public clear(red:number = 0.0, green:number = 0.0, blue:number = 0.0, alpha:number = 1.0, depth:number = 1.0, stencil:number = 0, mask:number = 0xffffffff):void + { + console.log("Mask: " + mask) + this._adaptee.clear(red, green, blue, alpha, depth, stencil, mask) } - - public get maxBackBufferHeight():number { - return + public configureBackBuffer(width:number, height:number, antiAlias:number, enableDepthAndStencil:boolean = true, wantsBestResolution:Boolean = false, wantsBestResolutionOnBrowserZoom:Boolean = false):void { + this._adaptee.configureBackBuffer(width, height, antiAlias, enableDepthAndStencil) } - public set maxBackBufferHeight(value:number) { - + public createIndexBuffer(numIndices:number, bufferUsage:string = "staticDraw"):IndexBuffer3D { + return new IndexBuffer3D(this._adaptee.context, numIndices) } - public get maxBackBufferWidth():number { - return this._adaptee.width + public createProgram():Program3D{ + return new Program3D(this._adaptee.context) } - public set maxBackBufferWidth(value:number) { - + public createVertexBuffer(numVertices:number, data32PerVertex:number, bufferUsage:string = "staticDraw"):VertexBuffer3D { + return new VertexBuffer3D(this._adaptee.context, numVertices, data32PerVertex) } - public get profile():string { - return this.profile + public drawTriangles(indexBuffer:IndexBuffer3D, firstIndex:number = 0, numTriangles:number = -1):void { + if (numTriangles != -1){ + var numIndices = numTriangles + } else { + var numIndices = numTriangles*3 + } + this._adaptee.context.drawIndices(ContextGLDrawMode.TRIANGLES, indexBuffer._adaptee, firstIndex, numIndices) } - public static get supportsVideoTexture():boolean { - return false + public present():void{ + this._adaptee.present() } - public get totalGPUMemory():number{ - return 512 + public setProgram(program:Program3D):void{ + this._adaptee.context.setProgram(program._adaptee) } - //Functions - public clear(red:number = 0.0, green:number = 0.0, blue:number = 0.0, alpha:number = 1.0, depth:number = 1.0, stencil:number = 0, mask:number = 0xffffffff):void - { - console.log("Mask: " + mask) - this._adaptee.clear(red, green, blue, alpha, depth, stencil, mask) + public setProgramConstantsFromMatrix(programType:string, firstRegister:number, matrix:Matrix3D, transposedMatrix:boolean = false):void { + //TODO: Figure out how to use ContextGL's setProgramConstantsFromArray with a Matrix3D } - public configureBackBuffer(width:number, height:number, antiAlias:number, enableDepthAndStencil:boolean = true, wantsBestResolution:Boolean = false, wantsBestResolutionOnBrowserZoom:Boolean = false):void { - this._adaptee.configureBackBuffer(width, height, antiAlias, enableDepthAndStencil) + public setVertexBufferAt(index:number, buffer:VertexBuffer3D, bufferOffset:number = 0, format:String = "float4"):void{ + switch(format) { + case Context3DVertexBufferFormat.BYTES_4: + var awayFormat = ContextGLVertexBufferFormat.BYTE_4 + break; + case Context3DVertexBufferFormat.FLOAT_1: + var awayFormat = ContextGLVertexBufferFormat.FLOAT_1 + break; + case Context3DVertexBufferFormat.FLOAT_2: + var awayFormat = ContextGLVertexBufferFormat.FLOAT_2 + break; + case Context3DVertexBufferFormat.FLOAT_3: + var awayFormat = ContextGLVertexBufferFormat.FLOAT_3 + break; + case Context3DVertexBufferFormat.FLOAT_4: + var awayFormat = ContextGLVertexBufferFormat.FLOAT_4 + break; + } + this._adaptee.context.setVertexBufferAt(index, buffer._adaptee, bufferOffset, awayFormat) } } \ No newline at end of file diff --git a/lib/display3D/Context3DVertexBufferFormat.ts b/lib/display3D/Context3DVertexBufferFormat.ts new file mode 100644 index 00000000..963db45d --- /dev/null +++ b/lib/display3D/Context3DVertexBufferFormat.ts @@ -0,0 +1,7 @@ +export enum Context3DVertexBufferFormat{ + BYTES_4 = "bytes4", + FLOAT_1 = "float1", + FLOAT_2 = "float2", + FLOAT_3 = "float3", + FLOAT_4 = "float4" +} \ No newline at end of file diff --git a/lib/display3D/IndexBuffer3D.ts b/lib/display3D/IndexBuffer3D.ts new file mode 100644 index 00000000..1438721b --- /dev/null +++ b/lib/display3D/IndexBuffer3D.ts @@ -0,0 +1,21 @@ +import { ASObject } from "@awayfl/avm2"; +import { IContextGL, IIndexBuffer } from "@awayjs/stage"; + +export class IndexBuffer3D extends ASObject { + static classInitializer = null; + + static axClass: typeof IndexBuffer3D; + + public _adaptee:IIndexBuffer + + constructor(context: IContextGL, numIndices: number) { + super() + this._adaptee = context.createIndexBuffer(numIndices) + } + + public uploadFromVector(data:Array, startOffset:number, count:number):void{ + var uint16ArrayData = new Uint16Array(data) + this._adaptee.uploadFromArray(uint16ArrayData, startOffset, count) + } + +} \ No newline at end of file diff --git a/lib/display3D/Program3D.ts b/lib/display3D/Program3D.ts new file mode 100644 index 00000000..e88fe771 --- /dev/null +++ b/lib/display3D/Program3D.ts @@ -0,0 +1,27 @@ +import { ASObject } from "@awayfl/avm2"; +import { ByteArray as AwayByteArray } from "@awayjs/core"; +import { IContextGL, IProgram } from "@awayjs/stage"; +import { ByteArray } from "../utils/ByteArray"; + +export class Program3D extends ASObject { + static classInitializer = null; + + static axClass: typeof Program3D; + + public _adaptee:IProgram + + constructor(context:IContextGL){ + super() + this._adaptee = context.createProgram() + + } + + public dispose(){ + this._adaptee.dispose() + } + + public upload(vertexProgram:ByteArray, fragmentProgram:ByteArray):void { + AwayByteArray + this._adaptee.upload(vertexProgram, fragmentProgram) + } +} \ No newline at end of file diff --git a/lib/display3D/VertexBuffer3D.ts b/lib/display3D/VertexBuffer3D.ts new file mode 100644 index 00000000..d2806453 --- /dev/null +++ b/lib/display3D/VertexBuffer3D.ts @@ -0,0 +1,20 @@ +import { ASObject } from "@awayfl/avm2"; +import { IContextGL, IVertexBuffer, VertexBufferWebGL } from "@awayjs/stage"; + +export class VertexBuffer3D extends ASObject { + public _adaptee:IVertexBuffer + + static classInitializer = null; + + static axClass: typeof VertexBuffer3D; + + constructor(context:IContextGL, numVertices, dataPerVertex) { + super() + this._adaptee = context.createVertexBuffer(numVertices, dataPerVertex) + } + + public uploadFromVector(data:Array, startVertex:number, numVertices){ + var dataFloat32Array:Float32Array = new Float32Array(data) + this._adaptee.uploadFromArray(dataFloat32Array, startVertex, numVertices) + } +} \ No newline at end of file From daacfbb456ae22959b222686bfd0392e5ad88e02 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 10 Sep 2024 19:26:55 +0000 Subject: [PATCH 04/59] Consitency Fix --- lib/display/Stage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/display/Stage.ts b/lib/display/Stage.ts index 000a8a06..6874e1d8 100644 --- a/lib/display/Stage.ts +++ b/lib/display/Stage.ts @@ -153,7 +153,7 @@ import { InteractiveObject } from './InteractiveObject'; export class Stage extends DisplayObjectContainer { - private _stage3Ds: Array; + private _stage3Ds: Stage3D[]; private _sendEventRender: boolean; From 4a6bb536a4158326fc5e66831b51b0089ace53dd Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 10 Sep 2024 19:41:59 +0000 Subject: [PATCH 05/59] Add comment to remind myself --- lib/SecurityDomain.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/SecurityDomain.ts b/lib/SecurityDomain.ts index 508f0c0a..2ff09751 100644 --- a/lib/SecurityDomain.ts +++ b/lib/SecurityDomain.ts @@ -100,6 +100,9 @@ export class SecurityDomain extends AXSecurityDomain { Shape: Shape, FrameLabel: FrameLabel }, + display3d: { + // TODO: Add display3d stuff + }, events: { EventDispatcher: EventDispatcher, Event: Event, From 25d16422d33427c05ea4647f9b3a3b753a98554b Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 10 Sep 2024 19:51:20 +0000 Subject: [PATCH 06/59] Fixed by eslint --- lib/display/Stage.ts | 4 +- lib/display/Stage3D.ts | 109 ++++++++------- lib/display3D/Context3D.ts | 137 +++++++++---------- lib/display3D/Context3DProfile.ts | 12 +- lib/display3D/Context3DProgramType.ts | 4 +- lib/display3D/Context3DRenderMode.ts | 4 +- lib/display3D/Context3DVertexBufferFormat.ts | 10 +- lib/display3D/IndexBuffer3D.ts | 26 ++-- lib/display3D/Program3D.ts | 34 ++--- lib/display3D/VertexBuffer3D.ts | 26 ++-- 10 files changed, 182 insertions(+), 184 deletions(-) diff --git a/lib/display/Stage.ts b/lib/display/Stage.ts index 6874e1d8..02636672 100644 --- a/lib/display/Stage.ts +++ b/lib/display/Stage.ts @@ -163,8 +163,8 @@ export class Stage extends DisplayObjectContainer { this._isStage = true; this._stage3Ds = []; - for (let i:number=0; i < 8; i++) { - this.stage3Ds.push(new Stage3D) + for (let i: number = 0; i < 8; i++) { + this.stage3Ds.push(new Stage3D); } // resize event listens on window diff --git a/lib/display/Stage3D.ts b/lib/display/Stage3D.ts index 699d1fff..32333e87 100644 --- a/lib/display/Stage3D.ts +++ b/lib/display/Stage3D.ts @@ -1,59 +1,58 @@ -import { ContextGLProfile, ContextMode, Stage as AwayStage, Stage, StageManager } from "@awayjs/stage"; -import { EventDispatcher } from "../events/EventDispatcher"; -import { Context3D } from "../display3D/Context3D"; +import { ContextGLProfile, ContextMode, Stage as AwayStage, Stage, StageManager } from '@awayjs/stage'; +import { EventDispatcher } from '../events/EventDispatcher'; +import { Context3D } from '../display3D/Context3D'; import { Event } from '../events/Event'; -import { Context3DProfile } from "../display3D/Context3DProfile"; -import { AVMStage } from "@awayfl/swf-loader"; +import { Context3DProfile } from '../display3D/Context3DProfile'; +import { AVMStage } from '@awayfl/swf-loader'; export class Stage3D extends EventDispatcher { - private _context3D:Context3D - private _visible:Boolean - private _x:number - private _y:number - - private _adapteeStage3Ds:AwayStage[] = AVMStage.instance().stage3Ds - private _adaptee:AwayStage - - constructor(){ - super() - - console.log("numSlotsTotal: " + StageManager.getInstance().numSlotsTotal); - console.log("numSlotsUsed: " + StageManager.getInstance().numSlotsUsed); - console.log("numSlotsFree: " + StageManager.getInstance().numSlotsFree); - this._adapteeStage3Ds[this._adapteeStage3Ds.length] = StageManager.getInstance().getFreeStage() - console.log("Created Stage3D " + (this._adapteeStage3Ds.length-1)) - - } - - public get context3D():Context3D { - return this._context3D - } - - public requestContext3D(context3DRenderMode:String = "auto", profile:String = "baseline"):void - { - this._context3D = new Context3D(this._adaptee, profile) - var forceSoftware:boolean = (context3DRenderMode == "auto"); - switch(profile) { - case Context3DProfile.BASELINE: - this._adaptee.requestContext(forceSoftware, ContextGLProfile.BASELINE); - break; - case Context3DProfile.BASELINE_CONSTRAINED: - this._adaptee.requestContext(forceSoftware, ContextGLProfile.BASELINE); - break; - case Context3DProfile.BASELINE_EXTENDED: - this._adaptee.requestContext(forceSoftware, ContextGLProfile.BASELINE); - break; - case Context3DProfile.STANDARD: - console.log("Unsupported Context3D Profile 'standard' Requested"); - break; - case Context3DProfile.STANDARD_CONSTRAINED: - console.log("Unsupported Context3D Profile 'standard_constrained' Requested"); - break; - case Context3DProfile.STANDARD_EXTENDED: - console.log("Unsupported Context3D Profile 'standard_extended' Requested"); - break; - - } - super.dispatchEvent(new Event(Event.CONTEXT3D_CREATE)) - } + private _context3D: Context3D + private _visible: Boolean + private _x: number + private _y: number + + private _adapteeStage3Ds: AwayStage[] = AVMStage.instance().stage3Ds + private _adaptee: AwayStage + + constructor() { + super(); + + console.log('numSlotsTotal: ' + StageManager.getInstance().numSlotsTotal); + console.log('numSlotsUsed: ' + StageManager.getInstance().numSlotsUsed); + console.log('numSlotsFree: ' + StageManager.getInstance().numSlotsFree); + this._adapteeStage3Ds[this._adapteeStage3Ds.length] = StageManager.getInstance().getFreeStage(); + console.log('Created Stage3D ' + (this._adapteeStage3Ds.length - 1)); + + } + + public get context3D(): Context3D { + return this._context3D; + } + + public requestContext3D(context3DRenderMode: String = 'auto', profile: String = 'baseline'): void { + this._context3D = new Context3D(this._adaptee, profile); + const forceSoftware: boolean = (context3DRenderMode == 'auto'); + switch (profile) { + case Context3DProfile.BASELINE: + this._adaptee.requestContext(forceSoftware, ContextGLProfile.BASELINE); + break; + case Context3DProfile.BASELINE_CONSTRAINED: + this._adaptee.requestContext(forceSoftware, ContextGLProfile.BASELINE); + break; + case Context3DProfile.BASELINE_EXTENDED: + this._adaptee.requestContext(forceSoftware, ContextGLProfile.BASELINE); + break; + case Context3DProfile.STANDARD: + console.log('Unsupported Context3D Profile \'standard\' Requested'); + break; + case Context3DProfile.STANDARD_CONSTRAINED: + console.log('Unsupported Context3D Profile \'standard_constrained\' Requested'); + break; + case Context3DProfile.STANDARD_EXTENDED: + console.log('Unsupported Context3D Profile \'standard_extended\' Requested'); + break; + + } + super.dispatchEvent(new Event(Event.CONTEXT3D_CREATE)); + } } \ No newline at end of file diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index 41720493..c8a09bbf 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -1,85 +1,84 @@ import { ContextGLDrawMode, ContextGLVertexBufferFormat, Stage as AwayStage, StageEvent } from '@awayjs/stage'; -import { EventDispatcher } from "../events/EventDispatcher"; -import { Context3DVertexBufferFormat } from "../display3D/Context3DVertexBufferFormat" -import { IndexBuffer3D } from "../display3D/IndexBuffer3D" -import { VertexBuffer3D } from "../display3D/VertexBuffer3D" -import { Program3D } from "../display3D/Program3D" -import { Matrix3D } from "../geom/Matrix3D" - +import { EventDispatcher } from '../events/EventDispatcher'; +import { Context3DVertexBufferFormat } from '../display3D/Context3DVertexBufferFormat'; +import { IndexBuffer3D } from '../display3D/IndexBuffer3D'; +import { VertexBuffer3D } from '../display3D/VertexBuffer3D'; +import { Program3D } from '../display3D/Program3D'; +import { Matrix3D } from '../geom/Matrix3D'; export class Context3D extends EventDispatcher { - private _adaptee:AwayStage + private _adaptee: AwayStage - constructor(awayStage:AwayStage, profile) { - super() - awayStage.addEventListener(StageEvent.CONTEXT_CREATED, - function() { - this._adaptee = awayStage - } - )} + constructor(awayStage: AwayStage, profile) { + super(); + awayStage.addEventListener(StageEvent.CONTEXT_CREATED, + function() { + this._adaptee = awayStage; + } + ); + } - public clear(red:number = 0.0, green:number = 0.0, blue:number = 0.0, alpha:number = 1.0, depth:number = 1.0, stencil:number = 0, mask:number = 0xffffffff):void - { - console.log("Mask: " + mask) - this._adaptee.clear(red, green, blue, alpha, depth, stencil, mask) - } + public clear(red: number = 0.0, green: number = 0.0, blue: number = 0.0, alpha: number = 1.0, depth: number = 1.0, stencil: number = 0, mask: number = 0xffffffff): void { + console.log('Mask: ' + mask); + this._adaptee.clear(red, green, blue, alpha, depth, stencil, mask); + } - public configureBackBuffer(width:number, height:number, antiAlias:number, enableDepthAndStencil:boolean = true, wantsBestResolution:Boolean = false, wantsBestResolutionOnBrowserZoom:Boolean = false):void { - this._adaptee.configureBackBuffer(width, height, antiAlias, enableDepthAndStencil) - } + public configureBackBuffer(width: number, height: number, antiAlias: number, enableDepthAndStencil: boolean = true, wantsBestResolution: Boolean = false, wantsBestResolutionOnBrowserZoom: Boolean = false): void { + this._adaptee.configureBackBuffer(width, height, antiAlias, enableDepthAndStencil); + } - public createIndexBuffer(numIndices:number, bufferUsage:string = "staticDraw"):IndexBuffer3D { - return new IndexBuffer3D(this._adaptee.context, numIndices) - } + public createIndexBuffer(numIndices: number, bufferUsage: string = 'staticDraw'): IndexBuffer3D { + return new IndexBuffer3D(this._adaptee.context, numIndices); + } - public createProgram():Program3D{ - return new Program3D(this._adaptee.context) - } + public createProgram(): Program3D { + return new Program3D(this._adaptee.context); + } - public createVertexBuffer(numVertices:number, data32PerVertex:number, bufferUsage:string = "staticDraw"):VertexBuffer3D { - return new VertexBuffer3D(this._adaptee.context, numVertices, data32PerVertex) - } + public createVertexBuffer(numVertices: number, data32PerVertex: number, bufferUsage: string = 'staticDraw'): VertexBuffer3D { + return new VertexBuffer3D(this._adaptee.context, numVertices, data32PerVertex); + } - public drawTriangles(indexBuffer:IndexBuffer3D, firstIndex:number = 0, numTriangles:number = -1):void { - if (numTriangles != -1){ - var numIndices = numTriangles - } else { - var numIndices = numTriangles*3 - } - this._adaptee.context.drawIndices(ContextGLDrawMode.TRIANGLES, indexBuffer._adaptee, firstIndex, numIndices) - } + public drawTriangles(indexBuffer: IndexBuffer3D, firstIndex: number = 0, numTriangles: number = -1): void { + if (numTriangles != -1) { + var numIndices = numTriangles; + } else { + var numIndices = numTriangles * 3; + } + this._adaptee.context.drawIndices(ContextGLDrawMode.TRIANGLES, indexBuffer._adaptee, firstIndex, numIndices); + } - public present():void{ - this._adaptee.present() - } + public present(): void { + this._adaptee.present(); + } - public setProgram(program:Program3D):void{ - this._adaptee.context.setProgram(program._adaptee) - } + public setProgram(program: Program3D): void { + this._adaptee.context.setProgram(program._adaptee); + } - public setProgramConstantsFromMatrix(programType:string, firstRegister:number, matrix:Matrix3D, transposedMatrix:boolean = false):void { - //TODO: Figure out how to use ContextGL's setProgramConstantsFromArray with a Matrix3D - } + public setProgramConstantsFromMatrix(programType: string, firstRegister: number, matrix: Matrix3D, transposedMatrix: boolean = false): void { + //TODO: Figure out how to use ContextGL's setProgramConstantsFromArray with a Matrix3D + } - public setVertexBufferAt(index:number, buffer:VertexBuffer3D, bufferOffset:number = 0, format:String = "float4"):void{ - switch(format) { - case Context3DVertexBufferFormat.BYTES_4: - var awayFormat = ContextGLVertexBufferFormat.BYTE_4 - break; - case Context3DVertexBufferFormat.FLOAT_1: - var awayFormat = ContextGLVertexBufferFormat.FLOAT_1 - break; - case Context3DVertexBufferFormat.FLOAT_2: - var awayFormat = ContextGLVertexBufferFormat.FLOAT_2 - break; - case Context3DVertexBufferFormat.FLOAT_3: - var awayFormat = ContextGLVertexBufferFormat.FLOAT_3 - break; - case Context3DVertexBufferFormat.FLOAT_4: - var awayFormat = ContextGLVertexBufferFormat.FLOAT_4 - break; - } - this._adaptee.context.setVertexBufferAt(index, buffer._adaptee, bufferOffset, awayFormat) - } + public setVertexBufferAt(index: number, buffer: VertexBuffer3D, bufferOffset: number = 0, format: String = 'float4'): void { + switch (format) { + case Context3DVertexBufferFormat.BYTES_4: + var awayFormat = ContextGLVertexBufferFormat.BYTE_4; + break; + case Context3DVertexBufferFormat.FLOAT_1: + var awayFormat = ContextGLVertexBufferFormat.FLOAT_1; + break; + case Context3DVertexBufferFormat.FLOAT_2: + var awayFormat = ContextGLVertexBufferFormat.FLOAT_2; + break; + case Context3DVertexBufferFormat.FLOAT_3: + var awayFormat = ContextGLVertexBufferFormat.FLOAT_3; + break; + case Context3DVertexBufferFormat.FLOAT_4: + var awayFormat = ContextGLVertexBufferFormat.FLOAT_4; + break; + } + this._adaptee.context.setVertexBufferAt(index, buffer._adaptee, bufferOffset, awayFormat); + } } \ No newline at end of file diff --git a/lib/display3D/Context3DProfile.ts b/lib/display3D/Context3DProfile.ts index fa41ddfe..0bf5a4a2 100644 --- a/lib/display3D/Context3DProfile.ts +++ b/lib/display3D/Context3DProfile.ts @@ -1,9 +1,9 @@ export enum Context3DProfile { - BASELINE = "baseline", - BASELINE_CONSTRAINED = "baselineConstrained", - BASELINE_EXTENDED = "baselineExtended", - STANDARD = "standard", - STANDARD_CONSTRAINED = "standardConstrained", - STANDARD_EXTENDED = "standardExtended", + BASELINE = 'baseline', + BASELINE_CONSTRAINED = 'baselineConstrained', + BASELINE_EXTENDED = 'baselineExtended', + STANDARD = 'standard', + STANDARD_CONSTRAINED = 'standardConstrained', + STANDARD_EXTENDED = 'standardExtended', } \ No newline at end of file diff --git a/lib/display3D/Context3DProgramType.ts b/lib/display3D/Context3DProgramType.ts index 26d69ea0..f29eefac 100644 --- a/lib/display3D/Context3DProgramType.ts +++ b/lib/display3D/Context3DProgramType.ts @@ -1,4 +1,4 @@ export enum Context3DProgramType{ - FRAGMENT = "fragment", - VERTEX = "vertex" + FRAGMENT = 'fragment', + VERTEX = 'vertex' } \ No newline at end of file diff --git a/lib/display3D/Context3DRenderMode.ts b/lib/display3D/Context3DRenderMode.ts index b8b1a34f..5b08c5af 100644 --- a/lib/display3D/Context3DRenderMode.ts +++ b/lib/display3D/Context3DRenderMode.ts @@ -1,4 +1,4 @@ export enum Context3DRenderMode{ - AUTO = "auto", - SOFTWARE = "software" + AUTO = 'auto', + SOFTWARE = 'software' } \ No newline at end of file diff --git a/lib/display3D/Context3DVertexBufferFormat.ts b/lib/display3D/Context3DVertexBufferFormat.ts index 963db45d..f1e1112d 100644 --- a/lib/display3D/Context3DVertexBufferFormat.ts +++ b/lib/display3D/Context3DVertexBufferFormat.ts @@ -1,7 +1,7 @@ export enum Context3DVertexBufferFormat{ - BYTES_4 = "bytes4", - FLOAT_1 = "float1", - FLOAT_2 = "float2", - FLOAT_3 = "float3", - FLOAT_4 = "float4" + BYTES_4 = 'bytes4', + FLOAT_1 = 'float1', + FLOAT_2 = 'float2', + FLOAT_3 = 'float3', + FLOAT_4 = 'float4' } \ No newline at end of file diff --git a/lib/display3D/IndexBuffer3D.ts b/lib/display3D/IndexBuffer3D.ts index 1438721b..e6206d41 100644 --- a/lib/display3D/IndexBuffer3D.ts +++ b/lib/display3D/IndexBuffer3D.ts @@ -1,21 +1,21 @@ -import { ASObject } from "@awayfl/avm2"; -import { IContextGL, IIndexBuffer } from "@awayjs/stage"; +import { ASObject } from '@awayfl/avm2'; +import { IContextGL, IIndexBuffer } from '@awayjs/stage'; export class IndexBuffer3D extends ASObject { - static classInitializer = null; + static classInitializer = null; static axClass: typeof IndexBuffer3D; - public _adaptee:IIndexBuffer + public _adaptee: IIndexBuffer - constructor(context: IContextGL, numIndices: number) { - super() - this._adaptee = context.createIndexBuffer(numIndices) - } + constructor(context: IContextGL, numIndices: number) { + super(); + this._adaptee = context.createIndexBuffer(numIndices); + } + + public uploadFromVector(data: Array, startOffset: number, count: number): void { + const uint16ArrayData = new Uint16Array(data); + this._adaptee.uploadFromArray(uint16ArrayData, startOffset, count); + } - public uploadFromVector(data:Array, startOffset:number, count:number):void{ - var uint16ArrayData = new Uint16Array(data) - this._adaptee.uploadFromArray(uint16ArrayData, startOffset, count) - } - } \ No newline at end of file diff --git a/lib/display3D/Program3D.ts b/lib/display3D/Program3D.ts index e88fe771..c5a29039 100644 --- a/lib/display3D/Program3D.ts +++ b/lib/display3D/Program3D.ts @@ -1,27 +1,27 @@ -import { ASObject } from "@awayfl/avm2"; -import { ByteArray as AwayByteArray } from "@awayjs/core"; -import { IContextGL, IProgram } from "@awayjs/stage"; -import { ByteArray } from "../utils/ByteArray"; +import { ASObject } from '@awayfl/avm2'; +import { ByteArray as AwayByteArray } from '@awayjs/core'; +import { IContextGL, IProgram } from '@awayjs/stage'; +import { ByteArray } from '../utils/ByteArray'; export class Program3D extends ASObject { - static classInitializer = null; + static classInitializer = null; static axClass: typeof Program3D; - public _adaptee:IProgram + public _adaptee: IProgram - constructor(context:IContextGL){ - super() - this._adaptee = context.createProgram() + constructor(context: IContextGL) { + super(); + this._adaptee = context.createProgram(); - } + } - public dispose(){ - this._adaptee.dispose() - } + public dispose() { + this._adaptee.dispose(); + } - public upload(vertexProgram:ByteArray, fragmentProgram:ByteArray):void { - AwayByteArray - this._adaptee.upload(vertexProgram, fragmentProgram) - } + public upload(vertexProgram: ByteArray, fragmentProgram: ByteArray): void { + AwayByteArray; + this._adaptee.upload(vertexProgram, fragmentProgram); + } } \ No newline at end of file diff --git a/lib/display3D/VertexBuffer3D.ts b/lib/display3D/VertexBuffer3D.ts index d2806453..98feb028 100644 --- a/lib/display3D/VertexBuffer3D.ts +++ b/lib/display3D/VertexBuffer3D.ts @@ -1,20 +1,20 @@ -import { ASObject } from "@awayfl/avm2"; -import { IContextGL, IVertexBuffer, VertexBufferWebGL } from "@awayjs/stage"; +import { ASObject } from '@awayfl/avm2'; +import { IContextGL, IVertexBuffer, VertexBufferWebGL } from '@awayjs/stage'; export class VertexBuffer3D extends ASObject { - public _adaptee:IVertexBuffer + public _adaptee: IVertexBuffer - static classInitializer = null; + static classInitializer = null; static axClass: typeof VertexBuffer3D; - - constructor(context:IContextGL, numVertices, dataPerVertex) { - super() - this._adaptee = context.createVertexBuffer(numVertices, dataPerVertex) - } - public uploadFromVector(data:Array, startVertex:number, numVertices){ - var dataFloat32Array:Float32Array = new Float32Array(data) - this._adaptee.uploadFromArray(dataFloat32Array, startVertex, numVertices) - } + constructor(context: IContextGL, numVertices, dataPerVertex) { + super(); + this._adaptee = context.createVertexBuffer(numVertices, dataPerVertex); + } + + public uploadFromVector(data: Array, startVertex: number, numVertices) { + const dataFloat32Array: Float32Array = new Float32Array(data); + this._adaptee.uploadFromArray(dataFloat32Array, startVertex, numVertices); + } } \ No newline at end of file From ba3919914f9dd00235d593fa89a7bb59dce621a1 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 10 Sep 2024 20:05:32 +0000 Subject: [PATCH 07/59] Fix requested Context Profile and Minor Fixes --- lib/display/Stage3D.ts | 6 ++++-- lib/display3D/Context3D.ts | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/display/Stage3D.ts b/lib/display/Stage3D.ts index 32333e87..91849439 100644 --- a/lib/display/Stage3D.ts +++ b/lib/display/Stage3D.ts @@ -37,10 +37,10 @@ export class Stage3D extends EventDispatcher { this._adaptee.requestContext(forceSoftware, ContextGLProfile.BASELINE); break; case Context3DProfile.BASELINE_CONSTRAINED: - this._adaptee.requestContext(forceSoftware, ContextGLProfile.BASELINE); + this._adaptee.requestContext(forceSoftware, ContextGLProfile.BASELINE_CONSTRAINED); break; case Context3DProfile.BASELINE_EXTENDED: - this._adaptee.requestContext(forceSoftware, ContextGLProfile.BASELINE); + this._adaptee.requestContext(forceSoftware, ContextGLProfile.BASELINE_EXTENDED); break; case Context3DProfile.STANDARD: console.log('Unsupported Context3D Profile \'standard\' Requested'); @@ -51,6 +51,8 @@ export class Stage3D extends EventDispatcher { case Context3DProfile.STANDARD_EXTENDED: console.log('Unsupported Context3D Profile \'standard_extended\' Requested'); break; + default: + break; } super.dispatchEvent(new Event(Event.CONTEXT3D_CREATE)); diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index c8a09bbf..e16c7be7 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -77,6 +77,8 @@ export class Context3D extends EventDispatcher { case Context3DVertexBufferFormat.FLOAT_4: var awayFormat = ContextGLVertexBufferFormat.FLOAT_4; break; + default: + break; } this._adaptee.context.setVertexBufferAt(index, buffer._adaptee, bufferOffset, awayFormat); } From fbaa7226287c50f0e331f0795b83563b2dad7aae Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 10 Sep 2024 22:07:39 +0000 Subject: [PATCH 08/59] Comit current work --- lib/display3D/Context3D.ts | 32 +++++++++++++++++++++++++------- lib/display3D/IndexBuffer3D.ts | 9 ++++++--- lib/display3D/VertexBuffer3D.ts | 9 ++++++--- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index e16c7be7..9218fa48 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -1,5 +1,6 @@ -import { ContextGLDrawMode, ContextGLVertexBufferFormat, Stage as AwayStage, StageEvent } from '@awayjs/stage'; +import { ContextGLDrawMode, ContextGLProgramType, ContextGLVertexBufferFormat, ContextWebGL, ProgramWebGL, Stage as AwayStage, StageEvent } from '@awayjs/stage'; import { EventDispatcher } from '../events/EventDispatcher'; +import { Context3DProgramType } from '../display3D/Context3DProgramType'; import { Context3DVertexBufferFormat } from '../display3D/Context3DVertexBufferFormat'; import { IndexBuffer3D } from '../display3D/IndexBuffer3D'; import { VertexBuffer3D } from '../display3D/VertexBuffer3D'; @@ -8,16 +9,19 @@ import { Matrix3D } from '../geom/Matrix3D'; export class Context3D extends EventDispatcher { private _adaptee: AwayStage + private _gl: WebGLRenderingContext | WebGL2RenderingContext + private _program:Program3D constructor(awayStage: AwayStage, profile) { super(); - awayStage.addEventListener(StageEvent.CONTEXT_CREATED, - function() { - this._adaptee = awayStage; - } - ); + awayStage.addEventListener(StageEvent.CONTEXT_CREATED, this.onAwayContextCreated); } + private onAwayContextCreated(e: StageEvent) { + this._adaptee = e.target; + this._gl = (this._adaptee.context as ContextWebGL)._gl; + } + public clear(red: number = 0.0, green: number = 0.0, blue: number = 0.0, alpha: number = 1.0, depth: number = 1.0, stencil: number = 0, mask: number = 0xffffffff): void { console.log('Mask: ' + mask); this._adaptee.clear(red, green, blue, alpha, depth, stencil, mask); @@ -53,11 +57,25 @@ export class Context3D extends EventDispatcher { } public setProgram(program: Program3D): void { + this._program = program; this._adaptee.context.setProgram(program._adaptee); } public setProgramConstantsFromMatrix(programType: string, firstRegister: number, matrix: Matrix3D, transposedMatrix: boolean = false): void { - //TODO: Figure out how to use ContextGL's setProgramConstantsFromArray with a Matrix3D + switch(programType){ + case Context3DProgramType.FRAGMENT: + var awayProgramType = ContextGLProgramType.FRAGMENT; + break; + case Context3DProgramType.VERTEX: + var awayProgramType = ContextGLProgramType.VERTEX; + break; + default: + break; + } + var programWebGL:ProgramWebGL = this._program._adaptee as ProgramWebGL; + var matrixRawData:Float32Array + matrix.adaptee.copyRawDataTo(matrixRawData, 0, false) + programWebGL.uniformMatrix4fv(awayProgramType, transposedMatrix, matrixRawData) } public setVertexBufferAt(index: number, buffer: VertexBuffer3D, bufferOffset: number = 0, format: String = 'float4'): void { diff --git a/lib/display3D/IndexBuffer3D.ts b/lib/display3D/IndexBuffer3D.ts index e6206d41..8a3c148b 100644 --- a/lib/display3D/IndexBuffer3D.ts +++ b/lib/display3D/IndexBuffer3D.ts @@ -1,4 +1,4 @@ -import { ASObject } from '@awayfl/avm2'; +import { ASObject, Uint32Vector } from '@awayfl/avm2'; import { IContextGL, IIndexBuffer } from '@awayjs/stage'; export class IndexBuffer3D extends ASObject { @@ -13,8 +13,11 @@ export class IndexBuffer3D extends ASObject { this._adaptee = context.createIndexBuffer(numIndices); } - public uploadFromVector(data: Array, startOffset: number, count: number): void { - const uint16ArrayData = new Uint16Array(data); + public uploadFromVector(data: Uint32Vector, startOffset: number, count: number): void { + const uint16ArrayData = new Uint16Array(data.length); + for(var i:number = 0; i < data.length; i++) { + data[i] = uint16ArrayData[i]; + } this._adaptee.uploadFromArray(uint16ArrayData, startOffset, count); } diff --git a/lib/display3D/VertexBuffer3D.ts b/lib/display3D/VertexBuffer3D.ts index 98feb028..3ccfa569 100644 --- a/lib/display3D/VertexBuffer3D.ts +++ b/lib/display3D/VertexBuffer3D.ts @@ -1,4 +1,4 @@ -import { ASObject } from '@awayfl/avm2'; +import { ASObject, Float64Vector } from '@awayfl/avm2'; import { IContextGL, IVertexBuffer, VertexBufferWebGL } from '@awayjs/stage'; export class VertexBuffer3D extends ASObject { @@ -13,8 +13,11 @@ export class VertexBuffer3D extends ASObject { this._adaptee = context.createVertexBuffer(numVertices, dataPerVertex); } - public uploadFromVector(data: Array, startVertex: number, numVertices) { - const dataFloat32Array: Float32Array = new Float32Array(data); + public uploadFromVector(data: Float64Vector, startVertex: number, numVertices) { + const dataFloat32Array: Float32Array = new Float32Array(data.length); + for(var i:number = 0; i < data.length; i++) { + data[i] = dataFloat32Array[i]; + } this._adaptee.uploadFromArray(dataFloat32Array, startVertex, numVertices); } } \ No newline at end of file From e617231e2ec364f66cfdfec4080cda784499e325 Mon Sep 17 00:00:00 2001 From: Fancy2209 <64917206+Fancy2209@users.noreply.github.com> Date: Wed, 11 Sep 2024 11:45:37 +0000 Subject: [PATCH 09/59] Update Stage.ts --- lib/display/Stage.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/display/Stage.ts b/lib/display/Stage.ts index 02636672..427e601d 100644 --- a/lib/display/Stage.ts +++ b/lib/display/Stage.ts @@ -163,7 +163,7 @@ export class Stage extends DisplayObjectContainer { this._isStage = true; this._stage3Ds = []; - for (let i: number = 0; i < 8; i++) { + for (let i: number = 0; i < StageManager.getInstance().numSlotsFree; i++) { this.stage3Ds.push(new Stage3D); } @@ -1146,4 +1146,4 @@ export class Stage extends DisplayObjectContainer { return false; } -} \ No newline at end of file +} From 8b681deb3f28f3d37a78db0209697c498d615b70 Mon Sep 17 00:00:00 2001 From: Fancy2209 <64917206+Fancy2209@users.noreply.github.com> Date: Wed, 11 Sep 2024 15:56:16 +0000 Subject: [PATCH 10/59] Commit work --- lib/display/Stage3D.ts | 5 ++++- lib/display3D/Context3D.ts | 10 ++++++++-- lib/display3D/Context3DClearMask.ts | 25 ++++++++++++++++++++++++- lib/display3D/IndexBuffer3D.ts | 7 ++++--- lib/display3D/Program3D.ts | 7 ++++--- 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/lib/display/Stage3D.ts b/lib/display/Stage3D.ts index 91849439..e475db53 100644 --- a/lib/display/Stage3D.ts +++ b/lib/display/Stage3D.ts @@ -55,6 +55,9 @@ export class Stage3D extends EventDispatcher { break; } - super.dispatchEvent(new Event(Event.CONTEXT3D_CREATE)); + } + + public dispatchEvent(event):boolean { + return super.dispatchEvent(event); } } \ No newline at end of file diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index 9218fa48..37f17758 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -8,18 +8,24 @@ import { Program3D } from '../display3D/Program3D'; import { Matrix3D } from '../geom/Matrix3D'; export class Context3D extends EventDispatcher { + + static classInitializer: any = null; + static classSymbols: string [] = null; // []; + static instanceSymbols: string [] = null; + private _adaptee: AwayStage private _gl: WebGLRenderingContext | WebGL2RenderingContext private _program:Program3D constructor(awayStage: AwayStage, profile) { super(); - awayStage.addEventListener(StageEvent.CONTEXT_CREATED, this.onAwayContextCreated); + awayStage.addEventListener(StageEvent.CONTEXT_RECREATED, this.onAwayContextCreated); } private onAwayContextCreated(e: StageEvent) { - this._adaptee = e.target; + this._adaptee = e.stage; this._gl = (this._adaptee.context as ContextWebGL)._gl; + this._adaptee.dispatchEvent(new Event(Event.CONTEXT3D_CREATE)); } public clear(red: number = 0.0, green: number = 0.0, blue: number = 0.0, alpha: number = 1.0, depth: number = 1.0, stencil: number = 0, mask: number = 0xffffffff): void { diff --git a/lib/display3D/Context3DClearMask.ts b/lib/display3D/Context3DClearMask.ts index 73d8f6f3..ca91566b 100644 --- a/lib/display3D/Context3DClearMask.ts +++ b/lib/display3D/Context3DClearMask.ts @@ -1 +1,24 @@ -export { ContextGLClearMask as Context3DClearMask } from '@awayjs/stage'; +import { ASObject } from "@awayfl/avm2"; + +// Based on https://github.com/ruffle-rs/ruffle/blob/master/core/src/avm2/globals/flash/display3D/Context3DClearMask.as +export class Context3DClearMask extends ASObject { + static classInitializer: any = null; + static classSymbols = null; // []; + static instanceSymbols = null; + + // Clear all buffers. + public static ALL:number = Context3DClearMask.COLOR | Context3DClearMask.DEPTH | Context3DClearMask.STENCIL; + + // Clear only the color buffer. + public static COLOR:number = 1 << 0; + + // Clear only the depth buffer. + public static DEPTH:number = 1 << 1; + + // Clear only the stencil buffer. + public static STENCIL:number = 1 << 2; + + constructor() { + super(); + } +} \ No newline at end of file diff --git a/lib/display3D/IndexBuffer3D.ts b/lib/display3D/IndexBuffer3D.ts index 8a3c148b..ad8d4ff1 100644 --- a/lib/display3D/IndexBuffer3D.ts +++ b/lib/display3D/IndexBuffer3D.ts @@ -2,9 +2,10 @@ import { ASObject, Uint32Vector } from '@awayfl/avm2'; import { IContextGL, IIndexBuffer } from '@awayjs/stage'; export class IndexBuffer3D extends ASObject { - static classInitializer = null; - - static axClass: typeof IndexBuffer3D; + + static classInitializer: any = null; + static classSymbols: string [] = null; // []; + static instanceSymbols: string [] = null; public _adaptee: IIndexBuffer diff --git a/lib/display3D/Program3D.ts b/lib/display3D/Program3D.ts index c5a29039..f7f85a2e 100644 --- a/lib/display3D/Program3D.ts +++ b/lib/display3D/Program3D.ts @@ -4,9 +4,10 @@ import { IContextGL, IProgram } from '@awayjs/stage'; import { ByteArray } from '../utils/ByteArray'; export class Program3D extends ASObject { - static classInitializer = null; - - static axClass: typeof Program3D; + + static classInitializer: any = null; + static classSymbols: string [] = null; // []; + static instanceSymbols: string [] = null; public _adaptee: IProgram From d7dd603740287a50b308553f1d004ee0c96286c3 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Wed, 11 Sep 2024 17:03:09 +0000 Subject: [PATCH 11/59] Commit Work --- lib/SecurityDomain.ts | 9 +++- lib/display/Stage.ts | 1 + lib/display/Stage3D.ts | 11 ++-- lib/display3D/Context3D.ts | 54 +++++++++----------- lib/display3D/Context3DClearMask.ts | 27 ++++------ lib/display3D/Context3DProfile.ts | 15 +++--- lib/display3D/Context3DProgramType.ts | 6 +-- lib/display3D/Context3DRenderMode.ts | 6 +-- lib/display3D/Context3DVertexBufferFormat.ts | 12 ++--- lib/display3D/IndexBuffer3D.ts | 6 +-- lib/display3D/Program3D.ts | 2 +- lib/display3D/VertexBuffer3D.ts | 10 ++-- lib/link.ts | 19 +++++++ 13 files changed, 89 insertions(+), 89 deletions(-) diff --git a/lib/SecurityDomain.ts b/lib/SecurityDomain.ts index 2ff09751..7a7a6ee5 100644 --- a/lib/SecurityDomain.ts +++ b/lib/SecurityDomain.ts @@ -78,6 +78,10 @@ import { FocusEvent } from './events/FocusEvent'; import { UncaughtErrorEvents } from './events/UncaughtErrorEvents'; import { NetConnection } from './net/NetConnection'; import { Responder } from './net/Responder'; +import { Context3D } from './display3D/Context3D'; +import { IndexBuffer3D } from './display3D/IndexBuffer3D'; +import { Program3D } from './display3D/Program3D'; +import { VertexBuffer3D } from './display3D/VertexBuffer3D'; export class Mouse {} @@ -101,7 +105,10 @@ export class SecurityDomain extends AXSecurityDomain { FrameLabel: FrameLabel }, display3d: { - // TODO: Add display3d stuff + Context3D: Context3D, + IndexBuffer3D: IndexBuffer3D, + Program3D: Program3D, + VertexBuffer3D: VertexBuffer3D }, events: { EventDispatcher: EventDispatcher, diff --git a/lib/display/Stage.ts b/lib/display/Stage.ts index 427e601d..97582233 100644 --- a/lib/display/Stage.ts +++ b/lib/display/Stage.ts @@ -16,6 +16,7 @@ import { Loader as PlayerGlobalLoader } from './Loader'; import { LoaderInfo, LoaderInfoCompleteQueue } from './LoaderInfo'; import { Debug } from '@awayjs/core'; import { InteractiveObject } from './InteractiveObject'; +import { StageManager } from '@awayjs/stage'; /** * Dispatched by the Stage object when the state of the stageVideos property changes. diff --git a/lib/display/Stage3D.ts b/lib/display/Stage3D.ts index e475db53..5544ece4 100644 --- a/lib/display/Stage3D.ts +++ b/lib/display/Stage3D.ts @@ -17,9 +17,6 @@ export class Stage3D extends EventDispatcher { constructor() { super(); - console.log('numSlotsTotal: ' + StageManager.getInstance().numSlotsTotal); - console.log('numSlotsUsed: ' + StageManager.getInstance().numSlotsUsed); - console.log('numSlotsFree: ' + StageManager.getInstance().numSlotsFree); this._adapteeStage3Ds[this._adapteeStage3Ds.length] = StageManager.getInstance().getFreeStage(); console.log('Created Stage3D ' + (this._adapteeStage3Ds.length - 1)); @@ -51,13 +48,11 @@ export class Stage3D extends EventDispatcher { case Context3DProfile.STANDARD_EXTENDED: console.log('Unsupported Context3D Profile \'standard_extended\' Requested'); break; - default: - break; + default: + break; } - } - public dispatchEvent(event):boolean { - return super.dispatchEvent(event); + this.dispatchEvent(new Event(Event.CONTEXT3D_CREATE)); } } \ No newline at end of file diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index 37f17758..86f010c4 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -9,24 +9,20 @@ import { Matrix3D } from '../geom/Matrix3D'; export class Context3D extends EventDispatcher { - static classInitializer: any = null; - static classSymbols: string [] = null; // []; - static instanceSymbols: string [] = null; - private _adaptee: AwayStage - private _gl: WebGLRenderingContext | WebGL2RenderingContext - private _program:Program3D + private _gl: WebGLRenderingContext | WebGL2RenderingContext + private _program: Program3D constructor(awayStage: AwayStage, profile) { super(); - awayStage.addEventListener(StageEvent.CONTEXT_RECREATED, this.onAwayContextCreated); + awayStage.addEventListener(StageEvent.CONTEXT_CREATED, this.onAwayContextCreated); } - private onAwayContextCreated(e: StageEvent) { - this._adaptee = e.stage; - this._gl = (this._adaptee.context as ContextWebGL)._gl; - this._adaptee.dispatchEvent(new Event(Event.CONTEXT3D_CREATE)); - } + private onAwayContextCreated(e: StageEvent) { + this._adaptee = e.stage; + e.target; + this._gl = (this._adaptee.context as ContextWebGL)._gl; + } public clear(red: number = 0.0, green: number = 0.0, blue: number = 0.0, alpha: number = 1.0, depth: number = 1.0, stencil: number = 0, mask: number = 0xffffffff): void { console.log('Mask: ' + mask); @@ -63,25 +59,25 @@ export class Context3D extends EventDispatcher { } public setProgram(program: Program3D): void { - this._program = program; + this._program = program; this._adaptee.context.setProgram(program._adaptee); } public setProgramConstantsFromMatrix(programType: string, firstRegister: number, matrix: Matrix3D, transposedMatrix: boolean = false): void { - switch(programType){ - case Context3DProgramType.FRAGMENT: - var awayProgramType = ContextGLProgramType.FRAGMENT; - break; - case Context3DProgramType.VERTEX: - var awayProgramType = ContextGLProgramType.VERTEX; - break; - default: - break; - } - var programWebGL:ProgramWebGL = this._program._adaptee as ProgramWebGL; - var matrixRawData:Float32Array - matrix.adaptee.copyRawDataTo(matrixRawData, 0, false) - programWebGL.uniformMatrix4fv(awayProgramType, transposedMatrix, matrixRawData) + switch (programType) { + case Context3DProgramType.FRAGMENT: + var awayProgramType = ContextGLProgramType.FRAGMENT; + break; + case Context3DProgramType.VERTEX: + var awayProgramType = ContextGLProgramType.VERTEX; + break; + default: + break; + } + const programWebGL: ProgramWebGL = this._program._adaptee as ProgramWebGL; + let matrixRawData: Float32Array; + matrix.adaptee.copyRawDataTo(matrixRawData, 0, false); + programWebGL.uniformMatrix4fv(awayProgramType, transposedMatrix, matrixRawData); } public setVertexBufferAt(index: number, buffer: VertexBuffer3D, bufferOffset: number = 0, format: String = 'float4'): void { @@ -101,8 +97,8 @@ export class Context3D extends EventDispatcher { case Context3DVertexBufferFormat.FLOAT_4: var awayFormat = ContextGLVertexBufferFormat.FLOAT_4; break; - default: - break; + default: + break; } this._adaptee.context.setVertexBufferAt(index, buffer._adaptee, bufferOffset, awayFormat); } diff --git a/lib/display3D/Context3DClearMask.ts b/lib/display3D/Context3DClearMask.ts index ca91566b..c78a2320 100644 --- a/lib/display3D/Context3DClearMask.ts +++ b/lib/display3D/Context3DClearMask.ts @@ -1,24 +1,15 @@ -import { ASObject } from "@awayfl/avm2"; - // Based on https://github.com/ruffle-rs/ruffle/blob/master/core/src/avm2/globals/flash/display3D/Context3DClearMask.as -export class Context3DClearMask extends ASObject { - static classInitializer: any = null; - static classSymbols = null; // []; - static instanceSymbols = null; - - // Clear all buffers. - public static ALL:number = Context3DClearMask.COLOR | Context3DClearMask.DEPTH | Context3DClearMask.STENCIL; +export class Context3DClearMask { - // Clear only the color buffer. - public static COLOR:number = 1 << 0; + // Clear only the color buffer. + public static COLOR: number = 1 << 0; - // Clear only the depth buffer. - public static DEPTH:number = 1 << 1; + // Clear only the depth buffer. + public static DEPTH: number = 1 << 1; - // Clear only the stencil buffer. - public static STENCIL:number = 1 << 2; + // Clear only the stencil buffer. + public static STENCIL: number = 1 << 2; - constructor() { - super(); - } + // Clear all buffers. + public static ALL: number = Context3DClearMask.COLOR | Context3DClearMask.DEPTH | Context3DClearMask.STENCIL; } \ No newline at end of file diff --git a/lib/display3D/Context3DProfile.ts b/lib/display3D/Context3DProfile.ts index 0bf5a4a2..ce09c93d 100644 --- a/lib/display3D/Context3DProfile.ts +++ b/lib/display3D/Context3DProfile.ts @@ -1,9 +1,8 @@ -export enum Context3DProfile { - BASELINE = 'baseline', - BASELINE_CONSTRAINED = 'baselineConstrained', - BASELINE_EXTENDED = 'baselineExtended', - STANDARD = 'standard', - STANDARD_CONSTRAINED = 'standardConstrained', - STANDARD_EXTENDED = 'standardExtended', - +export class Context3DProfile { + public static BASELINE: string = 'baseline'; + public static BASELINE_CONSTRAINED: string = 'baselineConstrained'; + public static BASELINE_EXTENDED: string = 'baselineExtended'; + public static STANDARD: string = 'standard'; + public static STANDARD_CONSTRAINED: string = 'standardConstrained'; + public static STANDARD_EXTENDED: string = 'standardExtended'; } \ No newline at end of file diff --git a/lib/display3D/Context3DProgramType.ts b/lib/display3D/Context3DProgramType.ts index f29eefac..74067626 100644 --- a/lib/display3D/Context3DProgramType.ts +++ b/lib/display3D/Context3DProgramType.ts @@ -1,4 +1,4 @@ -export enum Context3DProgramType{ - FRAGMENT = 'fragment', - VERTEX = 'vertex' +export class Context3DProgramType { + public static FRAGMENT: string = 'fragment'; + public static VERTEX = 'vertex'; } \ No newline at end of file diff --git a/lib/display3D/Context3DRenderMode.ts b/lib/display3D/Context3DRenderMode.ts index 5b08c5af..364f974b 100644 --- a/lib/display3D/Context3DRenderMode.ts +++ b/lib/display3D/Context3DRenderMode.ts @@ -1,4 +1,4 @@ -export enum Context3DRenderMode{ - AUTO = 'auto', - SOFTWARE = 'software' +export class Context3DRenderMode { + public static AUTO: string = 'auto'; + public static SOFTWARE: string = 'software'; } \ No newline at end of file diff --git a/lib/display3D/Context3DVertexBufferFormat.ts b/lib/display3D/Context3DVertexBufferFormat.ts index f1e1112d..cd53ef93 100644 --- a/lib/display3D/Context3DVertexBufferFormat.ts +++ b/lib/display3D/Context3DVertexBufferFormat.ts @@ -1,7 +1,7 @@ -export enum Context3DVertexBufferFormat{ - BYTES_4 = 'bytes4', - FLOAT_1 = 'float1', - FLOAT_2 = 'float2', - FLOAT_3 = 'float3', - FLOAT_4 = 'float4' +export class Context3DVertexBufferFormat { + public static BYTES_4: string = 'bytes4'; + public static FLOAT_1: string = 'float1'; + public static FLOAT_2: string = 'float2'; + public static FLOAT_3: string = 'float3'; + public static FLOAT_4: string = 'float4'; } \ No newline at end of file diff --git a/lib/display3D/IndexBuffer3D.ts b/lib/display3D/IndexBuffer3D.ts index ad8d4ff1..7e1b9fd8 100644 --- a/lib/display3D/IndexBuffer3D.ts +++ b/lib/display3D/IndexBuffer3D.ts @@ -2,10 +2,6 @@ import { ASObject, Uint32Vector } from '@awayfl/avm2'; import { IContextGL, IIndexBuffer } from '@awayjs/stage'; export class IndexBuffer3D extends ASObject { - - static classInitializer: any = null; - static classSymbols: string [] = null; // []; - static instanceSymbols: string [] = null; public _adaptee: IIndexBuffer @@ -16,7 +12,7 @@ export class IndexBuffer3D extends ASObject { public uploadFromVector(data: Uint32Vector, startOffset: number, count: number): void { const uint16ArrayData = new Uint16Array(data.length); - for(var i:number = 0; i < data.length; i++) { + for (let i: number = 0; i < data.length; i++) { data[i] = uint16ArrayData[i]; } this._adaptee.uploadFromArray(uint16ArrayData, startOffset, count); diff --git a/lib/display3D/Program3D.ts b/lib/display3D/Program3D.ts index f7f85a2e..8096f327 100644 --- a/lib/display3D/Program3D.ts +++ b/lib/display3D/Program3D.ts @@ -4,7 +4,7 @@ import { IContextGL, IProgram } from '@awayjs/stage'; import { ByteArray } from '../utils/ByteArray'; export class Program3D extends ASObject { - + static classInitializer: any = null; static classSymbols: string [] = null; // []; static instanceSymbols: string [] = null; diff --git a/lib/display3D/VertexBuffer3D.ts b/lib/display3D/VertexBuffer3D.ts index 3ccfa569..b7c80724 100644 --- a/lib/display3D/VertexBuffer3D.ts +++ b/lib/display3D/VertexBuffer3D.ts @@ -4,10 +4,6 @@ import { IContextGL, IVertexBuffer, VertexBufferWebGL } from '@awayjs/stage'; export class VertexBuffer3D extends ASObject { public _adaptee: IVertexBuffer - static classInitializer = null; - - static axClass: typeof VertexBuffer3D; - constructor(context: IContextGL, numVertices, dataPerVertex) { super(); this._adaptee = context.createVertexBuffer(numVertices, dataPerVertex); @@ -15,9 +11,9 @@ export class VertexBuffer3D extends ASObject { public uploadFromVector(data: Float64Vector, startVertex: number, numVertices) { const dataFloat32Array: Float32Array = new Float32Array(data.length); - for(var i:number = 0; i < data.length; i++) { - data[i] = dataFloat32Array[i]; - } + for (let i: number = 0; i < data.length; i++) { + data[i] = dataFloat32Array[i]; + } this._adaptee.uploadFromArray(dataFloat32Array, startVertex, numVertices); } } \ No newline at end of file diff --git a/lib/link.ts b/lib/link.ts index bcb0d7aa..5781db54 100644 --- a/lib/link.ts +++ b/lib/link.ts @@ -27,6 +27,16 @@ import { Sprite } from './display/Sprite'; import { Stage } from './display/Stage'; import { Stage3D } from './display/Stage3D'; +import { Context3D } from './display3D/Context3D'; +import { Context3DClearMask } from './display3D/Context3DClearMask'; +import { Context3DProfile } from './display3D/Context3DProfile'; +import { Context3DProgramType } from './display3D/Context3DProgramType'; +import { Context3DRenderMode } from './display3D/Context3DRenderMode'; +import { Context3DVertexBufferFormat } from './display3D/Context3DVertexBufferFormat'; +import { IndexBuffer3D } from './display3D/IndexBuffer3D'; +import { Program3D } from './display3D/Program3D'; +import { VertexBuffer3D } from './display3D/VertexBuffer3D'; + import { EOFError } from './errors/EOFError'; import { IllegalOperationError } from './errors/IllegalOperationError'; import { InvalidSWFError } from './errors/InvalidSWFError'; @@ -296,6 +306,15 @@ export function initLink() { //M('flash.display.TriangleCulling', TriangleCulling); // TODO: Add display3d stuff + M('flash.display3D.Context3D', Context3D); + M('flash.display3D.Context3DClearMask', Context3DClearMask); + M('flash.display3D.Context3DProfile', Context3DProfile); + M('flash.display3D.Context3DProgramType', Context3DProgramType); + M('flash.display3D.Context3DRenderMode', Context3DRenderMode); + M('flash.display3D.Context3DVertexBufferFormat', Context3DVertexBufferFormat); + M('flash.display3D.IndexBuffer3D', IndexBuffer3D); + M('flash.display3D.Program3D', Program3D); + M('flash.display3D.VertexBuffer3D', VertexBuffer3D); //M('flash.errors.DRMManagerError', DRMManagerError);//AIR M('flash.errors.EOFError', EOFError); From f12e88dc1bac4e20d29c721142afcfd35e0845dc Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Wed, 11 Sep 2024 20:56:46 +0000 Subject: [PATCH 12/59] Commit work --- lib/display/Stage.ts | 15 +++++++++------ lib/display/Stage3D.ts | 5 +---- lib/display3D/Context3D.ts | 12 +++++++++--- lib/display3D/IndexBuffer3D.ts | 3 +++ lib/display3D/Program3D.ts | 1 - lib/display3D/VertexBuffer3D.ts | 10 +++++++--- lib/link.ts | 2 ++ 7 files changed, 31 insertions(+), 17 deletions(-) diff --git a/lib/display/Stage.ts b/lib/display/Stage.ts index 97582233..812c77bb 100644 --- a/lib/display/Stage.ts +++ b/lib/display/Stage.ts @@ -17,6 +17,7 @@ import { LoaderInfo, LoaderInfoCompleteQueue } from './LoaderInfo'; import { Debug } from '@awayjs/core'; import { InteractiveObject } from './InteractiveObject'; import { StageManager } from '@awayjs/stage'; +import { GenericVector } from '@awayfl/avm2'; /** * Dispatched by the Stage object when the state of the stageVideos property changes. @@ -154,7 +155,7 @@ import { StageManager } from '@awayjs/stage'; export class Stage extends DisplayObjectContainer { - private _stage3Ds: Stage3D[]; + private _stage3Ds: GenericVector; private _sendEventRender: boolean; @@ -163,10 +164,7 @@ export class Stage extends DisplayObjectContainer { this._isStage = true; - this._stage3Ds = []; - for (let i: number = 0; i < StageManager.getInstance().numSlotsFree; i++) { - this.stage3Ds.push(new Stage3D); - } + this._stage3Ds = new ( this.sec).ObjectVector(StageManager.getInstance().numSlotsFree, true); // resize event listens on window this._resizeCallbackDelegate = (event: any) => this.resizeCallback(event); @@ -191,6 +189,11 @@ export class Stage extends DisplayObjectContainer { ( this.sec).flash.display.DisplayObject.axClass._activeStage = this; this._stage = this; + for (let i: number = 0; i < StageManager.getInstance().numSlotsFree; i++) { + this._stage3Ds.axSetNumericProperty(i, new ( this.sec).flash.display.Stage3D()); + //this.stage3Ds[i] = new Stage3D; + } + this._resizeCallbackDelegate(null); } @@ -812,7 +815,7 @@ export class Stage extends DisplayObjectContainer { } - public get stage3Ds (): Stage3D[] { + public get stage3Ds (): GenericVector { // @todo Debug.throwPIR('playerglobals/display/Stage', 'get stage3Ds', ''); return this._stage3Ds; diff --git a/lib/display/Stage3D.ts b/lib/display/Stage3D.ts index 5544ece4..2fba4459 100644 --- a/lib/display/Stage3D.ts +++ b/lib/display/Stage3D.ts @@ -1,7 +1,6 @@ import { ContextGLProfile, ContextMode, Stage as AwayStage, Stage, StageManager } from '@awayjs/stage'; import { EventDispatcher } from '../events/EventDispatcher'; import { Context3D } from '../display3D/Context3D'; -import { Event } from '../events/Event'; import { Context3DProfile } from '../display3D/Context3DProfile'; import { AVMStage } from '@awayfl/swf-loader'; @@ -27,7 +26,7 @@ export class Stage3D extends EventDispatcher { } public requestContext3D(context3DRenderMode: String = 'auto', profile: String = 'baseline'): void { - this._context3D = new Context3D(this._adaptee, profile); + this._context3D = new Context3D(this, this._adaptee, profile); const forceSoftware: boolean = (context3DRenderMode == 'auto'); switch (profile) { case Context3DProfile.BASELINE: @@ -52,7 +51,5 @@ export class Stage3D extends EventDispatcher { break; } - - this.dispatchEvent(new Event(Event.CONTEXT3D_CREATE)); } } \ No newline at end of file diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index 86f010c4..d91a4a23 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -6,22 +6,28 @@ import { IndexBuffer3D } from '../display3D/IndexBuffer3D'; import { VertexBuffer3D } from '../display3D/VertexBuffer3D'; import { Program3D } from '../display3D/Program3D'; import { Matrix3D } from '../geom/Matrix3D'; +import { Stage3D } from '../display/Stage3D'; +import { Event } from '../events/Event'; +import { SecurityDomain } from '../SecurityDomain'; export class Context3D extends EventDispatcher { - private _adaptee: AwayStage private _gl: WebGLRenderingContext | WebGL2RenderingContext private _program: Program3D + private _stage3D: Stage3D - constructor(awayStage: AwayStage, profile) { + constructor(stage3D: Stage3D, awayStage: AwayStage, profile) { super(); awayStage.addEventListener(StageEvent.CONTEXT_CREATED, this.onAwayContextCreated); + this._stage3D = stage3D } private onAwayContextCreated(e: StageEvent) { this._adaptee = e.stage; - e.target; + this._adaptee.removeEventListener(StageEvent.CONTEXT_CREATED, this.onAwayContextCreated); this._gl = (this._adaptee.context as ContextWebGL)._gl; + this._stage3D.dispatchEvent(new ( this.sec).flash.events.Event(Event.CONTEXT3D_CREATE)) + } public clear(red: number = 0.0, green: number = 0.0, blue: number = 0.0, alpha: number = 1.0, depth: number = 1.0, stencil: number = 0, mask: number = 0xffffffff): void { diff --git a/lib/display3D/IndexBuffer3D.ts b/lib/display3D/IndexBuffer3D.ts index 7e1b9fd8..7bb2e82a 100644 --- a/lib/display3D/IndexBuffer3D.ts +++ b/lib/display3D/IndexBuffer3D.ts @@ -2,6 +2,9 @@ import { ASObject, Uint32Vector } from '@awayfl/avm2'; import { IContextGL, IIndexBuffer } from '@awayjs/stage'; export class IndexBuffer3D extends ASObject { + static classInitializer: any = null; + static classSymbols: string [] = null; // []; + static instanceSymbols: string [] = null; public _adaptee: IIndexBuffer diff --git a/lib/display3D/Program3D.ts b/lib/display3D/Program3D.ts index 8096f327..035b8ac1 100644 --- a/lib/display3D/Program3D.ts +++ b/lib/display3D/Program3D.ts @@ -4,7 +4,6 @@ import { IContextGL, IProgram } from '@awayjs/stage'; import { ByteArray } from '../utils/ByteArray'; export class Program3D extends ASObject { - static classInitializer: any = null; static classSymbols: string [] = null; // []; static instanceSymbols: string [] = null; diff --git a/lib/display3D/VertexBuffer3D.ts b/lib/display3D/VertexBuffer3D.ts index b7c80724..67064a7d 100644 --- a/lib/display3D/VertexBuffer3D.ts +++ b/lib/display3D/VertexBuffer3D.ts @@ -2,6 +2,10 @@ import { ASObject, Float64Vector } from '@awayfl/avm2'; import { IContextGL, IVertexBuffer, VertexBufferWebGL } from '@awayjs/stage'; export class VertexBuffer3D extends ASObject { + static classInitializer: any = null; + static classSymbols: string [] = null; // []; + static instanceSymbols: string [] = null; + public _adaptee: IVertexBuffer constructor(context: IContextGL, numVertices, dataPerVertex) { @@ -11,9 +15,9 @@ export class VertexBuffer3D extends ASObject { public uploadFromVector(data: Float64Vector, startVertex: number, numVertices) { const dataFloat32Array: Float32Array = new Float32Array(data.length); - for (let i: number = 0; i < data.length; i++) { - data[i] = dataFloat32Array[i]; - } + for(var i:number = 0; i < data.length; i++) { + data[i] = dataFloat32Array[i]; + } this._adaptee.uploadFromArray(dataFloat32Array, startVertex, numVertices); } } \ No newline at end of file diff --git a/lib/link.ts b/lib/link.ts index 5781db54..31a35871 100644 --- a/lib/link.ts +++ b/lib/link.ts @@ -298,6 +298,7 @@ export function initLink() { M('flash.display.Sprite', Sprite); M('flash.display.Stage', Stage); M('flash.display.Stage3D', Stage3D); + //M('flash.display.StageAlign', StageAlign); //M('flash.display.StageAspectRatio', StageAspectRatio);//AIR //M('flash.display.StageDisplayState', StageDisplayState); @@ -306,6 +307,7 @@ export function initLink() { //M('flash.display.TriangleCulling', TriangleCulling); // TODO: Add display3d stuff + M('flash.display3D.Context3D', Context3D); M('flash.display3D.Context3DClearMask', Context3DClearMask); M('flash.display3D.Context3DProfile', Context3DProfile); From eaee8aa70009e6a844b61f5bc7f49edb8f9169f4 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Wed, 11 Sep 2024 22:08:58 +0000 Subject: [PATCH 13/59] Vectors suck --- lib/display/Stage.ts | 11 +++++------ lib/display/Stage3D.ts | 3 +++ lib/display3D/Context3D.ts | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/display/Stage.ts b/lib/display/Stage.ts index 812c77bb..f2840d87 100644 --- a/lib/display/Stage.ts +++ b/lib/display/Stage.ts @@ -164,7 +164,11 @@ export class Stage extends DisplayObjectContainer { this._isStage = true; - this._stage3Ds = new ( this.sec).ObjectVector(StageManager.getInstance().numSlotsFree, true); + this._stage3Ds = new ( this.sec).ObjectVector(); + for (let i: number = 0; i < StageManager.getInstance().numSlotsFree; i++) { + this._stage3Ds.axSetNumericProperty(i, new ( this.sec).flash.display.Stage3D()); + //this.stage3Ds[i] = new Stage3D; + } // resize event listens on window this._resizeCallbackDelegate = (event: any) => this.resizeCallback(event); @@ -189,11 +193,6 @@ export class Stage extends DisplayObjectContainer { ( this.sec).flash.display.DisplayObject.axClass._activeStage = this; this._stage = this; - for (let i: number = 0; i < StageManager.getInstance().numSlotsFree; i++) { - this._stage3Ds.axSetNumericProperty(i, new ( this.sec).flash.display.Stage3D()); - //this.stage3Ds[i] = new Stage3D; - } - this._resizeCallbackDelegate(null); } diff --git a/lib/display/Stage3D.ts b/lib/display/Stage3D.ts index 2fba4459..384d0de9 100644 --- a/lib/display/Stage3D.ts +++ b/lib/display/Stage3D.ts @@ -3,8 +3,11 @@ import { EventDispatcher } from '../events/EventDispatcher'; import { Context3D } from '../display3D/Context3D'; import { Context3DProfile } from '../display3D/Context3DProfile'; import { AVMStage } from '@awayfl/swf-loader'; +import { AXClass } from '@awayfl/avm2'; export class Stage3D extends EventDispatcher { + static axClass: typeof Stage3D & AXClass; + static classInitializer: any = null; private _context3D: Context3D private _visible: Boolean private _x: number diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index d91a4a23..f96dd74e 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -26,7 +26,7 @@ export class Context3D extends EventDispatcher { this._adaptee = e.stage; this._adaptee.removeEventListener(StageEvent.CONTEXT_CREATED, this.onAwayContextCreated); this._gl = (this._adaptee.context as ContextWebGL)._gl; - this._stage3D.dispatchEvent(new ( this.sec).flash.events.Event(Event.CONTEXT3D_CREATE)) + this._stage3D.dispatchEvent(new Event(Event.CONTEXT3D_CREATE)) } From 22ea7bfcd7a2ac1de8505be35cbcda35cc730ec0 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Thu, 12 Sep 2024 22:06:06 +0000 Subject: [PATCH 14/59] it almost works? --- lib/display/Stage.ts | 3 +- lib/display/Stage3D.ts | 104 ++++++++++++++++++++++--------------- lib/display3D/Context3D.ts | 64 ++++++++++++++++++++--- 3 files changed, 119 insertions(+), 52 deletions(-) diff --git a/lib/display/Stage.ts b/lib/display/Stage.ts index f2840d87..9976b901 100644 --- a/lib/display/Stage.ts +++ b/lib/display/Stage.ts @@ -165,9 +165,8 @@ export class Stage extends DisplayObjectContainer { this._isStage = true; this._stage3Ds = new ( this.sec).ObjectVector(); - for (let i: number = 0; i < StageManager.getInstance().numSlotsFree; i++) { + for (var i: number = 0; i < 4; i++) { this._stage3Ds.axSetNumericProperty(i, new ( this.sec).flash.display.Stage3D()); - //this.stage3Ds[i] = new Stage3D; } // resize event listens on window diff --git a/lib/display/Stage3D.ts b/lib/display/Stage3D.ts index 384d0de9..3e8c267b 100644 --- a/lib/display/Stage3D.ts +++ b/lib/display/Stage3D.ts @@ -2,57 +2,75 @@ import { ContextGLProfile, ContextMode, Stage as AwayStage, Stage, StageManager import { EventDispatcher } from '../events/EventDispatcher'; import { Context3D } from '../display3D/Context3D'; import { Context3DProfile } from '../display3D/Context3DProfile'; -import { AVMStage } from '@awayfl/swf-loader'; -import { AXClass } from '@awayfl/avm2'; +import { AVMStage, Debug } from '@awayfl/swf-loader'; +import { Bytecode } from '@awayfl/avm2/lib/Bytecode'; +import { Multiname } from '@awayfl/avm2'; +import { Event } from '../events/Event'; +import { SecurityDomain } from '../SecurityDomain'; + export class Stage3D extends EventDispatcher { - static axClass: typeof Stage3D & AXClass; - static classInitializer: any = null; + // Called whenever the class is initialized. + public static classInitializer: any = null; + + // List of static symbols to link. + public static classSymbols: string[] = null; // []; + + // List of instance symbols to link. + public static instanceSymbols: string[] = null; // []; private _context3D: Context3D - private _visible: Boolean + private _visible: boolean private _x: number private _y: number - - private _adapteeStage3Ds: AwayStage[] = AVMStage.instance().stage3Ds - private _adaptee: AwayStage + private instance: number constructor() { + // This is never called, what's going on??? super(); + console.log("Stage3D constructor called") + } + + public get x(): number { + Debug.notImplemented('[playerglobal/display/Stage3D] - get x not implemented'); + return this._x; + } + + public set x(value: number) { + this._x = value; + Debug.notImplemented('[playerglobal/display/Stage3D] - set x not implemented'); + } + + public get y(): number { + Debug.notImplemented('[playerglobal/display/Stage3D] - get y not implemented'); + return this._y; + } + + public set y(value: number) { + value = this._y; + Debug.notImplemented('[playerglobal/display/Stage3D] - set y not implemented'); + } + + public get visible(): boolean { + Debug.notImplemented('[playerglobal/display/Stage3D] - get visible not implemented'); + return this._visible; + } + + public set visible(value: boolean) { + this._visible = value + Debug.notImplemented('[playerglobal/display/Stage3D] - set visible not implemented'); + } + + public get context3D():Context3D { + return this._context3D + } + + public requestContext3D(context3DRenderMode: string = 'auto', profile: string = 'baseline'): void { + console.log("Request Context") + this._context3D = new Context3D(0, context3DRenderMode, profile ?? 'baseline' , this); + this._context3D.addEventListener(Event.CONTEXT3D_CREATE, this.onContextCreated) + } - this._adapteeStage3Ds[this._adapteeStage3Ds.length] = StageManager.getInstance().getFreeStage(); - console.log('Created Stage3D ' + (this._adapteeStage3Ds.length - 1)); - - } - - public get context3D(): Context3D { - return this._context3D; - } - - public requestContext3D(context3DRenderMode: String = 'auto', profile: String = 'baseline'): void { - this._context3D = new Context3D(this, this._adaptee, profile); - const forceSoftware: boolean = (context3DRenderMode == 'auto'); - switch (profile) { - case Context3DProfile.BASELINE: - this._adaptee.requestContext(forceSoftware, ContextGLProfile.BASELINE); - break; - case Context3DProfile.BASELINE_CONSTRAINED: - this._adaptee.requestContext(forceSoftware, ContextGLProfile.BASELINE_CONSTRAINED); - break; - case Context3DProfile.BASELINE_EXTENDED: - this._adaptee.requestContext(forceSoftware, ContextGLProfile.BASELINE_EXTENDED); - break; - case Context3DProfile.STANDARD: - console.log('Unsupported Context3D Profile \'standard\' Requested'); - break; - case Context3DProfile.STANDARD_CONSTRAINED: - console.log('Unsupported Context3D Profile \'standard_constrained\' Requested'); - break; - case Context3DProfile.STANDARD_EXTENDED: - console.log('Unsupported Context3D Profile \'standard_extended\' Requested'); - break; - default: - break; - - } + public onContextCreated(e:Event=null){ + super.dispatchEvent(new Event(Event.CONTEXT3D_CREATE)) } } \ No newline at end of file diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index f96dd74e..2de9f291 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -1,4 +1,4 @@ -import { ContextGLDrawMode, ContextGLProgramType, ContextGLVertexBufferFormat, ContextWebGL, ProgramWebGL, Stage as AwayStage, StageEvent } from '@awayjs/stage'; +import { ContextGLDrawMode, ContextGLProfile, ContextGLProgramType, ContextGLVertexBufferFormat, ContextMode, ContextWebGL, ProgramWebGL, Stage as AwayStage, Stage, StageEvent, StageManager } from '@awayjs/stage'; import { EventDispatcher } from '../events/EventDispatcher'; import { Context3DProgramType } from '../display3D/Context3DProgramType'; import { Context3DVertexBufferFormat } from '../display3D/Context3DVertexBufferFormat'; @@ -8,25 +8,57 @@ import { Program3D } from '../display3D/Program3D'; import { Matrix3D } from '../geom/Matrix3D'; import { Stage3D } from '../display/Stage3D'; import { Event } from '../events/Event'; +import { AVMStage } from '@awayfl/swf-loader'; +import { EventBase } from '@awayjs/core'; import { SecurityDomain } from '../SecurityDomain'; export class Context3D extends EventDispatcher { private _adaptee: AwayStage private _gl: WebGLRenderingContext | WebGL2RenderingContext private _program: Program3D - private _stage3D: Stage3D + private _stage3D:Stage3D - constructor(stage3D: Stage3D, awayStage: AwayStage, profile) { + constructor(id:number, renderMode:string = 'auto', profile:string = 'baseline', stage3D:Stage3D) { super(); - awayStage.addEventListener(StageEvent.CONTEXT_CREATED, this.onAwayContextCreated); + console.log("Context3D Init") this._stage3D = stage3D + console.log(stage3D) + var forceSoftware: boolean = (renderMode == 'auto'); + var awayContextProfile:ContextGLProfile = this.getAwayProfile(profile) + console.log("Context3D Config: ", "id: ", id+1, " forceSoftware: ", forceSoftware, " profile: ", awayContextProfile) + this._adaptee = AVMStage.instance().stage3Ds[id+1] + this._adaptee.addEventListener(StageEvent.CONTEXT_RECREATED, this.onAwayContextCreated); + this._adaptee.requestContext(forceSoftware, awayContextProfile) + } + + private getAwayProfile(context3DProfile:string):ContextGLProfile { + switch (context3DProfile) { + case 'baseline': + return ContextGLProfile.BASELINE; + case 'baseline_constrained': + return ContextGLProfile.BASELINE_CONSTRAINED; + case 'baseline_extended': + return ContextGLProfile.BASELINE_EXTENDED; + case 'standard': + console.log('Unsupported Context3D Profile \'standard\' Requested'); + return + case 'standard_constrained': + console.log('Unsupported Context3D Profile \'standard_constrained\' Requested'); + return + case 'standard_extended': + console.log('Unsupported Context3D Profile \'standard_extended\' Requested'); + return + default: + return ContextGLProfile.BASELINE; + } } private onAwayContextCreated(e: StageEvent) { - this._adaptee = e.stage; - this._adaptee.removeEventListener(StageEvent.CONTEXT_CREATED, this.onAwayContextCreated); + console.log(e.stage); + this._adaptee = e.stage this._gl = (this._adaptee.context as ContextWebGL)._gl; - this._stage3D.dispatchEvent(new Event(Event.CONTEXT3D_CREATE)) + super.dispatchEvent(new Event(Event.CONTEXT3D_CREATE)) + console.log(super.hasEventListener(Event.CONTEXT3D_CREATE)) } @@ -109,4 +141,22 @@ export class Context3D extends EventDispatcher { this._adaptee.context.setVertexBufferAt(index, buffer._adaptee, bufferOffset, awayFormat); } + public dispatchEvent(event: EventBase, comesFromAway: boolean = false): boolean { + (event).currentTarget = this; + if (event.type == 'enterFrame') {//} || event.type=="scroll"){ + (event).target = this; + } + const returnVal = super.dispatchEvent(event); + + // workaround for now. + // mousevents already bubble up the scenegraph in MouseMangager + // for all other events, we want to bubble them up here: + if (!comesFromAway && EventDispatcher.eventsThatBubbleInAwayJS.indexOf(event.type) == -1) { + if (( this).adaptee && ( this).adaptee.parent) { + ( this).adaptee.parent.adapter.dispatchEvent(event); + } + } + return returnVal; + } + } \ No newline at end of file From e619ab561f82c66a468d9a71b800135998891292 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Fri, 13 Sep 2024 22:11:08 +0000 Subject: [PATCH 15/59] Commit work --- lib/SecurityDomain.ts | 2 +- lib/display/Stage.ts | 4 +- lib/display/Stage3D.ts | 63 +++++++--- lib/display3D/Context3D.ts | 215 +++++++++++++++++++++----------- lib/display3D/IndexBuffer3D.ts | 23 +++- lib/display3D/Program3D.ts | 20 +-- lib/display3D/VertexBuffer3D.ts | 33 +++-- lib/link.ts | 2 +- 8 files changed, 243 insertions(+), 119 deletions(-) diff --git a/lib/SecurityDomain.ts b/lib/SecurityDomain.ts index 7a7a6ee5..da531f5b 100644 --- a/lib/SecurityDomain.ts +++ b/lib/SecurityDomain.ts @@ -104,7 +104,7 @@ export class SecurityDomain extends AXSecurityDomain { Shape: Shape, FrameLabel: FrameLabel }, - display3d: { + display3D: { Context3D: Context3D, IndexBuffer3D: IndexBuffer3D, Program3D: Program3D, diff --git a/lib/display/Stage.ts b/lib/display/Stage.ts index 9976b901..e05926db 100644 --- a/lib/display/Stage.ts +++ b/lib/display/Stage.ts @@ -165,8 +165,8 @@ export class Stage extends DisplayObjectContainer { this._isStage = true; this._stage3Ds = new ( this.sec).ObjectVector(); - for (var i: number = 0; i < 4; i++) { - this._stage3Ds.axSetNumericProperty(i, new ( this.sec).flash.display.Stage3D()); + for (let i: number = 0; i < AVMStage.instance().stage3Ds.length; i++) { + this._stage3Ds.axSetNumericProperty(i, new ( this.sec).flash.display.Stage3D(i)); } // resize event listens on window diff --git a/lib/display/Stage3D.ts b/lib/display/Stage3D.ts index 3e8c267b..c1bae309 100644 --- a/lib/display/Stage3D.ts +++ b/lib/display/Stage3D.ts @@ -4,12 +4,12 @@ import { Context3D } from '../display3D/Context3D'; import { Context3DProfile } from '../display3D/Context3DProfile'; import { AVMStage, Debug } from '@awayfl/swf-loader'; import { Bytecode } from '@awayfl/avm2/lib/Bytecode'; -import { Multiname } from '@awayfl/avm2'; +import { AXClass, Multiname } from '@awayfl/avm2'; import { Event } from '../events/Event'; import { SecurityDomain } from '../SecurityDomain'; - export class Stage3D extends EventDispatcher { + static axClass: typeof Stage3D & AXClass; // Called whenever the class is initialized. public static classInitializer: any = null; @@ -22,12 +22,18 @@ export class Stage3D extends EventDispatcher { private _visible: boolean private _x: number private _y: number - private instance: number + private _id: number + private _adaptee:AwayStage + + constructor(i) { + super() + console.log("Stage3D Constructor") + this._adaptee = AVMStage.instance().stage3Ds[i]; + this._id = i + } - constructor() { - // This is never called, what's going on??? - super(); - console.log("Stage3D constructor called") + public get adaptee(): AwayStage{ + return this._adaptee } public get x(): number { @@ -56,21 +62,44 @@ export class Stage3D extends EventDispatcher { } public set visible(value: boolean) { - this._visible = value + this._visible = value; Debug.notImplemented('[playerglobal/display/Stage3D] - set visible not implemented'); } - public get context3D():Context3D { - return this._context3D + public get context3D(): Context3D { + return this._context3D; } public requestContext3D(context3DRenderMode: string = 'auto', profile: string = 'baseline'): void { - console.log("Request Context") - this._context3D = new Context3D(0, context3DRenderMode, profile ?? 'baseline' , this); - this._context3D.addEventListener(Event.CONTEXT3D_CREATE, this.onContextCreated) - } - - public onContextCreated(e:Event=null){ - super.dispatchEvent(new Event(Event.CONTEXT3D_CREATE)) + console.log('Request Context'); + this._context3D = new (this.sec as SecurityDomain).flash.display3D.Context3D(0, this, profile, context3DRenderMode ); + const forceSoftware: boolean = (context3DRenderMode == 'auto'); + var awayContextProfile:ContextGLProfile + switch (profile) { + case 'baseline': + awayContextProfile = ContextGLProfile.BASELINE; + break; + case 'baseline_constrained': + awayContextProfile = ContextGLProfile.BASELINE_CONSTRAINED; + break; + case 'baseline_extended': + awayContextProfile = ContextGLProfile.BASELINE_EXTENDED; + break; + case 'standard': + console.log('Unsupported Context3D Profile \'standard\' Requested'); + break; + case 'standard_constrained': + console.log('Unsupported Context3D Profile \'standard_constrained\' Requested'); + break; + case 'standard_extended': + console.log('Unsupported Context3D Profile \'standard_extended\' Requested'); + break; + default: + awayContextProfile = ContextGLProfile.BASELINE; + break; + } + console.log('Context3D Config: ', 'id: ', 0, ' forceSoftware: ', forceSoftware, ' profile: ', awayContextProfile); + this._adaptee.requestContext(forceSoftware, awayContextProfile); + super.dispatchEvent(new (this.sec as SecurityDomain).flash.events.Event(Event.CONTEXT3D_CREATE)); } } \ No newline at end of file diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index 2de9f291..2417dcf6 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -1,89 +1,92 @@ -import { ContextGLDrawMode, ContextGLProfile, ContextGLProgramType, ContextGLVertexBufferFormat, ContextMode, ContextWebGL, ProgramWebGL, Stage as AwayStage, Stage, StageEvent, StageManager } from '@awayjs/stage'; -import { EventDispatcher } from '../events/EventDispatcher'; +import { ContextGLDrawMode, ContextGLProfile, ContextGLProgramType, ContextGLVertexBufferFormat, + ContextWebGL, ProgramWebGL, Stage as AwayStage, StageEvent } from '@awayjs/stage'; +import { BitmapData } from '../display/BitmapData'; +import { Stage3D } from '../display/Stage3D'; import { Context3DProgramType } from '../display3D/Context3DProgramType'; import { Context3DVertexBufferFormat } from '../display3D/Context3DVertexBufferFormat'; import { IndexBuffer3D } from '../display3D/IndexBuffer3D'; -import { VertexBuffer3D } from '../display3D/VertexBuffer3D'; import { Program3D } from '../display3D/Program3D'; +import { VertexBuffer3D } from '../display3D/VertexBuffer3D'; +import { EventDispatcher } from '../events/EventDispatcher'; import { Matrix3D } from '../geom/Matrix3D'; -import { Stage3D } from '../display/Stage3D'; -import { Event } from '../events/Event'; -import { AVMStage } from '@awayfl/swf-loader'; -import { EventBase } from '@awayjs/core'; +import { Rectangle } from '../geom/Rectangle'; +import { ByteArray } from '../utils/ByteArray'; + +import { AXClass, Float64Vector } from '@awayfl/avm2'; +import { AVMStage, Debug } from '@awayfl/swf-loader'; import { SecurityDomain } from '../SecurityDomain'; export class Context3D extends EventDispatcher { + // Called whenever the class is initialized. + public static classInitializer: any = null; + + // List of static symbols to link. + public static classSymbols: string[] = null; // []; + + // List of instance symbols to link. + public static instanceSymbols: string[] = null; // []; private _adaptee: AwayStage + private _renderMode: string + private _profile: string private _gl: WebGLRenderingContext | WebGL2RenderingContext private _program: Program3D - private _stage3D:Stage3D + private _stage3D: Stage3D - constructor(id:number, renderMode:string = 'auto', profile:string = 'baseline', stage3D:Stage3D) { - super(); - console.log("Context3D Init") + constructor(id: number, stage3D: Stage3D, renderMode: string = 'auto', profile: string = 'baseline') { + super() + console.log('Context3D Create'); + this._renderMode = renderMode + this._profile = profile this._stage3D = stage3D - console.log(stage3D) - var forceSoftware: boolean = (renderMode == 'auto'); - var awayContextProfile:ContextGLProfile = this.getAwayProfile(profile) - console.log("Context3D Config: ", "id: ", id+1, " forceSoftware: ", forceSoftware, " profile: ", awayContextProfile) - this._adaptee = AVMStage.instance().stage3Ds[id+1] - this._adaptee.addEventListener(StageEvent.CONTEXT_RECREATED, this.onAwayContextCreated); - this._adaptee.requestContext(forceSoftware, awayContextProfile) - } - - private getAwayProfile(context3DProfile:string):ContextGLProfile { - switch (context3DProfile) { - case 'baseline': - return ContextGLProfile.BASELINE; - case 'baseline_constrained': - return ContextGLProfile.BASELINE_CONSTRAINED; - case 'baseline_extended': - return ContextGLProfile.BASELINE_EXTENDED; - case 'standard': - console.log('Unsupported Context3D Profile \'standard\' Requested'); - return - case 'standard_constrained': - console.log('Unsupported Context3D Profile \'standard_constrained\' Requested'); - return - case 'standard_extended': - console.log('Unsupported Context3D Profile \'standard_extended\' Requested'); - return - default: - return ContextGLProfile.BASELINE; - } + this._adaptee = stage3D.adaptee + console.log(stage3D); + } + + public get adaptee():AwayStage { + return this._adaptee } - private onAwayContextCreated(e: StageEvent) { + private _onAwayContextCreatedDelegate(e: StageEvent): void { console.log(e.stage); - this._adaptee = e.stage + this._adaptee = e.stage; this._gl = (this._adaptee.context as ContextWebGL)._gl; - super.dispatchEvent(new Event(Event.CONTEXT3D_CREATE)) - console.log(super.hasEventListener(Event.CONTEXT3D_CREATE)) - + //this._stage3D.dispatchEvent(new (this.sec as SecurityDomain).flash.events.Event(Event.CONTEXT3D_CREATE)) + console.log('Context Created'); + } - public clear(red: number = 0.0, green: number = 0.0, blue: number = 0.0, alpha: number = 1.0, depth: number = 1.0, stencil: number = 0, mask: number = 0xffffffff): void { - console.log('Mask: ' + mask); - this._adaptee.clear(red, green, blue, alpha, depth, stencil, mask); + public get driverInfo(): string { + Debug.notImplemented('public flash.display3D.Context3D::get driverInfo'); return; + // return this._driverInfo; } - public configureBackBuffer(width: number, height: number, antiAlias: number, enableDepthAndStencil: boolean = true, wantsBestResolution: Boolean = false, wantsBestResolutionOnBrowserZoom: Boolean = false): void { - this._adaptee.configureBackBuffer(width, height, antiAlias, enableDepthAndStencil); + public get enableErrorChecking(): boolean { + Debug.notImplemented('public flash.display3D.Context3D::get enableErrorChecking'); return; + // return this._enableErrorChecking; } - public createIndexBuffer(numIndices: number, bufferUsage: string = 'staticDraw'): IndexBuffer3D { - return new IndexBuffer3D(this._adaptee.context, numIndices); + public set enableErrorChecking(toggle: boolean) { + toggle = !!toggle; + Debug.notImplemented('public flash.display3D.Context3D::set enableErrorChecking'); return; + // this._enableErrorChecking = toggle; } - public createProgram(): Program3D { - return new Program3D(this._adaptee.context); + public dispose(): void { + Debug.notImplemented('public flash.display3D.Context3D::dispose'); return; } - public createVertexBuffer(numVertices: number, data32PerVertex: number, bufferUsage: string = 'staticDraw'): VertexBuffer3D { - return new VertexBuffer3D(this._adaptee.context, numVertices, data32PerVertex); + public configureBackBuffer(width: number, height: number, antiAlias: number, enableDepthAndStencil: boolean = true, wantsBestResolution: Boolean = false, wantsBestResolutionOnBrowserZoom: Boolean = false): void { + this._adaptee.configureBackBuffer(width, height, antiAlias, enableDepthAndStencil); + console.log('configureBackBuffer') + } + + public clear(red: number = 0.0, green: number = 0.0, blue: number = 0.0, alpha: number = 1.0, depth: number = 1.0, stencil: number = 0, mask: number = 0xffffffff): void { + console.log('clear'); + this._adaptee.clear(red, green, blue, alpha, depth, stencil, mask); } public drawTriangles(indexBuffer: IndexBuffer3D, firstIndex: number = 0, numTriangles: number = -1): void { + console.log("drawTriangles") if (numTriangles != -1) { var numIndices = numTriangles; } else { @@ -93,32 +96,45 @@ export class Context3D extends EventDispatcher { } public present(): void { + console.log('present') this._adaptee.present(); } public setProgram(program: Program3D): void { + console.log('setProgram') this._program = program; this._adaptee.context.setProgram(program._adaptee); } + public setProgramConstantsFromVector(programType: string, firstRegister: number /*int*/, data: Float64Vector, numRegisters: number /*int*/ = -1): void { + Debug.notImplemented('public flash.display3D.Context3D::setProgramConstantsFromVector'); return; + } + public setProgramConstantsFromMatrix(programType: string, firstRegister: number, matrix: Matrix3D, transposedMatrix: boolean = false): void { + console.log('setProgramConstantsFromMatrix') + let awayProgramType:ContextGLProgramType switch (programType) { case Context3DProgramType.FRAGMENT: - var awayProgramType = ContextGLProgramType.FRAGMENT; + awayProgramType = ContextGLProgramType.FRAGMENT; break; case Context3DProgramType.VERTEX: - var awayProgramType = ContextGLProgramType.VERTEX; + awayProgramType = ContextGLProgramType.VERTEX; break; default: break; } const programWebGL: ProgramWebGL = this._program._adaptee as ProgramWebGL; - let matrixRawData: Float32Array; + let matrixRawData: Float32Array = new Float32Array(); matrix.adaptee.copyRawDataTo(matrixRawData, 0, false); programWebGL.uniformMatrix4fv(awayProgramType, transposedMatrix, matrixRawData); } + public setProgramConstantsFromByteArray(programType: string, firstRegister: number /*int*/, numRegisters: number /*int*/, data: ByteArray, byteArrayOffset: number /*uint*/): void { + Debug.notImplemented('public flash.display3D.Context3D::setProgramConstantsFromByteArray'); return; + } + public setVertexBufferAt(index: number, buffer: VertexBuffer3D, bufferOffset: number = 0, format: String = 'float4'): void { + console.log("setVertexBufferAt") switch (format) { case Context3DVertexBufferFormat.BYTES_4: var awayFormat = ContextGLVertexBufferFormat.BYTE_4; @@ -141,22 +157,71 @@ export class Context3D extends EventDispatcher { this._adaptee.context.setVertexBufferAt(index, buffer._adaptee, bufferOffset, awayFormat); } - public dispatchEvent(event: EventBase, comesFromAway: boolean = false): boolean { - (event).currentTarget = this; - if (event.type == 'enterFrame') {//} || event.type=="scroll"){ - (event).target = this; - } - const returnVal = super.dispatchEvent(event); - - // workaround for now. - // mousevents already bubble up the scenegraph in MouseMangager - // for all other events, we want to bubble them up here: - if (!comesFromAway && EventDispatcher.eventsThatBubbleInAwayJS.indexOf(event.type) == -1) { - if (( this).adaptee && ( this).adaptee.parent) { - ( this).adaptee.parent.adapter.dispatchEvent(event); - } - } - return returnVal; + public setBlendFactors(sourceFactor: string, destinationFactor: string): void { + Debug.notImplemented('public flash.display3D.Context3D::setBlendFactors'); return; + } + + public setColorMask(red: boolean, green: boolean, blue: boolean, alpha: boolean): void { + Debug.notImplemented('public flash.display3D.Context3D::setColorMask'); return; + } + + public setDepthTest(fdepthMask: boolean, passCompareMode: string): void { + Debug.notImplemented('public flash.display3D.Context3D::setDepthTest'); return; + } + + public setCulling(triangleFaceToCull: string): void { + Debug.notImplemented('public flash.display3D.Context3D::setCulling'); return; + } + + public setStencilActions(triangleFace: string = 'frontAndBack', compareMode: string = 'always', actionOnBothPass: string = 'keep', actionOnDepthFail: string = 'keep', actionOnDepthPassStencilFail: string = 'keep'): void { + Debug.notImplemented('public flash.display3D.Context3D::setStencilActions'); return; + } + + public setStencilReferenceValue(referenceValue: number /*uint*/, readMask: number /*uint*/ = 255, writeMask: number /*uint*/ = 255): void { + Debug.notImplemented('public flash.display3D.Context3D::setStencilReferenceValue'); return; + } + + public setScissorRectangle(rectangle: Rectangle): void { + Debug.notImplemented('public flash.display3D.Context3D::setScissorRectangle'); return; + } + + public createVertexBuffer(numVertices: number, data32PerVertex: number, bufferUsage: string = 'staticDraw'): VertexBuffer3D { + console.log("createVertexBuffer") + return new (this.sec as SecurityDomain).flash.display3D.VertexBuffer3D(this, numVertices, data32PerVertex); + } + + public createIndexBuffer(numIndices: number, bufferUsage: string = 'staticDraw'): IndexBuffer3D { + console.log("createIndexBuffer") + return new (this.sec as SecurityDomain).flash.display3D.IndexBuffer3D(this, numIndices); + } + + public createTexture(width: number /*int*/, height: number /*int*/, format: string, optimizeForRenderToTexture: boolean, streamingLevels: number /*int*/ = 0): any { + Debug.notImplemented('public flash.display3D.Context3D::createTexture'); return; + } + + public createCubeTexture(size: number /*int*/, format: string, optimizeForRenderToTexture: boolean, streamingLevels: number /*int*/ = 0): any /*CubeTexture*/ { + Debug.notImplemented('public flash.display3D.Context3D::createCubeTexture'); return; + } + + public createProgram(): Program3D { + console.log("createProgram") + return new (this.sec as SecurityDomain).flash.display3D.Program3D(this); + } + + public drawToBitmapData(destination: BitmapData): void { + Debug.notImplemented('public flash.display3D.Context3D::drawToBitmapData'); return; + } + + public setRenderToTextureInternal(textureTextureBase, targetType: number /*int*/, enableDepthAndStencil: boolean, antiAlias: number /*int*/, surfaceSelector: number /*int*/): void { + Debug.notImplemented('public flash.display3D.Context3D::setRenderToTextureInternal'); return; + } + + public setTextureInternal(sampler: number /*int*/, textureTexture): void { + Debug.notImplemented('public flash.display3D.Context3D::setTextureInternal'); return; + } + + public setCubeTextureInternal(sampler: number /*int*/, textureCubeTexture): void { + Debug.notImplemented('public flash.display3D.Context3D::setCubeTextureInternal'); return; } } \ No newline at end of file diff --git a/lib/display3D/IndexBuffer3D.ts b/lib/display3D/IndexBuffer3D.ts index 7bb2e82a..987c8bb2 100644 --- a/lib/display3D/IndexBuffer3D.ts +++ b/lib/display3D/IndexBuffer3D.ts @@ -1,24 +1,37 @@ -import { ASObject, Uint32Vector } from '@awayfl/avm2'; +import { ASObject, AXClass, Uint32Vector } from '@awayfl/avm2'; +import { Debug } from '@awayfl/swf-loader'; +import { ByteArray } from '../utils/ByteArray' import { IContextGL, IIndexBuffer } from '@awayjs/stage'; +import { Context3D } from './Context3D'; export class IndexBuffer3D extends ASObject { + static axClass: typeof IndexBuffer3D & AXClass; static classInitializer: any = null; static classSymbols: string [] = null; // []; static instanceSymbols: string [] = null; public _adaptee: IIndexBuffer - constructor(context: IContextGL, numIndices: number) { + constructor(context3D: Context3D, numIndices: number) { super(); - this._adaptee = context.createIndexBuffer(numIndices); + this._adaptee = context3D.adaptee.context.createIndexBuffer(numIndices); } public uploadFromVector(data: Uint32Vector, startOffset: number, count: number): void { - const uint16ArrayData = new Uint16Array(data.length); + let uint16ArrayData = new Uint16Array(data.length); for (let i: number = 0; i < data.length; i++) { - data[i] = uint16ArrayData[i]; + uint16ArrayData[i] = data.axGetNumericProperty(i);; } + console.log(uint16ArrayData) this._adaptee.uploadFromArray(uint16ArrayData, startOffset, count); } + public uploadFromByteArray(data: ByteArray, byteArrayOffset: number /*int*/, startOffset: number /*int*/, count: number /*int*/): void { + Debug.notImplemented('public flash.display3D.IndexBuffer3D::uploadFromByteArray'); return; + } + + public dispose(): void { + this._adaptee.dispose() + } + } \ No newline at end of file diff --git a/lib/display3D/Program3D.ts b/lib/display3D/Program3D.ts index 035b8ac1..f751e3ea 100644 --- a/lib/display3D/Program3D.ts +++ b/lib/display3D/Program3D.ts @@ -1,19 +1,20 @@ -import { ASObject } from '@awayfl/avm2'; -import { ByteArray as AwayByteArray } from '@awayjs/core'; -import { IContextGL, IProgram } from '@awayjs/stage'; +import { ASObject, AXClass } from '@awayfl/avm2'; +import { ByteArray as AwayByteArray } from '@awayjs/core'; +import { IContextGL, IProgram, ProgramWebGL } from '@awayjs/stage'; import { ByteArray } from '../utils/ByteArray'; +import { Context3D } from './Context3D'; export class Program3D extends ASObject { + static axClass: typeof Program3D & AXClass; static classInitializer: any = null; static classSymbols: string [] = null; // []; static instanceSymbols: string [] = null; public _adaptee: IProgram - constructor(context: IContextGL) { + constructor(context3D: Context3D) { super(); - this._adaptee = context.createProgram(); - + this._adaptee = context3D.adaptee.context.createProgram(); } public dispose() { @@ -21,7 +22,10 @@ export class Program3D extends ASObject { } public upload(vertexProgram: ByteArray, fragmentProgram: ByteArray): void { - AwayByteArray; - this._adaptee.upload(vertexProgram, fragmentProgram); + var awayVertexProgram:AwayByteArray = new ByteArray() + var awayFragmentProgram:AwayByteArray = new ByteArray() + vertexProgram.writeByteArray(awayVertexProgram) + fragmentProgram.writeByteArray(awayFragmentProgram) + this._adaptee.upload(awayVertexProgram, awayFragmentProgram); } } \ No newline at end of file diff --git a/lib/display3D/VertexBuffer3D.ts b/lib/display3D/VertexBuffer3D.ts index 67064a7d..616b1184 100644 --- a/lib/display3D/VertexBuffer3D.ts +++ b/lib/display3D/VertexBuffer3D.ts @@ -1,23 +1,36 @@ -import { ASObject, Float64Vector } from '@awayfl/avm2'; +import { ASObject, AXClass, Float64Vector } from '@awayfl/avm2'; +import { Debug } from '@awayfl/swf-loader'; +import { ByteArray } from '../utils/ByteArray' import { IContextGL, IVertexBuffer, VertexBufferWebGL } from '@awayjs/stage'; +import { Context3D } from './Context3D'; export class VertexBuffer3D extends ASObject { + static axClass: typeof VertexBuffer3D & AXClass; static classInitializer: any = null; static classSymbols: string [] = null; // []; static instanceSymbols: string [] = null; - public _adaptee: IVertexBuffer - - constructor(context: IContextGL, numVertices, dataPerVertex) { - super(); - this._adaptee = context.createVertexBuffer(numVertices, dataPerVertex); + + constructor(context3D: Context3D, numVertices, dataPerVertex) { + super() + this._adaptee = context3D.adaptee.context.createVertexBuffer(numVertices, dataPerVertex); } + public uploadFromVector(data: Float64Vector, startVertex: number, numVertices) { - const dataFloat32Array: Float32Array = new Float32Array(data.length); - for(var i:number = 0; i < data.length; i++) { - data[i] = dataFloat32Array[i]; - } + let dataFloat32Array: Float32Array = new Float32Array(data.length); + for (let i: number = 0; i < data.length; i++) { + dataFloat32Array[i] = data.axGetNumericProperty(i); + } + console.log(dataFloat32Array) this._adaptee.uploadFromArray(dataFloat32Array, startVertex, numVertices); } + + public uploadFromByteArray(data: ByteArray, byteArrayOffset: number /*int*/, startVertex: number /*int*/, numVertices: number /*int*/): void { + Debug.notImplemented('public flash.display3D.VertexBuffer3D::uploadFromByteArray'); return; + } + + public dispose(): void { + this._adaptee.dispose(); + } } \ No newline at end of file diff --git a/lib/link.ts b/lib/link.ts index 31a35871..449ce412 100644 --- a/lib/link.ts +++ b/lib/link.ts @@ -307,7 +307,7 @@ export function initLink() { //M('flash.display.TriangleCulling', TriangleCulling); // TODO: Add display3d stuff - + M('flash.display3D.Context3D', Context3D); M('flash.display3D.Context3DClearMask', Context3DClearMask); M('flash.display3D.Context3DProfile', Context3DProfile); From 2fca84794b40a7beb0387301e629135a71770fdd Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Fri, 13 Sep 2024 22:39:09 +0000 Subject: [PATCH 16/59] Fix --- lib/display3D/Context3D.ts | 10 +--------- lib/display3D/Program3D.ts | 6 +----- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index 2417dcf6..773b7b59 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -77,16 +77,14 @@ export class Context3D extends EventDispatcher { public configureBackBuffer(width: number, height: number, antiAlias: number, enableDepthAndStencil: boolean = true, wantsBestResolution: Boolean = false, wantsBestResolutionOnBrowserZoom: Boolean = false): void { this._adaptee.configureBackBuffer(width, height, antiAlias, enableDepthAndStencil); - console.log('configureBackBuffer') } public clear(red: number = 0.0, green: number = 0.0, blue: number = 0.0, alpha: number = 1.0, depth: number = 1.0, stencil: number = 0, mask: number = 0xffffffff): void { - console.log('clear'); this._adaptee.clear(red, green, blue, alpha, depth, stencil, mask); } public drawTriangles(indexBuffer: IndexBuffer3D, firstIndex: number = 0, numTriangles: number = -1): void { - console.log("drawTriangles") + this._adaptee.context.drawIndices(ContextGLDrawMode.TRIANGLES, indexBuffer._adaptee, firstIndex, numTriangles) if (numTriangles != -1) { var numIndices = numTriangles; } else { @@ -96,12 +94,10 @@ export class Context3D extends EventDispatcher { } public present(): void { - console.log('present') this._adaptee.present(); } public setProgram(program: Program3D): void { - console.log('setProgram') this._program = program; this._adaptee.context.setProgram(program._adaptee); } @@ -111,7 +107,6 @@ export class Context3D extends EventDispatcher { } public setProgramConstantsFromMatrix(programType: string, firstRegister: number, matrix: Matrix3D, transposedMatrix: boolean = false): void { - console.log('setProgramConstantsFromMatrix') let awayProgramType:ContextGLProgramType switch (programType) { case Context3DProgramType.FRAGMENT: @@ -134,7 +129,6 @@ export class Context3D extends EventDispatcher { } public setVertexBufferAt(index: number, buffer: VertexBuffer3D, bufferOffset: number = 0, format: String = 'float4'): void { - console.log("setVertexBufferAt") switch (format) { case Context3DVertexBufferFormat.BYTES_4: var awayFormat = ContextGLVertexBufferFormat.BYTE_4; @@ -191,7 +185,6 @@ export class Context3D extends EventDispatcher { } public createIndexBuffer(numIndices: number, bufferUsage: string = 'staticDraw'): IndexBuffer3D { - console.log("createIndexBuffer") return new (this.sec as SecurityDomain).flash.display3D.IndexBuffer3D(this, numIndices); } @@ -204,7 +197,6 @@ export class Context3D extends EventDispatcher { } public createProgram(): Program3D { - console.log("createProgram") return new (this.sec as SecurityDomain).flash.display3D.Program3D(this); } diff --git a/lib/display3D/Program3D.ts b/lib/display3D/Program3D.ts index f751e3ea..58a3e876 100644 --- a/lib/display3D/Program3D.ts +++ b/lib/display3D/Program3D.ts @@ -22,10 +22,6 @@ export class Program3D extends ASObject { } public upload(vertexProgram: ByteArray, fragmentProgram: ByteArray): void { - var awayVertexProgram:AwayByteArray = new ByteArray() - var awayFragmentProgram:AwayByteArray = new ByteArray() - vertexProgram.writeByteArray(awayVertexProgram) - fragmentProgram.writeByteArray(awayFragmentProgram) - this._adaptee.upload(awayVertexProgram, awayFragmentProgram); + this._adaptee.upload(vertexProgram, fragmentProgram); } } \ No newline at end of file From 84d345a3971062e04dca15f4048f469340faa52f Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Fri, 13 Sep 2024 23:02:20 +0000 Subject: [PATCH 17/59] fix --- lib/display3D/Context3D.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index 773b7b59..a36a1812 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -75,7 +75,7 @@ export class Context3D extends EventDispatcher { Debug.notImplemented('public flash.display3D.Context3D::dispose'); return; } - public configureBackBuffer(width: number, height: number, antiAlias: number, enableDepthAndStencil: boolean = true, wantsBestResolution: Boolean = false, wantsBestResolutionOnBrowserZoom: Boolean = false): void { + public configureBackBuffer(width: number, height: number, antiAlias: number, enableDepthAndStencil: boolean = true, wantsBestResolution: boolean = false, wantsBestResolutionOnBrowserZoom: boolean = false): void { this._adaptee.configureBackBuffer(width, height, antiAlias, enableDepthAndStencil); } @@ -84,13 +84,7 @@ export class Context3D extends EventDispatcher { } public drawTriangles(indexBuffer: IndexBuffer3D, firstIndex: number = 0, numTriangles: number = -1): void { - this._adaptee.context.drawIndices(ContextGLDrawMode.TRIANGLES, indexBuffer._adaptee, firstIndex, numTriangles) - if (numTriangles != -1) { - var numIndices = numTriangles; - } else { - var numIndices = numTriangles * 3; - } - this._adaptee.context.drawIndices(ContextGLDrawMode.TRIANGLES, indexBuffer._adaptee, firstIndex, numIndices); + this._adaptee.context.drawIndices(ContextGLDrawMode.TRIANGLES, indexBuffer._adaptee, firstIndex, numTriangles*3) } public present(): void { @@ -128,7 +122,7 @@ export class Context3D extends EventDispatcher { Debug.notImplemented('public flash.display3D.Context3D::setProgramConstantsFromByteArray'); return; } - public setVertexBufferAt(index: number, buffer: VertexBuffer3D, bufferOffset: number = 0, format: String = 'float4'): void { + public setVertexBufferAt(index: number, buffer: VertexBuffer3D, bufferOffset: number = 0, format: string = 'float4'): void { switch (format) { case Context3DVertexBufferFormat.BYTES_4: var awayFormat = ContextGLVertexBufferFormat.BYTE_4; From d5d1219b26a7719ba611ee3af255d67385b45b0d Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Sat, 14 Sep 2024 22:47:19 +0000 Subject: [PATCH 18/59] Temp Prog 3D Fix --- lib/display3D/Context3D.ts | 24 ++++++++++++------------ lib/display3D/Program3D.ts | 3 +++ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index a36a1812..d52a94ec 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -46,14 +46,14 @@ export class Context3D extends EventDispatcher { return this._adaptee } - private _onAwayContextCreatedDelegate(e: StageEvent): void { + /*private _onAwayContextCreatedDelegate(e: StageEvent): void { console.log(e.stage); this._adaptee = e.stage; this._gl = (this._adaptee.context as ContextWebGL)._gl; //this._stage3D.dispatchEvent(new (this.sec as SecurityDomain).flash.events.Event(Event.CONTEXT3D_CREATE)) console.log('Context Created'); - } + }*/ public get driverInfo(): string { Debug.notImplemented('public flash.display3D.Context3D::get driverInfo'); return; @@ -84,7 +84,8 @@ export class Context3D extends EventDispatcher { } public drawTriangles(indexBuffer: IndexBuffer3D, firstIndex: number = 0, numTriangles: number = -1): void { - this._adaptee.context.drawIndices(ContextGLDrawMode.TRIANGLES, indexBuffer._adaptee, firstIndex, numTriangles*3) + // @todo: This is not working + this._adaptee.context.drawIndices(ContextGLDrawMode.TRIANGLES, indexBuffer._adaptee, firstIndex, (numTriangles == -1) ? -1 : (numTriangles * 3)) } public present(): void { @@ -92,8 +93,8 @@ export class Context3D extends EventDispatcher { } public setProgram(program: Program3D): void { - this._program = program; this._adaptee.context.setProgram(program._adaptee); + this._program = program; } public setProgramConstantsFromVector(programType: string, firstRegister: number /*int*/, data: Float64Vector, numRegisters: number /*int*/ = -1): void { @@ -113,9 +114,7 @@ export class Context3D extends EventDispatcher { break; } const programWebGL: ProgramWebGL = this._program._adaptee as ProgramWebGL; - let matrixRawData: Float32Array = new Float32Array(); - matrix.adaptee.copyRawDataTo(matrixRawData, 0, false); - programWebGL.uniformMatrix4fv(awayProgramType, transposedMatrix, matrixRawData); + programWebGL.uniformMatrix4fv(awayProgramType, transposedMatrix, matrix.adaptee._rawData); } public setProgramConstantsFromByteArray(programType: string, firstRegister: number /*int*/, numRegisters: number /*int*/, data: ByteArray, byteArrayOffset: number /*uint*/): void { @@ -123,21 +122,22 @@ export class Context3D extends EventDispatcher { } public setVertexBufferAt(index: number, buffer: VertexBuffer3D, bufferOffset: number = 0, format: string = 'float4'): void { + let awayFormat:number switch (format) { case Context3DVertexBufferFormat.BYTES_4: - var awayFormat = ContextGLVertexBufferFormat.BYTE_4; + awayFormat = ContextGLVertexBufferFormat.BYTE_4; break; case Context3DVertexBufferFormat.FLOAT_1: - var awayFormat = ContextGLVertexBufferFormat.FLOAT_1; + awayFormat = ContextGLVertexBufferFormat.FLOAT_1; break; case Context3DVertexBufferFormat.FLOAT_2: - var awayFormat = ContextGLVertexBufferFormat.FLOAT_2; + awayFormat = ContextGLVertexBufferFormat.FLOAT_2; break; case Context3DVertexBufferFormat.FLOAT_3: - var awayFormat = ContextGLVertexBufferFormat.FLOAT_3; + awayFormat = ContextGLVertexBufferFormat.FLOAT_3; break; case Context3DVertexBufferFormat.FLOAT_4: - var awayFormat = ContextGLVertexBufferFormat.FLOAT_4; + awayFormat = ContextGLVertexBufferFormat.FLOAT_4; break; default: break; diff --git a/lib/display3D/Program3D.ts b/lib/display3D/Program3D.ts index 58a3e876..48b619f5 100644 --- a/lib/display3D/Program3D.ts +++ b/lib/display3D/Program3D.ts @@ -11,9 +11,11 @@ export class Program3D extends ASObject { static instanceSymbols: string [] = null; public _adaptee: IProgram + private _context: IContextGL constructor(context3D: Context3D) { super(); + this._context = context3D.adaptee.context this._adaptee = context3D.adaptee.context.createProgram(); } @@ -23,5 +25,6 @@ export class Program3D extends ASObject { public upload(vertexProgram: ByteArray, fragmentProgram: ByteArray): void { this._adaptee.upload(vertexProgram, fragmentProgram); + this._context.setProgram(this._adaptee) } } \ No newline at end of file From f1970051ef86e510f40caddedcee5a5c7eb241f3 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Mon, 16 Sep 2024 18:00:14 +0000 Subject: [PATCH 19/59] Fix DataPerVertex in VertexBuffer & Fixed by eslint Allows HelloTriangleColored to boot --- lib/display/Stage3D.ts | 17 ++++--- lib/display3D/Context3D.ts | 28 +++++------ lib/display3D/Context3DBlendFactor.ts | 43 +++++++++++++++++ lib/display3D/Context3DClearMask.ts | 7 ++- lib/display3D/Context3DCompareMode.ts | 48 +++++++++++++++++++ lib/display3D/Context3DProfile.ts | 7 ++- lib/display3D/Context3DProgramType.ts | 7 ++- lib/display3D/Context3DRenderMode.ts | 7 ++- lib/display3D/Context3DStencilAction.ts | 48 +++++++++++++++++++ lib/display3D/Context3DTextureFormat.ts | 43 +++++++++++++++++ lib/display3D/Context3DTriangleFace.ts | 44 +++++++++++++++++ .../Context3DVertexBufferFormat copy.ts | 45 +++++++++++++++++ lib/display3D/Context3DVertexBufferFormat.ts | 7 ++- lib/display3D/IndexBuffer3D.ts | 9 ++-- lib/display3D/Program3D.ts | 4 +- lib/display3D/VertexBuffer3D.ts | 14 +++--- lib/display3D/textures/CubeTexture.ts | 44 +++++++++++++++++ lib/display3D/{ => textures}/Texture.ts | 10 ++-- lib/display3D/textures/TextureBase.ts | 32 +++++++++++++ 19 files changed, 417 insertions(+), 47 deletions(-) create mode 100644 lib/display3D/Context3DBlendFactor.ts create mode 100644 lib/display3D/Context3DCompareMode.ts create mode 100644 lib/display3D/Context3DStencilAction.ts create mode 100644 lib/display3D/Context3DTextureFormat.ts create mode 100644 lib/display3D/Context3DTriangleFace.ts create mode 100644 lib/display3D/Context3DVertexBufferFormat copy.ts create mode 100644 lib/display3D/textures/CubeTexture.ts rename lib/display3D/{ => textures}/Texture.ts (78%) create mode 100644 lib/display3D/textures/TextureBase.ts diff --git a/lib/display/Stage3D.ts b/lib/display/Stage3D.ts index c1bae309..b7a4ff7d 100644 --- a/lib/display/Stage3D.ts +++ b/lib/display/Stage3D.ts @@ -9,7 +9,6 @@ import { Event } from '../events/Event'; import { SecurityDomain } from '../SecurityDomain'; export class Stage3D extends EventDispatcher { - static axClass: typeof Stage3D & AXClass; // Called whenever the class is initialized. public static classInitializer: any = null; @@ -23,17 +22,17 @@ export class Stage3D extends EventDispatcher { private _x: number private _y: number private _id: number - private _adaptee:AwayStage + private _adaptee: AwayStage constructor(i) { - super() - console.log("Stage3D Constructor") + super(); + console.log('Stage3D Constructor'); this._adaptee = AVMStage.instance().stage3Ds[i]; - this._id = i + this._id = i; } - public get adaptee(): AwayStage{ - return this._adaptee + public get adaptee(): AwayStage { + return this._adaptee; } public get x(): number { @@ -72,9 +71,9 @@ export class Stage3D extends EventDispatcher { public requestContext3D(context3DRenderMode: string = 'auto', profile: string = 'baseline'): void { console.log('Request Context'); - this._context3D = new (this.sec as SecurityDomain).flash.display3D.Context3D(0, this, profile, context3DRenderMode ); + this._context3D = new (this.sec as SecurityDomain).flash.display3D.Context3D(0, this, profile, context3DRenderMode); const forceSoftware: boolean = (context3DRenderMode == 'auto'); - var awayContextProfile:ContextGLProfile + let awayContextProfile: ContextGLProfile; switch (profile) { case 'baseline': awayContextProfile = ContextGLProfile.BASELINE; diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index d52a94ec..bca62925 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -1,5 +1,5 @@ -import { ContextGLDrawMode, ContextGLProfile, ContextGLProgramType, ContextGLVertexBufferFormat, - ContextWebGL, ProgramWebGL, Stage as AwayStage, StageEvent } from '@awayjs/stage'; +import { ContextGLDrawMode, ContextGLProfile, ContextGLProgramType, ContextGLVertexBufferFormat, + ContextWebGL, IndexBufferWebGL, ProgramWebGL, Stage as AwayStage, StageEvent } from '@awayjs/stage'; import { BitmapData } from '../display/BitmapData'; import { Stage3D } from '../display/Stage3D'; import { Context3DProgramType } from '../display3D/Context3DProgramType'; @@ -33,17 +33,17 @@ export class Context3D extends EventDispatcher { private _stage3D: Stage3D constructor(id: number, stage3D: Stage3D, renderMode: string = 'auto', profile: string = 'baseline') { - super() + super(); console.log('Context3D Create'); - this._renderMode = renderMode - this._profile = profile - this._stage3D = stage3D - this._adaptee = stage3D.adaptee + this._renderMode = renderMode; + this._profile = profile; + this._stage3D = stage3D; + this._adaptee = stage3D.adaptee; console.log(stage3D); } - public get adaptee():AwayStage { - return this._adaptee + public get adaptee(): AwayStage { + return this._adaptee; } /*private _onAwayContextCreatedDelegate(e: StageEvent): void { @@ -85,7 +85,7 @@ export class Context3D extends EventDispatcher { public drawTriangles(indexBuffer: IndexBuffer3D, firstIndex: number = 0, numTriangles: number = -1): void { // @todo: This is not working - this._adaptee.context.drawIndices(ContextGLDrawMode.TRIANGLES, indexBuffer._adaptee, firstIndex, (numTriangles == -1) ? -1 : (numTriangles * 3)) + this._adaptee.context.drawIndices(ContextGLDrawMode.TRIANGLES, indexBuffer._adaptee, firstIndex, (numTriangles == -1) ? -1 : (numTriangles * 3)); } public present(): void { @@ -102,7 +102,7 @@ export class Context3D extends EventDispatcher { } public setProgramConstantsFromMatrix(programType: string, firstRegister: number, matrix: Matrix3D, transposedMatrix: boolean = false): void { - let awayProgramType:ContextGLProgramType + let awayProgramType: ContextGLProgramType; switch (programType) { case Context3DProgramType.FRAGMENT: awayProgramType = ContextGLProgramType.FRAGMENT; @@ -122,7 +122,7 @@ export class Context3D extends EventDispatcher { } public setVertexBufferAt(index: number, buffer: VertexBuffer3D, bufferOffset: number = 0, format: string = 'float4'): void { - let awayFormat:number + let awayFormat: number; switch (format) { case Context3DVertexBufferFormat.BYTES_4: awayFormat = ContextGLVertexBufferFormat.BYTE_4; @@ -142,7 +142,7 @@ export class Context3D extends EventDispatcher { default: break; } - this._adaptee.context.setVertexBufferAt(index, buffer._adaptee, bufferOffset, awayFormat); + this._adaptee.context.setVertexBufferAt(index, buffer._adaptee, bufferOffset * 4, awayFormat); } public setBlendFactors(sourceFactor: string, destinationFactor: string): void { @@ -174,7 +174,7 @@ export class Context3D extends EventDispatcher { } public createVertexBuffer(numVertices: number, data32PerVertex: number, bufferUsage: string = 'staticDraw'): VertexBuffer3D { - console.log("createVertexBuffer") + console.log('createVertexBuffer'); return new (this.sec as SecurityDomain).flash.display3D.VertexBuffer3D(this, numVertices, data32PerVertex); } diff --git a/lib/display3D/Context3DBlendFactor.ts b/lib/display3D/Context3DBlendFactor.ts new file mode 100644 index 00000000..27e78a97 --- /dev/null +++ b/lib/display3D/Context3DBlendFactor.ts @@ -0,0 +1,43 @@ +/** + * Copyright 2014 Mozilla Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { ASObject } from '@awayfl/avm2'; + +// Class: Context3DBlendFactor +export class Context3DBlendFactor extends ASObject { + + // Called whenever the class is initialized. + public static classInitializer: any = null; + + constructor () { + super(); + } + + // JS -> AS Bindings + public static ONE: string = 'one'; + public static ZERO: string = 'zero'; + public static SOURCE_ALPHA: string = 'sourceAlpha'; + public static SOURCE_COLOR: string = 'sourceColor'; + public static ONE_MINUS_SOURCE_ALPHA: string = 'oneMinusSourceAlpha'; + public static ONE_MINUS_SOURCE_COLOR: string = 'oneMinusSourceColor'; + public static DESTINATION_ALPHA: string = 'destinationAlpha'; + public static DESTINATION_COLOR: string = 'destinationColor'; + public static ONE_MINUS_DESTINATION_ALPHA: string = 'oneMinusDestinationAlpha'; + public static ONE_MINUS_DESTINATION_COLOR: string = 'oneMinusDestinationColor'; + + // AS -> JS Bindings + +} diff --git a/lib/display3D/Context3DClearMask.ts b/lib/display3D/Context3DClearMask.ts index c78a2320..a6c0aa92 100644 --- a/lib/display3D/Context3DClearMask.ts +++ b/lib/display3D/Context3DClearMask.ts @@ -1,5 +1,10 @@ +import { ASObject } from '@awayfl/avm2'; + // Based on https://github.com/ruffle-rs/ruffle/blob/master/core/src/avm2/globals/flash/display3D/Context3DClearMask.as -export class Context3DClearMask { +export class Context3DClearMask extends ASObject { + + // Called whenever the class is initialized. + public static classInitializer: any = null; // Clear only the color buffer. public static COLOR: number = 1 << 0; diff --git a/lib/display3D/Context3DCompareMode.ts b/lib/display3D/Context3DCompareMode.ts new file mode 100644 index 00000000..6557254a --- /dev/null +++ b/lib/display3D/Context3DCompareMode.ts @@ -0,0 +1,48 @@ +/** + * Copyright 2014 Mozilla Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Class: Context3DCompareMode +module Shumway.AVMX.AS.flash.display3D { + import notImplemented = Shumway.Debug.notImplemented; + import axCoerceString = Shumway.AVMX.axCoerceString; + export class Context3DCompareMode extends ASObject { + + // Called whenever the class is initialized. + static classInitializer: any = null; + + // List of static symbols to link. + static classSymbols: string [] = null; // []; + + // List of instance symbols to link. + static instanceSymbols: string [] = null; // []; + + constructor () { + super(); + } + + // JS -> AS Bindings + static ALWAYS: string = 'always'; + static NEVER: string = 'never'; + static LESS: string = 'less'; + static LESS_EQUAL: string = 'lessEqual'; + static EQUAL: string = 'equal'; + static GREATER_EQUAL: string = 'greaterEqual'; + static GREATER: string = 'greater'; + static NOT_EQUAL: string = 'notEqual'; + + // AS -> JS Bindings + + } +} diff --git a/lib/display3D/Context3DProfile.ts b/lib/display3D/Context3DProfile.ts index ce09c93d..6c1f62bc 100644 --- a/lib/display3D/Context3DProfile.ts +++ b/lib/display3D/Context3DProfile.ts @@ -1,4 +1,9 @@ -export class Context3DProfile { +import { ASObject } from '@awayfl/avm2'; + +export class Context3DProfile extends ASObject { + // Called whenever the class is initialized. + public static classInitializer: any = null; + public static BASELINE: string = 'baseline'; public static BASELINE_CONSTRAINED: string = 'baselineConstrained'; public static BASELINE_EXTENDED: string = 'baselineExtended'; diff --git a/lib/display3D/Context3DProgramType.ts b/lib/display3D/Context3DProgramType.ts index 74067626..d59de964 100644 --- a/lib/display3D/Context3DProgramType.ts +++ b/lib/display3D/Context3DProgramType.ts @@ -1,4 +1,9 @@ -export class Context3DProgramType { +import { ASObject } from '@awayfl/avm2'; + +export class Context3DProgramType extends ASObject { + // Called whenever the class is initialized. + public static classInitializer: any = null; + public static FRAGMENT: string = 'fragment'; public static VERTEX = 'vertex'; } \ No newline at end of file diff --git a/lib/display3D/Context3DRenderMode.ts b/lib/display3D/Context3DRenderMode.ts index 364f974b..c0e45372 100644 --- a/lib/display3D/Context3DRenderMode.ts +++ b/lib/display3D/Context3DRenderMode.ts @@ -1,4 +1,9 @@ -export class Context3DRenderMode { +import { ASObject } from '@awayfl/avm2'; + +export class Context3DRenderMode extends ASObject { + // Called whenever the class is initialized. + public static classInitializer: any = null; + public static AUTO: string = 'auto'; public static SOFTWARE: string = 'software'; } \ No newline at end of file diff --git a/lib/display3D/Context3DStencilAction.ts b/lib/display3D/Context3DStencilAction.ts new file mode 100644 index 00000000..efaddc53 --- /dev/null +++ b/lib/display3D/Context3DStencilAction.ts @@ -0,0 +1,48 @@ +/** + * Copyright 2014 Mozilla Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Class: Context3DStencilAction +module Shumway.AVMX.AS.flash.display3D { + import notImplemented = Shumway.Debug.notImplemented; + import axCoerceString = Shumway.AVMX.axCoerceString; + export class Context3DStencilAction extends ASObject { + + // Called whenever the class is initialized. + static classInitializer: any = null; + + // List of static symbols to link. + static classSymbols: string [] = null; // []; + + // List of instance symbols to link. + static instanceSymbols: string [] = null; // []; + + constructor () { + super(); + } + + // JS -> AS Bindings + static KEEP: string = 'keep'; + static ZERO: string = 'zero'; + static INCREMENT_SATURATE: string = 'incrementSaturate'; + static DECREMENT_SATURATE: string = 'decrementSaturate'; + static INVERT: string = 'invert'; + static INCREMENT_WRAP: string = 'incrementWrap'; + static DECREMENT_WRAP: string = 'decrementWrap'; + static SET: string = 'set'; + + // AS -> JS Bindings + + } +} diff --git a/lib/display3D/Context3DTextureFormat.ts b/lib/display3D/Context3DTextureFormat.ts new file mode 100644 index 00000000..01b4b134 --- /dev/null +++ b/lib/display3D/Context3DTextureFormat.ts @@ -0,0 +1,43 @@ +/** + * Copyright 2014 Mozilla Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Class: Context3DTextureFormat +module Shumway.AVMX.AS.flash.display3D { + import notImplemented = Shumway.Debug.notImplemented; + import axCoerceString = Shumway.AVMX.axCoerceString; + export class Context3DTextureFormat extends ASObject { + + // Called whenever the class is initialized. + static classInitializer: any = null; + + // List of static symbols to link. + static classSymbols: string [] = null; // []; + + // List of instance symbols to link. + static instanceSymbols: string [] = null; // []; + + constructor () { + super(); + } + + // JS -> AS Bindings + static BGRA: string = 'bgra'; + static COMPRESSED: string = 'compressed'; + static COMPRESSED_ALPHA: string = 'compressedAlpha'; + + // AS -> JS Bindings + + } +} diff --git a/lib/display3D/Context3DTriangleFace.ts b/lib/display3D/Context3DTriangleFace.ts new file mode 100644 index 00000000..12a937f0 --- /dev/null +++ b/lib/display3D/Context3DTriangleFace.ts @@ -0,0 +1,44 @@ +/** + * Copyright 2014 Mozilla Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Class: Context3DTriangleFace +module Shumway.AVMX.AS.flash.display3D { + import notImplemented = Shumway.Debug.notImplemented; + import axCoerceString = Shumway.AVMX.axCoerceString; + export class Context3DTriangleFace extends ASObject { + + // Called whenever the class is initialized. + static classInitializer: any = null; + + // List of static symbols to link. + static classSymbols: string [] = null; // []; + + // List of instance symbols to link. + static instanceSymbols: string [] = null; // []; + + constructor () { + super(); + } + + // JS -> AS Bindings + static NONE: string = 'none'; + static BACK: string = 'back'; + static FRONT: string = 'front'; + static FRONT_AND_BACK: string = 'frontAndBack'; + + // AS -> JS Bindings + + } +} diff --git a/lib/display3D/Context3DVertexBufferFormat copy.ts b/lib/display3D/Context3DVertexBufferFormat copy.ts new file mode 100644 index 00000000..cd772aca --- /dev/null +++ b/lib/display3D/Context3DVertexBufferFormat copy.ts @@ -0,0 +1,45 @@ +/** + * Copyright 2014 Mozilla Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Class: Context3DVertexBufferFormat +module Shumway.AVMX.AS.flash.display3D { + import notImplemented = Shumway.Debug.notImplemented; + import axCoerceString = Shumway.AVMX.axCoerceString; + export class Context3DVertexBufferFormat extends ASObject { + + // Called whenever the class is initialized. + static classInitializer: any = null; + + // List of static symbols to link. + static classSymbols: string [] = null; // []; + + // List of instance symbols to link. + static instanceSymbols: string [] = null; // []; + + constructor () { + super(); + } + + // JS -> AS Bindings + static FLOAT_1: string = 'float1'; + static FLOAT_2: string = 'float2'; + static FLOAT_3: string = 'float3'; + static FLOAT_4: string = 'float4'; + static BYTES_4: string = 'bytes4'; + + // AS -> JS Bindings + + } +} diff --git a/lib/display3D/Context3DVertexBufferFormat.ts b/lib/display3D/Context3DVertexBufferFormat.ts index cd53ef93..f5d1e82f 100644 --- a/lib/display3D/Context3DVertexBufferFormat.ts +++ b/lib/display3D/Context3DVertexBufferFormat.ts @@ -1,4 +1,9 @@ -export class Context3DVertexBufferFormat { +import { ASObject } from '@awayfl/avm2'; + +export class Context3DVertexBufferFormat extends ASObject { + // Called whenever the class is initialized. + public static classInitializer: any = null; + public static BYTES_4: string = 'bytes4'; public static FLOAT_1: string = 'float1'; public static FLOAT_2: string = 'float2'; diff --git a/lib/display3D/IndexBuffer3D.ts b/lib/display3D/IndexBuffer3D.ts index 987c8bb2..270207b9 100644 --- a/lib/display3D/IndexBuffer3D.ts +++ b/lib/display3D/IndexBuffer3D.ts @@ -1,6 +1,6 @@ import { ASObject, AXClass, Uint32Vector } from '@awayfl/avm2'; import { Debug } from '@awayfl/swf-loader'; -import { ByteArray } from '../utils/ByteArray' +import { ByteArray } from '../utils/ByteArray'; import { IContextGL, IIndexBuffer } from '@awayjs/stage'; import { Context3D } from './Context3D'; @@ -18,11 +18,10 @@ export class IndexBuffer3D extends ASObject { } public uploadFromVector(data: Uint32Vector, startOffset: number, count: number): void { - let uint16ArrayData = new Uint16Array(data.length); + const uint16ArrayData = new Uint16Array(data.length); for (let i: number = 0; i < data.length; i++) { - uint16ArrayData[i] = data.axGetNumericProperty(i);; + uint16ArrayData[i] = data.axGetNumericProperty(i); } - console.log(uint16ArrayData) this._adaptee.uploadFromArray(uint16ArrayData, startOffset, count); } @@ -31,7 +30,7 @@ export class IndexBuffer3D extends ASObject { } public dispose(): void { - this._adaptee.dispose() + this._adaptee.dispose(); } } \ No newline at end of file diff --git a/lib/display3D/Program3D.ts b/lib/display3D/Program3D.ts index 48b619f5..00c44a59 100644 --- a/lib/display3D/Program3D.ts +++ b/lib/display3D/Program3D.ts @@ -15,7 +15,7 @@ export class Program3D extends ASObject { constructor(context3D: Context3D) { super(); - this._context = context3D.adaptee.context + this._context = context3D.adaptee.context; this._adaptee = context3D.adaptee.context.createProgram(); } @@ -25,6 +25,6 @@ export class Program3D extends ASObject { public upload(vertexProgram: ByteArray, fragmentProgram: ByteArray): void { this._adaptee.upload(vertexProgram, fragmentProgram); - this._context.setProgram(this._adaptee) + this._context.setProgram(this._adaptee); } } \ No newline at end of file diff --git a/lib/display3D/VertexBuffer3D.ts b/lib/display3D/VertexBuffer3D.ts index 616b1184..c053b103 100644 --- a/lib/display3D/VertexBuffer3D.ts +++ b/lib/display3D/VertexBuffer3D.ts @@ -1,6 +1,6 @@ import { ASObject, AXClass, Float64Vector } from '@awayfl/avm2'; import { Debug } from '@awayfl/swf-loader'; -import { ByteArray } from '../utils/ByteArray' +import { ByteArray } from '../utils/ByteArray'; import { IContextGL, IVertexBuffer, VertexBufferWebGL } from '@awayjs/stage'; import { Context3D } from './Context3D'; @@ -10,19 +10,17 @@ export class VertexBuffer3D extends ASObject { static classSymbols: string [] = null; // []; static instanceSymbols: string [] = null; public _adaptee: IVertexBuffer - - constructor(context3D: Context3D, numVertices, dataPerVertex) { - super() - this._adaptee = context3D.adaptee.context.createVertexBuffer(numVertices, dataPerVertex); - } + constructor(context3D: Context3D, numVertices: number, data32PerVertex: number) { + super(); + this._adaptee = context3D.adaptee.context.createVertexBuffer(numVertices, data32PerVertex * 4); + } public uploadFromVector(data: Float64Vector, startVertex: number, numVertices) { - let dataFloat32Array: Float32Array = new Float32Array(data.length); + const dataFloat32Array: Float32Array = new Float32Array(data.length); for (let i: number = 0; i < data.length; i++) { dataFloat32Array[i] = data.axGetNumericProperty(i); } - console.log(dataFloat32Array) this._adaptee.uploadFromArray(dataFloat32Array, startVertex, numVertices); } diff --git a/lib/display3D/textures/CubeTexture.ts b/lib/display3D/textures/CubeTexture.ts new file mode 100644 index 00000000..43384d34 --- /dev/null +++ b/lib/display3D/textures/CubeTexture.ts @@ -0,0 +1,44 @@ +/** + * Copyright 2014 Mozilla Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Class: CubeTexture +import { Debug } from '@awayfl/swf-loader'; +import { ByteArray } from './../../utils/ByteArray'; +import { BitmapData } from './../../display/BitmapData'; +import { TextureBase } from './TextureBase'; +export class CubeTexture extends TextureBase { + + // Called whenever the class is initialized. + static classInitializer: any = null; + + constructor () { + super(); + } + + uploadFromBitmapData(source: BitmapData, side: number /*uint*/, miplevel: number /*uint*/ = 0): void { + source = source; side = side >>> 0; miplevel = miplevel >>> 0; + Debug.notImplemented('public flash.display3D.textures.CubeTexture::uploadFromBitmapData'); return; + } + + uploadFromByteArray(data: ByteArray, byteArrayOffset: number /*uint*/, side: number /*uint*/, miplevel: number /*uint*/ = 0): void { + data = data; byteArrayOffset = byteArrayOffset >>> 0; side = side >>> 0; miplevel = miplevel >>> 0; + Debug.notImplemented('public flash.display3D.textures.CubeTexture::uploadFromByteArray'); return; + } + + uploadCompressedTextureFromByteArray(data: ByteArray, byteArrayOffset: number /*uint*/, async: boolean = false): void { + data = data; byteArrayOffset = byteArrayOffset >>> 0; async = !!async; + Debug.notImplemented('public flash.display3D.textures.CubeTexture::uploadCompressedTextureFromByteArray'); return; + } +} diff --git a/lib/display3D/Texture.ts b/lib/display3D/textures/Texture.ts similarity index 78% rename from lib/display3D/Texture.ts rename to lib/display3D/textures/Texture.ts index be3d1019..54d3a06e 100644 --- a/lib/display3D/Texture.ts +++ b/lib/display3D/textures/Texture.ts @@ -1,15 +1,17 @@ -import { BitmapData } from './../display/BitmapData'; -import { ByteArray } from './../utils/ByteArray'; -export class Texture { +import { TextureBase } from '@awayjs/renderer'; +import { BitmapData } from './../../display/BitmapData'; +import { ByteArray } from './../../utils/ByteArray'; +export class Texture extends TextureBase { // todo. can probably route directly to awayjs class public static fromBitmapData(bitmapData: BitmapData): Texture { console.warn('[playerglobal/display3D/Texture] - fromBitmapData not implemented'); - return null; + return; } constructor () { + super() } public uploadCompressedTextureFromByteArray (data: ByteArray, byteArrayOffset: number, async: boolean = false) { diff --git a/lib/display3D/textures/TextureBase.ts b/lib/display3D/textures/TextureBase.ts new file mode 100644 index 00000000..eea13a87 --- /dev/null +++ b/lib/display3D/textures/TextureBase.ts @@ -0,0 +1,32 @@ +/** + * Copyright 2014 Mozilla Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Debug } from '@awayfl/swf-loader'; +import { EventDispatcher } from '@awayjs/core'; + +export class TextureBase extends EventDispatcher { + + // Called whenever the class is initialized. + static classInitializer: any = null; + + constructor () { + super(); + } + + dispose(): void { + Debug.notImplemented('public flash.display3D.textures.TextureBase::dispose'); return; + } +} From 8bf2f0bdd232983def103f2c01443f718cf04742 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Mon, 16 Sep 2024 21:48:26 +0000 Subject: [PATCH 20/59] Add Missing classes from shumway and temp fix for setProgramConstantsFromMatrix --- lib/display/Stage3D.ts | 9 ++-- lib/display3D/Context3D.ts | 7 ++-- lib/display3D/IndexBuffer3D.ts | 2 +- lib/display3D/Program3D.ts | 3 +- lib/display3D/VertexBuffer3D.ts | 2 +- lib/display3D/textures/CubeTexture.ts | 5 ++- lib/display3D/textures/Texture.ts | 23 +++++------ lib/display3D/textures/TextureBase.ts | 4 +- lib/link.ts | 59 +++++++++++++++------------ 9 files changed, 58 insertions(+), 56 deletions(-) diff --git a/lib/display/Stage3D.ts b/lib/display/Stage3D.ts index b7a4ff7d..63e596cb 100644 --- a/lib/display/Stage3D.ts +++ b/lib/display/Stage3D.ts @@ -1,11 +1,8 @@ -import { ContextGLProfile, ContextMode, Stage as AwayStage, Stage, StageManager } from '@awayjs/stage'; -import { EventDispatcher } from '../events/EventDispatcher'; -import { Context3D } from '../display3D/Context3D'; -import { Context3DProfile } from '../display3D/Context3DProfile'; import { AVMStage, Debug } from '@awayfl/swf-loader'; -import { Bytecode } from '@awayfl/avm2/lib/Bytecode'; -import { AXClass, Multiname } from '@awayfl/avm2'; +import { ContextGLProfile, Stage as AwayStage } from '@awayjs/stage'; +import { Context3D } from '../display3D/Context3D'; import { Event } from '../events/Event'; +import { EventDispatcher } from '../events/EventDispatcher'; import { SecurityDomain } from '../SecurityDomain'; export class Stage3D extends EventDispatcher { diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index bca62925..ffd48c49 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -1,5 +1,4 @@ -import { ContextGLDrawMode, ContextGLProfile, ContextGLProgramType, ContextGLVertexBufferFormat, - ContextWebGL, IndexBufferWebGL, ProgramWebGL, Stage as AwayStage, StageEvent } from '@awayjs/stage'; +import { ContextGLDrawMode, ContextGLProgramType, ContextGLVertexBufferFormat, ProgramWebGL, Stage as AwayStage } from '@awayjs/stage'; import { BitmapData } from '../display/BitmapData'; import { Stage3D } from '../display/Stage3D'; import { Context3DProgramType } from '../display3D/Context3DProgramType'; @@ -12,8 +11,8 @@ import { Matrix3D } from '../geom/Matrix3D'; import { Rectangle } from '../geom/Rectangle'; import { ByteArray } from '../utils/ByteArray'; -import { AXClass, Float64Vector } from '@awayfl/avm2'; -import { AVMStage, Debug } from '@awayfl/swf-loader'; +import { Float64Vector } from '@awayfl/avm2'; +import { Debug } from '@awayfl/swf-loader'; import { SecurityDomain } from '../SecurityDomain'; export class Context3D extends EventDispatcher { diff --git a/lib/display3D/IndexBuffer3D.ts b/lib/display3D/IndexBuffer3D.ts index 270207b9..f69b2168 100644 --- a/lib/display3D/IndexBuffer3D.ts +++ b/lib/display3D/IndexBuffer3D.ts @@ -1,7 +1,7 @@ import { ASObject, AXClass, Uint32Vector } from '@awayfl/avm2'; import { Debug } from '@awayfl/swf-loader'; +import { IIndexBuffer } from '@awayjs/stage'; import { ByteArray } from '../utils/ByteArray'; -import { IContextGL, IIndexBuffer } from '@awayjs/stage'; import { Context3D } from './Context3D'; export class IndexBuffer3D extends ASObject { diff --git a/lib/display3D/Program3D.ts b/lib/display3D/Program3D.ts index 00c44a59..7623228c 100644 --- a/lib/display3D/Program3D.ts +++ b/lib/display3D/Program3D.ts @@ -1,6 +1,5 @@ import { ASObject, AXClass } from '@awayfl/avm2'; -import { ByteArray as AwayByteArray } from '@awayjs/core'; -import { IContextGL, IProgram, ProgramWebGL } from '@awayjs/stage'; +import { IContextGL, IProgram } from '@awayjs/stage'; import { ByteArray } from '../utils/ByteArray'; import { Context3D } from './Context3D'; diff --git a/lib/display3D/VertexBuffer3D.ts b/lib/display3D/VertexBuffer3D.ts index c053b103..f4b51199 100644 --- a/lib/display3D/VertexBuffer3D.ts +++ b/lib/display3D/VertexBuffer3D.ts @@ -1,7 +1,7 @@ import { ASObject, AXClass, Float64Vector } from '@awayfl/avm2'; import { Debug } from '@awayfl/swf-loader'; +import { IVertexBuffer } from '@awayjs/stage'; import { ByteArray } from '../utils/ByteArray'; -import { IContextGL, IVertexBuffer, VertexBufferWebGL } from '@awayjs/stage'; import { Context3D } from './Context3D'; export class VertexBuffer3D extends ASObject { diff --git a/lib/display3D/textures/CubeTexture.ts b/lib/display3D/textures/CubeTexture.ts index 43384d34..8c066f96 100644 --- a/lib/display3D/textures/CubeTexture.ts +++ b/lib/display3D/textures/CubeTexture.ts @@ -15,15 +15,16 @@ */ // Class: CubeTexture import { Debug } from '@awayfl/swf-loader'; -import { ByteArray } from './../../utils/ByteArray'; import { BitmapData } from './../../display/BitmapData'; +import { ByteArray } from './../../utils/ByteArray'; import { TextureBase } from './TextureBase'; + export class CubeTexture extends TextureBase { // Called whenever the class is initialized. static classInitializer: any = null; - constructor () { + constructor() { super(); } diff --git a/lib/display3D/textures/Texture.ts b/lib/display3D/textures/Texture.ts index 54d3a06e..7c47f42e 100644 --- a/lib/display3D/textures/Texture.ts +++ b/lib/display3D/textures/Texture.ts @@ -1,31 +1,30 @@ -import { TextureBase } from '@awayjs/renderer'; +import { Debug } from '@awayfl/swf-loader'; +import { TextureWebGL } from '@awayjs/stage'; import { BitmapData } from './../../display/BitmapData'; import { ByteArray } from './../../utils/ByteArray'; +import { TextureBase } from './TextureBase'; export class Texture extends TextureBase { + public _adaptee: TextureWebGL; - // todo. can probably route directly to awayjs class - - public static fromBitmapData(bitmapData: BitmapData): Texture { - console.warn('[playerglobal/display3D/Texture] - fromBitmapData not implemented'); - return; - } - - constructor () { + constructor() { super() + Debug.notImplemented('public flash.display3D.textures.Texture::Texture'); return; + + } public uploadCompressedTextureFromByteArray (data: ByteArray, byteArrayOffset: number, async: boolean = false) { - console.warn('[playerglobal/display3D/Texture] - uploadCompressedTextureFromByteArray not implemented'); + Debug.notImplemented('public flash.display3D.textures.Texture::uploadCompressedTextureFromByteArray'); } public uploadFromBitmapData (source: BitmapData, miplevel: number = 0) { - console.warn('[playerglobal/display3D/Texture] - uploadFromBitmapData not implemented'); + Debug.notImplemented('public flash.display3D.textures.Texture::uploadFromBitmapData'); } public uploadFromByteArray (data: ByteArray, byteArrayOffset: number, miplevel: number = 0) { - console.warn('[playerglobal/display3D/Texture] - uploadFromByteArray not implemented'); + Debug.notImplemented('public flash.display3D.textures.Texture::uploadFromByteArray'); } } diff --git a/lib/display3D/textures/TextureBase.ts b/lib/display3D/textures/TextureBase.ts index eea13a87..787418ef 100644 --- a/lib/display3D/textures/TextureBase.ts +++ b/lib/display3D/textures/TextureBase.ts @@ -26,7 +26,7 @@ export class TextureBase extends EventDispatcher { super(); } - dispose(): void { - Debug.notImplemented('public flash.display3D.textures.TextureBase::dispose'); return; + public dispose(): void { + Debug.notImplemented('public flash.display3D.textures.TextureBase::dispose') } } diff --git a/lib/link.ts b/lib/link.ts index 449ce412..18c21fcd 100644 --- a/lib/link.ts +++ b/lib/link.ts @@ -37,6 +37,10 @@ import { IndexBuffer3D } from './display3D/IndexBuffer3D'; import { Program3D } from './display3D/Program3D'; import { VertexBuffer3D } from './display3D/VertexBuffer3D'; +import { CubeTexture } from './display3D/textures/CubeTexture'; +import { Texture } from './display3D/textures/Texture'; +import { TextureBase } from './display3D/textures/TextureBase'; + import { EOFError } from './errors/EOFError'; import { IllegalOperationError } from './errors/IllegalOperationError'; import { InvalidSWFError } from './errors/InvalidSWFError'; @@ -61,8 +65,8 @@ import { AsyncErrorEvent } from './events/AsyncErrorEvent'; import { ContextMenuEvent } from './events/ContextMenuEvent'; import { DataEvent } from './events/DataEvent'; import { ErrorEvent } from './events/ErrorEvent'; -import { EventDispatcher } from './events/EventDispatcher'; import { Event } from './events/Event'; +import { EventDispatcher } from './events/EventDispatcher'; import { EventPhase } from './events/EventPhase'; import { FocusEvent } from './events/FocusEvent'; import { FullScreenEvent } from './events/FullScreenEvent'; @@ -115,42 +119,42 @@ import { NumberFormatter } from './globalization/NumberFormatter'; import { Sound } from './media/Sound'; import { SoundChannel } from './media/SoundChannel'; -import { SoundTransform } from './media/SoundTransform'; import { SoundMixer } from './media/SoundMixer'; +import { SoundTransform } from './media/SoundTransform'; import { FileFilter } from './net/FileFilter'; import { FileReference } from './net/FileReference'; -import { SharedObject } from './net/SharedObject'; -import { URLRequest } from './net/URLRequest'; -import { URLLoader } from './net/URLLoader'; -import { URLVariables } from './net/URLVariables'; import { LocalConnection } from './net/LocalConnection'; import { NetConnection } from './net/NetConnection'; import { Responder } from './net/Responder'; import { Socket } from './net/Socket'; +import { SharedObject } from './net/SharedObject'; +import { URLLoader } from './net/URLLoader'; +import { URLRequest } from './net/URLRequest'; +import { URLVariables } from './net/URLVariables'; -import { SecurityDomain } from './system/SecurityDomain'; +import { ApplicationDomain } from './system/ApplicationDomain'; import { Capabilities } from './system/Capabilities'; import { fscommand } from './system/FSCommand'; -import { Security } from './system/Security'; import { LoaderContext } from './system/LoaderContext'; -import { ApplicationDomain } from './system/ApplicationDomain'; +import { Security } from './system/Security'; +import { SecurityDomain } from './system/SecurityDomain'; import { System } from './system/System'; +import { CSMSettings } from './text/CSMSettings'; import { Font } from './text/Font'; +import { FontType } from './text/FontType'; +import { StaticText } from './text/StaticText'; import { StyleSheet } from './text/StyleSheet'; +import { TextColorType } from './text/TextColorType'; +import { TextDisplayMode } from './text/TextDisplayMode'; +import { TextExtent } from './text/TextExtent'; import { TextField } from './text/TextField'; import { TextFormat } from './text/TextFormat'; -import { TextRun } from './text/TextRun'; -import { StaticText } from './text/StaticText'; -import { TextRenderer } from './text/TextRenderer'; import { TextFormatDisplay } from './text/TextFormatDisplay'; -import { TextExtent } from './text/TextExtent'; -import { TextDisplayMode } from './text/TextDisplayMode'; -import { TextColorType } from './text/TextColorType'; -import { FontType } from './text/FontType'; -import { CSMSettings } from './text/CSMSettings'; import { TextLineMetrics } from './text/TextLineMetrics'; +import { TextRenderer } from './text/TextRenderer'; +import { TextRun } from './text/TextRun'; import { TextSnapshot } from './text/TextSnapshot'; import { CompositionAttributeRange } from './text/ime/CompositionAttributeRange'; @@ -188,27 +192,26 @@ import { TextLineValidity } from './text/engine/TextLineValidity'; import { TextRotation } from './text/engine/TextRotation'; import { TypographicCase } from './text/engine/TypographicCase'; -import { Keyboard } from './ui/Keyboard'; +import { ASClass, ByteArray, registerNativeClass, registerNativeFunction, XMLDocument, XMLNode } from '@awayfl/avm2'; +import { release } from '@awayfl/swf-loader'; +import { BlendMode } from '@awayjs/stage'; +import { GroupElement } from './text/engine/GroupElement'; import { ContextMenu } from './ui/ContextMenu'; -import { ContextMenuItem } from './ui/ContextMenuItem'; import { ContextMenuBuiltInItems } from './ui/ContextMenuBuiltInItems'; import { ContextMenuClipboardItems } from './ui/ContextMenuClipboardItems'; +import { ContextMenuItem } from './ui/ContextMenuItem'; import { GameInput } from './ui/GameInput'; import { GameInputControl } from './ui/GameInputControl'; import { GameInputControlType } from './ui/GameInputControlType'; import { GameInputDevice } from './ui/GameInputDevice'; import { GameInputFinger } from './ui/GameInputFinger'; import { GameInputHand } from './ui/GameInputHand'; +import { Keyboard } from './ui/Keyboard'; import { Mouse } from './ui/Mouse'; -import { MultitouchInputMode } from './ui/MultitouchInputMode'; import { Multitouch } from './ui/Multitouch'; -import { Timer } from './utils/Timer'; +import { MultitouchInputMode } from './ui/MultitouchInputMode'; import { CompressionAlgorithm } from './utils/CompressionAlgorithm'; -import { XMLDocument, XMLNode, ASClass, registerNativeClass, registerNativeFunction } from '@awayfl/avm2'; -import { release } from '@awayfl/swf-loader'; -import { BlendMode } from '@awayjs/stage'; -import { GroupElement } from './text/engine/GroupElement'; -import { ByteArray } from '@awayfl/avm2'; +import { Timer } from './utils/Timer'; import { BaseTextLayoutImporter, Property } from './text/engine/NativehacksForTLF'; @@ -318,6 +321,10 @@ export function initLink() { M('flash.display3D.Program3D', Program3D); M('flash.display3D.VertexBuffer3D', VertexBuffer3D); + M('flash.display3D.textures.TextureBase', TextureBase); + M('flash.display3D.textures.Texture', Texture); + M('flash.display3D.textures.CubeTexture', CubeTexture); + //M('flash.errors.DRMManagerError', DRMManagerError);//AIR M('flash.errors.EOFError', EOFError); M('flash.errors.IllegalOperationError', IllegalOperationError); From deca0b3477063283d32fa4c05a84421559c4eb00 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Mon, 16 Sep 2024 21:48:42 +0000 Subject: [PATCH 21/59] forgot to comm some changes --- lib/SecurityDomain.ts | 10 ++++- lib/display3D/Context3D.ts | 4 +- lib/display3D/Context3DCompareMode.ts | 15 ++----- lib/display3D/Context3DStencilAction.ts | 15 ++----- lib/display3D/Context3DTextureFormat.ts | 16 ++----- lib/display3D/Context3DTriangleFace.ts | 13 ++---- .../Context3DVertexBufferFormat copy.ts | 45 ------------------- lib/display3D/textures/TextureBase.ts | 2 +- lib/link.ts | 26 +++++++---- 9 files changed, 46 insertions(+), 100 deletions(-) delete mode 100644 lib/display3D/Context3DVertexBufferFormat copy.ts diff --git a/lib/SecurityDomain.ts b/lib/SecurityDomain.ts index da531f5b..7692a62b 100644 --- a/lib/SecurityDomain.ts +++ b/lib/SecurityDomain.ts @@ -82,6 +82,9 @@ import { Context3D } from './display3D/Context3D'; import { IndexBuffer3D } from './display3D/IndexBuffer3D'; import { Program3D } from './display3D/Program3D'; import { VertexBuffer3D } from './display3D/VertexBuffer3D'; +import { TextureBase } from './display3D/textures/TextureBase'; +import { Texture } from './display3D/textures/Texture'; +import { CubeTexture } from './display3D/textures/CubeTexture'; export class Mouse {} @@ -108,7 +111,12 @@ export class SecurityDomain extends AXSecurityDomain { Context3D: Context3D, IndexBuffer3D: IndexBuffer3D, Program3D: Program3D, - VertexBuffer3D: VertexBuffer3D + VertexBuffer3D: VertexBuffer3D, + textures: { + TextureBase: TextureBase, + Texture: Texture, + CubeTexture: CubeTexture, + } }, events: { EventDispatcher: EventDispatcher, diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index ffd48c49..971c47f7 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -113,7 +113,9 @@ export class Context3D extends EventDispatcher { break; } const programWebGL: ProgramWebGL = this._program._adaptee as ProgramWebGL; - programWebGL.uniformMatrix4fv(awayProgramType, transposedMatrix, matrix.adaptee._rawData); + // @todo: uniformMatrix4fv isn't working for some reason? + //programWebGL.uniformMatrix4fv(awayProgramType, transposedMatrix, matrix.adaptee._rawData); + programWebGL.uniform4fv(awayProgramType, matrix.adaptee._rawData); } public setProgramConstantsFromByteArray(programType: string, firstRegister: number /*int*/, numRegisters: number /*int*/, data: ByteArray, byteArrayOffset: number /*uint*/): void { diff --git a/lib/display3D/Context3DCompareMode.ts b/lib/display3D/Context3DCompareMode.ts index 6557254a..e5063d09 100644 --- a/lib/display3D/Context3DCompareMode.ts +++ b/lib/display3D/Context3DCompareMode.ts @@ -13,21 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -// Class: Context3DCompareMode -module Shumway.AVMX.AS.flash.display3D { - import notImplemented = Shumway.Debug.notImplemented; - import axCoerceString = Shumway.AVMX.axCoerceString; + +import { ASObject } from "@awayfl/avm2"; + export class Context3DCompareMode extends ASObject { // Called whenever the class is initialized. static classInitializer: any = null; - // List of static symbols to link. - static classSymbols: string [] = null; // []; - - // List of instance symbols to link. - static instanceSymbols: string [] = null; // []; - constructor () { super(); } @@ -45,4 +38,4 @@ module Shumway.AVMX.AS.flash.display3D { // AS -> JS Bindings } -} + diff --git a/lib/display3D/Context3DStencilAction.ts b/lib/display3D/Context3DStencilAction.ts index efaddc53..90576f56 100644 --- a/lib/display3D/Context3DStencilAction.ts +++ b/lib/display3D/Context3DStencilAction.ts @@ -13,21 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +import { ASObject } from "@awayfl/avm2"; + // Class: Context3DStencilAction -module Shumway.AVMX.AS.flash.display3D { - import notImplemented = Shumway.Debug.notImplemented; - import axCoerceString = Shumway.AVMX.axCoerceString; - export class Context3DStencilAction extends ASObject { +export class Context3DStencilAction extends ASObject { // Called whenever the class is initialized. static classInitializer: any = null; - // List of static symbols to link. - static classSymbols: string [] = null; // []; - - // List of instance symbols to link. - static instanceSymbols: string [] = null; // []; - constructor () { super(); } @@ -45,4 +39,3 @@ module Shumway.AVMX.AS.flash.display3D { // AS -> JS Bindings } -} diff --git a/lib/display3D/Context3DTextureFormat.ts b/lib/display3D/Context3DTextureFormat.ts index 01b4b134..7390d296 100644 --- a/lib/display3D/Context3DTextureFormat.ts +++ b/lib/display3D/Context3DTextureFormat.ts @@ -1,3 +1,5 @@ +import { ASObject } from "@awayfl/avm2"; + /** * Copyright 2014 Mozilla Foundation * @@ -13,21 +15,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -// Class: Context3DTextureFormat -module Shumway.AVMX.AS.flash.display3D { - import notImplemented = Shumway.Debug.notImplemented; - import axCoerceString = Shumway.AVMX.axCoerceString; export class Context3DTextureFormat extends ASObject { // Called whenever the class is initialized. static classInitializer: any = null; - - // List of static symbols to link. - static classSymbols: string [] = null; // []; - - // List of instance symbols to link. - static instanceSymbols: string [] = null; // []; - + constructor () { super(); } @@ -40,4 +32,4 @@ module Shumway.AVMX.AS.flash.display3D { // AS -> JS Bindings } -} + diff --git a/lib/display3D/Context3DTriangleFace.ts b/lib/display3D/Context3DTriangleFace.ts index 12a937f0..d6d3d7bd 100644 --- a/lib/display3D/Context3DTriangleFace.ts +++ b/lib/display3D/Context3DTriangleFace.ts @@ -14,20 +14,14 @@ * limitations under the License. */ // Class: Context3DTriangleFace -module Shumway.AVMX.AS.flash.display3D { - import notImplemented = Shumway.Debug.notImplemented; - import axCoerceString = Shumway.AVMX.axCoerceString; + +import { ASObject } from "@awayfl/avm2"; + export class Context3DTriangleFace extends ASObject { // Called whenever the class is initialized. static classInitializer: any = null; - // List of static symbols to link. - static classSymbols: string [] = null; // []; - - // List of instance symbols to link. - static instanceSymbols: string [] = null; // []; - constructor () { super(); } @@ -41,4 +35,3 @@ module Shumway.AVMX.AS.flash.display3D { // AS -> JS Bindings } -} diff --git a/lib/display3D/Context3DVertexBufferFormat copy.ts b/lib/display3D/Context3DVertexBufferFormat copy.ts deleted file mode 100644 index cd772aca..00000000 --- a/lib/display3D/Context3DVertexBufferFormat copy.ts +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright 2014 Mozilla Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// Class: Context3DVertexBufferFormat -module Shumway.AVMX.AS.flash.display3D { - import notImplemented = Shumway.Debug.notImplemented; - import axCoerceString = Shumway.AVMX.axCoerceString; - export class Context3DVertexBufferFormat extends ASObject { - - // Called whenever the class is initialized. - static classInitializer: any = null; - - // List of static symbols to link. - static classSymbols: string [] = null; // []; - - // List of instance symbols to link. - static instanceSymbols: string [] = null; // []; - - constructor () { - super(); - } - - // JS -> AS Bindings - static FLOAT_1: string = 'float1'; - static FLOAT_2: string = 'float2'; - static FLOAT_3: string = 'float3'; - static FLOAT_4: string = 'float4'; - static BYTES_4: string = 'bytes4'; - - // AS -> JS Bindings - - } -} diff --git a/lib/display3D/textures/TextureBase.ts b/lib/display3D/textures/TextureBase.ts index 787418ef..a8d329d1 100644 --- a/lib/display3D/textures/TextureBase.ts +++ b/lib/display3D/textures/TextureBase.ts @@ -15,7 +15,7 @@ */ import { Debug } from '@awayfl/swf-loader'; -import { EventDispatcher } from '@awayjs/core'; +import { EventDispatcher } from '../../events/EventDispatcher'; export class TextureBase extends EventDispatcher { diff --git a/lib/link.ts b/lib/link.ts index 18c21fcd..8c8d3750 100644 --- a/lib/link.ts +++ b/lib/link.ts @@ -28,10 +28,15 @@ import { Stage } from './display/Stage'; import { Stage3D } from './display/Stage3D'; import { Context3D } from './display3D/Context3D'; +import { Context3DBlendFactor } from './display3D/Context3DBlendFactor'; import { Context3DClearMask } from './display3D/Context3DClearMask'; +import { Context3DCompareMode } from './display3D/Context3DCompareMode'; import { Context3DProfile } from './display3D/Context3DProfile'; import { Context3DProgramType } from './display3D/Context3DProgramType'; import { Context3DRenderMode } from './display3D/Context3DRenderMode'; +import { Context3DStencilAction } from './display3D/Context3DStencilAction'; +import { Context3DTextureFormat } from './display3D/Context3DTextureFormat'; +import { Context3DTriangleFace } from './display3D/Context3DTriangleFace'; import { Context3DVertexBufferFormat } from './display3D/Context3DVertexBufferFormat'; import { IndexBuffer3D } from './display3D/IndexBuffer3D'; import { Program3D } from './display3D/Program3D'; @@ -312,18 +317,23 @@ export function initLink() { // TODO: Add display3d stuff M('flash.display3D.Context3D', Context3D); - M('flash.display3D.Context3DClearMask', Context3DClearMask); - M('flash.display3D.Context3DProfile', Context3DProfile); - M('flash.display3D.Context3DProgramType', Context3DProgramType); - M('flash.display3D.Context3DRenderMode', Context3DRenderMode); - M('flash.display3D.Context3DVertexBufferFormat', Context3DVertexBufferFormat); + M('flash.display3D.Context3DBlendFactor', Context3DBlendFactor); + M('flash.display3D.Context3DClearMask', Context3DClearMask); + M('flash.display3D.Context3DCompareMode', Context3DCompareMode); + M('flash.display3D.Context3DProfile', Context3DProfile); + M('flash.display3D.Context3DProgramType', Context3DProgramType); + M('flash.display3D.Context3DRenderMode', Context3DRenderMode); + M('flash.display3D.Context3DStencilAction', Context3DStencilAction); + M('flash.display3D.Context3DTextureFormat', Context3DTextureFormat); + M('flash.display3D.Context3DTriangleFace', Context3DTriangleFace); + M('flash.display3D.Context3DVertexBufferFormat', Context3DVertexBufferFormat); M('flash.display3D.IndexBuffer3D', IndexBuffer3D); M('flash.display3D.Program3D', Program3D); M('flash.display3D.VertexBuffer3D', VertexBuffer3D); - M('flash.display3D.textures.TextureBase', TextureBase); - M('flash.display3D.textures.Texture', Texture); - M('flash.display3D.textures.CubeTexture', CubeTexture); + M('flash.display3D.textures.TextureBase', TextureBase); + M('flash.display3D.textures.Texture', Texture); + M('flash.display3D.textures.CubeTexture', CubeTexture); //M('flash.errors.DRMManagerError', DRMManagerError);//AIR M('flash.errors.EOFError', EOFError); From fe93028818e7fed9fe0e722dacd6663291a8751d Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 17 Sep 2024 15:33:46 +0000 Subject: [PATCH 22/59] Add missing Context3D Getters and fix some oversights --- lib/display/Stage3D.ts | 2 +- lib/display3D/Context3D.ts | 83 ++++++++++++++++++++++++++++++-------- lib/geom/Matrix3D.ts | 2 +- 3 files changed, 69 insertions(+), 18 deletions(-) diff --git a/lib/display/Stage3D.ts b/lib/display/Stage3D.ts index 63e596cb..c70b337c 100644 --- a/lib/display/Stage3D.ts +++ b/lib/display/Stage3D.ts @@ -69,7 +69,7 @@ export class Stage3D extends EventDispatcher { public requestContext3D(context3DRenderMode: string = 'auto', profile: string = 'baseline'): void { console.log('Request Context'); this._context3D = new (this.sec as SecurityDomain).flash.display3D.Context3D(0, this, profile, context3DRenderMode); - const forceSoftware: boolean = (context3DRenderMode == 'auto'); + const forceSoftware: boolean = (context3DRenderMode == 'software'); let awayContextProfile: ContextGLProfile; switch (profile) { case 'baseline': diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index 971c47f7..9528323d 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -45,23 +45,26 @@ export class Context3D extends EventDispatcher { return this._adaptee; } - /*private _onAwayContextCreatedDelegate(e: StageEvent): void { - console.log(e.stage); - this._adaptee = e.stage; - this._gl = (this._adaptee.context as ContextWebGL)._gl; - //this._stage3D.dispatchEvent(new (this.sec as SecurityDomain).flash.events.Event(Event.CONTEXT3D_CREATE)) - console.log('Context Created'); + public get backBufferHeight(): number { + return this._adaptee.height + } - }*/ + public get backBufferWidth(): number { + return this._adaptee.width + } public get driverInfo(): string { - Debug.notImplemented('public flash.display3D.Context3D::get driverInfo'); return; - // return this._driverInfo; + Debug.notImplemented('public flash.display3D.Context3D::get driverInfo'); + let fmtProfile = this._profile + .split('_') + .map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()) + .join(' '); + return `OpenGL (${fmtProfile})`;; } public get enableErrorChecking(): boolean { - Debug.notImplemented('public flash.display3D.Context3D::get enableErrorChecking'); return; - // return this._enableErrorChecking; + Debug.notImplemented('public flash.display3D.Context3D::get enableErrorChecking'); + return false } public set enableErrorChecking(toggle: boolean) { @@ -70,6 +73,39 @@ export class Context3D extends EventDispatcher { // this._enableErrorChecking = toggle; } + public get maxBackBufferWidth(): number { + Debug.notImplemented('public flash.display3D.Context3D::get maxBackBufferWidth'); + return 2048; + } + + public set maxBackBufferWidth(value: number) { + Debug.notImplemented('public flash.display3D.Context3D::set maxBackBufferWidth'); + } + + public get maxBackBufferHeight(): number { + Debug.notImplemented('public flash.display3D.Context3D::set maxBackBufferHeight'); + return 2048; + } + + public set maxBackBufferHeight(value: number) { + Debug.notImplemented('public flash.display3D.Context3D::set maxBackBufferHeight'); + } + + public get profile(): string { + Debug.notImplemented('public flash.display3D.Context3D::get profile'); + return this._profile; + } + + public static get supportsVideoTexture(): boolean { + Debug.notImplemented('public flash.display3D.Context3D::get driverInfo'); + return false;; + } + + public get totalGPUMemory(): number { + Debug.notImplemented('public flash.display3D.Context3D::get totalGPUMemory'); + return 1024;; + } + public dispose(): void { Debug.notImplemented('public flash.display3D.Context3D::dispose'); return; } @@ -97,7 +133,24 @@ export class Context3D extends EventDispatcher { } public setProgramConstantsFromVector(programType: string, firstRegister: number /*int*/, data: Float64Vector, numRegisters: number /*int*/ = -1): void { - Debug.notImplemented('public flash.display3D.Context3D::setProgramConstantsFromVector'); return; + let awayProgramType: ContextGLProgramType; + switch (programType) { + case Context3DProgramType.FRAGMENT: + awayProgramType = ContextGLProgramType.FRAGMENT; + break; + case Context3DProgramType.VERTEX: + awayProgramType = ContextGLProgramType.VERTEX; + break; + default: + break; + } + // @todo: support transposed matrixes + let awayData:Float32Array = new Float32Array(data.length) + for(let i = 0; i < data.length; i++) { + awayData[i] = data.axGetNumericProperty(i) + + } + this._adaptee.context.setProgramConstantsFromArray(awayProgramType, awayData); } public setProgramConstantsFromMatrix(programType: string, firstRegister: number, matrix: Matrix3D, transposedMatrix: boolean = false): void { @@ -112,10 +165,8 @@ export class Context3D extends EventDispatcher { default: break; } - const programWebGL: ProgramWebGL = this._program._adaptee as ProgramWebGL; - // @todo: uniformMatrix4fv isn't working for some reason? - //programWebGL.uniformMatrix4fv(awayProgramType, transposedMatrix, matrix.adaptee._rawData); - programWebGL.uniform4fv(awayProgramType, matrix.adaptee._rawData); + // @todo: support transposed matrixes + this._adaptee.context.setProgramConstantsFromArray(awayProgramType, matrix.adaptee._rawData); } public setProgramConstantsFromByteArray(programType: string, firstRegister: number /*int*/, numRegisters: number /*int*/, data: ByteArray, byteArrayOffset: number /*uint*/): void { diff --git a/lib/geom/Matrix3D.ts b/lib/geom/Matrix3D.ts index 9f975a2c..36645586 100644 --- a/lib/geom/Matrix3D.ts +++ b/lib/geom/Matrix3D.ts @@ -142,7 +142,7 @@ export class Matrix3D extends ASObject { } public transformVector(v: Vector3D): Vector3D { - return new ( this.sec).flash.geom.Vector3D(this._adaptee.transformVector(v.adaptee, null, true)); + return new ( this.sec).flash.geom.Vector3D(this._adaptee.transformVector(v.adaptee)); } public deltaTransformVector(v: Vector3D): Vector3D { From 5f480d582a3e613d496146e49b668a40d1e8cbff Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 17 Sep 2024 18:44:14 +0000 Subject: [PATCH 23/59] Cleanup --- lib/display/Stage3D.ts | 23 +++++++---------------- lib/display3D/Context3D.ts | 23 ++++++----------------- 2 files changed, 13 insertions(+), 33 deletions(-) diff --git a/lib/display/Stage3D.ts b/lib/display/Stage3D.ts index c70b337c..db67e907 100644 --- a/lib/display/Stage3D.ts +++ b/lib/display/Stage3D.ts @@ -1,4 +1,4 @@ -import { AVMStage, Debug } from '@awayfl/swf-loader'; +import { AVMStage } from '@awayfl/swf-loader'; import { ContextGLProfile, Stage as AwayStage } from '@awayjs/stage'; import { Context3D } from '../display3D/Context3D'; import { Event } from '../events/Event'; @@ -15,9 +15,6 @@ export class Stage3D extends EventDispatcher { // List of instance symbols to link. public static instanceSymbols: string[] = null; // []; private _context3D: Context3D - private _visible: boolean - private _x: number - private _y: number private _id: number private _adaptee: AwayStage @@ -33,33 +30,27 @@ export class Stage3D extends EventDispatcher { } public get x(): number { - Debug.notImplemented('[playerglobal/display/Stage3D] - get x not implemented'); - return this._x; + return this._adaptee.x; } public set x(value: number) { - this._x = value; - Debug.notImplemented('[playerglobal/display/Stage3D] - set x not implemented'); + this._adaptee.y = value; } public get y(): number { - Debug.notImplemented('[playerglobal/display/Stage3D] - get y not implemented'); - return this._y; + return this._adaptee.y; } public set y(value: number) { - value = this._y; - Debug.notImplemented('[playerglobal/display/Stage3D] - set y not implemented'); + this._adaptee.y = value; } public get visible(): boolean { - Debug.notImplemented('[playerglobal/display/Stage3D] - get visible not implemented'); - return this._visible; + return this._adaptee.visible ; } public set visible(value: boolean) { - this._visible = value; - Debug.notImplemented('[playerglobal/display/Stage3D] - set visible not implemented'); + this._adaptee.visible = value; } public get context3D(): Context3D { diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index 9528323d..7349b84b 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -1,4 +1,4 @@ -import { ContextGLDrawMode, ContextGLProgramType, ContextGLVertexBufferFormat, ProgramWebGL, Stage as AwayStage } from '@awayjs/stage'; +import { ContextGLDrawMode, ContextGLProfile, ContextGLProgramType, ContextGLVertexBufferFormat, IVertexBuffer, ProgramWebGL, Stage as AwayStage, StageEvent } from '@awayjs/stage'; import { BitmapData } from '../display/BitmapData'; import { Stage3D } from '../display/Stage3D'; import { Context3DProgramType } from '../display3D/Context3DProgramType'; @@ -10,8 +10,7 @@ import { EventDispatcher } from '../events/EventDispatcher'; import { Matrix3D } from '../geom/Matrix3D'; import { Rectangle } from '../geom/Rectangle'; import { ByteArray } from '../utils/ByteArray'; - -import { Float64Vector } from '@awayfl/avm2'; +import { axCoerceString, Float64Vector } from '@awayfl/avm2'; import { Debug } from '@awayfl/swf-loader'; import { SecurityDomain } from '../SecurityDomain'; @@ -24,19 +23,14 @@ export class Context3D extends EventDispatcher { // List of instance symbols to link. public static instanceSymbols: string[] = null; // []; + private _adaptee: AwayStage - private _renderMode: string private _profile: string - private _gl: WebGLRenderingContext | WebGL2RenderingContext - private _program: Program3D - private _stage3D: Stage3D constructor(id: number, stage3D: Stage3D, renderMode: string = 'auto', profile: string = 'baseline') { super(); - console.log('Context3D Create'); - this._renderMode = renderMode; + console.log(`Context3D Create: ${renderMode} ${profile}`); this._profile = profile; - this._stage3D = stage3D; this._adaptee = stage3D.adaptee; console.log(stage3D); } @@ -55,11 +49,7 @@ export class Context3D extends EventDispatcher { public get driverInfo(): string { Debug.notImplemented('public flash.display3D.Context3D::get driverInfo'); - let fmtProfile = this._profile - .split('_') - .map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()) - .join(' '); - return `OpenGL (${fmtProfile})`;; + return axCoerceString(`OpenGL`);; } public get enableErrorChecking(): boolean { @@ -93,7 +83,7 @@ export class Context3D extends EventDispatcher { public get profile(): string { Debug.notImplemented('public flash.display3D.Context3D::get profile'); - return this._profile; + return axCoerceString(this._profile); } public static get supportsVideoTexture(): boolean { @@ -129,7 +119,6 @@ export class Context3D extends EventDispatcher { public setProgram(program: Program3D): void { this._adaptee.context.setProgram(program._adaptee); - this._program = program; } public setProgramConstantsFromVector(programType: string, firstRegister: number /*int*/, data: Float64Vector, numRegisters: number /*int*/ = -1): void { From 60241bf65578c10f672068fca6e4b3ce5bf58d25 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 17 Sep 2024 19:40:09 +0000 Subject: [PATCH 24/59] check event --- lib/display/Stage3D.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/display/Stage3D.ts b/lib/display/Stage3D.ts index db67e907..4d54671f 100644 --- a/lib/display/Stage3D.ts +++ b/lib/display/Stage3D.ts @@ -1,5 +1,5 @@ import { AVMStage } from '@awayfl/swf-loader'; -import { ContextGLProfile, Stage as AwayStage } from '@awayjs/stage'; +import { ContextGLProfile, Stage as AwayStage, StageEvent } from '@awayjs/stage'; import { Context3D } from '../display3D/Context3D'; import { Event } from '../events/Event'; import { EventDispatcher } from '../events/EventDispatcher'; @@ -86,7 +86,11 @@ export class Stage3D extends EventDispatcher { break; } console.log('Context3D Config: ', 'id: ', 0, ' forceSoftware: ', forceSoftware, ' profile: ', awayContextProfile); + const stage3D:Stage3D = this + const thisSec:SecurityDomain = (this.sec as SecurityDomain); + this._adaptee.addEventListener(StageEvent.CONTEXT_RECREATED, function(e:StageEvent){ + stage3D.dispatchEvent(new thisSec.flash.events.Event(Event.CONTEXT3D_CREATE)); + }) this._adaptee.requestContext(forceSoftware, awayContextProfile); - super.dispatchEvent(new (this.sec as SecurityDomain).flash.events.Event(Event.CONTEXT3D_CREATE)); } } \ No newline at end of file From 50dce419e71576a75668e01a93dbd4474d44e17d Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 17 Sep 2024 21:17:15 +0000 Subject: [PATCH 25/59] Listen dor events --- lib/display/Stage3D.ts | 7 +++++-- lib/display3D/Context3D.ts | 14 +++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/display/Stage3D.ts b/lib/display/Stage3D.ts index 4d54671f..e6bdf7ea 100644 --- a/lib/display/Stage3D.ts +++ b/lib/display/Stage3D.ts @@ -88,9 +88,12 @@ export class Stage3D extends EventDispatcher { console.log('Context3D Config: ', 'id: ', 0, ' forceSoftware: ', forceSoftware, ' profile: ', awayContextProfile); const stage3D:Stage3D = this const thisSec:SecurityDomain = (this.sec as SecurityDomain); - this._adaptee.addEventListener(StageEvent.CONTEXT_RECREATED, function(e:StageEvent){ + function dispatchContextCreated(e:Event){ + console.log(stage3D.context3D.driverInfo) + stage3D._context3D.removeEventListener(Event.CONTEXT3D_CREATE, dispatchContextCreated) stage3D.dispatchEvent(new thisSec.flash.events.Event(Event.CONTEXT3D_CREATE)); - }) + } + this._context3D.addEventListener(Event.CONTEXT3D_CREATE, dispatchContextCreated) this._adaptee.requestContext(forceSoftware, awayContextProfile); } } \ No newline at end of file diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index 7349b84b..e62e8571 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -13,6 +13,7 @@ import { ByteArray } from '../utils/ByteArray'; import { axCoerceString, Float64Vector } from '@awayfl/avm2'; import { Debug } from '@awayfl/swf-loader'; import { SecurityDomain } from '../SecurityDomain'; +import { Event } from '../events/Event'; export class Context3D extends EventDispatcher { // Called whenever the class is initialized. @@ -29,11 +30,18 @@ export class Context3D extends EventDispatcher { constructor(id: number, stage3D: Stage3D, renderMode: string = 'auto', profile: string = 'baseline') { super(); + const context3D:Context3D = this + const thisSec:SecurityDomain = (this.sec as SecurityDomain); + console.log(`Context3D Create: ${renderMode} ${profile}`); this._profile = profile; this._adaptee = stage3D.adaptee; - console.log(stage3D); - } + function dispatchContextCreated(e:StageEvent){ + context3D.adaptee.removeEventListener(StageEvent.CONTEXT_RECREATED, dispatchContextCreated) + context3D.dispatchEvent(new thisSec.flash.events.Event(Event.CONTEXT3D_CREATE)); + } + this._adaptee.addEventListener(StageEvent.CONTEXT_RECREATED, dispatchContextCreated) + } public get adaptee(): AwayStage { return this._adaptee; @@ -49,7 +57,7 @@ export class Context3D extends EventDispatcher { public get driverInfo(): string { Debug.notImplemented('public flash.display3D.Context3D::get driverInfo'); - return axCoerceString(`OpenGL`);; + return 'OpenGL'; } public get enableErrorChecking(): boolean { From 2aa4faeec7f6e8a631399c0df71f7a9bb049abfd Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Fri, 20 Sep 2024 16:51:35 +0000 Subject: [PATCH 26/59] Minor Fix --- lib/display/Stage3D.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/display/Stage3D.ts b/lib/display/Stage3D.ts index e6bdf7ea..53602c9e 100644 --- a/lib/display/Stage3D.ts +++ b/lib/display/Stage3D.ts @@ -59,7 +59,7 @@ export class Stage3D extends EventDispatcher { public requestContext3D(context3DRenderMode: string = 'auto', profile: string = 'baseline'): void { console.log('Request Context'); - this._context3D = new (this.sec as SecurityDomain).flash.display3D.Context3D(0, this, profile, context3DRenderMode); + this._context3D = new (this.sec as SecurityDomain).flash.display3D.Context3D(this._id, this, profile, context3DRenderMode); const forceSoftware: boolean = (context3DRenderMode == 'software'); let awayContextProfile: ContextGLProfile; switch (profile) { @@ -85,7 +85,7 @@ export class Stage3D extends EventDispatcher { awayContextProfile = ContextGLProfile.BASELINE; break; } - console.log('Context3D Config: ', 'id: ', 0, ' forceSoftware: ', forceSoftware, ' profile: ', awayContextProfile); + console.log('Context3D Config: ', 'id: ', this._id, ' forceSoftware: ', forceSoftware, ' profile: ', awayContextProfile); const stage3D:Stage3D = this const thisSec:SecurityDomain = (this.sec as SecurityDomain); function dispatchContextCreated(e:Event){ From 8358b1b831bda4020d4cc05ccbdaefb50a157fe7 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Mon, 23 Sep 2024 17:49:33 +0000 Subject: [PATCH 27/59] Implement Binary URLLoader --- lib/net/URLLoader.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/net/URLLoader.ts b/lib/net/URLLoader.ts index 069cca9f..f7e44360 100644 --- a/lib/net/URLLoader.ts +++ b/lib/net/URLLoader.ts @@ -70,8 +70,7 @@ export class URLLoader extends EventDispatcher { return new ( this.sec).flash.net.URLVariables(rawData); } case URLLoaderDataFormat.BINARY: { - console.warn('[URLLoader] Binary not supported'); - return null; + return new ( this.sec).flash.utils.ByteArray(rawData); } default: { From 4adeecfe72b4b2492dfbfe40064b6bd2544ddda5 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Mon, 23 Sep 2024 17:49:49 +0000 Subject: [PATCH 28/59] Fix flash.system.Capabilities.version --- lib/SecurityDomain.ts | 1 + lib/display3D/Context3D.ts | 24 +++++++---- lib/display3D/textures/CubeTexture.ts | 59 +++++++++++++++++++------- lib/display3D/textures/Texture.ts | 60 +++++++++++++++++---------- lib/display3D/textures/TextureBase.ts | 7 +++- lib/system/Capabilities.ts | 2 +- 6 files changed, 106 insertions(+), 47 deletions(-) diff --git a/lib/SecurityDomain.ts b/lib/SecurityDomain.ts index 7692a62b..ef349ac4 100644 --- a/lib/SecurityDomain.ts +++ b/lib/SecurityDomain.ts @@ -115,6 +115,7 @@ export class SecurityDomain extends AXSecurityDomain { textures: { TextureBase: TextureBase, Texture: Texture, + RectangleTexture: Texture, CubeTexture: CubeTexture, } }, diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index e62e8571..9b09d952 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -14,6 +14,10 @@ import { axCoerceString, Float64Vector } from '@awayfl/avm2'; import { Debug } from '@awayfl/swf-loader'; import { SecurityDomain } from '../SecurityDomain'; import { Event } from '../events/Event'; +import { Security } from '../system/Security'; +import { Texture } from './textures/Texture'; +import { CubeTexture } from './textures/CubeTexture'; +import { TextureBase } from '@awayjs/renderer'; export class Context3D extends EventDispatcher { // Called whenever the class is initialized. @@ -232,11 +236,15 @@ export class Context3D extends EventDispatcher { } public createTexture(width: number /*int*/, height: number /*int*/, format: string, optimizeForRenderToTexture: boolean, streamingLevels: number /*int*/ = 0): any { - Debug.notImplemented('public flash.display3D.Context3D::createTexture'); return; + return new (this.sec as SecurityDomain).flash.display3D.textures.Texture(this, width, height, format, optimizeForRenderToTexture, streamingLevels); + } + + public createRectangleTexture(width: number /*int*/, height: number /*int*/, format: string, optimizeForRenderToTexture: boolean): any { + return new (this.sec as SecurityDomain).flash.display3D.textures.RectangleTexture(this, width, height, format, optimizeForRenderToTexture); } public createCubeTexture(size: number /*int*/, format: string, optimizeForRenderToTexture: boolean, streamingLevels: number /*int*/ = 0): any /*CubeTexture*/ { - Debug.notImplemented('public flash.display3D.Context3D::createCubeTexture'); return; + return new (this.sec as SecurityDomain).flash.display3D.textures.CubeTexture(this, size, format, optimizeForRenderToTexture, streamingLevels) } public createProgram(): Program3D { @@ -247,16 +255,16 @@ export class Context3D extends EventDispatcher { Debug.notImplemented('public flash.display3D.Context3D::drawToBitmapData'); return; } - public setRenderToTextureInternal(textureTextureBase, targetType: number /*int*/, enableDepthAndStencil: boolean, antiAlias: number /*int*/, surfaceSelector: number /*int*/): void { - Debug.notImplemented('public flash.display3D.Context3D::setRenderToTextureInternal'); return; + public setRenderToTextureInternal(texture:TextureBase, targetType: number /*int*/, enableDepthAndStencil: boolean, antiAlias: number /*int*/, surfaceSelector: number /*int*/): void { + Debug.notImplemented('public flash.display3D.Context3D::setRenderToTextureInternal ' + texture.adaptee); return; } - public setTextureInternal(sampler: number /*int*/, textureTexture): void { - Debug.notImplemented('public flash.display3D.Context3D::setTextureInternal'); return; + public setTextureInternal(sampler: number /*int*/, texture:Texture): void { + this._adaptee.context.setTextureAt(sampler, texture._adaptee) } - public setCubeTextureInternal(sampler: number /*int*/, textureCubeTexture): void { - Debug.notImplemented('public flash.display3D.Context3D::setCubeTextureInternal'); return; + public setCubeTextureInternal(sampler: number /*int*/, textureCube:CubeTexture): void { + this._adaptee.context.setTextureAt(sampler, textureCube._adaptee) } } \ No newline at end of file diff --git a/lib/display3D/textures/CubeTexture.ts b/lib/display3D/textures/CubeTexture.ts index 8c066f96..85974f79 100644 --- a/lib/display3D/textures/CubeTexture.ts +++ b/lib/display3D/textures/CubeTexture.ts @@ -14,32 +14,61 @@ * limitations under the License. */ // Class: CubeTexture -import { Debug } from '@awayfl/swf-loader'; -import { BitmapData } from './../../display/BitmapData'; -import { ByteArray } from './../../utils/ByteArray'; -import { TextureBase } from './TextureBase'; +import { Debug } from "@awayfl/swf-loader"; +import { ContextGLTextureFormat, CubeTextureWebGL, TextureWebGL } from "@awayjs/stage"; +import { Context3D } from "../Context3D"; +import { BitmapData } from "./../../display/BitmapData"; +import { ByteArray } from "./../../utils/ByteArray"; +import { TextureBase } from "./TextureBase"; export class CubeTexture extends TextureBase { - // Called whenever the class is initialized. static classInitializer: any = null; - constructor() { + constructor( + context: Context3D, + size: number, + format: String, + optimizeForRenderToTexture: boolean, + streamingLevels: number = 0 + ) { super(); + let awayTextureFormat: ContextGLTextureFormat; + switch (format) { + case "bgra": + awayTextureFormat = ContextGLTextureFormat.BGRA; + break; + case "compressed": + awayTextureFormat = ContextGLTextureFormat.COMPRESSED; + break; + case "compressedAlpha": + awayTextureFormat = ContextGLTextureFormat.COMPRESSED_ALPHA; + break; + } + this._adaptee = context.adaptee.context.createCubeTexture( + size, + awayTextureFormat, + optimizeForRenderToTexture, + streamingLevels + ) as CubeTextureWebGL; } - uploadFromBitmapData(source: BitmapData, side: number /*uint*/, miplevel: number /*uint*/ = 0): void { - source = source; side = side >>> 0; miplevel = miplevel >>> 0; - Debug.notImplemented('public flash.display3D.textures.CubeTexture::uploadFromBitmapData'); return; + public uploadFromBitmapData(source: BitmapData, side: number /*uint*/, miplevel: number /*uint*/ = 0): void { + (this._adaptee).uploadFromArray(new Uint8Array(source.adaptee.getDataInternal()), side, miplevel) } - uploadFromByteArray(data: ByteArray, byteArrayOffset: number /*uint*/, side: number /*uint*/, miplevel: number /*uint*/ = 0): void { - data = data; byteArrayOffset = byteArrayOffset >>> 0; side = side >>> 0; miplevel = miplevel >>> 0; - Debug.notImplemented('public flash.display3D.textures.CubeTexture::uploadFromByteArray'); return; + uploadFromByteArray(data: ByteArray,byteArrayOffset: number /*uint*/,side: number /*uint*/,miplevel: number /*uint*/ = 0 + ): void { + data.position = byteArrayOffset; + (this._adaptee).uploadFromArray(new Uint8Array(data.arraybytes), side, miplevel) } - uploadCompressedTextureFromByteArray(data: ByteArray, byteArrayOffset: number /*uint*/, async: boolean = false): void { - data = data; byteArrayOffset = byteArrayOffset >>> 0; async = !!async; - Debug.notImplemented('public flash.display3D.textures.CubeTexture::uploadCompressedTextureFromByteArray'); return; + uploadCompressedTextureFromByteArray(data: ByteArray,byteArrayOffset: number /*uint*/,async: boolean = false + ): void { + data = data; + byteArrayOffset = byteArrayOffset >>> 0; + async = !!async; + Debug.notImplemented("public flash.display3D.textures.CubeTexture::uploadCompressedTextureFromByteArray"); + return; } } diff --git a/lib/display3D/textures/Texture.ts b/lib/display3D/textures/Texture.ts index 7c47f42e..58b2b115 100644 --- a/lib/display3D/textures/Texture.ts +++ b/lib/display3D/textures/Texture.ts @@ -1,30 +1,48 @@ -import { Debug } from '@awayfl/swf-loader'; -import { TextureWebGL } from '@awayjs/stage'; -import { BitmapData } from './../../display/BitmapData'; -import { ByteArray } from './../../utils/ByteArray'; -import { TextureBase } from './TextureBase'; +import { Debug } from "@awayfl/swf-loader"; +import { ContextGLTextureFormat, TextureWebGL } from "@awayjs/stage"; +import { Context3D } from "../Context3D"; +import { BitmapData } from "./../../display/BitmapData"; +import { ByteArray } from "./../../utils/ByteArray"; +import { TextureBase } from "./TextureBase"; export class Texture extends TextureBase { - public _adaptee: TextureWebGL; - - constructor() { - super() - Debug.notImplemented('public flash.display3D.textures.Texture::Texture'); return; - - + constructor( + context: Context3D, + width: number, + height: number, + format: string, + optimizeForRenderToTexture: boolean, + streamingLevels: number = 0 + ) { + super(); + let awayTextureFormat: ContextGLTextureFormat; + switch (format) { + case "bgra": + awayTextureFormat = ContextGLTextureFormat.BGRA; + break; + case "compressed": + awayTextureFormat = ContextGLTextureFormat.COMPRESSED; + break; + case "compressedAlpha": + awayTextureFormat = ContextGLTextureFormat.COMPRESSED_ALPHA; + break; + } + this._adaptee = context.adaptee.context.createTexture( + width, + height, + awayTextureFormat, + optimizeForRenderToTexture + ) as TextureWebGL; } - public uploadCompressedTextureFromByteArray (data: ByteArray, byteArrayOffset: number, async: boolean = false) { - Debug.notImplemented('public flash.display3D.textures.Texture::uploadCompressedTextureFromByteArray'); - + public uploadCompressedTextureFromByteArray(data: ByteArray, byteArrayOffset: number, async: boolean = false) { + Debug.notImplemented("public flash.display3D.textures.Texture::uploadCompressedTextureFromByteArray"); } - public uploadFromBitmapData (source: BitmapData, miplevel: number = 0) { - Debug.notImplemented('public flash.display3D.textures.Texture::uploadFromBitmapData'); - + public uploadFromBitmapData(source: BitmapData, miplevel: number = 0) { + (this._adaptee).uploadFromArray(new Uint8Array(source.adaptee.getDataInternal()), miplevel); } - public uploadFromByteArray (data: ByteArray, byteArrayOffset: number, miplevel: number = 0) { - Debug.notImplemented('public flash.display3D.textures.Texture::uploadFromByteArray'); - + public uploadFromByteArray(data: ByteArray, byteArrayOffset: number, miplevel: number = 0) { + (this._adaptee).uploadFromArray(new Uint8Array(data.arraybytes), miplevel); } } diff --git a/lib/display3D/textures/TextureBase.ts b/lib/display3D/textures/TextureBase.ts index a8d329d1..574d58f1 100644 --- a/lib/display3D/textures/TextureBase.ts +++ b/lib/display3D/textures/TextureBase.ts @@ -15,18 +15,21 @@ */ import { Debug } from '@awayfl/swf-loader'; +import { CubeTextureWebGL, TextureBaseWebGL, TextureWebGL } from '@awayjs/stage'; import { EventDispatcher } from '../../events/EventDispatcher'; +import { CubeTexture } from './CubeTexture'; +import { Texture } from './Texture'; export class TextureBase extends EventDispatcher { // Called whenever the class is initialized. static classInitializer: any = null; - + public _adaptee: TextureBaseWebGL; constructor () { super(); } public dispose(): void { - Debug.notImplemented('public flash.display3D.textures.TextureBase::dispose') + this._adaptee.dispose(); } } diff --git a/lib/system/Capabilities.ts b/lib/system/Capabilities.ts index 7b251fd1..098a21c1 100644 --- a/lib/system/Capabilities.ts +++ b/lib/system/Capabilities.ts @@ -54,7 +54,7 @@ export class Capabilities extends ASObject { private static _os: string = null; // static _cpuArchitecture: string; private static _playerType: string = null;// DEFAULT_CAPABILITIES.PLAYER_TYPE; - private static _version: string = 'SHUMWAY 10,0,0,0'; + private static _version: string = 'WIN 32,0,0,465'; // static _screenColor: string; // static _pixelAspectRatio: number; private static _screenDPI: number = 0;// = DEFAULT_CAPABILITIES.SCREEN_DPI; From e0dd64a4494a74bf48d758a54ac4600182c57f27 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Mon, 23 Sep 2024 17:50:17 +0000 Subject: [PATCH 29/59] Implement Textures --- lib/link.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/link.ts b/lib/link.ts index 8c8d3750..a716c5a4 100644 --- a/lib/link.ts +++ b/lib/link.ts @@ -333,6 +333,7 @@ export function initLink() { M('flash.display3D.textures.TextureBase', TextureBase); M('flash.display3D.textures.Texture', Texture); + M('flash.display3D.textures.RectangleTexture', Texture); M('flash.display3D.textures.CubeTexture', CubeTexture); //M('flash.errors.DRMManagerError', DRMManagerError);//AIR From 56b1ee9a85c0156a0f6fce19c1a5e0c73bebd8b1 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Mon, 23 Sep 2024 18:31:57 +0000 Subject: [PATCH 30/59] Ignore Mips for now, ignore setVertexBufferAt if no Program is set, prevent null texture or vertexBuffer since AwayJS doesn't support that --- lib/display3D/Context3D.ts | 11 ++++++++--- lib/display3D/Program3D.ts | 1 - lib/display3D/textures/CubeTexture.ts | 6 ++++-- lib/display3D/textures/Texture.ts | 2 ++ 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index 9b09d952..e89bf011 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -31,6 +31,7 @@ export class Context3D extends EventDispatcher { private _adaptee: AwayStage private _profile: string + private _currentProgram : Program3D constructor(id: number, stage3D: Stage3D, renderMode: string = 'auto', profile: string = 'baseline') { super(); @@ -131,6 +132,7 @@ export class Context3D extends EventDispatcher { public setProgram(program: Program3D): void { this._adaptee.context.setProgram(program._adaptee); + this._currentProgram = program } public setProgramConstantsFromVector(programType: string, firstRegister: number /*int*/, data: Float64Vector, numRegisters: number /*int*/ = -1): void { @@ -195,7 +197,8 @@ export class Context3D extends EventDispatcher { default: break; } - this._adaptee.context.setVertexBufferAt(index, buffer._adaptee, bufferOffset * 4, awayFormat); + if(this._currentProgram && buffer) // Away3D uses a null buffer to clear this, but null in AwayJS just errors + this._adaptee.context.setVertexBufferAt(index, buffer._adaptee, bufferOffset * 4, awayFormat); } public setBlendFactors(sourceFactor: string, destinationFactor: string): void { @@ -260,11 +263,13 @@ export class Context3D extends EventDispatcher { } public setTextureInternal(sampler: number /*int*/, texture:Texture): void { - this._adaptee.context.setTextureAt(sampler, texture._adaptee) + if(texture) // Away3D uses a null texture to clear this, but null in AwayJS just errors + this._adaptee.context.setTextureAt(sampler, texture._adaptee) } public setCubeTextureInternal(sampler: number /*int*/, textureCube:CubeTexture): void { - this._adaptee.context.setTextureAt(sampler, textureCube._adaptee) + if(textureCube) // Away3D uses a null texture to clear this, but null in AwayJS just errors + this._adaptee.context.setTextureAt(sampler, textureCube._adaptee) } } \ No newline at end of file diff --git a/lib/display3D/Program3D.ts b/lib/display3D/Program3D.ts index 7623228c..6a342f40 100644 --- a/lib/display3D/Program3D.ts +++ b/lib/display3D/Program3D.ts @@ -24,6 +24,5 @@ export class Program3D extends ASObject { public upload(vertexProgram: ByteArray, fragmentProgram: ByteArray): void { this._adaptee.upload(vertexProgram, fragmentProgram); - this._context.setProgram(this._adaptee); } } \ No newline at end of file diff --git a/lib/display3D/textures/CubeTexture.ts b/lib/display3D/textures/CubeTexture.ts index 85974f79..6cc8dee3 100644 --- a/lib/display3D/textures/CubeTexture.ts +++ b/lib/display3D/textures/CubeTexture.ts @@ -54,16 +54,18 @@ export class CubeTexture extends TextureBase { } public uploadFromBitmapData(source: BitmapData, side: number /*uint*/, miplevel: number /*uint*/ = 0): void { + if(miplevel==0) // @todo: Additional Mips cause errors (this._adaptee).uploadFromArray(new Uint8Array(source.adaptee.getDataInternal()), side, miplevel) } - uploadFromByteArray(data: ByteArray,byteArrayOffset: number /*uint*/,side: number /*uint*/,miplevel: number /*uint*/ = 0 + public uploadFromByteArray(data: ByteArray,byteArrayOffset: number /*uint*/,side: number /*uint*/,miplevel: number /*uint*/ = 0 ): void { + if(miplevel==0) // @todo: Additional Mips cause errors data.position = byteArrayOffset; (this._adaptee).uploadFromArray(new Uint8Array(data.arraybytes), side, miplevel) } - uploadCompressedTextureFromByteArray(data: ByteArray,byteArrayOffset: number /*uint*/,async: boolean = false + public uploadCompressedTextureFromByteArray(data: ByteArray,byteArrayOffset: number /*uint*/,async: boolean = false ): void { data = data; byteArrayOffset = byteArrayOffset >>> 0; diff --git a/lib/display3D/textures/Texture.ts b/lib/display3D/textures/Texture.ts index 58b2b115..56f104f6 100644 --- a/lib/display3D/textures/Texture.ts +++ b/lib/display3D/textures/Texture.ts @@ -39,10 +39,12 @@ export class Texture extends TextureBase { } public uploadFromBitmapData(source: BitmapData, miplevel: number = 0) { + if(miplevel==0) // @todo: Additional Mips cause errors (this._adaptee).uploadFromArray(new Uint8Array(source.adaptee.getDataInternal()), miplevel); } public uploadFromByteArray(data: ByteArray, byteArrayOffset: number, miplevel: number = 0) { + if(miplevel==0) // @todo: Additional Mips cause errors (this._adaptee).uploadFromArray(new Uint8Array(data.arraybytes), miplevel); } } From 4864750bf474fe0a4dafe96352cffbe77270af06 Mon Sep 17 00:00:00 2001 From: Fancy2209 <64917206+Fancy2209@users.noreply.github.com> Date: Tue, 24 Sep 2024 13:20:04 +0000 Subject: [PATCH 31/59] Fix based on stage change --- lib/display3D/Context3D.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index e89bf011..56dfcaaf 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -17,7 +17,7 @@ import { Event } from '../events/Event'; import { Security } from '../system/Security'; import { Texture } from './textures/Texture'; import { CubeTexture } from './textures/CubeTexture'; -import { TextureBase } from '@awayjs/renderer'; +import { TextureBase } from './textures/TextureBase'; export class Context3D extends EventDispatcher { // Called whenever the class is initialized. @@ -31,7 +31,7 @@ export class Context3D extends EventDispatcher { private _adaptee: AwayStage private _profile: string - private _currentProgram : Program3D + //private _currentProgram : Program3D constructor(id: number, stage3D: Stage3D, renderMode: string = 'auto', profile: string = 'baseline') { super(); @@ -122,7 +122,6 @@ export class Context3D extends EventDispatcher { } public drawTriangles(indexBuffer: IndexBuffer3D, firstIndex: number = 0, numTriangles: number = -1): void { - // @todo: This is not working this._adaptee.context.drawIndices(ContextGLDrawMode.TRIANGLES, indexBuffer._adaptee, firstIndex, (numTriangles == -1) ? -1 : (numTriangles * 3)); } @@ -132,7 +131,7 @@ export class Context3D extends EventDispatcher { public setProgram(program: Program3D): void { this._adaptee.context.setProgram(program._adaptee); - this._currentProgram = program + //this._currentProgram = program } public setProgramConstantsFromVector(programType: string, firstRegister: number /*int*/, data: Float64Vector, numRegisters: number /*int*/ = -1): void { @@ -197,8 +196,8 @@ export class Context3D extends EventDispatcher { default: break; } - if(this._currentProgram && buffer) // Away3D uses a null buffer to clear this, but null in AwayJS just errors - this._adaptee.context.setVertexBufferAt(index, buffer._adaptee, bufferOffset * 4, awayFormat); + //if(this._currentProgram && buffer) // Away3D uses a null buffer to clear this, but null in AwayJS just errors + this._adaptee.context.setVertexBufferAt(index, buffer._adaptee, bufferOffset * 4, awayFormat, false); } public setBlendFactors(sourceFactor: string, destinationFactor: string): void { @@ -259,7 +258,7 @@ export class Context3D extends EventDispatcher { } public setRenderToTextureInternal(texture:TextureBase, targetType: number /*int*/, enableDepthAndStencil: boolean, antiAlias: number /*int*/, surfaceSelector: number /*int*/): void { - Debug.notImplemented('public flash.display3D.Context3D::setRenderToTextureInternal ' + texture.adaptee); return; + Debug.notImplemented('public flash.display3D.Context3D::setRenderToTextureInternal ' + texture._adaptee); return; } public setTextureInternal(sampler: number /*int*/, texture:Texture): void { From bf7d0f9232e97fc24c8f56172758132670c1be70 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 24 Sep 2024 15:16:59 +0000 Subject: [PATCH 32/59] Revert Null Fix (Didn't work, just made nothing render) --- lib/display3D/Context3D.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index 56dfcaaf..5a664c2d 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -1,4 +1,4 @@ -import { ContextGLDrawMode, ContextGLProfile, ContextGLProgramType, ContextGLVertexBufferFormat, IVertexBuffer, ProgramWebGL, Stage as AwayStage, StageEvent } from '@awayjs/stage'; +import { ContextGLDrawMode, ContextGLProfile, ContextGLProgramType, ContextGLVertexBufferFormat, ContextWebGL, IVertexBuffer, ProgramWebGL, Stage as AwayStage, StageEvent } from '@awayjs/stage'; import { BitmapData } from '../display/BitmapData'; import { Stage3D } from '../display/Stage3D'; import { Context3DProgramType } from '../display3D/Context3DProgramType'; @@ -18,6 +18,7 @@ import { Security } from '../system/Security'; import { Texture } from './textures/Texture'; import { CubeTexture } from './textures/CubeTexture'; import { TextureBase } from './textures/TextureBase'; +import { VertexBufferWebGL } from '@awayjs/stage'; export class Context3D extends EventDispatcher { // Called whenever the class is initialized. @@ -196,8 +197,9 @@ export class Context3D extends EventDispatcher { default: break; } - //if(this._currentProgram && buffer) // Away3D uses a null buffer to clear this, but null in AwayJS just errors - this._adaptee.context.setVertexBufferAt(index, buffer._adaptee, bufferOffset * 4, awayFormat, false); + if(buffer) // Away3D uses a null buffer to clear this, but null in AwayJS just errors + (this._adaptee.context).setVertexBufferAt(index, buffer._adaptee, bufferOffset * 4, awayFormat, false); + } public setBlendFactors(sourceFactor: string, destinationFactor: string): void { From a599281e69d0e0665995bf04751698eac45deda3 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 24 Sep 2024 15:23:49 +0000 Subject: [PATCH 33/59] Fix null stuff --- lib/display3D/Context3D.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index 5a664c2d..56f0d052 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -198,7 +198,7 @@ export class Context3D extends EventDispatcher { break; } if(buffer) // Away3D uses a null buffer to clear this, but null in AwayJS just errors - (this._adaptee.context).setVertexBufferAt(index, buffer._adaptee, bufferOffset * 4, awayFormat, false); + (this._adaptee.context).setVertexBufferAt(index, buffer ? buffer._adaptee : null, bufferOffset * 4, awayFormat, false); } From 311bfee1fc90ef719bdddf22d31044cfc8f8f2a3 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 24 Sep 2024 15:27:50 +0000 Subject: [PATCH 34/59] Additional null fix --- lib/display3D/Context3D.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index 56f0d052..37e1cf65 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -198,7 +198,7 @@ export class Context3D extends EventDispatcher { break; } if(buffer) // Away3D uses a null buffer to clear this, but null in AwayJS just errors - (this._adaptee.context).setVertexBufferAt(index, buffer ? buffer._adaptee : null, bufferOffset * 4, awayFormat, false); + (this._adaptee.context).setVertexBufferAt( buffer ? index : -1, buffer ? buffer._adaptee : null, bufferOffset * 4, awayFormat, false); } From d20d8cbb0375bf069cf219a195bb54aad86c92fb Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 24 Sep 2024 15:39:48 +0000 Subject: [PATCH 35/59] Final fix for Null setVertexAt (for now) --- lib/display3D/Context3D.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index 37e1cf65..4c2e0422 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -197,8 +197,7 @@ export class Context3D extends EventDispatcher { default: break; } - if(buffer) // Away3D uses a null buffer to clear this, but null in AwayJS just errors - (this._adaptee.context).setVertexBufferAt( buffer ? index : -1, buffer ? buffer._adaptee : null, bufferOffset * 4, awayFormat, false); + (this._adaptee.context).setVertexBufferAt( buffer ? index : -1, buffer ? buffer._adaptee : null, bufferOffset * 4, awayFormat, false); } From ff148aa207ff26450681982cac4bdbb2622be79c Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Mon, 30 Sep 2024 20:22:33 +0000 Subject: [PATCH 36/59] Make requestContext3D async (doesn't fix all starling issues) --- lib/display/Stage3D.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/display/Stage3D.ts b/lib/display/Stage3D.ts index 53602c9e..81144124 100644 --- a/lib/display/Stage3D.ts +++ b/lib/display/Stage3D.ts @@ -4,6 +4,7 @@ import { Context3D } from '../display3D/Context3D'; import { Event } from '../events/Event'; import { EventDispatcher } from '../events/EventDispatcher'; import { SecurityDomain } from '../SecurityDomain'; +import { AXSecurityDomain } from '@awayfl/avm2'; export class Stage3D extends EventDispatcher { // Called whenever the class is initialized. @@ -58,8 +59,10 @@ export class Stage3D extends EventDispatcher { } public requestContext3D(context3DRenderMode: string = 'auto', profile: string = 'baseline'): void { + const stage3D:Stage3D = this + setTimeout(function(){ console.log('Request Context'); - this._context3D = new (this.sec as SecurityDomain).flash.display3D.Context3D(this._id, this, profile, context3DRenderMode); + stage3D._context3D = new (stage3D.sec as SecurityDomain).flash.display3D.Context3D(stage3D._id, stage3D, profile, context3DRenderMode); const forceSoftware: boolean = (context3DRenderMode == 'software'); let awayContextProfile: ContextGLProfile; switch (profile) { @@ -85,15 +88,14 @@ export class Stage3D extends EventDispatcher { awayContextProfile = ContextGLProfile.BASELINE; break; } - console.log('Context3D Config: ', 'id: ', this._id, ' forceSoftware: ', forceSoftware, ' profile: ', awayContextProfile); - const stage3D:Stage3D = this - const thisSec:SecurityDomain = (this.sec as SecurityDomain); + console.log('Context3D Config: ', 'id: ', stage3D._id, ' forceSoftware: ', forceSoftware, ' profile: ', awayContextProfile); + function dispatchContextCreated(e:Event){ console.log(stage3D.context3D.driverInfo) stage3D._context3D.removeEventListener(Event.CONTEXT3D_CREATE, dispatchContextCreated) - stage3D.dispatchEvent(new thisSec.flash.events.Event(Event.CONTEXT3D_CREATE)); + stage3D.dispatchEvent(new (stage3D.sec).flash.events.Event(Event.CONTEXT3D_CREATE)); } - this._context3D.addEventListener(Event.CONTEXT3D_CREATE, dispatchContextCreated) - this._adaptee.requestContext(forceSoftware, awayContextProfile); + stage3D._context3D.addEventListener(Event.CONTEXT3D_CREATE, dispatchContextCreated) + stage3D._adaptee.requestContext(forceSoftware, awayContextProfile);},1) } } \ No newline at end of file From 6e477e4395ff518621477f691e1af71772a9e3e9 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Mon, 30 Sep 2024 20:22:44 +0000 Subject: [PATCH 37/59] Fix LoaderInfo.UncaughtErrorEvents --- lib/display/LoaderInfo.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/display/LoaderInfo.ts b/lib/display/LoaderInfo.ts index d95e8731..07b0600e 100644 --- a/lib/display/LoaderInfo.ts +++ b/lib/display/LoaderInfo.ts @@ -160,6 +160,7 @@ export class LoaderInfo extends EventDispatcher { private _swfVersion: number; private _applicationDomain: ApplicationDomain; + private _uncaughtErrorEvents: UncaughtErrorEvents; /** * The ActionScript version of the loaded SWF file. The language @@ -194,6 +195,7 @@ export class LoaderInfo extends EventDispatcher { constructor(loader: ILoader, container: AwayDisplayObject) { super(); + this._uncaughtErrorEvents; // Events that are supposed to be working are registered as eventMappingExtern: this.eventMappingExtern[Event.COMPLETE] = 'LoaderInfo:Event.COMPLETE'; @@ -637,8 +639,14 @@ export class LoaderInfo extends EventDispatcher { * `uncaughtErrorEvents` property is available after the * `applicationComplete` event is dispatched. */ - public get uncaughtErrorEvents(): UncaughtErrorEvents { - return this._loader.uncaughtErrorEvents; + public get uncaughtErrorEvents(): any { + // @todo + Debug.throwPIR('playerglobals/display/LoaderInfo', 'get uncaughtErrorEvents', ''); + if (!this._uncaughtErrorEvents) + this._uncaughtErrorEvents = new UncaughtErrorEvents(); + + return this._uncaughtErrorEvents; + } /** From 0e5d7e94df80470b560c016d22984d3d3716c74e Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Mon, 30 Sep 2024 20:23:01 +0000 Subject: [PATCH 38/59] Fix contentScaleFactor (0 breaks stuff who checks it) --- lib/display/Stage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/display/Stage.ts b/lib/display/Stage.ts index e05926db..b9bf776f 100644 --- a/lib/display/Stage.ts +++ b/lib/display/Stage.ts @@ -481,7 +481,7 @@ export class Stage extends DisplayObjectContainer { public get contentsScaleFactor (): number { // @todo Debug.throwPIR('playerglobals/display/Stage', 'get contentsScaleFactor', ''); - return 0; + return 1; } public get displayContextInfo (): string { From 2992d0f46e61f3fa0b34c1adae2588edebaa47a3 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Thu, 3 Oct 2024 18:02:21 +0000 Subject: [PATCH 39/59] Comit work, fix WebPack without dist --- lib/display/Stage3D.ts | 15 +++++++++------ lib/display3D/Context3D.ts | 24 ++++++++++++------------ lib/display3D/textures/CubeTexture.ts | 1 - lib/media/SoundChannel.ts | 2 +- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/lib/display/Stage3D.ts b/lib/display/Stage3D.ts index 81144124..db1df70d 100644 --- a/lib/display/Stage3D.ts +++ b/lib/display/Stage3D.ts @@ -1,10 +1,11 @@ import { AVMStage } from '@awayfl/swf-loader'; -import { ContextGLProfile, Stage as AwayStage, StageEvent } from '@awayjs/stage'; +import { ContextGLProfile, Stage as AwayStage } from '@awayjs/stage'; import { Context3D } from '../display3D/Context3D'; import { Event } from '../events/Event'; import { EventDispatcher } from '../events/EventDispatcher'; import { SecurityDomain } from '../SecurityDomain'; import { AXSecurityDomain } from '@awayfl/avm2'; +import { ErrorEvent } from '../events/ErrorEvent'; export class Stage3D extends EventDispatcher { // Called whenever the class is initialized. @@ -64,7 +65,7 @@ export class Stage3D extends EventDispatcher { console.log('Request Context'); stage3D._context3D = new (stage3D.sec as SecurityDomain).flash.display3D.Context3D(stage3D._id, stage3D, profile, context3DRenderMode); const forceSoftware: boolean = (context3DRenderMode == 'software'); - let awayContextProfile: ContextGLProfile; + var awayContextProfile: ContextGLProfile; switch (profile) { case 'baseline': awayContextProfile = ContextGLProfile.BASELINE; @@ -76,16 +77,18 @@ export class Stage3D extends EventDispatcher { awayContextProfile = ContextGLProfile.BASELINE_EXTENDED; break; case 'standard': - console.log('Unsupported Context3D Profile \'standard\' Requested'); + awayContextProfile = ContextGLProfile.STANDARD; break; case 'standard_constrained': - console.log('Unsupported Context3D Profile \'standard_constrained\' Requested'); + awayContextProfile = ContextGLProfile.STANDARD_CONSTRAINED; break; case 'standard_extended': - console.log('Unsupported Context3D Profile \'standard_extended\' Requested'); + awayContextProfile = ContextGLProfile.STANDARD_EXTENDED; + break; + case 'enhanced': + awayContextProfile = ContextGLProfile.ENHANCED; break; default: - awayContextProfile = ContextGLProfile.BASELINE; break; } console.log('Context3D Config: ', 'id: ', stage3D._id, ' forceSoftware: ', forceSoftware, ' profile: ', awayContextProfile); diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index 4c2e0422..834941e0 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -1,4 +1,4 @@ -import { ContextGLDrawMode, ContextGLProfile, ContextGLProgramType, ContextGLVertexBufferFormat, ContextWebGL, IVertexBuffer, ProgramWebGL, Stage as AwayStage, StageEvent } from '@awayjs/stage'; +import { BitmapImage2D, ContextGLDrawMode, ContextGLProfile, ContextGLProgramType, ContextGLVertexBufferFormat, ContextWebGL, IVertexBuffer, ProgramWebGL, Stage as AwayStage, StageEvent, TextureWebGL } from '@awayjs/stage'; import { BitmapData } from '../display/BitmapData'; import { Stage3D } from '../display/Stage3D'; import { Context3DProgramType } from '../display3D/Context3DProgramType'; @@ -32,6 +32,7 @@ export class Context3D extends EventDispatcher { private _adaptee: AwayStage private _profile: string + private _gl: WebGL2RenderingContext | WebGLRenderingContext //private _currentProgram : Program3D constructor(id: number, stage3D: Stage3D, renderMode: string = 'auto', profile: string = 'baseline') { @@ -45,6 +46,7 @@ export class Context3D extends EventDispatcher { function dispatchContextCreated(e:StageEvent){ context3D.adaptee.removeEventListener(StageEvent.CONTEXT_RECREATED, dispatchContextCreated) context3D.dispatchEvent(new thisSec.flash.events.Event(Event.CONTEXT3D_CREATE)); + context3D._gl = (context3D.adaptee.context)._gl } this._adaptee.addEventListener(StageEvent.CONTEXT_RECREATED, dispatchContextCreated) } @@ -111,7 +113,7 @@ export class Context3D extends EventDispatcher { } public dispose(): void { - Debug.notImplemented('public flash.display3D.Context3D::dispose'); return; + this._adaptee.context.dispose(); } public configureBackBuffer(width: number, height: number, antiAlias: number, enableDepthAndStencil: boolean = true, wantsBestResolution: boolean = false, wantsBestResolutionOnBrowserZoom: boolean = false): void { @@ -255,21 +257,19 @@ export class Context3D extends EventDispatcher { } public drawToBitmapData(destination: BitmapData): void { - Debug.notImplemented('public flash.display3D.Context3D::drawToBitmapData'); return; + this.adaptee.context.drawToBitmapImage2D(destination.adaptee as any as BitmapImage2D); } - public setRenderToTextureInternal(texture:TextureBase, targetType: number /*int*/, enableDepthAndStencil: boolean, antiAlias: number /*int*/, surfaceSelector: number /*int*/): void { - Debug.notImplemented('public flash.display3D.Context3D::setRenderToTextureInternal ' + texture._adaptee); return; + public setRenderToBackBuffer() { + this._adaptee.context.setRenderToBackBuffer(); } - public setTextureInternal(sampler: number /*int*/, texture:Texture): void { - if(texture) // Away3D uses a null texture to clear this, but null in AwayJS just errors - this._adaptee.context.setTextureAt(sampler, texture._adaptee) + public setRenderToTexture(texture:TextureBase, targetType: number /*int*/, enableDepthAndStencil: boolean, antiAlias: number /*int*/, surfaceSelector: number /*int*/): void { + this._adaptee.context.setRenderToTexture(texture._adaptee, enableDepthAndStencil, antiAlias, surfaceSelector) } - public setCubeTextureInternal(sampler: number /*int*/, textureCube:CubeTexture): void { - if(textureCube) // Away3D uses a null texture to clear this, but null in AwayJS just errors - this._adaptee.context.setTextureAt(sampler, textureCube._adaptee) + public setTextureAt(sampler: number /*int*/, texture:TextureBase): void { + if(texture) + this._adaptee.context.setTextureAt(sampler, texture._adaptee) } - } \ No newline at end of file diff --git a/lib/display3D/textures/CubeTexture.ts b/lib/display3D/textures/CubeTexture.ts index 6cc8dee3..216d70ec 100644 --- a/lib/display3D/textures/CubeTexture.ts +++ b/lib/display3D/textures/CubeTexture.ts @@ -61,7 +61,6 @@ export class CubeTexture extends TextureBase { public uploadFromByteArray(data: ByteArray,byteArrayOffset: number /*uint*/,side: number /*uint*/,miplevel: number /*uint*/ = 0 ): void { if(miplevel==0) // @todo: Additional Mips cause errors - data.position = byteArrayOffset; (this._adaptee).uploadFromArray(new Uint8Array(data.arraybytes), side, miplevel) } diff --git a/lib/media/SoundChannel.ts b/lib/media/SoundChannel.ts index 8060849c..5cc5d17e 100644 --- a/lib/media/SoundChannel.ts +++ b/lib/media/SoundChannel.ts @@ -5,7 +5,7 @@ import { SecurityDomain } from '../SecurityDomain'; import { Event } from '../events/Event'; import { EventBase, IAudioChannel } from '@awayjs/core'; import { ISoundSource, SoundMixer } from './SoundMixer'; -import { BaseAudioChannel } from '@awayjs/core/dist/lib/managers/BaseAudioChannel'; +import { BaseAudioChannel } from '@awayjs/core'; /** * Dispatched when a sound has finished playing. From 8d527371211a1c002571bb2c975e6ef1f263d2a7 Mon Sep 17 00:00:00 2001 From: Fancy2209 <64917206+Fancy2209@users.noreply.github.com> Date: Wed, 29 Jan 2025 14:32:34 -0100 Subject: [PATCH 40/59] Update Stage3D.ts --- lib/display/Stage3D.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/display/Stage3D.ts b/lib/display/Stage3D.ts index db1df70d..5715309c 100644 --- a/lib/display/Stage3D.ts +++ b/lib/display/Stage3D.ts @@ -99,6 +99,6 @@ export class Stage3D extends EventDispatcher { stage3D.dispatchEvent(new (stage3D.sec).flash.events.Event(Event.CONTEXT3D_CREATE)); } stage3D._context3D.addEventListener(Event.CONTEXT3D_CREATE, dispatchContextCreated) - stage3D._adaptee.requestContext(forceSoftware, awayContextProfile);},1) + stage3D._adaptee.requestContext(forceSoftware, awayContextProfile) } -} \ No newline at end of file +} From 5065eb926099b0a8e2df0e827efce6bb0899123c Mon Sep 17 00:00:00 2001 From: Fancy2209 <64917206+Fancy2209@users.noreply.github.com> Date: Wed, 29 Jan 2025 14:50:52 -0100 Subject: [PATCH 41/59] Update link.ts --- lib/link.ts | 68 +++++++++++++++++++---------------------------------- 1 file changed, 24 insertions(+), 44 deletions(-) diff --git a/lib/link.ts b/lib/link.ts index a716c5a4..6080f0c4 100644 --- a/lib/link.ts +++ b/lib/link.ts @@ -25,26 +25,6 @@ import { Shape } from './display/Shape'; import { SimpleButton } from './display/SimpleButton'; import { Sprite } from './display/Sprite'; import { Stage } from './display/Stage'; -import { Stage3D } from './display/Stage3D'; - -import { Context3D } from './display3D/Context3D'; -import { Context3DBlendFactor } from './display3D/Context3DBlendFactor'; -import { Context3DClearMask } from './display3D/Context3DClearMask'; -import { Context3DCompareMode } from './display3D/Context3DCompareMode'; -import { Context3DProfile } from './display3D/Context3DProfile'; -import { Context3DProgramType } from './display3D/Context3DProgramType'; -import { Context3DRenderMode } from './display3D/Context3DRenderMode'; -import { Context3DStencilAction } from './display3D/Context3DStencilAction'; -import { Context3DTextureFormat } from './display3D/Context3DTextureFormat'; -import { Context3DTriangleFace } from './display3D/Context3DTriangleFace'; -import { Context3DVertexBufferFormat } from './display3D/Context3DVertexBufferFormat'; -import { IndexBuffer3D } from './display3D/IndexBuffer3D'; -import { Program3D } from './display3D/Program3D'; -import { VertexBuffer3D } from './display3D/VertexBuffer3D'; - -import { CubeTexture } from './display3D/textures/CubeTexture'; -import { Texture } from './display3D/textures/Texture'; -import { TextureBase } from './display3D/textures/TextureBase'; import { EOFError } from './errors/EOFError'; import { IllegalOperationError } from './errors/IllegalOperationError'; @@ -70,8 +50,8 @@ import { AsyncErrorEvent } from './events/AsyncErrorEvent'; import { ContextMenuEvent } from './events/ContextMenuEvent'; import { DataEvent } from './events/DataEvent'; import { ErrorEvent } from './events/ErrorEvent'; -import { Event } from './events/Event'; import { EventDispatcher } from './events/EventDispatcher'; +import { Event } from './events/Event'; import { EventPhase } from './events/EventPhase'; import { FocusEvent } from './events/FocusEvent'; import { FullScreenEvent } from './events/FullScreenEvent'; @@ -124,8 +104,8 @@ import { NumberFormatter } from './globalization/NumberFormatter'; import { Sound } from './media/Sound'; import { SoundChannel } from './media/SoundChannel'; -import { SoundMixer } from './media/SoundMixer'; import { SoundTransform } from './media/SoundTransform'; +import { SoundMixer } from './media/SoundMixer'; import { FileFilter } from './net/FileFilter'; import { FileReference } from './net/FileReference'; @@ -134,32 +114,33 @@ import { NetConnection } from './net/NetConnection'; import { Responder } from './net/Responder'; import { Socket } from './net/Socket'; import { SharedObject } from './net/SharedObject'; -import { URLLoader } from './net/URLLoader'; import { URLRequest } from './net/URLRequest'; +import { URLLoader } from './net/URLLoader'; import { URLVariables } from './net/URLVariables'; +import { LocalConnection } from './net/LocalConnection'; -import { ApplicationDomain } from './system/ApplicationDomain'; +import { SecurityDomain } from './system/SecurityDomain'; import { Capabilities } from './system/Capabilities'; import { fscommand } from './system/FSCommand'; -import { LoaderContext } from './system/LoaderContext'; import { Security } from './system/Security'; -import { SecurityDomain } from './system/SecurityDomain'; +import { LoaderContext } from './system/LoaderContext'; +import { ApplicationDomain } from './system/ApplicationDomain'; import { System } from './system/System'; -import { CSMSettings } from './text/CSMSettings'; import { Font } from './text/Font'; -import { FontType } from './text/FontType'; -import { StaticText } from './text/StaticText'; import { StyleSheet } from './text/StyleSheet'; -import { TextColorType } from './text/TextColorType'; -import { TextDisplayMode } from './text/TextDisplayMode'; -import { TextExtent } from './text/TextExtent'; import { TextField } from './text/TextField'; import { TextFormat } from './text/TextFormat'; +import { TextRun } from './text/TextRun'; +import { StaticText } from './text/StaticText'; +import { TextRenderer } from './text/TextRenderer'; import { TextFormatDisplay } from './text/TextFormatDisplay'; +import { TextExtent } from './text/TextExtent'; +import { TextDisplayMode } from './text/TextDisplayMode'; +import { TextColorType } from './text/TextColorType'; +import { FontType } from './text/FontType'; +import { CSMSettings } from './text/CSMSettings'; import { TextLineMetrics } from './text/TextLineMetrics'; -import { TextRenderer } from './text/TextRenderer'; -import { TextRun } from './text/TextRun'; import { TextSnapshot } from './text/TextSnapshot'; import { CompositionAttributeRange } from './text/ime/CompositionAttributeRange'; @@ -197,28 +178,27 @@ import { TextLineValidity } from './text/engine/TextLineValidity'; import { TextRotation } from './text/engine/TextRotation'; import { TypographicCase } from './text/engine/TypographicCase'; -import { ASClass, ByteArray, registerNativeClass, registerNativeFunction, XMLDocument, XMLNode } from '@awayfl/avm2'; -import { release } from '@awayfl/swf-loader'; -import { BlendMode } from '@awayjs/stage'; -import { GroupElement } from './text/engine/GroupElement'; +import { Keyboard } from './ui/Keyboard'; import { ContextMenu } from './ui/ContextMenu'; +import { ContextMenuItem } from './ui/ContextMenuItem'; import { ContextMenuBuiltInItems } from './ui/ContextMenuBuiltInItems'; import { ContextMenuClipboardItems } from './ui/ContextMenuClipboardItems'; -import { ContextMenuItem } from './ui/ContextMenuItem'; import { GameInput } from './ui/GameInput'; import { GameInputControl } from './ui/GameInputControl'; import { GameInputControlType } from './ui/GameInputControlType'; import { GameInputDevice } from './ui/GameInputDevice'; import { GameInputFinger } from './ui/GameInputFinger'; import { GameInputHand } from './ui/GameInputHand'; -import { Keyboard } from './ui/Keyboard'; import { Mouse } from './ui/Mouse'; -import { Multitouch } from './ui/Multitouch'; import { MultitouchInputMode } from './ui/MultitouchInputMode'; -import { CompressionAlgorithm } from './utils/CompressionAlgorithm'; +import { Multitouch } from './ui/Multitouch'; import { Timer } from './utils/Timer'; - -import { BaseTextLayoutImporter, Property } from './text/engine/NativehacksForTLF'; +import { CompressionAlgorithm } from './utils/CompressionAlgorithm'; +import { XMLDocument, XMLNode, ASClass, registerNativeClass, registerNativeFunction } from '@awayfl/avm2'; +import { release } from '@awayfl/swf-loader'; +import { BlendMode } from '@awayjs/stage'; +import { GroupElement } from './text/engine/GroupElement'; +import { ByteArray } from '@awayfl/avm2'; function M(name: string, asClass: ASClass) { registerNativeClass(name, asClass); From b6f097a2ff776ce372731446f3edc051dc735a27 Mon Sep 17 00:00:00 2001 From: Fancy2209 <64917206+Fancy2209@users.noreply.github.com> Date: Wed, 29 Jan 2025 14:52:21 -0100 Subject: [PATCH 42/59] Update link.ts --- lib/link.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/link.ts b/lib/link.ts index 6080f0c4..cc9105a0 100644 --- a/lib/link.ts +++ b/lib/link.ts @@ -26,6 +26,25 @@ import { SimpleButton } from './display/SimpleButton'; import { Sprite } from './display/Sprite'; import { Stage } from './display/Stage'; +import { Stage3D } from './display/Stage3D'; +import { Context3D } from './display3D/Context3D'; +import { Context3DBlendFactor } from './display3D/Context3DBlendFactor'; +import { Context3DClearMask } from './display3D/Context3DClearMask'; +import { Context3DCompareMode } from './display3D/Context3DCompareMode'; +import { Context3DProfile } from './display3D/Context3DProfile'; +import { Context3DProgramType } from './display3D/Context3DProgramType'; +import { Context3DRenderMode } from './display3D/Context3DRenderMode'; +import { Context3DStencilAction } from './display3D/Context3DStencilAction'; +import { Context3DTextureFormat } from './display3D/Context3DTextureFormat'; +import { Context3DTriangleFace } from './display3D/Context3DTriangleFace'; +import { Context3DVertexBufferFormat } from './display3D/Context3DVertexBufferFormat'; +import { IndexBuffer3D } from './display3D/IndexBuffer3D'; +import { Program3D } from './display3D/Program3D'; +import { VertexBuffer3D } from './display3D/VertexBuffer3D'; +import { CubeTexture } from './display3D/textures/CubeTexture'; +import { Texture } from './display3D/textures/Texture'; +import { TextureBase } from './display3D/textures/TextureBase'; + import { EOFError } from './errors/EOFError'; import { IllegalOperationError } from './errors/IllegalOperationError'; import { InvalidSWFError } from './errors/InvalidSWFError'; From 711cefc88cee95d17bfe87932d54289d210ee6b7 Mon Sep 17 00:00:00 2001 From: Fancy2209 <64917206+Fancy2209@users.noreply.github.com> Date: Wed, 29 Jan 2025 14:53:54 -0100 Subject: [PATCH 43/59] Update link.ts --- lib/link.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/link.ts b/lib/link.ts index cc9105a0..f7591ad0 100644 --- a/lib/link.ts +++ b/lib/link.ts @@ -219,6 +219,8 @@ import { BlendMode } from '@awayjs/stage'; import { GroupElement } from './text/engine/GroupElement'; import { ByteArray } from '@awayfl/avm2'; +import { BaseTextLayoutImporter, Property } from './text/engine/NativehacksForTLF'; + function M(name: string, asClass: ASClass) { registerNativeClass(name, asClass); } From 6e6ff9c6abf49c1c75ef3899f2d5da450c3f18b2 Mon Sep 17 00:00:00 2001 From: Fancy2209 <64917206+Fancy2209@users.noreply.github.com> Date: Thu, 27 Mar 2025 09:42:34 -0100 Subject: [PATCH 44/59] Remove unrelated changes and fix some vars that were lets --- lib/SecurityDomain.ts | 3 +- lib/display/LoaderInfo.ts | 8 +-- lib/display/Stage.ts | 2 - lib/display/Stage3D.ts | 13 ++-- lib/display3D/Context3D.ts | 77 ++++++++++++++-------- lib/display3D/textures/RectangleTexture.ts | 51 ++++++++++++++ lib/display3D/textures/Texture.ts | 4 +- lib/link.ts | 5 +- lib/net/URLLoader.ts | 3 +- 9 files changed, 115 insertions(+), 51 deletions(-) create mode 100644 lib/display3D/textures/RectangleTexture.ts diff --git a/lib/SecurityDomain.ts b/lib/SecurityDomain.ts index ef349ac4..881b07e9 100644 --- a/lib/SecurityDomain.ts +++ b/lib/SecurityDomain.ts @@ -85,6 +85,7 @@ import { VertexBuffer3D } from './display3D/VertexBuffer3D'; import { TextureBase } from './display3D/textures/TextureBase'; import { Texture } from './display3D/textures/Texture'; import { CubeTexture } from './display3D/textures/CubeTexture'; +import { RectangleTexture } from './display3D/textures/RectangleTexture'; export class Mouse {} @@ -115,7 +116,7 @@ export class SecurityDomain extends AXSecurityDomain { textures: { TextureBase: TextureBase, Texture: Texture, - RectangleTexture: Texture, + RectangleTexture: RectangleTexture, CubeTexture: CubeTexture, } }, diff --git a/lib/display/LoaderInfo.ts b/lib/display/LoaderInfo.ts index 07b0600e..faa4e695 100644 --- a/lib/display/LoaderInfo.ts +++ b/lib/display/LoaderInfo.ts @@ -12,7 +12,6 @@ import { DisplayObject as AwayDisplayObject } from '@awayjs/scene'; import { SecurityDomain } from '../SecurityDomain'; import { PickGroup } from '@awayjs/view'; import { AVMStage } from '@awayfl/swf-loader'; -import { UncaughtErrorEvents } from '../events/UncaughtErrorEvents'; interface LoaderInfoCompleteQueueItem { loaderInfo: LoaderInfo; @@ -160,7 +159,6 @@ export class LoaderInfo extends EventDispatcher { private _swfVersion: number; private _applicationDomain: ApplicationDomain; - private _uncaughtErrorEvents: UncaughtErrorEvents; /** * The ActionScript version of the loaded SWF file. The language @@ -195,7 +193,6 @@ export class LoaderInfo extends EventDispatcher { constructor(loader: ILoader, container: AwayDisplayObject) { super(); - this._uncaughtErrorEvents; // Events that are supposed to be working are registered as eventMappingExtern: this.eventMappingExtern[Event.COMPLETE] = 'LoaderInfo:Event.COMPLETE'; @@ -642,10 +639,7 @@ export class LoaderInfo extends EventDispatcher { public get uncaughtErrorEvents(): any { // @todo Debug.throwPIR('playerglobals/display/LoaderInfo', 'get uncaughtErrorEvents', ''); - if (!this._uncaughtErrorEvents) - this._uncaughtErrorEvents = new UncaughtErrorEvents(); - - return this._uncaughtErrorEvents; + return null; } diff --git a/lib/display/Stage.ts b/lib/display/Stage.ts index b9bf776f..5f844f2c 100644 --- a/lib/display/Stage.ts +++ b/lib/display/Stage.ts @@ -814,8 +814,6 @@ export class Stage extends DisplayObjectContainer { } public get stage3Ds (): GenericVector { - // @todo - Debug.throwPIR('playerglobals/display/Stage', 'get stage3Ds', ''); return this._stage3Ds; } diff --git a/lib/display/Stage3D.ts b/lib/display/Stage3D.ts index 5715309c..e9e1a4ed 100644 --- a/lib/display/Stage3D.ts +++ b/lib/display/Stage3D.ts @@ -61,7 +61,7 @@ export class Stage3D extends EventDispatcher { public requestContext3D(context3DRenderMode: string = 'auto', profile: string = 'baseline'): void { const stage3D:Stage3D = this - setTimeout(function(){ + // setTimeout(function(){ console.log('Request Context'); stage3D._context3D = new (stage3D.sec as SecurityDomain).flash.display3D.Context3D(stage3D._id, stage3D, profile, context3DRenderMode); const forceSoftware: boolean = (context3DRenderMode == 'software'); @@ -94,11 +94,12 @@ export class Stage3D extends EventDispatcher { console.log('Context3D Config: ', 'id: ', stage3D._id, ' forceSoftware: ', forceSoftware, ' profile: ', awayContextProfile); function dispatchContextCreated(e:Event){ - console.log(stage3D.context3D.driverInfo) - stage3D._context3D.removeEventListener(Event.CONTEXT3D_CREATE, dispatchContextCreated) + console.log(stage3D.context3D.driverInfo); + stage3D._context3D.removeEventListener(Event.CONTEXT3D_CREATE, dispatchContextCreated); stage3D.dispatchEvent(new (stage3D.sec).flash.events.Event(Event.CONTEXT3D_CREATE)); } - stage3D._context3D.addEventListener(Event.CONTEXT3D_CREATE, dispatchContextCreated) - stage3D._adaptee.requestContext(forceSoftware, awayContextProfile) - } + + stage3D._context3D.addEventListener(Event.CONTEXT3D_CREATE, dispatchContextCreated); + stage3D._adaptee.requestContext(forceSoftware, awayContextProfile); + } //, 0)}; } diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index 834941e0..a5954d63 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -1,4 +1,18 @@ -import { BitmapImage2D, ContextGLDrawMode, ContextGLProfile, ContextGLProgramType, ContextGLVertexBufferFormat, ContextWebGL, IVertexBuffer, ProgramWebGL, Stage as AwayStage, StageEvent, TextureWebGL } from '@awayjs/stage'; +import { BitmapImage2D, + ContextGLDrawMode, + ContextGLProfile, + ContextGLProgramType, + ContextGLVertexBufferFormat, + ContextWebGL, + IVertexBuffer, + ProgramWebGL, + Stage as AwayStage, + StageEvent, + TextureWebGL, + VertexBufferWebGL, + ContextGLClearMask} from '@awayjs/stage'; +import { axCoerceString, Float64Vector } from '@awayfl/avm2'; +import { Debug } from '@awayfl/swf-loader'; import { BitmapData } from '../display/BitmapData'; import { Stage3D } from '../display/Stage3D'; import { Context3DProgramType } from '../display3D/Context3DProgramType'; @@ -10,15 +24,14 @@ import { EventDispatcher } from '../events/EventDispatcher'; import { Matrix3D } from '../geom/Matrix3D'; import { Rectangle } from '../geom/Rectangle'; import { ByteArray } from '../utils/ByteArray'; -import { axCoerceString, Float64Vector } from '@awayfl/avm2'; -import { Debug } from '@awayfl/swf-loader'; import { SecurityDomain } from '../SecurityDomain'; import { Event } from '../events/Event'; import { Security } from '../system/Security'; import { Texture } from './textures/Texture'; +import { RectangleTexture } from './textures/RectangleTexture'; import { CubeTexture } from './textures/CubeTexture'; import { TextureBase } from './textures/TextureBase'; -import { VertexBufferWebGL } from '@awayjs/stage'; +import { Context3DClearMask } from './Context3DClearMask'; export class Context3D extends EventDispatcher { // Called whenever the class is initialized. @@ -30,10 +43,10 @@ export class Context3D extends EventDispatcher { // List of instance symbols to link. public static instanceSymbols: string[] = null; // []; - private _adaptee: AwayStage - private _profile: string - private _gl: WebGL2RenderingContext | WebGLRenderingContext - //private _currentProgram : Program3D + private _adaptee: AwayStage; + private _profile: string; + private _gl: WebGL2RenderingContext | WebGLRenderingContext; + //private _currentProgram : Program3D; constructor(id: number, stage3D: Stage3D, renderMode: string = 'auto', profile: string = 'baseline') { super(); @@ -46,7 +59,7 @@ export class Context3D extends EventDispatcher { function dispatchContextCreated(e:StageEvent){ context3D.adaptee.removeEventListener(StageEvent.CONTEXT_RECREATED, dispatchContextCreated) context3D.dispatchEvent(new thisSec.flash.events.Event(Event.CONTEXT3D_CREATE)); - context3D._gl = (context3D.adaptee.context)._gl + context3D._gl = (context3D.adaptee.context as ContextWebGL)._gl; } this._adaptee.addEventListener(StageEvent.CONTEXT_RECREATED, dispatchContextCreated) } @@ -80,8 +93,7 @@ export class Context3D extends EventDispatcher { } public get maxBackBufferWidth(): number { - Debug.notImplemented('public flash.display3D.Context3D::get maxBackBufferWidth'); - return 2048; + return this._gl.getParameter(this._gl.MAX_VIEWPORT_DIMS); } public set maxBackBufferWidth(value: number) { @@ -89,8 +101,7 @@ export class Context3D extends EventDispatcher { } public get maxBackBufferHeight(): number { - Debug.notImplemented('public flash.display3D.Context3D::set maxBackBufferHeight'); - return 2048; + return this._gl.getParameter(this._gl.MAX_VIEWPORT_DIMS); } public set maxBackBufferHeight(value: number) { @@ -98,7 +109,6 @@ export class Context3D extends EventDispatcher { } public get profile(): string { - Debug.notImplemented('public flash.display3D.Context3D::get profile'); return axCoerceString(this._profile); } @@ -121,7 +131,16 @@ export class Context3D extends EventDispatcher { } public clear(red: number = 0.0, green: number = 0.0, blue: number = 0.0, alpha: number = 1.0, depth: number = 1.0, stencil: number = 0, mask: number = 0xffffffff): void { - this._adaptee.clear(red, green, blue, alpha, depth, stencil, mask); + + var awayMask: number = 0; + if(mask & Context3DClearMask.COLOR) + awayMask |= ContextGLClearMask.COLOR; + if(mask & Context3DClearMask.DEPTH) + awayMask |= ContextGLClearMask.DEPTH; + if(mask & Context3DClearMask.STENCIL) + awayMask |= ContextGLClearMask.STENCIL; + + this._adaptee.clear(red, green, blue, alpha, depth, stencil, awayMask); } public drawTriangles(indexBuffer: IndexBuffer3D, firstIndex: number = 0, numTriangles: number = -1): void { @@ -138,7 +157,7 @@ export class Context3D extends EventDispatcher { } public setProgramConstantsFromVector(programType: string, firstRegister: number /*int*/, data: Float64Vector, numRegisters: number /*int*/ = -1): void { - let awayProgramType: ContextGLProgramType; + var awayProgramType: ContextGLProgramType; switch (programType) { case Context3DProgramType.FRAGMENT: awayProgramType = ContextGLProgramType.FRAGMENT; @@ -149,17 +168,17 @@ export class Context3D extends EventDispatcher { default: break; } + // @todo: support transposed matrixes - let awayData:Float32Array = new Float32Array(data.length) - for(let i = 0; i < data.length; i++) { + var awayData:Float32Array = new Float32Array(data.length) + for(let i = 0; i < data.length; i++) awayData[i] = data.axGetNumericProperty(i) - } this._adaptee.context.setProgramConstantsFromArray(awayProgramType, awayData); } public setProgramConstantsFromMatrix(programType: string, firstRegister: number, matrix: Matrix3D, transposedMatrix: boolean = false): void { - let awayProgramType: ContextGLProgramType; + var awayProgramType: ContextGLProgramType; switch (programType) { case Context3DProgramType.FRAGMENT: awayProgramType = ContextGLProgramType.FRAGMENT; @@ -179,7 +198,7 @@ export class Context3D extends EventDispatcher { } public setVertexBufferAt(index: number, buffer: VertexBuffer3D, bufferOffset: number = 0, format: string = 'float4'): void { - let awayFormat: number; + var awayFormat: number; switch (format) { case Context3DVertexBufferFormat.BYTES_4: awayFormat = ContextGLVertexBufferFormat.BYTE_4; @@ -199,7 +218,7 @@ export class Context3D extends EventDispatcher { default: break; } - (this._adaptee.context).setVertexBufferAt( buffer ? index : -1, buffer ? buffer._adaptee : null, bufferOffset * 4, awayFormat, false); + (this._adaptee.context as ContextWebGL).setVertexBufferAt( buffer ? index : -1, buffer ? buffer._adaptee : null, bufferOffset * 4, awayFormat, false); } @@ -228,7 +247,7 @@ export class Context3D extends EventDispatcher { } public setScissorRectangle(rectangle: Rectangle): void { - Debug.notImplemented('public flash.display3D.Context3D::setScissorRectangle'); return; + (this._adaptee.context as ContextWebGL).setScissorRectangle(rectangle.adaptee); } public createVertexBuffer(numVertices: number, data32PerVertex: number, bufferUsage: string = 'staticDraw'): VertexBuffer3D { @@ -240,15 +259,15 @@ export class Context3D extends EventDispatcher { return new (this.sec as SecurityDomain).flash.display3D.IndexBuffer3D(this, numIndices); } - public createTexture(width: number /*int*/, height: number /*int*/, format: string, optimizeForRenderToTexture: boolean, streamingLevels: number /*int*/ = 0): any { + public createTexture(width: number /*int*/, height: number /*int*/, format: string, optimizeForRenderToTexture: boolean, streamingLevels: number /*int*/ = 0): Texture { return new (this.sec as SecurityDomain).flash.display3D.textures.Texture(this, width, height, format, optimizeForRenderToTexture, streamingLevels); } - public createRectangleTexture(width: number /*int*/, height: number /*int*/, format: string, optimizeForRenderToTexture: boolean): any { + public createRectangleTexture(width: number /*int*/, height: number /*int*/, format: string, optimizeForRenderToTexture: boolean): RectangleTexture { return new (this.sec as SecurityDomain).flash.display3D.textures.RectangleTexture(this, width, height, format, optimizeForRenderToTexture); } - public createCubeTexture(size: number /*int*/, format: string, optimizeForRenderToTexture: boolean, streamingLevels: number /*int*/ = 0): any /*CubeTexture*/ { + public createCubeTexture(size: number /*int*/, format: string, optimizeForRenderToTexture: boolean, streamingLevels: number /*int*/ = 0): CubeTexture /*CubeTexture*/ { return new (this.sec as SecurityDomain).flash.display3D.textures.CubeTexture(this, size, format, optimizeForRenderToTexture, streamingLevels) } @@ -260,15 +279,15 @@ export class Context3D extends EventDispatcher { this.adaptee.context.drawToBitmapImage2D(destination.adaptee as any as BitmapImage2D); } - public setRenderToBackBuffer() { + public setRenderToBackBuffer(): void { this._adaptee.context.setRenderToBackBuffer(); } public setRenderToTexture(texture:TextureBase, targetType: number /*int*/, enableDepthAndStencil: boolean, antiAlias: number /*int*/, surfaceSelector: number /*int*/): void { - this._adaptee.context.setRenderToTexture(texture._adaptee, enableDepthAndStencil, antiAlias, surfaceSelector) + this._adaptee.context.setRenderToTexture(texture._adaptee, enableDepthAndStencil, antiAlias, surfaceSelector); } - public setTextureAt(sampler: number /*int*/, texture:TextureBase): void { + public setTextureAt(sampler: number /*int*/, texture: TextureBase): void { if(texture) this._adaptee.context.setTextureAt(sampler, texture._adaptee) } diff --git a/lib/display3D/textures/RectangleTexture.ts b/lib/display3D/textures/RectangleTexture.ts new file mode 100644 index 00000000..5111e562 --- /dev/null +++ b/lib/display3D/textures/RectangleTexture.ts @@ -0,0 +1,51 @@ +import { Debug } from "@awayfl/swf-loader"; +import { ContextGLTextureFormat, TextureWebGL } from "@awayjs/stage"; +import { Context3D } from "../Context3D"; +import { BitmapData } from "./../../display/BitmapData"; +import { ByteArray } from "./../../utils/ByteArray"; +import { TextureBase } from "./TextureBase"; + +export class RectangleTexture extends TextureBase { + constructor( + context: Context3D, + width: number, + height: number, + format: string, + optimizeForRenderToTexture: boolean, + streamingLevels: number = 0 + ) { + super(); + let awayTextureFormat: ContextGLTextureFormat; + switch (format) { + case "bgra": + awayTextureFormat = ContextGLTextureFormat.BGRA; + break; + case "compressed": + awayTextureFormat = ContextGLTextureFormat.COMPRESSED; + break; + case "compressedAlpha": + awayTextureFormat = ContextGLTextureFormat.COMPRESSED_ALPHA; + break; + } + this._adaptee = context.adaptee.context.createTexture( + width, + height, + awayTextureFormat, + optimizeForRenderToTexture + ) as TextureWebGL; + } + + public uploadCompressedTextureFromByteArray(data: ByteArray, byteArrayOffset: number, async: boolean = false) { + Debug.notImplemented("public flash.display3D.textures.Texture::uploadCompressedTextureFromByteArray"); + } + + public uploadFromBitmapData(source: BitmapData, miplevel: number = 0) { + if(miplevel==0) // @todo: Additional Mips cause errors + (this._adaptee).uploadFromArray(new Uint8Array(source.adaptee.getDataInternal()), miplevel); + } + + public uploadFromByteArray(data: ByteArray, byteArrayOffset: number, miplevel: number = 0) { + if(miplevel==0) // @todo: Additional Mips cause errors + (this._adaptee).uploadFromArray(new Uint8Array(data.arraybytes), miplevel); + } +} diff --git a/lib/display3D/textures/Texture.ts b/lib/display3D/textures/Texture.ts index 56f104f6..a72acd72 100644 --- a/lib/display3D/textures/Texture.ts +++ b/lib/display3D/textures/Texture.ts @@ -40,11 +40,11 @@ export class Texture extends TextureBase { public uploadFromBitmapData(source: BitmapData, miplevel: number = 0) { if(miplevel==0) // @todo: Additional Mips cause errors - (this._adaptee).uploadFromArray(new Uint8Array(source.adaptee.getDataInternal()), miplevel); + (this._adaptee).uploadFromArray(new Uint8Array(source.adaptee.getDataInternal()), miplevel); } public uploadFromByteArray(data: ByteArray, byteArrayOffset: number, miplevel: number = 0) { if(miplevel==0) // @todo: Additional Mips cause errors - (this._adaptee).uploadFromArray(new Uint8Array(data.arraybytes), miplevel); + (this._adaptee).uploadFromArray(new Uint8Array(data.arraybytes), miplevel); } } diff --git a/lib/link.ts b/lib/link.ts index f7591ad0..978aa455 100644 --- a/lib/link.ts +++ b/lib/link.ts @@ -42,6 +42,7 @@ import { IndexBuffer3D } from './display3D/IndexBuffer3D'; import { Program3D } from './display3D/Program3D'; import { VertexBuffer3D } from './display3D/VertexBuffer3D'; import { CubeTexture } from './display3D/textures/CubeTexture'; +import { RectangleTexture } from './display3D/textures/RectangleTexture'; import { Texture } from './display3D/textures/Texture'; import { TextureBase } from './display3D/textures/TextureBase'; @@ -315,8 +316,6 @@ export function initLink() { //M('flash.display.StageScaleMode', StageScaleMode); //M('flash.display.TriangleCulling', TriangleCulling); - // TODO: Add display3d stuff - M('flash.display3D.Context3D', Context3D); M('flash.display3D.Context3DBlendFactor', Context3DBlendFactor); M('flash.display3D.Context3DClearMask', Context3DClearMask); @@ -334,7 +333,7 @@ export function initLink() { M('flash.display3D.textures.TextureBase', TextureBase); M('flash.display3D.textures.Texture', Texture); - M('flash.display3D.textures.RectangleTexture', Texture); + M('flash.display3D.textures.RectangleTexture', RectangleTexture); M('flash.display3D.textures.CubeTexture', CubeTexture); //M('flash.errors.DRMManagerError', DRMManagerError);//AIR diff --git a/lib/net/URLLoader.ts b/lib/net/URLLoader.ts index f7e44360..069cca9f 100644 --- a/lib/net/URLLoader.ts +++ b/lib/net/URLLoader.ts @@ -70,7 +70,8 @@ export class URLLoader extends EventDispatcher { return new ( this.sec).flash.net.URLVariables(rawData); } case URLLoaderDataFormat.BINARY: { - return new ( this.sec).flash.utils.ByteArray(rawData); + console.warn('[URLLoader] Binary not supported'); + return null; } default: { From 6f5d57c9345ef2c4fed33a98f74abaad2bad5291 Mon Sep 17 00:00:00 2001 From: Fancy2209 Date: Fri, 28 Mar 2025 22:08:35 -0100 Subject: [PATCH 45/59] Fixup + Fixed by eslint --- lib/SecurityDomain.ts | 2 +- lib/display/Stage3D.ts | 84 +++-- lib/display3D/Context3D.ts | 377 +++++++++++++++++---- lib/display3D/Context3DCompareMode.ts | 37 +- lib/display3D/Context3DStencilAction.ts | 34 +- lib/display3D/Context3DTextureFormat.ts | 27 +- lib/display3D/Context3DTriangleFace.ts | 28 +- lib/display3D/textures/CubeTexture.ts | 28 +- lib/display3D/textures/RectangleTexture.ts | 28 +- lib/display3D/textures/Texture.ts | 28 +- 10 files changed, 463 insertions(+), 210 deletions(-) diff --git a/lib/SecurityDomain.ts b/lib/SecurityDomain.ts index 881b07e9..03d8454a 100644 --- a/lib/SecurityDomain.ts +++ b/lib/SecurityDomain.ts @@ -113,7 +113,7 @@ export class SecurityDomain extends AXSecurityDomain { IndexBuffer3D: IndexBuffer3D, Program3D: Program3D, VertexBuffer3D: VertexBuffer3D, - textures: { + textures: { TextureBase: TextureBase, Texture: Texture, RectangleTexture: RectangleTexture, diff --git a/lib/display/Stage3D.ts b/lib/display/Stage3D.ts index e9e1a4ed..e337397c 100644 --- a/lib/display/Stage3D.ts +++ b/lib/display/Stage3D.ts @@ -17,14 +17,12 @@ export class Stage3D extends EventDispatcher { // List of instance symbols to link. public static instanceSymbols: string[] = null; // []; private _context3D: Context3D - private _id: number private _adaptee: AwayStage constructor(i) { super(); console.log('Stage3D Constructor'); this._adaptee = AVMStage.instance().stage3Ds[i]; - this._id = i; } public get adaptee(): AwayStage { @@ -60,46 +58,46 @@ export class Stage3D extends EventDispatcher { } public requestContext3D(context3DRenderMode: string = 'auto', profile: string = 'baseline'): void { - const stage3D:Stage3D = this - // setTimeout(function(){ - console.log('Request Context'); - stage3D._context3D = new (stage3D.sec as SecurityDomain).flash.display3D.Context3D(stage3D._id, stage3D, profile, context3DRenderMode); - const forceSoftware: boolean = (context3DRenderMode == 'software'); - var awayContextProfile: ContextGLProfile; - switch (profile) { - case 'baseline': - awayContextProfile = ContextGLProfile.BASELINE; - break; - case 'baseline_constrained': - awayContextProfile = ContextGLProfile.BASELINE_CONSTRAINED; - break; - case 'baseline_extended': - awayContextProfile = ContextGLProfile.BASELINE_EXTENDED; - break; - case 'standard': - awayContextProfile = ContextGLProfile.STANDARD; - break; - case 'standard_constrained': - awayContextProfile = ContextGLProfile.STANDARD_CONSTRAINED; - break; - case 'standard_extended': - awayContextProfile = ContextGLProfile.STANDARD_EXTENDED; - break; - case 'enhanced': - awayContextProfile = ContextGLProfile.ENHANCED; - break; - default: - break; - } - console.log('Context3D Config: ', 'id: ', stage3D._id, ' forceSoftware: ', forceSoftware, ' profile: ', awayContextProfile); - - function dispatchContextCreated(e:Event){ - console.log(stage3D.context3D.driverInfo); - stage3D._context3D.removeEventListener(Event.CONTEXT3D_CREATE, dispatchContextCreated); - stage3D.dispatchEvent(new (stage3D.sec).flash.events.Event(Event.CONTEXT3D_CREATE)); - } + const stage3D: Stage3D = this; + setTimeout(function() { + console.log('Request Context'); + stage3D._context3D = new (stage3D.sec as SecurityDomain).flash.display3D.Context3D(stage3D, profile, context3DRenderMode); + const forceSoftware: boolean = (context3DRenderMode == 'software'); + let awayContextProfile: ContextGLProfile = ContextGLProfile.BASELINE; + switch (profile) { + case 'baseline': + awayContextProfile = ContextGLProfile.BASELINE; + break; + case 'baseline_constrained': + awayContextProfile = ContextGLProfile.BASELINE_CONSTRAINED; + break; + case 'baseline_extended': + awayContextProfile = ContextGLProfile.BASELINE_EXTENDED; + break; + case 'standard': + awayContextProfile = ContextGLProfile.STANDARD; + break; + case 'standard_constrained': + awayContextProfile = ContextGLProfile.STANDARD_CONSTRAINED; + break; + case 'standard_extended': + awayContextProfile = ContextGLProfile.STANDARD_EXTENDED; + break; + case 'enhanced': + awayContextProfile = ContextGLProfile.BASELINE_EXTENDED; + break; + default: + break; + } + console.log('Context3D Config: ', 'forceSoftware: ', forceSoftware, ' profile: ', profile); + function dispatchContextCreated(e: Event) { + console.log(stage3D.context3D.driverInfo); + stage3D._context3D.removeEventListener(Event.CONTEXT3D_CREATE, dispatchContextCreated); + stage3D.dispatchEvent(new (stage3D.sec).flash.events.Event(Event.CONTEXT3D_CREATE)); + } - stage3D._context3D.addEventListener(Event.CONTEXT3D_CREATE, dispatchContextCreated); - stage3D._adaptee.requestContext(forceSoftware, awayContextProfile); - } //, 0)}; + stage3D._context3D.addEventListener(Event.CONTEXT3D_CREATE, dispatchContextCreated); + stage3D._adaptee.requestContext(forceSoftware, awayContextProfile); + } , 0); + } } diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index a5954d63..183bece9 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -1,16 +1,17 @@ -import { BitmapImage2D, - ContextGLDrawMode, - ContextGLProfile, - ContextGLProgramType, - ContextGLVertexBufferFormat, - ContextWebGL, - IVertexBuffer, - ProgramWebGL, - Stage as AwayStage, - StageEvent, - TextureWebGL, - VertexBufferWebGL, - ContextGLClearMask} from '@awayjs/stage'; +import { BitmapImage2D, + ContextGLDrawMode, + ContextGLProgramType, + ContextGLVertexBufferFormat, + ContextWebGL, + Stage as AwayStage, + StageEvent, + TextureWebGL, + VertexBufferWebGL, + ContextGLClearMask, + ContextGLCompareMode, + ContextGLStencilAction, + ContextGLTriangleFace, + ContextGLBlendFactor } from '@awayjs/stage'; import { axCoerceString, Float64Vector } from '@awayfl/avm2'; import { Debug } from '@awayfl/swf-loader'; import { BitmapData } from '../display/BitmapData'; @@ -32,6 +33,11 @@ import { RectangleTexture } from './textures/RectangleTexture'; import { CubeTexture } from './textures/CubeTexture'; import { TextureBase } from './textures/TextureBase'; import { Context3DClearMask } from './Context3DClearMask'; +import { CoordinateSystem } from '@awayjs/core'; +import { Context3DTriangleFace } from './Context3DTriangleFace'; +import { Context3DCompareMode } from './Context3DCompareMode'; +import { Context3DStencilAction } from './Context3DStencilAction'; +import { Context3DBlendFactor } from './Context3DBlendFactor'; export class Context3D extends EventDispatcher { // Called whenever the class is initialized. @@ -48,42 +54,43 @@ export class Context3D extends EventDispatcher { private _gl: WebGL2RenderingContext | WebGLRenderingContext; //private _currentProgram : Program3D; - constructor(id: number, stage3D: Stage3D, renderMode: string = 'auto', profile: string = 'baseline') { + // @todo: Constructor isn't meant to be public + constructor(stage3D: Stage3D, renderMode: string = 'auto', profile: string = 'baseline') { super(); - const context3D:Context3D = this - const thisSec:SecurityDomain = (this.sec as SecurityDomain); + const context3D: Context3D = this; + const thisSec: SecurityDomain = (this.sec as SecurityDomain); console.log(`Context3D Create: ${renderMode} ${profile}`); this._profile = profile; this._adaptee = stage3D.adaptee; - function dispatchContextCreated(e:StageEvent){ - context3D.adaptee.removeEventListener(StageEvent.CONTEXT_RECREATED, dispatchContextCreated) + function dispatchContextCreated(e: StageEvent) { + context3D.adaptee.removeEventListener(StageEvent.CONTEXT_RECREATED, dispatchContextCreated); context3D.dispatchEvent(new thisSec.flash.events.Event(Event.CONTEXT3D_CREATE)); - context3D._gl = (context3D.adaptee.context as ContextWebGL)._gl; - } - this._adaptee.addEventListener(StageEvent.CONTEXT_RECREATED, dispatchContextCreated) + context3D._gl = (context3D.adaptee.context as unknown as ContextWebGL)._gl; } + this._adaptee.addEventListener(StageEvent.CONTEXT_RECREATED, dispatchContextCreated); + } public get adaptee(): AwayStage { return this._adaptee; } public get backBufferHeight(): number { - return this._adaptee.height + return this._adaptee.height; } public get backBufferWidth(): number { - return this._adaptee.width + return this._adaptee.width; } public get driverInfo(): string { - Debug.notImplemented('public flash.display3D.Context3D::get driverInfo'); - return 'OpenGL'; + Debug.notImplemented('public flash.display3D.Context3D::get driverInfo'); + return axCoerceString('OpenGL'); } public get enableErrorChecking(): boolean { - Debug.notImplemented('public flash.display3D.Context3D::get enableErrorChecking'); - return false + Debug.notImplemented('public flash.display3D.Context3D::get enableErrorChecking'); + return false; } public set enableErrorChecking(toggle: boolean) { @@ -97,7 +104,7 @@ export class Context3D extends EventDispatcher { } public set maxBackBufferWidth(value: number) { - Debug.notImplemented('public flash.display3D.Context3D::set maxBackBufferWidth'); + Debug.notImplemented('public flash.display3D.Context3D::set maxBackBufferWidth'); } public get maxBackBufferHeight(): number { @@ -105,7 +112,7 @@ export class Context3D extends EventDispatcher { } public set maxBackBufferHeight(value: number) { - Debug.notImplemented('public flash.display3D.Context3D::set maxBackBufferHeight'); + Debug.notImplemented('public flash.display3D.Context3D::set maxBackBufferHeight'); } public get profile(): string { @@ -113,13 +120,13 @@ export class Context3D extends EventDispatcher { } public static get supportsVideoTexture(): boolean { - Debug.notImplemented('public flash.display3D.Context3D::get driverInfo'); - return false;; + Debug.notImplemented('public flash.display3D.Context3D::get driverInfo'); + return false; } public get totalGPUMemory(): number { - Debug.notImplemented('public flash.display3D.Context3D::get totalGPUMemory'); - return 1024;; + Debug.notImplemented('public flash.display3D.Context3D::get totalGPUMemory'); + return 1024; } public dispose(): void { @@ -131,15 +138,15 @@ export class Context3D extends EventDispatcher { } public clear(red: number = 0.0, green: number = 0.0, blue: number = 0.0, alpha: number = 1.0, depth: number = 1.0, stencil: number = 0, mask: number = 0xffffffff): void { - - var awayMask: number = 0; - if(mask & Context3DClearMask.COLOR) + + let awayMask: number = 0; + if (mask & Context3DClearMask.COLOR) awayMask |= ContextGLClearMask.COLOR; - if(mask & Context3DClearMask.DEPTH) + if (mask & Context3DClearMask.DEPTH) awayMask |= ContextGLClearMask.DEPTH; - if(mask & Context3DClearMask.STENCIL) + if (mask & Context3DClearMask.STENCIL) awayMask |= ContextGLClearMask.STENCIL; - + this._adaptee.clear(red, green, blue, alpha, depth, stencil, awayMask); } @@ -157,7 +164,7 @@ export class Context3D extends EventDispatcher { } public setProgramConstantsFromVector(programType: string, firstRegister: number /*int*/, data: Float64Vector, numRegisters: number /*int*/ = -1): void { - var awayProgramType: ContextGLProgramType; + let awayProgramType: ContextGLProgramType; switch (programType) { case Context3DProgramType.FRAGMENT: awayProgramType = ContextGLProgramType.FRAGMENT; @@ -168,17 +175,17 @@ export class Context3D extends EventDispatcher { default: break; } - + // @todo: support transposed matrixes - var awayData:Float32Array = new Float32Array(data.length) - for(let i = 0; i < data.length; i++) - awayData[i] = data.axGetNumericProperty(i) + const awayData: Float32Array = new Float32Array(data.length); + for (let i = 0; i < data.length; i++) + awayData[i] = data.axGetNumericProperty(i); this._adaptee.context.setProgramConstantsFromArray(awayProgramType, awayData); } public setProgramConstantsFromMatrix(programType: string, firstRegister: number, matrix: Matrix3D, transposedMatrix: boolean = false): void { - var awayProgramType: ContextGLProgramType; + let awayProgramType: ContextGLProgramType; switch (programType) { case Context3DProgramType.FRAGMENT: awayProgramType = ContextGLProgramType.FRAGMENT; @@ -198,7 +205,7 @@ export class Context3D extends EventDispatcher { } public setVertexBufferAt(index: number, buffer: VertexBuffer3D, bufferOffset: number = 0, format: string = 'float4'): void { - var awayFormat: number; + let awayFormat: number; switch (format) { case Context3DVertexBufferFormat.BYTES_4: awayFormat = ContextGLVertexBufferFormat.BYTE_4; @@ -218,36 +225,286 @@ export class Context3D extends EventDispatcher { default: break; } - (this._adaptee.context as ContextWebGL).setVertexBufferAt( buffer ? index : -1, buffer ? buffer._adaptee : null, bufferOffset * 4, awayFormat, false); + (this._adaptee.context as unknown as ContextWebGL).setVertexBufferAt(buffer ? index : -1, buffer ? (buffer._adaptee as unknown as VertexBufferWebGL) : null, bufferOffset * 4, awayFormat, false); } public setBlendFactors(sourceFactor: string, destinationFactor: string): void { - Debug.notImplemented('public flash.display3D.Context3D::setBlendFactors'); return; + let awaySourceFactor: ContextGLBlendFactor; + switch (sourceFactor) { + case Context3DBlendFactor.ONE: + awaySourceFactor = ContextGLBlendFactor.ONE; + break; + case Context3DBlendFactor.ZERO: + awaySourceFactor = ContextGLBlendFactor.ZERO; + break; + case Context3DBlendFactor.SOURCE_ALPHA: + awaySourceFactor = ContextGLBlendFactor.SOURCE_ALPHA; + break; + case Context3DBlendFactor.SOURCE_COLOR: + awaySourceFactor = ContextGLBlendFactor.SOURCE_COLOR; + break; + case Context3DBlendFactor.ONE_MINUS_SOURCE_ALPHA: + awaySourceFactor = ContextGLBlendFactor.ONE_MINUS_SOURCE_ALPHA; + break; + case Context3DBlendFactor.ONE_MINUS_SOURCE_COLOR: + awaySourceFactor = ContextGLBlendFactor.ONE_MINUS_SOURCE_COLOR; + break; + case Context3DBlendFactor.DESTINATION_ALPHA: + awaySourceFactor = ContextGLBlendFactor.DESTINATION_ALPHA; + break; + case Context3DBlendFactor.DESTINATION_COLOR: + awaySourceFactor = ContextGLBlendFactor.DESTINATION_COLOR; + break; + case Context3DBlendFactor.ONE_MINUS_DESTINATION_ALPHA: + awaySourceFactor = ContextGLBlendFactor.ONE_MINUS_DESTINATION_ALPHA; + break; + case Context3DBlendFactor.ONE_MINUS_DESTINATION_COLOR: + awaySourceFactor = ContextGLBlendFactor.ONE_MINUS_DESTINATION_COLOR; + break; + default: + break; + } + + let awayDestinationFactor: ContextGLBlendFactor; + switch (destinationFactor) { + case Context3DBlendFactor.ONE: + awayDestinationFactor = ContextGLBlendFactor.ONE; + break; + case Context3DBlendFactor.ZERO: + awayDestinationFactor = ContextGLBlendFactor.ZERO; + break; + case Context3DBlendFactor.SOURCE_ALPHA: + awayDestinationFactor = ContextGLBlendFactor.SOURCE_ALPHA; + break; + case Context3DBlendFactor.SOURCE_COLOR: + awayDestinationFactor = ContextGLBlendFactor.SOURCE_COLOR; + break; + case Context3DBlendFactor.ONE_MINUS_SOURCE_ALPHA: + awayDestinationFactor = ContextGLBlendFactor.ONE_MINUS_SOURCE_ALPHA; + break; + case Context3DBlendFactor.ONE_MINUS_SOURCE_COLOR: + awayDestinationFactor = ContextGLBlendFactor.ONE_MINUS_SOURCE_COLOR; + break; + case Context3DBlendFactor.DESTINATION_ALPHA: + awayDestinationFactor = ContextGLBlendFactor.DESTINATION_ALPHA; + break; + case Context3DBlendFactor.DESTINATION_COLOR: + awayDestinationFactor = ContextGLBlendFactor.DESTINATION_COLOR; + break; + case Context3DBlendFactor.ONE_MINUS_DESTINATION_ALPHA: + awayDestinationFactor = ContextGLBlendFactor.ONE_MINUS_DESTINATION_ALPHA; + break; + case Context3DBlendFactor.ONE_MINUS_DESTINATION_COLOR: + awayDestinationFactor = ContextGLBlendFactor.ONE_MINUS_DESTINATION_COLOR; + break; + default: + break; + } + + this._adaptee.context.setBlendFactors(awaySourceFactor, awayDestinationFactor); } public setColorMask(red: boolean, green: boolean, blue: boolean, alpha: boolean): void { - Debug.notImplemented('public flash.display3D.Context3D::setColorMask'); return; + this._adaptee.context.setColorMask(red, green, blue, alpha); } - public setDepthTest(fdepthMask: boolean, passCompareMode: string): void { - Debug.notImplemented('public flash.display3D.Context3D::setDepthTest'); return; + public setDepthTest(depthMask: boolean, passCompareMode: string): void { + let awayPassCompareMode: ContextGLCompareMode = ContextGLCompareMode.ALWAYS; + switch (passCompareMode) { + case Context3DCompareMode.ALWAYS: + awayPassCompareMode = ContextGLCompareMode.ALWAYS; + break; + case Context3DCompareMode.NEVER: + awayPassCompareMode = ContextGLCompareMode.NEVER; + break; + case Context3DCompareMode.LESS: + awayPassCompareMode = ContextGLCompareMode.LESS; + break; + case Context3DCompareMode.LESS_EQUAL: + awayPassCompareMode = ContextGLCompareMode.LESS_EQUAL; + break; + case Context3DCompareMode.EQUAL: + awayPassCompareMode = ContextGLCompareMode.EQUAL; + break; + case Context3DCompareMode.GREATER_EQUAL: + awayPassCompareMode = ContextGLCompareMode.GREATER_EQUAL; + break; + case Context3DCompareMode.GREATER: + awayPassCompareMode = ContextGLCompareMode.GREATER; + break; + case Context3DCompareMode.NOT_EQUAL: + awayPassCompareMode = ContextGLCompareMode.NOT_EQUAL; + break; + default: + break; + } + this._adaptee.context.setDepthTest(depthMask, awayPassCompareMode); } public setCulling(triangleFaceToCull: string): void { - Debug.notImplemented('public flash.display3D.Context3D::setCulling'); return; + let awayTriangleFaceToCull: ContextGLTriangleFace; + switch (triangleFaceToCull) { + case Context3DTriangleFace.NONE: + awayTriangleFaceToCull = ContextGLTriangleFace.NONE; + case Context3DTriangleFace.BACK: + awayTriangleFaceToCull = ContextGLTriangleFace.BACK; + case Context3DTriangleFace.FRONT: + awayTriangleFaceToCull = ContextGLTriangleFace.FRONT; + case Context3DTriangleFace.FRONT_AND_BACK: + awayTriangleFaceToCull = ContextGLTriangleFace.FRONT_AND_BACK; + } + this._adaptee.context.setCulling(awayTriangleFaceToCull); } public setStencilActions(triangleFace: string = 'frontAndBack', compareMode: string = 'always', actionOnBothPass: string = 'keep', actionOnDepthFail: string = 'keep', actionOnDepthPassStencilFail: string = 'keep'): void { - Debug.notImplemented('public flash.display3D.Context3D::setStencilActions'); return; + let awayTriangleFace: ContextGLTriangleFace = ContextGLTriangleFace.FRONT_AND_BACK; + switch (triangleFace) { + case Context3DTriangleFace.BACK: + awayTriangleFace = ContextGLTriangleFace.BACK; + break; + case Context3DTriangleFace.FRONT: + awayTriangleFace = ContextGLTriangleFace.FRONT; + break; + case Context3DTriangleFace.FRONT_AND_BACK: + awayTriangleFace = ContextGLTriangleFace.FRONT_AND_BACK; + break; + case Context3DTriangleFace.NONE: + awayTriangleFace = ContextGLTriangleFace.NONE; + break; + default: + break; + } + + let awayCompareMode: ContextGLCompareMode = ContextGLCompareMode.ALWAYS; + switch (compareMode) { + case Context3DCompareMode.ALWAYS: + awayCompareMode = ContextGLCompareMode.ALWAYS; + break; + case Context3DCompareMode.NEVER: + awayCompareMode = ContextGLCompareMode.NEVER; + break; + case Context3DCompareMode.LESS: + awayCompareMode = ContextGLCompareMode.LESS; + break; + case Context3DCompareMode.LESS_EQUAL: + awayCompareMode = ContextGLCompareMode.LESS_EQUAL; + break; + case Context3DCompareMode.EQUAL: + awayCompareMode = ContextGLCompareMode.EQUAL; + break; + case Context3DCompareMode.GREATER_EQUAL: + awayCompareMode = ContextGLCompareMode.GREATER_EQUAL; + break; + case Context3DCompareMode.GREATER: + awayCompareMode = ContextGLCompareMode.GREATER; + break; + case Context3DCompareMode.NOT_EQUAL: + awayCompareMode = ContextGLCompareMode.NOT_EQUAL; + break; + default: + break; + } + + let awayActionOnBothPass: ContextGLStencilAction = ContextGLStencilAction.KEEP; + switch (actionOnBothPass) { + case Context3DStencilAction.DECREMENT_SATURATE: + awayActionOnBothPass = ContextGLStencilAction.DECREMENT_SATURATE; + break; + case Context3DStencilAction.DECREMENT_WRAP: + awayActionOnBothPass = ContextGLStencilAction.DECREMENT_WRAP; + break; + case Context3DStencilAction.INCREMENT_SATURATE: + awayActionOnBothPass = ContextGLStencilAction.INCREMENT_SATURATE; + break; + case Context3DStencilAction.INCREMENT_WRAP: + awayActionOnBothPass = ContextGLStencilAction.INCREMENT_WRAP; + break; + case Context3DStencilAction.INVERT: + awayActionOnBothPass = ContextGLStencilAction.INVERT; + break; + case Context3DStencilAction.KEEP: + awayActionOnBothPass = ContextGLStencilAction.KEEP; + break; + case Context3DStencilAction.SET: + awayActionOnBothPass = ContextGLStencilAction.SET; + break; + case Context3DStencilAction.ZERO: + awayActionOnBothPass = ContextGLStencilAction.ZERO; + break; + default: + break; + } + + let awayActionOnDepthFail: ContextGLStencilAction = ContextGLStencilAction.KEEP; + switch (actionOnDepthFail) { + case Context3DStencilAction.DECREMENT_SATURATE: + awayActionOnDepthFail = ContextGLStencilAction.DECREMENT_SATURATE; + break; + case Context3DStencilAction.DECREMENT_WRAP: + awayActionOnDepthFail = ContextGLStencilAction.DECREMENT_WRAP; + break; + case Context3DStencilAction.INCREMENT_SATURATE: + awayActionOnDepthFail = ContextGLStencilAction.INCREMENT_SATURATE; + break; + case Context3DStencilAction.INCREMENT_WRAP: + awayActionOnDepthFail = ContextGLStencilAction.INCREMENT_WRAP; + break; + case Context3DStencilAction.INVERT: + awayActionOnDepthFail = ContextGLStencilAction.INVERT; + break; + case Context3DStencilAction.KEEP: + awayActionOnDepthFail = ContextGLStencilAction.KEEP; + break; + case Context3DStencilAction.SET: + awayActionOnDepthFail = ContextGLStencilAction.SET; + break; + case Context3DStencilAction.ZERO: + awayActionOnDepthFail = ContextGLStencilAction.ZERO; + break; + default: + break; + } + + let awayActionOnDepthPassStencilFail: ContextGLStencilAction = ContextGLStencilAction.KEEP; + switch (actionOnDepthPassStencilFail) { + case Context3DStencilAction.DECREMENT_SATURATE: + awayActionOnDepthPassStencilFail = ContextGLStencilAction.DECREMENT_SATURATE; + break; + case Context3DStencilAction.DECREMENT_WRAP: + awayActionOnDepthPassStencilFail = ContextGLStencilAction.DECREMENT_WRAP; + break; + case Context3DStencilAction.INCREMENT_SATURATE: + awayActionOnDepthPassStencilFail = ContextGLStencilAction.INCREMENT_SATURATE; + break; + case Context3DStencilAction.INCREMENT_WRAP: + awayActionOnDepthPassStencilFail = ContextGLStencilAction.INCREMENT_WRAP; + break; + case Context3DStencilAction.INVERT: + awayActionOnDepthPassStencilFail = ContextGLStencilAction.INVERT; + break; + case Context3DStencilAction.KEEP: + awayActionOnDepthPassStencilFail = ContextGLStencilAction.KEEP; + break; + case Context3DStencilAction.SET: + awayActionOnDepthPassStencilFail = ContextGLStencilAction.SET; + break; + case Context3DStencilAction.ZERO: + awayActionOnDepthPassStencilFail = ContextGLStencilAction.ZERO; + break; + default: + break; + } + + this._adaptee.context.setStencilActions(awayTriangleFace, awayCompareMode, awayActionOnBothPass, awayActionOnDepthFail, awayActionOnDepthPassStencilFail, CoordinateSystem.LEFT_HANDED); } public setStencilReferenceValue(referenceValue: number /*uint*/, readMask: number /*uint*/ = 255, writeMask: number /*uint*/ = 255): void { - Debug.notImplemented('public flash.display3D.Context3D::setStencilReferenceValue'); return; + this._adaptee.context.setStencilReferenceValue(referenceValue, readMask, writeMask); } public setScissorRectangle(rectangle: Rectangle): void { - (this._adaptee.context as ContextWebGL).setScissorRectangle(rectangle.adaptee); + this._adaptee.context.setScissorRectangle(rectangle ? rectangle.adaptee : null); } public createVertexBuffer(numVertices: number, data32PerVertex: number, bufferUsage: string = 'staticDraw'): VertexBuffer3D { @@ -268,7 +525,7 @@ export class Context3D extends EventDispatcher { } public createCubeTexture(size: number /*int*/, format: string, optimizeForRenderToTexture: boolean, streamingLevels: number /*int*/ = 0): CubeTexture /*CubeTexture*/ { - return new (this.sec as SecurityDomain).flash.display3D.textures.CubeTexture(this, size, format, optimizeForRenderToTexture, streamingLevels) + return new (this.sec as SecurityDomain).flash.display3D.textures.CubeTexture(this, size, format, optimizeForRenderToTexture, streamingLevels); } public createProgram(): Program3D { @@ -276,19 +533,19 @@ export class Context3D extends EventDispatcher { } public drawToBitmapData(destination: BitmapData): void { - this.adaptee.context.drawToBitmapImage2D(destination.adaptee as any as BitmapImage2D); + this.adaptee.context.drawToBitmapImage2D(destination.adaptee as unknown as BitmapImage2D); } public setRenderToBackBuffer(): void { this._adaptee.context.setRenderToBackBuffer(); } - public setRenderToTexture(texture:TextureBase, targetType: number /*int*/, enableDepthAndStencil: boolean, antiAlias: number /*int*/, surfaceSelector: number /*int*/): void { + public setRenderToTexture(texture: TextureBase, targetType: number /*int*/, enableDepthAndStencil: boolean, antiAlias: number /*int*/, surfaceSelector: number /*int*/): void { this._adaptee.context.setRenderToTexture(texture._adaptee, enableDepthAndStencil, antiAlias, surfaceSelector); } public setTextureAt(sampler: number /*int*/, texture: TextureBase): void { - if(texture) - this._adaptee.context.setTextureAt(sampler, texture._adaptee) + if (texture) + this._adaptee.context.setTextureAt(sampler, texture._adaptee); } } \ No newline at end of file diff --git a/lib/display3D/Context3DCompareMode.ts b/lib/display3D/Context3DCompareMode.ts index e5063d09..bac90ebb 100644 --- a/lib/display3D/Context3DCompareMode.ts +++ b/lib/display3D/Context3DCompareMode.ts @@ -14,28 +14,27 @@ * limitations under the License. */ -import { ASObject } from "@awayfl/avm2"; +import { ASObject } from '@awayfl/avm2'; - export class Context3DCompareMode extends ASObject { +export class Context3DCompareMode extends ASObject { - // Called whenever the class is initialized. - static classInitializer: any = null; + // Called whenever the class is initialized. + static classInitializer: any = null; - constructor () { - super(); - } - - // JS -> AS Bindings - static ALWAYS: string = 'always'; - static NEVER: string = 'never'; - static LESS: string = 'less'; - static LESS_EQUAL: string = 'lessEqual'; - static EQUAL: string = 'equal'; - static GREATER_EQUAL: string = 'greaterEqual'; - static GREATER: string = 'greater'; - static NOT_EQUAL: string = 'notEqual'; + constructor () { + super(); + } - // AS -> JS Bindings + // JS -> AS Bindings + static ALWAYS: string = 'always'; + static NEVER: string = 'never'; + static LESS: string = 'less'; + static LESS_EQUAL: string = 'lessEqual'; + static EQUAL: string = 'equal'; + static GREATER_EQUAL: string = 'greaterEqual'; + static GREATER: string = 'greater'; + static NOT_EQUAL: string = 'notEqual'; - } + // AS -> JS Bindings +} diff --git a/lib/display3D/Context3DStencilAction.ts b/lib/display3D/Context3DStencilAction.ts index 90576f56..93d744af 100644 --- a/lib/display3D/Context3DStencilAction.ts +++ b/lib/display3D/Context3DStencilAction.ts @@ -14,28 +14,28 @@ * limitations under the License. */ -import { ASObject } from "@awayfl/avm2"; +import { ASObject } from '@awayfl/avm2'; // Class: Context3DStencilAction export class Context3DStencilAction extends ASObject { - // Called whenever the class is initialized. - static classInitializer: any = null; + // Called whenever the class is initialized. + static classInitializer: any = null; - constructor () { - super(); - } + constructor () { + super(); + } - // JS -> AS Bindings - static KEEP: string = 'keep'; - static ZERO: string = 'zero'; - static INCREMENT_SATURATE: string = 'incrementSaturate'; - static DECREMENT_SATURATE: string = 'decrementSaturate'; - static INVERT: string = 'invert'; - static INCREMENT_WRAP: string = 'incrementWrap'; - static DECREMENT_WRAP: string = 'decrementWrap'; - static SET: string = 'set'; + // JS -> AS Bindings + static KEEP: string = 'keep'; + static ZERO: string = 'zero'; + static INCREMENT_SATURATE: string = 'incrementSaturate'; + static DECREMENT_SATURATE: string = 'decrementSaturate'; + static INVERT: string = 'invert'; + static INCREMENT_WRAP: string = 'incrementWrap'; + static DECREMENT_WRAP: string = 'decrementWrap'; + static SET: string = 'set'; - // AS -> JS Bindings + // AS -> JS Bindings - } +} diff --git a/lib/display3D/Context3DTextureFormat.ts b/lib/display3D/Context3DTextureFormat.ts index 7390d296..f38f3dd6 100644 --- a/lib/display3D/Context3DTextureFormat.ts +++ b/lib/display3D/Context3DTextureFormat.ts @@ -1,4 +1,4 @@ -import { ASObject } from "@awayfl/avm2"; +import { ASObject } from '@awayfl/avm2'; /** * Copyright 2014 Mozilla Foundation @@ -15,21 +15,20 @@ import { ASObject } from "@awayfl/avm2"; * See the License for the specific language governing permissions and * limitations under the License. */ - export class Context3DTextureFormat extends ASObject { +export class Context3DTextureFormat extends ASObject { - // Called whenever the class is initialized. - static classInitializer: any = null; - - constructor () { - super(); - } + // Called whenever the class is initialized. + static classInitializer: any = null; - // JS -> AS Bindings - static BGRA: string = 'bgra'; - static COMPRESSED: string = 'compressed'; - static COMPRESSED_ALPHA: string = 'compressedAlpha'; + constructor () { + super(); + } - // AS -> JS Bindings + // JS -> AS Bindings + static BGRA: string = 'bgra'; + static COMPRESSED: string = 'compressed'; + static COMPRESSED_ALPHA: string = 'compressedAlpha'; - } + // AS -> JS Bindings +} diff --git a/lib/display3D/Context3DTriangleFace.ts b/lib/display3D/Context3DTriangleFace.ts index d6d3d7bd..f9558329 100644 --- a/lib/display3D/Context3DTriangleFace.ts +++ b/lib/display3D/Context3DTriangleFace.ts @@ -15,23 +15,23 @@ */ // Class: Context3DTriangleFace -import { ASObject } from "@awayfl/avm2"; +import { ASObject } from '@awayfl/avm2'; - export class Context3DTriangleFace extends ASObject { +export class Context3DTriangleFace extends ASObject { - // Called whenever the class is initialized. - static classInitializer: any = null; + // Called whenever the class is initialized. + static classInitializer: any = null; - constructor () { - super(); - } + constructor () { + super(); + } - // JS -> AS Bindings - static NONE: string = 'none'; - static BACK: string = 'back'; - static FRONT: string = 'front'; - static FRONT_AND_BACK: string = 'frontAndBack'; + // JS -> AS Bindings + static NONE: string = 'none'; + static BACK: string = 'back'; + static FRONT: string = 'front'; + static FRONT_AND_BACK: string = 'frontAndBack'; - // AS -> JS Bindings + // AS -> JS Bindings - } +} diff --git a/lib/display3D/textures/CubeTexture.ts b/lib/display3D/textures/CubeTexture.ts index 216d70ec..ac472f20 100644 --- a/lib/display3D/textures/CubeTexture.ts +++ b/lib/display3D/textures/CubeTexture.ts @@ -14,12 +14,12 @@ * limitations under the License. */ // Class: CubeTexture -import { Debug } from "@awayfl/swf-loader"; -import { ContextGLTextureFormat, CubeTextureWebGL, TextureWebGL } from "@awayjs/stage"; -import { Context3D } from "../Context3D"; -import { BitmapData } from "./../../display/BitmapData"; -import { ByteArray } from "./../../utils/ByteArray"; -import { TextureBase } from "./TextureBase"; +import { Debug } from '@awayfl/swf-loader'; +import { ContextGLTextureFormat, CubeTextureWebGL, TextureWebGL } from '@awayjs/stage'; +import { Context3D } from '../Context3D'; +import { BitmapData } from './../../display/BitmapData'; +import { ByteArray } from './../../utils/ByteArray'; +import { TextureBase } from './TextureBase'; export class CubeTexture extends TextureBase { // Called whenever the class is initialized. @@ -35,13 +35,13 @@ export class CubeTexture extends TextureBase { super(); let awayTextureFormat: ContextGLTextureFormat; switch (format) { - case "bgra": + case 'bgra': awayTextureFormat = ContextGLTextureFormat.BGRA; break; - case "compressed": + case 'compressed': awayTextureFormat = ContextGLTextureFormat.COMPRESSED; break; - case "compressedAlpha": + case 'compressedAlpha': awayTextureFormat = ContextGLTextureFormat.COMPRESSED_ALPHA; break; } @@ -54,14 +54,14 @@ export class CubeTexture extends TextureBase { } public uploadFromBitmapData(source: BitmapData, side: number /*uint*/, miplevel: number /*uint*/ = 0): void { - if(miplevel==0) // @todo: Additional Mips cause errors - (this._adaptee).uploadFromArray(new Uint8Array(source.adaptee.getDataInternal()), side, miplevel) + if (miplevel == 0) // @todo: Additional Mips cause errors + ( this._adaptee).uploadFromArray(new Uint8Array(source.adaptee.getDataInternal()), side, miplevel); } public uploadFromByteArray(data: ByteArray,byteArrayOffset: number /*uint*/,side: number /*uint*/,miplevel: number /*uint*/ = 0 ): void { - if(miplevel==0) // @todo: Additional Mips cause errors - (this._adaptee).uploadFromArray(new Uint8Array(data.arraybytes), side, miplevel) + if (miplevel == 0) // @todo: Additional Mips cause errors + ( this._adaptee).uploadFromArray(new Uint8Array(data.arraybytes), side, miplevel); } public uploadCompressedTextureFromByteArray(data: ByteArray,byteArrayOffset: number /*uint*/,async: boolean = false @@ -69,7 +69,7 @@ export class CubeTexture extends TextureBase { data = data; byteArrayOffset = byteArrayOffset >>> 0; async = !!async; - Debug.notImplemented("public flash.display3D.textures.CubeTexture::uploadCompressedTextureFromByteArray"); + Debug.notImplemented('public flash.display3D.textures.CubeTexture::uploadCompressedTextureFromByteArray'); return; } } diff --git a/lib/display3D/textures/RectangleTexture.ts b/lib/display3D/textures/RectangleTexture.ts index 5111e562..76c88c84 100644 --- a/lib/display3D/textures/RectangleTexture.ts +++ b/lib/display3D/textures/RectangleTexture.ts @@ -1,9 +1,9 @@ -import { Debug } from "@awayfl/swf-loader"; -import { ContextGLTextureFormat, TextureWebGL } from "@awayjs/stage"; -import { Context3D } from "../Context3D"; -import { BitmapData } from "./../../display/BitmapData"; -import { ByteArray } from "./../../utils/ByteArray"; -import { TextureBase } from "./TextureBase"; +import { Debug } from '@awayfl/swf-loader'; +import { ContextGLTextureFormat, TextureWebGL } from '@awayjs/stage'; +import { Context3D } from '../Context3D'; +import { BitmapData } from './../../display/BitmapData'; +import { ByteArray } from './../../utils/ByteArray'; +import { TextureBase } from './TextureBase'; export class RectangleTexture extends TextureBase { constructor( @@ -17,13 +17,13 @@ export class RectangleTexture extends TextureBase { super(); let awayTextureFormat: ContextGLTextureFormat; switch (format) { - case "bgra": + case 'bgra': awayTextureFormat = ContextGLTextureFormat.BGRA; break; - case "compressed": + case 'compressed': awayTextureFormat = ContextGLTextureFormat.COMPRESSED; break; - case "compressedAlpha": + case 'compressedAlpha': awayTextureFormat = ContextGLTextureFormat.COMPRESSED_ALPHA; break; } @@ -36,16 +36,16 @@ export class RectangleTexture extends TextureBase { } public uploadCompressedTextureFromByteArray(data: ByteArray, byteArrayOffset: number, async: boolean = false) { - Debug.notImplemented("public flash.display3D.textures.Texture::uploadCompressedTextureFromByteArray"); + Debug.notImplemented('public flash.display3D.textures.Texture::uploadCompressedTextureFromByteArray'); } public uploadFromBitmapData(source: BitmapData, miplevel: number = 0) { - if(miplevel==0) // @todo: Additional Mips cause errors - (this._adaptee).uploadFromArray(new Uint8Array(source.adaptee.getDataInternal()), miplevel); + if (miplevel == 0) // @todo: Additional Mips cause errors + ( this._adaptee).uploadFromArray(new Uint8Array(source.adaptee.getDataInternal()), miplevel); } public uploadFromByteArray(data: ByteArray, byteArrayOffset: number, miplevel: number = 0) { - if(miplevel==0) // @todo: Additional Mips cause errors - (this._adaptee).uploadFromArray(new Uint8Array(data.arraybytes), miplevel); + if (miplevel == 0) // @todo: Additional Mips cause errors + ( this._adaptee).uploadFromArray(new Uint8Array(data.arraybytes), miplevel); } } diff --git a/lib/display3D/textures/Texture.ts b/lib/display3D/textures/Texture.ts index a72acd72..3731a725 100644 --- a/lib/display3D/textures/Texture.ts +++ b/lib/display3D/textures/Texture.ts @@ -1,9 +1,9 @@ -import { Debug } from "@awayfl/swf-loader"; -import { ContextGLTextureFormat, TextureWebGL } from "@awayjs/stage"; -import { Context3D } from "../Context3D"; -import { BitmapData } from "./../../display/BitmapData"; -import { ByteArray } from "./../../utils/ByteArray"; -import { TextureBase } from "./TextureBase"; +import { Debug } from '@awayfl/swf-loader'; +import { ContextGLTextureFormat, TextureWebGL } from '@awayjs/stage'; +import { Context3D } from '../Context3D'; +import { BitmapData } from './../../display/BitmapData'; +import { ByteArray } from './../../utils/ByteArray'; +import { TextureBase } from './TextureBase'; export class Texture extends TextureBase { constructor( context: Context3D, @@ -16,13 +16,13 @@ export class Texture extends TextureBase { super(); let awayTextureFormat: ContextGLTextureFormat; switch (format) { - case "bgra": + case 'bgra': awayTextureFormat = ContextGLTextureFormat.BGRA; break; - case "compressed": + case 'compressed': awayTextureFormat = ContextGLTextureFormat.COMPRESSED; break; - case "compressedAlpha": + case 'compressedAlpha': awayTextureFormat = ContextGLTextureFormat.COMPRESSED_ALPHA; break; } @@ -35,16 +35,16 @@ export class Texture extends TextureBase { } public uploadCompressedTextureFromByteArray(data: ByteArray, byteArrayOffset: number, async: boolean = false) { - Debug.notImplemented("public flash.display3D.textures.Texture::uploadCompressedTextureFromByteArray"); + Debug.notImplemented('public flash.display3D.textures.Texture::uploadCompressedTextureFromByteArray'); } public uploadFromBitmapData(source: BitmapData, miplevel: number = 0) { - if(miplevel==0) // @todo: Additional Mips cause errors - (this._adaptee).uploadFromArray(new Uint8Array(source.adaptee.getDataInternal()), miplevel); + if (miplevel == 0) // @todo: Additional Mips cause errors + ( this._adaptee).uploadFromArray(new Uint8Array(source.adaptee.getDataInternal()), miplevel); } public uploadFromByteArray(data: ByteArray, byteArrayOffset: number, miplevel: number = 0) { - if(miplevel==0) // @todo: Additional Mips cause errors - (this._adaptee).uploadFromArray(new Uint8Array(data.arraybytes), miplevel); + if (miplevel == 0) // @todo: Additional Mips cause errors + ( this._adaptee).uploadFromArray(new Uint8Array(data.arraybytes), miplevel); } } From 46746987a3cf103657f775ca550faa3437f20db7 Mon Sep 17 00:00:00 2001 From: Fancy2209 Date: Fri, 28 Mar 2025 22:49:57 -0100 Subject: [PATCH 46/59] Dispatch event every time the context is recreated --- lib/display/Stage3D.ts | 16 ++++++++-------- lib/display3D/Context3D.ts | 2 -- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/display/Stage3D.ts b/lib/display/Stage3D.ts index e337397c..f4b85ea7 100644 --- a/lib/display/Stage3D.ts +++ b/lib/display/Stage3D.ts @@ -59,9 +59,16 @@ export class Stage3D extends EventDispatcher { public requestContext3D(context3DRenderMode: string = 'auto', profile: string = 'baseline'): void { const stage3D: Stage3D = this; + this._context3D = new (stage3D.sec as SecurityDomain).flash.display3D.Context3D(this, context3DRenderMode, profile); + + function dispatchContextCreated(e: Event) { + stage3D._context3D.removeEventListener(Event.CONTEXT3D_CREATE, dispatchContextCreated); + stage3D.dispatchEvent(new (stage3D.sec).flash.events.Event(Event.CONTEXT3D_CREATE)); + } + + this._context3D.addEventListener(Event.CONTEXT3D_CREATE, dispatchContextCreated); setTimeout(function() { console.log('Request Context'); - stage3D._context3D = new (stage3D.sec as SecurityDomain).flash.display3D.Context3D(stage3D, profile, context3DRenderMode); const forceSoftware: boolean = (context3DRenderMode == 'software'); let awayContextProfile: ContextGLProfile = ContextGLProfile.BASELINE; switch (profile) { @@ -90,13 +97,6 @@ export class Stage3D extends EventDispatcher { break; } console.log('Context3D Config: ', 'forceSoftware: ', forceSoftware, ' profile: ', profile); - function dispatchContextCreated(e: Event) { - console.log(stage3D.context3D.driverInfo); - stage3D._context3D.removeEventListener(Event.CONTEXT3D_CREATE, dispatchContextCreated); - stage3D.dispatchEvent(new (stage3D.sec).flash.events.Event(Event.CONTEXT3D_CREATE)); - } - - stage3D._context3D.addEventListener(Event.CONTEXT3D_CREATE, dispatchContextCreated); stage3D._adaptee.requestContext(forceSoftware, awayContextProfile); } , 0); } diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index 183bece9..2c642039 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -64,7 +64,6 @@ export class Context3D extends EventDispatcher { this._profile = profile; this._adaptee = stage3D.adaptee; function dispatchContextCreated(e: StageEvent) { - context3D.adaptee.removeEventListener(StageEvent.CONTEXT_RECREATED, dispatchContextCreated); context3D.dispatchEvent(new thisSec.flash.events.Event(Event.CONTEXT3D_CREATE)); context3D._gl = (context3D.adaptee.context as unknown as ContextWebGL)._gl; } @@ -120,7 +119,6 @@ export class Context3D extends EventDispatcher { } public static get supportsVideoTexture(): boolean { - Debug.notImplemented('public flash.display3D.Context3D::get driverInfo'); return false; } From b4135986d9f33ee262a685f984c9e6ffb14bd856 Mon Sep 17 00:00:00 2001 From: Fancy2209 Date: Wed, 8 Oct 2025 13:06:37 +0000 Subject: [PATCH 47/59] Fix mistakes when rebasing --- lib/display/LoaderInfo.ts | 8 +++----- lib/link.ts | 7 +++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/display/LoaderInfo.ts b/lib/display/LoaderInfo.ts index faa4e695..d95e8731 100644 --- a/lib/display/LoaderInfo.ts +++ b/lib/display/LoaderInfo.ts @@ -12,6 +12,7 @@ import { DisplayObject as AwayDisplayObject } from '@awayjs/scene'; import { SecurityDomain } from '../SecurityDomain'; import { PickGroup } from '@awayjs/view'; import { AVMStage } from '@awayfl/swf-loader'; +import { UncaughtErrorEvents } from '../events/UncaughtErrorEvents'; interface LoaderInfoCompleteQueueItem { loaderInfo: LoaderInfo; @@ -636,11 +637,8 @@ export class LoaderInfo extends EventDispatcher { * `uncaughtErrorEvents` property is available after the * `applicationComplete` event is dispatched. */ - public get uncaughtErrorEvents(): any { - // @todo - Debug.throwPIR('playerglobals/display/LoaderInfo', 'get uncaughtErrorEvents', ''); - return null; - + public get uncaughtErrorEvents(): UncaughtErrorEvents { + return this._loader.uncaughtErrorEvents; } /** diff --git a/lib/link.ts b/lib/link.ts index 978aa455..e7bc8d7d 100644 --- a/lib/link.ts +++ b/lib/link.ts @@ -129,15 +129,14 @@ import { SoundMixer } from './media/SoundMixer'; import { FileFilter } from './net/FileFilter'; import { FileReference } from './net/FileReference'; -import { LocalConnection } from './net/LocalConnection'; -import { NetConnection } from './net/NetConnection'; -import { Responder } from './net/Responder'; -import { Socket } from './net/Socket'; import { SharedObject } from './net/SharedObject'; import { URLRequest } from './net/URLRequest'; import { URLLoader } from './net/URLLoader'; import { URLVariables } from './net/URLVariables'; import { LocalConnection } from './net/LocalConnection'; +import { NetConnection } from './net/NetConnection'; +import { Responder } from './net/Responder'; +import { Socket } from './net/Socket'; import { SecurityDomain } from './system/SecurityDomain'; import { Capabilities } from './system/Capabilities'; From c67b46087e8d6f71babc4cde48b0932763e8ff68 Mon Sep 17 00:00:00 2001 From: Fancy2209 Date: Wed, 8 Oct 2025 14:34:00 +0000 Subject: [PATCH 48/59] Add missing breaks to Context3D.setCulling() --- lib/display3D/Context3D.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index 2c642039..c9ed77c9 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -345,12 +345,16 @@ export class Context3D extends EventDispatcher { switch (triangleFaceToCull) { case Context3DTriangleFace.NONE: awayTriangleFaceToCull = ContextGLTriangleFace.NONE; + break; case Context3DTriangleFace.BACK: awayTriangleFaceToCull = ContextGLTriangleFace.BACK; + break; case Context3DTriangleFace.FRONT: awayTriangleFaceToCull = ContextGLTriangleFace.FRONT; + break; case Context3DTriangleFace.FRONT_AND_BACK: awayTriangleFaceToCull = ContextGLTriangleFace.FRONT_AND_BACK; + break; } this._adaptee.context.setCulling(awayTriangleFaceToCull); } From 418e85adf0e28897a3ad0905e3f17ba10abede97 Mon Sep 17 00:00:00 2001 From: Fancy2209 Date: Wed, 8 Oct 2025 21:24:05 +0000 Subject: [PATCH 49/59] Fix Sending Constants --- lib/display3D/Context3D.ts | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index c9ed77c9..31658cdb 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -52,6 +52,7 @@ export class Context3D extends EventDispatcher { private _adaptee: AwayStage; private _profile: string; private _gl: WebGL2RenderingContext | WebGLRenderingContext; + private _programConstants = []; //private _currentProgram : Program3D; // @todo: Constructor isn't meant to be public @@ -153,6 +154,7 @@ export class Context3D extends EventDispatcher { } public present(): void { + this._programConstants.length = 0; this._adaptee.present(); } @@ -175,11 +177,14 @@ export class Context3D extends EventDispatcher { } // @todo: support transposed matrixes - const awayData: Float32Array = new Float32Array(data.length); + let awayData = []; + awayData.length = data.length; for (let i = 0; i < data.length; i++) awayData[i] = data.axGetNumericProperty(i); - this._adaptee.context.setProgramConstantsFromArray(awayProgramType, awayData); + this._programConstants.length++; + this._programConstants[firstRegister] = awayData; + this._adaptee.context.setProgramConstantsFromArray(awayProgramType, new Float32Array(this._programConstants.flat())); } public setProgramConstantsFromMatrix(programType: string, firstRegister: number, matrix: Matrix3D, transposedMatrix: boolean = false): void { @@ -195,7 +200,12 @@ export class Context3D extends EventDispatcher { break; } // @todo: support transposed matrixes - this._adaptee.context.setProgramConstantsFromArray(awayProgramType, matrix.adaptee._rawData); + this._programConstants.length += 4; + + for(let i = 0; i < 4; i++) + this._programConstants[firstRegister+i] = [matrix.adaptee._rawData[i], matrix.adaptee._rawData[i+4], matrix.adaptee._rawData[i+8], matrix.adaptee._rawData[i+12]]; + + this._adaptee.context.setProgramConstantsFromArray(awayProgramType, new Float32Array(this._programConstants.flat())); } public setProgramConstantsFromByteArray(programType: string, firstRegister: number /*int*/, numRegisters: number /*int*/, data: ByteArray, byteArrayOffset: number /*uint*/): void { @@ -223,7 +233,7 @@ export class Context3D extends EventDispatcher { default: break; } - (this._adaptee.context as unknown as ContextWebGL).setVertexBufferAt(buffer ? index : -1, buffer ? (buffer._adaptee as unknown as VertexBufferWebGL) : null, bufferOffset * 4, awayFormat, false); + this._adaptee.context.setVertexBufferAt(buffer ? index : -1, buffer?._adaptee, bufferOffset * 4, awayFormat); } @@ -543,11 +553,10 @@ export class Context3D extends EventDispatcher { } public setRenderToTexture(texture: TextureBase, targetType: number /*int*/, enableDepthAndStencil: boolean, antiAlias: number /*int*/, surfaceSelector: number /*int*/): void { - this._adaptee.context.setRenderToTexture(texture._adaptee, enableDepthAndStencil, antiAlias, surfaceSelector); + this._adaptee.context.setRenderToTexture(texture?._adaptee, enableDepthAndStencil, antiAlias, surfaceSelector); } public setTextureAt(sampler: number /*int*/, texture: TextureBase): void { - if (texture) - this._adaptee.context.setTextureAt(sampler, texture._adaptee); + this._adaptee.context.setTextureAt(sampler, texture?._adaptee); } } \ No newline at end of file From 210603453a926fdc844ef21a97f395cb398aab01 Mon Sep 17 00:00:00 2001 From: Fancy2209 Date: Wed, 8 Oct 2025 22:02:23 +0000 Subject: [PATCH 50/59] Properly separate fragment and vertex constants --- lib/display3D/Context3D.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index 31658cdb..a1f519e7 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -52,7 +52,8 @@ export class Context3D extends EventDispatcher { private _adaptee: AwayStage; private _profile: string; private _gl: WebGL2RenderingContext | WebGLRenderingContext; - private _programConstants = []; + private _fragmentProgramConstants = []; + private _vertexProgramConstants = []; //private _currentProgram : Program3D; // @todo: Constructor isn't meant to be public @@ -151,10 +152,11 @@ export class Context3D extends EventDispatcher { public drawTriangles(indexBuffer: IndexBuffer3D, firstIndex: number = 0, numTriangles: number = -1): void { this._adaptee.context.drawIndices(ContextGLDrawMode.TRIANGLES, indexBuffer._adaptee, firstIndex, (numTriangles == -1) ? -1 : (numTriangles * 3)); + this._vertexProgramConstants.length = 0; + this._fragmentProgramConstants.length = 0; } public present(): void { - this._programConstants.length = 0; this._adaptee.present(); } @@ -181,10 +183,9 @@ export class Context3D extends EventDispatcher { awayData.length = data.length; for (let i = 0; i < data.length; i++) awayData[i] = data.axGetNumericProperty(i); - - this._programConstants.length++; - this._programConstants[firstRegister] = awayData; - this._adaptee.context.setProgramConstantsFromArray(awayProgramType, new Float32Array(this._programConstants.flat())); + let programConstants = (programType == Context3DProgramType.FRAGMENT) ? this._fragmentProgramConstants : this._vertexProgramConstants; + programConstants[firstRegister] = awayData; + this._adaptee.context.setProgramConstantsFromArray(awayProgramType, new Float32Array(programConstants.flat())); } public setProgramConstantsFromMatrix(programType: string, firstRegister: number, matrix: Matrix3D, transposedMatrix: boolean = false): void { @@ -199,13 +200,13 @@ export class Context3D extends EventDispatcher { default: break; } + let programConstants = (programType == Context3DProgramType.FRAGMENT) ? this._fragmentProgramConstants : this._vertexProgramConstants; // @todo: support transposed matrixes - this._programConstants.length += 4; for(let i = 0; i < 4; i++) - this._programConstants[firstRegister+i] = [matrix.adaptee._rawData[i], matrix.adaptee._rawData[i+4], matrix.adaptee._rawData[i+8], matrix.adaptee._rawData[i+12]]; + programConstants[firstRegister+i] = [matrix.adaptee._rawData[i], matrix.adaptee._rawData[i+4], matrix.adaptee._rawData[i+8], matrix.adaptee._rawData[i+12]]; - this._adaptee.context.setProgramConstantsFromArray(awayProgramType, new Float32Array(this._programConstants.flat())); + this._adaptee.context.setProgramConstantsFromArray(awayProgramType, new Float32Array(programConstants.flat())); } public setProgramConstantsFromByteArray(programType: string, firstRegister: number /*int*/, numRegisters: number /*int*/, data: ByteArray, byteArrayOffset: number /*uint*/): void { @@ -520,7 +521,6 @@ export class Context3D extends EventDispatcher { } public createVertexBuffer(numVertices: number, data32PerVertex: number, bufferUsage: string = 'staticDraw'): VertexBuffer3D { - console.log('createVertexBuffer'); return new (this.sec as SecurityDomain).flash.display3D.VertexBuffer3D(this, numVertices, data32PerVertex); } From 9f7810ca2611d3f09e10fa77608a47b46413101b Mon Sep 17 00:00:00 2001 From: Fancy2209 <64917206+Fancy2209@users.noreply.github.com> Date: Thu, 9 Oct 2025 08:54:45 +0000 Subject: [PATCH 51/59] Add transposed matrix support to Context3D.uploadConstantsFromMatrix() --- lib/display3D/Context3D.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index a1f519e7..80935024 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -52,9 +52,11 @@ export class Context3D extends EventDispatcher { private _adaptee: AwayStage; private _profile: string; private _gl: WebGL2RenderingContext | WebGLRenderingContext; + + // Due to how AwayJS works, we need to submit a flat array of vectors + // We use these to make sure they're submitted in the right place private _fragmentProgramConstants = []; private _vertexProgramConstants = []; - //private _currentProgram : Program3D; // @todo: Constructor isn't meant to be public constructor(stage3D: Stage3D, renderMode: string = 'auto', profile: string = 'baseline') { @@ -180,7 +182,6 @@ export class Context3D extends EventDispatcher { // @todo: support transposed matrixes let awayData = []; - awayData.length = data.length; for (let i = 0; i < data.length; i++) awayData[i] = data.axGetNumericProperty(i); let programConstants = (programType == Context3DProgramType.FRAGMENT) ? this._fragmentProgramConstants : this._vertexProgramConstants; @@ -201,10 +202,17 @@ export class Context3D extends EventDispatcher { break; } let programConstants = (programType == Context3DProgramType.FRAGMENT) ? this._fragmentProgramConstants : this._vertexProgramConstants; - // @todo: support transposed matrixes - for(let i = 0; i < 4; i++) - programConstants[firstRegister+i] = [matrix.adaptee._rawData[i], matrix.adaptee._rawData[i+4], matrix.adaptee._rawData[i+8], matrix.adaptee._rawData[i+12]]; + if(!transposedMatrix) + { + for(let i = 0; i < 4; i++) + programConstants[firstRegister+i] = [matrix.adaptee._rawData[i], matrix.adaptee._rawData[i+4], matrix.adaptee._rawData[i+8], matrix.adaptee._rawData[i+12]]; + } + else + { + for(let i = 0; i < 4; i++) + programConstants[firstRegister+i] = [matrix.adaptee._rawData[i], matrix.adaptee._rawData[i+1], matrix.adaptee._rawData[i+2], matrix.adaptee._rawData[i+3]]; + } this._adaptee.context.setProgramConstantsFromArray(awayProgramType, new Float32Array(programConstants.flat())); } @@ -559,4 +567,4 @@ export class Context3D extends EventDispatcher { public setTextureAt(sampler: number /*int*/, texture: TextureBase): void { this._adaptee.context.setTextureAt(sampler, texture?._adaptee); } -} \ No newline at end of file +} From a29d22f2fa247a73a4c7cf64dbcab737f4dbdb7b Mon Sep 17 00:00:00 2001 From: Fancy2209 Date: Thu, 9 Oct 2025 14:21:37 +0000 Subject: [PATCH 52/59] Fix if in setProgramConstantsFromMatrix --- lib/display3D/Context3D.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index 80935024..0f1a5bc3 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -203,15 +203,17 @@ export class Context3D extends EventDispatcher { } let programConstants = (programType == Context3DProgramType.FRAGMENT) ? this._fragmentProgramConstants : this._vertexProgramConstants; - if(!transposedMatrix) + if(transposedMatrix) { for(let i = 0; i < 4; i++) programConstants[firstRegister+i] = [matrix.adaptee._rawData[i], matrix.adaptee._rawData[i+4], matrix.adaptee._rawData[i+8], matrix.adaptee._rawData[i+12]]; } else { - for(let i = 0; i < 4; i++) - programConstants[firstRegister+i] = [matrix.adaptee._rawData[i], matrix.adaptee._rawData[i+1], matrix.adaptee._rawData[i+2], matrix.adaptee._rawData[i+3]]; + programConstants[firstRegister+0] = [matrix.adaptee._rawData[0], matrix.adaptee._rawData[1], matrix.adaptee._rawData[2], matrix.adaptee._rawData[3]]; + programConstants[firstRegister+1] = [matrix.adaptee._rawData[4], matrix.adaptee._rawData[5], matrix.adaptee._rawData[6], matrix.adaptee._rawData[7]]; + programConstants[firstRegister+2] = [matrix.adaptee._rawData[8], matrix.adaptee._rawData[9], matrix.adaptee._rawData[10], matrix.adaptee._rawData[11]]; + programConstants[firstRegister+3] = [matrix.adaptee._rawData[12], matrix.adaptee._rawData[13], matrix.adaptee._rawData[14], matrix.adaptee._rawData[15]]; } this._adaptee.context.setProgramConstantsFromArray(awayProgramType, new Float32Array(programConstants.flat())); From 20ec402265862973658b80fab20a6c6a2843b1c5 Mon Sep 17 00:00:00 2001 From: Fancy2209 Date: Thu, 9 Oct 2025 15:48:47 +0000 Subject: [PATCH 53/59] Fix setProgramConstantsFromVector and cleanUp --- lib/display/Stage3D.ts | 13 ++++++------- lib/display3D/Context3D.ts | 32 +++++++++++++++++++------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/lib/display/Stage3D.ts b/lib/display/Stage3D.ts index f4b85ea7..a6272cdb 100644 --- a/lib/display/Stage3D.ts +++ b/lib/display/Stage3D.ts @@ -58,16 +58,15 @@ export class Stage3D extends EventDispatcher { } public requestContext3D(context3DRenderMode: string = 'auto', profile: string = 'baseline'): void { - const stage3D: Stage3D = this; - this._context3D = new (stage3D.sec as SecurityDomain).flash.display3D.Context3D(this, context3DRenderMode, profile); + this._context3D = new (this.sec as SecurityDomain).flash.display3D.Context3D(this, context3DRenderMode, profile); - function dispatchContextCreated(e: Event) { - stage3D._context3D.removeEventListener(Event.CONTEXT3D_CREATE, dispatchContextCreated); - stage3D.dispatchEvent(new (stage3D.sec).flash.events.Event(Event.CONTEXT3D_CREATE)); + const dispatchContextCreated = (e: Event) => { + this._context3D.removeEventListener(Event.CONTEXT3D_CREATE, dispatchContextCreated); + this.dispatchEvent(new (this.sec).flash.events.Event(Event.CONTEXT3D_CREATE)); } this._context3D.addEventListener(Event.CONTEXT3D_CREATE, dispatchContextCreated); - setTimeout(function() { + setTimeout(() => { console.log('Request Context'); const forceSoftware: boolean = (context3DRenderMode == 'software'); let awayContextProfile: ContextGLProfile = ContextGLProfile.BASELINE; @@ -97,7 +96,7 @@ export class Stage3D extends EventDispatcher { break; } console.log('Context3D Config: ', 'forceSoftware: ', forceSoftware, ' profile: ', profile); - stage3D._adaptee.requestContext(forceSoftware, awayContextProfile); + this._adaptee.requestContext(forceSoftware, awayContextProfile); } , 0); } } diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index 0f1a5bc3..27902748 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -61,15 +61,13 @@ export class Context3D extends EventDispatcher { // @todo: Constructor isn't meant to be public constructor(stage3D: Stage3D, renderMode: string = 'auto', profile: string = 'baseline') { super(); - const context3D: Context3D = this; - const thisSec: SecurityDomain = (this.sec as SecurityDomain); console.log(`Context3D Create: ${renderMode} ${profile}`); this._profile = profile; this._adaptee = stage3D.adaptee; - function dispatchContextCreated(e: StageEvent) { - context3D.dispatchEvent(new thisSec.flash.events.Event(Event.CONTEXT3D_CREATE)); - context3D._gl = (context3D.adaptee.context as unknown as ContextWebGL)._gl; + const dispatchContextCreated = (e: StageEvent) => { + stage3D.dispatchEvent(new (this.sec as SecurityDomain).flash.events.Event(Event.CONTEXT3D_CREATE)); + this._gl = (this.adaptee.context as unknown as ContextWebGL)._gl; } this._adaptee.addEventListener(StageEvent.CONTEXT_RECREATED, dispatchContextCreated); } @@ -182,11 +180,21 @@ export class Context3D extends EventDispatcher { // @todo: support transposed matrixes let awayData = []; - for (let i = 0; i < data.length; i++) - awayData[i] = data.axGetNumericProperty(i); let programConstants = (programType == Context3DProgramType.FRAGMENT) ? this._fragmentProgramConstants : this._vertexProgramConstants; - programConstants[firstRegister] = awayData; - this._adaptee.context.setProgramConstantsFromArray(awayProgramType, new Float32Array(programConstants.flat())); + const total = numRegisters === -1 ? data.length : numRegisters * 4; + + for (let i = 0, j = 0; i < total; i += 4, j++) { + programConstants[firstRegister + j] = [ + data.axGetNumericProperty(i + 0), + data.axGetNumericProperty(i + 1), + data.axGetNumericProperty(i + 2), + data.axGetNumericProperty(i + 3) + ]; + } + const flatConstants = new Float32Array(programConstants.flat()); + //console.log(flatConstants); + + this._adaptee.context.setProgramConstantsFromArray(awayProgramType, flatConstants); } public setProgramConstantsFromMatrix(programType: string, firstRegister: number, matrix: Matrix3D, transposedMatrix: boolean = false): void { @@ -210,10 +218,8 @@ export class Context3D extends EventDispatcher { } else { - programConstants[firstRegister+0] = [matrix.adaptee._rawData[0], matrix.adaptee._rawData[1], matrix.adaptee._rawData[2], matrix.adaptee._rawData[3]]; - programConstants[firstRegister+1] = [matrix.adaptee._rawData[4], matrix.adaptee._rawData[5], matrix.adaptee._rawData[6], matrix.adaptee._rawData[7]]; - programConstants[firstRegister+2] = [matrix.adaptee._rawData[8], matrix.adaptee._rawData[9], matrix.adaptee._rawData[10], matrix.adaptee._rawData[11]]; - programConstants[firstRegister+3] = [matrix.adaptee._rawData[12], matrix.adaptee._rawData[13], matrix.adaptee._rawData[14], matrix.adaptee._rawData[15]]; + for(let i = 0; i < 16; i+=4) + programConstants[firstRegister+i] = [matrix.adaptee._rawData[i+0], matrix.adaptee._rawData[i+1], matrix.adaptee._rawData[i+2], matrix.adaptee._rawData[i+3]]; } this._adaptee.context.setProgramConstantsFromArray(awayProgramType, new Float32Array(programConstants.flat())); From 557910cffafdf79b382f35fe6de2b82e651898f8 Mon Sep 17 00:00:00 2001 From: Fancy2209 <64917206+Fancy2209@users.noreply.github.com> Date: Fri, 10 Oct 2025 11:35:54 +0000 Subject: [PATCH 54/59] Update Matrix3D.ts --- lib/geom/Matrix3D.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/geom/Matrix3D.ts b/lib/geom/Matrix3D.ts index 36645586..b571612b 100644 --- a/lib/geom/Matrix3D.ts +++ b/lib/geom/Matrix3D.ts @@ -2,7 +2,7 @@ import { Vector3D } from './Vector3D'; import { ASObject } from '@awayfl/avm2'; import { notImplemented, release, somewhatImplemented } from '@awayfl/swf-loader'; import { axCoerceString } from '@awayjs/graphics'; -import { Matrix3D as AwayMatrix3D } from '@awayjs/core'; +import { Matrix3D as AwayMatrix3D, Vector3D as AwayVector3D } from '@awayjs/core'; import { Float64Vector, GenericVector } from '@awayfl/avm2'; import { SecurityDomain } from '../SecurityDomain'; @@ -107,10 +107,17 @@ export class Matrix3D extends ASObject { return v; } - public recompose(components: Float64Vector, orientationStyle: string = 'eulerAngles'): boolean { - //this._adaptee.recompose() - orientationStyle = axCoerceString(orientationStyle); - release || notImplemented('public flash.geom.Matrix3D::recompose'); return; + public recompose(components: ObjectVector, orientationStyle: string = 'eulerAngles'): boolean { + somewhatImplemented('public flash.geom.Matrix3D::recompose'); + + let array:AwayVector3D[] = []; + + for (let i = 0; i < 3; i++) + array[i] = components.axGetNumericProperty(i).adaptee; + + return this._adaptee.recompose(array); + //orientationStyle = axCoerceString(orientationStyle); + //release || notImplemented('public flash.geom.Matrix3D::recompose'); return; } public appendTranslation(x: number, y: number, z: number): void { @@ -225,4 +232,4 @@ export class Matrix3D extends ASObject { public copyColumnFrom(column: number /*uint*/, vector3D: Vector3D): void { this._adaptee.copyColumnFrom(column >>> 0, vector3D.adaptee); } -} \ No newline at end of file +} From 10ee0eb805d57ea6ca4511a86a5432ec5df3fd52 Mon Sep 17 00:00:00 2001 From: Fancy2209 Date: Fri, 10 Oct 2025 14:48:58 +0000 Subject: [PATCH 55/59] Cleanup Context3D.ts --- lib/display3D/Context3D.ts | 70 ++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index 27902748..406a12b9 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -11,7 +11,10 @@ import { BitmapImage2D, ContextGLCompareMode, ContextGLStencilAction, ContextGLTriangleFace, - ContextGLBlendFactor } from '@awayjs/stage'; + ContextGLBlendFactor, + ContextGLBlendEquation, + ContextMode, + ContextGLProfile} from '@awayjs/stage'; import { axCoerceString, Float64Vector } from '@awayfl/avm2'; import { Debug } from '@awayfl/swf-loader'; import { BitmapData } from '../display/BitmapData'; @@ -129,8 +132,9 @@ export class Context3D extends EventDispatcher { return 1024; } - public dispose(): void { + public dispose(recreate: boolean = true): void { this._adaptee.context.dispose(); + this._profile = "Disposed"; } public configureBackBuffer(width: number, height: number, antiAlias: number, enableDepthAndStencil: boolean = true, wantsBestResolution: boolean = false, wantsBestResolutionOnBrowserZoom: boolean = false): void { @@ -162,6 +166,8 @@ export class Context3D extends EventDispatcher { public setProgram(program: Program3D): void { this._adaptee.context.setProgram(program._adaptee); + this._vertexProgramConstants.length = 0; + this._fragmentProgramConstants.length = 0; //this._currentProgram = program } @@ -178,23 +184,22 @@ export class Context3D extends EventDispatcher { break; } - // @todo: support transposed matrixes - let awayData = []; let programConstants = (programType == Context3DProgramType.FRAGMENT) ? this._fragmentProgramConstants : this._vertexProgramConstants; - const total = numRegisters === -1 ? data.length : numRegisters * 4; - - for (let i = 0, j = 0; i < total; i += 4, j++) { - programConstants[firstRegister + j] = [ - data.axGetNumericProperty(i + 0), - data.axGetNumericProperty(i + 1), - data.axGetNumericProperty(i + 2), - data.axGetNumericProperty(i + 3) - ]; - } - const flatConstants = new Float32Array(programConstants.flat()); - //console.log(flatConstants); + if (numRegisters == -1) + { + numRegisters = (data.length >> 2); + } + let sourceIndex = 0; + let destIndex = firstRegister * 4; + for (let i = 0; i < numRegisters; i++) + { + programConstants[destIndex++] = data.axGetNumericProperty(sourceIndex++); + programConstants[destIndex++] = data.axGetNumericProperty(sourceIndex++); + programConstants[destIndex++] = data.axGetNumericProperty(sourceIndex++); + programConstants[destIndex++] = data.axGetNumericProperty(sourceIndex++); + } - this._adaptee.context.setProgramConstantsFromArray(awayProgramType, flatConstants); + this._adaptee.context.setProgramConstantsFromArray(awayProgramType, new Float32Array(programConstants)); } public setProgramConstantsFromMatrix(programType: string, firstRegister: number, matrix: Matrix3D, transposedMatrix: boolean = false): void { @@ -211,18 +216,30 @@ export class Context3D extends EventDispatcher { } let programConstants = (programType == Context3DProgramType.FRAGMENT) ? this._fragmentProgramConstants : this._vertexProgramConstants; - if(transposedMatrix) + let i = firstRegister * 4; + + if (transposedMatrix) { - for(let i = 0; i < 4; i++) - programConstants[firstRegister+i] = [matrix.adaptee._rawData[i], matrix.adaptee._rawData[i+4], matrix.adaptee._rawData[i+8], matrix.adaptee._rawData[i+12]]; + for(let j = 0; j < 16; j+=4) + { + programConstants[i++] = matrix.adaptee._rawData[j+0]; + programConstants[i++] = matrix.adaptee._rawData[j+4]; + programConstants[i++] = matrix.adaptee._rawData[j+8]; + programConstants[i++] = matrix.adaptee._rawData[j+12]; + } } else { - for(let i = 0; i < 16; i+=4) - programConstants[firstRegister+i] = [matrix.adaptee._rawData[i+0], matrix.adaptee._rawData[i+1], matrix.adaptee._rawData[i+2], matrix.adaptee._rawData[i+3]]; + for(let j = 0; j < 16; j+=4) + { + programConstants[i++] = matrix.adaptee._rawData[j+0]; + programConstants[i++] = matrix.adaptee._rawData[j+1]; + programConstants[i++] = matrix.adaptee._rawData[j+2]; + programConstants[i++] = matrix.adaptee._rawData[j+3]; + } } - - this._adaptee.context.setProgramConstantsFromArray(awayProgramType, new Float32Array(programConstants.flat())); + + this._adaptee.context.setProgramConstantsFromArray(awayProgramType, new Float32Array(programConstants)); } public setProgramConstantsFromByteArray(programType: string, firstRegister: number /*int*/, numRegisters: number /*int*/, data: ByteArray, byteArrayOffset: number /*uint*/): void { @@ -327,7 +344,8 @@ export class Context3D extends EventDispatcher { break; } - this._adaptee.context.setBlendFactors(awaySourceFactor, awayDestinationFactor); + this._adaptee.context.setBlendFactors(awaySourceFactor, awayDestinationFactor, awaySourceFactor, awayDestinationFactor); + this._adaptee.context.setBlendEquation(ContextGLBlendEquation.ADD, ContextGLBlendEquation.ADD); } public setColorMask(red: boolean, green: boolean, blue: boolean, alpha: boolean): void { @@ -533,7 +551,7 @@ export class Context3D extends EventDispatcher { } public setScissorRectangle(rectangle: Rectangle): void { - this._adaptee.context.setScissorRectangle(rectangle ? rectangle.adaptee : null); + this._adaptee.context.setScissorRectangle(rectangle?.adaptee); } public createVertexBuffer(numVertices: number, data32PerVertex: number, bufferUsage: string = 'staticDraw'): VertexBuffer3D { From 8f637740e114eb06dede9fc2b4d45d525bc90101 Mon Sep 17 00:00:00 2001 From: Fancy2209 <64917206+Fancy2209@users.noreply.github.com> Date: Tue, 14 Oct 2025 09:19:57 +0000 Subject: [PATCH 56/59] Stub Matrix3D::recompose again --- lib/geom/Matrix3D.ts | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/geom/Matrix3D.ts b/lib/geom/Matrix3D.ts index b571612b..bc6eff44 100644 --- a/lib/geom/Matrix3D.ts +++ b/lib/geom/Matrix3D.ts @@ -108,16 +108,9 @@ export class Matrix3D extends ASObject { } public recompose(components: ObjectVector, orientationStyle: string = 'eulerAngles'): boolean { - somewhatImplemented('public flash.geom.Matrix3D::recompose'); - - let array:AwayVector3D[] = []; - - for (let i = 0; i < 3; i++) - array[i] = components.axGetNumericProperty(i).adaptee; - - return this._adaptee.recompose(array); - //orientationStyle = axCoerceString(orientationStyle); - //release || notImplemented('public flash.geom.Matrix3D::recompose'); return; + //this._adaptee.recompose() + orientationStyle = axCoerceString(orientationStyle); + release || notImplemented('public flash.geom.Matrix3D::recompose'); return; } public appendTranslation(x: number, y: number, z: number): void { From 86a28fb42f087ab80940a0e6cfcc019b734491a6 Mon Sep 17 00:00:00 2001 From: Fancy2209 <64917206+Fancy2209@users.noreply.github.com> Date: Tue, 14 Oct 2025 09:20:36 +0000 Subject: [PATCH 57/59] Fix typo --- lib/geom/Matrix3D.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/geom/Matrix3D.ts b/lib/geom/Matrix3D.ts index bc6eff44..f10dded5 100644 --- a/lib/geom/Matrix3D.ts +++ b/lib/geom/Matrix3D.ts @@ -107,7 +107,7 @@ export class Matrix3D extends ASObject { return v; } - public recompose(components: ObjectVector, orientationStyle: string = 'eulerAngles'): boolean { + public recompose(components: GenericVector, orientationStyle: string = 'eulerAngles'): boolean { //this._adaptee.recompose() orientationStyle = axCoerceString(orientationStyle); release || notImplemented('public flash.geom.Matrix3D::recompose'); return; From 17447adf414cef02f2efabf318fd91becb495d8b Mon Sep 17 00:00:00 2001 From: Fancy2209 Date: Tue, 14 Oct 2025 19:01:02 +0000 Subject: [PATCH 58/59] Simplify setProgramConstantsFromMatrix. fix Matrix3D.recompose and add hack for StageScaleMode.SHOW_ALL --- lib/display3D/Context3D.ts | 81 ++++++++-------- lib/display3D/textures/RectangleTexture.ts | 2 +- lib/geom/Matrix3D.ts | 107 ++++++++++++++++++++- lib/geom/Utils3D.ts | 6 +- 4 files changed, 144 insertions(+), 52 deletions(-) diff --git a/lib/display3D/Context3D.ts b/lib/display3D/Context3D.ts index 406a12b9..03779bf5 100644 --- a/lib/display3D/Context3D.ts +++ b/lib/display3D/Context3D.ts @@ -1,22 +1,20 @@ -import { BitmapImage2D, - ContextGLDrawMode, - ContextGLProgramType, - ContextGLVertexBufferFormat, - ContextWebGL, - Stage as AwayStage, - StageEvent, - TextureWebGL, - VertexBufferWebGL, - ContextGLClearMask, - ContextGLCompareMode, - ContextGLStencilAction, - ContextGLTriangleFace, - ContextGLBlendFactor, - ContextGLBlendEquation, - ContextMode, - ContextGLProfile} from '@awayjs/stage'; +import { + BitmapImage2D, + ContextGLDrawMode, + ContextGLProgramType, + ContextGLVertexBufferFormat, + ContextWebGL, + Stage as AwayStage, + StageEvent, + ContextGLClearMask, + ContextGLCompareMode, + ContextGLStencilAction, + ContextGLTriangleFace, + ContextGLBlendFactor, + ContextGLBlendEquation, +} from '@awayjs/stage'; import { axCoerceString, Float64Vector } from '@awayfl/avm2'; -import { Debug } from '@awayfl/swf-loader'; +import { AVMStage, Debug } from '@awayfl/swf-loader'; import { BitmapData } from '../display/BitmapData'; import { Stage3D } from '../display/Stage3D'; import { Context3DProgramType } from '../display3D/Context3DProgramType'; @@ -30,7 +28,6 @@ import { Rectangle } from '../geom/Rectangle'; import { ByteArray } from '../utils/ByteArray'; import { SecurityDomain } from '../SecurityDomain'; import { Event } from '../events/Event'; -import { Security } from '../system/Security'; import { Texture } from './textures/Texture'; import { RectangleTexture } from './textures/RectangleTexture'; import { CubeTexture } from './textures/CubeTexture'; @@ -55,11 +52,9 @@ export class Context3D extends EventDispatcher { private _adaptee: AwayStage; private _profile: string; private _gl: WebGL2RenderingContext | WebGLRenderingContext; - - // Due to how AwayJS works, we need to submit a flat array of vectors - // We use these to make sure they're submitted in the right place private _fragmentProgramConstants = []; private _vertexProgramConstants = []; + private _resizeStage: boolean = false; // @todo: Constructor isn't meant to be public constructor(stage3D: Stage3D, renderMode: string = 'auto', profile: string = 'baseline') { @@ -89,7 +84,7 @@ export class Context3D extends EventDispatcher { public get driverInfo(): string { Debug.notImplemented('public flash.display3D.Context3D::get driverInfo'); - return axCoerceString('OpenGL'); + return axCoerceString('OpenGL (' + this.profile.replace(/([a-z])([A-Z])/g, '$1 $2').replace(/^./, str => str.toUpperCase()) + ')'); } public get enableErrorChecking(): boolean { @@ -138,6 +133,12 @@ export class Context3D extends EventDispatcher { } public configureBackBuffer(width: number, height: number, antiAlias: number, enableDepthAndStencil: boolean = true, wantsBestResolution: boolean = false, wantsBestResolutionOnBrowserZoom: boolean = false): void { + // Hack so that if we don't use noScale, the Stage3Ds get Scaled + // This isn't done directly here because some games seem to blow up if we do + // @todo: Should probably make this a Setting + let stageManager = AVMStage.instance(); + this._resizeStage = width == stageManager.stageWidth && height == stageManager.stageHeight && stageManager.scaleMode != 'noScale'; + this._adaptee.configureBackBuffer(width, height, antiAlias, enableDepthAndStencil); } @@ -161,6 +162,11 @@ export class Context3D extends EventDispatcher { } public present(): void { + if (this._resizeStage) { + AVMStage.instance().stageWidth = AVMStage.instance().stageWidth; + this._resizeStage = false; + } + this._adaptee.present(); } @@ -217,27 +223,16 @@ export class Context3D extends EventDispatcher { let programConstants = (programType == Context3DProgramType.FRAGMENT) ? this._fragmentProgramConstants : this._vertexProgramConstants; let i = firstRegister * 4; - - if (transposedMatrix) - { - for(let j = 0; j < 16; j+=4) - { - programConstants[i++] = matrix.adaptee._rawData[j+0]; - programConstants[i++] = matrix.adaptee._rawData[j+4]; - programConstants[i++] = matrix.adaptee._rawData[j+8]; - programConstants[i++] = matrix.adaptee._rawData[j+12]; - } - } - else - { + let matrixData = new Float32Array(16); + matrix.adaptee.copyRawDataTo(matrixData, 0, transposedMatrix); for(let j = 0; j < 16; j+=4) { - programConstants[i++] = matrix.adaptee._rawData[j+0]; - programConstants[i++] = matrix.adaptee._rawData[j+1]; - programConstants[i++] = matrix.adaptee._rawData[j+2]; - programConstants[i++] = matrix.adaptee._rawData[j+3]; + programConstants[i++] = matrixData[j+0]; + programConstants[i++] = matrixData[j+1]; + programConstants[i++] = matrixData[j+2]; + programConstants[i++] = matrixData[j+3]; } - } + this._adaptee.context.setProgramConstantsFromArray(awayProgramType, new Float32Array(programConstants)); } @@ -344,7 +339,7 @@ export class Context3D extends EventDispatcher { break; } - this._adaptee.context.setBlendFactors(awaySourceFactor, awayDestinationFactor, awaySourceFactor, awayDestinationFactor); + this._adaptee.context.setBlendFactors(awaySourceFactor, awayDestinationFactor); this._adaptee.context.setBlendEquation(ContextGLBlendEquation.ADD, ContextGLBlendEquation.ADD); } @@ -586,7 +581,7 @@ export class Context3D extends EventDispatcher { this._adaptee.context.setRenderToBackBuffer(); } - public setRenderToTexture(texture: TextureBase, targetType: number /*int*/, enableDepthAndStencil: boolean, antiAlias: number /*int*/, surfaceSelector: number /*int*/): void { + public setRenderToTexture(texture:TextureBase, enableDepthAndStencil:boolean = false, antiAlias:number/*int*/ = 0, surfaceSelector:number/*int*/ = 0, colorOutputIndex:number/*int*/ = 0): void { this._adaptee.context.setRenderToTexture(texture?._adaptee, enableDepthAndStencil, antiAlias, surfaceSelector); } diff --git a/lib/display3D/textures/RectangleTexture.ts b/lib/display3D/textures/RectangleTexture.ts index 76c88c84..8e5f6ae5 100644 --- a/lib/display3D/textures/RectangleTexture.ts +++ b/lib/display3D/textures/RectangleTexture.ts @@ -36,7 +36,7 @@ export class RectangleTexture extends TextureBase { } public uploadCompressedTextureFromByteArray(data: ByteArray, byteArrayOffset: number, async: boolean = false) { - Debug.notImplemented('public flash.display3D.textures.Texture::uploadCompressedTextureFromByteArray'); + Debug.notImplemented('public flash.display3D.textures.RectangleTexture::uploadCompressedTextureFromByteArray'); } public uploadFromBitmapData(source: BitmapData, miplevel: number = 0) { diff --git a/lib/geom/Matrix3D.ts b/lib/geom/Matrix3D.ts index f10dded5..ad0c0141 100644 --- a/lib/geom/Matrix3D.ts +++ b/lib/geom/Matrix3D.ts @@ -1,8 +1,8 @@ import { Vector3D } from './Vector3D'; -import { ASObject } from '@awayfl/avm2'; +import { ASObject, Errors } from '@awayfl/avm2'; import { notImplemented, release, somewhatImplemented } from '@awayfl/swf-loader'; import { axCoerceString } from '@awayjs/graphics'; -import { Matrix3D as AwayMatrix3D, Vector3D as AwayVector3D } from '@awayjs/core'; +import { Matrix3D as AwayMatrix3D, Vector3D as AwayVector3D, Orientation3D } from '@awayjs/core'; import { Float64Vector, GenericVector } from '@awayfl/avm2'; import { SecurityDomain } from '../SecurityDomain'; @@ -108,9 +108,106 @@ export class Matrix3D extends ASObject { } public recompose(components: GenericVector, orientationStyle: string = 'eulerAngles'): boolean { - //this._adaptee.recompose() - orientationStyle = axCoerceString(orientationStyle); - release || notImplemented('public flash.geom.Matrix3D::recompose'); return; + // RUFFLE - unlike in OpenFL, we continue on even if some of the 'scale' components are 0 + if (components.length < 3) { + return false; + } + + if (!(orientationStyle == Orientation3D.AXIS_ANGLE || orientationStyle == Orientation3D.EULER_ANGLES || orientationStyle == Orientation3D.QUATERNION)) { + this.sec.throwError("flash.geom.Matrix3D", Errors.Matrix3DDecomposeTypeInvalid, orientationStyle); + } + + let awayComponets: Array = new Array(3); + + for (let i = 0; i < 3; i++) + awayComponets[i] = components.axGetNumericProperty(i).adaptee; + + if (orientationStyle == Orientation3D.QUATERNION) { + // Flash throws exceptions from 'recompose' certain values of 'components', + // which we need to reproduce. See the 'matrix3d_compose' test + somewhatImplemented("public flash.geom.Matrix3D::recompose with Orientation3D.QUATERNION"); + } + + this.adaptee.identity(); + + let _rawData = this.adaptee._rawData; + + var scale = []; + scale[0] = scale[1] = scale[2] = awayComponets[2].x; + scale[4] = scale[5] = scale[6] = awayComponets[2].y; + scale[8] = scale[9] = scale[10] = awayComponets[2].z; + + switch (orientationStyle) { + case Orientation3D.EULER_ANGLES: + var cx = Math.cos(awayComponets[1].x); + var cy = Math.cos(awayComponets[1].y); + var cz = Math.cos(awayComponets[1].z); + var sx = Math.sin(awayComponets[1].x); + var sy = Math.sin(awayComponets[1].y); + var sz = Math.sin(awayComponets[1].z); + + _rawData[0] = cy * cz * scale[0]; + _rawData[1] = cy * sz * scale[1]; + _rawData[2] = -sy * scale[2]; + _rawData[3] = 0; + _rawData[4] = (sx * sy * cz - cx * sz) * scale[4]; + _rawData[5] = (sx * sy * sz + cx * cz) * scale[5]; + _rawData[6] = sx * cy * scale[6]; + _rawData[7] = 0; + _rawData[8] = (cx * sy * cz + sx * sz) * scale[8]; + _rawData[9] = (cx * sy * sz - sx * cz) * scale[9]; + _rawData[10] = cx * cy * scale[10]; + _rawData[11] = 0; + _rawData[12] = awayComponets[0].x; + _rawData[13] = awayComponets[0].y; + _rawData[14] = awayComponets[0].z; + _rawData[15] = 1; + break; + + default: + var x = awayComponets[1].x; + var y = awayComponets[1].y; + var z = awayComponets[1].z; + var w = awayComponets[1].w; + + if (orientationStyle == Orientation3D.AXIS_ANGLE) { + x *= Math.sin(w / 2); + y *= Math.sin(w / 2); + z *= Math.sin(w / 2); + w = Math.cos(w / 2); + } + + _rawData[0] = (1 - 2 * y * y - 2 * z * z) * scale[0]; + _rawData[1] = (2 * x * y + 2 * w * z) * scale[1]; + _rawData[2] = (2 * x * z - 2 * w * y) * scale[2]; + _rawData[3] = 0; + _rawData[4] = (2 * x * y - 2 * w * z) * scale[4]; + _rawData[5] = (1 - 2 * x * x - 2 * z * z) * scale[5]; + _rawData[6] = (2 * y * z + 2 * w * x) * scale[6]; + _rawData[7] = 0; + _rawData[8] = (2 * x * z + 2 * w * y) * scale[8]; + _rawData[9] = (2 * y * z - 2 * w * x) * scale[9]; + _rawData[10] = (1 - 2 * x * x - 2 * y * y) * scale[10]; + _rawData[11] = 0; + _rawData[12] = awayComponets[0].x; + _rawData[13] = awayComponets[0].y; + _rawData[14] = awayComponets[0].z; + _rawData[15] = 1; + } + + if (awayComponets[2].x == 0) { + _rawData[0] = 1e-15; + } + + if (awayComponets[2].y == 0) { + _rawData[5] = 1e-15; + } + + if (awayComponets[2].z == 0) { + _rawData[10] = 1e-15; + } + + return !(awayComponets[2].x == 0 || awayComponets[2].y == 0 || awayComponets[2].y == 0); } public appendTranslation(x: number, y: number, z: number): void { diff --git a/lib/geom/Utils3D.ts b/lib/geom/Utils3D.ts index 198a48ec..6fa566ed 100644 --- a/lib/geom/Utils3D.ts +++ b/lib/geom/Utils3D.ts @@ -21,16 +21,16 @@ export class Utils3D extends ASObject { // AS -> JS Bindings static projectVector(m: Matrix3D, v: Vector3D): Vector3D { Matrix3D; - release || notImplemented('public flash.geom.Utils3D::static projectVector'); return; + notImplemented('public flash.geom.Utils3D::static projectVector'); return; } static projectVectors(m: Matrix3D, verts: Float64Vector, projectedVerts: Float64Vector, uvts: Float64Vector): void { - release || notImplemented('public flash.geom.Utils3D::static projectVectors'); return; + notImplemented('public flash.geom.Utils3D::static projectVectors'); return; } static pointTowards(percent: number, mat: Matrix3D, pos: Vector3D, at: Vector3D = null, up: Vector3D = null): Matrix3D { percent = +percent; - release || notImplemented('public flash.geom.Utils3D::static pointTowards'); return; + notImplemented('public flash.geom.Utils3D::static pointTowards'); return; } } \ No newline at end of file From d7f20703d099f35d4e159a68b6c9527071045ceb Mon Sep 17 00:00:00 2001 From: Fancy2209 <64917206+Fancy2209@users.noreply.github.com> Date: Mon, 3 Aug 2026 01:34:27 +0000 Subject: [PATCH 59/59] Update Stage.ts --- lib/display/Stage.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/display/Stage.ts b/lib/display/Stage.ts index c59a72e5..9389a9e7 100644 --- a/lib/display/Stage.ts +++ b/lib/display/Stage.ts @@ -6,7 +6,7 @@ import { DisplayObjectContainer } from './DisplayObjectContainer'; import { DisplayObject } from './DisplayObject'; import { FrameScriptManager } from '@awayjs/scene'; import { View } from '@awayjs/view'; -import { Stage as AwayStage, StageQuality, Stage3D } from '@awayjs/stage'; +import { Stage as AwayStage, StageQuality } from '@awayjs/stage'; import { DisplayObjectContainer as AwayDisplayObjectContainer, MouseEvent as MouseEventAway } from '@awayjs/scene'; import { Transform } from '../geom/Transform'; import { Rectangle } from '../geom/Rectangle'; @@ -18,6 +18,7 @@ import { Debug } from '@awayjs/core'; import { InteractiveObject } from './InteractiveObject'; import { StageManager } from '@awayjs/stage'; import { GenericVector } from '@awayfl/avm2'; +import { Stage3D } from './Stage3D'; /** * Dispatched by the Stage object when the state of the stageVideos property changes.