void RenderContext::Init(XCShaderContainer* shaderMgr)
{
    m_clearColor = XCVec4(1.0f, 1.0f, 1.0f, 1.0f);

    m_shaderContainer = shaderMgr;

    m_graphicsSystem = &SystemLocator::GetInstance()->RequestSystem<XCGraphics>("GraphicsSystem");
    ID3DDevice* device = m_graphicsSystem->GetDevice();

#if defined(USE_IMMEDIATE_CONTEXT)
    m_deviceContext = m_graphicsSystem->GetDeviceContext();
#else
    #if defined(XCGRAPHICS_DX12)
        ValidateResult(device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&m_commandAllocator)));
    
        ValidateResult(device->CreateCommandList(
            0,
            D3D12_COMMAND_LIST_TYPE_DIRECT,
            m_commandAllocator,
            m_shaderContainer->GetShader(ShaderType_SolidColor)->GetPso().m_psos[RasterType_FillSolid].m_pPso,
            IID_PPV_ARGS(&m_deviceContext)));
    
        ValidateResult(m_deviceContext->Close());
    #elif defined(XCGRAPHICS_DX11)
        device->CreateDeferredContext(0, &m_deviceContext);
    #endif
#endif

}
void RenderContext::Reset()
{
#if defined(XCGRAPHICS_DX12)

    ValidateResult(m_commandAllocator->Reset());
    ValidateResult(m_deviceContext->Reset(m_commandAllocator, m_graphicsSystem->GetPipelineState()));
#elif defined(XCGRAPHICS_DX11)
    m_deviceContext->ClearState();
#endif
}
void XCShaderContainer::LoadSamplers()
{
#if defined(XCGRAPHICS_DX11)
    m_samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
    m_samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
    m_samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
    m_samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
    m_samplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
    m_samplerDesc.MinLOD = 0;
    m_samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;

    ValidateResult(m_device.CreateSamplerState(&m_samplerDesc, &m_SamplerLinear));
#elif defined(XCGRAPHICS_DX12)

    m_samplerDesc.Filter = D3D12_FILTER_MIN_MAG_MIP_LINEAR;
    m_samplerDesc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
    m_samplerDesc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
    m_samplerDesc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
    m_samplerDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_NEVER;
    m_samplerDesc.MinLOD = 0;
    m_samplerDesc.MaxLOD = D3D12_FLOAT32_MAX;

    SharedDescriptorHeap& heap = (SharedDescriptorHeap&)SystemLocator::GetInstance()->RequestSystem("SharedDescriptorHeap");
    m_device.CreateSampler(&m_samplerDesc, heap.GetDescriptorHeap(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER).m_heapDesc->GetCPUDescriptorHandleForHeapStart());
#endif
}
void RenderContext::FinishRender()
{
#if defined(USE_IMMEDIATE_CONTEXT)

#else
    #if defined(XCGRAPHICS_DX12)
        //Cmdlist Close can happen here when in multiple render context.
        ValidateResult(m_deviceContext->Close());
    #elif defined(XCGRAPHICS_DX11)
        ID3DCommandList* commandList;
        m_deviceContext->FinishCommandList(false, &commandList);

        //Execute on main device context
        m_graphicsSystem->GetDeviceContext()->ExecuteCommandList(commandList, true);
        ReleaseCOM(commandList);

        m_shaderContainer->ClearShaderAndRenderStates(*m_deviceContext);
    #endif
#endif
}
Exemple #5
0
void AudioSystem::Update(float deltaSeconds) {
	FMOD_RESULT result = m_fmodSystem->update();
	ValidateResult(result);
}
Exemple #6
0
//---------------------------------------------------------------------------
// FMOD startup code based on "GETTING STARTED With FMOD Ex Programmer’s API for Windows" document
//	from the FMOD programming API at http://www.fmod.org/download/
//
void AudioSystem::InitializeFMOD() {
	const int MAX_AUDIO_DEVICE_NAME_LEN = 256;
	FMOD_RESULT result;
	unsigned int fmodVersion;
	int numDrivers;
	FMOD_SPEAKERMODE speakerMode;
	FMOD_CAPS deviceCapabilities;
	char audioDeviceName[MAX_AUDIO_DEVICE_NAME_LEN];

	// Create a System object and initialize.
	result = FMOD::System_Create(&m_fmodSystem);
	ValidateResult(result);

	result = m_fmodSystem->getVersion(&fmodVersion);
	ValidateResult(result);

	if (fmodVersion < FMOD_VERSION)
		DebuggerPrintf("AUDIO SYSTEM ERROR!  Your FMOD .dll is of an older version (0x%08x == %d) than that the .lib used to compile this code (0x%08x == %d).\n", fmodVersion, fmodVersion, FMOD_VERSION, FMOD_VERSION);

	result = m_fmodSystem->getNumDrivers(&numDrivers);
	ValidateResult(result);

	if (numDrivers == 0) {
		result = m_fmodSystem->setOutput(FMOD_OUTPUTTYPE_NOSOUND);
		ValidateResult(result);
	}
	else {
		result = m_fmodSystem->getDriverCaps(0, &deviceCapabilities, 0, &speakerMode);
		ValidateResult(result);

		// Set the user selected speaker mode.
		result = m_fmodSystem->setSpeakerMode(speakerMode);
		ValidateResult(result);

		if (deviceCapabilities & FMOD_CAPS_HARDWARE_EMULATED) {
			// The user has the 'Acceleration' slider set to off! This is really bad
			// for latency! You might want to warn the user about this.
			result = m_fmodSystem->setDSPBufferSize(1024, 10);
			ValidateResult(result);
		}

		result = m_fmodSystem->getDriverInfo(0, audioDeviceName, MAX_AUDIO_DEVICE_NAME_LEN, 0);
		ValidateResult(result);

		if (strstr(audioDeviceName, "SigmaTel")) {
			// Sigmatel sound devices crackle for some reason if the format is PCM 16bit.
			// PCM floating point output seems to solve it.
			result = m_fmodSystem->setSoftwareFormat(48000, FMOD_SOUND_FORMAT_PCMFLOAT, 0, 0, FMOD_DSP_RESAMPLER_LINEAR);
			ValidateResult(result);
		}
	}

	result = m_fmodSystem->init(100, FMOD_INIT_NORMAL, 0);
	if (result == FMOD_ERR_OUTPUT_CREATEBUFFER) {
		// Ok, the speaker mode selected isn't supported by this sound card. Switch it
		// back to stereo...
		result = m_fmodSystem->setSpeakerMode(FMOD_SPEAKERMODE_STEREO);
		ValidateResult(result);

		// ... and re-init.
		result = m_fmodSystem->init(100, FMOD_INIT_NORMAL, 0);
		ValidateResult(result);
	}
}
void CubeMesh::BuildBuffers()
{
#if defined(DEBUG_OBB)
    if (!m_isBufferBuild)
    {
        XCGraphics& graphicsSystem = (XCGraphics&)SystemLocator::GetInstance()->RequestSystem("GraphicsSystem");

        //Set up vertices
        m_vertexBuffer.m_vertexData.push_back(VertexPosNormTex(XCVec3(-1.0f, -1.0f, -1.0f), XCVec3(-0.33f, -0.33f, -0.33f), XCVec2(0.0f, 1.0f)));
        m_vertexBuffer.m_vertexData.push_back(VertexPosNormTex(XCVec3(-1.0f, 1.0f, -1.0f), XCVec3(-0.33f, 0.33f, -0.33f), XCVec2(0.0f, 0.0f)));
        m_vertexBuffer.m_vertexData.push_back(VertexPosNormTex(XCVec3(1.0f, 1.0f, -1.0f), XCVec3(0.33f, 0.33f, -0.33f), XCVec2(1.0f, 0.0f)));
        m_vertexBuffer.m_vertexData.push_back(VertexPosNormTex(XCVec3(1.0f, -1.0f, -1.0f), XCVec3(0.33f, -0.33f, -0.33f), XCVec2(1.0f, 1.0f)));
        m_vertexBuffer.m_vertexData.push_back(VertexPosNormTex(XCVec3(-1.0f, -1.0f, 1.0f), XCVec3(-0.33f, -0.33f, 0.33f), XCVec2(0.0f, 1.0f)));
        m_vertexBuffer.m_vertexData.push_back(VertexPosNormTex(XCVec3(-1.0f, 1.0f, 1.0f), XCVec3(-0.33f, 0.33f, 0.33f), XCVec2(0.0f, 0.0f)));
        m_vertexBuffer.m_vertexData.push_back(VertexPosNormTex(XCVec3(1.0f, 1.0f, 1.0f), XCVec3(0.33f, 0.33f, 0.33f), XCVec2(1.0f, 0.0f)));
        m_vertexBuffer.m_vertexData.push_back(VertexPosNormTex(XCVec3(1.0f, -1.0f, 1.0f), XCVec3(0.33f, -0.33f, 0.33f), XCVec2(1.0f, 1.0f)));
         
        /*
        m_vertexBuffer.m_vertexData.push_back(VertexPosColor(XMFLOAT3(-1.0f, -1.0f, -1.0f), Colors::White));
        m_vertexBuffer.m_vertexData.push_back(VertexPosColor(XMFLOAT3(-1.0f, 1.0f, -1.0f), Colors::Black));
        m_vertexBuffer.m_vertexData.push_back(VertexPosColor(XMFLOAT3(1.0f, 1.0f, -1.0f), Colors::Red));
        m_vertexBuffer.m_vertexData.push_back(VertexPosColor(XMFLOAT3(1.0f, -1.0f, -1.0f), Colors::Green));
        m_vertexBuffer.m_vertexData.push_back(VertexPosColor(XMFLOAT3(-1.0f, -1.0f, 1.0f), Colors::Blue));
        m_vertexBuffer.m_vertexData.push_back(VertexPosColor(XMFLOAT3(-1.0f, 1.0f, 1.0f), Colors::Yellow));
        m_vertexBuffer.m_vertexData.push_back(VertexPosColor(XMFLOAT3(1.0f, 1.0f, 1.0f), Colors::Cyan));
        m_vertexBuffer.m_vertexData.push_back(VertexPosColor(XMFLOAT3(1.0f, -1.0f, 1.0f), Colors::Magenta));
        */
        m_vertexBuffer.BuildVertexBuffer();

        m_Stride = sizeof(VertexPosNormTex);
        m_Offset = 0;

        //Set up index buffer
        m_indexBuffer.AddIndicesVA
        ({   0, 1, 2,
            0, 2, 3,

            4, 6, 5,
            4, 7, 6,

            4, 5, 1,
            4, 1, 0,

            3, 2, 6,
            3, 6, 7,

            1, 5, 6,
            1, 6, 2,

            4, 0, 3,
            4, 3, 7 });

        m_indexBuffer.BuildIndexBuffer();

#if !defined(XCGRAPHICS_DX12)
        D3D11_BUFFER_DESC ibd;
        ibd.Usage = D3D11_USAGE_IMMUTABLE;
        ibd.ByteWidth = sizeof(indices);
        ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
        ibd.CPUAccessFlags = 0;
        ibd.MiscFlags = 0;
        //ibd.StructureByteStride = 0;
        ibd.StructureByteStride = sizeof(WORD);

        D3D11_SUBRESOURCE_DATA iInitData;
        iInitData.pSysMem = indices;
        iInitData.SysMemPitch = 0;
        iInitData.SysMemSlicePitch = 0;

        ValidateResult(graphicsSystem.GetDevice()->CreateBuffer(&ibd, &iInitData, &m_pIB));
        XCASSERT(m_pIB);
#endif
        m_isBufferBuild = true;
    }
#endif
}