• 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<GrGLDeleteFramebuffersFn> fDeleteFramebuffers;
110         GrGLFunction<GrGLDeleteProgramFn> fDeleteProgram;
111         GrGLFunction<GrGLDeleteQueriesFn> fDeleteQueries;
112         GrGLFunction<GrGLDeleteRenderbuffersFn> fDeleteRenderbuffers;
113         GrGLFunction<GrGLDeleteSamplersFn> fDeleteSamplers;
114         GrGLFunction<GrGLDeleteShaderFn> fDeleteShader;
115         GrGLFunction<GrGLDeleteTexturesFn> fDeleteTextures;
116         GrGLFunction<GrGLDeleteVertexArraysFn> fDeleteVertexArrays;
117         GrGLFunction<GrGLDepthMaskFn> fDepthMask;
118         GrGLFunction<GrGLDisableFn> fDisable;
119         GrGLFunction<GrGLDisableVertexAttribArrayFn> fDisableVertexAttribArray;
120         GrGLFunction<GrGLDrawArraysFn> fDrawArrays;
121         GrGLFunction<GrGLDrawArraysIndirectFn> fDrawArraysIndirect;
122         GrGLFunction<GrGLDrawArraysInstancedFn> fDrawArraysInstanced;
123         GrGLFunction<GrGLDrawBufferFn> fDrawBuffer;
124         GrGLFunction<GrGLDrawBuffersFn> fDrawBuffers;
125         GrGLFunction<GrGLDrawElementsFn> fDrawElements;
126         GrGLFunction<GrGLDrawElementsIndirectFn> fDrawElementsIndirect;
127         GrGLFunction<GrGLDrawElementsInstancedFn> fDrawElementsInstanced;
128         GrGLFunction<GrGLDrawRangeElementsFn> fDrawRangeElements;
129         GrGLFunction<GrGLEnableFn> fEnable;
130         GrGLFunction<GrGLEnableVertexAttribArrayFn> fEnableVertexAttribArray;
131         GrGLFunction<GrGLEndQueryFn> fEndQuery;
132         GrGLFunction<GrGLFinishFn> fFinish;
133         GrGLFunction<GrGLFlushFn> fFlush;
134         GrGLFunction<GrGLFlushMappedBufferRangeFn> fFlushMappedBufferRange;
135         GrGLFunction<GrGLFramebufferRenderbufferFn> fFramebufferRenderbuffer;
136         GrGLFunction<GrGLFramebufferTexture2DFn> fFramebufferTexture2D;
137         GrGLFunction<GrGLFramebufferTexture2DMultisampleFn> fFramebufferTexture2DMultisample;
138         GrGLFunction<GrGLFrontFaceFn> fFrontFace;
139         GrGLFunction<GrGLGenBuffersFn> fGenBuffers;
140         GrGLFunction<GrGLGenFramebuffersFn> fGenFramebuffers;
141         GrGLFunction<GrGLGenerateMipmapFn> fGenerateMipmap;
142         GrGLFunction<GrGLGenQueriesFn> fGenQueries;
143         GrGLFunction<GrGLGenRenderbuffersFn> fGenRenderbuffers;
144         GrGLFunction<GrGLGenSamplersFn> fGenSamplers;
145         GrGLFunction<GrGLGenTexturesFn> fGenTextures;
146         GrGLFunction<GrGLGenVertexArraysFn> fGenVertexArrays;
147         GrGLFunction<GrGLGetBufferParameterivFn> fGetBufferParameteriv;
148         GrGLFunction<GrGLGetErrorFn> fGetError;
149         GrGLFunction<GrGLGetFramebufferAttachmentParameterivFn> fGetFramebufferAttachmentParameteriv;
150         GrGLFunction<GrGLGetIntegervFn> fGetIntegerv;
151         GrGLFunction<GrGLGetMultisamplefvFn> fGetMultisamplefv;
152         GrGLFunction<GrGLGetProgramBinaryFn> fGetProgramBinary;
153         GrGLFunction<GrGLGetProgramInfoLogFn> fGetProgramInfoLog;
154         GrGLFunction<GrGLGetProgramivFn> fGetProgramiv;
155         GrGLFunction<GrGLGetQueryObjecti64vFn> fGetQueryObjecti64v;
156         GrGLFunction<GrGLGetQueryObjectivFn> fGetQueryObjectiv;
157         GrGLFunction<GrGLGetQueryObjectui64vFn> fGetQueryObjectui64v;
158         GrGLFunction<GrGLGetQueryObjectuivFn> fGetQueryObjectuiv;
159         GrGLFunction<GrGLGetQueryivFn> fGetQueryiv;
160         GrGLFunction<GrGLGetRenderbufferParameterivFn> fGetRenderbufferParameteriv;
161         GrGLFunction<GrGLGetShaderInfoLogFn> fGetShaderInfoLog;
162         GrGLFunction<GrGLGetShaderivFn> fGetShaderiv;
163         GrGLFunction<GrGLGetShaderPrecisionFormatFn> fGetShaderPrecisionFormat;
164         GrGLFunction<GrGLGetStringFn> fGetString;
165         GrGLFunction<GrGLGetStringiFn> fGetStringi;
166         GrGLFunction<GrGLGetTexLevelParameterivFn> fGetTexLevelParameteriv;
167         GrGLFunction<GrGLGetUniformLocationFn> fGetUniformLocation;
168         GrGLFunction<GrGLInsertEventMarkerFn> fInsertEventMarker;
169         GrGLFunction<GrGLInvalidateBufferDataFn> fInvalidateBufferData;
170         GrGLFunction<GrGLInvalidateBufferSubDataFn> fInvalidateBufferSubData;
171         GrGLFunction<GrGLInvalidateFramebufferFn> fInvalidateFramebuffer;
172         GrGLFunction<GrGLInvalidateSubFramebufferFn> fInvalidateSubFramebuffer;
173         GrGLFunction<GrGLInvalidateTexImageFn> fInvalidateTexImage;
174         GrGLFunction<GrGLInvalidateTexSubImageFn> fInvalidateTexSubImage;
175         GrGLFunction<GrGLIsTextureFn> fIsTexture;
176         GrGLFunction<GrGLLineWidthFn> fLineWidth;
177         GrGLFunction<GrGLLinkProgramFn> fLinkProgram;
178         GrGLFunction<GrGLProgramBinaryFn> fProgramBinary;
179         GrGLFunction<GrGLProgramParameteriFn> fProgramParameteri;
180         GrGLFunction<GrGLMapBufferFn> fMapBuffer;
181         GrGLFunction<GrGLMapBufferRangeFn> fMapBufferRange;
182         GrGLFunction<GrGLMapBufferSubDataFn> fMapBufferSubData;
183         GrGLFunction<GrGLMapTexSubImage2DFn> fMapTexSubImage2D;
184         GrGLFunction<GrGLMultiDrawArraysIndirectFn> fMultiDrawArraysIndirect;
185         GrGLFunction<GrGLMultiDrawElementsIndirectFn> fMultiDrawElementsIndirect;
186         GrGLFunction<GrGLPixelStoreiFn> fPixelStorei;
187         GrGLFunction<GrGLPolygonModeFn> fPolygonMode;
188         GrGLFunction<GrGLPopGroupMarkerFn> fPopGroupMarker;
189         GrGLFunction<GrGLPushGroupMarkerFn> fPushGroupMarker;
190         GrGLFunction<GrGLQueryCounterFn> fQueryCounter;
191         GrGLFunction<GrGLReadBufferFn> fReadBuffer;
192         GrGLFunction<GrGLReadPixelsFn> fReadPixels;
193         GrGLFunction<GrGLRenderbufferStorageFn> fRenderbufferStorage;
194 
195         //  On OpenGL ES there are multiple incompatible extensions that add support for MSAA
196         //  and ES3 adds MSAA support to the standard. On an ES3 driver we may still use the
197         //  older extensions for performance reasons or due to ES3 driver bugs. We want the function
198         //  that creates the GrGLInterface to provide all available functions and internally
199         //  we will select among them. They all have a method called glRenderbufferStorageMultisample*.
200         //  So we have separate function pointers for GL_IMG/EXT_multisampled_to_texture,
201         //  GL_CHROMIUM/ANGLE_framebuffer_multisample/ES3, and GL_APPLE_framebuffer_multisample
202         //  variations.
203         //
204         //  If a driver supports multiple GL_ARB_framebuffer_multisample-style extensions then we will
205         //  assume the function pointers for the standard (or equivalent GL_ARB) version have
206         //  been preferred over GL_EXT, GL_CHROMIUM, or GL_ANGLE variations that have reduced
207         //  functionality.
208 
209         //  GL_EXT_multisampled_render_to_texture (preferred) or GL_IMG_multisampled_render_to_texture
210         GrGLFunction<GrGLRenderbufferStorageMultisampleFn> fRenderbufferStorageMultisampleES2EXT;
211         //  GL_APPLE_framebuffer_multisample
212         GrGLFunction<GrGLRenderbufferStorageMultisampleFn> fRenderbufferStorageMultisampleES2APPLE;
213 
214         //  This is used to store the pointer for GL_ARB/EXT/ANGLE/CHROMIUM_framebuffer_multisample or
215         //  the standard function in ES3+ or GL 3.0+.
216         GrGLFunction<GrGLRenderbufferStorageMultisampleFn> fRenderbufferStorageMultisample;
217 
218         // Pointer to BindUniformLocationCHROMIUM from the GL_CHROMIUM_bind_uniform_location extension.
219         GrGLFunction<GrGLBindUniformLocationFn> fBindUniformLocation;
220 
221         GrGLFunction<GrGLResolveMultisampleFramebufferFn> fResolveMultisampleFramebuffer;
222         GrGLFunction<GrGLSamplerParameteriFn> fSamplerParameteri;
223         GrGLFunction<GrGLSamplerParameterivFn> fSamplerParameteriv;
224         GrGLFunction<GrGLScissorFn> fScissor;
225         GrGLFunction<GrGLShaderSourceFn> fShaderSource;
226         GrGLFunction<GrGLStencilFuncFn> fStencilFunc;
227         GrGLFunction<GrGLStencilFuncSeparateFn> fStencilFuncSeparate;
228         GrGLFunction<GrGLStencilMaskFn> fStencilMask;
229         GrGLFunction<GrGLStencilMaskSeparateFn> fStencilMaskSeparate;
230         GrGLFunction<GrGLStencilOpFn> fStencilOp;
231         GrGLFunction<GrGLStencilOpSeparateFn> fStencilOpSeparate;
232         GrGLFunction<GrGLTexBufferFn> fTexBuffer;
233         GrGLFunction<GrGLTexBufferRangeFn> fTexBufferRange;
234         GrGLFunction<GrGLTexImage2DFn> fTexImage2D;
235         GrGLFunction<GrGLTexParameterfFn> fTexParameterf;
236         GrGLFunction<GrGLTexParameterfvFn> fTexParameterfv;
237         GrGLFunction<GrGLTexParameteriFn> fTexParameteri;
238         GrGLFunction<GrGLTexParameterivFn> fTexParameteriv;
239         GrGLFunction<GrGLTexSubImage2DFn> fTexSubImage2D;
240         GrGLFunction<GrGLTexStorage2DFn> fTexStorage2D;
241         GrGLFunction<GrGLTextureBarrierFn> fTextureBarrier;
242         GrGLFunction<GrGLDiscardFramebufferFn> fDiscardFramebuffer;
243         GrGLFunction<GrGLUniform1fFn> fUniform1f;
244         GrGLFunction<GrGLUniform1iFn> fUniform1i;
245         GrGLFunction<GrGLUniform1fvFn> fUniform1fv;
246         GrGLFunction<GrGLUniform1ivFn> fUniform1iv;
247         GrGLFunction<GrGLUniform2fFn> fUniform2f;
248         GrGLFunction<GrGLUniform2iFn> fUniform2i;
249         GrGLFunction<GrGLUniform2fvFn> fUniform2fv;
250         GrGLFunction<GrGLUniform2ivFn> fUniform2iv;
251         GrGLFunction<GrGLUniform3fFn> fUniform3f;
252         GrGLFunction<GrGLUniform3iFn> fUniform3i;
253         GrGLFunction<GrGLUniform3fvFn> fUniform3fv;
254         GrGLFunction<GrGLUniform3ivFn> fUniform3iv;
255         GrGLFunction<GrGLUniform4fFn> fUniform4f;
256         GrGLFunction<GrGLUniform4iFn> fUniform4i;
257         GrGLFunction<GrGLUniform4fvFn> fUniform4fv;
258         GrGLFunction<GrGLUniform4ivFn> fUniform4iv;
259         GrGLFunction<GrGLUniformMatrix2fvFn> fUniformMatrix2fv;
260         GrGLFunction<GrGLUniformMatrix3fvFn> fUniformMatrix3fv;
261         GrGLFunction<GrGLUniformMatrix4fvFn> fUniformMatrix4fv;
262         GrGLFunction<GrGLUnmapBufferFn> fUnmapBuffer;
263         GrGLFunction<GrGLUnmapBufferSubDataFn> fUnmapBufferSubData;
264         GrGLFunction<GrGLUnmapTexSubImage2DFn> fUnmapTexSubImage2D;
265         GrGLFunction<GrGLUseProgramFn> fUseProgram;
266         GrGLFunction<GrGLVertexAttrib1fFn> fVertexAttrib1f;
267         GrGLFunction<GrGLVertexAttrib2fvFn> fVertexAttrib2fv;
268         GrGLFunction<GrGLVertexAttrib3fvFn> fVertexAttrib3fv;
269         GrGLFunction<GrGLVertexAttrib4fvFn> fVertexAttrib4fv;
270         GrGLFunction<GrGLVertexAttribDivisorFn> fVertexAttribDivisor;
271         GrGLFunction<GrGLVertexAttribIPointerFn> fVertexAttribIPointer;
272         GrGLFunction<GrGLVertexAttribPointerFn> fVertexAttribPointer;
273         GrGLFunction<GrGLViewportFn> fViewport;
274 
275         /* GL_NV_path_rendering */
276         GrGLFunction<GrGLMatrixLoadfFn> fMatrixLoadf;
277         GrGLFunction<GrGLMatrixLoadIdentityFn> fMatrixLoadIdentity;
278         GrGLFunction<GrGLGetProgramResourceLocationFn> fGetProgramResourceLocation;
279         GrGLFunction<GrGLPathCommandsFn> fPathCommands;
280         GrGLFunction<GrGLPathParameteriFn> fPathParameteri;
281         GrGLFunction<GrGLPathParameterfFn> fPathParameterf;
282         GrGLFunction<GrGLGenPathsFn> fGenPaths;
283         GrGLFunction<GrGLDeletePathsFn> fDeletePaths;
284         GrGLFunction<GrGLIsPathFn> fIsPath;
285         GrGLFunction<GrGLPathStencilFuncFn> fPathStencilFunc;
286         GrGLFunction<GrGLStencilFillPathFn> fStencilFillPath;
287         GrGLFunction<GrGLStencilStrokePathFn> fStencilStrokePath;
288         GrGLFunction<GrGLStencilFillPathInstancedFn> fStencilFillPathInstanced;
289         GrGLFunction<GrGLStencilStrokePathInstancedFn> fStencilStrokePathInstanced;
290         GrGLFunction<GrGLCoverFillPathFn> fCoverFillPath;
291         GrGLFunction<GrGLCoverStrokePathFn> fCoverStrokePath;
292         GrGLFunction<GrGLCoverFillPathInstancedFn> fCoverFillPathInstanced;
293         GrGLFunction<GrGLCoverStrokePathInstancedFn> fCoverStrokePathInstanced;
294         // NV_path_rendering v1.2
295         GrGLFunction<GrGLStencilThenCoverFillPathFn> fStencilThenCoverFillPath;
296         GrGLFunction<GrGLStencilThenCoverStrokePathFn> fStencilThenCoverStrokePath;
297         GrGLFunction<GrGLStencilThenCoverFillPathInstancedFn> fStencilThenCoverFillPathInstanced;
298         GrGLFunction<GrGLStencilThenCoverStrokePathInstancedFn> fStencilThenCoverStrokePathInstanced;
299         // NV_path_rendering v1.3
300         GrGLFunction<GrGLProgramPathFragmentInputGenFn> fProgramPathFragmentInputGen;
301         // CHROMIUM_path_rendering
302         GrGLFunction<GrGLBindFragmentInputLocationFn> fBindFragmentInputLocation;
303 
304         /* NV_framebuffer_mixed_samples */
305         GrGLFunction<GrGLCoverageModulationFn> fCoverageModulation;
306 
307         /* ARB_sync */
308         GrGLFunction<GrGLFenceSyncFn> fFenceSync;
309         GrGLFunction<GrGLIsSyncFn> fIsSync;
310         GrGLFunction<GrGLClientWaitSyncFn> fClientWaitSync;
311         GrGLFunction<GrGLWaitSyncFn> fWaitSync;
312         GrGLFunction<GrGLDeleteSyncFn> fDeleteSync;
313 
314         /* ARB_internalforamt_query */
315         GrGLFunction<GrGLGetInternalformativFn> fGetInternalformativ;
316 
317         /* KHR_debug */
318         GrGLFunction<GrGLDebugMessageControlFn> fDebugMessageControl;
319         GrGLFunction<GrGLDebugMessageInsertFn> fDebugMessageInsert;
320         GrGLFunction<GrGLDebugMessageCallbackFn> fDebugMessageCallback;
321         GrGLFunction<GrGLGetDebugMessageLogFn> fGetDebugMessageLog;
322         GrGLFunction<GrGLPushDebugGroupFn> fPushDebugGroup;
323         GrGLFunction<GrGLPopDebugGroupFn> fPopDebugGroup;
324         GrGLFunction<GrGLObjectLabelFn> fObjectLabel;
325 
326         /* EXT_window_rectangles */
327         GrGLFunction<GrGLWindowRectanglesFn> fWindowRectangles;
328     } fFunctions;
329 
330 #if GR_TEST_UTILS
331     // This exists for internal testing.
332     virtual void abandon() const;
333 #endif
334 };
335 
336 #endif
337