예제 #1
0
        /// <summary>
        /// Renders the mesh with either brush or pen. Both are permitted as well.
        /// If none are provided, an exception is thrown.
        /// </summary>
        /// <param name="mesh"></param>
        /// <param name="world"></param>
        /// <param name="view"></param>
        /// <param name="projection"></param>
        /// <param name="brush"></param>
        /// <param name="pen"></param>
        public virtual void DrawMesh(Mesh mesh, Matrix world, Matrix view, Matrix projection, Brush brush = null, Pen pen = null)
        {
            if (!_attached)
            {
                throw new NotSupportedException("RenderContext is not yet attached");
            }

            if (brush == null && pen == null)
            {
                throw new NotSupportedException("You must set either brush, pen or both. Setting none would result in nothing getting drawn.");
            }
            mesh.Attach();

            _effect.World      = world;
            _effect.View       = view;
            _effect.Projection = projection;

            if (brush != null)
            {
                GraphicsDevice.RasterizerState = _fillState;
                if (!brush.IsPrepared)
                {
                    brush.Prepare(this);
                }
                brush.Configure(_effect);

                foreach (var pass in _effect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    mesh.Draw();
                }
            }
            if (pen != null)
            {
                GraphicsDevice.RasterizerState = _wireFrameState;
                if (!pen.IsPrepared)
                {
                    pen.Prepare(this);
                }
                pen.Configure(_effect);

                foreach (var pass in _effect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    mesh.Draw();
                }
            }
            mesh.Detach();
            GraphicsDevice.RasterizerState = _fillState;
        }
예제 #2
0
        /// <summary>
        /// Renders the mesh with either brush or pen. Both are permitted as well.
        /// If none are provided, an exception is thrown.
        /// </summary>
        /// <param name="mesh"></param>
        /// <param name="world"></param>
        /// <param name="brush"></param>
        /// <param name="pen"></param>
        public void DrawMesh(Mesh mesh, Matrix world, Brush brush = null, Pen pen = null)
        {
            if (brush == null && pen == null)
            {
                throw new NotSupportedException("You must set either brush, pen or both. Setting none would result in nothing getting drawn.");
            }
            mesh.Attach();

            SetupCamera(world);
            if (brush != null)
            {
                RenderContext.GraphicsDevice.RasterizerState = _fillState;
                if (!brush.IsPrepared)
                {
                    brush.Prepare(RenderContext);
                }
                brush.Configure(_effect);

                foreach (var pass in _effect.CurrentTechnique.Passes)
                {
                    pass.Apply();

                    mesh.Draw();
                }
            }
            if (pen != null)
            {
                RenderContext.GraphicsDevice.RasterizerState = _wireFrameState;
                if (!pen.IsPrepared)
                {
                    pen.Prepare(RenderContext);
                }
                pen.Configure(_effect);

                foreach (var pass in _effect.CurrentTechnique.Passes)
                {
                    pass.Apply();

                    mesh.Draw();
                }
            }

            mesh.Detach();

            RenderContext.GraphicsDevice.RasterizerState = _fillState;
        }