/// <summary>
        /// Sets the aspect of the global render state associated with the specified bit.
        /// Consider using SetRenderStateByIndex if you have access to the index.</summary>
        /// <param name="renderStateBit">Render state bit to set</param>
        /// <param name="renderState">Current RenderState to commit to the graphics device driver layer</param>
        public void SetRenderState(int renderStateBit, RenderState renderState)
        {
            RenderStateSetHandler handler = TryGetHandler(renderStateBit);
            if (handler == null)
                return;

            handler(renderState, m_reset==false ? m_oldRenderState : null);
        }
Example #2
0
        /// <summary>
        /// Creates the render state object for this material, including finding and loading the
        /// diffuse texture, if any</summary>
        /// <returns>The render state representing this material</returns>
        public virtual RenderState CreateRenderState()
        {
            RenderState rs = new RenderState();
            rs.SolidColor = new Vec4F(1, 1, 1, 1);
            rs.WireframeColor = new Vec4F(1, 1, 1, 1);
            rs.RenderMode = RenderMode.Smooth | RenderMode.Lit | RenderMode.SolidColor | RenderMode.WireframeColor;

            rs.InheritState = ~(RenderMode.Alpha | RenderMode.DisableZBuffer | RenderMode.SolidColor);

            ParseBindingsForTexture(rs);

            return rs;
        }
Example #3
0
 /// <summary>
 /// Initializes this object from the given RenderState</summary>
 /// <param name="other">RenderState to copy</param>
 public void Init(RenderState other)
 {
     m_overrideChildState = other.m_overrideChildState;
     m_renderMode = other.m_renderMode;
     m_inheritState = other.m_inheritState;
     m_wireframeColor = other.m_wireframeColor;
     m_diffuseColor = other.m_diffuseColor;
     m_emissionColor = other.m_emissionColor;
     m_ambientColor = other.m_ambientColor;
     m_specularColor = other.m_specularColor;
     m_shininess = other.m_shininess;
     m_textureName = other.m_textureName;
     m_lineThickness = other.m_lineThickness;
 }
Example #4
0
File: Shader.cs Project: Joxx0r/ATF
        /// <summary>
        /// Creates RenderState for an object</summary>
        /// <returns>RenderState for object</returns>
        public RenderState CreateRenderState()
        {
            var rs = new RenderState
            {
                InheritState = ~(RenderMode.Alpha | RenderMode.DisableZBuffer | RenderMode.SolidColor),
                RenderMode = RenderMode.Smooth | RenderMode.Lit | RenderMode.SolidColor | RenderMode.WireframeColor,
                SolidColor = new Vec4F(1, 1, 1, 1),
                WireframeColor = new Vec4F(1, 1, 1, 1),

                AmbientColor = GetAttribute<Vec4F>(Schema.shaderType.ambientAttribute),
                DiffuseColor = GetAttribute<Vec4F>(Schema.shaderType.diffuseAttribute),
                Shininess = GetAttribute<float>(Schema.shaderType.shininessAttribute),
                SpecularColor = GetAttribute<Vec4F>(Schema.shaderType.specularAttribute)
            };

            ParseAttributesForTexture(rs);

            return rs;
        }
Example #5
0
File: Shader.cs Project: Joxx0r/ATF
        private void ParseAttributesForTexture(RenderState rs)
        {
            string texturePath = Uri.UnescapeDataString(GetAttribute<string>(Schema.shaderType.textureAttribute));

            if (texturePath.Equals(""))
                return;

            int texName = Global<TextureManager>.Instance.GetTextureName(texturePath);
            if (texName != -1)
            {
                rs.RenderMode |= RenderMode.Textured;
                rs.TextureName = texName;

                TextureInfo info = Global<TextureManager>.Instance.GetTextureInfo(texName);
                if (info.Components == 4)
                    rs.RenderMode |= RenderMode.Alpha;
            }

            return;
        }
Example #6
0
File: Shader.cs Project: Joxx0r/ATF
        private void ParseCustomAttributesForLightingInfo(RenderState rs)
        {
            IEnumerable attributes = CustomAttributes;
            
            if (attributes != null)
            {
                float[] alpha = null;

                foreach (DomNode attribute in attributes)
                {
                    string name = attribute.GetAttribute(Schema.customDataAttributeType.nameAttribute) as string;
                    if (name == "color")
                    {
                        float[] diffuse = new float[3];
                        PopulateCustomAttributeValueArray(
                            attribute.GetAttribute(Schema.customDataAttributeType.valueAttribute) as string, diffuse);
                        rs.SolidColor = new Vec4F(diffuse[0], diffuse[1], diffuse[2], 1.0f);
                    }
                    else if (name == "specularColor")
                    {
                        float[] specular = new float[3];
                        PopulateCustomAttributeValueArray(
                            attribute.GetAttribute(Schema.customDataAttributeType.valueAttribute) as string, specular);
                    }
                    else if (name == "transparency")
                    {
                        alpha = new float[3];
                        PopulateCustomAttributeValueArray(
                            attribute.GetAttribute(Schema.customDataAttributeType.valueAttribute) as string, alpha);
                    }
                }

                if (alpha != null)
                {
                    Vec4F color = new Vec4F(rs.SolidColor);
                    color[3] = alpha[0];
                    rs.SolidColor = color;
                    rs.RenderMode |= RenderMode.Alpha;
                }
            }
        }
Example #7
0
        /// <summary>
        /// Sets this RenderState to a combination of itself and the specified parent.
        /// The InheritState property of this RenderState and the OverrideChildState property of the parent
        /// are considered.</summary>
        /// <param name="parent">Parent RenderState to compose from</param>
        public virtual void ComposeFrom(RenderState parent)
        {
            RenderMode bitsFromChild =
                ((~parent.OverrideChildState & ~InheritState) | OverrideChildState) & RenderMode;

            RenderMode overrideFromParent = parent.OverrideChildState & ~OverrideChildState;
            RenderMode bitsFromParent = (overrideFromParent | InheritState) & parent.RenderMode;

            RenderMode = bitsFromChild | bitsFromParent;

            bool inheritSolidColor = ((overrideFromParent & RenderMode.SolidColor) != 0) ||
                                     ((InheritState & RenderMode.SolidColor) != 0);

            bool inheritWireColor = ((overrideFromParent & RenderMode.WireframeColor) != 0) ||
                                    ((InheritState & RenderMode.WireframeColor) != 0);

            bool inheritWireThickness = ((overrideFromParent & RenderMode.WireframeThickness) != 0) ||
                                        ((InheritState & RenderMode.WireframeThickness) != 0);

            bool parentIsTextured = ((parent.RenderMode & RenderMode.Textured) != 0);

            if (inheritSolidColor)
                SolidColor = parent.SolidColor;

            if (inheritSolidColor)
                SpecularColor = parent.SpecularColor;

            if (inheritWireColor)
                WireframeColor = parent.WireframeColor;

            if (inheritWireThickness)
                LineThickness = parent.LineThickness;

            if (parentIsTextured && (m_textureName == 0))
                m_textureName = parent.TextureName;
        }
 /// <summary>
 /// Applies the provided RenderState to the graphics driver.
 /// At exit, the state of the graphics device matches the parameters of the provided RenderState.</summary>
 /// <param name="renderState">The RenderState to set the graphics device state to</param>
 public void Commit(RenderState renderState)
 {
     renderState.CommitAllBitsToGuardian(this);
     m_oldRenderState.Init(renderState);
     m_reset = false;
 }
        /// <summary>
        /// Sets the aspect of the global render state associated with the specified bit.
        /// For performance reasons, this is better than SetRenderState().</summary>
        /// <param name="renderStateIndex">Zero-based render state index to set. Is equivalent
        /// to how many times the 1 is shifted left in the render state bit.</param>
        /// <param name="renderState">Current RenderState to commit to the graphics device driver layer</param>
        public void SetRenderStateByIndex(int renderStateIndex, RenderState renderState)
        {
            RenderStateSetHandler handler = m_renderStateSetters[renderStateIndex];
            if (handler == null)
                return;

            handler(renderState, m_reset == false ? m_oldRenderState : null);
        }
Example #10
0
File: Shader.cs Project: Joxx0r/ATF
        private void ParseBindingsForTexture(RenderState rs)
        {
            foreach (IBinding binding in Bindings)
            {
                if (binding.BindingType == "texture")
                {
                    DomNode textureObject = (DomNode)binding.Source;
                    ITexture texture = textureObject.As<ITexture>();

                    string texUri = texture.PathName;

                    int texName = Global<TextureManager>.Instance.GetTextureName(texUri);
                    
                    if (texName != -1)
                    {
                        rs.RenderMode |= RenderMode.Textured;
                        rs.TextureName = texName;

                        TextureInfo info = Global<TextureManager>.Instance.GetTextureInfo(texName);
                        if (info.Components == 4)
                            rs.RenderMode |= RenderMode.Alpha;
                    }

                    return;
                }
            }
        }
Example #11
0
        /// <summary>
        /// Custom pick rendering</summary>
        /// <param name="graphPath">The graph path</param>
        /// <param name="renderState">The render state</param>
        /// <param name="action">The render action</param>
        /// <param name="camera">The camera</param>
        public void PickDispatch(SceneNode[] graphPath, RenderState renderState, IRenderAction action, Camera camera)
        {
            action.RenderStateGuardian.Commit(renderState);

            // apply xform
            Gl.glPushMatrix();
            Util3D.glMultMatrixf(action.TopMatrix);
            RenderVertices(action);
            Gl.glPopMatrix();
        }
Example #12
0
 /// <summary>
 /// Pushes the specified RenderState onto the stack</summary>
 /// <param name="renderState">RenderState to push</param>
 public void Push(RenderState renderState)
 {
     m_contents.Add(renderState);
     ComputeComposedRenderState();
 }
Example #13
0
 /// <summary>
 /// Determines whether stack contains the specified RenderState</summary>
 /// <param name="renderState">Render state</param>
 /// <returns><c>True</c> iff stack contains the specified RenderState</returns>
 public bool Contains(RenderState renderState)
 {
     return m_contents.Contains(renderState);
 }
Example #14
0
        /// <summary>
        /// Renders the specified graph path</summary>
        /// <param name="graphPath">The graph path</param>
        /// <param name="renderState">The render state</param>
        /// <param name="action">The render action</param>
        /// <param name="camera">The camera</param>
        protected override void Render(SceneNode[] graphPath, RenderState renderState, IRenderAction action, Camera camera)
        {
            // apply xform
            Gl.glPushMatrix();
            Util3D.glMultMatrixf(action.TopMatrix);

            if (m_displayListId == 0)
            {
                RenderStats globalStats = Util3D.RenderStats;
                RenderStats ourStats = new RenderStats();
                Util3D.RenderStats = ourStats;

                m_displayListId = Gl.glGenLists(1);
                #if MEMORY_DEBUG
                lock(s_lock) NumDisplayListIds++;
                #endif
                Gl.glNewList(m_displayListId, Gl.GL_COMPILE);
                Render(action);
                Gl.glEndList();

                m_numPrimitives = ourStats.PrimCount;
                m_numVertices = ourStats.VertexCount;
                Util3D.RenderStats = globalStats;
            }

            Gl.glCallList(m_displayListId);

            Gl.glPopMatrix();
            Util3D.RenderStats.PrimCount += m_numPrimitives;
            Util3D.RenderStats.VertexCount += m_numVertices;
        }
Example #15
0
 /// <summary>
 /// Pushes the specified RenderState onto the stack</summary>
 public void Push(RenderState renderState)
 {
     m_contents.Add(renderState);
     ComputeComposedRenderState();
 }
Example #16
0
 /// <summary>
 /// Removes the specified RenderState from stack</summary>
 /// <param name="renderState">The RenderState to remove</param>
 public void Remove(RenderState renderState)
 {
     m_contents.Remove(renderState);
     ComputeComposedRenderState();
 }
Example #17
0
        /// <summary>
        /// Parses the bindings within this material to load the diffuse texture and set the
        /// RenderState. The diffuse texture is determined by the following preference:
        /// 1. A MaterialBinding whose type is "texture" and whose Tag is "diffuseTexture". See
        /// http://wiki.ship.scea.com/confluence/display/SCEEATGDOCS/Materials+in+.atgi.
        /// 2. The first binding whose type is "texture".</summary>
        /// <param name="rs">The RenderState object to be set for this material</param>
        private void ParseBindingsForTexture(RenderState rs)
        {
            IBinding bestMatch = null;
            foreach (IBinding binding in Bindings)
            {
                if (binding.BindingType == "texture")
                {
                    MaterialBinding matBinding = binding as MaterialBinding;
                    if (matBinding != null && matBinding.Tag == DiffuseTextureTag)
                    {
                        bestMatch = binding;
                        break;
                    }
                    else if (bestMatch == null)
                    {
                        bestMatch = binding;
                    }
                }
            }

            if (bestMatch != null)
            {
                DomNode textureObject = (DomNode)bestMatch.Source;
                ITexture texture = textureObject.As<ITexture>();

                int texId = Global<TextureManager>.Instance.GetTextureName(texture.PathName);

                if (texId != -1)
                {
                    rs.RenderMode |= RenderMode.Textured;
                    rs.TextureName = texId;

                    TextureInfo info = Global<TextureManager>.Instance.GetTextureInfo(texId);
                    if (info.Components == 4 &&
                        AlphaBlend)
                    {
                        rs.RenderMode |= RenderMode.Alpha;
                    }
                }
            }
        }
Example #18
0
 /// <summary>
 /// Removes the specified RenderState from stack</summary>
 /// <param name="renderState">The RenderState to remove</param>
 public void Remove(RenderState renderState)
 {
     m_contents.Remove(renderState);
     ComputeComposedRenderState();
 }
Example #19
0
 /// <summary>
 /// Determines whether stack contains the specified RenderState</summary>
 /// <param name="renderState">Render state</param>
 /// <returns><c>True</c> iff stack contains the specified RenderState</returns>
 public bool Contains(RenderState renderState)
 {
     return(m_contents.Contains(renderState));
 }
Example #20
0
 /// <summary>
 /// Applies the provided RenderState to the graphics driver.
 /// At exit, the state of the graphics device matches the parameters of the provided RenderState.</summary>
 /// <param name="renderState">The RenderState to set the graphics device state to</param>
 public void Commit(RenderState renderState)
 {
     renderState.CommitAllBitsToGuardian(this);
     m_oldRenderState.Init(renderState);
     m_reset = false;
 }
Example #21
0
 /// <summary>
 /// Constructor that copies another RenderState</summary>
 /// <param name="other">RenderState to copy</param>
 public RenderState(RenderState other)
 {
     Init(other);
 }
Example #22
0
 /// <summary>
 /// Constructor that copies another RenderState</summary>
 /// <param name="other">RenderState to copy</param>
 public RenderState(RenderState other)
 {
     Init(other);
 }
Example #23
0
File: Effect.cs Project: Joxx0r/ATF
        private void BindTexture(Uri relativeUri, RenderState rs)
        {
            Collada root = this.DomNode.GetRoot().As<Collada>();
            string fullPath = root.GetAbsolutePath(relativeUri);

            if (!System.IO.File.Exists(fullPath))
            {
                Outputs.WriteLine(OutputMessageType.Error, "Texture not found  " + fullPath);
                return;
            }

            // Load texture and set RenderState
            int texName = Global<TextureManager>.Instance.GetTextureName(fullPath);
            if (texName != -1)
            {
                rs.RenderMode |= RenderMode.Textured;
                rs.TextureName = texName;                
            }
        }