Guest User

Untitled

a guest
Feb 4th, 2013
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 16.64 KB | None | 0 0
  1. //filename d3dclass.cpp
  2. #include "d3dclass.h"
  3.  
  4. D3DClass::D3DClass()
  5. {
  6.     m_swapChain = 0;
  7.     m_device = 0;
  8.     m_deviceContext = 0;
  9.     m_renderTargetView = 0;
  10.     m_depthStencilBuffer = 0;
  11.     m_depthStencilState = 0;
  12.     m_depthStencilView = 0;
  13.     m_rasterState = 0;
  14.  
  15.     m_depthDisabledStencilState = 0;
  16.  
  17.     m_alphaDisableBlendingState = 0;
  18.     m_alphaEnableBlendingState = 0;
  19. }
  20.  
  21. D3DClass::D3DClass(const D3DClass& other)
  22. {
  23. }
  24.  
  25. D3DClass::~D3DClass()
  26. {
  27. }
  28.  
  29. bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hwnd, bool fullscreen,
  30.     float screenDepth, float screenNear)
  31. {
  32.  
  33.     HRESULT result;
  34.     IDXGIFactory* factory;
  35.     IDXGIAdapter* adapter;
  36.     IDXGIOutput* adapterOutput;
  37.     unsigned int numModes, i, numerator, denominator, stringLength;
  38.     DXGI_MODE_DESC* displayModeList;
  39.     DXGI_ADAPTER_DESC adapterDesc;
  40.     int error;
  41.     DXGI_SWAP_CHAIN_DESC swapChainDesc;
  42.     D3D_FEATURE_LEVEL featureLevel;
  43.     ID3D11Texture2D* backBufferPtr;
  44.     D3D11_TEXTURE2D_DESC depthBufferDesc;
  45.     D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
  46.     D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
  47.     D3D11_RASTERIZER_DESC rasterDesc;
  48.     D3D11_VIEWPORT viewport;
  49.     float fieldOfView, screenAspect;
  50.  
  51.     D3D11_DEPTH_STENCIL_DESC depthDisabledStencilDesc;
  52.  
  53.     D3D11_BLEND_DESC blendStateDescription;
  54.  
  55.     //store the vsync setting
  56.     m_vsync_enabled = vsync;
  57.  
  58.     //Create a directx graphics interface factory
  59.     result = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
  60.     if(FAILED(result))
  61.     {
  62.         return false;
  63.     }
  64.  
  65.     //use the factory to create an adapter for the primary graphics
  66.     //interface (video card).
  67.     result = factory->EnumAdapters(0, &adapter);
  68.     if(FAILED(result))
  69.     {
  70.         return false;
  71.     }
  72.  
  73.     //enum the primary adapter output (monitor)
  74.     result = adapter->EnumOutputs(0, &adapterOutput);
  75.     if(FAILED(result))
  76.     {
  77.         return false;
  78.     }
  79.  
  80.     //get the number of modes that fit the
  81.     //DXGI_FORMAT_R8G8B8A8_UNORM display format for the adapter output
  82.     result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, NULL);
  83.     if(FAILED(result))
  84.     {
  85.         return false;
  86.     }
  87.  
  88.     //create a list to hold all the possible display modes for this monitor/video card combo
  89.     displayModeList = new DXGI_MODE_DESC[numModes];
  90.     if(!displayModeList)
  91.     {
  92.         return false;
  93.     }
  94.  
  95.     //now fill the adapter mode list structures
  96.     result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM,
  97.         DXGI_ENUM_MODES_INTERLACED, &numModes, displayModeList);
  98.     if(FAILED(result))
  99.     {
  100.         return false;
  101.     }
  102.  
  103.     //now go through all the display modes and find the one that matches
  104.     //the screen h/w when a match is found store the numerator
  105.     //and deniminator of the refresh rate for that monitor
  106.     for(i=0; i<numModes; i++)
  107.     {
  108.         if(displayModeList[i].Width == (unsigned int)screenWidth)
  109.         {
  110.             if(displayModeList[i].Height == (unsigned int)screenHeight)
  111.             {
  112.                 numerator = displayModeList[i].RefreshRate.Numerator;
  113.                 denominator = displayModeList[i].RefreshRate.Denominator;
  114.             }
  115.         }
  116.     }
  117.  
  118.     //get the adapter(video card) desc
  119.     result = adapter->GetDesc(&adapterDesc);
  120.     if(FAILED(result))
  121.     {
  122.         return false;
  123.     }
  124.  
  125.     //store the dedicated video card memory in megabytes
  126.     m_videoCardMemory = (int)(adapterDesc.DedicatedVideoMemory /1024 / 1024);
  127.  
  128.     //convert the name of the video card to a character array and store it
  129.     error = wcstombs_s(&stringLength, m_videoCardDescription, 128, adapterDesc.Description, 128);
  130.     if(error != 0)
  131.     {
  132.         return false;
  133.     }
  134.  
  135.     ////release the display mode list
  136.     delete[] displayModeList;
  137.     displayModeList = 0;
  138.  
  139.     //release the adapter output
  140.     adapterOutput->Release();
  141.     adapterOutput = 0;
  142.  
  143.     //release the adapter
  144.     adapter->Release();
  145.     adapter = 0;
  146.  
  147.     //release the factory
  148.     factory->Release();
  149.     factory = 0;
  150.  
  151.    
  152.     //Ini the swapchain desc
  153.     ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
  154.  
  155.     //set to a single back buffer
  156.     swapChainDesc.BufferCount = 1;
  157.  
  158.     //st the width and height of the back buffer
  159.     swapChainDesc.BufferDesc.Width = screenWidth;
  160.     swapChainDesc.BufferDesc.Height = screenHeight;
  161.  
  162.     //set the reg 32-bit surface for the back buffer
  163.     swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
  164.  
  165.     //set the refresh rate of the back buffer
  166.     if(m_vsync_enabled)
  167.     {
  168.         swapChainDesc.BufferDesc.RefreshRate.Numerator = numerator;
  169.         swapChainDesc.BufferDesc.RefreshRate.Denominator = denominator;
  170.     }
  171.     else
  172.     {
  173.         swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
  174.         swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
  175.     }
  176.  
  177.     //set the usage of the back buffer
  178.     swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
  179.  
  180.     //set the handle for the window to render to
  181.     swapChainDesc.OutputWindow = hwnd;
  182.  
  183.     //turn multisampling off
  184.     swapChainDesc.SampleDesc.Count = 1;
  185.     swapChainDesc.SampleDesc.Quality = 0;
  186.  
  187.     //set to full screen or windowed mode
  188.     if(fullscreen)
  189.     {
  190.         swapChainDesc.Windowed = false;
  191.     }
  192.     else
  193.     {
  194.         swapChainDesc.Windowed = true;
  195.     }
  196.  
  197.     //set the scan line ordering and scaling to unspecified
  198.     swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
  199.     swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
  200.  
  201.     //discard the back buffer contexts after presenting
  202.     swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
  203.  
  204.     //dont set the advanced flags
  205.     swapChainDesc.Flags = 0;
  206.  
  207.     //set the feature level to DX 11
  208.     featureLevel = D3D_FEATURE_LEVEL_11_0;
  209.  
  210.     //create the swapchain, D3Ddevice and d3d device context
  211.     result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, &featureLevel,
  212.         1, D3D11_SDK_VERSION, &swapChainDesc, &m_swapChain, &m_device, NULL, &m_deviceContext);
  213.     if(FAILED(result))
  214.     {
  215.         return false;
  216.     }
  217.  
  218.     //get the pointer to the back buffer
  219.     result = m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBufferPtr);
  220.     if(FAILED(result))
  221.     {
  222.         return false;
  223.     }
  224.  
  225.     //create the render target view with the back buffer pointer
  226.     result = m_device->CreateRenderTargetView(backBufferPtr, NULL, &m_renderTargetView);
  227.     if(FAILED(result))
  228.     {
  229.         return false;
  230.     }
  231.  
  232.     //release the pointer to the back buffer as we no longer need it
  233.     backBufferPtr->Release();
  234.     backBufferPtr = 0;
  235.  
  236.     ZeroMemory(&depthBufferDesc, sizeof(depthBufferDesc));
  237.  
  238.     //set up the desc of th depth buffer
  239.     depthBufferDesc.Width = screenWidth;
  240.     depthBufferDesc.Height = screenHeight;
  241.     depthBufferDesc.MipLevels = 1;
  242.     depthBufferDesc.ArraySize = 1;
  243.     depthBufferDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
  244.     depthBufferDesc.SampleDesc.Count = 1;
  245.     depthBufferDesc.SampleDesc.Quality = 0;
  246.     depthBufferDesc.Usage = D3D11_USAGE_DEFAULT;
  247.     depthBufferDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
  248.     depthBufferDesc.CPUAccessFlags = 0;
  249.     depthBufferDesc.MiscFlags = 0;
  250.  
  251.     //create the texture for the depth buffer using the filled out desc
  252.     result = m_device->CreateTexture2D(&depthBufferDesc, NULL, &m_depthStencilBuffer);
  253.     if(FAILED(result))
  254.     {
  255.         return false;
  256.     }
  257.  
  258.  
  259.     // Initialize the description of the stencil state.
  260.     ZeroMemory(&depthStencilDesc, sizeof(depthStencilDesc));
  261.  
  262.     // Set up the description of the stencil state.
  263.     depthStencilDesc.DepthEnable = true;
  264.     depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
  265.     depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;
  266.  
  267.     depthStencilDesc.StencilEnable = true;
  268.     depthStencilDesc.StencilReadMask = 0xFF;
  269.     depthStencilDesc.StencilWriteMask = 0xFF;
  270.  
  271.     // Stencil operations if pixel is front-facing.
  272.     depthStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
  273.     depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
  274.     depthStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
  275.     depthStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
  276.  
  277.     // Stencil operations if pixel is back-facing.
  278.     depthStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
  279.     depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
  280.     depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
  281.     depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
  282.  
  283.     // Create the depth stencil state.
  284.     result = m_device->CreateDepthStencilState(&depthStencilDesc, &m_depthStencilState);
  285.     if(FAILED(result))
  286.     {
  287.         return false;
  288.     }
  289.  
  290.  
  291.     // Set the depth stencil state.
  292.     m_deviceContext->OMSetDepthStencilState(m_depthStencilState, 1);
  293.  
  294.     // Initailze the depth stencil view.
  295.     ZeroMemory(&depthStencilViewDesc, sizeof(depthStencilViewDesc));
  296.  
  297.     // Set up the depth stencil view description.
  298.     depthStencilViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
  299.     depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
  300.     depthStencilViewDesc.Texture2D.MipSlice = 0;
  301.  
  302.     // Create the depth stencil view.
  303.     result = m_device->CreateDepthStencilView(m_depthStencilBuffer, &depthStencilViewDesc, &m_depthStencilView);
  304.     if(FAILED(result))
  305.     {
  306.         return false;
  307.     }
  308.  
  309.     // Bind the render target view and depth stencil buffer to the output render pipeline.
  310.     m_deviceContext->OMSetRenderTargets(1, &m_renderTargetView, m_depthStencilView);
  311.  
  312.  
  313.     // Setup the raster description which will determine how and what polygons will be drawn.
  314.     rasterDesc.AntialiasedLineEnable = false;
  315.     rasterDesc.CullMode = D3D11_CULL_BACK;
  316.     rasterDesc.DepthBias = 0;
  317.     rasterDesc.DepthBiasClamp = 0.0f;
  318.     rasterDesc.DepthClipEnable = true;
  319.     rasterDesc.FillMode = D3D11_FILL_SOLID;
  320.     rasterDesc.FrontCounterClockwise = false;
  321.     rasterDesc.MultisampleEnable = false;
  322.     rasterDesc.ScissorEnable = false;
  323.     rasterDesc.SlopeScaledDepthBias = 0.0f;
  324.  
  325.     // Create the rasterizer state from the description we just filled out.
  326.     result = m_device->CreateRasterizerState(&rasterDesc, &m_rasterState);
  327.     if(FAILED(result))
  328.     {
  329.         return false;
  330.     }
  331.  
  332.     // Now set the rasterizer state.
  333.     m_deviceContext->RSSetState(m_rasterState);
  334.  
  335.  
  336.     // Setup the viewport for rendering.
  337.     viewport.Width = (float)screenWidth;
  338.     viewport.Height = (float)screenHeight;
  339.     viewport.MinDepth = 0.0f;
  340.     viewport.MaxDepth = 1.0f;
  341.     viewport.TopLeftX = 0.0f;
  342.     viewport.TopLeftY = 0.0f;
  343.  
  344.     // Create the viewport.
  345.     m_deviceContext->RSSetViewports(1, &viewport);
  346.  
  347.     // Setup the projection matrix.
  348.     fieldOfView = (float)D3DX_PI / 4.0f;
  349.     screenAspect = (float)screenWidth / (float)screenHeight;
  350.  
  351.     // Create the projection matrix for 3D rendering.
  352.     D3DXMatrixPerspectiveFovLH(&m_projectionMatrix, fieldOfView, screenAspect, screenNear, screenDepth);
  353.  
  354.     // Initialize the world matrix to the identity matrix.
  355.     D3DXMatrixIdentity(&m_worldMatrix);
  356.  
  357.     // Create an orthographic projection matrix for 2D rendering.
  358.     D3DXMatrixOrthoLH(&m_orthoMatrix, (float)screenWidth, (float)screenHeight, screenNear, screenDepth);
  359.  
  360.     //clear the second depth stencil state
  361.     ZeroMemory(&depthDisabledStencilDesc, sizeof(depthDisabledStencilDesc));
  362.  
  363.     //now create a second depth stencil state which turns off the Z buffer for 2d rendering
  364.     //the only difference is that depthenable is set to false
  365.  
  366.     depthDisabledStencilDesc.DepthEnable = false;
  367.     depthDisabledStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
  368.     depthDisabledStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;
  369.     depthDisabledStencilDesc.StencilEnable = true;
  370.     depthDisabledStencilDesc.StencilReadMask = 0xFF;
  371.     depthDisabledStencilDesc.StencilWriteMask = 0xFF;
  372.     depthDisabledStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
  373.     depthDisabledStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
  374.     depthDisabledStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
  375.     depthDisabledStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
  376.     depthDisabledStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
  377.     depthDisabledStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
  378.     depthDisabledStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
  379.     depthDisabledStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
  380.  
  381.     //create the state using the device
  382.     result = m_device->CreateDepthStencilState(&depthDisabledStencilDesc, &m_depthDisabledStencilState);
  383.     if(FAILED(result))
  384.     {
  385.         return false;
  386.     }
  387.  
  388.     //clear the blend state desc
  389.     ZeroMemory(&blendStateDescription, sizeof(D3D11_BLEND_DESC));
  390.  
  391.         // Create an alpha enabled blend state description.
  392.     blendStateDescription.RenderTarget[0].BlendEnable = TRUE;
  393.     blendStateDescription.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
  394.     blendStateDescription.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
  395.     blendStateDescription.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
  396.     blendStateDescription.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
  397.     blendStateDescription.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
  398.     blendStateDescription.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
  399.     blendStateDescription.RenderTarget[0].RenderTargetWriteMask = 0x0f;
  400.  
  401.     //create the blend state using the desc
  402.     result = m_device->CreateBlendState(&blendStateDescription, &m_alphaEnableBlendingState);
  403.     if(FAILED(result))
  404.     {
  405.         return false;
  406.     }
  407.  
  408.     //modify the dfesc to create an alpha disabled blend state desc
  409.     blendStateDescription.RenderTarget[0].BlendEnable = FALSE;
  410.  
  411.  
  412.     //create the blend state using the desc
  413.     result = m_device->CreateBlendState(&blendStateDescription, &m_alphaDisableBlendingState);
  414.     if(FAILED(result))
  415.     {
  416.         return false;
  417.     }
  418.  
  419.  
  420.     return true;
  421. }
  422.  
  423. void D3DClass::Shutdown()
  424. {
  425.     // Before shutting down set to windowed mode or when you release the swap chain it will throw an exception.
  426.     if(m_swapChain)
  427.     {
  428.         m_swapChain->SetFullscreenState(false, NULL);
  429.     }
  430.    
  431.     if(m_alphaEnableBlendingState)
  432.     {
  433.         m_alphaEnableBlendingState->Release();
  434.         m_alphaEnableBlendingState = 0;
  435.     }
  436.  
  437.     if(m_alphaDisableBlendingState)
  438.     {
  439.         m_alphaDisableBlendingState->Release();
  440.         m_alphaDisableBlendingState = 0;
  441.     }
  442.  
  443.     if(m_rasterState)
  444.     {
  445.         m_rasterState->Release();
  446.         m_rasterState = 0;
  447.     }
  448.  
  449.     if(m_depthStencilView)
  450.     {
  451.         m_depthStencilView->Release();
  452.         m_depthStencilView = 0;
  453.     }
  454.    
  455.     if(m_depthDisabledStencilState)
  456.     {
  457.         m_depthDisabledStencilState->Release();
  458.         m_depthDisabledStencilState = 0;
  459.     }
  460.  
  461.  
  462.     if(m_depthStencilState)
  463.     {
  464.         m_depthStencilState->Release();
  465.         m_depthStencilState = 0;
  466.     }
  467.  
  468.     if(m_depthStencilBuffer)
  469.     {
  470.         m_depthStencilBuffer->Release();
  471.         m_depthStencilBuffer = 0;
  472.     }
  473.  
  474.     if(m_renderTargetView)
  475.     {
  476.         m_renderTargetView->Release();
  477.         m_renderTargetView = 0;
  478.     }
  479.  
  480.     if(m_deviceContext)
  481.     {
  482.         m_deviceContext->Release();
  483.         m_deviceContext = 0;
  484.     }
  485.  
  486.     if(m_device)
  487.     {
  488.         m_device->Release();
  489.         m_device = 0;
  490.     }
  491.  
  492.     if(m_swapChain)
  493.     {
  494.         m_swapChain->Release();
  495.         m_swapChain = 0;
  496.     }
  497.  
  498.     return;
  499. }
  500.  
  501. void D3DClass::BeginScene(float red, float green, float blue, float alpha)
  502. {
  503.     float color[4];
  504.  
  505.     //setup the color to clear the buffer to
  506.     color[0] = red;
  507.     color[1] = green;
  508.     color[2] = blue;
  509.     color[3] = alpha;
  510.  
  511.     // Clear the back buffer.
  512.     m_deviceContext->ClearRenderTargetView(m_renderTargetView, color);
  513.    
  514.     // Clear the depth buffer.
  515.     m_deviceContext->ClearDepthStencilView(m_depthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0);
  516.  
  517.     return;
  518. }
  519.  
  520. void D3DClass::EndScene()
  521. {
  522.     // Present the back buffer to the screen since rendering is complete.
  523.     if(m_vsync_enabled)
  524.     {
  525.         // Lock to screen refresh rate.
  526.         m_swapChain->Present(1, 0);
  527.     }
  528.     else
  529.     {
  530.         // Present as fast as possible.
  531.         m_swapChain->Present(0, 0);
  532.     }
  533.  
  534.     return;
  535. }
  536.  
  537. ID3D11Device* D3DClass::GetDevice()
  538. {
  539.     return m_device;
  540. }
  541.  
  542.  
  543. ID3D11DeviceContext* D3DClass::GetDeviceContext()
  544. {
  545.     return m_deviceContext;
  546. }
  547.  
  548. void D3DClass::GetProjectionMatrix(D3DXMATRIX& projectionMatrix)
  549. {
  550.     projectionMatrix = m_projectionMatrix;
  551.     return;
  552. }
  553.  
  554.  
  555. void D3DClass::GetWorldMatrix(D3DXMATRIX& worldMatrix)
  556. {
  557.     worldMatrix = m_worldMatrix;
  558.     return;
  559. }
  560.  
  561.  
  562. void D3DClass::GetOrthoMatrix(D3DXMATRIX& orthoMatrix)
  563. {
  564.     orthoMatrix = m_orthoMatrix;
  565.     return;
  566. }
  567.  
  568. void D3DClass::GetVideoCardInfo(char* cardName, int& memory)
  569. {
  570.     strcpy_s(cardName, 128, m_videoCardDescription);
  571.     memory = m_videoCardMemory;
  572.     return;
  573. }
  574.  
  575. void D3DClass::TurnZBufferOn()
  576. {
  577.     m_deviceContext->OMSetDepthStencilState(m_depthStencilState ,1);
  578.     return;
  579. }
  580.  
  581. void D3DClass::TurnZBufferOff()
  582. {
  583.     m_deviceContext->OMSetDepthStencilState(m_depthDisabledStencilState, 1);
  584.     return;
  585. }
  586.  
  587. void D3DClass::TurnOnAlphaBlending()
  588. {
  589.     float blendFactor[4];
  590.    
  591.  
  592.     // Setup the blend factor.
  593.     blendFactor[0] = 0.0f;
  594.     blendFactor[1] = 0.0f;
  595.     blendFactor[2] = 0.0f;
  596.     blendFactor[3] = 0.0f;
  597.    
  598.     // Turn on the alpha blending.
  599.     m_deviceContext->OMSetBlendState(m_alphaEnableBlendingState, blendFactor, 0xffffffff);
  600.  
  601.     return;
  602. }
  603.  
  604. void D3DClass::TurnOffAlphaBlending()
  605. {
  606.     float blendFactor[4];
  607.    
  608.  
  609.     // Setup the blend factor.
  610.     blendFactor[0] = 0.0f;
  611.     blendFactor[1] = 0.0f;
  612.     blendFactor[2] = 0.0f;
  613.     blendFactor[3] = 0.0f;
  614.    
  615.     // Turn off the alpha blending.
  616.     m_deviceContext->OMSetBlendState(m_alphaDisableBlendingState, blendFactor, 0xffffffff);
  617.  
  618.     return;
  619. }
Add Comment
Please, Sign In to add comment