1 /**************************************************************************
3 * Copyright 2010 Luca Barbieri
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 **************************************************************************/
30 #include <galliumdxgi.h>
33 static d3d10_application
* app
;
34 static IDXGISwapChain
* swap_chain
;
35 unsigned width
, height
;
36 DXGI_FORMAT format
= DXGI_FORMAT_R8G8B8A8_UNORM
;
37 static ID3D10Device
* dev
;
38 static ID3D10Device
* ctx
;
40 static int attributeList
[] = {
52 return (double)tv
.tv_sec
+ (double)tv
.tv_usec
* 0.000001;
55 int main(int argc
, char** argv
)
57 Display
* dpy
= XOpenDisplay(0);
58 XVisualInfo
* vi
= glXChooseVisual(dpy
, DefaultScreen(dpy
), attributeList
);
59 Colormap cmap
= XCreateColormap(dpy
, RootWindow(dpy
, vi
->screen
), vi
->visual
, AllocNone
);
60 XSetWindowAttributes swa
;
63 swa
.event_mask
= StructureNotifyMask
;
66 Window win
= XCreateWindow(dpy
, RootWindow(dpy
, vi
->screen
), 0, 0, width
, height
, 0, vi
->depth
, InputOutput
, vi
->visual
, CWBorderPixel
| CWColormap
| CWEventMask
, &swa
);
69 GalliumDXGIUseX11Display(dpy
, 0);
71 DXGI_SWAP_CHAIN_DESC swap_chain_desc
;
72 memset(&swap_chain_desc
, 0, sizeof(swap_chain_desc
));
73 swap_chain_desc
.BufferDesc
.Width
= width
;
74 swap_chain_desc
.BufferDesc
.Height
= height
;
75 swap_chain_desc
.BufferDesc
.Format
= format
;
76 swap_chain_desc
.SampleDesc
.Count
= 1;
77 swap_chain_desc
.SampleDesc
.Quality
= 0;
78 swap_chain_desc
.OutputWindow
= (HWND
)win
;
79 swap_chain_desc
.Windowed
= TRUE
;
80 swap_chain_desc
.BufferCount
= 3;
81 swap_chain_desc
.Flags
= DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH
;
82 swap_chain_desc
.BufferUsage
= DXGI_USAGE_RENDER_TARGET_OUTPUT
;
84 D3D10_FEATURE_LEVEL1 feature_level
= D3D10_FEATURE_LEVEL_10_0
;
89 hr
= D3D10CreateDeviceAndSwapChain(
91 D3D10_DRIVER_TYPE_HARDWARE
,
93 D3D10_CREATE_DEVICE_SINGLETHREADED
,
101 hr
= D3D10CreateDeviceAndSwapChain1(
103 D3D10_DRIVER_TYPE_HARDWARE
,
105 D3D10_CREATE_DEVICE_SINGLETHREADED
,
110 (ID3D10Device1
**)&dev
);
114 fprintf(stderr
, "Failed to create D3D10 device (hresult %08x)\n", hr
);
119 app
= d3d10_application_create();
120 if(!app
->init(dev
, argc
, argv
))
123 double start_time
= get_time();
131 XNextEvent(dpy
, &event
);
132 if(event
.type
== DestroyNotify
)
136 case ConfigureNotify
:
137 width
= event
.xconfigure
.width
;
138 height
= event
.xconfigure
.height
;
139 swap_chain
->ResizeBuffers(3, width
, height
, format
, 0);
143 else if(width
&& height
)
145 ID3D10Texture2D
* tex
;
146 ID3D10RenderTargetView
* rtv
;
147 ensure(swap_chain
->GetBuffer(0, IID_ID3D10Texture2D
, (void**)&tex
));
148 ensure(dev
->CreateRenderTargetView(tex
, NULL
, &rtv
));
150 double ctime
= get_time() - start_time
;
152 app
->draw(ctx
, rtv
, width
, height
, ctime
);
153 ctx
->OMSetRenderTargets(0, 0, 0);
157 swap_chain
->Present(0, 0);
160 XPeekEvent(dpy
, &event
);
162 return (int) msg
.wParam
;