Example #1
0
//-----------------------------------------------------------------------------
//! @brief   TODO enter a description
//! @remark
//-----------------------------------------------------------------------------
bool VertexBuffer::createBufferAndLayoutElements(const DeviceManager& deviceManager, size_t bufferSize, void* data, bool dynamic, const VertexDecalartionDesctriptor& vertexDeclartion, const ID3DBlob* vertexShaderCodeBlob)
{
    D3D11_BUFFER_DESC bufferDescriptor;
    ZeroMemory(&bufferDescriptor, sizeof(D3D11_BUFFER_DESC));
    bufferDescriptor.Usage = D3D11_USAGE_IMMUTABLE;
    bufferDescriptor.ByteWidth = (unsigned int)bufferSize;
    bufferDescriptor.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    bufferDescriptor.CPUAccessFlags = 0;
    bufferDescriptor.MiscFlags = 0;

    D3D11_SUBRESOURCE_DATA initData;
    ZeroMemory(&initData, sizeof(D3D11_SUBRESOURCE_DATA));
    initData.pSysMem = data;
    initData.SysMemPitch = 0;
    initData.SysMemSlicePitch = 0;

    HRESULT hr = deviceManager.getDevice()->CreateBuffer( &bufferDescriptor, &initData, &m_buffer );
    if (FAILED(hr))
    {
        MSG_TRACE_CHANNEL("VERTEXBUFFER", "Failed to create a D3D11 Buffer object with code: 0x%x", hr );
        return false;
    }

    if (!createVertexInputLayout(deviceManager, const_cast<ID3DBlob*>(vertexShaderCodeBlob), vertexDeclartion.createInputElementLayout(m_vertexStride)))
    {
        MSG_TRACE_CHANNEL("VERTEXBUFFER", "Failed to create Vertex Input Layout" );
        return false;
    }
    
    m_vertexCount = bufferSize / m_vertexStride;
    dynamic = false;

    return true;
}
Example #2
0
//-------------------------------------------------------------------------
// @Create needed sampler states for the textures here
//-------------------------------------------------------------------------
bool TextureManager::createSamplerStates(const DeviceManager& deviceManager)
{
    //Setup sampler state here
    D3D11_SAMPLER_DESC samplerStateDesc;
    samplerStateDesc.Filter = D3D11_FILTER_ANISOTROPIC;
    samplerStateDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
    samplerStateDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
    samplerStateDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
    samplerStateDesc.MipLODBias = 0.0f;
    samplerStateDesc.MaxAnisotropy = 16;
    samplerStateDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
    samplerStateDesc.BorderColor[0] = 0.0f;
    samplerStateDesc.BorderColor[1] = 0.0f;
    samplerStateDesc.BorderColor[2] = 0.0f;
    samplerStateDesc.BorderColor[3] = 0.0f;
    samplerStateDesc.MinLOD = -3.402823466e+38F;
    samplerStateDesc.MaxLOD = 3.402823466e+38F;
    ID3D11Device* device = deviceManager.getDevice();
    HRESULT hr = device->CreateSamplerState(&samplerStateDesc, &m_samplerState);
    if (FAILED( hr ) )
    {
        MSG_TRACE_CHANNEL("TEXTUREMANAGER", "Failed to create sampler state: 0x%x", hr )
        return false;
    }

    return true;
}
Example #3
0
//-----------------------------------------------------------------------------
//! @brief   TODO enter a description
//! @remark
//-----------------------------------------------------------------------------
bool VertexBuffer::createVertexInputLayout( const DeviceManager& deviceManager, ID3DBlob* vertexShaderCodeBlob, const std::vector<D3D11_INPUT_ELEMENT_DESC>& inputElements )
{
    HRESULT hr = deviceManager.getDevice()->CreateInputLayout(&inputElements[0], (unsigned int)inputElements.size(), vertexShaderCodeBlob->GetBufferPointer(), vertexShaderCodeBlob->GetBufferSize(), &m_inputLayout );

    if (FAILED( hr ) )
    {        
        MSG_TRACE_CHANNEL("VERTEXBUFFER", "Failed to create the input layout: 0x%x", hr )
            return false;
    }

    return true;
}
Example #4
0
void IndexBuffer::createBuffer( const DeviceManager& deviceManager, unsigned int bufferSize, void* data, bool dynamic, unsigned int bindFlag )
{
    D3D11_BUFFER_DESC bufferDescriptor;
    ZeroMemory(&bufferDescriptor, sizeof(D3D11_BUFFER_DESC));
    bufferDescriptor.Usage = D3D11_USAGE_IMMUTABLE;
    bufferDescriptor.ByteWidth = bufferSize;
    bufferDescriptor.BindFlags = bindFlag;
    bufferDescriptor.CPUAccessFlags = 0;
    bufferDescriptor.MiscFlags = 0;

    D3D11_SUBRESOURCE_DATA initData;
    ZeroMemory(&initData, sizeof(D3D11_SUBRESOURCE_DATA));
    initData.pSysMem = data;
    initData.SysMemPitch = 0;
    initData.SysMemSlicePitch = 0;

    HRESULT hr = deviceManager.getDevice()->CreateBuffer( &bufferDescriptor, &initData, &m_buffer );
    if (FAILED(hr))
    {
        MSG_TRACE_CHANNEL("INDEXBUFFER", "Failed to create a D3D11 Buffer object with code: 0x%x", hr );
    }

    dynamic = false;
}
Example #5
0
//-----------------------------------------------------------------------------
int main( int argc, char* argv[])
//-----------------------------------------------------------------------------
{
	const char* pDevSerial = "BF*";

	cout << "\n ++ Start PowerDownTest sample: " << __DATE__ << "/" << __TIME__ << endl;

	if( argc > 1 )
	{
		pDevSerial = argv[1];
	}

	unsigned int uiDevCount = 0;
	DeviceManager DevMgr;
	if( ( uiDevCount = DevMgr.deviceCount() ) == 0 )
	{
		cout << "*** Error: No MATRIX VISION device found! Unable to continue!" << endl;
		return 0;
	}

	cout << "Have found " << uiDevCount << " devices on this platform!" << endl;

	for( unsigned i=0; i<uiDevCount; i++ )
	{
		Device* pDevTmp = DevMgr.getDevice( i );
		cout << " " << i << " Serial: " << pDevTmp->serial.read() << endl;
	}

	cout << "Initialising the device: "<< pDevSerial << ". This might take some time..." << endl;
	// create an interface to the first MATRIX VISION device with the serila number pDevSerial
	Device* pDev = DevMgr.getDeviceBySerial( pDevSerial );

	try
	{
		pDev->open();
	}
	catch( ImpactAcquireException& e )
	{
		// this e.g. might happen if the same device is already opened in another process...
		cout << "*** Error: An error occurred while opening the device(error code: " << e.getErrorCode() << ")." << endl;
		return 0;
	}

	FunctionInterface fi( pDev );

	// only 8Bit/pixel destination image are supported by the \c writeFile() function
	ImageDestination imgDst( pDev );
	imgDst.pixelFormat.write( idpfMono8 );

	// get mvBF system settings
	SystemBlueFOX sbf( pDev );

	bool bPowerDown = false;
	do
	{
		cout << "Ready to snap. Press 'p'<return> to power down, 'q'<return> to quit or <return> to snap an image.." << endl;
		char ch = getchar();

		if( ch == 'p' )
		{	// for mvBlueFOX only: test power down / up
			cout << "Power off!" << endl;
			sbf.powerMode.write( dpmOff );
			bPowerDown = true;
			// read and discard the <return> 
			getchar();
		}
		else if( ch == 'q' )
		{	// break out of loop to finish application
			// read and discard the <return> 
			getchar();
			break;
		}
		else
		{	// snap
			if( bPowerDown )
			{	// first we need to power up again
				CTime timer1;
				sbf.powerMode.write( dpmOn );
				bPowerDown = false;
				cout << "Power On!" << ". Power On took " << timer1.elapsed() << "s., " << endl;
			}

			CTime timer;

			// send a request to the default request queue of the device and wait for the result.
			fi.imageRequestSingle();
			const int iMaxWaitTime_ms = 5000;

			// wait for results from the default capture queue
			int iRequestNr = fi.imageRequestWaitFor( iMaxWaitTime_ms );

			cout << "Request Nr.: " << iRequestNr << ". Snap took " << timer.elapsed() << "s., " << endl;
			// check if the image has been captured without any problems
			if( !fi.isRequestNrValid( iRequestNr ) )
			{
				// this can not happen in this sample, but may happen if you wait for a request without
				// sending one to the driver before
				cout << "*** Error: No request has been sent to the driver." << endl;
				// unlock the buffer to let the driver know that you no longer need this buffer
				fi.imageRequestUnlock( iRequestNr );
				// free resources
				fi.imageRequestReset( 0, 0 );
				pDev->close();
				return 0;
			}

			const Request* psRequest = fi.getRequest(iRequestNr);
			if( !fi.isRequestOK( psRequest ) )
			{
				cout << "*** " << psRequest->requestResult << endl;
				// unlock the buffer to let the driver know that you no longer need this buffer
				fi.imageRequestUnlock( iRequestNr );
				// free resources
				fi.imageRequestReset( 0, 0 );
				pDev->close();
				return 0;
			}

			// Everything went well. Save the result
			const char* pImageName = "SingCapt.pgm";
			cout << "Will save the file as:  " << pImageName << endl;
			if( writeFile( (const unsigned char*)psRequest->imageData.read(), psRequest->imageWidth.read(), psRequest->imageHeight.read(),
						psRequest->imageLinePitch.read(), psRequest->imagePixelPitch.read(), pImageName ) < 0 )
				cout << "*** Error: File: "<< pImageName << " could not be saved!!" << endl;

			// unlock the buffer to let the driver know that you no longer need this buffer
			fi.imageRequestUnlock( iRequestNr );
		} // snap

	} while( true );

	// free resources
	fi.imageRequestReset( 0, 0 );

	pDev->close();

	return 0;
}