15 #include "wglGraphicsBuffer.h" 16 #include "wglGraphicsPipe.h" 17 #include "config_wgldisplay.h" 19 #include "pStatTimer.h" 39 GraphicsBuffer(engine, pipe, name, fb_prop, win_prop, flags, gsg, host)
41 _pbuffer = (HPBUFFERARB)0;
47 _screenshot_buffer_type = _draw_buffer_type;
56 ~wglGraphicsBuffer() {
71 begin_frame_spam(mode);
77 DCAST_INTO_R(wglgsg, _gsg,
false);
85 if (_fb_properties.is_single_buffered()) {
86 wglgsg->_wglReleaseTexImageARB(_pbuffer, WGL_FRONT_LEFT_ARB);
88 wglgsg->_wglReleaseTexImageARB(_pbuffer, WGL_BACK_LEFT_ARB);
92 if (!rebuild_bitplanes()) {
93 wglGraphicsPipe::wgl_make_current(0, 0, &_make_current_pcollector);
97 wglGraphicsPipe::wgl_make_current(_pbuffer_dc, context,
98 &_make_current_pcollector);
100 if (mode == FM_render) {
102 for (
size_t i = 0; i != cdata->_textures.size(); ++i) {
103 const RenderTexture &rt = cdata->_textures[i];
104 RenderTextureMode rtm_mode = rt._rtm_mode;
105 RenderTexturePlane plane = rt._plane;
106 if (rtm_mode == RTM_bind_or_copy && plane != RTP_color) {
107 CDWriter cdataw(_cycler, cdata,
false);
108 nassertr(cdata->_textures.size() == cdataw->_textures.size(),
false);
109 cdataw->_textures[i]._rtm_mode = RTM_copy_texture;
112 clear_cube_map_selection();
116 return _gsg->begin_frame(current_thread);
128 end_frame_spam(mode);
131 if (mode == FM_render) {
133 bind_texture_to_pbuffer();
136 _gsg->end_frame(current_thread);
138 if (mode == FM_render) {
140 clear_cube_map_selection();
150 void wglGraphicsBuffer::
151 bind_texture_to_pbuffer() {
153 DCAST_INTO_V(wglgsg, _gsg);
160 for (
size_t i = 0; i != cdata->_textures.size(); ++i) {
161 const RenderTexture &rt = cdata->_textures[i];
162 RenderTexturePlane plane = rt._plane;
163 if (plane == RTP_color && rt._rtm_mode == RTM_bind_or_copy) {
169 if (tex_index >= 0) {
170 const RenderTexture &rt = cdata->_textures[tex_index];
172 if ((_pbuffer_bound != 0)&&(_pbuffer_bound != tex)) {
173 _pbuffer_bound->
release(wglgsg->get_prepared_objects());
179 if (_fb_properties.get_alpha_bits()) {
189 if (target == GL_NONE) {
190 CDWriter cdataw(_cycler, cdata,
false);
191 nassertv(cdata->_textures.size() == cdataw->_textures.size());
192 cdataw->_textures[tex_index]._rtm_mode = RTM_copy_texture;
195 GLP(BindTexture)(target, gtc->_index);
196 if (_fb_properties.is_single_buffered()) {
197 wglgsg->_wglBindTexImageARB(_pbuffer, WGL_FRONT_LEFT_ARB);
199 wglgsg->_wglBindTexImageARB(_pbuffer, WGL_BACK_LEFT_ARB);
201 _pbuffer_bound = tex;
203 if (_pbuffer_bound != 0) {
204 _pbuffer_bound->
release(wglgsg->get_prepared_objects());
222 DCAST_INTO_V(wglgsg, _gsg);
224 nassertv(wglgsg->_wglSetPbufferAttribARB != NULL);
226 static const int max_attrib_list = 64;
227 int iattrib_list[max_attrib_list];
230 iattrib_list[ni++] = WGL_CUBE_MAP_FACE_ARB;
231 iattrib_list[ni++] = WGL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB + page;
234 nassertv(ni <= max_attrib_list);
235 iattrib_list[ni] = 0;
237 wglgsg->_wglSetPbufferAttribARB(_pbuffer, iattrib_list);
259 while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
279 DCAST_INTO_R(wglgsg, _gsg,
false);
289 void wglGraphicsBuffer::
293 DCAST_INTO_V(wglgsg, _gsg);
310 bool wglGraphicsBuffer::
317 _fb_properties.set_back_buffers(0);
318 _draw_buffer_type = RenderBuffer::T_front;
319 _screenshot_buffer_type = RenderBuffer::T_front;
332 DCAST_INTO_R(wglgsg, _gsg,
false);
345 if (twindow_dc == 0) {
355 wglGraphicsPipe::wgl_make_current(twindow_dc, context,
356 &_make_current_pcollector);
357 wglgsg->reset_if_new();
358 wglgsg->report_my_gl_errors();
360 (_fb_properties,wglgsg->get_gl_renderer())) {
370 if (!rebuild_bitplanes()) {
371 wglGraphicsPipe::wgl_make_current(0, 0, &_make_current_pcollector);
388 void wglGraphicsBuffer::
395 DCAST_INTO_V(wglgsg, _gsg);
397 if (_pbuffer_bound != 0) {
398 _pbuffer_bound->release(wglgsg->get_prepared_objects());
401 wglGraphicsPipe::wgl_make_current(0, 0, NULL);
403 wglgsg->_wglReleasePbufferDCARB(_pbuffer, _pbuffer_dc);
406 wglgsg->_wglDestroyPbufferARB(_pbuffer);
408 _pbuffer = (HPBUFFERARB)0;
409 _pbuffer_dc = (HDC)0;
410 _pbuffer_mipmap =
false;
413 _pbuffer_type = Texture::TT_2d_texture;
424 bool wglGraphicsBuffer::
425 rebuild_bitplanes() {
427 DCAST_INTO_R(wglgsg, _gsg,
false);
429 if (!wglgsg->_supports_pbuffer) {
430 wgldisplay_cat.info()
431 <<
"PBuffers not supported by GL implementation.\n";
450 wglgsg->_wglQueryPbufferARB(_pbuffer, WGL_PBUFFER_LOST_ARB, &flag);
459 if ((_host != 0)&&(_creation_flags & GraphicsPipe::BF_size_track_host)) {
460 if (_host->get_size() != _size) {
462 _host->get_y_size());
471 bool desired_mipmap =
false;
472 Texture::TextureType desired_type = Texture::TT_2d_texture;
473 if (bindtexture != 0) {
478 if ((_pbuffer != 0)&&
479 (_pbuffer_sizex == desired_x)&&
480 (_pbuffer_sizey == desired_y)&&
481 (_pbuffer_mipmap == desired_mipmap)&&
482 (_pbuffer_type == desired_type)) {
495 static const int max_attrib_list = 64;
496 int iattrib_list[max_attrib_list];
499 if (_fb_properties.get_alpha_bits()) {
500 iattrib_list[ni++] = WGL_TEXTURE_FORMAT_ARB;
501 iattrib_list[ni++] = WGL_TEXTURE_RGBA_ARB;
503 iattrib_list[ni++] = WGL_TEXTURE_FORMAT_ARB;
504 iattrib_list[ni++] = WGL_TEXTURE_RGB_ARB;
507 if (desired_mipmap) {
508 iattrib_list[ni++] = WGL_MIPMAP_TEXTURE_ARB;
509 iattrib_list[ni++] = 1;
512 switch (desired_type) {
513 case Texture::TT_cube_map:
514 iattrib_list[ni++] = WGL_TEXTURE_TARGET_ARB;
515 iattrib_list[ni++] = WGL_TEXTURE_CUBE_MAP_ARB;
518 case Texture::TT_1d_texture:
519 iattrib_list[ni++] = WGL_TEXTURE_TARGET_ARB;
520 iattrib_list[ni++] = WGL_TEXTURE_1D_ARB;
524 iattrib_list[ni++] = WGL_TEXTURE_TARGET_ARB;
525 iattrib_list[ni++] = WGL_TEXTURE_2D_ARB;
529 nassertr(ni <= max_attrib_list,
false);
530 iattrib_list[ni] = 0;
533 if (twindow_dc == 0) {
541 wglGraphicsPipe::wgl_make_current(twindow_dc, context,
542 &_make_current_pcollector);
544 _pbuffer = wglgsg->_wglCreatePbufferARB(twindow_dc, pfnum,
545 desired_x, desired_y, iattrib_list);
548 wgldisplay_cat.info()
549 <<
"Attempt to create pbuffer failed.\n";
553 _pbuffer_dc = wglgsg->_wglGetPbufferDCARB(_pbuffer);
554 _pbuffer_mipmap = desired_mipmap;
555 _pbuffer_type = desired_type;
556 _pbuffer_sizex = desired_x;
557 _pbuffer_sizey = desired_y;
567 void wglGraphicsBuffer::
571 if (!GetMessage(&msg, NULL, 0, 0)) {
578 TranslateMessage(&msg);
580 DispatchMessage(&msg);
virtual bool begin_frame(FrameMode mode, Thread *current_thread)
This function will be called within the draw thread before beginning rendering for a given frame...
Format get_format() const
Returns the format of the texture, which represents both the semantic meaning of the texels and...
HDC get_twindow_dc()
Returns the DC associated with the temporary, invisible window that was created with the gsg to query...
int get_pfnum() const
Returns the pixel format number chosen for windows that use this context.
void set_size_and_recalc(int x, int y)
Changes the x_size and y_size, then recalculates structures that depend on size.
virtual void end_frame(FrameMode mode, Thread *current_thread)
This function will be called within the draw thread after rendering is completed for a given frame...
virtual Texture * get_texture(int i=0) const
Returns the nth texture into which the GraphicsOutput renders.
TextureType get_texture_type() const
Returns the overall interpretation of the texture.
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
int get_y_size() const
Returns the visible height of the window or buffer, if it is known.
void set_format(Format format)
Changes the format value for the texture components.
This is a special class object that holds all the information returned by a particular GSG to indicat...
A tiny specialization on GLGraphicsStateGuardian to add some wgl-specific information.
bool get_match_framebuffer_format() const
Returns true if the special flag was set that indicates to the GSG that the Texture's format should b...
bool release(PreparedGraphicsObjects *prepared_objects)
Frees the texture context only on the indicated object, if it exists there.
virtual void process_events()
Honor any requests recently made via request_open() or request_close().
void set_size_padded(int x=1, int y=1, int z=1)
Changes the size of the texture, padding if necessary, and setting the pad region as well...
static AutoTextureScale get_textures_power_2()
This flag returns ATS_none, ATS_up, or ATS_down and controls the scaling of textures in general...
A container for the various kinds of properties we might ask to have on a graphics window before we o...
bool uses_mipmaps() const
Returns true if the minfilter settings on this texture indicate the use of mipmapping, false otherwise.
bool get_supports_wgl_render_texture() const
Returns true if this particular GSG can render from a wglGraphicsBuffer directly into a texture...
An offscreen buffer for rendering into.
HGLRC get_context(HDC hdc)
Returns the GL context associated with the GSG.
void choose_pixel_format(const FrameBufferProperties &properties, bool need_pbuffer)
Selects a pixel format for all the windows and buffers that use this gsg.
virtual void process_events()
Do whatever processing is necessary to ensure that the window responds to user events.
An object to create GraphicsOutputs that share a particular 3-D API.
This template class calls PipelineCycler::read() in the constructor and PipelineCycler::release_read(...
bool verify_hardware_software(const FrameBufferProperties &props, const string &renderer) const
Validates that the properties represent the desired kind of renderer (hardware or software)...
int count_textures() const
If the GraphicsOutput is set to render into a texture, returns the number of textures that are being ...
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
This is a base class for the various different classes that represent the result of a frame of render...
int get_x_size() const
Returns the visible width of the window or buffer, if it is known.
TextureContext * prepare_now(int view, PreparedGraphicsObjects *prepared_objects, GraphicsStateGuardianBase *gsg)
Creates a context for the texture on the particular GSG, if it does not already exist.
const FrameBufferProperties & get_fb_properties() const
Returns the properties of the pixel format that was chosen for this gsg.
static int up_to_power_2(int value)
Returns the smallest power of 2 greater than or equal to value.
A thread; that is, a lightweight process.
RenderTextureMode get_rtm_mode(int i=0) const
Returns the RenderTextureMode associated with the nth render-texture.
bool pfnum_supports_pbuffer() const
Returns true if the gsg's pixel format is capable of supporting a pbuffer.
Encapsulates all the communication with a particular instance of a given rendering backend...
virtual void select_target_tex_page(int page)
Called internally when the window is in render-to-a-texture mode and we are in the process of renderi...
bool subsumes(const FrameBufferProperties &other) const
Returns true if this set of properties makes strictly greater or equal demands of the framebuffer tha...
This class is the main interface to controlling the render process.
TypeHandle is the identifier used to differentiate C++ class types.
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
virtual bool get_supports_render_texture() const
Returns true if this particular GraphicsOutput can render directly into a texture, or false if it must always copy-to-texture at the end of each frame to achieve this effect.
const FrameBufferProperties & get_fb_properties() const
Returns the framebuffer properties of the window.