From d47a3707baee3286cc379b2fb829e61828020ea0 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Tue, 28 Sep 2021 10:18:23 -0700 Subject: [PATCH] Fixed bugs with render passes. --- CMakeLists.txt | 2 +- src/display/renderlist.c | 44 +++++++++++++++++++++++++++------------- src/display/renderlist.h | 15 ++++++++++---- src/game/dawn/dawngame.c | 40 ++++++++++++++++++++++++++++++++++++ src/game/dawn/dawngame.h | 8 ++++++++ src/game/poker/pokerui.c | 2 +- 6 files changed, 91 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9909e519..47452495 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 ##################################### diff --git a/src/display/renderlist.c b/src/display/renderlist.c index 91417bef..8ccd0a1f 100644 --- a/src/display/renderlist.c +++ b/src/display/renderlist.c @@ -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); } \ No newline at end of file diff --git a/src/display/renderlist.h b/src/display/renderlist.h index 27e10002..ff9506bb 100644 --- a/src/display/renderlist.h +++ b/src/display/renderlist.h @@ -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); \ No newline at end of file +void renderListRender(renderlist_t *list, shader_t *shader); + +void renderListAsBackbuffer( + renderlist_t *list, engine_t *engine, shader_t *shader +); \ No newline at end of file diff --git a/src/game/dawn/dawngame.c b/src/game/dawn/dawngame.c index 3e7585fb..d5fb64d6 100644 --- a/src/game/dawn/dawngame.c +++ b/src/game/dawn/dawngame.c @@ -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) { diff --git a/src/game/dawn/dawngame.h b/src/game/dawn/dawngame.h index 4f8846ae..4975421a 100644 --- a/src/game/dawn/dawngame.h +++ b/src/game/dawn/dawngame.h @@ -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; /** diff --git a/src/game/poker/pokerui.c b/src/game/poker/pokerui.c index 38c3f57d..9ff81430 100644 --- a/src/game/poker/pokerui.c +++ b/src/game/poker/pokerui.c @@ -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