Added namespaces to builtin types

This commit is contained in:
Elipzer 2018-09-19 03:52:42 -04:00
parent cc9db05987
commit 821111416f
46 changed files with 578 additions and 449 deletions

View File

@ -4,11 +4,13 @@ namespace charcoal
{
namespace builtin
{
void BasicBatch::setup_vao()
namespace basic
{
void Batch::setup_vao()
{
glBindBuffer(GL_ARRAY_BUFFER, m_vertex_vbo);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(BasicVertex), NULL);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), NULL);
glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[0]);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
@ -26,4 +28,5 @@ namespace charcoal
glVertexAttribDivisor(4, 1); // Send the offset data for each instance drawn
}
}
}
}

View File

@ -1,30 +1,33 @@
#pragma once
#include "PoseableBatch.h"
#include "BuiltinTypes.h"
#include "BasicTypes.h"
namespace charcoal
{
namespace builtin
{
class BasicBatch : public PoseableBatch<BasicVertex, BasicIndex, BasicRenderable>
namespace basic
{
class Batch : public PoseableBatch<Vertex, Index, Renderable>
{
public:
BasicBatch(
BasicRenderable* renderable,
Batch(
Renderable* renderable,
int element_count
) : PoseableBatch<BasicVertex, BasicIndex, BasicRenderable>(renderable, element_count)
) : PoseableBatch<Vertex, Index, Renderable>(renderable, element_count)
{}
BasicBatch(
BasicRenderable* renderable,
Batch(
Renderable* renderable,
int element_count,
int element_render_count
) : PoseableBatch<BasicVertex, BasicIndex, BasicRenderable>(renderable, element_count, element_render_count)
) : PoseableBatch<Vertex, Index, Renderable>(renderable, element_count, element_render_count)
{}
protected:
void setup_vao() override;
};
}
}
}

View File

@ -9,29 +9,31 @@ namespace charcoal
{
namespace builtin
{
void BasicScene::init()
namespace basic
{
void Scene::init()
{
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
{
BasicBatch& batch = *iter;
Batch& batch = *iter;
batch.init();
add_prerenderable(&batch);
}
}
void BasicScene::use()
void Scene::use()
{
// TODO: move to glutil
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
}
void BasicScene::unuse()
void Scene::unuse()
{
}
void BasicScene::render()
void Scene::render()
{
glutil::clear_screen();
m_shader_program.use();
@ -42,4 +44,5 @@ namespace charcoal
}
}
}
}
}

View File

@ -2,10 +2,11 @@
#include <vector>
#include "Application.h"
#include "AutoPrerenderingScene.h"
#include "BasicShaderProgram.h"
#include "BuiltinTypes.h"
#include "BasicTypes.h"
#include "Camera.h"
#include "Batched.h"
#include "BasicBatch.h"
@ -16,11 +17,13 @@ namespace charcoal
{
namespace builtin
{
class BasicScene : public AutoPrerenderingScene, public Batched<BasicRenderable, BasicBatch>
namespace basic
{
class Scene : public AutoPrerenderingScene, public Batched<Renderable, Batch>
{
public:
BasicScene(Application& application) : AutoPrerenderingScene(application) {}
virtual ~BasicScene() {}
Scene(Application& application) : AutoPrerenderingScene(application) {}
virtual ~Scene() {}
void init() override;
@ -34,8 +37,9 @@ namespace charcoal
void set_camera(const Camera* p_camera) { m_p_camera = p_camera; }
private:
BasicShaderProgram m_shader_program;
ShaderProgram m_shader_program;
const Camera* m_p_camera = nullptr;
};
}
}
}

View File

@ -6,10 +6,13 @@ namespace charcoal
{
namespace builtin
{
class BasicShaderProgram : public VertexFragmentShaderProgram
namespace basic
{
class ShaderProgram : public VertexFragmentShaderProgram
{
public:
BasicShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "BasicVS.glsl", SHADER_PATH "BasicFS.glsl") {}
ShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "BasicVS.glsl", SHADER_PATH "BasicFS.glsl") {}
};
}
}
}

16
OpenGLEngine/BasicTypes.h Normal file
View File

@ -0,0 +1,16 @@
#pragma once
#include "BuiltinTypes.h"
namespace charcoal
{
namespace builtin
{
namespace basic
{
typedef PVertex Vertex;
typedef Index Index;
typedef RenderableT<Vertex, Index> Renderable;
}
}
}

View File

@ -5,11 +5,13 @@
#include <cstddef>
#include <vector>
#include "Renderable.h"
#include "Exception.h"
namespace charcoal
{
template <typename VertexType, typename IndexType, int element_buffer_count, typename Renderable = Renderable<VertexType, IndexType> >
template <typename VertexType, typename IndexType, int element_buffer_count, typename Renderable = RenderableT<VertexType, IndexType> >
class Batch
{
public:

View File

@ -7,16 +7,16 @@ namespace charcoal
{
namespace builtin
{
template <typename VertexType, typename IndexType, int element_buffer_count, typename Renderable = Renderable<VertexType, IndexType> >
class Batch : public Prerenderable, public charcoal::Batch<VertexType, IndexType, element_buffer_count, Renderable>
template <typename VertexType, typename IndexType, int element_buffer_count, typename RenderableT = RenderableT<VertexType, IndexType> >
class Batch : public Prerenderable, public charcoal::Batch<VertexType, IndexType, element_buffer_count, RenderableT>
{
public:
Batch(
const Renderable* renderable,
const RenderableT* renderable,
int element_render_count
) : charcoal::Batch<VertexType, IndexType, element_buffer_count, Renderable>(renderable, element_render_count) {}
) : charcoal::Batch<VertexType, IndexType, element_buffer_count, RenderableT>(renderable, element_render_count) {}
void prerender() override { charcoal::Batch<VertexType, IndexType, element_buffer_count, Renderable>::prerender(); }
void prerender() override { charcoal::Batch<VertexType, IndexType, element_buffer_count, RenderableT>::prerender(); }
};
}
}

View File

@ -99,23 +99,5 @@ namespace charcoal
Position position;
UV uv;
};
// typedefs for builtin types
typedef PVertex BasicVertex;
typedef Index BasicIndex;
typedef Renderable<BasicVertex, BasicIndex> BasicRenderable;
typedef PNMVertex LitVertex;
typedef Index LitIndex;
typedef Renderable<LitVertex, LitIndex> LitRenderable;
typedef PNMVertex LitShadowedVertex;
typedef Index LitShadowedIndex;
typedef Renderable<LitShadowedVertex, LitShadowedIndex> LitShadowedRenderable;
typedef PTVertex TexturedVertex;
typedef Index TexturedIndex;
typedef TextureRenderable<TexturedVertex, TexturedIndex> TexturedRenderable;
}
}

View File

@ -4,15 +4,17 @@ namespace charcoal
{
namespace builtin
{
void LitBatch::setup_vao()
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(LitVertex), (void*)(offsetof(LitVertex, position)));
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(LitVertex), (void*)(offsetof(LitVertex, normal)));
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(LitVertex), (void*)(offsetof(LitVertex, material)));
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);
@ -32,4 +34,5 @@ namespace charcoal
glVertexAttribDivisor(6, 1); // Send the offset data for each instance drawn
}
}
}
}

View File

@ -1,30 +1,33 @@
#pragma once
#include "PoseableBatch.h"
#include "BuiltinTypes.h"
#include "LitTypes.h"
namespace charcoal
{
namespace builtin
{
class LitBatch : public PoseableBatch<LitVertex, LitIndex, LitRenderable>
namespace lit
{
class Batch : public PoseableBatch<Vertex, Index, Renderable>
{
public:
LitBatch(
LitRenderable* renderable,
Batch(
Renderable* renderable,
int element_count
) : PoseableBatch<LitVertex, LitIndex, LitRenderable>(renderable, element_count)
) : PoseableBatch<Vertex, Index, Renderable>(renderable, element_count)
{}
LitBatch(
LitRenderable* renderable,
Batch(
Renderable* renderable,
int element_count,
int element_render_count
) : PoseableBatch<LitVertex, LitIndex, LitRenderable>(renderable, element_count, element_render_count)
) : PoseableBatch<Vertex, Index, Renderable>(renderable, element_count, element_render_count)
{}
protected:
void setup_vao() override;
};
}
}
}

View File

@ -10,29 +10,31 @@ namespace charcoal
{
namespace builtin
{
void LitScene::init()
namespace lit
{
void Scene::init()
{
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
{
LitBatch& batch = *iter;
Batch& batch = *iter;
batch.init();
add_prerenderable(&batch);
}
}
void LitScene::use()
void Scene::use()
{
// TODO: move to glutil
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
}
void LitScene::unuse()
void Scene::unuse()
{
}
void LitScene::render()
void Scene::render()
{
glutil::clear_screen();
m_shader_program.use();
@ -46,4 +48,5 @@ namespace charcoal
}
}
}
}
}

View File

@ -3,7 +3,7 @@
#include <vector>
#include "AutoPrerenderingScene.h"
#include "BuiltinTypes.h"
#include "LitTypes.h"
#include "Camera.h"
#include "Batched.h"
#include "LitBatch.h"
@ -12,13 +12,15 @@
namespace charcoal
{
namespace builtin
{
namespace lit
{
// A scene lit by the Phong Reflection Model (See https://en.wikipedia.org/wiki/Phong_reflection_model )
class LitScene : public AutoPrerenderingScene, public Batched<LitRenderable, LitBatch>
class Scene : public AutoPrerenderingScene, public Batched<Renderable, Batch>
{
public:
LitScene(Application& application) : AutoPrerenderingScene(application) {}
virtual ~LitScene() {}
Scene(Application& application) : AutoPrerenderingScene(application) {}
virtual ~Scene() {}
void init() override;
@ -45,9 +47,10 @@ namespace charcoal
}
private:
LitShaderProgram m_shader_program;
ShaderProgram m_shader_program;
const Camera* m_p_camera = nullptr;
std::vector<Light> m_lights;
};
}
}
}

View File

@ -6,11 +6,14 @@ namespace charcoal
{
namespace builtin
{
// TODO: Add constatns for the uniform and vertex attribute locations (for all shader programs)
class LitShaderProgram : public VertexFragmentShaderProgram
namespace lit
{
// TODO: Add constants for the uniform and vertex attribute locations (for all shader programs)
class ShaderProgram : public VertexFragmentShaderProgram
{
public:
LitShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "LitVS.glsl", SHADER_PATH "LitFS.glsl") {}
ShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "LitVS.glsl", SHADER_PATH "LitFS.glsl") {}
};
}
}
}

View File

@ -4,15 +4,17 @@ namespace charcoal
{
namespace builtin
{
void LitShadowedBatch::setup_vao()
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(LitVertex), (void*)(offsetof(LitVertex, position)));
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(LitVertex), (void*)(offsetof(LitVertex, normal)));
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(LitVertex), (void*)(offsetof(LitVertex, material)));
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);
@ -32,4 +34,5 @@ namespace charcoal
glVertexAttribDivisor(6, 1); // Send the offset data for each instance drawn
}
}
}
}

View File

@ -1,30 +1,33 @@
#pragma once
#include "PoseableBatch.h"
#include "BuiltinTypes.h"
#include "LitShadowedTypes.h"
namespace charcoal
{
namespace builtin
{
class LitShadowedBatch : public PoseableBatch<LitVertex, LitIndex, LitRenderable>
namespace litshadowed
{
class Batch : public PoseableBatch<Vertex, Index, Renderable>
{
public:
LitShadowedBatch(
LitRenderable* renderable,
Batch(
Renderable* renderable,
int element_count
) : PoseableBatch<LitVertex, LitIndex, LitRenderable>(renderable, element_count)
) : PoseableBatch<Vertex, Index, Renderable>(renderable, element_count)
{}
LitShadowedBatch(
LitRenderable* renderable,
Batch(
Renderable* renderable,
int element_count,
int element_render_count
) : PoseableBatch<LitVertex, LitIndex, LitRenderable>(renderable, element_count, element_render_count)
) : PoseableBatch<Vertex, Index, Renderable>(renderable, element_count, element_render_count)
{}
protected:
void setup_vao() override;
};
}
}
}

View File

@ -10,29 +10,31 @@ namespace charcoal
{
namespace builtin
{
void LitShadowedScene::init()
namespace litshadowed
{
void Scene::init()
{
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
{
LitShadowedBatch& batch = *iter;
Batch& batch = *iter;
batch.init();
add_prerenderable(&batch);
}
}
void LitShadowedScene::use()
void Scene::use()
{
// TODO: move to glutil
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
}
void LitShadowedScene::unuse()
void Scene::unuse()
{
}
void LitShadowedScene::render()
void Scene::render()
{
glutil::clear_screen();
m_shader_program.use();
@ -46,4 +48,5 @@ namespace charcoal
}
}
}
}
}

View File

@ -3,7 +3,7 @@
#include <vector>
#include "AutoPrerenderingScene.h"
#include "BuiltinTypes.h"
#include "LitShadowedTypes.h"
#include "Camera.h"
#include "Batched.h"
#include "LitShadowedBatch.h"
@ -12,13 +12,15 @@
namespace charcoal
{
namespace builtin
{
namespace litshadowed
{
// A scene lit by the Phong Reflection Model (See https://en.wikipedia.org/wiki/Phong_reflection_model )
class LitShadowedScene : public AutoPrerenderingScene, public Batched<LitShadowedRenderable, LitShadowedBatch>
class Scene : public AutoPrerenderingScene, public Batched<Renderable, Batch>
{
public:
LitShadowedScene(Application& application) : AutoPrerenderingScene(application) {}
virtual ~LitShadowedScene() {}
Scene(Application& application) : AutoPrerenderingScene(application) {}
virtual ~Scene() {}
void init() override;
@ -45,9 +47,10 @@ namespace charcoal
}
private:
LitShadowedShaderProgram m_shader_program;
ShaderProgram m_shader_program;
const Camera* m_p_camera = nullptr;
std::vector<Light> m_lights;
};
}
}
}

View File

@ -6,11 +6,14 @@ namespace charcoal
{
namespace builtin
{
// TODO: Add constatns for the uniform and vertex attribute locations (for all shader programs)
class LitShadowedShaderProgram : public VertexFragmentShaderProgram
namespace litshadowed
{
// TODO: Add constants for the uniform and vertex attribute locations (for all shader programs)
class ShaderProgram : public VertexFragmentShaderProgram
{
public:
LitShadowedShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "LitShadowedVS.glsl", SHADER_PATH "LitShadowedFS.glsl") {}
ShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "LitShadowedVS.glsl", SHADER_PATH "LitShadowedFS.glsl") {}
};
}
}
}

View File

@ -0,0 +1,17 @@
#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;
}
}
}

17
OpenGLEngine/LitTypes.h Normal file
View 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;
typedef Light Light;
}
}
}

View File

@ -28,7 +28,7 @@ public:
float a = 1.0f;
};
typedef unsigned int Index;
typedef Renderable<Vertex, Index> Renderable;
typedef RenderableT<Vertex, Index> RenderableT;
typedef Mesh<Vertex, Index> Mesh;
MyBasicShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "MyBasicVS.glsl", SHADER_PATH "MyBasicFS.glsl") {}

View File

@ -12,12 +12,12 @@ class MyBatch : public charcoal::Batch<MySimpleShaderProgram::Vertex, MySimpleSh
{
public:
MyBatch(
const MySimpleShaderProgram::Renderable* renderable,
const MySimpleShaderProgram::RenderableT* renderable,
int element_count
) : MyBatch(renderable, element_count, element_count) {}
MyBatch(
const MySimpleShaderProgram::Renderable* renderable,
const MySimpleShaderProgram::RenderableT* renderable,
int element_count,
int element_render_count
) : Batch(renderable, element_render_count), m_color_elements(element_count), m_poseable_elements(element_count) {}

View File

@ -5,8 +5,8 @@
#include "constants.h"
MyBuiltinCubeScene::MyBuiltinCubeScene(Application& application)
: BasicScene(application),
m_shape(meshgenerator::gen_cube_p<BasicVertex, BasicIndex>(DRAW_TRIANGLES, 2.0f, 2.0f, 2.0f), DrawMode::DRAW_TRIANGLES),
: 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_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))
{

View File

@ -6,14 +6,14 @@
using namespace charcoal;
using namespace charcoal::builtin;
class MyBuiltinCubeScene : public BasicScene
class MyBuiltinCubeScene : public basic::Scene
{
public:
MyBuiltinCubeScene(Application& application);
void update(float delta_time, clock_t clock) override;
private:
BasicRenderable m_shape;
basic::Renderable m_shape;
builtin::Camera3D m_camera;
BasicBatch& m_batch;
basic::Batch& m_batch;
};

View File

@ -5,10 +5,10 @@
#include "constants.h"
MyBuiltinLitScene::MyBuiltinLitScene(Application& application)
: LitScene(application),
: lit::Scene(application),
m_shape(
meshgenerator::set_material<LitVertex, LitIndex>(
meshgenerator::gen_cube_pn<LitVertex, LitIndex>(DRAW_TRIANGLES, 2.0f, 2.0f, 2.0f),
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
),

View File

@ -6,14 +6,15 @@
using namespace charcoal;
using namespace charcoal::builtin;
class MyBuiltinLitScene : public LitScene
// 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:
LitRenderable m_shape;
lit::Renderable m_shape;
builtin::Camera3D m_camera;
LitBatch& m_batch;
lit::Batch& m_batch;
};

View File

@ -5,10 +5,10 @@
#include "constants.h"
MyBuiltinLitShadowedScene::MyBuiltinLitShadowedScene(Application& application)
: LitShadowedScene(application),
: litshadowed::Scene(application),
m_shape(
meshgenerator::set_material<LitVertex, LitIndex>(
meshgenerator::gen_cube_pn<LitVertex, LitIndex>(DRAW_TRIANGLES, 2.0f, 2.0f, 2.0f),
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
),

View File

@ -6,14 +6,14 @@
using namespace charcoal;
using namespace charcoal::builtin;
class MyBuiltinLitShadowedScene : public LitShadowedScene
class MyBuiltinLitShadowedScene : public litshadowed::Scene
{
public:
MyBuiltinLitShadowedScene(Application& application);
void update(float delta_time, clock_t clock) override;
private:
LitShadowedRenderable m_shape;
litshadowed::Renderable m_shape;
builtin::Camera3D m_camera;
LitShadowedBatch& m_batch;
litshadowed::Batch& m_batch;
};

View File

@ -6,9 +6,9 @@
#include "constants.h"
MyBuiltinTexturedScene::MyBuiltinTexturedScene(Application& application)
: TexturedScene(application),
: textured::Scene(application),
m_shape(
meshgenerator::gen_cube_pt<TexturedVertex, TexturedIndex>(DRAW_TRIANGLES, 2.0f, 2.0f, 2.0f),
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

View File

@ -6,14 +6,14 @@
using namespace charcoal;
using namespace charcoal::builtin;
class MyBuiltinTexturedScene : public TexturedScene
class MyBuiltinTexturedScene : public textured::Scene
{
public:
MyBuiltinTexturedScene(Application& application);
void update(float delta_time, clock_t clock) override;
private:
TexturedRenderable m_shape;
textured::Renderable m_shape;
builtin::Camera3D m_camera;
TexturedBatch& m_batch;
textured::Batch& m_batch;
};

View File

@ -29,7 +29,7 @@ public:
private:
MySimpleShaderProgram m_shader_program;
MySimpleShaderProgram::Renderable m_shape;
MySimpleShaderProgram::RenderableT m_shape;
MyBatch m_batch;
Camera2D m_camera;
};

View File

@ -29,7 +29,7 @@ public:
private:
MySimpleShaderProgram m_shader_program;
MySimpleShaderProgram::Renderable m_shape;
MySimpleShaderProgram::RenderableT m_shape;
MyBatch m_batch;
charcoal::Camera3D m_camera;
};

View File

@ -29,7 +29,7 @@ public:
private:
MySimpleShaderProgram m_shader_program;
MySimpleShaderProgram::Renderable m_shape;
MySimpleShaderProgram::RenderableT m_shape;
MyBatch m_batch;
charcoal::Camera3D m_camera;
};

View File

@ -28,7 +28,7 @@ public:
float a = 1.0f;
};
typedef unsigned int Index;
typedef Renderable<Vertex, Index> Renderable;
typedef RenderableT<Vertex, Index> RenderableT;
typedef Mesh<Vertex, Index> Mesh;
MySimpleShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "MySimpleVS.glsl", SHADER_PATH "MySimpleFS.glsl") {}

View File

@ -195,6 +195,7 @@
<ClInclude Include="BasicBatch.h" />
<ClInclude Include="BasicScene.h" />
<ClInclude Include="BasicShaderProgram.h" />
<ClInclude Include="BasicTypes.h" />
<ClInclude Include="Batch.h" />
<ClInclude Include="Batched.h" />
<ClInclude Include="BuiltinBatch.h" />
@ -213,6 +214,8 @@
<ClInclude Include="LitShadowedBatch.h" />
<ClInclude Include="LitShadowedScene.h" />
<ClInclude Include="LitShadowedShaderProgram.h" />
<ClInclude Include="LitShadowedTypes.h" />
<ClInclude Include="LitTypes.h" />
<ClInclude Include="MyBuiltinCubeScene.h" />
<ClInclude Include="MyBuiltinLitScene.h" />
<ClInclude Include="MyBuiltinLitShadowedScene.h" />
@ -222,6 +225,7 @@
<ClInclude Include="Sampler.h" />
<ClInclude Include="Texture.h" />
<ClInclude Include="TexturedBatch.h" />
<ClInclude Include="TexturedTypes.h" />
<ClInclude Include="TextureFactory.h" />
<ClInclude Include="TextureGenerator.h" />
<ClInclude Include="TextureRenderable.h" />

View File

@ -371,6 +371,18 @@
<ClInclude Include="MyBuiltinLitShadowedScene.h">
<Filter>Header Files\Example\Application</Filter>
</ClInclude>
<ClInclude Include="BasicTypes.h">
<Filter>Header Files\Engine\builtin\Basic</Filter>
</ClInclude>
<ClInclude Include="LitTypes.h">
<Filter>Header Files\Engine\builtin\Lit</Filter>
</ClInclude>
<ClInclude Include="TexturedTypes.h">
<Filter>Header Files\Engine\builtin\Textured</Filter>
</ClInclude>
<ClInclude Include="LitShadowedTypes.h">
<Filter>Header Files\Engine\builtin\LitShadowed</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="MySimpleVS.glsl">

View File

@ -9,22 +9,22 @@ namespace charcoal
{
namespace builtin
{
template <typename VertexType, typename IndexType, typename Renderable = Renderable<VertexType, IndexType> >
class PoseableBatch : public builtin::Batch<VertexType, IndexType, 1, Renderable>
template <typename VertexType, typename IndexType, typename RenderableT = RenderableT<VertexType, IndexType> >
class PoseableBatch : public builtin::Batch<VertexType, IndexType, 1, RenderableT>
{
public:
// TODO: Figure out how to get rid of this typename garbage. If that it figured out, m_element_buffers should get fixed.
PoseableBatch(
Renderable* renderable,
RenderableT* renderable,
int element_count
) : PoseableBatch(renderable, element_count, element_count)
{}
PoseableBatch(
Renderable* renderable,
RenderableT* renderable,
int element_count,
int element_render_count
) : builtin::Batch<VertexType, IndexType, 1, Renderable>(renderable, element_render_count), m_pose_elements(element_count)
) : builtin::Batch<VertexType, IndexType, 1, RenderableT>(renderable, element_render_count), m_pose_elements(element_count)
{}
virtual ~PoseableBatch() {}
@ -35,14 +35,14 @@ namespace charcoal
protected:
void setup_element_buffers()
{
glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch<VertexType, IndexType, 1, Renderable>::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);
}
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.
glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch<VertexType, IndexType, 1, Renderable>::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);
glBufferSubData(GL_ARRAY_BUFFER, 0, m_pose_elements.size() * sizeof(Poseable), m_pose_elements.data());
}

View File

@ -11,14 +11,14 @@
namespace charcoal
{
template <typename VertexType, typename IndexType>
class Renderable
class RenderableT
{
public:
typedef VertexType VertexType;
typedef IndexType IndexType;
typedef Mesh<VertexType, IndexType> MeshType;
Renderable(const MeshType* mesh, const DrawMode& draw_mode)
RenderableT(const MeshType* mesh, const DrawMode& draw_mode)
: m_p_mesh(mesh), m_draw_mode(draw_mode)
{}

View File

@ -7,11 +7,11 @@
namespace charcoal
{
template <typename VertexType, typename IndexType>
class TextureRenderable : public Renderable<VertexType, IndexType>
class TextureRenderable : public RenderableT<VertexType, IndexType>
{
public:
TextureRenderable(const Renderable<VertexType, IndexType>::MeshType* mesh, Texture* texture, Sampler* sampler, const DrawMode& draw_mode)
: Renderable<VertexType, IndexType>(mesh, draw_mode), m_p_texture(texture), m_p_sampler(sampler)
TextureRenderable(const RenderableT<VertexType, IndexType>::MeshType* mesh, Texture* texture, Sampler* sampler, const DrawMode& draw_mode)
: RenderableT<VertexType, IndexType>(mesh, draw_mode), m_p_texture(texture), m_p_sampler(sampler)
{}
const Texture* get_texture() const { return m_p_texture; }

View File

@ -4,20 +4,22 @@ namespace charcoal
{
namespace builtin
{
void TexturedBatch::preprender() const
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 TexturedBatch::setup_vao()
void Batch::setup_vao()
{
glBindBuffer(GL_ARRAY_BUFFER, m_vertex_vbo);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(TexturedVertex), (void*)offsetof(TexturedVertex, position));
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(TexturedVertex), (void*)offsetof(TexturedVertex, uv));
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);
@ -36,4 +38,5 @@ namespace charcoal
glVertexAttribDivisor(5, 1); // Send the offset data for each instance drawn
}
}
}
}

View File

@ -1,26 +1,28 @@
#pragma once
#include "PoseableBatch.h"
#include "BuiltinTypes.h"
#include "TexturedTypes.h"
namespace charcoal
{
namespace builtin
{
class TexturedBatch : public PoseableBatch<TexturedVertex, TexturedIndex, TexturedRenderable>
namespace textured
{
class Batch : public PoseableBatch<Vertex, Index, Renderable>
{
public:
TexturedBatch(
TexturedRenderable* renderable,
Batch(
Renderable* renderable,
int element_count
) : PoseableBatch<TexturedVertex, TexturedIndex, TexturedRenderable>(renderable, element_count)
) : PoseableBatch<Vertex, Index, Renderable>(renderable, element_count)
{}
TexturedBatch(
TexturedRenderable* renderable,
Batch(
Renderable* renderable,
int element_count,
int element_render_count
) : PoseableBatch<TexturedVertex, TexturedIndex, TexturedRenderable>(renderable, element_count, element_render_count)
) : PoseableBatch<Vertex, Index, Renderable>(renderable, element_count, element_render_count)
{}
void preprender() const override;
@ -29,4 +31,5 @@ namespace charcoal
void setup_vao() override;
};
}
}
}

View File

@ -9,29 +9,31 @@ namespace charcoal
{
namespace builtin
{
void TexturedScene::init()
namespace textured
{
void Scene::init()
{
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
{
TexturedBatch& batch = *iter;
Batch& batch = *iter;
batch.init();
add_prerenderable(&batch);
}
}
void TexturedScene::use()
void Scene::use()
{
// TODO: move to glutil
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
}
void TexturedScene::unuse()
void Scene::unuse()
{
}
void TexturedScene::render()
void Scene::render()
{
glutil::clear_screen();
m_shader_program.use();
@ -43,4 +45,5 @@ namespace charcoal
}
}
}
}
}

View File

@ -14,11 +14,13 @@ namespace charcoal
{
namespace builtin
{
class TexturedScene : public AutoPrerenderingScene, public Batched<TexturedRenderable, TexturedBatch>
namespace textured
{
class Scene : public AutoPrerenderingScene, public Batched<Renderable, Batch>
{
public:
TexturedScene(Application& application) : AutoPrerenderingScene(application) {}
virtual ~TexturedScene() {}
Scene(Application& application) : AutoPrerenderingScene(application) {}
virtual ~Scene() {}
void init() override;
@ -32,8 +34,9 @@ namespace charcoal
void set_camera(const Camera* p_camera) { m_p_camera = p_camera; }
private:
TexturedShaderProgram m_shader_program;
ShaderProgram m_shader_program;
const Camera* m_p_camera = nullptr;
};
}
}
}

View File

@ -6,10 +6,13 @@ namespace charcoal
{
namespace builtin
{
class TexturedShaderProgram : public VertexFragmentShaderProgram
namespace textured
{
class ShaderProgram : public VertexFragmentShaderProgram
{
public:
TexturedShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "TexturedVS.glsl", SHADER_PATH "TexturedFS.glsl") {}
ShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "TexturedVS.glsl", SHADER_PATH "TexturedFS.glsl") {}
};
}
}
}

View File

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