Changeset 2155


Ignore:
Timestamp:
Dec 20, 2012, 2:01:28 AM (7 years ago)
Author:
sam
Message:

neercs: some fallback code when shader model 4 isn’t available.

Location:
trunk/tools/neercs/video
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/neercs/video/text-render.cpp

    r2154 r2155  
    2424
    2525extern char const *lolfx_text;
     26
     27#define HAVE_SHADER_4 1
    2628
    2729/*
     
    4951    m_char = m_shader->GetAttribLocation("in_Char",
    5052                                         VertexUsage::Color, 1);
     53#if !HAVE_SHADER_4
     54    m_vertexid = m_shader->GetAttribLocation("in_VertexID",
     55                                             VertexUsage::Position, 0);
     56#endif
    5157    m_texture = m_shader->GetUniformLocation("u_Texture");
    5258    m_transform = m_shader->GetUniformLocation("u_Transform");
    5359    m_datasize = m_shader->GetUniformLocation("u_DataSize");
    5460    m_vdecl
     61#if HAVE_SHADER_4
     62      = new VertexDeclaration(VertexStream<uint32_t>(VertexUsage::Color),
     63                              VertexStream<uint32_t>(VertexUsage::Color));
     64#else
    5565      = new VertexDeclaration(VertexStream<u8vec4>(VertexUsage::Color),
    56                               VertexStream<u8vec4>(VertexUsage::Color));
     66                              VertexStream<u8vec4>(VertexUsage::Color),
     67                              VertexStream<float>(VertexUsage::Position));
     68#endif
    5769
    5870    CreateBuffers();
     
    6173void TextRender::CreateBuffers()
    6274{
    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
    6588
    6689    m_fbo = new FrameBuffer(m_fbo_size);
     
    7497    if (current_size != m_canvas_size)
    7598    {
     99        delete m_vbo1;
    76100        delete m_vbo2;
    77101        delete m_vbo3;
     
    96120
    97121    /* Upload libcaca canvas contents to the vertex buffers */
    98     uint32_t *colors = (uint32_t *)m_vbo2->Lock(0, 0);
     122    uint32_t *colors = (uint32_t *)m_vbo1->Lock(0, 0);
    99123    for (int j = 0; j < m_canvas_size.y; j++)
    100124    for (int i = 0; i < m_canvas_size.x; i++)
     
    109133    memcpy(colors, caca_get_canvas_attrs(m_caca),
    110134           m_cells * sizeof(uint32_t));
    111     m_vbo2->Unlock();
    112 
    113     uint32_t *chars = (uint32_t *)m_vbo3->Lock(0, 0);
     135    m_vbo1->Unlock();
     136
     137    uint32_t *chars = (uint32_t *)m_vbo2->Lock(0, 0);
    114138    memcpy(chars, caca_get_canvas_chars(m_caca),
    115139           m_cells * sizeof(uint32_t));
    116     m_vbo3->Unlock();
     140    m_vbo2->Unlock();
    117141
    118142    m_fbo->Bind();
     
    132156    m_shader->SetUniform(m_datasize, vec2(m_canvas_size.x,
    133157                                          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
    136163    m_vdecl->Bind();
    137164    m_vdecl->DrawElements(MeshPrimitive::Points, 0, m_cells);
  • trunk/tools/neercs/video/text-render.h

    r2091 r2155  
    2323
    2424    Shader *m_shader;
    25     ShaderAttrib m_color, m_char;
     25    ShaderAttrib m_color, m_char, m_vertexid;
    2626    ShaderUniform m_texture, m_transform, m_datasize;
    2727    VertexDeclaration *m_vdecl;
    28     VertexBuffer *m_vbo2, *m_vbo3;
     28    VertexBuffer *m_vbo1, *m_vbo2, *m_vbo3;
    2929
    3030    FrameBuffer *m_fbo;
  • trunk/tools/neercs/video/text.lolfx

    r2154 r2155  
    33#version 130
    44
    5 #define HAVE_UINT 1
     5#define HAVE_SHADER_4 1
    66
    7 #if HAVE_UINT
     7#if HAVE_SHADER_4
    88in uint in_Char, in_Attr;
    99#else
    1010in vec4 in_Char, in_Attr;
     11in float in_VertexID;
    1112#endif
    1213
     
    2021void main()
    2122{
    22 #if HAVE_UINT
     23#if HAVE_SHADER_4
    2324    float u = float(in_Char & 0xfu) / 32.0 + 0.0;
    2425    float v = float((in_Char >> 4u) & 0xfu) / 32.0 + 0.5;
     
    3132    pass_UV = vec2(u, v);
    3233
    33 #if HAVE_UINT
     34#if HAVE_SHADER_4
    3435    float A = float(in_Attr >> 29u) / 7.0;
    3536    float B = float((in_Attr >> 25u) & 0xfu) / 15.0;
     
    6364    gl_PointSize = u_DataSize[1];
    6465
     66#if HAVE_SHADER_4
    6567    vec2 coord = vec2(gl_VertexID % int(u_DataSize[0]),
    6668                      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
    6774    gl_Position = u_Transform * vec4(coord, 0.0, 1.0);
    6875}
Note: See TracChangeset for help on using the changeset viewer.