Beispiel #1
0
        //public override void Draw(SceneGraph.Cameras.Camera camera = null)
        //{
        //    this.Draw(camera, RenderMode.Design);
        //}

        /// <summary>
        /// Renders the element.
        /// </summary>
        /// <param name="gl">The gl.</param>
        /// <param name="renderMode">The render mode.</param>
        public void MyRenderElement(SceneElement sceneElement, OpenGL gl, RenderMode renderMode, SharedStageInfo info)
        {
            //  If the element is disabled, we're done.
            if (sceneElement.IsEnabled == false)
            {
                return;
            }

            //  Push each effect.
            foreach (var effect in sceneElement.Effects)
            {
                if (effect.IsEnabled)
                {
                    effect.Push(gl, sceneElement);
                }
            }

            //  If the element can be bound, bind it.
            IBindable bindable = sceneElement as IBindable;// example: Light

            if (bindable != null)
            {
                bindable.Push(gl);
            }

            //  If the element has an object space, transform into it.
            IHasObjectSpace hasObjectSpace = sceneElement as IHasObjectSpace;// example: Polygon, quadric, Teapot

            if (hasObjectSpace != null)
            {
                hasObjectSpace.PushObjectSpace(gl);
            }

            //  Render self.
            {
                //  If the element has a material, push it.
                IHasMaterial hasMaterial = sceneElement as IHasMaterial;// example: Polygon, quadric, Teapot
                if (hasMaterial != null && hasMaterial.Material != null)
                {
                    hasMaterial.Material.Push(gl);
                }

                if (renderMode == RenderMode.HitTest)
                {
                    IColorCodedPicking picking = sceneElement as IColorCodedPicking;
                    info.RenderForPicking(picking, gl, renderMode);
                }
                else
                {
                    //  If the element can be rendered, render it.
                    IRenderable renderable = sceneElement as IRenderable;
                    if (renderable != null)
                    {
                        renderable.Render(gl, renderMode);
                    }
                }

                //  If the element has a material, pop it.
                if (hasMaterial != null && hasMaterial.Material != null)
                {
                    hasMaterial.Material.Pop(gl);
                }
            }

            //  If the element is volume bound and we are rendering volumes, render the volume.
            IVolumeBound volumeBound = null;

            if (RenderBoundingVolumes)
            {
                volumeBound = sceneElement as IVolumeBound;
                if (volumeBound != null)
                {
                    volumeBound.BoundingVolume.Render(gl, renderMode);
                }
            }

            //  Recurse through the children.
            foreach (var childElement in sceneElement.Children)
            {
                MyRenderElement(childElement, gl, renderMode, info);
            }

            //  If the element has an object space, transform out of it.
            if (hasObjectSpace != null)
            {
                hasObjectSpace.PopObjectSpace(gl);
            }

            //  If the element can be bound, bind it.
            if (bindable != null)
            {
                bindable.Pop(gl);
            }

            //  Pop each effect.
            for (int i = sceneElement.Effects.Count - 1; i >= 0; i--)
            {
                if (sceneElement.Effects[i].IsEnabled)
                {
                    sceneElement.Effects[i].Pop(gl, sceneElement);
                }
            }
        }