|
|
@@ -25,24 +25,24 @@ TypeHandle MovieVideo::_type_handle;
|
|
|
// Function: MovieVideo::Constructor
|
|
|
// Access: Published
|
|
|
// Description: This constructor returns a null video stream --- a
|
|
|
-// stream of plain blue frames that last 1 second each.
|
|
|
-// To get more interesting video, you need to construct
|
|
|
-// a subclass of this class.
|
|
|
+// stream of plain blue and white frames that last one
|
|
|
+// second each. To get more interesting video, you need
|
|
|
+// to construct a subclass of this class.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
MovieVideo::
|
|
|
MovieVideo(const string &name, double len) :
|
|
|
Namable(name),
|
|
|
_size_x(1),
|
|
|
_size_y(1),
|
|
|
+ _last_frame(false),
|
|
|
+ _next_start(0.0),
|
|
|
_approx_len(len),
|
|
|
- _frame_start(0.0),
|
|
|
- _frame_end(1.0)
|
|
|
{
|
|
|
- if (len <= 0.0) {
|
|
|
- _approx_len = 1.0;
|
|
|
+ if (len < 0.0) {
|
|
|
+ _approx_len = 0.0;
|
|
|
}
|
|
|
- if (_frame_end > _approx_len) {
|
|
|
- _frame_end = _approx_len;
|
|
|
+ if (_approx_len == 0.0) {
|
|
|
+ _at_end = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -56,44 +56,42 @@ MovieVideo::
|
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-// Function: MovieVideo::load_image
|
|
|
+// Function: MovieVideo::fetch_into
|
|
|
// Access: Published, Virtual
|
|
|
-// Description: Copy the current frame into a texture's ram image.
|
|
|
+// Description: Load the next frame into a texture's ram image.
|
|
|
+// Advances the frame pointer.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
void MovieVideo::
|
|
|
-load_image(Texture *t) {
|
|
|
+fetch_into(Texture *t) {
|
|
|
|
|
|
// The following is the implementation of the null video
|
|
|
// stream --- a stream of solid blue frames. Normally,
|
|
|
// this method will be overridden by the subclass.
|
|
|
|
|
|
- if (_ram_image==0) {
|
|
|
- _ram_image = PTA_uchar::empty_array(4);
|
|
|
- _ram_image.set_element(0,128);
|
|
|
- _ram_image.set_element(1,128);
|
|
|
- _ram_image.set_element(2,255);
|
|
|
- _ram_image.set_element(3,255);
|
|
|
- }
|
|
|
t->setup_texture(Texture::TT_2d_texture, 1, 1, 1,
|
|
|
Texture::T_unsigned_byte, Texture::F_rgba);
|
|
|
- t->set_ram_image(_ram_image);
|
|
|
-}
|
|
|
-
|
|
|
-////////////////////////////////////////////////////////////////////
|
|
|
-// Function: MovieVideo::next_frame
|
|
|
-// Access: Published, Virtual
|
|
|
-// Description: Advances to the next frame.
|
|
|
-////////////////////////////////////////////////////////////////////
|
|
|
-void MovieVideo::
|
|
|
-next_frame() {
|
|
|
-
|
|
|
- // The following is the implementation of the null video
|
|
|
- // stream --- a stream of solid blue frames. Normally,
|
|
|
- // this method will be overridden by the subclass.
|
|
|
-
|
|
|
- _frame_start = _frame_end;
|
|
|
- _frame_end = _frame_end + 1.0;
|
|
|
- if (_frame_end > _approx_len) {
|
|
|
- _frame_end = _approx_len;
|
|
|
+ PTA_uchar *img = t->modify_ram_image();
|
|
|
+
|
|
|
+ int frame_index = (int)next_start;
|
|
|
+ if (at_end) {
|
|
|
+ img.set_element(0,0);
|
|
|
+ img.set_element(1,0);
|
|
|
+ img.set_element(2,0);
|
|
|
+ img.set_element(3,255);
|
|
|
+ } else if (frame_index & 1) {
|
|
|
+ img.set_element(0,128);
|
|
|
+ img.set_element(1,128);
|
|
|
+ img.set_element(2,255);
|
|
|
+ img.set_element(3,255);
|
|
|
+ } else {
|
|
|
+ img.set_element(0,255);
|
|
|
+ img.set_element(1,255);
|
|
|
+ img.set_element(2,255);
|
|
|
+ img.set_element(3,255);
|
|
|
+ }
|
|
|
+
|
|
|
+ _next_start = _next_start + 1.0;
|
|
|
+ if (_next_start > _approx_len) {
|
|
|
+ _at_end = true;
|
|
|
}
|
|
|
}
|