Răsfoiți Sursa

world: cleanup

Daniele Bartolini 5 luni în urmă
părinte
comite
cfe8b9efcb
4 a modificat fișierele cu 29 adăugiri și 34 ștergeri
  1. 18 4
      src/device/pipeline.cpp
  2. 6 1
      src/device/pipeline.h
  3. 5 23
      src/world/render_world.cpp
  4. 0 6
      src/world/render_world.h

+ 18 - 4
src/device/pipeline.cpp

@@ -127,6 +127,7 @@ Pipeline::Pipeline(ShaderManager &sm)
 	, _outline_frame_buffer(BGFX_INVALID_HANDLE)
 	, _outline_color_map(BGFX_INVALID_HANDLE)
 	, _outline_color(BGFX_INVALID_HANDLE)
+	, _unit_id(BGFX_INVALID_HANDLE)
 	, _sun_shadow_map_texture(BGFX_INVALID_HANDLE)
 	, _sun_shadow_map_frame_buffer(BGFX_INVALID_HANDLE)
 	, _local_lights_shadow_map_texture(BGFX_INVALID_HANDLE)
@@ -163,6 +164,7 @@ void Pipeline::create(u16 width, u16 height, const RenderSettings &render_settin
 
 	_outline_color_map = bgfx::createUniform("s_color_map", bgfx::UniformType::Sampler);
 	_outline_color = bgfx::createUniform("u_outline_color", bgfx::UniformType::Vec4);
+	_unit_id = bgfx::createUniform("u_unit_id", bgfx::UniformType::Vec4);
 
 	_u_cascaded_shadow_map = bgfx::createUniform("u_cascaded_shadow_map", bgfx::UniformType::Sampler);
 	_u_cascaded_lights = bgfx::createUniform("u_cascaded_lights", bgfx::UniformType::Mat4, MAX_NUM_CASCADES);
@@ -207,7 +209,10 @@ void Pipeline::create(u16 width, u16 height, const RenderSettings &render_settin
 	_u_local_lights_shadow_map = bgfx::createUniform("u_local_lights_shadow_map", bgfx::UniformType::Sampler);
 	_u_local_lights_params = bgfx::createUniform("u_local_lights_params", bgfx::UniformType::Vec4);
 
-	_u_lighting_params = bgfx::createUniform("u_lighting_params", bgfx::UniformType::Vec4);
+	_lights_num = bgfx::createUniform("u_lights_num", bgfx::UniformType::Vec4, 1);
+	_lights_data = bgfx::createUniform("u_lights_data", bgfx::UniformType::Vec4, LIGHT_SIZE*MAX_NUM_LIGHTS);
+	_fog_data = bgfx::createUniform("u_fog_data", bgfx::UniformType::Vec4, 2);
+	_lighting_params = bgfx::createUniform("u_lighting_params", bgfx::UniformType::Vec4);
 
 	_bloom_map = bgfx::createUniform("s_bloom_map", bgfx::UniformType::Sampler);
 	_map_pixel_size = bgfx::createUniform("u_map_pixel_size", bgfx::UniformType::Vec4);
@@ -231,8 +236,15 @@ void Pipeline::destroy()
 	bgfx::destroy(_html5_default_texture);
 	_html5_default_texture = BGFX_INVALID_HANDLE;
 #endif
-	bgfx::destroy(_u_lighting_params);
-	_u_lighting_params = BGFX_INVALID_HANDLE;
+
+	bgfx::destroy(_lighting_params);
+	_lighting_params = BGFX_INVALID_HANDLE;
+	bgfx::destroy(_fog_data);
+	_fog_data = BGFX_INVALID_HANDLE;
+	bgfx::destroy(_lights_data);
+	_lights_data = BGFX_INVALID_HANDLE;
+	bgfx::destroy(_lights_num);
+	_lights_num = BGFX_INVALID_HANDLE;
 
 	// Destroy local-lights shadow map resources.
 	bgfx::destroy(_u_local_lights_params);
@@ -275,6 +287,8 @@ void Pipeline::destroy()
 		_bloom_frame_buffers[i] = BGFX_INVALID_HANDLE;
 	}
 
+	bgfx::destroy(_unit_id);
+	_unit_id = BGFX_INVALID_HANDLE;
 	bgfx::destroy(_outline_color);
 	_outline_color = BGFX_INVALID_HANDLE;
 	bgfx::destroy(_outline_color_map);
@@ -722,7 +736,7 @@ void Pipeline::set_global_lighting_params(GlobalLightingDesc *global_lighting)
 	params.y = global_lighting->ambient_color.y;
 	params.z = global_lighting->ambient_color.z;
 
-	bgfx::setUniform(_u_lighting_params, &params, sizeof(params)/sizeof(Vector4));
+	bgfx::setUniform(_lighting_params, &params, sizeof(params)/sizeof(Vector4));
 }
 
 } // namespace crown

+ 6 - 1
src/device/pipeline.h

@@ -85,6 +85,7 @@ struct Pipeline
 	bgfx::FrameBufferHandle _outline_frame_buffer;
 	bgfx::UniformHandle _outline_color_map;
 	bgfx::UniformHandle _outline_color;
+	bgfx::UniformHandle _unit_id;
 
 	// Cascaded shadow mapping.
 	bgfx::TextureHandle _sun_shadow_map_texture;
@@ -97,7 +98,11 @@ struct Pipeline
 	bgfx::UniformHandle _u_local_lights_shadow_map;
 	bgfx::UniformHandle _u_local_lights_params;
 
-	bgfx::UniformHandle _u_lighting_params;
+	// Lighting.
+	bgfx::UniformHandle _lights_num;
+	bgfx::UniformHandle _lights_data;
+	bgfx::UniformHandle _fog_data;
+	bgfx::UniformHandle _lighting_params;
 
 	// Bloom.
 	bgfx::FrameBufferHandle _bloom_frame_buffers[BLOOM_MIPS];

+ 5 - 23
src/world/render_world.cpp

@@ -67,16 +67,8 @@ RenderWorld::RenderWorld(Allocator &a
 	_unit_destroy_callback.node.prev = NULL;
 	um.register_destroy_callback(&_unit_destroy_callback);
 
-	// Outlines.
-	_u_unit_id = bgfx::createUniform("u_unit_id", bgfx::UniformType::Vec4);
-
-	// Lighting.
-	_u_lights_num = bgfx::createUniform("u_lights_num", bgfx::UniformType::Vec4, 1);
-	_u_lights_data = bgfx::createUniform("u_lights_data", bgfx::UniformType::Vec4, LIGHT_SIZE*MAX_NUM_LIGHTS);
-
 	// Fog.
 	memset(&_fog_desc, 0, sizeof(_fog_desc));
-	_u_fog_data = bgfx::createUniform("u_fog_data", bgfx::UniformType::Vec4, 2);
 
 	// Global lighting.
 	memset((void *)&_global_lighting_desc, 0, sizeof(_global_lighting_desc));
@@ -91,16 +83,6 @@ RenderWorld::RenderWorld(Allocator &a
 
 RenderWorld::~RenderWorld()
 {
-	// Destroy fog uniform.
-	bgfx::destroy(_u_fog_data);
-
-	// Destroy lighting uniforms.
-	bgfx::destroy(_u_lights_data);
-	bgfx::destroy(_u_lights_num);
-
-	// Destroy outlines uniforms.
-	bgfx::destroy(_u_unit_id);
-
 	_unit_manager->unregister_destroy_callback(&_unit_destroy_callback);
 
 	_mesh_manager.destroy();
@@ -887,9 +869,9 @@ void RenderWorld::render(const Matrix4x4 &view, const Matrix4x4 &proj, UnitId sk
 	h.y = array::size(lm._local_lights_omni);
 	h.z = array::size(lm._local_lights_spot);
 	h.w = 0.0f;
-	bgfx::setUniform(_u_lights_num, &h);
+	bgfx::setUniform(_pipeline->_lights_num, &h);
 	CE_ENSURE(array::size(lm._lights_data) <= MAX_NUM_LIGHTS);
-	bgfx::setUniform(_u_lights_data, (char *)array::begin(lm._lights_data), array::size(lm._lights_data)*sizeof(LightManager::ShaderData)/sizeof(Vector4));
+	bgfx::setUniform(_pipeline->_lights_data, (char *)array::begin(lm._lights_data), array::size(lm._lights_data)*sizeof(LightManager::ShaderData)/sizeof(Vector4));
 	bgfx::touch(View::LIGHTS);
 
 	// Skydome.
@@ -1251,7 +1233,7 @@ void RenderWorld::MeshManager::draw_visibles(u8 view_id, SceneGraph &scene_graph
 		bgfx::setTexture(CASCADED_SHADOW_MAP_SLOT, _render_world->_pipeline->_u_cascaded_shadow_map, _render_world->_pipeline->_sun_shadow_map_texture);
 		bgfx::setUniform(_render_world->_pipeline->_u_cascaded_lights, cascaded_lights, MAX_NUM_CASCADES);
 		bgfx::setUniform(_render_world->_pipeline->_u_shadow_maps_texel_sizes, &texel_sizes);
-		bgfx::setUniform(_render_world->_u_fog_data, (char *)&_render_world->_fog_desc, sizeof(_render_world->_fog_desc) / sizeof(Vector4));
+		bgfx::setUniform(_render_world->_pipeline->_fog_data, (char *)&_render_world->_fog_desc, sizeof(_render_world->_fog_desc) / sizeof(Vector4));
 		_render_world->_pipeline->set_local_lights_params_uniform();
 		_render_world->_pipeline->set_global_lighting_params(&_render_world->_global_lighting_desc);
 
@@ -1277,7 +1259,7 @@ void RenderWorld::MeshManager::draw_selected(u8 view_id, SceneGraph &scene_graph
 
 		u2f.u = unit_id._idx;
 		Vector4 data = { u2f.f, 0.0f, 0.0f, 0.0f };
-		bgfx::setUniform(_render_world->_u_unit_id, &data);
+		bgfx::setUniform(_render_world->_pipeline->_unit_id, &data);
 
 		set_instance_data(ii, scene_graph);
 		bgfx::setState(_render_world->_pipeline->_selection_shader.state);
@@ -1622,7 +1604,7 @@ void RenderWorld::SpriteManager::draw_selected(u8 view_id)
 
 		u2f.u = unit_id._idx;
 		Vector4 data = { u2f.f, 0.0f, 0.0f, 0.0f };
-		bgfx::setUniform(_render_world->_u_unit_id, &data);
+		bgfx::setUniform(_render_world->_pipeline->_unit_id, &data);
 
 		bgfx::setState(_render_world->_pipeline->_selection_shader.state);
 		bgfx::submit(view_id, _render_world->_pipeline->_selection_shader.program);

+ 0 - 6
src/world/render_world.h

@@ -546,17 +546,11 @@ struct RenderWorld
 
 	// Outlines.
 	HashSet<UnitId> _selection;
-	bgfx::UniformHandle _u_unit_id;
-
-	// Lighting.
-	bgfx::UniformHandle _u_lights_num;
-	bgfx::UniformHandle _u_lights_data;
 
 	// Fog.
 	UnitId _fog_unit;
 	FogInstance _fog;
 	FogDesc _fog_desc;
-	bgfx::UniformHandle _u_fog_data;
 
 	// Global lighting.
 	UnitId _global_lighting_unit;