PageRenderTime 60ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/src/nodes/offscreen/Bind.cpp

https://github.com/adbrown85/glxml-old
C++ | 98 lines | 58 code | 18 blank | 22 comment | 10 complexity | b687838a1f07a87a81aeeea734f7da17 MD5 | raw file
  1. /*
  2. * Bind.cpp
  3. *
  4. * Author
  5. * Andrew Brown <adb1413@rit.edu>
  6. */
  7. #include "Bind.hpp"
  8. /** Initializes the @e name and @e to attributes. */
  9. Bind::Bind(const Tag &tag) : Node(tag) {
  10. tag.get("name", name, true, false);
  11. tag.get("to", to, true, false);
  12. }
  13. /** Adds attachment to outputs and sets its index in outputs to program value.
  14. *
  15. * @throw NodeException if maximum number of outputs exceeded.
  16. */
  17. void Bind::associate() {
  18. // Find required nodes
  19. findAttachment();
  20. findOutputs();
  21. findProgram();
  22. // Add attachment
  23. index = outputs->addAttachment(attachment);
  24. if (index == -1) {
  25. NodeException e(tag);
  26. e << "[Bind] Maximum number of outputs exceeded.";
  27. throw e;
  28. }
  29. // Set location
  30. glBindFragDataLocationGAN(program->getHandle(), index, name.c_str());
  31. }
  32. /** Checks that the variable's value was set successfully.
  33. *
  34. * @throw NodeException if the value in the program does not match.
  35. */
  36. void Bind::finalize() {
  37. GLint location;
  38. location = glGetFragDataLocationGAN(program->getHandle(), name.c_str());
  39. if (location != index) {
  40. NodeException e(tag);
  41. e << "[Bind] Variable was not bound correctly.";
  42. throw e;
  43. }
  44. }
  45. /** @throw NodeException if Attachment named @e to could not be found. */
  46. void Bind::findAttachment() {
  47. attachment = Attachment::find(this, to);
  48. if (attachment == NULL) {
  49. NodeException e(tag);
  50. e << "[Bind] Could not find attachment with name '" << to << "'.";
  51. throw e;
  52. }
  53. }
  54. /** @throw NodeException if could not find Outputs list. */
  55. void Bind::findOutputs() {
  56. outputs = Scout<Outputs>::locate(getParent());
  57. if (outputs == NULL) {
  58. NodeException e(tag);
  59. e << "[Bind] Could not find outputs.";
  60. throw e;
  61. }
  62. }
  63. /** @throw NodeException if could not find Program. */
  64. void Bind::findProgram() {
  65. program = Scout<Program>::locate(getParent());
  66. if (program == NULL) {
  67. NodeException e(tag);
  68. e << "[Bind] Could not find program.";
  69. throw e;
  70. }
  71. }
  72. /** @return String comprised of the object's attributes. */
  73. string Bind::toString() const {
  74. ostringstream stream;
  75. stream << Node::toString();
  76. stream << " name='" << name << "'"
  77. << " to='" << to << "'"
  78. << " index='" << index << "'";
  79. return stream.str();
  80. }