/// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="x">mouse position(Left Down is (0, 0)).</param>
        /// <param name="y">mouse position(Left Down is (0, 0)).</param>
        /// <param name="lastVertexId"></param>
        /// <param name="modernRenderer"></param>
        /// <returns></returns>
        internal override uint[] Search(RenderEventArgs arg,
            int x, int y,
            uint lastVertexId, ZeroIndexRenderer modernRenderer)
        {
            OneIndexBuffer buffer = Buffer.Create(IndexBufferElementType.UInt, 8, DrawMode.Lines, BufferUsage.StaticDraw);
            unsafe
            {
                var array = (uint*)buffer.MapBuffer(MapBufferAccess.WriteOnly);
                array[0] = lastVertexId - 0; array[1] = lastVertexId - 2;
                array[2] = lastVertexId - 2; array[3] = lastVertexId - 3;
                array[4] = lastVertexId - 3; array[5] = lastVertexId - 1;
                array[6] = lastVertexId - 1; array[7] = lastVertexId - 0;
                buffer.UnmapBuffer();
            }
            modernRenderer.Render4InnerPicking(arg, buffer);
            uint id = ColorCodedPicking.ReadStageVertexId(x, y);

            buffer.Dispose();
            if (id + 2 == lastVertexId)
            { return new uint[] { lastVertexId - 0, lastVertexId - 2, }; }
            else if (id + 3 == lastVertexId)
            { return new uint[] { lastVertexId - 2, lastVertexId - 3 }; }
            else if (id + 1 == lastVertexId)
            { return new uint[] { lastVertexId - 3, lastVertexId - 1, }; }
            else if (id + 0 == lastVertexId)
            { return new uint[] { lastVertexId - 1, lastVertexId - 0, }; }
            else
            { throw new Exception("This should not happen!"); }
        }
        internal override uint[] Search(RenderEventArgs arg,
            int x, int y, 
            uint lastVertexId, ZeroIndexRenderer modernRenderer)
        {
            OneIndexBufferPtr indexBufferPtr = null;
            using (var buffer = new OneIndexBuffer<uint>(DrawMode.Lines, BufferUsage.StaticDraw))
            {
                buffer.Alloc(8);
                unsafe
                {
                    var array = (uint*)buffer.Header.ToPointer();
                    array[0] = lastVertexId - 0; array[1] = lastVertexId - 2;
                    array[2] = lastVertexId - 2; array[3] = lastVertexId - 3;
                    array[4] = lastVertexId - 3; array[5] = lastVertexId - 1;
                    array[6] = lastVertexId - 1; array[7] = lastVertexId - 0;
                }

                indexBufferPtr = buffer.GetBufferPtr() as OneIndexBufferPtr;
            }

            modernRenderer.Render4InnerPicking(arg, indexBufferPtr);
            uint id = ColorCodedPicking.ReadPixel(x, y, arg.CanvasRect.Height);

            indexBufferPtr.Dispose();
            if (id + 2 == lastVertexId)
            { return new uint[] { lastVertexId - 0, lastVertexId - 2, }; }
            else if (id + 3 == lastVertexId)
            { return new uint[] { lastVertexId - 2, lastVertexId - 3 }; }
            else if (id + 1 == lastVertexId)
            { return new uint[] { lastVertexId - 3, lastVertexId - 1, }; }
            else if (id + 0 == lastVertexId)
            { return new uint[] { lastVertexId - 1, lastVertexId - 0, }; }
            else
            { throw new Exception("This should not happen!"); }
        }
        /// <summary>
        /// 在三角形图元中拾取指定位置的Point
        /// </summary>
        /// <param name="arg">渲染参数</param>
        /// <param name="x">mouse position(Left Down is (0, 0)).</param>
        /// <param name="y">mouse position(Left Down is (0, 0)).</param>
        /// <param name="lastVertexId">三角形图元的最后一个顶点</param>
        /// <param name="modernRenderer">目标Renderer</param>
        /// <returns></returns>
        internal override uint Search(RenderEventArgs arg,
            int x, int y,
            uint lastVertexId, ZeroIndexRenderer modernRenderer)
        {
            // 创建临时索引
            OneIndexBuffer buffer = Buffer.Create(IndexBufferElementType.UInt, 3, DrawMode.Points, BufferUsage.StaticDraw);
            unsafe
            {
                var array = (uint*)buffer.MapBuffer(MapBufferAccess.WriteOnly);
                array[0] = lastVertexId - 0;
                array[1] = lastVertexId - 1;
                array[2] = lastVertexId - 2;
                buffer.UnmapBuffer();
            }
            // 用临时索引渲染此三角形图元(仅渲染此三角形图元)
            modernRenderer.Render4InnerPicking(arg, buffer);
            // id是拾取到的Line的Last Vertex Id
            uint id = ColorCodedPicking.ReadStageVertexId(x, y);

            buffer.Dispose();

            // 对比临时索引,找到那个Line
            if (lastVertexId - 2 <= id && id <= lastVertexId - 0)
            { return id; }
            else
            { throw new Exception("This should not happen!"); }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="x">mouse position(Left Down is (0, 0)).</param>
        /// <param name="y">mouse position(Left Down is (0, 0)).</param>
        /// <param name="primitiveInfo"></param>
        /// <param name="modernRenderer"></param>
        /// <returns></returns>
        internal override uint[] Search(RenderEventArgs arg,
            int x, int y,
            RecognizedPrimitiveInfo primitiveInfo,
            OneIndexRenderer modernRenderer)
        {
            uint[] indexList = primitiveInfo.VertexIds;
            if (indexList.Length < 3) { throw new ArgumentException(); }

            OneIndexBuffer buffer = indexList.GenIndexBuffer(DrawMode.LineLoop, BufferUsage.StaticDraw);
            modernRenderer.Render4InnerPicking(arg, buffer);
            uint id = ColorCodedPicking.ReadStageVertexId(x, y);

            buffer.Dispose();

            if (id == indexList[0])
            { return new uint[] { indexList[indexList.Length - 1], id, }; }
            else
            {
                uint[] result = null;
                for (int i = 1; i < indexList.Length; i++)
                {
                    if (id == indexList[i])
                    {
                        result = new uint[] { indexList[i - 1], indexList[i], };
                        break;
                    }
                }

                if (result != null)
                { return result; }
                else
                { throw new Exception("This should not happen!"); }
            }
        }
Пример #5
0
        protected override void DoRender(RenderEventArgs arg)
        {
            DateTime now = DateTime.Now;
            const float speed = 1.0f;

            {
                float secondAngle = ((float)now.Second) / 60.0f * 360.0f * speed;
                this.RotationAngleDegree = secondAngle;
                OpenGL.LoadIdentity();
                this.LegacyTransform();

                secondLineWidthState.On();
                OpenGL.Begin(OpenGL.GL_LINES);
                for (int i = 0; i < secondPosition.Count; i++)
                {
                    vec3 color = secondColor[i];
                    OpenGL.Color3f(color.x, color.y, color.z);
                    vec3 position = secondPosition[i];
                    OpenGL.Vertex3f(position.x, position.y, position.z);
                }
                OpenGL.End();
                secondLineWidthState.Off();
            }
            {
                float minuteAngle = ((float)(now.Minute * 60 + now.Second)) / (60.0f * 60.0f) * 360.0f * speed;
                this.RotationAngleDegree = minuteAngle;
                OpenGL.LoadIdentity();
                this.LegacyTransform();

                minuteLineWidthState.On();
                OpenGL.Begin(OpenGL.GL_LINES);
                for (int i = 0; i < minutePosition.Count; i++)
                {
                    vec3 color = minuteColor[i];
                    OpenGL.Color3f(color.x, color.y, color.z);
                    vec3 position = minutePosition[i];
                    OpenGL.Vertex3f(position.x, position.y, position.z);
                }
                OpenGL.End();
                minuteLineWidthState.Off();
            }
            {
                float hourAngle = ((float)((now.Hour * 60 + now.Minute) * 60 + now.Second)) / (12.0f * 60.0f * 60.0f) * 360.0f * speed;
                this.RotationAngleDegree = hourAngle;
                OpenGL.LoadIdentity();
                this.LegacyTransform();

                hourLineWidthState.On();
                OpenGL.Begin(OpenGL.GL_LINES);
                for (int i = 0; i < hourPosition.Count; i++)
                {
                    vec3 color = hourColor[i];
                    OpenGL.Color3f(color.x, color.y, color.z);
                    vec3 position = hourPosition[i];
                    OpenGL.Vertex3f(position.x, position.y, position.z);
                }
                OpenGL.End();
                hourLineWidthState.Off();
            }
        }
        internal override uint Search(RenderEventArgs arg,
            int x, int y,
            uint lastVertexId, ZeroIndexRenderer modernRenderer)
        {
            OneIndexBufferPtr indexBufferPtr = null;
            using (var buffer = new OneIndexBuffer<uint>(DrawMode.Points, BufferUsage.StaticDraw))
            {
                buffer.Alloc(4);
                unsafe
                {
                    var array = (uint*)buffer.Header.ToPointer();
                    array[0] = lastVertexId - 0;
                    array[1] = lastVertexId - 1;
                    array[2] = lastVertexId - 2;
                    array[3] = lastVertexId - 3;
                }

                indexBufferPtr = buffer.GetBufferPtr() as OneIndexBufferPtr;
            }

            modernRenderer.Render4InnerPicking(arg, indexBufferPtr);
            uint id = ColorCodedPicking.ReadPixel(x, y, arg.CanvasRect.Height);

            indexBufferPtr.Dispose();
            if (lastVertexId - 3 <= id && id <= lastVertexId - 0)
            { return id; }
            else
            { throw new Exception("This should not happen!"); }
        }
Пример #7
0
        /// <summary>
        /// Color Coded Picking
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="rect">拾取范围</param>
        /// <param name="pickableElements">在哪些对象中执行拾取操作</param>
        /// <returns></returns>
        public static List<Tuple<Point, PickedGeometry>> Pick(
            RenderEventArgs arg,
            Rectangle rect,
            params PickableRenderer[] pickableElements)
        {
            var result = new List<Tuple<Point, PickedGeometry>>();
            if (pickableElements.Length == 0) { return result; }

            Render4Picking(arg, pickableElements);
            List<Tuple<Point, uint>> stageVertexIdList = ReadPixels(rect, arg.CanvasRect.Height);
            foreach (var tuple in stageVertexIdList)
            {
                int x = tuple.Item1.X;
                int y = tuple.Item1.Y;
                if (x < 0 || arg.CanvasRect.Width <= x || y < 0 || arg.CanvasRect.Height <= y) { continue; }

                uint stageVertexId = tuple.Item2;
                PickedGeometry pickedGeometry = PickGeometry(arg,
                    x, y, stageVertexId, pickableElements);
                if (pickedGeometry != null)
                {
                    result.Add(new Tuple<Point, PickedGeometry>(new Point(x, y), pickedGeometry));
                }
            }

            return result;
        }
Пример #8
0
        ///// <summary>
        ///// Maybe something is picked because depth buffer is valid.
        ///// </summary>
        ///// <param name="pickingRect"></param>
        ///// <returns></returns>
        //private static unsafe bool DepthBufferValid(Rectangle pickingRect)
        //{
        //    if (pickingRect.Width <= 0 || pickingRect.Height <= 0) { return false; }
        //    bool result = false;
        //    using (var codedColor = new UnmanagedArray<byte>(pickingRect.Width * pickingRect.Height))
        //    {
        //        OpenGL.ReadPixels(pickingRect.X, pickingRect.Y, pickingRect.Width, pickingRect.Height,
        //            OpenGL.GL_DEPTH_COMPONENT, OpenGL.GL_UNSIGNED_BYTE, codedColor.Header);
        //        var array = (byte*)codedColor.Header.ToPointer();
        //        for (int i = 0; i < codedColor.Length; i++)
        //        {
        //            if (array[i] < byte.MaxValue)
        //            {
        //                result = true;
        //                break;
        //            }
        //        }
        //    }
        //    return result;
        //}
        /// <summary>
        /// Render all <see cref="PickableRenderer"/>s for color-coded picking.
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        internal List<IPickable> Render4Picking(RenderEventArgs arg)
        {
            arg.UsingViewPort.On();

            // record clear color
            var originalClearColor = new float[4];
            OpenGL.GetFloat(GetTarget.ColorClearValue, originalClearColor);

            // white color means nothing picked.
            OpenGL.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
            OpenGL.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT | OpenGL.GL_STENCIL_BUFFER_BIT);

            // restore clear color
            OpenGL.glClearColor(originalClearColor[0], originalClearColor[1], originalClearColor[2], originalClearColor[3]);

            uint renderedVertexCount = 0;
            var pickedRendererList = new List<IPickable>();
            RenderPickableObject(this.rootObject, arg, ref renderedVertexCount, pickedRendererList);

            OpenGL.Flush();

            arg.UsingViewPort.Off();

            return pickedRendererList;
        }
        internal override uint[] Search(RenderEventArgs arg,
            int x, int y, 
            uint lastVertexId, ZeroIndexRenderer modernRenderer)
        {
            OneIndexBufferPtr indexBufferPtr = null;
            using (var buffer = new OneIndexBuffer<uint>(DrawMode.Lines, BufferUsage.StaticDraw))
            {
                buffer.Alloc(6);
                unsafe
                {
                    var array = (uint*)buffer.Header.ToPointer();
                    array[0] = lastVertexId - 2; array[1] = lastVertexId - 0;
                    array[2] = lastVertexId - 4; array[3] = lastVertexId - 2;
                    array[4] = lastVertexId - 0; array[5] = lastVertexId - 4;
                }

                indexBufferPtr = buffer.GetBufferPtr() as OneIndexBufferPtr;
            }

            modernRenderer.Render4InnerPicking(arg, indexBufferPtr);
            uint id = ColorCodedPicking.ReadPixel(x, y, arg.CanvasRect.Height);

            indexBufferPtr.Dispose();

            if (id + 4 == lastVertexId)
            { return new uint[] { id + 4, id, }; }
            else
            { return new uint[] { id - 2, id, }; }
        }
Пример #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        public void Render4Picking(RenderEventArgs arg)
        {
            InnerPickableRenderer renderer = this.innerPickableRenderer;
            if (renderer == null) { throw new Exception("InnerPickableRenderer is null!"); }

            renderer.Render4Picking(arg);
        }
        internal override uint Search(RenderEventArgs arg,
            int x, int y,
            RecognizedPrimitiveIndex lastIndexId,
            OneIndexRenderer modernRenderer)
        {
            List<uint> indexList = lastIndexId.IndexIdList;
            if (indexList.Count < 3) { throw new ArgumentException(); }

            OneIndexBufferPtr indexBufferPtr = null;
            using (var buffer = new OneIndexBuffer<uint>(DrawMode.Points, BufferUsage.StaticDraw))
            {
                buffer.Alloc(indexList.Count);
                unsafe
                {
                    var array = (uint*)buffer.Header.ToPointer();
                    for (int i = 0; i < indexList.Count; i++)
                    {
                        array[i] = indexList[i];
                    }
                }

                indexBufferPtr = buffer.GetBufferPtr() as OneIndexBufferPtr;
            }

            modernRenderer.Render4InnerPicking(arg, indexBufferPtr);
            uint id = ColorCodedPicking.ReadPixel(x, y, arg.CanvasRect.Height);

            indexBufferPtr.Dispose();

            if (id != uint.MaxValue)
            { return id; }
            else
            { throw new Exception("This should not happen!"); }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="x">mouse position(Left Down is (0, 0)).</param>
        /// <param name="y">mouse position(Left Down is (0, 0)).</param>
        /// <param name="primitiveInfo"></param>
        /// <param name="modernRenderer"></param>
        /// <returns></returns>
        internal override uint[] Search(RenderEventArgs arg,
            int x, int y,
            RecognizedPrimitiveInfo primitiveInfo,
            OneIndexRenderer modernRenderer)
        {
            uint[] indexList = primitiveInfo.VertexIds;
            if (indexList.Length != 3) { throw new ArgumentException(); }

            //if (indexList[0] == indexList[1]) { return new uint[] { indexList[0], indexList[2], }; }
            //else if (indexList[0] == indexList[2]) { return new uint[] { indexList[0], indexList[1], }; }
            //else if (indexList[1] == indexList[2]) { return new uint[] { indexList[1], indexList[0], }; }

            var targetIndexList = new uint[6] { indexList[0], indexList[1], indexList[1], indexList[2], indexList[2], indexList[0], };
            OneIndexBuffer buffer = targetIndexList.GenIndexBuffer(DrawMode.Lines, BufferUsage.StaticDraw);
            modernRenderer.Render4InnerPicking(arg, buffer);
            uint id = ColorCodedPicking.ReadStageVertexId(x, y);

            buffer.Dispose();

            if (id == indexList[1])
            { return new uint[] { indexList[0], indexList[1], }; }
            else if (id == indexList[2])
            { return new uint[] { indexList[1], indexList[2], }; }
            else if (id == indexList[0])
            { return new uint[] { indexList[2], indexList[0], }; }
            else
            { throw new Exception("This should not happen!"); }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        public void Render4Picking(RenderEventArgs arg)
        {
            if (!this.IsInitialized) { this.Initialize(); }

            UpdatePolygonMode(arg.PickingGeometryType);

            ShaderProgram program = this.Program;

            // 绑定shader
            program.Bind();
            program.SetUniform("pickingBaseId",
                 (int)this.PickingBaseId);
            UniformMat4 uniformmMVP4Picking = this.uniformmMVP4Picking;
            {
                mat4 projection = arg.Camera.GetProjectionMatrix();
                mat4 view = arg.Camera.GetViewMatrix();
                mat4 model = this.GetModelMatrix().Value;
                uniformmMVP4Picking.Value = projection * view * model;
            }
            uniformmMVP4Picking.SetUniform(program);

            PickingStateesOn();

            this.vertexArrayObject.Render(arg, program);

            PickingStateesOff();

            //if (mvpUpdated) { uniformmMVP4Picking.ResetUniform(program); }

            // 解绑shader
            program.Unbind();
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="stageVertexId"></param>
        /// <param name="x">mouse position(Left Down is (0, 0)).</param>
        /// <param name="y">mouse position(Left Down is (0, 0)).</param>
        /// <returns></returns>
        public override PickedGeometry GetPickedGeometry(RenderEventArgs arg, uint stageVertexId,
            int x, int y)
        {
            uint lastVertexId;
            if (!this.GetLastVertexIdOfPickedGeometry(stageVertexId, out lastVertexId))
            { return null; }

            PickingGeometryType geometryType = arg.PickingGeometryType;

            if (geometryType == PickingGeometryType.Point)
            {
                DrawMode mode = this.indexBuffer.Mode;
                PickingGeometryType typeOfMode = mode.ToGeometryType();
                if (typeOfMode == PickingGeometryType.Point)
                { return PickWhateverItIs(arg, stageVertexId, lastVertexId, mode, typeOfMode); }
                else if (typeOfMode == PickingGeometryType.Line)
                {
                    if (this.OnPrimitiveTest(lastVertexId, mode))
                    { return PickPoint(arg, stageVertexId, lastVertexId); }
                    else
                    { return null; }
                }
                else
                {
                    ZeroIndexPointSearcher searcher = GetPointSearcher(mode);
                    if (searcher != null)// point is from triangle, quad or polygon
                    { return SearchPoint(arg, stageVertexId, x, y, lastVertexId, searcher); }
                    else
                    { throw new Exception(string.Format("Lack of searcher for [{0}]", mode)); }
                }
            }
            else if (geometryType == PickingGeometryType.Line)
            {
                DrawMode mode = this.indexBuffer.Mode;
                PickingGeometryType typeOfMode = mode.ToGeometryType();
                if (geometryType == typeOfMode)
                { return PickWhateverItIs(arg, stageVertexId, lastVertexId, mode, typeOfMode); }
                else
                {
                    ZeroIndexLineSearcher searcher = GetLineSearcher(mode);
                    if (searcher != null)// line is from triangle, quad or polygon
                    { return SearchLine(arg, stageVertexId, x, y, lastVertexId, searcher); }
                    else if (mode == DrawMode.Points)// want a line when rendering GL_POINTS
                    { return null; }
                    else
                    { throw new Exception(string.Format("Lack of searcher for [{0}]", mode)); }
                }
            }
            else
            {
                DrawMode mode = this.indexBuffer.Mode;
                PickingGeometryType typeOfMode = mode.ToGeometryType();
                if (typeOfMode == geometryType)// I want what it is
                { return PickWhateverItIs(arg, stageVertexId, lastVertexId, mode, typeOfMode); }
                else
                { return null; }
                //{ throw new Exception(string.Format("Lack of searcher for [{0}]", mode)); }
            }
        }
Пример #15
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="arg"></param>
 protected override void DoRender(RenderEventArgs arg)
 {
     this.Layout();
     foreach (UIRenderer item in this.Children)
     {
         RenderUIRenderer(item, arg);
     }
 }
Пример #16
0
 public override void Render(RenderEventArgs arg)
 {
     UIRoot renderer = this.UIRoot;
     if (renderer != null)
     {
         renderer.Render(arg);
     }
 }
Пример #17
0
 ///// <summary>
 ///// Occurs before this object and all of its children's rendering.
 ///// </summary>
 //public event EventHandler BeforeRendering;
 ///// <summary>
 ///// Occurs before this object and all of its children's rendering.
 ///// </summary>
 //internal void DoBeforeRendering()
 //{
 //    EventHandler handler = this.BeforeRendering;
 //    if (handler != null)
 //    {
 //        handler(this, new EventArgs());
 //    }
 //}
 /// <summary>
 ///
 /// </summary>
 /// <param name="arg"></param>
 public void Render(RenderEventArgs arg)
 {
     RendererBase renderer = this.Renderer;
     if (renderer != null)
     {
         renderer.Render(arg);
     }
 }
Пример #18
0
        /// <summary>
        /// Render something.
        /// </summary>
        /// <param name="arg"></param>
        public void Render(RenderEventArgs arg)
        {
            if (this.Enabled)
            {
                if (!isInitialized) { Initialize(); }

                DoRender(arg);
            }
        }
Пример #19
0
 public void Render(RenderModes renderMode, Rectangle clientRectangle)
 {
     var arg = new RenderEventArgs(renderMode, clientRectangle, this.Camera);
     var list = this.ObjectList.ToArray();
     foreach (var item in list)
     {
         item.Render(arg);
     }
     this.UIRoot.Render(arg);
 }
Пример #20
0
        /// <summary>
        /// Color Coded Picking
        /// </summary>
        /// <param name="camera"></param>
        /// <param name="x">鼠标位置</param>
        /// <param name="y">鼠标位置</param>
        /// <param name="radius">以鼠标位置为中心,在半径为<paramref name="radius"/>的正方形范围内进行拾取</param>
        /// <param name="width">画布宽度</param>
        /// <param name="height">画布高度</param>
        /// <param name="pickableElements">在哪些对象中执行拾取操作</param>
        /// <returns></returns>
        public static List<Tuple<Point, PickedGeometry>> Pick(
            RenderEventArgs arg,
            int x, int y, int radius,
            params PickableRenderer[] pickableElements)
        {
            if (x < 0 || arg.CanvasRect.Width <= x || y < 0 || arg.CanvasRect.Height <= y) { return null; }

            Rectangle rect = new Rectangle(x - radius, y - radius, radius * 2, radius * 2);
            return Pick(arg, rect, pickableElements);
        }
Пример #21
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        protected override void DoRender(RenderEventArgs arg)
        {
            mat4 projection = this.GetOrthoProjection();
            mat4 view = glm.lookAt(new vec3(0, 0, 1), new vec3(0, 0, 0), new vec3(0, 1, 0));
            mat4 model = glm.scale(mat4.identity(), new vec3(this.Size.Width, this.Size.Height, 1));
            var renderer = this.Renderer as Renderer;
            renderer.SetUniform("mvp", projection * view * model);

            base.DoRender(arg);
        }
Пример #22
0
        protected override void DoRender(RenderEventArgs arg)
        {
            mat4 projection = arg.Camera.GetProjectionMat4();
            mat4 view = arg.Camera.GetViewMat4();

            Renderer boundingBox = this.BoundingBoxRenderer;
            if (boundingBox != null) { boundingBox.Render(arg); }

            Renderer renderer = this.ScientificRenderer;
            if (renderer != null) { renderer.Render(arg); }
        }
        protected override void DoRender(RenderEventArgs arg)
        {
            mat4 projection = this.GetOrthoProjection();
            mat4 view = glm.lookAt(new vec3(0, 0, 1), new vec3(0, 0, 0), new vec3(0, 1, 0));
            float length = this.Size.Height;
            mat4 model = glm.scale(mat4.identity(), new vec3(this.Size.Width - 1, this.Size.Height - 1, 1));// '-1' to make sure lines shows up.
            var renderer = this.Renderer as Renderer;
            renderer.SetUniform("mvp", projection * view * model);

            base.DoRender(arg);
        }
Пример #24
0
 public void Render(RenderEventArgs arg)
 {
     if (this.Enabled)
     {
         RendererComponent renderer = this.Renderer;
         if (renderer != null)
         {
             renderer.Render(arg);
         }
     }
 }
Пример #25
0
        protected override void DoRender(RenderEventArgs arg)
        {
            this.SetUniform("billboardCenter_worldspace", this.WorldPosition);
            int[] viewport = OpenGL.GetViewport();
            this.SetUniform("viewportSize", new vec2(viewport[2], viewport[3]));
            mat4 projection = arg.Camera.GetProjectionMat4();
            mat4 view = arg.Camera.GetViewMat4();
            this.SetUniform("projection", projection);
            this.SetUniform("view", view);

            base.DoRender(arg);
        }
Пример #26
0
        protected override void DoRender(RenderEventArgs arg)
        {
            this.SetUniform("projectionMatrix", arg.Camera.GetProjectionMatrix());
            this.SetUniform("viewMatrix", arg.Camera.GetViewMatrix());
            MarkableStruct<mat4> model = this.GetModelMatrix();
            if (this.modelTicks != model.UpdateTicks)
            {
                this.SetUniform("modelMatrix", model.Value);
                this.modelTicks = model.UpdateTicks;
            }

            base.DoRender(arg);
        }
Пример #27
0
 /// <summary>
 /// Render this bounding box.
 /// </summary>
 /// <param name="boundingBox"></param>
 /// <param name="color"></param>
 /// <param name="arg"></param>
 public static void Render(this IBoundingBox boundingBox, Color color, RenderEventArgs arg)
 {
     if (renderer == null)
     {
         var lengths = new vec3(1, 1, 1);
         renderer = BoundingBoxRenderer.Create(lengths);
         renderer.Initialize();
     }
     renderer.WorldPosition = boundingBox.MaxPosition / 2 + boundingBox.MinPosition / 2;
     renderer.Scale = boundingBox.MaxPosition - boundingBox.MinPosition;
     renderer.BoundingBoxColor = color;
     renderer.Render(arg);
 }
Пример #28
0
        protected override void DoRender(RenderEventArgs arg)
        {
            this.SetUniform("renderWireframe", false);
            base.DoRender(arg);

            polygonModeState.On();
            lineWidthState.On();
            // offsetState.On();
            this.SetUniform("renderWireframe", true);
            base.DoRender(arg);
            //offsetState.Off();
            lineWidthState.Off();
            polygonModeState.Off();
        }
Пример #29
0
 public override void Render(RenderEventArgs arg, ShaderProgram shaderProgram)
 {
     if (arg.RenderMode == RenderModes.ColorCodedPicking
         && arg.PickingGeometryType == GeometryType.Point
         && this.Mode.ToGeometryType() == GeometryType.Line)// picking point from a line
     {
         // this maybe render points that should not appear.
         // so need to select by another picking
         OpenGL.DrawArrays(DrawMode.Points, this.FirstVertex, this.VertexCount);
     }
     else
     {
         OpenGL.DrawArrays(this.Mode, this.FirstVertex, this.VertexCount);
     }
 }
Пример #30
0
        protected override void DoRender(RenderEventArgs arg)
        {
            OpenGL.LoadIdentity();
            this.LegacyTransform();

            OpenGL.Begin(DrawMode.Lines);
            for (int i = 0; i < markPosition.Count; i++)
            {
                vec3 color = markColor[i];
                OpenGL.Color3f(color.x, color.y, color.z);
                vec3 position = markPosition[i];
                OpenGL.Vertex3f(position.x, position.y, position.z);
            }
            OpenGL.End();
        }
Пример #31
0
        public override void RenderBeforeChildren(CSharpGL.RenderEventArgs arg)
        {
            if (!this.IsInitialized)
            {
                this.Initialize();
            }

            ICamera camera           = arg.CameraStack.Peek();
            mat4    projectionMatrix = camera.GetProjectionMatrix();
            mat4    viewMatrix       = camera.GetViewMatrix();
            mat4    modelMatrix      = this.GetModelMatrix();

            RenderMethod  method  = this.RenderUnit.Methods[0];
            ShaderProgram program = method.Program;

            program.SetUniform(mvpMatrix, projectionMatrix * viewMatrix * modelMatrix);
            program.SetUniform(skybox, this.texture);

            method.Render();
        }
Пример #32
0
 public override void RenderBeforeChildren(RenderEventArgs arg)
 {
 }
Пример #33
0
 protected override void DoRender(RenderEventArgs arg)
 {
     circleRenderer.Render(arg);
     markRenderer.Render(arg);
     pinRenderer.Render(arg);
 }
Пример #34
0
 /// <summary>
 /// 执行此VBO的渲染操作。
 /// <para>Render using this VBO.</para>
 /// </summary>
 /// <param name="arg"></param>
 public abstract void Render(RenderEventArgs arg);
Пример #35
0
        public override PickedGeometry GetPickedGeometry(RenderEventArgs arg, uint stageVertexId,
                                                         int x, int y)
        {
            uint lastVertexId;

            if (!this.GetLastVertexIdOfPickedGeometry(stageVertexId, out lastVertexId))
            {
                return(null);
            }

            // 找到 lastIndexId
            RecognizedPrimitiveInfo lastIndexId = this.GetLastIndexIdOfPickedGeometry(
                arg, lastVertexId, x, y);

            if (lastIndexId == null)
            {
                Debug.WriteLine(string.Format(
                                    "Got lastVertexId[{0}] but no lastIndexId! Params are [{1}] [{2}] [{3}] [{4}]",
                                    lastVertexId, arg, stageVertexId, x, y));
                { return(null); }
            }

            GeometryType geometryType = arg.PickingGeometryType;
            DrawMode     mode         = this.indexBufferPtr.Mode;
            GeometryType typeOfMode   = mode.ToGeometryType();

            if (geometryType == GeometryType.Point)
            {
                // 获取pickedGeometry
                if (typeOfMode == GeometryType.Point)
                {
                    return(PickWhateverItIs(stageVertexId, lastIndexId, typeOfMode));
                }
                else if (typeOfMode == GeometryType.Line)
                {
                    if (this.OnPrimitiveTest(lastVertexId, mode))
                    {
                        return(PickPoint(stageVertexId, lastVertexId));
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    OneIndexPointSearcher searcher = GetPointSearcher(mode);
                    if (searcher != null)// line is from triangle, quad or polygon
                    {
                        return(SearchPoint(arg, stageVertexId, x, y, lastVertexId, lastIndexId, searcher));
                    }
                    else
                    {
                        throw new Exception(string.Format("Lack of searcher for [{0}]", mode));
                    }
                }
            }
            else if (geometryType == GeometryType.Line)
            {
                // 获取pickedGeometry
                if (geometryType == typeOfMode)
                {
                    return(PickWhateverItIs(stageVertexId, lastIndexId, typeOfMode));
                }
                else
                {
                    OneIndexLineSearcher searcher = GetLineSearcher(mode);
                    if (searcher != null)// line is from triangle, quad or polygon
                    {
                        return(SearchLine(arg, stageVertexId, x, y, lastVertexId, lastIndexId, searcher));
                    }
                    else if (mode == DrawMode.Points)// want a line when rendering GL_POINTS
                    {
                        return(null);
                    }
                    else
                    {
                        throw new Exception(string.Format("Lack of searcher for [{0}]", mode));
                    }
                }
            }
            else
            {
                if (typeOfMode == geometryType)// I want what it is
                {
                    return(PickWhateverItIs(stageVertexId, lastIndexId, typeOfMode));
                }
                else
                {
                    return(null);
                }
                //{ throw new Exception(string.Format("Lack of searcher for [{0}]", mode)); }
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="arg"></param>
 /// <param name="stageVertexId"></param>
 /// <param name="x">mouse position(Left Down is (0, 0)).</param>
 /// <param name="y">mouse position(Left Down is (0, 0)).</param>
 /// <returns></returns>
 public abstract PickedGeometry GetPickedGeometry(
     RenderEventArgs arg,
     uint stageVertexId,
     int x, int y);
Пример #37
0
 internal abstract uint[] Search(RenderEventArgs arg,
                                 int x, int y,
                                 uint lastVertexId, ZeroIndexRenderer modernRenderer);
Пример #38
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        public override void Render(RenderEventArgs arg)
        {
            int primCount = this.PrimCount;

            if (primCount < 1)
            {
                throw new Exception("error: primCount is less than 1.");
            }

            uint   mode = 0;
            IntPtr offset;

            if (arg.PickingGeometryType == PickingGeometryType.Point &&
                this.Mode.ToGeometryType() == PickingGeometryType.Line)   // picking point from a line
            {
                // this may render points that should not appear.
                // so need to select by another picking.
                mode = (uint)DrawMode.Points;
            }
            else
            {
                mode = (uint)this.Mode;
            }

            switch (this.ElementType)
            {
            case IndexBufferElementType.UByte:
                offset = new IntPtr(this.FirstIndex * sizeof(byte));
                break;

            case IndexBufferElementType.UShort:
                offset = new IntPtr(this.FirstIndex * sizeof(ushort));
                break;

            case IndexBufferElementType.UInt:
                offset = new IntPtr(this.FirstIndex * sizeof(uint));
                break;

            default:
                throw new NotImplementedException();
            }

            if (glBindBuffer == null)
            {
                glBindBuffer = OpenGL.GetDelegateFor <OpenGL.glBindBuffer>();
            }
            glBindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, this.BufferId);
            if (primCount == 1)
            {
                OpenGL.DrawElements(mode, this.ElementCount, (uint)this.ElementType, offset);
            }
            else
            {
                if (glDrawElementsInstanced == null)
                {
                    glDrawElementsInstanced = OpenGL.GetDelegateFor <OpenGL.glDrawElementsInstanced>();
                }

                glDrawElementsInstanced(mode, this.ElementCount, (uint)this.ElementType, offset, primCount);
            }
            glBindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, 0);
        }
Пример #39
0
 public void RenderAfterChildren(RenderEventArgs arg)
 {
 }
Пример #40
0
        protected override void DoRender(RenderEventArgs arg)
        {
            ShaderProgram program = this.shaderProgram;

            if (program == null)
            {
                return;
            }

            // 绑定shader
            program.Bind();

            var updatedUniforms = (from item in this.uniformVariables where item.Updated select item).ToArray();

            foreach (var item in updatedUniforms)
            {
                item.SetUniform(program);
            }

            int count = this.switchList.Count;

            for (int i = 0; i < count; i++)
            {
                this.switchList[i].On();
            }

            IndexBufferPtr indexBufferPtr = this.indexBufferPtr;

            if (this.vertexArrayObject == null)
            {
                PropertyBufferPtr[] propertyBufferPtrs = this.propertyBufferPtrs;
                if (indexBufferPtr != null && propertyBufferPtrs != null)
                {
                    var vertexArrayObject = new VertexArrayObject(
                        indexBufferPtr, propertyBufferPtrs);
                    vertexArrayObject.Create(arg, program);

                    this.vertexArrayObject = vertexArrayObject;
                }
            }
            {
                VertexArrayObject vertexArrayObject = this.vertexArrayObject;
                if (vertexArrayObject != null)
                {
                    if (vertexArrayObject.IndexBufferPtr != indexBufferPtr)
                    {
                        vertexArrayObject.IndexBufferPtr = indexBufferPtr;
                    }
                    vertexArrayObject.Render(arg, program);
                }
            }

            for (int i = count - 1; i >= 0; i--)
            {
                this.switchList[i].Off();
            }

            foreach (var item in updatedUniforms)
            {
                item.ResetUniform(program);
            }

            // 解绑shader
            program.Unbind();
        }
Пример #41
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="arg"></param>
 public override void RenderAfterChildren(RenderEventArgs arg)
 {
     throw new NotImplementedException();
 }
Пример #42
0
 public override void RenderAfterChildren(RenderEventArgs arg)
 {
 }
Пример #43
0
 /// <summary>
 /// 执行此VBO的渲染操作。
 /// </summary>
 /// <param name="e"></param>
 /// <param name="shaderProgram">此VBO使用的shader program。</param>
 public abstract void Render(RenderEventArgs e, ShaderProgram shaderProgram);
Пример #44
0
        private PickedGeometry PickWhateverItIs(RenderEventArgs arg, uint stageVertexId, uint lastVertexId, DrawMode mode, PickingGeometryType typeOfMode)
        {
            //PickedGeometry pickedGeometry = new PickedGeometry();
            //pickedGeometry.GeometryType = typeOfMode;
            //pickedGeometry.StageVertexId = stageVertexId;
            //pickedGeometry.FromRenderer = this;

            // Fill primitive's position information.
            int vertexCount = typeOfMode.GetVertexCount();

            if (vertexCount == -1)
            {
                vertexCount = this.PositionBuffer.Length;
            }

            uint[] vertexIds; vec3[] positions;

            if (lastVertexId == 0 && vertexCount == 2)
            {
                // This is when mode is GL_LINE_LOOP and picked last line(the loop back one)
                PickingLastLineInLineLoop(out vertexIds, out positions);
            }
            else
            {
                // Other conditions
                switch (typeOfMode)
                {
                case PickingGeometryType.Point:
                    vertexIds = new uint[] { lastVertexId, };
                    positions = FillPickedGeometrysPosition(lastVertexId, 1);
                    break;

                case PickingGeometryType.Line:
                    vertexIds = new uint[] { lastVertexId - 1, lastVertexId, };
                    positions = FillPickedGeometrysPosition(lastVertexId - 1, 2);
                    break;

                case PickingGeometryType.Triangle:
                    if (mode == DrawMode.TriangleFan)
                    {
                        vertexIds = new uint[] { 0, lastVertexId - 1, lastVertexId, };
                        positions = FillPickedGeometrysPosition(vertexIds);
                    }
                    else if (mode == DrawMode.TrianglesAdjacency || mode == DrawMode.TriangleStripAdjacency)
                    {
                        vertexIds = new uint[] { lastVertexId - 4, lastVertexId - 2, lastVertexId, };
                        positions = FillPickedGeometrysPosition(vertexIds);
                    }
                    else
                    {
                        vertexIds = new uint[] { lastVertexId - 2, lastVertexId - 1, lastVertexId, };
                        positions = FillPickedGeometrysPosition(lastVertexId - 2, 3);
                    }
                    break;

                case PickingGeometryType.Quad:
                    vertexIds = new uint[] { lastVertexId - 3, lastVertexId - 2, lastVertexId - 1, lastVertexId, };
                    positions = FillPickedGeometrysPosition(lastVertexId - 3, 4);
                    break;

                case PickingGeometryType.Polygon:
                    vertexIds = new uint[vertexCount];
                    for (uint i = 0; i < vertexCount; i++)
                    {
                        vertexIds[i] = lastVertexId + i;
                    }
                    positions = FillPickedGeometrysPosition(0, vertexCount);
                    break;

                default:
                    throw new NotImplementedException();
                }
            }

            PickedGeometry pickedGeometry = new PickedGeometry(arg.UsingViewPort, typeOfMode, positions, vertexIds, stageVertexId, this);

            return(pickedGeometry);
        }
Пример #45
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="stageVertexId"></param>
        /// <param name="x">mouse position(Left Down is (0, 0)).</param>
        /// <param name="y">mouse position(Left Down is (0, 0)).</param>
        /// <returns></returns>
        public override PickedGeometry GetPickedGeometry(RenderEventArgs arg, uint stageVertexId,
                                                         int x, int y)
        {
            uint lastVertexId;

            if (!this.GetLastVertexIdOfPickedGeometry(stageVertexId, out lastVertexId))
            {
                return(null);
            }

            PickingGeometryType geometryType = arg.PickingGeometryType;

            if (geometryType == PickingGeometryType.Point)
            {
                DrawMode            mode       = this.indexBuffer.Mode;
                PickingGeometryType typeOfMode = mode.ToGeometryType();
                if (typeOfMode == PickingGeometryType.Point)
                {
                    return(PickWhateverItIs(arg, stageVertexId, lastVertexId, mode, typeOfMode));
                }
                else if (typeOfMode == PickingGeometryType.Line)
                {
                    if (this.OnPrimitiveTest(lastVertexId, mode))
                    {
                        return(PickPoint(arg, stageVertexId, lastVertexId));
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    ZeroIndexPointSearcher searcher = GetPointSearcher(mode);
                    if (searcher != null)// point is from triangle, quad or polygon
                    {
                        return(SearchPoint(arg, stageVertexId, x, y, lastVertexId, searcher));
                    }
                    else
                    {
                        throw new Exception(string.Format("Lack of searcher for [{0}]", mode));
                    }
                }
            }
            else if (geometryType == PickingGeometryType.Line)
            {
                DrawMode            mode       = this.indexBuffer.Mode;
                PickingGeometryType typeOfMode = mode.ToGeometryType();
                if (geometryType == typeOfMode)
                {
                    return(PickWhateverItIs(arg, stageVertexId, lastVertexId, mode, typeOfMode));
                }
                else
                {
                    ZeroIndexLineSearcher searcher = GetLineSearcher(mode);
                    if (searcher != null)// line is from triangle, quad or polygon
                    {
                        return(SearchLine(arg, stageVertexId, x, y, lastVertexId, searcher));
                    }
                    else if (mode == DrawMode.Points)// want a line when rendering GL_POINTS
                    {
                        return(null);
                    }
                    else
                    {
                        throw new Exception(string.Format("Lack of searcher for [{0}]", mode));
                    }
                }
            }
            else
            {
                DrawMode            mode       = this.indexBuffer.Mode;
                PickingGeometryType typeOfMode = mode.ToGeometryType();
                if (typeOfMode == geometryType)// I want what it is
                {
                    return(PickWhateverItIs(arg, stageVertexId, lastVertexId, mode, typeOfMode));
                }
                else
                {
                    return(null);
                }
                //{ throw new Exception(string.Format("Lack of searcher for [{0}]", mode)); }
            }
        }
Пример #46
0
 public override void RenderAfterChildren(CSharpGL.RenderEventArgs arg)
 {
 }
Пример #47
0
 /// <summary>
 /// Render something.
 /// </summary>
 /// <param name="arg"></param>
 protected abstract void DoRender(RenderEventArgs arg);
 /// <summary>
 /// Render something before renddering children.
 /// </summary>
 /// <param name="arg"></param>
 public abstract void RenderBeforeChildren(RenderEventArgs arg);
 /// <summary>
 /// Render something after renddering children.
 /// </summary>
 /// <param name="arg"></param>
 public abstract void RenderAfterChildren(RenderEventArgs arg);