BsGLMultiRenderTexture.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include "BsGLMultiRenderTexture.h"
  2. #include "BsGLTexture.h"
  3. namespace BansheeEngine
  4. {
  5. GLMultiRenderTextureCore::GLMultiRenderTextureCore(const MULTI_RENDER_TEXTURE_DESC& desc)
  6. :MultiRenderTextureCore(desc), mProperties(desc), mFB(nullptr)
  7. { }
  8. GLMultiRenderTextureCore::~GLMultiRenderTextureCore()
  9. { }
  10. void GLMultiRenderTextureCore::initialize()
  11. {
  12. MultiRenderTextureCore::initialize();
  13. if (mFB != nullptr)
  14. bs_delete(mFB);
  15. mFB = bs_new<GLFrameBufferObject, PoolAlloc>();
  16. for (size_t i = 0; i < mColorSurfaces.size(); i++)
  17. {
  18. if (mColorSurfaces[i] != nullptr)
  19. {
  20. GLTextureCore* glColorSurface = static_cast<GLTextureCore*>(mColorSurfaces[i]->getTexture().get());
  21. GLPixelBufferPtr colorBuffer = nullptr;
  22. GLSurfaceDesc surfaceDesc;
  23. if (glColorSurface->getProperties().getTextureType() != TEX_TYPE_3D)
  24. {
  25. surfaceDesc.zoffset = 0;
  26. colorBuffer = glColorSurface->getBuffer(mColorSurfaces[i]->getFirstArraySlice(),
  27. mColorSurfaces[i]->getMostDetailedMip());
  28. }
  29. else
  30. {
  31. surfaceDesc.zoffset = mColorSurfaces[i]->getFirstArraySlice();
  32. colorBuffer = glColorSurface->getBuffer(0, mColorSurfaces[i]->getMostDetailedMip());
  33. }
  34. surfaceDesc.numSamples = getProperties().getMultisampleCount();
  35. surfaceDesc.buffer = colorBuffer;
  36. mFB->bindSurface((UINT32)i, surfaceDesc);
  37. }
  38. else
  39. {
  40. mFB->unbindSurface((UINT32)i);
  41. }
  42. }
  43. if (mDepthStencilSurface != nullptr)
  44. {
  45. GLTextureCore* glDepthStencilSurface = static_cast<GLTextureCore*>(mDepthStencilSurface->getTexture().get());
  46. GLPixelBufferPtr depthStencilBuffer = nullptr;
  47. if (glDepthStencilSurface->getProperties().getTextureType() != TEX_TYPE_3D)
  48. {
  49. depthStencilBuffer = glDepthStencilSurface->getBuffer(mDepthStencilSurface->getDesc().firstArraySlice,
  50. mDepthStencilSurface->getDesc().mostDetailMip);
  51. }
  52. mFB->bindDepthStencil(depthStencilBuffer);
  53. }
  54. else
  55. {
  56. mFB->unbindDepthStencil();
  57. }
  58. MultiRenderTextureCore::initialize();
  59. }
  60. void GLMultiRenderTextureCore::destroy()
  61. {
  62. if (mFB != nullptr)
  63. bs_delete(mFB);
  64. MultiRenderTextureCore::destroy();
  65. }
  66. void GLMultiRenderTextureCore::getCustomAttribute(const String& name, void* pData) const
  67. {
  68. if(name=="FBO")
  69. {
  70. *static_cast<GLFrameBufferObject **>(pData) = mFB;
  71. }
  72. else if (name == "GL_FBOID" || name == "GL_MULTISAMPLEFBOID")
  73. {
  74. *static_cast<GLuint*>(pData) = mFB->getGLFBOID();
  75. }
  76. }
  77. GLMultiRenderTexture::GLMultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc)
  78. :MultiRenderTexture(desc), mProperties(desc)
  79. { }
  80. }