blob: 38a7f9d7f43e874bc051cbfceef6091c2e611746 [file] [log] [blame]
twiz@google.com59a190b2011-03-14 21:23:01 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
twiz@google.com59a190b2011-03-14 21:23:01 +00006 */
7
8
tomhudson@google.com6bf38b52012-02-14 15:11:59 +00009#include "gl/GrGLInterface.h"
bsalomon@google.com1744f972013-02-26 21:46:32 +000010#include "gl/GrGLExtensions.h"
11#include "gl/GrGLUtil.h"
twiz@google.com59a190b2011-03-14 21:23:01 +000012
13#include <stdio.h>
14
robertphillips@google.com15e9d3e2012-06-21 20:25:03 +000015SK_DEFINE_INST_COUNT(GrGLInterface)
16
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +000017#if GR_GL_PER_GL_FUNC_CALLBACK
18namespace {
19void GrGLDefaultInterfaceCallback(const GrGLInterface*) {}
20}
21#endif
22
bsalomon@google.com0b77d682011-08-19 13:28:54 +000023GrGLInterface::GrGLInterface() {
bsalomon@google.com89ec61e2012-02-10 20:05:18 +000024 fBindingsExported = kNone_GrGLBinding;
bsalomon@google.com0b77d682011-08-19 13:28:54 +000025
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +000026#if GR_GL_PER_GL_FUNC_CALLBACK
27 fCallback = GrGLDefaultInterfaceCallback;
28 fCallbackData = 0;
29#endif
bsalomon@google.com0b77d682011-08-19 13:28:54 +000030}
31
bsalomon@google.com89ec61e2012-02-10 20:05:18 +000032bool GrGLInterface::validate(GrGLBinding binding) const {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000033
bsalomon@google.com89ec61e2012-02-10 20:05:18 +000034 // kNone must be 0 so that the check we're about to do can never succeed if
35 // binding == kNone.
36 GR_STATIC_ASSERT(kNone_GrGLBinding == 0);
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000037
bsalomon@google.com89ec61e2012-02-10 20:05:18 +000038 if (0 == (binding & fBindingsExported)) {
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000039 return false;
40 }
skia.committer@gmail.com12eea2b2013-02-27 07:10:10 +000041
bsalomon@google.com1744f972013-02-26 21:46:32 +000042 GrGLExtensions extensions;
43 if (!extensions.init(binding, this)) {
44 return false;
45 }
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000046
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000047 bool isCoreProfile = false;
48 if (kDesktop_GrGLBinding == binding) {
49 if (NULL == this->fGetIntegerv) {
50 return false;
51 }
52 GrGLint profileMask = 0;
53 fGetIntegerv(GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
54 isCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
55 }
56
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000057 // functions that are always required
58 if (NULL == fActiveTexture ||
59 NULL == fAttachShader ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000060 NULL == fBindAttribLocation ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000061 NULL == fBindBuffer ||
62 NULL == fBindTexture ||
63 NULL == fBlendFunc ||
robertphillips@google.come7884302012-04-18 14:39:58 +000064 NULL == fBlendColor || // -> GL >= 1.4, ES >= 2.0 or extension
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000065 NULL == fBufferData ||
66 NULL == fBufferSubData ||
67 NULL == fClear ||
68 NULL == fClearColor ||
69 NULL == fClearStencil ||
70 NULL == fColorMask ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000071 NULL == fCompileShader ||
commit-bot@chromium.org98168bb2013-04-11 22:00:34 +000072 NULL == fCopyTexSubImage2D ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000073 NULL == fCreateProgram ||
74 NULL == fCreateShader ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000075 NULL == fCullFace ||
76 NULL == fDeleteBuffers ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000077 NULL == fDeleteProgram ||
78 NULL == fDeleteShader ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000079 NULL == fDeleteTextures ||
80 NULL == fDepthMask ||
81 NULL == fDisable ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000082 NULL == fDisableVertexAttribArray ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000083 NULL == fDrawArrays ||
84 NULL == fDrawElements ||
85 NULL == fEnable ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000086 NULL == fEnableVertexAttribArray ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000087 NULL == fFrontFace ||
88 NULL == fGenBuffers ||
89 NULL == fGenTextures ||
90 NULL == fGetBufferParameteriv ||
commit-bot@chromium.orgcffff792013-07-26 16:36:04 +000091#ifndef SKIA_IGNORE_GPU_MIPMAPS
92 NULL == fGenerateMipmap ||
93#endif
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000094 NULL == fGetError ||
95 NULL == fGetIntegerv ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000096 NULL == fGetProgramInfoLog ||
97 NULL == fGetProgramiv ||
98 NULL == fGetShaderInfoLog ||
99 NULL == fGetShaderiv ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +0000100 NULL == fGetString ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000101 NULL == fGetUniformLocation ||
102 NULL == fLinkProgram ||
commit-bot@chromium.org941df4f2013-08-20 20:54:08 +0000103 NULL == fLineWidth ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +0000104 NULL == fPixelStorei ||
105 NULL == fReadPixels ||
106 NULL == fScissor ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000107 NULL == fShaderSource ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +0000108 NULL == fStencilFunc ||
109 NULL == fStencilMask ||
110 NULL == fStencilOp ||
111 NULL == fTexImage2D ||
112 NULL == fTexParameteri ||
bsalomon@google.com4d063de2012-05-31 17:59:23 +0000113 NULL == fTexParameteriv ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +0000114 NULL == fTexSubImage2D ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000115 NULL == fUniform1f ||
116 NULL == fUniform1i ||
117 NULL == fUniform1fv ||
118 NULL == fUniform1iv ||
119 NULL == fUniform2f ||
120 NULL == fUniform2i ||
121 NULL == fUniform2fv ||
122 NULL == fUniform2iv ||
123 NULL == fUniform3f ||
124 NULL == fUniform3i ||
125 NULL == fUniform3fv ||
126 NULL == fUniform3iv ||
127 NULL == fUniform4f ||
128 NULL == fUniform4i ||
129 NULL == fUniform4fv ||
130 NULL == fUniform4iv ||
131 NULL == fUniformMatrix2fv ||
132 NULL == fUniformMatrix3fv ||
133 NULL == fUniformMatrix4fv ||
134 NULL == fUseProgram ||
135 NULL == fVertexAttrib4fv ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +0000136 NULL == fVertexAttribPointer ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000137 NULL == fViewport ||
138 NULL == fBindFramebuffer ||
139 NULL == fBindRenderbuffer ||
140 NULL == fCheckFramebufferStatus ||
141 NULL == fDeleteFramebuffers ||
142 NULL == fDeleteRenderbuffers ||
bsalomon@google.com373a6632011-10-19 20:43:20 +0000143 NULL == fFinish ||
144 NULL == fFlush ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000145 NULL == fFramebufferRenderbuffer ||
146 NULL == fFramebufferTexture2D ||
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000147 NULL == fGetFramebufferAttachmentParameteriv ||
148 NULL == fGetRenderbufferParameteriv ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000149 NULL == fGenFramebuffers ||
150 NULL == fGenRenderbuffers ||
151 NULL == fRenderbufferStorage) {
152 return false;
153 }
154
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000155 GrGLVersion glVer = GrGLGetVersion(this);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000156
157 // Now check that baseline ES/Desktop fns not covered above are present
158 // and that we have fn pointers for any advertised extensions that we will
159 // try to use.
160
161 // these functions are part of ES2, we assume they are available
162 // On the desktop we assume they are available if the extension
163 // is present or GL version is high enough.
bsalomon@google.com791816a2013-08-15 18:54:39 +0000164 if (kES_GrGLBinding == binding) {
robertphillips@google.come7884302012-04-18 14:39:58 +0000165 if (NULL == fStencilFuncSeparate ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000166 NULL == fStencilMaskSeparate ||
167 NULL == fStencilOpSeparate) {
168 return false;
169 }
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000170 } else if (kDesktop_GrGLBinding == binding) {
robertphillips@google.come7884302012-04-18 14:39:58 +0000171
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000172 if (glVer >= GR_GL_VER(2,0)) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000173 if (NULL == fStencilFuncSeparate ||
174 NULL == fStencilMaskSeparate ||
175 NULL == fStencilOpSeparate) {
176 return false;
177 }
178 }
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000179 if (glVer >= GR_GL_VER(3,0) && NULL == fBindFragDataLocation) {
bsalomon@google.combc5cf512011-09-21 16:21:07 +0000180 return false;
181 }
bsalomon@google.com1744f972013-02-26 21:46:32 +0000182 if (glVer >= GR_GL_VER(2,0) || extensions.has("GL_ARB_draw_buffers")) {
bsalomon@google.comd32c5f52011-08-02 19:29:03 +0000183 if (NULL == fDrawBuffers) {
184 return false;
185 }
186 }
robertphillips@google.come7884302012-04-18 14:39:58 +0000187
bsalomon@google.com1744f972013-02-26 21:46:32 +0000188 if (glVer >= GR_GL_VER(1,5) || extensions.has("GL_ARB_occlusion_query")) {
bsalomon@google.com373a6632011-10-19 20:43:20 +0000189 if (NULL == fGenQueries ||
190 NULL == fDeleteQueries ||
191 NULL == fBeginQuery ||
192 NULL == fEndQuery ||
193 NULL == fGetQueryiv ||
194 NULL == fGetQueryObjectiv ||
195 NULL == fGetQueryObjectuiv) {
196 return false;
197 }
198 }
199 if (glVer >= GR_GL_VER(3,3) ||
bsalomon@google.com1744f972013-02-26 21:46:32 +0000200 extensions.has("GL_ARB_timer_query") ||
201 extensions.has("GL_EXT_timer_query")) {
bsalomon@google.com373a6632011-10-19 20:43:20 +0000202 if (NULL == fGetQueryObjecti64v ||
203 NULL == fGetQueryObjectui64v) {
204 return false;
205 }
206 }
bsalomon@google.com1744f972013-02-26 21:46:32 +0000207 if (glVer >= GR_GL_VER(3,3) || extensions.has("GL_ARB_timer_query")) {
bsalomon@google.com373a6632011-10-19 20:43:20 +0000208 if (NULL == fQueryCounter) {
209 return false;
210 }
211 }
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000212 if (!isCoreProfile) {
213 if (NULL == fClientActiveTexture ||
214 NULL == fDisableClientState ||
215 NULL == fEnableClientState ||
216 NULL == fLoadIdentity ||
217 NULL == fLoadMatrixf ||
218 NULL == fMatrixMode ||
219 NULL == fTexGenf ||
220 NULL == fTexGenfv ||
221 NULL == fTexGeni ||
222 NULL == fVertexPointer) {
223 return false;
224 }
bsalomon@google.comfe11cb62012-06-06 15:17:54 +0000225 }
bsalomon@google.com1744f972013-02-26 21:46:32 +0000226 if (false && extensions.has("GL_NV_path_rendering")) {
bsalomon@google.comfe11cb62012-06-06 15:17:54 +0000227 if (NULL == fPathCommands ||
228 NULL == fPathCoords ||
229 NULL == fPathSubCommands ||
230 NULL == fPathSubCoords ||
231 NULL == fPathString ||
232 NULL == fPathGlyphs ||
233 NULL == fPathGlyphRange ||
234 NULL == fWeightPaths ||
235 NULL == fCopyPath ||
236 NULL == fInterpolatePaths ||
237 NULL == fTransformPath ||
238 NULL == fPathParameteriv ||
239 NULL == fPathParameteri ||
240 NULL == fPathParameterfv ||
241 NULL == fPathParameterf ||
242 NULL == fPathDashArray ||
243 NULL == fGenPaths ||
244 NULL == fDeletePaths ||
245 NULL == fIsPath ||
246 NULL == fPathStencilFunc ||
247 NULL == fPathStencilDepthOffset ||
248 NULL == fStencilFillPath ||
249 NULL == fStencilStrokePath ||
250 NULL == fStencilFillPathInstanced ||
251 NULL == fStencilStrokePathInstanced ||
252 NULL == fPathCoverDepthFunc ||
253 NULL == fPathColorGen ||
254 NULL == fPathTexGen ||
255 NULL == fPathFogGen ||
256 NULL == fCoverFillPath ||
257 NULL == fCoverStrokePath ||
258 NULL == fCoverFillPathInstanced ||
259 NULL == fCoverStrokePathInstanced ||
260 NULL == fGetPathParameteriv ||
261 NULL == fGetPathParameterfv ||
262 NULL == fGetPathCommands ||
263 NULL == fGetPathCoords ||
264 NULL == fGetPathDashArray ||
265 NULL == fGetPathMetrics ||
266 NULL == fGetPathMetricRange ||
267 NULL == fGetPathSpacing ||
268 NULL == fGetPathColorGeniv ||
269 NULL == fGetPathColorGenfv ||
270 NULL == fGetPathTexGeniv ||
271 NULL == fGetPathTexGenfv ||
272 NULL == fIsPointInFillPath ||
273 NULL == fIsPointInStrokePath ||
274 NULL == fGetPathLength ||
275 NULL == fPointAlongPath) {
276 return false;
277 }
278 }
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000279 }
280
281 // optional function on desktop before 1.3
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000282 if (kDesktop_GrGLBinding != binding ||
bsalomon@google.com1744f972013-02-26 21:46:32 +0000283 (glVer >= GR_GL_VER(1,3)) ||
284 extensions.has("GL_ARB_texture_compression")) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000285 if (NULL == fCompressedTexImage2D) {
286 return false;
287 }
288 }
289
bsalomon@google.comd32c5f52011-08-02 19:29:03 +0000290 // part of desktop GL, but not ES
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000291 if (kDesktop_GrGLBinding == binding &&
commit-bot@chromium.org941df4f2013-08-20 20:54:08 +0000292 (NULL == fGetTexLevelParameteriv ||
bsalomon@google.comc49d66b2011-08-03 14:22:30 +0000293 NULL == fDrawBuffer ||
294 NULL == fReadBuffer)) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000295 return false;
296 }
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000297
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000298 // GL_EXT_texture_storage is part of desktop 4.2
299 // There is a desktop ARB extension and an ES+desktop EXT extension
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000300 if (kDesktop_GrGLBinding == binding) {
bsalomon@google.combaa9ea12012-01-06 19:05:43 +0000301 if (glVer >= GR_GL_VER(4,2) ||
bsalomon@google.com1744f972013-02-26 21:46:32 +0000302 extensions.has("GL_ARB_texture_storage") ||
303 extensions.has("GL_EXT_texture_storage")) {
bsalomon@google.combaa9ea12012-01-06 19:05:43 +0000304 if (NULL == fTexStorage2D) {
305 return false;
306 }
307 }
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +0000308 } else if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_EXT_texture_storage")) {
bsalomon@google.combaa9ea12012-01-06 19:05:43 +0000309 if (NULL == fTexStorage2D) {
310 return false;
311 }
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000312 }
313
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000314 if (extensions.has("GL_EXT_discard_framebuffer")) {
315// FIXME: Remove this once Chromium is updated to provide this function
316#if 0
317 if (NULL == fDiscardFramebuffer) {
318 return false;
319 }
320#endif
321 }
322
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000323 // FBO MSAA
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000324 if (kDesktop_GrGLBinding == binding) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000325 // GL 3.0 and the ARB extension have multisample + blit
bsalomon@google.com1744f972013-02-26 21:46:32 +0000326 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_framebuffer_object")) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000327 if (NULL == fRenderbufferStorageMultisample ||
328 NULL == fBlitFramebuffer) {
329 return false;
330 }
331 } else {
bsalomon@google.com1744f972013-02-26 21:46:32 +0000332 if (extensions.has("GL_EXT_framebuffer_blit") &&
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000333 NULL == fBlitFramebuffer) {
334 return false;
335 }
bsalomon@google.com1744f972013-02-26 21:46:32 +0000336 if (extensions.has("GL_EXT_framebuffer_multisample") &&
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000337 NULL == fRenderbufferStorageMultisample) {
338 return false;
339 }
340 }
341 } else {
bsalomon@google.com1744f972013-02-26 21:46:32 +0000342 if (extensions.has("GL_CHROMIUM_framebuffer_multisample")) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000343 if (NULL == fRenderbufferStorageMultisample ||
344 NULL == fBlitFramebuffer) {
345 return false;
346 }
347 }
bsalomon@google.com1744f972013-02-26 21:46:32 +0000348 if (extensions.has("GL_APPLE_framebuffer_multisample")) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000349 if (NULL == fRenderbufferStorageMultisample ||
350 NULL == fResolveMultisampleFramebuffer) {
351 return false;
352 }
353 }
bsalomon@google.com347c3822013-05-01 20:10:01 +0000354 if (extensions.has("GL_IMG_multisampled_render_to_texture") ||
355 extensions.has("GL_EXT_multisampled_render_to_texture")) {
bsalomon@google.comf3a60c02013-03-19 19:06:09 +0000356 if (NULL == fRenderbufferStorageMultisample ||
357 NULL == fFramebufferTexture2DMultisample) {
358 return false;
359 }
360 }
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000361 }
362
363 // On ES buffer mapping is an extension. On Desktop
364 // buffer mapping was part of original VBO extension
365 // which we require.
bsalomon@google.com1744f972013-02-26 21:46:32 +0000366 if (kDesktop_GrGLBinding == binding || extensions.has("GL_OES_mapbuffer")) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000367 if (NULL == fMapBuffer ||
368 NULL == fUnmapBuffer) {
369 return false;
370 }
371 }
372
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000373 // Dual source blending
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000374 if (kDesktop_GrGLBinding == binding &&
bsalomon@google.com1744f972013-02-26 21:46:32 +0000375 (glVer >= GR_GL_VER(3,3) || extensions.has("GL_ARB_blend_func_extended"))) {
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000376 if (NULL == fBindFragDataLocationIndexed) {
377 return false;
378 }
379 }
skia.committer@gmail.com12eea2b2013-02-27 07:10:10 +0000380
commit-bot@chromium.org726e6212013-08-23 20:55:46 +0000381 // glGetStringi was added in version 3.0 of both desktop and ES.
382 if (glVer >= GR_GL_VER(3, 0)) {
bsalomon@google.com1744f972013-02-26 21:46:32 +0000383 if (NULL == fGetStringi) {
384 return false;
385 }
386 }
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000387
bsalomon@google.comecd84842013-03-01 15:36:02 +0000388 if (kDesktop_GrGLBinding == binding) {
389 if (glVer >= GR_GL_VER(3, 0) || extensions.has("GL_ARB_vertex_array_object")) {
390 if (NULL == fBindVertexArray ||
391 NULL == fDeleteVertexArrays ||
392 NULL == fGenVertexArrays) {
393 return false;
394 }
395 }
396 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000397 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_OES_vertex_array_object")) {
bsalomon@google.comecd84842013-03-01 15:36:02 +0000398 if (NULL == fBindVertexArray ||
399 NULL == fDeleteVertexArrays ||
400 NULL == fGenVertexArrays) {
401 return false;
402 }
403 }
bsalomon@google.comecd84842013-03-01 15:36:02 +0000404 }
405
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000406 return true;
407}