WebGLContextVertexArray.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "WebGLContext.h"
  6. #include "GLContext.h"
  7. #include "WebGLBuffer.h"
  8. #include "WebGLVertexArray.h"
  9. #include "WebGLVertexAttribData.h"
  10. namespace mozilla {
  11. void
  12. WebGLContext::BindVertexArray(WebGLVertexArray* array)
  13. {
  14. if (IsContextLost())
  15. return;
  16. if (array && !ValidateObject("bindVertexArrayObject", *array))
  17. return;
  18. InvalidateBufferFetching();
  19. MakeContextCurrent();
  20. if (mBoundVertexArray) {
  21. mBoundVertexArray->AddBufferBindCounts(-1);
  22. }
  23. if (array == nullptr) {
  24. array = mDefaultVertexArray;
  25. }
  26. array->BindVertexArray();
  27. MOZ_ASSERT(mBoundVertexArray == array);
  28. if (mBoundVertexArray) {
  29. mBoundVertexArray->AddBufferBindCounts(+1);
  30. }
  31. }
  32. already_AddRefed<WebGLVertexArray>
  33. WebGLContext::CreateVertexArray()
  34. {
  35. if (IsContextLost())
  36. return nullptr;
  37. RefPtr<WebGLVertexArray> globj = CreateVertexArrayImpl();
  38. MakeContextCurrent();
  39. globj->GenVertexArray();
  40. return globj.forget();
  41. }
  42. WebGLVertexArray*
  43. WebGLContext::CreateVertexArrayImpl()
  44. {
  45. return WebGLVertexArray::Create(this);
  46. }
  47. void
  48. WebGLContext::DeleteVertexArray(WebGLVertexArray* array)
  49. {
  50. if (!ValidateDeleteObject("deleteVertexArray", array))
  51. return;
  52. if (mBoundVertexArray == array)
  53. BindVertexArray(static_cast<WebGLVertexArray*>(nullptr));
  54. array->RequestDelete();
  55. }
  56. bool
  57. WebGLContext::IsVertexArray(const WebGLVertexArray* array)
  58. {
  59. if (!ValidateIsObject("isVertexArray", array))
  60. return false;
  61. MakeContextCurrent();
  62. return array->IsVertexArray();
  63. }
  64. } // namespace mozilla