BOOL CParamUtil::GetInitValue( izanagi::shader::S_SHD_PARAMETER& sDesc, CGparameter param) { IZ_UINT nElements = sDesc.Rows * sDesc.Columns; nElements = (sDesc.Elements > 0 ? nElements * sDesc.Elements : nElements); IZ_UINT nParamSize = sDesc.Bytes; CGtype type = _GetCGType(param); int nValueNum = 0; std::vector<IZ_UINT8> tvBuf(nParamSize); if (CShaderConvUtil::IsIntType(type)) { // int nValueNum = cgGetParameterValueir( param, nElements, (int*)&tvBuf[0]); } else if (CShaderConvUtil::IsFloatType(type)) { // float nValueNum = cgGetParameterValuefr( param, nElements, (float*)&tvBuf[0]); #if 0 for (int i = 0; i < nValueNum; i++) { float xx = *(float*)&tvBuf[i * 4]; printf("%f\n", xx); } #endif } else { VRETURN(IZ_FALSE); } BOOL ret = (nValueNum > 0); VRETURN(ret); if (ret) { sDesc.hasDefaultValue = IZ_TRUE; sDesc.Pos = CDataBuffer::GetInstance().Register( &tvBuf[0], tvBuf.size()); } return ret; }
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 }