GrGLExtensions.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright 2013 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef GrGLExtensions_DEFINED
  8. #define GrGLExtensions_DEFINED
  9. #include "../../private/SkTArray.h"
  10. #include "GrGLFunctions.h"
  11. #include "SkString.h"
  12. #include <utility>
  13. struct GrGLInterface;
  14. class SkJSONWriter;
  15. /**
  16. * This helper queries the current GL context for its extensions, remembers them, and can be
  17. * queried. It supports both glGetString- and glGetStringi-style extension string APIs and will
  18. * use the latter if it is available. It also will query for EGL extensions if a eglQueryString
  19. * implementation is provided.
  20. */
  21. class SK_API GrGLExtensions {
  22. public:
  23. GrGLExtensions() {}
  24. GrGLExtensions(const GrGLExtensions&);
  25. GrGLExtensions& operator=(const GrGLExtensions&);
  26. void swap(GrGLExtensions* that) {
  27. using std::swap;
  28. swap(fStrings, that->fStrings);
  29. swap(fInitialized, that->fInitialized);
  30. }
  31. /**
  32. * We sometimes need to use this class without having yet created a GrGLInterface. This version
  33. * of init expects that getString is always non-NULL while getIntegerv and getStringi are non-
  34. * NULL if on desktop GL with version 3.0 or higher. Otherwise it will fail.
  35. */
  36. bool init(GrGLStandard standard,
  37. GrGLFunction<GrGLGetStringFn> getString,
  38. GrGLFunction<GrGLGetStringiFn> getStringi,
  39. GrGLFunction<GrGLGetIntegervFn> getIntegerv,
  40. GrGLFunction<GrEGLQueryStringFn> queryString = nullptr,
  41. GrEGLDisplay eglDisplay = nullptr);
  42. bool isInitialized() const { return fInitialized; }
  43. /**
  44. * Queries whether an extension is present. This will fail if init() has not been called.
  45. */
  46. bool has(const char[]) const;
  47. /**
  48. * Removes an extension if present. Returns true if the extension was present before the call.
  49. */
  50. bool remove(const char[]);
  51. /**
  52. * Adds an extension to list
  53. */
  54. void add(const char[]);
  55. void reset() { fStrings.reset(); }
  56. void dumpJSON(SkJSONWriter*) const;
  57. private:
  58. bool fInitialized = false;
  59. SkTArray<SkString> fStrings;
  60. };
  61. #endif