162 lines
4.0 KiB
C++
162 lines
4.0 KiB
C++
|
/****************************************************************************
|
||
|
Copyright (C) 2007 Radon Labs GmbH
|
||
|
Copyright (c) 2011-2013,WebJet Business Division,CYOU
|
||
|
|
||
|
http://www.genesis-3d.com.cn
|
||
|
|
||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||
|
of this software and associated documentation files (the "Software"), to deal
|
||
|
in the Software without restriction, including without limitation the rights
|
||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||
|
copies of the Software, and to permit persons to whom the Software is
|
||
|
furnished to do so, subject to the following conditions:
|
||
|
|
||
|
The above copyright notice and this permission notice shall be included in
|
||
|
all copies or substantial portions of the Software.
|
||
|
|
||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||
|
THE SOFTWARE.
|
||
|
****************************************************************************/
|
||
|
|
||
|
#if WIN32
|
||
|
|
||
|
|
||
|
|
||
|
#include "stdneb.h"
|
||
|
#include "D3D9Types.h"
|
||
|
#include "PrimitiveGroupD3D9.h"
|
||
|
|
||
|
namespace D3D9
|
||
|
{
|
||
|
__ImplementClass(PrimitiveGroupD3D9,'PGD9',PrimitiveGroup)
|
||
|
using namespace RenderBase;
|
||
|
|
||
|
//------------------------------------------------------------------------------
|
||
|
/**
|
||
|
*/
|
||
|
PrimitiveGroupD3D9::PrimitiveGroupD3D9()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
PrimitiveGroupD3D9::~PrimitiveGroupD3D9()
|
||
|
{
|
||
|
m_vertexBuffer = 0;
|
||
|
m_indexBuffer = 0;
|
||
|
}
|
||
|
|
||
|
void PrimitiveGroupD3D9::Discard()
|
||
|
{
|
||
|
m_vertexBuffer = 0;
|
||
|
m_indexBuffer = 0;
|
||
|
}
|
||
|
|
||
|
bool PrimitiveGroupD3D9::IsDefaultPool()
|
||
|
{
|
||
|
if (m_vertexBuffer.isvalid())
|
||
|
{
|
||
|
if (D3DPOOL_DEFAULT == D3D9Types::AsD3D9Pool(m_vertexBuffer->GetUsage()))
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
if (m_indexBuffer.isvalid())
|
||
|
{
|
||
|
if (D3DPOOL_DEFAULT == D3D9Types::AsD3D9Pool(m_indexBuffer->GetUsage()))
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
void PrimitiveGroupD3D9::OnDeviceLost()
|
||
|
{
|
||
|
//TODO
|
||
|
|
||
|
if (IsDefaultPool())
|
||
|
{
|
||
|
if (m_vertexBuffer.isvalid())
|
||
|
{
|
||
|
if (D3DPOOL_DEFAULT == D3D9Types::AsD3D9Pool(m_vertexBuffer->GetUsage()))
|
||
|
{
|
||
|
GPtr<VertexBufferD3D9> vb9 = m_vertexBuffer.downcast<VertexBufferD3D9>();
|
||
|
vb9->OnDeviceLost();
|
||
|
}
|
||
|
}
|
||
|
if (m_indexBuffer.isvalid())
|
||
|
{
|
||
|
if (D3DPOOL_DEFAULT == D3D9Types::AsD3D9Pool(m_indexBuffer->GetUsage()))
|
||
|
{
|
||
|
GPtr<IndexBufferD3D9> ib9 = m_indexBuffer.downcast<IndexBufferD3D9>();
|
||
|
ib9->OnDeviceLost();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
/// on device reset
|
||
|
void PrimitiveGroupD3D9::OnDeviceReset()
|
||
|
{
|
||
|
if (IsDefaultPool())
|
||
|
{
|
||
|
if (m_vertexBuffer.isvalid())
|
||
|
{
|
||
|
if (D3DPOOL_DEFAULT == D3D9Types::AsD3D9Pool(m_vertexBuffer->GetUsage()))
|
||
|
{
|
||
|
GPtr<VertexBufferD3D9> vb9 = m_vertexBuffer.downcast<VertexBufferD3D9>();
|
||
|
vb9->OnDeviceReset();
|
||
|
}
|
||
|
}
|
||
|
if (m_indexBuffer.isvalid())
|
||
|
{
|
||
|
if (D3DPOOL_DEFAULT == D3D9Types::AsD3D9Pool(m_indexBuffer->GetUsage()))
|
||
|
{
|
||
|
GPtr<IndexBufferD3D9> ib9 = m_indexBuffer.downcast<IndexBufferD3D9>();
|
||
|
ib9->OnDeviceReset();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
//--------------------------------------------------------------------------------
|
||
|
void PrimitiveGroupD3D9::LoadBuffers(const VertexBufferData* vbd, const IndexBufferData* ibd)
|
||
|
{
|
||
|
n_assert(PrimitiveTopology::InvalidPrimitiveTopology != vbd->topology);
|
||
|
|
||
|
SetBoundingBox(Math::bbox::Zero);
|
||
|
if (vbd)
|
||
|
{
|
||
|
SetPrimitiveTopology(vbd->topology);
|
||
|
n_assert(NULL == m_vertexBuffer);
|
||
|
SetBaseVertex(0);
|
||
|
SetNumVertices(vbd->vertexCount);
|
||
|
|
||
|
GPtr<VertexBufferD3D9> out;
|
||
|
VertexBufferD3D9::CreateVertexBuffer(vbd, out);
|
||
|
m_vertexBuffer = out;
|
||
|
}
|
||
|
|
||
|
//copy index data
|
||
|
if (ibd)
|
||
|
{
|
||
|
n_assert(NULL == m_indexBuffer);
|
||
|
SetBaseIndex(0);
|
||
|
SetNumIndices(ibd->indexCount);
|
||
|
|
||
|
GPtr<IndexBufferD3D9> out;
|
||
|
IndexBufferD3D9::CreateIndexBuffer(ibd, out);
|
||
|
m_indexBuffer = out;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
#endif
|