Jump to content

Recommended Posts

Posted

Graphics pipelines in Vulkan are tied to both a shader and context. I want to store a map of these in the context, using the shader as the map key. I can use a weak_ptr to the shader for the key so it does not create a circular reference. This is what the third parameter in the map definition below does:

class Context
{
public:
	std::map<weak_ptr<Shader>, shared_ptr<Pipeline>, std::owner_less<std::weak_ptr<Shader> > pipelines;

	void Draw(shared_ptr<Shader> shader)
	{
		auto iter = pipelines.find(shader);
		if (iter == pipelines.end()) pipelines[shader] = CreatePipeline(shader);
		auto pipeline = iter->second;

		//Begin drawing...

	}
};

When the shader goes out of scope and is deleted the associated pipelines in each context will still be stored in the map. Is there any way I can set this up so that the shader being deleted automatically clears all the map values associated with that key, in each context? The only solution I can think of is to loop through a list of all contexts and remove the values in the shader destructor.

Let's build cool stuff and have fun. :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...