/* * Copyright 2011 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #ifndef GrGLInterface_DEFINED #define GrGLInterface_DEFINED #include "GrGLFunctions.h" #include "GrGLExtensions.h" #include "SkRefCnt.h" //////////////////////////////////////////////////////////////////////////////// typedef void(*GrGLFuncPtr)(); struct GrGLInterface; /** * Rather than depend on platform-specific GL headers and libraries, we require * the client to provide a struct of GL function pointers. This struct can be * specified per-GrContext as a parameter to GrContext::MakeGL. If no interface is * passed to MakeGL then a default GL interface is created using GrGLMakeNativeInterface(). * If this returns nullptr then GrContext::MakeGL() will fail. * * The implementation of GrGLMakeNativeInterface is platform-specific. Several * implementations have been provided (for GLX, WGL, EGL, etc), along with an * implementation that simply returns nullptr. Clients should select the most * appropriate one to build. */ SK_API sk_sp GrGLMakeNativeInterface(); // Deprecated alternative to GrGLMakeNativeInterface(). SK_API const GrGLInterface* GrGLCreateNativeInterface(); /** * Creates a null GrGLInterface that doesn't draw anything. Used for measuring * CPU overhead. TODO: We would like to move this to tools/gpu/gl/null but currently * Chromium is using it in its unit tests. */ const SK_API GrGLInterface* GrGLCreateNullInterface(bool enableNVPR = false); /** * GrContext uses the following interface to make all calls into OpenGL. When a * GrContext is created it is given a GrGLInterface. The interface's function * pointers must be valid for the OpenGL context associated with the GrContext. * On some platforms, such as Windows, function pointers for OpenGL extensions * may vary between OpenGL contexts. So the caller must be careful to use a * GrGLInterface initialized for the correct context. All functions that should * be available based on the OpenGL's version and extension string must be * non-NULL or GrContext creation will fail. This can be tested with the * validate() method when the OpenGL context has been made current. */ struct SK_API GrGLInterface : public SkRefCnt { private: typedef SkRefCnt INHERITED; public: GrGLInterface(); // Validates that the GrGLInterface supports its advertised standard. This means the necessary // function pointers have been initialized for both the GL version and any advertised // extensions. bool validate() const; // Indicates the type of GL implementation union { GrGLStandard fStandard; GrGLStandard fBindingsExported; // Legacy name, will be remove when Chromium is updated. }; GrGLExtensions fExtensions; bool hasExtension(const char ext[]) const { return fExtensions.has(ext); } /** * The function pointers are in a struct so that we can have a compiler generated assignment * operator. */ struct Functions { GrGLFunction fActiveTexture; GrGLFunction fAttachShader; GrGLFunction fBeginQuery; GrGLFunction fBindAttribLocation; GrGLFunction fBindBuffer; GrGLFunction fBindFragDataLocation; GrGLFunction fBindFragDataLocationIndexed; GrGLFunction fBindFramebuffer; GrGLFunction fBindRenderbuffer; GrGLFunction fBindSampler; GrGLFunction fBindTexture; GrGLFunction fBindVertexArray; GrGLFunction fBlendBarrier; GrGLFunction fBlendColor; GrGLFunction fBlendEquation; GrGLFunction fBlendFunc; GrGLFunction fBlitFramebuffer; GrGLFunction fBufferData; GrGLFunction fBufferSubData; GrGLFunction fCheckFramebufferStatus; GrGLFunction fClear; GrGLFunction fClearColor; GrGLFunction fClearStencil; GrGLFunction fClearTexImage; GrGLFunction fClearTexSubImage; GrGLFunction fColorMask; GrGLFunction fCompileShader; GrGLFunction fCompressedTexImage2D; GrGLFunction fCompressedTexSubImage2D; GrGLFunction fCopyTexSubImage2D; GrGLFunction fCreateProgram; GrGLFunction fCreateShader; GrGLFunction fCullFace; GrGLFunction fDeleteBuffers; GrGLFunction fDeleteFramebuffers; GrGLFunction fDeleteProgram; GrGLFunction fDeleteQueries; GrGLFunction fDeleteRenderbuffers; GrGLFunction fDeleteSamplers; GrGLFunction fDeleteShader; GrGLFunction fDeleteTextures; GrGLFunction fDeleteVertexArrays; GrGLFunction fDepthMask; GrGLFunction fDisable; GrGLFunction fDisableVertexAttribArray; GrGLFunction fDrawArrays; GrGLFunction fDrawArraysIndirect; GrGLFunction fDrawArraysInstanced; GrGLFunction fDrawBuffer; GrGLFunction fDrawBuffers; GrGLFunction fDrawElements; GrGLFunction fDrawElementsIndirect; GrGLFunction fDrawElementsInstanced; GrGLFunction fDrawRangeElements; GrGLFunction fEnable; GrGLFunction fEnableVertexAttribArray; GrGLFunction fEndQuery; GrGLFunction fFinish; GrGLFunction fFlush; GrGLFunction fFlushMappedBufferRange; GrGLFunction fFramebufferRenderbuffer; GrGLFunction fFramebufferTexture2D; GrGLFunction fFramebufferTexture2DMultisample; GrGLFunction fFrontFace; GrGLFunction fGenBuffers; GrGLFunction fGenFramebuffers; GrGLFunction fGenerateMipmap; GrGLFunction fGenQueries; GrGLFunction fGenRenderbuffers; GrGLFunction fGenSamplers; GrGLFunction fGenTextures; GrGLFunction fGenVertexArrays; GrGLFunction fGetBufferParameteriv; GrGLFunction fGetError; GrGLFunction fGetFramebufferAttachmentParameteriv; GrGLFunction fGetIntegerv; GrGLFunction fGetMultisamplefv; GrGLFunction fGetProgramBinary; GrGLFunction fGetProgramInfoLog; GrGLFunction fGetProgramiv; GrGLFunction fGetQueryObjecti64v; GrGLFunction fGetQueryObjectiv; GrGLFunction fGetQueryObjectui64v; GrGLFunction fGetQueryObjectuiv; GrGLFunction fGetQueryiv; GrGLFunction fGetRenderbufferParameteriv; GrGLFunction fGetShaderInfoLog; GrGLFunction fGetShaderiv; GrGLFunction fGetShaderPrecisionFormat; GrGLFunction fGetString; GrGLFunction fGetStringi; GrGLFunction fGetTexLevelParameteriv; GrGLFunction fGetUniformLocation; GrGLFunction fInsertEventMarker; GrGLFunction fInvalidateBufferData; GrGLFunction fInvalidateBufferSubData; GrGLFunction fInvalidateFramebuffer; GrGLFunction fInvalidateSubFramebuffer; GrGLFunction fInvalidateTexImage; GrGLFunction fInvalidateTexSubImage; GrGLFunction fIsTexture; GrGLFunction fLineWidth; GrGLFunction fLinkProgram; GrGLFunction fProgramBinary; GrGLFunction fProgramParameteri; GrGLFunction fMapBuffer; GrGLFunction fMapBufferRange; GrGLFunction fMapBufferSubData; GrGLFunction fMapTexSubImage2D; GrGLFunction fMultiDrawArraysIndirect; GrGLFunction fMultiDrawElementsIndirect; GrGLFunction fPixelStorei; GrGLFunction fPolygonMode; GrGLFunction fPopGroupMarker; GrGLFunction fPushGroupMarker; GrGLFunction fQueryCounter; GrGLFunction fRasterSamples; GrGLFunction fReadBuffer; GrGLFunction fReadPixels; GrGLFunction fRenderbufferStorage; // On OpenGL ES there are multiple incompatible extensions that add support for MSAA // and ES3 adds MSAA support to the standard. On an ES3 driver we may still use the // older extensions for performance reasons or due to ES3 driver bugs. We want the function // that creates the GrGLInterface to provide all available functions and internally // we will select among them. They all have a method called glRenderbufferStorageMultisample*. // So we have separate function pointers for GL_IMG/EXT_multisampled_to_texture, // GL_CHROMIUM/ANGLE_framebuffer_multisample/ES3, and GL_APPLE_framebuffer_multisample // variations. // // If a driver supports multiple GL_ARB_framebuffer_multisample-style extensions then we will // assume the function pointers for the standard (or equivalent GL_ARB) version have // been preferred over GL_EXT, GL_CHROMIUM, or GL_ANGLE variations that have reduced // functionality. // GL_EXT_multisampled_render_to_texture (preferred) or GL_IMG_multisampled_render_to_texture GrGLFunction fRenderbufferStorageMultisampleES2EXT; // GL_APPLE_framebuffer_multisample GrGLFunction fRenderbufferStorageMultisampleES2APPLE; // This is used to store the pointer for GL_ARB/EXT/ANGLE/CHROMIUM_framebuffer_multisample or // the standard function in ES3+ or GL 3.0+. GrGLFunction fRenderbufferStorageMultisample; // Pointer to BindUniformLocationCHROMIUM from the GL_CHROMIUM_bind_uniform_location extension. GrGLFunction fBindUniformLocation; GrGLFunction fResolveMultisampleFramebuffer; GrGLFunction fSamplerParameteri; GrGLFunction fSamplerParameteriv; GrGLFunction fScissor; GrGLFunction fShaderSource; GrGLFunction fStencilFunc; GrGLFunction fStencilFuncSeparate; GrGLFunction fStencilMask; GrGLFunction fStencilMaskSeparate; GrGLFunction fStencilOp; GrGLFunction fStencilOpSeparate; GrGLFunction fTexBuffer; GrGLFunction fTexBufferRange; GrGLFunction fTexImage2D; GrGLFunction fTexParameteri; GrGLFunction fTexParameteriv; GrGLFunction fTexSubImage2D; GrGLFunction fTexStorage2D; GrGLFunction fTextureBarrier; GrGLFunction fDiscardFramebuffer; GrGLFunction fUniform1f; GrGLFunction fUniform1i; GrGLFunction fUniform1fv; GrGLFunction fUniform1iv; GrGLFunction fUniform2f; GrGLFunction fUniform2i; GrGLFunction fUniform2fv; GrGLFunction fUniform2iv; GrGLFunction fUniform3f; GrGLFunction fUniform3i; GrGLFunction fUniform3fv; GrGLFunction fUniform3iv; GrGLFunction fUniform4f; GrGLFunction fUniform4i; GrGLFunction fUniform4fv; GrGLFunction fUniform4iv; GrGLFunction fUniformMatrix2fv; GrGLFunction fUniformMatrix3fv; GrGLFunction fUniformMatrix4fv; GrGLFunction fUnmapBuffer; GrGLFunction fUnmapBufferSubData; GrGLFunction fUnmapTexSubImage2D; GrGLFunction fUseProgram; GrGLFunction fVertexAttrib1f; GrGLFunction fVertexAttrib2fv; GrGLFunction fVertexAttrib3fv; GrGLFunction fVertexAttrib4fv; GrGLFunction fVertexAttribDivisor; GrGLFunction fVertexAttribIPointer; GrGLFunction fVertexAttribPointer; GrGLFunction fViewport; /* GL_NV_path_rendering */ GrGLFunction fMatrixLoadf; GrGLFunction fMatrixLoadIdentity; GrGLFunction fGetProgramResourceLocation; GrGLFunction fPathCommands; GrGLFunction fPathParameteri; GrGLFunction fPathParameterf; GrGLFunction fGenPaths; GrGLFunction fDeletePaths; GrGLFunction fIsPath; GrGLFunction fPathStencilFunc; GrGLFunction fStencilFillPath; GrGLFunction fStencilStrokePath; GrGLFunction fStencilFillPathInstanced; GrGLFunction fStencilStrokePathInstanced; GrGLFunction fCoverFillPath; GrGLFunction fCoverStrokePath; GrGLFunction fCoverFillPathInstanced; GrGLFunction fCoverStrokePathInstanced; // NV_path_rendering v1.2 GrGLFunction fStencilThenCoverFillPath; GrGLFunction fStencilThenCoverStrokePath; GrGLFunction fStencilThenCoverFillPathInstanced; GrGLFunction fStencilThenCoverStrokePathInstanced; // NV_path_rendering v1.3 GrGLFunction fProgramPathFragmentInputGen; // CHROMIUM_path_rendering GrGLFunction fBindFragmentInputLocation; /* NV_framebuffer_mixed_samples */ GrGLFunction fCoverageModulation; /* ARB_sample_shading */ GrGLFunction fMinSampleShading; /* ARB_sync */ GrGLFunction fFenceSync; GrGLFunction fIsSync; GrGLFunction fClientWaitSync; GrGLFunction fWaitSync; GrGLFunction fDeleteSync; /* ARB_internalforamt_query */ GrGLFunction fGetInternalformativ; /* KHR_debug */ GrGLFunction fDebugMessageControl; GrGLFunction fDebugMessageInsert; GrGLFunction fDebugMessageCallback; GrGLFunction fGetDebugMessageLog; GrGLFunction fPushDebugGroup; GrGLFunction fPopDebugGroup; GrGLFunction fObjectLabel; /* EXT_window_rectangles */ GrGLFunction fWindowRectangles; /* EGL functions */ GrGLFunction fEGLCreateImage; GrGLFunction fEGLDestroyImage; } fFunctions; #if GR_TEST_UTILS // This exists for internal testing. virtual void abandon() const; #endif }; #endif