|
@ -44,42 +44,43 @@ struct render_test : public test_scaffold { |
|
|
|
|
|
|
|
|
virtual int run() { |
|
|
virtual int run() { |
|
|
int res = 0; |
|
|
int res = 0; |
|
|
renderer a; |
|
|
|
|
|
|
|
|
gp::array<char, 2048> allocation_buffer; |
|
|
|
|
|
renderer a{allocation_buffer.as_buffer()}; |
|
|
a._resolution = vec2{128,64}; |
|
|
a._resolution = vec2{128,64}; |
|
|
a.passes = 5; |
|
|
a.passes = 5; |
|
|
a.projection_end = 3; |
|
|
a.projection_end = 3; |
|
|
|
|
|
|
|
|
a.sky_box = [](vec3) -> color_t { |
|
|
|
|
|
|
|
|
a.sky_box = n">material_t([](vec3) -> color_t { |
|
|
color_t ret; |
|
|
color_t ret; |
|
|
ret.r() = 0.5; |
|
|
ret.r() = 0.5; |
|
|
ret.g() = 0.5; |
|
|
ret.g() = 0.5; |
|
|
ret.b() = 1; |
|
|
ret.b() = 1; |
|
|
ret.a() = 1; |
|
|
ret.a() = 1; |
|
|
return ret; |
|
|
return ret; |
|
|
}; |
|
|
|
|
|
|
|
|
}, a.get_allocator()); |
|
|
auto red = a.materials.push( |
|
|
auto red = a.materials.push( |
|
|
[&](vec3 p) -> color_t { |
|
|
|
|
|
|
|
|
n">material_t([&](vec3 p) -> color_t { |
|
|
color_t ret; |
|
|
color_t ret; |
|
|
ret.r() = 1; |
|
|
ret.r() = 1; |
|
|
ret.g() = 0; |
|
|
ret.g() = 0; |
|
|
ret.b() = 0; |
|
|
ret.b() = 0; |
|
|
ret.a() = 1; |
|
|
ret.a() = 1; |
|
|
return ret; |
|
|
return ret; |
|
|
} |
|
|
|
|
|
|
|
|
}, a.get_allocator()) |
|
|
); |
|
|
); |
|
|
auto green = a.materials.push( |
|
|
auto green = a.materials.push( |
|
|
[&](vec3 p) -> color_t { |
|
|
|
|
|
|
|
|
n">material_t([&](vec3 p) -> color_t { |
|
|
color_t ret; |
|
|
color_t ret; |
|
|
ret.r() = 0; |
|
|
ret.r() = 0; |
|
|
ret.g() = 1; |
|
|
ret.g() = 1; |
|
|
ret.b() = 0; |
|
|
ret.b() = 0; |
|
|
ret.a() = 1; |
|
|
ret.a() = 1; |
|
|
return ret; |
|
|
return ret; |
|
|
} |
|
|
|
|
|
|
|
|
}, a.get_allocator()) |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
auto sphere = a.scene_elements.push( |
|
|
auto sphere = a.scene_elements.push( |
|
|
[&](vec3 pos) -> render_point { |
|
|
|
|
|
|
|
|
n">sdf_t([&](vec3 pos) -> render_point { |
|
|
auto l_sdf = gp::difference_sdf<float>( |
|
|
auto l_sdf = gp::difference_sdf<float>( |
|
|
gp::sphere_sdf<float>({0.0,0.0,0.0}, 1.0), |
|
|
gp::sphere_sdf<float>({0.0,0.0,0.0}, 1.0), |
|
|
gp::sphere_sdf<float>({-0.75,0.0,0.0}, 1.0) |
|
|
gp::sphere_sdf<float>({-0.75,0.0,0.0}, 1.0) |
|
@ -88,27 +89,28 @@ struct render_test : public test_scaffold { |
|
|
ret.distance = l_sdf(pos); |
|
|
ret.distance = l_sdf(pos); |
|
|
ret.material = red; |
|
|
ret.material = red; |
|
|
return ret; |
|
|
return ret; |
|
|
} |
|
|
|
|
|
|
|
|
}, a.get_allocator()) |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
auto sphere2 = a.scene_elements.push( |
|
|
auto sphere2 = a.scene_elements.push( |
|
|
[&](vec3 pos) -> render_point { |
|
|
|
|
|
|
|
|
n">sdf_t([&](vec3 pos) -> render_point { |
|
|
auto l_sdf_b = gp::sphere_sdf<float>({-0.75,0.0,0.0}, 1.0); |
|
|
auto l_sdf_b = gp::sphere_sdf<float>({-0.75,0.0,0.0}, 1.0); |
|
|
render_point ret; |
|
|
render_point ret; |
|
|
ret.distance = l_sdf_b(pos); |
|
|
ret.distance = l_sdf_b(pos); |
|
|
ret.material = green; |
|
|
ret.material = green; |
|
|
return ret; |
|
|
return ret; |
|
|
} |
|
|
|
|
|
|
|
|
}, a.get_allocator()) |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
a._camera.position = vec3{0, 0, -2}; |
|
|
a._camera.position = vec3{0, 0, -2}; |
|
|
a._camera.normal = vec3{0, 0, 1}; |
|
|
a._camera.normal = vec3{0, 0, 1}; |
|
|
|
|
|
|
|
|
using pic_color = gp::vec4_g<uint8_t>; |
|
|
using pic_color = gp::vec4_g<uint8_t>; |
|
|
|
|
|
using viewport = gp::bmp_viewport<true, pic_color, gp::buddy<>>; |
|
|
|
|
|
|
|
|
gp::bmp_viewport<true, pic_color> vp{ |
|
|
|
|
|
|
|
|
viewport vp{ |
|
|
{128,64}, |
|
|
{128,64}, |
|
|
[&](gp::vec2_g<int32_t> p) -> pic_color { |
|
|
|
|
|
|
|
|
n">viewport::src_t{[&](gp::vec2_g<int32_t> p) -> pic_color { |
|
|
auto orig = a.render({(float)p.x,(float)p.y}); |
|
|
auto orig = a.render({(float)p.x,(float)p.y}); |
|
|
pic_color ret{}; |
|
|
pic_color ret{}; |
|
|
ret.x = (uint8_t)(orig.x*255); |
|
|
ret.x = (uint8_t)(orig.x*255); |
|
@ -116,7 +118,7 @@ struct render_test : public test_scaffold { |
|
|
ret.z = (uint8_t)(orig.z*255); |
|
|
ret.z = (uint8_t)(orig.z*255); |
|
|
ret.w = (uint8_t)(orig.w*255); |
|
|
ret.w = (uint8_t)(orig.w*255); |
|
|
return ret; |
|
|
return ret; |
|
|
} |
|
|
|
|
|
|
|
|
}, a.get_allocator()} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
gp::array<char, 300000>* buff = new gp::array<char, 300000>(); |
|
|
gp::array<char, 300000>* buff = new gp::array<char, 300000>(); |
|
@ -156,9 +158,13 @@ struct function_test : public test_scaffold { |
|
|
|
|
|
|
|
|
virtual int run() { |
|
|
virtual int run() { |
|
|
int res = 0; |
|
|
int res = 0; |
|
|
gp::function<float(vec3)> l_sdf_b{gp::sphere_sdf<float>({0.0,0.0,0.0}, 1.0)}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gp::array<char, 2048> allocation_buffer; |
|
|
|
|
|
gp::buddy<> allocator{allocation_buffer.begin().data, allocation_buffer.size()}; |
|
|
|
|
|
|
|
|
|
|
|
gp::function<float(vec3), gp::buddy<>> l_sdf_b{gp::sphere_sdf<float>({0.0,0.0,0.0}, 1.0), allocator}; |
|
|
{ |
|
|
{ |
|
|
gp::function<float(vec3)> sdf{l_sdf_b}; |
|
|
|
|
|
|
|
|
gp::function<float(vec3)p">, gp::buddy<>> sdf{l_sdf_b}; |
|
|
|
|
|
|
|
|
gp_config::assertion(l_sdf_b(vec3(0,0,0)) == -1 && sdf(vec3(0,0,0)) == -1, "Bad sdf"); |
|
|
gp_config::assertion(l_sdf_b(vec3(0,0,0)) == -1 && sdf(vec3(0,0,0)) == -1, "Bad sdf"); |
|
|
} |
|
|
} |
|
|