Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / guicast / vframe3d.C
index 30c1b2bea23656a7873329b63c4e84c4841989db..90d75d7b76f6473ec593c870b83b60c0276fd301 100644 (file)
@@ -76,15 +76,6 @@ int VFrame::get_texture_components()
 }
 
 
-
-
-
-
-
-
-
-
-
 void VFrame::to_texture()
 {
 #ifdef HAVE_GL
@@ -147,7 +138,11 @@ void VFrame::to_texture()
 
 void VFrame::create_pbuffer()
 {
+#ifdef GLx4
        int ww = (get_w()+3) & ~3, hh = (get_h()+3) & ~3;
+#else
+       int ww = get_w(), hh = get_h();
+#endif
        if( pbuffer && (pbuffer->w != ww || pbuffer->h != hh ||
            pbuffer->window_id != BC_WindowBase::get_synchronous()->current_window->get_id() ) ) {
                delete pbuffer;
@@ -179,7 +174,6 @@ void VFrame::screen_to_texture(int x, int y, int w, int h)
 // Create texture
        BC_Texture::new_texture(&texture,
                get_w(), get_h(), get_color_model());
-
        if(pbuffer) {
                glEnable(GL_TEXTURE_2D);
 
@@ -237,20 +231,15 @@ void VFrame::draw_texture(int flip_y)
 }
 
 
-void VFrame::bind_texture(int texture_unit)
+void VFrame::bind_texture(int texture_unit, int nearest)
 {
 // Bind the texture
-       if(texture)
-       {
-               texture->bind(texture_unit);
+       if(texture) {
+               texture->bind(texture_unit, nearest);
        }
 }
 
 
-
-
-
-
 void VFrame::init_screen(int w, int h)
 {
 #ifdef HAVE_GL
@@ -266,7 +255,7 @@ void VFrame::init_screen(int w, int h)
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
 // Shift down and right so 0,0 is the top left corner
-       glTranslatef(-(w-1)/2.f, (h-1)/2.f, 0.0);
+       glTranslatef(-w/2.f, h/2.f, 0.f);
        glTranslatef(0.0, 0.0, -(far + near) / 2);
 
        glDisable(GL_DEPTH_TEST);
@@ -299,6 +288,10 @@ void VFrame::init_screen(int w, int h)
        glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, zero);
        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, zero);
        glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0);
+#ifndef GLx4
+       glPixelStorei(GL_PACK_ALIGNMENT,1);
+       glPixelStorei(GL_UNPACK_ALIGNMENT,1);
+#endif
 #endif
 }
 
@@ -404,13 +397,16 @@ unsigned int VFrame::make_shader(const char **segments, ...)
        unsigned int program = 0;
 #ifdef HAVE_GL
 // Construct single source file out of arguments
-       int nb_segs = 1;
-       if( !segments ) {
+       int nb_segs = 0;
+       if( !segments ) {  // arg list
                va_list list;  va_start(list, segments);
                while( va_arg(list, char*) != 0 ) ++nb_segs;
                va_end(list);
        }
-       const char *segs[nb_segs];
+       else { // segment list
+               while( segments[nb_segs] ) ++nb_segs;
+       }
+       const char *segs[++nb_segs];
        if( !segments ) {
                va_list list;  va_start(list, segments);
                for( int i=0; i<nb_segs; ++i )
@@ -448,8 +444,14 @@ void VFrame::dump_shader(int shader_id)
 void VFrame::clear_pbuffer()
 {
 #ifdef HAVE_GL
-       float gbuv = BC_CModels::is_yuv(get_color_model()) ? 0.5 : 0;
-       glClearColor(0.0, gbuv, gbuv, 0.0);
+       int rgb = clear_color>=0 ? clear_color : 0;
+       int a = clear_color>=0 ? clear_alpha : 0;
+       int r = (rgb>>16) & 0xff;
+       int g = (rgb>> 8) & 0xff;
+       int b = (rgb>> 0) & 0xff;
+       if( BC_CModels::is_yuv(get_color_model()) )
+               YUV::yuv.rgb_to_yuv_8(r, g, b);
+       glClearColor(r/255.f, g/255.f, b/255.f, a/255.f);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 #endif
 }