Texture.cpp 963 B

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