bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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 | #ifndef GrGLUtil_DEFINED |
| 9 | #define GrGLUtil_DEFINED |
| 10 | |
| 11 | #include "gl/GrGLInterface.h" |
bsalomon@google.com | 91bcc94 | 2012-05-07 17:28:41 +0000 | [diff] [blame] | 12 | #include "GrGLDefines.h" |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 13 | #include "GrStencilSettings.h" |
Brian Salomon | a6a3df7 | 2018-03-23 16:32:22 -0400 | [diff] [blame] | 14 | #include "GrTypesPriv.h" |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 15 | |
commit-bot@chromium.org | 215a682 | 2013-09-05 18:28:42 +0000 | [diff] [blame] | 16 | class SkMatrix; |
| 17 | |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 18 | //////////////////////////////////////////////////////////////////////////////// |
| 19 | |
| 20 | typedef uint32_t GrGLVersion; |
| 21 | typedef uint32_t GrGLSLVersion; |
Brian Salomon | 9a544bc | 2018-04-04 16:12:31 -0400 | [diff] [blame^] | 22 | typedef uint64_t GrGLDriverVersion; |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 23 | |
Brian Salomon | 9a544bc | 2018-04-04 16:12:31 -0400 | [diff] [blame^] | 24 | #define GR_GL_VER(major, minor) ((static_cast<uint32_t>(major) << 16) | \ |
| 25 | static_cast<uint32_t>(minor)) |
| 26 | #define GR_GLSL_VER(major, minor) ((static_cast<uint32_t>(major) << 16) | \ |
| 27 | static_cast<uint32_t>(minor)) |
| 28 | #define GR_GL_DRIVER_VER(major, minor, point) ((static_cast<uint64_t>(major) << 32) | \ |
| 29 | (static_cast<uint64_t>(minor) << 16) | \ |
| 30 | static_cast<uint64_t>(point)) |
commit-bot@chromium.org | f4e67e3 | 2014-04-30 01:26:04 +0000 | [diff] [blame] | 31 | |
| 32 | #define GR_GL_INVALID_VER GR_GL_VER(0, 0) |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 33 | #define GR_GLSL_INVALID_VER GR_GLSL_VER(0, 0) |
Brian Salomon | 9a544bc | 2018-04-04 16:12:31 -0400 | [diff] [blame^] | 34 | #define GR_GL_DRIVER_UNKNOWN_VER GR_GL_DRIVER_VER(0, 0, 0) |
commit-bot@chromium.org | f4e67e3 | 2014-04-30 01:26:04 +0000 | [diff] [blame] | 35 | |
bsalomon@google.com | 0b1e481 | 2012-10-23 13:52:43 +0000 | [diff] [blame] | 36 | /** |
commit-bot@chromium.org | 0694ea7 | 2013-09-18 13:00:28 +0000 | [diff] [blame] | 37 | * The Vendor and Renderer enum values are lazily updated as required. |
bsalomon@google.com | 0b1e481 | 2012-10-23 13:52:43 +0000 | [diff] [blame] | 38 | */ |
| 39 | enum GrGLVendor { |
bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame] | 40 | kARM_GrGLVendor, |
bsalomon@google.com | 3012ded | 2013-02-22 16:44:04 +0000 | [diff] [blame] | 41 | kImagination_GrGLVendor, |
| 42 | kIntel_GrGLVendor, |
commit-bot@chromium.org | 7a434a2 | 2013-08-21 14:01:56 +0000 | [diff] [blame] | 43 | kQualcomm_GrGLVendor, |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 44 | kNVIDIA_GrGLVendor, |
brianosman | 131ff13 | 2016-06-07 14:22:44 -0700 | [diff] [blame] | 45 | kATI_GrGLVendor, |
bsalomon@google.com | 3012ded | 2013-02-22 16:44:04 +0000 | [diff] [blame] | 46 | |
| 47 | kOther_GrGLVendor |
bsalomon@google.com | 0b1e481 | 2012-10-23 13:52:43 +0000 | [diff] [blame] | 48 | }; |
| 49 | |
commit-bot@chromium.org | 0694ea7 | 2013-09-18 13:00:28 +0000 | [diff] [blame] | 50 | enum GrGLRenderer { |
Chris Dalton | 0090ef6 | 2018-03-28 17:35:00 -0600 | [diff] [blame] | 51 | kTegra_PreK1_GrGLRenderer, // Legacy Tegra architecture (pre-K1). |
| 52 | kTegra_GrGLRenderer, // Tegra with the same architecture as NVIDIA desktop GPUs (K1+). |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 53 | kPowerVR54x_GrGLRenderer, |
| 54 | kPowerVRRogue_GrGLRenderer, |
bsalomon | a8fcea0 | 2015-02-13 09:00:39 -0800 | [diff] [blame] | 55 | kAdreno3xx_GrGLRenderer, |
| 56 | kAdreno4xx_GrGLRenderer, |
egdaniel | 7517e45 | 2016-09-20 13:00:26 -0700 | [diff] [blame] | 57 | kAdreno5xx_GrGLRenderer, |
bsalomon | 4017007 | 2016-05-05 14:40:03 -0700 | [diff] [blame] | 58 | kOSMesa_GrGLRenderer, |
Robert Phillips | a2fd62a | 2017-10-05 12:46:21 -0400 | [diff] [blame] | 59 | kIntelIrisPro_GrGLRenderer, |
Chris Dalton | 4a6a732 | 2017-10-06 14:28:11 -0600 | [diff] [blame] | 60 | /** Either HD 4xxx or Iris 4xxx */ |
| 61 | kIntel4xxx_GrGLRenderer, |
Brian Salomon | 028a9a5 | 2017-05-11 11:39:08 -0400 | [diff] [blame] | 62 | /** Either HD 6xxx or Iris 6xxx */ |
| 63 | kIntel6xxx_GrGLRenderer, |
Greg Daniel | 2501917 | 2017-10-26 13:32:33 -0400 | [diff] [blame] | 64 | kGalliumLLVM_GrGLRenderer, |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 65 | kMali4xx_GrGLRenderer, |
Brian Osman | ac1e496 | 2017-05-25 11:34:38 -0400 | [diff] [blame] | 66 | /** T-6xx, T-7xx, or T-8xx */ |
| 67 | kMaliT_GrGLRenderer, |
Robert Phillips | bc71274 | 2017-06-02 11:20:37 -0400 | [diff] [blame] | 68 | kANGLE_GrGLRenderer, |
Robert Phillips | dbfecd0 | 2017-10-18 15:44:08 -0400 | [diff] [blame] | 69 | |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 70 | kAMDRadeonHD7xxx_GrGLRenderer, // AMD Radeon HD 7000 Series |
| 71 | kAMDRadeonR9M4xx_GrGLRenderer, // AMD Radeon R9 M400 Series |
Robert Phillips | dbfecd0 | 2017-10-18 15:44:08 -0400 | [diff] [blame] | 72 | |
commit-bot@chromium.org | 0694ea7 | 2013-09-18 13:00:28 +0000 | [diff] [blame] | 73 | kOther_GrGLRenderer |
| 74 | }; |
| 75 | |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 76 | enum GrGLDriver { |
| 77 | kMesa_GrGLDriver, |
| 78 | kChromium_GrGLDriver, |
| 79 | kNVIDIA_GrGLDriver, |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 80 | kIntel_GrGLDriver, |
bsalomon | 88c7b98 | 2015-07-31 11:20:16 -0700 | [diff] [blame] | 81 | kANGLE_GrGLDriver, |
Brian Salomon | b52fa02 | 2017-06-07 09:42:52 -0400 | [diff] [blame] | 82 | kQualcomm_GrGLDriver, |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 83 | kUnknown_GrGLDriver |
| 84 | }; |
| 85 | |
Brian Salomon | 266ef6d | 2017-09-22 11:27:42 -0400 | [diff] [blame] | 86 | enum class GrGLANGLEBackend { |
| 87 | kUnknown, |
| 88 | kD3D9, |
| 89 | kD3D11, |
| 90 | kOpenGL |
| 91 | }; |
| 92 | |
| 93 | enum class GrGLANGLEVendor { |
| 94 | kUnknown, |
| 95 | kIntel |
| 96 | }; |
| 97 | |
Chris Dalton | 0a94e4c | 2018-01-18 15:06:50 -0700 | [diff] [blame] | 98 | enum class GrGLANGLERenderer { |
Brian Salomon | 266ef6d | 2017-09-22 11:27:42 -0400 | [diff] [blame] | 99 | kUnknown, |
Chris Dalton | 0a94e4c | 2018-01-18 15:06:50 -0700 | [diff] [blame] | 100 | kIvyBridge, |
| 101 | kSkylake |
Brian Salomon | 266ef6d | 2017-09-22 11:27:42 -0400 | [diff] [blame] | 102 | }; |
| 103 | |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 104 | //////////////////////////////////////////////////////////////////////////////// |
| 105 | |
| 106 | /** |
| 107 | * Some drivers want the var-int arg to be zero-initialized on input. |
| 108 | */ |
| 109 | #define GR_GL_INIT_ZERO 0 |
| 110 | #define GR_GL_GetIntegerv(gl, e, p) \ |
| 111 | do { \ |
| 112 | *(p) = GR_GL_INIT_ZERO; \ |
| 113 | GR_GL_CALL(gl, GetIntegerv(e, p)); \ |
| 114 | } while (0) |
| 115 | |
| 116 | #define GR_GL_GetFramebufferAttachmentParameteriv(gl, t, a, pname, p) \ |
| 117 | do { \ |
| 118 | *(p) = GR_GL_INIT_ZERO; \ |
| 119 | GR_GL_CALL(gl, GetFramebufferAttachmentParameteriv(t, a, pname, p)); \ |
| 120 | } while (0) |
| 121 | |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 122 | #define GR_GL_GetInternalformativ(gl, t, f, n, s, p) \ |
| 123 | do { \ |
| 124 | *(p) = GR_GL_INIT_ZERO; \ |
| 125 | GR_GL_CALL(gl, GetInternalformativ(t, f, n, s, p)); \ |
| 126 | } while (0) |
| 127 | |
robertphillips | 7354a4b | 2015-12-16 05:08:27 -0800 | [diff] [blame] | 128 | #define GR_GL_GetNamedFramebufferAttachmentParameteriv(gl, fb, a, pname, p) \ |
| 129 | do { \ |
| 130 | *(p) = GR_GL_INIT_ZERO; \ |
| 131 | GR_GL_CALL(gl, GetNamedFramebufferAttachmentParameteriv(fb, a, pname, p)); \ |
| 132 | } while (0) |
| 133 | |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 134 | #define GR_GL_GetRenderbufferParameteriv(gl, t, pname, p) \ |
| 135 | do { \ |
| 136 | *(p) = GR_GL_INIT_ZERO; \ |
| 137 | GR_GL_CALL(gl, GetRenderbufferParameteriv(t, pname, p)); \ |
| 138 | } while (0) |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 139 | |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 140 | #define GR_GL_GetTexLevelParameteriv(gl, t, l, pname, p) \ |
| 141 | do { \ |
| 142 | *(p) = GR_GL_INIT_ZERO; \ |
| 143 | GR_GL_CALL(gl, GetTexLevelParameteriv(t, l, pname, p)); \ |
| 144 | } while (0) |
| 145 | |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 146 | #define GR_GL_GetShaderPrecisionFormat(gl, st, pt, range, precision) \ |
| 147 | do { \ |
| 148 | (range)[0] = GR_GL_INIT_ZERO; \ |
| 149 | (range)[1] = GR_GL_INIT_ZERO; \ |
| 150 | (*precision) = GR_GL_INIT_ZERO; \ |
| 151 | GR_GL_CALL(gl, GetShaderPrecisionFormat(st, pt, range, precision)); \ |
| 152 | } while (0) |
| 153 | |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 154 | //////////////////////////////////////////////////////////////////////////////// |
| 155 | |
| 156 | /** |
| 157 | * Helpers for glGetString() |
| 158 | */ |
| 159 | |
| 160 | // these variants assume caller already has a string from glGetString() |
| 161 | GrGLVersion GrGLGetVersionFromString(const char* versionString); |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 162 | GrGLStandard GrGLGetStandardInUseFromString(const char* versionString); |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 163 | GrGLSLVersion GrGLGetGLSLVersionFromString(const char* versionString); |
bsalomon@google.com | 0b1e481 | 2012-10-23 13:52:43 +0000 | [diff] [blame] | 164 | GrGLVendor GrGLGetVendorFromString(const char* vendorString); |
Chris Dalton | 0090ef6 | 2018-03-28 17:35:00 -0600 | [diff] [blame] | 165 | GrGLRenderer GrGLGetRendererFromStrings(const char* rendererString, const char* extensionString); |
Brian Salomon | 266ef6d | 2017-09-22 11:27:42 -0400 | [diff] [blame] | 166 | void GrGLGetANGLEInfoFromString(const char* rendererString, GrGLANGLEBackend*, |
| 167 | GrGLANGLEVendor*, GrGLANGLERenderer*); |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 168 | |
| 169 | void GrGLGetDriverInfo(GrGLStandard standard, |
| 170 | GrGLVendor vendor, |
| 171 | const char* rendererString, |
| 172 | const char* versionString, |
| 173 | GrGLDriver* outDriver, |
| 174 | GrGLDriverVersion* outVersion); |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 175 | |
| 176 | // these variants call glGetString() |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 177 | GrGLVersion GrGLGetVersion(const GrGLInterface*); |
| 178 | GrGLSLVersion GrGLGetGLSLVersion(const GrGLInterface*); |
bsalomon@google.com | 0b1e481 | 2012-10-23 13:52:43 +0000 | [diff] [blame] | 179 | GrGLVendor GrGLGetVendor(const GrGLInterface*); |
commit-bot@chromium.org | 0694ea7 | 2013-09-18 13:00:28 +0000 | [diff] [blame] | 180 | GrGLRenderer GrGLGetRenderer(const GrGLInterface*); |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 181 | |
| 182 | /** |
| 183 | * Helpers for glGetError() |
| 184 | */ |
| 185 | |
bsalomon@google.com | 2717d56 | 2012-05-07 19:10:52 +0000 | [diff] [blame] | 186 | void GrGLCheckErr(const GrGLInterface* gl, |
| 187 | const char* location, |
| 188 | const char* call); |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 189 | |
bsalomon@google.com | 2717d56 | 2012-05-07 19:10:52 +0000 | [diff] [blame] | 190 | void GrGLClearErr(const GrGLInterface* gl); |
| 191 | |
| 192 | //////////////////////////////////////////////////////////////////////////////// |
| 193 | |
| 194 | /** |
| 195 | * Macros for using GrGLInterface to make GL calls |
| 196 | */ |
| 197 | |
| 198 | // internal macro to conditionally call glGetError based on compile-time and |
| 199 | // run-time flags. |
| 200 | #if GR_GL_CHECK_ERROR |
| 201 | extern bool gCheckErrorGL; |
| 202 | #define GR_GL_CHECK_ERROR_IMPL(IFACE, X) \ |
| 203 | if (gCheckErrorGL) \ |
| 204 | GrGLCheckErr(IFACE, GR_FILE_AND_LINE_STR, #X) |
| 205 | #else |
| 206 | #define GR_GL_CHECK_ERROR_IMPL(IFACE, X) |
| 207 | #endif |
| 208 | |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 209 | // internal macro to conditionally log the gl call using SkDebugf based on |
bsalomon@google.com | 2717d56 | 2012-05-07 19:10:52 +0000 | [diff] [blame] | 210 | // compile-time and run-time flags. |
| 211 | #if GR_GL_LOG_CALLS |
| 212 | extern bool gLogCallsGL; |
| 213 | #define GR_GL_LOG_CALLS_IMPL(X) \ |
| 214 | if (gLogCallsGL) \ |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 215 | SkDebugf(GR_FILE_AND_LINE_STR "GL: " #X "\n") |
bsalomon@google.com | 2717d56 | 2012-05-07 19:10:52 +0000 | [diff] [blame] | 216 | #else |
| 217 | #define GR_GL_LOG_CALLS_IMPL(X) |
| 218 | #endif |
| 219 | |
bsalomon@google.com | 2717d56 | 2012-05-07 19:10:52 +0000 | [diff] [blame] | 220 | // makes a GL call on the interface and does any error checking and logging |
| 221 | #define GR_GL_CALL(IFACE, X) \ |
| 222 | do { \ |
| 223 | GR_GL_CALL_NOERRCHECK(IFACE, X); \ |
| 224 | GR_GL_CHECK_ERROR_IMPL(IFACE, X); \ |
| 225 | } while (false) |
| 226 | |
| 227 | // Variant of above that always skips the error check. This is useful when |
| 228 | // the caller wants to do its own glGetError() call and examine the error value. |
| 229 | #define GR_GL_CALL_NOERRCHECK(IFACE, X) \ |
| 230 | do { \ |
commit-bot@chromium.org | c72425a | 2014-01-21 16:09:18 +0000 | [diff] [blame] | 231 | (IFACE)->fFunctions.f##X; \ |
bsalomon@google.com | 2717d56 | 2012-05-07 19:10:52 +0000 | [diff] [blame] | 232 | GR_GL_LOG_CALLS_IMPL(X); \ |
| 233 | } while (false) |
| 234 | |
| 235 | // same as GR_GL_CALL but stores the return value of the gl call in RET |
| 236 | #define GR_GL_CALL_RET(IFACE, RET, X) \ |
| 237 | do { \ |
| 238 | GR_GL_CALL_RET_NOERRCHECK(IFACE, RET, X); \ |
| 239 | GR_GL_CHECK_ERROR_IMPL(IFACE, X); \ |
| 240 | } while (false) |
| 241 | |
| 242 | // same as GR_GL_CALL_RET but always skips the error check. |
| 243 | #define GR_GL_CALL_RET_NOERRCHECK(IFACE, RET, X) \ |
| 244 | do { \ |
commit-bot@chromium.org | c72425a | 2014-01-21 16:09:18 +0000 | [diff] [blame] | 245 | (RET) = (IFACE)->fFunctions.f##X; \ |
bsalomon@google.com | 2717d56 | 2012-05-07 19:10:52 +0000 | [diff] [blame] | 246 | GR_GL_LOG_CALLS_IMPL(X); \ |
| 247 | } while (false) |
| 248 | |
| 249 | // call glGetError without doing a redundant error check or logging. |
commit-bot@chromium.org | c72425a | 2014-01-21 16:09:18 +0000 | [diff] [blame] | 250 | #define GR_GL_GET_ERROR(IFACE) (IFACE)->fFunctions.fGetError() |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 251 | |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 252 | GrGLenum GrToGLStencilFunc(GrStencilTest test); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 253 | |
Greg Daniel | 8a3f55c | 2018-03-14 17:32:12 +0000 | [diff] [blame] | 254 | GrPixelConfig GrGLSizedFormatToPixelConfig(GrGLenum sizedFormat); |
| 255 | |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 256 | #endif |