Texture.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef TEXTURE_H
  2. #define TEXTURE_H
  3. #include <GL/glew.h>
  4. #include "utils/Color.h"
  5. class Texture final {
  6. GLuint texture;
  7. public:
  8. enum Mode {
  9. NEAREST, LINEAR
  10. };
  11. Texture(Mode mode = NEAREST);
  12. ~Texture();
  13. Texture(const Texture& other) = delete;
  14. Texture(Texture&& other) = delete;
  15. Texture& operator=(const Texture& other) = delete;
  16. Texture& operator=(Texture&& other) = delete;
  17. void setColorData(int width, int height, const Color4* data);
  18. void setColorData(int width, int height, const Color3* data);
  19. void setColorData(int width, int height, const Color2* data);
  20. void setColorData(int width, int height, const Color1* data);
  21. void setRGBFloatData(int width, int height, const float* data);
  22. void bind(int index = 0) const;
  23. private:
  24. template<int N>
  25. void setColorData(int width, int height, int mode, const Color<N>* data) {
  26. glBindTexture(GL_TEXTURE_2D, texture);
  27. glTexImage2D(GL_TEXTURE_2D, 0, mode, width, height, 0, mode, GL_UNSIGNED_BYTE, data);
  28. }
  29. };
  30. #endif