123 lines
2.9 KiB
C
123 lines
2.9 KiB
C
/**
|
|
* Copyright (c) 2021 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#include "renderlist.h"
|
|
|
|
void renderListInit(renderlist_t *list,int32_t width, int32_t height) {
|
|
frameBufferInit(&list->frame, width, height);
|
|
quadInit(&list->quad, 0, 0,0,0,0, 1,1,1,1);
|
|
list->passCount = 0;
|
|
}
|
|
|
|
renderpass_t * renderListGetPass(renderlist_t *list, uint8_t pass) {
|
|
return list->passes + pass;
|
|
}
|
|
|
|
uint8_t renderPassAdd(renderlist_t *list, shader_t *shader) {
|
|
uint8_t i;
|
|
renderpass_t *pass;
|
|
|
|
i = list->passCount++;
|
|
pass = renderListGetPass(list, i);
|
|
|
|
pass->shader = shader;
|
|
frameBufferInit(&pass->frame,
|
|
list->frame.texture.width, list->frame.texture.height
|
|
);
|
|
|
|
return i;
|
|
}
|
|
|
|
renderpass_t * renderListRenderPass(
|
|
renderlist_t *list, engine_t *engine, uint8_t pass
|
|
) {
|
|
renderpass_t *renderPass;
|
|
|
|
renderPass = renderListGetPass(list, pass);
|
|
|
|
// Bind the shader.
|
|
frameBufferUse(&renderPass->frame, true);
|
|
shaderUse(renderPass->shader);
|
|
|
|
return renderPass;
|
|
}
|
|
|
|
void renderListRender(renderlist_t *list, shader_t *shader) {
|
|
camera_t camera;
|
|
int32_t i;
|
|
renderpass_t *pass;
|
|
|
|
// Setup the camera
|
|
cameraLookAt(&camera, 0,0,1, 0,0,0);
|
|
cameraOrtho(&camera, 0,1, 0,1, 0.5f, 1.5f);
|
|
|
|
// Bind the framebuffer
|
|
frameBufferUse(&list->frame, true);
|
|
|
|
// Set the shader
|
|
shaderUse(shader);
|
|
shaderUseCamera(shader, &camera);
|
|
shaderUsePosition(shader, 0,0,0, 0,0,0);
|
|
|
|
// Render each pass.
|
|
for(i = 0; i < list->passCount; i++) {
|
|
pass = renderListGetPass(list, i);
|
|
shaderUseTexture(shader, &pass->frame.texture);
|
|
primitiveDraw(&list->quad, 0, -1);
|
|
}
|
|
}
|
|
|
|
void renderListAsBackbuffer(
|
|
renderlist_t *list, engine_t *engine, shader_t *shader,
|
|
shaderuniform_t *uniforms
|
|
) {
|
|
camera_t camera;
|
|
|
|
// Reset to backbuffer
|
|
renderResetFramebuffer(&engine->render);
|
|
|
|
// Setup camera to look right at teh quad.
|
|
cameraLookAt(&camera, 0,0,1, 0,0,0);
|
|
cameraOrtho(&camera, 0,1, 0,1, 0.5f, 1.5f);
|
|
|
|
// Set up the shader.
|
|
shaderUse(shader);
|
|
shaderUseCamera(shader, &camera);
|
|
shaderUsePosition(shader, 0,0,0, 0,0,0);
|
|
shaderUseTexture(shader, &list->frame.texture);
|
|
|
|
// Render the quad to the back buffer.
|
|
primitiveDraw(&list->quad, 0, -1);
|
|
}
|
|
|
|
void renderListResize(renderlist_t *list, int32_t width, int32_t height) {
|
|
uint8_t i;
|
|
|
|
if(
|
|
width == list->frame.texture.width &&
|
|
height == list->frame.texture.height
|
|
) return;
|
|
|
|
frameBufferDispose(&list->frame);
|
|
frameBufferInit(&list->frame, width, height);
|
|
|
|
for(i = 0; i < list->passCount; i++) {
|
|
frameBufferDispose(&list->passes[i].frame);
|
|
frameBufferInit(&list->passes[i].frame, width, height);
|
|
}
|
|
}
|
|
|
|
void renderListDispose(renderlist_t *list) {
|
|
uint8_t i;
|
|
|
|
for(i = 0; i < list->passCount; i++) {
|
|
frameBufferDispose(&list->passes[i].frame);
|
|
}
|
|
|
|
frameBufferDispose(&list->frame);
|
|
primitiveDispose(&list->quad);
|
|
} |