Panda3D
graphicsEngine.I
1 // Filename: graphicsEngine.I
2 // Created by: drose (24Feb02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: GraphicsEngine::get_render_lock
18 // Access: Published
19 // Description: Returns a ReMutex object that is held by the
20 // GraphicsEngine during the entire call to
21 // render_frame(). While you hold this lock you can be
22 // confident that no part of the frame will be rendered
23 // (at least by the app thread).
24 ////////////////////////////////////////////////////////////////////
25 INLINE const ReMutex &GraphicsEngine::
26 get_render_lock() const {
27  return _public_lock;
28 }
29 
30 ////////////////////////////////////////////////////////////////////
31 // Function: GraphicsEngine::set_auto_flip
32 // Access: Published
33 // Description: Set this flag true to indicate the GraphicsEngine
34 // should automatically cause windows to sync and flip
35 // as soon as they have finished drawing, rather than
36 // waiting for all of the windows to finish drawing
37 // first so they can flip together.
38 //
39 // This only affects the timing of when the flip occurs.
40 // If this is true (the default), the flip occurs before
41 // render_frame() returns. If this is false, the flip
42 // occurs whenever flip_frame() is called, or at the
43 // beginning of the next call to render_frame(), if
44 // flip_frame() is never called.
45 ////////////////////////////////////////////////////////////////////
46 INLINE void GraphicsEngine::
47 set_auto_flip(bool auto_flip) {
48  // We don't bother with the mutex here. It's just a bool, after
49  // all.
50  _auto_flip = auto_flip;
51 }
52 
53 ////////////////////////////////////////////////////////////////////
54 // Function: GraphicsEngine::get_auto_flip
55 // Access: Published
56 // Description: Returns the current setting for the auto-flip flag.
57 // See set_auto_flip.
58 ////////////////////////////////////////////////////////////////////
59 INLINE bool GraphicsEngine::
60 get_auto_flip() const {
61  // We don't bother with the mutex here. It's just a bool, after
62  // all.
63  return _auto_flip;
64 }
65 
66 ////////////////////////////////////////////////////////////////////
67 // Function: GraphicsEngine::set_portal_cull
68 // Access: Published
69 // Description: Set this flag true to indicate the GraphicsEngine
70 // should start portal culling
71 ////////////////////////////////////////////////////////////////////
72 INLINE void GraphicsEngine::
73 set_portal_cull(bool value) {
74  // We don't bother with the mutex here. It's just a bool, after
75  // all.
76  _portal_enabled = value;
77 }
78 
79 ////////////////////////////////////////////////////////////////////
80 // Function: GraphicsEngine::get_portal_cull
81 // Access: Published
82 // Description: Returns the current setting for the portal culling flag.
83 ////////////////////////////////////////////////////////////////////
84 INLINE bool GraphicsEngine::
85 get_portal_cull() const {
86  // We don't bother with the mutex here. It's just a bool, after
87  // all.
88  return _portal_enabled;
89 }
90 
91 ////////////////////////////////////////////////////////////////////
92 // Function: GraphicsEngine::set_default_loader
93 // Access: Public
94 // Description: Sets the Loader object that will be assigned to every
95 // GSG created with this GraphicsEngine. See
96 // GraphicsStateGuardian::set_loader().
97 ////////////////////////////////////////////////////////////////////
98 INLINE void GraphicsEngine::
100  _default_loader = loader;
101 }
102 
103 ////////////////////////////////////////////////////////////////////
104 // Function: GraphicsEngine::get_default_loader
105 // Access: Public, Virtual
106 // Description: Returns the Loader object that will be assigned to
107 // every GSG created with this GraphicsEngine. See
108 // GraphicsStateGuardian::set_loader().
109 ////////////////////////////////////////////////////////////////////
110 INLINE Loader *GraphicsEngine::
112  return _default_loader;
113 }
114 
115 ////////////////////////////////////////////////////////////////////
116 // Function: GraphicsEngine::close_gsg
117 // Access: Published
118 // Description: Calls GraphicsPipe::close_gsg() on the indicated pipe
119 // and GSG. This function mainly exists to allow
120 // GraphicsEngine::WindowRenderer to call the protected
121 // method GraphicsPipe::close_gsg().
122 ////////////////////////////////////////////////////////////////////
123 INLINE void GraphicsEngine::
124 close_gsg(GraphicsPipe *pipe, GraphicsStateGuardian *gsg) {
125  pipe->close_gsg(gsg);
126 }
127 
128 ////////////////////////////////////////////////////////////////////
129 // Function: GraphicsEngine::make_buffer
130 // Access: Published
131 // Description: Syntactic shorthand for make_output. This is the
132 // preferred way to create an offscreen buffer, when you
133 // already have an onscreen window or another buffer to
134 // start with. For the first parameter, pass an
135 // existing GraphicsOutput object, e.g. the main window;
136 // this allows the buffer to adapt itself to that
137 // window's framebuffer properties, and allows maximum
138 // sharing of resources.
139 ////////////////////////////////////////////////////////////////////
141 make_buffer(GraphicsOutput *host, const string &name,
142  int sort, int x_size, int y_size) {
143  GraphicsOutput *result = make_output(host->get_pipe(), name, sort,
145  WindowProperties::size(x_size, y_size),
146  GraphicsPipe::BF_refuse_window |
147  GraphicsPipe::BF_fb_props_optional,
148  host->get_gsg(), host);
149  return result;
150 }
151 
152 ////////////////////////////////////////////////////////////////////
153 // Function: GraphicsEngine::make_buffer
154 // Access: Published
155 // Description: Syntactic shorthand for make_output. This flavor
156 // accepts a GSG rather than a GraphicsOutput as the
157 // first parameter, which is too limiting and disallows
158 // the possibility of creating a ParasiteBuffer if the
159 // user's graphics hardware prefers that. It also
160 // attempts to request specific framebuffer properties
161 // and may therefore do a poorer job of sharing the GSG
162 // between the old buffer and the new.
163 //
164 // For these reasons, this variant is a poor choice
165 // unless you are creating an offscreen buffer for the
166 // first time, without an onscreen window already in
167 // existence. If you already have an onscreen window,
168 // you should use the other flavor of make_buffer()
169 // instead, which accepts a GraphicsOutput as the first
170 // parameter.
171 ////////////////////////////////////////////////////////////////////
173 make_buffer(GraphicsStateGuardian *gsg, const string &name,
174  int sort, int x_size, int y_size) {
176  fb_props.set_back_buffers(0);
177  fb_props.set_stereo(0);
178  fb_props.set_accum_bits(0);
179  fb_props.set_multisamples(0);
180  fb_props.set_force_hardware(0);
181  fb_props.set_force_software(0);
182  GraphicsOutput *result = make_output(gsg->get_pipe(), name, sort,
183  fb_props,
184  WindowProperties::size(x_size, y_size),
185  GraphicsPipe::BF_refuse_window |
186  GraphicsPipe::BF_fb_props_optional,
187  gsg, NULL);
188  return result;
189 }
190 
191 ////////////////////////////////////////////////////////////////////
192 // Function: GraphicsEngine::make_parasite
193 // Access: Published
194 // Description: Syntactic shorthand for make_buffer.
195 ////////////////////////////////////////////////////////////////////
197 make_parasite(GraphicsOutput *host, const string &name,
198  int sort, int x_size, int y_size) {
199  GraphicsOutput *result = make_output(host->get_pipe(), name, sort,
201  WindowProperties::size(x_size, y_size),
202  GraphicsPipe::BF_require_parasite |
203  GraphicsPipe::BF_fb_props_optional,
204  host->get_gsg(), host);
205  return result;
206 }
static const FrameBufferProperties & get_default()
Returns a FrameBufferProperties structure with all of the default values filled in according to the u...
GraphicsPipe * get_pipe() const
Returns the GraphicsPipe that this window is associated with.
static WindowProperties size(int x_size, int y_size)
Returns a WindowProperties structure with only the size specified.
GraphicsPipe * get_pipe() const
Returns the graphics pipe on which this GSG was created.
bool get_auto_flip() const
Returns the current setting for the auto-flip flag.
A convenient class for loading models from disk, in bam or egg format (or any of a number of other fo...
Definition: loader.h:47
void set_portal_cull(bool value)
Set this flag true to indicate the GraphicsEngine should start portal culling.
bool get_portal_cull() const
Returns the current setting for the portal culling flag.
void set_auto_flip(bool auto_flip)
Set this flag true to indicate the GraphicsEngine should automatically cause windows to sync and flip...
const ReMutex & get_render_lock() const
Returns a ReMutex object that is held by the GraphicsEngine during the entire call to render_frame()...
An object to create GraphicsOutputs that share a particular 3-D API.
Definition: graphicsPipe.h:58
This is a base class for the various different classes that represent the result of a frame of render...
GraphicsOutput * make_output(GraphicsPipe *pipe, const string &name, int sort, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg=NULL, GraphicsOutput *host=NULL)
Creates a new window (or buffer) and returns it.
Loader * get_default_loader() const
Returns the Loader object that will be assigned to every GSG created with this GraphicsEngine.
GraphicsStateGuardian * get_gsg() const
Returns the GSG that is associated with this window.
GraphicsOutput * make_buffer(GraphicsOutput *host, const string &name, int sort, int x_size, int y_size)
Syntactic shorthand for make_output.
Encapsulates all the communication with a particular instance of a given rendering backend...
void set_default_loader(Loader *loader)
Sets the Loader object that will be assigned to every GSG created with this GraphicsEngine.
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
GraphicsOutput * make_parasite(GraphicsOutput *host, const string &name, int sort, int x_size, int y_size)
Syntactic shorthand for make_buffer.
A reentrant mutex.
Definition: reMutex.h:36