int     main(int ac, char **argv, char **env)
{
        if (ac < 2)
        {
                printf("Usage: %s EXPR\n", argv[0]);
                printf("we using env for value mapping\n");
                exit(-42);
        }
        map_t   mapping = createMap(env);
        int     res = 0;
        if (exprEval(&argv[1], mapping, &res))
        {       printf("%d\n", res);}
}
Beispiel #2
0
void render_glslshaderbind()
	{
	varFloat*		vfloat;
	varVec2*		vec2;
	varVec3*		vec3;
	varVec4*		vec4;
	varSampler2D*	sampler2D;
	int				i;
	double			d;
	
	local = (glslshaderbind_section*) mySection->vars;

	// Choose the proper program shader
	glslshad_bind(local->program);
	
	for (i = 0; i < local->vfloat_num; i++)
		if (local->vfloat[i].loc>-1) {
			vfloat = &(local->vfloat[i]);
			insertSectionVariables(&vfloat->eva);
			vfloat->eva.err = exprEval(vfloat->eva.o, &vfloat->eva.result);	// Evaluate the equations
			// Check for errors
			if(vfloat->eva.err != EXPR_ERROR_NOERROR) section_error("glslshaderbind: [vfloat] Expression evaluation Error (%d): %s", vfloat->eva.err, vfloat->eva.equation);
			// Retrieve the values and assign them
			exprValListGet(vfloat->eva.v, "v1", &vfloat->value);
			glUniform1f(vfloat->loc, (float)vfloat->value);
		}

	for (i = 0; i < local->vec2_num; i++)
		if (local->vec2[i].loc>-1) {
			vec2 = &(local->vec2[i]);
			insertSectionVariables(&vec2->eva);
			vec2->eva.err = exprEval(vec2->eva.o, &vec2->eva.result);		// Evaluate the equations
			// Check for errors
			if(vec2->eva.err != EXPR_ERROR_NOERROR) section_error("glslshaderbind: [vec2] Expression evaluation Error (%d): %s", vec2->eva.err, vec2->eva.equation);
			// Retrieve the values and assign them
			exprValListGet(vec2->eva.v, "v1", &d); vec2->value[0] = (float)d;
			exprValListGet(vec2->eva.v, "v2", &d); vec2->value[1] = (float)d;
			glUniform2fv(vec2->loc, 1, (GLfloat*)vec2->value);
		}
	
	for (i = 0; i < local->vec3_num; i++)
		if (local->vec3[i].loc>-1) {
			vec3 = &(local->vec3[i]);
			insertSectionVariables(&vec3->eva);
			vec3->eva.err = exprEval(vec3->eva.o, &vec3->eva.result);		// Evaluate the equations
			// Check for errors
			if(vec3->eva.err != EXPR_ERROR_NOERROR) section_error("glslshaderbind: [vec3] Expression evaluation Error (%d): %s", vec3->eva.err, vec3->eva.equation);
			// Retrieve the values and assign them
			exprValListGet(vec3->eva.v, "v1", &d); vec3->value[0] = (float)d;
			exprValListGet(vec3->eva.v, "v2", &d); vec3->value[1] = (float)d;
			exprValListGet(vec3->eva.v, "v3", &d); vec3->value[2] = (float)d;
			glUniform3fv(vec3->loc, 1, (GLfloat*)vec3->value);
		}

	for (i = 0; i < local->vec4_num; i++)
		if (local->vec4[i].loc>-1) {
			vec4 = &(local->vec4[i]);
			insertSectionVariables(&vec4->eva);
			vec4->eva.err = exprEval(vec4->eva.o, &vec4->eva.result);		// Evaluate the equations
			// Check for errors
			if(vec4->eva.err != EXPR_ERROR_NOERROR) section_error("glslshaderbind: [vec4] Expression evaluation Error (%d): %s", vec4->eva.err, vec4->eva.equation);
			// Retrieve the values and assign them
			exprValListGet(vec4->eva.v, "v1", &d); vec4->value[0] = (float)d;
			exprValListGet(vec4->eva.v, "v2", &d); vec4->value[1] = (float)d;
			exprValListGet(vec4->eva.v, "v3", &d); vec4->value[2] = (float)d;
			exprValListGet(vec4->eva.v, "v4", &d); vec4->value[3] = (float)d;
			glUniform4fv(vec4->loc, 1, (GLfloat*)vec4->value);
		}

	for (i = local->sampler2D_num-1; i>=0; i--)
	//for (i = 0; i<local->sampler2D_num; i++)
		if (local->sampler2D[i].loc>-1) {
			sampler2D = &(local->sampler2D[i]);
			glActiveTexture (GL_TEXTURE0 + i);
			glBindTexture(GL_TEXTURE_2D, sampler2D->texGLid);			
		}
	for (i = 0; i < local->matrix4x4_num; ++i)
		if (local->matrix4x4[i].m_ShaderUniformID>-1) {
			// cal->matrix4x4[i].m_ShaderUniformID -> Shader Uniform Variable ID
			// 16 ->  4x4 floats, 16 elements
			// 0 -> do not transpose
			// request to the engine the matrix value and pass it to the shader
			glUniformMatrix4fv(local->matrix4x4[i].m_ShaderUniformID, 16, 0, (GLfloat*)get_sve_variable_matrix_4x4f(local->matrix4x4[i].m_SVEVariableID));
		}
}