Panda3D
 All Classes Functions Variables Enumerations
graphicsBuffer.cxx
1 // Filename: graphicsBuffer.cxx
2 // Created by: drose (06Feb04)
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 #include "graphicsBuffer.h"
16 
17 TypeHandle GraphicsBuffer::_type_handle;
18 
19 ////////////////////////////////////////////////////////////////////
20 // Function: GraphicsBuffer::Constructor
21 // Access: Protected
22 // Description: Normally, the GraphicsBuffer constructor is not
23 // called directly; these are created instead via the
24 // GraphicsEngine::make_buffer() function.
25 ////////////////////////////////////////////////////////////////////
26 GraphicsBuffer::
27 GraphicsBuffer(GraphicsEngine *engine, GraphicsPipe *pipe,
28  const string &name,
29  const FrameBufferProperties &fb_prop,
30  const WindowProperties &win_prop, int flags,
32  GraphicsOutput *host) :
33  GraphicsOutput(engine, pipe, name, fb_prop, win_prop, flags, gsg, host, false)
34 {
35 #ifdef DO_MEMORY_USAGE
36  MemoryUsage::update_type(this, this);
37 #endif
38 
39  if (display_cat.is_debug()) {
40  display_cat.debug()
41  << "Creating new offscreen buffer " << get_name() << "\n";
42  }
43 
44  _overlay_display_region->compute_pixels(_size.get_x(), _size.get_y());
45  _open_request = OR_none;
46 }
47 
48 ////////////////////////////////////////////////////////////////////
49 // Function: GraphicsBuffer::Destructor
50 // Access: Published, Virtual
51 // Description:
52 ////////////////////////////////////////////////////////////////////
53 GraphicsBuffer::
54 ~GraphicsBuffer() {
55 }
56 
57 ////////////////////////////////////////////////////////////////////
58 // Function: GraphicsBuffer::set_size
59 // Access: Public, Virtual
60 // Description: This is called by the GraphicsEngine to request that
61 // the buffer resize itself. Although calls to get the
62 // size will return the new value, much of the actual
63 // resizing work doesn't take place until the next
64 // begin_frame. Not all buffers are resizeable.
65 ////////////////////////////////////////////////////////////////////
67 set_size(int x, int y) {
68  if ((_creation_flags & GraphicsPipe::BF_resizeable) == 0) {
69  nassert_raise("Cannot resize buffer unless it is created with BF_resizeable flag");
70  return;
71  }
72  set_size_and_recalc(x, y);
73 }
74 
75 ////////////////////////////////////////////////////////////////////
76 // Function: GraphicsBuffer::request_open
77 // Access: Public, Virtual
78 // Description: This is called by the GraphicsEngine to request that
79 // the buffer (or whatever) open itself or, in general,
80 // make itself valid, at the next call to
81 // process_events().
82 ////////////////////////////////////////////////////////////////////
85  _open_request = OR_open;
86 }
87 
88 ////////////////////////////////////////////////////////////////////
89 // Function: GraphicsBuffer::request_close
90 // Access: Public, Virtual
91 // Description: This is called by the GraphicsEngine to request that
92 // the buffer (or whatever) close itself or, in general,
93 // make itself invalid, at the next call to
94 // process_events(). By that time we promise the gsg
95 // pointer will be cleared.
96 ////////////////////////////////////////////////////////////////////
99  _open_request = OR_none;
100 }
101 
102 ////////////////////////////////////////////////////////////////////
103 // Function: GraphicsBuffer::set_close_now
104 // Access: Public, Virtual
105 // Description: This is called by the GraphicsEngine to insist that
106 // the buffer be closed immediately. This is only
107 // called from the buffer thread.
108 ////////////////////////////////////////////////////////////////////
109 void GraphicsBuffer::
111  _open_request = OR_none;
112  close_buffer();
113 }
114 
115 ////////////////////////////////////////////////////////////////////
116 // Function: GraphicsBuffer::process_events
117 // Access: Public, Virtual
118 // Description: Honor any requests recently made via request_open()
119 // or request_close().
120 //
121 // This function is called only within the window
122 // thread.
123 ////////////////////////////////////////////////////////////////////
124 void GraphicsBuffer::
126  // Save the current request and reset it immediately, in case we end
127  // up calling recursively back into this function.
128  OpenRequest this_request = _open_request;
129  _open_request = OR_none;
130 
131  switch (this_request) {
132  case OR_none:
133  return;
134 
135  case OR_open:
136  if (open_buffer()) {
137  _is_valid = true;
138  set_inverted(_gsg->get_copy_texture_inverted());
139  }
140  break;
141 
142  case OR_close:
143  close_buffer();
144  break;
145  }
146 }
147 
148 ////////////////////////////////////////////////////////////////////
149 // Function: GraphicsBuffer::close_buffer
150 // Access: Protected, Virtual
151 // Description: Closes the buffer right now. Called from the window
152 // thread.
153 ////////////////////////////////////////////////////////////////////
154 void GraphicsBuffer::
155 close_buffer() {
156  display_cat.info()
157  << "Closing " << get_type() << "\n";
158 }
159 
160 ////////////////////////////////////////////////////////////////////
161 // Function: GraphicsBuffer::open_buffer
162 // Access: Protected, Virtual
163 // Description: Opens the buffer right now. Called from the window
164 // thread. Returns true if the buffer is successfully
165 // opened, or false if there was a problem.
166 ////////////////////////////////////////////////////////////////////
167 bool GraphicsBuffer::
168 open_buffer() {
169  return false;
170 }
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 request_close()
This is called by the GraphicsEngine to request that the buffer (or whatever) close itself or...
virtual void set_size(int x, int y)
This is called by the GraphicsEngine to request that the buffer resize itself.
virtual void set_close_now()
This is called by the GraphicsEngine to insist that the buffer be closed immediately.
virtual void process_events()
Honor any requests recently made via request_open() or request_close().
A container for the various kinds of properties we might ask to have on a graphics window before we o...
virtual void request_open()
This is called by the GraphicsEngine to request that the buffer (or whatever) open itself or...
void set_inverted(bool inverted)
Changes the current setting of the inverted flag.
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...
Encapsulates all the communication with a particular instance of a given rendering backend...
This class is the main interface to controlling the render process.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...