Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
glfPBuffer_WGL.cpp
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2008, 2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10  BIAS is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 2.1 of the License, or
13  (at your option) any later version.
14 
15  BIAS is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with BIAS; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  */
24 
25 #include "glfPBuffer_WGL.hh"
26 #include <OpenGLFramework/Base/glfException.hh>
27 #include <Gui/biasgl.h>
28 
29 using namespace BIAS;
30 using namespace std;
31 
33 {
34  hglfPBuffer_ = NULL;
35 }
36 
38 {
39  BIASASSERT(hglfPBuffer_ == NULL);
40 }
41 
42 HDC glfPBuffer_WGL::CreateDeviceContext(int width, int height, int pixelFormat)
43 {
44  // check required extensions
45  if (!WGLEW_ARB_pbuffer) {
46  GLF_THROW_EXCEPTION("WGL_ARB_pbuffer extension is unsupported");
47  }
48 
49  // create pbuffer
50  int attribs[] = {
51  WGL_PBUFFER_LARGEST_ARB, 0,
52  0
53  };
54  hglfPBuffer_ = wglCreatePbufferARB(wglGetCurrentDC(), pixelFormat,
55  width, height, attribs);
56  if (hglfPBuffer_ == NULL) {
57  GLF_THROW_EXCEPTION("Failed to create glfPBuffer");
58  }
59 
60  // create device context for pbuffer
61  HDC hDC = wglGetPbufferDCARB(hglfPBuffer_);
62  if (hDC == NULL) {
63  GLF_THROW_EXCEPTION("Failed to get device context for pbuffer");
64  }
65 
66  return hDC;
67 }
68 
70 {
71  if (hDC_ != NULL) {
72  wglReleasePbufferDCARB(hglfPBuffer_, hDC_);
73  hDC_ = NULL;
74  }
75 
76  if (hglfPBuffer_ != NULL) {
77  wglDestroyPbufferARB(hglfPBuffer_);
78  hglfPBuffer_ = NULL;
79  }
80 }
81 
82 void glfPBuffer_WGL::GetSize(int& width, int& height)
83 {
84  BIASASSERT(hglfPBuffer_ != NULL);
85 
86  wglQueryPbufferARB(hglfPBuffer_, WGL_PBUFFER_WIDTH_ARB, &width);
87  wglQueryPbufferARB(hglfPBuffer_, WGL_PBUFFER_HEIGHT_ARB, &height);
88 }
89 
91 {
92  return WGL_DRAW_TO_PBUFFER_ARB;
93 }
virtual HDC CreateDeviceContext(int width, int height, int pixelFormat)
virtual int GetWglRenderTargetAttribute() const
virtual void DestroyDeviceContext()
virtual void GetSize(int &width, int &height)