00001 // Filename: graphicsEngine.I 00002 // Created by: drose (24Feb02) 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 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: GraphicsEngine::get_render_lock 00018 // Access: Published 00019 // Description: Returns a ReMutex object that is held by the 00020 // GraphicsEngine during the entire call to 00021 // render_frame(). While you hold this lock you can be 00022 // confident that no part of the frame will be rendered 00023 // (at least by the app thread). 00024 //////////////////////////////////////////////////////////////////// 00025 INLINE const ReMutex &GraphicsEngine:: 00026 get_render_lock() const { 00027 return _public_lock; 00028 } 00029 00030 //////////////////////////////////////////////////////////////////// 00031 // Function: GraphicsEngine::set_auto_flip 00032 // Access: Published 00033 // Description: Set this flag true to indicate the GraphicsEngine 00034 // should automatically cause windows to sync and flip 00035 // as soon as they have finished drawing, rather than 00036 // waiting for all of the windows to finish drawing 00037 // first so they can flip together. 00038 // 00039 // This only affects the timing of when the flip occurs. 00040 // If this is true (the default), the flip occurs before 00041 // render_frame() returns. If this is false, the flip 00042 // occurs whenever flip_frame() is called, or at the 00043 // beginning of the next call to render_frame(), if 00044 // flip_frame() is never called. 00045 //////////////////////////////////////////////////////////////////// 00046 INLINE void GraphicsEngine:: 00047 set_auto_flip(bool auto_flip) { 00048 // We don't bother with the mutex here. It's just a bool, after 00049 // all. 00050 _auto_flip = auto_flip; 00051 } 00052 00053 //////////////////////////////////////////////////////////////////// 00054 // Function: GraphicsEngine::get_auto_flip 00055 // Access: Published 00056 // Description: Returns the current setting for the auto-flip flag. 00057 // See set_auto_flip. 00058 //////////////////////////////////////////////////////////////////// 00059 INLINE bool GraphicsEngine:: 00060 get_auto_flip() const { 00061 // We don't bother with the mutex here. It's just a bool, after 00062 // all. 00063 return _auto_flip; 00064 } 00065 00066 //////////////////////////////////////////////////////////////////// 00067 // Function: GraphicsEngine::set_portal_cull 00068 // Access: Published 00069 // Description: Set this flag true to indicate the GraphicsEngine 00070 // should start portal culling 00071 //////////////////////////////////////////////////////////////////// 00072 INLINE void GraphicsEngine:: 00073 set_portal_cull(bool value) { 00074 // We don't bother with the mutex here. It's just a bool, after 00075 // all. 00076 _portal_enabled = value; 00077 } 00078 00079 //////////////////////////////////////////////////////////////////// 00080 // Function: GraphicsEngine::get_portal_cull 00081 // Access: Published 00082 // Description: Returns the current setting for the portal culling flag. 00083 //////////////////////////////////////////////////////////////////// 00084 INLINE bool GraphicsEngine:: 00085 get_portal_cull() const { 00086 // We don't bother with the mutex here. It's just a bool, after 00087 // all. 00088 return _portal_enabled; 00089 } 00090 00091 //////////////////////////////////////////////////////////////////// 00092 // Function: GraphicsEngine::set_default_loader 00093 // Access: Public 00094 // Description: Sets the Loader object that will be assigned to every 00095 // GSG created with this GraphicsEngine. See 00096 // GraphicsStateGuardian::set_loader(). 00097 //////////////////////////////////////////////////////////////////// 00098 INLINE void GraphicsEngine:: 00099 set_default_loader(Loader *loader) { 00100 _default_loader = loader; 00101 } 00102 00103 //////////////////////////////////////////////////////////////////// 00104 // Function: GraphicsEngine::get_default_loader 00105 // Access: Public, Virtual 00106 // Description: Returns the Loader object that will be assigned to 00107 // every GSG created with this GraphicsEngine. See 00108 // GraphicsStateGuardian::set_loader(). 00109 //////////////////////////////////////////////////////////////////// 00110 INLINE Loader *GraphicsEngine:: 00111 get_default_loader() const { 00112 return _default_loader; 00113 } 00114 00115 //////////////////////////////////////////////////////////////////// 00116 // Function: GraphicsEngine::close_gsg 00117 // Access: Published 00118 // Description: Calls GraphicsPipe::close_gsg() on the indicated pipe 00119 // and GSG. This function mainly exists to allow 00120 // GraphicsEngine::WindowRenderer to call the protected 00121 // method GraphicsPipe::close_gsg(). 00122 //////////////////////////////////////////////////////////////////// 00123 INLINE void GraphicsEngine:: 00124 close_gsg(GraphicsPipe *pipe, GraphicsStateGuardian *gsg) { 00125 pipe->close_gsg(gsg); 00126 } 00127 00128 //////////////////////////////////////////////////////////////////// 00129 // Function: GraphicsEngine::make_buffer 00130 // Access: Published 00131 // Description: Syntactic shorthand for make_output. This is the 00132 // preferred way to create an offscreen buffer, when you 00133 // already have an onscreen window or another buffer to 00134 // start with. For the first parameter, pass an 00135 // existing GraphicsOutput object, e.g. the main window; 00136 // this allows the buffer to adapt itself to that 00137 // window's framebuffer properties, and allows maximum 00138 // sharing of resources. 00139 //////////////////////////////////////////////////////////////////// 00140 INLINE GraphicsOutput *GraphicsEngine:: 00141 make_buffer(GraphicsOutput *host, const string &name, 00142 int sort, int x_size, int y_size) { 00143 GraphicsOutput *result = make_output(host->get_pipe(), name, sort, 00144 FrameBufferProperties(), 00145 WindowProperties::size(x_size, y_size), 00146 GraphicsPipe::BF_refuse_window | 00147 GraphicsPipe::BF_fb_props_optional, 00148 host->get_gsg(), host); 00149 return result; 00150 } 00151 00152 //////////////////////////////////////////////////////////////////// 00153 // Function: GraphicsEngine::make_buffer 00154 // Access: Published 00155 // Description: Syntactic shorthand for make_output. This flavor 00156 // accepts a GSG rather than a GraphicsOutput as the 00157 // first parameter, which is too limiting and disallows 00158 // the possibility of creating a ParasiteBuffer if the 00159 // user's graphics hardware prefers that. It also 00160 // attempts to request specific framebuffer properties 00161 // and may therefore do a poorer job of sharing the GSG 00162 // between the old buffer and the new. 00163 // 00164 // For these reasons, this variant is a poor choice 00165 // unless you are creating an offscreen buffer for the 00166 // first time, without an onscreen window already in 00167 // existence. If you already have an onscreen window, 00168 // you should use the other flavor of make_buffer() 00169 // instead, which accepts a GraphicsOutput as the first 00170 // parameter. 00171 //////////////////////////////////////////////////////////////////// 00172 INLINE GraphicsOutput *GraphicsEngine:: 00173 make_buffer(GraphicsStateGuardian *gsg, const string &name, 00174 int sort, int x_size, int y_size) { 00175 FrameBufferProperties fb_props = FrameBufferProperties::get_default(); 00176 fb_props.set_back_buffers(0); 00177 fb_props.set_stereo(0); 00178 fb_props.set_accum_bits(0); 00179 fb_props.set_multisamples(0); 00180 fb_props.set_force_hardware(0); 00181 fb_props.set_force_software(0); 00182 GraphicsOutput *result = make_output(gsg->get_pipe(), name, sort, 00183 fb_props, 00184 WindowProperties::size(x_size, y_size), 00185 GraphicsPipe::BF_refuse_window | 00186 GraphicsPipe::BF_fb_props_optional, 00187 gsg, NULL); 00188 return result; 00189 } 00190 00191 //////////////////////////////////////////////////////////////////// 00192 // Function: GraphicsEngine::make_parasite 00193 // Access: Published 00194 // Description: Syntactic shorthand for make_buffer. 00195 //////////////////////////////////////////////////////////////////// 00196 INLINE GraphicsOutput *GraphicsEngine:: 00197 make_parasite(GraphicsOutput *host, const string &name, 00198 int sort, int x_size, int y_size) { 00199 GraphicsOutput *result = make_output(host->get_pipe(), name, sort, 00200 FrameBufferProperties(), 00201 WindowProperties::size(x_size, y_size), 00202 GraphicsPipe::BF_require_parasite | 00203 GraphicsPipe::BF_fb_props_optional, 00204 host->get_gsg(), host); 00205 return result; 00206 }