WebGLShaderValidator.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. #ifndef WEBGL_SHADER_VALIDATOR_H_
  6. #define WEBGL_SHADER_VALIDATOR_H_
  7. #include "angle/ShaderLang.h"
  8. #include "GLDefs.h"
  9. #include "nsString.h"
  10. #include <string>
  11. namespace mozilla {
  12. namespace webgl {
  13. class ShaderValidator final
  14. {
  15. const ShHandle mHandle;
  16. const int mCompileOptions;
  17. const int mMaxVaryingVectors;
  18. bool mHasRun;
  19. public:
  20. static ShaderValidator* Create(GLenum shaderType, ShShaderSpec spec,
  21. ShShaderOutput outputLanguage,
  22. const ShBuiltInResources& resources,
  23. int compileOptions);
  24. private:
  25. ShaderValidator(ShHandle handle, int compileOptions,
  26. int maxVaryingVectors)
  27. : mHandle(handle)
  28. , mCompileOptions(compileOptions)
  29. , mMaxVaryingVectors(maxVaryingVectors)
  30. , mHasRun(false)
  31. { }
  32. public:
  33. ~ShaderValidator();
  34. bool ValidateAndTranslate(const char* source);
  35. void GetInfoLog(nsACString* out) const;
  36. void GetOutput(nsACString* out) const;
  37. bool CanLinkTo(const ShaderValidator* prev, nsCString* const out_log) const;
  38. size_t CalcNumSamplerUniforms() const;
  39. size_t NumAttributes() const;
  40. bool FindAttribUserNameByMappedName(const std::string& mappedName,
  41. const std::string** const out_userName) const;
  42. bool FindAttribMappedNameByUserName(const std::string& userName,
  43. const std::string** const out_mappedName) const;
  44. bool FindVaryingMappedNameByUserName(const std::string& userName,
  45. const std::string** const out_mappedName) const;
  46. bool FindVaryingByMappedName(const std::string& mappedName,
  47. std::string* const out_userName,
  48. bool* const out_isArray) const;
  49. bool FindUniformByMappedName(const std::string& mappedName,
  50. std::string* const out_userName,
  51. bool* const out_isArray) const;
  52. bool UnmapUniformBlockName(const nsACString& baseMappedName,
  53. nsCString* const out_baseUserName) const;
  54. void EnumerateFragOutputs(std::map<nsCString, const nsCString> &out_FragOutputs) const;
  55. bool ValidateTransformFeedback(const std::vector<nsString>& userNames,
  56. uint32_t maxComponents, nsCString* const out_errorText,
  57. std::vector<std::string>* const out_mappedNames);
  58. };
  59. } // namespace webgl
  60. } // namespace mozilla
  61. #endif // WEBGL_SHADER_VALIDATOR_H_