srgb.rasm

includes/learn/srgb.rasm · 27 lines

; srgb: the back buffer seen as sRGB
;
; From 5.3 on the shaders work in linear light and write linear values; an
; _SRGB render target view of the back buffer gamma-encodes them on the way
; in (5.2 gamma correction shows why).
;
;     invoke(window_create, "LearnD3D11")
;     call window_use_srgb              ; backbuffer_rtv is now the sRGB view

import "../calls.rasm"
import "../macros.rasm"
import "window.rasm"

; The view's description is known in full at assembly time, so it is data.
window_srgb_view: D3D11_RENDER_TARGET_VIEW_DESC = {
    .Format = DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
    .ViewDimension = D3D11_RTV_DIMENSION.D3D11_RTV_DIMENSION_TEXTURE2D,
}

window_use_srgb: proc() = {
    sub rsp, 40                            ; 32 shadow, and rsp back on 16
    release(backbuffer_rtv)
    vcall(device, ID3D11DeviceVtbl.CreateRenderTargetView, backbuffer, window_srgb_view&, backbuffer_rtv&)
    assert_hr()
    add rsp, 40
    ret
}
Part of rasm-dx11, LearnOpenGL's lessons rewritten for Direct3D 11 in rasm. Licensed CC BY-NC 4.0, after LearnOpenGL by Joey de Vries.