Texture3D.cpp 923 B

1234567891011121314151617181920212223242526
  1. #include "Texture3D.h"
  2. Texture3D::Texture3D() : texture(0) {
  3. glGenTextures(1, &texture);
  4. glBindTexture(GL_TEXTURE_3D, texture);
  5. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  6. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  7. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
  8. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_MIRRORED_REPEAT);
  9. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
  10. }
  11. Texture3D::~Texture3D() {
  12. glDeleteTextures(1, &texture);
  13. }
  14. void Texture3D::setData(int width, int height, int depth, void* data) {
  15. glBindTexture(GL_TEXTURE_3D, texture);
  16. glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, width, height, depth, 0, GL_RGB,
  17. GL_FLOAT, data);
  18. }
  19. void Texture3D::bindTo(int unit) const {
  20. glActiveTexture(GL_TEXTURE0 + unit);
  21. glBindTexture(GL_TEXTURE_3D, texture);
  22. }