michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "WebGLContext.h" michael@0: #include "WebGLBuffer.h" michael@0: #include "WebGLVertexAttribData.h" michael@0: #include "WebGLVertexArray.h" michael@0: #include "GLContext.h" michael@0: michael@0: using namespace mozilla; michael@0: michael@0: void michael@0: WebGLContext::BindVertexArray(WebGLVertexArray *array) michael@0: { michael@0: if (IsContextLost()) michael@0: return; michael@0: michael@0: if (!ValidateObjectAllowDeletedOrNull("bindVertexArrayObject", array)) michael@0: return; michael@0: michael@0: if (array && array->IsDeleted()) { michael@0: /* http://www.khronos.org/registry/gles/extensions/OES/OES_vertex_array_object.txt michael@0: * BindVertexArrayOES fails and an INVALID_OPERATION error is michael@0: * generated if array is not a name returned from a previous call to michael@0: * GenVertexArraysOES, or if such a name has since been deleted with michael@0: * DeleteVertexArraysOES michael@0: */ michael@0: ErrorInvalidOperation("bindVertexArray: can't bind a deleted array!"); michael@0: return; michael@0: } michael@0: michael@0: InvalidateBufferFetching(); michael@0: michael@0: MakeContextCurrent(); michael@0: michael@0: if (array) { michael@0: gl->fBindVertexArray(array->GLName()); michael@0: array->SetHasEverBeenBound(true); michael@0: mBoundVertexArray = array; michael@0: } michael@0: else { michael@0: gl->fBindVertexArray(0); michael@0: mBoundVertexArray = mDefaultVertexArray; michael@0: } michael@0: } michael@0: michael@0: already_AddRefed michael@0: WebGLContext::CreateVertexArray() michael@0: { michael@0: if (IsContextLost()) michael@0: return nullptr; michael@0: michael@0: nsRefPtr globj = new WebGLVertexArray(this); michael@0: michael@0: MakeContextCurrent(); michael@0: gl->fGenVertexArrays(1, &globj->mGLName); michael@0: michael@0: mVertexArrays.insertBack(globj); michael@0: michael@0: return globj.forget(); michael@0: } michael@0: michael@0: void michael@0: WebGLContext::DeleteVertexArray(WebGLVertexArray *array) michael@0: { michael@0: if (IsContextLost()) michael@0: return; michael@0: michael@0: if (array == nullptr) michael@0: return; michael@0: michael@0: if (array->IsDeleted()) michael@0: return; michael@0: michael@0: if (mBoundVertexArray == array) michael@0: BindVertexArray(static_cast(nullptr)); michael@0: michael@0: array->RequestDelete(); michael@0: } michael@0: michael@0: bool michael@0: WebGLContext::IsVertexArray(WebGLVertexArray *array) michael@0: { michael@0: if (IsContextLost()) michael@0: return false; michael@0: michael@0: if (!array) michael@0: return false; michael@0: michael@0: return ValidateObjectAllowDeleted("isVertexArray", array) && michael@0: !array->IsDeleted() && michael@0: array->HasEverBeenBound(); michael@0: } michael@0: michael@0: