Got the batch rendering to be similar to where I want it.

Changing the mechanic of the renderer to support pipelines.
One scene could have multiple pipelines. The pipelines allow for
one shader, one camera, and multiple batches.
This commit is contained in:
elipzer 2018-10-14 00:52:32 -04:00
parent 2f6c5ee319
commit bb4592ed63
55 changed files with 65 additions and 1658 deletions

View File

@ -6,26 +6,13 @@ namespace charcoal
{ {
namespace basic namespace basic
{ {
void Batch::setup_vao() void Batch::setup_vao_vertex()
{ {
glBindBuffer(GL_ARRAY_BUFFER, m_vertex_vbo); glBindBuffer(GL_ARRAY_BUFFER, m_vertex_vbo);
glEnableVertexAttribArray(0); glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), NULL); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), NULL);
glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[0]);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glEnableVertexAttribArray(3);
glEnableVertexAttribArray(4);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(0 * sizeof(vec4)));
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(1 * sizeof(vec4)));
glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(2 * sizeof(vec4)));
glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(3 * sizeof(vec4)));
glVertexAttribDivisor(0, 0); // Send the mesh data once glVertexAttribDivisor(0, 0);
glVertexAttribDivisor(1, 1); // Send the offset data for each instance drawn
glVertexAttribDivisor(2, 1); // Send the offset data for each instance drawn
glVertexAttribDivisor(3, 1); // Send the offset data for each instance drawn
glVertexAttribDivisor(4, 1); // Send the offset data for each instance drawn
} }
} }
} }

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "PoseableBatch.h"
#include "BasicTypes.h" #include "BasicTypes.h"
#include "PoseableBatch.h"
namespace charcoal namespace charcoal
{ {
@ -9,13 +9,12 @@ namespace charcoal
{ {
namespace basic namespace basic
{ {
class Batch : public PoseableBatch<Vertex, Index, Renderable> class Batch : public PoseableBatch<Vertex, Index, 1>
{ {
public: public:
using PoseableBatch<Vertex, Index, Renderable>::PoseableBatch; using PoseableBatch<Vertex, Index, 1>::PoseableBatch;
protected: protected:
void setup_vao() override; virtual void setup_vao_vertex() override;
}; };
} }
} }

View File

@ -37,7 +37,7 @@ namespace charcoal
{ {
glutil::clear_screen(); glutil::clear_screen();
m_shader_program.use(); m_shader_program.use();
glutil::uniform_matrix(0, m_p_camera->get_world_to_view_matrix()); glutil::uniform_matrix(0, get_camera()->get_world_to_view_matrix());
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
{ {
iter->render(); iter->render();

View File

@ -10,8 +10,9 @@
#include "BasicShaderProgram.h" #include "BasicShaderProgram.h"
#include "BasicTypes.h" #include "BasicTypes.h"
#include "Batched.h"
#include "BasicBatch.h" #include "BasicBatch.h"
#include "Batched.h"
#include "WithCamera.h"
namespace charcoal namespace charcoal
{ {
@ -19,7 +20,7 @@ namespace charcoal
{ {
namespace basic namespace basic
{ {
class Scene : public AutoPrerenderingScene, public Batched<Renderable, Batch> class Scene : public AutoPrerenderingScene, public Batched<Renderable, Batch>, public WithCamera
{ {
public: public:
Scene(Application& application) : AutoPrerenderingScene(application) {} Scene(Application& application) : AutoPrerenderingScene(application) {}
@ -32,12 +33,8 @@ namespace charcoal
void render() override; void render() override;
protected:
void set_camera(const Camera* p_camera) { m_p_camera = p_camera; }
private: private:
ShaderProgram m_shader_program; ShaderProgram m_shader_program;
const Camera* m_p_camera = nullptr;
}; };
} }
} }

View File

@ -2,6 +2,7 @@
#include "BuiltinTypes.h" #include "BuiltinTypes.h"
namespace charcoal namespace charcoal
{ {
namespace builtin namespace builtin

View File

@ -143,15 +143,6 @@ copy "$(ProjectDir)*.h" "$(SolutionDir)include\charcoal-builtin\"</Command>
<ClCompile Include="BasicBatch.cpp" /> <ClCompile Include="BasicBatch.cpp" />
<ClCompile Include="BasicScene.cpp" /> <ClCompile Include="BasicScene.cpp" />
<ClCompile Include="GLUtil.cpp" /> <ClCompile Include="GLUtil.cpp" />
<ClCompile Include="ImageScene.cpp" />
<ClCompile Include="LitBatch.cpp" />
<ClCompile Include="LitScene.cpp" />
<ClCompile Include="LitShadowedBatch.cpp" />
<ClCompile Include="LitShadowedScene.cpp" />
<ClCompile Include="SpecifiedBatch.cpp" />
<ClCompile Include="SpecifiedScene.cpp" />
<ClCompile Include="TexturedBatch.cpp" />
<ClCompile Include="TexturedScene.cpp" />
<ClCompile Include="TextureGenerator.cpp" /> <ClCompile Include="TextureGenerator.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -166,30 +157,9 @@ copy "$(ProjectDir)*.h" "$(SolutionDir)include\charcoal-builtin\"</Command>
<ClInclude Include="BuiltinCamera3D.h" /> <ClInclude Include="BuiltinCamera3D.h" />
<ClInclude Include="BuiltinTypes.h" /> <ClInclude Include="BuiltinTypes.h" />
<ClInclude Include="GLUtil.h" /> <ClInclude Include="GLUtil.h" />
<ClInclude Include="ImageScene.h" />
<ClInclude Include="ImageShaderProgram.h" />
<ClInclude Include="ImageTypes.h" />
<ClInclude Include="LitBatch.h" />
<ClInclude Include="LitScene.h" />
<ClInclude Include="LitShaderProgram.h" />
<ClInclude Include="LitShadowedBatch.h" />
<ClInclude Include="LitShadowedScene.h" />
<ClInclude Include="LitShadowedShaderProgram.h" />
<ClInclude Include="LitShadowedTypes.h" />
<ClInclude Include="LitTypes.h" />
<ClInclude Include="MeshGenerator.h" /> <ClInclude Include="MeshGenerator.h" />
<ClInclude Include="Poseable2DBatch.h" />
<ClInclude Include="PoseableBatch.h" /> <ClInclude Include="PoseableBatch.h" />
<ClInclude Include="SpecifiedBatch.h" />
<ClInclude Include="SpecifiedPoseable.h" />
<ClInclude Include="SpecifiedPoseableBatch.h" />
<ClInclude Include="SpecifiedScene.h" />
<ClInclude Include="SpecifiedTypes.h" />
<ClInclude Include="SpriteBatch.h" /> <ClInclude Include="SpriteBatch.h" />
<ClInclude Include="TexturedBatch.h" />
<ClInclude Include="TexturedScene.h" />
<ClInclude Include="TexturedShaderProgram.h" />
<ClInclude Include="TexturedTypes.h" />
<ClInclude Include="TextureGenerator.h" /> <ClInclude Include="TextureGenerator.h" />
<ClInclude Include="WithCamera.h" /> <ClInclude Include="WithCamera.h" />
</ItemGroup> </ItemGroup>

View File

@ -19,18 +19,6 @@
<Filter Include="Header Files\Scenes\Basic"> <Filter Include="Header Files\Scenes\Basic">
<UniqueIdentifier>{1dbc28a4-b52f-4171-a385-79490dfa9b0a}</UniqueIdentifier> <UniqueIdentifier>{1dbc28a4-b52f-4171-a385-79490dfa9b0a}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="Header Files\Scenes\Image">
<UniqueIdentifier>{4a034e10-73da-44fe-8308-b6a63b41c920}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Scenes\Lit">
<UniqueIdentifier>{b2538cf1-c4a2-40b6-9cef-8a937208aaf2}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Scenes\LitShadowed">
<UniqueIdentifier>{f255fa90-53ea-4a64-9d44-ca9d9013bc3f}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Scenes\Textured">
<UniqueIdentifier>{2c58c0aa-d1ef-4d03-825c-0b8a08672e78}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\General"> <Filter Include="Header Files\General">
<UniqueIdentifier>{5df56e70-8319-4228-b684-c38dd8730bd2}</UniqueIdentifier> <UniqueIdentifier>{5df56e70-8319-4228-b684-c38dd8730bd2}</UniqueIdentifier>
</Filter> </Filter>
@ -43,24 +31,6 @@
<Filter Include="Source Files\Scenes\Basic"> <Filter Include="Source Files\Scenes\Basic">
<UniqueIdentifier>{e167753a-dc8e-4c92-ad62-22b272484656}</UniqueIdentifier> <UniqueIdentifier>{e167753a-dc8e-4c92-ad62-22b272484656}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="Source Files\Scenes\Image">
<UniqueIdentifier>{2823fbc0-59e9-4b79-a7a5-15fd5de29516}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Scenes\Lit">
<UniqueIdentifier>{f3e1fe4f-dd8b-44ff-b427-379d34eb5b02}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Scenes\LitShadowed">
<UniqueIdentifier>{f6f4656e-2a26-4232-b147-a83a2a766e6a}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Scenes\Textured">
<UniqueIdentifier>{5f931ae6-23b1-43df-a4d8-e7f134d755c8}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Scenes\Specified">
<UniqueIdentifier>{d1604903-a209-427a-a879-3278b9fe8088}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Scenes\Specified">
<UniqueIdentifier>{eecad623-46fa-4c24-b93d-c8d77002608e}</UniqueIdentifier>
</Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="GLUtil.cpp"> <ClCompile Include="GLUtil.cpp">
@ -78,62 +48,8 @@
<ClCompile Include="BasicScene.cpp"> <ClCompile Include="BasicScene.cpp">
<Filter>Source Files\Scenes\Basic</Filter> <Filter>Source Files\Scenes\Basic</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="ImageScene.cpp">
<Filter>Source Files\Scenes\Image</Filter>
</ClCompile>
<ClCompile Include="LitBatch.cpp">
<Filter>Source Files\Scenes\Lit</Filter>
</ClCompile>
<ClCompile Include="LitScene.cpp">
<Filter>Source Files\Scenes\Lit</Filter>
</ClCompile>
<ClCompile Include="LitShadowedBatch.cpp">
<Filter>Source Files\Scenes\LitShadowed</Filter>
</ClCompile>
<ClCompile Include="LitShadowedScene.cpp">
<Filter>Source Files\Scenes\LitShadowed</Filter>
</ClCompile>
<ClCompile Include="TexturedBatch.cpp">
<Filter>Source Files\Scenes\Textured</Filter>
</ClCompile>
<ClCompile Include="TexturedScene.cpp">
<Filter>Source Files\Scenes\Textured</Filter>
</ClCompile>
<ClCompile Include="SpecifiedBatch.cpp">
<Filter>Source Files\Scenes\Specified</Filter>
</ClCompile>
<ClCompile Include="SpecifiedScene.cpp">
<Filter>Source Files\Scenes\Specified</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="TexturedBatch.h">
<Filter>Header Files\Scenes\Textured</Filter>
</ClInclude>
<ClInclude Include="TexturedScene.h">
<Filter>Header Files\Scenes\Textured</Filter>
</ClInclude>
<ClInclude Include="TexturedShaderProgram.h">
<Filter>Header Files\Scenes\Textured</Filter>
</ClInclude>
<ClInclude Include="TexturedTypes.h">
<Filter>Header Files\Scenes\Textured</Filter>
</ClInclude>
<ClInclude Include="LitShadowedBatch.h">
<Filter>Header Files\Scenes\LitShadowed</Filter>
</ClInclude>
<ClInclude Include="LitShadowedScene.h">
<Filter>Header Files\Scenes\LitShadowed</Filter>
</ClInclude>
<ClInclude Include="LitShadowedShaderProgram.h">
<Filter>Header Files\Scenes\LitShadowed</Filter>
</ClInclude>
<ClInclude Include="LitShadowedTypes.h">
<Filter>Header Files\Scenes\LitShadowed</Filter>
</ClInclude>
<ClInclude Include="BasicBatch.h">
<Filter>Header Files\Scenes\Basic</Filter>
</ClInclude>
<ClInclude Include="BasicScene.h"> <ClInclude Include="BasicScene.h">
<Filter>Header Files\Scenes\Basic</Filter> <Filter>Header Files\Scenes\Basic</Filter>
</ClInclude> </ClInclude>
@ -143,24 +59,6 @@
<ClInclude Include="BasicTypes.h"> <ClInclude Include="BasicTypes.h">
<Filter>Header Files\Scenes\Basic</Filter> <Filter>Header Files\Scenes\Basic</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="ImageScene.h">
<Filter>Header Files\Scenes\Image</Filter>
</ClInclude>
<ClInclude Include="ImageShaderProgram.h">
<Filter>Header Files\Scenes\Image</Filter>
</ClInclude>
<ClInclude Include="ImageTypes.h">
<Filter>Header Files\Scenes\Image</Filter>
</ClInclude>
<ClInclude Include="LitBatch.h">
<Filter>Header Files\Scenes\Lit</Filter>
</ClInclude>
<ClInclude Include="LitScene.h">
<Filter>Header Files\Scenes\Lit</Filter>
</ClInclude>
<ClInclude Include="LitTypes.h">
<Filter>Header Files\Scenes\Lit</Filter>
</ClInclude>
<ClInclude Include="AutoPrerenderingScene.h"> <ClInclude Include="AutoPrerenderingScene.h">
<Filter>Header Files\General</Filter> <Filter>Header Files\General</Filter>
</ClInclude> </ClInclude>
@ -185,9 +83,6 @@
<ClInclude Include="MeshGenerator.h"> <ClInclude Include="MeshGenerator.h">
<Filter>Header Files\General</Filter> <Filter>Header Files\General</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Poseable2DBatch.h">
<Filter>Header Files\General</Filter>
</ClInclude>
<ClInclude Include="PoseableBatch.h"> <ClInclude Include="PoseableBatch.h">
<Filter>Header Files\General</Filter> <Filter>Header Files\General</Filter>
</ClInclude> </ClInclude>
@ -200,23 +95,8 @@
<ClInclude Include="WithCamera.h"> <ClInclude Include="WithCamera.h">
<Filter>Header Files\General</Filter> <Filter>Header Files\General</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="LitShaderProgram.h"> <ClInclude Include="BasicBatch.h">
<Filter>Header Files\Scenes\Lit</Filter> <Filter>Header Files\Scenes\Basic</Filter>
</ClInclude>
<ClInclude Include="SpecifiedPoseableBatch.h">
<Filter>Header Files\General</Filter>
</ClInclude>
<ClInclude Include="SpecifiedPoseable.h">
<Filter>Header Files\General</Filter>
</ClInclude>
<ClInclude Include="SpecifiedBatch.h">
<Filter>Header Files\Scenes\Specified</Filter>
</ClInclude>
<ClInclude Include="SpecifiedScene.h">
<Filter>Header Files\Scenes\Specified</Filter>
</ClInclude>
<ClInclude Include="SpecifiedTypes.h">
<Filter>Header Files\Scenes\Specified</Filter>
</ClInclude> </ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -1,49 +0,0 @@
#include "ImageScene.h"
#include <charcoal/deps.h>
#include <charcoal/MeshFactory.h>
#include "GLUtil.h"
namespace charcoal
{
namespace builtin
{
namespace image
{
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());
glutil::uniform_int(4, 0); // The textured batch uses GL_TEXTURE0
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
{
iter->render();
}
}
}
}
}

View File

@ -1,35 +0,0 @@
#pragma once
#include "AutoPrerenderingScene.h"
#include "WithCamera.h"
#include "Batched.h"
#include "SpriteBatch.h"
#include "ImageShaderProgram.h"
#include "ImageTypes.h"
namespace charcoal
{
namespace builtin
{
namespace image
{
class Scene : public AutoPrerenderingScene, public WithCamera, public Batched<Renderable, Batch>
{
public:
Scene(Application& application) : AutoPrerenderingScene(application) {}
void init() override;
void use() override;
void unuse() override;
void render() override;
private:
ShaderProgram m_shader_program;
};
}
}
}

View File

@ -1,18 +0,0 @@
#pragma once
#include <charcoal/VertexFragmentShaderProgram.h>
namespace charcoal
{
namespace builtin
{
namespace image
{
class ShaderProgram : public VertexFragmentShaderProgram
{
public:
ShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "ImageVS.glsl", SHADER_PATH "ImageFS.glsl") {}
};
}
}
}

View File

@ -1,19 +0,0 @@
#pragma once
#include "BuiltinTypes.h"
#include "SpriteBatch.h"
namespace charcoal
{
namespace builtin
{
namespace image
{
typedef PTVertex Vertex;
typedef Index Index;
typedef TextureRenderable<Vertex, Index> Renderable;
typedef SpriteBatch<Vertex, Index, offsetof(Vertex, position), offsetof(Vertex, uv)> Batch;
}
}
}

View File

@ -1,38 +0,0 @@
#include "LitBatch.h"
namespace charcoal
{
namespace builtin
{
namespace lit
{
void Batch::setup_vao()
{
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)));
glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[0]);
glEnableVertexAttribArray(3);
glEnableVertexAttribArray(4);
glEnableVertexAttribArray(5);
glEnableVertexAttribArray(6);
glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(0 * sizeof(vec4)));
glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(1 * sizeof(vec4)));
glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(2 * sizeof(vec4)));
glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(3 * sizeof(vec4)));
glVertexAttribDivisor(0, 0); // Send the mesh data once
glVertexAttribDivisor(1, 0); // Send the mesh data once
glVertexAttribDivisor(2, 0); // Send the mesh data once
glVertexAttribDivisor(3, 1); // Send the offset data for each instance drawn
glVertexAttribDivisor(4, 1); // Send the offset data for each instance drawn
glVertexAttribDivisor(5, 1); // Send the offset data for each instance drawn
glVertexAttribDivisor(6, 1); // Send the offset data for each instance drawn
}
}
}
}

View File

@ -1,22 +0,0 @@
#pragma once
#include "PoseableBatch.h"
#include "LitTypes.h"
namespace charcoal
{
namespace builtin
{
namespace lit
{
class Batch : public PoseableBatch<Vertex, Index, Renderable>
{
public:
using PoseableBatch<Vertex, Index, Renderable>::PoseableBatch;
protected:
void setup_vao() override;
};
}
}
}

View File

@ -1,52 +0,0 @@
#include "LitScene.h"
#include <charcoal/deps.h>
#include <charcoal/Util.h>
#include <charcoal/MeshFactory.h>
#include "GLUtil.h"
namespace charcoal
{
namespace builtin
{
namespace lit
{
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, m_p_camera->get_world_to_view_matrix());
glutil::uniform_vec3(4, m_p_camera->get_position());
glutil::uniform_uint(5, (unsigned int)m_lights.size());
glutil::uniform_lights(6, m_lights);
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
{
iter->render();
}
}
}
}
}

View File

@ -1,56 +0,0 @@
#pragma once
#include <vector>
#include <charcoal/Camera.h>
#include "AutoPrerenderingScene.h"
#include "LitTypes.h"
#include "Batched.h"
#include "LitBatch.h"
#include "LitShaderProgram.h"
namespace charcoal
{
namespace builtin
{
namespace lit
{
// A scene lit by the Phong Reflection Model (See https://en.wikipedia.org/wiki/Phong_reflection_model )
class Scene : public AutoPrerenderingScene, public Batched<Renderable, Batch>
{
public:
Scene(Application& application) : AutoPrerenderingScene(application) {}
void init() override;
void use() override;
void unuse() override;
void render() override;
protected:
void set_camera(const Camera* p_camera) { m_p_camera = p_camera; }
Light& add_light(
const Position& position,
const Light::Power& power,
const ColorRGB ambient,
const ColorRGB diffuse,
const ColorRGB specular,
const Light::Fade& fade
)
{
m_lights.emplace_back(position, power, ambient, diffuse, specular, fade);
return m_lights.back();
}
private:
ShaderProgram m_shader_program;
const Camera* m_p_camera = nullptr;
std::vector<Light> m_lights;
};
}
}
}

View File

@ -1,19 +0,0 @@
#pragma once
#include <charcoal/VertexFragmentShaderProgram.h>
namespace charcoal
{
namespace builtin
{
namespace lit
{
// TODO: Add constants for the uniform and vertex attribute locations (for all shader programs)
class ShaderProgram : public VertexFragmentShaderProgram
{
public:
ShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "LitVS.glsl", SHADER_PATH "LitFS.glsl") {}
};
}
}
}

View File

@ -1,38 +0,0 @@
#include "LitShadowedBatch.h"
namespace charcoal
{
namespace builtin
{
namespace litshadowed
{
void Batch::setup_vao()
{
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)));
glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[0]);
glEnableVertexAttribArray(3);
glEnableVertexAttribArray(4);
glEnableVertexAttribArray(5);
glEnableVertexAttribArray(6);
glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(0 * sizeof(vec4)));
glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(1 * sizeof(vec4)));
glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(2 * sizeof(vec4)));
glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(3 * sizeof(vec4)));
glVertexAttribDivisor(0, 0); // Send the mesh data once
glVertexAttribDivisor(1, 0); // Send the mesh data once
glVertexAttribDivisor(2, 0); // Send the mesh data once
glVertexAttribDivisor(3, 1); // Send the offset data for each instance drawn
glVertexAttribDivisor(4, 1); // Send the offset data for each instance drawn
glVertexAttribDivisor(5, 1); // Send the offset data for each instance drawn
glVertexAttribDivisor(6, 1); // Send the offset data for each instance drawn
}
}
}
}

View File

@ -1,22 +0,0 @@
#pragma once
#include "PoseableBatch.h"
#include "LitShadowedTypes.h"
namespace charcoal
{
namespace builtin
{
namespace litshadowed
{
class Batch : public PoseableBatch<Vertex, Index, Renderable>
{
public:
using PoseableBatch<Vertex, Index, Renderable>::PoseableBatch;
protected:
void setup_vao() override;
};
}
}
}

View File

@ -1,52 +0,0 @@
#include "LitShadowedScene.h"
#include <charcoal/deps.h>
#include <charcoal/Util.h>
#include <charcoal/MeshFactory.h>
#include "GLUtil.h"
namespace charcoal
{
namespace builtin
{
namespace litshadowed
{
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, m_p_camera->get_world_to_view_matrix());
glutil::uniform_vec3(4, m_p_camera->get_position());
glutil::uniform_uint(5, (unsigned int)m_lights.size());
glutil::uniform_lights(6, m_lights);
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
{
iter->render();
}
}
}
}
}

View File

@ -1,56 +0,0 @@
#pragma once
#include <vector>
#include <charcoal/Camera.h>
#include "AutoPrerenderingScene.h"
#include "LitShadowedTypes.h"
#include "Batched.h"
#include "LitShadowedBatch.h"
#include "LitShadowedShaderProgram.h"
namespace charcoal
{
namespace builtin
{
namespace litshadowed
{
// A scene lit by the Phong Reflection Model (See https://en.wikipedia.org/wiki/Phong_reflection_model )
class Scene : public AutoPrerenderingScene, public Batched<Renderable, Batch>
{
public:
Scene(Application& application) : AutoPrerenderingScene(application) {}
void init() override;
void use() override;
void unuse() override;
void render() override;
protected:
void set_camera(const Camera* p_camera) { m_p_camera = p_camera; }
Light& add_light(
const Position& position,
const Light::Power& power,
const ColorRGB ambient,
const ColorRGB diffuse,
const ColorRGB specular,
const Light::Fade& fade
)
{
m_lights.emplace_back(position, power, ambient, diffuse, specular, fade);
return m_lights.back();
}
private:
ShaderProgram m_shader_program;
const Camera* m_p_camera = nullptr;
std::vector<Light> m_lights;
};
}
}
}

View File

@ -1,19 +0,0 @@
#pragma once
#include <charcoal/VertexFragmentShaderProgram.h>
namespace charcoal
{
namespace builtin
{
namespace litshadowed
{
// TODO: Add constants for the uniform and vertex attribute locations (for all shader programs)
class ShaderProgram : public VertexFragmentShaderProgram
{
public:
ShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "LitShadowedVS.glsl", SHADER_PATH "LitShadowedFS.glsl") {}
};
}
}
}

View File

@ -1,17 +0,0 @@
#pragma once
#include "BuiltinTypes.h"
namespace charcoal
{
namespace builtin
{
namespace litshadowed
{
typedef PNMVertex Vertex;
typedef Index Index;
typedef RenderableT<Vertex, Index> Renderable;
typedef Light Light;
}
}
}

View File

@ -1,17 +0,0 @@
#pragma once
#include "BuiltinTypes.h"
namespace charcoal
{
namespace builtin
{
namespace lit
{
typedef PNMVertex Vertex;
typedef Index Index;
typedef RenderableT<Vertex, Index> Renderable;
typedef Light Light;
}
}
}

View File

@ -1,37 +0,0 @@
#pragma once
#include <charcoal/Batch.h>
#include <charcoal/Renderable.h>
#include <charcoal/Poseable2D.h>
#include "PoseableBatch.h"
namespace charcoal
{
namespace builtin
{
// This has to be made completely seperately in order to avoid the vtable that gets added if Poseable is abstracted between
// 2D and 3D
template <typename VertexType, typename IndexType, typename RenderableT = RenderableT<VertexType, IndexType> >
class Poseable2DBatch : public PoseableBatch<VertexType, IndexType, RenderableT>
{
public:
using PoseableBatch<VertexType, IndexType, RenderableT>::PoseableBatch;
Poseable2D& get_pose(int index)
{
Poseable& pose = PoseableBatch<VertexType, IndexType, RenderableT>::get_pose(index);
Poseable* p_pose = &pose;
Poseable2D* p_pose_2d = reinterpret_cast<Poseable2D*>(p_pose); // Can do this since both are just mat4 wrappers
return *p_pose_2d;
}
const Poseable2D& get_pose(int index) const
{
Poseable& pose = PoseableBatch<VertexType, IndexType, RenderableT>::get_pose(index);
Poseable* p_pose = &pose;
Poseable2D* p_pose_2d = reinterpret_cast<Poseable2D*>(p_pose); // Can do this since both are just mat4 wrappers
return *p_pose_2d;
}
};
}
}

View File

@ -10,7 +10,7 @@ namespace charcoal
namespace builtin namespace builtin
{ {
// Note: If anything is changed in this file, it must also be changed in Poseable2DBatch // Note: If anything is changed in this file, it must also be changed in Poseable2DBatch
template <typename VertexType, typename IndexType, typename RenderableT = RenderableT<VertexType, IndexType> > template <typename VertexType, typename IndexType, int orientation_attrib_offset, typename RenderableT = RenderableT<VertexType, IndexType> >
class PoseableBatch : public builtin::Batch<VertexType, IndexType, 1, RenderableT> class PoseableBatch : public builtin::Batch<VertexType, IndexType, 1, RenderableT>
{ {
public: public:
@ -24,30 +24,55 @@ namespace charcoal
RenderableT* renderable, RenderableT* renderable,
int element_count, int element_count,
int element_render_count int element_render_count
) : builtin::Batch<VertexType, IndexType, 1, RenderableT>(renderable, element_render_count), m_pose_elements(element_count) ) : builtin::Batch<VertexType, IndexType, 1, RenderableT>(renderable, element_render_count), m_orientation_elements(element_count)
{} {}
virtual ~PoseableBatch() {} virtual ~PoseableBatch() {}
Poseable& get_pose(int index) { return m_pose_elements[index]; } void reset_rendered() { charcoal::Batch<VertexType, IndexType, 1, RenderableT>::m_element_render_count = 0; }
const Poseable& get_pose(int index) const { return m_pose_elements[index]; }
void add_rendered(const Poseable& poseable) { m_orientation_elements[charcoal::Batch<VertexType, IndexType, 1, RenderableT>::m_element_render_count++] = poseable.get_orientation_matrix(); }
protected: protected:
void setup_element_buffers() void setup_element_buffers()
{ {
glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch<VertexType, IndexType, 1, RenderableT>::m_element_buffers[0]); glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch<VertexType, IndexType, 1, RenderableT>::m_element_buffers[0]);
glBufferData(GL_ARRAY_BUFFER, m_pose_elements.size() * sizeof(Poseable), NULL, GL_STREAM_DRAW); glBufferData(GL_ARRAY_BUFFER, m_orientation_elements.size() * sizeof(mat4), NULL, GL_STREAM_DRAW);
} }
void update_element_buffers() void update_element_buffers()
{ {
// TODO: There are probably better ways to do this. Should check with the old engine to see what I did there. // TODO: There are probably better ways to do this. Should check with the old engine to see what I did there.
glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch<VertexType, IndexType, 1, RenderableT>::m_element_buffers[0]); glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch<VertexType, IndexType, 1, RenderableT>::m_element_buffers[0]);
glBufferData(GL_ARRAY_BUFFER, m_pose_elements.size() * sizeof(Poseable), NULL, GL_STREAM_DRAW); glBufferData(GL_ARRAY_BUFFER, m_orientation_elements.size() * sizeof(mat4), NULL, GL_STREAM_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, m_pose_elements.size() * sizeof(Poseable), m_pose_elements.data()); glBufferSubData(GL_ARRAY_BUFFER, 0, m_orientation_elements.size() * sizeof(mat4), m_orientation_elements.data());
} }
std::vector<Poseable> m_pose_elements; virtual void setup_vao_vertex() = 0;
void setup_vao() override
{
setup_vao_vertex();
glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch<VertexType, IndexType, 1, RenderableT>::m_element_buffers[0]);
glEnableVertexAttribArray(orientation_attrib_offset + 0);
glEnableVertexAttribArray(orientation_attrib_offset + 1);
glEnableVertexAttribArray(orientation_attrib_offset + 2);
glEnableVertexAttribArray(orientation_attrib_offset + 3);
glVertexAttribPointer(orientation_attrib_offset + 0, 4, GL_FLOAT, GL_FALSE, sizeof(mat4), (void*)(0 * sizeof(mat4::col_type)));
glVertexAttribPointer(orientation_attrib_offset + 1, 4, GL_FLOAT, GL_FALSE, sizeof(mat4), (void*)(1 * sizeof(mat4::col_type)));
glVertexAttribPointer(orientation_attrib_offset + 2, 4, GL_FLOAT, GL_FALSE, sizeof(mat4), (void*)(2 * sizeof(mat4::col_type)));
glVertexAttribPointer(orientation_attrib_offset + 3, 4, GL_FLOAT, GL_FALSE, sizeof(mat4), (void*)(3 * sizeof(mat4::col_type)));
glVertexAttribDivisor(orientation_attrib_offset + 0, 1); // Send the orientation data for each instance drawn
glVertexAttribDivisor(orientation_attrib_offset + 1, 1); // Send the orientation data for each instance drawn
glVertexAttribDivisor(orientation_attrib_offset + 2, 1); // Send the orientation data for each instance drawn
glVertexAttribDivisor(orientation_attrib_offset + 3, 1); // Send the orientation data for each instance drawn
}
std::vector<mat4> m_orientation_elements;
}; };
} }
} }

View File

@ -1,32 +0,0 @@
#include "SpecifiedBatch.h"
namespace charcoal
{
namespace builtin
{
namespace specified
{
void Batch::setup_vao()
{
glBindBuffer(GL_ARRAY_BUFFER, m_vertex_vbo);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), NULL);
glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[0]);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glEnableVertexAttribArray(3);
glEnableVertexAttribArray(4);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(0 * sizeof(vec4)));
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(1 * sizeof(vec4)));
glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(2 * sizeof(vec4)));
glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(3 * sizeof(vec4)));
glVertexAttribDivisor(0, 0); // Send the mesh data once
glVertexAttribDivisor(1, 1); // Send the offset data for each instance drawn
glVertexAttribDivisor(2, 1); // Send the offset data for each instance drawn
glVertexAttribDivisor(3, 1); // Send the offset data for each instance drawn
glVertexAttribDivisor(4, 1); // Send the offset data for each instance drawn
}
}
}
}

View File

@ -1,19 +0,0 @@
#pragma once
#include "SpecifiedPoseableBatch.h"
#include "SpecifiedTypes.h"
namespace charcoal
{
namespace builtin
{
namespace specified
{
class Batch : public SpecifiedPoseableBatch<Vertex, Index, Renderable>
{
protected:
void setup_vao() override;
};
}
}
}

View File

@ -1,25 +0,0 @@
#pragma once
#include <charcoal/Poseable.h>
namespace charcoal
{
namespace builtin
{
template <typename SpecifiedPoseableBatchType>
class SpecifiedPoseable : public Poseable
{
public:
SpecifiedPoseable(SpecifiedPoseableBatchType& batch) : m_batch(batch)
{}
void render()
{
m_batch.add_specified_poseable(this);
}
private:
SpecifiedPoseableBatchType& m_batch;
};
}
}

View File

@ -1,29 +0,0 @@
#pragma once
#include "PoseableBatch.h"
#include "SpecifiedPoseable.h"
namespace charcoal
{
namespace builtin
{
// Note: If anything is changed in this file, it must also be changed in Poseable2DBatch
template <typename VertexType, typename IndexType, typename RenderableT = RenderableT<VertexType, IndexType> >
class SpecifiedPoseableBatch : public PoseableBatch<VertexType, IndexType, RenderableT>
{
public:
using PoseableBatch<VertexType, IndexType, RenderableT>::PoseableBatch;
void reset()
{
m_element_render_count = 0;
}
void add_specified_poseable(SpecifiedPoseable<SpecifiedPoseableBatch<VertexType, IndexType, RenderableT> >* poseable)
{
PoseableBatch<VertexType, IndexType, RenderableT>::m_pose_elements[m_element_render_count++].set_orientation_matrix(poseable->get_orientation_matrix());
}
};
}
}

View File

@ -1,47 +0,0 @@
#include "SpecifiedScene.h"
#include <charcoal/deps.h>
#include "GLUtil.h"
namespace charcoal
{
namespace builtin
{
namespace specified
{
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();
}
}
}
}
}

View File

@ -1,34 +0,0 @@
#pragma once
#include "SpecifiedTypes.h"
#include "SpecifiedBatch.h"
#include "AutoPrerenderingScene.h"
#include "Batched.h"
#include "WithCamera.h"
namespace charcoal
{
namespace builtin
{
namespace specified
{
class Scene : public AutoPrerenderingScene, public Batched<Renderable, Batch>, 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;
};
}
}
}

View File

@ -1,23 +0,0 @@
#pragma once
#include "BuiltinTypes.h"
#include "BasicTypes.h"
#include "BasicShaderProgram.h"
namespace charcoal
{
namespace builtin
{
namespace specified
{
// Just use the basic types
typedef basic::Vertex Vertex;
typedef basic::Index Index;
typedef basic::Renderable Renderable;
typedef basic::ShaderProgram ShaderProgram;
}
}
}

View File

@ -3,19 +3,19 @@
#include <charcoal/Poseable2D.h> #include <charcoal/Poseable2D.h>
#include <charcoal/TextureRenderable.h> #include <charcoal/TextureRenderable.h>
#include "Poseable2DBatch.h" #include "PoseableBatch.h"
namespace charcoal namespace charcoal
{ {
namespace builtin namespace builtin
{ {
template <typename VertexType, typename IndexType, int position_offset, int uv_offset> template <typename VertexType, typename IndexType, int position_offset, int uv_offset>
class SpriteBatch : public Poseable2DBatch<VertexType, IndexType, TextureRenderable<VertexType, IndexType> > class SpriteBatch : public PoseableBatch<VertexType, IndexType, TextureRenderable<VertexType, IndexType> >
{ {
public: public:
// Note: This is VERY similar to builtin::textured::Batch // Note: This is VERY similar to builtin::textured::Batch
// Note: Uses GL_TEXTURE0. The uniform for this texture should be set in the scene before rendering. // Note: Uses GL_TEXTURE0. The uniform for this texture should be set in the scene before rendering.
using Poseable2DBatch<VertexType, IndexType, TextureRenderable<VertexType, IndexType> >::Poseable2DBatch; using PoseableBatch<VertexType, IndexType, TextureRenderable<VertexType, IndexType> >::PoseableBatch;
void preprender() const override void preprender() const override
{ {
@ -24,32 +24,6 @@ namespace charcoal
glBindTexture(GL_TEXTURE_2D, charcoal::Batch<VertexType, IndexType, 1, TextureRenderable<VertexType, IndexType> >::m_p_renderable->get_texture()->get_texture()); glBindTexture(GL_TEXTURE_2D, charcoal::Batch<VertexType, IndexType, 1, TextureRenderable<VertexType, IndexType> >::m_p_renderable->get_texture()->get_texture());
glBindSampler(0, charcoal::Batch<VertexType, IndexType, 1, TextureRenderable<VertexType, IndexType> >::m_p_renderable->get_sampler()->get_sampler()); glBindSampler(0, charcoal::Batch<VertexType, IndexType, 1, TextureRenderable<VertexType, IndexType> >::m_p_renderable->get_sampler()->get_sampler());
} }
protected:
void setup_vao() override
{
glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch<VertexType, IndexType, 1, TextureRenderable<VertexType, IndexType> >::m_vertex_vbo);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(VertexType), (void*)position_offset);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(VertexType), (void*)uv_offset);
glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch<VertexType, IndexType, 1, TextureRenderable<VertexType, IndexType> >::m_element_buffers[0]);
glEnableVertexAttribArray(2);
glEnableVertexAttribArray(3);
glEnableVertexAttribArray(4);
glEnableVertexAttribArray(5);
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable2D), (void*)(0 * sizeof(vec4)));
glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable2D), (void*)(1 * sizeof(vec4)));
glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable2D), (void*)(2 * sizeof(vec4)));
glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable2D), (void*)(3 * sizeof(vec4)));
glVertexAttribDivisor(0, 0); // Send the mesh data once
glVertexAttribDivisor(1, 0); // Send the mesh data once
glVertexAttribDivisor(2, 1); // Send the offset data for each instance drawn
glVertexAttribDivisor(3, 1); // Send the offset data for each instance drawn
glVertexAttribDivisor(4, 1); // Send the offset data for each instance drawn
glVertexAttribDivisor(5, 1); // Send the offset data for each instance drawn
}
}; };
} }
} }

View File

@ -1,42 +0,0 @@
#include "TexturedBatch.h"
namespace charcoal
{
namespace builtin
{
namespace textured
{
void Batch::preprender() const
{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_p_renderable->get_texture()->get_texture());
glBindSampler(0, m_p_renderable->get_sampler()->get_sampler());
}
void Batch::setup_vao()
{
glBindBuffer(GL_ARRAY_BUFFER, m_vertex_vbo);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, position));
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, uv));
glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[0]);
glEnableVertexAttribArray(2);
glEnableVertexAttribArray(3);
glEnableVertexAttribArray(4);
glEnableVertexAttribArray(5);
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(0 * sizeof(vec4)));
glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(1 * sizeof(vec4)));
glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(2 * sizeof(vec4)));
glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(3 * sizeof(vec4)));
glVertexAttribDivisor(0, 0); // Send the mesh data once
glVertexAttribDivisor(1, 0); // Send the mesh data once
glVertexAttribDivisor(2, 1); // Send the offset data for each instance drawn
glVertexAttribDivisor(3, 1); // Send the offset data for each instance drawn
glVertexAttribDivisor(4, 1); // Send the offset data for each instance drawn
glVertexAttribDivisor(5, 1); // Send the offset data for each instance drawn
}
}
}
}

View File

@ -1,24 +0,0 @@
#pragma once
#include "PoseableBatch.h"
#include "TexturedTypes.h"
namespace charcoal
{
namespace builtin
{
namespace textured
{
class Batch : public PoseableBatch<Vertex, Index, Renderable>
{
public:
using PoseableBatch<Vertex, Index, Renderable>::PoseableBatch;
void preprender() const override;
protected:
void setup_vao() override;
};
}
}
}

View File

@ -1,49 +0,0 @@
#include "TexturedScene.h"
#include <charcoal/deps.h>
#include <charcoal/MeshFactory.h>
#include "GLUtil.h"
namespace charcoal
{
namespace builtin
{
namespace textured
{
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, m_p_camera->get_world_to_view_matrix());
glutil::uniform_int(4, 0); // Sprite batches all use GL_TEXTURE0 so set this to 0
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
{
iter->render();
}
}
}
}
}

View File

@ -1,40 +0,0 @@
#pragma once
#include <vector>
#include <charcoal/Camera.h>
#include "AutoPrerenderingScene.h"
#include "Batched.h"
#include "TexturedBatch.h"
#include "TexturedShaderProgram.h"
namespace charcoal
{
namespace builtin
{
namespace textured
{
class Scene : public AutoPrerenderingScene, public Batched<Renderable, Batch>
{
public:
Scene(Application& application) : AutoPrerenderingScene(application) {}
void init() override;
void use() override;
void unuse() override;
void render() override;
protected:
void set_camera(const Camera* p_camera) { m_p_camera = p_camera; }
private:
ShaderProgram m_shader_program;
const Camera* m_p_camera = nullptr;
};
}
}
}

View File

@ -1,18 +0,0 @@
#pragma once
#include <charcoal/VertexFragmentShaderProgram.h>
namespace charcoal
{
namespace builtin
{
namespace textured
{
class ShaderProgram : public VertexFragmentShaderProgram
{
public:
ShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "TexturedVS.glsl", SHADER_PATH "TexturedFS.glsl") {}
};
}
}
}

View File

@ -1,18 +0,0 @@
#pragma once
#include <charcoal/TextureRenderable.h>
#include "BuiltinTypes.h"
namespace charcoal
{
namespace builtin
{
namespace textured
{
typedef PTVertex Vertex;
typedef Index Index;
typedef TextureRenderable<Vertex, Index> Renderable;
}
}
}

View File

@ -24,14 +24,9 @@
<ClCompile Include="MyBasicScene.cpp" /> <ClCompile Include="MyBasicScene.cpp" />
<ClCompile Include="MyBatch.cpp" /> <ClCompile Include="MyBatch.cpp" />
<ClCompile Include="MyBuiltinCubeScene.cpp" /> <ClCompile Include="MyBuiltinCubeScene.cpp" />
<ClCompile Include="MyBuiltinImageScene.cpp" />
<ClCompile Include="MyBuiltinLitScene.cpp" />
<ClCompile Include="MyBuiltinLitShadowedScene.cpp" />
<ClCompile Include="MyBuiltinTexturedScene.cpp" />
<ClCompile Include="MySimple2DScene.cpp" /> <ClCompile Include="MySimple2DScene.cpp" />
<ClCompile Include="MySimple3DScene.cpp" /> <ClCompile Include="MySimple3DScene.cpp" />
<ClCompile Include="MySimpleCubeScene.cpp" /> <ClCompile Include="MySimpleCubeScene.cpp" />
<ClCompile Include="MySpecifiedScene.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="MyApplication.h" /> <ClInclude Include="MyApplication.h" />
@ -39,15 +34,10 @@
<ClInclude Include="MyBasicShaderProgram.h" /> <ClInclude Include="MyBasicShaderProgram.h" />
<ClInclude Include="MyBatch.h" /> <ClInclude Include="MyBatch.h" />
<ClInclude Include="MyBuiltinCubeScene.h" /> <ClInclude Include="MyBuiltinCubeScene.h" />
<ClInclude Include="MyBuiltinImageScene.h" />
<ClInclude Include="MyBuiltinLitScene.h" />
<ClInclude Include="MyBuiltinLitShadowedScene.h" />
<ClInclude Include="MyBuiltinTexturedScene.h" />
<ClInclude Include="MySimple2DScene.h" /> <ClInclude Include="MySimple2DScene.h" />
<ClInclude Include="MySimple3DScene.h" /> <ClInclude Include="MySimple3DScene.h" />
<ClInclude Include="MySimpleCubeScene.h" /> <ClInclude Include="MySimpleCubeScene.h" />
<ClInclude Include="MySimpleShaderProgram.h" /> <ClInclude Include="MySimpleShaderProgram.h" />
<ClInclude Include="MySpecifiedScene.h" />
</ItemGroup> </ItemGroup>
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion> <VCProjectVersion>15.0</VCProjectVersion>

View File

@ -27,18 +27,6 @@
<ClCompile Include="MyBuiltinCubeScene.cpp"> <ClCompile Include="MyBuiltinCubeScene.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="MyBuiltinImageScene.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MyBuiltinLitScene.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MyBuiltinLitShadowedScene.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MyBuiltinTexturedScene.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MySimple2DScene.cpp"> <ClCompile Include="MySimple2DScene.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
@ -51,9 +39,6 @@
<ClCompile Include="main.cpp"> <ClCompile Include="main.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="MySpecifiedScene.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="MyApplication.h"> <ClInclude Include="MyApplication.h">
@ -74,18 +59,6 @@
<ClInclude Include="MyBuiltinCubeScene.h"> <ClInclude Include="MyBuiltinCubeScene.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="MyBuiltinImageScene.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MyBuiltinLitScene.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MyBuiltinLitShadowedScene.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MyBuiltinTexturedScene.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MySimple2DScene.h"> <ClInclude Include="MySimple2DScene.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
@ -95,8 +68,5 @@
<ClInclude Include="MySimpleCubeScene.h"> <ClInclude Include="MySimpleCubeScene.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="MySpecifiedScene.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -6,11 +6,7 @@ MyApplication::MyApplication(int width, int height)
m_simple_2d_scene(*this), m_simple_2d_scene(*this),
m_simple_3d_scene(*this), m_simple_3d_scene(*this),
m_simple_cube_scene(*this), m_simple_cube_scene(*this),
m_builtin_basic_cube_scene(*this), m_builtin_basic_cube_scene(*this)
m_builtin_lit_scene(*this),
m_builtin_textured_scene(*this),
m_builtin_lit_shadowed_scene(*this),
m_builtin_image_scene(*this)
{} {}
void MyApplication::init() void MyApplication::init()
@ -20,10 +16,6 @@ void MyApplication::init()
m_simple_3d_scene.init(); m_simple_3d_scene.init();
m_simple_cube_scene.init(); m_simple_cube_scene.init();
m_builtin_basic_cube_scene.init(); m_builtin_basic_cube_scene.init();
m_builtin_lit_scene.init();
m_builtin_textured_scene.init();
m_builtin_lit_shadowed_scene.init();
m_builtin_image_scene.init();
m_p_current_scene = &m_basic_scene; m_p_current_scene = &m_basic_scene;
m_p_current_scene->use(); m_p_current_scene->use();
@ -51,22 +43,6 @@ void MyApplication::update(float delta_time, clock_t clock)
{ {
swap_scene(&m_builtin_basic_cube_scene); swap_scene(&m_builtin_basic_cube_scene);
} }
else if (m_glfw_input_manager.is_key_pressed(GLFW_KEY_6))
{
swap_scene(&m_builtin_lit_scene);
}
else if (m_glfw_input_manager.is_key_pressed(GLFW_KEY_7))
{
swap_scene(&m_builtin_textured_scene);
}
else if (m_glfw_input_manager.is_key_pressed(GLFW_KEY_8))
{
swap_scene(&m_builtin_lit_shadowed_scene);
}
else if (m_glfw_input_manager.is_key_pressed(GLFW_KEY_9))
{
swap_scene(&m_builtin_image_scene);
}
m_p_current_scene->update(delta_time, clock); m_p_current_scene->update(delta_time, clock);
} }

View File

@ -8,15 +8,10 @@
#include "MySimple3DScene.h" #include "MySimple3DScene.h"
#include "MySimpleCubeScene.h" #include "MySimpleCubeScene.h"
#include "MyBuiltinCubeScene.h" #include "MyBuiltinCubeScene.h"
#include "MyBuiltinLitScene.h"
#include "MyBuiltinTexturedScene.h"
#include "MyBuiltinLitShadowedScene.h"
#include "MyBuiltinImageScene.h"
using namespace charcoal; using namespace charcoal;
class MyApplication : class MyApplication : public Application
public Application
{ {
public: public:
MyApplication(int width = -1, int height = -1); MyApplication(int width = -1, int height = -1);
@ -41,9 +36,5 @@ private:
MySimple3DScene m_simple_3d_scene; MySimple3DScene m_simple_3d_scene;
MySimpleCubeScene m_simple_cube_scene; MySimpleCubeScene m_simple_cube_scene;
MyBuiltinCubeScene m_builtin_basic_cube_scene; MyBuiltinCubeScene m_builtin_basic_cube_scene;
MyBuiltinLitScene m_builtin_lit_scene;
MyBuiltinTexturedScene m_builtin_textured_scene;
MyBuiltinLitShadowedScene m_builtin_lit_shadowed_scene; // Currently a WIP
MyBuiltinImageScene m_builtin_image_scene;
}; };

View File

@ -8,7 +8,7 @@ MyBuiltinCubeScene::MyBuiltinCubeScene(Application& application)
: basic::Scene(application), : basic::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, 1)) m_batch(add_batch(&m_shape, 2))
{ {
add_prerenderable(&m_camera); add_prerenderable(&m_camera);
set_camera(&m_camera); set_camera(&m_camera);
@ -30,11 +30,11 @@ void MyBuiltinCubeScene::update(float delta_time, clock_t clock)
radians = (float)TAU * c / intervals; radians = (float)TAU * c / intervals;
{ m_pose_a.rotate(glm::normalize(vec3(1.0f, 1.0f, 0.0f)), (float)TAU_1_2 * delta_time);
Poseable& pose = m_batch.get_pose(0); m_pose_a.update_position(vec3(3 * (float)cos(radians), 0.0f, 0.0f));
pose.rotate(glm::normalize(vec3(1.0f, 1.0f, 0.0f)), (float)TAU_1_2 * delta_time);
pose.update_position(vec3(3 * (float)cos(radians), 0.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));
vec3 camera_translation(0.0f, 0.0f, 0.0f); vec3 camera_translation(0.0f, 0.0f, 0.0f);
@ -51,5 +51,9 @@ void MyBuiltinCubeScene::update(float delta_time, clock_t clock)
m_camera.translate(camera_translation * delta_time); 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_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);
} }

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <charcoal/Poseable.h>
#include <charcoal-builtin/BasicScene.h> #include <charcoal-builtin/BasicScene.h>
#include <charcoal-builtin/BuiltinCamera3D.h> #include <charcoal-builtin/BuiltinCamera3D.h>
@ -16,4 +17,7 @@ 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;
Poseable m_pose_a;
Poseable m_pose_b;
}; };

View File

@ -1,60 +0,0 @@
#include "MyBuiltinImageScene.h"
#include <charcoal/constants.h>
#include <charcoal/TextureFactory.h>
#include <charcoal-builtin/MeshGenerator.h>
#include <charcoal-builtin/TextureGenerator.h>
MyBuiltinImageScene::MyBuiltinImageScene(Application& application)
: image::Scene(application),
m_image(image_loader::load_file(IMAGE_PATH "uber.png")),
m_image_renderable(
meshgenerator::gen_rect_pt<image::Vertex, image::Index>(DRAW_TRIANGLES, (float)m_image.width, (float)m_image.height),
TextureFactory::gen_image_texture(m_image),
texturegenerator::gen_quick_sampler(),
DrawMode::DRAW_TRIANGLES
),
m_camera(m_screen_size),
m_batch(add_batch(&m_image_renderable, 1))
{
add_prerenderable(&m_camera);
set_camera(&m_camera);
}
void MyBuiltinImageScene::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;
{
Poseable2D& pose = m_batch.get_pose(0);
// pose.rotate((float)TAU_1_4 * delta_time); TODO
pose.update_position(vec3(3 * (float)cos(radians), 0.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;
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, 0.0f, 1.0f), camera_rotation * (float)TAU_1_8 * delta_time); TODO
}

View File

@ -1,21 +0,0 @@
#pragma once
#include <charcoal/ImageLoader.h>
#include <charcoal-builtin/ImageScene.h>
#include <charcoal-builtin/BuiltinCamera2D.h>
using namespace charcoal;
using namespace charcoal::builtin;
class MyBuiltinImageScene : public image::Scene
{
public:
MyBuiltinImageScene(Application& application);
void update(float delta_time, clock_t clock) override;
private:
image_loader::ImageRGBA m_image;
image::Renderable m_image_renderable;
builtin::Camera2D m_camera;
image::Batch& m_batch;
};

View File

@ -1,68 +0,0 @@
#include "MyBuiltinLitScene.h"
#include <charcoal/constants.h>
#include <charcoal-builtin/MeshGenerator.h>
MyBuiltinLitScene::MyBuiltinLitScene(Application& application)
: lit::Scene(application),
m_shape(
meshgenerator::set_material<lit::Vertex, lit::Index>(
meshgenerator::gen_cube_pn<lit::Vertex, lit::Index>(DRAW_TRIANGLES, 2.0f, 2.0f, 2.0f),
Material(1.0f, 1.0f, 0.2f, 1.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, 1))
{
add_prerenderable(&m_camera);
set_camera(&m_camera);
add_light(
Position(0.0f, 2.0f, -2.0f),
Light::Power(0.2f, 1.0f, 1.0f),
ColorRGB(1.0f, 1.0f, 1.0f),
ColorRGB(1.0f, 1.0f, 1.0f),
ColorRGB(1.0f, 1.0f, 1.0f),
Light::Fade(1.0f, 0.1f, 0.01f)
);
}
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;
{
Poseable& pose = m_batch.get_pose(0);
pose.rotate(glm::normalize(vec3(1.0f, 1.0f, 0.0f)), (float)TAU_1_8 * delta_time);
pose.update_position(vec3(3 * (float)cos(radians), 0.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);
}

View File

@ -1,20 +0,0 @@
#pragma once
#include <charcoal-builtin/LitScene.h>
#include <charcoal-builtin/BuiltinCamera3D.h>
using namespace charcoal;
using namespace charcoal::builtin;
// TODO: Use the lit namespace in builtin
class MyBuiltinLitScene : public lit::Scene
{
public:
MyBuiltinLitScene(Application& application);
void update(float delta_time, clock_t clock) override;
private:
lit::Renderable m_shape;
builtin::Camera3D m_camera;
lit::Batch& m_batch;
};

View File

@ -1,75 +0,0 @@
#include "MyBuiltinLitShadowedScene.h"
#include <charcoal/constants.h>
#include <charcoal-builtin/MeshGenerator.h>
MyBuiltinLitShadowedScene::MyBuiltinLitShadowedScene(Application& application)
: litshadowed::Scene(application),
m_cube(
meshgenerator::set_material<litshadowed::Vertex, litshadowed::Index>(
meshgenerator::gen_cube_pn<litshadowed::Vertex, litshadowed::Index>(DRAW_TRIANGLES, 2.0f, 2.0f, 2.0f),
Material(1.0f, 1.0f, 0.2f, 1.0f)
), DrawMode::DRAW_TRIANGLES
),
m_plane(
meshgenerator::set_material<litshadowed::Vertex, litshadowed::Index>(
meshgenerator::gen_plane_pn<litshadowed::Vertex, litshadowed::Index>(DRAW_TRIANGLES, 4.0f, 4.0f),
Material(1.0f, 1.0f, 0.2f, 1.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_cube_batch(add_batch(&m_cube, 1)),
m_plane_batch(add_batch(&m_plane, 1))
{
add_prerenderable(&m_camera);
set_camera(&m_camera);
add_light(
Position(0.0f, 2.0f, -2.0f),
Light::Power(0.2f, 1.0f, 1.0f),
ColorRGB(1.0f, 1.0f, 1.0f),
ColorRGB(1.0f, 1.0f, 1.0f),
ColorRGB(1.0f, 1.0f, 1.0f),
Light::Fade(1.0f, 0.1f, 0.01f)
);
}
void MyBuiltinLitShadowedScene::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;
{
Poseable& pose = m_cube_batch.get_pose(0);
pose.rotate(glm::normalize(vec3(1.0f, 1.0f, 0.0f)), (float)TAU_1_8 * delta_time);
pose.update_position(vec3(3 * (float)cos(radians), 0.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);
}

View File

@ -1,21 +0,0 @@
#pragma once
#include <charcoal-builtin/LitShadowedScene.h>
#include <charcoal-builtin/BuiltinCamera3D.h>
using namespace charcoal;
using namespace charcoal::builtin;
class MyBuiltinLitShadowedScene : public litshadowed::Scene
{
public:
MyBuiltinLitShadowedScene(Application& application);
void update(float delta_time, clock_t clock) override;
private:
litshadowed::Renderable m_cube;
litshadowed::Renderable m_plane;
builtin::Camera3D m_camera;
litshadowed::Batch& m_cube_batch;
litshadowed::Batch& m_plane_batch;
};

View File

@ -1,60 +0,0 @@
#include "MyBuiltinTexturedScene.h"
#include <charcoal/constants.h>
#include <charcoal-builtin/MeshGenerator.h>
#include <charcoal-builtin/TextureGenerator.h>
MyBuiltinTexturedScene::MyBuiltinTexturedScene(Application& application)
: textured::Scene(application),
m_shape(
meshgenerator::gen_cube_pt<textured::Vertex, textured::Index>(DRAW_TRIANGLES, 2.0f, 2.0f, 2.0f),
texturegenerator::gen_quick_cube_texture(),
texturegenerator::gen_quick_sampler(),
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, 1))
{
add_prerenderable(&m_camera);
set_camera(&m_camera);
}
void MyBuiltinTexturedScene::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;
{
Poseable& pose = m_batch.get_pose(0);
pose.rotate(glm::normalize(vec3(1.0f, 1.0f, 0.0f)), (float)TAU_1_4 * delta_time);
pose.update_position(vec3(3 * (float)cos(radians), 0.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);
}

View File

@ -1,19 +0,0 @@
#pragma once
#include <charcoal-builtin/TexturedScene.h>
#include <charcoal-builtin/BuiltinCamera3D.h>
using namespace charcoal;
using namespace charcoal::builtin;
class MyBuiltinTexturedScene : public textured::Scene
{
public:
MyBuiltinTexturedScene(Application& application);
void update(float delta_time, clock_t clock) override;
private:
textured::Renderable m_shape;
builtin::Camera3D m_camera;
textured::Batch& m_batch;
};

View File

@ -1,26 +0,0 @@
#include "MySpecifiedScene.h"
#include <charcoal/constants.h>
#include <charcoal-builtin/MeshGenerator.h>
MyBuiltinSpecifiedScene::MyBuiltinSpecifiedScene(Application& application)
: specified::Scene(application),
m_shape(meshgenerator::gen_cube_p<specified::Vertex, specified::Index>(DRAW_TRIANGLES, 2.0f, 2.0f, 2.0f), 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_pose_a(m_batch),
m_pose_b(m_batch)
{
add_prerenderable(&m_camera);
set_camera(&m_camera);
m_pose_a.update_position(glm::vec3(-4.0f, 0.0f, 0.0f));
m_pose_a.update_position(glm::vec3(4.0f, 0.0f, 0.0f));
}
void MyBuiltinSpecifiedScene::update(float delta_time, clock_t clock)
{
m_batch.reset();
m_pose_a.render();
}

View File

@ -1,25 +0,0 @@
#pragma once
#include <charcoal-builtin/SpecifiedScene.h>
#include <charcoal-builtin/BuiltinCamera3D.h>
#include <charcoal-builtin/SpecifiedPoseable.h>
using namespace charcoal;
using namespace charcoal::builtin;
class MyBuiltinSpecifiedScene : public specified::Scene
{
public:
MyBuiltinSpecifiedScene(Application& application);
void update(float delta_time, clock_t clock) override;
private:
basic::Renderable m_shape;
builtin::Camera3D m_camera;
specified::Batch& m_batch;
SpecifiedPoseable<specified::Batch> m_pose_a;
SpecifiedPoseable<specified::Batch> m_pose_b;
};