1 // BEGIN_COPYRIGHT -*- glean -*-
3 // Copyright (C) 1999 Allen Akin All Rights Reserved.
5 // Permission is hereby granted, free of charge, to any person
6 // obtaining a copy of this software and associated documentation
7 // files (the "Software"), to deal in the Software without
8 // restriction, including without limitation the rights to use,
9 // copy, modify, merge, publish, distribute, sublicense, and/or
10 // sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 // KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
21 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ALLEN AKIN BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 // AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 // OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 // DEALINGS IN THE SOFTWARE.
32 // rc.cpp: implementation of rendering context utilities
45 // wglCreateContext requires a handle to a device context.
46 // The ctor of RenderingContext doesn't know which window
47 // it is creating a surface for, only what the pixelformat
48 // of that window is. The hDC passed to wglCreateContext
49 // doesn't have to be the same as the one use in SwapBuffers
50 // or wglMakeCurrent, their pixelformats have to be the
51 // same though. A limitation is that the pixelformat of
52 // a window can only be set once. That is why a
53 // temporary window is created.
56 HGLRC
create_context(GLEAN::DrawingSurfaceConfig
&c
)
58 HWND hwnd
= CreateWindow("STATIC","temp",WS_POPUP
,
59 CW_USEDEFAULT
,CW_USEDEFAULT
,CW_USEDEFAULT
,CW_USEDEFAULT
,
60 0,0,GetModuleHandle(NULL
),0);
65 HDC hDC
= GetDC(hwnd
);
69 PIXELFORMATDESCRIPTOR pfd
;
71 if (!SetPixelFormat(hDC
,c
.pfdID
,&pfd
))
78 HGLRC rc
= wglCreateContext(hDC
);
90 } // anonymous namespace
95 ///////////////////////////////////////////////////////////////////////////////
97 ///////////////////////////////////////////////////////////////////////////////
98 RenderingContext::RenderingContext(WindowSystem
& ws
, DrawingSurfaceConfig
& c
,
99 RenderingContext
* share
, bool direct
) {
101 // Link back to enclosing window system, so as to simplify bookkeeping:
103 ws
.contexts
.push_back(this);
105 # if defined(__X11__)
107 # if defined(GLX_VERSION_1_3)
109 if (ws
.GLXVersMajor
== 1 && ws
.GLXVersMinor
< 3)
111 // XXX Need GLX 1.3 rc constructor code
112 // For now, just fall through.
117 // Create the rendering context:
118 rc
= glXCreateContext(winSys
->dpy
, c
.vi
, (share
? share
->rc
: 0),
119 direct
? True
: False
);
122 // XXX Ideally, we would deal with X11 and GLX errors here, too
123 // (Badmatch, BadValue, GLXBadContext, BadAlloc)
125 # elif defined(__WIN__)
127 rc
= create_context(c
);
130 # elif defined(__AGL__)
131 rc
= aglCreateContext(c
.pf
, NULL
);
136 } // RenderingContext::RenderingContext
138 ///////////////////////////////////////////////////////////////////////////////
140 ///////////////////////////////////////////////////////////////////////////////
142 RenderingContext::~RenderingContext() {
143 remove(winSys
->contexts
.begin(), winSys
->contexts
.end(), this);
144 # if defined(__X11__)
145 # if defined(GLX_VERSION_1_3)
146 if (winSys
->GLXVersMajor
== 1 && winSys
->GLXVersMinor
< 3)
148 // XXX Need to write GLX 1.3 rc destructor
149 // For now, just fall through.
152 glXDestroyContext(winSys
->dpy
, rc
);
153 # elif defined(__WIN__)
154 wglDeleteContext(rc
);
156 } // RenderingContext::~RenderingContext