31 const std::string &name,
37 GraphicsBuffer(engine, pipe, name, fb_prop, win_prop, flags, gsg, host)
39 _pbuffer = (HPBUFFERARB)0;
45 _screenshot_buffer_type = _draw_buffer_type;
52 ~wglGraphicsBuffer() {
64 begin_frame_spam(mode);
65 if (_gsg ==
nullptr) {
70 DCAST_INTO_R(wglgsg, _gsg,
false);
78 if (_fb_properties.is_single_buffered()) {
79 wglgsg->_wglReleaseTexImageARB(_pbuffer, WGL_FRONT_LEFT_ARB);
81 wglgsg->_wglReleaseTexImageARB(_pbuffer, WGL_BACK_LEFT_ARB);
85 if (!rebuild_bitplanes()) {
86 wglGraphicsPipe::wgl_make_current(0, 0, &_make_current_pcollector);
90 wglGraphicsPipe::wgl_make_current(_pbuffer_dc, context,
91 &_make_current_pcollector);
93 if (mode == FM_render) {
95 for (
size_t i = 0; i != cdata->_textures.size(); ++i) {
96 const RenderTexture &rt = cdata->_textures[i];
97 RenderTextureMode rtm_mode = rt._rtm_mode;
98 RenderTexturePlane plane = rt._plane;
99 if (rtm_mode == RTM_bind_or_copy && plane != RTP_color) {
100 CDWriter cdataw(_cycler, cdata,
false);
101 nassertr(cdata->_textures.size() == cdataw->_textures.size(),
false);
102 cdataw->_textures[i]._rtm_mode = RTM_copy_texture;
105 clear_cube_map_selection();
109 return _gsg->begin_frame(current_thread);
119 end_frame_spam(mode);
120 nassertv(_gsg !=
nullptr);
122 if (mode == FM_render) {
124 bind_texture_to_pbuffer();
127 _gsg->end_frame(current_thread);
129 if (mode == FM_render) {
131 clear_cube_map_selection();
138 void wglGraphicsBuffer::
139 bind_texture_to_pbuffer() {
141 DCAST_INTO_V(wglgsg, _gsg);
147 CDLockedReader cdata(_cycler);
148 for (
size_t i = 0; i != cdata->_textures.size(); ++i) {
149 const RenderTexture &rt = cdata->_textures[i];
150 RenderTexturePlane plane = rt._plane;
151 if (plane == RTP_color && rt._rtm_mode == RTM_bind_or_copy) {
157 if (tex_index >= 0) {
158 const RenderTexture &rt = cdata->_textures[tex_index];
160 if ((_pbuffer_bound != 0)&&(_pbuffer_bound != tex)) {
161 _pbuffer_bound->
release(wglgsg->get_prepared_objects());
167 if (_fb_properties.get_alpha_bits()) {
174 nassertv(tc !=
nullptr);
177 if (target == GL_NONE) {
178 CDWriter cdataw(_cycler, cdata,
false);
179 nassertv(cdata->_textures.size() == cdataw->_textures.size());
180 cdataw->_textures[tex_index]._rtm_mode = RTM_copy_texture;
183 GLP(BindTexture)(target, gtc->_index);
184 if (_fb_properties.is_single_buffered()) {
185 wglgsg->_wglBindTexImageARB(_pbuffer, WGL_FRONT_LEFT_ARB);
187 wglgsg->_wglBindTexImageARB(_pbuffer, WGL_BACK_LEFT_ARB);
189 _pbuffer_bound = tex;
191 if (_pbuffer_bound != 0) {
192 _pbuffer_bound->
release(wglgsg->get_prepared_objects());
206 DCAST_INTO_V(wglgsg, _gsg);
208 nassertv(wglgsg->_wglSetPbufferAttribARB !=
nullptr);
210 static const int max_attrib_list = 64;
211 int iattrib_list[max_attrib_list];
214 iattrib_list[ni++] = WGL_CUBE_MAP_FACE_ARB;
215 iattrib_list[ni++] = WGL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB + page;
218 nassertv(ni <= max_attrib_list);
219 iattrib_list[ni] = 0;
221 wglgsg->_wglSetPbufferAttribARB(_pbuffer, iattrib_list);
239 while (PeekMessage(&msg,
nullptr, 0, 0, PM_NOREMOVE)) {
251 if (_gsg ==
nullptr) {
256 DCAST_INTO_R(wglgsg, _gsg,
false);
263 void wglGraphicsBuffer::
265 if (_gsg !=
nullptr) {
267 DCAST_INTO_V(wglgsg, _gsg);
281 bool wglGraphicsBuffer::
288 _fb_properties.set_back_buffers(0);
289 _draw_buffer_type = RenderBuffer::T_front;
290 _screenshot_buffer_type = RenderBuffer::T_front;
303 DCAST_INTO_R(wglgsg, _gsg,
false);
316 if (twindow_dc == 0) {
326 wglGraphicsPipe::wgl_make_current(twindow_dc, context,
327 &_make_current_pcollector);
328 wglgsg->reset_if_new();
329 wglgsg->report_my_gl_errors();
331 (_fb_properties,wglgsg->get_gl_renderer())) {
341 if (!rebuild_bitplanes()) {
342 wglGraphicsPipe::wgl_make_current(0, 0, &_make_current_pcollector);
356 void wglGraphicsBuffer::
363 DCAST_INTO_V(wglgsg, _gsg);
365 if (_pbuffer_bound != 0) {
366 _pbuffer_bound->release(wglgsg->get_prepared_objects());
369 wglGraphicsPipe::wgl_make_current(0, 0,
nullptr);
371 wglgsg->_wglReleasePbufferDCARB(_pbuffer, _pbuffer_dc);
374 wglgsg->_wglDestroyPbufferARB(_pbuffer);
376 _pbuffer = (HPBUFFERARB)0;
377 _pbuffer_dc = (HDC)0;
378 _pbuffer_mipmap =
false;
381 _pbuffer_type = Texture::TT_2d_texture;
389 bool wglGraphicsBuffer::
390 rebuild_bitplanes() {
392 DCAST_INTO_R(wglgsg, _gsg,
false);
394 if (!wglgsg->_supports_pbuffer) {
395 wgldisplay_cat.info()
396 <<
"PBuffers not supported by GL implementation.\n";
401 Texture *bindtexture =
nullptr;
414 wglgsg->_wglQueryPbufferARB(_pbuffer, WGL_PBUFFER_LOST_ARB, &flag);
423 if ((_host != 0)&&(_creation_flags & GraphicsPipe::BF_size_track_host)) {
424 if (_host->get_size() != _size) {
426 _host->get_y_size());
435 bool desired_mipmap =
false;
436 Texture::TextureType desired_type = Texture::TT_2d_texture;
437 if (bindtexture != 0) {
442 if ((_pbuffer != 0)&&
443 (_pbuffer_sizex == desired_x)&&
444 (_pbuffer_sizey == desired_y)&&
445 (_pbuffer_mipmap == desired_mipmap)&&
446 (_pbuffer_type == desired_type)) {
459 static const int max_attrib_list = 64;
460 int iattrib_list[max_attrib_list];
463 if (_fb_properties.get_alpha_bits()) {
464 iattrib_list[ni++] = WGL_TEXTURE_FORMAT_ARB;
465 iattrib_list[ni++] = WGL_TEXTURE_RGBA_ARB;
467 iattrib_list[ni++] = WGL_TEXTURE_FORMAT_ARB;
468 iattrib_list[ni++] = WGL_TEXTURE_RGB_ARB;
471 if (desired_mipmap) {
472 iattrib_list[ni++] = WGL_MIPMAP_TEXTURE_ARB;
473 iattrib_list[ni++] = 1;
476 switch (desired_type) {
477 case Texture::TT_cube_map:
478 iattrib_list[ni++] = WGL_TEXTURE_TARGET_ARB;
479 iattrib_list[ni++] = WGL_TEXTURE_CUBE_MAP_ARB;
482 case Texture::TT_1d_texture:
483 iattrib_list[ni++] = WGL_TEXTURE_TARGET_ARB;
484 iattrib_list[ni++] = WGL_TEXTURE_1D_ARB;
488 iattrib_list[ni++] = WGL_TEXTURE_TARGET_ARB;
489 iattrib_list[ni++] = WGL_TEXTURE_2D_ARB;
493 nassertr(ni <= max_attrib_list,
false);
494 iattrib_list[ni] = 0;
497 if (twindow_dc == 0) {
505 wglGraphicsPipe::wgl_make_current(twindow_dc, context,
506 &_make_current_pcollector);
508 _pbuffer = wglgsg->_wglCreatePbufferARB(twindow_dc, pfnum,
509 desired_x, desired_y, iattrib_list);
512 wgldisplay_cat.info()
513 <<
"Attempt to create pbuffer failed.\n";
517 _pbuffer_dc = wglgsg->_wglGetPbufferDCARB(_pbuffer);
518 _pbuffer_mipmap = desired_mipmap;
519 _pbuffer_type = desired_type;
520 _pbuffer_sizex = desired_x;
521 _pbuffer_sizey = desired_y;
529 void wglGraphicsBuffer::
533 if (!GetMessage(&msg,
nullptr, 0, 0)) {
540 TranslateMessage(&msg);
542 DispatchMessage(&msg);