summaryrefslogtreecommitdiffstats
path: root/host/libs/virglrenderer/libOpenglRender/GLESVersionDetector.cpp
blob: 57a3b50274ce5e327ad8ba872341df6837df3efd (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
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "GLESVersionDetector.h"

#include "DispatchTables.h"

#include "emugl/common/feature_control.h"

#include <algorithm>

GLESDispatchMaxVersion calcMaxVersionFromDispatch() {
    // Detect the proper OpenGL ES version to advertise to the system.
    //
    // If the underlying glesv2 library also is on top of system OpenGL,
    // we assume existence of a function called "gl_dispatch_get_max_version"
    // which matches the return type of gles2_dispatch_get_max_version,
    // and allows us to scale back if the underlying host machine
    // doesn't actually suppport a particular GLES version.
    if (!emugl_feature_is_enabled(android::featurecontrol::GLESDynamicVersion))
        return GLES_DISPATCH_MAX_VERSION_2;

    GLESDispatchMaxVersion underlying_gles2_lib_max =
        gles2_dispatch_get_max_version();
    if (s_gles2.gl_dispatch_get_max_version) {
        GLESDispatchMaxVersion underlying_gl_lib_max =
            (GLESDispatchMaxVersion)s_gles2.gl_dispatch_get_max_version();
        return std::min(underlying_gl_lib_max, underlying_gles2_lib_max);
    } else {
        return underlying_gles2_lib_max;
    }

    return GLES_DISPATCH_MAX_VERSION_2;
}