OSDN Git Service

Moving Chromium's version of the libraries first
[android-x86/external-swiftshader.git] / src / OpenGL / libGLESv2 / libGLESv2.hpp
1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #ifndef libGLESv2_hpp
16 #define libGLESv2_hpp
17
18 #include <GLES/gl.h>
19 #include <GLES/glext.h>
20 #include <EGL/egl.h>
21
22 #include "Common/SharedLibrary.hpp"
23
24 namespace sw
25 {
26 class FrameBuffer;
27 enum Format : unsigned char;
28 }
29
30 namespace egl
31 {
32 class Display;
33 class Context;
34 class Image;
35 class Config;
36 }
37
38 class LibGLESv2exports
39 {
40 public:
41         LibGLESv2exports();
42
43         void (*glActiveTexture)(GLenum texture);
44         void (*glAttachShader)(GLuint program, GLuint shader);
45         void (*glBeginQueryEXT)(GLenum target, GLuint name);
46         void (*glBindAttribLocation)(GLuint program, GLuint index, const GLchar* name);
47         void (*glBindBuffer)(GLenum target, GLuint buffer);
48         void (*glBindFramebuffer)(GLenum target, GLuint framebuffer);
49         void (*glBindRenderbuffer)(GLenum target, GLuint renderbuffer);
50         void (*glBindTexture)(GLenum target, GLuint texture);
51         void (*glBlendColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
52         void (*glBlendEquation)(GLenum mode);
53         void (*glBlendEquationSeparate)(GLenum modeRGB, GLenum modeAlpha);
54         void (*glBlendFunc)(GLenum sfactor, GLenum dfactor);
55         void (*glBlendFuncSeparate)(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
56         void (*glBufferData)(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage);
57         void (*glBufferSubData)(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data);
58         GLenum (*glCheckFramebufferStatus)(GLenum target);
59         void (*glClear)(GLbitfield mask);
60         void (*glClearColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
61         void (*glClearDepthf)(GLclampf depth);
62         void (*glClearStencil)(GLint s);
63         void (*glColorMask)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
64         void (*glCompileShader)(GLuint shader);
65         void (*glCompressedTexImage2D)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
66                                        GLint border, GLsizei imageSize, const GLvoid* data);
67         void (*glCompressedTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
68                                           GLenum format, GLsizei imageSize, const GLvoid* data);
69         void (*glCopyTexImage2D)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
70         void (*glCopyTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
71         GLuint (*glCreateProgram)(void);
72         GLuint (*glCreateShader)(GLenum type);
73         void (*glCullFace)(GLenum mode);
74         void (*glDeleteBuffers)(GLsizei n, const GLuint* buffers);
75         void (*glDeleteFencesNV)(GLsizei n, const GLuint* fences);
76         void (*glDeleteFramebuffers)(GLsizei n, const GLuint* framebuffers);
77         void (*glDeleteProgram)(GLuint program);
78         void (*glDeleteQueriesEXT)(GLsizei n, const GLuint *ids);
79         void (*glDeleteRenderbuffers)(GLsizei n, const GLuint* renderbuffers);
80         void (*glDeleteShader)(GLuint shader);
81         void (*glDeleteTextures)(GLsizei n, const GLuint* textures);
82         void (*glDepthFunc)(GLenum func);
83         void (*glDepthMask)(GLboolean flag);
84         void (*glDepthRangef)(GLclampf zNear, GLclampf zFar);
85         void (*glDetachShader)(GLuint program, GLuint shader);
86         void (*glDisable)(GLenum cap);
87         void (*glDisableVertexAttribArray)(GLuint index);
88         void (*glDrawArrays)(GLenum mode, GLint first, GLsizei count);
89         void (*glDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices);
90         void (*glDrawArraysInstancedEXT)(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount);
91         void (*glDrawElementsInstancedEXT)(GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instanceCount);
92         void (*glVertexAttribDivisorEXT)(GLuint index, GLuint divisor);
93         void (*glDrawArraysInstancedANGLE)(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount);
94         void (*glDrawElementsInstancedANGLE)(GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instanceCount);
95         void (*glVertexAttribDivisorANGLE)(GLuint index, GLuint divisor);
96         void (*glEnable)(GLenum cap);
97         void (*glEnableVertexAttribArray)(GLuint index);
98         void (*glEndQueryEXT)(GLenum target);
99         void (*glFinishFenceNV)(GLuint fence);
100         void (*glFinish)(void);
101         void (*glFlush)(void);
102         void (*glFramebufferRenderbuffer)(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
103         void (*glFramebufferTexture2D)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
104         void (*glFrontFace)(GLenum mode);
105         void (*glGenBuffers)(GLsizei n, GLuint* buffers);
106         void (*glGenerateMipmap)(GLenum target);
107         void (*glGenFencesNV)(GLsizei n, GLuint* fences);
108         void (*glGenFramebuffers)(GLsizei n, GLuint* framebuffers);
109         void (*glGenQueriesEXT)(GLsizei n, GLuint* ids);
110         void (*glGenRenderbuffers)(GLsizei n, GLuint* renderbuffers);
111         void (*glGenTextures)(GLsizei n, GLuint* textures);
112         void (*glGetActiveAttrib)(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
113         void (*glGetActiveUniform)(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name);
114         void (*glGetAttachedShaders)(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders);
115         int (*glGetAttribLocation)(GLuint program, const GLchar* name);
116         void (*glGetBooleanv)(GLenum pname, GLboolean* params);
117         void (*glGetBufferParameteriv)(GLenum target, GLenum pname, GLint* params);
118         GLenum (*glGetError)(void);
119         void (*glGetFenceivNV)(GLuint fence, GLenum pname, GLint *params);
120         void (*glGetFloatv)(GLenum pname, GLfloat* params);
121         void (*glGetFramebufferAttachmentParameteriv)(GLenum target, GLenum attachment, GLenum pname, GLint* params);
122         GLenum (*glGetGraphicsResetStatusEXT)(void);
123         void (*glGetIntegerv)(GLenum pname, GLint* params);
124         void (*glGetProgramiv)(GLuint program, GLenum pname, GLint* params);
125         void (*glGetProgramInfoLog)(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog);
126         void (*glGetQueryivEXT)(GLenum target, GLenum pname, GLint *params);
127         void (*glGetQueryObjectuivEXT)(GLuint name, GLenum pname, GLuint *params);
128         void (*glGetRenderbufferParameteriv)(GLenum target, GLenum pname, GLint* params);
129         void (*glGetShaderiv)(GLuint shader, GLenum pname, GLint* params);
130         void (*glGetShaderInfoLog)(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog);
131         void (*glGetShaderPrecisionFormat)(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision);
132         void (*glGetShaderSource)(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source);
133         const GLubyte* (*glGetString)(GLenum name);
134         void (*glGetTexParameterfv)(GLenum target, GLenum pname, GLfloat* params);
135         void (*glGetTexParameteriv)(GLenum target, GLenum pname, GLint* params);
136         void (*glGetnUniformfvEXT)(GLuint program, GLint location, GLsizei bufSize, GLfloat* params);
137         void (*glGetUniformfv)(GLuint program, GLint location, GLfloat* params);
138         void (*glGetnUniformivEXT)(GLuint program, GLint location, GLsizei bufSize, GLint* params);
139         void (*glGetUniformiv)(GLuint program, GLint location, GLint* params);
140         int (*glGetUniformLocation)(GLuint program, const GLchar* name);
141         void (*glGetVertexAttribfv)(GLuint index, GLenum pname, GLfloat* params);
142         void (*glGetVertexAttribiv)(GLuint index, GLenum pname, GLint* params);
143         void (*glGetVertexAttribPointerv)(GLuint index, GLenum pname, GLvoid** pointer);
144         void (*glHint)(GLenum target, GLenum mode);
145         GLboolean (*glIsBuffer)(GLuint buffer);
146         GLboolean (*glIsEnabled)(GLenum cap);
147         GLboolean (*glIsFenceNV)(GLuint fence);
148         GLboolean (*glIsFramebuffer)(GLuint framebuffer);
149         GLboolean (*glIsProgram)(GLuint program);
150         GLboolean (*glIsQueryEXT)(GLuint name);
151         GLboolean (*glIsRenderbuffer)(GLuint renderbuffer);
152         GLboolean (*glIsShader)(GLuint shader);
153         GLboolean (*glIsTexture)(GLuint texture);
154         void (*glLineWidth)(GLfloat width);
155         void (*glLinkProgram)(GLuint program);
156         void (*glPixelStorei)(GLenum pname, GLint param);
157         void (*glPolygonOffset)(GLfloat factor, GLfloat units);
158         void (*glReadnPixelsEXT)(GLint x, GLint y, GLsizei width, GLsizei height,
159                                  GLenum format, GLenum type, GLsizei bufSize, GLvoid *data);
160         void (*glReadPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels);
161         void (*glReleaseShaderCompiler)(void);
162         void (*glRenderbufferStorageMultisample)(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
163         void (*glRenderbufferStorageMultisampleANGLE)(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
164         void (*glRenderbufferStorage)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
165         void (*glSampleCoverage)(GLclampf value, GLboolean invert);
166         void (*glSetFenceNV)(GLuint fence, GLenum condition);
167         void (*glScissor)(GLint x, GLint y, GLsizei width, GLsizei height);
168         void (*glShaderBinary)(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length);
169         void (*glShaderSource)(GLuint shader, GLsizei count, const GLchar *const *string, const GLint *length);
170         void (*glStencilFunc)(GLenum func, GLint ref, GLuint mask);
171         void (*glStencilFuncSeparate)(GLenum face, GLenum func, GLint ref, GLuint mask);
172         void (*glStencilMask)(GLuint mask);
173         void (*glStencilMaskSeparate)(GLenum face, GLuint mask);
174         void (*glStencilOp)(GLenum fail, GLenum zfail, GLenum zpass);
175         void (*glStencilOpSeparate)(GLenum face, GLenum fail, GLenum zfail, GLenum zpass);
176         GLboolean (*glTestFenceNV)(GLuint fence);
177         void (*glTexImage2D)(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
178                              GLint border, GLenum format, GLenum type, const GLvoid* pixels);
179         void (*glTexParameterf)(GLenum target, GLenum pname, GLfloat param);
180         void (*glTexParameterfv)(GLenum target, GLenum pname, const GLfloat* params);
181         void (*glTexParameteri)(GLenum target, GLenum pname, GLint param);
182         void (*glTexParameteriv)(GLenum target, GLenum pname, const GLint* params);
183         void (*glTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
184                                 GLenum format, GLenum type, const GLvoid* pixels);
185         void (*glUniform1f)(GLint location, GLfloat x);
186         void (*glUniform1fv)(GLint location, GLsizei count, const GLfloat* v);
187         void (*glUniform1i)(GLint location, GLint x);
188         void (*glUniform1iv)(GLint location, GLsizei count, const GLint* v);
189         void (*glUniform2f)(GLint location, GLfloat x, GLfloat y);
190         void (*glUniform2fv)(GLint location, GLsizei count, const GLfloat* v);
191         void (*glUniform2i)(GLint location, GLint x, GLint y);
192         void (*glUniform2iv)(GLint location, GLsizei count, const GLint* v);
193         void (*glUniform3f)(GLint location, GLfloat x, GLfloat y, GLfloat z);
194         void (*glUniform3fv)(GLint location, GLsizei count, const GLfloat* v);
195         void (*glUniform3i)(GLint location, GLint x, GLint y, GLint z);
196         void (*glUniform3iv)(GLint location, GLsizei count, const GLint* v);
197         void (*glUniform4f)(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
198         void (*glUniform4fv)(GLint location, GLsizei count, const GLfloat* v);
199         void (*glUniform4i)(GLint location, GLint x, GLint y, GLint z, GLint w);
200         void (*glUniform4iv)(GLint location, GLsizei count, const GLint* v);
201         void (*glUniformMatrix2fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
202         void (*glUniformMatrix3fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
203         void (*glUniformMatrix4fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
204         void (*glUseProgram)(GLuint program);
205         void (*glValidateProgram)(GLuint program);
206         void (*glVertexAttrib1f)(GLuint index, GLfloat x);
207         void (*glVertexAttrib1fv)(GLuint index, const GLfloat* values);
208         void (*glVertexAttrib2f)(GLuint index, GLfloat x, GLfloat y);
209         void (*glVertexAttrib2fv)(GLuint index, const GLfloat* values);
210         void (*glVertexAttrib3f)(GLuint index, GLfloat x, GLfloat y, GLfloat z);
211         void (*glVertexAttrib3fv)(GLuint index, const GLfloat* values);
212         void (*glVertexAttrib4f)(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
213         void (*glVertexAttrib4fv)(GLuint index, const GLfloat* values);
214         void (*glVertexAttribPointer)(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr);
215         void (*glViewport)(GLint x, GLint y, GLsizei width, GLsizei height);
216         void (*glBlitFramebufferNV)(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
217         void (*glBlitFramebufferANGLE)(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
218                                        GLbitfield mask, GLenum filter);
219         void (*glTexImage3DOES)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
220                                 GLint border, GLenum format, GLenum type, const GLvoid* pixels);
221         void (*glTexSubImage3DOES)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels);
222         void (*glCopyTexSubImage3DOES)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
223         void (*glCompressedTexImage3DOES)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *data);
224         void (*glCompressedTexSubImage3DOES)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *data);
225         void (*glFramebufferTexture3DOES)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
226         void (*glEGLImageTargetTexture2DOES)(GLenum target, GLeglImageOES image);
227         void (*glEGLImageTargetRenderbufferStorageOES)(GLenum target, GLeglImageOES image);
228         GLboolean (*glIsRenderbufferOES)(GLuint renderbuffer);
229         void (*glBindRenderbufferOES)(GLenum target, GLuint renderbuffer);
230         void (*glDeleteRenderbuffersOES)(GLsizei n, const GLuint* renderbuffers);
231         void (*glGenRenderbuffersOES)(GLsizei n, GLuint* renderbuffers);
232         void (*glRenderbufferStorageOES)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
233         void (*glGetRenderbufferParameterivOES)(GLenum target, GLenum pname, GLint* params);
234         GLboolean (*glIsFramebufferOES)(GLuint framebuffer);
235         void (*glBindFramebufferOES)(GLenum target, GLuint framebuffer);
236         void (*glDeleteFramebuffersOES)(GLsizei n, const GLuint* framebuffers);
237         void (*glGenFramebuffersOES)(GLsizei n, GLuint* framebuffers);
238         GLenum (*glCheckFramebufferStatusOES)(GLenum target);
239         void (*glFramebufferRenderbufferOES)(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
240         void (*glFramebufferTexture2DOES)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
241         void (*glGetFramebufferAttachmentParameterivOES)(GLenum target, GLenum attachment, GLenum pname, GLint* params);
242         void (*glGenerateMipmapOES)(GLenum target);
243         void (*glDrawBuffersEXT)(GLsizei n, const GLenum *bufs);
244
245         egl::Context *(*es2CreateContext)(egl::Display *display, const egl::Context *shareContext, int clientVersion, const egl::Config *config);
246         __eglMustCastToProperFunctionPointerType (*es2GetProcAddress)(const char *procname);
247         egl::Image *(*createBackBuffer)(int width, int height, sw::Format format, int multiSampleDepth);
248         egl::Image *(*createDepthStencil)(int width, int height, sw::Format format, int multiSampleDepth);
249         sw::FrameBuffer *(*createFrameBuffer)(void *nativeDisplay, EGLNativeWindowType window, int width, int height);
250 };
251
252 class LibGLESv2
253 {
254 public:
255         LibGLESv2()
256         {
257                 libGLESv2 = nullptr;
258                 libGLESv2exports = nullptr;
259         }
260
261         ~LibGLESv2()
262         {
263                 freeLibrary(libGLESv2);
264         }
265
266         operator bool()
267         {
268                 return loadExports() != nullptr;
269         }
270
271         LibGLESv2exports *operator->()
272         {
273                 return loadExports();
274         }
275
276 private:
277         LibGLESv2exports *loadExports()
278         {
279                 if(!libGLESv2)
280                 {
281                         #if defined(_WIN32)
282                                 #if defined(__LP64__)
283                                         const char *libGLESv2_lib[] = {"libGLESv2.dll", "lib64GLES_V2_translator.dll"};
284                                 #else
285                                         const char *libGLESv2_lib[] = {"libGLESv2.dll", "libGLES_V2_translator.dll"};
286                                 #endif
287                         #elif defined(__ANDROID__)
288                                 #if defined(__LP64__)
289                                         const char *libGLESv2_lib[] = {"/vendor/lib64/egl/libGLESv2_swiftshader.so"};
290                                 #else
291                                         const char *libGLESv2_lib[] = {"/vendor/lib/egl/libGLESv2_swiftshader.so"};
292                                 #endif
293                         #elif defined(__linux__)
294                                 #if defined(__LP64__)
295                                         const char *libGLESv2_lib[] = {"lib64GLES_V2_translator.so", "libGLESv2.so.2", "libGLESv2.so"};
296                                 #else
297                                         const char *libGLESv2_lib[] = {"libGLES_V2_translator.so", "libGLESv2.so.2", "libGLESv2.so"};
298                                 #endif
299                         #elif defined(__APPLE__)
300                                 #if defined(__LP64__)
301                                         const char *libGLESv2_lib[] = {"libswiftshader_libGLESv2.dylib", "lib64GLES_V2_translator.dylib", "libGLESv2.dylib"};
302                                 #else
303                                         const char *libGLESv2_lib[] = {"libswiftshader_libGLESv2.dylib", "libGLES_V2_translator.dylib", "libGLESv2.dylib"};
304                                 #endif
305                         #elif defined(__Fuchsia__)
306                                 const char *libGLESv2_lib[] = {"libGLESv2.so"};
307                         #else
308                                 #error "libGLESv2::loadExports unimplemented for this platform"
309                         #endif
310
311                         libGLESv2 = loadLibrary(libGLESv2_lib, "libGLESv2_swiftshader");
312
313                         if(libGLESv2)
314                         {
315                                 auto libGLESv2_swiftshader = (LibGLESv2exports *(*)())getProcAddress(libGLESv2, "libGLESv2_swiftshader");
316                                 libGLESv2exports = libGLESv2_swiftshader();
317                         }
318                 }
319
320                 return libGLESv2exports;
321         }
322
323         void *libGLESv2;
324         LibGLESv2exports *libGLESv2exports;
325 };
326
327 #endif   // libGLESv2_hpp