Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GaussianProcessTuning/ILNumerics.2.14.4735.573/Drawing/Platform/OpenGL/ILOGLVertexRendererC4bV3f.cs @ 10102

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

#1967: ILNumerics source for experimentation

File size: 7.0 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 ILOGLVertexRendererC4bV3f : ILVertexRenderer {
51
52        #region attributes
53        BeginMode m_primitiveType;
54        #endregion
55
56        #region properties
57        public BeginMode PrimitiveType {
58            get {
59                return m_primitiveType;
60            }
61            set {
62                m_primitiveType = value;
63            }
64        }
65        #endregion
66
67        public ILOGLVertexRendererC4bV3f (BeginMode primitiveType) {
68            m_primitiveType = primitiveType;
69        }
70        public override void Draw(ILRenderProperties props, ILShape shape) {
71            GL.Enable(EnableCap.Blend);
72            GL.BlendFunc (BlendingFactorSrc.SrcAlpha,
73                          BlendingFactorDest.OneMinusSrcAlpha);
74            GL.Enable(EnableCap.DepthTest);
75            //GL.Disable(EnableCap.PolygonOffsetFill);
76            GL.Disable(EnableCap.LineSmooth);
77            ILShape<C4bV3f> cShape = (shape as ILShape<C4bV3f>);
78            ILBorderedShape<C4bV3f> bShape = (shape as ILBorderedShape<C4bV3f>);
79            if (bShape != null && bShape.Border.Visible) {
80                fixed (C4bV3f* pVertices = bShape.Vertices) {
81                    ILOGLPanel.SetupLineStyle(bShape.Border);
82                    GL.InterleavedArrays(InterleavedArrayFormat.C4ubV3f, 0, (IntPtr)pVertices);
83                    GL.DisableClientState(EnableCap.ColorArray);
84                    if (CloseLines)
85                        GL.DrawArrays(BeginMode.LineLoop, 0, bShape.VertexCount);
86                    else
87                        GL.DrawArrays(BeginMode.LineStrip, 0, bShape.VertexCount);
88                }
89            }
90            if (cShape is ILLine) {
91                ILOGLPanel.SetupLineStyle((cShape as ILLine).Properties);
92                GL.Disable(EnableCap.DepthTest);
93            }
94            fixed (C4bV3f* pVertices = cShape.Vertices) {
95                GL.InterleavedArrays(InterleavedArrayFormat.C4ubV3f, 0, (IntPtr)pVertices);
96                if (cShape.Shading == ShadingStyles.Interpolate)
97                    GL.ShadeModel(ShadingModel.Smooth);
98                else {
99                    GL.ShadeModel(ShadingModel.Flat);
100                    GL.DisableClientState(EnableCap.ColorArray);
101                    GL.Color4(shape.FillColor); 
102                }
103                GL.DrawArrays(m_primitiveType, 0, cShape.VertexCount);
104            }
105
106        }
107        public override void Draw(ILRenderProperties props, ILShape shape, int[] indices) {
108            System.Diagnostics.Debug.Assert(indices != null);
109            GL.Enable(EnableCap.DepthTest);
110            GL.Disable(EnableCap.Blend);
111            ILBorderedShape<C4bV3f> bShape = (shape as ILBorderedShape<C4bV3f>);
112            if (bShape != null && bShape.Border.Visible) {
113                fixed (int* pIndices = indices)
114                fixed (C4bV3f* pVertices = bShape.Vertices) {
115                    ILOGLPanel.SetupLineStyle(bShape.Border);
116                    GL.InterleavedArrays(
117                                    InterleavedArrayFormat.C4ubV3f, 0, (IntPtr)pVertices);
118                    GL.DisableClientState(EnableCap.ColorArray);
119                    if (CloseLines)
120                        GL.DrawElements(BeginMode.LineLoop, indices.Length,
121                                    DrawElementsType.UnsignedInt, (IntPtr)pIndices);
122                    else
123                        GL.DrawElements(BeginMode.LineStrip, indices.Length,
124                                    DrawElementsType.UnsignedInt, (IntPtr)pIndices);
125                }
126            }
127           
128            GL.Enable(EnableCap.Blend);
129            GL.BlendFunc (BlendingFactorSrc.SrcAlpha,
130                          BlendingFactorDest.OneMinusSrcAlpha);
131            ILShape<C4bV3f> cShape = (shape as ILShape<C4bV3f>);
132            if (cShape is ILLine) {
133                ILOGLPanel.SetupLineStyle((cShape as ILLine).Properties);
134                GL.Disable(EnableCap.DepthTest);
135            } else {
136                GL.Disable(EnableCap.LineSmooth);
137            }
138            fixed (int* pIndices = indices)
139            fixed (C4bV3f* pVertices = cShape.Vertices) {
140                GL.InterleavedArrays(InterleavedArrayFormat.C4ubV3f, 0, (IntPtr)pVertices);
141                if (cShape.Shading == ShadingStyles.Interpolate)
142                    GL.ShadeModel(ShadingModel.Smooth);
143                else {
144                    GL.ShadeModel(ShadingModel.Flat);
145                    GL.DisableClientState(EnableCap.ColorArray);
146                    GL.Color4(shape.FillColor);
147                }
148                GL.DrawElements(m_primitiveType, indices.Length,
149                                DrawElementsType.UnsignedInt, (IntPtr)pIndices);
150            }
151
152        }
153
154    }
155}
Note: See TracBrowser for help on using the repository browser.