예제 #1
0
void csShaderGLCGCommon::DebugDumpParam (csString& output, CGparameter param)
{
  output << "Parameter: " << cgGetParameterName (param) << "\n";
  output << " Type: " << 
    cgGetTypeString (cgGetParameterNamedType (param)) << "\n";
  output << " Direction: " <<
    cgGetEnumString (cgGetParameterDirection (param)) << "\n";
  output << " Semantic: " << cgGetParameterSemantic (param) << "\n";
  const CGenum var = cgGetParameterVariability (param);
  output << " Variability: " << cgGetEnumString (var) << "\n";
  output << " Resource: " <<
    cgGetResourceString (cgGetParameterResource (param)) << "\n";
  output << " Resource index: " <<
    cgGetParameterResourceIndex (param) << "\n";
  // Cg 2.0 seems to not like CG_DEFAULT for uniforms
  if (/*(var == CG_UNIFORM) || */(var == CG_CONSTANT))
  {
    int nValues;
    const double* values = cgGetParameterValues (param, 
      (var == CG_UNIFORM) ? CG_DEFAULT : CG_CONSTANT, &nValues);
    if (nValues != 0)
    {
      output << " Values:";
      for (int v = 0; v < nValues; v++)
      {
	output << ' ' << values[v];
      }
      output << "\n";
    }
  }
  if (!cgIsParameterUsed (param, program)) output << "  not used\n";
  if (!cgIsParameterReferenced (param)) output << "  not referenced\n";
}
예제 #2
0
cgfxRCPtr<cgfxVertexAttribute> cgfxVaryingParameter::setupAttribute(
    MString name, 
    const MString& semantic, 
    CGparameter parameter, 
    cgfxRCPtr<cgfxVertexAttribute>& vertexAttributes
)
{
	// Does a varying parameter of this name already exist?
	cgfxRCPtr<cgfxVertexAttribute>* attribute = &vertexAttributes;
	while( attribute->isNull() == false )
	{
		if( (*attribute)->fName == name)
		{
			return *attribute;
		}
		attribute = &(*attribute)->fNext;
	}

	// Add a new input for this parameter
	cgfxRCPtr<cgfxVertexAttribute> attr = cgfxRCPtr<cgfxVertexAttribute>(new cgfxVertexAttribute());
	*attribute = attr;

	// Setup the varying parameter description
	attr->fName = name;
	attr->fType = cgGetTypeString( cgGetParameterType( parameter));
	attr->fSemantic = semantic;
	return attr;
}
예제 #3
0
static void AddParameter(JSON &json, CGparameter param)
{
    const char * const parameterName = cgGetParameterName(param);

    if (sVerbose)
    {
        puts(parameterName);
    }

    json.AddObject(parameterName);

    const CGtype type = cgGetParameterType(param);
    const CGtype baseType = cgGetParameterBaseType(param);
    int numRows = cgGetParameterRows(param);
    const int numColumns = cgGetParameterColumns(param);
    if (CG_ARRAY == type)
    {
        const int totalArraySize = cgGetArrayTotalSize(param);
        numRows *= totalArraySize;
    }
    json.AddString("type", cgGetTypeString(baseType));
    if (1 < numRows)
    {
        json.AddValue("rows", numRows);
    }
    if (1 < numColumns)
    {
        json.AddValue("columns", numColumns);
    }

    const int maxNumElements = (numColumns * numRows);
    int n;
    if (CG_FLOAT == baseType)
    {
        float * const values = (float *)malloc(maxNumElements * sizeof(float));
        const int numValues = cgGetParameterValuefr(param, maxNumElements, values);
        if (numValues)
        {
            for (n = 0; n < numValues; n++)
            {
                if (values[n] != 0.0f)
                {
                    break;
                }
            }
            if (n < numValues)
            {
                json.AddArray("values", true);
                json.BeginData(true);
                for (n = 0; n < numValues; n++)
                {
                    json.AddData(values[n]);
                }
                json.EndData();
                json.CloseArray(true);
            }
        }
        free(values);
    }
    else if (CG_INT == baseType)
    {
        int * const values = (int *)malloc(maxNumElements * sizeof(int));
        const int numValues = cgGetParameterValueir(param, maxNumElements, values);
        if (numValues)
        {
            for (n = 0; n < numValues; n++)
            {
                if (values[n])
                {
                    break;
                }
            }
            if (n < numValues)
            {
                json.AddArray("values", true);
                json.BeginData(true);
                for (n = 0; n < numValues; n++)
                {
                    json.AddData(values[n]);
                }
                json.EndData();
                json.CloseArray(true);
            }
        }
        free(values);
    }
    else if (CG_BOOL == baseType)
    {
        int * const values = (int *)malloc(maxNumElements * sizeof(int));
        const int numValues = cgGetParameterValueir(param, maxNumElements, values);
        if (numValues)
        {
            for (n = 0; n < numValues; n++)
            {
                if (values[n])
                {
                    break;
                }
            }
            if (n < numValues)
            {
                json.AddArray("values", true);
                json.BeginData(true);
                for (n = 0; n < numValues; n++)
                {
                    json.AddData(values[n]);
                }
                json.EndData();
                json.CloseArray(true);
            }
        }
        free(values);
    }

    json.CloseObject(); // parameter
}
예제 #4
0
static bool AddState(JSON &json, CGstateassignment sa)
{
    const CGstate state = cgGetStateAssignmentState(sa);
    const char * const stateName = cgGetStateName(state);
    if (false == IsValidState(stateName))
    {
        ErrorMessage("Invalid state for OpenGL ES 2.0 %s", stateName);
        return false;
    }

    const CGtype type = cgGetStateType(state);
    int nValues;
    switch (type)
    {
    case CG_PROGRAM_TYPE:
        return true;

    case CG_FLOAT:
    case CG_FLOAT1:
        {
            const float * const fvalues = cgGetFloatStateAssignmentValues(sa, &nValues);
            json.AddValue(stateName, fvalues[0]);
        }
        break;

    case CG_FLOAT2:
    case CG_FLOAT3:
    case CG_FLOAT4:
        {
            const float * const fvalues = cgGetFloatStateAssignmentValues(sa, &nValues);
            json.AddArray(stateName, true);
            json.BeginData(true);
            for (int n = 0; n < nValues; ++n)
            {
                json.AddData(fvalues[n]);
            }
            json.EndData();
            json.CloseArray(true);
        }
        break;

    case CG_INT:
    case CG_INT1:
        {
            const int * const ivalues = cgGetIntStateAssignmentValues(sa, &nValues);
            json.AddValue(stateName, ivalues[0]);
        }
        break;

    case CG_INT2:
    case CG_INT3:
    case CG_INT4:
        {
            const int * const ivalues = cgGetIntStateAssignmentValues(sa, &nValues);
            json.AddArray(stateName, true);
            json.BeginData(true);
            for (int n = 0; n < nValues; ++n)
            {
                json.AddData(ivalues[n]);
            }
            json.EndData();
            json.CloseArray(true);
        }
        break;

    case CG_BOOL:
    case CG_BOOL1:
        {
            const CGbool * const bvalues = cgGetBoolStateAssignmentValues(sa, &nValues);
            json.AddBoolean(stateName, (bvalues[0] ? true : false));
        }
        break;

    case CG_BOOL2:
    case CG_BOOL3:
    case CG_BOOL4:
        {
            const CGbool * const bvalues = cgGetBoolStateAssignmentValues(sa, &nValues);
            json.AddArray(stateName, true);
            json.BeginData(true);
            for (int n = 0; n < nValues; ++n)
            {
                json.AddData(bvalues[n]);
            }
            json.EndData();
            json.CloseArray(true);
        }
        break;

    case CG_STRING:
        json.AddString(stateName, cgGetStringStateAssignmentValue(sa));
        break;

    default:
        ErrorMessage("UNEXPECTED State Assignment Type: %s 0x%x (%d)\n",
                        cgGetTypeString(type), type, type);
        return false;
    }
    return true;
}
예제 #5
0
void csShaderGLCGCommon::DoDebugDump ()
{
  csString output;
  DumpProgramInfo (output);
  output << "CG program type: " << programType << "\n";
  output << "CG profile: " << cgGetProgramString (program, 
    CG_PROGRAM_PROFILE) << "\n";
  output << "CG entry point: " << (entrypoint ? entrypoint : "main") << 
    "\n";
  output << "CG program valid: " << IsValid() << "\n";
  output << "\n";

  output << "Variable mappings:\n";
  for (size_t v = 0; v < variablemap.GetSize (); v++)
  {
    const VariableMapEntry& vme = variablemap[v];
    ShaderParameter* sparam =
      reinterpret_cast<ShaderParameter*> (vme.userVal);

    output << stringsSvName->Request (vme.name);
    output << '(' << vme.name << ") -> ";
    output << vme.destination << ' ';
    if (sparam == 0)
    {
      output << "(null)";
    }
    else
    {
      if (sparam->paramType != 0) output << cgGetTypeString (sparam->paramType) << ' ';
      if (sparam->param != 0) output << cgGetParameterName (sparam->param) << "  ";
      output << "baseslot " << sparam->baseSlot;
      if (sparam->assumeConstant) output << "  assumed constant";
    }
    output << '\n'; 
  }
  output << "\n";

  output << "Program leaf parameters:\n";
  CGparameter param = cgGetFirstLeafParameter (program, CG_PROGRAM);
  while (param)
  {
    DebugDumpParam (output, param);
    param = cgGetNextLeafParameter (param);
  }
  output << "\n";

  output << "Program global parameters:\n";
  param = cgGetFirstLeafParameter (program, CG_GLOBAL);
  while (param)
  {
    DebugDumpParam (output, param);
    param = cgGetNextLeafParameter (param);
  }
  output << "\n";

  output << "Program source:\n";
  output << cgGetProgramString (program, CG_PROGRAM_SOURCE);
  output << "\n";

  output << "Compiled program:\n";
  output << cgGetProgramString (program, CG_COMPILED_PROGRAM);
  output << "\n";

  csRef<iVFS> vfs = csQueryRegistry<iVFS> (objectReg);
  EnsureDumpFile();

  csRef<iFile> debugFile = vfs->Open (debugFN, VFS_FILE_APPEND);
  if (!debugFile)
  {
    csReport (objectReg, CS_REPORTER_SEVERITY_WARNING, 
      "crystalspace.graphics3d.shader.glcg",
      "Could not write %s", CS::Quote::Single (debugFN.GetData()));
  }
  else
  {
    debugFile->Write (output.GetData(), output.Length ());
    csReport (objectReg, CS_REPORTER_SEVERITY_NOTIFY, 
      "crystalspace.graphics3d.shader.glcg",
      "Dumped Cg program info to %s", CS::Quote::Single (debugFN.GetData()));
  }
}