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; |
| 107 | fNPOTRenderTargetSupport = kProbe_GrGLCapability; |
| 108 | fMinRenderTargetHeight = kProbe_GrGLCapability; |
| 109 | fMinRenderTargetWidth = kProbe_GrGLCapability; |
| 110 | |
| 111 | fActiveTexture = NULL; |
| 112 | fAttachShader = NULL; |
bsalomon@google.com | f97c194 | 2011-10-19 21:35:26 +0000 | [diff] [blame^] | 113 | fBeginQuery = NULL; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 114 | fBindAttribLocation = NULL; |
| 115 | fBindBuffer = NULL; |
bsalomon@google.com | bc5cf51 | 2011-09-21 16:21:07 +0000 | [diff] [blame] | 116 | fBindFragDataLocation = NULL; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 117 | fBindTexture = NULL; |
| 118 | fBlendColor = NULL; |
| 119 | fBlendFunc = NULL; |
| 120 | fBufferData = NULL; |
| 121 | fBufferSubData = NULL; |
| 122 | fClear = NULL; |
| 123 | fClearColor = NULL; |
| 124 | fClearStencil = NULL; |
| 125 | fClientActiveTexture = NULL; |
| 126 | fColor4ub = NULL; |
| 127 | fColorMask = NULL; |
| 128 | fColorPointer = NULL; |
| 129 | fCompileShader = NULL; |
| 130 | fCompressedTexImage2D = NULL; |
| 131 | fCreateProgram = NULL; |
| 132 | fCreateShader = NULL; |
| 133 | fCullFace = NULL; |
| 134 | fDeleteBuffers = NULL; |
| 135 | fDeleteProgram = NULL; |
bsalomon@google.com | f97c194 | 2011-10-19 21:35:26 +0000 | [diff] [blame^] | 136 | fDeleteQueries = NULL; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 137 | fDeleteShader = NULL; |
| 138 | fDeleteTextures = NULL; |
| 139 | fDepthMask = NULL; |
| 140 | fDisable = NULL; |
| 141 | fDisableClientState = NULL; |
| 142 | fDisableVertexAttribArray = NULL; |
| 143 | fDrawArrays = NULL; |
| 144 | fDrawBuffer = NULL; |
| 145 | fDrawBuffers = NULL; |
| 146 | fDrawElements = NULL; |
bsalomon@google.com | f97c194 | 2011-10-19 21:35:26 +0000 | [diff] [blame^] | 147 | fEndQuery = NULL; |
| 148 | fFinish = NULL; |
| 149 | fFlush = NULL; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 150 | fEnable = NULL; |
| 151 | fEnableClientState = NULL; |
| 152 | fEnableVertexAttribArray = NULL; |
| 153 | fFrontFace = NULL; |
| 154 | fGenBuffers = NULL; |
bsalomon@google.com | f97c194 | 2011-10-19 21:35:26 +0000 | [diff] [blame^] | 155 | fGenQueries = NULL; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 156 | fGenTextures = NULL; |
| 157 | fGetBufferParameteriv = NULL; |
| 158 | fGetError = NULL; |
| 159 | fGetIntegerv = NULL; |
bsalomon@google.com | f97c194 | 2011-10-19 21:35:26 +0000 | [diff] [blame^] | 160 | fGetQueryiv = NULL; |
| 161 | fGetQueryObjecti64v = NULL; |
| 162 | fGetQueryObjectiv = NULL; |
| 163 | fGetQueryObjectui64v = NULL; |
| 164 | fGetQueryObjectuiv = NULL; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 165 | fGetProgramInfoLog = NULL; |
| 166 | fGetProgramiv = NULL; |
| 167 | fGetShaderInfoLog = NULL; |
| 168 | fGetShaderiv = NULL; |
| 169 | fGetString = NULL; |
| 170 | fGetTexLevelParameteriv = NULL; |
| 171 | fGetUniformLocation = NULL; |
| 172 | fLineWidth = NULL; |
| 173 | fLinkProgram = NULL; |
| 174 | fLoadMatrixf = NULL; |
| 175 | fMatrixMode = NULL; |
| 176 | fPixelStorei = NULL; |
| 177 | fPointSize = NULL; |
bsalomon@google.com | f97c194 | 2011-10-19 21:35:26 +0000 | [diff] [blame^] | 178 | fQueryCounter = NULL; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 179 | fReadBuffer = NULL; |
| 180 | fReadPixels = NULL; |
| 181 | fScissor = NULL; |
| 182 | fShadeModel = NULL; |
| 183 | fShaderSource = NULL; |
| 184 | fStencilFunc = NULL; |
| 185 | fStencilFuncSeparate = NULL; |
| 186 | fStencilMask = NULL; |
| 187 | fStencilMaskSeparate = NULL; |
| 188 | fStencilOp = NULL; |
| 189 | fStencilOpSeparate = NULL; |
| 190 | fTexCoordPointer = NULL; |
| 191 | fTexEnvi = NULL; |
| 192 | fTexImage2D = NULL; |
| 193 | fTexParameteri = NULL; |
| 194 | fTexSubImage2D = NULL; |
| 195 | fUniform1f = NULL; |
| 196 | fUniform1i = NULL; |
| 197 | fUniform1fv = NULL; |
| 198 | fUniform1iv = NULL; |
| 199 | fUniform2f = NULL; |
| 200 | fUniform2i = NULL; |
| 201 | fUniform2fv = NULL; |
| 202 | fUniform2iv = NULL; |
| 203 | fUniform3f = NULL; |
| 204 | fUniform3i = NULL; |
| 205 | fUniform3fv = NULL; |
| 206 | fUniform3iv = NULL; |
| 207 | fUniform4f = NULL; |
| 208 | fUniform4i = NULL; |
| 209 | fUniform4fv = NULL; |
| 210 | fUniform4iv = NULL; |
| 211 | fUniformMatrix2fv = NULL; |
| 212 | fUniformMatrix3fv = NULL; |
| 213 | fUniformMatrix4fv = NULL; |
| 214 | fUseProgram = NULL; |
| 215 | fVertexAttrib4fv = NULL; |
| 216 | fVertexAttribPointer = NULL; |
| 217 | fVertexPointer = NULL; |
| 218 | fViewport = NULL; |
| 219 | fBindFramebuffer = NULL; |
| 220 | fBindRenderbuffer = NULL; |
| 221 | fCheckFramebufferStatus = NULL; |
| 222 | fDeleteFramebuffers = NULL; |
| 223 | fDeleteRenderbuffers = NULL; |
| 224 | fFramebufferRenderbuffer = NULL; |
| 225 | fFramebufferTexture2D = NULL; |
| 226 | fGenFramebuffers = NULL; |
| 227 | fGenRenderbuffers = NULL; |
| 228 | fGetFramebufferAttachmentParameteriv = NULL; |
| 229 | fGetRenderbufferParameteriv = NULL; |
| 230 | fRenderbufferStorage = NULL; |
| 231 | fRenderbufferStorageMultisample = NULL; |
| 232 | fBlitFramebuffer = NULL; |
| 233 | fResolveMultisampleFramebuffer = NULL; |
| 234 | fMapBuffer = NULL; |
| 235 | fUnmapBuffer = NULL; |
| 236 | fBindFragDataLocationIndexed = NULL; |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 237 | |
| 238 | #if GR_GL_PER_GL_FUNC_CALLBACK |
| 239 | fCallback = GrGLDefaultInterfaceCallback; |
| 240 | fCallbackData = 0; |
| 241 | #endif |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 245 | bool GrGLInterface::validateShaderFunctions() const { |
| 246 | // required for GrGpuGLShaders |
| 247 | if (NULL == fAttachShader || |
| 248 | NULL == fBindAttribLocation || |
| 249 | NULL == fCompileShader || |
| 250 | NULL == fCreateProgram || |
| 251 | NULL == fCreateShader || |
| 252 | NULL == fDeleteProgram || |
| 253 | NULL == fDeleteShader || |
| 254 | NULL == fDisableVertexAttribArray || |
| 255 | NULL == fEnableVertexAttribArray || |
| 256 | NULL == fGetProgramInfoLog || |
| 257 | NULL == fGetProgramiv || |
| 258 | NULL == fGetShaderInfoLog || |
| 259 | NULL == fGetShaderiv || |
| 260 | NULL == fGetUniformLocation || |
| 261 | NULL == fLinkProgram || |
| 262 | NULL == fShaderSource || |
| 263 | NULL == fUniform1f || |
| 264 | NULL == fUniform1i || |
| 265 | NULL == fUniform1fv || |
| 266 | NULL == fUniform1iv || |
| 267 | NULL == fUniform2f || |
| 268 | NULL == fUniform2i || |
| 269 | NULL == fUniform2fv || |
| 270 | NULL == fUniform2iv || |
| 271 | NULL == fUniform3f || |
| 272 | NULL == fUniform3i || |
| 273 | NULL == fUniform3fv || |
| 274 | NULL == fUniform3iv || |
| 275 | NULL == fUniform4f || |
| 276 | NULL == fUniform4i || |
| 277 | NULL == fUniform4fv || |
| 278 | NULL == fUniform4iv || |
| 279 | NULL == fUniformMatrix2fv || |
| 280 | NULL == fUniformMatrix3fv || |
| 281 | NULL == fUniformMatrix4fv || |
| 282 | NULL == fUseProgram || |
| 283 | NULL == fVertexAttrib4fv || |
| 284 | NULL == fVertexAttribPointer) { |
| 285 | return false; |
| 286 | } |
| 287 | return true; |
| 288 | } |
| 289 | |
| 290 | bool GrGLInterface::validateFixedFunctions() const { |
| 291 | if (NULL == fClientActiveTexture || |
| 292 | NULL == fColor4ub || |
| 293 | NULL == fColorPointer || |
| 294 | NULL == fDisableClientState || |
| 295 | NULL == fEnableClientState || |
| 296 | NULL == fLoadMatrixf || |
| 297 | NULL == fMatrixMode || |
| 298 | NULL == fPointSize || |
| 299 | NULL == fShadeModel || |
| 300 | NULL == fTexCoordPointer || |
bsalomon@google.com | 4b9b6a2 | 2011-05-04 15:01:16 +0000 | [diff] [blame] | 301 | NULL == fTexEnvi || |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 302 | NULL == fVertexPointer) { |
| 303 | return false; |
| 304 | } |
| 305 | return true; |
| 306 | } |
| 307 | |
| 308 | bool GrGLInterface::validate(GrEngine engine) const { |
| 309 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 310 | bool isDesktop = this->supportsDesktop(); |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 311 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 312 | bool isES = this->supportsES(); |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 313 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 314 | if (isDesktop == isES) { |
| 315 | // must have one, don't support both in same interface |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 316 | return false; |
| 317 | } |
| 318 | |
| 319 | // functions that are always required |
| 320 | if (NULL == fActiveTexture || |
| 321 | NULL == fBindBuffer || |
| 322 | NULL == fBindTexture || |
| 323 | NULL == fBlendFunc || |
| 324 | NULL == fBufferData || |
| 325 | NULL == fBufferSubData || |
| 326 | NULL == fClear || |
| 327 | NULL == fClearColor || |
| 328 | NULL == fClearStencil || |
| 329 | NULL == fColorMask || |
| 330 | NULL == fCullFace || |
| 331 | NULL == fDeleteBuffers || |
| 332 | NULL == fDeleteTextures || |
| 333 | NULL == fDepthMask || |
| 334 | NULL == fDisable || |
| 335 | NULL == fDrawArrays || |
| 336 | NULL == fDrawElements || |
| 337 | NULL == fEnable || |
| 338 | NULL == fFrontFace || |
| 339 | NULL == fGenBuffers || |
| 340 | NULL == fGenTextures || |
| 341 | NULL == fGetBufferParameteriv || |
| 342 | NULL == fGetError || |
| 343 | NULL == fGetIntegerv || |
| 344 | NULL == fGetString || |
| 345 | NULL == fPixelStorei || |
| 346 | NULL == fReadPixels || |
| 347 | NULL == fScissor || |
| 348 | NULL == fStencilFunc || |
| 349 | NULL == fStencilMask || |
| 350 | NULL == fStencilOp || |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 351 | NULL == fTexImage2D || |
| 352 | NULL == fTexParameteri || |
| 353 | NULL == fTexSubImage2D || |
| 354 | NULL == fViewport || |
| 355 | NULL == fBindFramebuffer || |
| 356 | NULL == fBindRenderbuffer || |
| 357 | NULL == fCheckFramebufferStatus || |
| 358 | NULL == fDeleteFramebuffers || |
| 359 | NULL == fDeleteRenderbuffers || |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 360 | NULL == fFinish || |
| 361 | NULL == fFlush || |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 362 | NULL == fFramebufferRenderbuffer || |
| 363 | NULL == fFramebufferTexture2D || |
bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame] | 364 | NULL == fGetFramebufferAttachmentParameteriv || |
| 365 | NULL == fGetRenderbufferParameteriv || |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 366 | NULL == fGenFramebuffers || |
| 367 | NULL == fGenRenderbuffers || |
| 368 | NULL == fRenderbufferStorage) { |
| 369 | return false; |
| 370 | } |
| 371 | |
| 372 | switch (engine) { |
| 373 | case kOpenGL_Shaders_GrEngine: |
| 374 | if (kES1_GrGLBinding == fBindingsExported) { |
| 375 | return false; |
| 376 | } |
| 377 | if (!this->validateShaderFunctions()) { |
| 378 | return false; |
| 379 | } |
| 380 | break; |
| 381 | case kOpenGL_Fixed_GrEngine: |
| 382 | if (kES1_GrGLBinding == fBindingsExported) { |
| 383 | return false; |
| 384 | } |
| 385 | if (!this->validateFixedFunctions()) { |
| 386 | return false; |
| 387 | } |
| 388 | break; |
| 389 | default: |
| 390 | return false; |
| 391 | } |
| 392 | |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 393 | const char* ext; |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 394 | GrGLVersion glVer = GrGLGetVersion(this); |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 395 | ext = (const char*)fGetString(GR_GL_EXTENSIONS); |
| 396 | |
| 397 | // Now check that baseline ES/Desktop fns not covered above are present |
| 398 | // and that we have fn pointers for any advertised extensions that we will |
| 399 | // try to use. |
| 400 | |
| 401 | // these functions are part of ES2, we assume they are available |
| 402 | // On the desktop we assume they are available if the extension |
| 403 | // is present or GL version is high enough. |
| 404 | if ((kES2_GrGLBinding & fBindingsExported)) { |
| 405 | if (NULL == fBlendColor || |
| 406 | NULL == fStencilFuncSeparate || |
| 407 | NULL == fStencilMaskSeparate || |
| 408 | NULL == fStencilOpSeparate) { |
| 409 | return false; |
| 410 | } |
| 411 | } else if (kDesktop_GrGLBinding == fBindingsExported) { |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 412 | if (glVer >= GR_GL_VER(2,0)) { |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 413 | if (NULL == fStencilFuncSeparate || |
| 414 | NULL == fStencilMaskSeparate || |
| 415 | NULL == fStencilOpSeparate) { |
| 416 | return false; |
| 417 | } |
| 418 | } |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 419 | if (glVer >= GR_GL_VER(3,0) && NULL == fBindFragDataLocation) { |
bsalomon@google.com | bc5cf51 | 2011-09-21 16:21:07 +0000 | [diff] [blame] | 420 | return false; |
| 421 | } |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 422 | if (glVer >= GR_GL_VER(2,0) || |
| 423 | GrGLHasExtensionFromString("GL_ARB_draw_buffers", ext)) { |
bsalomon@google.com | d32c5f5 | 2011-08-02 19:29:03 +0000 | [diff] [blame] | 424 | if (NULL == fDrawBuffers) { |
| 425 | return false; |
| 426 | } |
| 427 | } |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 428 | if (glVer >= GR_GL_VER(1,4) || |
| 429 | GrGLHasExtensionFromString("GL_EXT_blend_color", ext)) { |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 430 | if (NULL == fBlendColor) { |
| 431 | return false; |
| 432 | } |
| 433 | } |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 434 | if (glVer >= GR_GL_VER(1,5) || |
| 435 | GrGLHasExtensionFromString("GL_ARB_occlusion_query", ext)) { |
| 436 | if (NULL == fGenQueries || |
| 437 | NULL == fDeleteQueries || |
| 438 | NULL == fBeginQuery || |
| 439 | NULL == fEndQuery || |
| 440 | NULL == fGetQueryiv || |
| 441 | NULL == fGetQueryObjectiv || |
| 442 | NULL == fGetQueryObjectuiv) { |
| 443 | return false; |
| 444 | } |
| 445 | } |
| 446 | if (glVer >= GR_GL_VER(3,3) || |
| 447 | GrGLHasExtensionFromString("GL_ARB_timer_query", ext) || |
| 448 | GrGLHasExtensionFromString("GL_EXT_timer_query", ext)) { |
| 449 | if (NULL == fGetQueryObjecti64v || |
| 450 | NULL == fGetQueryObjectui64v) { |
| 451 | return false; |
| 452 | } |
| 453 | } |
| 454 | if (glVer >= GR_GL_VER(3,3) || |
| 455 | GrGLHasExtensionFromString("GL_ARB_timer_query", ext)) { |
| 456 | if (NULL == fQueryCounter) { |
| 457 | return false; |
| 458 | } |
| 459 | } |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | // optional function on desktop before 1.3 |
| 463 | if (kDesktop_GrGLBinding != fBindingsExported || |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 464 | (glVer >= GR_GL_VER(1,3) || |
| 465 | GrGLHasExtensionFromString("GL_ARB_texture_compression", ext))) { |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 466 | if (NULL == fCompressedTexImage2D) { |
| 467 | return false; |
| 468 | } |
| 469 | } |
| 470 | |
bsalomon@google.com | d32c5f5 | 2011-08-02 19:29:03 +0000 | [diff] [blame] | 471 | // part of desktop GL, but not ES |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 472 | if (kDesktop_GrGLBinding == fBindingsExported && |
bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame] | 473 | (NULL == fLineWidth || |
bsalomon@google.com | d32c5f5 | 2011-08-02 19:29:03 +0000 | [diff] [blame] | 474 | NULL == fGetTexLevelParameteriv || |
bsalomon@google.com | c49d66b | 2011-08-03 14:22:30 +0000 | [diff] [blame] | 475 | NULL == fDrawBuffer || |
| 476 | NULL == fReadBuffer)) { |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 477 | return false; |
| 478 | } |
bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame] | 479 | |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 480 | // FBO MSAA |
| 481 | if (kDesktop_GrGLBinding == fBindingsExported) { |
| 482 | // GL 3.0 and the ARB extension have multisample + blit |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 483 | 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] | 484 | if (NULL == fRenderbufferStorageMultisample || |
| 485 | NULL == fBlitFramebuffer) { |
| 486 | return false; |
| 487 | } |
| 488 | } else { |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 489 | if (GrGLHasExtensionFromString("GL_EXT_framebuffer_blit", ext) && |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 490 | NULL == fBlitFramebuffer) { |
| 491 | return false; |
| 492 | } |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 493 | if (GrGLHasExtensionFromString("GL_EXT_framebuffer_multisample", ext) && |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 494 | NULL == fRenderbufferStorageMultisample) { |
| 495 | return false; |
| 496 | } |
| 497 | } |
| 498 | } else { |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 499 | if (GrGLHasExtensionFromString("GL_CHROMIUM_framebuffer_multisample", ext)) { |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 500 | if (NULL == fRenderbufferStorageMultisample || |
| 501 | NULL == fBlitFramebuffer) { |
| 502 | return false; |
| 503 | } |
| 504 | } |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 505 | if (GrGLHasExtensionFromString("GL_APPLE_framebuffer_multisample", ext)) { |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 506 | if (NULL == fRenderbufferStorageMultisample || |
| 507 | NULL == fResolveMultisampleFramebuffer) { |
| 508 | return false; |
| 509 | } |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | // On ES buffer mapping is an extension. On Desktop |
| 514 | // buffer mapping was part of original VBO extension |
| 515 | // which we require. |
| 516 | if (kDesktop_GrGLBinding == fBindingsExported || |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 517 | GrGLHasExtensionFromString("GL_OES_mapbuffer", ext)) { |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 518 | if (NULL == fMapBuffer || |
| 519 | NULL == fUnmapBuffer) { |
| 520 | return false; |
| 521 | } |
| 522 | } |
| 523 | |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 524 | // Dual source blending |
| 525 | if (kDesktop_GrGLBinding == fBindingsExported && |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 526 | (glVer >= GR_GL_VER(3,3) || |
| 527 | GrGLHasExtensionFromString("GL_ARB_blend_func_extended", ext))) { |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 528 | if (NULL == fBindFragDataLocationIndexed) { |
| 529 | return false; |
| 530 | } |
| 531 | } |
| 532 | |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 533 | return true; |
| 534 | } |
| 535 | |