Changeset 1227


Ignore:
Timestamp:
Apr 14, 2012, 8:28:15 PM (8 years ago)
Author:
sam
Message:

gpu: implement vertex buffer streams for Direct3D. OpenGL is missing for now.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core.h

    r1224 r1227  
    9999#include "layer.h"
    100100#include "gpu/shader.h"
     101#include "gpu/vertexbuffer.h"
    101102#include "gpu/vbo.h"
    102 #include "gpu/vertexbuffer.h"
    103103#include "image/image.h"
    104104#include "application/application.h"
  • trunk/src/gpu/shader.cpp

    r1221 r1227  
    232232}
    233233
    234 int Shader::GetAttribLocation(char const *attr) const
    235 {
    236 #if defined USE_D3D9 || defined _XBOX
    237     /* FIXME: do we have attribs on these platforms? */
    238     return 0;
    239 #elif !defined __CELLOS_LV2__
    240     return glGetAttribLocation(data->prog_id, attr);
    241 #else
    242     /* FIXME: need to differentiate between vertex and fragment program */
    243     return 0;
    244 #endif
     234ShaderAttrib Shader::GetAttribLocation(char const *attr,
     235                                       VertexUsage usage, int index) const
     236{
     237    ShaderAttrib ret;
     238#if defined USE_D3D9 || defined _XBOX
     239    ret.m_flags = (uint32_t)index << 16;
     240    ret.m_flags |= (uint32_t)usage;
     241#elif !defined __CELLOS_LV2__
     242    ret.m_flags = glGetAttribLocation(data->prog_id, attr);
     243#else
     244    /* FIXME: can we do this at all? */
     245#endif
     246    return ret;
    245247}
    246248
  • trunk/src/gpu/shader.h

    r1215 r1227  
    3535};
    3636
     37struct ShaderAttrib
     38{
     39    friend class Shader;
     40    friend class VertexDeclaration;
     41
     42public:
     43    ShaderAttrib(int flags = 0xffffffff) : m_flags(flags) {}
     44
     45private:
     46    uint32_t m_flags;
     47};
     48
    3749class ShaderData;
    3850
     
    4355    static void Destroy(Shader *shader);
    4456
    45     int GetAttribLocation(char const *attr) const;
     57    ShaderAttrib GetAttribLocation(char const *attr, struct VertexUsage usage,
     58                                   int index) const;
    4659
    4760    ShaderUniform GetUniformLocation(char const *uni) const;
  • trunk/src/gpu/vertexbuffer.cpp

    r1226 r1227  
    3333{
    3434
     35//
     36// The VertexBufferData class
     37// --------------------------
     38//
     39
     40class VertexBufferData
     41{
     42    friend class VertexBuffer;
     43    friend class VertexDeclaration;
     44
     45#if defined USE_D3D9
     46    IDirect3DVertexBuffer9 *m_vbo;
     47#elif defined _XBOX
     48    D3DVertexBuffer *m_vbo;
     49#elif !defined __CELLOS_LV2__ && !defined __ANDROID__
     50    GLuint m_vbo;
     51    uint8_t *m_memory;
     52    size_t m_size;
     53#endif
     54};
     55
     56//
     57// The VertexDeclaration class
     58// ---------------------------
     59//
     60
    3561VertexStreamBase const VertexStreamBase::Empty;
     62
     63VertexDeclaration::VertexDeclaration(VertexStreamBase const &s1,
     64                                     VertexStreamBase const &s2,
     65                                     VertexStreamBase const &s3,
     66                                     VertexStreamBase const &s4,
     67                                     VertexStreamBase const &s5,
     68                                     VertexStreamBase const &s6,
     69                                     VertexStreamBase const &s7,
     70                                     VertexStreamBase const &s8,
     71                                     VertexStreamBase const &s9,
     72                                     VertexStreamBase const &s10,
     73                                     VertexStreamBase const &s11,
     74                                     VertexStreamBase const &s12) : m_count(0)
     75{
     76    if (&s1 != &VertexStreamBase::Empty) AddStream(s1);
     77    if (&s2 != &VertexStreamBase::Empty) AddStream(s2);
     78    if (&s3 != &VertexStreamBase::Empty) AddStream(s3);
     79    if (&s4 != &VertexStreamBase::Empty) AddStream(s4);
     80    if (&s5 != &VertexStreamBase::Empty) AddStream(s5);
     81    if (&s6 != &VertexStreamBase::Empty) AddStream(s6);
     82    if (&s7 != &VertexStreamBase::Empty) AddStream(s7);
     83    if (&s8 != &VertexStreamBase::Empty) AddStream(s8);
     84    if (&s9 != &VertexStreamBase::Empty) AddStream(s9);
     85    if (&s10 != &VertexStreamBase::Empty) AddStream(s10);
     86    if (&s11 != &VertexStreamBase::Empty) AddStream(s11);
     87    if (&s12 != &VertexStreamBase::Empty) AddStream(s12);
     88    Initialize();
     89}
     90
     91VertexDeclaration::~VertexDeclaration()
     92{
     93#if defined _XBOX || defined USE_D3D9
     94#   if defined USE_D3D9
     95    IDirect3DVertexDeclaration9 *vdecl = (IDirect3DVertexDeclaration9 *)m_data;
     96#   elif defined _XBOX
     97    D3DVertexDeclaration *vdecl = (D3DVertexDeclaration *)m_data;
     98#   endif
     99
     100    vdecl->Release();
     101#else
     102
     103#endif
     104}
     105
     106void VertexDeclaration::Bind()
     107{
     108#if defined _XBOX || defined USE_D3D9
     109#   if defined USE_D3D9
     110    IDirect3DVertexDeclaration9 *vdecl = (IDirect3DVertexDeclaration9 *)m_data;
     111#   elif defined _XBOX
     112    D3DVertexDeclaration *vdecl = (D3DVertexDeclaration *)m_data;
     113#   endif
     114
     115    g_d3ddevice->SetVertexDeclaration(vdecl);
     116#else
     117
     118#endif
     119}
     120
     121void VertexDeclaration::SetStream(VertexBuffer *vb, ShaderAttrib attr1,
     122                                                    ShaderAttrib attr2,
     123                                                    ShaderAttrib attr3,
     124                                                    ShaderAttrib attr4,
     125                                                    ShaderAttrib attr5,
     126                                                    ShaderAttrib attr6,
     127                                                    ShaderAttrib attr7,
     128                                                    ShaderAttrib attr8,
     129                                                    ShaderAttrib attr9,
     130                                                    ShaderAttrib attr10,
     131                                                    ShaderAttrib attr11,
     132                                                    ShaderAttrib attr12)
     133{
     134#if defined _XBOX || defined USE_D3D9
     135    /* Only the first item is required to know which stream this
     136     * is about; the rest of the information is stored in the
     137     * vertex declaration already. */
     138    uint32_t usage = attr1.m_flags >> 16;
     139    uint32_t index = attr1.m_flags & 0xffff;
     140    int usage_index = 0, stream = -1, stride = 0;
     141    for (int i = 0; i < m_count; i++)
     142    {
     143        if (m_streams[i].usage == usage)
     144            if (usage_index++ == index)
     145                stream = m_streams[i].index;
     146        if (stream == m_streams[i].index)
     147            stride += m_streams[i].size;
     148    }
     149
     150    /* Now we know the stream index and the element stride */
     151    /* FIXME: precompute most of the crap above! */
     152    if (stream >= 0)
     153        g_d3ddevice->SetStreamSource(stream, vb->m_data->m_vbo, 0, stride);
     154#else
     155    glBindBuffer(GL_ARRAY_BUFFER, vb);
     156    ShaderAttrib l[12] = { attr1, attr2, attr3, attr4, attr5, attr6,
     157                           attr7, attr8, attr9, attr10, attr11, attr12 };
     158    for (int i = 0; i < 12 && l[i].m_flags != 0xffffffff; i++)
     159    {
     160        uint32_t usage = l[i].m_flags >> 16;
     161        uint32_t index = l[i].m_flags & 0xffff;
     162    glEnableVertexAttribArray((GLint)attr.flags);
     163    /* FIXME: Hardcoded!! Where to get that from? */
     164    glVertexAttribPointer((GLint)attr.flags, 3, GL_FLOAT, GL_FALSE, 0, 0);
     165#endif
     166}
    36167
    37168void VertexDeclaration::Initialize()
     
    39170#if defined _XBOX || defined USE_D3D9
    40171    static D3DVERTEXELEMENT9 const end_element[] = { D3DDECL_END() };
    41     static D3DECLTYPE const X = D3DDECLTYPE_UNUSED;
    42     static D3DECLTYPE const tlut[] =
     172    static D3DDECLTYPE const X = D3DDECLTYPE_UNUSED;
     173    static D3DDECLTYPE const tlut[] =
    43174    {
    44175        D3DDECLTYPE_UNUSED,
     
    73204
    74205    D3DVERTEXELEMENT9 elements[12 + 1];
    75     int nstreams = 0;
    76     while (m_streams[nstreams].size)
    77     {
    78         elements[nstreams].Stream = m_streams[nstreams].index;
    79         elements[nstreams].Offset = 0;
    80         for (int i = 0; i < nstreams; i++)
    81             elements[nstreams].Offset += m_streams[nstreams].size;
    82 
    83         if (m_streams[nstreams].type >= 0
    84              && m_streams[nstreams].type < sizeof(tlut) / sizeof(*tlut))
    85             elements[nstreams].Type = tlut[m_streams[nstreams].type];
     206    for (int n = 0; n < m_count; n++)
     207    {
     208        elements[n].Stream = m_streams[n].index;
     209        elements[n].Offset = 0;
     210        for (int i = 0; i < n; i++)
     211            elements[n].Offset += m_streams[n].size;
     212
     213        if (m_streams[n].stream_type >= 0
     214             && m_streams[n].stream_type < sizeof(tlut) / sizeof(*tlut))
     215            elements[n].Type = tlut[m_streams[n].stream_type];
    86216        else
    87             elements[nstreams].Type = D3DDECLTYPE_UNUSED;
    88 
    89         elements[nstreams].Method = D3DDECLMETHOD_DEFAULT;
    90 
    91         if (m_streams[nstreams].usage >= 0
    92              && m_streams[nstreams].usage < sizeof(ulut) / sizeof(*ulut))
    93             elements[nstreams].Type = ulut[m_streams[nstreams].usage];
     217            elements[n].Type = D3DDECLTYPE_UNUSED;
     218
     219        elements[n].Method = D3DDECLMETHOD_DEFAULT;
     220
     221        if (m_streams[n].usage >= 0
     222             && m_streams[n].usage < sizeof(ulut) / sizeof(*ulut))
     223            elements[n].Usage = ulut[m_streams[n].usage];
    94224        else
    95             elements[nstreams].Type = D3DDECLUSAGE_POSITION;
    96 
    97         elements[nstreams].UsageIndex = 0;
    98         for (int i = 0; i < nstreams; i++)
    99             if (elements[i].Stream == elements[nstreams].Stream
    100                  && elements[i].Usage == elements[nstreams].Usage)
    101                 elements[nstreams].UsageIndex++;
    102 
    103         nstreams++;
     225            elements[n].Usage = D3DDECLUSAGE_POSITION;
     226
     227        elements[n].UsageIndex = 0;
     228        for (int i = 0; i < n; i++)
     229            if (elements[i].Stream == elements[n].Stream
     230                 && elements[i].Usage == elements[n].Usage)
     231                elements[n].UsageIndex++;
    104232    }
    105     elements[nstreams] = end_element[0];
     233    elements[m_count] = end_element[0];
    106234
    107235#   if defined USE_D3D9
     
    117245
    118246#endif
    119 }
    120 
    121 VertexDeclaration::~VertexDeclaration()
    122 {
    123 #if defined _XBOX || defined USE_D3D9
    124 #   if defined USE_D3D9
    125     IDirect3DVertexDeclaration9 *vdecl = (IDirect3DVertexDeclaration9 *)m_data;
    126 #   elif defined _XBOX
    127     D3DVertexDeclaration *vdecl = (D3DVertexDeclaration *)m_data;
    128 #   endif
    129 
    130     vdecl->Release();
    131 #else
    132 
    133 #endif
    134 }
    135 
    136 void VertexDeclaration::Bind()
    137 {
    138 #if defined _XBOX || defined USE_D3D9
    139 #   if defined USE_D3D9
    140     IDirect3DVertexDeclaration9 *vdecl = (IDirect3DVertexDeclaration9 *)m_data;
    141 #   elif defined _XBOX
    142     D3DVertexDeclaration *vdecl = (D3DVertexDeclaration *)m_data;
    143 #   endif
    144 
    145     g_d3ddevice->SetVertexDeclaration(vdecl);
    146 #else
    147 
    148 #endif
    149 }
    150 
    151 VertexDeclaration::VertexDeclaration(VertexStreamBase const &s1,
    152                                      VertexStreamBase const &s2,
    153                                      VertexStreamBase const &s3,
    154                                      VertexStreamBase const &s4,
    155                                      VertexStreamBase const &s5,
    156                                      VertexStreamBase const &s6,
    157                                      VertexStreamBase const &s7,
    158                                      VertexStreamBase const &s8,
    159                                      VertexStreamBase const &s9,
    160                                      VertexStreamBase const &s10,
    161                                      VertexStreamBase const &s11,
    162                                      VertexStreamBase const &s12) : m_count(0)
    163 {
    164     if (&s1 != &VertexStreamBase::Empty) AddStream(s1);
    165     if (&s2 != &VertexStreamBase::Empty) AddStream(s2);
    166     if (&s3 != &VertexStreamBase::Empty) AddStream(s3);
    167     if (&s4 != &VertexStreamBase::Empty) AddStream(s4);
    168     if (&s5 != &VertexStreamBase::Empty) AddStream(s5);
    169     if (&s6 != &VertexStreamBase::Empty) AddStream(s6);
    170     if (&s7 != &VertexStreamBase::Empty) AddStream(s7);
    171     if (&s8 != &VertexStreamBase::Empty) AddStream(s8);
    172     if (&s9 != &VertexStreamBase::Empty) AddStream(s9);
    173     if (&s10 != &VertexStreamBase::Empty) AddStream(s10);
    174     if (&s11 != &VertexStreamBase::Empty) AddStream(s11);
    175     if (&s12 != &VertexStreamBase::Empty) AddStream(s12);
    176     Initialize();
    177247}
    178248
     
    191261}
    192262
     263//
     264// The VertexBuffer class
     265// ----------------------
     266//
     267
     268VertexBuffer::VertexBuffer(size_t size)
     269  : m_data(new VertexBufferData)
     270{
     271#if defined USE_D3D9 || defined _XBOX
     272    g_d3ddevice->CreateVertexBuffer(size, D3DUSAGE_WRITEONLY, NULL,
     273                                    D3DPOOL_MANAGED, &m_data->m_vbo, NULL);
     274    new uint8_t[size];
     275#elif !defined __CELLOS_LV2__ && !defined __ANDROID__
     276    glGenBuffers(1, &m_data->m_vbo);
     277    m_data->m_memory = new uint8_t[size];
     278    m_data->m_size = size;
     279#endif
     280}
     281
     282VertexBuffer::~VertexBuffer()
     283{
     284#if defined USE_D3D9 || defined _XBOX
     285    m_data->m_vbo->Release();
     286#elif !defined __CELLOS_LV2__ && !defined __ANDROID__
     287    glDeleteBuffers(1, &m_data->m_vbo);
     288    delete[] m_data->m_memory;
     289#endif
     290}
     291
     292void *VertexBuffer::Lock(size_t offset, size_t size)
     293{
     294#if defined USE_D3D9 || defined _XBOX
     295    void *ret;
     296    if (FAILED(m_data->m_vbo->Lock(offset, size, (void **)&ret, 0)))
     297        exit(0);
     298    return ret;
     299#elif !defined __CELLOS_LV2__ && !defined __ANDROID__
     300    return m_data->m_memory + offset;
     301#endif
     302}
     303
     304void VertexBuffer::Unlock()
     305{
     306#if defined USE_D3D9 || defined _XBOX
     307    m_data->m_vbo->Unlock();
     308#elif !defined __CELLOS_LV2__ && !defined __ANDROID__
     309    glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
     310    glBufferData(GL_ARRAY_BUFFER, m_data->m_size, m_data->m_memory,
     311                 GL_STATIC_DRAW);
     312#endif
     313}
     314
    193315} /* namespace lol */
    194316
  • trunk/src/gpu/vertexbuffer.h

    r1226 r1227  
    1010
    1111//
    12 // The VertexBuffer class
    13 // ----------------------
     12// The VertexBuffer and VertexDeclaration classes
     13// ----------------------------------------------
    1414//
    1515
     
    2121namespace lol
    2222{
     23
     24class VertexBuffer
     25{
     26    friend class VertexDeclaration;
     27
     28public:
     29    VertexBuffer(size_t size);
     30    ~VertexBuffer();
     31
     32    void *Lock(size_t offset, size_t size);
     33    void Unlock();
     34
     35private:
     36    class VertexBufferData *m_data;
     37};
    2338
    2439struct VertexUsage
     
    8196#undef LOL_TYPE
    8297
    83     template<typename T> inline void AddStream(int n, int usage)
     98    template<typename T> inline void AddStream(int n, VertexUsage usage)
    8499    {
    85100        m_streams[n].stream_type = GetType((T *)NULL);
     
    97112
    98113template<>
    99 inline void VertexStreamBase::AddStream<void>(int n, int usage)
     114inline void VertexStreamBase::AddStream<void>(int n, VertexUsage usage)
    100115{
    101116    (void)usage;
     
    150165
    151166    void Bind();
     167    void SetStream(VertexBuffer *vb, ShaderAttrib attr1,
     168                                     ShaderAttrib attr2 = ShaderAttrib(),
     169                                     ShaderAttrib attr3 = ShaderAttrib(),
     170                                     ShaderAttrib attr4 = ShaderAttrib(),
     171                                     ShaderAttrib attr5 = ShaderAttrib(),
     172                                     ShaderAttrib attr6 = ShaderAttrib(),
     173                                     ShaderAttrib attr7 = ShaderAttrib(),
     174                                     ShaderAttrib attr8 = ShaderAttrib(),
     175                                     ShaderAttrib attr9 = ShaderAttrib(),
     176                                     ShaderAttrib attr10 = ShaderAttrib(),
     177                                     ShaderAttrib attr11 = ShaderAttrib(),
     178                                     ShaderAttrib attr12 = ShaderAttrib());
    152179
    153180private:
  • trunk/test/tutorial/tut01.cpp

    r1226 r1227  
    100100#endif
    101101            );
    102 #if !defined _XBOX && !defined USE_D3D9
    103             m_attrib = m_shader->GetAttribLocation("in_Position");
    104 #endif
    105             m_ready = true;
     102            m_coord = m_shader->GetAttribLocation("in_Position", VertexUsage::Position, 0);
    106103
    107 #if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ && !defined _XBOX && !defined USE_D3D9
    108             /* Method 1: store vertex buffer on the GPU memory */
    109             glGenBuffers(1, &m_vbo);
    110             glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
    111             glBufferData(GL_ARRAY_BUFFER, sizeof(m_vertices), m_vertices,
    112                          GL_STATIC_DRAW);
    113 #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ && !defined _XBOX && !defined USE_D3D9
    114             /* Method 2: upload vertex information at each frame */
    115 #elif defined _XBOX || defined USE_D3D9
    116             m_vdecl =
    117               new VertexDeclaration(VertexStream<vec2>(VertexUsage::Position));
     104            m_vdecl = new VertexDeclaration(VertexStream<vec2>(VertexUsage::Position));
    118105
    119             if (FAILED(g_d3ddevice->CreateVertexBuffer(sizeof(m_vertices), D3DUSAGE_WRITEONLY, NULL, D3DPOOL_MANAGED, &m_vbo, NULL)))
    120                 exit(0);
    121 
    122             vec2 *vertices;
    123             if (FAILED(m_vbo->Lock(0, 0, (void **)&vertices, 0)))
    124                 exit(0);
     106            m_vbo = new VertexBuffer(sizeof(m_vertices));
     107            void *vertices = m_vbo->Lock(0, 0);
    125108            memcpy(vertices, m_vertices, sizeof(m_vertices));
    126109            m_vbo->Unlock();
    127 #else
    128 #endif
     110
     111            m_ready = true;
    129112
    130113            /* FIXME: this object never cleans up */
     
    133116        m_shader->Bind();
    134117        m_vdecl->Bind();
     118        m_vdecl->SetStream(m_vbo, m_coord);
    135119#if defined _XBOX || defined USE_D3D9
    136120        g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
    137         g_d3ddevice->SetStreamSource(0, m_vbo, 0, sizeof(*m_vertices));
    138 #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__
    139         glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
    140         glEnableVertexAttribArray(m_attrib);
    141         glVertexAttribPointer(m_attrib, 2, GL_FLOAT, GL_FALSE, 0, 0);
    142 #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__
    143         /* Never used for now */
    144         glEnableVertexAttribArray(m_attrib);
    145         glVertexAttribPointer(m_attrib, 2, GL_FLOAT, GL_FALSE, 0, m_vertices);
    146 #else
    147         glEnableClientState(GL_VERTEX_ARRAY);
    148         glVertexPointer(3, GL_FLOAT, 0, m_vertices);
    149121#endif
    150122
     
    172144    Shader *m_shader;
    173145    VertexDeclaration *m_vdecl;
    174 #if defined USE_D3D9
    175     IDirect3DVertexBuffer9 *m_vbo;
    176 #elif defined _XBOX
    177     D3DVertexBuffer *m_vbo;
    178 #else
    179     int m_attrib;
    180 #   if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__
    181     GLuint m_vbo;
    182 #   endif
    183 #endif
     146    VertexBuffer *m_vbo;
     147    ShaderAttrib m_coord;
    184148    bool m_ready;
    185149};
  • trunk/test/tutorial/tut02.cpp

    r1226 r1227  
    139139#endif
    140140            );
    141 #if !defined _XBOX && !defined USE_D3D9
    142             m_coord = m_shader->GetAttribLocation("in_Vertex");
    143             m_color = m_shader->GetAttribLocation("in_Color");
    144 #endif
    145141            m_mvp = m_shader->GetUniformLocation("in_Matrix");
    146             m_ready = true;
     142            m_coord = m_shader->GetAttribLocation("in_Vertex",
     143                                                  VertexUsage::Position, 0);
     144            m_color = m_shader->GetAttribLocation("in_Color",
     145                                                  VertexUsage::Color, 0);
    147146
    148147            m_vdecl =
    149148              new VertexDeclaration(VertexStream<vec3>(VertexUsage::Position),
    150149                                    VertexStream<vec3>(VertexUsage::Color));
     150
     151            m_vbo = new VertexBuffer(sizeof(m_vertices));
     152            void *vertices = m_vbo->Lock(0, 0);
     153            memcpy(vertices, m_vertices, sizeof(m_vertices));
     154            m_vbo->Unlock();
     155
     156            m_cbo = new VertexBuffer(sizeof(m_colors));
     157            void *colors = m_cbo->Lock(0, 0);
     158            memcpy(colors, m_colors, sizeof(m_colors));
     159            m_cbo->Unlock();
     160
    151161#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ && !defined _XBOX && !defined USE_D3D9
    152162            /* Method 1: store vertex buffer on the GPU memory */
    153             glGenBuffers(1, &m_vbo);
    154             glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
    155             glBufferData(GL_ARRAY_BUFFER, sizeof(m_vertices), m_vertices,
    156                          GL_STATIC_DRAW);
    157             glGenBuffers(1, &m_cbo);
    158             glBindBuffer(GL_ARRAY_BUFFER, m_cbo);
    159             glBufferData(GL_ARRAY_BUFFER, sizeof(m_colors), m_colors,
    160                          GL_STATIC_DRAW);
    161163            glGenBuffers(1, &m_ibo);
    162164            glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ibo);
     
    164166                         GL_STATIC_DRAW);
    165167#elif defined _XBOX || defined USE_D3D9
    166             if (FAILED(g_d3ddevice->CreateVertexBuffer(sizeof(m_vertices), D3DUSAGE_WRITEONLY, NULL, D3DPOOL_MANAGED, &m_vbo, NULL)))
    167                 exit(0);
    168 
    169             vec3 *vertices;
    170             if (FAILED(m_vbo->Lock(0, 0, (void **)&vertices, 0)))
    171                 exit(0);
    172             memcpy(vertices, m_vertices, sizeof(m_vertices));
    173             m_vbo->Unlock();
    174 
    175             if (FAILED(g_d3ddevice->CreateVertexBuffer(sizeof(m_colors), D3DUSAGE_WRITEONLY, NULL, D3DPOOL_MANAGED, &m_cbo, NULL)))
    176                 exit(0);
    177 
    178             vec3 *colors;
    179             if (FAILED(m_cbo->Lock(0, 0, (void **)&colors, 0)))
    180                 exit(0);
    181             memcpy(colors, m_colors, sizeof(m_colors));
    182             m_cbo->Unlock();
    183 
    184168            int16_t *indices;
    185169            if (FAILED(g_d3ddevice->CreateIndexBuffer(sizeof(m_indices), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_ibo, NULL)))
     
    194178
    195179            /* FIXME: this object never cleans up */
     180            m_ready = true;
    196181        }
    197182
     
    199184        m_shader->SetUniform(m_mvp, m_matrix);
    200185        m_vdecl->Bind();
     186        m_vdecl->SetStream(m_vbo, m_coord);
     187        m_vdecl->SetStream(m_cbo, m_color);
     188
    201189#if defined _XBOX || defined USE_D3D9
    202190        g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
    203         g_d3ddevice->SetStreamSource(0, m_vbo, 0, sizeof(*m_vertices));
    204         g_d3ddevice->SetStreamSource(1, m_cbo, 0, sizeof(*m_colors));
    205191        g_d3ddevice->SetIndices(m_ibo);
    206192        g_d3ddevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 0, 0, sizeof(m_indices) / sizeof(*m_indices));
     
    238224    i16vec3 m_indices[12];
    239225    Shader *m_shader;
     226    ShaderAttrib m_coord, m_color;
     227    ShaderUniform m_mvp;
    240228    VertexDeclaration *m_vdecl;
     229    VertexBuffer *m_vbo, *m_cbo;
    241230#if defined USE_D3D9
    242     IDirect3DVertexBuffer9 *m_vbo, *m_cbo;
    243231    IDirect3DIndexBuffer9 *m_ibo;
    244232#elif defined _XBOX
    245     D3DVertexBuffer *m_vbo, *m_cbo;
    246233    D3DIndexBuffer *m_ibo;
    247234#else
    248     int m_coord, m_color;
    249235#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__
    250     GLuint m_vbo, m_cbo, m_ibo;
    251 #endif
    252 #endif
    253     ShaderUniform m_mvp;
     236    GLuint m_ibo;
     237#endif
     238#endif
    254239    bool m_ready;
    255240};
Note: See TracChangeset for help on using the changeset viewer.