blob: bc2600c90ab254072ee5fa28913ceffbf0260ef3 [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
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +000015#if GR_GL_PER_GL_FUNC_CALLBACK
16namespace {
17void GrGLDefaultInterfaceCallback(const GrGLInterface*) {}
18}
19#endif
20
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +000021const GrGLInterface* GrGLInterfaceAddTestDebugMarker(const GrGLInterface* interface,
22 GrGLInsertEventMarkerProc insertEventMarkerFn,
23 GrGLPushGroupMarkerProc pushGroupMarkerFn,
24 GrGLPopGroupMarkerProc popGroupMarkerFn) {
25 GrGLInterface* newInterface = GrGLInterface::NewClone(interface);
26
27 if (!newInterface->fExtensions.has("GL_EXT_debug_marker")) {
28 newInterface->fExtensions.add("GL_EXT_debug_marker");
29 }
30
commit-bot@chromium.orgf5355612014-02-28 20:28:50 +000031 newInterface->fFunctions.fInsertEventMarker = insertEventMarkerFn;
32 newInterface->fFunctions.fPushGroupMarker = pushGroupMarkerFn;
33 newInterface->fFunctions.fPopGroupMarker = popGroupMarkerFn;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +000034
35 return newInterface;
36}
37
commit-bot@chromium.orgd8ed8512014-01-24 20:49:44 +000038const GrGLInterface* GrGLInterfaceRemoveNVPR(const GrGLInterface* interface) {
39 GrGLInterface* newInterface = GrGLInterface::NewClone(interface);
40
41 newInterface->fExtensions.remove("GL_NV_path_rendering");
commit-bot@chromium.orgf5355612014-02-28 20:28:50 +000042 newInterface->fFunctions.fPathCommands = NULL;
43 newInterface->fFunctions.fPathCoords = NULL;
commit-bot@chromium.orgf5355612014-02-28 20:28:50 +000044 newInterface->fFunctions.fPathParameteri = NULL;
commit-bot@chromium.orgf5355612014-02-28 20:28:50 +000045 newInterface->fFunctions.fPathParameterf = NULL;
commit-bot@chromium.orgf5355612014-02-28 20:28:50 +000046 newInterface->fFunctions.fGenPaths = NULL;
47 newInterface->fFunctions.fDeletePaths = NULL;
cdalton8dd90cb2014-07-17 09:28:36 -070048 newInterface->fFunctions.fIsPath = NULL;
commit-bot@chromium.orgf5355612014-02-28 20:28:50 +000049 newInterface->fFunctions.fPathStencilFunc = NULL;
commit-bot@chromium.orgf5355612014-02-28 20:28:50 +000050 newInterface->fFunctions.fStencilFillPath = NULL;
51 newInterface->fFunctions.fStencilStrokePath = NULL;
52 newInterface->fFunctions.fStencilFillPathInstanced = NULL;
53 newInterface->fFunctions.fStencilStrokePathInstanced = NULL;
commit-bot@chromium.orgf5355612014-02-28 20:28:50 +000054 newInterface->fFunctions.fPathTexGen = NULL;
commit-bot@chromium.orgf5355612014-02-28 20:28:50 +000055 newInterface->fFunctions.fCoverFillPath = NULL;
56 newInterface->fFunctions.fCoverStrokePath = NULL;
57 newInterface->fFunctions.fCoverFillPathInstanced = NULL;
58 newInterface->fFunctions.fCoverStrokePathInstanced = NULL;
cdaltonc7103a12014-08-11 14:05:05 -070059 newInterface->fFunctions.fStencilThenCoverFillPath = NULL;
60 newInterface->fFunctions.fStencilThenCoverStrokePath = NULL;
61 newInterface->fFunctions.fStencilThenCoverFillPathInstanced = NULL;
62 newInterface->fFunctions.fStencilThenCoverStrokePathInstanced = NULL;
kkinnunen32b9a3b2014-07-02 22:56:35 -070063 newInterface->fFunctions.fProgramPathFragmentInputGen = NULL;
cdalton149b3ec2014-09-17 09:19:18 -070064 newInterface->fFunctions.fPathMemoryGlyphIndexArray = NULL;
commit-bot@chromium.orgd8ed8512014-01-24 20:49:44 +000065 return newInterface;
66}
67
commit-bot@chromium.orgf5355612014-02-28 20:28:50 +000068GrGLInterface::GrGLInterface() {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000069 fStandard = kNone_GrGLStandard;
bsalomon@google.com0b77d682011-08-19 13:28:54 +000070
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +000071#if GR_GL_PER_GL_FUNC_CALLBACK
72 fCallback = GrGLDefaultInterfaceCallback;
73 fCallbackData = 0;
74#endif
bsalomon@google.com0b77d682011-08-19 13:28:54 +000075}
76
commit-bot@chromium.orgd8ed8512014-01-24 20:49:44 +000077GrGLInterface* GrGLInterface::NewClone(const GrGLInterface* interface) {
bsalomon49f085d2014-09-05 13:34:00 -070078 SkASSERT(interface);
commit-bot@chromium.orgd8ed8512014-01-24 20:49:44 +000079
80 GrGLInterface* clone = SkNEW(GrGLInterface);
81 clone->fStandard = interface->fStandard;
82 clone->fExtensions = interface->fExtensions;
83 clone->fFunctions = interface->fFunctions;
84#if GR_GL_PER_GL_FUNC_CALLBACK
85 clone->fCallback = interface->fCallback;
86 clone->fCallbackData = interface->fCallbackData;
87#endif
88 return clone;
89}
90
commit-bot@chromium.orge83b9b72014-05-01 19:21:41 +000091#ifdef SK_DEBUG
92 static int kIsDebug = 1;
93#else
94 static int kIsDebug = 0;
95#endif
96
97#define RETURN_FALSE_INTERFACE \
98 if (kIsDebug) { SkDebugf("%s:%d GrGLInterface::validate() failed.\n", __FILE__, __LINE__); } \
99 return false;
commit-bot@chromium.orgadadf7c2014-03-24 19:43:02 +0000100
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000101bool GrGLInterface::validate() const {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000102
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000103 if (kNone_GrGLStandard == fStandard) {
commit-bot@chromium.orgadadf7c2014-03-24 19:43:02 +0000104 RETURN_FALSE_INTERFACE
bsalomon@google.com1dcf5062011-11-14 19:29:53 +0000105 }
skia.committer@gmail.com12eea2b2013-02-27 07:10:10 +0000106
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000107 if (!fExtensions.isInitialized()) {
commit-bot@chromium.orgadadf7c2014-03-24 19:43:02 +0000108 RETURN_FALSE_INTERFACE
bsalomon@google.com1744f972013-02-26 21:46:32 +0000109 }
bsalomon@google.com1dcf5062011-11-14 19:29:53 +0000110
111 // functions that are always required
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000112 if (NULL == fFunctions.fActiveTexture ||
113 NULL == fFunctions.fAttachShader ||
114 NULL == fFunctions.fBindAttribLocation ||
115 NULL == fFunctions.fBindBuffer ||
116 NULL == fFunctions.fBindTexture ||
cdaltonbae6f6c2015-04-22 10:39:03 -0700117 NULL == fFunctions.fBlendColor || // -> GL >= 1.4 or extension, ES >= 2.0
bsalomonc9aec1e2015-04-24 11:08:25 -0700118#if 0
119 // TODO: Re-enable validation for fBlendEquation when Chrome has it hooked up.
cdaltonbae6f6c2015-04-22 10:39:03 -0700120 NULL == fFunctions.fBlendEquation || // -> GL >= 1.4 or extension, ES >= 2.0
bsalomonc9aec1e2015-04-24 11:08:25 -0700121#endif
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000122 NULL == fFunctions.fBlendFunc ||
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000123 NULL == fFunctions.fBufferData ||
124 NULL == fFunctions.fBufferSubData ||
125 NULL == fFunctions.fClear ||
126 NULL == fFunctions.fClearColor ||
127 NULL == fFunctions.fClearStencil ||
128 NULL == fFunctions.fColorMask ||
129 NULL == fFunctions.fCompileShader ||
130 NULL == fFunctions.fCopyTexSubImage2D ||
131 NULL == fFunctions.fCreateProgram ||
132 NULL == fFunctions.fCreateShader ||
133 NULL == fFunctions.fCullFace ||
134 NULL == fFunctions.fDeleteBuffers ||
135 NULL == fFunctions.fDeleteProgram ||
136 NULL == fFunctions.fDeleteShader ||
137 NULL == fFunctions.fDeleteTextures ||
138 NULL == fFunctions.fDepthMask ||
139 NULL == fFunctions.fDisable ||
140 NULL == fFunctions.fDisableVertexAttribArray ||
141 NULL == fFunctions.fDrawArrays ||
142 NULL == fFunctions.fDrawElements ||
143 NULL == fFunctions.fEnable ||
144 NULL == fFunctions.fEnableVertexAttribArray ||
145 NULL == fFunctions.fFrontFace ||
146 NULL == fFunctions.fGenBuffers ||
147 NULL == fFunctions.fGenTextures ||
148 NULL == fFunctions.fGetBufferParameteriv ||
149 NULL == fFunctions.fGenerateMipmap ||
150 NULL == fFunctions.fGetError ||
151 NULL == fFunctions.fGetIntegerv ||
152 NULL == fFunctions.fGetProgramInfoLog ||
153 NULL == fFunctions.fGetProgramiv ||
154 NULL == fFunctions.fGetShaderInfoLog ||
155 NULL == fFunctions.fGetShaderiv ||
156 NULL == fFunctions.fGetString ||
157 NULL == fFunctions.fGetUniformLocation ||
158 NULL == fFunctions.fLinkProgram ||
159 NULL == fFunctions.fLineWidth ||
160 NULL == fFunctions.fPixelStorei ||
161 NULL == fFunctions.fReadPixels ||
162 NULL == fFunctions.fScissor ||
163 NULL == fFunctions.fShaderSource ||
164 NULL == fFunctions.fStencilFunc ||
165 NULL == fFunctions.fStencilMask ||
166 NULL == fFunctions.fStencilOp ||
167 NULL == fFunctions.fTexImage2D ||
168 NULL == fFunctions.fTexParameteri ||
169 NULL == fFunctions.fTexParameteriv ||
170 NULL == fFunctions.fTexSubImage2D ||
171 NULL == fFunctions.fUniform1f ||
172 NULL == fFunctions.fUniform1i ||
173 NULL == fFunctions.fUniform1fv ||
174 NULL == fFunctions.fUniform1iv ||
175 NULL == fFunctions.fUniform2f ||
176 NULL == fFunctions.fUniform2i ||
177 NULL == fFunctions.fUniform2fv ||
178 NULL == fFunctions.fUniform2iv ||
179 NULL == fFunctions.fUniform3f ||
180 NULL == fFunctions.fUniform3i ||
181 NULL == fFunctions.fUniform3fv ||
182 NULL == fFunctions.fUniform3iv ||
183 NULL == fFunctions.fUniform4f ||
184 NULL == fFunctions.fUniform4i ||
185 NULL == fFunctions.fUniform4fv ||
186 NULL == fFunctions.fUniform4iv ||
187 NULL == fFunctions.fUniformMatrix2fv ||
188 NULL == fFunctions.fUniformMatrix3fv ||
189 NULL == fFunctions.fUniformMatrix4fv ||
190 NULL == fFunctions.fUseProgram ||
egdaniel27c15212014-10-24 15:00:50 -0700191 NULL == fFunctions.fVertexAttrib1f ||
192 NULL == fFunctions.fVertexAttrib2fv ||
193 NULL == fFunctions.fVertexAttrib3fv ||
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000194 NULL == fFunctions.fVertexAttrib4fv ||
195 NULL == fFunctions.fVertexAttribPointer ||
196 NULL == fFunctions.fViewport ||
197 NULL == fFunctions.fBindFramebuffer ||
198 NULL == fFunctions.fBindRenderbuffer ||
199 NULL == fFunctions.fCheckFramebufferStatus ||
200 NULL == fFunctions.fDeleteFramebuffers ||
201 NULL == fFunctions.fDeleteRenderbuffers ||
202 NULL == fFunctions.fFinish ||
203 NULL == fFunctions.fFlush ||
204 NULL == fFunctions.fFramebufferRenderbuffer ||
205 NULL == fFunctions.fFramebufferTexture2D ||
206 NULL == fFunctions.fGetFramebufferAttachmentParameteriv ||
207 NULL == fFunctions.fGetRenderbufferParameteriv ||
208 NULL == fFunctions.fGenFramebuffers ||
209 NULL == fFunctions.fGenRenderbuffers ||
210 NULL == fFunctions.fRenderbufferStorage) {
commit-bot@chromium.orgadadf7c2014-03-24 19:43:02 +0000211 RETURN_FALSE_INTERFACE
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000212 }
213
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000214 GrGLVersion glVer = GrGLGetVersion(this);
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +0000215 if (GR_GL_INVALID_VER == glVer) {
216 RETURN_FALSE_INTERFACE
217 }
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000218
219 // Now check that baseline ES/Desktop fns not covered above are present
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000220 // and that we have fn pointers for any advertised fExtensions that we will
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000221 // try to use.
222
223 // these functions are part of ES2, we assume they are available
224 // On the desktop we assume they are available if the extension
225 // is present or GL version is high enough.
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000226 if (kGLES_GrGLStandard == fStandard) {
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000227 if (NULL == fFunctions.fStencilFuncSeparate ||
228 NULL == fFunctions.fStencilMaskSeparate ||
229 NULL == fFunctions.fStencilOpSeparate) {
commit-bot@chromium.orgadadf7c2014-03-24 19:43:02 +0000230 RETURN_FALSE_INTERFACE
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000231 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000232 } else if (kGL_GrGLStandard == fStandard) {
robertphillips@google.come7884302012-04-18 14:39:58 +0000233
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000234 if (glVer >= GR_GL_VER(2,0)) {
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000235 if (NULL == fFunctions.fStencilFuncSeparate ||
236 NULL == fFunctions.fStencilMaskSeparate ||
237 NULL == fFunctions.fStencilOpSeparate) {
commit-bot@chromium.orgadadf7c2014-03-24 19:43:02 +0000238 RETURN_FALSE_INTERFACE
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000239 }
240 }
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000241 if (glVer >= GR_GL_VER(3,0) && NULL == fFunctions.fBindFragDataLocation) {
commit-bot@chromium.orgadadf7c2014-03-24 19:43:02 +0000242 RETURN_FALSE_INTERFACE
bsalomon@google.combc5cf512011-09-21 16:21:07 +0000243 }
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000244 if (glVer >= GR_GL_VER(2,0) || fExtensions.has("GL_ARB_draw_buffers")) {
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000245 if (NULL == fFunctions.fDrawBuffers) {
commit-bot@chromium.orgadadf7c2014-03-24 19:43:02 +0000246 RETURN_FALSE_INTERFACE
bsalomon@google.comd32c5f52011-08-02 19:29:03 +0000247 }
248 }
robertphillips@google.come7884302012-04-18 14:39:58 +0000249
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000250 if (glVer >= GR_GL_VER(1,5) || fExtensions.has("GL_ARB_occlusion_query")) {
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000251 if (NULL == fFunctions.fGenQueries ||
252 NULL == fFunctions.fDeleteQueries ||
253 NULL == fFunctions.fBeginQuery ||
254 NULL == fFunctions.fEndQuery ||
255 NULL == fFunctions.fGetQueryiv ||
256 NULL == fFunctions.fGetQueryObjectiv ||
257 NULL == fFunctions.fGetQueryObjectuiv) {
commit-bot@chromium.orgadadf7c2014-03-24 19:43:02 +0000258 RETURN_FALSE_INTERFACE
bsalomon@google.com373a6632011-10-19 20:43:20 +0000259 }
260 }
261 if (glVer >= GR_GL_VER(3,3) ||
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000262 fExtensions.has("GL_ARB_timer_query") ||
263 fExtensions.has("GL_EXT_timer_query")) {
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000264 if (NULL == fFunctions.fGetQueryObjecti64v ||
265 NULL == fFunctions.fGetQueryObjectui64v) {
commit-bot@chromium.orgadadf7c2014-03-24 19:43:02 +0000266 RETURN_FALSE_INTERFACE
bsalomon@google.com373a6632011-10-19 20:43:20 +0000267 }
268 }
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000269 if (glVer >= GR_GL_VER(3,3) || fExtensions.has("GL_ARB_timer_query")) {
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000270 if (NULL == fFunctions.fQueryCounter) {
commit-bot@chromium.orgadadf7c2014-03-24 19:43:02 +0000271 RETURN_FALSE_INTERFACE
bsalomon@google.com373a6632011-10-19 20:43:20 +0000272 }
273 }
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000274 }
275
276 // optional function on desktop before 1.3
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000277 if (kGL_GrGLStandard != fStandard ||
bsalomon@google.com1744f972013-02-26 21:46:32 +0000278 (glVer >= GR_GL_VER(1,3)) ||
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000279 fExtensions.has("GL_ARB_texture_compression")) {
krajcevskie1f5a232014-06-11 16:08:50 -0700280 if (NULL == fFunctions.fCompressedTexImage2D
bsalomonc9aec1e2015-04-24 11:08:25 -0700281#if 0
krajcevskie1f5a232014-06-11 16:08:50 -0700282 || NULL == fFunctions.fCompressedTexSubImage2D
bsalomonc9aec1e2015-04-24 11:08:25 -0700283#endif
krajcevskie1f5a232014-06-11 16:08:50 -0700284 ) {
commit-bot@chromium.orgadadf7c2014-03-24 19:43:02 +0000285 RETURN_FALSE_INTERFACE
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000286 }
287 }
288
bsalomon@google.comd32c5f52011-08-02 19:29:03 +0000289 // part of desktop GL, but not ES
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000290 if (kGL_GrGLStandard == fStandard &&
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000291 (NULL == fFunctions.fGetTexLevelParameteriv ||
292 NULL == fFunctions.fDrawBuffer ||
293 NULL == fFunctions.fReadBuffer)) {
commit-bot@chromium.orgadadf7c2014-03-24 19:43:02 +0000294 RETURN_FALSE_INTERFACE
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000295 }
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000296
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000297 // GL_EXT_texture_storage is part of desktop 4.2
298 // There is a desktop ARB extension and an ES+desktop EXT extension
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000299 if (kGL_GrGLStandard == fStandard) {
bsalomon@google.combaa9ea12012-01-06 19:05:43 +0000300 if (glVer >= GR_GL_VER(4,2) ||
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000301 fExtensions.has("GL_ARB_texture_storage") ||
302 fExtensions.has("GL_EXT_texture_storage")) {
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000303 if (NULL == fFunctions.fTexStorage2D) {
commit-bot@chromium.orgadadf7c2014-03-24 19:43:02 +0000304 RETURN_FALSE_INTERFACE
bsalomon@google.combaa9ea12012-01-06 19:05:43 +0000305 }
306 }
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000307 } else if (glVer >= GR_GL_VER(3,0) || fExtensions.has("GL_EXT_texture_storage")) {
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000308 if (NULL == fFunctions.fTexStorage2D) {
commit-bot@chromium.orgadadf7c2014-03-24 19:43:02 +0000309 RETURN_FALSE_INTERFACE
bsalomon@google.combaa9ea12012-01-06 19:05:43 +0000310 }
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000311 }
312
cdaltonfd4167d2015-04-21 11:45:56 -0700313 // glTextureBarrier is part of desktop 4.5. There are also ARB and NV extensions.
314 if (kGL_GrGLStandard == fStandard) {
315 if (glVer >= GR_GL_VER(4,5) ||
316 fExtensions.has("GL_ARB_texture_barrier") ||
317 fExtensions.has("GL_NV_texture_barrier")) {
318 if (NULL == fFunctions.fTextureBarrier) {
319 RETURN_FALSE_INTERFACE
320 }
321 }
322 } else if (fExtensions.has("GL_NV_texture_barrier")) {
323 if (NULL == fFunctions.fTextureBarrier) {
324 RETURN_FALSE_INTERFACE
325 }
326 }
327
bsalomonc9aec1e2015-04-24 11:08:25 -0700328// FIXME: Remove this once Chromium is updated to provide this function
329#if 0
cdaltonbae6f6c2015-04-22 10:39:03 -0700330 if (fExtensions.has("GL_KHR_blend_equation_advanced") ||
331 fExtensions.has("GL_NV_blend_equation_advanced")) {
332 if (NULL == fFunctions.fBlendBarrier) {
333 RETURN_FALSE_INTERFACE
334 }
335 }
bsalomonc9aec1e2015-04-24 11:08:25 -0700336#endif
cdaltonbae6f6c2015-04-22 10:39:03 -0700337
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000338 if (fExtensions.has("GL_EXT_discard_framebuffer")) {
bsalomonc9aec1e2015-04-24 11:08:25 -0700339// FIXME: Remove this once Chromium is updated to provide this function
340#if 0
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000341 if (NULL == fFunctions.fDiscardFramebuffer) {
commit-bot@chromium.orgadadf7c2014-03-24 19:43:02 +0000342 RETURN_FALSE_INTERFACE
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000343 }
bsalomonc9aec1e2015-04-24 11:08:25 -0700344#endif
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000345 }
346
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000347 // FBO MSAA
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000348 if (kGL_GrGLStandard == fStandard) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000349 // GL 3.0 and the ARB extension have multisample + blit
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000350 if (glVer >= GR_GL_VER(3,0) || fExtensions.has("GL_ARB_framebuffer_object")) {
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000351 if (NULL == fFunctions.fRenderbufferStorageMultisample ||
352 NULL == fFunctions.fBlitFramebuffer) {
commit-bot@chromium.orgadadf7c2014-03-24 19:43:02 +0000353 RETURN_FALSE_INTERFACE
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000354 }
355 } else {
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000356 if (fExtensions.has("GL_EXT_framebuffer_blit") &&
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000357 NULL == fFunctions.fBlitFramebuffer) {
commit-bot@chromium.orgadadf7c2014-03-24 19:43:02 +0000358 RETURN_FALSE_INTERFACE
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000359 }
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000360 if (fExtensions.has("GL_EXT_framebuffer_multisample") &&
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000361 NULL == fFunctions.fRenderbufferStorageMultisample) {
commit-bot@chromium.orgadadf7c2014-03-24 19:43:02 +0000362 RETURN_FALSE_INTERFACE
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000363 }
364 }
365 } else {
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000366 if (glVer >= GR_GL_VER(3,0) || fExtensions.has("GL_CHROMIUM_framebuffer_multisample")) {
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000367 if (NULL == fFunctions.fRenderbufferStorageMultisample ||
368 NULL == fFunctions.fBlitFramebuffer) {
commit-bot@chromium.orgadadf7c2014-03-24 19:43:02 +0000369 RETURN_FALSE_INTERFACE
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000370 }
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000371 }
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000372 if (fExtensions.has("GL_APPLE_framebuffer_multisample")) {
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000373 if (NULL == fFunctions.fRenderbufferStorageMultisampleES2APPLE ||
374 NULL == fFunctions.fResolveMultisampleFramebuffer) {
commit-bot@chromium.orgadadf7c2014-03-24 19:43:02 +0000375 RETURN_FALSE_INTERFACE
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000376 }
377 }
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000378 if (fExtensions.has("GL_IMG_multisampled_render_to_texture") ||
379 fExtensions.has("GL_EXT_multisampled_render_to_texture")) {
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000380 if (NULL == fFunctions.fRenderbufferStorageMultisampleES2EXT ||
381 NULL == fFunctions.fFramebufferTexture2DMultisample) {
commit-bot@chromium.orgadadf7c2014-03-24 19:43:02 +0000382 RETURN_FALSE_INTERFACE
bsalomon@google.comf3a60c02013-03-19 19:06:09 +0000383 }
384 }
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000385 }
386
387 // On ES buffer mapping is an extension. On Desktop
388 // buffer mapping was part of original VBO extension
389 // which we require.
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000390 if (kGL_GrGLStandard == fStandard || fExtensions.has("GL_OES_mapbuffer")) {
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000391 if (NULL == fFunctions.fMapBuffer ||
392 NULL == fFunctions.fUnmapBuffer) {
commit-bot@chromium.orgadadf7c2014-03-24 19:43:02 +0000393 RETURN_FALSE_INTERFACE
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000394 }
395 }
396
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000397 // Dual source blending
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000398 if (kGL_GrGLStandard == fStandard &&
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000399 (glVer >= GR_GL_VER(3,3) || fExtensions.has("GL_ARB_blend_func_extended"))) {
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000400 if (NULL == fFunctions.fBindFragDataLocationIndexed) {
commit-bot@chromium.orgadadf7c2014-03-24 19:43:02 +0000401 RETURN_FALSE_INTERFACE
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000402 }
403 }
skia.committer@gmail.com12eea2b2013-02-27 07:10:10 +0000404
commit-bot@chromium.org726e6212013-08-23 20:55:46 +0000405 // glGetStringi was added in version 3.0 of both desktop and ES.
406 if (glVer >= GR_GL_VER(3, 0)) {
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000407 if (NULL == fFunctions.fGetStringi) {
commit-bot@chromium.orgadadf7c2014-03-24 19:43:02 +0000408 RETURN_FALSE_INTERFACE
bsalomon@google.com1744f972013-02-26 21:46:32 +0000409 }
410 }
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000411
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000412 if (kGL_GrGLStandard == fStandard) {
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000413 if (glVer >= GR_GL_VER(3, 0) || fExtensions.has("GL_ARB_vertex_array_object")) {
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000414 if (NULL == fFunctions.fBindVertexArray ||
415 NULL == fFunctions.fDeleteVertexArrays ||
416 NULL == fFunctions.fGenVertexArrays) {
commit-bot@chromium.orgadadf7c2014-03-24 19:43:02 +0000417 RETURN_FALSE_INTERFACE
bsalomon@google.comecd84842013-03-01 15:36:02 +0000418 }
419 }
420 } else {
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000421 if (glVer >= GR_GL_VER(3,0) || fExtensions.has("GL_OES_vertex_array_object")) {
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000422 if (NULL == fFunctions.fBindVertexArray ||
423 NULL == fFunctions.fDeleteVertexArrays ||
424 NULL == fFunctions.fGenVertexArrays) {
commit-bot@chromium.orgadadf7c2014-03-24 19:43:02 +0000425 RETURN_FALSE_INTERFACE
bsalomon@google.comecd84842013-03-01 15:36:02 +0000426 }
427 }
bsalomon@google.comecd84842013-03-01 15:36:02 +0000428 }
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000429
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000430 if (fExtensions.has("GL_EXT_debug_marker")) {
431 if (NULL == fFunctions.fInsertEventMarker ||
432 NULL == fFunctions.fPushGroupMarker ||
433 NULL == fFunctions.fPopGroupMarker) {
commit-bot@chromium.orgadadf7c2014-03-24 19:43:02 +0000434 RETURN_FALSE_INTERFACE
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000435 }
436 }
bsalomon@google.coma34bb602014-04-01 13:07:29 +0000437
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000438 if ((kGL_GrGLStandard == fStandard && glVer >= GR_GL_VER(4,3)) ||
439 fExtensions.has("GL_ARB_invalidate_subdata")) {
bsalomon@google.coma34bb602014-04-01 13:07:29 +0000440 if (NULL == fFunctions.fInvalidateBufferData ||
441 NULL == fFunctions.fInvalidateBufferSubData ||
442 NULL == fFunctions.fInvalidateFramebuffer ||
443 NULL == fFunctions.fInvalidateSubFramebuffer ||
444 NULL == fFunctions.fInvalidateTexImage ||
445 NULL == fFunctions.fInvalidateTexSubImage) {
446 RETURN_FALSE_INTERFACE;
447 }
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000448 } else if (kGLES_GrGLStandard == fStandard && glVer >= GR_GL_VER(3,0)) {
bsalomon@google.coma34bb602014-04-01 13:07:29 +0000449 // ES 3.0 adds the framebuffer functions but not the others.
450 if (NULL == fFunctions.fInvalidateFramebuffer ||
451 NULL == fFunctions.fInvalidateSubFramebuffer) {
452 RETURN_FALSE_INTERFACE;
453 }
454 }
commit-bot@chromium.orgbeb8b3a2014-04-15 15:37:51 +0000455
456 if (kGLES_GrGLStandard == fStandard && fExtensions.has("GL_CHROMIUM_map_sub")) {
457 if (NULL == fFunctions.fMapBufferSubData ||
458 NULL == fFunctions.fMapTexSubImage2D ||
459 NULL == fFunctions.fUnmapBufferSubData ||
460 NULL == fFunctions.fUnmapTexSubImage2D) {
461 RETURN_FALSE_INTERFACE;
462 }
463 }
bsalomon@google.coma34bb602014-04-01 13:07:29 +0000464
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000465 // These functions are added to the 3.0 version of both GLES and GL.
466 if (glVer >= GR_GL_VER(3,0) ||
467 (kGLES_GrGLStandard == fStandard && fExtensions.has("GL_EXT_map_buffer_range")) ||
468 (kGL_GrGLStandard == fStandard && fExtensions.has("GL_ARB_map_buffer_range"))) {
469 if (NULL == fFunctions.fMapBufferRange ||
470 NULL == fFunctions.fFlushMappedBufferRange) {
471 RETURN_FALSE_INTERFACE;
472 }
473 }
kkinnunen32b9a3b2014-07-02 22:56:35 -0700474
475 if ((kGL_GrGLStandard == fStandard && fExtensions.has("GL_EXT_direct_state_access")) ||
476 (kGLES_GrGLStandard == fStandard && fExtensions.has("GL_NV_path_rendering"))) {
477 if (NULL == fFunctions.fMatrixLoadf ||
478 NULL == fFunctions.fMatrixLoadIdentity) {
479 RETURN_FALSE_INTERFACE
480 }
481 }
482
483 if ((kGL_GrGLStandard == fStandard &&
484 (glVer >= GR_GL_VER(4,3) || fExtensions.has("GL_ARB_program_interface_query"))) ||
485 (kGLES_GrGLStandard == fStandard && glVer >= GR_GL_VER(3,1))) {
486 if (NULL == fFunctions.fGetProgramResourceLocation) {
487 RETURN_FALSE_INTERFACE
488 }
489 }
490
bsalomonee64d6e2014-12-03 10:46:08 -0800491 if (kGLES_GrGLStandard == fStandard || glVer >= GR_GL_VER(4,1) ||
492 fExtensions.has("GL_ARB_ES2_compatibility")) {
bsalomonc9aec1e2015-04-24 11:08:25 -0700493#if 0 // Enable this once Chrome gives us the function ptr
bsalomonee64d6e2014-12-03 10:46:08 -0800494 if (NULL == fFunctions.fGetShaderPrecisionFormat) {
495 RETURN_FALSE_INTERFACE
496 }
bsalomonc9aec1e2015-04-24 11:08:25 -0700497#endif
bsalomonee64d6e2014-12-03 10:46:08 -0800498 }
499
kkinnunen32b9a3b2014-07-02 22:56:35 -0700500 if (fExtensions.has("GL_NV_path_rendering")) {
501 if (NULL == fFunctions.fPathCommands ||
502 NULL == fFunctions.fPathCoords ||
503 NULL == fFunctions.fPathParameteri ||
504 NULL == fFunctions.fPathParameterf ||
505 NULL == fFunctions.fGenPaths ||
506 NULL == fFunctions.fDeletePaths ||
cdalton8dd90cb2014-07-17 09:28:36 -0700507 NULL == fFunctions.fIsPath ||
kkinnunen32b9a3b2014-07-02 22:56:35 -0700508 NULL == fFunctions.fPathStencilFunc ||
509 NULL == fFunctions.fStencilFillPath ||
510 NULL == fFunctions.fStencilStrokePath ||
511 NULL == fFunctions.fStencilFillPathInstanced ||
512 NULL == fFunctions.fStencilStrokePathInstanced ||
513 NULL == fFunctions.fCoverFillPath ||
514 NULL == fFunctions.fCoverStrokePath ||
515 NULL == fFunctions.fCoverFillPathInstanced ||
cdaltonc7103a12014-08-11 14:05:05 -0700516 NULL == fFunctions.fCoverStrokePathInstanced) {
kkinnunen32b9a3b2014-07-02 22:56:35 -0700517 RETURN_FALSE_INTERFACE
518 }
cdaltonc7103a12014-08-11 14:05:05 -0700519 if (kGL_GrGLStandard == fStandard) {
520 // Some methods only exist on desktop
521 if (NULL == fFunctions.fPathTexGen) {
522 RETURN_FALSE_INTERFACE
523 }
524 } else {
525 // All additions through v1.3 exist on GLES
526 if (NULL == fFunctions.fStencilThenCoverFillPath ||
527 NULL == fFunctions.fStencilThenCoverStrokePath ||
528 NULL == fFunctions.fStencilThenCoverFillPathInstanced ||
529 NULL == fFunctions.fStencilThenCoverStrokePathInstanced ||
cdalton149b3ec2014-09-17 09:19:18 -0700530 NULL == fFunctions.fProgramPathFragmentInputGen ||
531 NULL == fFunctions.fPathMemoryGlyphIndexArray) {
cdaltonc7103a12014-08-11 14:05:05 -0700532 RETURN_FALSE_INTERFACE
533 }
kkinnunen32b9a3b2014-07-02 22:56:35 -0700534 }
535 }
536
vbuzinov08b4d292015-04-01 06:29:49 -0700537 if (fExtensions.has("GL_NV_framebuffer_mixed_samples")) {
538 if (NULL == fFunctions.fCoverageModulation) {
539 RETURN_FALSE_INTERFACE
540 }
541 }
542
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000543 return true;
544}