blob: f5cef11b81e4316d27606f3166413391ba189787 [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 ||
81 NULL == fGetError ||
82 NULL == fGetIntegerv ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000083 NULL == fGetProgramInfoLog ||
84 NULL == fGetProgramiv ||
85 NULL == fGetShaderInfoLog ||
86 NULL == fGetShaderiv ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000087 NULL == fGetString ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000088 NULL == fGetUniformLocation ||
89 NULL == fLinkProgram ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000090 NULL == fPixelStorei ||
91 NULL == fReadPixels ||
92 NULL == fScissor ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000093 NULL == fShaderSource ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000094 NULL == fStencilFunc ||
95 NULL == fStencilMask ||
96 NULL == fStencilOp ||
97 NULL == fTexImage2D ||
98 NULL == fTexParameteri ||
bsalomon@google.com4d063de2012-05-31 17:59:23 +000099 NULL == fTexParameteriv ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +0000100 NULL == fTexSubImage2D ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000101 NULL == fUniform1f ||
102 NULL == fUniform1i ||
103 NULL == fUniform1fv ||
104 NULL == fUniform1iv ||
105 NULL == fUniform2f ||
106 NULL == fUniform2i ||
107 NULL == fUniform2fv ||
108 NULL == fUniform2iv ||
109 NULL == fUniform3f ||
110 NULL == fUniform3i ||
111 NULL == fUniform3fv ||
112 NULL == fUniform3iv ||
113 NULL == fUniform4f ||
114 NULL == fUniform4i ||
115 NULL == fUniform4fv ||
116 NULL == fUniform4iv ||
117 NULL == fUniformMatrix2fv ||
118 NULL == fUniformMatrix3fv ||
119 NULL == fUniformMatrix4fv ||
120 NULL == fUseProgram ||
121 NULL == fVertexAttrib4fv ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +0000122 NULL == fVertexAttribPointer ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000123 NULL == fViewport ||
124 NULL == fBindFramebuffer ||
125 NULL == fBindRenderbuffer ||
126 NULL == fCheckFramebufferStatus ||
127 NULL == fDeleteFramebuffers ||
128 NULL == fDeleteRenderbuffers ||
bsalomon@google.com373a6632011-10-19 20:43:20 +0000129 NULL == fFinish ||
130 NULL == fFlush ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000131 NULL == fFramebufferRenderbuffer ||
132 NULL == fFramebufferTexture2D ||
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000133 NULL == fGetFramebufferAttachmentParameteriv ||
134 NULL == fGetRenderbufferParameteriv ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000135 NULL == fGenFramebuffers ||
136 NULL == fGenRenderbuffers ||
137 NULL == fRenderbufferStorage) {
138 return false;
139 }
140
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000141 GrGLVersion glVer = GrGLGetVersion(this);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000142
143 // Now check that baseline ES/Desktop fns not covered above are present
144 // and that we have fn pointers for any advertised extensions that we will
145 // try to use.
146
147 // these functions are part of ES2, we assume they are available
148 // On the desktop we assume they are available if the extension
149 // is present or GL version is high enough.
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000150 if (kES2_GrGLBinding == binding) {
robertphillips@google.come7884302012-04-18 14:39:58 +0000151 if (NULL == fStencilFuncSeparate ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000152 NULL == fStencilMaskSeparate ||
153 NULL == fStencilOpSeparate) {
154 return false;
155 }
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000156 } else if (kDesktop_GrGLBinding == binding) {
robertphillips@google.come7884302012-04-18 14:39:58 +0000157
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000158 if (glVer >= GR_GL_VER(2,0)) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000159 if (NULL == fStencilFuncSeparate ||
160 NULL == fStencilMaskSeparate ||
161 NULL == fStencilOpSeparate) {
162 return false;
163 }
164 }
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000165 if (glVer >= GR_GL_VER(3,0) && NULL == fBindFragDataLocation) {
bsalomon@google.combc5cf512011-09-21 16:21:07 +0000166 return false;
167 }
bsalomon@google.com1744f972013-02-26 21:46:32 +0000168 if (glVer >= GR_GL_VER(2,0) || extensions.has("GL_ARB_draw_buffers")) {
bsalomon@google.comd32c5f52011-08-02 19:29:03 +0000169 if (NULL == fDrawBuffers) {
170 return false;
171 }
172 }
robertphillips@google.come7884302012-04-18 14:39:58 +0000173
bsalomon@google.com1744f972013-02-26 21:46:32 +0000174 if (glVer >= GR_GL_VER(1,5) || extensions.has("GL_ARB_occlusion_query")) {
bsalomon@google.com373a6632011-10-19 20:43:20 +0000175 if (NULL == fGenQueries ||
176 NULL == fDeleteQueries ||
177 NULL == fBeginQuery ||
178 NULL == fEndQuery ||
179 NULL == fGetQueryiv ||
180 NULL == fGetQueryObjectiv ||
181 NULL == fGetQueryObjectuiv) {
182 return false;
183 }
184 }
185 if (glVer >= GR_GL_VER(3,3) ||
bsalomon@google.com1744f972013-02-26 21:46:32 +0000186 extensions.has("GL_ARB_timer_query") ||
187 extensions.has("GL_EXT_timer_query")) {
bsalomon@google.com373a6632011-10-19 20:43:20 +0000188 if (NULL == fGetQueryObjecti64v ||
189 NULL == fGetQueryObjectui64v) {
190 return false;
191 }
192 }
bsalomon@google.com1744f972013-02-26 21:46:32 +0000193 if (glVer >= GR_GL_VER(3,3) || extensions.has("GL_ARB_timer_query")) {
bsalomon@google.com373a6632011-10-19 20:43:20 +0000194 if (NULL == fQueryCounter) {
195 return false;
196 }
197 }
bsalomon@google.comfe11cb62012-06-06 15:17:54 +0000198 // The below two blocks are checks for functions used with
199 // GL_NV_path_rendering. We're not enforcing that they be non-NULL
200 // because they aren't actually called at this time.
201 if (false &&
bsalomon@google.comd4340e22012-06-06 15:38:52 +0000202 (NULL == fMatrixMode ||
203 NULL == fLoadIdentity ||
204 NULL == fLoadMatrixf)) {
bsalomon@google.comfe11cb62012-06-06 15:17:54 +0000205 return false;
206 }
bsalomon@google.com1744f972013-02-26 21:46:32 +0000207 if (false && extensions.has("GL_NV_path_rendering")) {
bsalomon@google.comfe11cb62012-06-06 15:17:54 +0000208 if (NULL == fPathCommands ||
209 NULL == fPathCoords ||
210 NULL == fPathSubCommands ||
211 NULL == fPathSubCoords ||
212 NULL == fPathString ||
213 NULL == fPathGlyphs ||
214 NULL == fPathGlyphRange ||
215 NULL == fWeightPaths ||
216 NULL == fCopyPath ||
217 NULL == fInterpolatePaths ||
218 NULL == fTransformPath ||
219 NULL == fPathParameteriv ||
220 NULL == fPathParameteri ||
221 NULL == fPathParameterfv ||
222 NULL == fPathParameterf ||
223 NULL == fPathDashArray ||
224 NULL == fGenPaths ||
225 NULL == fDeletePaths ||
226 NULL == fIsPath ||
227 NULL == fPathStencilFunc ||
228 NULL == fPathStencilDepthOffset ||
229 NULL == fStencilFillPath ||
230 NULL == fStencilStrokePath ||
231 NULL == fStencilFillPathInstanced ||
232 NULL == fStencilStrokePathInstanced ||
233 NULL == fPathCoverDepthFunc ||
234 NULL == fPathColorGen ||
235 NULL == fPathTexGen ||
236 NULL == fPathFogGen ||
237 NULL == fCoverFillPath ||
238 NULL == fCoverStrokePath ||
239 NULL == fCoverFillPathInstanced ||
240 NULL == fCoverStrokePathInstanced ||
241 NULL == fGetPathParameteriv ||
242 NULL == fGetPathParameterfv ||
243 NULL == fGetPathCommands ||
244 NULL == fGetPathCoords ||
245 NULL == fGetPathDashArray ||
246 NULL == fGetPathMetrics ||
247 NULL == fGetPathMetricRange ||
248 NULL == fGetPathSpacing ||
249 NULL == fGetPathColorGeniv ||
250 NULL == fGetPathColorGenfv ||
251 NULL == fGetPathTexGeniv ||
252 NULL == fGetPathTexGenfv ||
253 NULL == fIsPointInFillPath ||
254 NULL == fIsPointInStrokePath ||
255 NULL == fGetPathLength ||
256 NULL == fPointAlongPath) {
257 return false;
258 }
259 }
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000260 }
261
262 // optional function on desktop before 1.3
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000263 if (kDesktop_GrGLBinding != binding ||
bsalomon@google.com1744f972013-02-26 21:46:32 +0000264 (glVer >= GR_GL_VER(1,3)) ||
265 extensions.has("GL_ARB_texture_compression")) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000266 if (NULL == fCompressedTexImage2D) {
267 return false;
268 }
269 }
270
bsalomon@google.comd32c5f52011-08-02 19:29:03 +0000271 // part of desktop GL, but not ES
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000272 if (kDesktop_GrGLBinding == binding &&
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000273 (NULL == fLineWidth ||
bsalomon@google.comd32c5f52011-08-02 19:29:03 +0000274 NULL == fGetTexLevelParameteriv ||
bsalomon@google.comc49d66b2011-08-03 14:22:30 +0000275 NULL == fDrawBuffer ||
276 NULL == fReadBuffer)) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000277 return false;
278 }
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000279
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000280 // GL_EXT_texture_storage is part of desktop 4.2
281 // There is a desktop ARB extension and an ES+desktop EXT extension
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000282 if (kDesktop_GrGLBinding == binding) {
bsalomon@google.combaa9ea12012-01-06 19:05:43 +0000283 if (glVer >= GR_GL_VER(4,2) ||
bsalomon@google.com1744f972013-02-26 21:46:32 +0000284 extensions.has("GL_ARB_texture_storage") ||
285 extensions.has("GL_EXT_texture_storage")) {
bsalomon@google.combaa9ea12012-01-06 19:05:43 +0000286 if (NULL == fTexStorage2D) {
287 return false;
288 }
289 }
bsalomon@google.com1744f972013-02-26 21:46:32 +0000290 } else if (extensions.has("GL_EXT_texture_storage")) {
bsalomon@google.combaa9ea12012-01-06 19:05:43 +0000291 if (NULL == fTexStorage2D) {
292 return false;
293 }
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000294 }
295
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000296 if (extensions.has("GL_EXT_discard_framebuffer")) {
297// FIXME: Remove this once Chromium is updated to provide this function
298#if 0
299 if (NULL == fDiscardFramebuffer) {
300 return false;
301 }
302#endif
303 }
304
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000305 // FBO MSAA
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000306 if (kDesktop_GrGLBinding == binding) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000307 // GL 3.0 and the ARB extension have multisample + blit
bsalomon@google.com1744f972013-02-26 21:46:32 +0000308 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_framebuffer_object")) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000309 if (NULL == fRenderbufferStorageMultisample ||
310 NULL == fBlitFramebuffer) {
311 return false;
312 }
313 } else {
bsalomon@google.com1744f972013-02-26 21:46:32 +0000314 if (extensions.has("GL_EXT_framebuffer_blit") &&
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000315 NULL == fBlitFramebuffer) {
316 return false;
317 }
bsalomon@google.com1744f972013-02-26 21:46:32 +0000318 if (extensions.has("GL_EXT_framebuffer_multisample") &&
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000319 NULL == fRenderbufferStorageMultisample) {
320 return false;
321 }
322 }
323 } else {
bsalomon@google.com1744f972013-02-26 21:46:32 +0000324 if (extensions.has("GL_CHROMIUM_framebuffer_multisample")) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000325 if (NULL == fRenderbufferStorageMultisample ||
326 NULL == fBlitFramebuffer) {
327 return false;
328 }
329 }
bsalomon@google.com1744f972013-02-26 21:46:32 +0000330 if (extensions.has("GL_APPLE_framebuffer_multisample")) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000331 if (NULL == fRenderbufferStorageMultisample ||
332 NULL == fResolveMultisampleFramebuffer) {
333 return false;
334 }
335 }
bsalomon@google.com347c3822013-05-01 20:10:01 +0000336 if (extensions.has("GL_IMG_multisampled_render_to_texture") ||
337 extensions.has("GL_EXT_multisampled_render_to_texture")) {
bsalomon@google.comf3a60c02013-03-19 19:06:09 +0000338 if (NULL == fRenderbufferStorageMultisample ||
339 NULL == fFramebufferTexture2DMultisample) {
340 return false;
341 }
342 }
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000343 }
344
345 // On ES buffer mapping is an extension. On Desktop
346 // buffer mapping was part of original VBO extension
347 // which we require.
bsalomon@google.com1744f972013-02-26 21:46:32 +0000348 if (kDesktop_GrGLBinding == binding || extensions.has("GL_OES_mapbuffer")) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000349 if (NULL == fMapBuffer ||
350 NULL == fUnmapBuffer) {
351 return false;
352 }
353 }
354
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000355 // Dual source blending
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000356 if (kDesktop_GrGLBinding == binding &&
bsalomon@google.com1744f972013-02-26 21:46:32 +0000357 (glVer >= GR_GL_VER(3,3) || extensions.has("GL_ARB_blend_func_extended"))) {
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000358 if (NULL == fBindFragDataLocationIndexed) {
359 return false;
360 }
361 }
skia.committer@gmail.com12eea2b2013-02-27 07:10:10 +0000362
bsalomon@google.com1744f972013-02-26 21:46:32 +0000363 if (kDesktop_GrGLBinding == binding && glVer >= GR_GL_VER(3, 0)) {
364 if (NULL == fGetStringi) {
365 return false;
366 }
367 }
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000368
bsalomon@google.comecd84842013-03-01 15:36:02 +0000369 if (kDesktop_GrGLBinding == binding) {
370 if (glVer >= GR_GL_VER(3, 0) || extensions.has("GL_ARB_vertex_array_object")) {
371 if (NULL == fBindVertexArray ||
372 NULL == fDeleteVertexArrays ||
373 NULL == fGenVertexArrays) {
374 return false;
375 }
376 }
377 } else {
bsalomon@google.comecd84842013-03-01 15:36:02 +0000378 if (extensions.has("GL_OES_vertex_array_object")) {
379 if (NULL == fBindVertexArray ||
380 NULL == fDeleteVertexArrays ||
381 NULL == fGenVertexArrays) {
382 return false;
383 }
384 }
bsalomon@google.comecd84842013-03-01 15:36:02 +0000385 }
386
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000387 return true;
388}