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