소스 검색

Canvas2D: little bug fixes

 - Canvas2D constructor with children is more stable
 - Text2D.fontTexture member access is now safe
 - Primitive alignment for shape based ones is now working!
nockawa 8 년 전
부모
커밋
bb0ba57e7f

+ 1 - 0
canvas2D/src/Engine/babylon.canvas2d.ts

@@ -326,6 +326,7 @@
             let cachingStrategy = (settings.cachingStrategy == null) ? Canvas2D.CACHESTRATEGY_DONTCACHE : settings.cachingStrategy;
             this._cachingStrategy = cachingStrategy;
             this._isScreenSpace = (settings.isScreenSpace == null) ? true : settings.isScreenSpace;
+            this._hierarchyDepth = 0;
         }
 
         public static _zMinDelta: number = 1 / (Math.pow(2, 24) - 1);

+ 1 - 1
canvas2D/src/Engine/babylon.primitiveCollisionManager.ts

@@ -640,7 +640,7 @@
             });
 
             if (!this._AABBRenderPrim) {
-                this._AABBRenderPrim = new WireFrame2D([g], { parent: this._owner, alignToPixel: false, id: "###DEBUG PCM AABB###" });
+                this._AABBRenderPrim = new WireFrame2D([g], { parent: this._owner, alignToPixel: true, id: "###DEBUG PCM AABB###" });
             } else {
                 this._AABBRenderPrim.wireFrameGroups.set("main", g);
                 this._AABBRenderPrim.wireFrameGroupsDirty();

+ 11 - 3
canvas2D/src/Engine/babylon.text2d.ts

@@ -305,7 +305,11 @@
         public get textSize(): Size {
             if (!this._textSize) {
                 if (this.owner && this._text) {
-                    let newSize = this.fontTexture.measureText(this._text, this._tabulationSize);
+                    let ft = this.fontTexture;
+                    if (ft == null) {
+                        return Text2D.nullSize;
+                    }
+                    let newSize = ft.measureText(this._text, this._tabulationSize);
                     if (!newSize.equals(this._textSize)) {
                         this.onPrimitivePropertyDirty(Prim2DBase.sizeProperty.flagId);
                         this._positioningDirty();
@@ -621,11 +625,15 @@
             if (part.id === Text2D.TEXT2D_MAINPARTID) {
 
                 let d = <Text2DInstanceData>part;
-                let texture = this.fontTexture;
+                let ft = this.fontTexture;
+                let texture = ft;
+                if (!texture) {
+                    return false;
+                }
                 let superSampleFactor = texture.isSuperSampled ? 0.5 : 1;
                 let ts = texture.getSize();
                 let offset = Vector2.Zero();
-                let lh = this.fontTexture.lineHeight;
+                let lh = ft.lineHeight;
 
                 d.dataElementCount = this._charCount;
                 d.curElement = 0;

+ 0 - 13
canvas2D/src/Engine/babylon.wireFrame2d.ts

@@ -406,11 +406,6 @@
             if (!super.refreshInstanceDataPart(part)) {
                 return false;
             }
-
-            if (part.id === WireFrame2D.WIREFRAME2D_MAINPARTID) {
-                let d = <WireFrame2DInstanceData>this._instanceDataParts[0];
-                d.properties = new Vector3(this.alignToPixel ? 1 : 0, 2/this.renderGroup.actualWidth, 2/this.renderGroup.actualHeight);
-            }
             return true;
         }
 
@@ -452,13 +447,5 @@
         constructor(partId: number) {
             super(partId, 1);
         }
-
-        // the properties is for now the alignedToPixel value
-        @instanceData()
-        get properties(): Vector3 {
-            return null;
-        }
-        set properties(value: Vector3) {
-        }
     }
 }

+ 10 - 6
canvas2D/src/shaders/ellipse2d.vertex.fx

@@ -106,13 +106,17 @@ void main(void) {
 	pos.z = 1.0;
 	pos.w = 1.0;
 
-	float rx = dot(pos, transformX);
-	float ry = dot(pos, transformY);
-
+	float x = dot(pos, transformX);
+	float y = dot(pos, transformY);
 	if (renderingInfo.z == 1.0) {
-		rx = floor((rx / renderingInfo.x) + 0.5) * renderingInfo.x;
-		ry = floor((ry / renderingInfo.y) + 0.5) * renderingInfo.y;
+		float rw = renderingInfo.x;
+		float rh = renderingInfo.y;
+		float irw = 2.0 / rw;
+		float irh = 2.0 / rh;
+
+		x = (floor((x / irw) + 0.5) * irw) + irw / 2.0;
+		y = (floor((y / irh) + 0.5) * irh) + irh / 2.0;
 	}
 
-	gl_Position = vec4(rx, ry, zBias.x, 1);
+	gl_Position = vec4(x, y, zBias.x, 1);
 }

+ 10 - 6
canvas2D/src/shaders/lines2d.vertex.fx

@@ -66,13 +66,17 @@ void main(void) {
 	pos.z = 1.0;
 	pos.w = 1.0;
 	
-	float rx = dot(pos, transformX);
-	float ry = dot(pos, transformY);
-
+	float x = dot(pos, transformX);
+	float y = dot(pos, transformY);
 	if (renderingInfo.z == 1.0) {
-		rx = floor((rx / renderingInfo.x) + 0.5) * renderingInfo.x;
-		ry = floor((ry / renderingInfo.y) + 0.5) * renderingInfo.y;
+		float rw = renderingInfo.x;
+		float rh = renderingInfo.y;
+		float irw = 2.0 / rw;
+		float irh = 2.0 / rh;
+
+		x = (floor((x / irw) + 0.5) * irw) + irw / 2.0;
+		y = (floor((y / irh) + 0.5) * irh) + irh / 2.0;
 	}
 
-	gl_Position = vec4(rx, ry, zBias.x, 1);
+	gl_Position = vec4(x, y, zBias.x, 1);
 }

+ 10 - 6
canvas2D/src/shaders/rect2d.vertex.fx

@@ -204,13 +204,17 @@ void main(void) {
 	pos.z = 1.0;
 	pos.w = 1.0;
 
-	float rx = dot(pos, transformX);
-	float ry = dot(pos, transformY);
-
+	float x = dot(pos, transformX);
+	float y = dot(pos, transformY);
 	if (renderingInfo.z == 1.0) {
-		rx = floor((rx / renderingInfo.x) + 0.5) * renderingInfo.x;
-		ry = floor((ry / renderingInfo.y) + 0.5) * renderingInfo.y;
+		float rw = renderingInfo.x;
+		float rh = renderingInfo.y;
+		float irw = 2.0 / rw;
+		float irh = 2.0 / rh;
+
+		x = (floor((x / irw) + 0.5) * irw) + irw / 2.0;
+		y = (floor((y / irh) + 0.5) * irh) + irh / 2.0;
 	}
 
-	gl_Position = vec4(rx, ry, zBias.x, 1);
+	gl_Position = vec4(x, y, zBias.x, 1);
 }

+ 1 - 1
canvas2D/src/shaders/sprite2d.vertex.fx

@@ -1,4 +1,4 @@
-// based on if Instanced Array are supported or not, declare the field either as attribute or uniform
+based on if Instanced Array are supported or not, declare the field either as attribute or uniform
 #ifdef Instanced
 #define att attribute
 #else

+ 13 - 6
canvas2D/src/shaders/wireframe2d.vertex.fx

@@ -18,6 +18,7 @@ att vec3 properties;
 att vec2 zBias;
 att vec4 transformX;
 att vec4 transformY;
+att vec3 renderingInfo;
 att float opacity;
 
 // Uniforms
@@ -30,11 +31,17 @@ void main(void) {
 	vec4 p = vec4(pos.xy, 1.0, 1.0);
 	vColor = vec4(col.xyz, col.w*opacity);
 
-	vec4 pp = vec4(dot(p, transformX), dot(p, transformY), zBias.x, 1);
-	
-	if (properties.x == 1.0) {
-		pp.xy = pp.xy - mod(pp.xy, properties.yz) + (properties.yz*0.5);
+	float x = dot(p, transformX);
+	float y = dot(p, transformY);
+	if (renderingInfo.z == 1.0) {
+		float rw = renderingInfo.x;
+		float rh = renderingInfo.y;
+		float irw = 2.0 / rw;
+		float irh = 2.0 / rh;
+
+		x = (floor((x / irw) + 0.5) * irw) + irw/2.0;
+		y = (floor((y / irh) + 0.5) * irh) + irh/2.0;
 	}
 
-	gl_Position = pp;
-}	
+	gl_Position = vec4(x, y, zBias.x, 1);
+}