CmGLMultiRenderTexture.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include "CmGLMultiRenderTexture.h"
  2. #include "CmGLTexture.h"
  3. namespace CamelotFramework
  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. cm_delete(mFB);
  16. mFB = cm_new<GLFrameBufferObject, PoolAlloc>(mFSAA);
  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 = std::static_pointer_cast<GLPixelBuffer>(
  23. glColorSurface->getBuffer(mColorSurfaces[i]->getDesc().firstArraySlice, mColorSurfaces[i]->getDesc().mostDetailMip));
  24. GLSurfaceDesc surfaceDesc;
  25. surfaceDesc.numSamples = mFSAA;
  26. surfaceDesc.zoffset = 0;
  27. surfaceDesc.buffer = colorBuffer;
  28. mFB->bindSurface((UINT32)i, surfaceDesc);
  29. }
  30. else
  31. {
  32. mFB->unbindSurface((UINT32)i);
  33. }
  34. }
  35. if(mDepthStencilSurface != nullptr)
  36. {
  37. GLTexture* glDepthStencilSurface = static_cast<GLTexture*>(mDepthStencilSurface->getTexture().get());
  38. GLPixelBufferPtr depthStencilBuffer = std::static_pointer_cast<GLPixelBuffer>(
  39. glDepthStencilSurface->getBuffer(mDepthStencilSurface->getDesc().firstArraySlice, mDepthStencilSurface->getDesc().mostDetailMip));
  40. mFB->bindDepthStencil(depthStencilBuffer);
  41. }
  42. else
  43. {
  44. mFB->unbindDepthStencil();
  45. }
  46. MultiRenderTexture::initialize_internal();
  47. }
  48. void GLMultiRenderTexture::destroy_internal()
  49. {
  50. if(mFB != nullptr)
  51. CM_DELETE(mFB, GLFrameBufferObject, GenAlloc);
  52. MultiRenderTexture::destroy_internal();
  53. }
  54. void GLMultiRenderTexture::getCustomAttribute(const String& name, void* pData) const
  55. {
  56. if(name=="FBO")
  57. {
  58. *static_cast<GLFrameBufferObject **>(pData) = mFB;
  59. }
  60. else if (name == "GL_FBOID" || name == "GL_MULTISAMPLEFBOID")
  61. {
  62. *static_cast<GLuint*>(pData) = mFB->getGLFBOID();
  63. }
  64. }
  65. }