summaryrefslogtreecommitdiff
path: root/src/gallium/state_trackers/d3d1x/progs/d3d10app
diff options
context:
space:
mode:
authorLuca Barbieri <luca@luca-barbieri.com>2010-09-24 15:08:57 +0200
committerLuca Barbieri <luca@luca-barbieri.com>2010-09-24 15:12:20 +0200
commit11547654295cadcfde69f6c2361f50a4cd17fc7a (patch)
treef2b123cb97cb3ee49e1e41b9f78db6955a2717d2 /src/gallium/state_trackers/d3d1x/progs/d3d10app
parent7e81c67c8b16c6f87e01320c9d9a7455a52cf91b (diff)
d3d1x: CRLF -> LF in progs
Diffstat (limited to 'src/gallium/state_trackers/d3d1x/progs/d3d10app')
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d10app/d3d10app.h102
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d10app/d3d10winmain.cpp376
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d10app/d3d10x11main.cpp308
3 files changed, 393 insertions, 393 deletions
diff --git a/src/gallium/state_trackers/d3d1x/progs/d3d10app/d3d10app.h b/src/gallium/state_trackers/d3d1x/progs/d3d10app/d3d10app.h
index c27e66ed54..59fe338f56 100755
--- a/src/gallium/state_trackers/d3d1x/progs/d3d10app/d3d10app.h
+++ b/src/gallium/state_trackers/d3d1x/progs/d3d10app/d3d10app.h
@@ -1,51 +1,51 @@
-/**************************************************************************
- *
- * Copyright 2010 Luca Barbieri
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial
- * portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-#ifndef D3D10APP_H
-#define D3D10APP_H
-
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-#include <objbase.h>
-#include <d3d10_1.h>
-#include <assert.h>
-#include <stdio.h>
-#include <float.h>
-
-#define ensure(x) do {HRESULT __hr = (x); if(!SUCCEEDED(__hr)) {fprintf(stderr, "COM error %08x\n", __hr); abort();}} while(0)
-
-struct d3d10_application
-{
- virtual ~d3d10_application() {}
-
- virtual void draw(ID3D10Device* ctx, ID3D10RenderTargetView* rtv, unsigned width, unsigned height, double time) = 0;
- virtual bool init(ID3D10Device* dev, int argc, char** argv) = 0;
-};
-
-/* this is the entry point you must provide */
-extern "C" d3d10_application* d3d10_application_create();
-
-#endif
+/**************************************************************************
+ *
+ * Copyright 2010 Luca Barbieri
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#ifndef D3D10APP_H
+#define D3D10APP_H
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <objbase.h>
+#include <d3d10_1.h>
+#include <assert.h>
+#include <stdio.h>
+#include <float.h>
+
+#define ensure(x) do {HRESULT __hr = (x); if(!SUCCEEDED(__hr)) {fprintf(stderr, "COM error %08x\n", __hr); abort();}} while(0)
+
+struct d3d10_application
+{
+ virtual ~d3d10_application() {}
+
+ virtual void draw(ID3D10Device* ctx, ID3D10RenderTargetView* rtv, unsigned width, unsigned height, double time) = 0;
+ virtual bool init(ID3D10Device* dev, int argc, char** argv) = 0;
+};
+
+/* this is the entry point you must provide */
+extern "C" d3d10_application* d3d10_application_create();
+
+#endif
diff --git a/src/gallium/state_trackers/d3d1x/progs/d3d10app/d3d10winmain.cpp b/src/gallium/state_trackers/d3d1x/progs/d3d10app/d3d10winmain.cpp
index ac4798a108..94680977eb 100755
--- a/src/gallium/state_trackers/d3d1x/progs/d3d10app/d3d10winmain.cpp
+++ b/src/gallium/state_trackers/d3d1x/progs/d3d10app/d3d10winmain.cpp
@@ -1,188 +1,188 @@
-/**************************************************************************
- *
- * Copyright 2010 Luca Barbieri
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial
- * portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-#define INITGUID
-#include "d3d10app.h"
-#include "stdio.h"
-
-static d3d10_application* app;
-static IDXGISwapChain* swap_chain;
-static unsigned width, height;
-static DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
-static ID3D10Device* dev;
-static ID3D10Device* ctx;
-static int frames = 0;
-static int buffer_count = 1;
-
-LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
-{
- switch (message)
- {
- case WM_SIZE:
- width = lParam & 0xffff;
- height = lParam >> 16;
-
- swap_chain->ResizeBuffers(buffer_count, width, height, format, 0);
- frames = 0;
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(hwnd, message, wParam, lParam);
- }
- return 0;
-}
-
-int main(int argc, char** argv)
-{
- HINSTANCE hInstance = GetModuleHandle(NULL);
- WNDCLASSEXA wcex;
-
- wcex.cbSize = sizeof(WNDCLASSEX);
-
- wcex.style = CS_HREDRAW | CS_VREDRAW;
- wcex.lpfnWndProc = WndProc;
- wcex.cbClsExtra = 0;
- wcex.cbWndExtra = 0;
- wcex.hInstance = hInstance;
- wcex.hIcon = 0;
- wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
- wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
- wcex.lpszMenuName = 0;
- wcex.lpszClassName = "d3d10";
- wcex.hIconSm = 0;
-
- RegisterClassExA(&wcex);
-
- HWND hwnd = CreateWindowA("d3d10", "d3d10", WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
-
- if(!hwnd)
- return FALSE;
-
- RECT rc;
- GetClientRect(hwnd, &rc );
- width = rc.right - rc.left;
- height = rc.bottom - rc.top;
-
- DXGI_SWAP_CHAIN_DESC swap_chain_desc;
- memset(&swap_chain_desc, 0, sizeof(swap_chain_desc));
- swap_chain_desc.BufferDesc.Width = width;
- swap_chain_desc.BufferDesc.Height = height;
- swap_chain_desc.BufferDesc.Format = format;
- swap_chain_desc.SampleDesc.Count = 1;
- swap_chain_desc.SampleDesc.Quality = 0;
- swap_chain_desc.OutputWindow = hwnd;
- swap_chain_desc.Windowed = TRUE;
- swap_chain_desc.BufferCount = buffer_count;
- swap_chain_desc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
- swap_chain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
- swap_chain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
-
- D3D10_FEATURE_LEVEL1 feature_level = D3D10_FEATURE_LEVEL_10_0;
-
- HRESULT hr;
- if(1)
- {
- hr = D3D10CreateDeviceAndSwapChain(
- NULL,
- D3D10_DRIVER_TYPE_HARDWARE,
- NULL,
- D3D10_CREATE_DEVICE_SINGLETHREADED, // | D3D10_CREATE_DEVICE_DEBUG,
- D3D10_SDK_VERSION,
- &swap_chain_desc,
- &swap_chain,
- &dev);
- }
- else
- {
- hr = D3D10CreateDeviceAndSwapChain1(
- NULL,
- D3D10_DRIVER_TYPE_HARDWARE,
- NULL,
- D3D10_CREATE_DEVICE_SINGLETHREADED, // | D3D10_CREATE_DEVICE_DEBUG,
- feature_level,
- D3D10_SDK_VERSION,
- &swap_chain_desc,
- &swap_chain,
- (ID3D10Device1**)&dev);
- }
-
- if(!SUCCEEDED(hr))
- {
- fprintf(stderr, "Failed to create D3D10 device (hresult %08x)\n", hr);
- return 1;
- }
-
- ctx = dev;
-
- app = d3d10_application_create();
- if(!app->init(dev, argc, argv))
- return 1;
-
- ShowWindow(hwnd, SW_SHOWDEFAULT);
- UpdateWindow(hwnd);
-
- LARGE_INTEGER freq;
- QueryPerformanceFrequency(&freq);
- double period = 1.0 / (double)freq.QuadPart;
- LARGE_INTEGER ctime_li;
- QueryPerformanceCounter(&ctime_li);
- double start_time = ctime_li.QuadPart * period;
-
- MSG msg;
- for(;;)
- {
- if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
- {
- if(msg.message == WM_QUIT)
- break;
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- else if(width && height)
- {
- ID3D10Texture2D* tex;
- static ID3D10RenderTargetView* rtv;
- ensure(swap_chain->GetBuffer(0, __uuidof(tex), (void**)&tex));
- ensure(dev->CreateRenderTargetView(tex, NULL, &rtv));
-
- QueryPerformanceCounter(&ctime_li);
- double ctime = (double)ctime_li.QuadPart * period - start_time;
-
- app->draw(ctx, rtv, width, height, ctime);
- ctx->OMSetRenderTargets(0, 0, 0);
-
- swap_chain->Present(0, 0);
- rtv->Release();
- tex->Release();
- }
- else
- WaitMessage();
- }
- return (int) msg.wParam;
-}
+/**************************************************************************
+ *
+ * Copyright 2010 Luca Barbieri
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#define INITGUID
+#include "d3d10app.h"
+#include "stdio.h"
+
+static d3d10_application* app;
+static IDXGISwapChain* swap_chain;
+static unsigned width, height;
+static DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
+static ID3D10Device* dev;
+static ID3D10Device* ctx;
+static int frames = 0;
+static int buffer_count = 1;
+
+LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ switch (message)
+ {
+ case WM_SIZE:
+ width = lParam & 0xffff;
+ height = lParam >> 16;
+
+ swap_chain->ResizeBuffers(buffer_count, width, height, format, 0);
+ frames = 0;
+ break;
+ case WM_DESTROY:
+ PostQuitMessage(0);
+ break;
+ default:
+ return DefWindowProc(hwnd, message, wParam, lParam);
+ }
+ return 0;
+}
+
+int main(int argc, char** argv)
+{
+ HINSTANCE hInstance = GetModuleHandle(NULL);
+ WNDCLASSEXA wcex;
+
+ wcex.cbSize = sizeof(WNDCLASSEX);
+
+ wcex.style = CS_HREDRAW | CS_VREDRAW;
+ wcex.lpfnWndProc = WndProc;
+ wcex.cbClsExtra = 0;
+ wcex.cbWndExtra = 0;
+ wcex.hInstance = hInstance;
+ wcex.hIcon = 0;
+ wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
+ wcex.lpszMenuName = 0;
+ wcex.lpszClassName = "d3d10";
+ wcex.hIconSm = 0;
+
+ RegisterClassExA(&wcex);
+
+ HWND hwnd = CreateWindowA("d3d10", "d3d10", WS_OVERLAPPEDWINDOW,
+ CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
+
+ if(!hwnd)
+ return FALSE;
+
+ RECT rc;
+ GetClientRect(hwnd, &rc );
+ width = rc.right - rc.left;
+ height = rc.bottom - rc.top;
+
+ DXGI_SWAP_CHAIN_DESC swap_chain_desc;
+ memset(&swap_chain_desc, 0, sizeof(swap_chain_desc));
+ swap_chain_desc.BufferDesc.Width = width;
+ swap_chain_desc.BufferDesc.Height = height;
+ swap_chain_desc.BufferDesc.Format = format;
+ swap_chain_desc.SampleDesc.Count = 1;
+ swap_chain_desc.SampleDesc.Quality = 0;
+ swap_chain_desc.OutputWindow = hwnd;
+ swap_chain_desc.Windowed = TRUE;
+ swap_chain_desc.BufferCount = buffer_count;
+ swap_chain_desc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
+ swap_chain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
+ swap_chain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
+
+ D3D10_FEATURE_LEVEL1 feature_level = D3D10_FEATURE_LEVEL_10_0;
+
+ HRESULT hr;
+ if(1)
+ {
+ hr = D3D10CreateDeviceAndSwapChain(
+ NULL,
+ D3D10_DRIVER_TYPE_HARDWARE,
+ NULL,
+ D3D10_CREATE_DEVICE_SINGLETHREADED, // | D3D10_CREATE_DEVICE_DEBUG,
+ D3D10_SDK_VERSION,
+ &swap_chain_desc,
+ &swap_chain,
+ &dev);
+ }
+ else
+ {
+ hr = D3D10CreateDeviceAndSwapChain1(
+ NULL,
+ D3D10_DRIVER_TYPE_HARDWARE,
+ NULL,
+ D3D10_CREATE_DEVICE_SINGLETHREADED, // | D3D10_CREATE_DEVICE_DEBUG,
+ feature_level,
+ D3D10_SDK_VERSION,
+ &swap_chain_desc,
+ &swap_chain,
+ (ID3D10Device1**)&dev);
+ }
+
+ if(!SUCCEEDED(hr))
+ {
+ fprintf(stderr, "Failed to create D3D10 device (hresult %08x)\n", hr);
+ return 1;
+ }
+
+ ctx = dev;
+
+ app = d3d10_application_create();
+ if(!app->init(dev, argc, argv))
+ return 1;
+
+ ShowWindow(hwnd, SW_SHOWDEFAULT);
+ UpdateWindow(hwnd);
+
+ LARGE_INTEGER freq;
+ QueryPerformanceFrequency(&freq);
+ double period = 1.0 / (double)freq.QuadPart;
+ LARGE_INTEGER ctime_li;
+ QueryPerformanceCounter(&ctime_li);
+ double start_time = ctime_li.QuadPart * period;
+
+ MSG msg;
+ for(;;)
+ {
+ if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
+ {
+ if(msg.message == WM_QUIT)
+ break;
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ else if(width && height)
+ {
+ ID3D10Texture2D* tex;
+ static ID3D10RenderTargetView* rtv;
+ ensure(swap_chain->GetBuffer(0, __uuidof(tex), (void**)&tex));
+ ensure(dev->CreateRenderTargetView(tex, NULL, &rtv));
+
+ QueryPerformanceCounter(&ctime_li);
+ double ctime = (double)ctime_li.QuadPart * period - start_time;
+
+ app->draw(ctx, rtv, width, height, ctime);
+ ctx->OMSetRenderTargets(0, 0, 0);
+
+ swap_chain->Present(0, 0);
+ rtv->Release();
+ tex->Release();
+ }
+ else
+ WaitMessage();
+ }
+ return (int) msg.wParam;
+}
diff --git a/src/gallium/state_trackers/d3d1x/progs/d3d10app/d3d10x11main.cpp b/src/gallium/state_trackers/d3d1x/progs/d3d10app/d3d10x11main.cpp
index efbe322fe6..8f07380056 100755
--- a/src/gallium/state_trackers/d3d1x/progs/d3d10app/d3d10x11main.cpp
+++ b/src/gallium/state_trackers/d3d1x/progs/d3d10app/d3d10x11main.cpp
@@ -1,154 +1,154 @@
-/**************************************************************************
- *
- * Copyright 2010 Luca Barbieri
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial
- * portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-#include "d3d10app.h"
-#include <X11/Xlib.h>
-#include <galliumdxgi.h>
-#include <sys/time.h>
-
-static d3d10_application* app;
-static IDXGISwapChain* swap_chain;
-unsigned width, height;
-DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
-static ID3D10Device* dev;
-static ID3D10Device* ctx;
-
-double get_time()
-{
- struct timeval tv;
- gettimeofday(&tv, 0);
- return (double)tv.tv_sec + (double)tv.tv_usec * 0.000001;
-}
-
-int main(int argc, char** argv)
-{
- Display* dpy = XOpenDisplay(0);
- Visual* visual = DefaultVisual(dpy, DefaultScreen(dpy));
- Colormap cmap = XCreateColormap(dpy, RootWindow(dpy, DefaultScreen(dpy)), visual, AllocNone);
- XSetWindowAttributes swa;
- swa.colormap = cmap;
- swa.border_pixel = 0;
- swa.event_mask = StructureNotifyMask;
- width = 512;
- height = 512;
- Window win = XCreateWindow(dpy, RootWindow(dpy, DefaultScreen(dpy)), 0, 0, width, height, 0, CopyFromParent, InputOutput, visual, CWBorderPixel | CWColormap| CWEventMask, &swa);
- XMapWindow(dpy, win);
-
- GalliumDXGIUseX11Display(dpy, 0);
-
- DXGI_SWAP_CHAIN_DESC swap_chain_desc;
- memset(&swap_chain_desc, 0, sizeof(swap_chain_desc));
- swap_chain_desc.BufferDesc.Width = width;
- swap_chain_desc.BufferDesc.Height = height;
- swap_chain_desc.BufferDesc.Format = format;
- swap_chain_desc.SampleDesc.Count = 1;
- swap_chain_desc.SampleDesc.Quality = 0;
- swap_chain_desc.OutputWindow = (HWND)win;
- swap_chain_desc.Windowed = TRUE;
- swap_chain_desc.BufferCount = 3;
- swap_chain_desc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
- swap_chain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
-
- D3D10_FEATURE_LEVEL1 feature_level = D3D10_FEATURE_LEVEL_10_0;
-
- HRESULT hr;
- if(0)
- {
- hr = D3D10CreateDeviceAndSwapChain(
- NULL,
- D3D10_DRIVER_TYPE_HARDWARE,
- NULL,
- D3D10_CREATE_DEVICE_SINGLETHREADED,
- D3D10_SDK_VERSION,
- &swap_chain_desc,
- &swap_chain,
- &dev);
- }
- else
- {
- hr = D3D10CreateDeviceAndSwapChain1(
- NULL,
- D3D10_DRIVER_TYPE_HARDWARE,
- NULL,
- D3D10_CREATE_DEVICE_SINGLETHREADED,
- feature_level,
- D3D10_SDK_VERSION,
- &swap_chain_desc,
- &swap_chain,
- (ID3D10Device1**)&dev);
- }
- if(!SUCCEEDED(hr))
- {
- fprintf(stderr, "Failed to create D3D10 device (hresult %08x)\n", hr);
- return 1;
- }
- ctx = dev;
-
- app = d3d10_application_create();
- if(!app->init(dev, argc, argv))
- return 1;
-
- double start_time = get_time();
-
- MSG msg;
- for(;;)
- {
- XEvent event;
- if(XPending(dpy))
- {
- XNextEvent(dpy, &event);
- if(event.type == DestroyNotify)
- break;
- switch(event.type)
- {
- case ConfigureNotify:
- width = event.xconfigure.width;
- height = event.xconfigure.height;
- swap_chain->ResizeBuffers(3, width, height, format, 0);
- break;
- }
- }
- else if(width && height)
- {
- ID3D10Texture2D* tex;
- ID3D10RenderTargetView* rtv;
- ensure(swap_chain->GetBuffer(0, IID_ID3D10Texture2D, (void**)&tex));
- ensure(dev->CreateRenderTargetView(tex, NULL, &rtv));
-
- double ctime = get_time() - start_time;
-
- app->draw(ctx, rtv, width, height, ctime);
- ctx->OMSetRenderTargets(0, 0, 0);
-
- tex->Release();
- rtv->Release();
- swap_chain->Present(0, 0);
- }
- else
- XPeekEvent(dpy, &event);
- }
- return (int) msg.wParam;
-}
+/**************************************************************************
+ *
+ * Copyright 2010 Luca Barbieri
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#include "d3d10app.h"
+#include <X11/Xlib.h>
+#include <galliumdxgi.h>
+#include <sys/time.h>
+
+static d3d10_application* app;
+static IDXGISwapChain* swap_chain;
+unsigned width, height;
+DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
+static ID3D10Device* dev;
+static ID3D10Device* ctx;
+
+double get_time()
+{
+ struct timeval tv;
+ gettimeofday(&tv, 0);
+ return (double)tv.tv_sec + (double)tv.tv_usec * 0.000001;
+}
+
+int main(int argc, char** argv)
+{
+ Display* dpy = XOpenDisplay(0);
+ Visual* visual = DefaultVisual(dpy, DefaultScreen(dpy));
+ Colormap cmap = XCreateColormap(dpy, RootWindow(dpy, DefaultScreen(dpy)), visual, AllocNone);
+ XSetWindowAttributes swa;
+ swa.colormap = cmap;
+ swa.border_pixel = 0;
+ swa.event_mask = StructureNotifyMask;
+ width = 512;
+ height = 512;
+ Window win = XCreateWindow(dpy, RootWindow(dpy, DefaultScreen(dpy)), 0, 0, width, height, 0, CopyFromParent, InputOutput, visual, CWBorderPixel | CWColormap| CWEventMask, &swa);
+ XMapWindow(dpy, win);
+
+ GalliumDXGIUseX11Display(dpy, 0);
+
+ DXGI_SWAP_CHAIN_DESC swap_chain_desc;
+ memset(&swap_chain_desc, 0, sizeof(swap_chain_desc));
+ swap_chain_desc.BufferDesc.Width = width;
+ swap_chain_desc.BufferDesc.Height = height;
+ swap_chain_desc.BufferDesc.Format = format;
+ swap_chain_desc.SampleDesc.Count = 1;
+ swap_chain_desc.SampleDesc.Quality = 0;
+ swap_chain_desc.OutputWindow = (HWND)win;
+ swap_chain_desc.Windowed = TRUE;
+ swap_chain_desc.BufferCount = 3;
+ swap_chain_desc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
+ swap_chain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
+
+ D3D10_FEATURE_LEVEL1 feature_level = D3D10_FEATURE_LEVEL_10_0;
+
+ HRESULT hr;
+ if(0)
+ {
+ hr = D3D10CreateDeviceAndSwapChain(
+ NULL,
+ D3D10_DRIVER_TYPE_HARDWARE,
+ NULL,
+ D3D10_CREATE_DEVICE_SINGLETHREADED,
+ D3D10_SDK_VERSION,
+ &swap_chain_desc,
+ &swap_chain,
+ &dev);
+ }
+ else
+ {
+ hr = D3D10CreateDeviceAndSwapChain1(
+ NULL,
+ D3D10_DRIVER_TYPE_HARDWARE,
+ NULL,
+ D3D10_CREATE_DEVICE_SINGLETHREADED,
+ feature_level,
+ D3D10_SDK_VERSION,
+ &swap_chain_desc,
+ &swap_chain,
+ (ID3D10Device1**)&dev);
+ }
+ if(!SUCCEEDED(hr))
+ {
+ fprintf(stderr, "Failed to create D3D10 device (hresult %08x)\n", hr);
+ return 1;
+ }
+ ctx = dev;
+
+ app = d3d10_application_create();
+ if(!app->init(dev, argc, argv))
+ return 1;
+
+ double start_time = get_time();
+
+ MSG msg;
+ for(;;)
+ {
+ XEvent event;
+ if(XPending(dpy))
+ {
+ XNextEvent(dpy, &event);
+ if(event.type == DestroyNotify)
+ break;
+ switch(event.type)
+ {
+ case ConfigureNotify:
+ width = event.xconfigure.width;
+ height = event.xconfigure.height;
+ swap_chain->ResizeBuffers(3, width, height, format, 0);
+ break;
+ }
+ }
+ else if(width && height)
+ {
+ ID3D10Texture2D* tex;
+ ID3D10RenderTargetView* rtv;
+ ensure(swap_chain->GetBuffer(0, IID_ID3D10Texture2D, (void**)&tex));
+ ensure(dev->CreateRenderTargetView(tex, NULL, &rtv));
+
+ double ctime = get_time() - start_time;
+
+ app->draw(ctx, rtv, width, height, ctime);
+ ctx->OMSetRenderTargets(0, 0, 0);
+
+ tex->Release();
+ rtv->Release();
+ swap_chain->Present(0, 0);
+ }
+ else
+ XPeekEvent(dpy, &event);
+ }
+ return (int) msg.wParam;
+}