Esempio n. 1
0
        //private readonly IBufferSource model;

        /// <summary>
        /// Scene node that supports 'Color-Coded-Picking'.
        /// </summary>
        ///<param name="model">Only <see cref="DrawArraysCmd"/> and <see cref="DrawElementsCmd"/> are supported as <see cref="IDrawCommand"/>.</param>
        /// <param name="positionNameInIBufferSource">The 'in' variable name which represents position buffer vertex shader.</param>
        ///<param name="builders"></param>
        public PickableNode(IBufferSource model, string positionNameInIBufferSource, params RenderMethodBuilder[] builders)
            : base(model, builders)
        {
            var pickProgramProvider = PickingShaderHelper.GetPickingShaderProgramProvider();

            this.pickingRenderUnitBuilder = new IPickableRenderMethodBuilder(pickProgramProvider, positionNameInIBufferSource);
        }
        /// <summary>
        /// 支持"拾取"的渲染器
        /// </summary>
        /// <param name="model">一种渲染方式</param>
        /// <param name="renderProgramProvider">各种类型的shader代码</param>
        /// <param name="attributeMap">关联<paramref name="model"/>和<paramref name="shaderProgramProvider"/>中的属性</param>
        /// <param name="positionNameInVertexShader">vertex shader种描述顶点位置信息的in变量的名字</param>
        ///<param name="switches"></param>
        public PickableRenderer(IBufferable model, IShaderProgramProvider renderProgramProvider,
                                AttributeMap attributeMap, string positionNameInVertexShader,
                                params GLState[] switches)
        {
            this.PositionNameInVertexShader = positionNameInVertexShader;
            this.pickProgramProvider        = PickingShaderHelper.GetPickingShaderProgramProvider();

            this.DataSource            = model;
            this.renderProgramProvider = renderProgramProvider;
            this.attributeMap          = attributeMap;
            this.stateList.AddRange(switches);
        }
Esempio n. 3
0
        /// <summary>
        /// 根据<see cref="IndexBuffer"/>的具体类型获取一个<see cref="PickableRenderer"/>
        /// </summary>
        /// <param name="model"></param>
        /// <param name="attributeMap"></param>
        /// <param name="positionNameInIBufferable"></param>
        /// <param name="switches"></param>
        /// <returns></returns>
        public static InnerPickableRenderer GetRenderer(
            this IBufferable model,
            AttributeMap attributeMap,
            string positionNameInIBufferable,
            params GLState[] switches)
        {
            if (model == null || attributeMap == null || string.IsNullOrEmpty(positionNameInIBufferable))
            {
                throw new ArgumentNullException();
            }

            AttributeMap map = null;

            foreach (AttributeMap.NamePair item in attributeMap)
            {
                if (item.NameInIBufferable == positionNameInIBufferable)
                {
                    map = new AttributeMap();
                    map.Add(item.VarNameInShader, item.NameInIBufferable);
                    break;
                }
            }
            if (map == null)
            {
                throw new Exception(string.Format("No matching variable name in shader for [{0}]", positionNameInIBufferable));
            }

            if (model.UsesZeroIndexBuffer())
            {
                return(new ZeroIndexRenderer(model, PickingShaderHelper.GetPickingShaderProgramProvider(), map, positionNameInIBufferable, switches));
            }
            else
            {
                return(new OneIndexRenderer(model, PickingShaderHelper.GetPickingShaderProgramProvider(), map, positionNameInIBufferable, switches));
            }
        }