Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GaussianProcessTuning/ILNumerics.2.14.4735.573/Drawing/Platform/OpenGL/ILOGLLineRendererC4bV3f.cs @ 10903

Last change on this file since 10903 was 9102, checked in by gkronber, 12 years ago

#1967: ILNumerics source for experimentation

File size: 7.3 KB
Line 
1///
2///    This file is part of ILNumerics Community Edition.
3///
4///    ILNumerics Community Edition - high performance computing for applications.
5///    Copyright (C) 2006 - 2012 Haymo Kutschbach, http://ilnumerics.net
6///
7///    ILNumerics Community Edition is free software: you can redistribute it and/or modify
8///    it under the terms of the GNU General Public License version 3 as published by
9///    the Free Software Foundation.
10///
11///    ILNumerics Community Edition is distributed in the hope that it will be useful,
12///    but WITHOUT ANY WARRANTY; without even the implied warranty of
13///    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14///    GNU General Public License for more details.
15///
16///    You should have received a copy of the GNU General Public License
17///    along with ILNumerics Community Edition. See the file License.txt in the root
18///    of your distribution package. If not, see <http://www.gnu.org/licenses/>.
19///
20///    In addition this software uses the following components and/or licenses:
21///
22///    =================================================================================
23///    The Open Toolkit Library License
24///   
25///    Copyright (c) 2006 - 2009 the Open Toolkit library.
26///   
27///    Permission is hereby granted, free of charge, to any person obtaining a copy
28///    of this software and associated documentation files (the "Software"), to deal
29///    in the Software without restriction, including without limitation the rights to
30///    use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
31///    the Software, and to permit persons to whom the Software is furnished to do
32///    so, subject to the following conditions:
33///
34///    The above copyright notice and this permission notice shall be included in all
35///    copies or substantial portions of the Software.
36///
37///    =================================================================================
38///   
39
40using System;
41using ILNumerics.Drawing.Shapes;
42using OpenTK.Graphics;
43using OpenTK.Graphics.OpenGL;
44
45namespace ILNumerics.Drawing.Platform.OpenGL {
46    /// <summary>
47    /// An OpenGL vertex renderer, capable of rendering
48    /// vertex arrays of type C4bV3f (simple /-primitive shapes).
49    /// </summary>
50    public unsafe class ILOGLLineRendererC4bV3f : ILVertexRenderer {
51
52        #region attributes
53        uint[] m_closeLoopIndices;
54        #endregion
55
56        #region properties
57        #endregion
58
59        public ILOGLLineRendererC4bV3f (int numVertices) {
60            CloseLines = false;
61            m_closeLoopIndices = new uint[2] {(uint)numVertices-1,0};
62        }
63        public override void Draw(ILRenderProperties props, ILShape shape) {
64            GL.Enable(EnableCap.Blend);
65            GL.BlendFunc (BlendingFactorSrc.SrcAlpha,
66                          BlendingFactorDest.OneMinusSrcAlpha);
67            GL.Enable(EnableCap.DepthTest);
68            ILLine line = (shape as ILLine);
69            if (line != null && line.Border.Visible) {
70                fixed (C4bV3f* pVertices = line.Vertices) {
71                    ILOGLPanel.SetupLineStyle(line.Border);
72                    GL.InterleavedArrays(InterleavedArrayFormat.C4ubV3f, 0, (IntPtr)pVertices);
73                    GL.DisableClientState(EnableCap.ColorArray);
74                    if (line.OldestVertexID == 0) {
75                        GL.DrawArrays(BeginMode.LineStrip, 0, line.VertexCount);
76                    } else {
77                        GL.DrawArrays(BeginMode.LineStrip, line.OldestVertexID, line.VertexCount - line.OldestVertexID);
78                        GL.DrawElements(BeginMode.Lines,2,DrawElementsType.UnsignedInt, m_closeLoopIndices);
79                        GL.DrawArrays(BeginMode.LineStrip, 0, line.OldestVertexID);
80                    }
81                }
82            }
83            GL.Disable(EnableCap.DepthTest);
84            ILOGLPanel.SetupLineStyle(line.Properties);
85            fixed (C4bV3f* pVertices = line.Vertices) {
86                GL.InterleavedArrays(InterleavedArrayFormat.C4ubV3f, 0, (IntPtr)pVertices);
87                if (line.Shading == ShadingStyles.Interpolate)
88                    GL.ShadeModel(ShadingModel.Smooth);
89                else {
90                    GL.ShadeModel(ShadingModel.Flat);
91                    GL.DisableClientState(EnableCap.ColorArray);
92                    GL.Color4(line.FillColor); 
93                }
94                if (line.OldestVertexID == 0) {
95                    GL.DrawArrays(BeginMode.LineStrip, 0, line.VertexCount);
96                } else {
97                    GL.DrawArrays(BeginMode.LineStrip, line.OldestVertexID, line.VertexCount - line.OldestVertexID);
98                    GL.DrawElements(BeginMode.Lines, 2, DrawElementsType.UnsignedInt, m_closeLoopIndices);
99                    GL.DrawArrays(BeginMode.LineStrip, 0, line.OldestVertexID);
100                }
101            }
102
103        }
104        public override void Draw(ILRenderProperties props, ILShape shape, int[] indices) {
105            System.Diagnostics.Debug.Assert(indices != null && indices != null);
106            GL.Enable(EnableCap.DepthTest);
107            GL.Disable(EnableCap.Blend);
108            ILBorderedShape<C4bV3f> bShape = (shape as ILBorderedShape<C4bV3f>);
109            if (bShape != null && bShape.Border.Visible) {
110                fixed (int* pIndices = indices)
111                fixed (C4bV3f* pVertices = bShape.Vertices) {
112                    ILOGLPanel.SetupLineStyle(bShape.Border);
113                    GL.InterleavedArrays(
114                                    InterleavedArrayFormat.C4ubV3f, 0, (IntPtr)pVertices);
115                    GL.DisableClientState(EnableCap.ColorArray);
116                    if (CloseLines)
117                        GL.DrawElements(BeginMode.LineLoop, indices.Length,
118                                    DrawElementsType.UnsignedInt, (IntPtr)pIndices);
119                    else
120                        GL.DrawElements(BeginMode.LineStrip, indices.Length,
121                                    DrawElementsType.UnsignedInt, (IntPtr)pIndices);
122                }
123            }
124           
125            GL.Enable(EnableCap.Blend);
126            GL.BlendFunc (BlendingFactorSrc.SrcAlpha,
127                          BlendingFactorDest.OneMinusSrcAlpha);
128            ILShape<C4bV3f> cShape = (shape as ILShape<C4bV3f>);
129            if (cShape is ILLine) {
130                ILOGLPanel.SetupLineStyle((cShape as ILLine).Properties);
131                GL.Disable(EnableCap.DepthTest);
132            } else {
133                GL.Disable(EnableCap.LineSmooth);
134            }
135            fixed (int* pIndices = indices)
136            fixed (C4bV3f* pVertices = cShape.Vertices) {
137                GL.InterleavedArrays(InterleavedArrayFormat.C4ubV3f, 0, (IntPtr)pVertices);
138                if (cShape.Shading == ShadingStyles.Interpolate)
139                    GL.ShadeModel(ShadingModel.Smooth);
140                else {
141                    GL.ShadeModel(ShadingModel.Flat);
142                    GL.DisableClientState(EnableCap.ColorArray);
143                    GL.Color4(shape.FillColor);
144                }
145                GL.DrawElements(BeginMode.LineStrip, indices.Length,
146                                DrawElementsType.UnsignedInt, (IntPtr)pIndices);
147            }
148
149        }
150
151    }
152}
Note: See TracBrowser for help on using the repository browser.