• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012 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 
9 #ifndef GrGLContextInfo_DEFINED
10 #define GrGLContextInfo_DEFINED
11 
12 #include "gl/GrGLInterface.h"
13 #include "GrGLCaps.h"
14 #include "GrGLSL.h"
15 #include "GrGLUtil.h"
16 
17 #include "SkString.h"
18 
19 /**
20  * Encapsulates information about an OpenGL context including the GrGLInterface
21  * used to make GL calls, the OpenGL version, the GrGLBinding type of the
22  * context, and GLSL version.
23  */
24 class GrGLContextInfo {
25 public:
26 
27     /**
28      * Default constructor, creates an uninitialized GrGLContextInfo
29      */
30     GrGLContextInfo();
31 
32     /**
33      * Creates a GrGLContextInfo from a GrGLInterface and the currently
34      * bound OpenGL context accessible by the GrGLInterface.
35      */
36     explicit GrGLContextInfo(const GrGLInterface* interface);
37 
38     /**
39      * Copies a GrGLContextInfo
40      */
41     GrGLContextInfo(const GrGLContextInfo& ctx);
42 
43     ~GrGLContextInfo();
44 
45     /**
46      * Copies a GrGLContextInfo
47      */
48     GrGLContextInfo& operator = (const GrGLContextInfo& ctx);
49 
50     /**
51      * Initializes a GrGLContextInfo from a GrGLInterface and the currently
52      * bound OpenGL context accessible by the GrGLInterface.
53      */
54     bool initialize(const GrGLInterface* interface);
55     bool isInitialized() const;
56 
interface()57     const GrGLInterface* interface() const { return fInterface; }
binding()58     GrGLBinding binding() const { return fBindingInUse; }
version()59     GrGLVersion version() const { return fGLVersion; }
glslGeneration()60     GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; }
vendor()61     GrGLVendor vendor() const { return fVendor; }
caps()62     const GrGLCaps& caps() const { return fGLCaps; }
caps()63     GrGLCaps& caps() { return fGLCaps; }
64 
65     /**
66      * Checks for extension support using a cached copy of the GL_EXTENSIONS
67      * string.
68      */
hasExtension(const char * ext)69     bool hasExtension(const char* ext) const {
70         if (!this->isInitialized()) {
71             return false;
72         }
73         return GrGLHasExtensionFromString(ext, fExtensionString.c_str());
74     }
75 
76 private:
77     void reset();
78 
79     const GrGLInterface* fInterface;
80     GrGLBinding          fBindingInUse;
81     GrGLVersion          fGLVersion;
82     GrGLSLGeneration     fGLSLGeneration;
83     GrGLVendor           fVendor;
84     SkString             fExtensionString;
85     GrGLCaps             fGLCaps;
86 };
87 
88 #endif
89