WebGLExtensionDrawBuffers.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  4. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "WebGLExtensions.h"
  6. #include <algorithm>
  7. #include "GLContext.h"
  8. #include "mozilla/dom/WebGLRenderingContextBinding.h"
  9. #include "WebGLContext.h"
  10. #include "WebGLFramebuffer.h"
  11. #include "WebGLRenderbuffer.h"
  12. #include "WebGLTexture.h"
  13. namespace mozilla {
  14. WebGLExtensionDrawBuffers::WebGLExtensionDrawBuffers(WebGLContext* webgl)
  15. : WebGLExtensionBase(webgl)
  16. {
  17. MOZ_ASSERT(IsSupported(webgl), "Don't construct extension if unsupported.");
  18. // WEBGL_draw_buffers:
  19. // "The value of the MAX_COLOR_ATTACHMENTS_WEBGL parameter must be greater than or
  20. // equal to that of the MAX_DRAW_BUFFERS_WEBGL parameter."
  21. webgl->mImplMaxColorAttachments = webgl->mGLMaxColorAttachments;
  22. webgl->mImplMaxDrawBuffers = std::min(webgl->mGLMaxDrawBuffers,
  23. webgl->mImplMaxColorAttachments);
  24. }
  25. WebGLExtensionDrawBuffers::~WebGLExtensionDrawBuffers()
  26. {
  27. }
  28. void
  29. WebGLExtensionDrawBuffers::DrawBuffersWEBGL(const dom::Sequence<GLenum>& buffers)
  30. {
  31. if (mIsLost) {
  32. if (mContext) {
  33. mContext->ErrorInvalidOperation("drawBuffersWEBGL: Extension is lost.");
  34. }
  35. return;
  36. }
  37. mContext->DrawBuffers(buffers);
  38. }
  39. bool
  40. WebGLExtensionDrawBuffers::IsSupported(const WebGLContext* webgl)
  41. {
  42. gl::GLContext* gl = webgl->GL();
  43. if (!gl->IsExtensionSupported(gl::GLContext::ARB_draw_buffers) &&
  44. !gl->IsExtensionSupported(gl::GLContext::EXT_draw_buffers))
  45. {
  46. return false;
  47. }
  48. // WEBGL_draw_buffers requires at least 4 color attachments.
  49. if (webgl->mGLMaxDrawBuffers < webgl->kMinMaxDrawBuffers ||
  50. webgl->mGLMaxColorAttachments < webgl->kMinMaxColorAttachments)
  51. {
  52. return false;
  53. }
  54. return true;
  55. }
  56. IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionDrawBuffers, WEBGL_draw_buffers)
  57. } // namespace mozilla