michael@0: /* -*- Mode: C++; tab-width: 20; 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 "WebGLFramebufferAttachable.h" michael@0: #include "WebGLFramebuffer.h" michael@0: #include "WebGLRenderbuffer.h" michael@0: #include "WebGLTexture.h" michael@0: michael@0: using namespace mozilla; michael@0: michael@0: WebGLFramebufferAttachable::AttachmentPoint* michael@0: WebGLFramebufferAttachable::Contains(const WebGLFramebuffer* fb, GLenum attachment) michael@0: { michael@0: AttachmentPoint* first = mAttachmentPoints.begin(); michael@0: AttachmentPoint* last = mAttachmentPoints.end(); michael@0: michael@0: for (; first != last; ++first) { michael@0: if (first->mFB == fb && first->mAttachment == attachment) michael@0: return first; michael@0: } michael@0: michael@0: return nullptr; michael@0: } michael@0: michael@0: void michael@0: WebGLFramebufferAttachable::AttachTo(WebGLFramebuffer* fb, GLenum attachment) michael@0: { michael@0: MOZ_ASSERT(fb); michael@0: if (!fb) michael@0: return; michael@0: michael@0: if (Contains(fb, attachment)) michael@0: return; // Already attached. Ignore. michael@0: michael@0: mAttachmentPoints.append(AttachmentPoint(fb, attachment)); michael@0: } michael@0: michael@0: void michael@0: WebGLFramebufferAttachable::DetachFrom(WebGLFramebuffer* fb, GLenum attachment) michael@0: { michael@0: MOZ_ASSERT(fb); michael@0: if (!fb) michael@0: return; michael@0: michael@0: AttachmentPoint* point = Contains(fb, attachment); michael@0: if (!point) { michael@0: MOZ_ASSERT(false, "Is not attached to FB"); michael@0: return; michael@0: } michael@0: michael@0: mAttachmentPoints.erase(point); michael@0: } michael@0: michael@0: void michael@0: WebGLFramebufferAttachable::NotifyFBsStatusChanged() michael@0: { michael@0: AttachmentPoint* first = mAttachmentPoints.begin(); michael@0: AttachmentPoint* last = mAttachmentPoints.end(); michael@0: for ( ; first != last; ++first) michael@0: first->mFB->NotifyAttachableChanged(); michael@0: }