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