Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sfRenderStates "constructors" from shaders and textures #20

Closed
Fabien-Chouteau opened this issue Jul 8, 2023 · 5 comments
Closed

sfRenderStates "constructors" from shaders and textures #20

Fabien-Chouteau opened this issue Jul 8, 2023 · 5 comments
Assignees
Labels
API enhancement New feature or request

Comments

@Fabien-Chouteau
Copy link
Contributor

Hi @mgrojo, the C++ API has constructors to create a default RenderStates from a shader;

This is convenient when one uses RenderStates just to apply shaders.

I think it should be doable to have something similar in Ada:

function To_RenderState (Shader : sfShader_Ptr) return sfRenderStates 
is (blendMode => Sf.Graphics.BlendMode.sfBlendAlpha,
    transform => Identity,
    texture => null,
    shader => Shader);
@mgrojo
Copy link
Owner

mgrojo commented Jul 8, 2023

Hi @Fabien-Chouteau,

Yes, the CSFML is sometimes minimal and only includes what is needed for bindings, but not general useful stuff for facilitating use of the library. In version 2.5.2 they had to add a function returning the default.

Constructors in the original C++ are always exported as create* functions in CSFML, so I'm hesitating between your naming, which is ideal per se, and createFromShader or createWithShader, which would be consistent with what CSFML does in other cases.

@mgrojo mgrojo added enhancement New feature or request API labels Jul 8, 2023
mgrojo added a commit that referenced this issue Jul 8, 2023
The set of constructors in the C++ API is conflated into a create function
with all possible default values in the parameters. Documentation inspired
by the C++ version.

Also, a default function is declared reusing those defaults in order to
match the following change made in CSFML:
SFML/CSFML#178
@mgrojo mgrojo self-assigned this Jul 8, 2023
@mgrojo
Copy link
Owner

mgrojo commented Jul 8, 2023

@Fabien-Chouteau, could you confirm it works for you? Then we can close the issue.

At the end I have chosen a create function with all the defaults as defined in the default constructor in C++, so one can have the same effect as in C++, but explicitly calling the conversion function, as expected in Ada. Additionally, I've created a default function to keep it aligned with CSFML after SFML/CSFML#180

mgrojo added a commit that referenced this issue Jul 8, 2023
)

There are changes probably due to a change in gnatdoc version. Now gnatdoc
from GNAT Community 2021 has been used. Previously, it was probably
the one from Ubuntu 20, but now it is no longer available en 22.
@Fabien-Chouteau
Copy link
Contributor Author

Thanks @mgrojo, I works!

I also realized that adding default values to the sfRenderStates record would also work:

   type sfRenderStates is record
      blendMode : aliased Sf.Graphics.BlendMode.sfBlendMode := Sf.Graphics.BlendMode.sfBlendAlpha;
      transform : aliased Sf.Graphics.Transform.sfTransform := Sf.Graphics.Transform.Identity;
      texture : sfTexture_Ptr := null;
      shader : sfShader_Ptr := null;
   end record;
  RS : aliased sfRenderStates := (shader => My_Shader, others => <>);

@mgrojo
Copy link
Owner

mgrojo commented Jul 9, 2023

I tend to avoid the record initializations because I've seen sometimes they could lead to a performance issue. But since there are two access fields, I suppose there is already an initialization function for the record, so it might make sense to include the others. I don't know if having both styles is going to be too much, but I'll add this without removing the function, because I like that for consistency to other types and to the C++ class.

mgrojo added a commit that referenced this issue Jul 9, 2023
This will let the user choose between an initialization expression or the
call to the create function.

See issue:  sfRenderStates "constructors" from shaders and textures #20
@mgrojo
Copy link
Owner

mgrojo commented Aug 21, 2023

@Fabien-Chouteau I plan to publish a new release, and apparently this is fixed. Feel free to comment and/or reopen this if there is something still missing.

@mgrojo mgrojo closed this as completed Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants