Texture.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #include "client/rendering/wrapper/Texture.h"
  2. Texture::Texture(Mode mode) : texture(0) {
  3. glGenTextures(1, &texture);
  4. glBindTexture(GL_TEXTURE_2D, texture);
  5. switch(mode) {
  6. case NEAREST:
  7. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  8. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  9. break;
  10. case LINEAR:
  11. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  12. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  13. break;
  14. }
  15. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  16. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  17. }
  18. Texture::~Texture() {
  19. glDeleteTextures(1, &texture);
  20. }
  21. void Texture::setRGBAData(int width, int height, const u32* data) {
  22. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
  23. }
  24. void Texture::setRGBFloatData(int width, int height, const float* data) {
  25. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, width, height, 0, GL_RGB, GL_FLOAT, data);
  26. }
  27. void Texture::bind(uint index) const {
  28. glActiveTexture(GL_TEXTURE0 + index);
  29. glBindTexture(GL_TEXTURE_2D, texture);
  30. }