/// <summary>
        /// 根据<see cref="IndexBufferPtr"/>的具体类型获取一个<see cref="PickableRenderer"/>
        /// </summary>
        /// <param name="bufferable"></param>
        /// <param name="propertyNameMap"></param>
        /// <param name="positionNameInIBufferable"></param>
        /// <param name="switches"></param>
        /// <returns></returns>
        public static InnerPickableRenderer GetRenderer(
            this IBufferable bufferable,
            PropertyNameMap propertyNameMap,
            string positionNameInIBufferable,
            params GLSwitch[] switches)
        {
            if (bufferable == null || propertyNameMap == null || string.IsNullOrEmpty(positionNameInIBufferable))
            {
                throw new ArgumentNullException();
            }

            IndexBufferPtr indexBufferPtr = bufferable.GetIndex();

            if (indexBufferPtr is ZeroIndexBufferPtr)
            {
                return(new ZeroIndexRenderer(bufferable, PickingShaderHelper.GetShaderCodes(), propertyNameMap, positionNameInIBufferable, switches));
            }
            else if (indexBufferPtr is OneIndexBufferPtr)
            {
                return(new OneIndexRenderer(bufferable, PickingShaderHelper.GetShaderCodes(), propertyNameMap, positionNameInIBufferable, switches));
            }
            else
            {
                throw new NotImplementedException();
            }
        }
示例#2
0
        private static PropertyNameMap GetMap(BuildInSceneObject buildIn)
        {
            var map = new PropertyNameMap();

            switch (buildIn)
            {
            case BuildInSceneObject.Cube:
                map.Add("in_Position", Cube.strPosition);
                map.Add("in_Color", Cube.strColor);
                break;

            case BuildInSceneObject.Sphere:
                map.Add("in_Position", Sphere.strPosition);
                map.Add("in_Color", Sphere.strColor);
                break;

            case BuildInSceneObject.Ground:
                map.Add("in_Position", Ground.strPosition);
                map.Add("in_Color", Ground.strColor);
                break;

            case BuildInSceneObject.Axis:
                map.Add("in_Position", Axis.strPosition);
                map.Add("in_Color", Axis.strColor);
                break;

            default:
                throw new NotImplementedException();
            }

            return(map);
        }
示例#3
0
 /// <summary>
 /// 用glDrarArrays进行渲染。
 /// </summary>
 /// <param name="bufferable">一种渲染方式</param>
 /// <param name="shaderCodes">各种类型的shader代码</param>
 /// <param name="propertyNameMap">关联<see cref="PropertyBufferPtr"/>和<see cref="shaderCode"/>中的属性</param>
 /// <param name="positionNameInIBufferable">描述顶点位置信息的buffer的名字</param>
 ///<param name="switches"></param>
 internal ZeroIndexRenderer(IBufferable bufferable, ShaderCode[] shaderCodes,
                            PropertyNameMap propertyNameMap, string positionNameInIBufferable,
                            params GLSwitch[] switches)
     : base(bufferable, shaderCodes, propertyNameMap, positionNameInIBufferable, switches)
 {
     this.Name = this.GetType().Name;
 }
示例#4
0
        public GLText(
            System.Windows.Forms.AnchorStyles anchor, System.Windows.Forms.Padding margin,
            System.Drawing.Size size, int zNear, int zFar, FontResource fontResource = null, int maxCharCount = 100)
            : base(null, anchor, margin, size, zNear, zFar)
        {
            if (fontResource == null)
            {
                this.fontResource = FontResource.Default;
            }
            else
            {
                this.fontResource = fontResource;
            }

            this.Name = "GLText";
            var shaderCodes = new ShaderCode[2];

            shaderCodes[0] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
                                                @"Resources.GLText.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
                                                @"Resources.GLText.frag"), ShaderType.FragmentShader);
            var map = new PropertyNameMap();

            map.Add("position", "position");
            map.Add("uv", "uv");
            var      model    = new TextModel(maxCharCount);
            Renderer renderer = new Renderer(model, shaderCodes, map);

            this.model    = model;
            this.Renderer = renderer;
        }
示例#5
0
        /// <summary>
        /// </summary>
        /// <param name="bufferable">一种渲染方式</param>
        /// <param name="shaderCodes">各种类型的shader代码</param>
        /// <param name="propertyNameMap">关联<see cref="PropertyBufferPtr"/>和<see cref="shaderCode"/>中的属性</param>
        /// <param name="positionNameInIBufferable">描述顶点位置信息的buffer的名字</param>
        ///<param name="switches"></param>
        internal InnerPickableRenderer(IBufferable bufferable, ShaderCode[] shaderCodes,
                                       PropertyNameMap propertyNameMap, string positionNameInIBufferable,
                                       params GLSwitch[] switches)
            : base(bufferable, shaderCodes, propertyNameMap, switches)
        {
            this.positionNameInIBufferable = positionNameInIBufferable;

            {
                var polygonModeSwitch = new PolygonModeSwitch(PolygonModes.Filled);
                this.PolygonModeSwitch = polygonModeSwitch;
                this.switchList.Add(polygonModeSwitch);
            }
            {
                float min, max;
                OpenGL.LineWidthRange(out min, out max);
                var lineWidthSwitch = new LineWidthSwitch(max);
                this.LineWidthSwitch = lineWidthSwitch;
                this.switchList.Add(lineWidthSwitch);
            }
            {
                float min, max;
                OpenGL.PointSizeRange(out min, out max);
                var pointSizeSwitch = new PointSizeSwitch(max);
                this.PointSizeSwitch = pointSizeSwitch;
                this.switchList.Add(pointSizeSwitch);
            }
        }
示例#6
0
 /// <summary>
 /// Rendering something using GLSL shader and VBO(VAO).
 /// </summary>
 /// <param name="bufferable">model data that can be transfermed into OpenGL Buffer's pointer.</param>
 /// <param name="shaderCodes">All shader codes needed for this renderer.</param>
 /// <param name="propertyNameMap">Mapping relations between 'in' variables in vertex shader in <see cref="shaderCodes"/> and buffers in <see cref="bufferable"/>.</param>
 ///<param name="switches">OpenGL switches.</param>
 public Renderer(IBufferable bufferable, ShaderCode[] shaderCodes,
                 PropertyNameMap propertyNameMap, params GLSwitch[] switches)
 {
     this.bufferable      = bufferable;
     this.shaderCodes     = shaderCodes;
     this.propertyNameMap = propertyNameMap;
     this.switchList.AddRange(switches);
 }
示例#7
0
        /// <summary>
        /// 支持"拾取"的渲染器
        /// </summary>
        /// <param name="bufferable">一种渲染方式</param>
        /// <param name="shaderCodes">各种类型的shader代码</param>
        /// <param name="propertyNameMap">关联<paramref name="bufferable"/>和<paramref name="shaderCodes"/>中的属性</param>
        /// <param name="positionNameInIBufferable">描述顶点位置信息的buffer的名字</param>
        ///<param name="switches"></param>
        public PickableRenderer(IBufferable bufferable, ShaderCode[] shaderCodes,
                                PropertyNameMap propertyNameMap, string positionNameInIBufferable,
                                params GLSwitch[] switches)
            : base(bufferable, shaderCodes, propertyNameMap, switches)
        {
            var innerPickableRenderer = InnerPickableRendererFactory.GetRenderer(
                bufferable, propertyNameMap, positionNameInIBufferable);

            this.innerPickableRenderer = innerPickableRenderer;
        }
示例#8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="bufferable">一种渲染方式</param>
 /// <param name="shaderCodes">各种类型的shader代码</param>
 /// <param name="propertyNameMap">关联<see cref="VertexBufferPtr"/>和<see cref="ShaderCode"/>中的属性</param>
 /// <param name="positionNameInIBufferable">描述顶点位置信息的buffer的名字</param>
 ///<param name="switches"></param>
 public ModernRenderer(IBufferable bufferable, ShaderCode[] shaderCodes,
                       PropertyNameMap propertyNameMap, string positionNameInIBufferable,
                       params GLSwitch[] switches)
 {
     this.bufferable                = bufferable;
     this.shaderCode                = shaderCodes;
     this.propertyNameMap           = propertyNameMap;
     this.positionNameInIBufferable = positionNameInIBufferable;
     this.switchList.AddRange(switches);
 }
示例#9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="buildIn"></param>
        /// <param name="bindingObject"></param>
        public DefaultRendererComponent(BuildInSceneObject buildIn, SceneObject bindingObject = null)
            : base(bindingObject)
        {
            var shaderCodes = new ShaderCode[2];

            shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\BuildInSceneObject.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\BuildInSceneObject.frag"), ShaderType.FragmentShader);
            IBufferable     bufferable = GetModel(buildIn);
            PropertyNameMap map        = GetMap(buildIn);
            var             renderer   = new Renderer(bufferable, shaderCodes, map);

            renderer.Initialize();
            this.Renderer = renderer;
        }
示例#10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="buildIn"></param>
        /// <returns></returns>
        public static SceneObject GetBuildInSceneObject(BuildInSceneObject buildIn)
        {
            var shaderCodes = new ShaderCode[2];

            shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\BuildInSceneObject.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\BuildInSceneObject.frag"), ShaderType.FragmentShader);
            IBufferable     bufferable = GetModel(buildIn);
            PropertyNameMap map        = GetMap(buildIn);
            var             renderer   = new BuildInRenderer(bufferable, shaderCodes, map);

            renderer.Initialize();

            SceneObject obj = renderer.WrapToSceneObject();

            return(obj);
        }
示例#11
0
        public static AxisRenderer Create(int partCount = 24)
        {
            var shaderCodes = new ShaderCode[2];

            shaderCodes[0] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
                                                @"Resources.UIAxis.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
                                                @"Resources.UIAxis.frag"), ShaderType.FragmentShader);
            var map = new PropertyNameMap();

            map.Add("in_Position", Axis.strPosition);
            map.Add("in_Color", Axis.strColor);
            var model    = new Axis(partCount);
            var renderer = new AxisRenderer(model, shaderCodes, map, "position");

            return(renderer);
        }
示例#12
0
        public static PropertyNameMap Parse(XElement xElement)
        {
            if (xElement.Name != typeof(PropertyNameMap).Name)
            {
                throw new Exception();
            }

            PropertyNameMap result = new PropertyNameMap();

            foreach (var item in xElement.Elements(typeof(NamePair).Name))
            {
                var pair = NamePair.Parse(item);
                result.namesInShader.Add(pair.VarNameInShader);
                result.namesInIBufferable.Add(pair.nameInIBufferable);
            }

            return(result);
        }
示例#13
0
        public static TextureRenderer Create(string bitmapFilename = "")
        {
            var shaderCodes = new ShaderCode[2];

            shaderCodes[0] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
                                                @"Resources.SquareRenderer.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
                                                @"Resources.SquareRenderer.frag"), ShaderType.FragmentShader);
            var map = new PropertyNameMap();

            map.Add("in_Position", Square.strPosition);
            map.Add("in_TexCoord", Square.strTexCoord);
            var model    = new Square();
            var renderer = new TextureRenderer(model, shaderCodes, map, Square.strPosition);

            renderer.bitmapFilename = bitmapFilename;
            return(renderer);
        }
示例#14
0
        /// <summary>
        /// get a bounding box renderer.
        /// </summary>
        /// <param name="lengths">bounding box's length at x, y, z direction.</param>
        /// <param name="originalWorldPosition"></param>
        /// <returns></returns>
        public static BoundingBoxRenderer Create(vec3 lengths, vec3 originalWorldPosition = new vec3())
        {
            var bufferable  = new BoundingBoxModel(lengths);
            var shaderCodes = new ShaderCode[2];

            shaderCodes[0] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
                                                @"Resources\BoundingBox.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
                                                @"Resources\BoundingBox.frag"), ShaderType.FragmentShader);
            var map = new PropertyNameMap();

            map.Add("in_Position", BoundingBoxModel.strPosition);
            var result = new BoundingBoxRenderer(bufferable, shaderCodes, map, new PolygonModeSwitch(PolygonModes.Lines), new PolygonOffsetFillSwitch());

            result.halfLengths           = new vec4(lengths / 2, 1.0f);
            result.OriginalWorldPosition = originalWorldPosition;
            result.ModelMatrix           = glm.translate(mat4.identity(), originalWorldPosition);
            return(result);
        }
示例#15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="maxCharCount">Max char count to display for this label.
        /// Careful to set this value because greater <paramref name="maxCharCount"/> means more space ocupied in GPU nemory.</param>
        /// <param name="labelHeight">Label height(in pixels)</param>
        /// <param name="fontTexture">Use which font to render text?</param>
        public LabelRenderer(int maxCharCount = 64, int labelHeight = 32, IFontTexture fontTexture = null)
            : base(null, null, null, new BlendSwitch(BlendingSourceFactor.SourceAlpha, BlendingDestinationFactor.One))
        {
            GLSwitch blendSwitch = this.SwitchList.Find(x => x is BlendSwitch);

            if (blendSwitch == null)
            {
                throw new Exception();
            }
            this.blendSwitch = blendSwitch;

            if (fontTexture == null)
            {
                this.fontTexture = FontTexture.Default;
            }                                          // FontResource.Default; }
            else
            {
                this.fontTexture = fontTexture;
            }

            this.LabelHeight = labelHeight;

            var model = new TextModel(maxCharCount);

            this.bufferable = model;
            this.model      = model;

            var shaderCodes = new ShaderCode[2];

            shaderCodes[0] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
                                                @"Resources\Label.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
                                                @"Resources\Label.frag"), ShaderType.FragmentShader);
            this.shaderCodes = shaderCodes;

            var map = new PropertyNameMap();

            map.Add("in_Position", TextModel.strPosition);
            map.Add("in_UV", TextModel.strUV);
            this.propertyNameMap = map;
        }
示例#16
0
        /// <summary>
        /// opengl UI for Axis
        /// </summary>
        /// <param name="anchor"></param>
        /// <param name="margin"></param>
        /// <param name="size"></param>
        /// <param name="zNear"></param>
        /// <param name="zFar"></param>
        public GLAxis(
            System.Windows.Forms.AnchorStyles anchor, System.Windows.Forms.Padding margin,
            System.Drawing.Size size, int zNear, int zFar)
            : base(null, anchor, margin, size, zNear, zFar)
        {
            this.Name = "GLAxis";
            var shaderCodes = new ShaderCode[2];

            shaderCodes[0] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
                                                @"Resources.GLAxis.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
                                                @"Resources.GLAxis.frag"), ShaderType.FragmentShader);
            var map = new PropertyNameMap();

            map.Add("in_Position", "position");
            map.Add("in_Color", "color");
            //PickableRenderer renderer = (new Axis()).GetRenderer(shaderCodes, map, "position");
            PickableRenderer renderer = new PickableRenderer(new Axis(), shaderCodes, map, "position");

            this.Renderer = renderer;
        }
示例#17
0
 private AxisRenderer(IBufferable bufferable, ShaderCode[] shaderCodes,
                      PropertyNameMap propertyNameMap, string positionNameInIBufferable, params GLSwitch[] switches)
     : base(bufferable, shaderCodes, propertyNameMap, positionNameInIBufferable, switches)
 {
 }
示例#18
0
 /// <summary>
 /// Rendering something using GLSL shader and VBO(VAO).
 /// </summary>
 /// <param name="bufferable">model data that can be transfermed into OpenGL Buffer's pointer.</param>
 /// <param name="shaderCodes">All shader codes needed for this renderer.</param>
 /// <param name="propertyNameMap">Mapping relations between 'in' variables in vertex shader in <paramref name="shaderCodes"/> and buffers in <paramref name="bufferable"/>.</param>
 ///<param name="switches">OpenGL switches.</param>
 private BoundingBoxRenderer(IBufferable bufferable, ShaderCode[] shaderCodes,
                             PropertyNameMap propertyNameMap, params GLSwitch[] switches)
     : base(bufferable, shaderCodes, propertyNameMap, switches)
 {
     this.BoundingBoxColor = Color.White;
 }
示例#19
0
 public BuildInRenderer(IBufferable bufferable, ShaderCode[] shaderCodes,
                        PropertyNameMap propertyNameMap, params GLSwitch[] switches)
     : base(bufferable, shaderCodes, propertyNameMap, switches)
 {
     this.Name = bufferable.GetType().Name;
 }