GL_API void GL_APIENTRY glFrontFace (GLenum mode) { State * state = GLES_GET_STATE(); if (GlesValidateEnum(state, mode, FrontFaceValues, GLES_ELEMENTSOF(FrontFaceValues))) { state->frontFace = mode; } }
GL_API void GL_APIENTRY glCullFace (GLenum mode) { State * state = GLES_GET_STATE(); if (GlesValidateEnum(state, mode, CullFaceValues, GLES_ELEMENTSOF(CullFaceValues))) { state->cullMode = mode; } }
GL_API void GL_APIENTRY glReleaseShaderCompilerOES(void) { State * state = GLES_GET_STATE(); if (state->compiler) { GlesCompilerDestroy(state->compiler); state->compiler = NULL; } }
GL_API void GL_APIENTRY glShaderSource(GLuint shader, GLsizei count, const char **string, const GLint *length) { State * state = GLES_GET_STATE(); GLuint index, totalLength = 0; char * text; Shader * shaderObject = GlesGetShaderObject(state, shader); if (!shaderObject) { return; } FreeShaderSource(shaderObject); for (index = 0; index < count; ++index) { const char * source = string[index]; GLuint lineLength = 0; if (source) { if (length && length[index] >= 0) { lineLength = length[index]; } else { lineLength = strlen(source); } } totalLength += lineLength; } text = shaderObject->text = (char *) GlesMalloc(totalLength + 1); if (!text) { GlesRecordOutOfMemory(state); return; } shaderObject->length = totalLength; for (index = 0; index < count; ++index) { const char * source = string[index]; if (source) { GLuint lineLength; if (length && length[index] >= 0) { lineLength = length[index]; } else { lineLength = strlen(source); } GlesMemcpy(text, source, lineLength); text += lineLength; } } /* add string terminator */ *text = '\0'; }
GL_API void GL_APIENTRY glDepthRangef (GLclampf zNear, GLclampf zFar) { State * state = GLES_GET_STATE(); state->depthRange[0] = zNear = GlesClampf(zNear); state->depthRange[1] = zFar = GlesClampf(zFar); state->depthOrigin = (zNear + zFar) / 2.0f; state->depthScale = ((zFar - zNear) / 2.0f) * (1.0f - FLT_EPSILON); }
GL_API void GL_APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const void *indices) { State * state = GLES_GET_STATE(); if (count < 0) { GlesRecordInvalidValue(state); return; } if (type != GL_UNSIGNED_BYTE && type != GL_UNSIGNED_SHORT) { GlesRecordInvalidEnum(state); return; } if (state->elementArrayBuffer) { GLubyte * bufferBase = (GLubyte *) state->buffers[state->elementArrayBuffer].data; if (!bufferBase) { GlesRecordInvalidOperation(state); return; } indices = bufferBase + ((const GLubyte *) indices - (const GLubyte *) NULL); } if (!indices) { return; } if (type == GL_UNSIGNED_BYTE) { const GLubyte * ptr = (const GLubyte *) indices; if (Begin(state, mode)) { while (count-- > 0) { state->drawFunction(state, *ptr++); } End(state); } } else if (type == GL_UNSIGNED_SHORT) { const GLushort * ptr = (const GLushort *) indices; if (Begin(state, mode)) { while (count-- > 0) { state->drawFunction(state, *ptr++); } End(state); } } else { GlesRecordInvalidEnum(state); } }
/* OES_shader_source + OES_shader_binary */ GL_API void GL_APIENTRY glGetShaderPrecisionFormatOES(GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision) { State * state = GLES_GET_STATE(); if (shadertype != GL_VERTEX_SHADER && shadertype != GL_FRAGMENT_SHADER) { GlesRecordInvalidEnum(state); return; } /* TODO: need to recognize the correct values for precisiontype */ *range = GLES_VERTEX_HIGH_FLOAT_RANGE; *precision = GLES_VERTEX_HIGH_FLOAT_PRECISION; }
GL_API void GL_APIENTRY glDeleteShader (GLuint shader) { State * state = GLES_GET_STATE(); Shader * shaderObject = GlesGetShaderObject(state, shader); if (!shaderObject) { return; } if (shaderObject->attachmentCount) { shaderObject->isDeleted = GL_TRUE; } else { GlesDeleteShader(state, shaderObject); } }
GL_API void GL_APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufsize, GLsizei *length, char *infolog) { State * state = GLES_GET_STATE(); Shader * shaderObject = GlesGetShaderObject(state, shader); if (!shaderObject) { return; } if (!infolog) { GlesRecordInvalidValue(state); return; } GlesLogExtract(&shaderObject->log, bufsize, infolog, length); }
GL_API void GL_APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height) { State * state = GLES_GET_STATE(); if (width < 0 || height < 0) { GlesRecordInvalidValue(state); } else { state->viewport.x = x; state->viewport.y = y; state->viewport.width = width; state->viewport.height = height; state->viewportOrigin.x = x + width / 2.0f; state->viewportOrigin.y = y + height / 2.0f; state->viewportScale.x = width / 2.0f; state->viewportScale.y = height / 2.0f; } }
GL_API void GL_APIENTRY glDrawArrays (GLenum mode, GLint first, GLsizei count) { State * state = GLES_GET_STATE(); if (count < 0) { GlesRecordInvalidValue(state); return; } if (Begin(state, mode)) { while (count-- > 0) { (state->drawFunction)(state, first++); } End(state); } }
GL_API GLuint GL_APIENTRY glCreateShader (GLenum type) { State * state = GLES_GET_STATE(); GLuint shader; if (type != GL_VERTEX_SHADER && type != GL_FRAGMENT_SHADER) { GlesRecordInvalidEnum(state); return 0; } shader = GlesBindObject(state->shaderFreeList, GLES_MAX_SHADERS); if (shader == NIL) { GlesRecordError(state, GL_OUT_OF_MEMORY); return 0; } else { InitShader(state->shaders + shader, type); return shader; } }
GL_API void GL_APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint *params) { State * state = GLES_GET_STATE(); Shader * shaderObject = GlesGetShaderObject(state, shader); if (!shaderObject) { return; } switch (pname) { case GL_SHADER_TYPE: *params = shaderObject->type; break; case GL_DELETE_STATUS: *params = shaderObject->isDeleted; break; case GL_COMPILE_STATUS: *params = shaderObject->isCompiled; break; case GL_INFO_LOG_LENGTH: *params = shaderObject->log.logSize + 1; break; case GL_SHADER_SOURCE_LENGTH: *params = shaderObject->length + 1; break; case GL_SHADER_INTERMEDIATE_LENGTH_VIN: *params = shaderObject->size + 1; break; default: GlesRecordInvalidEnum(state); return; } }
GL_API void GL_APIENTRY glGetShaderSource (GLuint shader, GLsizei bufsize, GLsizei *length, char *source) { State * state = GLES_GET_STATE(); GLsizei returnedLength; Shader * shaderObject = GlesGetShaderObject(state, shader); if (!shaderObject) { return; } if (!source) { GlesRecordInvalidValue(state); return; } returnedLength = shaderObject->length + 1 >= bufsize ? bufsize - 1 : shaderObject->length; GlesMemcpy(source, shaderObject->text, returnedLength); source[returnedLength] = '\0'; if (length) { *length = returnedLength; } }
GL_API void GL_APIENTRY glGetShaderIntermediateVIN (GLuint shader, GLsizei bufsize, GLsizei *length, char *intermediate) { State * state = GLES_GET_STATE(); Shader * shaderObject = GlesGetShaderObject(state, shader); GLsizei returnedLength; if (!shaderObject) { return; } if (!intermediate) { GlesRecordInvalidValue(state); return; } returnedLength = shaderObject->size + 1 >= bufsize ? bufsize - 1 : shaderObject->size; GlesMemcpy(intermediate, shaderObject->il, returnedLength); intermediate[returnedLength] = '\0'; if (length) { *length = returnedLength; } }
/* OES_shader_source */ GL_API void GL_APIENTRY glCompileShader (GLuint shader) { State * state = GLES_GET_STATE(); Shader * shaderObject = GlesGetShaderObject(state, shader); if (!shaderObject) { return; } GlesLogClear(&shaderObject->log); if (!state->compiler) { state->compiler = GlesCompilerCreate(state); if (!state->compiler) { GlesRecordOutOfMemory(state); return; } } shaderObject->isCompiled = GlesCompileShader(state->compiler, shaderObject); GLES_ASSERT(shaderObject->isCompiled == (shaderObject->il != NULL)); }
GL_API GLboolean GL_APIENTRY glIsShader (GLuint shader) { State * state = GLES_GET_STATE(); return GlesIsBoundObject(state->shaderFreeList, GLES_MAX_SHADERS, shader); }