Переглянути джерело

neercs: use gl_VertexID instead of sending a whole new vertex array.

master
Sam Hocevar 12 роки тому
джерело
коміт
6b32f0755c
3 змінених файлів з 12 додано та 22 видалено
  1. +4
    -15
      neercs/video/text-render.cpp
  2. +3
    -3
      neercs/video/text-render.h
  3. +5
    -4
      neercs/video/text.lolfx

+ 4
- 15
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<vec2>(VertexUsage::Position),
VertexStream<uint32_t>(VertexUsage::Color),
= new VertexDeclaration(VertexStream<uint32_t>(VertexUsage::Color),
VertexStream<uint32_t>(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();


+ 3
- 3
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;
};


+ 5
- 4
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]


Завантаження…
Відмінити
Зберегти