Renderer - SWTube/Darkest-Cave GitHub Wiki

Render Process

Init

  1. Set error callback (UNIX GLFW)
  2. Initialize Dependencies (UNIX GLFW)
  3. Initialize Window
  4. Initialize Device

InitWindow

  1. Register Class (WIN32 WNDCLASSEX)
  2. Create Window
  3. Show Window (WIN32 ShowWindow)
  4. Set Callbacks (UNIX GLFW)
    • Window Size
    • Key
    • Char

InitDevice

  1. Create D3D11 Device and Make Context Current (WIN32 D3D11CreateDevice)
  2. Make Context Current
  3. Initialize Dependencies (UNIX GL3W)
  4. Obtain DXGI factory from device (WIN32 IDXGIFactory*)
  5. Create swap chain (WIN32 DXGI_SWAP_CHAIN_DESC*)
  6. Create Render Target View (WIN32 CreateRenderTargetView)
  7. Create Depth Stencil Texture (WIN32 CreateTexture2D)
  8. Create Depth Stencil View (WIN32 CreateDepthStencilView)
  9. Set Render Targets (WIN32 OMSetRenderTargets)
  10. Setup Viewport (WIN32 RSSetViewport)
  11. Compile Shaders
  12. Define, create, set the input layout (in UNIX, this is done after binding the buffers)
    • WIN32
      • D3D11_INPUT_ELEMENT_DESC
      • CreateInputLayout
      • IASetInputLayout
    • UNIX
      • glVertexAttribPointer
      • glEnableVertexAttribArray
  13. Set up Vertices and Indices
  14. Create Buffer
    • WIN32
      • CreateBuffer
    • UNIX
      • glCreateBuffers / glGenBuffer
  15. Bind / Set Buffers
    • WIN32
      • IASetVertexBuffers
      • IASetIndexBuffer
    • UNIX
      • Bind glBindBuffer
      • Store Buffers (glNamedBufferStorage)
  16. Set primitive topology (WIN32 IASetPrimitiveTopology)
  17. Create constant buffer (WIN32 CreateBuffer)
  18. Load Textures
    • WIN32
      • CreateShaderResourceView
    • UNIX
      • Create Textures (glCreateTextures)
      • Bind Texture (glBindTextureUnit)
      • Get uniform location for Texture (glGetUniformLocation)
      • Set Texture Parameters (glTextureParameter*)
      • Store Texture (glTextureStorage2D)
      • Create Image (1glTextureSubImage2D`)
      • Generate Mipmap (glGenerateTextureMipmap)
      • Get uniform location for Texture and set (glUniform*)
  19. Create sample state (WIN32 CreateSamplerState)
  20. Initialize matrices + inject them to constant buffers
    • WIN32
      • XMMatrixIdentity() etc
  21. Create Vertex Arrays (glCreateVertexArrays)

Render

  1. Calculate transformations (WIN32)
  2. Clear buffer
    • WIN32
      • clear back buffer ClearRenderTargetView
      • clear depth buffer ClearDepthStencilView
    • UNIX
      • glClearBuffer*
  3. Update variables (WIN32 feed the transformed values to the constant buffer)
  4. Set Render Data
    • WIN32
      • *SSetShader
      • *SSetConstantBuffers
      • *SSetShaderResources
      • *SSetSamplers
    • UNIX
      • Bind Texture Unit (UNIX glBindTextureUnit)
      • Bind Vertex Array (UNIX glBindVertexArray)
      • Bind Buffers (UNIX glBindBuffer. bind element array buffer)
  5. Render
    • WIN32
      • Draw / DrawIndexed
    • UNIX
      • glDrawArrays, glDrawElements
  6. Swap buffers
    • WIN32
      • gSwapChain->Present
    • UNIX
      • glfwSwapBuffers

Destroy