WebGLActiveInfo.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* -*- Mode: C++; tab-width: 20; 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 "WebGLActiveInfo.h"
  6. #include "mozilla/dom/WebGLRenderingContextBinding.h"
  7. namespace mozilla {
  8. static uint8_t
  9. ElemSizeFromType(GLenum elemType)
  10. {
  11. switch (elemType) {
  12. case LOCAL_GL_BOOL:
  13. case LOCAL_GL_FLOAT:
  14. case LOCAL_GL_INT:
  15. case LOCAL_GL_UNSIGNED_INT:
  16. case LOCAL_GL_SAMPLER_2D:
  17. case LOCAL_GL_SAMPLER_3D:
  18. case LOCAL_GL_SAMPLER_CUBE:
  19. case LOCAL_GL_SAMPLER_2D_SHADOW:
  20. case LOCAL_GL_SAMPLER_2D_ARRAY:
  21. case LOCAL_GL_SAMPLER_2D_ARRAY_SHADOW:
  22. case LOCAL_GL_SAMPLER_CUBE_SHADOW:
  23. case LOCAL_GL_INT_SAMPLER_2D:
  24. case LOCAL_GL_INT_SAMPLER_3D:
  25. case LOCAL_GL_INT_SAMPLER_CUBE:
  26. case LOCAL_GL_INT_SAMPLER_2D_ARRAY:
  27. case LOCAL_GL_UNSIGNED_INT_SAMPLER_2D:
  28. case LOCAL_GL_UNSIGNED_INT_SAMPLER_3D:
  29. case LOCAL_GL_UNSIGNED_INT_SAMPLER_CUBE:
  30. case LOCAL_GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
  31. return 1;
  32. case LOCAL_GL_BOOL_VEC2:
  33. case LOCAL_GL_FLOAT_VEC2:
  34. case LOCAL_GL_INT_VEC2:
  35. case LOCAL_GL_UNSIGNED_INT_VEC2:
  36. return 2;
  37. case LOCAL_GL_BOOL_VEC3:
  38. case LOCAL_GL_FLOAT_VEC3:
  39. case LOCAL_GL_INT_VEC3:
  40. case LOCAL_GL_UNSIGNED_INT_VEC3:
  41. return 3;
  42. case LOCAL_GL_BOOL_VEC4:
  43. case LOCAL_GL_FLOAT_VEC4:
  44. case LOCAL_GL_INT_VEC4:
  45. case LOCAL_GL_UNSIGNED_INT_VEC4:
  46. case LOCAL_GL_FLOAT_MAT2:
  47. return 4;
  48. case LOCAL_GL_FLOAT_MAT2x3:
  49. case LOCAL_GL_FLOAT_MAT3x2:
  50. return 6;
  51. case LOCAL_GL_FLOAT_MAT2x4:
  52. case LOCAL_GL_FLOAT_MAT4x2:
  53. return 8;
  54. case LOCAL_GL_FLOAT_MAT3:
  55. return 9;
  56. case LOCAL_GL_FLOAT_MAT3x4:
  57. case LOCAL_GL_FLOAT_MAT4x3:
  58. return 12;
  59. case LOCAL_GL_FLOAT_MAT4:
  60. return 16;
  61. default:
  62. MOZ_CRASH("GFX: Bad `elemType`.");
  63. }
  64. }
  65. ////////////////////
  66. WebGLActiveInfo::WebGLActiveInfo(WebGLContext* webgl, GLint elemCount, GLenum elemType,
  67. bool isArray, const nsACString& baseUserName,
  68. const nsACString& baseMappedName)
  69. : mWebGL(webgl)
  70. , mElemCount(elemCount)
  71. , mElemType(elemType)
  72. , mBaseUserName(baseUserName)
  73. , mIsArray(isArray)
  74. , mElemSize(ElemSizeFromType(elemType))
  75. , mBaseMappedName(baseMappedName)
  76. { }
  77. bool
  78. WebGLActiveInfo::IsSampler() const
  79. {
  80. switch (mElemType) {
  81. case LOCAL_GL_SAMPLER_2D:
  82. case LOCAL_GL_SAMPLER_3D:
  83. case LOCAL_GL_SAMPLER_CUBE:
  84. case LOCAL_GL_SAMPLER_2D_SHADOW:
  85. case LOCAL_GL_SAMPLER_2D_ARRAY:
  86. case LOCAL_GL_SAMPLER_2D_ARRAY_SHADOW:
  87. case LOCAL_GL_SAMPLER_CUBE_SHADOW:
  88. case LOCAL_GL_INT_SAMPLER_2D:
  89. case LOCAL_GL_INT_SAMPLER_3D:
  90. case LOCAL_GL_INT_SAMPLER_CUBE:
  91. case LOCAL_GL_INT_SAMPLER_2D_ARRAY:
  92. case LOCAL_GL_UNSIGNED_INT_SAMPLER_2D:
  93. case LOCAL_GL_UNSIGNED_INT_SAMPLER_3D:
  94. case LOCAL_GL_UNSIGNED_INT_SAMPLER_CUBE:
  95. case LOCAL_GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
  96. return true;
  97. default:
  98. return false;
  99. }
  100. }
  101. ////////////////////////////////////////////////////////////////////////////////
  102. JSObject*
  103. WebGLActiveInfo::WrapObject(JSContext* js, JS::Handle<JSObject*> givenProto)
  104. {
  105. return dom::WebGLActiveInfoBinding::Wrap(js, this, givenProto);
  106. }
  107. NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLActiveInfo)
  108. NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLActiveInfo, AddRef)
  109. NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLActiveInfo, Release)
  110. } // namespace mozilla