blob: c959c36c59c4c2b06c62ed25f18cf04f8f250df4 [file] [log] [blame]
twiz@google.com59a190b2011-03-14 21:23:01 +00001/*
2 Copyright 2011 Google Inc.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17
18#ifndef GrGLInterface_DEFINED
19#define GrGLInterface_DEFINED
20
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000021#include "GrGLConfig.h"
bsalomon@google.combf2a4692011-05-04 12:35:39 +000022#include "GrTypes.h"
twiz@google.com59a190b2011-03-14 21:23:01 +000023
24#if !defined(GR_GL_FUNCTION_TYPE)
25 #define GR_GL_FUNCTION_TYPE
26#endif
27
28////////////////////////////////////////////////////////////////////////////////
29
30/**
31 * Helpers for glGetString()
32 */
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000033
bsalomon@google.com2c17fcd2011-07-06 17:47:02 +000034// these variants assume caller already has a string from glGetString()
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000035void gl_version_from_string(int* major, int* minor,
36 const char* versionString);
bsalomon@google.com2c17fcd2011-07-06 17:47:02 +000037float gl_version_as_float_from_string(const char* versionString);
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000038bool has_gl_extension_from_string(const char* ext,
39 const char* extensionString);
40
bsalomon@google.com2c17fcd2011-07-06 17:47:02 +000041// these variants call glGetString()
twiz@google.com59a190b2011-03-14 21:23:01 +000042bool has_gl_extension(const char* ext);
43void gl_version(int* major, int* minor);
bsalomon@google.com2c17fcd2011-07-06 17:47:02 +000044float gl_version_as_float();
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000045
twiz@google.com59a190b2011-03-14 21:23:01 +000046////////////////////////////////////////////////////////////////////////////////
47
48/*
49 * Routines managing the global interface used to invoke OpenGL calls.
50 */
51struct GrGLInterface;
bsalomon@google.com91826102011-03-21 19:51:57 +000052GR_API GrGLInterface* GrGLGetGLInterface();
53GR_API void GrGLSetGLInterface(GrGLInterface* gl_interface);
twiz@google.com59a190b2011-03-14 21:23:01 +000054
55/*
tomhudson@google.com747bf292011-06-14 18:16:52 +000056 * This is called when GrGLSetGLInterface() hasn't been called before creating
57 * a GrGpuGL object. It provides a default implementation. The actual
58 * implementation depends on which GrGLDefaultInterface_*.cpp has been linked.
59 * There are some platform-specific implementations provided as well as
60 * GrGLDefaultInterface_none.cpp which does nothing (effectively requiring an
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000061 * explicit GrGLSetGLInterface call by the host).
twiz@google.com59a190b2011-03-14 21:23:01 +000062 */
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000063void GrGLSetDefaultGLInterface();
twiz@google.com59a190b2011-03-14 21:23:01 +000064
twiz@google.com0f31ca72011-03-18 17:38:11 +000065typedef unsigned int GrGLenum;
66typedef unsigned char GrGLboolean;
67typedef unsigned int GrGLbitfield;
68typedef signed char GrGLbyte;
bsalomon@google.com271cffc2011-05-20 14:13:56 +000069typedef char GrGLchar;
twiz@google.com0f31ca72011-03-18 17:38:11 +000070typedef short GrGLshort;
71typedef int GrGLint;
72typedef int GrGLsizei;
73typedef unsigned char GrGLubyte;
74typedef unsigned short GrGLushort;
75typedef unsigned int GrGLuint;
76typedef float GrGLfloat;
77typedef float GrGLclampf;
78typedef double GrGLdouble;
79typedef double GrGLclampd;
80typedef void GrGLvoid;
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000081typedef long GrGLintptr;
82typedef long GrGLsizeiptr;
twiz@google.com0f31ca72011-03-18 17:38:11 +000083
twiz@google.comb65e0cb2011-03-18 20:41:44 +000084enum GrGLBinding {
85 kDesktop_GrGLBinding = 0x01,
86 kES1_GrGLBinding = 0x02,
87 kES2_GrGLBinding = 0x04
88};
89
twiz@google.com59a190b2011-03-14 21:23:01 +000090extern "C" {
twiz@google.com0f31ca72011-03-18 17:38:11 +000091 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLActiveTextureProc)(GrGLenum texture);
92 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLAttachShaderProc)(GrGLuint program, GrGLuint shader);
93 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindAttribLocationProc)(GrGLuint program, GrGLuint index, const char* name);
94 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindBufferProc)(GrGLenum target, GrGLuint buffer);
95 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindTextureProc)(GrGLenum target, GrGLuint texture);
96 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBlendColorProc)(GrGLclampf red, GrGLclampf green, GrGLclampf blue, GrGLclampf alpha);
97 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBlendFuncProc)(GrGLenum sfactor, GrGLenum dfactor);
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000098 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBufferDataProc)(GrGLenum target, GrGLsizeiptr size, const GrGLvoid* data, GrGLenum usage);
99 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBufferSubDataProc)(GrGLenum target, GrGLintptr offset, GrGLsizeiptr size, const GrGLvoid* data);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000100 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClearProc)(GrGLbitfield mask);
101 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClearColorProc)(GrGLclampf red, GrGLclampf green, GrGLclampf blue, GrGLclampf alpha);
102 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClearStencilProc)(GrGLint s);
103 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClientActiveTextureProc)(GrGLenum texture);
104 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLColor4ubProc)(GrGLubyte red, GrGLubyte green, GrGLubyte blue, GrGLubyte alpha);
105 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLColorMaskProc)(GrGLboolean red, GrGLboolean green, GrGLboolean blue, GrGLboolean alpha);
106 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLColorPointerProc)(GrGLint size, GrGLenum type, GrGLsizei stride, const GrGLvoid* pointer);
107 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLCompileShaderProc)(GrGLuint shader);
108 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLCompressedTexImage2DProc)(GrGLenum target, GrGLint level, GrGLenum internalformat, GrGLsizei width, GrGLsizei height, GrGLint border, GrGLsizei imageSize, const GrGLvoid* data);
109 typedef GrGLuint (GR_GL_FUNCTION_TYPE *GrGLCreateProgramProc)(void);
110 typedef GrGLuint (GR_GL_FUNCTION_TYPE *GrGLCreateShaderProc)(GrGLenum type);
111 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLCullFaceProc)(GrGLenum mode);
112 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteBuffersProc)(GrGLsizei n, const GrGLuint* buffers);
113 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteProgramProc)(GrGLuint program);
114 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteShaderProc)(GrGLuint shader);
115 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteTexturesProc)(GrGLsizei n, const GrGLuint* textures);
116 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDepthMaskProc)(GrGLboolean flag);
117 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDisableProc)(GrGLenum cap);
118 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDisableClientStateProc)(GrGLenum array);
119 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDisableVertexAttribArrayProc)(GrGLuint index);
120 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawArraysProc)(GrGLenum mode, GrGLint first, GrGLsizei count);
121 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawElementsProc)(GrGLenum mode, GrGLsizei count, GrGLenum type, const GrGLvoid* indices);
122 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLEnableProc)(GrGLenum cap);
123 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLEnableClientStateProc)(GrGLenum cap);
124 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLEnableVertexAttribArrayProc)(GrGLuint index);
125 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFrontFaceProc)(GrGLenum mode);
126 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenBuffersProc)(GrGLsizei n, GrGLuint* buffers);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000127 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenTexturesProc)(GrGLsizei n, GrGLuint* textures);
128 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetBufferParameterivProc)(GrGLenum target, GrGLenum pname, GrGLint* params);
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000129 typedef GrGLenum (GR_GL_FUNCTION_TYPE *GrGLGetErrorProc)(void);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000130 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetIntegervProc)(GrGLenum pname, GrGLint* params);
131 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetProgramInfoLogProc)(GrGLuint program, GrGLsizei bufsize, GrGLsizei* length, char* infolog);
132 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetProgramivProc)(GrGLuint program, GrGLenum pname, GrGLint* params);
133 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetShaderInfoLogProc)(GrGLuint shader, GrGLsizei bufsize, GrGLsizei* length, char* infolog);
134 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetShaderivProc)(GrGLuint shader, GrGLenum pname, GrGLint* params);
135 typedef const GrGLubyte* (GR_GL_FUNCTION_TYPE *GrGLGetStringProc)(GrGLenum name);
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000136 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetTexLevelParameteriv)(GrGLenum target, GrGLint level, GrGLenum pname, GrGLint* params);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000137 typedef GrGLint (GR_GL_FUNCTION_TYPE *GrGLGetUniformLocationProc)(GrGLuint program, const char* name);
138 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLLineWidthProc)(GrGLfloat width);
139 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLLinkProgramProc)(GrGLuint program);
140 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLLoadMatrixfProc)(const GrGLfloat* m);
141 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLMatrixModeProc)(GrGLenum mode);
142 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLPixelStoreiProc)(GrGLenum pname, GrGLint param);
143 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLPointSizeProc)(GrGLfloat size);
144 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLReadPixelsProc)(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height, GrGLenum format, GrGLenum type, GrGLvoid* pixels);
145 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLScissorProc)(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height);
146 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLShadeModelProc)(GrGLenum mode);
147 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLShaderSourceProc)(GrGLuint shader, GrGLsizei count, const char** str, const GrGLint* length);
148 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilFuncProc)(GrGLenum func, GrGLint ref, GrGLuint mask);
149 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilFuncSeparateProc)(GrGLenum face, GrGLenum func, GrGLint ref, GrGLuint mask);
150 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilMaskProc)(GrGLuint mask);
151 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilMaskSeparateProc)(GrGLenum face, GrGLuint mask);
152 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilOpProc)(GrGLenum fail, GrGLenum zfail, GrGLenum zpass);
153 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilOpSeparateProc)(GrGLenum face, GrGLenum fail, GrGLenum zfail, GrGLenum zpass);
154 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexCoordPointerProc)(GrGLint size, GrGLenum type, GrGLsizei stride, const GrGLvoid* pointer);
155 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexEnviProc)(GrGLenum target, GrGLenum pname, GrGLint param);
156 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);
157 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexParameteriProc)(GrGLenum target, GrGLenum pname, GrGLint param);
158 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 +0000159 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1fProc)(GrGLint location, GrGLfloat v0);
160 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1iProc)(GrGLint location, GrGLint v0);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000161 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1fvProc)(GrGLint location, GrGLsizei count, const GrGLfloat* v);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000162 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1ivProc)(GrGLint location, GrGLsizei count, const GrGLint* v);
163 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform2fProc)(GrGLint location, GrGLfloat v0, GrGLfloat v1);
164 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform2iProc)(GrGLint location, GrGLint v0, GrGLint v1);
165 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform2fvProc)(GrGLint location, GrGLsizei count, const GrGLfloat* v);
166 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform2ivProc)(GrGLint location, GrGLsizei count, const GrGLint* v);
167 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform3fProc)(GrGLint location, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2);
168 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform3iProc)(GrGLint location, GrGLint v0, GrGLint v1, GrGLint v2);
169 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform3fvProc)(GrGLint location, GrGLsizei count, const GrGLfloat* v);
170 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform3ivProc)(GrGLint location, GrGLsizei count, const GrGLint* v);
171 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform4fProc)(GrGLint location, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2, GrGLfloat v3);
172 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 +0000173 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform4fvProc)(GrGLint location, GrGLsizei count, const GrGLfloat* v);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000174 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform4ivProc)(GrGLint location, GrGLsizei count, const GrGLint* v);
175 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniformMatrix2fvProc)(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000176 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniformMatrix3fvProc)(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000177 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniformMatrix4fvProc)(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000178 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUseProgramProc)(GrGLuint program);
179 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLVertexAttrib4fvProc)(GrGLuint indx, const GrGLfloat* values);
180 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLVertexAttribPointerProc)(GrGLuint indx, GrGLint size, GrGLenum type, GrGLboolean normalized, GrGLsizei stride, const GrGLvoid* ptr);
181 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLVertexPointerProc)(GrGLint size, GrGLenum type, GrGLsizei stride, const GrGLvoid* pointer);
182 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLViewportProc)(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height);
twiz@google.com59a190b2011-03-14 21:23:01 +0000183
184 // FBO Extension Functions
twiz@google.com0f31ca72011-03-18 17:38:11 +0000185 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindFramebufferProc)(GrGLenum target, GrGLuint framebuffer);
186 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindRenderbufferProc)(GrGLenum target, GrGLuint renderbuffer);
187 typedef GrGLenum (GR_GL_FUNCTION_TYPE *GrGLCheckFramebufferStatusProc)(GrGLenum target);
188 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteFramebuffersProc)(GrGLsizei n, const GrGLuint *framebuffers);
189 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteRenderbuffersProc)(GrGLsizei n, const GrGLuint *renderbuffers);
190 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFramebufferRenderbufferProc)(GrGLenum target, GrGLenum attachment, GrGLenum renderbuffertarget, GrGLuint renderbuffer);
191 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFramebufferTexture2DProc)(GrGLenum target, GrGLenum attachment, GrGLenum textarget, GrGLuint texture, GrGLint level);
192 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenFramebuffersProc)(GrGLsizei n, GrGLuint *framebuffers);
193 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenRenderbuffersProc)(GrGLsizei n, GrGLuint *renderbuffers);
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000194 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetFramebufferAttachmentParameterivProc)(GrGLenum target, GrGLenum attachment, GrGLenum pname, GrGLint* params);
195 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetRenderbufferParameterivProc)(GrGLenum target, GrGLenum pname, GrGLint* params);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000196 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLRenderbufferStorageProc)(GrGLenum target, GrGLenum internalformat, GrGLsizei width, GrGLsizei height);
twiz@google.com59a190b2011-03-14 21:23:01 +0000197
198 // Multisampling Extension Functions
199 // same prototype for ARB_FBO, EXT_FBO, GL 3.0, & Apple ES extension
twiz@google.com0f31ca72011-03-18 17:38:11 +0000200 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 +0000201 // desktop: ext_fbo_blit, arb_fbo, gl 3.0
twiz@google.com0f31ca72011-03-18 17:38:11 +0000202 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 +0000203 // apple's es extension
twiz@google.com0f31ca72011-03-18 17:38:11 +0000204 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLResolveMultisampleFramebufferProc)();
twiz@google.com59a190b2011-03-14 21:23:01 +0000205
twiz@google.com59a190b2011-03-14 21:23:01 +0000206 // Buffer mapping (extension in ES).
twiz@google.com0f31ca72011-03-18 17:38:11 +0000207 typedef GrGLvoid* (GR_GL_FUNCTION_TYPE *GrGLMapBufferProc)(GrGLenum target, GrGLenum access);
208 typedef GrGLboolean (GR_GL_FUNCTION_TYPE *GrGLUnmapBufferProc)(GrGLenum target);
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000209
210 // Dual source blending
211 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindFragDataLocationIndexedProc)(GrGLuint program, GrGLuint colorNumber, GrGLuint index, const GrGLchar * name);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000212} // extern "C"
213
tomhudson@google.come67bd3f2011-06-16 14:08:04 +0000214enum GrGLCapability {
215 kProbe_GrGLCapability = -1
tomhudson@google.com30e4bb62011-06-15 19:41:46 +0000216};
217
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000218/*
219 * The following interface exports the OpenGL entry points used by the system.
220 * Use of OpenGL calls is disallowed. All calls should be invoked through
221 * the global instance of this struct, defined above.
222 *
223 * IMPORTANT NOTE: The OpenGL entry points exposed here include both core GL
224 * functions, and extensions. The system assumes that the address of the
225 * extension pointer will be valid across contexts.
226 */
227struct GrGLInterface {
228 bool validate(GrEngine engine) const;
twiz@google.com59a190b2011-03-14 21:23:01 +0000229
twiz@google.comb65e0cb2011-03-18 20:41:44 +0000230 // Indicator variable specifying the type of GL implementation
231 // exported: GLES{1|2} or Desktop.
232 GrGLBinding fBindingsExported;
233
tomhudson@google.com747bf292011-06-14 18:16:52 +0000234 /// Does this GL support NPOT textures on FBOs?
tomhudson@google.come67bd3f2011-06-16 14:08:04 +0000235 /// boolean value, or kProbe_GrGLCapability to probe (slowly) at context creation.
tomhudson@google.com747bf292011-06-14 18:16:52 +0000236 int fNPOTRenderTargetSupport;
237
238 /// Some GL implementations (PowerVR SGX devices like the iPhone 4)
239 /// have restrictions on the size of small render targets.
tomhudson@google.come67bd3f2011-06-16 14:08:04 +0000240 /// kProbe_GrGLCapability to probe (slowly) at context creation.
tomhudson@google.com747bf292011-06-14 18:16:52 +0000241 int fMinRenderTargetHeight;
242 int fMinRenderTargetWidth;
243
twiz@google.com59a190b2011-03-14 21:23:01 +0000244 GrGLActiveTextureProc fActiveTexture;
245 GrGLAttachShaderProc fAttachShader;
246 GrGLBindAttribLocationProc fBindAttribLocation;
247 GrGLBindBufferProc fBindBuffer;
248 GrGLBindTextureProc fBindTexture;
bsalomon@google.com080773c2011-03-15 19:09:25 +0000249 GrGLBlendColorProc fBlendColor;
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000250 GrGLBlendFuncProc fBlendFunc;
twiz@google.com59a190b2011-03-14 21:23:01 +0000251 GrGLBufferDataProc fBufferData;
252 GrGLBufferSubDataProc fBufferSubData;
253 GrGLClearProc fClear;
254 GrGLClearColorProc fClearColor;
255 GrGLClearStencilProc fClearStencil;
256 GrGLClientActiveTextureProc fClientActiveTexture;
257 GrGLColor4ubProc fColor4ub;
258 GrGLColorMaskProc fColorMask;
259 GrGLColorPointerProc fColorPointer;
260 GrGLCompileShaderProc fCompileShader;
261 GrGLCompressedTexImage2DProc fCompressedTexImage2D;
262 GrGLCreateProgramProc fCreateProgram;
263 GrGLCreateShaderProc fCreateShader;
264 GrGLCullFaceProc fCullFace;
265 GrGLDeleteBuffersProc fDeleteBuffers;
266 GrGLDeleteProgramProc fDeleteProgram;
267 GrGLDeleteShaderProc fDeleteShader;
268 GrGLDeleteTexturesProc fDeleteTextures;
269 GrGLDepthMaskProc fDepthMask;
270 GrGLDisableProc fDisable;
271 GrGLDisableClientStateProc fDisableClientState;
272 GrGLDisableVertexAttribArrayProc fDisableVertexAttribArray;
273 GrGLDrawArraysProc fDrawArrays;
274 GrGLDrawElementsProc fDrawElements;
275 GrGLEnableProc fEnable;
276 GrGLEnableClientStateProc fEnableClientState;
277 GrGLEnableVertexAttribArrayProc fEnableVertexAttribArray;
278 GrGLFrontFaceProc fFrontFace;
279 GrGLGenBuffersProc fGenBuffers;
280 GrGLGenTexturesProc fGenTextures;
281 GrGLGetBufferParameterivProc fGetBufferParameteriv;
282 GrGLGetErrorProc fGetError;
283 GrGLGetIntegervProc fGetIntegerv;
284 GrGLGetProgramInfoLogProc fGetProgramInfoLog;
285 GrGLGetProgramivProc fGetProgramiv;
286 GrGLGetShaderInfoLogProc fGetShaderInfoLog;
287 GrGLGetShaderivProc fGetShaderiv;
288 GrGLGetStringProc fGetString;
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000289 GrGLGetTexLevelParameteriv fGetTexLevelParameteriv;
twiz@google.com59a190b2011-03-14 21:23:01 +0000290 GrGLGetUniformLocationProc fGetUniformLocation;
291 GrGLLineWidthProc fLineWidth;
292 GrGLLinkProgramProc fLinkProgram;
293 GrGLLoadMatrixfProc fLoadMatrixf;
294 GrGLMatrixModeProc fMatrixMode;
295 GrGLPixelStoreiProc fPixelStorei;
296 GrGLPointSizeProc fPointSize;
297 GrGLReadPixelsProc fReadPixels;
298 GrGLScissorProc fScissor;
299 GrGLShadeModelProc fShadeModel;
300 GrGLShaderSourceProc fShaderSource;
301 GrGLStencilFuncProc fStencilFunc;
302 GrGLStencilFuncSeparateProc fStencilFuncSeparate;
303 GrGLStencilMaskProc fStencilMask;
304 GrGLStencilMaskSeparateProc fStencilMaskSeparate;
305 GrGLStencilOpProc fStencilOp;
306 GrGLStencilOpSeparateProc fStencilOpSeparate;
307 GrGLTexCoordPointerProc fTexCoordPointer;
308 GrGLTexEnviProc fTexEnvi;
309 GrGLTexImage2DProc fTexImage2D;
310 GrGLTexParameteriProc fTexParameteri;
311 GrGLTexSubImage2DProc fTexSubImage2D;
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000312 GrGLUniform1fProc fUniform1f;
twiz@google.com59a190b2011-03-14 21:23:01 +0000313 GrGLUniform1iProc fUniform1i;
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000314 GrGLUniform1fvProc fUniform1fv;
315 GrGLUniform1ivProc fUniform1iv;
316 GrGLUniform2fProc fUniform2f;
317 GrGLUniform2iProc fUniform2i;
318 GrGLUniform2fvProc fUniform2fv;
319 GrGLUniform2ivProc fUniform2iv;
320 GrGLUniform3fProc fUniform3f;
321 GrGLUniform3iProc fUniform3i;
322 GrGLUniform3fvProc fUniform3fv;
323 GrGLUniform3ivProc fUniform3iv;
324 GrGLUniform4fProc fUniform4f;
325 GrGLUniform4iProc fUniform4i;
twiz@google.com59a190b2011-03-14 21:23:01 +0000326 GrGLUniform4fvProc fUniform4fv;
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000327 GrGLUniform4ivProc fUniform4iv;
328 GrGLUniformMatrix2fvProc fUniformMatrix2fv;
twiz@google.com59a190b2011-03-14 21:23:01 +0000329 GrGLUniformMatrix3fvProc fUniformMatrix3fv;
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000330 GrGLUniformMatrix4fvProc fUniformMatrix4fv;
twiz@google.com59a190b2011-03-14 21:23:01 +0000331 GrGLUseProgramProc fUseProgram;
332 GrGLVertexAttrib4fvProc fVertexAttrib4fv;
333 GrGLVertexAttribPointerProc fVertexAttribPointer;
334 GrGLVertexPointerProc fVertexPointer;
335 GrGLViewportProc fViewport;
336
337 // FBO Extension Functions
338 GrGLBindFramebufferProc fBindFramebuffer;
339 GrGLBindRenderbufferProc fBindRenderbuffer;
340 GrGLCheckFramebufferStatusProc fCheckFramebufferStatus;
341 GrGLDeleteFramebuffersProc fDeleteFramebuffers;
342 GrGLDeleteRenderbuffersProc fDeleteRenderbuffers;
343 GrGLFramebufferRenderbufferProc fFramebufferRenderbuffer;
344 GrGLFramebufferTexture2DProc fFramebufferTexture2D;
345 GrGLGenFramebuffersProc fGenFramebuffers;
346 GrGLGenRenderbuffersProc fGenRenderbuffers;
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000347 GrGLGetFramebufferAttachmentParameterivProc fGetFramebufferAttachmentParameteriv;
348 GrGLGetRenderbufferParameterivProc fGetRenderbufferParameteriv;
twiz@google.com59a190b2011-03-14 21:23:01 +0000349 GrGLRenderbufferStorageProc fRenderbufferStorage;
350
351 // Multisampling Extension Functions
352 // same prototype for ARB_FBO, EXT_FBO, GL 3.0, & Apple ES extension
353 GrGLRenderbufferStorageMultisampleProc fRenderbufferStorageMultisample;
354 // desktop: ext_fbo_blit, arb_fbo, gl 3.0
355 GrGLBlitFramebufferProc fBlitFramebuffer;
356 // apple's es extension
357 GrGLResolveMultisampleFramebufferProc fResolveMultisampleFramebuffer;
358
twiz@google.com59a190b2011-03-14 21:23:01 +0000359 // Buffer mapping (extension in ES).
360 GrGLMapBufferProc fMapBuffer;
361 GrGLUnmapBufferProc fUnmapBuffer;
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000362
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000363 // Dual Source Blending
364 GrGLBindFragDataLocationIndexedProc fBindFragDataLocationIndexed;
365
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000366 // Code that initializes this struct using a static initializer should
367 // make this the last entry in the static initializer. It can help to guard
368 // against failing to initialize newly-added members of this struct.
369 enum { kStaticInitEndGuard } fStaticInitEndGuard;
twiz@google.com59a190b2011-03-14 21:23:01 +0000370
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000371private:
372 bool validateShaderFunctions() const;
373 bool validateFixedFunctions() const;
374};
twiz@google.com59a190b2011-03-14 21:23:01 +0000375
376#endif