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:
parent
bb4592ed63
commit
0c767e9441
24
CharcoalBuiltin/BasicPipeline.cpp
Normal file
24
CharcoalBuiltin/BasicPipeline.cpp
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
21
CharcoalBuiltin/BasicPipeline.h
Normal file
21
CharcoalBuiltin/BasicPipeline.h
Normal 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;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -141,6 +141,7 @@ copy "$(ProjectDir)*.h" "$(SolutionDir)include\charcoal-builtin\"</Command>
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="AutoPrerenderingScene.cpp" />
|
<ClCompile Include="AutoPrerenderingScene.cpp" />
|
||||||
<ClCompile Include="BasicBatch.cpp" />
|
<ClCompile Include="BasicBatch.cpp" />
|
||||||
|
<ClCompile Include="BasicPipeline.cpp" />
|
||||||
<ClCompile Include="BasicScene.cpp" />
|
<ClCompile Include="BasicScene.cpp" />
|
||||||
<ClCompile Include="GLUtil.cpp" />
|
<ClCompile Include="GLUtil.cpp" />
|
||||||
<ClCompile Include="TextureGenerator.cpp" />
|
<ClCompile Include="TextureGenerator.cpp" />
|
||||||
@ -148,6 +149,7 @@ copy "$(ProjectDir)*.h" "$(SolutionDir)include\charcoal-builtin\"</Command>
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="AutoPrerenderingScene.h" />
|
<ClInclude Include="AutoPrerenderingScene.h" />
|
||||||
<ClInclude Include="BasicBatch.h" />
|
<ClInclude Include="BasicBatch.h" />
|
||||||
|
<ClInclude Include="BasicPipeline.h" />
|
||||||
<ClInclude Include="BasicScene.h" />
|
<ClInclude Include="BasicScene.h" />
|
||||||
<ClInclude Include="BasicShaderProgram.h" />
|
<ClInclude Include="BasicShaderProgram.h" />
|
||||||
<ClInclude Include="BasicTypes.h" />
|
<ClInclude Include="BasicTypes.h" />
|
||||||
|
@ -48,6 +48,9 @@
|
|||||||
<ClCompile Include="BasicScene.cpp">
|
<ClCompile Include="BasicScene.cpp">
|
||||||
<Filter>Source Files\Scenes\Basic</Filter>
|
<Filter>Source Files\Scenes\Basic</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="BasicPipeline.cpp">
|
||||||
|
<Filter>Source Files\Scenes\Basic</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="BasicScene.h">
|
<ClInclude Include="BasicScene.h">
|
||||||
@ -98,5 +101,8 @@
|
|||||||
<ClInclude Include="BasicBatch.h">
|
<ClInclude Include="BasicBatch.h">
|
||||||
<Filter>Header Files\Scenes\Basic</Filter>
|
<Filter>Header Files\Scenes\Basic</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="BasicPipeline.h">
|
||||||
|
<Filter>Header Files\Scenes\Basic</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -8,7 +8,7 @@ namespace charcoal
|
|||||||
{
|
{
|
||||||
class WithCamera
|
class WithCamera
|
||||||
{
|
{
|
||||||
protected:
|
public:
|
||||||
void set_camera(Camera* camera) { m_p_camera = camera; }
|
void set_camera(Camera* camera) { m_p_camera = camera; }
|
||||||
|
|
||||||
Camera* get_camera() { return m_p_camera; }
|
Camera* get_camera() { return m_p_camera; }
|
||||||
|
@ -5,13 +5,25 @@
|
|||||||
#include <charcoal-builtin/MeshGenerator.h>
|
#include <charcoal-builtin/MeshGenerator.h>
|
||||||
|
|
||||||
MyBuiltinCubeScene::MyBuiltinCubeScene(Application& application)
|
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_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_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);
|
m_pipeline.add_batch(&m_batch);
|
||||||
set_camera(&m_camera);
|
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)
|
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);
|
m_batch.add_rendered(m_pose_b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MyBuiltinCubeScene::prerender()
|
||||||
|
{
|
||||||
|
m_camera.prerender();
|
||||||
|
m_batch.prerender();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyBuiltinCubeScene::render()
|
||||||
|
{
|
||||||
|
m_pipeline.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -3,20 +3,34 @@
|
|||||||
#include <charcoal/Poseable.h>
|
#include <charcoal/Poseable.h>
|
||||||
#include <charcoal-builtin/BasicScene.h>
|
#include <charcoal-builtin/BasicScene.h>
|
||||||
#include <charcoal-builtin/BuiltinCamera3D.h>
|
#include <charcoal-builtin/BuiltinCamera3D.h>
|
||||||
|
#include <charcoal-builtin/BasicPipeline.h>
|
||||||
|
|
||||||
using namespace charcoal;
|
using namespace charcoal;
|
||||||
using namespace charcoal::builtin;
|
using namespace charcoal::builtin;
|
||||||
|
|
||||||
class MyBuiltinCubeScene : public basic::Scene
|
class MyBuiltinCubeScene : public Scene
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyBuiltinCubeScene(Application& application);
|
MyBuiltinCubeScene(Application& application);
|
||||||
|
|
||||||
|
void init() override;
|
||||||
|
|
||||||
|
void use() override;
|
||||||
|
|
||||||
|
void unuse() override {}
|
||||||
|
|
||||||
void update(float delta_time, clock_t clock) override;
|
void update(float delta_time, clock_t clock) override;
|
||||||
|
|
||||||
|
void prerender() override;
|
||||||
|
|
||||||
|
void render() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
basic::Renderable m_shape;
|
basic::Renderable m_shape;
|
||||||
builtin::Camera3D m_camera;
|
builtin::Camera3D m_camera;
|
||||||
basic::Batch& m_batch;
|
basic::Batch m_batch;
|
||||||
|
|
||||||
|
basic::Pipeline m_pipeline;
|
||||||
|
|
||||||
Poseable m_pose_a;
|
Poseable m_pose_a;
|
||||||
Poseable m_pose_b;
|
Poseable m_pose_b;
|
||||||
|
@ -179,6 +179,7 @@ copy "$(ProjectDir)*.h" "$(SolutionDir)include\charcoal\"</Command>
|
|||||||
<ClInclude Include="FPS.h" />
|
<ClInclude Include="FPS.h" />
|
||||||
<ClInclude Include="ImageLoader.h" />
|
<ClInclude Include="ImageLoader.h" />
|
||||||
<ClInclude Include="lodepng.h" />
|
<ClInclude Include="lodepng.h" />
|
||||||
|
<ClInclude Include="Pipeline.h" />
|
||||||
<ClInclude Include="Sampler.h" />
|
<ClInclude Include="Sampler.h" />
|
||||||
<ClInclude Include="Poseable2D.h" />
|
<ClInclude Include="Poseable2D.h" />
|
||||||
<ClInclude Include="Texture.h" />
|
<ClInclude Include="Texture.h" />
|
||||||
|
@ -185,5 +185,8 @@
|
|||||||
<ClInclude Include="VertexFragmentShaderProgram.h">
|
<ClInclude Include="VertexFragmentShaderProgram.h">
|
||||||
<Filter>Header Files\Types</Filter>
|
<Filter>Header Files\Types</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="Pipeline.h">
|
||||||
|
<Filter>Header Files\Types</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
18
OpenGLEngine/Pipeline.h
Normal file
18
OpenGLEngine/Pipeline.h
Normal 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;
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user