CmGLMultiRenderTexture.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include "CmGLMultiRenderTexture.h"
  2. #include "CmGLTexture.h"
  3. namespace CamelotEngine
  4. {
  5. GLMultiRenderTexture::GLMultiRenderTexture()
  6. :MultiRenderTexture(), mFB(nullptr)
  7. {
  8. }
  9. GLMultiRenderTexture::~GLMultiRenderTexture()
  10. {
  11. }
  12. void GLMultiRenderTexture::destroy_internal()
  13. {
  14. if(mFB != nullptr)
  15. delete mFB;
  16. MultiRenderTexture::destroy_internal();
  17. }
  18. void GLMultiRenderTexture::setColorSurfaceImpl(UINT32 surfaceIdx, TexturePtr texture, UINT32 face, UINT32 numFaces, UINT32 mipLevel)
  19. {
  20. if(texture != nullptr)
  21. {
  22. GLSurfaceDesc surfaceDesc;
  23. surfaceDesc.numSamples = mFSAA;
  24. surfaceDesc.zoffset = 0;
  25. GLTexture* glTexture = static_cast<GLTexture*>(texture.get());
  26. surfaceDesc.buffer = std::static_pointer_cast<GLPixelBuffer>(glTexture->getBuffer(face, mipLevel));
  27. mFB->bindSurface(surfaceIdx, surfaceDesc);
  28. }
  29. else
  30. {
  31. mFB->unbindSurface(surfaceIdx);
  32. }
  33. }
  34. void GLMultiRenderTexture::setDepthStencilImpl(TexturePtr depthStencilSurface, UINT32 face, UINT32 numFaces, UINT32 mipLevel)
  35. {
  36. if(depthStencilSurface != nullptr)
  37. {
  38. GLTexture* glDepthStencilSurface = static_cast<GLTexture*>(depthStencilSurface.get());
  39. GLPixelBufferPtr depthStencilBuffer = std::static_pointer_cast<GLPixelBuffer>(glDepthStencilSurface->getBuffer(face, mipLevel));
  40. mFB->bindDepthStencil(depthStencilBuffer);
  41. }
  42. else
  43. {
  44. mFB->unbindDepthStencil();
  45. }
  46. }
  47. void GLMultiRenderTexture::getCustomAttribute(const String& name, void* pData)
  48. {
  49. if(name=="FBO")
  50. {
  51. *static_cast<GLFrameBufferObject **>(pData) = mFB;
  52. }
  53. else if (name == "GL_FBOID" || name == "GL_MULTISAMPLEFBOID")
  54. {
  55. *static_cast<GLuint*>(pData) = mFB->getGLFBOID();
  56. }
  57. }
  58. void GLMultiRenderTexture::initialize()
  59. {
  60. if(mFB != nullptr)
  61. delete mFB;
  62. mFB = new GLFrameBufferObject(mFSAA);
  63. MultiRenderTexture::initialize();
  64. }
  65. }