CDx11UmbralEffect::CDx11UmbralEffect(ID3D11Device* device, ID3D11DeviceContext* deviceContext,
	const CD3DShader& vertexShader, const CD3DShader& pixelShader, bool hasAlphaTest)
: CDx11Effect(device, deviceContext)
, m_vertexShader(vertexShader)
, m_pixelShader(pixelShader)
, m_hasAlphaTest(hasAlphaTest)
{
	auto vertexShaderText = CDx11UmbralEffectGenerator::GenerateVertexShader(m_vertexShader);
	auto pixelShaderText = CDx11UmbralEffectGenerator::GeneratePixelShader(m_vertexShader, m_pixelShader, hasAlphaTest);

	CompileVertexShader(vertexShaderText);
	CompilePixelShader(pixelShaderText);

	{
		auto vertexShaderConstantTable = vertexShader.GetConstantTable();
		OffsetKeeper constantOffset;
		ParseVertexShaderConstantTable(constantOffset, vertexShaderConstantTable, CD3DShaderConstantTable::REGISTER_SET_FLOAT4);
		ParseVertexShaderConstantTable(constantOffset, vertexShaderConstantTable, CD3DShaderConstantTable::REGISTER_SET_BOOL);
		CreateVertexConstantBuffer(constantOffset.currentOffset);
	}

	{
		auto pixelShaderConstantTable = pixelShader.GetConstantTable();
		OffsetKeeper constantOffset;
		ParsePixelShaderConstantTable(constantOffset, pixelShaderConstantTable, CD3DShaderConstantTable::REGISTER_SET_FLOAT4);
		CreatePixelConstantBuffer(constantOffset.currentOffset);
	}
}
示例#2
0
ID3D11VertexShader* CompileAndCreateVertexShader(const std::string& code)
{
    D3DBlob* blob = nullptr;
    if (CompileVertexShader(code, &blob))
    {
        ID3D11VertexShader* v_shader = CreateVertexShaderFromByteCode(blob);
        blob->Release();
        return v_shader;
    }
    return nullptr;
}
GLuint BuildShaderProgram(const std::string& vsPath, const std::string& fsPath)
{
    // load and compile vertex shader
    GLuint vs = CompileVertexShader(vsPath);
    if (!vs)
        return GL_NONE;

    // load and compile fragment shader
    GLuint fs = CompileFragmentShader(fsPath);
    if (!fs) {
        glDeleteShader(vs);   // cleanup
        return GL_NONE;
    }

    // create shader program object
    GLuint prog = glCreateProgram();
    if (!prog) {
        std::cerr << "*** Poop: Failed to create program object" << std::endl;
        glDeleteShader(vs);
        glDeleteShader(fs);
        return GL_NONE;
    }

    // attach vertex and fragment shaders to the program object
    glAttachShader(prog, vs);
    glAttachShader(prog, fs);

    // link program
    glLinkProgram(prog);

    // shader objects no longer needed once program is linked
    glDeleteShader(vs);
    glDeleteShader(fs);

    // check link status
    GLint linkStatus;
    glGetProgramiv(prog, GL_LINK_STATUS, &linkStatus);
    if (!linkStatus) {
        std::cerr << "*** Poop: Failed to vertex shader " << vsPath << " with fragment shader " << fsPath << std::endl;
        glDeleteProgram(prog);
        return GL_NONE;
    }

    // check for GL errors
    GLenum err = glGetError();
    if (err != GL_NO_ERROR) {
        std::cout << "*** Poop: GL Error in function " __FUNCTION__ " on line " << __LINE__ << ": " << gluErrorString(err) << std::endl;
        glDeleteProgram(prog);
        return GL_NONE;
    }

    // return program id
    return prog;
}
示例#4
0
ID3D11VertexShader* CompileAndCreateVertexShader(const char* code,
	unsigned int len)
{
	D3DBlob* blob = NULL;
	if (CompileVertexShader(code, len, &blob))
	{
		ID3D11VertexShader* v_shader = CreateVertexShaderFromByteCode(blob);
		blob->Release();
		return v_shader;
	}
	return NULL;
}
示例#5
0
ID3D11VertexShader* CompileAndCreateVertexShader(const char* code,
	unsigned int len)
{
	D3DBlob* blob = NULL;
	if (CompileVertexShader(code, len, &blob))
	{
		ID3D11VertexShader* v_shader = CreateVertexShaderFromByteCode(blob);
		blob->Release();
		return v_shader;
	}
	PanicAlert("Failed to compile and create vertex shader from %p (size %d) at %s %d\n", code, len, __FILE__, __LINE__);
	return NULL;
}
示例#6
0
void CompileShaders() {
	std::string errorMsg;
	HRESULT hr = -1;

	if (!CompileVertexShader(vscode, &pFramebufferVertexShader, NULL, errorMsg)) {
		OutputDebugStringA(errorMsg.c_str());
		DebugBreak();
	}

	if (!CompilePixelShader(pscode, &pFramebufferPixelShader, NULL, errorMsg)) {
		OutputDebugStringA(errorMsg.c_str());
		DebugBreak();
	}

	pD3Ddevice->CreateVertexDeclaration(VertexElements, &pFramebufferVertexDecl);
	pD3Ddevice->SetVertexDeclaration(pFramebufferVertexDecl);
	pD3Ddevice->CreateVertexDeclaration(SoftTransVertexElements, &pSoftVertexDecl);
}
示例#7
0
bool CompileShaders(std::string &errorMsg) {
	if (!CompileVertexShader(vscode, &pFramebufferVertexShader, NULL, errorMsg)) {
		OutputDebugStringA(errorMsg.c_str());
		return false;
	}

	if (!CompilePixelShader(pscode, &pFramebufferPixelShader, NULL, errorMsg)) {
		OutputDebugStringA(errorMsg.c_str());
		if (pFramebufferVertexShader) {
			pFramebufferVertexShader->Release();
		}
		return false;
	}

	pD3Ddevice->CreateVertexDeclaration(VertexElements, &pFramebufferVertexDecl);
	pD3Ddevice->SetVertexDeclaration(pFramebufferVertexDecl);
	pD3Ddevice->CreateVertexDeclaration(SoftTransVertexElements, &pSoftVertexDecl);

	return true;
}
	i32	CCGShaderSystem::CompileVertexShader(Resources::IVertexShader* pVS)
	{
		return CompileVertexShader( (lpcastr)pVS->GetResourceFile().GetPtr()->GetData().GetPointer(), 0, pVS );
	}
//--------------------------------------------------------------------------------------
// Create any D3D11 resources that aren't dependant on the back buffer
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D11CreateDevice( ID3D11Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc,
                                     void* pUserContext )
{
    DXUT_SetDebugName( pd3dDevice, "Main Device" );

    HRESULT hr;

    ID3D11DeviceContext* pd3dImmediateContext = DXUTGetD3D11DeviceContext();
    V_RETURN( g_DialogResourceManager.OnD3D11CreateDevice( pd3dDevice, pd3dImmediateContext ) );
    V_RETURN( g_SettingsDlg.OnD3D11CreateDevice( pd3dDevice ) );
    g_pTxtHelper = new CDXUTTextHelper( pd3dDevice, pd3dImmediateContext, &g_DialogResourceManager, 15 );

    IDXGIDevice* pDXGIDevice;
    hr = pd3dDevice->QueryInterface( __uuidof(IDXGIDevice), (VOID**)&pDXGIDevice );
    if( SUCCEEDED(hr) )
    {
        IDXGIAdapter* pAdapter;
        hr = pDXGIDevice->GetAdapter( &pAdapter );
        if( SUCCEEDED(hr) )
        {
            DXGI_ADAPTER_DESC AdapterDesc;
            pAdapter->GetDesc( &AdapterDesc );
            SetAdapterInfoForShaderCompilation( AdapterDesc.Description );
            SAFE_RELEASE( pAdapter );
        }
        SAFE_RELEASE( pDXGIDevice );
    }

    ID3D10Blob* pVSBlob = NULL;
    g_pVSTransform = CompileVertexShader( pd3dDevice, L"SceneRender.hlsl", "VSTransform", &pVSBlob );
    g_pPSSceneRender = CompilePixelShader( pd3dDevice, L"SceneRender.hlsl", "PSSceneRender" );
    g_pPSSceneRenderArray = CompilePixelShader( pd3dDevice, L"SceneRender.hlsl", "PSSceneRenderArray" );
    g_pPSSceneRenderQuilt = CompilePixelShader( pd3dDevice, L"SceneRender.hlsl", "PSSceneRenderQuilt" );

    // Create a layout for the object data
    const D3D11_INPUT_ELEMENT_DESC layout[] =
    {
        { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0,  0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
        { "TEXCOORD", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
    };

    V_RETURN( pd3dDevice->CreateInputLayout( layout, ARRAYSIZE( layout ), pVSBlob->GetBufferPointer(),
                                             pVSBlob->GetBufferSize(), &g_pDefaultInputLayout ) );

    // No longer need the shader blobs
    SAFE_RELEASE( pVSBlob );

    // Create state objects
    D3D11_SAMPLER_DESC samDesc;
    ZeroMemory( &samDesc, sizeof(samDesc) );
    samDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
    samDesc.AddressU = samDesc.AddressV = samDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
    samDesc.MaxAnisotropy = 1;
    samDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
    samDesc.MaxLOD = D3D11_FLOAT32_MAX;
    V_RETURN( pd3dDevice->CreateSamplerState( &samDesc, &g_pSamLinear ) );
    DXUT_SetDebugName( g_pSamLinear, "Linear" );

    D3D11_BLEND_DESC BlendDesc;
    ZeroMemory( &BlendDesc, sizeof( D3D11_BLEND_DESC ) );
    BlendDesc.RenderTarget[0].BlendEnable = FALSE;
    BlendDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
    BlendDesc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
    BlendDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
    BlendDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
    BlendDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
    BlendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
    BlendDesc.RenderTarget[0].RenderTargetWriteMask = D3D10_COLOR_WRITE_ENABLE_ALL;
    hr = pd3dDevice->CreateBlendState( &BlendDesc, &g_pBlendState );
    ASSERT( SUCCEEDED(hr) );

    D3D11_DEPTH_STENCIL_DESC DSDesc;
    ZeroMemory( &DSDesc, sizeof(D3D11_DEPTH_STENCIL_DESC) );
    DSDesc.DepthEnable = FALSE;
    DSDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
    DSDesc.DepthFunc = D3D11_COMPARISON_LESS;
    DSDesc.StencilEnable = FALSE;
    DSDesc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
    DSDesc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
    hr = pd3dDevice->CreateDepthStencilState( &DSDesc, &g_pDepthStencilState );
    ASSERT( SUCCEEDED(hr) );

    D3D11_RASTERIZER_DESC RSDesc;
    ZeroMemory( &RSDesc, sizeof(RSDesc) );
    RSDesc.AntialiasedLineEnable = FALSE;
    RSDesc.CullMode = D3D11_CULL_BACK;
    RSDesc.DepthBias = 0;
    RSDesc.DepthBiasClamp = 0.0f;
    RSDesc.DepthClipEnable = TRUE;
    RSDesc.FillMode = D3D11_FILL_SOLID;
    RSDesc.FrontCounterClockwise = FALSE;
    RSDesc.MultisampleEnable = TRUE;
    RSDesc.ScissorEnable = FALSE;
    RSDesc.SlopeScaledDepthBias = 0.0f;
    hr = pd3dDevice->CreateRasterizerState( &RSDesc, &g_pRasterizerState );
    ASSERT( SUCCEEDED(hr) );

    g_pcbVSPerObject11 = CreateConstantBuffer( pd3dDevice, sizeof(CB_VS_PER_OBJECT) );
    DXUT_SetDebugName( g_pcbVSPerObject11, "CB_VS_PER_OBJECT" );

    // Create other render resources here
    D3D11_TILED_EMULATION_PARAMETERS EmulationParams;
    EmulationParams.DefaultPhysicalTileFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
    EmulationParams.MaxPhysicalTileCount = 1000;
    D3D11CreateTiledResourceDevice( pd3dDevice, pd3dImmediateContext, &EmulationParams, &g_pd3dDeviceEx );

    g_pd3dDeviceEx->CreateTilePool( &g_pTilePool );

    g_pTitleResidencyManager = new TitleResidencyManager( pd3dDevice, pd3dImmediateContext, 1, EmulationParams.MaxPhysicalTileCount, g_pTilePool );

    ResidencySampleRender::Initialize( pd3dDevice );

    g_PageDebugRender.Initialize( pd3dDevice );

    CreateSceneGeometry( pd3dDevice );

    // Setup the camera's view parameters
    XMMATRIX matProjection = XMMatrixPerspectiveFovLH( XM_PIDIV4, (FLOAT)pBackBufferSurfaceDesc->Width / (FLOAT)pBackBufferSurfaceDesc->Height, 0.001f, 100.0f );
    XMStoreFloat4x4A( &g_matProjection, matProjection );

    UpdateViewMatrix();

    g_pTitleResidencyManager->StartThreads();

    return S_OK;
}