2
0

PolyGLSLProgram.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * PolyCGProgram.cpp
  3. * Poly
  4. *
  5. * Created by Ivan Safrin on 9/20/08.
  6. * Copyright 2008 __MyCompanyName__. All rights reserved.
  7. *
  8. */
  9. #include "PolyCGProgram.h"
  10. using namespace Polycode;
  11. CGProgram::CGProgram(int type) : Resource(Resource::RESOURCE_PROGRAM) {
  12. this->type = type;
  13. }
  14. CGProgram::~CGProgram() {
  15. }
  16. void CGProgram::addParam(string name, bool isAuto, int autoID, int paramType, void *defaultData) {
  17. CGProgramParam newParam;
  18. newParam.name = name;
  19. newParam.paramType = paramType;
  20. newParam.defaultData = defaultData;
  21. newParam.isAuto = isAuto;
  22. newParam.autoID = autoID;
  23. newParam.cgParam = cgGetNamedParameter(program, name.c_str());
  24. params.push_back(newParam);
  25. }
  26. void *CGProgramParam::createParamData(int *retType, string type, string value) {
  27. void *defaultData;
  28. if(type == "float") {
  29. *retType = CGProgramParam::PARAM_FLOAT;
  30. float *val = new float();
  31. *val = atof(value.c_str());
  32. defaultData = (void*)val;
  33. return defaultData;
  34. } else if(type == "float3") {
  35. *retType = CGProgramParam::PARAM_FLOAT3;
  36. Vector3 *val = new Vector3();
  37. defaultData = (void*)val;
  38. vector<string> values = StringUtil::split(value, " ");
  39. if(values.size() == 3) {
  40. val->set(atof(values[0].c_str()), atof(values[1].c_str()), atof(values[2].c_str()));
  41. } else {
  42. Logger::log("Error: A float3 must have 3 values (%d provided)!\n", values.size());
  43. }
  44. return defaultData;
  45. } else {
  46. *retType = CGProgramParam::PARAM_UNKNOWN;
  47. return NULL;
  48. }
  49. }