public void Draw(GameTime gameTime, Camera camera) { try { // First, we need to figure out which stars // are behind us and throw them out in front of us again // based on how fast the camera is moving if (!motionReady) { GenerateStars(camera); vertexBuffer.SetData <VertexPointSprite>(data); } else { MoveStars(camera); vertexBuffer.SetData <VertexPointSprite>(data); } { // // STARS // starEffect.Parameters["World"].SetValue(Matrix.Identity); starEffect.Parameters["View"].SetValue(camera.View); starEffect.Parameters["Projection"].SetValue(camera.Projection); starEffect.Parameters["Texture"].SetValue(starTexture); starEffect.Parameters["ViewportHeight"].SetValue(GraphicsDevice.Viewport.Height); GraphicsDevice.SetVertexBuffer(vertexBuffer); PointSpriteHelper.Enable(); // Set the alpha blend mode. BlendStateHelper.BeginApply(GraphicsDevice); BlendStateHelper.AlphaBlendEnable = true; BlendStateHelper.SourceBlend = Blend.SourceAlpha; BlendStateHelper.DestinationBlend = Blend.InverseSourceAlpha; BlendStateHelper.EndApply(GraphicsDevice); // Enable the depth buffer (so particles will not be visible through // solid objects like the space ship), but disable depth writes // (so particles will not obscure other particles). GraphicsDevice.DepthStencilState = DepthStencilState.DepthRead; for (int i = 0; i < starEffect.CurrentTechnique.Passes.Count; ++i) { starEffect.CurrentTechnique.Passes[i].Apply(); #if SDL2 GraphicsDevice.DrawPrimitives(PrimitiveType.PointListEXT, 0, starCount); #endif } PointSpriteHelper.Disable(); GraphicsDevice.SetVertexBuffer(null); BlendStateHelper.BeginApply(GraphicsDevice); BlendStateHelper.AlphaBlendEnable = false; BlendStateHelper.EndApply(GraphicsDevice); if (GraphicsDevice.DepthStencilState.DepthBufferEnable) { GraphicsDevice.DepthStencilState = DepthStencilState.Default; } else { GraphicsDevice.DepthStencilState = Helpers.DepthWrite; } } base.Draw(gameTime); } catch { } }
/// <summary> /// Draws the particle system. /// </summary> public override void Draw(GameTime gameTime) { try { GraphicsDevice device = GraphicsDevice; SetCamera(Camera.View, Camera.Projection); // Restore the vertex buffer contents if the graphics device was lost. if (vertexBuffer.IsContentLost) { vertexBuffer.SetData(particles); } // If there are any particles waiting in the newly added queue, // we'd better upload them to the GPU ready for drawing. if (firstNewParticle != firstFreeParticle) { AddNewParticlesToVertexBuffer(); } // If there are any active particles, draw them now! if (firstActiveParticle != firstFreeParticle) { SetParticleRenderStates(device); // Set an effect parameter describing the viewport size. This is needed // to convert particle sizes into screen space point sprite sizes. effectViewportHeightParameter.SetValue(device.Viewport.Height); // Set an effect parameter describing the current time. All the vertex // shader particle animation is keyed off this value. effectTimeParameter.SetValue(currentTime); // Set the particle vertex buffer and vertex declaration. device.SetVertexBuffer(vertexBuffer); //foreach (EffectPass pass in particleEffect.CurrentTechnique.Passes) for (int i = 0; i < particleEffect.CurrentTechnique.Passes.Count; ++i) { particleEffect.CurrentTechnique.Passes[i].Apply(); #if SDL2 if (firstActiveParticle < firstFreeParticle) { // If the active particles are all in one consecutive range, // we can draw them all in a single call. device.DrawPrimitives(PrimitiveType.PointListEXT, firstActiveParticle, firstFreeParticle - firstActiveParticle); } else { // If the active particle range wraps past the end of the queue // back to the start, we must split them over two draw calls. device.DrawPrimitives(PrimitiveType.PointListEXT, firstActiveParticle, particles.Length - firstActiveParticle); if (firstFreeParticle > 0) { device.DrawPrimitives(PrimitiveType.PointListEXT, 0, firstFreeParticle); } } #endif } // Reset a couple of the more unusual renderstates that we changed, // so as not to mess up any other subsequent drawing. PointSpriteHelper.Disable(); if (device.DepthStencilState.DepthBufferEnable) { device.DepthStencilState = DepthStencilState.Default; } else { device.DepthStencilState = Helpers.DepthWrite; } } } catch { } drawCounter++; }