2
0

CmGLMultiRenderTexture.cpp 1.8 KB

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