Advertisement
Ember

drawindexed

Dec 12th, 2015
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.32 KB | None | 0 0
  1. Void Testbed::Update()
  2. {
  3.     Graphics::Manager* graphicsManager = Graphics::Manager::Singleton;
  4.     Resource::Manager* resourceManager = Resource::Manager::Singleton;
  5.     // These too (no pun intended)
  6.     Graphics::Device::Context& deviceContext = graphicsManager->Context;
  7.     Graphics::Window& window = graphicsManager->Window;
  8.  
  9.     // Bind the layout
  10.     auto layout = resourceManager->GetLayout("Layout/FullTangent3D");
  11.     layout->Bind();
  12.  
  13.     // Bind the shaders
  14.     auto shader = resourceManager->GetShader("FullTangent3D.vso");
  15.     shader->BindVS();
  16.     shader = resourceManager->GetShader("ColorPS.pso");
  17.     shader->BindPS();
  18.  
  19.     Float time = mTimer.Elapsed(Timer::Seconds);
  20.     // Generate the transforms and constant buffer data
  21.     Aligned Float4x4 world = To4x4(RotationZ(time)); //To4x4(RotationZ(fmod(ttime * 1.0f, 1.0f) * Pi * 2.0f));
  22.     SSE::Float4x4 worldMatrix = SSE::Load(world); //Matrix::RotationZ((fmod(ttime * 1.0f, 1.0f) * Pi * 2.0f));
  23.     //SSE::Float4x4 viewMatrix = SSE::LookAt(SSE::Load(-5.0f * cosf(time), -5.0f * sinf(time), 3.0f), SSE::Load(0.0f, 0.0f, 0.0f));
  24.     SSE::Float4x4 viewMatrix = SSE::LookAt(SSE::Load(-3.0f, -3.0f, 3.0f), SSE::Load(0.0f, 0.0f, 0.0f));
  25.     SSE::Float4x4 projectionMatrix = SSE::PerspectiveFovLH(pi / 4.0f, (Float)window.Width / window.Height, 0.01f, 1000.0f); //SSE::Load(window.ProjectionMatrix);
  26.     // -- //
  27.     Transforms buffer;
  28.     buffer.WorldMatrix = SSE::Store(SSE::Transpose(worldMatrix));
  29.     buffer.ViewProjectionMatrix = SSE::Store(SSE::MultiplyTranspose(viewMatrix, projectionMatrix));
  30.     buffer.WorldViewProjectionMatrix = SSE::Store(SSE::MultiplyTranspose(SSE::Multiply(worldMatrix, viewMatrix), projectionMatrix));
  31.     //buffer.WorldMatrix = Transpose(world);
  32.     //buffer.ViewProjectionMatrix = Transpose(Multiply(view, projection));
  33.     //buffer.WorldViewProjectionMatrix = Transpose(Multiply(Multiply(world, view), projection));
  34.     mBuffer.Update(&buffer);
  35.     // -- //
  36.     Colors colors;
  37.     colors.ColorPrimary = Float3(0.9f, 0.9f, 0.9f);
  38.     colors.ColorSecondary = Float3(0.9f, 0.7f, 0.1f);
  39.     colors.ColorOptional = Float3(0.9f, 0.1f, 0.1f);
  40.     mColors.Update(&colors);
  41.     // -- //
  42.     PointLight light;
  43.     light.Position = Float3(30.0f, 0.0f, 40.0f);
  44.     light.Radius = 3.0f;
  45.     light.Color = Float3(1.0f, 1.0f, 1.0f);
  46.     light.Power = 100;
  47.     mLight.Update(&light);
  48.  
  49.     // Bind the constant buffers
  50.     Resource::Shader::SetBufferVS(mBuffer, 0);
  51.     Resource::Shader::SetBufferPS(mColors, 0);
  52.     Resource::Shader::SetBufferPS(mLight, 1);
  53.  
  54.     // Render the model
  55.  
  56.     // Get the model header
  57.     auto lookupmodel = resourceManager->Resources.find(mModel.Handle);
  58.     if(lookupmodel == resourceManager->Resources.end()) { Error("buh"); }
  59.     // -- //
  60.     auto model = (Model*)lookupmodel->second;
  61.     // Get the mesh
  62.     auto lookupmesh = resourceManager->Resources.find(model->Presets[mModel.Preset].Meshes[0].Handle); // lol
  63.     if(lookupmesh == resourceManager->Resources.end()) { Error("buh"); }
  64.     // -- //
  65.     auto mesh = (Mesh*)lookupmesh->second;
  66.     // Get the vertex and index buffers
  67.     auto lookupvbuffer = resourceManager->Resources.find(mesh->VertexBufferID.Handle);
  68.     auto lookupibuffer = resourceManager->Resources.find(mesh->IndexBufferID.Handle);
  69.     if(lookupvbuffer == resourceManager->Resources.end()) { Error("buh"); }
  70.     if(lookupibuffer == resourceManager->Resources.end()) { Error("buh"); }
  71.     // -- //
  72.     auto vbuffer = (Buffer*)lookupvbuffer->second;
  73.     auto ibuffer = (Buffer*)lookupibuffer->second;
  74.     // Bind the vbuffer and ibuffer
  75.  
  76.     // Set vertex buffer stride and offset.
  77.     UInt stride = sizeof(Mesh::Vertex); // vbuffer->Size / vbuffer->Groups[0].Count;
  78.     UInt offset = 0;
  79.  
  80.     // Set the vertex buffer to active in the input assembler so it can be rendered
  81.     deviceContext->IASetVertexBuffers(0, 1, &vbuffer->Handle, &stride, &offset);
  82.  
  83.     // Set the index buffer to active in the input assembler so it can be rendered
  84.     deviceContext->IASetIndexBuffer(ibuffer->Handle, DXGI_FORMAT_R16_UINT, 0);
  85.  
  86.     // Set the type of primitive that should be rendered from this vertex buffer, in this case, triangles
  87.     deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
  88.  
  89.     // Render the mesh
  90.     deviceContext->DrawIndexed(ibuffer->Groups[0].Count * 3, 0, 0);
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement