From 6b32f0755cf5d3175d104560ae82d470c524b1cf Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 19 Nov 2012 00:45:44 +0000 Subject: [PATCH] neercs: use gl_VertexID instead of sending a whole new vertex array. --- neercs/video/text-render.cpp | 19 ++++--------------- neercs/video/text-render.h | 6 +++--- neercs/video/text.lolfx | 9 +++++---- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/neercs/video/text-render.cpp b/neercs/video/text-render.cpp index 3e4e046..3bf330e 100644 --- a/neercs/video/text-render.cpp +++ b/neercs/video/text-render.cpp @@ -44,18 +44,15 @@ void TextRender::Init() ivec2(256, 256), ivec2(1)); m_shader = Shader::Create(lolfx_text); - m_coord = m_shader->GetAttribLocation("in_Position", - VertexUsage::Position, 0); m_color = m_shader->GetAttribLocation("in_Attr", VertexUsage::Color, 0); m_char = m_shader->GetAttribLocation("in_Char", VertexUsage::Color, 1); m_texture = m_shader->GetUniformLocation("u_Texture"); m_transform = m_shader->GetUniformLocation("u_Transform"); - m_pointsize = m_shader->GetUniformLocation("u_PointSize"); + m_datasize = m_shader->GetUniformLocation("u_DataSize"); m_vdecl - = new VertexDeclaration(VertexStream(VertexUsage::Position), - VertexStream(VertexUsage::Color), + = new VertexDeclaration(VertexStream(VertexUsage::Color), VertexStream(VertexUsage::Color)); CreateBuffers(); @@ -63,13 +60,6 @@ void TextRender::Init() void TextRender::CreateBuffers() { - m_vbo1 = new VertexBuffer(m_cells * sizeof(vec2)); - vec2 *vertices = (vec2 *)m_vbo1->Lock(0, 0); - for (int j = 0; j < m_canvas_size.y; j++) - for (int i = 0; i < m_canvas_size.x; i++) - vertices[j * m_canvas_size.x + i] = vec2(i, j); - m_vbo1->Unlock(); - m_vbo2 = new VertexBuffer(m_cells * sizeof(int32_t)); m_vbo3 = new VertexBuffer(m_cells * sizeof(int32_t)); @@ -83,7 +73,6 @@ void TextRender::Render() caca_get_canvas_height(m_caca)); if (current_size != m_canvas_size) { - delete m_vbo1; delete m_vbo2; delete m_vbo3; delete m_fbo; @@ -140,8 +129,8 @@ void TextRender::Render() m_font->Bind(); m_shader->SetUniform(m_texture, 0); m_shader->SetUniform(m_transform, xform); - m_shader->SetUniform(m_pointsize, (float)max(m_font_size.x, m_font_size.y)); - m_vdecl->SetStream(m_vbo1, m_coord); + m_shader->SetUniform(m_datasize, vec2(m_canvas_size.x, + max(m_font_size.x, m_font_size.y))); m_vdecl->SetStream(m_vbo2, m_color); m_vdecl->SetStream(m_vbo3, m_char); m_vdecl->Bind(); diff --git a/neercs/video/text-render.h b/neercs/video/text-render.h index e9bc45c..0d4cc4f 100644 --- a/neercs/video/text-render.h +++ b/neercs/video/text-render.h @@ -22,10 +22,10 @@ private: TileSet *m_font; Shader *m_shader; - ShaderAttrib m_coord, m_color, m_char; - ShaderUniform m_texture, m_transform, m_pointsize; + ShaderAttrib m_color, m_char; + ShaderUniform m_texture, m_transform, m_datasize; VertexDeclaration *m_vdecl; - VertexBuffer *m_vbo1, *m_vbo2, *m_vbo3; + VertexBuffer *m_vbo2, *m_vbo3; FrameBuffer *m_fbo; }; diff --git a/neercs/video/text.lolfx b/neercs/video/text.lolfx index fa22246..127eabe 100644 --- a/neercs/video/text.lolfx +++ b/neercs/video/text.lolfx @@ -4,7 +4,6 @@ #define HAVE_UINT 1 -attribute vec2 in_Position; #if HAVE_UINT attribute uint in_Char, in_Attr; #else @@ -15,7 +14,7 @@ varying vec4 pass_Foreground; varying vec4 pass_Background; varying vec2 pass_UV; -uniform float u_PointSize; +uniform vec2 u_DataSize; uniform mat4 u_Transform; void main() @@ -57,9 +56,11 @@ void main() if (F + G + H < 0.01) E = 1.0; // This only works with glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); - gl_PointSize = u_PointSize; + gl_PointSize = u_DataSize[1]; - gl_Position = u_Transform * vec4(in_Position, 0.0, 1.0); + vec2 coord = vec2(gl_VertexID % int(u_DataSize[0]), + gl_VertexID / int(u_DataSize[0])); + gl_Position = u_Transform * vec4(coord, 0.0, 1.0); } [frag.glsl]