blob: a86c143b1779ad5afe2f7d15b48660d4f844b88a [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.com9c1f1ac2012-05-07 17:09:37 +000010#include "GrGLUtil.h"
twiz@google.com59a190b2011-03-14 21:23:01 +000011
12#include <stdio.h>
13
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +000014#if GR_GL_PER_GL_FUNC_CALLBACK
15namespace {
16void GrGLDefaultInterfaceCallback(const GrGLInterface*) {}
17}
18#endif
19
bsalomon@google.com0b77d682011-08-19 13:28:54 +000020GrGLInterface::GrGLInterface() {
bsalomon@google.com89ec61e2012-02-10 20:05:18 +000021 fBindingsExported = kNone_GrGLBinding;
bsalomon@google.com0b77d682011-08-19 13:28:54 +000022
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +000023#if GR_GL_PER_GL_FUNC_CALLBACK
24 fCallback = GrGLDefaultInterfaceCallback;
25 fCallbackData = 0;
26#endif
bsalomon@google.com0b77d682011-08-19 13:28:54 +000027}
28
bsalomon@google.com89ec61e2012-02-10 20:05:18 +000029bool GrGLInterface::validate(GrGLBinding binding) const {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000030
bsalomon@google.com89ec61e2012-02-10 20:05:18 +000031 // kNone must be 0 so that the check we're about to do can never succeed if
32 // binding == kNone.
33 GR_STATIC_ASSERT(kNone_GrGLBinding == 0);
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000034
bsalomon@google.com89ec61e2012-02-10 20:05:18 +000035 if (0 == (binding & fBindingsExported)) {
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000036 return false;
37 }
38
39 // functions that are always required
40 if (NULL == fActiveTexture ||
41 NULL == fAttachShader ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000042 NULL == fBindAttribLocation ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000043 NULL == fBindBuffer ||
44 NULL == fBindTexture ||
45 NULL == fBlendFunc ||
robertphillips@google.come7884302012-04-18 14:39:58 +000046 NULL == fBlendColor || // -> GL >= 1.4, ES >= 2.0 or extension
47 NULL == fBlendEquation || // -> GL >= 1.4, ES >= 2.0 or extension
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000048 NULL == fBufferData ||
49 NULL == fBufferSubData ||
50 NULL == fClear ||
51 NULL == fClearColor ||
52 NULL == fClearStencil ||
53 NULL == fColorMask ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000054 NULL == fCompileShader ||
55 NULL == fCreateProgram ||
56 NULL == fCreateShader ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000057 NULL == fCullFace ||
58 NULL == fDeleteBuffers ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000059 NULL == fDeleteProgram ||
60 NULL == fDeleteShader ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000061 NULL == fDeleteTextures ||
62 NULL == fDepthMask ||
63 NULL == fDisable ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000064 NULL == fDisableVertexAttribArray ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000065 NULL == fDrawArrays ||
66 NULL == fDrawElements ||
67 NULL == fEnable ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000068 NULL == fEnableVertexAttribArray ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000069 NULL == fFrontFace ||
70 NULL == fGenBuffers ||
71 NULL == fGenTextures ||
72 NULL == fGetBufferParameteriv ||
73 NULL == fGetError ||
74 NULL == fGetIntegerv ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000075 NULL == fGetProgramInfoLog ||
76 NULL == fGetProgramiv ||
77 NULL == fGetShaderInfoLog ||
78 NULL == fGetShaderiv ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000079 NULL == fGetString ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000080 NULL == fGetUniformLocation ||
81 NULL == fLinkProgram ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000082 NULL == fPixelStorei ||
83 NULL == fReadPixels ||
84 NULL == fScissor ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000085 NULL == fShaderSource ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000086 NULL == fStencilFunc ||
87 NULL == fStencilMask ||
88 NULL == fStencilOp ||
89 NULL == fTexImage2D ||
90 NULL == fTexParameteri ||
91 NULL == fTexSubImage2D ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +000092 NULL == fUniform1f ||
93 NULL == fUniform1i ||
94 NULL == fUniform1fv ||
95 NULL == fUniform1iv ||
96 NULL == fUniform2f ||
97 NULL == fUniform2i ||
98 NULL == fUniform2fv ||
99 NULL == fUniform2iv ||
100 NULL == fUniform3f ||
101 NULL == fUniform3i ||
102 NULL == fUniform3fv ||
103 NULL == fUniform3iv ||
104 NULL == fUniform4f ||
105 NULL == fUniform4i ||
106 NULL == fUniform4fv ||
107 NULL == fUniform4iv ||
108 NULL == fUniformMatrix2fv ||
109 NULL == fUniformMatrix3fv ||
110 NULL == fUniformMatrix4fv ||
111 NULL == fUseProgram ||
112 NULL == fVertexAttrib4fv ||
bsalomon@google.com1dcf5062011-11-14 19:29:53 +0000113 NULL == fVertexAttribPointer ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000114 NULL == fViewport ||
115 NULL == fBindFramebuffer ||
116 NULL == fBindRenderbuffer ||
117 NULL == fCheckFramebufferStatus ||
118 NULL == fDeleteFramebuffers ||
119 NULL == fDeleteRenderbuffers ||
bsalomon@google.com373a6632011-10-19 20:43:20 +0000120 NULL == fFinish ||
121 NULL == fFlush ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000122 NULL == fFramebufferRenderbuffer ||
123 NULL == fFramebufferTexture2D ||
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000124 NULL == fGetFramebufferAttachmentParameteriv ||
125 NULL == fGetRenderbufferParameteriv ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000126 NULL == fGenFramebuffers ||
127 NULL == fGenRenderbuffers ||
128 NULL == fRenderbufferStorage) {
129 return false;
130 }
131
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000132 const char* ext;
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000133 GrGLVersion glVer = GrGLGetVersion(this);
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000134 ext = (const char*)fGetString(GR_GL_EXTENSIONS);
135
136 // Now check that baseline ES/Desktop fns not covered above are present
137 // and that we have fn pointers for any advertised extensions that we will
138 // try to use.
139
140 // these functions are part of ES2, we assume they are available
141 // On the desktop we assume they are available if the extension
142 // is present or GL version is high enough.
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000143 if (kES2_GrGLBinding == binding) {
robertphillips@google.come7884302012-04-18 14:39:58 +0000144 if (NULL == fStencilFuncSeparate ||
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000145 NULL == fStencilMaskSeparate ||
146 NULL == fStencilOpSeparate) {
147 return false;
148 }
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000149 } else if (kDesktop_GrGLBinding == binding) {
robertphillips@google.come7884302012-04-18 14:39:58 +0000150
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000151 if (glVer >= GR_GL_VER(2,0)) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000152 if (NULL == fStencilFuncSeparate ||
153 NULL == fStencilMaskSeparate ||
154 NULL == fStencilOpSeparate) {
155 return false;
156 }
157 }
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000158 if (glVer >= GR_GL_VER(3,0) && NULL == fBindFragDataLocation) {
bsalomon@google.combc5cf512011-09-21 16:21:07 +0000159 return false;
160 }
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000161 if (glVer >= GR_GL_VER(2,0) ||
162 GrGLHasExtensionFromString("GL_ARB_draw_buffers", ext)) {
bsalomon@google.comd32c5f52011-08-02 19:29:03 +0000163 if (NULL == fDrawBuffers) {
164 return false;
165 }
166 }
robertphillips@google.come7884302012-04-18 14:39:58 +0000167
bsalomon@google.com373a6632011-10-19 20:43:20 +0000168 if (glVer >= GR_GL_VER(1,5) ||
169 GrGLHasExtensionFromString("GL_ARB_occlusion_query", ext)) {
170 if (NULL == fGenQueries ||
171 NULL == fDeleteQueries ||
172 NULL == fBeginQuery ||
173 NULL == fEndQuery ||
174 NULL == fGetQueryiv ||
175 NULL == fGetQueryObjectiv ||
176 NULL == fGetQueryObjectuiv) {
177 return false;
178 }
179 }
180 if (glVer >= GR_GL_VER(3,3) ||
181 GrGLHasExtensionFromString("GL_ARB_timer_query", ext) ||
182 GrGLHasExtensionFromString("GL_EXT_timer_query", ext)) {
183 if (NULL == fGetQueryObjecti64v ||
184 NULL == fGetQueryObjectui64v) {
185 return false;
186 }
187 }
188 if (glVer >= GR_GL_VER(3,3) ||
189 GrGLHasExtensionFromString("GL_ARB_timer_query", ext)) {
190 if (NULL == fQueryCounter) {
191 return false;
192 }
193 }
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000194 }
195
196 // optional function on desktop before 1.3
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000197 if (kDesktop_GrGLBinding != binding ||
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000198 (glVer >= GR_GL_VER(1,3) ||
199 GrGLHasExtensionFromString("GL_ARB_texture_compression", ext))) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000200 if (NULL == fCompressedTexImage2D) {
201 return false;
202 }
203 }
204
bsalomon@google.comd32c5f52011-08-02 19:29:03 +0000205 // part of desktop GL, but not ES
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000206 if (kDesktop_GrGLBinding == binding &&
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000207 (NULL == fLineWidth ||
bsalomon@google.comd32c5f52011-08-02 19:29:03 +0000208 NULL == fGetTexLevelParameteriv ||
bsalomon@google.comc49d66b2011-08-03 14:22:30 +0000209 NULL == fDrawBuffer ||
210 NULL == fReadBuffer)) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000211 return false;
212 }
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000213
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000214 // GL_EXT_texture_storage is part of desktop 4.2
215 // There is a desktop ARB extension and an ES+desktop EXT extension
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000216 if (kDesktop_GrGLBinding == binding) {
bsalomon@google.combaa9ea12012-01-06 19:05:43 +0000217 if (glVer >= GR_GL_VER(4,2) ||
218 GrGLHasExtensionFromString("GL_ARB_texture_storage", ext) ||
219 GrGLHasExtensionFromString("GL_EXT_texture_storage", ext)) {
220 if (NULL == fTexStorage2D) {
221 return false;
222 }
223 }
224 } else if (GrGLHasExtensionFromString("GL_EXT_texture_storage", ext)) {
225 if (NULL == fTexStorage2D) {
226 return false;
227 }
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000228 }
229
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000230 // FBO MSAA
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000231 if (kDesktop_GrGLBinding == binding) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000232 // GL 3.0 and the ARB extension have multisample + blit
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000233 if (glVer >= GR_GL_VER(3,0) || GrGLHasExtensionFromString("GL_ARB_framebuffer_object", ext)) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000234 if (NULL == fRenderbufferStorageMultisample ||
235 NULL == fBlitFramebuffer) {
236 return false;
237 }
238 } else {
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000239 if (GrGLHasExtensionFromString("GL_EXT_framebuffer_blit", ext) &&
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000240 NULL == fBlitFramebuffer) {
241 return false;
242 }
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000243 if (GrGLHasExtensionFromString("GL_EXT_framebuffer_multisample", ext) &&
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000244 NULL == fRenderbufferStorageMultisample) {
245 return false;
246 }
247 }
248 } else {
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000249 if (GrGLHasExtensionFromString("GL_CHROMIUM_framebuffer_multisample", ext)) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000250 if (NULL == fRenderbufferStorageMultisample ||
251 NULL == fBlitFramebuffer) {
252 return false;
253 }
254 }
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000255 if (GrGLHasExtensionFromString("GL_APPLE_framebuffer_multisample", ext)) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000256 if (NULL == fRenderbufferStorageMultisample ||
257 NULL == fResolveMultisampleFramebuffer) {
258 return false;
259 }
260 }
261 }
262
263 // On ES buffer mapping is an extension. On Desktop
264 // buffer mapping was part of original VBO extension
265 // which we require.
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000266 if (kDesktop_GrGLBinding == binding ||
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000267 GrGLHasExtensionFromString("GL_OES_mapbuffer", ext)) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000268 if (NULL == fMapBuffer ||
269 NULL == fUnmapBuffer) {
270 return false;
271 }
272 }
273
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000274 // Dual source blending
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000275 if (kDesktop_GrGLBinding == binding &&
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000276 (glVer >= GR_GL_VER(3,3) ||
277 GrGLHasExtensionFromString("GL_ARB_blend_func_extended", ext))) {
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000278 if (NULL == fBindFragDataLocationIndexed) {
279 return false;
280 }
281 }
282
bsalomon@google.combf2a4692011-05-04 12:35:39 +0000283 return true;
284}
285