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