blob: 172cd8b86402a597659da979c1579a005afb0fbb [file] [log] [blame]
robertphillips@google.com6177e692013-02-28 20:16:25 +00001/*
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.com631cdcb2013-03-01 12:12:55 +000021 * Encapsulates information about an OpenGL context including the OpenGL
robertphillips@google.com6177e692013-02-28 20:16:25 +000022 * version, the GrGLBinding type of the context, and GLSL version.
23 */
24class GrGLContextInfo {
25public:
26 /**
27 * Default constructor
28 */
bsalomon@google.combcce8922013-03-25 15:38:39 +000029 GrGLContextInfo() {
30 fGLCaps.reset(SkNEW(GrGLCaps));
31 this->reset();
32 }
robertphillips@google.com6177e692013-02-28 20:16:25 +000033
34 /**
35 * Copies a GrGLContextInfo
36 */
37 GrGLContextInfo& operator= (const GrGLContextInfo& ctxInfo);
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +000038
robertphillips@google.com6177e692013-02-28 20:16:25 +000039 /**
40 * Initializes a GrGLContextInfo from a GrGLInterface and the currently
41 * bound OpenGL context accessible by the GrGLInterface.
42 */
43 bool initialize(const GrGLInterface* interface);
44 bool isInitialized() const;
45
46 GrGLBinding binding() const { return fBindingInUse; }
47 GrGLVersion version() const { return fGLVersion; }
48 GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; }
49 GrGLVendor vendor() const { return fVendor; }
bsalomon@google.combcce8922013-03-25 15:38:39 +000050 const GrGLCaps* caps() const { return fGLCaps.get(); }
51 GrGLCaps* caps() { return fGLCaps; }
bsalomon@google.com00142c42013-05-02 19:42:54 +000052 const GrGLExtensions& extensions() const { return fExtensions; }
robertphillips@google.com6177e692013-02-28 20:16:25 +000053
54 /**
bsalomon@google.com00142c42013-05-02 19:42:54 +000055 * Shortcut for extensions().has(ext);
robertphillips@google.com6177e692013-02-28 20:16:25 +000056 */
57 bool hasExtension(const char* ext) const {
58 if (!this->isInitialized()) {
59 return false;
60 }
61 return fExtensions.has(ext);
62 }
63
64 /**
65 * Reset the information
66 */
67 void reset();
68
69private:
70
bsalomon@google.combcce8922013-03-25 15:38:39 +000071 GrGLBinding fBindingInUse;
72 GrGLVersion fGLVersion;
73 GrGLSLGeneration fGLSLGeneration;
74 GrGLVendor fVendor;
75 GrGLExtensions fExtensions;
76 SkAutoTUnref<GrGLCaps> fGLCaps;
robertphillips@google.com6177e692013-02-28 20:16:25 +000077};
78
79/**
80 * Encapsulates the GrGLInterface used to make GL calls plus information
81 * about the context (via GrGLContextInfo).
82 */
83class GrGLContext {
84public:
85 /**
86 * Default constructor
87 */
88 GrGLContext() { this->reset(); }
89
90 /**
91 * Creates a GrGLContext from a GrGLInterface and the currently
92 * bound OpenGL context accessible by the GrGLInterface.
93 */
94 explicit GrGLContext(const GrGLInterface* interface);
95
96 /**
97 * Copies a GrGLContext
98 */
99 GrGLContext(const GrGLContext& ctx);
100
101 ~GrGLContext() { GrSafeUnref(fInterface); }
102
103 /**
104 * Copies a GrGLContext
105 */
106 GrGLContext& operator= (const GrGLContext& ctx);
107
108 /**
109 * Initializes a GrGLContext from a GrGLInterface and the currently
110 * bound OpenGL context accessible by the GrGLInterface.
111 */
112 bool initialize(const GrGLInterface* interface);
113 bool isInitialized() const { return fInfo.isInitialized(); }
114
115 const GrGLInterface* interface() const { return fInterface; }
116 const GrGLContextInfo& info() const { return fInfo; }
117 GrGLContextInfo& info() { return fInfo; }
118
119private:
120 void reset();
121
122 const GrGLInterface* fInterface;
123 GrGLContextInfo fInfo;
124};
125
126#endif