4 #include <galliumdxgi.h>
7 static d3d11_application
* app
;
8 static IDXGISwapChain
* swap_chain
;
9 unsigned width
, height
;
10 DXGI_FORMAT format
= DXGI_FORMAT_R8G8B8A8_UNORM
;
11 static ID3D11Device
* dev
;
12 static ID3D11DeviceContext
* ctx
;
14 static int attributeList
[] = {
26 return (double)tv
.tv_sec
+ (double)tv
.tv_usec
* 0.000001;
29 int main(int argc
, char** argv
)
31 Display
* dpy
= XOpenDisplay(0);
32 XVisualInfo
* vi
= glXChooseVisual(dpy
, DefaultScreen(dpy
), attributeList
);
33 Colormap cmap
= XCreateColormap(dpy
, RootWindow(dpy
, vi
->screen
), vi
->visual
, AllocNone
);
34 XSetWindowAttributes swa
;
37 swa
.event_mask
= StructureNotifyMask
;
40 Window win
= XCreateWindow(dpy
, RootWindow(dpy
, vi
->screen
), 0, 0, width
, height
, 0, vi
->depth
, InputOutput
, vi
->visual
, CWBorderPixel
| CWColormap
| CWEventMask
, &swa
);
43 GalliumDXGIUseX11Display(dpy
, 0);
45 DXGI_SWAP_CHAIN_DESC swap_chain_desc
;
46 memset(&swap_chain_desc
, 0, sizeof(swap_chain_desc
));
47 swap_chain_desc
.BufferDesc
.Width
= width
;
48 swap_chain_desc
.BufferDesc
.Height
= height
;
49 swap_chain_desc
.BufferDesc
.Format
= format
;
50 swap_chain_desc
.SampleDesc
.Count
= 1;
51 swap_chain_desc
.SampleDesc
.Quality
= 0;
52 swap_chain_desc
.OutputWindow
= (HWND
)win
;
53 swap_chain_desc
.Windowed
= TRUE
;
54 swap_chain_desc
.BufferCount
= 3;
55 swap_chain_desc
.Flags
= DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH
;
56 swap_chain_desc
.BufferUsage
= DXGI_USAGE_RENDER_TARGET_OUTPUT
;
58 D3D_FEATURE_LEVEL feature_level
= D3D_FEATURE_LEVEL_10_0
;
60 HRESULT hr
=D3D11CreateDeviceAndSwapChain(
62 D3D_DRIVER_TYPE_HARDWARE
,
64 D3D11_CREATE_DEVICE_SINGLETHREADED
,
75 fprintf(stderr
, "Failed to create D3D11 device (hresult %08x)\n", hr
);
79 app
= d3d11_application_create();
80 if(!app
->init(dev
, argc
, argv
))
83 double start_time
= get_time();
91 XNextEvent(dpy
, &event
);
92 if(event
.type
== DestroyNotify
)
97 width
= event
.xconfigure
.width
;
98 height
= event
.xconfigure
.height
;
99 swap_chain
->ResizeBuffers(3, width
, height
, format
, 0);
103 else if(width
&& height
)
105 ID3D11Texture2D
* tex
;
106 ID3D11RenderTargetView
* rtv
;
107 ensure(swap_chain
->GetBuffer(0, IID_ID3D11Texture2D
, (void**)&tex
));
108 ensure(dev
->CreateRenderTargetView(tex
, NULL
, &rtv
));
110 double ctime
= get_time() - start_time
;
112 app
->draw(ctx
, rtv
, width
, height
, ctime
);
113 ctx
->OMSetRenderTargets(0, 0, 0);
117 swap_chain
->Present(0, 0);
120 XPeekEvent(dpy
, &event
);
122 return (int) msg
.wParam
;