| 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" |
| bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 13 | |
| 14 | //////////////////////////////////////////////////////////////////////////////// |
| 15 | |
| 16 | typedef uint32_t GrGLVersion; |
| 17 | typedef uint32_t GrGLSLVersion; |
| 18 | |
| bsalomon@google.com | 0b1e481 | 2012-10-23 13:52:43 +0000 | [diff] [blame] | 19 | /** |
| 20 | * This list is lazily updated as required. |
| 21 | */ |
| 22 | enum GrGLVendor { |
| bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame] | 23 | kARM_GrGLVendor, |
| bsalomon@google.com | 3012ded | 2013-02-22 16:44:04 +0000 | [diff] [blame] | 24 | kImagination_GrGLVendor, |
| 25 | kIntel_GrGLVendor, |
| commit-bot@chromium.org | 7a434a2 | 2013-08-21 14:01:56 +0000 | [diff] [blame^] | 26 | kQualcomm_GrGLVendor, |
| bsalomon@google.com | 3012ded | 2013-02-22 16:44:04 +0000 | [diff] [blame] | 27 | |
| 28 | kOther_GrGLVendor |
| bsalomon@google.com | 0b1e481 | 2012-10-23 13:52:43 +0000 | [diff] [blame] | 29 | }; |
| 30 | |
| bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 31 | #define GR_GL_VER(major, minor) ((static_cast<int>(major) << 16) | \ |
| 32 | static_cast<int>(minor)) |
| 33 | #define GR_GLSL_VER(major, minor) ((static_cast<int>(major) << 16) | \ |
| 34 | static_cast<int>(minor)) |
| 35 | |
| 36 | //////////////////////////////////////////////////////////////////////////////// |
| 37 | |
| 38 | /** |
| 39 | * Some drivers want the var-int arg to be zero-initialized on input. |
| 40 | */ |
| 41 | #define GR_GL_INIT_ZERO 0 |
| 42 | #define GR_GL_GetIntegerv(gl, e, p) \ |
| 43 | do { \ |
| 44 | *(p) = GR_GL_INIT_ZERO; \ |
| 45 | GR_GL_CALL(gl, GetIntegerv(e, p)); \ |
| 46 | } while (0) |
| 47 | |
| 48 | #define GR_GL_GetFramebufferAttachmentParameteriv(gl, t, a, pname, p) \ |
| 49 | do { \ |
| 50 | *(p) = GR_GL_INIT_ZERO; \ |
| 51 | GR_GL_CALL(gl, GetFramebufferAttachmentParameteriv(t, a, pname, p)); \ |
| 52 | } while (0) |
| 53 | |
| 54 | #define GR_GL_GetRenderbufferParameteriv(gl, t, pname, p) \ |
| 55 | do { \ |
| 56 | *(p) = GR_GL_INIT_ZERO; \ |
| 57 | GR_GL_CALL(gl, GetRenderbufferParameteriv(t, pname, p)); \ |
| 58 | } while (0) |
| 59 | #define GR_GL_GetTexLevelParameteriv(gl, t, l, pname, p) \ |
| 60 | do { \ |
| 61 | *(p) = GR_GL_INIT_ZERO; \ |
| 62 | GR_GL_CALL(gl, GetTexLevelParameteriv(t, l, pname, p)); \ |
| 63 | } while (0) |
| 64 | |
| 65 | //////////////////////////////////////////////////////////////////////////////// |
| 66 | |
| 67 | /** |
| 68 | * Helpers for glGetString() |
| 69 | */ |
| 70 | |
| 71 | // these variants assume caller already has a string from glGetString() |
| 72 | GrGLVersion GrGLGetVersionFromString(const char* versionString); |
| 73 | GrGLBinding GrGLGetBindingInUseFromString(const char* versionString); |
| 74 | GrGLSLVersion GrGLGetGLSLVersionFromString(const char* versionString); |
| commit-bot@chromium.org | 459104c | 2013-06-14 14:42:56 +0000 | [diff] [blame] | 75 | bool GrGLIsMesaFromVersionString(const char* versionString); |
| bsalomon@google.com | 0b1e481 | 2012-10-23 13:52:43 +0000 | [diff] [blame] | 76 | GrGLVendor GrGLGetVendorFromString(const char* vendorString); |
| bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 77 | |
| 78 | // these variants call glGetString() |
| bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 79 | GrGLBinding GrGLGetBindingInUse(const GrGLInterface*); |
| 80 | GrGLVersion GrGLGetVersion(const GrGLInterface*); |
| 81 | GrGLSLVersion GrGLGetGLSLVersion(const GrGLInterface*); |
| bsalomon@google.com | 0b1e481 | 2012-10-23 13:52:43 +0000 | [diff] [blame] | 82 | GrGLVendor GrGLGetVendor(const GrGLInterface*); |
| bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 83 | |
| 84 | /** |
| 85 | * Helpers for glGetError() |
| 86 | */ |
| 87 | |
| bsalomon@google.com | 2717d56 | 2012-05-07 19:10:52 +0000 | [diff] [blame] | 88 | void GrGLCheckErr(const GrGLInterface* gl, |
| 89 | const char* location, |
| 90 | const char* call); |
| bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 91 | |
| bsalomon@google.com | 2717d56 | 2012-05-07 19:10:52 +0000 | [diff] [blame] | 92 | void GrGLClearErr(const GrGLInterface* gl); |
| 93 | |
| 94 | //////////////////////////////////////////////////////////////////////////////// |
| 95 | |
| 96 | /** |
| 97 | * Macros for using GrGLInterface to make GL calls |
| 98 | */ |
| 99 | |
| 100 | // internal macro to conditionally call glGetError based on compile-time and |
| 101 | // run-time flags. |
| 102 | #if GR_GL_CHECK_ERROR |
| 103 | extern bool gCheckErrorGL; |
| 104 | #define GR_GL_CHECK_ERROR_IMPL(IFACE, X) \ |
| 105 | if (gCheckErrorGL) \ |
| 106 | GrGLCheckErr(IFACE, GR_FILE_AND_LINE_STR, #X) |
| 107 | #else |
| 108 | #define GR_GL_CHECK_ERROR_IMPL(IFACE, X) |
| 109 | #endif |
| 110 | |
| 111 | // internal macro to conditionally log the gl call using GrPrintf based on |
| 112 | // compile-time and run-time flags. |
| 113 | #if GR_GL_LOG_CALLS |
| 114 | extern bool gLogCallsGL; |
| 115 | #define GR_GL_LOG_CALLS_IMPL(X) \ |
| 116 | if (gLogCallsGL) \ |
| 117 | GrPrintf(GR_FILE_AND_LINE_STR "GL: " #X "\n") |
| 118 | #else |
| 119 | #define GR_GL_LOG_CALLS_IMPL(X) |
| 120 | #endif |
| 121 | |
| 122 | // internal macro that does the per-GL-call callback (if necessary) |
| 123 | #if GR_GL_PER_GL_FUNC_CALLBACK |
| 124 | #define GR_GL_CALLBACK_IMPL(IFACE) (IFACE)->fCallback(IFACE) |
| 125 | #else |
| 126 | #define GR_GL_CALLBACK_IMPL(IFACE) |
| 127 | #endif |
| 128 | |
| 129 | // makes a GL call on the interface and does any error checking and logging |
| 130 | #define GR_GL_CALL(IFACE, X) \ |
| 131 | do { \ |
| 132 | GR_GL_CALL_NOERRCHECK(IFACE, X); \ |
| 133 | GR_GL_CHECK_ERROR_IMPL(IFACE, X); \ |
| 134 | } while (false) |
| 135 | |
| 136 | // Variant of above that always skips the error check. This is useful when |
| 137 | // the caller wants to do its own glGetError() call and examine the error value. |
| 138 | #define GR_GL_CALL_NOERRCHECK(IFACE, X) \ |
| 139 | do { \ |
| 140 | GR_GL_CALLBACK_IMPL(IFACE); \ |
| 141 | (IFACE)->f##X; \ |
| 142 | GR_GL_LOG_CALLS_IMPL(X); \ |
| 143 | } while (false) |
| 144 | |
| 145 | // same as GR_GL_CALL but stores the return value of the gl call in RET |
| 146 | #define GR_GL_CALL_RET(IFACE, RET, X) \ |
| 147 | do { \ |
| 148 | GR_GL_CALL_RET_NOERRCHECK(IFACE, RET, X); \ |
| 149 | GR_GL_CHECK_ERROR_IMPL(IFACE, X); \ |
| 150 | } while (false) |
| 151 | |
| 152 | // same as GR_GL_CALL_RET but always skips the error check. |
| 153 | #define GR_GL_CALL_RET_NOERRCHECK(IFACE, RET, X) \ |
| 154 | do { \ |
| 155 | GR_GL_CALLBACK_IMPL(IFACE); \ |
| 156 | (RET) = (IFACE)->f##X; \ |
| 157 | GR_GL_LOG_CALLS_IMPL(X); \ |
| 158 | } while (false) |
| 159 | |
| 160 | // call glGetError without doing a redundant error check or logging. |
| 161 | #define GR_GL_GET_ERROR(IFACE) (IFACE)->fGetError() |
| bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 162 | |
| 163 | #endif |