Beispiel #1
0
void Material::setShader(Shader* shader)
{
	bool is_alpha = isAlphaCutout();
	bool is_receiver = isShadowReceiver();
	if (m_shader)
	{
		Shader* shader = m_shader;
		m_shader = nullptr;
		removeDependency(*shader);
		m_resource_manager.get(ResourceManager::SHADER)->unload(*shader);
	}
	m_shader = shader;
	if (m_shader)
	{
		addDependency(*m_shader);

		if (m_shader->isReady())
		{
			m_shader_mask = 0;
			enableShadowReceiving(is_receiver);
			enableAlphaCutout(is_alpha);

			for (int i = 0; i < m_shader->getTextureSlotCount(); ++i)
			{
				if (m_shader->getTextureSlot(i).m_define_idx >= 0 && m_textures[i])
				{
					m_shader_mask |= m_shader->getDefineMask(
						m_shader->getTextureSlot(i).m_define_idx);
				}
			}
			m_shader_instance = &m_shader->getInstance(m_shader_mask);
		}
	}
}
Beispiel #2
0
void Material::setTexture(int i, Texture* texture)
{ 
	Texture* old_texture = i < m_texture_count ? m_textures[i] : nullptr;

	if (texture) addDependency(*texture);
	m_textures[i] = texture;
	if (i >= m_texture_count) m_texture_count = i + 1;

	if (old_texture)
	{
		if (texture) texture->setAtlasSize(old_texture->getAtlasSize());
		removeDependency(*old_texture);
		m_resource_manager.get(ResourceManager::TEXTURE)->unload(*old_texture);
	}
	if (isReady() && m_shader)
	{
		int define_idx = m_shader->getTextureSlot(i).m_define_idx;
		if (define_idx >= 0 && m_textures[i])
		{
			m_shader_mask |= m_shader->getDefineMask(define_idx);
		}
		else
		{
			m_shader_mask &= ~m_shader->getDefineMask(define_idx);
		}

		m_shader_instance = &m_shader->getInstance(m_shader_mask);
	}
}
Beispiel #3
0
void Task::removeDependency (int id)
{
  std::string depends = get ("depends");
  std::string uuid = context.tdb2.pending.uuid (id);
  if (uuid != "" && depends.find (uuid) != std::string::npos)
    removeDependency (uuid);
  else
    throw format (STRING_TASK_DEPEND_MISS_DEL, id);
}
Beispiel #4
0
void Model::doUnload(void)
{
	for (int i = 0; i < m_meshes.size(); ++i)
	{
		removeDependency(*m_meshes[i].getMaterial());
		m_resource_manager.get(ResourceManager::MATERIAL)
			->unload(*m_meshes[i].getMaterial());
	}
	m_meshes.clear();
	m_bones.clear();
	m_lods.clear();
	m_geometry_buffer_object.clear();

	m_size = 0;
	onEmpty();
}
Beispiel #5
0
void Model::unload()
{
	auto* material_manager = m_resource_manager.getOwner().get(Material::TYPE);
	for (int i = 0; i < m_meshes.size(); ++i)
	{
		removeDependency(*m_meshes[i].material);
		material_manager->unload(*m_meshes[i].material);
	}
	for (Mesh& mesh : m_meshes)
	{
		if (bgfx::isValid(mesh.index_buffer_handle)) bgfx::destroy(mesh.index_buffer_handle);
		if (bgfx::isValid(mesh.vertex_buffer_handle)) bgfx::destroy(mesh.vertex_buffer_handle);
	}
	m_meshes.clear();
	m_bones.clear();
}
Beispiel #6
0
void Material::unload(void)
{
	clearUniforms();
	setShader(nullptr);

	ResourceManagerBase* texture_manager = m_resource_manager.get(ResourceManager::TEXTURE);
	for (int i = 0; i < m_texture_count; i++)
	{
		if (m_textures[i])
		{
			removeDependency(*m_textures[i]);
			texture_manager->unload(*m_textures[i]);
		}
	}
	m_texture_count = 0;
}
Beispiel #7
0
void Model::unload(void)
{
	auto* material_manager = m_resource_manager.get(ResourceManager::MATERIAL);
	for (int i = 0; i < m_meshes.size(); ++i)
	{
		removeDependency(*m_meshes[i].getMaterial());
		material_manager->unload(*m_meshes[i].getMaterial());
	}
	m_meshes.clear();
	m_bones.clear();
	m_lods.clear();

	if(bgfx::isValid(m_vertices_handle)) bgfx::destroyVertexBuffer(m_vertices_handle);
	if(bgfx::isValid(m_indices_handle)) bgfx::destroyIndexBuffer(m_indices_handle);
	m_indices_handle = BGFX_INVALID_HANDLE;
	m_vertices_handle = BGFX_INVALID_HANDLE;
}