framebuffer.hpp 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #ifndef IS_FRAMEBUFFER_H_
  2. #define IS_FRAMEBUFFER_H_
  3. #include <GL/glew.h>
  4. #include <GL/gl.h>
  5. #include <glm/glm.hpp>
  6. #include <stdexcept>
  7. #include "x.hpp"
  8. #include "shader.hpp"
  9. #include "resource.hpp"
  10. namespace slop {
  11. class Framebuffer
  12. {
  13. public:
  14. enum buffers
  15. {
  16. color = 0x01,
  17. depth = 0x02,
  18. stencil = 0x04
  19. };
  20. Framebuffer();
  21. Framebuffer( unsigned int width, unsigned int height, unsigned char flags = color, std::string shader = "simple" );
  22. ~Framebuffer();
  23. void create( unsigned int width, unsigned int height, unsigned char flags = color, std::string shader = "simple" );
  24. void createFromTexture( unsigned int texture, std::string shader = "simple" );
  25. void setShader( std::string shader = "simple" );
  26. void clear( glm::vec4 color = glm::vec4( 0, 0, 0, 1 ), unsigned char flags = color | depth | stencil );
  27. void bind();
  28. void unbind();
  29. void draw( float time, unsigned int image );
  30. unsigned int m_texture;
  31. unsigned int m_depth;
  32. unsigned int m_stencil;
  33. slop::Shader* m_shader;
  34. private:
  35. unsigned int m_width;
  36. unsigned int m_height;
  37. void check();
  38. void generateBuffers();
  39. unsigned char m_flags;
  40. bool generatedBuffers;
  41. unsigned int m_frame;
  42. unsigned int m_buffers[2];
  43. };
  44. }
  45. #endif //IS_FRAMEBUFFER_H_