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

#pragma once
#include "../libs.h"
#include "framebuffer.h"
#include "primitive.h"
#include "shader.h"
#include "camera.h"
#include "../engine/engine.h"
#include "primitives/quad.h"
#include "../util/dynarray.h"
#include "render.h"

#define RENDER_PASSES_MAX 8

typedef struct {
  framebuffer_t frame;
  shader_t *shader;
} renderpass_t;

typedef struct {
  framebuffer_t frame;
  primitive_t quad;

  renderpass_t passes[RENDER_PASSES_MAX];
  int32_t passCount;
  void *user;
} renderlist_t;

typedef void renderitemcallback_t(
  renderlist_t *list, renderpass_t *pass, engine_t *engine, int32_t i
);

typedef struct {
  renderitemcallback_t *onRender;
} renderitem_t;

void renderListInit(renderlist_t *list, int32_t width, int32_t height);
renderpass_t * renderListGetPass(renderlist_t *list, int32_t pass);
int32_t renderPassAdd(renderlist_t *list);
void renderListRenderPass(
  renderlist_t *list, engine_t *engine,
  camera_t *camera, int32_t pass, renderitem_t *items, int32_t itemCount
);

void renderListRender(renderlist_t *list, shader_t *shader);

void renderListAsBackbuffer(
  renderlist_t *list, engine_t *engine, shader_t *shader
);