/// <summary>
        /// Pushes the effect onto the specified parent element.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        /// <param name="parentElement">The parent element.</param>
        public override void Push(OpenGL gl, SceneElement parentElement)
        {
            //  Create a combined mask.
            AttributeMask attributeFlags = AttributeMask.None;

            attributeFlags &= accumBufferAttributes.AreAnyAttributesSet() ? accumBufferAttributes.AttributeFlags : AttributeMask.None;
            attributeFlags &= colorBufferAttributes.AreAnyAttributesSet() ? colorBufferAttributes.AttributeFlags : AttributeMask.None;
            attributeFlags &= currentAttributes.AreAnyAttributesSet() ? currentAttributes.AttributeFlags : AttributeMask.None;
            attributeFlags &= depthBufferAttributes.AreAnyAttributesSet() ? depthBufferAttributes.AttributeFlags : AttributeMask.None;
            attributeFlags &= enableAttributes.AreAnyAttributesSet() ? enableAttributes.AttributeFlags : AttributeMask.None;
            attributeFlags &= fogAttributes.AreAnyAttributesSet() ? fogAttributes.AttributeFlags : AttributeMask.None;
            attributeFlags &= lightingAttributes.AreAnyAttributesSet() ? lightingAttributes.AttributeFlags : AttributeMask.None;
            attributeFlags &= lineAttributes.AreAnyAttributesSet() ? lineAttributes.AttributeFlags : AttributeMask.None;
            attributeFlags &= pointAttributes.AreAnyAttributesSet() ? pointAttributes.AttributeFlags : AttributeMask.None;
            attributeFlags &= polygonAttributes.AreAnyAttributesSet() ? polygonAttributes.AttributeFlags : AttributeMask.None;
            attributeFlags &= evalAttributes.AreAnyAttributesSet() ? evalAttributes.AttributeFlags : AttributeMask.None;
            attributeFlags &= hintAttributes.AreAnyAttributesSet() ? hintAttributes.AttributeFlags : AttributeMask.None;
            attributeFlags &= listAttributes.AreAnyAttributesSet() ? listAttributes.AttributeFlags : AttributeMask.None;
            attributeFlags &= pixelModeAttributes.AreAnyAttributesSet() ? pixelModeAttributes.AttributeFlags : AttributeMask.None;
            attributeFlags &= polygonStippleAttributes.AreAnyAttributesSet() ? polygonStippleAttributes.AttributeFlags : AttributeMask.None;
            attributeFlags &= scissorAttributes.AreAnyAttributesSet() ? scissorAttributes.AttributeFlags : AttributeMask.None;
            attributeFlags &= stencilBufferAttributes.AreAnyAttributesSet() ? stencilBufferAttributes.AttributeFlags : AttributeMask.None;
            attributeFlags &= textureAttributes.AreAnyAttributesSet() ? textureAttributes.AttributeFlags : AttributeMask.None;
            attributeFlags &= transformAttributes.AreAnyAttributesSet() ? transformAttributes.AttributeFlags : AttributeMask.None;
            attributeFlags &= viewportAttributes.AreAnyAttributesSet() ? viewportAttributes.AttributeFlags : AttributeMask.None;

            //  Push the attribute stack.
            gl.PushAttrib((uint)attributeFlags);

            //  Set the attributes.
            accumBufferAttributes.SetAttributes(gl);
            colorBufferAttributes.SetAttributes(gl);
            currentAttributes.SetAttributes(gl);
            depthBufferAttributes.SetAttributes(gl);
            enableAttributes.SetAttributes(gl);
            fogAttributes.SetAttributes(gl);
            lightingAttributes.SetAttributes(gl);
            lineAttributes.SetAttributes(gl);
            pointAttributes.SetAttributes(gl);
            polygonAttributes.SetAttributes(gl);
            evalAttributes.SetAttributes(gl);
            hintAttributes.SetAttributes(gl);
            listAttributes.SetAttributes(gl);
            pixelModeAttributes.SetAttributes(gl);
            polygonStippleAttributes.SetAttributes(gl);
            scissorAttributes.SetAttributes(gl);
            stencilBufferAttributes.SetAttributes(gl);
            textureAttributes.SetAttributes(gl);
            transformAttributes.SetAttributes(gl);
            viewportAttributes.SetAttributes(gl);
        }
Esempio n. 2
0
        /// <summary>
        /// Removes the child scene element.
        /// </summary>
        /// <param name="child">The child scene element.</param>
        public void RemoveChild(SceneElement child)
        {
            //  If the child has OpenGL context which is not the current one, we must destroy it.
            if (child is IHasOpenGLContext)
            {
                if (((IHasOpenGLContext)child).CurrentOpenGLContext != TraverseToRootElement().ParentScene.OpenGL)
                {
                    ((IHasOpenGLContext)child).DestroyInContext(TraverseToRootElement().ParentScene.OpenGL);
                }
            }

            //  Throw an exception if the child is not a child of this element..
            if (child.Parent != this)
            {
                throw new Exception("Cannot remove the child element '" + child.Name +
                                    "' - it is not a child of '" + Name + "'.");
            }

            //  Remove the child.
            children.Remove(child);
            child.Parent = null;
        }
 /// <summary>
 /// Pops the effect off the specified parent element.
 /// </summary>
 /// <param name="gl">The OpenGL instance.</param>
 /// <param name="parentElement">The parent element.</param>
 public override void Pop(OpenGL gl, SceneElement parentElement)
 {
     //  Pop the attribute stack.
     gl.PopAttrib();
 }
Esempio n. 4
0
 /// <summary>
 /// Pushes the effect onto the specified parent element.
 /// </summary>
 /// <param name="gl">The OpenGL instance.</param>
 /// <param name="parentElement">The parent element.</param>
 public override void Push(OpenGL gl, SceneElement parentElement)
 {
     //  Use this shader object.
     gl.UseProgram(ProgramObject);
 }
Esempio n. 5
0
 /// <summary>
 /// Pops the effect off the specified parent element.
 /// </summary>
 /// <param name="gl">The OpenGL instance.</param>
 /// <param name="parentElement">The parent element.</param>
 public override void Pop(OpenGL gl, SceneElement parentElement)
 {
     //  Un-use this shader object.
     gl.UseProgram(0);
 }
Esempio n. 6
0
 /// <summary>
 /// Pops the effect off the specified parent element.
 /// </summary>
 /// <param name="gl">The OpenGL instance.</param>
 /// <param name="parentElement">The parent element.</param>
 public abstract void Pop(OpenGL gl, SceneElement parentElement);
 /// <summary>
 /// Pops the specified parent element.
 /// </summary>
 /// <param name="gl">The OpenGL instance.</param>
 /// <param name="parentElement">The parent element.</param>
 public override void Pop(OpenGL gl, SceneElement parentElement)
 {
     //  Pop the stack.
     gl.PopMatrix();
 }
Esempio n. 8
0
 /// <summary>
 /// Pushes the effect onto the specified parent element.
 /// </summary>
 /// <param name="gl">The OpenGL instance.</param>
 /// <param name="parentElement">The parent element.</param>
 public override void Push(OpenGL gl, SceneElement parentElement)
 {
 }
Esempio n. 9
0
        /// <summary>
        /// Renders the element.
        /// </summary>
        /// <param name="gl">The gl.</param>
        /// <param name="renderMode">The render mode.</param>
        public void RenderElement(SceneElement sceneElement, RenderMode renderMode)
        {
            //  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.
            if (sceneElement is IBindable)
            {
                ((IBindable)sceneElement).Bind(gl);
            }

            //  If the element has an object space, transform into it.
            if (sceneElement is IHasObjectSpace)
            {
                ((IHasObjectSpace)sceneElement).PushObjectSpace(gl);
            }

            //  If the element has a material, push it.
            if (sceneElement is IHasMaterial && ((IHasMaterial)sceneElement).Material != null)
            {
                ((IHasMaterial)sceneElement).Material.Push(gl);
            }

            //  If the element can be rendered, render it.
            if (sceneElement is IRenderable)
            {
                ((IRenderable)sceneElement).Render(gl, renderMode);
            }

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

            //  IF the element is volume bound and we are rendering volumes, render the volume.
            if (RenderBoundingVolumes && sceneElement is IVolumeBound)
            {
                ((IVolumeBound)sceneElement).BoundingVolume.Render(gl, renderMode);
            }

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

            //  If the element has an object space, transform out of it.
            if (sceneElement is IHasObjectSpace)
            {
                ((IHasObjectSpace)sceneElement).PopObjectSpace(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);
                }
            }
        }