| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- #include "BsGLMultiRenderTexture.h"
- #include "BsGLTexture.h"
- namespace BansheeEngine
- {
- GLMultiRenderTextureCore::GLMultiRenderTextureCore(GLMultiRenderTexture* parent, MultiRenderTextureProperties* properties, const MULTI_RENDER_TEXTURE_DESC& desc)
- :MultiRenderTextureCore(parent, properties, desc), mFB(nullptr)
- { }
- GLMultiRenderTextureCore::~GLMultiRenderTextureCore()
- { }
- void GLMultiRenderTextureCore::initialize()
- {
- MultiRenderTextureCore::initialize();
- if (mFB != nullptr)
- bs_delete(mFB);
- mFB = bs_new<GLFrameBufferObject, PoolAlloc>();
- for (size_t i = 0; i < mColorSurfaces.size(); i++)
- {
- if (mColorSurfaces[i] != nullptr)
- {
- GLTexture* glColorSurface = static_cast<GLTexture*>(mColorSurfaces[i]->getTexture().get());
- GLPixelBufferPtr colorBuffer = nullptr;
- GLSurfaceDesc surfaceDesc;
- if (glColorSurface->getTextureType() != TEX_TYPE_3D)
- {
- surfaceDesc.zoffset = 0;
- colorBuffer = glColorSurface->getBuffer(mColorSurfaces[i]->getFirstArraySlice(),
- mColorSurfaces[i]->getMostDetailedMip());
- }
- else
- {
- surfaceDesc.zoffset = mColorSurfaces[i]->getFirstArraySlice();
- colorBuffer = glColorSurface->getBuffer(0, mColorSurfaces[i]->getMostDetailedMip());
- }
- surfaceDesc.numSamples = getProperties().getMultisampleCount();
- surfaceDesc.buffer = colorBuffer;
- mFB->bindSurface((UINT32)i, surfaceDesc);
- }
- else
- {
- mFB->unbindSurface((UINT32)i);
- }
- }
- if (mDepthStencilSurface != nullptr)
- {
- GLTexture* glDepthStencilSurface = static_cast<GLTexture*>(mDepthStencilSurface->getTexture().get());
- GLPixelBufferPtr depthStencilBuffer = nullptr;
- if (glDepthStencilSurface->getTextureType() != TEX_TYPE_3D)
- {
- depthStencilBuffer = glDepthStencilSurface->getBuffer(mDepthStencilSurface->getDesc().firstArraySlice,
- mDepthStencilSurface->getDesc().mostDetailMip);
- }
- mFB->bindDepthStencil(depthStencilBuffer);
- }
- else
- {
- mFB->unbindDepthStencil();
- }
- MultiRenderTextureCore::initialize();
- }
- void GLMultiRenderTextureCore::destroy()
- {
- if (mFB != nullptr)
- bs_delete(mFB);
- MultiRenderTextureCore::destroy();
- }
- void GLMultiRenderTextureCore::getCustomAttribute(const String& name, void* pData) const
- {
- if(name=="FBO")
- {
- *static_cast<GLFrameBufferObject **>(pData) = mFB;
- }
- else if (name == "GL_FBOID" || name == "GL_MULTISAMPLEFBOID")
- {
- *static_cast<GLuint*>(pData) = mFB->getGLFBOID();
- }
- }
- RenderTargetProperties* GLMultiRenderTexture::createProperties() const
- {
- return bs_new<MultiRenderTextureProperties>();
- }
- SPtr<CoreObjectCore> GLMultiRenderTexture::createCore() const
- {
- MultiRenderTextureProperties* coreProperties = bs_new<MultiRenderTextureProperties>();
- MultiRenderTextureProperties* myProperties = static_cast<MultiRenderTextureProperties*>(mProperties);
- *coreProperties = *myProperties;
- return bs_shared_ptr<GLMultiRenderTextureCore>(const_cast<GLMultiRenderTexture*>(this),
- coreProperties, mDesc);
- }
- }
|