/* * 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 "GrRefCnt.h" //////////////////////////////////////////////////////////////////////////////// /** * Classifies GL contexts (currently as Desktop vs. ES2). This is a bitfield. * A GrGLInterface (defined below) may support multiple bindings. */ enum GrGLBinding { kNone_GrGLBinding = 0x0, kDesktop_GrGLBinding = 0x01, kES2_GrGLBinding = 0x02, // for iteration of GrGLBindings kFirstGrGLBinding = kDesktop_GrGLBinding, kLastGrGLBinding = kES2_GrGLBinding }; //////////////////////////////////////////////////////////////////////////////// /** * 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 the "default" GL interface is used. 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. It is implementation-specific * whether the same GrGLInterface is returned or whether a new one is created * at each call. Some platforms may not be able to use a single GrGLInterface * because extension function ptrs vary across contexts. Note that GrGLInterface * is ref-counted. So if the same object is returned by multiple calls to * GrGLDefaultInterface, each should bump the ref count. * * 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 */ struct GrGLInterface; const GrGLInterface* GrGLDefaultInterface(); /** * Creates a GrGLInterface for a "native" GL context (e.g. WGL on windows, * GLX on linux, AGL on Mac). On platforms that have context-specific function * pointers for GL extensions (e.g. windows) the returned interface is only * valid for the context that was current at creation. */ const GrGLInterface* GrGLCreateNativeInterface(); #if SK_MESA /** * Creates a GrGLInterface for an OSMesa context. */ const GrGLInterface* GrGLCreateMesaInterface(); #endif #if SK_ANGLE /** * Creates a GrGLInterface for an ANGLE context. */ const GrGLInterface* GrGLCreateANGLEInterface(); #endif /** * Creates a null GrGLInterface that doesn't draw anything. Used for measuring * CPU overhead. */ const GrGLInterface* GrGLCreateNullInterface(); /** * Creates a debugging GrGLInterface that doesn't draw anything. Used for * finding memory leaks and invalid memory accesses. */ const GrGLInterface* GrGLCreateDebugInterface(); #if GR_GL_PER_GL_FUNC_CALLBACK typedef void (*GrGLInterfaceCallbackProc)(const GrGLInterface*); typedef intptr_t GrGLInterfaceCallbackData; #endif /* * The following interface exports the OpenGL entry points used by the system. * Use of OpenGL calls is disallowed. All calls should be invoked through * the global instance of this struct, defined above. * * IMPORTANT NOTE: The OpenGL entry points exposed here include both core GL * functions, and extensions. The system assumes that the address of the * extension pointer will be valid across contexts. */ struct GR_API GrGLInterface : public GrRefCnt { private: // simple wrapper class that exists only to initialize a pointer to NULL template class GLPtr { public: GLPtr() : fPtr(NULL) {} GLPtr operator =(FNPTR_TYPE ptr) { fPtr = ptr; return *this; } operator FNPTR_TYPE() const { return fPtr; } private: FNPTR_TYPE fPtr; }; public: GrGLInterface(); // Validates that the GrGLInterface supports a binding. This means that // the GrGLinterface advertises the binding in fBindingsExported and all // the necessary function pointers have been initialized. bool validate(GrGLBinding binding) const; // Indicator variable specifying the type of GL implementation // exported: GLES2 and/or Desktop. GrGLBinding fBindingsExported; GLPtr fActiveTexture; GLPtr fAttachShader; GLPtr fBeginQuery; GLPtr fBindAttribLocation; GLPtr fBindBuffer; GLPtr fBindFragDataLocation; GLPtr fBindFragDataLocationIndexed; GLPtr fBindFramebuffer; GLPtr fBindRenderbuffer; GLPtr fBindTexture; GLPtr fBlendColor; GLPtr fBlendFunc; GLPtr fBlendEquation; GLPtr fBlitFramebuffer; GLPtr fBufferData; GLPtr fBufferSubData; GLPtr fCheckFramebufferStatus; GLPtr fClear; GLPtr fClearColor; GLPtr fClearStencil; GLPtr fColorMask; GLPtr fColorPointer; GLPtr fCompileShader; GLPtr fCompressedTexImage2D; GLPtr fCreateProgram; GLPtr fCreateShader; GLPtr fCullFace; GLPtr fDeleteBuffers; GLPtr fDeleteFramebuffers; GLPtr fDeleteProgram; GLPtr fDeleteQueries; GLPtr fDeleteRenderbuffers; GLPtr fDeleteShader; GLPtr fDeleteTextures; GLPtr fDepthMask; GLPtr fDisable; GLPtr fDisableVertexAttribArray; GLPtr fDrawArrays; GLPtr fDrawBuffer; GLPtr fDrawBuffers; GLPtr fDrawElements; GLPtr fEnable; GLPtr fEnableVertexAttribArray; GLPtr fEndQuery; GLPtr fFinish; GLPtr fFlush; GLPtr fFramebufferRenderbuffer; GLPtr fFramebufferTexture2D; GLPtr fFrontFace; GLPtr fGenBuffers; GLPtr fGenFramebuffers; GLPtr fGenQueries; GLPtr fGenRenderbuffers; GLPtr fGenTextures; GLPtr fGetBufferParameteriv; GLPtr fGetError; GLPtr fGetFramebufferAttachmentParameteriv; GLPtr fGetIntegerv; GLPtr fGetQueryObjecti64v; GLPtr fGetQueryObjectiv; GLPtr fGetQueryObjectui64v; GLPtr fGetQueryObjectuiv; GLPtr fGetQueryiv; GLPtr fGetProgramInfoLog; GLPtr fGetProgramiv; GLPtr fGetRenderbufferParameteriv; GLPtr fGetShaderInfoLog; GLPtr fGetShaderiv; GLPtr fGetString; GLPtr fGetTexLevelParameteriv; GLPtr fGetUniformLocation; GLPtr fLineWidth; GLPtr fLinkProgram; GLPtr fMapBuffer; GLPtr fPixelStorei; GLPtr fQueryCounter; GLPtr fReadBuffer; GLPtr fReadPixels; GLPtr fRenderbufferStorage; GLPtr fRenderbufferStorageMultisample; GLPtr fRenderbufferStorageMultisampleCoverage; GLPtr fResolveMultisampleFramebuffer; GLPtr fScissor; GLPtr fShaderSource; GLPtr fStencilFunc; GLPtr fStencilFuncSeparate; GLPtr fStencilMask; GLPtr fStencilMaskSeparate; GLPtr fStencilOp; GLPtr fStencilOpSeparate; GLPtr fTexImage2D; GLPtr fTexParameteri; GLPtr fTexSubImage2D; GLPtr fTexStorage2D; GLPtr fUniform1f; GLPtr fUniform1i; GLPtr fUniform1fv; GLPtr fUniform1iv; GLPtr fUniform2f; GLPtr fUniform2i; GLPtr fUniform2fv; GLPtr fUniform2iv; GLPtr fUniform3f; GLPtr fUniform3i; GLPtr fUniform3fv; GLPtr fUniform3iv; GLPtr fUniform4f; GLPtr fUniform4i; GLPtr fUniform4fv; GLPtr fUniform4iv; GLPtr fUniformMatrix2fv; GLPtr fUniformMatrix3fv; GLPtr fUniformMatrix4fv; GLPtr fUnmapBuffer; GLPtr fUseProgram; GLPtr fVertexAttrib4fv; GLPtr fVertexAttribPointer; GLPtr fViewport; // Per-GL func callback #if GR_GL_PER_GL_FUNC_CALLBACK GrGLInterfaceCallbackProc fCallback; GrGLInterfaceCallbackData fCallbackData; #endif }; #endif