//draw all the instances
		//Note this class must be drawn after all the instances, to keep drawing in
		//the correct order. Otherwise instance culling may appear a frame delayed.
		public void Draw(DrawState state)
		{
			//get the instancing shader and bind it
			var shader = state.GetShader<Shader.Tutorial16>();

			using (state + shader)
			{
				//in this case, Xen.Ex.Geometry.Sphere implements IDrawBatch - allowing drawing a batch easily
				//otherwise, a call to:
				//
				//  vertices.DrawInstances(...)
				//
				//can be made (internally, the Sphere class does exactly this)

				//Note that all prebuilt shaders in Xen supports hardware instancing, and could be used in place of the custom shader

				//Get a dynamic instance buffer from the DrawState.
				//Pass in the matrix array to fill the buffer with the matrices
				//(Alternatively, get an empty instance buffer and write each matrix one at a time)
				var buffer = state.GetDynamicInstanceBuffer(this.instanceMatrices, this.instanceCount);

				//draw the dynamic instances
				geometry.DrawBatch(state, buffer);

				//reset the counter for the next frame
				instanceCount = 0;
			}
		}
		/// <summary>
		/// Draw the logo
		/// </summary>
		public void Draw(DrawState state)
		{
			if (clearBackground)
				this.clear.Draw(state);

			if (EffectFinished)
			{
				if (this.particles != null)
					this.particles.Dispose();
				if (content != null)
					this.content.Dispose();
				this.particleDrawer = null;
				this.particles = null;
				this.particleTrigger = null;
				this.content = null;
			}
			else
			{
				//x axis min/max start range for the particles to spawn in at
				this.particles.GlobalValues[0] = -state.DrawTarget.Size.X / 2;
				this.particles.GlobalValues[1] = 0;

				//y axis min/max start range for the particles to spawn in at
				this.particles.GlobalValues[2] = -state.DrawTarget.Size.Y / 2 - 200;
				this.particles.GlobalValues[3] = +state.DrawTarget.Size.Y / 2 + 200;

				drawingBegun = true;

				if (particles.GetParticleCount(0) > 0)
					particlesCreated = true;

				this.particleDrawer.Draw(state);
			}
		}
		public void Draw(DrawState state)
		{
			using (state.WorldMatrix.PushTranslateMultiply(ref this.position))
			{
				if (geometry.CullTest(state))
				{
					//draw the geometry

					using (state + shader)
					{
						geometry.Draw(state);

						//now, if set, draw the wireframe too
						if (wireframeShader != null)
						{
							state.Shader.Set(wireframeShader);

							//show the wireframe, disabling depth testing
							state.RenderState.Push();
							state.RenderState.CurrentDepthState.DepthTestEnabled = false;
							//also set additive blending
							state.RenderState.CurrentBlendState = AlphaBlendState.Additive;
							//set wireframe
							state.RenderState.CurrentRasterState.FillMode = FillMode.WireFrame;

							//draw
							geometry.Draw(state);

							state.RenderState.Pop();
						}
					}
				}
			}
		}
		//when drawing, the instances will call this method
		public void AddDynamicInstance(DrawState state)
		{
			//store the instance matrix
			state.WorldMatrix.GetMatrix(out instanceMatrices[instanceCount]);

			instanceCount++;
		}
		public void Draw(DrawState state)
		{
			using (state.WorldMatrix.PushMultiply(ref worldMatrix))
			{

				//cull test the sphere (note, the cull test uses the current world matrix)
				if (sphereGeometry.CullTest(state))
				{
					//NEW CODE
					//In this sample, the shader instance is defined in this class, however
					//the draw state can be used to get a shared static instance of a shader. 
					//Getting shader instances in this way can reduce memory usage. Eg:
					//
					// var shader = state.GetShader<Shader.Tutorial03Technique>();
					//

					//compute a scale value that follows a sin wave
					float scaleValue = (float)Math.Sin(state.TotalTimeSeconds) * 0.5f + 1.0f;

					//Set the scale value (scale is declared in the shader source)
					shader.Scale = scaleValue;
					
					//Bind the custom shader instance
					using (state.Shader.Push(shader))
					{
						//draw the sphere geometry
						sphereGeometry.Draw(state);
					}
				}

				//xen will reset the world matrix when the using statement finishes:
			}
		}
		public void Draw(DrawState state)
		{
			//ModelInstances automatically setup the default material shaders
			//Custom shaders can be used with model.SetShaderOverride(...)
			model.Draw(state);

			DrawBoundingBoxes(state);
		}
Example #7
0
        public void Draw(DrawState state)
        {
            //bind the background filling shader

            using (state.Shader.Push(state.GetShader<Shaders.BackgroundFill>()))
            {
                geometry.Draw(state);
            }
        }
		//everything else from here on is identical...

		public void Draw(DrawState state)
		{
			//ModelInstances automatically setup the default material shaders
			//Custom shaders can be used with model.SetShaderOverride(...)
			using (state.WorldMatrix.PushMultiply(ref WorldMatrix))
			{
				model.Draw(state);
			}
		}
		public void Draw(DrawState state)
		{
			using (state.WorldMatrix.Push(ref worldMatrix))
			{
				//ModelData stores accurate bounding box information
				//the ModelInstance uses this to cull the model.

				if (model.CullTest(state))
					model.Draw(state);
			}
		}
Example #10
0
        public void Draw(DrawState state)
        {
            //set the draw flags up, which will control rendering
            //this will make the models render depth
            using (state.DrawFlags.Push(new ModelShaderProviderFlag(this.shaderProvider)))
            using (state.DrawFlags.Push(RenderMode.DepthOutput))
            {
                //draw the scene
                scene.Draw(state);

            }
        }
Example #11
0
 public void Draw(DrawState state)
 {
     using (state.WorldMatrix.Push(ref worldMatrix))
     {
         using(state.WorldMatrix.Push(ref scaleMatrix))
         {
             if (model.CullTest(state))
             {
                 model.Draw(state);
             }
         }
     }
 }
		public void Draw(DrawState state)
		{
			using (state.WorldMatrix.PushMultiply(ref this.worldMatrix))
			{
				if (instance.CullTest(state))
				{
					//note: this doesn't actually draw the instance right now, it simply
					//stores information in the BatchModel about where this instance is drawn.
					//When the BatchModel draws, it will draw all the instances in one go.

					instance.Draw(state);
				}
			}
		}
Example #13
0
 public void Draw(DrawState state)
 {
     using (state.WorldMatrix.Push(ref worldMatrix))
     {
         using (state.WorldMatrix.PushMultiply(ref scaleMatrix))
         {
             if (model.CullTest(state))
             {
                 using (state.Shader.Push(this.shader))
                 {
                     model.Draw(state);
                 }
             }
         }
     }
 }
		//draw the sphere with alpha blending
		public void Draw(DrawState state)
		{
			//below are 4 variations on how to set the alpha blending render state
			switch (renderStateMode % 4)
			{
				case 0:
					DrawManual(state);
					break;
				case 1:
					DrawPushPopManual(state);
					break;
				case 2:
					DrawPushPopStatic(state);
					break;
				case 3:
					DrawPushPopStored(state);
					break;
			}

			//cycle the various methods
			renderStateMode++;
		}
		public void Draw(DrawState state)
		{
            state.RenderState.CurrentRasterState.CullMode = CullMode.None;

			if (Model.ModelData == null) return;


            
			Matrix worldMatrix = Transform * (PhysicsEntity != null ? PhysicsEntity.WorldTransform : Matrix.Identity);

            if (isSquashed)
            {
                float progress = squashTicks / 100.0f;
                worldMatrix = Matrix.CreateScale(progress) * Matrix.CreateFromYawPitchRoll(progress * 10, progress * 10, progress * 10) * worldMatrix;
                squashTicks--;

                if (squashTicks <= 0)
                {
                    ClearKillRemoveDestroy();
                }
            }


			using (state.WorldMatrix.PushMultiply(ref worldMatrix))
			{
				
				if (Model.CullTest(state))
				{
					using (state.Shader.Push(Shader))
					{
						Model.Draw(state);
					}
				}
			}

			//DrawDebug(state, worldMatrix);
		}
		//each of these 4 methods is more efficient than the previous...

		//this method is the manual method where each state is setup peice by peice
		private void DrawManual(DrawState state)
		{
			//manual render state

			//First, take a copy of current render state..
			DeviceRenderState currentState = state.RenderState;
			
			//The DeviceRenderState structure stores common render state.
			//The majority of render state is stored, with most commonly used xbox-supported state included.
			//The entire structure is less than 16 bytes (the size of a Vector4)
			//
			//The DeviceRenderState structure stores four smaller structures:
			//
			//	StencilState			Stencil;		(8 bytes)
			//	AlphaBlendState			Blend;			(4 bytes)	
			//	RasterState				Raster;			(2 bytes)
			//	DepthState				Depth;		    (1 byte)
			//
			
			//Here the alpha blend state is changed manually...

			//reset the DrawState's alpha blending render state to default (no blending)
			state.RenderState.CurrentBlendState = new AlphaBlendState();

			//set blending states one by one...
			state.RenderState.CurrentBlendState.Enabled = true;
			state.RenderState.CurrentBlendState.SourceBlend = Blend.SourceAlpha;
			state.RenderState.CurrentBlendState.DestinationBlend = Blend.InverseSourceAlpha;


			//draw the sphere
			DrawGeometry(state);


			//reset the previous state back
			state.RenderState.Set(ref currentState);
		}
		public void Draw(DrawState state)
		{
			//switch rendering mode based on the TutorialRenderMode flag
			switch (state.DrawFlags.GetFlag<TutorialRenderMode>())
			{
				case TutorialRenderMode.DepthOutput:
					//bind the depth output shader
					state.Shader.Push(state.GetShader<Xen.Ex.Shaders.NonLinearDepthOut>());
					break;
				case TutorialRenderMode.DrawShadow:
					//bind the shadow rendering shader
					Shader.ShadowShader shader = state.GetShader<Shader.ShadowShader>();
					shader.TextureMap = material.Textures.TextureMap;
					shader.TextureSampler = material.Textures.TextureMapSampler;
					state.Shader.Push(shader);
					break;
				default:
					//no flag known specified
					state.Shader.Push(material);
					break;
			}

			//draw the ground
			vertices.Draw(state, indices, PrimitiveType.TriangleList);

			state.Shader.Pop();
		}
Example #18
0
        internal void OnDraw(DrawState state)
        {
#if DEBUG
            previousFrame = currentFrame;
            currentFrame.Reset();
            currentFrame.Begin();
#endif

            ushort stackHeight, stateHeight, cameraHeight, preCull, postCull;
            state.GetStackHeight(out stackHeight, out stateHeight, out cameraHeight, out preCull, out postCull);

            if (approxFps.Count == 20)
            {
                LinkedListNode <double> first = approxFps.First;
                approxFps.Remove(first);
                first.Value = state.DeltaTimeFrequency;
                approxFps.AddLast(first);
            }
            else
            {
                approxFps.AddLast(state.DeltaTimeFrequency);
            }

            double total = 0;
            foreach (double d in approxFps)
            {
                total += d;
            }
            if (approxFps.Count > 0)
            {
                total /= approxFps.Count;
            }

            approximateFrameRate = (float)total;

            state.PrepareForNewFrame();

            //the predraw list is a list of items that need to be drawn before the frame starts
            //eg, an object in Update may require something is drawn this frame.
            //call PreFrameDraw in either Update() or Draw() to add to this list
            while (true)
            {
                lock (preFrameDrawList)
                {
                    if (preFrameDrawList.Count == 0)
                    {
                        break;
                    }

                    preFrameDrawListBuffer.AddRange(preFrameDrawList);
                    preFrameDrawList.Clear();
                }

                foreach (IDraw item in preFrameDrawListBuffer)
                {
                    if (item.CullTest(state))
                    {
                        item.Draw(state);
                    }
                }

                preFrameDrawListBuffer.Clear();
            }

            Draw(state);

            state.ValidateStackHeight(stackHeight, stateHeight, cameraHeight, preCull, postCull);

#if DEBUG
            currentFrame.End();
#endif

#if !XBOX360
            if (winFormsDispose)
            {
                xnaLogic.Exit();

                xnaLogic.Dispose();
            }
#endif
        }
		public void Draw(DrawState state)
		{
			//set the draw flags up, which will control rendering
			//this will make the models render depth
			using (state.DrawFlags.Push(TutorialRenderMode.DepthOutput))					//set the flag to depth output
			using (state.DrawFlags.Push(new ModelShaderProviderFlag(this.shaderProvider)))	//make sure the provider is used
			{
				//draw the scene
				scene.Draw(state);

			}
		}
		public void Draw(DrawState state)
		{
			using (state.WorldMatrix.PushMultiply(ref this.worldMatrix))
			{
				model.Draw(state);
			}
		}
		public void Draw(DrawState state)
		{
			SetupShadowShader(state);

			//set render mode to shadow map
			using (state.DrawFlags.Push(TutorialRenderMode.DrawShadow))						//set the flag to draw the shadowed light
			using (state.DrawFlags.Push(new ModelShaderProviderFlag(this.shaderProvider)))	//make sure the provider is used
			{

				//Push the shadow map camera as a post-culler.
				//This way, anything not within the frustum of the shadow map
				//camera will not be drawn with the shadow shader
				//if it's not in the view of the shadow map camera, it can't be lit.
				using (state.Cullers.PushPostCuller(this.shadowMapTarget.Camera))
				using (state.RenderState.Push())
				{
					//set an additive blending mode
					state.RenderState.CurrentBlendState = AlphaBlendState.AdditiveSaturate;
					state.RenderState.CurrentDepthState.DepthWriteEnabled = false;

					//draw the shadowed scene
					scene.Draw(state);
				}

			}
		}
Example #22
0
 public void EndModel(DrawState state)
 {
 }
		/// <summary>Draw the cone as a batch</summary>
		public void DrawBatch(DrawState state, Xen.Graphics.InstanceBuffer instances)
		{
			verts.DrawInstances(state, inds, PrimitiveType.TriangleList, instances);
		}
			internal UsingPopBeginEndDraw(IBeginEndDraw draw, DrawState state)
			{
				this.draw = draw;
				this.state = state;
				draw.Begin(state);
			}
Example #25
0
 /// <summary>
 /// Override this method to perform custom content unloading
 /// </summary>
 /// <param name="state"></param>
 protected virtual void UnloadContent(DrawState state)
 {
 }
Example #26
0
 /// <summary>
 /// Run all drawing code in this method
 /// </summary>
 /// <param name="state"></param>
 protected internal abstract void Draw(DrawState state);
		private void SetupShadowShader(DrawState state)
		{
			var shadowCamera = this.shadowMapTarget.Camera;

			//compute the view*projection matrix for the shadow map camera...

			Matrix view, projection, viewProjection;
			shadowCamera.GetViewMatrix(out view);
			shadowCamera.GetProjectionMatrix(out projection, this.shadowMapTarget.Size);

			Matrix.Multiply(ref view, ref projection, out viewProjection);

			//and the view direction
			Vector3 viewDirection;
			shadowCamera.GetCameraViewDirection(out viewDirection);


			//set the matrix and other constants in the shadow mapping shader instances
			var shader = state.GetShader<Shader.ShadowShader>();

			//non-blending shader
			shader.LightColour = lightColour;
			shader.ShadowMap = this.shadowMapTarget.GetTexture();
			shader.SetShadowMapProjection(ref viewProjection);
			shader.SetShadowViewDirection(ref viewDirection);
		}
Example #28
0
 /// <summary>
 /// Override this method to perform custom content loading through an XNA ContentManager
 /// </summary>
 /// <param name="state"></param>
 /// <param name="manager"></param>
 protected virtual void LoadContent(DrawState state, ContentManager manager)
 {
 }
		internal void OnDraw(FrameState frame,DrawState state)
		{
#if DEBUG
			previousFrame = currentFrame;
			currentFrame.Reset();
			currentFrame.Begin();
#endif

			ushort stackHeight, stateHeight, cameraHeight, preCull,postCull;
			state.GetStackHeight(out stackHeight, out stateHeight, out cameraHeight,out preCull,out postCull);

			if (approxFps.Count == 20)
			{
				LinkedListNode<double> first = approxFps.First;
				approxFps.Remove(first);
				first.Value = state.DeltaTimeFrequency;
				approxFps.AddLast(first);
			}
			else
				approxFps.AddLast(state.DeltaTimeFrequency);
			
			double total = 0;
			foreach (double d in approxFps)
				total += d;
			if (approxFps.Count > 0)
				total /= approxFps.Count;

			approximateFrameRate = (float)total;

			if (drawableComponents > 0)
				state.renderState.InternalDirtyRenderState(Xen.Graphics.StateFlag.All);

			state.PrepareForNewFrame();

			//the predraw list is a list of items that need to be drawn before the frame starts
			//eg, an object in Update may require something is drawn this frame.
			//call PreFrameDraw in either Update() or Draw() to add to this list
			while (true)
			{
				lock (preFrameDrawList)
				{
					if (preFrameDrawList.Count == 0)
						break;

					foreach (IFrameDraw item in preFrameDrawList)
						preFrameDrawListBuffer.Add(item);
					preFrameDrawList.Clear();
				}

				foreach (IFrameDraw item in preFrameDrawListBuffer)
				{
					item.Draw(frame);
				}

				preFrameDrawListBuffer.Clear();
			}

			Frame(frame);

			state.ValidateStackHeight(stackHeight, stateHeight, cameraHeight, preCull, postCull);

#if DEBUG
			currentFrame.End();
#endif

#if !XBOX360
			//if (winFormsDispose)
			//{
			//	xnaLogic.Exit();
			//
			//	xnaLogic.Dispose();
			//}
#endif
		}
Example #30
0
 void IContentOwner.UnloadContent(ContentRegister content, DrawState state)
 {
     xnaLogic.state.GetRenderState(state.BeginGetGraphicsDevice(Xen.Graphics.State.StateFlag.None)).DirtyInternalRenderState(Xen.Graphics.State.StateFlag.All);
     state.EndGetGraphicsDevice();
     this.UnloadContent(state);
 }
Example #31
0
        public void Draw(DrawState state)
        {
            using (state.WorldMatrix.Push(ref worldMatrix))
            {
                //ModelInstances automatically setup the default material shaders
                //Custom shaders can be used with model.SetShaderOverride(...)

                //ModelData stores accurate bounding box information
                //the ModelInstance uses this to cull the model

                if (model.CullTest(state))
                {
                    //using (state.Shader.Push(Material))
                    {
                        Vector2 mousePos = MousePosition;
                        Vector3 worldPosition, cameraPosition;
                        state.Camera.ProjectFromTarget(ref mousePos, 1000, out worldPosition);
                        state.Camera.GetCameraPosition(out cameraPosition);
                        RayFromMouse = worldPosition - cameraPosition;
                        RayFromMouse.Normalize();
                        RayFromMouse *= 100;

                        //PickingDrawer.position = rayFromMouse;
                        //state.RenderState.CurrentRasterState.FillMode = FillMode.WireFrame;

                        model.Draw(state);
                        //state.RenderState.CurrentRasterState.FillMode = FillMode.Solid;
                    }
                }
            }
        }
		/// <summary>Draw the cone</summary>
		public void Draw(DrawState state)
		{
			verts.Draw(state, inds, PrimitiveType.TriangleList);
		}
Example #33
0
 //get the shader specific to this geometry.
 public IShader BeginGeometry(DrawState state, Xen.Ex.Graphics.Content.GeometryData geometry)
 {
     //setup the shader specifics, including texture, normal map and SOF texture
     shader.AlbedoTexture = geometry.MaterialData.Texture;
     shader.NormalTexture = geometry.MaterialData.NormalMap;
     shader.SofTexture = this.SofTextures[geometry.Index];
     return shader;
 }
		/// <summary></summary>
		public void DrawBatch(DrawState state, Matrix[] instances, int instanceCount)
		{
			verts.DrawInstances(state, inds, PrimitiveType.TriangleList, instances, instanceCount);
		}
Example #35
0
 //IModelShaderProvider implementation:
 public IShader BeginModel(DrawState state, Xen.Ex.Material.MaterialLightCollection lights)
 {
     return null;
 }