blob: c37b11d92a8f7b39b5655405a6715860361b0692 [file] [log] [blame]
bsalomon@google.com4ebf2b42012-02-10 21:35:35 +00001/*
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.comf7fa8062012-02-14 14:09:57 +000012#include "GrGLCaps.h"
tomhudson@google.com6bf38b52012-02-14 15:11:59 +000013#include "gl/GrGLInterface.h"
bsalomon@google.com89ec61e2012-02-10 20:05:18 +000014#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 */
23class GrGLContextInfo {
24public:
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.com96399942012-02-13 14:39:16 +000035 explicit GrGLContextInfo(const GrGLInterface* interface);
bsalomon@google.com89ec61e2012-02-10 20:05:18 +000036
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.comf7fa8062012-02-14 14:09:57 +000060 const GrGLCaps& caps() const { return fGLCaps; }
61 GrGLCaps& caps() { return fGLCaps; }
bsalomon@google.com89ec61e2012-02-10 20:05:18 +000062
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
74private:
75 void reset();
76
77 const GrGLInterface* fInterface;
78 GrGLBinding fBindingInUse;
79 GrGLVersion fGLVersion;
80 GrGLSLGeneration fGLSLGeneration;
81 SkString fExtensionString;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000082 GrGLCaps fGLCaps;
bsalomon@google.com89ec61e2012-02-10 20:05:18 +000083};
bsalomon@google.com4ebf2b42012-02-10 21:35:35 +000084
85#endif