Framebuffer.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #ifndef FRAMEBUFFER_H
  2. #define FRAMEBUFFER_H
  3. #include <GL/glew.h>
  4. #include "gaming-core/utils/Size.h"
  5. #include "gaming-core/utils/Array.h"
  6. class Framebuffer final {
  7. public:
  8. static const int POSITION = 1;
  9. static const int NORMAL = 2;
  10. static const int COLOR = 4;
  11. static const int RED = 8;
  12. static const int DEPTH = 16;
  13. Framebuffer(const Size& size, int mode, bool texCompare = false);
  14. ~Framebuffer();
  15. Framebuffer(const Framebuffer& other) = delete;
  16. Framebuffer(Framebuffer&& other) = delete;
  17. Framebuffer& operator=(const Framebuffer& other) = delete;
  18. Framebuffer& operator=(Framebuffer&& other) = delete;
  19. bool hasError() const;
  20. void bind() const;
  21. void resize(int width, int height) const;
  22. void bindPositionTexture(int textureUnit) const;
  23. void bindNormalTexture(int textureUnit) const;
  24. void bindColorTexture(int textureUnit) const;
  25. void bindRedTexture(int textureUnit) const;
  26. void bindDepthTexture(int textureUnit) const;
  27. private:
  28. void genTexture(int index, int width, int height);
  29. void setupTexture(int index, int width, int height, GLuint* attachments, int& counter);
  30. void bindTexture(int textureUnit, GLuint texture) const;
  31. const char* getErrorString(GLenum error) const;
  32. const Size& size;
  33. int mode;
  34. Array<GLuint, 5> textures;
  35. GLuint buffer;
  36. bool error;
  37. struct Data final {
  38. int mask;
  39. GLint internalFormat;
  40. GLenum format;
  41. GLenum type;
  42. };
  43. Data data[5];
  44. };
  45. #endif