Changeset 1228


Ignore:
Timestamp:
Apr 14, 2012, 11:33:08 PM (8 years ago)
Author:
sam
Message:

gpu: port the vertex buffer abstraction layer to OpenGL.

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/debug/quad.cpp

    r1215 r1228  
    1313#endif
    1414
    15 #if !defined USE_D3D9 && !defined _XBOX /* This file is meaningless on Xbox */
     15#if 0
    1616
    1717#if defined WIN32 && !_XBOX
     
    11201120} /* namespace lol */
    11211121
    1122 #endif /* !defined _XBOX */
     1122#endif /* 0 */
  • trunk/src/gpu/shader.cpp

    r1227 r1228  
    236236{
    237237    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? */
     238    ret.m_flags = (uint64_t)(uint16_t)usage << 16;
     239    ret.m_flags |= (uint64_t)(uint16_t)index;
     240#if defined USE_D3D9 || defined _XBOX
     241#elif !defined __CELLOS_LV2__
     242    ret.m_flags |= (uint64_t)
     243                  (uint32_t)glGetAttribLocation(data->prog_id, attr) << 32;
     244#else
     245    /* FIXME: can we do this at all on the PS3? */
    245246#endif
    246247    return ret;
  • trunk/src/gpu/shader.h

    r1227 r1228  
    2727
    2828public:
    29     ShaderUniform() : flags(0) {}
     29    inline ShaderUniform() : flags(0) {}
    3030
    3131private:
     
    4141
    4242public:
    43     ShaderAttrib(int flags = 0xffffffff) : m_flags(flags) {}
     43    inline ShaderAttrib() : m_flags((uint64_t)0 - 1) {}
    4444
    4545private:
    46     uint32_t m_flags;
     46    uint64_t m_flags;
    4747};
    4848
  • trunk/src/gpu/vertexbuffer.cpp

    r1227 r1228  
    115115    g_d3ddevice->SetVertexDeclaration(vdecl);
    116116#else
    117 
     117    /* FIXME: Nothing to do? */
     118#endif
     119}
     120
     121void VertexDeclaration::Unbind()
     122{
     123#if defined _XBOX || defined USE_D3D9
     124    /* FIXME: Nothing to do? */
     125#else
     126    /* FIXME: we need to record what happens */
     127    //glDisableVertexAttribArray(m_attrib);
     128    /* FIXME: only useful for VAOs */
     129    //glBindBuffer(GL_ARRAY_BUFFER, 0);
    118130#endif
    119131}
     
    136148     * is about; the rest of the information is stored in the
    137149     * vertex declaration already. */
    138     uint32_t usage = attr1.m_flags >> 16;
     150    uint32_t usage = (attr1.m_flags >> 16) & 0xffff;
    139151    uint32_t index = attr1.m_flags & 0xffff;
    140     int usage_index = 0, stream = -1, stride = 0;
     152
     153    /* Find the stream number */
     154    int usage_index = 0, stream = -1;
    141155    for (int i = 0; i < m_count; i++)
    142     {
    143156        if (m_streams[i].usage == usage)
    144157            if (usage_index++ == index)
     158            {
    145159                stream = m_streams[i].index;
     160                break;
     161            }
     162
     163    /* Compute this stream's stride */
     164    int stride = 0;
     165    for (int i = 0; i < m_count; i++)
    146166        if (stream == m_streams[i].index)
    147167            stride += m_streams[i].size;
    148     }
    149168
    150169    /* Now we know the stream index and the element stride */
     
    153172        g_d3ddevice->SetStreamSource(stream, vb->m_data->m_vbo, 0, stride);
    154173#else
    155     glBindBuffer(GL_ARRAY_BUFFER, vb);
     174    glBindBuffer(GL_ARRAY_BUFFER, vb->m_data->m_vbo);
    156175    ShaderAttrib l[12] = { attr1, attr2, attr3, attr4, attr5, attr6,
    157176                           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);
     177    for (int n = 0; n < 12 && l[n].m_flags != (uint64_t)0 - 1; n++)
     178    {
     179        uint32_t reg = l[n].m_flags >> 32;
     180        uint32_t usage = (l[n].m_flags >> 16) & 0xffff;
     181        uint32_t index = l[n].m_flags & 0xffff;
     182
     183        glEnableVertexAttribArray((GLint)reg);
     184
     185        /* We need to parse the whole vertex declaration to retrieve
     186         * the information. It sucks. */
     187
     188        int attr_index = 0, usage_index = 0, stream = -1;
     189        /* First, find the stream index */
     190        for (; attr_index < m_count; attr_index++)
     191            if (m_streams[attr_index].usage == usage)
     192                if (usage_index++ == index)
     193                {
     194                    stream = m_streams[attr_index].index;
     195                    break;
     196                }
     197
     198        /* Now compute the stride and offset up to this stream index */
     199        int stride = 0, offset = 0;
     200        for (int i = 0; i < m_count; i++)
     201            if (m_streams[i].index == m_streams[attr_index].index)
     202            {
     203                stride += m_streams[i].size;
     204                if (i < attr_index)
     205                    offset += m_streams[i].size;
     206            }
     207
     208        /* Finally, we need to retrieve the type of the data */
     209        static struct { GLint size; GLenum type; } const tlut[] =
     210        {
     211            { 0, 0 },
     212            { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, /* half */
     213            { 1, GL_FLOAT }, { 2, GL_FLOAT }, { 3, GL_FLOAT },
     214                { 4, GL_FLOAT }, /* float */
     215            { 1, GL_DOUBLE }, { 2, GL_DOUBLE }, { 3, GL_DOUBLE },
     216                { 4, GL_DOUBLE }, /* double */
     217            { 1, GL_BYTE }, { 2, GL_BYTE }, { 3, GL_BYTE },
     218                { 4, GL_BYTE }, /* int8_t */
     219            { 1, GL_UNSIGNED_BYTE }, { 2, GL_UNSIGNED_BYTE },
     220                { 3, GL_UNSIGNED_BYTE }, { 4, GL_UNSIGNED_BYTE }, /* uint8_t */
     221            { 1, GL_SHORT }, { 2, GL_SHORT }, { 3, GL_SHORT },
     222                { 4, GL_SHORT }, /* int16_t */
     223            { 1, GL_UNSIGNED_SHORT }, { 2, GL_UNSIGNED_SHORT }, { 3,
     224                GL_UNSIGNED_SHORT }, { 4, GL_UNSIGNED_SHORT }, /* uint16_t */
     225            { 1, GL_INT }, { 2, GL_INT }, { 3, GL_INT },
     226                { 4, GL_INT }, /* int32_t */
     227            { 1, GL_UNSIGNED_INT }, { 2, GL_UNSIGNED_INT },
     228                { 3, GL_UNSIGNED_INT }, { 4, GL_UNSIGNED_INT }, /* uint32_t */
     229        };
     230
     231        int type_index = m_streams[attr_index].stream_type;
     232        if (type_index < 0 || type_index >= sizeof(tlut) / sizeof(*tlut))
     233            type_index = 0;
     234Log::Error("Size %d Type %d Stride %d offset %d\n", tlut[type_index].size,
     235                              tlut[type_index].type,stride,offset);
     236
     237        glVertexAttribPointer((GLint)reg, tlut[type_index].size,
     238                              tlut[type_index].type, GL_FALSE,
     239                              stride, (GLvoid const *)(uintptr_t)offset);
     240    }
    165241#endif
    166242}
     
    307383    m_data->m_vbo->Unlock();
    308384#elif !defined __CELLOS_LV2__ && !defined __ANDROID__
    309     glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
     385    glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo);
    310386    glBufferData(GL_ARRAY_BUFFER, m_data->m_size, m_data->m_memory,
    311387                 GL_STATIC_DRAW);
  • trunk/src/gpu/vertexbuffer.h

    r1227 r1228  
    165165
    166166    void Bind();
     167    void Unbind();
    167168    void SetStream(VertexBuffer *vb, ShaderAttrib attr1,
    168169                                     ShaderAttrib attr2 = ShaderAttrib(),
  • trunk/src/gradient.cpp

    r1215 r1228  
    3333private:
    3434    Shader *shader;
    35 #if !defined USE_D3D9 && !defined _XBOX /* This file is meaningless on Xbox */
    36 
    37     GLuint bufs[2];
    38 #if defined HAVE_GL_2X && !defined __APPLE__
    39     GLuint vaos[1];
    40 #endif
    41 #endif
     35    VertexDeclaration *m_vdecl;
     36    VertexBuffer *m_vbo, *m_cbo;
    4237};
    4338
     
    6661    Entity::TickDraw(deltams);
    6762
    68 #if !defined USE_D3D9 && !defined _XBOX /* This file is meaningless on Xbox */
     63    float const vertex[] = {   0.0f,   0.0f, 0.0f,
     64                             640.0f,   0.0f, 0.0f,
     65                               0.0f, 480.0f, 0.0f,
     66                               0.0f, 480.0f, 0.0f,
     67                             640.0f, 480.0f, 0.0f,
     68                             640.0f,   0.0f, 0.0f, };
     69
     70    float const color[] = { 0.73f, 0.85f, 0.85f, 1.0f,
     71                            0.73f, 0.85f, 0.85f, 1.0f,
     72                            0.0f, 0.0f, 1.0f, 1.0f,
     73                            0.0f, 0.0f, 1.0f, 1.0f,
     74                            0.0f, 0.0f, 1.0f, 1.0f,
     75                            0.73f, 0.85f, 0.85f, 1.0f, };
     76
    6977    if (!data->shader)
    7078    {
    71 #if !defined __CELLOS_LV2__
     79#if !defined __CELLOS_LV2__ && !defined USE_D3D9 && !defined _XBOX
    7280        data->shader = Shader::Create(
    7381            "#version 130\n"
     
    157165            "}");
    158166#endif
    159 #if !defined __CELLOS_LV2__
    160         glGenBuffers(2, data->bufs);
    161 #   if defined HAVE_GL_2X && !defined __APPLE__
    162         glGenVertexArrays(1, data->vaos);
    163 #   endif
    164 #endif
     167        data->m_vbo = new VertexBuffer(sizeof(vertex));
     168        data->m_cbo = new VertexBuffer(sizeof(color));
     169
     170        data->m_vdecl = new VertexDeclaration(VertexStream<vec3>(VertexUsage::Position),
     171                                              VertexStream<vec4>(VertexUsage::Color));
    165172    }
    166173
     
    168175
    169176    ShaderUniform uni_mat;
    170     GLuint attr_pos, attr_col;
    171 #if !defined __CELLOS_LV2__
    172     attr_pos = data->shader->GetAttribLocation("in_Vertex");
    173     attr_col = data->shader->GetAttribLocation("in_Color");
    174 #endif
     177    ShaderAttrib attr_pos, attr_col;
     178    attr_pos = data->shader->GetAttribLocation("in_Vertex", VertexUsage::Position, 0);
     179    attr_col = data->shader->GetAttribLocation("in_Color", VertexUsage::Color, 0);
    175180
    176181    data->shader->Bind();
     
    183188    data->shader->SetUniform(uni_mat, model_matrix);
    184189
    185     float const vertex[] = {   0.0f,   0.0f, 0.0f,
    186                              640.0f,   0.0f, 0.0f,
    187                                0.0f, 480.0f, 0.0f,
    188                                0.0f, 480.0f, 0.0f,
    189                              640.0f, 480.0f, 0.0f,
    190                              640.0f,   0.0f, 0.0f, };
    191 
    192     float const color[] = { 0.73f, 0.85f, 0.85f, 1.0f,
    193                             0.73f, 0.85f, 0.85f, 1.0f,
    194                             0.0f, 0.0f, 1.0f, 1.0f,
    195                             0.0f, 0.0f, 1.0f, 1.0f,
    196                             0.0f, 0.0f, 1.0f, 1.0f,
    197                             0.73f, 0.85f, 0.85f, 1.0f, };
    198 
    199190    data->shader->Bind();
    200 
    201     /* Bind vertex, color and texture coordinate buffers */
    202 #if !defined __CELLOS_LV2__
    203 #   if defined HAVE_GL_2X && !defined __APPLE__
    204     glBindVertexArray(data->vaos[0]);
    205 #   endif
    206     glEnableVertexAttribArray(attr_pos);
    207     glEnableVertexAttribArray(attr_col);
    208 
    209     glBindBuffer(GL_ARRAY_BUFFER, data->bufs[0]);
    210     glBufferData(GL_ARRAY_BUFFER, 18 * sizeof(GLfloat),
    211                  vertex, GL_DYNAMIC_DRAW);
    212     glVertexAttribPointer(attr_pos, 3, GL_FLOAT, GL_FALSE, 0, 0);
    213 
    214     glBindBuffer(GL_ARRAY_BUFFER, data->bufs[1]);
    215     glBufferData(GL_ARRAY_BUFFER, 24 * sizeof(GLfloat),
    216                  color, GL_DYNAMIC_DRAW);
    217     glVertexAttribPointer(attr_col, 4, GL_FLOAT, GL_FALSE, 0, 0);
    218 #else
    219     glEnableClientState(GL_VERTEX_ARRAY);
    220     glEnableClientState(GL_COLOR_ARRAY);
    221 
    222     glVertexPointer(3, GL_FLOAT, 0, vertex);
    223     glColorPointer(4, GL_FLOAT, 0, color);
    224 #endif
     191    data->m_vdecl->Bind();
     192
     193    void *tmp = data->m_vbo->Lock(0, 0);
     194    memcpy(tmp, vertex, sizeof(vertex));
     195    data->m_vbo->Unlock();
     196
     197    tmp = data->m_cbo->Lock(0, 0);
     198    memcpy(tmp, color, sizeof(color));
     199    data->m_cbo->Unlock();
     200
     201    /* Bind vertex and color buffers */
     202    data->m_vdecl->SetStream(data->m_vbo, attr_pos);
     203    data->m_vdecl->SetStream(data->m_cbo, attr_col);
    225204
    226205    /* Draw arrays */
    227206    glDrawArrays(GL_TRIANGLES, 0, 6);
    228 
    229 #if !defined __CELLOS_LV2__
    230 #   if defined HAVE_GL_2X && !defined __APPLE__
    231     glBindVertexArray(0);
    232 #   endif
    233     glDisableVertexAttribArray(attr_pos);
    234     glDisableVertexAttribArray(attr_col);
    235 #else
    236     glDisableClientState(GL_VERTEX_ARRAY);
    237     glDisableClientState(GL_COLOR_ARRAY);
    238 #endif
    239 #endif
    240207}
    241208
  • trunk/src/scene.cpp

    r1222 r1228  
    7272    float angle;
    7373
    74 #if defined USE_D3D9
    75     IDirect3DVertexDeclaration9 *m_vdecl;
    76     IDirect3DVertexBuffer9 **bufs;
    77 #elif defined _XBOX
    78     D3DVertexDeclaration *m_vdecl;
    79     D3DVertexBuffer **bufs;
    80 #else
    81 #   if defined HAVE_GL_2X && !defined __APPLE__
    82     GLuint vao;
    83 #   endif
    84     GLuint *bufs;
    85 #endif
     74    VertexDeclaration *m_vdecl;
     75    VertexBuffer **bufs;
    8676    int nbufs;
    8777
     
    10595    data->nbufs = 0;
    10696
    107 #if defined _XBOX || defined USE_D3D9
    108     D3DVERTEXELEMENT9 const elements[] =
    109     {
    110         { 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
    111         { 1, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
    112         D3DDECL_END()
    113     };
    114     g_d3ddevice->CreateVertexDeclaration(elements, &data->m_vdecl);
    115 #else
    116 #   if defined HAVE_GL_2X && !defined __APPLE__
    117     glGenVertexArrays(1, &data->vao);
    118 #   endif
    119 #endif
     97    data->m_vdecl = new VertexDeclaration(VertexStream<vec3>(VertexUsage::Position),
     98                                          VertexStream<vec2>(VertexUsage::TexCoord));
    12099}
    121100
     
    128107     * Change the code architecture to make sure of that. */
    129108    /* XXX: The test is necessary because of a crash with PSGL. */
    130     if (data->nbufs > 0)
    131         glDeleteBuffers(data->nbufs, data->bufs);
    132 #   if defined HAVE_GL_2X && !defined __APPLE__
    133     glDeleteVertexArrays(1, &data->vao);
    134 #   endif
     109    for (int i = 0; i < data->nbufs; i++)
     110        delete data->bufs[i];
    135111    free(data->bufs);
    136112#endif
     
    338314
    339315    ShaderUniform uni_mat, uni_tex;
    340 #if defined USE_D3D9 || defined _XBOX
    341     /* Nothing? */
    342 #elif !defined __CELLOS_LV2__
    343     int attr_pos, attr_tex;
    344     attr_pos = stdshader->GetAttribLocation("in_Position");
    345     attr_tex = stdshader->GetAttribLocation("in_TexCoord");
    346 #endif
     316    ShaderAttrib attr_pos, attr_tex;
     317    attr_pos = stdshader->GetAttribLocation("in_Position", VertexUsage::Position, 0);
     318    attr_tex = stdshader->GetAttribLocation("in_TexCoord", VertexUsage::TexCoord, 0);
    347319
    348320    stdshader->Bind();
     
    355327    stdshader->SetUniform(uni_mat, data->model_matrix);
    356328
     329    data->m_vdecl->Bind();
    357330#if defined USE_D3D9 || defined _XBOX
    358331    //g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
    359332    g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
    360     g_d3ddevice->SetVertexDeclaration(data->m_vdecl);
    361333#else
    362334    uni_tex = stdshader->GetUniformLocation("in_Texture");
     
    381353        if (buf + 2 > data->nbufs)
    382354        {
    383 #if defined USE_D3D9
    384             data->bufs = (IDirect3DVertexBuffer9 **)realloc(data->bufs, (buf + 2) * sizeof(IDirect3DVertexBuffer9 *));
    385 #elif defined _XBOX
    386             data->bufs = (D3DVertexBuffer **)realloc(data->bufs, (buf + 2) * sizeof(D3DVertexBuffer *));
    387 #else
    388             data->bufs = (uint32_t *)realloc(data->bufs, (buf + 2) * sizeof(uint32_t));
    389             glGenBuffers(buf + 2 - data->nbufs, data->bufs + data->nbufs);
    390 #endif
     355            data->bufs = (VertexBuffer **)realloc(data->bufs, (buf + 2) * sizeof(VertexBuffer *));
    391356            data->nbufs = buf + 2;
    392357        }
    393 #if defined USE_D3D9 || defined _XBOX
    394358        else
    395359        {
    396             data->bufs[buf]->Release();
    397             data->bufs[buf + 1]->Release();
     360            delete data->bufs[buf];
     361            delete data->bufs[buf + 1];
    398362        }
    399 #endif
    400363
    401364        /* Count how many quads will be needed */
     
    405368
    406369        /* Create a vertex array object */
    407         float *vertex, *texture;
    408 #if defined USE_D3D9 || defined _XBOX
    409         if (FAILED(g_d3ddevice->CreateVertexBuffer(6 * 3 * (n - i) * sizeof(float), D3DUSAGE_WRITEONLY, NULL, D3DPOOL_MANAGED, &data->bufs[buf], NULL)))
    410             exit(0);
    411         if (FAILED(data->bufs[buf]->Lock(0, 0, (void **)&vertex, 0)))
    412             exit(0);
    413         if (FAILED(g_d3ddevice->CreateVertexBuffer(6 * 2 * (n - i) * sizeof(float), D3DUSAGE_WRITEONLY, NULL, D3DPOOL_MANAGED, &data->bufs[buf + 1], NULL)))
    414             exit(0);
    415         if (FAILED(data->bufs[buf + 1]->Lock(0, 0, (void **)&texture, 0)))
    416             exit(0);
    417 #else
    418         vertex = (float *)malloc(6 * 3 * (n - i) * sizeof(float));
    419         texture = (float *)malloc(6 * 2 * (n - i) * sizeof(float));
    420 #endif
     370        data->bufs[buf] = new VertexBuffer(6 * 3 * (n - i) * sizeof(float));
     371        float *vertex = (float *)data->bufs[buf]->Lock(0, 0);
     372        data->bufs[buf + 1] = new VertexBuffer(6 * 2 * (n - i) * sizeof(float));
     373        float *texture = (float *)data->bufs[buf + 1]->Lock(0, 0);
    421374
    422375        for (int j = i; j < n; j++)
     
    428381        }
    429382
    430 #if defined USE_D3D9 || defined _XBOX
    431         data->bufs[buf]->Unlock();
    432         data->bufs[buf + 1]->Unlock();
    433 #endif
    434 
    435383        stdshader->Bind();
    436384
     
    438386        data->tiles[i].tileset->Bind();
    439387
    440         /* Bind vertex, color and texture coordinate buffers */
     388        /* Bind vertex and texture coordinate buffers */
     389        data->m_vdecl->SetStream(data->bufs[buf], attr_pos);
     390        data->m_vdecl->SetStream(data->bufs[buf + 1], attr_tex);
     391
     392        /* Draw arrays */
    441393#if defined USE_D3D9 || defined _XBOX
    442         g_d3ddevice->SetStreamSource(0, data->bufs[data->nbufs - 2], 0, 6 * 3 * (n - i) * sizeof(float));
    443         g_d3ddevice->SetStreamSource(1, data->bufs[data->nbufs - 1], 0, 6 * 2 * (n - i) * sizeof(float));
    444394        g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, (n - i) * 6);
    445395#else
    446 #   if defined HAVE_GL_2X && !defined __APPLE__
    447         glBindVertexArray(data->vao);
    448 #   endif
    449 #   if !defined __CELLOS_LV2__ // Use cgGLEnableClientState etc.
    450         glEnableVertexAttribArray(attr_pos);
    451         glEnableVertexAttribArray(attr_tex);
    452 
    453         glBindBuffer(GL_ARRAY_BUFFER, data->bufs[buf]);
    454         glBufferData(GL_ARRAY_BUFFER, 18 * (n - i) * sizeof(GLfloat),
    455                      vertex, GL_STATIC_DRAW);
    456         glVertexAttribPointer(attr_pos, 3, GL_FLOAT, GL_FALSE, 0, 0);
    457 
    458         glBindBuffer(GL_ARRAY_BUFFER, data->bufs[buf + 1]);
    459         glBufferData(GL_ARRAY_BUFFER, 12 * (n - i) * sizeof(GLfloat),
    460                      texture, GL_STATIC_DRAW);
    461         glVertexAttribPointer(attr_tex, 2, GL_FLOAT, GL_FALSE, 0, 0);
    462 #   else
    463         glEnableClientState(GL_VERTEX_ARRAY);
    464         glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    465 
    466         glVertexPointer(3, GL_FLOAT, 0, vertex);
    467         glTexCoordPointer(2, GL_FLOAT, 0, texture);
    468 #   endif
    469 
    470         /* Draw arrays */
    471396        glDrawArrays(GL_TRIANGLES, 0, (n - i) * 6);
    472397
     
    475400#   endif
    476401#   if !defined __CELLOS_LV2__ // Use cgGLEnableClientState etc.
    477         glDisableVertexAttribArray(attr_pos);
    478         glDisableVertexAttribArray(attr_tex);
    479402#   else
    480403        glDisableClientState(GL_VERTEX_ARRAY);
    481404        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    482405#   endif
    483 
    484         free(vertex);
    485         free(texture);
    486406#endif
    487407    }
  • trunk/test/debug/quad.cpp

    r1040 r1228  
    3434    /* Register some debug stuff */
    3535    new DebugFps(5, 5);
    36     new DebugQuad();
     36    //new DebugQuad();
    3737
    3838    app.Run();
  • trunk/test/tutorial/tut01.cpp

    r1227 r1228  
    127127#endif
    128128
     129        m_vdecl->Unbind();
    129130#if defined _XBOX || defined USE_D3D9
    130131        /* FIXME: do we need to unset anything here? */
    131132#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__
    132         glDisableVertexAttribArray(m_attrib);
    133         glBindBuffer(GL_ARRAY_BUFFER, 0);
     133        //glDisableVertexAttribArray(m_attrib);
     134        //glBindBuffer(GL_ARRAY_BUFFER, 0);
    134135#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__
    135136        /* Never used for now */
  • trunk/test/tutorial/tut02.cpp

    r1227 r1228  
    192192        g_d3ddevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 0, 0, sizeof(m_indices) / sizeof(*m_indices));
    193193#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__
    194         glEnableVertexAttribArray(m_coord);
    195         glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
    196         glVertexAttribPointer(m_coord, 3, GL_FLOAT, GL_FALSE, 0, 0);
    197 
    198         glEnableVertexAttribArray(m_color);
    199         glBindBuffer(GL_ARRAY_BUFFER, m_cbo);
    200         glVertexAttribPointer(m_color, 3, GL_FLOAT, GL_FALSE, 0, 0);
    201 
    202194        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ibo);
    203195        int size;
     
    207199        glDrawElements(GL_TRIANGLES, size / sizeof(uint16_t), GL_UNSIGNED_SHORT, 0);
    208200
    209         glDisableVertexAttribArray(m_coord);
    210         glDisableVertexAttribArray(m_color);
    211201        glBindBuffer(GL_ARRAY_BUFFER, 0);
    212202#else
  • trunk/test/tutorial/tut03.cpp

    r1226 r1228  
    428428    virtual void TickDraw(float deltams)
    429429    {
     430Log::Error("Tick Fractal\n");
    430431        WorldEntity::TickDraw(deltams);
    431432
     
    667668#endif
    668669            );
    669 #if !defined _XBOX && !defined USE_D3D9
    670             m_vertexattrib = m_shader->GetAttribLocation("a_Vertex");
    671             m_texattrib = m_shader->GetAttribLocation("a_TexCoord");
    672 #endif
     670            m_vertexattrib = m_shader->GetAttribLocation("a_Vertex", VertexUsage::Position, 0);
     671            m_texattrib = m_shader->GetAttribLocation("a_TexCoord", VertexUsage::TexCoord, 0);
    673672            m_texeluni = m_shader->GetUniformLocation("u_TexelSize");
    674673            m_screenuni = m_shader->GetUniformLocation("u_ScreenSize");
    675674            m_zoomuni = m_shader->GetUniformLocation("u_ZoomSettings");
    676             m_ready = true;
    677675
    678676            m_vdecl =
    679677              new VertexDeclaration(VertexStream<vec2>(VertexUsage::Position),
    680678                                    VertexStream<vec2>(VertexUsage::TexCoord));
    681 #if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined _XBOX && !defined USE_D3D9
    682             /* Method 1: store vertex buffer on the GPU memory */
    683             glGenBuffers(1, &m_vbo);
    684             glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
    685             glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices,
    686                          GL_STATIC_DRAW);
    687             glGenBuffers(1, &m_tbo);
    688             glBindBuffer(GL_ARRAY_BUFFER, m_tbo);
    689             glBufferData(GL_ARRAY_BUFFER, sizeof(texcoords), texcoords,
    690                          GL_STATIC_DRAW);
    691 #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined _XBOX && !defined USE_D3D9
    692             /* Method 2: upload vertex information at each frame */
    693 #elif defined _XBOX || defined USE_D3D9
    694             if (FAILED(g_d3ddevice->CreateVertexBuffer(sizeof(vertices), D3DUSAGE_WRITEONLY, NULL, D3DPOOL_MANAGED, &m_vbo, NULL)))
    695                 exit(0);
    696             vec2 *tmp1;
    697             if (FAILED(m_vbo->Lock(0, 0, (void **)&tmp1, 0)))
    698                 exit(0);
    699             memcpy(tmp1, vertices, sizeof(vertices));
     679            m_vbo = new VertexBuffer(sizeof(vertices));
     680            m_tbo = new VertexBuffer(sizeof(texcoords));
     681
     682            void *tmp = m_vbo->Lock(0, 0);
     683            memcpy(tmp, vertices, sizeof(vertices));
    700684            m_vbo->Unlock();
    701685
    702             if (FAILED(g_d3ddevice->CreateVertexBuffer(sizeof(texcoords), D3DUSAGE_WRITEONLY, NULL, D3DPOOL_MANAGED, &m_tbo, NULL)))
    703                 exit(0);
    704             vec2 *tmp2;
    705             if (FAILED(m_tbo->Lock(0, 0, (void **)&tmp2, 0)))
    706                 exit(0);
    707             memcpy(tmp2, texcoords, sizeof(texcoords));
     686            tmp = m_tbo->Lock(0, 0);
     687            memcpy(tmp, texcoords, sizeof(texcoords));
    708688            m_tbo->Unlock();
    709 #else
    710 #endif
    711689
    712690            /* FIXME: this object never cleans up */
     691            m_ready = true;
    713692        }
    714693
     
    763742        m_shader->SetUniform(m_zoomuni, m_zoom_settings);
    764743        m_vdecl->Bind();
     744        m_vdecl->SetStream(m_vbo, m_vertexattrib);
     745        m_vdecl->SetStream(m_tbo, m_texattrib);
    765746#if defined _XBOX || defined USE_D3D9
    766747        g_d3ddevice->SetTexture(0, m_tex);
    767748        //g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
    768749        g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
    769         g_d3ddevice->SetStreamSource(0, m_vbo, 0, sizeof(*vertices));
    770         g_d3ddevice->SetStreamSource(1, m_tbo, 0, sizeof(*texcoords));
    771750#elif !defined __CELLOS_LV2__ && !defined __ANDROID__
    772         glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
    773         glEnableVertexAttribArray(m_vertexattrib);
    774         glVertexAttribPointer(m_vertexattrib, 2, GL_FLOAT, GL_FALSE, 0, 0);
    775 
    776         glBindBuffer(GL_ARRAY_BUFFER, m_tbo);
    777         glEnableVertexAttribArray(m_texattrib);
    778         glVertexAttribPointer(m_texattrib, 2, GL_FLOAT, GL_FALSE, 0, 0);
    779 #elif !defined __CELLOS_LV2__ && !defined __ANDROID__
    780         /* Never used for now */
    781         //glEnableVertexAttribArray(m_vertexattrib);
    782         //glVertexAttribPointer(m_vertexattrib, 2, GL_FLOAT, GL_FALSE, 0, vertices);
    783 #else
    784         glEnableClientState(GL_VERTEX_ARRAY);
    785         glVertexPointer(2, GL_FLOAT, 0, vertices);
    786         glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    787         glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
     751#else
     752        //glEnableClientState(GL_VERTEX_ARRAY);
     753        //glVertexPointer(2, GL_FLOAT, 0, vertices);
     754        //glEnableClientState(GL_TEXTURE_COORD_ARRAY);
     755        //glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
    788756#endif
    789757
     
    797765#if defined _XBOX || defined USE_D3D9
    798766
     767        m_vdecl->Unbind();
    799768#elif !defined __CELLOS_LV2__ && !defined __ANDROID__
    800         glDisableVertexAttribArray(m_vertexattrib);
    801         glDisableVertexAttribArray(m_texattrib);
    802         glBindBuffer(GL_ARRAY_BUFFER, 0);
     769        //glDisableVertexAttribArray(m_vertexattrib);
     770        //glDisableVertexAttribArray(m_texattrib);
     771        //glBindBuffer(GL_ARRAY_BUFFER, 0);
    803772#elif !defined __CELLOS_LV2__ && !defined __ANDROID__
    804773        /* Never used for now */
     
    806775        //glDisableVertexAttribArray(m_texattrib);
    807776#else
    808         glDisableClientState(GL_VERTEX_ARRAY);
    809         glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    810 #endif
     777        //glDisableClientState(GL_VERTEX_ARRAY);
     778        //glDisableClientState(GL_TEXTURE_COORD_ARRAY);
     779#endif
     780Log::Error("~Tick Fractal\n");
    811781    }
    812782
     
    821791    f64vec2 m_texel2world;
    822792    u8vec4 *m_pixels, *m_tmppixels, *m_palette;
     793
    823794    Shader *m_shader;
     795    ShaderAttrib m_vertexattrib, m_texattrib;
     796    ShaderUniform m_texeluni, m_screenuni, m_zoomuni;
     797
    824798    VertexDeclaration *m_vdecl;
     799    VertexBuffer *m_vbo, *m_tbo;
    825800#if defined USE_D3D9
    826801    IDirect3DTexture9 *m_tex;
    827     IDirect3DVertexBuffer9 *m_vbo, *m_tbo;
    828802#elif defined _XBOX
    829803    D3DTexture *m_tex;
    830     D3DVertexBuffer *m_vbo, *m_tbo;
    831804#else
    832805    GLuint m_texid;
    833 #   if !defined __CELLOS_LV2__ && !defined __ANDROID__
    834     GLuint m_vbo, m_tbo;
    835     GLuint m_tco;
    836 #   endif
    837 #endif
    838     int m_vertexattrib, m_texattrib;
    839     ShaderUniform m_texeluni, m_screenuni, m_zoomuni;
     806#endif
    840807    int m_frame, m_slices, m_dirty[4];
    841808    bool m_ready, m_drag;
Note: See TracChangeset for help on using the changeset viewer.