From e3c85324c64c16d8c781d3be010fb202d2b98687 Mon Sep 17 00:00:00 2001 From: elipzer Date: Sun, 14 Oct 2018 15:44:04 -0400 Subject: [PATCH] Changed Filters to be more representitive Also moved all the code for each pipeline into the header files rather than the .cpp files to keep it all in one place. Considering just moving all the code into one file just to make it easier to create new pipelines but that may be overkill and may make the project harder to maintain in the future. --- CharcoalBuiltin/BasicBatch.cpp | 19 -------- CharcoalBuiltin/BasicBatch.h | 9 +++- CharcoalBuiltin/BasicPipeline.cpp | 24 ---------- CharcoalBuiltin/BasicPipeline.h | 16 +++++-- CharcoalBuiltin/BasicScene.cpp | 48 ------------------- CharcoalBuiltin/BasicScene.h | 41 ---------------- CharcoalBuiltin/BuiltinPipeline.h | 30 ++++++++++++ CharcoalBuiltin/CharcoalBuiltin.vcxproj | 5 +- .../CharcoalBuiltin.vcxproj.filters | 37 +++++--------- Example/MyBuiltinCubeScene.cpp | 14 ++---- Example/MyBuiltinCubeScene.h | 2 +- 11 files changed, 69 insertions(+), 176 deletions(-) delete mode 100644 CharcoalBuiltin/BasicBatch.cpp delete mode 100644 CharcoalBuiltin/BasicPipeline.cpp delete mode 100644 CharcoalBuiltin/BasicScene.cpp delete mode 100644 CharcoalBuiltin/BasicScene.h create mode 100644 CharcoalBuiltin/BuiltinPipeline.h diff --git a/CharcoalBuiltin/BasicBatch.cpp b/CharcoalBuiltin/BasicBatch.cpp deleted file mode 100644 index 4d0b059..0000000 --- a/CharcoalBuiltin/BasicBatch.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "BasicBatch.h" - -namespace charcoal -{ - namespace builtin - { - namespace basic - { - void Batch::setup_vao_vertex() - { - glBindBuffer(GL_ARRAY_BUFFER, m_vertex_vbo); - glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), NULL); - - glVertexAttribDivisor(0, 0); - } - } - } -} diff --git a/CharcoalBuiltin/BasicBatch.h b/CharcoalBuiltin/BasicBatch.h index bc9b702..9915ceb 100644 --- a/CharcoalBuiltin/BasicBatch.h +++ b/CharcoalBuiltin/BasicBatch.h @@ -14,7 +14,14 @@ namespace charcoal public: using PoseableBatch::PoseableBatch; protected: - virtual void setup_vao_vertex() override; + void setup_vao_vertex() override + { + glBindBuffer(GL_ARRAY_BUFFER, m_vertex_vbo); + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), NULL); + + glVertexAttribDivisor(0, 0); + } }; } } diff --git a/CharcoalBuiltin/BasicPipeline.cpp b/CharcoalBuiltin/BasicPipeline.cpp deleted file mode 100644 index 9a819c5..0000000 --- a/CharcoalBuiltin/BasicPipeline.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#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 index f78b170..4288171 100644 --- a/CharcoalBuiltin/BasicPipeline.h +++ b/CharcoalBuiltin/BasicPipeline.h @@ -1,6 +1,7 @@ #pragma once -#include +#include "GLUtil.h" +#include "BuiltinPipeline.h" #include "WithCamera.h" #include "BasicShaderProgram.h" #include "BasicBatch.h" @@ -11,10 +12,19 @@ namespace charcoal { namespace basic { - class Pipeline : public charcoal::Pipeline, public WithCamera + class Pipeline : public builtin::Pipeline, public WithCamera { public: - void render() override; + void prepare_opengl() override + { + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); + } + + void prepare_uniforms() override + { + glutil::uniform_matrix(0, get_camera()->get_world_to_view_matrix()); + } }; } } diff --git a/CharcoalBuiltin/BasicScene.cpp b/CharcoalBuiltin/BasicScene.cpp deleted file mode 100644 index 10b8914..0000000 --- a/CharcoalBuiltin/BasicScene.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "BasicScene.h" - -#include -#include - -#include "GLUtil.h" - -namespace charcoal -{ - namespace builtin - { - namespace basic - { - void Scene::init() - { - for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) - { - Batch& batch = *iter; - batch.init(); - add_prerenderable(&batch); - } - } - - void Scene::use() - { - // TODO: move to glutil - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LESS); - } - - void Scene::unuse() - { - - } - - void Scene::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) - { - iter->render(); - } - } - } - } -} \ No newline at end of file diff --git a/CharcoalBuiltin/BasicScene.h b/CharcoalBuiltin/BasicScene.h deleted file mode 100644 index 0977713..0000000 --- a/CharcoalBuiltin/BasicScene.h +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -#include - -#include -#include -#include - -#include "AutoPrerenderingScene.h" - -#include "BasicShaderProgram.h" -#include "BasicTypes.h" -#include "BasicBatch.h" -#include "Batched.h" -#include "WithCamera.h" - -namespace charcoal -{ - namespace builtin - { - namespace basic - { - class Scene : public AutoPrerenderingScene, public Batched, public WithCamera - { - public: - Scene(Application& application) : AutoPrerenderingScene(application) {} - - void init() override; - - void use() override; - - void unuse() override; - - void render() override; - - private: - ShaderProgram m_shader_program; - }; - } - } -} \ No newline at end of file diff --git a/CharcoalBuiltin/BuiltinPipeline.h b/CharcoalBuiltin/BuiltinPipeline.h new file mode 100644 index 0000000..175c1ae --- /dev/null +++ b/CharcoalBuiltin/BuiltinPipeline.h @@ -0,0 +1,30 @@ +#pragma once + +#include + +namespace charcoal +{ + namespace builtin + { + template + class Pipeline : public charcoal::Pipeline + { + public: + void render() override + { + prepare_opengl(); + charcoal::Pipeline::m_shader_program.use(); + prepare_uniforms(); + for (auto iter = charcoal::Pipeline::m_batches.begin(); iter != charcoal::Pipeline::m_batches.end(); ++iter) + { + BatchType* batch = *iter; + batch->render(); + } + } + + virtual void prepare_opengl() {}; + + virtual void prepare_uniforms() {}; + }; + } +} \ No newline at end of file diff --git a/CharcoalBuiltin/CharcoalBuiltin.vcxproj b/CharcoalBuiltin/CharcoalBuiltin.vcxproj index 167f56c..2aa36e8 100644 --- a/CharcoalBuiltin/CharcoalBuiltin.vcxproj +++ b/CharcoalBuiltin/CharcoalBuiltin.vcxproj @@ -140,9 +140,6 @@ copy "$(ProjectDir)*.h" "$(SolutionDir)include\charcoal-builtin\" - - - @@ -150,13 +147,13 @@ copy "$(ProjectDir)*.h" "$(SolutionDir)include\charcoal-builtin\" - + diff --git a/CharcoalBuiltin/CharcoalBuiltin.vcxproj.filters b/CharcoalBuiltin/CharcoalBuiltin.vcxproj.filters index 1c81fbd..a3dc84d 100644 --- a/CharcoalBuiltin/CharcoalBuiltin.vcxproj.filters +++ b/CharcoalBuiltin/CharcoalBuiltin.vcxproj.filters @@ -13,23 +13,17 @@ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - {808e9376-c6b7-4d65-806e-935f34d5ec4a} - - - {1dbc28a4-b52f-4171-a385-79490dfa9b0a} - {5df56e70-8319-4228-b684-c38dd8730bd2} {38a6019a-d441-4f64-a1d3-00b15fce2106} - - {49e6ab0e-f7a1-45ca-812a-44bc15016b45} + + {808e9376-c6b7-4d65-806e-935f34d5ec4a} - - {e167753a-dc8e-4c92-ad62-22b272484656} + + {1dbc28a4-b52f-4171-a385-79490dfa9b0a} @@ -42,25 +36,13 @@ Source Files\General - - Source Files\Scenes\Basic - - - Source Files\Scenes\Basic - - - Source Files\Scenes\Basic - - - Header Files\Scenes\Basic - - Header Files\Scenes\Basic + Header Files\Pipelines\Basic - Header Files\Scenes\Basic + Header Files\Pipelines\Basic Header Files\General @@ -99,10 +81,13 @@ Header Files\General - Header Files\Scenes\Basic + Header Files\Pipelines\Basic - Header Files\Scenes\Basic + Header Files\Pipelines\Basic + + + Header Files\General \ No newline at end of file diff --git a/Example/MyBuiltinCubeScene.cpp b/Example/MyBuiltinCubeScene.cpp index 6e7f793..6b2c258 100644 --- a/Example/MyBuiltinCubeScene.cpp +++ b/Example/MyBuiltinCubeScene.cpp @@ -4,6 +4,8 @@ #include +#include + MyBuiltinCubeScene::MyBuiltinCubeScene(Application& application) : Scene(application), m_shape(meshgenerator::gen_cube_p(DRAW_TRIANGLES, 2.0f, 2.0f, 2.0f), DrawMode::DRAW_TRIANGLES), @@ -19,13 +21,6 @@ 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) { float brightness; @@ -43,10 +38,10 @@ void MyBuiltinCubeScene::update(float delta_time, clock_t clock) radians = (float)TAU * c / intervals; m_pose_a.rotate(glm::normalize(vec3(1.0f, 1.0f, 0.0f)), (float)TAU_1_2 * delta_time); - m_pose_a.update_position(vec3(3 * (float)cos(radians), 0.0f, 0.0f)); + m_pose_a.update_position(vec3(3 * (float)cos(radians), 1.0f, 0.0f)); m_pose_b.rotate(glm::normalize(vec3(1.0f, 1.0f, 0.0f)), (float)TAU_1_2 * delta_time); - m_pose_b.update_position(vec3(-3 * (float)cos(radians), 0.0f, 0.0f)); + m_pose_b.update_position(vec3(-3 * (float)cos(radians), -1.0f, 0.0f)); vec3 camera_translation(0.0f, 0.0f, 0.0f); @@ -77,6 +72,7 @@ void MyBuiltinCubeScene::prerender() void MyBuiltinCubeScene::render() { + glutil::clear_screen(); m_pipeline.render(); } diff --git a/Example/MyBuiltinCubeScene.h b/Example/MyBuiltinCubeScene.h index c3f040b..7a64136 100644 --- a/Example/MyBuiltinCubeScene.h +++ b/Example/MyBuiltinCubeScene.h @@ -15,7 +15,7 @@ public: void init() override; - void use() override; + void use() override {} void unuse() override {}