Changeset 1963


Ignore:
Timestamp:
Oct 1, 2012, 1:49:53 AM (5 years ago)
Author:
sam
Message:

gpu: add support for triangle strips and fans, and change the DrawElement
calls so that they take a number of vertices or indexes, not elements.

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/easymesh/easymesh.cpp

    r1888 r1963  
    126126    m_gpu.vdecl->DrawIndexedElements(MeshPrimitive::Triangles,
    127127                                     0, 0, m_gpu.vertexcount,
    128                                      0, m_gpu.indexcount / 3);
     128                                     0, m_gpu.indexcount);
    129129    m_gpu.ibo->Unbind();
    130130    m_gpu.vdecl->Unbind();
  • trunk/src/gpu/vertexbuffer.cpp

    r1961 r1963  
    136136    {
    137137    case MeshPrimitive::Triangles:
    138         if (FAILED(g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST, skip, count)))
     138        if (FAILED(g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST,
     139                                              skip, count)))
     140            Abort();
     141        break;
     142    case MeshPrimitive::TriangleStrips:
     143        if (FAILED(g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,
     144                                              skip, count)))
     145            Abort();
     146        break;
     147    case MeshPrimitive::TriangleFans:
     148        if (FAILED(g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
     149                                              skip, count)))
    139150            Abort();
    140151        break;
    141152    case MeshPrimitive::Points:
    142         if (FAILED(g_d3ddevice->DrawPrimitive(D3DPT_POINTLIST, skip, count)))
     153        if (FAILED(g_d3ddevice->DrawPrimitive(D3DPT_POINTLIST,
     154                                              skip, count)))
    143155            Abort();
    144156        break;
     
    158170    {
    159171    case MeshPrimitive::Triangles:
    160         glDrawArrays(GL_TRIANGLES, skip * 3, count * 3);
     172        glDrawArrays(GL_TRIANGLES, skip, count);
     173        break;
     174    case MeshPrimitive::TriangleStrips:
     175        glDrawArrays(GL_TRIANGLE_STRIP, skip, count);
     176        break;
     177    case MeshPrimitive::TriangleFans:
     178        glDrawArrays(GL_TRIANGLE_FAN, skip, count);
    161179        break;
    162180    case MeshPrimitive::Points:
     
    186204    {
    187205    case MeshPrimitive::Triangles:
    188         if (FAILED(g_d3ddevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, vbase, vskip, vcount, skip, count)))
     206        if (FAILED(g_d3ddevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,
     207                                           vbase, vskip, vcount, skip, count)))
     208            Abort();
     209        break;
     210    case MeshPrimitive::TriangleStrips:
     211        if (FAILED(g_d3ddevice->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP,
     212                                           vbase, vskip, vcount, skip, count)))
     213            Abort();
     214        break;
     215    case MeshPrimitive::TriangleFans:
     216        if (FAILED(g_d3ddevice->DrawIndexedPrimitive(D3DPT_TRIANGLEFAN,
     217                                           vbase, vskip, vcount, skip, count)))
    189218            Abort();
    190219        break;
    191220    case MeshPrimitive::Points:
    192         if (FAILED(g_d3ddevice->DrawIndexedPrimitive(D3DPT_POINTLIST, vbase, vskip, vcount, skip, count)))
     221        if (FAILED(g_d3ddevice->DrawIndexedPrimitive(D3DPT_POINTLIST,
     222                                           vbase, vskip, vcount, skip, count)))
    193223            Abort();
    194224        break;
     
    210240        /* FIXME: ignores most of the arguments! */
    211241        (void)vbase; (void)vskip; (void)vcount; (void)skip;
    212         glDrawElements(GL_TRIANGLES, count * 3, GL_UNSIGNED_SHORT, 0);
     242        glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, 0);
     243        break;
     244    case MeshPrimitive::TriangleStrips:
     245        /* FIXME: ignores most of the arguments! */
     246        (void)vbase; (void)vskip; (void)vcount; (void)skip;
     247        glDrawElements(GL_TRIANGLE_STRIP, count, GL_UNSIGNED_SHORT, 0);
     248        break;
     249    case MeshPrimitive::TriangleFans:
     250        /* FIXME: ignores most of the arguments! */
     251        (void)vbase; (void)vskip; (void)vcount; (void)skip;
     252        glDrawElements(GL_TRIANGLE_FAN, count, GL_UNSIGNED_SHORT, 0);
    213253        break;
    214254    case MeshPrimitive::Points:
  • trunk/src/gpu/vertexbuffer.h

    r1788 r1963  
    7373    {
    7474        Triangles,
     75        TriangleStrips,
     76        TriangleFans,
    7577        Points,
    7678    }
     
    185187
    186188    void Bind();
     189
     190    /* Draw elements. See MeshPrimitive for a list of all available
     191     * types. Both skip and count are numbers of vertices, not primitives. */
    187192    void DrawElements(MeshPrimitive type, int skip, int count);
     193
     194    /* Draw elements. See MeshPrimitive for a list of all available
     195     * types. Both skip and count are numbers of indices, not primitives. */
    188196    void DrawIndexedElements(MeshPrimitive type, int vbase, int vskip,
    189197                             int vcount, int skip, int count);
     198
    190199    void Unbind();
    191200    void SetStream(VertexBuffer *vb, ShaderAttrib attr1,
  • trunk/src/gradient.cpp

    r1949 r1963  
    118118
    119119    /* Draw arrays */
    120     data->m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 2);
     120    data->m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6);
    121121}
    122122
  • trunk/src/scene.cpp

    r1945 r1963  
    256256
    257257        /* Draw arrays */
    258         data->m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, (n - i) * 2);
     258        data->m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, (n - i) * 6);
    259259        data->m_vdecl->Unbind();
    260260        data->tiles[i].tileset->Unbind();
  • trunk/tutorial/01_triangle.cpp

    r1647 r1963  
    6060        m_vdecl->SetStream(m_vbo, m_coord);
    6161        m_vdecl->Bind();
    62         m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 1);
     62        m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 3);
    6363        m_vdecl->Unbind();
    6464    }
  • trunk/tutorial/02_cube.cpp

    r1647 r1963  
    113113        m_ibo->Bind();
    114114        m_vdecl->DrawIndexedElements(MeshPrimitive::Triangles, 0, 0,
    115                                      m_mesh.Count(), 0, m_indices.Count());
     115                                     m_mesh.Count(), 0, m_indices.Count() * 3);
    116116        m_ibo->Unbind();
    117117        m_vdecl->Unbind();
  • trunk/tutorial/03_noise.cpp

    r1827 r1963  
    6969        m_vdecl->SetStream(m_vbo, m_coord);
    7070        m_vdecl->Bind();
    71         m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 2);
     71        m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6);
    7272        m_vdecl->Unbind();
    7373    }
  • trunk/tutorial/08_fbo.cpp

    r1817 r1963  
    100100        m_vdecl->SetStream(m_vbo, m_coord);
    101101        m_vdecl->Bind();
    102         m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 2);
     102        m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6);
    103103        m_vdecl->Unbind();
    104104#endif
     
    109109        m_vdecl->SetStream(m_vbo, m_coord);
    110110        m_vdecl->Bind();
    111         m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 2);
     111        m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6);
    112112        m_vdecl->Unbind();
    113113        m_shader->Unbind();
     
    119119        m_vdecl->SetStream(m_vbo, m_coord);
    120120        m_vdecl->Bind();
    121         m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 2);
     121        m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6);
    122122        m_vdecl->Unbind();
    123123        m_shader->Unbind();
  • trunk/tutorial/11_fractal.cpp

    r1921 r1963  
    579579#else
    580580#endif
    581         m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 2);
     581        m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6);
    582582        m_vdecl->Unbind();
    583583    }
Note: See TracChangeset for help on using the changeset viewer.