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" |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 14 | |
commit-bot@chromium.org | 215a682 | 2013-09-05 18:28:42 +0000 | [diff] [blame] | 15 | class SkMatrix; |
| 16 | |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 17 | //////////////////////////////////////////////////////////////////////////////// |
| 18 | |
| 19 | typedef uint32_t GrGLVersion; |
| 20 | typedef uint32_t GrGLSLVersion; |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 21 | typedef uint32_t GrGLDriverVersion; |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 22 | |
commit-bot@chromium.org | f4e67e3 | 2014-04-30 01:26:04 +0000 | [diff] [blame] | 23 | #define GR_GL_VER(major, minor) ((static_cast<int>(major) << 16) | \ |
| 24 | static_cast<int>(minor)) |
| 25 | #define GR_GLSL_VER(major, minor) ((static_cast<int>(major) << 16) | \ |
| 26 | static_cast<int>(minor)) |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 27 | #define GR_GL_DRIVER_VER(major, minor) ((static_cast<int>(major) << 16) | \ |
| 28 | static_cast<int>(minor)) |
commit-bot@chromium.org | f4e67e3 | 2014-04-30 01:26:04 +0000 | [diff] [blame] | 29 | |
| 30 | #define GR_GL_INVALID_VER GR_GL_VER(0, 0) |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 31 | #define GR_GLSL_INVALID_VER GR_GLSL_VER(0, 0) |
| 32 | #define GR_GL_DRIVER_UNKNOWN_VER GR_GL_DRIVER_VER(0, 0) |
commit-bot@chromium.org | f4e67e3 | 2014-04-30 01:26:04 +0000 | [diff] [blame] | 33 | |
bsalomon@google.com | 0b1e481 | 2012-10-23 13:52:43 +0000 | [diff] [blame] | 34 | /** |
commit-bot@chromium.org | 0694ea7 | 2013-09-18 13:00:28 +0000 | [diff] [blame] | 35 | * The Vendor and Renderer enum values are lazily updated as required. |
bsalomon@google.com | 0b1e481 | 2012-10-23 13:52:43 +0000 | [diff] [blame] | 36 | */ |
| 37 | enum GrGLVendor { |
bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame] | 38 | kARM_GrGLVendor, |
bsalomon@google.com | 3012ded | 2013-02-22 16:44:04 +0000 | [diff] [blame] | 39 | kImagination_GrGLVendor, |
| 40 | kIntel_GrGLVendor, |
commit-bot@chromium.org | 7a434a2 | 2013-08-21 14:01:56 +0000 | [diff] [blame] | 41 | kQualcomm_GrGLVendor, |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 42 | kNVIDIA_GrGLVendor, |
brianosman | 131ff13 | 2016-06-07 14:22:44 -0700 | [diff] [blame^] | 43 | kATI_GrGLVendor, |
bsalomon@google.com | 3012ded | 2013-02-22 16:44:04 +0000 | [diff] [blame] | 44 | |
| 45 | kOther_GrGLVendor |
bsalomon@google.com | 0b1e481 | 2012-10-23 13:52:43 +0000 | [diff] [blame] | 46 | }; |
| 47 | |
commit-bot@chromium.org | 0694ea7 | 2013-09-18 13:00:28 +0000 | [diff] [blame] | 48 | enum GrGLRenderer { |
commit-bot@chromium.org | 6dee875 | 2014-02-07 22:39:01 +0000 | [diff] [blame] | 49 | kTegra2_GrGLRenderer, |
commit-bot@chromium.org | 0694ea7 | 2013-09-18 13:00:28 +0000 | [diff] [blame] | 50 | kTegra3_GrGLRenderer, |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 51 | kPowerVR54x_GrGLRenderer, |
| 52 | kPowerVRRogue_GrGLRenderer, |
bsalomon | a8fcea0 | 2015-02-13 09:00:39 -0800 | [diff] [blame] | 53 | kAdreno3xx_GrGLRenderer, |
| 54 | kAdreno4xx_GrGLRenderer, |
bsalomon | 4017007 | 2016-05-05 14:40:03 -0700 | [diff] [blame] | 55 | kOSMesa_GrGLRenderer, |
commit-bot@chromium.org | 0694ea7 | 2013-09-18 13:00:28 +0000 | [diff] [blame] | 56 | kOther_GrGLRenderer |
| 57 | }; |
| 58 | |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 59 | enum GrGLDriver { |
| 60 | kMesa_GrGLDriver, |
| 61 | kChromium_GrGLDriver, |
| 62 | kNVIDIA_GrGLDriver, |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 63 | kIntel_GrGLDriver, |
bsalomon | 88c7b98 | 2015-07-31 11:20:16 -0700 | [diff] [blame] | 64 | kANGLE_GrGLDriver, |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 65 | kUnknown_GrGLDriver |
| 66 | }; |
| 67 | |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 68 | //////////////////////////////////////////////////////////////////////////////// |
| 69 | |
| 70 | /** |
| 71 | * Some drivers want the var-int arg to be zero-initialized on input. |
| 72 | */ |
| 73 | #define GR_GL_INIT_ZERO 0 |
| 74 | #define GR_GL_GetIntegerv(gl, e, p) \ |
| 75 | do { \ |
| 76 | *(p) = GR_GL_INIT_ZERO; \ |
| 77 | GR_GL_CALL(gl, GetIntegerv(e, p)); \ |
| 78 | } while (0) |
| 79 | |
| 80 | #define GR_GL_GetFramebufferAttachmentParameteriv(gl, t, a, pname, p) \ |
| 81 | do { \ |
| 82 | *(p) = GR_GL_INIT_ZERO; \ |
| 83 | GR_GL_CALL(gl, GetFramebufferAttachmentParameteriv(t, a, pname, p)); \ |
| 84 | } while (0) |
| 85 | |
robertphillips | 7354a4b | 2015-12-16 05:08:27 -0800 | [diff] [blame] | 86 | #define GR_GL_GetNamedFramebufferAttachmentParameteriv(gl, fb, a, pname, p) \ |
| 87 | do { \ |
| 88 | *(p) = GR_GL_INIT_ZERO; \ |
| 89 | GR_GL_CALL(gl, GetNamedFramebufferAttachmentParameteriv(fb, a, pname, p)); \ |
| 90 | } while (0) |
| 91 | |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 92 | #define GR_GL_GetRenderbufferParameteriv(gl, t, pname, p) \ |
| 93 | do { \ |
| 94 | *(p) = GR_GL_INIT_ZERO; \ |
| 95 | GR_GL_CALL(gl, GetRenderbufferParameteriv(t, pname, p)); \ |
| 96 | } while (0) |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 97 | |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 98 | #define GR_GL_GetTexLevelParameteriv(gl, t, l, pname, p) \ |
| 99 | do { \ |
| 100 | *(p) = GR_GL_INIT_ZERO; \ |
| 101 | GR_GL_CALL(gl, GetTexLevelParameteriv(t, l, pname, p)); \ |
| 102 | } while (0) |
| 103 | |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 104 | #define GR_GL_GetShaderPrecisionFormat(gl, st, pt, range, precision) \ |
| 105 | do { \ |
| 106 | (range)[0] = GR_GL_INIT_ZERO; \ |
| 107 | (range)[1] = GR_GL_INIT_ZERO; \ |
| 108 | (*precision) = GR_GL_INIT_ZERO; \ |
| 109 | GR_GL_CALL(gl, GetShaderPrecisionFormat(st, pt, range, precision)); \ |
| 110 | } while (0) |
| 111 | |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 112 | //////////////////////////////////////////////////////////////////////////////// |
| 113 | |
| 114 | /** |
| 115 | * Helpers for glGetString() |
| 116 | */ |
| 117 | |
| 118 | // these variants assume caller already has a string from glGetString() |
| 119 | GrGLVersion GrGLGetVersionFromString(const char* versionString); |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 120 | GrGLStandard GrGLGetStandardInUseFromString(const char* versionString); |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 121 | GrGLSLVersion GrGLGetGLSLVersionFromString(const char* versionString); |
bsalomon@google.com | 0b1e481 | 2012-10-23 13:52:43 +0000 | [diff] [blame] | 122 | GrGLVendor GrGLGetVendorFromString(const char* vendorString); |
commit-bot@chromium.org | 0694ea7 | 2013-09-18 13:00:28 +0000 | [diff] [blame] | 123 | GrGLRenderer GrGLGetRendererFromString(const char* rendererString); |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 124 | |
| 125 | void GrGLGetDriverInfo(GrGLStandard standard, |
| 126 | GrGLVendor vendor, |
| 127 | const char* rendererString, |
| 128 | const char* versionString, |
| 129 | GrGLDriver* outDriver, |
| 130 | GrGLDriverVersion* outVersion); |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 131 | |
| 132 | // these variants call glGetString() |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 133 | GrGLVersion GrGLGetVersion(const GrGLInterface*); |
| 134 | GrGLSLVersion GrGLGetGLSLVersion(const GrGLInterface*); |
bsalomon@google.com | 0b1e481 | 2012-10-23 13:52:43 +0000 | [diff] [blame] | 135 | GrGLVendor GrGLGetVendor(const GrGLInterface*); |
commit-bot@chromium.org | 0694ea7 | 2013-09-18 13:00:28 +0000 | [diff] [blame] | 136 | GrGLRenderer GrGLGetRenderer(const GrGLInterface*); |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 137 | |
commit-bot@chromium.org | c9424b8 | 2013-10-30 20:03:16 +0000 | [diff] [blame] | 138 | |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 139 | /** |
| 140 | * Helpers for glGetError() |
| 141 | */ |
| 142 | |
bsalomon@google.com | 2717d56 | 2012-05-07 19:10:52 +0000 | [diff] [blame] | 143 | void GrGLCheckErr(const GrGLInterface* gl, |
| 144 | const char* location, |
| 145 | const char* call); |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 146 | |
bsalomon@google.com | 2717d56 | 2012-05-07 19:10:52 +0000 | [diff] [blame] | 147 | void GrGLClearErr(const GrGLInterface* gl); |
| 148 | |
| 149 | //////////////////////////////////////////////////////////////////////////////// |
| 150 | |
| 151 | /** |
| 152 | * Macros for using GrGLInterface to make GL calls |
| 153 | */ |
| 154 | |
| 155 | // internal macro to conditionally call glGetError based on compile-time and |
| 156 | // run-time flags. |
| 157 | #if GR_GL_CHECK_ERROR |
| 158 | extern bool gCheckErrorGL; |
| 159 | #define GR_GL_CHECK_ERROR_IMPL(IFACE, X) \ |
| 160 | if (gCheckErrorGL) \ |
| 161 | GrGLCheckErr(IFACE, GR_FILE_AND_LINE_STR, #X) |
| 162 | #else |
| 163 | #define GR_GL_CHECK_ERROR_IMPL(IFACE, X) |
| 164 | #endif |
| 165 | |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 166 | // 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] | 167 | // compile-time and run-time flags. |
| 168 | #if GR_GL_LOG_CALLS |
| 169 | extern bool gLogCallsGL; |
| 170 | #define GR_GL_LOG_CALLS_IMPL(X) \ |
| 171 | if (gLogCallsGL) \ |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 172 | SkDebugf(GR_FILE_AND_LINE_STR "GL: " #X "\n") |
bsalomon@google.com | 2717d56 | 2012-05-07 19:10:52 +0000 | [diff] [blame] | 173 | #else |
| 174 | #define GR_GL_LOG_CALLS_IMPL(X) |
| 175 | #endif |
| 176 | |
bsalomon@google.com | 2717d56 | 2012-05-07 19:10:52 +0000 | [diff] [blame] | 177 | // makes a GL call on the interface and does any error checking and logging |
| 178 | #define GR_GL_CALL(IFACE, X) \ |
| 179 | do { \ |
| 180 | GR_GL_CALL_NOERRCHECK(IFACE, X); \ |
| 181 | GR_GL_CHECK_ERROR_IMPL(IFACE, X); \ |
| 182 | } while (false) |
| 183 | |
| 184 | // Variant of above that always skips the error check. This is useful when |
| 185 | // the caller wants to do its own glGetError() call and examine the error value. |
| 186 | #define GR_GL_CALL_NOERRCHECK(IFACE, X) \ |
| 187 | do { \ |
commit-bot@chromium.org | c72425a | 2014-01-21 16:09:18 +0000 | [diff] [blame] | 188 | (IFACE)->fFunctions.f##X; \ |
bsalomon@google.com | 2717d56 | 2012-05-07 19:10:52 +0000 | [diff] [blame] | 189 | GR_GL_LOG_CALLS_IMPL(X); \ |
| 190 | } while (false) |
| 191 | |
| 192 | // same as GR_GL_CALL but stores the return value of the gl call in RET |
| 193 | #define GR_GL_CALL_RET(IFACE, RET, X) \ |
| 194 | do { \ |
| 195 | GR_GL_CALL_RET_NOERRCHECK(IFACE, RET, X); \ |
| 196 | GR_GL_CHECK_ERROR_IMPL(IFACE, X); \ |
| 197 | } while (false) |
| 198 | |
| 199 | // same as GR_GL_CALL_RET but always skips the error check. |
| 200 | #define GR_GL_CALL_RET_NOERRCHECK(IFACE, RET, X) \ |
| 201 | do { \ |
commit-bot@chromium.org | c72425a | 2014-01-21 16:09:18 +0000 | [diff] [blame] | 202 | (RET) = (IFACE)->fFunctions.f##X; \ |
bsalomon@google.com | 2717d56 | 2012-05-07 19:10:52 +0000 | [diff] [blame] | 203 | GR_GL_LOG_CALLS_IMPL(X); \ |
| 204 | } while (false) |
| 205 | |
| 206 | // call glGetError without doing a redundant error check or logging. |
commit-bot@chromium.org | c72425a | 2014-01-21 16:09:18 +0000 | [diff] [blame] | 207 | #define GR_GL_GET_ERROR(IFACE) (IFACE)->fFunctions.fGetError() |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 208 | |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 209 | GrGLenum GrToGLStencilFunc(GrStencilTest test); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 210 | |
| 211 | |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 212 | #endif |