Panda3D
|
00001 // Filename: osMesaGraphicsBuffer.cxx 00002 // Created by: drose (09Feb04) 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 "osMesaGraphicsBuffer.h" 00016 #include "config_mesadisplay.h" 00017 #include "osMesaGraphicsPipe.h" 00018 #include "osMesaGraphicsStateGuardian.h" 00019 00020 TypeHandle OsMesaGraphicsBuffer::_type_handle; 00021 00022 //////////////////////////////////////////////////////////////////// 00023 // Function: OsMesaGraphicsBuffer::Constructor 00024 // Access: Public 00025 // Description: 00026 //////////////////////////////////////////////////////////////////// 00027 OsMesaGraphicsBuffer:: 00028 OsMesaGraphicsBuffer(GraphicsEngine *engine, GraphicsPipe *pipe, 00029 const string &name, 00030 const FrameBufferProperties &fb_prop, 00031 const WindowProperties &win_prop, 00032 int flags, 00033 GraphicsStateGuardian *gsg, 00034 GraphicsOutput *host) : 00035 GraphicsBuffer(engine, pipe, name, fb_prop, win_prop, flags, gsg, host) 00036 { 00037 _type = GL_UNSIGNED_BYTE; 00038 _screenshot_buffer_type = _draw_buffer_type; 00039 } 00040 00041 //////////////////////////////////////////////////////////////////// 00042 // Function: OsMesaGraphicsBuffer::Destructor 00043 // Access: Public, Virtual 00044 // Description: 00045 //////////////////////////////////////////////////////////////////// 00046 OsMesaGraphicsBuffer:: 00047 ~OsMesaGraphicsBuffer() { 00048 } 00049 00050 //////////////////////////////////////////////////////////////////// 00051 // Function: OsMesaGraphicsBuffer::begin_frame 00052 // Access: Public, Virtual 00053 // Description: This function will be called within the draw thread 00054 // before beginning rendering for a given frame. It 00055 // should do whatever setup is required, and return true 00056 // if the frame should be rendered, or false if it 00057 // should be skipped. 00058 //////////////////////////////////////////////////////////////////// 00059 bool OsMesaGraphicsBuffer:: 00060 begin_frame(FrameMode mode, Thread *current_thread) { 00061 begin_frame_spam(mode); 00062 if (_gsg == (GraphicsStateGuardian *)NULL) { 00063 return false; 00064 } 00065 00066 OSMesaGraphicsStateGuardian *mesagsg; 00067 DCAST_INTO_R(mesagsg, _gsg, false); 00068 OSMesaMakeCurrent(mesagsg->_context, _image.p(), _type, 00069 _x_size, _y_size); 00070 00071 mesagsg->reset_if_new(); 00072 00073 if (mode == FM_render) { 00074 for (int i=0; i<count_textures(); i++) { 00075 if (get_rtm_mode(i) == RTM_bind_or_copy) { 00076 _textures[i]._rtm_mode = RTM_copy_texture; 00077 } 00078 } 00079 clear_cube_map_selection(); 00080 } 00081 _gsg->set_current_properties(&get_fb_properties()); 00082 return _gsg->begin_frame(current_thread); 00083 } 00084 00085 //////////////////////////////////////////////////////////////////// 00086 // Function: OsMesaGraphicsBuffer::end_frame 00087 // Access: Public, Virtual 00088 // Description: This function will be called within the draw thread 00089 // after rendering is completed for a given frame. It 00090 // should do whatever finalization is required. 00091 //////////////////////////////////////////////////////////////////// 00092 void OsMesaGraphicsBuffer:: 00093 end_frame(FrameMode mode, Thread *current_thread) { 00094 end_frame_spam(mode); 00095 nassertv(_gsg != (GraphicsStateGuardian *)NULL); 00096 00097 if (mode == FM_render) { 00098 copy_to_textures(); 00099 } 00100 00101 _gsg->end_frame(current_thread); 00102 00103 if (mode == FM_render) { 00104 trigger_flip(); 00105 if (_one_shot) { 00106 prepare_for_deletion(); 00107 } 00108 clear_cube_map_selection(); 00109 } 00110 } 00111 00112 //////////////////////////////////////////////////////////////////// 00113 // Function: OsMesaGraphicsBuffer::close_buffer 00114 // Access: Protected, Virtual 00115 // Description: Closes the buffer right now. Called from the window 00116 // thread. 00117 //////////////////////////////////////////////////////////////////// 00118 void OsMesaGraphicsBuffer:: 00119 close_buffer() { 00120 _image.clear(); 00121 _is_valid = false; 00122 } 00123 00124 //////////////////////////////////////////////////////////////////// 00125 // Function: OsMesaGraphicsBuffer::open_buffer 00126 // Access: Protected, Virtual 00127 // Description: Opens the buffer right now. Called from the window 00128 // thread. Returns true if the buffer is successfully 00129 // opened, or false if there was a problem. 00130 //////////////////////////////////////////////////////////////////// 00131 bool OsMesaGraphicsBuffer:: 00132 open_buffer() { 00133 if (_gsg == 0) { 00134 _gsg = new OSMesaGraphicsStateGuardian(_engine, _pipe, NULL); 00135 } 00136 00137 _image = PTA_uchar::empty_array(_x_size * _y_size * 4); 00138 _is_valid = true; 00139 00140 // All OSMesa buffers (that we create) always have the same format. 00141 _fb_properties.clear(); 00142 _fb_properties.set_rgb_color(1); 00143 _fb_properties.set_color_bits(24); 00144 _fb_properties.set_alpha_bits(8); 00145 _fb_properties.set_stencil_bits(8); 00146 _fb_properties.set_depth_bits(16); 00147 _fb_properties.set_accum_bits(8); 00148 _fb_properties.set_force_software(1); 00149 00150 return true; 00151 }