示例#1
0
        public void Render(ShaderColorXY shader, RectangleF view, Size areaInPixels, TimeStamp offset)
        {
            if (_vbo.Length == 0)
            {
                return;
            }

            // TODO: this should be done in Add
            //       as the buffer will be reloaded for every frame.
            //       Not much data to be copied, but still unnecessary.
            var lastVertex = _vbo[_vbo.Length - 1];

            _vbo.AddVertex(float.MaxValue, lastVertex.Y);
            _vbo.IndexFromLength();
            _vbo.Reload();

            shader.SetTranslateMatrix(Matrix4.Identity);
            shader.SetShaderColor(LineColor);

            var trsl = Matrix4.CreateTranslation(-offset.ToRate(SamplesPerSecond), 0, 0);

            shader.SetTranslateMatrix(trsl);

            GL.LineWidth(Selected ? 3.0f : 1.0f);
            _vbo.DrawMode = BeginMode.LineStrip;
            _vbo.BindAndDraw(shader);

            GL.PointSize(Selected ? 8.0f : 6.0f);
            _vbo.DrawMode = BeginMode.Points;
            _vbo.BindAndDraw(shader);

            _vbo.PopVertex();
        }
示例#2
0
        protected void DrawGridLines()
        {
            _shader.SetShaderMatrix(
                Matrix4.CreateOrthographicOffCenter(
                    0, 1,
                    (float)AxisY.VisibleMinimum,
                    (float)AxisY.VisibleMaximum,
                    -1, 1
                    )
                );

            _shader.SetTranslateMatrix(Matrix4.Identity);

            _shader.SetShaderColor(Color.DarkGray);

            GL.LineWidth(1.0f);

            _gridLines.BindAndDraw(_shader);
        }
示例#3
0
        public void Render(ShaderColorXY shader, RectangleF view, Size areaInPixels, TimeStamp offset)
        {
            var ringBuffer = _ringBuffer;

            // y per pixel
            var visibleY = -1 * view.Height / areaInPixels.Height;

            // find an appropriate zoom level for current view
            var level      = -1;
            var zoomFactor = areaInPixels.Width / (double)view.Width;

            for (int i = _zoomLevels.Length - 1; i >= 0; i--)
            {
                if (zoomFactor < 1.0 / _zoomLevels[i])
                {
                    level = i;
                    break;
                }
            }

            if (_level != level)
            {
                System.Diagnostics.Debug.WriteLine("Level: " + level);
                if (level == -1)
                {
                    _ringBuffer.Length = _ringBuffer.Capacity;
                    SetX(1);
                }
                else
                {
                    _ringBuffer.Length = _ringBuffer.Capacity / _zoomLevels[level];
                    SetXTriangles(_zoomLevels[level]);
                }

                _level = level;
            }

            // leftSample is the first sample that is visible in the current View.
            // It will be shifted to the left though if it is older than the other signals.
            // This must be corrected.
            // So calculate the left sample index to be the one that sits on the reference time.

            // fill GL buffer with visible samples
            var shift      = ((offset - Duration.Begin).AsSeconds() * SamplesPerSecond);
            var leftSample = (int)((Math.Max(0, view.Left)) + shift);

            // Now the sample count is no more correct. We have to subtract what we just added.

            var sampleCount = FillBuffer(
                level:   level,
                offset:  leftSample / (level == -1 ? 1 : _zoomLevels[level]),
                samples: (int)(Math.Max(0, view.Width + shift) / (level == -1 ? 1 : _zoomLevels[level]))
                );


            // Render
            GL.BindBuffer(BufferTarget.ArrayBuffer, ringBuffer.VboX);
            GL.EnableVertexAttribArray(shader.AttributeX);
            GL.VertexAttribPointer(shader.AttributeX, 1, VertexAttribPointerType.Float, false, 4, 0);

            GL.BindBuffer(BufferTarget.ArrayBuffer, ringBuffer.VboY);
            GL.EnableVertexAttribArray(shader.AttributeY);
            GL.VertexAttribPointer(shader.AttributeY, 1, VertexAttribPointerType.Float, false, 4, 0);

            GL.BindBuffer(BufferTarget.ElementArrayBuffer, ringBuffer.Ebo);

            shader.SetShaderColor(LineColor);

            GL.LineWidth(Selected ? 3.0f : 1.0f);

            var trsl = Matrix4.CreateTranslation((float)(leftSample + ((-offset.AsSeconds() + _currentTime.AsSeconds()) * SamplesPerSecond) - _signalBuffer.Length), 0, 0);

            shader.SetTranslateMatrix(trsl);

            if (level == -1)
            {
                GL.DrawElements(BeginMode.LineStrip, sampleCount, DrawElementsType.UnsignedInt, new IntPtr(0));
            }
            else
            {
                GL.DrawElements(BeginMode.TriangleStrip, sampleCount, DrawElementsType.UnsignedInt, new IntPtr(0));
            }

            if (level != -1)
            {
                GL.BindBuffer(BufferTarget.ArrayBuffer, _ringBufferMax.VboX);
                GL.EnableVertexAttribArray(shader.AttributeX);
                GL.VertexAttribPointer(shader.AttributeX, 1, VertexAttribPointerType.Float, false, 4, 0);

                GL.BindBuffer(BufferTarget.ArrayBuffer, _ringBufferMax.VboY);
                GL.EnableVertexAttribArray(shader.AttributeY);
                GL.VertexAttribPointer(shader.AttributeY, 1, VertexAttribPointerType.Float, false, 4, 0);

                GL.BindBuffer(BufferTarget.ElementArrayBuffer, _ringBufferMax.Ebo);

                shader.SetShaderColor(LineColor);

                GL.LineWidth(Selected ? 3.0f : 1.0f);

                trsl = Matrix4.CreateTranslation((float)(leftSample + ((-offset.AsSeconds() + _currentTime.AsSeconds()) * SamplesPerSecond) - _signalBuffer.Length), 0, 0);
                shader.SetTranslateMatrix(trsl);

                GL.DrawElements(BeginMode.LineStrip, sampleCount / 2, DrawElementsType.UnsignedInt, new IntPtr(0));



                GL.BindBuffer(BufferTarget.ArrayBuffer, _ringBufferMin.VboX);
                GL.EnableVertexAttribArray(shader.AttributeX);
                GL.VertexAttribPointer(shader.AttributeX, 1, VertexAttribPointerType.Float, false, 4, 0);

                GL.BindBuffer(BufferTarget.ArrayBuffer, _ringBufferMin.VboY);
                GL.EnableVertexAttribArray(shader.AttributeY);
                GL.VertexAttribPointer(shader.AttributeY, 1, VertexAttribPointerType.Float, false, 4, 0);

                GL.BindBuffer(BufferTarget.ElementArrayBuffer, _ringBufferMin.Ebo);

                shader.SetShaderColor(LineColor);

                GL.LineWidth(Selected ? 3.0f : 1.0f);

                trsl = Matrix4.CreateTranslation((float)(leftSample + ((-offset.AsSeconds() + _currentTime.AsSeconds()) * SamplesPerSecond) - _signalBuffer.Length), 0, 0);
                shader.SetTranslateMatrix(trsl);

                GL.DrawElements(BeginMode.LineStrip, sampleCount / 2, DrawElementsType.UnsignedInt, new IntPtr(0));
            }
        }
示例#4
0
        public void Render(ShaderColorXY shader, RectangleF view, Size areaInPixels, TimeStamp offset)
        {
            // find an appropriate zoom level for current view
            var level      = -1;
            var zoomFactor = areaInPixels.Width / (double)view.Width;

            for (int i = _zoomLevels.Length - 1; i >= 0; i--)
            {
                if (zoomFactor < 1.0 / _zoomLevels[i])
                {
                    level = i;
                    break;
                }
            }

            if (_level != level)
            {
                if (level == -1)
                {
                    SetX(1);
                }
                else
                {
                    //SetX(_zoomLevels[level]);
                    SetXTriangles(_zoomLevels[level] / 2);
                }

                _level = level;
            }

            var leftSample = (int)(Math.Max(0, view.Left - Duration.Begin.ToRate(SamplesPerSecond)));

            var sampleCount = FillBuffer(
                level:   level,
                offset:  leftSample / (level == -1 ? 1 : _zoomLevels[level]),
                samples: (int)((Math.Max(0, view.Width)) / (level == -1 ? 1 : _zoomLevels[level]))
                );

            // Render
            GL.BindBuffer(BufferTarget.ArrayBuffer, _ringBuffer.VboX);
            GL.EnableVertexAttribArray(shader.AttributeX);
            GL.VertexAttribPointer(shader.AttributeX, 1, VertexAttribPointerType.Float, false, 4, 0);

            GL.BindBuffer(BufferTarget.ArrayBuffer, _ringBuffer.VboY);
            GL.EnableVertexAttribArray(shader.AttributeY);
            GL.VertexAttribPointer(shader.AttributeY, 1, VertexAttribPointerType.Float, false, 4, 0);

            GL.BindBuffer(BufferTarget.ElementArrayBuffer, _ringBuffer.Ebo);

            shader.SetShaderColor(LineColor);

            GL.LineWidth(Selected ? 3.0f : 1.0f);

            var trsl = Matrix4.CreateTranslation(leftSample + Duration.Begin.ToRate(SamplesPerSecond), 0, 0);

            shader.SetTranslateMatrix(trsl);
            GL.DrawElements(BeginMode.LineStrip, sampleCount, DrawElementsType.UnsignedInt, new IntPtr(0));


            if (level != -1)
            {
                GL.BindBuffer(BufferTarget.ArrayBuffer, _ringBufferMax.VboX);
                GL.EnableVertexAttribArray(shader.AttributeX);
                GL.VertexAttribPointer(shader.AttributeX, 1, VertexAttribPointerType.Float, false, 4, 0);

                GL.BindBuffer(BufferTarget.ArrayBuffer, _ringBufferMax.VboY);
                GL.EnableVertexAttribArray(shader.AttributeY);
                GL.VertexAttribPointer(shader.AttributeY, 1, VertexAttribPointerType.Float, false, 4, 0);

                GL.BindBuffer(BufferTarget.ElementArrayBuffer, _ringBufferMax.Ebo);

                shader.SetShaderColor(LineColor);

                GL.LineWidth(Selected ? 3.0f : 1.0f);

                trsl = Matrix4.CreateTranslation(leftSample + Duration.Begin.ToRate(SamplesPerSecond), 0, 0);
                shader.SetTranslateMatrix(trsl);

                GL.DrawElements(BeginMode.LineStrip, sampleCount / 2 - 1, DrawElementsType.UnsignedInt, new IntPtr(0));



                GL.BindBuffer(BufferTarget.ArrayBuffer, _ringBufferMin.VboX);
                GL.EnableVertexAttribArray(shader.AttributeX);
                GL.VertexAttribPointer(shader.AttributeX, 1, VertexAttribPointerType.Float, false, 4, 0);

                GL.BindBuffer(BufferTarget.ArrayBuffer, _ringBufferMin.VboY);
                GL.EnableVertexAttribArray(shader.AttributeY);
                GL.VertexAttribPointer(shader.AttributeY, 1, VertexAttribPointerType.Float, false, 4, 0);

                GL.BindBuffer(BufferTarget.ElementArrayBuffer, _ringBufferMin.Ebo);

                shader.SetShaderColor(LineColor);

                GL.LineWidth(Selected ? 3.0f : 1.0f);

                trsl = Matrix4.CreateTranslation(leftSample + Duration.Begin.ToRate(SamplesPerSecond), 0, 0);
                shader.SetTranslateMatrix(trsl);

                GL.DrawElements(BeginMode.LineStrip, sampleCount / 2, DrawElementsType.UnsignedInt, new IntPtr(0));
            }
        }