BsGLMultiRenderTexture.cpp 1.9 KB

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