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<GrGLDrawArraysInstancedBaseInstanceFn> fDrawArraysInstancedBaseInstance; 189 GrGLFunction<GrGLDrawElementsInstancedBaseVertexBaseInstanceFn> fDrawElementsInstancedBaseVertexBaseInstance; 190 GrGLFunction<GrGLMultiDrawArraysIndirectFn> fMultiDrawArraysIndirect; 191 GrGLFunction<GrGLMultiDrawElementsIndirectFn> fMultiDrawElementsIndirect; 192 GrGLFunction<GrGLPatchParameteriFn> fPatchParameteri; 193 GrGLFunction<GrGLPixelStoreiFn> fPixelStorei; 194 GrGLFunction<GrGLPolygonModeFn> fPolygonMode; 195 GrGLFunction<GrGLPopGroupMarkerFn> fPopGroupMarker; 196 GrGLFunction<GrGLPushGroupMarkerFn> fPushGroupMarker; 197 GrGLFunction<GrGLQueryCounterFn> fQueryCounter; 198 GrGLFunction<GrGLReadBufferFn> fReadBuffer; 199 GrGLFunction<GrGLReadPixelsFn> fReadPixels; 200 GrGLFunction<GrGLRenderbufferStorageFn> fRenderbufferStorage; 201 202 // On OpenGL ES there are multiple incompatible extensions that add support for MSAA 203 // and ES3 adds MSAA support to the standard. On an ES3 driver we may still use the 204 // older extensions for performance reasons or due to ES3 driver bugs. We want the function 205 // that creates the GrGLInterface to provide all available functions and internally 206 // we will select among them. They all have a method called glRenderbufferStorageMultisample*. 207 // So we have separate function pointers for GL_IMG/EXT_multisampled_to_texture, 208 // GL_CHROMIUM/ANGLE_framebuffer_multisample/ES3, and GL_APPLE_framebuffer_multisample 209 // variations. 210 // 211 // If a driver supports multiple GL_ARB_framebuffer_multisample-style extensions then we will 212 // assume the function pointers for the standard (or equivalent GL_ARB) version have 213 // been preferred over GL_EXT, GL_CHROMIUM, or GL_ANGLE variations that have reduced 214 // functionality. 215 216 // GL_EXT_multisampled_render_to_texture (preferred) or GL_IMG_multisampled_render_to_texture 217 GrGLFunction<GrGLRenderbufferStorageMultisampleFn> fRenderbufferStorageMultisampleES2EXT; 218 // GL_APPLE_framebuffer_multisample 219 GrGLFunction<GrGLRenderbufferStorageMultisampleFn> fRenderbufferStorageMultisampleES2APPLE; 220 221 // This is used to store the pointer for GL_ARB/EXT/ANGLE/CHROMIUM_framebuffer_multisample or 222 // the standard function in ES3+ or GL 3.0+. 223 GrGLFunction<GrGLRenderbufferStorageMultisampleFn> fRenderbufferStorageMultisample; 224 225 // Pointer to BindUniformLocationCHROMIUM from the GL_CHROMIUM_bind_uniform_location extension. 226 GrGLFunction<GrGLBindUniformLocationFn> fBindUniformLocation; 227 228 GrGLFunction<GrGLResolveMultisampleFramebufferFn> fResolveMultisampleFramebuffer; 229 GrGLFunction<GrGLSamplerParameteriFn> fSamplerParameteri; 230 GrGLFunction<GrGLSamplerParameterivFn> fSamplerParameteriv; 231 GrGLFunction<GrGLScissorFn> fScissor; 232 GrGLFunction<GrGLSetFenceFn> fSetFence; 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<GrGLTestFenceFn> fTestFence; 241 GrGLFunction<GrGLTexBufferFn> fTexBuffer; 242 GrGLFunction<GrGLTexBufferRangeFn> fTexBufferRange; 243 GrGLFunction<GrGLTexImage2DFn> fTexImage2D; 244 GrGLFunction<GrGLTexParameterfFn> fTexParameterf; 245 GrGLFunction<GrGLTexParameterfvFn> fTexParameterfv; 246 GrGLFunction<GrGLTexParameteriFn> fTexParameteri; 247 GrGLFunction<GrGLTexParameterivFn> fTexParameteriv; 248 GrGLFunction<GrGLTexSubImage2DFn> fTexSubImage2D; 249 GrGLFunction<GrGLTexStorage2DFn> fTexStorage2D; 250 GrGLFunction<GrGLTextureBarrierFn> fTextureBarrier; 251 GrGLFunction<GrGLDiscardFramebufferFn> fDiscardFramebuffer; 252 GrGLFunction<GrGLUniform1fFn> fUniform1f; 253 GrGLFunction<GrGLUniform1iFn> fUniform1i; 254 GrGLFunction<GrGLUniform1fvFn> fUniform1fv; 255 GrGLFunction<GrGLUniform1ivFn> fUniform1iv; 256 GrGLFunction<GrGLUniform2fFn> fUniform2f; 257 GrGLFunction<GrGLUniform2iFn> fUniform2i; 258 GrGLFunction<GrGLUniform2fvFn> fUniform2fv; 259 GrGLFunction<GrGLUniform2ivFn> fUniform2iv; 260 GrGLFunction<GrGLUniform3fFn> fUniform3f; 261 GrGLFunction<GrGLUniform3iFn> fUniform3i; 262 GrGLFunction<GrGLUniform3fvFn> fUniform3fv; 263 GrGLFunction<GrGLUniform3ivFn> fUniform3iv; 264 GrGLFunction<GrGLUniform4fFn> fUniform4f; 265 GrGLFunction<GrGLUniform4iFn> fUniform4i; 266 GrGLFunction<GrGLUniform4fvFn> fUniform4fv; 267 GrGLFunction<GrGLUniform4ivFn> fUniform4iv; 268 GrGLFunction<GrGLUniformMatrix2fvFn> fUniformMatrix2fv; 269 GrGLFunction<GrGLUniformMatrix3fvFn> fUniformMatrix3fv; 270 GrGLFunction<GrGLUniformMatrix4fvFn> fUniformMatrix4fv; 271 GrGLFunction<GrGLUnmapBufferFn> fUnmapBuffer; 272 GrGLFunction<GrGLUnmapBufferSubDataFn> fUnmapBufferSubData; 273 GrGLFunction<GrGLUnmapTexSubImage2DFn> fUnmapTexSubImage2D; 274 GrGLFunction<GrGLUseProgramFn> fUseProgram; 275 GrGLFunction<GrGLVertexAttrib1fFn> fVertexAttrib1f; 276 GrGLFunction<GrGLVertexAttrib2fvFn> fVertexAttrib2fv; 277 GrGLFunction<GrGLVertexAttrib3fvFn> fVertexAttrib3fv; 278 GrGLFunction<GrGLVertexAttrib4fvFn> fVertexAttrib4fv; 279 GrGLFunction<GrGLVertexAttribDivisorFn> fVertexAttribDivisor; 280 GrGLFunction<GrGLVertexAttribIPointerFn> fVertexAttribIPointer; 281 GrGLFunction<GrGLVertexAttribPointerFn> fVertexAttribPointer; 282 GrGLFunction<GrGLViewportFn> fViewport; 283 284 /* GL_NV_path_rendering */ 285 GrGLFunction<GrGLMatrixLoadfFn> fMatrixLoadf; 286 GrGLFunction<GrGLMatrixLoadIdentityFn> fMatrixLoadIdentity; 287 GrGLFunction<GrGLGetProgramResourceLocationFn> fGetProgramResourceLocation; 288 GrGLFunction<GrGLPathCommandsFn> fPathCommands; 289 GrGLFunction<GrGLPathParameteriFn> fPathParameteri; 290 GrGLFunction<GrGLPathParameterfFn> fPathParameterf; 291 GrGLFunction<GrGLGenPathsFn> fGenPaths; 292 GrGLFunction<GrGLDeletePathsFn> fDeletePaths; 293 GrGLFunction<GrGLIsPathFn> fIsPath; 294 GrGLFunction<GrGLPathStencilFuncFn> fPathStencilFunc; 295 GrGLFunction<GrGLStencilFillPathFn> fStencilFillPath; 296 GrGLFunction<GrGLStencilStrokePathFn> fStencilStrokePath; 297 GrGLFunction<GrGLStencilFillPathInstancedFn> fStencilFillPathInstanced; 298 GrGLFunction<GrGLStencilStrokePathInstancedFn> fStencilStrokePathInstanced; 299 GrGLFunction<GrGLCoverFillPathFn> fCoverFillPath; 300 GrGLFunction<GrGLCoverStrokePathFn> fCoverStrokePath; 301 GrGLFunction<GrGLCoverFillPathInstancedFn> fCoverFillPathInstanced; 302 GrGLFunction<GrGLCoverStrokePathInstancedFn> fCoverStrokePathInstanced; 303 // NV_path_rendering v1.2 304 GrGLFunction<GrGLStencilThenCoverFillPathFn> fStencilThenCoverFillPath; 305 GrGLFunction<GrGLStencilThenCoverStrokePathFn> fStencilThenCoverStrokePath; 306 GrGLFunction<GrGLStencilThenCoverFillPathInstancedFn> fStencilThenCoverFillPathInstanced; 307 GrGLFunction<GrGLStencilThenCoverStrokePathInstancedFn> fStencilThenCoverStrokePathInstanced; 308 // NV_path_rendering v1.3 309 GrGLFunction<GrGLProgramPathFragmentInputGenFn> fProgramPathFragmentInputGen; 310 // CHROMIUM_path_rendering 311 GrGLFunction<GrGLBindFragmentInputLocationFn> fBindFragmentInputLocation; 312 313 /* NV_framebuffer_mixed_samples */ 314 GrGLFunction<GrGLCoverageModulationFn> fCoverageModulation; 315 316 /* ARB_sync */ 317 GrGLFunction<GrGLFenceSyncFn> fFenceSync; 318 GrGLFunction<GrGLIsSyncFn> fIsSync; 319 GrGLFunction<GrGLClientWaitSyncFn> fClientWaitSync; 320 GrGLFunction<GrGLWaitSyncFn> fWaitSync; 321 GrGLFunction<GrGLDeleteSyncFn> fDeleteSync; 322 323 /* ARB_internalforamt_query */ 324 GrGLFunction<GrGLGetInternalformativFn> fGetInternalformativ; 325 326 /* KHR_debug */ 327 GrGLFunction<GrGLDebugMessageControlFn> fDebugMessageControl; 328 GrGLFunction<GrGLDebugMessageInsertFn> fDebugMessageInsert; 329 GrGLFunction<GrGLDebugMessageCallbackFn> fDebugMessageCallback; 330 GrGLFunction<GrGLGetDebugMessageLogFn> fGetDebugMessageLog; 331 GrGLFunction<GrGLPushDebugGroupFn> fPushDebugGroup; 332 GrGLFunction<GrGLPopDebugGroupFn> fPopDebugGroup; 333 GrGLFunction<GrGLObjectLabelFn> fObjectLabel; 334 335 /* EXT_window_rectangles */ 336 GrGLFunction<GrGLWindowRectanglesFn> fWindowRectangles; 337 338 /* GL_QCOM_tiled_rendering */ 339 GrGLFunction<GrGLStartTilingFn> fStartTiling; 340 GrGLFunction<GrGLEndTilingFn> fEndTiling; 341 } fFunctions; 342 343 #if GR_TEST_UTILS 344 // This exists for internal testing. 345 virtual void abandon() const; 346 #endif 347 }; 348 349 #endif 350