BsGLTextureView.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsGLTextureView.h"
  4. #include "BsGLTexture.h"
  5. namespace bs { namespace ct {
  6. GLTextureView::GLTextureView(const GLTexture* texture, const TEXTURE_VIEW_DESC& desc)
  7. :TextureView(desc), mViewID(0)
  8. {
  9. const TextureProperties& props = texture->getProperties();
  10. GLuint originalTexture = texture->getGLID();
  11. GLenum target;
  12. switch (props.getTextureType())
  13. {
  14. case TEX_TYPE_1D:
  15. {
  16. if (desc.numArraySlices <= 1)
  17. target = GL_TEXTURE_1D;
  18. else
  19. target = GL_TEXTURE_1D_ARRAY;
  20. }
  21. break;
  22. default:
  23. case TEX_TYPE_2D:
  24. {
  25. if(props.getNumSamples() <= 1)
  26. {
  27. if (desc.numArraySlices <= 1)
  28. target = GL_TEXTURE_2D;
  29. else
  30. target = GL_TEXTURE_2D_ARRAY;
  31. }
  32. else
  33. {
  34. if (desc.numArraySlices <= 1)
  35. target = GL_TEXTURE_2D_MULTISAMPLE;
  36. else
  37. target = GL_TEXTURE_2D_MULTISAMPLE_ARRAY;
  38. }
  39. }
  40. break;
  41. case TEX_TYPE_3D:
  42. target = GL_TEXTURE_3D;
  43. break;
  44. case TEX_TYPE_CUBE_MAP:
  45. {
  46. if(desc.numArraySlices % 6 == 0)
  47. {
  48. if (desc.numArraySlices == 6)
  49. target = GL_TEXTURE_CUBE_MAP;
  50. else
  51. target = GL_TEXTURE_CUBE_MAP_ARRAY;
  52. }
  53. else
  54. {
  55. if(desc.numArraySlices == 1)
  56. target = GL_TEXTURE_2D;
  57. else
  58. target = GL_TEXTURE_2D_ARRAY;
  59. }
  60. }
  61. break;
  62. }
  63. glGenTextures(1, &mViewID);
  64. glTextureView(mViewID, target, originalTexture, texture->getGLFormat(), desc.mostDetailMip, desc.numMips,
  65. desc.firstArraySlice, desc.numArraySlices);
  66. mTarget = GLTexture::getGLTextureTarget(props.getTextureType(), props.getNumSamples(), desc.numArraySlices);
  67. }
  68. GLTextureView::~GLTextureView()
  69. {
  70. glDeleteTextures(1, &mViewID);
  71. }
  72. }}