Lecture 11: Application’s window

Computer graphics in Game development

Ivan Belyavtsev

23.06.2022

Basics of DirectX 12

This part of course is going to be boring. There is plenty of preliminary work. We’ll get a somehow working application on Saturday only.

jump meme

Graphics APIs

  • Vintage:
    • OpenGL
    • DirectX 9
    • DirectX 11
    • Mantle
  • Modern:
    • Metal
    • DirectX 12
    • Vulkan

What our choice is

  • Metal: Apple only
  • Vulkan: open-source, well-documented, overcomplicated
  • DirectX 12: Microsoft, less documentation, simpler

Pre requirements

Plan

  • Learn how to create a window
  • Initialize DX12
  • Create and setup resources
  • Create and setup the rendering pipeline
  • Add per frame updates

Creating the window

  1. Create WNDCLASS or WNDCLASSEX instance
  2. Register the instance with RegisterClass or RegisterClassEx call
  3. Call CreateWindow or CreateWindowEx and keep HWND results
  4. Call ShowWindows to present [1]

Event loop

  1. Take the message via GetMessage or PeekMessage
  2. Run TranslateMessage to make the message readable
  3. Call DispatchMessage to handling (DispatchMessage calls the windows procedure from WNDCLASS) [1]

Lab: 3.01 Review and preparations

  1. Review a code of WinMain procedure and cg::utils::window class
  2. Add model and camera creation code into init method of dx12_renderer class

ComObj

The Microsoft Component Object Model (COM) is a platform-independent, distributed, object-oriented system for creating binary software components that can interact[2].

IUnknown interface

All COM interfaces inherit from the IUnknown interface.

IUnknown interface has the next functions:

  • QueryInterface(REFIID riid, LPVOID *ppv)
  • AddRef()
  • Release() [2]

IID_PPV_ARGS macro

AwesomeFunction(
    ...
    REFIID    riid,
    LPVOID    *ppv
)

Use the IID_PPV_ARGS macro to get both arguments

ComPtr

Microsoft::WRL::ComPtr is a C++ template smart-pointer for COM objects that is used extensively in Windows Runtime (WinRT) C++ programming.

  • include wrl/client.h
  • use namespace Microsoft::WRL::ComPtr
  • use instead of raw Com objects [3]

References

1.
Satran M., Jacobs M. Get started with Win32 and c++ [Electronic resource]. 2018. URL: https://docs.microsoft.com/en-us/windows/win32/learnwin32/learn-to-program-for-windows.
2.
Satran M. The component object model [Electronic resource]. 2018. URL: https://docs.microsoft.com/en-us/windows/win32/com/the-component-object-model.
3.
Walbourn C. ComPtr [Electronic resource]. 2019. URL: https://github.com/Microsoft/DirectXTK/wiki/ComPtr.
// reveal.js plugins