public void RenderMesh(GraphicsDevice graphicsDevice) { graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, meshPart.NumVertices, meshPart.StartIndex, meshPart.PrimitiveCount); }
public void Draw(Microsoft.Xna.Framework.Graphics.GraphicsDevice gd) { gd.Vertices[0].SetSource(VertexBuffer, 0, TerrainVertex.SizeInBytes); gd.VertexDeclaration = new VertexDeclaration(gd, TerrainVertex.VertexElements); gd.Indices = IndexBuffer; gd.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, Vertices.Length, 0, PrimitiveCount); }
void IMesh.Render(GraphicsDevice Device) { Device.SetVertexBuffer(verticies); Device.Indices = indicies; Device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, verticies.VertexCount, 0, System.Math.Min(primitiveCount, 65535)); }
/// <summary> /// Render the terrain /// </summary> /// <param name="device"></param> /// <param name="world"></param> public override void Draw(GraphicsDevice device, WorldState world) { world._3D.ApplyCamera(Effect, this); //device.SamplerStates[0].AddressU = TextureAddressMode.Wrap; //device.SamplerStates[0].AddressV = TextureAddressMode.Wrap; device.SetVertexBuffer(VertexBuffer); device.Indices = IndexBuffer; //device.RasterizerState.CullMode = CullMode.None; foreach (var pass in Effect.CurrentTechnique.Passes) { pass.Apply(); device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, GeomLength, 0, NumPrimitives); } device.SetVertexBuffer(GrassVertexBuffer); //device.Indices = GrassIndexBuffer; foreach (var pass in Effect.CurrentTechnique.Passes) { pass.Apply(); device.DrawPrimitives(PrimitiveType.LineList, 0, GrassPrimitives); //device.DrawIndexedPrimitives(PrimitiveType.LineList, 0, 0, GrassPrimitives*2, 0, GrassPrimitives); }; }
public void Render(GraphicsDevice device, Camera cam) { if (!Transform.renderer.enabled) { return; } device.SetVertexBuffer(VertexBuffer); device.Indices = IndexBuffer; Effect e = Material.shader.effect; Material.shader.ApplyPreRenderSettings(Material, UseVertexColor); Material.SetBlendState(device); IEffectMatrices ems = e as IEffectMatrices; if (ems != null) { ems.World = Transform.world; ems.View = cam.view; ems.Projection = cam.projectionMatrix; } foreach (EffectPass pass in e.CurrentTechnique.Passes) { pass.Apply(); device.DrawIndexedPrimitives( PrimitiveType.TriangleList, 0, 0, VertexBuffer.VertexCount, 0, IndexBuffer.IndexCount / 3 ); } RenderStats.AddDrawCall(batches, VertexBuffer.VertexCount, IndexBuffer.IndexCount / 3); }
/// <summary> /// Draws the primitive to the screen. /// </summary> /// <param Name="device">GPU to draw with.</param> public virtual void Render(GraphicsDevice device) { lock (VertexLock) { #if MONOGAME_BUILD device.SamplerStates[0].Filter = TextureFilter.Point; device.SamplerStates[1].Filter = TextureFilter.Point; device.SamplerStates[2].Filter = TextureFilter.Point; device.SamplerStates[3].Filter = TextureFilter.Point; device.SamplerStates[4].Filter = TextureFilter.Point; #endif if (VertexBuffer == null) { return; } if (Vertices == null || VertexBuffer == null || Vertices.Length < 3 || VertexBuffer.IsDisposed || VertexBuffer.VertexCount < 3) { return; } device.SetVertexBuffer(VertexBuffer); if (IndexBuffer != null) { device.Indices = IndexBuffer; device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, VertexBuffer.VertexCount, 0, IndexBuffer.IndexCount / 3); } else { device.DrawPrimitives(PrimitiveType.TriangleList, 0, Vertices.Length/3); } } }
public void draw(GraphicsDevice graphics) { foreach (EffectPass pass in _shader.CurrentTechnique.Passes) { pass.Apply(); CGraphics.GPU.SetVertexBuffer(_vertexBuffer); graphics.DrawIndexedPrimitives(PrimitiveType.LineList, 0, 0, vertices.Length, 0, 1); } }
public override void DrawIndexed(PrimitiveType primType, int indexCount, int startIndex, int baseVertex) { XFG.PrimitiveType xnaPrim; int numPrims; ComputeXNADrawCall(primType, indexCount, out xnaPrim, out numPrims); _device.DrawIndexedPrimitives(xnaPrim, baseVertex, 0, indexCount, startIndex, numPrims); }
public void Draw(GraphicsDevice graphics, Matrix world, Matrix view, Matrix projection) { graphics.SetVertexBuffer(vertices); graphics.Indices = indices; skyEffect.Parameters["WVP"].SetValue(world * view * projection); skyEffect.CurrentTechnique.Passes[0].Apply(); graphics.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, number_of_vertices, 0, number_of_indices / 3); }
internal void Draw(Texture2D[] textures, GraphicsDevice device, BasicEffect effect, EffectPass pass) { effect.World = displayObject.WorldTransform; effect.Texture = textures[displayObject.TextureIndex]; device.SetVertexBuffer(vertexBuffer); device.Indices = indexBuffer; pass.Apply(); device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertices.Length, 0, indices.Length / 3); }
//Draw and Set Buffers public void Draw(GraphicsDevice GraphicsDevice) { //Set Vertex Buffer GraphicsDevice.SetVertexBuffer(vb); //Set Index Buffer GraphicsDevice.Indices = ib; //Draw Quad GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 4, 0, 2); }
/// <summary> /// Draws the Sphere /// </summary> /// <param name="device">Graphics device</param> /// <param name="camera">What camera to draw on</param> public void draw(GraphicsDevice device, Camera.CameraMatrices camera) { for (int i = 0; i < numB; i++) { device.VertexDeclaration = vDecl; device.Vertices[0].SetSource(vBuffer, 0, vertexPos.SizeInBytes); device.Indices = iBuffer[i]; device.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, 0, numV, 0, numI - 2); } }
public void DrawGeometry(GraphicsDevice gd) { if (GPUMode){ gd.VertexDeclaration = new VertexDeclaration(gd, MeshVertex.VertexElements); gd.Indices = GPUIndexBuffer; gd.Vertices[0].SetSource(GPUBlendVertexBuffer, 0, MeshVertex.SizeInBytes); gd.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, BlendVertexBuffer.Length, 0, NumPrimitives); }else{ gd.VertexDeclaration = new VertexDeclaration(gd, MeshVertex.VertexElements); gd.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, BlendVertexBuffer, 0, BlendVertexBuffer.Length, IndexBuffer, 0, NumPrimitives); } }
//----------------------------------------------------------------------- public void Draw(GraphicsDevice device) { if (indices.Length == 0) return; if (isDirty) Warm(device); device.SetVertexBuffer(vertexbuffer); device.Indices = indexbuffer; device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertices.Length, 0, indices.Length / 3); }
/// <summary> /// This renders the grid as constructed. /// </summary> public void Draw() { IGraphicsDeviceService igs = (IGraphicsDeviceService)game.Services.GetService(typeof(IGraphicsDeviceService)); graphicsDevice = igs.GraphicsDevice; int numVertices = (dimension + 1) * (dimension + 1); int numTriangles = 2 * dimension * dimension; graphicsDevice.VertexDeclaration = vertexDecl; graphicsDevice.Vertices[0].SetSource(vertexBuffer, 0, VertexPositionNormalTexture.SizeInBytes); graphicsDevice.Indices = indexBuffer; graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, numVertices, 0, numTriangles); }
//描画パスごとに呼び出す public void drawPass(GraphicsDevice inDevice) { inDevice.SetVertexBuffer(m_VertexBuffer); inDevice.Indices=m_IndexBuffer; inDevice.DrawIndexedPrimitives( PrimitiveType.TriangleList, 0, 0, m_Vertices.Length, 0, m_Indices.Length / 3 ); }
public void DrawSkybox(Matrix viewMatrix, Matrix projectionMatrix, Matrix camWorld, GraphicsDevice device) { device.SetVertexBuffer(vertices); device.Indices = indices; skyEffect.Parameters["WVP"].SetValue(camWorld * projectionMatrix * viewMatrix *Matrix.CreateScale(100)); skyEffect.CurrentTechnique.Passes[0].Apply(); device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, number_of_vertices, 0, number_of_indices / 3); }
/// <summary> /// Sends the triangle list to the graphics device. Here is where the actual drawing starts. /// </summary> /// <param name="start">Start index of vertices to draw. Not used except to compute the count of vertices to draw.</param> /// <param name="end">End index of vertices to draw. Not used except to compute the count of vertices to draw.</param> /// <param name="effect">The custom effect to apply to the geometry</param> /// <param name="texture">The texture to draw.</param> private void FlushVertexArray(int start, int end, Effect effect, Texture texture) { if (start == end) { return; } var vertexCount = end - start; _device.Indices = indexBuffer; // If the effect is not null, then apply each pass and render the geometry if (effect != null) { var passes = effect.CurrentTechnique.Passes; foreach (var pass in passes) { pass.Apply(); // Whatever happens in pass.Apply, make sure the texture being drawn // ends up in Textures[0]. _device.Textures[0] = texture; vertexBuffer.SetData(_vertexArray, start, vertexCount); _device.SetVertexBuffer(vertexBuffer); _device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, (vertexCount / 4) * 2); } } else { // If no custom effect is defined, then simply render. vertexBuffer.SetData(_vertexArray, start, vertexCount); _device.SetVertexBuffer(vertexBuffer); _device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, (vertexCount / 4) * 2); } _device.Indices = null; }
public void Draw() { IGraphicsDeviceService igs = (IGraphicsDeviceService)game.Services.GetService(typeof(IGraphicsDeviceService)); device = igs.GraphicsDevice; //XNA 3.1 // device.VertexDeclaration = vertexDecl; // device.Vertices[0].SetSource(vb, 0, VertexPositionNormalTexture.SizeInBytes); // XNA 4.0 // set vertex buffer and declaration device.SetVertexBuffer(vb); device.Indices = ib; device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, (dimension + 1) * (dimension + 1), 0, 2 * dimension * dimension); }
public override void ReconstructShading(GameTime deltaTime, Camera3D camera, Matrix view, Matrix projection, GraphicsDevice graphicsDevice) { // this pass uses the light accumulation texture and reconstruct the mesh's shading // our parameters were already filled in the first pass RenderEffect.SetCurrentTechnique(1); RenderEffect.SetMatrices(GlobalTransform, view, projection); // Apply the Render Effect RenderEffect.Apply(); graphicsDevice.SetVertexBuffer(m_MeshPart.VertexBuffer, m_MeshPart.VertexOffset); graphicsDevice.Indices = m_MeshPart.IndexBuffer; graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, m_MeshPart.NumVertices, m_MeshPart.StartIndex, m_MeshPart.PrimitiveCount); }
public override void RenderToGBuffer(Camera3D camera, GraphicsDevice graphicsDevice) { RenderEffect.SetCurrentTechnique(0); RenderEffect.SetMatrices(GlobalTransform, camera.View, camera.Projection); //our first pass is responsible for rendering into GBuffer RenderEffect.SetFarClip(camera.FarPlane); if (m_Parent.BoneMatrices != null) RenderEffect.SetBones(m_Parent.BoneMatrices); RenderEffect.Apply(); graphicsDevice.SetVertexBuffer(m_MeshPart.VertexBuffer, m_MeshPart.VertexOffset); graphicsDevice.Indices = m_MeshPart.IndexBuffer; // Draw indexed primitives for this sub mesh graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, m_MeshPart.NumVertices, m_MeshPart.StartIndex, m_MeshPart.PrimitiveCount); }
public void Draw(GameTime gameTime, SpriteBatch spriteBatch, GraphicsDevice graphicsDevice) { spriteBatch.Begin(); spriteBatch.Draw(ButtonFace, Position, Color.White); spriteBatch.End(); int numTriangles; CalcTriangleList(TriangleListPoints, TriangleListIndicies, out numTriangles); IndexBuffer.SetData<short>(TriangleListIndicies); graphicsDevice.Indices = IndexBuffer; VertexBuffer.SetData<VertexPositionColor>(TriangleListPoints, 0, TriangleListPoints.Length); graphicsDevice.SetVertexBuffer(VertexBuffer); BasicEffect.CurrentTechnique.Passes[0].Apply(); graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, numTriangles * 3, 0, numTriangles); }
// Summary: // Draws all of the ModelMeshPart objects in this mesh, using their current // Effect settings. public void Draw() { for (int i = 0; i < MeshParts.Count; i++) { var part = MeshParts[i]; var effect = part.Effect; if (part.PrimitiveCount > 0) { this.graphicsDevice.SetVertexBuffer(part.VertexBuffer); this.graphicsDevice.Indices = part.IndexBuffer; for (int j = 0; j < effect.CurrentTechnique.Passes.Count; j++) { effect.CurrentTechnique.Passes[j].Apply(); graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, part.VertexOffset, part.StartIndex, part.PrimitiveCount); } } } }
/// <summary> /// Render the terrain /// </summary> /// <param name="device"></param> /// <param name="world"></param> public override void Draw(GraphicsDevice device, WorldState world) { world._3D.ApplyCamera(Effect, this); device.SamplerStates[0].AddressU = TextureAddressMode.Wrap; device.SamplerStates[0].AddressV = TextureAddressMode.Wrap; device.VertexDeclaration = new VertexDeclaration(device, VertexPositionTexture.VertexElements); device.Vertices[0].SetSource(VertexBuffer, 0, VertexPositionTexture.SizeInBytes); device.Indices = IndexBuffer; device.RenderState.CullMode = CullMode.None; Effect.Begin(); foreach (var pass in Effect.CurrentTechnique.Passes) { pass.Begin(); device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, Geom.Length, 0, NumPrimitives); //device.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleFan, Geom, 0, 2); pass.End(); } Effect.End(); }
public void Draw() { IGraphicsDeviceService igs = (IGraphicsDeviceService)game.Services.GetService(typeof(IGraphicsDeviceService)); device = igs.GraphicsDevice; DepthStencilState dss = new DepthStencilState(); dss.DepthBufferEnable = true; dss.DepthBufferFunction = CompareFunction.LessEqual; dss.DepthBufferWriteEnable = true; RasterizerState rs = new RasterizerState(); rs.CullMode = CullMode.CullClockwiseFace; rs.FillMode = FillMode.Solid; device.RasterizerState = rs; device.DepthStencilState = dss; device.SetVertexBuffer(vb); device.Indices = ib; device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, (dimension + 1) * (dimension + 1), 0, 2 * dimension * dimension); }
public void Draw(Matrix World, Matrix View, Matrix Projection, GraphicsDevice graphics, BasicEffect efeito) { angulo += 0.01f; Matrix rotacaoEixoAngulo = Matrix.CreateFromAxisAngle(new Vector3(0, 1, 0), angulo); Matrix translacao = Matrix.CreateTranslation(new Vector3(-2, 0, 2)); //World, View, Projection efeito.World = rotacaoEixoAngulo * translacao; efeito.View = View; efeito.Projection = Projection; foreach (EffectPass pass in efeito.CurrentTechnique.Passes) { pass.Apply(); graphics.SetVertexBuffer(vertexBuffer); graphics.Indices = indexBuffer; graphics.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, 0, vertexes.Length, 0, indices.Length - 2); } }
/// <summary> /// Renders the bounding box for debugging purposes. /// </summary> /// <param name="box">The box to render.</param> /// <param name="graphicsDevice">The graphics device to use when rendering.</param> /// <param name="view">The current view matrix.</param> /// <param name="projection">The current projection matrix.</param> /// <param name="color">The color to use drawing the lines of the box.</param> public static void Render( BoundingBox box, GraphicsDevice graphicsDevice, Matrix view, Matrix projection, Color color) { if (effect == null) { effect = new BasicEffect(graphicsDevice); effect.VertexColorEnabled = true; effect.LightingEnabled = false; vertDecl = new VertexDeclaration(VertexPositionColor.VertexDeclaration.GetVertexElements()); } Vector3[] corners = box.GetCorners(); for (int i = 0; i < 8; i++) { verts[i].Position = corners[i]; verts[i].Color = color; } VertexBuffer vertexBuffer = new VertexBuffer(graphicsDevice, vertDecl, 8, BufferUsage.None); vertexBuffer.SetData(verts); IndexBuffer indexBuffer = new IndexBuffer(graphicsDevice, typeof(int), 24, BufferUsage.WriteOnly); indexBuffer.SetData(indices); effect.View = view; effect.Projection = projection; graphicsDevice.SetVertexBuffer(vertexBuffer); graphicsDevice.Indices = indexBuffer; effect.CurrentTechnique.Passes[0].Apply(); graphicsDevice.DrawIndexedPrimitives(PrimitiveType.LineList, 0, 0, vertexBuffer.VertexCount, 0, indexBuffer.IndexCount / 2); }
public virtual void Draw(float dt, GraphicsDevice device) { viewport = device.Viewport; if (Stage.ActiveStage.GetQB<ControlsQB>().CurrentMouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed && Stage.ActiveStage.GetQB<ControlsQB>().LastMouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Released && viewport.Bounds.Contains(new Point(Stage.ActiveStage.GetQB<ControlsQB>().CurrentMouseState.X, Stage.ActiveStage.GetQB<ControlsQB>().CurrentMouseState.Y)) && CanSelect()) Pick(); if (selectedActor != null) { device.RasterizerState = wireframeState; RModel model = selectedActor.modelInstance.model; Matrix[] transforms = new Matrix[model.Model.Bones.Count]; model.Model.CopyAbsoluteBoneTransformsTo(transforms); distFromActor = Vector3.Distance(CameraQB.WorldMatrix.Translation, selectedActor.PhysicsObject.Position); foreach (ModelMesh mesh in model.Model.Meshes) { foreach (ModelMeshPart meshPart in mesh.MeshParts) { editorEffect.CurrentTechnique = editorEffect.Techniques["Technique1"]; editorEffect.Parameters["World"].SetValue(transforms[mesh.ParentBone.Index] * Matrix.CreateScale(1.0f) * selectedActor.PhysicsObject.TransformMatrix); editorEffect.Parameters["View"].SetValue(CameraQB.ViewMatrix); editorEffect.Parameters["Projection"].SetValue(CameraQB.ProjectionMatrix); editorEffect.CurrentTechnique.Passes[0].Apply(); device.SetVertexBuffer(meshPart.VertexBuffer); device.Indices = meshPart.IndexBuffer; device.DrawIndexedPrimitives(PrimitiveType.TriangleList, meshPart.VertexOffset, 0, meshPart.NumVertices, meshPart.StartIndex, meshPart.PrimitiveCount); } } device.RasterizerState = normalState; } }
public void JustDraw(GraphicsDevice graphicsDevice) { graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 4, 0, 2); }
public void Draw(GraphicsDevice graphicsDevice) { graphicsDevice.SetVertexBuffer(this.vertexBuffer); graphicsDevice.Indices = this.indexBuffer; graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 4, 0, 2); }
/// <summary> /// This renders the grass chunk. /// </summary> public void Draw(Vector3 center, Camera camera) { IGraphicsDeviceService igs = (IGraphicsDeviceService)game.Services.GetService(typeof(IGraphicsDeviceService)); graphicsDevice = igs.GraphicsDevice; // Prepare the effect Matrix worldTransform = Matrix.CreateTranslation(center); quadTree.GrassShader.Parameters["world"].SetValue(worldTransform); quadTree.GrassShader.Parameters["view"].SetValue(camera.ViewMatrix); quadTree.GrassShader.Parameters["proj"].SetValue(camera.ProjMatrix); quadTree.GrassShader.Parameters["maxHeight"].SetValue(quadTree.Parameters.MaxHeight); quadTree.GrassShader.Parameters["textureSize"].SetValue(quadTree.HeightMap.Width); quadTree.GrassShader.Parameters["heightMap"].SetValue(quadTree.HeightMap); quadTree.GrassShader.Parameters["normalMap"].SetValue(quadTree.NormalMap); quadTree.GrassShader.Parameters["grassMap"].SetValue(quadTree.GrassTexture); quadTree.GrassShader.Parameters["terrainScale"].SetValue(quadTree.Parameters.TerrainScale); quadTree.GrassShader.Parameters["cameraPosition"].SetValue(camera.Position); quadTree.GrassShader.Parameters["timer"].SetValue(timer); quadTree.GrassShader.Parameters["startFadingInDistance"].SetValue(quadTree.Parameters.GrassStartFadingInDistance); quadTree.GrassShader.Parameters["stopFadingInDistance"].SetValue(quadTree.Parameters.GrassStopFadingInDistance); quadTree.GrassShader.Parameters["windStrength"].SetValue(quadTree.Parameters.WindStrength); quadTree.GrassShader.Parameters["windDirection"].SetValue(quadTree.Parameters.WindDirection); // Render it! int numVertices = dimension * dimension * 12; int numTriangles = dimension * dimension * 6; quadTree.GrassShader.CurrentTechnique = quadTree.GrassShader.Techniques["GrassDraw"]; quadTree.GrassShader.Begin(); graphicsDevice.VertexDeclaration = vertexDecl; graphicsDevice.Vertices[0].SetSource(vertexBuffer, 0, VertexPositionNormalTexture.SizeInBytes); graphicsDevice.Indices = indexBuffer; foreach (EffectPass pass in quadTree.GrassShader.CurrentTechnique.Passes) { pass.Begin(); graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, numVertices, 0, numTriangles); pass.End(); } quadTree.GrassShader.End(); }
/// <summary> /// Draw the wall. /// </summary> /// <param name="world">The world.</param> /// <param name="viewMatrix">The view matrix</param> /// <param name="projectionMatrix">The projection matrix</param> /// <param name="lightView">The light view.</param> /// <param name="shaderEffect">The shader effect.</param> /// <param name="graphicsDevice">The graphics device.</param> public void Draw(Matrix world, Matrix viewMatrix, Matrix projectionMatrix, Matrix lightView, Effect shaderEffect, GraphicsDevice graphicsDevice) { shaderEffect.Parameters["xWorldViewProjection"].SetValue(world * viewMatrix * projectionMatrix); shaderEffect.Parameters["xTexture"].SetValue(wallTexture); shaderEffect.Parameters["xWorld"].SetValue(world); shaderEffect.Parameters["xLightsWorldViewProjection"].SetValue(world * lightView); graphicsDevice.RasterizerState = RasterizerState.CullNone; graphicsDevice.BlendState = BlendState.Opaque; for (var s = 0; s < 3; ++s) { foreach (var pass in shaderEffect.CurrentTechnique.Passes) { pass.Apply(); graphicsDevice.SetVertexBuffer(vb); graphicsDevice.Indices = ib; graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, 0, 4, 0, 2); } } }
public void Draw(GameTime gameTime, GraphicsDevice graphicsDevice, Matrix world, Matrix view, Matrix projection) { List<VertexBuffer> vertices; List<IndexBuffer> indices; List<Model> models; GetRenderables(out vertices, out indices, out models); graphicsDevice.DepthStencilState = DepthStencilState.Default; for (int i = 0; i < vertices.Count; ++i) { Model model = models[i]; foreach (ModelMesh mesh in model.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.World = world; effect.View = view; effect.Projection = projection; effect.LightingEnabled = true; effect.EnableDefaultLighting(); effect.AmbientLightColor = new Vector3(0.2f, 0.2f, 0.2f); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); graphicsDevice.SetVertexBuffer(vertices[i]); graphicsDevice.Indices = indices[i]; int primitivesToRender = indices[i].IndexCount / 3; int startIndex = 0; while (primitivesToRender > _maxPrimitives) { graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertices[i].VertexCount, startIndex, _maxPrimitives); startIndex += _maxPrimitives * 3; primitivesToRender -= _maxPrimitives; } graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertices[i].VertexCount, startIndex, primitivesToRender); } } } } }
public void Draw(GraphicsDevice gd) { gd.Vertices[0].SetSource(VertexBuffer, 0, TerrainVertex.SizeInBytes); gd.VertexDeclaration = new VertexDeclaration(gd, TerrainVertex.VertexElements); gd.Indices = IndexBuffer; gd.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, Vertices.Length, 0, PrimitiveCount); }
private void RenderBatch(int offset, int batchSize) { GraphicsDevice.Textures[0] = spriteData[offset].texture; for (int i = 0; i < batchSize; i += 1) { /* FIXME: OPTIMIZATION POINT: This method * allocates like f**k right now! In general, * it's by far the slowest block of code in the * whole file, and needs fixing. * -flibit */ // Current sprite being calculated SpriteInfo info = spriteData[i + offset]; // Calculate initial sprite information Vector2 source = new Vector2( info.source.X, info.source.Y ); Vector2 destination = new Vector2( info.destination.X, info.destination.Y ); Vector2 sourceSize = new Vector2( Math.Max( info.source.Width, MathHelper.MachineEpsilonFloat ), Math.Max( info.source.Height, MathHelper.MachineEpsilonFloat ) ); Vector2 destinationSize = new Vector2( info.destination.Z, info.destination.W ); Vector2 origin = info.origin / sourceSize; // Calculations performed with inverse texture size Vector2 inverseTexSize = new Vector2( (1.0f / (float)spriteData[offset].texture.Width), (1.0f / (float)spriteData[offset].texture.Height) ); if ((info.effects & SpriteInfo.SourceInTexels) == SpriteInfo.SourceInTexels) { source *= inverseTexSize; sourceSize *= inverseTexSize; } else { origin *= inverseTexSize; } // Calculations done with texture size if ((info.effects & SpriteInfo.DestSizeInPixels) != SpriteInfo.DestSizeInPixels) { destinationSize.X *= spriteData[offset].texture.Width; destinationSize.Y *= spriteData[offset].texture.Height; } // Calculations performed with rotation Vector2 rotationMatrix1; Vector2 rotationMatrix2; if (!MathHelper.WithinEpsilon(info.rotation, 0.0f)) { float sin = (float)Math.Sin(info.rotation); float cos = (float)Math.Cos(info.rotation); rotationMatrix1.X = cos; rotationMatrix1.Y = sin; rotationMatrix2.X = -sin; rotationMatrix2.Y = cos; } else { rotationMatrix1.X = 1.0f; rotationMatrix1.Y = 0.0f; rotationMatrix2.X = 0.0f; rotationMatrix2.Y = 1.0f; } // Calculate vertices, finally. for (int j = 0; j < 4; j += 1) { Vector2 cornerOffset = ( SpriteInfo.CornerOffsets[j] - origin ) * destinationSize; Vector2 position = Vector2.Add( Vector2.Multiply( rotationMatrix2, cornerOffset.Y ), Vector2.Add( Vector2.Multiply( rotationMatrix1, cornerOffset.X ), destination ) ); var k = (i * 4) + j; vertexInfo[k].Position.X = position.X; vertexInfo[k].Position.Y = position.Y; vertexInfo[k].Position.Z = info.depth; vertexInfo[k].Color = info.color; vertexInfo[k].TextureCoordinate = Vector2.Add( Vector2.Multiply( SpriteInfo.CornerOffsets[j ^ (info.effects & 0x3)], sourceSize ), source ); } } vertexBuffer.SetData(vertexInfo, 0, batchSize * 4, SetDataOptions.None); if (customEffect != null) { foreach (EffectPass pass in customEffect.CurrentTechnique.Passes._passes) { pass.Apply(); GraphicsDevice.DrawIndexedPrimitives( PrimitiveType.TriangleList, 0, 0, batchSize * 4, 0, batchSize * 2 ); } } else { GraphicsDevice.DrawIndexedPrimitives( PrimitiveType.TriangleList, 0, 0, batchSize * 4, 0, batchSize * 2 ); } }
public void DrawGeometry(Microsoft.Xna.Framework.Graphics.GraphicsDevice device, Effect effect) { //Effect.CurrentTechnique = Effect.Techniques[0]; if (SkelBones == null) { ReloadSkeleton(); } effect.Parameters["SkelBindings"].SetValue(SkelBones); lock (Bindings) { foreach (var pass in effect.CurrentTechnique.Passes) { foreach (var binding in Bindings) { if (binding.Texture != null) { var tex = binding.Texture.Get(device); effect.Parameters["MeshTex"].SetValue(tex); } else { effect.Parameters["MeshTex"].SetValue((Texture2D)null); } pass.Apply(); binding.Mesh.Draw(device); } } } //skip drawing shadows if we're drawing id if (LightPositions == null || effect.CurrentTechnique == effect.Techniques[1]) { return; } if (ShadBuf == null) { var shadVerts = new ShadowVertex[] { new ShadowVertex(new Vector3(-1, 0, -1), 25), new ShadowVertex(new Vector3(-1, 0, 1), 25), new ShadowVertex(new Vector3(1, 0, 1), 25), new ShadowVertex(new Vector3(1, 0, -1), 25), new ShadowVertex(new Vector3(-1, 0, -1), 19), new ShadowVertex(new Vector3(-1, 0, 1), 19), new ShadowVertex(new Vector3(1, 0, 1), 19), new ShadowVertex(new Vector3(1, 0, -1), 19) }; for (int i = 0; i < shadVerts.Length; i++) { shadVerts[i].Position *= 1f; } int[] shadInd = new int[] { 2, 1, 0, 2, 0, 3, 6, 5, 4, 6, 4, 7 }; ShadBuf = new VertexBuffer(device, typeof(ShadowVertex), shadVerts.Length, BufferUsage.None); ShadBuf.SetData(shadVerts); ShadIBuf = new IndexBuffer(device, IndexElementSize.ThirtyTwoBits, shadInd.Length, BufferUsage.None); ShadIBuf.SetData(shadInd); } foreach (var light in LightPositions) { //effect.Parameters["FloorHeight"].SetValue((float)(Math.Floor(Position.Y/2.95)*2.95 + 0.05)); effect.Parameters["LightPosition"].SetValue(light); var oldTech = effect.CurrentTechnique; effect.CurrentTechnique = effect.Techniques[4]; effect.CurrentTechnique.Passes[0].Apply(); device.DepthStencilState = DepthStencilState.DepthRead; device.SetVertexBuffer(ShadBuf); device.Indices = ShadIBuf; device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 4); effect.CurrentTechnique = oldTech; device.DepthStencilState = DepthStencilState.Default; } DrawHeadObject(device, effect); }