
#include "pw/core/debug.hpp"
#include "pw/visual/pipeline.hpp"
#include "pw/visual/shader.hpp"
#include "pw/visual/framebuffer.hpp"
#include "pw/visual/texture.hpp"
#include "pw/visual/context.hpp"

#include "pw/core/size.hpp"


#include "runtime_lua.hpp"

namespace pw {

void register_visual_function(sol::state& lua,sol::table &ns)
{

//    ns.new_usertype<pipeline>("pipeline"
//							  ,"create",&pipeline::create
//                              ,"draw",&pipeline::draw
//                              );

    ns.new_usertype<shader>("shader"
                            ,sol::call_constructor,sol::constructors<shader()>()
                            ,"ready",sol::readonly_property(&shader::ready)
                            ,"use",&shader::use
                            ,"build",&shader::build
                            ,"source",&shader::source
                            ,"set_source",&shader::set_source
                            ,"set_uniforms",&shader::set_uniforms
                            ,"set_uniform_float",&shader::set_uniform<float>
                            ,"set_uniform_uint",&shader::set_uniform<uint32_t>
                            ,"set_uniform_int",&shader::set_uniform<int32_t>
                            ,"set_uniform_mat4",&shader::set_uniform<matrix4x4&>
                            ,"set_uniform_vec4",&shader::set_uniform<vector4&>
                            ,"set_uniform_texture",&shader::set_uniform<texture&>

                            );


    ns["shader_type"] = ns.create_named("shader_type"
                                       ,"fragment",shader::code_type::fragment
                                        ,"vertex",shader::code_type::vertex
                                        ,"geometry",shader::code_type::geometry
                                        ,"compute",shader::code_type::compute);

//    new_enum<false>(


//    ns.new_usertype<render_pass>("render_pass"
//                                ,"submit",&render_pass::submit
//                                 );


    ns.new_usertype<renderer>("renderer"
                              ,sol::call_constructor,sol::constructors<renderer(),renderer(const geometry&)>()
                              ,"update",&renderer::update
                              ,"ready",sol::readonly_property(&renderer::ready)
                              ,"change_count",sol::readonly_property(&renderer::change_count)
                              ,"release",&renderer::release
                              ,"draw",&renderer::draw
                              );

    ns.new_usertype<framebuffer>("framebuffer"
                                 ,sol::call_constructor,sol::constructors<framebuffer()>()
                                 ,"create",&framebuffer::create
                                 ,"bind",&framebuffer::bind
                                 ,"unbind",&framebuffer::unbind
                                 ,"blit",&framebuffer::blit);

    ns.new_usertype<texture>("texture"
                             ,sol::call_constructor,sol::constructors<texture()>()
                             ,"create",&texture::create
                             ,"update",&texture::update
                             ,"bind",&texture::bind
                             ,"unbind",&texture::unbind
                             ,"native_handle",&texture::native_handle
                             );

    ns.new_usertype<context>("context"
                             ,sol::call_constructor,sol::constructors<context()>()
                             ,"clear",&context::clear
                             ,"clearcolor",sol::property(&context::clearcolor,&context::set_clearcolor)
                             ,"set_viewport",&context::set_viewport
                             ,"get_error",&context::get_error
                             );
}

PW_REGISTER_LUA(visual)

}
