olaf neophyte and de.po updates, valgrind tweaks, delete green lady, inkscape dpi=96
[goodguy/history.git] / cinelerra-5.1 / cinelerra / playback3d.C
index becf31f6b90bc6bc2bdeee53372e5c523a3255a3..2ca2a4c68e4d43f35f03595d76f23e8a6483d1d4 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 = \
@@ -656,6 +659,13 @@ void Playback3D::write_buffer_sync(Playback3DCommand *command)
                                window->enable_opengl();
 // Composite texture to screen and swap buffer
                        case VFrame::TEXTURE:
+                               if( !flip_y ) {
+                                       int fh1 = command->frame->get_h()-1;
+                                       float in_y1 = fh1 - command->in_y1;
+                                       float in_y2 = fh1 - command->in_y2;
+                                       command->in_y1 = in_y2;
+                                       command->in_y2 = in_y1;
+                               }
                                draw_output(command, flip_y);
                                break;
                        default:
@@ -691,11 +701,13 @@ void Playback3D::draw_output(Playback3DCommand *command, int flip_y)
                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
@@ -703,8 +715,7 @@ void Playback3D::draw_output(Playback3DCommand *command, int flip_y)
                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
@@ -713,11 +724,11 @@ void Playback3D::draw_output(Playback3DCommand *command, int flip_y)
                        BC_GL_YUV_TO_RGB(shader);
                }
 
-               if(BC_CModels::components(command->frame->get_color_model()) == 4)
-               {
-                       glEnable(GL_BLEND);
-                       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-               }
+//             if(BC_CModels::components(color_model) == 4)
+//             {
+//                     glEnable(GL_BLEND);
+//                     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+//             }
 
                command->frame->draw_texture(
                        command->in_x1, command->in_y1, command->in_x2, command->in_y2,
@@ -744,13 +755,11 @@ void Playback3D::draw_output(Playback3DCommand *command, int flip_y)
 }
 
 
-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
 }
@@ -773,15 +782,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();
@@ -956,19 +967,6 @@ void Playback3D::overlay_sync(Playback3DCommand *command)
                glColor4f(1, 1, 1, 1);
                glDisable(GL_BLEND);
 
-               if(command->frame) {
-// Render to PBuffer
-                       command->frame->enable_opengl();
-                       command->frame->set_opengl_state(VFrame::SCREEN);
-                       canvas_w = command->frame->get_w();
-                       canvas_h = command->frame->get_h();
-               }
-               else {
-// Render to canvas
-                       canvas_w = window->get_w();
-                       canvas_h = window->get_h();
-               }
-
 
 //printf("Playback3D::overlay_sync 1 %d\n", command->input->get_opengl_state());
                switch( command->input->get_opengl_state() ) {
@@ -983,16 +981,26 @@ void Playback3D::overlay_sync(Playback3DCommand *command)
                case VFrame::SCREEN:
                        command->input->enable_opengl();
                        command->input->screen_to_texture();
-                       if(command->frame)
-                               command->frame->enable_opengl();
-                       else
-                               window->enable_opengl();
                        break;
                default:
                        printf("Playback3D::overlay_sync unknown state\n");
                        break;
                }
 
+               if(command->frame) {
+// Render to PBuffer
+                       command->frame->enable_opengl();
+                       command->frame->set_opengl_state(VFrame::SCREEN);
+                       canvas_w = command->frame->get_w();
+                       canvas_h = command->frame->get_h();
+               }
+               else {
+// Render to canvas
+                       window->enable_opengl();
+                       canvas_w = window->get_w();
+                       canvas_h = window->get_h();
+               }
+
 
                const char *shader_stack[16];
                memset(shader_stack,0, sizeof(shader_stack));