Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="glNode"></param>
        /// <returns></returns>
        protected override GLSnippet FindSnippet(GLNode glNode)
        {
            Type      nodeType = glNode.SelfTypeCache;
            GLSnippet snippet  = null;

            dictionary.TryGetValue(nodeType, out snippet);

            return(snippet);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="glAction"></param>
        /// <param name="glNode"></param>
        public override void BeforeChildren(GLAction glAction, GLNode glNode)
        {
            var action = glAction as RenderAction;
            var node   = glNode as GLZeroIndexNode;

            Debug.Assert(action != null);
            Debug.Assert(node != null);

            action.Context.indexBuffer = node.GetIndexBuffer();
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="glAction"></param>
        /// <param name="glNode"></param>
        public override void BeforeChildren(GLAction glAction, GLNode glNode)
        {
            var action = glAction as RenderAction;
            var node   = glNode as GLProgramNode;

            Debug.Assert(action != null);
            Debug.Assert(node != null);

            action.Context.shaderProgram = node.GetShaderProgram();
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="glAction"></param>
        /// <param name="glNode"></param>
        public override void DoAction(GLAction glAction, GLNode glNode)
        {
            var action = glAction as RenderAction;
            var node   = glNode as GLVertexNode;

            Debug.Assert(action != null);
            Debug.Assert(node != null);

            VertexBuffer vertexAttributeBuffer = node.GetVertexAttributeBuffer();

            action.Context.vertexAttributeBuffers.Add(vertexAttributeBuffer);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="glAction"></param>
        /// <param name="glNode"></param>
        public override void BeforeChildren(GLAction glAction, GLNode glNode)
        {
            var action = glAction as RenderAction;
            var node   = glNode as GLStateNode;

            Debug.Assert(action != null);
            Debug.Assert(node != null);

            GLState state = node.GetState();

            action.Context.glStateList.Add(state);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Find the wanted <see cref="GLSnippet"/> according to specified <paramref name="glNode"/>.
        /// </summary>
        /// <param name="glNode"></param>
        /// <returns></returns>
        protected GLSnippet Find(GLNode glNode)
        {
            Type      nodeType = glNode.GetType();
            GLSnippet snippet  = null;
            var       dict     = this.Dictionary;

            if (!dict.TryGetValue(nodeType, out snippet))
            {
                snippet = GLSnippetHelper.CreateInstance(this, glNode);
                dict.Add(nodeType, snippet);
            }

            return(snippet);
        }
Ejemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="glAction"></param>
        /// <param name="glNode"></param>
        public override void DoAction(GLAction glAction, GLNode glNode)
        {
            var action = glAction as RenderAction;
            var node   = glNode as GLTriangleStripNode;

            Debug.Assert(action != null);
            Debug.Assert(node != null);

            if (action.Context.vertexArrayObject == null)
            {
                VertexArrayObject vao = node.GetVertexArrayObject(action.Context.indexBuffer, action.Context.vertexAttributeBuffers.ToArray());
                action.Context.vertexArrayObject = vao;
            }

            action.Context.Render();
        }
Ejemplo n.º 8
0
        private void Triverse(GLNode gLNode)
        {
            GLSnippet snippet = this.FindSnippet(gLNode);

            if (snippet != null)
            {
                snippet.BeforeChildren(this, gLNode);
            }

            foreach (var item in gLNode.Children)
            {
                this.Triverse(item);
            }

            if (snippet != null)
            {
                snippet.AfterChildren(this, gLNode);
            }
        }
Ejemplo n.º 9
0
        public static GLSnippet CreateInstance(GLAction someAction, GLNode glSomeNode)
        {
            Type actionType = someAction.ThisTypeCache;
            Type nodeType   = glSomeNode.ThisTypeCache;

            GLSnippet result = null;
            // NOTE: This forces GLSnippet's class name's pattern.
            string prefix  = actionType.Name.Substring(0, actionType.Name.Length - "Action".Length);
            string postfix = nodeType.Name.Substring("GL".Length, nodeType.Name.Length - "GL".Length - "Node".Length);

            try
            {
                Type type = Type.GetType(prefix + "_" + postfix);
                result = Activator.CreateInstance(type) as GLSnippet;
            }
            catch (Exception)
            {
            }

            return(result);
        }
Ejemplo n.º 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="glAction"></param>
        /// <param name="glNode"></param>
        public override void BeforeChildren(GLAction glAction, GLNode glNode)
        {
            var action = glAction as RenderAction;
            var node   = glNode as GLPositionColorNode;

            Debug.Assert(action != null);
            Debug.Assert(node != null);

            if (action.Context.vertexArrayObject == null)
            {
                VertexArrayObject vao = node.GetVertexArrayObject(action.Context.indexBuffer, action.Context.vertexAttributeBuffers.ToArray());
                action.Context.vertexArrayObject = vao;
            }

            if (action.Context.shaderProgram == null)
            {
                action.Context.shaderProgram = node.GetProgram();
            }

            action.Context.Render();
        }
Ejemplo n.º 11
0
 /// <summary>
 ///  a group of related OpenGL codes to specified <paramref name="glAction"/> and <paramref name="glNode"/>.
 /// </summary>
 /// <param name="glAction"></param>
 /// <param name="glNode"></param>
 public abstract void DoAction(GLAction glAction, GLNode glNode);
Ejemplo n.º 12
0
 /// <summary>
 ///  a group of related OpenGL codes to specified <paramref name="glAction"/> and <paramref name="glNode"/>.
 /// </summary>
 /// <param name="glAction"></param>
 /// <param name="glNode"></param>
 public virtual void AfterChildren(GLAction glAction, GLNode glNode)
 {
 }
Ejemplo n.º 13
0
 /// <summary>
 ///  a group of related OpenGL codes to specified <paramref name="glAction"/> and <paramref name="glNode"/>.
 /// </summary>
 /// <param name="glAction"></param>
 /// <param name="glNode"></param>
 public virtual void BeforeChildren(GLAction glAction, GLNode glNode)
 {
 }
Ejemplo n.º 14
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="glNode"></param>
 public void Apply(GLNode glNode)
 {
     this.appliedNode = glNode;
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Find the wanted <see cref="GLSnippet"/> according to specified <paramref name="glNode"/>.
 /// </summary>
 /// <param name="glNode"></param>
 /// <returns></returns>
 protected abstract GLSnippet FindSnippet(GLNode glNode);