Added Pipelines!

Greatly streamline the concept of rendering and abstract rendering
so that scenes can render from many different pipelines if they
want to!.
This commit is contained in:
elipzer 2018-10-14 15:06:51 -04:00
parent bb4592ed63
commit 0c767e9441
10 changed files with 119 additions and 7 deletions

View File

@ -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();
}
}
}
}
}

View File

@ -0,0 +1,21 @@
#pragma once
#include <charcoal/Pipeline.h>
#include "WithCamera.h"
#include "BasicShaderProgram.h"
#include "BasicBatch.h"
namespace charcoal
{
namespace builtin
{
namespace basic
{
class Pipeline : public charcoal::Pipeline<ShaderProgram, Batch>, public WithCamera
{
public:
void render() override;
};
}
}
}

View File

@ -141,6 +141,7 @@ copy "$(ProjectDir)*.h" "$(SolutionDir)include\charcoal-builtin\"</Command>
<ItemGroup>
<ClCompile Include="AutoPrerenderingScene.cpp" />
<ClCompile Include="BasicBatch.cpp" />
<ClCompile Include="BasicPipeline.cpp" />
<ClCompile Include="BasicScene.cpp" />
<ClCompile Include="GLUtil.cpp" />
<ClCompile Include="TextureGenerator.cpp" />
@ -148,6 +149,7 @@ copy "$(ProjectDir)*.h" "$(SolutionDir)include\charcoal-builtin\"</Command>
<ItemGroup>
<ClInclude Include="AutoPrerenderingScene.h" />
<ClInclude Include="BasicBatch.h" />
<ClInclude Include="BasicPipeline.h" />
<ClInclude Include="BasicScene.h" />
<ClInclude Include="BasicShaderProgram.h" />
<ClInclude Include="BasicTypes.h" />

View File

@ -48,6 +48,9 @@
<ClCompile Include="BasicScene.cpp">
<Filter>Source Files\Scenes\Basic</Filter>
</ClCompile>
<ClCompile Include="BasicPipeline.cpp">
<Filter>Source Files\Scenes\Basic</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="BasicScene.h">
@ -98,5 +101,8 @@
<ClInclude Include="BasicBatch.h">
<Filter>Header Files\Scenes\Basic</Filter>
</ClInclude>
<ClInclude Include="BasicPipeline.h">
<Filter>Header Files\Scenes\Basic</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -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; }

View File

@ -5,13 +5,25 @@
#include <charcoal-builtin/MeshGenerator.h>
MyBuiltinCubeScene::MyBuiltinCubeScene(Application& application)
: basic::Scene(application),
: Scene(application),
m_shape(meshgenerator::gen_cube_p<basic::Vertex, basic::Index>(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();
}

View File

@ -3,20 +3,34 @@
#include <charcoal/Poseable.h>
#include <charcoal-builtin/BasicScene.h>
#include <charcoal-builtin/BuiltinCamera3D.h>
#include <charcoal-builtin/BasicPipeline.h>
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;

View File

@ -179,6 +179,7 @@ copy "$(ProjectDir)*.h" "$(SolutionDir)include\charcoal\"</Command>
<ClInclude Include="FPS.h" />
<ClInclude Include="ImageLoader.h" />
<ClInclude Include="lodepng.h" />
<ClInclude Include="Pipeline.h" />
<ClInclude Include="Sampler.h" />
<ClInclude Include="Poseable2D.h" />
<ClInclude Include="Texture.h" />

View File

@ -185,5 +185,8 @@
<ClInclude Include="VertexFragmentShaderProgram.h">
<Filter>Header Files\Types</Filter>
</ClInclude>
<ClInclude Include="Pipeline.h">
<Filter>Header Files\Types</Filter>
</ClInclude>
</ItemGroup>
</Project>

18
OpenGLEngine/Pipeline.h Normal file
View File

@ -0,0 +1,18 @@
#pragma once
#include <vector>
namespace charcoal
{
template <typename ShaderProgramType, typename BatchType>
class Pipeline
{
public:
void add_batch(BatchType* batch) { m_batches.emplace_back(batch); }
virtual void render() = 0;
protected:
ShaderProgramType m_shader_program;
std::vector<BatchType*> m_batches;
};
}