blob: fe3187057c95b4e145b3d29c2e8a1fe478fac87a [file] [log] [blame]
bsalomon@google.com1744f972013-02-26 21:46:32 +00001/*
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.org90313cc2014-01-17 15:05:38 +000011#include "GrGLFunctions.h"
bsalomon@google.com1744f972013-02-26 21:46:32 +000012#include "SkString.h"
13#include "SkTArray.h"
14
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000015struct GrGLInterface;
16
bsalomon@google.com1744f972013-02-26 21:46:32 +000017/**
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
bsalomonb1a32ad2015-11-16 06:48:44 -080020 * use the latter if it is available. It also will query for EGL extensions if a eglQueryString
21 * implementation is provided.
bsalomon@google.com1744f972013-02-26 21:46:32 +000022 */
commit-bot@chromium.org07143602014-02-25 02:14:57 +000023class SK_API GrGLExtensions {
bsalomon@google.com1744f972013-02-26 21:46:32 +000024public:
halcanary385fe4d2015-08-26 13:07:48 -070025 GrGLExtensions() : fInitialized(false), fStrings(new SkTArray<SkString>) {}
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000026
commit-bot@chromium.orgd8ed8512014-01-24 20:49:44 +000027 GrGLExtensions(const GrGLExtensions&);
28
29 GrGLExtensions& operator=(const GrGLExtensions&);
30
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000031 void swap(GrGLExtensions* that) {
bungemana3434d82015-09-07 12:45:52 -070032 fStrings.swap(that->fStrings);
commit-bot@chromium.orgd8ed8512014-01-24 20:49:44 +000033 SkTSwap(fInitialized, that->fInitialized);
bsalomon@google.com1744f972013-02-26 21:46:32 +000034 }
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000035
bsalomon@google.com1744f972013-02-26 21:46:32 +000036 /**
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.org9e90aed2014-01-16 16:35:09 +000041 bool init(GrGLStandard standard,
bsalomon9f2dc272016-02-08 07:22:17 -080042 GrGLFunction<GrGLGetStringProc> getString,
43 GrGLFunction<GrGLGetStringiProc> getStringi,
44 GrGLFunction<GrGLGetIntegervProc> getIntegerv,
45 GrGLFunction<GrEGLQueryStringProc> queryString = nullptr,
bsalomona779ef12015-11-16 08:28:21 -080046 GrEGLDisplay eglDisplay = nullptr);
skia.committer@gmail.com12eea2b2013-02-27 07:10:10 +000047
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000048 bool isInitialized() const { return fInitialized; }
49
bsalomon@google.com1744f972013-02-26 21:46:32 +000050 /**
51 * Queries whether an extension is present. This will fail if init() has not been called.
52 */
commit-bot@chromium.orgd8ed8512014-01-24 20:49:44 +000053 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.com12eea2b2013-02-27 07:10:10 +000059
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +000060 /**
61 * Adds an extension to list
62 */
63 void add(const char[]);
64
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000065 void reset() { fStrings->reset(); }
bsalomon@google.com1744f972013-02-26 21:46:32 +000066
bsalomon@google.com00142c42013-05-02 19:42:54 +000067 void print(const char* sep = "\n") const;
68
bsalomon@google.com1744f972013-02-26 21:46:32 +000069private:
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000070 bool fInitialized;
71 SkAutoTDelete<SkTArray<SkString> > fStrings;
bsalomon@google.com1744f972013-02-26 21:46:32 +000072};
73
74#endif