//
//  GameViewController.m
//  KDE
//
//  Created by Ronja Enseleit on 01.07.23.
//

#import "GameViewController.h"
#import "MetalViewDelegate.h"

#include "../cpp/Renderer.h"

@implementation GameViewController
{
    MTKView *_view;

    MetalViewDelegate *_renderer;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    _view = (MTKView *)self.view;
    
    _view.device = MTLCreateSystemDefaultDevice();
    _view.backgroundColor = UIColor.blackColor;
    
    if(!_view.device)
    {
        NSLog(@"Metal is not supported on this device");
        self.view = [[UIView alloc] initWithFrame:self.view.frame];
        return;
    }
    
    _renderer = [[MetalViewDelegate alloc] initWithMetalKitView:_view];
    
    [_renderer mtkView:_view drawableSizeWillChange:_view.bounds.size];
    
    _view.delegate = _renderer;
    
    Renderer::create((__bridge void*)_renderer);
}

@end
