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 11 #include "../../private/SkTArray.h" 12 #include "GrGLFunctions.h" 13 #include "SkString.h" 14 15 struct GrGLInterface; 16 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 20 * use the latter if it is available. It also will query for EGL extensions if a eglQueryString 21 * implementation is provided. 22 */ 23 class SK_API GrGLExtensions { 24 public: GrGLExtensions()25 GrGLExtensions() : fInitialized(false), fStrings(new SkTArray<SkString>) {} 26 27 GrGLExtensions(const GrGLExtensions&); 28 29 GrGLExtensions& operator=(const GrGLExtensions&); 30 swap(GrGLExtensions * that)31 void swap(GrGLExtensions* that) { 32 fStrings.swap(that->fStrings); 33 SkTSwap(fInitialized, that->fInitialized); 34 } 35 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 */ 41 bool init(GrGLStandard standard, 42 GrGLFunction<GrGLGetStringProc> getString, 43 GrGLFunction<GrGLGetStringiProc> getStringi, 44 GrGLFunction<GrGLGetIntegervProc> getIntegerv, 45 GrGLFunction<GrEGLQueryStringProc> queryString = nullptr, 46 GrEGLDisplay eglDisplay = nullptr); 47 isInitialized()48 bool isInitialized() const { return fInitialized; } 49 50 /** 51 * Queries whether an extension is present. This will fail if init() has not been called. 52 */ 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[]); 59 60 /** 61 * Adds an extension to list 62 */ 63 void add(const char[]); 64 reset()65 void reset() { fStrings->reset(); } 66 67 void print(const char* sep = "\n") const; 68 69 private: 70 bool fInitialized; 71 SkAutoTDelete<SkTArray<SkString> > fStrings; 72 }; 73 74 #endif 75