XML test

C code posted
created at 17 Jun 13:56, updated at 21 Aug 16:05

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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;
}
1.42 KB in 6 ms with coderay