4 * Copyright (C) 2009 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 "arraylist.h"
26 #include "bcpixmap.inc"
27 #include "bcsynchronous.h"
28 #include "bcwindowbase.inc"
30 #include "condition.inc"
31 #include "maskauto.inc"
32 #include "maskautos.inc"
34 #include "mwindow.inc"
35 #include "pluginclient.inc"
43 // Macros for useful fragment shaders
44 #define YUV_TO_RGB_FRAG(PIXEL) \
45 PIXEL ".gb -= vec2(0.5, 0.5);\n" \
46 PIXEL ".rgb = mat3(\n" \
48 " 0, -0.34414, 1.77200, \n" \
49 " 1.40200, -0.71414, 0) * " PIXEL ".rgb;\n"
51 #define RGB_TO_YUV_FRAG(PIXEL) \
52 PIXEL ".rgb = mat3(\n" \
53 " 0.29900, -0.16874, 0.50000, \n" \
54 " 0.58700, -0.33126, -0.41869, \n" \
55 " 0.11400, 0.50000, -0.08131) * " PIXEL ".rgb;\n" \
56 PIXEL ".gb += vec2(0.5, 0.5);\n"
58 #define RGB_TO_HSV_FRAG(PIXEL) \
62 "float min, max, delta;\n" \
63 "float f, p, q, t;\n" \
64 "r = " PIXEL ".r;\n" \
65 "g = " PIXEL ".g;\n" \
66 "b = " PIXEL ".b;\n" \
67 "min = ((r < g) ? r : g) < b ? ((r < g) ? r : g) : b;\n" \
68 "max = ((r > g) ? r : g) > b ? ((r > g) ? r : g) : b;\n" \
70 "delta = max - min;\n" \
71 "if(max != 0.0 && delta != 0.0)\n" \
73 " s = delta / max;\n" \
75 " h = (g - b) / delta;\n" \
78 " h = 2.0 + (b - r) / delta;\n" \
80 " h = 4.0 + (r - g) / delta;\n" \
91 "" PIXEL ".r = h;\n" \
92 "" PIXEL ".g = s;\n" \
93 "" PIXEL ".b = v;\n" \
96 #define HSV_TO_RGB_FRAG(PIXEL) \
101 "float min, max, delta;\n" \
102 "float f, p, q, t;\n" \
103 "h = " PIXEL ".r;\n" \
104 "s = " PIXEL ".g;\n" \
105 "v = " PIXEL ".b;\n" \
108 " r = g = b = v;\n" \
114 " f = h - float(i);\n" \
115 " p = v * (1.0 - s);\n" \
116 " q = v * (1.0 - s * f);\n" \
117 " t = v * (1.0 - s * (1.0 - f));\n" \
161 "" PIXEL ".r = r;\n" \
162 "" PIXEL ".g = g;\n" \
163 "" PIXEL ".b = b;\n" \
168 class Playback3DCommand : public BC_SynchronousCommand
172 void copy_from(BC_SynchronousCommand *command);
178 WRITE_BUFFER = LAST_COMMAND,
193 // Parameters for overlay command
205 int interpolation_type;
211 int64_t start_position_project;
212 MaskAutos *keyframe_set;
214 MaskAuto *default_auto;
215 PluginClient *plugin_client;
219 class Playback3D : public BC_Synchronous
222 Playback3D(MWindow *mwindow);
225 BC_SynchronousCommand* new_command();
226 void handle_command(BC_SynchronousCommand *command);
228 // Called by VDeviceX11::write_buffer during video playback
229 void write_buffer(Canvas *canvas,
241 // Reads from pbuffer to either RAM or texture and updates the dst state
242 // want_texture - causes read into texture if 1
243 void copy_from(Canvas *canvas,
246 int want_texture = 0);
248 // Clear framebuffer before composing virtual console
249 // output - passed when rendering refresh frame. If 0, the canvas is cleared.
250 void clear_output(Canvas *canvas, VFrame *output);
252 void do_fade(Canvas *canvas, VFrame *frame, float fade);
253 void convert_cmodel(Canvas *canvas, VFrame *output, int dst_cmodel);
255 void do_mask(Canvas *canvas,
257 int64_t start_position_project,
258 MaskAutos *keyframe_set,
260 MaskAuto *default_auto);
263 // Overlay a virtual node on the framebuffer
264 void overlay(Canvas *canvas,
274 float alpha, // 0 - 1
276 int interpolation_type,
277 // supplied if rendering single frame to PBuffer.
282 int run_plugin(Canvas *canvas, PluginClient *client);
284 void clear_input(Canvas *canvas, VFrame *frame);
285 void do_camera(Canvas *canvas,
298 // Called by write_buffer and clear_frame to initialize OpenGL flags
299 void init_frame(Playback3DCommand *command);
300 void write_buffer_sync(Playback3DCommand *command);
301 void draw_output(Playback3DCommand *command);
302 void clear_output_sync(Playback3DCommand *command);
303 void clear_input_sync(Playback3DCommand *command);
304 void overlay_sync(Playback3DCommand *command);
305 // Read frame buffer back into texture for overlay operation
306 void enable_overlay_texture(Playback3DCommand *command);
307 void do_fade_sync(Playback3DCommand *command);
308 void do_mask_sync(Playback3DCommand *command);
309 void run_plugin_sync(Playback3DCommand *command);
310 void do_camera_sync(Playback3DCommand *command);
311 // void draw_refresh_sync(Playback3DCommand *command);
312 void copy_from_sync(Playback3DCommand *command);
313 void convert_cmodel_sync(Playback3DCommand *command);
315 // Print errors from shader compilation
316 void print_error(unsigned int object, int is_program);
318 // This quits the program when it's 1.
320 // Temporaries for render to texture
321 BC_Texture *temp_texture;
322 // This is set by clear_output and used in compositing directly
323 // to the output framebuffer.