11744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com/*
21744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com * Copyright 2013 Google Inc.
31744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com *
41744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com * Use of this source code is governed by a BSD-style license that can be
51744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com * found in the LICENSE file.
61744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com */
71744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com
81744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com#ifndef GrGLExtensions_DEFINED
91744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com#define GrGLExtensions_DEFINED
101744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com
1190313cc36a6f43a3e9d3818aca536cd6631c222bcommit-bot@chromium.org#include "GrGLFunctions.h"
121744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com#include "SkString.h"
131744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com#include "SkTArray.h"
141744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com
1590313cc36a6f43a3e9d3818aca536cd6631c222bcommit-bot@chromium.orgstruct GrGLInterface;
1690313cc36a6f43a3e9d3818aca536cd6631c222bcommit-bot@chromium.org
171744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com/**
181744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com * This helper queries the current GL context for its extensions, remembers them, and can be
191744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com * queried. It supports both glGetString- and glGetStringi-style extension string APIs and will
201744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com * use the latter if it is available.
211744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com */
220714360591c258328e9f863d105389f5a6784750commit-bot@chromium.orgclass SK_API GrGLExtensions {
231744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.compublic:
2490313cc36a6f43a3e9d3818aca536cd6631c222bcommit-bot@chromium.org    GrGLExtensions() : fInitialized(false), fStrings(SkNEW(SkTArray<SkString>)) {}
2590313cc36a6f43a3e9d3818aca536cd6631c222bcommit-bot@chromium.org
26d8ed85101ee77ad2cb0c186a79d197698a75d246commit-bot@chromium.org    GrGLExtensions(const GrGLExtensions&);
27d8ed85101ee77ad2cb0c186a79d197698a75d246commit-bot@chromium.org
28d8ed85101ee77ad2cb0c186a79d197698a75d246commit-bot@chromium.org    GrGLExtensions& operator=(const GrGLExtensions&);
29d8ed85101ee77ad2cb0c186a79d197698a75d246commit-bot@chromium.org
3090313cc36a6f43a3e9d3818aca536cd6631c222bcommit-bot@chromium.org    void swap(GrGLExtensions* that) {
3190313cc36a6f43a3e9d3818aca536cd6631c222bcommit-bot@chromium.org        fStrings.swap(&that->fStrings);
32d8ed85101ee77ad2cb0c186a79d197698a75d246commit-bot@chromium.org        SkTSwap(fInitialized, that->fInitialized);
331744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com    }
3490313cc36a6f43a3e9d3818aca536cd6631c222bcommit-bot@chromium.org
351744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com    /**
361744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com     * We sometimes need to use this class without having yet created a GrGLInterface. This version
371744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com     * of init expects that getString is always non-NULL while getIntegerv and getStringi are non-
381744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com     * NULL if on desktop GL with version 3.0 or higher. Otherwise it will fail.
391744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com     */
409e90aed5de82732cc9921f01388d3063a41a053bcommit-bot@chromium.org    bool init(GrGLStandard standard,
411744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com              GrGLGetStringProc getString,
421744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com              GrGLGetStringiProc getStringi,
431744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com              GrGLGetIntegervProc getIntegerv);
4412eea2b10d6caaafe0a207d10b1e9322510983a2skia.committer@gmail.com
4590313cc36a6f43a3e9d3818aca536cd6631c222bcommit-bot@chromium.org    bool isInitialized() const { return fInitialized; }
4690313cc36a6f43a3e9d3818aca536cd6631c222bcommit-bot@chromium.org
471744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com    /**
481744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com     * Queries whether an extension is present. This will fail if init() has not been called.
491744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com     */
50d8ed85101ee77ad2cb0c186a79d197698a75d246commit-bot@chromium.org    bool has(const char[]) const;
51d8ed85101ee77ad2cb0c186a79d197698a75d246commit-bot@chromium.org
52d8ed85101ee77ad2cb0c186a79d197698a75d246commit-bot@chromium.org    /**
53d8ed85101ee77ad2cb0c186a79d197698a75d246commit-bot@chromium.org     * Removes an extension if present. Returns true if the extension was present before the call.
54d8ed85101ee77ad2cb0c186a79d197698a75d246commit-bot@chromium.org     */
55d8ed85101ee77ad2cb0c186a79d197698a75d246commit-bot@chromium.org    bool remove(const char[]);
5612eea2b10d6caaafe0a207d10b1e9322510983a2skia.committer@gmail.com
57a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org    /**
58a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org     * Adds an extension to list
59a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org     */
60a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org    void add(const char[]);
61a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org
6290313cc36a6f43a3e9d3818aca536cd6631c222bcommit-bot@chromium.org    void reset() { fStrings->reset(); }
631744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com
6400142c44057e5a7c156b17a4bfc98a9605cf3f18bsalomon@google.com    void print(const char* sep = "\n") const;
6500142c44057e5a7c156b17a4bfc98a9605cf3f18bsalomon@google.com
661744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.comprivate:
6790313cc36a6f43a3e9d3818aca536cd6631c222bcommit-bot@chromium.org    bool                                fInitialized;
6890313cc36a6f43a3e9d3818aca536cd6631c222bcommit-bot@chromium.org    SkAutoTDelete<SkTArray<SkString> >  fStrings;
691744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com};
701744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com
711744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com#endif
72