Panda3D
|
00001 // Filename: videoTexture.I 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 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: VideoTexture::get_video_width 00018 // Access: Published 00019 // Description: Returns the width in texels of the source video 00020 // stream. This is not necessarily the width of the 00021 // actual texture, since the texture may have been 00022 // expanded to raise it to a power of 2. 00023 //////////////////////////////////////////////////////////////////// 00024 INLINE int VideoTexture:: 00025 get_video_width() const { 00026 return _video_width; 00027 } 00028 00029 //////////////////////////////////////////////////////////////////// 00030 // Function: VideoTexture::get_video_height 00031 // Access: Published 00032 // Description: Returns the height in texels of the source video 00033 // stream. This is not necessarily the height of the 00034 // actual texture, since the texture may have been 00035 // expanded to raise it to a power of 2. 00036 //////////////////////////////////////////////////////////////////// 00037 INLINE int VideoTexture:: 00038 get_video_height() const { 00039 return _video_height; 00040 } 00041 00042 //////////////////////////////////////////////////////////////////// 00043 // Function: VideoTexture::get_tex_scale 00044 // Access: Published 00045 // Description: Returns a scale pair that is suitable for applying to 00046 // geometry via NodePath::set_tex_scale(), which will 00047 // convert texture coordinates on the geometry from the 00048 // range 0..1 into the appropriate range to render the 00049 // video part of the texture. 00050 // 00051 // This is necessary in the event the video source is 00052 // not a power of two and set_power_2() is true. In 00053 // this case, the video image will be mapped to the 00054 // lower-left corner of the texture, and the rest of the 00055 // texture space will be unused; so we will need to 00056 // remap any texture coordinates to fill the space 00057 // correctly. 00058 //////////////////////////////////////////////////////////////////// 00059 INLINE LVecBase2f VideoTexture:: 00060 get_tex_scale() const { 00061 if (_video_width == 0 || _video_height == 0 || 00062 _x_size == 0 || _y_size == 0) { 00063 LVecBase2f(1.0f, 1.0f); 00064 } 00065 return LVecBase2f((float)_video_width / _x_size, 00066 (float)_video_height / _y_size); 00067 } 00068 00069 //////////////////////////////////////////////////////////////////// 00070 // Function: VideoTexture::set_video_size 00071 // Access: Protected 00072 // Description: Should be called by a derived class to set the size 00073 // of the video when it is loaded. 00074 //////////////////////////////////////////////////////////////////// 00075 INLINE void VideoTexture:: 00076 set_video_size(int video_width, int video_height) { 00077 _video_width = video_width; 00078 _video_height = video_height; 00079 } 00080 00081 //////////////////////////////////////////////////////////////////// 00082 // Function: VideoTexture::consider_update 00083 // Access: Protected 00084 // Description: Calls update_frame() if the current frame has 00085 // changed. 00086 //////////////////////////////////////////////////////////////////// 00087 INLINE void VideoTexture:: 00088 consider_update() { 00089 int this_frame = ClockObject::get_global_clock()->get_frame_count(); 00090 if (this_frame != _last_frame_update) { 00091 int frame = get_frame(); 00092 if (_current_frame != frame) { 00093 update_frame(frame); 00094 _current_frame = frame; 00095 } 00096 _last_frame_update = this_frame; 00097 } 00098 } 00099 00100 //////////////////////////////////////////////////////////////////// 00101 // Function: VideoTexture::clear_current_frame 00102 // Access: Protected 00103 // Description: Resets the record of the current frame so that it 00104 // will be forced to reload the next time it is 00105 // requested. 00106 //////////////////////////////////////////////////////////////////// 00107 INLINE void VideoTexture:: 00108 clear_current_frame() { 00109 _last_frame_update = 0; 00110 _current_frame = -1; 00111 }