Пример #1
0
        public override void DrawAll(GLControl control)
        {
            if (GLContext != null && GLContext != control)
            {
                Dispose();
            }

            if (control.InvokeRequired)
            {
                control.Invoke(new Action <GLControl>(this.DrawAll), control);
            }
            else
            {
                if (VtxVboID == 0)
                {
                    GL.GenBuffers(1, out VtxVboID);
                    GL.BindBuffer(BufferTarget.ArrayBuffer, VtxVboID);
                    GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(NumVertices * BlittableValueType.StrideOf(Vertices)), Vertices, BufferUsageHint.StaticDraw);
                }

                int vbosize = NumVertices;
                GL.EnableClientState(ArrayCap.VertexArray);
                GL.BindBuffer(BufferTarget.ArrayBuffer, VtxVboID);
                GL.VertexPointer(3, VertexPointerType.Double, 0, 0);
                GL.PointSize(pointSize);
                GL.Color3(color);
                GL.DrawArrays(PrimitiveType.Lines, 0, vbosize);
                GL.DisableClientState(ArrayCap.VertexArray);
            }
        }
Пример #2
0
        public void Draw(GLControl control)
        {
            if (control.InvokeRequired)
            {
                control.Invoke(new Action <GLControl>(this.Draw), control);
            }
            else
            {
                _control = control;

                CreateTexture();
                CreateVertices();

                int vbosize = NumVertices;
                GL.Enable(EnableCap.Texture2D);
                GL.EnableClientState(ArrayCap.VertexArray);
                GL.BindTexture(TextureTarget.Texture2D, _texid);
                GL.BindBuffer(BufferTarget.ArrayBuffer, VtxVboID);
                GL.VertexPointer(3, VertexPointerType.Double, 0, 0);
                GL.EnableClientState(ArrayCap.TextureCoordArray);
                GL.BindBuffer(BufferTarget.ArrayBuffer, TexVboID);
                GL.TexCoordPointer(4, TexCoordPointerType.Double, 0, 0);
                GL.Color4(Color);
                GL.DrawArrays(PrimitiveType.Triangles, 0, vbosize);
                GL.DisableClientState(ArrayCap.TextureCoordArray);
                GL.DisableClientState(ArrayCap.VertexArray);
                GL.Disable(EnableCap.Texture2D);
            }
        }
Пример #3
0
 private void makeCurrent()
 {
     if (!control.Context.IsCurrent)
     {
         control.Invoke(new glControlThreadSwitcher(control.Context.MakeCurrent), new object[] { null });
         control.MakeCurrent();
     }
 }
Пример #4
0
        public void FreeTexture(bool remove)
        {
            if (_control != null && TextureVboID != 0)
            {
                if (_control.InvokeRequired)
                {
                    _control.Invoke(new Action <bool>(this.FreeTexture), remove);
                }
                else
                {
                    if (TextureVboID != 0)
                    {
                        GL.DeleteTexture(TextureVboID);
                        TextureVboID = 0;
                    }
                }

                if (remove)
                {
                    if (_parentTexture != null)
                    {
                        _parentTexture._childTextures.Remove(this);

                        _parentTexture = null;
                    }
                    else if (_childTextures.Count != 0)
                    {
                        _childTextures[0]._parentTexture = null;

                        for (int i = 1; i < _childTextures.Count; i++)
                        {
                            _childTextures[i] = _childTextures[0];
                            _childTextures[0]._childTextures.Add(_childTextures[i]);
                        }

                        _childTextures.Clear();
                    }
                }
            }
        }
Пример #5
0
        public override void DrawAll(GLControl control)
        {
            if (GLContext != null && GLContext != control)
            {
                Dispose();
            }

            if (control.InvokeRequired)
            {
                control.Invoke(new Action <GLControl>(this.DrawAll), control);
            }
            else
            {
                if (VtxVboID == 0)
                {
                    GL.GenBuffers(1, out VtxVboID);
                    GL.BindBuffer(BufferTarget.ArrayBuffer, VtxVboID);
                    GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(NumVertices * BlittableValueType.StrideOf(Vertices)), Vertices, BufferUsageHint.StaticDraw);

                    if (UsePointDataColour)
                    {
                        GL.GenBuffers(1, out VtxColorVboId);
                        GL.BindBuffer(BufferTarget.ArrayBuffer, VtxColorVboId);
                        GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(NumVertices * BlittableValueType.StrideOf(carray)), carray, BufferUsageHint.StaticDraw);
                    }

                    GLContext = control;
                }

                GL.EnableClientState(ArrayCap.VertexArray);
                GL.BindBuffer(BufferTarget.ArrayBuffer, VtxVboID);
                GL.VertexPointer(3, VertexPointerType.Float, 0, 0);
                GL.PointSize(this.Size);

                if (UsePointDataColour)
                {
                    GL.EnableClientState(ArrayCap.ColorArray);
                    GL.BindBuffer(BufferTarget.ArrayBuffer, VtxColorVboId);
                    GL.ColorPointer(4, ColorPointerType.UnsignedByte, 0, 0);
                    GL.DrawArrays(PrimitiveType.Points, 0, NumVertices);
                    GL.DisableClientState(ArrayCap.ColorArray);
                }
                else
                {
                    GL.Color4(this.Color);
                    GL.DrawArrays(PrimitiveType.Points, 0, NumVertices);
                }

                GL.DisableClientState(ArrayCap.VertexArray);
            }
        }
Пример #6
0
 public void Dispose()
 {
     if (GLContext != null)
     {
         if (GLContext.InvokeRequired)
         {
             GLContext.Invoke(new Action(this.Dispose));
         }
         else
         {
             GL.DeleteBuffer(VtxVboID);
             GLContext = null;
         }
     }
 }
Пример #7
0
 public void FreeTexture()
 {
     if (_control != null && _texid != 0)
     {
         if (_control.InvokeRequired)
         {
             _control.Invoke(new Action(this.FreeTexture));
         }
         else
         {
             GL.DeleteTexture(_texid);
             _texid = 0;
         }
     }
 }
Пример #8
0
        public void Draw(GLControl control)
        {
            if (control.InvokeRequired)
            {
                control.Invoke(new Action <GLControl>(this.Draw), control);
            }
            else
            {
                GL.PointSize(Size);

                GL.Begin(Type);
                GL.Color3(Color);
                GL.Vertex3(Pos);
                GL.End();
            }
        }
Пример #9
0
 public void Draw(GLControl control)
 {
     if (control.InvokeRequired)
     {
         control.Invoke(new Action <GLControl>(this.Draw), control);
     }
     else
     {
         GL.Begin(Type);
         GL.Color4(Color);
         foreach (Vector3 v in vertices)
         {
             GL.Vertex3(v);
         }
         GL.End();
     }
 }
Пример #10
0
 public void DeleteContext()
 {
     if (GLContext != null)
     {
         if (GLContext.InvokeRequired)
         {
             GLContext.Invoke(new Action(this.DeleteContext));
         }
         else
         {
             GL.DeleteBuffer(VtxVboID);
             GL.DeleteBuffer(VtxColorVboId);
             GLContext     = null;
             VtxVboID      = 0;
             VtxColorVboId = 0;
         }
     }
 }
Пример #11
0
        public virtual void DrawAll(GLControl control)
        {
            if (!Visible)
            {
                return;
            }

            if (control.InvokeRequired)
            {
                control.Invoke(new Action <GLControl>(this.DrawAll), control);
            }
            else
            {
                foreach (var primative in Primatives)
                {
                    primative.Draw(control);
                }
            }
        }
Пример #12
0
        public void Draw(GLControl control)         // UI thread.
        {
            Debug.Assert(Application.MessageLoop);

            if (GLContext != null)
            {
                Debug.Assert(GLContext == control);
                Debug.Assert(VtxVboID > 0);

                if (control.InvokeRequired)
                {
                    control.Invoke(new Action <GLControl>(this.Draw), control);
                }
                else
                {
                    int numpoints = (array1displayed) ? array1vertices : array2vertices;

                    if (numpoints > 0)
                    {
                        GL.EnableClientState(ArrayCap.VertexArray);
                        GL.BindBuffer(BufferTarget.ArrayBuffer, VtxVboID);
                        GL.VertexPointer(3, VertexPointerType.Float, 0, 0);
                        GL.PointSize(Size);

                        if (Color.IsFullyTransparent())
                        {
                            GL.EnableClientState(ArrayCap.ColorArray);
                            GL.BindBuffer(BufferTarget.ArrayBuffer, VtxColorVboId);
                            GL.ColorPointer(4, ColorPointerType.UnsignedByte, 0, 0);
                            GL.DrawArrays(PrimitiveType.Points, 0, numpoints);
                            GL.DisableClientState(ArrayCap.ColorArray);
                        }
                        else
                        {
                            GL.Color4(Color);
                            GL.DrawArrays(PrimitiveType.Points, 0, numpoints);
                        }

                        GL.DisableClientState(ArrayCap.VertexArray);
                    }
                }
            }
        }
Пример #13
0
        public override void DrawAll(GLControl control)
        {
            if (GLContext != null && GLContext != control)
            {
                Dispose();
            }

            if (control.InvokeRequired)
            {
                control.Invoke(new Action <GLControl>(this.DrawAll), control);
            }
            else
            {
                if (VtxVboID == 0)                                              // shove vertexes into a buffer
                {
                    GL.GenBuffers(1, out VtxVboID);
                    GL.BindBuffer(BufferTarget.ArrayBuffer, VtxVboID);
                    GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(NumVertices * BlittableValueType.StrideOf(Vertices)), Vertices, BufferUsageHint.StaticDraw);

                    GL.GenBuffers(1, out VtxColourVboId);
                    GL.BindBuffer(BufferTarget.ArrayBuffer, VtxColourVboId);
                    GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(NumVertices * BlittableValueType.StrideOf(Colourarray)), Colourarray, BufferUsageHint.StaticDraw);

                    GLContext = control;
                }

                GL.EnableClientState(ArrayCap.VertexArray);                     // MEASUREMENTS are showing this can for some reason take 40ms to draw.. at random times
                GL.BindBuffer(BufferTarget.ArrayBuffer, VtxVboID);              // Maybe we should tesselate the polygons to triangles
                GL.VertexPointer(3, VertexPointerType.Float, 0, 0);
                GL.PointSize(this.Size);

                GL.EnableClientState(ArrayCap.ColorArray);
                GL.BindBuffer(BufferTarget.ArrayBuffer, VtxColourVboId);
                GL.ColorPointer(4, ColorPointerType.UnsignedByte, 0, 0);

                GL.MultiDrawArrays(Primative, Polystart.ToArray(), Polycount.ToArray(), Polystart.Count);

                GL.DisableClientState(ArrayCap.ColorArray);
                GL.DisableClientState(ArrayCap.VertexArray);
            }
        }
Пример #14
0
        public void Draw(GLControl control)
        {
            if (_control != null && control != _control)
            {
                FreeTexture();
            }

            if (control.InvokeRequired)
            {
                control.Invoke(new Action <GLControl>(this.Draw), control);
            }
            else
            {
                _control = control;

                if (_texture != Texture)
                {
                    FreeTexture();
                }

                if (_texid == 0)
                {
                    Bitmap bmp = Texture;

                    /*
                     * int newwidth = 1 << (int)(Math.Log(bmp.Width - 1, 2) + 1);
                     * int newheight = 1 << (int)(Math.Log(bmp.Height - 1, 2) + 1);
                     * if (bmp.Width != newwidth || bmp.Height != newheight)
                     * {
                     *  bmp = new Bitmap(Texture, new Size(newwidth, newheight));
                     * }
                     */
                    GL.GenTextures(1, out _texid);
                    GL.BindTexture(TextureTarget.Texture2D, _texid);
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
                    System.Drawing.Imaging.BitmapData bmpdata = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                    GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bmpdata.Width, bmpdata.Height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, bmpdata.Scan0);
                    bmp.UnlockBits(bmpdata);
                    _texture = Texture;
                }

                GL.Color3(Color);
                GL.Enable(EnableCap.Texture2D);
                GL.BindTexture(TextureTarget.Texture2D, _texid);
                GL.Begin(PrimitiveType.Triangles);
                GL.TexCoord4(Texcoords[0]);
                GL.Vertex3(Vertices[0]);
                GL.TexCoord4(Texcoords[1]);
                GL.Vertex3(Vertices[1]);
                GL.TexCoord4(Texcoords[2]);
                GL.Vertex3(Vertices[2]);
                GL.TexCoord4(Texcoords[0]);
                GL.Vertex3(Vertices[0]);
                GL.TexCoord4(Texcoords[2]);
                GL.Vertex3(Vertices[2]);
                GL.TexCoord4(Texcoords[3]);
                GL.Vertex3(Vertices[3]);
                GL.End();
                GL.Disable(EnableCap.Texture2D);
            }
        }