port from perforce
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
#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<RenderTargetTexture*>(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();
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "IRenderTargetTexture.h"
|
||||
#include "../RenderTargetBase.h"
|
||||
|
||||
struct ITexture;
|
||||
class RenderTargetTexture
|
||||
: public RenderTargetBase
|
||||
, public IRenderTargetTexture
|
||||
{
|
||||
public:
|
||||
RenderTargetTexture(IEngine& argEngine);
|
||||
virtual ~RenderTargetTexture();
|
||||
|
||||
virtual void SetTextureParameters(uint32 argWidth, uint32 argHeight, DataFormat::Enumeration argFormat, uint32 argMultiSampleCount = 1, uint32 argMultiSampleQuality = 0);
|
||||
virtual void Resize(int argWidth, int argHeight);
|
||||
virtual ITexture& get_TextureResource() const { return *m_Texture; }
|
||||
|
||||
virtual IRenderTargetBase& get_Base() { return *dynamic_cast<IRenderTargetBase*>(this); }
|
||||
|
||||
virtual void Uninitialize();
|
||||
|
||||
// IRenderTargetBase
|
||||
virtual uint32 get_RenderTargetWidth() const;
|
||||
virtual uint32 get_RenderTargetHeight() const;
|
||||
virtual DataFormat::Enumeration get_RenderTargetFormat() const;
|
||||
|
||||
protected:
|
||||
//ICommandUser
|
||||
virtual string8 get_UserName() const { return "RenderTargetTexture"; }
|
||||
|
||||
private:
|
||||
ITexture* m_Texture;
|
||||
};
|
||||
Reference in New Issue
Block a user