Skip to content

Conversation

MightyJosip
Copy link
Member

@MightyJosip MightyJosip commented Feb 7, 2025

This PR converts pygame._sdl2.video.Texture to C code. It has the implementation of all the Texture methods and attributes.

commit 813f384
Author: Josip Komljenović <[email protected]>
Date:   Wed Jan 29 15:43:45 2025 +0100

    Add interface for _sdl2.video classes

commit 702958c
Author: Josip Komljenović <[email protected]>
Date:   Wed Jan 29 15:38:01 2025 +0100

    Add interface for _sdl2.video classes

commit 081b032
Author: Josip Komljenović <[email protected]>
Date:   Wed Jan 29 15:33:20 2025 +0100

    Add interface for _sdl2.video classes

commit c9ffd1c
Author: Josip Komljenović <[email protected]>
Date:   Wed Jan 29 15:25:10 2025 +0100

    Add interface for _sdl2.video classes
commit 813f384
Author: Josip Komljenović <[email protected]>
Date:   Wed Jan 29 15:43:45 2025 +0100

    Add interface for _sdl2.video classes

commit 702958c
Author: Josip Komljenović <[email protected]>
Date:   Wed Jan 29 15:38:01 2025 +0100

    Add interface for _sdl2.video classes

commit 081b032
Author: Josip Komljenović <[email protected]>
Date:   Wed Jan 29 15:33:20 2025 +0100

    Add interface for _sdl2.video classes

commit c9ffd1c
Author: Josip Komljenović <[email protected]>
Date:   Wed Jan 29 15:25:10 2025 +0100

    Add interface for _sdl2.video classes
@MightyJosip MightyJosip changed the title New texture Port Texture to C code Feb 7, 2025
This was referenced Feb 7, 2025
@MightyJosip MightyJosip marked this pull request as ready for review May 17, 2025 06:36
@MightyJosip MightyJosip requested a review from a team as a code owner May 17, 2025 06:36
if (!pg_TwoFloatsFromObj(originobj, &origin.x, &origin.y)) {
return RAISE(PyExc_ValueError, "origin must be a point or None");
}
originptr = &origin;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could pass &origin into SDL_RenderCopyExF directly rather than needing this extra variable. (I see the Cython has it, maybe it's a weird Cython thing or the person who wrote it wasn't as experienced with pointers).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used because &origin cannot be NULL, but in some cases SDL_RenderCopyExF expects the center argument to be NULL

new_texture->texture =
SDL_CreateTextureFromSurface(renderer->renderer, surf);
if (!new_texture->texture) {
return RAISE(pgExc_SDLError, SDL_GetError());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think new_texture should be freed before the RAISE?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, rewrote the function a bit so free isn't needed in current version, but otherwise you are correct, can you check again

src_c/render.c Outdated
Comment on lines 745 to 756
vertices[0].color.r = (int)r_mod * p1_mod[0];
vertices[0].color.g = (int)g_mod * p1_mod[1];
vertices[0].color.b = (int)b_mod * p1_mod[2];
vertices[0].color.a = (int)a_mod * p1_mod[3];
vertices[1].color.r = (int)r_mod * p2_mod[0];
vertices[1].color.g = (int)g_mod * p2_mod[1];
vertices[1].color.b = (int)b_mod * p2_mod[2];
vertices[1].color.a = (int)a_mod * p2_mod[3];
vertices[2].color.r = (int)r_mod * p3_mod[0];
vertices[2].color.g = (int)g_mod * p3_mod[1];
vertices[2].color.b = (int)b_mod * p3_mod[2];
vertices[2].color.a = (int)a_mod * p3_mod[3];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Casting (to int) happens before the multiplication, so (int)r_mod will be 0 unless that channel has 255 as a color mod.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed a bit and moved repetitive lines to macro (at the start of the file), can you check if the current version is correct

Comment on lines +207 to +209
FLIP_HORIZONTAL as FLIP_HORIZONTAL,
FLIP_NONE as FLIP_NONE,
FLIP_VERTICAL as FLIP_VERTICAL,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to expose these constants? As far as I can tell, these are always handled by keyword arguments like flip_x and flip_y

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can remove them, used just as a possible improvement for the future if we change flip x/y arguments with the single flip that would accept something like FLIP_HORIZONTAL | FLIP_VERTICAL

Copy link
Member

@Starbuck5 Starbuck5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sort of PR is very hard to review, not your fault JoKing, just the nature of it.

I could spend quite a long time looking over all the details, but I think I'm comfortable enough with it to approve, given that it's going to be experimental anyways.

Copy link
Member

@oddbookworm oddbookworm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! My functional testing produced results in line with _sdl2

@oddbookworm oddbookworm added this to the 2.5.6 milestone Aug 3, 2025
@oddbookworm oddbookworm merged commit 10bc90e into pygame-community:main Aug 3, 2025
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants