Exemplo n.º 1
0
        /// <summary>
        /// Render all meshes we collected this frame sorted by techniques
        /// and materials. This method is about 3-5 times faster than just
        /// using Model's Mesh.Draw method (see commented out code there).
        /// The reason for that is that we require only very few state changes
        /// and render everthing down as fast as we can. The only optimization
        /// left would be to put vertices of several meshes together if they
        /// are static and use the same technique and material. But since
        /// meshes have WriteOnly vertex and index buffers, we can't do that
        /// without using a custom model format.
        /// </summary>
        public void Render()
        {
            // Make sure z buffer is on
            BaseGame.Device.RenderState.DepthBufferEnable      = true;
            BaseGame.Device.RenderState.DepthBufferWriteEnable = true;

            // We always use the normalMapping shader here.
            Effect effect = ShaderEffect.normalMapping.Effect;

            // Set general parameters for the shader
            ShaderEffect.normalMapping.SetParametersOptimizedGeneral();
            // Don't set vertex buffer again if it does not change this frame.
            // Clear these remember settings.
            lastVertexBufferSet = null;
            lastIndexBufferSet  = null;

            for (int listNum = 0; listNum < sortedMeshes.Count; listNum++)
            {
                MeshesPerMaterialPerTechniques list = sortedMeshes[listNum];

                if (list.NumberOfRenderMatrices > 0)
                {
                    list.Render(effect);
                }
            }
        }
        }         // Add(vertexBuffer, indexBuffer, part)

        #endregion

        #region Render
        /// <summary>
        /// Render all meshes we collected this frame sorted by techniques
        /// and materials. This method is about 3-5 times faster than just
        /// using Model's Mesh.Draw method (see commented out code there).
        /// The reason for that is that we require only very few state changes
        /// and render everthing down as fast as we can. The only optimization
        /// left would be to put vertices of several meshes together if they
        /// are static and use the same technique and material. But since
        /// meshes have WriteOnly vertex and index buffers, we can't do that
        /// without using a custom model format.
        /// </summary>
        public void Render()
        {
            // Copy over last frame's object to this frame
            for (int listNum = 0; listNum < sortedMeshes.Count; listNum++)
            {
                MeshesPerMaterialPerTechniques list = sortedMeshes[listNum];
                for (int meshNum = 0; meshNum < list.meshesPerMaterials.Count; meshNum++)
                {
                    MeshesPerMaterial list2 = list.meshesPerMaterials[meshNum];
                    for (int num = 0; num < list2.meshes.Count; num++)
                    {
                        RenderableMesh mesh = list2.meshes[num];
                        // Copy over last frame matrices for rendering now!
                        mesh.lastFrameRenderMatricesAndAlpha =
                            mesh.thisFrameRenderMatricesAndAlpha;
                        // Clear list for this frame
                        mesh.thisFrameRenderMatricesAndAlpha =
                            new List <MatrixAndAlpha>();
                    }     // for
                }         // for
            }             // for

            // Make sure z buffer is on for 3D content
            BaseGame.Device.RenderState.DepthBufferEnable      = true;
            BaseGame.Device.RenderState.DepthBufferWriteEnable = true;

            // We always use the normalMapping shader here.
            Effect effect = BaseGame.ParallaxShader.Effect;

            // Set general parameters for the shader
            BaseGame.ParallaxShader.SetParametersOptimizedGeneral();

            // Don't set vertex buffer again if it does not change this frame.
            // Clear these remember settings.
            lastVertexBufferSet = null;
            lastIndexBufferSet  = null;

            //obs: foreach (MeshesPerMaterialPerTechniques list in sortedMeshes)
            for (int listNum = 0; listNum < sortedMeshes.Count; listNum++)
            {
                MeshesPerMaterialPerTechniques list = sortedMeshes[listNum];

                if (list.NumberOfRenderMatrices > 0)
                {
                    list.Render(effect);
                }
            }     // for (listNum)
        }         // Render()