/// <summary> /// Custom drawing technique - sets graphics states and /// draws the custom shape /// </summary> /// <param name="camera">The currently drawing camera</param> #endregion public void Draw(Camera camera) { ////////////////////Early Out/////////////////// if (!Visible) { return; } //////////////////End Early Out///////////////// // Set graphics states FlatRedBallServices.GraphicsDevice.RasterizerState = RasterizerState.CullNone; // texture options // Have the current camera set our current view/projection variables camera.SetDeviceViewAndProjection(mEffect, false); // Here we get the positioned object's transformation (position / rotation) mEffect.World = Matrix.CreateScale(RenderingScale) * base.TransformationMatrix; mEffect.Texture = mTexture; // We won't need to use any other kind of texture // address mode besides clamp, and clamp is required // on the "Reach" profile when the texture is not power // of two. Let's set it to clamp here so that we don't crash // on non-power-of-two textures. TextureAddressMode oldTextureAddressMode = Renderer.TextureAddressMode; Renderer.TextureAddressMode = TextureAddressMode.Clamp; // Start the effect foreach (EffectPass pass in mEffect.CurrentTechnique.Passes) { // Start each pass pass.Apply(); // Draw the shape FlatRedBallServices.GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionTexture>( PrimitiveType.TriangleList, mVertices, 0, mVertices.Length, mIndices, 0, mIndices.Length / 3); } Renderer.TextureAddressMode = oldTextureAddressMode; }
/// <summary> /// Custom drawing technique - sets graphics states and /// draws the custom shape /// </summary> /// <param name="camera">The currently drawing camera</param> #endregion public void Draw(Camera camera) { ////////////////////Early Out/////////////////// if (!Visible) { return; } if (mVertices.Length == 0) { return; } //////////////////End Early Out///////////////// int firstVertIndex; int lastVertIndex; int indexStart; int numberOfTriangles; GetRenderingIndexValues(camera, out firstVertIndex, out lastVertIndex, out indexStart, out numberOfTriangles); if (numberOfTriangles != 0) { // Set graphics states FlatRedBallServices.GraphicsDevice.RasterizerState = RasterizerState.CullNone; FlatRedBall.Graphics.Renderer.BlendOperation = BlendOperation.Regular; Effect effectTouse = null; if (ZBuffered) { FlatRedBallServices.GraphicsDevice.DepthStencilState = DepthStencilState.Default; camera.SetDeviceViewAndProjection(mAlphaTestEffect, false); mAlphaTestEffect.World = Matrix.CreateScale(RenderingScale) * base.TransformationMatrix; mAlphaTestEffect.Texture = mTexture; effectTouse = mAlphaTestEffect; } else { camera.SetDeviceViewAndProjection(mBasicEffect, false); mBasicEffect.World = Matrix.CreateScale(RenderingScale) * base.TransformationMatrix; mBasicEffect.Texture = mTexture; effectTouse = mBasicEffect; } // We won't need to use any other kind of texture // address mode besides clamp, and clamp is required // on the "Reach" profile when the texture is not power // of two. Let's set it to clamp here so that we don't crash // on non-power-of-two textures. TextureAddressMode oldTextureAddressMode = Renderer.TextureAddressMode; Renderer.TextureAddressMode = TextureAddressMode.Clamp; foreach (EffectPass pass in effectTouse.CurrentTechnique.Passes) { // Start each pass pass.Apply(); // Right now this uses the (slower) DrawUserIndexedPrimitives // It could use DrawIndexedPrimitives instead for much faster performance, // but to do that we'd have to keep VB's around and make sure to re-create them // whenever the graphics device is lost. FlatRedBallServices.GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionTexture>( PrimitiveType.TriangleList, mVertices, firstVertIndex, // 0, lastVertIndex - firstVertIndex,// mVertices.Length, mIndices, indexStart, numberOfTriangles); } Renderer.TextureAddressMode = oldTextureAddressMode; if (ZBuffered) { FlatRedBallServices.GraphicsDevice.DepthStencilState = DepthStencilState.DepthRead; } } }
public void Draw(Camera camera) { ////////////////////Early Out/////////////////// if (!Visible) { return; } //////////////////End Early Out///////////////// Effect effectTouse = null; // Set graphics states FlatRedBallServices.GraphicsDevice.RasterizerState = RasterizerState.CullNone; if (ZBuffered) { FlatRedBallServices.GraphicsDevice.DepthStencilState = DepthStencilState.Default; camera.SetDeviceViewAndProjection(mAlphaTestEffect, false); mAlphaTestEffect.World = Matrix.CreateScale(RenderingScale) * base.TransformationMatrix; mAlphaTestEffect.Texture = mTexture; effectTouse = mAlphaTestEffect; } else { camera.SetDeviceViewAndProjection(mBasicEffect, false); mBasicEffect.World = Matrix.CreateScale(RenderingScale) * base.TransformationMatrix; mBasicEffect.Texture = mTexture; effectTouse = mBasicEffect; } // We won't need to use any other kind of texture // address mode besides clamp, and clamp is required // on the "Reach" profile when the texture is not power // of two. Let's set it to clamp here so that we don't crash // on non-power-of-two textures. TextureAddressMode oldTextureAddressMode = Renderer.TextureAddressMode; Renderer.TextureAddressMode = TextureAddressMode.Clamp; // Start the effect foreach (EffectPass pass in effectTouse.CurrentTechnique.Passes) { // Start each pass pass.Apply(); int indexStart = 0; int indexEndExclusive = mIndices.Length; int numberOfTriangles = (indexEndExclusive - indexStart) / 3; // Draw the shape FlatRedBallServices.GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionTexture>( PrimitiveType.TriangleList, mVertices, 0, mVertices.Length, mIndices, indexStart, numberOfTriangles); } Renderer.TextureAddressMode = oldTextureAddressMode; if (ZBuffered) { FlatRedBallServices.GraphicsDevice.DepthStencilState = DepthStencilState.DepthRead; } }
private Effect PrepareRenderingStates(Camera camera, out TextureAddressMode oldTextureAddressMode) { // Set graphics states FlatRedBallServices.GraphicsDevice.RasterizerState = RasterizerState.CullNone; FlatRedBall.Graphics.Renderer.BlendOperation = BlendOperation.Regular; Effect effectTouse = null; if (ZBuffered) { FlatRedBallServices.GraphicsDevice.DepthStencilState = DepthStencilState.Default; camera.SetDeviceViewAndProjection(mAlphaTestEffect, false); mAlphaTestEffect.World = Matrix.CreateScale(RenderingScale) * base.TransformationMatrix; mAlphaTestEffect.Texture = mTexture; effectTouse = mAlphaTestEffect; } else { camera.SetDeviceViewAndProjection(mBasicEffect, false); mBasicEffect.World = Matrix.CreateScale(RenderingScale) * base.TransformationMatrix; mBasicEffect.Texture = mTexture; effectTouse = mBasicEffect; } // We won't need to use any other kind of texture // address mode besides clamp, and clamp is required // on the "Reach" profile when the texture is not power // of two. Let's set it to clamp here so that we don't crash // on non-power-of-two textures. oldTextureAddressMode = Renderer.TextureAddressMode; Renderer.TextureAddressMode = TextureAddressMode.Clamp; return effectTouse; }