From c7cbe4ac21a83513dbcdc8f659cc67b5657ce112 Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Wed, 20 Mar 2019 08:15:54 +0000 Subject: [PATCH] Rendercommand API --- src/modules/RenderCommands.cc | 47 +++++++++++++++++++++++++++++++++++ src/modules/RenderCommands.h | 31 ++++++++++++++++++++++- 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/src/modules/RenderCommands.cc b/src/modules/RenderCommands.cc index 18fdf41..5f9b7c5 100644 --- a/src/modules/RenderCommands.cc +++ b/src/modules/RenderCommands.cc @@ -7,7 +7,41 @@ using namespace std; +const int cNumMaxRenderCommands = 1024; + +RenderCommand sRenderCommands[PassCount][cNumMaxRenderCommands]; +int sRenderCommandCount[PassCount]; + +void RenderCommandReset(RenderCommand *command) { + assert (command != nullptr); + + command->mColor[0] = 0.f; + command->mColor[1] = 0.f; + command->mColor[2] = 0.f; + command->mColor[3] = 0.f; + + for (int i = 0; i < 16; i++) { + command->mTransform[i] = 0.f; + } + for (int i = 0; i < 4; i++) { + command->mTransform[i * 4 + i] = 1.f; + } + + command->mVAId = -1; + command->mVBId = -1; + + command->mAlbedoTexture = -1; + command->mPrimitive = PrimitiveTriangles; +}; + void RenderCommandsClear() { + for (int i = 0; i < PassCount; i++) { + for (int j = 0; j < sRenderCommandCount[i]; j++) { + RenderCommandReset(&sRenderCommands[i][j]); + } + sRenderCommandCount[i] = 0; + } + if (gRenderer == NULL) { gLog ("Warning: Cannot clear render commands: no renderer found!"); return; @@ -15,6 +49,19 @@ void RenderCommandsClear() { gRenderer->mRenderCommands.clear(); } +RenderCommand *GetRenderCommand(RenderPass pass) { + int& pass_count = sRenderCommandCount[pass]; + if (pass_count == cNumMaxRenderCommands) { + gLog ("Error: Reached max number of render commands: %d for pass %d", + cNumMaxRenderCommands, pass); + return nullptr; + } + + pass_count++; + + return &sRenderCommands[pass][pass_count]; +} + void RenderSubmit ( RenderObject object, float* transform, diff --git a/src/modules/RenderCommands.h b/src/modules/RenderCommands.h index 92590a2..394c52f 100644 --- a/src/modules/RenderCommands.h +++ b/src/modules/RenderCommands.h @@ -8,12 +8,41 @@ typedef enum { DebugCube = 1, DebugFrame = 2, DebugSphere = 3, - DebugBone = 4 + DebugBone = 4, + StaticMesh = 5, + Line = 6, + SkinnedMesh = 7 } RenderObject; +typedef enum { + PassDepth = 1, + PassShadowMap = 2, + PassSSAO = 3, + PassLighting = 4, + PassCount +} RenderPass; + +typedef enum { + PrimitivePoints + PrimitiveLines, + PrimitiveTriangles, +} RenderPrimitive; + +typedef struct { + float mColor[4]; + float mTransform[16]; + GLuint mVAId; + GLuint mVBId; + GLuint mAlbedoTexture; + RenderPrimitive mPrimitive; +} RenderCommand; + void RenderCommandsClear (); +RenderCommand *GetRenderCommand(RenderPass pass); + void RenderSubmit ( + RenderPass pass, RenderObject object, float* transform, float color[4]