blob: 20b74ab21a7b8c43290535932240029892f22de1 [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/**
24 * Helpers for glGetString()
25 */
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000026
bsalomon@google.com4d062142011-09-22 14:31:24 +000027typedef uint32_t GrGLVersion;
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +000028typedef uint32_t GrGLSLVersion;
bsalomon@google.comc82b8892011-09-22 14:10:33 +000029
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +000030#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))
bsalomon@google.comc82b8892011-09-22 14:10:33 +000034
bsalomon@google.com2c17fcd2011-07-06 17:47:02 +000035// these variants assume caller already has a string from glGetString()
bsalomon@google.comc82b8892011-09-22 14:10:33 +000036GrGLVersion GrGLGetVersionFromString(const char* versionString);
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +000037GrGLSLVersion GrGLGetGLSLVersionFromString(const char* versionString);
bsalomon@google.comc82b8892011-09-22 14:10:33 +000038bool GrGLHasExtensionFromString(const char* ext, const char* extensionString);
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000039
bsalomon@google.com2c17fcd2011-07-06 17:47:02 +000040// these variants call glGetString()
bsalomon@google.com373a6632011-10-19 20:43:20 +000041bool GrGLHasExtension(const GrGLInterface*, const char* ext);
bsalomon@google.comc82b8892011-09-22 14:10:33 +000042GrGLVersion GrGLGetVersion(const GrGLInterface*);
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +000043GrGLSLVersion GrGLGetGLSLVersion(const GrGLInterface*);
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000044
twiz@google.com59a190b2011-03-14 21:23:01 +000045////////////////////////////////////////////////////////////////////////////////
46
bsalomon@google.com0b77d682011-08-19 13:28:54 +000047/**
48 * Rather than depend on platform-specific GL headers and libraries, we require
49 * the client to provide a struct of GL function pointers. This struct can be
50 * specified per-GrContext as a parameter to GrContext::Create. If NULL is
51 * passed to Create then the "default" GL interface is used. If the default is
52 * also NULL GrContext creation will fail.
53 *
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000054 * The default interface is returned by GrGLDefaultInterface. This function's
55 * implementation is platform-specifc. Several have been provided, along with an
56 * implementation that simply returns NULL. It is implementation-specific
57 * whether the same GrGLInterface is returned or whether a new one is created
58 * at each call. Some platforms may not be able to use a single GrGLInterface
59 * because extension function ptrs vary across contexts. Note that GrGLInterface
60 * is ref-counted. So if the same object is returned by multiple calls to
61 * GrGLDefaultInterface, each should bump the ref count.
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +000062 *
63 * By defining GR_GL_PER_GL_CALL_IFACE_CALLBACK to 1 the client can specify a
64 * callback function that will be called prior to each GL function call. See
65 * comments in GrGLConfig.h
twiz@google.com59a190b2011-03-14 21:23:01 +000066 */
twiz@google.com59a190b2011-03-14 21:23:01 +000067
bsalomon@google.com0b77d682011-08-19 13:28:54 +000068struct GrGLInterface;
69
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000070const GrGLInterface* GrGLDefaultInterface();
twiz@google.com59a190b2011-03-14 21:23:01 +000071
bsalomon@google.com57f5d982011-10-24 21:17:53 +000072/**
73 * Creates a GrGLInterface for a "native" GL context (e.g. WGL on windows,
74 * GLX on linux, AGL on Mac). On platforms that have context-specific function
75 * pointers for GL extensions (e.g. windows) the returned interface is only
76 * valid for the context that was current at creation.
77 */
bsalomon@google.com373a6632011-10-19 20:43:20 +000078const GrGLInterface* GrGLCreateNativeInterface();
79
bsalomon@google.com57f5d982011-10-24 21:17:53 +000080/**
81 * Creates a GrGLInterface for an OSMesa context.
82 */
bsalomon@google.com373a6632011-10-19 20:43:20 +000083const GrGLInterface* GrGLCreateMesaInterface();
84
twiz@google.com0f31ca72011-03-18 17:38:11 +000085typedef unsigned int GrGLenum;
86typedef unsigned char GrGLboolean;
87typedef unsigned int GrGLbitfield;
88typedef signed char GrGLbyte;
bsalomon@google.com271cffc2011-05-20 14:13:56 +000089typedef char GrGLchar;
twiz@google.com0f31ca72011-03-18 17:38:11 +000090typedef short GrGLshort;
91typedef int GrGLint;
92typedef int GrGLsizei;
bsalomon@google.com373a6632011-10-19 20:43:20 +000093typedef int64_t GrGLint64;
twiz@google.com0f31ca72011-03-18 17:38:11 +000094typedef unsigned char GrGLubyte;
95typedef unsigned short GrGLushort;
96typedef unsigned int GrGLuint;
bsalomon@google.com373a6632011-10-19 20:43:20 +000097typedef uint64_t GrGLuint64;
twiz@google.com0f31ca72011-03-18 17:38:11 +000098typedef float GrGLfloat;
99typedef float GrGLclampf;
100typedef double GrGLdouble;
101typedef double GrGLclampd;
102typedef void GrGLvoid;
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000103typedef long GrGLintptr;
104typedef long GrGLsizeiptr;
twiz@google.com0f31ca72011-03-18 17:38:11 +0000105
twiz@google.comb65e0cb2011-03-18 20:41:44 +0000106enum GrGLBinding {
107 kDesktop_GrGLBinding = 0x01,
108 kES1_GrGLBinding = 0x02,
109 kES2_GrGLBinding = 0x04
110};
111
twiz@google.com59a190b2011-03-14 21:23:01 +0000112extern "C" {
twiz@google.com0f31ca72011-03-18 17:38:11 +0000113 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLActiveTextureProc)(GrGLenum texture);
114 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLAttachShaderProc)(GrGLuint program, GrGLuint shader);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000115 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBeginQueryProc)(GrGLenum target, GrGLuint id);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000116 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindAttribLocationProc)(GrGLuint program, GrGLuint index, const char* name);
117 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindBufferProc)(GrGLenum target, GrGLuint buffer);
118 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindTextureProc)(GrGLenum target, GrGLuint texture);
119 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBlendColorProc)(GrGLclampf red, GrGLclampf green, GrGLclampf blue, GrGLclampf alpha);
bsalomon@google.combc5cf512011-09-21 16:21:07 +0000120 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindFragDataLocationProc)(GrGLuint program, GrGLuint colorNumber, const GrGLchar* name);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000121 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBlendFuncProc)(GrGLenum sfactor, GrGLenum dfactor);
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000122 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBufferDataProc)(GrGLenum target, GrGLsizeiptr size, const GrGLvoid* data, GrGLenum usage);
123 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBufferSubDataProc)(GrGLenum target, GrGLintptr offset, GrGLsizeiptr size, const GrGLvoid* data);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000124 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClearProc)(GrGLbitfield mask);
125 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClearColorProc)(GrGLclampf red, GrGLclampf green, GrGLclampf blue, GrGLclampf alpha);
126 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClearStencilProc)(GrGLint s);
127 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClientActiveTextureProc)(GrGLenum texture);
128 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLColor4ubProc)(GrGLubyte red, GrGLubyte green, GrGLubyte blue, GrGLubyte alpha);
129 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLColorMaskProc)(GrGLboolean red, GrGLboolean green, GrGLboolean blue, GrGLboolean alpha);
130 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLColorPointerProc)(GrGLint size, GrGLenum type, GrGLsizei stride, const GrGLvoid* pointer);
131 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLCompileShaderProc)(GrGLuint shader);
132 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLCompressedTexImage2DProc)(GrGLenum target, GrGLint level, GrGLenum internalformat, GrGLsizei width, GrGLsizei height, GrGLint border, GrGLsizei imageSize, const GrGLvoid* data);
133 typedef GrGLuint (GR_GL_FUNCTION_TYPE *GrGLCreateProgramProc)(void);
134 typedef GrGLuint (GR_GL_FUNCTION_TYPE *GrGLCreateShaderProc)(GrGLenum type);
135 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLCullFaceProc)(GrGLenum mode);
136 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteBuffersProc)(GrGLsizei n, const GrGLuint* buffers);
137 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteProgramProc)(GrGLuint program);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000138 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteQueriesProc)(GrGLsizei n, const GrGLuint *ids);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000139 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteShaderProc)(GrGLuint shader);
140 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteTexturesProc)(GrGLsizei n, const GrGLuint* textures);
141 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDepthMaskProc)(GrGLboolean flag);
142 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDisableProc)(GrGLenum cap);
143 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDisableClientStateProc)(GrGLenum array);
144 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDisableVertexAttribArrayProc)(GrGLuint index);
145 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawArraysProc)(GrGLenum mode, GrGLint first, GrGLsizei count);
bsalomon@google.comd32c5f52011-08-02 19:29:03 +0000146 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawBufferProc)(GrGLenum mode);
147 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawBuffersProc)(GrGLsizei n, const GrGLenum* bufs);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000148 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawElementsProc)(GrGLenum mode, GrGLsizei count, GrGLenum type, const GrGLvoid* indices);
149 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLEnableProc)(GrGLenum cap);
150 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLEnableClientStateProc)(GrGLenum cap);
151 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLEnableVertexAttribArrayProc)(GrGLuint index);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000152 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLEndQueryProc)(GrGLenum target);
153 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFinishProc)();
154 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFlushProc)();
twiz@google.com0f31ca72011-03-18 17:38:11 +0000155 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFrontFaceProc)(GrGLenum mode);
156 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenBuffersProc)(GrGLsizei n, GrGLuint* buffers);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000157 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenQueriesProc)(GrGLsizei n, GrGLuint *ids);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000158 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenTexturesProc)(GrGLsizei n, GrGLuint* textures);
159 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetBufferParameterivProc)(GrGLenum target, GrGLenum pname, GrGLint* params);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000160 typedef GrGLenum (GR_GL_FUNCTION_TYPE *GrGLGetErrorProc)();
twiz@google.com0f31ca72011-03-18 17:38:11 +0000161 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetIntegervProc)(GrGLenum pname, GrGLint* params);
162 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetProgramInfoLogProc)(GrGLuint program, GrGLsizei bufsize, GrGLsizei* length, char* infolog);
163 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetProgramivProc)(GrGLuint program, GrGLenum pname, GrGLint* params);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000164 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetQueryivProc)(GrGLenum GLtarget, GrGLenum pname, GrGLint *params);
165 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetQueryObjecti64vProc)(GrGLuint id, GrGLenum pname, GrGLint64 *params);
166 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetQueryObjectivProc)(GrGLuint id, GrGLenum pname, GrGLint *params);
167 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetQueryObjectui64vProc)(GrGLuint id, GrGLenum pname, GrGLuint64 *params);
168 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetQueryObjectuivProc)(GrGLuint id, GrGLenum pname, GrGLuint *params);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000169 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetShaderInfoLogProc)(GrGLuint shader, GrGLsizei bufsize, GrGLsizei* length, char* infolog);
170 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetShaderivProc)(GrGLuint shader, GrGLenum pname, GrGLint* params);
171 typedef const GrGLubyte* (GR_GL_FUNCTION_TYPE *GrGLGetStringProc)(GrGLenum name);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000172 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetTexLevelParameterivProc)(GrGLenum target, GrGLint level, GrGLenum pname, GrGLint* params);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000173 typedef GrGLint (GR_GL_FUNCTION_TYPE *GrGLGetUniformLocationProc)(GrGLuint program, const char* name);
174 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLLineWidthProc)(GrGLfloat width);
175 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLLinkProgramProc)(GrGLuint program);
176 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLLoadMatrixfProc)(const GrGLfloat* m);
177 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLMatrixModeProc)(GrGLenum mode);
178 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLPixelStoreiProc)(GrGLenum pname, GrGLint param);
179 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLPointSizeProc)(GrGLfloat size);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000180 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLQueryCounterProc)(GrGLuint id, GrGLenum target);
bsalomon@google.comc49d66b2011-08-03 14:22:30 +0000181 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLReadBufferProc)(GrGLenum src);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000182 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLReadPixelsProc)(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height, GrGLenum format, GrGLenum type, GrGLvoid* pixels);
183 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLScissorProc)(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height);
184 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLShadeModelProc)(GrGLenum mode);
185 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLShaderSourceProc)(GrGLuint shader, GrGLsizei count, const char** str, const GrGLint* length);
186 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilFuncProc)(GrGLenum func, GrGLint ref, GrGLuint mask);
187 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilFuncSeparateProc)(GrGLenum face, GrGLenum func, GrGLint ref, GrGLuint mask);
188 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilMaskProc)(GrGLuint mask);
189 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilMaskSeparateProc)(GrGLenum face, GrGLuint mask);
190 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilOpProc)(GrGLenum fail, GrGLenum zfail, GrGLenum zpass);
191 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilOpSeparateProc)(GrGLenum face, GrGLenum fail, GrGLenum zfail, GrGLenum zpass);
192 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexCoordPointerProc)(GrGLint size, GrGLenum type, GrGLsizei stride, const GrGLvoid* pointer);
193 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexEnviProc)(GrGLenum target, GrGLenum pname, GrGLint param);
194 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);
195 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexParameteriProc)(GrGLenum target, GrGLenum pname, GrGLint param);
196 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 +0000197 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1fProc)(GrGLint location, GrGLfloat v0);
198 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1iProc)(GrGLint location, GrGLint v0);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000199 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1fvProc)(GrGLint location, GrGLsizei count, const GrGLfloat* v);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000200 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1ivProc)(GrGLint location, GrGLsizei count, const GrGLint* v);
201 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform2fProc)(GrGLint location, GrGLfloat v0, GrGLfloat v1);
202 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform2iProc)(GrGLint location, GrGLint v0, GrGLint v1);
203 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform2fvProc)(GrGLint location, GrGLsizei count, const GrGLfloat* v);
204 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform2ivProc)(GrGLint location, GrGLsizei count, const GrGLint* v);
205 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform3fProc)(GrGLint location, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2);
206 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform3iProc)(GrGLint location, GrGLint v0, GrGLint v1, GrGLint v2);
207 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform3fvProc)(GrGLint location, GrGLsizei count, const GrGLfloat* v);
208 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform3ivProc)(GrGLint location, GrGLsizei count, const GrGLint* v);
209 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform4fProc)(GrGLint location, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2, GrGLfloat v3);
210 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 +0000211 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform4fvProc)(GrGLint location, GrGLsizei count, const GrGLfloat* v);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000212 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform4ivProc)(GrGLint location, GrGLsizei count, const GrGLint* v);
213 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniformMatrix2fvProc)(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000214 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniformMatrix3fvProc)(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000215 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniformMatrix4fvProc)(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000216 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUseProgramProc)(GrGLuint program);
217 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLVertexAttrib4fvProc)(GrGLuint indx, const GrGLfloat* values);
218 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLVertexAttribPointerProc)(GrGLuint indx, GrGLint size, GrGLenum type, GrGLboolean normalized, GrGLsizei stride, const GrGLvoid* ptr);
219 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLVertexPointerProc)(GrGLint size, GrGLenum type, GrGLsizei stride, const GrGLvoid* pointer);
220 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLViewportProc)(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height);
twiz@google.com59a190b2011-03-14 21:23:01 +0000221
222 // FBO Extension Functions
twiz@google.com0f31ca72011-03-18 17:38:11 +0000223 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindFramebufferProc)(GrGLenum target, GrGLuint framebuffer);
224 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindRenderbufferProc)(GrGLenum target, GrGLuint renderbuffer);
225 typedef GrGLenum (GR_GL_FUNCTION_TYPE *GrGLCheckFramebufferStatusProc)(GrGLenum target);
226 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteFramebuffersProc)(GrGLsizei n, const GrGLuint *framebuffers);
227 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteRenderbuffersProc)(GrGLsizei n, const GrGLuint *renderbuffers);
228 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFramebufferRenderbufferProc)(GrGLenum target, GrGLenum attachment, GrGLenum renderbuffertarget, GrGLuint renderbuffer);
229 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFramebufferTexture2DProc)(GrGLenum target, GrGLenum attachment, GrGLenum textarget, GrGLuint texture, GrGLint level);
230 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenFramebuffersProc)(GrGLsizei n, GrGLuint *framebuffers);
231 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenRenderbuffersProc)(GrGLsizei n, GrGLuint *renderbuffers);
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000232 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetFramebufferAttachmentParameterivProc)(GrGLenum target, GrGLenum attachment, GrGLenum pname, GrGLint* params);
233 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetRenderbufferParameterivProc)(GrGLenum target, GrGLenum pname, GrGLint* params);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000234 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLRenderbufferStorageProc)(GrGLenum target, GrGLenum internalformat, GrGLsizei width, GrGLsizei height);
twiz@google.com59a190b2011-03-14 21:23:01 +0000235
236 // Multisampling Extension Functions
237 // same prototype for ARB_FBO, EXT_FBO, GL 3.0, & Apple ES extension
twiz@google.com0f31ca72011-03-18 17:38:11 +0000238 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 +0000239 // desktop: ext_fbo_blit, arb_fbo, gl 3.0
twiz@google.com0f31ca72011-03-18 17:38:11 +0000240 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 +0000241 // apple's es extension
twiz@google.com0f31ca72011-03-18 17:38:11 +0000242 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLResolveMultisampleFramebufferProc)();
twiz@google.com59a190b2011-03-14 21:23:01 +0000243
twiz@google.com59a190b2011-03-14 21:23:01 +0000244 // Buffer mapping (extension in ES).
twiz@google.com0f31ca72011-03-18 17:38:11 +0000245 typedef GrGLvoid* (GR_GL_FUNCTION_TYPE *GrGLMapBufferProc)(GrGLenum target, GrGLenum access);
246 typedef GrGLboolean (GR_GL_FUNCTION_TYPE *GrGLUnmapBufferProc)(GrGLenum target);
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000247
248 // Dual source blending
249 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindFragDataLocationIndexedProc)(GrGLuint program, GrGLuint colorNumber, GrGLuint index, const GrGLchar * name);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000250} // extern "C"
251
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +0000252#if GR_GL_PER_GL_FUNC_CALLBACK
253typedef void (*GrGLInterfaceCallbackProc)(const GrGLInterface*);
254typedef intptr_t GrGLInterfaceCallbackData;
255#endif
256
257
tomhudson@google.come67bd3f2011-06-16 14:08:04 +0000258enum GrGLCapability {
259 kProbe_GrGLCapability = -1
tomhudson@google.com30e4bb62011-06-15 19:41:46 +0000260};
261
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000262/*
263 * The following interface exports the OpenGL entry points used by the system.
264 * Use of OpenGL calls is disallowed. All calls should be invoked through
265 * the global instance of this struct, defined above.
266 *
267 * IMPORTANT NOTE: The OpenGL entry points exposed here include both core GL
268 * functions, and extensions. The system assumes that the address of the
269 * extension pointer will be valid across contexts.
270 */
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000271struct GR_API GrGLInterface : public GrRefCnt {
272
273 GrGLInterface();
274
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000275 bool validate(GrEngine engine) const;
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000276 bool supportsDesktop() const {
277 return 0 != (kDesktop_GrGLBinding & fBindingsExported);
278 }
279 bool supportsES1() const {
280 return 0 != (kES1_GrGLBinding & fBindingsExported);
281 }
282 bool supportsES2() const {
283 return 0 != (kES2_GrGLBinding & fBindingsExported);
284 }
285 bool supportsES() const {
286 return 0 != ((kES1_GrGLBinding | kES2_GrGLBinding) &
287 fBindingsExported);
288 }
twiz@google.com59a190b2011-03-14 21:23:01 +0000289
twiz@google.comb65e0cb2011-03-18 20:41:44 +0000290 // Indicator variable specifying the type of GL implementation
291 // exported: GLES{1|2} or Desktop.
292 GrGLBinding fBindingsExported;
293
tomhudson@google.com747bf292011-06-14 18:16:52 +0000294 /// Does this GL support NPOT textures on FBOs?
tomhudson@google.come67bd3f2011-06-16 14:08:04 +0000295 /// boolean value, or kProbe_GrGLCapability to probe (slowly) at context creation.
tomhudson@google.com747bf292011-06-14 18:16:52 +0000296 int fNPOTRenderTargetSupport;
297
298 /// Some GL implementations (PowerVR SGX devices like the iPhone 4)
299 /// have restrictions on the size of small render targets.
tomhudson@google.come67bd3f2011-06-16 14:08:04 +0000300 /// kProbe_GrGLCapability to probe (slowly) at context creation.
tomhudson@google.com747bf292011-06-14 18:16:52 +0000301 int fMinRenderTargetHeight;
302 int fMinRenderTargetWidth;
303
twiz@google.com59a190b2011-03-14 21:23:01 +0000304 GrGLActiveTextureProc fActiveTexture;
305 GrGLAttachShaderProc fAttachShader;
bsalomon@google.com373a6632011-10-19 20:43:20 +0000306 GrGLBeginQueryProc fBeginQuery;
twiz@google.com59a190b2011-03-14 21:23:01 +0000307 GrGLBindAttribLocationProc fBindAttribLocation;
308 GrGLBindBufferProc fBindBuffer;
bsalomon@google.combc5cf512011-09-21 16:21:07 +0000309 GrGLBindFragDataLocationProc fBindFragDataLocation;
twiz@google.com59a190b2011-03-14 21:23:01 +0000310 GrGLBindTextureProc fBindTexture;
bsalomon@google.com080773c2011-03-15 19:09:25 +0000311 GrGLBlendColorProc fBlendColor;
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000312 GrGLBlendFuncProc fBlendFunc;
twiz@google.com59a190b2011-03-14 21:23:01 +0000313 GrGLBufferDataProc fBufferData;
314 GrGLBufferSubDataProc fBufferSubData;
315 GrGLClearProc fClear;
316 GrGLClearColorProc fClearColor;
317 GrGLClearStencilProc fClearStencil;
318 GrGLClientActiveTextureProc fClientActiveTexture;
319 GrGLColor4ubProc fColor4ub;
320 GrGLColorMaskProc fColorMask;
321 GrGLColorPointerProc fColorPointer;
322 GrGLCompileShaderProc fCompileShader;
323 GrGLCompressedTexImage2DProc fCompressedTexImage2D;
324 GrGLCreateProgramProc fCreateProgram;
325 GrGLCreateShaderProc fCreateShader;
326 GrGLCullFaceProc fCullFace;
327 GrGLDeleteBuffersProc fDeleteBuffers;
328 GrGLDeleteProgramProc fDeleteProgram;
bsalomon@google.com373a6632011-10-19 20:43:20 +0000329 GrGLDeleteQueriesProc fDeleteQueries;
twiz@google.com59a190b2011-03-14 21:23:01 +0000330 GrGLDeleteShaderProc fDeleteShader;
331 GrGLDeleteTexturesProc fDeleteTextures;
332 GrGLDepthMaskProc fDepthMask;
333 GrGLDisableProc fDisable;
334 GrGLDisableClientStateProc fDisableClientState;
335 GrGLDisableVertexAttribArrayProc fDisableVertexAttribArray;
336 GrGLDrawArraysProc fDrawArrays;
bsalomon@google.comd32c5f52011-08-02 19:29:03 +0000337 GrGLDrawBufferProc fDrawBuffer;
338 GrGLDrawBuffersProc fDrawBuffers;
twiz@google.com59a190b2011-03-14 21:23:01 +0000339 GrGLDrawElementsProc fDrawElements;
340 GrGLEnableProc fEnable;
341 GrGLEnableClientStateProc fEnableClientState;
342 GrGLEnableVertexAttribArrayProc fEnableVertexAttribArray;
bsalomon@google.com373a6632011-10-19 20:43:20 +0000343 GrGLEndQueryProc fEndQuery;
344 GrGLFinishProc fFinish;
345 GrGLFlushProc fFlush;
twiz@google.com59a190b2011-03-14 21:23:01 +0000346 GrGLFrontFaceProc fFrontFace;
347 GrGLGenBuffersProc fGenBuffers;
bsalomon@google.com373a6632011-10-19 20:43:20 +0000348 GrGLGenQueriesProc fGenQueries;
twiz@google.com59a190b2011-03-14 21:23:01 +0000349 GrGLGenTexturesProc fGenTextures;
350 GrGLGetBufferParameterivProc fGetBufferParameteriv;
351 GrGLGetErrorProc fGetError;
352 GrGLGetIntegervProc fGetIntegerv;
bsalomon@google.com373a6632011-10-19 20:43:20 +0000353 GrGLGetQueryObjecti64vProc fGetQueryObjecti64v;
354 GrGLGetQueryObjectivProc fGetQueryObjectiv;
355 GrGLGetQueryObjectui64vProc fGetQueryObjectui64v;
356 GrGLGetQueryObjectuivProc fGetQueryObjectuiv;
357 GrGLGetQueryivProc fGetQueryiv;
twiz@google.com59a190b2011-03-14 21:23:01 +0000358 GrGLGetProgramInfoLogProc fGetProgramInfoLog;
359 GrGLGetProgramivProc fGetProgramiv;
360 GrGLGetShaderInfoLogProc fGetShaderInfoLog;
361 GrGLGetShaderivProc fGetShaderiv;
362 GrGLGetStringProc fGetString;
bsalomon@google.com373a6632011-10-19 20:43:20 +0000363 GrGLGetTexLevelParameterivProc fGetTexLevelParameteriv;
twiz@google.com59a190b2011-03-14 21:23:01 +0000364 GrGLGetUniformLocationProc fGetUniformLocation;
365 GrGLLineWidthProc fLineWidth;
366 GrGLLinkProgramProc fLinkProgram;
367 GrGLLoadMatrixfProc fLoadMatrixf;
368 GrGLMatrixModeProc fMatrixMode;
369 GrGLPixelStoreiProc fPixelStorei;
370 GrGLPointSizeProc fPointSize;
bsalomon@google.com373a6632011-10-19 20:43:20 +0000371 GrGLQueryCounterProc fQueryCounter;
bsalomon@google.comc49d66b2011-08-03 14:22:30 +0000372 GrGLReadBufferProc fReadBuffer;
twiz@google.com59a190b2011-03-14 21:23:01 +0000373 GrGLReadPixelsProc fReadPixels;
374 GrGLScissorProc fScissor;
375 GrGLShadeModelProc fShadeModel;
376 GrGLShaderSourceProc fShaderSource;
377 GrGLStencilFuncProc fStencilFunc;
378 GrGLStencilFuncSeparateProc fStencilFuncSeparate;
379 GrGLStencilMaskProc fStencilMask;
380 GrGLStencilMaskSeparateProc fStencilMaskSeparate;
381 GrGLStencilOpProc fStencilOp;
382 GrGLStencilOpSeparateProc fStencilOpSeparate;
383 GrGLTexCoordPointerProc fTexCoordPointer;
384 GrGLTexEnviProc fTexEnvi;
385 GrGLTexImage2DProc fTexImage2D;
386 GrGLTexParameteriProc fTexParameteri;
387 GrGLTexSubImage2DProc fTexSubImage2D;
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000388 GrGLUniform1fProc fUniform1f;
twiz@google.com59a190b2011-03-14 21:23:01 +0000389 GrGLUniform1iProc fUniform1i;
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000390 GrGLUniform1fvProc fUniform1fv;
391 GrGLUniform1ivProc fUniform1iv;
392 GrGLUniform2fProc fUniform2f;
393 GrGLUniform2iProc fUniform2i;
394 GrGLUniform2fvProc fUniform2fv;
395 GrGLUniform2ivProc fUniform2iv;
396 GrGLUniform3fProc fUniform3f;
397 GrGLUniform3iProc fUniform3i;
398 GrGLUniform3fvProc fUniform3fv;
399 GrGLUniform3ivProc fUniform3iv;
400 GrGLUniform4fProc fUniform4f;
401 GrGLUniform4iProc fUniform4i;
twiz@google.com59a190b2011-03-14 21:23:01 +0000402 GrGLUniform4fvProc fUniform4fv;
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000403 GrGLUniform4ivProc fUniform4iv;
404 GrGLUniformMatrix2fvProc fUniformMatrix2fv;
twiz@google.com59a190b2011-03-14 21:23:01 +0000405 GrGLUniformMatrix3fvProc fUniformMatrix3fv;
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000406 GrGLUniformMatrix4fvProc fUniformMatrix4fv;
twiz@google.com59a190b2011-03-14 21:23:01 +0000407 GrGLUseProgramProc fUseProgram;
408 GrGLVertexAttrib4fvProc fVertexAttrib4fv;
409 GrGLVertexAttribPointerProc fVertexAttribPointer;
410 GrGLVertexPointerProc fVertexPointer;
411 GrGLViewportProc fViewport;
412
413 // FBO Extension Functions
414 GrGLBindFramebufferProc fBindFramebuffer;
415 GrGLBindRenderbufferProc fBindRenderbuffer;
416 GrGLCheckFramebufferStatusProc fCheckFramebufferStatus;
417 GrGLDeleteFramebuffersProc fDeleteFramebuffers;
418 GrGLDeleteRenderbuffersProc fDeleteRenderbuffers;
419 GrGLFramebufferRenderbufferProc fFramebufferRenderbuffer;
420 GrGLFramebufferTexture2DProc fFramebufferTexture2D;
421 GrGLGenFramebuffersProc fGenFramebuffers;
422 GrGLGenRenderbuffersProc fGenRenderbuffers;
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000423 GrGLGetFramebufferAttachmentParameterivProc fGetFramebufferAttachmentParameteriv;
424 GrGLGetRenderbufferParameterivProc fGetRenderbufferParameteriv;
twiz@google.com59a190b2011-03-14 21:23:01 +0000425 GrGLRenderbufferStorageProc fRenderbufferStorage;
426
427 // Multisampling Extension Functions
428 // same prototype for ARB_FBO, EXT_FBO, GL 3.0, & Apple ES extension
429 GrGLRenderbufferStorageMultisampleProc fRenderbufferStorageMultisample;
430 // desktop: ext_fbo_blit, arb_fbo, gl 3.0
431 GrGLBlitFramebufferProc fBlitFramebuffer;
432 // apple's es extension
433 GrGLResolveMultisampleFramebufferProc fResolveMultisampleFramebuffer;
434
twiz@google.com59a190b2011-03-14 21:23:01 +0000435 // Buffer mapping (extension in ES).
436 GrGLMapBufferProc fMapBuffer;
437 GrGLUnmapBufferProc fUnmapBuffer;
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000438
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000439 // Dual Source Blending
440 GrGLBindFragDataLocationIndexedProc fBindFragDataLocationIndexed;
441
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +0000442 // Per-GL func callback
443#if GR_GL_PER_GL_FUNC_CALLBACK
444 GrGLInterfaceCallbackProc fCallback;
445 GrGLInterfaceCallbackData fCallbackData;
446#endif
447
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000448private:
449 bool validateShaderFunctions() const;
450 bool validateFixedFunctions() const;
451};
twiz@google.com59a190b2011-03-14 21:23:01 +0000452
453#endif