Title / Description
Code class DepthOfField { // Autofocus ID3D10Texture1D *autofocus_texture_; // Viewport and texture dimensions UINT width_; UINT height_; }; HRESULT DepthOfField::OnDeviceCreated(ID3D10Device *device) { HRESULT hr; D3D10_TEXTURE1D_DESC tex1d_desc; tex1d_desc.Width = 1; tex1d_desc.MipLevels = 1; tex1d_desc.ArraySize = 1; tex1d_desc.Format = DXGI_FORMAT_R32_TYPELESS; tex1d_desc.Usage = D3D10_USAGE_STAGING; tex1d_desc.BindFlags = 0; tex1d_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ; tex1d_desc.MiscFlags = 0; V(device->CreateTexture1D(&tex1d_desc, NULL, &autofocus_texture_)); return S_OK; } void DepthOfField3::OnWindowResized(ID3D10Device *device, UINT width, UINT height) { width_ = width; height_ = height; } void DepthOfField3::OnDeviceDestroyed(void) { SAFE_RELEASE(autofocus_texture_); } void DepthOfField3::Draw(ID3D10Device *device) { // Autofocus D3D10_BOX box; box.left = width_ / 2; box.right = box.left + 1; box.top = height_ / 2; box.bottom = box.top + 1; box.front = 0; box.back = 1; device->CopySubresourceRegion(autofocus_texture_, 0, 0, 0, 0, depth_texture_, 0, &box); float *data; if (SUCCEEDED(autofocus_texture_->Map(0, D3D10_MAP_READ, 0, (void**)&data))) { focal_plane_depth_ = near_clip*far_clip / ((*data)*(near_clip - far_clip) + far_clip); autofocus_texture_->Unmap(0); } autofocus_ = false; }
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code