Skip to content

Port Texture to C code #3330

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

Open
wants to merge 38 commits into
base: main
Choose a base branch
from

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.

TODO: fix Renderer.target reference counting in set_target

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
@@ -629,12 +1234,14 @@ static PyTypeObject pgRenderer_Type = {
.tp_getset = renderer_getset};

static PyTypeObject pgTexture_Type = {
PyVarObject_HEAD_INIT(NULL, 0).tp_name = "pygame._render.Texture",
PyVarObject_HEAD_INIT(NULL, 0).tp_name = "pygame._renderer.Texture",
Copy link
Member

Choose a reason for hiding this comment

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

It's the render module, not the renderer module

else {
access = SDL_TEXTUREACCESS_STATIC;
}
self->renderer = renderer;
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't this need to be incref-ed?

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

Choose a reason for hiding this comment

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

Same concern here about refcounting.

texture_set_blend_mode(pgTextureObject *self, PyObject *arg, void *closure)
{
if (PyLong_Check(arg)) {
long longval = PyLong_AsLong(arg);
Copy link
Member

Choose a reason for hiding this comment

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

Technically this function could fail and return -1 with an error set, which you're not checking.

Rather than doing PyLong_Check + PyLong_AsLong you could just do PyLong_AsLong and check it succeeds?

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).

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.

2 participants