• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2011 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef GrGLInterface_DEFINED
9 #define GrGLInterface_DEFINED
10 
11 #include "include/core/SkRefCnt.h"
12 #include "include/gpu/gl/GrGLExtensions.h"
13 #include "include/gpu/gl/GrGLFunctions.h"
14 
15 ////////////////////////////////////////////////////////////////////////////////
16 
17 typedef void(*GrGLFuncPtr)();
18 struct GrGLInterface;
19 
20 
21 /**
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.
27  *
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.
32  */
33 SK_API sk_sp<const GrGLInterface> GrGLMakeNativeInterface();
34 // Deprecated alternative to GrGLMakeNativeInterface().
35 SK_API const GrGLInterface* GrGLCreateNativeInterface();
36 
37 /**
38  * GrContext uses the following interface to make all calls into OpenGL. When a
39  * GrContext is created it is given a GrGLInterface. The interface's function
40  * pointers must be valid for the OpenGL context associated with the GrContext.
41  * On some platforms, such as Windows, function pointers for OpenGL extensions
42  * may vary between OpenGL contexts. So the caller must be careful to use a
43  * GrGLInterface initialized for the correct context. All functions that should
44  * be available based on the OpenGL's version and extension string must be
45  * non-NULL or GrContext creation will fail. This can be tested with the
46  * validate() method when the OpenGL context has been made current.
47  */
48 struct SK_API GrGLInterface : public SkRefCnt {
49 private:
50     typedef SkRefCnt INHERITED;
51 
52 public:
53     GrGLInterface();
54 
55     // Validates that the GrGLInterface supports its advertised standard. This means the necessary
56     // function pointers have been initialized for both the GL version and any advertised
57     // extensions.
58     bool validate() const;
59 
60     // Indicates the type of GL implementation
61     union {
62         GrGLStandard fStandard;
63         GrGLStandard fBindingsExported; // Legacy name, will be remove when Chromium is updated.
64     };
65 
66     GrGLExtensions fExtensions;
67 
hasExtensionGrGLInterface68     bool hasExtension(const char ext[]) const { return fExtensions.has(ext); }
69 
70     /**
71      * The function pointers are in a struct so that we can have a compiler generated assignment
72      * operator.
73      */
74     struct Functions {
75         GrGLFunction<GrGLActiveTextureFn> fActiveTexture;
76         GrGLFunction<GrGLAttachShaderFn> fAttachShader;
77         GrGLFunction<GrGLBeginQueryFn> fBeginQuery;
78         GrGLFunction<GrGLBindAttribLocationFn> fBindAttribLocation;
79         GrGLFunction<GrGLBindBufferFn> fBindBuffer;
80         GrGLFunction<GrGLBindFragDataLocationFn> fBindFragDataLocation;
81         GrGLFunction<GrGLBindFragDataLocationIndexedFn> fBindFragDataLocationIndexed;
82         GrGLFunction<GrGLBindFramebufferFn> fBindFramebuffer;
83         GrGLFunction<GrGLBindRenderbufferFn> fBindRenderbuffer;
84         GrGLFunction<GrGLBindSamplerFn> fBindSampler;
85         GrGLFunction<GrGLBindTextureFn> fBindTexture;
86         GrGLFunction<GrGLBindVertexArrayFn> fBindVertexArray;
87         GrGLFunction<GrGLBlendBarrierFn> fBlendBarrier;
88         GrGLFunction<GrGLBlendColorFn> fBlendColor;
89         GrGLFunction<GrGLBlendEquationFn> fBlendEquation;
90         GrGLFunction<GrGLBlendFuncFn> fBlendFunc;
91         GrGLFunction<GrGLBlitFramebufferFn> fBlitFramebuffer;
92         GrGLFunction<GrGLBufferDataFn> fBufferData;
93         GrGLFunction<GrGLBufferSubDataFn> fBufferSubData;
94         GrGLFunction<GrGLCheckFramebufferStatusFn> fCheckFramebufferStatus;
95         GrGLFunction<GrGLClearFn> fClear;
96         GrGLFunction<GrGLClearColorFn> fClearColor;
97         GrGLFunction<GrGLClearStencilFn> fClearStencil;
98         GrGLFunction<GrGLClearTexImageFn> fClearTexImage;
99         GrGLFunction<GrGLClearTexSubImageFn> fClearTexSubImage;
100         GrGLFunction<GrGLColorMaskFn> fColorMask;
101         GrGLFunction<GrGLCompileShaderFn> fCompileShader;
102         GrGLFunction<GrGLCompressedTexImage2DFn> fCompressedTexImage2D;
103         GrGLFunction<GrGLCompressedTexSubImage2DFn> fCompressedTexSubImage2D;
104         GrGLFunction<GrGLCopyTexSubImage2DFn> fCopyTexSubImage2D;
105         GrGLFunction<GrGLCreateProgramFn> fCreateProgram;
106         GrGLFunction<GrGLCreateShaderFn> fCreateShader;
107         GrGLFunction<GrGLCullFaceFn> fCullFace;
108         GrGLFunction<GrGLDeleteBuffersFn> fDeleteBuffers;
109         GrGLFunction<GrGLDeleteFencesFn> fDeleteFences;
110         GrGLFunction<GrGLDeleteFramebuffersFn> fDeleteFramebuffers;
111         GrGLFunction<GrGLDeleteProgramFn> fDeleteProgram;
112         GrGLFunction<GrGLDeleteQueriesFn> fDeleteQueries;
113         GrGLFunction<GrGLDeleteRenderbuffersFn> fDeleteRenderbuffers;
114         GrGLFunction<GrGLDeleteSamplersFn> fDeleteSamplers;
115         GrGLFunction<GrGLDeleteShaderFn> fDeleteShader;
116         GrGLFunction<GrGLDeleteTexturesFn> fDeleteTextures;
117         GrGLFunction<GrGLDeleteVertexArraysFn> fDeleteVertexArrays;
118         GrGLFunction<GrGLDepthMaskFn> fDepthMask;
119         GrGLFunction<GrGLDisableFn> fDisable;
120         GrGLFunction<GrGLDisableVertexAttribArrayFn> fDisableVertexAttribArray;
121         GrGLFunction<GrGLDrawArraysFn> fDrawArrays;
122         GrGLFunction<GrGLDrawArraysIndirectFn> fDrawArraysIndirect;
123         GrGLFunction<GrGLDrawArraysInstancedFn> fDrawArraysInstanced;
124         GrGLFunction<GrGLDrawBufferFn> fDrawBuffer;
125         GrGLFunction<GrGLDrawBuffersFn> fDrawBuffers;
126         GrGLFunction<GrGLDrawElementsFn> fDrawElements;
127         GrGLFunction<GrGLDrawElementsIndirectFn> fDrawElementsIndirect;
128         GrGLFunction<GrGLDrawElementsInstancedFn> fDrawElementsInstanced;
129         GrGLFunction<GrGLDrawRangeElementsFn> fDrawRangeElements;
130         GrGLFunction<GrGLEnableFn> fEnable;
131         GrGLFunction<GrGLEnableVertexAttribArrayFn> fEnableVertexAttribArray;
132         GrGLFunction<GrGLEndQueryFn> fEndQuery;
133         GrGLFunction<GrGLFinishFn> fFinish;
134         GrGLFunction<GrGLFinishFenceFn> fFinishFence;
135         GrGLFunction<GrGLFlushFn> fFlush;
136         GrGLFunction<GrGLFlushMappedBufferRangeFn> fFlushMappedBufferRange;
137         GrGLFunction<GrGLFramebufferRenderbufferFn> fFramebufferRenderbuffer;
138         GrGLFunction<GrGLFramebufferTexture2DFn> fFramebufferTexture2D;
139         GrGLFunction<GrGLFramebufferTexture2DMultisampleFn> fFramebufferTexture2DMultisample;
140         GrGLFunction<GrGLFrontFaceFn> fFrontFace;
141         GrGLFunction<GrGLGenBuffersFn> fGenBuffers;
142         GrGLFunction<GrGLGenFencesFn> fGenFences;
143         GrGLFunction<GrGLGenFramebuffersFn> fGenFramebuffers;
144         GrGLFunction<GrGLGenerateMipmapFn> fGenerateMipmap;
145         GrGLFunction<GrGLGenQueriesFn> fGenQueries;
146         GrGLFunction<GrGLGenRenderbuffersFn> fGenRenderbuffers;
147         GrGLFunction<GrGLGenSamplersFn> fGenSamplers;
148         GrGLFunction<GrGLGenTexturesFn> fGenTextures;
149         GrGLFunction<GrGLGenVertexArraysFn> fGenVertexArrays;
150         GrGLFunction<GrGLGetBufferParameterivFn> fGetBufferParameteriv;
151         GrGLFunction<GrGLGetErrorFn> fGetError;
152         GrGLFunction<GrGLGetFramebufferAttachmentParameterivFn> fGetFramebufferAttachmentParameteriv;
153         GrGLFunction<GrGLGetIntegervFn> fGetIntegerv;
154         GrGLFunction<GrGLGetMultisamplefvFn> fGetMultisamplefv;
155         GrGLFunction<GrGLGetProgramBinaryFn> fGetProgramBinary;
156         GrGLFunction<GrGLGetProgramInfoLogFn> fGetProgramInfoLog;
157         GrGLFunction<GrGLGetProgramivFn> fGetProgramiv;
158         GrGLFunction<GrGLGetQueryObjecti64vFn> fGetQueryObjecti64v;
159         GrGLFunction<GrGLGetQueryObjectivFn> fGetQueryObjectiv;
160         GrGLFunction<GrGLGetQueryObjectui64vFn> fGetQueryObjectui64v;
161         GrGLFunction<GrGLGetQueryObjectuivFn> fGetQueryObjectuiv;
162         GrGLFunction<GrGLGetQueryivFn> fGetQueryiv;
163         GrGLFunction<GrGLGetRenderbufferParameterivFn> fGetRenderbufferParameteriv;
164         GrGLFunction<GrGLGetShaderInfoLogFn> fGetShaderInfoLog;
165         GrGLFunction<GrGLGetShaderivFn> fGetShaderiv;
166         GrGLFunction<GrGLGetShaderPrecisionFormatFn> fGetShaderPrecisionFormat;
167         GrGLFunction<GrGLGetStringFn> fGetString;
168         GrGLFunction<GrGLGetStringiFn> fGetStringi;
169         GrGLFunction<GrGLGetTexLevelParameterivFn> fGetTexLevelParameteriv;
170         GrGLFunction<GrGLGetUniformLocationFn> fGetUniformLocation;
171         GrGLFunction<GrGLInsertEventMarkerFn> fInsertEventMarker;
172         GrGLFunction<GrGLInvalidateBufferDataFn> fInvalidateBufferData;
173         GrGLFunction<GrGLInvalidateBufferSubDataFn> fInvalidateBufferSubData;
174         GrGLFunction<GrGLInvalidateFramebufferFn> fInvalidateFramebuffer;
175         GrGLFunction<GrGLInvalidateSubFramebufferFn> fInvalidateSubFramebuffer;
176         GrGLFunction<GrGLInvalidateTexImageFn> fInvalidateTexImage;
177         GrGLFunction<GrGLInvalidateTexSubImageFn> fInvalidateTexSubImage;
178         GrGLFunction<GrGLIsTextureFn> fIsTexture;
179         GrGLFunction<GrGLLineWidthFn> fLineWidth;
180         GrGLFunction<GrGLLinkProgramFn> fLinkProgram;
181         GrGLFunction<GrGLProgramBinaryFn> fProgramBinary;
182         GrGLFunction<GrGLProgramParameteriFn> fProgramParameteri;
183         GrGLFunction<GrGLMapBufferFn> fMapBuffer;
184         GrGLFunction<GrGLMapBufferRangeFn> fMapBufferRange;
185         GrGLFunction<GrGLMapBufferSubDataFn> fMapBufferSubData;
186         GrGLFunction<GrGLMapTexSubImage2DFn> fMapTexSubImage2D;
187         GrGLFunction<GrGLMemoryBarrierFn> fMemoryBarrier;
188         GrGLFunction<GrGLMultiDrawArraysIndirectFn> fMultiDrawArraysIndirect;
189         GrGLFunction<GrGLMultiDrawElementsIndirectFn> fMultiDrawElementsIndirect;
190         GrGLFunction<GrGLPatchParameteriFn> fPatchParameteri;
191         GrGLFunction<GrGLPixelStoreiFn> fPixelStorei;
192         GrGLFunction<GrGLPolygonModeFn> fPolygonMode;
193         GrGLFunction<GrGLPopGroupMarkerFn> fPopGroupMarker;
194         GrGLFunction<GrGLPushGroupMarkerFn> fPushGroupMarker;
195         GrGLFunction<GrGLQueryCounterFn> fQueryCounter;
196         GrGLFunction<GrGLReadBufferFn> fReadBuffer;
197         GrGLFunction<GrGLReadPixelsFn> fReadPixels;
198         GrGLFunction<GrGLRenderbufferStorageFn> fRenderbufferStorage;
199 
200         //  On OpenGL ES there are multiple incompatible extensions that add support for MSAA
201         //  and ES3 adds MSAA support to the standard. On an ES3 driver we may still use the
202         //  older extensions for performance reasons or due to ES3 driver bugs. We want the function
203         //  that creates the GrGLInterface to provide all available functions and internally
204         //  we will select among them. They all have a method called glRenderbufferStorageMultisample*.
205         //  So we have separate function pointers for GL_IMG/EXT_multisampled_to_texture,
206         //  GL_CHROMIUM/ANGLE_framebuffer_multisample/ES3, and GL_APPLE_framebuffer_multisample
207         //  variations.
208         //
209         //  If a driver supports multiple GL_ARB_framebuffer_multisample-style extensions then we will
210         //  assume the function pointers for the standard (or equivalent GL_ARB) version have
211         //  been preferred over GL_EXT, GL_CHROMIUM, or GL_ANGLE variations that have reduced
212         //  functionality.
213 
214         //  GL_EXT_multisampled_render_to_texture (preferred) or GL_IMG_multisampled_render_to_texture
215         GrGLFunction<GrGLRenderbufferStorageMultisampleFn> fRenderbufferStorageMultisampleES2EXT;
216         //  GL_APPLE_framebuffer_multisample
217         GrGLFunction<GrGLRenderbufferStorageMultisampleFn> fRenderbufferStorageMultisampleES2APPLE;
218 
219         //  This is used to store the pointer for GL_ARB/EXT/ANGLE/CHROMIUM_framebuffer_multisample or
220         //  the standard function in ES3+ or GL 3.0+.
221         GrGLFunction<GrGLRenderbufferStorageMultisampleFn> fRenderbufferStorageMultisample;
222 
223         // Pointer to BindUniformLocationCHROMIUM from the GL_CHROMIUM_bind_uniform_location extension.
224         GrGLFunction<GrGLBindUniformLocationFn> fBindUniformLocation;
225 
226         GrGLFunction<GrGLResolveMultisampleFramebufferFn> fResolveMultisampleFramebuffer;
227         GrGLFunction<GrGLSamplerParameteriFn> fSamplerParameteri;
228         GrGLFunction<GrGLSamplerParameterivFn> fSamplerParameteriv;
229         GrGLFunction<GrGLScissorFn> fScissor;
230         GrGLFunction<GrGLSetFenceFn> fSetFence;
231         GrGLFunction<GrGLShaderSourceFn> fShaderSource;
232         GrGLFunction<GrGLStencilFuncFn> fStencilFunc;
233         GrGLFunction<GrGLStencilFuncSeparateFn> fStencilFuncSeparate;
234         GrGLFunction<GrGLStencilMaskFn> fStencilMask;
235         GrGLFunction<GrGLStencilMaskSeparateFn> fStencilMaskSeparate;
236         GrGLFunction<GrGLStencilOpFn> fStencilOp;
237         GrGLFunction<GrGLStencilOpSeparateFn> fStencilOpSeparate;
238         GrGLFunction<GrGLTestFenceFn> fTestFence;
239         GrGLFunction<GrGLTexBufferFn> fTexBuffer;
240         GrGLFunction<GrGLTexBufferRangeFn> fTexBufferRange;
241         GrGLFunction<GrGLTexImage2DFn> fTexImage2D;
242         GrGLFunction<GrGLTexParameterfFn> fTexParameterf;
243         GrGLFunction<GrGLTexParameterfvFn> fTexParameterfv;
244         GrGLFunction<GrGLTexParameteriFn> fTexParameteri;
245         GrGLFunction<GrGLTexParameterivFn> fTexParameteriv;
246         GrGLFunction<GrGLTexSubImage2DFn> fTexSubImage2D;
247         GrGLFunction<GrGLTexStorage2DFn> fTexStorage2D;
248         GrGLFunction<GrGLTextureBarrierFn> fTextureBarrier;
249         GrGLFunction<GrGLDiscardFramebufferFn> fDiscardFramebuffer;
250         GrGLFunction<GrGLUniform1fFn> fUniform1f;
251         GrGLFunction<GrGLUniform1iFn> fUniform1i;
252         GrGLFunction<GrGLUniform1fvFn> fUniform1fv;
253         GrGLFunction<GrGLUniform1ivFn> fUniform1iv;
254         GrGLFunction<GrGLUniform2fFn> fUniform2f;
255         GrGLFunction<GrGLUniform2iFn> fUniform2i;
256         GrGLFunction<GrGLUniform2fvFn> fUniform2fv;
257         GrGLFunction<GrGLUniform2ivFn> fUniform2iv;
258         GrGLFunction<GrGLUniform3fFn> fUniform3f;
259         GrGLFunction<GrGLUniform3iFn> fUniform3i;
260         GrGLFunction<GrGLUniform3fvFn> fUniform3fv;
261         GrGLFunction<GrGLUniform3ivFn> fUniform3iv;
262         GrGLFunction<GrGLUniform4fFn> fUniform4f;
263         GrGLFunction<GrGLUniform4iFn> fUniform4i;
264         GrGLFunction<GrGLUniform4fvFn> fUniform4fv;
265         GrGLFunction<GrGLUniform4ivFn> fUniform4iv;
266         GrGLFunction<GrGLUniformMatrix2fvFn> fUniformMatrix2fv;
267         GrGLFunction<GrGLUniformMatrix3fvFn> fUniformMatrix3fv;
268         GrGLFunction<GrGLUniformMatrix4fvFn> fUniformMatrix4fv;
269         GrGLFunction<GrGLUnmapBufferFn> fUnmapBuffer;
270         GrGLFunction<GrGLUnmapBufferSubDataFn> fUnmapBufferSubData;
271         GrGLFunction<GrGLUnmapTexSubImage2DFn> fUnmapTexSubImage2D;
272         GrGLFunction<GrGLUseProgramFn> fUseProgram;
273         GrGLFunction<GrGLVertexAttrib1fFn> fVertexAttrib1f;
274         GrGLFunction<GrGLVertexAttrib2fvFn> fVertexAttrib2fv;
275         GrGLFunction<GrGLVertexAttrib3fvFn> fVertexAttrib3fv;
276         GrGLFunction<GrGLVertexAttrib4fvFn> fVertexAttrib4fv;
277         GrGLFunction<GrGLVertexAttribDivisorFn> fVertexAttribDivisor;
278         GrGLFunction<GrGLVertexAttribIPointerFn> fVertexAttribIPointer;
279         GrGLFunction<GrGLVertexAttribPointerFn> fVertexAttribPointer;
280         GrGLFunction<GrGLViewportFn> fViewport;
281 
282         /* GL_NV_path_rendering */
283         GrGLFunction<GrGLMatrixLoadfFn> fMatrixLoadf;
284         GrGLFunction<GrGLMatrixLoadIdentityFn> fMatrixLoadIdentity;
285         GrGLFunction<GrGLGetProgramResourceLocationFn> fGetProgramResourceLocation;
286         GrGLFunction<GrGLPathCommandsFn> fPathCommands;
287         GrGLFunction<GrGLPathParameteriFn> fPathParameteri;
288         GrGLFunction<GrGLPathParameterfFn> fPathParameterf;
289         GrGLFunction<GrGLGenPathsFn> fGenPaths;
290         GrGLFunction<GrGLDeletePathsFn> fDeletePaths;
291         GrGLFunction<GrGLIsPathFn> fIsPath;
292         GrGLFunction<GrGLPathStencilFuncFn> fPathStencilFunc;
293         GrGLFunction<GrGLStencilFillPathFn> fStencilFillPath;
294         GrGLFunction<GrGLStencilStrokePathFn> fStencilStrokePath;
295         GrGLFunction<GrGLStencilFillPathInstancedFn> fStencilFillPathInstanced;
296         GrGLFunction<GrGLStencilStrokePathInstancedFn> fStencilStrokePathInstanced;
297         GrGLFunction<GrGLCoverFillPathFn> fCoverFillPath;
298         GrGLFunction<GrGLCoverStrokePathFn> fCoverStrokePath;
299         GrGLFunction<GrGLCoverFillPathInstancedFn> fCoverFillPathInstanced;
300         GrGLFunction<GrGLCoverStrokePathInstancedFn> fCoverStrokePathInstanced;
301         // NV_path_rendering v1.2
302         GrGLFunction<GrGLStencilThenCoverFillPathFn> fStencilThenCoverFillPath;
303         GrGLFunction<GrGLStencilThenCoverStrokePathFn> fStencilThenCoverStrokePath;
304         GrGLFunction<GrGLStencilThenCoverFillPathInstancedFn> fStencilThenCoverFillPathInstanced;
305         GrGLFunction<GrGLStencilThenCoverStrokePathInstancedFn> fStencilThenCoverStrokePathInstanced;
306         // NV_path_rendering v1.3
307         GrGLFunction<GrGLProgramPathFragmentInputGenFn> fProgramPathFragmentInputGen;
308         // CHROMIUM_path_rendering
309         GrGLFunction<GrGLBindFragmentInputLocationFn> fBindFragmentInputLocation;
310 
311         /* NV_framebuffer_mixed_samples */
312         GrGLFunction<GrGLCoverageModulationFn> fCoverageModulation;
313 
314         /* ARB_sync */
315         GrGLFunction<GrGLFenceSyncFn> fFenceSync;
316         GrGLFunction<GrGLIsSyncFn> fIsSync;
317         GrGLFunction<GrGLClientWaitSyncFn> fClientWaitSync;
318         GrGLFunction<GrGLWaitSyncFn> fWaitSync;
319         GrGLFunction<GrGLDeleteSyncFn> fDeleteSync;
320 
321         /* ARB_internalforamt_query */
322         GrGLFunction<GrGLGetInternalformativFn> fGetInternalformativ;
323 
324         /* KHR_debug */
325         GrGLFunction<GrGLDebugMessageControlFn> fDebugMessageControl;
326         GrGLFunction<GrGLDebugMessageInsertFn> fDebugMessageInsert;
327         GrGLFunction<GrGLDebugMessageCallbackFn> fDebugMessageCallback;
328         GrGLFunction<GrGLGetDebugMessageLogFn> fGetDebugMessageLog;
329         GrGLFunction<GrGLPushDebugGroupFn> fPushDebugGroup;
330         GrGLFunction<GrGLPopDebugGroupFn> fPopDebugGroup;
331         GrGLFunction<GrGLObjectLabelFn> fObjectLabel;
332 
333         /* EXT_window_rectangles */
334         GrGLFunction<GrGLWindowRectanglesFn> fWindowRectangles;
335 
336         /* GL_QCOM_tiled_rendering */
337         GrGLFunction<GrGLStartTilingFn> fStartTiling;
338         GrGLFunction<GrGLEndTilingFn> fEndTiling;
339     } fFunctions;
340 
341 #if GR_TEST_UTILS
342     // This exists for internal testing.
343     virtual void abandon() const;
344 #endif
345 };
346 
347 #endif
348