blob: 73e509798e2bc3860a3c5179cc50835e363497d5 [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
bungemanbf521ff2016-02-17 13:13:44 -080011#include "../../private/SkTArray.h"
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000012#include "GrGLFunctions.h"
bsalomon@google.com1744f972013-02-26 21:46:32 +000013#include "SkString.h"
bsalomon@google.com1744f972013-02-26 21:46:32 +000014
Ben Wagnerf08d1d02018-06-18 15:11:00 -040015#include <utility>
16
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000017struct GrGLInterface;
Brian Osman71a18892017-08-10 10:23:25 -040018class SkJSONWriter;
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000019
bsalomon@google.com1744f972013-02-26 21:46:32 +000020/**
21 * This helper queries the current GL context for its extensions, remembers them, and can be
22 * queried. It supports both glGetString- and glGetStringi-style extension string APIs and will
bsalomonb1a32ad2015-11-16 06:48:44 -080023 * use the latter if it is available. It also will query for EGL extensions if a eglQueryString
24 * implementation is provided.
bsalomon@google.com1744f972013-02-26 21:46:32 +000025 */
commit-bot@chromium.org07143602014-02-25 02:14:57 +000026class SK_API GrGLExtensions {
bsalomon@google.com1744f972013-02-26 21:46:32 +000027public:
Hal Canary10450132018-03-21 12:49:56 -040028 GrGLExtensions() {}
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000029
commit-bot@chromium.orgd8ed8512014-01-24 20:49:44 +000030 GrGLExtensions(const GrGLExtensions&);
31
32 GrGLExtensions& operator=(const GrGLExtensions&);
33
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000034 void swap(GrGLExtensions* that) {
Ben Wagnerf08d1d02018-06-18 15:11:00 -040035 using std::swap;
36 swap(fStrings, that->fStrings);
37 swap(fInitialized, that->fInitialized);
bsalomon@google.com1744f972013-02-26 21:46:32 +000038 }
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000039
bsalomon@google.com1744f972013-02-26 21:46:32 +000040 /**
41 * We sometimes need to use this class without having yet created a GrGLInterface. This version
42 * of init expects that getString is always non-NULL while getIntegerv and getStringi are non-
43 * NULL if on desktop GL with version 3.0 or higher. Otherwise it will fail.
44 */
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000045 bool init(GrGLStandard standard,
bsalomon9f2dc272016-02-08 07:22:17 -080046 GrGLFunction<GrGLGetStringProc> getString,
47 GrGLFunction<GrGLGetStringiProc> getStringi,
48 GrGLFunction<GrGLGetIntegervProc> getIntegerv,
49 GrGLFunction<GrEGLQueryStringProc> queryString = nullptr,
bsalomona779ef12015-11-16 08:28:21 -080050 GrEGLDisplay eglDisplay = nullptr);
skia.committer@gmail.com12eea2b2013-02-27 07:10:10 +000051
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000052 bool isInitialized() const { return fInitialized; }
53
bsalomon@google.com1744f972013-02-26 21:46:32 +000054 /**
55 * Queries whether an extension is present. This will fail if init() has not been called.
56 */
commit-bot@chromium.orgd8ed8512014-01-24 20:49:44 +000057 bool has(const char[]) const;
58
59 /**
60 * Removes an extension if present. Returns true if the extension was present before the call.
61 */
62 bool remove(const char[]);
skia.committer@gmail.com12eea2b2013-02-27 07:10:10 +000063
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +000064 /**
65 * Adds an extension to list
66 */
67 void add(const char[]);
68
Hal Canary10450132018-03-21 12:49:56 -040069 void reset() { fStrings.reset(); }
bsalomon@google.com1744f972013-02-26 21:46:32 +000070
Brian Osman71a18892017-08-10 10:23:25 -040071 void dumpJSON(SkJSONWriter*) const;
bsalomon@google.com00142c42013-05-02 19:42:54 +000072
bsalomon@google.com1744f972013-02-26 21:46:32 +000073private:
Hal Canary10450132018-03-21 12:49:56 -040074 bool fInitialized = false;
75 SkTArray<SkString> fStrings;
bsalomon@google.com1744f972013-02-26 21:46:32 +000076};
77
78#endif