 		}
 
 
-		/** Assembles fragment- and vertex-shaders, passed as Strings, to a Program3D. 
-		 *  If any argument is  null, it is replaced by the class constants STD_FRAGMENT_SHADER or
-		 *  STD_VERTEX_SHADER, respectively. */
-		protected function assembleAgal(fragmentShader:String = null, vertexShader:String = null):Program3D
-		{
-			if (fragmentShader == null) fragmentShader = STD_FRAGMENT_SHADER;
-			if (vertexShader == null) vertexShader = STD_VERTEX_SHADER;
-
+		/**
+		 * Assembles fragment- and vertex-shaders, passed as Strings, to a Program3D. 
+		 * If any argument is  null, it is replaced by the class constants STD_FRAGMENT_SHADER or
+		 * STD_VERTEX_SHADER, respectively.
+		 * 
+		 * @param fragmentShader
+		 * @param vertexShader
+		 * @return Program3D
+		 */
+		protected function assembleAgal(fragmentShader:String = null,
+			vertexShader:String = null):Program3D
+		{
+			if (!fragmentShader) fragmentShader = STD_FRAGMENT_SHADER;
+			if (!vertexShader) vertexShader = STD_VERTEX_SHADER;
 			return RenderSupport2D.assembleAgal(vertexShader, fragmentShader);
 		}
-
-
-		// cache
-		/** Caches the filter output into a texture. An uncached filter is rendered in every frame;
-		 *  a cached filter only once. However, if the filtered object or the filter settings
-		 *  change, it has to be updated manually; to do that, call "cache" again. */
-		public function cache():void
-		{
-			mCacheRequested = true;
-			disposeCache();
-		}
-
-
-		/** Clears the cached output of the filter. After calling this method, the filter will
-		 *  be executed once per frame again. */
-		public function clearCache():void
-		{
-			mCacheRequested = false;
-			disposeCache();
-		}
-
-
-		// flattening
-		/** @private */
-		public function compile(object:DisplayObject2D):QuadBatch2D
-		{
-			if (mCache) return mCache;
-			else
-			{
-				var renderSupport:RenderSupport2D;
-				var stage:Stage2D = object.stage;
-
-				if (stage == null)
-					throw new Error("Filtered object must be on the stage.");
-
-				renderSupport = new RenderSupport2D();
-				object.getTransformationMatrix(stage, renderSupport.modelViewMatrix);
-				return renderPasses(object, renderSupport, 1.0, true);
-			}
-		}
-
-
-		// properties
-		/** Indicates if the filter is cached (via the "cache" method). */
-		public function get isCached():Boolean
-		{
-			return (mCache != null) || mCacheRequested;
-		}
-
-
-		/** The resolution of the filter texture. "1" means stage resolution, "0.5" half the
-		 *  stage resolution. A lower resolution saves memory and execution time (depending on 
-		 *  the GPU), but results in a lower output quality. Values greater than 1 are allowed;
-		 *  such values might make sense for a cached filter when it is scaled up. @default 1 */
-		public function get resolution():Number
-		{
-			return mResolution;
-		}
-
-
-		public function set resolution(value:Number):void
-		{
-			if (value <= 0) throw new ArgumentError("Resolution must be > 0");
-			else mResolution = value;
-		}
-
-
-		/** The filter mode, which is one of the constants defined in the "FragmentFilterMode" 
-		 *  class. @default "replace" */
-		public function get mode():String
-		{
-			return mMode;
-		}
-
-
-		public function set mode(value:String):void
-		{
-			mMode = value;
-		}
-
-
-		/** Use the x-offset to move the filter output to the right or left. */
-		public function get offsetX():Number
-		{
-			return mOffsetX;
-		}
-
-
-		public function set offsetX(value:Number):void
-		{
-			mOffsetX = value;
-		}
-
-
-		/** Use the y-offset to move the filter output to the top or bottom. */
-		public function get offsetY():Number
-		{
-			return mOffsetY;
-		}
-
-
-		public function set offsetY(value:Number):void
-		{
-			mOffsetY = value;
-		}
-
-
-		/** The x-margin will extend the size of the filter texture along the x-axis.
-		 *  Useful when the filter will "grow" the rendered object. */
-		protected function get marginX():Number
-		{
-			return mMarginX;
-		}
-
-
-		protected function set marginX(value:Number):void
-		{
-			mMarginX = value;
-		}
-
-
-		/** The y-margin will extend the size of the filter texture along the y-axis.
-		 *  Useful when the filter will "grow" the rendered object. */
-		protected function get marginY():Number
-		{
-			return mMarginY;
-		}
-
-
-		protected function set marginY(value:Number):void
-		{
-			mMarginY = value;
-		}
-
-
-		/** The number of passes the filter is applied. The "activate" and "deactivate" methods
-		 *  will be called that often. */
-		protected function set numPasses(value:int):void
-		{
-			mNumPasses = value;
-		}
-
-
-		protected function get numPasses():int
-		{
-			return mNumPasses;
-		}
-
-
-		/** The ID of the vertex buffer attribute that stores the vertex position. */
-		protected final function get vertexPosAtID():int
-		{
-			return mVertexPosAtID;
-		}
-
-
-		protected final function set vertexPosAtID(value:int):void
-		{
-			mVertexPosAtID = value;
-		}
-
-
-		/** The ID of the vertex buffer attribute that stores the texture coordinates. */
-		protected final function get texCoordsAtID():int
-		{
-			return mTexCoordsAtID;
-		}
-
-
-		protected final function set texCoordsAtID(value:int):void
-		{
-			mTexCoordsAtID = value;
-		}
-
-
-		/** The ID (sampler) of the input texture (containing the output of the previous pass). */
-		protected final function get baseTextureID():int
-		{
-			return mBaseTextureID;
-		}
-
-
-		protected final function set baseTextureID(value:int):void
-		{
-			mBaseTextureID = value;
-		}
-
-
-		/** The ID of the first register of the modelview-projection constant (a 4x4 matrix). */
-		protected final function get mvpConstantID():int
-		{
-			return mMvpConstantID;
-		}
-
-
-		protected final function set mvpConstantID(value:int):void
-		{
-			mMvpConstantID = value;
-		}
 	}
-}+}

	import flash.errors.IllegalOperationError;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;
	import flash.system.Capabilities;
	import flash.utils.getQualifiedClassName;


	/** The FragmentFilter class is the base class for all filter effects in Render2D.

				// the bounds are a rectangle around the object, in stage coordinates,
				// and with an optional margin. To fit into a POT-texture, it will grow towards
				// the right and bottom.
				var deltaMargin:Number = _resolution == 1.0 ? 0.0 : 1.0 / _resolution;
				// avoid hard edges
				resultRect.x -= _marginX + deltaMargin;
				resultRect.y -= _marginY + deltaMargin;
				resultRect.width += 2 * (_marginX + deltaMargin);
				resultRect.height += 2 * (_marginY + deltaMargin);
				resultRect.width = nextPowerOfTwo(resultRect.width * _resolution) / _resolution;
				resultRect.height = nextPowerOfTwo(resultRect.height * _resolution) / _resolution;
			}
		}


		private function disposePassTextures():void
		{
			for each (var texture:Texture2D in _passTextures)
				texture.dispose();

			_passTextures = null;
		}


		private function disposeCache():void
		{
			if (_cache)
			{
				if (_cache.texture) _cache.texture.dispose();
				_cache.dispose();
				_cache = null;
			}
		}

