Panda3D
parasiteBuffer.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file parasiteBuffer.h
10  * @author drose
11  * @date 2004-02-27
12  */
13 
14 #ifndef PARASITEBUFFER_H
15 #define PARASITEBUFFER_H
16 
17 #include "pandabase.h"
18 
19 #include "graphicsOutput.h"
20 #include "texture.h"
21 #include "pointerTo.h"
22 
23 /**
24  * This is a special GraphicsOutput type that acts a lot like a
25  * GraphicsBuffer, effectively allowing rendering to an offscreen buffer,
26  * except it does not create any framebuffer space for itself. Instead, it
27  * renders into the framebuffer owned by some other GraphicsOutput.
28  *
29  * The x_size and y_size must therefore fit within the bounds of the source
30  * GraphicsOutput.
31  *
32  * Since the framebuffer will be subsequently cleared when the actual owner
33  * draws in it later, this only makes sense if we are going to copy the
34  * contents of the framebuffer to a texture immediately after we draw it.
35  * Thus, has_texture() is implicitly true for a ParasiteBuffer.
36  *
37  * This class is useful to render offscreen to a texture while preventing the
38  * waste of framebuffer memory for API's that are unable to render directly
39  * into a texture (and must render into a separate framebuffer first and then
40  * copy to texture). It is also the only way to render to a texture on API's
41  * that do not support offscreen rendering.
42  */
43 class EXPCL_PANDA_DISPLAY ParasiteBuffer : public GraphicsOutput {
44 public:
45  ParasiteBuffer(GraphicsOutput *host, const std::string &name,
46  int x_size, int y_size, int flags);
47 
48 PUBLISHED:
49  virtual ~ParasiteBuffer();
50 
51  virtual bool is_active() const;
52  void set_size(int x, int y);
53 
54 public:
55  void set_size_and_recalc(int x, int y);
56  virtual bool flip_ready() const;
57  virtual void begin_flip();
58  virtual void ready_flip();
59  virtual void end_flip();
60 
61  virtual bool begin_frame(FrameMode mode, Thread *current_thread);
62  virtual void end_frame(FrameMode mode, Thread *current_thread);
63  virtual GraphicsOutput *get_host();
64 
65 private:
66  int _creation_flags;
67 
68 public:
69  static TypeHandle get_class_type() {
70  return _type_handle;
71  }
72  static void init_type() {
73  GraphicsOutput::init_type();
74  register_type(_type_handle, "ParasiteBuffer",
75  GraphicsOutput::get_class_type());
76  }
77  virtual TypeHandle get_type() const {
78  return get_class_type();
79  }
80  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
81 
82 private:
83  static TypeHandle _type_handle;
84 };
85 
86 #include "parasiteBuffer.I"
87 
88 #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...
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:46
virtual void begin_flip()
This function will be called within the draw thread after end_frame() has been called on all windows,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:81
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.