Namespaces

  • crosire
  • Topic Author
More
9 years 3 weeks ago #1 by crosire Namespaces was created by crosire
The next update adds a new useful feature to ReShade's shader language: namespaces. Developers knowing C++, C# and similar languages are familar with the concept already. It basically allows you to encapsulate variables/functions with the same name in different naming spaces and then access them.

Example:
// global namespace
float4 Func() { return float4(1, 0, 0, 1); /* red */ }

namespace NS1
{
	// NS1 namespace
	float4 Func() { return float4(0, 1, 0, 1); /* green */ }

	namespace NS2
	{
		// NS2 namespace
		float4 Func() { return float4(0, 0, 1, 1); /* blue */ }
	}
 
	float4 FuncCaller()
	{
		float4 color;

		color = Func(); // color is green, since best match is Func in the current NS1 namespace
		color = NS2::Func(); // color is blue, since we access Func from the NS2 namespace here
		color = NS1::NS2::Func(); // color is blue, same as the previous, we just specify the full name here

		// prefixing with "::" accesses the global namespace
		color = ::Func(); // color is red, since this accesses Func in the global namespace
		color = ::NS1::Func(); // color is green, because we access Func in the NS1 namespace here

		return color;
	}
}
The following user(s) said Thank You: jmp909

Please Log in or Create an account to join the conversation.

We use cookies
We use cookies on our website. Some of them are essential for the operation of the forum. You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.