BsGLMultiRenderTexture.cpp 2.5 KB

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