aboutsummaryrefslogtreecommitdiff
path: root/src/egl-state.h
blob: 2eaeba396fdbfb2a90093b8b27286e7b22ecbc33 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//
// Copyright © 2012 Linaro Limited
//
// This file is part of the glmark2 OpenGL (ES) 2.0 benchmark.
//
// glmark2 is free software: you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the Free Software
// Foundation, either version 3 of the License, or (at your option) any later
// version.
//
// glmark2 is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// glmark2.  If not, see <http://www.gnu.org/licenses/>.
//
// Authors:
//  Jesse Barker
//
#ifndef EGL_STATE_H_
#define EGL_STATE_H_

#include <vector>
#include <EGL/egl.h>
#include "gl-visual-config.h"

class EglConfig
{
    EGLConfig handle_;
    // Color buffer attributes.
    EGLint bufferSize_;
    EGLint redSize_;
    EGLint greenSize_;
    EGLint blueSize_;
    EGLint luminanceSize_;
    EGLint alphaSize_;
    EGLint alphaMaskSize_;
    bool bindTexRGB_;
    bool bindTexRGBA_;
    EGLint bufferType_;
    // Base config attributes
    EGLint caveat_;
    EGLint configID_;
    EGLint conformant_;
    // Depth buffer
    EGLint depthSize_;
    // Framebuffer level
    EGLint level_;
    // Pbuffers
    EGLint pbufferWidth_;
    EGLint pbufferHeight_;
    EGLint pbufferPixels_;
    // Swap interval
    EGLint minSwapInterval_;
    EGLint maxSwapInterval_;
    // Native window system attributes.
    EGLint nativeID_;
    EGLint nativeType_;
    bool nativeRenderable_;
    // Multisample support
    EGLint sampleBuffers_;
    EGLint samples_;
    // Stencil buffer
    EGLint stencilSize_;
    EGLint surfaceType_;
    // Transparency
    EGLint xparentType_; // Should be RGB or NONE
    EGLint xparentRedValue_;
    EGLint xparentGreenValue_;
    EGLint xparentBlueValue_;

public:
    EglConfig() :
        handle_(0),
        bufferSize_(0),
        redSize_(0),
        greenSize_(0),
        blueSize_(0),
        luminanceSize_(0),
        alphaSize_(0),
        alphaMaskSize_(0),
        bindTexRGB_(false),
        bindTexRGBA_(false),
        bufferType_(EGL_RGB_BUFFER),
        caveat_(0),
        configID_(0),
        conformant_(0),
        depthSize_(0),
        level_(0),
        pbufferWidth_(0),
        pbufferHeight_(0),
        pbufferPixels_(0),
        minSwapInterval_(0),
        maxSwapInterval_(0),
        nativeID_(0),
        nativeType_(0),
        nativeRenderable_(false),
        sampleBuffers_(0),
        samples_(0),
        stencilSize_(0),
        surfaceType_(0),
        xparentType_(0),
        xparentRedValue_(0),
        xparentGreenValue_(0),
        xparentBlueValue_(0) {}
    EglConfig(EGLDisplay dpy, EGLConfig config);
    ~EglConfig() {}
    void print() const;
    static void print_header();
    bool isWindowConfig() const { return surfaceType_ & EGL_WINDOW_BIT; }
    EGLint configID() const { return configID_; }
};

class EGLState
{
    EGLNativeDisplayType native_display_;
    EGLNativeWindowType native_window_;
    EGLDisplay egl_display_;
    EGLConfig egl_config_;
    EGLContext egl_context_;
    EGLSurface egl_surface_;
    GLVisualConfig visual_config_;
    EglConfig best_config_;
    bool gotValidDisplay();
    bool gotValidConfig();
    bool gotValidSurface();
    bool gotValidContext();
    void get_glvisualconfig(EGLConfig config, GLVisualConfig& visual_config);
    EGLConfig select_best_config(std::vector<EGLConfig>& configs);
public:
    EGLState() :
        native_display_(0),
        native_window_(0),
        egl_display_(0),
        egl_config_(0),
        egl_context_(0),
        egl_surface_(0) {}
    ~EGLState() {}
    bool valid();
    bool init_display(EGLNativeDisplayType native_display, GLVisualConfig& config_pref);
    bool init_surface(EGLNativeWindowType native_window);
    bool reset();
    void swap();
    // Performs a config search, returning a native visual ID on success
    bool gotNativeConfig(int& vid);
    void getVisualConfig(GLVisualConfig& vc) { vc = visual_config_; }
};

#endif // EGL_STATE_H_