blob: ffb0649429112eafbe24f2ea86b21fe91883d52d [file] [log] [blame]
John Reck041b9852015-02-25 14:32:41 -08001/*
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
John Reck975591a2016-01-22 16:28:07 -080017#include "unwrap_gles.h"
18
John Reck041b9852015-02-25 14:32:41 -080019#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
136const char* getString(GLenum name) {
137 switch (name) {
138 case GL_VENDOR:
139 return "android";
140 case GL_RENDERER:
141 return "null";
142 case GL_VERSION:
143 return "OpenGL ES 2.0 rev1";
144 case GL_SHADING_LANGUAGE_VERSION:
145 return "OpenGL ES GLSL ES 2.0 rev1";
146 case GL_EXTENSIONS:
147 default:
148 return "";
149 }
150}
151
152const GLubyte* glGetString(GLenum name) {
153 return (GLubyte*) getString(name);
154}
155
156void glActiveTexture(GLenum texture) {}
157void glAttachShader(GLuint program, GLuint shader) {}
158void glBindAttribLocation(GLuint program, GLuint index, const GLchar *name) {}
159void glBindBuffer(GLenum target, GLuint buffer) {}
160void glBindFramebuffer(GLenum target, GLuint framebuffer) {}
161void glBindRenderbuffer(GLenum target, GLuint renderbuffer) {}
162void glBindTexture(GLenum target, GLuint texture) {}
163void glBlendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) {}
164void glBlendEquation(GLenum mode) {}
165void glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha) {}
166void glBlendFunc(GLenum sfactor, GLenum dfactor) {}
167void glBlendFuncSeparate(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha) {}
168void glBufferData(GLenum target, GLsizeiptr size, const void *data, GLenum usage) {}
169void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data) {}
170void glClear(GLbitfield mask) {}
171void glClearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) {}
172void glClearDepthf(GLfloat d) {}
173void glClearStencil(GLint s) {}
174void glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) {}
175void glCompileShader(GLuint shader) {}
176void glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data) {}
177void glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data) {}
178void glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) {}
179void glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) {}
180void glCullFace(GLenum mode) {}
181void glDeleteBuffers(GLsizei n, const GLuint *buffers) {}
182void glDeleteFramebuffers(GLsizei n, const GLuint *framebuffers) {}
183void glDeleteProgram(GLuint program) {}
184void glDeleteRenderbuffers(GLsizei n, const GLuint *renderbuffers) {}
185void glDeleteShader(GLuint shader) {}
186void glDeleteTextures(GLsizei n, const GLuint *textures) {}
187void glDepthFunc(GLenum func) {}
188void glDepthMask(GLboolean flag) {}
189void glDepthRangef(GLfloat n, GLfloat f) {}
190void glDetachShader(GLuint program, GLuint shader) {}
191void glDisableVertexAttribArray(GLuint index) {}
192void glDrawArrays(GLenum mode, GLint first, GLsizei count) {}
193void glDrawElements(GLenum mode, GLsizei count, GLenum type, const void *indices) {}
194void glEnableVertexAttribArray(GLuint index) {}
195void glFinish(void) {}
196void glFlush(void) {}
197void glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) {}
198void glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) {}
199void glFrontFace(GLenum mode) {}
200void glGenerateMipmap(GLenum target) {}
201GLint glGetAttribLocation(GLuint program, const GLchar *name) { return 1; }
202GLenum glGetError(void) { return GL_NO_ERROR; }
203GLint glGetUniformLocation(GLuint program, const GLchar *name) { return 2; }
204void glHint(GLenum target, GLenum mode) {}
205void glLineWidth(GLfloat width) {}
206void glLinkProgram(GLuint program) {}
207void glPixelStorei(GLenum pname, GLint param) {}
208void glPolygonOffset(GLfloat factor, GLfloat units) {}
209void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels) {}
210void glReleaseShaderCompiler(void) {}
211void glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height) {}
212void glSampleCoverage(GLfloat value, GLboolean invert) {}
213void glScissor(GLint x, GLint y, GLsizei width, GLsizei height) {}
214void glShaderBinary(GLsizei count, const GLuint *shaders, GLenum binaryformat, const void *binary, GLsizei length) {}
215void glShaderSource(GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length) {}
216void glStencilFunc(GLenum func, GLint ref, GLuint mask) {}
217void glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask) {}
218void glStencilMask(GLuint mask) {}
219void glStencilMaskSeparate(GLenum face, GLuint mask) {}
220void glStencilOp(GLenum fail, GLenum zfail, GLenum zpass) {}
221void glStencilOpSeparate(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass) {}
222void glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels) {}
223void glTexParameterf(GLenum target, GLenum pname, GLfloat param) {}
224void glTexParameterfv(GLenum target, GLenum pname, const GLfloat *params) {}
225void glTexParameteri(GLenum target, GLenum pname, GLint param) {}
226void glTexParameteriv(GLenum target, GLenum pname, const GLint *params) {}
227void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels) {}
228void glUniform1f(GLint location, GLfloat v0) {}
229void glUniform1fv(GLint location, GLsizei count, const GLfloat *value) {}
230void glUniform1i(GLint location, GLint v0) {}
231void glUniform1iv(GLint location, GLsizei count, const GLint *value) {}
232void glUniform2f(GLint location, GLfloat v0, GLfloat v1) {}
233void glUniform2fv(GLint location, GLsizei count, const GLfloat *value) {}
234void glUniform2i(GLint location, GLint v0, GLint v1) {}
235void glUniform2iv(GLint location, GLsizei count, const GLint *value) {}
236void glUniform3f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2) {}
237void glUniform3fv(GLint location, GLsizei count, const GLfloat *value) {}
238void glUniform3i(GLint location, GLint v0, GLint v1, GLint v2) {}
239void glUniform3iv(GLint location, GLsizei count, const GLint *value) {}
240void glUniform4f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) {}
241void glUniform4fv(GLint location, GLsizei count, const GLfloat *value) {}
242void glUniform4i(GLint location, GLint v0, GLint v1, GLint v2, GLint v3) {}
243void glUniform4iv(GLint location, GLsizei count, const GLint *value) {}
244void glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) {}
245void glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) {}
246void glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) {}
247void glUseProgram(GLuint program) {}
248void glValidateProgram(GLuint program) {}
249void glVertexAttrib1f(GLuint index, GLfloat x) {}
250void glVertexAttrib1fv(GLuint index, const GLfloat *v) {}
251void glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y) {}
252void glVertexAttrib2fv(GLuint index, const GLfloat *v) {}
253void glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z) {}
254void glVertexAttrib3fv(GLuint index, const GLfloat *v) {}
255void glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w) {}
256void glVertexAttrib4fv(GLuint index, const GLfloat *v) {}
257void glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer) {}
258void glViewport(GLint x, GLint y, GLsizei width, GLsizei height) {}
259
260
261// gles2 ext
262void glInsertEventMarkerEXT(GLsizei length, const GLchar *marker) {}
263void glPushGroupMarkerEXT(GLsizei length, const GLchar *marker) {}
264void glPopGroupMarkerEXT(void) {}
265void glDiscardFramebufferEXT(GLenum target, GLsizei numAttachments, const GLenum *attachments) {}
John Reck041b9852015-02-25 14:32:41 -0800266void 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}