texture.d 916 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Written in the D programming language.
  2. /**
  3. Copyright: Copyright Felix 'Zoadian' Hufnagel 2014-.
  4. License: $(WEB http://www.gnu.org/licenses/lgpl.html, LGPLv3).
  5. Authors: $(WEB zoadian.de, Felix 'Zoadian' Hufnagel)
  6. */
  7. module aurora.gl.texture;
  8. import derelict.opengl3.gl3;
  9. import aurora.gl.util;
  10. //==============================================================================
  11. ///
  12. final class Texture {
  13. private:
  14. uint _id;
  15. public:
  16. ///
  17. this() {
  18. check!glGenTextures(1, &this._id);
  19. }
  20. ///
  21. ~this() {
  22. check!glDeleteTextures(1, &this._id);
  23. }
  24. public:
  25. ///
  26. void activate(uint location) {
  27. check!glActiveTexture(GL_TEXTURE0 + location);
  28. }
  29. ///
  30. void bind() {
  31. check!glBindTexture(GL_TEXTURE_2D, this._id);
  32. }
  33. ///
  34. static void unbind() {
  35. check!glBindTexture(GL_TEXTURE_2D, 0);
  36. }
  37. public:
  38. ///
  39. @property bool isValid() const @safe nothrow {
  40. return (this._id > 0);
  41. }
  42. }