Panda3D
|
00001 // Filename: videoTexture.cxx 00002 // Created by: drose (21Sep05) 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 #include "pandabase.h" 00016 00017 #include "videoTexture.h" 00018 #include "clockObject.h" 00019 #include "config_gobj.h" 00020 00021 TypeHandle VideoTexture::_type_handle; 00022 00023 //////////////////////////////////////////////////////////////////// 00024 // Function: VideoTexture::Constructor 00025 // Access: Protected 00026 // Description: 00027 //////////////////////////////////////////////////////////////////// 00028 VideoTexture:: 00029 VideoTexture(const string &name) : 00030 Texture(name) 00031 { 00032 // We don't want to try to compress each frame as it's loaded. 00033 _compression = CM_off; 00034 00035 _video_width = 0; 00036 _video_height = 0; 00037 00038 _last_frame_update = 0; 00039 _current_frame = -1; 00040 } 00041 00042 //////////////////////////////////////////////////////////////////// 00043 // Function: VideoTexture::Copy Constructor 00044 // Access: Protected 00045 // Description: 00046 //////////////////////////////////////////////////////////////////// 00047 VideoTexture:: 00048 VideoTexture(const VideoTexture ©) : 00049 Texture(copy), 00050 AnimInterface(copy), 00051 _video_width(copy._video_width), 00052 _video_height(copy._video_height), 00053 _last_frame_update(copy._last_frame_update), 00054 _current_frame(copy._current_frame) 00055 { 00056 } 00057 00058 //////////////////////////////////////////////////////////////////// 00059 // Function: VideoTexture::get_keep_ram_image 00060 // Access: Published, Virtual 00061 // Description: Returns the flag that indicates whether this Texture 00062 // is eligible to have its main RAM copy of the texture 00063 // memory dumped when the texture is prepared for 00064 // rendering. See set_keep_ram_image(). 00065 //////////////////////////////////////////////////////////////////// 00066 bool VideoTexture:: 00067 get_keep_ram_image() const { 00068 // A VideoTexture should never dump its RAM image. 00069 return true; 00070 } 00071 00072 //////////////////////////////////////////////////////////////////// 00073 // Function: VideoTexture::has_cull_callback 00074 // Access: Public, Virtual 00075 // Description: Should be overridden by derived classes to return 00076 // true if cull_callback() has been defined. Otherwise, 00077 // returns false to indicate cull_callback() does not 00078 // need to be called for this node during the cull 00079 // traversal. 00080 //////////////////////////////////////////////////////////////////// 00081 bool VideoTexture:: 00082 has_cull_callback() const { 00083 return true; 00084 } 00085 00086 //////////////////////////////////////////////////////////////////// 00087 // Function: VideoTexture::cull_callback 00088 // Access: Public, Virtual 00089 // Description: If has_cull_callback() returns true, this function 00090 // will be called during the cull traversal to perform 00091 // any additional operations that should be performed at 00092 // cull time. 00093 // 00094 // This is called each time the Texture is discovered 00095 // applied to a Geom in the traversal. It should return 00096 // true if the Geom is visible, false if it should be 00097 // omitted. 00098 //////////////////////////////////////////////////////////////////// 00099 bool VideoTexture:: 00100 cull_callback(CullTraverser *, const CullTraverserData &) const { 00101 // Strictly speaking, the cull_callback() method isn't necessary for 00102 // VideoTexture, since the get_ram_image() function is already 00103 // overloaded to update itself if necessary. However, we define it 00104 // anyway, to move the update calculation into the cull traversal 00105 // rather than the draw traversal. 00106 ((VideoTexture *)this)->reconsider_dirty(); 00107 return true; 00108 } 00109 00110 //////////////////////////////////////////////////////////////////// 00111 // Function: VideoTexture::do_has_ram_image 00112 // Access: Protected, Virtual 00113 // Description: Returns true if the Texture has its image contents 00114 // available in main RAM, false if it exists only in 00115 // texture memory or in the prepared GSG context. 00116 //////////////////////////////////////////////////////////////////// 00117 bool VideoTexture:: 00118 do_has_ram_image() const { 00119 int this_frame = ClockObject::get_global_clock()->get_frame_count(); 00120 if (this_frame != _last_frame_update) { 00121 return false; 00122 } 00123 return !_ram_images.empty() && !_ram_images[0]._image.empty(); 00124 } 00125 00126 //////////////////////////////////////////////////////////////////// 00127 // Function: VideoTexture::reconsider_dirty 00128 // Access: Protected, Virtual 00129 // Description: Called by TextureContext to give the Texture a chance 00130 // to mark itself dirty before rendering, if necessary. 00131 //////////////////////////////////////////////////////////////////// 00132 void VideoTexture:: 00133 reconsider_dirty() { 00134 consider_update(); 00135 } 00136 00137 //////////////////////////////////////////////////////////////////// 00138 // Function: VideoTexture::do_reload_ram_image 00139 // Access: Protected, Virtual 00140 // Description: Called when the Texture image is required but the ram 00141 // image is not available, this will reload it from disk 00142 // or otherwise do whatever is required to make it 00143 // available, if possible. 00144 //////////////////////////////////////////////////////////////////// 00145 void VideoTexture:: 00146 do_reload_ram_image() { 00147 consider_update(); 00148 } 00149