/**
 * Copyright (c) 2025 Dominic Masters
 * 
 * This software is released under the MIT License.
 * https://opensource.org/licenses/MIT
 */

#include "assert/assertgl.h"
#include "util/memory.h"
#include "render.h"
#include "display/scene.h"
#include "display/shader/shadermanager.h"
#include "display/quad.h"
#include "display/window.h"

render_t RENDER;

void renderInit() {
  memoryZero(&RENDER, sizeof(render_t));
  
  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  assertNoGLError();

  shaderManagerInit();
  quadInit();
}

void renderUpdate() {
  glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
  assertNoGLError();
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  assertNoGLError();

  // Update shader stuff
  shaderManagerUpdate();
  
  // Hand off to the scene to do its rendering.
  sceneRender();
}

void renderDispose() {
  quadDispose();
  shaderManagerDispose();
}