gfx/gl/VBOArena.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/gl/VBOArena.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,37 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "VBOArena.h"
    1.10 +#include "GLContext.h"
    1.11 +
    1.12 +using namespace mozilla::gl;
    1.13 +
    1.14 +GLuint VBOArena::Allocate(GLContext *aGLContext)
    1.15 +{
    1.16 +    if (!mAvailableVBOs.size()) {
    1.17 +        GLuint vbo;
    1.18 +        aGLContext->fGenBuffers(1, &vbo);
    1.19 +        mAllocatedVBOs.push_back(vbo);
    1.20 +        return vbo;
    1.21 +    }
    1.22 +    GLuint vbo = mAvailableVBOs.back();
    1.23 +    mAvailableVBOs.pop_back();
    1.24 +    return vbo;
    1.25 +}
    1.26 +
    1.27 +void VBOArena::Reset()
    1.28 +{
    1.29 +    mAvailableVBOs = mAllocatedVBOs;
    1.30 +}
    1.31 +
    1.32 +void VBOArena::Flush(GLContext *aGLContext)
    1.33 +{
    1.34 +    if (mAvailableVBOs.size()) {
    1.35 +#ifdef DEBUG
    1.36 +        printf_stderr("VBOArena::Flush for %u VBOs\n", mAvailableVBOs.size());
    1.37 +#endif
    1.38 +        aGLContext->fDeleteBuffers(mAvailableVBOs.size(), &mAvailableVBOs[0]);
    1.39 +    }
    1.40 +}

mercurial