Debian Codegraph @

include/gpu/ganesh/gl/GrGLInterface.h

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