charcoal/OpenGLEngine/BasicScene.cpp

67 lines
1.4 KiB
C++
Raw Normal View History

#include "BasicScene.h"
#include "stdafx.h"
#include "GLUtil.h"
namespace charcoal
{
namespace builtin
{
BasicScene::BasicScene(Application& application)
: Scene(application), m_camera((float)TAU_1_4, (float)m_screen_size.x / (float)m_screen_size.y, 1.0f, 10.0f, vec3(0.0f, 0.0f, -5.0f))
{}
void BasicScene::init()
{
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
{
iter->init();
}
}
void BasicScene::use()
{
// TODO: move to glutil
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
}
void BasicScene::unuse()
{
}
void BasicScene::prerender()
{
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
{
iter->prerender();
}
m_camera.prerender();
}
void BasicScene::render()
{
// TODO: This is not rendering :(
glutil::clear_screen();
m_shader_program.use();
glutil::uniform_matrix(0, m_camera.get_world_to_view_matrix());
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
{
iter->render();
}
}
BasicBatch* BasicScene::add_batch(BasicRenderable* renderable, int element_count)
{
return add_batch(renderable, element_count, element_count);
}
BasicBatch* BasicScene::add_batch(BasicRenderable* renderable, int element_count, int element_render_count)
{
m_batches.emplace_back(renderable, element_count, element_render_count);
return &m_batches.back();
}
}
}