From 0c767e944176fbe855f98d85fd80200da16441b4 Mon Sep 17 00:00:00 2001 From: elipzer Date: Sun, 14 Oct 2018 15:06:51 -0400 Subject: [PATCH] Added Pipelines! Greatly streamline the concept of rendering and abstract rendering so that scenes can render from many different pipelines if they want to!. --- CharcoalBuiltin/BasicPipeline.cpp | 24 ++++++++++++++ CharcoalBuiltin/BasicPipeline.h | 21 +++++++++++++ CharcoalBuiltin/CharcoalBuiltin.vcxproj | 2 ++ .../CharcoalBuiltin.vcxproj.filters | 6 ++++ CharcoalBuiltin/WithCamera.h | 2 +- Example/MyBuiltinCubeScene.cpp | 31 ++++++++++++++++--- Example/MyBuiltinCubeScene.h | 18 +++++++++-- OpenGLEngine/OpenGLEngine.vcxproj | 1 + OpenGLEngine/OpenGLEngine.vcxproj.filters | 3 ++ OpenGLEngine/Pipeline.h | 18 +++++++++++ 10 files changed, 119 insertions(+), 7 deletions(-) create mode 100644 CharcoalBuiltin/BasicPipeline.cpp create mode 100644 CharcoalBuiltin/BasicPipeline.h create mode 100644 OpenGLEngine/Pipeline.h diff --git a/CharcoalBuiltin/BasicPipeline.cpp b/CharcoalBuiltin/BasicPipeline.cpp new file mode 100644 index 0000000..9a819c5 --- /dev/null +++ b/CharcoalBuiltin/BasicPipeline.cpp @@ -0,0 +1,24 @@ +#include "BasicPipeline.h" + +#include "GLUtil.h" + +namespace charcoal +{ + namespace builtin + { + namespace basic + { + void Pipeline::render() + { + glutil::clear_screen(); + m_shader_program.use(); + glutil::uniform_matrix(0, get_camera()->get_world_to_view_matrix()); + for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) + { + Batch* batch = *iter; + batch->render(); + } + } + } + } +} \ No newline at end of file diff --git a/CharcoalBuiltin/BasicPipeline.h b/CharcoalBuiltin/BasicPipeline.h new file mode 100644 index 0000000..f78b170 --- /dev/null +++ b/CharcoalBuiltin/BasicPipeline.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include "WithCamera.h" +#include "BasicShaderProgram.h" +#include "BasicBatch.h" + +namespace charcoal +{ + namespace builtin + { + namespace basic + { + class Pipeline : public charcoal::Pipeline, public WithCamera + { + public: + void render() override; + }; + } + } +} \ No newline at end of file diff --git a/CharcoalBuiltin/CharcoalBuiltin.vcxproj b/CharcoalBuiltin/CharcoalBuiltin.vcxproj index cac8d28..167f56c 100644 --- a/CharcoalBuiltin/CharcoalBuiltin.vcxproj +++ b/CharcoalBuiltin/CharcoalBuiltin.vcxproj @@ -141,6 +141,7 @@ copy "$(ProjectDir)*.h" "$(SolutionDir)include\charcoal-builtin\" + @@ -148,6 +149,7 @@ copy "$(ProjectDir)*.h" "$(SolutionDir)include\charcoal-builtin\" + diff --git a/CharcoalBuiltin/CharcoalBuiltin.vcxproj.filters b/CharcoalBuiltin/CharcoalBuiltin.vcxproj.filters index b64462e..1c81fbd 100644 --- a/CharcoalBuiltin/CharcoalBuiltin.vcxproj.filters +++ b/CharcoalBuiltin/CharcoalBuiltin.vcxproj.filters @@ -48,6 +48,9 @@ Source Files\Scenes\Basic + + Source Files\Scenes\Basic + @@ -98,5 +101,8 @@ Header Files\Scenes\Basic + + Header Files\Scenes\Basic + \ No newline at end of file diff --git a/CharcoalBuiltin/WithCamera.h b/CharcoalBuiltin/WithCamera.h index 11e5e3d..e578df6 100644 --- a/CharcoalBuiltin/WithCamera.h +++ b/CharcoalBuiltin/WithCamera.h @@ -8,7 +8,7 @@ namespace charcoal { class WithCamera { - protected: + public: void set_camera(Camera* camera) { m_p_camera = camera; } Camera* get_camera() { return m_p_camera; } diff --git a/Example/MyBuiltinCubeScene.cpp b/Example/MyBuiltinCubeScene.cpp index 9f77ae7..6e7f793 100644 --- a/Example/MyBuiltinCubeScene.cpp +++ b/Example/MyBuiltinCubeScene.cpp @@ -5,13 +5,25 @@ #include MyBuiltinCubeScene::MyBuiltinCubeScene(Application& application) - : basic::Scene(application), + : Scene(application), m_shape(meshgenerator::gen_cube_p(DRAW_TRIANGLES, 2.0f, 2.0f, 2.0f), DrawMode::DRAW_TRIANGLES), m_camera((float)TAU_1_4, (float)m_screen_size.x / m_screen_size.y, 1.0f, 10.0f, vec3(0.0f, 0.0f, -5.0f)), - m_batch(add_batch(&m_shape, 2)) + m_batch(&m_shape, 2) { - add_prerenderable(&m_camera); - set_camera(&m_camera); + m_pipeline.add_batch(&m_batch); + m_pipeline.set_camera(&m_camera); +} + +void MyBuiltinCubeScene::init() +{ + m_batch.init(); +} + +void MyBuiltinCubeScene::use() +{ + // TODO: Pipeline these + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); } void MyBuiltinCubeScene::update(float delta_time, clock_t clock) @@ -57,3 +69,14 @@ void MyBuiltinCubeScene::update(float delta_time, clock_t clock) m_batch.add_rendered(m_pose_b); } +void MyBuiltinCubeScene::prerender() +{ + m_camera.prerender(); + m_batch.prerender(); +} + +void MyBuiltinCubeScene::render() +{ + m_pipeline.render(); +} + diff --git a/Example/MyBuiltinCubeScene.h b/Example/MyBuiltinCubeScene.h index 9acaaa1..c3f040b 100644 --- a/Example/MyBuiltinCubeScene.h +++ b/Example/MyBuiltinCubeScene.h @@ -3,20 +3,34 @@ #include #include #include +#include using namespace charcoal; using namespace charcoal::builtin; -class MyBuiltinCubeScene : public basic::Scene +class MyBuiltinCubeScene : public Scene { public: MyBuiltinCubeScene(Application& application); + void init() override; + + void use() override; + + void unuse() override {} + void update(float delta_time, clock_t clock) override; + + void prerender() override; + + void render() override; + private: basic::Renderable m_shape; builtin::Camera3D m_camera; - basic::Batch& m_batch; + basic::Batch m_batch; + + basic::Pipeline m_pipeline; Poseable m_pose_a; Poseable m_pose_b; diff --git a/OpenGLEngine/OpenGLEngine.vcxproj b/OpenGLEngine/OpenGLEngine.vcxproj index 6646e23..736f2fa 100644 --- a/OpenGLEngine/OpenGLEngine.vcxproj +++ b/OpenGLEngine/OpenGLEngine.vcxproj @@ -179,6 +179,7 @@ copy "$(ProjectDir)*.h" "$(SolutionDir)include\charcoal\" + diff --git a/OpenGLEngine/OpenGLEngine.vcxproj.filters b/OpenGLEngine/OpenGLEngine.vcxproj.filters index 4c38d2c..1fee18f 100644 --- a/OpenGLEngine/OpenGLEngine.vcxproj.filters +++ b/OpenGLEngine/OpenGLEngine.vcxproj.filters @@ -185,5 +185,8 @@ Header Files\Types + + Header Files\Types + \ No newline at end of file diff --git a/OpenGLEngine/Pipeline.h b/OpenGLEngine/Pipeline.h new file mode 100644 index 0000000..7296a05 --- /dev/null +++ b/OpenGLEngine/Pipeline.h @@ -0,0 +1,18 @@ +#pragma once + +#include + +namespace charcoal +{ + template + class Pipeline + { + public: + void add_batch(BatchType* batch) { m_batches.emplace_back(batch); } + + virtual void render() = 0; + protected: + ShaderProgramType m_shader_program; + std::vector m_batches; + }; +} \ No newline at end of file