blob: 433a496264de45f27f45868c3909d56fc009107c [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/*
100 * The following interface exports the OpenGL entry points used by the system.
101 * Use of OpenGL calls is disallowed. All calls should be invoked through
102 * the global instance of this struct, defined above.
103 *
104 * IMPORTANT NOTE: The OpenGL entry points exposed here include both core GL
105 * functions, and extensions. The system assumes that the address of the
106 * extension pointer will be valid across contexts.
107 */
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000108struct GR_API GrGLInterface : public GrRefCnt {
bsalomon@google.comba800e22012-03-29 21:04:52 +0000109private:
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000110 // simple wrapper class that exists only to initialize a pointer to NULL
bsalomon@google.comba800e22012-03-29 21:04:52 +0000111 template <typename FNPTR_TYPE> class GLPtr {
112 public:
113 GLPtr() : fPtr(NULL) {}
114 GLPtr operator =(FNPTR_TYPE ptr) { fPtr = ptr; return *this; }
115 operator FNPTR_TYPE() const { return fPtr; }
116 private:
117 FNPTR_TYPE fPtr;
118 };
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000119
bsalomon@google.comba800e22012-03-29 21:04:52 +0000120public:
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000121 GrGLInterface();
122
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000123 // Validates that the GrGLInterface supports a binding. This means that
124 // the GrGLinterface advertises the binding in fBindingsExported and all
125 // the necessary function pointers have been initialized.
126 bool validate(GrGLBinding binding) const;
127
twiz@google.comb65e0cb2011-03-18 20:41:44 +0000128 // Indicator variable specifying the type of GL implementation
bsalomon@google.comba800e22012-03-29 21:04:52 +0000129 // exported: GLES2 and/or Desktop.
twiz@google.comb65e0cb2011-03-18 20:41:44 +0000130 GrGLBinding fBindingsExported;
131
bsalomon@google.comba800e22012-03-29 21:04:52 +0000132 GLPtr<GrGLActiveTextureProc> fActiveTexture;
133 GLPtr<GrGLAttachShaderProc> fAttachShader;
134 GLPtr<GrGLBeginQueryProc> fBeginQuery;
135 GLPtr<GrGLBindAttribLocationProc> fBindAttribLocation;
136 GLPtr<GrGLBindBufferProc> fBindBuffer;
137 GLPtr<GrGLBindFragDataLocationProc> fBindFragDataLocation;
138 GLPtr<GrGLBindFragDataLocationIndexedProc> fBindFragDataLocationIndexed;
139 GLPtr<GrGLBindFramebufferProc> fBindFramebuffer;
140 GLPtr<GrGLBindRenderbufferProc> fBindRenderbuffer;
141 GLPtr<GrGLBindTextureProc> fBindTexture;
142 GLPtr<GrGLBlendColorProc> fBlendColor;
143 GLPtr<GrGLBlendFuncProc> fBlendFunc;
robertphillips@google.come7884302012-04-18 14:39:58 +0000144 GLPtr<GrGLBlendEquationProc> fBlendEquation;
bsalomon@google.comba800e22012-03-29 21:04:52 +0000145 GLPtr<GrGLBlitFramebufferProc> fBlitFramebuffer;
146 GLPtr<GrGLBufferDataProc> fBufferData;
147 GLPtr<GrGLBufferSubDataProc> fBufferSubData;
148 GLPtr<GrGLCheckFramebufferStatusProc> fCheckFramebufferStatus;
149 GLPtr<GrGLClearProc> fClear;
150 GLPtr<GrGLClearColorProc> fClearColor;
151 GLPtr<GrGLClearStencilProc> fClearStencil;
152 GLPtr<GrGLColorMaskProc> fColorMask;
153 GLPtr<GrGLColorPointerProc> fColorPointer;
154 GLPtr<GrGLCompileShaderProc> fCompileShader;
155 GLPtr<GrGLCompressedTexImage2DProc> fCompressedTexImage2D;
156 GLPtr<GrGLCreateProgramProc> fCreateProgram;
157 GLPtr<GrGLCreateShaderProc> fCreateShader;
158 GLPtr<GrGLCullFaceProc> fCullFace;
159 GLPtr<GrGLDeleteBuffersProc> fDeleteBuffers;
160 GLPtr<GrGLDeleteFramebuffersProc> fDeleteFramebuffers;
161 GLPtr<GrGLDeleteProgramProc> fDeleteProgram;
162 GLPtr<GrGLDeleteQueriesProc> fDeleteQueries;
163 GLPtr<GrGLDeleteRenderbuffersProc> fDeleteRenderbuffers;
164 GLPtr<GrGLDeleteShaderProc> fDeleteShader;
165 GLPtr<GrGLDeleteTexturesProc> fDeleteTextures;
166 GLPtr<GrGLDepthMaskProc> fDepthMask;
167 GLPtr<GrGLDisableProc> fDisable;
168 GLPtr<GrGLDisableVertexAttribArrayProc> fDisableVertexAttribArray;
169 GLPtr<GrGLDrawArraysProc> fDrawArrays;
170 GLPtr<GrGLDrawBufferProc> fDrawBuffer;
171 GLPtr<GrGLDrawBuffersProc> fDrawBuffers;
172 GLPtr<GrGLDrawElementsProc> fDrawElements;
173 GLPtr<GrGLEnableProc> fEnable;
174 GLPtr<GrGLEnableVertexAttribArrayProc> fEnableVertexAttribArray;
175 GLPtr<GrGLEndQueryProc> fEndQuery;
176 GLPtr<GrGLFinishProc> fFinish;
177 GLPtr<GrGLFlushProc> fFlush;
178 GLPtr<GrGLFramebufferRenderbufferProc> fFramebufferRenderbuffer;
179 GLPtr<GrGLFramebufferTexture2DProc> fFramebufferTexture2D;
180 GLPtr<GrGLFrontFaceProc> fFrontFace;
181 GLPtr<GrGLGenBuffersProc> fGenBuffers;
182 GLPtr<GrGLGenFramebuffersProc> fGenFramebuffers;
183 GLPtr<GrGLGenQueriesProc> fGenQueries;
184 GLPtr<GrGLGenRenderbuffersProc> fGenRenderbuffers;
185 GLPtr<GrGLGenTexturesProc> fGenTextures;
186 GLPtr<GrGLGetBufferParameterivProc> fGetBufferParameteriv;
187 GLPtr<GrGLGetErrorProc> fGetError;
188 GLPtr<GrGLGetFramebufferAttachmentParameterivProc> fGetFramebufferAttachmentParameteriv;
189 GLPtr<GrGLGetIntegervProc> fGetIntegerv;
190 GLPtr<GrGLGetQueryObjecti64vProc> fGetQueryObjecti64v;
191 GLPtr<GrGLGetQueryObjectivProc> fGetQueryObjectiv;
192 GLPtr<GrGLGetQueryObjectui64vProc> fGetQueryObjectui64v;
193 GLPtr<GrGLGetQueryObjectuivProc> fGetQueryObjectuiv;
194 GLPtr<GrGLGetQueryivProc> fGetQueryiv;
195 GLPtr<GrGLGetProgramInfoLogProc> fGetProgramInfoLog;
196 GLPtr<GrGLGetProgramivProc> fGetProgramiv;
197 GLPtr<GrGLGetRenderbufferParameterivProc> fGetRenderbufferParameteriv;
198 GLPtr<GrGLGetShaderInfoLogProc> fGetShaderInfoLog;
199 GLPtr<GrGLGetShaderivProc> fGetShaderiv;
200 GLPtr<GrGLGetStringProc> fGetString;
201 GLPtr<GrGLGetTexLevelParameterivProc> fGetTexLevelParameteriv;
202 GLPtr<GrGLGetUniformLocationProc> fGetUniformLocation;
203 GLPtr<GrGLLineWidthProc> fLineWidth;
204 GLPtr<GrGLLinkProgramProc> fLinkProgram;
205 GLPtr<GrGLMapBufferProc> fMapBuffer;
206 GLPtr<GrGLPixelStoreiProc> fPixelStorei;
207 GLPtr<GrGLQueryCounterProc> fQueryCounter;
208 GLPtr<GrGLReadBufferProc> fReadBuffer;
209 GLPtr<GrGLReadPixelsProc> fReadPixels;
210 GLPtr<GrGLRenderbufferStorageProc> fRenderbufferStorage;
211 GLPtr<GrGLRenderbufferStorageMultisampleProc> fRenderbufferStorageMultisample;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000212 GLPtr<GrGLRenderbufferStorageMultisampleCoverageProc> fRenderbufferStorageMultisampleCoverage;
bsalomon@google.comba800e22012-03-29 21:04:52 +0000213 GLPtr<GrGLResolveMultisampleFramebufferProc> fResolveMultisampleFramebuffer;
214 GLPtr<GrGLScissorProc> fScissor;
215 GLPtr<GrGLShaderSourceProc> fShaderSource;
216 GLPtr<GrGLStencilFuncProc> fStencilFunc;
217 GLPtr<GrGLStencilFuncSeparateProc> fStencilFuncSeparate;
218 GLPtr<GrGLStencilMaskProc> fStencilMask;
219 GLPtr<GrGLStencilMaskSeparateProc> fStencilMaskSeparate;
220 GLPtr<GrGLStencilOpProc> fStencilOp;
221 GLPtr<GrGLStencilOpSeparateProc> fStencilOpSeparate;
222 GLPtr<GrGLTexImage2DProc> fTexImage2D;
223 GLPtr<GrGLTexParameteriProc> fTexParameteri;
224 GLPtr<GrGLTexSubImage2DProc> fTexSubImage2D;
225 GLPtr<GrGLTexStorage2DProc> fTexStorage2D;
226 GLPtr<GrGLUniform1fProc> fUniform1f;
227 GLPtr<GrGLUniform1iProc> fUniform1i;
228 GLPtr<GrGLUniform1fvProc> fUniform1fv;
229 GLPtr<GrGLUniform1ivProc> fUniform1iv;
230 GLPtr<GrGLUniform2fProc> fUniform2f;
231 GLPtr<GrGLUniform2iProc> fUniform2i;
232 GLPtr<GrGLUniform2fvProc> fUniform2fv;
233 GLPtr<GrGLUniform2ivProc> fUniform2iv;
234 GLPtr<GrGLUniform3fProc> fUniform3f;
235 GLPtr<GrGLUniform3iProc> fUniform3i;
236 GLPtr<GrGLUniform3fvProc> fUniform3fv;
237 GLPtr<GrGLUniform3ivProc> fUniform3iv;
238 GLPtr<GrGLUniform4fProc> fUniform4f;
239 GLPtr<GrGLUniform4iProc> fUniform4i;
240 GLPtr<GrGLUniform4fvProc> fUniform4fv;
241 GLPtr<GrGLUniform4ivProc> fUniform4iv;
242 GLPtr<GrGLUniformMatrix2fvProc> fUniformMatrix2fv;
243 GLPtr<GrGLUniformMatrix3fvProc> fUniformMatrix3fv;
244 GLPtr<GrGLUniformMatrix4fvProc> fUniformMatrix4fv;
245 GLPtr<GrGLUnmapBufferProc> fUnmapBuffer;
246 GLPtr<GrGLUseProgramProc> fUseProgram;
247 GLPtr<GrGLVertexAttrib4fvProc> fVertexAttrib4fv;
248 GLPtr<GrGLVertexAttribPointerProc> fVertexAttribPointer;
249 GLPtr<GrGLViewportProc> fViewport;
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000250
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +0000251 // Per-GL func callback
252#if GR_GL_PER_GL_FUNC_CALLBACK
253 GrGLInterfaceCallbackProc fCallback;
254 GrGLInterfaceCallbackData fCallbackData;
255#endif
256
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000257};
twiz@google.com59a190b2011-03-14 21:23:01 +0000258
259#endif