Need to understand the correct use of constantbuffer incoming data to shader::
Cb1.voutputcolor = XMFLOAT4 (0, 0, 0, 0); G_pimmediatecontext->updatesubresource (G_pconstantbuffer, 0, NULL, &CB1 , 0, 0);
Update cube Data////Render the Cube//g_pimmediatecontext->vssetshader (G_pvertexshader, NULL, 0);g_pimmediatecontext->vssetconstantbuffers (0, 1, &g_pconstantbuffer);
VS shader needs constant dataG_pimmediatecontext->pssetshader (G_ppixelshader, NULL, 0);g_pimmediatecontext->pssetconstantbuffers (0, 1, &g_pconstantbuffer);
PS shader incoming constant dataG_pimmediatecontext->drawindexed (0, 0);////Render each light//for (int m = 0; m < 2; m++) {Xmmatrix mlight = Xmmatrixtranslationfromvector (5.0f * XMLOADFLOAT4 (&vlightdirs[m])); Xmmatrix Mlightscale = xmmatrixscaling (0.2f, 0.2f, 0.2f); Mlight = Mlightscale * mlight;//Update the world variable to reflect the current Lightcb1.mworld = Xmmatrixtranspose (mLi ght); Cb1.voutputcolor = vlightcolors[m];g_pimmediatecontext->Updatesubresource(G_pconstantbuffer, 0, NULL, &CB1, 0, 0);
//Update the location of LightcubeG_pimmediatecontext->pssetshader (G_ppixelshadersolid, NULL, 0);
//Because light does not use constant data, it does not require pssetconstantbuffers
G_pimmediatecontext->drawindexed (36, 0, 0); }
Dx11 Getting Started Tutorial 06: Understanding Context->updatesubsource and Setconstantbuffers Directxsamplebrowser (June 2010)