| 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 | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 12 | |
| 13 | //////////////////////////////////////////////////////////////////////////////// |
| 14 | |
| 15 | typedef uint32_t GrGLVersion; |
| 16 | typedef uint32_t GrGLSLVersion; |
| 17 | |
| 18 | #define GR_GL_VER(major, minor) ((static_cast<int>(major) << 16) | \ |
| 19 | static_cast<int>(minor)) |
| 20 | #define GR_GLSL_VER(major, minor) ((static_cast<int>(major) << 16) | \ |
| 21 | static_cast<int>(minor)) |
| 22 | |
| 23 | //////////////////////////////////////////////////////////////////////////////// |
| 24 | |
| 25 | /** |
| 26 | * Some drivers want the var-int arg to be zero-initialized on input. |
| 27 | */ |
| 28 | #define GR_GL_INIT_ZERO 0 |
| 29 | #define GR_GL_GetIntegerv(gl, e, p) \ |
| 30 | do { \ |
| 31 | *(p) = GR_GL_INIT_ZERO; \ |
| 32 | GR_GL_CALL(gl, GetIntegerv(e, p)); \ |
| 33 | } while (0) |
| 34 | |
| 35 | #define GR_GL_GetFramebufferAttachmentParameteriv(gl, t, a, pname, p) \ |
| 36 | do { \ |
| 37 | *(p) = GR_GL_INIT_ZERO; \ |
| 38 | GR_GL_CALL(gl, GetFramebufferAttachmentParameteriv(t, a, pname, p)); \ |
| 39 | } while (0) |
| 40 | |
| 41 | #define GR_GL_GetRenderbufferParameteriv(gl, t, pname, p) \ |
| 42 | do { \ |
| 43 | *(p) = GR_GL_INIT_ZERO; \ |
| 44 | GR_GL_CALL(gl, GetRenderbufferParameteriv(t, pname, p)); \ |
| 45 | } while (0) |
| 46 | #define GR_GL_GetTexLevelParameteriv(gl, t, l, pname, p) \ |
| 47 | do { \ |
| 48 | *(p) = GR_GL_INIT_ZERO; \ |
| 49 | GR_GL_CALL(gl, GetTexLevelParameteriv(t, l, pname, p)); \ |
| 50 | } while (0) |
| 51 | |
| 52 | //////////////////////////////////////////////////////////////////////////////// |
| 53 | |
| 54 | /** |
| 55 | * Helpers for glGetString() |
| 56 | */ |
| 57 | |
| 58 | // these variants assume caller already has a string from glGetString() |
| 59 | GrGLVersion GrGLGetVersionFromString(const char* versionString); |
| 60 | GrGLBinding GrGLGetBindingInUseFromString(const char* versionString); |
| 61 | GrGLSLVersion GrGLGetGLSLVersionFromString(const char* versionString); |
| 62 | bool GrGLHasExtensionFromString(const char* ext, const char* extensionString); |
| 63 | |
| 64 | // these variants call glGetString() |
| 65 | bool GrGLHasExtension(const GrGLInterface*, const char* ext); |
| 66 | GrGLBinding GrGLGetBindingInUse(const GrGLInterface*); |
| 67 | GrGLVersion GrGLGetVersion(const GrGLInterface*); |
| 68 | GrGLSLVersion GrGLGetGLSLVersion(const GrGLInterface*); |
| 69 | |
| 70 | /** |
| 71 | * Helpers for glGetError() |
| 72 | */ |
| 73 | |
| 74 | extern void GrGLCheckErr(const GrGLInterface* gl, |
| 75 | const char* location, |
| 76 | const char* call); |
| 77 | |
| 78 | extern void GrGLClearErr(const GrGLInterface* gl); |
| 79 | |
| 80 | #endif |