4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "overlayframe.h"
30 PluginClient* new_plugin(PluginServer *server)
32 return new DissolveMain(server);
39 DissolveMain::DissolveMain(PluginServer *server)
40 : PluginVClient(server)
45 DissolveMain::~DissolveMain()
50 const char* DissolveMain::plugin_title() { return N_("Dissolve"); }
51 int DissolveMain::is_video() { return 1; }
52 int DissolveMain::is_transition() { return 1; }
53 int DissolveMain::uses_gui() { return 0; }
57 int DissolveMain::process_realtime(VFrame *incoming, VFrame *outgoing)
59 fade = (float)PluginClient::get_source_position() /
60 PluginClient::get_total_len();
70 if(!overlayer) overlayer = new OverlayFrame(get_project_smp() + 1);
72 overlayer->overlay(outgoing, incoming,
73 0, 0, incoming->get_w(), incoming->get_h(),
74 0, 0, incoming->get_w(), incoming->get_h(),
75 fade, TRANSFER_SRC, NEAREST_NEIGHBOR);
80 int DissolveMain::handle_opengl()
83 static const char *blend_dissolve =
84 "uniform float fade;\n"
85 "uniform sampler2D src_tex;\n"
86 "uniform sampler2D dst_tex;\n"
87 "uniform vec2 dst_tex_dimensions;\n"
88 "uniform vec3 chroma_offset;\n"
91 " vec4 result_color;\n"
92 " vec4 dst_color = texture2D(dst_tex, gl_FragCoord.xy / dst_tex_dimensions);\n"
93 " vec4 src_color = texture2D(src_tex, gl_TexCoord[0].st);\n"
94 " src_color.rgb -= chroma_offset;\n"
95 " dst_color.rgb -= chroma_offset;\n"
96 " result_color = mix(dst_color, src_color, fade);\n"
97 " result_color.rgb += chroma_offset;\n"
98 " gl_FragColor = result_color;\n"
101 // Read images from RAM
102 VFrame *src = get_input();
104 VFrame *dst = get_output();
106 dst->enable_opengl();
108 src->bind_texture(0);
109 dst->bind_texture(1);
111 unsigned int shader = VFrame::make_shader(0, blend_dissolve, 0);
113 glUseProgram(shader);
114 glUniform1f(glGetUniformLocation(shader, "fade"), fade);
115 glUniform1i(glGetUniformLocation(shader, "src_tex"), 0);
116 glUniform1i(glGetUniformLocation(shader, "dst_tex"), 1);
117 if(BC_CModels::is_yuv(dst->get_color_model()))
118 glUniform3f(glGetUniformLocation(shader, "chroma_offset"), 0.0, 0.5, 0.5);
120 glUniform3f(glGetUniformLocation(shader, "chroma_offset"), 0.0, 0.0, 0.0);
121 glUniform2f(glGetUniformLocation(shader, "dst_tex_dimensions"),
122 (float)dst->get_texture_w(),
123 (float)dst->get_texture_h());
130 glActiveTexture(GL_TEXTURE1);
131 glDisable(GL_TEXTURE_2D);
132 glActiveTexture(GL_TEXTURE0);
133 glDisable(GL_TEXTURE_2D);
135 dst->set_opengl_state(VFrame::SCREEN);