Browse Source

Less allocs for HtmlText drop shadows.

clementlandrin 2 years ago
parent
commit
20fa2de1a1
2 changed files with 11 additions and 5 deletions
  1. 8 4
      h2d/HtmlText.hx
  2. 3 1
      h3d/shader/ColorMatrix.hx

+ 8 - 4
h2d/HtmlText.hx

@@ -105,9 +105,11 @@ class HtmlText extends Text {
 			var oldX = absX, oldY = absY;
 			absX += dropShadow.dx * matA + dropShadow.dy * matC;
 			absY += dropShadow.dx * matB + dropShadow.dy * matD;
-			if( dropMatrix == null )
+			if( dropMatrix == null ) {
 				dropMatrix = new h3d.shader.ColorMatrix();
-			addShader(dropMatrix);
+				addShader(dropMatrix);
+			}
+			dropMatrix.enabled = true;
 			var m = dropMatrix.matrix;
 			m.zero();
 			m._41 = ((dropShadow.color >> 16) & 0xFF) / 255;
@@ -115,11 +117,13 @@ class HtmlText extends Text {
 			m._43 = (dropShadow.color & 0xFF) / 255;
 			m._44 = dropShadow.alpha;
 			glyphs.drawWith(ctx, this);
-			removeShader(dropMatrix);
+			dropMatrix.enabled = false;
 			absX = oldX;
 			absY = oldY;
-		} else
+		} else {
+			removeShader(dropMatrix);
 			dropMatrix = null;
+		}
 		glyphs.drawWith(ctx,this);
 	}
 

+ 3 - 1
h3d/shader/ColorMatrix.hx

@@ -6,9 +6,11 @@ class ColorMatrix extends hxsl.Shader {
 		var pixelColor : Vec4;
 
 		@param var matrix : Mat4;
+		@const var enabled : Bool = true; // allows for drop shadow toggle
 
 		function fragment() {
-			pixelColor = vec4( (vec4(pixelColor.rgb,1.) * matrix).rgb, (pixelColor * matrix).a);
+			if ( enabled )
+				pixelColor = vec4( (vec4(pixelColor.rgb,1.) * matrix).rgb, (pixelColor * matrix).a);
 		}
 
 	};