John Reck | 041b985 | 2015-02-25 14:32:41 -0800 | [diff] [blame] | 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 | |
John Reck | 975591a | 2016-01-22 16:28:07 -0800 | [diff] [blame] | 17 | #include "unwrap_gles.h" |
| 18 | |
John Reck | 041b985 | 2015-02-25 14:32:41 -0800 | [diff] [blame] | 19 | #include <GLES3/gl3.h> |
| 20 | #include <GLES2/gl2ext.h> |
| 21 | |
| 22 | #include <stdlib.h> |
| 23 | #include <string.h> |
| 24 | |
| 25 | struct { |
| 26 | GLboolean scissorEnabled; |
| 27 | } gState; |
| 28 | |
| 29 | void 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 | |
| 37 | void glGenBuffers(GLsizei n, GLuint *buffers) { |
| 38 | glGenCommon(n, buffers); |
| 39 | } |
| 40 | |
| 41 | void glGenFramebuffers(GLsizei n, GLuint *framebuffers) { |
| 42 | glGenCommon(n, framebuffers); |
| 43 | } |
| 44 | |
| 45 | void glGenRenderbuffers(GLsizei n, GLuint *renderbuffers) { |
| 46 | glGenCommon(n, renderbuffers); |
| 47 | } |
| 48 | |
| 49 | void glGenTextures(GLsizei n, GLuint *textures) { |
| 50 | glGenCommon(n, textures); |
| 51 | } |
| 52 | |
| 53 | GLuint glCreateProgram(void) { |
| 54 | static GLuint nextProgram = 0; |
| 55 | return ++nextProgram; |
| 56 | } |
| 57 | |
| 58 | GLuint glCreateShader(GLenum type) { |
| 59 | static GLuint nextShader = 0; |
| 60 | return ++nextShader; |
| 61 | } |
| 62 | |
| 63 | void 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 | |
| 76 | void 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 | |
| 83 | void 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 | |
| 91 | void 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 | |
| 98 | void setBooleanState(GLenum cap, GLboolean value) { |
| 99 | switch (cap) { |
| 100 | case GL_SCISSOR_TEST: |
| 101 | gState.scissorEnabled = value; |
| 102 | break; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | void glEnable(GLenum cap) { |
| 107 | setBooleanState(cap, GL_TRUE); |
| 108 | } |
| 109 | |
| 110 | void glDisable(GLenum cap) { |
| 111 | setBooleanState(cap, GL_FALSE); |
| 112 | } |
| 113 | |
| 114 | GLboolean glIsEnabled(GLenum cap) { |
| 115 | switch (cap) { |
| 116 | case GL_SCISSOR_TEST: |
| 117 | return gState.scissorEnabled; |
| 118 | default: |
| 119 | return GL_FALSE; |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | void 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 | |
Chris Craik | 0280628 | 2016-03-11 19:16:21 -0800 | [diff] [blame] | 136 | GLenum 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 | |
John Reck | 041b985 | 2015-02-25 14:32:41 -0800 | [diff] [blame] | 145 | const 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 | |
| 161 | const GLubyte* glGetString(GLenum name) { |
| 162 | return (GLubyte*) getString(name); |
| 163 | } |
| 164 | |
| 165 | void glActiveTexture(GLenum texture) {} |
| 166 | void glAttachShader(GLuint program, GLuint shader) {} |
| 167 | void glBindAttribLocation(GLuint program, GLuint index, const GLchar *name) {} |
| 168 | void glBindBuffer(GLenum target, GLuint buffer) {} |
| 169 | void glBindFramebuffer(GLenum target, GLuint framebuffer) {} |
| 170 | void glBindRenderbuffer(GLenum target, GLuint renderbuffer) {} |
| 171 | void glBindTexture(GLenum target, GLuint texture) {} |
| 172 | void glBlendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) {} |
| 173 | void glBlendEquation(GLenum mode) {} |
| 174 | void glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha) {} |
| 175 | void glBlendFunc(GLenum sfactor, GLenum dfactor) {} |
| 176 | void glBlendFuncSeparate(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha) {} |
| 177 | void glBufferData(GLenum target, GLsizeiptr size, const void *data, GLenum usage) {} |
| 178 | void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data) {} |
| 179 | void glClear(GLbitfield mask) {} |
| 180 | void glClearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) {} |
| 181 | void glClearDepthf(GLfloat d) {} |
| 182 | void glClearStencil(GLint s) {} |
| 183 | void glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) {} |
| 184 | void glCompileShader(GLuint shader) {} |
| 185 | void glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data) {} |
| 186 | void glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data) {} |
| 187 | void glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) {} |
| 188 | void glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) {} |
| 189 | void glCullFace(GLenum mode) {} |
| 190 | void glDeleteBuffers(GLsizei n, const GLuint *buffers) {} |
| 191 | void glDeleteFramebuffers(GLsizei n, const GLuint *framebuffers) {} |
| 192 | void glDeleteProgram(GLuint program) {} |
| 193 | void glDeleteRenderbuffers(GLsizei n, const GLuint *renderbuffers) {} |
| 194 | void glDeleteShader(GLuint shader) {} |
| 195 | void glDeleteTextures(GLsizei n, const GLuint *textures) {} |
| 196 | void glDepthFunc(GLenum func) {} |
| 197 | void glDepthMask(GLboolean flag) {} |
| 198 | void glDepthRangef(GLfloat n, GLfloat f) {} |
| 199 | void glDetachShader(GLuint program, GLuint shader) {} |
| 200 | void glDisableVertexAttribArray(GLuint index) {} |
| 201 | void glDrawArrays(GLenum mode, GLint first, GLsizei count) {} |
| 202 | void glDrawElements(GLenum mode, GLsizei count, GLenum type, const void *indices) {} |
| 203 | void glEnableVertexAttribArray(GLuint index) {} |
| 204 | void glFinish(void) {} |
| 205 | void glFlush(void) {} |
| 206 | void glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) {} |
| 207 | void glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) {} |
| 208 | void glFrontFace(GLenum mode) {} |
| 209 | void glGenerateMipmap(GLenum target) {} |
| 210 | GLint glGetAttribLocation(GLuint program, const GLchar *name) { return 1; } |
| 211 | GLenum glGetError(void) { return GL_NO_ERROR; } |
| 212 | GLint glGetUniformLocation(GLuint program, const GLchar *name) { return 2; } |
| 213 | void glHint(GLenum target, GLenum mode) {} |
| 214 | void glLineWidth(GLfloat width) {} |
| 215 | void glLinkProgram(GLuint program) {} |
| 216 | void glPixelStorei(GLenum pname, GLint param) {} |
| 217 | void glPolygonOffset(GLfloat factor, GLfloat units) {} |
| 218 | void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels) {} |
| 219 | void glReleaseShaderCompiler(void) {} |
| 220 | void glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height) {} |
| 221 | void glSampleCoverage(GLfloat value, GLboolean invert) {} |
| 222 | void glScissor(GLint x, GLint y, GLsizei width, GLsizei height) {} |
| 223 | void glShaderBinary(GLsizei count, const GLuint *shaders, GLenum binaryformat, const void *binary, GLsizei length) {} |
| 224 | void glShaderSource(GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length) {} |
| 225 | void glStencilFunc(GLenum func, GLint ref, GLuint mask) {} |
| 226 | void glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask) {} |
| 227 | void glStencilMask(GLuint mask) {} |
| 228 | void glStencilMaskSeparate(GLenum face, GLuint mask) {} |
| 229 | void glStencilOp(GLenum fail, GLenum zfail, GLenum zpass) {} |
| 230 | void glStencilOpSeparate(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass) {} |
| 231 | void glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels) {} |
| 232 | void glTexParameterf(GLenum target, GLenum pname, GLfloat param) {} |
| 233 | void glTexParameterfv(GLenum target, GLenum pname, const GLfloat *params) {} |
| 234 | void glTexParameteri(GLenum target, GLenum pname, GLint param) {} |
| 235 | void glTexParameteriv(GLenum target, GLenum pname, const GLint *params) {} |
| 236 | void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels) {} |
| 237 | void glUniform1f(GLint location, GLfloat v0) {} |
| 238 | void glUniform1fv(GLint location, GLsizei count, const GLfloat *value) {} |
| 239 | void glUniform1i(GLint location, GLint v0) {} |
| 240 | void glUniform1iv(GLint location, GLsizei count, const GLint *value) {} |
| 241 | void glUniform2f(GLint location, GLfloat v0, GLfloat v1) {} |
| 242 | void glUniform2fv(GLint location, GLsizei count, const GLfloat *value) {} |
| 243 | void glUniform2i(GLint location, GLint v0, GLint v1) {} |
| 244 | void glUniform2iv(GLint location, GLsizei count, const GLint *value) {} |
| 245 | void glUniform3f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2) {} |
| 246 | void glUniform3fv(GLint location, GLsizei count, const GLfloat *value) {} |
| 247 | void glUniform3i(GLint location, GLint v0, GLint v1, GLint v2) {} |
| 248 | void glUniform3iv(GLint location, GLsizei count, const GLint *value) {} |
| 249 | void glUniform4f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) {} |
| 250 | void glUniform4fv(GLint location, GLsizei count, const GLfloat *value) {} |
| 251 | void glUniform4i(GLint location, GLint v0, GLint v1, GLint v2, GLint v3) {} |
| 252 | void glUniform4iv(GLint location, GLsizei count, const GLint *value) {} |
| 253 | void glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) {} |
| 254 | void glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) {} |
| 255 | void glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) {} |
| 256 | void glUseProgram(GLuint program) {} |
| 257 | void glValidateProgram(GLuint program) {} |
| 258 | void glVertexAttrib1f(GLuint index, GLfloat x) {} |
| 259 | void glVertexAttrib1fv(GLuint index, const GLfloat *v) {} |
| 260 | void glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y) {} |
| 261 | void glVertexAttrib2fv(GLuint index, const GLfloat *v) {} |
| 262 | void glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z) {} |
| 263 | void glVertexAttrib3fv(GLuint index, const GLfloat *v) {} |
| 264 | void glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w) {} |
| 265 | void glVertexAttrib4fv(GLuint index, const GLfloat *v) {} |
| 266 | void glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer) {} |
| 267 | void glViewport(GLint x, GLint y, GLsizei width, GLsizei height) {} |
| 268 | |
| 269 | |
| 270 | // gles2 ext |
| 271 | void glInsertEventMarkerEXT(GLsizei length, const GLchar *marker) {} |
| 272 | void glPushGroupMarkerEXT(GLsizei length, const GLchar *marker) {} |
| 273 | void glPopGroupMarkerEXT(void) {} |
| 274 | void glDiscardFramebufferEXT(GLenum target, GLsizei numAttachments, const GLenum *attachments) {} |
John Reck | 041b985 | 2015-02-25 14:32:41 -0800 | [diff] [blame] | 275 | void glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image) {} |
| 276 | |
| 277 | // GLES3 |
| 278 | void* glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access) { |
| 279 | return 0; |
| 280 | } |
| 281 | |
| 282 | GLboolean glUnmapBuffer(GLenum target) { |
| 283 | return GL_FALSE; |
| 284 | } |