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

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

neercs: added a protection glass above the monitor

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