Changeset 1627


Ignore:
Timestamp:
Jul 11, 2012, 8:29:22 PM (8 years ago)
Author:
sam
Message:

neercs: handle caca canvas size changes automatically.

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

Legend:

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

    r1561 r1627  
    3737    m_cells(m_canvas_size.x * m_canvas_size.y)
    3838{
    39     for (int j = 0; j < m_canvas_size.y; j++)
    40     for (int i = 0; i < m_canvas_size.x; i++)
    41         m_vertices << vec2(i, j);
    4239}
    4340
     
    6158                              VertexStream<uint32_t>(VertexUsage::Color));
    6259
    63     m_vbo1 = new VertexBuffer(m_vertices.Bytes());
    64     void *vertices = m_vbo1->Lock(0, 0);
    65     memcpy(vertices, &m_vertices[0], m_vertices.Bytes());
     60    CreateBuffers();
     61}
     62
     63void TextRender::CreateBuffers()
     64{
     65    m_vbo1 = new VertexBuffer(m_cells * sizeof(vec2));
     66    vec2 *vertices = (vec2 *)m_vbo1->Lock(0, 0);
     67    for (int j = 0; j < m_canvas_size.y; j++)
     68    for (int i = 0; i < m_canvas_size.x; i++)
     69        vertices[j * m_canvas_size.x + i] = vec2(i, j);
    6670    m_vbo1->Unlock();
    6771
     
    7478void TextRender::Render()
    7579{
     80    /* Handle canvas size changes */
     81    ivec2 current_size(caca_get_canvas_width(m_caca),
     82                       caca_get_canvas_height(m_caca));
     83    if (current_size != m_canvas_size)
     84    {
     85        delete m_vbo1;
     86        delete m_vbo2;
     87        delete m_vbo3;
     88        delete m_fbo;
     89
     90        m_canvas_size = current_size;
     91        m_fbo_size = m_font_size * m_canvas_size;
     92        m_cells = m_canvas_size.x * m_canvas_size.y;
     93
     94        CreateBuffers();
     95    }
     96
    7697    /* Transform matrix for the scene:
    7798     *  - translate to the centre of the glyph
  • trunk/tools/neercs/video/text-render.h

    r1503 r1627  
    1414
    1515private:
     16    void CreateBuffers();
     17
    1618    caca_canvas_t *m_caca;
    1719    ivec2 m_font_size, m_canvas_size, m_fbo_size;
    1820    int m_cells;
    1921
    20     Array<vec2> m_vertices;
    2122    TileSet *m_font;
    2223    Shader *m_shader;
Note: See TracChangeset for help on using the changeset viewer.