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::initialize_internal()
  13. {
  14. if(mFB != nullptr)
  15. delete mFB;
  16. mFB = new GLFrameBufferObject(mFSAA);
  17. MultiRenderTexture::initialize_internal();
  18. }
  19. void GLMultiRenderTexture::destroy_internal()
  20. {
  21. if(mFB != nullptr)
  22. delete mFB;
  23. MultiRenderTexture::destroy_internal();
  24. }
  25. void GLMultiRenderTexture::setColorSurfaceImpl(UINT32 surfaceIdx, TexturePtr texture, UINT32 face, UINT32 numFaces, UINT32 mipLevel)
  26. {
  27. if(texture != nullptr)
  28. {
  29. GLSurfaceDesc surfaceDesc;
  30. surfaceDesc.numSamples = mFSAA;
  31. surfaceDesc.zoffset = 0;
  32. GLTexture* glTexture = static_cast<GLTexture*>(texture.get());
  33. surfaceDesc.buffer = std::static_pointer_cast<GLPixelBuffer>(glTexture->getBuffer(face, mipLevel));
  34. mFB->bindSurface(surfaceIdx, surfaceDesc);
  35. }
  36. else
  37. {
  38. mFB->unbindSurface(surfaceIdx);
  39. }
  40. }
  41. void GLMultiRenderTexture::setDepthStencilImpl(TexturePtr depthStencilSurface, UINT32 face, UINT32 numFaces, UINT32 mipLevel)
  42. {
  43. if(depthStencilSurface != nullptr)
  44. {
  45. GLTexture* glDepthStencilSurface = static_cast<GLTexture*>(depthStencilSurface.get());
  46. GLPixelBufferPtr depthStencilBuffer = std::static_pointer_cast<GLPixelBuffer>(glDepthStencilSurface->getBuffer(face, mipLevel));
  47. mFB->bindDepthStencil(depthStencilBuffer);
  48. }
  49. else
  50. {
  51. mFB->unbindDepthStencil();
  52. }
  53. }
  54. void GLMultiRenderTexture::getCustomAttribute(const String& name, void* pData)
  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. }