2013-07-17 20:13:38 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "WebGLContext.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
#include "GLContext.h"
|
2013-07-17 20:13:38 +04:00
|
|
|
#include "WebGLBuffer.h"
|
|
|
|
#include "WebGLVertexArray.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "WebGLVertexAttribData.h"
|
2013-07-17 20:13:38 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
namespace mozilla {
|
2013-07-17 20:13:38 +04:00
|
|
|
|
|
|
|
void
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLContext::BindVertexArray(WebGLVertexArray* array)
|
2013-07-17 20:13:38 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2013-07-17 20:13:38 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!ValidateObjectAllowDeletedOrNull("bindVertexArrayObject", array))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (array && array->IsDeleted()) {
|
|
|
|
/* http://www.khronos.org/registry/gles/extensions/OES/OES_vertex_array_object.txt
|
|
|
|
* BindVertexArrayOES fails and an INVALID_OPERATION error is
|
|
|
|
* generated if array is not a name returned from a previous call to
|
|
|
|
* GenVertexArraysOES, or if such a name has since been deleted with
|
|
|
|
* DeleteVertexArraysOES
|
|
|
|
*/
|
|
|
|
ErrorInvalidOperation("bindVertexArray: can't bind a deleted array!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-07 04:05:51 +04:00
|
|
|
InvalidateBufferFetching();
|
2013-07-22 22:15:49 +04:00
|
|
|
|
2013-07-17 20:13:38 +04:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
2014-06-11 04:23:50 +04:00
|
|
|
if (array == nullptr) {
|
|
|
|
array = mDefaultVertexArray;
|
2013-07-17 20:13:38 +04:00
|
|
|
}
|
2014-06-06 03:38:27 +04:00
|
|
|
|
2014-06-11 04:23:50 +04:00
|
|
|
array->BindVertexArray();
|
|
|
|
|
|
|
|
MOZ_ASSERT(mBoundVertexArray == array);
|
2013-07-17 20:13:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<WebGLVertexArray>
|
|
|
|
WebGLContext::CreateVertexArray()
|
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2013-07-17 20:13:38 +04:00
|
|
|
return nullptr;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WebGLVertexArray> globj = CreateVertexArrayImpl();
|
2013-07-17 20:13:38 +04:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
2014-06-06 03:38:27 +04:00
|
|
|
globj->GenVertexArray();
|
2013-07-17 20:13:38 +04:00
|
|
|
|
|
|
|
return globj.forget();
|
|
|
|
}
|
|
|
|
|
2015-06-01 09:49:47 +03:00
|
|
|
WebGLVertexArray*
|
|
|
|
WebGLContext::CreateVertexArrayImpl()
|
|
|
|
{
|
|
|
|
return WebGLVertexArray::Create(this);
|
|
|
|
}
|
|
|
|
|
2013-07-17 20:13:38 +04:00
|
|
|
void
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLContext::DeleteVertexArray(WebGLVertexArray* array)
|
2013-07-17 20:13:38 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2013-07-17 20:13:38 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (array == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (array->IsDeleted())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (mBoundVertexArray == array)
|
|
|
|
BindVertexArray(static_cast<WebGLVertexArray*>(nullptr));
|
|
|
|
|
|
|
|
array->RequestDelete();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLContext::IsVertexArray(WebGLVertexArray* array)
|
2013-07-17 20:13:38 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2013-07-17 20:13:38 +04:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!array)
|
|
|
|
return false;
|
|
|
|
|
2015-05-21 02:58:36 +03:00
|
|
|
if (!ValidateObjectAllowDeleted("isVertexArray", array))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (array->IsDeleted())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
return array->IsVertexArray();
|
2013-07-17 20:13:38 +04:00
|
|
|
}
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|