コード例 #1
0
/// @copydoc RShader::Unlock()
bool D3D9PixelShader::Unlock()
{
    if( !m_bStaging )
    {
        HELIUM_TRACE( TraceLevels::Error, TXT( "D3D9PixelShader::Unlock(): Pixel shader has already been loaded.\n" ) );

        return false;
    }

    // Verify that the shader data is DWORD-aligned since we need to cast it when passing it to the shader creation
    // function.
    HELIUM_ASSERT( ( reinterpret_cast< uintptr_t >( m_pShaderData ) & ( sizeof( DWORD ) - 1 ) ) == 0 );

    D3D9Renderer* pRenderer = static_cast< D3D9Renderer* >( Renderer::GetStaticInstance() );
    HELIUM_ASSERT( pRenderer );

    IDirect3DDevice9* pD3DDevice = pRenderer->GetD3DDevice();
    HELIUM_ASSERT( pD3DDevice );

    IDirect3DPixelShader9* pD3DShader = NULL;
    HRESULT createResult = pD3DDevice->CreatePixelShader( static_cast< DWORD* >( m_pShaderData ), &pD3DShader );
    if( FAILED( createResult ) )
    {
        HELIUM_TRACE( TraceLevels::Error, TXT( "D3D9PixelShader::Unlock(): Pixel shader creation failed.\n" ) );
        pD3DShader = NULL;
    }

    DefaultAllocator().Free( m_pShaderData );
    m_pShaderData = pD3DShader;
    m_bStaging = false;

    return ( pD3DShader != NULL );
}
コード例 #2
0
D3D9RendererTexture2D::D3D9RendererTexture2D(IDirect3DDevice9 &d3dDevice, D3D9Renderer& renderer, const RendererTexture2DDesc &desc)
       :RendererTexture2D(desc)
	,m_d3dDevice(d3dDevice)
{
	m_d3dTexture     = 0;
	//managed textures can't be locked.
#ifdef	DIRECT3D9_SUPPORT_D3DUSAGE_DYNAMIC
	m_usage          = renderer.canUseManagedResources() ? 0 : D3DUSAGE_DYNAMIC;
#else
	m_usage          = 0;
#endif
	m_pool           = renderer.canUseManagedResources() ? D3DPOOL_MANAGED : D3DPOOL_DEFAULT;
	m_format         = getD3D9TextureFormat(desc.format);
	m_d3dMinFilter   = getD3D9TextureFilter(desc.filter);
	m_d3dMagFilter   = getD3D9TextureFilter(desc.filter);
	m_d3dMipFilter   = getD3D9TextureFilter(desc.filter);
	m_d3dAddressingU = getD3D9TextureAddressing(desc.addressingU);
	m_d3dAddressingV = getD3D9TextureAddressing(desc.addressingV);
	if(desc.renderTarget)
	{
		m_usage = D3DUSAGE_RENDERTARGET; 
		m_pool  = D3DPOOL_DEFAULT;
	}
	if(isDepthStencilFormat(desc.format))
	{
		m_usage = D3DUSAGE_DEPTHSTENCIL; 
		m_pool  = D3DPOOL_DEFAULT;
	}
	onDeviceReset();
}
コード例 #3
0
D3D9RendererInstanceBuffer::D3D9RendererInstanceBuffer(IDirect3DDevice9 &d3dDevice, D3D9Renderer& renderer, const RendererInstanceBufferDesc &desc) :
RendererInstanceBuffer(desc)
#if RENDERER_INSTANCING
	,m_d3dDevice(d3dDevice)
#endif
{
#if RENDERER_INSTANCING
	m_d3dVertexBuffer = 0;
#endif

	m_usage      = 0;
	m_pool       = renderer.canUseManagedResources() ? D3DPOOL_MANAGED : D3DPOOL_DEFAULT;
	m_bufferSize = (UINT)(desc.maxInstances * m_stride);

#if RENDERER_ENABLE_DYNAMIC_VB_POOLS
	if(desc.hint==RendererInstanceBuffer::HINT_DYNAMIC )
	{
		m_usage = desc.registerInCUDA ? 0 : D3DUSAGE_DYNAMIC;
		m_pool  = D3DPOOL_DEFAULT;
	}
#endif

	onDeviceReset();

#if RENDERER_INSTANCING	
	if(m_d3dVertexBuffer)
	{
		m_maxInstances = desc.maxInstances;
	}
#else
	m_maxInstances = desc.maxInstances;
	mInstanceBuffer = malloc(m_maxInstances*m_stride); // PX_ALLOC(m_maxInstances*m_stride);
#endif
}
コード例 #4
0
D3D9RendererVertexBuffer::D3D9RendererVertexBuffer(IDirect3DDevice9 &d3dDevice, D3D9Renderer& renderer, const RendererVertexBufferDesc &desc, bool deferredUnlock) :
RendererVertexBuffer(desc),
	m_d3dDevice(d3dDevice),
	m_savedData(NULL)
{
	m_d3dVertexBuffer = 0;
	m_deferredUnlock = deferredUnlock;

	m_usage      = 0;
	m_pool       = renderer.canUseManagedResources() ? D3DPOOL_MANAGED : D3DPOOL_DEFAULT;
	m_bufferSize = (UINT)(desc.maxVertices * m_stride);

	m_bufferWritten = false;

#if RENDERER_ENABLE_DYNAMIC_VB_POOLS
	if(desc.hint==RendererVertexBuffer::HINT_DYNAMIC && !desc.canReadBack)
	{
		m_usage = desc.registerInCUDA ? 0 : D3DUSAGE_DYNAMIC;
		m_pool  = D3DPOOL_DEFAULT;
	}
#endif

	onDeviceReset();

	if(m_d3dVertexBuffer)
	{
		m_maxVertices = desc.maxVertices;
	}
}
コード例 #5
0
D3D9RendererIndexBuffer::D3D9RendererIndexBuffer(IDirect3DDevice9 &d3dDevice, D3D9Renderer& renderer, const RendererIndexBufferDesc &desc) :
	RendererIndexBuffer(desc),
	m_d3dDevice(d3dDevice)
{
	m_d3dIndexBuffer = 0;

	m_usage      = 0;
	m_pool       = renderer.canUseManagedResources() ? D3DPOOL_MANAGED : D3DPOOL_DEFAULT;
	PxU32	indexSize  = getFormatByteSize(desc.format);
	m_format     = getD3D9Format(desc.format);
	m_bufferSize = indexSize * desc.maxIndices;

#if RENDERER_ENABLE_DYNAMIC_VB_POOLS
	if(desc.hint == RendererIndexBuffer::HINT_DYNAMIC && !desc.canReadBack)
	{
		m_usage = desc.registerInCUDA ? 0 : D3DUSAGE_DYNAMIC;
		m_pool  = D3DPOOL_DEFAULT;
	}
#endif

	onDeviceReset();

	if(m_d3dIndexBuffer)
	{
		m_maxIndices = desc.maxIndices;
	}
}
コード例 #6
0
/// @copydoc RRenderContext::Swap()
void D3D9MainContext::Swap()
{
    // Release the current back buffer surface.
    m_spBackBufferSurface.Release();

    // Present the scene.
    HRESULT result = m_pDevice->Present( NULL, NULL, NULL, NULL );
    if( result == D3DERR_DEVICELOST )
    {
        D3D9Renderer* pRenderer = static_cast< D3D9Renderer* >( Renderer::GetStaticInstance() );
        HELIUM_ASSERT( pRenderer );
        pRenderer->NotifyLost();
    }
    else
    {
        HELIUM_D3D9_ASSERT( result );
    }
}
コード例 #7
0
D3D9RendererVertexBuffer::D3D9RendererVertexBuffer(IDirect3DDevice9 &d3dDevice, D3D9Renderer& renderer, const RendererVertexBufferDesc &desc) :
RendererVertexBuffer(desc),
	m_d3dDevice(d3dDevice),
	m_savedData(NULL)
{
	m_d3dVertexBuffer = 0;

	m_usage      = D3DUSAGE_WRITEONLY;
	m_lockFlags  = 0;
	m_pool       = renderer.canUseManagedResources() ? D3DPOOL_MANAGED : D3DPOOL_DEFAULT;
	m_bufferSize = (UINT)(desc.maxVertices * m_stride);

	m_bufferWritten = false;

#if RENDERER_ENABLE_DYNAMIC_VB_POOLS
	if(desc.hint==RendererVertexBuffer::HINT_DYNAMIC )
	{
		if (!desc.registerInCUDA)
		{
			m_usage = D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY;
			// discard all that data if we are going to overwrite it again (saves some time waiting to copy everything back)
			m_lockFlags = D3DLOCK_DISCARD;
		}
		else
		{
			m_usage = 0;
		}

		m_pool  = D3DPOOL_DEFAULT;
	}
#endif

	onDeviceReset();

	if(m_d3dVertexBuffer)
	{
		m_maxVertices = desc.maxVertices;
	}
}