#include "dx_rounded_rect_pipeline.h"

#include "backend/dx/dx_renderer.h"

bool dx_rounded_rect_pipeline::init() {
    rounded_rect_pipeline::init();
    return loader.load("aorii_rounded_rect_vertex_main", "aorii_rounded_rect_pixel_main");
}

void dx_rounded_rect_pipeline::use() {
    loader.use();
}

void dx_rounded_rect_pipeline::draw(uint32_t in_index_count) {
    const auto d3d_context = aorii::get_renderer<dx_renderer>()->get_d3d_context();

    // 设置顶点缓冲区
    constexpr UINT stride = sizeof(aorii_vertex);
    constexpr UINT offset = 0;
    auto* v_buffer = static_cast<ID3D11Buffer*>(vertex_buffer->get_native_handle());
    auto* i_buffer = static_cast<ID3D11Buffer*>(index_buffer->get_native_handle());
    auto* c_buffer = static_cast<ID3D11Buffer*>(param_buffer->get_native_handle());
    d3d_context->IASetVertexBuffers(0, 1, &v_buffer, &stride, &offset);
    d3d_context->IASetIndexBuffer(i_buffer, DXGI_FORMAT_R32_UINT, 0);
    d3d_context->VSSetConstantBuffers(0, 1, &c_buffer);
    d3d_context->PSSetConstantBuffers(0, 1, &c_buffer);

    // 设置图元拓扑
    d3d_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

    // 绘制矩形
    d3d_context->DrawIndexed(in_index_count, 0, 0);
}
