Пример #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);
                }
            }
        }
Пример #2
0
        public void Render(ShaderProgram shader, Camera camera)
        {
            int indiceat = 0;

            Matrix4 cameraPerspective = camera.PerspectiveMatrix;

            cameraMatrix.Value = cameraPerspective;
            cameraMatrix.Update(shader);

            cameraPosition.Value = camera.Position;
            cameraPosition.Update(shader);

            numberOfLights.Value = Lights.Count;
            numberOfLights.Update(shader);

            for (int i = 0; i < Lights.Count; i++)
            {
                lightIntensity.Value = Lights[i].Data.Intensity;
                lightIntensity.Update(shader, i);

                lightColor.Value = Lights[i].Data.Color;
                lightColor.Update(shader, i);

                lightPosition.Value = Lights[i].Data.Position;
                lightPosition.Update(shader, i);

                lightAttenuation.Value = Lights[i].Data.Attenuation;
                lightAttenuation.Update(shader, i);

                lightAmbient.Value = Lights[i].Data.Ambient;
                lightAmbient.Update(shader, i);

                lightConeAngle.Value = Lights[i].Data.ConeAngle;
                lightConeAngle.Update(shader, i);

                lightConeDirection.Value = Lights[i].Data.ConeDirection;
                lightConeDirection.Update(shader, i);
            }

            foreach (Volume v in ObjectManager.Instance.Objects)
            {
                IHasMaterial vMat = v as IHasMaterial;
                if (vMat != null)
                {
                    var m = vMat.Material;

                    materialDiffuse.Value = m.DiffuseColor;
                    materialDiffuse.Update(shader);

                    materialDiffuseTexture.Value = m.DiffuseTexture;
                    materialDiffuseTexture.Update(shader);

                    materialSpecular.Value = m.SpecularColor;
                    materialSpecular.Update(shader);

                    materialSpecularExponent.Value = m.SpecularExponent;
                    materialSpecularExponent.Update(shader);
                }

                modelMatrix.Value = v.ModelMatrix;
                modelMatrix.Update(shader);

                GL.DrawElements(BeginMode.Triangles, v.IndiceCount, DrawElementsType.UnsignedInt, indiceat * sizeof(uint));
                indiceat += v.IndiceCount;
            }
        }