add olaf de.po, opengl bg clr, asset drag select tweak
[goodguy/history.git] / cinelerra-5.1 / cinelerra / playback3d.C
index 04c668be0de57f495b1dc9d51c92051bdd18182d..6d6dee358b5bc18e72fae98e0ed45ce3b131cf59 100644 (file)
 #include "canvas.h"
 #include "clip.h"
 #include "condition.h"
+#include "edl.h"
 #include "maskautos.h"
 #include "maskauto.h"
 #include "mutex.h"
+#include "mwindow.h"
 #include "overlayframe.inc"
 #include "overlayframe.h"
 #include "playback3d.h"
 #include "pluginclient.h"
 #include "pluginvclient.h"
+#include "edlsession.h"
 #include "transportque.inc"
 #include "vframe.h"
 
@@ -134,11 +137,11 @@ static const char *rgba_to_yuv_frag =
        "       gl_FragColor = rgba;\n"
        "}\n";
 
-static const char *rgba_to_rgb_flatten =
-       "void main() {\n"
-       "       gl_FragColor.rgb *= gl_FragColor.a;\n"
-       "       gl_FragColor.a = 1.0;\n"
-       "}\n";
+//static const char *rgba_to_rgb_flatten =
+//     "void main() {\n"
+//     "       gl_FragColor.rgb *= gl_FragColor.a;\n"
+//     "       gl_FragColor.a = 1.0;\n"
+//     "}\n";
 
 #define GL_STD_BLEND(FN) \
 static const char *blend_##FN##_frag = \
@@ -498,12 +501,23 @@ void Playback3D::copy_from_sync(Playback3DCommand *command)
                        else
 // Copy to RAM
                        {
-                               command->input->enable_opengl();
-                               glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-                               glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE,
-                                       command->frame->get_rows()[0]);
-                               command->frame->flip_vert();
-                               command->frame->set_opengl_state(VFrame::RAM);
+                               command->input->to_texture();
+                               command->input->bind_texture(0);
+                               command->frame->enable_opengl();
+                               command->frame->init_screen();
+                               unsigned int shader = BC_CModels::is_yuv(command->input->get_color_model()) ?
+                                       VFrame::make_shader(0, yuv_to_rgb_frag, 0) : 0;
+                               if( shader > 0 ) {
+                                       glUseProgram(shader);
+                                       int variable = glGetUniformLocation(shader, "tex");
+                                       glUniform1i(variable, 0);
+                                       BC_GL_YUV_TO_RGB(shader);
+                               }
+                               else
+                                       glUseProgram(0);
+                               command->input->draw_texture(1);
+                               command->frame->screen_to_ram();
+                               glUseProgram(0);
                        }
                }
                else
@@ -634,27 +648,24 @@ void Playback3D::write_buffer_sync(Playback3DCommand *command)
 // Make sure OpenGL is enabled first.
                window->enable_opengl();
 
-
 //printf("Playback3D::write_buffer_sync 1 %d\n", window->get_id());
-               switch(command->frame->get_opengl_state())
-               {
+               int flip_y = 0, frame_state = command->frame->get_opengl_state();
+               switch( frame_state ) {
 // Upload texture and composite to screen
                        case VFrame::RAM:
+                               flip_y = 1;
+                       case VFrame::SCREEN:
                                command->frame->to_texture();
-                               draw_output(command);
-                               break;
+                               window->enable_opengl();
 // Composite texture to screen and swap buffer
                        case VFrame::TEXTURE:
-                               draw_output(command);
-                               break;
-                       case VFrame::SCREEN:
-// swap buffers only
-                               window->flip_opengl();
+                               draw_output(command, flip_y);
                                break;
                        default:
                                printf("Playback3D::write_buffer_sync unknown state\n");
                                break;
                }
+               command->frame->set_opengl_state(frame_state);
                window->unlock_window();
        }
 
@@ -663,7 +674,7 @@ void Playback3D::write_buffer_sync(Playback3DCommand *command)
 
 
 
-void Playback3D::draw_output(Playback3DCommand *command)
+void Playback3D::draw_output(Playback3DCommand *command, int flip_y)
 {
 #ifdef HAVE_GL
        int texture_id = command->frame->get_texture_id();
@@ -683,11 +694,13 @@ void Playback3D::draw_output(Playback3DCommand *command)
                canvas_w = window->get_w();
                canvas_h = window->get_h();
                VFrame::init_screen(canvas_w, canvas_h);
+               int color_model = command->frame->get_color_model();
+               int is_yuv = BC_CModels::is_yuv(color_model);
 
                if(!command->is_cleared)
                {
 // If we get here, the virtual console was not used.
-                       init_frame(command);
+                       init_frame(command, 0);
                }
 
 // Texture
@@ -695,8 +708,7 @@ void Playback3D::draw_output(Playback3DCommand *command)
                command->frame->bind_texture(0);
 
 // Convert colormodel
-               unsigned int shader = !BC_CModels::is_yuv(command->frame->get_color_model()) ? 0 :
-                       VFrame::make_shader(0, yuv_to_rgb_frag, 0);
+               unsigned int shader = is_yuv ? VFrame::make_shader(0, yuv_to_rgb_frag, 0) : 0;
                if( shader > 0 ) {
                        glUseProgram(shader);
 // Set texture unit of the texture
@@ -705,7 +717,7 @@ void Playback3D::draw_output(Playback3DCommand *command)
                        BC_GL_YUV_TO_RGB(shader);
                }
 
-               if(BC_CModels::components(command->frame->get_color_model()) == 4)
+               if(BC_CModels::components(color_model) == 4)
                {
                        glEnable(GL_BLEND);
                        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -714,10 +726,10 @@ void Playback3D::draw_output(Playback3DCommand *command)
                command->frame->draw_texture(
                        command->in_x1, command->in_y1, command->in_x2, command->in_y2,
                        command->out_x1, command->out_y1, command->out_x2, command->out_y2,
-                       1);
+                       flip_y);
 
 
-// printf("Playback3D::draw_output 2 %f,%f %f,%f -> %f,%f %f,%f\n",
+//printf("Playback3D::draw_output 2 %f,%f %f,%f -> %f,%f %f,%f\n",
 // command->in_x1,
 // command->in_y1,
 // command->in_x2,
@@ -736,13 +748,11 @@ void Playback3D::draw_output(Playback3DCommand *command)
 }
 
 
-void Playback3D::init_frame(Playback3DCommand *command)
+void Playback3D::init_frame(Playback3DCommand *command, int is_yuv)
 {
 #ifdef HAVE_GL
-       canvas_w = command->canvas->get_canvas()->get_w();
-       canvas_h = command->canvas->get_canvas()->get_h();
-
-       glClearColor(0.0, 0.0, 0.0, 0.0);
+       float gbuv = is_yuv ? 0.5 : 0.0;
+       glClearColor(0.0, gbuv, gbuv, 0.0);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 #endif
 }
@@ -765,15 +775,17 @@ void Playback3D::clear_output_sync(Playback3DCommand *command)
                command->canvas->get_canvas()->lock_window("Playback3D::clear_output_sync");
 // If we get here, the virtual console is being used.
                command->canvas->get_canvas()->enable_opengl();
+               int is_yuv = 0;
 
 // Using pbuffer for refresh frame.
                if(command->frame)
                {
                        command->frame->enable_opengl();
+                       int color_model = command->canvas->mwindow->edl->session->color_model;
+                       is_yuv = BC_CModels::is_yuv(color_model);
                }
 
-
-               init_frame(command);
+               init_frame(command, is_yuv);
                command->canvas->get_canvas()->unlock_window();
        }
        command->canvas->unlock_canvas();
@@ -963,7 +975,7 @@ void Playback3D::overlay_sync(Playback3DCommand *command)
 
 
 //printf("Playback3D::overlay_sync 1 %d\n", command->input->get_opengl_state());
-               switch(command->input->get_opengl_state()) {
+               switch( command->input->get_opengl_state() ) {
 // Upload texture and composite to screen
                case VFrame::RAM:
                        command->input->to_texture();
@@ -997,11 +1009,11 @@ void Playback3D::overlay_sync(Playback3DCommand *command)
 
 // Convert colormodel to RGB if not nested.
 // The color model setting in the output frame is ignored.
-               if( command->is_nested <= 0 &&  // not nested
-                   BC_CModels::is_yuv(command->input->get_color_model()) ) {
-                       need_matrix = 1;
-                       shader_stack[total_shaders++] = yuv_to_rgb_frag;
-               }
+//             if( command->is_nested <= 0 &&  // not nested
+//                 BC_CModels::is_yuv(command->input->get_color_model()) ) {
+//                     need_matrix = 1;
+//                     shader_stack[total_shaders++] = yuv_to_rgb_frag;
+//             }
 
 // get the shaders
 #define add_shader(s) \
@@ -1021,16 +1033,16 @@ void Playback3D::overlay_sync(Playback3DCommand *command)
                }
 
 // if to flatten alpha
-               if( command->is_nested < 0 ) {
-                       switch(command->input->get_color_model()) {
-// yuv has already been converted to rgb
-                       case BC_YUVA8888:
-                       case BC_RGBA_FLOAT:
-                       case BC_RGBA8888:
-                               add_shader(rgba_to_rgb_flatten);
-                               break;
-                       }
-               }
+//             if( command->is_nested < 0 ) {
+//                     switch(command->input->get_color_model()) {
+//// yuv has already been converted to rgb
+//                     case BC_YUVA8888:
+//                     case BC_RGBA_FLOAT:
+//                     case BC_RGBA8888:
+//                             add_shader(rgba_to_rgb_flatten);
+//                             break;
+//                     }
+//             }
 
 // run the shaders
                add_shader(0);
@@ -1056,15 +1068,14 @@ void Playback3D::overlay_sync(Playback3DCommand *command)
                        glUseProgram(0);
 
 
-// printf("Playback3D::overlay_sync %f %f %f %f %f %f %f %f\n",
+//printf("Playback3D::overlay_sync %f %f %f %f %f %f %f %f\n",
 // command->in_x1, command->in_y1, command->in_x2, command->in_y2,
 // command->out_x1, command->out_y1, command->out_x2, command->out_y2);
 
                command->input->draw_texture(
                        command->in_x1, command->in_y1, command->in_x2, command->in_y2,
                        command->out_x1, command->out_y1, command->out_x2, command->out_y2,
-// Don't flip vertical if nested
-                       command->is_nested > 0 ? 0 : 1);
+                       !command->is_nested);
                glUseProgram(0);
 
 // Delete temp texture