示例#1
0
        /// <summary>
        /// opengl UI for Axis
        /// </summary>
        /// <param name="anchor"></param>
        /// <param name="margin"></param>
        /// <param name="size"></param>
        /// <param name="partCount">24 as default.</param>
        public UIAxis(
            System.Windows.Forms.AnchorStyles anchor, System.Windows.Forms.Padding margin,
            System.Drawing.Size size, int partCount = 24)
            : base(anchor, margin, size, -Math.Max(size.Width, size.Height), Math.Max(size.Width, size.Height))
        {
            var shaderCodes = new ShaderCode[2];

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

            map.Add("in_Position", Axis.strPosition);
            map.Add("in_Color", Axis.strColor);
            var axis     = new Axis(partCount, 0.5f);
            var renderer = new Renderer(axis, provider, map);

            renderer.ModelSize = axis.ModelSize;

            this.Renderer = renderer;
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static ObjVNFNode Create(ObjVNFMesh mesh)
        {
            var model = new ObjVNF(mesh);
            RenderMethodBuilder builder;
            {
                var vs       = new VertexShader(vertexCode);
                var fs       = new FragmentShader(fragmentCode);
                var provider = new ShaderArray(vs, fs);
                var map      = new AttributeMap();
                map.Add(inPosition, Teapot.strPosition);
                map.Add(inNormal, Teapot.strNormal);
                builder = new RenderMethodBuilder(provider, map);
            }
            var node = new ObjVNFNode(model, ObjVNF.strPosition, builder);

            node.ModelSize     = model.GetSize();
            node.WorldPosition = model.GetPosition();

            node.Initialize();

            return(node);
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        public CtrlButtonRenderer()
        {
            var model = new CtrlImageModel();
            var vs    = new VertexShader(vert, inPosition, inUV);
            var fs    = new FragmentShader(frag);
            var codes = new ShaderArray(vs, fs);
            var map   = new AttributeMap();

            map.Add(inPosition, CtrlImageModel.position);
            var methodBuilder = new RenderMethodBuilder(codes, map);

            this.RenderUnit = new ModernRenderUnit(model, methodBuilder);
        }
示例#4
0
        public static AxisNode Create()
        {
            // vertex buffer and index buffer.
            var model = new AxisModel();
            // vertex shader and fragment shader.
            var vs    = new VertexShader(vertexCode);
            var fs    = new FragmentShader(fragmentCode);
            var array = new ShaderArray(vs, fs);
            // which vertex buffer maps to which attribute in shader.
            var map = new AttributeMap();

            map.Add("inPosition", AxisModel.strPosition);
            map.Add("inColor", AxisModel.strColor);
            // build a render method.
            var builder = new RenderMethodBuilder(array, map, new LineWidthSwitch(3));
            // create node.
            var node = new AxisNode(model, builder);

            // initialize node.
            node.Initialize();

            return(node);
        }
示例#5
0
        /// <summary>
        /// Render propeller in modern opengl.
        /// </summary>
        /// <returns></returns>
        public static CubeNode Create()
        {
            var vs       = new VertexShader(vertexCode);
            var fs       = new FragmentShader(fragmentCode);
            var provider = new ShaderArray(vs, fs);
            var map      = new AttributeMap();

            map.Add(inPosition, CubeModel.strPosition);
            var builder = new RenderMethodBuilder(provider, map);
            var node    = new CubeNode(new CubeModel(), CubeModel.strPosition, builder);

            node.Initialize();

            return(node);
        }
示例#6
0
        /// <summary>
        /// Render propeller in modern opengl.
        /// </summary>
        /// <returns></returns>
        public static PLYRenderer Create()
        {
            var vertexShader   = new VertexShader(vertexCode, inPosition);
            var fragmentShader = new FragmentShader(fragmentCode);
            var provider       = new ShaderArray(vertexShader, fragmentShader);
            var map            = new AttributeMap();

            map.Add(inPosition, PLY.strPosition);
            //map.Add(inColor, PLY.strColor);
            var renderer = new PLYRenderer(new PLY(), provider, map);

            renderer.Initialize();

            return(renderer);
        }
        /// <summary>
        /// Render propeller in modern opengl.
        /// </summary>
        /// <returns></returns>
        public static DepthGroundNode Create()
        {
            RenderMethodBuilder shadowmapBuilder;
            {
                var vs       = new VertexShader(vertexCode);
                var provider = new ShaderArray(vs);
                var map      = new AttributeMap();
                map.Add(inPosition, GroundModel.strPosition);
                shadowmapBuilder = new RenderMethodBuilder(provider, map);
            }
            var node = new DepthGroundNode(new GroundModel(), GroundModel.strPosition, shadowmapBuilder);

            node.Initialize();

            return(node);
        }
示例#8
0
        /// <summary>
        /// Render a PLY model in modern opengl.
        /// </summary>
        /// <returns></returns>
        public static PLYNode Create()
        {
            var vs       = new VertexShader(vertexCode, inPosition);
            var fs       = new FragmentShader(fragmentCode);
            var provider = new ShaderArray(vs, fs);
            var map      = new AttributeMap();

            map.Add(inPosition, PLY.strPosition);
            //map.Add(inColor, PLY.strColor);
            var builder = new RenderUnitBuilder(provider, map);
            var node    = new PLYNode(new PLY(), PLY.strPosition, builder);

            node.Initialize();

            return(node);
        }
示例#9
0
        /// <summary>
        /// get a bounding box renderer.
        /// </summary>
        /// <param name="lengths">bounding box's length at x, y, z direction.</param>
        /// <returns></returns>
        public static BoundingBoxRenderer Create(vec3 lengths)
        {
            var model       = 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 AttributeMap();

            map.Add("in_Position", BoundingBoxModel.strPosition);
            var result = new BoundingBoxRenderer(model, shaderCodes, map, new PolygonModeState(PolygonMode.Line), new PolygonOffsetFillState());

            result.ModelSize = lengths;
            return(result);
        }
示例#10
0
        /// <summary>
        /// </summary>
        /// <returns></returns>
        public static PlaneNode Create()
        {
            RenderMethodBuilder renderBuilder;
            {
                var vs       = new VertexShader(vertexCode);
                var fs       = new FragmentShader(fragmentCode);
                var provider = new ShaderArray(vs, fs);
                var map      = new AttributeMap();
                map.Add(inPosition, GroundModel.strPosition);
                renderBuilder = new RenderMethodBuilder(provider, map);
            }
            var node = new PlaneNode(new GroundModel(), GroundModel.strPosition, renderBuilder);

            node.Initialize();

            return(node);
        }
示例#11
0
        /// <summary>
        /// Creates a <see cref="LightPositionNode"/> which displays and updates light's position.
        /// </summary>
        /// <param name="light"></param>
        /// <param name="initAngle"></param>
        /// <returns></returns>
        public static LightPositionNode Create(CSharpGL.LightBase light, float initAngle = 0)
        {
            var model    = new Sphere(0.3f, 2, 3);
            var vs       = new VertexShader(vertexCode);
            var fs       = new FragmentShader(fragmentCode);
            var provider = new ShaderArray(vs, fs);
            var map      = new AttributeMap();

            map.Add(inPosition, Sphere.strPosition);
            var builder = new RenderMethodBuilder(provider, map, new PolygonModeSwitch(PolygonMode.Line));
            var node    = new LightPositionNode(model, Sphere.strPosition, builder);

            node.Initialize();
            node.light         = light;
            node.RotationAngle = initAngle;

            return(node);
        }
        /// <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.GetShaderCodes(), map, positionNameInIBufferable, switches));
            }
            else
            {
                return(new OneIndexRenderer(model, PickingShaderHelper.GetShaderCodes(), map, positionNameInIBufferable, switches));
            }
        }