Moderators: Moderators, OGRE Team





There are some directX parts of it that I don't know how to translate to OGRE, it uses functions like "SetStreamSourceFreq" that the OGRE dx render system doesn't use – so it is not that easy to convert the project to OGRE.
size_t instancesCount; ///< use 0 for turn off instancing if(op.instancesCount > 0) {
hr = mpD3DDevice->SetStreamSourceFreq(0, D3DSTREAMSOURCE_INDEXEDDATA | op.instancesCount);
if(SUCCEEDED(hr)) {
mpD3DDevice->SetStreamSourceFreq(1, D3DSTREAMSOURCE_INSTANCEDATA | 1);
}
if (FAILED(hr))
{
OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Unable to setup geometry instancing", "D3D9RenderSystem::_render" );
}
}
if(op.instancesCount > 0) {
// finish instancing
hr = mpD3DDevice->SetStreamSourceFreq(0, 1);
if( SUCCEEDED( hr ) ) {
mpD3DDevice->SetStreamSourceFreq(1, 1);
}
if (FAILED(hr))
{
OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Unable to unbind geometry instancing", "D3D9RenderSystem::_render" );
}
}
//---------------------------------------------------------------------
void D3D9RenderSystem::_render(const RenderOperation& op)
{
// Exit immediately if there is nothing to render
// This caused a problem on FireGL 8800
if (op.vertexData->vertexCount == 0)
return;
// Call super class
RenderSystem::_render(op);
// To think about: possibly remove setVertexDeclaration and
// setVertexBufferBinding from RenderSystem since the sequence is
// a bit too D3D9-specific?
setVertexDeclaration(op.vertexData->vertexDeclaration);
setVertexBufferBinding(op.vertexData->vertexBufferBinding);
// Determine rendering operation
D3DPRIMITIVETYPE primType = D3DPT_TRIANGLELIST;
DWORD primCount = 0;
switch( op.operationType )
{
case RenderOperation::OT_POINT_LIST:
primType = D3DPT_POINTLIST;
primCount = (DWORD)(op.useIndexes ? op.indexData->indexCount : op.vertexData->vertexCount);
break;
case RenderOperation::OT_LINE_LIST:
primType = D3DPT_LINELIST;
primCount = (DWORD)(op.useIndexes ? op.indexData->indexCount : op.vertexData->vertexCount) / 2;
break;
case RenderOperation::OT_LINE_STRIP:
primType = D3DPT_LINESTRIP;
primCount = (DWORD)(op.useIndexes ? op.indexData->indexCount : op.vertexData->vertexCount) - 1;
break;
case RenderOperation::OT_TRIANGLE_LIST:
primType = D3DPT_TRIANGLELIST;
primCount = (DWORD)(op.useIndexes ? op.indexData->indexCount : op.vertexData->vertexCount) / 3;
break;
case RenderOperation::OT_TRIANGLE_STRIP:
primType = D3DPT_TRIANGLESTRIP;
primCount = (DWORD)(op.useIndexes ? op.indexData->indexCount : op.vertexData->vertexCount) - 2;
break;
case RenderOperation::OT_TRIANGLE_FAN:
primType = D3DPT_TRIANGLEFAN;
primCount = (DWORD)(op.useIndexes ? op.indexData->indexCount : op.vertexData->vertexCount) - 2;
break;
}
if (!primCount)
return;
HRESULT hr;
if(op.instancesCount > 0) {
hr = mpD3DDevice->SetStreamSourceFreq(0, D3DSTREAMSOURCE_INDEXEDDATA | op.instancesCount);
if(SUCCEEDED(hr)) {
mpD3DDevice->SetStreamSourceFreq(1, D3DSTREAMSOURCE_INSTANCEDATA | 1);
}
if (FAILED(hr))
{
OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Unable to setup geometry instancing", "D3D9RenderSystem::_render" );
}
}
// Issue the op
if( op.useIndexes )
{
D3D9HardwareIndexBuffer* d3dIdxBuf =
static_cast<D3D9HardwareIndexBuffer*>(op.indexData->indexBuffer.get());
hr = mpD3DDevice->SetIndices( d3dIdxBuf->getD3DIndexBuffer() );
if (FAILED(hr))
{
OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Failed to set index buffer", "D3D9RenderSystem::_render" );
}
do
{
// do indexed draw operation
hr = mpD3DDevice->DrawIndexedPrimitive(
primType,
static_cast<INT>(op.vertexData->vertexStart),
0, // Min vertex index - assume we can go right down to 0
static_cast<UINT>(op.vertexData->vertexCount),
static_cast<UINT>(op.indexData->indexStart),
static_cast<UINT>(primCount)
);
} while (updatePassIterationRenderState());
}
else
{
// nfz: gpu_iterate
do
{
// Unindexed, a little simpler!
hr = mpD3DDevice->DrawPrimitive(
primType,
static_cast<UINT>(op.vertexData->vertexStart),
static_cast<UINT>(primCount)
);
} while (updatePassIterationRenderState());
}
if(op.instancesCount > 0) {
// finish instancing
hr = mpD3DDevice->SetStreamSourceFreq(0, 1);
if( SUCCEEDED( hr ) ) {
mpD3DDevice->SetStreamSourceFreq(1, 1);
}
if (FAILED(hr))
{
OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Unable to unbind geometry instancing", "D3D9RenderSystem::_render" );
}
}
if( FAILED( hr ) )
{
String msg = DXGetErrorDescription9(hr);
OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Failed to DrawPrimitive : " + msg, "D3D9RenderSystem::_render" );
}
}sinbad wrote:Yep, hellcatv and shirsoft from Stanford have a project they're actively working on,so wanted an addon spot for it. I rarely say no to that kind of offer

shirsoft wrote:Somehow I landed up on this page. Its BSD license.

Users browsing this forum: Gohla, MSN [Bot], TeaBag, Xavyiy and 5 guests