blob: e6f0b57010ceaf9217c27162c656acc6eb0d741e [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.com2c17fcd2011-07-06 17:47:02 +000027// these variants assume caller already has a string from glGetString()
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000028void gl_version_from_string(int* major, int* minor,
29 const char* versionString);
bsalomon@google.com2c17fcd2011-07-06 17:47:02 +000030float gl_version_as_float_from_string(const char* versionString);
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000031bool has_gl_extension_from_string(const char* ext,
32 const char* extensionString);
33
bsalomon@google.com2c17fcd2011-07-06 17:47:02 +000034// these variants call glGetString()
bsalomon@google.com0b77d682011-08-19 13:28:54 +000035bool has_gl_extension(const GrGLInterface*, const char* ext);
36void gl_version(const GrGLInterface*, int* major, int* minor);
37float gl_version_as_float(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 *
48 * The default interface is specified by calling GrGLSetDefaultInterface. If
49 * this function hasn't been called or was last called with NULL then
50 * GrGLInitializeDefaultGLInterface will be called to attempt to initialize it.
51 * There are several implementations of this function provided. Each builds a
52 * GrGLInterface for a specific platform and sets it as the default. There is
53 * also an implementation that does nothing. You can link in any of the provided
54 * implementations or your own implementation that sets up the GL function
55 * pointers for your specific platform.
twiz@google.com59a190b2011-03-14 21:23:01 +000056 */
twiz@google.com59a190b2011-03-14 21:23:01 +000057
bsalomon@google.com0b77d682011-08-19 13:28:54 +000058struct GrGLInterface;
59
60GR_API const GrGLInterface* GrGLGetDefaultGLInterface();
61// returns param so that you can unref it
62GR_API const GrGLInterface* GrGLSetDefaultGLInterface(const GrGLInterface* gl_interface);
63
64// If this is implemented it must allocate a GrGLInterface on the heap because
65// GrGLInterface subclasses SkRefCnt.
66void GrGLInitializeDefaultGLInterface();
twiz@google.com59a190b2011-03-14 21:23:01 +000067
twiz@google.com0f31ca72011-03-18 17:38:11 +000068typedef unsigned int GrGLenum;
69typedef unsigned char GrGLboolean;
70typedef unsigned int GrGLbitfield;
71typedef signed char GrGLbyte;
bsalomon@google.com271cffc2011-05-20 14:13:56 +000072typedef char GrGLchar;
twiz@google.com0f31ca72011-03-18 17:38:11 +000073typedef short GrGLshort;
74typedef int GrGLint;
75typedef int GrGLsizei;
76typedef unsigned char GrGLubyte;
77typedef unsigned short GrGLushort;
78typedef unsigned int GrGLuint;
79typedef float GrGLfloat;
80typedef float GrGLclampf;
81typedef double GrGLdouble;
82typedef double GrGLclampd;
83typedef void GrGLvoid;
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000084typedef long GrGLintptr;
85typedef long GrGLsizeiptr;
twiz@google.com0f31ca72011-03-18 17:38:11 +000086
twiz@google.comb65e0cb2011-03-18 20:41:44 +000087enum GrGLBinding {
88 kDesktop_GrGLBinding = 0x01,
89 kES1_GrGLBinding = 0x02,
90 kES2_GrGLBinding = 0x04
91};
92
twiz@google.com59a190b2011-03-14 21:23:01 +000093extern "C" {
twiz@google.com0f31ca72011-03-18 17:38:11 +000094 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLActiveTextureProc)(GrGLenum texture);
95 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLAttachShaderProc)(GrGLuint program, GrGLuint shader);
96 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindAttribLocationProc)(GrGLuint program, GrGLuint index, const char* name);
97 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindBufferProc)(GrGLenum target, GrGLuint buffer);
98 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindTextureProc)(GrGLenum target, GrGLuint texture);
99 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBlendColorProc)(GrGLclampf red, GrGLclampf green, GrGLclampf blue, GrGLclampf alpha);
100 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBlendFuncProc)(GrGLenum sfactor, GrGLenum dfactor);
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000101 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBufferDataProc)(GrGLenum target, GrGLsizeiptr size, const GrGLvoid* data, GrGLenum usage);
102 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBufferSubDataProc)(GrGLenum target, GrGLintptr offset, GrGLsizeiptr size, const GrGLvoid* data);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000103 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClearProc)(GrGLbitfield mask);
104 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClearColorProc)(GrGLclampf red, GrGLclampf green, GrGLclampf blue, GrGLclampf alpha);
105 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClearStencilProc)(GrGLint s);
106 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClientActiveTextureProc)(GrGLenum texture);
107 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLColor4ubProc)(GrGLubyte red, GrGLubyte green, GrGLubyte blue, GrGLubyte alpha);
108 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLColorMaskProc)(GrGLboolean red, GrGLboolean green, GrGLboolean blue, GrGLboolean alpha);
109 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLColorPointerProc)(GrGLint size, GrGLenum type, GrGLsizei stride, const GrGLvoid* pointer);
110 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLCompileShaderProc)(GrGLuint shader);
111 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLCompressedTexImage2DProc)(GrGLenum target, GrGLint level, GrGLenum internalformat, GrGLsizei width, GrGLsizei height, GrGLint border, GrGLsizei imageSize, const GrGLvoid* data);
112 typedef GrGLuint (GR_GL_FUNCTION_TYPE *GrGLCreateProgramProc)(void);
113 typedef GrGLuint (GR_GL_FUNCTION_TYPE *GrGLCreateShaderProc)(GrGLenum type);
114 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLCullFaceProc)(GrGLenum mode);
115 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteBuffersProc)(GrGLsizei n, const GrGLuint* buffers);
116 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteProgramProc)(GrGLuint program);
117 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteShaderProc)(GrGLuint shader);
118 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteTexturesProc)(GrGLsizei n, const GrGLuint* textures);
119 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDepthMaskProc)(GrGLboolean flag);
120 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDisableProc)(GrGLenum cap);
121 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDisableClientStateProc)(GrGLenum array);
122 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDisableVertexAttribArrayProc)(GrGLuint index);
123 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawArraysProc)(GrGLenum mode, GrGLint first, GrGLsizei count);
bsalomon@google.comd32c5f52011-08-02 19:29:03 +0000124 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawBufferProc)(GrGLenum mode);
125 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawBuffersProc)(GrGLsizei n, const GrGLenum* bufs);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000126 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawElementsProc)(GrGLenum mode, GrGLsizei count, GrGLenum type, const GrGLvoid* indices);
127 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLEnableProc)(GrGLenum cap);
128 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLEnableClientStateProc)(GrGLenum cap);
129 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLEnableVertexAttribArrayProc)(GrGLuint index);
130 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFrontFaceProc)(GrGLenum mode);
131 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenBuffersProc)(GrGLsizei n, GrGLuint* buffers);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000132 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenTexturesProc)(GrGLsizei n, GrGLuint* textures);
133 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetBufferParameterivProc)(GrGLenum target, GrGLenum pname, GrGLint* params);
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000134 typedef GrGLenum (GR_GL_FUNCTION_TYPE *GrGLGetErrorProc)(void);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000135 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetIntegervProc)(GrGLenum pname, GrGLint* params);
136 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetProgramInfoLogProc)(GrGLuint program, GrGLsizei bufsize, GrGLsizei* length, char* infolog);
137 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetProgramivProc)(GrGLuint program, GrGLenum pname, GrGLint* params);
138 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetShaderInfoLogProc)(GrGLuint shader, GrGLsizei bufsize, GrGLsizei* length, char* infolog);
139 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetShaderivProc)(GrGLuint shader, GrGLenum pname, GrGLint* params);
140 typedef const GrGLubyte* (GR_GL_FUNCTION_TYPE *GrGLGetStringProc)(GrGLenum name);
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000141 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetTexLevelParameteriv)(GrGLenum target, GrGLint level, GrGLenum pname, GrGLint* params);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000142 typedef GrGLint (GR_GL_FUNCTION_TYPE *GrGLGetUniformLocationProc)(GrGLuint program, const char* name);
143 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLLineWidthProc)(GrGLfloat width);
144 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLLinkProgramProc)(GrGLuint program);
145 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLLoadMatrixfProc)(const GrGLfloat* m);
146 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLMatrixModeProc)(GrGLenum mode);
147 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLPixelStoreiProc)(GrGLenum pname, GrGLint param);
148 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLPointSizeProc)(GrGLfloat size);
bsalomon@google.comc49d66b2011-08-03 14:22:30 +0000149 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLReadBufferProc)(GrGLenum src);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000150 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLReadPixelsProc)(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height, GrGLenum format, GrGLenum type, GrGLvoid* pixels);
151 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLScissorProc)(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height);
152 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLShadeModelProc)(GrGLenum mode);
153 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLShaderSourceProc)(GrGLuint shader, GrGLsizei count, const char** str, const GrGLint* length);
154 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilFuncProc)(GrGLenum func, GrGLint ref, GrGLuint mask);
155 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilFuncSeparateProc)(GrGLenum face, GrGLenum func, GrGLint ref, GrGLuint mask);
156 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilMaskProc)(GrGLuint mask);
157 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilMaskSeparateProc)(GrGLenum face, GrGLuint mask);
158 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilOpProc)(GrGLenum fail, GrGLenum zfail, GrGLenum zpass);
159 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilOpSeparateProc)(GrGLenum face, GrGLenum fail, GrGLenum zfail, GrGLenum zpass);
160 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexCoordPointerProc)(GrGLint size, GrGLenum type, GrGLsizei stride, const GrGLvoid* pointer);
161 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexEnviProc)(GrGLenum target, GrGLenum pname, GrGLint param);
162 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);
163 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexParameteriProc)(GrGLenum target, GrGLenum pname, GrGLint param);
164 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 +0000165 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1fProc)(GrGLint location, GrGLfloat v0);
166 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1iProc)(GrGLint location, GrGLint v0);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000167 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1fvProc)(GrGLint location, GrGLsizei count, const GrGLfloat* v);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000168 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1ivProc)(GrGLint location, GrGLsizei count, const GrGLint* v);
169 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform2fProc)(GrGLint location, GrGLfloat v0, GrGLfloat v1);
170 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform2iProc)(GrGLint location, GrGLint v0, GrGLint v1);
171 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform2fvProc)(GrGLint location, GrGLsizei count, const GrGLfloat* v);
172 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform2ivProc)(GrGLint location, GrGLsizei count, const GrGLint* v);
173 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform3fProc)(GrGLint location, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2);
174 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform3iProc)(GrGLint location, GrGLint v0, GrGLint v1, GrGLint v2);
175 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform3fvProc)(GrGLint location, GrGLsizei count, const GrGLfloat* v);
176 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform3ivProc)(GrGLint location, GrGLsizei count, const GrGLint* v);
177 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform4fProc)(GrGLint location, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2, GrGLfloat v3);
178 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 +0000179 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform4fvProc)(GrGLint location, GrGLsizei count, const GrGLfloat* v);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000180 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform4ivProc)(GrGLint location, GrGLsizei count, const GrGLint* v);
181 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniformMatrix2fvProc)(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000182 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniformMatrix3fvProc)(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000183 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniformMatrix4fvProc)(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000184 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUseProgramProc)(GrGLuint program);
185 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLVertexAttrib4fvProc)(GrGLuint indx, const GrGLfloat* values);
186 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLVertexAttribPointerProc)(GrGLuint indx, GrGLint size, GrGLenum type, GrGLboolean normalized, GrGLsizei stride, const GrGLvoid* ptr);
187 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLVertexPointerProc)(GrGLint size, GrGLenum type, GrGLsizei stride, const GrGLvoid* pointer);
188 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLViewportProc)(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height);
twiz@google.com59a190b2011-03-14 21:23:01 +0000189
190 // FBO Extension Functions
twiz@google.com0f31ca72011-03-18 17:38:11 +0000191 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindFramebufferProc)(GrGLenum target, GrGLuint framebuffer);
192 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindRenderbufferProc)(GrGLenum target, GrGLuint renderbuffer);
193 typedef GrGLenum (GR_GL_FUNCTION_TYPE *GrGLCheckFramebufferStatusProc)(GrGLenum target);
194 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteFramebuffersProc)(GrGLsizei n, const GrGLuint *framebuffers);
195 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteRenderbuffersProc)(GrGLsizei n, const GrGLuint *renderbuffers);
196 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFramebufferRenderbufferProc)(GrGLenum target, GrGLenum attachment, GrGLenum renderbuffertarget, GrGLuint renderbuffer);
197 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFramebufferTexture2DProc)(GrGLenum target, GrGLenum attachment, GrGLenum textarget, GrGLuint texture, GrGLint level);
198 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenFramebuffersProc)(GrGLsizei n, GrGLuint *framebuffers);
199 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenRenderbuffersProc)(GrGLsizei n, GrGLuint *renderbuffers);
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000200 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetFramebufferAttachmentParameterivProc)(GrGLenum target, GrGLenum attachment, GrGLenum pname, GrGLint* params);
201 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetRenderbufferParameterivProc)(GrGLenum target, GrGLenum pname, GrGLint* params);
twiz@google.com0f31ca72011-03-18 17:38:11 +0000202 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLRenderbufferStorageProc)(GrGLenum target, GrGLenum internalformat, GrGLsizei width, GrGLsizei height);
twiz@google.com59a190b2011-03-14 21:23:01 +0000203
204 // Multisampling Extension Functions
205 // same prototype for ARB_FBO, EXT_FBO, GL 3.0, & Apple ES extension
twiz@google.com0f31ca72011-03-18 17:38:11 +0000206 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 +0000207 // desktop: ext_fbo_blit, arb_fbo, gl 3.0
twiz@google.com0f31ca72011-03-18 17:38:11 +0000208 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 +0000209 // apple's es extension
twiz@google.com0f31ca72011-03-18 17:38:11 +0000210 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLResolveMultisampleFramebufferProc)();
twiz@google.com59a190b2011-03-14 21:23:01 +0000211
twiz@google.com59a190b2011-03-14 21:23:01 +0000212 // Buffer mapping (extension in ES).
twiz@google.com0f31ca72011-03-18 17:38:11 +0000213 typedef GrGLvoid* (GR_GL_FUNCTION_TYPE *GrGLMapBufferProc)(GrGLenum target, GrGLenum access);
214 typedef GrGLboolean (GR_GL_FUNCTION_TYPE *GrGLUnmapBufferProc)(GrGLenum target);
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000215
216 // Dual source blending
217 typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindFragDataLocationIndexedProc)(GrGLuint program, GrGLuint colorNumber, GrGLuint index, const GrGLchar * name);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000218} // extern "C"
219
tomhudson@google.come67bd3f2011-06-16 14:08:04 +0000220enum GrGLCapability {
221 kProbe_GrGLCapability = -1
tomhudson@google.com30e4bb62011-06-15 19:41:46 +0000222};
223
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000224/*
225 * The following interface exports the OpenGL entry points used by the system.
226 * Use of OpenGL calls is disallowed. All calls should be invoked through
227 * the global instance of this struct, defined above.
228 *
229 * IMPORTANT NOTE: The OpenGL entry points exposed here include both core GL
230 * functions, and extensions. The system assumes that the address of the
231 * extension pointer will be valid across contexts.
232 */
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000233struct GR_API GrGLInterface : public GrRefCnt {
234
235 GrGLInterface();
236
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000237 bool validate(GrEngine engine) const;
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000238 bool supportsDesktop() const {
239 return 0 != (kDesktop_GrGLBinding & fBindingsExported);
240 }
241 bool supportsES1() const {
242 return 0 != (kES1_GrGLBinding & fBindingsExported);
243 }
244 bool supportsES2() const {
245 return 0 != (kES2_GrGLBinding & fBindingsExported);
246 }
247 bool supportsES() const {
248 return 0 != ((kES1_GrGLBinding | kES2_GrGLBinding) &
249 fBindingsExported);
250 }
twiz@google.com59a190b2011-03-14 21:23:01 +0000251
twiz@google.comb65e0cb2011-03-18 20:41:44 +0000252 // Indicator variable specifying the type of GL implementation
253 // exported: GLES{1|2} or Desktop.
254 GrGLBinding fBindingsExported;
255
tomhudson@google.com747bf292011-06-14 18:16:52 +0000256 /// Does this GL support NPOT textures on FBOs?
tomhudson@google.come67bd3f2011-06-16 14:08:04 +0000257 /// boolean value, or kProbe_GrGLCapability to probe (slowly) at context creation.
tomhudson@google.com747bf292011-06-14 18:16:52 +0000258 int fNPOTRenderTargetSupport;
259
260 /// Some GL implementations (PowerVR SGX devices like the iPhone 4)
261 /// have restrictions on the size of small render targets.
tomhudson@google.come67bd3f2011-06-16 14:08:04 +0000262 /// kProbe_GrGLCapability to probe (slowly) at context creation.
tomhudson@google.com747bf292011-06-14 18:16:52 +0000263 int fMinRenderTargetHeight;
264 int fMinRenderTargetWidth;
265
twiz@google.com59a190b2011-03-14 21:23:01 +0000266 GrGLActiveTextureProc fActiveTexture;
267 GrGLAttachShaderProc fAttachShader;
268 GrGLBindAttribLocationProc fBindAttribLocation;
269 GrGLBindBufferProc fBindBuffer;
270 GrGLBindTextureProc fBindTexture;
bsalomon@google.com080773c2011-03-15 19:09:25 +0000271 GrGLBlendColorProc fBlendColor;
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000272 GrGLBlendFuncProc fBlendFunc;
twiz@google.com59a190b2011-03-14 21:23:01 +0000273 GrGLBufferDataProc fBufferData;
274 GrGLBufferSubDataProc fBufferSubData;
275 GrGLClearProc fClear;
276 GrGLClearColorProc fClearColor;
277 GrGLClearStencilProc fClearStencil;
278 GrGLClientActiveTextureProc fClientActiveTexture;
279 GrGLColor4ubProc fColor4ub;
280 GrGLColorMaskProc fColorMask;
281 GrGLColorPointerProc fColorPointer;
282 GrGLCompileShaderProc fCompileShader;
283 GrGLCompressedTexImage2DProc fCompressedTexImage2D;
284 GrGLCreateProgramProc fCreateProgram;
285 GrGLCreateShaderProc fCreateShader;
286 GrGLCullFaceProc fCullFace;
287 GrGLDeleteBuffersProc fDeleteBuffers;
288 GrGLDeleteProgramProc fDeleteProgram;
289 GrGLDeleteShaderProc fDeleteShader;
290 GrGLDeleteTexturesProc fDeleteTextures;
291 GrGLDepthMaskProc fDepthMask;
292 GrGLDisableProc fDisable;
293 GrGLDisableClientStateProc fDisableClientState;
294 GrGLDisableVertexAttribArrayProc fDisableVertexAttribArray;
295 GrGLDrawArraysProc fDrawArrays;
bsalomon@google.comd32c5f52011-08-02 19:29:03 +0000296 GrGLDrawBufferProc fDrawBuffer;
297 GrGLDrawBuffersProc fDrawBuffers;
twiz@google.com59a190b2011-03-14 21:23:01 +0000298 GrGLDrawElementsProc fDrawElements;
299 GrGLEnableProc fEnable;
300 GrGLEnableClientStateProc fEnableClientState;
301 GrGLEnableVertexAttribArrayProc fEnableVertexAttribArray;
302 GrGLFrontFaceProc fFrontFace;
303 GrGLGenBuffersProc fGenBuffers;
304 GrGLGenTexturesProc fGenTextures;
305 GrGLGetBufferParameterivProc fGetBufferParameteriv;
306 GrGLGetErrorProc fGetError;
307 GrGLGetIntegervProc fGetIntegerv;
308 GrGLGetProgramInfoLogProc fGetProgramInfoLog;
309 GrGLGetProgramivProc fGetProgramiv;
310 GrGLGetShaderInfoLogProc fGetShaderInfoLog;
311 GrGLGetShaderivProc fGetShaderiv;
312 GrGLGetStringProc fGetString;
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000313 GrGLGetTexLevelParameteriv fGetTexLevelParameteriv;
twiz@google.com59a190b2011-03-14 21:23:01 +0000314 GrGLGetUniformLocationProc fGetUniformLocation;
315 GrGLLineWidthProc fLineWidth;
316 GrGLLinkProgramProc fLinkProgram;
317 GrGLLoadMatrixfProc fLoadMatrixf;
318 GrGLMatrixModeProc fMatrixMode;
319 GrGLPixelStoreiProc fPixelStorei;
320 GrGLPointSizeProc fPointSize;
bsalomon@google.comc49d66b2011-08-03 14:22:30 +0000321 GrGLReadBufferProc fReadBuffer;
twiz@google.com59a190b2011-03-14 21:23:01 +0000322 GrGLReadPixelsProc fReadPixels;
323 GrGLScissorProc fScissor;
324 GrGLShadeModelProc fShadeModel;
325 GrGLShaderSourceProc fShaderSource;
326 GrGLStencilFuncProc fStencilFunc;
327 GrGLStencilFuncSeparateProc fStencilFuncSeparate;
328 GrGLStencilMaskProc fStencilMask;
329 GrGLStencilMaskSeparateProc fStencilMaskSeparate;
330 GrGLStencilOpProc fStencilOp;
331 GrGLStencilOpSeparateProc fStencilOpSeparate;
332 GrGLTexCoordPointerProc fTexCoordPointer;
333 GrGLTexEnviProc fTexEnvi;
334 GrGLTexImage2DProc fTexImage2D;
335 GrGLTexParameteriProc fTexParameteri;
336 GrGLTexSubImage2DProc fTexSubImage2D;
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000337 GrGLUniform1fProc fUniform1f;
twiz@google.com59a190b2011-03-14 21:23:01 +0000338 GrGLUniform1iProc fUniform1i;
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000339 GrGLUniform1fvProc fUniform1fv;
340 GrGLUniform1ivProc fUniform1iv;
341 GrGLUniform2fProc fUniform2f;
342 GrGLUniform2iProc fUniform2i;
343 GrGLUniform2fvProc fUniform2fv;
344 GrGLUniform2ivProc fUniform2iv;
345 GrGLUniform3fProc fUniform3f;
346 GrGLUniform3iProc fUniform3i;
347 GrGLUniform3fvProc fUniform3fv;
348 GrGLUniform3ivProc fUniform3iv;
349 GrGLUniform4fProc fUniform4f;
350 GrGLUniform4iProc fUniform4i;
twiz@google.com59a190b2011-03-14 21:23:01 +0000351 GrGLUniform4fvProc fUniform4fv;
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000352 GrGLUniform4ivProc fUniform4iv;
353 GrGLUniformMatrix2fvProc fUniformMatrix2fv;
twiz@google.com59a190b2011-03-14 21:23:01 +0000354 GrGLUniformMatrix3fvProc fUniformMatrix3fv;
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000355 GrGLUniformMatrix4fvProc fUniformMatrix4fv;
twiz@google.com59a190b2011-03-14 21:23:01 +0000356 GrGLUseProgramProc fUseProgram;
357 GrGLVertexAttrib4fvProc fVertexAttrib4fv;
358 GrGLVertexAttribPointerProc fVertexAttribPointer;
359 GrGLVertexPointerProc fVertexPointer;
360 GrGLViewportProc fViewport;
361
362 // FBO Extension Functions
363 GrGLBindFramebufferProc fBindFramebuffer;
364 GrGLBindRenderbufferProc fBindRenderbuffer;
365 GrGLCheckFramebufferStatusProc fCheckFramebufferStatus;
366 GrGLDeleteFramebuffersProc fDeleteFramebuffers;
367 GrGLDeleteRenderbuffersProc fDeleteRenderbuffers;
368 GrGLFramebufferRenderbufferProc fFramebufferRenderbuffer;
369 GrGLFramebufferTexture2DProc fFramebufferTexture2D;
370 GrGLGenFramebuffersProc fGenFramebuffers;
371 GrGLGenRenderbuffersProc fGenRenderbuffers;
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000372 GrGLGetFramebufferAttachmentParameterivProc fGetFramebufferAttachmentParameteriv;
373 GrGLGetRenderbufferParameterivProc fGetRenderbufferParameteriv;
twiz@google.com59a190b2011-03-14 21:23:01 +0000374 GrGLRenderbufferStorageProc fRenderbufferStorage;
375
376 // Multisampling Extension Functions
377 // same prototype for ARB_FBO, EXT_FBO, GL 3.0, & Apple ES extension
378 GrGLRenderbufferStorageMultisampleProc fRenderbufferStorageMultisample;
379 // desktop: ext_fbo_blit, arb_fbo, gl 3.0
380 GrGLBlitFramebufferProc fBlitFramebuffer;
381 // apple's es extension
382 GrGLResolveMultisampleFramebufferProc fResolveMultisampleFramebuffer;
383
twiz@google.com59a190b2011-03-14 21:23:01 +0000384 // Buffer mapping (extension in ES).
385 GrGLMapBufferProc fMapBuffer;
386 GrGLUnmapBufferProc fUnmapBuffer;
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000387
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000388 // Dual Source Blending
389 GrGLBindFragDataLocationIndexedProc fBindFragDataLocationIndexed;
390
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000391private:
392 bool validateShaderFunctions() const;
393 bool validateFixedFunctions() const;
394};
twiz@google.com59a190b2011-03-14 21:23:01 +0000395
396#endif