content/canvas/src/WebGLContextVertexArray.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/canvas/src/WebGLContextVertexArray.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,97 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; 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 "WebGLContext.h"
    1.10 +#include "WebGLBuffer.h"
    1.11 +#include "WebGLVertexAttribData.h"
    1.12 +#include "WebGLVertexArray.h"
    1.13 +#include "GLContext.h"
    1.14 +
    1.15 +using namespace mozilla;
    1.16 +
    1.17 +void
    1.18 +WebGLContext::BindVertexArray(WebGLVertexArray *array)
    1.19 +{
    1.20 +    if (IsContextLost())
    1.21 +        return;
    1.22 +
    1.23 +    if (!ValidateObjectAllowDeletedOrNull("bindVertexArrayObject", array))
    1.24 +        return;
    1.25 +
    1.26 +    if (array && array->IsDeleted()) {
    1.27 +        /* http://www.khronos.org/registry/gles/extensions/OES/OES_vertex_array_object.txt
    1.28 +         * BindVertexArrayOES fails and an INVALID_OPERATION error is
    1.29 +         * generated if array is not a name returned from a previous call to
    1.30 +         * GenVertexArraysOES, or if such a name has since been deleted with
    1.31 +         * DeleteVertexArraysOES
    1.32 +         */
    1.33 +        ErrorInvalidOperation("bindVertexArray: can't bind a deleted array!");
    1.34 +        return;
    1.35 +    }
    1.36 +
    1.37 +    InvalidateBufferFetching();
    1.38 +
    1.39 +    MakeContextCurrent();
    1.40 +
    1.41 +    if (array) {
    1.42 +        gl->fBindVertexArray(array->GLName());
    1.43 +        array->SetHasEverBeenBound(true);
    1.44 +        mBoundVertexArray = array;
    1.45 +    }
    1.46 +    else {
    1.47 +        gl->fBindVertexArray(0);
    1.48 +        mBoundVertexArray = mDefaultVertexArray;
    1.49 +    }
    1.50 +}
    1.51 +
    1.52 +already_AddRefed<WebGLVertexArray>
    1.53 +WebGLContext::CreateVertexArray()
    1.54 +{
    1.55 +    if (IsContextLost())
    1.56 +        return nullptr;
    1.57 +
    1.58 +    nsRefPtr<WebGLVertexArray> globj = new WebGLVertexArray(this);
    1.59 +
    1.60 +    MakeContextCurrent();
    1.61 +    gl->fGenVertexArrays(1, &globj->mGLName);
    1.62 +
    1.63 +    mVertexArrays.insertBack(globj);
    1.64 +
    1.65 +    return globj.forget();
    1.66 +}
    1.67 +
    1.68 +void
    1.69 +WebGLContext::DeleteVertexArray(WebGLVertexArray *array)
    1.70 +{
    1.71 +    if (IsContextLost())
    1.72 +        return;
    1.73 +
    1.74 +    if (array == nullptr)
    1.75 +        return;
    1.76 +
    1.77 +    if (array->IsDeleted())
    1.78 +        return;
    1.79 +
    1.80 +    if (mBoundVertexArray == array)
    1.81 +        BindVertexArray(static_cast<WebGLVertexArray*>(nullptr));
    1.82 +
    1.83 +    array->RequestDelete();
    1.84 +}
    1.85 +
    1.86 +bool
    1.87 +WebGLContext::IsVertexArray(WebGLVertexArray *array)
    1.88 +{
    1.89 +    if (IsContextLost())
    1.90 +        return false;
    1.91 +
    1.92 +    if (!array)
    1.93 +        return false;
    1.94 +
    1.95 +    return ValidateObjectAllowDeleted("isVertexArray", array) &&
    1.96 +           !array->IsDeleted() &&
    1.97 +           array->HasEverBeenBound();
    1.98 +}
    1.99 +
   1.100 +

mercurial