Guest User

dxmanager.cpp

a guest
Aug 19th, 2015
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.43 KB | None | 0 0
  1. #pragma once
  2. #include "dxmanager.h"
  3. #include "window.h"
  4. #include <d3d10.h>
  5. //temp
  6. float red = 0.0f;
  7. float green = 0.0f;
  8. float blue = 0.0f;
  9. int colormodr = 1;
  10. int colormodg = 1;
  11. int colormodb = 1;
  12. //end temp
  13. //ALL Direct3D Initialization
  14.  
  15. bool DXManager::InitializeDirect3dApp(HINSTANCE* hInstance, HWND* hwnd, ID3D10Device* d3dDevice, IDXGISwapChain* swapChain, ID3D10RenderTargetView* renderTargetView, int* width, int* height, bool* windowed)
  16. {
  17.     //definition of swap chain
  18.     /*typedef struct DXGI_SWAP_CHAIN_DESC
  19.     {
  20.         DXGI_MODE_DESC BufferDesc;
  21.         DXGI_SAMPLE_DESC SampleDesc;
  22.         DXGI_USAGE BufferUsage;
  23.         UINT BufferCount;
  24.         HWND OutputWindow;
  25.         BOOL Windowed;
  26.         DXGI_SWAP_EFFECT SwapEffect;
  27.         UINT Flags;
  28.     }DXGI_SWAP_CHAIN_DESK;*/
  29.     DXGI_SWAP_CHAIN_DESC scd;
  30.     //defines general properties of our back buffer
  31.     /*typedef struct DXGI_MODE_DESC
  32.     {
  33.         UINT Width;
  34.         UINT Height;
  35.         DXGI_RATIONAL RefreshRate;
  36.         DXGI_FORMAT Format;
  37.         DXGI_MODE_SCANLINE_ORDER ScanlineOrdering;
  38.         DXGI_MODE_SCALING Scaling;
  39.     }DXGI_MODE_DESC, *LPDXGI_MODE_DESC;*/
  40.     scd.BufferDesc.Width = *width; //width of window
  41.     scd.BufferDesc.Height = *height; //height of window
  42.     scd.BufferDesc.RefreshRate.Numerator = 60;
  43.     scd.BufferDesc.RefreshRate.Denominator = 1;
  44.     scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
  45.     scd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
  46.     scd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
  47.    
  48.     //defines number of antialiasing samples and quality
  49.     scd.SampleDesc.Count = 1;
  50.     scd.SampleDesc.Quality = 0;
  51.  
  52.     //specifies that the back buffer will be the target to render to
  53.     scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
  54.    
  55.     //number of back buffers to use in the swap chain (1=double buffering, 2=triple buffering)
  56.     scd.BufferCount = 1;
  57.  
  58.     //the handle to the window
  59.     scd.OutputWindow = *hwnd;
  60.  
  61.     //windowed?
  62.     scd.Windowed = *windowed;
  63.  
  64.     //how we want to swap our front and back buffers
  65.     scd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; //DXGI_S_E_D will let the GPU Driver the most efficient presentation technique for the swap chain
  66.     scd.Flags = 0; //extra flags (we have none)
  67.  
  68.     //creation of swap chain
  69.     /*HRESULT D3D10CreateDeviceAndSwapChain(
  70.         __in IDXGIAdapter *pAdapter, //specifies the display adapter (0 or MULL = primary display adapter)
  71.         __in D3D10_DRIVER_TYPE DriverType, //D3D10_DRIVER_TYPE_HARDWARE (graphics card) or D3D10_DRIVER_TYPE_REFERENCE (software)(slow)
  72.         __in HMODULE Software, //using software rasterizing? we don't
  73.         __in UINT Flags, //optional device creation flags, usually 0 for release builds
  74.         __in UINT SDKVersion, //always set to D3D10_SDK_VERSION
  75.         __in DXGI_SWAP_CHAIN_DESC *pSwapChainDesc, //a pointer to DXGI_SWAP_CHAIN_DESC which describes the swap chain we want to make
  76.         __out IDXGISwapChain **ppSwapChain, //returns the created swap chain
  77.         __out ID3D10Device **ppDevice //returns the created device
  78.     );*/
  79.     D3D10CreateDeviceAndSwapChain(0, //*pAdapter
  80.                                 D3D10_DRIVER_TYPE_HARDWARE, //DriverType
  81.                                 0, //Software Rasterizing
  82.                                 0, //Flags
  83.                                 D3D10_SDK_VERSION, //SDKVersion
  84.                                 &scd, //*pSwapChainDesc
  85.                                 &swapChain, //**ppSwapChain
  86.                                 &d3dDevice); //**ppDevice
  87.     ID3D10Texture2D* backBuffer;    //2dtexture for the back buffer to render onto (COM object)
  88.     swapChain->GetBuffer(0, _uuidof(ID3D10Texture2D), (LPVOID*)&backBuffer); //give backbuffer to the swap chain.
  89.  
  90.     //create the render target view by calling CreateRenderTargetView.
  91.     d3dDevice->CreateRenderTargetView(backBuffer, //render target
  92.                                     0, //pointer to a D3D10_RENDER_TARGET_VIEW_DESC (if created with a tyed format, then it can be NULL.
  93.                                     &renderTargetView); //returs a pointer to the created render target view object
  94.     backBuffer->Release(); //backBuffer is a COM object, therefore we release it at the end of the code.
  95.     //sends the device to the merger stage of the pipeline to make resources the render target and depth/stencil buffers.
  96.     d3dDevice->OMSetRenderTargets(1, //number of render targets to send to the pipeline
  97.                                 &renderTargetView, //pointer to the first element in an array of render target view pointers to bind to the pipeline
  98.                                 NULL); //pointer to the depth/stencil view to bind to the pipeline (we dont have one)
  99.     /*Viewport Creation. (Causing an error-please examine.)
  100.     //typedef struct D3D10_VIEWPORT
  101.     //{
  102.     //  INT TopLeftX; //define how big and where our vbiewport is drawn onto the backbuffer.
  103.     //  INT TopLeftY; //...
  104.     //  UINT Width; //...
  105.     //  UINT Height; //...
  106.     //  FLOAT MinDepth; //minimum depth value in the buffer
  107.     //  FLOAT MaxDepth; //maximum depth value in the buffer
  108.     //}D3D10_VIEWPORT;*/
  109.     D3D10_VIEWPORT vp;
  110.     vp.TopLeftY = 0;
  111.     vp.Width = *width;
  112.     vp.Height = *height;
  113.     vp.MinDepth = 0.0f;
  114.     vp.MaxDepth = 1.0f;
  115.     //setting the viewport with direct3d using the RSSetViewports (ID3D10Device)
  116.     d3dDevice->RSSetViewports(1, //number of viewports
  117.                             &vp); //pointer to the viewport
  118.     const FLOAT bgColor[4] = { 0.0f, 0.2f, 0.4f, 1.0f }; //creates a black color to use with the back buffer
  119.     d3dDevice -> ClearRenderTargetView(renderTargetView, bgColor); //clears the back buffer to the color
  120.  
  121.     swapChain->Present(0, 0); //presents the back buffer
  122.  
  123.     return true; //d3d10 has initialized
  124. }
  125.  
  126. bool DXManager::InitScene()
  127. {
  128.     return true; //where we prepare the necessary things before we draw our scene
  129. }
  130. void DXManager::DrawScene(ID3D10Device* d3dDevice, IDXGISwapChain* swapChain, ID3D10RenderTargetView* renderTargetView)
  131. {
  132. }
Advertisement
Add Comment
Please, Sign In to add comment