Esempio n. 1
0
        public void ExecuteRenderQueue(RenderContext renderContext)
        {
            if (mRenderEntries.Count == 0)
            {
                return;
            }

            mRenderEntries.Sort(mEntryComparer);

            // Prime the previousEntry variable:
            RenderEntry    previousEntry = mRenderEntries[0];
            GraphicsDevice gd            = SharedResources.Game.GraphicsDevice;

            gd.BlendState        = previousEntry.Material.BlendState;
            gd.DepthStencilState = previousEntry.Material.DepthStencilState;
            gd.RasterizerState   = previousEntry.Material.RasterizerState;
            gd.SetVertexBuffer(previousEntry.DrawNode.VertexBuffer);
            gd.Indices = previousEntry.DrawNode.IndexBuffer;

            for (int i = 0; i < mRenderEntries.Count; ++i)
            {
                if (previousEntry.Material.BlendState != mRenderEntries[i].Material.BlendState)
                {
                    gd.BlendState = mRenderEntries[i].Material.BlendState;
                }

                if (previousEntry.Material.DepthStencilState != mRenderEntries[i].Material.DepthStencilState)
                {
                    gd.DepthStencilState = mRenderEntries[i].Material.DepthStencilState;
                }

                if (previousEntry.Material.RasterizerState != mRenderEntries[i].Material.RasterizerState)
                {
                    gd.RasterizerState = mRenderEntries[i].Material.RasterizerState;
                }

                if (previousEntry.DrawNode.VertexBuffer != mRenderEntries[i].DrawNode.VertexBuffer)
                {
                    gd.SetVertexBuffer(mRenderEntries[i].DrawNode.VertexBuffer);
                }

                if (previousEntry.DrawNode.IndexBuffer != mRenderEntries[i].DrawNode.IndexBuffer)
                {
                    gd.Indices = mRenderEntries[i].DrawNode.IndexBuffer;
                }

                mRenderEntries[i].DrawNode.Draw(renderContext, mRenderEntries[i].Material, mRenderEntries[i].Transform);
                previousEntry = mRenderEntries[i];
            }

            mRenderEntries.Clear();
            SharedResources.GraphicsDeviceReady = !SharedResources.GraphicsDeviceResetting;
        }
Esempio n. 2
0
        public void AcceptForRender(GeometryNode drawNode, EffectApplication material)
        {
            RenderEntry newEntry = new RenderEntry(drawNode, material);

            if (material.UseAlphaPass)
            {
                Vector3 homogeneousClipSpacePos = Vector3.Transform(Transform.Top.Translation, VisibilityFrustum.Matrix);
                newEntry.SceneDepth = -homogeneousClipSpacePos.Z; // Negate because we want to sort far-to-near.
            }
            newEntry.Transform = Transform.Top;

            mRenderEntries.Add(newEntry);
        }