epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
twiz@google.com | 59a190b | 2011-03-14 21:23:01 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
twiz@google.com | 59a190b | 2011-03-14 21:23:01 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | |
| 10 | #ifndef GrGLInterface_DEFINED |
| 11 | #define GrGLInterface_DEFINED |
| 12 | |
bsalomon@google.com | 637d5e9 | 2012-05-07 21:33:56 +0000 | [diff] [blame^] | 13 | #include "GrGLFunctions.h" |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 14 | #include "GrRefCnt.h" |
twiz@google.com | 59a190b | 2011-03-14 21:23:01 +0000 | [diff] [blame] | 15 | |
twiz@google.com | 59a190b | 2011-03-14 21:23:01 +0000 | [diff] [blame] | 16 | //////////////////////////////////////////////////////////////////////////////// |
| 17 | |
| 18 | /** |
bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 19 | * Classifies GL contexts (currently as Desktop vs. ES2). This is a bitfield. |
| 20 | * A GrGLInterface (defined below) may support multiple bindings. |
| 21 | */ |
| 22 | enum GrGLBinding { |
| 23 | kNone_GrGLBinding = 0x0, |
| 24 | |
| 25 | kDesktop_GrGLBinding = 0x01, |
| 26 | kES2_GrGLBinding = 0x02, |
| 27 | |
| 28 | // for iteration of GrGLBindings |
bsalomon@google.com | b447d21 | 2012-02-10 20:25:36 +0000 | [diff] [blame] | 29 | kFirstGrGLBinding = kDesktop_GrGLBinding, |
bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 30 | kLastGrGLBinding = kES2_GrGLBinding |
| 31 | }; |
| 32 | |
| 33 | //////////////////////////////////////////////////////////////////////////////// |
| 34 | |
| 35 | /** |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 36 | * Rather than depend on platform-specific GL headers and libraries, we require |
| 37 | * the client to provide a struct of GL function pointers. This struct can be |
| 38 | * specified per-GrContext as a parameter to GrContext::Create. If NULL is |
| 39 | * passed to Create then the "default" GL interface is used. If the default is |
| 40 | * also NULL GrContext creation will fail. |
| 41 | * |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 42 | * The default interface is returned by GrGLDefaultInterface. This function's |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 43 | * implementation is platform-specific. Several have been provided, along with |
| 44 | * an implementation that simply returns NULL. It is implementation-specific |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 45 | * whether the same GrGLInterface is returned or whether a new one is created |
| 46 | * at each call. Some platforms may not be able to use a single GrGLInterface |
| 47 | * because extension function ptrs vary across contexts. Note that GrGLInterface |
| 48 | * is ref-counted. So if the same object is returned by multiple calls to |
| 49 | * GrGLDefaultInterface, each should bump the ref count. |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 50 | * |
| 51 | * By defining GR_GL_PER_GL_CALL_IFACE_CALLBACK to 1 the client can specify a |
| 52 | * callback function that will be called prior to each GL function call. See |
| 53 | * comments in GrGLConfig.h |
twiz@google.com | 59a190b | 2011-03-14 21:23:01 +0000 | [diff] [blame] | 54 | */ |
twiz@google.com | 59a190b | 2011-03-14 21:23:01 +0000 | [diff] [blame] | 55 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 56 | struct GrGLInterface; |
| 57 | |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 58 | const GrGLInterface* GrGLDefaultInterface(); |
twiz@google.com | 59a190b | 2011-03-14 21:23:01 +0000 | [diff] [blame] | 59 | |
bsalomon@google.com | 57f5d98 | 2011-10-24 21:17:53 +0000 | [diff] [blame] | 60 | /** |
| 61 | * Creates a GrGLInterface for a "native" GL context (e.g. WGL on windows, |
| 62 | * GLX on linux, AGL on Mac). On platforms that have context-specific function |
| 63 | * pointers for GL extensions (e.g. windows) the returned interface is only |
| 64 | * valid for the context that was current at creation. |
| 65 | */ |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 66 | const GrGLInterface* GrGLCreateNativeInterface(); |
| 67 | |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 68 | #if SK_MESA |
bsalomon@google.com | 57f5d98 | 2011-10-24 21:17:53 +0000 | [diff] [blame] | 69 | /** |
| 70 | * Creates a GrGLInterface for an OSMesa context. |
| 71 | */ |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 72 | const GrGLInterface* GrGLCreateMesaInterface(); |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 73 | #endif |
| 74 | |
| 75 | #if SK_ANGLE |
| 76 | /** |
| 77 | * Creates a GrGLInterface for an ANGLE context. |
| 78 | */ |
| 79 | const GrGLInterface* GrGLCreateANGLEInterface(); |
| 80 | #endif |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 81 | |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 82 | /** |
| 83 | * Creates a null GrGLInterface that doesn't draw anything. Used for measuring |
| 84 | * CPU overhead. |
| 85 | */ |
| 86 | const GrGLInterface* GrGLCreateNullInterface(); |
| 87 | |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 88 | /** |
| 89 | * Creates a debugging GrGLInterface that doesn't draw anything. Used for |
| 90 | * finding memory leaks and invalid memory accesses. |
| 91 | */ |
| 92 | const GrGLInterface* GrGLCreateDebugInterface(); |
| 93 | |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 94 | #if GR_GL_PER_GL_FUNC_CALLBACK |
| 95 | typedef void (*GrGLInterfaceCallbackProc)(const GrGLInterface*); |
| 96 | typedef intptr_t GrGLInterfaceCallbackData; |
| 97 | #endif |
| 98 | |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 99 | /* |
| 100 | * The following interface exports the OpenGL entry points used by the system. |
| 101 | * Use of OpenGL calls is disallowed. All calls should be invoked through |
| 102 | * the global instance of this struct, defined above. |
| 103 | * |
| 104 | * IMPORTANT NOTE: The OpenGL entry points exposed here include both core GL |
| 105 | * functions, and extensions. The system assumes that the address of the |
| 106 | * extension pointer will be valid across contexts. |
| 107 | */ |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 108 | struct GR_API GrGLInterface : public GrRefCnt { |
bsalomon@google.com | ba800e2 | 2012-03-29 21:04:52 +0000 | [diff] [blame] | 109 | private: |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 110 | // simple wrapper class that exists only to initialize a pointer to NULL |
bsalomon@google.com | ba800e2 | 2012-03-29 21:04:52 +0000 | [diff] [blame] | 111 | template <typename FNPTR_TYPE> class GLPtr { |
| 112 | public: |
| 113 | GLPtr() : fPtr(NULL) {} |
| 114 | GLPtr operator =(FNPTR_TYPE ptr) { fPtr = ptr; return *this; } |
| 115 | operator FNPTR_TYPE() const { return fPtr; } |
| 116 | private: |
| 117 | FNPTR_TYPE fPtr; |
| 118 | }; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 119 | |
bsalomon@google.com | ba800e2 | 2012-03-29 21:04:52 +0000 | [diff] [blame] | 120 | public: |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 121 | GrGLInterface(); |
| 122 | |
bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 123 | // Validates that the GrGLInterface supports a binding. This means that |
| 124 | // the GrGLinterface advertises the binding in fBindingsExported and all |
| 125 | // the necessary function pointers have been initialized. |
| 126 | bool validate(GrGLBinding binding) const; |
| 127 | |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 128 | // Indicator variable specifying the type of GL implementation |
bsalomon@google.com | ba800e2 | 2012-03-29 21:04:52 +0000 | [diff] [blame] | 129 | // exported: GLES2 and/or Desktop. |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 130 | GrGLBinding fBindingsExported; |
| 131 | |
bsalomon@google.com | ba800e2 | 2012-03-29 21:04:52 +0000 | [diff] [blame] | 132 | GLPtr<GrGLActiveTextureProc> fActiveTexture; |
| 133 | GLPtr<GrGLAttachShaderProc> fAttachShader; |
| 134 | GLPtr<GrGLBeginQueryProc> fBeginQuery; |
| 135 | GLPtr<GrGLBindAttribLocationProc> fBindAttribLocation; |
| 136 | GLPtr<GrGLBindBufferProc> fBindBuffer; |
| 137 | GLPtr<GrGLBindFragDataLocationProc> fBindFragDataLocation; |
| 138 | GLPtr<GrGLBindFragDataLocationIndexedProc> fBindFragDataLocationIndexed; |
| 139 | GLPtr<GrGLBindFramebufferProc> fBindFramebuffer; |
| 140 | GLPtr<GrGLBindRenderbufferProc> fBindRenderbuffer; |
| 141 | GLPtr<GrGLBindTextureProc> fBindTexture; |
| 142 | GLPtr<GrGLBlendColorProc> fBlendColor; |
| 143 | GLPtr<GrGLBlendFuncProc> fBlendFunc; |
robertphillips@google.com | e788430 | 2012-04-18 14:39:58 +0000 | [diff] [blame] | 144 | GLPtr<GrGLBlendEquationProc> fBlendEquation; |
bsalomon@google.com | ba800e2 | 2012-03-29 21:04:52 +0000 | [diff] [blame] | 145 | GLPtr<GrGLBlitFramebufferProc> fBlitFramebuffer; |
| 146 | GLPtr<GrGLBufferDataProc> fBufferData; |
| 147 | GLPtr<GrGLBufferSubDataProc> fBufferSubData; |
| 148 | GLPtr<GrGLCheckFramebufferStatusProc> fCheckFramebufferStatus; |
| 149 | GLPtr<GrGLClearProc> fClear; |
| 150 | GLPtr<GrGLClearColorProc> fClearColor; |
| 151 | GLPtr<GrGLClearStencilProc> fClearStencil; |
| 152 | GLPtr<GrGLColorMaskProc> fColorMask; |
| 153 | GLPtr<GrGLColorPointerProc> fColorPointer; |
| 154 | GLPtr<GrGLCompileShaderProc> fCompileShader; |
| 155 | GLPtr<GrGLCompressedTexImage2DProc> fCompressedTexImage2D; |
| 156 | GLPtr<GrGLCreateProgramProc> fCreateProgram; |
| 157 | GLPtr<GrGLCreateShaderProc> fCreateShader; |
| 158 | GLPtr<GrGLCullFaceProc> fCullFace; |
| 159 | GLPtr<GrGLDeleteBuffersProc> fDeleteBuffers; |
| 160 | GLPtr<GrGLDeleteFramebuffersProc> fDeleteFramebuffers; |
| 161 | GLPtr<GrGLDeleteProgramProc> fDeleteProgram; |
| 162 | GLPtr<GrGLDeleteQueriesProc> fDeleteQueries; |
| 163 | GLPtr<GrGLDeleteRenderbuffersProc> fDeleteRenderbuffers; |
| 164 | GLPtr<GrGLDeleteShaderProc> fDeleteShader; |
| 165 | GLPtr<GrGLDeleteTexturesProc> fDeleteTextures; |
| 166 | GLPtr<GrGLDepthMaskProc> fDepthMask; |
| 167 | GLPtr<GrGLDisableProc> fDisable; |
| 168 | GLPtr<GrGLDisableVertexAttribArrayProc> fDisableVertexAttribArray; |
| 169 | GLPtr<GrGLDrawArraysProc> fDrawArrays; |
| 170 | GLPtr<GrGLDrawBufferProc> fDrawBuffer; |
| 171 | GLPtr<GrGLDrawBuffersProc> fDrawBuffers; |
| 172 | GLPtr<GrGLDrawElementsProc> fDrawElements; |
| 173 | GLPtr<GrGLEnableProc> fEnable; |
| 174 | GLPtr<GrGLEnableVertexAttribArrayProc> fEnableVertexAttribArray; |
| 175 | GLPtr<GrGLEndQueryProc> fEndQuery; |
| 176 | GLPtr<GrGLFinishProc> fFinish; |
| 177 | GLPtr<GrGLFlushProc> fFlush; |
| 178 | GLPtr<GrGLFramebufferRenderbufferProc> fFramebufferRenderbuffer; |
| 179 | GLPtr<GrGLFramebufferTexture2DProc> fFramebufferTexture2D; |
| 180 | GLPtr<GrGLFrontFaceProc> fFrontFace; |
| 181 | GLPtr<GrGLGenBuffersProc> fGenBuffers; |
| 182 | GLPtr<GrGLGenFramebuffersProc> fGenFramebuffers; |
| 183 | GLPtr<GrGLGenQueriesProc> fGenQueries; |
| 184 | GLPtr<GrGLGenRenderbuffersProc> fGenRenderbuffers; |
| 185 | GLPtr<GrGLGenTexturesProc> fGenTextures; |
| 186 | GLPtr<GrGLGetBufferParameterivProc> fGetBufferParameteriv; |
| 187 | GLPtr<GrGLGetErrorProc> fGetError; |
| 188 | GLPtr<GrGLGetFramebufferAttachmentParameterivProc> fGetFramebufferAttachmentParameteriv; |
| 189 | GLPtr<GrGLGetIntegervProc> fGetIntegerv; |
| 190 | GLPtr<GrGLGetQueryObjecti64vProc> fGetQueryObjecti64v; |
| 191 | GLPtr<GrGLGetQueryObjectivProc> fGetQueryObjectiv; |
| 192 | GLPtr<GrGLGetQueryObjectui64vProc> fGetQueryObjectui64v; |
| 193 | GLPtr<GrGLGetQueryObjectuivProc> fGetQueryObjectuiv; |
| 194 | GLPtr<GrGLGetQueryivProc> fGetQueryiv; |
| 195 | GLPtr<GrGLGetProgramInfoLogProc> fGetProgramInfoLog; |
| 196 | GLPtr<GrGLGetProgramivProc> fGetProgramiv; |
| 197 | GLPtr<GrGLGetRenderbufferParameterivProc> fGetRenderbufferParameteriv; |
| 198 | GLPtr<GrGLGetShaderInfoLogProc> fGetShaderInfoLog; |
| 199 | GLPtr<GrGLGetShaderivProc> fGetShaderiv; |
| 200 | GLPtr<GrGLGetStringProc> fGetString; |
| 201 | GLPtr<GrGLGetTexLevelParameterivProc> fGetTexLevelParameteriv; |
| 202 | GLPtr<GrGLGetUniformLocationProc> fGetUniformLocation; |
| 203 | GLPtr<GrGLLineWidthProc> fLineWidth; |
| 204 | GLPtr<GrGLLinkProgramProc> fLinkProgram; |
| 205 | GLPtr<GrGLMapBufferProc> fMapBuffer; |
| 206 | GLPtr<GrGLPixelStoreiProc> fPixelStorei; |
| 207 | GLPtr<GrGLQueryCounterProc> fQueryCounter; |
| 208 | GLPtr<GrGLReadBufferProc> fReadBuffer; |
| 209 | GLPtr<GrGLReadPixelsProc> fReadPixels; |
| 210 | GLPtr<GrGLRenderbufferStorageProc> fRenderbufferStorage; |
| 211 | GLPtr<GrGLRenderbufferStorageMultisampleProc> fRenderbufferStorageMultisample; |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 212 | GLPtr<GrGLRenderbufferStorageMultisampleCoverageProc> fRenderbufferStorageMultisampleCoverage; |
bsalomon@google.com | ba800e2 | 2012-03-29 21:04:52 +0000 | [diff] [blame] | 213 | GLPtr<GrGLResolveMultisampleFramebufferProc> fResolveMultisampleFramebuffer; |
| 214 | GLPtr<GrGLScissorProc> fScissor; |
| 215 | GLPtr<GrGLShaderSourceProc> fShaderSource; |
| 216 | GLPtr<GrGLStencilFuncProc> fStencilFunc; |
| 217 | GLPtr<GrGLStencilFuncSeparateProc> fStencilFuncSeparate; |
| 218 | GLPtr<GrGLStencilMaskProc> fStencilMask; |
| 219 | GLPtr<GrGLStencilMaskSeparateProc> fStencilMaskSeparate; |
| 220 | GLPtr<GrGLStencilOpProc> fStencilOp; |
| 221 | GLPtr<GrGLStencilOpSeparateProc> fStencilOpSeparate; |
| 222 | GLPtr<GrGLTexImage2DProc> fTexImage2D; |
| 223 | GLPtr<GrGLTexParameteriProc> fTexParameteri; |
| 224 | GLPtr<GrGLTexSubImage2DProc> fTexSubImage2D; |
| 225 | GLPtr<GrGLTexStorage2DProc> fTexStorage2D; |
| 226 | GLPtr<GrGLUniform1fProc> fUniform1f; |
| 227 | GLPtr<GrGLUniform1iProc> fUniform1i; |
| 228 | GLPtr<GrGLUniform1fvProc> fUniform1fv; |
| 229 | GLPtr<GrGLUniform1ivProc> fUniform1iv; |
| 230 | GLPtr<GrGLUniform2fProc> fUniform2f; |
| 231 | GLPtr<GrGLUniform2iProc> fUniform2i; |
| 232 | GLPtr<GrGLUniform2fvProc> fUniform2fv; |
| 233 | GLPtr<GrGLUniform2ivProc> fUniform2iv; |
| 234 | GLPtr<GrGLUniform3fProc> fUniform3f; |
| 235 | GLPtr<GrGLUniform3iProc> fUniform3i; |
| 236 | GLPtr<GrGLUniform3fvProc> fUniform3fv; |
| 237 | GLPtr<GrGLUniform3ivProc> fUniform3iv; |
| 238 | GLPtr<GrGLUniform4fProc> fUniform4f; |
| 239 | GLPtr<GrGLUniform4iProc> fUniform4i; |
| 240 | GLPtr<GrGLUniform4fvProc> fUniform4fv; |
| 241 | GLPtr<GrGLUniform4ivProc> fUniform4iv; |
| 242 | GLPtr<GrGLUniformMatrix2fvProc> fUniformMatrix2fv; |
| 243 | GLPtr<GrGLUniformMatrix3fvProc> fUniformMatrix3fv; |
| 244 | GLPtr<GrGLUniformMatrix4fvProc> fUniformMatrix4fv; |
| 245 | GLPtr<GrGLUnmapBufferProc> fUnmapBuffer; |
| 246 | GLPtr<GrGLUseProgramProc> fUseProgram; |
| 247 | GLPtr<GrGLVertexAttrib4fvProc> fVertexAttrib4fv; |
| 248 | GLPtr<GrGLVertexAttribPointerProc> fVertexAttribPointer; |
| 249 | GLPtr<GrGLViewportProc> fViewport; |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 250 | |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 251 | // Per-GL func callback |
| 252 | #if GR_GL_PER_GL_FUNC_CALLBACK |
| 253 | GrGLInterfaceCallbackProc fCallback; |
| 254 | GrGLInterfaceCallbackData fCallbackData; |
| 255 | #endif |
| 256 | |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 257 | }; |
twiz@google.com | 59a190b | 2011-03-14 21:23:01 +0000 | [diff] [blame] | 258 | |
| 259 | #endif |