/*
(c) 2004-14 Filip Stoklas, aka FipS, www.4FipS.com
THIS CODE IS FREE - LICENSED UNDER THE MIT LICENSE
*/
#include "fs_app_host.h"
#include "fs_gfx_core.h"
#include "fs_gfx_extra.h"
#include "fs_math_func.h"
#include "fs_data_duck.cpp"
using namespace fs;
class test_app final : public app::host
{
public:
test_app() {}
private:
FS_NON_COPYABLE(test_app);
void on_config(app::host_config &cfg) override final
{
cfg.title = "fs_test_geometry | 4FIPS.COM";
}
void on_init() override final
{
FS_TRACE(("[o] TEST: fs_test_geometry"));
auto &g = graphics();
gfx::geometry_view gv(g_duck_geom_data);
_ctx.geom = std::move(gfx::create_from_view(g, gv));
gfx::texture_view tv(g_duck_tex_data);
_ctx.tex = std::move(gfx::create_from_view(g, tv));
g.param_dict("s_tex", gfx::param_type::texture).set(*_ctx.tex);
g.binding().rebind_geometry(*_ctx.geom);
g.binding().rebind_shader(gfx_resources().shader(gfx::resource_db::shader_id::color_tex));
}
void on_deinit() override final
{
_ctx.reset();
}
void on_draw(gfx::canvas &cvs) override final
{
namespace m = fs::math;
auto &g = graphics();
const auto w = float(state().width);
const auto h = float(state().height);
const auto ratio = w / (h > 0.f ? h : 1.f);
const auto proj = m::mat4_make_perspective(45.f, ratio, 1.f, 1000.f);
const auto view = m::mat4_make_xyz(0.f, -80.f, -300.f);
const auto model = m::mat4_make_rot_y(float(state().frame_time));
g.param_dict("u_mvp", gfx::param_type::matrix4_f).set(proj * view * model);
g.draw(gfx::primitive_type::triangles);
}
struct context
{
std::unique_ptr<gfx::geometry> geom;
std::unique_ptr<gfx::texture> tex;
void reset()
{
geom.reset();
tex.reset();
}
} _ctx;
};
FS_APP_HOST_MAIN(test_app);