Panda3D

graphicsBuffer.cxx

00001 // Filename: graphicsBuffer.cxx
00002 // Created by:  drose (06Feb04)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "graphicsBuffer.h"
00016 
00017 TypeHandle GraphicsBuffer::_type_handle;
00018 
00019 ////////////////////////////////////////////////////////////////////
00020 //     Function: GraphicsBuffer::Constructor
00021 //       Access: Protected
00022 //  Description: Normally, the GraphicsBuffer constructor is not
00023 //               called directly; these are created instead via the
00024 //               GraphicsEngine::make_buffer() function.
00025 ////////////////////////////////////////////////////////////////////
00026 GraphicsBuffer::
00027 GraphicsBuffer(GraphicsEngine *engine, GraphicsPipe *pipe,
00028                const string &name,
00029                const FrameBufferProperties &fb_prop,
00030                const WindowProperties &win_prop, int flags,
00031                GraphicsStateGuardian *gsg,
00032                GraphicsOutput *host) :
00033   GraphicsOutput(engine, pipe, name, fb_prop, win_prop, flags, gsg, host, false)
00034 {
00035 #ifdef DO_MEMORY_USAGE
00036   MemoryUsage::update_type(this, this);
00037 #endif
00038 
00039   if (display_cat.is_debug()) {
00040     display_cat.debug()
00041       << "Creating new offscreen buffer " << get_name() << "\n";
00042   }
00043 
00044   _overlay_display_region->compute_pixels(_x_size, _y_size);
00045   _open_request = OR_none;
00046 }
00047 
00048 ////////////////////////////////////////////////////////////////////
00049 //     Function: GraphicsBuffer::Destructor
00050 //       Access: Published, Virtual
00051 //  Description: 
00052 ////////////////////////////////////////////////////////////////////
00053 GraphicsBuffer::
00054 ~GraphicsBuffer() {
00055 }
00056  
00057 ////////////////////////////////////////////////////////////////////
00058 //     Function: GraphicsBuffer::set_size
00059 //       Access: Public, Virtual
00060 //  Description: This is called by the GraphicsEngine to request that
00061 //               the buffer resize itself.  Although calls to get the
00062 //               size will return the new value, much of the actual
00063 //               resizing work doesn't take place until the next
00064 //               begin_frame.  Not all buffers are resizeable.
00065 ////////////////////////////////////////////////////////////////////
00066 void GraphicsBuffer::
00067 set_size(int x, int y) {
00068   if ((_creation_flags & GraphicsPipe::BF_resizeable) == 0) {
00069     nassert_raise("Cannot resize buffer unless it is created with BF_resizeable flag");
00070     return;
00071   }
00072   set_size_and_recalc(x, y);
00073 }
00074 
00075 ////////////////////////////////////////////////////////////////////
00076 //     Function: GraphicsBuffer::request_open
00077 //       Access: Public, Virtual
00078 //  Description: This is called by the GraphicsEngine to request that
00079 //               the buffer (or whatever) open itself or, in general,
00080 //               make itself valid, at the next call to
00081 //               process_events().
00082 ////////////////////////////////////////////////////////////////////
00083 void GraphicsBuffer::
00084 request_open() {
00085   _open_request = OR_open;
00086 }
00087 
00088 ////////////////////////////////////////////////////////////////////
00089 //     Function: GraphicsBuffer::request_close
00090 //       Access: Public, Virtual
00091 //  Description: This is called by the GraphicsEngine to request that
00092 //               the buffer (or whatever) close itself or, in general,
00093 //               make itself invalid, at the next call to
00094 //               process_events().  By that time we promise the gsg
00095 //               pointer will be cleared.
00096 ////////////////////////////////////////////////////////////////////
00097 void GraphicsBuffer::
00098 request_close() {
00099   _open_request = OR_none;
00100 }
00101  
00102 ////////////////////////////////////////////////////////////////////
00103 //     Function: GraphicsBuffer::set_close_now
00104 //       Access: Public, Virtual
00105 //  Description: This is called by the GraphicsEngine to insist that
00106 //               the buffer be closed immediately.  This is only
00107 //               called from the buffer thread.
00108 ////////////////////////////////////////////////////////////////////
00109 void GraphicsBuffer::
00110 set_close_now() {
00111   _open_request = OR_none;
00112   close_buffer();
00113 }
00114 
00115 ////////////////////////////////////////////////////////////////////
00116 //     Function: GraphicsBuffer::process_events
00117 //       Access: Public, Virtual
00118 //  Description: Honor any requests recently made via request_open()
00119 //               or request_close().
00120 //
00121 //               This function is called only within the window
00122 //               thread.
00123 ////////////////////////////////////////////////////////////////////
00124 void GraphicsBuffer::
00125 process_events() {
00126   // Save the current request and reset it immediately, in case we end
00127   // up calling recursively back into this function.
00128   OpenRequest this_request = _open_request;
00129   _open_request = OR_none;
00130 
00131   switch (this_request) {
00132   case OR_none:
00133     return;
00134 
00135   case OR_open:
00136     if (open_buffer()) {
00137       _is_valid = true;
00138       set_inverted(_gsg->get_copy_texture_inverted());
00139     }
00140     break;
00141 
00142   case OR_close:
00143     close_buffer();
00144     break;
00145   }
00146 }
00147 
00148 ////////////////////////////////////////////////////////////////////
00149 //     Function: GraphicsBuffer::close_buffer
00150 //       Access: Protected, Virtual
00151 //  Description: Closes the buffer right now.  Called from the window
00152 //               thread.
00153 ////////////////////////////////////////////////////////////////////
00154 void GraphicsBuffer::
00155 close_buffer() {
00156   display_cat.info()
00157     << "Closing " << get_type() << "\n";
00158 }
00159 
00160 ////////////////////////////////////////////////////////////////////
00161 //     Function: GraphicsBuffer::open_buffer
00162 //       Access: Protected, Virtual
00163 //  Description: Opens the buffer right now.  Called from the window
00164 //               thread.  Returns true if the buffer is successfully
00165 //               opened, or false if there was a problem.
00166 ////////////////////////////////////////////////////////////////////
00167 bool GraphicsBuffer::
00168 open_buffer() {
00169   return false;
00170 }
 All Classes Functions Variables Enumerations