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,26 +4,29 @@ namespace charcoal
{
namespace builtin
{
void BasicBatch::setup_vao()
namespace basic
{
glBindBuffer(GL_ARRAY_BUFFER, m_vertex_vbo);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(BasicVertex), 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)));
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
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,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
{
public:
BasicBatch(
BasicRenderable* renderable,
int element_count
) : PoseableBatch<BasicVertex, BasicIndex, BasicRenderable>(renderable, element_count)
{}
class Batch : public PoseableBatch<Vertex, Index, Renderable>
{
public:
Batch(
Renderable* renderable,
int element_count
) : PoseableBatch<Vertex, Index, Renderable>(renderable, element_count)
{}
BasicBatch(
BasicRenderable* renderable,
int element_count,
int element_render_count
) : PoseableBatch<BasicVertex, BasicIndex, BasicRenderable>(renderable, element_count, element_render_count)
{}
Batch(
Renderable* renderable,
int element_count,
int element_render_count
) : PoseableBatch<Vertex, Index, Renderable>(renderable, element_count, element_render_count)
{}
protected:
void setup_vao() override;
};
protected:
void setup_vao() override;
};
}
}
}

View File

@ -9,36 +9,39 @@ namespace charcoal
{
namespace builtin
{
void BasicScene::init()
namespace basic
{
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
void Scene::init()
{
BasicBatch& batch = *iter;
batch.init();
add_prerenderable(&batch);
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
{
Batch& batch = *iter;
batch.init();
add_prerenderable(&batch);
}
}
}
void BasicScene::use()
{
// TODO: move to glutil
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
}
void BasicScene::unuse()
{
}
void BasicScene::render()
{
glutil::clear_screen();
m_shader_program.use();
glutil::uniform_matrix(0, m_p_camera->get_world_to_view_matrix());
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
void Scene::use()
{
iter->render();
// 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());
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
{
iter->render();
}
}
}
}

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,26 +17,29 @@ namespace charcoal
{
namespace builtin
{
class BasicScene : public AutoPrerenderingScene, public Batched<BasicRenderable, BasicBatch>
namespace basic
{
public:
BasicScene(Application& application) : AutoPrerenderingScene(application) {}
virtual ~BasicScene() {}
class Scene : public AutoPrerenderingScene, public Batched<Renderable, Batch>
{
public:
Scene(Application& application) : AutoPrerenderingScene(application) {}
virtual ~Scene() {}
void init() override;
void init() override;
void use() override;
void use() override;
void unuse() override;
void unuse() override;
void render() override;
void render() override;
protected:
void set_camera(const Camera* p_camera) { m_p_camera = p_camera; }
protected:
void set_camera(const Camera* p_camera) { m_p_camera = p_camera; }
private:
BasicShaderProgram m_shader_program;
const Camera* m_p_camera = nullptr;
};
private:
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
{
public:
BasicShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "BasicVS.glsl", SHADER_PATH "BasicFS.glsl") {}
};
class ShaderProgram : public VertexFragmentShaderProgram
{
public:
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,32 +4,35 @@ namespace charcoal
{
namespace builtin
{
void LitBatch::setup_vao()
namespace lit
{
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)));
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)));
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
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,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
{
public:
LitBatch(
LitRenderable* renderable,
int element_count
) : PoseableBatch<LitVertex, LitIndex, LitRenderable>(renderable, element_count)
{}
class Batch : public PoseableBatch<Vertex, Index, Renderable>
{
public:
Batch(
Renderable* renderable,
int element_count
) : PoseableBatch<Vertex, Index, Renderable>(renderable, element_count)
{}
LitBatch(
LitRenderable* renderable,
int element_count,
int element_render_count
) : PoseableBatch<LitVertex, LitIndex, LitRenderable>(renderable, element_count, element_render_count)
{}
Batch(
Renderable* renderable,
int element_count,
int element_render_count
) : PoseableBatch<Vertex, Index, Renderable>(renderable, element_count, element_render_count)
{}
protected:
void setup_vao() override;
};
protected:
void setup_vao() override;
};
}
}
}

View File

@ -10,39 +10,42 @@ namespace charcoal
{
namespace builtin
{
void LitScene::init()
namespace lit
{
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
void Scene::init()
{
LitBatch& batch = *iter;
batch.init();
add_prerenderable(&batch);
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
{
Batch& batch = *iter;
batch.init();
add_prerenderable(&batch);
}
}
}
void LitScene::use()
{
// TODO: move to glutil
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
}
void LitScene::unuse()
{
}
void LitScene::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)
void Scene::use()
{
iter->render();
// 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

@ -3,7 +3,7 @@
#include <vector>
#include "AutoPrerenderingScene.h"
#include "BuiltinTypes.h"
#include "LitTypes.h"
#include "Camera.h"
#include "Batched.h"
#include "LitBatch.h"
@ -13,41 +13,44 @@ namespace charcoal
{
namespace builtin
{
// 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>
namespace lit
{
public:
LitScene(Application& application) : AutoPrerenderingScene(application) {}
virtual ~LitScene() {}
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
)
// 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>
{
m_lights.emplace_back(position, power, ambient, diffuse, specular, fade);
return m_lights.back();
}
public:
Scene(Application& application) : AutoPrerenderingScene(application) {}
virtual ~Scene() {}
private:
LitShaderProgram m_shader_program;
const Camera* m_p_camera = nullptr;
std::vector<Light> m_lights;
};
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

@ -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
{
public:
LitShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "LitVS.glsl", SHADER_PATH "LitFS.glsl") {}
};
// 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

@ -4,32 +4,35 @@ namespace charcoal
{
namespace builtin
{
void LitShadowedBatch::setup_vao()
namespace litshadowed
{
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)));
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)));
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
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,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
{
public:
LitShadowedBatch(
LitRenderable* renderable,
int element_count
) : PoseableBatch<LitVertex, LitIndex, LitRenderable>(renderable, element_count)
{}
class Batch : public PoseableBatch<Vertex, Index, Renderable>
{
public:
Batch(
Renderable* renderable,
int element_count
) : PoseableBatch<Vertex, Index, Renderable>(renderable, element_count)
{}
LitShadowedBatch(
LitRenderable* renderable,
int element_count,
int element_render_count
) : PoseableBatch<LitVertex, LitIndex, LitRenderable>(renderable, element_count, element_render_count)
{}
Batch(
Renderable* renderable,
int element_count,
int element_render_count
) : PoseableBatch<Vertex, Index, Renderable>(renderable, element_count, element_render_count)
{}
protected:
void setup_vao() override;
};
protected:
void setup_vao() override;
};
}
}
}

View File

@ -10,39 +10,42 @@ namespace charcoal
{
namespace builtin
{
void LitShadowedScene::init()
namespace litshadowed
{
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
void Scene::init()
{
LitShadowedBatch& batch = *iter;
batch.init();
add_prerenderable(&batch);
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
{
Batch& batch = *iter;
batch.init();
add_prerenderable(&batch);
}
}
}
void LitShadowedScene::use()
{
// TODO: move to glutil
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
}
void LitShadowedScene::unuse()
{
}
void LitShadowedScene::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)
void Scene::use()
{
iter->render();
// 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

@ -3,7 +3,7 @@
#include <vector>
#include "AutoPrerenderingScene.h"
#include "BuiltinTypes.h"
#include "LitShadowedTypes.h"
#include "Camera.h"
#include "Batched.h"
#include "LitShadowedBatch.h"
@ -13,41 +13,44 @@ namespace charcoal
{
namespace builtin
{
// 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>
namespace litshadowed
{
public:
LitShadowedScene(Application& application) : AutoPrerenderingScene(application) {}
virtual ~LitShadowedScene() {}
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
)
// 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>
{
m_lights.emplace_back(position, power, ambient, diffuse, specular, fade);
return m_lights.back();
}
public:
Scene(Application& application) : AutoPrerenderingScene(application) {}
virtual ~Scene() {}
private:
LitShadowedShaderProgram m_shader_program;
const Camera* m_p_camera = nullptr;
std::vector<Light> m_lights;
};
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

@ -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
{
public:
LitShadowedShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "LitShadowedVS.glsl", SHADER_PATH "LitShadowedFS.glsl") {}
};
// 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

@ -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,36 +4,39 @@ namespace charcoal
{
namespace builtin
{
void TexturedBatch::preprender() const
namespace textured
{
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::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()
{
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));
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)));
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
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,32 +1,35 @@
#pragma once
#include "PoseableBatch.h"
#include "BuiltinTypes.h"
#include "TexturedTypes.h"
namespace charcoal
{
namespace builtin
{
class TexturedBatch : public PoseableBatch<TexturedVertex, TexturedIndex, TexturedRenderable>
namespace textured
{
public:
TexturedBatch(
TexturedRenderable* renderable,
int element_count
) : PoseableBatch<TexturedVertex, TexturedIndex, TexturedRenderable>(renderable, element_count)
{}
class Batch : public PoseableBatch<Vertex, Index, Renderable>
{
public:
Batch(
Renderable* renderable,
int element_count
) : PoseableBatch<Vertex, Index, Renderable>(renderable, element_count)
{}
TexturedBatch(
TexturedRenderable* renderable,
int element_count,
int element_render_count
) : PoseableBatch<TexturedVertex, TexturedIndex, TexturedRenderable>(renderable, element_count, element_render_count)
{}
Batch(
Renderable* renderable,
int element_count,
int element_render_count
) : PoseableBatch<Vertex, Index, Renderable>(renderable, element_count, element_render_count)
{}
void preprender() const override;
void preprender() const override;
protected:
void setup_vao() override;
};
protected:
void setup_vao() override;
};
}
}
}

View File

@ -9,37 +9,40 @@ namespace charcoal
{
namespace builtin
{
void TexturedScene::init()
namespace textured
{
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
void Scene::init()
{
TexturedBatch& batch = *iter;
batch.init();
add_prerenderable(&batch);
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
{
Batch& batch = *iter;
batch.init();
add_prerenderable(&batch);
}
}
}
void TexturedScene::use()
{
// TODO: move to glutil
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
}
void TexturedScene::unuse()
{
}
void TexturedScene::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); // The textured batch uses GL_TEXTURE0
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
void Scene::use()
{
iter->render();
// 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); // The textured batch uses GL_TEXTURE0
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
{
iter->render();
}
}
}
}

View File

@ -14,26 +14,29 @@ namespace charcoal
{
namespace builtin
{
class TexturedScene : public AutoPrerenderingScene, public Batched<TexturedRenderable, TexturedBatch>
namespace textured
{
public:
TexturedScene(Application& application) : AutoPrerenderingScene(application) {}
virtual ~TexturedScene() {}
class Scene : public AutoPrerenderingScene, public Batched<Renderable, Batch>
{
public:
Scene(Application& application) : AutoPrerenderingScene(application) {}
virtual ~Scene() {}
void init() override;
void init() override;
void use() override;
void use() override;
void unuse() override;
void unuse() override;
void render() override;
void render() override;
protected:
void set_camera(const Camera* p_camera) { m_p_camera = p_camera; }
protected:
void set_camera(const Camera* p_camera) { m_p_camera = p_camera; }
private:
TexturedShaderProgram m_shader_program;
const Camera* m_p_camera = nullptr;
};
private:
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
{
public:
TexturedShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "TexturedVS.glsl", SHADER_PATH "TexturedFS.glsl") {}
};
class ShaderProgram : public VertexFragmentShaderProgram
{
public:
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;
}
}
}