blob: d08442d214fcd2e3734c4bc3721974ab26cf0dc7 [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
10#ifndef GrGLInterface_DEFINED
11#define GrGLInterface_DEFINED
12
bsalomon@google.com637d5e92012-05-07 21:33:56 +000013#include "GrGLFunctions.h"
bsalomon@google.com0b77d682011-08-19 13:28:54 +000014#include "GrRefCnt.h"
twiz@google.com59a190b2011-03-14 21:23:01 +000015
twiz@google.com59a190b2011-03-14 21:23:01 +000016////////////////////////////////////////////////////////////////////////////////
17
18/**
bsalomon@google.com89ec61e2012-02-10 20:05:18 +000019 * Classifies GL contexts (currently as Desktop vs. ES2). This is a bitfield.
20 * A GrGLInterface (defined below) may support multiple bindings.
21 */
22enum GrGLBinding {
23 kNone_GrGLBinding = 0x0,
24
25 kDesktop_GrGLBinding = 0x01,
26 kES2_GrGLBinding = 0x02,
27
28 // for iteration of GrGLBindings
bsalomon@google.comb447d212012-02-10 20:25:36 +000029 kFirstGrGLBinding = kDesktop_GrGLBinding,
bsalomon@google.com89ec61e2012-02-10 20:05:18 +000030 kLastGrGLBinding = kES2_GrGLBinding
31};
32
33////////////////////////////////////////////////////////////////////////////////
34
35/**
bsalomon@google.com0b77d682011-08-19 13:28:54 +000036 * Rather than depend on platform-specific GL headers and libraries, we require
37 * the client to provide a struct of GL function pointers. This struct can be
38 * specified per-GrContext as a parameter to GrContext::Create. If NULL is
39 * passed to Create then the "default" GL interface is used. If the default is
40 * also NULL GrContext creation will fail.
41 *
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000042 * The default interface is returned by GrGLDefaultInterface. This function's
robertphillips@google.com0da37192012-03-19 14:42:13 +000043 * implementation is platform-specific. Several have been provided, along with
44 * an implementation that simply returns NULL. It is implementation-specific
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000045 * whether the same GrGLInterface is returned or whether a new one is created
46 * at each call. Some platforms may not be able to use a single GrGLInterface
47 * because extension function ptrs vary across contexts. Note that GrGLInterface
48 * is ref-counted. So if the same object is returned by multiple calls to
49 * GrGLDefaultInterface, each should bump the ref count.
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +000050 *
51 * By defining GR_GL_PER_GL_CALL_IFACE_CALLBACK to 1 the client can specify a
52 * callback function that will be called prior to each GL function call. See
53 * comments in GrGLConfig.h
twiz@google.com59a190b2011-03-14 21:23:01 +000054 */
twiz@google.com59a190b2011-03-14 21:23:01 +000055
bsalomon@google.com0b77d682011-08-19 13:28:54 +000056struct GrGLInterface;
57
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000058const GrGLInterface* GrGLDefaultInterface();
twiz@google.com59a190b2011-03-14 21:23:01 +000059
bsalomon@google.com57f5d982011-10-24 21:17:53 +000060/**
61 * Creates a GrGLInterface for a "native" GL context (e.g. WGL on windows,
62 * GLX on linux, AGL on Mac). On platforms that have context-specific function
63 * pointers for GL extensions (e.g. windows) the returned interface is only
64 * valid for the context that was current at creation.
65 */
bsalomon@google.com373a6632011-10-19 20:43:20 +000066const GrGLInterface* GrGLCreateNativeInterface();
67
robertphillips@google.comd3b9fbb2012-03-28 16:19:11 +000068#if SK_MESA
bsalomon@google.com57f5d982011-10-24 21:17:53 +000069/**
70 * Creates a GrGLInterface for an OSMesa context.
71 */
bsalomon@google.com373a6632011-10-19 20:43:20 +000072const GrGLInterface* GrGLCreateMesaInterface();
robertphillips@google.comd3b9fbb2012-03-28 16:19:11 +000073#endif
74
75#if SK_ANGLE
76/**
77 * Creates a GrGLInterface for an ANGLE context.
78 */
79const GrGLInterface* GrGLCreateANGLEInterface();
80#endif
bsalomon@google.com373a6632011-10-19 20:43:20 +000081
bsalomon@google.com74913722011-10-27 20:44:19 +000082/**
83 * Creates a null GrGLInterface that doesn't draw anything. Used for measuring
84 * CPU overhead.
85 */
86const GrGLInterface* GrGLCreateNullInterface();
87
robertphillips@google.com0da37192012-03-19 14:42:13 +000088/**
89 * Creates a debugging GrGLInterface that doesn't draw anything. Used for
90 * finding memory leaks and invalid memory accesses.
91 */
92const GrGLInterface* GrGLCreateDebugInterface();
93
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +000094#if GR_GL_PER_GL_FUNC_CALLBACK
95typedef void (*GrGLInterfaceCallbackProc)(const GrGLInterface*);
96typedef intptr_t GrGLInterfaceCallbackData;
97#endif
98
bsalomon@google.combf2a4692011-05-04 12:35:39 +000099/*
bsalomon@google.comcc61b172012-05-07 21:45:48 +0000100 * GrContext uses the following interface to make all calls into OpenGL. When a
101 * GrContext is created it is given a GrGLInterface. The interface's function
102 * pointers must be valid for the OpenGL context associated with the GrContext.
103 * On some platforms, such as Windows, function pointers for OpenGL extensions
104 * may vary between OpenGL contexts. So the caller must be careful to use a
105 * GrGLInterface initialized for the correct context. All functions that should
106 * be available based on the OpenGL's version and extension string must be
107 * non-NULL or GrContext creation will fail. This can be tested with the
108 * validate() method when the OpenGL context has been made current.
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000109 */
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000110struct GR_API GrGLInterface : public GrRefCnt {
bsalomon@google.comba800e22012-03-29 21:04:52 +0000111private:
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000112 // simple wrapper class that exists only to initialize a pointer to NULL
bsalomon@google.comba800e22012-03-29 21:04:52 +0000113 template <typename FNPTR_TYPE> class GLPtr {
114 public:
115 GLPtr() : fPtr(NULL) {}
116 GLPtr operator =(FNPTR_TYPE ptr) { fPtr = ptr; return *this; }
117 operator FNPTR_TYPE() const { return fPtr; }
118 private:
119 FNPTR_TYPE fPtr;
120 };
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000121
bsalomon@google.comba800e22012-03-29 21:04:52 +0000122public:
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000123 GrGLInterface();
124
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000125 // Validates that the GrGLInterface supports a binding. This means that
126 // the GrGLinterface advertises the binding in fBindingsExported and all
bsalomon@google.comcc61b172012-05-07 21:45:48 +0000127 // the necessary function pointers have been initialized. The interface is
128 // validated for the current OpenGL context.
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000129 bool validate(GrGLBinding binding) const;
130
twiz@google.comb65e0cb2011-03-18 20:41:44 +0000131 // Indicator variable specifying the type of GL implementation
bsalomon@google.comba800e22012-03-29 21:04:52 +0000132 // exported: GLES2 and/or Desktop.
twiz@google.comb65e0cb2011-03-18 20:41:44 +0000133 GrGLBinding fBindingsExported;
134
bsalomon@google.comba800e22012-03-29 21:04:52 +0000135 GLPtr<GrGLActiveTextureProc> fActiveTexture;
136 GLPtr<GrGLAttachShaderProc> fAttachShader;
137 GLPtr<GrGLBeginQueryProc> fBeginQuery;
138 GLPtr<GrGLBindAttribLocationProc> fBindAttribLocation;
139 GLPtr<GrGLBindBufferProc> fBindBuffer;
140 GLPtr<GrGLBindFragDataLocationProc> fBindFragDataLocation;
141 GLPtr<GrGLBindFragDataLocationIndexedProc> fBindFragDataLocationIndexed;
142 GLPtr<GrGLBindFramebufferProc> fBindFramebuffer;
143 GLPtr<GrGLBindRenderbufferProc> fBindRenderbuffer;
144 GLPtr<GrGLBindTextureProc> fBindTexture;
145 GLPtr<GrGLBlendColorProc> fBlendColor;
146 GLPtr<GrGLBlendFuncProc> fBlendFunc;
robertphillips@google.come7884302012-04-18 14:39:58 +0000147 GLPtr<GrGLBlendEquationProc> fBlendEquation;
bsalomon@google.comba800e22012-03-29 21:04:52 +0000148 GLPtr<GrGLBlitFramebufferProc> fBlitFramebuffer;
149 GLPtr<GrGLBufferDataProc> fBufferData;
150 GLPtr<GrGLBufferSubDataProc> fBufferSubData;
151 GLPtr<GrGLCheckFramebufferStatusProc> fCheckFramebufferStatus;
152 GLPtr<GrGLClearProc> fClear;
153 GLPtr<GrGLClearColorProc> fClearColor;
154 GLPtr<GrGLClearStencilProc> fClearStencil;
155 GLPtr<GrGLColorMaskProc> fColorMask;
156 GLPtr<GrGLColorPointerProc> fColorPointer;
157 GLPtr<GrGLCompileShaderProc> fCompileShader;
158 GLPtr<GrGLCompressedTexImage2DProc> fCompressedTexImage2D;
159 GLPtr<GrGLCreateProgramProc> fCreateProgram;
160 GLPtr<GrGLCreateShaderProc> fCreateShader;
161 GLPtr<GrGLCullFaceProc> fCullFace;
162 GLPtr<GrGLDeleteBuffersProc> fDeleteBuffers;
163 GLPtr<GrGLDeleteFramebuffersProc> fDeleteFramebuffers;
164 GLPtr<GrGLDeleteProgramProc> fDeleteProgram;
165 GLPtr<GrGLDeleteQueriesProc> fDeleteQueries;
166 GLPtr<GrGLDeleteRenderbuffersProc> fDeleteRenderbuffers;
167 GLPtr<GrGLDeleteShaderProc> fDeleteShader;
168 GLPtr<GrGLDeleteTexturesProc> fDeleteTextures;
169 GLPtr<GrGLDepthMaskProc> fDepthMask;
170 GLPtr<GrGLDisableProc> fDisable;
171 GLPtr<GrGLDisableVertexAttribArrayProc> fDisableVertexAttribArray;
172 GLPtr<GrGLDrawArraysProc> fDrawArrays;
173 GLPtr<GrGLDrawBufferProc> fDrawBuffer;
174 GLPtr<GrGLDrawBuffersProc> fDrawBuffers;
175 GLPtr<GrGLDrawElementsProc> fDrawElements;
176 GLPtr<GrGLEnableProc> fEnable;
177 GLPtr<GrGLEnableVertexAttribArrayProc> fEnableVertexAttribArray;
178 GLPtr<GrGLEndQueryProc> fEndQuery;
179 GLPtr<GrGLFinishProc> fFinish;
180 GLPtr<GrGLFlushProc> fFlush;
181 GLPtr<GrGLFramebufferRenderbufferProc> fFramebufferRenderbuffer;
182 GLPtr<GrGLFramebufferTexture2DProc> fFramebufferTexture2D;
183 GLPtr<GrGLFrontFaceProc> fFrontFace;
184 GLPtr<GrGLGenBuffersProc> fGenBuffers;
185 GLPtr<GrGLGenFramebuffersProc> fGenFramebuffers;
186 GLPtr<GrGLGenQueriesProc> fGenQueries;
187 GLPtr<GrGLGenRenderbuffersProc> fGenRenderbuffers;
188 GLPtr<GrGLGenTexturesProc> fGenTextures;
189 GLPtr<GrGLGetBufferParameterivProc> fGetBufferParameteriv;
190 GLPtr<GrGLGetErrorProc> fGetError;
191 GLPtr<GrGLGetFramebufferAttachmentParameterivProc> fGetFramebufferAttachmentParameteriv;
192 GLPtr<GrGLGetIntegervProc> fGetIntegerv;
193 GLPtr<GrGLGetQueryObjecti64vProc> fGetQueryObjecti64v;
194 GLPtr<GrGLGetQueryObjectivProc> fGetQueryObjectiv;
195 GLPtr<GrGLGetQueryObjectui64vProc> fGetQueryObjectui64v;
196 GLPtr<GrGLGetQueryObjectuivProc> fGetQueryObjectuiv;
197 GLPtr<GrGLGetQueryivProc> fGetQueryiv;
198 GLPtr<GrGLGetProgramInfoLogProc> fGetProgramInfoLog;
199 GLPtr<GrGLGetProgramivProc> fGetProgramiv;
200 GLPtr<GrGLGetRenderbufferParameterivProc> fGetRenderbufferParameteriv;
201 GLPtr<GrGLGetShaderInfoLogProc> fGetShaderInfoLog;
202 GLPtr<GrGLGetShaderivProc> fGetShaderiv;
203 GLPtr<GrGLGetStringProc> fGetString;
204 GLPtr<GrGLGetTexLevelParameterivProc> fGetTexLevelParameteriv;
205 GLPtr<GrGLGetUniformLocationProc> fGetUniformLocation;
206 GLPtr<GrGLLineWidthProc> fLineWidth;
207 GLPtr<GrGLLinkProgramProc> fLinkProgram;
208 GLPtr<GrGLMapBufferProc> fMapBuffer;
209 GLPtr<GrGLPixelStoreiProc> fPixelStorei;
210 GLPtr<GrGLQueryCounterProc> fQueryCounter;
211 GLPtr<GrGLReadBufferProc> fReadBuffer;
212 GLPtr<GrGLReadPixelsProc> fReadPixels;
213 GLPtr<GrGLRenderbufferStorageProc> fRenderbufferStorage;
214 GLPtr<GrGLRenderbufferStorageMultisampleProc> fRenderbufferStorageMultisample;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000215 GLPtr<GrGLRenderbufferStorageMultisampleCoverageProc> fRenderbufferStorageMultisampleCoverage;
bsalomon@google.comba800e22012-03-29 21:04:52 +0000216 GLPtr<GrGLResolveMultisampleFramebufferProc> fResolveMultisampleFramebuffer;
217 GLPtr<GrGLScissorProc> fScissor;
218 GLPtr<GrGLShaderSourceProc> fShaderSource;
219 GLPtr<GrGLStencilFuncProc> fStencilFunc;
220 GLPtr<GrGLStencilFuncSeparateProc> fStencilFuncSeparate;
221 GLPtr<GrGLStencilMaskProc> fStencilMask;
222 GLPtr<GrGLStencilMaskSeparateProc> fStencilMaskSeparate;
223 GLPtr<GrGLStencilOpProc> fStencilOp;
224 GLPtr<GrGLStencilOpSeparateProc> fStencilOpSeparate;
225 GLPtr<GrGLTexImage2DProc> fTexImage2D;
226 GLPtr<GrGLTexParameteriProc> fTexParameteri;
227 GLPtr<GrGLTexSubImage2DProc> fTexSubImage2D;
228 GLPtr<GrGLTexStorage2DProc> fTexStorage2D;
229 GLPtr<GrGLUniform1fProc> fUniform1f;
230 GLPtr<GrGLUniform1iProc> fUniform1i;
231 GLPtr<GrGLUniform1fvProc> fUniform1fv;
232 GLPtr<GrGLUniform1ivProc> fUniform1iv;
233 GLPtr<GrGLUniform2fProc> fUniform2f;
234 GLPtr<GrGLUniform2iProc> fUniform2i;
235 GLPtr<GrGLUniform2fvProc> fUniform2fv;
236 GLPtr<GrGLUniform2ivProc> fUniform2iv;
237 GLPtr<GrGLUniform3fProc> fUniform3f;
238 GLPtr<GrGLUniform3iProc> fUniform3i;
239 GLPtr<GrGLUniform3fvProc> fUniform3fv;
240 GLPtr<GrGLUniform3ivProc> fUniform3iv;
241 GLPtr<GrGLUniform4fProc> fUniform4f;
242 GLPtr<GrGLUniform4iProc> fUniform4i;
243 GLPtr<GrGLUniform4fvProc> fUniform4fv;
244 GLPtr<GrGLUniform4ivProc> fUniform4iv;
245 GLPtr<GrGLUniformMatrix2fvProc> fUniformMatrix2fv;
246 GLPtr<GrGLUniformMatrix3fvProc> fUniformMatrix3fv;
247 GLPtr<GrGLUniformMatrix4fvProc> fUniformMatrix4fv;
248 GLPtr<GrGLUnmapBufferProc> fUnmapBuffer;
249 GLPtr<GrGLUseProgramProc> fUseProgram;
250 GLPtr<GrGLVertexAttrib4fvProc> fVertexAttrib4fv;
251 GLPtr<GrGLVertexAttribPointerProc> fVertexAttribPointer;
252 GLPtr<GrGLViewportProc> fViewport;
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000253
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +0000254 // Per-GL func callback
255#if GR_GL_PER_GL_FUNC_CALLBACK
256 GrGLInterfaceCallbackProc fCallback;
257 GrGLInterfaceCallbackData fCallbackData;
258#endif
259
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000260};
twiz@google.com59a190b2011-03-14 21:23:01 +0000261
262#endif