BsGLMultiRenderTexture.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include "BsGLMultiRenderTexture.h"
  2. #include "BsGLTexture.h"
  3. namespace BansheeEngine
  4. {
  5. GLMultiRenderTextureCore::GLMultiRenderTextureCore(GLMultiRenderTexture* parent, MultiRenderTextureProperties* properties, const MULTI_RENDER_TEXTURE_DESC& desc)
  6. :MultiRenderTextureCore(parent, properties, 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. GLTexture* glColorSurface = static_cast<GLTexture*>(mColorSurfaces[i]->getTexture().get());
  21. GLPixelBufferPtr colorBuffer = nullptr;
  22. GLSurfaceDesc surfaceDesc;
  23. if (glColorSurface->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. GLTexture* glDepthStencilSurface = static_cast<GLTexture*>(mDepthStencilSurface->getTexture().get());
  46. GLPixelBufferPtr depthStencilBuffer = nullptr;
  47. if (glDepthStencilSurface->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. RenderTargetProperties* GLMultiRenderTexture::createProperties() const
  78. {
  79. return bs_new<MultiRenderTextureProperties>();
  80. }
  81. SPtr<CoreObjectCore> GLMultiRenderTexture::createCore() const
  82. {
  83. MultiRenderTextureProperties* coreProperties = bs_new<MultiRenderTextureProperties>();
  84. MultiRenderTextureProperties* myProperties = static_cast<MultiRenderTextureProperties*>(mProperties);
  85. *coreProperties = *myProperties;
  86. return bs_shared_ptr<GLMultiRenderTextureCore>(const_cast<GLMultiRenderTexture*>(this),
  87. coreProperties, mDesc);
  88. }
  89. }