aboutsummaryrefslogtreecommitdiff
path: root/src/OpenGL/libGLES_CM/libGLES_CM.hpp
blob: d6740ec974286334b4cf426b9e34cdc7f96408b2 (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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef libGLES_CM_hpp
#define libGLES_CM_hpp

#include <GLES/gl.h>
#include <GLES/glext.h>
#include <EGL/egl.h>

#include "Common/SharedLibrary.hpp"

namespace sw
{
class FrameBuffer;
enum Format : unsigned char;
}

namespace egl
{
class Display;
class Context;
class Image;
class Config;
}

class LibGLES_CMexports
{
public:
	LibGLES_CMexports();

	void (*glActiveTexture)(GLenum texture);
	void (*glAlphaFunc)(GLenum func, GLclampf ref);
	void (*glAlphaFuncx)(GLenum func, GLclampx ref);
	void (*glBindBuffer)(GLenum target, GLuint buffer);
	void (*glBindFramebuffer)(GLenum target, GLuint framebuffer);
	void (*glBindFramebufferOES)(GLenum target, GLuint framebuffer);
	void (*glBindRenderbufferOES)(GLenum target, GLuint renderbuffer);
	void (*glBindTexture)(GLenum target, GLuint texture);
	void (*glBlendEquationOES)(GLenum mode);
	void (*glBlendEquationSeparateOES)(GLenum modeRGB, GLenum modeAlpha);
	void (*glBlendFunc)(GLenum sfactor, GLenum dfactor);
	void (*glBlendFuncSeparateOES)(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
	void (*glBufferData)(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage);
	void (*glBufferSubData)(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data);
	GLenum (*glCheckFramebufferStatusOES)(GLenum target);
	void (*glClear)(GLbitfield mask);
	void (*glClearColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
	void (*glClearColorx)(GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha);
	void (*glClearDepthf)(GLclampf depth);
	void (*glClearDepthx)(GLclampx depth);
	void (*glClearStencil)(GLint s);
	void (*glClientActiveTexture)(GLenum texture);
	void (*glClipPlanef)(GLenum plane, const GLfloat *equation);
	void (*glClipPlanex)(GLenum plane, const GLfixed *equation);
	void (*glColor4f)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
	void (*glColor4ub)(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha);
	void (*glColor4x)(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha);
	void (*glColorMask)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
	void (*glColorPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
	void (*glCompressedTexImage2D)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
	                               GLint border, GLsizei imageSize, const GLvoid* data);
	void (*glCompressedTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
	                                  GLenum format, GLsizei imageSize, const GLvoid* data);
	void (*glCopyTexImage2D)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
	void (*glCopyTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
	void (*glCullFace)(GLenum mode);
	void (*glDeleteBuffers)(GLsizei n, const GLuint* buffers);
	void (*glDeleteFramebuffersOES)(GLsizei n, const GLuint* framebuffers);
	void (*glDeleteRenderbuffersOES)(GLsizei n, const GLuint* renderbuffers);
	void (*glDeleteTextures)(GLsizei n, const GLuint* textures);
	void (*glDepthFunc)(GLenum func);
	void (*glDepthMask)(GLboolean flag);
	void (*glDepthRangex)(GLclampx zNear, GLclampx zFar);
	void (*glDepthRangef)(GLclampf zNear, GLclampf zFar);
	void (*glDisable)(GLenum cap);
	void (*glDisableClientState)(GLenum array);
	void (*glDrawArrays)(GLenum mode, GLint first, GLsizei count);
	void (*glDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices);
	void (*glEnable)(GLenum cap);
	void (*glEnableClientState)(GLenum array);
	void (*glFinish)(void);
	void (*glFlush)(void);
	void (*glFramebufferRenderbufferOES)(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
	void (*glFramebufferTexture2DOES)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
	void (*glFogf)(GLenum pname, GLfloat param);
	void (*glFogfv)(GLenum pname, const GLfloat *params);
	void (*glFogx)(GLenum pname, GLfixed param);
	void (*glFogxv)(GLenum pname, const GLfixed *params);
	void (*glFrontFace)(GLenum mode);
	void (*glFrustumf)(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar);
	void (*glFrustumx)(GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar);
	void (*glGenerateMipmapOES)(GLenum target);
	void (*glGenBuffers)(GLsizei n, GLuint* buffers);
	void (*glGenFramebuffersOES)(GLsizei n, GLuint* framebuffers);
	void (*glGenRenderbuffersOES)(GLsizei n, GLuint* renderbuffers);
	void (*glGenTextures)(GLsizei n, GLuint* textures);
	void (*glGetRenderbufferParameterivOES)(GLenum target, GLenum pname, GLint* params);
	void (*glGetBooleanv)(GLenum pname, GLboolean* params);
	void (*glGetBufferParameteriv)(GLenum target, GLenum pname, GLint* params);
	void (*glGetClipPlanef)(GLenum pname, GLfloat eqn[4]);
	void (*glGetClipPlanex)(GLenum pname, GLfixed eqn[4]);
	GLenum (*glGetError)(void);
	void (*glGetFixedv)(GLenum pname, GLfixed *params);
	void (*glGetFloatv)(GLenum pname, GLfloat* params);
	void (*glGetFramebufferAttachmentParameterivOES)(GLenum target, GLenum attachment, GLenum pname, GLint* params);
	void (*glGetIntegerv)(GLenum pname, GLint* params);
	void (*glGetLightfv)(GLenum light, GLenum pname, GLfloat *params);
	void (*glGetLightxv)(GLenum light, GLenum pname, GLfixed *params);
	void (*glGetMaterialfv)(GLenum face, GLenum pname, GLfloat *params);
	void (*glGetMaterialxv)(GLenum face, GLenum pname, GLfixed *params);
	void (*glGetPointerv)(GLenum pname, GLvoid **params);
	const GLubyte* (*glGetString)(GLenum name);
	void (*glGetTexParameterfv)(GLenum target, GLenum pname, GLfloat* params);
	void (*glGetTexParameteriv)(GLenum target, GLenum pname, GLint* params);
	void (*glGetTexEnvfv)(GLenum env, GLenum pname, GLfloat *params);
	void (*glGetTexEnviv)(GLenum env, GLenum pname, GLint *params);
	void (*glGetTexEnvxv)(GLenum env, GLenum pname, GLfixed *params);
	void (*glGetTexParameterxv)(GLenum target, GLenum pname, GLfixed *params);
	void (*glHint)(GLenum target, GLenum mode);
	GLboolean (*glIsBuffer)(GLuint buffer);
	GLboolean (*glIsEnabled)(GLenum cap);
	GLboolean (*glIsFramebufferOES)(GLuint framebuffer);
	GLboolean (*glIsTexture)(GLuint texture);
	GLboolean (*glIsRenderbufferOES)(GLuint renderbuffer);
	void (*glLightModelf)(GLenum pname, GLfloat param);
	void (*glLightModelfv)(GLenum pname, const GLfloat *params);
	void (*glLightModelx)(GLenum pname, GLfixed param);
	void (*glLightModelxv)(GLenum pname, const GLfixed *params);
	void (*glLightf)(GLenum light, GLenum pname, GLfloat param);
	void (*glLightfv)(GLenum light, GLenum pname, const GLfloat *params);
	void (*glLightx)(GLenum light, GLenum pname, GLfixed param);
	void (*glLightxv)(GLenum light, GLenum pname, const GLfixed *params);
	void (*glLineWidth)(GLfloat width);
	void (*glLineWidthx)(GLfixed width);
	void (*glLoadIdentity)(void);
	void (*glLoadMatrixf)(const GLfloat *m);
	void (*glLoadMatrixx)(const GLfixed *m);
	void (*glLogicOp)(GLenum opcode);
	void (*glMaterialf)(GLenum face, GLenum pname, GLfloat param);
	void (*glMaterialfv)(GLenum face, GLenum pname, const GLfloat *params);
	void (*glMaterialx)(GLenum face, GLenum pname, GLfixed param);
	void (*glMaterialxv)(GLenum face, GLenum pname, const GLfixed *params);
	void (*glMatrixMode)(GLenum mode);
	void (*glMultMatrixf)(const GLfloat *m);
	void (*glMultMatrixx)(const GLfixed *m);
	void (*glMultiTexCoord4f)(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q);
	void (*glMultiTexCoord4x)(GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q);
	void (*glNormal3f)(GLfloat nx, GLfloat ny, GLfloat nz);
	void (*glNormal3x)(GLfixed nx, GLfixed ny, GLfixed nz);
	void (*glNormalPointer)(GLenum type, GLsizei stride, const GLvoid *pointer);
	void (*glOrthof)(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar);
	void (*glOrthox)(GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar);
	void (*glPixelStorei)(GLenum pname, GLint param);
	void (*glPointParameterf)(GLenum pname, GLfloat param);
	void (*glPointParameterfv)(GLenum pname, const GLfloat *params);
	void (*glPointParameterx)(GLenum pname, GLfixed param);
	void (*glPointParameterxv)(GLenum pname, const GLfixed *params);
	void (*glPointSize)(GLfloat size);
	void (*glPointSizePointerOES)(GLenum type, GLsizei stride, const GLvoid *pointer);
	void (*glPointSizex)(GLfixed size);
	void (*glPolygonOffset)(GLfloat factor, GLfloat units);
	void (*glPolygonOffsetx)(GLfixed factor, GLfixed units);
	void (*glPopMatrix)(void);
	void (*glPushMatrix)(void);
	void (*glReadPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels);
	void (*glRenderbufferStorageOES)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
	void (*glRotatef)(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
	void (*glRotatex)(GLfixed angle, GLfixed x, GLfixed y, GLfixed z);
	void (*glSampleCoverage)(GLclampf value, GLboolean invert);
	void (*glSampleCoveragex)(GLclampx value, GLboolean invert);
	void (*glScalef)(GLfloat x, GLfloat y, GLfloat z);
	void (*glScalex)(GLfixed x, GLfixed y, GLfixed z);
	void (*glScissor)(GLint x, GLint y, GLsizei width, GLsizei height);
	void (*glShadeModel)(GLenum mode);
	void (*glStencilFunc)(GLenum func, GLint ref, GLuint mask);
	void (*glStencilMask)(GLuint mask);
	void (*glStencilOp)(GLenum fail, GLenum zfail, GLenum zpass);
	void (*glTexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
	void (*glTexEnvf)(GLenum target, GLenum pname, GLfloat param);
	void (*glTexEnvfv)(GLenum target, GLenum pname, const GLfloat *params);
	void (*glTexEnvi)(GLenum target, GLenum pname, GLint param);
	void (*glTexEnvx)(GLenum target, GLenum pname, GLfixed param);
	void (*glTexEnviv)(GLenum target, GLenum pname, const GLint *params);
	void (*glTexEnvxv)(GLenum target, GLenum pname, const GLfixed *params);
	void (*glTexImage2D)(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
	                     GLint border, GLenum format, GLenum type, const GLvoid* pixels);
	void (*glTexParameterf)(GLenum target, GLenum pname, GLfloat param);
	void (*glTexParameterfv)(GLenum target, GLenum pname, const GLfloat* params);
	void (*glTexParameteri)(GLenum target, GLenum pname, GLint param);
	void (*glTexParameteriv)(GLenum target, GLenum pname, const GLint* params);
	void (*glTexParameterx)(GLenum target, GLenum pname, GLfixed param);
	void (*glTexParameterxv)(GLenum target, GLenum pname, const GLfixed *params);
	void (*glTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
	                        GLenum format, GLenum type, const GLvoid* pixels);
	void (*glTranslatef)(GLfloat x, GLfloat y, GLfloat z);
	void (*glTranslatex)(GLfixed x, GLfixed y, GLfixed z);
	void (*glVertexPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
	void (*glViewport)(GLint x, GLint y, GLsizei width, GLsizei height);
	void (*glEGLImageTargetTexture2DOES)(GLenum target, GLeglImageOES image);
	void (*glEGLImageTargetRenderbufferStorageOES)(GLenum target, GLeglImageOES image);
	void (*glDrawTexsOES)(GLshort x, GLshort y, GLshort z, GLshort width, GLshort height);
	void (*glDrawTexiOES)(GLint x, GLint y, GLint z, GLint width, GLint height);
	void (*glDrawTexxOES)(GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height);
	void (*glDrawTexsvOES)(const GLshort *coords);
	void (*glDrawTexivOES)(const GLint *coords);
	void (*glDrawTexxvOES)(const GLfixed *coords);
	void (*glDrawTexfOES)(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height);
	void (*glDrawTexfvOES)(const GLfloat *coords);

	egl::Context *(*es1CreateContext)(egl::Display *display, const egl::Context *shareContext, const egl::Config *config);
	__eglMustCastToProperFunctionPointerType (*es1GetProcAddress)(const char *procname);
	egl::Image *(*createBackBuffer)(int width, int height, sw::Format format, int multiSampleDepth);
	egl::Image *(*createDepthStencil)(int width, int height, sw::Format format, int multiSampleDepth);
	sw::FrameBuffer *(*createFrameBuffer)(void *nativeDisplay, EGLNativeWindowType window, int width, int height);
};

class LibGLES_CM
{
public:
	LibGLES_CM()
	{
		libGLES_CM = nullptr;
		libGLES_CMexports = nullptr;
	}

	~LibGLES_CM()
	{
		freeLibrary(libGLES_CM);
	}

	operator bool()
	{
		return loadExports() != nullptr;
	}

	LibGLES_CMexports *operator->()
	{
		return loadExports();
	}

private:
	LibGLES_CMexports *loadExports()
	{
		if(!libGLES_CM)
		{
			#if defined(_WIN32)
				#if defined(__LP64__)
					const char *libGLES_CM_lib[] = {"libGLES_CM.dll", "lib64GLES_CM_translator.dll"};
				#else
					const char *libGLES_CM_lib[] = {"libGLES_CM.dll", "libGLES_CM_translator.dll"};
				#endif
			#elif defined(__ANDROID__)
				#if defined(__LP64__)
					const char *libGLES_CM_lib[] = {"/vendor/lib64/egl/libGLESv1_CM_swiftshader.so", "/system/lib64/egl/libGLESv1_CM_swiftshader.so"};
				#else
					const char *libGLES_CM_lib[] = {"/vendor/lib/egl/libGLESv1_CM_swiftshader.so", "/system/lib/egl/libGLESv1_CM_swiftshader.so"};
				#endif
			#elif defined(__linux__)
				#if defined(__LP64__)
					const char *libGLES_CM_lib[] = {"lib64GLES_CM_translator.so", "libGLES_CM.so.1", "libGLES_CM.so"};
				#else
					const char *libGLES_CM_lib[] = {"libGLES_CM_translator.so", "libGLES_CM.so.1", "libGLES_CM.so"};
				#endif
			#elif defined(__APPLE__)
				#if defined(__LP64__)
					const char *libGLES_CM_lib[] = {"lib64GLES_CM_translator.dylib", "libGLES_CM.dylib"};
				#else
					const char *libGLES_CM_lib[] = {"libGLES_CM_translator.dylib", "libGLES_CM.dylib"};
				#endif
			#elif defined(__Fuchsia__)
				const char *libGLES_CM_lib[] = {"libGLES_CM.so"};
			#else
				#error "libGLES_CM::loadExports unimplemented for this platform"
			#endif

			libGLES_CM = loadLibrary(libGLES_CM_lib, "libGLES_CM_swiftshader");

			if(libGLES_CM)
			{
				auto libGLES_CM_swiftshader = (LibGLES_CMexports *(*)())getProcAddress(libGLES_CM, "libGLES_CM_swiftshader");
				libGLES_CMexports = libGLES_CM_swiftshader();
			}
		}

		return libGLES_CMexports;
	}

	void *libGLES_CM;
	LibGLES_CMexports *libGLES_CMexports;
};

#endif   // libGLES_CM_hpp