You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

glstate.cpp 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <vector>
  2. #include <utility>
  3. #include <iostream>
  4. #include "graphics/glstate.h"
  5. #include "graphics/shader.h"
  6. namespace vtk { namespace gls {
  7. static GLuint activeShader(0);
  8. static bool trackingEnabled(false);
  9. static std::vector<std::pair<GLenum, bool> > flags;
  10. int setShader(const GLuint& shaderID) {
  11. //check that the shader we want to set isn't already active
  12. if (activeShader == shaderID){ return 0; }
  13. //set the shader
  14. glUseProgram(shaderID);
  15. activeShader = shaderID;
  16. return 1;
  17. }
  18. void setTracking(const bool& flag) {
  19. trackingEnabled = flag;
  20. }
  21. void setFlag(const GLenum& flag, const bool& newState) {
  22. if (trackingEnabled) {
  23. //check if flag already === newState
  24. GLboolean state;
  25. glGetBooleanv(flag, &state);
  26. if ((bool)state != newState) {
  27. //set flag and push the new status into the flags list
  28. if (newState) glEnable(flag);
  29. else glDisable(flag);
  30. flags.push_back(std::make_pair(flag,newState));
  31. }
  32. } else {
  33. if (newState) glEnable(flag);
  34. else glDisable(flag);
  35. }
  36. }
  37. void restoreState() {
  38. if (flags.empty()) return;
  39. //iterate through flags and reset them
  40. for(auto& i : flags) {
  41. if(i.second) glDisable(i.first);
  42. else glEnable(i.first);
  43. }
  44. flags.clear();
  45. }
  46. }}