char * GlesCompoundName(struct MemoryPool * pool, const char * base, GLsizei baseLength, const char * field, GLsizei fieldLength) { GLsizeiptr length = baseLength + fieldLength + 1; char * name = GlesMemoryPoolAllocate(pool, length); GlesMemcpy(name, base, baseLength); name[baseLength] = '.'; GlesMemcpy(name + baseLength + 1, field, fieldLength); return name; }
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'; }
ProgVar * GlesCreateProgVarParam(ShaderProgram * program, Type * type, const char * name, GLsizei length) { ProgVar * var = GlesMemoryPoolAllocate(program->memory, sizeof(ProgVarParam)); var->base.kind = ProgVarKindParam; var->base.id = program->numVars++; var->param.named.base.type = type; var->param.named.name = GlesMemoryPoolAllocate(program->memory, length); GlesMemcpy(var->param.named.name, name, length); var->param.named.length = length; var->param.named.base.next = program->param; program->param = var; return var; }
SymbolArray * GlesSymbolArrayGrow(struct MemoryPool * pool, SymbolArray * old) { GLsizeiptr newSize = old->allocated * 2; GLsizeiptr size = sizeof(struct SymbolArray) + sizeof(Symbol *) * newSize; SymbolArray * array = GlesMemoryPoolAllocate(pool, size); if (array) { array->allocated = newSize; array->used = old->used; GlesMemcpy(array->values, old->values, old->used * sizeof(Symbol *)); } return array; }
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; } }
ProgVar * GlesCreateProgVarConst(ShaderProgram * program, Constant * constant, Type * type) { GLsizei hash = GlesHashConstant(constant, type) % GLES_CONSTANT_HASH; ProgVar * var; for (var = program->constants[hash]; var; var = var->base.next) { if (GlesCompareConstant(var->constant.values, constant, type)) { return var; } } var = GlesMemoryPoolAllocate(program->memory, sizeof(ProgVarConst)); var->base.kind = ProgVarKindConst; var->base.type = type; var->base.id = program->numVars++; var->constant.values = GlesMemoryPoolAllocate(program->memory, sizeof(Constant) * type->base.size); GlesMemcpy(var->constant.values, constant, sizeof(Constant) * type->base.size); var->base.next = program->constants[hash]; program->constants[hash] = var; return var; }
Symbol * GlesSymbolCreate(struct MemoryPool * pool, Scope * scope, const char * name, GLsizei length, GLsizei hash, Type * type, Qualifier qualifier) { GLsizeiptr size; Symbol * symbol; switch (qualifier) { case QualifierConstant: /* constant value */ case QualifierVariable: /* general variable */ case QualifierAttrib: /* vertex attrib */ case QualifierUniform: /* uniform value */ case QualifierVarying: /* varying value */ size = sizeof(SymbolVariable); break; case QualifierField: /* struct member */ size = sizeof(SymbolField); break; case QualifierFunction: /* user-defined function */ size = sizeof(SymbolFunction); break; case QualifierParameterIn: /* input parameter */ case QualifierParameterOut: /* output parameter */ case QualifierParameterInOut: /* input/output parameter */ size = sizeof(SymbolParameter); break; case QualifierTypeName: /* type name */ case QualifierPosition: /* gl_Position variable */ case QualifierPointSize: /* gl_PointSize */ case QualifierFragCoord: /* gl_FragCoord */ case QualifierFrontFacing: /* gl_FrontFacing */ case QualifierFragColor: /* gl_FragColor */ case QualifierFragData: /* gl_FragData */ case QualifierPointCoord: /* gl_PointCoord */ size = sizeof(SymbolBase); break; default: GLES_ASSERT(GL_FALSE); return NULL; } symbol = (Symbol *) GlesMemoryPoolAllocate(pool, size); symbol->base.name = (char *) GlesMemoryPoolAllocate(pool, length); GlesMemcpy(symbol->base.name, name, length); symbol->base.length = length; symbol->base.type = type; symbol->base.qualifier = qualifier; symbol->base.scope = scope; /*implied: symbol->base.next = NULL;*/ if (hash == ~0) { hash = GlesSymbolHash(name, length); } symbol->base.next = scope->buckets[hash]; scope->buckets[hash] = symbol; return symbol; }