1 //////////////////////////////////////////////////////////////////////////////////////////
3 // functions to set up a pbuffer
4 // Downloaded from: www.paulsprojects.net
5 // Created: 9th September 2002
7 // Copyright (c) 2006, Paul Baker
8 // Distributed under the New BSD Licence. (See accompanying file License.txt or copy at
9 // http://www.paulsprojects.net/NewBSDLicense.txt)
10 //////////////////////////////////////////////////////////////////////////////////////////
21 bool PBUFFER::Init( int newWidth
, int newHeight
,
22 int newColorBits
, int newDepthBits
, int newStencilBits
,
23 int numExtraIAttribs
, int * extraIAttribList
, int * flags
)
25 //Check for pbuffer support
26 if( !WGLEW_ARB_extensions_string
||
27 !WGLEW_ARB_pixel_format
||
30 errorLog
.OutputError("Extension required for pbuffer unsupported");
34 //set class's member variables
37 colorBits
=newColorBits
;
38 depthBits
=newDepthBits
;
39 stencilBits
=newStencilBits
;
41 //Get the current device context
42 HDC hCurrentDC
=wglGetCurrentDC();
45 errorLog
.OutputError("Unable to get current Device Context");
53 const int standardIAttribList
[]={ WGL_DRAW_TO_PBUFFER_ARB
, 1,
54 WGL_COLOR_BITS_ARB
, colorBits
,
55 WGL_ALPHA_BITS_ARB
, colorBits
==32 ? 8 : 0,
56 WGL_DEPTH_BITS_ARB
, depthBits
,
57 WGL_STENCIL_BITS_ARB
, stencilBits
};
58 const float fAttribList
[]={
61 //add the extraIAttribList to the standardIAttribList
62 int * iAttribList
=new int[sizeof(standardIAttribList
)/sizeof(int)+numExtraIAttribs
*2+1];
65 errorLog
.OutputError("Unable to allocate space for iAttribList");
69 memcpy( iAttribList
, standardIAttribList
, sizeof(standardIAttribList
));
70 memcpy( iAttribList
+sizeof(standardIAttribList
)/sizeof(int),
71 extraIAttribList
, numExtraIAttribs
*2*sizeof(int)+sizeof(int));
74 unsigned int numFormats
;
75 if(!wglChoosePixelFormatARB(hCurrentDC
, iAttribList
, fAttribList
, 1,
76 &pixelFormat
, &numFormats
))
78 errorLog
.OutputError("Unable to find a pixel format for the pbuffer");
83 hBuffer
=wglCreatePbufferARB(hCurrentDC
, pixelFormat
, width
, height
, flags
);
86 errorLog
.OutputError("Unable to create pbuffer");
90 //Get the pbuffer's device context
91 hDC
=wglGetPbufferDCARB(hBuffer
);
94 errorLog
.OutputError("Unable to get pbuffer's device context");
98 //Create a rendering context for the pbuffer
99 hRC
=wglCreateContext(hDC
);
102 errorLog
.OutputError("Unable to create pbuffer's rendering context");
106 //Set and output the actual pBuffer dimensions
107 wglQueryPbufferARB(hBuffer
, WGL_PBUFFER_WIDTH_ARB
, &width
);
108 wglQueryPbufferARB(hBuffer
, WGL_PBUFFER_HEIGHT_ARB
, &height
);
109 errorLog
.OutputSuccess("Pbuffer Created: (%d x %d)", width
, height
);
111 return TRUE
; //success!
114 void PBUFFER::Shutdown(void)
116 if(hRC
) //have a rendering context?
118 if(!wglDeleteContext(hRC
)) //try to delete RC
120 errorLog
.OutputError("Release of Pbuffer Rendering Context Failed.");
123 hRC
=NULL
; //set RC to NULL
126 if(hDC
&& !wglReleasePbufferDCARB(hBuffer
, hDC
)) //Are we able to release DC?
128 errorLog
.OutputError("Release of Pbuffer Device Context Failed.");
132 if(!wglDestroyPbufferARB(hBuffer
))
134 errorLog
.OutputError("Unable to destroy pbuffer");
139 bool PBUFFER::MakeCurrent()
141 if(!wglMakeCurrent(hDC
, hRC
))
143 errorLog
.OutputError("Unable to change current context");