OLD | NEW |
| (Empty) |
1 | |
2 /* | |
3 * Copyright 2014 Google Inc. | |
4 * | |
5 * Use of this source code is governed by a BSD-style license that can be | |
6 * found in the LICENSE file. | |
7 */ | |
8 | |
9 /* This file is meant to be included "inline" the implementation that is using t
he function. | |
10 * The platform native GL implementation header file should be included before t
his file. | |
11 * Following macros should be defined before this file is included: | |
12 * GET_PROC and GET_PROC_SUFFIX | |
13 * Call the get function and assign to the interface instance | |
14 * GET_PROC_LOCAL | |
15 * Call the get function and assign to a local variable | |
16 * GET_LINKED and GET_LINKED_SUFFIX | |
17 * Get the link-time address of the function and assign it to the interface in
stance. If | |
18 * using the linked addresses is not intended, can be the same as GET_PROC. | |
19 */ | |
20 | |
21 /** | |
22 * Generic function for creating a GrGLInterface for an OpenGL ES (but not Open
GL) context. It | |
23 * calls get() to get each function address. ctx is a generic ptr passed to and
interpreted by | |
24 * get(). | |
25 */ | |
26 static const GrGLInterface* GrGLAssembleGLESInterface(void* ctx, GrGLGetProc get
) { | |
27 const char* verStr = reinterpret_cast<const char*>(glGetString(GR_GL_VERSION
)); | |
28 GrGLVersion version = GrGLGetVersionFromString(verStr); | |
29 | |
30 if (version < GR_GL_VER(2,0)) { | |
31 return NULL; | |
32 } | |
33 | |
34 GET_PROC_LOCAL(GetIntegerv); | |
35 GET_PROC_LOCAL(GetStringi); | |
36 GrGLExtensions extensions; | |
37 if (!extensions.init(kGLES_GrGLStandard, glGetString, GetStringi, GetInteger
v)) { | |
38 return NULL; | |
39 } | |
40 | |
41 GrGLInterface* interface = SkNEW(GrGLInterface); | |
42 GrGLInterface::Functions* functions = &interface->fFunctions; | |
43 | |
44 GET_LINKED(ActiveTexture); | |
45 GET_LINKED(AttachShader); | |
46 GET_LINKED(BindAttribLocation); | |
47 GET_LINKED(BindBuffer); | |
48 GET_LINKED(BindTexture); | |
49 GET_LINKED_SUFFIX(BindVertexArray, OES); | |
50 GET_LINKED(BlendColor); | |
51 GET_LINKED(BlendFunc); | |
52 GET_LINKED(BufferData); | |
53 GET_LINKED(BufferSubData); | |
54 GET_LINKED(Clear); | |
55 GET_LINKED(ClearColor); | |
56 GET_LINKED(ClearStencil); | |
57 GET_LINKED(ColorMask); | |
58 GET_LINKED(CompileShader); | |
59 GET_LINKED(CompressedTexImage2D); | |
60 GET_LINKED(CompressedTexSubImage2D); | |
61 GET_LINKED(CopyTexSubImage2D); | |
62 GET_LINKED(CreateProgram); | |
63 GET_LINKED(CreateShader); | |
64 GET_LINKED(CullFace); | |
65 GET_LINKED(DeleteBuffers); | |
66 GET_LINKED(DeleteProgram); | |
67 GET_LINKED(DeleteShader); | |
68 GET_LINKED(DeleteTextures); | |
69 GET_LINKED_SUFFIX(DeleteVertexArrays, OES); | |
70 GET_LINKED(DepthMask); | |
71 GET_LINKED(Disable); | |
72 GET_LINKED(DisableVertexAttribArray); | |
73 GET_LINKED(DrawArrays); | |
74 GET_LINKED(DrawElements); | |
75 GET_LINKED(Enable); | |
76 GET_LINKED(EnableVertexAttribArray); | |
77 GET_LINKED(Finish); | |
78 GET_LINKED(Flush); | |
79 GET_LINKED(FrontFace); | |
80 GET_LINKED(GenBuffers); | |
81 GET_LINKED(GenerateMipmap); | |
82 GET_LINKED(GenTextures); | |
83 GET_LINKED_SUFFIX(GenVertexArrays, OES); | |
84 GET_LINKED(GetBufferParameteriv); | |
85 GET_LINKED(GetError); | |
86 GET_LINKED(GetIntegerv); | |
87 GET_LINKED(GetProgramInfoLog); | |
88 GET_LINKED(GetProgramiv); | |
89 GET_LINKED(GetShaderInfoLog); | |
90 GET_LINKED(GetShaderiv); | |
91 GET_LINKED(GetString); | |
92 #if GL_ES_VERSION_3_0 | |
93 GET_LINKED(GetStringi); | |
94 #else | |
95 GET_PROC(GetStringi); | |
96 #endif | |
97 GET_LINKED(GetUniformLocation); | |
98 GET_LINKED(LineWidth); | |
99 GET_LINKED(LinkProgram); | |
100 GET_LINKED(PixelStorei); | |
101 GET_LINKED(ReadPixels); | |
102 GET_LINKED(Scissor); | |
103 #if GR_GL_USE_NEW_SHADER_SOURCE_SIGNATURE | |
104 functions->fShaderSource = (GrGLShaderSourceProc) glShaderSource; | |
105 #else | |
106 GET_LINKED(ShaderSource); | |
107 #endif | |
108 GET_LINKED(StencilFunc); | |
109 GET_LINKED(StencilFuncSeparate); | |
110 GET_LINKED(StencilMask); | |
111 GET_LINKED(StencilMaskSeparate); | |
112 GET_LINKED(StencilOp); | |
113 GET_LINKED(StencilOpSeparate); | |
114 GET_LINKED(TexImage2D); | |
115 GET_LINKED(TexParameteri); | |
116 GET_LINKED(TexParameteriv); | |
117 GET_LINKED(TexSubImage2D); | |
118 | |
119 if (version >= GR_GL_VER(3,0)) { | |
120 #if GL_ES_VERSION_3_0 | |
121 GET_LINKED(TexStorage2D); | |
122 #else | |
123 GET_PROC(TexStorage2D); | |
124 #endif | |
125 } else { | |
126 #if GL_EXT_texture_storage | |
127 GET_LINKED_SUFFIX(TexStorage2D, EXT); | |
128 #else | |
129 GET_PROC_SUFFIX(TexStorage2D, EXT); | |
130 #endif | |
131 } | |
132 | |
133 #if GL_EXT_discard_framebuffer | |
134 GET_LINKED_SUFFIX(DiscardFramebuffer, EXT); | |
135 #endif | |
136 GET_LINKED(Uniform1f); | |
137 GET_LINKED(Uniform1i); | |
138 GET_LINKED(Uniform1fv); | |
139 GET_LINKED(Uniform1iv); | |
140 GET_LINKED(Uniform2f); | |
141 GET_LINKED(Uniform2i); | |
142 GET_LINKED(Uniform2fv); | |
143 GET_LINKED(Uniform2iv); | |
144 GET_LINKED(Uniform3f); | |
145 GET_LINKED(Uniform3i); | |
146 GET_LINKED(Uniform3fv); | |
147 GET_LINKED(Uniform3iv); | |
148 GET_LINKED(Uniform4f); | |
149 GET_LINKED(Uniform4i); | |
150 GET_LINKED(Uniform4fv); | |
151 GET_LINKED(Uniform4iv); | |
152 GET_LINKED(UniformMatrix2fv); | |
153 GET_LINKED(UniformMatrix3fv); | |
154 GET_LINKED(UniformMatrix4fv); | |
155 GET_LINKED(UseProgram); | |
156 GET_LINKED(VertexAttrib4fv); | |
157 GET_LINKED(VertexAttribPointer); | |
158 GET_LINKED(Viewport); | |
159 GET_LINKED(BindFramebuffer); | |
160 GET_LINKED(BindRenderbuffer); | |
161 GET_LINKED(CheckFramebufferStatus); | |
162 GET_LINKED(DeleteFramebuffers); | |
163 GET_LINKED(DeleteRenderbuffers); | |
164 GET_LINKED(FramebufferRenderbuffer); | |
165 GET_LINKED(FramebufferTexture2D); | |
166 | |
167 if (version >= GR_GL_VER(3,0)) { | |
168 #if GL_ES_VERSION_3_0 | |
169 GET_LINKED(RenderbufferStorageMultisample); | |
170 GET_LINKED(BlitFramebuffer); | |
171 #else | |
172 GET_PROC(RenderbufferStorageMultisample); | |
173 GET_PROC(BlitFramebuffer); | |
174 #endif | |
175 } | |
176 | |
177 if (extensions.has("GL_EXT_multisampled_render_to_texture")) { | |
178 #if GL_EXT_multisampled_render_to_texture | |
179 GET_LINKED_SUFFIX(FramebufferTexture2DMultisample, EXT); | |
180 functions->fRenderbufferStorageMultisampleES2EXT = glRenderbufferStorage
MultisampleEXT; | |
181 #else | |
182 GET_PROC_SUFFIX(FramebufferTexture2DMultisample, EXT); | |
183 functions->fRenderbufferStorageMultisampleES2EXT = (GrGLRenderbufferStor
ageMultisampleProc) get(ctx, "glRenderbufferStorageMultisampleEXT"); | |
184 #endif | |
185 } else if (extensions.has("GL_IMG_multisampled_render_to_texture")) { | |
186 #if GL_IMG_multisampled_render_to_texture | |
187 GET_LINKED_SUFFIX(FramebufferTexture2DMultisample, IMG); | |
188 functions->fRenderbufferStorageMultisampleES2EXT = glRenderbufferStorage
MultisampleIMG; | |
189 #else | |
190 GET_PROC_SUFFIX(FramebufferTexture2DMultisample, IMG); | |
191 functions->fRenderbufferStorageMultisampleES2EXT = (GrGLRenderbufferStor
ageMultisampleProc) get(ctx, "glRenderbufferStorageMultisampleIMG"); | |
192 #endif | |
193 } | |
194 | |
195 GET_LINKED(GenFramebuffers); | |
196 GET_LINKED(GenRenderbuffers); | |
197 GET_LINKED(GetFramebufferAttachmentParameteriv); | |
198 GET_LINKED(GetRenderbufferParameteriv); | |
199 GET_LINKED(RenderbufferStorage); | |
200 | |
201 #if GL_OES_mapbuffer | |
202 GET_LINKED_SUFFIX(MapBuffer, OES); | |
203 GET_LINKED_SUFFIX(UnmapBuffer, OES); | |
204 #else | |
205 GET_PROC_SUFFIX(MapBuffer, OES); | |
206 GET_PROC_SUFFIX(UnmapBuffer, OES); | |
207 #endif | |
208 | |
209 if (version >= GR_GL_VER(3,0)) { | |
210 #if GL_ES_VERSION_3_0 | |
211 GET_LINKED(MapBufferRange); | |
212 GET_LINKED(FlushMappedBufferRange); | |
213 #else | |
214 GET_PROC(MapBufferRange); | |
215 GET_PROC(FlushMappedBufferRange); | |
216 #endif | |
217 } else if (extensions.has("GL_EXT_map_buffer_range")) { | |
218 #if GL_EXT_map_buffer_range | |
219 GET_LINKED_SUFFIX(MapBufferRange, EXT); | |
220 GET_LINKED_SUFFIX(FlushMappedBufferRange, EXT); | |
221 #else | |
222 GET_PROC_SUFFIX(MapBufferRange, EXT); | |
223 GET_PROC_SUFFIX(FlushMappedBufferRange, EXT); | |
224 #endif | |
225 } | |
226 | |
227 if (extensions.has("GL_EXT_debug_marker")) { | |
228 GET_PROC(InsertEventMarker); | |
229 GET_PROC(PushGroupMarker); | |
230 GET_PROC(PopGroupMarker); | |
231 // The below check is here because a device has been found that has the
extension string but | |
232 // returns NULL from the eglGetProcAddress for the functions | |
233 if (NULL == functions->fInsertEventMarker || | |
234 NULL == functions->fPushGroupMarker || | |
235 NULL == functions->fPopGroupMarker) { | |
236 extensions.remove("GL_EXT_debug_marker"); | |
237 } | |
238 } | |
239 | |
240 #if GL_ES_VERSION_3_0 | |
241 GET_LINKED(InvalidateFramebuffer); | |
242 GET_LINKED(InvalidateSubFramebuffer); | |
243 #else | |
244 GET_PROC(InvalidateFramebuffer); | |
245 GET_PROC(InvalidateSubFramebuffer); | |
246 #endif | |
247 GET_PROC(InvalidateBufferData); | |
248 GET_PROC(InvalidateBufferSubData); | |
249 GET_PROC(InvalidateTexImage); | |
250 GET_PROC(InvalidateTexSubImage); | |
251 | |
252 #if GL_ES_VERSION_3_1 | |
253 GET_LINKED(GetProgramResourceLocation); | |
254 #else | |
255 if (version >= GR_GL_VER(3,1)) { | |
256 GET_PROC(GetProgramResourceLocation); | |
257 } | |
258 #endif | |
259 | |
260 if (extensions.has("GL_NV_path_rendering")) { | |
261 GET_PROC_SUFFIX(MatrixLoadf, EXT); | |
262 GET_PROC_SUFFIX(MatrixLoadIdentity, EXT); | |
263 GET_PROC_SUFFIX(PathCommands, NV); | |
264 GET_PROC_SUFFIX(PathCoords, NV); | |
265 GET_PROC_SUFFIX(PathParameteri, NV); | |
266 GET_PROC_SUFFIX(PathParameterf, NV); | |
267 GET_PROC_SUFFIX(GenPaths, NV); | |
268 GET_PROC_SUFFIX(DeletePaths, NV); | |
269 GET_PROC_SUFFIX(IsPath, NV); | |
270 GET_PROC_SUFFIX(PathStencilFunc, NV); | |
271 GET_PROC_SUFFIX(StencilFillPath, NV); | |
272 GET_PROC_SUFFIX(StencilStrokePath, NV); | |
273 GET_PROC_SUFFIX(StencilFillPathInstanced, NV); | |
274 GET_PROC_SUFFIX(StencilStrokePathInstanced, NV); | |
275 GET_PROC_SUFFIX(CoverFillPath, NV); | |
276 GET_PROC_SUFFIX(CoverStrokePath, NV); | |
277 GET_PROC_SUFFIX(CoverFillPathInstanced, NV); | |
278 GET_PROC_SUFFIX(CoverStrokePathInstanced, NV); | |
279 GET_PROC_SUFFIX(StencilThenCoverFillPath, NV); | |
280 GET_PROC_SUFFIX(StencilThenCoverStrokePath, NV); | |
281 GET_PROC_SUFFIX(StencilThenCoverFillPathInstanced, NV); | |
282 GET_PROC_SUFFIX(StencilThenCoverStrokePathInstanced, NV); | |
283 GET_PROC_SUFFIX(ProgramPathFragmentInputGen, NV); | |
284 } | |
285 | |
286 interface->fStandard = kGLES_GrGLStandard; | |
287 interface->fExtensions.swap(&extensions); | |
288 | |
289 return interface; | |
290 } | |
OLD | NEW |