X-Git-Url: http://git.cinelerra-gg.org/git/?p=goodguy%2Fhistory.git;a=blobdiff_plain;f=cinelerra-5.1%2Fguicast%2Fvframe3d.C;h=aba006b8a11c43270ec1ab5ef53f16ae0b343105;hp=f6f0a440cf85fdf41364655287d660387e73465a;hb=d60a59baa6cfe24c0fb153ed9e150a834ba29feb;hpb=21b49090a36821cfe97bdfc573c7fbacc80653d1 diff --git a/cinelerra-5.1/guicast/vframe3d.C b/cinelerra-5.1/guicast/vframe3d.C index f6f0a440..aba006b8 100644 --- a/cinelerra-5.1/guicast/vframe3d.C +++ b/cinelerra-5.1/guicast/vframe3d.C @@ -29,9 +29,6 @@ #include "bcwindowbase.h" #include "vframe.h" -#if defined(HAVE_CONFIG_H) -#include "config.h" -#endif #ifdef HAVE_GL #include #include @@ -102,10 +99,6 @@ void VFrame::to_texture() return; case VFrame::SCREEN: - if((get_w() % 4) || (get_h() % 4)) { - printf("VFrame::to_texture w=%d h=%d\n", get_w(), get_h()); - return; - } if(pbuffer) { enable_opengl(); screen_to_texture(); @@ -154,30 +147,22 @@ void VFrame::to_texture() void VFrame::create_pbuffer() { - if(pbuffer && - pbuffer->window_id != BC_WindowBase::get_synchronous()->current_window->get_id()) - { + int ww = (get_w()+3) & ~3, hh = (get_h()+3) & ~3; + if( pbuffer && (pbuffer->w != ww || pbuffer->h != hh || + pbuffer->window_id != BC_WindowBase::get_synchronous()->current_window->get_id() ) ) { delete pbuffer; pbuffer = 0; } - if((get_w() % 4) || (get_h() % 4)) - { - printf("VFrame::create_pbuffer w=%d h=%d\n", get_w(), get_h()); - return; - } - - if(!pbuffer) - { - pbuffer = new BC_PBuffer(get_w(), get_h()); + if( !pbuffer ) { + pbuffer = new BC_PBuffer(ww, hh); } } void VFrame::enable_opengl() { create_pbuffer(); - if(pbuffer) - { + if( pbuffer ) { pbuffer->enable_opengl(); } } @@ -229,49 +214,26 @@ void VFrame::screen_to_ram() #endif } -void VFrame::draw_texture(float in_x1, - float in_y1, - float in_x2, - float in_y2, - float out_x1, - float out_y1, - float out_x2, - float out_y2, - int flip_y) +void VFrame::draw_texture( + float in_x1, float in_y1, float in_x2, float in_y2, + float out_x1, float out_y1, float out_x2, float out_y2, + int flip_y) { #ifdef HAVE_GL - glBegin(GL_QUADS); - glNormal3f(0, 0, 1.0); - - glTexCoord2f(in_x1 / get_texture_w(), in_y1 / get_texture_h()); - glVertex3f(out_x1, flip_y ? -out_y1 : -out_y2, 0); - - glTexCoord2f(in_x2 / get_texture_w(), in_y1 / get_texture_h()); - glVertex3f(out_x2, flip_y ? -out_y1 : -out_y2, 0); - - glTexCoord2f(in_x2 / get_texture_w(), in_y2 / get_texture_h()); - glVertex3f(out_x2, flip_y ? -out_y2 : -out_y1, 0); - - glTexCoord2f(in_x1 / get_texture_w(), in_y2 / get_texture_h()); - glVertex3f(out_x1, flip_y ? -out_y2 : -out_y1, 0); - - - glEnd(); - + in_x1 /= get_texture_w(); in_y1 /= get_texture_h(); + in_x2 /= get_texture_w(); in_y2 /= get_texture_h(); + float ot_y1 = flip_y ? -out_y1 : -out_y2; + float ot_y2 = flip_y ? -out_y2 : -out_y1; + texture->draw_texture( + in_x1,in_y1, in_x2,in_y2, + out_x1,ot_y1, out_x2, ot_y2); #endif } void VFrame::draw_texture(int flip_y) { - draw_texture(0, - 0, - get_w(), - get_h(), - 0, - 0, - get_w(), - get_h(), - flip_y); + draw_texture(0,0, get_w(),get_h(), + 0,0, get_w(),get_h(), flip_y); } @@ -356,133 +318,90 @@ static int print_error(char *source, unsigned int object, int is_program) glGetShaderInfoLog(object, BCTEXTLEN, &len, string); if(len > 0) printf("Playback3D::print_error:\n%s\n%s\n", source, string); if(len > 0) return 1; - return 0; #endif + return 0; } +// call as: +// make_shader(0, frag1, .., fragn, 0); +// or make_shader(fragments); - -unsigned int VFrame::make_shader(int x, ...) +unsigned int VFrame::make_shader(const char **fragments, ...) { unsigned int result = 0; #ifdef HAVE_GL // Construct single source file out of arguments - char *complete_program = 0; - int complete_size = 0; - int current_shader = 0; - - va_list list; - va_start(list, x); - - while(1) - { - char *text = va_arg(list, char*); - if(!text) break; - -// Replace one occurrance in each source of main() with a unique id. - char main_replacement[BCTEXTLEN]; - sprintf(main_replacement, "main%03d()", current_shader); -//printf("VFrame::make_shader %s %s\n", text, main_replacement); - char *source_replacement = new char[strlen(text) + strlen(main_replacement) + 1]; - char *ptr = strstr(text, "main()"); - - if(ptr) - { - memcpy(source_replacement, text, ptr - text); - source_replacement[ptr - text] = 0; - strcat(source_replacement, main_replacement); - ptr += strlen("main()"); - strcat(source_replacement, ptr); - current_shader++; - } - else - { - memcpy(source_replacement, text, strlen(text)); - source_replacement[strlen(text)] = 0; - } - - if(!complete_program) - { - complete_size = strlen(source_replacement) + 1; - complete_program = (char*)malloc(complete_size); - strcpy(complete_program, source_replacement); - } - else - { - complete_size += strlen(source_replacement); - complete_program = (char*)realloc(complete_program, complete_size); - strcat(complete_program, source_replacement); - } - - delete [] source_replacement; - } - va_end(list); - -// Add main() function which calls all the unique main replacements in order - char main_function[BCTEXTLEN]; - sprintf(main_function, - "\n" - "void main()\n" - "{\n"); - - for(int i = 0; i < current_shader; i++) - { - char main_replacement[BCTEXTLEN]; - sprintf(main_replacement, "\tmain%03d();\n", i); - strcat(main_function, main_replacement); - } - - strcat(main_function, "}\n"); - if(!complete_program) - { - complete_size = strlen(main_function) + 1; - complete_program = (char*)malloc(complete_size); - strcpy(complete_program, main_function); + char *program = 0; + int nb_mains = 0; + + int nb_frags = 1; + if( !fragments ) { + va_list list; va_start(list, fragments); + while( va_arg(list, char*) != 0 ) ++nb_frags; + va_end(list); } - else - { - complete_size += strlen(main_function); - complete_program = (char*)realloc(complete_program, complete_size); - strcat(complete_program, main_function); + const char *frags[nb_frags], *text = 0; + if( !fragments ) { + va_list list; va_start(list, fragments); + for( int i=0; iget_shader(complete_program, - &got_it); - - if(!got_it) - { + result = BC_WindowBase::get_synchronous()->get_shader(program, &got_it); + if( !got_it ) { result = glCreateProgram(); - - unsigned int shader; - shader = glCreateShader(GL_FRAGMENT_SHADER); - const GLchar *text_ptr = complete_program; + unsigned int shader = glCreateShader(GL_FRAGMENT_SHADER); + const GLchar *text_ptr = program; glShaderSource(shader, 1, &text_ptr, NULL); glCompileShader(shader); - int error = print_error(complete_program, shader, 0); + int error = print_error(program, shader, 0); glAttachShader(result, shader); glDeleteShader(shader); - glLinkProgram(result); - if(!error) error = print_error(complete_program, result, 1); - - -// printf("BC_WindowBase::make_shader: shader=%d window_id=%d\n", -// result, + if( !error ) + error = print_error(program, result, 1); +//printf("BC_WindowBase::make_shader: shader=%d window_id=%d\n", result, // BC_WindowBase::get_synchronous()->current_window->get_id()); - BC_WindowBase::get_synchronous()->put_shader(result, complete_program); + BC_WindowBase::get_synchronous()->put_shader(result, program); } -//printf("VFrame::make_shader\n%s\n", complete_program); - free(complete_program); - complete_program = NULL; - +//printf("VFrame::make_shader\n%s\n", program); + delete [] program; #endif return result; } @@ -496,10 +415,8 @@ void VFrame::dump_shader(int shader_id) void VFrame::clear_pbuffer() { #ifdef HAVE_GL - if(BC_CModels::is_yuv(get_color_model())) - glClearColor(0.0, 0.5, 0.5, 0.0); - else - glClearColor(0.0, 0.0, 0.0, 0.0); + float gbuv = BC_CModels::is_yuv(get_color_model()) ? 0.5 : 0; + glClearColor(0.0, gbuv, gbuv, 0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); #endif }