BsGLTextureView.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. BS_CHECK_GL_ERROR();
  65. glTextureView(
  66. mViewID,
  67. target,
  68. originalTexture,
  69. texture->getGLFormat(),
  70. desc.mostDetailMip,
  71. desc.numMips,
  72. desc.firstArraySlice,
  73. desc.numArraySlices);
  74. BS_CHECK_GL_ERROR();
  75. mTarget = GLTexture::getGLTextureTarget(props.getTextureType(), props.getNumSamples(), desc.numArraySlices);
  76. }
  77. GLTextureView::~GLTextureView()
  78. {
  79. glDeleteTextures(1, &mViewID);
  80. BS_CHECK_GL_ERROR();
  81. }
  82. }}