Fixed bugs with render passes.

This commit is contained in:
2021-09-28 10:18:23 -07:00
parent 327db3557e
commit d47a3707ba
6 changed files with 91 additions and 20 deletions

View File

@ -20,7 +20,7 @@ set(SETTING_GAME_POKER 1)
set(SETTING_GAME_DAWN 2)
set(SETTING_GAME_SANDBOX 3)
set(SETTING_GAME SETTING_GAME_POKER)
set(SETTING_GAME SETTING_GAME_DAWN)
set(SETTING_GAME_NAME "DawnGame")
################################## Targets #####################################

View File

@ -7,30 +7,28 @@
#include "renderlist.h"
void renderListInit(renderlist_t *list, int32_t passes, int32_t width, int32_t height) {
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);
dynArrayInit(&list->passes, sizeof(renderpass_t), passes);
list->passCount = 0;
}
renderpass_t * renderListGetPass(renderlist_t *list, int32_t pass) {
return (renderpass_t *)dynArrayGet(&list->passes, pass);
return list->passes + pass;
}
int32_t renderPassAdd(renderlist_t *list) {
int32_t i = dynArrayAdd(&list->passes);
int32_t i = list->passCount++;
renderpass_t *pass = renderListGetPass(list, i);
frameBufferInit(&pass->frame,
list->frame.texture.width, list->frame.texture.height
);
return i;
}
void renderListRenderPass(
renderlist_t *list, engine_t *engine,
camera_t *camera, int32_t pass, dynarray_t *items
camera_t *camera, int32_t pass, renderitem_t *items, int32_t itemCount
) {
int32_t i;
renderpass_t *renderPass;
@ -46,15 +44,13 @@ void renderListRenderPass(
shaderUseCamera(renderPass->shader, camera);
// Render list
for(i = 0; i < items->length; i++) {
item = (renderitem_t *)dynArrayGet(items, i);
for(i = 0; i < itemCount; i++) {
item = items + i;
item->onRender(list, renderPass, engine, i);
}
renderResetFramebuffer(&engine->render);
}
void renderListRender(renderlist_t *list, engine_t *engine, shader_t *shader) {
void renderListRender(renderlist_t *list, shader_t *shader) {
camera_t camera;
int32_t i;
renderpass_t *pass;
@ -64,7 +60,7 @@ void renderListRender(renderlist_t *list, engine_t *engine, shader_t *shader) {
cameraOrtho(&camera, 0,1, 0,1, 0.5f, 1.5f);
// Bind the framebuffer
frameBufferUse(&list->frame, false);
frameBufferUse(&list->frame, true);
// Set the shader
shaderUse(shader);
@ -72,11 +68,31 @@ void renderListRender(renderlist_t *list, engine_t *engine, shader_t *shader) {
shaderUseCamera(shader, &camera);
// Render each pass.
for(i = 0; i < list->passes.length; i++) {
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
) {
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);
shaderUseTexture(shader, &list->frame.texture);
shaderUseCamera(shader, &camera);
shaderUsePosition(shader, 0,0,0, 0,0,0);
// Render the quad to the back buffer.
primitiveDraw(&list->quad, 0, -1);
}

View File

@ -16,6 +16,8 @@
#include "../util/dynarray.h"
#include "render.h"
#define RENDER_PASSES_MAX 8
typedef struct {
framebuffer_t frame;
shader_t *shader;
@ -25,7 +27,8 @@ typedef struct {
framebuffer_t frame;
primitive_t quad;
dynarray_t passes;
renderpass_t passes[RENDER_PASSES_MAX];
int32_t passCount;
void *user;
} renderlist_t;
@ -37,12 +40,16 @@ typedef struct {
renderitemcallback_t *onRender;
} renderitem_t;
void renderListInit(renderlist_t *list, int32_t passes, int32_t width, int32_t height);
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, dynarray_t *items
camera_t *camera, int32_t pass, renderitem_t *items, int32_t itemCount
);
void renderListRender(renderlist_t *list, engine_t *engine, shader_t *shader);
void renderListRender(renderlist_t *list, shader_t *shader);
void renderListAsBackbuffer(
renderlist_t *list, engine_t *engine, shader_t *shader
);

View File

@ -7,12 +7,52 @@
#include "dawngame.h"
shader_t shader;
primitive_t cube;
texture_t texture;
renderitem_t items[32];
int32_t itemCount;
void _renderTest(
renderlist_t *list, renderpass_t *pass, engine_t *engine, int32_t i
) {
shaderUsePosition(pass->shader, 0,0,0, 0,engine->time.current,0);
shaderUseTexture(pass->shader, &texture);
primitiveDraw(&cube, 0, -1);
}
bool dawnGameInit(dawngame_t *game) {
renderListInit(&game->renderList, 512, 512);
assetShaderLoad(&shader, "shaders/textured.vert", "shaders/textured.frag");
assetTextureLoad(&texture, "test_texture.png");
cubeInit(&cube, 1, 1, 1);
items[itemCount++].onRender = &_renderTest;
int32_t passNumber = renderPassAdd(&game->renderList);
renderpass_t *pass = renderListGetPass(&game->renderList, passNumber);
pass->shader = &shader;
return true;
}
void dawnGameUpdate(dawngame_t *game) {
camera_t camera;
cameraPerspective(&camera, 45.0f, 512.0f/512.0f, 0.01f, 100.0f);
cameraLookAt(&camera, 3,3,3, 0,0,0);
// Render First Pass
renderListRenderPass(
&game->renderList, &game->engine, &camera, 0, items, itemCount
);
// Render the list itself.
renderListRender(&game->renderList, &shader);
// Render that to the backbuffer.
renderListAsBackbuffer(&game->renderList, &game->engine, &shader);
}
void dawnGameDispose(dawngame_t *game) {

View File

@ -8,9 +8,17 @@
#pragma once
#include "../../libs.h"
#include "../../engine/engine.h"
#include "../../display/renderlist.h"
#include "../../display/shader.h"
#include "../../display/texture.h"
#include "../../display/primitives/cube.h"
#include "../../display/primitive.h"
#include "../../file/asset.h"
#include "../../util/dynarray.h"
typedef struct {
engine_t engine;
renderlist_t renderList;
} dawngame_t;
/**

View File

@ -84,7 +84,7 @@ void pokerUiUpdate(
// Render the VN character
shaderUseCamera(shader, &camera);
shaderUsePosition(shader, 0,0,0, 0,0,0);
// shaderUsePosition(shader, 0,0,0, 0,0,0);
vnCharacterRender(characters + i, shader);
// Increment