blob: b3e0cf191b606697349af0ab9d70a99cc3d35ab6 [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.com373a6632011-10-19 20:43:20 +000072const GrGLInterface* GrGLCreateNativeInterface();
73
74const GrGLInterface* GrGLCreateMesaInterface();
75
twiz@google.com0f31ca72011-03-18 17:38:11 +000076typedef unsigned int GrGLenum;
77typedef unsigned char GrGLboolean;
78typedef unsigned int GrGLbitfield;
79typedef signed char GrGLbyte;
bsalomon@google.com271cffc2011-05-20 14:13:56 +000080typedef char GrGLchar;
twiz@google.com0f31ca72011-03-18 17:38:11 +000081typedef short GrGLshort;
82typedef int GrGLint;
83typedef int GrGLsizei;
bsalomon@google.com373a6632011-10-19 20:43:20 +000084typedef int64_t GrGLint64;
twiz@google.com0f31ca72011-03-18 17:38:11 +000085typedef unsigned char GrGLubyte;
86typedef unsigned short GrGLushort;
87typedef unsigned int GrGLuint;
bsalomon@google.com373a6632011-10-19 20:43:20 +000088typedef uint64_t GrGLuint64;
twiz@google.com0f31ca72011-03-18 17:38:11 +000089typedef float GrGLfloat;
90typedef float GrGLclampf;
91typedef double GrGLdouble;
92typedef double GrGLclampd;
93typedef void GrGLvoid;
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000094typedef long GrGLintptr;
95typedef long GrGLsizeiptr;
twiz@google.com0f31ca72011-03-18 17:38:11 +000096
twiz@google.comb65e0cb2011-03-18 20:41:44 +000097enum GrGLBinding {
98 kDesktop_GrGLBinding = 0x01,
99 kES1_GrGLBinding = 0x02,
100 kES2_GrGLBinding = 0x04
101};
102
twiz@google.com59a190b2011-03-14 21:23:01 +0000103extern "C" {
twiz@google.com0f31ca72011-03-18 17:38:11 +0000104 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLActiveTextureProc)(GrGLenum texture);
105 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLAttachShaderProc)(GrGLuint program, GrGLuint shader);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000106 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBeginQueryProc)(GrGLenum target, GrGLuint id);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000107 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindAttribLocationProc)(GrGLuint program, GrGLuint index, const char* name);
108 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindBufferProc)(GrGLenum target, GrGLuint buffer);
109 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindTextureProc)(GrGLenum target, GrGLuint texture);
110 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBlendColorProc)(GrGLclampf red, GrGLclampf green, GrGLclampf blue, GrGLclampf alpha);
bsalomon@google.combc5cf512011-09-21 16:21:07 +0000111 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindFragDataLocationProc)(GrGLuint program, GrGLuint colorNumber, const GrGLchar* name);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000112 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBlendFuncProc)(GrGLenum sfactor, GrGLenum dfactor);
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000113 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBufferDataProc)(GrGLenum target, GrGLsizeiptr size, const GrGLvoid* data, GrGLenum usage);
114 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBufferSubDataProc)(GrGLenum target, GrGLintptr offset, GrGLsizeiptr size, const GrGLvoid* data);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000115 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClearProc)(GrGLbitfield mask);
116 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClearColorProc)(GrGLclampf red, GrGLclampf green, GrGLclampf blue, GrGLclampf alpha);
117 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClearStencilProc)(GrGLint s);
118 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClientActiveTextureProc)(GrGLenum texture);
119 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLColor4ubProc)(GrGLubyte red, GrGLubyte green, GrGLubyte blue, GrGLubyte alpha);
120 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLColorMaskProc)(GrGLboolean red, GrGLboolean green, GrGLboolean blue, GrGLboolean alpha);
121 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLColorPointerProc)(GrGLint size, GrGLenum type, GrGLsizei stride, const GrGLvoid* pointer);
122 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLCompileShaderProc)(GrGLuint shader);
123 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLCompressedTexImage2DProc)(GrGLenum target, GrGLint level, GrGLenum internalformat, GrGLsizei width, GrGLsizei height, GrGLint border, GrGLsizei imageSize, const GrGLvoid* data);
124 typedef GrGLuint (GR_GL_FUNCTION_TYPE *GrGLCreateProgramProc)(void);
125 typedef GrGLuint (GR_GL_FUNCTION_TYPE *GrGLCreateShaderProc)(GrGLenum type);
126 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLCullFaceProc)(GrGLenum mode);
127 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteBuffersProc)(GrGLsizei n, const GrGLuint* buffers);
128 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteProgramProc)(GrGLuint program);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000129 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteQueriesProc)(GrGLsizei n, const GrGLuint *ids);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000130 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteShaderProc)(GrGLuint shader);
131 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteTexturesProc)(GrGLsizei n, const GrGLuint* textures);
132 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDepthMaskProc)(GrGLboolean flag);
133 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDisableProc)(GrGLenum cap);
134 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDisableClientStateProc)(GrGLenum array);
135 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDisableVertexAttribArrayProc)(GrGLuint index);
136 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawArraysProc)(GrGLenum mode, GrGLint first, GrGLsizei count);
bsalomon@google.comd32c5f52011-08-02 19:29:03 +0000137 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawBufferProc)(GrGLenum mode);
138 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawBuffersProc)(GrGLsizei n, const GrGLenum* bufs);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000139 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawElementsProc)(GrGLenum mode, GrGLsizei count, GrGLenum type, const GrGLvoid* indices);
140 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLEnableProc)(GrGLenum cap);
141 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLEnableClientStateProc)(GrGLenum cap);
142 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLEnableVertexAttribArrayProc)(GrGLuint index);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000143 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLEndQueryProc)(GrGLenum target);
144 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFinishProc)();
145 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFlushProc)();
twiz@google.com0f31ca72011-03-18 17:38:11 +0000146 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFrontFaceProc)(GrGLenum mode);
147 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenBuffersProc)(GrGLsizei n, GrGLuint* buffers);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000148 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenQueriesProc)(GrGLsizei n, GrGLuint *ids);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000149 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenTexturesProc)(GrGLsizei n, GrGLuint* textures);
150 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetBufferParameterivProc)(GrGLenum target, GrGLenum pname, GrGLint* params);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000151 typedef GrGLenum (GR_GL_FUNCTION_TYPE *GrGLGetErrorProc)();
twiz@google.com0f31ca72011-03-18 17:38:11 +0000152 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetIntegervProc)(GrGLenum pname, GrGLint* params);
153 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetProgramInfoLogProc)(GrGLuint program, GrGLsizei bufsize, GrGLsizei* length, char* infolog);
154 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetProgramivProc)(GrGLuint program, GrGLenum pname, GrGLint* params);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000155 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetQueryivProc)(GrGLenum GLtarget, GrGLenum pname, GrGLint *params);
156 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetQueryObjecti64vProc)(GrGLuint id, GrGLenum pname, GrGLint64 *params);
157 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetQueryObjectivProc)(GrGLuint id, GrGLenum pname, GrGLint *params);
158 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetQueryObjectui64vProc)(GrGLuint id, GrGLenum pname, GrGLuint64 *params);
159 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetQueryObjectuivProc)(GrGLuint id, GrGLenum pname, GrGLuint *params);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000160 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetShaderInfoLogProc)(GrGLuint shader, GrGLsizei bufsize, GrGLsizei* length, char* infolog);
161 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetShaderivProc)(GrGLuint shader, GrGLenum pname, GrGLint* params);
162 typedef const GrGLubyte* (GR_GL_FUNCTION_TYPE *GrGLGetStringProc)(GrGLenum name);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000163 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetTexLevelParameterivProc)(GrGLenum target, GrGLint level, GrGLenum pname, GrGLint* params);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000164 typedef GrGLint (GR_GL_FUNCTION_TYPE *GrGLGetUniformLocationProc)(GrGLuint program, const char* name);
165 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLLineWidthProc)(GrGLfloat width);
166 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLLinkProgramProc)(GrGLuint program);
167 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLLoadMatrixfProc)(const GrGLfloat* m);
168 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLMatrixModeProc)(GrGLenum mode);
169 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLPixelStoreiProc)(GrGLenum pname, GrGLint param);
170 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLPointSizeProc)(GrGLfloat size);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000171 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLQueryCounterProc)(GrGLuint id, GrGLenum target);
bsalomon@google.comc49d66b2011-08-03 14:22:30 +0000172 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLReadBufferProc)(GrGLenum src);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000173 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLReadPixelsProc)(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height, GrGLenum format, GrGLenum type, GrGLvoid* pixels);
174 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLScissorProc)(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height);
175 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLShadeModelProc)(GrGLenum mode);
176 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLShaderSourceProc)(GrGLuint shader, GrGLsizei count, const char** str, const GrGLint* length);
177 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilFuncProc)(GrGLenum func, GrGLint ref, GrGLuint mask);
178 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilFuncSeparateProc)(GrGLenum face, GrGLenum func, GrGLint ref, GrGLuint mask);
179 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilMaskProc)(GrGLuint mask);
180 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilMaskSeparateProc)(GrGLenum face, GrGLuint mask);
181 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilOpProc)(GrGLenum fail, GrGLenum zfail, GrGLenum zpass);
182 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilOpSeparateProc)(GrGLenum face, GrGLenum fail, GrGLenum zfail, GrGLenum zpass);
183 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexCoordPointerProc)(GrGLint size, GrGLenum type, GrGLsizei stride, const GrGLvoid* pointer);
184 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexEnviProc)(GrGLenum target, GrGLenum pname, GrGLint param);
185 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);
186 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexParameteriProc)(GrGLenum target, GrGLenum pname, GrGLint param);
187 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 +0000188 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1fProc)(GrGLint location, GrGLfloat v0);
189 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1iProc)(GrGLint location, GrGLint v0);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000190 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1fvProc)(GrGLint location, GrGLsizei count, const GrGLfloat* v);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000191 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1ivProc)(GrGLint location, GrGLsizei count, const GrGLint* v);
192 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform2fProc)(GrGLint location, GrGLfloat v0, GrGLfloat v1);
193 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform2iProc)(GrGLint location, GrGLint v0, GrGLint v1);
194 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform2fvProc)(GrGLint location, GrGLsizei count, const GrGLfloat* v);
195 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform2ivProc)(GrGLint location, GrGLsizei count, const GrGLint* v);
196 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform3fProc)(GrGLint location, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2);
197 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform3iProc)(GrGLint location, GrGLint v0, GrGLint v1, GrGLint v2);
198 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform3fvProc)(GrGLint location, GrGLsizei count, const GrGLfloat* v);
199 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform3ivProc)(GrGLint location, GrGLsizei count, const GrGLint* v);
200 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform4fProc)(GrGLint location, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2, GrGLfloat v3);
201 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 +0000202 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform4fvProc)(GrGLint location, GrGLsizei count, const GrGLfloat* v);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000203 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform4ivProc)(GrGLint location, GrGLsizei count, const GrGLint* v);
204 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniformMatrix2fvProc)(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000205 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniformMatrix3fvProc)(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000206 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniformMatrix4fvProc)(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000207 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUseProgramProc)(GrGLuint program);
208 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLVertexAttrib4fvProc)(GrGLuint indx, const GrGLfloat* values);
209 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLVertexAttribPointerProc)(GrGLuint indx, GrGLint size, GrGLenum type, GrGLboolean normalized, GrGLsizei stride, const GrGLvoid* ptr);
210 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLVertexPointerProc)(GrGLint size, GrGLenum type, GrGLsizei stride, const GrGLvoid* pointer);
211 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLViewportProc)(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height);
twiz@google.com59a190b2011-03-14 21:23:01 +0000212
213 // FBO Extension Functions
twiz@google.com0f31ca72011-03-18 17:38:11 +0000214 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindFramebufferProc)(GrGLenum target, GrGLuint framebuffer);
215 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindRenderbufferProc)(GrGLenum target, GrGLuint renderbuffer);
216 typedef GrGLenum (GR_GL_FUNCTION_TYPE *GrGLCheckFramebufferStatusProc)(GrGLenum target);
217 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteFramebuffersProc)(GrGLsizei n, const GrGLuint *framebuffers);
218 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteRenderbuffersProc)(GrGLsizei n, const GrGLuint *renderbuffers);
219 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFramebufferRenderbufferProc)(GrGLenum target, GrGLenum attachment, GrGLenum renderbuffertarget, GrGLuint renderbuffer);
220 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFramebufferTexture2DProc)(GrGLenum target, GrGLenum attachment, GrGLenum textarget, GrGLuint texture, GrGLint level);
221 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenFramebuffersProc)(GrGLsizei n, GrGLuint *framebuffers);
222 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenRenderbuffersProc)(GrGLsizei n, GrGLuint *renderbuffers);
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000223 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetFramebufferAttachmentParameterivProc)(GrGLenum target, GrGLenum attachment, GrGLenum pname, GrGLint* params);
224 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetRenderbufferParameterivProc)(GrGLenum target, GrGLenum pname, GrGLint* params);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000225 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLRenderbufferStorageProc)(GrGLenum target, GrGLenum internalformat, GrGLsizei width, GrGLsizei height);
twiz@google.com59a190b2011-03-14 21:23:01 +0000226
227 // Multisampling Extension Functions
228 // same prototype for ARB_FBO, EXT_FBO, GL 3.0, & Apple ES extension
twiz@google.com0f31ca72011-03-18 17:38:11 +0000229 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 +0000230 // desktop: ext_fbo_blit, arb_fbo, gl 3.0
twiz@google.com0f31ca72011-03-18 17:38:11 +0000231 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 +0000232 // apple's es extension
twiz@google.com0f31ca72011-03-18 17:38:11 +0000233 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLResolveMultisampleFramebufferProc)();
twiz@google.com59a190b2011-03-14 21:23:01 +0000234
twiz@google.com59a190b2011-03-14 21:23:01 +0000235 // Buffer mapping (extension in ES).
twiz@google.com0f31ca72011-03-18 17:38:11 +0000236 typedef GrGLvoid* (GR_GL_FUNCTION_TYPE *GrGLMapBufferProc)(GrGLenum target, GrGLenum access);
237 typedef GrGLboolean (GR_GL_FUNCTION_TYPE *GrGLUnmapBufferProc)(GrGLenum target);
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000238
239 // Dual source blending
240 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindFragDataLocationIndexedProc)(GrGLuint program, GrGLuint colorNumber, GrGLuint index, const GrGLchar * name);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000241} // extern "C"
242
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +0000243#if GR_GL_PER_GL_FUNC_CALLBACK
244typedef void (*GrGLInterfaceCallbackProc)(const GrGLInterface*);
245typedef intptr_t GrGLInterfaceCallbackData;
246#endif
247
248
tomhudson@google.come67bd3f2011-06-16 14:08:04 +0000249enum GrGLCapability {
250 kProbe_GrGLCapability = -1
tomhudson@google.com30e4bb62011-06-15 19:41:46 +0000251};
252
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000253/*
254 * The following interface exports the OpenGL entry points used by the system.
255 * Use of OpenGL calls is disallowed. All calls should be invoked through
256 * the global instance of this struct, defined above.
257 *
258 * IMPORTANT NOTE: The OpenGL entry points exposed here include both core GL
259 * functions, and extensions. The system assumes that the address of the
260 * extension pointer will be valid across contexts.
261 */
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000262struct GR_API GrGLInterface : public GrRefCnt {
263
264 GrGLInterface();
265
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000266 bool validate(GrEngine engine) const;
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000267 bool supportsDesktop() const {
268 return 0 != (kDesktop_GrGLBinding & fBindingsExported);
269 }
270 bool supportsES1() const {
271 return 0 != (kES1_GrGLBinding & fBindingsExported);
272 }
273 bool supportsES2() const {
274 return 0 != (kES2_GrGLBinding & fBindingsExported);
275 }
276 bool supportsES() const {
277 return 0 != ((kES1_GrGLBinding | kES2_GrGLBinding) &
278 fBindingsExported);
279 }
twiz@google.com59a190b2011-03-14 21:23:01 +0000280
twiz@google.comb65e0cb2011-03-18 20:41:44 +0000281 // Indicator variable specifying the type of GL implementation
282 // exported: GLES{1|2} or Desktop.
283 GrGLBinding fBindingsExported;
284
tomhudson@google.com747bf292011-06-14 18:16:52 +0000285 /// Does this GL support NPOT textures on FBOs?
tomhudson@google.come67bd3f2011-06-16 14:08:04 +0000286 /// boolean value, or kProbe_GrGLCapability to probe (slowly) at context creation.
tomhudson@google.com747bf292011-06-14 18:16:52 +0000287 int fNPOTRenderTargetSupport;
288
289 /// Some GL implementations (PowerVR SGX devices like the iPhone 4)
290 /// have restrictions on the size of small render targets.
tomhudson@google.come67bd3f2011-06-16 14:08:04 +0000291 /// kProbe_GrGLCapability to probe (slowly) at context creation.
tomhudson@google.com747bf292011-06-14 18:16:52 +0000292 int fMinRenderTargetHeight;
293 int fMinRenderTargetWidth;
294
twiz@google.com59a190b2011-03-14 21:23:01 +0000295 GrGLActiveTextureProc fActiveTexture;
296 GrGLAttachShaderProc fAttachShader;
bsalomon@google.com373a6632011-10-19 20:43:20 +0000297 GrGLBeginQueryProc fBeginQuery;
twiz@google.com59a190b2011-03-14 21:23:01 +0000298 GrGLBindAttribLocationProc fBindAttribLocation;
299 GrGLBindBufferProc fBindBuffer;
bsalomon@google.combc5cf512011-09-21 16:21:07 +0000300 GrGLBindFragDataLocationProc fBindFragDataLocation;
twiz@google.com59a190b2011-03-14 21:23:01 +0000301 GrGLBindTextureProc fBindTexture;
bsalomon@google.com080773c2011-03-15 19:09:25 +0000302 GrGLBlendColorProc fBlendColor;
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000303 GrGLBlendFuncProc fBlendFunc;
twiz@google.com59a190b2011-03-14 21:23:01 +0000304 GrGLBufferDataProc fBufferData;
305 GrGLBufferSubDataProc fBufferSubData;
306 GrGLClearProc fClear;
307 GrGLClearColorProc fClearColor;
308 GrGLClearStencilProc fClearStencil;
309 GrGLClientActiveTextureProc fClientActiveTexture;
310 GrGLColor4ubProc fColor4ub;
311 GrGLColorMaskProc fColorMask;
312 GrGLColorPointerProc fColorPointer;
313 GrGLCompileShaderProc fCompileShader;
314 GrGLCompressedTexImage2DProc fCompressedTexImage2D;
315 GrGLCreateProgramProc fCreateProgram;
316 GrGLCreateShaderProc fCreateShader;
317 GrGLCullFaceProc fCullFace;
318 GrGLDeleteBuffersProc fDeleteBuffers;
319 GrGLDeleteProgramProc fDeleteProgram;
bsalomon@google.com373a6632011-10-19 20:43:20 +0000320 GrGLDeleteQueriesProc fDeleteQueries;
twiz@google.com59a190b2011-03-14 21:23:01 +0000321 GrGLDeleteShaderProc fDeleteShader;
322 GrGLDeleteTexturesProc fDeleteTextures;
323 GrGLDepthMaskProc fDepthMask;
324 GrGLDisableProc fDisable;
325 GrGLDisableClientStateProc fDisableClientState;
326 GrGLDisableVertexAttribArrayProc fDisableVertexAttribArray;
327 GrGLDrawArraysProc fDrawArrays;
bsalomon@google.comd32c5f52011-08-02 19:29:03 +0000328 GrGLDrawBufferProc fDrawBuffer;
329 GrGLDrawBuffersProc fDrawBuffers;
twiz@google.com59a190b2011-03-14 21:23:01 +0000330 GrGLDrawElementsProc fDrawElements;
331 GrGLEnableProc fEnable;
332 GrGLEnableClientStateProc fEnableClientState;
333 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;
358 GrGLLoadMatrixfProc fLoadMatrixf;
359 GrGLMatrixModeProc fMatrixMode;
360 GrGLPixelStoreiProc fPixelStorei;
361 GrGLPointSizeProc fPointSize;
bsalomon@google.com373a6632011-10-19 20:43:20 +0000362 GrGLQueryCounterProc fQueryCounter;
bsalomon@google.comc49d66b2011-08-03 14:22:30 +0000363 GrGLReadBufferProc fReadBuffer;
twiz@google.com59a190b2011-03-14 21:23:01 +0000364 GrGLReadPixelsProc fReadPixels;
365 GrGLScissorProc fScissor;
366 GrGLShadeModelProc fShadeModel;
367 GrGLShaderSourceProc fShaderSource;
368 GrGLStencilFuncProc fStencilFunc;
369 GrGLStencilFuncSeparateProc fStencilFuncSeparate;
370 GrGLStencilMaskProc fStencilMask;
371 GrGLStencilMaskSeparateProc fStencilMaskSeparate;
372 GrGLStencilOpProc fStencilOp;
373 GrGLStencilOpSeparateProc fStencilOpSeparate;
374 GrGLTexCoordPointerProc fTexCoordPointer;
375 GrGLTexEnviProc fTexEnvi;
376 GrGLTexImage2DProc fTexImage2D;
377 GrGLTexParameteriProc fTexParameteri;
378 GrGLTexSubImage2DProc fTexSubImage2D;
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000379 GrGLUniform1fProc fUniform1f;
twiz@google.com59a190b2011-03-14 21:23:01 +0000380 GrGLUniform1iProc fUniform1i;
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000381 GrGLUniform1fvProc fUniform1fv;
382 GrGLUniform1ivProc fUniform1iv;
383 GrGLUniform2fProc fUniform2f;
384 GrGLUniform2iProc fUniform2i;
385 GrGLUniform2fvProc fUniform2fv;
386 GrGLUniform2ivProc fUniform2iv;
387 GrGLUniform3fProc fUniform3f;
388 GrGLUniform3iProc fUniform3i;
389 GrGLUniform3fvProc fUniform3fv;
390 GrGLUniform3ivProc fUniform3iv;
391 GrGLUniform4fProc fUniform4f;
392 GrGLUniform4iProc fUniform4i;
twiz@google.com59a190b2011-03-14 21:23:01 +0000393 GrGLUniform4fvProc fUniform4fv;
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000394 GrGLUniform4ivProc fUniform4iv;
395 GrGLUniformMatrix2fvProc fUniformMatrix2fv;
twiz@google.com59a190b2011-03-14 21:23:01 +0000396 GrGLUniformMatrix3fvProc fUniformMatrix3fv;
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000397 GrGLUniformMatrix4fvProc fUniformMatrix4fv;
twiz@google.com59a190b2011-03-14 21:23:01 +0000398 GrGLUseProgramProc fUseProgram;
399 GrGLVertexAttrib4fvProc fVertexAttrib4fv;
400 GrGLVertexAttribPointerProc fVertexAttribPointer;
401 GrGLVertexPointerProc fVertexPointer;
402 GrGLViewportProc fViewport;
403
404 // FBO Extension Functions
405 GrGLBindFramebufferProc fBindFramebuffer;
406 GrGLBindRenderbufferProc fBindRenderbuffer;
407 GrGLCheckFramebufferStatusProc fCheckFramebufferStatus;
408 GrGLDeleteFramebuffersProc fDeleteFramebuffers;
409 GrGLDeleteRenderbuffersProc fDeleteRenderbuffers;
410 GrGLFramebufferRenderbufferProc fFramebufferRenderbuffer;
411 GrGLFramebufferTexture2DProc fFramebufferTexture2D;
412 GrGLGenFramebuffersProc fGenFramebuffers;
413 GrGLGenRenderbuffersProc fGenRenderbuffers;
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000414 GrGLGetFramebufferAttachmentParameterivProc fGetFramebufferAttachmentParameteriv;
415 GrGLGetRenderbufferParameterivProc fGetRenderbufferParameteriv;
twiz@google.com59a190b2011-03-14 21:23:01 +0000416 GrGLRenderbufferStorageProc fRenderbufferStorage;
417
418 // Multisampling Extension Functions
419 // same prototype for ARB_FBO, EXT_FBO, GL 3.0, & Apple ES extension
420 GrGLRenderbufferStorageMultisampleProc fRenderbufferStorageMultisample;
421 // desktop: ext_fbo_blit, arb_fbo, gl 3.0
422 GrGLBlitFramebufferProc fBlitFramebuffer;
423 // apple's es extension
424 GrGLResolveMultisampleFramebufferProc fResolveMultisampleFramebuffer;
425
twiz@google.com59a190b2011-03-14 21:23:01 +0000426 // Buffer mapping (extension in ES).
427 GrGLMapBufferProc fMapBuffer;
428 GrGLUnmapBufferProc fUnmapBuffer;
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000429
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000430 // Dual Source Blending
431 GrGLBindFragDataLocationIndexedProc fBindFragDataLocationIndexed;
432
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +0000433 // Per-GL func callback
434#if GR_GL_PER_GL_FUNC_CALLBACK
435 GrGLInterfaceCallbackProc fCallback;
436 GrGLInterfaceCallbackData fCallbackData;
437#endif
438
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000439private:
440 bool validateShaderFunctions() const;
441 bool validateFixedFunctions() const;
442};
twiz@google.com59a190b2011-03-14 21:23:01 +0000443
444#endif