Example #1
0
Directx::TShader::TShader(const std::string& vertexSrc,const std::string& fragmentSrc,const SoyGraphics::TGeometryVertex& Vertex,const std::string& ShaderName,const std::map<std::string,std::string>& Macros,TContext& Context) :
	mBoundContext	( nullptr )
{
	auto& Device = Context.LockGetDevice();
	auto& Compiler = Context.GetCompiler();

	try
	{
		Array<uint8> VertBlob;
		Array<uint8> FragBlob;
		Compiler.Compile( GetArrayBridge(VertBlob), vertexSrc, "Vert", "vs_5_0", ShaderName + " vert shader", Macros );
		Compiler.Compile( GetArrayBridge(FragBlob), fragmentSrc, "Frag", "ps_5_0", ShaderName + " frag shader", Macros );
	
		auto Result = Device.CreateVertexShader( VertBlob.GetArray(), VertBlob.GetDataSize(), nullptr, &mVertexShader.mObject );
		Directx::IsOkay( Result, "CreateVertexShader" );

		Result = Device.CreatePixelShader( FragBlob.GetArray(), FragBlob.GetDataSize(), nullptr, &mPixelShader.mObject );
		Directx::IsOkay( Result, "CreatePixelShader" );

		MakeLayout( Vertex, GetArrayBridge(VertBlob), ShaderName, Device );
		Context.Unlock();
	}
	catch(std::exception& e)
	{
		Context.Unlock();
		throw;
	}
}
Example #2
0
Directx::TGeometry::TGeometry(const ArrayBridge<uint8>&& Data,const ArrayBridge<size_t>&& _Indexes,const SoyGraphics::TGeometryVertex& Vertex,TContext& ContextDx) :
	mVertexDescription	( Vertex ),
	mIndexCount			( 0 )
{
	Array<uint32> Indexes;
	for ( int i=0;	i<_Indexes.GetSize();	i++ )
		Indexes.PushBack( size_cast<uint32>( _Indexes[i] ) );


	// Set up the description of the static vertex buffer.
	D3D11_BUFFER_DESC vertexBufferDesc;
	vertexBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
	vertexBufferDesc.ByteWidth = Data.GetDataSize();//Vertex.GetDataSize();
	vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	vertexBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
	vertexBufferDesc.MiscFlags = 0;
	vertexBufferDesc.StructureByteStride = Vertex.GetStride(0);	//	should be 0

	// Give the subresource structure a pointer to the vertex data.
	D3D11_SUBRESOURCE_DATA vertexData;
	vertexData.pSysMem = Data.GetArray();
	vertexData.SysMemPitch = 0;
	vertexData.SysMemSlicePitch = 0;

	// Set up the description of the static index buffer.
	D3D11_BUFFER_DESC indexBufferDesc;

	indexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
	indexBufferDesc.ByteWidth = Indexes.GetDataSize();
	indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
	indexBufferDesc.CPUAccessFlags = 0;
	indexBufferDesc.MiscFlags = 0;
	indexBufferDesc.StructureByteStride = 0;

	// Give the subresource structure a pointer to the index data.
	D3D11_SUBRESOURCE_DATA indexData;
	indexData.pSysMem = Indexes.GetArray();
	indexData.SysMemPitch = 0;
	indexData.SysMemSlicePitch = 0;


	auto& Device = ContextDx.LockGetDevice();
	try
	{
		auto Result = Device.CreateBuffer(&vertexBufferDesc, &vertexData, &mVertexBuffer.mObject );
		Directx::IsOkay( Result, "Create vertex buffer");

		Result = Device.CreateBuffer(&indexBufferDesc, &indexData, &mIndexBuffer.mObject );
		Directx::IsOkay( Result, "Create index buffer");
		mIndexCount = Indexes.GetSize();
		mIndexFormat = DXGI_FORMAT_R32_UINT;
	}
	catch( std::exception& e)
	{
		ContextDx.Unlock();
		throw;
	}
}
bool TProtocolPokey::Encode(const TJob& Job,Array<char>& Output)
{
	//	job to command id
	auto Command = TPokeyCommand::ToType( Job.mParams.mCommand );
	
	unsigned char tempOut[64-8];	//	gr: was 64, but their code NEVER uses more than 56 (64-8)
	unsigned char data2,data3,data4,data5;
	
	switch ( Command )
	{
		case TPokeyCommand::GetDeviceMeta:
		case TPokeyCommand::GetDeviceState:
			data2 = 0;
			data3 = 0;
			data4 = 0;
			data5 = 0;
			break;
			
			//	special case where we send zero bytes
		case TPokeyCommand::Discover:
			Output.PushBack(0xff);
			//Soy::Assert( Output.GetDataSize() == 0, "should send zero bytes for discovery");
			return true;
			
		default:
			return false;
	};
	
	auto RequestId = mRequestCounter++;
	unsigned char Header[8];
	
	Header[0] = 0xBB;
	Header[1] = Command;
	Header[2] = data2;
	Header[3] = data3;
	Header[4] = data4;
	Header[5] = data5;
	Header[6] = RequestId;
	Header[7] = TPokeyCommand::CalculateChecksum(Header);
	
	Output.PushBackArray( GetRemoteArray( reinterpret_cast<const char*>(Header), sizeofarray(Header) ) );
	Output.PushBackArray( GetRemoteArray( reinterpret_cast<const char*>(tempOut), sizeofarray(tempOut) ) );
	
	if ( !Soy::Assert( Output.GetDataSize()==64, "Always send 64 bytes" ) )
		return false;
	
	/*
	 
		// Wait for the response
		while(1)
		{
	 result = recv(comSocket, (char *)rxBuffer, 64, 0);
	 
	 // 64 bytes received?
	 if (result == 64)
	 {
	 if (rxBuffer[0] == 0xAA && rxBuffer[6] == RequestID)
	 {
	 if (rxBuffer[7] == CalculateChecksum(rxBuffer))
	 {
	 memcpy(Response, rxBuffer, 64);
	 return 0;
	 }
	 }
	 }
	 else if (result == 0)
	 printf("Connection closed\n");
	 else
	 printf("recv failed: %d\n", WSAGetLastError());
	 
	 
	 if (++retries1 > 10) break;
		}
		
		if (retries2++ > 3) break;
	 }
	 
	 return -1;
	 
	 
	 // Get serial number and versions
	 if (SendRequest(0x00, 0, 0, 0, 0, tempOut, tempIn) != 0) return -1;
	 deviceStat->DeviceData.SerialNumber = (int)(tempIn[2]) * 256 + (int)tempIn[3];
	 deviceStat->DeviceData.FirmwareVersionMajor = tempIn[4];
	 deviceStat->DeviceData.FirmwareVersionMinor = tempIn[5];
	 */
	return true;
}
TDecodeResult::Type TProtocolPokey::DecodeHeader(TJob& Job,TChannelStream& Stream)
{
	//	read the first byte, if it's 0xAA we know it's a reply packet
	//	if it's not, we have to assume it's a broadcast reply with an IP...
	Array<char> Data;
	auto DataBridge = GetArrayBridge(Data);
	if ( !Stream.Pop( 1, DataBridge ) )
		return TDecodeResult::Waiting;
	
	if ( static_cast<unsigned char>(Data[0]) == 0xAA )
	{
		if ( !Stream.Pop( 64-1, DataBridge ) )
		{
			Stream.UnPop(DataBridge);
			return TDecodeResult::Waiting;
		}
		
		BufferArray<unsigned char,64> UData;
		GetArrayBridge(UData).PushBackReinterpret( Data.GetArray(), Data.GetDataSize() );
		
		if ( !DecodeReply( Job, UData ) )
			return TDecodeResult::Ignore;
		
		return TDecodeResult::Success;
	}
	else
	{
		//	old protocol size 14
		//	new protocol size 19
		//	assume is broadcast reply
		if ( !Stream.Pop( 14-1, DataBridge ) )
		{
			Stream.UnPop(DataBridge);
			return TDecodeResult::Waiting;
		}

		//	gr: not sure why but have to use some data as signed and some as unsigned... not making sense to me, maybe encoding done wrong on pokey side
		BufferArray<unsigned char, 100> UData;
		GetArrayBridge(UData).PushBackReinterpret(Data.GetArray(), Data.GetDataSize());

		std::stringstream Version;
		Version << (int)UData[3] << "." << (int)UData[4];

		//	if new protocol
		bool Protocol4913 = Version.str() == "49.13";
		bool Protocol3352 = Version.str() == "33.52";
		bool Protocol4800 = Version.str() == "48.0";

		//	same protocol as newer
		Protocol4913 |= Protocol4800;

		if ( Protocol4913 )
		{
			if ( !Stream.Pop(5, DataBridge) )
			{
				Stream.UnPop(DataBridge);
				return TDecodeResult::Waiting;
			}
			UData.Clear();
			GetArrayBridge(UData).PushBackReinterpret(Data.GetArray(), Data.GetDataSize());
		}
		else if ( Protocol3352 )
		{
			
		}
		else
		{
			std::Debug << "unknown pokey protocol " << Version.str() << std::endl;
			return TDecodeResult::Ignore;
		}
		
		int Serial = 0;
		if ( Protocol4913 )
		{
			Serial = ( (int)UData[15] << 8 ) | (int)UData[14];
		}
		else if ( Protocol3352 )
		{
			Serial = ( (int)UData[1] << 8 ) | (int)UData[2];
		}

		
		std::stringstream Address;
		Address << (int)UData[5] << "." << (int)UData[6] << "." << (int)UData[7] << "." << (int)UData[8];
		Address << ":20055";
		
		std::stringstream HostAddress;
		HostAddress << (int)UData[10] << "." << (int)UData[11] << "." << (int)UData[12] << "." << (int)UData[13];
		
		Job.mParams.mCommand = TJobParams::CommandReplyPrefix + TPokeyCommand::ToString( TPokeyCommand::Discover );
		Job.mParams.AddParam("userid", static_cast<int>(UData[0]) );
		Job.mParams.AddParam("version", Version.str() );
		Job.mParams.AddParam("serial", Serial );
		Job.mParams.AddParam("dhcpenabled", static_cast<int>(UData[9]) );
		Job.mParams.AddParam("address", Address.str() );
		Job.mParams.AddParam("hostaddress", HostAddress.str() );
		return TDecodeResult::Success;
	}
}