From 9bfaa46d5442a16640854f3dea95fc5fc4119b6d Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sat, 14 Jun 2014 17:05:39 +0000 Subject: [PATCH] neercs: refactor the shader system. --- neercs/video/blurh.lolfx | 5 +- neercs/video/blurv.lolfx | 5 +- neercs/video/color.lolfx | 4 +- neercs/video/copper.lolfx | 5 +- neercs/video/glow.lolfx | 5 +- neercs/video/mirror.lolfx | 5 +- neercs/video/noise.lolfx | 4 +- neercs/video/postfx.lolfx | 4 +- neercs/video/radial.lolfx | 5 +- neercs/video/remanence.lolfx | 5 +- neercs/video/render.cpp | 288 +++++++++++++++++++---------------- neercs/video/render.h | 27 ++-- neercs/video/simple.lolfx | 5 +- 13 files changed, 206 insertions(+), 161 deletions(-) diff --git a/neercs/video/blurh.lolfx b/neercs/video/blurh.lolfx index 4c4dbee..9ce8985 100644 --- a/neercs/video/blurh.lolfx +++ b/neercs/video/blurh.lolfx @@ -2,12 +2,13 @@ #version 120 +attribute vec4 in_Position; varying vec2 pass_TexCoord; void main() { - gl_Position = gl_Vertex; - pass_TexCoord = vec2(0.5, 0.5) + 0.5 * gl_Vertex.xy; + gl_Position = in_Position; + pass_TexCoord = vec2(0.5, 0.5) + 0.5 * in_Position.xy; } [frag.glsl] diff --git a/neercs/video/blurv.lolfx b/neercs/video/blurv.lolfx index c719180..40e7218 100644 --- a/neercs/video/blurv.lolfx +++ b/neercs/video/blurv.lolfx @@ -2,12 +2,13 @@ #version 120 +attribute vec4 in_Position; varying vec2 pass_TexCoord; void main() { - gl_Position = gl_Vertex; - pass_TexCoord = vec2(0.5, 0.5) + 0.5 * gl_Vertex.xy; + gl_Position = in_Position; + pass_TexCoord = vec2(0.5, 0.5) + 0.5 * in_Position.xy; } [frag.glsl] diff --git a/neercs/video/color.lolfx b/neercs/video/color.lolfx index e28bd6f..6e3ab4b 100644 --- a/neercs/video/color.lolfx +++ b/neercs/video/color.lolfx @@ -2,9 +2,11 @@ #version 120 +attribute vec4 in_Position; + void main() { - gl_Position = gl_Vertex; + gl_Position = in_Position; } [frag.glsl] diff --git a/neercs/video/copper.lolfx b/neercs/video/copper.lolfx index 9f6e2cf..57676d2 100644 --- a/neercs/video/copper.lolfx +++ b/neercs/video/copper.lolfx @@ -2,12 +2,13 @@ #version 120 +attribute vec4 in_Position; varying vec2 pass_TexCoord; void main() { - gl_Position = gl_Vertex; - pass_TexCoord = vec2(0.5, 0.5) + 0.5 * gl_Vertex.xy; + gl_Position = in_Position; + pass_TexCoord = vec2(0.5, 0.5) + 0.5 * in_Position.xy; } [frag.glsl] diff --git a/neercs/video/glow.lolfx b/neercs/video/glow.lolfx index 0a74056..0aa0568 100644 --- a/neercs/video/glow.lolfx +++ b/neercs/video/glow.lolfx @@ -2,12 +2,13 @@ #version 120 +attribute vec4 in_Position; varying vec2 pass_TexCoord; void main() { - gl_Position = gl_Vertex; - pass_TexCoord = vec2(0.5, 0.5) + 0.5 * gl_Vertex.xy; + gl_Position = in_Position; + pass_TexCoord = vec2(0.5, 0.5) + 0.5 * in_Position.xy; } [frag.glsl] diff --git a/neercs/video/mirror.lolfx b/neercs/video/mirror.lolfx index f19aa93..3bedd56 100644 --- a/neercs/video/mirror.lolfx +++ b/neercs/video/mirror.lolfx @@ -2,12 +2,13 @@ #version 120 +attribute vec4 in_Position; varying vec2 pass_TexCoord; void main() { - gl_Position = gl_Vertex; - pass_TexCoord = vec2(0.5, 0.5) + 0.5 * gl_Vertex.xy; + gl_Position = in_Position; + pass_TexCoord = vec2(0.5, 0.5) + 0.5 * in_Position.xy; } [frag.glsl] diff --git a/neercs/video/noise.lolfx b/neercs/video/noise.lolfx index 0b817ce..15a48b6 100644 --- a/neercs/video/noise.lolfx +++ b/neercs/video/noise.lolfx @@ -2,9 +2,11 @@ #version 120 +attribute vec4 in_Position; + void main() { - gl_Position = gl_Vertex; + gl_Position = in_Position; } [frag.glsl] diff --git a/neercs/video/postfx.lolfx b/neercs/video/postfx.lolfx index acf17d2..4640903 100644 --- a/neercs/video/postfx.lolfx +++ b/neercs/video/postfx.lolfx @@ -2,9 +2,11 @@ #version 120 +attribute vec4 in_Position; + void main() { - gl_Position = gl_Vertex; + gl_Position = in_Position; } [frag.glsl] diff --git a/neercs/video/radial.lolfx b/neercs/video/radial.lolfx index 7cb606e..2ce6b9c 100644 --- a/neercs/video/radial.lolfx +++ b/neercs/video/radial.lolfx @@ -2,12 +2,13 @@ #version 120 +attribute vec4 in_Position; varying vec2 pass_TexCoord; void main() { - gl_Position = gl_Vertex; - pass_TexCoord = vec2(0.5, 0.5) + 0.5 * gl_Vertex.xy; + gl_Position = in_Position; + pass_TexCoord = vec2(0.5, 0.5) + 0.5 * in_Position.xy; } [frag.glsl] diff --git a/neercs/video/remanence.lolfx b/neercs/video/remanence.lolfx index 3bef08e..7d35581 100644 --- a/neercs/video/remanence.lolfx +++ b/neercs/video/remanence.lolfx @@ -2,12 +2,13 @@ #version 120 +attribute vec4 in_Position; varying vec2 pass_TexCoord; void main() { - gl_Position = gl_Vertex; - pass_TexCoord = vec2(0.5, 0.5) + 0.5 * gl_Vertex.xy; + gl_Position = in_Position; + pass_TexCoord = vec2(0.5, 0.5) + 0.5 * in_Position.xy; } [frag.glsl] diff --git a/neercs/video/render.cpp b/neercs/video/render.cpp index c66a6f7..906cdc6 100644 --- a/neercs/video/render.cpp +++ b/neercs/video/render.cpp @@ -841,34 +841,46 @@ ShaderUniform shader_radial_texture, shader_radial_screen_size, shader_radial_radial; -Framebuffer *fbo_back, *fbo_front, *fbo_screen; -Framebuffer *fbo_blur_h, *fbo_blur_v; -Framebuffer *fbo_tmp, *fbo_buffer; - void Render::TraceQuad() { - glLoadIdentity(); - glDrawArrays(GL_QUADS, 0, 4); + m_vdecl->Bind(); + m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); + m_vdecl->Unbind(); } void Render::ShaderSimple(Framebuffer *fbo_output, int n) { shader_simple->Bind(); shader_simple->SetUniform(shader_simple_texture, fbo_output->GetTextureUniform(), n); + m_vdecl->SetStream(m_vbo, shader_simple->GetAttribLocation(VertexUsage::Position, 0)); TraceQuad(); shader_simple->Unbind(); } int Render::InitDrawResources(void) { - /* initialise framebuffer objects */ - fbo_back = new Framebuffer(screen_size); - fbo_screen = new Framebuffer(screen_size); - fbo_front = new Framebuffer(screen_size); - fbo_buffer = new Framebuffer(screen_size); - fbo_blur_h = new Framebuffer(screen_size); - fbo_blur_v = new Framebuffer(screen_size); - fbo_tmp = new Framebuffer(screen_size); + /* Initialise framebuffer objects */ + m_fbos.back = new Framebuffer(screen_size); + m_fbos.screen = new Framebuffer(screen_size); + m_fbos.front = new Framebuffer(screen_size); + m_fbos.buffer = new Framebuffer(screen_size); + m_fbos.blur_h = new Framebuffer(screen_size); + m_fbos.blur_v = new Framebuffer(screen_size); + m_fbos.tmp = new Framebuffer(screen_size); + + /* Initialise vertex declaration */ + m_vdecl = new VertexDeclaration(VertexStream(VertexUsage::Position)); + Array vertices; + vertices << vec2(-1, 1); + vertices << vec2(-1, -1); + vertices << vec2(1, -1); + vertices << vec2(1, -1); + vertices << vec2(1, 1); + vertices << vec2(-1, 1); + m_vbo = new VertexBuffer(vertices.Bytes()); + memcpy(m_vbo->Lock(0, 0), vertices.Data(), vertices.Bytes()); + m_vbo->Unlock(); + // shader simple shader_simple = Shader::Create(LOLFX_RESOURCE_NAME(simple)); shader_simple_texture = shader_simple->GetUniformLocation("texture"); @@ -949,33 +961,26 @@ int Render::InitDrawResources(void) return true; } -int Render::CreateGLWindow() -{ - InitShaderVar(); - UpdateSize(); - InitDrawResources(); - return true; -} - Render::Render(caca_canvas_t *caca) : m_cv_screen(caca), m_cv_setup(caca_create_canvas(1, 1)), m_fps_debug(0), m_ready(false), - m_pause(false), - m_shader(true), - m_shader_remanence(true), - m_shader_glow(true), - m_shader_blur(true), - m_shader_postfx(true), - m_shader_copper(true), - m_shader_color(true), - m_shader_noise(true), - m_shader_mirror(true), - m_shader_radial(true) + m_pause(false) { m_txt_screen = new TextRender(m_cv_screen, font_size); m_txt_setup = new TextRender(m_cv_setup, font_size); + + m_flags.shader = false; + m_flags.remanence = true; + m_flags.glow = true; + m_flags.blur = true; + m_flags.postfx = true; + m_flags.copper = true; + m_flags.color = true; + m_flags.noise = true; + m_flags.mirror = true; + m_flags.radial = true; } void Render::TickGame(float seconds) @@ -1096,15 +1101,15 @@ void Render::TickDraw(float seconds) } if (Input::WasPressed(Key::F2)) { - m_shader_remanence = !m_shader_remanence; - m_shader_glow = !m_shader_glow; - m_shader_blur = !m_shader_blur; - m_shader_postfx = !m_shader_postfx; - //m_shader_copper = !m_shader_copper; - m_shader_color = !m_shader_color; - m_shader_noise = !m_shader_noise; - m_shader_mirror = !m_shader_mirror; - m_shader_radial = !m_shader_radial; + m_flags.remanence = !m_flags.remanence; + m_flags.glow = !m_flags.glow; + m_flags.blur = !m_flags.blur; + m_flags.postfx = !m_flags.postfx; + //m_flags.copper = !m_flags.copper; + m_flags.color = !m_flags.color; + m_flags.noise = !m_flags.noise; + m_flags.mirror = !m_flags.mirror; + m_flags.radial = !m_flags.radial; } if (Input::WasPressed(Key::F4)) { @@ -1378,7 +1383,10 @@ void Render::TickDraw(float seconds) if (!m_ready) { - CreateGLWindow(); + InitShaderVar(); + UpdateSize(); + InitDrawResources(); + m_txt_screen->Init(); m_txt_setup->Init(); m_ready = true; @@ -1443,8 +1451,8 @@ void Render::Draw2D() if (g_setup) m_txt_setup->Render(); - if (m_shader) - fbo_back->Bind(); + if (m_flags.shader) + m_fbos.back->Bind(); glViewport(0, 0, screen_size.x, screen_size.y); @@ -1463,6 +1471,9 @@ void Render::Draw2D() if (g_setup) m_txt_setup->Blit((screen_size - setup_canvas_size) / 2, setup_canvas_size); + if (m_flags.shader) + m_fbos.back->Unbind(); + glMatrixMode(GL_PROJECTION); mat4 m = mat4::ortho(0, screen_size.x, screen_size.y, 0, -1.f, 1.f); glLoadMatrixf(&m[0][0]); @@ -1473,7 +1484,7 @@ void Render::Draw2D() void Render::Draw3D() { - if (!m_shader) + if (!m_flags.shader) return; RenderContext rc; @@ -1484,173 +1495,185 @@ void Render::Draw3D() glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(4, GL_FLOAT, 0, fs_quad_vtx); - if (m_shader_copper) + if (m_flags.copper) { // shader copper - fbo_tmp->Bind(); + m_fbos.tmp->Bind(); shader_copper->Bind(); - shader_copper->SetUniform(shader_copper_texture, fbo_back->GetTextureUniform(), 0); + shader_copper->SetUniform(shader_copper_texture, m_fbos.back->GetTextureUniform(), 0); shader_copper->SetUniform(shader_copper_screen_size, (vec2)screen_size); shader_copper->SetUniform(shader_copper_time, fx_angle); shader_copper->SetUniform(shader_copper_copper, vec4(copper_copper.x, copper_copper.y, copper_copper.z * 16.0f, copper_copper.w * 16.0f)); shader_copper->SetUniform(shader_copper_mask_color, copper_mask_color); + m_vdecl->SetStream(m_vbo, shader_copper->GetAttribLocation(VertexUsage::Position, 0)); TraceQuad(); shader_color->Unbind(); - fbo_tmp->Unbind(); + m_fbos.tmp->Unbind(); // shader simple - fbo_back->Bind(); - ShaderSimple(fbo_tmp, 0); - fbo_back->Unbind(); + m_fbos.back->Bind(); + ShaderSimple(m_fbos.tmp, 0); + m_fbos.back->Unbind(); } - if (m_shader_remanence) + if (m_flags.remanence) { // shader remanence - fbo_tmp->Bind(); + m_fbos.tmp->Bind(); shader_remanence->Bind(); - shader_remanence->SetUniform(shader_remanence_source, fbo_back->GetTextureUniform(), 0); - shader_remanence->SetUniform(shader_remanence_buffer, fbo_buffer->GetTextureUniform(), 1); + shader_remanence->SetUniform(shader_remanence_source, m_fbos.back->GetTextureUniform(), 0); + shader_remanence->SetUniform(shader_remanence_buffer, m_fbos.buffer->GetTextureUniform(), 1); shader_remanence->SetUniform(shader_remanence_mix, remanence); + m_vdecl->SetStream(m_vbo, shader_remanence->GetAttribLocation(VertexUsage::Position, 0)); TraceQuad(); shader_remanence->Unbind(); - fbo_tmp->Unbind(); + m_fbos.tmp->Unbind(); // shader simple - fbo_back->Bind(); - ShaderSimple(fbo_tmp, 0); - fbo_back->Unbind(); + m_fbos.back->Bind(); + ShaderSimple(m_fbos.tmp, 0); + m_fbos.back->Unbind(); // save previous fbo - fbo_tmp->Bind(); + m_fbos.tmp->Bind(); shader_remanence->Bind(); - shader_remanence->SetUniform(shader_remanence_source, fbo_screen->GetTextureUniform(), 0); - shader_remanence->SetUniform(shader_remanence_buffer, fbo_buffer->GetTextureUniform(), 1); + shader_remanence->SetUniform(shader_remanence_source, m_fbos.screen->GetTextureUniform(), 0); + shader_remanence->SetUniform(shader_remanence_buffer, m_fbos.buffer->GetTextureUniform(), 1); shader_remanence->SetUniform(shader_remanence_mix, buffer); + m_vdecl->SetStream(m_vbo, shader_remanence->GetAttribLocation(VertexUsage::Position, 0)); TraceQuad(); shader_remanence->Unbind(); - fbo_tmp->Unbind(); + m_fbos.tmp->Unbind(); // shader simple - fbo_buffer->Bind(); - ShaderSimple(fbo_tmp, 0); - fbo_buffer->Unbind(); + m_fbos.buffer->Bind(); + ShaderSimple(m_fbos.tmp, 0); + m_fbos.buffer->Unbind(); } // shader glow - if (m_shader_glow) + if (m_flags.glow) { // shader blur horizontal - fbo_blur_h->Bind(); + m_fbos.blur_h->Bind(); shader_blur_h->Bind(); - shader_blur_h->SetUniform(shader_blur_h_texture, fbo_back->GetTextureUniform(), 0); + shader_blur_h->SetUniform(shader_blur_h_texture, m_fbos.back->GetTextureUniform(), 0); shader_blur_h->SetUniform(shader_blur_h_radius, glow_large / (float)screen_size.x); + m_vdecl->SetStream(m_vbo, shader_blur_h->GetAttribLocation(VertexUsage::Position, 0)); TraceQuad(); shader_blur_h->Unbind(); - fbo_blur_h->Unbind(); + m_fbos.blur_h->Unbind(); // shader blur vertical - fbo_blur_v->Bind(); + m_fbos.blur_v->Bind(); shader_blur_v->Bind(); - shader_blur_v->SetUniform(shader_blur_v_texture, fbo_blur_h->GetTextureUniform(), 0); + shader_blur_v->SetUniform(shader_blur_v_texture, m_fbos.blur_h->GetTextureUniform(), 0); shader_blur_v->SetUniform(shader_blur_v_radius, glow_large / (float)screen_size.y); + m_vdecl->SetStream(m_vbo, shader_blur_v->GetAttribLocation(VertexUsage::Position, 0)); TraceQuad(); shader_blur_v->Unbind(); - fbo_blur_v->Unbind(); + m_fbos.blur_v->Unbind(); // shader blur horizontal - fbo_blur_h->Bind(); + m_fbos.blur_h->Bind(); shader_blur_h->Bind(); - shader_blur_h->SetUniform(shader_blur_h_texture, fbo_blur_v->GetTextureUniform(), 0); + shader_blur_h->SetUniform(shader_blur_h_texture, m_fbos.blur_v->GetTextureUniform(), 0); shader_blur_h->SetUniform(shader_blur_h_radius, glow_small / (float)screen_size.x); + m_vdecl->SetStream(m_vbo, shader_blur_h->GetAttribLocation(VertexUsage::Position, 0)); TraceQuad(); shader_blur_h->Unbind(); - fbo_blur_h->Unbind(); + m_fbos.blur_h->Unbind(); // shader blur vertical - fbo_blur_v->Bind(); + m_fbos.blur_v->Bind(); shader_blur_v->Bind(); - shader_blur_v->SetUniform(shader_blur_v_texture, fbo_blur_h->GetTextureUniform(), 0); + shader_blur_v->SetUniform(shader_blur_v_texture, m_fbos.blur_h->GetTextureUniform(), 0); shader_blur_v->SetUniform(shader_blur_v_radius, glow_small / (float)screen_size.y); + m_vdecl->SetStream(m_vbo, shader_blur_v->GetAttribLocation(VertexUsage::Position, 0)); TraceQuad(); shader_blur_v->Unbind(); - fbo_blur_v->Unbind(); + m_fbos.blur_v->Unbind(); // shader glow - fbo_screen->Bind(); + m_fbos.screen->Bind(); shader_glow->Bind(); - shader_glow->SetUniform(shader_glow_glow, fbo_blur_v->GetTextureUniform(), 0); - shader_glow->SetUniform(shader_glow_source, fbo_back->GetTextureUniform(), 1); + shader_glow->SetUniform(shader_glow_glow, m_fbos.blur_v->GetTextureUniform(), 0); + shader_glow->SetUniform(shader_glow_source, m_fbos.back->GetTextureUniform(), 1); shader_glow->SetUniform(shader_glow_mix, glow_mix); + m_vdecl->SetStream(m_vbo, shader_glow->GetAttribLocation(VertexUsage::Position, 0)); TraceQuad(); shader_glow->Unbind(); - fbo_screen->Unbind(); + m_fbos.screen->Unbind(); } else { // shader simple - fbo_screen->Bind(); - ShaderSimple(fbo_back, 0); - fbo_screen->Unbind(); + m_fbos.screen->Bind(); + ShaderSimple(m_fbos.back, 0); + m_fbos.screen->Unbind(); } - if (m_shader_color) + if (m_flags.color) { // shader color - fbo_tmp->Bind(); + m_fbos.tmp->Bind(); shader_color->Bind(); - shader_color->SetUniform(shader_color_texture, fbo_screen->GetTextureUniform(), 0); + shader_color->SetUniform(shader_color_texture, m_fbos.screen->GetTextureUniform(), 0); shader_color->SetUniform(shader_color_screen_size, (vec2)screen_size); shader_color->SetUniform(shader_color_filter, color_filter); shader_color->SetUniform(shader_color_color, color_color); shader_color->SetUniform(shader_color_flash, flash_value); + m_vdecl->SetStream(m_vbo, shader_color->GetAttribLocation(VertexUsage::Position, 0)); TraceQuad(); shader_color->Unbind(); - fbo_tmp->Unbind(); + m_fbos.tmp->Unbind(); // shader simple - fbo_screen->Bind(); - ShaderSimple(fbo_tmp, 0); - fbo_screen->Unbind(); + m_fbos.screen->Bind(); + ShaderSimple(m_fbos.tmp, 0); + m_fbos.screen->Unbind(); } - if (m_shader_noise) + if (m_flags.noise) { // shader noise - fbo_tmp->Bind(); + m_fbos.tmp->Bind(); shader_noise->Bind(); - shader_noise->SetUniform(shader_noise_texture, fbo_screen->GetTextureUniform(), 0); + shader_noise->SetUniform(shader_noise_texture, m_fbos.screen->GetTextureUniform(), 0); shader_noise->SetUniform(shader_noise_screen_size, (vec2)screen_size); shader_noise->SetUniform(shader_noise_time, fx_angle); shader_noise->SetUniform(shader_noise_offset, noise_offset); shader_noise->SetUniform(shader_noise_noise, noise_noise); shader_noise->SetUniform(shader_noise_retrace, noise_retrace); + m_vdecl->SetStream(m_vbo, shader_noise->GetAttribLocation(VertexUsage::Position, 0)); TraceQuad(); shader_noise->Unbind(); - fbo_tmp->Unbind(); + m_fbos.tmp->Unbind(); // shader simple - fbo_screen->Bind(); - ShaderSimple(fbo_tmp, 0); - fbo_screen->Unbind(); + m_fbos.screen->Bind(); + ShaderSimple(m_fbos.tmp, 0); + m_fbos.screen->Unbind(); } - if (m_shader_blur) + if (m_flags.blur) { // shader blur horizontal - fbo_tmp->Bind(); + m_fbos.tmp->Bind(); shader_blur_h->Bind(); - shader_blur_h->SetUniform(shader_blur_h_texture, fbo_screen->GetTextureUniform(), 0); + shader_blur_h->SetUniform(shader_blur_h_texture, m_fbos.screen->GetTextureUniform(), 0); shader_blur_h->SetUniform(shader_blur_h_radius, blur / (float)screen_size.x); + m_vdecl->SetStream(m_vbo, shader_blur_h->GetAttribLocation(VertexUsage::Position, 0)); TraceQuad(); shader_blur_h->Unbind(); - fbo_tmp->Unbind(); + m_fbos.tmp->Unbind(); // shader blur vertical - fbo_screen->Bind(); + m_fbos.screen->Bind(); shader_blur_v->Bind(); - shader_blur_v->SetUniform(shader_blur_v_texture, fbo_tmp->GetTextureUniform(), 0); + shader_blur_v->SetUniform(shader_blur_v_texture, m_fbos.tmp->GetTextureUniform(), 0); shader_blur_v->SetUniform(shader_blur_v_radius, blur / (float)screen_size.y); + m_vdecl->SetStream(m_vbo, shader_blur_v->GetAttribLocation(VertexUsage::Position, 0)); TraceQuad(); shader_blur_v->Unbind(); - fbo_screen->Unbind(); + m_fbos.screen->Unbind(); } - if (m_shader_postfx) + if (m_flags.postfx) { // shader postfx - fbo_front->Bind(); + m_fbos.front->Bind(); shader_postfx->Bind(); - shader_postfx->SetUniform(shader_postfx_texture, fbo_screen->GetTextureUniform(), 0); + shader_postfx->SetUniform(shader_postfx_texture, m_fbos.screen->GetTextureUniform(), 0); shader_postfx->SetUniform(shader_postfx_screen_size, (vec2)screen_size); shader_postfx->SetUniform(shader_postfx_ratio_2d, (vec2)ratio_2d * 0.5f); shader_postfx->SetUniform(shader_postfx_time, fx_angle); @@ -1669,54 +1692,57 @@ void Render::Draw3D() shader_postfx->SetUniform(shader_postfx_corner, postfx_corner); shader_postfx->SetUniform(shader_postfx_sync, (float)fabs(sync_value * cosf((main_angle - sync_angle) * 6.0f))); shader_postfx->SetUniform(shader_postfx_beat, (float)fabs(beat_value * cosf((main_angle - beat_angle) * 6.0f))); + m_vdecl->SetStream(m_vbo, shader_postfx->GetAttribLocation(VertexUsage::Position, 0)); TraceQuad(); shader_postfx->Unbind(); - fbo_front->Unbind(); + m_fbos.front->Unbind(); } else { // shader simple - fbo_front->Bind(); - ShaderSimple(fbo_screen, 0); - fbo_front->Unbind(); + m_fbos.front->Bind(); + ShaderSimple(m_fbos.screen, 0); + m_fbos.front->Unbind(); } - if (m_shader_mirror) + if (m_flags.mirror) { // shader mirror - fbo_tmp->Bind(); + m_fbos.tmp->Bind(); shader_mirror->Bind(); - shader_mirror->SetUniform(shader_mirror_texture, fbo_front->GetTextureUniform(), 0); + shader_mirror->SetUniform(shader_mirror_texture, m_fbos.front->GetTextureUniform(), 0); shader_mirror->SetUniform(shader_mirror_screen_size, (vec2)screen_size); shader_mirror->SetUniform(shader_mirror_mirror, vec4(mirror.x * 0.1f, mirror.y * 0.1f, mirror.z, mirror.w)); + m_vdecl->SetStream(m_vbo, shader_mirror->GetAttribLocation(VertexUsage::Position, 0)); TraceQuad(); shader_mirror->Unbind(); - fbo_tmp->Unbind(); + m_fbos.tmp->Unbind(); // shader simple - fbo_front->Bind(); - ShaderSimple(fbo_tmp, 0); - fbo_front->Unbind(); + m_fbos.front->Bind(); + ShaderSimple(m_fbos.tmp, 0); + m_fbos.front->Unbind(); } - if (m_shader_radial) + if (m_flags.radial) { // shader radial blur - fbo_tmp->Bind(); + m_fbos.tmp->Bind(); shader_radial->Bind(); - shader_radial->SetUniform(shader_radial_texture, fbo_front->GetTextureUniform(), 0); + shader_radial->SetUniform(shader_radial_texture, m_fbos.front->GetTextureUniform(), 0); shader_radial->SetUniform(shader_radial_screen_size, (vec2)screen_size); shader_radial->SetUniform(shader_radial_radial, vec4(radial.x, radial.y, radial.z, radial.w * 0.1f)); + m_vdecl->SetStream(m_vbo, shader_radial->GetAttribLocation(VertexUsage::Position, 0)); TraceQuad(); shader_radial->Unbind(); - fbo_tmp->Unbind(); + m_fbos.tmp->Unbind(); // shader simple - fbo_front->Bind(); - ShaderSimple(fbo_tmp, 0); - fbo_front->Unbind(); + m_fbos.front->Bind(); + ShaderSimple(m_fbos.tmp, 0); + m_fbos.front->Unbind(); } // shader simple - ShaderSimple(fbo_front, 0); + ShaderSimple(m_fbos.front, 0); glDisableClientState(GL_VERTEX_ARRAY); } diff --git a/neercs/video/render.h b/neercs/video/render.h index eec0b5e..ea3e69f 100644 --- a/neercs/video/render.h +++ b/neercs/video/render.h @@ -21,7 +21,6 @@ protected: void Draw3D(); private: - int CreateGLWindow(); int InitDrawResources(); void ShaderSimple(Framebuffer *fbo_output, int n); void TraceQuad(); @@ -33,21 +32,27 @@ private: caca_canvas_t *m_cv_screen, *m_cv_setup; class TextRender *m_txt_screen, *m_txt_setup; + VertexDeclaration *m_vdecl; + VertexBuffer *m_vbo; Entity *m_fps_debug; + struct + { + Framebuffer *back, *screen, *front, *buffer, + *blur_h, *blur_v, *tmp; + } + m_fbos; + bool m_ready; bool m_pause; - bool m_shader; - bool m_shader_remanence; - bool m_shader_glow; - bool m_shader_blur; - bool m_shader_postfx; - bool m_shader_copper; - bool m_shader_color; - bool m_shader_noise; - bool m_shader_mirror; - bool m_shader_radial; + + struct + { + bool shader, remanence, glow, blur, postfx, + copper, color, noise, mirror, radial; + } + m_flags; }; #endif // __VIDEO_RENDER_H__ diff --git a/neercs/video/simple.lolfx b/neercs/video/simple.lolfx index eaa5cfe..225a995 100644 --- a/neercs/video/simple.lolfx +++ b/neercs/video/simple.lolfx @@ -2,12 +2,13 @@ #version 120 +attribute vec4 in_Position; varying vec2 pass_TexCoord; void main() { - gl_Position = gl_Vertex; - pass_TexCoord = vec2(0.5, 0.5) + 0.5 * gl_Vertex.xy; + gl_Position = in_Position; + pass_TexCoord = vec2(0.5, 0.5) + 0.5 * in_Position.xy; } [frag.glsl]