blob: 0ff30344cdfc76ad0cbb1bf725d249f1047d0740 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
twiz@google.com59a190b2011-03-14 21:23:01 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
twiz@google.com59a190b2011-03-14 21:23:01 +00007 */
8
9
epoger@google.comec3ed6a2011-07-28 14:26:00 +000010
twiz@google.com59a190b2011-03-14 21:23:01 +000011#ifndef GrGLInterface_DEFINED
12#define GrGLInterface_DEFINED
13
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000014#include "GrGLConfig.h"
bsalomon@google.com0b77d682011-08-19 13:28:54 +000015#include "GrRefCnt.h"
twiz@google.com59a190b2011-03-14 21:23:01 +000016
17#if !defined(GR_GL_FUNCTION_TYPE)
18 #define GR_GL_FUNCTION_TYPE
19#endif
20
21////////////////////////////////////////////////////////////////////////////////
22
23/**
bsalomon@google.com89ec61e2012-02-10 20:05:18 +000024 * Classifies GL contexts (currently as Desktop vs. ES2). This is a bitfield.
25 * A GrGLInterface (defined below) may support multiple bindings.
26 */
27enum GrGLBinding {
28 kNone_GrGLBinding = 0x0,
29
30 kDesktop_GrGLBinding = 0x01,
31 kES2_GrGLBinding = 0x02,
32
33 // for iteration of GrGLBindings
bsalomon@google.comb447d212012-02-10 20:25:36 +000034 kFirstGrGLBinding = kDesktop_GrGLBinding,
bsalomon@google.com89ec61e2012-02-10 20:05:18 +000035 kLastGrGLBinding = kES2_GrGLBinding
36};
37
38////////////////////////////////////////////////////////////////////////////////
39
40/**
twiz@google.com59a190b2011-03-14 21:23:01 +000041 * Helpers for glGetString()
42 */
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000043
bsalomon@google.com4d062142011-09-22 14:31:24 +000044typedef uint32_t GrGLVersion;
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +000045typedef uint32_t GrGLSLVersion;
bsalomon@google.comc82b8892011-09-22 14:10:33 +000046
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +000047#define GR_GL_VER(major, minor) ((static_cast<int>(major) << 16) | \
48 static_cast<int>(minor))
49#define GR_GLSL_VER(major, minor) ((static_cast<int>(major) << 16) | \
50 static_cast<int>(minor))
bsalomon@google.comc82b8892011-09-22 14:10:33 +000051
bsalomon@google.com2c17fcd2011-07-06 17:47:02 +000052// these variants assume caller already has a string from glGetString()
bsalomon@google.comc82b8892011-09-22 14:10:33 +000053GrGLVersion GrGLGetVersionFromString(const char* versionString);
bsalomon@google.com89ec61e2012-02-10 20:05:18 +000054GrGLBinding GrGLGetBindingInUseFromString(const char* versionString);
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +000055GrGLSLVersion GrGLGetGLSLVersionFromString(const char* versionString);
bsalomon@google.comc82b8892011-09-22 14:10:33 +000056bool GrGLHasExtensionFromString(const char* ext, const char* extensionString);
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000057
bsalomon@google.com2c17fcd2011-07-06 17:47:02 +000058// these variants call glGetString()
bsalomon@google.com373a6632011-10-19 20:43:20 +000059bool GrGLHasExtension(const GrGLInterface*, const char* ext);
bsalomon@google.com89ec61e2012-02-10 20:05:18 +000060GrGLBinding GrGLGetBindingInUse(const GrGLInterface*);
bsalomon@google.comc82b8892011-09-22 14:10:33 +000061GrGLVersion GrGLGetVersion(const GrGLInterface*);
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +000062GrGLSLVersion GrGLGetGLSLVersion(const GrGLInterface*);
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000063
twiz@google.com59a190b2011-03-14 21:23:01 +000064////////////////////////////////////////////////////////////////////////////////
65
bsalomon@google.com0b77d682011-08-19 13:28:54 +000066/**
67 * Rather than depend on platform-specific GL headers and libraries, we require
68 * the client to provide a struct of GL function pointers. This struct can be
69 * specified per-GrContext as a parameter to GrContext::Create. If NULL is
70 * passed to Create then the "default" GL interface is used. If the default is
71 * also NULL GrContext creation will fail.
72 *
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000073 * The default interface is returned by GrGLDefaultInterface. This function's
robertphillips@google.com0da37192012-03-19 14:42:13 +000074 * implementation is platform-specific. Several have been provided, along with
75 * an implementation that simply returns NULL. It is implementation-specific
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000076 * whether the same GrGLInterface is returned or whether a new one is created
77 * at each call. Some platforms may not be able to use a single GrGLInterface
78 * because extension function ptrs vary across contexts. Note that GrGLInterface
79 * is ref-counted. So if the same object is returned by multiple calls to
80 * GrGLDefaultInterface, each should bump the ref count.
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +000081 *
82 * By defining GR_GL_PER_GL_CALL_IFACE_CALLBACK to 1 the client can specify a
83 * callback function that will be called prior to each GL function call. See
84 * comments in GrGLConfig.h
twiz@google.com59a190b2011-03-14 21:23:01 +000085 */
twiz@google.com59a190b2011-03-14 21:23:01 +000086
bsalomon@google.com0b77d682011-08-19 13:28:54 +000087struct GrGLInterface;
88
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000089const GrGLInterface* GrGLDefaultInterface();
twiz@google.com59a190b2011-03-14 21:23:01 +000090
bsalomon@google.com57f5d982011-10-24 21:17:53 +000091/**
92 * Creates a GrGLInterface for a "native" GL context (e.g. WGL on windows,
93 * GLX on linux, AGL on Mac). On platforms that have context-specific function
94 * pointers for GL extensions (e.g. windows) the returned interface is only
95 * valid for the context that was current at creation.
96 */
bsalomon@google.com373a6632011-10-19 20:43:20 +000097const GrGLInterface* GrGLCreateNativeInterface();
98
bsalomon@google.com57f5d982011-10-24 21:17:53 +000099/**
100 * Creates a GrGLInterface for an OSMesa context.
101 */
bsalomon@google.com373a6632011-10-19 20:43:20 +0000102const GrGLInterface* GrGLCreateMesaInterface();
103
bsalomon@google.com74913722011-10-27 20:44:19 +0000104/**
105 * Creates a null GrGLInterface that doesn't draw anything. Used for measuring
106 * CPU overhead.
107 */
108const GrGLInterface* GrGLCreateNullInterface();
109
robertphillips@google.com0da37192012-03-19 14:42:13 +0000110/**
111 * Creates a debugging GrGLInterface that doesn't draw anything. Used for
112 * finding memory leaks and invalid memory accesses.
113 */
114const GrGLInterface* GrGLCreateDebugInterface();
115
twiz@google.com0f31ca72011-03-18 17:38:11 +0000116typedef unsigned int GrGLenum;
117typedef unsigned char GrGLboolean;
118typedef unsigned int GrGLbitfield;
119typedef signed char GrGLbyte;
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000120typedef char GrGLchar;
twiz@google.com0f31ca72011-03-18 17:38:11 +0000121typedef short GrGLshort;
122typedef int GrGLint;
123typedef int GrGLsizei;
bsalomon@google.com373a6632011-10-19 20:43:20 +0000124typedef int64_t GrGLint64;
twiz@google.com0f31ca72011-03-18 17:38:11 +0000125typedef unsigned char GrGLubyte;
126typedef unsigned short GrGLushort;
127typedef unsigned int GrGLuint;
bsalomon@google.com373a6632011-10-19 20:43:20 +0000128typedef uint64_t GrGLuint64;
twiz@google.com0f31ca72011-03-18 17:38:11 +0000129typedef float GrGLfloat;
130typedef float GrGLclampf;
131typedef double GrGLdouble;
132typedef double GrGLclampd;
133typedef void GrGLvoid;
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000134typedef long GrGLintptr;
135typedef long GrGLsizeiptr;
twiz@google.com0f31ca72011-03-18 17:38:11 +0000136
twiz@google.com59a190b2011-03-14 21:23:01 +0000137extern "C" {
twiz@google.com0f31ca72011-03-18 17:38:11 +0000138 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLActiveTextureProc)(GrGLenum texture);
139 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLAttachShaderProc)(GrGLuint program, GrGLuint shader);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000140 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBeginQueryProc)(GrGLenum target, GrGLuint id);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000141 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindAttribLocationProc)(GrGLuint program, GrGLuint index, const char* name);
142 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindBufferProc)(GrGLenum target, GrGLuint buffer);
143 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindTextureProc)(GrGLenum target, GrGLuint texture);
144 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBlendColorProc)(GrGLclampf red, GrGLclampf green, GrGLclampf blue, GrGLclampf alpha);
bsalomon@google.combc5cf512011-09-21 16:21:07 +0000145 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindFragDataLocationProc)(GrGLuint program, GrGLuint colorNumber, const GrGLchar* name);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000146 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBlendFuncProc)(GrGLenum sfactor, GrGLenum dfactor);
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000147 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBufferDataProc)(GrGLenum target, GrGLsizeiptr size, const GrGLvoid* data, GrGLenum usage);
148 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBufferSubDataProc)(GrGLenum target, GrGLintptr offset, GrGLsizeiptr size, const GrGLvoid* data);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000149 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClearProc)(GrGLbitfield mask);
150 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClearColorProc)(GrGLclampf red, GrGLclampf green, GrGLclampf blue, GrGLclampf alpha);
151 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClearStencilProc)(GrGLint s);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000152 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLColorMaskProc)(GrGLboolean red, GrGLboolean green, GrGLboolean blue, GrGLboolean alpha);
153 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLColorPointerProc)(GrGLint size, GrGLenum type, GrGLsizei stride, const GrGLvoid* pointer);
154 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLCompileShaderProc)(GrGLuint shader);
155 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLCompressedTexImage2DProc)(GrGLenum target, GrGLint level, GrGLenum internalformat, GrGLsizei width, GrGLsizei height, GrGLint border, GrGLsizei imageSize, const GrGLvoid* data);
156 typedef GrGLuint (GR_GL_FUNCTION_TYPE *GrGLCreateProgramProc)(void);
157 typedef GrGLuint (GR_GL_FUNCTION_TYPE *GrGLCreateShaderProc)(GrGLenum type);
158 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLCullFaceProc)(GrGLenum mode);
159 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteBuffersProc)(GrGLsizei n, const GrGLuint* buffers);
160 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteProgramProc)(GrGLuint program);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000161 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteQueriesProc)(GrGLsizei n, const GrGLuint *ids);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000162 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteShaderProc)(GrGLuint shader);
163 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteTexturesProc)(GrGLsizei n, const GrGLuint* textures);
164 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDepthMaskProc)(GrGLboolean flag);
165 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDisableProc)(GrGLenum cap);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000166 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDisableVertexAttribArrayProc)(GrGLuint index);
167 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawArraysProc)(GrGLenum mode, GrGLint first, GrGLsizei count);
bsalomon@google.comd32c5f52011-08-02 19:29:03 +0000168 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawBufferProc)(GrGLenum mode);
169 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawBuffersProc)(GrGLsizei n, const GrGLenum* bufs);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000170 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawElementsProc)(GrGLenum mode, GrGLsizei count, GrGLenum type, const GrGLvoid* indices);
171 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLEnableProc)(GrGLenum cap);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000172 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLEnableVertexAttribArrayProc)(GrGLuint index);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000173 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLEndQueryProc)(GrGLenum target);
174 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFinishProc)();
175 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFlushProc)();
twiz@google.com0f31ca72011-03-18 17:38:11 +0000176 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFrontFaceProc)(GrGLenum mode);
177 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenBuffersProc)(GrGLsizei n, GrGLuint* buffers);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000178 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenQueriesProc)(GrGLsizei n, GrGLuint *ids);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000179 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenTexturesProc)(GrGLsizei n, GrGLuint* textures);
180 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetBufferParameterivProc)(GrGLenum target, GrGLenum pname, GrGLint* params);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000181 typedef GrGLenum (GR_GL_FUNCTION_TYPE *GrGLGetErrorProc)();
twiz@google.com0f31ca72011-03-18 17:38:11 +0000182 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetIntegervProc)(GrGLenum pname, GrGLint* params);
183 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetProgramInfoLogProc)(GrGLuint program, GrGLsizei bufsize, GrGLsizei* length, char* infolog);
184 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetProgramivProc)(GrGLuint program, GrGLenum pname, GrGLint* params);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000185 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetQueryivProc)(GrGLenum GLtarget, GrGLenum pname, GrGLint *params);
186 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetQueryObjecti64vProc)(GrGLuint id, GrGLenum pname, GrGLint64 *params);
187 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetQueryObjectivProc)(GrGLuint id, GrGLenum pname, GrGLint *params);
188 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetQueryObjectui64vProc)(GrGLuint id, GrGLenum pname, GrGLuint64 *params);
189 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetQueryObjectuivProc)(GrGLuint id, GrGLenum pname, GrGLuint *params);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000190 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetShaderInfoLogProc)(GrGLuint shader, GrGLsizei bufsize, GrGLsizei* length, char* infolog);
191 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetShaderivProc)(GrGLuint shader, GrGLenum pname, GrGLint* params);
192 typedef const GrGLubyte* (GR_GL_FUNCTION_TYPE *GrGLGetStringProc)(GrGLenum name);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000193 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetTexLevelParameterivProc)(GrGLenum target, GrGLint level, GrGLenum pname, GrGLint* params);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000194 typedef GrGLint (GR_GL_FUNCTION_TYPE *GrGLGetUniformLocationProc)(GrGLuint program, const char* name);
195 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLLineWidthProc)(GrGLfloat width);
196 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLLinkProgramProc)(GrGLuint program);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000197 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLPixelStoreiProc)(GrGLenum pname, GrGLint param);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000198 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLQueryCounterProc)(GrGLuint id, GrGLenum target);
bsalomon@google.comc49d66b2011-08-03 14:22:30 +0000199 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLReadBufferProc)(GrGLenum src);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000200 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLReadPixelsProc)(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height, GrGLenum format, GrGLenum type, GrGLvoid* pixels);
201 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLScissorProc)(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000202 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLShaderSourceProc)(GrGLuint shader, GrGLsizei count, const char** str, const GrGLint* length);
203 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilFuncProc)(GrGLenum func, GrGLint ref, GrGLuint mask);
204 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilFuncSeparateProc)(GrGLenum face, GrGLenum func, GrGLint ref, GrGLuint mask);
205 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilMaskProc)(GrGLuint mask);
206 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilMaskSeparateProc)(GrGLenum face, GrGLuint mask);
207 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilOpProc)(GrGLenum fail, GrGLenum zfail, GrGLenum zpass);
208 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilOpSeparateProc)(GrGLenum face, GrGLenum fail, GrGLenum zfail, GrGLenum zpass);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000209 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexImage2DProc)(GrGLenum target, GrGLint level, GrGLint internalformat, GrGLsizei width, GrGLsizei height, GrGLint border, GrGLenum format, GrGLenum type, const GrGLvoid* pixels);
210 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexParameteriProc)(GrGLenum target, GrGLenum pname, GrGLint param);
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000211 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexStorage2DProc)(GrGLenum target, GrGLsizei levels, GrGLenum internalformat, GrGLsizei width, GrGLsizei height);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000212 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexSubImage2DProc)(GrGLenum target, GrGLint level, GrGLint xoffset, GrGLint yoffset, GrGLsizei width, GrGLsizei height, GrGLenum format, GrGLenum type, const GrGLvoid* pixels);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000213 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1fProc)(GrGLint location, GrGLfloat v0);
214 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1iProc)(GrGLint location, GrGLint v0);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000215 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1fvProc)(GrGLint location, GrGLsizei count, const GrGLfloat* v);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000216 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1ivProc)(GrGLint location, GrGLsizei count, const GrGLint* v);
217 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform2fProc)(GrGLint location, GrGLfloat v0, GrGLfloat v1);
218 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform2iProc)(GrGLint location, GrGLint v0, GrGLint v1);
219 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform2fvProc)(GrGLint location, GrGLsizei count, const GrGLfloat* v);
220 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform2ivProc)(GrGLint location, GrGLsizei count, const GrGLint* v);
221 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform3fProc)(GrGLint location, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2);
222 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform3iProc)(GrGLint location, GrGLint v0, GrGLint v1, GrGLint v2);
223 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform3fvProc)(GrGLint location, GrGLsizei count, const GrGLfloat* v);
224 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform3ivProc)(GrGLint location, GrGLsizei count, const GrGLint* v);
225 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform4fProc)(GrGLint location, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2, GrGLfloat v3);
226 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform4iProc)(GrGLint location, GrGLint v0, GrGLint v1, GrGLint v2, GrGLint v3);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000227 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform4fvProc)(GrGLint location, GrGLsizei count, const GrGLfloat* v);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000228 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform4ivProc)(GrGLint location, GrGLsizei count, const GrGLint* v);
229 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniformMatrix2fvProc)(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000230 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniformMatrix3fvProc)(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000231 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniformMatrix4fvProc)(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000232 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUseProgramProc)(GrGLuint program);
233 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLVertexAttrib4fvProc)(GrGLuint indx, const GrGLfloat* values);
234 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLVertexAttribPointerProc)(GrGLuint indx, GrGLint size, GrGLenum type, GrGLboolean normalized, GrGLsizei stride, const GrGLvoid* ptr);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000235 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLViewportProc)(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height);
twiz@google.com59a190b2011-03-14 21:23:01 +0000236
237 // FBO Extension Functions
twiz@google.com0f31ca72011-03-18 17:38:11 +0000238 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindFramebufferProc)(GrGLenum target, GrGLuint framebuffer);
239 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindRenderbufferProc)(GrGLenum target, GrGLuint renderbuffer);
240 typedef GrGLenum (GR_GL_FUNCTION_TYPE *GrGLCheckFramebufferStatusProc)(GrGLenum target);
241 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteFramebuffersProc)(GrGLsizei n, const GrGLuint *framebuffers);
242 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteRenderbuffersProc)(GrGLsizei n, const GrGLuint *renderbuffers);
243 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFramebufferRenderbufferProc)(GrGLenum target, GrGLenum attachment, GrGLenum renderbuffertarget, GrGLuint renderbuffer);
244 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFramebufferTexture2DProc)(GrGLenum target, GrGLenum attachment, GrGLenum textarget, GrGLuint texture, GrGLint level);
245 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenFramebuffersProc)(GrGLsizei n, GrGLuint *framebuffers);
246 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenRenderbuffersProc)(GrGLsizei n, GrGLuint *renderbuffers);
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000247 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetFramebufferAttachmentParameterivProc)(GrGLenum target, GrGLenum attachment, GrGLenum pname, GrGLint* params);
248 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetRenderbufferParameterivProc)(GrGLenum target, GrGLenum pname, GrGLint* params);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000249 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLRenderbufferStorageProc)(GrGLenum target, GrGLenum internalformat, GrGLsizei width, GrGLsizei height);
twiz@google.com59a190b2011-03-14 21:23:01 +0000250
251 // Multisampling Extension Functions
252 // same prototype for ARB_FBO, EXT_FBO, GL 3.0, & Apple ES extension
twiz@google.com0f31ca72011-03-18 17:38:11 +0000253 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLRenderbufferStorageMultisampleProc)(GrGLenum target, GrGLsizei samples, GrGLenum internalformat, GrGLsizei width, GrGLsizei height);
twiz@google.com59a190b2011-03-14 21:23:01 +0000254 // desktop: ext_fbo_blit, arb_fbo, gl 3.0
twiz@google.com0f31ca72011-03-18 17:38:11 +0000255 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBlitFramebufferProc)(GrGLint srcX0, GrGLint srcY0, GrGLint srcX1, GrGLint srcY1, GrGLint dstX0, GrGLint dstY0, GrGLint dstX1, GrGLint dstY1, GrGLbitfield mask, GrGLenum filter);
twiz@google.com59a190b2011-03-14 21:23:01 +0000256 // apple's es extension
twiz@google.com0f31ca72011-03-18 17:38:11 +0000257 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLResolveMultisampleFramebufferProc)();
twiz@google.com59a190b2011-03-14 21:23:01 +0000258
twiz@google.com59a190b2011-03-14 21:23:01 +0000259 // Buffer mapping (extension in ES).
twiz@google.com0f31ca72011-03-18 17:38:11 +0000260 typedef GrGLvoid* (GR_GL_FUNCTION_TYPE *GrGLMapBufferProc)(GrGLenum target, GrGLenum access);
261 typedef GrGLboolean (GR_GL_FUNCTION_TYPE *GrGLUnmapBufferProc)(GrGLenum target);
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000262
263 // Dual source blending
264 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindFragDataLocationIndexedProc)(GrGLuint program, GrGLuint colorNumber, GrGLuint index, const GrGLchar * name);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000265} // extern "C"
266
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +0000267#if GR_GL_PER_GL_FUNC_CALLBACK
268typedef void (*GrGLInterfaceCallbackProc)(const GrGLInterface*);
269typedef intptr_t GrGLInterfaceCallbackData;
270#endif
271
272
tomhudson@google.come67bd3f2011-06-16 14:08:04 +0000273enum GrGLCapability {
274 kProbe_GrGLCapability = -1
tomhudson@google.com30e4bb62011-06-15 19:41:46 +0000275};
276
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000277/*
278 * The following interface exports the OpenGL entry points used by the system.
279 * Use of OpenGL calls is disallowed. All calls should be invoked through
280 * the global instance of this struct, defined above.
281 *
282 * IMPORTANT NOTE: The OpenGL entry points exposed here include both core GL
283 * functions, and extensions. The system assumes that the address of the
284 * extension pointer will be valid across contexts.
285 */
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000286struct GR_API GrGLInterface : public GrRefCnt {
287
288 GrGLInterface();
289
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000290 // Validates that the GrGLInterface supports a binding. This means that
291 // the GrGLinterface advertises the binding in fBindingsExported and all
292 // the necessary function pointers have been initialized.
293 bool validate(GrGLBinding binding) const;
294
twiz@google.comb65e0cb2011-03-18 20:41:44 +0000295 // Indicator variable specifying the type of GL implementation
296 // exported: GLES{1|2} or Desktop.
297 GrGLBinding fBindingsExported;
298
twiz@google.com59a190b2011-03-14 21:23:01 +0000299 GrGLActiveTextureProc fActiveTexture;
300 GrGLAttachShaderProc fAttachShader;
bsalomon@google.com373a6632011-10-19 20:43:20 +0000301 GrGLBeginQueryProc fBeginQuery;
twiz@google.com59a190b2011-03-14 21:23:01 +0000302 GrGLBindAttribLocationProc fBindAttribLocation;
303 GrGLBindBufferProc fBindBuffer;
bsalomon@google.combc5cf512011-09-21 16:21:07 +0000304 GrGLBindFragDataLocationProc fBindFragDataLocation;
twiz@google.com59a190b2011-03-14 21:23:01 +0000305 GrGLBindTextureProc fBindTexture;
bsalomon@google.com080773c2011-03-15 19:09:25 +0000306 GrGLBlendColorProc fBlendColor;
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000307 GrGLBlendFuncProc fBlendFunc;
twiz@google.com59a190b2011-03-14 21:23:01 +0000308 GrGLBufferDataProc fBufferData;
309 GrGLBufferSubDataProc fBufferSubData;
310 GrGLClearProc fClear;
311 GrGLClearColorProc fClearColor;
312 GrGLClearStencilProc fClearStencil;
twiz@google.com59a190b2011-03-14 21:23:01 +0000313 GrGLColorMaskProc fColorMask;
314 GrGLColorPointerProc fColorPointer;
315 GrGLCompileShaderProc fCompileShader;
316 GrGLCompressedTexImage2DProc fCompressedTexImage2D;
317 GrGLCreateProgramProc fCreateProgram;
318 GrGLCreateShaderProc fCreateShader;
319 GrGLCullFaceProc fCullFace;
320 GrGLDeleteBuffersProc fDeleteBuffers;
321 GrGLDeleteProgramProc fDeleteProgram;
bsalomon@google.com373a6632011-10-19 20:43:20 +0000322 GrGLDeleteQueriesProc fDeleteQueries;
twiz@google.com59a190b2011-03-14 21:23:01 +0000323 GrGLDeleteShaderProc fDeleteShader;
324 GrGLDeleteTexturesProc fDeleteTextures;
325 GrGLDepthMaskProc fDepthMask;
326 GrGLDisableProc fDisable;
twiz@google.com59a190b2011-03-14 21:23:01 +0000327 GrGLDisableVertexAttribArrayProc fDisableVertexAttribArray;
328 GrGLDrawArraysProc fDrawArrays;
bsalomon@google.comd32c5f52011-08-02 19:29:03 +0000329 GrGLDrawBufferProc fDrawBuffer;
330 GrGLDrawBuffersProc fDrawBuffers;
twiz@google.com59a190b2011-03-14 21:23:01 +0000331 GrGLDrawElementsProc fDrawElements;
332 GrGLEnableProc fEnable;
twiz@google.com59a190b2011-03-14 21:23:01 +0000333 GrGLEnableVertexAttribArrayProc fEnableVertexAttribArray;
bsalomon@google.com373a6632011-10-19 20:43:20 +0000334 GrGLEndQueryProc fEndQuery;
335 GrGLFinishProc fFinish;
336 GrGLFlushProc fFlush;
twiz@google.com59a190b2011-03-14 21:23:01 +0000337 GrGLFrontFaceProc fFrontFace;
338 GrGLGenBuffersProc fGenBuffers;
bsalomon@google.com373a6632011-10-19 20:43:20 +0000339 GrGLGenQueriesProc fGenQueries;
twiz@google.com59a190b2011-03-14 21:23:01 +0000340 GrGLGenTexturesProc fGenTextures;
341 GrGLGetBufferParameterivProc fGetBufferParameteriv;
342 GrGLGetErrorProc fGetError;
343 GrGLGetIntegervProc fGetIntegerv;
bsalomon@google.com373a6632011-10-19 20:43:20 +0000344 GrGLGetQueryObjecti64vProc fGetQueryObjecti64v;
345 GrGLGetQueryObjectivProc fGetQueryObjectiv;
346 GrGLGetQueryObjectui64vProc fGetQueryObjectui64v;
347 GrGLGetQueryObjectuivProc fGetQueryObjectuiv;
348 GrGLGetQueryivProc fGetQueryiv;
twiz@google.com59a190b2011-03-14 21:23:01 +0000349 GrGLGetProgramInfoLogProc fGetProgramInfoLog;
350 GrGLGetProgramivProc fGetProgramiv;
351 GrGLGetShaderInfoLogProc fGetShaderInfoLog;
352 GrGLGetShaderivProc fGetShaderiv;
353 GrGLGetStringProc fGetString;
bsalomon@google.com373a6632011-10-19 20:43:20 +0000354 GrGLGetTexLevelParameterivProc fGetTexLevelParameteriv;
twiz@google.com59a190b2011-03-14 21:23:01 +0000355 GrGLGetUniformLocationProc fGetUniformLocation;
356 GrGLLineWidthProc fLineWidth;
357 GrGLLinkProgramProc fLinkProgram;
twiz@google.com59a190b2011-03-14 21:23:01 +0000358 GrGLPixelStoreiProc fPixelStorei;
bsalomon@google.com373a6632011-10-19 20:43:20 +0000359 GrGLQueryCounterProc fQueryCounter;
bsalomon@google.comc49d66b2011-08-03 14:22:30 +0000360 GrGLReadBufferProc fReadBuffer;
twiz@google.com59a190b2011-03-14 21:23:01 +0000361 GrGLReadPixelsProc fReadPixels;
362 GrGLScissorProc fScissor;
twiz@google.com59a190b2011-03-14 21:23:01 +0000363 GrGLShaderSourceProc fShaderSource;
364 GrGLStencilFuncProc fStencilFunc;
365 GrGLStencilFuncSeparateProc fStencilFuncSeparate;
366 GrGLStencilMaskProc fStencilMask;
367 GrGLStencilMaskSeparateProc fStencilMaskSeparate;
368 GrGLStencilOpProc fStencilOp;
369 GrGLStencilOpSeparateProc fStencilOpSeparate;
twiz@google.com59a190b2011-03-14 21:23:01 +0000370 GrGLTexImage2DProc fTexImage2D;
371 GrGLTexParameteriProc fTexParameteri;
372 GrGLTexSubImage2DProc fTexSubImage2D;
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000373 GrGLTexStorage2DProc fTexStorage2D;
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000374 GrGLUniform1fProc fUniform1f;
twiz@google.com59a190b2011-03-14 21:23:01 +0000375 GrGLUniform1iProc fUniform1i;
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000376 GrGLUniform1fvProc fUniform1fv;
377 GrGLUniform1ivProc fUniform1iv;
378 GrGLUniform2fProc fUniform2f;
379 GrGLUniform2iProc fUniform2i;
380 GrGLUniform2fvProc fUniform2fv;
381 GrGLUniform2ivProc fUniform2iv;
382 GrGLUniform3fProc fUniform3f;
383 GrGLUniform3iProc fUniform3i;
384 GrGLUniform3fvProc fUniform3fv;
385 GrGLUniform3ivProc fUniform3iv;
386 GrGLUniform4fProc fUniform4f;
387 GrGLUniform4iProc fUniform4i;
twiz@google.com59a190b2011-03-14 21:23:01 +0000388 GrGLUniform4fvProc fUniform4fv;
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000389 GrGLUniform4ivProc fUniform4iv;
390 GrGLUniformMatrix2fvProc fUniformMatrix2fv;
twiz@google.com59a190b2011-03-14 21:23:01 +0000391 GrGLUniformMatrix3fvProc fUniformMatrix3fv;
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000392 GrGLUniformMatrix4fvProc fUniformMatrix4fv;
twiz@google.com59a190b2011-03-14 21:23:01 +0000393 GrGLUseProgramProc fUseProgram;
394 GrGLVertexAttrib4fvProc fVertexAttrib4fv;
395 GrGLVertexAttribPointerProc fVertexAttribPointer;
twiz@google.com59a190b2011-03-14 21:23:01 +0000396 GrGLViewportProc fViewport;
397
398 // FBO Extension Functions
399 GrGLBindFramebufferProc fBindFramebuffer;
400 GrGLBindRenderbufferProc fBindRenderbuffer;
401 GrGLCheckFramebufferStatusProc fCheckFramebufferStatus;
402 GrGLDeleteFramebuffersProc fDeleteFramebuffers;
403 GrGLDeleteRenderbuffersProc fDeleteRenderbuffers;
404 GrGLFramebufferRenderbufferProc fFramebufferRenderbuffer;
405 GrGLFramebufferTexture2DProc fFramebufferTexture2D;
406 GrGLGenFramebuffersProc fGenFramebuffers;
407 GrGLGenRenderbuffersProc fGenRenderbuffers;
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000408 GrGLGetFramebufferAttachmentParameterivProc fGetFramebufferAttachmentParameteriv;
409 GrGLGetRenderbufferParameterivProc fGetRenderbufferParameteriv;
twiz@google.com59a190b2011-03-14 21:23:01 +0000410 GrGLRenderbufferStorageProc fRenderbufferStorage;
411
412 // Multisampling Extension Functions
413 // same prototype for ARB_FBO, EXT_FBO, GL 3.0, & Apple ES extension
414 GrGLRenderbufferStorageMultisampleProc fRenderbufferStorageMultisample;
415 // desktop: ext_fbo_blit, arb_fbo, gl 3.0
416 GrGLBlitFramebufferProc fBlitFramebuffer;
417 // apple's es extension
418 GrGLResolveMultisampleFramebufferProc fResolveMultisampleFramebuffer;
419
twiz@google.com59a190b2011-03-14 21:23:01 +0000420 // Buffer mapping (extension in ES).
421 GrGLMapBufferProc fMapBuffer;
422 GrGLUnmapBufferProc fUnmapBuffer;
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000423
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000424 // Dual Source Blending
425 GrGLBindFragDataLocationIndexedProc fBindFragDataLocationIndexed;
426
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +0000427 // Per-GL func callback
428#if GR_GL_PER_GL_FUNC_CALLBACK
429 GrGLInterfaceCallbackProc fCallback;
430 GrGLInterfaceCallbackData fCallbackData;
431#endif
432
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000433};
twiz@google.com59a190b2011-03-14 21:23:01 +0000434
435#endif