summaryrefslogtreecommitdiff
path: root/c2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'c2.cpp')
-rw-r--r--c2.cpp36
1 files changed, 34 insertions, 2 deletions
diff --git a/c2.cpp b/c2.cpp
index fd02e50..73bbbb6 100644
--- a/c2.cpp
+++ b/c2.cpp
@@ -58,6 +58,30 @@ static Buffer_Id upload_verts(Device* dev) {
return vbo;
}
+Texture_Id make_default_texture(Device* dev) {
+ unsigned* mem;
+ Texture_Id tex;
+ Buffer_Id buf = dev->create_buffer(
+ "default texture stage",
+ 4,
+ Buffer_Flags::copy_src |
+ Buffer_Flags::cpu_readwrite
+ );
+ mem = (unsigned*)dev->map_buffer(buf, 0, 4);
+ mem[0] = 0xffffffff;
+ dev->unmap_buffer(buf);
+ tex = dev->create_texture(
+ "default PBR texture",
+ texture_format_rgba8i,
+ Texture_Flags::sampleable | Texture_Flags::copy_dst,
+ 1,
+ 1,
+ buf
+ );
+ dev->destroy_bufferi(buf);
+ return tex;
+}
+
static Sampler_Id create_clamped_linear(Device* dev) {
Sampler_State s{};
s.min = Filter_Mode::linear;
@@ -79,11 +103,13 @@ struct Config_Buffer2 {
extern "C" int entrypoint() {
Arena video_arena, asset_arena, ui_arena;
Model_Loader model_loader;
+ Material_Loader mat_loader;
Asset_Arena assets;
Device* dev;
Shader* shader, * ui_shader;
Texture* texture;
Texture* texture2;
+ Texture_Id default_texture;
Model* monkey;
Buffer_Id vbo, cbuf;
Sampler_Id clamped_linear;
@@ -109,8 +135,11 @@ extern "C" int entrypoint() {
);
assets.init(&asset_arena, "pack", 128);
dev = Device::create(&video_arena, app);
+ default_texture = make_default_texture(dev);
model_loader.init(dev, &assets);
+ mat_loader.init(&assets, default_texture);
register_asset_loader("MODL", &model_loader);
+ register_asset_loader("MTRL", &mat_loader);
monkey = (Model*)assets.load("monkey.mdl");
app->dev = dev;
shader = (Shader*)assets.load("triangle.csh");
@@ -234,14 +263,16 @@ extern "C" int entrypoint() {
monkey->render(
dev,
&frame_arena,
- depth_prepass
+ depth_prepass,
+ clamped_linear
);
ctx.debug_pop();
ctx.debug_push("forward");
monkey->render(
dev,
&frame_arena,
- pass2
+ pass2,
+ clamped_linear
);
ctx.debug_pop();
@@ -257,6 +288,7 @@ extern "C" int entrypoint() {
}
ui->destroy();
assets.destroy();
+ dev->destroy_texture(default_texture);
dev->destroy_sampler(clamped_linear);
dev->destroy_buffer(vbo);
dev->destroy_buffer(cbuf);