#include "depthSurface.hpp"
#include "gpuMemory.hpp"
#include <cstring>
#include <netlog.h>

namespace render::kernel
{

DepthSurface::DepthSurface(uint32_t width, uint32_t height)
{
    uint32_t depthWidth = ALIGN(width, SCE_GXM_TILE_SIZEX);
    uint32_t depthHeight = ALIGN(height, SCE_GXM_TILE_SIZEY);

    this->data = gpuAllocator(
        SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW,
        SCE_GXM_MEMORY_ATTRIB_RW,
        4 * depthWidth * depthHeight,
        &this->uid);

    int error = sceGxmDepthStencilSurfaceInit(&this->surface, SCE_GXM_DEPTH_STENCIL_FORMAT_S8D24, SCE_GXM_DEPTH_STENCIL_SURFACE_TILED, depthWidth, this->data, nullptr);
    // netlog("depth %d", error);
}

DepthSurface::~DepthSurface()
{
    // sceGxmDestroyRenderTarget(this->target);
}

SceGxmDepthStencilSurface *DepthSurface::GetSurface()
{
    return &this->surface;
}

void *DepthSurface::GetData()
{
    return this->data;
}

} // namespace render::kernel
