public void UpdateVertexBuffer(Device device)
        {
            // Don't do anything if we got no lines.
            if (NumOfLines == 0 ||
                // Or if some data is invalid
                lines.Count < NumOfLines)
            {
                numOfPrimitives = 0;
                return;
            } // if (numOfLines)

            if (buildVertexBuffer || numOfPrimitives != NumOfLines)
            {
                //UpdateVertexBuffer();



                // Set all lines
                for (int lineNum = 0; lineNum < NumOfLines; lineNum++)
                {
                    LineManager3D.Line line = lines[lineNum];
                    LineVertices[lineNum * 2 + 0] = new VertexPositionColor(
                        new Vector4(line.startPoint, 1), line.startColor);
                    LineVertices[lineNum * 2 + 1] = new VertexPositionColor(
                        new Vector4(line.endPoint, 1), line.endColor);
                } // for (lineNum)
                numOfPrimitives = NumOfLines;

                //TODO: WARNING: is this a memory leak?
                //var dataRect = VertexBuffer.AsSurface().Map(SlimDX.DXGI.MapFlags.Discard);


                //TODO: WARNING: possible bottleneck here
                var dataRect = device.ImmediateContext.MapSubresource(vertexBuffer, MapMode.WriteDiscard, MapFlags.None);

                dataRect.Data.WriteRange(lineVertices, 0, numOfPrimitives * 2);

                device.ImmediateContext.UnmapSubresource(vertexBuffer, 0);
                //VertexBuffer.AsSurface().Unmap();

                // Vertex buffer was build
                buildVertexBuffer = false;
            } // if (buildVertexBuffer)
        }     // UpdateVertexBuffer()
        /// <summary>
        /// Add line
        /// </summary>
        public void addLineInternal(
            Vector3 startPoint, Color4 startColor,
            Vector3 endPoint, Color4 endColor)
        {
            // Don't add new lines if limit is reached
            if (NumOfLines >= MaxNumOfLines)
            {
                /*ignore
                 * Log.Write("Too many lines requested in LineManager3D. " +
                 *  "Max lines = " + MaxNumOfLines);
                 */
                return;
            } // if (numOfLines)

            // Build line
            LineManager3D.Line line = new LineManager3D.Line(startPoint, startColor, endPoint, endColor);

            // Check if this exact line exists at the current lines position.
            if (lines.Count > NumOfLines)
            {
                if ((LineManager3D.Line)lines[NumOfLines] != line)
                {
                    // overwrite old line, otherwise just increase numOfLines
                    lines[NumOfLines] = line;
                    // Remember to build vertex buffer in Render()
                    buildVertexBuffer = true;
                } // if if
            }     // if
            else
            {
                // Then just add new line
                lines.Add(line);
                // Remember to build vertex buffer in Render()
                buildVertexBuffer = true;
            } // else

            // nextUpValue line
            NumOfLines++;
        } // AddLine(startPoint, startColor, endPoint)