BsGLMultiRenderTexture.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsGLMultiRenderTexture.h"
  4. #include "BsGLTexture.h"
  5. namespace BansheeEngine
  6. {
  7. GLMultiRenderTextureCore::GLMultiRenderTextureCore(const MULTI_RENDER_TEXTURE_CORE_DESC& desc)
  8. :MultiRenderTextureCore(desc), mFB(nullptr), mProperties(desc)
  9. { }
  10. GLMultiRenderTextureCore::~GLMultiRenderTextureCore()
  11. {
  12. if (mFB != nullptr)
  13. bs_delete(mFB);
  14. }
  15. void GLMultiRenderTextureCore::initialize()
  16. {
  17. MultiRenderTextureCore::initialize();
  18. if (mFB != nullptr)
  19. bs_delete(mFB);
  20. mFB = bs_new<GLFrameBufferObject>();
  21. for (size_t i = 0; i < mColorSurfaces.size(); i++)
  22. {
  23. if (mColorSurfaces[i] != nullptr)
  24. {
  25. GLTextureCore* glColorSurface = static_cast<GLTextureCore*>(mColorSurfaces[i]->getTexture().get());
  26. GLSurfaceDesc surfaceDesc;
  27. surfaceDesc.numSamples = getProperties().getMultisampleCount();
  28. if (mColorSurfaces[i]->getNumArraySlices() == 1) // Binding a single texture layer
  29. {
  30. surfaceDesc.allLayers = glColorSurface->getProperties().getNumFaces() == 1;
  31. if (glColorSurface->getProperties().getTextureType() != TEX_TYPE_3D)
  32. {
  33. surfaceDesc.zoffset = 0;
  34. surfaceDesc.buffer = glColorSurface->getBuffer(mColorSurfaces[i]->getFirstArraySlice(),
  35. mColorSurfaces[i]->getMostDetailedMip());
  36. }
  37. else
  38. {
  39. surfaceDesc.zoffset = mColorSurfaces[i]->getFirstArraySlice();
  40. surfaceDesc.buffer = glColorSurface->getBuffer(0, mColorSurfaces[i]->getMostDetailedMip());
  41. }
  42. }
  43. else // Binding an array of textures or a range of 3D texture slices
  44. {
  45. surfaceDesc.allLayers = true;
  46. if (glColorSurface->getProperties().getTextureType() != TEX_TYPE_3D)
  47. {
  48. if (mColorSurfaces[i]->getNumArraySlices() != glColorSurface->getProperties().getNumFaces())
  49. LOGWRN("OpenGL doesn't support binding of arbitrary ranges for array textures. The entire range will be bound instead.");
  50. surfaceDesc.zoffset = 0;
  51. surfaceDesc.buffer = glColorSurface->getBuffer(0, mColorSurfaces[i]->getMostDetailedMip());
  52. }
  53. else
  54. {
  55. if (mColorSurfaces[i]->getNumArraySlices() != glColorSurface->getProperties().getDepth())
  56. LOGWRN("OpenGL doesn't support binding of arbitrary ranges for array textures. The entire range will be bound instead.");
  57. surfaceDesc.zoffset = 0;
  58. surfaceDesc.buffer = glColorSurface->getBuffer(0, mColorSurfaces[i]->getMostDetailedMip());
  59. }
  60. }
  61. mFB->bindSurface((UINT32)i, surfaceDesc);
  62. }
  63. else
  64. {
  65. mFB->unbindSurface((UINT32)i);
  66. }
  67. }
  68. if (mDepthStencilSurface != nullptr)
  69. {
  70. GLTextureCore* glDepthStencilSurface = static_cast<GLTextureCore*>(mDepthStencilSurface->getTexture().get());
  71. SPtr<GLPixelBuffer> depthStencilBuffer = nullptr;
  72. if (glDepthStencilSurface->getProperties().getTextureType() != TEX_TYPE_3D)
  73. {
  74. depthStencilBuffer = glDepthStencilSurface->getBuffer(mDepthStencilSurface->getDesc().firstArraySlice,
  75. mDepthStencilSurface->getDesc().mostDetailMip);
  76. }
  77. mFB->bindDepthStencil(depthStencilBuffer);
  78. }
  79. else
  80. {
  81. mFB->unbindDepthStencil();
  82. }
  83. }
  84. void GLMultiRenderTextureCore::getCustomAttribute(const String& name, void* pData) const
  85. {
  86. if(name=="FBO")
  87. {
  88. *static_cast<GLFrameBufferObject **>(pData) = mFB;
  89. }
  90. else if (name == "GL_FBOID" || name == "GL_MULTISAMPLEFBOID")
  91. {
  92. *static_cast<GLuint*>(pData) = mFB->getGLFBOID();
  93. }
  94. }
  95. GLMultiRenderTexture::GLMultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc)
  96. :MultiRenderTexture(desc), mProperties(desc)
  97. { }
  98. }