Exemplo n.º 1
0
void TextComponent::DrawTextUI(){

	if (!impl->mModel){
		impl->mModel = gameObject->GetComponent<TextureModelComponent>();
	}

	Game::AddDrawList(DrawStage::UI, [&](){

		if (!impl->mModel)return;
		impl->mModel->SetMatrix();
		Model& model = *impl->mModel->mModel;

		ID3D11DepthStencilState* pBackDS;
		UINT ref;
		Device::mpImmediateContext->OMGetDepthStencilState(&pBackDS, &ref);

		D3D11_DEPTH_STENCIL_DESC descDS = CD3D11_DEPTH_STENCIL_DESC(CD3D11_DEFAULT());
		descDS.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
		//descDS.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
		descDS.DepthFunc = D3D11_COMPARISON_ALWAYS;
		ID3D11DepthStencilState* pDS_tex = NULL;
		Device::mpd3dDevice->CreateDepthStencilState(&descDS, &pDS_tex);
		Device::mpImmediateContext->OMSetDepthStencilState(pDS_tex, 0);

		D3D11_RASTERIZER_DESC descRS = CD3D11_RASTERIZER_DESC(CD3D11_DEFAULT());
		descRS.CullMode = D3D11_CULL_BACK;
		descRS.FillMode = D3D11_FILL_SOLID;

		ID3D11RasterizerState* pRS = NULL;
		Device::mpd3dDevice->CreateRasterizerState(&descRS, &pRS);

		Device::mpImmediateContext->RSSetState(pRS);

		model.Draw(impl->mTexMaterial);

		Device::mpImmediateContext->RSSetState(NULL);
		if (pRS)pRS->Release();

		Device::mpImmediateContext->OMSetDepthStencilState(NULL, 0);
		pDS_tex->Release();

		Device::mpImmediateContext->OMSetDepthStencilState(pBackDS, ref);
		if (pBackDS)pBackDS->Release();
	});
}
Exemplo n.º 2
0
void DeferredRendering::Debug_AlbedoOnly_Rendering(RenderTarget* rt){

	Model::mForcedMaterialUseTexture = NULL;

	rt->SetRendererTarget();

	mModelTexture.Update();

	ID3D11DepthStencilState* pBackDS;
	UINT ref;
	Device::mpImmediateContext->OMGetDepthStencilState(&pBackDS, &ref);

	D3D11_DEPTH_STENCIL_DESC descDS = CD3D11_DEPTH_STENCIL_DESC(CD3D11_DEFAULT());
	descDS.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
	descDS.DepthFunc = D3D11_COMPARISON_ALWAYS;
	ID3D11DepthStencilState* pDS_tex = NULL;
	Device::mpd3dDevice->CreateDepthStencilState(&descDS, &pDS_tex);
	Device::mpImmediateContext->OMSetDepthStencilState(pDS_tex, 0);


	D3D11_RASTERIZER_DESC descRS = CD3D11_RASTERIZER_DESC(CD3D11_DEFAULT());
	descRS.CullMode = D3D11_CULL_NONE;
	descRS.FillMode = D3D11_FILL_SOLID;

	ID3D11RasterizerState* pRS = NULL;
	Device::mpd3dDevice->CreateRasterizerState(&descRS, &pRS);

	Device::mpImmediateContext->RSSetState(pRS);

	mModelTexture.Draw(mMaterialDebugDraw);

	Device::mpImmediateContext->RSSetState(NULL);
	if (pRS)pRS->Release();

	Device::mpImmediateContext->OMSetDepthStencilState(NULL, 0);
	pDS_tex->Release();

	Device::mpImmediateContext->OMSetDepthStencilState(pBackDS, ref);
	if (pBackDS)pBackDS->Release();

	RenderTarget::NullSetRendererTarget();
	mMaterialPostEffect.PSSetShaderResources();
}
Exemplo n.º 3
0
ID3D11RasterizerState* StateCache::Get(RasterizerState state)
{
	auto it = m_raster.find(state.packed);

	if (it != m_raster.end())
		return it->second;

	D3D11_RASTERIZER_DESC rastdc = CD3D11_RASTERIZER_DESC(state.wireframe ? D3D11_FILL_WIREFRAME : D3D11_FILL_SOLID,
		state.cull_mode,
		false, 0, 0.f, 0, true, true, false, false);

	ID3D11RasterizerState* res = nullptr;

	HRESULT hr = D3D::device->CreateRasterizerState(&rastdc, &res);
	if (FAILED(hr)) PanicAlert("Failed to create rasterizer state at %s %d\n", __FILE__, __LINE__);
	D3D::SetDebugObjectName((ID3D11DeviceChild*)res, "rasterizer state used to emulate the GX pipeline");
	m_raster.insert(std::make_pair(state.packed, res));

	return res;
}
Exemplo n.º 4
0
    RenderDevice* Gfx_CreateDevice(Window* window, const RenderDeviceConfig& cfg) 
    {
        (void)cfg; // TODO

        RenderDevice* dev = new RenderDevice;

		dev->window = window;

        dev->vsync = cfg.use_vertical_sync ? 1 : 0;

        dev->default_context = new RenderContext;
        dev->default_context->resources = &dev->resources;

        // create d3d11 device and essential resources

        HWND hwnd = *(HWND*)window->native_window_handle();

        DXGI_SWAP_CHAIN_DESC sd;
        ZeroMemory( &sd, sizeof( sd ) );
        sd.BufferCount = 1;
        sd.BufferDesc.Width = window->width();
        sd.BufferDesc.Height = window->height();
        sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
        sd.BufferDesc.RefreshRate.Numerator = 60;
        sd.BufferDesc.RefreshRate.Denominator = 1;
        sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
        sd.OutputWindow = hwnd;
        sd.SampleDesc.Count = 1;
        sd.SampleDesc.Quality = 0;
        sd.Windowed = TRUE;

        uint32 flags = D3D11_CREATE_DEVICE_SINGLETHREADED;

#ifdef _DEBUG
        flags |= D3D11_CREATE_DEVICE_DEBUG;
#endif //_DEBUG

        D3D_DRIVER_TYPE type = D3D_DRIVER_TYPE_HARDWARE;

        IDXGIAdapter* adapter = NULL;

        if( cfg.use_nvperfhud )
        {
            IDXGIAdapter* enumerated_adapter = NULL;
            IDXGIFactory* factory = NULL;
            D3D_CALL( CreateDXGIFactory(__uuidof(IDXGIFactory),(void**)&factory) );
            for( uint32 i=0; factory->EnumAdapters(i,&enumerated_adapter) != DXGI_ERROR_NOT_FOUND; ++i )
            {
                DXGI_ADAPTER_DESC adapter_desc;
                if(enumerated_adapter->GetDesc(&adapter_desc) != S_OK) 
                {
                    continue;
                }
                if(wcsstr(adapter_desc.Description,L"PerfHUD") != 0) 
                {
                    type = D3D_DRIVER_TYPE_REFERENCE;
                    adapter = enumerated_adapter;
                    break;
                }
            }
            SafeRelease(factory);
        }

        D3D_FEATURE_LEVEL features[] =
        {
            D3D_FEATURE_LEVEL_11_0,
            D3D_FEATURE_LEVEL_10_1,
            D3D_FEATURE_LEVEL_10_0,
            D3D_FEATURE_LEVEL_9_3,
            D3D_FEATURE_LEVEL_9_2,
            D3D_FEATURE_LEVEL_9_1
        };

        const uint32 num_features = sizeof(features) / sizeof(features[0]);

        D3D_FEATURE_LEVEL supported_features = D3D_FEATURE_LEVEL_9_1;

        // Create device

        D3D_CALL( D3D11CreateDeviceAndSwapChain(
            adapter, type, NULL, flags, features, num_features, 
            D3D11_SDK_VERSION, &sd, &dev->swap_chain, &dev->native, 
            &supported_features, &dev->default_context->native) );

        // Set-up default Colour and Depth surfaces

		dx11_acquire_back_buffer(dev);
		dx11_setup_back_buffer(dev);

        // create default pixel and vertex constant buffers

        D3D11_BUFFER_DESC desc;

        desc.ByteWidth = MaxShaderConstants*sizeof(Vector4);
        desc.Usage = D3D11_USAGE_DYNAMIC;
        desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
        desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
        desc.MiscFlags = 0;
        desc.StructureByteStride = 0;

        D3D_CALL(dev->native->CreateBuffer(&desc, NULL, &dev->default_context->ps_cb));
        D3D_CALL(dev->native->CreateBuffer(&desc, NULL, &dev->default_context->vs_cb));

		// Hack -- enable scissor rect state by default
		D3D11_RASTERIZER_DESC rasterizer_desc = CD3D11_RASTERIZER_DESC(CD3D11_DEFAULT());
		rasterizer_desc.ScissorEnable = TRUE;
		dev->native->CreateRasterizerState(&rasterizer_desc, &dev->rasterizer_state);
		dev->default_context->native->RSSetState(dev->rasterizer_state);

        // all done

		dev->resize_listener = new WindowResizeListener(window);

        return dev;
    }
Exemplo n.º 5
0
void XFBEncoder::Init()
{
    HRESULT hr;

    // Create output texture

    // The pixel shader can generate one YUYV entry per pixel. One YUYV entry
    // is created for every two EFB pixels.
    D3D11_TEXTURE2D_DESC t2dd = CD3D11_TEXTURE2D_DESC(
                                    DXGI_FORMAT_R8G8B8A8_UNORM, MAX_XFB_WIDTH/2, MAX_XFB_HEIGHT, 1, 1,
                                    D3D11_BIND_RENDER_TARGET);
    hr = D3D::device->CreateTexture2D(&t2dd, nullptr, &m_out);
    CHECK(SUCCEEDED(hr), "create xfb encoder output texture");
    D3D::SetDebugObjectName(m_out, "xfb encoder output texture");

    // Create output render target view

    D3D11_RENDER_TARGET_VIEW_DESC rtvd = CD3D11_RENDER_TARGET_VIEW_DESC(m_out,
                                         D3D11_RTV_DIMENSION_TEXTURE2D, DXGI_FORMAT_R8G8B8A8_UNORM);
    hr = D3D::device->CreateRenderTargetView(m_out, &rtvd, &m_outRTV);
    CHECK(SUCCEEDED(hr), "create xfb encoder output texture rtv");
    D3D::SetDebugObjectName(m_outRTV, "xfb encoder output rtv");

    // Create output staging buffer

    t2dd.Usage = D3D11_USAGE_STAGING;
    t2dd.BindFlags = 0;
    t2dd.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
    hr = D3D::device->CreateTexture2D(&t2dd, nullptr, &m_outStage);
    CHECK(SUCCEEDED(hr), "create xfb encoder output staging buffer");
    D3D::SetDebugObjectName(m_outStage, "xfb encoder output staging buffer");

    // Create constant buffer for uploading params to shaders

    D3D11_BUFFER_DESC bd = CD3D11_BUFFER_DESC(sizeof(XFBEncodeParams),
                           D3D11_BIND_CONSTANT_BUFFER);
    hr = D3D::device->CreateBuffer(&bd, nullptr, &m_encodeParams);
    CHECK(SUCCEEDED(hr), "create xfb encode params buffer");
    D3D::SetDebugObjectName(m_encodeParams, "xfb encoder params buffer");

    // Create vertex quad

    bd = CD3D11_BUFFER_DESC(sizeof(QUAD_VERTS), D3D11_BIND_VERTEX_BUFFER,
                            D3D11_USAGE_IMMUTABLE);
    D3D11_SUBRESOURCE_DATA srd = { QUAD_VERTS, 0, 0 };

    hr = D3D::device->CreateBuffer(&bd, &srd, &m_quad);
    CHECK(SUCCEEDED(hr), "create xfb encode quad vertex buffer");
    D3D::SetDebugObjectName(m_quad, "xfb encoder quad vertex buffer");

    // Create vertex shader

    D3DBlob* bytecode = nullptr;
    if (!D3D::CompileVertexShader(XFB_ENCODE_VS, &bytecode))
    {
        ERROR_LOG(VIDEO, "XFB encode vertex shader failed to compile");
        return;
    }

    hr = D3D::device->CreateVertexShader(bytecode->Data(), bytecode->Size(), nullptr, &m_vShader);
    CHECK(SUCCEEDED(hr), "create xfb encode vertex shader");
    D3D::SetDebugObjectName(m_vShader, "xfb encoder vertex shader");

    // Create input layout for vertex quad using bytecode from vertex shader

    hr = D3D::device->CreateInputLayout(QUAD_LAYOUT_DESC,
                                        sizeof(QUAD_LAYOUT_DESC)/sizeof(D3D11_INPUT_ELEMENT_DESC),
                                        bytecode->Data(), bytecode->Size(), &m_quadLayout);
    CHECK(SUCCEEDED(hr), "create xfb encode quad vertex layout");
    D3D::SetDebugObjectName(m_quadLayout, "xfb encoder quad layout");

    bytecode->Release();

    // Create pixel shader

    m_pShader = D3D::CompileAndCreatePixelShader(XFB_ENCODE_PS);
    if (!m_pShader)
    {
        ERROR_LOG(VIDEO, "XFB encode pixel shader failed to compile");
        return;
    }
    D3D::SetDebugObjectName(m_pShader, "xfb encoder pixel shader");

    // Create blend state

    D3D11_BLEND_DESC bld = CD3D11_BLEND_DESC(CD3D11_DEFAULT());
    hr = D3D::device->CreateBlendState(&bld, &m_xfbEncodeBlendState);
    CHECK(SUCCEEDED(hr), "create xfb encode blend state");
    D3D::SetDebugObjectName(m_xfbEncodeBlendState, "xfb encoder blend state");

    // Create depth state

    D3D11_DEPTH_STENCIL_DESC dsd = CD3D11_DEPTH_STENCIL_DESC(CD3D11_DEFAULT());
    dsd.DepthEnable = FALSE;
    hr = D3D::device->CreateDepthStencilState(&dsd, &m_xfbEncodeDepthState);
    CHECK(SUCCEEDED(hr), "create xfb encode depth state");
    D3D::SetDebugObjectName(m_xfbEncodeDepthState, "xfb encoder depth state");

    // Create rasterizer state

    D3D11_RASTERIZER_DESC rd = CD3D11_RASTERIZER_DESC(CD3D11_DEFAULT());
    rd.CullMode = D3D11_CULL_NONE;
    rd.DepthClipEnable = FALSE;
    hr = D3D::device->CreateRasterizerState(&rd, &m_xfbEncodeRastState);
    CHECK(SUCCEEDED(hr), "create xfb encode rasterizer state");
    D3D::SetDebugObjectName(m_xfbEncodeRastState, "xfb encoder rast state");

    // Create EFB texture sampler

    D3D11_SAMPLER_DESC sd = CD3D11_SAMPLER_DESC(CD3D11_DEFAULT());
    // FIXME: Should we really use point sampling here?
    sd.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
    hr = D3D::device->CreateSamplerState(&sd, &m_efbSampler);
    CHECK(SUCCEEDED(hr), "create xfb encode texture sampler");
    D3D::SetDebugObjectName(m_efbSampler, "xfb encoder texture sampler");
}
Exemplo n.º 6
0
  bool InitD3D11QuadRendering( RENDERER_SETTINGS * settings )
  {
    ID3DBlob * pCode = NULL;
    ID3DBlob * pErrors = NULL;
    if (D3DCompile( defaultVertexShader, strlen(defaultVertexShader), NULL, NULL, NULL, "main", "vs_4_0", NULL, NULL, &pCode, &pErrors ) != S_OK)
    {
      printf("[Renderer] D3DCompile failed\n");
      return false;
    }

    if (pDevice->CreateVertexShader( pCode->GetBufferPointer(), pCode->GetBufferSize(), NULL, &pVertexShader ) != S_OK)
    {
      printf("[Renderer] CreateVertexShader failed\n");
      return false;
    }

    //////////////////////////////////////////////////////////////////////////

    static float pQuad[] = {
      -1.0, -1.0,  0.5, 0.0, 0.0,
      -1.0,  1.0,  0.5, 0.0, 1.0,
       1.0, -1.0,  0.5, 1.0, 0.0,
       1.0,  1.0,  0.5, 1.0, 1.0,
    };

    D3D11_BUFFER_DESC desc;
    ZeroMemory(&desc, sizeof(D3D11_BUFFER_DESC));

    desc.ByteWidth = sizeof(float) * 5 * 4;
    desc.Usage = D3D11_USAGE_DEFAULT;
    desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;

    D3D11_SUBRESOURCE_DATA subData;
    ZeroMemory(&subData, sizeof(D3D11_SUBRESOURCE_DATA));
    subData.pSysMem = pQuad;

    if (pDevice->CreateBuffer(&desc, &subData, &pFullscreenQuadVB) != S_OK)
    {
      printf("[Renderer] CreateBuffer failed\n");
      return false;
    }

    static D3D11_INPUT_ELEMENT_DESC pQuadDesc[] =
    {
      {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0 * sizeof(float), D3D11_INPUT_PER_VERTEX_DATA, 0},
      {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT   , 0, 3 * sizeof(float), D3D11_INPUT_PER_VERTEX_DATA, 0},
    };

    if (pDevice->CreateInputLayout( pQuadDesc, 2, pCode->GetBufferPointer(), pCode->GetBufferSize(), &pFullscreenQuadLayout) != S_OK)
    {
      printf("[Renderer] CreateInputLayout failed\n");
      return false;
    }

    //////////////////////////////////////////////////////////////////////////

    D3D11_VIEWPORT viewport;
    ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT));

    viewport.TopLeftX = 0;
    viewport.TopLeftY = 0;
    viewport.Width  = settings->nWidth;
    viewport.Height = settings->nHeight;

    pContext->RSSetViewports(1, &viewport);

    //////////////////////////////////////////////////////////////////////////

    D3D11_SAMPLER_DESC sampDesc = CD3D11_SAMPLER_DESC( CD3D11_DEFAULT() );
    sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
    sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
    sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
    sampDesc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT;
    if (pDevice->CreateSamplerState( &sampDesc, &pFullscreenQuadSamplerState ) != S_OK)
      return false;

    //////////////////////////////////////////////////////////////////////////

    D3D11_BUFFER_DESC cbDesc;
    ZeroMemory( &cbDesc, sizeof(D3D11_BUFFER_DESC) );
    cbDesc.ByteWidth = sizeof( pFullscreenQuadConstants );
    cbDesc.Usage = D3D11_USAGE_DYNAMIC;
    cbDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
    cbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;

    ZeroMemory( &subData, sizeof(D3D11_SUBRESOURCE_DATA) );
    subData.pSysMem = &pFullscreenQuadConstants;

    if (pDevice->CreateBuffer( &cbDesc, &subData, &pFullscreenQuadConstantBuffer ) != S_OK)
      return false;

    //////////////////////////////////////////////////////////////////////////

    D3D11_BLEND_DESC blendDesc = CD3D11_BLEND_DESC( CD3D11_DEFAULT() );
    if (pDevice->CreateBlendState( &blendDesc, &pFullscreenQuadBlendState ) != S_OK)
      return false;

    D3D11_RASTERIZER_DESC rastDesc = CD3D11_RASTERIZER_DESC( CD3D11_DEFAULT() );
    if (pDevice->CreateRasterizerState( &rastDesc, &pFullscreenQuadRasterizerState ) != S_OK)
      return false;

    return true;
  }
Exemplo n.º 7
0
bool StateHolder::Initialize(ID3D11Device* device)
{
	// Raster states
	std::function<CD3D11_RASTERIZER_DESC()> rasterGenerators[RST_Count] =
	{
		[]() -> CD3D11_RASTERIZER_DESC {
			CD3D11_RASTERIZER_DESC desc((CD3D11_DEFAULT()));
			desc.CullMode = D3D11_CULL_BACK;
			desc.FillMode = D3D11_FILL_SOLID;
			desc.FrontCounterClockwise = FALSE;
			return desc;
		},
		[]() -> CD3D11_RASTERIZER_DESC {
			CD3D11_RASTERIZER_DESC desc((CD3D11_DEFAULT()));
			desc.CullMode = D3D11_CULL_BACK;
			desc.FillMode = D3D11_FILL_SOLID;
			desc.FrontCounterClockwise = TRUE;
			return desc;
		},
		[]() -> CD3D11_RASTERIZER_DESC {
			CD3D11_RASTERIZER_DESC desc((CD3D11_DEFAULT()));
			desc.CullMode = D3D11_CULL_BACK;
			desc.FillMode = D3D11_FILL_WIREFRAME;
			desc.FrontCounterClockwise = FALSE;
			return desc;
		},
			[]() -> CD3D11_RASTERIZER_DESC {
			CD3D11_RASTERIZER_DESC desc((CD3D11_DEFAULT()));
			desc.CullMode = D3D11_CULL_BACK;
			desc.FillMode = D3D11_FILL_WIREFRAME;
			desc.FrontCounterClockwise = TRUE;
			return desc;
		},
	};

	for (auto gen = 0; gen < RST_Count; ++gen) {
		if (FAILED(device->CreateRasterizerState(&rasterGenerators[gen](), m_RasterStates[gen].Receive())))
		{
			SLOG(Sev_Error, Fac_Rendering, "Unable to create raster state!");
			return false;
		}
	}
	
	// Blend states
	std::function<CD3D11_BLEND_DESC()> blendGenerators[BLST_Count] =
	{
		[]() -> CD3D11_BLEND_DESC {
			CD3D11_BLEND_DESC desc((CD3D11_DEFAULT()));
			for (unsigned i = 0; i < 8; ++i) {
				desc.RenderTarget[i].RenderTargetWriteMask = 0;
			}
			return desc;
		},
		[]() -> CD3D11_BLEND_DESC {
			CD3D11_BLEND_DESC desc((CD3D11_DEFAULT()));
			desc.AlphaToCoverageEnable = true;
			desc.RenderTarget[0].BlendEnable = true;
			return desc;
		},
	};

	for (auto gen = 0; gen < BLST_Count; ++gen) {
		if (FAILED(device->CreateBlendState(&blendGenerators[gen](), m_BlendStates[gen].Receive())))
		{
			SLOG(Sev_Error, Fac_Rendering, "Unable to create blend state!");
			return false;
		}
	}

	// Depth states
	std::function<CD3D11_DEPTH_STENCIL_DESC()> depthGenerators[DSST_Count] =
	{
		[]()->CD3D11_DEPTH_STENCIL_DESC {
			CD3D11_DEPTH_STENCIL_DESC desc((CD3D11_DEFAULT()));
			desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
			desc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
			return desc;
		},
		[]()->CD3D11_DEPTH_STENCIL_DESC {
			CD3D11_DEPTH_STENCIL_DESC desc((CD3D11_DEFAULT()));
			desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
			desc.DepthFunc = D3D11_COMPARISON_ALWAYS;
			return desc;
		},
	};
	for (auto gen = 0; gen < DSST_Count; ++gen) {
		if (FAILED(device->CreateDepthStencilState(&depthGenerators[gen](), m_DepthStates[gen].Receive())))
		{
			SLOG(Sev_Error, Fac_Rendering, "Unable to create depth-stencil state!");
			return false;
		}
	}

	return true;
}
Exemplo n.º 8
0
    void sparse_voxel_octree::create(ID3D11Device* device, UINT volume_size)
    {
        profiler_.create(device);

        volume_size_ = volume_size;
        UINT voxel_count = volume_size_ * volume_size_ * volume_size_;
        UINT mips = static_cast<UINT>(std::log2(volume_size_));

        // create volume(s)
        D3D11_TEXTURE3D_DESC desc;
        ZeroMemory(&desc, sizeof(desc));
        desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS | D3D11_BIND_RENDER_TARGET;
        desc.Width = volume_size;
        desc.Height = volume_size;
        desc.Depth = volume_size;
        desc.Usage = D3D11_USAGE_DEFAULT;
        desc.Format = DXGI_FORMAT_R16G16B16A16_FLOAT;
        desc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;
        desc.MipLevels = mips;

        assert_hr(device->CreateTexture3D(&desc, nullptr, &v_normal_));
        assert_hr(device->CreateTexture3D(&desc, nullptr, &v_rho_));

        // create unordered access view for volume(s)
        D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
        ZeroMemory(&uav_desc, sizeof(uav_desc));

        uav_desc.Format = DXGI_FORMAT_R16G16B16A16_FLOAT;
        uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE3D;
        uav_desc.Texture3D.FirstWSlice = 0;
        uav_desc.Texture3D.MipSlice = 0;
        uav_desc.Texture3D.WSize = volume_size;

        assert_hr(device->CreateUnorderedAccessView(v_normal_, &uav_desc, &uav_v_normal_));
        assert_hr(device->CreateUnorderedAccessView(v_rho_, &uav_desc, &uav_v_rho_));

        // create shader resource view for volume(s)
        D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;

        srv_desc.Format = DXGI_FORMAT_R16G16B16A16_FLOAT;
        srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
        srv_desc.Texture3D.MostDetailedMip = 0;
        srv_desc.Texture3D.MipLevels = mips;

        assert_hr(device->CreateShaderResourceView(v_normal_, &srv_desc, &srv_v_normal_));
        assert_hr(device->CreateShaderResourceView(v_rho_, &srv_desc, &srv_v_rho_));

        D3D11_BLEND_DESC bld;
        ZeroMemory(&bld, sizeof(D3D11_BLEND_DESC));

        bld.IndependentBlendEnable = TRUE;

        for (size_t i = 0; i < 6; ++i)
        {
            bld.RenderTarget[i].BlendEnable = TRUE;
            bld.RenderTarget[i].SrcBlend = D3D11_BLEND_ONE;
            bld.RenderTarget[i].DestBlend = D3D11_BLEND_ONE;
            bld.RenderTarget[i].SrcBlendAlpha = D3D11_BLEND_ONE;
            bld.RenderTarget[i].DestBlendAlpha = D3D11_BLEND_ONE;
            bld.RenderTarget[i].BlendOp = D3D11_BLEND_OP_MAX;
            bld.RenderTarget[i].BlendOpAlpha = D3D11_BLEND_OP_MAX;
            bld.RenderTarget[i].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
        }

        assert_hr(device->CreateBlendState(&bld, &bs_voxelize_));

        CD3D11_RASTERIZER_DESC raster_desc = CD3D11_RASTERIZER_DESC(CD3D11_DEFAULT());
        raster_desc.FrontCounterClockwise = true;
        raster_desc.CullMode = D3D11_CULL_NONE;

        assert_hr(device->CreateRasterizerState(&raster_desc, &no_culling_));

        cb_parameters_.create(device);
        cb_gi_parameters_.create(device);

        DirectX::XMStoreFloat4x4(&world_to_svo_, DirectX::XMMatrixIdentity());
    }
Exemplo n.º 9
0
DEMO_APP::DEMO_APP(HINSTANCE hinst, WNDPROC proc)
{
	// ****************** BEGIN WARNING ***********************// 
	// WINDOWS CODE, I DON'T TEACH THIS YOU MUST KNOW IT ALREADY! 
	application = hinst;
	appWndProc = proc;

	WNDCLASSEX  wndClass;
	ZeroMemory(&wndClass, sizeof(wndClass));
	wndClass.cbSize = sizeof(WNDCLASSEX);
	wndClass.lpfnWndProc = appWndProc;
	wndClass.lpszClassName = L"DirectXApplication";
	wndClass.hInstance = application;
	wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
	wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOWFRAME);
	//wndClass.hIcon			= LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_FSICON));
	RegisterClassEx(&wndClass);

	RECT window_size = { 0, 0, BACKBUFFER_WIDTH, BACKBUFFER_HEIGHT };
	AdjustWindowRect(&window_size, WS_OVERLAPPEDWINDOW, false);

	window = CreateWindow(L"DirectXApplication", L"Graphics II Project", WS_OVERLAPPEDWINDOW & ~(WS_THICKFRAME | WS_MAXIMIZEBOX),
		CW_USEDEFAULT, CW_USEDEFAULT, window_size.right - window_size.left, window_size.bottom - window_size.top,
		NULL, NULL, application, this);

	ShowWindow(window, SW_SHOW);
	//********************* END WARNING ************************//

	// TODO: PART 1 STEP 3a
	DXGI_SWAP_CHAIN_DESC swapDescription;
	ZeroMemory(&swapDescription, sizeof(swapDescription));
	swapDescription.BufferCount = 1;
	swapDescription.BufferDesc.Width = BACKBUFFER_WIDTH;
	swapDescription.BufferDesc.Height = BACKBUFFER_HEIGHT;
	swapDescription.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	swapDescription.BufferDesc.RefreshRate.Numerator = 60;
	swapDescription.BufferDesc.RefreshRate.Denominator = 1;
	swapDescription.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
	swapDescription.OutputWindow = window;
	swapDescription.SampleDesc.Count = 4;
	swapDescription.SampleDesc.Quality = D3D11_CENTER_MULTISAMPLE_PATTERN;
	swapDescription.Windowed = true;

	// TODO: PART 1 STEP 3b
	D3D_FEATURE_LEVEL list[6] =
	{
		D3D_FEATURE_LEVEL_11_0,
		D3D_FEATURE_LEVEL_10_1,
		D3D_FEATURE_LEVEL_10_0,
		D3D_FEATURE_LEVEL_9_3,
		D3D_FEATURE_LEVEL_9_2,
		D3D_FEATURE_LEVEL_9_1,
	};

	HRESULT test =
		D3D11CreateDeviceAndSwapChain(nullptr,		// which screen to draw on
		D3D_DRIVER_TYPE_HARDWARE,				// use the hardware
		NULL,
		D3D11_CREATE_DEVICE_DEBUG,				// how to treat the device
		list, 6,								// array of feature levels and how many there are (null sets a default value)
		D3D11_SDK_VERSION,						// whatever sdk we are currently using
		&swapDescription,
		&swapChain, &theDevice,					// output parameters
		nullptr, &devContext);

	ID3D11Texture2D* DepthStencil = NULL;
	D3D11_TEXTURE2D_DESC depthDescription;
	depthDescription.Width = BACKBUFFER_WIDTH;
	depthDescription.Height = BACKBUFFER_HEIGHT;
	depthDescription.MipLevels = 1;
	depthDescription.ArraySize = 1;
	depthDescription.Format = DXGI_FORMAT_D32_FLOAT;
	depthDescription.SampleDesc.Count = 4;
	depthDescription.SampleDesc.Quality = D3D11_CENTER_MULTISAMPLE_PATTERN;
	depthDescription.Usage = D3D11_USAGE_DEFAULT;
	depthDescription.BindFlags = D3D11_BIND_DEPTH_STENCIL;
	depthDescription.CPUAccessFlags = 0;
	depthDescription.MiscFlags = 0;

	HRESULT depthHR;
	depthHR = theDevice->CreateTexture2D(&depthDescription, NULL, &DepthStencil);

#pragma region STENCIL
	//D3D11_DEPTH_STENCIL_DESC depthStencilDescription;
	//ZeroMemory(&depthStencilDescription, sizeof(depthStencilDescription));
	//// Depth test parameters
	//depthStencilDescription.DepthEnable = true;
	//depthStencilDescription.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
	//depthStencilDescription.DepthFunc = D3D11_COMPARISON_LESS;

	//// Stencil test parameters
	//depthStencilDescription.StencilEnable = true;
	//depthStencilDescription.StencilReadMask = 0xFF;
	//depthStencilDescription.StencilWriteMask = 0xFF;

	//// Stencil operations if pixel is front-facing
	//depthStencilDescription.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
	//depthStencilDescription.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
	//depthStencilDescription.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
	//depthStencilDescription.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;

	//// Stencil operations if pixel is back-facing
	//depthStencilDescription.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
	//depthStencilDescription.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
	//depthStencilDescription.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
	//depthStencilDescription.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;

	// Create depth stencil state
	//ID3D11DepthStencilState * pDSState;
	//HRESULT DSS;
	//DSS = theDevice->CreateDepthStencilState(&depthStencilDescription, &pDSState);

	//D3D11_DEPTH_STENCIL_VIEW_DESC DSVdesc;
	//ZeroMemory(&DSVdesc, sizeof(DSVdesc));
	//DSVdesc.Format = DXGI_FORMAT_D32_FLOAT;
	//DSVdesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
	//DSVdesc.Texture2D.MipSlice = 0;
#pragma endregion

	HRESULT DSVHR;
	DSVHR = theDevice->CreateDepthStencilView(DepthStencil, NULL, &DepthStencilView);

	//pDSState->Release();
	DepthStencil->Release();


	swapChain->GetBuffer(0, __uuidof(backBuffer), reinterpret_cast<void**>(&backBuffer));
	HRESULT hr = theDevice->CreateRenderTargetView(backBuffer, NULL, &targetView);

	viewPort.TopLeftX = 0.0f;
	viewPort.TopLeftY = 0.0f;
	viewPort.Width = BACKBUFFER_WIDTH;
	viewPort.Height = BACKBUFFER_HEIGHT;
	viewPort.MinDepth = 0.0f;
	viewPort.MaxDepth = 1.0f;

	otherPort.TopLeftX = 0.0f;
	otherPort.TopLeftY = 0.0f;
	otherPort.Width = BACKBUFFER_WIDTH / 4;
	otherPort.Height = BACKBUFFER_HEIGHT / 4;
	otherPort.MinDepth = 0.0f;
	otherPort.MaxDepth = 1.0f;

#if 1

	theDevice->CreateVertexShader(SkyVShader, sizeof(SkyVShader), nullptr, &SkyBox.pVShader);
	theDevice->CreatePixelShader(SkyPShader, sizeof(SkyPShader), nullptr, &SkyBox.pPShader);

	D3D11_INPUT_ELEMENT_DESC skyLayout[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "UV", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }
	};

	theDevice->CreateInputLayout(skyLayout, ARRAYSIZE(skyLayout), SkyVShader, sizeof(SkyVShader), &SkyBox.pInputLayout);

	SkyBox.Initialize(L"sky.obj", L"SkyboxOcean.dds");

#if 1
	theDevice->CreateVertexShader(InstanceVShader, sizeof(InstanceVShader), nullptr, &Pyramid.pVShader);
	theDevice->CreatePixelShader(Trivial_PS, sizeof(Trivial_PS), nullptr, &Pyramid.pPShader);

	D3D11_INPUT_ELEMENT_DESC vLayout[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "UV", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }
	};

	// TODO: PART 2 STEP 8b
	unsigned int numElements = ARRAYSIZE(vLayout);
	theDevice->CreateInputLayout(vLayout, numElements, InstanceVShader, sizeof(InstanceVShader), &Pyramid.pInputLayout);

	Pyramid.numInstances = 4;
	Pyramid.instanced = true;
	Pyramid.Initialize(L"test_pyramid_triangle.obj", L"metallock.dds");

	Translate(Pyramid.worldMatrix, 0.0f, 0.0f, 3.0f);

	//theDevice->CreateVertexShader(VertexSlimShader, sizeof(VertexSlimShader), nullptr, &TexturePyramid.pVShader);
	//theDevice->CreatePixelShader(Trivial_PS, sizeof(Trivial_PS), nullptr, &TexturePyramid.pPShader);
	//theDevice->CreateInputLayout(vLayout, numElements, VertexSlimShader, sizeof(VertexSlimShader), &TexturePyramid.pInputLayout);

	//TexturePyramid.Initialize(L"test_pyramid_trianlge.obj", L"checkerboard.dds");

	float length = 5.0f;

	VertexOBJ quad[4] =
	{
		{ -length, 0.0f, length, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f },
		{ length, 0.0f, length, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f },
		{ -length, 0.0f, -length, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f },
		{ length, 0.0f, -length, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f }
	};

	unsigned int quadIndices[6] =
	{
		0, 1, 3,
		0, 3, 2
	};

	theDevice->CreateVertexShader(VertexSlimShader, sizeof(VertexSlimShader), nullptr, &Quad.pVShader);
	theDevice->CreatePixelShader(Trivial_PS, sizeof(Trivial_PS), nullptr, &Quad.pPShader);

	theDevice->CreateInputLayout(skyLayout, 3, VertexSlimShader, sizeof(VertexSlimShader), &Quad.pInputLayout);

	Quad.pVertices = quad;
	Quad.numVertices = 4;
	Quad.pIndices = quadIndices;
	Quad.numIndices = 6;
	Quad.Initialize(nullptr, L"checkerboard.dds");

	Translate(Quad.worldMatrix, 0.0f, -1.0f, 3.0f);

	theDevice->CreateVertexShader(PassToGeoVShader, sizeof(PassToGeoVShader), nullptr, &QuadSeed.pVShader);
	theDevice->CreatePixelShader(Trivial_PS, sizeof(Trivial_PS), nullptr, &QuadSeed.pPShader);
	theDevice->CreateGeometryShader(QuadCreator, sizeof(QuadCreator), nullptr, &QuadSeed.pGShader);

	theDevice->CreateInputLayout(skyLayout, 3, PassToGeoVShader, sizeof(PassToGeoVShader), &QuadSeed.pInputLayout);

	theDevice->CreateVertexShader(VertexSlimShader, sizeof(VertexSlimShader), nullptr, &Tree.pVShader);
	theDevice->CreatePixelShader(Trivial_PS, sizeof(Trivial_PS), nullptr, &Tree.pPShader);
	theDevice->CreateInputLayout(skyLayout, 3, VertexSlimShader, sizeof(VertexSlimShader), &Tree.pInputLayout);
	Tree.Initialize(L"the_tree.obj", L"treeTexture.dds");
	Translate(Tree.worldMatrix, 2.0f, -1.0f, 3.0f);

	theDevice->CreateVertexShader(VertexSlimShader, sizeof(VertexSlimShader), nullptr, &Tree1.pVShader);
	theDevice->CreatePixelShader(Trivial_PS, sizeof(Trivial_PS), nullptr, &Tree1.pPShader);
	theDevice->CreateInputLayout(skyLayout, 3, VertexSlimShader, sizeof(VertexSlimShader), &Tree1.pInputLayout);
	Tree1.Initialize(L"the_tree.obj", L"treeTexture.dds");
	Translate(Tree1.worldMatrix, 2.0f, -1.0f, 0.0f);

	theDevice->CreateVertexShader(VertexSlimShader, sizeof(VertexSlimShader), nullptr, &Tree2.pVShader);
	theDevice->CreatePixelShader(Trivial_PS, sizeof(Trivial_PS), nullptr, &Tree2.pPShader);
	theDevice->CreateInputLayout(skyLayout, 3, VertexSlimShader, sizeof(VertexSlimShader), &Tree2.pInputLayout);
	Tree2.Initialize(L"the_tree.obj", L"treeTexture.dds");
	Translate(Tree2.worldMatrix, 2.0f, -1.0f, 7.0f);

	theDevice->CreateVertexShader(PassToGeoVShader, sizeof(PassToGeoVShader), nullptr, &PostQuad.pVShader);
	theDevice->CreatePixelShader(PostProcess, sizeof(PostProcess), nullptr, &PostQuad.pPShader);
	theDevice->CreateGeometryShader(PostGeoShader, sizeof(PostGeoShader), nullptr, &PostQuad.pGShader);
	theDevice->CreateInputLayout(skyLayout, 3, PassToGeoVShader, sizeof(PassToGeoVShader), &PostQuad.pInputLayout);
	
	VertexOBJ seed =  { 0.0f, 0.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f };
	unsigned int x = 0;
	QuadSeed.pVertices = &seed;
	QuadSeed.numVertices = 1;
	QuadSeed.pIndices = &x;
	QuadSeed.numIndices = 1;
	
	VertexOBJ center;
	PostQuad.pVertices = &center;
	PostQuad.numVertices = 1;
	PostQuad.pIndices = &x;
	PostQuad.numIndices = 1;

	D3D11_TEXTURE2D_DESC viewDesc;
	ZeroMemory(&viewDesc, sizeof(viewDesc));
	viewDesc.Width = BACKBUFFER_WIDTH;
	viewDesc.Height = BACKBUFFER_HEIGHT;
	viewDesc.MipLevels = 1;
	viewDesc.ArraySize = 1;
	viewDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
	viewDesc.SampleDesc.Count = 4;
	viewDesc.SampleDesc.Quality = D3D11_CENTER_MULTISAMPLE_PATTERN;
	viewDesc.Usage = D3D11_USAGE_DEFAULT;
	viewDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
	viewDesc.CPUAccessFlags = 0;
	viewDesc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;
	theDevice->CreateTexture2D(&viewDesc, NULL, &renderTexture);

	D3D11_TEXTURE2D_DESC postDesc;
	ZeroMemory(&postDesc, sizeof(postDesc));
	postDesc.Width = BACKBUFFER_WIDTH;
	postDesc.Height = BACKBUFFER_HEIGHT;
	postDesc.MipLevels = 1;
	postDesc.ArraySize = 1;
	postDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
	postDesc.SampleDesc.Count = 4;
	postDesc.SampleDesc.Quality = D3D11_CENTER_MULTISAMPLE_PATTERN;
	postDesc.Usage = D3D11_USAGE_DEFAULT;
	postDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
	postDesc.CPUAccessFlags = 0;
	postDesc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;
	theDevice->CreateTexture2D(&postDesc, NULL, &postTexture);

	viewDesc.SampleDesc.Count = 1;
	viewDesc.SampleDesc.Quality = 0;
	theDevice->CreateTexture2D(&viewDesc, nullptr, &fixerTexture);

	D3D11_RENDER_TARGET_VIEW_DESC rendViewDesc;
	ZeroMemory(&rendViewDesc, sizeof(rendViewDesc));
	rendViewDesc.Format = viewDesc.Format;
	rendViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS;
	rendViewDesc.Texture2D.MipSlice = 0;
	theDevice->CreateRenderTargetView(renderTexture, &rendViewDesc, &anotherView);
	theDevice->CreateRenderTargetView(postTexture, &rendViewDesc, &postProcessView);

	D3D11_SHADER_RESOURCE_VIEW_DESC shadeDesc;
	ZeroMemory(&shadeDesc, sizeof(shadeDesc));
	shadeDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMS;
	shadeDesc.Format = viewDesc.Format;
	shadeDesc.Texture2D.MostDetailedMip = 0;
	shadeDesc.Texture2D.MipLevels = 5;
	theDevice->CreateShaderResourceView(renderTexture, &shadeDesc, &QuadSeed.pShaderResource);
	theDevice->CreateShaderResourceView(postTexture, &shadeDesc, &PostQuad.pShaderResource);

	D3D11_SHADER_RESOURCE_VIEW_DESC yetAnotherShadeDesc;
	ZeroMemory(&yetAnotherShadeDesc, sizeof(yetAnotherShadeDesc));
	yetAnotherShadeDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
	yetAnotherShadeDesc.Format = viewDesc.Format;
	yetAnotherShadeDesc.Texture2D.MostDetailedMip = 0;
	yetAnotherShadeDesc.Texture2D.MipLevels = 5;
	theDevice->CreateShaderResourceView(renderTexture, &yetAnotherShadeDesc, &QuadSeed.pOtherShaderResource);
	theDevice->CreateShaderResourceView(postTexture, &yetAnotherShadeDesc, &PostQuad.pOtherShaderResource);

	PostQuad.Initialize();

	QuadSeed.Initialize(nullptr);
	Translate(QuadSeed.worldMatrix, 0.0f, 0.0f, 3.0f);

	D3D11_BUFFER_DESC viewPortsDesc;
	ZeroMemory(&viewPortsDesc, sizeof(viewPortsDesc));
	viewPortsDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	viewPortsDesc.ByteWidth = sizeof(D3D11_VIEWPORT) * 2;
	viewPortsDesc.Usage = D3D11_USAGE_DYNAMIC;
	viewPortsDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
	
	//D3D11_SUBRESOURCE_DATA viewPortsSub;
	//ZeroMemory(&viewPortsSub, sizeof(viewPortsSub));

#pragma region THE_LIGHTS
	theLight = DIR_LIGHT(1.0f, 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 1.0f);
	ambientLight[0] = 0.5f;
	ambientLight[1] = 0.5f;
	ambientLight[2] = 0.5f;
	ambientLight[3] = 1.0f;

	D3D11_BUFFER_DESC lightDesc;
	ZeroMemory(&lightDesc, sizeof(lightDesc));
	lightDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	lightDesc.ByteWidth = sizeof(theLight);
	lightDesc.Usage = D3D11_USAGE_DYNAMIC;
	lightDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;

	D3D11_SUBRESOURCE_DATA lightSub;
	ZeroMemory(&lightSub, sizeof(lightSub));
	lightSub.pSysMem = &theLight;
	lightSub.SysMemPitch = 0;
	lightSub.SysMemSlicePitch = 0;

	theDevice->CreateBuffer(&lightDesc, &lightSub, &lightBuff);

	D3D11_BUFFER_DESC ambDesc;
	ZeroMemory(&ambDesc, sizeof(ambDesc));
	ambDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	ambDesc.ByteWidth = 32;//sizeof(theLight);
	ambDesc.Usage = D3D11_USAGE_DYNAMIC;
	ambDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;

	D3D11_SUBRESOURCE_DATA ambSub;
	ZeroMemory(&ambSub, sizeof(ambSub));
	ambSub.pSysMem = &ambientLight;
	ambSub.SysMemPitch = 0;
	ambSub.SysMemSlicePitch = 0;

	theDevice->CreateBuffer(&ambDesc, &ambSub, &ambientBuff);

	thePtLight = DIR_LIGHT(0.0f, 0.0f, 1.0f, 1.0f, 0.5f, 0.0f, 0.5f);

	D3D11_BUFFER_DESC ptDesc;
	ZeroMemory(&ptDesc, sizeof(ptDesc));
	ptDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	ptDesc.ByteWidth = sizeof(thePtLight);
	ptDesc.Usage = D3D11_USAGE_DYNAMIC;
	ptDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;

	D3D11_SUBRESOURCE_DATA ptSub;
	ZeroMemory(&ptSub, sizeof(ptSub));
	ptSub.pSysMem = &thePtLight;
	ptSub.SysMemPitch = 0;
	ptSub.SysMemSlicePitch = 0;

	theDevice->CreateBuffer(&ptDesc, &ptSub, &ptltBuff);

	theSpotLight = SPOT_LIGHT(-0.5f, 5.0f, 2.0f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.99f);

	D3D11_BUFFER_DESC spotDesc;
	ZeroMemory(&spotDesc, sizeof(spotDesc));
	spotDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	spotDesc.ByteWidth = sizeof(theSpotLight);
	spotDesc.Usage = D3D11_USAGE_DYNAMIC;
	spotDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;

	D3D11_SUBRESOURCE_DATA spotSub;
	ZeroMemory(&spotSub, sizeof(spotSub));
	spotSub.pSysMem = &theSpotLight;

	theDevice->CreateBuffer(&spotDesc, &spotSub, &spotBuff);
#pragma endregion

#endif



#endif

#if 1
	// Matrix setup
	float XScale, YScale, Aspect, zFar, zNear;
	Aspect = 1.0f;
	YScale = 1.0f / tanf((45.0f * 3.14f) / 180.0f);
	XScale = YScale * Aspect;
	zNear = 0.1f;
	zFar = 100.0f;

	projMatrix =
	{
		XScale, 0.0f, 0.0f, 0.0f,
		0.0f, YScale, 0.0f, 0.0f,
		0.0f, 0.0f, zFar / (zFar - zNear), 1.0f,
		0.0f, 0.0f, -(zFar * zNear) / (zFar - zNear), 0.0f
	};

	cameraMatrix = Inverse4x4(viewMatrix);
	SkyBox.worldMatrix.M[3][0] = viewMatrix.M[3][0];
	SkyBox.worldMatrix.M[3][1] = viewMatrix.M[3][1];
	SkyBox.worldMatrix.M[3][2] = viewMatrix.M[3][2];

	scene[0] = /*cameraMatrix*/ viewMatrix;
	scene[1] = projMatrix;

	// Build World Matrix Buffer
	D3D11_BUFFER_DESC worldBuffDesc;
	ZeroMemory(&worldBuffDesc, sizeof(worldBuffDesc));
	worldBuffDesc.Usage = D3D11_USAGE_DYNAMIC;
	worldBuffDesc.ByteWidth = sizeof(M_4x4);
	worldBuffDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	worldBuffDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;

	D3D11_SUBRESOURCE_DATA worldSub;
	worldSub.pSysMem = &worldMatrix;
	worldSub.SysMemPitch = 0;
	worldSub.SysMemSlicePitch = 0;

	theDevice->CreateBuffer(&worldBuffDesc, &worldSub, &pWorldBuffer);

	D3D11_BUFFER_DESC sceneBuffDesc;
	ZeroMemory(&sceneBuffDesc, sizeof(sceneBuffDesc));
	sceneBuffDesc.Usage = D3D11_USAGE_DYNAMIC;
	sceneBuffDesc.ByteWidth = sizeof(M_4x4) * 2;
	sceneBuffDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	sceneBuffDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;

	D3D11_SUBRESOURCE_DATA sceneSub;
	sceneSub.pSysMem = scene;
	sceneSub.SysMemPitch = 0;
	sceneSub.SysMemSlicePitch = 0;

	theDevice->CreateBuffer(&sceneBuffDesc, &sceneSub, &sceneMatrixBuffer);
#endif


#if 1 // Rasterstate

	CD3D11_RASTERIZER_DESC rasterDesc = CD3D11_RASTERIZER_DESC(CD3D11_DEFAULT());
	rasterDesc.FrontCounterClockwise = TRUE;
	rasterDesc.CullMode = D3D11_CULL_NONE;
	rasterDesc.AntialiasedLineEnable = true;
	rasterDesc.MultisampleEnable = true;

	theDevice->CreateRasterizerState(&rasterDesc, &pRasterState);

	CD3D11_RASTERIZER_DESC otherDesc = CD3D11_RASTERIZER_DESC(CD3D11_DEFAULT());
	otherDesc.FrontCounterClockwise = FALSE;
	otherDesc.CullMode = D3D11_CULL_FRONT;
	otherDesc.AntialiasedLineEnable = true;
	//rasterDesc.MultisampleEnable = true;

	theDevice->CreateRasterizerState(&otherDesc, &pOtherState);
#endif



}
Exemplo n.º 10
0
//--------------------------------------------------------------------------------------
// Name: Initialize()
// Desc: 
//--------------------------------------------------------------------------------------
BOOL CSample::Initialize()
{
    // Initialize sample variables
    m_nCurMeshIndex  = CUBE_MESH;
    m_bShowShadowMap = TRUE;
    m_vLightPosition = FRMVECTOR3( 0.0f, 8.0f, 0.01f );

    // Create the font
    if( FALSE == m_Font.Create( "Tuffy12.pak" ) )
        return FALSE;

    // Load the packed resources
    CFrmPackedResourceD3D resource;
    if( FALSE == resource.LoadFromFile( "Textures.pak" ) )
        return FALSE;

    // Create the logo texture
    m_pLogoTexture = resource.GetTexture( "Logo" );

    // Setup the user interface
    if( FALSE == m_UserInterface.Initialize( &m_Font, m_strName ) )
        return FALSE;
    m_UserInterface.AddOverlay( m_pLogoTexture, -5, -5,
                                m_pLogoTexture->m_nWidth, m_pLogoTexture->m_nHeight );
    m_UserInterface.AddTextString( "Press " FRM_FONT_KEY_0 " for Help", 1.0f, -1.0f, 1.0f );
    m_UserInterface.AddIntVariable( &m_nShadowMapFBOTextureWidth , "Shadow Map Size", "%d" );
    m_UserInterface.AddBoolVariable( &m_bUsePCF , "PCF On", "True", "False" );
    m_UserInterface.AddHelpKey( FRM_FONT_KEY_0, "Toggle Help" );
    m_UserInterface.AddHelpKey( FRM_FONT_KEY_1, "Next Model" );
    m_UserInterface.AddHelpKey( FRM_FONT_KEY_2, "Next Floor" );
    m_UserInterface.AddHelpKey( FRM_FONT_KEY_3, "Decrease Shadow Map Size" );
    m_UserInterface.AddHelpKey( FRM_FONT_KEY_4, "Increase Shadow Map Size" );
    m_UserInterface.AddHelpKey( FRM_FONT_KEY_5, "Toggle PCF" );
    m_UserInterface.AddHelpKey( FRM_FONT_KEY_6, "Toggle Shadow Map Display" );
    m_UserInterface.AddHelpKey( FRM_FONT_KEY_DPAD, "Rotate light" );

     // Load the meshes
    if( FALSE == m_Floor[ PLANE_FLOOR ].Load( "Plane.mesh" ) )
        return FALSE;
    if( FALSE == m_Floor[ PLANE_FLOOR ].MakeDrawable() )
        return FALSE;
    if( FALSE == m_Floor[ TERRAIN_FLOOR ].Load( "Terrain.mesh" ) )
        return FALSE;
    if( FALSE == m_Floor[ TERRAIN_FLOOR ].MakeDrawable() )
        return FALSE;
    if( FALSE == m_Meshes[ CUBE_MESH ].Load( "Cube.mesh" ) )
        return FALSE;
    if( FALSE == m_Meshes[ CUBE_MESH ].MakeDrawable() )
        return FALSE;
    if( FALSE == m_Meshes[ SPHERE_MESH ].Load( "Sphere.mesh" ) )
        return FALSE;
    if( FALSE == m_Meshes[ SPHERE_MESH ].MakeDrawable() )
        return FALSE;
    if( FALSE == m_Meshes[ BUMPY_SPHERE_MESH ].Load( "BumpySphere.mesh" ) )
        return FALSE;
    if( FALSE == m_Meshes[ BUMPY_SPHERE_MESH ].MakeDrawable() )
        return FALSE;
    if( FALSE == m_Meshes[ TORUS_MESH ].Load( "Torus.mesh" ) )
        return FALSE;
    if( FALSE == m_Meshes[ TORUS_MESH ].MakeDrawable() )
        return FALSE;
    if( FALSE == m_Meshes[ ROCKET_MESH ].Load( "Rocket.mesh" ) )
        return FALSE;
    if( FALSE == m_Meshes[ ROCKET_MESH ].MakeDrawable() )
        return FALSE;

    // Initialize the shaders
    if( FALSE == InitShaders() )
        return FALSE;

    // Initialize the camera and light perspective matrices
    FLOAT32 fAspect = (FLOAT32)m_nWidth / (FLOAT32)m_nHeight;
    m_matCameraPersp = FrmMatrixPerspectiveFovRH( FRM_PI/4.0f, fAspect, 1.0f, 100.0f );
    m_matLightPersp  = FrmMatrixPerspectiveFovRH( FRM_PI/4.0f, 1.0f, 5.0f, 20.0f );

    // Setup the FBOs
    m_nShadowMapFBOTextureExp    = 7;
    m_nShadowMapFBOTextureWidth  = 2 << m_nShadowMapFBOTextureExp;
    m_nShadowMapFBOTextureHeight = 2 << m_nShadowMapFBOTextureExp;
    
    if( FALSE == CreateShadowMapFBO() )
        return FALSE;

    if( FALSE == CreateLightingFBO() )
        return FALSE;

    // Setup the camera view matrix
    FRMVECTOR3 vCameraPosition = FRMVECTOR3( 0.0f, 4.0f, 10.0f );
    FRMVECTOR3 vCameraLookAt   = FRMVECTOR3( 0.0f, 0.0f, 0.0f );
    FRMVECTOR3 vCameraUp       = FRMVECTOR3( 0.0f, 1.0f, 0.0f );
    m_matCameraView = FrmMatrixLookAtRH( vCameraPosition, vCameraLookAt, vCameraUp );

    // Setup the floor's camera relative model view projection matrix
    FRMMATRIX4X4 matFloorScale            = FrmMatrixScale( 5.0f, 5.0f, 5.0f );
    FRMMATRIX4X4 matFloorTranslate        = FrmMatrixTranslate( 0.0f, -0.1f, 0.0f );
    m_matFloorModel                       = FrmMatrixMultiply( matFloorScale, matFloorTranslate );
    m_matCameraFloorModelView             = FrmMatrixMultiply( m_matFloorModel, m_matCameraView );
    m_matCameraFloorModelViewProj         = FrmMatrixMultiply( m_matCameraFloorModelView, m_matCameraPersp );
    m_matCameraFloorNormal                = FrmMatrixNormal( m_matCameraFloorModelView );

    // Setup the light look at and up vectors
    m_vLightLookAt = FRMVECTOR3( 0.0f, 0.0f, 0.0f );
    m_vLightUp     = FRMVECTOR3( 0.0f, 1.0f, 0.0f );

    // Create our scale and bias matrix that is used to convert the coordinates of vertices that are multiplied by a 
    // model view projection matrix from the range [-1, 1] to the range [0, 1], so that they can be used for texture lookups
    m_matScaleAndBias.M( 0, 0 ) = 0.5f; m_matScaleAndBias.M( 0, 1 ) = 0.0f; m_matScaleAndBias.M( 0, 2 ) = 0.0f; m_matScaleAndBias.M( 0, 3 ) = 0.0f;  
    m_matScaleAndBias.M( 1, 0 ) = 0.0f; m_matScaleAndBias.M( 1, 1 ) = -0.5f; m_matScaleAndBias.M( 1, 2 ) = 0.0f; m_matScaleAndBias.M( 1, 3 ) = 0.0f;  
    m_matScaleAndBias.M( 2, 0 ) = 0.0f; m_matScaleAndBias.M( 2, 1 ) = 0.0f; m_matScaleAndBias.M( 2, 2 ) = 0.5f; m_matScaleAndBias.M( 2, 3 ) = 0.0f;  
    m_matScaleAndBias.M( 3, 0 ) = 0.5f; m_matScaleAndBias.M( 3, 1 ) = 0.5f; m_matScaleAndBias.M( 3, 2 ) = 0.5f; m_matScaleAndBias.M( 3, 3 ) = 1.0f;  

    // State blocks
    D3D11_RASTERIZER_DESC rdesc = CD3D11_RASTERIZER_DESC(D3D11_DEFAULT);    
    rdesc.FrontCounterClockwise = TRUE; // Change the winding direction to match GL    
    D3DDevice()->CreateRasterizerState(&rdesc, &m_DefaultRasterizerState);
    D3DDeviceContext()->RSSetState(m_DefaultRasterizerState.Get());

    rdesc = CD3D11_RASTERIZER_DESC(D3D11_DEFAULT);   
    rdesc.CullMode = D3D11_CULL_NONE;
    rdesc.DepthBias = 200;
    rdesc.SlopeScaledDepthBias = 2.0f; 
    D3DDevice()->CreateRasterizerState(&rdesc, &m_PolygonOffsetRasterizerState);

    D3D11_DEPTH_STENCIL_DESC dsdesc = CD3D11_DEPTH_STENCIL_DESC(D3D11_DEFAULT);
    dsdesc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
    D3DDevice()->CreateDepthStencilState(&dsdesc, &m_DepthLEqualStencilState);
    D3DDeviceContext()->OMSetDepthStencilState( m_DepthLEqualStencilState.Get(), 0 );

    return TRUE;
}
Exemplo n.º 11
0
//--------------------------------------------------------------------------------------
// Name: Initialize()
// Desc: 
//--------------------------------------------------------------------------------------
BOOL CSample::Initialize()
{
    // Initialize sample variables
  //  m_nCurMeshIndex  = CUBE_MESH;

    m_vLightPosition = FRMVECTOR3( 0.0f, 8.0f, 0.01f );

    // Create the font
    if( FALSE == m_Font.Create( "Tuffy12.pak" ) )
        return FALSE;

    // Load the packed resources
    CFrmPackedResourceD3D resource;
    if( FALSE == resource.LoadFromFile( "Textures.pak" ) )
        return FALSE;

    // Create the logo texture
    m_pLogoTexture = resource.GetTexture( "Logo" );

    // Setup the user interface
    if( FALSE == m_UserInterface.Initialize( &m_Font, m_strName ) )
        return FALSE;
    m_UserInterface.AddOverlay( m_pLogoTexture, -5, -5,
                                m_pLogoTexture->m_nWidth, m_pLogoTexture->m_nHeight );
    m_UserInterface.AddTextString( "Press " FRM_FONT_KEY_0 " for Help", 1.0f, -1.0f, 1.0f );

    m_UserInterface.AddHelpKey( FRM_FONT_KEY_0, "Toggle Help" );
    m_UserInterface.AddHelpKey( FRM_FONT_KEY_1, "Increase Hg param " );
    m_UserInterface.AddHelpKey( FRM_FONT_KEY_2, "Decrease Hg param " );
    m_UserInterface.AddHelpKey( FRM_FONT_KEY_3, "Increase InscatteringMultiplier param" );
    m_UserInterface.AddHelpKey( FRM_FONT_KEY_4, "Decrease InscatteringMultiplier param" );
    m_UserInterface.AddHelpKey( FRM_FONT_KEY_5, "Increase MieMultiplier param" );
    m_UserInterface.AddHelpKey( FRM_FONT_KEY_6, "Decrease MieMultiplier param" );
    m_UserInterface.AddHelpKey( FRM_FONT_KEY_7, "Increase Turbitity param" );
    m_UserInterface.AddHelpKey( FRM_FONT_KEY_8, "Decrease Turbitity param" );
//	m_UserInterface.AddHelpKey( FRM_FONT_KEY_9, "Change Shader Hoffman/Preetham" );

	// Create a new terrain height field and landscape
	UINT32 nWidth, nHeight;
    BYTE*  pHeightMapData = LoadTGA( "heights.tga", &nWidth, &nHeight, 3 );
    if( NULL == pHeightMapData )
          return FALSE;

    HeightField heightField;
                heightField.createFromRGBImage  ( pHeightMapData
                                                , nWidth 
                                                , nHeight 
                                                , 2.0
                                                , 40.0
                                                );

	delete [] pHeightMapData;

	BYTE*  pTextureData = LoadTGA( "terrain.tga", &nWidth, &nHeight, 4 );
    if( NULL == pTextureData )
		return FALSE;

	UINT32 nNormalsWidth, nNormalsHeight;
	BYTE*  pNormalMapData = LoadTGA( "normals.tga", &nNormalsWidth, &nNormalsHeight, 4 );
    if( NULL == pNormalMapData )
		return FALSE;


    m_terrain.create( heightField );

	mover.SetPosition( FRMVECTOR3( -((float)m_terrain.getTotalWidth())/2.0f, -70.0f, -((float)m_terrain.getTotalHeight())/2.0f));
	m_terrain.GenTerrainAndNormalTextures( pTextureData, nWidth, nHeight, 
							pNormalMapData, nNormalsWidth, nNormalsHeight);

	delete [] pTextureData;
	delete [] pNormalMapData;

	////////////////

    // Initialize the shaders
    if( FALSE == InitShaders() )
        return FALSE;

    // Initialize the camera and light perspective matrices
    FLOAT32 fAspect = (FLOAT32)m_nWidth / (FLOAT32)m_nHeight;
    m_matCameraPersp = FrmMatrixPerspectiveFovRH( FRM_PI/4.0f, fAspect, 1.0f, 6000.0f );
  //  m_matLightPersp  = FrmMatrixPerspectiveFovRH( FRM_PI/4.0f, 1.0f, 5.0f, 20.0f );

    // Initialize the viewport
#ifdef TEMP
    glViewport( 0, 0, m_nWidth, m_nHeight );
#endif

    // Setup the camera view matrix
    FRMVECTOR3 vCameraPosition = FRMVECTOR3( 0.0f, 0.0f, 10.0f );
    FRMVECTOR3 vCameraLookAt   = FRMVECTOR3( 0.0f, 0.0f, 0.0f );
    FRMVECTOR3 vCameraUp       = FRMVECTOR3( 0.0f, 1.0f, 0.0f );
    m_matCameraView = FrmMatrixLookAtRH( vCameraPosition, vCameraLookAt, vCameraUp );

    // Setup the light look at and up vectors
    m_vLightLookAt = FRMVECTOR3( 0.0f, 0.0f, 0.0f );
    m_vLightUp     = FRMVECTOR3( 0.0f, 1.0f, 0.0f );

    // Initial state
    D3D11_RASTERIZER_DESC rdesc = CD3D11_RASTERIZER_DESC(D3D11_DEFAULT);    
    rdesc.CullMode = D3D11_CULL_NONE; // No culling for the terrain
    rdesc.FrontCounterClockwise = TRUE; // Change the winding direction to match GL    
    D3DDevice()->CreateRasterizerState(&rdesc, &m_RasterizerState);
    D3DDeviceContext()->RSSetState(m_RasterizerState.Get());

    return TRUE;
}
Exemplo n.º 12
0
//--------------------------------------------------------------------------------------
// Name: Initialize()
// Desc: 
//--------------------------------------------------------------------------------------
BOOL CSample::Initialize()
{
    // Initialize sample variables
    m_nCurMeshIndex  = CUBE_MESH;

    m_vLightPosition = FRMVECTOR3( 0.0f, 4.0f, 0.0f );

    // Create the font
    if( FALSE == m_Font.Create( "Tuffy12.pak" ) )
        return FALSE;

    // Load the packed resources
    CFrmPackedResourceD3D resource;
    if( FALSE == resource.LoadFromFile( "Textures.pak" ) )
        return FALSE;

    // Create the logo texture
    m_pLogoTexture = resource.GetTexture( "Logo" );

    // Setup the user interface
    if( FALSE == m_UserInterface.Initialize( &m_Font, m_strName ) )
        return FALSE;

	//hack in a title for first model
	m_UserInterface.SetHeading("Cook Torrance");

    m_UserInterface.AddOverlay( m_pLogoTexture, -5, -5,
                                m_pLogoTexture->m_nWidth, m_pLogoTexture->m_nHeight );
    m_UserInterface.AddTextString( "Press " FRM_FONT_KEY_0 " for Help", 1.0f, -1.0f, 1.0f );

    m_UserInterface.AddHelpKey( FRM_FONT_KEY_0, "Toggle Help" );
    m_UserInterface.AddHelpKey( FRM_FONT_KEY_1, "Next Model" );
    m_UserInterface.AddHelpKey( FRM_FONT_KEY_2, "Next Shader" );
	m_UserInterface.AddHelpKey( FRM_FONT_KEY_3, "Increase Material Glossinesss" );
	m_UserInterface.AddHelpKey( FRM_FONT_KEY_4, "Decrease Material Glossinesss" );

     // Load the meshes
    if( FALSE == m_Meshes[ CUBE_MESH ].Load( "Cube.mesh" ) )//
        return FALSE;
	if( FALSE == m_Meshes[ CUBE_MESH ].MakeDrawable() )
        return FALSE;
    if( FALSE == m_Meshes[ SPHERE_MESH ].Load( "Sphere.mesh" ) )
        return FALSE;
    if( FALSE == m_Meshes[ SPHERE_MESH ].MakeDrawable() )
        return FALSE;
    if( FALSE == m_Meshes[ BUMPY_SPHERE_MESH ].Load( "BumpySphere.mesh" ) )
        return FALSE;
    if( FALSE == m_Meshes[ BUMPY_SPHERE_MESH ].MakeDrawable() )
        return FALSE;
    if( FALSE == m_Meshes[ TORUS_MESH ].Load( "Torus.mesh" ) )
        return FALSE;
    if( FALSE == m_Meshes[ TORUS_MESH ].MakeDrawable() )
        return FALSE;
    if( FALSE == m_Meshes[ ROCKET_MESH ].Load( "Rocket.mesh" ) )
        return FALSE;
    if( FALSE == m_Meshes[ ROCKET_MESH ].MakeDrawable() )
        return FALSE;
	////////////

    // Initialize the shaders
    if( FALSE == InitShaders() )
        return FALSE;

    // Initialize the camera and light perspective matrices
    FLOAT32 fAspect = (FLOAT32)m_nWidth / (FLOAT32)m_nHeight;
    m_matCameraPersp = FrmMatrixPerspectiveFovRH( FRM_PI/4.0f, fAspect, 1.0f, 100.0f );
    m_matLightPersp  = FrmMatrixPerspectiveFovRH( FRM_PI/4.0f, 1.0f, 5.0f, 20.0f );

    // Setup the camera view matrix
    FRMVECTOR3 vCameraPosition = FRMVECTOR3( 0.0f, 0.0f, 10.0f );
    FRMVECTOR3 vCameraLookAt   = FRMVECTOR3( 0.0f, 0.0f, 0.0f );
    FRMVECTOR3 vCameraUp       = FRMVECTOR3( 0.0f, 1.0f, 0.0f );
    m_matCameraView = FrmMatrixLookAtRH( vCameraPosition, vCameraLookAt, vCameraUp );

    // Setup the light look at and up vectors
    m_vLightLookAt = FRMVECTOR3( 0.0f, 0.0f, 0.0f );
    m_vLightUp     = FRMVECTOR3( 0.0f, 1.0f, 0.0f );

    // Initial state
    D3D11_RASTERIZER_DESC rdesc = CD3D11_RASTERIZER_DESC(D3D11_DEFAULT);    
    rdesc.FrontCounterClockwise = TRUE; // Change the winding direction to match GL    
    D3DDevice()->CreateRasterizerState(&rdesc, &m_RasterizerState);
    D3DDeviceContext()->RSSetState(m_RasterizerState.Get());
    return TRUE;
}
Exemplo n.º 13
0
int CD3DFont::Init()
{
	// Create vertex buffer for the letters
	HRESULT hr;

	// Prepare to create a bitmap
	unsigned int* pBitmapBits;
	BITMAPINFO bmi;
	ZeroMemory(&bmi.bmiHeader, sizeof(BITMAPINFOHEADER));
	bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	bmi.bmiHeader.biWidth = (int)m_dwTexWidth;
	bmi.bmiHeader.biHeight = -(int)m_dwTexHeight;
	bmi.bmiHeader.biPlanes = 1;
	bmi.bmiHeader.biCompression = BI_RGB;
	bmi.bmiHeader.biBitCount = 32;

	// Create a DC and a bitmap for the font
	HDC hDC = CreateCompatibleDC(nullptr);
	HBITMAP hbmBitmap = CreateDIBSection(hDC, &bmi, DIB_RGB_COLORS, (void**)&pBitmapBits, nullptr, 0);
	SetMapMode(hDC, MM_TEXT);

	// create a GDI font
	HFONT hFont = CreateFont(24, 0, 0, 0, FW_NORMAL, FALSE,
		FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
		CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
		VARIABLE_PITCH, _T("Tahoma"));
	if (nullptr == hFont) return E_FAIL;

	HGDIOBJ hOldbmBitmap = SelectObject(hDC, hbmBitmap);
	HGDIOBJ hOldFont = SelectObject(hDC, hFont);

	// Set text properties
	SetTextColor(hDC, 0xFFFFFF);
	SetBkColor(hDC, 0);
	SetTextAlign(hDC, TA_TOP);

	TEXTMETRICW tm;
	GetTextMetricsW(hDC, &tm);
	m_LineHeight = tm.tmHeight;

	// Loop through all printable characters and output them to the bitmap
	// Meanwhile, keep track of the corresponding tex coords for each character.
	int x = 0, y = 0;
	char str[2] = "\0";
	for (int c = 0; c < 127 - 32; c++)
	{
		str[0] = c + 32;
		SIZE size;
		GetTextExtentPoint32A(hDC, str, 1, &size);
		if ((int)(x + size.cx + 1) > m_dwTexWidth)
		{
			x = 0;
			y += m_LineHeight;
		}

		ExtTextOutA(hDC, x + 1, y + 0, ETO_OPAQUE | ETO_CLIPPED, nullptr, str, 1, nullptr);
		m_fTexCoords[c][0] = ((float)(x + 0)) / m_dwTexWidth;
		m_fTexCoords[c][1] = ((float)(y + 0)) / m_dwTexHeight;
		m_fTexCoords[c][2] = ((float)(x + 0 + size.cx)) / m_dwTexWidth;
		m_fTexCoords[c][3] = ((float)(y + 0 + size.cy)) / m_dwTexHeight;

		x += size.cx + 3;  // 3 to work around annoying ij conflict (part of the j ends up with the i)
	}

	// Create a new texture for the font
	// possible optimization: store the converted data in a buffer and fill the texture on creation.
	//							That way, we can use a static texture
	ID3D11Texture2D* buftex;
	D3D11_TEXTURE2D_DESC texdesc = CD3D11_TEXTURE2D_DESC(D3D::GetBaseBufferFormat(), m_dwTexWidth, m_dwTexHeight,
		1, 1, D3D11_BIND_SHADER_RESOURCE, D3D11_USAGE_DYNAMIC,
		D3D11_CPU_ACCESS_WRITE);
	hr = device->CreateTexture2D(&texdesc, nullptr, &buftex);
	if (FAILED(hr))
	{
		PanicAlert("Failed to create font texture");
		return hr;
	}
	D3D::SetDebugObjectName(buftex, "texture of a CD3DFont object");

	// Lock the surface and write the alpha values for the set pixels
	D3D11_MAPPED_SUBRESOURCE texmap;
	hr = context->Map(buftex, 0, D3D11_MAP_WRITE_DISCARD, 0, &texmap);
	if (FAILED(hr)) PanicAlert("Failed to map a texture at %s %d\n", __FILE__, __LINE__);

	for (y = 0; y < m_dwTexHeight; y++)
	{
		u32* pDst32 = (u32*)((u8*)texmap.pData + y * texmap.RowPitch);
		for (x = 0; x < m_dwTexWidth; x++)
		{
			const u8 bAlpha = (pBitmapBits[m_dwTexWidth * y + x] & 0xff);
			*pDst32++ = (((bAlpha << 4) | bAlpha) << 24) | 0xFFFFFF;
		}
	}

	// Done updating texture, so clean up used objects
	context->Unmap(buftex, 0);
	hr = D3D::device->CreateShaderResourceView(buftex, nullptr, ToAddr(m_pTexture));
	if (FAILED(hr)) PanicAlert("Failed to create shader resource view at %s %d\n", __FILE__, __LINE__);
	SAFE_RELEASE(buftex);

	SelectObject(hDC, hOldbmBitmap);
	DeleteObject(hbmBitmap);

	SelectObject(hDC, hOldFont);
	DeleteObject(hFont);

	// setup device objects for drawing
	m_pshader = D3D::CompileAndCreatePixelShader(fontpixshader);
	if (m_pshader == nullptr) PanicAlert("Failed to create pixel shader, %s %d\n", __FILE__, __LINE__);
	D3D::SetDebugObjectName(m_pshader.get(), "pixel shader of a CD3DFont object");

	D3DBlob vsbytecode;
	D3D::CompileShader(DX11::D3D::ShaderType::Vertex, fontvertshader, vsbytecode);
	if (vsbytecode.Data() == nullptr) PanicAlert("Failed to compile vertex shader, %s %d\n", __FILE__, __LINE__);
	m_vshader = D3D::CreateVertexShaderFromByteCode(vsbytecode);
	if (m_vshader.get() == nullptr) PanicAlert("Failed to create vertex shader, %s %d\n", __FILE__, __LINE__);
	D3D::SetDebugObjectName(m_vshader.get(), "vertex shader of a CD3DFont object");

	const D3D11_INPUT_ELEMENT_DESC desc[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	};
	hr = D3D::device->CreateInputLayout(desc, 3, vsbytecode.Data(), vsbytecode.Size(), ToAddr(m_InputLayout));
	if (FAILED(hr)) PanicAlert("Failed to create input layout, %s %d\n", __FILE__, __LINE__);

	D3D11_BLEND_DESC blenddesc;
	blenddesc.AlphaToCoverageEnable = FALSE;
	blenddesc.IndependentBlendEnable = FALSE;
	blenddesc.RenderTarget[0].BlendEnable = TRUE;
	blenddesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
	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_INV_SRC_ALPHA;
	blenddesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
	hr = D3D::device->CreateBlendState(&blenddesc, ToAddr(m_blendstate));
	CHECK(hr == S_OK, "Create font blend state");
	D3D::SetDebugObjectName(m_blendstate.get(), "blend state of a CD3DFont object");

	D3D11_RASTERIZER_DESC rastdesc = CD3D11_RASTERIZER_DESC(D3D11_FILL_SOLID, D3D11_CULL_NONE, false, 0, 0.f, 0.f, false, false, false, false);
	hr = D3D::device->CreateRasterizerState(&rastdesc, ToAddr(m_raststate));
	CHECK(hr == S_OK, "Create font rasterizer state");
	D3D::SetDebugObjectName(m_raststate.get(), "rasterizer state of a CD3DFont object");

	D3D11_BUFFER_DESC vbdesc = CD3D11_BUFFER_DESC(MAX_NUM_VERTICES*sizeof(FONT2DVERTEX), D3D11_BIND_VERTEX_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE);
	if (FAILED(hr = device->CreateBuffer(&vbdesc, nullptr, ToAddr(m_pVB))))
	{
		PanicAlert("Failed to create font vertex buffer at %s, line %d\n", __FILE__, __LINE__);
		return hr;
	}
	D3D::SetDebugObjectName(m_pVB.get(), "vertex buffer of a CD3DFont object");
	return S_OK;
}
Exemplo n.º 14
0
bool D3D11Context::startup (void* hwnd)
{
    UINT flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;

#ifdef _DEBUG
    flags |= D3D11_CREATE_DEVICE_DEBUG;
#endif

    D3D_FEATURE_LEVEL featureLevels[] =
    {
        D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0,
    };

    if (m_failed (::D3D11CreateDevice (nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, flags, featureLevels, numElementsInArray (featureLevels), D3D11_SDK_VERSION, device, &featureLevel, contextIM)))
    {
        if (m_failed (::D3D11CreateDevice (nullptr, D3D_DRIVER_TYPE_WARP, nullptr, flags, featureLevels, numElementsInArray (featureLevels), D3D11_SDK_VERSION, device, &featureLevel, contextIM)))
            return false;
    }

    Hold<IDXGIDevice2> dxgiDevice;
    if (m_failed (device.as (dxgiDevice)))
        return false;

    Hold<IDXGIAdapter> dxgiAdapter;
    if (m_failed (dxgiDevice->GetAdapter (dxgiAdapter)))
        return false;

    Hold<IDXGIFactory2> dxgiFactory;
    if (m_failed (dxgiAdapter->GetParent (__uuidof (IDXGIFactory2), dxgiFactory)))
        return false;

    DXGI_SWAP_CHAIN_DESC1 desc;

    desc.Width = 0;
    desc.Height = 0;
    desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
    desc.Stereo = false;
    desc.SampleDesc.Count = 1;
    desc.SampleDesc.Quality = 0;
    desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    desc.BufferCount = 2;
    desc.Scaling = DXGI_SCALING_STRETCH; // DXGI_SCALING_NONE is not supported on Windows7
    desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
    desc.AlphaMode = DXGI_ALPHA_MODE_IGNORE;
    desc.Flags = 0;

    if (m_failed (dxgiFactory->CreateSwapChainForHwnd (device, (HWND)hwnd, &desc, nullptr, nullptr, swapchain)))
        return false;

    Hold<ID3D11Texture2D> backBuf;
    if (m_failed (swapchain->GetBuffer (0, __uuidof (ID3D11Texture2D), backBuf)))
        return false;

    if (m_failed (device->CreateRenderTargetView (backBuf, nullptr, backBufRTView)))
        return false;

    RECT rect;
    ::GetClientRect ((HWND)hwnd, &rect);
    if (m_isnull (depthBuf.set (createTexture2DRT (rect.right - rect.left, rect.bottom - rect.top, 1, DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT))))
        return false;

    if (m_isnull (depthBufDSView.set (createDepthStencilView (depthBuf, 0, DXGI_FORMAT_D32_FLOAT))))
        return false;

    if (m_isnull (depthBufSRView.set (createShaderResourceView (depthBuf, DXGI_FORMAT_R32_FLOAT))))
        return false;

    // common sampler states
    {
        D3D11_SAMPLER_DESC _ = CD3D11_SAMPLER_DESC (D3D11_DEFAULT);
        _.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
        _.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
        _.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
        _.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
        if (m_isnull (sampWrapLinear.set (createSamplerState (_))))
            return false;
    }
    {
        D3D11_SAMPLER_DESC _ = CD3D11_SAMPLER_DESC (D3D11_DEFAULT);
        _.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
        _.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
        _.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
        _.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
        if (m_isnull (sampWrapPoint.set (createSamplerState (_))))
            return false;
    }
    {
        D3D11_SAMPLER_DESC _ = CD3D11_SAMPLER_DESC (D3D11_DEFAULT);
        _.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
        _.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
        _.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
        _.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
        if (m_isnull (sampClampLinear.set (createSamplerState (_))))
            return false;
    }
    {
        D3D11_SAMPLER_DESC _ = CD3D11_SAMPLER_DESC (D3D11_DEFAULT);
        _.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
        _.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
        _.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
        _.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
        if (m_isnull (sampClampPoint.set (createSamplerState (_))))
            return false;
    }

    // common rasterizer state
    {
        D3D11_RASTERIZER_DESC _ = CD3D11_RASTERIZER_DESC (D3D11_DEFAULT);
        _.CullMode = D3D11_CULL_NONE;
        _.FrontCounterClockwise = FALSE;
        if (m_isnull (rastCullNone.set (createRasterizerState (_))))
            return false;
    }

    {
        D3D11_RASTERIZER_DESC _ = CD3D11_RASTERIZER_DESC (D3D11_DEFAULT);
        _.CullMode = D3D11_CULL_FRONT;
        _.FrontCounterClockwise = FALSE;
        if (m_isnull (rastCWCullFront.set (createRasterizerState (_))))
            return false;
    }

    {
        D3D11_RASTERIZER_DESC _ = CD3D11_RASTERIZER_DESC (D3D11_DEFAULT);
        _.CullMode = D3D11_CULL_BACK;
        _.FrontCounterClockwise = FALSE;
        if (m_isnull (rastCWCullBack.set (createRasterizerState (_))))
            return false;
    }

    {
        D3D11_RASTERIZER_DESC _ = CD3D11_RASTERIZER_DESC (D3D11_DEFAULT);
        _.CullMode = D3D11_CULL_FRONT;
        _.FrontCounterClockwise = TRUE;
        if (m_isnull (rastCCWCullFront.set (createRasterizerState (_))))
            return false;
    }

    {
        D3D11_RASTERIZER_DESC _ = CD3D11_RASTERIZER_DESC (D3D11_DEFAULT);
        _.CullMode = D3D11_CULL_BACK;
        _.FrontCounterClockwise = TRUE;
        if (m_isnull (rastCCWCullBack.set (createRasterizerState (_))))
            return false;
    }

    // common depth stencil state
    {
        D3D11_DEPTH_STENCIL_DESC _ = CD3D11_DEPTH_STENCIL_DESC (D3D11_DEFAULT);
        _.DepthEnable = TRUE;
        _.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
        if (m_isnull (depthTestOnWriteOn.set (createDepthStencilState (_))))
            return false;
    }

    {
        D3D11_DEPTH_STENCIL_DESC _ = CD3D11_DEPTH_STENCIL_DESC (D3D11_DEFAULT);
        _.DepthEnable = TRUE;
        _.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
        if (m_isnull (depthTestOnWriteOff.set (createDepthStencilState (_))))
            return false;
    }

    {
        D3D11_DEPTH_STENCIL_DESC _ = CD3D11_DEPTH_STENCIL_DESC (D3D11_DEFAULT);
        _.DepthEnable = FALSE;
        _.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
        if (m_isnull (depthTestOffWriteOn.set (createDepthStencilState (_))))
            return false;
    }

    {
        D3D11_DEPTH_STENCIL_DESC _ = CD3D11_DEPTH_STENCIL_DESC (D3D11_DEFAULT);
        _.DepthEnable = FALSE;
        _.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
        if (m_isnull (depthTestOffWriteOff.set (createDepthStencilState (_))))
            return false;
    }

    return true;
}
Exemplo n.º 15
-1
  bool InitD3D11GUIRendering( RENDERER_SETTINGS * settings )
  {
    ID3DBlob * pCode = NULL;
    ID3DBlob * pErrors = NULL;
    if (D3DCompile( defaultGUIPixelShader, strlen(defaultGUIPixelShader), NULL, NULL, NULL, "main", "ps_4_0", NULL, NULL, &pCode, &pErrors ) != S_OK)
    {
      printf("[Renderer] D3DCompile (PS) failed\n");
      return false;
    }

    if (pDevice->CreatePixelShader( pCode->GetBufferPointer(), pCode->GetBufferSize(), NULL, &pGUIPixelShader ) != S_OK)
    {
      printf("[Renderer] CreatePixelShader failed\n");
      return false;
    }

    if (D3DCompile( defaultGUIVertexShader, strlen(defaultGUIVertexShader), NULL, NULL, NULL, "main", "vs_4_0", NULL, NULL, &pCode, &pErrors ) != S_OK)
    {
      printf("[Renderer] D3DCompile (VS) failed\n");
      return false;
    }

    if (pDevice->CreateVertexShader( pCode->GetBufferPointer(), pCode->GetBufferSize(), NULL, &pGUIVertexShader ) != S_OK)
    {
      printf("[Renderer] CreateVertexShader failed\n");
      return false;
    }

    D3D11_BUFFER_DESC desc;
    ZeroMemory(&desc, sizeof(D3D11_BUFFER_DESC));

    desc.ByteWidth = sizeof(float) * 7 * GUIQUADVB_SIZE;
    desc.Usage = D3D11_USAGE_DYNAMIC;
    desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;

    if (pDevice->CreateBuffer(&desc, NULL, &pGUIQuadVB) != S_OK)
    {
      printf("[Renderer] CreateBuffer (VB) failed\n");
      return false;
    }

    static D3D11_INPUT_ELEMENT_DESC pGUIDesc[] =
    {
      {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0 * sizeof(float), D3D11_INPUT_PER_VERTEX_DATA, 0},
      {"COLOR"   , 0, DXGI_FORMAT_R8G8B8A8_UNORM , 0, 3 * sizeof(float), D3D11_INPUT_PER_VERTEX_DATA, 0},
      {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT   , 0, 4 * sizeof(float), D3D11_INPUT_PER_VERTEX_DATA, 0},
      {"TEXCOORD", 1, DXGI_FORMAT_R32_FLOAT      , 0, 6 * sizeof(float), D3D11_INPUT_PER_VERTEX_DATA, 0},
    };

    if (pDevice->CreateInputLayout( pGUIDesc, 4, pCode->GetBufferPointer(), pCode->GetBufferSize(), &pGUIQuadLayout) != S_OK)
    {
      printf("[Renderer] CreateInputLayout failed\n");
      return false;
    }

    D3D11_BUFFER_DESC cbDesc;
    ZeroMemory( &cbDesc, sizeof(D3D11_BUFFER_DESC) );
    cbDesc.ByteWidth = sizeof( float ) * 4 * 4 * 2;
    cbDesc.Usage = D3D11_USAGE_DYNAMIC;
    cbDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
    cbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;

    MatrixOrthoOffCenterLH( pGUIMatrix, 0, nWidth, nHeight, 0, -1.0f, 1.0f );
    
    D3D11_SUBRESOURCE_DATA subData;
    ZeroMemory( &subData, sizeof(D3D11_SUBRESOURCE_DATA) );
    subData.pSysMem = &pGUIMatrix;

    if (pDevice->CreateBuffer( &cbDesc, &subData, &pGUIConstantBuffer ) != S_OK)
    {
      printf("[Renderer] CreateBuffer (CB) failed\n");
      return false;
    }

    D3D11_BLEND_DESC blendDesc = CD3D11_BLEND_DESC( CD3D11_DEFAULT() );
    blendDesc.RenderTarget[0].BlendEnable = true;
    blendDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
    blendDesc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
    if (pDevice->CreateBlendState( &blendDesc, &pGUIBlendState ) != S_OK)
      return false;

    D3D11_RASTERIZER_DESC rastDesc = CD3D11_RASTERIZER_DESC( CD3D11_DEFAULT() );
    rastDesc.ScissorEnable = true;
    if (pDevice->CreateRasterizerState( &rastDesc, &pGUIRasterizerState ) != S_OK)
      return false;

    return true;
  }