add igors mask svgs, add composer clear_color pref, remove key DEL for mask gui,...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / playback3d.C
index 1c7ddc75701e8fbcbebc5779aebe4e32e3bc6028..53f6c9e6aa4abc298d6e4c37d9f9125c15fbb4c8 100644 (file)
@@ -38,6 +38,7 @@
 #include "pluginclient.h"
 #include "pluginvclient.h"
 #include "edlsession.h"
+#include "track.h"
 #include "transportque.inc"
 #include "vframe.h"
 
@@ -704,7 +705,7 @@ void Playback3D::draw_output(Playback3DCommand *command, int flip_y)
                if(!command->is_cleared)
                {
 // If we get here, the virtual console was not used.
-                       init_frame(command, 0);
+                       color_frame(command, 0,0,0,0);
                }
 
 // Texture
@@ -746,11 +747,11 @@ void Playback3D::draw_output(Playback3DCommand *command, int flip_y)
 }
 
 
-void Playback3D::init_frame(Playback3DCommand *command, int is_yuv)
+void Playback3D::color_frame(Playback3DCommand *command,
+               float r, float g, float b, float a)
 {
 #ifdef HAVE_GL
-       float gbuv = is_yuv ? 0.5 : 0.0;
-       glClearColor(0.0, gbuv, gbuv, 0.0);
+       glClearColor(r, g, b, a);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 #endif
 }
@@ -774,14 +775,21 @@ void Playback3D::clear_output_sync(Playback3DCommand *command)
 // If we get here, the virtual console is being used.
                command->canvas->get_canvas()->enable_opengl();
                int is_yuv = 0;
+               int color = BLACK, alpha = 0;
 // Using pbuffer for refresh frame.
                if( command->frame ) {
                        command->frame->enable_opengl();
+                       color = command->frame->get_clear_color();
+                       alpha = command->frame->get_clear_alpha();
                        int color_model = command->canvas->mwindow->edl->session->color_model;
                        is_yuv = BC_CModels::is_yuv(color_model);
                }
-
-               init_frame(command, is_yuv);
+               int a = alpha;
+               int r = (color>>16) & 0xff;
+               int g = (color>>8) & 0xff;
+               int b = (color>>0) & 0xff;
+               if( is_yuv ) YUV::yuv.rgb_to_yuv_8(r, g, b);
+               color_frame(command, r/255.f, g/255.f, b/255.f, a/255.f);
        }
        command->canvas->unlock_canvas();
 #endif
@@ -1271,13 +1279,13 @@ void Playback3D::do_mask_sync(Playback3DCommand *command)
                int h = command->frame->get_h();
                MaskEdges edges;
                float faders[SUBMASKS], feathers[SUBMASKS], bg = 1;
-               MaskPointSet point_set[SUBMASKS];
+               MaskPoints point_set[SUBMASKS];
 // Draw every submask as a new polygon
                int total_submasks = command->keyframe_set->total_submasks(
                        command->start_position_project, PLAY_FORWARD);
 
                for(int k = 0; k < total_submasks; k++) {
-                       MaskPointSet &points = point_set[k];
+                       MaskPoints &points = point_set[k];
                        command->keyframe_set->get_points(&points,
                                k, command->start_position_project, PLAY_FORWARD);
                        float fader = command->keyframe_set->get_fader(
@@ -1294,81 +1302,11 @@ void Playback3D::do_mask_sync(Playback3DCommand *command)
                glClearColor(bg, bg, bg, bg);
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
+               int show_mask = command->keyframe_set->track->masks;
                for(int k = 0; k < total_submasks; k++) {
-                       MaskPointSet &points = point_set[k];
                        MaskEdge &edge = *edges.append(new MaskEdge());
-                       int first_point = 0;
-// Need to tabulate every vertex in persistent memory because
-// gluTessVertex doesn't copy them.
-                       for(int i = 0; i < points.total; i++) {
-                               MaskPoint *point1 = points.values[i];
-                               MaskPoint *point2 = (i >= points.total - 1) ?
-                                       points.values[0] : points.values[i + 1];
-
-                               float x, y;
-                               int segments = 0;
-                               if( point1->control_x2 == 0 && point1->control_y2 == 0 &&
-                                   point2->control_x1 == 0 && point2->control_y1 == 0 )
-                                       segments = 1;
-
-                               float x0 = point1->x, y0 = point1->y;
-                               float x1 = point1->x + point1->control_x2;
-                               float y1 = point1->y + point1->control_y2;
-                               float x2 = point2->x + point2->control_x1;
-                               float y2 = point2->y + point2->control_y1;
-                               float x3 = point2->x, y3 = point2->y;
-
-                               // forward differencing bezier curves implementation taken from GPL code at
-                               // http://cvs.sourceforge.net/viewcvs.py/guliverkli/guliverkli/src/subtitles/Rasterizer.cpp?rev=1.3
-
-                               float cx3, cx2, cx1, cx0, cy3, cy2, cy1, cy0;
-
-                               // [-1 +3 -3 +1]
-                               // [+3 -6 +3  0]
-                               // [-3 +3  0  0]
-                               // [+1  0  0  0]
-
-                               cx3 = -  x0 + 3*x1 - 3*x2 + x3;
-                               cx2 =  3*x0 - 6*x1 + 3*x2;
-                               cx1 = -3*x0 + 3*x1;
-                               cx0 =    x0;
-
-                               cy3 = -  y0 + 3*y1 - 3*y2 + y3;
-                               cy2 =  3*y0 - 6*y1 + 3*y2;
-                               cy1 = -3*y0 + 3*y1;
-                               cy0 =    y0;
-
-                               // This equation is from Graphics Gems I.
-                               //
-                               // The idea is that since we're approximating a cubic curve with lines,
-                               // any error we incur is due to the curvature of the line, which we can
-                               // estimate by calculating the maximum acceleration of the curve.  For
-                               // a cubic, the acceleration (second derivative) is a line, meaning that
-                               // the absolute maximum acceleration must occur at either the beginning
-                               // (|c2|) or the end (|c2+c3|).  Our bounds here are a little more
-                               // conservative than that, but that's okay.
-                               if (segments == 0) {
-                                       float maxaccel1 = fabs(2*cy2) + fabs(6*cy3);
-                                       float maxaccel2 = fabs(2*cx2) + fabs(6*cx3);
-
-                                       float maxaccel = maxaccel1 > maxaccel2 ? maxaccel1 : maxaccel2;
-                                       float h = 1.0;
-
-                                       if(maxaccel > 8.0) h = sqrt((8.0) / maxaccel);
-                                       segments = int(1/h);
-                               }
-
-                               for(int j = 0; j <= segments; j++) {
-                                       float t = (float)j / segments;
-                                       x = cx0 + t*(cx1 + t*(cx2 + t*cx3));
-                                       y = cy0 + t*(cy1 + t*(cy2 + t*cy3));
-
-                                       if(j > 0 || first_point) {
-                                               edge.append(x, y - h);
-                                               first_point = 0;
-                                       }
-                               }
-                       }
+                       if( !((show_mask>>k) & 1) ) continue;
+                       edge.load(point_set[k], h);
                        if( edge.size() > 0 ) {
 // draw polygon
                                float fader = faders[k];