aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/gl/GrGLAssembleGLESInterface.h
blob: ddbc9809295f6baaa3bc5b4d6c454d55643dffb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240

/*
 * Copyright 2014 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

const GrGLInterface* GrGLAssembleGLESInterface(void* ctx, GrGLGetProc get) {
    GET_PROC_LOCAL(GetString);
    const char* verStr = reinterpret_cast<const char*>(GetString(GR_GL_VERSION));
    GrGLVersion version = GrGLGetVersionFromString(verStr);

    if (version < GR_GL_VER(2,0)) {
        return NULL;
    }

    GET_PROC_LOCAL(GetIntegerv);
    GET_PROC_LOCAL(GetStringi);
    GrGLExtensions extensions;
    if (!extensions.init(kGLES_GrGLStandard, GetString, GetStringi, GetIntegerv)) {
        return NULL;
    }

    GrGLInterface* interface = SkNEW(GrGLInterface);
    GrGLInterface::Functions* functions = &interface->fFunctions;

    GET_LINKED(ActiveTexture);
    GET_LINKED(AttachShader);
    GET_LINKED(BindAttribLocation);
    GET_LINKED(BindBuffer);
    GET_LINKED(BindTexture);
    GET_LINKED_SUFFIX(BindVertexArray, OES);
    GET_LINKED(BlendColor);
    GET_LINKED(BlendFunc);
    GET_LINKED(BufferData);
    GET_LINKED(BufferSubData);
    GET_LINKED(Clear);
    GET_LINKED(ClearColor);
    GET_LINKED(ClearStencil);
    GET_LINKED(ColorMask);
    GET_LINKED(CompileShader);
    GET_LINKED(CompressedTexImage2D);
    GET_LINKED(CompressedTexSubImage2D);
    GET_LINKED(CopyTexSubImage2D);
    GET_LINKED(CreateProgram);
    GET_LINKED(CreateShader);
    GET_LINKED(CullFace);
    GET_LINKED(DeleteBuffers);
    GET_LINKED(DeleteProgram);
    GET_LINKED(DeleteShader);
    GET_LINKED(DeleteTextures);
    GET_LINKED_SUFFIX(DeleteVertexArrays, OES);
    GET_LINKED(DepthMask);
    GET_LINKED(Disable);
    GET_LINKED(DisableVertexAttribArray);
    GET_LINKED(DrawArrays);
    GET_LINKED(DrawElements);
    GET_LINKED(Enable);
    GET_LINKED(EnableVertexAttribArray);
    GET_LINKED(Finish);
    GET_LINKED(Flush);
    GET_LINKED(FrontFace);
    GET_LINKED(GenBuffers);
    GET_LINKED(GenerateMipmap);
    GET_LINKED(GenTextures);
    GET_LINKED_SUFFIX(GenVertexArrays, OES);
    GET_LINKED(GetBufferParameteriv);
    GET_LINKED(GetError);
    GET_LINKED(GetIntegerv);
    GET_LINKED(GetProgramInfoLog);
    GET_LINKED(GetProgramiv);
    GET_LINKED(GetShaderInfoLog);
    GET_LINKED(GetShaderiv);
    GET_LINKED(GetString);
#if USE_LINKED && GL_ES_VERSION_3_0
    GET_LINKED(GetStringi);
#else
    GET_PROC(GetStringi);
#endif
    GET_LINKED(GetUniformLocation);
    GET_LINKED(LineWidth);
    GET_LINKED(LinkProgram);
    GET_LINKED(PixelStorei);
    GET_LINKED(ReadPixels);
    GET_LINKED(Scissor);
#if GR_GL_USE_NEW_SHADER_SOURCE_SIGNATURE
    functions->fShaderSource = (GrGLShaderSourceProc) glShaderSource;
#else
    GET_LINKED(ShaderSource);
#endif
    GET_LINKED(StencilFunc);
    GET_LINKED(StencilFuncSeparate);
    GET_LINKED(StencilMask);
    GET_LINKED(StencilMaskSeparate);
    GET_LINKED(StencilOp);
    GET_LINKED(StencilOpSeparate);
    GET_LINKED(TexImage2D);
    GET_LINKED(TexParameteri);
    GET_LINKED(TexParameteriv);
    GET_LINKED(TexSubImage2D);

    if (version >= GR_GL_VER(3,0)) {
#if USE_LINKED && GL_ES_VERSION_3_0
        GET_LINKED(TexStorage2D);
#else
        GET_PROC(TexStorage2D);
#endif
    } else {
#if USE_LINKED && GL_EXT_texture_storage
        GET_LINKED_SUFFIX(TexStorage2D, EXT);
#else
        GET_PROC_SUFFIX(TexStorage2D, EXT);
#endif
    }

#if USE_LINKED && GL_EXT_discard_framebuffer
    GET_LINKED_SUFFIX(DiscardFramebuffer, EXT);
#endif
    GET_LINKED(Uniform1f);
    GET_LINKED(Uniform1i);
    GET_LINKED(Uniform1fv);
    GET_LINKED(Uniform1iv);
    GET_LINKED(Uniform2f);
    GET_LINKED(Uniform2i);
    GET_LINKED(Uniform2fv);
    GET_LINKED(Uniform2iv);
    GET_LINKED(Uniform3f);
    GET_LINKED(Uniform3i);
    GET_LINKED(Uniform3fv);
    GET_LINKED(Uniform3iv);
    GET_LINKED(Uniform4f);
    GET_LINKED(Uniform4i);
    GET_LINKED(Uniform4fv);
    GET_LINKED(Uniform4iv);
    GET_LINKED(UniformMatrix2fv);
    GET_LINKED(UniformMatrix3fv);
    GET_LINKED(UniformMatrix4fv);
    GET_LINKED(UseProgram);
    GET_LINKED(VertexAttrib4fv);
    GET_LINKED(VertexAttribPointer);
    GET_LINKED(Viewport);
    GET_LINKED(BindFramebuffer);
    GET_LINKED(BindRenderbuffer);
    GET_LINKED(CheckFramebufferStatus);
    GET_LINKED(DeleteFramebuffers);
    GET_LINKED(DeleteRenderbuffers);
    GET_LINKED(FramebufferRenderbuffer);
    GET_LINKED(FramebufferTexture2D);

    if (version >= GR_GL_VER(3,0)) {
#if USE_LINKED && GL_ES_VERSION_3_0
        GET_LINKED(RenderbufferStorageMultisample);
        GET_LINKED(BlitFramebuffer);
#else
        GET_PROC(RenderbufferStorageMultisample);
        GET_PROC(BlitFramebuffer);
#endif
    }

    if (extensions.has("GL_EXT_multisampled_render_to_texture")) {
#if USE_LINKED && GL_EXT_multisampled_render_to_texture
        GET_LINKED_SUFFIX(FramebufferTexture2DMultisample, EXT);
        functions->fRenderbufferStorageMultisampleES2EXT = glRenderbufferStorageMultisampleEXT;
#else
        GET_PROC_SUFFIX(FramebufferTexture2DMultisample, EXT);
        functions->fRenderbufferStorageMultisampleES2EXT = (GrGLRenderbufferStorageMultisampleProc) get(ctx, "glRenderbufferStorageMultisampleEXT");
#endif
    } else if (extensions.has("GL_IMG_multisampled_render_to_texture")) {
#if USE_LINKED && GL_IMG_multisampled_render_to_texture
        GET_LINKED_SUFFIX(FramebufferTexture2DMultisample, IMG);
        functions->fRenderbufferStorageMultisampleES2EXT = glRenderbufferStorageMultisampleIMG;
#else
        GET_PROC_SUFFIX(FramebufferTexture2DMultisample, IMG);
        functions->fRenderbufferStorageMultisampleES2EXT = (GrGLRenderbufferStorageMultisampleProc) get(ctx, "glRenderbufferStorageMultisampleIMG");
#endif
    }

    GET_LINKED(GenFramebuffers);
    GET_LINKED(GenRenderbuffers);
    GET_LINKED(GetFramebufferAttachmentParameteriv);
    GET_LINKED(GetRenderbufferParameteriv);
    GET_LINKED(RenderbufferStorage);

#if USE_LINKED && GL_OES_mapbuffer
    GET_LINKED_SUFFIX(MapBuffer, OES);
    GET_LINKED_SUFFIX(UnmapBuffer, OES);
#else
    GET_PROC_SUFFIX(MapBuffer, OES);
    GET_PROC_SUFFIX(UnmapBuffer, OES);
#endif

    if (version >= GR_GL_VER(3,0)) {
#if USE_LINKED && GL_ES_VERSION_3_0
        GET_LINKED(MapBufferRange);
        GET_LINKED(FlushMappedBufferRange);
#else
        GET_PROC(MapBufferRange);
        GET_PROC(FlushMappedBufferRange);
#endif
    } else if (extensions.has("GL_EXT_map_buffer_range")) {
#if USE_LINKED && GL_EXT_map_buffer_range
        GET_LINKED_SUFFIX(MapBufferRange, EXT);
        GET_LINKED_SUFFIX(FlushMappedBufferRange, EXT);
#else
        GET_PROC_SUFFIX(MapBufferRange, EXT);
        GET_PROC_SUFFIX(FlushMappedBufferRange, EXT);
#endif
    }

    if (extensions.has("GL_EXT_debug_marker")) {
        GET_PROC(InsertEventMarker);
        GET_PROC(PushGroupMarker);
        GET_PROC(PopGroupMarker);
        // The below check is here because a device has been found that has the extension string but
        // returns NULL from the eglGetProcAddress for the functions
        if (NULL == functions->fInsertEventMarker ||
            NULL == functions->fPushGroupMarker ||
            NULL == functions->fPopGroupMarker) {
            extensions.remove("GL_EXT_debug_marker");
        }
    }

#if USE_LINKED && GL_ES_VERSION_3_0
    GET_LINKED(InvalidateFramebuffer);
    GET_LINKED(InvalidateSubFramebuffer);
#else
    GET_PROC(InvalidateFramebuffer);
    GET_PROC(InvalidateSubFramebuffer);
#endif
    GET_PROC(InvalidateBufferData);
    GET_PROC(InvalidateBufferSubData);
    GET_PROC(InvalidateTexImage);
    GET_PROC(InvalidateTexSubImage);

    interface->fStandard = kGLES_GrGLStandard;
    interface->fExtensions.swap(&extensions);

    return interface;
}