bool CDirectiveArea::LoadStart(ArgumentList &Args) { if (initExpression(SizeExpression,Args[0].text) == false) return false; Start = true; if (Args.size() == 2) { if (initExpression(FillExpression,Args[1].text) == false) return false; } return true; }
CDirectiveData::CDirectiveData(ArgumentList& Args, int SizePerUnit, bool asc) { TotalAmount = Args.size(); StrAmount = 0; ExpAmount = 0; for (int i = 0; i < TotalAmount; i++) { if (Args[i].isString == true) { StrAmount++; } else { ExpAmount++; } } Entries = (tDirectiveDataEntry*) malloc(TotalAmount*sizeof(tDirectiveDataEntry)); ExpData = new CExpressionCommandList[ExpAmount]; switch (SizePerUnit) { case 1: case 2: case 4: UnitSize = SizePerUnit; ascii = asc; break; default: Logger::printError(Logger::Error,L"Invalid data unit size %d",SizePerUnit); return; } int ExpNum = 0; SpaceNeeded = 0; for (int i = 0; i < TotalAmount; i++) { if (Args[i].isString == true) { std::string tt = convertWStringToUtf8(Args[i].text); char* t = (char*) tt.c_str(); int len = strlen(t); Entries[i].String = true; Entries[i].num = StrData.GetCount(); StrData.AddEntry((unsigned char*)t,len); SpaceNeeded += len*UnitSize; } else { Entries[i].String = false; Entries[i].num = ExpNum; if (initExpression(ExpData[ExpNum++],Args[i].text) == false) return; SpaceNeeded += UnitSize; } } g_fileManager->advanceMemory(SpaceNeeded); }
int FLTApplyFilterToLayerCommonExpression(mapObj *map, int iLayerIndex, char *pszExpression) { int retval; msInitQuery(&(map->query)); map->query.type = MS_QUERY_BY_FILTER; map->query.filter = (expressionObj *) msSmallMalloc(sizeof(expressionObj)); initExpression( map->query.filter); map->query.filter->string = msStrdup(pszExpression); map->query.filter->type = 2000; map->query.layer = iLayerIndex; /*TODO: if there is a bbox in the node, get it and set the map extent*/ map->query.rect = map->extent; retval = msQueryByFilter(map); return retval; }
void load_glslshaderbind () { int i; int num; char string_name[128]; char string_type[128]; char string_value[512]; varFloat* vfloat; varVec2* vec2; varVec3* vec3; varVec4* vec4; varSampler2D* sampler2D; script_variable_matrix_4x4* pVariableMatrix4x4; // script validation // 2 strings needed: Vertex and fragment shader path if (mySection->stringNum < 2){ section_error("At least 2 strings are needed: vertex and fragment shader files"); return; } local = malloc(sizeof(glslshaderbind_section)); mySection->vars = (void *) local; // load program, 2 first strings are vertex and fragment program paths local->program = glslshad_load(mySection->strings[0], mySection->strings[1]); if (local->program == -1) return; glslshad_upload(local->program); glslshad_bind(local->program); // We need to use the program (bind it) in order to retrieve it locations (some drivers need it) // Reset variables local->vfloat_num = 0; local->vec2_num = 0; local->vec3_num = 0; local->vec4_num = 0; local->sampler2D_num = 0; local->matrix4x4_num = 0; num = 0; // Read the variables for (i=2; i<mySection->stringNum; i++) { sscanf ( mySection->strings[i], "%s %s %s", string_type, string_name, string_value); // Read one string and store values on temporary strings for frther evaluation dkernel_trace("glslshaderbind: string_type [%s], string_name [%s], string_value [%s]", string_type, string_name, string_value); remove_spaces(string_value); if (strcmp(string_type,"float")==0) // FLOAT detected { num = max_shader_reached ( local->vfloat_num++ ); vfloat = &(local->vfloat[num]); strcpy (vfloat->name, string_name); strcpy (vfloat->equation, string_value); vfloat->loc = glslshad_getUniformLocation (local->program, vfloat->name); vfloat->eva.equation = vfloat->equation; initExpression(&vfloat->eva); // Inits the evaluator } else if (strcmp(string_type,"vec2")==0) // VEC2 detected { num = max_shader_reached ( local->vec2_num++ ); vec2 = &(local->vec2[num]); strcpy (vec2->name, string_name); strcpy (vec2->equation, string_value); vec2->loc = glslshad_getUniformLocation (local->program, vec2->name); vec2->eva.equation = vec2->equation; initExpression(&vec2->eva); // Inits the evaluator } else if (strcmp(string_type,"vec3")==0) // VEC3 detected { num = max_shader_reached ( local->vec3_num++ ); vec3 = &(local->vec3[num]); strcpy (vec3->name, string_name); strcpy (vec3->equation, string_value); vec3->loc = glslshad_getUniformLocation (local->program, vec3->name); vec3->eva.equation = vec3->equation; initExpression(&vec3->eva); // Inits the evaluator } else if (strcmp(string_type,"vec4")==0) // VEC4 detected { num = max_shader_reached ( local->vec4_num++ ); vec4 = &(local->vec4[num]); strcpy (vec4->name, string_name); strcpy (vec4->equation, string_value); vec4->loc = glslshad_getUniformLocation (local->program, vec4->name); vec4->eva.equation = vec4->equation; initExpression(&vec4->eva); // Inits the evaluator } else if (strcmp(string_type,"sampler2D")==0) // Texture (sampler2D) detected { num = max_shader_reached ( local->sampler2D_num++ ); sampler2D = &(local->sampler2D[num]); strcpy (sampler2D->name, string_name); // If sampler2D is a fbo... if (0 == strncmp("fbo",string_value,3)) { int fbonum; sscanf(string_value, "fbo%d",&fbonum); if (fbonum<0 || fbonum>(FBO_BUFFERS - 1)) { section_error("sampler2D fbo not correct, it should be 'fboX', where X=>0 and X<=%d, you choose: %s", (FBO_BUFFERS - 1), string_value); return; } else { sampler2D->texture = demoSystem.fboRenderingBuffer[fbonum]; sampler2D->texGLid = fbo_get_texbind_id(sampler2D->texture); } } // Is it s a normal texture... else { sampler2D->texture = tex_load (string_value, USE_CACHE); if (sampler2D->texture == -1) return; tex_properties(sampler2D->texture, NO_MIPMAP); tex_upload (sampler2D->texture, USE_CACHE); sampler2D->texGLid = tex_get_OpenGLid(sampler2D->texture); } sampler2D->loc = glslshad_getUniformLocation (local->program, sampler2D->name); glUniform1i(sampler2D->loc, (GLuint)num); } else if (strcmp(string_type,"mat4")==0) { num = max_shader_reached( local->matrix4x4_num++ ); pVariableMatrix4x4 = &local->matrix4x4[num]; strcpy(pVariableMatrix4x4->m_name, string_name); // remove the ';' if (string_value[0] != '\0') string_value[strlen(string_value)-1] = '\0'; pVariableMatrix4x4->m_SVEVariableID = get_sve_variable_id(string_value); pVariableMatrix4x4->m_ShaderUniformID = glslshad_getUniformLocation(local->program, pVariableMatrix4x4->m_name); // check whether the requested SVE Matrix4x4 variable exists /* if (get_sve_variable_type(pVariableMatrix4x4->m_SVEVariableID) != sve_variable_type_matrix_4x4f) { section_error("\"%s\" is not a valid SVE Engine Matrix4x4 variable", string_value); return; } */ } } // Unbind any shader used glslshad_reset_bind(); glUseProgram(0); mySection->loaded=1; }
void load_objectShader () { char *fullName; char *positionEquation; size_t theSize; // script validation if ((mySection->paramNum != 1)||(mySection->stringNum < 10)) { section_error("1 param and 10 strings needed"); return; } local = malloc(sizeof(objectShader_section)); if (!local) { dkernel_error("insuficient memory"); return; } else { mySection->vars = (void *) local; // Depth Buffer Clearing Flag local->enableDepthBufferClearing = (int)mySection->param[0]; // load object model theSize = strlen(mySection->strings[0]) + strlen(mySection->strings[1]); fullName = calloc(theSize+1, sizeof(char)); sprintf(fullName, "%s%s", mySection->strings[0], mySection->strings[1]); local->object = model_load(fullName, USE_CACHE); if (!local->object) { section_error("ObjectShader: Error loading object %s for drawing", fullName); return; } if (model_upload_tex(local->object, mySection->strings[0]) == -1) return; // load layers for drawing the object local->layers = layers_load(mySection->strings[2]); // load sources model if (strcmp(mySection->strings[3], "default") != 0) { local->sources = model_load(mySection->strings[3], USE_CACHE); if (!local->object) { section_error("ObjectShader: Error loading object %s for sources positioning", mySection->strings[3]); return; } } else { local->sources = NULL; } // load the object positioning equation theSize = strlen(mySection->strings[4]) + strlen(mySection->strings[5]) + strlen(mySection->strings[6]); positionEquation = calloc(theSize+1, sizeof(char)); sprintf(positionEquation, "%s%s%s", mySection->strings[4], mySection->strings[5], mySection->strings[6]); local->evalPositioning.equation = positionEquation; // load the sources positioning equation theSize = strlen(mySection->strings[7]) + strlen(mySection->strings[8]) + strlen(mySection->strings[9]); positionEquation = calloc(theSize+1, sizeof(char)); sprintf(positionEquation, "%s%s%s", mySection->strings[7], mySection->strings[8], mySection->strings[9]); local->evalSources.equation = positionEquation; // Init the expression evaluation library initExpression(&local->evalPositioning); initExpression(&local->evalSources); } mySection->loaded=1; }
void load_objectMatrix() { char *evalEquation; char *evalSources; size_t equationSize; H3dsMeshObj *mesh; int i; // script validation if (mySection->stringNum != 14) { section_error("14 strings needed"); return; } local = malloc(sizeof(objectMatrix_section)); memset(local, 0, sizeof(objectMatrix_section)); local->myParticleSystem = particles_init(local->myParticleSystem); mySection->vars = (void *) local; // load the object that will server as sources local->object = model_load(mySection->strings[0], USE_CACHE); if (!local->object) { section_error("objectMatrix: Error loading object sources: %s", mySection->strings[0]); return; } // load the object that will server as particle (and the shader) local->obj_part = model_load(mySection->strings[2], USE_CACHE); if (!local->object) { section_error("objectMatrix: Error loading particle object: %s", mySection->strings[1]); return; } if (model_upload_tex(local->obj_part, mySection->strings[1]) == -1) return; // load layers for drawing the object local->layers = layers_load(mySection->strings[3]); if (mySection->param[0] > 0) { local->myParticleSystem->disableDepthTest = 1; } else { local->myParticleSystem->disableDepthTest = 0; } // Equation defining the rate at which the particles are created (particles created per second) local->myParticleSystem->rate.equation = mySection->strings[4]; // We only take into account the first mesh as particle sources mesh = &local->object->meshobjlist[0]; // Get and store the particle source positions local->myParticleSystem->sourcesCount = mesh->verts; local->myParticleSystem->sources = (tVector *) malloc(sizeof(tVector) * mesh->verts); local->myParticleSystem->sourcesColor = (tColor *) malloc(sizeof(tColor ) * mesh->verts); for (i=0; i<local->myParticleSystem->sourcesCount; i++) { local->myParticleSystem->sources[i].x = mesh->vertlist[i].x; local->myParticleSystem->sources[i].y = mesh->vertlist[i].y; local->myParticleSystem->sources[i].z = mesh->vertlist[i].z; local->myParticleSystem->sourcesColor[i].r = 1.0; local->myParticleSystem->sourcesColor[i].g = 1.0; local->myParticleSystem->sourcesColor[i].b = 1.0; } // Particle evaluator equationSize = strlen(mySection->strings[5]); equationSize += strlen(mySection->strings[6]); equationSize += strlen(mySection->strings[7]); equationSize += strlen(mySection->strings[8]); equationSize += strlen(mySection->strings[9]); equationSize += strlen(mySection->strings[10]); evalEquation = calloc(equationSize+1, sizeof(char)); strcat(evalEquation, (char *) mySection->strings[5]); strcat(evalEquation, (char *) mySection->strings[6]); strcat(evalEquation, (char *) mySection->strings[7]); strcat(evalEquation, (char *) mySection->strings[8]); strcat(evalEquation, (char *) mySection->strings[9]); strcat(evalEquation, (char *) mySection->strings[10]); local->myParticleSystem->Evaluator.equation = evalEquation; // Sources evaluator equationSize = strlen(mySection->strings[11]); equationSize += strlen(mySection->strings[12]); equationSize += strlen(mySection->strings[13]); evalSources = calloc(equationSize+1, sizeof(char)); strcpy(evalSources, (char *) mySection->strings[11]); //-V525 strcat(evalSources, (char *) mySection->strings[12]); strcat(evalSources, (char *) mySection->strings[13]); local->myParticleSystem->Sources.equation = evalSources; // Init the expression evaluation library initExpression(&local->myParticleSystem->Sources); initExpression(&local->myParticleSystem->Evaluator); initExpression(&local->myParticleSystem->rate); mySection->loaded=1; }