Changeset 1231


Ignore:
Timestamp:
Apr 15, 2012, 11:20:05 PM (8 years ago)
Author:
sam
Message:

gpu: move the platform-specific triangle drawing call to the VertexDeclaration
class, so that the calling code does not need to know what the backend is.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gpu/vertexbuffer.cpp

    r1230 r1231  
    119119}
    120120
     121void VertexDeclaration::DrawElements(MeshPrimitive type, int skip, int count)
     122{
     123#if defined _XBOX || defined USE_D3D9
     124    g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
     125    switch (type)
     126    {
     127    case MeshPrimitive::Triangles:
     128        g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST, skip, count);
     129        break;
     130    }
     131#else
     132    switch (type)
     133    {
     134    case MeshPrimitive::Triangles:
     135        glDrawArrays(GL_TRIANGLES, skip * 3, count * 3);
     136        break;
     137    }
     138#endif
     139}
     140
    121141void VertexDeclaration::Unbind()
    122142{
     
    124144    /* FIXME: Nothing to do? */
    125145#else
    126     /* FIXME: we need to record what happens */
     146    /* FIXME: we need to unbind what we bound */
    127147    //glDisableVertexAttribArray(m_attrib);
    128148    /* FIXME: only useful for VAOs */
    129149    //glBindBuffer(GL_ARRAY_BUFFER, 0);
     150    /* Or: */
     151    //glDisableVertexAttribArray(m_attrib);
     152    /* Or even: */
     153    //glDisableClientState(GL_VERTEX_ARRAY);
    130154#endif
    131155}
     
    186210         * the information. It sucks. */
    187211
    188         int attr_index = 0, usage_index = 0, stream = -1;
     212        int attr_index = 0, usage_index = 0;
    189213        /* First, find the stream index */
    190214        for (; attr_index < m_count; attr_index++)
    191215            if (m_streams[attr_index].usage == usage)
    192216                if (usage_index++ == index)
    193                 {
    194                     stream = m_streams[attr_index].index;
    195217                    break;
    196                 }
    197218
    198219        /* Now compute the stride and offset up to this stream index */
  • trunk/src/gpu/vertexbuffer.h

    r1230 r1231  
    6262};
    6363
     64struct MeshPrimitive
     65{
     66    enum Value
     67    {
     68        Triangles,
     69    }
     70    m_value;
     71
     72    inline MeshPrimitive(Value v) { m_value = v; }
     73    inline operator Value() { return m_value; }
     74};
     75
    6476class VertexStreamBase
    6577{
     
    165177
    166178    void Bind();
     179    void DrawElements(MeshPrimitive type, int skip, int count);
    167180    void Unbind();
    168181    void SetStream(VertexBuffer *vb, ShaderAttrib attr1,
  • trunk/test/tutorial/tut01.cpp

    r1228 r1231  
    1414
    1515#include "core.h"
    16 #include "lolgl.h"
    1716#include "loldebug.h"
    1817
    1918using namespace std;
    2019using namespace lol;
    21 
    22 #if defined _WIN32 && defined USE_D3D9
    23 #   define FAR
    24 #   define NEAR
    25 #   include <d3d9.h>
    26 #endif
    2720
    2821#if USE_SDL && defined __APPLE__
     
    3730#   undef main /* FIXME: still needed? */
    3831#   include <direct.h>
    39 #endif
    40 
    41 #if defined USE_D3D9
    42 extern IDirect3DDevice9 *g_d3ddevice;
    43 #elif defined _XBOX
    44 extern D3DDevice *g_d3ddevice;
    4532#endif
    4633
     
    6249        if (!m_ready)
    6350        {
    64 
    65 
    66 
    67 
    68 
    69 
    70 
    71 
    72 
    73 
    74 
    75 
    76 
    77 
    78 
    7951            m_shader = Shader::Create(
    8052#if !defined __CELLOS_LV2__ && !defined _XBOX && !defined USE_D3D9
     
    11789        m_vdecl->Bind();
    11890        m_vdecl->SetStream(m_vbo, m_coord);
    119 #if defined _XBOX || defined USE_D3D9
    120         g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
    121 #endif
    122 
    123 #if defined _XBOX || defined USE_D3D9
    124         g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);
    125 #else
    126         glDrawArrays(GL_TRIANGLES, 0, 3);
    127 #endif
    128 
     91        m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 1);
    12992        m_vdecl->Unbind();
    130 #if defined _XBOX || defined USE_D3D9
    131         /* FIXME: do we need to unset anything here? */
    132 #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__
    133         //glDisableVertexAttribArray(m_attrib);
    134         //glBindBuffer(GL_ARRAY_BUFFER, 0);
    135 #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__
    136         /* Never used for now */
    137         glDisableVertexAttribArray(m_attrib);
    138 #else
    139         glDisableClientState(GL_VERTEX_ARRAY);
    140 #endif
    14193    }
    14294
     
    14496    vec2 m_vertices[3];
    14597    Shader *m_shader;
     98    ShaderAttrib m_coord;
    14699    VertexDeclaration *m_vdecl;
    147100    VertexBuffer *m_vbo;
    148     ShaderAttrib m_coord;
    149101    bool m_ready;
    150102};
Note: See TracChangeset for help on using the changeset viewer.