#include "stdafx.h" #include "ITexture.h" #include "IEngine.h" #include "IResourcefactory.h" #include "RenderTargetTexture.h" RenderTargetTexture::RenderTargetTexture(IEngine& argEngine) : RenderTargetBase(argEngine) , m_Texture(NULL) { } RenderTargetTexture::~RenderTargetTexture() { delete m_Texture; m_Engine.get_ResourceFactory().DeleteRenderTargetTexture(*const_cast(this), true); } void RenderTargetTexture::SetTextureParameters(uint32 argWidth, uint32 argHeight, DataFormat::Enumeration argFormat, uint32 argMultiSampleCount, uint32 argMultiSampleQuality) { if (argWidth == this->get_RenderTargetWidth() && argHeight == this->get_RenderTargetHeight() && argFormat == this->get_RenderTargetFormat() && m_MultiSampleCount == argMultiSampleCount && m_MultiSampleQuality == argMultiSampleQuality) { return; } RenderTargetBase::Uninitialize(); // get missing information if (argMultiSampleCount == 0) argMultiSampleCount = 1; if (argWidth == 0) argWidth = 1; if (argHeight == 0) argHeight = 1; if (argFormat == DataFormat::Unknown) argFormat = DataFormat::R8G8B8A8_UnsignedNormalized; if (m_Texture == NULL) m_Texture = &m_Engine.get_ResourceFactory().CreateOrFindTexture(); m_MultiSampleCount = argMultiSampleCount; m_MultiSampleQuality = argMultiSampleQuality; m_Texture->CreateRenderTargetTexture(argWidth, argHeight, argFormat, argMultiSampleCount, argMultiSampleQuality); HRESULT lh_Result = m_Engine.get_DX10Device().CreateRenderTargetView(m_Texture->get_Texture2D(), NULL, &m_RenderTargetView); if(FAILED(lh_Result)) throw L"RenderTargetTexture: Unable to retrieve rendertarget view."; ViewPort viewPort; viewPort.m_Width = argWidth; viewPort.m_Height = argHeight; this->set_ViewPort(viewPort); } void RenderTargetTexture::Resize(int argWidth, int argHeight) { if (m_Texture == NULL) throw L"SwapChainResource: Access forbidden until resource has been initialized."; if (this->get_RenderTargetWidth() == argWidth || this->get_RenderTargetHeight() == argHeight) return; bool lb_DepthStencilBuffer = this->get_HasDepthStencilBuffer(); this->SetTextureParameters(argWidth, argHeight, this->get_RenderTargetFormat(), m_MultiSampleCount, m_MultiSampleQuality); this->set_HasDepthStencilBuffer(lb_DepthStencilBuffer); } void RenderTargetTexture::Uninitialize() { if (m_Texture != NULL) m_Engine.get_ResourceFactory().DeleteTexture(*m_Texture); RenderTargetBase::Uninitialize(); } uint32 RenderTargetTexture::get_RenderTargetWidth() const { return m_Texture == NULL ? 0 : m_Texture->get_TextureWidth(); } uint32 RenderTargetTexture::get_RenderTargetHeight() const { return m_Texture == NULL ? 0 : m_Texture->get_TextureHeight(); } DataFormat::Enumeration RenderTargetTexture::get_RenderTargetFormat() const { return m_Texture == NULL ? DataFormat::Unknown : m_Texture->get_TextureFormat(); }