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