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

Last change on this file since 1701 was 1701, checked in by rez, 9 years ago

added items to setup menu (unfinished)

File size: 24.6 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
27using namespace std;
28using namespace lol;
29
30#include "../neercs.h"
31#include "render.h"
32#include "text-render.h"
33
34extern char const *lolfx_blurh;
35extern char const *lolfx_blurv;
36extern char const *lolfx_remanency;
37extern char const *lolfx_glow;
38extern char const *lolfx_postfx;
39extern char const *lolfx_radial;
40extern char const *lolfx_simple;
41
42#define PID M_PI/180.0f    // pi ratio
43#define CR 1.0f/256.0f     // color ratio
44
45/*
46 * Various variables
47 */
48
49int active = true;         // window active flag
50float nearplane = 0.1f;    // nearplane
51float farplane = 1000.0f;  // farplane
52int polygon_fillmode = GL_FILL; // fill mode
53/* timer variable */
54float timer = 0;           // timer
55float timer_key = 0;       // key timer
56float timer_key_repeat = 0.25f;// key repeat delay
57/* window variable */
58ivec2 screen_size;         // screen size
59vec3 screen_color = CR * vec3(32, 32, 32); // screen color
60/* object variable */
61float main_angle = 0.0f;   // main angle
62float part_angle = 0.0f;   // part angle
63float fx_angle;            // current angle
64/* fs_quad variable */
65float 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};
66float fs_quad_tex[] = {0, 1.0f, 0, 0, 1.0f, 0, 1.0f, 1.0f};
67/* flash variable */
68bool flash_flag = false;   // flag
69float flash_angle = 0;     // angle
70float flash_value = 0;     // value
71float flash_speed = 1.5f;  // speed
72/* fade variable */
73bool fade_flag = false;    // flag
74float fade_angle = 0;      // angle
75float fade_value = 0;      // value
76float fade_speed = 0.2f;   // speed
77/* sync variable */
78bool sync_flag = false;    // flagsh
79float sync_angle = 0;      // angle
80float sync_value = 1.0f;   // value
81float sync_speed = 1.0f;   // speed
82/* beat variable */
83bool beat_flag = false;    // flag
84float beat_angle = 0;      // angle
85float beat_value = 0;      // value
86float beat_speed = 2.0f;   // speed
87/* window variable */
88ivec2 border;              // border width
89/* text variable */
90ivec2 ratio_2d(2,4);       // 2d ratio
91ivec2 map_size(256,256);   // texture map size
92ivec2 font_size(8,8);      // font size
93ivec2 canvas_char(0,0);    // canvas char number
94ivec2 canvas_size(0,0);    // caca size
95/* setup variable */
96int setup_option=0;             // selected option
97int setup_option_n=6;           // option number
98int setup_item=-1;              // selected item
99int setup_item_n=8;             // item number
100ivec2 setup_p(1,1);             // position [x,y]
101ivec3 setup_size(30,0,12);      // size [w,h,split]
102ivec2 setup_color(0x678,0x234); // size [w,h]
103char const *setup_text[] = {
104    "remanency",
105        "buffer new frame",
106        "buffer old frame",
107        "source",
108        "buffer",
109        "",
110        "",
111        "",
112        "",
113    "blur/glow",
114        "blur center",
115        "blur corner",
116        "glow large center",
117        "glow large corner",
118        "glow small center",
119        "glow small corner",
120        "",
121        "",
122    "color",
123        "filter red",
124        "filter green",
125        "filter blue",
126        "brightness",
127        "contrast",
128        "grayscale",
129        "",
130        "",
131    "modifier",
132        "deform ratio",
133        "retrace color",
134        "retrace length",
135        "retrace speed",
136        "offset h",
137        "offset v",
138        "noise",
139        "aberration",
140    "moire",
141        "h base",
142        "h variable",
143        "h repeat x",
144        "h repeat y",
145        "v base",
146        "v variable",
147        "v repeat x",
148        "v repeat y",
149    "scanline",
150        "h base",
151        "h variable",
152        "h repeat x",
153        "h repeat y",
154        "v base",
155        "v variable",
156        "v repeat x",
157        "v repeat y"
158    };
159/* common variable */
160float value, angle, radius, scale, speed;
161/* shader variable */
162vec2 buffer(0.75f,0.25f);       // [new frame mix,old frame mix]
163vec2 remanency(0.25f,0.75f);    // remanency [source mix,buffer mix]
164vec2 blur(0.25f,0.75f);         // glow radius [center,corner]
165vec2 glow_mix(0.5f,0.5f);       // glow mix [source mix,glow mix]
166vec2 glow_large(2.0f,2.0f);     // large glow radius [center,corner]
167vec2 glow_small(1.0f,1.0f);     // small glow radius [center,corner]
168//vec3 radial(2.0f,0.8f,0);     // radial [mix,strength,color mode]
169//------------------------------// [IDEAS] http://www.youtube.com/watch?v=d1qEP2vMe-I
170float postfx_deform = 0.625f;   // deformation ratio
171vec3 postfx_filter(0.875f,0.75f,1.0f);// color filter [red,green,blue]
172vec3 postfx_color(1.75f,1.75f,0.5f);  // color modifier [brightness,contrast,grayscale]
173vec3 postfx_retrace(0.025f,2.0f,4.0f);// retrace [color,length,speed]
174vec2 postfx_offset(3.0f,3.0f);  // random line [horizontal,vertical]
175float postfx_noise = 0.125f;    // noise
176float postfx_aberration = 3.0f; // chromatic aberration
177bool postfx_moire = true;       // moire
178vec4 postfx_moire_h(0.75f,-0.25f,0.0f,1.0f);
179vec4 postfx_moire_v(0.75f,-0.25f,1.0f,1.5f);
180bool postfx_scanline = true;    // scanline
181vec4 postfx_scanline_h(0.75f, 0.25f,0.0f,2.0f);// vertical scanline [base,variable,repeat x,repeat y]
182vec4 postfx_scanline_v(0.75f,-0.25f,2.0f,0.0f);// horizontal scanline [base,variable,repeat x,repeat y]
183
184Shader *shader_simple;
185Shader *shader_blur_h, *shader_blur_v;
186Shader *shader_remanency, *shader_glow, *shader_radial, *shader_postfx;
187// shader variables
188ShaderUniform shader_simple_texture;
189ShaderUniform shader_blur_h_texture,
190              shader_blur_h_radius,
191              shader_blur_v_texture,
192              shader_blur_v_radius;
193ShaderUniform shader_remanency_source,
194              shader_remanency_buffer,
195              shader_remanency_mix;
196ShaderUniform shader_glow_glow,
197              shader_glow_source,
198              shader_glow_mix;
199ShaderUniform shader_radial_texture,
200              shader_radial_screen_size,
201              shader_radial_time,
202              shader_radial_value1,
203              shader_radial_value2,
204              shader_radial_color;
205ShaderUniform shader_postfx_texture,
206              shader_postfx_texture_2d,
207              shader_postfx_screen_size,
208              shader_postfx_time,
209              shader_postfx_deform,
210              shader_postfx_filter,
211              shader_postfx_color,
212              shader_postfx_retrace,
213              shader_postfx_offset,
214              shader_postfx_noise,
215              shader_postfx_aberration,
216              shader_postfx_moire,
217              shader_postfx_moire_h,
218              shader_postfx_moire_v,
219              shader_postfx_scanline,
220              shader_postfx_scanline_h,
221              shader_postfx_scanline_v,
222              shader_postfx_flash,
223              shader_postfx_sync;
224
225FrameBuffer *fbo_back, *fbo_front, *fbo_buffer;
226FrameBuffer *fbo_blur_h, *fbo_blur_v, *fbo_ping, *fbo_pong;
227
228TextRender *text_render;
229
230void fs_quad()
231{
232    glLoadIdentity();
233    glDrawArrays(GL_QUADS, 0, 4);
234}
235
236void draw_shader_simple(FrameBuffer *fbo_output, int n)
237{
238    shader_simple->Bind();
239    shader_simple->SetTexture(shader_simple_texture, fbo_output->GetTexture(), n);
240    fs_quad();
241    shader_simple->Unbind();
242}
243
244void rectangle(int x, int y, int w, int h)
245{
246    glLoadIdentity();
247    glBegin(GL_QUADS);
248        glVertex2i(x+w, y  );
249        glVertex2i(x  , y  );
250        glVertex2i(x  , y+h);
251        glVertex2i(x+w, y+h);
252    glEnd();
253}
254
255int Render::InitDraw(void)
256{
257    glDepthMask(GL_TRUE);     // do not write z-buffer
258    glEnable(GL_CULL_FACE);   // disable cull face
259    glCullFace(GL_BACK);      // don't draw front face
260
261    /* Initialise framebuffer objects */
262    fbo_back = new FrameBuffer(screen_size);
263    fbo_front = new FrameBuffer(screen_size);
264    fbo_buffer = new FrameBuffer(screen_size);
265    fbo_blur_h = new FrameBuffer(screen_size);
266    fbo_blur_v = new FrameBuffer(screen_size);
267    fbo_ping = new FrameBuffer(screen_size);
268    fbo_pong = new FrameBuffer(screen_size);
269    // shader simple
270    shader_simple = Shader::Create(lolfx_simple);
271    shader_simple_texture = shader_simple->GetUniformLocation("texture");
272    // shader blur horizontal
273    shader_blur_h = Shader::Create(lolfx_blurh);
274    shader_blur_h_texture = shader_blur_h->GetUniformLocation("texture");
275    shader_blur_h_radius = shader_blur_h->GetUniformLocation("radius");
276    // shader blur vertical
277    shader_blur_v = Shader::Create(lolfx_blurv);
278    shader_blur_v_texture = shader_blur_v->GetUniformLocation("texture");
279    shader_blur_v_radius = shader_blur_v->GetUniformLocation("radius");
280    // shader remanency
281    shader_remanency = Shader::Create(lolfx_remanency);
282    shader_remanency_source = shader_remanency->GetUniformLocation("source");
283    shader_remanency_buffer = shader_remanency->GetUniformLocation("buffer");
284    shader_remanency_mix = shader_remanency->GetUniformLocation("mix");
285    // shader glow
286    shader_glow = Shader::Create(lolfx_glow);
287    shader_glow_glow = shader_glow->GetUniformLocation("glow");
288    shader_glow_source = shader_glow->GetUniformLocation("source");
289    shader_glow_mix = shader_glow->GetUniformLocation("mix");
290    // shader radial
291    shader_radial = Shader::Create(lolfx_radial);
292    shader_radial_texture = shader_radial->GetUniformLocation("texture");
293    shader_radial_screen_size = shader_radial->GetUniformLocation("screen_size");
294    shader_radial_time = shader_radial->GetUniformLocation("time");
295    shader_radial_value1 = shader_radial->GetUniformLocation("value1");
296    shader_radial_value2 = shader_radial->GetUniformLocation("value2");
297    shader_radial_color = shader_radial->GetUniformLocation("color");
298    // shader postfx
299    shader_postfx = Shader::Create(lolfx_postfx);
300    shader_postfx_texture = shader_postfx->GetUniformLocation("texture");
301    shader_postfx_texture_2d = shader_postfx->GetUniformLocation("texture_2d");
302    shader_postfx_screen_size = shader_postfx->GetUniformLocation("screen_size");
303    shader_postfx_time = shader_postfx->GetUniformLocation("time");
304    shader_postfx_deform = shader_postfx->GetUniformLocation("deform");
305    shader_postfx_filter = shader_postfx->GetUniformLocation("filter");
306    shader_postfx_color = shader_postfx->GetUniformLocation("color");
307    shader_postfx_retrace = shader_postfx->GetUniformLocation("retrace");
308    shader_postfx_offset = shader_postfx->GetUniformLocation("offset");
309    shader_postfx_noise = shader_postfx->GetUniformLocation("noise");
310    shader_postfx_aberration = shader_postfx->GetUniformLocation("aberration");
311    shader_postfx_moire = shader_postfx->GetUniformLocation("moire");
312    shader_postfx_moire_h = shader_postfx->GetUniformLocation("moire_h");
313    shader_postfx_moire_v = shader_postfx->GetUniformLocation("moire_v");
314    shader_postfx_scanline = shader_postfx->GetUniformLocation("scanline");
315    shader_postfx_scanline_h = shader_postfx->GetUniformLocation("scanline_h");
316    shader_postfx_scanline_v = shader_postfx->GetUniformLocation("scanline_v");
317    shader_postfx_flash = shader_postfx->GetUniformLocation("flash");
318    shader_postfx_sync = shader_postfx->GetUniformLocation("sync");
319
320    return true;
321}
322
323int Render::CreateGLWindow()
324{
325    screen_size = Video::GetSize();
326    border = 18 * ratio_2d;
327    border.y = border.x; // enabled to get same border everywhere
328    canvas_char = (screen_size - border * 2) / (font_size * ratio_2d);
329    canvas_size = canvas_char * font_size * ratio_2d;
330
331    border = (screen_size - canvas_size) / 2;
332
333    caca_set_canvas_size(m_caca, canvas_char.x, canvas_char.y);
334
335    setup_size.y = ((setup_option_n > setup_item_n) ? setup_option_n : setup_item_n) + 1;
336    setup_p = (canvas_char - setup_size.xy) / 2;
337
338    InitDraw();
339    return true;
340}
341
342Render::Render(caca_canvas_t *caca)
343  : m_caca(caca),
344    m_ready(false),
345    m_pause(false),
346    m_polygon(true),
347    m_setup(true),
348    m_shader(true),
349    m_shader_remanency(true),
350    m_shader_glow(true),
351    m_shader_blur(true),
352    m_shader_fx(true),
353    m_shader_postfx(true),
354    m_border(false)
355{
356    text_render = new TextRender(m_caca, font_size);
357}
358
359void Render::TickGame(float seconds)
360{
361    Entity::TickGame(seconds);
362}
363
364void Render::Pause()
365{
366    m_pause=!m_pause;
367}
368
369void Render::TickDraw(float seconds)
370{
371    /* keyboard manager */
372    if (Input::GetButtonState(27/*SDLK_ESCAPE*/))
373        Ticker::Shutdown();
374    if (Input::GetButtonState(282/*SDLK_F1*/) && (timer - timer_key > timer_key_repeat))
375    {
376        m_setup = !m_setup;
377        timer_key = timer;
378    }
379    if (Input::GetButtonState(283/*SDLK_F2*/) && (timer - timer_key > timer_key_repeat))
380    {
381        /*
382        m_polygon = !m_polygon;
383        polygon_fillmode = (m_polygon)?GL_FILL:GL_LINE;
384        glPolygonMode(GL_FRONT, polygon_fillmode);
385        */
386        timer_key = timer;
387    }
388    if (Input::GetButtonState(284/*SDLK_F3*/) && (timer - timer_key > timer_key_repeat))
389    {
390        m_shader_blur = !m_shader_blur;
391        m_shader_glow = !m_shader_glow;
392        timer_key = timer;
393    }
394    if (Input::GetButtonState(285/*SDLK_F4*/)&&(timer-timer_key>timer_key_repeat))
395    {
396        m_shader_postfx = !m_shader_postfx;
397        timer_key = timer;
398    }
399    if (Input::GetButtonState(286/*SDLK_F5*/))
400    {
401        Pause();
402    }
403    if (Input::GetButtonState(273/*SDLK_UP*/)&&(timer-timer_key>timer_key_repeat))
404    {
405        if (setup_item == -1)
406        {
407            setup_option--;
408            if (setup_option < 0) setup_option = setup_option_n - 1;
409        }
410        else
411        {
412            setup_item--;
413            if (setup_item < 0) setup_item = setup_item_n - 1;
414        }
415        timer_key = timer;
416    }
417    if (Input::GetButtonState(274/*SDLK_DOWN*/)&&(timer-timer_key>timer_key_repeat))
418    {
419        if (setup_item == -1)
420        {
421            setup_option++;
422            if (setup_option > setup_option_n - 1) setup_option = 0;
423        }
424        else
425        {
426            setup_item++;
427            if (setup_item > setup_item_n - 1) setup_item = 0;
428        }
429        timer_key = timer;
430    }
431    if (Input::GetButtonState(276/*SDLK_LEFT*/)&&(timer-timer_key>timer_key_repeat))
432    {
433        setup_item = -1;
434        timer_key = timer;
435    }
436    if (Input::GetButtonState(275/*SDLK_RIGHT*/)&&(timer-timer_key>timer_key_repeat))
437    {
438        setup_item = 0;
439        timer_key = timer;
440    }
441
442    Entity::TickDraw(seconds);
443
444    if (!m_ready)
445    {
446        CreateGLWindow();
447        text_render->Init();
448        m_ready = true;
449    }
450
451    // timer
452    if (!m_pause)
453    {
454        timer += seconds;
455        main_angle = timer * 100.0f * PID;
456    }
457    if (sync_flag)
458    {
459        angle=(main_angle-sync_angle)*sync_speed;
460        sync_value=1.0f-sinf(angle);
461        if (angle>90.0f*PID)
462        {
463            sync_value=0;
464            sync_flag=false;
465        }
466    }
467    if (beat_flag)
468    {
469        angle=(main_angle-beat_angle)*beat_speed;
470        beat_value=1.0f-sinf(angle);
471        if (angle>90.0f*PID)
472        {
473            beat_value=0;
474            beat_flag=false;
475        }
476    }
477    if (flash_flag)
478    {
479        angle=(main_angle-flash_angle)*flash_speed;
480        flash_value=1.0f-sinf(angle);
481        if (angle>90.0f*PID)
482        {
483            flash_value=0;
484            flash_flag=false;
485        }
486    }
487    if (fade_flag)
488    {
489        angle=(main_angle-fade_angle)*fade_speed;
490        fade_value=1.0f-sinf(angle);
491        if (angle>90.0f*PID)
492        {
493            fade_value=0;
494            fade_flag=false;
495        }
496    }
497    /* draw setup */
498    if (m_setup)
499    {
500        /* background */
501        caca_set_color_argb(m_caca, setup_color.x, setup_color.y);
502        caca_fill_box(m_caca, setup_p.x, setup_p.y, setup_size.x + 1, setup_size.y,' ');
503        caca_draw_line(m_caca, setup_p.x + setup_size.z - 1, setup_p.y + 1, setup_p.x + setup_size.z - 1, setup_p.y + setup_size.y - 1,'|');
504        /* title */
505        caca_set_color_argb(m_caca, setup_color.y, setup_color.x);
506        caca_draw_line(m_caca, setup_p.x, setup_p.y, setup_p.x + setup_size.x, setup_p.y,' ');
507        caca_put_str(m_caca, setup_p.x + setup_size.x / 2 - 3, setup_p.y, "SETUP");
508        /* display option */
509        for (int i = 0; i < setup_option_n; i++)
510        {
511            int y = setup_p.y + 1 + i;
512            int k = i * (setup_item_n + 1);
513            if (setup_option != i)
514            {
515                caca_set_color_argb(m_caca, setup_color.x, setup_color.y);
516                caca_put_str(m_caca, setup_p.x + 1, y, setup_text[k]);
517            }
518            else
519            {
520                caca_set_color_argb(m_caca, setup_color.y, setup_color.x);
521                caca_draw_line(m_caca, setup_p.x, y, setup_p.x + setup_size.z - 2, y,' ');
522                caca_put_str(m_caca, setup_p.x + 1, y, setup_text[k]);
523            }
524        }
525        /* display item */
526        for (int i = 0; i < setup_item_n; i++)
527        {
528            int y = setup_p.y + 1 + i;
529            int k = setup_option * (setup_item_n + 1) + 1;
530            if (setup_option != i)
531            {
532                caca_set_color_argb(m_caca, setup_color.x, setup_color.y);
533                caca_put_str(m_caca, setup_p.x + setup_size.z + 1, y, setup_text[k + i]);
534            }
535            else
536            {
537                caca_set_color_argb(m_caca, setup_color.y, setup_color.x);
538                caca_draw_line(m_caca, setup_p.x + setup_size.z + 1, y, setup_p.x + setup_size.x, y,' ');
539                caca_put_str(m_caca, setup_p.x + setup_size.z + 1, y, setup_text[k + i]);
540            }
541        }
542    }
543
544    Draw2D();
545    Draw3D();
546
547}
548
549void Render::Draw2D()
550{
551    /* Draw text in an offline buffer */
552    text_render->Render();
553
554    if (m_shader)
555    {
556        fbo_back->Bind();
557    }
558
559    glViewport(0, 0, screen_size.x, screen_size.y);
560
561    /* Clear the back buffer */
562    glEnable(GL_BLEND);
563    glBlendFunc(GL_SRC_COLOR,GL_DST_ALPHA);
564    glClearColor(screen_color.r, screen_color.g, screen_color.b, 1.0f);
565    glClearDepth(1.0f); // set depth buffer
566    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
567
568    text_render->Blit(border, canvas_size);
569
570    //if (m_polygon) glEnable(GL_LINE_SMOOTH); else glDisable(GL_LINE_SMOOTH);
571    glLineWidth((m_polygon)?2.0f:1.0f);
572    fx_angle=main_angle-part_angle;
573    if (m_polygon)
574        glEnable(GL_TEXTURE_2D);
575
576    glMatrixMode(GL_PROJECTION);
577    mat4 m = mat4::ortho(0, screen_size.x, screen_size.y, 0, -1.f, 1.f);
578    glLoadMatrixf(&m[0][0]);
579    glMatrixMode(GL_MODELVIEW);
580    // draw border
581    if (m_border)
582    {
583        glDisable(GL_TEXTURE_2D);
584        glDisable(GL_BLEND);
585        glColor3f(1.0f, 1.0f, 1.0f);
586        rectangle(border.x - ratio_2d.x, border.y - ratio_2d.y, canvas_size.x + ratio_2d.x * 2, ratio_2d.y);
587        rectangle(border.x - ratio_2d.x, border.y, ratio_2d.x, canvas_size.y);
588        rectangle(border.x + canvas_size.x, border.y, ratio_2d.x, canvas_size.y);
589        rectangle(border.x - ratio_2d.x, border.y + canvas_size.y, canvas_size.x + ratio_2d.x * 2, ratio_2d.y);
590        glEnable(GL_BLEND);
591    }
592}
593
594void Render::Draw3D()
595{
596    if (!m_shader)
597        return;
598
599    glDisable(GL_DEPTH_TEST);
600    glDisable(GL_BLEND);
601
602    glEnableClientState(GL_VERTEX_ARRAY);
603    glVertexPointer(4, GL_FLOAT, 0, fs_quad_vtx);
604
605    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
606    glTexCoordPointer(2, GL_FLOAT, 0, fs_quad_tex);
607
608    if (m_shader_remanency)
609    {
610        // shader remanency
611        fbo_ping->Bind();
612        shader_remanency->Bind();
613        shader_remanency->SetTexture(shader_remanency_source, fbo_back->GetTexture(), 0);
614        shader_remanency->SetTexture(shader_remanency_buffer, fbo_buffer->GetTexture(), 1);
615        shader_remanency->SetUniform(shader_remanency_mix, remanency);
616        fs_quad();
617        shader_remanency->Unbind();
618        fbo_ping->Unbind();
619        // shader simple
620        fbo_back->Bind();
621        draw_shader_simple(fbo_ping, 0);
622        fbo_back->Unbind();
623        // save previous fbo
624        fbo_ping->Bind();
625        shader_remanency->Bind();
626        shader_remanency->SetTexture(shader_remanency_source, fbo_front->GetTexture(), 0);
627        shader_remanency->SetTexture(shader_remanency_buffer, fbo_buffer->GetTexture(), 1);
628        shader_remanency->SetUniform(shader_remanency_mix, buffer);
629        fs_quad();
630        shader_remanency->Unbind();
631        fbo_ping->Unbind();
632        // shader simple
633        fbo_buffer->Bind();
634        draw_shader_simple(fbo_ping, 0);
635        fbo_buffer->Unbind();
636    }
637
638    // shader glow
639    if (m_shader_fx && m_shader_glow)
640    {
641        // shader blur horizontal
642        fbo_blur_h->Bind();
643        shader_blur_h->Bind();
644        shader_blur_h->SetTexture(shader_blur_h_texture, fbo_back->GetTexture(), 0);
645        shader_blur_h->SetUniform(shader_blur_h_radius, glow_large / screen_size.x);
646        fs_quad();
647        shader_blur_h->Unbind();
648        fbo_blur_h->Unbind();
649        // shader blur vertical
650        fbo_blur_v->Bind();
651        shader_blur_v->Bind();
652        shader_blur_v->SetTexture(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
653        shader_blur_v->SetUniform(shader_blur_v_radius, glow_large / screen_size.y);
654        fs_quad();
655        shader_blur_v->Unbind();
656        fbo_blur_v->Unbind();
657        // shader blur horizontal
658        fbo_blur_h->Bind();
659        shader_blur_h->Bind();
660        shader_blur_h->SetTexture(shader_blur_h_texture, fbo_blur_v->GetTexture(), 0);
661        shader_blur_h->SetUniform(shader_blur_h_radius, glow_small / screen_size.x);
662        fs_quad();
663        shader_blur_h->Unbind();
664        fbo_blur_h->Unbind();
665        // shader blur vertical
666        fbo_blur_v->Bind();
667        shader_blur_v->Bind();
668        shader_blur_v->SetTexture(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
669        shader_blur_v->SetUniform(shader_blur_v_radius, glow_small / screen_size.y);
670        fs_quad();
671        shader_blur_v->Unbind();
672        fbo_blur_v->Unbind();
673        // shader glow
674        fbo_front->Bind();
675        shader_glow->Bind();
676        shader_glow->SetTexture(shader_glow_glow, fbo_blur_v->GetTexture(), 0);
677        shader_glow->SetTexture(shader_glow_source, fbo_back->GetTexture(), 1);
678        shader_glow->SetUniform(shader_glow_mix, glow_mix);
679        fs_quad();
680        shader_glow->Unbind();
681        fbo_front->Unbind();
682    }
683    else
684    {
685        // shader simple
686        fbo_front->Bind();
687        draw_shader_simple(fbo_back, 0);
688        fbo_front->Unbind();
689    }
690
691    if (m_shader_fx && m_shader_blur)
692    {
693        // shader blur horizontal
694        fbo_ping->Bind();
695        shader_blur_h->Bind();
696        shader_blur_h->SetTexture(shader_blur_h_texture, fbo_front->GetTexture(), 0);
697        shader_blur_h->SetUniform(shader_blur_h_radius, blur / screen_size.x);
698        fs_quad();
699        shader_blur_h->Unbind();
700        fbo_ping->Unbind();
701        // shader blur vertical
702        fbo_front->Bind();
703        shader_blur_v->Bind();
704        shader_blur_v->SetTexture(shader_blur_v_texture, fbo_ping->GetTexture(), 0);
705        shader_blur_v->SetUniform(shader_blur_v_radius, blur / screen_size.y);
706        fs_quad();
707        shader_blur_v->Unbind();
708        fbo_front->Unbind();
709    }
710
711    if (m_shader_postfx)
712    {
713        // shader postfx
714        shader_postfx->Bind();
715        shader_postfx->SetTexture(shader_postfx_texture, fbo_front->GetTexture(), 0);
716        shader_postfx->SetUniform(shader_postfx_screen_size, (vec2)screen_size);
717        shader_postfx->SetUniform(shader_postfx_time, fx_angle);
718        shader_postfx->SetUniform(shader_postfx_deform, postfx_deform);
719        shader_postfx->SetUniform(shader_postfx_filter, postfx_filter);
720        shader_postfx->SetUniform(shader_postfx_color, postfx_color);
721        shader_postfx->SetUniform(shader_postfx_retrace, postfx_retrace);
722        shader_postfx->SetUniform(shader_postfx_offset, postfx_offset);
723        shader_postfx->SetUniform(shader_postfx_noise, postfx_noise);
724        shader_postfx->SetUniform(shader_postfx_aberration, postfx_aberration);
725        shader_postfx->SetUniform(shader_postfx_moire, postfx_moire);
726        shader_postfx->SetUniform(shader_postfx_moire_h, postfx_moire_h);
727        shader_postfx->SetUniform(shader_postfx_moire_v, postfx_moire_v);
728        shader_postfx->SetUniform(shader_postfx_scanline, postfx_scanline);
729        shader_postfx->SetUniform(shader_postfx_scanline_h, postfx_scanline_h);
730        shader_postfx->SetUniform(shader_postfx_scanline_v, postfx_scanline_v);
731        shader_postfx->SetUniform(shader_postfx_flash, flash_value);
732        shader_postfx->SetUniform(shader_postfx_sync, (float)fabs(beat_value*cosf((main_angle-beat_angle)*8.0f)));
733        fs_quad();
734        shader_postfx->Unbind();
735    }
736    else
737    {
738        // shader simple
739        draw_shader_simple(fbo_front, 0);
740    }
741
742    glDisableClientState(GL_VERTEX_ARRAY);
743    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
744}
745
746Render::~Render()
747{
748}
Note: See TracBrowser for help on using the repository browser.