Changeset 1228 for trunk/test


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

gpu: port the vertex buffer abstraction layer to OpenGL.

Location:
trunk/test
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • 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.