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