A 2D tile-based sandbox game.
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.

GlProgram.h 696B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #pragma once
  2. #include <vector>
  3. #include <initializer_list>
  4. #include <functional>
  5. #include <SDL_opengles2.h>
  6. #include "util.h"
  7. namespace Cygnet {
  8. class GlShader: NonCopyable {
  9. public:
  10. enum class Type {
  11. VERTEX,
  12. FRAGMENT,
  13. };
  14. GlShader(const char *source, Type type);
  15. ~GlShader();
  16. GLuint id() { return id_; }
  17. private:
  18. GLuint id_;
  19. bool valid_ = false;
  20. };
  21. class GlProgram: NonCopyable {
  22. public:
  23. GlProgram(std::initializer_list<std::reference_wrapper<GlShader>> shaders);
  24. ~GlProgram();
  25. void use() { glUseProgram(id_); }
  26. GLuint id() { return id_; }
  27. GLuint getLocation(const char *name) { return glGetAttribLocation(id_, name); }
  28. private:
  29. GLuint id_;
  30. bool valid_ = false;
  31. };
  32. }