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