BsGLMultiRenderTexture.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //__________________________ Banshee Project - A modern game development toolkit _________________________________//
  2. //_____________________________________ www.banshee-project.com __________________________________________________//
  3. //________________________ Copyright (c) 2014 Marko Pintera. All rights reserved. ________________________________//
  4. #include "BsGLMultiRenderTexture.h"
  5. #include "BsGLTexture.h"
  6. namespace BansheeEngine
  7. {
  8. GLMultiRenderTexture::GLMultiRenderTexture()
  9. :MultiRenderTexture(), mFB(nullptr)
  10. {
  11. }
  12. GLMultiRenderTexture::~GLMultiRenderTexture()
  13. {
  14. }
  15. void GLMultiRenderTexture::initialize_internal()
  16. {
  17. if(mFB != nullptr)
  18. bs_delete(mFB);
  19. mFB = bs_new<GLFrameBufferObject, PoolAlloc>();
  20. for(size_t i = 0; i < mColorSurfaces.size(); i++)
  21. {
  22. if(mColorSurfaces[i] != nullptr)
  23. {
  24. GLTexture* glColorSurface = static_cast<GLTexture*>(mColorSurfaces[i]->getTexture().get());
  25. GLPixelBufferPtr colorBuffer =
  26. glColorSurface->getBuffer(mColorSurfaces[i]->getDesc().firstArraySlice,
  27. mColorSurfaces[i]->getDesc().mostDetailMip);
  28. GLSurfaceDesc surfaceDesc;
  29. surfaceDesc.numSamples = mMultisampleCount;
  30. surfaceDesc.zoffset = 0;
  31. surfaceDesc.buffer = colorBuffer;
  32. mFB->bindSurface((UINT32)i, surfaceDesc);
  33. }
  34. else
  35. {
  36. mFB->unbindSurface((UINT32)i);
  37. }
  38. }
  39. if(mDepthStencilSurface != nullptr)
  40. {
  41. GLTexture* glDepthStencilSurface = static_cast<GLTexture*>(mDepthStencilSurface->getTexture().get());
  42. GLPixelBufferPtr depthStencilBuffer =
  43. glDepthStencilSurface->getBuffer(mDepthStencilSurface->getDesc().firstArraySlice,
  44. mDepthStencilSurface->getDesc().mostDetailMip);
  45. mFB->bindDepthStencil(depthStencilBuffer);
  46. }
  47. else
  48. {
  49. mFB->unbindDepthStencil();
  50. }
  51. MultiRenderTexture::initialize_internal();
  52. }
  53. void GLMultiRenderTexture::destroy_internal()
  54. {
  55. if(mFB != nullptr)
  56. bs_delete(mFB);
  57. MultiRenderTexture::destroy_internal();
  58. }
  59. void GLMultiRenderTexture::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. }