blob: 8f94f1002c43ba97eb13c0e5a4a472045e5d99c3 [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
47 // functions that are always required
48 if (NULL == fActiveTexture ||
49 NULL == fAttachShader ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000050 NULL == fBindAttribLocation ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000051 NULL == fBindBuffer ||
52 NULL == fBindTexture ||
53 NULL == fBlendFunc ||
robertphillips@google.come7884302012-04-18 14:39:58 +000054 NULL == fBlendColor || // -> GL >= 1.4, ES >= 2.0 or extension
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000055 NULL == fBufferData ||
56 NULL == fBufferSubData ||
57 NULL == fClear ||
58 NULL == fClearColor ||
59 NULL == fClearStencil ||
60 NULL == fColorMask ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000061 NULL == fCompileShader ||
commit-bot@chromium.org98168bb2013-04-11 22:00:34 +000062 NULL == fCopyTexSubImage2D ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000063 NULL == fCreateProgram ||
64 NULL == fCreateShader ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000065 NULL == fCullFace ||
66 NULL == fDeleteBuffers ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000067 NULL == fDeleteProgram ||
68 NULL == fDeleteShader ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000069 NULL == fDeleteTextures ||
70 NULL == fDepthMask ||
71 NULL == fDisable ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000072 NULL == fDisableVertexAttribArray ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000073 NULL == fDrawArrays ||
74 NULL == fDrawElements ||
75 NULL == fEnable ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000076 NULL == fEnableVertexAttribArray ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000077 NULL == fFrontFace ||
78 NULL == fGenBuffers ||
79 NULL == fGenTextures ||
80 NULL == fGetBufferParameteriv ||
commit-bot@chromium.orgcffff792013-07-26 16:36:04 +000081#ifndef SKIA_IGNORE_GPU_MIPMAPS
82 NULL == fGenerateMipmap ||
83#endif
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000084 NULL == fGetError ||
85 NULL == fGetIntegerv ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000086 NULL == fGetProgramInfoLog ||
87 NULL == fGetProgramiv ||
88 NULL == fGetShaderInfoLog ||
89 NULL == fGetShaderiv ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000090 NULL == fGetString ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000091 NULL == fGetUniformLocation ||
92 NULL == fLinkProgram ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000093 NULL == fPixelStorei ||
94 NULL == fReadPixels ||
95 NULL == fScissor ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000096 NULL == fShaderSource ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000097 NULL == fStencilFunc ||
98 NULL == fStencilMask ||
99 NULL == fStencilOp ||
100 NULL == fTexImage2D ||
101 NULL == fTexParameteri ||
bsalomon@google.com4d063de2012-05-31 17:59:23 +0000102 NULL == fTexParameteriv ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +0000103 NULL == fTexSubImage2D ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000104 NULL == fUniform1f ||
105 NULL == fUniform1i ||
106 NULL == fUniform1fv ||
107 NULL == fUniform1iv ||
108 NULL == fUniform2f ||
109 NULL == fUniform2i ||
110 NULL == fUniform2fv ||
111 NULL == fUniform2iv ||
112 NULL == fUniform3f ||
113 NULL == fUniform3i ||
114 NULL == fUniform3fv ||
115 NULL == fUniform3iv ||
116 NULL == fUniform4f ||
117 NULL == fUniform4i ||
118 NULL == fUniform4fv ||
119 NULL == fUniform4iv ||
120 NULL == fUniformMatrix2fv ||
121 NULL == fUniformMatrix3fv ||
122 NULL == fUniformMatrix4fv ||
123 NULL == fUseProgram ||
124 NULL == fVertexAttrib4fv ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +0000125 NULL == fVertexAttribPointer ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000126 NULL == fViewport ||
127 NULL == fBindFramebuffer ||
128 NULL == fBindRenderbuffer ||
129 NULL == fCheckFramebufferStatus ||
130 NULL == fDeleteFramebuffers ||
131 NULL == fDeleteRenderbuffers ||
bsalomon@google.com373a6632011-10-19 20:43:20 +0000132 NULL == fFinish ||
133 NULL == fFlush ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000134 NULL == fFramebufferRenderbuffer ||
135 NULL == fFramebufferTexture2D ||
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000136 NULL == fGetFramebufferAttachmentParameteriv ||
137 NULL == fGetRenderbufferParameteriv ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000138 NULL == fGenFramebuffers ||
139 NULL == fGenRenderbuffers ||
140 NULL == fRenderbufferStorage) {
141 return false;
142 }
143
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000144 GrGLVersion glVer = GrGLGetVersion(this);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000145
146 // Now check that baseline ES/Desktop fns not covered above are present
147 // and that we have fn pointers for any advertised extensions that we will
148 // try to use.
149
150 // these functions are part of ES2, we assume they are available
151 // On the desktop we assume they are available if the extension
152 // is present or GL version is high enough.
bsalomon@google.com791816a2013-08-15 18:54:39 +0000153 if (kES_GrGLBinding == binding) {
robertphillips@google.come7884302012-04-18 14:39:58 +0000154 if (NULL == fStencilFuncSeparate ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000155 NULL == fStencilMaskSeparate ||
156 NULL == fStencilOpSeparate) {
157 return false;
158 }
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000159 } else if (kDesktop_GrGLBinding == binding) {
robertphillips@google.come7884302012-04-18 14:39:58 +0000160
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000161 if (glVer >= GR_GL_VER(2,0)) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000162 if (NULL == fStencilFuncSeparate ||
163 NULL == fStencilMaskSeparate ||
164 NULL == fStencilOpSeparate) {
165 return false;
166 }
167 }
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000168 if (glVer >= GR_GL_VER(3,0) && NULL == fBindFragDataLocation) {
bsalomon@google.combc5cf512011-09-21 16:21:07 +0000169 return false;
170 }
bsalomon@google.com1744f972013-02-26 21:46:32 +0000171 if (glVer >= GR_GL_VER(2,0) || extensions.has("GL_ARB_draw_buffers")) {
bsalomon@google.comd32c5f52011-08-02 19:29:03 +0000172 if (NULL == fDrawBuffers) {
173 return false;
174 }
175 }
robertphillips@google.come7884302012-04-18 14:39:58 +0000176
bsalomon@google.com1744f972013-02-26 21:46:32 +0000177 if (glVer >= GR_GL_VER(1,5) || extensions.has("GL_ARB_occlusion_query")) {
bsalomon@google.com373a6632011-10-19 20:43:20 +0000178 if (NULL == fGenQueries ||
179 NULL == fDeleteQueries ||
180 NULL == fBeginQuery ||
181 NULL == fEndQuery ||
182 NULL == fGetQueryiv ||
183 NULL == fGetQueryObjectiv ||
184 NULL == fGetQueryObjectuiv) {
185 return false;
186 }
187 }
188 if (glVer >= GR_GL_VER(3,3) ||
bsalomon@google.com1744f972013-02-26 21:46:32 +0000189 extensions.has("GL_ARB_timer_query") ||
190 extensions.has("GL_EXT_timer_query")) {
bsalomon@google.com373a6632011-10-19 20:43:20 +0000191 if (NULL == fGetQueryObjecti64v ||
192 NULL == fGetQueryObjectui64v) {
193 return false;
194 }
195 }
bsalomon@google.com1744f972013-02-26 21:46:32 +0000196 if (glVer >= GR_GL_VER(3,3) || extensions.has("GL_ARB_timer_query")) {
bsalomon@google.com373a6632011-10-19 20:43:20 +0000197 if (NULL == fQueryCounter) {
198 return false;
199 }
200 }
bsalomon@google.comfe11cb62012-06-06 15:17:54 +0000201 // The below two blocks are checks for functions used with
202 // GL_NV_path_rendering. We're not enforcing that they be non-NULL
203 // because they aren't actually called at this time.
204 if (false &&
bsalomon@google.comd4340e22012-06-06 15:38:52 +0000205 (NULL == fMatrixMode ||
206 NULL == fLoadIdentity ||
207 NULL == fLoadMatrixf)) {
bsalomon@google.comfe11cb62012-06-06 15:17:54 +0000208 return false;
209 }
bsalomon@google.com1744f972013-02-26 21:46:32 +0000210 if (false && extensions.has("GL_NV_path_rendering")) {
bsalomon@google.comfe11cb62012-06-06 15:17:54 +0000211 if (NULL == fPathCommands ||
212 NULL == fPathCoords ||
213 NULL == fPathSubCommands ||
214 NULL == fPathSubCoords ||
215 NULL == fPathString ||
216 NULL == fPathGlyphs ||
217 NULL == fPathGlyphRange ||
218 NULL == fWeightPaths ||
219 NULL == fCopyPath ||
220 NULL == fInterpolatePaths ||
221 NULL == fTransformPath ||
222 NULL == fPathParameteriv ||
223 NULL == fPathParameteri ||
224 NULL == fPathParameterfv ||
225 NULL == fPathParameterf ||
226 NULL == fPathDashArray ||
227 NULL == fGenPaths ||
228 NULL == fDeletePaths ||
229 NULL == fIsPath ||
230 NULL == fPathStencilFunc ||
231 NULL == fPathStencilDepthOffset ||
232 NULL == fStencilFillPath ||
233 NULL == fStencilStrokePath ||
234 NULL == fStencilFillPathInstanced ||
235 NULL == fStencilStrokePathInstanced ||
236 NULL == fPathCoverDepthFunc ||
237 NULL == fPathColorGen ||
238 NULL == fPathTexGen ||
239 NULL == fPathFogGen ||
240 NULL == fCoverFillPath ||
241 NULL == fCoverStrokePath ||
242 NULL == fCoverFillPathInstanced ||
243 NULL == fCoverStrokePathInstanced ||
244 NULL == fGetPathParameteriv ||
245 NULL == fGetPathParameterfv ||
246 NULL == fGetPathCommands ||
247 NULL == fGetPathCoords ||
248 NULL == fGetPathDashArray ||
249 NULL == fGetPathMetrics ||
250 NULL == fGetPathMetricRange ||
251 NULL == fGetPathSpacing ||
252 NULL == fGetPathColorGeniv ||
253 NULL == fGetPathColorGenfv ||
254 NULL == fGetPathTexGeniv ||
255 NULL == fGetPathTexGenfv ||
256 NULL == fIsPointInFillPath ||
257 NULL == fIsPointInStrokePath ||
258 NULL == fGetPathLength ||
259 NULL == fPointAlongPath) {
260 return false;
261 }
262 }
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000263 }
264
265 // optional function on desktop before 1.3
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000266 if (kDesktop_GrGLBinding != binding ||
bsalomon@google.com1744f972013-02-26 21:46:32 +0000267 (glVer >= GR_GL_VER(1,3)) ||
268 extensions.has("GL_ARB_texture_compression")) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000269 if (NULL == fCompressedTexImage2D) {
270 return false;
271 }
272 }
273
bsalomon@google.comd32c5f52011-08-02 19:29:03 +0000274 // part of desktop GL, but not ES
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000275 if (kDesktop_GrGLBinding == binding &&
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000276 (NULL == fLineWidth ||
bsalomon@google.comd32c5f52011-08-02 19:29:03 +0000277 NULL == fGetTexLevelParameteriv ||
bsalomon@google.comc49d66b2011-08-03 14:22:30 +0000278 NULL == fDrawBuffer ||
279 NULL == fReadBuffer)) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000280 return false;
281 }
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000282
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000283 // GL_EXT_texture_storage is part of desktop 4.2
284 // There is a desktop ARB extension and an ES+desktop EXT extension
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000285 if (kDesktop_GrGLBinding == binding) {
bsalomon@google.combaa9ea12012-01-06 19:05:43 +0000286 if (glVer >= GR_GL_VER(4,2) ||
bsalomon@google.com1744f972013-02-26 21:46:32 +0000287 extensions.has("GL_ARB_texture_storage") ||
288 extensions.has("GL_EXT_texture_storage")) {
bsalomon@google.combaa9ea12012-01-06 19:05:43 +0000289 if (NULL == fTexStorage2D) {
290 return false;
291 }
292 }
bsalomon@google.com1744f972013-02-26 21:46:32 +0000293 } else if (extensions.has("GL_EXT_texture_storage")) {
bsalomon@google.combaa9ea12012-01-06 19:05:43 +0000294 if (NULL == fTexStorage2D) {
295 return false;
296 }
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000297 }
298
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000299 if (extensions.has("GL_EXT_discard_framebuffer")) {
300// FIXME: Remove this once Chromium is updated to provide this function
301#if 0
302 if (NULL == fDiscardFramebuffer) {
303 return false;
304 }
305#endif
306 }
307
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000308 // FBO MSAA
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000309 if (kDesktop_GrGLBinding == binding) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000310 // GL 3.0 and the ARB extension have multisample + blit
bsalomon@google.com1744f972013-02-26 21:46:32 +0000311 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_framebuffer_object")) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000312 if (NULL == fRenderbufferStorageMultisample ||
313 NULL == fBlitFramebuffer) {
314 return false;
315 }
316 } else {
bsalomon@google.com1744f972013-02-26 21:46:32 +0000317 if (extensions.has("GL_EXT_framebuffer_blit") &&
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000318 NULL == fBlitFramebuffer) {
319 return false;
320 }
bsalomon@google.com1744f972013-02-26 21:46:32 +0000321 if (extensions.has("GL_EXT_framebuffer_multisample") &&
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000322 NULL == fRenderbufferStorageMultisample) {
323 return false;
324 }
325 }
326 } else {
bsalomon@google.com1744f972013-02-26 21:46:32 +0000327 if (extensions.has("GL_CHROMIUM_framebuffer_multisample")) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000328 if (NULL == fRenderbufferStorageMultisample ||
329 NULL == fBlitFramebuffer) {
330 return false;
331 }
332 }
bsalomon@google.com1744f972013-02-26 21:46:32 +0000333 if (extensions.has("GL_APPLE_framebuffer_multisample")) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000334 if (NULL == fRenderbufferStorageMultisample ||
335 NULL == fResolveMultisampleFramebuffer) {
336 return false;
337 }
338 }
bsalomon@google.com347c3822013-05-01 20:10:01 +0000339 if (extensions.has("GL_IMG_multisampled_render_to_texture") ||
340 extensions.has("GL_EXT_multisampled_render_to_texture")) {
bsalomon@google.comf3a60c02013-03-19 19:06:09 +0000341 if (NULL == fRenderbufferStorageMultisample ||
342 NULL == fFramebufferTexture2DMultisample) {
343 return false;
344 }
345 }
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000346 }
347
348 // On ES buffer mapping is an extension. On Desktop
349 // buffer mapping was part of original VBO extension
350 // which we require.
bsalomon@google.com1744f972013-02-26 21:46:32 +0000351 if (kDesktop_GrGLBinding == binding || extensions.has("GL_OES_mapbuffer")) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000352 if (NULL == fMapBuffer ||
353 NULL == fUnmapBuffer) {
354 return false;
355 }
356 }
357
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000358 // Dual source blending
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000359 if (kDesktop_GrGLBinding == binding &&
bsalomon@google.com1744f972013-02-26 21:46:32 +0000360 (glVer >= GR_GL_VER(3,3) || extensions.has("GL_ARB_blend_func_extended"))) {
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000361 if (NULL == fBindFragDataLocationIndexed) {
362 return false;
363 }
364 }
skia.committer@gmail.com12eea2b2013-02-27 07:10:10 +0000365
bsalomon@google.com1744f972013-02-26 21:46:32 +0000366 if (kDesktop_GrGLBinding == binding && glVer >= GR_GL_VER(3, 0)) {
367 if (NULL == fGetStringi) {
368 return false;
369 }
370 }
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000371
bsalomon@google.comecd84842013-03-01 15:36:02 +0000372 if (kDesktop_GrGLBinding == binding) {
373 if (glVer >= GR_GL_VER(3, 0) || extensions.has("GL_ARB_vertex_array_object")) {
374 if (NULL == fBindVertexArray ||
375 NULL == fDeleteVertexArrays ||
376 NULL == fGenVertexArrays) {
377 return false;
378 }
379 }
380 } else {
bsalomon@google.comecd84842013-03-01 15:36:02 +0000381 if (extensions.has("GL_OES_vertex_array_object")) {
382 if (NULL == fBindVertexArray ||
383 NULL == fDeleteVertexArrays ||
384 NULL == fGenVertexArrays) {
385 return false;
386 }
387 }
bsalomon@google.comecd84842013-03-01 15:36:02 +0000388 }
389
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000390 return true;
391}