Jump to content

  • Log In with Google      Sign In   
  • Create Account


RythBlade

Member Since 01 Jan 2012
Offline Last Active Aug 13 2013 04:44 AM

Topics I've Started

[DX11] HLSL 5 setting SamplerState from within the shader isn't working

20 April 2012 - 03:35 AM

Hi there,
I'm having some trouble with a hlsl shader I've written for a deferred shader to do texture mapping onto a road in my game.
Basically I define a SamplerState at the top of my shader which I then use to sample my textures to map onto the surface.
I've defined it based on the MSDN documentation so that I shouldn't need to create and set and Samplers from within my C++ code and it can all be done from within the shader.
However when I run it, the sampler seems to be ignored. The directx debug gives the following warning:

D3D11: WARNING: ID3D11DeviceContext::Draw: The Pixel Shader unit expects a Sampler to be set at Slot 0, but none is bound. This is perfectly valid, as a NULL Sampler maps to default Sampler state. However, the developer may not want to rely on the defaults.  [ EXECUTION WARNING #352: DEVICE_DRAW_SAMPLER_NOT_SET ]

Here are the relevant code snippets from my shader:
// textures are passed in from my application
Texture2D widthMap  : register ( t0 );
Texture2D lengthMap  : register ( t1 );
// the sampler state defined in shader code so that my application
// doesn't have to
SamplerState MySampler
{
Filter = MIN_MAG_MIP_POINT;
    AddressU = Wrap;
    AddressV = Wrap;
};
// pixel shader which samples the texture
POut PShader(PIn input)
{
.....
output.colour = float4(lengthMap.Sample(MySampler, float2(input.texCoord.y, 0.0f)));
......
return output;
}


Ignore the dodgy texture coordinate - the premise for my texture sampling is to "build" the actual texture out of 2 textures which define the u colour and v colour - when both the u and v are filled in then I use the colour, otherwise that pixel is set to black - I'm using it to generate the road lines so that I can define any road line layout I want based on 2 very small textures.

I've dug through a few of the DirectX samples and I can see them declaring the SamplerState at the top just like I have and seem to have no such problems.
I've also tried declaring a samplerstate for each texture I want to sample and within each state I set the "Texture" field to the target texture. I changed it to the current version as this is how the directx samples seem to do it.

This problem is also present everywhere I sample a texture in my deferred shaders as well!

I've got no idea what I've missed. I can't see any settings that I need to set to tell DirectX to use what ever the shader itself supplies, as far as I was aware - declaring it in my shader should work fine.

I can post more examples of my shader files if needed.

Has anyone got any suggests???

Thanks very much!!

DirectX 11 Jerky rendering

03 April 2012 - 11:16 AM

Hi folks,
I'm still in the process of debugging this problem but I've got no idea what the problem really is. Basically I have a simple direct x 11 simulation running - 3 balls that spin.

Basically it mostly runs incredibly fast as you'd expect - how ever every 1 or seconds it seems to stick or jump. Varying from quite small to very large jumps.

I'm not aware of any extra work that I'm doing in between these frames - generally after initialisation the workload is constant.

I just wanted to try brainstorm a few potential causes for my problems.

The only thing I thought it might be is that I'm writing a parallel game engine that uses a deferred shader and deferred DirectX contexts.
My engine is broken up into tasks using the Intel Threaded building blocks API. I have an input, asset, update and graphics task. The update task relies on both input and assets tasks and the graphics task relies on update the update task.

I've profiled in sampling and instrumentation mode and can't seem to find a trouble spot if its some mystery blocking function or something but nothing stands out.

DXUT seems to think I'm running at a consistent 500 frames per second - but I added a few getTickCounts() and I can see a few spikes appearing in the frame time.

Any help or ideas with this would be fantastic!!

SDKMesh Vertex format + DirectX 11 mesh load and animator

22 March 2012 - 08:32 AM

Hi folks,
I've been looking for a quick and easy way to load in a model of a person and animate them for a simulator I'm working on.

Oh before I forget, I'm using DirectX 11.

I've been looking at the SDKMesh class in DXUT as it seems the fastest simplest way for me to achieve this, but I'm a little confused over the vertex format stuff.
I've looked at a few different examples using the class and each has a different, seemingly global, vertex format, but they all use the SDKMesh class. E.g. the old multi-animation example only has position and texture coordinates, but in the DXUT tutorials they add the normals as well. I'm new to dealing with meshes loaded from file in DirectX, I'm usually hard coding spheres for examples :P

Does the SDKMesh class deal with the vertex format separately - or is it that the vertex format is embedded in the .sdkmesh file, and you have to mirror it in the code??

I notice that the intel multi animation example using threaded building blocks includes some animation data as part of their vertex format and yet in the folder structure I can see an sdkmesh file - presumably the actual mesh - and an sdkmesh_anim file - which I assume is the animation data. I'm just wandering how they all deal with this....

This isn't something I'm interested in programming at the moment, nor do I have the time - my uni deadline is fast approaching :s
Basically I need a way to call load on something to get a mesh and call animate on it to make it move :P and then I'll move the object around the world as it animates. Lazy I know, but animation is not the theme of my project but I'd like it in there for completeness and an added facet of realism.

Sorry its a bit disjoint - I'm not really sure how to ask what I need :s
Hopefully you'll understand
Thanks very much!!

DirectX 11 can't find all of my graphics adapters

03 January 2012 - 06:01 PM

Hi folks,
I'm in a long battle with DirectX 11. Originally my aim was to do deferred shading (the original thread is here), but the code got a little hacky and a long story short, I started again trying to keep things clean and tidy.

Now my problem is with the creation of a device and swap chain using, D3D11CreateDeviceAndSwapChain(). It won't build me a context at feature level 11.

I'll try and explain everything I've tried and give you a code listing below.

I read somewhere that sometimes, especially on laptops the primary graphcis adapter is a low powered DX10.1 chip and the more powerful DX11 card has to be selected. I'm developing on a laptop so on these lines, I enumerated through all of the available graphics adapters using an IDXGIFactory and try to set up my D3D objects at feature level 11 on all of them until I succeed. It only returns 1 adapter before returning DXGI_ERROR_NOT_FOUND.
I extracted the adapters description in the debugger and it says it's an intel graphics family chip. On inspection of my device manager under Display Adapters I can see 2 adapters listed - this Intel® HD Graphics Family (that DX 11 seems to be able to find) and my NVIDIA GeForce GT 555M (which DX11 can't seem to find).
I've checked the NVidia website and my card is definitly fully DX 11 compatible. Infact I can run all of the DX11 samples in the SDK Sample browser!!! I've also made sure all of my drivers are up to date and still I can't get it build my D3D objects at feature level 11....

I've also tried letting DX try and pick the adapter for me by leaving the corresponding argument blank and simply specifying a feature level but it only manages feature level 10.1

So....any ideas on why it won't let me build my device and swap chain a feature leve 11??

Thanks very much in advance!

P.s. Here is all of my set up code so far. It just fills out the swap chain description, and creates a DXGI Factory. The creation code enumerates through the adapters trying to create everything at feature level 11, if it fails it moves to the next. As a last ditch if it really can't do it - it'll go for software emulation but let you opt out if you want.
HRESULT result = S_OK;
D3D_DRIVER_TYPE driverType;
// a hardware driver is preferred so this is default.
driverType = D3D_DRIVER_TYPE_HARDWARE;
//driverType = D3D_DRIVER_TYPE_REFERENCE;
IDXGIFactory* factory = NULL;
IDXGIAdapter* adapter = NULL;
// this will be used to step through the devices to find a DX11 compatible one
result = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
if(FAILED(result))
{
  m_crashed = true;
  return result;
}
DXGI_SWAP_CHAIN_DESC swapChainDesc;
D3D_FEATURE_LEVEL featureLevel;
// Initialize the swap chain description.
ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
// Set to a single back buffer.
swapChainDesc.BufferCount = 1;
// Set the width and height of the back buffer.
swapChainDesc.BufferDesc.Width = screenWidth;
swapChainDesc.BufferDesc.Height = screenHeight;
// Set regular 32-bit surface for the back buffer.
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
// TODO:FLAG - These can be altered to make the rendering match the refresh rate of the hardware
swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
// Set the usage of the back buffer.
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
// Set the handle for the window to render to.
swapChainDesc.OutputWindow = m_hWnd;
// Turn multisampling off.
swapChainDesc.SampleDesc.Count = D3D_SAMPLE_DESC_COUNT;
swapChainDesc.SampleDesc.Quality = D3D_SAMPLE_DESC_QUALITY;

swapChainDesc.Windowed = !fullscreen;
// Set the scan line ordering and scaling to unspecified.
swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
// Discard the back buffer contents after presenting.
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
// Don't set the advanced flags.
swapChainDesc.Flags = 0;
D3D_FEATURE_LEVEL targetLevels[] =
{
  D3D_FEATURE_LEVEL_11_0,
  //D3D_FEATURE_LEVEL_10_1,
  //D3D_FEATURE_LEVEL_10_0,
  //D3D_FEATURE_LEVEL_9_3,
  //D3D_FEATURE_LEVEL_9_2,
  //D3D_FEATURE_LEVEL_9_1,
};
int levelCount = 1;
// initialise to true, as if there aren't any adapters - then we've failed to create the device and swap chain
bool failedToCreateDeviceAndSwapChain = true;

char videoCardDescription[128];
DXGI_ADAPTER_DESC adapterDesc;
unsigned int stringLength;
// step through the adapters until we find a compatible adapter and successfully create a device and swap chain
for(int i = 0; factory->EnumAdapters(i, &adapter) != DXGI_ERROR_NOT_FOUND; i++)
{
  failedToCreateDeviceAndSwapChain = false;
  adapter->GetDesc(&adapterDesc);
  int error = wcstombs_s(&stringLength, videoCardDescription, 128, adapterDesc.Description, 128);
  driverType = D3D_DRIVER_TYPE_UNKNOWN;// as we're specifying an adapter to use, we must specify that the driver type is unknown!!!
  result = D3D11CreateDeviceAndSwapChain(
   adapter,
   driverType,
   NULL,
   0,
   targetLevels,
   levelCount,
   D3D11_SDK_VERSION,
   &swapChainDesc,
   &m_pSwapChain,
   &m_pDevice,
   &featureLevel,
   &m_pDeviceContext);
  // this device failed to create the devie and swap chain - ensure no handles are left by safely releasing what we were trying to create,
  // set the flag to fail and then try again with the next device
  if(FAILED(result))
  {
   SafeRelease(m_pSwapChain);
   SafeRelease(m_pDevice);
   SafeRelease(m_pDeviceContext);
   failedToCreateDeviceAndSwapChain = true;
   // try again with the next device
   continue;
  }
  // if we've reached this point then a compatible graphics device must've been found so break from the loop
  break;
}
// after looping through the devices we still couldn't find what we needed, therefore see if the user will use software emulation as a last attempt
if(failedToCreateDeviceAndSwapChain)
{
  int messageAnswer = MessageBox(
   m_hWnd,
   "No compatible graphics hardware was detected. Do you want to use software emulation instead? Note: This will be very slow!",
   "No compatible graphics hardware",
   MB_YESNO | MB_ICONWARNING);
  // the user doesn't want to use software emulation - therefore initialisation has failed. Quit here
  if(messageAnswer == IDNO)
  {
   m_crashed = true;
   return E_FAIL;
  }
  // the user is happy to use software emulation so make a final attempt at creating the device and swap chain at the desired level using the
  // reference device
  driverType = D3D_DRIVER_TYPE_REFERENCE;
  result = D3D11CreateDeviceAndSwapChain(
   NULL,
   driverType,
   NULL,
   0,
   targetLevels,
   levelCount,
   D3D11_SDK_VERSION,
   &swapChainDesc,
   &m_pSwapChain,
   &m_pDevice,
   &featureLevel,
   &m_pDeviceContext);
}
// Ensure all temporary COM objects are released
SafeRelease(factory);
return S_OK;

incorrect depth test result

01 January 2012 - 06:36 PM

Hi folks I was wondering if you guys could help me with a DirectX problem.

I'm trying to implement deferred shading. I've got a G-buffer set up and mostly working and a full screen quad ready to render it all to. Basically what's stopping me is what appears to be an incorrect depth test result when rendering.

I reverted back to drawing a simple cube and sphere on screen with some phong shading, but now these are suffering the same problem.

Simply if I don't set up the depth buffer - everything renders, albeit with obvious problems due to no depth test - if I do set it up and use it nothing renders and I'm stuck with a lovely clear screen.

Pix says the pixels are being eliminated by the depth test, but there's nothing to occlude anything....The history of the pixel wthin Pix however does display the correct colour before eiliminating the pixel.....
The directX debug output doesn't seem to give any clues either.....

I'm at a complete loss on this one, I've diffed the code between a working and non-working version and can't find what/where I've done wrong so here comes a code dump for your perusal:

Thanks very much for any help in advance!

This is the main class I'm doing the work in for now. It contains the setup/destruction and render code (see initD3D and render functions)
You should also see some of the deferred shading stuff commented out within this class.

#include "D3DApplication.h"
/*----------------------------------------------------------------------------\
*	  Initialisation and Clean up					   |
*----------------------------------------------------------------------------*/
/*
Constructor
Parameter list
  eventBroker:  the event broker for the application
inputHandler:  the input handler for the application
*/
D3DApplication::D3DApplication(InputHandler *inputHandler)
{
crashed = false;
pInputHandler = inputHandler;
}
/*
Destructor
*/
D3DApplication::~D3DApplication()
{
}
/*
Initialises Direct3D
Parameter list
  hWnd:  handle of window
*/
HRESULT D3DApplication::initD3D(HWND hWnd)
{
// create a struct to hold information about the swap chain
DXGI_SWAP_CHAIN_DESC scd;
// clear out the struct for use
ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC));
// fill the swap chain description struct
scd.BufferCount = 1;		// On use one backbuffer
scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; // use 32-bit colour
scd.BufferDesc.Width = SCREEN_WIDTH;	// set the back buffer width
scd.BufferDesc.Height = SCREEN_HEIGHT;	// set the back buffer height
scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; // how the swap chain is to be used
scd.OutputWindow = hWnd;	   // the window to be used
scd.SampleDesc.Count = D3D_SAMPLE_DESC_COUNT;  // how many multisamples - anti-aliasing
scd.SampleDesc.Quality = D3D_SAMPLE_DESC_QUALITY;
scd.Windowed = TRUE;		// windowed/full-screen mode
scd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; // allow full-screen switching
scd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
scd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
scd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
scd.Flags = 0;
// for this to work we need a directX 11 or 10.1 device so check for these
D3D_FEATURE_LEVEL levelsWanted[] =
{
  D3D_FEATURE_LEVEL_11_0,
  D3D_FEATURE_LEVEL_10_1,
};
D3D_FEATURE_LEVEL *acceptable = NULL;
// create a device, device context and swap chaing using the scd struct
HrCheck(D3D11CreateDeviceAndSwapChain(
  NULL,
  D3D_DRIVER_TYPE_HARDWARE, // we don't want to use the software reference device so only specify the hardware device
  NULL,
  NULL,
  levelsWanted,
  sizeof( levelsWanted ) / sizeof( levelsWanted[0] ),
  D3D11_SDK_VERSION,
  &scd,
  &pSwapchain,
  &pDev,
  acceptable,
  &pDevcon));
// now we have a device, check it supports directx 11
HrCheck(checkFeatureSupport());
// get the address of the back buffer
ID3D11Texture2D *pBackBufferTex;
// the first back buffer defined in the swap chain using ID3D11Texture2D COM object.
HrCheck(pSwapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBufferTex));
// use the back buffer address to create the render target
HrCheck(pDev->CreateRenderTargetView(pBackBufferTex, NULL, &pBackbuffer));
// we're done with the texture COM object so we can release it (this doesn't release the actual back
// buffer - just the COM object accessing it
SafeRelease(pBackBufferTex);
// prepare the depth stencil - create the depth texture
D3D11_TEXTURE2D_DESC descDepth;
ZeroMemory( &descDepth, sizeof(descDepth) );
	descDepth.Width = SCREEN_WIDTH;
	descDepth.Height = SCREEN_HEIGHT;
	descDepth.MipLevels = 1;
	descDepth.ArraySize = 1;
	descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
	descDepth.SampleDesc.Count = D3D_SAMPLE_DESC_COUNT;
	descDepth.SampleDesc.Quality = D3D_SAMPLE_DESC_QUALITY;
	descDepth.Usage = D3D11_USAGE_DEFAULT;
	descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
	descDepth.CPUAccessFlags = 0;
	descDepth.MiscFlags = 0;
	HrCheck(pDev->CreateTexture2D( &descDepth, NULL, &pDepthStencil));
// Create the depth stencil view
	D3D11_DEPTH_STENCIL_VIEW_DESC descDSV;
ZeroMemory( &descDSV, sizeof(descDSV) );
	descDSV.Format = descDepth.Format;
	descDSV.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
	descDSV.Texture2D.MipSlice = 0;
HrCheck(pDev->CreateDepthStencilView( pDepthStencil, &descDSV, &pDepthStencilView ));
// set the render target as the back buffer, using the depth stencil view
pDevcon->OMSetRenderTargets(1, &pBackbuffer, pDepthStencilView);
D3D11_BLEND_DESC desc;
ZeroMemory(&desc, sizeof(desc));
desc.AlphaToCoverageEnable = false;
desc.IndependentBlendEnable = true;
D3D11_RENDER_TARGET_BLEND_DESC targetDesc;
ZeroMemory(&targetDesc, sizeof(targetDesc));
desc.RenderTarget[0] = targetDesc;
desc.RenderTarget[0].BlendEnable = true;
desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
HrCheck(pDev->CreateBlendState(&desc, &pBlend));
// text rendering requires alpha blending
float blendFactors[] = { 0.0f, 0.0f, 0.0f, 0.0f };
pDevcon->OMSetBlendState(pBlend, blendFactors, 0xffffffff);
// set the viewport
D3D11_VIEWPORT viewport;
ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT));
viewport.TopLeftX = D3D_VIEWPORT_TOPLEFT_X;
viewport.TopLeftY = D3D_VIEWPORT_TOPLEFT_Y;
viewport.Width = D3D_VIEWPORT_WIDTH;
viewport.Height = D3D_VIEWPORT_HEIGHT;
viewport.MinDepth = D3D_VIEWPORT_MIN_DEPTH;
viewport.MaxDepth = D3D_VIEWPORT_MAX_DEPTH;
pDevcon->RSSetViewports(1, &viewport);
HrCheck(initPipeline());
HrCheck(initGraphics());

HrCheck(myCube.init(pDev, pDevcon));
HrCheck(mySphere.init(pDev, pDevcon, 1.0f, 10, 10));
HrCheck(myPlane.init(pDev, pDevcon));
lightPosition.x = 10.0f;
lightPosition.y = 10.0f;
lightPosition.z = 10.0f;
cubeRotation.x = 0.0f;
cubeRotation.y = 0.0f;
cubeRotation.z = 0.0f;
cubePosition.x = 0.0f;
cubePosition.y = 0.0f;
cubePosition.z = 0.0f;
D3D11_BUFFER_DESC bufferDesc;
//----------------------------- create the constants buffer ------------------------
ZeroMemory(&bufferDesc, sizeof(bufferDesc));
bufferDesc.Usage = D3D11_USAGE_DEFAULT;
bufferDesc.ByteWidth = sizeof(ToolVertexShaderConstantBuffer);
bufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
bufferDesc.CPUAccessFlags = 0;
bufferDesc.MiscFlags = 0;

	HRReturn(pDev->CreateBuffer( &bufferDesc, NULL, &m_pConstantBuffer ));
bufferDesc.Usage = D3D11_USAGE_DEFAULT;
bufferDesc.ByteWidth = sizeof(LightConstantBuffer);
bufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
bufferDesc.CPUAccessFlags = 0;
bufferDesc.MiscFlags = 0;
	HRReturn(pDev->CreateBuffer( &bufferDesc, NULL, &m_pLightingConstantBuffer ));

D3D11_TEXTURE2D_DESC textureDesc;
HRESULT result;
D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc;
D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc;
// Initialize the render target texture description.
ZeroMemory(&textureDesc, sizeof(textureDesc));
// Setup the render target texture description.
textureDesc.Width = SCREEN_WIDTH;
	textureDesc.Height = SCREEN_HEIGHT;
	textureDesc.MipLevels = 1;
	textureDesc.ArraySize = 1;
	textureDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
	textureDesc.SampleDesc.Count = D3D_SAMPLE_DESC_COUNT;
	textureDesc.SampleDesc.Quality = D3D_SAMPLE_DESC_QUALITY;
	textureDesc.Usage = D3D11_USAGE_DEFAULT;
	textureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
	textureDesc.CPUAccessFlags = 0;
	textureDesc.MiscFlags = 0;
// Create the render target texture.
HRReturn(pDev->CreateTexture2D(&textureDesc, NULL, &pGBufNormalTex));
HRReturn(pDev->CreateTexture2D(&textureDesc, NULL, &pGBufColourTex));
// Setup the description of the render target view.
renderTargetViewDesc.Format = textureDesc.Format;
renderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
renderTargetViewDesc.Texture2D.MipSlice = 0;
// Create the render target view.
HRReturn(pDev->CreateRenderTargetView(pGBufNormalTex, &renderTargetViewDesc, &pGBufNormalTarget));
HRReturn(pDev->CreateRenderTargetView(pGBufColourTex, &renderTargetViewDesc, &pGBufColourTarget));
/*
// Setup the description of the shader resource view.
shaderResourceViewDesc.Format = textureDesc.Format;
shaderResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
shaderResourceViewDesc.Texture2D.MostDetailedMip = 0;
shaderResourceViewDesc.Texture2D.MipLevels = 1;
// Create the shader resource view.
result = pDev->CreateShaderResourceView(m_renderTargetTexture, &shaderResourceViewDesc, &m_shaderResourceView);
if(FAILED(result))
{
  return false;
}*/
return S_OK;
}
/*
Checks whether the hardware supports the compute shader
*/
HRESULT D3DApplication::checkFeatureSupport()
{
D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS options;
HrCheck(pDev->CheckFeatureSupport(
  D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS,
  &options,
  sizeof(D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS)));
if( !options.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x )
{
  int returned = MessageBox(NULL, "COMPUTE NOTE SUPPORTED", "UNSUPPORTED HARDWARE", MB_YESNO | MB_ICONERROR);
  // if the user decides to continue with no compute acceleration, make sure we switch it off
  if(returned == IDYES)
  {
   //m_allowDirectCompute = false;
  }
  else
  {
   // something went wrong on the message box, or the user doesn't want to continue.
   // In this instance we quite the application be returning E_FAIL
   return E_FAIL;
  }
}
return S_OK;
}
/*
Initialises the rendering pipeline
*/
HRESULT D3DApplication::initPipeline()
{
// load and compile the two shaders
	ID3DBlob *VS, *PS, *gVS, *gPS, *gLightVS, *gLightPS;
  
HrCheck(CompileShaderFromFile(".\\Resources\\ToolsShaders.hlsl", "VShader", "vs_4_0", &VS));
HrCheck(CompileShaderFromFile(".\\Resources\\ToolsShaders.hlsl", "PShader", "ps_4_0", &PS));
HrCheck(CompileShaderFromFile(".\\Resources\\GBufferOutput.hlsl", "VShader", "vs_4_0", &gVS));
HrCheck(CompileShaderFromFile(".\\Resources\\GBufferOutput.hlsl", "PShader", "ps_4_0", &gPS));
HrCheck(CompileShaderFromFile(".\\Resources\\GBufferLighting.hlsl", "VShader", "vs_4_0", &gLightVS));
HrCheck(CompileShaderFromFile(".\\Resources\\GBufferLighting.hlsl", "PShader", "ps_4_0", &gLightPS));
	// encapsulate both shaders into shader objects
	HrCheck(pDev->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), NULL, &p3DVS));
	HrCheck(pDev->CreatePixelShader(PS->GetBufferPointer(), PS->GetBufferSize(), NULL, &p3DPS));
HrCheck(pDev->CreateVertexShader(gVS->GetBufferPointer(), gVS->GetBufferSize(), NULL, &pGBufferVS));
	HrCheck(pDev->CreatePixelShader(gPS->GetBufferPointer(), gPS->GetBufferSize(), NULL, &pGBufferPS));
HrCheck(pDev->CreateVertexShader(gLightVS->GetBufferPointer(), gLightVS->GetBufferSize(), NULL, &pGBufferLightingVS));
	HrCheck(pDev->CreatePixelShader(gLightPS->GetBufferPointer(), gLightPS->GetBufferSize(), NULL, &pGBufferLightingPS));
	// create the input layout object
	D3D11_INPUT_ELEMENT_DESC ied[] =
	{
		{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
		{"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
  {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
	};
	HrCheck(pDev->CreateInputLayout(ied, 3, VS->GetBufferPointer(), VS->GetBufferSize(), &pLayout));
	pDevcon->IASetInputLayout(pLayout);
SafeRelease(VS);
SafeRelease(PS);
SafeRelease(gVS);
SafeRelease(gPS);
SafeRelease(gLightVS);
SafeRelease(gLightPS);

return S_OK;
}
/*
Initialises the graphics
*/
HRESULT D3DApplication::initGraphics()
{
// initiaise the camera position
camera.setRadius(10.0f);
camera.setMatrices();
D3D11_BUFFER_DESC bufferDesc;
//----------------------------- create the constants buffer ------------------------
ZeroMemory(&bufferDesc, sizeof(bufferDesc));
bufferDesc.Usage = D3D11_USAGE_DEFAULT;
bufferDesc.ByteWidth = sizeof(VertexShaderConstantBuffer);
bufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
bufferDesc.CPUAccessFlags = 0;
bufferDesc.MiscFlags = 0;

	HrCheck(pDev->CreateBuffer( &bufferDesc, NULL, &pConstantBuffer ));
bufferDesc.Usage = D3D11_USAGE_DEFAULT;
bufferDesc.ByteWidth = sizeof(LightConstantBuffer);
bufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
bufferDesc.CPUAccessFlags = 0;
bufferDesc.MiscFlags = 0;
	HrCheck(pDev->CreateBuffer( &bufferDesc, NULL, &pLightingConstantBuffer ));
return S_OK;
}
/*
Cleans up Direct3D and COM
Parameter list
  hWnd:  handle of window
*/
HRESULT D3DApplication::cleanD3D()
{
// direct x can't close properly when in full screen mode - so ensure everything is windowed
HrCheck(pSwapchain->SetFullscreenState(FALSE, NULL)); // switch to windowed mode
// close and release all existing COM objects
SafeRelease(pBlend);
SafeRelease(m_pConstantBuffer);
SafeRelease(pGBufferVS);
SafeRelease(pGBufferPS);
SafeRelease(pGBufferLightingVS);
SafeRelease(pGBufferLightingPS);
SafeRelease(pGBufNormalTarget);
SafeRelease(pGBufColourTarget);
SafeRelease(pGBufNormalTex);
SafeRelease(pGBufColourTex);
SafeRelease(m_pLightingConstantBuffer);
SafeRelease(pConstantBuffer);
SafeRelease(pLightingConstantBuffer);
SafeRelease(pDepthStencil);
SafeRelease(pDepthStencilView);
SafeRelease(pLayout);
SafeRelease(p3DVS);
SafeRelease(p3DPS);
SafeRelease(pSwapchain);
SafeRelease(pBackbuffer);
SafeRelease(pDev);
SafeRelease(pDevcon);
return S_OK;
}
/*----------------------------------------------------------------------------\
*		 Update						 |
*----------------------------------------------------------------------------*/
HRESULT D3DApplication::run()
{
if(crashed)
{
  return E_FAIL;
}
if(FAILED(update()))
{
  return E_FAIL;
}
if(FAILED(renderFrame()))
{
  return E_FAIL;
}
return S_OK;
}
/*
Runs the update for the frame.
*/
HRESULT D3DApplication::update()
{
handleCameraInput();
handleInput();
return S_OK;
}
void D3DApplication::handleInput()
{
if((*pInputHandler->getKeyboardMap())[KEY_Q] == KEY_HELD)
{
  lightPosition.x += 0.001;
}
if((*pInputHandler->getKeyboardMap())[KEY_A] == KEY_HELD)
{
  lightPosition.x -= 0.001;
}
if((*pInputHandler->getKeyboardMap())[KEY_W] == KEY_HELD)
{
  lightPosition.y += 0.001;
}
if((*pInputHandler->getKeyboardMap())[KEY_S] == KEY_HELD)
{
  lightPosition.y -= 0.001;
}
if((*pInputHandler->getKeyboardMap())[KEY_E] == KEY_HELD)
{
  lightPosition.z += 0.001;
}
if((*pInputHandler->getKeyboardMap())[KEY_D] == KEY_HELD)
{
  lightPosition.z -= 0.001;
}
}
void D3DApplication::handleCameraInput()
{
if((*pInputHandler->getMouseButtonMap())[MOUSE_LBUTTON] == KEY_HELD)
{
  D3DXVECTOR3 *delta = pInputHandler->getMousePosDelta();
  if(delta->x != 0)
  {
   camera.setHorizontalRotation(camera.getHorizontalRotation() + MOUSE_X_SCROLL_SPEED * delta->x);
  }
  if(delta->y != 0)
  {
   camera.setVerticalRotation(camera.getVerticalRotation() + MOUSE_Y_SCROLL_SPEED * delta->y);
  }
}
float mouseWheelDelta = pInputHandler->getMouseWheelDelta();
if(mouseWheelDelta != 0)
{
  camera.setRadius(camera.getRadius() + MOUSE_WHEEL_SCROLL_SPEED * mouseWheelDelta);
}
}
/*----------------------------------------------------------------------------\
*		Rendering						 |
*----------------------------------------------------------------------------*/
/*
Function used to render a single frame
*/
HRESULT D3DApplication::renderFrame()
{
// clear the screen and depth buffer
pDevcon->ClearRenderTargetView(pBackbuffer, D3DXCOLOR(D3D_CLEAR_COLOUR));
pDevcon->ClearRenderTargetView(pGBufColourTarget, D3DXCOLOR(1.0f, 1.0f, 1.0f, 0.0f));
pDevcon->ClearRenderTargetView(pGBufNormalTarget, D3DXCOLOR(1.0f, 0.0f, 0.0f, 0.0f));
	pDevcon->ClearDepthStencilView(pDepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0);
// render the 3D world first
HrCheck(render3DWorld());
// switch the back buffer and front buffer
HrCheck(pSwapchain->Present(0, 0));
return S_OK;
}
HRESULT D3DApplication::render3DWorld()
{
// set the shader objects to be the standard 3D shaders.
	pDevcon->VSSetShader(p3DVS, 0, 0);
	pDevcon->PSSetShader(p3DPS, 0, 0);
// set the vertex and index buffers for the pipeline
	UINT stride = sizeof(VERTEX);
	UINT offset = 0;

// finalise the view and projection matrices for this frame
camera.setMatrices();
LightConstantBuffer lightBuffer;
lightBuffer.eyePos.x = camera.getCameraPos()->x;
lightBuffer.eyePos.y = camera.getCameraPos()->y;
lightBuffer.eyePos.z = camera.getCameraPos()->z;
lightBuffer.eyePos.w = 99.99;
lightBuffer.lightPositon.x = lightPosition.x;
lightBuffer.lightPositon.y = lightPosition.y;
lightBuffer.lightPositon.z = lightPosition.z;
lightBuffer.lightPositon.w = 99.99;
pDevcon->UpdateSubresource( m_pLightingConstantBuffer, 0, NULL, &lightBuffer, sizeof(LightConstantBuffer), 0 );
ToolVertexShaderConstantBuffer cb;
// pass the constant buffer information into the vertex shader constant buffer
// due to the way the graphics card arranges it's memory, the matrices need to be transposed
D3DXMatrixTranspose(&cb.mView, camera.getViewMat() );
D3DXMatrixTranspose(&cb.mProjection, camera.getProjMat() );

D3DXMATRIXA16 tempx;
D3DXMATRIXA16 tempy;
D3DXMATRIXA16 tempz;
cubeRotation.x += 0.001f;
cubeRotation.y += 0.001f;
cubeRotation.z += 0.001f;
cubePosition.x = 0.0f;
cubePosition.y = 0.0f;
cubePosition.z = 0.0f;
D3DXMatrixTranslation(
  &cb.mWorld,
  cubePosition.x,
  cubePosition.y,
  cubePosition.z);
D3DXMatrixRotationX(&tempx, cubeRotation.x);
D3DXMatrixRotationY(&tempy, cubeRotation.y);
D3DXMatrixRotationZ(&tempz, cubeRotation.z);
D3DXMatrixMultiply(&tempx, &tempx, &tempy);
D3DXMatrixMultiply(&tempx, &tempx, &tempz);
D3DXMatrixMultiply(&cb.mWorld, &tempx, &cb.mWorld);
D3DXMatrixTranspose(&cb.mWorld, &cb.mWorld );
cb.materialColour.x = 1.0f;
cb.materialColour.y = 0.0f;
cb.materialColour.z = 0.0f;
cb.materialColour.w = 1.0f;
pDevcon->UpdateSubresource( m_pConstantBuffer, 0, NULL, &cb, 0, 0 );
pDevcon->VSSetConstantBuffers( 0, 1, &m_pConstantBuffer );
pDevcon->VSSetConstantBuffers( 1, 1, &m_pLightingConstantBuffer );
pDevcon->PSSetConstantBuffers( 1, 1, &m_pLightingConstantBuffer );
// select which primtive type we are using
pDevcon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
//myCube.setBuffers();
//myCube.draw();
mySphere.setBuffers();
mySphere.draw();
// mark the light position.
D3DXMatrixTranslation(
  &cb.mWorld,
  lightPosition.x,
  lightPosition.y,
  lightPosition.z);
D3DXMatrixTranspose(&cb.mWorld, &cb.mWorld );
pDevcon->UpdateSubresource( m_pConstantBuffer, 0, NULL, &cb, 0, 0 );
pDevcon->VSSetConstantBuffers( 0, 1, &m_pConstantBuffer );
pDevcon->VSSetConstantBuffers( 1, 1, &m_pLightingConstantBuffer );
pDevcon->PSSetConstantBuffers( 1, 1, &m_pLightingConstantBuffer );
myCube.setBuffers();
myCube.draw();

/*
// set the shader objects to be the standard 3D shaders.
	pDevcon->VSSetShader(pGBufferVS, 0, 0);
	pDevcon->PSSetShader(pGBufferPS, 0, 0);
// set the vertex and index buffers for the pipeline
	UINT stride = sizeof(VERTEX);
	UINT offset = 0;

// finalise the view and projection matrices for this frame
camera.setMatrices();
ToolVertexShaderConstantBuffer cb;
// pass the constant buffer information into the vertex shader constant buffer
// due to the way the graphics card arranges it's memory, the matrices need to be transposed
D3DXMatrixTranspose(&cb.mView, camera.getViewMat() );
D3DXMatrixTranspose(&cb.mProjection, camera.getProjMat() );

D3DXMATRIXA16 tempx;
cubeRotation.x += 0.001f;
D3DXMatrixRotationX(&cb.mWorld, cubeRotation.x);
D3DXMatrixTranspose(&cb.mWorld, &cb.mWorld );
cb.materialColour.x = 1.0f;
cb.materialColour.y = 0.0f;
cb.materialColour.z = 0.0f;
cb.materialColour.w = 1.0f;
pDevcon->UpdateSubresource( m_pConstantBuffer, 0, NULL, &cb, 0, 0 );
pDevcon->VSSetConstantBuffers( 0, 1, &m_pConstantBuffer );
// select which primtive type we are using
pDevcon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
//myCube.setBuffers();
mySphere.setBuffers();
ID3D11RenderTargetView *targets[2];
targets[0] = pGBufNormalTarget;
targets[1] = pGBufColourTarget;
pDevcon->OMSetRenderTargets(2, targets, pDepthStencilView);
// render to the GBuffer
//myCube.draw();
mySphere.draw();

// mark the light position.
D3DXMatrixTranslation(
  &cb.mWorld,
  lightPosition.x,
  lightPosition.y,
  lightPosition.z);
D3DXMatrixTranspose(&cb.mWorld, &cb.mWorld );
pDevcon->UpdateSubresource( m_pConstantBuffer, 0, NULL, &cb, 0, 0 );
pDevcon->VSSetConstantBuffers( 0, 1, &m_pConstantBuffer );
pDevcon->VSSetConstantBuffers( 1, 1, &m_pLightingConstantBuffer );
pDevcon->PSSetConstantBuffers( 1, 1, &m_pLightingConstantBuffer );
mySphere.setBuffers();
mySphere.draw();


/* // set the shader objects to be the standard 3D shaders.
	pDevcon->VSSetShader(pGBufferLightingVS, 0, 0);
	pDevcon->PSSetShader(pGBufferLightingPS, 0, 0);

// when doing the final render
// set the render target as the back buffer, using the depth stencil view
pDevcon->OMSetRenderTargets(1, &pBackbuffer, pDepthStencilView);
D3DXMatrixIdentity(&cb.mWorld);
D3DXMatrixTranspose(&cb.mWorld, &cb.mWorld );
cb.materialColour.x = 1.0f;
cb.materialColour.y = 0.0f;
cb.materialColour.z = 0.0f;
cb.materialColour.w = 1.0f;
pDevcon->UpdateSubresource( m_pConstantBuffer, 0, NULL, &cb, 0, 0 );
LightConstantBuffer lightBuffer;
lightBuffer.eyePos.x = camera.getCameraPos()->x;
lightBuffer.eyePos.y = camera.getCameraPos()->y;
lightBuffer.eyePos.z = camera.getCameraPos()->z;
lightBuffer.eyePos.w = 99.99;
lightBuffer.lightPositon.x = lightPosition.x;
lightBuffer.lightPositon.y = lightPosition.y;
lightBuffer.lightPositon.z = lightPosition.z;
lightBuffer.lightPositon.w = 99.99;
pDevcon->UpdateSubresource( m_pLightingConstantBuffer, 0, NULL, &lightBuffer, sizeof(LightConstantBuffer), 0 );
pDevcon->VSSetConstantBuffers( 0, 1, &m_pConstantBuffer );
pDevcon->VSSetConstantBuffers( 1, 1, &m_pLightingConstantBuffer );
pDevcon->PSSetConstantBuffers( 1, 1, &m_pLightingConstantBuffer );
myPlane.setBuffers();
//render to the back buffer
myPlane.draw();*/
return S_OK;
}

This is the sphere class I'm drawing:
// LCCREDIT start of LunaDX10.2
#include "D3DSphere.h"

D3DSphere::D3DSphere()
: mNumVertices(0), mNumFaces(0), md3dDevice(0), mVB(0), mIB(0),
  mRadius(0.0f), mNumSlices(0), mNumStacks(0)
{
}
D3DSphere::~D3DSphere()
{
// ensure the COM objects are all cleaned up
SafeRelease(mVB);
SafeRelease(mIB);
}
HRESULT D3DSphere::init(ID3D11Device* device, ID3D11DeviceContext *pDeviceContext, float radius, UINT numSlices, UINT numStacks)
{
md3dDevice = device;
pDevcon = pDeviceContext;
mRadius	= radius;
mNumSlices = numSlices;
mNumStacks = numStacks;
std::vector<VERTEX> vertices;
std::vector<DWORD> indices;
buildStacks(vertices, indices);

mNumVertices = (UINT)vertices.size();
mNumFaces	= (UINT)indices.size()/3;
//----------------------------- create the vertex buffer---------------------------
D3D11_BUFFER_DESC bufferDesc;
D3D11_SUBRESOURCE_DATA defaultData;
ZeroMemory(&bufferDesc, sizeof(bufferDesc));
ZeroMemory(&defaultData, sizeof(defaultData));
defaultData.pSysMem = &vertices[0];
bufferDesc.Usage = D3D11_USAGE_IMMUTABLE;
bufferDesc.ByteWidth = sizeof(VERTEX) * mNumVertices;
bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bufferDesc.CPUAccessFlags = 0;
bufferDesc.MiscFlags = 0;
HRReturn(device->CreateBuffer(&bufferDesc, &defaultData, &mVB));
//----------------------------- create the index buffer----------------------------
ZeroMemory(&bufferDesc, sizeof(bufferDesc));
ZeroMemory(&defaultData, sizeof(defaultData));
defaultData.pSysMem = &indices[0];
bufferDesc.Usage = D3D11_USAGE_IMMUTABLE;
bufferDesc.ByteWidth = sizeof(DWORD) * mNumFaces * 3;
bufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
bufferDesc.CPUAccessFlags = 0;
bufferDesc.MiscFlags = 0;
HRReturn(device->CreateBuffer(&bufferDesc, &defaultData, &mIB));
return S_OK;
}
void D3DSphere::setBuffers()
{
UINT stride = sizeof(VERTEX);
	UINT offset = 0;
	pDevcon->IASetVertexBuffers(0, 1, &mVB, &stride, &offset);
pDevcon->IASetIndexBuffer(mIB, DXGI_FORMAT_R32_UINT, 0);
}
void D3DSphere::draw()
{
pDevcon->DrawIndexed(mNumFaces*3, 0, 0);
}
void D3DSphere::buildStacks(VertexList& vertices, IndexList& indices)
{
float phiStep = D3DX_PI / mNumStacks;
// do not count the poles as rings
UINT numRings = mNumStacks-1;
// Compute vertices for each stack ring.
for(UINT i = 1; i <= numRings; ++i)
{
  float phi = i*phiStep;
  // vertices of ring
  float thetaStep = 2.0f * D3DX_PI /mNumSlices;
  for(UINT j = 0; j <= mNumSlices; ++j)
  {
   float theta = j*thetaStep;
   VERTEX v;
   // spherical to cartesian
   v.Position.x = mRadius*sinf(phi)*cosf(theta);
   v.Position.y = mRadius*cosf(phi);
   v.Position.z = mRadius*sinf(phi)*sinf(theta);
   D3DXVec3Normalize(&v.normal, &v.Position);
   vertices.push_back( v );
  }
}
// poles: note that there will be texture coordinate distortion

VERTEX poles[] =
	{
		{D3DXVECTOR3(0.0f, -mRadius, 0.0f), D3DXVECTOR3(0.0f, -1.0f, 0.0f), 0.0f, 1.0f},
  {D3DXVECTOR3(0.0f, mRadius, 0.0f), D3DXVECTOR3(0.0f, 1.0f, 0.0f), 0.0f, 0.0f}
};
vertices.push_back( poles[0] );
vertices.push_back( poles[1] );
UINT northPoleIndex = (UINT)vertices.size()-1;
UINT southPoleIndex = (UINT)vertices.size()-2;
UINT numRingVertices = mNumSlices+1;
// Compute indices for inner stacks (not connected to poles).
for(UINT i = 0; i < mNumStacks-2; ++i)
{
  for(UINT j = 0; j < mNumSlices; ++j)
  {
   indices.push_back(i*numRingVertices + j);
   indices.push_back(i*numRingVertices + j+1);
   indices.push_back((i+1)*numRingVertices + j);
   indices.push_back((i+1)*numRingVertices + j);
   indices.push_back(i*numRingVertices + j+1);
   indices.push_back((i+1)*numRingVertices + j+1);
  }
}
// Compute indices for top stack.  The top stack was written
// first to the vertex buffer.
for(UINT i = 0; i < mNumSlices; ++i)
{
  indices.push_back(northPoleIndex);
  indices.push_back(i+1);
  indices.push_back(i);
}
// Compute indices for bottom stack.  The bottom stack was written
// last to the vertex buffer, so we need to offset to the index
// of first vertex in the last ring.
UINT baseIndex = (numRings-1)*numRingVertices;
for(UINT i = 0; i < mNumSlices; ++i)
{
  indices.push_back(southPoleIndex);
  indices.push_back(baseIndex+i);
  indices.push_back(baseIndex+i+1);
}
}
// end of LunaDX10.2

and this is the cube class I'm drawing:
#include "D3DCube.h"

D3DCube::D3DCube()
: mNumVertices(0), mNumFaces(0), pDev(0), m_pVertexBuffer(0), m_pIndexBuffer(0)
{
}
D3DCube::~D3DCube()
{
// ensure the COM objects are all cleaned up
SafeRelease(m_pVertexBuffer);
SafeRelease(m_pIndexBuffer);
}
HRESULT D3DCube::init(ID3D11Device* device, ID3D11DeviceContext *pDeviceContext)
{
pDev = device;
pDevcon = pDeviceContext;
std::vector<VERTEX> vertices;
std::vector<DWORD> indices;
buildCube(vertices, indices);

mNumVertices = (UINT)vertices.size();
mNumFaces	= (UINT)indices.size()/3;
//----------------------------- create the vertex buffer---------------------------
D3D11_BUFFER_DESC bufferDesc;
D3D11_SUBRESOURCE_DATA defaultData;
ZeroMemory(&bufferDesc, sizeof(bufferDesc));
ZeroMemory(&defaultData, sizeof(defaultData));
defaultData.pSysMem = &vertices[0];
bufferDesc.Usage = D3D11_USAGE_IMMUTABLE;
bufferDesc.ByteWidth = sizeof(VERTEX) * mNumVertices;
bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bufferDesc.CPUAccessFlags = 0;
bufferDesc.MiscFlags = 0;
HRReturn(pDev->CreateBuffer(&bufferDesc, &defaultData, &m_pVertexBuffer));
//----------------------------- create the index buffer----------------------------
ZeroMemory(&bufferDesc, sizeof(bufferDesc));
ZeroMemory(&defaultData, sizeof(defaultData));
defaultData.pSysMem = &indices[0];
bufferDesc.Usage = D3D11_USAGE_IMMUTABLE;
bufferDesc.ByteWidth = sizeof(DWORD) * mNumFaces * 3;
bufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
bufferDesc.CPUAccessFlags = 0;
bufferDesc.MiscFlags = 0;
HRReturn(pDev->CreateBuffer(&bufferDesc, &defaultData, &m_pIndexBuffer));
return S_OK;
}
void D3DCube::setBuffers()
{
UINT stride = sizeof(VERTEX);
	UINT offset = 0;
	pDevcon->IASetVertexBuffers(0, 1, &m_pVertexBuffer, &stride, &offset);
pDevcon->IASetIndexBuffer(m_pIndexBuffer, DXGI_FORMAT_R32_UINT, 0);
}
void D3DCube::draw()
{
pDevcon->DrawIndexed(mNumFaces*3, 0, 0);
}
void D3DCube::buildCube(VertexList& vertices, IndexList& indices)
{
VERTEX vertex1;
vertex1.Position = SIDE_A;
vertex1.normal = NORMAL_1;
vertices.push_back(vertex1);
VERTEX vertex2;
vertex2.Position = SIDE_B;
vertex2.normal = NORMAL_1;
vertices.push_back(vertex2);
VERTEX vertex3;
vertex3.Position = SIDE_C;
vertex3.normal = NORMAL_1;
vertices.push_back(vertex3);

/**********************************/
VERTEX vertex4;
vertex4.Position = SIDE_B;
vertex4.normal = NORMAL_1;
vertices.push_back(vertex4);
VERTEX vertex5;
vertex5.Position = SIDE_D;
vertex5.normal = NORMAL_1;
vertices.push_back(vertex5);
VERTEX vertex6;
vertex6.Position = SIDE_C;
vertex6.normal = NORMAL_1;
vertices.push_back(vertex6);
/**********************************/
VERTEX vertex7;
vertex7.Position = SIDE_B;
vertex7.normal = NORMAL_2;
vertices.push_back(vertex7);
VERTEX vertex8;
vertex8.Position = SIDE_F;
vertex8.normal = NORMAL_2;
vertices.push_back(vertex8);
VERTEX vertex9;
vertex9.Position = SIDE_D;
vertex9.normal = NORMAL_2;
vertices.push_back(vertex9);
/**********************************/
VERTEX vertex10;
vertex10.Position = SIDE_D;
vertex10.normal = NORMAL_2;
vertices.push_back(vertex10);
VERTEX vertex11;
vertex11.Position = SIDE_F;
vertex11.normal = NORMAL_2;
vertices.push_back(vertex11);
VERTEX vertex12;
vertex12.Position = SIDE_G;
vertex12.normal = NORMAL_2;
vertices.push_back(vertex12);
/**********************************/
VERTEX vertex13;
vertex13.Position = SIDE_G;
vertex13.normal = NORMAL_3;
vertices.push_back(vertex13);
VERTEX vertex14;
vertex14.Position = SIDE_F;
vertex14.normal = NORMAL_3;
vertices.push_back(vertex14);
VERTEX vertex15;
vertex15.Position = SIDE_E;
vertex15.normal = NORMAL_3;
vertices.push_back(vertex15);
/**********************************/
VERTEX vertex16;
vertex16.Position = SIDE_G;
vertex16.normal = NORMAL_3;
vertices.push_back(vertex16);
VERTEX vertex17;
vertex17.Position = SIDE_E;
vertex17.normal = NORMAL_3;
vertices.push_back(vertex17);
VERTEX vertex18;
vertex18.Position = SIDE_H;
vertex18.normal = NORMAL_3;
vertices.push_back(vertex18);
/**********************************/
VERTEX vertex19;
vertex19.Position = SIDE_E;
vertex19.normal = NORMAL_4;
vertices.push_back(vertex19);
VERTEX vertex20;
vertex20.Position = SIDE_A;
vertex20.normal = NORMAL_4;
vertices.push_back(vertex20);
VERTEX vertex21;
vertex21.Position = SIDE_H;
vertex21.normal = NORMAL_4;
vertices.push_back(vertex21);
/**********************************/
VERTEX vertex22;
vertex22.Position = SIDE_A;
vertex22.normal = NORMAL_4;
vertices.push_back(vertex22);
VERTEX vertex23;
vertex23.Position = SIDE_C;
vertex23.normal = NORMAL_4;
vertices.push_back(vertex23);
VERTEX vertex24;
vertex24.Position = SIDE_H;
vertex24.normal = NORMAL_4;
vertices.push_back(vertex24);
/**********************************/
VERTEX vertex25;
vertex25.Position = SIDE_E;
vertex25.normal = NORMAL_6;
vertices.push_back(vertex25);
VERTEX vertex26;
vertex26.Position = SIDE_F;
vertex26.normal = NORMAL_6;
vertices.push_back(vertex26);
VERTEX vertex27;
vertex27.Position = SIDE_B;
vertex27.normal = NORMAL_6;
vertices.push_back(vertex27);
/**********************************/
VERTEX vertex28;
vertex28.Position = SIDE_A;
vertex28.normal = NORMAL_6;
vertices.push_back(vertex28);
VERTEX vertex29;
vertex29.Position = SIDE_E;
vertex29.normal = NORMAL_6;
vertices.push_back(vertex29);
VERTEX vertex30;
vertex30.Position = SIDE_B;
vertex30.normal = NORMAL_6;
vertices.push_back(vertex30);
/**********************************/
VERTEX vertex31;
vertex31.Position = SIDE_D;
vertex31.normal = NORMAL_5;
vertices.push_back(vertex31);
VERTEX vertex32;
vertex32.Position = SIDE_G;
vertex32.normal = NORMAL_5;
vertices.push_back(vertex32);
VERTEX vertex33;
vertex33.Position = SIDE_H;
vertex33.normal = NORMAL_5;
vertices.push_back(vertex33);
/**********************************/
VERTEX vertex34;
vertex34.Position = SIDE_D;
vertex34.normal = NORMAL_5;
vertices.push_back(vertex34);
VERTEX vertex35;
vertex35.Position = SIDE_H;
vertex35.normal = NORMAL_5;
vertices.push_back(vertex35);
VERTEX vertex36;
vertex36.Position = SIDE_C;
vertex36.normal = NORMAL_5;
vertices.push_back(vertex36);
/**********************************/
for(int i = 0; i < vertices.size(); i++)
{
  indices.push_back(i);
}
}

PARTNERS