bsalomon@google.com | 1744f97 | 2013-02-26 21:46:32 +0000 | [diff] [blame] | 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 | |
| 8 | #ifndef GrGLExtensions_DEFINED |
| 9 | #define GrGLExtensions_DEFINED |
| 10 | |
commit-bot@chromium.org | 90313cc | 2014-01-17 15:05:38 +0000 | [diff] [blame] | 11 | #include "GrGLFunctions.h" |
bsalomon@google.com | 1744f97 | 2013-02-26 21:46:32 +0000 | [diff] [blame] | 12 | #include "SkString.h" |
| 13 | #include "SkTArray.h" |
| 14 | |
commit-bot@chromium.org | 90313cc | 2014-01-17 15:05:38 +0000 | [diff] [blame] | 15 | struct GrGLInterface; |
| 16 | |
bsalomon@google.com | 1744f97 | 2013-02-26 21:46:32 +0000 | [diff] [blame] | 17 | /** |
| 18 | * This helper queries the current GL context for its extensions, remembers them, and can be |
| 19 | * queried. It supports both glGetString- and glGetStringi-style extension string APIs and will |
bsalomon | b1a32ad | 2015-11-16 06:48:44 -0800 | [diff] [blame] | 20 | * use the latter if it is available. It also will query for EGL extensions if a eglQueryString |
| 21 | * implementation is provided. |
bsalomon@google.com | 1744f97 | 2013-02-26 21:46:32 +0000 | [diff] [blame] | 22 | */ |
commit-bot@chromium.org | 0714360 | 2014-02-25 02:14:57 +0000 | [diff] [blame] | 23 | class SK_API GrGLExtensions { |
bsalomon@google.com | 1744f97 | 2013-02-26 21:46:32 +0000 | [diff] [blame] | 24 | public: |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 25 | GrGLExtensions() : fInitialized(false), fStrings(new SkTArray<SkString>) {} |
commit-bot@chromium.org | 90313cc | 2014-01-17 15:05:38 +0000 | [diff] [blame] | 26 | |
commit-bot@chromium.org | d8ed851 | 2014-01-24 20:49:44 +0000 | [diff] [blame] | 27 | GrGLExtensions(const GrGLExtensions&); |
| 28 | |
| 29 | GrGLExtensions& operator=(const GrGLExtensions&); |
| 30 | |
commit-bot@chromium.org | 90313cc | 2014-01-17 15:05:38 +0000 | [diff] [blame] | 31 | void swap(GrGLExtensions* that) { |
bungeman | a3434d8 | 2015-09-07 12:45:52 -0700 | [diff] [blame] | 32 | fStrings.swap(that->fStrings); |
commit-bot@chromium.org | d8ed851 | 2014-01-24 20:49:44 +0000 | [diff] [blame] | 33 | SkTSwap(fInitialized, that->fInitialized); |
bsalomon@google.com | 1744f97 | 2013-02-26 21:46:32 +0000 | [diff] [blame] | 34 | } |
commit-bot@chromium.org | 90313cc | 2014-01-17 15:05:38 +0000 | [diff] [blame] | 35 | |
bsalomon@google.com | 1744f97 | 2013-02-26 21:46:32 +0000 | [diff] [blame] | 36 | /** |
| 37 | * We sometimes need to use this class without having yet created a GrGLInterface. This version |
| 38 | * of init expects that getString is always non-NULL while getIntegerv and getStringi are non- |
| 39 | * NULL if on desktop GL with version 3.0 or higher. Otherwise it will fail. |
| 40 | */ |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 41 | bool init(GrGLStandard standard, |
bsalomon | 9f2dc27 | 2016-02-08 07:22:17 -0800 | [diff] [blame] | 42 | GrGLFunction<GrGLGetStringProc> getString, |
| 43 | GrGLFunction<GrGLGetStringiProc> getStringi, |
| 44 | GrGLFunction<GrGLGetIntegervProc> getIntegerv, |
| 45 | GrGLFunction<GrEGLQueryStringProc> queryString = nullptr, |
bsalomon | a779ef1 | 2015-11-16 08:28:21 -0800 | [diff] [blame] | 46 | GrEGLDisplay eglDisplay = nullptr); |
skia.committer@gmail.com | 12eea2b | 2013-02-27 07:10:10 +0000 | [diff] [blame] | 47 | |
commit-bot@chromium.org | 90313cc | 2014-01-17 15:05:38 +0000 | [diff] [blame] | 48 | bool isInitialized() const { return fInitialized; } |
| 49 | |
bsalomon@google.com | 1744f97 | 2013-02-26 21:46:32 +0000 | [diff] [blame] | 50 | /** |
| 51 | * Queries whether an extension is present. This will fail if init() has not been called. |
| 52 | */ |
commit-bot@chromium.org | d8ed851 | 2014-01-24 20:49:44 +0000 | [diff] [blame] | 53 | bool has(const char[]) const; |
| 54 | |
| 55 | /** |
| 56 | * Removes an extension if present. Returns true if the extension was present before the call. |
| 57 | */ |
| 58 | bool remove(const char[]); |
skia.committer@gmail.com | 12eea2b | 2013-02-27 07:10:10 +0000 | [diff] [blame] | 59 | |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 60 | /** |
| 61 | * Adds an extension to list |
| 62 | */ |
| 63 | void add(const char[]); |
| 64 | |
commit-bot@chromium.org | 90313cc | 2014-01-17 15:05:38 +0000 | [diff] [blame] | 65 | void reset() { fStrings->reset(); } |
bsalomon@google.com | 1744f97 | 2013-02-26 21:46:32 +0000 | [diff] [blame] | 66 | |
bsalomon@google.com | 00142c4 | 2013-05-02 19:42:54 +0000 | [diff] [blame] | 67 | void print(const char* sep = "\n") const; |
| 68 | |
bsalomon@google.com | 1744f97 | 2013-02-26 21:46:32 +0000 | [diff] [blame] | 69 | private: |
commit-bot@chromium.org | 90313cc | 2014-01-17 15:05:38 +0000 | [diff] [blame] | 70 | bool fInitialized; |
| 71 | SkAutoTDelete<SkTArray<SkString> > fStrings; |
bsalomon@google.com | 1744f97 | 2013-02-26 21:46:32 +0000 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | #endif |