material asset

This commit is contained in:
2018-11-30 18:26:33 +07:00
parent 8879e86c15
commit c67848a05a
6 changed files with 1537 additions and 11 deletions

View File

@@ -460,7 +460,7 @@ namespace e2d
public:
stencil_state& write(u8 mask) noexcept;
stencil_state& func(compare_func func, u8 ref, u8 mask) noexcept;
stencil_state& op(stencil_op sfail, stencil_op zfail, stencil_op pass) noexcept;
stencil_state& op(stencil_op pass, stencil_op sfail, stencil_op zfail) noexcept;
u8 write() const noexcept;
compare_func func() const noexcept;

View File

@@ -53,4 +53,10 @@ namespace e2d
using content_asset<texture_ptr>::content_asset;
static std::shared_ptr<texture_asset> load(library& library, str_view address);
};
class material_asset final : public content_asset<render::material> {
public:
using content_asset<render::material>::content_asset;
static std::shared_ptr<material_asset> load(library& library, str_view address);
};
}

View File

@@ -357,10 +357,10 @@ namespace e2d
return *this;
}
render::stencil_state& render::stencil_state::op(stencil_op sfail, stencil_op zfail, stencil_op pass) noexcept {
render::stencil_state& render::stencil_state::op(stencil_op pass, stencil_op sfail, stencil_op zfail) noexcept {
pass_ = pass;
sfail_ = sfail;
zfail_ = zfail;
pass_ = pass;
return *this;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,64 @@
{
"passes" : [{
"shader" : "shader.json",
"state_block" : {
"depth_state" : {
"range" : { "near" : 1, "far" : 2 },
"write" : false,
"func" : "greater"
},
"stencil_state" : {
"write" : 2,
"func" : "never",
"ref" : 4,
"mask" : 5,
"pass" : "incr",
"sfail" : "decr",
"zfail" : "invert"
},
"culling_state" : {
"mode" : "cw",
"face" : "front"
},
"blending_state" : {
"constant_color" : { "r" : 1, "g" : 1, "b" : 1, "a" : 1 },
"color_mask" : "gba",
"src_factor" : "dst_alpha",
"dst_factor" : { "rgb" : "dst_color", "alpha" : "src_color" },
"equation" : { "rgb" : "subtract", "alpha" : "reverse_subtract" }
},
"capabilities_state" : {
"culling" : true,
"blending" : true,
"depth_test" : true,
"stencil_test" : true
}
},
"property_block" : {
"properties" : [
{ "name" : "f", "type" : "f32", "value" : 4.2 },
{ "name" : "v1", "type" : "v2i", "value" : { "x" : 1, "y" : 2 } },
{ "name" : "v2", "type" : "v3f", "value" : 3.0 },
{ "name" : "v3", "type" : "v4i", "value" : [1,2,3,4] }
]
}
}],
"property_block" : {
"samplers" : [{
"name" : "s",
"texture" : "image.png",
"wrap" : {
"s" : "clamp",
"t" : "repeat",
"r" : "mirror"
},
"filter" : {
"min" : "linear_mipmap_linear",
"mag" : "linear"
}
}],
"properties" : [
{ "name" : "i", "type" : "i32", "value" : 42 }
]
}
}

View File

@@ -10,6 +10,8 @@ using namespace e2d;
TEST_CASE("library"){
modules::initialize<vfs>();
modules::initialize<debug>();
//modules::initialize<window>(v2u{640,480}, "", false);
//modules::initialize<render>(the<debug>(), the<window>());
modules::initialize<library>(url{"resources://bin/library"});
modules::initialize<asset_cache<text_asset>>(the<library>());
modules::initialize<asset_cache<image_asset>>(the<library>());
@@ -83,6 +85,94 @@ TEST_CASE("library"){
REQUIRE_FALSE(the<asset_cache<image_asset>>().find("image.png"));
REQUIRE_FALSE(the<asset_cache<binary_asset>>().find("image.png"));
}
{
//library& l = the<library>();
//auto shader_res = l.load_asset<shader_asset>("shader.json");
//REQUIRE(shader_res);
//REQUIRE(shader_res->content());
}
{
library& l = the<library>();
auto material_res = l.load_asset<material_asset>("material.json");
REQUIRE(material_res);
{
const auto* sampler = material_res->content().properties().sampler("s");
REQUIRE(sampler);
REQUIRE(sampler->s_wrap() == render::sampler_wrap::clamp);
REQUIRE(sampler->t_wrap() == render::sampler_wrap::repeat);
REQUIRE(sampler->r_wrap() == render::sampler_wrap::mirror);
REQUIRE(sampler->min_filter() == render::sampler_min_filter::linear_mipmap_linear);
REQUIRE(sampler->mag_filter() == render::sampler_mag_filter::linear);
}
{
const auto* property = material_res->content().properties().property("i");
REQUIRE(property);
REQUIRE(property->index() == 0);
REQUIRE(stdex::get<i32>(*property) == 42);
}
REQUIRE(material_res->content().pass_count() == 1);
const auto& pass = material_res->content().pass(0);
//REQUIRE(pass.shader());
{
const auto* property = pass.properties().property("f");
REQUIRE(property);
REQUIRE(property->index() == 1);
REQUIRE(math::approximately(stdex::get<f32>(*property), 4.2f));
}
{
const auto* property = pass.properties().property("v1");
REQUIRE(property);
REQUIRE(property->index() == 2);
REQUIRE(stdex::get<v2i>(*property) == v2i(1,2));
}
{
const auto* property = pass.properties().property("v2");
REQUIRE(property);
REQUIRE(property->index() == 6);
REQUIRE(stdex::get<v3f>(*property) == v3f(3.f));
}
{
const auto* property = pass.properties().property("v3");
REQUIRE(property);
REQUIRE(property->index() == 4);
REQUIRE(stdex::get<v4i>(*property) == v4i(1,2,3,4));
}
REQUIRE(pass.states().depth().range_near() == 1.f);
REQUIRE(pass.states().depth().range_far() == 2.f);
REQUIRE(pass.states().depth().write() == false);
REQUIRE(pass.states().depth().func() == render::compare_func::greater);
REQUIRE(pass.states().stencil().write() == 2u);
REQUIRE(pass.states().stencil().func() == render::compare_func::never);
REQUIRE(pass.states().stencil().ref() == 4u);
REQUIRE(pass.states().stencil().mask() == 5u);
REQUIRE(pass.states().stencil().pass() == render::stencil_op::incr);
REQUIRE(pass.states().stencil().sfail() == render::stencil_op::decr);
REQUIRE(pass.states().stencil().zfail() == render::stencil_op::invert);
REQUIRE(pass.states().culling().mode() == render::culling_mode::cw);
REQUIRE(pass.states().culling().face() == render::culling_face::front);
REQUIRE(pass.states().capabilities().culling());
REQUIRE(pass.states().capabilities().blending());
REQUIRE(pass.states().capabilities().depth_test());
REQUIRE(pass.states().capabilities().stencil_test());
REQUIRE(pass.states().blending().constant_color() == color::white());
REQUIRE(pass.states().blending().color_mask() == render::blending_color_mask::gba);
REQUIRE(pass.states().blending().src_rgb_factor() == render::blending_factor::dst_alpha);
REQUIRE(pass.states().blending().src_alpha_factor() == render::blending_factor::dst_alpha);
REQUIRE(pass.states().blending().dst_rgb_factor() == render::blending_factor::dst_color);
REQUIRE(pass.states().blending().dst_alpha_factor() == render::blending_factor::src_color);
REQUIRE(pass.states().blending().rgb_equation() == render::blending_equation::subtract);
REQUIRE(pass.states().blending().alpha_equation() == render::blending_equation::reverse_subtract);
}
modules::shutdown<asset_cache<binary_asset>>();
modules::shutdown<asset_cache<image_asset>>();
modules::shutdown<asset_cache<text_asset>>();