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; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame^] | 181 | fTexStorage2D = NULL; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 182 | fTexSubImage2D = NULL; |
| 183 | fUniform1f = NULL; |
| 184 | fUniform1i = NULL; |
| 185 | fUniform1fv = NULL; |
| 186 | fUniform1iv = NULL; |
| 187 | fUniform2f = NULL; |
| 188 | fUniform2i = NULL; |
| 189 | fUniform2fv = NULL; |
| 190 | fUniform2iv = NULL; |
| 191 | fUniform3f = NULL; |
| 192 | fUniform3i = NULL; |
| 193 | fUniform3fv = NULL; |
| 194 | fUniform3iv = NULL; |
| 195 | fUniform4f = NULL; |
| 196 | fUniform4i = NULL; |
| 197 | fUniform4fv = NULL; |
| 198 | fUniform4iv = NULL; |
| 199 | fUniformMatrix2fv = NULL; |
| 200 | fUniformMatrix3fv = NULL; |
| 201 | fUniformMatrix4fv = NULL; |
| 202 | fUseProgram = NULL; |
| 203 | fVertexAttrib4fv = NULL; |
| 204 | fVertexAttribPointer = NULL; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 205 | fViewport = NULL; |
| 206 | fBindFramebuffer = NULL; |
| 207 | fBindRenderbuffer = NULL; |
| 208 | fCheckFramebufferStatus = NULL; |
| 209 | fDeleteFramebuffers = NULL; |
| 210 | fDeleteRenderbuffers = NULL; |
| 211 | fFramebufferRenderbuffer = NULL; |
| 212 | fFramebufferTexture2D = NULL; |
| 213 | fGenFramebuffers = NULL; |
| 214 | fGenRenderbuffers = NULL; |
| 215 | fGetFramebufferAttachmentParameteriv = NULL; |
| 216 | fGetRenderbufferParameteriv = NULL; |
| 217 | fRenderbufferStorage = NULL; |
| 218 | fRenderbufferStorageMultisample = NULL; |
| 219 | fBlitFramebuffer = NULL; |
| 220 | fResolveMultisampleFramebuffer = NULL; |
| 221 | fMapBuffer = NULL; |
| 222 | fUnmapBuffer = NULL; |
| 223 | fBindFragDataLocationIndexed = NULL; |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 224 | |
| 225 | #if GR_GL_PER_GL_FUNC_CALLBACK |
| 226 | fCallback = GrGLDefaultInterfaceCallback; |
| 227 | fCallbackData = 0; |
| 228 | #endif |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 229 | } |
| 230 | |
bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 231 | bool GrGLInterface::validate() const { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 232 | |
bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 233 | bool isDesktop = this->supportsDesktop(); |
| 234 | |
| 235 | bool isES2 = this->supportsES2(); |
| 236 | |
| 237 | if (isDesktop == isES2) { |
| 238 | // must have one, don't support both in same interface |
| 239 | return false; |
| 240 | } |
| 241 | |
| 242 | // functions that are always required |
| 243 | if (NULL == fActiveTexture || |
| 244 | NULL == fAttachShader || |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 245 | NULL == fBindAttribLocation || |
bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 246 | NULL == fBindBuffer || |
| 247 | NULL == fBindTexture || |
| 248 | NULL == fBlendFunc || |
| 249 | NULL == fBufferData || |
| 250 | NULL == fBufferSubData || |
| 251 | NULL == fClear || |
| 252 | NULL == fClearColor || |
| 253 | NULL == fClearStencil || |
| 254 | NULL == fColorMask || |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 255 | NULL == fCompileShader || |
| 256 | NULL == fCreateProgram || |
| 257 | NULL == fCreateShader || |
bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 258 | NULL == fCullFace || |
| 259 | NULL == fDeleteBuffers || |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 260 | NULL == fDeleteProgram || |
| 261 | NULL == fDeleteShader || |
bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 262 | NULL == fDeleteTextures || |
| 263 | NULL == fDepthMask || |
| 264 | NULL == fDisable || |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 265 | NULL == fDisableVertexAttribArray || |
bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 266 | NULL == fDrawArrays || |
| 267 | NULL == fDrawElements || |
| 268 | NULL == fEnable || |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 269 | NULL == fEnableVertexAttribArray || |
bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 270 | NULL == fFrontFace || |
| 271 | NULL == fGenBuffers || |
| 272 | NULL == fGenTextures || |
| 273 | NULL == fGetBufferParameteriv || |
| 274 | NULL == fGetError || |
| 275 | NULL == fGetIntegerv || |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 276 | NULL == fGetProgramInfoLog || |
| 277 | NULL == fGetProgramiv || |
| 278 | NULL == fGetShaderInfoLog || |
| 279 | NULL == fGetShaderiv || |
bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 280 | NULL == fGetString || |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 281 | NULL == fGetUniformLocation || |
| 282 | NULL == fLinkProgram || |
bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 283 | NULL == fPixelStorei || |
| 284 | NULL == fReadPixels || |
| 285 | NULL == fScissor || |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 286 | NULL == fShaderSource || |
bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 287 | NULL == fStencilFunc || |
| 288 | NULL == fStencilMask || |
| 289 | NULL == fStencilOp || |
| 290 | NULL == fTexImage2D || |
| 291 | NULL == fTexParameteri || |
| 292 | NULL == fTexSubImage2D || |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 293 | NULL == fUniform1f || |
| 294 | NULL == fUniform1i || |
| 295 | NULL == fUniform1fv || |
| 296 | NULL == fUniform1iv || |
| 297 | NULL == fUniform2f || |
| 298 | NULL == fUniform2i || |
| 299 | NULL == fUniform2fv || |
| 300 | NULL == fUniform2iv || |
| 301 | NULL == fUniform3f || |
| 302 | NULL == fUniform3i || |
| 303 | NULL == fUniform3fv || |
| 304 | NULL == fUniform3iv || |
| 305 | NULL == fUniform4f || |
| 306 | NULL == fUniform4i || |
| 307 | NULL == fUniform4fv || |
| 308 | NULL == fUniform4iv || |
| 309 | NULL == fUniformMatrix2fv || |
| 310 | NULL == fUniformMatrix3fv || |
| 311 | NULL == fUniformMatrix4fv || |
| 312 | NULL == fUseProgram || |
| 313 | NULL == fVertexAttrib4fv || |
bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 314 | NULL == fVertexAttribPointer || |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 315 | NULL == fViewport || |
| 316 | NULL == fBindFramebuffer || |
| 317 | NULL == fBindRenderbuffer || |
| 318 | NULL == fCheckFramebufferStatus || |
| 319 | NULL == fDeleteFramebuffers || |
| 320 | NULL == fDeleteRenderbuffers || |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 321 | NULL == fFinish || |
| 322 | NULL == fFlush || |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 323 | NULL == fFramebufferRenderbuffer || |
| 324 | NULL == fFramebufferTexture2D || |
bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame] | 325 | NULL == fGetFramebufferAttachmentParameteriv || |
| 326 | NULL == fGetRenderbufferParameteriv || |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 327 | NULL == fGenFramebuffers || |
| 328 | NULL == fGenRenderbuffers || |
| 329 | NULL == fRenderbufferStorage) { |
| 330 | return false; |
| 331 | } |
| 332 | |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 333 | const char* ext; |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 334 | GrGLVersion glVer = GrGLGetVersion(this); |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 335 | ext = (const char*)fGetString(GR_GL_EXTENSIONS); |
| 336 | |
| 337 | // Now check that baseline ES/Desktop fns not covered above are present |
| 338 | // and that we have fn pointers for any advertised extensions that we will |
| 339 | // try to use. |
| 340 | |
| 341 | // these functions are part of ES2, we assume they are available |
| 342 | // On the desktop we assume they are available if the extension |
| 343 | // is present or GL version is high enough. |
| 344 | if ((kES2_GrGLBinding & fBindingsExported)) { |
| 345 | if (NULL == fBlendColor || |
| 346 | NULL == fStencilFuncSeparate || |
| 347 | NULL == fStencilMaskSeparate || |
| 348 | NULL == fStencilOpSeparate) { |
| 349 | return false; |
| 350 | } |
| 351 | } else if (kDesktop_GrGLBinding == fBindingsExported) { |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 352 | if (glVer >= GR_GL_VER(2,0)) { |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 353 | if (NULL == fStencilFuncSeparate || |
| 354 | NULL == fStencilMaskSeparate || |
| 355 | NULL == fStencilOpSeparate) { |
| 356 | return false; |
| 357 | } |
| 358 | } |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 359 | if (glVer >= GR_GL_VER(3,0) && NULL == fBindFragDataLocation) { |
bsalomon@google.com | bc5cf51 | 2011-09-21 16:21:07 +0000 | [diff] [blame] | 360 | return false; |
| 361 | } |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 362 | if (glVer >= GR_GL_VER(2,0) || |
| 363 | GrGLHasExtensionFromString("GL_ARB_draw_buffers", ext)) { |
bsalomon@google.com | d32c5f5 | 2011-08-02 19:29:03 +0000 | [diff] [blame] | 364 | if (NULL == fDrawBuffers) { |
| 365 | return false; |
| 366 | } |
| 367 | } |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 368 | if (glVer >= GR_GL_VER(1,4) || |
| 369 | GrGLHasExtensionFromString("GL_EXT_blend_color", ext)) { |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 370 | if (NULL == fBlendColor) { |
| 371 | return false; |
| 372 | } |
| 373 | } |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 374 | if (glVer >= GR_GL_VER(1,5) || |
| 375 | GrGLHasExtensionFromString("GL_ARB_occlusion_query", ext)) { |
| 376 | if (NULL == fGenQueries || |
| 377 | NULL == fDeleteQueries || |
| 378 | NULL == fBeginQuery || |
| 379 | NULL == fEndQuery || |
| 380 | NULL == fGetQueryiv || |
| 381 | NULL == fGetQueryObjectiv || |
| 382 | NULL == fGetQueryObjectuiv) { |
| 383 | return false; |
| 384 | } |
| 385 | } |
| 386 | if (glVer >= GR_GL_VER(3,3) || |
| 387 | GrGLHasExtensionFromString("GL_ARB_timer_query", ext) || |
| 388 | GrGLHasExtensionFromString("GL_EXT_timer_query", ext)) { |
| 389 | if (NULL == fGetQueryObjecti64v || |
| 390 | NULL == fGetQueryObjectui64v) { |
| 391 | return false; |
| 392 | } |
| 393 | } |
| 394 | if (glVer >= GR_GL_VER(3,3) || |
| 395 | GrGLHasExtensionFromString("GL_ARB_timer_query", ext)) { |
| 396 | if (NULL == fQueryCounter) { |
| 397 | return false; |
| 398 | } |
| 399 | } |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | // optional function on desktop before 1.3 |
| 403 | if (kDesktop_GrGLBinding != fBindingsExported || |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 404 | (glVer >= GR_GL_VER(1,3) || |
| 405 | GrGLHasExtensionFromString("GL_ARB_texture_compression", ext))) { |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 406 | if (NULL == fCompressedTexImage2D) { |
| 407 | return false; |
| 408 | } |
| 409 | } |
| 410 | |
bsalomon@google.com | d32c5f5 | 2011-08-02 19:29:03 +0000 | [diff] [blame] | 411 | // part of desktop GL, but not ES |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 412 | if (kDesktop_GrGLBinding == fBindingsExported && |
bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame] | 413 | (NULL == fLineWidth || |
bsalomon@google.com | d32c5f5 | 2011-08-02 19:29:03 +0000 | [diff] [blame] | 414 | NULL == fGetTexLevelParameteriv || |
bsalomon@google.com | c49d66b | 2011-08-03 14:22:30 +0000 | [diff] [blame] | 415 | NULL == fDrawBuffer || |
| 416 | NULL == fReadBuffer)) { |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 417 | return false; |
| 418 | } |
bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame] | 419 | |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame^] | 420 | // GL_EXT_texture_storage is part of desktop 4.2 |
| 421 | // There is a desktop ARB extension and an ES+desktop EXT extension |
| 422 | if ((kDesktop_GrGLBinding == fBindingsExported && |
| 423 | (glVer >= GR_GL_VER(4,2)) || |
| 424 | GrGLHasExtensionFromString("GL_ARB_texture_storage", ext)) || |
| 425 | GrGLHasExtensionFromString("GL_EXT_texture_storage", ext)) { |
| 426 | } |
| 427 | |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 428 | // FBO MSAA |
| 429 | if (kDesktop_GrGLBinding == fBindingsExported) { |
| 430 | // GL 3.0 and the ARB extension have multisample + blit |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 431 | 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] | 432 | if (NULL == fRenderbufferStorageMultisample || |
| 433 | NULL == fBlitFramebuffer) { |
| 434 | return false; |
| 435 | } |
| 436 | } else { |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 437 | if (GrGLHasExtensionFromString("GL_EXT_framebuffer_blit", ext) && |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 438 | NULL == fBlitFramebuffer) { |
| 439 | return false; |
| 440 | } |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 441 | if (GrGLHasExtensionFromString("GL_EXT_framebuffer_multisample", ext) && |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 442 | NULL == fRenderbufferStorageMultisample) { |
| 443 | return false; |
| 444 | } |
| 445 | } |
| 446 | } else { |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 447 | if (GrGLHasExtensionFromString("GL_CHROMIUM_framebuffer_multisample", ext)) { |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 448 | if (NULL == fRenderbufferStorageMultisample || |
| 449 | NULL == fBlitFramebuffer) { |
| 450 | return false; |
| 451 | } |
| 452 | } |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 453 | if (GrGLHasExtensionFromString("GL_APPLE_framebuffer_multisample", ext)) { |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 454 | if (NULL == fRenderbufferStorageMultisample || |
| 455 | NULL == fResolveMultisampleFramebuffer) { |
| 456 | return false; |
| 457 | } |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | // On ES buffer mapping is an extension. On Desktop |
| 462 | // buffer mapping was part of original VBO extension |
| 463 | // which we require. |
| 464 | if (kDesktop_GrGLBinding == fBindingsExported || |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 465 | GrGLHasExtensionFromString("GL_OES_mapbuffer", ext)) { |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 466 | if (NULL == fMapBuffer || |
| 467 | NULL == fUnmapBuffer) { |
| 468 | return false; |
| 469 | } |
| 470 | } |
| 471 | |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 472 | // Dual source blending |
| 473 | if (kDesktop_GrGLBinding == fBindingsExported && |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 474 | (glVer >= GR_GL_VER(3,3) || |
| 475 | GrGLHasExtensionFromString("GL_ARB_blend_func_extended", ext))) { |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 476 | if (NULL == fBindFragDataLocationIndexed) { |
| 477 | return false; |
| 478 | } |
| 479 | } |
| 480 | |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 481 | return true; |
| 482 | } |
| 483 | |