/* * 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" //////////////////////////////////////////////////////////////////////////////// /** * 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::Create. If NULL is * passed to Create then a "default" GL interface is created. If the default is * also NULL GrContext creation will fail. * * The default interface is returned by GrGLDefaultInterface. This function's * implementation is platform-specific. Several have been provided, along with * an implementation that simply returns NULL. * * By defining GR_GL_PER_GL_CALL_IFACE_CALLBACK to 1 the client can specify a * callback function that will be called prior to each GL function call. See * comments in GrGLConfig.h */ typedef void(*GrGLFuncPtr)(); struct GrGLInterface; const GrGLInterface* GrGLDefaultInterface(); /** * Creates a GrGLInterface for a "native" GL context (e.g. WGL on windows, * GLX on linux, AGL on Mac). The interface is only valid for the GL context * that is current when the interface is created. */ SK_API const GrGLInterface* GrGLCreateNativeInterface(); #if GR_GL_PER_GL_FUNC_CALLBACK typedef void (*GrGLInterfaceCallbackProc)(const GrGLInterface*); typedef intptr_t GrGLInterfaceCallbackData; #endif /** * 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); /** Function that returns a new interface identical to "interface" but without support for GL_NV_path_rendering. */ const GrGLInterface* GrGLInterfaceRemoveNVPR(const GrGLInterface*); /** Function that returns a new interface identical to "interface" but with support for test version of GL_EXT_debug_marker. */ const GrGLInterface* GrGLInterfaceAddTestDebugMarker(const GrGLInterface*, GrGLInsertEventMarkerProc insertEventMarkerFn, GrGLPushGroupMarkerProc pushGroupMarkerFn, GrGLPopGroupMarkerProc popGroupMarkerFn); /** * 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(); static GrGLInterface* NewClone(const 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 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 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 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 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 fGenTextures; GrGLFunction fGenVertexArrays; GrGLFunction fGetBufferParameteriv; GrGLFunction fGetError; GrGLFunction fGetFramebufferAttachmentParameteriv; GrGLFunction fGetIntegerv; GrGLFunction fGetMultisamplefv; GrGLFunction fGetQueryObjecti64v; GrGLFunction fGetQueryObjectiv; GrGLFunction fGetQueryObjectui64v; GrGLFunction fGetQueryObjectuiv; GrGLFunction fGetQueryiv; GrGLFunction fGetProgramInfoLog; GrGLFunction fGetProgramiv; 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 fMapBuffer; GrGLFunction fMapBufferRange; GrGLFunction fMapBufferSubData; GrGLFunction fMapTexSubImage2D; GrGLFunction fPixelStorei; 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 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; /* EXT_multi_draw_indirect */ GrGLFunction fMultiDrawArraysIndirect; GrGLFunction fMultiDrawElementsIndirect; /* NV_bindless_texture */ // We use the NVIDIA verson for now because it does not require dynamically uniform handles. // We may switch the the ARB version and/or omit methods in the future. GrGLFunction fGetTextureHandle; GrGLFunction fGetTextureSamplerHandle; GrGLFunction fMakeTextureHandleResident; GrGLFunction fMakeTextureHandleNonResident; GrGLFunction fGetImageHandle; GrGLFunction fMakeImageHandleResident; GrGLFunction fMakeImageHandleNonResident; GrGLFunction fIsTextureHandleResident; GrGLFunction fIsImageHandleResident; GrGLFunction fUniformHandleui64; GrGLFunction fUniformHandleui64v; GrGLFunction fProgramUniformHandleui64; GrGLFunction fProgramUniformHandleui64v; /* ARB_sample_shading */ GrGLFunction fMinSampleShading; /* EXT_direct_state_access */ // We use the EXT verson because it is more expansive and interacts with more extensions // than the ARB or core (4.5) versions. We may switch and/or omit methods in the future. GrGLFunction fTextureParameteri; GrGLFunction fTextureParameteriv; GrGLFunction fTextureParameterf; GrGLFunction fTextureParameterfv; GrGLFunction fTextureImage1D; GrGLFunction fTextureImage2D; GrGLFunction fTextureSubImage1D; GrGLFunction fTextureSubImage2D; GrGLFunction fCopyTextureImage1D; GrGLFunction fCopyTextureImage2D; GrGLFunction fCopyTextureSubImage1D; GrGLFunction fCopyTextureSubImage2D; GrGLFunction fGetTextureImage; GrGLFunction fGetTextureParameterfv; GrGLFunction fGetTextureParameteriv; GrGLFunction fGetTextureLevelParameterfv; GrGLFunction fGetTextureLevelParameteriv; // OpenGL 1.2 GrGLFunction fTextureImage3D; GrGLFunction fTextureSubImage3D; GrGLFunction fCopyTextureSubImage3D; GrGLFunction fCompressedTextureImage3D; GrGLFunction fCompressedTextureImage2D; GrGLFunction fCompressedTextureImage1D; GrGLFunction fCompressedTextureSubImage3D; GrGLFunction fCompressedTextureSubImage2D; GrGLFunction fCompressedTextureSubImage1D; GrGLFunction fGetCompressedTextureImage; // OpenGL 1.5 GrGLFunction fNamedBufferData; GrGLFunction fNamedBufferSubData; GrGLFunction fMapNamedBuffer; GrGLFunction fUnmapNamedBuffer; GrGLFunction fGetNamedBufferParameteriv; GrGLFunction fGetNamedBufferPointerv; GrGLFunction fGetNamedBufferSubData; // OpenGL 2.0 GrGLFunction fProgramUniform1f; GrGLFunction fProgramUniform2f; GrGLFunction fProgramUniform3f; GrGLFunction fProgramUniform4f; GrGLFunction fProgramUniform1i; GrGLFunction fProgramUniform2i; GrGLFunction fProgramUniform3i; GrGLFunction fProgramUniform4i; GrGLFunction fProgramUniform1fv; GrGLFunction fProgramUniform2fv; GrGLFunction fProgramUniform3fv; GrGLFunction fProgramUniform4fv; GrGLFunction fProgramUniform1iv; GrGLFunction fProgramUniform2iv; GrGLFunction fProgramUniform3iv; GrGLFunction fProgramUniform4iv; GrGLFunction fProgramUniformMatrix2fv; GrGLFunction fProgramUniformMatrix3fv; GrGLFunction fProgramUniformMatrix4fv; // OpenGL 2.1 GrGLFunction fProgramUniformMatrix2x3fv; GrGLFunction fProgramUniformMatrix3x2fv; GrGLFunction fProgramUniformMatrix2x4fv; GrGLFunction fProgramUniformMatrix4x2fv; GrGLFunction fProgramUniformMatrix3x4fv; GrGLFunction fProgramUniformMatrix4x3fv; // OpenGL 3.0 GrGLFunction fNamedRenderbufferStorage; GrGLFunction fGetNamedRenderbufferParameteriv; GrGLFunction fNamedRenderbufferStorageMultisample; GrGLFunction fCheckNamedFramebufferStatus; GrGLFunction fNamedFramebufferTexture1D; GrGLFunction fNamedFramebufferTexture2D; GrGLFunction fNamedFramebufferTexture3D; GrGLFunction fNamedFramebufferRenderbuffer; GrGLFunction fGetNamedFramebufferAttachmentParameteriv; GrGLFunction fGenerateTextureMipmap; GrGLFunction fFramebufferDrawBuffer; GrGLFunction fFramebufferDrawBuffers; GrGLFunction fFramebufferReadBuffer; GrGLFunction fGetFramebufferParameteriv; GrGLFunction fNamedCopyBufferSubData; GrGLFunction fVertexArrayVertexOffset; GrGLFunction fVertexArrayColorOffset; GrGLFunction fVertexArrayEdgeFlagOffset; GrGLFunction fVertexArrayIndexOffset; GrGLFunction fVertexArrayNormalOffset; GrGLFunction fVertexArrayTexCoordOffset; GrGLFunction fVertexArrayMultiTexCoordOffset; GrGLFunction fVertexArrayFogCoordOffset; GrGLFunction fVertexArraySecondaryColorOffset; GrGLFunction fVertexArrayVertexAttribOffset; GrGLFunction fVertexArrayVertexAttribIOffset; GrGLFunction fEnableVertexArray; GrGLFunction fDisableVertexArray; GrGLFunction fEnableVertexArrayAttrib; GrGLFunction fDisableVertexArrayAttrib; GrGLFunction fGetVertexArrayIntegerv; GrGLFunction fGetVertexArrayPointerv; GrGLFunction fGetVertexArrayIntegeri_v; GrGLFunction fGetVertexArrayPointeri_v; GrGLFunction fMapNamedBufferRange; GrGLFunction fFlushMappedNamedBufferRange; // OpenGL 3.1 GrGLFunction fTextureBuffer; /* KHR_debug */ GrGLFunction fDebugMessageControl; GrGLFunction fDebugMessageInsert; GrGLFunction fDebugMessageCallback; GrGLFunction fGetDebugMessageLog; GrGLFunction fPushDebugGroup; GrGLFunction fPopDebugGroup; GrGLFunction fObjectLabel; /* EGL functions */ GrGLFunction fEGLCreateImage; GrGLFunction fEGLDestroyImage; } fFunctions; // This exists for internal testing. virtual void abandon() const {} }; #endif