SFML community forums

Bindings - other languages => DotNet => Topic started by: Spodi on November 07, 2010, 09:59:51 pm

Title: Call to invalid method: sfShader_Create
Post 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.
Title: Call to invalid method: sfShader_Create
Post by: Laurent on November 11, 2010, 10:52:47 am
It's fixed, thank you.
Title: Call to invalid method: sfShader_Create
Post by: Spodi on November 13, 2010, 07:17:24 pm
Thanks. :)

At the risk of sounding like a butt, the following should also be removed now:

Code: [Select]
static extern IntPtr sfShader_Create();

Code: [Select]
static extern IntPtr sfImage_Create();

And I'm not sure about this one, but:

Code: [Select]
void LoadFromString(string shader)

That method is never used. Was it supposed to be public?
Title: Call to invalid method: sfShader_Create
Post by: Laurent on November 13, 2010, 07:28:10 pm
You'll never sound like a butt for fixing things ;)

Quote
Code: [Select]
static extern IntPtr sfShader_Create();
static extern IntPtr sfImage_Create();

I removed them.

Quote
Code: [Select]
void LoadFromString(string shader)

It's now public.

Thank you :)
Title: Call to invalid method: sfShader_Create
Post by: Spodi on November 13, 2010, 07:46:36 pm
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:

Code: [Select]
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.
Title: Call to invalid method: sfShader_Create
Post by: Laurent on November 13, 2010, 08:29:49 pm
Quote
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:

Quote
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)?
Title: Call to invalid method: sfShader_Create
Post by: Spodi on November 13, 2010, 08:47:03 pm
Quote from: "Laurent"
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.
Title: Call to invalid method: sfShader_Create
Post by: Laurent on November 13, 2010, 09:07:36 pm
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.