Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "WebGLContext.h" |
michael@0 | 7 | #include "WebGLBuffer.h" |
michael@0 | 8 | #include "WebGLVertexAttribData.h" |
michael@0 | 9 | #include "WebGLVertexArray.h" |
michael@0 | 10 | #include "GLContext.h" |
michael@0 | 11 | |
michael@0 | 12 | using namespace mozilla; |
michael@0 | 13 | |
michael@0 | 14 | void |
michael@0 | 15 | WebGLContext::BindVertexArray(WebGLVertexArray *array) |
michael@0 | 16 | { |
michael@0 | 17 | if (IsContextLost()) |
michael@0 | 18 | return; |
michael@0 | 19 | |
michael@0 | 20 | if (!ValidateObjectAllowDeletedOrNull("bindVertexArrayObject", array)) |
michael@0 | 21 | return; |
michael@0 | 22 | |
michael@0 | 23 | if (array && array->IsDeleted()) { |
michael@0 | 24 | /* http://www.khronos.org/registry/gles/extensions/OES/OES_vertex_array_object.txt |
michael@0 | 25 | * BindVertexArrayOES fails and an INVALID_OPERATION error is |
michael@0 | 26 | * generated if array is not a name returned from a previous call to |
michael@0 | 27 | * GenVertexArraysOES, or if such a name has since been deleted with |
michael@0 | 28 | * DeleteVertexArraysOES |
michael@0 | 29 | */ |
michael@0 | 30 | ErrorInvalidOperation("bindVertexArray: can't bind a deleted array!"); |
michael@0 | 31 | return; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | InvalidateBufferFetching(); |
michael@0 | 35 | |
michael@0 | 36 | MakeContextCurrent(); |
michael@0 | 37 | |
michael@0 | 38 | if (array) { |
michael@0 | 39 | gl->fBindVertexArray(array->GLName()); |
michael@0 | 40 | array->SetHasEverBeenBound(true); |
michael@0 | 41 | mBoundVertexArray = array; |
michael@0 | 42 | } |
michael@0 | 43 | else { |
michael@0 | 44 | gl->fBindVertexArray(0); |
michael@0 | 45 | mBoundVertexArray = mDefaultVertexArray; |
michael@0 | 46 | } |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | already_AddRefed<WebGLVertexArray> |
michael@0 | 50 | WebGLContext::CreateVertexArray() |
michael@0 | 51 | { |
michael@0 | 52 | if (IsContextLost()) |
michael@0 | 53 | return nullptr; |
michael@0 | 54 | |
michael@0 | 55 | nsRefPtr<WebGLVertexArray> globj = new WebGLVertexArray(this); |
michael@0 | 56 | |
michael@0 | 57 | MakeContextCurrent(); |
michael@0 | 58 | gl->fGenVertexArrays(1, &globj->mGLName); |
michael@0 | 59 | |
michael@0 | 60 | mVertexArrays.insertBack(globj); |
michael@0 | 61 | |
michael@0 | 62 | return globj.forget(); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | void |
michael@0 | 66 | WebGLContext::DeleteVertexArray(WebGLVertexArray *array) |
michael@0 | 67 | { |
michael@0 | 68 | if (IsContextLost()) |
michael@0 | 69 | return; |
michael@0 | 70 | |
michael@0 | 71 | if (array == nullptr) |
michael@0 | 72 | return; |
michael@0 | 73 | |
michael@0 | 74 | if (array->IsDeleted()) |
michael@0 | 75 | return; |
michael@0 | 76 | |
michael@0 | 77 | if (mBoundVertexArray == array) |
michael@0 | 78 | BindVertexArray(static_cast<WebGLVertexArray*>(nullptr)); |
michael@0 | 79 | |
michael@0 | 80 | array->RequestDelete(); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | bool |
michael@0 | 84 | WebGLContext::IsVertexArray(WebGLVertexArray *array) |
michael@0 | 85 | { |
michael@0 | 86 | if (IsContextLost()) |
michael@0 | 87 | return false; |
michael@0 | 88 | |
michael@0 | 89 | if (!array) |
michael@0 | 90 | return false; |
michael@0 | 91 | |
michael@0 | 92 | return ValidateObjectAllowDeleted("isVertexArray", array) && |
michael@0 | 93 | !array->IsDeleted() && |
michael@0 | 94 | array->HasEverBeenBound(); |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 |