blob: 4dc7536d60bc6c4570ad3d1650673911ee22c7f5 [file] [log] [blame]
Romain Guy3bbacf22013-02-06 16:51:04 -08001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Chris Craik117bdbc2015-02-05 10:12:38 -080017#include "Extensions.h"
18
19#include "Debug.h"
20#include "Properties.h"
Chris Craik6e6646c2015-09-14 15:54:12 -070021#include "utils/StringUtils.h"
Romain Guye9bc11f2013-05-23 12:47:26 -070022
John Reck6b507802015-11-03 10:09:59 -080023#include <GLES2/gl2.h>
Chris Craik117bdbc2015-02-05 10:12:38 -080024#include <GLES2/gl2ext.h>
Romain Guy253f2c22016-09-28 17:34:42 -070025
Romain Guye9bc11f2013-05-23 12:47:26 -070026#include <utils/Log.h>
27
Romain Guy3bbacf22013-02-06 16:51:04 -080028namespace android {
Romain Guy3bbacf22013-02-06 16:51:04 -080029namespace uirenderer {
30
Romain Guy3bbacf22013-02-06 16:51:04 -080031// Debug
32#if DEBUG_EXTENSIONS
33 #define EXT_LOGD(...) ALOGD(__VA_ARGS__)
34#else
35 #define EXT_LOGD(...)
36#endif
37
Romain Guy3bbacf22013-02-06 16:51:04 -080038
John Reck15401532015-11-16 10:40:31 -080039Extensions::Extensions() {
John Reck704bed02015-11-05 09:22:17 -080040 auto extensions = StringUtils::split((const char*) glGetString(GL_EXTENSIONS));
Chris Craik6e6646c2015-09-14 15:54:12 -070041 mHasNPot = extensions.has("GL_OES_texture_npot");
42 mHasFramebufferFetch = extensions.has("GL_NV_shader_framebuffer_fetch");
43 mHasDiscardFramebuffer = extensions.has("GL_EXT_discard_framebuffer");
44 mHasDebugMarker = extensions.has("GL_EXT_debug_marker");
45 mHas1BitStencil = extensions.has("GL_OES_stencil1");
46 mHas4BitStencil = extensions.has("GL_OES_stencil4");
47 mHasUnpackSubImage = extensions.has("GL_EXT_unpack_subimage");
Romain Guy253f2c22016-09-28 17:34:42 -070048 mHasSRGB = extensions.has("GL_EXT_sRGB");
49 mHasSRGBWriteControl = extensions.has("GL_EXT_sRGB_write_control");
50
51 // If linear blending is enabled, the device must have ES3.0 and GL_EXT_sRGB_write_control
52#ifdef ANDROID_ENABLE_LINEAR_BLENDING
53 assert(mVersionMajor >= 3 || mHasSRGB);
54 assert(mHasSRGBWriteControl);
55#endif
Romain Guy3bbacf22013-02-06 16:51:04 -080056
Romain Guydf1dc282013-03-29 18:32:29 -070057 const char* version = (const char*) glGetString(GL_VERSION);
Romain Guydf1dc282013-03-29 18:32:29 -070058
59 // Section 6.1.5 of the OpenGL ES specification indicates the GL version
60 // string strictly follows this format:
61 //
62 // OpenGL<space>ES<space><version number><space><vendor-specific information>
63 //
64 // In addition section 6.1.5 describes the version number thusly:
65 //
66 // "The version number is either of the form major number.minor number or
67 // major number.minor number.release number, where the numbers all have one
68 // or more digits. The release number and vendor specific information are
69 // optional."
70
Romain Guy6cad7572013-07-24 11:49:33 -070071 if (sscanf(version, "OpenGL ES %d.%d", &mVersionMajor, &mVersionMinor) != 2) {
Romain Guydf1dc282013-03-29 18:32:29 -070072 // If we cannot parse the version number, assume OpenGL ES 2.0
73 mVersionMajor = 2;
74 mVersionMinor = 0;
75 }
Romain Guy3bbacf22013-02-06 16:51:04 -080076}
77
Romain Guy3bbacf22013-02-06 16:51:04 -080078}; // namespace uirenderer
79}; // namespace android