CmGLMultiRenderTexture.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "CmGLMultiRenderTexture.h"
  2. #include "CmGLDepthStencilBuffer.h"
  3. #include "CmGLTexture.h"
  4. namespace CamelotEngine
  5. {
  6. GLMultiRenderTexture::GLMultiRenderTexture()
  7. :MultiRenderTexture(), mFB(nullptr)
  8. {
  9. }
  10. GLMultiRenderTexture::~GLMultiRenderTexture()
  11. {
  12. if(mFB != nullptr)
  13. delete mFB;
  14. }
  15. void GLMultiRenderTexture::setColorSurfaceImpl(UINT32 surfaceIdx, TexturePtr texture, UINT32 face, UINT32 numFaces, UINT32 mipLevel)
  16. {
  17. if(texture != nullptr)
  18. {
  19. GLSurfaceDesc surfaceDesc;
  20. surfaceDesc.numSamples = mFSAA;
  21. surfaceDesc.zoffset = 0;
  22. GLTexture* glTexture = static_cast<GLTexture*>(texture.get());
  23. surfaceDesc.buffer = std::static_pointer_cast<GLHardwarePixelBuffer>(glTexture->getBuffer(face, mipLevel));
  24. mFB->bindSurface(surfaceIdx, surfaceDesc);
  25. }
  26. else
  27. {
  28. mFB->unbindSurface(surfaceIdx);
  29. }
  30. }
  31. void GLMultiRenderTexture::setDepthStencilImpl(DepthStencilBufferPtr depthStencilBuffer)
  32. {
  33. if(depthStencilBuffer != nullptr)
  34. {
  35. GLDepthStencilBuffer* glDepthStencilBuffer = static_cast<GLDepthStencilBuffer*>(mDepthStencilBuffer.get());
  36. mFB->bindDepthStencil(glDepthStencilBuffer->getGLRenderBuffer());
  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. }