static ID3D10Device * g_pDevice = NULL;
-int main(int argc, char *argv[]){
+int
+main(int argc, char *argv[])
+{
HRESULT hr;
HINSTANCE hInstance = GetModuleHandle(NULL);
include_directories (
+ ${CMAKE_CURRENT_SOURCE_DIR}/../d3dcommon
${DirectX_D3D9_INCLUDE_DIR}
)
set (targets
tri
+ tri_pp
)
foreach (target ${targets})
- add_executable (${api}_${target} WIN32 ${target}.cpp)
+ add_executable (${api}_${target} ${target}.cpp)
set_target_properties (${api}_${target} PROPERTIES OUTPUT_NAME ${target})
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${target}.ref.txt)
static D3DPRESENT_PARAMETERS g_PresentationParameters;
-int WINAPI
-WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine, int nCmdShow)
+int
+main(int argc, char *argv[])
{
HRESULT hr;
+ HINSTANCE hInstance = GetModuleHandle(NULL);
+
WNDCLASSEX wc = {
sizeof(WNDCLASSEX),
CS_CLASSDC,
--- /dev/null
+/**************************************************************************
+ *
+ * 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 <stddef.h>
+
+#include <windows.h>
+
+#include <d3d9.h>
+
+#include "tri_vs_2_0.h"
+#include "tri_ps_2_0.h"
+
+
+static IDirect3D9 * g_pD3D = NULL;
+static IDirect3DDevice9 * 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,
+ "SimpleDX9",
+ 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 DirectX9",
+ 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 = Direct3DCreate9(D3D_SDK_VERSION);
+ if (!g_pD3D) {
+ return 1;
+ }
+
+ D3DCAPS9 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_FLIP;
+ if (!Windowed) {
+ g_PresentationParameters.BackBufferFormat = D3DFMT_X8R8G8B8;
+ } else {
+ g_PresentationParameters.BackBufferFormat = D3DFMT_UNKNOWN;
+ }
+ g_PresentationParameters.hDeviceWindow = hWnd;
+
+ g_PresentationParameters.EnableAutoDepthStencil = FALSE;
+ g_PresentationParameters.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
+
+ hr = g_pD3D->CreateDevice(D3DADAPTER_DEFAULT,
+ D3DDEVTYPE_HAL,
+ hWnd,
+ dwBehaviorFlags,
+ &g_PresentationParameters,
+ &g_pDevice);
+ if (FAILED(hr)) {
+ return 1;
+ }
+
+ D3DCOLOR clearColor = D3DCOLOR_COLORVALUE(0.3f, 0.1f, 0.3f, 1.0f);
+ g_pDevice->Clear(0, NULL, D3DCLEAR_TARGET, clearColor, 1.0f, 0);
+
+ struct Vertex {
+ float position[4];
+ float color[4];
+ };
+
+ static const Vertex vertices[] = {
+ { { -0.9f, -0.9f, 0.5f, 1.0f}, { 0.8f, 0.0f, 0.0f, 0.1f } },
+ { { 0.9f, -0.9f, 0.5f, 1.0f}, { 0.0f, 0.9f, 0.0f, 0.1f } },
+ { { 0.0f, 0.9f, 0.5f, 1.0f}, { 0.0f, 0.0f, 0.7f, 0.1f } },
+ };
+
+ static const D3DVERTEXELEMENT9 VertexElements[] = {
+ { 0, offsetof(Vertex, position), D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
+ { 0, offsetof(Vertex, color), D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
+ D3DDECL_END()
+ };
+
+ LPDIRECT3DVERTEXDECLARATION9 pVertexDeclaration = NULL;
+ hr = g_pDevice->CreateVertexDeclaration(VertexElements, &pVertexDeclaration);
+ if (FAILED(hr)) {
+ return 1;
+ }
+ g_pDevice->SetVertexDeclaration(pVertexDeclaration);
+
+ LPDIRECT3DVERTEXSHADER9 pVertexShader = NULL;
+ hr = g_pDevice->CreateVertexShader((CONST DWORD *)g_vs20_VS, &pVertexShader);
+ if (FAILED(hr)) {
+ return 1;
+ }
+ g_pDevice->SetVertexShader(pVertexShader);
+
+ LPDIRECT3DPIXELSHADER9 pPixelShader = NULL;
+ hr = g_pDevice->CreatePixelShader((CONST DWORD *)g_ps20_PS, &pPixelShader);
+ if (FAILED(hr)) {
+ return 1;
+ }
+ g_pDevice->SetPixelShader(pPixelShader);
+
+ g_pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
+
+ g_pDevice->BeginScene();
+
+ g_pDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 1, vertices, sizeof(Vertex));
+
+ g_pDevice->EndScene();
+
+ g_pDevice->Present(NULL, NULL, NULL, NULL);
+
+ pPixelShader->Release();
+ pPixelShader = NULL;
+
+ pVertexShader->Release();
+ pVertexShader = NULL;
+
+ pVertexDeclaration->Release();
+ pVertexDeclaration = NULL;
+
+ g_pDevice->Release();
+ g_pDevice = NULL;
+
+ g_pD3D->Release();
+ g_pD3D = NULL;
+
+ DestroyWindow(hWnd);
+
+ return 0;
+}
+
--- /dev/null
+Direct3DCreate9(SDKVersion = 32) = <pD3D>
+IDirect3D9::GetDeviceCaps(this = <pD3D>, Adapter = D3DADAPTER_DEFAULT, DeviceType = D3DDEVTYPE_HAL, pCaps = &<Caps>) = D3D_OK
+IDirect3D9::CreateDevice(this = <pD3D>, Adapter = D3DADAPTER_DEFAULT, DeviceType = D3DDEVTYPE_HAL, hFocusWindow = <hWnd>, BehaviorFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING, pPresentationParameters = &{BackBufferWidth = 250, BackBufferHeight = 250, BackBufferFormat = D3DFMT_X8R8G8B8, BackBufferCount = 1, MultiSampleType = D3DMULTISAMPLE_NONE, MultiSampleQuality = 0, SwapEffect = D3DSWAPEFFECT_FLIP, hDeviceWindow = <hWnd>, Windowed = TRUE, EnableAutoDepthStencil = FALSE, AutoDepthStencilFormat = D3DFMT_UNKNOWN, Flags = 0, FullScreen_RefreshRateInHz = 0, PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE}, ppReturnedDeviceInterface = &<pDevice>) = D3D_OK
+IDirect3DDevice9::Clear(this = <pDevice>, Count = 0, pRects = NULL, Flags = D3DCLEAR_TARGET, Color = 0xff4c194c, Z = 1, Stencil = 0) = D3D_OK
+IDirect3DDevice9::CreateVertexDeclaration(this = <pDevice>, pVertexElements = {{Stream = 0, Offset = 0, Type = D3DDECLTYPE_FLOAT4, Method = D3DDECLMETHOD_DEFAULT, Usage = D3DDECLUSAGE_POSITION, UsageIndex = 0}, {Stream = 0, Offset = 16, Type = D3DDECLTYPE_FLOAT4, Method = D3DDECLMETHOD_DEFAULT, Usage = D3DDECLUSAGE_COLOR, UsageIndex = 0}, {Stream = 255, Offset = 0, Type = D3DDECLTYPE_UNUSED, Method = D3DDECLMETHOD_DEFAULT, Usage = D3DDECLUSAGE_POSITION, UsageIndex = 0}}, ppDecl = &<pVertexDeclaration>) = D3D_OK
+IDirect3DDevice9::SetVertexDeclaration(this = <pDevice>, pDecl = <pVertexDeclaration>) = D3D_OK
+IDirect3DDevice9::CreateVertexShader(this = <pDevice>, pFunction = "//
+// Generated by Microsoft (R) HLSL Shader Compiler 9.30.960.8229
+ vs_2_0
+ dcl_position v0
+ dcl_color v1
+ mov oPos, v0
+ mov oD0, v1
+
+// approximately 2 instruction slots used
+", ppShader = &<pVertexShader>) = D3D_OK
+IDirect3DDevice9::SetVertexShader(this = <pDevice>, pShader = <pVertexShader>) = D3D_OK
+IDirect3DDevice9::CreatePixelShader(this = <pDevice>, pFunction = "//
+// Generated by Microsoft (R) HLSL Shader Compiler 9.30.960.8229
+ ps_2_0
+ dcl v0
+ mov oC0, v0
+
+// approximately 1 instruction slot used
+", ppShader = &<pPixelShader>) = D3D_OK
+IDirect3DDevice9::SetPixelShader(this = <pDevice>, pShader = <pPixelShader>) = D3D_OK
+IDirect3DDevice9::SetRenderState(this = <pDevice>, State = D3DRS_CULLMODE, Value = D3DCULL_NONE) = D3D_OK
+IDirect3DDevice9::BeginScene(this = <pDevice>) = D3D_OK
+IDirect3DDevice9::DrawPrimitiveUP(this = <pDevice>, PrimitiveType = D3DPT_TRIANGLELIST, PrimitiveCount = 1, pVertexStreamZeroData = blob(96), VertexStreamZeroStride = 32) = D3D_OK
+IDirect3DDevice9::EndScene(this = <pDevice>) = D3D_OK
+IDirect3DDevice9::Present(this = <pDevice>, pSourceRect = NULL, pDestRect = NULL, hDestWindowOverride = NULL, pDirtyRegion = NULL) = D3D_OK
+IDirect3DPixelShader9::Release(this = <pPixelShader>) = 0
+IDirect3DVertexShader9::Release(this = <pVertexShader>) = 0
+IDirect3DVertexDeclaration9::Release(this = <pVertexDeclaration>) = 0
+IDirect3DDevice9::Release(this = <pDevice>) = 0
+IDirect3D9::Release(this = <pD3D>) = 0
set (HEADERS ${HEADERS} ${VS_HEADER} ${PS_HEADER})
endmacro ()
+fxc (vs_2_0 ps_2_0)
fxc (vs_4_0 ps_4_0)
fxc (vs_4_0_level_9_1 ps_4_0_level_9_1)
--- /dev/null
+#if 0
+//
+// Generated by Microsoft (R) HLSL Shader Compiler 9.30.960.8229
+//
+// fxc /nologo /Qstrip_reflect /T ps_2_0 /E PS /Fh
+// Z:/projects/apitrace/tests/apps/d3dcommon/tri_ps_2_0.h
+// Z:/projects/apitrace/tests/apps/d3dcommon/tri.fx
+//
+ ps_2_0
+ dcl v0
+ mov oC0, v0
+
+// approximately 1 instruction slot used
+#endif
+
+const BYTE g_ps20_PS[] =
+{
+ 0, 2, 255, 255, 254, 255,
+ 22, 0, 67, 84, 65, 66,
+ 28, 0, 0, 0, 35, 0,
+ 0, 0, 0, 2, 255, 255,
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 1, 0, 0,
+ 28, 0, 0, 0, 112, 115,
+ 95, 50, 95, 48, 0, 77,
+ 105, 99, 114, 111, 115, 111,
+ 102, 116, 32, 40, 82, 41,
+ 32, 72, 76, 83, 76, 32,
+ 83, 104, 97, 100, 101, 114,
+ 32, 67, 111, 109, 112, 105,
+ 108, 101, 114, 32, 57, 46,
+ 51, 48, 46, 57, 54, 48,
+ 46, 56, 50, 50, 57, 0,
+ 31, 0, 0, 2, 0, 0,
+ 0, 128, 0, 0, 15, 144,
+ 1, 0, 0, 2, 0, 8,
+ 15, 128, 0, 0, 228, 144,
+ 255, 255, 0, 0
+};
--- /dev/null
+#if 0
+//
+// Generated by Microsoft (R) HLSL Shader Compiler 9.30.960.8229
+//
+// fxc /nologo /Qstrip_reflect /T vs_2_0 /E VS /Fh
+// Z:/projects/apitrace/tests/apps/d3dcommon/tri_vs_2_0.h
+// Z:/projects/apitrace/tests/apps/d3dcommon/tri.fx
+//
+ vs_2_0
+ dcl_position v0
+ dcl_color v1
+ mov oPos, v0
+ mov oD0, v1
+
+// approximately 2 instruction slots used
+#endif
+
+const BYTE g_vs20_VS[] =
+{
+ 0, 2, 254, 255, 254, 255,
+ 22, 0, 67, 84, 65, 66,
+ 28, 0, 0, 0, 35, 0,
+ 0, 0, 0, 2, 254, 255,
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 1, 0, 0,
+ 28, 0, 0, 0, 118, 115,
+ 95, 50, 95, 48, 0, 77,
+ 105, 99, 114, 111, 115, 111,
+ 102, 116, 32, 40, 82, 41,
+ 32, 72, 76, 83, 76, 32,
+ 83, 104, 97, 100, 101, 114,
+ 32, 67, 111, 109, 112, 105,
+ 108, 101, 114, 32, 57, 46,
+ 51, 48, 46, 57, 54, 48,
+ 46, 56, 50, 50, 57, 0,
+ 31, 0, 0, 2, 0, 0,
+ 0, 128, 0, 0, 15, 144,
+ 31, 0, 0, 2, 10, 0,
+ 0, 128, 1, 0, 15, 144,
+ 1, 0, 0, 2, 0, 0,
+ 15, 192, 0, 0, 228, 144,
+ 1, 0, 0, 2, 0, 0,
+ 15, 208, 1, 0, 228, 144,
+ 255, 255, 0, 0
+};