OESVertexArrayObject.cpp [plain text]
#include "config.h"
#include "OESVertexArrayObject.h"
#if ENABLE(WEBGL)
#include "ExtensionsGL.h"
#include "WebGLRenderingContext.h"
#include <wtf/IsoMallocInlines.h>
#include <wtf/Lock.h>
#include <wtf/Locker.h>
namespace WebCore {
WTF_MAKE_ISO_ALLOCATED_IMPL(OESVertexArrayObject);
OESVertexArrayObject::OESVertexArrayObject(WebGLRenderingContextBase& context)
: WebGLExtension(context)
{
}
WebGLExtension::ExtensionName OESVertexArrayObject::getName() const
{
return OESVertexArrayObjectName;
}
RefPtr<WebGLVertexArrayObjectOES> OESVertexArrayObject::createVertexArrayOES()
{
if (!m_context || m_context->isContextLost())
return nullptr;
auto object = WebGLVertexArrayObjectOES::create(*m_context, WebGLVertexArrayObjectOES::Type::User);
m_context->addContextObject(object.get());
return object;
}
void OESVertexArrayObject::deleteVertexArrayOES(WebGLVertexArrayObjectOES* arrayObject)
{
if (!m_context)
return;
auto locker = holdLock(m_context->objectGraphLock());
if (!arrayObject || m_context->isContextLost())
return;
if (!arrayObject->isDefaultObject() && arrayObject == static_cast<WebGLRenderingContext*>(m_context)->m_boundVertexArrayObject)
static_cast<WebGLRenderingContext*>(m_context)->setBoundVertexArrayObject(locker, nullptr);
arrayObject->deleteObject(locker, m_context->graphicsContextGL());
}
GCGLboolean OESVertexArrayObject::isVertexArrayOES(WebGLVertexArrayObjectOES* arrayObject)
{
if (!m_context)
return false;
return arrayObject && !m_context->isContextLost() && arrayObject->hasEverBeenBound()
&& m_context->graphicsContextGL()->getExtensions().isVertexArrayOES(arrayObject->object());
}
void OESVertexArrayObject::bindVertexArrayOES(WebGLVertexArrayObjectOES* arrayObject)
{
if (!m_context)
return;
auto locker = holdLock(m_context->objectGraphLock());
if (m_context->isContextLost())
return;
if (arrayObject && (arrayObject->isDeleted() || !arrayObject->validate(nullptr, *context()))) {
m_context->graphicsContextGL()->synthesizeGLError(GraphicsContextGL::INVALID_OPERATION);
return;
}
auto& extensions = m_context->graphicsContextGL()->getExtensions();
auto& context = downcast<WebGLRenderingContext>(*m_context);
if (arrayObject && !arrayObject->isDefaultObject() && arrayObject->object()) {
extensions.bindVertexArrayOES(arrayObject->object());
arrayObject->setHasEverBeenBound();
context.setBoundVertexArrayObject(locker, arrayObject);
} else {
extensions.bindVertexArrayOES(0);
context.setBoundVertexArrayObject(locker, nullptr);
}
}
}
#endif // ENABLE(WEBGL)