Exemple #1
0
        public static void DrawNow(Mesh mesh, Material.Material material, Matrix4 worldMatrix = default)
        {
            if (material == null)
            {
                material = AssetDatabase.GetAsset <Material.Material>("Resources/Materials/Fallback.mat");
            }

            if (worldMatrix == default)
            {
                worldMatrix = Matrix4.Identity;
            }

            if (worldMatrix != default)
            {
                material.Shader.SetUniform("u_World", worldMatrix);
            }

            UniformBuffers.BindAll(material.Shader.Handle);
            material.Bind();
            mesh.VertexArray.Bind();
            mesh.IndexBuffer.Bind();

            GL.DrawElements(PrimitiveType.Triangles, mesh.IndexBuffer.Length, DrawElementsType.UnsignedInt, 0);

            mesh.VertexArray.Unbind();
            mesh.IndexBuffer.Unbind();
            material.Unbind();
            UniformBuffers.UnbindAll();
        }
Exemple #2
0
        public static void DrawRequest(Mesh mesh, Material.Material material, Matrix4 worldMatrix = default)
        {
            if (mesh.IndexBuffer.Length == 0)
            {
                return;
            }

            if (worldMatrix == default)
            {
                worldMatrix = Matrix4.Identity;
            }

            if (World.GetInstance() != null && !World.GetInstance().WorldCamera.Frustum.Intersects(mesh.Bounds.Transform(worldMatrix.ExtractTranslation(), Vector3.One)))
            {
                ClippedCount++;
                return;
            }

            if (material == null)
            {
                material = AssetDatabase.GetAsset <Material.Material>("Resources/Materials/Fallback.mat");
            }

            if (drawQueue.Contains(material.Name))
            {
                var batch = (BatchDraw)drawQueue[material.Name];
                batch.draws.Add(new QueuedDraw()
                {
                    mesh        = mesh,
                    worldMatrix = worldMatrix
                });
            }
            else if (material.Shader.IsTransparent)
            {
                drawQueue.Add(material.Name, new BatchDraw()
                {
                    draws = new List <QueuedDraw>()
                    {
                        new QueuedDraw()
                        {
                            mesh        = mesh,
                            worldMatrix = worldMatrix
                        }
                    },
                    material = material,
                });
            }
            else
            {
                drawQueue.Insert(0, material.Name, new BatchDraw()
                {
                    draws = new List <QueuedDraw>()
                    {
                        new QueuedDraw()
                        {
                            mesh        = mesh,
                            worldMatrix = worldMatrix
                        }
                    },
                    material = material,
                });
            }
            DrawCalls = drawQueue.Count;
        }
Exemple #3
0
 public Skybox(Material.Material mat)
 {
     skyMesh = AssetDatabase.GetAsset <Mesh>("Resources/Models/SkySphere.obj");
     skyMat  = mat;
 }