2 * Copyright 2011 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef GrGLInterface_DEFINED
9 #define GrGLInterface_DEFINED
11 #include "include/core/SkRefCnt.h"
12 #include "include/gpu/gl/GrGLExtensions.h"
13 #include "include/gpu/gl/GrGLFunctions.h"
15 ////////////////////////////////////////////////////////////////////////////////
17 typedef void(*GrGLFuncPtr)();
22 * Rather than depend on platform-specific GL headers and libraries, we require
23 * the client to provide a struct of GL function pointers. This struct can be
24 * specified per-GrContext as a parameter to GrContext::MakeGL. If no interface is
25 * passed to MakeGL then a default GL interface is created using GrGLMakeNativeInterface().
26 * If this returns nullptr then GrContext::MakeGL() will fail.
28 * The implementation of GrGLMakeNativeInterface is platform-specific. Several
29 * implementations have been provided (for GLX, WGL, EGL, etc), along with an
30 * implementation that simply returns nullptr. Clients should select the most
31 * appropriate one to build.
33 SK_API sk_sp<const GrGLInterface> GrGLMakeNativeInterface();
36 * GrContext uses the following interface to make all calls into OpenGL. When a
37 * GrContext is created it is given a GrGLInterface. The interface's function
38 * pointers must be valid for the OpenGL context associated with the GrContext.
39 * On some platforms, such as Windows, function pointers for OpenGL extensions
40 * may vary between OpenGL contexts. So the caller must be careful to use a
41 * GrGLInterface initialized for the correct context. All functions that should
42 * be available based on the OpenGL's version and extension string must be
43 * non-NULL or GrContext creation will fail. This can be tested with the
44 * validate() method when the OpenGL context has been made current.
46 struct SK_API GrGLInterface : public SkRefCnt {
48 using INHERITED = SkRefCnt;
51 // This is here to avoid having our debug code that checks for a GL error after most GL calls
52 // accidentally swallow an OOM that should be reported.
53 mutable bool fOOMed = false;
54 bool fSuppressErrorLogging = false;
60 // Validates that the GrGLInterface supports its advertised standard. This means the necessary
61 // function pointers have been initialized for both the GL version and any advertised
63 bool validate() const;
66 GrGLenum checkError(const char* location, const char* call) const;
67 bool checkAndResetOOMed() const;
68 void suppressErrorLogging();
72 GrGLInterface(const GrGLInterface& that)
73 : fStandard(that.fStandard)
74 , fExtensions(that.fExtensions)
75 , fFunctions(that.fFunctions) {}
78 // Indicates the type of GL implementation
80 GrGLStandard fStandard;
81 GrGLStandard fBindingsExported; // Legacy name, will be remove when Chromium is updated.
84 GrGLExtensions fExtensions;
86 bool hasExtension(const char ext[]) const { return fExtensions.has(ext); }
89 * The function pointers are in a struct so that we can have a compiler generated assignment
93 GrGLFunction<GrGLActiveTextureFn> fActiveTexture;
94 GrGLFunction<GrGLAttachShaderFn> fAttachShader;
95 GrGLFunction<GrGLBeginQueryFn> fBeginQuery;
96 GrGLFunction<GrGLBindAttribLocationFn> fBindAttribLocation;
97 GrGLFunction<GrGLBindBufferFn> fBindBuffer;
98 GrGLFunction<GrGLBindFragDataLocationFn> fBindFragDataLocation;
99 GrGLFunction<GrGLBindFragDataLocationIndexedFn> fBindFragDataLocationIndexed;
100 GrGLFunction<GrGLBindFramebufferFn> fBindFramebuffer;
101 GrGLFunction<GrGLBindRenderbufferFn> fBindRenderbuffer;
102 GrGLFunction<GrGLBindSamplerFn> fBindSampler;
103 GrGLFunction<GrGLBindTextureFn> fBindTexture;
104 GrGLFunction<GrGLBindVertexArrayFn> fBindVertexArray;
105 GrGLFunction<GrGLBlendBarrierFn> fBlendBarrier;
106 GrGLFunction<GrGLBlendColorFn> fBlendColor;
107 GrGLFunction<GrGLBlendEquationFn> fBlendEquation;
108 GrGLFunction<GrGLBlendFuncFn> fBlendFunc;
109 GrGLFunction<GrGLBlitFramebufferFn> fBlitFramebuffer;
110 GrGLFunction<GrGLBufferDataFn> fBufferData;
111 GrGLFunction<GrGLBufferSubDataFn> fBufferSubData;
112 GrGLFunction<GrGLCheckFramebufferStatusFn> fCheckFramebufferStatus;
113 GrGLFunction<GrGLClearFn> fClear;
114 GrGLFunction<GrGLClearColorFn> fClearColor;
115 GrGLFunction<GrGLClearStencilFn> fClearStencil;
116 GrGLFunction<GrGLClearTexImageFn> fClearTexImage;
117 GrGLFunction<GrGLClearTexSubImageFn> fClearTexSubImage;
118 GrGLFunction<GrGLColorMaskFn> fColorMask;
119 GrGLFunction<GrGLCompileShaderFn> fCompileShader;
120 GrGLFunction<GrGLCompressedTexImage2DFn> fCompressedTexImage2D;
121 GrGLFunction<GrGLCompressedTexSubImage2DFn> fCompressedTexSubImage2D;
122 GrGLFunction<GrGLCopyTexSubImage2DFn> fCopyTexSubImage2D;
123 GrGLFunction<GrGLCreateProgramFn> fCreateProgram;
124 GrGLFunction<GrGLCreateShaderFn> fCreateShader;
125 GrGLFunction<GrGLCullFaceFn> fCullFace;
126 GrGLFunction<GrGLDeleteBuffersFn> fDeleteBuffers;
127 GrGLFunction<GrGLDeleteFencesFn> fDeleteFences;
128 GrGLFunction<GrGLDeleteFramebuffersFn> fDeleteFramebuffers;
129 GrGLFunction<GrGLDeleteProgramFn> fDeleteProgram;
130 GrGLFunction<GrGLDeleteQueriesFn> fDeleteQueries;
131 GrGLFunction<GrGLDeleteRenderbuffersFn> fDeleteRenderbuffers;
132 GrGLFunction<GrGLDeleteSamplersFn> fDeleteSamplers;
133 GrGLFunction<GrGLDeleteShaderFn> fDeleteShader;
134 GrGLFunction<GrGLDeleteTexturesFn> fDeleteTextures;
135 GrGLFunction<GrGLDeleteVertexArraysFn> fDeleteVertexArrays;
136 GrGLFunction<GrGLDepthMaskFn> fDepthMask;
137 GrGLFunction<GrGLDisableFn> fDisable;
138 GrGLFunction<GrGLDisableVertexAttribArrayFn> fDisableVertexAttribArray;
139 GrGLFunction<GrGLDrawArraysFn> fDrawArrays;
140 GrGLFunction<GrGLDrawArraysIndirectFn> fDrawArraysIndirect;
141 GrGLFunction<GrGLDrawArraysInstancedFn> fDrawArraysInstanced;
142 GrGLFunction<GrGLDrawBufferFn> fDrawBuffer;
143 GrGLFunction<GrGLDrawBuffersFn> fDrawBuffers;
144 GrGLFunction<GrGLDrawElementsFn> fDrawElements;
145 GrGLFunction<GrGLDrawElementsIndirectFn> fDrawElementsIndirect;
146 GrGLFunction<GrGLDrawElementsInstancedFn> fDrawElementsInstanced;
147 GrGLFunction<GrGLDrawRangeElementsFn> fDrawRangeElements;
148 GrGLFunction<GrGLEnableFn> fEnable;
149 GrGLFunction<GrGLEnableVertexAttribArrayFn> fEnableVertexAttribArray;
150 GrGLFunction<GrGLEndQueryFn> fEndQuery;
151 GrGLFunction<GrGLFinishFn> fFinish;
152 GrGLFunction<GrGLFinishFenceFn> fFinishFence;
153 GrGLFunction<GrGLFlushFn> fFlush;
154 GrGLFunction<GrGLFlushMappedBufferRangeFn> fFlushMappedBufferRange;
155 GrGLFunction<GrGLFramebufferRenderbufferFn> fFramebufferRenderbuffer;
156 GrGLFunction<GrGLFramebufferTexture2DFn> fFramebufferTexture2D;
157 GrGLFunction<GrGLFramebufferTexture2DMultisampleFn> fFramebufferTexture2DMultisample;
158 GrGLFunction<GrGLFrontFaceFn> fFrontFace;
159 GrGLFunction<GrGLGenBuffersFn> fGenBuffers;
160 GrGLFunction<GrGLGenFencesFn> fGenFences;
161 GrGLFunction<GrGLGenFramebuffersFn> fGenFramebuffers;
162 GrGLFunction<GrGLGenerateMipmapFn> fGenerateMipmap;
163 GrGLFunction<GrGLGenQueriesFn> fGenQueries;
164 GrGLFunction<GrGLGenRenderbuffersFn> fGenRenderbuffers;
165 GrGLFunction<GrGLGenSamplersFn> fGenSamplers;
166 GrGLFunction<GrGLGenTexturesFn> fGenTextures;
167 GrGLFunction<GrGLGenVertexArraysFn> fGenVertexArrays;
168 GrGLFunction<GrGLGetBufferParameterivFn> fGetBufferParameteriv;
169 GrGLFunction<GrGLGetErrorFn> fGetError;
170 GrGLFunction<GrGLGetFramebufferAttachmentParameterivFn> fGetFramebufferAttachmentParameteriv;
171 GrGLFunction<GrGLGetFloatvFn> fGetFloatv;
172 GrGLFunction<GrGLGetIntegervFn> fGetIntegerv;
173 GrGLFunction<GrGLGetMultisamplefvFn> fGetMultisamplefv;
174 GrGLFunction<GrGLGetProgramBinaryFn> fGetProgramBinary;
175 GrGLFunction<GrGLGetProgramInfoLogFn> fGetProgramInfoLog;
176 GrGLFunction<GrGLGetProgramivFn> fGetProgramiv;
177 GrGLFunction<GrGLGetQueryObjecti64vFn> fGetQueryObjecti64v;
178 GrGLFunction<GrGLGetQueryObjectivFn> fGetQueryObjectiv;
179 GrGLFunction<GrGLGetQueryObjectui64vFn> fGetQueryObjectui64v;
180 GrGLFunction<GrGLGetQueryObjectuivFn> fGetQueryObjectuiv;
181 GrGLFunction<GrGLGetQueryivFn> fGetQueryiv;
182 GrGLFunction<GrGLGetRenderbufferParameterivFn> fGetRenderbufferParameteriv;
183 GrGLFunction<GrGLGetShaderInfoLogFn> fGetShaderInfoLog;
184 GrGLFunction<GrGLGetShaderivFn> fGetShaderiv;
185 GrGLFunction<GrGLGetShaderPrecisionFormatFn> fGetShaderPrecisionFormat;
186 GrGLFunction<GrGLGetStringFn> fGetString;
187 GrGLFunction<GrGLGetStringiFn> fGetStringi;
188 GrGLFunction<GrGLGetTexLevelParameterivFn> fGetTexLevelParameteriv;
189 GrGLFunction<GrGLGetUniformLocationFn> fGetUniformLocation;
190 GrGLFunction<GrGLInsertEventMarkerFn> fInsertEventMarker;
191 GrGLFunction<GrGLInvalidateBufferDataFn> fInvalidateBufferData;
192 GrGLFunction<GrGLInvalidateBufferSubDataFn> fInvalidateBufferSubData;
193 GrGLFunction<GrGLInvalidateFramebufferFn> fInvalidateFramebuffer;
194 GrGLFunction<GrGLInvalidateSubFramebufferFn> fInvalidateSubFramebuffer;
195 GrGLFunction<GrGLInvalidateTexImageFn> fInvalidateTexImage;
196 GrGLFunction<GrGLInvalidateTexSubImageFn> fInvalidateTexSubImage;
197 GrGLFunction<GrGLIsTextureFn> fIsTexture;
198 GrGLFunction<GrGLLineWidthFn> fLineWidth;
199 GrGLFunction<GrGLLinkProgramFn> fLinkProgram;
200 GrGLFunction<GrGLProgramBinaryFn> fProgramBinary;
201 GrGLFunction<GrGLProgramParameteriFn> fProgramParameteri;
202 GrGLFunction<GrGLMapBufferFn> fMapBuffer;
203 GrGLFunction<GrGLMapBufferRangeFn> fMapBufferRange;
204 GrGLFunction<GrGLMapBufferSubDataFn> fMapBufferSubData;
205 GrGLFunction<GrGLMapTexSubImage2DFn> fMapTexSubImage2D;
206 GrGLFunction<GrGLMemoryBarrierFn> fMemoryBarrier;
207 GrGLFunction<GrGLDrawArraysInstancedBaseInstanceFn> fDrawArraysInstancedBaseInstance;
208 GrGLFunction<GrGLDrawElementsInstancedBaseVertexBaseInstanceFn> fDrawElementsInstancedBaseVertexBaseInstance;
209 GrGLFunction<GrGLMultiDrawArraysIndirectFn> fMultiDrawArraysIndirect;
210 GrGLFunction<GrGLMultiDrawElementsIndirectFn> fMultiDrawElementsIndirect;
211 GrGLFunction<GrGLMultiDrawArraysInstancedBaseInstanceFn> fMultiDrawArraysInstancedBaseInstance;
212 GrGLFunction<GrGLMultiDrawElementsInstancedBaseVertexBaseInstanceFn> fMultiDrawElementsInstancedBaseVertexBaseInstance;
213 GrGLFunction<GrGLPatchParameteriFn> fPatchParameteri;
214 GrGLFunction<GrGLPixelStoreiFn> fPixelStorei;
215 GrGLFunction<GrGLPolygonModeFn> fPolygonMode;
216 GrGLFunction<GrGLPopGroupMarkerFn> fPopGroupMarker;
217 GrGLFunction<GrGLPushGroupMarkerFn> fPushGroupMarker;
218 GrGLFunction<GrGLQueryCounterFn> fQueryCounter;
219 GrGLFunction<GrGLReadBufferFn> fReadBuffer;
220 GrGLFunction<GrGLReadPixelsFn> fReadPixels;
221 GrGLFunction<GrGLRenderbufferStorageFn> fRenderbufferStorage;
223 // On OpenGL ES there are multiple incompatible extensions that add support for MSAA
224 // and ES3 adds MSAA support to the standard. On an ES3 driver we may still use the
225 // older extensions for performance reasons or due to ES3 driver bugs. We want the function
226 // that creates the GrGLInterface to provide all available functions and internally
227 // we will select among them. They all have a method called glRenderbufferStorageMultisample*.
228 // So we have separate function pointers for GL_IMG/EXT_multisampled_to_texture,
229 // GL_CHROMIUM/ANGLE_framebuffer_multisample/ES3, and GL_APPLE_framebuffer_multisample
232 // If a driver supports multiple GL_ARB_framebuffer_multisample-style extensions then we will
233 // assume the function pointers for the standard (or equivalent GL_ARB) version have
234 // been preferred over GL_EXT, GL_CHROMIUM, or GL_ANGLE variations that have reduced
237 // GL_EXT_multisampled_render_to_texture (preferred) or GL_IMG_multisampled_render_to_texture
238 GrGLFunction<GrGLRenderbufferStorageMultisampleFn> fRenderbufferStorageMultisampleES2EXT;
239 // GL_APPLE_framebuffer_multisample
240 GrGLFunction<GrGLRenderbufferStorageMultisampleFn> fRenderbufferStorageMultisampleES2APPLE;
242 // This is used to store the pointer for GL_ARB/EXT/ANGLE/CHROMIUM_framebuffer_multisample or
243 // the standard function in ES3+ or GL 3.0+.
244 GrGLFunction<GrGLRenderbufferStorageMultisampleFn> fRenderbufferStorageMultisample;
246 // Pointer to BindUniformLocationCHROMIUM from the GL_CHROMIUM_bind_uniform_location extension.
247 GrGLFunction<GrGLBindUniformLocationFn> fBindUniformLocation;
249 GrGLFunction<GrGLResolveMultisampleFramebufferFn> fResolveMultisampleFramebuffer;
250 GrGLFunction<GrGLSamplerParameterfFn> fSamplerParameterf;
251 GrGLFunction<GrGLSamplerParameteriFn> fSamplerParameteri;
252 GrGLFunction<GrGLSamplerParameterivFn> fSamplerParameteriv;
253 GrGLFunction<GrGLScissorFn> fScissor;
254 GrGLFunction<GrGLSetFenceFn> fSetFence;
255 GrGLFunction<GrGLShaderSourceFn> fShaderSource;
256 GrGLFunction<GrGLStencilFuncFn> fStencilFunc;
257 GrGLFunction<GrGLStencilFuncSeparateFn> fStencilFuncSeparate;
258 GrGLFunction<GrGLStencilMaskFn> fStencilMask;
259 GrGLFunction<GrGLStencilMaskSeparateFn> fStencilMaskSeparate;
260 GrGLFunction<GrGLStencilOpFn> fStencilOp;
261 GrGLFunction<GrGLStencilOpSeparateFn> fStencilOpSeparate;
262 GrGLFunction<GrGLTestFenceFn> fTestFence;
263 GrGLFunction<GrGLTexBufferFn> fTexBuffer;
264 GrGLFunction<GrGLTexBufferRangeFn> fTexBufferRange;
265 GrGLFunction<GrGLTexImage2DFn> fTexImage2D;
266 GrGLFunction<GrGLTexParameterfFn> fTexParameterf;
267 GrGLFunction<GrGLTexParameterfvFn> fTexParameterfv;
268 GrGLFunction<GrGLTexParameteriFn> fTexParameteri;
269 GrGLFunction<GrGLTexParameterivFn> fTexParameteriv;
270 GrGLFunction<GrGLTexSubImage2DFn> fTexSubImage2D;
271 GrGLFunction<GrGLTexStorage2DFn> fTexStorage2D;
272 GrGLFunction<GrGLTextureBarrierFn> fTextureBarrier;
273 GrGLFunction<GrGLDiscardFramebufferFn> fDiscardFramebuffer;
274 GrGLFunction<GrGLUniform1fFn> fUniform1f;
275 GrGLFunction<GrGLUniform1iFn> fUniform1i;
276 GrGLFunction<GrGLUniform1fvFn> fUniform1fv;
277 GrGLFunction<GrGLUniform1ivFn> fUniform1iv;
278 GrGLFunction<GrGLUniform2fFn> fUniform2f;
279 GrGLFunction<GrGLUniform2iFn> fUniform2i;
280 GrGLFunction<GrGLUniform2fvFn> fUniform2fv;
281 GrGLFunction<GrGLUniform2ivFn> fUniform2iv;
282 GrGLFunction<GrGLUniform3fFn> fUniform3f;
283 GrGLFunction<GrGLUniform3iFn> fUniform3i;
284 GrGLFunction<GrGLUniform3fvFn> fUniform3fv;
285 GrGLFunction<GrGLUniform3ivFn> fUniform3iv;
286 GrGLFunction<GrGLUniform4fFn> fUniform4f;
287 GrGLFunction<GrGLUniform4iFn> fUniform4i;
288 GrGLFunction<GrGLUniform4fvFn> fUniform4fv;
289 GrGLFunction<GrGLUniform4ivFn> fUniform4iv;
290 GrGLFunction<GrGLUniformMatrix2fvFn> fUniformMatrix2fv;
291 GrGLFunction<GrGLUniformMatrix3fvFn> fUniformMatrix3fv;
292 GrGLFunction<GrGLUniformMatrix4fvFn> fUniformMatrix4fv;
293 GrGLFunction<GrGLUnmapBufferFn> fUnmapBuffer;
294 GrGLFunction<GrGLUnmapBufferSubDataFn> fUnmapBufferSubData;
295 GrGLFunction<GrGLUnmapTexSubImage2DFn> fUnmapTexSubImage2D;
296 GrGLFunction<GrGLUseProgramFn> fUseProgram;
297 GrGLFunction<GrGLVertexAttrib1fFn> fVertexAttrib1f;
298 GrGLFunction<GrGLVertexAttrib2fvFn> fVertexAttrib2fv;
299 GrGLFunction<GrGLVertexAttrib3fvFn> fVertexAttrib3fv;
300 GrGLFunction<GrGLVertexAttrib4fvFn> fVertexAttrib4fv;
301 GrGLFunction<GrGLVertexAttribDivisorFn> fVertexAttribDivisor;
302 GrGLFunction<GrGLVertexAttribIPointerFn> fVertexAttribIPointer;
303 GrGLFunction<GrGLVertexAttribPointerFn> fVertexAttribPointer;
304 GrGLFunction<GrGLViewportFn> fViewport;
306 /* NV_framebuffer_mixed_samples */
307 GrGLFunction<GrGLCoverageModulationFn> fCoverageModulation;
310 GrGLFunction<GrGLFenceSyncFn> fFenceSync;
311 GrGLFunction<GrGLIsSyncFn> fIsSync;
312 GrGLFunction<GrGLClientWaitSyncFn> fClientWaitSync;
313 GrGLFunction<GrGLWaitSyncFn> fWaitSync;
314 GrGLFunction<GrGLDeleteSyncFn> fDeleteSync;
316 /* ARB_internalforamt_query */
317 GrGLFunction<GrGLGetInternalformativFn> fGetInternalformativ;
320 GrGLFunction<GrGLDebugMessageControlFn> fDebugMessageControl;
321 GrGLFunction<GrGLDebugMessageInsertFn> fDebugMessageInsert;
322 GrGLFunction<GrGLDebugMessageCallbackFn> fDebugMessageCallback;
323 GrGLFunction<GrGLGetDebugMessageLogFn> fGetDebugMessageLog;
324 GrGLFunction<GrGLPushDebugGroupFn> fPushDebugGroup;
325 GrGLFunction<GrGLPopDebugGroupFn> fPopDebugGroup;
326 GrGLFunction<GrGLObjectLabelFn> fObjectLabel;
328 /* EXT_window_rectangles */
329 GrGLFunction<GrGLWindowRectanglesFn> fWindowRectangles;
331 /* GL_QCOM_tiled_rendering */
332 GrGLFunction<GrGLStartTilingFn> fStartTiling;
333 GrGLFunction<GrGLEndTilingFn> fEndTiling;
337 // This exists for internal testing.
338 virtual void abandon() const;