Subversion Repositories AndroidProjects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1452 chris 1
#region --- License ---
2
/* Licensed under the MIT/X11 license.
3
 * Copyright (c) 2006-2008 the OpenTK Team.
4
 * This notice may not be removed from any source distribution.
5
 * See license.txt for licensing detailed licensing details.
6
 */
7
#endregion
8
 
9
using System;
10
using System.Collections.Generic;
11
using System.Text;
12
using System.Threading;
13
 
14
using OpenTK.Graphics;
15
 
16
namespace OpenTK.Platform.Dummy
17
{
18
    /// \internal
19
    /// <summary>
20
    /// An empty IGraphicsContext implementation to be used inside the Visual Studio designer.
21
    /// This class supports OpenTK, and is not intended for use by OpenTK programs.
22
    /// </summary>
23
    internal sealed class DummyGLContext : DesktopGraphicsContext
24
    {
25
        // This mode is not real. To receive a real mode we'd have to create a temporary context, which is not desirable!
26
        bool vsync;
27
        static int handle_count;
28
        Thread current_thread;
29
 
30
        #region --- Constructors ---
31
 
32
        public DummyGLContext()
33
            : this(new ContextHandle(new IntPtr(++handle_count)))
34
        {
35
            Mode = new GraphicsMode(new IntPtr(2), 32, 16, 0, 0, 0, 2, false);
36
        }
37
 
38
        public DummyGLContext(ContextHandle handle)
39
        {
40
            Handle = handle;
41
        }
42
 
43
        #endregion
44
 
45
        #region --- IGraphicsContext Members ---
46
 
47
        public void CreateContext(bool direct, IGraphicsContext source)
48
        {
49
            if (Handle == ContextHandle.Zero)
50
            {
51
                ++handle_count;
52
                Handle = new ContextHandle((IntPtr)handle_count);
53
            }
54
        }
55
 
56
        public override void SwapBuffers() { }
57
 
58
        public override void MakeCurrent(IWindowInfo info)
59
        {
60
            Thread new_thread = Thread.CurrentThread;
61
            // A context may be current only on one thread at a time.
62
            if (current_thread != null && new_thread != current_thread)
63
            {
64
                throw new GraphicsContextException(
65
                    "Cannot make context current on two threads at the same time");
66
            }
67
 
68
            if (info != null)
69
            {
70
                current_thread = Thread.CurrentThread;
71
            }
72
            else
73
            {
74
                current_thread = null;
75
            }
76
        }
77
 
78
        public override bool IsCurrent
79
        {
80
            get { return current_thread != null && current_thread == Thread.CurrentThread; }
81
        }
82
 
83
        public override IntPtr GetAddress(string function) { return IntPtr.Zero; }
84
 
85
        public override bool VSync { get { return vsync; } set { vsync = value; } }
86
 
87
        public override void Update(IWindowInfo window)
88
        { }
89
 
90
        public override void LoadAll()
91
        { }
92
 
93
        #endregion
94
 
95
        #region --- IDisposable Members ---
96
 
97
        public override void Dispose() { IsDisposed = true; }
98
 
99
        #endregion
100
    }
101
}