Added the base to the lit pipeline.
Still need to allow for adding lights!
This commit is contained in:
parent
04c31686ec
commit
98c6d3868c
@ -156,6 +156,10 @@ copy "$(ProjectDir)*.h" "$(SolutionDir)include\charcoal-builtin\"</Command>
|
||||
<ClInclude Include="BuiltinPipeline.h" />
|
||||
<ClInclude Include="BuiltinTypes.h" />
|
||||
<ClInclude Include="GLUtil.h" />
|
||||
<ClInclude Include="LitBatch.h" />
|
||||
<ClInclude Include="LitPipeline.h" />
|
||||
<ClInclude Include="LitShaderProgram.h" />
|
||||
<ClInclude Include="LitTypes.h" />
|
||||
<ClInclude Include="MeshGenerator.h" />
|
||||
<ClInclude Include="PoseableBatch.h" />
|
||||
<ClInclude Include="SpriteBatch.h" />
|
||||
|
@ -28,6 +28,9 @@
|
||||
<Filter Include="Header Files\Pipelines\Textured">
|
||||
<UniqueIdentifier>{a0a4d461-a490-40ce-bc57-22c47460f60e}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Header Files\Pipelines\Lit">
|
||||
<UniqueIdentifier>{bc6d5912-669e-4e73-8e9e-67e1d4af38be}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="GLUtil.cpp">
|
||||
@ -107,5 +110,17 @@
|
||||
<ClInclude Include="TexturedRenderable.h">
|
||||
<Filter>Header Files\Pipelines\Textured</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="LitBatch.h">
|
||||
<Filter>Header Files\Pipelines\Lit</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="LitTypes.h">
|
||||
<Filter>Header Files\Pipelines\Lit</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="LitShaderProgram.h">
|
||||
<Filter>Header Files\Pipelines\Lit</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="LitPipeline.h">
|
||||
<Filter>Header Files\Pipelines\Lit</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
36
CharcoalBuiltin/LitBatch.h
Normal file
36
CharcoalBuiltin/LitBatch.h
Normal file
@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include "LitTypes.h"
|
||||
#include "PoseableBatch.h"
|
||||
|
||||
namespace charcoal
|
||||
{
|
||||
namespace builtin
|
||||
{
|
||||
namespace lit
|
||||
{
|
||||
class Batch : public PoseableBatch<Vertex, Index, 3>
|
||||
{
|
||||
public:
|
||||
using PoseableBatch<Vertex, Index, 3>::PoseableBatch;
|
||||
protected:
|
||||
void setup_vao_vertex() override
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_vertex_vbo);
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glEnableVertexAttribArray(2);
|
||||
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, position));
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, normal));
|
||||
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, material));
|
||||
|
||||
glVertexAttribDivisor(0, 0);
|
||||
glVertexAttribDivisor(1, 0);
|
||||
glVertexAttribDivisor(2, 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
32
CharcoalBuiltin/LitPipeline.h
Normal file
32
CharcoalBuiltin/LitPipeline.h
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "GLUtil.h"
|
||||
#include "BuiltinPipeline.h"
|
||||
#include "WithCamera.h"
|
||||
#include "LitShaderProgram.h"
|
||||
#include "LitBatch.h"
|
||||
|
||||
namespace charcoal
|
||||
{
|
||||
namespace builtin
|
||||
{
|
||||
namespace lit
|
||||
{
|
||||
// TODO: May want to abstract this into a base pipeline class since this is the same as basic::Pipeline
|
||||
class Pipeline : public builtin::Pipeline<ShaderProgram, Batch>, public WithCamera
|
||||
{
|
||||
public:
|
||||
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());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
18
CharcoalBuiltin/LitShaderProgram.h
Normal file
18
CharcoalBuiltin/LitShaderProgram.h
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <charcoal/VertexFragmentShaderProgram.h>
|
||||
|
||||
namespace charcoal
|
||||
{
|
||||
namespace builtin
|
||||
{
|
||||
namespace lit
|
||||
{
|
||||
class ShaderProgram : public VertexFragmentShaderProgram
|
||||
{
|
||||
public:
|
||||
ShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "LitVS.glsl", SHADER_PATH "LitFS.glsl") {}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
17
CharcoalBuiltin/LitTypes.h
Normal file
17
CharcoalBuiltin/LitTypes.h
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "BuiltinTypes.h"
|
||||
|
||||
|
||||
namespace charcoal
|
||||
{
|
||||
namespace builtin
|
||||
{
|
||||
namespace lit
|
||||
{
|
||||
typedef PNMVertex Vertex;
|
||||
typedef Index Index;
|
||||
typedef RenderableT<Vertex, Index> Renderable;
|
||||
}
|
||||
}
|
||||
}
|
@ -24,6 +24,7 @@
|
||||
<ClCompile Include="MyBasicScene.cpp" />
|
||||
<ClCompile Include="MyBatch.cpp" />
|
||||
<ClCompile Include="MyBuiltinCubeScene.cpp" />
|
||||
<ClCompile Include="MyBuiltinLitScene.cpp" />
|
||||
<ClCompile Include="MyBuiltinTexturedScene.cpp" />
|
||||
<ClCompile Include="MySimple2DScene.cpp" />
|
||||
<ClCompile Include="MySimple3DScene.cpp" />
|
||||
@ -36,6 +37,7 @@
|
||||
<ClInclude Include="MyBatch.h" />
|
||||
<ClInclude Include="MyBuiltinCubeScene.h" />
|
||||
<ClInclude Include="MyBuiltinTexturedScene.h" />
|
||||
<ClInclude Include="MyBuiltinLitScene.h" />
|
||||
<ClInclude Include="MySimple2DScene.h" />
|
||||
<ClInclude Include="MySimple3DScene.h" />
|
||||
<ClInclude Include="MySimpleCubeScene.h" />
|
||||
|
@ -42,6 +42,9 @@
|
||||
<ClCompile Include="MyBuiltinTexturedScene.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MyBuiltinLitScene.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="MyApplication.h">
|
||||
@ -74,5 +77,8 @@
|
||||
<ClInclude Include="MyBuiltinTexturedScene.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MyBuiltinLitScene.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -7,7 +7,8 @@ MyApplication::MyApplication(int width, int height)
|
||||
m_simple_3d_scene(*this),
|
||||
m_simple_cube_scene(*this),
|
||||
m_builtin_basic_cube_scene(*this),
|
||||
m_builtin_textured_scene(*this)
|
||||
m_builtin_textured_scene(*this),
|
||||
m_builtin_lit_scene(*this)
|
||||
{}
|
||||
|
||||
void MyApplication::init()
|
||||
@ -18,6 +19,7 @@ void MyApplication::init()
|
||||
m_simple_cube_scene.init();
|
||||
m_builtin_basic_cube_scene.init();
|
||||
m_builtin_textured_scene.init();
|
||||
m_builtin_lit_scene.init();
|
||||
|
||||
m_p_current_scene = &m_basic_scene;
|
||||
m_p_current_scene->use();
|
||||
@ -49,6 +51,10 @@ void MyApplication::update(float delta_time, clock_t clock)
|
||||
{
|
||||
swap_scene(&m_builtin_textured_scene);
|
||||
}
|
||||
else if (m_glfw_input_manager.is_key_pressed(GLFW_KEY_7))
|
||||
{
|
||||
swap_scene(&m_builtin_lit_scene);
|
||||
}
|
||||
m_p_current_scene->update(delta_time, clock);
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "MySimpleCubeScene.h"
|
||||
#include "MyBuiltinCubeScene.h"
|
||||
#include "MyBuiltinTexturedScene.h"
|
||||
#include "MyBuiltinLitScene.h"
|
||||
|
||||
using namespace charcoal;
|
||||
|
||||
@ -38,5 +39,6 @@ private:
|
||||
MySimpleCubeScene m_simple_cube_scene;
|
||||
MyBuiltinCubeScene m_builtin_basic_cube_scene;
|
||||
MyBuiltinTexturedScene m_builtin_textured_scene;
|
||||
MyBuiltinLitScene m_builtin_lit_scene;
|
||||
};
|
||||
|
||||
|
81
Example/MyBuiltinLitScene.cpp
Normal file
81
Example/MyBuiltinLitScene.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
#include "MyBuiltinLitScene.h"
|
||||
|
||||
#include <charcoal/constants.h>
|
||||
|
||||
#include <charcoal-builtin/MeshGenerator.h>
|
||||
|
||||
#include <charcoal-builtin/GLUtil.h>
|
||||
|
||||
// TODO: Consider just making a template class for testing out stuff like this...
|
||||
// Especially considering that update and render are probably going to be relatively similar almost every time.
|
||||
|
||||
MyBuiltinLitScene::MyBuiltinLitScene(Application& application)
|
||||
: Scene(application),
|
||||
m_shape(meshgenerator::gen_cube_p<lit::Vertex, lit::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(&m_shape, 2)
|
||||
{
|
||||
m_pipeline.add_batch(&m_batch);
|
||||
m_pipeline.set_camera(&m_camera);
|
||||
}
|
||||
|
||||
void MyBuiltinLitScene::init()
|
||||
{
|
||||
m_batch.init();
|
||||
}
|
||||
|
||||
void MyBuiltinLitScene::update(float delta_time, clock_t clock)
|
||||
{
|
||||
float brightness;
|
||||
float radians;
|
||||
|
||||
clock_t c;
|
||||
const clock_t intervals = 512 * CLOCKS_PER_SEC / 100;
|
||||
const clock_t half_interval = 256 * CLOCKS_PER_SEC / 100;
|
||||
c = clock % intervals;
|
||||
if (c < half_interval)
|
||||
brightness = (float)c / half_interval;
|
||||
else
|
||||
brightness = (float)(intervals - c) / half_interval;
|
||||
|
||||
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), 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), -1.0f, 0.0f));
|
||||
|
||||
vec3 camera_translation(0.0f, 0.0f, 0.0f);
|
||||
|
||||
if (m_input_manager.is_key_down(GLFW_KEY_W)) camera_translation.y += 1;
|
||||
if (m_input_manager.is_key_down(GLFW_KEY_S)) camera_translation.y -= 1;
|
||||
if (m_input_manager.is_key_down(GLFW_KEY_A)) camera_translation.x -= 1;
|
||||
if (m_input_manager.is_key_down(GLFW_KEY_D)) camera_translation.x += 1;
|
||||
if (m_input_manager.is_key_down(GLFW_KEY_Q)) camera_translation.z -= 1;
|
||||
if (m_input_manager.is_key_down(GLFW_KEY_E)) camera_translation.z += 1;
|
||||
|
||||
float camera_rotation = 0.0f;
|
||||
if (m_input_manager.is_key_down(GLFW_KEY_Z)) camera_rotation += 1;
|
||||
if (m_input_manager.is_key_down(GLFW_KEY_C)) camera_rotation -= 1;
|
||||
|
||||
m_camera.translate(camera_translation * delta_time);
|
||||
m_camera.rotate(vec3(0.0f, 1.0f, 0.0f), camera_rotation * (float)TAU_1_8 * delta_time);
|
||||
|
||||
m_batch.reset_rendered();
|
||||
m_batch.add_rendered(m_pose_a);
|
||||
m_batch.add_rendered(m_pose_b);
|
||||
}
|
||||
|
||||
void MyBuiltinLitScene::prerender()
|
||||
{
|
||||
m_camera.prerender();
|
||||
m_batch.prerender();
|
||||
}
|
||||
|
||||
void MyBuiltinLitScene::render()
|
||||
{
|
||||
glutil::clear_screen();
|
||||
m_pipeline.render();
|
||||
}
|
||||
|
39
Example/MyBuiltinLitScene.h
Normal file
39
Example/MyBuiltinLitScene.h
Normal file
@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <charcoal/Poseable.h>
|
||||
#include <charcoal/Scene.h>
|
||||
#include <charcoal-builtin/BuiltinCamera3D.h>
|
||||
#include <charcoal-builtin/LitPipeline.h>
|
||||
|
||||
using namespace charcoal;
|
||||
using namespace charcoal::builtin;
|
||||
|
||||
class MyBuiltinLitScene : public Scene
|
||||
{
|
||||
public:
|
||||
// TODO: Add the lights!
|
||||
// This should be done in the pipeline!
|
||||
MyBuiltinLitScene(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:
|
||||
lit::Renderable m_shape;
|
||||
builtin::Camera3D m_camera;
|
||||
lit::Batch m_batch;
|
||||
|
||||
lit::Pipeline m_pipeline;
|
||||
|
||||
Poseable m_pose_a;
|
||||
Poseable m_pose_b;
|
||||
};
|
Loading…
Reference in New Issue
Block a user