Changeset 2155
- Timestamp:
- Dec 20, 2012, 2:01:28 AM (10 years ago)
- Location:
- trunk/tools/neercs/video
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/neercs/video/text-render.cpp
r2154 r2155 24 24 25 25 extern char const *lolfx_text; 26 27 #define HAVE_SHADER_4 1 26 28 27 29 /* … … 49 51 m_char = m_shader->GetAttribLocation("in_Char", 50 52 VertexUsage::Color, 1); 53 #if !HAVE_SHADER_4 54 m_vertexid = m_shader->GetAttribLocation("in_VertexID", 55 VertexUsage::Position, 0); 56 #endif 51 57 m_texture = m_shader->GetUniformLocation("u_Texture"); 52 58 m_transform = m_shader->GetUniformLocation("u_Transform"); 53 59 m_datasize = m_shader->GetUniformLocation("u_DataSize"); 54 60 m_vdecl 61 #if HAVE_SHADER_4 62 = new VertexDeclaration(VertexStream<uint32_t>(VertexUsage::Color), 63 VertexStream<uint32_t>(VertexUsage::Color)); 64 #else 55 65 = new VertexDeclaration(VertexStream<u8vec4>(VertexUsage::Color), 56 VertexStream<u8vec4>(VertexUsage::Color)); 66 VertexStream<u8vec4>(VertexUsage::Color), 67 VertexStream<float>(VertexUsage::Position)); 68 #endif 57 69 58 70 CreateBuffers(); … … 61 73 void TextRender::CreateBuffers() 62 74 { 63 m_vbo2 = new VertexBuffer(m_cells * sizeof(int32_t)); 64 m_vbo3 = new VertexBuffer(m_cells * sizeof(u8vec4)); 75 #if HAVE_SHADER_4 76 m_vbo1 = new VertexBuffer(m_cells * sizeof(uint32_t)); 77 m_vbo2 = new VertexBuffer(m_cells * sizeof(uint32_t)); 78 #else 79 m_vbo1 = new VertexBuffer(m_cells * sizeof(u8vec4)); 80 m_vbo2 = new VertexBuffer(m_cells * sizeof(u8vec4)); 81 m_vbo3 = new VertexBuffer(4 * m_cells * sizeof(float)); 82 83 float *idx = (float *)m_vbo3->Lock(0, 0); 84 for (int i = 0; i < m_cells; i++) 85 idx[i] = (float)i; 86 m_vbo3->Unlock(); 87 #endif 65 88 66 89 m_fbo = new FrameBuffer(m_fbo_size); … … 74 97 if (current_size != m_canvas_size) 75 98 { 99 delete m_vbo1; 76 100 delete m_vbo2; 77 101 delete m_vbo3; … … 96 120 97 121 /* Upload libcaca canvas contents to the vertex buffers */ 98 uint32_t *colors = (uint32_t *)m_vbo 2->Lock(0, 0);122 uint32_t *colors = (uint32_t *)m_vbo1->Lock(0, 0); 99 123 for (int j = 0; j < m_canvas_size.y; j++) 100 124 for (int i = 0; i < m_canvas_size.x; i++) … … 109 133 memcpy(colors, caca_get_canvas_attrs(m_caca), 110 134 m_cells * sizeof(uint32_t)); 111 m_vbo 2->Unlock();112 113 uint32_t *chars = (uint32_t *)m_vbo 3->Lock(0, 0);135 m_vbo1->Unlock(); 136 137 uint32_t *chars = (uint32_t *)m_vbo2->Lock(0, 0); 114 138 memcpy(chars, caca_get_canvas_chars(m_caca), 115 139 m_cells * sizeof(uint32_t)); 116 m_vbo 3->Unlock();140 m_vbo2->Unlock(); 117 141 118 142 m_fbo->Bind(); … … 132 156 m_shader->SetUniform(m_datasize, vec2(m_canvas_size.x, 133 157 max(m_font_size.x, m_font_size.y))); 134 m_vdecl->SetStream(m_vbo2, m_color); 135 m_vdecl->SetStream(m_vbo3, m_char); 158 m_vdecl->SetStream(m_vbo1, m_color); 159 m_vdecl->SetStream(m_vbo2, m_char); 160 #if !HAVE_SHADER_4 161 m_vdecl->SetStream(m_vbo3, m_vertexid); 162 #endif 136 163 m_vdecl->Bind(); 137 164 m_vdecl->DrawElements(MeshPrimitive::Points, 0, m_cells); -
trunk/tools/neercs/video/text-render.h
r2091 r2155 23 23 24 24 Shader *m_shader; 25 ShaderAttrib m_color, m_char ;25 ShaderAttrib m_color, m_char, m_vertexid; 26 26 ShaderUniform m_texture, m_transform, m_datasize; 27 27 VertexDeclaration *m_vdecl; 28 VertexBuffer *m_vbo 2, *m_vbo3;28 VertexBuffer *m_vbo1, *m_vbo2, *m_vbo3; 29 29 30 30 FrameBuffer *m_fbo; -
trunk/tools/neercs/video/text.lolfx
r2154 r2155 3 3 #version 130 4 4 5 #define HAVE_ UINT15 #define HAVE_SHADER_4 1 6 6 7 #if HAVE_ UINT7 #if HAVE_SHADER_4 8 8 in uint in_Char, in_Attr; 9 9 #else 10 10 in vec4 in_Char, in_Attr; 11 in float in_VertexID; 11 12 #endif 12 13 … … 20 21 void main() 21 22 { 22 #if HAVE_ UINT23 #if HAVE_SHADER_4 23 24 float u = float(in_Char & 0xfu) / 32.0 + 0.0; 24 25 float v = float((in_Char >> 4u) & 0xfu) / 32.0 + 0.5; … … 31 32 pass_UV = vec2(u, v); 32 33 33 #if HAVE_ UINT34 #if HAVE_SHADER_4 34 35 float A = float(in_Attr >> 29u) / 7.0; 35 36 float B = float((in_Attr >> 25u) & 0xfu) / 15.0; … … 63 64 gl_PointSize = u_DataSize[1]; 64 65 66 #if HAVE_SHADER_4 65 67 vec2 coord = vec2(gl_VertexID % int(u_DataSize[0]), 66 68 gl_VertexID / int(u_DataSize[0])); 69 #else 70 vec2 coord = vec2(mod(in_VertexID, u_DataSize[0]), 71 floor(in_VertexID / u_DataSize[0])); 72 #endif 73 67 74 gl_Position = u_Transform * vec4(coord, 0.0, 1.0); 68 75 }
Note: See TracChangeset
for help on using the changeset viewer.