BsGLTextureView.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. GLenum target;
  11. switch (props.getTextureType())
  12. {
  13. case TEX_TYPE_1D:
  14. {
  15. if (desc.numArraySlices <= 1)
  16. target = GL_TEXTURE_1D;
  17. else
  18. target = GL_TEXTURE_1D_ARRAY;
  19. }
  20. break;
  21. default:
  22. case TEX_TYPE_2D:
  23. {
  24. if(props.getNumSamples() <= 1)
  25. {
  26. if (desc.numArraySlices <= 1)
  27. target = GL_TEXTURE_2D;
  28. else
  29. target = GL_TEXTURE_2D_ARRAY;
  30. }
  31. else
  32. {
  33. if (desc.numArraySlices <= 1)
  34. target = GL_TEXTURE_2D_MULTISAMPLE;
  35. else
  36. target = GL_TEXTURE_2D_MULTISAMPLE_ARRAY;
  37. }
  38. }
  39. break;
  40. case TEX_TYPE_3D:
  41. target = GL_TEXTURE_3D;
  42. break;
  43. case TEX_TYPE_CUBE_MAP:
  44. {
  45. if(desc.numArraySlices % 6 == 0)
  46. {
  47. if (desc.numArraySlices == 6)
  48. target = GL_TEXTURE_CUBE_MAP;
  49. else
  50. target = GL_TEXTURE_CUBE_MAP_ARRAY;
  51. }
  52. else
  53. {
  54. if(desc.numArraySlices == 1)
  55. target = GL_TEXTURE_2D;
  56. else
  57. target = GL_TEXTURE_2D_ARRAY;
  58. }
  59. }
  60. break;
  61. }
  62. #if BS_OPENGL_4_3 || BS_OPENGLES_3_1
  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. #endif
  76. mTarget = GLTexture::getGLTextureTarget(props.getTextureType(), props.getNumSamples(), desc.numArraySlices);
  77. }
  78. GLTextureView::~GLTextureView()
  79. {
  80. if(mViewID != 0)
  81. {
  82. glDeleteTextures(1, &mViewID);
  83. BS_CHECK_GL_ERROR();
  84. }
  85. }
  86. }}