X-Git-Url: https://git.cworth.org/git?p=apitrace-tests;a=blobdiff_plain;f=apps%2Fd3d10%2Ftri.cpp;h=1029be91906f95fe618c5735b53dde3f4f020cef;hp=15397977e972848ddb59b640cffd2890cb25e14b;hb=716cd83ce5cc7bd696451ff60c52d4e7443e168a;hpb=31b8ad2c38b6697088ab30422bb32d703947c43a diff --git a/apps/d3d10/tri.cpp b/apps/d3d10/tri.cpp index 1539797..1029be9 100644 --- a/apps/d3d10/tri.cpp +++ b/apps/d3d10/tri.cpp @@ -33,14 +33,20 @@ #include "compat.h" #include -#include +#include "tri_vs_4_0.h" +#include "tri_ps_4_0.h" + +static IDXGIFactory *g_pFactory = NULL; +static IDXGIAdapter *g_pAdapter = NULL; static IDXGISwapChain* g_pSwapChain = NULL; static ID3D10Device * g_pDevice = NULL; -int main(int argc, char *argv[]){ +int +main(int argc, char *argv[]) +{ HRESULT hr; HINSTANCE hInstance = GetModuleHandle(NULL); @@ -86,6 +92,31 @@ int main(int argc, char *argv[]){ ShowWindow(hWnd, SW_SHOW); + UINT Flags = 0; + if (LoadLibraryA("d3d10sdklayers")) { + Flags |= D3D10_CREATE_DEVICE_DEBUG; + } + + hr = CreateDXGIFactory(IID_IDXGIFactory, (void**)(&g_pFactory) ); + if (FAILED(hr)) { + return 1; + } + + hr = g_pFactory->EnumAdapters(0, &g_pAdapter); + if (FAILED(hr)) { + return 1; + } + + hr = D3D10CreateDevice(g_pAdapter, + D3D10_DRIVER_TYPE_HARDWARE, + NULL, + Flags, + D3D10_SDK_VERSION, + &g_pDevice); + if (FAILED(hr)) { + return 1; + } + DXGI_SWAP_CHAIN_DESC SwapChainDesc; ZeroMemory(&SwapChainDesc, sizeof SwapChainDesc); SwapChainDesc.BufferDesc.Width = WindowWidth; @@ -100,14 +131,7 @@ int main(int argc, char *argv[]){ SwapChainDesc.OutputWindow = hWnd; SwapChainDesc.Windowed = true; - hr = D3D10CreateDeviceAndSwapChain(NULL, - D3D10_DRIVER_TYPE_HARDWARE, - NULL, - D3D10_CREATE_DEVICE_DEBUG, - D3D10_SDK_VERSION, - &SwapChainDesc, - &g_pSwapChain, - &g_pDevice); + hr = g_pFactory->CreateSwapChain(g_pDevice, &SwapChainDesc, &g_pSwapChain); if (FAILED(hr)) { return 1; } @@ -118,7 +142,12 @@ int main(int argc, char *argv[]){ if (FAILED(hr)) { return 1; } - hr = g_pDevice->CreateRenderTargetView(pBackBuffer, NULL, &pRenderTargetView); + D3D10_RENDER_TARGET_VIEW_DESC RenderTargetViewDesc; + ZeroMemory(&RenderTargetViewDesc, sizeof RenderTargetViewDesc); + RenderTargetViewDesc.Format = SwapChainDesc.BufferDesc.Format; + RenderTargetViewDesc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D; + RenderTargetViewDesc.Texture2D.MipSlice = 0; + hr = g_pDevice->CreateRenderTargetView(pBackBuffer, &RenderTargetViewDesc, &pRenderTargetView); if (FAILED(hr)) { return 1; } @@ -129,76 +158,40 @@ int main(int argc, char *argv[]){ const float clearColor[4] = { 0.3f, 0.1f, 0.3f, 1.0f }; g_pDevice->ClearRenderTargetView(pRenderTargetView, clearColor); - const char *szShader = - "struct VS_OUTPUT {\n" - " float4 Pos : SV_POSITION;\n" - " float4 Color : COLOR0;\n" - "};\n" - "\n" - "VS_OUTPUT VS(float4 Pos : POSITION, float4 Color : COLOR) {\n" - " VS_OUTPUT Out;\n" - " Out.Pos = Pos;\n" - " Out.Color = Color;\n" - " return Out;\n" - "}\n" - "\n" - "float4 PS(VS_OUTPUT In) : SV_Target {\n" - " return In.Color;\n" - "}\n" - ; - - ID3D10Blob *pVertexShaderBlob = NULL; - ID3D10Blob *pErrorMsgs = NULL; - - hr = D3D10CompileShader(szShader, strlen(szShader), NULL, NULL, NULL, "VS", "vs_4_0", 0, &pVertexShaderBlob, &pErrorMsgs); - if (pErrorMsgs) { - fprintf(stderr, "%s\n", pErrorMsgs->GetBufferPointer()); - pErrorMsgs->Release(); - } + ID3D10VertexShader * pVertexShader; + hr = g_pDevice->CreateVertexShader(g_VS, sizeof g_VS, &pVertexShader); if (FAILED(hr)) { return 1; } - ID3D10VertexShader * pVertexShader; - hr = g_pDevice->CreateVertexShader((DWORD*)pVertexShaderBlob->GetBufferPointer(), pVertexShaderBlob->GetBufferSize(), &pVertexShader); - struct Vertex { float position[4]; float color[4]; }; - D3D10_INPUT_ELEMENT_DESC InputElementDescs[] = { - { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, offsetof(Vertex, position), D3D10_INPUT_PER_VERTEX_DATA, 0 }, + static const D3D10_INPUT_ELEMENT_DESC InputElementDescs[] = { + { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, offsetof(Vertex, position), D3D10_INPUT_PER_VERTEX_DATA, 0 }, { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, offsetof(Vertex, color), D3D10_INPUT_PER_VERTEX_DATA, 0 } }; ID3D10InputLayout *pVertexLayout = NULL; hr = g_pDevice->CreateInputLayout(InputElementDescs, 2, - pVertexShaderBlob->GetBufferPointer(), - pVertexShaderBlob->GetBufferSize(), + g_VS, + sizeof g_VS, &pVertexLayout); - pVertexShaderBlob->Release(); + if (FAILED(hr)) { + return 1; + } g_pDevice->IASetInputLayout(pVertexLayout); - - ID3D10Blob *pPixelShaderBlob = NULL; - pErrorMsgs = NULL; - hr = D3D10CompileShader(szShader, strlen(szShader), NULL, NULL, NULL, "PS", "ps_4_0", 0, &pPixelShaderBlob, &pErrorMsgs); - if (pErrorMsgs) { - fprintf(stderr, "%s\n", pErrorMsgs->GetBufferPointer()); - pErrorMsgs->Release(); - } + ID3D10PixelShader * pPixelShader; + hr = g_pDevice->CreatePixelShader(g_PS, sizeof g_PS, &pPixelShader); if (FAILED(hr)) { return 1; } - ID3D10PixelShader * pPixelShader; - hr = g_pDevice->CreatePixelShader((DWORD*)pPixelShaderBlob->GetBufferPointer(), pPixelShaderBlob->GetBufferSize(), &pPixelShader); - pPixelShaderBlob->Release(); - - g_pDevice->VSSetShader(pVertexShader); g_pDevice->PSSetShader(pPixelShader); @@ -218,6 +211,9 @@ int main(int argc, char *argv[]){ ID3D10Buffer *pVertexBuffer; hr = g_pDevice->CreateBuffer(&BufferDesc, NULL, &pVertexBuffer); + if (FAILED(hr)) { + return 1; + } void *pMap = NULL; pVertexBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &pMap); @@ -242,8 +238,12 @@ int main(int argc, char *argv[]){ RasterizerDesc.CullMode = D3D10_CULL_NONE; RasterizerDesc.FillMode = D3D10_FILL_SOLID; RasterizerDesc.FrontCounterClockwise = true; + RasterizerDesc.DepthClipEnable = true; ID3D10RasterizerState* pRasterizerState = NULL; - g_pDevice->CreateRasterizerState(&RasterizerDesc, &pRasterizerState); + hr = g_pDevice->CreateRasterizerState(&RasterizerDesc, &pRasterizerState); + if (FAILED(hr)) { + return 1; + } g_pDevice->RSSetState(pRasterizerState); g_pDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);