Panda3D
|
00001 // Filename: parasiteBuffer.h 00002 // Created by: drose (27Feb04) 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 #ifndef PARASITEBUFFER_H 00016 #define PARASITEBUFFER_H 00017 00018 #include "pandabase.h" 00019 00020 #include "graphicsOutput.h" 00021 #include "texture.h" 00022 #include "pointerTo.h" 00023 00024 //////////////////////////////////////////////////////////////////// 00025 // Class : ParasiteBuffer 00026 // Description : This is a special GraphicsOutput type that acts a lot 00027 // like a GraphicsBuffer, effectively allowing rendering 00028 // to an offscreen buffer, except it does not create any 00029 // framebuffer space for itself. Instead, it renders 00030 // into the framebuffer owned by some other 00031 // GraphicsOutput. 00032 // 00033 // The x_size and y_size must therefore fit within the 00034 // bounds of the source GraphicsOutput. 00035 // 00036 // Since the framebuffer will be subsequently cleared 00037 // when the actual owner draws in it later, this only 00038 // makes sense if we are going to copy the contents of 00039 // the framebuffer to a texture immediately after we 00040 // draw it. Thus, has_texture() is implicitly true for 00041 // a ParasiteBuffer. 00042 // 00043 // This class is useful to render offscreen to a texture 00044 // while preventing the waste of framebuffer memory for 00045 // API's that are unable to render directly into a 00046 // texture (and must render into a separate framebuffer 00047 // first and then copy to texture). It is also the only 00048 // way to render to a texture on API's that do not 00049 // support offscreen rendering. 00050 //////////////////////////////////////////////////////////////////// 00051 class EXPCL_PANDA_DISPLAY ParasiteBuffer : public GraphicsOutput { 00052 public: 00053 ParasiteBuffer(GraphicsOutput *host, const string &name, 00054 int x_size, int y_size, int flags); 00055 00056 PUBLISHED: 00057 virtual ~ParasiteBuffer(); 00058 00059 virtual bool is_active() const; 00060 void set_size(int x, int y); 00061 00062 public: 00063 void set_size_and_recalc(int x, int y); 00064 virtual bool flip_ready() const; 00065 virtual void begin_flip(); 00066 virtual void ready_flip(); 00067 virtual void end_flip(); 00068 00069 virtual bool begin_frame(FrameMode mode, Thread *current_thread); 00070 virtual void end_frame(FrameMode mode, Thread *current_thread); 00071 virtual GraphicsOutput *get_host(); 00072 00073 private: 00074 int _creation_flags; 00075 00076 public: 00077 static TypeHandle get_class_type() { 00078 return _type_handle; 00079 } 00080 static void init_type() { 00081 GraphicsOutput::init_type(); 00082 register_type(_type_handle, "ParasiteBuffer", 00083 GraphicsOutput::get_class_type()); 00084 } 00085 virtual TypeHandle get_type() const { 00086 return get_class_type(); 00087 } 00088 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00089 00090 private: 00091 static TypeHandle _type_handle; 00092 }; 00093 00094 #include "parasiteBuffer.I" 00095 00096 #endif