blob: 303a85386a5d9586907a6194307c085e812b0de0 [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.comc82b8892011-09-22 14:10:33 +000027typedef GrFixed GrGLVersion;
28
29#define GR_GL_VER(major, minor) (((int)(major) << 16) | ((int)(minor)))
30
bsalomon@google.com2c17fcd2011-07-06 17:47:02 +000031// these variants assume caller already has a string from glGetString()
bsalomon@google.comc82b8892011-09-22 14:10:33 +000032GrGLVersion GrGLGetVersionFromString(const char* versionString);
33bool GrGLHasExtensionFromString(const char* ext, const char* extensionString);
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000034
bsalomon@google.com2c17fcd2011-07-06 17:47:02 +000035// these variants call glGetString()
bsalomon@google.comc82b8892011-09-22 14:10:33 +000036bool GrGLGetString(const GrGLInterface*, const char* ext);
37GrGLVersion GrGLGetVersion(const GrGLInterface*);
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000038
twiz@google.com59a190b2011-03-14 21:23:01 +000039////////////////////////////////////////////////////////////////////////////////
40
bsalomon@google.com0b77d682011-08-19 13:28:54 +000041/**
42 * Rather than depend on platform-specific GL headers and libraries, we require
43 * the client to provide a struct of GL function pointers. This struct can be
44 * specified per-GrContext as a parameter to GrContext::Create. If NULL is
45 * passed to Create then the "default" GL interface is used. If the default is
46 * also NULL GrContext creation will fail.
47 *
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000048 * The default interface is returned by GrGLDefaultInterface. This function's
49 * implementation is platform-specifc. Several have been provided, along with an
50 * implementation that simply returns NULL. It is implementation-specific
51 * whether the same GrGLInterface is returned or whether a new one is created
52 * at each call. Some platforms may not be able to use a single GrGLInterface
53 * because extension function ptrs vary across contexts. Note that GrGLInterface
54 * is ref-counted. So if the same object is returned by multiple calls to
55 * GrGLDefaultInterface, each should bump the ref count.
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +000056 *
57 * By defining GR_GL_PER_GL_CALL_IFACE_CALLBACK to 1 the client can specify a
58 * callback function that will be called prior to each GL function call. See
59 * comments in GrGLConfig.h
twiz@google.com59a190b2011-03-14 21:23:01 +000060 */
twiz@google.com59a190b2011-03-14 21:23:01 +000061
bsalomon@google.com0b77d682011-08-19 13:28:54 +000062struct GrGLInterface;
63
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000064const GrGLInterface* GrGLDefaultInterface();
twiz@google.com59a190b2011-03-14 21:23:01 +000065
twiz@google.com0f31ca72011-03-18 17:38:11 +000066typedef unsigned int GrGLenum;
67typedef unsigned char GrGLboolean;
68typedef unsigned int GrGLbitfield;
69typedef signed char GrGLbyte;
bsalomon@google.com271cffc2011-05-20 14:13:56 +000070typedef char GrGLchar;
twiz@google.com0f31ca72011-03-18 17:38:11 +000071typedef short GrGLshort;
72typedef int GrGLint;
73typedef int GrGLsizei;
74typedef unsigned char GrGLubyte;
75typedef unsigned short GrGLushort;
76typedef unsigned int GrGLuint;
77typedef float GrGLfloat;
78typedef float GrGLclampf;
79typedef double GrGLdouble;
80typedef double GrGLclampd;
81typedef void GrGLvoid;
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000082typedef long GrGLintptr;
83typedef long GrGLsizeiptr;
twiz@google.com0f31ca72011-03-18 17:38:11 +000084
twiz@google.comb65e0cb2011-03-18 20:41:44 +000085enum GrGLBinding {
86 kDesktop_GrGLBinding = 0x01,
87 kES1_GrGLBinding = 0x02,
88 kES2_GrGLBinding = 0x04
89};
90
twiz@google.com59a190b2011-03-14 21:23:01 +000091extern "C" {
twiz@google.com0f31ca72011-03-18 17:38:11 +000092 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLActiveTextureProc)(GrGLenum texture);
93 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLAttachShaderProc)(GrGLuint program, GrGLuint shader);
94 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindAttribLocationProc)(GrGLuint program, GrGLuint index, const char* name);
95 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindBufferProc)(GrGLenum target, GrGLuint buffer);
96 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindTextureProc)(GrGLenum target, GrGLuint texture);
97 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBlendColorProc)(GrGLclampf red, GrGLclampf green, GrGLclampf blue, GrGLclampf alpha);
bsalomon@google.combc5cf512011-09-21 16:21:07 +000098 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindFragDataLocationProc)(GrGLuint program, GrGLuint colorNumber, const GrGLchar* name);
twiz@google.com0f31ca72011-03-18 17:38:11 +000099 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBlendFuncProc)(GrGLenum sfactor, GrGLenum dfactor);
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000100 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBufferDataProc)(GrGLenum target, GrGLsizeiptr size, const GrGLvoid* data, GrGLenum usage);
101 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBufferSubDataProc)(GrGLenum target, GrGLintptr offset, GrGLsizeiptr size, const GrGLvoid* data);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000102 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClearProc)(GrGLbitfield mask);
103 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClearColorProc)(GrGLclampf red, GrGLclampf green, GrGLclampf blue, GrGLclampf alpha);
104 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClearStencilProc)(GrGLint s);
105 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClientActiveTextureProc)(GrGLenum texture);
106 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLColor4ubProc)(GrGLubyte red, GrGLubyte green, GrGLubyte blue, GrGLubyte alpha);
107 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLColorMaskProc)(GrGLboolean red, GrGLboolean green, GrGLboolean blue, GrGLboolean alpha);
108 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLColorPointerProc)(GrGLint size, GrGLenum type, GrGLsizei stride, const GrGLvoid* pointer);
109 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLCompileShaderProc)(GrGLuint shader);
110 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLCompressedTexImage2DProc)(GrGLenum target, GrGLint level, GrGLenum internalformat, GrGLsizei width, GrGLsizei height, GrGLint border, GrGLsizei imageSize, const GrGLvoid* data);
111 typedef GrGLuint (GR_GL_FUNCTION_TYPE *GrGLCreateProgramProc)(void);
112 typedef GrGLuint (GR_GL_FUNCTION_TYPE *GrGLCreateShaderProc)(GrGLenum type);
113 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLCullFaceProc)(GrGLenum mode);
114 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteBuffersProc)(GrGLsizei n, const GrGLuint* buffers);
115 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteProgramProc)(GrGLuint program);
116 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteShaderProc)(GrGLuint shader);
117 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteTexturesProc)(GrGLsizei n, const GrGLuint* textures);
118 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDepthMaskProc)(GrGLboolean flag);
119 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDisableProc)(GrGLenum cap);
120 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDisableClientStateProc)(GrGLenum array);
121 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDisableVertexAttribArrayProc)(GrGLuint index);
122 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawArraysProc)(GrGLenum mode, GrGLint first, GrGLsizei count);
bsalomon@google.comd32c5f52011-08-02 19:29:03 +0000123 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawBufferProc)(GrGLenum mode);
124 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawBuffersProc)(GrGLsizei n, const GrGLenum* bufs);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000125 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawElementsProc)(GrGLenum mode, GrGLsizei count, GrGLenum type, const GrGLvoid* indices);
126 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLEnableProc)(GrGLenum cap);
127 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLEnableClientStateProc)(GrGLenum cap);
128 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLEnableVertexAttribArrayProc)(GrGLuint index);
129 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFrontFaceProc)(GrGLenum mode);
130 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenBuffersProc)(GrGLsizei n, GrGLuint* buffers);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000131 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenTexturesProc)(GrGLsizei n, GrGLuint* textures);
132 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetBufferParameterivProc)(GrGLenum target, GrGLenum pname, GrGLint* params);
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000133 typedef GrGLenum (GR_GL_FUNCTION_TYPE *GrGLGetErrorProc)(void);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000134 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetIntegervProc)(GrGLenum pname, GrGLint* params);
135 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetProgramInfoLogProc)(GrGLuint program, GrGLsizei bufsize, GrGLsizei* length, char* infolog);
136 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetProgramivProc)(GrGLuint program, GrGLenum pname, GrGLint* params);
137 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetShaderInfoLogProc)(GrGLuint shader, GrGLsizei bufsize, GrGLsizei* length, char* infolog);
138 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetShaderivProc)(GrGLuint shader, GrGLenum pname, GrGLint* params);
139 typedef const GrGLubyte* (GR_GL_FUNCTION_TYPE *GrGLGetStringProc)(GrGLenum name);
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000140 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetTexLevelParameteriv)(GrGLenum target, GrGLint level, GrGLenum pname, GrGLint* params);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000141 typedef GrGLint (GR_GL_FUNCTION_TYPE *GrGLGetUniformLocationProc)(GrGLuint program, const char* name);
142 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLLineWidthProc)(GrGLfloat width);
143 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLLinkProgramProc)(GrGLuint program);
144 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLLoadMatrixfProc)(const GrGLfloat* m);
145 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLMatrixModeProc)(GrGLenum mode);
146 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLPixelStoreiProc)(GrGLenum pname, GrGLint param);
147 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLPointSizeProc)(GrGLfloat size);
bsalomon@google.comc49d66b2011-08-03 14:22:30 +0000148 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLReadBufferProc)(GrGLenum src);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000149 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLReadPixelsProc)(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height, GrGLenum format, GrGLenum type, GrGLvoid* pixels);
150 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLScissorProc)(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height);
151 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLShadeModelProc)(GrGLenum mode);
152 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLShaderSourceProc)(GrGLuint shader, GrGLsizei count, const char** str, const GrGLint* length);
153 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilFuncProc)(GrGLenum func, GrGLint ref, GrGLuint mask);
154 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilFuncSeparateProc)(GrGLenum face, GrGLenum func, GrGLint ref, GrGLuint mask);
155 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilMaskProc)(GrGLuint mask);
156 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilMaskSeparateProc)(GrGLenum face, GrGLuint mask);
157 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilOpProc)(GrGLenum fail, GrGLenum zfail, GrGLenum zpass);
158 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilOpSeparateProc)(GrGLenum face, GrGLenum fail, GrGLenum zfail, GrGLenum zpass);
159 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexCoordPointerProc)(GrGLint size, GrGLenum type, GrGLsizei stride, const GrGLvoid* pointer);
160 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexEnviProc)(GrGLenum target, GrGLenum pname, GrGLint param);
161 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);
162 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexParameteriProc)(GrGLenum target, GrGLenum pname, GrGLint param);
163 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 +0000164 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1fProc)(GrGLint location, GrGLfloat v0);
165 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1iProc)(GrGLint location, GrGLint v0);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000166 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1fvProc)(GrGLint location, GrGLsizei count, const GrGLfloat* v);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000167 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1ivProc)(GrGLint location, GrGLsizei count, const GrGLint* v);
168 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform2fProc)(GrGLint location, GrGLfloat v0, GrGLfloat v1);
169 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform2iProc)(GrGLint location, GrGLint v0, GrGLint v1);
170 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform2fvProc)(GrGLint location, GrGLsizei count, const GrGLfloat* v);
171 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform2ivProc)(GrGLint location, GrGLsizei count, const GrGLint* v);
172 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform3fProc)(GrGLint location, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2);
173 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform3iProc)(GrGLint location, GrGLint v0, GrGLint v1, GrGLint v2);
174 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform3fvProc)(GrGLint location, GrGLsizei count, const GrGLfloat* v);
175 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform3ivProc)(GrGLint location, GrGLsizei count, const GrGLint* v);
176 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform4fProc)(GrGLint location, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2, GrGLfloat v3);
177 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 +0000178 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform4fvProc)(GrGLint location, GrGLsizei count, const GrGLfloat* v);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000179 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform4ivProc)(GrGLint location, GrGLsizei count, const GrGLint* v);
180 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniformMatrix2fvProc)(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000181 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniformMatrix3fvProc)(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000182 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniformMatrix4fvProc)(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000183 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUseProgramProc)(GrGLuint program);
184 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLVertexAttrib4fvProc)(GrGLuint indx, const GrGLfloat* values);
185 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLVertexAttribPointerProc)(GrGLuint indx, GrGLint size, GrGLenum type, GrGLboolean normalized, GrGLsizei stride, const GrGLvoid* ptr);
186 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLVertexPointerProc)(GrGLint size, GrGLenum type, GrGLsizei stride, const GrGLvoid* pointer);
187 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLViewportProc)(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height);
twiz@google.com59a190b2011-03-14 21:23:01 +0000188
189 // FBO Extension Functions
twiz@google.com0f31ca72011-03-18 17:38:11 +0000190 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindFramebufferProc)(GrGLenum target, GrGLuint framebuffer);
191 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindRenderbufferProc)(GrGLenum target, GrGLuint renderbuffer);
192 typedef GrGLenum (GR_GL_FUNCTION_TYPE *GrGLCheckFramebufferStatusProc)(GrGLenum target);
193 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteFramebuffersProc)(GrGLsizei n, const GrGLuint *framebuffers);
194 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteRenderbuffersProc)(GrGLsizei n, const GrGLuint *renderbuffers);
195 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFramebufferRenderbufferProc)(GrGLenum target, GrGLenum attachment, GrGLenum renderbuffertarget, GrGLuint renderbuffer);
196 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFramebufferTexture2DProc)(GrGLenum target, GrGLenum attachment, GrGLenum textarget, GrGLuint texture, GrGLint level);
197 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenFramebuffersProc)(GrGLsizei n, GrGLuint *framebuffers);
198 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenRenderbuffersProc)(GrGLsizei n, GrGLuint *renderbuffers);
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000199 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetFramebufferAttachmentParameterivProc)(GrGLenum target, GrGLenum attachment, GrGLenum pname, GrGLint* params);
200 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetRenderbufferParameterivProc)(GrGLenum target, GrGLenum pname, GrGLint* params);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000201 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLRenderbufferStorageProc)(GrGLenum target, GrGLenum internalformat, GrGLsizei width, GrGLsizei height);
twiz@google.com59a190b2011-03-14 21:23:01 +0000202
203 // Multisampling Extension Functions
204 // same prototype for ARB_FBO, EXT_FBO, GL 3.0, & Apple ES extension
twiz@google.com0f31ca72011-03-18 17:38:11 +0000205 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 +0000206 // desktop: ext_fbo_blit, arb_fbo, gl 3.0
twiz@google.com0f31ca72011-03-18 17:38:11 +0000207 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 +0000208 // apple's es extension
twiz@google.com0f31ca72011-03-18 17:38:11 +0000209 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLResolveMultisampleFramebufferProc)();
twiz@google.com59a190b2011-03-14 21:23:01 +0000210
twiz@google.com59a190b2011-03-14 21:23:01 +0000211 // Buffer mapping (extension in ES).
twiz@google.com0f31ca72011-03-18 17:38:11 +0000212 typedef GrGLvoid* (GR_GL_FUNCTION_TYPE *GrGLMapBufferProc)(GrGLenum target, GrGLenum access);
213 typedef GrGLboolean (GR_GL_FUNCTION_TYPE *GrGLUnmapBufferProc)(GrGLenum target);
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000214
215 // Dual source blending
216 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindFragDataLocationIndexedProc)(GrGLuint program, GrGLuint colorNumber, GrGLuint index, const GrGLchar * name);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000217} // extern "C"
218
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +0000219#if GR_GL_PER_GL_FUNC_CALLBACK
220typedef void (*GrGLInterfaceCallbackProc)(const GrGLInterface*);
221typedef intptr_t GrGLInterfaceCallbackData;
222#endif
223
224
tomhudson@google.come67bd3f2011-06-16 14:08:04 +0000225enum GrGLCapability {
226 kProbe_GrGLCapability = -1
tomhudson@google.com30e4bb62011-06-15 19:41:46 +0000227};
228
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000229/*
230 * The following interface exports the OpenGL entry points used by the system.
231 * Use of OpenGL calls is disallowed. All calls should be invoked through
232 * the global instance of this struct, defined above.
233 *
234 * IMPORTANT NOTE: The OpenGL entry points exposed here include both core GL
235 * functions, and extensions. The system assumes that the address of the
236 * extension pointer will be valid across contexts.
237 */
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000238struct GR_API GrGLInterface : public GrRefCnt {
239
240 GrGLInterface();
241
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000242 bool validate(GrEngine engine) const;
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000243 bool supportsDesktop() const {
244 return 0 != (kDesktop_GrGLBinding & fBindingsExported);
245 }
246 bool supportsES1() const {
247 return 0 != (kES1_GrGLBinding & fBindingsExported);
248 }
249 bool supportsES2() const {
250 return 0 != (kES2_GrGLBinding & fBindingsExported);
251 }
252 bool supportsES() const {
253 return 0 != ((kES1_GrGLBinding | kES2_GrGLBinding) &
254 fBindingsExported);
255 }
twiz@google.com59a190b2011-03-14 21:23:01 +0000256
twiz@google.comb65e0cb2011-03-18 20:41:44 +0000257 // Indicator variable specifying the type of GL implementation
258 // exported: GLES{1|2} or Desktop.
259 GrGLBinding fBindingsExported;
260
tomhudson@google.com747bf292011-06-14 18:16:52 +0000261 /// Does this GL support NPOT textures on FBOs?
tomhudson@google.come67bd3f2011-06-16 14:08:04 +0000262 /// boolean value, or kProbe_GrGLCapability to probe (slowly) at context creation.
tomhudson@google.com747bf292011-06-14 18:16:52 +0000263 int fNPOTRenderTargetSupport;
264
265 /// Some GL implementations (PowerVR SGX devices like the iPhone 4)
266 /// have restrictions on the size of small render targets.
tomhudson@google.come67bd3f2011-06-16 14:08:04 +0000267 /// kProbe_GrGLCapability to probe (slowly) at context creation.
tomhudson@google.com747bf292011-06-14 18:16:52 +0000268 int fMinRenderTargetHeight;
269 int fMinRenderTargetWidth;
270
twiz@google.com59a190b2011-03-14 21:23:01 +0000271 GrGLActiveTextureProc fActiveTexture;
272 GrGLAttachShaderProc fAttachShader;
273 GrGLBindAttribLocationProc fBindAttribLocation;
274 GrGLBindBufferProc fBindBuffer;
bsalomon@google.combc5cf512011-09-21 16:21:07 +0000275 GrGLBindFragDataLocationProc fBindFragDataLocation;
twiz@google.com59a190b2011-03-14 21:23:01 +0000276 GrGLBindTextureProc fBindTexture;
bsalomon@google.com080773c2011-03-15 19:09:25 +0000277 GrGLBlendColorProc fBlendColor;
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000278 GrGLBlendFuncProc fBlendFunc;
twiz@google.com59a190b2011-03-14 21:23:01 +0000279 GrGLBufferDataProc fBufferData;
280 GrGLBufferSubDataProc fBufferSubData;
281 GrGLClearProc fClear;
282 GrGLClearColorProc fClearColor;
283 GrGLClearStencilProc fClearStencil;
284 GrGLClientActiveTextureProc fClientActiveTexture;
285 GrGLColor4ubProc fColor4ub;
286 GrGLColorMaskProc fColorMask;
287 GrGLColorPointerProc fColorPointer;
288 GrGLCompileShaderProc fCompileShader;
289 GrGLCompressedTexImage2DProc fCompressedTexImage2D;
290 GrGLCreateProgramProc fCreateProgram;
291 GrGLCreateShaderProc fCreateShader;
292 GrGLCullFaceProc fCullFace;
293 GrGLDeleteBuffersProc fDeleteBuffers;
294 GrGLDeleteProgramProc fDeleteProgram;
295 GrGLDeleteShaderProc fDeleteShader;
296 GrGLDeleteTexturesProc fDeleteTextures;
297 GrGLDepthMaskProc fDepthMask;
298 GrGLDisableProc fDisable;
299 GrGLDisableClientStateProc fDisableClientState;
300 GrGLDisableVertexAttribArrayProc fDisableVertexAttribArray;
301 GrGLDrawArraysProc fDrawArrays;
bsalomon@google.comd32c5f52011-08-02 19:29:03 +0000302 GrGLDrawBufferProc fDrawBuffer;
303 GrGLDrawBuffersProc fDrawBuffers;
twiz@google.com59a190b2011-03-14 21:23:01 +0000304 GrGLDrawElementsProc fDrawElements;
305 GrGLEnableProc fEnable;
306 GrGLEnableClientStateProc fEnableClientState;
307 GrGLEnableVertexAttribArrayProc fEnableVertexAttribArray;
308 GrGLFrontFaceProc fFrontFace;
309 GrGLGenBuffersProc fGenBuffers;
310 GrGLGenTexturesProc fGenTextures;
311 GrGLGetBufferParameterivProc fGetBufferParameteriv;
312 GrGLGetErrorProc fGetError;
313 GrGLGetIntegervProc fGetIntegerv;
314 GrGLGetProgramInfoLogProc fGetProgramInfoLog;
315 GrGLGetProgramivProc fGetProgramiv;
316 GrGLGetShaderInfoLogProc fGetShaderInfoLog;
317 GrGLGetShaderivProc fGetShaderiv;
318 GrGLGetStringProc fGetString;
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000319 GrGLGetTexLevelParameteriv fGetTexLevelParameteriv;
twiz@google.com59a190b2011-03-14 21:23:01 +0000320 GrGLGetUniformLocationProc fGetUniformLocation;
321 GrGLLineWidthProc fLineWidth;
322 GrGLLinkProgramProc fLinkProgram;
323 GrGLLoadMatrixfProc fLoadMatrixf;
324 GrGLMatrixModeProc fMatrixMode;
325 GrGLPixelStoreiProc fPixelStorei;
326 GrGLPointSizeProc fPointSize;
bsalomon@google.comc49d66b2011-08-03 14:22:30 +0000327 GrGLReadBufferProc fReadBuffer;
twiz@google.com59a190b2011-03-14 21:23:01 +0000328 GrGLReadPixelsProc fReadPixels;
329 GrGLScissorProc fScissor;
330 GrGLShadeModelProc fShadeModel;
331 GrGLShaderSourceProc fShaderSource;
332 GrGLStencilFuncProc fStencilFunc;
333 GrGLStencilFuncSeparateProc fStencilFuncSeparate;
334 GrGLStencilMaskProc fStencilMask;
335 GrGLStencilMaskSeparateProc fStencilMaskSeparate;
336 GrGLStencilOpProc fStencilOp;
337 GrGLStencilOpSeparateProc fStencilOpSeparate;
338 GrGLTexCoordPointerProc fTexCoordPointer;
339 GrGLTexEnviProc fTexEnvi;
340 GrGLTexImage2DProc fTexImage2D;
341 GrGLTexParameteriProc fTexParameteri;
342 GrGLTexSubImage2DProc fTexSubImage2D;
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000343 GrGLUniform1fProc fUniform1f;
twiz@google.com59a190b2011-03-14 21:23:01 +0000344 GrGLUniform1iProc fUniform1i;
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000345 GrGLUniform1fvProc fUniform1fv;
346 GrGLUniform1ivProc fUniform1iv;
347 GrGLUniform2fProc fUniform2f;
348 GrGLUniform2iProc fUniform2i;
349 GrGLUniform2fvProc fUniform2fv;
350 GrGLUniform2ivProc fUniform2iv;
351 GrGLUniform3fProc fUniform3f;
352 GrGLUniform3iProc fUniform3i;
353 GrGLUniform3fvProc fUniform3fv;
354 GrGLUniform3ivProc fUniform3iv;
355 GrGLUniform4fProc fUniform4f;
356 GrGLUniform4iProc fUniform4i;
twiz@google.com59a190b2011-03-14 21:23:01 +0000357 GrGLUniform4fvProc fUniform4fv;
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000358 GrGLUniform4ivProc fUniform4iv;
359 GrGLUniformMatrix2fvProc fUniformMatrix2fv;
twiz@google.com59a190b2011-03-14 21:23:01 +0000360 GrGLUniformMatrix3fvProc fUniformMatrix3fv;
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000361 GrGLUniformMatrix4fvProc fUniformMatrix4fv;
twiz@google.com59a190b2011-03-14 21:23:01 +0000362 GrGLUseProgramProc fUseProgram;
363 GrGLVertexAttrib4fvProc fVertexAttrib4fv;
364 GrGLVertexAttribPointerProc fVertexAttribPointer;
365 GrGLVertexPointerProc fVertexPointer;
366 GrGLViewportProc fViewport;
367
368 // FBO Extension Functions
369 GrGLBindFramebufferProc fBindFramebuffer;
370 GrGLBindRenderbufferProc fBindRenderbuffer;
371 GrGLCheckFramebufferStatusProc fCheckFramebufferStatus;
372 GrGLDeleteFramebuffersProc fDeleteFramebuffers;
373 GrGLDeleteRenderbuffersProc fDeleteRenderbuffers;
374 GrGLFramebufferRenderbufferProc fFramebufferRenderbuffer;
375 GrGLFramebufferTexture2DProc fFramebufferTexture2D;
376 GrGLGenFramebuffersProc fGenFramebuffers;
377 GrGLGenRenderbuffersProc fGenRenderbuffers;
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000378 GrGLGetFramebufferAttachmentParameterivProc fGetFramebufferAttachmentParameteriv;
379 GrGLGetRenderbufferParameterivProc fGetRenderbufferParameteriv;
twiz@google.com59a190b2011-03-14 21:23:01 +0000380 GrGLRenderbufferStorageProc fRenderbufferStorage;
381
382 // Multisampling Extension Functions
383 // same prototype for ARB_FBO, EXT_FBO, GL 3.0, & Apple ES extension
384 GrGLRenderbufferStorageMultisampleProc fRenderbufferStorageMultisample;
385 // desktop: ext_fbo_blit, arb_fbo, gl 3.0
386 GrGLBlitFramebufferProc fBlitFramebuffer;
387 // apple's es extension
388 GrGLResolveMultisampleFramebufferProc fResolveMultisampleFramebuffer;
389
twiz@google.com59a190b2011-03-14 21:23:01 +0000390 // Buffer mapping (extension in ES).
391 GrGLMapBufferProc fMapBuffer;
392 GrGLUnmapBufferProc fUnmapBuffer;
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000393
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000394 // Dual Source Blending
395 GrGLBindFragDataLocationIndexedProc fBindFragDataLocationIndexed;
396
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +0000397 // Per-GL func callback
398#if GR_GL_PER_GL_FUNC_CALLBACK
399 GrGLInterfaceCallbackProc fCallback;
400 GrGLInterfaceCallbackData fCallbackData;
401#endif
402
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000403private:
404 bool validateShaderFunctions() const;
405 bool validateFixedFunctions() const;
406};
twiz@google.com59a190b2011-03-14 21:23:01 +0000407
408#endif