summaryrefslogtreecommitdiff
path: root/lighting.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lighting.cpp')
-rw-r--r--lighting.cpp49
1 files changed, 48 insertions, 1 deletions
diff --git a/lighting.cpp b/lighting.cpp
index 0e41ddd..4f1fdfb 100644
--- a/lighting.cpp
+++ b/lighting.cpp
@@ -20,7 +20,7 @@ struct GPU_Caster {
m4f projection;
};
-void Lighting::init(Device* dev) {
+void Lighting::init(Device* dev, int w, int h) {
int i;
Sampler_State ss{};
lights.init(
@@ -46,6 +46,9 @@ void Lighting::init(Device* dev) {
max_shadows,
0
);
+ zero(ss_shadows, sizeof ss_shadows);
+ zero(ss_shadow_slices, sizeof ss_shadow_slices);
+ recreate(dev, w, h);
for (i = 0; i < max_shadows; i++) {
cameras[i] = 0;
shadow_slices[i] = dev->alias_texture(
@@ -85,6 +88,50 @@ void Lighting::destroy(Device* dev, Renderer& r) {
r.destroy_camera(cameras[i]);
}
dev->destroy_texture(shadows);
+ destroy_ss(dev);
+}
+
+void Lighting::destroy_ss(Device* dev) {
+ int i, j;
+ for (i = 0; i < 2; i++) {
+ for (j = 0; j < max_shadows; j++)
+ if (ss_shadow_slices[i][j])
+ dev->destroy_texture(ss_shadow_slices[i][j]);
+ if (ss_shadows[i])
+ dev->destroy_texture(ss_shadows[i]);
+ }
+}
+
+void Lighting::recreate(Device* dev, int w, int h) {
+ int i, j;
+ destroy_ss(dev);
+ for (i = 0; i < 2; i++) {
+ ss_shadows[i] = dev->create_texture(
+ "Shadow accumulation buffer",
+ texture_format_r8i,
+ Texture_Flags::sampleable | Texture_Flags::colour_target,
+ w,
+ h,
+ 1,
+ 1,
+ max_shadows,
+ 0
+ );
+ for (j = 0; j < max_shadows; j++)
+ ss_shadow_slices[i][j] = dev->alias_texture(
+ ss_shadows[i],
+ "Shadow accumulation buffer slice",
+ texture_format_r8i,
+ Texture_Flags::colour_target,
+ shadow_res,
+ shadow_res,
+ 1,
+ 1,
+ 1,
+ 0,
+ j
+ );
+ }
}
void Lighting::write_bufs(