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