blob: b70841cf09b799e18bea265eb61fa6a17f5a383d [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#if 0 // FIXME: Remove this once Chromium is updated to provide this function
63 NULL == fCopyTexSubImage2D ||
64#endif
bsalomon@google.combf2a4692011-05-04 12:35:39 +000065 NULL == fCreateProgram ||
66 NULL == fCreateShader ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000067 NULL == fCullFace ||
68 NULL == fDeleteBuffers ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000069 NULL == fDeleteProgram ||
70 NULL == fDeleteShader ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000071 NULL == fDeleteTextures ||
72 NULL == fDepthMask ||
73 NULL == fDisable ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000074 NULL == fDisableVertexAttribArray ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000075 NULL == fDrawArrays ||
76 NULL == fDrawElements ||
77 NULL == fEnable ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000078 NULL == fEnableVertexAttribArray ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000079 NULL == fFrontFace ||
80 NULL == fGenBuffers ||
81 NULL == fGenTextures ||
82 NULL == fGetBufferParameteriv ||
83 NULL == fGetError ||
84 NULL == fGetIntegerv ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000085 NULL == fGetProgramInfoLog ||
86 NULL == fGetProgramiv ||
87 NULL == fGetShaderInfoLog ||
88 NULL == fGetShaderiv ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000089 NULL == fGetString ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000090 NULL == fGetUniformLocation ||
91 NULL == fLinkProgram ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000092 NULL == fPixelStorei ||
93 NULL == fReadPixels ||
94 NULL == fScissor ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000095 NULL == fShaderSource ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000096 NULL == fStencilFunc ||
97 NULL == fStencilMask ||
98 NULL == fStencilOp ||
99 NULL == fTexImage2D ||
100 NULL == fTexParameteri ||
bsalomon@google.com4d063de2012-05-31 17:59:23 +0000101 NULL == fTexParameteriv ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +0000102 NULL == fTexSubImage2D ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000103 NULL == fUniform1f ||
104 NULL == fUniform1i ||
105 NULL == fUniform1fv ||
106 NULL == fUniform1iv ||
107 NULL == fUniform2f ||
108 NULL == fUniform2i ||
109 NULL == fUniform2fv ||
110 NULL == fUniform2iv ||
111 NULL == fUniform3f ||
112 NULL == fUniform3i ||
113 NULL == fUniform3fv ||
114 NULL == fUniform3iv ||
115 NULL == fUniform4f ||
116 NULL == fUniform4i ||
117 NULL == fUniform4fv ||
118 NULL == fUniform4iv ||
119 NULL == fUniformMatrix2fv ||
120 NULL == fUniformMatrix3fv ||
121 NULL == fUniformMatrix4fv ||
122 NULL == fUseProgram ||
123 NULL == fVertexAttrib4fv ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +0000124 NULL == fVertexAttribPointer ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000125 NULL == fViewport ||
126 NULL == fBindFramebuffer ||
127 NULL == fBindRenderbuffer ||
128 NULL == fCheckFramebufferStatus ||
129 NULL == fDeleteFramebuffers ||
130 NULL == fDeleteRenderbuffers ||
bsalomon@google.com373a6632011-10-19 20:43:20 +0000131 NULL == fFinish ||
132 NULL == fFlush ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000133 NULL == fFramebufferRenderbuffer ||
134 NULL == fFramebufferTexture2D ||
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000135 NULL == fGetFramebufferAttachmentParameteriv ||
136 NULL == fGetRenderbufferParameteriv ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000137 NULL == fGenFramebuffers ||
138 NULL == fGenRenderbuffers ||
139 NULL == fRenderbufferStorage) {
140 return false;
141 }
142
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000143 GrGLVersion glVer = GrGLGetVersion(this);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000144
145 // Now check that baseline ES/Desktop fns not covered above are present
146 // and that we have fn pointers for any advertised extensions that we will
147 // try to use.
148
149 // these functions are part of ES2, we assume they are available
150 // On the desktop we assume they are available if the extension
151 // is present or GL version is high enough.
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000152 if (kES2_GrGLBinding == binding) {
robertphillips@google.come7884302012-04-18 14:39:58 +0000153 if (NULL == fStencilFuncSeparate ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000154 NULL == fStencilMaskSeparate ||
155 NULL == fStencilOpSeparate) {
156 return false;
157 }
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000158 } else if (kDesktop_GrGLBinding == binding) {
robertphillips@google.come7884302012-04-18 14:39:58 +0000159
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000160 if (glVer >= GR_GL_VER(2,0)) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000161 if (NULL == fStencilFuncSeparate ||
162 NULL == fStencilMaskSeparate ||
163 NULL == fStencilOpSeparate) {
164 return false;
165 }
166 }
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000167 if (glVer >= GR_GL_VER(3,0) && NULL == fBindFragDataLocation) {
bsalomon@google.combc5cf512011-09-21 16:21:07 +0000168 return false;
169 }
bsalomon@google.com1744f972013-02-26 21:46:32 +0000170 if (glVer >= GR_GL_VER(2,0) || extensions.has("GL_ARB_draw_buffers")) {
bsalomon@google.comd32c5f52011-08-02 19:29:03 +0000171 if (NULL == fDrawBuffers) {
172 return false;
173 }
174 }
robertphillips@google.come7884302012-04-18 14:39:58 +0000175
bsalomon@google.com1744f972013-02-26 21:46:32 +0000176 if (glVer >= GR_GL_VER(1,5) || extensions.has("GL_ARB_occlusion_query")) {
bsalomon@google.com373a6632011-10-19 20:43:20 +0000177 if (NULL == fGenQueries ||
178 NULL == fDeleteQueries ||
179 NULL == fBeginQuery ||
180 NULL == fEndQuery ||
181 NULL == fGetQueryiv ||
182 NULL == fGetQueryObjectiv ||
183 NULL == fGetQueryObjectuiv) {
184 return false;
185 }
186 }
187 if (glVer >= GR_GL_VER(3,3) ||
bsalomon@google.com1744f972013-02-26 21:46:32 +0000188 extensions.has("GL_ARB_timer_query") ||
189 extensions.has("GL_EXT_timer_query")) {
bsalomon@google.com373a6632011-10-19 20:43:20 +0000190 if (NULL == fGetQueryObjecti64v ||
191 NULL == fGetQueryObjectui64v) {
192 return false;
193 }
194 }
bsalomon@google.com1744f972013-02-26 21:46:32 +0000195 if (glVer >= GR_GL_VER(3,3) || extensions.has("GL_ARB_timer_query")) {
bsalomon@google.com373a6632011-10-19 20:43:20 +0000196 if (NULL == fQueryCounter) {
197 return false;
198 }
199 }
bsalomon@google.comfe11cb62012-06-06 15:17:54 +0000200 // The below two blocks are checks for functions used with
201 // GL_NV_path_rendering. We're not enforcing that they be non-NULL
202 // because they aren't actually called at this time.
203 if (false &&
bsalomon@google.comd4340e22012-06-06 15:38:52 +0000204 (NULL == fMatrixMode ||
205 NULL == fLoadIdentity ||
206 NULL == fLoadMatrixf)) {
bsalomon@google.comfe11cb62012-06-06 15:17:54 +0000207 return false;
208 }
bsalomon@google.com1744f972013-02-26 21:46:32 +0000209 if (false && extensions.has("GL_NV_path_rendering")) {
bsalomon@google.comfe11cb62012-06-06 15:17:54 +0000210 if (NULL == fPathCommands ||
211 NULL == fPathCoords ||
212 NULL == fPathSubCommands ||
213 NULL == fPathSubCoords ||
214 NULL == fPathString ||
215 NULL == fPathGlyphs ||
216 NULL == fPathGlyphRange ||
217 NULL == fWeightPaths ||
218 NULL == fCopyPath ||
219 NULL == fInterpolatePaths ||
220 NULL == fTransformPath ||
221 NULL == fPathParameteriv ||
222 NULL == fPathParameteri ||
223 NULL == fPathParameterfv ||
224 NULL == fPathParameterf ||
225 NULL == fPathDashArray ||
226 NULL == fGenPaths ||
227 NULL == fDeletePaths ||
228 NULL == fIsPath ||
229 NULL == fPathStencilFunc ||
230 NULL == fPathStencilDepthOffset ||
231 NULL == fStencilFillPath ||
232 NULL == fStencilStrokePath ||
233 NULL == fStencilFillPathInstanced ||
234 NULL == fStencilStrokePathInstanced ||
235 NULL == fPathCoverDepthFunc ||
236 NULL == fPathColorGen ||
237 NULL == fPathTexGen ||
238 NULL == fPathFogGen ||
239 NULL == fCoverFillPath ||
240 NULL == fCoverStrokePath ||
241 NULL == fCoverFillPathInstanced ||
242 NULL == fCoverStrokePathInstanced ||
243 NULL == fGetPathParameteriv ||
244 NULL == fGetPathParameterfv ||
245 NULL == fGetPathCommands ||
246 NULL == fGetPathCoords ||
247 NULL == fGetPathDashArray ||
248 NULL == fGetPathMetrics ||
249 NULL == fGetPathMetricRange ||
250 NULL == fGetPathSpacing ||
251 NULL == fGetPathColorGeniv ||
252 NULL == fGetPathColorGenfv ||
253 NULL == fGetPathTexGeniv ||
254 NULL == fGetPathTexGenfv ||
255 NULL == fIsPointInFillPath ||
256 NULL == fIsPointInStrokePath ||
257 NULL == fGetPathLength ||
258 NULL == fPointAlongPath) {
259 return false;
260 }
261 }
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000262 }
263
264 // optional function on desktop before 1.3
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000265 if (kDesktop_GrGLBinding != binding ||
bsalomon@google.com1744f972013-02-26 21:46:32 +0000266 (glVer >= GR_GL_VER(1,3)) ||
267 extensions.has("GL_ARB_texture_compression")) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000268 if (NULL == fCompressedTexImage2D) {
269 return false;
270 }
271 }
272
bsalomon@google.comd32c5f52011-08-02 19:29:03 +0000273 // part of desktop GL, but not ES
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000274 if (kDesktop_GrGLBinding == binding &&
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000275 (NULL == fLineWidth ||
bsalomon@google.comd32c5f52011-08-02 19:29:03 +0000276 NULL == fGetTexLevelParameteriv ||
bsalomon@google.comc49d66b2011-08-03 14:22:30 +0000277 NULL == fDrawBuffer ||
278 NULL == fReadBuffer)) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000279 return false;
280 }
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000281
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000282 // GL_EXT_texture_storage is part of desktop 4.2
283 // There is a desktop ARB extension and an ES+desktop EXT extension
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000284 if (kDesktop_GrGLBinding == binding) {
bsalomon@google.combaa9ea12012-01-06 19:05:43 +0000285 if (glVer >= GR_GL_VER(4,2) ||
bsalomon@google.com1744f972013-02-26 21:46:32 +0000286 extensions.has("GL_ARB_texture_storage") ||
287 extensions.has("GL_EXT_texture_storage")) {
bsalomon@google.combaa9ea12012-01-06 19:05:43 +0000288 if (NULL == fTexStorage2D) {
289 return false;
290 }
291 }
bsalomon@google.com1744f972013-02-26 21:46:32 +0000292 } else if (extensions.has("GL_EXT_texture_storage")) {
bsalomon@google.combaa9ea12012-01-06 19:05:43 +0000293 if (NULL == fTexStorage2D) {
294 return false;
295 }
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000296 }
297
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000298 if (extensions.has("GL_EXT_discard_framebuffer")) {
299// FIXME: Remove this once Chromium is updated to provide this function
300#if 0
301 if (NULL == fDiscardFramebuffer) {
302 return false;
303 }
304#endif
305 }
306
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000307 // FBO MSAA
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000308 if (kDesktop_GrGLBinding == binding) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000309 // GL 3.0 and the ARB extension have multisample + blit
bsalomon@google.com1744f972013-02-26 21:46:32 +0000310 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_framebuffer_object")) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000311 if (NULL == fRenderbufferStorageMultisample ||
312 NULL == fBlitFramebuffer) {
313 return false;
314 }
315 } else {
bsalomon@google.com1744f972013-02-26 21:46:32 +0000316 if (extensions.has("GL_EXT_framebuffer_blit") &&
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000317 NULL == fBlitFramebuffer) {
318 return false;
319 }
bsalomon@google.com1744f972013-02-26 21:46:32 +0000320 if (extensions.has("GL_EXT_framebuffer_multisample") &&
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000321 NULL == fRenderbufferStorageMultisample) {
322 return false;
323 }
324 }
325 } else {
bsalomon@google.com1744f972013-02-26 21:46:32 +0000326 if (extensions.has("GL_CHROMIUM_framebuffer_multisample")) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000327 if (NULL == fRenderbufferStorageMultisample ||
328 NULL == fBlitFramebuffer) {
329 return false;
330 }
331 }
bsalomon@google.com1744f972013-02-26 21:46:32 +0000332 if (extensions.has("GL_APPLE_framebuffer_multisample")) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000333 if (NULL == fRenderbufferStorageMultisample ||
334 NULL == fResolveMultisampleFramebuffer) {
335 return false;
336 }
337 }
bsalomon@google.comf3a60c02013-03-19 19:06:09 +0000338 if (extensions.has("GL_IMG_multisampled_render_to_texture")) {
339 if (NULL == fRenderbufferStorageMultisample ||
340 NULL == fFramebufferTexture2DMultisample) {
341 return false;
342 }
343 }
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000344 }
345
346 // On ES buffer mapping is an extension. On Desktop
347 // buffer mapping was part of original VBO extension
348 // which we require.
bsalomon@google.com1744f972013-02-26 21:46:32 +0000349 if (kDesktop_GrGLBinding == binding || extensions.has("GL_OES_mapbuffer")) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000350 if (NULL == fMapBuffer ||
351 NULL == fUnmapBuffer) {
352 return false;
353 }
354 }
355
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000356 // Dual source blending
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000357 if (kDesktop_GrGLBinding == binding &&
bsalomon@google.com1744f972013-02-26 21:46:32 +0000358 (glVer >= GR_GL_VER(3,3) || extensions.has("GL_ARB_blend_func_extended"))) {
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000359 if (NULL == fBindFragDataLocationIndexed) {
360 return false;
361 }
362 }
skia.committer@gmail.com12eea2b2013-02-27 07:10:10 +0000363
bsalomon@google.com1744f972013-02-26 21:46:32 +0000364 if (kDesktop_GrGLBinding == binding && glVer >= GR_GL_VER(3, 0)) {
365 if (NULL == fGetStringi) {
366 return false;
367 }
368 }
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000369
bsalomon@google.comecd84842013-03-01 15:36:02 +0000370 if (kDesktop_GrGLBinding == binding) {
371 if (glVer >= GR_GL_VER(3, 0) || extensions.has("GL_ARB_vertex_array_object")) {
372 if (NULL == fBindVertexArray ||
373 NULL == fDeleteVertexArrays ||
374 NULL == fGenVertexArrays) {
375 return false;
376 }
377 }
378 } else {
bsalomon@google.comecd84842013-03-01 15:36:02 +0000379 if (extensions.has("GL_OES_vertex_array_object")) {
380 if (NULL == fBindVertexArray ||
381 NULL == fDeleteVertexArrays ||
382 NULL == fGenVertexArrays) {
383 return false;
384 }
385 }
bsalomon@google.comecd84842013-03-01 15:36:02 +0000386 }
387
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000388 return true;
389}