From e798f848a66bc01d001e26c07de63d6aca8a2788 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 10 Sep 2024 17:34:00 +0000 Subject: [PATCH 01/39] 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 070094f..03c3e8d 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 9d75429..df24e3c 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 3de18cf..40ca0be 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 0000000..cbe04a2 --- /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 882b07c..5abb5cd 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 0000000..fa41ddf --- /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 325b76b..26d69ea 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 0000000..b8b1a34 --- /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 48e3836..2e34523 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'; @@ -283,7 +284,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); @@ -291,8 +292,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 ae53bb0d82f8ddc602be6e527fca48b8ad5ac6f5 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 10 Sep 2024 17:37:34 +0000 Subject: [PATCH 02/39] 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 df24e3c..67815c5 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'; @@ -86,6 +85,7 @@ export class SecurityDomain extends AXSecurityDomain { DisplayObject: DisplayObject, DisplayObjectContainer: DisplayObjectContainer, Stage: Stage, + Stage3D: Stage3D, Loader: Loader, LoaderInfo: LoaderInfo, MovieClip: MovieClip, From 675767cddb921e3c78153cc2c4085b41c0c8764e Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 10 Sep 2024 19:25:11 +0000 Subject: [PATCH 03/39] 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 cbe04a2..699d1ff 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 5abb5cd..4172049 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 0000000..963db45 --- /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 0000000..1438721 --- /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 0000000..e88fe77 --- /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 0000000..d280645 --- /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 b9e818678ccda14986c208bcb43dbf4ca26072a3 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 10 Sep 2024 19:26:55 +0000 Subject: [PATCH 04/39] 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 40ca0be..eb79707 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 af7ae3a65b96c508fe14c7309af0d4f225cea988 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 10 Sep 2024 19:41:59 +0000 Subject: [PATCH 05/39] 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 67815c5..8f61c30 100644 --- a/lib/SecurityDomain.ts +++ b/lib/SecurityDomain.ts @@ -97,6 +97,9 @@ export class SecurityDomain extends AXSecurityDomain { Shape: Shape, FrameLabel: FrameLabel }, + display3d: { + // TODO: Add display3d stuff + }, events: { EventDispatcher: EventDispatcher, Event: Event, From e5edc128f4a8b310a6ce91504947e5bf0f0ce41c Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 10 Sep 2024 19:51:20 +0000 Subject: [PATCH 06/39] 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 eb79707..12d2eb6 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 699d1ff..32333e8 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 4172049..c8a09bb 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 fa41ddf..0bf5a4a 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 26d69ea..f29eefa 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 b8b1a34..5b08c5a 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 963db45..f1e1112 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 1438721..e6206d4 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 e88fe77..c5a2903 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 d280645..98feb02 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 5d8f5da1c6d65c83d7ba49fa5ed4b782bc6fc8a6 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 10 Sep 2024 20:05:32 +0000 Subject: [PATCH 07/39] 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 32333e8..9184943 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 c8a09bb..e16c7be 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 6b49026ba345307f4e276cdeb2eda2806aef7020 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 10 Sep 2024 22:07:39 +0000 Subject: [PATCH 08/39] 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 e16c7be..9218fa4 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 e6206d4..8a3c148 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 98feb02..3ccfa56 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 a50c368c94443d73009d4afacfa24a6deeca54bc 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/39] 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 12d2eb6..fc5b118 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 723bb11c424cb2e261de0dabb1acd138c2fc5a9a 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/39] 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 9184943..e475db5 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 9218fa4..37f1775 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 73d8f6f..ca91566 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 8a3c148..ad8d4ff 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 c5a2903..f7f85a2 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 073ca3c4f9b0e9da10dd0ea0898e06465dfd77c4 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Wed, 11 Sep 2024 17:03:09 +0000 Subject: [PATCH 11/39] Commit Work --- lib/SecurityDomain.ts | 10 +++- 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, 90 insertions(+), 89 deletions(-) diff --git a/lib/SecurityDomain.ts b/lib/SecurityDomain.ts index 8f61c30..9f1337e 100644 --- a/lib/SecurityDomain.ts +++ b/lib/SecurityDomain.ts @@ -75,6 +75,11 @@ import { ContextMenuItem } from './ui/ContextMenuItem'; import { FrameLabel } from './display/FrameLabel'; import { TextLineMetrics } from './text/TextLineMetrics'; import { FocusEvent } from './events/FocusEvent'; +import { Context3D } from './display3D/Context3D'; +import { IndexBuffer3D } from './display3D/IndexBuffer3D'; +import { Program3D } from './display3D/Program3D'; +import { VertexBuffer3D } from './display3D/VertexBuffer3D'; + export class Mouse {} @@ -98,7 +103,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 fc5b118..74d6288 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 e475db5..5544ece 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 37f1775..86f010c 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 ca91566..c78a232 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 0bf5a4a..ce09c93 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 f29eefa..7406762 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 5b08c5a..364f974 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 f1e1112..cd53ef9 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 ad8d4ff..7e1b9fd 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 f7f85a2..8096f32 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 3ccfa56..b7c8072 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 2e34523..da4d272 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'; @@ -293,6 +303,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 2bd0f96b50871286685e2ad48f41fa204f96f601 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Wed, 11 Sep 2024 20:56:46 +0000 Subject: [PATCH 12/39] 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 74d6288..f864340 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 5544ece..2fba445 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 86f010c..d91a4a2 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 7e1b9fd..7bb2e82 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 8096f32..035b8ac 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 b7c8072..67064a7 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 da4d272..a065da5 100644 --- a/lib/link.ts +++ b/lib/link.ts @@ -295,6 +295,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); @@ -303,6 +304,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 d0882ea2dfdf7aa9a126c6572e6fd33a4f290ced Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Wed, 11 Sep 2024 22:08:58 +0000 Subject: [PATCH 13/39] 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 f864340..eebf051 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 2fba445..384d0de 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 d91a4a2..f96dd74 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 10ba69b67db2e8fba4d6c36688e4072e8b4ab2a4 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Thu, 12 Sep 2024 22:06:06 +0000 Subject: [PATCH 14/39] 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 eebf051..fae4b80 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 384d0de..3e8c267 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 f96dd74..2de9f29 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 74234015b9bd4c7876c2974fa4646d526a0c91ac Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Fri, 13 Sep 2024 22:11:08 +0000 Subject: [PATCH 15/39] Commit work --- lib/SecurityDomain.ts | 3 +- 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(+), 120 deletions(-) diff --git a/lib/SecurityDomain.ts b/lib/SecurityDomain.ts index 9f1337e..4fcb91b 100644 --- a/lib/SecurityDomain.ts +++ b/lib/SecurityDomain.ts @@ -80,7 +80,6 @@ import { IndexBuffer3D } from './display3D/IndexBuffer3D'; import { Program3D } from './display3D/Program3D'; import { VertexBuffer3D } from './display3D/VertexBuffer3D'; - export class Mouse {} export class SecurityDomain extends AXSecurityDomain { @@ -102,7 +101,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 fae4b80..6fe9950 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 3e8c267..c1bae30 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 2de9f29..2417dcf 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 7bb2e82..987c8bb 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 035b8ac..f751e3e 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 67064a7..616b118 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 a065da5..a080887 100644 --- a/lib/link.ts +++ b/lib/link.ts @@ -304,7 +304,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 e9ac84d496804b30c6e7038af10f8da81abe4c6f Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Fri, 13 Sep 2024 22:39:09 +0000 Subject: [PATCH 16/39] 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 2417dcf..773b7b5 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 f751e3e..58a3e87 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 1d2a3eb3b23a7cdea503836a87096f2de309e449 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Fri, 13 Sep 2024 23:02:20 +0000 Subject: [PATCH 17/39] 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 773b7b5..a36a181 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 f7ba23b099a53e6b176db2aeba909b64672ac31f Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Sat, 14 Sep 2024 22:47:19 +0000 Subject: [PATCH 18/39] 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 a36a181..d52a94e 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 58a3e87..48b619f 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 388d0a28f26251feb8f290456f678ea2fbc0f091 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Mon, 16 Sep 2024 18:00:14 +0000 Subject: [PATCH 19/39] 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 c1bae30..b7a4ff7 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 d52a94e..bca6292 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 0000000..27e78a9 --- /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 c78a232..a6c0aa9 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 0000000..6557254 --- /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 ce09c93..6c1f62b 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 7406762..d59de96 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 364f974..c0e4537 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 0000000..efaddc5 --- /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 0000000..01b4b13 --- /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 0000000..12a937f --- /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 0000000..cd772ac --- /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 cd53ef9..f5d1e82 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 987c8bb..270207b 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 48b619f..00c44a5 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 616b118..c053b10 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 0000000..43384d3 --- /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 be3d101..54d3a06 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 0000000..eea13a8 --- /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 cb8705b2afc6ef809c372b1e404b12b1e11e214d Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Mon, 16 Sep 2024 21:48:26 +0000 Subject: [PATCH 20/39] 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 | 55 +++++++++++++++------------ 9 files changed, 56 insertions(+), 54 deletions(-) diff --git a/lib/display/Stage3D.ts b/lib/display/Stage3D.ts index b7a4ff7..63e596c 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 bca6292..ffd48c4 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 270207b..f69b216 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 00c44a5..7623228 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 c053b10..f4b5119 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 43384d3..8c066f9 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 54d3a06..7c47f42 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 eea13a8..787418e 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 a080887..bb91a35 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,39 +119,39 @@ 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 { LocalConnection } from './net/LocalConnection'; import { SharedObject } from './net/SharedObject'; -import { URLRequest } from './net/URLRequest'; import { URLLoader } from './net/URLLoader'; +import { URLRequest } from './net/URLRequest'; import { URLVariables } from './net/URLVariables'; -import { LocalConnection } from './net/LocalConnection'; -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'; @@ -185,27 +189,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'; @@ -315,6 +318,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 9b47776bbcfe4926537fdebcd34db74998fe8496 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Mon, 16 Sep 2024 21:48:42 +0000 Subject: [PATCH 21/39] 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 4fcb91b..2c37255 100644 --- a/lib/SecurityDomain.ts +++ b/lib/SecurityDomain.ts @@ -79,6 +79,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 {} @@ -105,7 +108,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 ffd48c4..971c47f 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 6557254..e5063d0 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 efaddc5..90576f5 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 01b4b13..7390d29 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 12a937f..d6d3d7b 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 cd772ac..0000000 --- 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 787418e..a8d329d 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 bb91a35..c11dcb1 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'; @@ -309,18 +314,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 10b5828c05b7e49a052346d872874ad979cc43c3 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 17 Sep 2024 15:33:46 +0000 Subject: [PATCH 22/39] 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 63e596c..c70b337 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 971c47f..9528323 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 3376dfd..5fe89bc 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 2fbf9fcd715e986bd7183f7f483d14782a0c2bcf Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 17 Sep 2024 18:44:14 +0000 Subject: [PATCH 23/39] 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 c70b337..db67e90 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 9528323..7349b84 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 ac525b3f44a8abbb2946130d79daf9cba4f93bde Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 17 Sep 2024 19:40:09 +0000 Subject: [PATCH 24/39] 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 db67e90..4d54671 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 c9f561d7c71508748cbd8ba269e615ed4d68c632 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 17 Sep 2024 21:17:15 +0000 Subject: [PATCH 25/39] 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 4d54671..e6bdf7e 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 7349b84..e62e857 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 1b27c86949aec9ea72dc989e704bf1d777a83aa7 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Fri, 20 Sep 2024 16:51:35 +0000 Subject: [PATCH 26/39] 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 e6bdf7e..53602c9 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 36d24508a14ef9b1e3c32e1bf23311dc9e13927a Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Mon, 23 Sep 2024 17:49:33 +0000 Subject: [PATCH 27/39] 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 069cca9..f7e4436 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 4438bdab68b59b7570ee0c7e242aa2ecbedb9b04 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Mon, 23 Sep 2024 17:49:49 +0000 Subject: [PATCH 28/39] 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 2c37255..5f0a11d 100644 --- a/lib/SecurityDomain.ts +++ b/lib/SecurityDomain.ts @@ -112,6 +112,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 e62e857..9b09d95 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 8c066f9..85974f7 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 7c47f42..58b2b11 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 a8d329d..574d58f 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 7b251fd..098a21c 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 413a535e364933bfbfadf825e2e9bebb991de1ff Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Mon, 23 Sep 2024 17:50:17 +0000 Subject: [PATCH 29/39] Implement Textures --- lib/link.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/link.ts b/lib/link.ts index c11dcb1..9a959bf 100644 --- a/lib/link.ts +++ b/lib/link.ts @@ -330,6 +330,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 67d90da6c85fcd1aa4067dc95d218e6b1053b816 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Mon, 23 Sep 2024 18:31:57 +0000 Subject: [PATCH 30/39] 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 9b09d95..e89bf01 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 7623228..6a342f4 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 85974f7..6cc8dee 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 58b2b11..56f104f 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 81bfd52321aa153887c2239a36e05369597f4992 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/39] 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 e89bf01..56dfcaa 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 cd8da2b77d6b4ddc0271c6dc0f4a8a637c5eb5f1 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 24 Sep 2024 15:16:59 +0000 Subject: [PATCH 32/39] 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 56dfcaa..5a664c2 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 e2d5d5a2216f8321575e5f8e705ee21dd290e09b Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 24 Sep 2024 15:23:49 +0000 Subject: [PATCH 33/39] 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 5a664c2..56f0d05 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 7612f9e2eaff916dd8f28838c0f2459f34ef22e8 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 24 Sep 2024 15:27:50 +0000 Subject: [PATCH 34/39] 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 56f0d05..37e1cf6 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 27a99f140f73ce5bf94701edf4b4afdd8322e813 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Tue, 24 Sep 2024 15:39:48 +0000 Subject: [PATCH 35/39] 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 37e1cf6..4c2e042 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 f923db777db848e45f4263aa9be71c4fad688112 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Mon, 30 Sep 2024 20:22:33 +0000 Subject: [PATCH 36/39] 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 53602c9..8114412 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 869f233b8cd95ce64ca1bdc995bc32775c11c700 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Mon, 30 Sep 2024 20:22:44 +0000 Subject: [PATCH 37/39] Fix LoaderInfo.UncaughtErrorEvents --- lib/display/LoaderInfo.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/display/LoaderInfo.ts b/lib/display/LoaderInfo.ts index b673679..44511c1 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; @@ -159,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 @@ -193,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'; @@ -639,7 +642,10 @@ export class LoaderInfo extends EventDispatcher { public get uncaughtErrorEvents(): any { // @todo Debug.throwPIR('playerglobals/display/LoaderInfo', 'get uncaughtErrorEvents', ''); - return null; + if (!this._uncaughtErrorEvents) + this._uncaughtErrorEvents = new UncaughtErrorEvents(); + + return this._uncaughtErrorEvents; } From 6c048f085a3c581f35a20848cbe249a75577647c Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Mon, 30 Sep 2024 20:23:01 +0000 Subject: [PATCH 38/39] 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 6fe9950..1919085 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 8323f4f7c057a9f6ed93f0763f622ea908bb3e44 Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Thu, 3 Oct 2024 18:02:21 +0000 Subject: [PATCH 39/39] 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 8114412..db1df70 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 4c2e042..834941e 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 6cc8dee..216d70e 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 ee0ef68..6a967c7 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.