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