blob: 76516cf11f9fff31a7b1044c46aeb65e9fc9d1bb [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
20 * use the latter if it is available.
21 */
commit-bot@chromium.orgd8ed8512014-01-24 20:49:44 +000022class GrGLExtensions {
bsalomon@google.com1744f972013-02-26 21:46:32 +000023public:
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000024 GrGLExtensions() : fInitialized(false), fStrings(SkNEW(SkTArray<SkString>)) {}
25
commit-bot@chromium.orgd8ed8512014-01-24 20:49:44 +000026 GrGLExtensions(const GrGLExtensions&);
27
28 GrGLExtensions& operator=(const GrGLExtensions&);
29
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000030 void swap(GrGLExtensions* that) {
31 fStrings.swap(&that->fStrings);
commit-bot@chromium.orgd8ed8512014-01-24 20:49:44 +000032 SkTSwap(fInitialized, that->fInitialized);
bsalomon@google.com1744f972013-02-26 21:46:32 +000033 }
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000034
bsalomon@google.com1744f972013-02-26 21:46:32 +000035 /**
36 * We sometimes need to use this class without having yet created a GrGLInterface. This version
37 * of init expects that getString is always non-NULL while getIntegerv and getStringi are non-
38 * NULL if on desktop GL with version 3.0 or higher. Otherwise it will fail.
39 */
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000040 bool init(GrGLStandard standard,
bsalomon@google.com1744f972013-02-26 21:46:32 +000041 GrGLGetStringProc getString,
42 GrGLGetStringiProc getStringi,
43 GrGLGetIntegervProc getIntegerv);
skia.committer@gmail.com12eea2b2013-02-27 07:10:10 +000044
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000045 bool isInitialized() const { return fInitialized; }
46
bsalomon@google.com1744f972013-02-26 21:46:32 +000047 /**
48 * Queries whether an extension is present. This will fail if init() has not been called.
49 */
commit-bot@chromium.orgd8ed8512014-01-24 20:49:44 +000050 bool has(const char[]) const;
51
52 /**
53 * Removes an extension if present. Returns true if the extension was present before the call.
54 */
55 bool remove(const char[]);
skia.committer@gmail.com12eea2b2013-02-27 07:10:10 +000056
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000057 void reset() { fStrings->reset(); }
bsalomon@google.com1744f972013-02-26 21:46:32 +000058
bsalomon@google.com00142c42013-05-02 19:42:54 +000059 void print(const char* sep = "\n") const;
60
bsalomon@google.com1744f972013-02-26 21:46:32 +000061private:
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000062 bool fInitialized;
63 SkAutoTDelete<SkTArray<SkString> > fStrings;
bsalomon@google.com1744f972013-02-26 21:46:32 +000064};
65
66#endif