1/*
2 * Copyright(C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0(the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "unwrap_gles.h"
18
19#include <GLES3/gl3.h>
20#include <GLES2/gl2ext.h>
21
22#include <stdlib.h>
23#include <string.h>
24
25struct {
26    GLboolean scissorEnabled;
27} gState;
28
29void glGenCommon(GLsizei n, GLuint *buffers) {
30    static GLuint nextId = 0;
31    int i;
32    for(i = 0; i < n; i++) {
33        buffers[i] = ++nextId;
34    }
35}
36
37void glGenBuffers(GLsizei n, GLuint *buffers) {
38    glGenCommon(n, buffers);
39}
40
41void glGenFramebuffers(GLsizei n, GLuint *framebuffers) {
42    glGenCommon(n, framebuffers);
43}
44
45void glGenRenderbuffers(GLsizei n, GLuint *renderbuffers) {
46    glGenCommon(n, renderbuffers);
47}
48
49void glGenTextures(GLsizei n, GLuint *textures) {
50    glGenCommon(n, textures);
51}
52
53GLuint glCreateProgram(void) {
54    static GLuint nextProgram = 0;
55    return ++nextProgram;
56}
57
58GLuint glCreateShader(GLenum type) {
59    static GLuint nextShader = 0;
60    return ++nextShader;
61}
62
63void glGetProgramiv(GLuint program, GLenum pname, GLint *params) {
64    switch (pname) {
65    case GL_DELETE_STATUS:
66    case GL_LINK_STATUS:
67    case GL_VALIDATE_STATUS:
68        *params = GL_TRUE;
69        break;
70    case GL_INFO_LOG_LENGTH:
71        *params = 16;
72        break;
73    }
74}
75
76void glGetProgramInfoLog(GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog) {
77    *length = snprintf(infoLog, bufSize, "success");
78    if (*length >= bufSize) {
79        *length = bufSize - 1;
80    }
81}
82
83void glGetShaderiv(GLuint shader, GLenum pname, GLint *params) {
84    switch (pname) {
85    case GL_COMPILE_STATUS:
86    case GL_DELETE_STATUS:
87        *params = GL_TRUE;
88    }
89}
90
91void glGetShaderInfoLog(GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog) {
92    *length = snprintf(infoLog, bufSize, "success");
93    if (*length >= bufSize) {
94        *length = bufSize - 1;
95    }
96}
97
98void setBooleanState(GLenum cap, GLboolean value) {
99    switch (cap) {
100    case GL_SCISSOR_TEST:
101        gState.scissorEnabled = value;
102        break;
103    }
104}
105
106void glEnable(GLenum cap) {
107    setBooleanState(cap, GL_TRUE);
108}
109
110void glDisable(GLenum cap) {
111    setBooleanState(cap, GL_FALSE);
112}
113
114GLboolean glIsEnabled(GLenum cap) {
115    switch (cap) {
116    case GL_SCISSOR_TEST:
117        return gState.scissorEnabled;
118    default:
119        return GL_FALSE;
120    }
121}
122
123void glGetIntegerv(GLenum pname, GLint *data) {
124    switch (pname) {
125    case GL_MAX_TEXTURE_SIZE:
126        *data = 2048;
127        break;
128    case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
129        *data = 4;
130        break;
131    default:
132        *data = 0;
133    }
134}
135
136GLenum glCheckFramebufferStatus(GLenum target) {
137    switch (target) {
138    case GL_FRAMEBUFFER:
139        return GL_FRAMEBUFFER_COMPLETE;
140    default:
141        return 0; // error case
142    }
143}
144
145const char* getString(GLenum name) {
146    switch (name) {
147    case GL_VENDOR:
148        return "android";
149    case GL_RENDERER:
150        return "null";
151    case GL_VERSION:
152        return "OpenGL ES 2.0 rev1";
153    case GL_SHADING_LANGUAGE_VERSION:
154        return "OpenGL ES GLSL ES 2.0 rev1";
155    case GL_EXTENSIONS:
156    default:
157        return "";
158    }
159}
160
161const GLubyte* glGetString(GLenum name) {
162    return (GLubyte*) getString(name);
163}
164
165void glActiveTexture(GLenum texture) {}
166void glAttachShader(GLuint program, GLuint shader) {}
167void glBindAttribLocation(GLuint program, GLuint index, const GLchar *name) {}
168void glBindBuffer(GLenum target, GLuint buffer) {}
169void glBindFramebuffer(GLenum target, GLuint framebuffer) {}
170void glBindRenderbuffer(GLenum target, GLuint renderbuffer) {}
171void glBindTexture(GLenum target, GLuint texture) {}
172void glBlendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) {}
173void glBlendEquation(GLenum mode) {}
174void glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha) {}
175void glBlendFunc(GLenum sfactor, GLenum dfactor) {}
176void glBlendFuncSeparate(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha) {}
177void glBufferData(GLenum target, GLsizeiptr size, const void *data, GLenum usage) {}
178void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data) {}
179void glClear(GLbitfield mask) {}
180void glClearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) {}
181void glClearDepthf(GLfloat d) {}
182void glClearStencil(GLint s) {}
183void glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) {}
184void glCompileShader(GLuint shader) {}
185void glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data) {}
186void glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data) {}
187void glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) {}
188void glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) {}
189void glCullFace(GLenum mode) {}
190void glDeleteBuffers(GLsizei n, const GLuint *buffers) {}
191void glDeleteFramebuffers(GLsizei n, const GLuint *framebuffers) {}
192void glDeleteProgram(GLuint program) {}
193void glDeleteRenderbuffers(GLsizei n, const GLuint *renderbuffers) {}
194void glDeleteShader(GLuint shader) {}
195void glDeleteTextures(GLsizei n, const GLuint *textures) {}
196void glDepthFunc(GLenum func) {}
197void glDepthMask(GLboolean flag) {}
198void glDepthRangef(GLfloat n, GLfloat f) {}
199void glDetachShader(GLuint program, GLuint shader) {}
200void glDisableVertexAttribArray(GLuint index) {}
201void glDrawArrays(GLenum mode, GLint first, GLsizei count) {}
202void glDrawElements(GLenum mode, GLsizei count, GLenum type, const void *indices) {}
203void glEnableVertexAttribArray(GLuint index) {}
204void glFinish(void) {}
205void glFlush(void) {}
206void glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) {}
207void glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) {}
208void glFrontFace(GLenum mode) {}
209void glGenerateMipmap(GLenum target) {}
210GLint glGetAttribLocation(GLuint program, const GLchar *name) { return 1; }
211GLenum glGetError(void) { return GL_NO_ERROR; }
212GLint glGetUniformLocation(GLuint program, const GLchar *name) { return 2; }
213void glHint(GLenum target, GLenum mode) {}
214void glLineWidth(GLfloat width) {}
215void glLinkProgram(GLuint program) {}
216void glPixelStorei(GLenum pname, GLint param) {}
217void glPolygonOffset(GLfloat factor, GLfloat units) {}
218void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels) {}
219void glReleaseShaderCompiler(void) {}
220void glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height) {}
221void glSampleCoverage(GLfloat value, GLboolean invert) {}
222void glScissor(GLint x, GLint y, GLsizei width, GLsizei height) {}
223void glShaderBinary(GLsizei count, const GLuint *shaders, GLenum binaryformat, const void *binary, GLsizei length) {}
224void glShaderSource(GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length) {}
225void glStencilFunc(GLenum func, GLint ref, GLuint mask) {}
226void glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask) {}
227void glStencilMask(GLuint mask) {}
228void glStencilMaskSeparate(GLenum face, GLuint mask) {}
229void glStencilOp(GLenum fail, GLenum zfail, GLenum zpass) {}
230void glStencilOpSeparate(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass) {}
231void glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels) {}
232void glTexParameterf(GLenum target, GLenum pname, GLfloat param) {}
233void glTexParameterfv(GLenum target, GLenum pname, const GLfloat *params) {}
234void glTexParameteri(GLenum target, GLenum pname, GLint param) {}
235void glTexParameteriv(GLenum target, GLenum pname, const GLint *params) {}
236void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels) {}
237void glUniform1f(GLint location, GLfloat v0) {}
238void glUniform1fv(GLint location, GLsizei count, const GLfloat *value) {}
239void glUniform1i(GLint location, GLint v0) {}
240void glUniform1iv(GLint location, GLsizei count, const GLint *value) {}
241void glUniform2f(GLint location, GLfloat v0, GLfloat v1) {}
242void glUniform2fv(GLint location, GLsizei count, const GLfloat *value) {}
243void glUniform2i(GLint location, GLint v0, GLint v1) {}
244void glUniform2iv(GLint location, GLsizei count, const GLint *value) {}
245void glUniform3f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2) {}
246void glUniform3fv(GLint location, GLsizei count, const GLfloat *value) {}
247void glUniform3i(GLint location, GLint v0, GLint v1, GLint v2) {}
248void glUniform3iv(GLint location, GLsizei count, const GLint *value) {}
249void glUniform4f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) {}
250void glUniform4fv(GLint location, GLsizei count, const GLfloat *value) {}
251void glUniform4i(GLint location, GLint v0, GLint v1, GLint v2, GLint v3) {}
252void glUniform4iv(GLint location, GLsizei count, const GLint *value) {}
253void glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) {}
254void glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) {}
255void glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) {}
256void glUseProgram(GLuint program) {}
257void glValidateProgram(GLuint program) {}
258void glVertexAttrib1f(GLuint index, GLfloat x) {}
259void glVertexAttrib1fv(GLuint index, const GLfloat *v) {}
260void glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y) {}
261void glVertexAttrib2fv(GLuint index, const GLfloat *v) {}
262void glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z) {}
263void glVertexAttrib3fv(GLuint index, const GLfloat *v) {}
264void glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w) {}
265void glVertexAttrib4fv(GLuint index, const GLfloat *v) {}
266void glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer) {}
267void glViewport(GLint x, GLint y, GLsizei width, GLsizei height) {}
268
269
270// gles2 ext
271void glInsertEventMarkerEXT(GLsizei length, const GLchar *marker) {}
272void glPushGroupMarkerEXT(GLsizei length, const GLchar *marker) {}
273void glPopGroupMarkerEXT(void) {}
274void glDiscardFramebufferEXT(GLenum target, GLsizei numAttachments, const GLenum *attachments) {}
275void glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image) {}
276
277// GLES3
278void* glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access) {
279    return 0;
280}
281
282GLboolean glUnmapBuffer(GLenum target) {
283    return GL_FALSE;
284}
285