Panda3D
parasiteBuffer.h
1 // Filename: parasiteBuffer.h
2 // Created by: drose (27Feb04)
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 #ifndef PARASITEBUFFER_H
16 #define PARASITEBUFFER_H
17 
18 #include "pandabase.h"
19 
20 #include "graphicsOutput.h"
21 #include "texture.h"
22 #include "pointerTo.h"
23 
24 ////////////////////////////////////////////////////////////////////
25 // Class : ParasiteBuffer
26 // Description : This is a special GraphicsOutput type that acts a lot
27 // like a GraphicsBuffer, effectively allowing rendering
28 // to an offscreen buffer, except it does not create any
29 // framebuffer space for itself. Instead, it renders
30 // into the framebuffer owned by some other
31 // GraphicsOutput.
32 //
33 // The x_size and y_size must therefore fit within the
34 // bounds of the source GraphicsOutput.
35 //
36 // Since the framebuffer will be subsequently cleared
37 // when the actual owner draws in it later, this only
38 // makes sense if we are going to copy the contents of
39 // the framebuffer to a texture immediately after we
40 // draw it. Thus, has_texture() is implicitly true for
41 // a ParasiteBuffer.
42 //
43 // This class is useful to render offscreen to a texture
44 // while preventing the waste of framebuffer memory for
45 // API's that are unable to render directly into a
46 // texture (and must render into a separate framebuffer
47 // first and then copy to texture). It is also the only
48 // way to render to a texture on API's that do not
49 // support offscreen rendering.
50 ////////////////////////////////////////////////////////////////////
51 class EXPCL_PANDA_DISPLAY ParasiteBuffer : public GraphicsOutput {
52 public:
53  ParasiteBuffer(GraphicsOutput *host, const string &name,
54  int x_size, int y_size, int flags);
55 
56 PUBLISHED:
57  virtual ~ParasiteBuffer();
58 
59  virtual bool is_active() const;
60  void set_size(int x, int y);
61 
62 public:
63  void set_size_and_recalc(int x, int y);
64  virtual bool flip_ready() const;
65  virtual void begin_flip();
66  virtual void ready_flip();
67  virtual void end_flip();
68 
69  virtual bool begin_frame(FrameMode mode, Thread *current_thread);
70  virtual void end_frame(FrameMode mode, Thread *current_thread);
71  virtual GraphicsOutput *get_host();
72 
73 private:
74  int _creation_flags;
75 
76 public:
77  static TypeHandle get_class_type() {
78  return _type_handle;
79  }
80  static void init_type() {
81  GraphicsOutput::init_type();
82  register_type(_type_handle, "ParasiteBuffer",
83  GraphicsOutput::get_class_type());
84  }
85  virtual TypeHandle get_type() const {
86  return get_class_type();
87  }
88  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
89 
90 private:
91  static TypeHandle _type_handle;
92 };
93 
94 #include "parasiteBuffer.I"
95 
96 #endif
void set_size_and_recalc(int x, int y)
Changes the x_size and y_size, then recalculates structures that depend on size.
virtual GraphicsOutput * get_host()
This is normally called only from within make_texture_buffer().
virtual void end_flip()
This function will be called within the draw thread after begin_flip() has been called on all windows...
virtual bool is_active() const
Returns true if the window is ready to be rendered into, false otherwise.
virtual void end_frame(FrameMode mode, Thread *current_thread)
This function will be called within the draw thread after rendering is completed for a given frame...
This is a special GraphicsOutput type that acts a lot like a GraphicsBuffer, effectively allowing ren...
This is a base class for the various different classes that represent the result of a frame of render...
virtual void ready_flip()
This function will be called within the draw thread after end_frame() has been called on all windows...
A thread; that is, a lightweight process.
Definition: thread.h:51
virtual void begin_flip()
This function will be called within the draw thread after end_frame() has been called on all windows...
virtual bool flip_ready() const
Returns true if a frame has been rendered and needs to be flipped, false otherwise.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
virtual bool begin_frame(FrameMode mode, Thread *current_thread)
This function will be called within the draw thread before beginning rendering for a given frame...