source: trunk/tools/neercs/video/render.cpp @ 2041

Last change on this file since 2041 was 2041, checked in by rez, 8 years ago

neercs: moved some init variable, removed useless iborder init

File size: 48.4 KB
Line 
1//
2// Neercs
3//
4
5#if defined HAVE_CONFIG_H
6#   include "config.h"
7#endif
8
9#if defined _XBOX
10#   define _USE_MATH_DEFINES /* for M_PI */
11#   include <xtl.h>
12#elif defined _WIN32
13#   define _USE_MATH_DEFINES /* for M_PI */
14#   define WIN32_LEAN_AND_MEAN
15#   include <windows.h>
16#endif
17
18#include <cmath>
19#include <cstdio>
20#include <cstdlib>
21#include <ctime>
22#include <string>
23
24#include "core.h"
25#include "lolgl.h"
26#include "loldebug.h"
27
28using namespace std;
29using namespace lol;
30
31#include "../neercs.h"
32#include "render.h"
33#include "text-render.h"
34
35extern char const *lolfx_simple;
36extern char const *lolfx_blurh;
37extern char const *lolfx_blurv;
38extern char const *lolfx_glow;
39extern char const *lolfx_remanence;
40extern char const *lolfx_copper;
41extern char const *lolfx_color;
42extern char const *lolfx_noise;
43extern char const *lolfx_postfx;
44extern char const *lolfx_mirror;
45extern char const *lolfx_radial;
46
47#define PID M_PI/180.0f    // pi ratio
48
49/*
50 * Global variable -- ugly (<rez> sam: c'est toi qui est ugly! \:D/)
51 */
52bool g_setup = false;
53
54/*
55 * Various variables
56 */
57
58int active = true;         // window active flag
59float nearplane = 0.1f;    // nearplane
60float farplane = 1000.0f;  // farplane
61/* timer variable */
62float timer = 0;           // timer
63/* window variable */
64ivec2 screen_size;         // screen size
65/* object variable */
66float main_angle = 0.0f;   // main angle
67float part_angle = 0.0f;   // part angle
68float fx_angle;            // current angle
69/* fs_quad variable */
70float fs_quad_vtx[] = {-1.0f, 1.0f, 0, 1.0f, -1.0f, -1.0f, 0, 1.0f, 1.0f, -1.0f, 0, 1.0f, 1.0f, 1.0f, 0, 1.0f};
71float fs_quad_tex[] = {0, 1.0f, 0, 0, 1.0f, 0, 1.0f, 1.0f};
72/* flash variable */
73bool flash_flag = false;   // flag
74float flash_angle = 0;     // angle
75float flash_value = 0;     // value
76float flash_speed = 2.0f;  // speed
77/* fade variable */
78bool fade_flag = false;    // flag
79float fade_angle = 0;      // angle
80float fade_value = 0;      // value
81float fade_speed = 0.2f;   // speed
82/* sync variable */
83bool sync_flag = false;    // flagsh
84float sync_angle = 0;      // angle
85float sync_value = 0;      // value
86float sync_speed = 1.0f;   // speed
87/* beat variable */
88bool beat_flag = false;    // flag
89float beat_angle = 0;      // angle
90float beat_value = 0;      // value
91float beat_speed = 2.0f;   // speed
92/* common variable */
93float value, angle, radius, scale, speed;
94/* text variable */
95ivec2 map_size(256,256);        // texture map size
96ivec2 canvas_char(0,0);         // canvas char number
97ivec2 canvas_size(0,0);         // caca size
98ivec2 font_size(8,8);           // font size
99ivec2 ratio_2d(2,3);            // 2d ratio
100ivec2 border(2,1);              // border width
101/* shader variable */
102vec2 buffer(0.2f,0.8f);         // [new frame mix,old frame mix]
103vec2 remanence(0.6f,0.4f);      // remanence [source mix,buffer mix]
104vec2 glow_mix(0.7f,0.3f);       // glow mix [source mix,glow mix]
105vec2 glow_large(3.0f,0.0f);     // large glow radius [center,corner]
106vec2 glow_small(1.5f,0.0f);     // small glow radius [center,corner]
107vec2 blur(0.5f,0.0f);           // blur radius [center,corner]
108vec4 copper_copper(0.75f,0.25f,0.42f,4.0f);     // copper [base,variable,repeat,color cycle]
109vec3 copper_mask_color(4.0f,4.0f,4.0f);         // color [red,green,blue]
110vec3 color_filter(0.9f,0.95f,0.85f);            // color filter [red,green,blue]
111vec4 color_color(1.0f,1.25f,0.1f,0.4f);         // color modifier [brightness,contrast,level,grayscale]
112vec2 noise_offset(1.0f,1.0f);                   // random line [horizontal,vertical]
113float noise_noise = 0.15f;                      // noise
114vec3 noise_retrace(1.0f,1.0f,0.5f);             // retrace [strength,length,speed]
115vec2 postfx_deform(0.8f,0.48f);                 // deformation [ratio,zoom]
116float postfx_vignetting = 0.5f;                 // vignetting strength
117float postfx_aberration = 4.0f;                 // chromatic aberration
118vec4 postfx_ghost1(1.0f,0.0f,0.0f,-0.25f);      // ghost picture 1 [position x,position y,position z,strength]
119vec4 postfx_ghost2(1.5f,0.0f,0.0f,0.25f);       // ghost picture 2 [position x,position y,position z,strength]
120vec4 postfx_glass(8.0f,0.25f,0.75f,0.2f);       // glass [depth,thickness,strength,deform ratio]
121vec4 postfx_moire_h(0.75f,-0.25f,0.0f,1.0f);    // vertical moire [base,variable,repeat,shift]
122vec4 postfx_moire_v(0.75f,-0.25f,1.0f,2.0f);    // horizontal moire [base,variable,repeat,shift]
123vec4 postfx_scanline_h(1.0f,0.0f,0.0f,0.0f);    // vertical scanline [base,variable,repeat,shift]
124vec4 postfx_scanline_v(0.75f,-0.25f,2.0f,0.0f); // horizontal scanline [base,variable,repeat,shift]
125vec3 postfx_corner(0.0f,0.8f,0.96f);            // corner [width,radius,blur]
126vec4 mirror(0.95f,0.9f,0.4f,4.0f);              // mirror [width,height,strength,ratio]
127vec4 radial(4.0f,0.9f,16,0.25f);                // radial [distance,fade ratio,iteration,strength]
128/* setup variable */
129bool setup_switch = false;      // switch [option/item]
130int setup_n = 0;                // item/option number
131int setup_h = 8;                // height
132int setup_cursor = 0;           // cursor position
133int setup_option_i = 0;         // selected option
134int setup_option_n = 14;        // option number
135int setup_option_p = 0;         // option position
136int setup_item_i = 0;           // selected item
137int setup_item_n = 8;           // item number
138int setup_item_p = 0;           // item position
139int setup_item_key = 0;         // item array key
140ivec3 setup_size(29,9,12);      // size [w,h,split]
141ivec2 setup_canvas_size(ivec2(setup_size.x + 1, setup_size.y + 1) * font_size * ivec2(2,4));
142ivec2 setup_color(0xaaa,0x222); // color [foreground,background] 0x678,0x234
143char const *setup_text[] = {
144    "main",
145        "2d ratio w",
146        "2d ratio h",
147        "border w",
148        "border h",
149        "",
150        "",
151        "",
152        "",
153    "remanence",
154        "enable",
155        "buffer new frame",
156        "buffer old frame",
157        "source mix",
158        "buffer mix",
159        "",
160        "",
161        "",
162    "glow",
163        "enable",
164        "source mix",
165        "glow mix",
166        "large center",
167        "large corner",
168        "small center",
169        "small corner",
170        "",
171    "blur",
172        "enable",
173        "blur center",
174        "blur corner",
175        "",
176        "",
177        "",
178        "",
179        "",
180    "screen",
181        "enable",
182        "deform ratio",
183        "zoom base",
184        "corner width",
185        "corner radius",
186        "corner blur",
187        "vignetting",
188        "",
189    "copper",
190        "enable",
191        "base",
192        "variable",
193        "repeat",
194        "color cycle",
195        "color r",
196        "color g",
197        "color b",
198    "color",
199        "filter red",
200        "filter green",
201        "filter blue",
202        "brightness",
203        "contrast",
204        "level",
205        "grayscale",
206        "aberration",
207    "noise",
208        "enable",
209        "offset h",
210        "offset v",
211        "noise",
212        "retrace strength",
213        "retrace length",
214        "retrace speed",
215        "",
216    "ghost",
217        "back x",
218        "back y",
219        "back z",
220        "back strength",
221        "front x",
222        "front y",
223        "front z",
224        "front strength",
225    "glass",
226        "depth",
227        "thickness",
228        "strength",
229        "deform ratio",
230        "",
231        "",
232        "",
233        "",
234    "moire",
235        "h base",
236        "h variable",
237        "h repeat",
238        "h shift",
239        "v base",
240        "v variable",
241        "v repeat",
242        "v shift",
243    "scanline",
244        "h base",
245        "h variable",
246        "h repeat",
247        "h shift",
248        "v base",
249        "v variable",
250        "v repeat",
251        "v shift",
252    "mirror",
253        "enable",
254        "width",
255        "height",
256        "strength",
257        "ratio",
258        "",
259        "",
260        "",
261    "radial",
262        "enable",
263        "distance",
264        "fade ratio",
265        "iteration",
266        "strength",
267        "",
268        "",
269        ""
270    };
271
272vec4 theme_var[]={
273    vec4(0), /* default */
274        vec4(0),
275    vec4(0), /* crt */
276        vec4(0),
277    vec4(0), /* green screen */
278        vec4(0),
279    vec4(0), /* granpa tv */
280        vec4(0)
281    };
282
283vec4 setup_var[]={ // setup variable [start,end,step,value]
284    vec4(0), /* main */
285        vec4(1,  8, 1, ratio_2d.x),
286        vec4(1,  8, 1, ratio_2d.y),
287        vec4(0, 16, 1, border.x),
288        vec4(0, 16, 1, border.y),
289        vec4(0),
290        vec4(0),
291        vec4(0),
292        vec4(0),
293    vec4(0), /* remanence */
294        vec4(0, 1, 1, 1),
295        vec4(0.0f, 1.0f, 0.1f, buffer.x),
296        vec4(0.0f, 1.0f, 0.1f, buffer.y),
297        vec4(0.0f, 1.0f, 0.1f, remanence.x),
298        vec4(0.0f, 1.0f, 0.1f, remanence.y),
299        vec4(0),
300        vec4(0),
301        vec4(0),
302    vec4(0), /* glow */
303        vec4(0, 1, 1, 1),
304        vec4(0.0f, 1.0f, 0.1f, glow_mix.x),
305        vec4(0.0f, 1.0f, 0.1f, glow_mix.y),
306        vec4(0.0f, 4.0f, 0.1f, glow_large.x),
307        vec4(0.0f, 4.0f, 0.1f, glow_large.y),
308        vec4(0.0f, 2.0f, 0.1f, glow_small.x),
309        vec4(0.0f, 2.0f, 0.1f, glow_small.y),
310        vec4(0),
311    vec4(0), /* blur */
312        vec4(0, 1, 1, 1),
313        vec4(0, 2, 0.05f, blur.x),
314        vec4(0, 2, 0.05f, blur.y),
315        vec4(0),
316        vec4(0),
317        vec4(0),
318        vec4(0),
319        vec4(0),
320    vec4(0), /* screen */
321        vec4(0, 1, 1, 1),
322        vec4(0.0f, 1.0f, 0.05f, postfx_deform.x),
323        vec4(0.2f, 0.7f, 0.01f, postfx_deform.y),
324        vec4(0.0f, 4.0f, 0.10f, postfx_corner.x),
325        vec4(0.0f, 1.0f, 0.05f, postfx_corner.y),
326        vec4(0.8f, 1.0f, 0.01f, postfx_corner.z),
327        vec4(0.0f, 1.0f, 0.10f, postfx_vignetting),
328        vec4(0),
329    vec4(0), /* copper */
330        vec4(0, 1, 1, 1),
331        vec4(0.0f, 1.0f, 0.05f, copper_copper.x),
332        vec4(0.0f, 1.0f, 0.05f, copper_copper.y),
333        vec4(0.0f, 1.0f, 0.02f, copper_copper.z),
334        vec4(1.0f, 8.0f, 0.25f, copper_copper.w),
335        vec4(0.0f, 4.0f, 0.25f, copper_mask_color.x),
336        vec4(0.0f, 4.0f, 0.25f, copper_mask_color.y),
337        vec4(0.0f, 4.0f, 0.25f, copper_mask_color.z),
338    vec4(0), /* color */
339        vec4( 0.0f, 1.0f, 0.05f, color_filter.x),
340        vec4( 0.0f, 1.0f, 0.05f, color_filter.y),
341        vec4( 0.0f, 1.0f, 0.05f, color_filter.z),
342        vec4( 0.0f, 2.0f, 0.05f, color_color.x),
343        vec4( 0.0f, 2.0f, 0.05f, color_color.y),
344        vec4(-1.0f, 1.0f, 0.05f, color_color.z),
345        vec4( 0.0f, 1.0f, 0.05f, color_color.w),
346        vec4( 0.0f, 8.0f, 0.50f, postfx_aberration),
347    vec4(0), /* noise */
348        vec4(0, 1, 1, 1),
349        vec4(0.0f, 4.0f, 0.50f, noise_offset.x),
350        vec4(0.0f, 4.0f, 0.50f, noise_offset.y),
351        vec4(0.0f, 0.5f, 0.05f, noise_noise),
352        vec4(0.0f, 4.0f, 0.25f, noise_retrace.x),
353        vec4(0.0f, 8.0f, 0.50f, noise_retrace.y),
354        vec4(0.0f, 4.0f, 0.25f, noise_retrace.z),
355        vec4(0),
356    vec4(0), /* ghost */
357        vec4(-2.0f, 2.0f, 0.10f, postfx_ghost1.x),
358        vec4(-2.0f, 2.0f, 0.10f, postfx_ghost1.y),
359        vec4(-2.0f, 2.0f, 0.10f, postfx_ghost1.z),
360        vec4(-1.0f, 1.0f, 0.05f, postfx_ghost1.w),
361        vec4(-2.0f, 2.0f, 0.10f, postfx_ghost2.x),
362        vec4(-2.0f, 2.0f, 0.10f, postfx_ghost2.y),
363        vec4(-2.0f, 2.0f, 0.10f, postfx_ghost2.z),
364        vec4(-1.0f, 1.0f, 0.05f, postfx_ghost2.w),
365    vec4(0), /* glass */
366        vec4(0.0f, 16.0f, 0.50f, postfx_glass.x),
367        vec4(0.0f,  1.0f, 0.05f, postfx_glass.y),
368        vec4(0.0f,  2.0f, 0.05f, postfx_glass.z),
369        vec4(0.0f,  1.0f, 0.05f, postfx_glass.w),
370        vec4(0),
371        vec4(0),
372        vec4(0),
373        vec4(0),
374    vec4(0), /* moire */
375        vec4( 0.5f, 1.0f, 0.05f, postfx_moire_h.x),
376        vec4(-0.5f, 0.5f, 0.05f, postfx_moire_h.y),
377        vec4( 0.0f, 4.0f, 0.50f, postfx_moire_h.z),
378        vec4( 0.0f, 4.0f, 0.50f, postfx_moire_h.w),
379        vec4( 0.5f, 1.0f, 0.05f, postfx_moire_v.x),
380        vec4(-0.5f, 0.5f, 0.05f, postfx_moire_v.y),
381        vec4( 0.0f, 4.0f, 0.50f, postfx_moire_v.z),
382        vec4( 0.0f, 4.0f, 0.50f, postfx_moire_v.w),
383    vec4(0), /* scanline */
384        vec4( 0.5f, 1.0f, 0.05f, postfx_scanline_h.x),
385        vec4(-0.5f, 0.5f, 0.05f, postfx_scanline_h.y),
386        vec4( 0.0f, 4.0f, 0.50f, postfx_scanline_h.z),
387        vec4( 0.0f, 4.0f, 0.50f, postfx_scanline_h.w),
388        vec4( 0.5f, 1.0f, 0.05f, postfx_scanline_v.x),
389        vec4(-0.5f, 0.5f, 0.05f, postfx_scanline_v.y),
390        vec4( 0.0f, 4.0f, 0.50f, postfx_scanline_v.z),
391        vec4( 0.0f, 4.0f, 0.50f, postfx_scanline_v.w),
392    vec4(0), /* mirror */
393        vec4(0, 1, 1, 1),
394        vec4(0.0f, 2.0f, 0.05f, mirror.x),
395        vec4(0.0f, 2.0f, 0.05f, mirror.y),
396        vec4(0.0f, 1.0f, 0.05f, mirror.z),
397        vec4(1.0f, 8.0f, 1.00f, mirror.w),
398        vec4(0),
399        vec4(0),
400        vec4(0),
401    vec4(0), /* radial blur */
402        vec4(0, 1, 1, 1),
403        vec4(2.0f, 8.0f, 0.25f, radial.x),
404        vec4(0.8f, 1.0f, 0.01f, radial.y),
405        vec4(2.0f,32.0f, 2.00f, radial.z),
406        vec4(0.0f, 1.0f, 0.05f, radial.w),
407        vec4(0),
408        vec4(0),
409        vec4(0),
410    vec4(0) /* ? */
411    };
412
413void Render::UpdateVar()
414{
415    int k = 1; /* main */
416    ratio_2d = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
417    border = vec2(setup_var[k].w, setup_var[k + 1].w) * ratio_2d * font_size; k += 2;
418    k += 5; /* remanence */
419    m_shader_remanence = (setup_var[k].w == 1) ? true : false; k++;
420    buffer = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
421    remanence = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
422    k += 4; /* glow */
423    m_shader_glow = (setup_var[k].w == 1) ? true : false; k++;
424    glow_mix = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
425    glow_large = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
426    glow_small = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
427    k += 2; /* blur */
428    m_shader_blur = (setup_var[k].w == 1) ? true : false; k++;
429    blur = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
430    k += 6; /* screen */
431    m_shader_postfx = (setup_var[k].w == 1) ? true : false; k++;
432    postfx_deform = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
433    postfx_corner = vec3(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w); k += 3;
434    postfx_vignetting = setup_var[k].w; k++;
435    k += 2; /* copper */
436    m_shader_copper = (setup_var[k].w == 1) ? true : false; k++;
437    copper_copper = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4;
438    copper_mask_color = vec3(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w); k += 3;
439    k += 1; /* color */
440    color_filter = vec3(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w); k += 3;
441    color_color = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4;
442    postfx_aberration = setup_var[k].w; k++;
443    k += 1; /* noise */
444    m_shader_noise = (setup_var[k].w == 1) ? true : false; k++;
445    noise_offset = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
446    noise_noise = setup_var[k].w; k++;
447    noise_retrace = vec3(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w); k += 3;
448    k += 2; /* ghost */
449    postfx_ghost1 = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4;
450    postfx_ghost2 = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4;
451    k += 1; /* glass */
452    postfx_glass = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4;
453    k += 5; /* moire */
454    postfx_moire_h = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4;
455    postfx_moire_v = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4;
456    k += 1; /* scanline */
457    postfx_scanline_h = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4;
458    postfx_scanline_v = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4;
459    k += 1; /* mirror */
460    m_shader_mirror = (setup_var[k].w == 1) ? true : false; k++;
461    mirror = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4;
462    k += 4; /* radial blur */
463    m_shader_radial = (setup_var[k].w == 1) ? true : false; k++;
464    radial = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4;
465    UpdateSize();
466}
467
468void Render::UpdateSize()
469{
470    screen_size = Video::GetSize();
471    canvas_char = (screen_size - border * 2) / (font_size * ratio_2d);
472    canvas_char = max(canvas_char, ivec2(1, 1));
473    canvas_size = canvas_char * font_size * ratio_2d;
474
475    border = (screen_size - canvas_size) / 2;
476
477    caca_set_canvas_size(m_cv_screen, canvas_char.x, canvas_char.y);
478    caca_set_canvas_size(m_cv_setup, setup_size.x + 1, setup_size.y + 1);
479}
480
481int calc_item_length()
482{
483    int n = !setup_switch ? setup_option_n : setup_item_n;
484    for (int i = 0; i < n; i++)
485    {
486        int k = !setup_switch ? (i * (setup_item_n + 1)) : (setup_option_i * (setup_item_n + 1) + 1 + i);
487        if (setup_text[k][0] == '\0') return i - 1;
488    }
489    return n - 1;
490}
491
492Shader *shader_simple;
493Shader *shader_blur_h, *shader_blur_v, *shader_glow;
494Shader *shader_remanence, *shader_copper, *shader_color;
495Shader *shader_noise, *shader_postfx, *shader_mirror, *shader_radial;
496// shader variables
497ShaderUniform shader_simple_texture;
498ShaderUniform shader_blur_h_texture,
499              shader_blur_h_radius,
500              shader_blur_v_texture,
501              shader_blur_v_radius;
502ShaderUniform shader_glow_glow,
503              shader_glow_source,
504              shader_glow_mix;
505ShaderUniform shader_remanence_source,
506              shader_remanence_buffer,
507              shader_remanence_mix;
508ShaderUniform shader_copper_texture,
509              shader_copper_screen_size,
510              shader_copper_time,
511              shader_copper_copper,
512              shader_copper_mask_color;
513ShaderUniform shader_color_texture,
514              shader_color_screen_size,
515              shader_color_filter,
516              shader_color_color,
517              shader_color_flash;
518ShaderUniform shader_noise_texture,
519              shader_noise_screen_size,
520              shader_noise_time,
521              shader_noise_offset,
522              shader_noise_noise,
523              shader_noise_retrace;
524ShaderUniform shader_postfx_texture,
525              shader_postfx_texture_2d,
526              shader_postfx_screen_size,
527              shader_postfx_ratio_2d,
528              shader_postfx_time,
529              shader_postfx_deform,
530              shader_postfx_ghost1,
531              shader_postfx_ghost2,
532              shader_postfx_glass,
533              shader_postfx_vignetting,
534              shader_postfx_aberration,
535              shader_postfx_moire_h,
536              shader_postfx_moire_v,
537              shader_postfx_scanline_h,
538              shader_postfx_scanline_v,
539              shader_postfx_corner,
540              shader_postfx_sync,
541              shader_postfx_beat;
542ShaderUniform shader_mirror_texture,
543              shader_mirror_screen_size,
544              shader_mirror_mirror;
545ShaderUniform shader_radial_texture,
546              shader_radial_screen_size,
547              shader_radial_radial;
548
549FrameBuffer *fbo_back, *fbo_front, *fbo_screen;
550FrameBuffer *fbo_blur_h, *fbo_blur_v;
551FrameBuffer *fbo_tmp, *fbo_buffer;
552
553void Render::TraceQuad()
554{
555    glLoadIdentity();
556    glDrawArrays(GL_QUADS, 0, 4);
557}
558
559void Render::ShaderSimple(FrameBuffer *fbo_output, int n)
560{
561    shader_simple->Bind();
562    shader_simple->SetUniform(shader_simple_texture, fbo_output->GetTexture(), n);
563    TraceQuad();
564    shader_simple->Unbind();
565}
566
567int Render::InitDraw(void)
568{
569    glDepthMask(GL_TRUE);     // do not write z-buffer
570    glEnable(GL_CULL_FACE);   // disable cull face
571    glCullFace(GL_BACK);      // don't draw front face
572
573    /* initialise framebuffer objects */
574    fbo_back = new FrameBuffer(screen_size);
575    fbo_screen = new FrameBuffer(screen_size);
576    fbo_front = new FrameBuffer(screen_size);
577    fbo_buffer = new FrameBuffer(screen_size);
578    fbo_blur_h = new FrameBuffer(screen_size);
579    fbo_blur_v = new FrameBuffer(screen_size);
580    fbo_tmp = new FrameBuffer(screen_size);
581    // shader simple
582    shader_simple = Shader::Create(lolfx_simple);
583    shader_simple_texture = shader_simple->GetUniformLocation("texture");
584    // shader glow
585    shader_glow = Shader::Create(lolfx_glow);
586    shader_glow_glow = shader_glow->GetUniformLocation("glow");
587    shader_glow_source = shader_glow->GetUniformLocation("source");
588    shader_glow_mix = shader_glow->GetUniformLocation("mix");
589    // shader blur horizontal
590    shader_blur_h = Shader::Create(lolfx_blurh);
591    shader_blur_h_texture = shader_blur_h->GetUniformLocation("texture");
592    shader_blur_h_radius = shader_blur_h->GetUniformLocation("radius");
593    // shader blur vertical
594    shader_blur_v = Shader::Create(lolfx_blurv);
595    shader_blur_v_texture = shader_blur_v->GetUniformLocation("texture");
596    shader_blur_v_radius = shader_blur_v->GetUniformLocation("radius");
597    // shader remanence
598    shader_remanence = Shader::Create(lolfx_remanence);
599    shader_remanence_source = shader_remanence->GetUniformLocation("source");
600    shader_remanence_buffer = shader_remanence->GetUniformLocation("buffer");
601    shader_remanence_mix = shader_remanence->GetUniformLocation("mix");
602    // shader copper
603    shader_copper = Shader::Create(lolfx_copper);
604    shader_copper_texture = shader_copper->GetUniformLocation("texture");
605    shader_copper_screen_size = shader_copper->GetUniformLocation("screen_size");
606    shader_copper_time = shader_copper->GetUniformLocation("time");
607    shader_copper_copper = shader_copper->GetUniformLocation("copper");
608    shader_copper_mask_color = shader_copper->GetUniformLocation("mask_color");
609    // shader color
610    shader_color = Shader::Create(lolfx_color);
611    shader_color_texture = shader_color->GetUniformLocation("texture");
612    shader_color_screen_size = shader_color->GetUniformLocation("screen_size");
613    shader_color_filter = shader_color->GetUniformLocation("filter");
614    shader_color_color = shader_color->GetUniformLocation("color");
615    shader_color_flash = shader_color->GetUniformLocation("flash");
616    // shader noise
617    shader_noise = Shader::Create(lolfx_noise);
618    shader_noise_texture = shader_noise->GetUniformLocation("texture");
619    shader_noise_screen_size = shader_noise->GetUniformLocation("screen_size");
620    shader_noise_time = shader_noise->GetUniformLocation("time");
621    shader_noise_offset = shader_noise->GetUniformLocation("offset");
622    shader_noise_noise = shader_noise->GetUniformLocation("noise");
623    shader_noise_retrace = shader_noise->GetUniformLocation("retrace");
624    // shader postfx
625    shader_postfx = Shader::Create(lolfx_postfx);
626    shader_postfx_texture = shader_postfx->GetUniformLocation("texture");
627    shader_postfx_texture_2d = shader_postfx->GetUniformLocation("texture_2d");
628    shader_postfx_screen_size = shader_postfx->GetUniformLocation("screen_size");
629    shader_postfx_ratio_2d = shader_postfx->GetUniformLocation("ratio_2d");
630    shader_postfx_time = shader_postfx->GetUniformLocation("time");
631    shader_postfx_deform = shader_postfx->GetUniformLocation("deform");
632    shader_postfx_ghost1 = shader_postfx->GetUniformLocation("ghost1");
633    shader_postfx_ghost2 = shader_postfx->GetUniformLocation("ghost2");
634    shader_postfx_glass = shader_postfx->GetUniformLocation("glass");
635    shader_postfx_vignetting = shader_postfx->GetUniformLocation("vignetting");
636    shader_postfx_aberration = shader_postfx->GetUniformLocation("aberration");
637    shader_postfx_moire_h = shader_postfx->GetUniformLocation("moire_h");
638    shader_postfx_moire_v = shader_postfx->GetUniformLocation("moire_v");
639    shader_postfx_scanline_h = shader_postfx->GetUniformLocation("scanline_h");
640    shader_postfx_scanline_v = shader_postfx->GetUniformLocation("scanline_v");
641    shader_postfx_corner = shader_postfx->GetUniformLocation("corner");
642    shader_postfx_sync = shader_postfx->GetUniformLocation("sync");
643    shader_postfx_beat = shader_postfx->GetUniformLocation("beat");
644    // shader mirror
645    shader_mirror = Shader::Create(lolfx_mirror);
646    shader_mirror_texture = shader_mirror->GetUniformLocation("texture");
647    shader_mirror_screen_size = shader_mirror->GetUniformLocation("screen_size");
648    shader_mirror_mirror = shader_mirror->GetUniformLocation("mirror");
649    // shader radial blur
650    shader_radial = Shader::Create(lolfx_radial);
651    shader_radial_texture = shader_radial->GetUniformLocation("texture");
652    shader_radial_screen_size = shader_radial->GetUniformLocation("screen_size");
653    shader_radial_radial = shader_radial->GetUniformLocation("radial");
654    // initialize setup
655    setup_n = calc_item_length();
656    return true;
657}
658
659int Render::CreateGLWindow()
660{
661    UpdateSize();
662    InitDraw();
663    return true;
664}
665
666Render::Render(caca_canvas_t *caca)
667  : m_cv_screen(caca),
668    m_cv_setup(caca_create_canvas(1, 1)),
669    m_fps_debug(0),
670    m_ready(false),
671    m_pause(false),
672    m_shader(true),
673    m_shader_glow(true),
674    m_shader_blur(true),
675    m_shader_remanence(true),
676    m_shader_copper(true),
677    m_shader_color(true),
678    m_shader_noise(true),
679    m_shader_postfx(true),
680    m_shader_mirror(true),
681    m_shader_radial(true)
682{
683    m_txt_screen = new TextRender(m_cv_screen, font_size);
684    m_txt_setup = new TextRender(m_cv_setup, font_size);
685}
686
687void Render::TickGame(float seconds)
688{
689    Entity::TickGame(seconds);
690    /* draw setup */
691    if (g_setup)
692    {
693        /* background */
694        caca_set_color_argb(m_cv_setup, setup_color.x, setup_color.y);
695        caca_fill_box(m_cv_setup, 0, 0, setup_size.x + 1, setup_size.y,' ');
696        caca_draw_line(m_cv_setup, setup_size.z - 1, 1, setup_size.z - 1, setup_size.y - 1,'|');
697        /* title */
698        caca_set_color_argb(m_cv_setup, setup_color.y, setup_color.x);
699        caca_draw_line(m_cv_setup, 0, 0, setup_size.x, 0, ' ');
700        caca_put_str(m_cv_setup, setup_size.x / 2 - 3, 0, "SETUP");
701        /* informations */
702        /*
703        int w = caca_get_canvas_width(m_cv_screen);
704        int h = caca_get_canvas_height(m_cv_screen);
705        caca_set_color_argb(m_cv_setup, setup_color.y, setup_color.x);
706        caca_printf(m_cv_setup, 1, 0, "%i*%i", w, h);
707        */
708        /* display option */
709        for (int i = 0; i < setup_h; i++)
710        {
711            int y = 1 + i;
712            int k = (setup_option_p + i) * (setup_item_n + 1);
713            if (setup_option_i != setup_option_p + i || setup_switch)
714            {
715                caca_set_color_argb(m_cv_setup, setup_color.x, setup_color.y);
716                caca_put_str(m_cv_setup, 1, y, setup_text[k]);
717            }
718            else
719            {
720                caca_set_color_argb(m_cv_setup, setup_color.y, 0xfff);//setup_color.x);
721                caca_draw_line(m_cv_setup, 0, y, setup_size.z - 2, y,' ');
722                caca_put_str(m_cv_setup, 1, y, setup_text[k]);
723            }
724        }
725        /* display item */
726        for (int i = 0; i < setup_h; i++)
727        {
728            int y = 1 + i;
729            int k = setup_option_i * (setup_item_n + 1) + 1 + setup_item_p + i;
730            if (setup_item_i != setup_item_p + i || !setup_switch)
731            {
732                caca_set_color_argb(m_cv_setup, setup_color.x, setup_color.y);
733                caca_put_str(m_cv_setup, setup_size.z + 1, y, setup_text[k]);
734            }
735            else
736            {
737                caca_set_color_argb(m_cv_setup, setup_color.y, 0xfff);//setup_color.x);
738                caca_draw_line(m_cv_setup, setup_size.z, y, setup_size.x, y,' ');
739                caca_put_str(m_cv_setup, setup_size.z + 1, y, setup_text[k]);
740            }
741        }
742        /* display variable */
743        int y = setup_size.y;
744        setup_item_key = setup_option_i * (setup_item_n + 1) + 1 + setup_item_i;
745        caca_set_color_argb(m_cv_setup, setup_color.y, setup_color.x);
746        caca_draw_line(m_cv_setup, 0, y, setup_size.x, y,' ');
747        if (setup_switch)
748        {
749            int x = 1;
750            int w = setup_size.x - 3 - 4;
751            float bar_w = w / (setup_var[setup_item_key].y - setup_var[setup_item_key].x);
752            int bar_x = bar_w * setup_var[setup_item_key].x;
753            if ((setup_var[setup_item_key].y - setup_var[setup_item_key].x) / setup_var[setup_item_key].z > 1)
754            {
755                /* Work around a bug in libcaca */
756                if (setup_size.x - 4 < caca_get_canvas_width(m_cv_setup)) caca_printf(m_cv_setup, setup_size.x - 4, y, "%4.2f", setup_var[setup_item_key].w);
757                caca_draw_line(m_cv_setup, x, y, x - bar_x + int(bar_w * setup_var[setup_item_key].y), y,'.');
758                if (setup_var[setup_item_key].w != setup_var[setup_item_key].x) caca_draw_line(m_cv_setup, x, y, x - bar_x + int(bar_w * setup_var[setup_item_key].w), y, 'x');
759            }
760            else
761            {
762                if (setup_var[setup_item_key] != vec4(0))
763                {
764                    caca_put_str(m_cv_setup, setup_size.x - 3, y, (setup_var[setup_item_key].w == setup_var[setup_item_key].y)?"YES":" NO");
765                }
766            }
767        }
768        else
769        {
770            caca_printf(m_cv_setup, 1, y, "%d/%d", setup_option_i, setup_n);
771        }
772    }
773
774}
775
776void Render::Pause()
777{
778    m_pause=!m_pause;
779}
780
781void Render::TickDraw(float seconds)
782{
783    /* keyboard manager */
784    if (Input::WasPressed(Key::F1))
785    {
786        g_setup = !g_setup;
787        if (g_setup) setup_n = calc_item_length();
788        sync_flag = true;
789        sync_angle = main_angle;
790
791        if (m_fps_debug)
792        {
793            Ticker::Unref(m_fps_debug);
794            m_fps_debug = NULL;
795        }
796
797        if (g_setup)
798        {
799            m_fps_debug = new DebugFps(2, 2);
800            Ticker::Ref(m_fps_debug);
801        }
802    }
803    if (Input::WasPressed(Key::F2))
804    {
805        m_shader_glow = !m_shader_glow;
806        m_shader_blur = !m_shader_blur;
807        m_shader_remanence = !m_shader_remanence;
808        //m_shader_copper = !m_shader_copper;
809        m_shader_color = !m_shader_color;
810        m_shader_noise = !m_shader_noise;
811        m_shader_postfx = !m_shader_postfx;
812        m_shader_mirror = !m_shader_mirror;
813        m_shader_radial = !m_shader_radial;
814    }
815   if (Input::WasPressed(Key::Tab))
816    {
817        if (g_setup)
818        {
819            setup_switch = !setup_switch;
820            setup_n = calc_item_length();
821            setup_cursor = (!setup_switch?setup_option_i:setup_item_i) - (!setup_switch?setup_option_p:setup_item_p);
822        }
823    }
824    if (Input::WasPressed(Key::Up))
825    {
826        if (g_setup)
827        {
828            if (!setup_switch)
829            {
830                if (setup_cursor > 0)
831                {
832                    setup_cursor--;
833                }
834                else
835                {
836                    if (setup_cursor == 0) setup_option_p--;
837                }
838                if (setup_option_i > 0)
839                {
840                    setup_option_i--;
841                }
842                else
843                {
844                    setup_option_i = setup_option_n - 1;
845                    setup_option_p = setup_option_n - setup_h;
846                    setup_cursor = setup_h - 1;
847                }
848                setup_item_i = 0;
849                setup_item_p = 0;
850            }
851            else
852            {
853                if (setup_cursor > 0)
854                {
855                    setup_cursor--;
856                }
857                else
858                {
859                    if (setup_cursor == 0) setup_item_p--;
860                }
861                if (setup_item_i > 0)
862                {
863                    setup_item_i--;
864                }
865                else
866                {
867                    setup_item_i = setup_n;
868                    setup_item_p = (setup_n < setup_h) ? 0 : setup_n - setup_h + 1;
869                    setup_cursor = (setup_n < setup_h) ? setup_n : setup_h - 1;
870                }
871            }
872        }
873    }
874    if (Input::WasPressed(Key::Down))
875    {
876        if (g_setup)
877        {
878            if (!setup_switch)
879            {
880                if (setup_cursor < setup_h - 1)
881                {
882                    setup_cursor++;
883                }
884                else
885                {
886                    if (setup_cursor == setup_h - 1) setup_option_p++;
887                }
888                if (setup_option_i < setup_option_n - 1)
889                {
890                    setup_option_i++;
891                }
892                else
893                {
894                    setup_option_i = 0;
895                    setup_option_p = 0;
896                    setup_cursor = 0;
897                }
898                setup_item_i = 0;
899                setup_item_p = 0;
900            }
901            else
902            {
903                if (setup_cursor < setup_h - 1)
904                {
905                    setup_cursor++;
906                }
907                else
908                {
909                    if (setup_cursor == setup_h - 1) setup_item_p++;
910                }
911                if (setup_item_i < setup_n)
912                {
913                    setup_item_i++;
914                }
915                else
916                {
917                    setup_item_i = 0;
918                    setup_item_p = 0;
919                    setup_cursor = 0;
920                }
921            }
922        }
923    }
924    if (Input::WasPressed(Key::PageUp))
925    {
926        if (g_setup)
927        {
928            if (!setup_switch)
929            {
930                if (setup_cursor > 0)
931                {
932                    setup_option_i -= setup_cursor;
933                    setup_cursor = 0;
934                }
935                else
936                {
937                    if (setup_option_i > setup_h)
938                    {
939                        setup_option_i -= setup_h;
940                        setup_option_p -= setup_h;
941                    }
942                else
943                    {
944                        setup_option_i = 0;
945                        setup_option_p = 0;
946                    }
947                }
948            setup_item_i = 0;
949            }
950            else
951            {
952                if (setup_cursor > 0)
953                {
954                    setup_item_i -= setup_cursor;
955                    setup_cursor = 0;
956                }
957                else
958                {
959                    if (setup_item_i > setup_h)
960                    {
961                        setup_item_i -= setup_h;
962                        setup_item_p -= setup_h;
963                    }
964                else
965                    {
966                        setup_item_i = 0;
967                        setup_item_p = 0;
968                    }
969                }
970            }
971        }
972    }
973    if (Input::WasPressed(Key::PageDown))
974    {
975        if (g_setup)
976        {
977            if (!setup_switch)
978            {
979                if (setup_cursor < setup_h - 1)
980                {
981                    setup_option_i += setup_h - setup_cursor - 1;
982                    setup_cursor = setup_h - 1;
983                    setup_item_i = 0;
984                }
985                else
986                {
987                    if (setup_option_i < setup_option_n - setup_h - 1)
988                    {
989                        setup_option_i += setup_h;
990                        setup_option_p += setup_h;
991                    }
992                else
993                    {
994                        setup_option_i = setup_option_n - 1;
995                        setup_option_p = setup_option_n - setup_h;
996                    }
997                }
998            }
999            else
1000            {
1001                if (setup_cursor < setup_h - 1)
1002                {
1003                    setup_item_i += (setup_n < setup_h) ? setup_n - setup_cursor : setup_h - setup_cursor - 1;
1004                    setup_cursor = (setup_n < setup_h) ? setup_n : setup_h - 1;
1005                }
1006                else
1007                {
1008                    if (setup_item_i < setup_n - setup_h + 1)
1009                    {
1010                        setup_item_i += setup_h;
1011                        setup_item_p += setup_h;
1012                    }
1013                else
1014                    {
1015                        setup_item_i = setup_n;
1016                        setup_item_p = setup_n - setup_h + 1;
1017                    }
1018                }
1019            }
1020        }
1021    }
1022    if (Input::WasPressed(Key::Left))
1023    {
1024        if (g_setup && setup_switch)
1025        {
1026            setup_var[setup_item_key].w -= setup_var[setup_item_key].z;
1027            if (setup_var[setup_item_key].w < setup_var[setup_item_key].x) setup_var[setup_item_key].w = setup_var[setup_item_key].x;
1028            UpdateVar();
1029        }
1030    }
1031    if (Input::WasPressed(Key::Right))
1032    {
1033        if (g_setup && setup_switch)
1034        {
1035            setup_var[setup_item_key].w += setup_var[setup_item_key].z;
1036            if (setup_var[setup_item_key].w > setup_var[setup_item_key].y) setup_var[setup_item_key].w = setup_var[setup_item_key].y;
1037            UpdateVar();
1038        }
1039    }
1040    if (Input::WasPressed(Key::Home))
1041    {
1042        if (g_setup && setup_switch)
1043        {
1044            setup_var[setup_item_key].w = setup_var[setup_item_key].x;
1045            UpdateVar();
1046        }
1047    }
1048    if (Input::WasPressed(Key::End))
1049    {
1050        if (g_setup && setup_switch)
1051        {
1052            setup_var[setup_item_key].w = setup_var[setup_item_key].y;
1053            UpdateVar();
1054        }
1055    }
1056    if (Input::WasPressed(Key::Return))
1057    {
1058        beat_flag = true;
1059        beat_angle = main_angle;
1060        //flash_flag = true;
1061        //flash_angle = main_angle;
1062    }
1063
1064    Entity::TickDraw(seconds);
1065
1066    if (!m_ready)
1067    {
1068        CreateGLWindow();
1069        m_txt_screen->Init();
1070        m_txt_setup->Init();
1071        m_ready = true;
1072    }
1073
1074    // timer
1075    if (!m_pause)
1076    {
1077        timer += seconds;
1078        main_angle = timer * 100.0f * PID;
1079    }
1080    if (sync_flag)
1081    {
1082        angle = (main_angle - sync_angle) * sync_speed;
1083        sync_value = 1.0f - sinf(angle);
1084        if (angle > 90.0f * PID)
1085        {
1086            sync_value = 0;
1087            sync_flag = false;
1088        }
1089    }
1090    if (beat_flag)
1091    {
1092        angle = (main_angle - beat_angle) * beat_speed;
1093        beat_value = 1.0f - sinf(angle);
1094        if (angle > 90.0f * PID)
1095        {
1096            beat_value = 0;
1097            beat_flag = false;
1098        }
1099    }
1100    if (flash_flag)
1101    {
1102        angle = (main_angle - flash_angle) * flash_speed;
1103        flash_value = 1.0f - sinf(angle);
1104        if (angle > 90.0f * PID)
1105        {
1106            flash_value = 0;
1107            flash_flag = false;
1108        }
1109    }
1110    if (fade_flag)
1111    {
1112        angle = (main_angle - fade_angle) * fade_speed;
1113        fade_value = 1.0f - sinf(angle);
1114        if (angle > 90.0f * PID)
1115        {
1116            fade_value = 0;
1117            fade_flag = false;
1118        }
1119    }
1120
1121    Draw2D();
1122    Draw3D();
1123}
1124
1125void Render::Draw2D()
1126{
1127    /* Draw text in an offline buffer */
1128    m_txt_screen->Render();
1129
1130    if (g_setup)
1131        m_txt_setup->Render();
1132
1133    if (m_shader)
1134        fbo_back->Bind();
1135
1136    glViewport(0, 0, screen_size.x, screen_size.y);
1137
1138    /* Clear the back buffer */
1139    glEnable(GL_TEXTURE_2D);
1140    glEnable(GL_BLEND);
1141    glBlendFunc(GL_SRC_COLOR, GL_DST_ALPHA);
1142
1143    Video::SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f));
1144    Video::SetClearDepth(1.0f); // set depth buffer
1145    Video::Clear(ClearMask::Color | ClearMask::Depth);
1146
1147    m_txt_screen->Blit(border, canvas_size);
1148    if (g_setup)
1149        m_txt_setup->Blit((screen_size - setup_canvas_size) / 2, setup_canvas_size);
1150
1151    glMatrixMode(GL_PROJECTION);
1152    mat4 m = mat4::ortho(0, screen_size.x, screen_size.y, 0, -1.f, 1.f);
1153    glLoadMatrixf(&m[0][0]);
1154    glMatrixMode(GL_MODELVIEW);
1155
1156    fx_angle=main_angle-part_angle;
1157}
1158
1159void Render::Draw3D()
1160{
1161    if (!m_shader)
1162        return;
1163
1164    glDisable(GL_DEPTH_TEST);
1165    glDisable(GL_BLEND);
1166
1167    glEnableClientState(GL_VERTEX_ARRAY);
1168    glVertexPointer(4, GL_FLOAT, 0, fs_quad_vtx);
1169
1170    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1171    glTexCoordPointer(2, GL_FLOAT, 0, fs_quad_tex);
1172
1173    if (m_shader_copper)
1174    {
1175        // shader copper
1176        fbo_tmp->Bind();
1177        shader_copper->Bind();
1178        shader_copper->SetUniform(shader_copper_texture, fbo_back->GetTexture(), 0);
1179        shader_copper->SetUniform(shader_copper_screen_size, (vec2)screen_size);
1180        shader_copper->SetUniform(shader_copper_time, fx_angle);
1181        shader_copper->SetUniform(shader_copper_copper, vec4(copper_copper.x, copper_copper.y, copper_copper.z * 16.0f, copper_copper.w * 16.0f));
1182        shader_copper->SetUniform(shader_copper_mask_color, copper_mask_color / 4.0f);
1183        TraceQuad();
1184        shader_color->Unbind();
1185        fbo_tmp->Unbind();
1186        // shader simple
1187        fbo_back->Bind();
1188        ShaderSimple(fbo_tmp, 0);
1189        fbo_back->Unbind();
1190    }
1191
1192    if (m_shader_remanence)
1193    {
1194        // shader remanence
1195        fbo_tmp->Bind();
1196        shader_remanence->Bind();
1197        shader_remanence->SetUniform(shader_remanence_source, fbo_back->GetTexture(), 0);
1198        shader_remanence->SetUniform(shader_remanence_buffer, fbo_buffer->GetTexture(), 1);
1199        shader_remanence->SetUniform(shader_remanence_mix, remanence);
1200        TraceQuad();
1201        shader_remanence->Unbind();
1202        fbo_tmp->Unbind();
1203        // shader simple
1204        fbo_back->Bind();
1205        ShaderSimple(fbo_tmp, 0);
1206        fbo_back->Unbind();
1207        // save previous fbo
1208        fbo_tmp->Bind();
1209        shader_remanence->Bind();
1210        shader_remanence->SetUniform(shader_remanence_source, fbo_screen->GetTexture(), 0);
1211        shader_remanence->SetUniform(shader_remanence_buffer, fbo_buffer->GetTexture(), 1);
1212        shader_remanence->SetUniform(shader_remanence_mix, buffer);
1213        TraceQuad();
1214        shader_remanence->Unbind();
1215        fbo_tmp->Unbind();
1216        // shader simple
1217        fbo_buffer->Bind();
1218        ShaderSimple(fbo_tmp, 0);
1219        fbo_buffer->Unbind();
1220    }
1221
1222    // shader glow
1223    if (m_shader_glow)
1224    {
1225        // shader blur horizontal
1226        fbo_blur_h->Bind();
1227        shader_blur_h->Bind();
1228        shader_blur_h->SetUniform(shader_blur_h_texture, fbo_back->GetTexture(), 0);
1229        shader_blur_h->SetUniform(shader_blur_h_radius, glow_large / screen_size.x);
1230        TraceQuad();
1231        shader_blur_h->Unbind();
1232        fbo_blur_h->Unbind();
1233        // shader blur vertical
1234        fbo_blur_v->Bind();
1235        shader_blur_v->Bind();
1236        shader_blur_v->SetUniform(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
1237        shader_blur_v->SetUniform(shader_blur_v_radius, glow_large / screen_size.y);
1238        TraceQuad();
1239        shader_blur_v->Unbind();
1240        fbo_blur_v->Unbind();
1241        // shader blur horizontal
1242        fbo_blur_h->Bind();
1243        shader_blur_h->Bind();
1244        shader_blur_h->SetUniform(shader_blur_h_texture, fbo_blur_v->GetTexture(), 0);
1245        shader_blur_h->SetUniform(shader_blur_h_radius, glow_small / screen_size.x);
1246        TraceQuad();
1247        shader_blur_h->Unbind();
1248        fbo_blur_h->Unbind();
1249        // shader blur vertical
1250        fbo_blur_v->Bind();
1251        shader_blur_v->Bind();
1252        shader_blur_v->SetUniform(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
1253        shader_blur_v->SetUniform(shader_blur_v_radius, glow_small / screen_size.y);
1254        TraceQuad();
1255        shader_blur_v->Unbind();
1256        fbo_blur_v->Unbind();
1257        // shader glow
1258        fbo_screen->Bind();
1259        shader_glow->Bind();
1260        shader_glow->SetUniform(shader_glow_glow, fbo_blur_v->GetTexture(), 0);
1261        shader_glow->SetUniform(shader_glow_source, fbo_back->GetTexture(), 1);
1262        shader_glow->SetUniform(shader_glow_mix, glow_mix);
1263        TraceQuad();
1264        shader_glow->Unbind();
1265        fbo_screen->Unbind();
1266    }
1267    else
1268    {
1269        // shader simple
1270        fbo_screen->Bind();
1271        ShaderSimple(fbo_back, 0);
1272        fbo_screen->Unbind();
1273    }
1274
1275    if (m_shader_color)
1276    {
1277        // shader color
1278        fbo_tmp->Bind();
1279        shader_color->Bind();
1280        shader_color->SetUniform(shader_color_texture, fbo_screen->GetTexture(), 0);
1281        shader_color->SetUniform(shader_color_screen_size, (vec2)screen_size);
1282        shader_color->SetUniform(shader_color_filter, color_filter);
1283        shader_color->SetUniform(shader_color_color, color_color);
1284        shader_color->SetUniform(shader_color_flash, flash_value);
1285        TraceQuad();
1286        shader_color->Unbind();
1287        fbo_tmp->Unbind();
1288        // shader simple
1289        fbo_screen->Bind();
1290        ShaderSimple(fbo_tmp, 0);
1291        fbo_screen->Unbind();
1292    }
1293
1294    if (m_shader_noise)
1295    {
1296        // shader noise
1297        fbo_tmp->Bind();
1298        shader_noise->Bind();
1299        shader_noise->SetUniform(shader_noise_texture, fbo_screen->GetTexture(), 0);
1300        shader_noise->SetUniform(shader_noise_screen_size, (vec2)screen_size);
1301        shader_noise->SetUniform(shader_noise_time, fx_angle);
1302        shader_noise->SetUniform(shader_noise_offset, noise_offset);
1303        shader_noise->SetUniform(shader_noise_noise, noise_noise);
1304        shader_noise->SetUniform(shader_noise_retrace, noise_retrace);
1305        TraceQuad();
1306        shader_noise->Unbind();
1307        fbo_tmp->Unbind();
1308        // shader simple
1309        fbo_screen->Bind();
1310        ShaderSimple(fbo_tmp, 0);
1311        fbo_screen->Unbind();
1312    }
1313
1314    if (m_shader_blur)
1315    {
1316        // shader blur horizontal
1317        fbo_tmp->Bind();
1318        shader_blur_h->Bind();
1319        shader_blur_h->SetUniform(shader_blur_h_texture, fbo_screen->GetTexture(), 0);
1320        shader_blur_h->SetUniform(shader_blur_h_radius, blur / screen_size.x);
1321        TraceQuad();
1322        shader_blur_h->Unbind();
1323        fbo_tmp->Unbind();
1324        // shader blur vertical
1325        fbo_screen->Bind();
1326        shader_blur_v->Bind();
1327        shader_blur_v->SetUniform(shader_blur_v_texture, fbo_tmp->GetTexture(), 0);
1328        shader_blur_v->SetUniform(shader_blur_v_radius, blur / screen_size.y);
1329        TraceQuad();
1330        shader_blur_v->Unbind();
1331        fbo_screen->Unbind();
1332    }
1333
1334    if (m_shader_postfx)
1335    {
1336        // shader postfx
1337        fbo_front->Bind();
1338        shader_postfx->Bind();
1339        shader_postfx->SetUniform(shader_postfx_texture, fbo_screen->GetTexture(), 0);
1340        shader_postfx->SetUniform(shader_postfx_screen_size, (vec2)screen_size);
1341        shader_postfx->SetUniform(shader_postfx_ratio_2d, (vec2)ratio_2d / 2);
1342        shader_postfx->SetUniform(shader_postfx_time, fx_angle);
1343        shader_postfx->SetUniform(shader_postfx_deform, postfx_deform);
1344        shader_postfx->SetUniform(shader_postfx_ghost1, vec4(postfx_ghost1.x * 0.01, postfx_ghost1.y * 0.01, postfx_ghost1.z * 0.01, postfx_ghost1.w));
1345        shader_postfx->SetUniform(shader_postfx_ghost2, vec4(postfx_ghost2.x * 0.01, postfx_ghost2.y * 0.01, postfx_ghost2.z * 0.01, postfx_ghost2.w));
1346        shader_postfx->SetUniform(shader_postfx_glass, vec4(postfx_glass.x * 0.01, postfx_glass.y * 0.01, postfx_glass.z * 0.1, postfx_glass.w));
1347        shader_postfx->SetUniform(shader_postfx_vignetting, postfx_vignetting);
1348        shader_postfx->SetUniform(shader_postfx_aberration, postfx_aberration);
1349        shader_postfx->SetUniform(shader_postfx_moire_h, postfx_moire_h);
1350        shader_postfx->SetUniform(shader_postfx_moire_v, postfx_moire_v);
1351        shader_postfx->SetUniform(shader_postfx_scanline_h, postfx_scanline_h);
1352        shader_postfx->SetUniform(shader_postfx_scanline_v, postfx_scanline_v);
1353        shader_postfx->SetUniform(shader_postfx_corner, postfx_corner);
1354        shader_postfx->SetUniform(shader_postfx_sync, (float)fabs(sync_value * cosf((main_angle - sync_angle) * 6.0f)));
1355        shader_postfx->SetUniform(shader_postfx_beat, (float)fabs(beat_value * cosf((main_angle - beat_angle) * 6.0f)));
1356        TraceQuad();
1357        shader_postfx->Unbind();
1358        fbo_front->Unbind();
1359    }
1360    else
1361    {
1362        // shader simple
1363        fbo_front->Bind();
1364        ShaderSimple(fbo_screen, 0);
1365        fbo_front->Unbind();
1366    }
1367
1368    if (m_shader_mirror)
1369    {
1370        // shader mirror
1371        fbo_tmp->Bind();
1372        shader_mirror->Bind();
1373        shader_mirror->SetUniform(shader_mirror_texture, fbo_front->GetTexture(), 0);
1374        shader_mirror->SetUniform(shader_mirror_screen_size, (vec2)screen_size);
1375        shader_mirror->SetUniform(shader_mirror_mirror, vec4(mirror.x * 0.1f, mirror.y * 0.1f, mirror.z, mirror.w));
1376        TraceQuad();
1377        shader_mirror->Unbind();
1378        fbo_tmp->Unbind();
1379        // shader simple
1380        fbo_front->Bind();
1381        ShaderSimple(fbo_tmp, 0);
1382        fbo_front->Unbind();
1383    }
1384
1385    if (m_shader_radial)
1386    {
1387        // shader radial blur
1388        fbo_tmp->Bind();
1389        shader_radial->Bind();
1390        shader_radial->SetUniform(shader_radial_texture, fbo_front->GetTexture(), 0);
1391        shader_radial->SetUniform(shader_radial_screen_size, (vec2)screen_size);
1392        shader_radial->SetUniform(shader_radial_radial, vec4(radial.x, radial.y, radial.z, radial.w * 0.1f));
1393        TraceQuad();
1394        shader_radial->Unbind();
1395        fbo_tmp->Unbind();
1396        // shader simple
1397        fbo_front->Bind();
1398        ShaderSimple(fbo_tmp, 0);
1399        fbo_front->Unbind();
1400    }
1401
1402    // shader simple
1403    ShaderSimple(fbo_front, 0);
1404
1405    glDisableClientState(GL_VERTEX_ARRAY);
1406    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1407}
1408
1409Render::~Render()
1410{
1411    if (m_fps_debug)
1412        Ticker::Unref(m_fps_debug);
1413}
Note: See TracBrowser for help on using the repository browser.