diff options
Diffstat (limited to 'lighting.cpp')
-rw-r--r-- | lighting.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/lighting.cpp b/lighting.cpp index d78ef6e..75ae7c2 100644 --- a/lighting.cpp +++ b/lighting.cpp @@ -1,4 +1,5 @@ #include "lighting.hpp" +#include "model.hpp" #include "world.hpp" extern "C" { @@ -15,21 +16,52 @@ struct GPU_Light { }; void Lighting::init(Device* dev) { + int i; lights.init( dev, "Light buffer", max_lights * sizeof(GPU_Light), Buffer_Flags::storage_buffer ); + shadows = dev->create_texture( + "Shadowmap Array", + texture_format_d16, + Texture_Flags::sampleable | Texture_Flags::depth_stencil_target, + shadow_res, + shadow_res, + 1, + 1, + max_shadows, + 0 + ); + for (i = 0; i < max_shadows; i++) { + shadow_slices[i] = dev->alias_texture( + shadows, + "Shadowmap Slice", + texture_format_d16, + Texture_Flags::depth_stencil_target, + shadow_res, + shadow_res, + 1, + 1, + 1, + 0, + i + ); + } } void Lighting::destroy(Device* dev) { + int i; lights.destroy(dev); + for (i = 0; i < max_shadows; i++) + dev->destroy_texture(shadow_slices[i]); + dev->destroy_texture(shadows); } void Lighting::write_buf(void* ptr, World& w) { GPU_Light* dst = (GPU_Light*)ptr; - int count = 0; + int count = 0, ccount = 0; for (auto v : w.view<Sun_Light>()) { GPU_Light gl; Sun_Light& l = v.get<Sun_Light>(); @@ -41,8 +73,13 @@ void Lighting::write_buf(void* ptr, World& w) { gl.colour = l.colour; gl.dir = l.dir; dst[count++] = gl; + if (l.caster) { + Caster& c = casters[ccount++]; + c.vp = m4f::identity(); + } } light_count = count; + caster_count = ccount; } void Lighting::update(Device* dev, Context& ctx, World& w) { |