aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/gl/GrGLContextInfo.h
blob: 44fc98555fdda3cfcc52438754219b48a4295854 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 * Copyright 2012 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */


#ifndef GrGLContextInfo_DEFINED
#define GrGLContextInfo_DEFINED

#include "gl/GrGLInterface.h"
#include "GrGLCaps.h"
#include "GrGLSL.h"
#include "GrGLUtil.h"

#include "SkString.h"

/**
 * Encapsulates information about an OpenGL context including the GrGLInterface
 * used to make GL calls, the OpenGL version, the GrGLBinding type of the
 * context, and GLSL version.
 */
class GrGLContextInfo {
public:

    /**
     * Default constructor, creates an uninitialized GrGLContextInfo
     */
    GrGLContextInfo();

    /**
     * Creates a GrGLContextInfo from a GrGLInterface and the currently
     * bound OpenGL context accesible by the GrGLInterface.
     */
    explicit GrGLContextInfo(const GrGLInterface* interface);

    /**
     * Copies a GrGLContextInfo
     */
    GrGLContextInfo(const GrGLContextInfo& ctx);

    ~GrGLContextInfo();

    /**
     * Copies a GrGLContextInfo
     */
    GrGLContextInfo& operator = (const GrGLContextInfo& ctx);

    /**
     * Initializes a GrGLContextInfo from a GrGLInterface and the currently
     * bound OpenGL context accessible by the GrGLInterface.
     */
    bool initialize(const GrGLInterface* interface);
    bool isInitialized() const;

    const GrGLInterface* interface() const { return fInterface; }
    GrGLBinding binding() const { return fBindingInUse; }
    GrGLVersion version() const { return fGLVersion; }
    GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; }
    const GrGLCaps& caps() const { return fGLCaps; }
    GrGLCaps& caps() { return fGLCaps; }

    /**
     * Checks for extension support using a cached copy of the GL_EXTENSIONS
     * string.
     */
    bool hasExtension(const char* ext) const {
        if (!this->isInitialized()) {
            return false;
        }
        return GrGLHasExtensionFromString(ext, fExtensionString.c_str());
    }

private:
    void reset();

    const GrGLInterface* fInterface;
    GrGLBinding          fBindingInUse;
    GrGLVersion          fGLVersion;
    GrGLSLGeneration     fGLSLGeneration;
    SkString             fExtensionString;
    GrGLCaps             fGLCaps;
};

#endif