Example #1
0
void
ppline(int line, char* file)
{
	char*		s;
	static char	type[5];

	if (pp.flags & PP_lineignore)
	{
		pp.flags &= ~PP_lineignore;
		if (!(pp.flags & PP_linetype) || *pp.lineid)
		{
			ppline(1, file);
			file = error_info.file;
		}
		else
			type[1] = PP_sync_ignore;
	}
	else if (file != pp.lastfile)
	{
		if (!pp.firstfile)
			pp.firstfile = file;
		type[1] = ((pp.flags & PP_linetype) && !*pp.lineid && pp.lastfile) ? (line <= 1 ? (file == pp.firstfile ? PP_sync : PP_sync_push) : PP_sync_pop) : PP_sync;
		pp.lastfile = file;
	}
	else
	{
		if (!(pp.flags & PP_linefile))
			file = 0;
		type[1] = PP_sync;
	}
	if (!(pp.flags & PP_linetype) || *pp.lineid || type[1] == PP_sync)
		type[0] = 0;
	else
	{
		type[0] = ' ';
		if ((pp.flags & (PP_hosted|PP_linehosted)) == (PP_hosted|PP_linehosted))
		{
			type[2] = ' ';
			type[3] = PP_sync_hosted;
		}
		else
			type[2] = 0;
	}

	/*
	 * some front ends can't handle two line syncs in a row
	 */

	if (pp.pending == pppendout() || pplastout() != '\n')
		ppputchar('\n');
	if (file)
		ppprintf("#%s %d \"%s\"%s\n", pp.lineid, line, (pp.flags & PP_linebase) && (s = strrchr(file, '/')) ? s + 1 : file, type);
	else
		ppprintf("#%s %d\n", pp.lineid, line);
	if (!pp.macref)
		pp.pending = pppendout();
}
Example #2
0
//==============================================================================
GlProgramPipelineHandle Renderer::createDrawQuadProgramPipeline(
	GlProgramHandle frag)
{
	GlDevice& gl = GlDeviceSingleton::get();
	GlCommandBufferHandle jobs(&gl);

	Array<GlProgramHandle, 2> progs = {{m_drawQuadVert->getGlProgram(), frag}};

	GlProgramPipelineHandle ppline(jobs, &progs[0], &progs[0] + 2);
	jobs.finish();

	return ppline;
}
Example #3
0
// source is float
bool line_tree::variable_node_convert_float(VARIABLE_NODE ch, VARIABLE_TYPE target, VARIABLE_NODE *p_result)
{
  if(target == VARIABLE_INT) {
    p_result->type = VARIABLE_INT;
    p_result->vint = roundf(ch.vfloat);
    return(TRUE);
  }
  else {
    ppline();
    pperror(TRUE, "type mismatch - can't convert type %s to %s", 
                  variable_type_translate(ch.type),
                  variable_type_translate(target));
  }
  return(FALSE);
}
Example #4
0
VARIABLE_NODE line_tree::variable_node_sub(VARIABLE_NODE ch1, VARIABLE_NODE ch2)
{
  if(ch1.type == VARIABLE_FLOAT && ch2.type == VARIABLE_FLOAT) {
    return(variable_node_sub_float(ch1.vfloat, ch2.vfloat));
  }
  else if(ch1.type == VARIABLE_RGBAF && ch2.type == VARIABLE_RGBAF) {
    return(variable_node_sub_color(ch1.vcolor, ch2.vcolor));
  }
  else {
    ppline();
    pperror(TRUE, "type mismatch - can't substract types %s and %s", 
                  variable_type_translate(ch1.type),
                  variable_type_translate(ch2.type));
  }
}
Example #5
0
// source is int
bool line_tree::variable_node_convert_int(VARIABLE_NODE ch, VARIABLE_TYPE target, VARIABLE_NODE *p_result)
{
  if(target == VARIABLE_FLOAT) {
    p_result->type = VARIABLE_FLOAT;
    p_result->vfloat = (float)ch.vint;
    return(TRUE);
  }
  else if(target == VARIABLE_RGBAF) {
    p_result->type = VARIABLE_RGBAF;
    rgba_float(ch.vint, &p_result->vcolor.r, &p_result->vcolor.g,
               &p_result->vcolor.b, &p_result->vcolor.a);
    return(TRUE);
  }
  else {
    ppline();
    pperror(TRUE, "type mismatch - can't convert type %s to %s", 
                  variable_type_translate(ch.type),
                  variable_type_translate(target));
  }
  return(FALSE);
}
Example #6
0
bool line_tree::variable_node_convert(VARIABLE_NODE ch, VARIABLE_TYPE target, VARIABLE_NODE *p_result)
{
  if(ch.type == VARIABLE_FLOAT) {
    // convert from float
    return(variable_node_convert_float(ch, target, p_result));
  }
  else if(ch.type == VARIABLE_INT) {
    // convert from int
    return(variable_node_convert_int(ch, target, p_result));
  }
  else if(ch.type == VARIABLE_RGBAF) {
    // convert from color
    return(variable_node_convert_color(ch, target, p_result));
  }
  else {
    ppline();
    pperror(TRUE, "type mismatch - can't convert type %s to %s", 
                  variable_type_translate(ch.type),
                  variable_type_translate(target));
    return(FALSE);
  }
}
Example #7
0
VARIABLE_NODE line_tree::execute_leaf(PARAM_NODE_LEAF *p_leaf, PIXEL_PARAMS *p_params)
{
  VARIABLE_NODE ret;
  
  PARAM_NODE *p_node = &p_leaf->node;
  switch(p_node->content_type) {
    
    // Parameters from previous modificator
    case NODE_PARAM_PREV_0:
    case NODE_PARAM_PREV_1:
    case NODE_PARAM_PREV_2:
    case NODE_PARAM_PREV_3:
    case NODE_PARAM_PREV_4:
    case NODE_PARAM_PREV_5:
    case NODE_PARAM_PREV_6:
    case NODE_PARAM_PREV_7:
    case NODE_PARAM_PREV_8:
    case NODE_PARAM_PREV_9:
    {
      assert(p_params);
      MODIFICATOR_PARAMS *p_par = p_params->p_params;
      int parameter = p_node->content_type - NODE_PARAM_PREV_0;
      if(p_par->is_index(parameter)) {
        ret.type = VARIABLE_FLOAT;
        ret.vfloat = p_par->get(parameter);
      } 
      else {
        ppline();
        pperror(TRUE, "parametrizer::execute_leaf() - missing parameter %d", parameter);
        ret.type = VARIABLE_INT;
        ret.vint = FALSE;
      }
      break;
    }
    
    // random numbers
    case NODE_PARAM_RAND:
      ret.type = VARIABLE_FLOAT;
      ret.vfloat = random_generator::generator_rand_0();
      break;
    case NODE_PARAM_RAND_HALF:
      ret.type = VARIABLE_FLOAT;
      ret.vfloat = random_generator::generator_rand();
      break;
    case NODE_PARAM_GAUSS:
      ret.type = VARIABLE_FLOAT;
      ret.vfloat = random_generator::generator_gauss_0();
      break;
    case NODE_PARAM_GAUSS_HALF:
      ret.type = VARIABLE_FLOAT;
      ret.vfloat = fabs(random_generator::generator_gauss_0());
      break;
    
    case NODE_CONSTANT_INT:
      ret.type = VARIABLE_INT;
      ret.vint = p_node->cint;
      break;
    case NODE_CONSTANT_FLOAT:
      ret.type = VARIABLE_FLOAT;
      ret.vfloat = p_node->cfloat;
      break;
    case NODE_CONSTANT_RGBAF:
      ret.type = VARIABLE_RGBAF;
      ret.vcolor = p_node->ccolor;
      break;
    case NODE_CONSTANT_VECT3DF:
      ret.type = VARIABLE_VECT3DF;
      ret.vvector = p_node->cvector;
      break;
    case NODE_CONSTANT_RECT2DF:
      ret.type = VARIABLE_RECT2DI;
      ret.vrect = p_node->crect;
      break;

    case NODE_VAR_VARIABLE:
      ret = p_node->p_cvariable->value;
      break;
    
    case NODE_VAR_VARIABLE_R:
    case NODE_VAR_VARIABLE_G:
    case NODE_VAR_VARIABLE_B:
    case NODE_VAR_VARIABLE_A:
    {
      assert(p_node->p_cvariable->value.type == VARIABLE_RGBAF);
      ret.type = VARIABLE_FLOAT;
      ret.vfloat = variable_content_get(&p_node->p_cvariable->value, p_node->content_type);
      break;
    }     
    case NODE_VAR_VARIABLE_X:
    case NODE_VAR_VARIABLE_Y:
    case NODE_VAR_VARIABLE_Z:
    {
      assert(p_node->p_cvariable->value.type == VARIABLE_VECT3DF);
      ret.type = VARIABLE_FLOAT;
      ret.vfloat = variable_content_get(&p_node->p_cvariable->value, p_node->content_type);
      break;
    } 
    case NODE_VAR_VARIABLE_DX:
    case NODE_VAR_VARIABLE_DY:
    {
      ppline();
      pperror(TRUE, "Rectangles are not yet implemented.");
    }
    
    case NODE_OP_ADD:  // +
    {
      assert(p_leaf->p_child[0] && p_leaf->p_child[1]);
      VARIABLE_NODE ch1 = execute_leaf(p_leaf->p_child[0],p_params);
      VARIABLE_NODE ch2 = execute_leaf(p_leaf->p_child[1],p_params);
      ret = variable_node_add(ch1,ch2);
      break;
    }
    case NODE_OP_SUB:  // -
    {
      assert(p_leaf->p_child[0] && p_leaf->p_child[1]);
      VARIABLE_NODE ch1 = execute_leaf(p_leaf->p_child[0],p_params);
      VARIABLE_NODE ch2 = execute_leaf(p_leaf->p_child[1],p_params);
      ret = variable_node_sub(ch1,ch2);
      break;
    }
    case NODE_OP_MULT: // *
    {
      assert(p_leaf->p_child[0] && p_leaf->p_child[1]);
      VARIABLE_NODE ch1 = execute_leaf(p_leaf->p_child[0],p_params);
      VARIABLE_NODE ch2 = execute_leaf(p_leaf->p_child[1],p_params);
      ret = variable_node_mult(ch1,ch2);
      break;
    }
    case NODE_OP_DIV:  // /
    {
      assert(p_leaf->p_child[0] && p_leaf->p_child[1]);
      VARIABLE_NODE ch1 = execute_leaf(p_leaf->p_child[0],p_params);
      VARIABLE_NODE ch2 = execute_leaf(p_leaf->p_child[1],p_params);
      ret = variable_node_div(ch1,ch2);
      break;
    }
    case NODE_OP_EQ:  // =
    {
      assert(p_leaf->p_child[0] && p_leaf->p_child[1]);
      assert(p_leaf->p_child[0]->node.node_type == NODE_VARIABLE);
      
      PARAM_NODE *p_target_node = &p_leaf->p_child[0]->node;
      VARIABLE_NODE *p_target = &(p_target_node->p_cvariable->value);
      VARIABLE_NODE source = execute_leaf(p_leaf->p_child[1],p_params);

      // Set whole variable
      if(p_target_node->content_type == NODE_VAR_VARIABLE) {
        if(p_target->type == VARIABLE_UNSET || p_target->type == source.type) {
          *p_target = source;
        }
        else {
          bool ret = variable_node_convert(source, p_target->type, p_target);
          if(!ret) {
            ppline();
            pperror(TRUE, "Type mismatch: can't convert %s to %s",
                    variable_type_translate(source.type), 
                    variable_type_translate(p_target->type));
          }
        }
      }
      else if(p_target_node->content_type == NODE_VAR_VARIABLE_R ||
              p_target_node->content_type == NODE_VAR_VARIABLE_G ||
              p_target_node->content_type == NODE_VAR_VARIABLE_B ||
              p_target_node->content_type == NODE_VAR_VARIABLE_A)        
      {        
        VARIABLE_NODE target;
        if(source.type == VARIABLE_FLOAT) {
          target = source;
        }
        else {
          bool ret = variable_node_convert(source, VARIABLE_FLOAT, &target);
          if(!ret) {            
            ppline();
            pperror(TRUE, "Type mismatch: can't convert %s to %s",
                    variable_type_translate(source.type),
                    variable_type_translate(VARIABLE_FLOAT));
          }
        }
        target.type = VARIABLE_FLOAT;
        variable_content_set(p_target, p_target_node->content_type, target.vfloat);
      }
      else {
        ppline();
        pperror(TRUE, "Assignment target is not a variable!");
      }
      
      ret.type = VARIABLE_INT;
      ret.vint = TRUE;
      break;
    }
      
    case NODE_FUNC_SIN:   // sin()
    {
      assert(p_leaf->p_child[0]);
      ret = execute_leaf(p_leaf->p_child[0],p_params);
      if(ret.type != VARIABLE_FLOAT) {
        ppline();
        pperror(TRUE, "Type mismatch: sin() needs a parameter type FLOAT, not %s",
                variable_type_translate(ret.type));
      }
      ret.vfloat = sinf(ret.vfloat);
      break;
    }
    case NODE_FUNC_COS:   // cos()
    {
      assert(p_leaf->p_child[0]);
      ret = execute_leaf(p_leaf->p_child[0],p_params);
      if(ret.type != VARIABLE_FLOAT) {
        ppline();
        pperror(TRUE, "Type mismatch: cos() needs a parameter type FLOAT, not %s",
                variable_type_translate(ret.type));
      }
      ret.vfloat = cosf(ret.vfloat);
      break;
    }
    case NODE_FUNC_SQRT:  // sqrt()
    {
      assert(p_leaf->p_child[0]);
      ret = execute_leaf(p_leaf->p_child[0],p_params);
      if(ret.type != VARIABLE_FLOAT) {
        ppline();
        pperror(TRUE, "Type mismatch: sqrt() needs a parameter type FLOAT, not %s",
                variable_type_translate(ret.type));
      }
      ret.vfloat = sqrtf(ret.vfloat);
      break;
    }
    case NODE_FUNC_NORM:  // norm()
    {
      assert(p_leaf->p_child[0]);
      ret = execute_leaf(p_leaf->p_child[0],p_params);
      if(ret.type != VARIABLE_FLOAT) {
        ppline();
        pperror(TRUE, "Type mismatch: norm() needs a parameter type FLOAT, not %s",
                variable_type_translate(ret.type));
      }
      if(ret.vfloat > 1) {
        ret.vfloat = 1.0f;
      }
      else if(ret.vfloat < 0) {
        ret.vfloat = 0.0f;
      }      
      break;
    }
    case NODE_FUNC_ABS: // abs()
    {
      assert(p_leaf->p_child[0]);
      ret = execute_leaf(p_leaf->p_child[0],p_params);
      if(ret.type != VARIABLE_FLOAT) {
        ppline();
        pperror(TRUE, "Type mismatch: abs() needs a parameter type FLOAT, not %s",
                variable_type_translate(ret.type));
      }
      ret.vfloat = fabs(ret.vfloat);
      break;
    }
    case NODE_FUNC_RGB: // rgb()
    {
      assert(p_leaf->p_child[0]);
      ret = execute_leaf(p_leaf->p_child[0],p_params);
      if(ret.type != VARIABLE_FLOAT) {
        ppline();
        pperror(TRUE, "Type mismatch: rgb() needs a parameter type FLOAT, not %s",
                variable_type_translate(ret.type));
      }
      
      if(ret.vfloat < 0)
        ret.vfloat = 0;
      else if(ret.vfloat > 255)
        ret.vfloat = 1;
      else
        ret.vfloat = ret.vfloat/255;
      
      break;
    }    
    case NODE_FUNC_BLEND:  // blend()
    {
      assert(p_leaf->p_child[0]);
      assert(p_leaf->p_child[1]);
      assert(p_leaf->p_child[2]);
      VARIABLE_NODE ch1 = execute_leaf(p_leaf->p_child[0],p_params);
      VARIABLE_NODE ch2 = execute_leaf(p_leaf->p_child[1],p_params);
      VARIABLE_NODE ch3 = execute_leaf(p_leaf->p_child[2],p_params);
      
      if(ch1.type != VARIABLE_RGBAF ||
         ch2.type != VARIABLE_FLOAT ||
         ch3.type != VARIABLE_RGBAF)
      {      
        if(ret.type != VARIABLE_FLOAT) {
          ppline();
          pperror(TRUE, "Type mismatch: blend() takes types COLOR, FLOAT, COLOR, but it got %s %s %s",
                  variable_type_translate(ch1.type),
                  variable_type_translate(ch2.type),
                  variable_type_translate(ch3.type));
                  
        }      
      }
      
      float alpha_dest = ch2.vfloat;
      float alpha_src = 1.0f - ch2.vfloat;
      
      RGBAF dest(ch1.vcolor);
      RGBAF src(ch3.vcolor);
      
      ret.type = VARIABLE_RGBAF;
      ret.vcolor = dest*alpha_dest + src*alpha_src;
      break;
    }
    
    default:
      ret.type = VARIABLE_INT;
      ret.vint = FALSE;
      break;
  }
  
  return(ret);
}