BsGLTextureView.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. GLuint originalTexture = texture->getGLID();
  64. glGenTextures(1, &mViewID);
  65. BS_CHECK_GL_ERROR();
  66. glTextureView(
  67. mViewID,
  68. target,
  69. originalTexture,
  70. texture->getGLFormat(),
  71. desc.mostDetailMip,
  72. desc.numMips,
  73. desc.firstArraySlice,
  74. desc.numArraySlices);
  75. BS_CHECK_GL_ERROR();
  76. #endif
  77. mTarget = GLTexture::getGLTextureTarget(props.getTextureType(), props.getNumSamples(), desc.numArraySlices);
  78. }
  79. GLTextureView::~GLTextureView()
  80. {
  81. if(mViewID != 0)
  82. {
  83. glDeleteTextures(1, &mViewID);
  84. BS_CHECK_GL_ERROR();
  85. }
  86. }
  87. }}