| 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 | |
| twiz@google.com | 59a190b | 2011-03-14 21:23:01 +0000 | [diff] [blame] | 10 | #include "GrTypes.h" |
| bsalomon@google.com | f987d1b | 2011-04-04 17:13:52 +0000 | [diff] [blame] | 11 | #include "GrGLInterface.h" |
| 12 | #include "GrGLDefines.h" |
| twiz@google.com | 59a190b | 2011-03-14 21:23:01 +0000 | [diff] [blame] | 13 | |
| 14 | #include <stdio.h> |
| 15 | |
| bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 16 | #if GR_GL_PER_GL_FUNC_CALLBACK |
| 17 | namespace { |
| 18 | void GrGLDefaultInterfaceCallback(const GrGLInterface*) {} |
| 19 | } |
| 20 | #endif |
| 21 | |
| bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 22 | GrGLVersion GrGLGetVersionFromString(const char* versionString) { |
| bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 23 | if (NULL == versionString) { |
| 24 | GrAssert(!"NULL GL version string."); |
| 25 | return 0; |
| 26 | } |
| 27 | |
| bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 28 | int major, minor; |
| twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 29 | |
| bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 30 | int n = sscanf(versionString, "%d.%d", &major, &minor); |
| twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 31 | if (2 == n) { |
| bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 32 | return GR_GL_VER(major, minor); |
| twiz@google.com | 59a190b | 2011-03-14 21:23:01 +0000 | [diff] [blame] | 33 | } |
| twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 34 | |
| twiz@google.com | 59a190b | 2011-03-14 21:23:01 +0000 | [diff] [blame] | 35 | char profile[2]; |
| twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 36 | n = sscanf(versionString, "OpenGL ES-%c%c %d.%d", profile, profile+1, |
| bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 37 | &major, &minor); |
| 38 | if (4 == n) { |
| 39 | return GR_GL_VER(major, minor); |
| 40 | } |
| 41 | |
| 42 | n = sscanf(versionString, "OpenGL ES %d.%d", &major, &minor); |
| 43 | if (2 == n) { |
| 44 | return GR_GL_VER(major, minor); |
| twiz@google.com | 59a190b | 2011-03-14 21:23:01 +0000 | [diff] [blame] | 45 | } |
| twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 46 | |
| bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 47 | return 0; |
| twiz@google.com | 59a190b | 2011-03-14 21:23:01 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 50 | GrGLSLVersion GrGLGetGLSLVersionFromString(const char* versionString) { |
| 51 | if (NULL == versionString) { |
| 52 | GrAssert(!"NULL GLSL version string."); |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | int major, minor; |
| 57 | |
| 58 | int n = sscanf(versionString, "%d.%d", &major, &minor); |
| 59 | if (2 == n) { |
| 60 | return GR_GLSL_VER(major, minor); |
| 61 | } |
| 62 | |
| 63 | n = sscanf(versionString, "OpenGL ES GLSL ES %d.%d", &major, &minor); |
| 64 | if (2 == n) { |
| 65 | return GR_GLSL_VER(major, minor); |
| 66 | } |
| 67 | return 0; |
| 68 | } |
| 69 | |
| bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 70 | bool GrGLHasExtensionFromString(const char* ext, const char* extensionString) { |
| twiz@google.com | 59a190b | 2011-03-14 21:23:01 +0000 | [diff] [blame] | 71 | int extLength = strlen(ext); |
| 72 | |
| 73 | while (true) { |
| 74 | int n = strcspn(extensionString, " "); |
| 75 | if (n == extLength && 0 == strncmp(ext, extensionString, n)) { |
| 76 | return true; |
| 77 | } |
| 78 | if (0 == extensionString[n]) { |
| 79 | return false; |
| 80 | } |
| 81 | extensionString += n+1; |
| 82 | } |
| 83 | |
| 84 | return false; |
| 85 | } |
| 86 | |
| bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 87 | bool GrGLHasExtension(const GrGLInterface* gl, const char* ext) { |
| bsalomon@google.com | dca4aab | 2011-09-06 19:05:24 +0000 | [diff] [blame] | 88 | const GrGLubyte* glstr; |
| 89 | GR_GL_CALL_RET(gl, glstr, GetString(GR_GL_EXTENSIONS)); |
| bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 90 | return GrGLHasExtensionFromString(ext, (const char*) glstr); |
| twiz@google.com | 59a190b | 2011-03-14 21:23:01 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 93 | GrGLVersion GrGLGetVersion(const GrGLInterface* gl) { |
| bsalomon@google.com | dca4aab | 2011-09-06 19:05:24 +0000 | [diff] [blame] | 94 | const GrGLubyte* v; |
| 95 | GR_GL_CALL_RET(gl, v, GetString(GR_GL_VERSION)); |
| bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 96 | return GrGLGetVersionFromString((const char*) v); |
| bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 99 | GrGLSLVersion GrGLGetGLSLVersion(const GrGLInterface* gl) { |
| 100 | const GrGLubyte* v; |
| 101 | GR_GL_CALL_RET(gl, v, GetString(GR_GL_SHADING_LANGUAGE_VERSION)); |
| 102 | return GrGLGetGLSLVersionFromString((const char*) v); |
| 103 | } |
| 104 | |
| bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 105 | GrGLInterface::GrGLInterface() { |
| 106 | fBindingsExported = (GrGLBinding)0; |
| bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 107 | |
| 108 | fActiveTexture = NULL; |
| 109 | fAttachShader = NULL; |
| bsalomon@google.com | f97c194 | 2011-10-19 21:35:26 +0000 | [diff] [blame] | 110 | fBeginQuery = NULL; |
| bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 111 | fBindAttribLocation = NULL; |
| 112 | fBindBuffer = NULL; |
| bsalomon@google.com | bc5cf51 | 2011-09-21 16:21:07 +0000 | [diff] [blame] | 113 | fBindFragDataLocation = NULL; |
| bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 114 | fBindTexture = NULL; |
| 115 | fBlendColor = NULL; |
| 116 | fBlendFunc = NULL; |
| 117 | fBufferData = NULL; |
| 118 | fBufferSubData = NULL; |
| 119 | fClear = NULL; |
| 120 | fClearColor = NULL; |
| 121 | fClearStencil = NULL; |
| bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 122 | fColorMask = NULL; |
| 123 | fColorPointer = NULL; |
| 124 | fCompileShader = NULL; |
| 125 | fCompressedTexImage2D = NULL; |
| 126 | fCreateProgram = NULL; |
| 127 | fCreateShader = NULL; |
| 128 | fCullFace = NULL; |
| 129 | fDeleteBuffers = NULL; |
| 130 | fDeleteProgram = NULL; |
| bsalomon@google.com | f97c194 | 2011-10-19 21:35:26 +0000 | [diff] [blame] | 131 | fDeleteQueries = NULL; |
| bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 132 | fDeleteShader = NULL; |
| 133 | fDeleteTextures = NULL; |
| 134 | fDepthMask = NULL; |
| 135 | fDisable = NULL; |
| bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 136 | fDisableVertexAttribArray = NULL; |
| 137 | fDrawArrays = NULL; |
| 138 | fDrawBuffer = NULL; |
| 139 | fDrawBuffers = NULL; |
| 140 | fDrawElements = NULL; |
| bsalomon@google.com | f97c194 | 2011-10-19 21:35:26 +0000 | [diff] [blame] | 141 | fEndQuery = NULL; |
| 142 | fFinish = NULL; |
| 143 | fFlush = NULL; |
| bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 144 | fEnable = NULL; |
| bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 145 | fEnableVertexAttribArray = NULL; |
| 146 | fFrontFace = NULL; |
| 147 | fGenBuffers = NULL; |
| bsalomon@google.com | f97c194 | 2011-10-19 21:35:26 +0000 | [diff] [blame] | 148 | fGenQueries = NULL; |
| bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 149 | fGenTextures = NULL; |
| 150 | fGetBufferParameteriv = NULL; |
| 151 | fGetError = NULL; |
| 152 | fGetIntegerv = NULL; |
| bsalomon@google.com | f97c194 | 2011-10-19 21:35:26 +0000 | [diff] [blame] | 153 | fGetQueryiv = NULL; |
| 154 | fGetQueryObjecti64v = NULL; |
| 155 | fGetQueryObjectiv = NULL; |
| 156 | fGetQueryObjectui64v = NULL; |
| 157 | fGetQueryObjectuiv = NULL; |
| bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 158 | fGetProgramInfoLog = NULL; |
| 159 | fGetProgramiv = NULL; |
| 160 | fGetShaderInfoLog = NULL; |
| 161 | fGetShaderiv = NULL; |
| 162 | fGetString = NULL; |
| 163 | fGetTexLevelParameteriv = NULL; |
| 164 | fGetUniformLocation = NULL; |
| 165 | fLineWidth = NULL; |
| 166 | fLinkProgram = NULL; |
| bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 167 | fPixelStorei = NULL; |
| bsalomon@google.com | f97c194 | 2011-10-19 21:35:26 +0000 | [diff] [blame] | 168 | fQueryCounter = NULL; |
| bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 169 | fReadBuffer = NULL; |
| 170 | fReadPixels = NULL; |
| 171 | fScissor = NULL; |
| bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 172 | fShaderSource = NULL; |
| 173 | fStencilFunc = NULL; |
| 174 | fStencilFuncSeparate = NULL; |
| 175 | fStencilMask = NULL; |
| 176 | fStencilMaskSeparate = NULL; |
| 177 | fStencilOp = NULL; |
| 178 | fStencilOpSeparate = NULL; |
| bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 179 | fTexImage2D = NULL; |
| 180 | fTexParameteri = NULL; |
| 181 | fTexSubImage2D = NULL; |
| 182 | fUniform1f = NULL; |
| 183 | fUniform1i = NULL; |
| 184 | fUniform1fv = NULL; |
| 185 | fUniform1iv = NULL; |
| 186 | fUniform2f = NULL; |
| 187 | fUniform2i = NULL; |
| 188 | fUniform2fv = NULL; |
| 189 | fUniform2iv = NULL; |
| 190 | fUniform3f = NULL; |
| 191 | fUniform3i = NULL; |
| 192 | fUniform3fv = NULL; |
| 193 | fUniform3iv = NULL; |
| 194 | fUniform4f = NULL; |
| 195 | fUniform4i = NULL; |
| 196 | fUniform4fv = NULL; |
| 197 | fUniform4iv = NULL; |
| 198 | fUniformMatrix2fv = NULL; |
| 199 | fUniformMatrix3fv = NULL; |
| 200 | fUniformMatrix4fv = NULL; |
| 201 | fUseProgram = NULL; |
| 202 | fVertexAttrib4fv = NULL; |
| 203 | fVertexAttribPointer = NULL; |
| bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 204 | fViewport = NULL; |
| 205 | fBindFramebuffer = NULL; |
| 206 | fBindRenderbuffer = NULL; |
| 207 | fCheckFramebufferStatus = NULL; |
| 208 | fDeleteFramebuffers = NULL; |
| 209 | fDeleteRenderbuffers = NULL; |
| 210 | fFramebufferRenderbuffer = NULL; |
| 211 | fFramebufferTexture2D = NULL; |
| 212 | fGenFramebuffers = NULL; |
| 213 | fGenRenderbuffers = NULL; |
| 214 | fGetFramebufferAttachmentParameteriv = NULL; |
| 215 | fGetRenderbufferParameteriv = NULL; |
| 216 | fRenderbufferStorage = NULL; |
| 217 | fRenderbufferStorageMultisample = NULL; |
| 218 | fBlitFramebuffer = NULL; |
| 219 | fResolveMultisampleFramebuffer = NULL; |
| 220 | fMapBuffer = NULL; |
| 221 | fUnmapBuffer = NULL; |
| 222 | fBindFragDataLocationIndexed = NULL; |
| bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 223 | |
| 224 | #if GR_GL_PER_GL_FUNC_CALLBACK |
| 225 | fCallback = GrGLDefaultInterfaceCallback; |
| 226 | fCallbackData = 0; |
| 227 | #endif |
| bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 230 | bool GrGLInterface::validate() const { |
| bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 231 | |
| bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 232 | bool isDesktop = this->supportsDesktop(); |
| 233 | |
| 234 | bool isES2 = this->supportsES2(); |
| 235 | |
| 236 | if (isDesktop == isES2) { |
| 237 | // must have one, don't support both in same interface |
| 238 | return false; |
| 239 | } |
| 240 | |
| 241 | // functions that are always required |
| 242 | if (NULL == fActiveTexture || |
| 243 | NULL == fAttachShader || |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 244 | NULL == fBindAttribLocation || |
| bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 245 | NULL == fBindBuffer || |
| 246 | NULL == fBindTexture || |
| 247 | NULL == fBlendFunc || |
| 248 | NULL == fBufferData || |
| 249 | NULL == fBufferSubData || |
| 250 | NULL == fClear || |
| 251 | NULL == fClearColor || |
| 252 | NULL == fClearStencil || |
| 253 | NULL == fColorMask || |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 254 | NULL == fCompileShader || |
| 255 | NULL == fCreateProgram || |
| 256 | NULL == fCreateShader || |
| bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 257 | NULL == fCullFace || |
| 258 | NULL == fDeleteBuffers || |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 259 | NULL == fDeleteProgram || |
| 260 | NULL == fDeleteShader || |
| bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 261 | NULL == fDeleteTextures || |
| 262 | NULL == fDepthMask || |
| 263 | NULL == fDisable || |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 264 | NULL == fDisableVertexAttribArray || |
| bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 265 | NULL == fDrawArrays || |
| 266 | NULL == fDrawElements || |
| 267 | NULL == fEnable || |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 268 | NULL == fEnableVertexAttribArray || |
| bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 269 | NULL == fFrontFace || |
| 270 | NULL == fGenBuffers || |
| 271 | NULL == fGenTextures || |
| 272 | NULL == fGetBufferParameteriv || |
| 273 | NULL == fGetError || |
| 274 | NULL == fGetIntegerv || |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 275 | NULL == fGetProgramInfoLog || |
| 276 | NULL == fGetProgramiv || |
| 277 | NULL == fGetShaderInfoLog || |
| 278 | NULL == fGetShaderiv || |
| bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 279 | NULL == fGetString || |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 280 | NULL == fGetUniformLocation || |
| 281 | NULL == fLinkProgram || |
| bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 282 | NULL == fPixelStorei || |
| 283 | NULL == fReadPixels || |
| 284 | NULL == fScissor || |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 285 | NULL == fShaderSource || |
| bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 286 | NULL == fStencilFunc || |
| 287 | NULL == fStencilMask || |
| 288 | NULL == fStencilOp || |
| 289 | NULL == fTexImage2D || |
| 290 | NULL == fTexParameteri || |
| 291 | NULL == fTexSubImage2D || |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 292 | NULL == fUniform1f || |
| 293 | NULL == fUniform1i || |
| 294 | NULL == fUniform1fv || |
| 295 | NULL == fUniform1iv || |
| 296 | NULL == fUniform2f || |
| 297 | NULL == fUniform2i || |
| 298 | NULL == fUniform2fv || |
| 299 | NULL == fUniform2iv || |
| 300 | NULL == fUniform3f || |
| 301 | NULL == fUniform3i || |
| 302 | NULL == fUniform3fv || |
| 303 | NULL == fUniform3iv || |
| 304 | NULL == fUniform4f || |
| 305 | NULL == fUniform4i || |
| 306 | NULL == fUniform4fv || |
| 307 | NULL == fUniform4iv || |
| 308 | NULL == fUniformMatrix2fv || |
| 309 | NULL == fUniformMatrix3fv || |
| 310 | NULL == fUniformMatrix4fv || |
| 311 | NULL == fUseProgram || |
| 312 | NULL == fVertexAttrib4fv || |
| bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 313 | NULL == fVertexAttribPointer || |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 314 | NULL == fViewport || |
| 315 | NULL == fBindFramebuffer || |
| 316 | NULL == fBindRenderbuffer || |
| 317 | NULL == fCheckFramebufferStatus || |
| 318 | NULL == fDeleteFramebuffers || |
| 319 | NULL == fDeleteRenderbuffers || |
| bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 320 | NULL == fFinish || |
| 321 | NULL == fFlush || |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 322 | NULL == fFramebufferRenderbuffer || |
| 323 | NULL == fFramebufferTexture2D || |
| bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame] | 324 | NULL == fGetFramebufferAttachmentParameteriv || |
| 325 | NULL == fGetRenderbufferParameteriv || |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 326 | NULL == fGenFramebuffers || |
| 327 | NULL == fGenRenderbuffers || |
| 328 | NULL == fRenderbufferStorage) { |
| 329 | return false; |
| 330 | } |
| 331 | |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 332 | const char* ext; |
| bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 333 | GrGLVersion glVer = GrGLGetVersion(this); |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 334 | ext = (const char*)fGetString(GR_GL_EXTENSIONS); |
| 335 | |
| 336 | // Now check that baseline ES/Desktop fns not covered above are present |
| 337 | // and that we have fn pointers for any advertised extensions that we will |
| 338 | // try to use. |
| 339 | |
| 340 | // these functions are part of ES2, we assume they are available |
| 341 | // On the desktop we assume they are available if the extension |
| 342 | // is present or GL version is high enough. |
| 343 | if ((kES2_GrGLBinding & fBindingsExported)) { |
| 344 | if (NULL == fBlendColor || |
| 345 | NULL == fStencilFuncSeparate || |
| 346 | NULL == fStencilMaskSeparate || |
| 347 | NULL == fStencilOpSeparate) { |
| 348 | return false; |
| 349 | } |
| 350 | } else if (kDesktop_GrGLBinding == fBindingsExported) { |
| bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 351 | if (glVer >= GR_GL_VER(2,0)) { |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 352 | if (NULL == fStencilFuncSeparate || |
| 353 | NULL == fStencilMaskSeparate || |
| 354 | NULL == fStencilOpSeparate) { |
| 355 | return false; |
| 356 | } |
| 357 | } |
| bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 358 | if (glVer >= GR_GL_VER(3,0) && NULL == fBindFragDataLocation) { |
| bsalomon@google.com | bc5cf51 | 2011-09-21 16:21:07 +0000 | [diff] [blame] | 359 | return false; |
| 360 | } |
| bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 361 | if (glVer >= GR_GL_VER(2,0) || |
| 362 | GrGLHasExtensionFromString("GL_ARB_draw_buffers", ext)) { |
| bsalomon@google.com | d32c5f5 | 2011-08-02 19:29:03 +0000 | [diff] [blame] | 363 | if (NULL == fDrawBuffers) { |
| 364 | return false; |
| 365 | } |
| 366 | } |
| bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 367 | if (glVer >= GR_GL_VER(1,4) || |
| 368 | GrGLHasExtensionFromString("GL_EXT_blend_color", ext)) { |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 369 | if (NULL == fBlendColor) { |
| 370 | return false; |
| 371 | } |
| 372 | } |
| bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 373 | if (glVer >= GR_GL_VER(1,5) || |
| 374 | GrGLHasExtensionFromString("GL_ARB_occlusion_query", ext)) { |
| 375 | if (NULL == fGenQueries || |
| 376 | NULL == fDeleteQueries || |
| 377 | NULL == fBeginQuery || |
| 378 | NULL == fEndQuery || |
| 379 | NULL == fGetQueryiv || |
| 380 | NULL == fGetQueryObjectiv || |
| 381 | NULL == fGetQueryObjectuiv) { |
| 382 | return false; |
| 383 | } |
| 384 | } |
| 385 | if (glVer >= GR_GL_VER(3,3) || |
| 386 | GrGLHasExtensionFromString("GL_ARB_timer_query", ext) || |
| 387 | GrGLHasExtensionFromString("GL_EXT_timer_query", ext)) { |
| 388 | if (NULL == fGetQueryObjecti64v || |
| 389 | NULL == fGetQueryObjectui64v) { |
| 390 | return false; |
| 391 | } |
| 392 | } |
| 393 | if (glVer >= GR_GL_VER(3,3) || |
| 394 | GrGLHasExtensionFromString("GL_ARB_timer_query", ext)) { |
| 395 | if (NULL == fQueryCounter) { |
| 396 | return false; |
| 397 | } |
| 398 | } |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | // optional function on desktop before 1.3 |
| 402 | if (kDesktop_GrGLBinding != fBindingsExported || |
| bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 403 | (glVer >= GR_GL_VER(1,3) || |
| 404 | GrGLHasExtensionFromString("GL_ARB_texture_compression", ext))) { |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 405 | if (NULL == fCompressedTexImage2D) { |
| 406 | return false; |
| 407 | } |
| 408 | } |
| 409 | |
| bsalomon@google.com | d32c5f5 | 2011-08-02 19:29:03 +0000 | [diff] [blame] | 410 | // part of desktop GL, but not ES |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 411 | if (kDesktop_GrGLBinding == fBindingsExported && |
| bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame] | 412 | (NULL == fLineWidth || |
| bsalomon@google.com | d32c5f5 | 2011-08-02 19:29:03 +0000 | [diff] [blame] | 413 | NULL == fGetTexLevelParameteriv || |
| bsalomon@google.com | c49d66b | 2011-08-03 14:22:30 +0000 | [diff] [blame] | 414 | NULL == fDrawBuffer || |
| 415 | NULL == fReadBuffer)) { |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 416 | return false; |
| 417 | } |
| bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame] | 418 | |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 419 | // FBO MSAA |
| 420 | if (kDesktop_GrGLBinding == fBindingsExported) { |
| 421 | // GL 3.0 and the ARB extension have multisample + blit |
| bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 422 | if (glVer >= GR_GL_VER(3,0) || GrGLHasExtensionFromString("GL_ARB_framebuffer_object", ext)) { |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 423 | if (NULL == fRenderbufferStorageMultisample || |
| 424 | NULL == fBlitFramebuffer) { |
| 425 | return false; |
| 426 | } |
| 427 | } else { |
| bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 428 | if (GrGLHasExtensionFromString("GL_EXT_framebuffer_blit", ext) && |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 429 | NULL == fBlitFramebuffer) { |
| 430 | return false; |
| 431 | } |
| bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 432 | if (GrGLHasExtensionFromString("GL_EXT_framebuffer_multisample", ext) && |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 433 | NULL == fRenderbufferStorageMultisample) { |
| 434 | return false; |
| 435 | } |
| 436 | } |
| 437 | } else { |
| bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 438 | if (GrGLHasExtensionFromString("GL_CHROMIUM_framebuffer_multisample", ext)) { |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 439 | if (NULL == fRenderbufferStorageMultisample || |
| 440 | NULL == fBlitFramebuffer) { |
| 441 | return false; |
| 442 | } |
| 443 | } |
| bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 444 | if (GrGLHasExtensionFromString("GL_APPLE_framebuffer_multisample", ext)) { |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 445 | if (NULL == fRenderbufferStorageMultisample || |
| 446 | NULL == fResolveMultisampleFramebuffer) { |
| 447 | return false; |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | // On ES buffer mapping is an extension. On Desktop |
| 453 | // buffer mapping was part of original VBO extension |
| 454 | // which we require. |
| 455 | if (kDesktop_GrGLBinding == fBindingsExported || |
| bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 456 | GrGLHasExtensionFromString("GL_OES_mapbuffer", ext)) { |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 457 | if (NULL == fMapBuffer || |
| 458 | NULL == fUnmapBuffer) { |
| 459 | return false; |
| 460 | } |
| 461 | } |
| 462 | |
| bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 463 | // Dual source blending |
| 464 | if (kDesktop_GrGLBinding == fBindingsExported && |
| bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 465 | (glVer >= GR_GL_VER(3,3) || |
| 466 | GrGLHasExtensionFromString("GL_ARB_blend_func_extended", ext))) { |
| bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 467 | if (NULL == fBindFragDataLocationIndexed) { |
| 468 | return false; |
| 469 | } |
| 470 | } |
| 471 | |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 472 | return true; |
| 473 | } |
| 474 | |