D3D8 sample app.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Thu, 3 May 2012 12:31:37 +0000 (13:31 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Thu, 3 May 2012 12:31:37 +0000 (13:31 +0100)
app_driver.py
apps/CMakeLists.txt
apps/d3d8/CMakeLists.txt [new file with mode: 0644]
apps/d3d8/tri.cpp [new file with mode: 0644]
apps/d3d8/tri.ref.txt [new file with mode: 0644]

index 2c7a319a5d556b7006711a70cd0464c4793dc35a..27eb4528394b6ef65ec751f75a6d0022fe48d3d0 100755 (executable)
@@ -175,6 +175,7 @@ class AppDriver(Driver):
         'egl_gl': 'egl',
         'egl_gles1': 'egl',
         'egl_gles2': 'egl',
+        'd3d8': 'd3d8',
         'd3d9': 'd3d9',
     }
 
@@ -236,6 +237,9 @@ class AppDriver(Driver):
 
         self.doubleBuffer = checker.doubleBuffer
 
+        if self.api not in self.api_retrace_map:
+            return
+
         for callNo, refImageFileName in checker.images:
             self.checkImage(callNo, refImageFileName)
         for callNo, refStateFileName in checker.states:
@@ -302,6 +306,9 @@ class AppDriver(Driver):
         open(filename, 'wt').write(s)
 
     def retrace(self):
+        if self.api not in self.api_retrace_map:
+            return
+
         p = self._retrace()
         p.wait()
         if p.returncode != 0:
index 98c41f5ce55b18d25e906e0e206887f22215f677..f75c9f851f7ffb2b580324338ce3f95a85c52270 100644 (file)
@@ -35,3 +35,7 @@ endif ()
 if (DirectX_D3D9_FOUND)
     add_subdirectory (d3d9)
 endif ()
+
+if (DirectX_D3D8_FOUND)
+    add_subdirectory (d3d8)
+endif ()
diff --git a/apps/d3d8/CMakeLists.txt b/apps/d3d8/CMakeLists.txt
new file mode 100644 (file)
index 0000000..964a080
--- /dev/null
@@ -0,0 +1,27 @@
+include_directories (
+    ${DirectX_D3D8_INCLUDE_DIR}
+)
+
+link_libraries (
+    ${DirectX_D3D8_LIBRARY}
+)
+
+set (api d3d8)
+
+set (targets
+    tri
+)
+
+foreach (target ${targets})
+    add_executable (${api}_${target} ${target}.cpp)
+    set_target_properties (${api}_${target} PROPERTIES OUTPUT_NAME ${target})
+
+    if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${target}.ref.txt)
+        add_app_test(
+            NAME ${api}_${target}
+            TARGET ${api}_${target}
+            REF ${target}.ref.txt
+        )
+    endif ()
+endforeach (target)
+
diff --git a/apps/d3d8/tri.cpp b/apps/d3d8/tri.cpp
new file mode 100644 (file)
index 0000000..156d0c5
--- /dev/null
@@ -0,0 +1,176 @@
+/**************************************************************************
+ *
+ * Copyright 2012 Jose Fonseca
+ * All Rights Reserved.
+ *
+ * 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 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
+ * AUTHORS OR COPYRIGHT HOLDERS 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 <windows.h>
+
+#include <d3d8.h>
+
+
+static IDirect3D8 * g_pD3D = NULL;
+static IDirect3DDevice8 * g_pDevice = NULL;
+static D3DPRESENT_PARAMETERS g_PresentationParameters;
+
+
+int main(int argc, char *argv[])
+{
+    HRESULT hr;
+
+    HINSTANCE hInstance = GetModuleHandle(NULL);
+
+    WNDCLASSEX wc = {
+        sizeof(WNDCLASSEX),
+        CS_CLASSDC,
+        DefWindowProc,
+        0,
+        0,
+        hInstance,
+        NULL,
+        NULL,
+        NULL,
+        NULL,
+        "SimpleDX8",
+        NULL
+    };
+    RegisterClassEx(&wc);
+
+    const int WindowWidth = 250;
+    const int WindowHeight = 250;
+    BOOL Windowed = TRUE;
+
+    DWORD dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW;
+
+    RECT rect = {0, 0, WindowWidth, WindowHeight};
+    AdjustWindowRect(&rect, dwStyle, FALSE);
+
+    HWND hWnd = CreateWindow(wc.lpszClassName,
+                             "Simple example using DirectX8",
+                             dwStyle,
+                             CW_USEDEFAULT, CW_USEDEFAULT,
+                             rect.right - rect.left,
+                             rect.bottom - rect.top,
+                             NULL,
+                             NULL,
+                             hInstance,
+                             NULL);
+    if (!hWnd) {
+        return 1;
+    }
+
+    ShowWindow(hWnd, SW_SHOW);
+
+    g_pD3D = Direct3DCreate8(D3D_SDK_VERSION);
+    if (!g_pD3D) {
+        return 1;
+    }
+
+    D3DCAPS8 caps;
+    hr = g_pD3D->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps);
+    if (FAILED(hr)) {
+       return 1;
+    }
+
+    DWORD dwBehaviorFlags;
+    if ((caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == 0 ||
+        caps.VertexShaderVersion < D3DVS_VERSION(1, 1)) {
+       dwBehaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
+    } else {
+       dwBehaviorFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
+    }
+
+    ZeroMemory(&g_PresentationParameters, sizeof g_PresentationParameters);
+    g_PresentationParameters.Windowed = Windowed;
+    if (!Windowed) {
+        g_PresentationParameters.BackBufferWidth = WindowWidth;
+        g_PresentationParameters.BackBufferHeight = WindowHeight;
+    }
+    g_PresentationParameters.BackBufferCount = 1;
+    g_PresentationParameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
+    if (Windowed) {
+        // Must matche the format of the current display mode
+        D3DDISPLAYMODE Mode;
+        hr = g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &Mode);
+        if (FAILED(hr)) {
+            g_pD3D->Release();
+            g_pD3D = NULL;
+            return 1;
+        }
+        g_PresentationParameters.BackBufferFormat = Mode.Format;
+    } else {
+        g_PresentationParameters.BackBufferFormat = D3DFMT_X8R8G8B8;
+        g_PresentationParameters.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
+    }
+    g_PresentationParameters.hDeviceWindow = hWnd;
+
+    g_PresentationParameters.EnableAutoDepthStencil = FALSE;
+
+    hr = g_pD3D->CreateDevice(D3DADAPTER_DEFAULT,
+                              D3DDEVTYPE_HAL,
+                              hWnd,
+                              dwBehaviorFlags,
+                              &g_PresentationParameters,
+                              &g_pDevice);
+    if (FAILED(hr)) {
+        g_pD3D->Release();
+        g_pD3D = NULL;
+        return 1;
+    }
+
+    struct Vertex {
+        float x, y, z;
+        DWORD color;
+    };
+
+
+    D3DCOLOR clearColor = D3DCOLOR_COLORVALUE(0.3f, 0.1f, 0.3f, 1.0f);
+    g_pDevice->Clear(0, NULL, D3DCLEAR_TARGET, clearColor, 1.0f, 0);
+    g_pDevice->BeginScene();
+
+    g_pDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
+    g_pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
+
+    static const Vertex vertices[] = {
+        { -0.9f, -0.9f, 0.5f, D3DCOLOR_COLORVALUE(0.8f, 0.0f, 0.0f, 0.1f) },
+        {  0.9f, -0.9f, 0.5f, D3DCOLOR_COLORVALUE(0.0f, 0.9f, 0.0f, 0.1f) },
+        {  0.0f,  0.9f, 0.5f, D3DCOLOR_COLORVALUE(0.0f, 0.0f, 0.7f, 0.1f) },
+    };
+
+    g_pDevice->SetVertexShader(D3DFVF_XYZ | D3DFVF_DIFFUSE);
+    g_pDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 1, vertices, sizeof(Vertex));
+
+    g_pDevice->EndScene();
+
+    g_pDevice->Present(NULL, NULL, NULL, NULL);
+
+    g_pDevice->Release();
+    g_pDevice = NULL;
+    g_pD3D->Release();
+    g_pD3D = NULL;
+
+    DestroyWindow(hWnd);
+
+    return 0;
+}
+
diff --git a/apps/d3d8/tri.ref.txt b/apps/d3d8/tri.ref.txt
new file mode 100644 (file)
index 0000000..e69de29