SFML community forums
Bindings - other languages => DotNet => Topic started by: Spodi on November 07, 2010, 09:59:51 pm
-
The default Shader() constructor calls sfShader_Create, which doesn't seem to exist in csfml.
-
It's fixed, thank you.
-
Thanks. :)
At the risk of sounding like a butt, the following should also be removed now:
static extern IntPtr sfShader_Create();
static extern IntPtr sfImage_Create();
And I'm not sure about this one, but:
void LoadFromString(string shader)
That method is never used. Was it supposed to be public?
-
You'll never sound like a butt for fixing things ;)
static extern IntPtr sfShader_Create();
static extern IntPtr sfImage_Create();
I removed them.
void LoadFromString(string shader)
It's now public.
Thank you :)
-
Now that we have this public LoadFromString, and you removed the default constructor, how should we go about using it without loading a shader from somewhere else first? :wink:
From what it looks like, the LoadFromString was never added since there was already a public constructor using a string (for loading from file). Maybe LoadFromString can be introduced as a public static method:
public static Shader FromString(string shader)
{
return new Shader(sfShader_CreateFromMemory(shader));
}
Shader(IntPtr shader) : base(shader)
{
if (This == IntPtr.Zero)
throw new LoadingFailedException("shader");
}
Its a pretty common approach in .NET for when you have multiple constructors with very similar (or identical) parameters, but the way the parameters are used are very different.
-
Now that we have this public LoadFromString, and you removed the default constructor, how should we go about using it without loading a shader from somewhere else first?
Ha ha :twisted:
Its a pretty common approach in .NET for when you have multiple constructors with very similar (or identical) parameters, but the way the parameters are used are very different.
That's also what the PySFML guys chose to do. Do you think that I should do it for every constructor of every class? Or maybe only resource classes (Image, Font, SoundBuffer, Shader)?
-
Do you think that I should do it for every constructor of every class? Or maybe only resource classes (Image, Font, SoundBuffer, Shader)?
Right now, every resource class has a constructor that takes a string that loads from file (at least from what I remember). So it should be fine leaving the rest as they are since the Shader is just a special scenario that just happens to be able to load from a raw string.
-
It's not a special scenario: images can be loaded from an array of pixels, sound buffers can be loaded from an array of samples, etc. It can also be seen as the equivalent of a "load from memory" that other classes have. So if possible I'd like to keep a consistent API between all these classes.