public void AddCommand(Shader shader, ShaderAction setup, Action <RenderState> cleanup, Matrix4 world, Lighting lt, RenderUserData user, VertexBuffer buffer, PrimitiveTypes primitive, int baseVertex, int start, int count, bool transparent, int layer, float z = 0) { if (transparent) { Transparents[transparentCommand++] = new RenderCommand() { Source = shader, ShaderSetup = setup, World = world, UserData = user, Cleanup = cleanup, Buffer = buffer, Lights = lt, Start = start, Count = count, Primitive = primitive, CmdType = RenderCmdType.Shader, SortLayer = transparent ? layer : SortLayers.OPAQUE, Z = z }; } else { throw new InvalidOperationException(); } }
//TODO: Implement MaterialAnim for asteroids public unsafe void AddCommandFade(RenderMaterial material, Matrix4 world, Lighting lights, VertexBuffer buffer, PrimitiveTypes primitive, int start, int count, int layer, Vector2 fadeParams, float z = 0) { Transparents[transparentCommand++] = new RenderCommand() { Source = material, MaterialAnim = null, Lights = lights, Buffer = buffer, Start = start, Count = count, Primitive = primitive, CmdType = RenderCmdType.MaterialFade, BaseVertex = *(int *)(&fadeParams.X), Index = *(int *)(&fadeParams.Y), World = world, SortLayer = layer, //Fade is always transparent Z = z }; }
public PhysicsDebugRenderer() { shader = Shaders.PhysicsDebug.Get(); linebuffer = new VertexBuffer(typeof(VertexPositionColor), MAX_LINES * 2, true); }
public void AddCommand(RenderMaterial material, MaterialAnim anim, Matrix4 world, Lighting lights, VertexBuffer buffer, PrimitiveTypes primitive, int baseVertex, int start, int count, int layer, float z = 0) { if (material.IsTransparent) { Transparents[transparentCommand++] = new RenderCommand() { Source = material, MaterialAnim = anim, Lights = lights, Buffer = buffer, BaseVertex = baseVertex, Start = start, Count = count, Primitive = primitive, CmdType = RenderCmdType.Material, World = world, SortLayer = layer, Z = z }; } else { material.MaterialAnim = anim; material.World = world; material.Use(rstate, buffer.VertexType, ref lights); buffer.Draw(primitive, baseVertex, start, count); if (material.DoubleSided) { material.FlipNormals = true; material.UpdateFlipNormals(); rstate.CullFace = CullFaces.Front; buffer.Draw(primitive, baseVertex, start, count); rstate.CullFace = CullFaces.Back; material.FlipNormals = false; } } }
//Code for baking an asteroid cube into a mesh void CreateBufferObject() { verts = new List <VertexPositionNormalDiffuseTexture>(); indices = new List <ushort>(); //Gather a list of all materials List <Material> mats = new List <Material>(); if (field.AllowMultipleMaterials) { foreach (var ast in field.Cube) { var f = (ModelFile)ast.Drawable.LoadFile(sys.ResourceManager); f.Initialize(sys.ResourceManager); var l0 = f.Levels[0]; for (int i = l0.StartMesh; i < l0.StartMesh + l0.MeshCount; i++) { var m = l0.Mesh.Meshes[i].Material; bool add = true; foreach (var mat in mats) { if (m.Name == mat.Name) { add = false; break; } } if (add) { mats.Add(m); } } } } else { var f = (ModelFile)field.Cube[0].Drawable.LoadFile(sys.ResourceManager); f.Initialize(sys.ResourceManager); var msh = f.Levels[0]; mats.Add(msh.Mesh.Meshes[msh.StartMesh].Material); } //Create the draw calls foreach (var mat in mats) { var start = indices.Count; foreach (var ast in field.Cube) { AddAsteroidToBuffer(ast, mat, mats.Count == 1); } var count = indices.Count - start; cubeDrawCalls.Add(new DrawCall() { Material = mat, StartIndex = start, Count = count }); } cube_vbo = new VertexBuffer(typeof(VertexPositionNormalDiffuseTexture), verts.Count); cube_ibo = new ElementBuffer(indices.Count); cube_ibo.SetData(indices.ToArray()); cube_vbo.SetData(verts.ToArray()); cube_vbo.SetElementBuffer(cube_ibo); verts = null; indices = null; }