robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 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 | |
| 9 | #ifndef GrGLContext_DEFINED |
| 10 | #define GrGLContext_DEFINED |
| 11 | |
| 12 | #include "gl/GrGLExtensions.h" |
| 13 | #include "gl/GrGLInterface.h" |
| 14 | #include "GrGLCaps.h" |
| 15 | #include "GrGLSL.h" |
| 16 | #include "GrGLUtil.h" |
| 17 | |
| 18 | #include "SkString.h" |
| 19 | |
| 20 | /** |
skia.committer@gmail.com | 631cdcb | 2013-03-01 12:12:55 +0000 | [diff] [blame] | 21 | * Encapsulates information about an OpenGL context including the OpenGL |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 22 | * version, the GrGLBinding type of the context, and GLSL version. |
| 23 | */ |
| 24 | class GrGLContextInfo { |
| 25 | public: |
| 26 | /** |
| 27 | * Default constructor |
| 28 | */ |
| 29 | GrGLContextInfo() { this->reset(); } |
| 30 | |
| 31 | /** |
| 32 | * Copies a GrGLContextInfo |
| 33 | */ |
| 34 | GrGLContextInfo& operator= (const GrGLContextInfo& ctxInfo); |
skia.committer@gmail.com | 631cdcb | 2013-03-01 12:12:55 +0000 | [diff] [blame] | 35 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 36 | /** |
| 37 | * Initializes a GrGLContextInfo from a GrGLInterface and the currently |
| 38 | * bound OpenGL context accessible by the GrGLInterface. |
| 39 | */ |
| 40 | bool initialize(const GrGLInterface* interface); |
| 41 | bool isInitialized() const; |
| 42 | |
| 43 | GrGLBinding binding() const { return fBindingInUse; } |
| 44 | GrGLVersion version() const { return fGLVersion; } |
| 45 | GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; } |
| 46 | GrGLVendor vendor() const { return fVendor; } |
| 47 | const GrGLCaps& caps() const { return fGLCaps; } |
| 48 | GrGLCaps& caps() { return fGLCaps; } |
| 49 | |
| 50 | /** |
| 51 | * Checks for extension support using a cached copy of the GL_EXTENSIONS |
| 52 | * string. |
| 53 | */ |
| 54 | bool hasExtension(const char* ext) const { |
| 55 | if (!this->isInitialized()) { |
| 56 | return false; |
| 57 | } |
| 58 | return fExtensions.has(ext); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Reset the information |
| 63 | */ |
| 64 | void reset(); |
| 65 | |
| 66 | private: |
| 67 | |
| 68 | GrGLBinding fBindingInUse; |
| 69 | GrGLVersion fGLVersion; |
| 70 | GrGLSLGeneration fGLSLGeneration; |
| 71 | GrGLVendor fVendor; |
| 72 | GrGLExtensions fExtensions; |
| 73 | GrGLCaps fGLCaps; |
| 74 | }; |
| 75 | |
| 76 | /** |
| 77 | * Encapsulates the GrGLInterface used to make GL calls plus information |
| 78 | * about the context (via GrGLContextInfo). |
| 79 | */ |
| 80 | class GrGLContext { |
| 81 | public: |
| 82 | /** |
| 83 | * Default constructor |
| 84 | */ |
| 85 | GrGLContext() { this->reset(); } |
| 86 | |
| 87 | /** |
| 88 | * Creates a GrGLContext from a GrGLInterface and the currently |
| 89 | * bound OpenGL context accessible by the GrGLInterface. |
| 90 | */ |
| 91 | explicit GrGLContext(const GrGLInterface* interface); |
| 92 | |
| 93 | /** |
| 94 | * Copies a GrGLContext |
| 95 | */ |
| 96 | GrGLContext(const GrGLContext& ctx); |
| 97 | |
| 98 | ~GrGLContext() { GrSafeUnref(fInterface); } |
| 99 | |
| 100 | /** |
| 101 | * Copies a GrGLContext |
| 102 | */ |
| 103 | GrGLContext& operator= (const GrGLContext& ctx); |
| 104 | |
| 105 | /** |
| 106 | * Initializes a GrGLContext from a GrGLInterface and the currently |
| 107 | * bound OpenGL context accessible by the GrGLInterface. |
| 108 | */ |
| 109 | bool initialize(const GrGLInterface* interface); |
| 110 | bool isInitialized() const { return fInfo.isInitialized(); } |
| 111 | |
| 112 | const GrGLInterface* interface() const { return fInterface; } |
| 113 | const GrGLContextInfo& info() const { return fInfo; } |
| 114 | GrGLContextInfo& info() { return fInfo; } |
| 115 | |
| 116 | private: |
| 117 | void reset(); |
| 118 | |
| 119 | const GrGLInterface* fInterface; |
| 120 | GrGLContextInfo fInfo; |
| 121 | }; |
| 122 | |
| 123 | #endif |