BsGLMultiRenderTexture.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. if (mFB != nullptr)
  9. bs_delete(mFB);
  10. mFB = bs_new<GLFrameBufferObject, PoolAlloc>();
  11. for (size_t i = 0; i < mColorSurfaces.size(); i++)
  12. {
  13. if (mColorSurfaces[i] != nullptr)
  14. {
  15. GLTexture* glColorSurface = static_cast<GLTexture*>(mColorSurfaces[i]->getTexture().get());
  16. GLPixelBufferPtr colorBuffer =
  17. glColorSurface->getBuffer(mColorSurfaces[i]->getDesc().firstArraySlice,
  18. mColorSurfaces[i]->getDesc().mostDetailMip);
  19. GLSurfaceDesc surfaceDesc;
  20. surfaceDesc.numSamples = getProperties().getMultisampleCount();
  21. surfaceDesc.zoffset = 0;
  22. surfaceDesc.buffer = colorBuffer;
  23. mFB->bindSurface((UINT32)i, surfaceDesc);
  24. }
  25. else
  26. {
  27. mFB->unbindSurface((UINT32)i);
  28. }
  29. }
  30. if (mDepthStencilSurface != nullptr)
  31. {
  32. GLTexture* glDepthStencilSurface = static_cast<GLTexture*>(mDepthStencilSurface->getTexture().get());
  33. GLPixelBufferPtr depthStencilBuffer =
  34. glDepthStencilSurface->getBuffer(mDepthStencilSurface->getDesc().firstArraySlice,
  35. mDepthStencilSurface->getDesc().mostDetailMip);
  36. mFB->bindDepthStencil(depthStencilBuffer);
  37. }
  38. else
  39. {
  40. mFB->unbindDepthStencil();
  41. }
  42. }
  43. GLMultiRenderTextureCore::~GLMultiRenderTextureCore()
  44. {
  45. if (mFB != nullptr)
  46. bs_delete(mFB);
  47. }
  48. void GLMultiRenderTextureCore::getCustomAttribute(const String& name, void* pData) const
  49. {
  50. if(name=="FBO")
  51. {
  52. *static_cast<GLFrameBufferObject **>(pData) = mFB;
  53. }
  54. else if (name == "GL_FBOID" || name == "GL_MULTISAMPLEFBOID")
  55. {
  56. *static_cast<GLuint*>(pData) = mFB->getGLFBOID();
  57. }
  58. }
  59. RenderTargetProperties* GLMultiRenderTexture::createProperties() const
  60. {
  61. return bs_new<MultiRenderTextureProperties>();
  62. }
  63. MultiRenderTextureCore* GLMultiRenderTexture::createCore(MultiRenderTextureProperties* properties, const MULTI_RENDER_TEXTURE_DESC& desc)
  64. {
  65. return bs_new<GLMultiRenderTextureCore>(this, properties, desc);
  66. }
  67. }