#include "arc/graphics/renderer.h"
#include "renderer.h"

#include <SDL.h>
#include <stdlib.h>
#include "arc/engine/engine.h"
#include "arc/graphics/window.h"
#include "arc/std/errno.h"

void ARC_Renderer_CreateWithEngineData(ARC_Renderer **renderer, ARC_EngineData *data){
    if(!data){
        arc_errno = ARC_ERRNO_NULL;
        ARC_DEBUG_LOG_ERROR("ARC_Renderer_CreateWithEngineData(**renderer, NULL)");
        return;
    }

    *renderer = (ARC_Renderer *)SDL_CreateRenderer((SDL_Window *)(data->window), -1, SDL_RENDERER_ACCELERATED);

    if(!*renderer){
        arc_errno = ARC_ERRNO_NULL;
        ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("SDL_CreateRenderer(%p, %d, %u);", data->window, -1, SDL_RENDERER_ACCELERATED);
        free(renderer);
    }

    SDL_SetRenderDrawBlendMode((SDL_Renderer *)*renderer, SDL_BLENDMODE_BLEND);
}

void ARC_Renderer_Destroy(ARC_Renderer *renderer){
    SDL_DestroyRenderer((SDL_Renderer *) renderer);
}

void ARC_Renderer_Clear(ARC_Renderer *renderer){
    //TODO: changed for school, also need to add the ability to change render draw color
    //SDL_SetRenderDrawColor((SDL_Renderer *)renderer, 0x1c, 0x2c, 0x3c, 0x00);
    SDL_SetRenderDrawColor((SDL_Renderer *)renderer, 0x15, 0x2a, 0x26, 0x00);
    SDL_RenderClear((SDL_Renderer *)renderer);
}

void ARC_Renderer_Render(ARC_Renderer *renderer){
    SDL_RenderPresent((SDL_Renderer *)renderer);
}
