Kav/Renderer.cs

57 lines
2.1 KiB
C#
Raw Normal View History

2020-08-04 09:32:02 +00:00
using System.Collections.Generic;
using Microsoft.Xna.Framework.Graphics;
namespace Kav
{
2020-08-05 03:50:44 +00:00
public static class Renderer
2020-08-04 09:32:02 +00:00
{
2020-08-05 03:50:44 +00:00
public static void Render(GraphicsDevice graphicsDevice, Camera camera, IEnumerable<Model> models, IEnumerable<PointLight> pointLights)
2020-08-04 09:32:02 +00:00
{
var view = camera.View;
var projection = camera.Projection;
foreach (var model in models)
{
foreach (var modelMesh in model.Meshes)
{
foreach (var meshPart in modelMesh.MeshParts)
{
graphicsDevice.SetVertexBuffer(meshPart.VertexBuffer);
graphicsDevice.Indices = meshPart.IndexBuffer;
if (meshPart.Effect is TransformEffect transformEffect)
{
transformEffect.View = view;
transformEffect.Projection = projection;
}
if (meshPart.Effect is PointLightEffect pointLightEffect)
{
2020-08-05 03:50:44 +00:00
int i = 0;
foreach (var pointLight in pointLights)
2020-08-04 09:32:02 +00:00
{
2020-08-05 03:50:44 +00:00
pointLightEffect.PointLights[i] = pointLight;
i++;
2020-08-04 09:32:02 +00:00
}
}
foreach (var pass in meshPart.Effect.CurrentTechnique.Passes)
{
pass.Apply();
graphicsDevice.DrawIndexedPrimitives(
PrimitiveType.TriangleList,
0,
0,
meshPart.VertexBuffer.VertexCount,
0,
meshPart.Triangles.Length
);
}
}
}
}
}
}
}